worker-base.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. "no use strict";
  2. !(function(window) {
  3. if (typeof window.window != "undefined" && window.document)
  4. return;
  5. if (window.require && window.define)
  6. return;
  7. if (!window.console) {
  8. window.console = function() {
  9. var msgs = Array.prototype.slice.call(arguments, 0);
  10. postMessage({type: "log", data: msgs});
  11. };
  12. window.console.error =
  13. window.console.warn =
  14. window.console.log =
  15. window.console.trace = window.console;
  16. }
  17. window.window = window;
  18. window.ace = window;
  19. window.onerror = function(message, file, line, col, err) {
  20. postMessage({type: "error", data: {
  21. message: message,
  22. data: err.data,
  23. file: file,
  24. line: line,
  25. col: col,
  26. stack: err.stack
  27. }});
  28. };
  29. window.normalizeModule = function(parentId, moduleName) {
  30. // normalize plugin requires
  31. if (moduleName.indexOf("!") !== -1) {
  32. var chunks = moduleName.split("!");
  33. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  34. }
  35. // normalize relative requires
  36. if (moduleName.charAt(0) == ".") {
  37. var base = parentId.split("/").slice(0, -1).join("/");
  38. moduleName = (base ? base + "/" : "") + moduleName;
  39. while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
  40. var previous = moduleName;
  41. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  42. }
  43. }
  44. return moduleName;
  45. };
  46. window.require = function require(parentId, id) {
  47. if (!id) {
  48. id = parentId;
  49. parentId = null;
  50. }
  51. if (!id.charAt)
  52. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  53. id = window.normalizeModule(parentId, id);
  54. var module = window.require.modules[id];
  55. if (module) {
  56. if (!module.initialized) {
  57. module.initialized = true;
  58. module.exports = module.factory().exports;
  59. }
  60. return module.exports;
  61. }
  62. if (!window.require.tlns)
  63. return console.log("unable to load " + id);
  64. var path = resolveModuleId(id, window.require.tlns);
  65. if (path.slice(-3) != ".js") path += ".js";
  66. window.require.id = id;
  67. window.require.modules[id] = {}; // prevent infinite loop on broken modules
  68. importScripts(path);
  69. return window.require(parentId, id);
  70. };
  71. function resolveModuleId(id, paths) {
  72. var testPath = id, tail = "";
  73. while (testPath) {
  74. var alias = paths[testPath];
  75. if (typeof alias == "string") {
  76. return alias + tail;
  77. } else if (alias) {
  78. return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
  79. } else if (alias === false) {
  80. return "";
  81. }
  82. var i = testPath.lastIndexOf("/");
  83. if (i === -1) break;
  84. tail = testPath.substr(i) + tail;
  85. testPath = testPath.slice(0, i);
  86. }
  87. return id;
  88. }
  89. window.require.modules = {};
  90. window.require.tlns = {};
  91. window.define = function(id, deps, factory) {
  92. if (arguments.length == 2) {
  93. factory = deps;
  94. if (typeof id != "string") {
  95. deps = id;
  96. id = window.require.id;
  97. }
  98. } else if (arguments.length == 1) {
  99. factory = id;
  100. deps = [];
  101. id = window.require.id;
  102. }
  103. if (typeof factory != "function") {
  104. window.require.modules[id] = {
  105. exports: factory,
  106. initialized: true
  107. };
  108. return;
  109. }
  110. if (!deps.length)
  111. // If there is no dependencies, we inject "require", "exports" and
  112. // "module" as dependencies, to provide CommonJS compatibility.
  113. deps = ["require", "exports", "module"];
  114. var req = function(childId) {
  115. return window.require(id, childId);
  116. };
  117. window.require.modules[id] = {
  118. exports: {},
  119. factory: function() {
  120. var module = this;
  121. var returnExports = factory.apply(this, deps.slice(0, factory.length).map(function(dep) {
  122. switch (dep) {
  123. // Because "require", "exports" and "module" aren't actual
  124. // dependencies, we must handle them seperately.
  125. case "require": return req;
  126. case "exports": return module.exports;
  127. case "module": return module;
  128. // But for all other dependencies, we can just go ahead and
  129. // require them.
  130. default: return req(dep);
  131. }
  132. }));
  133. if (returnExports)
  134. module.exports = returnExports;
  135. return module;
  136. }
  137. };
  138. };
  139. window.define.amd = {};
  140. require.tlns = {};
  141. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  142. for (var i in topLevelNamespaces)
  143. require.tlns[i] = topLevelNamespaces[i];
  144. };
  145. window.initSender = function initSender() {
  146. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  147. var oop = window.require("ace/lib/oop");
  148. var Sender = function() {};
  149. (function() {
  150. oop.implement(this, EventEmitter);
  151. this.callback = function(data, callbackId) {
  152. postMessage({
  153. type: "call",
  154. id: callbackId,
  155. data: data
  156. });
  157. };
  158. this.emit = function(name, data) {
  159. postMessage({
  160. type: "event",
  161. name: name,
  162. data: data
  163. });
  164. };
  165. }).call(Sender.prototype);
  166. return new Sender();
  167. };
  168. var main = window.main = null;
  169. var sender = window.sender = null;
  170. window.onmessage = function(e) {
  171. var msg = e.data;
  172. if (msg.event && sender) {
  173. sender._signal(msg.event, msg.data);
  174. }
  175. else if (msg.command) {
  176. if (main[msg.command])
  177. main[msg.command].apply(main, msg.args);
  178. else if (window[msg.command])
  179. window[msg.command].apply(window, msg.args);
  180. else
  181. throw new Error("Unknown command:" + msg.command);
  182. }
  183. else if (msg.init) {
  184. window.initBaseUrls(msg.tlns);
  185. sender = window.sender = window.initSender();
  186. var clazz = require(msg.module)[msg.classname];
  187. main = window.main = new clazz(sender);
  188. }
  189. };
  190. })(this);
  191. ace.define("ace/range",[], function(require, exports, module) {
  192. "use strict";
  193. var comparePoints = function(p1, p2) {
  194. return p1.row - p2.row || p1.column - p2.column;
  195. };
  196. var Range = function(startRow, startColumn, endRow, endColumn) {
  197. this.start = {
  198. row: startRow,
  199. column: startColumn
  200. };
  201. this.end = {
  202. row: endRow,
  203. column: endColumn
  204. };
  205. };
  206. (function() {
  207. this.isEqual = function(range) {
  208. return this.start.row === range.start.row &&
  209. this.end.row === range.end.row &&
  210. this.start.column === range.start.column &&
  211. this.end.column === range.end.column;
  212. };
  213. this.toString = function() {
  214. return ("Range: [" + this.start.row + "/" + this.start.column +
  215. "] -> [" + this.end.row + "/" + this.end.column + "]");
  216. };
  217. this.contains = function(row, column) {
  218. return this.compare(row, column) == 0;
  219. };
  220. this.compareRange = function(range) {
  221. var cmp,
  222. end = range.end,
  223. start = range.start;
  224. cmp = this.compare(end.row, end.column);
  225. if (cmp == 1) {
  226. cmp = this.compare(start.row, start.column);
  227. if (cmp == 1) {
  228. return 2;
  229. } else if (cmp == 0) {
  230. return 1;
  231. } else {
  232. return 0;
  233. }
  234. } else if (cmp == -1) {
  235. return -2;
  236. } else {
  237. cmp = this.compare(start.row, start.column);
  238. if (cmp == -1) {
  239. return -1;
  240. } else if (cmp == 1) {
  241. return 42;
  242. } else {
  243. return 0;
  244. }
  245. }
  246. };
  247. this.comparePoint = function(p) {
  248. return this.compare(p.row, p.column);
  249. };
  250. this.containsRange = function(range) {
  251. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  252. };
  253. this.intersects = function(range) {
  254. var cmp = this.compareRange(range);
  255. return (cmp == -1 || cmp == 0 || cmp == 1);
  256. };
  257. this.isEnd = function(row, column) {
  258. return this.end.row == row && this.end.column == column;
  259. };
  260. this.isStart = function(row, column) {
  261. return this.start.row == row && this.start.column == column;
  262. };
  263. this.setStart = function(row, column) {
  264. if (typeof row == "object") {
  265. this.start.column = row.column;
  266. this.start.row = row.row;
  267. } else {
  268. this.start.row = row;
  269. this.start.column = column;
  270. }
  271. };
  272. this.setEnd = function(row, column) {
  273. if (typeof row == "object") {
  274. this.end.column = row.column;
  275. this.end.row = row.row;
  276. } else {
  277. this.end.row = row;
  278. this.end.column = column;
  279. }
  280. };
  281. this.inside = function(row, column) {
  282. if (this.compare(row, column) == 0) {
  283. if (this.isEnd(row, column) || this.isStart(row, column)) {
  284. return false;
  285. } else {
  286. return true;
  287. }
  288. }
  289. return false;
  290. };
  291. this.insideStart = function(row, column) {
  292. if (this.compare(row, column) == 0) {
  293. if (this.isEnd(row, column)) {
  294. return false;
  295. } else {
  296. return true;
  297. }
  298. }
  299. return false;
  300. };
  301. this.insideEnd = function(row, column) {
  302. if (this.compare(row, column) == 0) {
  303. if (this.isStart(row, column)) {
  304. return false;
  305. } else {
  306. return true;
  307. }
  308. }
  309. return false;
  310. };
  311. this.compare = function(row, column) {
  312. if (!this.isMultiLine()) {
  313. if (row === this.start.row) {
  314. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  315. }
  316. }
  317. if (row < this.start.row)
  318. return -1;
  319. if (row > this.end.row)
  320. return 1;
  321. if (this.start.row === row)
  322. return column >= this.start.column ? 0 : -1;
  323. if (this.end.row === row)
  324. return column <= this.end.column ? 0 : 1;
  325. return 0;
  326. };
  327. this.compareStart = function(row, column) {
  328. if (this.start.row == row && this.start.column == column) {
  329. return -1;
  330. } else {
  331. return this.compare(row, column);
  332. }
  333. };
  334. this.compareEnd = function(row, column) {
  335. if (this.end.row == row && this.end.column == column) {
  336. return 1;
  337. } else {
  338. return this.compare(row, column);
  339. }
  340. };
  341. this.compareInside = function(row, column) {
  342. if (this.end.row == row && this.end.column == column) {
  343. return 1;
  344. } else if (this.start.row == row && this.start.column == column) {
  345. return -1;
  346. } else {
  347. return this.compare(row, column);
  348. }
  349. };
  350. this.clipRows = function(firstRow, lastRow) {
  351. if (this.end.row > lastRow)
  352. var end = {row: lastRow + 1, column: 0};
  353. else if (this.end.row < firstRow)
  354. var end = {row: firstRow, column: 0};
  355. if (this.start.row > lastRow)
  356. var start = {row: lastRow + 1, column: 0};
  357. else if (this.start.row < firstRow)
  358. var start = {row: firstRow, column: 0};
  359. return Range.fromPoints(start || this.start, end || this.end);
  360. };
  361. this.extend = function(row, column) {
  362. var cmp = this.compare(row, column);
  363. if (cmp == 0)
  364. return this;
  365. else if (cmp == -1)
  366. var start = {row: row, column: column};
  367. else
  368. var end = {row: row, column: column};
  369. return Range.fromPoints(start || this.start, end || this.end);
  370. };
  371. this.isEmpty = function() {
  372. return (this.start.row === this.end.row && this.start.column === this.end.column);
  373. };
  374. this.isMultiLine = function() {
  375. return (this.start.row !== this.end.row);
  376. };
  377. this.clone = function() {
  378. return Range.fromPoints(this.start, this.end);
  379. };
  380. this.collapseRows = function() {
  381. if (this.end.column == 0)
  382. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  383. else
  384. return new Range(this.start.row, 0, this.end.row, 0);
  385. };
  386. this.toScreenRange = function(session) {
  387. var screenPosStart = session.documentToScreenPosition(this.start);
  388. var screenPosEnd = session.documentToScreenPosition(this.end);
  389. return new Range(
  390. screenPosStart.row, screenPosStart.column,
  391. screenPosEnd.row, screenPosEnd.column
  392. );
  393. };
  394. this.moveBy = function(row, column) {
  395. this.start.row += row;
  396. this.start.column += column;
  397. this.end.row += row;
  398. this.end.column += column;
  399. };
  400. }).call(Range.prototype);
  401. Range.fromPoints = function(start, end) {
  402. return new Range(start.row, start.column, end.row, end.column);
  403. };
  404. Range.comparePoints = comparePoints;
  405. Range.comparePoints = function(p1, p2) {
  406. return p1.row - p2.row || p1.column - p2.column;
  407. };
  408. exports.Range = Range;
  409. });
  410. ace.define("ace/lib/oop",[], function(require, exports, module) {
  411. "use strict";
  412. exports.inherits = function(ctor, superCtor) {
  413. ctor.super_ = superCtor;
  414. ctor.prototype = Object.create(superCtor.prototype, {
  415. constructor: {
  416. value: ctor,
  417. enumerable: false,
  418. writable: true,
  419. configurable: true
  420. }
  421. });
  422. };
  423. exports.mixin = function(obj, mixin) {
  424. for (var key in mixin) {
  425. obj[key] = mixin[key];
  426. }
  427. return obj;
  428. };
  429. exports.implement = function(proto, mixin) {
  430. exports.mixin(proto, mixin);
  431. };
  432. });
  433. ace.define("ace/apply_delta",[], function(require, exports, module) {
  434. "use strict";
  435. function throwDeltaError(delta, errorText){
  436. console.log("Invalid Delta:", delta);
  437. throw "Invalid Delta: " + errorText;
  438. }
  439. function positionInDocument(docLines, position) {
  440. return position.row >= 0 && position.row < docLines.length &&
  441. position.column >= 0 && position.column <= docLines[position.row].length;
  442. }
  443. function validateDelta(docLines, delta) {
  444. if (delta.action != "insert" && delta.action != "remove")
  445. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  446. if (!(delta.lines instanceof Array))
  447. throwDeltaError(delta, "delta.lines must be an Array");
  448. if (!delta.start || !delta.end)
  449. throwDeltaError(delta, "delta.start/end must be an present");
  450. var start = delta.start;
  451. if (!positionInDocument(docLines, delta.start))
  452. throwDeltaError(delta, "delta.start must be contained in document");
  453. var end = delta.end;
  454. if (delta.action == "remove" && !positionInDocument(docLines, end))
  455. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  456. var numRangeRows = end.row - start.row;
  457. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  458. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  459. throwDeltaError(delta, "delta.range must match delta lines");
  460. }
  461. exports.applyDelta = function(docLines, delta, doNotValidate) {
  462. var row = delta.start.row;
  463. var startColumn = delta.start.column;
  464. var line = docLines[row] || "";
  465. switch (delta.action) {
  466. case "insert":
  467. var lines = delta.lines;
  468. if (lines.length === 1) {
  469. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  470. } else {
  471. var args = [row, 1].concat(delta.lines);
  472. docLines.splice.apply(docLines, args);
  473. docLines[row] = line.substring(0, startColumn) + docLines[row];
  474. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  475. }
  476. break;
  477. case "remove":
  478. var endColumn = delta.end.column;
  479. var endRow = delta.end.row;
  480. if (row === endRow) {
  481. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  482. } else {
  483. docLines.splice(
  484. row, endRow - row + 1,
  485. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  486. );
  487. }
  488. break;
  489. }
  490. };
  491. });
  492. ace.define("ace/lib/event_emitter",[], function(require, exports, module) {
  493. "use strict";
  494. var EventEmitter = {};
  495. var stopPropagation = function() { this.propagationStopped = true; };
  496. var preventDefault = function() { this.defaultPrevented = true; };
  497. EventEmitter._emit =
  498. EventEmitter._dispatchEvent = function(eventName, e) {
  499. this._eventRegistry || (this._eventRegistry = {});
  500. this._defaultHandlers || (this._defaultHandlers = {});
  501. var listeners = this._eventRegistry[eventName] || [];
  502. var defaultHandler = this._defaultHandlers[eventName];
  503. if (!listeners.length && !defaultHandler)
  504. return;
  505. if (typeof e != "object" || !e)
  506. e = {};
  507. if (!e.type)
  508. e.type = eventName;
  509. if (!e.stopPropagation)
  510. e.stopPropagation = stopPropagation;
  511. if (!e.preventDefault)
  512. e.preventDefault = preventDefault;
  513. listeners = listeners.slice();
  514. for (var i=0; i<listeners.length; i++) {
  515. listeners[i](e, this);
  516. if (e.propagationStopped)
  517. break;
  518. }
  519. if (defaultHandler && !e.defaultPrevented)
  520. return defaultHandler(e, this);
  521. };
  522. EventEmitter._signal = function(eventName, e) {
  523. var listeners = (this._eventRegistry || {})[eventName];
  524. if (!listeners)
  525. return;
  526. listeners = listeners.slice();
  527. for (var i=0; i<listeners.length; i++)
  528. listeners[i](e, this);
  529. };
  530. EventEmitter.once = function(eventName, callback) {
  531. var _self = this;
  532. this.on(eventName, function newCallback() {
  533. _self.off(eventName, newCallback);
  534. callback.apply(null, arguments);
  535. });
  536. if (!callback) {
  537. return new Promise(function(resolve) {
  538. callback = resolve;
  539. });
  540. }
  541. };
  542. EventEmitter.setDefaultHandler = function(eventName, callback) {
  543. var handlers = this._defaultHandlers;
  544. if (!handlers)
  545. handlers = this._defaultHandlers = {_disabled_: {}};
  546. if (handlers[eventName]) {
  547. var old = handlers[eventName];
  548. var disabled = handlers._disabled_[eventName];
  549. if (!disabled)
  550. handlers._disabled_[eventName] = disabled = [];
  551. disabled.push(old);
  552. var i = disabled.indexOf(callback);
  553. if (i != -1)
  554. disabled.splice(i, 1);
  555. }
  556. handlers[eventName] = callback;
  557. };
  558. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  559. var handlers = this._defaultHandlers;
  560. if (!handlers)
  561. return;
  562. var disabled = handlers._disabled_[eventName];
  563. if (handlers[eventName] == callback) {
  564. if (disabled)
  565. this.setDefaultHandler(eventName, disabled.pop());
  566. } else if (disabled) {
  567. var i = disabled.indexOf(callback);
  568. if (i != -1)
  569. disabled.splice(i, 1);
  570. }
  571. };
  572. EventEmitter.on =
  573. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  574. this._eventRegistry = this._eventRegistry || {};
  575. var listeners = this._eventRegistry[eventName];
  576. if (!listeners)
  577. listeners = this._eventRegistry[eventName] = [];
  578. if (listeners.indexOf(callback) == -1)
  579. listeners[capturing ? "unshift" : "push"](callback);
  580. return callback;
  581. };
  582. EventEmitter.off =
  583. EventEmitter.removeListener =
  584. EventEmitter.removeEventListener = function(eventName, callback) {
  585. this._eventRegistry = this._eventRegistry || {};
  586. var listeners = this._eventRegistry[eventName];
  587. if (!listeners)
  588. return;
  589. var index = listeners.indexOf(callback);
  590. if (index !== -1)
  591. listeners.splice(index, 1);
  592. };
  593. EventEmitter.removeAllListeners = function(eventName) {
  594. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  595. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  596. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  597. };
  598. exports.EventEmitter = EventEmitter;
  599. });
  600. ace.define("ace/anchor",[], function(require, exports, module) {
  601. "use strict";
  602. var oop = require("./lib/oop");
  603. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  604. var Anchor = exports.Anchor = function(doc, row, column) {
  605. this.$onChange = this.onChange.bind(this);
  606. this.attach(doc);
  607. if (typeof column == "undefined")
  608. this.setPosition(row.row, row.column);
  609. else
  610. this.setPosition(row, column);
  611. };
  612. (function() {
  613. oop.implement(this, EventEmitter);
  614. this.getPosition = function() {
  615. return this.$clipPositionToDocument(this.row, this.column);
  616. };
  617. this.getDocument = function() {
  618. return this.document;
  619. };
  620. this.$insertRight = false;
  621. this.onChange = function(delta) {
  622. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  623. return;
  624. if (delta.start.row > this.row)
  625. return;
  626. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  627. this.setPosition(point.row, point.column, true);
  628. };
  629. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  630. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  631. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  632. }
  633. function $getTransformedPoint(delta, point, moveIfEqual) {
  634. var deltaIsInsert = delta.action == "insert";
  635. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  636. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  637. var deltaStart = delta.start;
  638. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  639. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  640. return {
  641. row: point.row,
  642. column: point.column
  643. };
  644. }
  645. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  646. return {
  647. row: point.row + deltaRowShift,
  648. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  649. };
  650. }
  651. return {
  652. row: deltaStart.row,
  653. column: deltaStart.column
  654. };
  655. }
  656. this.setPosition = function(row, column, noClip) {
  657. var pos;
  658. if (noClip) {
  659. pos = {
  660. row: row,
  661. column: column
  662. };
  663. } else {
  664. pos = this.$clipPositionToDocument(row, column);
  665. }
  666. if (this.row == pos.row && this.column == pos.column)
  667. return;
  668. var old = {
  669. row: this.row,
  670. column: this.column
  671. };
  672. this.row = pos.row;
  673. this.column = pos.column;
  674. this._signal("change", {
  675. old: old,
  676. value: pos
  677. });
  678. };
  679. this.detach = function() {
  680. this.document.off("change", this.$onChange);
  681. };
  682. this.attach = function(doc) {
  683. this.document = doc || this.document;
  684. this.document.on("change", this.$onChange);
  685. };
  686. this.$clipPositionToDocument = function(row, column) {
  687. var pos = {};
  688. if (row >= this.document.getLength()) {
  689. pos.row = Math.max(0, this.document.getLength() - 1);
  690. pos.column = this.document.getLine(pos.row).length;
  691. }
  692. else if (row < 0) {
  693. pos.row = 0;
  694. pos.column = 0;
  695. }
  696. else {
  697. pos.row = row;
  698. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  699. }
  700. if (column < 0)
  701. pos.column = 0;
  702. return pos;
  703. };
  704. }).call(Anchor.prototype);
  705. });
  706. ace.define("ace/document",[], function(require, exports, module) {
  707. "use strict";
  708. var oop = require("./lib/oop");
  709. var applyDelta = require("./apply_delta").applyDelta;
  710. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  711. var Range = require("./range").Range;
  712. var Anchor = require("./anchor").Anchor;
  713. var Document = function(textOrLines) {
  714. this.$lines = [""];
  715. if (textOrLines.length === 0) {
  716. this.$lines = [""];
  717. } else if (Array.isArray(textOrLines)) {
  718. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  719. } else {
  720. this.insert({row: 0, column:0}, textOrLines);
  721. }
  722. };
  723. (function() {
  724. oop.implement(this, EventEmitter);
  725. this.setValue = function(text) {
  726. var len = this.getLength() - 1;
  727. this.remove(new Range(0, 0, len, this.getLine(len).length));
  728. this.insert({row: 0, column: 0}, text);
  729. };
  730. this.getValue = function() {
  731. return this.getAllLines().join(this.getNewLineCharacter());
  732. };
  733. this.createAnchor = function(row, column) {
  734. return new Anchor(this, row, column);
  735. };
  736. if ("aaa".split(/a/).length === 0) {
  737. this.$split = function(text) {
  738. return text.replace(/\r\n|\r/g, "\n").split("\n");
  739. };
  740. } else {
  741. this.$split = function(text) {
  742. return text.split(/\r\n|\r|\n/);
  743. };
  744. }
  745. this.$detectNewLine = function(text) {
  746. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  747. this.$autoNewLine = match ? match[1] : "\n";
  748. this._signal("changeNewLineMode");
  749. };
  750. this.getNewLineCharacter = function() {
  751. switch (this.$newLineMode) {
  752. case "windows":
  753. return "\r\n";
  754. case "unix":
  755. return "\n";
  756. default:
  757. return this.$autoNewLine || "\n";
  758. }
  759. };
  760. this.$autoNewLine = "";
  761. this.$newLineMode = "auto";
  762. this.setNewLineMode = function(newLineMode) {
  763. if (this.$newLineMode === newLineMode)
  764. return;
  765. this.$newLineMode = newLineMode;
  766. this._signal("changeNewLineMode");
  767. };
  768. this.getNewLineMode = function() {
  769. return this.$newLineMode;
  770. };
  771. this.isNewLine = function(text) {
  772. return (text == "\r\n" || text == "\r" || text == "\n");
  773. };
  774. this.getLine = function(row) {
  775. return this.$lines[row] || "";
  776. };
  777. this.getLines = function(firstRow, lastRow) {
  778. return this.$lines.slice(firstRow, lastRow + 1);
  779. };
  780. this.getAllLines = function() {
  781. return this.getLines(0, this.getLength());
  782. };
  783. this.getLength = function() {
  784. return this.$lines.length;
  785. };
  786. this.getTextRange = function(range) {
  787. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  788. };
  789. this.getLinesForRange = function(range) {
  790. var lines;
  791. if (range.start.row === range.end.row) {
  792. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  793. } else {
  794. lines = this.getLines(range.start.row, range.end.row);
  795. lines[0] = (lines[0] || "").substring(range.start.column);
  796. var l = lines.length - 1;
  797. if (range.end.row - range.start.row == l)
  798. lines[l] = lines[l].substring(0, range.end.column);
  799. }
  800. return lines;
  801. };
  802. this.insertLines = function(row, lines) {
  803. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  804. return this.insertFullLines(row, lines);
  805. };
  806. this.removeLines = function(firstRow, lastRow) {
  807. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  808. return this.removeFullLines(firstRow, lastRow);
  809. };
  810. this.insertNewLine = function(position) {
  811. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  812. return this.insertMergedLines(position, ["", ""]);
  813. };
  814. this.insert = function(position, text) {
  815. if (this.getLength() <= 1)
  816. this.$detectNewLine(text);
  817. return this.insertMergedLines(position, this.$split(text));
  818. };
  819. this.insertInLine = function(position, text) {
  820. var start = this.clippedPos(position.row, position.column);
  821. var end = this.pos(position.row, position.column + text.length);
  822. this.applyDelta({
  823. start: start,
  824. end: end,
  825. action: "insert",
  826. lines: [text]
  827. }, true);
  828. return this.clonePos(end);
  829. };
  830. this.clippedPos = function(row, column) {
  831. var length = this.getLength();
  832. if (row === undefined) {
  833. row = length;
  834. } else if (row < 0) {
  835. row = 0;
  836. } else if (row >= length) {
  837. row = length - 1;
  838. column = undefined;
  839. }
  840. var line = this.getLine(row);
  841. if (column == undefined)
  842. column = line.length;
  843. column = Math.min(Math.max(column, 0), line.length);
  844. return {row: row, column: column};
  845. };
  846. this.clonePos = function(pos) {
  847. return {row: pos.row, column: pos.column};
  848. };
  849. this.pos = function(row, column) {
  850. return {row: row, column: column};
  851. };
  852. this.$clipPosition = function(position) {
  853. var length = this.getLength();
  854. if (position.row >= length) {
  855. position.row = Math.max(0, length - 1);
  856. position.column = this.getLine(length - 1).length;
  857. } else {
  858. position.row = Math.max(0, position.row);
  859. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  860. }
  861. return position;
  862. };
  863. this.insertFullLines = function(row, lines) {
  864. row = Math.min(Math.max(row, 0), this.getLength());
  865. var column = 0;
  866. if (row < this.getLength()) {
  867. lines = lines.concat([""]);
  868. column = 0;
  869. } else {
  870. lines = [""].concat(lines);
  871. row--;
  872. column = this.$lines[row].length;
  873. }
  874. this.insertMergedLines({row: row, column: column}, lines);
  875. };
  876. this.insertMergedLines = function(position, lines) {
  877. var start = this.clippedPos(position.row, position.column);
  878. var end = {
  879. row: start.row + lines.length - 1,
  880. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  881. };
  882. this.applyDelta({
  883. start: start,
  884. end: end,
  885. action: "insert",
  886. lines: lines
  887. });
  888. return this.clonePos(end);
  889. };
  890. this.remove = function(range) {
  891. var start = this.clippedPos(range.start.row, range.start.column);
  892. var end = this.clippedPos(range.end.row, range.end.column);
  893. this.applyDelta({
  894. start: start,
  895. end: end,
  896. action: "remove",
  897. lines: this.getLinesForRange({start: start, end: end})
  898. });
  899. return this.clonePos(start);
  900. };
  901. this.removeInLine = function(row, startColumn, endColumn) {
  902. var start = this.clippedPos(row, startColumn);
  903. var end = this.clippedPos(row, endColumn);
  904. this.applyDelta({
  905. start: start,
  906. end: end,
  907. action: "remove",
  908. lines: this.getLinesForRange({start: start, end: end})
  909. }, true);
  910. return this.clonePos(start);
  911. };
  912. this.removeFullLines = function(firstRow, lastRow) {
  913. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  914. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  915. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  916. var deleteLastNewLine = lastRow < this.getLength() - 1;
  917. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  918. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  919. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  920. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  921. var range = new Range(startRow, startCol, endRow, endCol);
  922. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  923. this.applyDelta({
  924. start: range.start,
  925. end: range.end,
  926. action: "remove",
  927. lines: this.getLinesForRange(range)
  928. });
  929. return deletedLines;
  930. };
  931. this.removeNewLine = function(row) {
  932. if (row < this.getLength() - 1 && row >= 0) {
  933. this.applyDelta({
  934. start: this.pos(row, this.getLine(row).length),
  935. end: this.pos(row + 1, 0),
  936. action: "remove",
  937. lines: ["", ""]
  938. });
  939. }
  940. };
  941. this.replace = function(range, text) {
  942. if (!(range instanceof Range))
  943. range = Range.fromPoints(range.start, range.end);
  944. if (text.length === 0 && range.isEmpty())
  945. return range.start;
  946. if (text == this.getTextRange(range))
  947. return range.end;
  948. this.remove(range);
  949. var end;
  950. if (text) {
  951. end = this.insert(range.start, text);
  952. }
  953. else {
  954. end = range.start;
  955. }
  956. return end;
  957. };
  958. this.applyDeltas = function(deltas) {
  959. for (var i=0; i<deltas.length; i++) {
  960. this.applyDelta(deltas[i]);
  961. }
  962. };
  963. this.revertDeltas = function(deltas) {
  964. for (var i=deltas.length-1; i>=0; i--) {
  965. this.revertDelta(deltas[i]);
  966. }
  967. };
  968. this.applyDelta = function(delta, doNotValidate) {
  969. var isInsert = delta.action == "insert";
  970. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  971. : !Range.comparePoints(delta.start, delta.end)) {
  972. return;
  973. }
  974. if (isInsert && delta.lines.length > 20000) {
  975. this.$splitAndapplyLargeDelta(delta, 20000);
  976. }
  977. else {
  978. applyDelta(this.$lines, delta, doNotValidate);
  979. this._signal("change", delta);
  980. }
  981. };
  982. this.$safeApplyDelta = function(delta) {
  983. var docLength = this.$lines.length;
  984. if (
  985. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  986. || delta.action == "insert" && delta.start.row <= docLength
  987. ) {
  988. this.applyDelta(delta);
  989. }
  990. };
  991. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  992. var lines = delta.lines;
  993. var l = lines.length - MAX + 1;
  994. var row = delta.start.row;
  995. var column = delta.start.column;
  996. for (var from = 0, to = 0; from < l; from = to) {
  997. to += MAX - 1;
  998. var chunk = lines.slice(from, to);
  999. chunk.push("");
  1000. this.applyDelta({
  1001. start: this.pos(row + from, column),
  1002. end: this.pos(row + to, column = 0),
  1003. action: delta.action,
  1004. lines: chunk
  1005. }, true);
  1006. }
  1007. delta.lines = lines.slice(from);
  1008. delta.start.row = row + from;
  1009. delta.start.column = column;
  1010. this.applyDelta(delta, true);
  1011. };
  1012. this.revertDelta = function(delta) {
  1013. this.$safeApplyDelta({
  1014. start: this.clonePos(delta.start),
  1015. end: this.clonePos(delta.end),
  1016. action: (delta.action == "insert" ? "remove" : "insert"),
  1017. lines: delta.lines.slice()
  1018. });
  1019. };
  1020. this.indexToPosition = function(index, startRow) {
  1021. var lines = this.$lines || this.getAllLines();
  1022. var newlineLength = this.getNewLineCharacter().length;
  1023. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1024. index -= lines[i].length + newlineLength;
  1025. if (index < 0)
  1026. return {row: i, column: index + lines[i].length + newlineLength};
  1027. }
  1028. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1029. };
  1030. this.positionToIndex = function(pos, startRow) {
  1031. var lines = this.$lines || this.getAllLines();
  1032. var newlineLength = this.getNewLineCharacter().length;
  1033. var index = 0;
  1034. var row = Math.min(pos.row, lines.length);
  1035. for (var i = startRow || 0; i < row; ++i)
  1036. index += lines[i].length + newlineLength;
  1037. return index + pos.column;
  1038. };
  1039. }).call(Document.prototype);
  1040. exports.Document = Document;
  1041. });
  1042. ace.define("ace/lib/lang",[], function(require, exports, module) {
  1043. "use strict";
  1044. exports.last = function(a) {
  1045. return a[a.length - 1];
  1046. };
  1047. exports.stringReverse = function(string) {
  1048. return string.split("").reverse().join("");
  1049. };
  1050. exports.stringRepeat = function (string, count) {
  1051. var result = '';
  1052. while (count > 0) {
  1053. if (count & 1)
  1054. result += string;
  1055. if (count >>= 1)
  1056. string += string;
  1057. }
  1058. return result;
  1059. };
  1060. var trimBeginRegexp = /^\s\s*/;
  1061. var trimEndRegexp = /\s\s*$/;
  1062. exports.stringTrimLeft = function (string) {
  1063. return string.replace(trimBeginRegexp, '');
  1064. };
  1065. exports.stringTrimRight = function (string) {
  1066. return string.replace(trimEndRegexp, '');
  1067. };
  1068. exports.copyObject = function(obj) {
  1069. var copy = {};
  1070. for (var key in obj) {
  1071. copy[key] = obj[key];
  1072. }
  1073. return copy;
  1074. };
  1075. exports.copyArray = function(array){
  1076. var copy = [];
  1077. for (var i=0, l=array.length; i<l; i++) {
  1078. if (array[i] && typeof array[i] == "object")
  1079. copy[i] = this.copyObject(array[i]);
  1080. else
  1081. copy[i] = array[i];
  1082. }
  1083. return copy;
  1084. };
  1085. exports.deepCopy = function deepCopy(obj) {
  1086. if (typeof obj !== "object" || !obj)
  1087. return obj;
  1088. var copy;
  1089. if (Array.isArray(obj)) {
  1090. copy = [];
  1091. for (var key = 0; key < obj.length; key++) {
  1092. copy[key] = deepCopy(obj[key]);
  1093. }
  1094. return copy;
  1095. }
  1096. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1097. return obj;
  1098. copy = {};
  1099. for (var key in obj)
  1100. copy[key] = deepCopy(obj[key]);
  1101. return copy;
  1102. };
  1103. exports.arrayToMap = function(arr) {
  1104. var map = {};
  1105. for (var i=0; i<arr.length; i++) {
  1106. map[arr[i]] = 1;
  1107. }
  1108. return map;
  1109. };
  1110. exports.createMap = function(props) {
  1111. var map = Object.create(null);
  1112. for (var i in props) {
  1113. map[i] = props[i];
  1114. }
  1115. return map;
  1116. };
  1117. exports.arrayRemove = function(array, value) {
  1118. for (var i = 0; i <= array.length; i++) {
  1119. if (value === array[i]) {
  1120. array.splice(i, 1);
  1121. }
  1122. }
  1123. };
  1124. exports.escapeRegExp = function(str) {
  1125. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1126. };
  1127. exports.escapeHTML = function(str) {
  1128. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1129. };
  1130. exports.getMatchOffsets = function(string, regExp) {
  1131. var matches = [];
  1132. string.replace(regExp, function(str) {
  1133. matches.push({
  1134. offset: arguments[arguments.length-2],
  1135. length: str.length
  1136. });
  1137. });
  1138. return matches;
  1139. };
  1140. exports.deferredCall = function(fcn) {
  1141. var timer = null;
  1142. var callback = function() {
  1143. timer = null;
  1144. fcn();
  1145. };
  1146. var deferred = function(timeout) {
  1147. deferred.cancel();
  1148. timer = setTimeout(callback, timeout || 0);
  1149. return deferred;
  1150. };
  1151. deferred.schedule = deferred;
  1152. deferred.call = function() {
  1153. this.cancel();
  1154. fcn();
  1155. return deferred;
  1156. };
  1157. deferred.cancel = function() {
  1158. clearTimeout(timer);
  1159. timer = null;
  1160. return deferred;
  1161. };
  1162. deferred.isPending = function() {
  1163. return timer;
  1164. };
  1165. return deferred;
  1166. };
  1167. exports.delayedCall = function(fcn, defaultTimeout) {
  1168. var timer = null;
  1169. var callback = function() {
  1170. timer = null;
  1171. fcn();
  1172. };
  1173. var _self = function(timeout) {
  1174. if (timer == null)
  1175. timer = setTimeout(callback, timeout || defaultTimeout);
  1176. };
  1177. _self.delay = function(timeout) {
  1178. timer && clearTimeout(timer);
  1179. timer = setTimeout(callback, timeout || defaultTimeout);
  1180. };
  1181. _self.schedule = _self;
  1182. _self.call = function() {
  1183. this.cancel();
  1184. fcn();
  1185. };
  1186. _self.cancel = function() {
  1187. timer && clearTimeout(timer);
  1188. timer = null;
  1189. };
  1190. _self.isPending = function() {
  1191. return timer;
  1192. };
  1193. return _self;
  1194. };
  1195. });
  1196. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1197. "use strict";
  1198. var Range = require("../range").Range;
  1199. var Document = require("../document").Document;
  1200. var lang = require("../lib/lang");
  1201. var Mirror = exports.Mirror = function(sender) {
  1202. this.sender = sender;
  1203. var doc = this.doc = new Document("");
  1204. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1205. var _self = this;
  1206. sender.on("change", function(e) {
  1207. var data = e.data;
  1208. if (data[0].start) {
  1209. doc.applyDeltas(data);
  1210. } else {
  1211. for (var i = 0; i < data.length; i += 2) {
  1212. if (Array.isArray(data[i+1])) {
  1213. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1214. } else {
  1215. var d = {action: "remove", start: data[i], end: data[i+1]};
  1216. }
  1217. doc.applyDelta(d, true);
  1218. }
  1219. }
  1220. if (_self.$timeout)
  1221. return deferredUpdate.schedule(_self.$timeout);
  1222. _self.onUpdate();
  1223. });
  1224. };
  1225. (function() {
  1226. this.$timeout = 500;
  1227. this.setTimeout = function(timeout) {
  1228. this.$timeout = timeout;
  1229. };
  1230. this.setValue = function(value) {
  1231. this.doc.setValue(value);
  1232. this.deferredUpdate.schedule(this.$timeout);
  1233. };
  1234. this.getValue = function(callbackId) {
  1235. this.sender.callback(this.doc.getValue(), callbackId);
  1236. };
  1237. this.onUpdate = function() {
  1238. };
  1239. this.isPending = function() {
  1240. return this.deferredUpdate.isPending();
  1241. };
  1242. }).call(Mirror.prototype);
  1243. });