9809b0a4cdf48800e450966e62c6d144.js 43 KB

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