Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

plist-parse.js 118KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.plist = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
  2. (function (Buffer){
  3. /**
  4. * Module dependencies.
  5. */
  6. var DOMParser = require('xmldom').DOMParser;
  7. /**
  8. * Module exports.
  9. */
  10. exports.parse = parse;
  11. var TEXT_NODE = 3;
  12. var CDATA_NODE = 4;
  13. var COMMENT_NODE = 8;
  14. /**
  15. * We ignore raw text (usually whitespace), <!-- xml comments -->,
  16. * and raw CDATA nodes.
  17. *
  18. * @param {Element} node
  19. * @returns {Boolean}
  20. * @api private
  21. */
  22. function shouldIgnoreNode (node) {
  23. return node.nodeType === TEXT_NODE
  24. || node.nodeType === COMMENT_NODE
  25. || node.nodeType === CDATA_NODE;
  26. }
  27. /**
  28. * Check if the node is empty. Some plist file has such node:
  29. * <key />
  30. * this node shoud be ignored.
  31. *
  32. * @see https://github.com/TooTallNate/plist.js/issues/66
  33. * @param {Element} node
  34. * @returns {Boolean}
  35. * @api private
  36. */
  37. function isEmptyNode(node){
  38. if(!node.childNodes || node.childNodes.length === 0) {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }
  44. function invariant(test, message) {
  45. if (!test) {
  46. throw new Error(message);
  47. }
  48. }
  49. /**
  50. * Parses a Plist XML string. Returns an Object.
  51. *
  52. * @param {String} xml - the XML String to decode
  53. * @returns {Mixed} the decoded value from the Plist XML
  54. * @api public
  55. */
  56. function parse (xml) {
  57. var doc = new DOMParser().parseFromString(xml);
  58. invariant(
  59. doc.documentElement.nodeName === 'plist',
  60. 'malformed document. First element should be <plist>'
  61. );
  62. var plist = parsePlistXML(doc.documentElement);
  63. // the root <plist> node gets interpreted as an Array,
  64. // so pull out the inner data first
  65. if (plist.length == 1) plist = plist[0];
  66. return plist;
  67. }
  68. /**
  69. * Convert an XML based plist document into a JSON representation.
  70. *
  71. * @param {Object} xml_node - current XML node in the plist
  72. * @returns {Mixed} built up JSON object
  73. * @api private
  74. */
  75. function parsePlistXML (node) {
  76. var i, new_obj, key, val, new_arr, res, counter, type;
  77. if (!node)
  78. return null;
  79. if (node.nodeName === 'plist') {
  80. new_arr = [];
  81. if (isEmptyNode(node)) {
  82. return new_arr;
  83. }
  84. for (i=0; i < node.childNodes.length; i++) {
  85. if (!shouldIgnoreNode(node.childNodes[i])) {
  86. new_arr.push( parsePlistXML(node.childNodes[i]));
  87. }
  88. }
  89. return new_arr;
  90. } else if (node.nodeName === 'dict') {
  91. new_obj = {};
  92. key = null;
  93. counter = 0;
  94. if (isEmptyNode(node)) {
  95. return new_obj;
  96. }
  97. for (i=0; i < node.childNodes.length; i++) {
  98. if (shouldIgnoreNode(node.childNodes[i])) continue;
  99. if (counter % 2 === 0) {
  100. invariant(
  101. node.childNodes[i].nodeName === 'key',
  102. 'Missing key while parsing <dict/>.'
  103. );
  104. key = parsePlistXML(node.childNodes[i]);
  105. } else {
  106. invariant(
  107. node.childNodes[i].nodeName !== 'key',
  108. 'Unexpected key "'
  109. + parsePlistXML(node.childNodes[i])
  110. + '" while parsing <dict/>.'
  111. );
  112. new_obj[key] = parsePlistXML(node.childNodes[i]);
  113. }
  114. counter += 1;
  115. }
  116. if (counter % 2 === 1) {
  117. throw new Error('Missing value for "' + key + '" while parsing <dict/>');
  118. }
  119. return new_obj;
  120. } else if (node.nodeName === 'array') {
  121. new_arr = [];
  122. if (isEmptyNode(node)) {
  123. return new_arr;
  124. }
  125. for (i=0; i < node.childNodes.length; i++) {
  126. if (!shouldIgnoreNode(node.childNodes[i])) {
  127. res = parsePlistXML(node.childNodes[i]);
  128. if (null != res) new_arr.push(res);
  129. }
  130. }
  131. return new_arr;
  132. } else if (node.nodeName === '#text') {
  133. // TODO: what should we do with text types? (CDATA sections)
  134. } else if (node.nodeName === 'key') {
  135. if (isEmptyNode(node)) {
  136. return '';
  137. }
  138. return node.childNodes[0].nodeValue;
  139. } else if (node.nodeName === 'string') {
  140. res = '';
  141. if (isEmptyNode(node)) {
  142. return res;
  143. }
  144. for (i=0; i < node.childNodes.length; i++) {
  145. var type = node.childNodes[i].nodeType;
  146. if (type === TEXT_NODE || type === CDATA_NODE) {
  147. res += node.childNodes[i].nodeValue;
  148. }
  149. }
  150. return res;
  151. } else if (node.nodeName === 'integer') {
  152. invariant(
  153. !isEmptyNode(node),
  154. 'Cannot parse "" as integer.'
  155. );
  156. return parseInt(node.childNodes[0].nodeValue, 10);
  157. } else if (node.nodeName === 'real') {
  158. invariant(
  159. !isEmptyNode(node),
  160. 'Cannot parse "" as real.'
  161. );
  162. res = '';
  163. for (i=0; i < node.childNodes.length; i++) {
  164. if (node.childNodes[i].nodeType === TEXT_NODE) {
  165. res += node.childNodes[i].nodeValue;
  166. }
  167. }
  168. return parseFloat(res);
  169. } else if (node.nodeName === 'data') {
  170. res = '';
  171. if (isEmptyNode(node)) {
  172. return Buffer.from(res, 'base64');
  173. }
  174. for (i=0; i < node.childNodes.length; i++) {
  175. if (node.childNodes[i].nodeType === TEXT_NODE) {
  176. res += node.childNodes[i].nodeValue.replace(/\s+/g, '');
  177. }
  178. }
  179. return Buffer.from(res, 'base64');
  180. } else if (node.nodeName === 'date') {
  181. invariant(
  182. !isEmptyNode(node),
  183. 'Cannot parse "" as Date.'
  184. )
  185. return new Date(node.childNodes[0].nodeValue);
  186. } else if (node.nodeName === 'true') {
  187. return true;
  188. } else if (node.nodeName === 'false') {
  189. return false;
  190. }
  191. }
  192. }).call(this,require("buffer").Buffer)
  193. },{"buffer":3,"xmldom":5}],2:[function(require,module,exports){
  194. 'use strict'
  195. exports.byteLength = byteLength
  196. exports.toByteArray = toByteArray
  197. exports.fromByteArray = fromByteArray
  198. var lookup = []
  199. var revLookup = []
  200. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  201. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  202. for (var i = 0, len = code.length; i < len; ++i) {
  203. lookup[i] = code[i]
  204. revLookup[code.charCodeAt(i)] = i
  205. }
  206. // Support decoding URL-safe base64 strings, as Node.js does.
  207. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  208. revLookup['-'.charCodeAt(0)] = 62
  209. revLookup['_'.charCodeAt(0)] = 63
  210. function placeHoldersCount (b64) {
  211. var len = b64.length
  212. if (len % 4 > 0) {
  213. throw new Error('Invalid string. Length must be a multiple of 4')
  214. }
  215. // the number of equal signs (place holders)
  216. // if there are two placeholders, than the two characters before it
  217. // represent one byte
  218. // if there is only one, then the three characters before it represent 2 bytes
  219. // this is just a cheap hack to not do indexOf twice
  220. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  221. }
  222. function byteLength (b64) {
  223. // base64 is 4/3 + up to two characters of the original data
  224. return (b64.length * 3 / 4) - placeHoldersCount(b64)
  225. }
  226. function toByteArray (b64) {
  227. var i, l, tmp, placeHolders, arr
  228. var len = b64.length
  229. placeHolders = placeHoldersCount(b64)
  230. arr = new Arr((len * 3 / 4) - placeHolders)
  231. // if there are placeholders, only get up to the last complete 4 chars
  232. l = placeHolders > 0 ? len - 4 : len
  233. var L = 0
  234. for (i = 0; i < l; i += 4) {
  235. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  236. arr[L++] = (tmp >> 16) & 0xFF
  237. arr[L++] = (tmp >> 8) & 0xFF
  238. arr[L++] = tmp & 0xFF
  239. }
  240. if (placeHolders === 2) {
  241. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  242. arr[L++] = tmp & 0xFF
  243. } else if (placeHolders === 1) {
  244. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  245. arr[L++] = (tmp >> 8) & 0xFF
  246. arr[L++] = tmp & 0xFF
  247. }
  248. return arr
  249. }
  250. function tripletToBase64 (num) {
  251. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  252. }
  253. function encodeChunk (uint8, start, end) {
  254. var tmp
  255. var output = []
  256. for (var i = start; i < end; i += 3) {
  257. tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF)
  258. output.push(tripletToBase64(tmp))
  259. }
  260. return output.join('')
  261. }
  262. function fromByteArray (uint8) {
  263. var tmp
  264. var len = uint8.length
  265. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  266. var output = ''
  267. var parts = []
  268. var maxChunkLength = 16383 // must be multiple of 3
  269. // go through the array every three bytes, we'll deal with trailing stuff later
  270. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  271. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  272. }
  273. // pad the end with zeros, but make sure to not forget the extra bytes
  274. if (extraBytes === 1) {
  275. tmp = uint8[len - 1]
  276. output += lookup[tmp >> 2]
  277. output += lookup[(tmp << 4) & 0x3F]
  278. output += '=='
  279. } else if (extraBytes === 2) {
  280. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  281. output += lookup[tmp >> 10]
  282. output += lookup[(tmp >> 4) & 0x3F]
  283. output += lookup[(tmp << 2) & 0x3F]
  284. output += '='
  285. }
  286. parts.push(output)
  287. return parts.join('')
  288. }
  289. },{}],3:[function(require,module,exports){
  290. /*!
  291. * The buffer module from node.js, for the browser.
  292. *
  293. * @author Feross Aboukhadijeh <https://feross.org>
  294. * @license MIT
  295. */
  296. /* eslint-disable no-proto */
  297. 'use strict'
  298. var base64 = require('base64-js')
  299. var ieee754 = require('ieee754')
  300. exports.Buffer = Buffer
  301. exports.SlowBuffer = SlowBuffer
  302. exports.INSPECT_MAX_BYTES = 50
  303. var K_MAX_LENGTH = 0x7fffffff
  304. exports.kMaxLength = K_MAX_LENGTH
  305. /**
  306. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  307. * === true Use Uint8Array implementation (fastest)
  308. * === false Print warning and recommend using `buffer` v4.x which has an Object
  309. * implementation (most compatible, even IE6)
  310. *
  311. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  312. * Opera 11.6+, iOS 4.2+.
  313. *
  314. * We report that the browser does not support typed arrays if the are not subclassable
  315. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  316. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  317. * for __proto__ and has a buggy typed array implementation.
  318. */
  319. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  320. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  321. typeof console.error === 'function') {
  322. console.error(
  323. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  324. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  325. )
  326. }
  327. function typedArraySupport () {
  328. // Can typed array instances can be augmented?
  329. try {
  330. var arr = new Uint8Array(1)
  331. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  332. return arr.foo() === 42
  333. } catch (e) {
  334. return false
  335. }
  336. }
  337. Object.defineProperty(Buffer.prototype, 'parent', {
  338. get: function () {
  339. if (!(this instanceof Buffer)) {
  340. return undefined
  341. }
  342. return this.buffer
  343. }
  344. })
  345. Object.defineProperty(Buffer.prototype, 'offset', {
  346. get: function () {
  347. if (!(this instanceof Buffer)) {
  348. return undefined
  349. }
  350. return this.byteOffset
  351. }
  352. })
  353. function createBuffer (length) {
  354. if (length > K_MAX_LENGTH) {
  355. throw new RangeError('Invalid typed array length')
  356. }
  357. // Return an augmented `Uint8Array` instance
  358. var buf = new Uint8Array(length)
  359. buf.__proto__ = Buffer.prototype
  360. return buf
  361. }
  362. /**
  363. * The Buffer constructor returns instances of `Uint8Array` that have their
  364. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  365. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  366. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  367. * returns a single octet.
  368. *
  369. * The `Uint8Array` prototype remains unmodified.
  370. */
  371. function Buffer (arg, encodingOrOffset, length) {
  372. // Common case.
  373. if (typeof arg === 'number') {
  374. if (typeof encodingOrOffset === 'string') {
  375. throw new Error(
  376. 'If encoding is specified then the first argument must be a string'
  377. )
  378. }
  379. return allocUnsafe(arg)
  380. }
  381. return from(arg, encodingOrOffset, length)
  382. }
  383. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  384. if (typeof Symbol !== 'undefined' && Symbol.species &&
  385. Buffer[Symbol.species] === Buffer) {
  386. Object.defineProperty(Buffer, Symbol.species, {
  387. value: null,
  388. configurable: true,
  389. enumerable: false,
  390. writable: false
  391. })
  392. }
  393. Buffer.poolSize = 8192 // not used by this implementation
  394. function from (value, encodingOrOffset, length) {
  395. if (typeof value === 'number') {
  396. throw new TypeError('"value" argument must not be a number')
  397. }
  398. if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
  399. return fromArrayBuffer(value, encodingOrOffset, length)
  400. }
  401. if (typeof value === 'string') {
  402. return fromString(value, encodingOrOffset)
  403. }
  404. return fromObject(value)
  405. }
  406. /**
  407. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  408. * if value is a number.
  409. * Buffer.from(str[, encoding])
  410. * Buffer.from(array)
  411. * Buffer.from(buffer)
  412. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  413. **/
  414. Buffer.from = function (value, encodingOrOffset, length) {
  415. return from(value, encodingOrOffset, length)
  416. }
  417. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  418. // https://github.com/feross/buffer/pull/148
  419. Buffer.prototype.__proto__ = Uint8Array.prototype
  420. Buffer.__proto__ = Uint8Array
  421. function assertSize (size) {
  422. if (typeof size !== 'number') {
  423. throw new TypeError('"size" argument must be of type number')
  424. } else if (size < 0) {
  425. throw new RangeError('"size" argument must not be negative')
  426. }
  427. }
  428. function alloc (size, fill, encoding) {
  429. assertSize(size)
  430. if (size <= 0) {
  431. return createBuffer(size)
  432. }
  433. if (fill !== undefined) {
  434. // Only pay attention to encoding if it's a string. This
  435. // prevents accidentally sending in a number that would
  436. // be interpretted as a start offset.
  437. return typeof encoding === 'string'
  438. ? createBuffer(size).fill(fill, encoding)
  439. : createBuffer(size).fill(fill)
  440. }
  441. return createBuffer(size)
  442. }
  443. /**
  444. * Creates a new filled Buffer instance.
  445. * alloc(size[, fill[, encoding]])
  446. **/
  447. Buffer.alloc = function (size, fill, encoding) {
  448. return alloc(size, fill, encoding)
  449. }
  450. function allocUnsafe (size) {
  451. assertSize(size)
  452. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  453. }
  454. /**
  455. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  456. * */
  457. Buffer.allocUnsafe = function (size) {
  458. return allocUnsafe(size)
  459. }
  460. /**
  461. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  462. */
  463. Buffer.allocUnsafeSlow = function (size) {
  464. return allocUnsafe(size)
  465. }
  466. function fromString (string, encoding) {
  467. if (typeof encoding !== 'string' || encoding === '') {
  468. encoding = 'utf8'
  469. }
  470. if (!Buffer.isEncoding(encoding)) {
  471. throw new TypeError('Unknown encoding: ' + encoding)
  472. }
  473. var length = byteLength(string, encoding) | 0
  474. var buf = createBuffer(length)
  475. var actual = buf.write(string, encoding)
  476. if (actual !== length) {
  477. // Writing a hex string, for example, that contains invalid characters will
  478. // cause everything after the first invalid character to be ignored. (e.g.
  479. // 'abxxcd' will be treated as 'ab')
  480. buf = buf.slice(0, actual)
  481. }
  482. return buf
  483. }
  484. function fromArrayLike (array) {
  485. var length = array.length < 0 ? 0 : checked(array.length) | 0
  486. var buf = createBuffer(length)
  487. for (var i = 0; i < length; i += 1) {
  488. buf[i] = array[i] & 255
  489. }
  490. return buf
  491. }
  492. function fromArrayBuffer (array, byteOffset, length) {
  493. if (byteOffset < 0 || array.byteLength < byteOffset) {
  494. throw new RangeError('"offset" is outside of buffer bounds')
  495. }
  496. if (array.byteLength < byteOffset + (length || 0)) {
  497. throw new RangeError('"length" is outside of buffer bounds')
  498. }
  499. var buf
  500. if (byteOffset === undefined && length === undefined) {
  501. buf = new Uint8Array(array)
  502. } else if (length === undefined) {
  503. buf = new Uint8Array(array, byteOffset)
  504. } else {
  505. buf = new Uint8Array(array, byteOffset, length)
  506. }
  507. // Return an augmented `Uint8Array` instance
  508. buf.__proto__ = Buffer.prototype
  509. return buf
  510. }
  511. function fromObject (obj) {
  512. if (Buffer.isBuffer(obj)) {
  513. var len = checked(obj.length) | 0
  514. var buf = createBuffer(len)
  515. if (buf.length === 0) {
  516. return buf
  517. }
  518. obj.copy(buf, 0, 0, len)
  519. return buf
  520. }
  521. if (obj) {
  522. if (ArrayBuffer.isView(obj) || 'length' in obj) {
  523. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  524. return createBuffer(0)
  525. }
  526. return fromArrayLike(obj)
  527. }
  528. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  529. return fromArrayLike(obj.data)
  530. }
  531. }
  532. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
  533. }
  534. function checked (length) {
  535. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  536. // length is NaN (which is otherwise coerced to zero.)
  537. if (length >= K_MAX_LENGTH) {
  538. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  539. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  540. }
  541. return length | 0
  542. }
  543. function SlowBuffer (length) {
  544. if (+length != length) { // eslint-disable-line eqeqeq
  545. length = 0
  546. }
  547. return Buffer.alloc(+length)
  548. }
  549. Buffer.isBuffer = function isBuffer (b) {
  550. return b != null && b._isBuffer === true
  551. }
  552. Buffer.compare = function compare (a, b) {
  553. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  554. throw new TypeError('Arguments must be Buffers')
  555. }
  556. if (a === b) return 0
  557. var x = a.length
  558. var y = b.length
  559. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  560. if (a[i] !== b[i]) {
  561. x = a[i]
  562. y = b[i]
  563. break
  564. }
  565. }
  566. if (x < y) return -1
  567. if (y < x) return 1
  568. return 0
  569. }
  570. Buffer.isEncoding = function isEncoding (encoding) {
  571. switch (String(encoding).toLowerCase()) {
  572. case 'hex':
  573. case 'utf8':
  574. case 'utf-8':
  575. case 'ascii':
  576. case 'latin1':
  577. case 'binary':
  578. case 'base64':
  579. case 'ucs2':
  580. case 'ucs-2':
  581. case 'utf16le':
  582. case 'utf-16le':
  583. return true
  584. default:
  585. return false
  586. }
  587. }
  588. Buffer.concat = function concat (list, length) {
  589. if (!Array.isArray(list)) {
  590. throw new TypeError('"list" argument must be an Array of Buffers')
  591. }
  592. if (list.length === 0) {
  593. return Buffer.alloc(0)
  594. }
  595. var i
  596. if (length === undefined) {
  597. length = 0
  598. for (i = 0; i < list.length; ++i) {
  599. length += list[i].length
  600. }
  601. }
  602. var buffer = Buffer.allocUnsafe(length)
  603. var pos = 0
  604. for (i = 0; i < list.length; ++i) {
  605. var buf = list[i]
  606. if (ArrayBuffer.isView(buf)) {
  607. buf = Buffer.from(buf)
  608. }
  609. if (!Buffer.isBuffer(buf)) {
  610. throw new TypeError('"list" argument must be an Array of Buffers')
  611. }
  612. buf.copy(buffer, pos)
  613. pos += buf.length
  614. }
  615. return buffer
  616. }
  617. function byteLength (string, encoding) {
  618. if (Buffer.isBuffer(string)) {
  619. return string.length
  620. }
  621. if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
  622. return string.byteLength
  623. }
  624. if (typeof string !== 'string') {
  625. string = '' + string
  626. }
  627. var len = string.length
  628. if (len === 0) return 0
  629. // Use a for loop to avoid recursion
  630. var loweredCase = false
  631. for (;;) {
  632. switch (encoding) {
  633. case 'ascii':
  634. case 'latin1':
  635. case 'binary':
  636. return len
  637. case 'utf8':
  638. case 'utf-8':
  639. case undefined:
  640. return utf8ToBytes(string).length
  641. case 'ucs2':
  642. case 'ucs-2':
  643. case 'utf16le':
  644. case 'utf-16le':
  645. return len * 2
  646. case 'hex':
  647. return len >>> 1
  648. case 'base64':
  649. return base64ToBytes(string).length
  650. default:
  651. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  652. encoding = ('' + encoding).toLowerCase()
  653. loweredCase = true
  654. }
  655. }
  656. }
  657. Buffer.byteLength = byteLength
  658. function slowToString (encoding, start, end) {
  659. var loweredCase = false
  660. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  661. // property of a typed array.
  662. // This behaves neither like String nor Uint8Array in that we set start/end
  663. // to their upper/lower bounds if the value passed is out of range.
  664. // undefined is handled specially as per ECMA-262 6th Edition,
  665. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  666. if (start === undefined || start < 0) {
  667. start = 0
  668. }
  669. // Return early if start > this.length. Done here to prevent potential uint32
  670. // coercion fail below.
  671. if (start > this.length) {
  672. return ''
  673. }
  674. if (end === undefined || end > this.length) {
  675. end = this.length
  676. }
  677. if (end <= 0) {
  678. return ''
  679. }
  680. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  681. end >>>= 0
  682. start >>>= 0
  683. if (end <= start) {
  684. return ''
  685. }
  686. if (!encoding) encoding = 'utf8'
  687. while (true) {
  688. switch (encoding) {
  689. case 'hex':
  690. return hexSlice(this, start, end)
  691. case 'utf8':
  692. case 'utf-8':
  693. return utf8Slice(this, start, end)
  694. case 'ascii':
  695. return asciiSlice(this, start, end)
  696. case 'latin1':
  697. case 'binary':
  698. return latin1Slice(this, start, end)
  699. case 'base64':
  700. return base64Slice(this, start, end)
  701. case 'ucs2':
  702. case 'ucs-2':
  703. case 'utf16le':
  704. case 'utf-16le':
  705. return utf16leSlice(this, start, end)
  706. default:
  707. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  708. encoding = (encoding + '').toLowerCase()
  709. loweredCase = true
  710. }
  711. }
  712. }
  713. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  714. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  715. // reliably in a browserify context because there could be multiple different
  716. // copies of the 'buffer' package in use. This method works even for Buffer
  717. // instances that were created from another copy of the `buffer` package.
  718. // See: https://github.com/feross/buffer/issues/154
  719. Buffer.prototype._isBuffer = true
  720. function swap (b, n, m) {
  721. var i = b[n]
  722. b[n] = b[m]
  723. b[m] = i
  724. }
  725. Buffer.prototype.swap16 = function swap16 () {
  726. var len = this.length
  727. if (len % 2 !== 0) {
  728. throw new RangeError('Buffer size must be a multiple of 16-bits')
  729. }
  730. for (var i = 0; i < len; i += 2) {
  731. swap(this, i, i + 1)
  732. }
  733. return this
  734. }
  735. Buffer.prototype.swap32 = function swap32 () {
  736. var len = this.length
  737. if (len % 4 !== 0) {
  738. throw new RangeError('Buffer size must be a multiple of 32-bits')
  739. }
  740. for (var i = 0; i < len; i += 4) {
  741. swap(this, i, i + 3)
  742. swap(this, i + 1, i + 2)
  743. }
  744. return this
  745. }
  746. Buffer.prototype.swap64 = function swap64 () {
  747. var len = this.length
  748. if (len % 8 !== 0) {
  749. throw new RangeError('Buffer size must be a multiple of 64-bits')
  750. }
  751. for (var i = 0; i < len; i += 8) {
  752. swap(this, i, i + 7)
  753. swap(this, i + 1, i + 6)
  754. swap(this, i + 2, i + 5)
  755. swap(this, i + 3, i + 4)
  756. }
  757. return this
  758. }
  759. Buffer.prototype.toString = function toString () {
  760. var length = this.length
  761. if (length === 0) return ''
  762. if (arguments.length === 0) return utf8Slice(this, 0, length)
  763. return slowToString.apply(this, arguments)
  764. }
  765. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  766. Buffer.prototype.equals = function equals (b) {
  767. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  768. if (this === b) return true
  769. return Buffer.compare(this, b) === 0
  770. }
  771. Buffer.prototype.inspect = function inspect () {
  772. var str = ''
  773. var max = exports.INSPECT_MAX_BYTES
  774. if (this.length > 0) {
  775. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  776. if (this.length > max) str += ' ... '
  777. }
  778. return '<Buffer ' + str + '>'
  779. }
  780. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  781. if (!Buffer.isBuffer(target)) {
  782. throw new TypeError('Argument must be a Buffer')
  783. }
  784. if (start === undefined) {
  785. start = 0
  786. }
  787. if (end === undefined) {
  788. end = target ? target.length : 0
  789. }
  790. if (thisStart === undefined) {
  791. thisStart = 0
  792. }
  793. if (thisEnd === undefined) {
  794. thisEnd = this.length
  795. }
  796. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  797. throw new RangeError('out of range index')
  798. }
  799. if (thisStart >= thisEnd && start >= end) {
  800. return 0
  801. }
  802. if (thisStart >= thisEnd) {
  803. return -1
  804. }
  805. if (start >= end) {
  806. return 1
  807. }
  808. start >>>= 0
  809. end >>>= 0
  810. thisStart >>>= 0
  811. thisEnd >>>= 0
  812. if (this === target) return 0
  813. var x = thisEnd - thisStart
  814. var y = end - start
  815. var len = Math.min(x, y)
  816. var thisCopy = this.slice(thisStart, thisEnd)
  817. var targetCopy = target.slice(start, end)
  818. for (var i = 0; i < len; ++i) {
  819. if (thisCopy[i] !== targetCopy[i]) {
  820. x = thisCopy[i]
  821. y = targetCopy[i]
  822. break
  823. }
  824. }
  825. if (x < y) return -1
  826. if (y < x) return 1
  827. return 0
  828. }
  829. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  830. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  831. //
  832. // Arguments:
  833. // - buffer - a Buffer to search
  834. // - val - a string, Buffer, or number
  835. // - byteOffset - an index into `buffer`; will be clamped to an int32
  836. // - encoding - an optional encoding, relevant is val is a string
  837. // - dir - true for indexOf, false for lastIndexOf
  838. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  839. // Empty buffer means no match
  840. if (buffer.length === 0) return -1
  841. // Normalize byteOffset
  842. if (typeof byteOffset === 'string') {
  843. encoding = byteOffset
  844. byteOffset = 0
  845. } else if (byteOffset > 0x7fffffff) {
  846. byteOffset = 0x7fffffff
  847. } else if (byteOffset < -0x80000000) {
  848. byteOffset = -0x80000000
  849. }
  850. byteOffset = +byteOffset // Coerce to Number.
  851. if (numberIsNaN(byteOffset)) {
  852. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  853. byteOffset = dir ? 0 : (buffer.length - 1)
  854. }
  855. // Normalize byteOffset: negative offsets start from the end of the buffer
  856. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  857. if (byteOffset >= buffer.length) {
  858. if (dir) return -1
  859. else byteOffset = buffer.length - 1
  860. } else if (byteOffset < 0) {
  861. if (dir) byteOffset = 0
  862. else return -1
  863. }
  864. // Normalize val
  865. if (typeof val === 'string') {
  866. val = Buffer.from(val, encoding)
  867. }
  868. // Finally, search either indexOf (if dir is true) or lastIndexOf
  869. if (Buffer.isBuffer(val)) {
  870. // Special case: looking for empty string/buffer always fails
  871. if (val.length === 0) {
  872. return -1
  873. }
  874. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  875. } else if (typeof val === 'number') {
  876. val = val & 0xFF // Search for a byte value [0-255]
  877. if (typeof Uint8Array.prototype.indexOf === 'function') {
  878. if (dir) {
  879. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  880. } else {
  881. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  882. }
  883. }
  884. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  885. }
  886. throw new TypeError('val must be string, number or Buffer')
  887. }
  888. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  889. var indexSize = 1
  890. var arrLength = arr.length
  891. var valLength = val.length
  892. if (encoding !== undefined) {
  893. encoding = String(encoding).toLowerCase()
  894. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  895. encoding === 'utf16le' || encoding === 'utf-16le') {
  896. if (arr.length < 2 || val.length < 2) {
  897. return -1
  898. }
  899. indexSize = 2
  900. arrLength /= 2
  901. valLength /= 2
  902. byteOffset /= 2
  903. }
  904. }
  905. function read (buf, i) {
  906. if (indexSize === 1) {
  907. return buf[i]
  908. } else {
  909. return buf.readUInt16BE(i * indexSize)
  910. }
  911. }
  912. var i
  913. if (dir) {
  914. var foundIndex = -1
  915. for (i = byteOffset; i < arrLength; i++) {
  916. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  917. if (foundIndex === -1) foundIndex = i
  918. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  919. } else {
  920. if (foundIndex !== -1) i -= i - foundIndex
  921. foundIndex = -1
  922. }
  923. }
  924. } else {
  925. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  926. for (i = byteOffset; i >= 0; i--) {
  927. var found = true
  928. for (var j = 0; j < valLength; j++) {
  929. if (read(arr, i + j) !== read(val, j)) {
  930. found = false
  931. break
  932. }
  933. }
  934. if (found) return i
  935. }
  936. }
  937. return -1
  938. }
  939. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  940. return this.indexOf(val, byteOffset, encoding) !== -1
  941. }
  942. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  943. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  944. }
  945. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  946. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  947. }
  948. function hexWrite (buf, string, offset, length) {
  949. offset = Number(offset) || 0
  950. var remaining = buf.length - offset
  951. if (!length) {
  952. length = remaining
  953. } else {
  954. length = Number(length)
  955. if (length > remaining) {
  956. length = remaining
  957. }
  958. }
  959. var strLen = string.length
  960. if (length > strLen / 2) {
  961. length = strLen / 2
  962. }
  963. for (var i = 0; i < length; ++i) {
  964. var parsed = parseInt(string.substr(i * 2, 2), 16)
  965. if (numberIsNaN(parsed)) return i
  966. buf[offset + i] = parsed
  967. }
  968. return i
  969. }
  970. function utf8Write (buf, string, offset, length) {
  971. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  972. }
  973. function asciiWrite (buf, string, offset, length) {
  974. return blitBuffer(asciiToBytes(string), buf, offset, length)
  975. }
  976. function latin1Write (buf, string, offset, length) {
  977. return asciiWrite(buf, string, offset, length)
  978. }
  979. function base64Write (buf, string, offset, length) {
  980. return blitBuffer(base64ToBytes(string), buf, offset, length)
  981. }
  982. function ucs2Write (buf, string, offset, length) {
  983. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  984. }
  985. Buffer.prototype.write = function write (string, offset, length, encoding) {
  986. // Buffer#write(string)
  987. if (offset === undefined) {
  988. encoding = 'utf8'
  989. length = this.length
  990. offset = 0
  991. // Buffer#write(string, encoding)
  992. } else if (length === undefined && typeof offset === 'string') {
  993. encoding = offset
  994. length = this.length
  995. offset = 0
  996. // Buffer#write(string, offset[, length][, encoding])
  997. } else if (isFinite(offset)) {
  998. offset = offset >>> 0
  999. if (isFinite(length)) {
  1000. length = length >>> 0
  1001. if (encoding === undefined) encoding = 'utf8'
  1002. } else {
  1003. encoding = length
  1004. length = undefined
  1005. }
  1006. } else {
  1007. throw new Error(
  1008. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  1009. )
  1010. }
  1011. var remaining = this.length - offset
  1012. if (length === undefined || length > remaining) length = remaining
  1013. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  1014. throw new RangeError('Attempt to write outside buffer bounds')
  1015. }
  1016. if (!encoding) encoding = 'utf8'
  1017. var loweredCase = false
  1018. for (;;) {
  1019. switch (encoding) {
  1020. case 'hex':
  1021. return hexWrite(this, string, offset, length)
  1022. case 'utf8':
  1023. case 'utf-8':
  1024. return utf8Write(this, string, offset, length)
  1025. case 'ascii':
  1026. return asciiWrite(this, string, offset, length)
  1027. case 'latin1':
  1028. case 'binary':
  1029. return latin1Write(this, string, offset, length)
  1030. case 'base64':
  1031. // Warning: maxLength not taken into account in base64Write
  1032. return base64Write(this, string, offset, length)
  1033. case 'ucs2':
  1034. case 'ucs-2':
  1035. case 'utf16le':
  1036. case 'utf-16le':
  1037. return ucs2Write(this, string, offset, length)
  1038. default:
  1039. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1040. encoding = ('' + encoding).toLowerCase()
  1041. loweredCase = true
  1042. }
  1043. }
  1044. }
  1045. Buffer.prototype.toJSON = function toJSON () {
  1046. return {
  1047. type: 'Buffer',
  1048. data: Array.prototype.slice.call(this._arr || this, 0)
  1049. }
  1050. }
  1051. function base64Slice (buf, start, end) {
  1052. if (start === 0 && end === buf.length) {
  1053. return base64.fromByteArray(buf)
  1054. } else {
  1055. return base64.fromByteArray(buf.slice(start, end))
  1056. }
  1057. }
  1058. function utf8Slice (buf, start, end) {
  1059. end = Math.min(buf.length, end)
  1060. var res = []
  1061. var i = start
  1062. while (i < end) {
  1063. var firstByte = buf[i]
  1064. var codePoint = null
  1065. var bytesPerSequence = (firstByte > 0xEF) ? 4
  1066. : (firstByte > 0xDF) ? 3
  1067. : (firstByte > 0xBF) ? 2
  1068. : 1
  1069. if (i + bytesPerSequence <= end) {
  1070. var secondByte, thirdByte, fourthByte, tempCodePoint
  1071. switch (bytesPerSequence) {
  1072. case 1:
  1073. if (firstByte < 0x80) {
  1074. codePoint = firstByte
  1075. }
  1076. break
  1077. case 2:
  1078. secondByte = buf[i + 1]
  1079. if ((secondByte & 0xC0) === 0x80) {
  1080. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  1081. if (tempCodePoint > 0x7F) {
  1082. codePoint = tempCodePoint
  1083. }
  1084. }
  1085. break
  1086. case 3:
  1087. secondByte = buf[i + 1]
  1088. thirdByte = buf[i + 2]
  1089. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  1090. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  1091. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  1092. codePoint = tempCodePoint
  1093. }
  1094. }
  1095. break
  1096. case 4:
  1097. secondByte = buf[i + 1]
  1098. thirdByte = buf[i + 2]
  1099. fourthByte = buf[i + 3]
  1100. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  1101. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  1102. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  1103. codePoint = tempCodePoint
  1104. }
  1105. }
  1106. }
  1107. }
  1108. if (codePoint === null) {
  1109. // we did not generate a valid codePoint so insert a
  1110. // replacement char (U+FFFD) and advance only 1 byte
  1111. codePoint = 0xFFFD
  1112. bytesPerSequence = 1
  1113. } else if (codePoint > 0xFFFF) {
  1114. // encode to utf16 (surrogate pair dance)
  1115. codePoint -= 0x10000
  1116. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  1117. codePoint = 0xDC00 | codePoint & 0x3FF
  1118. }
  1119. res.push(codePoint)
  1120. i += bytesPerSequence
  1121. }
  1122. return decodeCodePointsArray(res)
  1123. }
  1124. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1125. // the lowest limit is Chrome, with 0x10000 args.
  1126. // We go 1 magnitude less, for safety
  1127. var MAX_ARGUMENTS_LENGTH = 0x1000
  1128. function decodeCodePointsArray (codePoints) {
  1129. var len = codePoints.length
  1130. if (len <= MAX_ARGUMENTS_LENGTH) {
  1131. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1132. }
  1133. // Decode in chunks to avoid "call stack size exceeded".
  1134. var res = ''
  1135. var i = 0
  1136. while (i < len) {
  1137. res += String.fromCharCode.apply(
  1138. String,
  1139. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1140. )
  1141. }
  1142. return res
  1143. }
  1144. function asciiSlice (buf, start, end) {
  1145. var ret = ''
  1146. end = Math.min(buf.length, end)
  1147. for (var i = start; i < end; ++i) {
  1148. ret += String.fromCharCode(buf[i] & 0x7F)
  1149. }
  1150. return ret
  1151. }
  1152. function latin1Slice (buf, start, end) {
  1153. var ret = ''
  1154. end = Math.min(buf.length, end)
  1155. for (var i = start; i < end; ++i) {
  1156. ret += String.fromCharCode(buf[i])
  1157. }
  1158. return ret
  1159. }
  1160. function hexSlice (buf, start, end) {
  1161. var len = buf.length
  1162. if (!start || start < 0) start = 0
  1163. if (!end || end < 0 || end > len) end = len
  1164. var out = ''
  1165. for (var i = start; i < end; ++i) {
  1166. out += toHex(buf[i])
  1167. }
  1168. return out
  1169. }
  1170. function utf16leSlice (buf, start, end) {
  1171. var bytes = buf.slice(start, end)
  1172. var res = ''
  1173. for (var i = 0; i < bytes.length; i += 2) {
  1174. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  1175. }
  1176. return res
  1177. }
  1178. Buffer.prototype.slice = function slice (start, end) {
  1179. var len = this.length
  1180. start = ~~start
  1181. end = end === undefined ? len : ~~end
  1182. if (start < 0) {
  1183. start += len
  1184. if (start < 0) start = 0
  1185. } else if (start > len) {
  1186. start = len
  1187. }
  1188. if (end < 0) {
  1189. end += len
  1190. if (end < 0) end = 0
  1191. } else if (end > len) {
  1192. end = len
  1193. }
  1194. if (end < start) end = start
  1195. var newBuf = this.subarray(start, end)
  1196. // Return an augmented `Uint8Array` instance
  1197. newBuf.__proto__ = Buffer.prototype
  1198. return newBuf
  1199. }
  1200. /*
  1201. * Need to make sure that buffer isn't trying to write out of bounds.
  1202. */
  1203. function checkOffset (offset, ext, length) {
  1204. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1205. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1206. }
  1207. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1208. offset = offset >>> 0
  1209. byteLength = byteLength >>> 0
  1210. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1211. var val = this[offset]
  1212. var mul = 1
  1213. var i = 0
  1214. while (++i < byteLength && (mul *= 0x100)) {
  1215. val += this[offset + i] * mul
  1216. }
  1217. return val
  1218. }
  1219. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1220. offset = offset >>> 0
  1221. byteLength = byteLength >>> 0
  1222. if (!noAssert) {
  1223. checkOffset(offset, byteLength, this.length)
  1224. }
  1225. var val = this[offset + --byteLength]
  1226. var mul = 1
  1227. while (byteLength > 0 && (mul *= 0x100)) {
  1228. val += this[offset + --byteLength] * mul
  1229. }
  1230. return val
  1231. }
  1232. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1233. offset = offset >>> 0
  1234. if (!noAssert) checkOffset(offset, 1, this.length)
  1235. return this[offset]
  1236. }
  1237. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1238. offset = offset >>> 0
  1239. if (!noAssert) checkOffset(offset, 2, this.length)
  1240. return this[offset] | (this[offset + 1] << 8)
  1241. }
  1242. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1243. offset = offset >>> 0
  1244. if (!noAssert) checkOffset(offset, 2, this.length)
  1245. return (this[offset] << 8) | this[offset + 1]
  1246. }
  1247. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1248. offset = offset >>> 0
  1249. if (!noAssert) checkOffset(offset, 4, this.length)
  1250. return ((this[offset]) |
  1251. (this[offset + 1] << 8) |
  1252. (this[offset + 2] << 16)) +
  1253. (this[offset + 3] * 0x1000000)
  1254. }
  1255. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1256. offset = offset >>> 0
  1257. if (!noAssert) checkOffset(offset, 4, this.length)
  1258. return (this[offset] * 0x1000000) +
  1259. ((this[offset + 1] << 16) |
  1260. (this[offset + 2] << 8) |
  1261. this[offset + 3])
  1262. }
  1263. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1264. offset = offset >>> 0
  1265. byteLength = byteLength >>> 0
  1266. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1267. var val = this[offset]
  1268. var mul = 1
  1269. var i = 0
  1270. while (++i < byteLength && (mul *= 0x100)) {
  1271. val += this[offset + i] * mul
  1272. }
  1273. mul *= 0x80
  1274. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1275. return val
  1276. }
  1277. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1278. offset = offset >>> 0
  1279. byteLength = byteLength >>> 0
  1280. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1281. var i = byteLength
  1282. var mul = 1
  1283. var val = this[offset + --i]
  1284. while (i > 0 && (mul *= 0x100)) {
  1285. val += this[offset + --i] * mul
  1286. }
  1287. mul *= 0x80
  1288. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1289. return val
  1290. }
  1291. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1292. offset = offset >>> 0
  1293. if (!noAssert) checkOffset(offset, 1, this.length)
  1294. if (!(this[offset] & 0x80)) return (this[offset])
  1295. return ((0xff - this[offset] + 1) * -1)
  1296. }
  1297. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1298. offset = offset >>> 0
  1299. if (!noAssert) checkOffset(offset, 2, this.length)
  1300. var val = this[offset] | (this[offset + 1] << 8)
  1301. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1302. }
  1303. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1304. offset = offset >>> 0
  1305. if (!noAssert) checkOffset(offset, 2, this.length)
  1306. var val = this[offset + 1] | (this[offset] << 8)
  1307. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1308. }
  1309. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1310. offset = offset >>> 0
  1311. if (!noAssert) checkOffset(offset, 4, this.length)
  1312. return (this[offset]) |
  1313. (this[offset + 1] << 8) |
  1314. (this[offset + 2] << 16) |
  1315. (this[offset + 3] << 24)
  1316. }
  1317. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1318. offset = offset >>> 0
  1319. if (!noAssert) checkOffset(offset, 4, this.length)
  1320. return (this[offset] << 24) |
  1321. (this[offset + 1] << 16) |
  1322. (this[offset + 2] << 8) |
  1323. (this[offset + 3])
  1324. }
  1325. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1326. offset = offset >>> 0
  1327. if (!noAssert) checkOffset(offset, 4, this.length)
  1328. return ieee754.read(this, offset, true, 23, 4)
  1329. }
  1330. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1331. offset = offset >>> 0
  1332. if (!noAssert) checkOffset(offset, 4, this.length)
  1333. return ieee754.read(this, offset, false, 23, 4)
  1334. }
  1335. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1336. offset = offset >>> 0
  1337. if (!noAssert) checkOffset(offset, 8, this.length)
  1338. return ieee754.read(this, offset, true, 52, 8)
  1339. }
  1340. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1341. offset = offset >>> 0
  1342. if (!noAssert) checkOffset(offset, 8, this.length)
  1343. return ieee754.read(this, offset, false, 52, 8)
  1344. }
  1345. function checkInt (buf, value, offset, ext, max, min) {
  1346. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1347. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1348. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1349. }
  1350. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1351. value = +value
  1352. offset = offset >>> 0
  1353. byteLength = byteLength >>> 0
  1354. if (!noAssert) {
  1355. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1356. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1357. }
  1358. var mul = 1
  1359. var i = 0
  1360. this[offset] = value & 0xFF
  1361. while (++i < byteLength && (mul *= 0x100)) {
  1362. this[offset + i] = (value / mul) & 0xFF
  1363. }
  1364. return offset + byteLength
  1365. }
  1366. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1367. value = +value
  1368. offset = offset >>> 0
  1369. byteLength = byteLength >>> 0
  1370. if (!noAssert) {
  1371. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1372. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1373. }
  1374. var i = byteLength - 1
  1375. var mul = 1
  1376. this[offset + i] = value & 0xFF
  1377. while (--i >= 0 && (mul *= 0x100)) {
  1378. this[offset + i] = (value / mul) & 0xFF
  1379. }
  1380. return offset + byteLength
  1381. }
  1382. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1383. value = +value
  1384. offset = offset >>> 0
  1385. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1386. this[offset] = (value & 0xff)
  1387. return offset + 1
  1388. }
  1389. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1390. value = +value
  1391. offset = offset >>> 0
  1392. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1393. this[offset] = (value & 0xff)
  1394. this[offset + 1] = (value >>> 8)
  1395. return offset + 2
  1396. }
  1397. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1398. value = +value
  1399. offset = offset >>> 0
  1400. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1401. this[offset] = (value >>> 8)
  1402. this[offset + 1] = (value & 0xff)
  1403. return offset + 2
  1404. }
  1405. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1406. value = +value
  1407. offset = offset >>> 0
  1408. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1409. this[offset + 3] = (value >>> 24)
  1410. this[offset + 2] = (value >>> 16)
  1411. this[offset + 1] = (value >>> 8)
  1412. this[offset] = (value & 0xff)
  1413. return offset + 4
  1414. }
  1415. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1416. value = +value
  1417. offset = offset >>> 0
  1418. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1419. this[offset] = (value >>> 24)
  1420. this[offset + 1] = (value >>> 16)
  1421. this[offset + 2] = (value >>> 8)
  1422. this[offset + 3] = (value & 0xff)
  1423. return offset + 4
  1424. }
  1425. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1426. value = +value
  1427. offset = offset >>> 0
  1428. if (!noAssert) {
  1429. var limit = Math.pow(2, (8 * byteLength) - 1)
  1430. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1431. }
  1432. var i = 0
  1433. var mul = 1
  1434. var sub = 0
  1435. this[offset] = value & 0xFF
  1436. while (++i < byteLength && (mul *= 0x100)) {
  1437. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1438. sub = 1
  1439. }
  1440. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1441. }
  1442. return offset + byteLength
  1443. }
  1444. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1445. value = +value
  1446. offset = offset >>> 0
  1447. if (!noAssert) {
  1448. var limit = Math.pow(2, (8 * byteLength) - 1)
  1449. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1450. }
  1451. var i = byteLength - 1
  1452. var mul = 1
  1453. var sub = 0
  1454. this[offset + i] = value & 0xFF
  1455. while (--i >= 0 && (mul *= 0x100)) {
  1456. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1457. sub = 1
  1458. }
  1459. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1460. }
  1461. return offset + byteLength
  1462. }
  1463. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1464. value = +value
  1465. offset = offset >>> 0
  1466. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1467. if (value < 0) value = 0xff + value + 1
  1468. this[offset] = (value & 0xff)
  1469. return offset + 1
  1470. }
  1471. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1472. value = +value
  1473. offset = offset >>> 0
  1474. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1475. this[offset] = (value & 0xff)
  1476. this[offset + 1] = (value >>> 8)
  1477. return offset + 2
  1478. }
  1479. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1480. value = +value
  1481. offset = offset >>> 0
  1482. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1483. this[offset] = (value >>> 8)
  1484. this[offset + 1] = (value & 0xff)
  1485. return offset + 2
  1486. }
  1487. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1488. value = +value
  1489. offset = offset >>> 0
  1490. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1491. this[offset] = (value & 0xff)
  1492. this[offset + 1] = (value >>> 8)
  1493. this[offset + 2] = (value >>> 16)
  1494. this[offset + 3] = (value >>> 24)
  1495. return offset + 4
  1496. }
  1497. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1498. value = +value
  1499. offset = offset >>> 0
  1500. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1501. if (value < 0) value = 0xffffffff + value + 1
  1502. this[offset] = (value >>> 24)
  1503. this[offset + 1] = (value >>> 16)
  1504. this[offset + 2] = (value >>> 8)
  1505. this[offset + 3] = (value & 0xff)
  1506. return offset + 4
  1507. }
  1508. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1509. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1510. if (offset < 0) throw new RangeError('Index out of range')
  1511. }
  1512. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1513. value = +value
  1514. offset = offset >>> 0
  1515. if (!noAssert) {
  1516. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1517. }
  1518. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1519. return offset + 4
  1520. }
  1521. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1522. return writeFloat(this, value, offset, true, noAssert)
  1523. }
  1524. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1525. return writeFloat(this, value, offset, false, noAssert)
  1526. }
  1527. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1528. value = +value
  1529. offset = offset >>> 0
  1530. if (!noAssert) {
  1531. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1532. }
  1533. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1534. return offset + 8
  1535. }
  1536. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1537. return writeDouble(this, value, offset, true, noAssert)
  1538. }
  1539. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1540. return writeDouble(this, value, offset, false, noAssert)
  1541. }
  1542. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1543. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  1544. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  1545. if (!start) start = 0
  1546. if (!end && end !== 0) end = this.length
  1547. if (targetStart >= target.length) targetStart = target.length
  1548. if (!targetStart) targetStart = 0
  1549. if (end > 0 && end < start) end = start
  1550. // Copy 0 bytes; we're done
  1551. if (end === start) return 0
  1552. if (target.length === 0 || this.length === 0) return 0
  1553. // Fatal error conditions
  1554. if (targetStart < 0) {
  1555. throw new RangeError('targetStart out of bounds')
  1556. }
  1557. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  1558. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1559. // Are we oob?
  1560. if (end > this.length) end = this.length
  1561. if (target.length - targetStart < end - start) {
  1562. end = target.length - targetStart + start
  1563. }
  1564. var len = end - start
  1565. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1566. // Use built-in when available, missing from IE11
  1567. this.copyWithin(targetStart, start, end)
  1568. } else if (this === target && start < targetStart && targetStart < end) {
  1569. // descending copy from end
  1570. for (var i = len - 1; i >= 0; --i) {
  1571. target[i + targetStart] = this[i + start]
  1572. }
  1573. } else {
  1574. Uint8Array.prototype.set.call(
  1575. target,
  1576. this.subarray(start, end),
  1577. targetStart
  1578. )
  1579. }
  1580. return len
  1581. }
  1582. // Usage:
  1583. // buffer.fill(number[, offset[, end]])
  1584. // buffer.fill(buffer[, offset[, end]])
  1585. // buffer.fill(string[, offset[, end]][, encoding])
  1586. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  1587. // Handle string cases:
  1588. if (typeof val === 'string') {
  1589. if (typeof start === 'string') {
  1590. encoding = start
  1591. start = 0
  1592. end = this.length
  1593. } else if (typeof end === 'string') {
  1594. encoding = end
  1595. end = this.length
  1596. }
  1597. if (encoding !== undefined && typeof encoding !== 'string') {
  1598. throw new TypeError('encoding must be a string')
  1599. }
  1600. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1601. throw new TypeError('Unknown encoding: ' + encoding)
  1602. }
  1603. if (val.length === 1) {
  1604. var code = val.charCodeAt(0)
  1605. if ((encoding === 'utf8' && code < 128) ||
  1606. encoding === 'latin1') {
  1607. // Fast path: If `val` fits into a single byte, use that numeric value.
  1608. val = code
  1609. }
  1610. }
  1611. } else if (typeof val === 'number') {
  1612. val = val & 255
  1613. }
  1614. // Invalid ranges are not set to a default, so can range check early.
  1615. if (start < 0 || this.length < start || this.length < end) {
  1616. throw new RangeError('Out of range index')
  1617. }
  1618. if (end <= start) {
  1619. return this
  1620. }
  1621. start = start >>> 0
  1622. end = end === undefined ? this.length : end >>> 0
  1623. if (!val) val = 0
  1624. var i
  1625. if (typeof val === 'number') {
  1626. for (i = start; i < end; ++i) {
  1627. this[i] = val
  1628. }
  1629. } else {
  1630. var bytes = Buffer.isBuffer(val)
  1631. ? val
  1632. : new Buffer(val, encoding)
  1633. var len = bytes.length
  1634. if (len === 0) {
  1635. throw new TypeError('The value "' + val +
  1636. '" is invalid for argument "value"')
  1637. }
  1638. for (i = 0; i < end - start; ++i) {
  1639. this[i + start] = bytes[i % len]
  1640. }
  1641. }
  1642. return this
  1643. }
  1644. // HELPER FUNCTIONS
  1645. // ================
  1646. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  1647. function base64clean (str) {
  1648. // Node takes equal signs as end of the Base64 encoding
  1649. str = str.split('=')[0]
  1650. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1651. str = str.trim().replace(INVALID_BASE64_RE, '')
  1652. // Node converts strings with length < 2 to ''
  1653. if (str.length < 2) return ''
  1654. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1655. while (str.length % 4 !== 0) {
  1656. str = str + '='
  1657. }
  1658. return str
  1659. }
  1660. function toHex (n) {
  1661. if (n < 16) return '0' + n.toString(16)
  1662. return n.toString(16)
  1663. }
  1664. function utf8ToBytes (string, units) {
  1665. units = units || Infinity
  1666. var codePoint
  1667. var length = string.length
  1668. var leadSurrogate = null
  1669. var bytes = []
  1670. for (var i = 0; i < length; ++i) {
  1671. codePoint = string.charCodeAt(i)
  1672. // is surrogate component
  1673. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1674. // last char was a lead
  1675. if (!leadSurrogate) {
  1676. // no lead yet
  1677. if (codePoint > 0xDBFF) {
  1678. // unexpected trail
  1679. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1680. continue
  1681. } else if (i + 1 === length) {
  1682. // unpaired lead
  1683. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1684. continue
  1685. }
  1686. // valid lead
  1687. leadSurrogate = codePoint
  1688. continue
  1689. }
  1690. // 2 leads in a row
  1691. if (codePoint < 0xDC00) {
  1692. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1693. leadSurrogate = codePoint
  1694. continue
  1695. }
  1696. // valid surrogate pair
  1697. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1698. } else if (leadSurrogate) {
  1699. // valid bmp char, but last char was a lead
  1700. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1701. }
  1702. leadSurrogate = null
  1703. // encode utf8
  1704. if (codePoint < 0x80) {
  1705. if ((units -= 1) < 0) break
  1706. bytes.push(codePoint)
  1707. } else if (codePoint < 0x800) {
  1708. if ((units -= 2) < 0) break
  1709. bytes.push(
  1710. codePoint >> 0x6 | 0xC0,
  1711. codePoint & 0x3F | 0x80
  1712. )
  1713. } else if (codePoint < 0x10000) {
  1714. if ((units -= 3) < 0) break
  1715. bytes.push(
  1716. codePoint >> 0xC | 0xE0,
  1717. codePoint >> 0x6 & 0x3F | 0x80,
  1718. codePoint & 0x3F | 0x80
  1719. )
  1720. } else if (codePoint < 0x110000) {
  1721. if ((units -= 4) < 0) break
  1722. bytes.push(
  1723. codePoint >> 0x12 | 0xF0,
  1724. codePoint >> 0xC & 0x3F | 0x80,
  1725. codePoint >> 0x6 & 0x3F | 0x80,
  1726. codePoint & 0x3F | 0x80
  1727. )
  1728. } else {
  1729. throw new Error('Invalid code point')
  1730. }
  1731. }
  1732. return bytes
  1733. }
  1734. function asciiToBytes (str) {
  1735. var byteArray = []
  1736. for (var i = 0; i < str.length; ++i) {
  1737. // Node's code seems to be doing this and not & 0x7F..
  1738. byteArray.push(str.charCodeAt(i) & 0xFF)
  1739. }
  1740. return byteArray
  1741. }
  1742. function utf16leToBytes (str, units) {
  1743. var c, hi, lo
  1744. var byteArray = []
  1745. for (var i = 0; i < str.length; ++i) {
  1746. if ((units -= 2) < 0) break
  1747. c = str.charCodeAt(i)
  1748. hi = c >> 8
  1749. lo = c % 256
  1750. byteArray.push(lo)
  1751. byteArray.push(hi)
  1752. }
  1753. return byteArray
  1754. }
  1755. function base64ToBytes (str) {
  1756. return base64.toByteArray(base64clean(str))
  1757. }
  1758. function blitBuffer (src, dst, offset, length) {
  1759. for (var i = 0; i < length; ++i) {
  1760. if ((i + offset >= dst.length) || (i >= src.length)) break
  1761. dst[i + offset] = src[i]
  1762. }
  1763. return i
  1764. }
  1765. // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
  1766. // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
  1767. function isArrayBuffer (obj) {
  1768. return obj instanceof ArrayBuffer ||
  1769. (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
  1770. typeof obj.byteLength === 'number')
  1771. }
  1772. function numberIsNaN (obj) {
  1773. return obj !== obj // eslint-disable-line no-self-compare
  1774. }
  1775. },{"base64-js":2,"ieee754":4}],4:[function(require,module,exports){
  1776. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  1777. var e, m
  1778. var eLen = (nBytes * 8) - mLen - 1
  1779. var eMax = (1 << eLen) - 1
  1780. var eBias = eMax >> 1
  1781. var nBits = -7
  1782. var i = isLE ? (nBytes - 1) : 0
  1783. var d = isLE ? -1 : 1
  1784. var s = buffer[offset + i]
  1785. i += d
  1786. e = s & ((1 << (-nBits)) - 1)
  1787. s >>= (-nBits)
  1788. nBits += eLen
  1789. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  1790. m = e & ((1 << (-nBits)) - 1)
  1791. e >>= (-nBits)
  1792. nBits += mLen
  1793. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  1794. if (e === 0) {
  1795. e = 1 - eBias
  1796. } else if (e === eMax) {
  1797. return m ? NaN : ((s ? -1 : 1) * Infinity)
  1798. } else {
  1799. m = m + Math.pow(2, mLen)
  1800. e = e - eBias
  1801. }
  1802. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  1803. }
  1804. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  1805. var e, m, c
  1806. var eLen = (nBytes * 8) - mLen - 1
  1807. var eMax = (1 << eLen) - 1
  1808. var eBias = eMax >> 1
  1809. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  1810. var i = isLE ? 0 : (nBytes - 1)
  1811. var d = isLE ? 1 : -1
  1812. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  1813. value = Math.abs(value)
  1814. if (isNaN(value) || value === Infinity) {
  1815. m = isNaN(value) ? 1 : 0
  1816. e = eMax
  1817. } else {
  1818. e = Math.floor(Math.log(value) / Math.LN2)
  1819. if (value * (c = Math.pow(2, -e)) < 1) {
  1820. e--
  1821. c *= 2
  1822. }
  1823. if (e + eBias >= 1) {
  1824. value += rt / c
  1825. } else {
  1826. value += rt * Math.pow(2, 1 - eBias)
  1827. }
  1828. if (value * c >= 2) {
  1829. e++
  1830. c /= 2
  1831. }
  1832. if (e + eBias >= eMax) {
  1833. m = 0
  1834. e = eMax
  1835. } else if (e + eBias >= 1) {
  1836. m = ((value * c) - 1) * Math.pow(2, mLen)
  1837. e = e + eBias
  1838. } else {
  1839. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  1840. e = 0
  1841. }
  1842. }
  1843. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  1844. e = (e << mLen) | m
  1845. eLen += mLen
  1846. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  1847. buffer[offset + i - d] |= s * 128
  1848. }
  1849. },{}],5:[function(require,module,exports){
  1850. function DOMParser(options){
  1851. this.options = options ||{locator:{}};
  1852. }
  1853. DOMParser.prototype.parseFromString = function(source,mimeType){
  1854. var options = this.options;
  1855. var sax = new XMLReader();
  1856. var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
  1857. var errorHandler = options.errorHandler;
  1858. var locator = options.locator;
  1859. var defaultNSMap = options.xmlns||{};
  1860. var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
  1861. if(locator){
  1862. domBuilder.setDocumentLocator(locator)
  1863. }
  1864. sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
  1865. sax.domBuilder = options.domBuilder || domBuilder;
  1866. if(/\/x?html?$/.test(mimeType)){
  1867. entityMap.nbsp = '\xa0';
  1868. entityMap.copy = '\xa9';
  1869. defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
  1870. }
  1871. defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
  1872. if(source){
  1873. sax.parse(source,defaultNSMap,entityMap);
  1874. }else{
  1875. sax.errorHandler.error("invalid doc source");
  1876. }
  1877. return domBuilder.doc;
  1878. }
  1879. function buildErrorHandler(errorImpl,domBuilder,locator){
  1880. if(!errorImpl){
  1881. if(domBuilder instanceof DOMHandler){
  1882. return domBuilder;
  1883. }
  1884. errorImpl = domBuilder ;
  1885. }
  1886. var errorHandler = {}
  1887. var isCallback = errorImpl instanceof Function;
  1888. locator = locator||{}
  1889. function build(key){
  1890. var fn = errorImpl[key];
  1891. if(!fn && isCallback){
  1892. fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
  1893. }
  1894. errorHandler[key] = fn && function(msg){
  1895. fn('[xmldom '+key+']\t'+msg+_locator(locator));
  1896. }||function(){};
  1897. }
  1898. build('warning');
  1899. build('error');
  1900. build('fatalError');
  1901. return errorHandler;
  1902. }
  1903. //console.log('#\n\n\n\n\n\n\n####')
  1904. /**
  1905. * +ContentHandler+ErrorHandler
  1906. * +LexicalHandler+EntityResolver2
  1907. * -DeclHandler-DTDHandler
  1908. *
  1909. * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
  1910. * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
  1911. * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
  1912. */
  1913. function DOMHandler() {
  1914. this.cdata = false;
  1915. }
  1916. function position(locator,node){
  1917. node.lineNumber = locator.lineNumber;
  1918. node.columnNumber = locator.columnNumber;
  1919. }
  1920. /**
  1921. * @see org.xml.sax.ContentHandler#startDocument
  1922. * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
  1923. */
  1924. DOMHandler.prototype = {
  1925. startDocument : function() {
  1926. this.doc = new DOMImplementation().createDocument(null, null, null);
  1927. if (this.locator) {
  1928. this.doc.documentURI = this.locator.systemId;
  1929. }
  1930. },
  1931. startElement:function(namespaceURI, localName, qName, attrs) {
  1932. var doc = this.doc;
  1933. var el = doc.createElementNS(namespaceURI, qName||localName);
  1934. var len = attrs.length;
  1935. appendElement(this, el);
  1936. this.currentElement = el;
  1937. this.locator && position(this.locator,el)
  1938. for (var i = 0 ; i < len; i++) {
  1939. var namespaceURI = attrs.getURI(i);
  1940. var value = attrs.getValue(i);
  1941. var qName = attrs.getQName(i);
  1942. var attr = doc.createAttributeNS(namespaceURI, qName);
  1943. this.locator &&position(attrs.getLocator(i),attr);
  1944. attr.value = attr.nodeValue = value;
  1945. el.setAttributeNode(attr)
  1946. }
  1947. },
  1948. endElement:function(namespaceURI, localName, qName) {
  1949. var current = this.currentElement
  1950. var tagName = current.tagName;
  1951. this.currentElement = current.parentNode;
  1952. },
  1953. startPrefixMapping:function(prefix, uri) {
  1954. },
  1955. endPrefixMapping:function(prefix) {
  1956. },
  1957. processingInstruction:function(target, data) {
  1958. var ins = this.doc.createProcessingInstruction(target, data);
  1959. this.locator && position(this.locator,ins)
  1960. appendElement(this, ins);
  1961. },
  1962. ignorableWhitespace:function(ch, start, length) {
  1963. },
  1964. characters:function(chars, start, length) {
  1965. chars = _toString.apply(this,arguments)
  1966. //console.log(chars)
  1967. if(chars){
  1968. if (this.cdata) {
  1969. var charNode = this.doc.createCDATASection(chars);
  1970. } else {
  1971. var charNode = this.doc.createTextNode(chars);
  1972. }
  1973. if(this.currentElement){
  1974. this.currentElement.appendChild(charNode);
  1975. }else if(/^\s*$/.test(chars)){
  1976. this.doc.appendChild(charNode);
  1977. //process xml
  1978. }
  1979. this.locator && position(this.locator,charNode)
  1980. }
  1981. },
  1982. skippedEntity:function(name) {
  1983. },
  1984. endDocument:function() {
  1985. this.doc.normalize();
  1986. },
  1987. setDocumentLocator:function (locator) {
  1988. if(this.locator = locator){// && !('lineNumber' in locator)){
  1989. locator.lineNumber = 0;
  1990. }
  1991. },
  1992. //LexicalHandler
  1993. comment:function(chars, start, length) {
  1994. chars = _toString.apply(this,arguments)
  1995. var comm = this.doc.createComment(chars);
  1996. this.locator && position(this.locator,comm)
  1997. appendElement(this, comm);
  1998. },
  1999. startCDATA:function() {
  2000. //used in characters() methods
  2001. this.cdata = true;
  2002. },
  2003. endCDATA:function() {
  2004. this.cdata = false;
  2005. },
  2006. startDTD:function(name, publicId, systemId) {
  2007. var impl = this.doc.implementation;
  2008. if (impl && impl.createDocumentType) {
  2009. var dt = impl.createDocumentType(name, publicId, systemId);
  2010. this.locator && position(this.locator,dt)
  2011. appendElement(this, dt);
  2012. }
  2013. },
  2014. /**
  2015. * @see org.xml.sax.ErrorHandler
  2016. * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
  2017. */
  2018. warning:function(error) {
  2019. console.warn('[xmldom warning]\t'+error,_locator(this.locator));
  2020. },
  2021. error:function(error) {
  2022. console.error('[xmldom error]\t'+error,_locator(this.locator));
  2023. },
  2024. fatalError:function(error) {
  2025. console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
  2026. throw error;
  2027. }
  2028. }
  2029. function _locator(l){
  2030. if(l){
  2031. return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
  2032. }
  2033. }
  2034. function _toString(chars,start,length){
  2035. if(typeof chars == 'string'){
  2036. return chars.substr(start,length)
  2037. }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
  2038. if(chars.length >= start+length || start){
  2039. return new java.lang.String(chars,start,length)+'';
  2040. }
  2041. return chars;
  2042. }
  2043. }
  2044. /*
  2045. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
  2046. * used method of org.xml.sax.ext.LexicalHandler:
  2047. * #comment(chars, start, length)
  2048. * #startCDATA()
  2049. * #endCDATA()
  2050. * #startDTD(name, publicId, systemId)
  2051. *
  2052. *
  2053. * IGNORED method of org.xml.sax.ext.LexicalHandler:
  2054. * #endDTD()
  2055. * #startEntity(name)
  2056. * #endEntity(name)
  2057. *
  2058. *
  2059. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
  2060. * IGNORED method of org.xml.sax.ext.DeclHandler
  2061. * #attributeDecl(eName, aName, type, mode, value)
  2062. * #elementDecl(name, model)
  2063. * #externalEntityDecl(name, publicId, systemId)
  2064. * #internalEntityDecl(name, value)
  2065. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
  2066. * IGNORED method of org.xml.sax.EntityResolver2
  2067. * #resolveEntity(String name,String publicId,String baseURI,String systemId)
  2068. * #resolveEntity(publicId, systemId)
  2069. * #getExternalSubset(name, baseURI)
  2070. * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
  2071. * IGNORED method of org.xml.sax.DTDHandler
  2072. * #notationDecl(name, publicId, systemId) {};
  2073. * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
  2074. */
  2075. "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
  2076. DOMHandler.prototype[key] = function(){return null}
  2077. })
  2078. /* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
  2079. function appendElement (hander,node) {
  2080. if (!hander.currentElement) {
  2081. hander.doc.appendChild(node);
  2082. } else {
  2083. hander.currentElement.appendChild(node);
  2084. }
  2085. }//appendChild and setAttributeNS are preformance key
  2086. //if(typeof require == 'function'){
  2087. var XMLReader = require('./sax').XMLReader;
  2088. var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
  2089. exports.XMLSerializer = require('./dom').XMLSerializer ;
  2090. exports.DOMParser = DOMParser;
  2091. //}
  2092. },{"./dom":6,"./sax":7}],6:[function(require,module,exports){
  2093. /*
  2094. * DOM Level 2
  2095. * Object DOMException
  2096. * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
  2097. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
  2098. */
  2099. function copy(src,dest){
  2100. for(var p in src){
  2101. dest[p] = src[p];
  2102. }
  2103. }
  2104. /**
  2105. ^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
  2106. ^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
  2107. */
  2108. function _extends(Class,Super){
  2109. var pt = Class.prototype;
  2110. if(Object.create){
  2111. var ppt = Object.create(Super.prototype)
  2112. pt.__proto__ = ppt;
  2113. }
  2114. if(!(pt instanceof Super)){
  2115. function t(){};
  2116. t.prototype = Super.prototype;
  2117. t = new t();
  2118. copy(pt,t);
  2119. Class.prototype = pt = t;
  2120. }
  2121. if(pt.constructor != Class){
  2122. if(typeof Class != 'function'){
  2123. console.error("unknow Class:"+Class)
  2124. }
  2125. pt.constructor = Class
  2126. }
  2127. }
  2128. var htmlns = 'http://www.w3.org/1999/xhtml' ;
  2129. // Node Types
  2130. var NodeType = {}
  2131. var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
  2132. var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
  2133. var TEXT_NODE = NodeType.TEXT_NODE = 3;
  2134. var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
  2135. var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
  2136. var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
  2137. var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
  2138. var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
  2139. var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
  2140. var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
  2141. var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
  2142. var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
  2143. // ExceptionCode
  2144. var ExceptionCode = {}
  2145. var ExceptionMessage = {};
  2146. var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
  2147. var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
  2148. var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
  2149. var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
  2150. var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
  2151. var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
  2152. var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
  2153. var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
  2154. var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
  2155. var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
  2156. //level2
  2157. var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
  2158. var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
  2159. var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
  2160. var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
  2161. var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
  2162. function DOMException(code, message) {
  2163. if(message instanceof Error){
  2164. var error = message;
  2165. }else{
  2166. error = this;
  2167. Error.call(this, ExceptionMessage[code]);
  2168. this.message = ExceptionMessage[code];
  2169. if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
  2170. }
  2171. error.code = code;
  2172. if(message) this.message = this.message + ": " + message;
  2173. return error;
  2174. };
  2175. DOMException.prototype = Error.prototype;
  2176. copy(ExceptionCode,DOMException)
  2177. /**
  2178. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
  2179. * The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live.
  2180. * The items in the NodeList are accessible via an integral index, starting from 0.
  2181. */
  2182. function NodeList() {
  2183. };
  2184. NodeList.prototype = {
  2185. /**
  2186. * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
  2187. * @standard level1
  2188. */
  2189. length:0,
  2190. /**
  2191. * Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
  2192. * @standard level1
  2193. * @param index unsigned long
  2194. * Index into the collection.
  2195. * @return Node
  2196. * The node at the indexth position in the NodeList, or null if that is not a valid index.
  2197. */
  2198. item: function(index) {
  2199. return this[index] || null;
  2200. },
  2201. toString:function(isHTML,nodeFilter){
  2202. for(var buf = [], i = 0;i<this.length;i++){
  2203. serializeToString(this[i],buf,isHTML,nodeFilter);
  2204. }
  2205. return buf.join('');
  2206. }
  2207. };
  2208. function LiveNodeList(node,refresh){
  2209. this._node = node;
  2210. this._refresh = refresh
  2211. _updateLiveList(this);
  2212. }
  2213. function _updateLiveList(list){
  2214. var inc = list._node._inc || list._node.ownerDocument._inc;
  2215. if(list._inc != inc){
  2216. var ls = list._refresh(list._node);
  2217. //console.log(ls.length)
  2218. __set__(list,'length',ls.length);
  2219. copy(ls,list);
  2220. list._inc = inc;
  2221. }
  2222. }
  2223. LiveNodeList.prototype.item = function(i){
  2224. _updateLiveList(this);
  2225. return this[i];
  2226. }
  2227. _extends(LiveNodeList,NodeList);
  2228. /**
  2229. *
  2230. * Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can be accessed by name. Note that NamedNodeMap does not inherit from NodeList; NamedNodeMaps are not maintained in any particular order. Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.
  2231. * NamedNodeMap objects in the DOM are live.
  2232. * used for attributes or DocumentType entities
  2233. */
  2234. function NamedNodeMap() {
  2235. };
  2236. function _findNodeIndex(list,node){
  2237. var i = list.length;
  2238. while(i--){
  2239. if(list[i] === node){return i}
  2240. }
  2241. }
  2242. function _addNamedNode(el,list,newAttr,oldAttr){
  2243. if(oldAttr){
  2244. list[_findNodeIndex(list,oldAttr)] = newAttr;
  2245. }else{
  2246. list[list.length++] = newAttr;
  2247. }
  2248. if(el){
  2249. newAttr.ownerElement = el;
  2250. var doc = el.ownerDocument;
  2251. if(doc){
  2252. oldAttr && _onRemoveAttribute(doc,el,oldAttr);
  2253. _onAddAttribute(doc,el,newAttr);
  2254. }
  2255. }
  2256. }
  2257. function _removeNamedNode(el,list,attr){
  2258. //console.log('remove attr:'+attr)
  2259. var i = _findNodeIndex(list,attr);
  2260. if(i>=0){
  2261. var lastIndex = list.length-1
  2262. while(i<lastIndex){
  2263. list[i] = list[++i]
  2264. }
  2265. list.length = lastIndex;
  2266. if(el){
  2267. var doc = el.ownerDocument;
  2268. if(doc){
  2269. _onRemoveAttribute(doc,el,attr);
  2270. attr.ownerElement = null;
  2271. }
  2272. }
  2273. }else{
  2274. throw DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
  2275. }
  2276. }
  2277. NamedNodeMap.prototype = {
  2278. length:0,
  2279. item:NodeList.prototype.item,
  2280. getNamedItem: function(key) {
  2281. // if(key.indexOf(':')>0 || key == 'xmlns'){
  2282. // return null;
  2283. // }
  2284. //console.log()
  2285. var i = this.length;
  2286. while(i--){
  2287. var attr = this[i];
  2288. //console.log(attr.nodeName,key)
  2289. if(attr.nodeName == key){
  2290. return attr;
  2291. }
  2292. }
  2293. },
  2294. setNamedItem: function(attr) {
  2295. var el = attr.ownerElement;
  2296. if(el && el!=this._ownerElement){
  2297. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  2298. }
  2299. var oldAttr = this.getNamedItem(attr.nodeName);
  2300. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  2301. return oldAttr;
  2302. },
  2303. /* returns Node */
  2304. setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
  2305. var el = attr.ownerElement, oldAttr;
  2306. if(el && el!=this._ownerElement){
  2307. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  2308. }
  2309. oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
  2310. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  2311. return oldAttr;
  2312. },
  2313. /* returns Node */
  2314. removeNamedItem: function(key) {
  2315. var attr = this.getNamedItem(key);
  2316. _removeNamedNode(this._ownerElement,this,attr);
  2317. return attr;
  2318. },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
  2319. //for level2
  2320. removeNamedItemNS:function(namespaceURI,localName){
  2321. var attr = this.getNamedItemNS(namespaceURI,localName);
  2322. _removeNamedNode(this._ownerElement,this,attr);
  2323. return attr;
  2324. },
  2325. getNamedItemNS: function(namespaceURI, localName) {
  2326. var i = this.length;
  2327. while(i--){
  2328. var node = this[i];
  2329. if(node.localName == localName && node.namespaceURI == namespaceURI){
  2330. return node;
  2331. }
  2332. }
  2333. return null;
  2334. }
  2335. };
  2336. /**
  2337. * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
  2338. */
  2339. function DOMImplementation(/* Object */ features) {
  2340. this._features = {};
  2341. if (features) {
  2342. for (var feature in features) {
  2343. this._features = features[feature];
  2344. }
  2345. }
  2346. };
  2347. DOMImplementation.prototype = {
  2348. hasFeature: function(/* string */ feature, /* string */ version) {
  2349. var versions = this._features[feature.toLowerCase()];
  2350. if (versions && (!version || version in versions)) {
  2351. return true;
  2352. } else {
  2353. return false;
  2354. }
  2355. },
  2356. // Introduced in DOM Level 2:
  2357. createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
  2358. var doc = new Document();
  2359. doc.implementation = this;
  2360. doc.childNodes = new NodeList();
  2361. doc.doctype = doctype;
  2362. if(doctype){
  2363. doc.appendChild(doctype);
  2364. }
  2365. if(qualifiedName){
  2366. var root = doc.createElementNS(namespaceURI,qualifiedName);
  2367. doc.appendChild(root);
  2368. }
  2369. return doc;
  2370. },
  2371. // Introduced in DOM Level 2:
  2372. createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
  2373. var node = new DocumentType();
  2374. node.name = qualifiedName;
  2375. node.nodeName = qualifiedName;
  2376. node.publicId = publicId;
  2377. node.systemId = systemId;
  2378. // Introduced in DOM Level 2:
  2379. //readonly attribute DOMString internalSubset;
  2380. //TODO:..
  2381. // readonly attribute NamedNodeMap entities;
  2382. // readonly attribute NamedNodeMap notations;
  2383. return node;
  2384. }
  2385. };
  2386. /**
  2387. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247
  2388. */
  2389. function Node() {
  2390. };
  2391. Node.prototype = {
  2392. firstChild : null,
  2393. lastChild : null,
  2394. previousSibling : null,
  2395. nextSibling : null,
  2396. attributes : null,
  2397. parentNode : null,
  2398. childNodes : null,
  2399. ownerDocument : null,
  2400. nodeValue : null,
  2401. namespaceURI : null,
  2402. prefix : null,
  2403. localName : null,
  2404. // Modified in DOM Level 2:
  2405. insertBefore:function(newChild, refChild){//raises
  2406. return _insertBefore(this,newChild,refChild);
  2407. },
  2408. replaceChild:function(newChild, oldChild){//raises
  2409. this.insertBefore(newChild,oldChild);
  2410. if(oldChild){
  2411. this.removeChild(oldChild);
  2412. }
  2413. },
  2414. removeChild:function(oldChild){
  2415. return _removeChild(this,oldChild);
  2416. },
  2417. appendChild:function(newChild){
  2418. return this.insertBefore(newChild,null);
  2419. },
  2420. hasChildNodes:function(){
  2421. return this.firstChild != null;
  2422. },
  2423. cloneNode:function(deep){
  2424. return cloneNode(this.ownerDocument||this,this,deep);
  2425. },
  2426. // Modified in DOM Level 2:
  2427. normalize:function(){
  2428. var child = this.firstChild;
  2429. while(child){
  2430. var next = child.nextSibling;
  2431. if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
  2432. this.removeChild(next);
  2433. child.appendData(next.data);
  2434. }else{
  2435. child.normalize();
  2436. child = next;
  2437. }
  2438. }
  2439. },
  2440. // Introduced in DOM Level 2:
  2441. isSupported:function(feature, version){
  2442. return this.ownerDocument.implementation.hasFeature(feature,version);
  2443. },
  2444. // Introduced in DOM Level 2:
  2445. hasAttributes:function(){
  2446. return this.attributes.length>0;
  2447. },
  2448. lookupPrefix:function(namespaceURI){
  2449. var el = this;
  2450. while(el){
  2451. var map = el._nsMap;
  2452. //console.dir(map)
  2453. if(map){
  2454. for(var n in map){
  2455. if(map[n] == namespaceURI){
  2456. return n;
  2457. }
  2458. }
  2459. }
  2460. el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
  2461. }
  2462. return null;
  2463. },
  2464. // Introduced in DOM Level 3:
  2465. lookupNamespaceURI:function(prefix){
  2466. var el = this;
  2467. while(el){
  2468. var map = el._nsMap;
  2469. //console.dir(map)
  2470. if(map){
  2471. if(prefix in map){
  2472. return map[prefix] ;
  2473. }
  2474. }
  2475. el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
  2476. }
  2477. return null;
  2478. },
  2479. // Introduced in DOM Level 3:
  2480. isDefaultNamespace:function(namespaceURI){
  2481. var prefix = this.lookupPrefix(namespaceURI);
  2482. return prefix == null;
  2483. }
  2484. };
  2485. function _xmlEncoder(c){
  2486. return c == '<' && '&lt;' ||
  2487. c == '>' && '&gt;' ||
  2488. c == '&' && '&amp;' ||
  2489. c == '"' && '&quot;' ||
  2490. '&#'+c.charCodeAt()+';'
  2491. }
  2492. copy(NodeType,Node);
  2493. copy(NodeType,Node.prototype);
  2494. /**
  2495. * @param callback return true for continue,false for break
  2496. * @return boolean true: break visit;
  2497. */
  2498. function _visitNode(node,callback){
  2499. if(callback(node)){
  2500. return true;
  2501. }
  2502. if(node = node.firstChild){
  2503. do{
  2504. if(_visitNode(node,callback)){return true}
  2505. }while(node=node.nextSibling)
  2506. }
  2507. }
  2508. function Document(){
  2509. }
  2510. function _onAddAttribute(doc,el,newAttr){
  2511. doc && doc._inc++;
  2512. var ns = newAttr.namespaceURI ;
  2513. if(ns == 'http://www.w3.org/2000/xmlns/'){
  2514. //update namespace
  2515. el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
  2516. }
  2517. }
  2518. function _onRemoveAttribute(doc,el,newAttr,remove){
  2519. doc && doc._inc++;
  2520. var ns = newAttr.namespaceURI ;
  2521. if(ns == 'http://www.w3.org/2000/xmlns/'){
  2522. //update namespace
  2523. delete el._nsMap[newAttr.prefix?newAttr.localName:'']
  2524. }
  2525. }
  2526. function _onUpdateChild(doc,el,newChild){
  2527. if(doc && doc._inc){
  2528. doc._inc++;
  2529. //update childNodes
  2530. var cs = el.childNodes;
  2531. if(newChild){
  2532. cs[cs.length++] = newChild;
  2533. }else{
  2534. //console.log(1)
  2535. var child = el.firstChild;
  2536. var i = 0;
  2537. while(child){
  2538. cs[i++] = child;
  2539. child =child.nextSibling;
  2540. }
  2541. cs.length = i;
  2542. }
  2543. }
  2544. }
  2545. /**
  2546. * attributes;
  2547. * children;
  2548. *
  2549. * writeable properties:
  2550. * nodeValue,Attr:value,CharacterData:data
  2551. * prefix
  2552. */
  2553. function _removeChild(parentNode,child){
  2554. var previous = child.previousSibling;
  2555. var next = child.nextSibling;
  2556. if(previous){
  2557. previous.nextSibling = next;
  2558. }else{
  2559. parentNode.firstChild = next
  2560. }
  2561. if(next){
  2562. next.previousSibling = previous;
  2563. }else{
  2564. parentNode.lastChild = previous;
  2565. }
  2566. _onUpdateChild(parentNode.ownerDocument,parentNode);
  2567. return child;
  2568. }
  2569. /**
  2570. * preformance key(refChild == null)
  2571. */
  2572. function _insertBefore(parentNode,newChild,nextChild){
  2573. var cp = newChild.parentNode;
  2574. if(cp){
  2575. cp.removeChild(newChild);//remove and update
  2576. }
  2577. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  2578. var newFirst = newChild.firstChild;
  2579. if (newFirst == null) {
  2580. return newChild;
  2581. }
  2582. var newLast = newChild.lastChild;
  2583. }else{
  2584. newFirst = newLast = newChild;
  2585. }
  2586. var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
  2587. newFirst.previousSibling = pre;
  2588. newLast.nextSibling = nextChild;
  2589. if(pre){
  2590. pre.nextSibling = newFirst;
  2591. }else{
  2592. parentNode.firstChild = newFirst;
  2593. }
  2594. if(nextChild == null){
  2595. parentNode.lastChild = newLast;
  2596. }else{
  2597. nextChild.previousSibling = newLast;
  2598. }
  2599. do{
  2600. newFirst.parentNode = parentNode;
  2601. }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
  2602. _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
  2603. //console.log(parentNode.lastChild.nextSibling == null)
  2604. if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
  2605. newChild.firstChild = newChild.lastChild = null;
  2606. }
  2607. return newChild;
  2608. }
  2609. function _appendSingleChild(parentNode,newChild){
  2610. var cp = newChild.parentNode;
  2611. if(cp){
  2612. var pre = parentNode.lastChild;
  2613. cp.removeChild(newChild);//remove and update
  2614. var pre = parentNode.lastChild;
  2615. }
  2616. var pre = parentNode.lastChild;
  2617. newChild.parentNode = parentNode;
  2618. newChild.previousSibling = pre;
  2619. newChild.nextSibling = null;
  2620. if(pre){
  2621. pre.nextSibling = newChild;
  2622. }else{
  2623. parentNode.firstChild = newChild;
  2624. }
  2625. parentNode.lastChild = newChild;
  2626. _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
  2627. return newChild;
  2628. //console.log("__aa",parentNode.lastChild.nextSibling == null)
  2629. }
  2630. Document.prototype = {
  2631. //implementation : null,
  2632. nodeName : '#document',
  2633. nodeType : DOCUMENT_NODE,
  2634. doctype : null,
  2635. documentElement : null,
  2636. _inc : 1,
  2637. insertBefore : function(newChild, refChild){//raises
  2638. if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
  2639. var child = newChild.firstChild;
  2640. while(child){
  2641. var next = child.nextSibling;
  2642. this.insertBefore(child,refChild);
  2643. child = next;
  2644. }
  2645. return newChild;
  2646. }
  2647. if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
  2648. this.documentElement = newChild;
  2649. }
  2650. return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
  2651. },
  2652. removeChild : function(oldChild){
  2653. if(this.documentElement == oldChild){
  2654. this.documentElement = null;
  2655. }
  2656. return _removeChild(this,oldChild);
  2657. },
  2658. // Introduced in DOM Level 2:
  2659. importNode : function(importedNode,deep){
  2660. return importNode(this,importedNode,deep);
  2661. },
  2662. // Introduced in DOM Level 2:
  2663. getElementById : function(id){
  2664. var rtv = null;
  2665. _visitNode(this.documentElement,function(node){
  2666. if(node.nodeType == ELEMENT_NODE){
  2667. if(node.getAttribute('id') == id){
  2668. rtv = node;
  2669. return true;
  2670. }
  2671. }
  2672. })
  2673. return rtv;
  2674. },
  2675. //document factory method:
  2676. createElement : function(tagName){
  2677. var node = new Element();
  2678. node.ownerDocument = this;
  2679. node.nodeName = tagName;
  2680. node.tagName = tagName;
  2681. node.childNodes = new NodeList();
  2682. var attrs = node.attributes = new NamedNodeMap();
  2683. attrs._ownerElement = node;
  2684. return node;
  2685. },
  2686. createDocumentFragment : function(){
  2687. var node = new DocumentFragment();
  2688. node.ownerDocument = this;
  2689. node.childNodes = new NodeList();
  2690. return node;
  2691. },
  2692. createTextNode : function(data){
  2693. var node = new Text();
  2694. node.ownerDocument = this;
  2695. node.appendData(data)
  2696. return node;
  2697. },
  2698. createComment : function(data){
  2699. var node = new Comment();
  2700. node.ownerDocument = this;
  2701. node.appendData(data)
  2702. return node;
  2703. },
  2704. createCDATASection : function(data){
  2705. var node = new CDATASection();
  2706. node.ownerDocument = this;
  2707. node.appendData(data)
  2708. return node;
  2709. },
  2710. createProcessingInstruction : function(target,data){
  2711. var node = new ProcessingInstruction();
  2712. node.ownerDocument = this;
  2713. node.tagName = node.target = target;
  2714. node.nodeValue= node.data = data;
  2715. return node;
  2716. },
  2717. createAttribute : function(name){
  2718. var node = new Attr();
  2719. node.ownerDocument = this;
  2720. node.name = name;
  2721. node.nodeName = name;
  2722. node.localName = name;
  2723. node.specified = true;
  2724. return node;
  2725. },
  2726. createEntityReference : function(name){
  2727. var node = new EntityReference();
  2728. node.ownerDocument = this;
  2729. node.nodeName = name;
  2730. return node;
  2731. },
  2732. // Introduced in DOM Level 2:
  2733. createElementNS : function(namespaceURI,qualifiedName){
  2734. var node = new Element();
  2735. var pl = qualifiedName.split(':');
  2736. var attrs = node.attributes = new NamedNodeMap();
  2737. node.childNodes = new NodeList();
  2738. node.ownerDocument = this;
  2739. node.nodeName = qualifiedName;
  2740. node.tagName = qualifiedName;
  2741. node.namespaceURI = namespaceURI;
  2742. if(pl.length == 2){
  2743. node.prefix = pl[0];
  2744. node.localName = pl[1];
  2745. }else{
  2746. //el.prefix = null;
  2747. node.localName = qualifiedName;
  2748. }
  2749. attrs._ownerElement = node;
  2750. return node;
  2751. },
  2752. // Introduced in DOM Level 2:
  2753. createAttributeNS : function(namespaceURI,qualifiedName){
  2754. var node = new Attr();
  2755. var pl = qualifiedName.split(':');
  2756. node.ownerDocument = this;
  2757. node.nodeName = qualifiedName;
  2758. node.name = qualifiedName;
  2759. node.namespaceURI = namespaceURI;
  2760. node.specified = true;
  2761. if(pl.length == 2){
  2762. node.prefix = pl[0];
  2763. node.localName = pl[1];
  2764. }else{
  2765. //el.prefix = null;
  2766. node.localName = qualifiedName;
  2767. }
  2768. return node;
  2769. }
  2770. };
  2771. _extends(Document,Node);
  2772. function Element() {
  2773. this._nsMap = {};
  2774. };
  2775. Element.prototype = {
  2776. nodeType : ELEMENT_NODE,
  2777. hasAttribute : function(name){
  2778. return this.getAttributeNode(name)!=null;
  2779. },
  2780. getAttribute : function(name){
  2781. var attr = this.getAttributeNode(name);
  2782. return attr && attr.value || '';
  2783. },
  2784. getAttributeNode : function(name){
  2785. return this.attributes.getNamedItem(name);
  2786. },
  2787. setAttribute : function(name, value){
  2788. var attr = this.ownerDocument.createAttribute(name);
  2789. attr.value = attr.nodeValue = "" + value;
  2790. this.setAttributeNode(attr)
  2791. },
  2792. removeAttribute : function(name){
  2793. var attr = this.getAttributeNode(name)
  2794. attr && this.removeAttributeNode(attr);
  2795. },
  2796. //four real opeartion method
  2797. appendChild:function(newChild){
  2798. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  2799. return this.insertBefore(newChild,null);
  2800. }else{
  2801. return _appendSingleChild(this,newChild);
  2802. }
  2803. },
  2804. setAttributeNode : function(newAttr){
  2805. return this.attributes.setNamedItem(newAttr);
  2806. },
  2807. setAttributeNodeNS : function(newAttr){
  2808. return this.attributes.setNamedItemNS(newAttr);
  2809. },
  2810. removeAttributeNode : function(oldAttr){
  2811. //console.log(this == oldAttr.ownerElement)
  2812. return this.attributes.removeNamedItem(oldAttr.nodeName);
  2813. },
  2814. //get real attribute name,and remove it by removeAttributeNode
  2815. removeAttributeNS : function(namespaceURI, localName){
  2816. var old = this.getAttributeNodeNS(namespaceURI, localName);
  2817. old && this.removeAttributeNode(old);
  2818. },
  2819. hasAttributeNS : function(namespaceURI, localName){
  2820. return this.getAttributeNodeNS(namespaceURI, localName)!=null;
  2821. },
  2822. getAttributeNS : function(namespaceURI, localName){
  2823. var attr = this.getAttributeNodeNS(namespaceURI, localName);
  2824. return attr && attr.value || '';
  2825. },
  2826. setAttributeNS : function(namespaceURI, qualifiedName, value){
  2827. var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
  2828. attr.value = attr.nodeValue = "" + value;
  2829. this.setAttributeNode(attr)
  2830. },
  2831. getAttributeNodeNS : function(namespaceURI, localName){
  2832. return this.attributes.getNamedItemNS(namespaceURI, localName);
  2833. },
  2834. getElementsByTagName : function(tagName){
  2835. return new LiveNodeList(this,function(base){
  2836. var ls = [];
  2837. _visitNode(base,function(node){
  2838. if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
  2839. ls.push(node);
  2840. }
  2841. });
  2842. return ls;
  2843. });
  2844. },
  2845. getElementsByTagNameNS : function(namespaceURI, localName){
  2846. return new LiveNodeList(this,function(base){
  2847. var ls = [];
  2848. _visitNode(base,function(node){
  2849. if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
  2850. ls.push(node);
  2851. }
  2852. });
  2853. return ls;
  2854. });
  2855. }
  2856. };
  2857. Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
  2858. Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
  2859. _extends(Element,Node);
  2860. function Attr() {
  2861. };
  2862. Attr.prototype.nodeType = ATTRIBUTE_NODE;
  2863. _extends(Attr,Node);
  2864. function CharacterData() {
  2865. };
  2866. CharacterData.prototype = {
  2867. data : '',
  2868. substringData : function(offset, count) {
  2869. return this.data.substring(offset, offset+count);
  2870. },
  2871. appendData: function(text) {
  2872. text = this.data+text;
  2873. this.nodeValue = this.data = text;
  2874. this.length = text.length;
  2875. },
  2876. insertData: function(offset,text) {
  2877. this.replaceData(offset,0,text);
  2878. },
  2879. appendChild:function(newChild){
  2880. throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
  2881. },
  2882. deleteData: function(offset, count) {
  2883. this.replaceData(offset,count,"");
  2884. },
  2885. replaceData: function(offset, count, text) {
  2886. var start = this.data.substring(0,offset);
  2887. var end = this.data.substring(offset+count);
  2888. text = start + text + end;
  2889. this.nodeValue = this.data = text;
  2890. this.length = text.length;
  2891. }
  2892. }
  2893. _extends(CharacterData,Node);
  2894. function Text() {
  2895. };
  2896. Text.prototype = {
  2897. nodeName : "#text",
  2898. nodeType : TEXT_NODE,
  2899. splitText : function(offset) {
  2900. var text = this.data;
  2901. var newText = text.substring(offset);
  2902. text = text.substring(0, offset);
  2903. this.data = this.nodeValue = text;
  2904. this.length = text.length;
  2905. var newNode = this.ownerDocument.createTextNode(newText);
  2906. if(this.parentNode){
  2907. this.parentNode.insertBefore(newNode, this.nextSibling);
  2908. }
  2909. return newNode;
  2910. }
  2911. }
  2912. _extends(Text,CharacterData);
  2913. function Comment() {
  2914. };
  2915. Comment.prototype = {
  2916. nodeName : "#comment",
  2917. nodeType : COMMENT_NODE
  2918. }
  2919. _extends(Comment,CharacterData);
  2920. function CDATASection() {
  2921. };
  2922. CDATASection.prototype = {
  2923. nodeName : "#cdata-section",
  2924. nodeType : CDATA_SECTION_NODE
  2925. }
  2926. _extends(CDATASection,CharacterData);
  2927. function DocumentType() {
  2928. };
  2929. DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
  2930. _extends(DocumentType,Node);
  2931. function Notation() {
  2932. };
  2933. Notation.prototype.nodeType = NOTATION_NODE;
  2934. _extends(Notation,Node);
  2935. function Entity() {
  2936. };
  2937. Entity.prototype.nodeType = ENTITY_NODE;
  2938. _extends(Entity,Node);
  2939. function EntityReference() {
  2940. };
  2941. EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
  2942. _extends(EntityReference,Node);
  2943. function DocumentFragment() {
  2944. };
  2945. DocumentFragment.prototype.nodeName = "#document-fragment";
  2946. DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
  2947. _extends(DocumentFragment,Node);
  2948. function ProcessingInstruction() {
  2949. }
  2950. ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
  2951. _extends(ProcessingInstruction,Node);
  2952. function XMLSerializer(){}
  2953. XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
  2954. return nodeSerializeToString.call(node,isHtml,nodeFilter);
  2955. }
  2956. Node.prototype.toString = nodeSerializeToString;
  2957. function nodeSerializeToString(isHtml,nodeFilter){
  2958. var buf = [];
  2959. var refNode = this.nodeType == 9?this.documentElement:this;
  2960. var prefix = refNode.prefix;
  2961. var uri = refNode.namespaceURI;
  2962. if(uri && prefix == null){
  2963. //console.log(prefix)
  2964. var prefix = refNode.lookupPrefix(uri);
  2965. if(prefix == null){
  2966. //isHTML = true;
  2967. var visibleNamespaces=[
  2968. {namespace:uri,prefix:null}
  2969. //{namespace:uri,prefix:''}
  2970. ]
  2971. }
  2972. }
  2973. serializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);
  2974. //console.log('###',this.nodeType,uri,prefix,buf.join(''))
  2975. return buf.join('');
  2976. }
  2977. function needNamespaceDefine(node,isHTML, visibleNamespaces) {
  2978. var prefix = node.prefix||'';
  2979. var uri = node.namespaceURI;
  2980. if (!prefix && !uri){
  2981. return false;
  2982. }
  2983. if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
  2984. || uri == 'http://www.w3.org/2000/xmlns/'){
  2985. return false;
  2986. }
  2987. var i = visibleNamespaces.length
  2988. //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
  2989. while (i--) {
  2990. var ns = visibleNamespaces[i];
  2991. // get namespace prefix
  2992. //console.log(node.nodeType,node.tagName,ns.prefix,prefix)
  2993. if (ns.prefix == prefix){
  2994. return ns.namespace != uri;
  2995. }
  2996. }
  2997. //console.log(isHTML,uri,prefix=='')
  2998. //if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
  2999. // return false;
  3000. //}
  3001. //node.flag = '11111'
  3002. //console.error(3,true,node.flag,node.prefix,node.namespaceURI)
  3003. return true;
  3004. }
  3005. function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
  3006. if(nodeFilter){
  3007. node = nodeFilter(node);
  3008. if(node){
  3009. if(typeof node == 'string'){
  3010. buf.push(node);
  3011. return;
  3012. }
  3013. }else{
  3014. return;
  3015. }
  3016. //buf.sort.apply(attrs, attributeSorter);
  3017. }
  3018. switch(node.nodeType){
  3019. case ELEMENT_NODE:
  3020. if (!visibleNamespaces) visibleNamespaces = [];
  3021. var startVisibleNamespaces = visibleNamespaces.length;
  3022. var attrs = node.attributes;
  3023. var len = attrs.length;
  3024. var child = node.firstChild;
  3025. var nodeName = node.tagName;
  3026. isHTML = (htmlns === node.namespaceURI) ||isHTML
  3027. buf.push('<',nodeName);
  3028. for(var i=0;i<len;i++){
  3029. // add namespaces for attributes
  3030. var attr = attrs.item(i);
  3031. if (attr.prefix == 'xmlns') {
  3032. visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });
  3033. }else if(attr.nodeName == 'xmlns'){
  3034. visibleNamespaces.push({ prefix: '', namespace: attr.value });
  3035. }
  3036. }
  3037. for(var i=0;i<len;i++){
  3038. var attr = attrs.item(i);
  3039. if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
  3040. var prefix = attr.prefix||'';
  3041. var uri = attr.namespaceURI;
  3042. var ns = prefix ? ' xmlns:' + prefix : " xmlns";
  3043. buf.push(ns, '="' , uri , '"');
  3044. visibleNamespaces.push({ prefix: prefix, namespace:uri });
  3045. }
  3046. serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
  3047. }
  3048. // add namespace for current node
  3049. if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
  3050. var prefix = node.prefix||'';
  3051. var uri = node.namespaceURI;
  3052. var ns = prefix ? ' xmlns:' + prefix : " xmlns";
  3053. buf.push(ns, '="' , uri , '"');
  3054. visibleNamespaces.push({ prefix: prefix, namespace:uri });
  3055. }
  3056. if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
  3057. buf.push('>');
  3058. //if is cdata child node
  3059. if(isHTML && /^script$/i.test(nodeName)){
  3060. while(child){
  3061. if(child.data){
  3062. buf.push(child.data);
  3063. }else{
  3064. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  3065. }
  3066. child = child.nextSibling;
  3067. }
  3068. }else
  3069. {
  3070. while(child){
  3071. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  3072. child = child.nextSibling;
  3073. }
  3074. }
  3075. buf.push('</',nodeName,'>');
  3076. }else{
  3077. buf.push('/>');
  3078. }
  3079. // remove added visible namespaces
  3080. //visibleNamespaces.length = startVisibleNamespaces;
  3081. return;
  3082. case DOCUMENT_NODE:
  3083. case DOCUMENT_FRAGMENT_NODE:
  3084. var child = node.firstChild;
  3085. while(child){
  3086. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  3087. child = child.nextSibling;
  3088. }
  3089. return;
  3090. case ATTRIBUTE_NODE:
  3091. return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
  3092. case TEXT_NODE:
  3093. return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
  3094. case CDATA_SECTION_NODE:
  3095. return buf.push( '<![CDATA[',node.data,']]>');
  3096. case COMMENT_NODE:
  3097. return buf.push( "<!--",node.data,"-->");
  3098. case DOCUMENT_TYPE_NODE:
  3099. var pubid = node.publicId;
  3100. var sysid = node.systemId;
  3101. buf.push('<!DOCTYPE ',node.name);
  3102. if(pubid){
  3103. buf.push(' PUBLIC "',pubid);
  3104. if (sysid && sysid!='.') {
  3105. buf.push( '" "',sysid);
  3106. }
  3107. buf.push('">');
  3108. }else if(sysid && sysid!='.'){
  3109. buf.push(' SYSTEM "',sysid,'">');
  3110. }else{
  3111. var sub = node.internalSubset;
  3112. if(sub){
  3113. buf.push(" [",sub,"]");
  3114. }
  3115. buf.push(">");
  3116. }
  3117. return;
  3118. case PROCESSING_INSTRUCTION_NODE:
  3119. return buf.push( "<?",node.target," ",node.data,"?>");
  3120. case ENTITY_REFERENCE_NODE:
  3121. return buf.push( '&',node.nodeName,';');
  3122. //case ENTITY_NODE:
  3123. //case NOTATION_NODE:
  3124. default:
  3125. buf.push('??',node.nodeName);
  3126. }
  3127. }
  3128. function importNode(doc,node,deep){
  3129. var node2;
  3130. switch (node.nodeType) {
  3131. case ELEMENT_NODE:
  3132. node2 = node.cloneNode(false);
  3133. node2.ownerDocument = doc;
  3134. //var attrs = node2.attributes;
  3135. //var len = attrs.length;
  3136. //for(var i=0;i<len;i++){
  3137. //node2.setAttributeNodeNS(importNode(doc,attrs.item(i),deep));
  3138. //}
  3139. case DOCUMENT_FRAGMENT_NODE:
  3140. break;
  3141. case ATTRIBUTE_NODE:
  3142. deep = true;
  3143. break;
  3144. //case ENTITY_REFERENCE_NODE:
  3145. //case PROCESSING_INSTRUCTION_NODE:
  3146. ////case TEXT_NODE:
  3147. //case CDATA_SECTION_NODE:
  3148. //case COMMENT_NODE:
  3149. // deep = false;
  3150. // break;
  3151. //case DOCUMENT_NODE:
  3152. //case DOCUMENT_TYPE_NODE:
  3153. //cannot be imported.
  3154. //case ENTITY_NODE:
  3155. //case NOTATION_NODE:
  3156. //can not hit in level3
  3157. //default:throw e;
  3158. }
  3159. if(!node2){
  3160. node2 = node.cloneNode(false);//false
  3161. }
  3162. node2.ownerDocument = doc;
  3163. node2.parentNode = null;
  3164. if(deep){
  3165. var child = node.firstChild;
  3166. while(child){
  3167. node2.appendChild(importNode(doc,child,deep));
  3168. child = child.nextSibling;
  3169. }
  3170. }
  3171. return node2;
  3172. }
  3173. //
  3174. //var _relationMap = {firstChild:1,lastChild:1,previousSibling:1,nextSibling:1,
  3175. // attributes:1,childNodes:1,parentNode:1,documentElement:1,doctype,};
  3176. function cloneNode(doc,node,deep){
  3177. var node2 = new node.constructor();
  3178. for(var n in node){
  3179. var v = node[n];
  3180. if(typeof v != 'object' ){
  3181. if(v != node2[n]){
  3182. node2[n] = v;
  3183. }
  3184. }
  3185. }
  3186. if(node.childNodes){
  3187. node2.childNodes = new NodeList();
  3188. }
  3189. node2.ownerDocument = doc;
  3190. switch (node2.nodeType) {
  3191. case ELEMENT_NODE:
  3192. var attrs = node.attributes;
  3193. var attrs2 = node2.attributes = new NamedNodeMap();
  3194. var len = attrs.length
  3195. attrs2._ownerElement = node2;
  3196. for(var i=0;i<len;i++){
  3197. node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
  3198. }
  3199. break;;
  3200. case ATTRIBUTE_NODE:
  3201. deep = true;
  3202. }
  3203. if(deep){
  3204. var child = node.firstChild;
  3205. while(child){
  3206. node2.appendChild(cloneNode(doc,child,deep));
  3207. child = child.nextSibling;
  3208. }
  3209. }
  3210. return node2;
  3211. }
  3212. function __set__(object,key,value){
  3213. object[key] = value
  3214. }
  3215. //do dynamic
  3216. try{
  3217. if(Object.defineProperty){
  3218. Object.defineProperty(LiveNodeList.prototype,'length',{
  3219. get:function(){
  3220. _updateLiveList(this);
  3221. return this.$$length;
  3222. }
  3223. });
  3224. Object.defineProperty(Node.prototype,'textContent',{
  3225. get:function(){
  3226. return getTextContent(this);
  3227. },
  3228. set:function(data){
  3229. switch(this.nodeType){
  3230. case ELEMENT_NODE:
  3231. case DOCUMENT_FRAGMENT_NODE:
  3232. while(this.firstChild){
  3233. this.removeChild(this.firstChild);
  3234. }
  3235. if(data || String(data)){
  3236. this.appendChild(this.ownerDocument.createTextNode(data));
  3237. }
  3238. break;
  3239. default:
  3240. //TODO:
  3241. this.data = data;
  3242. this.value = data;
  3243. this.nodeValue = data;
  3244. }
  3245. }
  3246. })
  3247. function getTextContent(node){
  3248. switch(node.nodeType){
  3249. case ELEMENT_NODE:
  3250. case DOCUMENT_FRAGMENT_NODE:
  3251. var buf = [];
  3252. node = node.firstChild;
  3253. while(node){
  3254. if(node.nodeType!==7 && node.nodeType !==8){
  3255. buf.push(getTextContent(node));
  3256. }
  3257. node = node.nextSibling;
  3258. }
  3259. return buf.join('');
  3260. default:
  3261. return node.nodeValue;
  3262. }
  3263. }
  3264. __set__ = function(object,key,value){
  3265. //console.log(value)
  3266. object['$$'+key] = value
  3267. }
  3268. }
  3269. }catch(e){//ie8
  3270. }
  3271. //if(typeof require == 'function'){
  3272. exports.DOMImplementation = DOMImplementation;
  3273. exports.XMLSerializer = XMLSerializer;
  3274. //}
  3275. },{}],7:[function(require,module,exports){
  3276. //[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
  3277. //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
  3278. //[5] Name ::= NameStartChar (NameChar)*
  3279. 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
  3280. var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
  3281. var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
  3282. //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
  3283. //var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
  3284. //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
  3285. //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
  3286. var S_TAG = 0;//tag name offerring
  3287. var S_ATTR = 1;//attr name offerring
  3288. var S_ATTR_SPACE=2;//attr name end and space offer
  3289. var S_EQ = 3;//=space?
  3290. var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
  3291. var S_ATTR_END = 5;//attr value end and no space(quot end)
  3292. var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
  3293. var S_TAG_CLOSE = 7;//closed el<el />
  3294. function XMLReader(){
  3295. }
  3296. XMLReader.prototype = {
  3297. parse:function(source,defaultNSMap,entityMap){
  3298. var domBuilder = this.domBuilder;
  3299. domBuilder.startDocument();
  3300. _copy(defaultNSMap ,defaultNSMap = {})
  3301. parse(source,defaultNSMap,entityMap,
  3302. domBuilder,this.errorHandler);
  3303. domBuilder.endDocument();
  3304. }
  3305. }
  3306. function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
  3307. function fixedFromCharCode(code) {
  3308. // String.prototype.fromCharCode does not supports
  3309. // > 2 bytes unicode chars directly
  3310. if (code > 0xffff) {
  3311. code -= 0x10000;
  3312. var surrogate1 = 0xd800 + (code >> 10)
  3313. , surrogate2 = 0xdc00 + (code & 0x3ff);
  3314. return String.fromCharCode(surrogate1, surrogate2);
  3315. } else {
  3316. return String.fromCharCode(code);
  3317. }
  3318. }
  3319. function entityReplacer(a){
  3320. var k = a.slice(1,-1);
  3321. if(k in entityMap){
  3322. return entityMap[k];
  3323. }else if(k.charAt(0) === '#'){
  3324. return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
  3325. }else{
  3326. errorHandler.error('entity not found:'+a);
  3327. return a;
  3328. }
  3329. }
  3330. function appendText(end){//has some bugs
  3331. if(end>start){
  3332. var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
  3333. locator&&position(start);
  3334. domBuilder.characters(xt,0,end-start);
  3335. start = end
  3336. }
  3337. }
  3338. function position(p,m){
  3339. while(p>=lineEnd && (m = linePattern.exec(source))){
  3340. lineStart = m.index;
  3341. lineEnd = lineStart + m[0].length;
  3342. locator.lineNumber++;
  3343. //console.log('line++:',locator,startPos,endPos)
  3344. }
  3345. locator.columnNumber = p-lineStart+1;
  3346. }
  3347. var lineStart = 0;
  3348. var lineEnd = 0;
  3349. var linePattern = /.*(?:\r\n?|\n)|.*$/g
  3350. var locator = domBuilder.locator;
  3351. var parseStack = [{currentNSMap:defaultNSMapCopy}]
  3352. var closeMap = {};
  3353. var start = 0;
  3354. while(true){
  3355. try{
  3356. var tagStart = source.indexOf('<',start);
  3357. if(tagStart<0){
  3358. if(!source.substr(start).match(/^\s*$/)){
  3359. var doc = domBuilder.doc;
  3360. var text = doc.createTextNode(source.substr(start));
  3361. doc.appendChild(text);
  3362. domBuilder.currentElement = text;
  3363. }
  3364. return;
  3365. }
  3366. if(tagStart>start){
  3367. appendText(tagStart);
  3368. }
  3369. switch(source.charAt(tagStart+1)){
  3370. case '/':
  3371. var end = source.indexOf('>',tagStart+3);
  3372. var tagName = source.substring(tagStart+2,end);
  3373. var config = parseStack.pop();
  3374. if(end<0){
  3375. tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
  3376. //console.error('#@@@@@@'+tagName)
  3377. errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
  3378. end = tagStart+1+tagName.length;
  3379. }else if(tagName.match(/\s</)){
  3380. tagName = tagName.replace(/[\s<].*/,'');
  3381. errorHandler.error("end tag name: "+tagName+' maybe not complete');
  3382. end = tagStart+1+tagName.length;
  3383. }
  3384. //console.error(parseStack.length,parseStack)
  3385. //console.error(config);
  3386. var localNSMap = config.localNSMap;
  3387. var endMatch = config.tagName == tagName;
  3388. var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
  3389. if(endIgnoreCaseMach){
  3390. domBuilder.endElement(config.uri,config.localName,tagName);
  3391. if(localNSMap){
  3392. for(var prefix in localNSMap){
  3393. domBuilder.endPrefixMapping(prefix) ;
  3394. }
  3395. }
  3396. if(!endMatch){
  3397. errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
  3398. }
  3399. }else{
  3400. parseStack.push(config)
  3401. }
  3402. end++;
  3403. break;
  3404. // end elment
  3405. case '?':// <?...?>
  3406. locator&&position(tagStart);
  3407. end = parseInstruction(source,tagStart,domBuilder);
  3408. break;
  3409. case '!':// <!doctype,<![CDATA,<!--
  3410. locator&&position(tagStart);
  3411. end = parseDCC(source,tagStart,domBuilder,errorHandler);
  3412. break;
  3413. default:
  3414. locator&&position(tagStart);
  3415. var el = new ElementAttributes();
  3416. var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  3417. //elStartEnd
  3418. var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
  3419. var len = el.length;
  3420. if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
  3421. el.closed = true;
  3422. if(!entityMap.nbsp){
  3423. errorHandler.warning('unclosed xml attribute');
  3424. }
  3425. }
  3426. if(locator && len){
  3427. var locator2 = copyLocator(locator,{});
  3428. //try{//attribute position fixed
  3429. for(var i = 0;i<len;i++){
  3430. var a = el[i];
  3431. position(a.offset);
  3432. a.locator = copyLocator(locator,{});
  3433. }
  3434. //}catch(e){console.error('@@@@@'+e)}
  3435. domBuilder.locator = locator2
  3436. if(appendElement(el,domBuilder,currentNSMap)){
  3437. parseStack.push(el)
  3438. }
  3439. domBuilder.locator = locator;
  3440. }else{
  3441. if(appendElement(el,domBuilder,currentNSMap)){
  3442. parseStack.push(el)
  3443. }
  3444. }
  3445. if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
  3446. end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
  3447. }else{
  3448. end++;
  3449. }
  3450. }
  3451. }catch(e){
  3452. errorHandler.error('element parse error: '+e)
  3453. //errorHandler.error('element parse error: '+e);
  3454. end = -1;
  3455. //throw e;
  3456. }
  3457. if(end>start){
  3458. start = end;
  3459. }else{
  3460. //TODO: 这里有可能sax回退,有位置错误风险
  3461. appendText(Math.max(tagStart,start)+1);
  3462. }
  3463. }
  3464. }
  3465. function copyLocator(f,t){
  3466. t.lineNumber = f.lineNumber;
  3467. t.columnNumber = f.columnNumber;
  3468. return t;
  3469. }
  3470. /**
  3471. * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
  3472. * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
  3473. */
  3474. function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
  3475. var attrName;
  3476. var value;
  3477. var p = ++start;
  3478. var s = S_TAG;//status
  3479. while(true){
  3480. var c = source.charAt(p);
  3481. switch(c){
  3482. case '=':
  3483. if(s === S_ATTR){//attrName
  3484. attrName = source.slice(start,p);
  3485. s = S_EQ;
  3486. }else if(s === S_ATTR_SPACE){
  3487. s = S_EQ;
  3488. }else{
  3489. //fatalError: equal must after attrName or space after attrName
  3490. throw new Error('attribute equal must after attrName');
  3491. }
  3492. break;
  3493. case '\'':
  3494. case '"':
  3495. if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
  3496. ){//equal
  3497. if(s === S_ATTR){
  3498. errorHandler.warning('attribute value must after "="')
  3499. attrName = source.slice(start,p)
  3500. }
  3501. start = p+1;
  3502. p = source.indexOf(c,start)
  3503. if(p>0){
  3504. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  3505. el.add(attrName,value,start-1);
  3506. s = S_ATTR_END;
  3507. }else{
  3508. //fatalError: no end quot match
  3509. throw new Error('attribute value no end \''+c+'\' match');
  3510. }
  3511. }else if(s == S_ATTR_NOQUOT_VALUE){
  3512. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  3513. //console.log(attrName,value,start,p)
  3514. el.add(attrName,value,start);
  3515. //console.dir(el)
  3516. errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
  3517. start = p+1;
  3518. s = S_ATTR_END
  3519. }else{
  3520. //fatalError: no equal before
  3521. throw new Error('attribute value must after "="');
  3522. }
  3523. break;
  3524. case '/':
  3525. switch(s){
  3526. case S_TAG:
  3527. el.setTagName(source.slice(start,p));
  3528. case S_ATTR_END:
  3529. case S_TAG_SPACE:
  3530. case S_TAG_CLOSE:
  3531. s =S_TAG_CLOSE;
  3532. el.closed = true;
  3533. case S_ATTR_NOQUOT_VALUE:
  3534. case S_ATTR:
  3535. case S_ATTR_SPACE:
  3536. break;
  3537. //case S_EQ:
  3538. default:
  3539. throw new Error("attribute invalid close char('/')")
  3540. }
  3541. break;
  3542. case ''://end document
  3543. //throw new Error('unexpected end of input')
  3544. errorHandler.error('unexpected end of input');
  3545. if(s == S_TAG){
  3546. el.setTagName(source.slice(start,p));
  3547. }
  3548. return p;
  3549. case '>':
  3550. switch(s){
  3551. case S_TAG:
  3552. el.setTagName(source.slice(start,p));
  3553. case S_ATTR_END:
  3554. case S_TAG_SPACE:
  3555. case S_TAG_CLOSE:
  3556. break;//normal
  3557. case S_ATTR_NOQUOT_VALUE://Compatible state
  3558. case S_ATTR:
  3559. value = source.slice(start,p);
  3560. if(value.slice(-1) === '/'){
  3561. el.closed = true;
  3562. value = value.slice(0,-1)
  3563. }
  3564. case S_ATTR_SPACE:
  3565. if(s === S_ATTR_SPACE){
  3566. value = attrName;
  3567. }
  3568. if(s == S_ATTR_NOQUOT_VALUE){
  3569. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  3570. el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
  3571. }else{
  3572. if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
  3573. errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
  3574. }
  3575. el.add(value,value,start)
  3576. }
  3577. break;
  3578. case S_EQ:
  3579. throw new Error('attribute value missed!!');
  3580. }
  3581. // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
  3582. return p;
  3583. /*xml space '\x20' | #x9 | #xD | #xA; */
  3584. case '\u0080':
  3585. c = ' ';
  3586. default:
  3587. if(c<= ' '){//space
  3588. switch(s){
  3589. case S_TAG:
  3590. el.setTagName(source.slice(start,p));//tagName
  3591. s = S_TAG_SPACE;
  3592. break;
  3593. case S_ATTR:
  3594. attrName = source.slice(start,p)
  3595. s = S_ATTR_SPACE;
  3596. break;
  3597. case S_ATTR_NOQUOT_VALUE:
  3598. var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  3599. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  3600. el.add(attrName,value,start)
  3601. case S_ATTR_END:
  3602. s = S_TAG_SPACE;
  3603. break;
  3604. //case S_TAG_SPACE:
  3605. //case S_EQ:
  3606. //case S_ATTR_SPACE:
  3607. // void();break;
  3608. //case S_TAG_CLOSE:
  3609. //ignore warning
  3610. }
  3611. }else{//not space
  3612. //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
  3613. //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
  3614. switch(s){
  3615. //case S_TAG:void();break;
  3616. //case S_ATTR:void();break;
  3617. //case S_ATTR_NOQUOT_VALUE:void();break;
  3618. case S_ATTR_SPACE:
  3619. var tagName = el.tagName;
  3620. if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
  3621. errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
  3622. }
  3623. el.add(attrName,attrName,start);
  3624. start = p;
  3625. s = S_ATTR;
  3626. break;
  3627. case S_ATTR_END:
  3628. errorHandler.warning('attribute space is required"'+attrName+'"!!')
  3629. case S_TAG_SPACE:
  3630. s = S_ATTR;
  3631. start = p;
  3632. break;
  3633. case S_EQ:
  3634. s = S_ATTR_NOQUOT_VALUE;
  3635. start = p;
  3636. break;
  3637. case S_TAG_CLOSE:
  3638. throw new Error("elements closed character '/' and '>' must be connected to");
  3639. }
  3640. }
  3641. }//end outer switch
  3642. //console.log('p++',p)
  3643. p++;
  3644. }
  3645. }
  3646. /**
  3647. * @return true if has new namespace define
  3648. */
  3649. function appendElement(el,domBuilder,currentNSMap){
  3650. var tagName = el.tagName;
  3651. var localNSMap = null;
  3652. //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  3653. var i = el.length;
  3654. while(i--){
  3655. var a = el[i];
  3656. var qName = a.qName;
  3657. var value = a.value;
  3658. var nsp = qName.indexOf(':');
  3659. if(nsp>0){
  3660. var prefix = a.prefix = qName.slice(0,nsp);
  3661. var localName = qName.slice(nsp+1);
  3662. var nsPrefix = prefix === 'xmlns' && localName
  3663. }else{
  3664. localName = qName;
  3665. prefix = null
  3666. nsPrefix = qName === 'xmlns' && ''
  3667. }
  3668. //can not set prefix,because prefix !== ''
  3669. a.localName = localName ;
  3670. //prefix == null for no ns prefix attribute
  3671. if(nsPrefix !== false){//hack!!
  3672. if(localNSMap == null){
  3673. localNSMap = {}
  3674. //console.log(currentNSMap,0)
  3675. _copy(currentNSMap,currentNSMap={})
  3676. //console.log(currentNSMap,1)
  3677. }
  3678. currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
  3679. a.uri = 'http://www.w3.org/2000/xmlns/'
  3680. domBuilder.startPrefixMapping(nsPrefix, value)
  3681. }
  3682. }
  3683. var i = el.length;
  3684. while(i--){
  3685. a = el[i];
  3686. var prefix = a.prefix;
  3687. if(prefix){//no prefix attribute has no namespace
  3688. if(prefix === 'xml'){
  3689. a.uri = 'http://www.w3.org/XML/1998/namespace';
  3690. }if(prefix !== 'xmlns'){
  3691. a.uri = currentNSMap[prefix || '']
  3692. //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
  3693. }
  3694. }
  3695. }
  3696. var nsp = tagName.indexOf(':');
  3697. if(nsp>0){
  3698. prefix = el.prefix = tagName.slice(0,nsp);
  3699. localName = el.localName = tagName.slice(nsp+1);
  3700. }else{
  3701. prefix = null;//important!!
  3702. localName = el.localName = tagName;
  3703. }
  3704. //no prefix element has default namespace
  3705. var ns = el.uri = currentNSMap[prefix || ''];
  3706. domBuilder.startElement(ns,localName,tagName,el);
  3707. //endPrefixMapping and startPrefixMapping have not any help for dom builder
  3708. //localNSMap = null
  3709. if(el.closed){
  3710. domBuilder.endElement(ns,localName,tagName);
  3711. if(localNSMap){
  3712. for(prefix in localNSMap){
  3713. domBuilder.endPrefixMapping(prefix)
  3714. }
  3715. }
  3716. }else{
  3717. el.currentNSMap = currentNSMap;
  3718. el.localNSMap = localNSMap;
  3719. //parseStack.push(el);
  3720. return true;
  3721. }
  3722. }
  3723. function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
  3724. if(/^(?:script|textarea)$/i.test(tagName)){
  3725. var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
  3726. var text = source.substring(elStartEnd+1,elEndStart);
  3727. if(/[&<]/.test(text)){
  3728. if(/^script$/i.test(tagName)){
  3729. //if(!/\]\]>/.test(text)){
  3730. //lexHandler.startCDATA();
  3731. domBuilder.characters(text,0,text.length);
  3732. //lexHandler.endCDATA();
  3733. return elEndStart;
  3734. //}
  3735. }//}else{//text area
  3736. text = text.replace(/&#?\w+;/g,entityReplacer);
  3737. domBuilder.characters(text,0,text.length);
  3738. return elEndStart;
  3739. //}
  3740. }
  3741. }
  3742. return elStartEnd+1;
  3743. }
  3744. function fixSelfClosed(source,elStartEnd,tagName,closeMap){
  3745. //if(tagName in closeMap){
  3746. var pos = closeMap[tagName];
  3747. if(pos == null){
  3748. //console.log(tagName)
  3749. pos = source.lastIndexOf('</'+tagName+'>')
  3750. if(pos<elStartEnd){//忘记闭合
  3751. pos = source.lastIndexOf('</'+tagName)
  3752. }
  3753. closeMap[tagName] =pos
  3754. }
  3755. return pos<elStartEnd;
  3756. //}
  3757. }
  3758. function _copy(source,target){
  3759. for(var n in source){target[n] = source[n]}
  3760. }
  3761. function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
  3762. var next= source.charAt(start+2)
  3763. switch(next){
  3764. case '-':
  3765. if(source.charAt(start + 3) === '-'){
  3766. var end = source.indexOf('-->',start+4);
  3767. //append comment source.substring(4,end)//<!--
  3768. if(end>start){
  3769. domBuilder.comment(source,start+4,end-start-4);
  3770. return end+3;
  3771. }else{
  3772. errorHandler.error("Unclosed comment");
  3773. return -1;
  3774. }
  3775. }else{
  3776. //error
  3777. return -1;
  3778. }
  3779. default:
  3780. if(source.substr(start+3,6) == 'CDATA['){
  3781. var end = source.indexOf(']]>',start+9);
  3782. domBuilder.startCDATA();
  3783. domBuilder.characters(source,start+9,end-start-9);
  3784. domBuilder.endCDATA()
  3785. return end+3;
  3786. }
  3787. //<!DOCTYPE
  3788. //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
  3789. var matchs = split(source,start);
  3790. var len = matchs.length;
  3791. if(len>1 && /!doctype/i.test(matchs[0][0])){
  3792. var name = matchs[1][0];
  3793. var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
  3794. var sysid = len>4 && matchs[4][0];
  3795. var lastMatch = matchs[len-1]
  3796. domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
  3797. sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
  3798. domBuilder.endDTD();
  3799. return lastMatch.index+lastMatch[0].length
  3800. }
  3801. }
  3802. return -1;
  3803. }
  3804. function parseInstruction(source,start,domBuilder){
  3805. var end = source.indexOf('?>',start);
  3806. if(end){
  3807. var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
  3808. if(match){
  3809. var len = match[0].length;
  3810. domBuilder.processingInstruction(match[1], match[2]) ;
  3811. return end+2;
  3812. }else{//error
  3813. return -1;
  3814. }
  3815. }
  3816. return -1;
  3817. }
  3818. /**
  3819. * @param source
  3820. */
  3821. function ElementAttributes(source){
  3822. }
  3823. ElementAttributes.prototype = {
  3824. setTagName:function(tagName){
  3825. if(!tagNamePattern.test(tagName)){
  3826. throw new Error('invalid tagName:'+tagName)
  3827. }
  3828. this.tagName = tagName
  3829. },
  3830. add:function(qName,value,offset){
  3831. if(!tagNamePattern.test(qName)){
  3832. throw new Error('invalid attribute:'+qName)
  3833. }
  3834. this[this.length++] = {qName:qName,value:value,offset:offset}
  3835. },
  3836. length:0,
  3837. getLocalName:function(i){return this[i].localName},
  3838. getLocator:function(i){return this[i].locator},
  3839. getQName:function(i){return this[i].qName},
  3840. getURI:function(i){return this[i].uri},
  3841. getValue:function(i){return this[i].value}
  3842. // ,getIndex:function(uri, localName)){
  3843. // if(localName){
  3844. //
  3845. // }else{
  3846. // var qName = uri
  3847. // }
  3848. // },
  3849. // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
  3850. // getType:function(uri,localName){}
  3851. // getType:function(i){},
  3852. }
  3853. function _set_proto_(thiz,parent){
  3854. thiz.__proto__ = parent;
  3855. return thiz;
  3856. }
  3857. if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
  3858. _set_proto_ = function(thiz,parent){
  3859. function p(){};
  3860. p.prototype = parent;
  3861. p = new p();
  3862. for(parent in thiz){
  3863. p[parent] = thiz[parent];
  3864. }
  3865. return p;
  3866. }
  3867. }
  3868. function split(source,start){
  3869. var match;
  3870. var buf = [];
  3871. var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
  3872. reg.lastIndex = start;
  3873. reg.exec(source);//skip <
  3874. while(match = reg.exec(source)){
  3875. buf.push(match);
  3876. if(match[1])return buf;
  3877. }
  3878. }
  3879. exports.XMLReader = XMLReader;
  3880. },{}]},{},[1])(1)
  3881. });