worker-xml.js 110 KB

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