worker-xml.js 89 KB

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