182aa449781ff6997bc12b8eb3611ccb.js 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122
  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/lib/deep_copy",[], function(require, exports, module){exports.deepCopy = function deepCopy(obj) {
  214. if (typeof obj !== "object" || !obj)
  215. return obj;
  216. var copy;
  217. if (Array.isArray(obj)) {
  218. copy = [];
  219. for (var key = 0; key < obj.length; key++) {
  220. copy[key] = deepCopy(obj[key]);
  221. }
  222. return copy;
  223. }
  224. if (Object.prototype.toString.call(obj) !== "[object Object]")
  225. return obj;
  226. copy = {};
  227. for (var key in obj)
  228. copy[key] = deepCopy(obj[key]);
  229. return copy;
  230. };
  231. });
  232. ace.define("ace/lib/lang",[], function(require, exports, module){"use strict";
  233. exports.last = function (a) {
  234. return a[a.length - 1];
  235. };
  236. exports.stringReverse = function (string) {
  237. return string.split("").reverse().join("");
  238. };
  239. exports.stringRepeat = function (string, count) {
  240. var result = '';
  241. while (count > 0) {
  242. if (count & 1)
  243. result += string;
  244. if (count >>= 1)
  245. string += string;
  246. }
  247. return result;
  248. };
  249. var trimBeginRegexp = /^\s\s*/;
  250. var trimEndRegexp = /\s\s*$/;
  251. exports.stringTrimLeft = function (string) {
  252. return string.replace(trimBeginRegexp, '');
  253. };
  254. exports.stringTrimRight = function (string) {
  255. return string.replace(trimEndRegexp, '');
  256. };
  257. exports.copyObject = function (obj) {
  258. var copy = {};
  259. for (var key in obj) {
  260. copy[key] = obj[key];
  261. }
  262. return copy;
  263. };
  264. exports.copyArray = function (array) {
  265. var copy = [];
  266. for (var i = 0, l = array.length; i < l; i++) {
  267. if (array[i] && typeof array[i] == "object")
  268. copy[i] = this.copyObject(array[i]);
  269. else
  270. copy[i] = array[i];
  271. }
  272. return copy;
  273. };
  274. exports.deepCopy = require("./deep_copy").deepCopy;
  275. exports.arrayToMap = function (arr) {
  276. var map = {};
  277. for (var i = 0; i < arr.length; i++) {
  278. map[arr[i]] = 1;
  279. }
  280. return map;
  281. };
  282. exports.createMap = function (props) {
  283. var map = Object.create(null);
  284. for (var i in props) {
  285. map[i] = props[i];
  286. }
  287. return map;
  288. };
  289. exports.arrayRemove = function (array, value) {
  290. for (var i = 0; i <= array.length; i++) {
  291. if (value === array[i]) {
  292. array.splice(i, 1);
  293. }
  294. }
  295. };
  296. exports.escapeRegExp = function (str) {
  297. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  298. };
  299. exports.escapeHTML = function (str) {
  300. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  301. };
  302. exports.getMatchOffsets = function (string, regExp) {
  303. var matches = [];
  304. string.replace(regExp, function (str) {
  305. matches.push({
  306. offset: arguments[arguments.length - 2],
  307. length: str.length
  308. });
  309. });
  310. return matches;
  311. };
  312. exports.deferredCall = function (fcn) {
  313. var timer = null;
  314. var callback = function () {
  315. timer = null;
  316. fcn();
  317. };
  318. var deferred = function (timeout) {
  319. deferred.cancel();
  320. timer = setTimeout(callback, timeout || 0);
  321. return deferred;
  322. };
  323. deferred.schedule = deferred;
  324. deferred.call = function () {
  325. this.cancel();
  326. fcn();
  327. return deferred;
  328. };
  329. deferred.cancel = function () {
  330. clearTimeout(timer);
  331. timer = null;
  332. return deferred;
  333. };
  334. deferred.isPending = function () {
  335. return timer;
  336. };
  337. return deferred;
  338. };
  339. exports.delayedCall = function (fcn, defaultTimeout) {
  340. var timer = null;
  341. var callback = function () {
  342. timer = null;
  343. fcn();
  344. };
  345. var _self = function (timeout) {
  346. if (timer == null)
  347. timer = setTimeout(callback, timeout || defaultTimeout);
  348. };
  349. _self.delay = function (timeout) {
  350. timer && clearTimeout(timer);
  351. timer = setTimeout(callback, timeout || defaultTimeout);
  352. };
  353. _self.schedule = _self;
  354. _self.call = function () {
  355. this.cancel();
  356. fcn();
  357. };
  358. _self.cancel = function () {
  359. timer && clearTimeout(timer);
  360. timer = null;
  361. };
  362. _self.isPending = function () {
  363. return timer;
  364. };
  365. return _self;
  366. };
  367. exports.supportsLookbehind = function () {
  368. try {
  369. new RegExp('(?<=.)');
  370. }
  371. catch (e) {
  372. return false;
  373. }
  374. return true;
  375. };
  376. exports.skipEmptyMatch = function (line, last, supportsUnicodeFlag) {
  377. return supportsUnicodeFlag && line.codePointAt(last) > 0xffff ? 2 : 1;
  378. };
  379. });
  380. ace.define("ace/apply_delta",[], function(require, exports, module){"use strict";
  381. function throwDeltaError(delta, errorText) {
  382. console.log("Invalid Delta:", delta);
  383. throw "Invalid Delta: " + errorText;
  384. }
  385. function positionInDocument(docLines, position) {
  386. return position.row >= 0 && position.row < docLines.length &&
  387. position.column >= 0 && position.column <= docLines[position.row].length;
  388. }
  389. function validateDelta(docLines, delta) {
  390. if (delta.action != "insert" && delta.action != "remove")
  391. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  392. if (!(delta.lines instanceof Array))
  393. throwDeltaError(delta, "delta.lines must be an Array");
  394. if (!delta.start || !delta.end)
  395. throwDeltaError(delta, "delta.start/end must be an present");
  396. var start = delta.start;
  397. if (!positionInDocument(docLines, delta.start))
  398. throwDeltaError(delta, "delta.start must be contained in document");
  399. var end = delta.end;
  400. if (delta.action == "remove" && !positionInDocument(docLines, end))
  401. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  402. var numRangeRows = end.row - start.row;
  403. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  404. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  405. throwDeltaError(delta, "delta.range must match delta lines");
  406. }
  407. exports.applyDelta = function (docLines, delta, doNotValidate) {
  408. var row = delta.start.row;
  409. var startColumn = delta.start.column;
  410. var line = docLines[row] || "";
  411. switch (delta.action) {
  412. case "insert":
  413. var lines = delta.lines;
  414. if (lines.length === 1) {
  415. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  416. }
  417. else {
  418. var args = [row, 1].concat(delta.lines);
  419. docLines.splice.apply(docLines, args);
  420. docLines[row] = line.substring(0, startColumn) + docLines[row];
  421. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  422. }
  423. break;
  424. case "remove":
  425. var endColumn = delta.end.column;
  426. var endRow = delta.end.row;
  427. if (row === endRow) {
  428. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  429. }
  430. else {
  431. docLines.splice(row, endRow - row + 1, line.substring(0, startColumn) + docLines[endRow].substring(endColumn));
  432. }
  433. break;
  434. }
  435. };
  436. });
  437. ace.define("ace/lib/event_emitter",[], function(require, exports, module){"use strict";
  438. var EventEmitter = {};
  439. var stopPropagation = function () { this.propagationStopped = true; };
  440. var preventDefault = function () { this.defaultPrevented = true; };
  441. EventEmitter._emit =
  442. EventEmitter._dispatchEvent = function (eventName, e) {
  443. this._eventRegistry || (this._eventRegistry = {});
  444. this._defaultHandlers || (this._defaultHandlers = {});
  445. var listeners = this._eventRegistry[eventName] || [];
  446. var defaultHandler = this._defaultHandlers[eventName];
  447. if (!listeners.length && !defaultHandler)
  448. return;
  449. if (typeof e != "object" || !e)
  450. e = {};
  451. if (!e.type)
  452. e.type = eventName;
  453. if (!e.stopPropagation)
  454. e.stopPropagation = stopPropagation;
  455. if (!e.preventDefault)
  456. e.preventDefault = preventDefault;
  457. listeners = listeners.slice();
  458. for (var i = 0; i < listeners.length; i++) {
  459. listeners[i](e, this);
  460. if (e.propagationStopped)
  461. break;
  462. }
  463. if (defaultHandler && !e.defaultPrevented)
  464. return defaultHandler(e, this);
  465. };
  466. EventEmitter._signal = function (eventName, e) {
  467. var listeners = (this._eventRegistry || {})[eventName];
  468. if (!listeners)
  469. return;
  470. listeners = listeners.slice();
  471. for (var i = 0; i < listeners.length; i++)
  472. listeners[i](e, this);
  473. };
  474. EventEmitter.once = function (eventName, callback) {
  475. var _self = this;
  476. this.on(eventName, function newCallback() {
  477. _self.off(eventName, newCallback);
  478. callback.apply(null, arguments);
  479. });
  480. if (!callback) {
  481. return new Promise(function (resolve) {
  482. callback = resolve;
  483. });
  484. }
  485. };
  486. EventEmitter.setDefaultHandler = function (eventName, callback) {
  487. var handlers = this._defaultHandlers;
  488. if (!handlers)
  489. handlers = this._defaultHandlers = { _disabled_: {} };
  490. if (handlers[eventName]) {
  491. var old = handlers[eventName];
  492. var disabled = handlers._disabled_[eventName];
  493. if (!disabled)
  494. handlers._disabled_[eventName] = disabled = [];
  495. disabled.push(old);
  496. var i = disabled.indexOf(callback);
  497. if (i != -1)
  498. disabled.splice(i, 1);
  499. }
  500. handlers[eventName] = callback;
  501. };
  502. EventEmitter.removeDefaultHandler = function (eventName, callback) {
  503. var handlers = this._defaultHandlers;
  504. if (!handlers)
  505. return;
  506. var disabled = handlers._disabled_[eventName];
  507. if (handlers[eventName] == callback) {
  508. if (disabled)
  509. this.setDefaultHandler(eventName, disabled.pop());
  510. }
  511. else if (disabled) {
  512. var i = disabled.indexOf(callback);
  513. if (i != -1)
  514. disabled.splice(i, 1);
  515. }
  516. };
  517. EventEmitter.on =
  518. EventEmitter.addEventListener = function (eventName, callback, capturing) {
  519. this._eventRegistry = this._eventRegistry || {};
  520. var listeners = this._eventRegistry[eventName];
  521. if (!listeners)
  522. listeners = this._eventRegistry[eventName] = [];
  523. if (listeners.indexOf(callback) == -1)
  524. listeners[capturing ? "unshift" : "push"](callback);
  525. return callback;
  526. };
  527. EventEmitter.off =
  528. EventEmitter.removeListener =
  529. EventEmitter.removeEventListener = function (eventName, callback) {
  530. this._eventRegistry = this._eventRegistry || {};
  531. var listeners = this._eventRegistry[eventName];
  532. if (!listeners)
  533. return;
  534. var index = listeners.indexOf(callback);
  535. if (index !== -1)
  536. listeners.splice(index, 1);
  537. };
  538. EventEmitter.removeAllListeners = function (eventName) {
  539. if (!eventName)
  540. this._eventRegistry = this._defaultHandlers = undefined;
  541. if (this._eventRegistry)
  542. this._eventRegistry[eventName] = undefined;
  543. if (this._defaultHandlers)
  544. this._defaultHandlers[eventName] = undefined;
  545. };
  546. exports.EventEmitter = EventEmitter;
  547. });
  548. ace.define("ace/range",[], function(require, exports, module){"use strict";
  549. var Range = /** @class */ (function () {
  550. function Range(startRow, startColumn, endRow, endColumn) {
  551. this.start = {
  552. row: startRow,
  553. column: startColumn
  554. };
  555. this.end = {
  556. row: endRow,
  557. column: endColumn
  558. };
  559. }
  560. Range.prototype.isEqual = function (range) {
  561. return this.start.row === range.start.row &&
  562. this.end.row === range.end.row &&
  563. this.start.column === range.start.column &&
  564. this.end.column === range.end.column;
  565. };
  566. Range.prototype.toString = function () {
  567. return ("Range: [" + this.start.row + "/" + this.start.column +
  568. "] -> [" + this.end.row + "/" + this.end.column + "]");
  569. };
  570. Range.prototype.contains = function (row, column) {
  571. return this.compare(row, column) == 0;
  572. };
  573. Range.prototype.compareRange = function (range) {
  574. var cmp, end = range.end, start = range.start;
  575. cmp = this.compare(end.row, end.column);
  576. if (cmp == 1) {
  577. cmp = this.compare(start.row, start.column);
  578. if (cmp == 1) {
  579. return 2;
  580. }
  581. else if (cmp == 0) {
  582. return 1;
  583. }
  584. else {
  585. return 0;
  586. }
  587. }
  588. else if (cmp == -1) {
  589. return -2;
  590. }
  591. else {
  592. cmp = this.compare(start.row, start.column);
  593. if (cmp == -1) {
  594. return -1;
  595. }
  596. else if (cmp == 1) {
  597. return 42;
  598. }
  599. else {
  600. return 0;
  601. }
  602. }
  603. };
  604. Range.prototype.comparePoint = function (p) {
  605. return this.compare(p.row, p.column);
  606. };
  607. Range.prototype.containsRange = function (range) {
  608. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  609. };
  610. Range.prototype.intersects = function (range) {
  611. var cmp = this.compareRange(range);
  612. return (cmp == -1 || cmp == 0 || cmp == 1);
  613. };
  614. Range.prototype.isEnd = function (row, column) {
  615. return this.end.row == row && this.end.column == column;
  616. };
  617. Range.prototype.isStart = function (row, column) {
  618. return this.start.row == row && this.start.column == column;
  619. };
  620. Range.prototype.setStart = function (row, column) {
  621. if (typeof row == "object") {
  622. this.start.column = row.column;
  623. this.start.row = row.row;
  624. }
  625. else {
  626. this.start.row = row;
  627. this.start.column = column;
  628. }
  629. };
  630. Range.prototype.setEnd = function (row, column) {
  631. if (typeof row == "object") {
  632. this.end.column = row.column;
  633. this.end.row = row.row;
  634. }
  635. else {
  636. this.end.row = row;
  637. this.end.column = column;
  638. }
  639. };
  640. Range.prototype.inside = function (row, column) {
  641. if (this.compare(row, column) == 0) {
  642. if (this.isEnd(row, column) || this.isStart(row, column)) {
  643. return false;
  644. }
  645. else {
  646. return true;
  647. }
  648. }
  649. return false;
  650. };
  651. Range.prototype.insideStart = function (row, column) {
  652. if (this.compare(row, column) == 0) {
  653. if (this.isEnd(row, column)) {
  654. return false;
  655. }
  656. else {
  657. return true;
  658. }
  659. }
  660. return false;
  661. };
  662. Range.prototype.insideEnd = function (row, column) {
  663. if (this.compare(row, column) == 0) {
  664. if (this.isStart(row, column)) {
  665. return false;
  666. }
  667. else {
  668. return true;
  669. }
  670. }
  671. return false;
  672. };
  673. Range.prototype.compare = function (row, column) {
  674. if (!this.isMultiLine()) {
  675. if (row === this.start.row) {
  676. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  677. }
  678. }
  679. if (row < this.start.row)
  680. return -1;
  681. if (row > this.end.row)
  682. return 1;
  683. if (this.start.row === row)
  684. return column >= this.start.column ? 0 : -1;
  685. if (this.end.row === row)
  686. return column <= this.end.column ? 0 : 1;
  687. return 0;
  688. };
  689. Range.prototype.compareStart = function (row, column) {
  690. if (this.start.row == row && this.start.column == column) {
  691. return -1;
  692. }
  693. else {
  694. return this.compare(row, column);
  695. }
  696. };
  697. Range.prototype.compareEnd = function (row, column) {
  698. if (this.end.row == row && this.end.column == column) {
  699. return 1;
  700. }
  701. else {
  702. return this.compare(row, column);
  703. }
  704. };
  705. Range.prototype.compareInside = function (row, column) {
  706. if (this.end.row == row && this.end.column == column) {
  707. return 1;
  708. }
  709. else if (this.start.row == row && this.start.column == column) {
  710. return -1;
  711. }
  712. else {
  713. return this.compare(row, column);
  714. }
  715. };
  716. Range.prototype.clipRows = function (firstRow, lastRow) {
  717. if (this.end.row > lastRow)
  718. var end = { row: lastRow + 1, column: 0 };
  719. else if (this.end.row < firstRow)
  720. var end = { row: firstRow, column: 0 };
  721. if (this.start.row > lastRow)
  722. var start = { row: lastRow + 1, column: 0 };
  723. else if (this.start.row < firstRow)
  724. var start = { row: firstRow, column: 0 };
  725. return Range.fromPoints(start || this.start, end || this.end);
  726. };
  727. Range.prototype.extend = function (row, column) {
  728. var cmp = this.compare(row, column);
  729. if (cmp == 0)
  730. return this;
  731. else if (cmp == -1)
  732. var start = { row: row, column: column };
  733. else
  734. var end = { row: row, column: column };
  735. return Range.fromPoints(start || this.start, end || this.end);
  736. };
  737. Range.prototype.isEmpty = function () {
  738. return (this.start.row === this.end.row && this.start.column === this.end.column);
  739. };
  740. Range.prototype.isMultiLine = function () {
  741. return (this.start.row !== this.end.row);
  742. };
  743. Range.prototype.clone = function () {
  744. return Range.fromPoints(this.start, this.end);
  745. };
  746. Range.prototype.collapseRows = function () {
  747. if (this.end.column == 0)
  748. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row - 1), 0);
  749. else
  750. return new Range(this.start.row, 0, this.end.row, 0);
  751. };
  752. Range.prototype.toScreenRange = function (session) {
  753. var screenPosStart = session.documentToScreenPosition(this.start);
  754. var screenPosEnd = session.documentToScreenPosition(this.end);
  755. return new Range(screenPosStart.row, screenPosStart.column, screenPosEnd.row, screenPosEnd.column);
  756. };
  757. Range.prototype.moveBy = function (row, column) {
  758. this.start.row += row;
  759. this.start.column += column;
  760. this.end.row += row;
  761. this.end.column += column;
  762. };
  763. return Range;
  764. }());
  765. Range.fromPoints = function (start, end) {
  766. return new Range(start.row, start.column, end.row, end.column);
  767. };
  768. Range.comparePoints = function (p1, p2) {
  769. return p1.row - p2.row || p1.column - p2.column;
  770. };
  771. exports.Range = Range;
  772. });
  773. ace.define("ace/anchor",[], function(require, exports, module){"use strict";
  774. var oop = require("./lib/oop");
  775. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  776. var Anchor = /** @class */ (function () {
  777. function Anchor(doc, row, column) {
  778. this.$onChange = this.onChange.bind(this);
  779. this.attach(doc);
  780. if (typeof row != "number")
  781. this.setPosition(row.row, row.column);
  782. else
  783. this.setPosition(row, column);
  784. }
  785. Anchor.prototype.getPosition = function () {
  786. return this.$clipPositionToDocument(this.row, this.column);
  787. };
  788. Anchor.prototype.getDocument = function () {
  789. return this.document;
  790. };
  791. Anchor.prototype.onChange = function (delta) {
  792. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  793. return;
  794. if (delta.start.row > this.row)
  795. return;
  796. var point = $getTransformedPoint(delta, { row: this.row, column: this.column }, this.$insertRight);
  797. this.setPosition(point.row, point.column, true);
  798. };
  799. Anchor.prototype.setPosition = function (row, column, noClip) {
  800. var pos;
  801. if (noClip) {
  802. pos = {
  803. row: row,
  804. column: column
  805. };
  806. }
  807. else {
  808. pos = this.$clipPositionToDocument(row, column);
  809. }
  810. if (this.row == pos.row && this.column == pos.column)
  811. return;
  812. var old = {
  813. row: this.row,
  814. column: this.column
  815. };
  816. this.row = pos.row;
  817. this.column = pos.column;
  818. this._signal("change", {
  819. old: old,
  820. value: pos
  821. });
  822. };
  823. Anchor.prototype.detach = function () {
  824. this.document.off("change", this.$onChange);
  825. };
  826. Anchor.prototype.attach = function (doc) {
  827. this.document = doc || this.document;
  828. this.document.on("change", this.$onChange);
  829. };
  830. Anchor.prototype.$clipPositionToDocument = function (row, column) {
  831. var pos = {};
  832. if (row >= this.document.getLength()) {
  833. pos.row = Math.max(0, this.document.getLength() - 1);
  834. pos.column = this.document.getLine(pos.row).length;
  835. }
  836. else if (row < 0) {
  837. pos.row = 0;
  838. pos.column = 0;
  839. }
  840. else {
  841. pos.row = row;
  842. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  843. }
  844. if (column < 0)
  845. pos.column = 0;
  846. return pos;
  847. };
  848. return Anchor;
  849. }());
  850. Anchor.prototype.$insertRight = false;
  851. oop.implement(Anchor.prototype, EventEmitter);
  852. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  853. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  854. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  855. }
  856. function $getTransformedPoint(delta, point, moveIfEqual) {
  857. var deltaIsInsert = delta.action == "insert";
  858. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  859. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  860. var deltaStart = delta.start;
  861. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  862. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  863. return {
  864. row: point.row,
  865. column: point.column
  866. };
  867. }
  868. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  869. return {
  870. row: point.row + deltaRowShift,
  871. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  872. };
  873. }
  874. return {
  875. row: deltaStart.row,
  876. column: deltaStart.column
  877. };
  878. }
  879. exports.Anchor = Anchor;
  880. });
  881. ace.define("ace/document",[], function(require, exports, module){"use strict";
  882. var oop = require("./lib/oop");
  883. var applyDelta = require("./apply_delta").applyDelta;
  884. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  885. var Range = require("./range").Range;
  886. var Anchor = require("./anchor").Anchor;
  887. var Document = /** @class */ (function () {
  888. function Document(textOrLines) {
  889. this.$lines = [""];
  890. if (textOrLines.length === 0) {
  891. this.$lines = [""];
  892. }
  893. else if (Array.isArray(textOrLines)) {
  894. this.insertMergedLines({ row: 0, column: 0 }, textOrLines);
  895. }
  896. else {
  897. this.insert({ row: 0, column: 0 }, textOrLines);
  898. }
  899. }
  900. Document.prototype.setValue = function (text) {
  901. var len = this.getLength() - 1;
  902. this.remove(new Range(0, 0, len, this.getLine(len).length));
  903. this.insert({ row: 0, column: 0 }, text || "");
  904. };
  905. Document.prototype.getValue = function () {
  906. return this.getAllLines().join(this.getNewLineCharacter());
  907. };
  908. Document.prototype.createAnchor = function (row, column) {
  909. return new Anchor(this, row, column);
  910. };
  911. Document.prototype.$detectNewLine = function (text) {
  912. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  913. this.$autoNewLine = match ? match[1] : "\n";
  914. this._signal("changeNewLineMode");
  915. };
  916. Document.prototype.getNewLineCharacter = function () {
  917. switch (this.$newLineMode) {
  918. case "windows":
  919. return "\r\n";
  920. case "unix":
  921. return "\n";
  922. default:
  923. return this.$autoNewLine || "\n";
  924. }
  925. };
  926. Document.prototype.setNewLineMode = function (newLineMode) {
  927. if (this.$newLineMode === newLineMode)
  928. return;
  929. this.$newLineMode = newLineMode;
  930. this._signal("changeNewLineMode");
  931. };
  932. Document.prototype.getNewLineMode = function () {
  933. return this.$newLineMode;
  934. };
  935. Document.prototype.isNewLine = function (text) {
  936. return (text == "\r\n" || text == "\r" || text == "\n");
  937. };
  938. Document.prototype.getLine = function (row) {
  939. return this.$lines[row] || "";
  940. };
  941. Document.prototype.getLines = function (firstRow, lastRow) {
  942. return this.$lines.slice(firstRow, lastRow + 1);
  943. };
  944. Document.prototype.getAllLines = function () {
  945. return this.getLines(0, this.getLength());
  946. };
  947. Document.prototype.getLength = function () {
  948. return this.$lines.length;
  949. };
  950. Document.prototype.getTextRange = function (range) {
  951. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  952. };
  953. Document.prototype.getLinesForRange = function (range) {
  954. var lines;
  955. if (range.start.row === range.end.row) {
  956. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  957. }
  958. else {
  959. lines = this.getLines(range.start.row, range.end.row);
  960. lines[0] = (lines[0] || "").substring(range.start.column);
  961. var l = lines.length - 1;
  962. if (range.end.row - range.start.row == l)
  963. lines[l] = lines[l].substring(0, range.end.column);
  964. }
  965. return lines;
  966. };
  967. Document.prototype.insertLines = function (row, lines) {
  968. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  969. return this.insertFullLines(row, lines);
  970. };
  971. Document.prototype.removeLines = function (firstRow, lastRow) {
  972. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  973. return this.removeFullLines(firstRow, lastRow);
  974. };
  975. Document.prototype.insertNewLine = function (position) {
  976. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  977. return this.insertMergedLines(position, ["", ""]);
  978. };
  979. Document.prototype.insert = function (position, text) {
  980. if (this.getLength() <= 1)
  981. this.$detectNewLine(text);
  982. return this.insertMergedLines(position, this.$split(text));
  983. };
  984. Document.prototype.insertInLine = function (position, text) {
  985. var start = this.clippedPos(position.row, position.column);
  986. var end = this.pos(position.row, position.column + text.length);
  987. this.applyDelta({
  988. start: start,
  989. end: end,
  990. action: "insert",
  991. lines: [text]
  992. }, true);
  993. return this.clonePos(end);
  994. };
  995. Document.prototype.clippedPos = function (row, column) {
  996. var length = this.getLength();
  997. if (row === undefined) {
  998. row = length;
  999. }
  1000. else if (row < 0) {
  1001. row = 0;
  1002. }
  1003. else if (row >= length) {
  1004. row = length - 1;
  1005. column = undefined;
  1006. }
  1007. var line = this.getLine(row);
  1008. if (column == undefined)
  1009. column = line.length;
  1010. column = Math.min(Math.max(column, 0), line.length);
  1011. return { row: row, column: column };
  1012. };
  1013. Document.prototype.clonePos = function (pos) {
  1014. return { row: pos.row, column: pos.column };
  1015. };
  1016. Document.prototype.pos = function (row, column) {
  1017. return { row: row, column: column };
  1018. };
  1019. Document.prototype.$clipPosition = function (position) {
  1020. var length = this.getLength();
  1021. if (position.row >= length) {
  1022. position.row = Math.max(0, length - 1);
  1023. position.column = this.getLine(length - 1).length;
  1024. }
  1025. else {
  1026. position.row = Math.max(0, position.row);
  1027. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  1028. }
  1029. return position;
  1030. };
  1031. Document.prototype.insertFullLines = function (row, lines) {
  1032. row = Math.min(Math.max(row, 0), this.getLength());
  1033. var column = 0;
  1034. if (row < this.getLength()) {
  1035. lines = lines.concat([""]);
  1036. column = 0;
  1037. }
  1038. else {
  1039. lines = [""].concat(lines);
  1040. row--;
  1041. column = this.$lines[row].length;
  1042. }
  1043. this.insertMergedLines({ row: row, column: column }, lines);
  1044. };
  1045. Document.prototype.insertMergedLines = function (position, lines) {
  1046. var start = this.clippedPos(position.row, position.column);
  1047. var end = {
  1048. row: start.row + lines.length - 1,
  1049. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  1050. };
  1051. this.applyDelta({
  1052. start: start,
  1053. end: end,
  1054. action: "insert",
  1055. lines: lines
  1056. });
  1057. return this.clonePos(end);
  1058. };
  1059. Document.prototype.remove = function (range) {
  1060. var start = this.clippedPos(range.start.row, range.start.column);
  1061. var end = this.clippedPos(range.end.row, range.end.column);
  1062. this.applyDelta({
  1063. start: start,
  1064. end: end,
  1065. action: "remove",
  1066. lines: this.getLinesForRange({ start: start, end: end })
  1067. });
  1068. return this.clonePos(start);
  1069. };
  1070. Document.prototype.removeInLine = function (row, startColumn, endColumn) {
  1071. var start = this.clippedPos(row, startColumn);
  1072. var end = this.clippedPos(row, endColumn);
  1073. this.applyDelta({
  1074. start: start,
  1075. end: end,
  1076. action: "remove",
  1077. lines: this.getLinesForRange({ start: start, end: end })
  1078. }, true);
  1079. return this.clonePos(start);
  1080. };
  1081. Document.prototype.removeFullLines = function (firstRow, lastRow) {
  1082. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  1083. lastRow = Math.min(Math.max(0, lastRow), this.getLength() - 1);
  1084. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  1085. var deleteLastNewLine = lastRow < this.getLength() - 1;
  1086. var startRow = (deleteFirstNewLine ? firstRow - 1 : firstRow);
  1087. var startCol = (deleteFirstNewLine ? this.getLine(startRow).length : 0);
  1088. var endRow = (deleteLastNewLine ? lastRow + 1 : lastRow);
  1089. var endCol = (deleteLastNewLine ? 0 : this.getLine(endRow).length);
  1090. var range = new Range(startRow, startCol, endRow, endCol);
  1091. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  1092. this.applyDelta({
  1093. start: range.start,
  1094. end: range.end,
  1095. action: "remove",
  1096. lines: this.getLinesForRange(range)
  1097. });
  1098. return deletedLines;
  1099. };
  1100. Document.prototype.removeNewLine = function (row) {
  1101. if (row < this.getLength() - 1 && row >= 0) {
  1102. this.applyDelta({
  1103. start: this.pos(row, this.getLine(row).length),
  1104. end: this.pos(row + 1, 0),
  1105. action: "remove",
  1106. lines: ["", ""]
  1107. });
  1108. }
  1109. };
  1110. Document.prototype.replace = function (range, text) {
  1111. if (!(range instanceof Range))
  1112. range = Range.fromPoints(range.start, range.end);
  1113. if (text.length === 0 && range.isEmpty())
  1114. return range.start;
  1115. if (text == this.getTextRange(range))
  1116. return range.end;
  1117. this.remove(range);
  1118. var end;
  1119. if (text) {
  1120. end = this.insert(range.start, text);
  1121. }
  1122. else {
  1123. end = range.start;
  1124. }
  1125. return end;
  1126. };
  1127. Document.prototype.applyDeltas = function (deltas) {
  1128. for (var i = 0; i < deltas.length; i++) {
  1129. this.applyDelta(deltas[i]);
  1130. }
  1131. };
  1132. Document.prototype.revertDeltas = function (deltas) {
  1133. for (var i = deltas.length - 1; i >= 0; i--) {
  1134. this.revertDelta(deltas[i]);
  1135. }
  1136. };
  1137. Document.prototype.applyDelta = function (delta, doNotValidate) {
  1138. var isInsert = delta.action == "insert";
  1139. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  1140. : !Range.comparePoints(delta.start, delta.end)) {
  1141. return;
  1142. }
  1143. if (isInsert && delta.lines.length > 20000) {
  1144. this.$splitAndapplyLargeDelta(delta, 20000);
  1145. }
  1146. else {
  1147. applyDelta(this.$lines, delta, doNotValidate);
  1148. this._signal("change", delta);
  1149. }
  1150. };
  1151. Document.prototype.$safeApplyDelta = function (delta) {
  1152. var docLength = this.$lines.length;
  1153. if (delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  1154. || delta.action == "insert" && delta.start.row <= docLength) {
  1155. this.applyDelta(delta);
  1156. }
  1157. };
  1158. Document.prototype.$splitAndapplyLargeDelta = function (delta, MAX) {
  1159. var lines = delta.lines;
  1160. var l = lines.length - MAX + 1;
  1161. var row = delta.start.row;
  1162. var column = delta.start.column;
  1163. for (var from = 0, to = 0; from < l; from = to) {
  1164. to += MAX - 1;
  1165. var chunk = lines.slice(from, to);
  1166. chunk.push("");
  1167. this.applyDelta({
  1168. start: this.pos(row + from, column),
  1169. end: this.pos(row + to, column = 0),
  1170. action: delta.action,
  1171. lines: chunk
  1172. }, true);
  1173. }
  1174. delta.lines = lines.slice(from);
  1175. delta.start.row = row + from;
  1176. delta.start.column = column;
  1177. this.applyDelta(delta, true);
  1178. };
  1179. Document.prototype.revertDelta = function (delta) {
  1180. this.$safeApplyDelta({
  1181. start: this.clonePos(delta.start),
  1182. end: this.clonePos(delta.end),
  1183. action: (delta.action == "insert" ? "remove" : "insert"),
  1184. lines: delta.lines.slice()
  1185. });
  1186. };
  1187. Document.prototype.indexToPosition = function (index, startRow) {
  1188. var lines = this.$lines || this.getAllLines();
  1189. var newlineLength = this.getNewLineCharacter().length;
  1190. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1191. index -= lines[i].length + newlineLength;
  1192. if (index < 0)
  1193. return { row: i, column: index + lines[i].length + newlineLength };
  1194. }
  1195. return { row: l - 1, column: index + lines[l - 1].length + newlineLength };
  1196. };
  1197. Document.prototype.positionToIndex = function (pos, startRow) {
  1198. var lines = this.$lines || this.getAllLines();
  1199. var newlineLength = this.getNewLineCharacter().length;
  1200. var index = 0;
  1201. var row = Math.min(pos.row, lines.length);
  1202. for (var i = startRow || 0; i < row; ++i)
  1203. index += lines[i].length + newlineLength;
  1204. return index + pos.column;
  1205. };
  1206. Document.prototype.$split = function (text) {
  1207. return text.split(/\r\n|\r|\n/);
  1208. };
  1209. return Document;
  1210. }());
  1211. Document.prototype.$autoNewLine = "";
  1212. Document.prototype.$newLineMode = "auto";
  1213. oop.implement(Document.prototype, EventEmitter);
  1214. exports.Document = Document;
  1215. });
  1216. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1217. "use strict";
  1218. var Document = require("../document").Document;
  1219. var lang = require("../lib/lang");
  1220. var Mirror = exports.Mirror = function(sender) {
  1221. this.sender = sender;
  1222. var doc = this.doc = new Document("");
  1223. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1224. var _self = this;
  1225. sender.on("change", function(e) {
  1226. var data = e.data;
  1227. if (data[0].start) {
  1228. doc.applyDeltas(data);
  1229. } else {
  1230. for (var i = 0; i < data.length; i += 2) {
  1231. var d, err;
  1232. if (Array.isArray(data[i+1])) {
  1233. d = {action: "insert", start: data[i], lines: data[i+1]};
  1234. } else {
  1235. d = {action: "remove", start: data[i], end: data[i+1]};
  1236. }
  1237. if ((d.action == "insert" ? d.start : d.end).row >= doc.$lines.length) {
  1238. err = new Error("Invalid delta");
  1239. err.data = {
  1240. path: _self.$path,
  1241. linesLength: doc.$lines.length,
  1242. start: d.start,
  1243. end: d.end
  1244. };
  1245. throw err;
  1246. }
  1247. doc.applyDelta(d, true);
  1248. }
  1249. }
  1250. if (_self.$timeout)
  1251. return deferredUpdate.schedule(_self.$timeout);
  1252. _self.onUpdate();
  1253. });
  1254. };
  1255. (function() {
  1256. this.$timeout = 500;
  1257. this.setTimeout = function(timeout) {
  1258. this.$timeout = timeout;
  1259. };
  1260. this.setValue = function(value) {
  1261. this.doc.setValue(value);
  1262. this.deferredUpdate.schedule(this.$timeout);
  1263. };
  1264. this.getValue = function(callbackId) {
  1265. this.sender.callback(this.doc.getValue(), callbackId);
  1266. };
  1267. this.onUpdate = function() {
  1268. };
  1269. this.isPending = function() {
  1270. return this.deferredUpdate.isPending();
  1271. };
  1272. }).call(Mirror.prototype);
  1273. });
  1274. ace.define("ace/mode/xml/sax",[], function(require, exports, module) {
  1275. var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
  1276. var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\u00B7\u0300-\u036F\\ux203F-\u2040]");
  1277. var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
  1278. var S_TAG = 0;//tag name offerring
  1279. var S_ATTR = 1;//attr name offerring
  1280. var S_ATTR_S=2;//attr name end and space offer
  1281. var S_EQ = 3;//=space?
  1282. var S_V = 4;//attr value(no quot value only)
  1283. var S_E = 5;//attr value end and no space(quot end)
  1284. var S_S = 6;//(attr value end || tag end ) && (space offer)
  1285. var S_C = 7;//closed el<el />
  1286. function XMLReader(){
  1287. }
  1288. XMLReader.prototype = {
  1289. parse:function(source,defaultNSMap,entityMap){
  1290. var domBuilder = this.domBuilder;
  1291. domBuilder.startDocument();
  1292. _copy(defaultNSMap ,defaultNSMap = {})
  1293. parse(source,defaultNSMap,entityMap,
  1294. domBuilder,this.errorHandler);
  1295. domBuilder.endDocument();
  1296. }
  1297. }
  1298. function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
  1299. function fixedFromCharCode(code) {
  1300. if (code > 0xffff) {
  1301. code -= 0x10000;
  1302. var surrogate1 = 0xd800 + (code >> 10)
  1303. , surrogate2 = 0xdc00 + (code & 0x3ff);
  1304. return String.fromCharCode(surrogate1, surrogate2);
  1305. } else {
  1306. return String.fromCharCode(code);
  1307. }
  1308. }
  1309. function entityReplacer(a){
  1310. var k = a.slice(1,-1);
  1311. if(k in entityMap){
  1312. return entityMap[k];
  1313. }else if(k.charAt(0) === '#'){
  1314. return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
  1315. }else{
  1316. errorHandler.error('entity not found:'+a);
  1317. return a;
  1318. }
  1319. }
  1320. function appendText(end){//has some bugs
  1321. var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
  1322. locator&&position(start);
  1323. domBuilder.characters(xt,0,end-start);
  1324. start = end
  1325. }
  1326. function position(start,m){
  1327. while(start>=endPos && (m = linePattern.exec(source))){
  1328. startPos = m.index;
  1329. endPos = startPos + m[0].length;
  1330. locator.lineNumber++;
  1331. }
  1332. locator.columnNumber = start-startPos+1;
  1333. }
  1334. var startPos = 0;
  1335. var endPos = 0;
  1336. var linePattern = /.+(?:\r\n?|\n)|.*$/g
  1337. var locator = domBuilder.locator;
  1338. var parseStack = [{currentNSMap:defaultNSMapCopy}]
  1339. var closeMap = {};
  1340. var start = 0;
  1341. while(true){
  1342. var i = source.indexOf('<',start);
  1343. if(i<0){
  1344. if(!source.substr(start).match(/^\s*$/)){
  1345. var doc = domBuilder.document;
  1346. var text = doc.createTextNode(source.substr(start));
  1347. doc.appendChild(text);
  1348. domBuilder.currentElement = text;
  1349. }
  1350. return;
  1351. }
  1352. if(i>start){
  1353. appendText(i);
  1354. }
  1355. switch(source.charAt(i+1)){
  1356. case '/':
  1357. var end = source.indexOf('>',i+3);
  1358. var tagName = source.substring(i+2,end);
  1359. var config;
  1360. if (parseStack.length > 1) {
  1361. config = parseStack.pop();
  1362. } else {
  1363. errorHandler.fatalError("end tag name not found for: "+tagName);
  1364. break;
  1365. }
  1366. var localNSMap = config.localNSMap;
  1367. if(config.tagName != tagName){
  1368. errorHandler.fatalError("end tag name: " + tagName + " does not match the current start tagName: "+config.tagName );
  1369. }
  1370. domBuilder.endElement(config.uri,config.localName,tagName);
  1371. if(localNSMap){
  1372. for(var prefix in localNSMap){
  1373. domBuilder.endPrefixMapping(prefix) ;
  1374. }
  1375. }
  1376. end++;
  1377. break;
  1378. case '?':// <?...?>
  1379. locator&&position(i);
  1380. end = parseInstruction(source,i,domBuilder);
  1381. break;
  1382. case '!':// <!doctype,<![CDATA,<!--
  1383. locator&&position(i);
  1384. end = parseDCC(source,i,domBuilder,errorHandler);
  1385. break;
  1386. default:
  1387. try{
  1388. locator&&position(i);
  1389. var el = new ElementAttributes();
  1390. var end = parseElementStartPart(source,i,el,entityReplacer,errorHandler);
  1391. var len = el.length;
  1392. if(len && locator){
  1393. var backup = copyLocator(locator,{});
  1394. for(var i = 0;i<len;i++){
  1395. var a = el[i];
  1396. position(a.offset);
  1397. a.offset = copyLocator(locator,{});
  1398. }
  1399. copyLocator(backup,locator);
  1400. }
  1401. if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
  1402. el.closed = true;
  1403. if(!entityMap.nbsp){
  1404. errorHandler.warning('unclosed xml attribute');
  1405. }
  1406. }
  1407. appendElement(el,domBuilder,parseStack,errorHandler);
  1408. if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
  1409. end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
  1410. }else{
  1411. end++;
  1412. }
  1413. }catch(e){
  1414. errorHandler.error('element parse error: '+e);
  1415. end = -1;
  1416. }
  1417. }
  1418. if(end<0){
  1419. appendText(i+1);
  1420. }else{
  1421. start = end;
  1422. }
  1423. }
  1424. }
  1425. function copyLocator(f,t){
  1426. t.lineNumber = f.lineNumber;
  1427. t.columnNumber = f.columnNumber;
  1428. return t;
  1429. }
  1430. function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
  1431. var attrName;
  1432. var value;
  1433. var p = ++start;
  1434. var s = S_TAG;//status
  1435. while(true){
  1436. var c = source.charAt(p);
  1437. switch(c){
  1438. case '=':
  1439. if(s === S_ATTR){//attrName
  1440. attrName = source.slice(start,p);
  1441. s = S_EQ;
  1442. }else if(s === S_ATTR_S){
  1443. s = S_EQ;
  1444. }else{
  1445. throw new Error('attribute equal must after attrName');
  1446. }
  1447. break;
  1448. case '\'':
  1449. case '"':
  1450. if(s === S_EQ){//equal
  1451. start = p+1;
  1452. p = source.indexOf(c,start)
  1453. if(p>0){
  1454. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  1455. el.add(attrName,value,start-1);
  1456. s = S_E;
  1457. }else{
  1458. throw new Error('attribute value no end \''+c+'\' match');
  1459. }
  1460. }else if(s == S_V){
  1461. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  1462. el.add(attrName,value,start);
  1463. errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
  1464. start = p+1;
  1465. s = S_E
  1466. }else{
  1467. throw new Error('attribute value must after "="');
  1468. }
  1469. break;
  1470. case '/':
  1471. switch(s){
  1472. case S_TAG:
  1473. el.setTagName(source.slice(start,p));
  1474. case S_E:
  1475. case S_S:
  1476. case S_C:
  1477. s = S_C;
  1478. el.closed = true;
  1479. case S_V:
  1480. case S_ATTR:
  1481. case S_ATTR_S:
  1482. break;
  1483. default:
  1484. throw new Error("attribute invalid close char('/')")
  1485. }
  1486. break;
  1487. case ''://end document
  1488. errorHandler.error('unexpected end of input');
  1489. case '>':
  1490. switch(s){
  1491. case S_TAG:
  1492. el.setTagName(source.slice(start,p));
  1493. case S_E:
  1494. case S_S:
  1495. case S_C:
  1496. break;//normal
  1497. case S_V://Compatible state
  1498. case S_ATTR:
  1499. value = source.slice(start,p);
  1500. if(value.slice(-1) === '/'){
  1501. el.closed = true;
  1502. value = value.slice(0,-1)
  1503. }
  1504. case S_ATTR_S:
  1505. if(s === S_ATTR_S){
  1506. value = attrName;
  1507. }
  1508. if(s == S_V){
  1509. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  1510. el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
  1511. }else{
  1512. errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
  1513. el.add(value,value,start)
  1514. }
  1515. break;
  1516. case S_EQ:
  1517. throw new Error('attribute value missed!!');
  1518. }
  1519. return p;
  1520. case '\u0080':
  1521. c = ' ';
  1522. default:
  1523. if(c<= ' '){//space
  1524. switch(s){
  1525. case S_TAG:
  1526. el.setTagName(source.slice(start,p));//tagName
  1527. s = S_S;
  1528. break;
  1529. case S_ATTR:
  1530. attrName = source.slice(start,p)
  1531. s = S_ATTR_S;
  1532. break;
  1533. case S_V:
  1534. var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  1535. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  1536. el.add(attrName,value,start)
  1537. case S_E:
  1538. s = S_S;
  1539. break;
  1540. }
  1541. }else{//not space
  1542. switch(s){
  1543. case S_ATTR_S:
  1544. errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead!!')
  1545. el.add(attrName,attrName,start);
  1546. start = p;
  1547. s = S_ATTR;
  1548. break;
  1549. case S_E:
  1550. errorHandler.warning('attribute space is required"'+attrName+'"!!')
  1551. case S_S:
  1552. s = S_ATTR;
  1553. start = p;
  1554. break;
  1555. case S_EQ:
  1556. s = S_V;
  1557. start = p;
  1558. break;
  1559. case S_C:
  1560. throw new Error("elements closed character '/' and '>' must be connected to");
  1561. }
  1562. }
  1563. }
  1564. p++;
  1565. }
  1566. }
  1567. function appendElement(el,domBuilder,parseStack,errorHandler){
  1568. var tagName = el.tagName;
  1569. var localNSMap = null;
  1570. var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  1571. var i = el.length;
  1572. while(i--){
  1573. var a = el[i];
  1574. var qName = a.qName;
  1575. var value = a.value;
  1576. var nsp = qName.indexOf(':');
  1577. if(nsp>0){
  1578. var prefix = a.prefix = qName.slice(0,nsp);
  1579. var localName = qName.slice(nsp+1);
  1580. var nsPrefix = prefix === 'xmlns' && localName
  1581. }else{
  1582. localName = qName;
  1583. prefix = null
  1584. nsPrefix = qName === 'xmlns' && ''
  1585. }
  1586. a.localName = localName ;
  1587. if(nsPrefix !== false){//hack!!
  1588. if(localNSMap == null){
  1589. localNSMap = {}
  1590. _copy(currentNSMap,currentNSMap={})
  1591. }
  1592. currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
  1593. a.uri = 'http://www.w3.org/2000/xmlns/'
  1594. domBuilder.startPrefixMapping(nsPrefix, value)
  1595. }
  1596. }
  1597. var i = el.length;
  1598. while(i--){
  1599. a = el[i];
  1600. var prefix = a.prefix;
  1601. if(prefix){//no prefix attribute has no namespace
  1602. if(prefix === 'xml'){
  1603. a.uri = 'http://www.w3.org/XML/1998/namespace';
  1604. }if(prefix !== 'xmlns'){
  1605. a.uri = currentNSMap[prefix]
  1606. }
  1607. }
  1608. }
  1609. var nsp = tagName.indexOf(':');
  1610. if(nsp>0){
  1611. prefix = el.prefix = tagName.slice(0,nsp);
  1612. localName = el.localName = tagName.slice(nsp+1);
  1613. }else{
  1614. prefix = null;//important!!
  1615. localName = el.localName = tagName;
  1616. }
  1617. var ns = el.uri = currentNSMap[prefix || ''];
  1618. if (prefix && !ns) {
  1619. errorHandler.error('unexpected namespace ' + prefix);
  1620. }
  1621. domBuilder.startElement(ns,localName,tagName,el);
  1622. if(el.closed){
  1623. domBuilder.endElement(ns,localName,tagName);
  1624. if(localNSMap){
  1625. for(prefix in localNSMap){
  1626. domBuilder.endPrefixMapping(prefix)
  1627. }
  1628. }
  1629. }else{
  1630. el.currentNSMap = currentNSMap;
  1631. el.localNSMap = localNSMap;
  1632. parseStack.push(el);
  1633. }
  1634. }
  1635. function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
  1636. if(/^(?:script|textarea)$/i.test(tagName)){
  1637. var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
  1638. var text = source.substring(elStartEnd+1,elEndStart);
  1639. if(/[&<]/.test(text)){
  1640. if(/^script$/i.test(tagName)){
  1641. domBuilder.characters(text,0,text.length);
  1642. return elEndStart;
  1643. }//}else{//text area
  1644. text = text.replace(/&#?\w+;/g,entityReplacer);
  1645. domBuilder.characters(text,0,text.length);
  1646. return elEndStart;
  1647. }
  1648. }
  1649. return elStartEnd+1;
  1650. }
  1651. function fixSelfClosed(source,elStartEnd,tagName,closeMap){
  1652. var pos = closeMap[tagName];
  1653. if(pos == null){
  1654. pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>')
  1655. }
  1656. return pos<elStartEnd;
  1657. }
  1658. function _copy(source,target){
  1659. for(var n in source){target[n] = source[n]}
  1660. }
  1661. function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
  1662. var next= source.charAt(start+2)
  1663. switch(next){
  1664. case '-':
  1665. if(source.charAt(start + 3) === '-'){
  1666. var end = source.indexOf('-->',start+4);
  1667. if(end>start){
  1668. domBuilder.comment(source,start+4,end-start-4);
  1669. return end+3;
  1670. }else{
  1671. errorHandler.error("Unclosed comment");
  1672. return -1;
  1673. }
  1674. }else{
  1675. return -1;
  1676. }
  1677. default:
  1678. if(source.substr(start+3,6) == 'CDATA['){
  1679. var end = source.indexOf(']]>',start+9);
  1680. if (end > start) {
  1681. domBuilder.startCDATA();
  1682. domBuilder.characters(source,start+9,end-start-9);
  1683. domBuilder.endCDATA()
  1684. return end+3;
  1685. } else {
  1686. errorHandler.error("Unclosed CDATA");
  1687. return -1;
  1688. }
  1689. }
  1690. var matchs = split(source,start);
  1691. var len = matchs.length;
  1692. if(len>1 && /!doctype/i.test(matchs[0][0])){
  1693. var name = matchs[1][0];
  1694. var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
  1695. var sysid = len>4 && matchs[4][0];
  1696. var lastMatch = matchs[len-1]
  1697. domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
  1698. sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
  1699. domBuilder.endDTD();
  1700. return lastMatch.index+lastMatch[0].length
  1701. }
  1702. }
  1703. return -1;
  1704. }
  1705. function parseInstruction(source,start,domBuilder){
  1706. var end = source.indexOf('?>',start);
  1707. if(end){
  1708. var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
  1709. if(match){
  1710. var len = match[0].length;
  1711. domBuilder.processingInstruction(match[1], match[2]) ;
  1712. return end+2;
  1713. }else{//error
  1714. return -1;
  1715. }
  1716. }
  1717. return -1;
  1718. }
  1719. function ElementAttributes(source){
  1720. }
  1721. ElementAttributes.prototype = {
  1722. setTagName:function(tagName){
  1723. if(!tagNamePattern.test(tagName)){
  1724. throw new Error('invalid tagName:'+tagName)
  1725. }
  1726. this.tagName = tagName
  1727. },
  1728. add:function(qName,value,offset){
  1729. if(!tagNamePattern.test(qName)){
  1730. throw new Error('invalid attribute:'+qName)
  1731. }
  1732. this[this.length++] = {qName:qName,value:value,offset:offset}
  1733. },
  1734. length:0,
  1735. getLocalName:function(i){return this[i].localName},
  1736. getOffset:function(i){return this[i].offset},
  1737. getQName:function(i){return this[i].qName},
  1738. getURI:function(i){return this[i].uri},
  1739. getValue:function(i){return this[i].value}
  1740. }
  1741. function _set_proto_(thiz,parent){
  1742. thiz.__proto__ = parent;
  1743. return thiz;
  1744. }
  1745. if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
  1746. _set_proto_ = function(thiz,parent){
  1747. function p(){};
  1748. p.prototype = parent;
  1749. p = new p();
  1750. for(parent in thiz){
  1751. p[parent] = thiz[parent];
  1752. }
  1753. return p;
  1754. }
  1755. }
  1756. function split(source,start){
  1757. var match;
  1758. var buf = [];
  1759. var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
  1760. reg.lastIndex = start;
  1761. reg.exec(source);//skip <
  1762. while(match = reg.exec(source)){
  1763. buf.push(match);
  1764. if(match[1])return buf;
  1765. }
  1766. }
  1767. return XMLReader;
  1768. });
  1769. ace.define("ace/mode/xml/dom",[], function(require, exports, module) {
  1770. function copy(src,dest){
  1771. for(var p in src){
  1772. dest[p] = src[p];
  1773. }
  1774. }
  1775. function _extends(Class,Super){
  1776. var t = function(){};
  1777. var pt = Class.prototype;
  1778. if(Object.create){
  1779. var ppt = Object.create(Super.prototype);
  1780. pt.__proto__ = ppt;
  1781. }
  1782. if(!(pt instanceof Super)){
  1783. t.prototype = Super.prototype;
  1784. t = new t();
  1785. copy(pt,t);
  1786. Class.prototype = pt = t;
  1787. }
  1788. if(pt.constructor != Class){
  1789. if(typeof Class != 'function'){
  1790. console.error("unknown Class:"+Class);
  1791. }
  1792. pt.constructor = Class;
  1793. }
  1794. }
  1795. var htmlns = 'http://www.w3.org/1999/xhtml' ;
  1796. var NodeType = {};
  1797. var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
  1798. var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
  1799. var TEXT_NODE = NodeType.TEXT_NODE = 3;
  1800. var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
  1801. var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
  1802. var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
  1803. var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
  1804. var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
  1805. var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
  1806. var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
  1807. var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
  1808. var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
  1809. var ExceptionCode = {};
  1810. var ExceptionMessage = {};
  1811. var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
  1812. var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
  1813. var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
  1814. var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
  1815. var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
  1816. var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
  1817. var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
  1818. var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
  1819. var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
  1820. var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
  1821. var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
  1822. var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
  1823. var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
  1824. var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
  1825. var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
  1826. function DOMException(code, message) {
  1827. if(message instanceof Error){
  1828. var error = message;
  1829. }else{
  1830. error = this;
  1831. Error.call(this, ExceptionMessage[code]);
  1832. this.message = ExceptionMessage[code];
  1833. if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
  1834. }
  1835. error.code = code;
  1836. if(message) this.message = this.message + ": " + message;
  1837. return error;
  1838. };
  1839. DOMException.prototype = Error.prototype;
  1840. copy(ExceptionCode,DOMException)
  1841. function NodeList() {
  1842. };
  1843. NodeList.prototype = {
  1844. length:0,
  1845. item: function(index) {
  1846. return this[index] || null;
  1847. }
  1848. };
  1849. function LiveNodeList(node,refresh){
  1850. this._node = node;
  1851. this._refresh = refresh;
  1852. _updateLiveList(this);
  1853. }
  1854. function _updateLiveList(list){
  1855. var inc = list._node._inc || list._node.ownerDocument._inc;
  1856. if(list._inc != inc){
  1857. var ls = list._refresh(list._node);
  1858. __set__(list,'length',ls.length);
  1859. copy(ls,list);
  1860. list._inc = inc;
  1861. }
  1862. }
  1863. LiveNodeList.prototype.item = function(i){
  1864. _updateLiveList(this);
  1865. return this[i];
  1866. }
  1867. _extends(LiveNodeList,NodeList);
  1868. function NamedNodeMap() {
  1869. };
  1870. function _findNodeIndex(list,node){
  1871. var i = list.length;
  1872. while(i--){
  1873. if(list[i] === node){return i}
  1874. }
  1875. }
  1876. function _addNamedNode(el,list,newAttr,oldAttr){
  1877. if(oldAttr){
  1878. list[_findNodeIndex(list,oldAttr)] = newAttr;
  1879. }else{
  1880. list[list.length++] = newAttr;
  1881. }
  1882. if(el){
  1883. newAttr.ownerElement = el;
  1884. var doc = el.ownerDocument;
  1885. if(doc){
  1886. oldAttr && _onRemoveAttribute(doc,el,oldAttr);
  1887. _onAddAttribute(doc,el,newAttr);
  1888. }
  1889. }
  1890. }
  1891. function _removeNamedNode(el,list,attr){
  1892. var i = _findNodeIndex(list,attr);
  1893. if(i>=0){
  1894. var lastIndex = list.length-1;
  1895. while(i<lastIndex){
  1896. list[i] = list[++i];
  1897. }
  1898. list.length = lastIndex;
  1899. if(el){
  1900. var doc = el.ownerDocument;
  1901. if(doc){
  1902. _onRemoveAttribute(doc,el,attr);
  1903. attr.ownerElement = null;
  1904. }
  1905. }
  1906. }else{
  1907. throw new DOMException(NOT_FOUND_ERR,new Error());
  1908. }
  1909. }
  1910. NamedNodeMap.prototype = {
  1911. length:0,
  1912. item:NodeList.prototype.item,
  1913. getNamedItem: function(key) {
  1914. var i = this.length;
  1915. while(i--){
  1916. var attr = this[i];
  1917. if(attr.nodeName == key){
  1918. return attr;
  1919. }
  1920. }
  1921. },
  1922. setNamedItem: function(attr) {
  1923. var el = attr.ownerElement;
  1924. if(el && el!=this._ownerElement){
  1925. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  1926. }
  1927. var oldAttr = this.getNamedItem(attr.nodeName);
  1928. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  1929. return oldAttr;
  1930. },
  1931. setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
  1932. var el = attr.ownerElement, oldAttr;
  1933. if(el && el!=this._ownerElement){
  1934. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  1935. }
  1936. oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
  1937. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  1938. return oldAttr;
  1939. },
  1940. removeNamedItem: function(key) {
  1941. var attr = this.getNamedItem(key);
  1942. _removeNamedNode(this._ownerElement,this,attr);
  1943. return attr;
  1944. },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
  1945. removeNamedItemNS:function(namespaceURI,localName){
  1946. var attr = this.getNamedItemNS(namespaceURI,localName);
  1947. _removeNamedNode(this._ownerElement,this,attr);
  1948. return attr;
  1949. },
  1950. getNamedItemNS: function(namespaceURI, localName) {
  1951. var i = this.length;
  1952. while(i--){
  1953. var node = this[i];
  1954. if(node.localName == localName && node.namespaceURI == namespaceURI){
  1955. return node;
  1956. }
  1957. }
  1958. return null;
  1959. }
  1960. };
  1961. function DOMImplementation(/* Object */ features) {
  1962. this._features = {};
  1963. if (features) {
  1964. for (var feature in features) {
  1965. this._features = features[feature];
  1966. }
  1967. }
  1968. };
  1969. DOMImplementation.prototype = {
  1970. hasFeature: function(/* string */ feature, /* string */ version) {
  1971. var versions = this._features[feature.toLowerCase()];
  1972. if (versions && (!version || version in versions)) {
  1973. return true;
  1974. } else {
  1975. return false;
  1976. }
  1977. },
  1978. createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
  1979. var doc = new Document();
  1980. doc.implementation = this;
  1981. doc.childNodes = new NodeList();
  1982. doc.doctype = doctype;
  1983. if(doctype){
  1984. doc.appendChild(doctype);
  1985. }
  1986. if(qualifiedName){
  1987. var root = doc.createElementNS(namespaceURI,qualifiedName);
  1988. doc.appendChild(root);
  1989. }
  1990. return doc;
  1991. },
  1992. createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
  1993. var node = new DocumentType();
  1994. node.name = qualifiedName;
  1995. node.nodeName = qualifiedName;
  1996. node.publicId = publicId;
  1997. node.systemId = systemId;
  1998. return node;
  1999. }
  2000. };
  2001. function Node() {
  2002. };
  2003. Node.prototype = {
  2004. firstChild : null,
  2005. lastChild : null,
  2006. previousSibling : null,
  2007. nextSibling : null,
  2008. attributes : null,
  2009. parentNode : null,
  2010. childNodes : null,
  2011. ownerDocument : null,
  2012. nodeValue : null,
  2013. namespaceURI : null,
  2014. prefix : null,
  2015. localName : null,
  2016. insertBefore:function(newChild, refChild){//raises
  2017. return _insertBefore(this,newChild,refChild);
  2018. },
  2019. replaceChild:function(newChild, oldChild){//raises
  2020. this.insertBefore(newChild,oldChild);
  2021. if(oldChild){
  2022. this.removeChild(oldChild);
  2023. }
  2024. },
  2025. removeChild:function(oldChild){
  2026. return _removeChild(this,oldChild);
  2027. },
  2028. appendChild:function(newChild){
  2029. return this.insertBefore(newChild,null);
  2030. },
  2031. hasChildNodes:function(){
  2032. return this.firstChild != null;
  2033. },
  2034. cloneNode:function(deep){
  2035. return cloneNode(this.ownerDocument||this,this,deep);
  2036. },
  2037. normalize:function(){
  2038. var child = this.firstChild;
  2039. while(child){
  2040. var next = child.nextSibling;
  2041. if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
  2042. this.removeChild(next);
  2043. child.appendData(next.data);
  2044. }else{
  2045. child.normalize();
  2046. child = next;
  2047. }
  2048. }
  2049. },
  2050. isSupported:function(feature, version){
  2051. return this.ownerDocument.implementation.hasFeature(feature,version);
  2052. },
  2053. hasAttributes:function(){
  2054. return this.attributes.length>0;
  2055. },
  2056. lookupPrefix:function(namespaceURI){
  2057. var el = this;
  2058. while(el){
  2059. var map = el._nsMap;
  2060. if(map){
  2061. for(var n in map){
  2062. if(map[n] == namespaceURI){
  2063. return n;
  2064. }
  2065. }
  2066. }
  2067. el = el.nodeType == 2?el.ownerDocument : el.parentNode;
  2068. }
  2069. return null;
  2070. },
  2071. lookupNamespaceURI:function(prefix){
  2072. var el = this;
  2073. while(el){
  2074. var map = el._nsMap;
  2075. if(map){
  2076. if(prefix in map){
  2077. return map[prefix] ;
  2078. }
  2079. }
  2080. el = el.nodeType == 2?el.ownerDocument : el.parentNode;
  2081. }
  2082. return null;
  2083. },
  2084. isDefaultNamespace:function(namespaceURI){
  2085. var prefix = this.lookupPrefix(namespaceURI);
  2086. return prefix == null;
  2087. }
  2088. };
  2089. function _xmlEncoder(c){
  2090. return c == '<' && '&lt;' ||
  2091. c == '>' && '&gt;' ||
  2092. c == '&' && '&amp;' ||
  2093. c == '"' && '&quot;' ||
  2094. '&#'+c.charCodeAt()+';';
  2095. }
  2096. copy(NodeType,Node);
  2097. copy(NodeType,Node.prototype);
  2098. function _visitNode(node,callback){
  2099. if(callback(node)){
  2100. return true;
  2101. }
  2102. if(node = node.firstChild){
  2103. do{
  2104. if(_visitNode(node,callback)){return true}
  2105. }while(node=node.nextSibling)
  2106. }
  2107. }
  2108. function Document(){
  2109. }
  2110. function _onAddAttribute(doc,el,newAttr){
  2111. doc && doc._inc++;
  2112. var ns = newAttr.namespaceURI ;
  2113. if(ns == 'http://www.w3.org/2000/xmlns/'){
  2114. el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
  2115. }
  2116. }
  2117. function _onRemoveAttribute(doc,el,newAttr,remove){
  2118. doc && doc._inc++;
  2119. var ns = newAttr.namespaceURI ;
  2120. if(ns == 'http://www.w3.org/2000/xmlns/'){
  2121. delete el._nsMap[newAttr.prefix?newAttr.localName:''];
  2122. }
  2123. }
  2124. function _onUpdateChild(doc,el,newChild){
  2125. if(doc && doc._inc){
  2126. doc._inc++;
  2127. var cs = el.childNodes;
  2128. if(newChild){
  2129. cs[cs.length++] = newChild;
  2130. }else{
  2131. var child = el.firstChild;
  2132. var i = 0;
  2133. while(child){
  2134. cs[i++] = child;
  2135. child =child.nextSibling;
  2136. }
  2137. cs.length = i;
  2138. }
  2139. }
  2140. }
  2141. function _removeChild(parentNode,child){
  2142. var previous = child.previousSibling;
  2143. var next = child.nextSibling;
  2144. if(previous){
  2145. previous.nextSibling = next;
  2146. }else{
  2147. parentNode.firstChild = next
  2148. }
  2149. if(next){
  2150. next.previousSibling = previous;
  2151. }else{
  2152. parentNode.lastChild = previous;
  2153. }
  2154. _onUpdateChild(parentNode.ownerDocument,parentNode);
  2155. return child;
  2156. }
  2157. function _insertBefore(parentNode,newChild,nextChild){
  2158. var cp = newChild.parentNode;
  2159. if(cp){
  2160. cp.removeChild(newChild);//remove and update
  2161. }
  2162. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  2163. var newFirst = newChild.firstChild;
  2164. if (newFirst == null) {
  2165. return newChild;
  2166. }
  2167. var newLast = newChild.lastChild;
  2168. }else{
  2169. newFirst = newLast = newChild;
  2170. }
  2171. var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
  2172. newFirst.previousSibling = pre;
  2173. newLast.nextSibling = nextChild;
  2174. if(pre){
  2175. pre.nextSibling = newFirst;
  2176. }else{
  2177. parentNode.firstChild = newFirst;
  2178. }
  2179. if(nextChild == null){
  2180. parentNode.lastChild = newLast;
  2181. }else{
  2182. nextChild.previousSibling = newLast;
  2183. }
  2184. do{
  2185. newFirst.parentNode = parentNode;
  2186. }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
  2187. _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
  2188. if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
  2189. newChild.firstChild = newChild.lastChild = null;
  2190. }
  2191. return newChild;
  2192. }
  2193. function _appendSingleChild(parentNode,newChild){
  2194. var cp = newChild.parentNode;
  2195. if(cp){
  2196. var pre = parentNode.lastChild;
  2197. cp.removeChild(newChild);//remove and update
  2198. var pre = parentNode.lastChild;
  2199. }
  2200. var pre = parentNode.lastChild;
  2201. newChild.parentNode = parentNode;
  2202. newChild.previousSibling = pre;
  2203. newChild.nextSibling = null;
  2204. if(pre){
  2205. pre.nextSibling = newChild;
  2206. }else{
  2207. parentNode.firstChild = newChild;
  2208. }
  2209. parentNode.lastChild = newChild;
  2210. _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
  2211. return newChild;
  2212. }
  2213. Document.prototype = {
  2214. nodeName : '#document',
  2215. nodeType : DOCUMENT_NODE,
  2216. doctype : null,
  2217. documentElement : null,
  2218. _inc : 1,
  2219. insertBefore : function(newChild, refChild){//raises
  2220. if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
  2221. var child = newChild.firstChild;
  2222. while(child){
  2223. var next = child.nextSibling;
  2224. this.insertBefore(child,refChild);
  2225. child = next;
  2226. }
  2227. return newChild;
  2228. }
  2229. if(this.documentElement == null && newChild.nodeType == 1){
  2230. this.documentElement = newChild;
  2231. }
  2232. return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
  2233. },
  2234. removeChild : function(oldChild){
  2235. if(this.documentElement == oldChild){
  2236. this.documentElement = null;
  2237. }
  2238. return _removeChild(this,oldChild);
  2239. },
  2240. importNode : function(importedNode,deep){
  2241. return importNode(this,importedNode,deep);
  2242. },
  2243. getElementById : function(id){
  2244. var rtv = null;
  2245. _visitNode(this.documentElement,function(node){
  2246. if(node.nodeType == 1){
  2247. if(node.getAttribute('id') == id){
  2248. rtv = node;
  2249. return true;
  2250. }
  2251. }
  2252. });
  2253. return rtv;
  2254. },
  2255. createElement : function(tagName){
  2256. var node = new Element();
  2257. node.ownerDocument = this;
  2258. node.nodeName = tagName;
  2259. node.tagName = tagName;
  2260. node.childNodes = new NodeList();
  2261. var attrs = node.attributes = new NamedNodeMap();
  2262. attrs._ownerElement = node;
  2263. return node;
  2264. },
  2265. createDocumentFragment : function(){
  2266. var node = new DocumentFragment();
  2267. node.ownerDocument = this;
  2268. node.childNodes = new NodeList();
  2269. return node;
  2270. },
  2271. createTextNode : function(data){
  2272. var node = new Text();
  2273. node.ownerDocument = this;
  2274. node.appendData(data);
  2275. return node;
  2276. },
  2277. createComment : function(data){
  2278. var node = new Comment();
  2279. node.ownerDocument = this;
  2280. node.appendData(data);
  2281. return node;
  2282. },
  2283. createCDATASection : function(data){
  2284. var node = new CDATASection();
  2285. node.ownerDocument = this;
  2286. node.appendData(data);
  2287. return node;
  2288. },
  2289. createProcessingInstruction : function(target,data){
  2290. var node = new ProcessingInstruction();
  2291. node.ownerDocument = this;
  2292. node.tagName = node.target = target;
  2293. node.nodeValue= node.data = data;
  2294. return node;
  2295. },
  2296. createAttribute : function(name){
  2297. var node = new Attr();
  2298. node.ownerDocument = this;
  2299. node.name = name;
  2300. node.nodeName = name;
  2301. node.localName = name;
  2302. node.specified = true;
  2303. return node;
  2304. },
  2305. createEntityReference : function(name){
  2306. var node = new EntityReference();
  2307. node.ownerDocument = this;
  2308. node.nodeName = name;
  2309. return node;
  2310. },
  2311. createElementNS : function(namespaceURI,qualifiedName){
  2312. var node = new Element();
  2313. var pl = qualifiedName.split(':');
  2314. var attrs = node.attributes = new NamedNodeMap();
  2315. node.childNodes = new NodeList();
  2316. node.ownerDocument = this;
  2317. node.nodeName = qualifiedName;
  2318. node.tagName = qualifiedName;
  2319. node.namespaceURI = namespaceURI;
  2320. if(pl.length == 2){
  2321. node.prefix = pl[0];
  2322. node.localName = pl[1];
  2323. }else{
  2324. node.localName = qualifiedName;
  2325. }
  2326. attrs._ownerElement = node;
  2327. return node;
  2328. },
  2329. createAttributeNS : function(namespaceURI,qualifiedName){
  2330. var node = new Attr();
  2331. var pl = qualifiedName.split(':');
  2332. node.ownerDocument = this;
  2333. node.nodeName = qualifiedName;
  2334. node.name = qualifiedName;
  2335. node.namespaceURI = namespaceURI;
  2336. node.specified = true;
  2337. if(pl.length == 2){
  2338. node.prefix = pl[0];
  2339. node.localName = pl[1];
  2340. }else{
  2341. node.localName = qualifiedName;
  2342. }
  2343. return node;
  2344. }
  2345. };
  2346. _extends(Document,Node);
  2347. function Element() {
  2348. this._nsMap = {};
  2349. };
  2350. Element.prototype = {
  2351. nodeType : ELEMENT_NODE,
  2352. hasAttribute : function(name){
  2353. return this.getAttributeNode(name)!=null;
  2354. },
  2355. getAttribute : function(name){
  2356. var attr = this.getAttributeNode(name);
  2357. return attr && attr.value || '';
  2358. },
  2359. getAttributeNode : function(name){
  2360. return this.attributes.getNamedItem(name);
  2361. },
  2362. setAttribute : function(name, value){
  2363. var attr = this.ownerDocument.createAttribute(name);
  2364. attr.value = attr.nodeValue = "" + value;
  2365. this.setAttributeNode(attr);
  2366. },
  2367. removeAttribute : function(name){
  2368. var attr = this.getAttributeNode(name);
  2369. attr && this.removeAttributeNode(attr);
  2370. },
  2371. appendChild:function(newChild){
  2372. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  2373. return this.insertBefore(newChild,null);
  2374. }else{
  2375. return _appendSingleChild(this,newChild);
  2376. }
  2377. },
  2378. setAttributeNode : function(newAttr){
  2379. return this.attributes.setNamedItem(newAttr);
  2380. },
  2381. setAttributeNodeNS : function(newAttr){
  2382. return this.attributes.setNamedItemNS(newAttr);
  2383. },
  2384. removeAttributeNode : function(oldAttr){
  2385. return this.attributes.removeNamedItem(oldAttr.nodeName);
  2386. },
  2387. removeAttributeNS : function(namespaceURI, localName){
  2388. var old = this.getAttributeNodeNS(namespaceURI, localName);
  2389. old && this.removeAttributeNode(old);
  2390. },
  2391. hasAttributeNS : function(namespaceURI, localName){
  2392. return this.getAttributeNodeNS(namespaceURI, localName)!=null;
  2393. },
  2394. getAttributeNS : function(namespaceURI, localName){
  2395. var attr = this.getAttributeNodeNS(namespaceURI, localName);
  2396. return attr && attr.value || '';
  2397. },
  2398. setAttributeNS : function(namespaceURI, qualifiedName, value){
  2399. var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
  2400. attr.value = attr.nodeValue = "" + value;
  2401. this.setAttributeNode(attr);
  2402. },
  2403. getAttributeNodeNS : function(namespaceURI, localName){
  2404. return this.attributes.getNamedItemNS(namespaceURI, localName);
  2405. },
  2406. getElementsByTagName : function(tagName){
  2407. return new LiveNodeList(this,function(base){
  2408. var ls = [];
  2409. _visitNode(base,function(node){
  2410. if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
  2411. ls.push(node);
  2412. }
  2413. });
  2414. return ls;
  2415. });
  2416. },
  2417. getElementsByTagNameNS : function(namespaceURI, localName){
  2418. return new LiveNodeList(this,function(base){
  2419. var ls = [];
  2420. _visitNode(base,function(node){
  2421. if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
  2422. ls.push(node);
  2423. }
  2424. });
  2425. return ls;
  2426. });
  2427. }
  2428. };
  2429. Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
  2430. Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
  2431. _extends(Element,Node);
  2432. function Attr() {
  2433. };
  2434. Attr.prototype.nodeType = ATTRIBUTE_NODE;
  2435. _extends(Attr,Node);
  2436. function CharacterData() {
  2437. };
  2438. CharacterData.prototype = {
  2439. data : '',
  2440. substringData : function(offset, count) {
  2441. return this.data.substring(offset, offset+count);
  2442. },
  2443. appendData: function(text) {
  2444. text = this.data+text;
  2445. this.nodeValue = this.data = text;
  2446. this.length = text.length;
  2447. },
  2448. insertData: function(offset,text) {
  2449. this.replaceData(offset,0,text);
  2450. },
  2451. appendChild:function(newChild){
  2452. throw new Error(ExceptionMessage[3]);
  2453. return Node.prototype.appendChild.apply(this,arguments);
  2454. },
  2455. deleteData: function(offset, count) {
  2456. this.replaceData(offset,count,"");
  2457. },
  2458. replaceData: function(offset, count, text) {
  2459. var start = this.data.substring(0,offset);
  2460. var end = this.data.substring(offset+count);
  2461. text = start + text + end;
  2462. this.nodeValue = this.data = text;
  2463. this.length = text.length;
  2464. }
  2465. }
  2466. _extends(CharacterData,Node);
  2467. function Text() {
  2468. };
  2469. Text.prototype = {
  2470. nodeName : "#text",
  2471. nodeType : TEXT_NODE,
  2472. splitText : function(offset) {
  2473. var text = this.data;
  2474. var newText = text.substring(offset);
  2475. text = text.substring(0, offset);
  2476. this.data = this.nodeValue = text;
  2477. this.length = text.length;
  2478. var newNode = this.ownerDocument.createTextNode(newText);
  2479. if(this.parentNode){
  2480. this.parentNode.insertBefore(newNode, this.nextSibling);
  2481. }
  2482. return newNode;
  2483. }
  2484. }
  2485. _extends(Text,CharacterData);
  2486. function Comment() {
  2487. };
  2488. Comment.prototype = {
  2489. nodeName : "#comment",
  2490. nodeType : COMMENT_NODE
  2491. }
  2492. _extends(Comment,CharacterData);
  2493. function CDATASection() {
  2494. };
  2495. CDATASection.prototype = {
  2496. nodeName : "#cdata-section",
  2497. nodeType : CDATA_SECTION_NODE
  2498. }
  2499. _extends(CDATASection,CharacterData);
  2500. function DocumentType() {
  2501. }
  2502. DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
  2503. _extends(DocumentType,Node);
  2504. function Notation() {
  2505. }
  2506. Notation.prototype.nodeType = NOTATION_NODE;
  2507. _extends(Notation,Node);
  2508. function Entity() {
  2509. }
  2510. Entity.prototype.nodeType = ENTITY_NODE;
  2511. _extends(Entity,Node);
  2512. function EntityReference() {
  2513. }
  2514. EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
  2515. _extends(EntityReference,Node);
  2516. function DocumentFragment() {
  2517. }
  2518. DocumentFragment.prototype.nodeName = "#document-fragment";
  2519. DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
  2520. _extends(DocumentFragment,Node);
  2521. function ProcessingInstruction() {
  2522. }
  2523. ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
  2524. _extends(ProcessingInstruction,Node);
  2525. function XMLSerializer(){}
  2526. XMLSerializer.prototype.serializeToString = function(node){
  2527. var buf = [];
  2528. serializeToString(node,buf);
  2529. return buf.join('');
  2530. }
  2531. Node.prototype.toString =function(){
  2532. return XMLSerializer.prototype.serializeToString(this);
  2533. }
  2534. function serializeToString(node,buf){
  2535. switch(node.nodeType){
  2536. case ELEMENT_NODE:
  2537. var attrs = node.attributes;
  2538. var len = attrs.length;
  2539. var child = node.firstChild;
  2540. var nodeName = node.tagName;
  2541. var isHTML = htmlns === node.namespaceURI;
  2542. buf.push('<',nodeName);
  2543. for(var i=0;i<len;i++){
  2544. serializeToString(attrs.item(i),buf);
  2545. }
  2546. if(child || isHTML && !/^(?:meta|link|img|br|hr|input|button)$/i.test(nodeName)){
  2547. buf.push('>');
  2548. if(isHTML && /^script$/i.test(nodeName)){
  2549. if(child){
  2550. buf.push(child.data);
  2551. }
  2552. }else{
  2553. while(child){
  2554. serializeToString(child,buf);
  2555. child = child.nextSibling;
  2556. }
  2557. }
  2558. buf.push('</',nodeName,'>');
  2559. }else{
  2560. buf.push('/>');
  2561. }
  2562. return;
  2563. case DOCUMENT_NODE:
  2564. case DOCUMENT_FRAGMENT_NODE:
  2565. var child = node.firstChild;
  2566. while(child){
  2567. serializeToString(child,buf);
  2568. child = child.nextSibling;
  2569. }
  2570. return;
  2571. case ATTRIBUTE_NODE:
  2572. return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
  2573. case TEXT_NODE:
  2574. return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
  2575. case CDATA_SECTION_NODE:
  2576. return buf.push( '<![CDATA[',node.data,']]>');
  2577. case COMMENT_NODE:
  2578. return buf.push( "<!--",node.data,"-->");
  2579. case DOCUMENT_TYPE_NODE:
  2580. var pubid = node.publicId;
  2581. var sysid = node.systemId;
  2582. buf.push('<!DOCTYPE ',node.name);
  2583. if(pubid){
  2584. buf.push(' PUBLIC "',pubid);
  2585. if (sysid && sysid!='.') {
  2586. buf.push( '" "',sysid);
  2587. }
  2588. buf.push('">');
  2589. }else if(sysid && sysid!='.'){
  2590. buf.push(' SYSTEM "',sysid,'">');
  2591. }else{
  2592. var sub = node.internalSubset;
  2593. if(sub){
  2594. buf.push(" [",sub,"]");
  2595. }
  2596. buf.push(">");
  2597. }
  2598. return;
  2599. case PROCESSING_INSTRUCTION_NODE:
  2600. return buf.push( "<?",node.target," ",node.data,"?>");
  2601. case ENTITY_REFERENCE_NODE:
  2602. return buf.push( '&',node.nodeName,';');
  2603. default:
  2604. buf.push('??',node.nodeName);
  2605. }
  2606. }
  2607. function importNode(doc,node,deep){
  2608. var node2;
  2609. switch (node.nodeType) {
  2610. case ELEMENT_NODE:
  2611. node2 = node.cloneNode(false);
  2612. node2.ownerDocument = doc;
  2613. case DOCUMENT_FRAGMENT_NODE:
  2614. break;
  2615. case ATTRIBUTE_NODE:
  2616. deep = true;
  2617. break;
  2618. }
  2619. if(!node2){
  2620. node2 = node.cloneNode(false);//false
  2621. }
  2622. node2.ownerDocument = doc;
  2623. node2.parentNode = null;
  2624. if(deep){
  2625. var child = node.firstChild;
  2626. while(child){
  2627. node2.appendChild(importNode(doc,child,deep));
  2628. child = child.nextSibling;
  2629. }
  2630. }
  2631. return node2;
  2632. }
  2633. function cloneNode(doc,node,deep){
  2634. var node2 = new node.constructor();
  2635. for(var n in node){
  2636. var v = node[n];
  2637. if(typeof v != 'object' ){
  2638. if(v != node2[n]){
  2639. node2[n] = v;
  2640. }
  2641. }
  2642. }
  2643. if(node.childNodes){
  2644. node2.childNodes = new NodeList();
  2645. }
  2646. node2.ownerDocument = doc;
  2647. switch (node2.nodeType) {
  2648. case ELEMENT_NODE:
  2649. var attrs = node.attributes;
  2650. var attrs2 = node2.attributes = new NamedNodeMap();
  2651. var len = attrs.length;
  2652. attrs2._ownerElement = node2;
  2653. for(var i=0;i<len;i++){
  2654. node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
  2655. }
  2656. break;
  2657. case ATTRIBUTE_NODE:
  2658. deep = true;
  2659. }
  2660. if(deep){
  2661. var child = node.firstChild;
  2662. while(child){
  2663. node2.appendChild(cloneNode(doc,child,deep));
  2664. child = child.nextSibling;
  2665. }
  2666. }
  2667. return node2;
  2668. }
  2669. function __set__(object,key,value){
  2670. object[key] = value;
  2671. }
  2672. function getTextContent(node){
  2673. switch(node.nodeType){
  2674. case 1:
  2675. case 11:
  2676. var buf = [];
  2677. node = node.firstChild;
  2678. while(node){
  2679. if(node.nodeType!==7 && node.nodeType !==8){
  2680. buf.push(getTextContent(node));
  2681. }
  2682. node = node.nextSibling;
  2683. }
  2684. return buf.join('');
  2685. default:
  2686. return node.nodeValue;
  2687. }
  2688. }
  2689. try{
  2690. if(Object.defineProperty){
  2691. Object.defineProperty(LiveNodeList.prototype,'length',{
  2692. get:function(){
  2693. _updateLiveList(this);
  2694. return this.$$length;
  2695. }
  2696. });
  2697. Object.defineProperty(Node.prototype,'textContent',{
  2698. get:function(){
  2699. return getTextContent(this);
  2700. },
  2701. set:function(data){
  2702. switch(this.nodeType){
  2703. case 1:
  2704. case 11:
  2705. while(this.firstChild){
  2706. this.removeChild(this.firstChild);
  2707. }
  2708. if(data || String(data)){
  2709. this.appendChild(this.ownerDocument.createTextNode(data));
  2710. }
  2711. break;
  2712. default:
  2713. this.data = data;
  2714. this.value = value;
  2715. this.nodeValue = data;
  2716. }
  2717. }
  2718. });
  2719. __set__ = function(object,key,value){
  2720. object['$$'+key] = value;
  2721. };
  2722. }
  2723. }catch(e){//ie8
  2724. }
  2725. return DOMImplementation;
  2726. });
  2727. ace.define("ace/mode/xml/dom-parser",[], function(require, exports, module) {
  2728. 'use strict';
  2729. var XMLReader = require('./sax'),
  2730. DOMImplementation = require('./dom');
  2731. function DOMParser(options){
  2732. this.options = options ||{locator:{}};
  2733. }
  2734. DOMParser.prototype.parseFromString = function(source,mimeType){
  2735. var options = this.options;
  2736. var sax = new XMLReader();
  2737. var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
  2738. var errorHandler = options.errorHandler;
  2739. var locator = options.locator;
  2740. var defaultNSMap = options.xmlns||{};
  2741. var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
  2742. if(locator){
  2743. domBuilder.setDocumentLocator(locator)
  2744. }
  2745. sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
  2746. sax.domBuilder = options.domBuilder || domBuilder;
  2747. if(/\/x?html?$/.test(mimeType)){
  2748. entityMap.nbsp = '\xa0';
  2749. entityMap.copy = '\xa9';
  2750. defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
  2751. }
  2752. if(source){
  2753. sax.parse(source,defaultNSMap,entityMap);
  2754. }else{
  2755. sax.errorHandler.error("invalid document source");
  2756. }
  2757. return domBuilder.document;
  2758. }
  2759. function buildErrorHandler(errorImpl,domBuilder,locator){
  2760. if(!errorImpl){
  2761. if(domBuilder instanceof DOMHandler){
  2762. return domBuilder;
  2763. }
  2764. errorImpl = domBuilder ;
  2765. }
  2766. var errorHandler = {}
  2767. var isCallback = errorImpl instanceof Function;
  2768. locator = locator||{}
  2769. function build(key){
  2770. var fn = errorImpl[key];
  2771. if(!fn){
  2772. if(isCallback){
  2773. fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
  2774. }else{
  2775. var i=arguments.length;
  2776. while(--i){
  2777. if(fn = errorImpl[arguments[i]]){
  2778. break;
  2779. }
  2780. }
  2781. }
  2782. }
  2783. errorHandler[key] = fn && function(msg){
  2784. fn(msg+_locator(locator), msg, locator);
  2785. }||function(){};
  2786. }
  2787. build('warning','warn');
  2788. build('error','warn','warning');
  2789. build('fatalError','warn','warning','error');
  2790. return errorHandler;
  2791. }
  2792. function DOMHandler() {
  2793. this.cdata = false;
  2794. }
  2795. function position(locator,node){
  2796. node.lineNumber = locator.lineNumber;
  2797. node.columnNumber = locator.columnNumber;
  2798. }
  2799. DOMHandler.prototype = {
  2800. startDocument : function() {
  2801. this.document = new DOMImplementation().createDocument(null, null, null);
  2802. if (this.locator) {
  2803. this.document.documentURI = this.locator.systemId;
  2804. }
  2805. },
  2806. startElement:function(namespaceURI, localName, qName, attrs) {
  2807. var doc = this.document;
  2808. var el = doc.createElementNS(namespaceURI, qName||localName);
  2809. var len = attrs.length;
  2810. appendElement(this, el);
  2811. this.currentElement = el;
  2812. this.locator && position(this.locator,el)
  2813. for (var i = 0 ; i < len; i++) {
  2814. var namespaceURI = attrs.getURI(i);
  2815. var value = attrs.getValue(i);
  2816. var qName = attrs.getQName(i);
  2817. var attr = doc.createAttributeNS(namespaceURI, qName);
  2818. if( attr.getOffset){
  2819. position(attr.getOffset(1),attr)
  2820. }
  2821. attr.value = attr.nodeValue = value;
  2822. el.setAttributeNode(attr)
  2823. }
  2824. },
  2825. endElement:function(namespaceURI, localName, qName) {
  2826. var current = this.currentElement
  2827. var tagName = current.tagName;
  2828. this.currentElement = current.parentNode;
  2829. },
  2830. startPrefixMapping:function(prefix, uri) {
  2831. },
  2832. endPrefixMapping:function(prefix) {
  2833. },
  2834. processingInstruction:function(target, data) {
  2835. var ins = this.document.createProcessingInstruction(target, data);
  2836. this.locator && position(this.locator,ins)
  2837. appendElement(this, ins);
  2838. },
  2839. ignorableWhitespace:function(ch, start, length) {
  2840. },
  2841. characters:function(chars, start, length) {
  2842. chars = _toString.apply(this,arguments)
  2843. if(this.currentElement && chars){
  2844. if (this.cdata) {
  2845. var charNode = this.document.createCDATASection(chars);
  2846. this.currentElement.appendChild(charNode);
  2847. } else {
  2848. var charNode = this.document.createTextNode(chars);
  2849. this.currentElement.appendChild(charNode);
  2850. }
  2851. this.locator && position(this.locator,charNode)
  2852. }
  2853. },
  2854. skippedEntity:function(name) {
  2855. },
  2856. endDocument:function() {
  2857. this.document.normalize();
  2858. },
  2859. setDocumentLocator:function (locator) {
  2860. if(this.locator = locator){// && !('lineNumber' in locator)){
  2861. locator.lineNumber = 0;
  2862. }
  2863. },
  2864. comment:function(chars, start, length) {
  2865. chars = _toString.apply(this,arguments)
  2866. var comm = this.document.createComment(chars);
  2867. this.locator && position(this.locator,comm)
  2868. appendElement(this, comm);
  2869. },
  2870. startCDATA:function() {
  2871. this.cdata = true;
  2872. },
  2873. endCDATA:function() {
  2874. this.cdata = false;
  2875. },
  2876. startDTD:function(name, publicId, systemId) {
  2877. var impl = this.document.implementation;
  2878. if (impl && impl.createDocumentType) {
  2879. var dt = impl.createDocumentType(name, publicId, systemId);
  2880. this.locator && position(this.locator,dt)
  2881. appendElement(this, dt);
  2882. }
  2883. },
  2884. warning:function(error) {
  2885. console.warn(error,_locator(this.locator));
  2886. },
  2887. error:function(error) {
  2888. console.error(error,_locator(this.locator));
  2889. },
  2890. fatalError:function(error) {
  2891. console.error(error,_locator(this.locator));
  2892. throw error;
  2893. }
  2894. }
  2895. function _locator(l){
  2896. if(l){
  2897. return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
  2898. }
  2899. }
  2900. function _toString(chars,start,length){
  2901. if(typeof chars == 'string'){
  2902. return chars.substr(start,length)
  2903. }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
  2904. if(chars.length >= start+length || start){
  2905. return new java.lang.String(chars,start,length)+'';
  2906. }
  2907. return chars;
  2908. }
  2909. }
  2910. "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
  2911. DOMHandler.prototype[key] = function(){return null}
  2912. })
  2913. function appendElement (hander,node) {
  2914. if (!hander.currentElement) {
  2915. hander.document.appendChild(node);
  2916. } else {
  2917. hander.currentElement.appendChild(node);
  2918. }
  2919. }//appendChild and setAttributeNS are preformance key
  2920. return {
  2921. DOMParser: DOMParser
  2922. };
  2923. });
  2924. ace.define("ace/mode/xml_worker",[], function(require, exports, module) {
  2925. "use strict";
  2926. var oop = require("../lib/oop");
  2927. var lang = require("../lib/lang");
  2928. var Mirror = require("../worker/mirror").Mirror;
  2929. var DOMParser = require("./xml/dom-parser").DOMParser;
  2930. var Worker = exports.Worker = function(sender) {
  2931. Mirror.call(this, sender);
  2932. this.setTimeout(400);
  2933. this.context = null;
  2934. };
  2935. oop.inherits(Worker, Mirror);
  2936. (function() {
  2937. this.setOptions = function(options) {
  2938. this.context = options.context;
  2939. };
  2940. this.onUpdate = function() {
  2941. var value = this.doc.getValue();
  2942. if (!value)
  2943. return;
  2944. var parser = new DOMParser();
  2945. var errors = [];
  2946. parser.options.errorHandler = {
  2947. fatalError: function(fullMsg, errorMsg, locator) {
  2948. errors.push({
  2949. row: locator.lineNumber,
  2950. column: locator.columnNumber,
  2951. text: errorMsg,
  2952. type: "error"
  2953. });
  2954. },
  2955. error: function(fullMsg, errorMsg, locator) {
  2956. errors.push({
  2957. row: locator.lineNumber,
  2958. column: locator.columnNumber,
  2959. text: errorMsg,
  2960. type: "error"
  2961. });
  2962. },
  2963. warning: function(fullMsg, errorMsg, locator) {
  2964. errors.push({
  2965. row: locator.lineNumber,
  2966. column: locator.columnNumber,
  2967. text: errorMsg,
  2968. type: "warning"
  2969. });
  2970. }
  2971. };
  2972. parser.parseFromString(value);
  2973. this.sender.emit("error", errors);
  2974. };
  2975. }).call(Worker.prototype);
  2976. });