d5452f10ffab904fba74ca2956dc9532.js 89 KB

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