You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plist.js 286KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888
  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 r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. /**
  3. * Parser functions.
  4. */
  5. var parserFunctions = require('./lib/parse');
  6. Object.keys(parserFunctions).forEach(function (k) { exports[k] = parserFunctions[k]; });
  7. /**
  8. * Builder functions.
  9. */
  10. var builderFunctions = require('./lib/build');
  11. Object.keys(builderFunctions).forEach(function (k) { exports[k] = builderFunctions[k]; });
  12. },{"./lib/build":2,"./lib/parse":3}],2:[function(require,module,exports){
  13. (function (Buffer){(function (){
  14. /**
  15. * Module dependencies.
  16. */
  17. var base64 = require('base64-js');
  18. var xmlbuilder = require('xmlbuilder');
  19. /**
  20. * Module exports.
  21. */
  22. exports.build = build;
  23. /**
  24. * Accepts a `Date` instance and returns an ISO date string.
  25. *
  26. * @param {Date} d - Date instance to serialize
  27. * @returns {String} ISO date string representation of `d`
  28. * @api private
  29. */
  30. function ISODateString(d){
  31. function pad(n){
  32. return n < 10 ? '0' + n : n;
  33. }
  34. return d.getUTCFullYear()+'-'
  35. + pad(d.getUTCMonth()+1)+'-'
  36. + pad(d.getUTCDate())+'T'
  37. + pad(d.getUTCHours())+':'
  38. + pad(d.getUTCMinutes())+':'
  39. + pad(d.getUTCSeconds())+'Z';
  40. }
  41. /**
  42. * Returns the internal "type" of `obj` via the
  43. * `Object.prototype.toString()` trick.
  44. *
  45. * @param {Mixed} obj - any value
  46. * @returns {String} the internal "type" name
  47. * @api private
  48. */
  49. var toString = Object.prototype.toString;
  50. function type (obj) {
  51. var m = toString.call(obj).match(/\[object (.*)\]/);
  52. return m ? m[1] : m;
  53. }
  54. /**
  55. * Generate an XML plist string from the input object `obj`.
  56. *
  57. * @param {Object} obj - the object to convert
  58. * @param {Object} [opts] - optional options object
  59. * @returns {String} converted plist XML string
  60. * @api public
  61. */
  62. function build (obj, opts) {
  63. var XMLHDR = {
  64. version: '1.0',
  65. encoding: 'UTF-8'
  66. };
  67. var XMLDTD = {
  68. pubid: '-//Apple//DTD PLIST 1.0//EN',
  69. sysid: 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'
  70. };
  71. var doc = xmlbuilder.create('plist');
  72. doc.dec(XMLHDR.version, XMLHDR.encoding, XMLHDR.standalone);
  73. doc.dtd(XMLDTD.pubid, XMLDTD.sysid);
  74. doc.att('version', '1.0');
  75. walk_obj(obj, doc);
  76. if (!opts) opts = {};
  77. // default `pretty` to `true`
  78. opts.pretty = opts.pretty !== false;
  79. return doc.end(opts);
  80. }
  81. /**
  82. * depth first, recursive traversal of a javascript object. when complete,
  83. * next_child contains a reference to the build XML object.
  84. *
  85. * @api private
  86. */
  87. function walk_obj(next, next_child) {
  88. var tag_type, i, prop;
  89. var name = type(next);
  90. if ('Undefined' == name) {
  91. return;
  92. } else if (Array.isArray(next)) {
  93. next_child = next_child.ele('array');
  94. for (i = 0; i < next.length; i++) {
  95. walk_obj(next[i], next_child);
  96. }
  97. } else if (Buffer.isBuffer(next)) {
  98. next_child.ele('data').raw(next.toString('base64'));
  99. } else if ('Object' == name) {
  100. next_child = next_child.ele('dict');
  101. for (prop in next) {
  102. if (next.hasOwnProperty(prop)) {
  103. next_child.ele('key').txt(prop);
  104. walk_obj(next[prop], next_child);
  105. }
  106. }
  107. } else if ('Number' == name) {
  108. // detect if this is an integer or real
  109. // TODO: add an ability to force one way or another via a "cast"
  110. tag_type = (next % 1 === 0) ? 'integer' : 'real';
  111. next_child.ele(tag_type).txt(next.toString());
  112. } else if ('Date' == name) {
  113. next_child.ele('date').txt(ISODateString(new Date(next)));
  114. } else if ('Boolean' == name) {
  115. next_child.ele(next ? 'true' : 'false');
  116. } else if ('String' == name) {
  117. next_child.ele('string').txt(next);
  118. } else if ('ArrayBuffer' == name) {
  119. next_child.ele('data').raw(base64.fromByteArray(next));
  120. } else if (next && next.buffer && 'ArrayBuffer' == type(next.buffer)) {
  121. // a typed array
  122. next_child.ele('data').raw(base64.fromByteArray(new Uint8Array(next.buffer), next_child));
  123. } else if ('Null' === name) {
  124. next_child.ele('null').txt('');
  125. }
  126. }
  127. }).call(this)}).call(this,{"isBuffer":require("../node_modules/is-buffer/index.js")})
  128. },{"../node_modules/is-buffer/index.js":11,"base64-js":8,"xmlbuilder":44}],3:[function(require,module,exports){
  129. (function (Buffer){(function (){
  130. /**
  131. * Module dependencies.
  132. */
  133. const { DOMParser } = require('@xmldom/xmldom');
  134. /**
  135. * Module exports.
  136. */
  137. exports.parse = parse;
  138. var TEXT_NODE = 3;
  139. var CDATA_NODE = 4;
  140. var COMMENT_NODE = 8;
  141. /**
  142. * We ignore raw text (usually whitespace), <!-- xml comments -->,
  143. * and raw CDATA nodes.
  144. *
  145. * @param {Element} node
  146. * @returns {Boolean}
  147. * @api private
  148. */
  149. function shouldIgnoreNode (node) {
  150. return node.nodeType === TEXT_NODE
  151. || node.nodeType === COMMENT_NODE
  152. || node.nodeType === CDATA_NODE;
  153. }
  154. /**
  155. * Check if the node is empty. Some plist file has such node:
  156. * <key />
  157. * this node shoud be ignored.
  158. *
  159. * @see https://github.com/TooTallNate/plist.js/issues/66
  160. * @param {Element} node
  161. * @returns {Boolean}
  162. * @api private
  163. */
  164. function isEmptyNode(node){
  165. if(!node.childNodes || node.childNodes.length === 0) {
  166. return true;
  167. } else {
  168. return false;
  169. }
  170. }
  171. function invariant(test, message) {
  172. if (!test) {
  173. throw new Error(message);
  174. }
  175. }
  176. /**
  177. * Parses a Plist XML string. Returns an Object.
  178. *
  179. * @param {String} xml - the XML String to decode
  180. * @returns {Mixed} the decoded value from the Plist XML
  181. * @api public
  182. */
  183. function parse (xml) {
  184. var doc = new DOMParser().parseFromString(xml);
  185. invariant(
  186. doc.documentElement.nodeName === 'plist',
  187. 'malformed document. First element should be <plist>'
  188. );
  189. var plist = parsePlistXML(doc.documentElement);
  190. // the root <plist> node gets interpreted as an Array,
  191. // so pull out the inner data first
  192. if (plist.length == 1) plist = plist[0];
  193. return plist;
  194. }
  195. /**
  196. * Convert an XML based plist document into a JSON representation.
  197. *
  198. * @param {Object} xml_node - current XML node in the plist
  199. * @returns {Mixed} built up JSON object
  200. * @api private
  201. */
  202. function parsePlistXML (node) {
  203. var i, new_obj, key, val, new_arr, res, counter, type;
  204. if (!node)
  205. return null;
  206. if (node.nodeName === 'plist') {
  207. new_arr = [];
  208. if (isEmptyNode(node)) {
  209. return new_arr;
  210. }
  211. for (i=0; i < node.childNodes.length; i++) {
  212. if (!shouldIgnoreNode(node.childNodes[i])) {
  213. new_arr.push( parsePlistXML(node.childNodes[i]));
  214. }
  215. }
  216. return new_arr;
  217. } else if (node.nodeName === 'dict') {
  218. new_obj = {};
  219. key = null;
  220. counter = 0;
  221. if (isEmptyNode(node)) {
  222. return new_obj;
  223. }
  224. for (i=0; i < node.childNodes.length; i++) {
  225. if (shouldIgnoreNode(node.childNodes[i])) continue;
  226. if (counter % 2 === 0) {
  227. invariant(
  228. node.childNodes[i].nodeName === 'key',
  229. 'Missing key while parsing <dict/>.'
  230. );
  231. key = parsePlistXML(node.childNodes[i]);
  232. } else {
  233. invariant(
  234. node.childNodes[i].nodeName !== 'key',
  235. 'Unexpected key "'
  236. + parsePlistXML(node.childNodes[i])
  237. + '" while parsing <dict/>.'
  238. );
  239. new_obj[key] = parsePlistXML(node.childNodes[i]);
  240. }
  241. counter += 1;
  242. }
  243. if (counter % 2 === 1) {
  244. new_obj[key] = '';
  245. }
  246. return new_obj;
  247. } else if (node.nodeName === 'array') {
  248. new_arr = [];
  249. if (isEmptyNode(node)) {
  250. return new_arr;
  251. }
  252. for (i=0; i < node.childNodes.length; i++) {
  253. if (!shouldIgnoreNode(node.childNodes[i])) {
  254. res = parsePlistXML(node.childNodes[i]);
  255. if (null != res) new_arr.push(res);
  256. }
  257. }
  258. return new_arr;
  259. } else if (node.nodeName === '#text') {
  260. // TODO: what should we do with text types? (CDATA sections)
  261. } else if (node.nodeName === 'key') {
  262. if (isEmptyNode(node)) {
  263. return '';
  264. }
  265. invariant(
  266. node.childNodes[0].nodeValue !== '__proto__',
  267. '__proto__ keys can lead to prototype pollution. More details on CVE-2022-22912'
  268. );
  269. return node.childNodes[0].nodeValue;
  270. } else if (node.nodeName === 'string') {
  271. res = '';
  272. if (isEmptyNode(node)) {
  273. return res;
  274. }
  275. for (i=0; i < node.childNodes.length; i++) {
  276. var type = node.childNodes[i].nodeType;
  277. if (type === TEXT_NODE || type === CDATA_NODE) {
  278. res += node.childNodes[i].nodeValue;
  279. }
  280. }
  281. return res;
  282. } else if (node.nodeName === 'integer') {
  283. invariant(
  284. !isEmptyNode(node),
  285. 'Cannot parse "" as integer.'
  286. );
  287. return parseInt(node.childNodes[0].nodeValue, 10);
  288. } else if (node.nodeName === 'real') {
  289. invariant(
  290. !isEmptyNode(node),
  291. 'Cannot parse "" as real.'
  292. );
  293. res = '';
  294. for (i=0; i < node.childNodes.length; i++) {
  295. if (node.childNodes[i].nodeType === TEXT_NODE) {
  296. res += node.childNodes[i].nodeValue;
  297. }
  298. }
  299. return parseFloat(res);
  300. } else if (node.nodeName === 'data') {
  301. res = '';
  302. if (isEmptyNode(node)) {
  303. return Buffer.from(res, 'base64');
  304. }
  305. for (i=0; i < node.childNodes.length; i++) {
  306. if (node.childNodes[i].nodeType === TEXT_NODE) {
  307. res += node.childNodes[i].nodeValue.replace(/\s+/g, '');
  308. }
  309. }
  310. return Buffer.from(res, 'base64');
  311. } else if (node.nodeName === 'date') {
  312. invariant(
  313. !isEmptyNode(node),
  314. 'Cannot parse "" as Date.'
  315. )
  316. return new Date(node.childNodes[0].nodeValue);
  317. } else if (node.nodeName === 'null') {
  318. return null;
  319. } else if (node.nodeName === 'true') {
  320. return true;
  321. } else if (node.nodeName === 'false') {
  322. return false;
  323. } else {
  324. throw new Error('Invalid PLIST tag ' + node.nodeName);
  325. }
  326. }
  327. }).call(this)}).call(this,require("buffer").Buffer)
  328. },{"./xmldom/dom-parser":4,"buffer":9}],4:[function(require,module,exports){
  329. function DOMParser(options){
  330. this.options = options ||{locator:{}};
  331. }
  332. DOMParser.prototype.parseFromString = function(source,mimeType){
  333. var options = this.options;
  334. var sax = new XMLReader();
  335. var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
  336. var errorHandler = options.errorHandler;
  337. var locator = options.locator;
  338. var defaultNSMap = options.xmlns||{};
  339. var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
  340. var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
  341. if(locator){
  342. domBuilder.setDocumentLocator(locator)
  343. }
  344. sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
  345. sax.domBuilder = options.domBuilder || domBuilder;
  346. if(isHTML){
  347. defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
  348. }
  349. defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
  350. if(source && typeof source === 'string'){
  351. sax.parse(source,defaultNSMap,entityMap);
  352. }else{
  353. sax.errorHandler.error("invalid doc source");
  354. }
  355. return domBuilder.doc;
  356. }
  357. function buildErrorHandler(errorImpl,domBuilder,locator){
  358. if(!errorImpl){
  359. if(domBuilder instanceof DOMHandler){
  360. return domBuilder;
  361. }
  362. errorImpl = domBuilder ;
  363. }
  364. var errorHandler = {}
  365. var isCallback = errorImpl instanceof Function;
  366. locator = locator||{}
  367. function build(key){
  368. var fn = errorImpl[key];
  369. if(!fn && isCallback){
  370. fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
  371. }
  372. errorHandler[key] = fn && function(msg){
  373. fn('[xmldom '+key+']\t'+msg+_locator(locator));
  374. }||function(){};
  375. }
  376. build('warning');
  377. build('error');
  378. build('fatalError');
  379. return errorHandler;
  380. }
  381. //console.log('#\n\n\n\n\n\n\n####')
  382. /**
  383. * +ContentHandler+ErrorHandler
  384. * +LexicalHandler+EntityResolver2
  385. * -DeclHandler-DTDHandler
  386. *
  387. * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
  388. * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
  389. * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
  390. */
  391. function DOMHandler() {
  392. this.cdata = false;
  393. }
  394. function position(locator,node){
  395. node.lineNumber = locator.lineNumber;
  396. node.columnNumber = locator.columnNumber;
  397. }
  398. /**
  399. * @see org.xml.sax.ContentHandler#startDocument
  400. * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
  401. */
  402. DOMHandler.prototype = {
  403. startDocument : function() {
  404. this.doc = new DOMImplementation().createDocument(null, null, null);
  405. if (this.locator) {
  406. this.doc.documentURI = this.locator.systemId;
  407. }
  408. },
  409. startElement:function(namespaceURI, localName, qName, attrs) {
  410. var doc = this.doc;
  411. var el = doc.createElementNS(namespaceURI, qName||localName);
  412. var len = attrs.length;
  413. appendElement(this, el);
  414. this.currentElement = el;
  415. this.locator && position(this.locator,el)
  416. for (var i = 0 ; i < len; i++) {
  417. var namespaceURI = attrs.getURI(i);
  418. var value = attrs.getValue(i);
  419. var qName = attrs.getQName(i);
  420. var attr = doc.createAttributeNS(namespaceURI, qName);
  421. this.locator &&position(attrs.getLocator(i),attr);
  422. attr.value = attr.nodeValue = value;
  423. el.setAttributeNode(attr)
  424. }
  425. },
  426. endElement:function(namespaceURI, localName, qName) {
  427. var current = this.currentElement
  428. var tagName = current.tagName;
  429. this.currentElement = current.parentNode;
  430. },
  431. startPrefixMapping:function(prefix, uri) {
  432. },
  433. endPrefixMapping:function(prefix) {
  434. },
  435. processingInstruction:function(target, data) {
  436. var ins = this.doc.createProcessingInstruction(target, data);
  437. this.locator && position(this.locator,ins)
  438. appendElement(this, ins);
  439. },
  440. ignorableWhitespace:function(ch, start, length) {
  441. },
  442. characters:function(chars, start, length) {
  443. chars = _toString.apply(this,arguments)
  444. //console.log(chars)
  445. if(chars){
  446. if (this.cdata) {
  447. var charNode = this.doc.createCDATASection(chars);
  448. } else {
  449. var charNode = this.doc.createTextNode(chars);
  450. }
  451. if(this.currentElement){
  452. this.currentElement.appendChild(charNode);
  453. }else if(/^\s*$/.test(chars)){
  454. this.doc.appendChild(charNode);
  455. //process xml
  456. }
  457. this.locator && position(this.locator,charNode)
  458. }
  459. },
  460. skippedEntity:function(name) {
  461. },
  462. endDocument:function() {
  463. this.doc.normalize();
  464. },
  465. setDocumentLocator:function (locator) {
  466. if(this.locator = locator){// && !('lineNumber' in locator)){
  467. locator.lineNumber = 0;
  468. }
  469. },
  470. //LexicalHandler
  471. comment:function(chars, start, length) {
  472. chars = _toString.apply(this,arguments)
  473. var comm = this.doc.createComment(chars);
  474. this.locator && position(this.locator,comm)
  475. appendElement(this, comm);
  476. },
  477. startCDATA:function() {
  478. //used in characters() methods
  479. this.cdata = true;
  480. },
  481. endCDATA:function() {
  482. this.cdata = false;
  483. },
  484. startDTD:function(name, publicId, systemId) {
  485. var impl = this.doc.implementation;
  486. if (impl && impl.createDocumentType) {
  487. var dt = impl.createDocumentType(name, publicId, systemId);
  488. this.locator && position(this.locator,dt)
  489. appendElement(this, dt);
  490. }
  491. },
  492. /**
  493. * @see org.xml.sax.ErrorHandler
  494. * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
  495. */
  496. warning:function(error) {
  497. console.warn('[xmldom warning]\t'+error,_locator(this.locator));
  498. },
  499. error:function(error) {
  500. console.error('[xmldom error]\t'+error,_locator(this.locator));
  501. },
  502. fatalError:function(error) {
  503. throw new ParseError(error, this.locator);
  504. }
  505. }
  506. function _locator(l){
  507. if(l){
  508. return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
  509. }
  510. }
  511. function _toString(chars,start,length){
  512. if(typeof chars == 'string'){
  513. return chars.substr(start,length)
  514. }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
  515. if(chars.length >= start+length || start){
  516. return new java.lang.String(chars,start,length)+'';
  517. }
  518. return chars;
  519. }
  520. }
  521. /*
  522. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
  523. * used method of org.xml.sax.ext.LexicalHandler:
  524. * #comment(chars, start, length)
  525. * #startCDATA()
  526. * #endCDATA()
  527. * #startDTD(name, publicId, systemId)
  528. *
  529. *
  530. * IGNORED method of org.xml.sax.ext.LexicalHandler:
  531. * #endDTD()
  532. * #startEntity(name)
  533. * #endEntity(name)
  534. *
  535. *
  536. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
  537. * IGNORED method of org.xml.sax.ext.DeclHandler
  538. * #attributeDecl(eName, aName, type, mode, value)
  539. * #elementDecl(name, model)
  540. * #externalEntityDecl(name, publicId, systemId)
  541. * #internalEntityDecl(name, value)
  542. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
  543. * IGNORED method of org.xml.sax.EntityResolver2
  544. * #resolveEntity(String name,String publicId,String baseURI,String systemId)
  545. * #resolveEntity(publicId, systemId)
  546. * #getExternalSubset(name, baseURI)
  547. * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
  548. * IGNORED method of org.xml.sax.DTDHandler
  549. * #notationDecl(name, publicId, systemId) {};
  550. * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
  551. */
  552. "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
  553. DOMHandler.prototype[key] = function(){return null}
  554. })
  555. /* 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 */
  556. function appendElement (hander,node) {
  557. if (!hander.currentElement) {
  558. hander.doc.appendChild(node);
  559. } else {
  560. hander.currentElement.appendChild(node);
  561. }
  562. }//appendChild and setAttributeNS are preformance key
  563. //if(typeof require == 'function'){
  564. var htmlEntity = require('./entities');
  565. var sax = require('./sax');
  566. var XMLReader = sax.XMLReader;
  567. var ParseError = sax.ParseError;
  568. var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
  569. exports.XMLSerializer = require('./dom').XMLSerializer ;
  570. exports.DOMParser = DOMParser;
  571. exports.__DOMHandler = DOMHandler;
  572. //}
  573. },{"./dom":5,"./entities":6,"./sax":7}],5:[function(require,module,exports){
  574. function copy(src,dest){
  575. for(var p in src){
  576. dest[p] = src[p];
  577. }
  578. }
  579. /**
  580. ^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
  581. ^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
  582. */
  583. function _extends(Class,Super){
  584. var pt = Class.prototype;
  585. if(!(pt instanceof Super)){
  586. function t(){};
  587. t.prototype = Super.prototype;
  588. t = new t();
  589. copy(pt,t);
  590. Class.prototype = pt = t;
  591. }
  592. if(pt.constructor != Class){
  593. if(typeof Class != 'function'){
  594. console.error("unknow Class:"+Class)
  595. }
  596. pt.constructor = Class
  597. }
  598. }
  599. var htmlns = 'http://www.w3.org/1999/xhtml' ;
  600. // Node Types
  601. var NodeType = {}
  602. var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
  603. var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
  604. var TEXT_NODE = NodeType.TEXT_NODE = 3;
  605. var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
  606. var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
  607. var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
  608. var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
  609. var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
  610. var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
  611. var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
  612. var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
  613. var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
  614. // ExceptionCode
  615. var ExceptionCode = {}
  616. var ExceptionMessage = {};
  617. var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
  618. var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
  619. var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
  620. var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
  621. var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
  622. var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
  623. var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
  624. var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
  625. var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
  626. var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
  627. //level2
  628. var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
  629. var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
  630. var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
  631. var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
  632. var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
  633. /**
  634. * DOM Level 2
  635. * Object DOMException
  636. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
  637. * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
  638. */
  639. function DOMException(code, message) {
  640. if(message instanceof Error){
  641. var error = message;
  642. }else{
  643. error = this;
  644. Error.call(this, ExceptionMessage[code]);
  645. this.message = ExceptionMessage[code];
  646. if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
  647. }
  648. error.code = code;
  649. if(message) this.message = this.message + ": " + message;
  650. return error;
  651. };
  652. DOMException.prototype = Error.prototype;
  653. copy(ExceptionCode,DOMException)
  654. /**
  655. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
  656. * 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.
  657. * The items in the NodeList are accessible via an integral index, starting from 0.
  658. */
  659. function NodeList() {
  660. };
  661. NodeList.prototype = {
  662. /**
  663. * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
  664. * @standard level1
  665. */
  666. length:0,
  667. /**
  668. * 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.
  669. * @standard level1
  670. * @param index unsigned long
  671. * Index into the collection.
  672. * @return Node
  673. * The node at the indexth position in the NodeList, or null if that is not a valid index.
  674. */
  675. item: function(index) {
  676. return this[index] || null;
  677. },
  678. toString:function(isHTML,nodeFilter){
  679. for(var buf = [], i = 0;i<this.length;i++){
  680. serializeToString(this[i],buf,isHTML,nodeFilter);
  681. }
  682. return buf.join('');
  683. }
  684. };
  685. function LiveNodeList(node,refresh){
  686. this._node = node;
  687. this._refresh = refresh
  688. _updateLiveList(this);
  689. }
  690. function _updateLiveList(list){
  691. var inc = list._node._inc || list._node.ownerDocument._inc;
  692. if(list._inc != inc){
  693. var ls = list._refresh(list._node);
  694. //console.log(ls.length)
  695. __set__(list,'length',ls.length);
  696. copy(ls,list);
  697. list._inc = inc;
  698. }
  699. }
  700. LiveNodeList.prototype.item = function(i){
  701. _updateLiveList(this);
  702. return this[i];
  703. }
  704. _extends(LiveNodeList,NodeList);
  705. /**
  706. *
  707. * 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.
  708. * NamedNodeMap objects in the DOM are live.
  709. * used for attributes or DocumentType entities
  710. */
  711. function NamedNodeMap() {
  712. };
  713. function _findNodeIndex(list,node){
  714. var i = list.length;
  715. while(i--){
  716. if(list[i] === node){return i}
  717. }
  718. }
  719. function _addNamedNode(el,list,newAttr,oldAttr){
  720. if(oldAttr){
  721. list[_findNodeIndex(list,oldAttr)] = newAttr;
  722. }else{
  723. list[list.length++] = newAttr;
  724. }
  725. if(el){
  726. newAttr.ownerElement = el;
  727. var doc = el.ownerDocument;
  728. if(doc){
  729. oldAttr && _onRemoveAttribute(doc,el,oldAttr);
  730. _onAddAttribute(doc,el,newAttr);
  731. }
  732. }
  733. }
  734. function _removeNamedNode(el,list,attr){
  735. //console.log('remove attr:'+attr)
  736. var i = _findNodeIndex(list,attr);
  737. if(i>=0){
  738. var lastIndex = list.length-1
  739. while(i<lastIndex){
  740. list[i] = list[++i]
  741. }
  742. list.length = lastIndex;
  743. if(el){
  744. var doc = el.ownerDocument;
  745. if(doc){
  746. _onRemoveAttribute(doc,el,attr);
  747. attr.ownerElement = null;
  748. }
  749. }
  750. }else{
  751. throw DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
  752. }
  753. }
  754. NamedNodeMap.prototype = {
  755. length:0,
  756. item:NodeList.prototype.item,
  757. getNamedItem: function(key) {
  758. // if(key.indexOf(':')>0 || key == 'xmlns'){
  759. // return null;
  760. // }
  761. //console.log()
  762. var i = this.length;
  763. while(i--){
  764. var attr = this[i];
  765. //console.log(attr.nodeName,key)
  766. if(attr.nodeName == key){
  767. return attr;
  768. }
  769. }
  770. },
  771. setNamedItem: function(attr) {
  772. var el = attr.ownerElement;
  773. if(el && el!=this._ownerElement){
  774. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  775. }
  776. var oldAttr = this.getNamedItem(attr.nodeName);
  777. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  778. return oldAttr;
  779. },
  780. /* returns Node */
  781. setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
  782. var el = attr.ownerElement, oldAttr;
  783. if(el && el!=this._ownerElement){
  784. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  785. }
  786. oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
  787. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  788. return oldAttr;
  789. },
  790. /* returns Node */
  791. removeNamedItem: function(key) {
  792. var attr = this.getNamedItem(key);
  793. _removeNamedNode(this._ownerElement,this,attr);
  794. return attr;
  795. },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
  796. //for level2
  797. removeNamedItemNS:function(namespaceURI,localName){
  798. var attr = this.getNamedItemNS(namespaceURI,localName);
  799. _removeNamedNode(this._ownerElement,this,attr);
  800. return attr;
  801. },
  802. getNamedItemNS: function(namespaceURI, localName) {
  803. var i = this.length;
  804. while(i--){
  805. var node = this[i];
  806. if(node.localName == localName && node.namespaceURI == namespaceURI){
  807. return node;
  808. }
  809. }
  810. return null;
  811. }
  812. };
  813. /**
  814. * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
  815. */
  816. function DOMImplementation(/* Object */ features) {
  817. this._features = {};
  818. if (features) {
  819. for (var feature in features) {
  820. this._features = features[feature];
  821. }
  822. }
  823. };
  824. DOMImplementation.prototype = {
  825. hasFeature: function(/* string */ feature, /* string */ version) {
  826. var versions = this._features[feature.toLowerCase()];
  827. if (versions && (!version || version in versions)) {
  828. return true;
  829. } else {
  830. return false;
  831. }
  832. },
  833. // Introduced in DOM Level 2:
  834. createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
  835. var doc = new Document();
  836. doc.implementation = this;
  837. doc.childNodes = new NodeList();
  838. doc.doctype = doctype;
  839. if(doctype){
  840. doc.appendChild(doctype);
  841. }
  842. if(qualifiedName){
  843. var root = doc.createElementNS(namespaceURI,qualifiedName);
  844. doc.appendChild(root);
  845. }
  846. return doc;
  847. },
  848. // Introduced in DOM Level 2:
  849. createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
  850. var node = new DocumentType();
  851. node.name = qualifiedName;
  852. node.nodeName = qualifiedName;
  853. node.publicId = publicId;
  854. node.systemId = systemId;
  855. // Introduced in DOM Level 2:
  856. //readonly attribute DOMString internalSubset;
  857. //TODO:..
  858. // readonly attribute NamedNodeMap entities;
  859. // readonly attribute NamedNodeMap notations;
  860. return node;
  861. }
  862. };
  863. /**
  864. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247
  865. */
  866. function Node() {
  867. };
  868. Node.prototype = {
  869. firstChild : null,
  870. lastChild : null,
  871. previousSibling : null,
  872. nextSibling : null,
  873. attributes : null,
  874. parentNode : null,
  875. childNodes : null,
  876. ownerDocument : null,
  877. nodeValue : null,
  878. namespaceURI : null,
  879. prefix : null,
  880. localName : null,
  881. // Modified in DOM Level 2:
  882. insertBefore:function(newChild, refChild){//raises
  883. return _insertBefore(this,newChild,refChild);
  884. },
  885. replaceChild:function(newChild, oldChild){//raises
  886. this.insertBefore(newChild,oldChild);
  887. if(oldChild){
  888. this.removeChild(oldChild);
  889. }
  890. },
  891. removeChild:function(oldChild){
  892. return _removeChild(this,oldChild);
  893. },
  894. appendChild:function(newChild){
  895. return this.insertBefore(newChild,null);
  896. },
  897. hasChildNodes:function(){
  898. return this.firstChild != null;
  899. },
  900. cloneNode:function(deep){
  901. return cloneNode(this.ownerDocument||this,this,deep);
  902. },
  903. // Modified in DOM Level 2:
  904. normalize:function(){
  905. var child = this.firstChild;
  906. while(child){
  907. var next = child.nextSibling;
  908. if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
  909. this.removeChild(next);
  910. child.appendData(next.data);
  911. }else{
  912. child.normalize();
  913. child = next;
  914. }
  915. }
  916. },
  917. // Introduced in DOM Level 2:
  918. isSupported:function(feature, version){
  919. return this.ownerDocument.implementation.hasFeature(feature,version);
  920. },
  921. // Introduced in DOM Level 2:
  922. hasAttributes:function(){
  923. return this.attributes.length>0;
  924. },
  925. lookupPrefix:function(namespaceURI){
  926. var el = this;
  927. while(el){
  928. var map = el._nsMap;
  929. //console.dir(map)
  930. if(map){
  931. for(var n in map){
  932. if(map[n] == namespaceURI){
  933. return n;
  934. }
  935. }
  936. }
  937. el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
  938. }
  939. return null;
  940. },
  941. // Introduced in DOM Level 3:
  942. lookupNamespaceURI:function(prefix){
  943. var el = this;
  944. while(el){
  945. var map = el._nsMap;
  946. //console.dir(map)
  947. if(map){
  948. if(prefix in map){
  949. return map[prefix] ;
  950. }
  951. }
  952. el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
  953. }
  954. return null;
  955. },
  956. // Introduced in DOM Level 3:
  957. isDefaultNamespace:function(namespaceURI){
  958. var prefix = this.lookupPrefix(namespaceURI);
  959. return prefix == null;
  960. }
  961. };
  962. function _xmlEncoder(c){
  963. return c == '<' && '&lt;' ||
  964. c == '>' && '&gt;' ||
  965. c == '&' && '&amp;' ||
  966. c == '"' && '&quot;' ||
  967. '&#'+c.charCodeAt()+';'
  968. }
  969. copy(NodeType,Node);
  970. copy(NodeType,Node.prototype);
  971. /**
  972. * @param callback return true for continue,false for break
  973. * @return boolean true: break visit;
  974. */
  975. function _visitNode(node,callback){
  976. if(callback(node)){
  977. return true;
  978. }
  979. if(node = node.firstChild){
  980. do{
  981. if(_visitNode(node,callback)){return true}
  982. }while(node=node.nextSibling)
  983. }
  984. }
  985. function Document(){
  986. }
  987. function _onAddAttribute(doc,el,newAttr){
  988. doc && doc._inc++;
  989. var ns = newAttr.namespaceURI ;
  990. if(ns == 'http://www.w3.org/2000/xmlns/'){
  991. //update namespace
  992. el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
  993. }
  994. }
  995. function _onRemoveAttribute(doc,el,newAttr,remove){
  996. doc && doc._inc++;
  997. var ns = newAttr.namespaceURI ;
  998. if(ns == 'http://www.w3.org/2000/xmlns/'){
  999. //update namespace
  1000. delete el._nsMap[newAttr.prefix?newAttr.localName:'']
  1001. }
  1002. }
  1003. function _onUpdateChild(doc,el,newChild){
  1004. if(doc && doc._inc){
  1005. doc._inc++;
  1006. //update childNodes
  1007. var cs = el.childNodes;
  1008. if(newChild){
  1009. cs[cs.length++] = newChild;
  1010. }else{
  1011. //console.log(1)
  1012. var child = el.firstChild;
  1013. var i = 0;
  1014. while(child){
  1015. cs[i++] = child;
  1016. child =child.nextSibling;
  1017. }
  1018. cs.length = i;
  1019. }
  1020. }
  1021. }
  1022. /**
  1023. * attributes;
  1024. * children;
  1025. *
  1026. * writeable properties:
  1027. * nodeValue,Attr:value,CharacterData:data
  1028. * prefix
  1029. */
  1030. function _removeChild(parentNode,child){
  1031. var previous = child.previousSibling;
  1032. var next = child.nextSibling;
  1033. if(previous){
  1034. previous.nextSibling = next;
  1035. }else{
  1036. parentNode.firstChild = next
  1037. }
  1038. if(next){
  1039. next.previousSibling = previous;
  1040. }else{
  1041. parentNode.lastChild = previous;
  1042. }
  1043. _onUpdateChild(parentNode.ownerDocument,parentNode);
  1044. return child;
  1045. }
  1046. /**
  1047. * preformance key(refChild == null)
  1048. */
  1049. function _insertBefore(parentNode,newChild,nextChild){
  1050. var cp = newChild.parentNode;
  1051. if(cp){
  1052. cp.removeChild(newChild);//remove and update
  1053. }
  1054. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  1055. var newFirst = newChild.firstChild;
  1056. if (newFirst == null) {
  1057. return newChild;
  1058. }
  1059. var newLast = newChild.lastChild;
  1060. }else{
  1061. newFirst = newLast = newChild;
  1062. }
  1063. var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
  1064. newFirst.previousSibling = pre;
  1065. newLast.nextSibling = nextChild;
  1066. if(pre){
  1067. pre.nextSibling = newFirst;
  1068. }else{
  1069. parentNode.firstChild = newFirst;
  1070. }
  1071. if(nextChild == null){
  1072. parentNode.lastChild = newLast;
  1073. }else{
  1074. nextChild.previousSibling = newLast;
  1075. }
  1076. do{
  1077. newFirst.parentNode = parentNode;
  1078. }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
  1079. _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
  1080. //console.log(parentNode.lastChild.nextSibling == null)
  1081. if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
  1082. newChild.firstChild = newChild.lastChild = null;
  1083. }
  1084. return newChild;
  1085. }
  1086. function _appendSingleChild(parentNode,newChild){
  1087. var cp = newChild.parentNode;
  1088. if(cp){
  1089. var pre = parentNode.lastChild;
  1090. cp.removeChild(newChild);//remove and update
  1091. var pre = parentNode.lastChild;
  1092. }
  1093. var pre = parentNode.lastChild;
  1094. newChild.parentNode = parentNode;
  1095. newChild.previousSibling = pre;
  1096. newChild.nextSibling = null;
  1097. if(pre){
  1098. pre.nextSibling = newChild;
  1099. }else{
  1100. parentNode.firstChild = newChild;
  1101. }
  1102. parentNode.lastChild = newChild;
  1103. _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
  1104. return newChild;
  1105. //console.log("__aa",parentNode.lastChild.nextSibling == null)
  1106. }
  1107. Document.prototype = {
  1108. //implementation : null,
  1109. nodeName : '#document',
  1110. nodeType : DOCUMENT_NODE,
  1111. doctype : null,
  1112. documentElement : null,
  1113. _inc : 1,
  1114. insertBefore : function(newChild, refChild){//raises
  1115. if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
  1116. var child = newChild.firstChild;
  1117. while(child){
  1118. var next = child.nextSibling;
  1119. this.insertBefore(child,refChild);
  1120. child = next;
  1121. }
  1122. return newChild;
  1123. }
  1124. if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
  1125. this.documentElement = newChild;
  1126. }
  1127. return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
  1128. },
  1129. removeChild : function(oldChild){
  1130. if(this.documentElement == oldChild){
  1131. this.documentElement = null;
  1132. }
  1133. return _removeChild(this,oldChild);
  1134. },
  1135. // Introduced in DOM Level 2:
  1136. importNode : function(importedNode,deep){
  1137. return importNode(this,importedNode,deep);
  1138. },
  1139. // Introduced in DOM Level 2:
  1140. getElementById : function(id){
  1141. var rtv = null;
  1142. _visitNode(this.documentElement,function(node){
  1143. if(node.nodeType == ELEMENT_NODE){
  1144. if(node.getAttribute('id') == id){
  1145. rtv = node;
  1146. return true;
  1147. }
  1148. }
  1149. })
  1150. return rtv;
  1151. },
  1152. getElementsByClassName: function(className) {
  1153. var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
  1154. return new LiveNodeList(this, function(base) {
  1155. var ls = [];
  1156. _visitNode(base.documentElement, function(node) {
  1157. if(node !== base && node.nodeType == ELEMENT_NODE) {
  1158. if(pattern.test(node.getAttribute('class'))) {
  1159. ls.push(node);
  1160. }
  1161. }
  1162. });
  1163. return ls;
  1164. });
  1165. },
  1166. //document factory method:
  1167. createElement : function(tagName){
  1168. var node = new Element();
  1169. node.ownerDocument = this;
  1170. node.nodeName = tagName;
  1171. node.tagName = tagName;
  1172. node.childNodes = new NodeList();
  1173. var attrs = node.attributes = new NamedNodeMap();
  1174. attrs._ownerElement = node;
  1175. return node;
  1176. },
  1177. createDocumentFragment : function(){
  1178. var node = new DocumentFragment();
  1179. node.ownerDocument = this;
  1180. node.childNodes = new NodeList();
  1181. return node;
  1182. },
  1183. createTextNode : function(data){
  1184. var node = new Text();
  1185. node.ownerDocument = this;
  1186. node.appendData(data)
  1187. return node;
  1188. },
  1189. createComment : function(data){
  1190. var node = new Comment();
  1191. node.ownerDocument = this;
  1192. node.appendData(data)
  1193. return node;
  1194. },
  1195. createCDATASection : function(data){
  1196. var node = new CDATASection();
  1197. node.ownerDocument = this;
  1198. node.appendData(data)
  1199. return node;
  1200. },
  1201. createProcessingInstruction : function(target,data){
  1202. var node = new ProcessingInstruction();
  1203. node.ownerDocument = this;
  1204. node.tagName = node.target = target;
  1205. node.nodeValue= node.data = data;
  1206. return node;
  1207. },
  1208. createAttribute : function(name){
  1209. var node = new Attr();
  1210. node.ownerDocument = this;
  1211. node.name = name;
  1212. node.nodeName = name;
  1213. node.localName = name;
  1214. node.specified = true;
  1215. return node;
  1216. },
  1217. createEntityReference : function(name){
  1218. var node = new EntityReference();
  1219. node.ownerDocument = this;
  1220. node.nodeName = name;
  1221. return node;
  1222. },
  1223. // Introduced in DOM Level 2:
  1224. createElementNS : function(namespaceURI,qualifiedName){
  1225. var node = new Element();
  1226. var pl = qualifiedName.split(':');
  1227. var attrs = node.attributes = new NamedNodeMap();
  1228. node.childNodes = new NodeList();
  1229. node.ownerDocument = this;
  1230. node.nodeName = qualifiedName;
  1231. node.tagName = qualifiedName;
  1232. node.namespaceURI = namespaceURI;
  1233. if(pl.length == 2){
  1234. node.prefix = pl[0];
  1235. node.localName = pl[1];
  1236. }else{
  1237. //el.prefix = null;
  1238. node.localName = qualifiedName;
  1239. }
  1240. attrs._ownerElement = node;
  1241. return node;
  1242. },
  1243. // Introduced in DOM Level 2:
  1244. createAttributeNS : function(namespaceURI,qualifiedName){
  1245. var node = new Attr();
  1246. var pl = qualifiedName.split(':');
  1247. node.ownerDocument = this;
  1248. node.nodeName = qualifiedName;
  1249. node.name = qualifiedName;
  1250. node.namespaceURI = namespaceURI;
  1251. node.specified = true;
  1252. if(pl.length == 2){
  1253. node.prefix = pl[0];
  1254. node.localName = pl[1];
  1255. }else{
  1256. //el.prefix = null;
  1257. node.localName = qualifiedName;
  1258. }
  1259. return node;
  1260. }
  1261. };
  1262. _extends(Document,Node);
  1263. function Element() {
  1264. this._nsMap = {};
  1265. };
  1266. Element.prototype = {
  1267. nodeType : ELEMENT_NODE,
  1268. hasAttribute : function(name){
  1269. return this.getAttributeNode(name)!=null;
  1270. },
  1271. getAttribute : function(name){
  1272. var attr = this.getAttributeNode(name);
  1273. return attr && attr.value || '';
  1274. },
  1275. getAttributeNode : function(name){
  1276. return this.attributes.getNamedItem(name);
  1277. },
  1278. setAttribute : function(name, value){
  1279. var attr = this.ownerDocument.createAttribute(name);
  1280. attr.value = attr.nodeValue = "" + value;
  1281. this.setAttributeNode(attr)
  1282. },
  1283. removeAttribute : function(name){
  1284. var attr = this.getAttributeNode(name)
  1285. attr && this.removeAttributeNode(attr);
  1286. },
  1287. //four real opeartion method
  1288. appendChild:function(newChild){
  1289. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  1290. return this.insertBefore(newChild,null);
  1291. }else{
  1292. return _appendSingleChild(this,newChild);
  1293. }
  1294. },
  1295. setAttributeNode : function(newAttr){
  1296. return this.attributes.setNamedItem(newAttr);
  1297. },
  1298. setAttributeNodeNS : function(newAttr){
  1299. return this.attributes.setNamedItemNS(newAttr);
  1300. },
  1301. removeAttributeNode : function(oldAttr){
  1302. //console.log(this == oldAttr.ownerElement)
  1303. return this.attributes.removeNamedItem(oldAttr.nodeName);
  1304. },
  1305. //get real attribute name,and remove it by removeAttributeNode
  1306. removeAttributeNS : function(namespaceURI, localName){
  1307. var old = this.getAttributeNodeNS(namespaceURI, localName);
  1308. old && this.removeAttributeNode(old);
  1309. },
  1310. hasAttributeNS : function(namespaceURI, localName){
  1311. return this.getAttributeNodeNS(namespaceURI, localName)!=null;
  1312. },
  1313. getAttributeNS : function(namespaceURI, localName){
  1314. var attr = this.getAttributeNodeNS(namespaceURI, localName);
  1315. return attr && attr.value || '';
  1316. },
  1317. setAttributeNS : function(namespaceURI, qualifiedName, value){
  1318. var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
  1319. attr.value = attr.nodeValue = "" + value;
  1320. this.setAttributeNode(attr)
  1321. },
  1322. getAttributeNodeNS : function(namespaceURI, localName){
  1323. return this.attributes.getNamedItemNS(namespaceURI, localName);
  1324. },
  1325. getElementsByTagName : function(tagName){
  1326. return new LiveNodeList(this,function(base){
  1327. var ls = [];
  1328. _visitNode(base,function(node){
  1329. if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
  1330. ls.push(node);
  1331. }
  1332. });
  1333. return ls;
  1334. });
  1335. },
  1336. getElementsByTagNameNS : function(namespaceURI, localName){
  1337. return new LiveNodeList(this,function(base){
  1338. var ls = [];
  1339. _visitNode(base,function(node){
  1340. if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
  1341. ls.push(node);
  1342. }
  1343. });
  1344. return ls;
  1345. });
  1346. }
  1347. };
  1348. Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
  1349. Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
  1350. _extends(Element,Node);
  1351. function Attr() {
  1352. };
  1353. Attr.prototype.nodeType = ATTRIBUTE_NODE;
  1354. _extends(Attr,Node);
  1355. function CharacterData() {
  1356. };
  1357. CharacterData.prototype = {
  1358. data : '',
  1359. substringData : function(offset, count) {
  1360. return this.data.substring(offset, offset+count);
  1361. },
  1362. appendData: function(text) {
  1363. text = this.data+text;
  1364. this.nodeValue = this.data = text;
  1365. this.length = text.length;
  1366. },
  1367. insertData: function(offset,text) {
  1368. this.replaceData(offset,0,text);
  1369. },
  1370. appendChild:function(newChild){
  1371. throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
  1372. },
  1373. deleteData: function(offset, count) {
  1374. this.replaceData(offset,count,"");
  1375. },
  1376. replaceData: function(offset, count, text) {
  1377. var start = this.data.substring(0,offset);
  1378. var end = this.data.substring(offset+count);
  1379. text = start + text + end;
  1380. this.nodeValue = this.data = text;
  1381. this.length = text.length;
  1382. }
  1383. }
  1384. _extends(CharacterData,Node);
  1385. function Text() {
  1386. };
  1387. Text.prototype = {
  1388. nodeName : "#text",
  1389. nodeType : TEXT_NODE,
  1390. splitText : function(offset) {
  1391. var text = this.data;
  1392. var newText = text.substring(offset);
  1393. text = text.substring(0, offset);
  1394. this.data = this.nodeValue = text;
  1395. this.length = text.length;
  1396. var newNode = this.ownerDocument.createTextNode(newText);
  1397. if(this.parentNode){
  1398. this.parentNode.insertBefore(newNode, this.nextSibling);
  1399. }
  1400. return newNode;
  1401. }
  1402. }
  1403. _extends(Text,CharacterData);
  1404. function Comment() {
  1405. };
  1406. Comment.prototype = {
  1407. nodeName : "#comment",
  1408. nodeType : COMMENT_NODE
  1409. }
  1410. _extends(Comment,CharacterData);
  1411. function CDATASection() {
  1412. };
  1413. CDATASection.prototype = {
  1414. nodeName : "#cdata-section",
  1415. nodeType : CDATA_SECTION_NODE
  1416. }
  1417. _extends(CDATASection,CharacterData);
  1418. function DocumentType() {
  1419. };
  1420. DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
  1421. _extends(DocumentType,Node);
  1422. function Notation() {
  1423. };
  1424. Notation.prototype.nodeType = NOTATION_NODE;
  1425. _extends(Notation,Node);
  1426. function Entity() {
  1427. };
  1428. Entity.prototype.nodeType = ENTITY_NODE;
  1429. _extends(Entity,Node);
  1430. function EntityReference() {
  1431. };
  1432. EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
  1433. _extends(EntityReference,Node);
  1434. function DocumentFragment() {
  1435. };
  1436. DocumentFragment.prototype.nodeName = "#document-fragment";
  1437. DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
  1438. _extends(DocumentFragment,Node);
  1439. function ProcessingInstruction() {
  1440. }
  1441. ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
  1442. _extends(ProcessingInstruction,Node);
  1443. function XMLSerializer(){}
  1444. XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
  1445. return nodeSerializeToString.call(node,isHtml,nodeFilter);
  1446. }
  1447. Node.prototype.toString = nodeSerializeToString;
  1448. function nodeSerializeToString(isHtml,nodeFilter){
  1449. var buf = [];
  1450. var refNode = this.nodeType == 9 && this.documentElement || this;
  1451. var prefix = refNode.prefix;
  1452. var uri = refNode.namespaceURI;
  1453. if(uri && prefix == null){
  1454. //console.log(prefix)
  1455. var prefix = refNode.lookupPrefix(uri);
  1456. if(prefix == null){
  1457. //isHTML = true;
  1458. var visibleNamespaces=[
  1459. {namespace:uri,prefix:null}
  1460. //{namespace:uri,prefix:''}
  1461. ]
  1462. }
  1463. }
  1464. serializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);
  1465. //console.log('###',this.nodeType,uri,prefix,buf.join(''))
  1466. return buf.join('');
  1467. }
  1468. function needNamespaceDefine(node,isHTML, visibleNamespaces) {
  1469. var prefix = node.prefix||'';
  1470. var uri = node.namespaceURI;
  1471. if (!prefix && !uri){
  1472. return false;
  1473. }
  1474. if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
  1475. || uri == 'http://www.w3.org/2000/xmlns/'){
  1476. return false;
  1477. }
  1478. var i = visibleNamespaces.length
  1479. //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
  1480. while (i--) {
  1481. var ns = visibleNamespaces[i];
  1482. // get namespace prefix
  1483. //console.log(node.nodeType,node.tagName,ns.prefix,prefix)
  1484. if (ns.prefix == prefix){
  1485. return ns.namespace != uri;
  1486. }
  1487. }
  1488. //console.log(isHTML,uri,prefix=='')
  1489. //if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
  1490. // return false;
  1491. //}
  1492. //node.flag = '11111'
  1493. //console.error(3,true,node.flag,node.prefix,node.namespaceURI)
  1494. return true;
  1495. }
  1496. function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
  1497. if(nodeFilter){
  1498. node = nodeFilter(node);
  1499. if(node){
  1500. if(typeof node == 'string'){
  1501. buf.push(node);
  1502. return;
  1503. }
  1504. }else{
  1505. return;
  1506. }
  1507. //buf.sort.apply(attrs, attributeSorter);
  1508. }
  1509. switch(node.nodeType){
  1510. case ELEMENT_NODE:
  1511. if (!visibleNamespaces) visibleNamespaces = [];
  1512. var startVisibleNamespaces = visibleNamespaces.length;
  1513. var attrs = node.attributes;
  1514. var len = attrs.length;
  1515. var child = node.firstChild;
  1516. var nodeName = node.tagName;
  1517. isHTML = (htmlns === node.namespaceURI) ||isHTML
  1518. buf.push('<',nodeName);
  1519. for(var i=0;i<len;i++){
  1520. // add namespaces for attributes
  1521. var attr = attrs.item(i);
  1522. if (attr.prefix == 'xmlns') {
  1523. visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });
  1524. }else if(attr.nodeName == 'xmlns'){
  1525. visibleNamespaces.push({ prefix: '', namespace: attr.value });
  1526. }
  1527. }
  1528. for(var i=0;i<len;i++){
  1529. var attr = attrs.item(i);
  1530. if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
  1531. var prefix = attr.prefix||'';
  1532. var uri = attr.namespaceURI;
  1533. var ns = prefix ? ' xmlns:' + prefix : " xmlns";
  1534. buf.push(ns, '="' , uri , '"');
  1535. visibleNamespaces.push({ prefix: prefix, namespace:uri });
  1536. }
  1537. serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
  1538. }
  1539. // add namespace for current node
  1540. if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
  1541. var prefix = node.prefix||'';
  1542. var uri = node.namespaceURI;
  1543. if (uri) {
  1544. // Avoid empty namespace value like xmlns:ds=""
  1545. // Empty namespace URL will we produce an invalid XML document
  1546. var ns = prefix ? ' xmlns:' + prefix : " xmlns";
  1547. buf.push(ns, '="' , uri , '"');
  1548. visibleNamespaces.push({ prefix: prefix, namespace:uri });
  1549. }
  1550. }
  1551. if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
  1552. buf.push('>');
  1553. //if is cdata child node
  1554. if(isHTML && /^script$/i.test(nodeName)){
  1555. while(child){
  1556. if(child.data){
  1557. buf.push(child.data);
  1558. }else{
  1559. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  1560. }
  1561. child = child.nextSibling;
  1562. }
  1563. }else
  1564. {
  1565. while(child){
  1566. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  1567. child = child.nextSibling;
  1568. }
  1569. }
  1570. buf.push('</',nodeName,'>');
  1571. }else{
  1572. buf.push('/>');
  1573. }
  1574. // remove added visible namespaces
  1575. //visibleNamespaces.length = startVisibleNamespaces;
  1576. return;
  1577. case DOCUMENT_NODE:
  1578. case DOCUMENT_FRAGMENT_NODE:
  1579. var child = node.firstChild;
  1580. while(child){
  1581. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  1582. child = child.nextSibling;
  1583. }
  1584. return;
  1585. case ATTRIBUTE_NODE:
  1586. /**
  1587. * Well-formedness constraint: No < in Attribute Values
  1588. * The replacement text of any entity referred to directly or indirectly in an attribute value must not contain a <.
  1589. * @see https://www.w3.org/TR/xml/#CleanAttrVals
  1590. * @see https://www.w3.org/TR/xml/#NT-AttValue
  1591. */
  1592. return buf.push(' ', node.name, '="', node.value.replace(/[<&"]/g,_xmlEncoder), '"');
  1593. case TEXT_NODE:
  1594. /**
  1595. * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
  1596. * except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section.
  1597. * If they are needed elsewhere, they must be escaped using either numeric character references or the strings
  1598. * `&amp;` and `&lt;` respectively.
  1599. * The right angle bracket (>) may be represented using the string " &gt; ", and must, for compatibility,
  1600. * be escaped using either `&gt;` or a character reference when it appears in the string `]]>` in content,
  1601. * when that string is not marking the end of a CDATA section.
  1602. *
  1603. * In the content of elements, character data is any string of characters
  1604. * which does not contain the start-delimiter of any markup
  1605. * and does not include the CDATA-section-close delimiter, `]]>`.
  1606. *
  1607. * @see https://www.w3.org/TR/xml/#NT-CharData
  1608. */
  1609. return buf.push(node.data
  1610. .replace(/[<&]/g,_xmlEncoder)
  1611. .replace(/]]>/g, ']]&gt;')
  1612. );
  1613. case CDATA_SECTION_NODE:
  1614. return buf.push( '<![CDATA[',node.data,']]>');
  1615. case COMMENT_NODE:
  1616. return buf.push( "<!--",node.data,"-->");
  1617. case DOCUMENT_TYPE_NODE:
  1618. var pubid = node.publicId;
  1619. var sysid = node.systemId;
  1620. buf.push('<!DOCTYPE ',node.name);
  1621. if(pubid){
  1622. buf.push(' PUBLIC ', pubid);
  1623. if (sysid && sysid!='.') {
  1624. buf.push(' ', sysid);
  1625. }
  1626. buf.push('>');
  1627. }else if(sysid && sysid!='.'){
  1628. buf.push(' SYSTEM ', sysid, '>');
  1629. }else{
  1630. var sub = node.internalSubset;
  1631. if(sub){
  1632. buf.push(" [",sub,"]");
  1633. }
  1634. buf.push(">");
  1635. }
  1636. return;
  1637. case PROCESSING_INSTRUCTION_NODE:
  1638. return buf.push( "<?",node.target," ",node.data,"?>");
  1639. case ENTITY_REFERENCE_NODE:
  1640. return buf.push( '&',node.nodeName,';');
  1641. //case ENTITY_NODE:
  1642. //case NOTATION_NODE:
  1643. default:
  1644. buf.push('??',node.nodeName);
  1645. }
  1646. }
  1647. function importNode(doc,node,deep){
  1648. var node2;
  1649. switch (node.nodeType) {
  1650. case ELEMENT_NODE:
  1651. node2 = node.cloneNode(false);
  1652. node2.ownerDocument = doc;
  1653. //var attrs = node2.attributes;
  1654. //var len = attrs.length;
  1655. //for(var i=0;i<len;i++){
  1656. //node2.setAttributeNodeNS(importNode(doc,attrs.item(i),deep));
  1657. //}
  1658. case DOCUMENT_FRAGMENT_NODE:
  1659. break;
  1660. case ATTRIBUTE_NODE:
  1661. deep = true;
  1662. break;
  1663. //case ENTITY_REFERENCE_NODE:
  1664. //case PROCESSING_INSTRUCTION_NODE:
  1665. ////case TEXT_NODE:
  1666. //case CDATA_SECTION_NODE:
  1667. //case COMMENT_NODE:
  1668. // deep = false;
  1669. // break;
  1670. //case DOCUMENT_NODE:
  1671. //case DOCUMENT_TYPE_NODE:
  1672. //cannot be imported.
  1673. //case ENTITY_NODE:
  1674. //case NOTATION_NODE:
  1675. //can not hit in level3
  1676. //default:throw e;
  1677. }
  1678. if(!node2){
  1679. node2 = node.cloneNode(false);//false
  1680. }
  1681. node2.ownerDocument = doc;
  1682. node2.parentNode = null;
  1683. if(deep){
  1684. var child = node.firstChild;
  1685. while(child){
  1686. node2.appendChild(importNode(doc,child,deep));
  1687. child = child.nextSibling;
  1688. }
  1689. }
  1690. return node2;
  1691. }
  1692. //
  1693. //var _relationMap = {firstChild:1,lastChild:1,previousSibling:1,nextSibling:1,
  1694. // attributes:1,childNodes:1,parentNode:1,documentElement:1,doctype,};
  1695. function cloneNode(doc,node,deep){
  1696. var node2 = new node.constructor();
  1697. for(var n in node){
  1698. var v = node[n];
  1699. if(typeof v != 'object' ){
  1700. if(v != node2[n]){
  1701. node2[n] = v;
  1702. }
  1703. }
  1704. }
  1705. if(node.childNodes){
  1706. node2.childNodes = new NodeList();
  1707. }
  1708. node2.ownerDocument = doc;
  1709. switch (node2.nodeType) {
  1710. case ELEMENT_NODE:
  1711. var attrs = node.attributes;
  1712. var attrs2 = node2.attributes = new NamedNodeMap();
  1713. var len = attrs.length
  1714. attrs2._ownerElement = node2;
  1715. for(var i=0;i<len;i++){
  1716. node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
  1717. }
  1718. break;;
  1719. case ATTRIBUTE_NODE:
  1720. deep = true;
  1721. }
  1722. if(deep){
  1723. var child = node.firstChild;
  1724. while(child){
  1725. node2.appendChild(cloneNode(doc,child,deep));
  1726. child = child.nextSibling;
  1727. }
  1728. }
  1729. return node2;
  1730. }
  1731. function __set__(object,key,value){
  1732. object[key] = value
  1733. }
  1734. //do dynamic
  1735. try{
  1736. if(Object.defineProperty){
  1737. Object.defineProperty(LiveNodeList.prototype,'length',{
  1738. get:function(){
  1739. _updateLiveList(this);
  1740. return this.$$length;
  1741. }
  1742. });
  1743. Object.defineProperty(Node.prototype,'textContent',{
  1744. get:function(){
  1745. return getTextContent(this);
  1746. },
  1747. set:function(data){
  1748. switch(this.nodeType){
  1749. case ELEMENT_NODE:
  1750. case DOCUMENT_FRAGMENT_NODE:
  1751. while(this.firstChild){
  1752. this.removeChild(this.firstChild);
  1753. }
  1754. if(data || String(data)){
  1755. this.appendChild(this.ownerDocument.createTextNode(data));
  1756. }
  1757. break;
  1758. default:
  1759. //TODO:
  1760. this.data = data;
  1761. this.value = data;
  1762. this.nodeValue = data;
  1763. }
  1764. }
  1765. })
  1766. function getTextContent(node){
  1767. switch(node.nodeType){
  1768. case ELEMENT_NODE:
  1769. case DOCUMENT_FRAGMENT_NODE:
  1770. var buf = [];
  1771. node = node.firstChild;
  1772. while(node){
  1773. if(node.nodeType!==7 && node.nodeType !==8){
  1774. buf.push(getTextContent(node));
  1775. }
  1776. node = node.nextSibling;
  1777. }
  1778. return buf.join('');
  1779. default:
  1780. return node.nodeValue;
  1781. }
  1782. }
  1783. __set__ = function(object,key,value){
  1784. //console.log(value)
  1785. object['$$'+key] = value
  1786. }
  1787. }
  1788. }catch(e){//ie8
  1789. }
  1790. //if(typeof require == 'function'){
  1791. exports.Node = Node;
  1792. exports.DOMException = DOMException;
  1793. exports.DOMImplementation = DOMImplementation;
  1794. exports.XMLSerializer = XMLSerializer;
  1795. //}
  1796. },{}],6:[function(require,module,exports){
  1797. exports.entityMap = {
  1798. lt: '<',
  1799. gt: '>',
  1800. amp: '&',
  1801. quot: '"',
  1802. apos: "'",
  1803. Agrave: "À",
  1804. Aacute: "Á",
  1805. Acirc: "Â",
  1806. Atilde: "Ã",
  1807. Auml: "Ä",
  1808. Aring: "Å",
  1809. AElig: "Æ",
  1810. Ccedil: "Ç",
  1811. Egrave: "È",
  1812. Eacute: "É",
  1813. Ecirc: "Ê",
  1814. Euml: "Ë",
  1815. Igrave: "Ì",
  1816. Iacute: "Í",
  1817. Icirc: "Î",
  1818. Iuml: "Ï",
  1819. ETH: "Ð",
  1820. Ntilde: "Ñ",
  1821. Ograve: "Ò",
  1822. Oacute: "Ó",
  1823. Ocirc: "Ô",
  1824. Otilde: "Õ",
  1825. Ouml: "Ö",
  1826. Oslash: "Ø",
  1827. Ugrave: "Ù",
  1828. Uacute: "Ú",
  1829. Ucirc: "Û",
  1830. Uuml: "Ü",
  1831. Yacute: "Ý",
  1832. THORN: "Þ",
  1833. szlig: "ß",
  1834. agrave: "à",
  1835. aacute: "á",
  1836. acirc: "â",
  1837. atilde: "ã",
  1838. auml: "ä",
  1839. aring: "å",
  1840. aelig: "æ",
  1841. ccedil: "ç",
  1842. egrave: "è",
  1843. eacute: "é",
  1844. ecirc: "ê",
  1845. euml: "ë",
  1846. igrave: "ì",
  1847. iacute: "í",
  1848. icirc: "î",
  1849. iuml: "ï",
  1850. eth: "ð",
  1851. ntilde: "ñ",
  1852. ograve: "ò",
  1853. oacute: "ó",
  1854. ocirc: "ô",
  1855. otilde: "õ",
  1856. ouml: "ö",
  1857. oslash: "ø",
  1858. ugrave: "ù",
  1859. uacute: "ú",
  1860. ucirc: "û",
  1861. uuml: "ü",
  1862. yacute: "ý",
  1863. thorn: "þ",
  1864. yuml: "ÿ",
  1865. nbsp: "\u00a0",
  1866. iexcl: "¡",
  1867. cent: "¢",
  1868. pound: "£",
  1869. curren: "¤",
  1870. yen: "¥",
  1871. brvbar: "¦",
  1872. sect: "§",
  1873. uml: "¨",
  1874. copy: "©",
  1875. ordf: "ª",
  1876. laquo: "«",
  1877. not: "¬",
  1878. shy: "­­",
  1879. reg: "®",
  1880. macr: "¯",
  1881. deg: "°",
  1882. plusmn: "±",
  1883. sup2: "²",
  1884. sup3: "³",
  1885. acute: "´",
  1886. micro: "µ",
  1887. para: "¶",
  1888. middot: "·",
  1889. cedil: "¸",
  1890. sup1: "¹",
  1891. ordm: "º",
  1892. raquo: "»",
  1893. frac14: "¼",
  1894. frac12: "½",
  1895. frac34: "¾",
  1896. iquest: "¿",
  1897. times: "×",
  1898. divide: "÷",
  1899. forall: "∀",
  1900. part: "∂",
  1901. exist: "∃",
  1902. empty: "∅",
  1903. nabla: "∇",
  1904. isin: "∈",
  1905. notin: "∉",
  1906. ni: "∋",
  1907. prod: "∏",
  1908. sum: "∑",
  1909. minus: "−",
  1910. lowast: "∗",
  1911. radic: "√",
  1912. prop: "∝",
  1913. infin: "∞",
  1914. ang: "∠",
  1915. and: "∧",
  1916. or: "∨",
  1917. cap: "∩",
  1918. cup: "∪",
  1919. 'int': "∫",
  1920. there4: "∴",
  1921. sim: "∼",
  1922. cong: "≅",
  1923. asymp: "≈",
  1924. ne: "≠",
  1925. equiv: "≡",
  1926. le: "≤",
  1927. ge: "≥",
  1928. sub: "⊂",
  1929. sup: "⊃",
  1930. nsub: "⊄",
  1931. sube: "⊆",
  1932. supe: "⊇",
  1933. oplus: "⊕",
  1934. otimes: "⊗",
  1935. perp: "⊥",
  1936. sdot: "⋅",
  1937. Alpha: "Α",
  1938. Beta: "Β",
  1939. Gamma: "Γ",
  1940. Delta: "Δ",
  1941. Epsilon: "Ε",
  1942. Zeta: "Ζ",
  1943. Eta: "Η",
  1944. Theta: "Θ",
  1945. Iota: "Ι",
  1946. Kappa: "Κ",
  1947. Lambda: "Λ",
  1948. Mu: "Μ",
  1949. Nu: "Ν",
  1950. Xi: "Ξ",
  1951. Omicron: "Ο",
  1952. Pi: "Π",
  1953. Rho: "Ρ",
  1954. Sigma: "Σ",
  1955. Tau: "Τ",
  1956. Upsilon: "Υ",
  1957. Phi: "Φ",
  1958. Chi: "Χ",
  1959. Psi: "Ψ",
  1960. Omega: "Ω",
  1961. alpha: "α",
  1962. beta: "β",
  1963. gamma: "γ",
  1964. delta: "δ",
  1965. epsilon: "ε",
  1966. zeta: "ζ",
  1967. eta: "η",
  1968. theta: "θ",
  1969. iota: "ι",
  1970. kappa: "κ",
  1971. lambda: "λ",
  1972. mu: "μ",
  1973. nu: "ν",
  1974. xi: "ξ",
  1975. omicron: "ο",
  1976. pi: "π",
  1977. rho: "ρ",
  1978. sigmaf: "ς",
  1979. sigma: "σ",
  1980. tau: "τ",
  1981. upsilon: "υ",
  1982. phi: "φ",
  1983. chi: "χ",
  1984. psi: "ψ",
  1985. omega: "ω",
  1986. thetasym: "ϑ",
  1987. upsih: "ϒ",
  1988. piv: "ϖ",
  1989. OElig: "Œ",
  1990. oelig: "œ",
  1991. Scaron: "Š",
  1992. scaron: "š",
  1993. Yuml: "Ÿ",
  1994. fnof: "ƒ",
  1995. circ: "ˆ",
  1996. tilde: "˜",
  1997. ensp: " ",
  1998. emsp: " ",
  1999. thinsp: " ",
  2000. zwnj: "‌",
  2001. zwj: "‍",
  2002. lrm: "‎",
  2003. rlm: "‏",
  2004. ndash: "–",
  2005. mdash: "—",
  2006. lsquo: "‘",
  2007. rsquo: "’",
  2008. sbquo: "‚",
  2009. ldquo: "“",
  2010. rdquo: "”",
  2011. bdquo: "„",
  2012. dagger: "†",
  2013. Dagger: "‡",
  2014. bull: "•",
  2015. hellip: "…",
  2016. permil: "‰",
  2017. prime: "′",
  2018. Prime: "″",
  2019. lsaquo: "‹",
  2020. rsaquo: "›",
  2021. oline: "‾",
  2022. euro: "€",
  2023. trade: "™",
  2024. larr: "←",
  2025. uarr: "↑",
  2026. rarr: "→",
  2027. darr: "↓",
  2028. harr: "↔",
  2029. crarr: "↵",
  2030. lceil: "⌈",
  2031. rceil: "⌉",
  2032. lfloor: "⌊",
  2033. rfloor: "⌋",
  2034. loz: "◊",
  2035. spades: "♠",
  2036. clubs: "♣",
  2037. hearts: "♥",
  2038. diams: "♦"
  2039. };
  2040. },{}],7:[function(require,module,exports){
  2041. //[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]
  2042. //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
  2043. //[5] Name ::= NameStartChar (NameChar)*
  2044. 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
  2045. var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
  2046. var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
  2047. //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
  2048. //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(',')
  2049. //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
  2050. //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
  2051. var S_TAG = 0;//tag name offerring
  2052. var S_ATTR = 1;//attr name offerring
  2053. var S_ATTR_SPACE=2;//attr name end and space offer
  2054. var S_EQ = 3;//=space?
  2055. var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
  2056. var S_ATTR_END = 5;//attr value end and no space(quot end)
  2057. var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
  2058. var S_TAG_CLOSE = 7;//closed el<el />
  2059. /**
  2060. * Creates an error that will not be caught by XMLReader aka the SAX parser.
  2061. *
  2062. * @param {string} message
  2063. * @param {any?} locator Optional, can provide details about the location in the source
  2064. * @constructor
  2065. */
  2066. function ParseError(message, locator) {
  2067. this.message = message
  2068. this.locator = locator
  2069. if(Error.captureStackTrace) Error.captureStackTrace(this, ParseError);
  2070. }
  2071. ParseError.prototype = new Error();
  2072. ParseError.prototype.name = ParseError.name
  2073. function XMLReader(){
  2074. }
  2075. XMLReader.prototype = {
  2076. parse:function(source,defaultNSMap,entityMap){
  2077. var domBuilder = this.domBuilder;
  2078. domBuilder.startDocument();
  2079. _copy(defaultNSMap ,defaultNSMap = {})
  2080. parse(source,defaultNSMap,entityMap,
  2081. domBuilder,this.errorHandler);
  2082. domBuilder.endDocument();
  2083. }
  2084. }
  2085. function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
  2086. function fixedFromCharCode(code) {
  2087. // String.prototype.fromCharCode does not supports
  2088. // > 2 bytes unicode chars directly
  2089. if (code > 0xffff) {
  2090. code -= 0x10000;
  2091. var surrogate1 = 0xd800 + (code >> 10)
  2092. , surrogate2 = 0xdc00 + (code & 0x3ff);
  2093. return String.fromCharCode(surrogate1, surrogate2);
  2094. } else {
  2095. return String.fromCharCode(code);
  2096. }
  2097. }
  2098. function entityReplacer(a){
  2099. var k = a.slice(1,-1);
  2100. if(k in entityMap){
  2101. return entityMap[k];
  2102. }else if(k.charAt(0) === '#'){
  2103. return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
  2104. }else{
  2105. errorHandler.error('entity not found:'+a);
  2106. return a;
  2107. }
  2108. }
  2109. function appendText(end){//has some bugs
  2110. if(end>start){
  2111. var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
  2112. locator&&position(start);
  2113. domBuilder.characters(xt,0,end-start);
  2114. start = end
  2115. }
  2116. }
  2117. function position(p,m){
  2118. while(p>=lineEnd && (m = linePattern.exec(source))){
  2119. lineStart = m.index;
  2120. lineEnd = lineStart + m[0].length;
  2121. locator.lineNumber++;
  2122. //console.log('line++:',locator,startPos,endPos)
  2123. }
  2124. locator.columnNumber = p-lineStart+1;
  2125. }
  2126. var lineStart = 0;
  2127. var lineEnd = 0;
  2128. var linePattern = /.*(?:\r\n?|\n)|.*$/g
  2129. var locator = domBuilder.locator;
  2130. var parseStack = [{currentNSMap:defaultNSMapCopy}]
  2131. var closeMap = {};
  2132. var start = 0;
  2133. while(true){
  2134. try{
  2135. var tagStart = source.indexOf('<',start);
  2136. if(tagStart<0){
  2137. if(!source.substr(start).match(/^\s*$/)){
  2138. var doc = domBuilder.doc;
  2139. var text = doc.createTextNode(source.substr(start));
  2140. doc.appendChild(text);
  2141. domBuilder.currentElement = text;
  2142. }
  2143. return;
  2144. }
  2145. if(tagStart>start){
  2146. appendText(tagStart);
  2147. }
  2148. switch(source.charAt(tagStart+1)){
  2149. case '/':
  2150. var end = source.indexOf('>',tagStart+3);
  2151. var tagName = source.substring(tagStart+2,end);
  2152. var config = parseStack.pop();
  2153. if(end<0){
  2154. tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
  2155. errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
  2156. end = tagStart+1+tagName.length;
  2157. }else if(tagName.match(/\s</)){
  2158. tagName = tagName.replace(/[\s<].*/,'');
  2159. errorHandler.error("end tag name: "+tagName+' maybe not complete');
  2160. end = tagStart+1+tagName.length;
  2161. }
  2162. var localNSMap = config.localNSMap;
  2163. var endMatch = config.tagName == tagName;
  2164. var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
  2165. if(endIgnoreCaseMach){
  2166. domBuilder.endElement(config.uri,config.localName,tagName);
  2167. if(localNSMap){
  2168. for(var prefix in localNSMap){
  2169. domBuilder.endPrefixMapping(prefix) ;
  2170. }
  2171. }
  2172. if(!endMatch){
  2173. errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName ); // No known test case
  2174. }
  2175. }else{
  2176. parseStack.push(config)
  2177. }
  2178. end++;
  2179. break;
  2180. // end elment
  2181. case '?':// <?...?>
  2182. locator&&position(tagStart);
  2183. end = parseInstruction(source,tagStart,domBuilder);
  2184. break;
  2185. case '!':// <!doctype,<![CDATA,<!--
  2186. locator&&position(tagStart);
  2187. end = parseDCC(source,tagStart,domBuilder,errorHandler);
  2188. break;
  2189. default:
  2190. locator&&position(tagStart);
  2191. var el = new ElementAttributes();
  2192. var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  2193. //elStartEnd
  2194. var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
  2195. var len = el.length;
  2196. if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
  2197. el.closed = true;
  2198. if(!entityMap.nbsp){
  2199. errorHandler.warning('unclosed xml attribute');
  2200. }
  2201. }
  2202. if(locator && len){
  2203. var locator2 = copyLocator(locator,{});
  2204. //try{//attribute position fixed
  2205. for(var i = 0;i<len;i++){
  2206. var a = el[i];
  2207. position(a.offset);
  2208. a.locator = copyLocator(locator,{});
  2209. }
  2210. domBuilder.locator = locator2
  2211. if(appendElement(el,domBuilder,currentNSMap)){
  2212. parseStack.push(el)
  2213. }
  2214. domBuilder.locator = locator;
  2215. }else{
  2216. if(appendElement(el,domBuilder,currentNSMap)){
  2217. parseStack.push(el)
  2218. }
  2219. }
  2220. if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
  2221. end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
  2222. }else{
  2223. end++;
  2224. }
  2225. }
  2226. }catch(e){
  2227. if (e instanceof ParseError) {
  2228. throw e;
  2229. }
  2230. errorHandler.error('element parse error: '+e)
  2231. end = -1;
  2232. }
  2233. if(end>start){
  2234. start = end;
  2235. }else{
  2236. //TODO: 这里有可能sax回退,有位置错误风险
  2237. appendText(Math.max(tagStart,start)+1);
  2238. }
  2239. }
  2240. }
  2241. function copyLocator(f,t){
  2242. t.lineNumber = f.lineNumber;
  2243. t.columnNumber = f.columnNumber;
  2244. return t;
  2245. }
  2246. /**
  2247. * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
  2248. * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
  2249. */
  2250. function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
  2251. /**
  2252. * @param {string} qname
  2253. * @param {string} value
  2254. * @param {number} startIndex
  2255. */
  2256. function addAttribute(qname, value, startIndex) {
  2257. if (qname in el.attributeNames) errorHandler.fatalError('Attribute ' + qname + ' redefined')
  2258. el.addValue(qname, value, startIndex)
  2259. }
  2260. var attrName;
  2261. var value;
  2262. var p = ++start;
  2263. var s = S_TAG;//status
  2264. while(true){
  2265. var c = source.charAt(p);
  2266. switch(c){
  2267. case '=':
  2268. if(s === S_ATTR){//attrName
  2269. attrName = source.slice(start,p);
  2270. s = S_EQ;
  2271. }else if(s === S_ATTR_SPACE){
  2272. s = S_EQ;
  2273. }else{
  2274. //fatalError: equal must after attrName or space after attrName
  2275. throw new Error('attribute equal must after attrName'); // No known test case
  2276. }
  2277. break;
  2278. case '\'':
  2279. case '"':
  2280. if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
  2281. ){//equal
  2282. if(s === S_ATTR){
  2283. errorHandler.warning('attribute value must after "="')
  2284. attrName = source.slice(start,p)
  2285. }
  2286. start = p+1;
  2287. p = source.indexOf(c,start)
  2288. if(p>0){
  2289. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  2290. addAttribute(attrName, value, start-1);
  2291. s = S_ATTR_END;
  2292. }else{
  2293. //fatalError: no end quot match
  2294. throw new Error('attribute value no end \''+c+'\' match');
  2295. }
  2296. }else if(s == S_ATTR_NOQUOT_VALUE){
  2297. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  2298. //console.log(attrName,value,start,p)
  2299. addAttribute(attrName, value, start);
  2300. //console.dir(el)
  2301. errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
  2302. start = p+1;
  2303. s = S_ATTR_END
  2304. }else{
  2305. //fatalError: no equal before
  2306. throw new Error('attribute value must after "="'); // No known test case
  2307. }
  2308. break;
  2309. case '/':
  2310. switch(s){
  2311. case S_TAG:
  2312. el.setTagName(source.slice(start,p));
  2313. case S_ATTR_END:
  2314. case S_TAG_SPACE:
  2315. case S_TAG_CLOSE:
  2316. s =S_TAG_CLOSE;
  2317. el.closed = true;
  2318. case S_ATTR_NOQUOT_VALUE:
  2319. case S_ATTR:
  2320. case S_ATTR_SPACE:
  2321. break;
  2322. //case S_EQ:
  2323. default:
  2324. throw new Error("attribute invalid close char('/')") // No known test case
  2325. }
  2326. break;
  2327. case ''://end document
  2328. errorHandler.error('unexpected end of input');
  2329. if(s == S_TAG){
  2330. el.setTagName(source.slice(start,p));
  2331. }
  2332. return p;
  2333. case '>':
  2334. switch(s){
  2335. case S_TAG:
  2336. el.setTagName(source.slice(start,p));
  2337. case S_ATTR_END:
  2338. case S_TAG_SPACE:
  2339. case S_TAG_CLOSE:
  2340. break;//normal
  2341. case S_ATTR_NOQUOT_VALUE://Compatible state
  2342. case S_ATTR:
  2343. value = source.slice(start,p);
  2344. if(value.slice(-1) === '/'){
  2345. el.closed = true;
  2346. value = value.slice(0,-1)
  2347. }
  2348. case S_ATTR_SPACE:
  2349. if(s === S_ATTR_SPACE){
  2350. value = attrName;
  2351. }
  2352. if(s == S_ATTR_NOQUOT_VALUE){
  2353. errorHandler.warning('attribute "'+value+'" missed quot(")!');
  2354. addAttribute(attrName, value.replace(/&#?\w+;/g,entityReplacer), start)
  2355. }else{
  2356. if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
  2357. errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
  2358. }
  2359. addAttribute(value, value, start)
  2360. }
  2361. break;
  2362. case S_EQ:
  2363. throw new Error('attribute value missed!!');
  2364. }
  2365. // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
  2366. return p;
  2367. /*xml space '\x20' | #x9 | #xD | #xA; */
  2368. case '\u0080':
  2369. c = ' ';
  2370. default:
  2371. if(c<= ' '){//space
  2372. switch(s){
  2373. case S_TAG:
  2374. el.setTagName(source.slice(start,p));//tagName
  2375. s = S_TAG_SPACE;
  2376. break;
  2377. case S_ATTR:
  2378. attrName = source.slice(start,p)
  2379. s = S_ATTR_SPACE;
  2380. break;
  2381. case S_ATTR_NOQUOT_VALUE:
  2382. var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  2383. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  2384. addAttribute(attrName, value, start)
  2385. case S_ATTR_END:
  2386. s = S_TAG_SPACE;
  2387. break;
  2388. //case S_TAG_SPACE:
  2389. //case S_EQ:
  2390. //case S_ATTR_SPACE:
  2391. // void();break;
  2392. //case S_TAG_CLOSE:
  2393. //ignore warning
  2394. }
  2395. }else{//not space
  2396. //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
  2397. //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
  2398. switch(s){
  2399. //case S_TAG:void();break;
  2400. //case S_ATTR:void();break;
  2401. //case S_ATTR_NOQUOT_VALUE:void();break;
  2402. case S_ATTR_SPACE:
  2403. var tagName = el.tagName;
  2404. if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
  2405. errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
  2406. }
  2407. addAttribute(attrName, attrName, start);
  2408. start = p;
  2409. s = S_ATTR;
  2410. break;
  2411. case S_ATTR_END:
  2412. errorHandler.warning('attribute space is required"'+attrName+'"!!')
  2413. case S_TAG_SPACE:
  2414. s = S_ATTR;
  2415. start = p;
  2416. break;
  2417. case S_EQ:
  2418. s = S_ATTR_NOQUOT_VALUE;
  2419. start = p;
  2420. break;
  2421. case S_TAG_CLOSE:
  2422. throw new Error("elements closed character '/' and '>' must be connected to");
  2423. }
  2424. }
  2425. }//end outer switch
  2426. //console.log('p++',p)
  2427. p++;
  2428. }
  2429. }
  2430. /**
  2431. * @return true if has new namespace define
  2432. */
  2433. function appendElement(el,domBuilder,currentNSMap){
  2434. var tagName = el.tagName;
  2435. var localNSMap = null;
  2436. //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  2437. var i = el.length;
  2438. while(i--){
  2439. var a = el[i];
  2440. var qName = a.qName;
  2441. var value = a.value;
  2442. var nsp = qName.indexOf(':');
  2443. if(nsp>0){
  2444. var prefix = a.prefix = qName.slice(0,nsp);
  2445. var localName = qName.slice(nsp+1);
  2446. var nsPrefix = prefix === 'xmlns' && localName
  2447. }else{
  2448. localName = qName;
  2449. prefix = null
  2450. nsPrefix = qName === 'xmlns' && ''
  2451. }
  2452. //can not set prefix,because prefix !== ''
  2453. a.localName = localName ;
  2454. //prefix == null for no ns prefix attribute
  2455. if(nsPrefix !== false){//hack!!
  2456. if(localNSMap == null){
  2457. localNSMap = {}
  2458. //console.log(currentNSMap,0)
  2459. _copy(currentNSMap,currentNSMap={})
  2460. //console.log(currentNSMap,1)
  2461. }
  2462. currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
  2463. a.uri = 'http://www.w3.org/2000/xmlns/'
  2464. domBuilder.startPrefixMapping(nsPrefix, value)
  2465. }
  2466. }
  2467. var i = el.length;
  2468. while(i--){
  2469. a = el[i];
  2470. var prefix = a.prefix;
  2471. if(prefix){//no prefix attribute has no namespace
  2472. if(prefix === 'xml'){
  2473. a.uri = 'http://www.w3.org/XML/1998/namespace';
  2474. }if(prefix !== 'xmlns'){
  2475. a.uri = currentNSMap[prefix || '']
  2476. //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
  2477. }
  2478. }
  2479. }
  2480. var nsp = tagName.indexOf(':');
  2481. if(nsp>0){
  2482. prefix = el.prefix = tagName.slice(0,nsp);
  2483. localName = el.localName = tagName.slice(nsp+1);
  2484. }else{
  2485. prefix = null;//important!!
  2486. localName = el.localName = tagName;
  2487. }
  2488. //no prefix element has default namespace
  2489. var ns = el.uri = currentNSMap[prefix || ''];
  2490. domBuilder.startElement(ns,localName,tagName,el);
  2491. //endPrefixMapping and startPrefixMapping have not any help for dom builder
  2492. //localNSMap = null
  2493. if(el.closed){
  2494. domBuilder.endElement(ns,localName,tagName);
  2495. if(localNSMap){
  2496. for(prefix in localNSMap){
  2497. domBuilder.endPrefixMapping(prefix)
  2498. }
  2499. }
  2500. }else{
  2501. el.currentNSMap = currentNSMap;
  2502. el.localNSMap = localNSMap;
  2503. //parseStack.push(el);
  2504. return true;
  2505. }
  2506. }
  2507. function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
  2508. if(/^(?:script|textarea)$/i.test(tagName)){
  2509. var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
  2510. var text = source.substring(elStartEnd+1,elEndStart);
  2511. if(/[&<]/.test(text)){
  2512. if(/^script$/i.test(tagName)){
  2513. //if(!/\]\]>/.test(text)){
  2514. //lexHandler.startCDATA();
  2515. domBuilder.characters(text,0,text.length);
  2516. //lexHandler.endCDATA();
  2517. return elEndStart;
  2518. //}
  2519. }//}else{//text area
  2520. text = text.replace(/&#?\w+;/g,entityReplacer);
  2521. domBuilder.characters(text,0,text.length);
  2522. return elEndStart;
  2523. //}
  2524. }
  2525. }
  2526. return elStartEnd+1;
  2527. }
  2528. function fixSelfClosed(source,elStartEnd,tagName,closeMap){
  2529. //if(tagName in closeMap){
  2530. var pos = closeMap[tagName];
  2531. if(pos == null){
  2532. //console.log(tagName)
  2533. pos = source.lastIndexOf('</'+tagName+'>')
  2534. if(pos<elStartEnd){//忘记闭合
  2535. pos = source.lastIndexOf('</'+tagName)
  2536. }
  2537. closeMap[tagName] =pos
  2538. }
  2539. return pos<elStartEnd;
  2540. //}
  2541. }
  2542. function _copy(source,target){
  2543. for(var n in source){target[n] = source[n]}
  2544. }
  2545. function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
  2546. var next= source.charAt(start+2)
  2547. switch(next){
  2548. case '-':
  2549. if(source.charAt(start + 3) === '-'){
  2550. var end = source.indexOf('-->',start+4);
  2551. //append comment source.substring(4,end)//<!--
  2552. if(end>start){
  2553. domBuilder.comment(source,start+4,end-start-4);
  2554. return end+3;
  2555. }else{
  2556. errorHandler.error("Unclosed comment");
  2557. return -1;
  2558. }
  2559. }else{
  2560. //error
  2561. return -1;
  2562. }
  2563. default:
  2564. if(source.substr(start+3,6) == 'CDATA['){
  2565. var end = source.indexOf(']]>',start+9);
  2566. domBuilder.startCDATA();
  2567. domBuilder.characters(source,start+9,end-start-9);
  2568. domBuilder.endCDATA()
  2569. return end+3;
  2570. }
  2571. //<!DOCTYPE
  2572. //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
  2573. var matchs = split(source,start);
  2574. var len = matchs.length;
  2575. if(len>1 && /!doctype/i.test(matchs[0][0])){
  2576. var name = matchs[1][0];
  2577. var pubid = false;
  2578. var sysid = false;
  2579. if(len>3){
  2580. if(/^public$/i.test(matchs[2][0])){
  2581. pubid = matchs[3][0];
  2582. sysid = len>4 && matchs[4][0];
  2583. }else if(/^system$/i.test(matchs[2][0])){
  2584. sysid = matchs[3][0];
  2585. }
  2586. }
  2587. var lastMatch = matchs[len-1]
  2588. domBuilder.startDTD(name, pubid, sysid);
  2589. domBuilder.endDTD();
  2590. return lastMatch.index+lastMatch[0].length
  2591. }
  2592. }
  2593. return -1;
  2594. }
  2595. function parseInstruction(source,start,domBuilder){
  2596. var end = source.indexOf('?>',start);
  2597. if(end){
  2598. var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
  2599. if(match){
  2600. var len = match[0].length;
  2601. domBuilder.processingInstruction(match[1], match[2]) ;
  2602. return end+2;
  2603. }else{//error
  2604. return -1;
  2605. }
  2606. }
  2607. return -1;
  2608. }
  2609. function ElementAttributes(){
  2610. this.attributeNames = {}
  2611. }
  2612. ElementAttributes.prototype = {
  2613. setTagName:function(tagName){
  2614. if(!tagNamePattern.test(tagName)){
  2615. throw new Error('invalid tagName:'+tagName)
  2616. }
  2617. this.tagName = tagName
  2618. },
  2619. addValue:function(qName, value, offset) {
  2620. if(!tagNamePattern.test(qName)){
  2621. throw new Error('invalid attribute:'+qName)
  2622. }
  2623. this.attributeNames[qName] = this.length;
  2624. this[this.length++] = {qName:qName,value:value,offset:offset}
  2625. },
  2626. length:0,
  2627. getLocalName:function(i){return this[i].localName},
  2628. getLocator:function(i){return this[i].locator},
  2629. getQName:function(i){return this[i].qName},
  2630. getURI:function(i){return this[i].uri},
  2631. getValue:function(i){return this[i].value}
  2632. // ,getIndex:function(uri, localName)){
  2633. // if(localName){
  2634. //
  2635. // }else{
  2636. // var qName = uri
  2637. // }
  2638. // },
  2639. // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
  2640. // getType:function(uri,localName){}
  2641. // getType:function(i){},
  2642. }
  2643. function split(source,start){
  2644. var match;
  2645. var buf = [];
  2646. var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
  2647. reg.lastIndex = start;
  2648. reg.exec(source);//skip <
  2649. while(match = reg.exec(source)){
  2650. buf.push(match);
  2651. if(match[1])return buf;
  2652. }
  2653. }
  2654. exports.XMLReader = XMLReader;
  2655. exports.ParseError = ParseError;
  2656. },{}],8:[function(require,module,exports){
  2657. 'use strict'
  2658. exports.byteLength = byteLength
  2659. exports.toByteArray = toByteArray
  2660. exports.fromByteArray = fromByteArray
  2661. var lookup = []
  2662. var revLookup = []
  2663. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  2664. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  2665. for (var i = 0, len = code.length; i < len; ++i) {
  2666. lookup[i] = code[i]
  2667. revLookup[code.charCodeAt(i)] = i
  2668. }
  2669. // Support decoding URL-safe base64 strings, as Node.js does.
  2670. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  2671. revLookup['-'.charCodeAt(0)] = 62
  2672. revLookup['_'.charCodeAt(0)] = 63
  2673. function getLens (b64) {
  2674. var len = b64.length
  2675. if (len % 4 > 0) {
  2676. throw new Error('Invalid string. Length must be a multiple of 4')
  2677. }
  2678. // Trim off extra bytes after placeholder bytes are found
  2679. // See: https://github.com/beatgammit/base64-js/issues/42
  2680. var validLen = b64.indexOf('=')
  2681. if (validLen === -1) validLen = len
  2682. var placeHoldersLen = validLen === len
  2683. ? 0
  2684. : 4 - (validLen % 4)
  2685. return [validLen, placeHoldersLen]
  2686. }
  2687. // base64 is 4/3 + up to two characters of the original data
  2688. function byteLength (b64) {
  2689. var lens = getLens(b64)
  2690. var validLen = lens[0]
  2691. var placeHoldersLen = lens[1]
  2692. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  2693. }
  2694. function _byteLength (b64, validLen, placeHoldersLen) {
  2695. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  2696. }
  2697. function toByteArray (b64) {
  2698. var tmp
  2699. var lens = getLens(b64)
  2700. var validLen = lens[0]
  2701. var placeHoldersLen = lens[1]
  2702. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  2703. var curByte = 0
  2704. // if there are placeholders, only get up to the last complete 4 chars
  2705. var len = placeHoldersLen > 0
  2706. ? validLen - 4
  2707. : validLen
  2708. var i
  2709. for (i = 0; i < len; i += 4) {
  2710. tmp =
  2711. (revLookup[b64.charCodeAt(i)] << 18) |
  2712. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  2713. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  2714. revLookup[b64.charCodeAt(i + 3)]
  2715. arr[curByte++] = (tmp >> 16) & 0xFF
  2716. arr[curByte++] = (tmp >> 8) & 0xFF
  2717. arr[curByte++] = tmp & 0xFF
  2718. }
  2719. if (placeHoldersLen === 2) {
  2720. tmp =
  2721. (revLookup[b64.charCodeAt(i)] << 2) |
  2722. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  2723. arr[curByte++] = tmp & 0xFF
  2724. }
  2725. if (placeHoldersLen === 1) {
  2726. tmp =
  2727. (revLookup[b64.charCodeAt(i)] << 10) |
  2728. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  2729. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  2730. arr[curByte++] = (tmp >> 8) & 0xFF
  2731. arr[curByte++] = tmp & 0xFF
  2732. }
  2733. return arr
  2734. }
  2735. function tripletToBase64 (num) {
  2736. return lookup[num >> 18 & 0x3F] +
  2737. lookup[num >> 12 & 0x3F] +
  2738. lookup[num >> 6 & 0x3F] +
  2739. lookup[num & 0x3F]
  2740. }
  2741. function encodeChunk (uint8, start, end) {
  2742. var tmp
  2743. var output = []
  2744. for (var i = start; i < end; i += 3) {
  2745. tmp =
  2746. ((uint8[i] << 16) & 0xFF0000) +
  2747. ((uint8[i + 1] << 8) & 0xFF00) +
  2748. (uint8[i + 2] & 0xFF)
  2749. output.push(tripletToBase64(tmp))
  2750. }
  2751. return output.join('')
  2752. }
  2753. function fromByteArray (uint8) {
  2754. var tmp
  2755. var len = uint8.length
  2756. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  2757. var parts = []
  2758. var maxChunkLength = 16383 // must be multiple of 3
  2759. // go through the array every three bytes, we'll deal with trailing stuff later
  2760. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  2761. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  2762. }
  2763. // pad the end with zeros, but make sure to not forget the extra bytes
  2764. if (extraBytes === 1) {
  2765. tmp = uint8[len - 1]
  2766. parts.push(
  2767. lookup[tmp >> 2] +
  2768. lookup[(tmp << 4) & 0x3F] +
  2769. '=='
  2770. )
  2771. } else if (extraBytes === 2) {
  2772. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  2773. parts.push(
  2774. lookup[tmp >> 10] +
  2775. lookup[(tmp >> 4) & 0x3F] +
  2776. lookup[(tmp << 2) & 0x3F] +
  2777. '='
  2778. )
  2779. }
  2780. return parts.join('')
  2781. }
  2782. },{}],9:[function(require,module,exports){
  2783. (function (Buffer){(function (){
  2784. /*!
  2785. * The buffer module from node.js, for the browser.
  2786. *
  2787. * @author Feross Aboukhadijeh <https://feross.org>
  2788. * @license MIT
  2789. */
  2790. /* eslint-disable no-proto */
  2791. 'use strict'
  2792. var base64 = require('base64-js')
  2793. var ieee754 = require('ieee754')
  2794. exports.Buffer = Buffer
  2795. exports.SlowBuffer = SlowBuffer
  2796. exports.INSPECT_MAX_BYTES = 50
  2797. var K_MAX_LENGTH = 0x7fffffff
  2798. exports.kMaxLength = K_MAX_LENGTH
  2799. /**
  2800. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  2801. * === true Use Uint8Array implementation (fastest)
  2802. * === false Print warning and recommend using `buffer` v4.x which has an Object
  2803. * implementation (most compatible, even IE6)
  2804. *
  2805. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  2806. * Opera 11.6+, iOS 4.2+.
  2807. *
  2808. * We report that the browser does not support typed arrays if the are not subclassable
  2809. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  2810. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  2811. * for __proto__ and has a buggy typed array implementation.
  2812. */
  2813. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  2814. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  2815. typeof console.error === 'function') {
  2816. console.error(
  2817. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  2818. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  2819. )
  2820. }
  2821. function typedArraySupport () {
  2822. // Can typed array instances can be augmented?
  2823. try {
  2824. var arr = new Uint8Array(1)
  2825. arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
  2826. return arr.foo() === 42
  2827. } catch (e) {
  2828. return false
  2829. }
  2830. }
  2831. Object.defineProperty(Buffer.prototype, 'parent', {
  2832. enumerable: true,
  2833. get: function () {
  2834. if (!Buffer.isBuffer(this)) return undefined
  2835. return this.buffer
  2836. }
  2837. })
  2838. Object.defineProperty(Buffer.prototype, 'offset', {
  2839. enumerable: true,
  2840. get: function () {
  2841. if (!Buffer.isBuffer(this)) return undefined
  2842. return this.byteOffset
  2843. }
  2844. })
  2845. function createBuffer (length) {
  2846. if (length > K_MAX_LENGTH) {
  2847. throw new RangeError('The value "' + length + '" is invalid for option "size"')
  2848. }
  2849. // Return an augmented `Uint8Array` instance
  2850. var buf = new Uint8Array(length)
  2851. buf.__proto__ = Buffer.prototype
  2852. return buf
  2853. }
  2854. /**
  2855. * The Buffer constructor returns instances of `Uint8Array` that have their
  2856. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  2857. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  2858. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  2859. * returns a single octet.
  2860. *
  2861. * The `Uint8Array` prototype remains unmodified.
  2862. */
  2863. function Buffer (arg, encodingOrOffset, length) {
  2864. // Common case.
  2865. if (typeof arg === 'number') {
  2866. if (typeof encodingOrOffset === 'string') {
  2867. throw new TypeError(
  2868. 'The "string" argument must be of type string. Received type number'
  2869. )
  2870. }
  2871. return allocUnsafe(arg)
  2872. }
  2873. return from(arg, encodingOrOffset, length)
  2874. }
  2875. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  2876. if (typeof Symbol !== 'undefined' && Symbol.species != null &&
  2877. Buffer[Symbol.species] === Buffer) {
  2878. Object.defineProperty(Buffer, Symbol.species, {
  2879. value: null,
  2880. configurable: true,
  2881. enumerable: false,
  2882. writable: false
  2883. })
  2884. }
  2885. Buffer.poolSize = 8192 // not used by this implementation
  2886. function from (value, encodingOrOffset, length) {
  2887. if (typeof value === 'string') {
  2888. return fromString(value, encodingOrOffset)
  2889. }
  2890. if (ArrayBuffer.isView(value)) {
  2891. return fromArrayLike(value)
  2892. }
  2893. if (value == null) {
  2894. throw TypeError(
  2895. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  2896. 'or Array-like Object. Received type ' + (typeof value)
  2897. )
  2898. }
  2899. if (isInstance(value, ArrayBuffer) ||
  2900. (value && isInstance(value.buffer, ArrayBuffer))) {
  2901. return fromArrayBuffer(value, encodingOrOffset, length)
  2902. }
  2903. if (typeof value === 'number') {
  2904. throw new TypeError(
  2905. 'The "value" argument must not be of type number. Received type number'
  2906. )
  2907. }
  2908. var valueOf = value.valueOf && value.valueOf()
  2909. if (valueOf != null && valueOf !== value) {
  2910. return Buffer.from(valueOf, encodingOrOffset, length)
  2911. }
  2912. var b = fromObject(value)
  2913. if (b) return b
  2914. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
  2915. typeof value[Symbol.toPrimitive] === 'function') {
  2916. return Buffer.from(
  2917. value[Symbol.toPrimitive]('string'), encodingOrOffset, length
  2918. )
  2919. }
  2920. throw new TypeError(
  2921. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  2922. 'or Array-like Object. Received type ' + (typeof value)
  2923. )
  2924. }
  2925. /**
  2926. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  2927. * if value is a number.
  2928. * Buffer.from(str[, encoding])
  2929. * Buffer.from(array)
  2930. * Buffer.from(buffer)
  2931. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  2932. **/
  2933. Buffer.from = function (value, encodingOrOffset, length) {
  2934. return from(value, encodingOrOffset, length)
  2935. }
  2936. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  2937. // https://github.com/feross/buffer/pull/148
  2938. Buffer.prototype.__proto__ = Uint8Array.prototype
  2939. Buffer.__proto__ = Uint8Array
  2940. function assertSize (size) {
  2941. if (typeof size !== 'number') {
  2942. throw new TypeError('"size" argument must be of type number')
  2943. } else if (size < 0) {
  2944. throw new RangeError('The value "' + size + '" is invalid for option "size"')
  2945. }
  2946. }
  2947. function alloc (size, fill, encoding) {
  2948. assertSize(size)
  2949. if (size <= 0) {
  2950. return createBuffer(size)
  2951. }
  2952. if (fill !== undefined) {
  2953. // Only pay attention to encoding if it's a string. This
  2954. // prevents accidentally sending in a number that would
  2955. // be interpretted as a start offset.
  2956. return typeof encoding === 'string'
  2957. ? createBuffer(size).fill(fill, encoding)
  2958. : createBuffer(size).fill(fill)
  2959. }
  2960. return createBuffer(size)
  2961. }
  2962. /**
  2963. * Creates a new filled Buffer instance.
  2964. * alloc(size[, fill[, encoding]])
  2965. **/
  2966. Buffer.alloc = function (size, fill, encoding) {
  2967. return alloc(size, fill, encoding)
  2968. }
  2969. function allocUnsafe (size) {
  2970. assertSize(size)
  2971. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  2972. }
  2973. /**
  2974. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  2975. * */
  2976. Buffer.allocUnsafe = function (size) {
  2977. return allocUnsafe(size)
  2978. }
  2979. /**
  2980. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  2981. */
  2982. Buffer.allocUnsafeSlow = function (size) {
  2983. return allocUnsafe(size)
  2984. }
  2985. function fromString (string, encoding) {
  2986. if (typeof encoding !== 'string' || encoding === '') {
  2987. encoding = 'utf8'
  2988. }
  2989. if (!Buffer.isEncoding(encoding)) {
  2990. throw new TypeError('Unknown encoding: ' + encoding)
  2991. }
  2992. var length = byteLength(string, encoding) | 0
  2993. var buf = createBuffer(length)
  2994. var actual = buf.write(string, encoding)
  2995. if (actual !== length) {
  2996. // Writing a hex string, for example, that contains invalid characters will
  2997. // cause everything after the first invalid character to be ignored. (e.g.
  2998. // 'abxxcd' will be treated as 'ab')
  2999. buf = buf.slice(0, actual)
  3000. }
  3001. return buf
  3002. }
  3003. function fromArrayLike (array) {
  3004. var length = array.length < 0 ? 0 : checked(array.length) | 0
  3005. var buf = createBuffer(length)
  3006. for (var i = 0; i < length; i += 1) {
  3007. buf[i] = array[i] & 255
  3008. }
  3009. return buf
  3010. }
  3011. function fromArrayBuffer (array, byteOffset, length) {
  3012. if (byteOffset < 0 || array.byteLength < byteOffset) {
  3013. throw new RangeError('"offset" is outside of buffer bounds')
  3014. }
  3015. if (array.byteLength < byteOffset + (length || 0)) {
  3016. throw new RangeError('"length" is outside of buffer bounds')
  3017. }
  3018. var buf
  3019. if (byteOffset === undefined && length === undefined) {
  3020. buf = new Uint8Array(array)
  3021. } else if (length === undefined) {
  3022. buf = new Uint8Array(array, byteOffset)
  3023. } else {
  3024. buf = new Uint8Array(array, byteOffset, length)
  3025. }
  3026. // Return an augmented `Uint8Array` instance
  3027. buf.__proto__ = Buffer.prototype
  3028. return buf
  3029. }
  3030. function fromObject (obj) {
  3031. if (Buffer.isBuffer(obj)) {
  3032. var len = checked(obj.length) | 0
  3033. var buf = createBuffer(len)
  3034. if (buf.length === 0) {
  3035. return buf
  3036. }
  3037. obj.copy(buf, 0, 0, len)
  3038. return buf
  3039. }
  3040. if (obj.length !== undefined) {
  3041. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  3042. return createBuffer(0)
  3043. }
  3044. return fromArrayLike(obj)
  3045. }
  3046. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  3047. return fromArrayLike(obj.data)
  3048. }
  3049. }
  3050. function checked (length) {
  3051. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  3052. // length is NaN (which is otherwise coerced to zero.)
  3053. if (length >= K_MAX_LENGTH) {
  3054. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  3055. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  3056. }
  3057. return length | 0
  3058. }
  3059. function SlowBuffer (length) {
  3060. if (+length != length) { // eslint-disable-line eqeqeq
  3061. length = 0
  3062. }
  3063. return Buffer.alloc(+length)
  3064. }
  3065. Buffer.isBuffer = function isBuffer (b) {
  3066. return b != null && b._isBuffer === true &&
  3067. b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
  3068. }
  3069. Buffer.compare = function compare (a, b) {
  3070. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  3071. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  3072. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  3073. throw new TypeError(
  3074. 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  3075. )
  3076. }
  3077. if (a === b) return 0
  3078. var x = a.length
  3079. var y = b.length
  3080. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  3081. if (a[i] !== b[i]) {
  3082. x = a[i]
  3083. y = b[i]
  3084. break
  3085. }
  3086. }
  3087. if (x < y) return -1
  3088. if (y < x) return 1
  3089. return 0
  3090. }
  3091. Buffer.isEncoding = function isEncoding (encoding) {
  3092. switch (String(encoding).toLowerCase()) {
  3093. case 'hex':
  3094. case 'utf8':
  3095. case 'utf-8':
  3096. case 'ascii':
  3097. case 'latin1':
  3098. case 'binary':
  3099. case 'base64':
  3100. case 'ucs2':
  3101. case 'ucs-2':
  3102. case 'utf16le':
  3103. case 'utf-16le':
  3104. return true
  3105. default:
  3106. return false
  3107. }
  3108. }
  3109. Buffer.concat = function concat (list, length) {
  3110. if (!Array.isArray(list)) {
  3111. throw new TypeError('"list" argument must be an Array of Buffers')
  3112. }
  3113. if (list.length === 0) {
  3114. return Buffer.alloc(0)
  3115. }
  3116. var i
  3117. if (length === undefined) {
  3118. length = 0
  3119. for (i = 0; i < list.length; ++i) {
  3120. length += list[i].length
  3121. }
  3122. }
  3123. var buffer = Buffer.allocUnsafe(length)
  3124. var pos = 0
  3125. for (i = 0; i < list.length; ++i) {
  3126. var buf = list[i]
  3127. if (isInstance(buf, Uint8Array)) {
  3128. buf = Buffer.from(buf)
  3129. }
  3130. if (!Buffer.isBuffer(buf)) {
  3131. throw new TypeError('"list" argument must be an Array of Buffers')
  3132. }
  3133. buf.copy(buffer, pos)
  3134. pos += buf.length
  3135. }
  3136. return buffer
  3137. }
  3138. function byteLength (string, encoding) {
  3139. if (Buffer.isBuffer(string)) {
  3140. return string.length
  3141. }
  3142. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  3143. return string.byteLength
  3144. }
  3145. if (typeof string !== 'string') {
  3146. throw new TypeError(
  3147. 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  3148. 'Received type ' + typeof string
  3149. )
  3150. }
  3151. var len = string.length
  3152. var mustMatch = (arguments.length > 2 && arguments[2] === true)
  3153. if (!mustMatch && len === 0) return 0
  3154. // Use a for loop to avoid recursion
  3155. var loweredCase = false
  3156. for (;;) {
  3157. switch (encoding) {
  3158. case 'ascii':
  3159. case 'latin1':
  3160. case 'binary':
  3161. return len
  3162. case 'utf8':
  3163. case 'utf-8':
  3164. return utf8ToBytes(string).length
  3165. case 'ucs2':
  3166. case 'ucs-2':
  3167. case 'utf16le':
  3168. case 'utf-16le':
  3169. return len * 2
  3170. case 'hex':
  3171. return len >>> 1
  3172. case 'base64':
  3173. return base64ToBytes(string).length
  3174. default:
  3175. if (loweredCase) {
  3176. return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
  3177. }
  3178. encoding = ('' + encoding).toLowerCase()
  3179. loweredCase = true
  3180. }
  3181. }
  3182. }
  3183. Buffer.byteLength = byteLength
  3184. function slowToString (encoding, start, end) {
  3185. var loweredCase = false
  3186. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  3187. // property of a typed array.
  3188. // This behaves neither like String nor Uint8Array in that we set start/end
  3189. // to their upper/lower bounds if the value passed is out of range.
  3190. // undefined is handled specially as per ECMA-262 6th Edition,
  3191. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  3192. if (start === undefined || start < 0) {
  3193. start = 0
  3194. }
  3195. // Return early if start > this.length. Done here to prevent potential uint32
  3196. // coercion fail below.
  3197. if (start > this.length) {
  3198. return ''
  3199. }
  3200. if (end === undefined || end > this.length) {
  3201. end = this.length
  3202. }
  3203. if (end <= 0) {
  3204. return ''
  3205. }
  3206. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  3207. end >>>= 0
  3208. start >>>= 0
  3209. if (end <= start) {
  3210. return ''
  3211. }
  3212. if (!encoding) encoding = 'utf8'
  3213. while (true) {
  3214. switch (encoding) {
  3215. case 'hex':
  3216. return hexSlice(this, start, end)
  3217. case 'utf8':
  3218. case 'utf-8':
  3219. return utf8Slice(this, start, end)
  3220. case 'ascii':
  3221. return asciiSlice(this, start, end)
  3222. case 'latin1':
  3223. case 'binary':
  3224. return latin1Slice(this, start, end)
  3225. case 'base64':
  3226. return base64Slice(this, start, end)
  3227. case 'ucs2':
  3228. case 'ucs-2':
  3229. case 'utf16le':
  3230. case 'utf-16le':
  3231. return utf16leSlice(this, start, end)
  3232. default:
  3233. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  3234. encoding = (encoding + '').toLowerCase()
  3235. loweredCase = true
  3236. }
  3237. }
  3238. }
  3239. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  3240. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  3241. // reliably in a browserify context because there could be multiple different
  3242. // copies of the 'buffer' package in use. This method works even for Buffer
  3243. // instances that were created from another copy of the `buffer` package.
  3244. // See: https://github.com/feross/buffer/issues/154
  3245. Buffer.prototype._isBuffer = true
  3246. function swap (b, n, m) {
  3247. var i = b[n]
  3248. b[n] = b[m]
  3249. b[m] = i
  3250. }
  3251. Buffer.prototype.swap16 = function swap16 () {
  3252. var len = this.length
  3253. if (len % 2 !== 0) {
  3254. throw new RangeError('Buffer size must be a multiple of 16-bits')
  3255. }
  3256. for (var i = 0; i < len; i += 2) {
  3257. swap(this, i, i + 1)
  3258. }
  3259. return this
  3260. }
  3261. Buffer.prototype.swap32 = function swap32 () {
  3262. var len = this.length
  3263. if (len % 4 !== 0) {
  3264. throw new RangeError('Buffer size must be a multiple of 32-bits')
  3265. }
  3266. for (var i = 0; i < len; i += 4) {
  3267. swap(this, i, i + 3)
  3268. swap(this, i + 1, i + 2)
  3269. }
  3270. return this
  3271. }
  3272. Buffer.prototype.swap64 = function swap64 () {
  3273. var len = this.length
  3274. if (len % 8 !== 0) {
  3275. throw new RangeError('Buffer size must be a multiple of 64-bits')
  3276. }
  3277. for (var i = 0; i < len; i += 8) {
  3278. swap(this, i, i + 7)
  3279. swap(this, i + 1, i + 6)
  3280. swap(this, i + 2, i + 5)
  3281. swap(this, i + 3, i + 4)
  3282. }
  3283. return this
  3284. }
  3285. Buffer.prototype.toString = function toString () {
  3286. var length = this.length
  3287. if (length === 0) return ''
  3288. if (arguments.length === 0) return utf8Slice(this, 0, length)
  3289. return slowToString.apply(this, arguments)
  3290. }
  3291. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  3292. Buffer.prototype.equals = function equals (b) {
  3293. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  3294. if (this === b) return true
  3295. return Buffer.compare(this, b) === 0
  3296. }
  3297. Buffer.prototype.inspect = function inspect () {
  3298. var str = ''
  3299. var max = exports.INSPECT_MAX_BYTES
  3300. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  3301. if (this.length > max) str += ' ... '
  3302. return '<Buffer ' + str + '>'
  3303. }
  3304. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  3305. if (isInstance(target, Uint8Array)) {
  3306. target = Buffer.from(target, target.offset, target.byteLength)
  3307. }
  3308. if (!Buffer.isBuffer(target)) {
  3309. throw new TypeError(
  3310. 'The "target" argument must be one of type Buffer or Uint8Array. ' +
  3311. 'Received type ' + (typeof target)
  3312. )
  3313. }
  3314. if (start === undefined) {
  3315. start = 0
  3316. }
  3317. if (end === undefined) {
  3318. end = target ? target.length : 0
  3319. }
  3320. if (thisStart === undefined) {
  3321. thisStart = 0
  3322. }
  3323. if (thisEnd === undefined) {
  3324. thisEnd = this.length
  3325. }
  3326. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  3327. throw new RangeError('out of range index')
  3328. }
  3329. if (thisStart >= thisEnd && start >= end) {
  3330. return 0
  3331. }
  3332. if (thisStart >= thisEnd) {
  3333. return -1
  3334. }
  3335. if (start >= end) {
  3336. return 1
  3337. }
  3338. start >>>= 0
  3339. end >>>= 0
  3340. thisStart >>>= 0
  3341. thisEnd >>>= 0
  3342. if (this === target) return 0
  3343. var x = thisEnd - thisStart
  3344. var y = end - start
  3345. var len = Math.min(x, y)
  3346. var thisCopy = this.slice(thisStart, thisEnd)
  3347. var targetCopy = target.slice(start, end)
  3348. for (var i = 0; i < len; ++i) {
  3349. if (thisCopy[i] !== targetCopy[i]) {
  3350. x = thisCopy[i]
  3351. y = targetCopy[i]
  3352. break
  3353. }
  3354. }
  3355. if (x < y) return -1
  3356. if (y < x) return 1
  3357. return 0
  3358. }
  3359. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  3360. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  3361. //
  3362. // Arguments:
  3363. // - buffer - a Buffer to search
  3364. // - val - a string, Buffer, or number
  3365. // - byteOffset - an index into `buffer`; will be clamped to an int32
  3366. // - encoding - an optional encoding, relevant is val is a string
  3367. // - dir - true for indexOf, false for lastIndexOf
  3368. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  3369. // Empty buffer means no match
  3370. if (buffer.length === 0) return -1
  3371. // Normalize byteOffset
  3372. if (typeof byteOffset === 'string') {
  3373. encoding = byteOffset
  3374. byteOffset = 0
  3375. } else if (byteOffset > 0x7fffffff) {
  3376. byteOffset = 0x7fffffff
  3377. } else if (byteOffset < -0x80000000) {
  3378. byteOffset = -0x80000000
  3379. }
  3380. byteOffset = +byteOffset // Coerce to Number.
  3381. if (numberIsNaN(byteOffset)) {
  3382. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  3383. byteOffset = dir ? 0 : (buffer.length - 1)
  3384. }
  3385. // Normalize byteOffset: negative offsets start from the end of the buffer
  3386. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  3387. if (byteOffset >= buffer.length) {
  3388. if (dir) return -1
  3389. else byteOffset = buffer.length - 1
  3390. } else if (byteOffset < 0) {
  3391. if (dir) byteOffset = 0
  3392. else return -1
  3393. }
  3394. // Normalize val
  3395. if (typeof val === 'string') {
  3396. val = Buffer.from(val, encoding)
  3397. }
  3398. // Finally, search either indexOf (if dir is true) or lastIndexOf
  3399. if (Buffer.isBuffer(val)) {
  3400. // Special case: looking for empty string/buffer always fails
  3401. if (val.length === 0) {
  3402. return -1
  3403. }
  3404. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  3405. } else if (typeof val === 'number') {
  3406. val = val & 0xFF // Search for a byte value [0-255]
  3407. if (typeof Uint8Array.prototype.indexOf === 'function') {
  3408. if (dir) {
  3409. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  3410. } else {
  3411. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  3412. }
  3413. }
  3414. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  3415. }
  3416. throw new TypeError('val must be string, number or Buffer')
  3417. }
  3418. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  3419. var indexSize = 1
  3420. var arrLength = arr.length
  3421. var valLength = val.length
  3422. if (encoding !== undefined) {
  3423. encoding = String(encoding).toLowerCase()
  3424. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  3425. encoding === 'utf16le' || encoding === 'utf-16le') {
  3426. if (arr.length < 2 || val.length < 2) {
  3427. return -1
  3428. }
  3429. indexSize = 2
  3430. arrLength /= 2
  3431. valLength /= 2
  3432. byteOffset /= 2
  3433. }
  3434. }
  3435. function read (buf, i) {
  3436. if (indexSize === 1) {
  3437. return buf[i]
  3438. } else {
  3439. return buf.readUInt16BE(i * indexSize)
  3440. }
  3441. }
  3442. var i
  3443. if (dir) {
  3444. var foundIndex = -1
  3445. for (i = byteOffset; i < arrLength; i++) {
  3446. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  3447. if (foundIndex === -1) foundIndex = i
  3448. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  3449. } else {
  3450. if (foundIndex !== -1) i -= i - foundIndex
  3451. foundIndex = -1
  3452. }
  3453. }
  3454. } else {
  3455. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  3456. for (i = byteOffset; i >= 0; i--) {
  3457. var found = true
  3458. for (var j = 0; j < valLength; j++) {
  3459. if (read(arr, i + j) !== read(val, j)) {
  3460. found = false
  3461. break
  3462. }
  3463. }
  3464. if (found) return i
  3465. }
  3466. }
  3467. return -1
  3468. }
  3469. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  3470. return this.indexOf(val, byteOffset, encoding) !== -1
  3471. }
  3472. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  3473. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  3474. }
  3475. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  3476. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  3477. }
  3478. function hexWrite (buf, string, offset, length) {
  3479. offset = Number(offset) || 0
  3480. var remaining = buf.length - offset
  3481. if (!length) {
  3482. length = remaining
  3483. } else {
  3484. length = Number(length)
  3485. if (length > remaining) {
  3486. length = remaining
  3487. }
  3488. }
  3489. var strLen = string.length
  3490. if (length > strLen / 2) {
  3491. length = strLen / 2
  3492. }
  3493. for (var i = 0; i < length; ++i) {
  3494. var parsed = parseInt(string.substr(i * 2, 2), 16)
  3495. if (numberIsNaN(parsed)) return i
  3496. buf[offset + i] = parsed
  3497. }
  3498. return i
  3499. }
  3500. function utf8Write (buf, string, offset, length) {
  3501. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  3502. }
  3503. function asciiWrite (buf, string, offset, length) {
  3504. return blitBuffer(asciiToBytes(string), buf, offset, length)
  3505. }
  3506. function latin1Write (buf, string, offset, length) {
  3507. return asciiWrite(buf, string, offset, length)
  3508. }
  3509. function base64Write (buf, string, offset, length) {
  3510. return blitBuffer(base64ToBytes(string), buf, offset, length)
  3511. }
  3512. function ucs2Write (buf, string, offset, length) {
  3513. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  3514. }
  3515. Buffer.prototype.write = function write (string, offset, length, encoding) {
  3516. // Buffer#write(string)
  3517. if (offset === undefined) {
  3518. encoding = 'utf8'
  3519. length = this.length
  3520. offset = 0
  3521. // Buffer#write(string, encoding)
  3522. } else if (length === undefined && typeof offset === 'string') {
  3523. encoding = offset
  3524. length = this.length
  3525. offset = 0
  3526. // Buffer#write(string, offset[, length][, encoding])
  3527. } else if (isFinite(offset)) {
  3528. offset = offset >>> 0
  3529. if (isFinite(length)) {
  3530. length = length >>> 0
  3531. if (encoding === undefined) encoding = 'utf8'
  3532. } else {
  3533. encoding = length
  3534. length = undefined
  3535. }
  3536. } else {
  3537. throw new Error(
  3538. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  3539. )
  3540. }
  3541. var remaining = this.length - offset
  3542. if (length === undefined || length > remaining) length = remaining
  3543. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  3544. throw new RangeError('Attempt to write outside buffer bounds')
  3545. }
  3546. if (!encoding) encoding = 'utf8'
  3547. var loweredCase = false
  3548. for (;;) {
  3549. switch (encoding) {
  3550. case 'hex':
  3551. return hexWrite(this, string, offset, length)
  3552. case 'utf8':
  3553. case 'utf-8':
  3554. return utf8Write(this, string, offset, length)
  3555. case 'ascii':
  3556. return asciiWrite(this, string, offset, length)
  3557. case 'latin1':
  3558. case 'binary':
  3559. return latin1Write(this, string, offset, length)
  3560. case 'base64':
  3561. // Warning: maxLength not taken into account in base64Write
  3562. return base64Write(this, string, offset, length)
  3563. case 'ucs2':
  3564. case 'ucs-2':
  3565. case 'utf16le':
  3566. case 'utf-16le':
  3567. return ucs2Write(this, string, offset, length)
  3568. default:
  3569. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  3570. encoding = ('' + encoding).toLowerCase()
  3571. loweredCase = true
  3572. }
  3573. }
  3574. }
  3575. Buffer.prototype.toJSON = function toJSON () {
  3576. return {
  3577. type: 'Buffer',
  3578. data: Array.prototype.slice.call(this._arr || this, 0)
  3579. }
  3580. }
  3581. function base64Slice (buf, start, end) {
  3582. if (start === 0 && end === buf.length) {
  3583. return base64.fromByteArray(buf)
  3584. } else {
  3585. return base64.fromByteArray(buf.slice(start, end))
  3586. }
  3587. }
  3588. function utf8Slice (buf, start, end) {
  3589. end = Math.min(buf.length, end)
  3590. var res = []
  3591. var i = start
  3592. while (i < end) {
  3593. var firstByte = buf[i]
  3594. var codePoint = null
  3595. var bytesPerSequence = (firstByte > 0xEF) ? 4
  3596. : (firstByte > 0xDF) ? 3
  3597. : (firstByte > 0xBF) ? 2
  3598. : 1
  3599. if (i + bytesPerSequence <= end) {
  3600. var secondByte, thirdByte, fourthByte, tempCodePoint
  3601. switch (bytesPerSequence) {
  3602. case 1:
  3603. if (firstByte < 0x80) {
  3604. codePoint = firstByte
  3605. }
  3606. break
  3607. case 2:
  3608. secondByte = buf[i + 1]
  3609. if ((secondByte & 0xC0) === 0x80) {
  3610. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  3611. if (tempCodePoint > 0x7F) {
  3612. codePoint = tempCodePoint
  3613. }
  3614. }
  3615. break
  3616. case 3:
  3617. secondByte = buf[i + 1]
  3618. thirdByte = buf[i + 2]
  3619. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  3620. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  3621. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  3622. codePoint = tempCodePoint
  3623. }
  3624. }
  3625. break
  3626. case 4:
  3627. secondByte = buf[i + 1]
  3628. thirdByte = buf[i + 2]
  3629. fourthByte = buf[i + 3]
  3630. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  3631. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  3632. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  3633. codePoint = tempCodePoint
  3634. }
  3635. }
  3636. }
  3637. }
  3638. if (codePoint === null) {
  3639. // we did not generate a valid codePoint so insert a
  3640. // replacement char (U+FFFD) and advance only 1 byte
  3641. codePoint = 0xFFFD
  3642. bytesPerSequence = 1
  3643. } else if (codePoint > 0xFFFF) {
  3644. // encode to utf16 (surrogate pair dance)
  3645. codePoint -= 0x10000
  3646. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  3647. codePoint = 0xDC00 | codePoint & 0x3FF
  3648. }
  3649. res.push(codePoint)
  3650. i += bytesPerSequence
  3651. }
  3652. return decodeCodePointsArray(res)
  3653. }
  3654. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  3655. // the lowest limit is Chrome, with 0x10000 args.
  3656. // We go 1 magnitude less, for safety
  3657. var MAX_ARGUMENTS_LENGTH = 0x1000
  3658. function decodeCodePointsArray (codePoints) {
  3659. var len = codePoints.length
  3660. if (len <= MAX_ARGUMENTS_LENGTH) {
  3661. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  3662. }
  3663. // Decode in chunks to avoid "call stack size exceeded".
  3664. var res = ''
  3665. var i = 0
  3666. while (i < len) {
  3667. res += String.fromCharCode.apply(
  3668. String,
  3669. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  3670. )
  3671. }
  3672. return res
  3673. }
  3674. function asciiSlice (buf, start, end) {
  3675. var ret = ''
  3676. end = Math.min(buf.length, end)
  3677. for (var i = start; i < end; ++i) {
  3678. ret += String.fromCharCode(buf[i] & 0x7F)
  3679. }
  3680. return ret
  3681. }
  3682. function latin1Slice (buf, start, end) {
  3683. var ret = ''
  3684. end = Math.min(buf.length, end)
  3685. for (var i = start; i < end; ++i) {
  3686. ret += String.fromCharCode(buf[i])
  3687. }
  3688. return ret
  3689. }
  3690. function hexSlice (buf, start, end) {
  3691. var len = buf.length
  3692. if (!start || start < 0) start = 0
  3693. if (!end || end < 0 || end > len) end = len
  3694. var out = ''
  3695. for (var i = start; i < end; ++i) {
  3696. out += toHex(buf[i])
  3697. }
  3698. return out
  3699. }
  3700. function utf16leSlice (buf, start, end) {
  3701. var bytes = buf.slice(start, end)
  3702. var res = ''
  3703. for (var i = 0; i < bytes.length; i += 2) {
  3704. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  3705. }
  3706. return res
  3707. }
  3708. Buffer.prototype.slice = function slice (start, end) {
  3709. var len = this.length
  3710. start = ~~start
  3711. end = end === undefined ? len : ~~end
  3712. if (start < 0) {
  3713. start += len
  3714. if (start < 0) start = 0
  3715. } else if (start > len) {
  3716. start = len
  3717. }
  3718. if (end < 0) {
  3719. end += len
  3720. if (end < 0) end = 0
  3721. } else if (end > len) {
  3722. end = len
  3723. }
  3724. if (end < start) end = start
  3725. var newBuf = this.subarray(start, end)
  3726. // Return an augmented `Uint8Array` instance
  3727. newBuf.__proto__ = Buffer.prototype
  3728. return newBuf
  3729. }
  3730. /*
  3731. * Need to make sure that buffer isn't trying to write out of bounds.
  3732. */
  3733. function checkOffset (offset, ext, length) {
  3734. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  3735. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  3736. }
  3737. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  3738. offset = offset >>> 0
  3739. byteLength = byteLength >>> 0
  3740. if (!noAssert) checkOffset(offset, byteLength, this.length)
  3741. var val = this[offset]
  3742. var mul = 1
  3743. var i = 0
  3744. while (++i < byteLength && (mul *= 0x100)) {
  3745. val += this[offset + i] * mul
  3746. }
  3747. return val
  3748. }
  3749. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  3750. offset = offset >>> 0
  3751. byteLength = byteLength >>> 0
  3752. if (!noAssert) {
  3753. checkOffset(offset, byteLength, this.length)
  3754. }
  3755. var val = this[offset + --byteLength]
  3756. var mul = 1
  3757. while (byteLength > 0 && (mul *= 0x100)) {
  3758. val += this[offset + --byteLength] * mul
  3759. }
  3760. return val
  3761. }
  3762. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  3763. offset = offset >>> 0
  3764. if (!noAssert) checkOffset(offset, 1, this.length)
  3765. return this[offset]
  3766. }
  3767. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  3768. offset = offset >>> 0
  3769. if (!noAssert) checkOffset(offset, 2, this.length)
  3770. return this[offset] | (this[offset + 1] << 8)
  3771. }
  3772. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  3773. offset = offset >>> 0
  3774. if (!noAssert) checkOffset(offset, 2, this.length)
  3775. return (this[offset] << 8) | this[offset + 1]
  3776. }
  3777. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  3778. offset = offset >>> 0
  3779. if (!noAssert) checkOffset(offset, 4, this.length)
  3780. return ((this[offset]) |
  3781. (this[offset + 1] << 8) |
  3782. (this[offset + 2] << 16)) +
  3783. (this[offset + 3] * 0x1000000)
  3784. }
  3785. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  3786. offset = offset >>> 0
  3787. if (!noAssert) checkOffset(offset, 4, this.length)
  3788. return (this[offset] * 0x1000000) +
  3789. ((this[offset + 1] << 16) |
  3790. (this[offset + 2] << 8) |
  3791. this[offset + 3])
  3792. }
  3793. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  3794. offset = offset >>> 0
  3795. byteLength = byteLength >>> 0
  3796. if (!noAssert) checkOffset(offset, byteLength, this.length)
  3797. var val = this[offset]
  3798. var mul = 1
  3799. var i = 0
  3800. while (++i < byteLength && (mul *= 0x100)) {
  3801. val += this[offset + i] * mul
  3802. }
  3803. mul *= 0x80
  3804. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  3805. return val
  3806. }
  3807. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  3808. offset = offset >>> 0
  3809. byteLength = byteLength >>> 0
  3810. if (!noAssert) checkOffset(offset, byteLength, this.length)
  3811. var i = byteLength
  3812. var mul = 1
  3813. var val = this[offset + --i]
  3814. while (i > 0 && (mul *= 0x100)) {
  3815. val += this[offset + --i] * mul
  3816. }
  3817. mul *= 0x80
  3818. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  3819. return val
  3820. }
  3821. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  3822. offset = offset >>> 0
  3823. if (!noAssert) checkOffset(offset, 1, this.length)
  3824. if (!(this[offset] & 0x80)) return (this[offset])
  3825. return ((0xff - this[offset] + 1) * -1)
  3826. }
  3827. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  3828. offset = offset >>> 0
  3829. if (!noAssert) checkOffset(offset, 2, this.length)
  3830. var val = this[offset] | (this[offset + 1] << 8)
  3831. return (val & 0x8000) ? val | 0xFFFF0000 : val
  3832. }
  3833. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  3834. offset = offset >>> 0
  3835. if (!noAssert) checkOffset(offset, 2, this.length)
  3836. var val = this[offset + 1] | (this[offset] << 8)
  3837. return (val & 0x8000) ? val | 0xFFFF0000 : val
  3838. }
  3839. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  3840. offset = offset >>> 0
  3841. if (!noAssert) checkOffset(offset, 4, this.length)
  3842. return (this[offset]) |
  3843. (this[offset + 1] << 8) |
  3844. (this[offset + 2] << 16) |
  3845. (this[offset + 3] << 24)
  3846. }
  3847. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  3848. offset = offset >>> 0
  3849. if (!noAssert) checkOffset(offset, 4, this.length)
  3850. return (this[offset] << 24) |
  3851. (this[offset + 1] << 16) |
  3852. (this[offset + 2] << 8) |
  3853. (this[offset + 3])
  3854. }
  3855. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  3856. offset = offset >>> 0
  3857. if (!noAssert) checkOffset(offset, 4, this.length)
  3858. return ieee754.read(this, offset, true, 23, 4)
  3859. }
  3860. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  3861. offset = offset >>> 0
  3862. if (!noAssert) checkOffset(offset, 4, this.length)
  3863. return ieee754.read(this, offset, false, 23, 4)
  3864. }
  3865. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  3866. offset = offset >>> 0
  3867. if (!noAssert) checkOffset(offset, 8, this.length)
  3868. return ieee754.read(this, offset, true, 52, 8)
  3869. }
  3870. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  3871. offset = offset >>> 0
  3872. if (!noAssert) checkOffset(offset, 8, this.length)
  3873. return ieee754.read(this, offset, false, 52, 8)
  3874. }
  3875. function checkInt (buf, value, offset, ext, max, min) {
  3876. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  3877. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  3878. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  3879. }
  3880. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  3881. value = +value
  3882. offset = offset >>> 0
  3883. byteLength = byteLength >>> 0
  3884. if (!noAssert) {
  3885. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  3886. checkInt(this, value, offset, byteLength, maxBytes, 0)
  3887. }
  3888. var mul = 1
  3889. var i = 0
  3890. this[offset] = value & 0xFF
  3891. while (++i < byteLength && (mul *= 0x100)) {
  3892. this[offset + i] = (value / mul) & 0xFF
  3893. }
  3894. return offset + byteLength
  3895. }
  3896. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  3897. value = +value
  3898. offset = offset >>> 0
  3899. byteLength = byteLength >>> 0
  3900. if (!noAssert) {
  3901. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  3902. checkInt(this, value, offset, byteLength, maxBytes, 0)
  3903. }
  3904. var i = byteLength - 1
  3905. var mul = 1
  3906. this[offset + i] = value & 0xFF
  3907. while (--i >= 0 && (mul *= 0x100)) {
  3908. this[offset + i] = (value / mul) & 0xFF
  3909. }
  3910. return offset + byteLength
  3911. }
  3912. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  3913. value = +value
  3914. offset = offset >>> 0
  3915. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  3916. this[offset] = (value & 0xff)
  3917. return offset + 1
  3918. }
  3919. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  3920. value = +value
  3921. offset = offset >>> 0
  3922. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  3923. this[offset] = (value & 0xff)
  3924. this[offset + 1] = (value >>> 8)
  3925. return offset + 2
  3926. }
  3927. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  3928. value = +value
  3929. offset = offset >>> 0
  3930. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  3931. this[offset] = (value >>> 8)
  3932. this[offset + 1] = (value & 0xff)
  3933. return offset + 2
  3934. }
  3935. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  3936. value = +value
  3937. offset = offset >>> 0
  3938. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  3939. this[offset + 3] = (value >>> 24)
  3940. this[offset + 2] = (value >>> 16)
  3941. this[offset + 1] = (value >>> 8)
  3942. this[offset] = (value & 0xff)
  3943. return offset + 4
  3944. }
  3945. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  3946. value = +value
  3947. offset = offset >>> 0
  3948. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  3949. this[offset] = (value >>> 24)
  3950. this[offset + 1] = (value >>> 16)
  3951. this[offset + 2] = (value >>> 8)
  3952. this[offset + 3] = (value & 0xff)
  3953. return offset + 4
  3954. }
  3955. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  3956. value = +value
  3957. offset = offset >>> 0
  3958. if (!noAssert) {
  3959. var limit = Math.pow(2, (8 * byteLength) - 1)
  3960. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  3961. }
  3962. var i = 0
  3963. var mul = 1
  3964. var sub = 0
  3965. this[offset] = value & 0xFF
  3966. while (++i < byteLength && (mul *= 0x100)) {
  3967. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  3968. sub = 1
  3969. }
  3970. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  3971. }
  3972. return offset + byteLength
  3973. }
  3974. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  3975. value = +value
  3976. offset = offset >>> 0
  3977. if (!noAssert) {
  3978. var limit = Math.pow(2, (8 * byteLength) - 1)
  3979. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  3980. }
  3981. var i = byteLength - 1
  3982. var mul = 1
  3983. var sub = 0
  3984. this[offset + i] = value & 0xFF
  3985. while (--i >= 0 && (mul *= 0x100)) {
  3986. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  3987. sub = 1
  3988. }
  3989. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  3990. }
  3991. return offset + byteLength
  3992. }
  3993. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  3994. value = +value
  3995. offset = offset >>> 0
  3996. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  3997. if (value < 0) value = 0xff + value + 1
  3998. this[offset] = (value & 0xff)
  3999. return offset + 1
  4000. }
  4001. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  4002. value = +value
  4003. offset = offset >>> 0
  4004. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  4005. this[offset] = (value & 0xff)
  4006. this[offset + 1] = (value >>> 8)
  4007. return offset + 2
  4008. }
  4009. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  4010. value = +value
  4011. offset = offset >>> 0
  4012. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  4013. this[offset] = (value >>> 8)
  4014. this[offset + 1] = (value & 0xff)
  4015. return offset + 2
  4016. }
  4017. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  4018. value = +value
  4019. offset = offset >>> 0
  4020. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  4021. this[offset] = (value & 0xff)
  4022. this[offset + 1] = (value >>> 8)
  4023. this[offset + 2] = (value >>> 16)
  4024. this[offset + 3] = (value >>> 24)
  4025. return offset + 4
  4026. }
  4027. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  4028. value = +value
  4029. offset = offset >>> 0
  4030. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  4031. if (value < 0) value = 0xffffffff + value + 1
  4032. this[offset] = (value >>> 24)
  4033. this[offset + 1] = (value >>> 16)
  4034. this[offset + 2] = (value >>> 8)
  4035. this[offset + 3] = (value & 0xff)
  4036. return offset + 4
  4037. }
  4038. function checkIEEE754 (buf, value, offset, ext, max, min) {
  4039. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  4040. if (offset < 0) throw new RangeError('Index out of range')
  4041. }
  4042. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  4043. value = +value
  4044. offset = offset >>> 0
  4045. if (!noAssert) {
  4046. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  4047. }
  4048. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  4049. return offset + 4
  4050. }
  4051. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  4052. return writeFloat(this, value, offset, true, noAssert)
  4053. }
  4054. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  4055. return writeFloat(this, value, offset, false, noAssert)
  4056. }
  4057. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  4058. value = +value
  4059. offset = offset >>> 0
  4060. if (!noAssert) {
  4061. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  4062. }
  4063. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  4064. return offset + 8
  4065. }
  4066. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  4067. return writeDouble(this, value, offset, true, noAssert)
  4068. }
  4069. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  4070. return writeDouble(this, value, offset, false, noAssert)
  4071. }
  4072. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  4073. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  4074. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  4075. if (!start) start = 0
  4076. if (!end && end !== 0) end = this.length
  4077. if (targetStart >= target.length) targetStart = target.length
  4078. if (!targetStart) targetStart = 0
  4079. if (end > 0 && end < start) end = start
  4080. // Copy 0 bytes; we're done
  4081. if (end === start) return 0
  4082. if (target.length === 0 || this.length === 0) return 0
  4083. // Fatal error conditions
  4084. if (targetStart < 0) {
  4085. throw new RangeError('targetStart out of bounds')
  4086. }
  4087. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  4088. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  4089. // Are we oob?
  4090. if (end > this.length) end = this.length
  4091. if (target.length - targetStart < end - start) {
  4092. end = target.length - targetStart + start
  4093. }
  4094. var len = end - start
  4095. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  4096. // Use built-in when available, missing from IE11
  4097. this.copyWithin(targetStart, start, end)
  4098. } else if (this === target && start < targetStart && targetStart < end) {
  4099. // descending copy from end
  4100. for (var i = len - 1; i >= 0; --i) {
  4101. target[i + targetStart] = this[i + start]
  4102. }
  4103. } else {
  4104. Uint8Array.prototype.set.call(
  4105. target,
  4106. this.subarray(start, end),
  4107. targetStart
  4108. )
  4109. }
  4110. return len
  4111. }
  4112. // Usage:
  4113. // buffer.fill(number[, offset[, end]])
  4114. // buffer.fill(buffer[, offset[, end]])
  4115. // buffer.fill(string[, offset[, end]][, encoding])
  4116. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  4117. // Handle string cases:
  4118. if (typeof val === 'string') {
  4119. if (typeof start === 'string') {
  4120. encoding = start
  4121. start = 0
  4122. end = this.length
  4123. } else if (typeof end === 'string') {
  4124. encoding = end
  4125. end = this.length
  4126. }
  4127. if (encoding !== undefined && typeof encoding !== 'string') {
  4128. throw new TypeError('encoding must be a string')
  4129. }
  4130. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  4131. throw new TypeError('Unknown encoding: ' + encoding)
  4132. }
  4133. if (val.length === 1) {
  4134. var code = val.charCodeAt(0)
  4135. if ((encoding === 'utf8' && code < 128) ||
  4136. encoding === 'latin1') {
  4137. // Fast path: If `val` fits into a single byte, use that numeric value.
  4138. val = code
  4139. }
  4140. }
  4141. } else if (typeof val === 'number') {
  4142. val = val & 255
  4143. }
  4144. // Invalid ranges are not set to a default, so can range check early.
  4145. if (start < 0 || this.length < start || this.length < end) {
  4146. throw new RangeError('Out of range index')
  4147. }
  4148. if (end <= start) {
  4149. return this
  4150. }
  4151. start = start >>> 0
  4152. end = end === undefined ? this.length : end >>> 0
  4153. if (!val) val = 0
  4154. var i
  4155. if (typeof val === 'number') {
  4156. for (i = start; i < end; ++i) {
  4157. this[i] = val
  4158. }
  4159. } else {
  4160. var bytes = Buffer.isBuffer(val)
  4161. ? val
  4162. : Buffer.from(val, encoding)
  4163. var len = bytes.length
  4164. if (len === 0) {
  4165. throw new TypeError('The value "' + val +
  4166. '" is invalid for argument "value"')
  4167. }
  4168. for (i = 0; i < end - start; ++i) {
  4169. this[i + start] = bytes[i % len]
  4170. }
  4171. }
  4172. return this
  4173. }
  4174. // HELPER FUNCTIONS
  4175. // ================
  4176. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  4177. function base64clean (str) {
  4178. // Node takes equal signs as end of the Base64 encoding
  4179. str = str.split('=')[0]
  4180. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  4181. str = str.trim().replace(INVALID_BASE64_RE, '')
  4182. // Node converts strings with length < 2 to ''
  4183. if (str.length < 2) return ''
  4184. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  4185. while (str.length % 4 !== 0) {
  4186. str = str + '='
  4187. }
  4188. return str
  4189. }
  4190. function toHex (n) {
  4191. if (n < 16) return '0' + n.toString(16)
  4192. return n.toString(16)
  4193. }
  4194. function utf8ToBytes (string, units) {
  4195. units = units || Infinity
  4196. var codePoint
  4197. var length = string.length
  4198. var leadSurrogate = null
  4199. var bytes = []
  4200. for (var i = 0; i < length; ++i) {
  4201. codePoint = string.charCodeAt(i)
  4202. // is surrogate component
  4203. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  4204. // last char was a lead
  4205. if (!leadSurrogate) {
  4206. // no lead yet
  4207. if (codePoint > 0xDBFF) {
  4208. // unexpected trail
  4209. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4210. continue
  4211. } else if (i + 1 === length) {
  4212. // unpaired lead
  4213. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4214. continue
  4215. }
  4216. // valid lead
  4217. leadSurrogate = codePoint
  4218. continue
  4219. }
  4220. // 2 leads in a row
  4221. if (codePoint < 0xDC00) {
  4222. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4223. leadSurrogate = codePoint
  4224. continue
  4225. }
  4226. // valid surrogate pair
  4227. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  4228. } else if (leadSurrogate) {
  4229. // valid bmp char, but last char was a lead
  4230. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4231. }
  4232. leadSurrogate = null
  4233. // encode utf8
  4234. if (codePoint < 0x80) {
  4235. if ((units -= 1) < 0) break
  4236. bytes.push(codePoint)
  4237. } else if (codePoint < 0x800) {
  4238. if ((units -= 2) < 0) break
  4239. bytes.push(
  4240. codePoint >> 0x6 | 0xC0,
  4241. codePoint & 0x3F | 0x80
  4242. )
  4243. } else if (codePoint < 0x10000) {
  4244. if ((units -= 3) < 0) break
  4245. bytes.push(
  4246. codePoint >> 0xC | 0xE0,
  4247. codePoint >> 0x6 & 0x3F | 0x80,
  4248. codePoint & 0x3F | 0x80
  4249. )
  4250. } else if (codePoint < 0x110000) {
  4251. if ((units -= 4) < 0) break
  4252. bytes.push(
  4253. codePoint >> 0x12 | 0xF0,
  4254. codePoint >> 0xC & 0x3F | 0x80,
  4255. codePoint >> 0x6 & 0x3F | 0x80,
  4256. codePoint & 0x3F | 0x80
  4257. )
  4258. } else {
  4259. throw new Error('Invalid code point')
  4260. }
  4261. }
  4262. return bytes
  4263. }
  4264. function asciiToBytes (str) {
  4265. var byteArray = []
  4266. for (var i = 0; i < str.length; ++i) {
  4267. // Node's code seems to be doing this and not & 0x7F..
  4268. byteArray.push(str.charCodeAt(i) & 0xFF)
  4269. }
  4270. return byteArray
  4271. }
  4272. function utf16leToBytes (str, units) {
  4273. var c, hi, lo
  4274. var byteArray = []
  4275. for (var i = 0; i < str.length; ++i) {
  4276. if ((units -= 2) < 0) break
  4277. c = str.charCodeAt(i)
  4278. hi = c >> 8
  4279. lo = c % 256
  4280. byteArray.push(lo)
  4281. byteArray.push(hi)
  4282. }
  4283. return byteArray
  4284. }
  4285. function base64ToBytes (str) {
  4286. return base64.toByteArray(base64clean(str))
  4287. }
  4288. function blitBuffer (src, dst, offset, length) {
  4289. for (var i = 0; i < length; ++i) {
  4290. if ((i + offset >= dst.length) || (i >= src.length)) break
  4291. dst[i + offset] = src[i]
  4292. }
  4293. return i
  4294. }
  4295. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  4296. // the `instanceof` check but they should be treated as of that type.
  4297. // See: https://github.com/feross/buffer/issues/166
  4298. function isInstance (obj, type) {
  4299. return obj instanceof type ||
  4300. (obj != null && obj.constructor != null && obj.constructor.name != null &&
  4301. obj.constructor.name === type.name)
  4302. }
  4303. function numberIsNaN (obj) {
  4304. // For IE11 support
  4305. return obj !== obj // eslint-disable-line no-self-compare
  4306. }
  4307. }).call(this)}).call(this,require("buffer").Buffer)
  4308. },{"base64-js":8,"buffer":9,"ieee754":10}],10:[function(require,module,exports){
  4309. /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
  4310. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  4311. var e, m
  4312. var eLen = (nBytes * 8) - mLen - 1
  4313. var eMax = (1 << eLen) - 1
  4314. var eBias = eMax >> 1
  4315. var nBits = -7
  4316. var i = isLE ? (nBytes - 1) : 0
  4317. var d = isLE ? -1 : 1
  4318. var s = buffer[offset + i]
  4319. i += d
  4320. e = s & ((1 << (-nBits)) - 1)
  4321. s >>= (-nBits)
  4322. nBits += eLen
  4323. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  4324. m = e & ((1 << (-nBits)) - 1)
  4325. e >>= (-nBits)
  4326. nBits += mLen
  4327. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  4328. if (e === 0) {
  4329. e = 1 - eBias
  4330. } else if (e === eMax) {
  4331. return m ? NaN : ((s ? -1 : 1) * Infinity)
  4332. } else {
  4333. m = m + Math.pow(2, mLen)
  4334. e = e - eBias
  4335. }
  4336. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  4337. }
  4338. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  4339. var e, m, c
  4340. var eLen = (nBytes * 8) - mLen - 1
  4341. var eMax = (1 << eLen) - 1
  4342. var eBias = eMax >> 1
  4343. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  4344. var i = isLE ? 0 : (nBytes - 1)
  4345. var d = isLE ? 1 : -1
  4346. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  4347. value = Math.abs(value)
  4348. if (isNaN(value) || value === Infinity) {
  4349. m = isNaN(value) ? 1 : 0
  4350. e = eMax
  4351. } else {
  4352. e = Math.floor(Math.log(value) / Math.LN2)
  4353. if (value * (c = Math.pow(2, -e)) < 1) {
  4354. e--
  4355. c *= 2
  4356. }
  4357. if (e + eBias >= 1) {
  4358. value += rt / c
  4359. } else {
  4360. value += rt * Math.pow(2, 1 - eBias)
  4361. }
  4362. if (value * c >= 2) {
  4363. e++
  4364. c /= 2
  4365. }
  4366. if (e + eBias >= eMax) {
  4367. m = 0
  4368. e = eMax
  4369. } else if (e + eBias >= 1) {
  4370. m = ((value * c) - 1) * Math.pow(2, mLen)
  4371. e = e + eBias
  4372. } else {
  4373. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  4374. e = 0
  4375. }
  4376. }
  4377. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  4378. e = (e << mLen) | m
  4379. eLen += mLen
  4380. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  4381. buffer[offset + i - d] |= s * 128
  4382. }
  4383. },{}],11:[function(require,module,exports){
  4384. /*!
  4385. * Determine if an object is a Buffer
  4386. *
  4387. * @author Feross Aboukhadijeh <https://feross.org>
  4388. * @license MIT
  4389. */
  4390. // The _isBuffer check is for Safari 5-7 support, because it's missing
  4391. // Object.prototype.constructor. Remove this eventually
  4392. module.exports = function (obj) {
  4393. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  4394. }
  4395. function isBuffer (obj) {
  4396. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  4397. }
  4398. // For Node v0.10 support. Remove this eventually.
  4399. function isSlowBuffer (obj) {
  4400. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  4401. }
  4402. },{}],12:[function(require,module,exports){
  4403. // Generated by CoffeeScript 2.4.1
  4404. (function() {
  4405. module.exports = {
  4406. Disconnected: 1,
  4407. Preceding: 2,
  4408. Following: 4,
  4409. Contains: 8,
  4410. ContainedBy: 16,
  4411. ImplementationSpecific: 32
  4412. };
  4413. }).call(this);
  4414. },{}],13:[function(require,module,exports){
  4415. // Generated by CoffeeScript 2.4.1
  4416. (function() {
  4417. module.exports = {
  4418. Element: 1,
  4419. Attribute: 2,
  4420. Text: 3,
  4421. CData: 4,
  4422. EntityReference: 5,
  4423. EntityDeclaration: 6,
  4424. ProcessingInstruction: 7,
  4425. Comment: 8,
  4426. Document: 9,
  4427. DocType: 10,
  4428. DocumentFragment: 11,
  4429. NotationDeclaration: 12,
  4430. // Numeric codes up to 200 are reserved to W3C for possible future use.
  4431. // Following are types internal to this library:
  4432. Declaration: 201,
  4433. Raw: 202,
  4434. AttributeDeclaration: 203,
  4435. ElementDeclaration: 204,
  4436. Dummy: 205
  4437. };
  4438. }).call(this);
  4439. },{}],14:[function(require,module,exports){
  4440. // Generated by CoffeeScript 2.4.1
  4441. (function() {
  4442. // Copies all enumerable own properties from `sources` to `target`
  4443. var assign, getValue, isArray, isEmpty, isFunction, isObject, isPlainObject,
  4444. hasProp = {}.hasOwnProperty;
  4445. assign = function(target, ...sources) {
  4446. var i, key, len, source;
  4447. if (isFunction(Object.assign)) {
  4448. Object.assign.apply(null, arguments);
  4449. } else {
  4450. for (i = 0, len = sources.length; i < len; i++) {
  4451. source = sources[i];
  4452. if (source != null) {
  4453. for (key in source) {
  4454. if (!hasProp.call(source, key)) continue;
  4455. target[key] = source[key];
  4456. }
  4457. }
  4458. }
  4459. }
  4460. return target;
  4461. };
  4462. // Determines if `val` is a Function object
  4463. isFunction = function(val) {
  4464. return !!val && Object.prototype.toString.call(val) === '[object Function]';
  4465. };
  4466. // Determines if `val` is an Object
  4467. isObject = function(val) {
  4468. var ref;
  4469. return !!val && ((ref = typeof val) === 'function' || ref === 'object');
  4470. };
  4471. // Determines if `val` is an Array
  4472. isArray = function(val) {
  4473. if (isFunction(Array.isArray)) {
  4474. return Array.isArray(val);
  4475. } else {
  4476. return Object.prototype.toString.call(val) === '[object Array]';
  4477. }
  4478. };
  4479. // Determines if `val` is an empty Array or an Object with no own properties
  4480. isEmpty = function(val) {
  4481. var key;
  4482. if (isArray(val)) {
  4483. return !val.length;
  4484. } else {
  4485. for (key in val) {
  4486. if (!hasProp.call(val, key)) continue;
  4487. return false;
  4488. }
  4489. return true;
  4490. }
  4491. };
  4492. // Determines if `val` is a plain Object
  4493. isPlainObject = function(val) {
  4494. var ctor, proto;
  4495. return isObject(val) && (proto = Object.getPrototypeOf(val)) && (ctor = proto.constructor) && (typeof ctor === 'function') && (ctor instanceof ctor) && (Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object));
  4496. };
  4497. // Gets the primitive value of an object
  4498. getValue = function(obj) {
  4499. if (isFunction(obj.valueOf)) {
  4500. return obj.valueOf();
  4501. } else {
  4502. return obj;
  4503. }
  4504. };
  4505. module.exports.assign = assign;
  4506. module.exports.isFunction = isFunction;
  4507. module.exports.isObject = isObject;
  4508. module.exports.isArray = isArray;
  4509. module.exports.isEmpty = isEmpty;
  4510. module.exports.isPlainObject = isPlainObject;
  4511. module.exports.getValue = getValue;
  4512. }).call(this);
  4513. },{}],15:[function(require,module,exports){
  4514. // Generated by CoffeeScript 2.4.1
  4515. (function() {
  4516. module.exports = {
  4517. None: 0,
  4518. OpenTag: 1,
  4519. InsideTag: 2,
  4520. CloseTag: 3
  4521. };
  4522. }).call(this);
  4523. },{}],16:[function(require,module,exports){
  4524. // Generated by CoffeeScript 2.4.1
  4525. (function() {
  4526. var NodeType, XMLAttribute, XMLNode;
  4527. NodeType = require('./NodeType');
  4528. XMLNode = require('./XMLNode');
  4529. // Represents an attribute
  4530. module.exports = XMLAttribute = (function() {
  4531. class XMLAttribute {
  4532. // Initializes a new instance of `XMLAttribute`
  4533. // `parent` the parent node
  4534. // `name` attribute target
  4535. // `value` attribute value
  4536. constructor(parent, name, value) {
  4537. this.parent = parent;
  4538. if (this.parent) {
  4539. this.options = this.parent.options;
  4540. this.stringify = this.parent.stringify;
  4541. }
  4542. if (name == null) {
  4543. throw new Error("Missing attribute name. " + this.debugInfo(name));
  4544. }
  4545. this.name = this.stringify.name(name);
  4546. this.value = this.stringify.attValue(value);
  4547. this.type = NodeType.Attribute;
  4548. // DOM level 3
  4549. this.isId = false;
  4550. this.schemaTypeInfo = null;
  4551. }
  4552. // Creates and returns a deep clone of `this`
  4553. clone() {
  4554. return Object.create(this);
  4555. }
  4556. // Converts the XML fragment to string
  4557. // `options.pretty` pretty prints the result
  4558. // `options.indent` indentation for pretty print
  4559. // `options.offset` how many indentations to add to every line for pretty print
  4560. // `options.newline` newline sequence for pretty print
  4561. toString(options) {
  4562. return this.options.writer.attribute(this, this.options.writer.filterOptions(options));
  4563. }
  4564. // Returns debug string for this node
  4565. debugInfo(name) {
  4566. name = name || this.name;
  4567. if (name == null) {
  4568. return "parent: <" + this.parent.name + ">";
  4569. } else {
  4570. return "attribute: {" + name + "}, parent: <" + this.parent.name + ">";
  4571. }
  4572. }
  4573. isEqualNode(node) {
  4574. if (node.namespaceURI !== this.namespaceURI) {
  4575. return false;
  4576. }
  4577. if (node.prefix !== this.prefix) {
  4578. return false;
  4579. }
  4580. if (node.localName !== this.localName) {
  4581. return false;
  4582. }
  4583. if (node.value !== this.value) {
  4584. return false;
  4585. }
  4586. return true;
  4587. }
  4588. };
  4589. // DOM level 1
  4590. Object.defineProperty(XMLAttribute.prototype, 'nodeType', {
  4591. get: function() {
  4592. return this.type;
  4593. }
  4594. });
  4595. Object.defineProperty(XMLAttribute.prototype, 'ownerElement', {
  4596. get: function() {
  4597. return this.parent;
  4598. }
  4599. });
  4600. // DOM level 3
  4601. Object.defineProperty(XMLAttribute.prototype, 'textContent', {
  4602. get: function() {
  4603. return this.value;
  4604. },
  4605. set: function(value) {
  4606. return this.value = value || '';
  4607. }
  4608. });
  4609. // DOM level 4
  4610. Object.defineProperty(XMLAttribute.prototype, 'namespaceURI', {
  4611. get: function() {
  4612. return '';
  4613. }
  4614. });
  4615. Object.defineProperty(XMLAttribute.prototype, 'prefix', {
  4616. get: function() {
  4617. return '';
  4618. }
  4619. });
  4620. Object.defineProperty(XMLAttribute.prototype, 'localName', {
  4621. get: function() {
  4622. return this.name;
  4623. }
  4624. });
  4625. Object.defineProperty(XMLAttribute.prototype, 'specified', {
  4626. get: function() {
  4627. return true;
  4628. }
  4629. });
  4630. return XMLAttribute;
  4631. }).call(this);
  4632. }).call(this);
  4633. },{"./NodeType":13,"./XMLNode":35}],17:[function(require,module,exports){
  4634. // Generated by CoffeeScript 2.4.1
  4635. (function() {
  4636. var NodeType, XMLCData, XMLCharacterData;
  4637. NodeType = require('./NodeType');
  4638. XMLCharacterData = require('./XMLCharacterData');
  4639. // Represents a CDATA node
  4640. module.exports = XMLCData = class XMLCData extends XMLCharacterData {
  4641. // Initializes a new instance of `XMLCData`
  4642. // `text` CDATA text
  4643. constructor(parent, text) {
  4644. super(parent);
  4645. if (text == null) {
  4646. throw new Error("Missing CDATA text. " + this.debugInfo());
  4647. }
  4648. this.name = "#cdata-section";
  4649. this.type = NodeType.CData;
  4650. this.value = this.stringify.cdata(text);
  4651. }
  4652. // Creates and returns a deep clone of `this`
  4653. clone() {
  4654. return Object.create(this);
  4655. }
  4656. // Converts the XML fragment to string
  4657. // `options.pretty` pretty prints the result
  4658. // `options.indent` indentation for pretty print
  4659. // `options.offset` how many indentations to add to every line for pretty print
  4660. // `options.newline` newline sequence for pretty print
  4661. toString(options) {
  4662. return this.options.writer.cdata(this, this.options.writer.filterOptions(options));
  4663. }
  4664. };
  4665. }).call(this);
  4666. },{"./NodeType":13,"./XMLCharacterData":18}],18:[function(require,module,exports){
  4667. // Generated by CoffeeScript 2.4.1
  4668. (function() {
  4669. var XMLCharacterData, XMLNode;
  4670. XMLNode = require('./XMLNode');
  4671. // Represents a character data node
  4672. module.exports = XMLCharacterData = (function() {
  4673. class XMLCharacterData extends XMLNode {
  4674. // Initializes a new instance of `XMLCharacterData`
  4675. constructor(parent) {
  4676. super(parent);
  4677. this.value = '';
  4678. }
  4679. // Creates and returns a deep clone of `this`
  4680. clone() {
  4681. return Object.create(this);
  4682. }
  4683. // DOM level 1 functions to be implemented later
  4684. substringData(offset, count) {
  4685. throw new Error("This DOM method is not implemented." + this.debugInfo());
  4686. }
  4687. appendData(arg) {
  4688. throw new Error("This DOM method is not implemented." + this.debugInfo());
  4689. }
  4690. insertData(offset, arg) {
  4691. throw new Error("This DOM method is not implemented." + this.debugInfo());
  4692. }
  4693. deleteData(offset, count) {
  4694. throw new Error("This DOM method is not implemented." + this.debugInfo());
  4695. }
  4696. replaceData(offset, count, arg) {
  4697. throw new Error("This DOM method is not implemented." + this.debugInfo());
  4698. }
  4699. isEqualNode(node) {
  4700. if (!super.isEqualNode(node)) {
  4701. return false;
  4702. }
  4703. if (node.data !== this.data) {
  4704. return false;
  4705. }
  4706. return true;
  4707. }
  4708. };
  4709. // DOM level 1
  4710. Object.defineProperty(XMLCharacterData.prototype, 'data', {
  4711. get: function() {
  4712. return this.value;
  4713. },
  4714. set: function(value) {
  4715. return this.value = value || '';
  4716. }
  4717. });
  4718. Object.defineProperty(XMLCharacterData.prototype, 'length', {
  4719. get: function() {
  4720. return this.value.length;
  4721. }
  4722. });
  4723. // DOM level 3
  4724. Object.defineProperty(XMLCharacterData.prototype, 'textContent', {
  4725. get: function() {
  4726. return this.value;
  4727. },
  4728. set: function(value) {
  4729. return this.value = value || '';
  4730. }
  4731. });
  4732. return XMLCharacterData;
  4733. }).call(this);
  4734. }).call(this);
  4735. },{"./XMLNode":35}],19:[function(require,module,exports){
  4736. // Generated by CoffeeScript 2.4.1
  4737. (function() {
  4738. var NodeType, XMLCharacterData, XMLComment;
  4739. NodeType = require('./NodeType');
  4740. XMLCharacterData = require('./XMLCharacterData');
  4741. // Represents a comment node
  4742. module.exports = XMLComment = class XMLComment extends XMLCharacterData {
  4743. // Initializes a new instance of `XMLComment`
  4744. // `text` comment text
  4745. constructor(parent, text) {
  4746. super(parent);
  4747. if (text == null) {
  4748. throw new Error("Missing comment text. " + this.debugInfo());
  4749. }
  4750. this.name = "#comment";
  4751. this.type = NodeType.Comment;
  4752. this.value = this.stringify.comment(text);
  4753. }
  4754. // Creates and returns a deep clone of `this`
  4755. clone() {
  4756. return Object.create(this);
  4757. }
  4758. // Converts the XML fragment to string
  4759. // `options.pretty` pretty prints the result
  4760. // `options.indent` indentation for pretty print
  4761. // `options.offset` how many indentations to add to every line for pretty print
  4762. // `options.newline` newline sequence for pretty print
  4763. toString(options) {
  4764. return this.options.writer.comment(this, this.options.writer.filterOptions(options));
  4765. }
  4766. };
  4767. }).call(this);
  4768. },{"./NodeType":13,"./XMLCharacterData":18}],20:[function(require,module,exports){
  4769. // Generated by CoffeeScript 2.4.1
  4770. (function() {
  4771. var XMLDOMConfiguration, XMLDOMErrorHandler, XMLDOMStringList;
  4772. XMLDOMErrorHandler = require('./XMLDOMErrorHandler');
  4773. XMLDOMStringList = require('./XMLDOMStringList');
  4774. // Implements the DOMConfiguration interface
  4775. module.exports = XMLDOMConfiguration = (function() {
  4776. class XMLDOMConfiguration {
  4777. constructor() {
  4778. var clonedSelf;
  4779. this.defaultParams = {
  4780. "canonical-form": false,
  4781. "cdata-sections": false,
  4782. "comments": false,
  4783. "datatype-normalization": false,
  4784. "element-content-whitespace": true,
  4785. "entities": true,
  4786. "error-handler": new XMLDOMErrorHandler(),
  4787. "infoset": true,
  4788. "validate-if-schema": false,
  4789. "namespaces": true,
  4790. "namespace-declarations": true,
  4791. "normalize-characters": false,
  4792. "schema-location": '',
  4793. "schema-type": '',
  4794. "split-cdata-sections": true,
  4795. "validate": false,
  4796. "well-formed": true
  4797. };
  4798. this.params = clonedSelf = Object.create(this.defaultParams);
  4799. }
  4800. // Gets the value of a parameter.
  4801. // `name` name of the parameter
  4802. getParameter(name) {
  4803. if (this.params.hasOwnProperty(name)) {
  4804. return this.params[name];
  4805. } else {
  4806. return null;
  4807. }
  4808. }
  4809. // Checks if setting a parameter to a specific value is supported.
  4810. // `name` name of the parameter
  4811. // `value` parameter value
  4812. canSetParameter(name, value) {
  4813. return true;
  4814. }
  4815. // Sets the value of a parameter.
  4816. // `name` name of the parameter
  4817. // `value` new value or null if the user wishes to unset the parameter
  4818. setParameter(name, value) {
  4819. if (value != null) {
  4820. return this.params[name] = value;
  4821. } else {
  4822. return delete this.params[name];
  4823. }
  4824. }
  4825. };
  4826. // Returns the list of parameter names
  4827. Object.defineProperty(XMLDOMConfiguration.prototype, 'parameterNames', {
  4828. get: function() {
  4829. return new XMLDOMStringList(Object.keys(this.defaultParams));
  4830. }
  4831. });
  4832. return XMLDOMConfiguration;
  4833. }).call(this);
  4834. }).call(this);
  4835. },{"./XMLDOMErrorHandler":21,"./XMLDOMStringList":23}],21:[function(require,module,exports){
  4836. // Generated by CoffeeScript 2.4.1
  4837. (function() {
  4838. // Represents the error handler for DOM operations
  4839. var XMLDOMErrorHandler;
  4840. module.exports = XMLDOMErrorHandler = class XMLDOMErrorHandler {
  4841. // Initializes a new instance of `XMLDOMErrorHandler`
  4842. constructor() {}
  4843. // Called on the error handler when an error occurs.
  4844. // `error` the error message as a string
  4845. handleError(error) {
  4846. throw new Error(error);
  4847. }
  4848. };
  4849. }).call(this);
  4850. },{}],22:[function(require,module,exports){
  4851. // Generated by CoffeeScript 2.4.1
  4852. (function() {
  4853. // Implements the DOMImplementation interface
  4854. var XMLDOMImplementation;
  4855. module.exports = XMLDOMImplementation = class XMLDOMImplementation {
  4856. // Tests if the DOM implementation implements a specific feature.
  4857. // `feature` package name of the feature to test. In Level 1, the
  4858. // legal values are "HTML" and "XML" (case-insensitive).
  4859. // `version` version number of the package name to test.
  4860. // In Level 1, this is the string "1.0". If the version is
  4861. // not specified, supporting any version of the feature will
  4862. // cause the method to return true.
  4863. hasFeature(feature, version) {
  4864. return true;
  4865. }
  4866. // Creates a new document type declaration.
  4867. // `qualifiedName` qualified name of the document type to be created
  4868. // `publicId` public identifier of the external subset
  4869. // `systemId` system identifier of the external subset
  4870. createDocumentType(qualifiedName, publicId, systemId) {
  4871. throw new Error("This DOM method is not implemented.");
  4872. }
  4873. // Creates a new document.
  4874. // `namespaceURI` namespace URI of the document element to create
  4875. // `qualifiedName` the qualified name of the document to be created
  4876. // `doctype` the type of document to be created or null
  4877. createDocument(namespaceURI, qualifiedName, doctype) {
  4878. throw new Error("This DOM method is not implemented.");
  4879. }
  4880. // Creates a new HTML document.
  4881. // `title` document title
  4882. createHTMLDocument(title) {
  4883. throw new Error("This DOM method is not implemented.");
  4884. }
  4885. // Returns a specialized object which implements the specialized APIs
  4886. // of the specified feature and version.
  4887. // `feature` name of the feature requested.
  4888. // `version` version number of the feature to test
  4889. getFeature(feature, version) {
  4890. throw new Error("This DOM method is not implemented.");
  4891. }
  4892. };
  4893. }).call(this);
  4894. },{}],23:[function(require,module,exports){
  4895. // Generated by CoffeeScript 2.4.1
  4896. (function() {
  4897. // Represents a list of string entries
  4898. var XMLDOMStringList;
  4899. module.exports = XMLDOMStringList = (function() {
  4900. class XMLDOMStringList {
  4901. // Initializes a new instance of `XMLDOMStringList`
  4902. // This is just a wrapper around an ordinary
  4903. // JS array.
  4904. // `arr` the array of string values
  4905. constructor(arr) {
  4906. this.arr = arr || [];
  4907. }
  4908. // Returns the indexth item in the collection.
  4909. // `index` index into the collection
  4910. item(index) {
  4911. return this.arr[index] || null;
  4912. }
  4913. // Test if a string is part of this DOMStringList.
  4914. // `str` the string to look for
  4915. contains(str) {
  4916. return this.arr.indexOf(str) !== -1;
  4917. }
  4918. };
  4919. // Returns the number of strings in the list.
  4920. Object.defineProperty(XMLDOMStringList.prototype, 'length', {
  4921. get: function() {
  4922. return this.arr.length;
  4923. }
  4924. });
  4925. return XMLDOMStringList;
  4926. }).call(this);
  4927. }).call(this);
  4928. },{}],24:[function(require,module,exports){
  4929. // Generated by CoffeeScript 2.4.1
  4930. (function() {
  4931. var NodeType, XMLDTDAttList, XMLNode;
  4932. XMLNode = require('./XMLNode');
  4933. NodeType = require('./NodeType');
  4934. // Represents an attribute list
  4935. module.exports = XMLDTDAttList = class XMLDTDAttList extends XMLNode {
  4936. // Initializes a new instance of `XMLDTDAttList`
  4937. // `parent` the parent `XMLDocType` element
  4938. // `elementName` the name of the element containing this attribute
  4939. // `attributeName` attribute name
  4940. // `attributeType` type of the attribute
  4941. // `defaultValueType` default value type (either #REQUIRED, #IMPLIED,
  4942. // #FIXED or #DEFAULT)
  4943. // `defaultValue` default value of the attribute
  4944. // (only used for #FIXED or #DEFAULT)
  4945. constructor(parent, elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  4946. super(parent);
  4947. if (elementName == null) {
  4948. throw new Error("Missing DTD element name. " + this.debugInfo());
  4949. }
  4950. if (attributeName == null) {
  4951. throw new Error("Missing DTD attribute name. " + this.debugInfo(elementName));
  4952. }
  4953. if (!attributeType) {
  4954. throw new Error("Missing DTD attribute type. " + this.debugInfo(elementName));
  4955. }
  4956. if (!defaultValueType) {
  4957. throw new Error("Missing DTD attribute default. " + this.debugInfo(elementName));
  4958. }
  4959. if (defaultValueType.indexOf('#') !== 0) {
  4960. defaultValueType = '#' + defaultValueType;
  4961. }
  4962. if (!defaultValueType.match(/^(#REQUIRED|#IMPLIED|#FIXED|#DEFAULT)$/)) {
  4963. throw new Error("Invalid default value type; expected: #REQUIRED, #IMPLIED, #FIXED or #DEFAULT. " + this.debugInfo(elementName));
  4964. }
  4965. if (defaultValue && !defaultValueType.match(/^(#FIXED|#DEFAULT)$/)) {
  4966. throw new Error("Default value only applies to #FIXED or #DEFAULT. " + this.debugInfo(elementName));
  4967. }
  4968. this.elementName = this.stringify.name(elementName);
  4969. this.type = NodeType.AttributeDeclaration;
  4970. this.attributeName = this.stringify.name(attributeName);
  4971. this.attributeType = this.stringify.dtdAttType(attributeType);
  4972. if (defaultValue) {
  4973. this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
  4974. }
  4975. this.defaultValueType = defaultValueType;
  4976. }
  4977. // Converts the XML fragment to string
  4978. // `options.pretty` pretty prints the result
  4979. // `options.indent` indentation for pretty print
  4980. // `options.offset` how many indentations to add to every line for pretty print
  4981. // `options.newline` newline sequence for pretty print
  4982. toString(options) {
  4983. return this.options.writer.dtdAttList(this, this.options.writer.filterOptions(options));
  4984. }
  4985. };
  4986. }).call(this);
  4987. },{"./NodeType":13,"./XMLNode":35}],25:[function(require,module,exports){
  4988. // Generated by CoffeeScript 2.4.1
  4989. (function() {
  4990. var NodeType, XMLDTDElement, XMLNode;
  4991. XMLNode = require('./XMLNode');
  4992. NodeType = require('./NodeType');
  4993. // Represents an attribute
  4994. module.exports = XMLDTDElement = class XMLDTDElement extends XMLNode {
  4995. // Initializes a new instance of `XMLDTDElement`
  4996. // `parent` the parent `XMLDocType` element
  4997. // `name` element name
  4998. // `value` element content (defaults to #PCDATA)
  4999. constructor(parent, name, value) {
  5000. super(parent);
  5001. if (name == null) {
  5002. throw new Error("Missing DTD element name. " + this.debugInfo());
  5003. }
  5004. if (!value) {
  5005. value = '(#PCDATA)';
  5006. }
  5007. if (Array.isArray(value)) {
  5008. value = '(' + value.join(',') + ')';
  5009. }
  5010. this.name = this.stringify.name(name);
  5011. this.type = NodeType.ElementDeclaration;
  5012. this.value = this.stringify.dtdElementValue(value);
  5013. }
  5014. // Converts the XML fragment to string
  5015. // `options.pretty` pretty prints the result
  5016. // `options.indent` indentation for pretty print
  5017. // `options.offset` how many indentations to add to every line for pretty print
  5018. // `options.newline` newline sequence for pretty print
  5019. toString(options) {
  5020. return this.options.writer.dtdElement(this, this.options.writer.filterOptions(options));
  5021. }
  5022. };
  5023. }).call(this);
  5024. },{"./NodeType":13,"./XMLNode":35}],26:[function(require,module,exports){
  5025. // Generated by CoffeeScript 2.4.1
  5026. (function() {
  5027. var NodeType, XMLDTDEntity, XMLNode, isObject;
  5028. ({isObject} = require('./Utility'));
  5029. XMLNode = require('./XMLNode');
  5030. NodeType = require('./NodeType');
  5031. // Represents an entity declaration in the DTD
  5032. module.exports = XMLDTDEntity = (function() {
  5033. class XMLDTDEntity extends XMLNode {
  5034. // Initializes a new instance of `XMLDTDEntity`
  5035. // `parent` the parent `XMLDocType` element
  5036. // `pe` whether this is a parameter entity or a general entity
  5037. // defaults to `false` (general entity)
  5038. // `name` the name of the entity
  5039. // `value` internal entity value or an object with external entity details
  5040. // `value.pubID` public identifier
  5041. // `value.sysID` system identifier
  5042. // `value.nData` notation declaration
  5043. constructor(parent, pe, name, value) {
  5044. super(parent);
  5045. if (name == null) {
  5046. throw new Error("Missing DTD entity name. " + this.debugInfo(name));
  5047. }
  5048. if (value == null) {
  5049. throw new Error("Missing DTD entity value. " + this.debugInfo(name));
  5050. }
  5051. this.pe = !!pe;
  5052. this.name = this.stringify.name(name);
  5053. this.type = NodeType.EntityDeclaration;
  5054. if (!isObject(value)) {
  5055. this.value = this.stringify.dtdEntityValue(value);
  5056. this.internal = true;
  5057. } else {
  5058. if (!value.pubID && !value.sysID) {
  5059. throw new Error("Public and/or system identifiers are required for an external entity. " + this.debugInfo(name));
  5060. }
  5061. if (value.pubID && !value.sysID) {
  5062. throw new Error("System identifier is required for a public external entity. " + this.debugInfo(name));
  5063. }
  5064. this.internal = false;
  5065. if (value.pubID != null) {
  5066. this.pubID = this.stringify.dtdPubID(value.pubID);
  5067. }
  5068. if (value.sysID != null) {
  5069. this.sysID = this.stringify.dtdSysID(value.sysID);
  5070. }
  5071. if (value.nData != null) {
  5072. this.nData = this.stringify.dtdNData(value.nData);
  5073. }
  5074. if (this.pe && this.nData) {
  5075. throw new Error("Notation declaration is not allowed in a parameter entity. " + this.debugInfo(name));
  5076. }
  5077. }
  5078. }
  5079. // Converts the XML fragment to string
  5080. // `options.pretty` pretty prints the result
  5081. // `options.indent` indentation for pretty print
  5082. // `options.offset` how many indentations to add to every line for pretty print
  5083. // `options.newline` newline sequence for pretty print
  5084. toString(options) {
  5085. return this.options.writer.dtdEntity(this, this.options.writer.filterOptions(options));
  5086. }
  5087. };
  5088. // DOM level 1
  5089. Object.defineProperty(XMLDTDEntity.prototype, 'publicId', {
  5090. get: function() {
  5091. return this.pubID;
  5092. }
  5093. });
  5094. Object.defineProperty(XMLDTDEntity.prototype, 'systemId', {
  5095. get: function() {
  5096. return this.sysID;
  5097. }
  5098. });
  5099. Object.defineProperty(XMLDTDEntity.prototype, 'notationName', {
  5100. get: function() {
  5101. return this.nData || null;
  5102. }
  5103. });
  5104. // DOM level 3
  5105. Object.defineProperty(XMLDTDEntity.prototype, 'inputEncoding', {
  5106. get: function() {
  5107. return null;
  5108. }
  5109. });
  5110. Object.defineProperty(XMLDTDEntity.prototype, 'xmlEncoding', {
  5111. get: function() {
  5112. return null;
  5113. }
  5114. });
  5115. Object.defineProperty(XMLDTDEntity.prototype, 'xmlVersion', {
  5116. get: function() {
  5117. return null;
  5118. }
  5119. });
  5120. return XMLDTDEntity;
  5121. }).call(this);
  5122. }).call(this);
  5123. },{"./NodeType":13,"./Utility":14,"./XMLNode":35}],27:[function(require,module,exports){
  5124. // Generated by CoffeeScript 2.4.1
  5125. (function() {
  5126. var NodeType, XMLDTDNotation, XMLNode;
  5127. XMLNode = require('./XMLNode');
  5128. NodeType = require('./NodeType');
  5129. // Represents a NOTATION entry in the DTD
  5130. module.exports = XMLDTDNotation = (function() {
  5131. class XMLDTDNotation extends XMLNode {
  5132. // Initializes a new instance of `XMLDTDNotation`
  5133. // `parent` the parent `XMLDocType` element
  5134. // `name` the name of the notation
  5135. // `value` an object with external entity details
  5136. // `value.pubID` public identifier
  5137. // `value.sysID` system identifier
  5138. constructor(parent, name, value) {
  5139. super(parent);
  5140. if (name == null) {
  5141. throw new Error("Missing DTD notation name. " + this.debugInfo(name));
  5142. }
  5143. if (!value.pubID && !value.sysID) {
  5144. throw new Error("Public or system identifiers are required for an external entity. " + this.debugInfo(name));
  5145. }
  5146. this.name = this.stringify.name(name);
  5147. this.type = NodeType.NotationDeclaration;
  5148. if (value.pubID != null) {
  5149. this.pubID = this.stringify.dtdPubID(value.pubID);
  5150. }
  5151. if (value.sysID != null) {
  5152. this.sysID = this.stringify.dtdSysID(value.sysID);
  5153. }
  5154. }
  5155. // Converts the XML fragment to string
  5156. // `options.pretty` pretty prints the result
  5157. // `options.indent` indentation for pretty print
  5158. // `options.offset` how many indentations to add to every line for pretty print
  5159. // `options.newline` newline sequence for pretty print
  5160. toString(options) {
  5161. return this.options.writer.dtdNotation(this, this.options.writer.filterOptions(options));
  5162. }
  5163. };
  5164. // DOM level 1
  5165. Object.defineProperty(XMLDTDNotation.prototype, 'publicId', {
  5166. get: function() {
  5167. return this.pubID;
  5168. }
  5169. });
  5170. Object.defineProperty(XMLDTDNotation.prototype, 'systemId', {
  5171. get: function() {
  5172. return this.sysID;
  5173. }
  5174. });
  5175. return XMLDTDNotation;
  5176. }).call(this);
  5177. }).call(this);
  5178. },{"./NodeType":13,"./XMLNode":35}],28:[function(require,module,exports){
  5179. // Generated by CoffeeScript 2.4.1
  5180. (function() {
  5181. var NodeType, XMLDeclaration, XMLNode, isObject;
  5182. ({isObject} = require('./Utility'));
  5183. XMLNode = require('./XMLNode');
  5184. NodeType = require('./NodeType');
  5185. // Represents the XML declaration
  5186. module.exports = XMLDeclaration = class XMLDeclaration extends XMLNode {
  5187. // Initializes a new instance of `XMLDeclaration`
  5188. // `parent` the document object
  5189. // `version` A version number string, e.g. 1.0
  5190. // `encoding` Encoding declaration, e.g. UTF-8
  5191. // `standalone` standalone document declaration: true or false
  5192. constructor(parent, version, encoding, standalone) {
  5193. super(parent);
  5194. // arguments may also be passed as an object
  5195. if (isObject(version)) {
  5196. ({version, encoding, standalone} = version);
  5197. }
  5198. if (!version) {
  5199. version = '1.0';
  5200. }
  5201. this.type = NodeType.Declaration;
  5202. this.version = this.stringify.xmlVersion(version);
  5203. if (encoding != null) {
  5204. this.encoding = this.stringify.xmlEncoding(encoding);
  5205. }
  5206. if (standalone != null) {
  5207. this.standalone = this.stringify.xmlStandalone(standalone);
  5208. }
  5209. }
  5210. // Converts to string
  5211. // `options.pretty` pretty prints the result
  5212. // `options.indent` indentation for pretty print
  5213. // `options.offset` how many indentations to add to every line for pretty print
  5214. // `options.newline` newline sequence for pretty print
  5215. toString(options) {
  5216. return this.options.writer.declaration(this, this.options.writer.filterOptions(options));
  5217. }
  5218. };
  5219. }).call(this);
  5220. },{"./NodeType":13,"./Utility":14,"./XMLNode":35}],29:[function(require,module,exports){
  5221. // Generated by CoffeeScript 2.4.1
  5222. (function() {
  5223. var NodeType, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLNamedNodeMap, XMLNode, isObject;
  5224. ({isObject} = require('./Utility'));
  5225. XMLNode = require('./XMLNode');
  5226. NodeType = require('./NodeType');
  5227. XMLDTDAttList = require('./XMLDTDAttList');
  5228. XMLDTDEntity = require('./XMLDTDEntity');
  5229. XMLDTDElement = require('./XMLDTDElement');
  5230. XMLDTDNotation = require('./XMLDTDNotation');
  5231. XMLNamedNodeMap = require('./XMLNamedNodeMap');
  5232. // Represents doctype declaration
  5233. module.exports = XMLDocType = (function() {
  5234. class XMLDocType extends XMLNode {
  5235. // Initializes a new instance of `XMLDocType`
  5236. // `parent` the document object
  5237. // `pubID` public identifier of the external subset
  5238. // `sysID` system identifier of the external subset
  5239. constructor(parent, pubID, sysID) {
  5240. var child, i, len, ref;
  5241. super(parent);
  5242. this.type = NodeType.DocType;
  5243. // set DTD name to the name of the root node
  5244. if (parent.children) {
  5245. ref = parent.children;
  5246. for (i = 0, len = ref.length; i < len; i++) {
  5247. child = ref[i];
  5248. if (child.type === NodeType.Element) {
  5249. this.name = child.name;
  5250. break;
  5251. }
  5252. }
  5253. }
  5254. this.documentObject = parent;
  5255. // arguments may also be passed as an object
  5256. if (isObject(pubID)) {
  5257. ({pubID, sysID} = pubID);
  5258. }
  5259. if (sysID == null) {
  5260. [sysID, pubID] = [pubID, sysID];
  5261. }
  5262. if (pubID != null) {
  5263. this.pubID = this.stringify.dtdPubID(pubID);
  5264. }
  5265. if (sysID != null) {
  5266. this.sysID = this.stringify.dtdSysID(sysID);
  5267. }
  5268. }
  5269. // Creates an element type declaration
  5270. // `name` element name
  5271. // `value` element content (defaults to #PCDATA)
  5272. element(name, value) {
  5273. var child;
  5274. child = new XMLDTDElement(this, name, value);
  5275. this.children.push(child);
  5276. return this;
  5277. }
  5278. // Creates an attribute declaration
  5279. // `elementName` the name of the element containing this attribute
  5280. // `attributeName` attribute name
  5281. // `attributeType` type of the attribute (defaults to CDATA)
  5282. // `defaultValueType` default value type (either #REQUIRED, #IMPLIED, #FIXED or
  5283. // #DEFAULT) (defaults to #IMPLIED)
  5284. // `defaultValue` default value of the attribute
  5285. // (only used for #FIXED or #DEFAULT)
  5286. attList(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  5287. var child;
  5288. child = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
  5289. this.children.push(child);
  5290. return this;
  5291. }
  5292. // Creates a general entity declaration
  5293. // `name` the name of the entity
  5294. // `value` internal entity value or an object with external entity details
  5295. // `value.pubID` public identifier
  5296. // `value.sysID` system identifier
  5297. // `value.nData` notation declaration
  5298. entity(name, value) {
  5299. var child;
  5300. child = new XMLDTDEntity(this, false, name, value);
  5301. this.children.push(child);
  5302. return this;
  5303. }
  5304. // Creates a parameter entity declaration
  5305. // `name` the name of the entity
  5306. // `value` internal entity value or an object with external entity details
  5307. // `value.pubID` public identifier
  5308. // `value.sysID` system identifier
  5309. pEntity(name, value) {
  5310. var child;
  5311. child = new XMLDTDEntity(this, true, name, value);
  5312. this.children.push(child);
  5313. return this;
  5314. }
  5315. // Creates a NOTATION declaration
  5316. // `name` the name of the notation
  5317. // `value` an object with external entity details
  5318. // `value.pubID` public identifier
  5319. // `value.sysID` system identifier
  5320. notation(name, value) {
  5321. var child;
  5322. child = new XMLDTDNotation(this, name, value);
  5323. this.children.push(child);
  5324. return this;
  5325. }
  5326. // Converts to string
  5327. // `options.pretty` pretty prints the result
  5328. // `options.indent` indentation for pretty print
  5329. // `options.offset` how many indentations to add to every line for pretty print
  5330. // `options.newline` newline sequence for pretty print
  5331. toString(options) {
  5332. return this.options.writer.docType(this, this.options.writer.filterOptions(options));
  5333. }
  5334. // Aliases
  5335. ele(name, value) {
  5336. return this.element(name, value);
  5337. }
  5338. att(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  5339. return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);
  5340. }
  5341. ent(name, value) {
  5342. return this.entity(name, value);
  5343. }
  5344. pent(name, value) {
  5345. return this.pEntity(name, value);
  5346. }
  5347. not(name, value) {
  5348. return this.notation(name, value);
  5349. }
  5350. up() {
  5351. return this.root() || this.documentObject;
  5352. }
  5353. isEqualNode(node) {
  5354. if (!super.isEqualNode(node)) {
  5355. return false;
  5356. }
  5357. if (node.name !== this.name) {
  5358. return false;
  5359. }
  5360. if (node.publicId !== this.publicId) {
  5361. return false;
  5362. }
  5363. if (node.systemId !== this.systemId) {
  5364. return false;
  5365. }
  5366. return true;
  5367. }
  5368. };
  5369. // DOM level 1
  5370. Object.defineProperty(XMLDocType.prototype, 'entities', {
  5371. get: function() {
  5372. var child, i, len, nodes, ref;
  5373. nodes = {};
  5374. ref = this.children;
  5375. for (i = 0, len = ref.length; i < len; i++) {
  5376. child = ref[i];
  5377. if ((child.type === NodeType.EntityDeclaration) && !child.pe) {
  5378. nodes[child.name] = child;
  5379. }
  5380. }
  5381. return new XMLNamedNodeMap(nodes);
  5382. }
  5383. });
  5384. Object.defineProperty(XMLDocType.prototype, 'notations', {
  5385. get: function() {
  5386. var child, i, len, nodes, ref;
  5387. nodes = {};
  5388. ref = this.children;
  5389. for (i = 0, len = ref.length; i < len; i++) {
  5390. child = ref[i];
  5391. if (child.type === NodeType.NotationDeclaration) {
  5392. nodes[child.name] = child;
  5393. }
  5394. }
  5395. return new XMLNamedNodeMap(nodes);
  5396. }
  5397. });
  5398. // DOM level 2
  5399. Object.defineProperty(XMLDocType.prototype, 'publicId', {
  5400. get: function() {
  5401. return this.pubID;
  5402. }
  5403. });
  5404. Object.defineProperty(XMLDocType.prototype, 'systemId', {
  5405. get: function() {
  5406. return this.sysID;
  5407. }
  5408. });
  5409. Object.defineProperty(XMLDocType.prototype, 'internalSubset', {
  5410. get: function() {
  5411. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5412. }
  5413. });
  5414. return XMLDocType;
  5415. }).call(this);
  5416. }).call(this);
  5417. },{"./NodeType":13,"./Utility":14,"./XMLDTDAttList":24,"./XMLDTDElement":25,"./XMLDTDEntity":26,"./XMLDTDNotation":27,"./XMLNamedNodeMap":34,"./XMLNode":35}],30:[function(require,module,exports){
  5418. // Generated by CoffeeScript 2.4.1
  5419. (function() {
  5420. var NodeType, XMLDOMConfiguration, XMLDOMImplementation, XMLDocument, XMLNode, XMLStringWriter, XMLStringifier, isPlainObject;
  5421. ({isPlainObject} = require('./Utility'));
  5422. XMLDOMImplementation = require('./XMLDOMImplementation');
  5423. XMLDOMConfiguration = require('./XMLDOMConfiguration');
  5424. XMLNode = require('./XMLNode');
  5425. NodeType = require('./NodeType');
  5426. XMLStringifier = require('./XMLStringifier');
  5427. XMLStringWriter = require('./XMLStringWriter');
  5428. // Represents an XML builder
  5429. module.exports = XMLDocument = (function() {
  5430. class XMLDocument extends XMLNode {
  5431. // Initializes a new instance of `XMLDocument`
  5432. // `options.keepNullNodes` whether nodes with null values will be kept
  5433. // or ignored: true or false
  5434. // `options.keepNullAttributes` whether attributes with null values will be
  5435. // kept or ignored: true or false
  5436. // `options.ignoreDecorators` whether decorator strings will be ignored when
  5437. // converting JS objects: true or false
  5438. // `options.separateArrayItems` whether array items are created as separate
  5439. // nodes when passed as an object value: true or false
  5440. // `options.noDoubleEncoding` whether existing html entities are encoded:
  5441. // true or false
  5442. // `options.stringify` a set of functions to use for converting values to
  5443. // strings
  5444. // `options.writer` the default XML writer to use for converting nodes to
  5445. // string. If the default writer is not set, the built-in XMLStringWriter
  5446. // will be used instead.
  5447. constructor(options) {
  5448. super(null);
  5449. this.name = "#document";
  5450. this.type = NodeType.Document;
  5451. this.documentURI = null;
  5452. this.domConfig = new XMLDOMConfiguration();
  5453. options || (options = {});
  5454. if (!options.writer) {
  5455. options.writer = new XMLStringWriter();
  5456. }
  5457. this.options = options;
  5458. this.stringify = new XMLStringifier(options);
  5459. }
  5460. // Ends the document and passes it to the given XML writer
  5461. // `writer` is either an XML writer or a plain object to pass to the
  5462. // constructor of the default XML writer. The default writer is assigned when
  5463. // creating the XML document. Following flags are recognized by the
  5464. // built-in XMLStringWriter:
  5465. // `writer.pretty` pretty prints the result
  5466. // `writer.indent` indentation for pretty print
  5467. // `writer.offset` how many indentations to add to every line for pretty print
  5468. // `writer.newline` newline sequence for pretty print
  5469. end(writer) {
  5470. var writerOptions;
  5471. writerOptions = {};
  5472. if (!writer) {
  5473. writer = this.options.writer;
  5474. } else if (isPlainObject(writer)) {
  5475. writerOptions = writer;
  5476. writer = this.options.writer;
  5477. }
  5478. return writer.document(this, writer.filterOptions(writerOptions));
  5479. }
  5480. // Converts the XML document to string
  5481. // `options.pretty` pretty prints the result
  5482. // `options.indent` indentation for pretty print
  5483. // `options.offset` how many indentations to add to every line for pretty print
  5484. // `options.newline` newline sequence for pretty print
  5485. toString(options) {
  5486. return this.options.writer.document(this, this.options.writer.filterOptions(options));
  5487. }
  5488. // DOM level 1 functions to be implemented later
  5489. createElement(tagName) {
  5490. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5491. }
  5492. createDocumentFragment() {
  5493. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5494. }
  5495. createTextNode(data) {
  5496. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5497. }
  5498. createComment(data) {
  5499. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5500. }
  5501. createCDATASection(data) {
  5502. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5503. }
  5504. createProcessingInstruction(target, data) {
  5505. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5506. }
  5507. createAttribute(name) {
  5508. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5509. }
  5510. createEntityReference(name) {
  5511. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5512. }
  5513. getElementsByTagName(tagname) {
  5514. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5515. }
  5516. // DOM level 2 functions to be implemented later
  5517. importNode(importedNode, deep) {
  5518. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5519. }
  5520. createElementNS(namespaceURI, qualifiedName) {
  5521. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5522. }
  5523. createAttributeNS(namespaceURI, qualifiedName) {
  5524. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5525. }
  5526. getElementsByTagNameNS(namespaceURI, localName) {
  5527. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5528. }
  5529. getElementById(elementId) {
  5530. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5531. }
  5532. // DOM level 3 functions to be implemented later
  5533. adoptNode(source) {
  5534. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5535. }
  5536. normalizeDocument() {
  5537. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5538. }
  5539. renameNode(node, namespaceURI, qualifiedName) {
  5540. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5541. }
  5542. // DOM level 4 functions to be implemented later
  5543. getElementsByClassName(classNames) {
  5544. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5545. }
  5546. createEvent(eventInterface) {
  5547. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5548. }
  5549. createRange() {
  5550. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5551. }
  5552. createNodeIterator(root, whatToShow, filter) {
  5553. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5554. }
  5555. createTreeWalker(root, whatToShow, filter) {
  5556. throw new Error("This DOM method is not implemented." + this.debugInfo());
  5557. }
  5558. };
  5559. // DOM level 1
  5560. Object.defineProperty(XMLDocument.prototype, 'implementation', {
  5561. value: new XMLDOMImplementation()
  5562. });
  5563. Object.defineProperty(XMLDocument.prototype, 'doctype', {
  5564. get: function() {
  5565. var child, i, len, ref;
  5566. ref = this.children;
  5567. for (i = 0, len = ref.length; i < len; i++) {
  5568. child = ref[i];
  5569. if (child.type === NodeType.DocType) {
  5570. return child;
  5571. }
  5572. }
  5573. return null;
  5574. }
  5575. });
  5576. Object.defineProperty(XMLDocument.prototype, 'documentElement', {
  5577. get: function() {
  5578. return this.rootObject || null;
  5579. }
  5580. });
  5581. // DOM level 3
  5582. Object.defineProperty(XMLDocument.prototype, 'inputEncoding', {
  5583. get: function() {
  5584. return null;
  5585. }
  5586. });
  5587. Object.defineProperty(XMLDocument.prototype, 'strictErrorChecking', {
  5588. get: function() {
  5589. return false;
  5590. }
  5591. });
  5592. Object.defineProperty(XMLDocument.prototype, 'xmlEncoding', {
  5593. get: function() {
  5594. if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
  5595. return this.children[0].encoding;
  5596. } else {
  5597. return null;
  5598. }
  5599. }
  5600. });
  5601. Object.defineProperty(XMLDocument.prototype, 'xmlStandalone', {
  5602. get: function() {
  5603. if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
  5604. return this.children[0].standalone === 'yes';
  5605. } else {
  5606. return false;
  5607. }
  5608. }
  5609. });
  5610. Object.defineProperty(XMLDocument.prototype, 'xmlVersion', {
  5611. get: function() {
  5612. if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
  5613. return this.children[0].version;
  5614. } else {
  5615. return "1.0";
  5616. }
  5617. }
  5618. });
  5619. // DOM level 4
  5620. Object.defineProperty(XMLDocument.prototype, 'URL', {
  5621. get: function() {
  5622. return this.documentURI;
  5623. }
  5624. });
  5625. Object.defineProperty(XMLDocument.prototype, 'origin', {
  5626. get: function() {
  5627. return null;
  5628. }
  5629. });
  5630. Object.defineProperty(XMLDocument.prototype, 'compatMode', {
  5631. get: function() {
  5632. return null;
  5633. }
  5634. });
  5635. Object.defineProperty(XMLDocument.prototype, 'characterSet', {
  5636. get: function() {
  5637. return null;
  5638. }
  5639. });
  5640. Object.defineProperty(XMLDocument.prototype, 'contentType', {
  5641. get: function() {
  5642. return null;
  5643. }
  5644. });
  5645. return XMLDocument;
  5646. }).call(this);
  5647. }).call(this);
  5648. },{"./NodeType":13,"./Utility":14,"./XMLDOMConfiguration":20,"./XMLDOMImplementation":22,"./XMLNode":35,"./XMLStringWriter":40,"./XMLStringifier":41}],31:[function(require,module,exports){
  5649. // Generated by CoffeeScript 2.4.1
  5650. (function() {
  5651. var NodeType, WriterState, XMLAttribute, XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDocument, XMLDocumentCB, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLStringifier, XMLText, getValue, isFunction, isObject, isPlainObject,
  5652. hasProp = {}.hasOwnProperty;
  5653. ({isObject, isFunction, isPlainObject, getValue} = require('./Utility'));
  5654. NodeType = require('./NodeType');
  5655. XMLDocument = require('./XMLDocument');
  5656. XMLElement = require('./XMLElement');
  5657. XMLCData = require('./XMLCData');
  5658. XMLComment = require('./XMLComment');
  5659. XMLRaw = require('./XMLRaw');
  5660. XMLText = require('./XMLText');
  5661. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  5662. XMLDeclaration = require('./XMLDeclaration');
  5663. XMLDocType = require('./XMLDocType');
  5664. XMLDTDAttList = require('./XMLDTDAttList');
  5665. XMLDTDEntity = require('./XMLDTDEntity');
  5666. XMLDTDElement = require('./XMLDTDElement');
  5667. XMLDTDNotation = require('./XMLDTDNotation');
  5668. XMLAttribute = require('./XMLAttribute');
  5669. XMLStringifier = require('./XMLStringifier');
  5670. XMLStringWriter = require('./XMLStringWriter');
  5671. WriterState = require('./WriterState');
  5672. // Represents an XML builder
  5673. module.exports = XMLDocumentCB = class XMLDocumentCB {
  5674. // Initializes a new instance of `XMLDocumentCB`
  5675. // `options.keepNullNodes` whether nodes with null values will be kept
  5676. // or ignored: true or false
  5677. // `options.keepNullAttributes` whether attributes with null values will be
  5678. // kept or ignored: true or false
  5679. // `options.ignoreDecorators` whether decorator strings will be ignored when
  5680. // converting JS objects: true or false
  5681. // `options.separateArrayItems` whether array items are created as separate
  5682. // nodes when passed as an object value: true or false
  5683. // `options.noDoubleEncoding` whether existing html entities are encoded:
  5684. // true or false
  5685. // `options.stringify` a set of functions to use for converting values to
  5686. // strings
  5687. // `options.writer` the default XML writer to use for converting nodes to
  5688. // string. If the default writer is not set, the built-in XMLStringWriter
  5689. // will be used instead.
  5690. // `onData` the function to be called when a new chunk of XML is output. The
  5691. // string containing the XML chunk is passed to `onData` as its first
  5692. // argument, and the current indentation level as its second argument.
  5693. // `onEnd` the function to be called when the XML document is completed with
  5694. // `end`. `onEnd` does not receive any arguments.
  5695. constructor(options, onData, onEnd) {
  5696. var writerOptions;
  5697. this.name = "?xml";
  5698. this.type = NodeType.Document;
  5699. options || (options = {});
  5700. writerOptions = {};
  5701. if (!options.writer) {
  5702. options.writer = new XMLStringWriter();
  5703. } else if (isPlainObject(options.writer)) {
  5704. writerOptions = options.writer;
  5705. options.writer = new XMLStringWriter();
  5706. }
  5707. this.options = options;
  5708. this.writer = options.writer;
  5709. this.writerOptions = this.writer.filterOptions(writerOptions);
  5710. this.stringify = new XMLStringifier(options);
  5711. this.onDataCallback = onData || function() {};
  5712. this.onEndCallback = onEnd || function() {};
  5713. this.currentNode = null;
  5714. this.currentLevel = -1;
  5715. this.openTags = {};
  5716. this.documentStarted = false;
  5717. this.documentCompleted = false;
  5718. this.root = null;
  5719. }
  5720. // Creates a child element node from the given XMLNode
  5721. // `node` the child node
  5722. createChildNode(node) {
  5723. var att, attName, attributes, child, i, len, ref, ref1;
  5724. switch (node.type) {
  5725. case NodeType.CData:
  5726. this.cdata(node.value);
  5727. break;
  5728. case NodeType.Comment:
  5729. this.comment(node.value);
  5730. break;
  5731. case NodeType.Element:
  5732. attributes = {};
  5733. ref = node.attribs;
  5734. for (attName in ref) {
  5735. if (!hasProp.call(ref, attName)) continue;
  5736. att = ref[attName];
  5737. attributes[attName] = att.value;
  5738. }
  5739. this.node(node.name, attributes);
  5740. break;
  5741. case NodeType.Dummy:
  5742. this.dummy();
  5743. break;
  5744. case NodeType.Raw:
  5745. this.raw(node.value);
  5746. break;
  5747. case NodeType.Text:
  5748. this.text(node.value);
  5749. break;
  5750. case NodeType.ProcessingInstruction:
  5751. this.instruction(node.target, node.value);
  5752. break;
  5753. default:
  5754. throw new Error("This XML node type is not supported in a JS object: " + node.constructor.name);
  5755. }
  5756. ref1 = node.children;
  5757. // write child nodes recursively
  5758. for (i = 0, len = ref1.length; i < len; i++) {
  5759. child = ref1[i];
  5760. this.createChildNode(child);
  5761. if (child.type === NodeType.Element) {
  5762. this.up();
  5763. }
  5764. }
  5765. return this;
  5766. }
  5767. // Creates a dummy node
  5768. dummy() {
  5769. // no-op, just return this
  5770. return this;
  5771. }
  5772. // Creates a node
  5773. // `name` name of the node
  5774. // `attributes` an object containing name/value pairs of attributes
  5775. // `text` element text
  5776. node(name, attributes, text) {
  5777. if (name == null) {
  5778. throw new Error("Missing node name.");
  5779. }
  5780. if (this.root && this.currentLevel === -1) {
  5781. throw new Error("Document can only have one root node. " + this.debugInfo(name));
  5782. }
  5783. this.openCurrent();
  5784. name = getValue(name);
  5785. if (attributes == null) {
  5786. attributes = {};
  5787. }
  5788. attributes = getValue(attributes);
  5789. // swap argument order: text <-> attributes
  5790. if (!isObject(attributes)) {
  5791. [text, attributes] = [attributes, text];
  5792. }
  5793. this.currentNode = new XMLElement(this, name, attributes);
  5794. this.currentNode.children = false;
  5795. this.currentLevel++;
  5796. this.openTags[this.currentLevel] = this.currentNode;
  5797. if (text != null) {
  5798. this.text(text);
  5799. }
  5800. return this;
  5801. }
  5802. // Creates a child element node or an element type declaration when called
  5803. // inside the DTD
  5804. // `name` name of the node
  5805. // `attributes` an object containing name/value pairs of attributes
  5806. // `text` element text
  5807. element(name, attributes, text) {
  5808. var child, i, len, oldValidationFlag, ref, root;
  5809. if (this.currentNode && this.currentNode.type === NodeType.DocType) {
  5810. this.dtdElement(...arguments);
  5811. } else {
  5812. if (Array.isArray(name) || isObject(name) || isFunction(name)) {
  5813. oldValidationFlag = this.options.noValidation;
  5814. this.options.noValidation = true;
  5815. root = new XMLDocument(this.options).element('TEMP_ROOT');
  5816. root.element(name);
  5817. this.options.noValidation = oldValidationFlag;
  5818. ref = root.children;
  5819. for (i = 0, len = ref.length; i < len; i++) {
  5820. child = ref[i];
  5821. this.createChildNode(child);
  5822. if (child.type === NodeType.Element) {
  5823. this.up();
  5824. }
  5825. }
  5826. } else {
  5827. this.node(name, attributes, text);
  5828. }
  5829. }
  5830. return this;
  5831. }
  5832. // Adds or modifies an attribute
  5833. // `name` attribute name
  5834. // `value` attribute value
  5835. attribute(name, value) {
  5836. var attName, attValue;
  5837. if (!this.currentNode || this.currentNode.children) {
  5838. throw new Error("att() can only be used immediately after an ele() call in callback mode. " + this.debugInfo(name));
  5839. }
  5840. if (name != null) {
  5841. name = getValue(name);
  5842. }
  5843. if (isObject(name)) { // expand if object
  5844. for (attName in name) {
  5845. if (!hasProp.call(name, attName)) continue;
  5846. attValue = name[attName];
  5847. this.attribute(attName, attValue);
  5848. }
  5849. } else {
  5850. if (isFunction(value)) {
  5851. value = value.apply();
  5852. }
  5853. if (this.options.keepNullAttributes && (value == null)) {
  5854. this.currentNode.attribs[name] = new XMLAttribute(this, name, "");
  5855. } else if (value != null) {
  5856. this.currentNode.attribs[name] = new XMLAttribute(this, name, value);
  5857. }
  5858. }
  5859. return this;
  5860. }
  5861. // Creates a text node
  5862. // `value` element text
  5863. text(value) {
  5864. var node;
  5865. this.openCurrent();
  5866. node = new XMLText(this, value);
  5867. this.onData(this.writer.text(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5868. return this;
  5869. }
  5870. // Creates a CDATA node
  5871. // `value` element text without CDATA delimiters
  5872. cdata(value) {
  5873. var node;
  5874. this.openCurrent();
  5875. node = new XMLCData(this, value);
  5876. this.onData(this.writer.cdata(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5877. return this;
  5878. }
  5879. // Creates a comment node
  5880. // `value` comment text
  5881. comment(value) {
  5882. var node;
  5883. this.openCurrent();
  5884. node = new XMLComment(this, value);
  5885. this.onData(this.writer.comment(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5886. return this;
  5887. }
  5888. // Adds unescaped raw text
  5889. // `value` text
  5890. raw(value) {
  5891. var node;
  5892. this.openCurrent();
  5893. node = new XMLRaw(this, value);
  5894. this.onData(this.writer.raw(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5895. return this;
  5896. }
  5897. // Adds a processing instruction
  5898. // `target` instruction target
  5899. // `value` instruction value
  5900. instruction(target, value) {
  5901. var i, insTarget, insValue, len, node;
  5902. this.openCurrent();
  5903. if (target != null) {
  5904. target = getValue(target);
  5905. }
  5906. if (value != null) {
  5907. value = getValue(value);
  5908. }
  5909. if (Array.isArray(target)) { // expand if array
  5910. for (i = 0, len = target.length; i < len; i++) {
  5911. insTarget = target[i];
  5912. this.instruction(insTarget);
  5913. }
  5914. } else if (isObject(target)) { // expand if object
  5915. for (insTarget in target) {
  5916. if (!hasProp.call(target, insTarget)) continue;
  5917. insValue = target[insTarget];
  5918. this.instruction(insTarget, insValue);
  5919. }
  5920. } else {
  5921. if (isFunction(value)) {
  5922. value = value.apply();
  5923. }
  5924. node = new XMLProcessingInstruction(this, target, value);
  5925. this.onData(this.writer.processingInstruction(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5926. }
  5927. return this;
  5928. }
  5929. // Creates the xml declaration
  5930. // `version` A version number string, e.g. 1.0
  5931. // `encoding` Encoding declaration, e.g. UTF-8
  5932. // `standalone` standalone document declaration: true or false
  5933. declaration(version, encoding, standalone) {
  5934. var node;
  5935. this.openCurrent();
  5936. if (this.documentStarted) {
  5937. throw new Error("declaration() must be the first node.");
  5938. }
  5939. node = new XMLDeclaration(this, version, encoding, standalone);
  5940. this.onData(this.writer.declaration(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5941. return this;
  5942. }
  5943. // Creates the document type declaration
  5944. // `root` the name of the root node
  5945. // `pubID` the public identifier of the external subset
  5946. // `sysID` the system identifier of the external subset
  5947. doctype(root, pubID, sysID) {
  5948. this.openCurrent();
  5949. if (root == null) {
  5950. throw new Error("Missing root node name.");
  5951. }
  5952. if (this.root) {
  5953. throw new Error("dtd() must come before the root node.");
  5954. }
  5955. this.currentNode = new XMLDocType(this, pubID, sysID);
  5956. this.currentNode.rootNodeName = root;
  5957. this.currentNode.children = false;
  5958. this.currentLevel++;
  5959. this.openTags[this.currentLevel] = this.currentNode;
  5960. return this;
  5961. }
  5962. // Creates an element type declaration
  5963. // `name` element name
  5964. // `value` element content (defaults to #PCDATA)
  5965. dtdElement(name, value) {
  5966. var node;
  5967. this.openCurrent();
  5968. node = new XMLDTDElement(this, name, value);
  5969. this.onData(this.writer.dtdElement(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5970. return this;
  5971. }
  5972. // Creates an attribute declaration
  5973. // `elementName` the name of the element containing this attribute
  5974. // `attributeName` attribute name
  5975. // `attributeType` type of the attribute (defaults to CDATA)
  5976. // `defaultValueType` default value type (either #REQUIRED, #IMPLIED, #FIXED or
  5977. // #DEFAULT) (defaults to #IMPLIED)
  5978. // `defaultValue` default value of the attribute
  5979. // (only used for #FIXED or #DEFAULT)
  5980. attList(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  5981. var node;
  5982. this.openCurrent();
  5983. node = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
  5984. this.onData(this.writer.dtdAttList(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5985. return this;
  5986. }
  5987. // Creates a general entity declaration
  5988. // `name` the name of the entity
  5989. // `value` internal entity value or an object with external entity details
  5990. // `value.pubID` public identifier
  5991. // `value.sysID` system identifier
  5992. // `value.nData` notation declaration
  5993. entity(name, value) {
  5994. var node;
  5995. this.openCurrent();
  5996. node = new XMLDTDEntity(this, false, name, value);
  5997. this.onData(this.writer.dtdEntity(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  5998. return this;
  5999. }
  6000. // Creates a parameter entity declaration
  6001. // `name` the name of the entity
  6002. // `value` internal entity value or an object with external entity details
  6003. // `value.pubID` public identifier
  6004. // `value.sysID` system identifier
  6005. pEntity(name, value) {
  6006. var node;
  6007. this.openCurrent();
  6008. node = new XMLDTDEntity(this, true, name, value);
  6009. this.onData(this.writer.dtdEntity(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  6010. return this;
  6011. }
  6012. // Creates a NOTATION declaration
  6013. // `name` the name of the notation
  6014. // `value` an object with external entity details
  6015. // `value.pubID` public identifier
  6016. // `value.sysID` system identifier
  6017. notation(name, value) {
  6018. var node;
  6019. this.openCurrent();
  6020. node = new XMLDTDNotation(this, name, value);
  6021. this.onData(this.writer.dtdNotation(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
  6022. return this;
  6023. }
  6024. // Gets the parent node
  6025. up() {
  6026. if (this.currentLevel < 0) {
  6027. throw new Error("The document node has no parent.");
  6028. }
  6029. if (this.currentNode) {
  6030. if (this.currentNode.children) {
  6031. this.closeNode(this.currentNode);
  6032. } else {
  6033. this.openNode(this.currentNode);
  6034. }
  6035. this.currentNode = null;
  6036. } else {
  6037. this.closeNode(this.openTags[this.currentLevel]);
  6038. }
  6039. delete this.openTags[this.currentLevel];
  6040. this.currentLevel--;
  6041. return this;
  6042. }
  6043. // Ends the document
  6044. end() {
  6045. while (this.currentLevel >= 0) {
  6046. this.up();
  6047. }
  6048. return this.onEnd();
  6049. }
  6050. // Opens the current parent node
  6051. openCurrent() {
  6052. if (this.currentNode) {
  6053. this.currentNode.children = true;
  6054. return this.openNode(this.currentNode);
  6055. }
  6056. }
  6057. // Writes the opening tag of the current node or the entire node if it has
  6058. // no child nodes
  6059. openNode(node) {
  6060. var att, chunk, name, ref;
  6061. if (!node.isOpen) {
  6062. if (!this.root && this.currentLevel === 0 && node.type === NodeType.Element) {
  6063. this.root = node;
  6064. }
  6065. chunk = '';
  6066. if (node.type === NodeType.Element) {
  6067. this.writerOptions.state = WriterState.OpenTag;
  6068. chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + '<' + node.name;
  6069. ref = node.attribs;
  6070. for (name in ref) {
  6071. if (!hasProp.call(ref, name)) continue;
  6072. att = ref[name];
  6073. chunk += this.writer.attribute(att, this.writerOptions, this.currentLevel);
  6074. }
  6075. chunk += (node.children ? '>' : '/>') + this.writer.endline(node, this.writerOptions, this.currentLevel);
  6076. this.writerOptions.state = WriterState.InsideTag; // if node.type is NodeType.DocType
  6077. } else {
  6078. this.writerOptions.state = WriterState.OpenTag;
  6079. chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + '<!DOCTYPE ' + node.rootNodeName;
  6080. // external identifier
  6081. if (node.pubID && node.sysID) {
  6082. chunk += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  6083. } else if (node.sysID) {
  6084. chunk += ' SYSTEM "' + node.sysID + '"';
  6085. }
  6086. // internal subset
  6087. if (node.children) {
  6088. chunk += ' [';
  6089. this.writerOptions.state = WriterState.InsideTag;
  6090. } else {
  6091. this.writerOptions.state = WriterState.CloseTag;
  6092. chunk += '>';
  6093. }
  6094. chunk += this.writer.endline(node, this.writerOptions, this.currentLevel);
  6095. }
  6096. this.onData(chunk, this.currentLevel);
  6097. return node.isOpen = true;
  6098. }
  6099. }
  6100. // Writes the closing tag of the current node
  6101. closeNode(node) {
  6102. var chunk;
  6103. if (!node.isClosed) {
  6104. chunk = '';
  6105. this.writerOptions.state = WriterState.CloseTag;
  6106. if (node.type === NodeType.Element) {
  6107. chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + '</' + node.name + '>' + this.writer.endline(node, this.writerOptions, this.currentLevel); // if node.type is NodeType.DocType
  6108. } else {
  6109. chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + ']>' + this.writer.endline(node, this.writerOptions, this.currentLevel);
  6110. }
  6111. this.writerOptions.state = WriterState.None;
  6112. this.onData(chunk, this.currentLevel);
  6113. return node.isClosed = true;
  6114. }
  6115. }
  6116. // Called when a new chunk of XML is output
  6117. // `chunk` a string containing the XML chunk
  6118. // `level` current indentation level
  6119. onData(chunk, level) {
  6120. this.documentStarted = true;
  6121. return this.onDataCallback(chunk, level + 1);
  6122. }
  6123. // Called when the XML document is completed
  6124. onEnd() {
  6125. this.documentCompleted = true;
  6126. return this.onEndCallback();
  6127. }
  6128. // Returns debug string
  6129. debugInfo(name) {
  6130. if (name == null) {
  6131. return "";
  6132. } else {
  6133. return "node: <" + name + ">";
  6134. }
  6135. }
  6136. // Node aliases
  6137. ele() {
  6138. return this.element(...arguments);
  6139. }
  6140. nod(name, attributes, text) {
  6141. return this.node(name, attributes, text);
  6142. }
  6143. txt(value) {
  6144. return this.text(value);
  6145. }
  6146. dat(value) {
  6147. return this.cdata(value);
  6148. }
  6149. com(value) {
  6150. return this.comment(value);
  6151. }
  6152. ins(target, value) {
  6153. return this.instruction(target, value);
  6154. }
  6155. dec(version, encoding, standalone) {
  6156. return this.declaration(version, encoding, standalone);
  6157. }
  6158. dtd(root, pubID, sysID) {
  6159. return this.doctype(root, pubID, sysID);
  6160. }
  6161. e(name, attributes, text) {
  6162. return this.element(name, attributes, text);
  6163. }
  6164. n(name, attributes, text) {
  6165. return this.node(name, attributes, text);
  6166. }
  6167. t(value) {
  6168. return this.text(value);
  6169. }
  6170. d(value) {
  6171. return this.cdata(value);
  6172. }
  6173. c(value) {
  6174. return this.comment(value);
  6175. }
  6176. r(value) {
  6177. return this.raw(value);
  6178. }
  6179. i(target, value) {
  6180. return this.instruction(target, value);
  6181. }
  6182. // Attribute aliases
  6183. att() {
  6184. if (this.currentNode && this.currentNode.type === NodeType.DocType) {
  6185. return this.attList(...arguments);
  6186. } else {
  6187. return this.attribute(...arguments);
  6188. }
  6189. }
  6190. a() {
  6191. if (this.currentNode && this.currentNode.type === NodeType.DocType) {
  6192. return this.attList(...arguments);
  6193. } else {
  6194. return this.attribute(...arguments);
  6195. }
  6196. }
  6197. // DTD aliases
  6198. // att() and ele() are defined above
  6199. ent(name, value) {
  6200. return this.entity(name, value);
  6201. }
  6202. pent(name, value) {
  6203. return this.pEntity(name, value);
  6204. }
  6205. not(name, value) {
  6206. return this.notation(name, value);
  6207. }
  6208. };
  6209. }).call(this);
  6210. },{"./NodeType":13,"./Utility":14,"./WriterState":15,"./XMLAttribute":16,"./XMLCData":17,"./XMLComment":19,"./XMLDTDAttList":24,"./XMLDTDElement":25,"./XMLDTDEntity":26,"./XMLDTDNotation":27,"./XMLDeclaration":28,"./XMLDocType":29,"./XMLDocument":30,"./XMLElement":33,"./XMLProcessingInstruction":37,"./XMLRaw":38,"./XMLStringWriter":40,"./XMLStringifier":41,"./XMLText":42}],32:[function(require,module,exports){
  6211. // Generated by CoffeeScript 2.4.1
  6212. (function() {
  6213. var NodeType, XMLDummy, XMLNode;
  6214. XMLNode = require('./XMLNode');
  6215. NodeType = require('./NodeType');
  6216. // Represents a raw node
  6217. module.exports = XMLDummy = class XMLDummy extends XMLNode {
  6218. // Initializes a new instance of `XMLDummy`
  6219. // `XMLDummy` is a special node representing a node with
  6220. // a null value. Dummy nodes are created while recursively
  6221. // building the XML tree. Simply skipping null values doesn't
  6222. // work because that would break the recursive chain.
  6223. constructor(parent) {
  6224. super(parent);
  6225. this.type = NodeType.Dummy;
  6226. }
  6227. // Creates and returns a deep clone of `this`
  6228. clone() {
  6229. return Object.create(this);
  6230. }
  6231. // Converts the XML fragment to string
  6232. // `options.pretty` pretty prints the result
  6233. // `options.indent` indentation for pretty print
  6234. // `options.offset` how many indentations to add to every line for pretty print
  6235. // `options.newline` newline sequence for pretty print
  6236. toString(options) {
  6237. return '';
  6238. }
  6239. };
  6240. }).call(this);
  6241. },{"./NodeType":13,"./XMLNode":35}],33:[function(require,module,exports){
  6242. // Generated by CoffeeScript 2.4.1
  6243. (function() {
  6244. var NodeType, XMLAttribute, XMLElement, XMLNamedNodeMap, XMLNode, getValue, isFunction, isObject,
  6245. hasProp = {}.hasOwnProperty;
  6246. ({isObject, isFunction, getValue} = require('./Utility'));
  6247. XMLNode = require('./XMLNode');
  6248. NodeType = require('./NodeType');
  6249. XMLAttribute = require('./XMLAttribute');
  6250. XMLNamedNodeMap = require('./XMLNamedNodeMap');
  6251. // Represents an element of the XML document
  6252. module.exports = XMLElement = (function() {
  6253. class XMLElement extends XMLNode {
  6254. // Initializes a new instance of `XMLElement`
  6255. // `parent` the parent node
  6256. // `name` element name
  6257. // `attributes` an object containing name/value pairs of attributes
  6258. constructor(parent, name, attributes) {
  6259. var child, j, len, ref;
  6260. super(parent);
  6261. if (name == null) {
  6262. throw new Error("Missing element name. " + this.debugInfo());
  6263. }
  6264. this.name = this.stringify.name(name);
  6265. this.type = NodeType.Element;
  6266. this.attribs = {};
  6267. this.schemaTypeInfo = null;
  6268. if (attributes != null) {
  6269. this.attribute(attributes);
  6270. }
  6271. // set properties if this is the root node
  6272. if (parent.type === NodeType.Document) {
  6273. this.isRoot = true;
  6274. this.documentObject = parent;
  6275. parent.rootObject = this;
  6276. // set dtd name
  6277. if (parent.children) {
  6278. ref = parent.children;
  6279. for (j = 0, len = ref.length; j < len; j++) {
  6280. child = ref[j];
  6281. if (child.type === NodeType.DocType) {
  6282. child.name = this.name;
  6283. break;
  6284. }
  6285. }
  6286. }
  6287. }
  6288. }
  6289. // Creates and returns a deep clone of `this`
  6290. clone() {
  6291. var att, attName, clonedSelf, ref;
  6292. clonedSelf = Object.create(this);
  6293. // remove document element
  6294. if (clonedSelf.isRoot) {
  6295. clonedSelf.documentObject = null;
  6296. }
  6297. // clone attributes
  6298. clonedSelf.attribs = {};
  6299. ref = this.attribs;
  6300. for (attName in ref) {
  6301. if (!hasProp.call(ref, attName)) continue;
  6302. att = ref[attName];
  6303. clonedSelf.attribs[attName] = att.clone();
  6304. }
  6305. // clone child nodes
  6306. clonedSelf.children = [];
  6307. this.children.forEach(function(child) {
  6308. var clonedChild;
  6309. clonedChild = child.clone();
  6310. clonedChild.parent = clonedSelf;
  6311. return clonedSelf.children.push(clonedChild);
  6312. });
  6313. return clonedSelf;
  6314. }
  6315. // Adds or modifies an attribute
  6316. // `name` attribute name
  6317. // `value` attribute value
  6318. attribute(name, value) {
  6319. var attName, attValue;
  6320. if (name != null) {
  6321. name = getValue(name);
  6322. }
  6323. if (isObject(name)) { // expand if object
  6324. for (attName in name) {
  6325. if (!hasProp.call(name, attName)) continue;
  6326. attValue = name[attName];
  6327. this.attribute(attName, attValue);
  6328. }
  6329. } else {
  6330. if (isFunction(value)) {
  6331. value = value.apply();
  6332. }
  6333. if (this.options.keepNullAttributes && (value == null)) {
  6334. this.attribs[name] = new XMLAttribute(this, name, "");
  6335. } else if (value != null) {
  6336. this.attribs[name] = new XMLAttribute(this, name, value);
  6337. }
  6338. }
  6339. return this;
  6340. }
  6341. // Removes an attribute
  6342. // `name` attribute name
  6343. removeAttribute(name) {
  6344. var attName, j, len;
  6345. // Also defined in DOM level 1
  6346. // removeAttribute(name) removes an attribute by name.
  6347. if (name == null) {
  6348. throw new Error("Missing attribute name. " + this.debugInfo());
  6349. }
  6350. name = getValue(name);
  6351. if (Array.isArray(name)) { // expand if array
  6352. for (j = 0, len = name.length; j < len; j++) {
  6353. attName = name[j];
  6354. delete this.attribs[attName];
  6355. }
  6356. } else {
  6357. delete this.attribs[name];
  6358. }
  6359. return this;
  6360. }
  6361. // Converts the XML fragment to string
  6362. // `options.pretty` pretty prints the result
  6363. // `options.indent` indentation for pretty print
  6364. // `options.offset` how many indentations to add to every line for pretty print
  6365. // `options.newline` newline sequence for pretty print
  6366. // `options.allowEmpty` do not self close empty element tags
  6367. toString(options) {
  6368. return this.options.writer.element(this, this.options.writer.filterOptions(options));
  6369. }
  6370. // Aliases
  6371. att(name, value) {
  6372. return this.attribute(name, value);
  6373. }
  6374. a(name, value) {
  6375. return this.attribute(name, value);
  6376. }
  6377. // DOM Level 1
  6378. getAttribute(name) {
  6379. if (this.attribs.hasOwnProperty(name)) {
  6380. return this.attribs[name].value;
  6381. } else {
  6382. return null;
  6383. }
  6384. }
  6385. setAttribute(name, value) {
  6386. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6387. }
  6388. getAttributeNode(name) {
  6389. if (this.attribs.hasOwnProperty(name)) {
  6390. return this.attribs[name];
  6391. } else {
  6392. return null;
  6393. }
  6394. }
  6395. setAttributeNode(newAttr) {
  6396. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6397. }
  6398. removeAttributeNode(oldAttr) {
  6399. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6400. }
  6401. getElementsByTagName(name) {
  6402. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6403. }
  6404. // DOM Level 2
  6405. getAttributeNS(namespaceURI, localName) {
  6406. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6407. }
  6408. setAttributeNS(namespaceURI, qualifiedName, value) {
  6409. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6410. }
  6411. removeAttributeNS(namespaceURI, localName) {
  6412. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6413. }
  6414. getAttributeNodeNS(namespaceURI, localName) {
  6415. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6416. }
  6417. setAttributeNodeNS(newAttr) {
  6418. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6419. }
  6420. getElementsByTagNameNS(namespaceURI, localName) {
  6421. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6422. }
  6423. hasAttribute(name) {
  6424. return this.attribs.hasOwnProperty(name);
  6425. }
  6426. hasAttributeNS(namespaceURI, localName) {
  6427. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6428. }
  6429. // DOM Level 3
  6430. setIdAttribute(name, isId) {
  6431. if (this.attribs.hasOwnProperty(name)) {
  6432. return this.attribs[name].isId;
  6433. } else {
  6434. return isId;
  6435. }
  6436. }
  6437. setIdAttributeNS(namespaceURI, localName, isId) {
  6438. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6439. }
  6440. setIdAttributeNode(idAttr, isId) {
  6441. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6442. }
  6443. // DOM Level 4
  6444. getElementsByTagName(tagname) {
  6445. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6446. }
  6447. getElementsByTagNameNS(namespaceURI, localName) {
  6448. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6449. }
  6450. getElementsByClassName(classNames) {
  6451. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6452. }
  6453. isEqualNode(node) {
  6454. var i, j, ref;
  6455. if (!super.isEqualNode(node)) {
  6456. return false;
  6457. }
  6458. if (node.namespaceURI !== this.namespaceURI) {
  6459. return false;
  6460. }
  6461. if (node.prefix !== this.prefix) {
  6462. return false;
  6463. }
  6464. if (node.localName !== this.localName) {
  6465. return false;
  6466. }
  6467. if (node.attribs.length !== this.attribs.length) {
  6468. return false;
  6469. }
  6470. for (i = j = 0, ref = this.attribs.length - 1; (0 <= ref ? j <= ref : j >= ref); i = 0 <= ref ? ++j : --j) {
  6471. if (!this.attribs[i].isEqualNode(node.attribs[i])) {
  6472. return false;
  6473. }
  6474. }
  6475. return true;
  6476. }
  6477. };
  6478. // DOM level 1
  6479. Object.defineProperty(XMLElement.prototype, 'tagName', {
  6480. get: function() {
  6481. return this.name;
  6482. }
  6483. });
  6484. // DOM level 4
  6485. Object.defineProperty(XMLElement.prototype, 'namespaceURI', {
  6486. get: function() {
  6487. return '';
  6488. }
  6489. });
  6490. Object.defineProperty(XMLElement.prototype, 'prefix', {
  6491. get: function() {
  6492. return '';
  6493. }
  6494. });
  6495. Object.defineProperty(XMLElement.prototype, 'localName', {
  6496. get: function() {
  6497. return this.name;
  6498. }
  6499. });
  6500. Object.defineProperty(XMLElement.prototype, 'id', {
  6501. get: function() {
  6502. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6503. }
  6504. });
  6505. Object.defineProperty(XMLElement.prototype, 'className', {
  6506. get: function() {
  6507. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6508. }
  6509. });
  6510. Object.defineProperty(XMLElement.prototype, 'classList', {
  6511. get: function() {
  6512. throw new Error("This DOM method is not implemented." + this.debugInfo());
  6513. }
  6514. });
  6515. Object.defineProperty(XMLElement.prototype, 'attributes', {
  6516. get: function() {
  6517. if (!this.attributeMap || !this.attributeMap.nodes) {
  6518. this.attributeMap = new XMLNamedNodeMap(this.attribs);
  6519. }
  6520. return this.attributeMap;
  6521. }
  6522. });
  6523. return XMLElement;
  6524. }).call(this);
  6525. }).call(this);
  6526. },{"./NodeType":13,"./Utility":14,"./XMLAttribute":16,"./XMLNamedNodeMap":34,"./XMLNode":35}],34:[function(require,module,exports){
  6527. // Generated by CoffeeScript 2.4.1
  6528. (function() {
  6529. // Represents a map of nodes accessed by a string key
  6530. var XMLNamedNodeMap;
  6531. module.exports = XMLNamedNodeMap = (function() {
  6532. class XMLNamedNodeMap {
  6533. // Initializes a new instance of `XMLNamedNodeMap`
  6534. // This is just a wrapper around an ordinary
  6535. // JS object.
  6536. // `nodes` the object containing nodes.
  6537. constructor(nodes) {
  6538. this.nodes = nodes;
  6539. }
  6540. // Creates and returns a deep clone of `this`
  6541. clone() {
  6542. // this class should not be cloned since it wraps
  6543. // around a given object. The calling function should check
  6544. // whether the wrapped object is null and supply a new object
  6545. // (from the clone).
  6546. return this.nodes = null;
  6547. }
  6548. // DOM Level 1
  6549. getNamedItem(name) {
  6550. return this.nodes[name];
  6551. }
  6552. setNamedItem(node) {
  6553. var oldNode;
  6554. oldNode = this.nodes[node.nodeName];
  6555. this.nodes[node.nodeName] = node;
  6556. return oldNode || null;
  6557. }
  6558. removeNamedItem(name) {
  6559. var oldNode;
  6560. oldNode = this.nodes[name];
  6561. delete this.nodes[name];
  6562. return oldNode || null;
  6563. }
  6564. item(index) {
  6565. return this.nodes[Object.keys(this.nodes)[index]] || null;
  6566. }
  6567. // DOM level 2 functions to be implemented later
  6568. getNamedItemNS(namespaceURI, localName) {
  6569. throw new Error("This DOM method is not implemented.");
  6570. }
  6571. setNamedItemNS(node) {
  6572. throw new Error("This DOM method is not implemented.");
  6573. }
  6574. removeNamedItemNS(namespaceURI, localName) {
  6575. throw new Error("This DOM method is not implemented.");
  6576. }
  6577. };
  6578. // DOM level 1
  6579. Object.defineProperty(XMLNamedNodeMap.prototype, 'length', {
  6580. get: function() {
  6581. return Object.keys(this.nodes).length || 0;
  6582. }
  6583. });
  6584. return XMLNamedNodeMap;
  6585. }).call(this);
  6586. }).call(this);
  6587. },{}],35:[function(require,module,exports){
  6588. // Generated by CoffeeScript 2.4.1
  6589. (function() {
  6590. var DocumentPosition, NodeType, XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLNamedNodeMap, XMLNode, XMLNodeList, XMLProcessingInstruction, XMLRaw, XMLText, getValue, isEmpty, isFunction, isObject,
  6591. hasProp = {}.hasOwnProperty,
  6592. splice = [].splice;
  6593. ({isObject, isFunction, isEmpty, getValue} = require('./Utility'));
  6594. XMLElement = null;
  6595. XMLCData = null;
  6596. XMLComment = null;
  6597. XMLDeclaration = null;
  6598. XMLDocType = null;
  6599. XMLRaw = null;
  6600. XMLText = null;
  6601. XMLProcessingInstruction = null;
  6602. XMLDummy = null;
  6603. NodeType = null;
  6604. XMLNodeList = null;
  6605. XMLNamedNodeMap = null;
  6606. DocumentPosition = null;
  6607. // Represents a generic XMl element
  6608. module.exports = XMLNode = (function() {
  6609. class XMLNode {
  6610. // Initializes a new instance of `XMLNode`
  6611. // `parent` the parent node
  6612. constructor(parent1) {
  6613. this.parent = parent1;
  6614. if (this.parent) {
  6615. this.options = this.parent.options;
  6616. this.stringify = this.parent.stringify;
  6617. }
  6618. this.value = null;
  6619. this.children = [];
  6620. this.baseURI = null;
  6621. // first execution, load dependencies that are otherwise
  6622. // circular (so we can't load them at the top)
  6623. if (!XMLElement) {
  6624. XMLElement = require('./XMLElement');
  6625. XMLCData = require('./XMLCData');
  6626. XMLComment = require('./XMLComment');
  6627. XMLDeclaration = require('./XMLDeclaration');
  6628. XMLDocType = require('./XMLDocType');
  6629. XMLRaw = require('./XMLRaw');
  6630. XMLText = require('./XMLText');
  6631. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  6632. XMLDummy = require('./XMLDummy');
  6633. NodeType = require('./NodeType');
  6634. XMLNodeList = require('./XMLNodeList');
  6635. XMLNamedNodeMap = require('./XMLNamedNodeMap');
  6636. DocumentPosition = require('./DocumentPosition');
  6637. }
  6638. }
  6639. // Sets the parent node of this node and its children recursively
  6640. // `parent` the parent node
  6641. setParent(parent) {
  6642. var child, j, len, ref1, results;
  6643. this.parent = parent;
  6644. if (parent) {
  6645. this.options = parent.options;
  6646. this.stringify = parent.stringify;
  6647. }
  6648. ref1 = this.children;
  6649. results = [];
  6650. for (j = 0, len = ref1.length; j < len; j++) {
  6651. child = ref1[j];
  6652. results.push(child.setParent(this));
  6653. }
  6654. return results;
  6655. }
  6656. // Creates a child element node
  6657. // `name` node name or an object describing the XML tree
  6658. // `attributes` an object containing name/value pairs of attributes
  6659. // `text` element text
  6660. element(name, attributes, text) {
  6661. var childNode, item, j, k, key, lastChild, len, len1, val;
  6662. lastChild = null;
  6663. if (attributes === null && (text == null)) {
  6664. [attributes, text] = [{}, null];
  6665. }
  6666. if (attributes == null) {
  6667. attributes = {};
  6668. }
  6669. attributes = getValue(attributes);
  6670. // swap argument order: text <-> attributes
  6671. if (!isObject(attributes)) {
  6672. [text, attributes] = [attributes, text];
  6673. }
  6674. if (name != null) {
  6675. name = getValue(name);
  6676. }
  6677. // expand if array
  6678. if (Array.isArray(name)) {
  6679. for (j = 0, len = name.length; j < len; j++) {
  6680. item = name[j];
  6681. lastChild = this.element(item);
  6682. }
  6683. // evaluate if function
  6684. } else if (isFunction(name)) {
  6685. lastChild = this.element(name.apply());
  6686. // expand if object
  6687. } else if (isObject(name)) {
  6688. for (key in name) {
  6689. if (!hasProp.call(name, key)) continue;
  6690. val = name[key];
  6691. if (isFunction(val)) {
  6692. // evaluate if function
  6693. val = val.apply();
  6694. }
  6695. // assign attributes
  6696. if (!this.options.ignoreDecorators && this.stringify.convertAttKey && key.indexOf(this.stringify.convertAttKey) === 0) {
  6697. lastChild = this.attribute(key.substr(this.stringify.convertAttKey.length), val);
  6698. // skip empty arrays
  6699. } else if (!this.options.separateArrayItems && Array.isArray(val) && isEmpty(val)) {
  6700. lastChild = this.dummy();
  6701. // empty objects produce one node
  6702. } else if (isObject(val) && isEmpty(val)) {
  6703. lastChild = this.element(key);
  6704. // skip null and undefined nodes
  6705. } else if (!this.options.keepNullNodes && (val == null)) {
  6706. lastChild = this.dummy();
  6707. // expand list by creating child nodes
  6708. } else if (!this.options.separateArrayItems && Array.isArray(val)) {
  6709. for (k = 0, len1 = val.length; k < len1; k++) {
  6710. item = val[k];
  6711. childNode = {};
  6712. childNode[key] = item;
  6713. lastChild = this.element(childNode);
  6714. }
  6715. // expand child nodes under parent
  6716. } else if (isObject(val)) {
  6717. // if the key is #text expand child nodes under this node to support mixed content
  6718. if (!this.options.ignoreDecorators && this.stringify.convertTextKey && key.indexOf(this.stringify.convertTextKey) === 0) {
  6719. lastChild = this.element(val);
  6720. } else {
  6721. lastChild = this.element(key);
  6722. lastChild.element(val);
  6723. }
  6724. } else {
  6725. // text node
  6726. lastChild = this.element(key, val);
  6727. }
  6728. }
  6729. // skip null nodes
  6730. } else if (!this.options.keepNullNodes && text === null) {
  6731. lastChild = this.dummy();
  6732. } else {
  6733. // text node
  6734. if (!this.options.ignoreDecorators && this.stringify.convertTextKey && name.indexOf(this.stringify.convertTextKey) === 0) {
  6735. lastChild = this.text(text);
  6736. // cdata node
  6737. } else if (!this.options.ignoreDecorators && this.stringify.convertCDataKey && name.indexOf(this.stringify.convertCDataKey) === 0) {
  6738. lastChild = this.cdata(text);
  6739. // comment node
  6740. } else if (!this.options.ignoreDecorators && this.stringify.convertCommentKey && name.indexOf(this.stringify.convertCommentKey) === 0) {
  6741. lastChild = this.comment(text);
  6742. // raw text node
  6743. } else if (!this.options.ignoreDecorators && this.stringify.convertRawKey && name.indexOf(this.stringify.convertRawKey) === 0) {
  6744. lastChild = this.raw(text);
  6745. // processing instruction
  6746. } else if (!this.options.ignoreDecorators && this.stringify.convertPIKey && name.indexOf(this.stringify.convertPIKey) === 0) {
  6747. lastChild = this.instruction(name.substr(this.stringify.convertPIKey.length), text);
  6748. } else {
  6749. // element node
  6750. lastChild = this.node(name, attributes, text);
  6751. }
  6752. }
  6753. if (lastChild == null) {
  6754. throw new Error("Could not create any elements with: " + name + ". " + this.debugInfo());
  6755. }
  6756. return lastChild;
  6757. }
  6758. // Creates a child element node before the current node
  6759. // `name` node name or an object describing the XML tree
  6760. // `attributes` an object containing name/value pairs of attributes
  6761. // `text` element text
  6762. insertBefore(name, attributes, text) {
  6763. var child, i, newChild, refChild, removed;
  6764. // DOM level 1
  6765. // insertBefore(newChild, refChild) inserts the child node newChild before refChild
  6766. if (name != null ? name.type : void 0) {
  6767. newChild = name;
  6768. refChild = attributes;
  6769. newChild.setParent(this);
  6770. if (refChild) {
  6771. // temporarily remove children starting *with* refChild
  6772. i = children.indexOf(refChild);
  6773. removed = children.splice(i);
  6774. // add the new child
  6775. children.push(newChild);
  6776. // add back removed children after new child
  6777. Array.prototype.push.apply(children, removed);
  6778. } else {
  6779. children.push(newChild);
  6780. }
  6781. return newChild;
  6782. } else {
  6783. if (this.isRoot) {
  6784. throw new Error("Cannot insert elements at root level. " + this.debugInfo(name));
  6785. }
  6786. // temporarily remove children starting *with* this
  6787. i = this.parent.children.indexOf(this);
  6788. removed = this.parent.children.splice(i);
  6789. // add the new child
  6790. child = this.parent.element(name, attributes, text);
  6791. // add back removed children after new child
  6792. Array.prototype.push.apply(this.parent.children, removed);
  6793. return child;
  6794. }
  6795. }
  6796. // Creates a child element node after the current node
  6797. // `name` node name or an object describing the XML tree
  6798. // `attributes` an object containing name/value pairs of attributes
  6799. // `text` element text
  6800. insertAfter(name, attributes, text) {
  6801. var child, i, removed;
  6802. if (this.isRoot) {
  6803. throw new Error("Cannot insert elements at root level. " + this.debugInfo(name));
  6804. }
  6805. // temporarily remove children starting *after* this
  6806. i = this.parent.children.indexOf(this);
  6807. removed = this.parent.children.splice(i + 1);
  6808. // add the new child
  6809. child = this.parent.element(name, attributes, text);
  6810. // add back removed children after new child
  6811. Array.prototype.push.apply(this.parent.children, removed);
  6812. return child;
  6813. }
  6814. // Deletes a child element node
  6815. remove() {
  6816. var i, ref1;
  6817. if (this.isRoot) {
  6818. throw new Error("Cannot remove the root element. " + this.debugInfo());
  6819. }
  6820. i = this.parent.children.indexOf(this);
  6821. splice.apply(this.parent.children, [i, i - i + 1].concat(ref1 = [])), ref1;
  6822. return this.parent;
  6823. }
  6824. // Creates a node
  6825. // `name` name of the node
  6826. // `attributes` an object containing name/value pairs of attributes
  6827. // `text` element text
  6828. node(name, attributes, text) {
  6829. var child;
  6830. if (name != null) {
  6831. name = getValue(name);
  6832. }
  6833. attributes || (attributes = {});
  6834. attributes = getValue(attributes);
  6835. // swap argument order: text <-> attributes
  6836. if (!isObject(attributes)) {
  6837. [text, attributes] = [attributes, text];
  6838. }
  6839. child = new XMLElement(this, name, attributes);
  6840. if (text != null) {
  6841. child.text(text);
  6842. }
  6843. this.children.push(child);
  6844. return child;
  6845. }
  6846. // Creates a text node
  6847. // `value` element text
  6848. text(value) {
  6849. var child;
  6850. if (isObject(value)) {
  6851. this.element(value);
  6852. }
  6853. child = new XMLText(this, value);
  6854. this.children.push(child);
  6855. return this;
  6856. }
  6857. // Creates a CDATA node
  6858. // `value` element text without CDATA delimiters
  6859. cdata(value) {
  6860. var child;
  6861. child = new XMLCData(this, value);
  6862. this.children.push(child);
  6863. return this;
  6864. }
  6865. // Creates a comment node
  6866. // `value` comment text
  6867. comment(value) {
  6868. var child;
  6869. child = new XMLComment(this, value);
  6870. this.children.push(child);
  6871. return this;
  6872. }
  6873. // Creates a comment node before the current node
  6874. // `value` comment text
  6875. commentBefore(value) {
  6876. var child, i, removed;
  6877. // temporarily remove children starting *with* this
  6878. i = this.parent.children.indexOf(this);
  6879. removed = this.parent.children.splice(i);
  6880. // add the new child
  6881. child = this.parent.comment(value);
  6882. // add back removed children after new child
  6883. Array.prototype.push.apply(this.parent.children, removed);
  6884. return this;
  6885. }
  6886. // Creates a comment node after the current node
  6887. // `value` comment text
  6888. commentAfter(value) {
  6889. var child, i, removed;
  6890. // temporarily remove children starting *after* this
  6891. i = this.parent.children.indexOf(this);
  6892. removed = this.parent.children.splice(i + 1);
  6893. // add the new child
  6894. child = this.parent.comment(value);
  6895. // add back removed children after new child
  6896. Array.prototype.push.apply(this.parent.children, removed);
  6897. return this;
  6898. }
  6899. // Adds unescaped raw text
  6900. // `value` text
  6901. raw(value) {
  6902. var child;
  6903. child = new XMLRaw(this, value);
  6904. this.children.push(child);
  6905. return this;
  6906. }
  6907. // Adds a dummy node
  6908. dummy() {
  6909. var child;
  6910. child = new XMLDummy(this);
  6911. // Normally when a new node is created it is added to the child node collection.
  6912. // However, dummy nodes are never added to the XML tree. They are created while
  6913. // converting JS objects to XML nodes in order not to break the recursive function
  6914. // chain. They can be thought of as invisible nodes. They can be traversed through
  6915. // by using prev(), next(), up(), etc. functions but they do not exists in the tree.
  6916. // @children.push child
  6917. return child;
  6918. }
  6919. // Adds a processing instruction
  6920. // `target` instruction target
  6921. // `value` instruction value
  6922. instruction(target, value) {
  6923. var insTarget, insValue, instruction, j, len;
  6924. if (target != null) {
  6925. target = getValue(target);
  6926. }
  6927. if (value != null) {
  6928. value = getValue(value);
  6929. }
  6930. if (Array.isArray(target)) { // expand if array
  6931. for (j = 0, len = target.length; j < len; j++) {
  6932. insTarget = target[j];
  6933. this.instruction(insTarget);
  6934. }
  6935. } else if (isObject(target)) { // expand if object
  6936. for (insTarget in target) {
  6937. if (!hasProp.call(target, insTarget)) continue;
  6938. insValue = target[insTarget];
  6939. this.instruction(insTarget, insValue);
  6940. }
  6941. } else {
  6942. if (isFunction(value)) {
  6943. value = value.apply();
  6944. }
  6945. instruction = new XMLProcessingInstruction(this, target, value);
  6946. this.children.push(instruction);
  6947. }
  6948. return this;
  6949. }
  6950. // Creates a processing instruction node before the current node
  6951. // `target` instruction target
  6952. // `value` instruction value
  6953. instructionBefore(target, value) {
  6954. var child, i, removed;
  6955. // temporarily remove children starting *with* this
  6956. i = this.parent.children.indexOf(this);
  6957. removed = this.parent.children.splice(i);
  6958. // add the new child
  6959. child = this.parent.instruction(target, value);
  6960. // add back removed children after new child
  6961. Array.prototype.push.apply(this.parent.children, removed);
  6962. return this;
  6963. }
  6964. // Creates a processing instruction node after the current node
  6965. // `target` instruction target
  6966. // `value` instruction value
  6967. instructionAfter(target, value) {
  6968. var child, i, removed;
  6969. // temporarily remove children starting *after* this
  6970. i = this.parent.children.indexOf(this);
  6971. removed = this.parent.children.splice(i + 1);
  6972. // add the new child
  6973. child = this.parent.instruction(target, value);
  6974. // add back removed children after new child
  6975. Array.prototype.push.apply(this.parent.children, removed);
  6976. return this;
  6977. }
  6978. // Creates the xml declaration
  6979. // `version` A version number string, e.g. 1.0
  6980. // `encoding` Encoding declaration, e.g. UTF-8
  6981. // `standalone` standalone document declaration: true or false
  6982. declaration(version, encoding, standalone) {
  6983. var doc, xmldec;
  6984. doc = this.document();
  6985. xmldec = new XMLDeclaration(doc, version, encoding, standalone);
  6986. // Replace XML declaration if exists, otherwise insert at top
  6987. if (doc.children.length === 0) {
  6988. doc.children.unshift(xmldec);
  6989. } else if (doc.children[0].type === NodeType.Declaration) {
  6990. doc.children[0] = xmldec;
  6991. } else {
  6992. doc.children.unshift(xmldec);
  6993. }
  6994. return doc.root() || doc;
  6995. }
  6996. // Creates the document type declaration
  6997. // `pubID` the public identifier of the external subset
  6998. // `sysID` the system identifier of the external subset
  6999. dtd(pubID, sysID) {
  7000. var child, doc, doctype, i, j, k, len, len1, ref1, ref2;
  7001. doc = this.document();
  7002. doctype = new XMLDocType(doc, pubID, sysID);
  7003. ref1 = doc.children;
  7004. // Replace DTD if exists
  7005. for (i = j = 0, len = ref1.length; j < len; i = ++j) {
  7006. child = ref1[i];
  7007. if (child.type === NodeType.DocType) {
  7008. doc.children[i] = doctype;
  7009. return doctype;
  7010. }
  7011. }
  7012. ref2 = doc.children;
  7013. // insert before root node if the root node exists
  7014. for (i = k = 0, len1 = ref2.length; k < len1; i = ++k) {
  7015. child = ref2[i];
  7016. if (child.isRoot) {
  7017. doc.children.splice(i, 0, doctype);
  7018. return doctype;
  7019. }
  7020. }
  7021. // otherwise append to end
  7022. doc.children.push(doctype);
  7023. return doctype;
  7024. }
  7025. // Gets the parent node
  7026. up() {
  7027. if (this.isRoot) {
  7028. throw new Error("The root node has no parent. Use doc() if you need to get the document object.");
  7029. }
  7030. return this.parent;
  7031. }
  7032. // Gets the root node
  7033. root() {
  7034. var node;
  7035. node = this;
  7036. while (node) {
  7037. if (node.type === NodeType.Document) {
  7038. return node.rootObject;
  7039. } else if (node.isRoot) {
  7040. return node;
  7041. } else {
  7042. node = node.parent;
  7043. }
  7044. }
  7045. }
  7046. // Gets the node representing the XML document
  7047. document() {
  7048. var node;
  7049. node = this;
  7050. while (node) {
  7051. if (node.type === NodeType.Document) {
  7052. return node;
  7053. } else {
  7054. node = node.parent;
  7055. }
  7056. }
  7057. }
  7058. // Ends the document and converts string
  7059. end(options) {
  7060. return this.document().end(options);
  7061. }
  7062. // Gets the previous node
  7063. prev() {
  7064. var i;
  7065. i = this.parent.children.indexOf(this);
  7066. if (i < 1) {
  7067. throw new Error("Already at the first node. " + this.debugInfo());
  7068. }
  7069. return this.parent.children[i - 1];
  7070. }
  7071. // Gets the next node
  7072. next() {
  7073. var i;
  7074. i = this.parent.children.indexOf(this);
  7075. if (i === -1 || i === this.parent.children.length - 1) {
  7076. throw new Error("Already at the last node. " + this.debugInfo());
  7077. }
  7078. return this.parent.children[i + 1];
  7079. }
  7080. // Imports cloned root from another XML document
  7081. // `doc` the XML document to insert nodes from
  7082. importDocument(doc) {
  7083. var child, clonedRoot, j, len, ref1;
  7084. clonedRoot = doc.root().clone();
  7085. clonedRoot.parent = this;
  7086. clonedRoot.isRoot = false;
  7087. this.children.push(clonedRoot);
  7088. // set properties if imported element becomes the root node
  7089. if (this.type === NodeType.Document) {
  7090. clonedRoot.isRoot = true;
  7091. clonedRoot.documentObject = this;
  7092. this.rootObject = clonedRoot;
  7093. // set dtd name
  7094. if (this.children) {
  7095. ref1 = this.children;
  7096. for (j = 0, len = ref1.length; j < len; j++) {
  7097. child = ref1[j];
  7098. if (child.type === NodeType.DocType) {
  7099. child.name = clonedRoot.name;
  7100. break;
  7101. }
  7102. }
  7103. }
  7104. }
  7105. return this;
  7106. }
  7107. // Returns debug string for this node
  7108. debugInfo(name) {
  7109. var ref1, ref2;
  7110. name = name || this.name;
  7111. if ((name == null) && !((ref1 = this.parent) != null ? ref1.name : void 0)) {
  7112. return "";
  7113. } else if (name == null) {
  7114. return "parent: <" + this.parent.name + ">";
  7115. } else if (!((ref2 = this.parent) != null ? ref2.name : void 0)) {
  7116. return "node: <" + name + ">";
  7117. } else {
  7118. return "node: <" + name + ">, parent: <" + this.parent.name + ">";
  7119. }
  7120. }
  7121. // Aliases
  7122. ele(name, attributes, text) {
  7123. return this.element(name, attributes, text);
  7124. }
  7125. nod(name, attributes, text) {
  7126. return this.node(name, attributes, text);
  7127. }
  7128. txt(value) {
  7129. return this.text(value);
  7130. }
  7131. dat(value) {
  7132. return this.cdata(value);
  7133. }
  7134. com(value) {
  7135. return this.comment(value);
  7136. }
  7137. ins(target, value) {
  7138. return this.instruction(target, value);
  7139. }
  7140. doc() {
  7141. return this.document();
  7142. }
  7143. dec(version, encoding, standalone) {
  7144. return this.declaration(version, encoding, standalone);
  7145. }
  7146. e(name, attributes, text) {
  7147. return this.element(name, attributes, text);
  7148. }
  7149. n(name, attributes, text) {
  7150. return this.node(name, attributes, text);
  7151. }
  7152. t(value) {
  7153. return this.text(value);
  7154. }
  7155. d(value) {
  7156. return this.cdata(value);
  7157. }
  7158. c(value) {
  7159. return this.comment(value);
  7160. }
  7161. r(value) {
  7162. return this.raw(value);
  7163. }
  7164. i(target, value) {
  7165. return this.instruction(target, value);
  7166. }
  7167. u() {
  7168. return this.up();
  7169. }
  7170. // can be deprecated in a future release
  7171. importXMLBuilder(doc) {
  7172. return this.importDocument(doc);
  7173. }
  7174. // Adds or modifies an attribute.
  7175. // `name` attribute name
  7176. // `value` attribute value
  7177. attribute(name, value) {
  7178. throw new Error("attribute() applies to element nodes only.");
  7179. }
  7180. att(name, value) {
  7181. return this.attribute(name, value);
  7182. }
  7183. a(name, value) {
  7184. return this.attribute(name, value);
  7185. }
  7186. // Removes an attribute
  7187. // `name` attribute name
  7188. removeAttribute(name) {
  7189. throw new Error("attribute() applies to element nodes only.");
  7190. }
  7191. // DOM level 1 functions to be implemented later
  7192. replaceChild(newChild, oldChild) {
  7193. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7194. }
  7195. removeChild(oldChild) {
  7196. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7197. }
  7198. appendChild(newChild) {
  7199. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7200. }
  7201. hasChildNodes() {
  7202. return this.children.length !== 0;
  7203. }
  7204. cloneNode(deep) {
  7205. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7206. }
  7207. normalize() {
  7208. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7209. }
  7210. // DOM level 2
  7211. isSupported(feature, version) {
  7212. return true;
  7213. }
  7214. hasAttributes() {
  7215. return this.attribs.length !== 0;
  7216. }
  7217. // DOM level 3 functions to be implemented later
  7218. compareDocumentPosition(other) {
  7219. var ref, res;
  7220. ref = this;
  7221. if (ref === other) {
  7222. return 0;
  7223. } else if (this.document() !== other.document()) {
  7224. res = DocumentPosition.Disconnected | DocumentPosition.ImplementationSpecific;
  7225. if (Math.random() < 0.5) {
  7226. res |= DocumentPosition.Preceding;
  7227. } else {
  7228. res |= DocumentPosition.Following;
  7229. }
  7230. return res;
  7231. } else if (ref.isAncestor(other)) {
  7232. return DocumentPosition.Contains | DocumentPosition.Preceding;
  7233. } else if (ref.isDescendant(other)) {
  7234. return DocumentPosition.Contains | DocumentPosition.Following;
  7235. } else if (ref.isPreceding(other)) {
  7236. return DocumentPosition.Preceding;
  7237. } else {
  7238. return DocumentPosition.Following;
  7239. }
  7240. }
  7241. isSameNode(other) {
  7242. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7243. }
  7244. lookupPrefix(namespaceURI) {
  7245. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7246. }
  7247. isDefaultNamespace(namespaceURI) {
  7248. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7249. }
  7250. lookupNamespaceURI(prefix) {
  7251. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7252. }
  7253. isEqualNode(node) {
  7254. var i, j, ref1;
  7255. if (node.nodeType !== this.nodeType) {
  7256. return false;
  7257. }
  7258. if (node.children.length !== this.children.length) {
  7259. return false;
  7260. }
  7261. for (i = j = 0, ref1 = this.children.length - 1; (0 <= ref1 ? j <= ref1 : j >= ref1); i = 0 <= ref1 ? ++j : --j) {
  7262. if (!this.children[i].isEqualNode(node.children[i])) {
  7263. return false;
  7264. }
  7265. }
  7266. return true;
  7267. }
  7268. getFeature(feature, version) {
  7269. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7270. }
  7271. setUserData(key, data, handler) {
  7272. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7273. }
  7274. getUserData(key) {
  7275. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7276. }
  7277. // Returns true if other is an inclusive descendant of node,
  7278. // and false otherwise.
  7279. contains(other) {
  7280. if (!other) {
  7281. return false;
  7282. }
  7283. return other === this || this.isDescendant(other);
  7284. }
  7285. // An object A is called a descendant of an object B, if either A is
  7286. // a child of B or A is a child of an object C that is a descendant of B.
  7287. isDescendant(node) {
  7288. var child, isDescendantChild, j, len, ref1;
  7289. ref1 = this.children;
  7290. for (j = 0, len = ref1.length; j < len; j++) {
  7291. child = ref1[j];
  7292. if (node === child) {
  7293. return true;
  7294. }
  7295. isDescendantChild = child.isDescendant(node);
  7296. if (isDescendantChild) {
  7297. return true;
  7298. }
  7299. }
  7300. return false;
  7301. }
  7302. // An object A is called an ancestor of an object B if and only if
  7303. // B is a descendant of A.
  7304. isAncestor(node) {
  7305. return node.isDescendant(this);
  7306. }
  7307. // An object A is preceding an object B if A and B are in the
  7308. // same tree and A comes before B in tree order.
  7309. isPreceding(node) {
  7310. var nodePos, thisPos;
  7311. nodePos = this.treePosition(node);
  7312. thisPos = this.treePosition(this);
  7313. if (nodePos === -1 || thisPos === -1) {
  7314. return false;
  7315. } else {
  7316. return nodePos < thisPos;
  7317. }
  7318. }
  7319. // An object A is folllowing an object B if A and B are in the
  7320. // same tree and A comes after B in tree order.
  7321. isFollowing(node) {
  7322. var nodePos, thisPos;
  7323. nodePos = this.treePosition(node);
  7324. thisPos = this.treePosition(this);
  7325. if (nodePos === -1 || thisPos === -1) {
  7326. return false;
  7327. } else {
  7328. return nodePos > thisPos;
  7329. }
  7330. }
  7331. // Returns the preorder position of the given node in the tree, or -1
  7332. // if the node is not in the tree.
  7333. treePosition(node) {
  7334. var found, pos;
  7335. pos = 0;
  7336. found = false;
  7337. this.foreachTreeNode(this.document(), function(childNode) {
  7338. pos++;
  7339. if (!found && childNode === node) {
  7340. return found = true;
  7341. }
  7342. });
  7343. if (found) {
  7344. return pos;
  7345. } else {
  7346. return -1;
  7347. }
  7348. }
  7349. // Depth-first preorder traversal through the XML tree
  7350. foreachTreeNode(node, func) {
  7351. var child, j, len, ref1, res;
  7352. node || (node = this.document());
  7353. ref1 = node.children;
  7354. for (j = 0, len = ref1.length; j < len; j++) {
  7355. child = ref1[j];
  7356. if (res = func(child)) {
  7357. return res;
  7358. } else {
  7359. res = this.foreachTreeNode(child, func);
  7360. if (res) {
  7361. return res;
  7362. }
  7363. }
  7364. }
  7365. }
  7366. };
  7367. // DOM level 1
  7368. Object.defineProperty(XMLNode.prototype, 'nodeName', {
  7369. get: function() {
  7370. return this.name;
  7371. }
  7372. });
  7373. Object.defineProperty(XMLNode.prototype, 'nodeType', {
  7374. get: function() {
  7375. return this.type;
  7376. }
  7377. });
  7378. Object.defineProperty(XMLNode.prototype, 'nodeValue', {
  7379. get: function() {
  7380. return this.value;
  7381. }
  7382. });
  7383. Object.defineProperty(XMLNode.prototype, 'parentNode', {
  7384. get: function() {
  7385. return this.parent;
  7386. }
  7387. });
  7388. Object.defineProperty(XMLNode.prototype, 'childNodes', {
  7389. get: function() {
  7390. if (!this.childNodeList || !this.childNodeList.nodes) {
  7391. this.childNodeList = new XMLNodeList(this.children);
  7392. }
  7393. return this.childNodeList;
  7394. }
  7395. });
  7396. Object.defineProperty(XMLNode.prototype, 'firstChild', {
  7397. get: function() {
  7398. return this.children[0] || null;
  7399. }
  7400. });
  7401. Object.defineProperty(XMLNode.prototype, 'lastChild', {
  7402. get: function() {
  7403. return this.children[this.children.length - 1] || null;
  7404. }
  7405. });
  7406. Object.defineProperty(XMLNode.prototype, 'previousSibling', {
  7407. get: function() {
  7408. var i;
  7409. i = this.parent.children.indexOf(this);
  7410. return this.parent.children[i - 1] || null;
  7411. }
  7412. });
  7413. Object.defineProperty(XMLNode.prototype, 'nextSibling', {
  7414. get: function() {
  7415. var i;
  7416. i = this.parent.children.indexOf(this);
  7417. return this.parent.children[i + 1] || null;
  7418. }
  7419. });
  7420. Object.defineProperty(XMLNode.prototype, 'ownerDocument', {
  7421. get: function() {
  7422. return this.document() || null;
  7423. }
  7424. });
  7425. // DOM level 3
  7426. Object.defineProperty(XMLNode.prototype, 'textContent', {
  7427. get: function() {
  7428. var child, j, len, ref1, str;
  7429. if (this.nodeType === NodeType.Element || this.nodeType === NodeType.DocumentFragment) {
  7430. str = '';
  7431. ref1 = this.children;
  7432. for (j = 0, len = ref1.length; j < len; j++) {
  7433. child = ref1[j];
  7434. if (child.textContent) {
  7435. str += child.textContent;
  7436. }
  7437. }
  7438. return str;
  7439. } else {
  7440. return null;
  7441. }
  7442. },
  7443. set: function(value) {
  7444. throw new Error("This DOM method is not implemented." + this.debugInfo());
  7445. }
  7446. });
  7447. return XMLNode;
  7448. }).call(this);
  7449. }).call(this);
  7450. },{"./DocumentPosition":12,"./NodeType":13,"./Utility":14,"./XMLCData":17,"./XMLComment":19,"./XMLDeclaration":28,"./XMLDocType":29,"./XMLDummy":32,"./XMLElement":33,"./XMLNamedNodeMap":34,"./XMLNodeList":36,"./XMLProcessingInstruction":37,"./XMLRaw":38,"./XMLText":42}],36:[function(require,module,exports){
  7451. // Generated by CoffeeScript 2.4.1
  7452. (function() {
  7453. // Represents a list of nodes
  7454. var XMLNodeList;
  7455. module.exports = XMLNodeList = (function() {
  7456. class XMLNodeList {
  7457. // Initializes a new instance of `XMLNodeList`
  7458. // This is just a wrapper around an ordinary
  7459. // JS array.
  7460. // `nodes` the array containing nodes.
  7461. constructor(nodes) {
  7462. this.nodes = nodes;
  7463. }
  7464. // Creates and returns a deep clone of `this`
  7465. clone() {
  7466. // this class should not be cloned since it wraps
  7467. // around a given array. The calling function should check
  7468. // whether the wrapped array is null and supply a new array
  7469. // (from the clone).
  7470. return this.nodes = null;
  7471. }
  7472. // DOM Level 1
  7473. item(index) {
  7474. return this.nodes[index] || null;
  7475. }
  7476. };
  7477. // DOM level 1
  7478. Object.defineProperty(XMLNodeList.prototype, 'length', {
  7479. get: function() {
  7480. return this.nodes.length || 0;
  7481. }
  7482. });
  7483. return XMLNodeList;
  7484. }).call(this);
  7485. }).call(this);
  7486. },{}],37:[function(require,module,exports){
  7487. // Generated by CoffeeScript 2.4.1
  7488. (function() {
  7489. var NodeType, XMLCharacterData, XMLProcessingInstruction;
  7490. NodeType = require('./NodeType');
  7491. XMLCharacterData = require('./XMLCharacterData');
  7492. // Represents a processing instruction
  7493. module.exports = XMLProcessingInstruction = class XMLProcessingInstruction extends XMLCharacterData {
  7494. // Initializes a new instance of `XMLProcessingInstruction`
  7495. // `parent` the parent node
  7496. // `target` instruction target
  7497. // `value` instruction value
  7498. constructor(parent, target, value) {
  7499. super(parent);
  7500. if (target == null) {
  7501. throw new Error("Missing instruction target. " + this.debugInfo());
  7502. }
  7503. this.type = NodeType.ProcessingInstruction;
  7504. this.target = this.stringify.insTarget(target);
  7505. this.name = this.target;
  7506. if (value) {
  7507. this.value = this.stringify.insValue(value);
  7508. }
  7509. }
  7510. // Creates and returns a deep clone of `this`
  7511. clone() {
  7512. return Object.create(this);
  7513. }
  7514. // Converts the XML fragment to string
  7515. // `options.pretty` pretty prints the result
  7516. // `options.indent` indentation for pretty print
  7517. // `options.offset` how many indentations to add to every line for pretty print
  7518. // `options.newline` newline sequence for pretty print
  7519. toString(options) {
  7520. return this.options.writer.processingInstruction(this, this.options.writer.filterOptions(options));
  7521. }
  7522. isEqualNode(node) {
  7523. if (!super.isEqualNode(node)) {
  7524. return false;
  7525. }
  7526. if (node.target !== this.target) {
  7527. return false;
  7528. }
  7529. return true;
  7530. }
  7531. };
  7532. }).call(this);
  7533. },{"./NodeType":13,"./XMLCharacterData":18}],38:[function(require,module,exports){
  7534. // Generated by CoffeeScript 2.4.1
  7535. (function() {
  7536. var NodeType, XMLNode, XMLRaw;
  7537. NodeType = require('./NodeType');
  7538. XMLNode = require('./XMLNode');
  7539. // Represents a raw node
  7540. module.exports = XMLRaw = class XMLRaw extends XMLNode {
  7541. // Initializes a new instance of `XMLRaw`
  7542. // `text` raw text
  7543. constructor(parent, text) {
  7544. super(parent);
  7545. if (text == null) {
  7546. throw new Error("Missing raw text. " + this.debugInfo());
  7547. }
  7548. this.type = NodeType.Raw;
  7549. this.value = this.stringify.raw(text);
  7550. }
  7551. // Creates and returns a deep clone of `this`
  7552. clone() {
  7553. return Object.create(this);
  7554. }
  7555. // Converts the XML fragment to string
  7556. // `options.pretty` pretty prints the result
  7557. // `options.indent` indentation for pretty print
  7558. // `options.offset` how many indentations to add to every line for pretty print
  7559. // `options.newline` newline sequence for pretty print
  7560. toString(options) {
  7561. return this.options.writer.raw(this, this.options.writer.filterOptions(options));
  7562. }
  7563. };
  7564. }).call(this);
  7565. },{"./NodeType":13,"./XMLNode":35}],39:[function(require,module,exports){
  7566. // Generated by CoffeeScript 2.4.1
  7567. (function() {
  7568. var NodeType, WriterState, XMLStreamWriter, XMLWriterBase,
  7569. hasProp = {}.hasOwnProperty;
  7570. NodeType = require('./NodeType');
  7571. XMLWriterBase = require('./XMLWriterBase');
  7572. WriterState = require('./WriterState');
  7573. // Prints XML nodes to a stream
  7574. module.exports = XMLStreamWriter = class XMLStreamWriter extends XMLWriterBase {
  7575. // Initializes a new instance of `XMLStreamWriter`
  7576. // `stream` output stream
  7577. // `options.pretty` pretty prints the result
  7578. // `options.indent` indentation string
  7579. // `options.newline` newline sequence
  7580. // `options.offset` a fixed number of indentations to add to every line
  7581. // `options.allowEmpty` do not self close empty element tags
  7582. // 'options.dontPrettyTextNodes' if any text is present in node, don't indent or LF
  7583. // `options.spaceBeforeSlash` add a space before the closing slash of empty elements
  7584. constructor(stream, options) {
  7585. super(options);
  7586. this.stream = stream;
  7587. }
  7588. endline(node, options, level) {
  7589. if (node.isLastRootNode && options.state === WriterState.CloseTag) {
  7590. return '';
  7591. } else {
  7592. return super.endline(node, options, level);
  7593. }
  7594. }
  7595. document(doc, options) {
  7596. var child, i, j, k, len1, len2, ref, ref1, results;
  7597. ref = doc.children;
  7598. // set a flag so that we don't insert a newline after the last root level node
  7599. for (i = j = 0, len1 = ref.length; j < len1; i = ++j) {
  7600. child = ref[i];
  7601. child.isLastRootNode = i === doc.children.length - 1;
  7602. }
  7603. options = this.filterOptions(options);
  7604. ref1 = doc.children;
  7605. results = [];
  7606. for (k = 0, len2 = ref1.length; k < len2; k++) {
  7607. child = ref1[k];
  7608. results.push(this.writeChildNode(child, options, 0));
  7609. }
  7610. return results;
  7611. }
  7612. cdata(node, options, level) {
  7613. return this.stream.write(super.cdata(node, options, level));
  7614. }
  7615. comment(node, options, level) {
  7616. return this.stream.write(super.comment(node, options, level));
  7617. }
  7618. declaration(node, options, level) {
  7619. return this.stream.write(super.declaration(node, options, level));
  7620. }
  7621. docType(node, options, level) {
  7622. var child, j, len1, ref;
  7623. level || (level = 0);
  7624. this.openNode(node, options, level);
  7625. options.state = WriterState.OpenTag;
  7626. this.stream.write(this.indent(node, options, level));
  7627. this.stream.write('<!DOCTYPE ' + node.root().name);
  7628. // external identifier
  7629. if (node.pubID && node.sysID) {
  7630. this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
  7631. } else if (node.sysID) {
  7632. this.stream.write(' SYSTEM "' + node.sysID + '"');
  7633. }
  7634. // internal subset
  7635. if (node.children.length > 0) {
  7636. this.stream.write(' [');
  7637. this.stream.write(this.endline(node, options, level));
  7638. options.state = WriterState.InsideTag;
  7639. ref = node.children;
  7640. for (j = 0, len1 = ref.length; j < len1; j++) {
  7641. child = ref[j];
  7642. this.writeChildNode(child, options, level + 1);
  7643. }
  7644. options.state = WriterState.CloseTag;
  7645. this.stream.write(']');
  7646. }
  7647. // close tag
  7648. options.state = WriterState.CloseTag;
  7649. this.stream.write(options.spaceBeforeSlash + '>');
  7650. this.stream.write(this.endline(node, options, level));
  7651. options.state = WriterState.None;
  7652. return this.closeNode(node, options, level);
  7653. }
  7654. element(node, options, level) {
  7655. var att, attLen, child, childNodeCount, firstChildNode, j, len, len1, name, prettySuppressed, r, ratt, ref, ref1, ref2, rline;
  7656. level || (level = 0);
  7657. // open tag
  7658. this.openNode(node, options, level);
  7659. options.state = WriterState.OpenTag;
  7660. r = this.indent(node, options, level) + '<' + node.name;
  7661. // attributes
  7662. if (options.pretty && options.width > 0) {
  7663. len = r.length;
  7664. ref = node.attribs;
  7665. for (name in ref) {
  7666. if (!hasProp.call(ref, name)) continue;
  7667. att = ref[name];
  7668. ratt = this.attribute(att, options, level);
  7669. attLen = ratt.length;
  7670. if (len + attLen > options.width) {
  7671. rline = this.indent(node, options, level + 1) + ratt;
  7672. r += this.endline(node, options, level) + rline;
  7673. len = rline.length;
  7674. } else {
  7675. rline = ' ' + ratt;
  7676. r += rline;
  7677. len += rline.length;
  7678. }
  7679. }
  7680. } else {
  7681. ref1 = node.attribs;
  7682. for (name in ref1) {
  7683. if (!hasProp.call(ref1, name)) continue;
  7684. att = ref1[name];
  7685. r += this.attribute(att, options, level);
  7686. }
  7687. }
  7688. this.stream.write(r);
  7689. childNodeCount = node.children.length;
  7690. firstChildNode = childNodeCount === 0 ? null : node.children[0];
  7691. if (childNodeCount === 0 || node.children.every(function(e) {
  7692. return (e.type === NodeType.Text || e.type === NodeType.Raw || e.type === NodeType.CData) && e.value === '';
  7693. })) {
  7694. // empty element
  7695. if (options.allowEmpty) {
  7696. this.stream.write('>');
  7697. options.state = WriterState.CloseTag;
  7698. this.stream.write('</' + node.name + '>');
  7699. } else {
  7700. options.state = WriterState.CloseTag;
  7701. this.stream.write(options.spaceBeforeSlash + '/>');
  7702. }
  7703. } else if (options.pretty && childNodeCount === 1 && (firstChildNode.type === NodeType.Text || firstChildNode.type === NodeType.Raw || firstChildNode.type === NodeType.CData) && (firstChildNode.value != null)) {
  7704. // do not indent text-only nodes
  7705. this.stream.write('>');
  7706. options.state = WriterState.InsideTag;
  7707. options.suppressPrettyCount++;
  7708. prettySuppressed = true;
  7709. this.writeChildNode(firstChildNode, options, level + 1);
  7710. options.suppressPrettyCount--;
  7711. prettySuppressed = false;
  7712. options.state = WriterState.CloseTag;
  7713. this.stream.write('</' + node.name + '>');
  7714. } else {
  7715. this.stream.write('>' + this.endline(node, options, level));
  7716. options.state = WriterState.InsideTag;
  7717. ref2 = node.children;
  7718. // inner tags
  7719. for (j = 0, len1 = ref2.length; j < len1; j++) {
  7720. child = ref2[j];
  7721. this.writeChildNode(child, options, level + 1);
  7722. }
  7723. // close tag
  7724. options.state = WriterState.CloseTag;
  7725. this.stream.write(this.indent(node, options, level) + '</' + node.name + '>');
  7726. }
  7727. this.stream.write(this.endline(node, options, level));
  7728. options.state = WriterState.None;
  7729. return this.closeNode(node, options, level);
  7730. }
  7731. processingInstruction(node, options, level) {
  7732. return this.stream.write(super.processingInstruction(node, options, level));
  7733. }
  7734. raw(node, options, level) {
  7735. return this.stream.write(super.raw(node, options, level));
  7736. }
  7737. text(node, options, level) {
  7738. return this.stream.write(super.text(node, options, level));
  7739. }
  7740. dtdAttList(node, options, level) {
  7741. return this.stream.write(super.dtdAttList(node, options, level));
  7742. }
  7743. dtdElement(node, options, level) {
  7744. return this.stream.write(super.dtdElement(node, options, level));
  7745. }
  7746. dtdEntity(node, options, level) {
  7747. return this.stream.write(super.dtdEntity(node, options, level));
  7748. }
  7749. dtdNotation(node, options, level) {
  7750. return this.stream.write(super.dtdNotation(node, options, level));
  7751. }
  7752. };
  7753. }).call(this);
  7754. },{"./NodeType":13,"./WriterState":15,"./XMLWriterBase":43}],40:[function(require,module,exports){
  7755. // Generated by CoffeeScript 2.4.1
  7756. (function() {
  7757. var XMLStringWriter, XMLWriterBase;
  7758. XMLWriterBase = require('./XMLWriterBase');
  7759. // Prints XML nodes as plain text
  7760. module.exports = XMLStringWriter = class XMLStringWriter extends XMLWriterBase {
  7761. // Initializes a new instance of `XMLStringWriter`
  7762. // `options.pretty` pretty prints the result
  7763. // `options.indent` indentation string
  7764. // `options.newline` newline sequence
  7765. // `options.offset` a fixed number of indentations to add to every line
  7766. // `options.allowEmpty` do not self close empty element tags
  7767. // 'options.dontPrettyTextNodes' if any text is present in node, don't indent or LF
  7768. // `options.spaceBeforeSlash` add a space before the closing slash of empty elements
  7769. constructor(options) {
  7770. super(options);
  7771. }
  7772. document(doc, options) {
  7773. var child, i, len, r, ref;
  7774. options = this.filterOptions(options);
  7775. r = '';
  7776. ref = doc.children;
  7777. for (i = 0, len = ref.length; i < len; i++) {
  7778. child = ref[i];
  7779. r += this.writeChildNode(child, options, 0);
  7780. }
  7781. // remove trailing newline
  7782. if (options.pretty && r.slice(-options.newline.length) === options.newline) {
  7783. r = r.slice(0, -options.newline.length);
  7784. }
  7785. return r;
  7786. }
  7787. };
  7788. }).call(this);
  7789. },{"./XMLWriterBase":43}],41:[function(require,module,exports){
  7790. // Generated by CoffeeScript 2.4.1
  7791. (function() {
  7792. // Converts values to strings
  7793. var XMLStringifier,
  7794. hasProp = {}.hasOwnProperty;
  7795. module.exports = XMLStringifier = (function() {
  7796. class XMLStringifier {
  7797. // Initializes a new instance of `XMLStringifier`
  7798. // `options.version` The version number string of the XML spec to validate against, e.g. 1.0
  7799. // `options.noDoubleEncoding` whether existing html entities are encoded: true or false
  7800. // `options.stringify` a set of functions to use for converting values to strings
  7801. // `options.noValidation` whether values will be validated and escaped or returned as is
  7802. // `options.invalidCharReplacement` a character to replace invalid characters and disable character validation
  7803. constructor(options) {
  7804. var key, ref, value;
  7805. // Checks whether the given string contains legal characters
  7806. // Fails with an exception on error
  7807. // `str` the string to check
  7808. this.assertLegalChar = this.assertLegalChar.bind(this);
  7809. // Checks whether the given string contains legal characters for a name
  7810. // Fails with an exception on error
  7811. // `str` the string to check
  7812. this.assertLegalName = this.assertLegalName.bind(this);
  7813. options || (options = {});
  7814. this.options = options;
  7815. if (!this.options.version) {
  7816. this.options.version = '1.0';
  7817. }
  7818. ref = options.stringify || {};
  7819. for (key in ref) {
  7820. if (!hasProp.call(ref, key)) continue;
  7821. value = ref[key];
  7822. this[key] = value;
  7823. }
  7824. }
  7825. // Defaults
  7826. name(val) {
  7827. if (this.options.noValidation) {
  7828. return val;
  7829. }
  7830. return this.assertLegalName('' + val || '');
  7831. }
  7832. text(val) {
  7833. if (this.options.noValidation) {
  7834. return val;
  7835. }
  7836. return this.assertLegalChar(this.textEscape('' + val || ''));
  7837. }
  7838. cdata(val) {
  7839. if (this.options.noValidation) {
  7840. return val;
  7841. }
  7842. val = '' + val || '';
  7843. val = val.replace(']]>', ']]]]><![CDATA[>');
  7844. return this.assertLegalChar(val);
  7845. }
  7846. comment(val) {
  7847. if (this.options.noValidation) {
  7848. return val;
  7849. }
  7850. val = '' + val || '';
  7851. if (val.match(/--/)) {
  7852. throw new Error("Comment text cannot contain double-hypen: " + val);
  7853. }
  7854. return this.assertLegalChar(val);
  7855. }
  7856. raw(val) {
  7857. if (this.options.noValidation) {
  7858. return val;
  7859. }
  7860. return '' + val || '';
  7861. }
  7862. attValue(val) {
  7863. if (this.options.noValidation) {
  7864. return val;
  7865. }
  7866. return this.assertLegalChar(this.attEscape(val = '' + val || ''));
  7867. }
  7868. insTarget(val) {
  7869. if (this.options.noValidation) {
  7870. return val;
  7871. }
  7872. return this.assertLegalChar('' + val || '');
  7873. }
  7874. insValue(val) {
  7875. if (this.options.noValidation) {
  7876. return val;
  7877. }
  7878. val = '' + val || '';
  7879. if (val.match(/\?>/)) {
  7880. throw new Error("Invalid processing instruction value: " + val);
  7881. }
  7882. return this.assertLegalChar(val);
  7883. }
  7884. xmlVersion(val) {
  7885. if (this.options.noValidation) {
  7886. return val;
  7887. }
  7888. val = '' + val || '';
  7889. if (!val.match(/1\.[0-9]+/)) {
  7890. throw new Error("Invalid version number: " + val);
  7891. }
  7892. return val;
  7893. }
  7894. xmlEncoding(val) {
  7895. if (this.options.noValidation) {
  7896. return val;
  7897. }
  7898. val = '' + val || '';
  7899. if (!val.match(/^[A-Za-z](?:[A-Za-z0-9._-])*$/)) {
  7900. throw new Error("Invalid encoding: " + val);
  7901. }
  7902. return this.assertLegalChar(val);
  7903. }
  7904. xmlStandalone(val) {
  7905. if (this.options.noValidation) {
  7906. return val;
  7907. }
  7908. if (val) {
  7909. return "yes";
  7910. } else {
  7911. return "no";
  7912. }
  7913. }
  7914. dtdPubID(val) {
  7915. if (this.options.noValidation) {
  7916. return val;
  7917. }
  7918. return this.assertLegalChar('' + val || '');
  7919. }
  7920. dtdSysID(val) {
  7921. if (this.options.noValidation) {
  7922. return val;
  7923. }
  7924. return this.assertLegalChar('' + val || '');
  7925. }
  7926. dtdElementValue(val) {
  7927. if (this.options.noValidation) {
  7928. return val;
  7929. }
  7930. return this.assertLegalChar('' + val || '');
  7931. }
  7932. dtdAttType(val) {
  7933. if (this.options.noValidation) {
  7934. return val;
  7935. }
  7936. return this.assertLegalChar('' + val || '');
  7937. }
  7938. dtdAttDefault(val) {
  7939. if (this.options.noValidation) {
  7940. return val;
  7941. }
  7942. return this.assertLegalChar('' + val || '');
  7943. }
  7944. dtdEntityValue(val) {
  7945. if (this.options.noValidation) {
  7946. return val;
  7947. }
  7948. return this.assertLegalChar('' + val || '');
  7949. }
  7950. dtdNData(val) {
  7951. if (this.options.noValidation) {
  7952. return val;
  7953. }
  7954. return this.assertLegalChar('' + val || '');
  7955. }
  7956. assertLegalChar(str) {
  7957. var regex, res;
  7958. if (this.options.noValidation) {
  7959. return str;
  7960. }
  7961. if (this.options.version === '1.0') {
  7962. // Valid characters from https://www.w3.org/TR/xml/#charsets
  7963. // any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
  7964. // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
  7965. // This ES5 compatible Regexp has been generated using the "regenerate" NPM module:
  7966. // let xml_10_InvalidChars = regenerate()
  7967. // .addRange(0x0000, 0x0008)
  7968. // .add(0x000B, 0x000C)
  7969. // .addRange(0x000E, 0x001F)
  7970. // .addRange(0xD800, 0xDFFF)
  7971. // .addRange(0xFFFE, 0xFFFF)
  7972. regex = /[\0-\x08\x0B\f\x0E-\x1F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
  7973. if (this.options.invalidCharReplacement !== void 0) {
  7974. str = str.replace(regex, this.options.invalidCharReplacement);
  7975. } else if (res = str.match(regex)) {
  7976. throw new Error(`Invalid character in string: ${str} at index ${res.index}`);
  7977. }
  7978. } else if (this.options.version === '1.1') {
  7979. // Valid characters from https://www.w3.org/TR/xml11/#charsets
  7980. // any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
  7981. // [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
  7982. // This ES5 compatible Regexp has been generated using the "regenerate" NPM module:
  7983. // let xml_11_InvalidChars = regenerate()
  7984. // .add(0x0000)
  7985. // .addRange(0xD800, 0xDFFF)
  7986. // .addRange(0xFFFE, 0xFFFF)
  7987. regex = /[\0\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
  7988. if (this.options.invalidCharReplacement !== void 0) {
  7989. str = str.replace(regex, this.options.invalidCharReplacement);
  7990. } else if (res = str.match(regex)) {
  7991. throw new Error(`Invalid character in string: ${str} at index ${res.index}`);
  7992. }
  7993. }
  7994. return str;
  7995. }
  7996. assertLegalName(str) {
  7997. var regex;
  7998. if (this.options.noValidation) {
  7999. return str;
  8000. }
  8001. str = this.assertLegalChar(str);
  8002. regex = /^([:A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uDB7F][\uDC00-\uDFFF])([\x2D\.0-:A-Z_a-z\xB7\xC0-\xD6\xD8-\xF6\xF8-\u037D\u037F-\u1FFF\u200C\u200D\u203F\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uDB7F][\uDC00-\uDFFF])*$/;
  8003. if (!str.match(regex)) {
  8004. throw new Error(`Invalid character in name: ${str}`);
  8005. }
  8006. return str;
  8007. }
  8008. // Escapes special characters in text
  8009. // See http://www.w3.org/TR/2000/WD-xml-c14n-20000119.html#charescaping
  8010. // `str` the string to escape
  8011. textEscape(str) {
  8012. var ampregex;
  8013. if (this.options.noValidation) {
  8014. return str;
  8015. }
  8016. ampregex = this.options.noDoubleEncoding ? /(?!&(lt|gt|amp|apos|quot);)&/g : /&/g;
  8017. return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r/g, '&#xD;');
  8018. }
  8019. // Escapes special characters in attribute values
  8020. // See http://www.w3.org/TR/2000/WD-xml-c14n-20000119.html#charescaping
  8021. // `str` the string to escape
  8022. attEscape(str) {
  8023. var ampregex;
  8024. if (this.options.noValidation) {
  8025. return str;
  8026. }
  8027. ampregex = this.options.noDoubleEncoding ? /(?!&(lt|gt|amp|apos|quot);)&/g : /&/g;
  8028. return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/\t/g, '&#x9;').replace(/\n/g, '&#xA;').replace(/\r/g, '&#xD;');
  8029. }
  8030. };
  8031. // strings to match while converting from JS objects
  8032. XMLStringifier.prototype.convertAttKey = '@';
  8033. XMLStringifier.prototype.convertPIKey = '?';
  8034. XMLStringifier.prototype.convertTextKey = '#text';
  8035. XMLStringifier.prototype.convertCDataKey = '#cdata';
  8036. XMLStringifier.prototype.convertCommentKey = '#comment';
  8037. XMLStringifier.prototype.convertRawKey = '#raw';
  8038. return XMLStringifier;
  8039. }).call(this);
  8040. }).call(this);
  8041. },{}],42:[function(require,module,exports){
  8042. // Generated by CoffeeScript 2.4.1
  8043. (function() {
  8044. var NodeType, XMLCharacterData, XMLText;
  8045. NodeType = require('./NodeType');
  8046. XMLCharacterData = require('./XMLCharacterData');
  8047. // Represents a text node
  8048. module.exports = XMLText = (function() {
  8049. class XMLText extends XMLCharacterData {
  8050. // Initializes a new instance of `XMLText`
  8051. // `text` element text
  8052. constructor(parent, text) {
  8053. super(parent);
  8054. if (text == null) {
  8055. throw new Error("Missing element text. " + this.debugInfo());
  8056. }
  8057. this.name = "#text";
  8058. this.type = NodeType.Text;
  8059. this.value = this.stringify.text(text);
  8060. }
  8061. // Creates and returns a deep clone of `this`
  8062. clone() {
  8063. return Object.create(this);
  8064. }
  8065. // Converts the XML fragment to string
  8066. // `options.pretty` pretty prints the result
  8067. // `options.indent` indentation for pretty print
  8068. // `options.offset` how many indentations to add to every line for pretty print
  8069. // `options.newline` newline sequence for pretty print
  8070. toString(options) {
  8071. return this.options.writer.text(this, this.options.writer.filterOptions(options));
  8072. }
  8073. // DOM level 1 functions to be implemented later
  8074. splitText(offset) {
  8075. throw new Error("This DOM method is not implemented." + this.debugInfo());
  8076. }
  8077. // DOM level 3 functions to be implemented later
  8078. replaceWholeText(content) {
  8079. throw new Error("This DOM method is not implemented." + this.debugInfo());
  8080. }
  8081. };
  8082. // DOM level 3
  8083. Object.defineProperty(XMLText.prototype, 'isElementContentWhitespace', {
  8084. get: function() {
  8085. throw new Error("This DOM method is not implemented." + this.debugInfo());
  8086. }
  8087. });
  8088. Object.defineProperty(XMLText.prototype, 'wholeText', {
  8089. get: function() {
  8090. var next, prev, str;
  8091. str = '';
  8092. prev = this.previousSibling;
  8093. while (prev) {
  8094. str = prev.data + str;
  8095. prev = prev.previousSibling;
  8096. }
  8097. str += this.data;
  8098. next = this.nextSibling;
  8099. while (next) {
  8100. str = str + next.data;
  8101. next = next.nextSibling;
  8102. }
  8103. return str;
  8104. }
  8105. });
  8106. return XMLText;
  8107. }).call(this);
  8108. }).call(this);
  8109. },{"./NodeType":13,"./XMLCharacterData":18}],43:[function(require,module,exports){
  8110. // Generated by CoffeeScript 2.4.1
  8111. (function() {
  8112. var NodeType, WriterState, XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLProcessingInstruction, XMLRaw, XMLText, XMLWriterBase, assign,
  8113. hasProp = {}.hasOwnProperty;
  8114. ({assign} = require('./Utility'));
  8115. NodeType = require('./NodeType');
  8116. XMLDeclaration = require('./XMLDeclaration');
  8117. XMLDocType = require('./XMLDocType');
  8118. XMLCData = require('./XMLCData');
  8119. XMLComment = require('./XMLComment');
  8120. XMLElement = require('./XMLElement');
  8121. XMLRaw = require('./XMLRaw');
  8122. XMLText = require('./XMLText');
  8123. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  8124. XMLDummy = require('./XMLDummy');
  8125. XMLDTDAttList = require('./XMLDTDAttList');
  8126. XMLDTDElement = require('./XMLDTDElement');
  8127. XMLDTDEntity = require('./XMLDTDEntity');
  8128. XMLDTDNotation = require('./XMLDTDNotation');
  8129. WriterState = require('./WriterState');
  8130. // Base class for XML writers
  8131. module.exports = XMLWriterBase = class XMLWriterBase {
  8132. // Initializes a new instance of `XMLWriterBase`
  8133. // `options.pretty` pretty prints the result
  8134. // `options.indent` indentation string
  8135. // `options.newline` newline sequence
  8136. // `options.offset` a fixed number of indentations to add to every line
  8137. // `options.width` maximum column width
  8138. // `options.allowEmpty` do not self close empty element tags
  8139. // 'options.dontPrettyTextNodes' if any text is present in node, don't indent or LF
  8140. // `options.spaceBeforeSlash` add a space before the closing slash of empty elements
  8141. constructor(options) {
  8142. var key, ref, value;
  8143. options || (options = {});
  8144. this.options = options;
  8145. ref = options.writer || {};
  8146. for (key in ref) {
  8147. if (!hasProp.call(ref, key)) continue;
  8148. value = ref[key];
  8149. this["_" + key] = this[key];
  8150. this[key] = value;
  8151. }
  8152. }
  8153. // Filters writer options and provides defaults
  8154. // `options` writer options
  8155. filterOptions(options) {
  8156. var filteredOptions, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
  8157. options || (options = {});
  8158. options = assign({}, this.options, options);
  8159. filteredOptions = {
  8160. writer: this
  8161. };
  8162. filteredOptions.pretty = options.pretty || false;
  8163. filteredOptions.allowEmpty = options.allowEmpty || false;
  8164. filteredOptions.indent = (ref = options.indent) != null ? ref : ' ';
  8165. filteredOptions.newline = (ref1 = options.newline) != null ? ref1 : '\n';
  8166. filteredOptions.offset = (ref2 = options.offset) != null ? ref2 : 0;
  8167. filteredOptions.width = (ref3 = options.width) != null ? ref3 : 0;
  8168. filteredOptions.dontPrettyTextNodes = (ref4 = (ref5 = options.dontPrettyTextNodes) != null ? ref5 : options.dontprettytextnodes) != null ? ref4 : 0;
  8169. filteredOptions.spaceBeforeSlash = (ref6 = (ref7 = options.spaceBeforeSlash) != null ? ref7 : options.spacebeforeslash) != null ? ref6 : '';
  8170. if (filteredOptions.spaceBeforeSlash === true) {
  8171. filteredOptions.spaceBeforeSlash = ' ';
  8172. }
  8173. filteredOptions.suppressPrettyCount = 0;
  8174. filteredOptions.user = {};
  8175. filteredOptions.state = WriterState.None;
  8176. return filteredOptions;
  8177. }
  8178. // Returns the indentation string for the current level
  8179. // `node` current node
  8180. // `options` writer options
  8181. // `level` current indentation level
  8182. indent(node, options, level) {
  8183. var indentLevel;
  8184. if (!options.pretty || options.suppressPrettyCount) {
  8185. return '';
  8186. } else if (options.pretty) {
  8187. indentLevel = (level || 0) + options.offset + 1;
  8188. if (indentLevel > 0) {
  8189. return new Array(indentLevel).join(options.indent);
  8190. }
  8191. }
  8192. return '';
  8193. }
  8194. // Returns the newline string
  8195. // `node` current node
  8196. // `options` writer options
  8197. // `level` current indentation level
  8198. endline(node, options, level) {
  8199. if (!options.pretty || options.suppressPrettyCount) {
  8200. return '';
  8201. } else {
  8202. return options.newline;
  8203. }
  8204. }
  8205. attribute(att, options, level) {
  8206. var r;
  8207. this.openAttribute(att, options, level);
  8208. if (options.pretty && options.width > 0) {
  8209. r = att.name + '="' + att.value + '"';
  8210. } else {
  8211. r = ' ' + att.name + '="' + att.value + '"';
  8212. }
  8213. this.closeAttribute(att, options, level);
  8214. return r;
  8215. }
  8216. cdata(node, options, level) {
  8217. var r;
  8218. this.openNode(node, options, level);
  8219. options.state = WriterState.OpenTag;
  8220. r = this.indent(node, options, level) + '<![CDATA[';
  8221. options.state = WriterState.InsideTag;
  8222. r += node.value;
  8223. options.state = WriterState.CloseTag;
  8224. r += ']]>' + this.endline(node, options, level);
  8225. options.state = WriterState.None;
  8226. this.closeNode(node, options, level);
  8227. return r;
  8228. }
  8229. comment(node, options, level) {
  8230. var r;
  8231. this.openNode(node, options, level);
  8232. options.state = WriterState.OpenTag;
  8233. r = this.indent(node, options, level) + '<!-- ';
  8234. options.state = WriterState.InsideTag;
  8235. r += node.value;
  8236. options.state = WriterState.CloseTag;
  8237. r += ' -->' + this.endline(node, options, level);
  8238. options.state = WriterState.None;
  8239. this.closeNode(node, options, level);
  8240. return r;
  8241. }
  8242. declaration(node, options, level) {
  8243. var r;
  8244. this.openNode(node, options, level);
  8245. options.state = WriterState.OpenTag;
  8246. r = this.indent(node, options, level) + '<?xml';
  8247. options.state = WriterState.InsideTag;
  8248. r += ' version="' + node.version + '"';
  8249. if (node.encoding != null) {
  8250. r += ' encoding="' + node.encoding + '"';
  8251. }
  8252. if (node.standalone != null) {
  8253. r += ' standalone="' + node.standalone + '"';
  8254. }
  8255. options.state = WriterState.CloseTag;
  8256. r += options.spaceBeforeSlash + '?>';
  8257. r += this.endline(node, options, level);
  8258. options.state = WriterState.None;
  8259. this.closeNode(node, options, level);
  8260. return r;
  8261. }
  8262. docType(node, options, level) {
  8263. var child, i, len1, r, ref;
  8264. level || (level = 0);
  8265. this.openNode(node, options, level);
  8266. options.state = WriterState.OpenTag;
  8267. r = this.indent(node, options, level);
  8268. r += '<!DOCTYPE ' + node.root().name;
  8269. // external identifier
  8270. if (node.pubID && node.sysID) {
  8271. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  8272. } else if (node.sysID) {
  8273. r += ' SYSTEM "' + node.sysID + '"';
  8274. }
  8275. // internal subset
  8276. if (node.children.length > 0) {
  8277. r += ' [';
  8278. r += this.endline(node, options, level);
  8279. options.state = WriterState.InsideTag;
  8280. ref = node.children;
  8281. for (i = 0, len1 = ref.length; i < len1; i++) {
  8282. child = ref[i];
  8283. r += this.writeChildNode(child, options, level + 1);
  8284. }
  8285. options.state = WriterState.CloseTag;
  8286. r += ']';
  8287. }
  8288. // close tag
  8289. options.state = WriterState.CloseTag;
  8290. r += options.spaceBeforeSlash + '>';
  8291. r += this.endline(node, options, level);
  8292. options.state = WriterState.None;
  8293. this.closeNode(node, options, level);
  8294. return r;
  8295. }
  8296. element(node, options, level) {
  8297. var att, attLen, child, childNodeCount, firstChildNode, i, j, len, len1, len2, name, prettySuppressed, r, ratt, ref, ref1, ref2, ref3, rline;
  8298. level || (level = 0);
  8299. prettySuppressed = false;
  8300. // open tag
  8301. this.openNode(node, options, level);
  8302. options.state = WriterState.OpenTag;
  8303. r = this.indent(node, options, level) + '<' + node.name;
  8304. // attributes
  8305. if (options.pretty && options.width > 0) {
  8306. len = r.length;
  8307. ref = node.attribs;
  8308. for (name in ref) {
  8309. if (!hasProp.call(ref, name)) continue;
  8310. att = ref[name];
  8311. ratt = this.attribute(att, options, level);
  8312. attLen = ratt.length;
  8313. if (len + attLen > options.width) {
  8314. rline = this.indent(node, options, level + 1) + ratt;
  8315. r += this.endline(node, options, level) + rline;
  8316. len = rline.length;
  8317. } else {
  8318. rline = ' ' + ratt;
  8319. r += rline;
  8320. len += rline.length;
  8321. }
  8322. }
  8323. } else {
  8324. ref1 = node.attribs;
  8325. for (name in ref1) {
  8326. if (!hasProp.call(ref1, name)) continue;
  8327. att = ref1[name];
  8328. r += this.attribute(att, options, level);
  8329. }
  8330. }
  8331. childNodeCount = node.children.length;
  8332. firstChildNode = childNodeCount === 0 ? null : node.children[0];
  8333. if (childNodeCount === 0 || node.children.every(function(e) {
  8334. return (e.type === NodeType.Text || e.type === NodeType.Raw || e.type === NodeType.CData) && e.value === '';
  8335. })) {
  8336. // empty element
  8337. if (options.allowEmpty) {
  8338. r += '>';
  8339. options.state = WriterState.CloseTag;
  8340. r += '</' + node.name + '>' + this.endline(node, options, level);
  8341. } else {
  8342. options.state = WriterState.CloseTag;
  8343. r += options.spaceBeforeSlash + '/>' + this.endline(node, options, level);
  8344. }
  8345. } else if (options.pretty && childNodeCount === 1 && (firstChildNode.type === NodeType.Text || firstChildNode.type === NodeType.Raw || firstChildNode.type === NodeType.CData) && (firstChildNode.value != null)) {
  8346. // do not indent text-only nodes
  8347. r += '>';
  8348. options.state = WriterState.InsideTag;
  8349. options.suppressPrettyCount++;
  8350. prettySuppressed = true;
  8351. r += this.writeChildNode(firstChildNode, options, level + 1);
  8352. options.suppressPrettyCount--;
  8353. prettySuppressed = false;
  8354. options.state = WriterState.CloseTag;
  8355. r += '</' + node.name + '>' + this.endline(node, options, level);
  8356. } else {
  8357. // if ANY are a text node, then suppress pretty now
  8358. if (options.dontPrettyTextNodes) {
  8359. ref2 = node.children;
  8360. for (i = 0, len1 = ref2.length; i < len1; i++) {
  8361. child = ref2[i];
  8362. if ((child.type === NodeType.Text || child.type === NodeType.Raw || child.type === NodeType.CData) && (child.value != null)) {
  8363. options.suppressPrettyCount++;
  8364. prettySuppressed = true;
  8365. break;
  8366. }
  8367. }
  8368. }
  8369. // close the opening tag, after dealing with newline
  8370. r += '>' + this.endline(node, options, level);
  8371. options.state = WriterState.InsideTag;
  8372. ref3 = node.children;
  8373. // inner tags
  8374. for (j = 0, len2 = ref3.length; j < len2; j++) {
  8375. child = ref3[j];
  8376. r += this.writeChildNode(child, options, level + 1);
  8377. }
  8378. // close tag
  8379. options.state = WriterState.CloseTag;
  8380. r += this.indent(node, options, level) + '</' + node.name + '>';
  8381. if (prettySuppressed) {
  8382. options.suppressPrettyCount--;
  8383. }
  8384. r += this.endline(node, options, level);
  8385. options.state = WriterState.None;
  8386. }
  8387. this.closeNode(node, options, level);
  8388. return r;
  8389. }
  8390. writeChildNode(node, options, level) {
  8391. switch (node.type) {
  8392. case NodeType.CData:
  8393. return this.cdata(node, options, level);
  8394. case NodeType.Comment:
  8395. return this.comment(node, options, level);
  8396. case NodeType.Element:
  8397. return this.element(node, options, level);
  8398. case NodeType.Raw:
  8399. return this.raw(node, options, level);
  8400. case NodeType.Text:
  8401. return this.text(node, options, level);
  8402. case NodeType.ProcessingInstruction:
  8403. return this.processingInstruction(node, options, level);
  8404. case NodeType.Dummy:
  8405. return '';
  8406. case NodeType.Declaration:
  8407. return this.declaration(node, options, level);
  8408. case NodeType.DocType:
  8409. return this.docType(node, options, level);
  8410. case NodeType.AttributeDeclaration:
  8411. return this.dtdAttList(node, options, level);
  8412. case NodeType.ElementDeclaration:
  8413. return this.dtdElement(node, options, level);
  8414. case NodeType.EntityDeclaration:
  8415. return this.dtdEntity(node, options, level);
  8416. case NodeType.NotationDeclaration:
  8417. return this.dtdNotation(node, options, level);
  8418. default:
  8419. throw new Error("Unknown XML node type: " + node.constructor.name);
  8420. }
  8421. }
  8422. processingInstruction(node, options, level) {
  8423. var r;
  8424. this.openNode(node, options, level);
  8425. options.state = WriterState.OpenTag;
  8426. r = this.indent(node, options, level) + '<?';
  8427. options.state = WriterState.InsideTag;
  8428. r += node.target;
  8429. if (node.value) {
  8430. r += ' ' + node.value;
  8431. }
  8432. options.state = WriterState.CloseTag;
  8433. r += options.spaceBeforeSlash + '?>';
  8434. r += this.endline(node, options, level);
  8435. options.state = WriterState.None;
  8436. this.closeNode(node, options, level);
  8437. return r;
  8438. }
  8439. raw(node, options, level) {
  8440. var r;
  8441. this.openNode(node, options, level);
  8442. options.state = WriterState.OpenTag;
  8443. r = this.indent(node, options, level);
  8444. options.state = WriterState.InsideTag;
  8445. r += node.value;
  8446. options.state = WriterState.CloseTag;
  8447. r += this.endline(node, options, level);
  8448. options.state = WriterState.None;
  8449. this.closeNode(node, options, level);
  8450. return r;
  8451. }
  8452. text(node, options, level) {
  8453. var r;
  8454. this.openNode(node, options, level);
  8455. options.state = WriterState.OpenTag;
  8456. r = this.indent(node, options, level);
  8457. options.state = WriterState.InsideTag;
  8458. r += node.value;
  8459. options.state = WriterState.CloseTag;
  8460. r += this.endline(node, options, level);
  8461. options.state = WriterState.None;
  8462. this.closeNode(node, options, level);
  8463. return r;
  8464. }
  8465. dtdAttList(node, options, level) {
  8466. var r;
  8467. this.openNode(node, options, level);
  8468. options.state = WriterState.OpenTag;
  8469. r = this.indent(node, options, level) + '<!ATTLIST';
  8470. options.state = WriterState.InsideTag;
  8471. r += ' ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType;
  8472. if (node.defaultValueType !== '#DEFAULT') {
  8473. r += ' ' + node.defaultValueType;
  8474. }
  8475. if (node.defaultValue) {
  8476. r += ' "' + node.defaultValue + '"';
  8477. }
  8478. options.state = WriterState.CloseTag;
  8479. r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
  8480. options.state = WriterState.None;
  8481. this.closeNode(node, options, level);
  8482. return r;
  8483. }
  8484. dtdElement(node, options, level) {
  8485. var r;
  8486. this.openNode(node, options, level);
  8487. options.state = WriterState.OpenTag;
  8488. r = this.indent(node, options, level) + '<!ELEMENT';
  8489. options.state = WriterState.InsideTag;
  8490. r += ' ' + node.name + ' ' + node.value;
  8491. options.state = WriterState.CloseTag;
  8492. r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
  8493. options.state = WriterState.None;
  8494. this.closeNode(node, options, level);
  8495. return r;
  8496. }
  8497. dtdEntity(node, options, level) {
  8498. var r;
  8499. this.openNode(node, options, level);
  8500. options.state = WriterState.OpenTag;
  8501. r = this.indent(node, options, level) + '<!ENTITY';
  8502. options.state = WriterState.InsideTag;
  8503. if (node.pe) {
  8504. r += ' %';
  8505. }
  8506. r += ' ' + node.name;
  8507. if (node.value) {
  8508. r += ' "' + node.value + '"';
  8509. } else {
  8510. if (node.pubID && node.sysID) {
  8511. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  8512. } else if (node.sysID) {
  8513. r += ' SYSTEM "' + node.sysID + '"';
  8514. }
  8515. if (node.nData) {
  8516. r += ' NDATA ' + node.nData;
  8517. }
  8518. }
  8519. options.state = WriterState.CloseTag;
  8520. r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
  8521. options.state = WriterState.None;
  8522. this.closeNode(node, options, level);
  8523. return r;
  8524. }
  8525. dtdNotation(node, options, level) {
  8526. var r;
  8527. this.openNode(node, options, level);
  8528. options.state = WriterState.OpenTag;
  8529. r = this.indent(node, options, level) + '<!NOTATION';
  8530. options.state = WriterState.InsideTag;
  8531. r += ' ' + node.name;
  8532. if (node.pubID && node.sysID) {
  8533. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  8534. } else if (node.pubID) {
  8535. r += ' PUBLIC "' + node.pubID + '"';
  8536. } else if (node.sysID) {
  8537. r += ' SYSTEM "' + node.sysID + '"';
  8538. }
  8539. options.state = WriterState.CloseTag;
  8540. r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
  8541. options.state = WriterState.None;
  8542. this.closeNode(node, options, level);
  8543. return r;
  8544. }
  8545. openNode(node, options, level) {}
  8546. closeNode(node, options, level) {}
  8547. openAttribute(att, options, level) {}
  8548. closeAttribute(att, options, level) {}
  8549. };
  8550. }).call(this);
  8551. },{"./NodeType":13,"./Utility":14,"./WriterState":15,"./XMLCData":17,"./XMLComment":19,"./XMLDTDAttList":24,"./XMLDTDElement":25,"./XMLDTDEntity":26,"./XMLDTDNotation":27,"./XMLDeclaration":28,"./XMLDocType":29,"./XMLDummy":32,"./XMLElement":33,"./XMLProcessingInstruction":37,"./XMLRaw":38,"./XMLText":42}],44:[function(require,module,exports){
  8552. // Generated by CoffeeScript 2.4.1
  8553. (function() {
  8554. var NodeType, WriterState, XMLDOMImplementation, XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction;
  8555. ({assign, isFunction} = require('./Utility'));
  8556. XMLDOMImplementation = require('./XMLDOMImplementation');
  8557. XMLDocument = require('./XMLDocument');
  8558. XMLDocumentCB = require('./XMLDocumentCB');
  8559. XMLStringWriter = require('./XMLStringWriter');
  8560. XMLStreamWriter = require('./XMLStreamWriter');
  8561. NodeType = require('./NodeType');
  8562. WriterState = require('./WriterState');
  8563. // Creates a new document and returns the root node for
  8564. // chain-building the document tree
  8565. // `name` name of the root element
  8566. // `xmldec.version` A version number string, e.g. 1.0
  8567. // `xmldec.encoding` Encoding declaration, e.g. UTF-8
  8568. // `xmldec.standalone` standalone document declaration: true or false
  8569. // `doctype.pubID` public identifier of the external subset
  8570. // `doctype.sysID` system identifier of the external subset
  8571. // `options.headless` whether XML declaration and doctype will be included:
  8572. // true or false
  8573. // `options.keepNullNodes` whether nodes with null values will be kept
  8574. // or ignored: true or false
  8575. // `options.keepNullAttributes` whether attributes with null values will be
  8576. // kept or ignored: true or false
  8577. // `options.ignoreDecorators` whether decorator strings will be ignored when
  8578. // converting JS objects: true or false
  8579. // `options.separateArrayItems` whether array items are created as separate
  8580. // nodes when passed as an object value: true or false
  8581. // `options.noDoubleEncoding` whether existing html entities are encoded:
  8582. // true or false
  8583. // `options.stringify` a set of functions to use for converting values to
  8584. // strings
  8585. // `options.writer` the default XML writer to use for converting nodes to
  8586. // string. If the default writer is not set, the built-in XMLStringWriter
  8587. // will be used instead.
  8588. module.exports.create = function(name, xmldec, doctype, options) {
  8589. var doc, root;
  8590. if (name == null) {
  8591. throw new Error("Root element needs a name.");
  8592. }
  8593. options = assign({}, xmldec, doctype, options);
  8594. // create the document node
  8595. doc = new XMLDocument(options);
  8596. // add the root node
  8597. root = doc.element(name);
  8598. // prolog
  8599. if (!options.headless) {
  8600. doc.declaration(options);
  8601. if ((options.pubID != null) || (options.sysID != null)) {
  8602. doc.dtd(options);
  8603. }
  8604. }
  8605. return root;
  8606. };
  8607. // Creates a new document and returns the document node for
  8608. // chain-building the document tree
  8609. // `options.keepNullNodes` whether nodes with null values will be kept
  8610. // or ignored: true or false
  8611. // `options.keepNullAttributes` whether attributes with null values will be
  8612. // kept or ignored: true or false
  8613. // `options.ignoreDecorators` whether decorator strings will be ignored when
  8614. // converting JS objects: true or false
  8615. // `options.separateArrayItems` whether array items are created as separate
  8616. // nodes when passed as an object value: true or false
  8617. // `options.noDoubleEncoding` whether existing html entities are encoded:
  8618. // true or false
  8619. // `options.stringify` a set of functions to use for converting values to
  8620. // strings
  8621. // `options.writer` the default XML writer to use for converting nodes to
  8622. // string. If the default writer is not set, the built-in XMLStringWriter
  8623. // will be used instead.
  8624. // `onData` the function to be called when a new chunk of XML is output. The
  8625. // string containing the XML chunk is passed to `onData` as its single
  8626. // argument.
  8627. // `onEnd` the function to be called when the XML document is completed with
  8628. // `end`. `onEnd` does not receive any arguments.
  8629. module.exports.begin = function(options, onData, onEnd) {
  8630. if (isFunction(options)) {
  8631. [onData, onEnd] = [options, onData];
  8632. options = {};
  8633. }
  8634. if (onData) {
  8635. return new XMLDocumentCB(options, onData, onEnd);
  8636. } else {
  8637. return new XMLDocument(options);
  8638. }
  8639. };
  8640. module.exports.stringWriter = function(options) {
  8641. return new XMLStringWriter(options);
  8642. };
  8643. module.exports.streamWriter = function(stream, options) {
  8644. return new XMLStreamWriter(stream, options);
  8645. };
  8646. module.exports.implementation = new XMLDOMImplementation();
  8647. module.exports.nodeType = NodeType;
  8648. module.exports.writerState = WriterState;
  8649. }).call(this);
  8650. },{"./NodeType":13,"./Utility":14,"./WriterState":15,"./XMLDOMImplementation":22,"./XMLDocument":30,"./XMLDocumentCB":31,"./XMLStreamWriter":39,"./XMLStringWriter":40}]},{},[1])(1)
  8651. });