worker-latex.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  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.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. require("ace/lib/es5-shim");
  186. sender = window.sender = window.initSender();
  187. var clazz = require(msg.module)[msg.classname];
  188. main = window.main = new clazz(sender);
  189. }
  190. };
  191. })(this);
  192. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  193. "use strict";
  194. exports.inherits = function(ctor, superCtor) {
  195. ctor.super_ = superCtor;
  196. ctor.prototype = Object.create(superCtor.prototype, {
  197. constructor: {
  198. value: ctor,
  199. enumerable: false,
  200. writable: true,
  201. configurable: true
  202. }
  203. });
  204. };
  205. exports.mixin = function(obj, mixin) {
  206. for (var key in mixin) {
  207. obj[key] = mixin[key];
  208. }
  209. return obj;
  210. };
  211. exports.implement = function(proto, mixin) {
  212. exports.mixin(proto, mixin);
  213. };
  214. });
  215. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  216. "use strict";
  217. var comparePoints = function(p1, p2) {
  218. return p1.row - p2.row || p1.column - p2.column;
  219. };
  220. var Range = function(startRow, startColumn, endRow, endColumn) {
  221. this.start = {
  222. row: startRow,
  223. column: startColumn
  224. };
  225. this.end = {
  226. row: endRow,
  227. column: endColumn
  228. };
  229. };
  230. (function() {
  231. this.isEqual = function(range) {
  232. return this.start.row === range.start.row &&
  233. this.end.row === range.end.row &&
  234. this.start.column === range.start.column &&
  235. this.end.column === range.end.column;
  236. };
  237. this.toString = function() {
  238. return ("Range: [" + this.start.row + "/" + this.start.column +
  239. "] -> [" + this.end.row + "/" + this.end.column + "]");
  240. };
  241. this.contains = function(row, column) {
  242. return this.compare(row, column) == 0;
  243. };
  244. this.compareRange = function(range) {
  245. var cmp,
  246. end = range.end,
  247. start = range.start;
  248. cmp = this.compare(end.row, end.column);
  249. if (cmp == 1) {
  250. cmp = this.compare(start.row, start.column);
  251. if (cmp == 1) {
  252. return 2;
  253. } else if (cmp == 0) {
  254. return 1;
  255. } else {
  256. return 0;
  257. }
  258. } else if (cmp == -1) {
  259. return -2;
  260. } else {
  261. cmp = this.compare(start.row, start.column);
  262. if (cmp == -1) {
  263. return -1;
  264. } else if (cmp == 1) {
  265. return 42;
  266. } else {
  267. return 0;
  268. }
  269. }
  270. };
  271. this.comparePoint = function(p) {
  272. return this.compare(p.row, p.column);
  273. };
  274. this.containsRange = function(range) {
  275. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  276. };
  277. this.intersects = function(range) {
  278. var cmp = this.compareRange(range);
  279. return (cmp == -1 || cmp == 0 || cmp == 1);
  280. };
  281. this.isEnd = function(row, column) {
  282. return this.end.row == row && this.end.column == column;
  283. };
  284. this.isStart = function(row, column) {
  285. return this.start.row == row && this.start.column == column;
  286. };
  287. this.setStart = function(row, column) {
  288. if (typeof row == "object") {
  289. this.start.column = row.column;
  290. this.start.row = row.row;
  291. } else {
  292. this.start.row = row;
  293. this.start.column = column;
  294. }
  295. };
  296. this.setEnd = function(row, column) {
  297. if (typeof row == "object") {
  298. this.end.column = row.column;
  299. this.end.row = row.row;
  300. } else {
  301. this.end.row = row;
  302. this.end.column = column;
  303. }
  304. };
  305. this.inside = function(row, column) {
  306. if (this.compare(row, column) == 0) {
  307. if (this.isEnd(row, column) || this.isStart(row, column)) {
  308. return false;
  309. } else {
  310. return true;
  311. }
  312. }
  313. return false;
  314. };
  315. this.insideStart = function(row, column) {
  316. if (this.compare(row, column) == 0) {
  317. if (this.isEnd(row, column)) {
  318. return false;
  319. } else {
  320. return true;
  321. }
  322. }
  323. return false;
  324. };
  325. this.insideEnd = function(row, column) {
  326. if (this.compare(row, column) == 0) {
  327. if (this.isStart(row, column)) {
  328. return false;
  329. } else {
  330. return true;
  331. }
  332. }
  333. return false;
  334. };
  335. this.compare = function(row, column) {
  336. if (!this.isMultiLine()) {
  337. if (row === this.start.row) {
  338. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  339. }
  340. }
  341. if (row < this.start.row)
  342. return -1;
  343. if (row > this.end.row)
  344. return 1;
  345. if (this.start.row === row)
  346. return column >= this.start.column ? 0 : -1;
  347. if (this.end.row === row)
  348. return column <= this.end.column ? 0 : 1;
  349. return 0;
  350. };
  351. this.compareStart = function(row, column) {
  352. if (this.start.row == row && this.start.column == column) {
  353. return -1;
  354. } else {
  355. return this.compare(row, column);
  356. }
  357. };
  358. this.compareEnd = function(row, column) {
  359. if (this.end.row == row && this.end.column == column) {
  360. return 1;
  361. } else {
  362. return this.compare(row, column);
  363. }
  364. };
  365. this.compareInside = function(row, column) {
  366. if (this.end.row == row && this.end.column == column) {
  367. return 1;
  368. } else if (this.start.row == row && this.start.column == column) {
  369. return -1;
  370. } else {
  371. return this.compare(row, column);
  372. }
  373. };
  374. this.clipRows = function(firstRow, lastRow) {
  375. if (this.end.row > lastRow)
  376. var end = {row: lastRow + 1, column: 0};
  377. else if (this.end.row < firstRow)
  378. var end = {row: firstRow, column: 0};
  379. if (this.start.row > lastRow)
  380. var start = {row: lastRow + 1, column: 0};
  381. else if (this.start.row < firstRow)
  382. var start = {row: firstRow, column: 0};
  383. return Range.fromPoints(start || this.start, end || this.end);
  384. };
  385. this.extend = function(row, column) {
  386. var cmp = this.compare(row, column);
  387. if (cmp == 0)
  388. return this;
  389. else if (cmp == -1)
  390. var start = {row: row, column: column};
  391. else
  392. var end = {row: row, column: column};
  393. return Range.fromPoints(start || this.start, end || this.end);
  394. };
  395. this.isEmpty = function() {
  396. return (this.start.row === this.end.row && this.start.column === this.end.column);
  397. };
  398. this.isMultiLine = function() {
  399. return (this.start.row !== this.end.row);
  400. };
  401. this.clone = function() {
  402. return Range.fromPoints(this.start, this.end);
  403. };
  404. this.collapseRows = function() {
  405. if (this.end.column == 0)
  406. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  407. else
  408. return new Range(this.start.row, 0, this.end.row, 0)
  409. };
  410. this.toScreenRange = function(session) {
  411. var screenPosStart = session.documentToScreenPosition(this.start);
  412. var screenPosEnd = session.documentToScreenPosition(this.end);
  413. return new Range(
  414. screenPosStart.row, screenPosStart.column,
  415. screenPosEnd.row, screenPosEnd.column
  416. );
  417. };
  418. this.moveBy = function(row, column) {
  419. this.start.row += row;
  420. this.start.column += column;
  421. this.end.row += row;
  422. this.end.column += column;
  423. };
  424. }).call(Range.prototype);
  425. Range.fromPoints = function(start, end) {
  426. return new Range(start.row, start.column, end.row, end.column);
  427. };
  428. Range.comparePoints = comparePoints;
  429. Range.comparePoints = function(p1, p2) {
  430. return p1.row - p2.row || p1.column - p2.column;
  431. };
  432. exports.Range = Range;
  433. });
  434. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  435. "use strict";
  436. function throwDeltaError(delta, errorText){
  437. console.log("Invalid Delta:", delta);
  438. throw "Invalid Delta: " + errorText;
  439. }
  440. function positionInDocument(docLines, position) {
  441. return position.row >= 0 && position.row < docLines.length &&
  442. position.column >= 0 && position.column <= docLines[position.row].length;
  443. }
  444. function validateDelta(docLines, delta) {
  445. if (delta.action != "insert" && delta.action != "remove")
  446. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  447. if (!(delta.lines instanceof Array))
  448. throwDeltaError(delta, "delta.lines must be an Array");
  449. if (!delta.start || !delta.end)
  450. throwDeltaError(delta, "delta.start/end must be an present");
  451. var start = delta.start;
  452. if (!positionInDocument(docLines, delta.start))
  453. throwDeltaError(delta, "delta.start must be contained in document");
  454. var end = delta.end;
  455. if (delta.action == "remove" && !positionInDocument(docLines, end))
  456. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  457. var numRangeRows = end.row - start.row;
  458. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  459. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  460. throwDeltaError(delta, "delta.range must match delta lines");
  461. }
  462. exports.applyDelta = function(docLines, delta, doNotValidate) {
  463. var row = delta.start.row;
  464. var startColumn = delta.start.column;
  465. var line = docLines[row] || "";
  466. switch (delta.action) {
  467. case "insert":
  468. var lines = delta.lines;
  469. if (lines.length === 1) {
  470. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  471. } else {
  472. var args = [row, 1].concat(delta.lines);
  473. docLines.splice.apply(docLines, args);
  474. docLines[row] = line.substring(0, startColumn) + docLines[row];
  475. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  476. }
  477. break;
  478. case "remove":
  479. var endColumn = delta.end.column;
  480. var endRow = delta.end.row;
  481. if (row === endRow) {
  482. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  483. } else {
  484. docLines.splice(
  485. row, endRow - row + 1,
  486. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  487. );
  488. }
  489. break;
  490. }
  491. }
  492. });
  493. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  494. "use strict";
  495. var EventEmitter = {};
  496. var stopPropagation = function() { this.propagationStopped = true; };
  497. var preventDefault = function() { this.defaultPrevented = true; };
  498. EventEmitter._emit =
  499. EventEmitter._dispatchEvent = function(eventName, e) {
  500. this._eventRegistry || (this._eventRegistry = {});
  501. this._defaultHandlers || (this._defaultHandlers = {});
  502. var listeners = this._eventRegistry[eventName] || [];
  503. var defaultHandler = this._defaultHandlers[eventName];
  504. if (!listeners.length && !defaultHandler)
  505. return;
  506. if (typeof e != "object" || !e)
  507. e = {};
  508. if (!e.type)
  509. e.type = eventName;
  510. if (!e.stopPropagation)
  511. e.stopPropagation = stopPropagation;
  512. if (!e.preventDefault)
  513. e.preventDefault = preventDefault;
  514. listeners = listeners.slice();
  515. for (var i=0; i<listeners.length; i++) {
  516. listeners[i](e, this);
  517. if (e.propagationStopped)
  518. break;
  519. }
  520. if (defaultHandler && !e.defaultPrevented)
  521. return defaultHandler(e, this);
  522. };
  523. EventEmitter._signal = function(eventName, e) {
  524. var listeners = (this._eventRegistry || {})[eventName];
  525. if (!listeners)
  526. return;
  527. listeners = listeners.slice();
  528. for (var i=0; i<listeners.length; i++)
  529. listeners[i](e, this);
  530. };
  531. EventEmitter.once = function(eventName, callback) {
  532. var _self = this;
  533. callback && this.addEventListener(eventName, function newCallback() {
  534. _self.removeEventListener(eventName, newCallback);
  535. callback.apply(null, arguments);
  536. });
  537. };
  538. EventEmitter.setDefaultHandler = function(eventName, callback) {
  539. var handlers = this._defaultHandlers
  540. if (!handlers)
  541. handlers = this._defaultHandlers = {_disabled_: {}};
  542. if (handlers[eventName]) {
  543. var old = handlers[eventName];
  544. var disabled = handlers._disabled_[eventName];
  545. if (!disabled)
  546. handlers._disabled_[eventName] = disabled = [];
  547. disabled.push(old);
  548. var i = disabled.indexOf(callback);
  549. if (i != -1)
  550. disabled.splice(i, 1);
  551. }
  552. handlers[eventName] = callback;
  553. };
  554. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  555. var handlers = this._defaultHandlers
  556. if (!handlers)
  557. return;
  558. var disabled = handlers._disabled_[eventName];
  559. if (handlers[eventName] == callback) {
  560. var old = handlers[eventName];
  561. if (disabled)
  562. this.setDefaultHandler(eventName, disabled.pop());
  563. } else if (disabled) {
  564. var i = disabled.indexOf(callback);
  565. if (i != -1)
  566. disabled.splice(i, 1);
  567. }
  568. };
  569. EventEmitter.on =
  570. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  571. this._eventRegistry = this._eventRegistry || {};
  572. var listeners = this._eventRegistry[eventName];
  573. if (!listeners)
  574. listeners = this._eventRegistry[eventName] = [];
  575. if (listeners.indexOf(callback) == -1)
  576. listeners[capturing ? "unshift" : "push"](callback);
  577. return callback;
  578. };
  579. EventEmitter.off =
  580. EventEmitter.removeListener =
  581. EventEmitter.removeEventListener = function(eventName, callback) {
  582. this._eventRegistry = this._eventRegistry || {};
  583. var listeners = this._eventRegistry[eventName];
  584. if (!listeners)
  585. return;
  586. var index = listeners.indexOf(callback);
  587. if (index !== -1)
  588. listeners.splice(index, 1);
  589. };
  590. EventEmitter.removeAllListeners = function(eventName) {
  591. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  592. };
  593. exports.EventEmitter = EventEmitter;
  594. });
  595. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  596. "use strict";
  597. var oop = require("./lib/oop");
  598. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  599. var Anchor = exports.Anchor = function(doc, row, column) {
  600. this.$onChange = this.onChange.bind(this);
  601. this.attach(doc);
  602. if (typeof column == "undefined")
  603. this.setPosition(row.row, row.column);
  604. else
  605. this.setPosition(row, column);
  606. };
  607. (function() {
  608. oop.implement(this, EventEmitter);
  609. this.getPosition = function() {
  610. return this.$clipPositionToDocument(this.row, this.column);
  611. };
  612. this.getDocument = function() {
  613. return this.document;
  614. };
  615. this.$insertRight = false;
  616. this.onChange = function(delta) {
  617. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  618. return;
  619. if (delta.start.row > this.row)
  620. return;
  621. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  622. this.setPosition(point.row, point.column, true);
  623. };
  624. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  625. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  626. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  627. }
  628. function $getTransformedPoint(delta, point, moveIfEqual) {
  629. var deltaIsInsert = delta.action == "insert";
  630. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  631. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  632. var deltaStart = delta.start;
  633. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  634. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  635. return {
  636. row: point.row,
  637. column: point.column
  638. };
  639. }
  640. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  641. return {
  642. row: point.row + deltaRowShift,
  643. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  644. };
  645. }
  646. return {
  647. row: deltaStart.row,
  648. column: deltaStart.column
  649. };
  650. }
  651. this.setPosition = function(row, column, noClip) {
  652. var pos;
  653. if (noClip) {
  654. pos = {
  655. row: row,
  656. column: column
  657. };
  658. } else {
  659. pos = this.$clipPositionToDocument(row, column);
  660. }
  661. if (this.row == pos.row && this.column == pos.column)
  662. return;
  663. var old = {
  664. row: this.row,
  665. column: this.column
  666. };
  667. this.row = pos.row;
  668. this.column = pos.column;
  669. this._signal("change", {
  670. old: old,
  671. value: pos
  672. });
  673. };
  674. this.detach = function() {
  675. this.document.removeEventListener("change", this.$onChange);
  676. };
  677. this.attach = function(doc) {
  678. this.document = doc || this.document;
  679. this.document.on("change", this.$onChange);
  680. };
  681. this.$clipPositionToDocument = function(row, column) {
  682. var pos = {};
  683. if (row >= this.document.getLength()) {
  684. pos.row = Math.max(0, this.document.getLength() - 1);
  685. pos.column = this.document.getLine(pos.row).length;
  686. }
  687. else if (row < 0) {
  688. pos.row = 0;
  689. pos.column = 0;
  690. }
  691. else {
  692. pos.row = row;
  693. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  694. }
  695. if (column < 0)
  696. pos.column = 0;
  697. return pos;
  698. };
  699. }).call(Anchor.prototype);
  700. });
  701. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  702. "use strict";
  703. var oop = require("./lib/oop");
  704. var applyDelta = require("./apply_delta").applyDelta;
  705. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  706. var Range = require("./range").Range;
  707. var Anchor = require("./anchor").Anchor;
  708. var Document = function(textOrLines) {
  709. this.$lines = [""];
  710. if (textOrLines.length === 0) {
  711. this.$lines = [""];
  712. } else if (Array.isArray(textOrLines)) {
  713. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  714. } else {
  715. this.insert({row: 0, column:0}, textOrLines);
  716. }
  717. };
  718. (function() {
  719. oop.implement(this, EventEmitter);
  720. this.setValue = function(text) {
  721. var len = this.getLength() - 1;
  722. this.remove(new Range(0, 0, len, this.getLine(len).length));
  723. this.insert({row: 0, column: 0}, text);
  724. };
  725. this.getValue = function() {
  726. return this.getAllLines().join(this.getNewLineCharacter());
  727. };
  728. this.createAnchor = function(row, column) {
  729. return new Anchor(this, row, column);
  730. };
  731. if ("aaa".split(/a/).length === 0) {
  732. this.$split = function(text) {
  733. return text.replace(/\r\n|\r/g, "\n").split("\n");
  734. };
  735. } else {
  736. this.$split = function(text) {
  737. return text.split(/\r\n|\r|\n/);
  738. };
  739. }
  740. this.$detectNewLine = function(text) {
  741. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  742. this.$autoNewLine = match ? match[1] : "\n";
  743. this._signal("changeNewLineMode");
  744. };
  745. this.getNewLineCharacter = function() {
  746. switch (this.$newLineMode) {
  747. case "windows":
  748. return "\r\n";
  749. case "unix":
  750. return "\n";
  751. default:
  752. return this.$autoNewLine || "\n";
  753. }
  754. };
  755. this.$autoNewLine = "";
  756. this.$newLineMode = "auto";
  757. this.setNewLineMode = function(newLineMode) {
  758. if (this.$newLineMode === newLineMode)
  759. return;
  760. this.$newLineMode = newLineMode;
  761. this._signal("changeNewLineMode");
  762. };
  763. this.getNewLineMode = function() {
  764. return this.$newLineMode;
  765. };
  766. this.isNewLine = function(text) {
  767. return (text == "\r\n" || text == "\r" || text == "\n");
  768. };
  769. this.getLine = function(row) {
  770. return this.$lines[row] || "";
  771. };
  772. this.getLines = function(firstRow, lastRow) {
  773. return this.$lines.slice(firstRow, lastRow + 1);
  774. };
  775. this.getAllLines = function() {
  776. return this.getLines(0, this.getLength());
  777. };
  778. this.getLength = function() {
  779. return this.$lines.length;
  780. };
  781. this.getTextRange = function(range) {
  782. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  783. };
  784. this.getLinesForRange = function(range) {
  785. var lines;
  786. if (range.start.row === range.end.row) {
  787. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  788. } else {
  789. lines = this.getLines(range.start.row, range.end.row);
  790. lines[0] = (lines[0] || "").substring(range.start.column);
  791. var l = lines.length - 1;
  792. if (range.end.row - range.start.row == l)
  793. lines[l] = lines[l].substring(0, range.end.column);
  794. }
  795. return lines;
  796. };
  797. this.insertLines = function(row, lines) {
  798. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  799. return this.insertFullLines(row, lines);
  800. };
  801. this.removeLines = function(firstRow, lastRow) {
  802. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  803. return this.removeFullLines(firstRow, lastRow);
  804. };
  805. this.insertNewLine = function(position) {
  806. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  807. return this.insertMergedLines(position, ["", ""]);
  808. };
  809. this.insert = function(position, text) {
  810. if (this.getLength() <= 1)
  811. this.$detectNewLine(text);
  812. return this.insertMergedLines(position, this.$split(text));
  813. };
  814. this.insertInLine = function(position, text) {
  815. var start = this.clippedPos(position.row, position.column);
  816. var end = this.pos(position.row, position.column + text.length);
  817. this.applyDelta({
  818. start: start,
  819. end: end,
  820. action: "insert",
  821. lines: [text]
  822. }, true);
  823. return this.clonePos(end);
  824. };
  825. this.clippedPos = function(row, column) {
  826. var length = this.getLength();
  827. if (row === undefined) {
  828. row = length;
  829. } else if (row < 0) {
  830. row = 0;
  831. } else if (row >= length) {
  832. row = length - 1;
  833. column = undefined;
  834. }
  835. var line = this.getLine(row);
  836. if (column == undefined)
  837. column = line.length;
  838. column = Math.min(Math.max(column, 0), line.length);
  839. return {row: row, column: column};
  840. };
  841. this.clonePos = function(pos) {
  842. return {row: pos.row, column: pos.column};
  843. };
  844. this.pos = function(row, column) {
  845. return {row: row, column: column};
  846. };
  847. this.$clipPosition = function(position) {
  848. var length = this.getLength();
  849. if (position.row >= length) {
  850. position.row = Math.max(0, length - 1);
  851. position.column = this.getLine(length - 1).length;
  852. } else {
  853. position.row = Math.max(0, position.row);
  854. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  855. }
  856. return position;
  857. };
  858. this.insertFullLines = function(row, lines) {
  859. row = Math.min(Math.max(row, 0), this.getLength());
  860. var column = 0;
  861. if (row < this.getLength()) {
  862. lines = lines.concat([""]);
  863. column = 0;
  864. } else {
  865. lines = [""].concat(lines);
  866. row--;
  867. column = this.$lines[row].length;
  868. }
  869. this.insertMergedLines({row: row, column: column}, lines);
  870. };
  871. this.insertMergedLines = function(position, lines) {
  872. var start = this.clippedPos(position.row, position.column);
  873. var end = {
  874. row: start.row + lines.length - 1,
  875. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  876. };
  877. this.applyDelta({
  878. start: start,
  879. end: end,
  880. action: "insert",
  881. lines: lines
  882. });
  883. return this.clonePos(end);
  884. };
  885. this.remove = function(range) {
  886. var start = this.clippedPos(range.start.row, range.start.column);
  887. var end = this.clippedPos(range.end.row, range.end.column);
  888. this.applyDelta({
  889. start: start,
  890. end: end,
  891. action: "remove",
  892. lines: this.getLinesForRange({start: start, end: end})
  893. });
  894. return this.clonePos(start);
  895. };
  896. this.removeInLine = function(row, startColumn, endColumn) {
  897. var start = this.clippedPos(row, startColumn);
  898. var end = this.clippedPos(row, endColumn);
  899. this.applyDelta({
  900. start: start,
  901. end: end,
  902. action: "remove",
  903. lines: this.getLinesForRange({start: start, end: end})
  904. }, true);
  905. return this.clonePos(start);
  906. };
  907. this.removeFullLines = function(firstRow, lastRow) {
  908. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  909. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  910. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  911. var deleteLastNewLine = lastRow < this.getLength() - 1;
  912. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  913. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  914. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  915. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  916. var range = new Range(startRow, startCol, endRow, endCol);
  917. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  918. this.applyDelta({
  919. start: range.start,
  920. end: range.end,
  921. action: "remove",
  922. lines: this.getLinesForRange(range)
  923. });
  924. return deletedLines;
  925. };
  926. this.removeNewLine = function(row) {
  927. if (row < this.getLength() - 1 && row >= 0) {
  928. this.applyDelta({
  929. start: this.pos(row, this.getLine(row).length),
  930. end: this.pos(row + 1, 0),
  931. action: "remove",
  932. lines: ["", ""]
  933. });
  934. }
  935. };
  936. this.replace = function(range, text) {
  937. if (!(range instanceof Range))
  938. range = Range.fromPoints(range.start, range.end);
  939. if (text.length === 0 && range.isEmpty())
  940. return range.start;
  941. if (text == this.getTextRange(range))
  942. return range.end;
  943. this.remove(range);
  944. var end;
  945. if (text) {
  946. end = this.insert(range.start, text);
  947. }
  948. else {
  949. end = range.start;
  950. }
  951. return end;
  952. };
  953. this.applyDeltas = function(deltas) {
  954. for (var i=0; i<deltas.length; i++) {
  955. this.applyDelta(deltas[i]);
  956. }
  957. };
  958. this.revertDeltas = function(deltas) {
  959. for (var i=deltas.length-1; i>=0; i--) {
  960. this.revertDelta(deltas[i]);
  961. }
  962. };
  963. this.applyDelta = function(delta, doNotValidate) {
  964. var isInsert = delta.action == "insert";
  965. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  966. : !Range.comparePoints(delta.start, delta.end)) {
  967. return;
  968. }
  969. if (isInsert && delta.lines.length > 20000)
  970. this.$splitAndapplyLargeDelta(delta, 20000);
  971. applyDelta(this.$lines, delta, doNotValidate);
  972. this._signal("change", delta);
  973. };
  974. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  975. var lines = delta.lines;
  976. var l = lines.length;
  977. var row = delta.start.row;
  978. var column = delta.start.column;
  979. var from = 0, to = 0;
  980. do {
  981. from = to;
  982. to += MAX - 1;
  983. var chunk = lines.slice(from, to);
  984. if (to > l) {
  985. delta.lines = chunk;
  986. delta.start.row = row + from;
  987. delta.start.column = column;
  988. break;
  989. }
  990. chunk.push("");
  991. this.applyDelta({
  992. start: this.pos(row + from, column),
  993. end: this.pos(row + to, column = 0),
  994. action: delta.action,
  995. lines: chunk
  996. }, true);
  997. } while(true);
  998. };
  999. this.revertDelta = function(delta) {
  1000. this.applyDelta({
  1001. start: this.clonePos(delta.start),
  1002. end: this.clonePos(delta.end),
  1003. action: (delta.action == "insert" ? "remove" : "insert"),
  1004. lines: delta.lines.slice()
  1005. });
  1006. };
  1007. this.indexToPosition = function(index, startRow) {
  1008. var lines = this.$lines || this.getAllLines();
  1009. var newlineLength = this.getNewLineCharacter().length;
  1010. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1011. index -= lines[i].length + newlineLength;
  1012. if (index < 0)
  1013. return {row: i, column: index + lines[i].length + newlineLength};
  1014. }
  1015. return {row: l-1, column: lines[l-1].length};
  1016. };
  1017. this.positionToIndex = function(pos, startRow) {
  1018. var lines = this.$lines || this.getAllLines();
  1019. var newlineLength = this.getNewLineCharacter().length;
  1020. var index = 0;
  1021. var row = Math.min(pos.row, lines.length);
  1022. for (var i = startRow || 0; i < row; ++i)
  1023. index += lines[i].length + newlineLength;
  1024. return index + pos.column;
  1025. };
  1026. }).call(Document.prototype);
  1027. exports.Document = Document;
  1028. });
  1029. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1030. "use strict";
  1031. exports.last = function(a) {
  1032. return a[a.length - 1];
  1033. };
  1034. exports.stringReverse = function(string) {
  1035. return string.split("").reverse().join("");
  1036. };
  1037. exports.stringRepeat = function (string, count) {
  1038. var result = '';
  1039. while (count > 0) {
  1040. if (count & 1)
  1041. result += string;
  1042. if (count >>= 1)
  1043. string += string;
  1044. }
  1045. return result;
  1046. };
  1047. var trimBeginRegexp = /^\s\s*/;
  1048. var trimEndRegexp = /\s\s*$/;
  1049. exports.stringTrimLeft = function (string) {
  1050. return string.replace(trimBeginRegexp, '');
  1051. };
  1052. exports.stringTrimRight = function (string) {
  1053. return string.replace(trimEndRegexp, '');
  1054. };
  1055. exports.copyObject = function(obj) {
  1056. var copy = {};
  1057. for (var key in obj) {
  1058. copy[key] = obj[key];
  1059. }
  1060. return copy;
  1061. };
  1062. exports.copyArray = function(array){
  1063. var copy = [];
  1064. for (var i=0, l=array.length; i<l; i++) {
  1065. if (array[i] && typeof array[i] == "object")
  1066. copy[i] = this.copyObject(array[i]);
  1067. else
  1068. copy[i] = array[i];
  1069. }
  1070. return copy;
  1071. };
  1072. exports.deepCopy = function deepCopy(obj) {
  1073. if (typeof obj !== "object" || !obj)
  1074. return obj;
  1075. var copy;
  1076. if (Array.isArray(obj)) {
  1077. copy = [];
  1078. for (var key = 0; key < obj.length; key++) {
  1079. copy[key] = deepCopy(obj[key]);
  1080. }
  1081. return copy;
  1082. }
  1083. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1084. return obj;
  1085. copy = {};
  1086. for (var key in obj)
  1087. copy[key] = deepCopy(obj[key]);
  1088. return copy;
  1089. };
  1090. exports.arrayToMap = function(arr) {
  1091. var map = {};
  1092. for (var i=0; i<arr.length; i++) {
  1093. map[arr[i]] = 1;
  1094. }
  1095. return map;
  1096. };
  1097. exports.createMap = function(props) {
  1098. var map = Object.create(null);
  1099. for (var i in props) {
  1100. map[i] = props[i];
  1101. }
  1102. return map;
  1103. };
  1104. exports.arrayRemove = function(array, value) {
  1105. for (var i = 0; i <= array.length; i++) {
  1106. if (value === array[i]) {
  1107. array.splice(i, 1);
  1108. }
  1109. }
  1110. };
  1111. exports.escapeRegExp = function(str) {
  1112. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1113. };
  1114. exports.escapeHTML = function(str) {
  1115. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1116. };
  1117. exports.getMatchOffsets = function(string, regExp) {
  1118. var matches = [];
  1119. string.replace(regExp, function(str) {
  1120. matches.push({
  1121. offset: arguments[arguments.length-2],
  1122. length: str.length
  1123. });
  1124. });
  1125. return matches;
  1126. };
  1127. exports.deferredCall = function(fcn) {
  1128. var timer = null;
  1129. var callback = function() {
  1130. timer = null;
  1131. fcn();
  1132. };
  1133. var deferred = function(timeout) {
  1134. deferred.cancel();
  1135. timer = setTimeout(callback, timeout || 0);
  1136. return deferred;
  1137. };
  1138. deferred.schedule = deferred;
  1139. deferred.call = function() {
  1140. this.cancel();
  1141. fcn();
  1142. return deferred;
  1143. };
  1144. deferred.cancel = function() {
  1145. clearTimeout(timer);
  1146. timer = null;
  1147. return deferred;
  1148. };
  1149. deferred.isPending = function() {
  1150. return timer;
  1151. };
  1152. return deferred;
  1153. };
  1154. exports.delayedCall = function(fcn, defaultTimeout) {
  1155. var timer = null;
  1156. var callback = function() {
  1157. timer = null;
  1158. fcn();
  1159. };
  1160. var _self = function(timeout) {
  1161. if (timer == null)
  1162. timer = setTimeout(callback, timeout || defaultTimeout);
  1163. };
  1164. _self.delay = function(timeout) {
  1165. timer && clearTimeout(timer);
  1166. timer = setTimeout(callback, timeout || defaultTimeout);
  1167. };
  1168. _self.schedule = _self;
  1169. _self.call = function() {
  1170. this.cancel();
  1171. fcn();
  1172. };
  1173. _self.cancel = function() {
  1174. timer && clearTimeout(timer);
  1175. timer = null;
  1176. };
  1177. _self.isPending = function() {
  1178. return timer;
  1179. };
  1180. return _self;
  1181. };
  1182. });
  1183. ace.define("ace/worker/mirror",["require","exports","module","ace/range","ace/document","ace/lib/lang"], function(require, exports, module) {
  1184. "use strict";
  1185. var Range = require("../range").Range;
  1186. var Document = require("../document").Document;
  1187. var lang = require("../lib/lang");
  1188. var Mirror = exports.Mirror = function(sender) {
  1189. this.sender = sender;
  1190. var doc = this.doc = new Document("");
  1191. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1192. var _self = this;
  1193. sender.on("change", function(e) {
  1194. var data = e.data;
  1195. if (data[0].start) {
  1196. doc.applyDeltas(data);
  1197. } else {
  1198. for (var i = 0; i < data.length; i += 2) {
  1199. if (Array.isArray(data[i+1])) {
  1200. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1201. } else {
  1202. var d = {action: "remove", start: data[i], end: data[i+1]};
  1203. }
  1204. doc.applyDelta(d, true);
  1205. }
  1206. }
  1207. if (_self.$timeout)
  1208. return deferredUpdate.schedule(_self.$timeout);
  1209. _self.onUpdate();
  1210. });
  1211. };
  1212. (function() {
  1213. this.$timeout = 500;
  1214. this.setTimeout = function(timeout) {
  1215. this.$timeout = timeout;
  1216. };
  1217. this.setValue = function(value) {
  1218. this.doc.setValue(value);
  1219. this.deferredUpdate.schedule(this.$timeout);
  1220. };
  1221. this.getValue = function(callbackId) {
  1222. this.sender.callback(this.doc.getValue(), callbackId);
  1223. };
  1224. this.onUpdate = function() {
  1225. };
  1226. this.isPending = function() {
  1227. return this.deferredUpdate.isPending();
  1228. };
  1229. }).call(Mirror.prototype);
  1230. });
  1231. ace.define("ace/mode/latex_worker",["require","exports","module","ace/lib/oop","ace/worker/mirror"], function(require, exports, module) {
  1232. "use strict";
  1233. var oop = require("../lib/oop");
  1234. var Mirror = require("../worker/mirror").Mirror;
  1235. var LatexWorker = exports.LatexWorker = function(sender) {
  1236. Mirror.call(this, sender);
  1237. this.setTimeout(500);
  1238. };
  1239. oop.inherits(LatexWorker, Mirror);
  1240. var Parse = function (text) {
  1241. var lines = text.split('\n');
  1242. var state = [], errors = [];
  1243. var i;
  1244. var regex = /^\s*\\(begin|end)\{(\w+\*?)\}/; // keep the regex outside the loop for performance
  1245. for (i = 0; i < lines.length; i++) {
  1246. var line = lines[i];
  1247. var result;
  1248. var error = null;
  1249. regex.lastIndex = 0;
  1250. if ((result = regex.exec(line))) {
  1251. var type = result[1];
  1252. var env = result[2];
  1253. if (type == "begin") {
  1254. state.push({"env":env, "row": i});
  1255. } else if (type == "end") {
  1256. var last_open = state.pop();
  1257. if (last_open && last_open.env == env) {
  1258. } else if (last_open && last_open.env != env) {
  1259. error = {"type":"info", "text": "end " + env + "with begin " + last_open.env, "start_row": last_open.row, "end_row":i };
  1260. } else if (!last_open) {
  1261. error = {"type":"info", "text": "end without begin " + type, "start_row": 0, "end_row": i};
  1262. }
  1263. };
  1264. };
  1265. if (error) {
  1266. errors.push(error);
  1267. };
  1268. };
  1269. if (state.length > 0) {
  1270. for (i = 0; i < state.length; i++) {
  1271. var unclosed = state[i];
  1272. error = {"type":"info", "text": "begin without end " + unclosed.type, "start_row": unclosed.row, "end_row": lines.length-1};
  1273. errors.push(error);
  1274. };
  1275. };
  1276. if (errors.length) {
  1277. return [errors[0]];
  1278. };
  1279. return errors;
  1280. };
  1281. (function() {
  1282. this.onUpdate = function() {
  1283. var value = this.doc.getValue();
  1284. var errors = [];
  1285. try {
  1286. if (value)
  1287. errors = Parse(value);
  1288. } catch (e) {
  1289. console.log("latex worker error",e);
  1290. }
  1291. this.sender.emit("lint", errors);
  1292. };
  1293. }).call(LatexWorker.prototype);
  1294. });
  1295. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  1296. function Empty() {}
  1297. if (!Function.prototype.bind) {
  1298. Function.prototype.bind = function bind(that) { // .length is 1
  1299. var target = this;
  1300. if (typeof target != "function") {
  1301. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  1302. }
  1303. var args = slice.call(arguments, 1); // for normal call
  1304. var bound = function () {
  1305. if (this instanceof bound) {
  1306. var result = target.apply(
  1307. this,
  1308. args.concat(slice.call(arguments))
  1309. );
  1310. if (Object(result) === result) {
  1311. return result;
  1312. }
  1313. return this;
  1314. } else {
  1315. return target.apply(
  1316. that,
  1317. args.concat(slice.call(arguments))
  1318. );
  1319. }
  1320. };
  1321. if(target.prototype) {
  1322. Empty.prototype = target.prototype;
  1323. bound.prototype = new Empty();
  1324. Empty.prototype = null;
  1325. }
  1326. return bound;
  1327. };
  1328. }
  1329. var call = Function.prototype.call;
  1330. var prototypeOfArray = Array.prototype;
  1331. var prototypeOfObject = Object.prototype;
  1332. var slice = prototypeOfArray.slice;
  1333. var _toString = call.bind(prototypeOfObject.toString);
  1334. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  1335. var defineGetter;
  1336. var defineSetter;
  1337. var lookupGetter;
  1338. var lookupSetter;
  1339. var supportsAccessors;
  1340. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  1341. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  1342. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  1343. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  1344. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  1345. }
  1346. if ([1,2].splice(0).length != 2) {
  1347. if(function() { // test IE < 9 to splice bug - see issue #138
  1348. function makeArray(l) {
  1349. var a = new Array(l+2);
  1350. a[0] = a[1] = 0;
  1351. return a;
  1352. }
  1353. var array = [], lengthBefore;
  1354. array.splice.apply(array, makeArray(20));
  1355. array.splice.apply(array, makeArray(26));
  1356. lengthBefore = array.length; //46
  1357. array.splice(5, 0, "XXX"); // add one element
  1358. lengthBefore + 1 == array.length
  1359. if (lengthBefore + 1 == array.length) {
  1360. return true;// has right splice implementation without bugs
  1361. }
  1362. }()) {//IE 6/7
  1363. var array_splice = Array.prototype.splice;
  1364. Array.prototype.splice = function(start, deleteCount) {
  1365. if (!arguments.length) {
  1366. return [];
  1367. } else {
  1368. return array_splice.apply(this, [
  1369. start === void 0 ? 0 : start,
  1370. deleteCount === void 0 ? (this.length - start) : deleteCount
  1371. ].concat(slice.call(arguments, 2)))
  1372. }
  1373. };
  1374. } else {//IE8
  1375. Array.prototype.splice = function(pos, removeCount){
  1376. var length = this.length;
  1377. if (pos > 0) {
  1378. if (pos > length)
  1379. pos = length;
  1380. } else if (pos == void 0) {
  1381. pos = 0;
  1382. } else if (pos < 0) {
  1383. pos = Math.max(length + pos, 0);
  1384. }
  1385. if (!(pos+removeCount < length))
  1386. removeCount = length - pos;
  1387. var removed = this.slice(pos, pos+removeCount);
  1388. var insert = slice.call(arguments, 2);
  1389. var add = insert.length;
  1390. if (pos === length) {
  1391. if (add) {
  1392. this.push.apply(this, insert);
  1393. }
  1394. } else {
  1395. var remove = Math.min(removeCount, length - pos);
  1396. var tailOldPos = pos + remove;
  1397. var tailNewPos = tailOldPos + add - remove;
  1398. var tailCount = length - tailOldPos;
  1399. var lengthAfterRemove = length - remove;
  1400. if (tailNewPos < tailOldPos) { // case A
  1401. for (var i = 0; i < tailCount; ++i) {
  1402. this[tailNewPos+i] = this[tailOldPos+i];
  1403. }
  1404. } else if (tailNewPos > tailOldPos) { // case B
  1405. for (i = tailCount; i--; ) {
  1406. this[tailNewPos+i] = this[tailOldPos+i];
  1407. }
  1408. } // else, add == remove (nothing to do)
  1409. if (add && pos === lengthAfterRemove) {
  1410. this.length = lengthAfterRemove; // truncate array
  1411. this.push.apply(this, insert);
  1412. } else {
  1413. this.length = lengthAfterRemove + add; // reserves space
  1414. for (i = 0; i < add; ++i) {
  1415. this[pos+i] = insert[i];
  1416. }
  1417. }
  1418. }
  1419. return removed;
  1420. };
  1421. }
  1422. }
  1423. if (!Array.isArray) {
  1424. Array.isArray = function isArray(obj) {
  1425. return _toString(obj) == "[object Array]";
  1426. };
  1427. }
  1428. var boxedString = Object("a"),
  1429. splitString = boxedString[0] != "a" || !(0 in boxedString);
  1430. if (!Array.prototype.forEach) {
  1431. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  1432. var object = toObject(this),
  1433. self = splitString && _toString(this) == "[object String]" ?
  1434. this.split("") :
  1435. object,
  1436. thisp = arguments[1],
  1437. i = -1,
  1438. length = self.length >>> 0;
  1439. if (_toString(fun) != "[object Function]") {
  1440. throw new TypeError(); // TODO message
  1441. }
  1442. while (++i < length) {
  1443. if (i in self) {
  1444. fun.call(thisp, self[i], i, object);
  1445. }
  1446. }
  1447. };
  1448. }
  1449. if (!Array.prototype.map) {
  1450. Array.prototype.map = function map(fun /*, thisp*/) {
  1451. var object = toObject(this),
  1452. self = splitString && _toString(this) == "[object String]" ?
  1453. this.split("") :
  1454. object,
  1455. length = self.length >>> 0,
  1456. result = Array(length),
  1457. thisp = arguments[1];
  1458. if (_toString(fun) != "[object Function]") {
  1459. throw new TypeError(fun + " is not a function");
  1460. }
  1461. for (var i = 0; i < length; i++) {
  1462. if (i in self)
  1463. result[i] = fun.call(thisp, self[i], i, object);
  1464. }
  1465. return result;
  1466. };
  1467. }
  1468. if (!Array.prototype.filter) {
  1469. Array.prototype.filter = function filter(fun /*, thisp */) {
  1470. var object = toObject(this),
  1471. self = splitString && _toString(this) == "[object String]" ?
  1472. this.split("") :
  1473. object,
  1474. length = self.length >>> 0,
  1475. result = [],
  1476. value,
  1477. thisp = arguments[1];
  1478. if (_toString(fun) != "[object Function]") {
  1479. throw new TypeError(fun + " is not a function");
  1480. }
  1481. for (var i = 0; i < length; i++) {
  1482. if (i in self) {
  1483. value = self[i];
  1484. if (fun.call(thisp, value, i, object)) {
  1485. result.push(value);
  1486. }
  1487. }
  1488. }
  1489. return result;
  1490. };
  1491. }
  1492. if (!Array.prototype.every) {
  1493. Array.prototype.every = function every(fun /*, thisp */) {
  1494. var object = toObject(this),
  1495. self = splitString && _toString(this) == "[object String]" ?
  1496. this.split("") :
  1497. object,
  1498. length = self.length >>> 0,
  1499. thisp = arguments[1];
  1500. if (_toString(fun) != "[object Function]") {
  1501. throw new TypeError(fun + " is not a function");
  1502. }
  1503. for (var i = 0; i < length; i++) {
  1504. if (i in self && !fun.call(thisp, self[i], i, object)) {
  1505. return false;
  1506. }
  1507. }
  1508. return true;
  1509. };
  1510. }
  1511. if (!Array.prototype.some) {
  1512. Array.prototype.some = function some(fun /*, thisp */) {
  1513. var object = toObject(this),
  1514. self = splitString && _toString(this) == "[object String]" ?
  1515. this.split("") :
  1516. object,
  1517. length = self.length >>> 0,
  1518. thisp = arguments[1];
  1519. if (_toString(fun) != "[object Function]") {
  1520. throw new TypeError(fun + " is not a function");
  1521. }
  1522. for (var i = 0; i < length; i++) {
  1523. if (i in self && fun.call(thisp, self[i], i, object)) {
  1524. return true;
  1525. }
  1526. }
  1527. return false;
  1528. };
  1529. }
  1530. if (!Array.prototype.reduce) {
  1531. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  1532. var object = toObject(this),
  1533. self = splitString && _toString(this) == "[object String]" ?
  1534. this.split("") :
  1535. object,
  1536. length = self.length >>> 0;
  1537. if (_toString(fun) != "[object Function]") {
  1538. throw new TypeError(fun + " is not a function");
  1539. }
  1540. if (!length && arguments.length == 1) {
  1541. throw new TypeError("reduce of empty array with no initial value");
  1542. }
  1543. var i = 0;
  1544. var result;
  1545. if (arguments.length >= 2) {
  1546. result = arguments[1];
  1547. } else {
  1548. do {
  1549. if (i in self) {
  1550. result = self[i++];
  1551. break;
  1552. }
  1553. if (++i >= length) {
  1554. throw new TypeError("reduce of empty array with no initial value");
  1555. }
  1556. } while (true);
  1557. }
  1558. for (; i < length; i++) {
  1559. if (i in self) {
  1560. result = fun.call(void 0, result, self[i], i, object);
  1561. }
  1562. }
  1563. return result;
  1564. };
  1565. }
  1566. if (!Array.prototype.reduceRight) {
  1567. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  1568. var object = toObject(this),
  1569. self = splitString && _toString(this) == "[object String]" ?
  1570. this.split("") :
  1571. object,
  1572. length = self.length >>> 0;
  1573. if (_toString(fun) != "[object Function]") {
  1574. throw new TypeError(fun + " is not a function");
  1575. }
  1576. if (!length && arguments.length == 1) {
  1577. throw new TypeError("reduceRight of empty array with no initial value");
  1578. }
  1579. var result, i = length - 1;
  1580. if (arguments.length >= 2) {
  1581. result = arguments[1];
  1582. } else {
  1583. do {
  1584. if (i in self) {
  1585. result = self[i--];
  1586. break;
  1587. }
  1588. if (--i < 0) {
  1589. throw new TypeError("reduceRight of empty array with no initial value");
  1590. }
  1591. } while (true);
  1592. }
  1593. do {
  1594. if (i in this) {
  1595. result = fun.call(void 0, result, self[i], i, object);
  1596. }
  1597. } while (i--);
  1598. return result;
  1599. };
  1600. }
  1601. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  1602. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  1603. var self = splitString && _toString(this) == "[object String]" ?
  1604. this.split("") :
  1605. toObject(this),
  1606. length = self.length >>> 0;
  1607. if (!length) {
  1608. return -1;
  1609. }
  1610. var i = 0;
  1611. if (arguments.length > 1) {
  1612. i = toInteger(arguments[1]);
  1613. }
  1614. i = i >= 0 ? i : Math.max(0, length + i);
  1615. for (; i < length; i++) {
  1616. if (i in self && self[i] === sought) {
  1617. return i;
  1618. }
  1619. }
  1620. return -1;
  1621. };
  1622. }
  1623. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  1624. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  1625. var self = splitString && _toString(this) == "[object String]" ?
  1626. this.split("") :
  1627. toObject(this),
  1628. length = self.length >>> 0;
  1629. if (!length) {
  1630. return -1;
  1631. }
  1632. var i = length - 1;
  1633. if (arguments.length > 1) {
  1634. i = Math.min(i, toInteger(arguments[1]));
  1635. }
  1636. i = i >= 0 ? i : length - Math.abs(i);
  1637. for (; i >= 0; i--) {
  1638. if (i in self && sought === self[i]) {
  1639. return i;
  1640. }
  1641. }
  1642. return -1;
  1643. };
  1644. }
  1645. if (!Object.getPrototypeOf) {
  1646. Object.getPrototypeOf = function getPrototypeOf(object) {
  1647. return object.__proto__ || (
  1648. object.constructor ?
  1649. object.constructor.prototype :
  1650. prototypeOfObject
  1651. );
  1652. };
  1653. }
  1654. if (!Object.getOwnPropertyDescriptor) {
  1655. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  1656. "non-object: ";
  1657. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  1658. if ((typeof object != "object" && typeof object != "function") || object === null)
  1659. throw new TypeError(ERR_NON_OBJECT + object);
  1660. if (!owns(object, property))
  1661. return;
  1662. var descriptor, getter, setter;
  1663. descriptor = { enumerable: true, configurable: true };
  1664. if (supportsAccessors) {
  1665. var prototype = object.__proto__;
  1666. object.__proto__ = prototypeOfObject;
  1667. var getter = lookupGetter(object, property);
  1668. var setter = lookupSetter(object, property);
  1669. object.__proto__ = prototype;
  1670. if (getter || setter) {
  1671. if (getter) descriptor.get = getter;
  1672. if (setter) descriptor.set = setter;
  1673. return descriptor;
  1674. }
  1675. }
  1676. descriptor.value = object[property];
  1677. return descriptor;
  1678. };
  1679. }
  1680. if (!Object.getOwnPropertyNames) {
  1681. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  1682. return Object.keys(object);
  1683. };
  1684. }
  1685. if (!Object.create) {
  1686. var createEmpty;
  1687. if (Object.prototype.__proto__ === null) {
  1688. createEmpty = function () {
  1689. return { "__proto__": null };
  1690. };
  1691. } else {
  1692. createEmpty = function () {
  1693. var empty = {};
  1694. for (var i in empty)
  1695. empty[i] = null;
  1696. empty.constructor =
  1697. empty.hasOwnProperty =
  1698. empty.propertyIsEnumerable =
  1699. empty.isPrototypeOf =
  1700. empty.toLocaleString =
  1701. empty.toString =
  1702. empty.valueOf =
  1703. empty.__proto__ = null;
  1704. return empty;
  1705. }
  1706. }
  1707. Object.create = function create(prototype, properties) {
  1708. var object;
  1709. if (prototype === null) {
  1710. object = createEmpty();
  1711. } else {
  1712. if (typeof prototype != "object")
  1713. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  1714. var Type = function () {};
  1715. Type.prototype = prototype;
  1716. object = new Type();
  1717. object.__proto__ = prototype;
  1718. }
  1719. if (properties !== void 0)
  1720. Object.defineProperties(object, properties);
  1721. return object;
  1722. };
  1723. }
  1724. function doesDefinePropertyWork(object) {
  1725. try {
  1726. Object.defineProperty(object, "sentinel", {});
  1727. return "sentinel" in object;
  1728. } catch (exception) {
  1729. }
  1730. }
  1731. if (Object.defineProperty) {
  1732. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  1733. var definePropertyWorksOnDom = typeof document == "undefined" ||
  1734. doesDefinePropertyWork(document.createElement("div"));
  1735. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  1736. var definePropertyFallback = Object.defineProperty;
  1737. }
  1738. }
  1739. if (!Object.defineProperty || definePropertyFallback) {
  1740. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  1741. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  1742. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  1743. "on this javascript engine";
  1744. Object.defineProperty = function defineProperty(object, property, descriptor) {
  1745. if ((typeof object != "object" && typeof object != "function") || object === null)
  1746. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  1747. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  1748. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  1749. if (definePropertyFallback) {
  1750. try {
  1751. return definePropertyFallback.call(Object, object, property, descriptor);
  1752. } catch (exception) {
  1753. }
  1754. }
  1755. if (owns(descriptor, "value")) {
  1756. if (supportsAccessors && (lookupGetter(object, property) ||
  1757. lookupSetter(object, property)))
  1758. {
  1759. var prototype = object.__proto__;
  1760. object.__proto__ = prototypeOfObject;
  1761. delete object[property];
  1762. object[property] = descriptor.value;
  1763. object.__proto__ = prototype;
  1764. } else {
  1765. object[property] = descriptor.value;
  1766. }
  1767. } else {
  1768. if (!supportsAccessors)
  1769. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  1770. if (owns(descriptor, "get"))
  1771. defineGetter(object, property, descriptor.get);
  1772. if (owns(descriptor, "set"))
  1773. defineSetter(object, property, descriptor.set);
  1774. }
  1775. return object;
  1776. };
  1777. }
  1778. if (!Object.defineProperties) {
  1779. Object.defineProperties = function defineProperties(object, properties) {
  1780. for (var property in properties) {
  1781. if (owns(properties, property))
  1782. Object.defineProperty(object, property, properties[property]);
  1783. }
  1784. return object;
  1785. };
  1786. }
  1787. if (!Object.seal) {
  1788. Object.seal = function seal(object) {
  1789. return object;
  1790. };
  1791. }
  1792. if (!Object.freeze) {
  1793. Object.freeze = function freeze(object) {
  1794. return object;
  1795. };
  1796. }
  1797. try {
  1798. Object.freeze(function () {});
  1799. } catch (exception) {
  1800. Object.freeze = (function freeze(freezeObject) {
  1801. return function freeze(object) {
  1802. if (typeof object == "function") {
  1803. return object;
  1804. } else {
  1805. return freezeObject(object);
  1806. }
  1807. };
  1808. })(Object.freeze);
  1809. }
  1810. if (!Object.preventExtensions) {
  1811. Object.preventExtensions = function preventExtensions(object) {
  1812. return object;
  1813. };
  1814. }
  1815. if (!Object.isSealed) {
  1816. Object.isSealed = function isSealed(object) {
  1817. return false;
  1818. };
  1819. }
  1820. if (!Object.isFrozen) {
  1821. Object.isFrozen = function isFrozen(object) {
  1822. return false;
  1823. };
  1824. }
  1825. if (!Object.isExtensible) {
  1826. Object.isExtensible = function isExtensible(object) {
  1827. if (Object(object) === object) {
  1828. throw new TypeError(); // TODO message
  1829. }
  1830. var name = '';
  1831. while (owns(object, name)) {
  1832. name += '?';
  1833. }
  1834. object[name] = true;
  1835. var returnValue = owns(object, name);
  1836. delete object[name];
  1837. return returnValue;
  1838. };
  1839. }
  1840. if (!Object.keys) {
  1841. var hasDontEnumBug = true,
  1842. dontEnums = [
  1843. "toString",
  1844. "toLocaleString",
  1845. "valueOf",
  1846. "hasOwnProperty",
  1847. "isPrototypeOf",
  1848. "propertyIsEnumerable",
  1849. "constructor"
  1850. ],
  1851. dontEnumsLength = dontEnums.length;
  1852. for (var key in {"toString": null}) {
  1853. hasDontEnumBug = false;
  1854. }
  1855. Object.keys = function keys(object) {
  1856. if (
  1857. (typeof object != "object" && typeof object != "function") ||
  1858. object === null
  1859. ) {
  1860. throw new TypeError("Object.keys called on a non-object");
  1861. }
  1862. var keys = [];
  1863. for (var name in object) {
  1864. if (owns(object, name)) {
  1865. keys.push(name);
  1866. }
  1867. }
  1868. if (hasDontEnumBug) {
  1869. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  1870. var dontEnum = dontEnums[i];
  1871. if (owns(object, dontEnum)) {
  1872. keys.push(dontEnum);
  1873. }
  1874. }
  1875. }
  1876. return keys;
  1877. };
  1878. }
  1879. if (!Date.now) {
  1880. Date.now = function now() {
  1881. return new Date().getTime();
  1882. };
  1883. }
  1884. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  1885. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  1886. "\u2029\uFEFF";
  1887. if (!String.prototype.trim || ws.trim()) {
  1888. ws = "[" + ws + "]";
  1889. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  1890. trimEndRegexp = new RegExp(ws + ws + "*$");
  1891. String.prototype.trim = function trim() {
  1892. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  1893. };
  1894. }
  1895. function toInteger(n) {
  1896. n = +n;
  1897. if (n !== n) { // isNaN
  1898. n = 0;
  1899. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  1900. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  1901. }
  1902. return n;
  1903. }
  1904. function isPrimitive(input) {
  1905. var type = typeof input;
  1906. return (
  1907. input === null ||
  1908. type === "undefined" ||
  1909. type === "boolean" ||
  1910. type === "number" ||
  1911. type === "string"
  1912. );
  1913. }
  1914. function toPrimitive(input) {
  1915. var val, valueOf, toString;
  1916. if (isPrimitive(input)) {
  1917. return input;
  1918. }
  1919. valueOf = input.valueOf;
  1920. if (typeof valueOf === "function") {
  1921. val = valueOf.call(input);
  1922. if (isPrimitive(val)) {
  1923. return val;
  1924. }
  1925. }
  1926. toString = input.toString;
  1927. if (typeof toString === "function") {
  1928. val = toString.call(input);
  1929. if (isPrimitive(val)) {
  1930. return val;
  1931. }
  1932. }
  1933. throw new TypeError();
  1934. }
  1935. var toObject = function (o) {
  1936. if (o == null) { // this matches both null and undefined
  1937. throw new TypeError("can't convert "+o+" to object");
  1938. }
  1939. return Object(o);
  1940. };
  1941. });