Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.plist = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
  2. /**
  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){
  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. }
  124. }
  125. }).call(this,{"isBuffer":require("../node_modules/is-buffer/index.js")})
  126. },{"../node_modules/is-buffer/index.js":7,"base64-js":4,"xmlbuilder":29}],3:[function(require,module,exports){
  127. (function (Buffer){
  128. /**
  129. * Module dependencies.
  130. */
  131. var DOMParser = require('xmldom').DOMParser;
  132. /**
  133. * Module exports.
  134. */
  135. exports.parse = parse;
  136. var TEXT_NODE = 3;
  137. var CDATA_NODE = 4;
  138. var COMMENT_NODE = 8;
  139. /**
  140. * We ignore raw text (usually whitespace), <!-- xml comments -->,
  141. * and raw CDATA nodes.
  142. *
  143. * @param {Element} node
  144. * @returns {Boolean}
  145. * @api private
  146. */
  147. function shouldIgnoreNode (node) {
  148. return node.nodeType === TEXT_NODE
  149. || node.nodeType === COMMENT_NODE
  150. || node.nodeType === CDATA_NODE;
  151. }
  152. /**
  153. * Check if the node is empty. Some plist file has such node:
  154. * <key />
  155. * this node shoud be ignored.
  156. *
  157. * @see https://github.com/TooTallNate/plist.js/issues/66
  158. * @param {Element} node
  159. * @returns {Boolean}
  160. * @api private
  161. */
  162. function isEmptyNode(node){
  163. if(!node.childNodes || node.childNodes.length === 0) {
  164. return true;
  165. } else {
  166. return false;
  167. }
  168. }
  169. function invariant(test, message) {
  170. if (!test) {
  171. throw new Error(message);
  172. }
  173. }
  174. /**
  175. * Parses a Plist XML string. Returns an Object.
  176. *
  177. * @param {String} xml - the XML String to decode
  178. * @returns {Mixed} the decoded value from the Plist XML
  179. * @api public
  180. */
  181. function parse (xml) {
  182. var doc = new DOMParser().parseFromString(xml);
  183. invariant(
  184. doc.documentElement.nodeName === 'plist',
  185. 'malformed document. First element should be <plist>'
  186. );
  187. var plist = parsePlistXML(doc.documentElement);
  188. // the root <plist> node gets interpreted as an Array,
  189. // so pull out the inner data first
  190. if (plist.length == 1) plist = plist[0];
  191. return plist;
  192. }
  193. /**
  194. * Convert an XML based plist document into a JSON representation.
  195. *
  196. * @param {Object} xml_node - current XML node in the plist
  197. * @returns {Mixed} built up JSON object
  198. * @api private
  199. */
  200. function parsePlistXML (node) {
  201. var i, new_obj, key, val, new_arr, res, counter, type;
  202. if (!node)
  203. return null;
  204. if (node.nodeName === 'plist') {
  205. new_arr = [];
  206. if (isEmptyNode(node)) {
  207. return new_arr;
  208. }
  209. for (i=0; i < node.childNodes.length; i++) {
  210. if (!shouldIgnoreNode(node.childNodes[i])) {
  211. new_arr.push( parsePlistXML(node.childNodes[i]));
  212. }
  213. }
  214. return new_arr;
  215. } else if (node.nodeName === 'dict') {
  216. new_obj = {};
  217. key = null;
  218. counter = 0;
  219. if (isEmptyNode(node)) {
  220. return new_obj;
  221. }
  222. for (i=0; i < node.childNodes.length; i++) {
  223. if (shouldIgnoreNode(node.childNodes[i])) continue;
  224. if (counter % 2 === 0) {
  225. invariant(
  226. node.childNodes[i].nodeName === 'key',
  227. 'Missing key while parsing <dict/>.'
  228. );
  229. key = parsePlistXML(node.childNodes[i]);
  230. } else {
  231. invariant(
  232. node.childNodes[i].nodeName !== 'key',
  233. 'Unexpected key "'
  234. + parsePlistXML(node.childNodes[i])
  235. + '" while parsing <dict/>.'
  236. );
  237. new_obj[key] = parsePlistXML(node.childNodes[i]);
  238. }
  239. counter += 1;
  240. }
  241. if (counter % 2 === 1) {
  242. throw new Error('Missing value for "' + key + '" while parsing <dict/>');
  243. }
  244. return new_obj;
  245. } else if (node.nodeName === 'array') {
  246. new_arr = [];
  247. if (isEmptyNode(node)) {
  248. return new_arr;
  249. }
  250. for (i=0; i < node.childNodes.length; i++) {
  251. if (!shouldIgnoreNode(node.childNodes[i])) {
  252. res = parsePlistXML(node.childNodes[i]);
  253. if (null != res) new_arr.push(res);
  254. }
  255. }
  256. return new_arr;
  257. } else if (node.nodeName === '#text') {
  258. // TODO: what should we do with text types? (CDATA sections)
  259. } else if (node.nodeName === 'key') {
  260. if (isEmptyNode(node)) {
  261. return '';
  262. }
  263. return node.childNodes[0].nodeValue;
  264. } else if (node.nodeName === 'string') {
  265. res = '';
  266. if (isEmptyNode(node)) {
  267. return res;
  268. }
  269. for (i=0; i < node.childNodes.length; i++) {
  270. var type = node.childNodes[i].nodeType;
  271. if (type === TEXT_NODE || type === CDATA_NODE) {
  272. res += node.childNodes[i].nodeValue;
  273. }
  274. }
  275. return res;
  276. } else if (node.nodeName === 'integer') {
  277. invariant(
  278. !isEmptyNode(node),
  279. 'Cannot parse "" as integer.'
  280. );
  281. return parseInt(node.childNodes[0].nodeValue, 10);
  282. } else if (node.nodeName === 'real') {
  283. invariant(
  284. !isEmptyNode(node),
  285. 'Cannot parse "" as real.'
  286. );
  287. res = '';
  288. for (i=0; i < node.childNodes.length; i++) {
  289. if (node.childNodes[i].nodeType === TEXT_NODE) {
  290. res += node.childNodes[i].nodeValue;
  291. }
  292. }
  293. return parseFloat(res);
  294. } else if (node.nodeName === 'data') {
  295. res = '';
  296. if (isEmptyNode(node)) {
  297. return Buffer.from(res, 'base64');
  298. }
  299. for (i=0; i < node.childNodes.length; i++) {
  300. if (node.childNodes[i].nodeType === TEXT_NODE) {
  301. res += node.childNodes[i].nodeValue.replace(/\s+/g, '');
  302. }
  303. }
  304. return Buffer.from(res, 'base64');
  305. } else if (node.nodeName === 'date') {
  306. invariant(
  307. !isEmptyNode(node),
  308. 'Cannot parse "" as Date.'
  309. )
  310. return new Date(node.childNodes[0].nodeValue);
  311. } else if (node.nodeName === 'true') {
  312. return true;
  313. } else if (node.nodeName === 'false') {
  314. return false;
  315. }
  316. }
  317. }).call(this,require("buffer").Buffer)
  318. },{"buffer":5,"xmldom":30}],4:[function(require,module,exports){
  319. 'use strict'
  320. exports.byteLength = byteLength
  321. exports.toByteArray = toByteArray
  322. exports.fromByteArray = fromByteArray
  323. var lookup = []
  324. var revLookup = []
  325. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  326. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  327. for (var i = 0, len = code.length; i < len; ++i) {
  328. lookup[i] = code[i]
  329. revLookup[code.charCodeAt(i)] = i
  330. }
  331. // Support decoding URL-safe base64 strings, as Node.js does.
  332. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  333. revLookup['-'.charCodeAt(0)] = 62
  334. revLookup['_'.charCodeAt(0)] = 63
  335. function placeHoldersCount (b64) {
  336. var len = b64.length
  337. if (len % 4 > 0) {
  338. throw new Error('Invalid string. Length must be a multiple of 4')
  339. }
  340. // the number of equal signs (place holders)
  341. // if there are two placeholders, than the two characters before it
  342. // represent one byte
  343. // if there is only one, then the three characters before it represent 2 bytes
  344. // this is just a cheap hack to not do indexOf twice
  345. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  346. }
  347. function byteLength (b64) {
  348. // base64 is 4/3 + up to two characters of the original data
  349. return (b64.length * 3 / 4) - placeHoldersCount(b64)
  350. }
  351. function toByteArray (b64) {
  352. var i, l, tmp, placeHolders, arr
  353. var len = b64.length
  354. placeHolders = placeHoldersCount(b64)
  355. arr = new Arr((len * 3 / 4) - placeHolders)
  356. // if there are placeholders, only get up to the last complete 4 chars
  357. l = placeHolders > 0 ? len - 4 : len
  358. var L = 0
  359. for (i = 0; i < l; i += 4) {
  360. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  361. arr[L++] = (tmp >> 16) & 0xFF
  362. arr[L++] = (tmp >> 8) & 0xFF
  363. arr[L++] = tmp & 0xFF
  364. }
  365. if (placeHolders === 2) {
  366. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  367. arr[L++] = tmp & 0xFF
  368. } else if (placeHolders === 1) {
  369. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  370. arr[L++] = (tmp >> 8) & 0xFF
  371. arr[L++] = tmp & 0xFF
  372. }
  373. return arr
  374. }
  375. function tripletToBase64 (num) {
  376. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  377. }
  378. function encodeChunk (uint8, start, end) {
  379. var tmp
  380. var output = []
  381. for (var i = start; i < end; i += 3) {
  382. tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF)
  383. output.push(tripletToBase64(tmp))
  384. }
  385. return output.join('')
  386. }
  387. function fromByteArray (uint8) {
  388. var tmp
  389. var len = uint8.length
  390. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  391. var output = ''
  392. var parts = []
  393. var maxChunkLength = 16383 // must be multiple of 3
  394. // go through the array every three bytes, we'll deal with trailing stuff later
  395. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  396. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  397. }
  398. // pad the end with zeros, but make sure to not forget the extra bytes
  399. if (extraBytes === 1) {
  400. tmp = uint8[len - 1]
  401. output += lookup[tmp >> 2]
  402. output += lookup[(tmp << 4) & 0x3F]
  403. output += '=='
  404. } else if (extraBytes === 2) {
  405. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  406. output += lookup[tmp >> 10]
  407. output += lookup[(tmp >> 4) & 0x3F]
  408. output += lookup[(tmp << 2) & 0x3F]
  409. output += '='
  410. }
  411. parts.push(output)
  412. return parts.join('')
  413. }
  414. },{}],5:[function(require,module,exports){
  415. /*!
  416. * The buffer module from node.js, for the browser.
  417. *
  418. * @author Feross Aboukhadijeh <https://feross.org>
  419. * @license MIT
  420. */
  421. /* eslint-disable no-proto */
  422. 'use strict'
  423. var base64 = require('base64-js')
  424. var ieee754 = require('ieee754')
  425. exports.Buffer = Buffer
  426. exports.SlowBuffer = SlowBuffer
  427. exports.INSPECT_MAX_BYTES = 50
  428. var K_MAX_LENGTH = 0x7fffffff
  429. exports.kMaxLength = K_MAX_LENGTH
  430. /**
  431. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  432. * === true Use Uint8Array implementation (fastest)
  433. * === false Print warning and recommend using `buffer` v4.x which has an Object
  434. * implementation (most compatible, even IE6)
  435. *
  436. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  437. * Opera 11.6+, iOS 4.2+.
  438. *
  439. * We report that the browser does not support typed arrays if the are not subclassable
  440. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  441. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  442. * for __proto__ and has a buggy typed array implementation.
  443. */
  444. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  445. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  446. typeof console.error === 'function') {
  447. console.error(
  448. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  449. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  450. )
  451. }
  452. function typedArraySupport () {
  453. // Can typed array instances can be augmented?
  454. try {
  455. var arr = new Uint8Array(1)
  456. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  457. return arr.foo() === 42
  458. } catch (e) {
  459. return false
  460. }
  461. }
  462. Object.defineProperty(Buffer.prototype, 'parent', {
  463. get: function () {
  464. if (!(this instanceof Buffer)) {
  465. return undefined
  466. }
  467. return this.buffer
  468. }
  469. })
  470. Object.defineProperty(Buffer.prototype, 'offset', {
  471. get: function () {
  472. if (!(this instanceof Buffer)) {
  473. return undefined
  474. }
  475. return this.byteOffset
  476. }
  477. })
  478. function createBuffer (length) {
  479. if (length > K_MAX_LENGTH) {
  480. throw new RangeError('Invalid typed array length')
  481. }
  482. // Return an augmented `Uint8Array` instance
  483. var buf = new Uint8Array(length)
  484. buf.__proto__ = Buffer.prototype
  485. return buf
  486. }
  487. /**
  488. * The Buffer constructor returns instances of `Uint8Array` that have their
  489. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  490. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  491. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  492. * returns a single octet.
  493. *
  494. * The `Uint8Array` prototype remains unmodified.
  495. */
  496. function Buffer (arg, encodingOrOffset, length) {
  497. // Common case.
  498. if (typeof arg === 'number') {
  499. if (typeof encodingOrOffset === 'string') {
  500. throw new Error(
  501. 'If encoding is specified then the first argument must be a string'
  502. )
  503. }
  504. return allocUnsafe(arg)
  505. }
  506. return from(arg, encodingOrOffset, length)
  507. }
  508. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  509. if (typeof Symbol !== 'undefined' && Symbol.species &&
  510. Buffer[Symbol.species] === Buffer) {
  511. Object.defineProperty(Buffer, Symbol.species, {
  512. value: null,
  513. configurable: true,
  514. enumerable: false,
  515. writable: false
  516. })
  517. }
  518. Buffer.poolSize = 8192 // not used by this implementation
  519. function from (value, encodingOrOffset, length) {
  520. if (typeof value === 'number') {
  521. throw new TypeError('"value" argument must not be a number')
  522. }
  523. if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
  524. return fromArrayBuffer(value, encodingOrOffset, length)
  525. }
  526. if (typeof value === 'string') {
  527. return fromString(value, encodingOrOffset)
  528. }
  529. return fromObject(value)
  530. }
  531. /**
  532. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  533. * if value is a number.
  534. * Buffer.from(str[, encoding])
  535. * Buffer.from(array)
  536. * Buffer.from(buffer)
  537. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  538. **/
  539. Buffer.from = function (value, encodingOrOffset, length) {
  540. return from(value, encodingOrOffset, length)
  541. }
  542. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  543. // https://github.com/feross/buffer/pull/148
  544. Buffer.prototype.__proto__ = Uint8Array.prototype
  545. Buffer.__proto__ = Uint8Array
  546. function assertSize (size) {
  547. if (typeof size !== 'number') {
  548. throw new TypeError('"size" argument must be of type number')
  549. } else if (size < 0) {
  550. throw new RangeError('"size" argument must not be negative')
  551. }
  552. }
  553. function alloc (size, fill, encoding) {
  554. assertSize(size)
  555. if (size <= 0) {
  556. return createBuffer(size)
  557. }
  558. if (fill !== undefined) {
  559. // Only pay attention to encoding if it's a string. This
  560. // prevents accidentally sending in a number that would
  561. // be interpretted as a start offset.
  562. return typeof encoding === 'string'
  563. ? createBuffer(size).fill(fill, encoding)
  564. : createBuffer(size).fill(fill)
  565. }
  566. return createBuffer(size)
  567. }
  568. /**
  569. * Creates a new filled Buffer instance.
  570. * alloc(size[, fill[, encoding]])
  571. **/
  572. Buffer.alloc = function (size, fill, encoding) {
  573. return alloc(size, fill, encoding)
  574. }
  575. function allocUnsafe (size) {
  576. assertSize(size)
  577. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  578. }
  579. /**
  580. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  581. * */
  582. Buffer.allocUnsafe = function (size) {
  583. return allocUnsafe(size)
  584. }
  585. /**
  586. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  587. */
  588. Buffer.allocUnsafeSlow = function (size) {
  589. return allocUnsafe(size)
  590. }
  591. function fromString (string, encoding) {
  592. if (typeof encoding !== 'string' || encoding === '') {
  593. encoding = 'utf8'
  594. }
  595. if (!Buffer.isEncoding(encoding)) {
  596. throw new TypeError('Unknown encoding: ' + encoding)
  597. }
  598. var length = byteLength(string, encoding) | 0
  599. var buf = createBuffer(length)
  600. var actual = buf.write(string, encoding)
  601. if (actual !== length) {
  602. // Writing a hex string, for example, that contains invalid characters will
  603. // cause everything after the first invalid character to be ignored. (e.g.
  604. // 'abxxcd' will be treated as 'ab')
  605. buf = buf.slice(0, actual)
  606. }
  607. return buf
  608. }
  609. function fromArrayLike (array) {
  610. var length = array.length < 0 ? 0 : checked(array.length) | 0
  611. var buf = createBuffer(length)
  612. for (var i = 0; i < length; i += 1) {
  613. buf[i] = array[i] & 255
  614. }
  615. return buf
  616. }
  617. function fromArrayBuffer (array, byteOffset, length) {
  618. if (byteOffset < 0 || array.byteLength < byteOffset) {
  619. throw new RangeError('"offset" is outside of buffer bounds')
  620. }
  621. if (array.byteLength < byteOffset + (length || 0)) {
  622. throw new RangeError('"length" is outside of buffer bounds')
  623. }
  624. var buf
  625. if (byteOffset === undefined && length === undefined) {
  626. buf = new Uint8Array(array)
  627. } else if (length === undefined) {
  628. buf = new Uint8Array(array, byteOffset)
  629. } else {
  630. buf = new Uint8Array(array, byteOffset, length)
  631. }
  632. // Return an augmented `Uint8Array` instance
  633. buf.__proto__ = Buffer.prototype
  634. return buf
  635. }
  636. function fromObject (obj) {
  637. if (Buffer.isBuffer(obj)) {
  638. var len = checked(obj.length) | 0
  639. var buf = createBuffer(len)
  640. if (buf.length === 0) {
  641. return buf
  642. }
  643. obj.copy(buf, 0, 0, len)
  644. return buf
  645. }
  646. if (obj) {
  647. if (ArrayBuffer.isView(obj) || 'length' in obj) {
  648. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  649. return createBuffer(0)
  650. }
  651. return fromArrayLike(obj)
  652. }
  653. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  654. return fromArrayLike(obj.data)
  655. }
  656. }
  657. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
  658. }
  659. function checked (length) {
  660. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  661. // length is NaN (which is otherwise coerced to zero.)
  662. if (length >= K_MAX_LENGTH) {
  663. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  664. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  665. }
  666. return length | 0
  667. }
  668. function SlowBuffer (length) {
  669. if (+length != length) { // eslint-disable-line eqeqeq
  670. length = 0
  671. }
  672. return Buffer.alloc(+length)
  673. }
  674. Buffer.isBuffer = function isBuffer (b) {
  675. return b != null && b._isBuffer === true
  676. }
  677. Buffer.compare = function compare (a, b) {
  678. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  679. throw new TypeError('Arguments must be Buffers')
  680. }
  681. if (a === b) return 0
  682. var x = a.length
  683. var y = b.length
  684. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  685. if (a[i] !== b[i]) {
  686. x = a[i]
  687. y = b[i]
  688. break
  689. }
  690. }
  691. if (x < y) return -1
  692. if (y < x) return 1
  693. return 0
  694. }
  695. Buffer.isEncoding = function isEncoding (encoding) {
  696. switch (String(encoding).toLowerCase()) {
  697. case 'hex':
  698. case 'utf8':
  699. case 'utf-8':
  700. case 'ascii':
  701. case 'latin1':
  702. case 'binary':
  703. case 'base64':
  704. case 'ucs2':
  705. case 'ucs-2':
  706. case 'utf16le':
  707. case 'utf-16le':
  708. return true
  709. default:
  710. return false
  711. }
  712. }
  713. Buffer.concat = function concat (list, length) {
  714. if (!Array.isArray(list)) {
  715. throw new TypeError('"list" argument must be an Array of Buffers')
  716. }
  717. if (list.length === 0) {
  718. return Buffer.alloc(0)
  719. }
  720. var i
  721. if (length === undefined) {
  722. length = 0
  723. for (i = 0; i < list.length; ++i) {
  724. length += list[i].length
  725. }
  726. }
  727. var buffer = Buffer.allocUnsafe(length)
  728. var pos = 0
  729. for (i = 0; i < list.length; ++i) {
  730. var buf = list[i]
  731. if (ArrayBuffer.isView(buf)) {
  732. buf = Buffer.from(buf)
  733. }
  734. if (!Buffer.isBuffer(buf)) {
  735. throw new TypeError('"list" argument must be an Array of Buffers')
  736. }
  737. buf.copy(buffer, pos)
  738. pos += buf.length
  739. }
  740. return buffer
  741. }
  742. function byteLength (string, encoding) {
  743. if (Buffer.isBuffer(string)) {
  744. return string.length
  745. }
  746. if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
  747. return string.byteLength
  748. }
  749. if (typeof string !== 'string') {
  750. string = '' + string
  751. }
  752. var len = string.length
  753. if (len === 0) return 0
  754. // Use a for loop to avoid recursion
  755. var loweredCase = false
  756. for (;;) {
  757. switch (encoding) {
  758. case 'ascii':
  759. case 'latin1':
  760. case 'binary':
  761. return len
  762. case 'utf8':
  763. case 'utf-8':
  764. case undefined:
  765. return utf8ToBytes(string).length
  766. case 'ucs2':
  767. case 'ucs-2':
  768. case 'utf16le':
  769. case 'utf-16le':
  770. return len * 2
  771. case 'hex':
  772. return len >>> 1
  773. case 'base64':
  774. return base64ToBytes(string).length
  775. default:
  776. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  777. encoding = ('' + encoding).toLowerCase()
  778. loweredCase = true
  779. }
  780. }
  781. }
  782. Buffer.byteLength = byteLength
  783. function slowToString (encoding, start, end) {
  784. var loweredCase = false
  785. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  786. // property of a typed array.
  787. // This behaves neither like String nor Uint8Array in that we set start/end
  788. // to their upper/lower bounds if the value passed is out of range.
  789. // undefined is handled specially as per ECMA-262 6th Edition,
  790. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  791. if (start === undefined || start < 0) {
  792. start = 0
  793. }
  794. // Return early if start > this.length. Done here to prevent potential uint32
  795. // coercion fail below.
  796. if (start > this.length) {
  797. return ''
  798. }
  799. if (end === undefined || end > this.length) {
  800. end = this.length
  801. }
  802. if (end <= 0) {
  803. return ''
  804. }
  805. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  806. end >>>= 0
  807. start >>>= 0
  808. if (end <= start) {
  809. return ''
  810. }
  811. if (!encoding) encoding = 'utf8'
  812. while (true) {
  813. switch (encoding) {
  814. case 'hex':
  815. return hexSlice(this, start, end)
  816. case 'utf8':
  817. case 'utf-8':
  818. return utf8Slice(this, start, end)
  819. case 'ascii':
  820. return asciiSlice(this, start, end)
  821. case 'latin1':
  822. case 'binary':
  823. return latin1Slice(this, start, end)
  824. case 'base64':
  825. return base64Slice(this, start, end)
  826. case 'ucs2':
  827. case 'ucs-2':
  828. case 'utf16le':
  829. case 'utf-16le':
  830. return utf16leSlice(this, start, end)
  831. default:
  832. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  833. encoding = (encoding + '').toLowerCase()
  834. loweredCase = true
  835. }
  836. }
  837. }
  838. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  839. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  840. // reliably in a browserify context because there could be multiple different
  841. // copies of the 'buffer' package in use. This method works even for Buffer
  842. // instances that were created from another copy of the `buffer` package.
  843. // See: https://github.com/feross/buffer/issues/154
  844. Buffer.prototype._isBuffer = true
  845. function swap (b, n, m) {
  846. var i = b[n]
  847. b[n] = b[m]
  848. b[m] = i
  849. }
  850. Buffer.prototype.swap16 = function swap16 () {
  851. var len = this.length
  852. if (len % 2 !== 0) {
  853. throw new RangeError('Buffer size must be a multiple of 16-bits')
  854. }
  855. for (var i = 0; i < len; i += 2) {
  856. swap(this, i, i + 1)
  857. }
  858. return this
  859. }
  860. Buffer.prototype.swap32 = function swap32 () {
  861. var len = this.length
  862. if (len % 4 !== 0) {
  863. throw new RangeError('Buffer size must be a multiple of 32-bits')
  864. }
  865. for (var i = 0; i < len; i += 4) {
  866. swap(this, i, i + 3)
  867. swap(this, i + 1, i + 2)
  868. }
  869. return this
  870. }
  871. Buffer.prototype.swap64 = function swap64 () {
  872. var len = this.length
  873. if (len % 8 !== 0) {
  874. throw new RangeError('Buffer size must be a multiple of 64-bits')
  875. }
  876. for (var i = 0; i < len; i += 8) {
  877. swap(this, i, i + 7)
  878. swap(this, i + 1, i + 6)
  879. swap(this, i + 2, i + 5)
  880. swap(this, i + 3, i + 4)
  881. }
  882. return this
  883. }
  884. Buffer.prototype.toString = function toString () {
  885. var length = this.length
  886. if (length === 0) return ''
  887. if (arguments.length === 0) return utf8Slice(this, 0, length)
  888. return slowToString.apply(this, arguments)
  889. }
  890. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  891. Buffer.prototype.equals = function equals (b) {
  892. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  893. if (this === b) return true
  894. return Buffer.compare(this, b) === 0
  895. }
  896. Buffer.prototype.inspect = function inspect () {
  897. var str = ''
  898. var max = exports.INSPECT_MAX_BYTES
  899. if (this.length > 0) {
  900. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  901. if (this.length > max) str += ' ... '
  902. }
  903. return '<Buffer ' + str + '>'
  904. }
  905. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  906. if (!Buffer.isBuffer(target)) {
  907. throw new TypeError('Argument must be a Buffer')
  908. }
  909. if (start === undefined) {
  910. start = 0
  911. }
  912. if (end === undefined) {
  913. end = target ? target.length : 0
  914. }
  915. if (thisStart === undefined) {
  916. thisStart = 0
  917. }
  918. if (thisEnd === undefined) {
  919. thisEnd = this.length
  920. }
  921. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  922. throw new RangeError('out of range index')
  923. }
  924. if (thisStart >= thisEnd && start >= end) {
  925. return 0
  926. }
  927. if (thisStart >= thisEnd) {
  928. return -1
  929. }
  930. if (start >= end) {
  931. return 1
  932. }
  933. start >>>= 0
  934. end >>>= 0
  935. thisStart >>>= 0
  936. thisEnd >>>= 0
  937. if (this === target) return 0
  938. var x = thisEnd - thisStart
  939. var y = end - start
  940. var len = Math.min(x, y)
  941. var thisCopy = this.slice(thisStart, thisEnd)
  942. var targetCopy = target.slice(start, end)
  943. for (var i = 0; i < len; ++i) {
  944. if (thisCopy[i] !== targetCopy[i]) {
  945. x = thisCopy[i]
  946. y = targetCopy[i]
  947. break
  948. }
  949. }
  950. if (x < y) return -1
  951. if (y < x) return 1
  952. return 0
  953. }
  954. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  955. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  956. //
  957. // Arguments:
  958. // - buffer - a Buffer to search
  959. // - val - a string, Buffer, or number
  960. // - byteOffset - an index into `buffer`; will be clamped to an int32
  961. // - encoding - an optional encoding, relevant is val is a string
  962. // - dir - true for indexOf, false for lastIndexOf
  963. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  964. // Empty buffer means no match
  965. if (buffer.length === 0) return -1
  966. // Normalize byteOffset
  967. if (typeof byteOffset === 'string') {
  968. encoding = byteOffset
  969. byteOffset = 0
  970. } else if (byteOffset > 0x7fffffff) {
  971. byteOffset = 0x7fffffff
  972. } else if (byteOffset < -0x80000000) {
  973. byteOffset = -0x80000000
  974. }
  975. byteOffset = +byteOffset // Coerce to Number.
  976. if (numberIsNaN(byteOffset)) {
  977. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  978. byteOffset = dir ? 0 : (buffer.length - 1)
  979. }
  980. // Normalize byteOffset: negative offsets start from the end of the buffer
  981. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  982. if (byteOffset >= buffer.length) {
  983. if (dir) return -1
  984. else byteOffset = buffer.length - 1
  985. } else if (byteOffset < 0) {
  986. if (dir) byteOffset = 0
  987. else return -1
  988. }
  989. // Normalize val
  990. if (typeof val === 'string') {
  991. val = Buffer.from(val, encoding)
  992. }
  993. // Finally, search either indexOf (if dir is true) or lastIndexOf
  994. if (Buffer.isBuffer(val)) {
  995. // Special case: looking for empty string/buffer always fails
  996. if (val.length === 0) {
  997. return -1
  998. }
  999. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  1000. } else if (typeof val === 'number') {
  1001. val = val & 0xFF // Search for a byte value [0-255]
  1002. if (typeof Uint8Array.prototype.indexOf === 'function') {
  1003. if (dir) {
  1004. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  1005. } else {
  1006. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  1007. }
  1008. }
  1009. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  1010. }
  1011. throw new TypeError('val must be string, number or Buffer')
  1012. }
  1013. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  1014. var indexSize = 1
  1015. var arrLength = arr.length
  1016. var valLength = val.length
  1017. if (encoding !== undefined) {
  1018. encoding = String(encoding).toLowerCase()
  1019. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  1020. encoding === 'utf16le' || encoding === 'utf-16le') {
  1021. if (arr.length < 2 || val.length < 2) {
  1022. return -1
  1023. }
  1024. indexSize = 2
  1025. arrLength /= 2
  1026. valLength /= 2
  1027. byteOffset /= 2
  1028. }
  1029. }
  1030. function read (buf, i) {
  1031. if (indexSize === 1) {
  1032. return buf[i]
  1033. } else {
  1034. return buf.readUInt16BE(i * indexSize)
  1035. }
  1036. }
  1037. var i
  1038. if (dir) {
  1039. var foundIndex = -1
  1040. for (i = byteOffset; i < arrLength; i++) {
  1041. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  1042. if (foundIndex === -1) foundIndex = i
  1043. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  1044. } else {
  1045. if (foundIndex !== -1) i -= i - foundIndex
  1046. foundIndex = -1
  1047. }
  1048. }
  1049. } else {
  1050. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  1051. for (i = byteOffset; i >= 0; i--) {
  1052. var found = true
  1053. for (var j = 0; j < valLength; j++) {
  1054. if (read(arr, i + j) !== read(val, j)) {
  1055. found = false
  1056. break
  1057. }
  1058. }
  1059. if (found) return i
  1060. }
  1061. }
  1062. return -1
  1063. }
  1064. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  1065. return this.indexOf(val, byteOffset, encoding) !== -1
  1066. }
  1067. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  1068. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  1069. }
  1070. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  1071. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  1072. }
  1073. function hexWrite (buf, string, offset, length) {
  1074. offset = Number(offset) || 0
  1075. var remaining = buf.length - offset
  1076. if (!length) {
  1077. length = remaining
  1078. } else {
  1079. length = Number(length)
  1080. if (length > remaining) {
  1081. length = remaining
  1082. }
  1083. }
  1084. var strLen = string.length
  1085. if (length > strLen / 2) {
  1086. length = strLen / 2
  1087. }
  1088. for (var i = 0; i < length; ++i) {
  1089. var parsed = parseInt(string.substr(i * 2, 2), 16)
  1090. if (numberIsNaN(parsed)) return i
  1091. buf[offset + i] = parsed
  1092. }
  1093. return i
  1094. }
  1095. function utf8Write (buf, string, offset, length) {
  1096. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  1097. }
  1098. function asciiWrite (buf, string, offset, length) {
  1099. return blitBuffer(asciiToBytes(string), buf, offset, length)
  1100. }
  1101. function latin1Write (buf, string, offset, length) {
  1102. return asciiWrite(buf, string, offset, length)
  1103. }
  1104. function base64Write (buf, string, offset, length) {
  1105. return blitBuffer(base64ToBytes(string), buf, offset, length)
  1106. }
  1107. function ucs2Write (buf, string, offset, length) {
  1108. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  1109. }
  1110. Buffer.prototype.write = function write (string, offset, length, encoding) {
  1111. // Buffer#write(string)
  1112. if (offset === undefined) {
  1113. encoding = 'utf8'
  1114. length = this.length
  1115. offset = 0
  1116. // Buffer#write(string, encoding)
  1117. } else if (length === undefined && typeof offset === 'string') {
  1118. encoding = offset
  1119. length = this.length
  1120. offset = 0
  1121. // Buffer#write(string, offset[, length][, encoding])
  1122. } else if (isFinite(offset)) {
  1123. offset = offset >>> 0
  1124. if (isFinite(length)) {
  1125. length = length >>> 0
  1126. if (encoding === undefined) encoding = 'utf8'
  1127. } else {
  1128. encoding = length
  1129. length = undefined
  1130. }
  1131. } else {
  1132. throw new Error(
  1133. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  1134. )
  1135. }
  1136. var remaining = this.length - offset
  1137. if (length === undefined || length > remaining) length = remaining
  1138. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  1139. throw new RangeError('Attempt to write outside buffer bounds')
  1140. }
  1141. if (!encoding) encoding = 'utf8'
  1142. var loweredCase = false
  1143. for (;;) {
  1144. switch (encoding) {
  1145. case 'hex':
  1146. return hexWrite(this, string, offset, length)
  1147. case 'utf8':
  1148. case 'utf-8':
  1149. return utf8Write(this, string, offset, length)
  1150. case 'ascii':
  1151. return asciiWrite(this, string, offset, length)
  1152. case 'latin1':
  1153. case 'binary':
  1154. return latin1Write(this, string, offset, length)
  1155. case 'base64':
  1156. // Warning: maxLength not taken into account in base64Write
  1157. return base64Write(this, string, offset, length)
  1158. case 'ucs2':
  1159. case 'ucs-2':
  1160. case 'utf16le':
  1161. case 'utf-16le':
  1162. return ucs2Write(this, string, offset, length)
  1163. default:
  1164. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1165. encoding = ('' + encoding).toLowerCase()
  1166. loweredCase = true
  1167. }
  1168. }
  1169. }
  1170. Buffer.prototype.toJSON = function toJSON () {
  1171. return {
  1172. type: 'Buffer',
  1173. data: Array.prototype.slice.call(this._arr || this, 0)
  1174. }
  1175. }
  1176. function base64Slice (buf, start, end) {
  1177. if (start === 0 && end === buf.length) {
  1178. return base64.fromByteArray(buf)
  1179. } else {
  1180. return base64.fromByteArray(buf.slice(start, end))
  1181. }
  1182. }
  1183. function utf8Slice (buf, start, end) {
  1184. end = Math.min(buf.length, end)
  1185. var res = []
  1186. var i = start
  1187. while (i < end) {
  1188. var firstByte = buf[i]
  1189. var codePoint = null
  1190. var bytesPerSequence = (firstByte > 0xEF) ? 4
  1191. : (firstByte > 0xDF) ? 3
  1192. : (firstByte > 0xBF) ? 2
  1193. : 1
  1194. if (i + bytesPerSequence <= end) {
  1195. var secondByte, thirdByte, fourthByte, tempCodePoint
  1196. switch (bytesPerSequence) {
  1197. case 1:
  1198. if (firstByte < 0x80) {
  1199. codePoint = firstByte
  1200. }
  1201. break
  1202. case 2:
  1203. secondByte = buf[i + 1]
  1204. if ((secondByte & 0xC0) === 0x80) {
  1205. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  1206. if (tempCodePoint > 0x7F) {
  1207. codePoint = tempCodePoint
  1208. }
  1209. }
  1210. break
  1211. case 3:
  1212. secondByte = buf[i + 1]
  1213. thirdByte = buf[i + 2]
  1214. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  1215. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  1216. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  1217. codePoint = tempCodePoint
  1218. }
  1219. }
  1220. break
  1221. case 4:
  1222. secondByte = buf[i + 1]
  1223. thirdByte = buf[i + 2]
  1224. fourthByte = buf[i + 3]
  1225. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  1226. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  1227. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  1228. codePoint = tempCodePoint
  1229. }
  1230. }
  1231. }
  1232. }
  1233. if (codePoint === null) {
  1234. // we did not generate a valid codePoint so insert a
  1235. // replacement char (U+FFFD) and advance only 1 byte
  1236. codePoint = 0xFFFD
  1237. bytesPerSequence = 1
  1238. } else if (codePoint > 0xFFFF) {
  1239. // encode to utf16 (surrogate pair dance)
  1240. codePoint -= 0x10000
  1241. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  1242. codePoint = 0xDC00 | codePoint & 0x3FF
  1243. }
  1244. res.push(codePoint)
  1245. i += bytesPerSequence
  1246. }
  1247. return decodeCodePointsArray(res)
  1248. }
  1249. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1250. // the lowest limit is Chrome, with 0x10000 args.
  1251. // We go 1 magnitude less, for safety
  1252. var MAX_ARGUMENTS_LENGTH = 0x1000
  1253. function decodeCodePointsArray (codePoints) {
  1254. var len = codePoints.length
  1255. if (len <= MAX_ARGUMENTS_LENGTH) {
  1256. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1257. }
  1258. // Decode in chunks to avoid "call stack size exceeded".
  1259. var res = ''
  1260. var i = 0
  1261. while (i < len) {
  1262. res += String.fromCharCode.apply(
  1263. String,
  1264. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1265. )
  1266. }
  1267. return res
  1268. }
  1269. function asciiSlice (buf, start, end) {
  1270. var ret = ''
  1271. end = Math.min(buf.length, end)
  1272. for (var i = start; i < end; ++i) {
  1273. ret += String.fromCharCode(buf[i] & 0x7F)
  1274. }
  1275. return ret
  1276. }
  1277. function latin1Slice (buf, start, end) {
  1278. var ret = ''
  1279. end = Math.min(buf.length, end)
  1280. for (var i = start; i < end; ++i) {
  1281. ret += String.fromCharCode(buf[i])
  1282. }
  1283. return ret
  1284. }
  1285. function hexSlice (buf, start, end) {
  1286. var len = buf.length
  1287. if (!start || start < 0) start = 0
  1288. if (!end || end < 0 || end > len) end = len
  1289. var out = ''
  1290. for (var i = start; i < end; ++i) {
  1291. out += toHex(buf[i])
  1292. }
  1293. return out
  1294. }
  1295. function utf16leSlice (buf, start, end) {
  1296. var bytes = buf.slice(start, end)
  1297. var res = ''
  1298. for (var i = 0; i < bytes.length; i += 2) {
  1299. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  1300. }
  1301. return res
  1302. }
  1303. Buffer.prototype.slice = function slice (start, end) {
  1304. var len = this.length
  1305. start = ~~start
  1306. end = end === undefined ? len : ~~end
  1307. if (start < 0) {
  1308. start += len
  1309. if (start < 0) start = 0
  1310. } else if (start > len) {
  1311. start = len
  1312. }
  1313. if (end < 0) {
  1314. end += len
  1315. if (end < 0) end = 0
  1316. } else if (end > len) {
  1317. end = len
  1318. }
  1319. if (end < start) end = start
  1320. var newBuf = this.subarray(start, end)
  1321. // Return an augmented `Uint8Array` instance
  1322. newBuf.__proto__ = Buffer.prototype
  1323. return newBuf
  1324. }
  1325. /*
  1326. * Need to make sure that buffer isn't trying to write out of bounds.
  1327. */
  1328. function checkOffset (offset, ext, length) {
  1329. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1330. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1331. }
  1332. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1333. offset = offset >>> 0
  1334. byteLength = byteLength >>> 0
  1335. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1336. var val = this[offset]
  1337. var mul = 1
  1338. var i = 0
  1339. while (++i < byteLength && (mul *= 0x100)) {
  1340. val += this[offset + i] * mul
  1341. }
  1342. return val
  1343. }
  1344. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1345. offset = offset >>> 0
  1346. byteLength = byteLength >>> 0
  1347. if (!noAssert) {
  1348. checkOffset(offset, byteLength, this.length)
  1349. }
  1350. var val = this[offset + --byteLength]
  1351. var mul = 1
  1352. while (byteLength > 0 && (mul *= 0x100)) {
  1353. val += this[offset + --byteLength] * mul
  1354. }
  1355. return val
  1356. }
  1357. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1358. offset = offset >>> 0
  1359. if (!noAssert) checkOffset(offset, 1, this.length)
  1360. return this[offset]
  1361. }
  1362. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1363. offset = offset >>> 0
  1364. if (!noAssert) checkOffset(offset, 2, this.length)
  1365. return this[offset] | (this[offset + 1] << 8)
  1366. }
  1367. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1368. offset = offset >>> 0
  1369. if (!noAssert) checkOffset(offset, 2, this.length)
  1370. return (this[offset] << 8) | this[offset + 1]
  1371. }
  1372. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1373. offset = offset >>> 0
  1374. if (!noAssert) checkOffset(offset, 4, this.length)
  1375. return ((this[offset]) |
  1376. (this[offset + 1] << 8) |
  1377. (this[offset + 2] << 16)) +
  1378. (this[offset + 3] * 0x1000000)
  1379. }
  1380. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1381. offset = offset >>> 0
  1382. if (!noAssert) checkOffset(offset, 4, this.length)
  1383. return (this[offset] * 0x1000000) +
  1384. ((this[offset + 1] << 16) |
  1385. (this[offset + 2] << 8) |
  1386. this[offset + 3])
  1387. }
  1388. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1389. offset = offset >>> 0
  1390. byteLength = byteLength >>> 0
  1391. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1392. var val = this[offset]
  1393. var mul = 1
  1394. var i = 0
  1395. while (++i < byteLength && (mul *= 0x100)) {
  1396. val += this[offset + i] * mul
  1397. }
  1398. mul *= 0x80
  1399. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1400. return val
  1401. }
  1402. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1403. offset = offset >>> 0
  1404. byteLength = byteLength >>> 0
  1405. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1406. var i = byteLength
  1407. var mul = 1
  1408. var val = this[offset + --i]
  1409. while (i > 0 && (mul *= 0x100)) {
  1410. val += this[offset + --i] * mul
  1411. }
  1412. mul *= 0x80
  1413. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1414. return val
  1415. }
  1416. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1417. offset = offset >>> 0
  1418. if (!noAssert) checkOffset(offset, 1, this.length)
  1419. if (!(this[offset] & 0x80)) return (this[offset])
  1420. return ((0xff - this[offset] + 1) * -1)
  1421. }
  1422. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1423. offset = offset >>> 0
  1424. if (!noAssert) checkOffset(offset, 2, this.length)
  1425. var val = this[offset] | (this[offset + 1] << 8)
  1426. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1427. }
  1428. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1429. offset = offset >>> 0
  1430. if (!noAssert) checkOffset(offset, 2, this.length)
  1431. var val = this[offset + 1] | (this[offset] << 8)
  1432. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1433. }
  1434. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1435. offset = offset >>> 0
  1436. if (!noAssert) checkOffset(offset, 4, this.length)
  1437. return (this[offset]) |
  1438. (this[offset + 1] << 8) |
  1439. (this[offset + 2] << 16) |
  1440. (this[offset + 3] << 24)
  1441. }
  1442. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1443. offset = offset >>> 0
  1444. if (!noAssert) checkOffset(offset, 4, this.length)
  1445. return (this[offset] << 24) |
  1446. (this[offset + 1] << 16) |
  1447. (this[offset + 2] << 8) |
  1448. (this[offset + 3])
  1449. }
  1450. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1451. offset = offset >>> 0
  1452. if (!noAssert) checkOffset(offset, 4, this.length)
  1453. return ieee754.read(this, offset, true, 23, 4)
  1454. }
  1455. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1456. offset = offset >>> 0
  1457. if (!noAssert) checkOffset(offset, 4, this.length)
  1458. return ieee754.read(this, offset, false, 23, 4)
  1459. }
  1460. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1461. offset = offset >>> 0
  1462. if (!noAssert) checkOffset(offset, 8, this.length)
  1463. return ieee754.read(this, offset, true, 52, 8)
  1464. }
  1465. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1466. offset = offset >>> 0
  1467. if (!noAssert) checkOffset(offset, 8, this.length)
  1468. return ieee754.read(this, offset, false, 52, 8)
  1469. }
  1470. function checkInt (buf, value, offset, ext, max, min) {
  1471. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1472. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1473. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1474. }
  1475. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1476. value = +value
  1477. offset = offset >>> 0
  1478. byteLength = byteLength >>> 0
  1479. if (!noAssert) {
  1480. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1481. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1482. }
  1483. var mul = 1
  1484. var i = 0
  1485. this[offset] = value & 0xFF
  1486. while (++i < byteLength && (mul *= 0x100)) {
  1487. this[offset + i] = (value / mul) & 0xFF
  1488. }
  1489. return offset + byteLength
  1490. }
  1491. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1492. value = +value
  1493. offset = offset >>> 0
  1494. byteLength = byteLength >>> 0
  1495. if (!noAssert) {
  1496. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1497. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1498. }
  1499. var i = byteLength - 1
  1500. var mul = 1
  1501. this[offset + i] = value & 0xFF
  1502. while (--i >= 0 && (mul *= 0x100)) {
  1503. this[offset + i] = (value / mul) & 0xFF
  1504. }
  1505. return offset + byteLength
  1506. }
  1507. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1508. value = +value
  1509. offset = offset >>> 0
  1510. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1511. this[offset] = (value & 0xff)
  1512. return offset + 1
  1513. }
  1514. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1515. value = +value
  1516. offset = offset >>> 0
  1517. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1518. this[offset] = (value & 0xff)
  1519. this[offset + 1] = (value >>> 8)
  1520. return offset + 2
  1521. }
  1522. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1523. value = +value
  1524. offset = offset >>> 0
  1525. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1526. this[offset] = (value >>> 8)
  1527. this[offset + 1] = (value & 0xff)
  1528. return offset + 2
  1529. }
  1530. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1531. value = +value
  1532. offset = offset >>> 0
  1533. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1534. this[offset + 3] = (value >>> 24)
  1535. this[offset + 2] = (value >>> 16)
  1536. this[offset + 1] = (value >>> 8)
  1537. this[offset] = (value & 0xff)
  1538. return offset + 4
  1539. }
  1540. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1541. value = +value
  1542. offset = offset >>> 0
  1543. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1544. this[offset] = (value >>> 24)
  1545. this[offset + 1] = (value >>> 16)
  1546. this[offset + 2] = (value >>> 8)
  1547. this[offset + 3] = (value & 0xff)
  1548. return offset + 4
  1549. }
  1550. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1551. value = +value
  1552. offset = offset >>> 0
  1553. if (!noAssert) {
  1554. var limit = Math.pow(2, (8 * byteLength) - 1)
  1555. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1556. }
  1557. var i = 0
  1558. var mul = 1
  1559. var sub = 0
  1560. this[offset] = value & 0xFF
  1561. while (++i < byteLength && (mul *= 0x100)) {
  1562. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1563. sub = 1
  1564. }
  1565. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1566. }
  1567. return offset + byteLength
  1568. }
  1569. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1570. value = +value
  1571. offset = offset >>> 0
  1572. if (!noAssert) {
  1573. var limit = Math.pow(2, (8 * byteLength) - 1)
  1574. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1575. }
  1576. var i = byteLength - 1
  1577. var mul = 1
  1578. var sub = 0
  1579. this[offset + i] = value & 0xFF
  1580. while (--i >= 0 && (mul *= 0x100)) {
  1581. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1582. sub = 1
  1583. }
  1584. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1585. }
  1586. return offset + byteLength
  1587. }
  1588. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1589. value = +value
  1590. offset = offset >>> 0
  1591. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1592. if (value < 0) value = 0xff + value + 1
  1593. this[offset] = (value & 0xff)
  1594. return offset + 1
  1595. }
  1596. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1597. value = +value
  1598. offset = offset >>> 0
  1599. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1600. this[offset] = (value & 0xff)
  1601. this[offset + 1] = (value >>> 8)
  1602. return offset + 2
  1603. }
  1604. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1605. value = +value
  1606. offset = offset >>> 0
  1607. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1608. this[offset] = (value >>> 8)
  1609. this[offset + 1] = (value & 0xff)
  1610. return offset + 2
  1611. }
  1612. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1613. value = +value
  1614. offset = offset >>> 0
  1615. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1616. this[offset] = (value & 0xff)
  1617. this[offset + 1] = (value >>> 8)
  1618. this[offset + 2] = (value >>> 16)
  1619. this[offset + 3] = (value >>> 24)
  1620. return offset + 4
  1621. }
  1622. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1623. value = +value
  1624. offset = offset >>> 0
  1625. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1626. if (value < 0) value = 0xffffffff + value + 1
  1627. this[offset] = (value >>> 24)
  1628. this[offset + 1] = (value >>> 16)
  1629. this[offset + 2] = (value >>> 8)
  1630. this[offset + 3] = (value & 0xff)
  1631. return offset + 4
  1632. }
  1633. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1634. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1635. if (offset < 0) throw new RangeError('Index out of range')
  1636. }
  1637. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1638. value = +value
  1639. offset = offset >>> 0
  1640. if (!noAssert) {
  1641. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1642. }
  1643. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1644. return offset + 4
  1645. }
  1646. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1647. return writeFloat(this, value, offset, true, noAssert)
  1648. }
  1649. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1650. return writeFloat(this, value, offset, false, noAssert)
  1651. }
  1652. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1653. value = +value
  1654. offset = offset >>> 0
  1655. if (!noAssert) {
  1656. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1657. }
  1658. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1659. return offset + 8
  1660. }
  1661. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1662. return writeDouble(this, value, offset, true, noAssert)
  1663. }
  1664. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1665. return writeDouble(this, value, offset, false, noAssert)
  1666. }
  1667. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1668. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  1669. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  1670. if (!start) start = 0
  1671. if (!end && end !== 0) end = this.length
  1672. if (targetStart >= target.length) targetStart = target.length
  1673. if (!targetStart) targetStart = 0
  1674. if (end > 0 && end < start) end = start
  1675. // Copy 0 bytes; we're done
  1676. if (end === start) return 0
  1677. if (target.length === 0 || this.length === 0) return 0
  1678. // Fatal error conditions
  1679. if (targetStart < 0) {
  1680. throw new RangeError('targetStart out of bounds')
  1681. }
  1682. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  1683. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1684. // Are we oob?
  1685. if (end > this.length) end = this.length
  1686. if (target.length - targetStart < end - start) {
  1687. end = target.length - targetStart + start
  1688. }
  1689. var len = end - start
  1690. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1691. // Use built-in when available, missing from IE11
  1692. this.copyWithin(targetStart, start, end)
  1693. } else if (this === target && start < targetStart && targetStart < end) {
  1694. // descending copy from end
  1695. for (var i = len - 1; i >= 0; --i) {
  1696. target[i + targetStart] = this[i + start]
  1697. }
  1698. } else {
  1699. Uint8Array.prototype.set.call(
  1700. target,
  1701. this.subarray(start, end),
  1702. targetStart
  1703. )
  1704. }
  1705. return len
  1706. }
  1707. // Usage:
  1708. // buffer.fill(number[, offset[, end]])
  1709. // buffer.fill(buffer[, offset[, end]])
  1710. // buffer.fill(string[, offset[, end]][, encoding])
  1711. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  1712. // Handle string cases:
  1713. if (typeof val === 'string') {
  1714. if (typeof start === 'string') {
  1715. encoding = start
  1716. start = 0
  1717. end = this.length
  1718. } else if (typeof end === 'string') {
  1719. encoding = end
  1720. end = this.length
  1721. }
  1722. if (encoding !== undefined && typeof encoding !== 'string') {
  1723. throw new TypeError('encoding must be a string')
  1724. }
  1725. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1726. throw new TypeError('Unknown encoding: ' + encoding)
  1727. }
  1728. if (val.length === 1) {
  1729. var code = val.charCodeAt(0)
  1730. if ((encoding === 'utf8' && code < 128) ||
  1731. encoding === 'latin1') {
  1732. // Fast path: If `val` fits into a single byte, use that numeric value.
  1733. val = code
  1734. }
  1735. }
  1736. } else if (typeof val === 'number') {
  1737. val = val & 255
  1738. }
  1739. // Invalid ranges are not set to a default, so can range check early.
  1740. if (start < 0 || this.length < start || this.length < end) {
  1741. throw new RangeError('Out of range index')
  1742. }
  1743. if (end <= start) {
  1744. return this
  1745. }
  1746. start = start >>> 0
  1747. end = end === undefined ? this.length : end >>> 0
  1748. if (!val) val = 0
  1749. var i
  1750. if (typeof val === 'number') {
  1751. for (i = start; i < end; ++i) {
  1752. this[i] = val
  1753. }
  1754. } else {
  1755. var bytes = Buffer.isBuffer(val)
  1756. ? val
  1757. : new Buffer(val, encoding)
  1758. var len = bytes.length
  1759. if (len === 0) {
  1760. throw new TypeError('The value "' + val +
  1761. '" is invalid for argument "value"')
  1762. }
  1763. for (i = 0; i < end - start; ++i) {
  1764. this[i + start] = bytes[i % len]
  1765. }
  1766. }
  1767. return this
  1768. }
  1769. // HELPER FUNCTIONS
  1770. // ================
  1771. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  1772. function base64clean (str) {
  1773. // Node takes equal signs as end of the Base64 encoding
  1774. str = str.split('=')[0]
  1775. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1776. str = str.trim().replace(INVALID_BASE64_RE, '')
  1777. // Node converts strings with length < 2 to ''
  1778. if (str.length < 2) return ''
  1779. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1780. while (str.length % 4 !== 0) {
  1781. str = str + '='
  1782. }
  1783. return str
  1784. }
  1785. function toHex (n) {
  1786. if (n < 16) return '0' + n.toString(16)
  1787. return n.toString(16)
  1788. }
  1789. function utf8ToBytes (string, units) {
  1790. units = units || Infinity
  1791. var codePoint
  1792. var length = string.length
  1793. var leadSurrogate = null
  1794. var bytes = []
  1795. for (var i = 0; i < length; ++i) {
  1796. codePoint = string.charCodeAt(i)
  1797. // is surrogate component
  1798. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1799. // last char was a lead
  1800. if (!leadSurrogate) {
  1801. // no lead yet
  1802. if (codePoint > 0xDBFF) {
  1803. // unexpected trail
  1804. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1805. continue
  1806. } else if (i + 1 === length) {
  1807. // unpaired lead
  1808. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1809. continue
  1810. }
  1811. // valid lead
  1812. leadSurrogate = codePoint
  1813. continue
  1814. }
  1815. // 2 leads in a row
  1816. if (codePoint < 0xDC00) {
  1817. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1818. leadSurrogate = codePoint
  1819. continue
  1820. }
  1821. // valid surrogate pair
  1822. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1823. } else if (leadSurrogate) {
  1824. // valid bmp char, but last char was a lead
  1825. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1826. }
  1827. leadSurrogate = null
  1828. // encode utf8
  1829. if (codePoint < 0x80) {
  1830. if ((units -= 1) < 0) break
  1831. bytes.push(codePoint)
  1832. } else if (codePoint < 0x800) {
  1833. if ((units -= 2) < 0) break
  1834. bytes.push(
  1835. codePoint >> 0x6 | 0xC0,
  1836. codePoint & 0x3F | 0x80
  1837. )
  1838. } else if (codePoint < 0x10000) {
  1839. if ((units -= 3) < 0) break
  1840. bytes.push(
  1841. codePoint >> 0xC | 0xE0,
  1842. codePoint >> 0x6 & 0x3F | 0x80,
  1843. codePoint & 0x3F | 0x80
  1844. )
  1845. } else if (codePoint < 0x110000) {
  1846. if ((units -= 4) < 0) break
  1847. bytes.push(
  1848. codePoint >> 0x12 | 0xF0,
  1849. codePoint >> 0xC & 0x3F | 0x80,
  1850. codePoint >> 0x6 & 0x3F | 0x80,
  1851. codePoint & 0x3F | 0x80
  1852. )
  1853. } else {
  1854. throw new Error('Invalid code point')
  1855. }
  1856. }
  1857. return bytes
  1858. }
  1859. function asciiToBytes (str) {
  1860. var byteArray = []
  1861. for (var i = 0; i < str.length; ++i) {
  1862. // Node's code seems to be doing this and not & 0x7F..
  1863. byteArray.push(str.charCodeAt(i) & 0xFF)
  1864. }
  1865. return byteArray
  1866. }
  1867. function utf16leToBytes (str, units) {
  1868. var c, hi, lo
  1869. var byteArray = []
  1870. for (var i = 0; i < str.length; ++i) {
  1871. if ((units -= 2) < 0) break
  1872. c = str.charCodeAt(i)
  1873. hi = c >> 8
  1874. lo = c % 256
  1875. byteArray.push(lo)
  1876. byteArray.push(hi)
  1877. }
  1878. return byteArray
  1879. }
  1880. function base64ToBytes (str) {
  1881. return base64.toByteArray(base64clean(str))
  1882. }
  1883. function blitBuffer (src, dst, offset, length) {
  1884. for (var i = 0; i < length; ++i) {
  1885. if ((i + offset >= dst.length) || (i >= src.length)) break
  1886. dst[i + offset] = src[i]
  1887. }
  1888. return i
  1889. }
  1890. // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
  1891. // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
  1892. function isArrayBuffer (obj) {
  1893. return obj instanceof ArrayBuffer ||
  1894. (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
  1895. typeof obj.byteLength === 'number')
  1896. }
  1897. function numberIsNaN (obj) {
  1898. return obj !== obj // eslint-disable-line no-self-compare
  1899. }
  1900. },{"base64-js":4,"ieee754":6}],6:[function(require,module,exports){
  1901. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  1902. var e, m
  1903. var eLen = (nBytes * 8) - mLen - 1
  1904. var eMax = (1 << eLen) - 1
  1905. var eBias = eMax >> 1
  1906. var nBits = -7
  1907. var i = isLE ? (nBytes - 1) : 0
  1908. var d = isLE ? -1 : 1
  1909. var s = buffer[offset + i]
  1910. i += d
  1911. e = s & ((1 << (-nBits)) - 1)
  1912. s >>= (-nBits)
  1913. nBits += eLen
  1914. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  1915. m = e & ((1 << (-nBits)) - 1)
  1916. e >>= (-nBits)
  1917. nBits += mLen
  1918. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  1919. if (e === 0) {
  1920. e = 1 - eBias
  1921. } else if (e === eMax) {
  1922. return m ? NaN : ((s ? -1 : 1) * Infinity)
  1923. } else {
  1924. m = m + Math.pow(2, mLen)
  1925. e = e - eBias
  1926. }
  1927. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  1928. }
  1929. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  1930. var e, m, c
  1931. var eLen = (nBytes * 8) - mLen - 1
  1932. var eMax = (1 << eLen) - 1
  1933. var eBias = eMax >> 1
  1934. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  1935. var i = isLE ? 0 : (nBytes - 1)
  1936. var d = isLE ? 1 : -1
  1937. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  1938. value = Math.abs(value)
  1939. if (isNaN(value) || value === Infinity) {
  1940. m = isNaN(value) ? 1 : 0
  1941. e = eMax
  1942. } else {
  1943. e = Math.floor(Math.log(value) / Math.LN2)
  1944. if (value * (c = Math.pow(2, -e)) < 1) {
  1945. e--
  1946. c *= 2
  1947. }
  1948. if (e + eBias >= 1) {
  1949. value += rt / c
  1950. } else {
  1951. value += rt * Math.pow(2, 1 - eBias)
  1952. }
  1953. if (value * c >= 2) {
  1954. e++
  1955. c /= 2
  1956. }
  1957. if (e + eBias >= eMax) {
  1958. m = 0
  1959. e = eMax
  1960. } else if (e + eBias >= 1) {
  1961. m = ((value * c) - 1) * Math.pow(2, mLen)
  1962. e = e + eBias
  1963. } else {
  1964. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  1965. e = 0
  1966. }
  1967. }
  1968. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  1969. e = (e << mLen) | m
  1970. eLen += mLen
  1971. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  1972. buffer[offset + i - d] |= s * 128
  1973. }
  1974. },{}],7:[function(require,module,exports){
  1975. /*!
  1976. * Determine if an object is a Buffer
  1977. *
  1978. * @author Feross Aboukhadijeh <https://feross.org>
  1979. * @license MIT
  1980. */
  1981. // The _isBuffer check is for Safari 5-7 support, because it's missing
  1982. // Object.prototype.constructor. Remove this eventually
  1983. module.exports = function (obj) {
  1984. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  1985. }
  1986. function isBuffer (obj) {
  1987. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  1988. }
  1989. // For Node v0.10 support. Remove this eventually.
  1990. function isSlowBuffer (obj) {
  1991. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  1992. }
  1993. },{}],8:[function(require,module,exports){
  1994. // Generated by CoffeeScript 1.12.7
  1995. (function() {
  1996. var assign, isArray, isEmpty, isFunction, isObject, isPlainObject,
  1997. slice = [].slice,
  1998. hasProp = {}.hasOwnProperty;
  1999. assign = function() {
  2000. var i, key, len, source, sources, target;
  2001. target = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  2002. if (isFunction(Object.assign)) {
  2003. Object.assign.apply(null, arguments);
  2004. } else {
  2005. for (i = 0, len = sources.length; i < len; i++) {
  2006. source = sources[i];
  2007. if (source != null) {
  2008. for (key in source) {
  2009. if (!hasProp.call(source, key)) continue;
  2010. target[key] = source[key];
  2011. }
  2012. }
  2013. }
  2014. }
  2015. return target;
  2016. };
  2017. isFunction = function(val) {
  2018. return !!val && Object.prototype.toString.call(val) === '[object Function]';
  2019. };
  2020. isObject = function(val) {
  2021. var ref;
  2022. return !!val && ((ref = typeof val) === 'function' || ref === 'object');
  2023. };
  2024. isArray = function(val) {
  2025. if (isFunction(Array.isArray)) {
  2026. return Array.isArray(val);
  2027. } else {
  2028. return Object.prototype.toString.call(val) === '[object Array]';
  2029. }
  2030. };
  2031. isEmpty = function(val) {
  2032. var key;
  2033. if (isArray(val)) {
  2034. return !val.length;
  2035. } else {
  2036. for (key in val) {
  2037. if (!hasProp.call(val, key)) continue;
  2038. return false;
  2039. }
  2040. return true;
  2041. }
  2042. };
  2043. isPlainObject = function(val) {
  2044. var ctor, proto;
  2045. 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));
  2046. };
  2047. module.exports.assign = assign;
  2048. module.exports.isFunction = isFunction;
  2049. module.exports.isObject = isObject;
  2050. module.exports.isArray = isArray;
  2051. module.exports.isEmpty = isEmpty;
  2052. module.exports.isPlainObject = isPlainObject;
  2053. }).call(this);
  2054. },{}],9:[function(require,module,exports){
  2055. // Generated by CoffeeScript 1.12.7
  2056. (function() {
  2057. var XMLAttribute;
  2058. module.exports = XMLAttribute = (function() {
  2059. function XMLAttribute(parent, name, value) {
  2060. this.options = parent.options;
  2061. this.stringify = parent.stringify;
  2062. if (name == null) {
  2063. throw new Error("Missing attribute name of element " + parent.name);
  2064. }
  2065. if (value == null) {
  2066. throw new Error("Missing attribute value for attribute " + name + " of element " + parent.name);
  2067. }
  2068. this.name = this.stringify.attName(name);
  2069. this.value = this.stringify.attValue(value);
  2070. }
  2071. XMLAttribute.prototype.clone = function() {
  2072. return Object.create(this);
  2073. };
  2074. XMLAttribute.prototype.toString = function(options) {
  2075. return this.options.writer.set(options).attribute(this);
  2076. };
  2077. return XMLAttribute;
  2078. })();
  2079. }).call(this);
  2080. },{}],10:[function(require,module,exports){
  2081. // Generated by CoffeeScript 1.12.7
  2082. (function() {
  2083. var XMLCData, XMLNode,
  2084. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2085. hasProp = {}.hasOwnProperty;
  2086. XMLNode = require('./XMLNode');
  2087. module.exports = XMLCData = (function(superClass) {
  2088. extend(XMLCData, superClass);
  2089. function XMLCData(parent, text) {
  2090. XMLCData.__super__.constructor.call(this, parent);
  2091. if (text == null) {
  2092. throw new Error("Missing CDATA text");
  2093. }
  2094. this.text = this.stringify.cdata(text);
  2095. }
  2096. XMLCData.prototype.clone = function() {
  2097. return Object.create(this);
  2098. };
  2099. XMLCData.prototype.toString = function(options) {
  2100. return this.options.writer.set(options).cdata(this);
  2101. };
  2102. return XMLCData;
  2103. })(XMLNode);
  2104. }).call(this);
  2105. },{"./XMLNode":21}],11:[function(require,module,exports){
  2106. // Generated by CoffeeScript 1.12.7
  2107. (function() {
  2108. var XMLComment, XMLNode,
  2109. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2110. hasProp = {}.hasOwnProperty;
  2111. XMLNode = require('./XMLNode');
  2112. module.exports = XMLComment = (function(superClass) {
  2113. extend(XMLComment, superClass);
  2114. function XMLComment(parent, text) {
  2115. XMLComment.__super__.constructor.call(this, parent);
  2116. if (text == null) {
  2117. throw new Error("Missing comment text");
  2118. }
  2119. this.text = this.stringify.comment(text);
  2120. }
  2121. XMLComment.prototype.clone = function() {
  2122. return Object.create(this);
  2123. };
  2124. XMLComment.prototype.toString = function(options) {
  2125. return this.options.writer.set(options).comment(this);
  2126. };
  2127. return XMLComment;
  2128. })(XMLNode);
  2129. }).call(this);
  2130. },{"./XMLNode":21}],12:[function(require,module,exports){
  2131. // Generated by CoffeeScript 1.12.7
  2132. (function() {
  2133. var XMLDTDAttList, XMLNode,
  2134. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2135. hasProp = {}.hasOwnProperty;
  2136. XMLNode = require('./XMLNode');
  2137. module.exports = XMLDTDAttList = (function(superClass) {
  2138. extend(XMLDTDAttList, superClass);
  2139. function XMLDTDAttList(parent, elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  2140. XMLDTDAttList.__super__.constructor.call(this, parent);
  2141. if (elementName == null) {
  2142. throw new Error("Missing DTD element name");
  2143. }
  2144. if (attributeName == null) {
  2145. throw new Error("Missing DTD attribute name");
  2146. }
  2147. if (!attributeType) {
  2148. throw new Error("Missing DTD attribute type");
  2149. }
  2150. if (!defaultValueType) {
  2151. throw new Error("Missing DTD attribute default");
  2152. }
  2153. if (defaultValueType.indexOf('#') !== 0) {
  2154. defaultValueType = '#' + defaultValueType;
  2155. }
  2156. if (!defaultValueType.match(/^(#REQUIRED|#IMPLIED|#FIXED|#DEFAULT)$/)) {
  2157. throw new Error("Invalid default value type; expected: #REQUIRED, #IMPLIED, #FIXED or #DEFAULT");
  2158. }
  2159. if (defaultValue && !defaultValueType.match(/^(#FIXED|#DEFAULT)$/)) {
  2160. throw new Error("Default value only applies to #FIXED or #DEFAULT");
  2161. }
  2162. this.elementName = this.stringify.eleName(elementName);
  2163. this.attributeName = this.stringify.attName(attributeName);
  2164. this.attributeType = this.stringify.dtdAttType(attributeType);
  2165. this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
  2166. this.defaultValueType = defaultValueType;
  2167. }
  2168. XMLDTDAttList.prototype.toString = function(options) {
  2169. return this.options.writer.set(options).dtdAttList(this);
  2170. };
  2171. return XMLDTDAttList;
  2172. })(XMLNode);
  2173. }).call(this);
  2174. },{"./XMLNode":21}],13:[function(require,module,exports){
  2175. // Generated by CoffeeScript 1.12.7
  2176. (function() {
  2177. var XMLDTDElement, XMLNode,
  2178. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2179. hasProp = {}.hasOwnProperty;
  2180. XMLNode = require('./XMLNode');
  2181. module.exports = XMLDTDElement = (function(superClass) {
  2182. extend(XMLDTDElement, superClass);
  2183. function XMLDTDElement(parent, name, value) {
  2184. XMLDTDElement.__super__.constructor.call(this, parent);
  2185. if (name == null) {
  2186. throw new Error("Missing DTD element name");
  2187. }
  2188. if (!value) {
  2189. value = '(#PCDATA)';
  2190. }
  2191. if (Array.isArray(value)) {
  2192. value = '(' + value.join(',') + ')';
  2193. }
  2194. this.name = this.stringify.eleName(name);
  2195. this.value = this.stringify.dtdElementValue(value);
  2196. }
  2197. XMLDTDElement.prototype.toString = function(options) {
  2198. return this.options.writer.set(options).dtdElement(this);
  2199. };
  2200. return XMLDTDElement;
  2201. })(XMLNode);
  2202. }).call(this);
  2203. },{"./XMLNode":21}],14:[function(require,module,exports){
  2204. // Generated by CoffeeScript 1.12.7
  2205. (function() {
  2206. var XMLDTDEntity, XMLNode, isObject,
  2207. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2208. hasProp = {}.hasOwnProperty;
  2209. isObject = require('./Utility').isObject;
  2210. XMLNode = require('./XMLNode');
  2211. module.exports = XMLDTDEntity = (function(superClass) {
  2212. extend(XMLDTDEntity, superClass);
  2213. function XMLDTDEntity(parent, pe, name, value) {
  2214. XMLDTDEntity.__super__.constructor.call(this, parent);
  2215. if (name == null) {
  2216. throw new Error("Missing entity name");
  2217. }
  2218. if (value == null) {
  2219. throw new Error("Missing entity value");
  2220. }
  2221. this.pe = !!pe;
  2222. this.name = this.stringify.eleName(name);
  2223. if (!isObject(value)) {
  2224. this.value = this.stringify.dtdEntityValue(value);
  2225. } else {
  2226. if (!value.pubID && !value.sysID) {
  2227. throw new Error("Public and/or system identifiers are required for an external entity");
  2228. }
  2229. if (value.pubID && !value.sysID) {
  2230. throw new Error("System identifier is required for a public external entity");
  2231. }
  2232. if (value.pubID != null) {
  2233. this.pubID = this.stringify.dtdPubID(value.pubID);
  2234. }
  2235. if (value.sysID != null) {
  2236. this.sysID = this.stringify.dtdSysID(value.sysID);
  2237. }
  2238. if (value.nData != null) {
  2239. this.nData = this.stringify.dtdNData(value.nData);
  2240. }
  2241. if (this.pe && this.nData) {
  2242. throw new Error("Notation declaration is not allowed in a parameter entity");
  2243. }
  2244. }
  2245. }
  2246. XMLDTDEntity.prototype.toString = function(options) {
  2247. return this.options.writer.set(options).dtdEntity(this);
  2248. };
  2249. return XMLDTDEntity;
  2250. })(XMLNode);
  2251. }).call(this);
  2252. },{"./Utility":8,"./XMLNode":21}],15:[function(require,module,exports){
  2253. // Generated by CoffeeScript 1.12.7
  2254. (function() {
  2255. var XMLDTDNotation, XMLNode,
  2256. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2257. hasProp = {}.hasOwnProperty;
  2258. XMLNode = require('./XMLNode');
  2259. module.exports = XMLDTDNotation = (function(superClass) {
  2260. extend(XMLDTDNotation, superClass);
  2261. function XMLDTDNotation(parent, name, value) {
  2262. XMLDTDNotation.__super__.constructor.call(this, parent);
  2263. if (name == null) {
  2264. throw new Error("Missing notation name");
  2265. }
  2266. if (!value.pubID && !value.sysID) {
  2267. throw new Error("Public or system identifiers are required for an external entity");
  2268. }
  2269. this.name = this.stringify.eleName(name);
  2270. if (value.pubID != null) {
  2271. this.pubID = this.stringify.dtdPubID(value.pubID);
  2272. }
  2273. if (value.sysID != null) {
  2274. this.sysID = this.stringify.dtdSysID(value.sysID);
  2275. }
  2276. }
  2277. XMLDTDNotation.prototype.toString = function(options) {
  2278. return this.options.writer.set(options).dtdNotation(this);
  2279. };
  2280. return XMLDTDNotation;
  2281. })(XMLNode);
  2282. }).call(this);
  2283. },{"./XMLNode":21}],16:[function(require,module,exports){
  2284. // Generated by CoffeeScript 1.12.7
  2285. (function() {
  2286. var XMLDeclaration, XMLNode, isObject,
  2287. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2288. hasProp = {}.hasOwnProperty;
  2289. isObject = require('./Utility').isObject;
  2290. XMLNode = require('./XMLNode');
  2291. module.exports = XMLDeclaration = (function(superClass) {
  2292. extend(XMLDeclaration, superClass);
  2293. function XMLDeclaration(parent, version, encoding, standalone) {
  2294. var ref;
  2295. XMLDeclaration.__super__.constructor.call(this, parent);
  2296. if (isObject(version)) {
  2297. ref = version, version = ref.version, encoding = ref.encoding, standalone = ref.standalone;
  2298. }
  2299. if (!version) {
  2300. version = '1.0';
  2301. }
  2302. this.version = this.stringify.xmlVersion(version);
  2303. if (encoding != null) {
  2304. this.encoding = this.stringify.xmlEncoding(encoding);
  2305. }
  2306. if (standalone != null) {
  2307. this.standalone = this.stringify.xmlStandalone(standalone);
  2308. }
  2309. }
  2310. XMLDeclaration.prototype.toString = function(options) {
  2311. return this.options.writer.set(options).declaration(this);
  2312. };
  2313. return XMLDeclaration;
  2314. })(XMLNode);
  2315. }).call(this);
  2316. },{"./Utility":8,"./XMLNode":21}],17:[function(require,module,exports){
  2317. // Generated by CoffeeScript 1.12.7
  2318. (function() {
  2319. var XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLNode, isObject,
  2320. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2321. hasProp = {}.hasOwnProperty;
  2322. isObject = require('./Utility').isObject;
  2323. XMLNode = require('./XMLNode');
  2324. XMLDTDAttList = require('./XMLDTDAttList');
  2325. XMLDTDEntity = require('./XMLDTDEntity');
  2326. XMLDTDElement = require('./XMLDTDElement');
  2327. XMLDTDNotation = require('./XMLDTDNotation');
  2328. module.exports = XMLDocType = (function(superClass) {
  2329. extend(XMLDocType, superClass);
  2330. function XMLDocType(parent, pubID, sysID) {
  2331. var ref, ref1;
  2332. XMLDocType.__super__.constructor.call(this, parent);
  2333. this.documentObject = parent;
  2334. if (isObject(pubID)) {
  2335. ref = pubID, pubID = ref.pubID, sysID = ref.sysID;
  2336. }
  2337. if (sysID == null) {
  2338. ref1 = [pubID, sysID], sysID = ref1[0], pubID = ref1[1];
  2339. }
  2340. if (pubID != null) {
  2341. this.pubID = this.stringify.dtdPubID(pubID);
  2342. }
  2343. if (sysID != null) {
  2344. this.sysID = this.stringify.dtdSysID(sysID);
  2345. }
  2346. }
  2347. XMLDocType.prototype.element = function(name, value) {
  2348. var child;
  2349. child = new XMLDTDElement(this, name, value);
  2350. this.children.push(child);
  2351. return this;
  2352. };
  2353. XMLDocType.prototype.attList = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  2354. var child;
  2355. child = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
  2356. this.children.push(child);
  2357. return this;
  2358. };
  2359. XMLDocType.prototype.entity = function(name, value) {
  2360. var child;
  2361. child = new XMLDTDEntity(this, false, name, value);
  2362. this.children.push(child);
  2363. return this;
  2364. };
  2365. XMLDocType.prototype.pEntity = function(name, value) {
  2366. var child;
  2367. child = new XMLDTDEntity(this, true, name, value);
  2368. this.children.push(child);
  2369. return this;
  2370. };
  2371. XMLDocType.prototype.notation = function(name, value) {
  2372. var child;
  2373. child = new XMLDTDNotation(this, name, value);
  2374. this.children.push(child);
  2375. return this;
  2376. };
  2377. XMLDocType.prototype.toString = function(options) {
  2378. return this.options.writer.set(options).docType(this);
  2379. };
  2380. XMLDocType.prototype.ele = function(name, value) {
  2381. return this.element(name, value);
  2382. };
  2383. XMLDocType.prototype.att = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  2384. return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);
  2385. };
  2386. XMLDocType.prototype.ent = function(name, value) {
  2387. return this.entity(name, value);
  2388. };
  2389. XMLDocType.prototype.pent = function(name, value) {
  2390. return this.pEntity(name, value);
  2391. };
  2392. XMLDocType.prototype.not = function(name, value) {
  2393. return this.notation(name, value);
  2394. };
  2395. XMLDocType.prototype.up = function() {
  2396. return this.root() || this.documentObject;
  2397. };
  2398. return XMLDocType;
  2399. })(XMLNode);
  2400. }).call(this);
  2401. },{"./Utility":8,"./XMLDTDAttList":12,"./XMLDTDElement":13,"./XMLDTDEntity":14,"./XMLDTDNotation":15,"./XMLNode":21}],18:[function(require,module,exports){
  2402. // Generated by CoffeeScript 1.12.7
  2403. (function() {
  2404. var XMLDocument, XMLNode, XMLStringWriter, XMLStringifier, isPlainObject,
  2405. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2406. hasProp = {}.hasOwnProperty;
  2407. isPlainObject = require('./Utility').isPlainObject;
  2408. XMLNode = require('./XMLNode');
  2409. XMLStringifier = require('./XMLStringifier');
  2410. XMLStringWriter = require('./XMLStringWriter');
  2411. module.exports = XMLDocument = (function(superClass) {
  2412. extend(XMLDocument, superClass);
  2413. function XMLDocument(options) {
  2414. XMLDocument.__super__.constructor.call(this, null);
  2415. options || (options = {});
  2416. if (!options.writer) {
  2417. options.writer = new XMLStringWriter();
  2418. }
  2419. this.options = options;
  2420. this.stringify = new XMLStringifier(options);
  2421. this.isDocument = true;
  2422. }
  2423. XMLDocument.prototype.end = function(writer) {
  2424. var writerOptions;
  2425. if (!writer) {
  2426. writer = this.options.writer;
  2427. } else if (isPlainObject(writer)) {
  2428. writerOptions = writer;
  2429. writer = this.options.writer.set(writerOptions);
  2430. }
  2431. return writer.document(this);
  2432. };
  2433. XMLDocument.prototype.toString = function(options) {
  2434. return this.options.writer.set(options).document(this);
  2435. };
  2436. return XMLDocument;
  2437. })(XMLNode);
  2438. }).call(this);
  2439. },{"./Utility":8,"./XMLNode":21,"./XMLStringWriter":25,"./XMLStringifier":26}],19:[function(require,module,exports){
  2440. // Generated by CoffeeScript 1.12.7
  2441. (function() {
  2442. var XMLAttribute, XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDocumentCB, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLStringifier, XMLText, isFunction, isObject, isPlainObject, ref,
  2443. hasProp = {}.hasOwnProperty;
  2444. ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction, isPlainObject = ref.isPlainObject;
  2445. XMLElement = require('./XMLElement');
  2446. XMLCData = require('./XMLCData');
  2447. XMLComment = require('./XMLComment');
  2448. XMLRaw = require('./XMLRaw');
  2449. XMLText = require('./XMLText');
  2450. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  2451. XMLDeclaration = require('./XMLDeclaration');
  2452. XMLDocType = require('./XMLDocType');
  2453. XMLDTDAttList = require('./XMLDTDAttList');
  2454. XMLDTDEntity = require('./XMLDTDEntity');
  2455. XMLDTDElement = require('./XMLDTDElement');
  2456. XMLDTDNotation = require('./XMLDTDNotation');
  2457. XMLAttribute = require('./XMLAttribute');
  2458. XMLStringifier = require('./XMLStringifier');
  2459. XMLStringWriter = require('./XMLStringWriter');
  2460. module.exports = XMLDocumentCB = (function() {
  2461. function XMLDocumentCB(options, onData, onEnd) {
  2462. var writerOptions;
  2463. options || (options = {});
  2464. if (!options.writer) {
  2465. options.writer = new XMLStringWriter(options);
  2466. } else if (isPlainObject(options.writer)) {
  2467. writerOptions = options.writer;
  2468. options.writer = new XMLStringWriter(writerOptions);
  2469. }
  2470. this.options = options;
  2471. this.writer = options.writer;
  2472. this.stringify = new XMLStringifier(options);
  2473. this.onDataCallback = onData || function() {};
  2474. this.onEndCallback = onEnd || function() {};
  2475. this.currentNode = null;
  2476. this.currentLevel = -1;
  2477. this.openTags = {};
  2478. this.documentStarted = false;
  2479. this.documentCompleted = false;
  2480. this.root = null;
  2481. }
  2482. XMLDocumentCB.prototype.node = function(name, attributes, text) {
  2483. var ref1;
  2484. if (name == null) {
  2485. throw new Error("Missing node name");
  2486. }
  2487. if (this.root && this.currentLevel === -1) {
  2488. throw new Error("Document can only have one root node");
  2489. }
  2490. this.openCurrent();
  2491. name = name.valueOf();
  2492. if (attributes == null) {
  2493. attributes = {};
  2494. }
  2495. attributes = attributes.valueOf();
  2496. if (!isObject(attributes)) {
  2497. ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
  2498. }
  2499. this.currentNode = new XMLElement(this, name, attributes);
  2500. this.currentNode.children = false;
  2501. this.currentLevel++;
  2502. this.openTags[this.currentLevel] = this.currentNode;
  2503. if (text != null) {
  2504. this.text(text);
  2505. }
  2506. return this;
  2507. };
  2508. XMLDocumentCB.prototype.element = function(name, attributes, text) {
  2509. if (this.currentNode && this.currentNode instanceof XMLDocType) {
  2510. return this.dtdElement.apply(this, arguments);
  2511. } else {
  2512. return this.node(name, attributes, text);
  2513. }
  2514. };
  2515. XMLDocumentCB.prototype.attribute = function(name, value) {
  2516. var attName, attValue;
  2517. if (!this.currentNode || this.currentNode.children) {
  2518. throw new Error("att() can only be used immediately after an ele() call in callback mode");
  2519. }
  2520. if (name != null) {
  2521. name = name.valueOf();
  2522. }
  2523. if (isObject(name)) {
  2524. for (attName in name) {
  2525. if (!hasProp.call(name, attName)) continue;
  2526. attValue = name[attName];
  2527. this.attribute(attName, attValue);
  2528. }
  2529. } else {
  2530. if (isFunction(value)) {
  2531. value = value.apply();
  2532. }
  2533. if (!this.options.skipNullAttributes || (value != null)) {
  2534. this.currentNode.attributes[name] = new XMLAttribute(this, name, value);
  2535. }
  2536. }
  2537. return this;
  2538. };
  2539. XMLDocumentCB.prototype.text = function(value) {
  2540. var node;
  2541. this.openCurrent();
  2542. node = new XMLText(this, value);
  2543. this.onData(this.writer.text(node, this.currentLevel + 1));
  2544. return this;
  2545. };
  2546. XMLDocumentCB.prototype.cdata = function(value) {
  2547. var node;
  2548. this.openCurrent();
  2549. node = new XMLCData(this, value);
  2550. this.onData(this.writer.cdata(node, this.currentLevel + 1));
  2551. return this;
  2552. };
  2553. XMLDocumentCB.prototype.comment = function(value) {
  2554. var node;
  2555. this.openCurrent();
  2556. node = new XMLComment(this, value);
  2557. this.onData(this.writer.comment(node, this.currentLevel + 1));
  2558. return this;
  2559. };
  2560. XMLDocumentCB.prototype.raw = function(value) {
  2561. var node;
  2562. this.openCurrent();
  2563. node = new XMLRaw(this, value);
  2564. this.onData(this.writer.raw(node, this.currentLevel + 1));
  2565. return this;
  2566. };
  2567. XMLDocumentCB.prototype.instruction = function(target, value) {
  2568. var i, insTarget, insValue, len, node;
  2569. this.openCurrent();
  2570. if (target != null) {
  2571. target = target.valueOf();
  2572. }
  2573. if (value != null) {
  2574. value = value.valueOf();
  2575. }
  2576. if (Array.isArray(target)) {
  2577. for (i = 0, len = target.length; i < len; i++) {
  2578. insTarget = target[i];
  2579. this.instruction(insTarget);
  2580. }
  2581. } else if (isObject(target)) {
  2582. for (insTarget in target) {
  2583. if (!hasProp.call(target, insTarget)) continue;
  2584. insValue = target[insTarget];
  2585. this.instruction(insTarget, insValue);
  2586. }
  2587. } else {
  2588. if (isFunction(value)) {
  2589. value = value.apply();
  2590. }
  2591. node = new XMLProcessingInstruction(this, target, value);
  2592. this.onData(this.writer.processingInstruction(node, this.currentLevel + 1));
  2593. }
  2594. return this;
  2595. };
  2596. XMLDocumentCB.prototype.declaration = function(version, encoding, standalone) {
  2597. var node;
  2598. this.openCurrent();
  2599. if (this.documentStarted) {
  2600. throw new Error("declaration() must be the first node");
  2601. }
  2602. node = new XMLDeclaration(this, version, encoding, standalone);
  2603. this.onData(this.writer.declaration(node, this.currentLevel + 1));
  2604. return this;
  2605. };
  2606. XMLDocumentCB.prototype.doctype = function(root, pubID, sysID) {
  2607. this.openCurrent();
  2608. if (root == null) {
  2609. throw new Error("Missing root node name");
  2610. }
  2611. if (this.root) {
  2612. throw new Error("dtd() must come before the root node");
  2613. }
  2614. this.currentNode = new XMLDocType(this, pubID, sysID);
  2615. this.currentNode.rootNodeName = root;
  2616. this.currentNode.children = false;
  2617. this.currentLevel++;
  2618. this.openTags[this.currentLevel] = this.currentNode;
  2619. return this;
  2620. };
  2621. XMLDocumentCB.prototype.dtdElement = function(name, value) {
  2622. var node;
  2623. this.openCurrent();
  2624. node = new XMLDTDElement(this, name, value);
  2625. this.onData(this.writer.dtdElement(node, this.currentLevel + 1));
  2626. return this;
  2627. };
  2628. XMLDocumentCB.prototype.attList = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
  2629. var node;
  2630. this.openCurrent();
  2631. node = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
  2632. this.onData(this.writer.dtdAttList(node, this.currentLevel + 1));
  2633. return this;
  2634. };
  2635. XMLDocumentCB.prototype.entity = function(name, value) {
  2636. var node;
  2637. this.openCurrent();
  2638. node = new XMLDTDEntity(this, false, name, value);
  2639. this.onData(this.writer.dtdEntity(node, this.currentLevel + 1));
  2640. return this;
  2641. };
  2642. XMLDocumentCB.prototype.pEntity = function(name, value) {
  2643. var node;
  2644. this.openCurrent();
  2645. node = new XMLDTDEntity(this, true, name, value);
  2646. this.onData(this.writer.dtdEntity(node, this.currentLevel + 1));
  2647. return this;
  2648. };
  2649. XMLDocumentCB.prototype.notation = function(name, value) {
  2650. var node;
  2651. this.openCurrent();
  2652. node = new XMLDTDNotation(this, name, value);
  2653. this.onData(this.writer.dtdNotation(node, this.currentLevel + 1));
  2654. return this;
  2655. };
  2656. XMLDocumentCB.prototype.up = function() {
  2657. if (this.currentLevel < 0) {
  2658. throw new Error("The document node has no parent");
  2659. }
  2660. if (this.currentNode) {
  2661. if (this.currentNode.children) {
  2662. this.closeNode(this.currentNode);
  2663. } else {
  2664. this.openNode(this.currentNode);
  2665. }
  2666. this.currentNode = null;
  2667. } else {
  2668. this.closeNode(this.openTags[this.currentLevel]);
  2669. }
  2670. delete this.openTags[this.currentLevel];
  2671. this.currentLevel--;
  2672. return this;
  2673. };
  2674. XMLDocumentCB.prototype.end = function() {
  2675. while (this.currentLevel >= 0) {
  2676. this.up();
  2677. }
  2678. return this.onEnd();
  2679. };
  2680. XMLDocumentCB.prototype.openCurrent = function() {
  2681. if (this.currentNode) {
  2682. this.currentNode.children = true;
  2683. return this.openNode(this.currentNode);
  2684. }
  2685. };
  2686. XMLDocumentCB.prototype.openNode = function(node) {
  2687. if (!node.isOpen) {
  2688. if (!this.root && this.currentLevel === 0 && node instanceof XMLElement) {
  2689. this.root = node;
  2690. }
  2691. this.onData(this.writer.openNode(node, this.currentLevel));
  2692. return node.isOpen = true;
  2693. }
  2694. };
  2695. XMLDocumentCB.prototype.closeNode = function(node) {
  2696. if (!node.isClosed) {
  2697. this.onData(this.writer.closeNode(node, this.currentLevel));
  2698. return node.isClosed = true;
  2699. }
  2700. };
  2701. XMLDocumentCB.prototype.onData = function(chunk) {
  2702. this.documentStarted = true;
  2703. return this.onDataCallback(chunk);
  2704. };
  2705. XMLDocumentCB.prototype.onEnd = function() {
  2706. this.documentCompleted = true;
  2707. return this.onEndCallback();
  2708. };
  2709. XMLDocumentCB.prototype.ele = function() {
  2710. return this.element.apply(this, arguments);
  2711. };
  2712. XMLDocumentCB.prototype.nod = function(name, attributes, text) {
  2713. return this.node(name, attributes, text);
  2714. };
  2715. XMLDocumentCB.prototype.txt = function(value) {
  2716. return this.text(value);
  2717. };
  2718. XMLDocumentCB.prototype.dat = function(value) {
  2719. return this.cdata(value);
  2720. };
  2721. XMLDocumentCB.prototype.com = function(value) {
  2722. return this.comment(value);
  2723. };
  2724. XMLDocumentCB.prototype.ins = function(target, value) {
  2725. return this.instruction(target, value);
  2726. };
  2727. XMLDocumentCB.prototype.dec = function(version, encoding, standalone) {
  2728. return this.declaration(version, encoding, standalone);
  2729. };
  2730. XMLDocumentCB.prototype.dtd = function(root, pubID, sysID) {
  2731. return this.doctype(root, pubID, sysID);
  2732. };
  2733. XMLDocumentCB.prototype.e = function(name, attributes, text) {
  2734. return this.element(name, attributes, text);
  2735. };
  2736. XMLDocumentCB.prototype.n = function(name, attributes, text) {
  2737. return this.node(name, attributes, text);
  2738. };
  2739. XMLDocumentCB.prototype.t = function(value) {
  2740. return this.text(value);
  2741. };
  2742. XMLDocumentCB.prototype.d = function(value) {
  2743. return this.cdata(value);
  2744. };
  2745. XMLDocumentCB.prototype.c = function(value) {
  2746. return this.comment(value);
  2747. };
  2748. XMLDocumentCB.prototype.r = function(value) {
  2749. return this.raw(value);
  2750. };
  2751. XMLDocumentCB.prototype.i = function(target, value) {
  2752. return this.instruction(target, value);
  2753. };
  2754. XMLDocumentCB.prototype.att = function() {
  2755. if (this.currentNode && this.currentNode instanceof XMLDocType) {
  2756. return this.attList.apply(this, arguments);
  2757. } else {
  2758. return this.attribute.apply(this, arguments);
  2759. }
  2760. };
  2761. XMLDocumentCB.prototype.a = function() {
  2762. if (this.currentNode && this.currentNode instanceof XMLDocType) {
  2763. return this.attList.apply(this, arguments);
  2764. } else {
  2765. return this.attribute.apply(this, arguments);
  2766. }
  2767. };
  2768. XMLDocumentCB.prototype.ent = function(name, value) {
  2769. return this.entity(name, value);
  2770. };
  2771. XMLDocumentCB.prototype.pent = function(name, value) {
  2772. return this.pEntity(name, value);
  2773. };
  2774. XMLDocumentCB.prototype.not = function(name, value) {
  2775. return this.notation(name, value);
  2776. };
  2777. return XMLDocumentCB;
  2778. })();
  2779. }).call(this);
  2780. },{"./Utility":8,"./XMLAttribute":9,"./XMLCData":10,"./XMLComment":11,"./XMLDTDAttList":12,"./XMLDTDElement":13,"./XMLDTDEntity":14,"./XMLDTDNotation":15,"./XMLDeclaration":16,"./XMLDocType":17,"./XMLElement":20,"./XMLProcessingInstruction":22,"./XMLRaw":23,"./XMLStringWriter":25,"./XMLStringifier":26,"./XMLText":27}],20:[function(require,module,exports){
  2781. // Generated by CoffeeScript 1.12.7
  2782. (function() {
  2783. var XMLAttribute, XMLElement, XMLNode, isFunction, isObject, ref,
  2784. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2785. hasProp = {}.hasOwnProperty;
  2786. ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction;
  2787. XMLNode = require('./XMLNode');
  2788. XMLAttribute = require('./XMLAttribute');
  2789. module.exports = XMLElement = (function(superClass) {
  2790. extend(XMLElement, superClass);
  2791. function XMLElement(parent, name, attributes) {
  2792. XMLElement.__super__.constructor.call(this, parent);
  2793. if (name == null) {
  2794. throw new Error("Missing element name");
  2795. }
  2796. this.name = this.stringify.eleName(name);
  2797. this.attributes = {};
  2798. if (attributes != null) {
  2799. this.attribute(attributes);
  2800. }
  2801. if (parent.isDocument) {
  2802. this.isRoot = true;
  2803. this.documentObject = parent;
  2804. parent.rootObject = this;
  2805. }
  2806. }
  2807. XMLElement.prototype.clone = function() {
  2808. var att, attName, clonedSelf, ref1;
  2809. clonedSelf = Object.create(this);
  2810. if (clonedSelf.isRoot) {
  2811. clonedSelf.documentObject = null;
  2812. }
  2813. clonedSelf.attributes = {};
  2814. ref1 = this.attributes;
  2815. for (attName in ref1) {
  2816. if (!hasProp.call(ref1, attName)) continue;
  2817. att = ref1[attName];
  2818. clonedSelf.attributes[attName] = att.clone();
  2819. }
  2820. clonedSelf.children = [];
  2821. this.children.forEach(function(child) {
  2822. var clonedChild;
  2823. clonedChild = child.clone();
  2824. clonedChild.parent = clonedSelf;
  2825. return clonedSelf.children.push(clonedChild);
  2826. });
  2827. return clonedSelf;
  2828. };
  2829. XMLElement.prototype.attribute = function(name, value) {
  2830. var attName, attValue;
  2831. if (name != null) {
  2832. name = name.valueOf();
  2833. }
  2834. if (isObject(name)) {
  2835. for (attName in name) {
  2836. if (!hasProp.call(name, attName)) continue;
  2837. attValue = name[attName];
  2838. this.attribute(attName, attValue);
  2839. }
  2840. } else {
  2841. if (isFunction(value)) {
  2842. value = value.apply();
  2843. }
  2844. if (!this.options.skipNullAttributes || (value != null)) {
  2845. this.attributes[name] = new XMLAttribute(this, name, value);
  2846. }
  2847. }
  2848. return this;
  2849. };
  2850. XMLElement.prototype.removeAttribute = function(name) {
  2851. var attName, i, len;
  2852. if (name == null) {
  2853. throw new Error("Missing attribute name");
  2854. }
  2855. name = name.valueOf();
  2856. if (Array.isArray(name)) {
  2857. for (i = 0, len = name.length; i < len; i++) {
  2858. attName = name[i];
  2859. delete this.attributes[attName];
  2860. }
  2861. } else {
  2862. delete this.attributes[name];
  2863. }
  2864. return this;
  2865. };
  2866. XMLElement.prototype.toString = function(options) {
  2867. return this.options.writer.set(options).element(this);
  2868. };
  2869. XMLElement.prototype.att = function(name, value) {
  2870. return this.attribute(name, value);
  2871. };
  2872. XMLElement.prototype.a = function(name, value) {
  2873. return this.attribute(name, value);
  2874. };
  2875. return XMLElement;
  2876. })(XMLNode);
  2877. }).call(this);
  2878. },{"./Utility":8,"./XMLAttribute":9,"./XMLNode":21}],21:[function(require,module,exports){
  2879. // Generated by CoffeeScript 1.12.7
  2880. (function() {
  2881. var XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLElement, XMLNode, XMLProcessingInstruction, XMLRaw, XMLText, isEmpty, isFunction, isObject, ref,
  2882. hasProp = {}.hasOwnProperty;
  2883. ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction, isEmpty = ref.isEmpty;
  2884. XMLElement = null;
  2885. XMLCData = null;
  2886. XMLComment = null;
  2887. XMLDeclaration = null;
  2888. XMLDocType = null;
  2889. XMLRaw = null;
  2890. XMLText = null;
  2891. XMLProcessingInstruction = null;
  2892. module.exports = XMLNode = (function() {
  2893. function XMLNode(parent) {
  2894. this.parent = parent;
  2895. if (this.parent) {
  2896. this.options = this.parent.options;
  2897. this.stringify = this.parent.stringify;
  2898. }
  2899. this.children = [];
  2900. if (!XMLElement) {
  2901. XMLElement = require('./XMLElement');
  2902. XMLCData = require('./XMLCData');
  2903. XMLComment = require('./XMLComment');
  2904. XMLDeclaration = require('./XMLDeclaration');
  2905. XMLDocType = require('./XMLDocType');
  2906. XMLRaw = require('./XMLRaw');
  2907. XMLText = require('./XMLText');
  2908. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  2909. }
  2910. }
  2911. XMLNode.prototype.element = function(name, attributes, text) {
  2912. var childNode, item, j, k, key, lastChild, len, len1, ref1, val;
  2913. lastChild = null;
  2914. if (attributes == null) {
  2915. attributes = {};
  2916. }
  2917. attributes = attributes.valueOf();
  2918. if (!isObject(attributes)) {
  2919. ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
  2920. }
  2921. if (name != null) {
  2922. name = name.valueOf();
  2923. }
  2924. if (Array.isArray(name)) {
  2925. for (j = 0, len = name.length; j < len; j++) {
  2926. item = name[j];
  2927. lastChild = this.element(item);
  2928. }
  2929. } else if (isFunction(name)) {
  2930. lastChild = this.element(name.apply());
  2931. } else if (isObject(name)) {
  2932. for (key in name) {
  2933. if (!hasProp.call(name, key)) continue;
  2934. val = name[key];
  2935. if (isFunction(val)) {
  2936. val = val.apply();
  2937. }
  2938. if ((isObject(val)) && (isEmpty(val))) {
  2939. val = null;
  2940. }
  2941. if (!this.options.ignoreDecorators && this.stringify.convertAttKey && key.indexOf(this.stringify.convertAttKey) === 0) {
  2942. lastChild = this.attribute(key.substr(this.stringify.convertAttKey.length), val);
  2943. } else if (!this.options.separateArrayItems && Array.isArray(val)) {
  2944. for (k = 0, len1 = val.length; k < len1; k++) {
  2945. item = val[k];
  2946. childNode = {};
  2947. childNode[key] = item;
  2948. lastChild = this.element(childNode);
  2949. }
  2950. } else if (isObject(val)) {
  2951. lastChild = this.element(key);
  2952. lastChild.element(val);
  2953. } else {
  2954. lastChild = this.element(key, val);
  2955. }
  2956. }
  2957. } else {
  2958. if (!this.options.ignoreDecorators && this.stringify.convertTextKey && name.indexOf(this.stringify.convertTextKey) === 0) {
  2959. lastChild = this.text(text);
  2960. } else if (!this.options.ignoreDecorators && this.stringify.convertCDataKey && name.indexOf(this.stringify.convertCDataKey) === 0) {
  2961. lastChild = this.cdata(text);
  2962. } else if (!this.options.ignoreDecorators && this.stringify.convertCommentKey && name.indexOf(this.stringify.convertCommentKey) === 0) {
  2963. lastChild = this.comment(text);
  2964. } else if (!this.options.ignoreDecorators && this.stringify.convertRawKey && name.indexOf(this.stringify.convertRawKey) === 0) {
  2965. lastChild = this.raw(text);
  2966. } else if (!this.options.ignoreDecorators && this.stringify.convertPIKey && name.indexOf(this.stringify.convertPIKey) === 0) {
  2967. lastChild = this.instruction(name.substr(this.stringify.convertPIKey.length), text);
  2968. } else {
  2969. lastChild = this.node(name, attributes, text);
  2970. }
  2971. }
  2972. if (lastChild == null) {
  2973. throw new Error("Could not create any elements with: " + name);
  2974. }
  2975. return lastChild;
  2976. };
  2977. XMLNode.prototype.insertBefore = function(name, attributes, text) {
  2978. var child, i, removed;
  2979. if (this.isRoot) {
  2980. throw new Error("Cannot insert elements at root level");
  2981. }
  2982. i = this.parent.children.indexOf(this);
  2983. removed = this.parent.children.splice(i);
  2984. child = this.parent.element(name, attributes, text);
  2985. Array.prototype.push.apply(this.parent.children, removed);
  2986. return child;
  2987. };
  2988. XMLNode.prototype.insertAfter = function(name, attributes, text) {
  2989. var child, i, removed;
  2990. if (this.isRoot) {
  2991. throw new Error("Cannot insert elements at root level");
  2992. }
  2993. i = this.parent.children.indexOf(this);
  2994. removed = this.parent.children.splice(i + 1);
  2995. child = this.parent.element(name, attributes, text);
  2996. Array.prototype.push.apply(this.parent.children, removed);
  2997. return child;
  2998. };
  2999. XMLNode.prototype.remove = function() {
  3000. var i, ref1;
  3001. if (this.isRoot) {
  3002. throw new Error("Cannot remove the root element");
  3003. }
  3004. i = this.parent.children.indexOf(this);
  3005. [].splice.apply(this.parent.children, [i, i - i + 1].concat(ref1 = [])), ref1;
  3006. return this.parent;
  3007. };
  3008. XMLNode.prototype.node = function(name, attributes, text) {
  3009. var child, ref1;
  3010. if (name != null) {
  3011. name = name.valueOf();
  3012. }
  3013. attributes || (attributes = {});
  3014. attributes = attributes.valueOf();
  3015. if (!isObject(attributes)) {
  3016. ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
  3017. }
  3018. child = new XMLElement(this, name, attributes);
  3019. if (text != null) {
  3020. child.text(text);
  3021. }
  3022. this.children.push(child);
  3023. return child;
  3024. };
  3025. XMLNode.prototype.text = function(value) {
  3026. var child;
  3027. child = new XMLText(this, value);
  3028. this.children.push(child);
  3029. return this;
  3030. };
  3031. XMLNode.prototype.cdata = function(value) {
  3032. var child;
  3033. child = new XMLCData(this, value);
  3034. this.children.push(child);
  3035. return this;
  3036. };
  3037. XMLNode.prototype.comment = function(value) {
  3038. var child;
  3039. child = new XMLComment(this, value);
  3040. this.children.push(child);
  3041. return this;
  3042. };
  3043. XMLNode.prototype.commentBefore = function(value) {
  3044. var child, i, removed;
  3045. i = this.parent.children.indexOf(this);
  3046. removed = this.parent.children.splice(i);
  3047. child = this.parent.comment(value);
  3048. Array.prototype.push.apply(this.parent.children, removed);
  3049. return this;
  3050. };
  3051. XMLNode.prototype.commentAfter = function(value) {
  3052. var child, i, removed;
  3053. i = this.parent.children.indexOf(this);
  3054. removed = this.parent.children.splice(i + 1);
  3055. child = this.parent.comment(value);
  3056. Array.prototype.push.apply(this.parent.children, removed);
  3057. return this;
  3058. };
  3059. XMLNode.prototype.raw = function(value) {
  3060. var child;
  3061. child = new XMLRaw(this, value);
  3062. this.children.push(child);
  3063. return this;
  3064. };
  3065. XMLNode.prototype.instruction = function(target, value) {
  3066. var insTarget, insValue, instruction, j, len;
  3067. if (target != null) {
  3068. target = target.valueOf();
  3069. }
  3070. if (value != null) {
  3071. value = value.valueOf();
  3072. }
  3073. if (Array.isArray(target)) {
  3074. for (j = 0, len = target.length; j < len; j++) {
  3075. insTarget = target[j];
  3076. this.instruction(insTarget);
  3077. }
  3078. } else if (isObject(target)) {
  3079. for (insTarget in target) {
  3080. if (!hasProp.call(target, insTarget)) continue;
  3081. insValue = target[insTarget];
  3082. this.instruction(insTarget, insValue);
  3083. }
  3084. } else {
  3085. if (isFunction(value)) {
  3086. value = value.apply();
  3087. }
  3088. instruction = new XMLProcessingInstruction(this, target, value);
  3089. this.children.push(instruction);
  3090. }
  3091. return this;
  3092. };
  3093. XMLNode.prototype.instructionBefore = function(target, value) {
  3094. var child, i, removed;
  3095. i = this.parent.children.indexOf(this);
  3096. removed = this.parent.children.splice(i);
  3097. child = this.parent.instruction(target, value);
  3098. Array.prototype.push.apply(this.parent.children, removed);
  3099. return this;
  3100. };
  3101. XMLNode.prototype.instructionAfter = function(target, value) {
  3102. var child, i, removed;
  3103. i = this.parent.children.indexOf(this);
  3104. removed = this.parent.children.splice(i + 1);
  3105. child = this.parent.instruction(target, value);
  3106. Array.prototype.push.apply(this.parent.children, removed);
  3107. return this;
  3108. };
  3109. XMLNode.prototype.declaration = function(version, encoding, standalone) {
  3110. var doc, xmldec;
  3111. doc = this.document();
  3112. xmldec = new XMLDeclaration(doc, version, encoding, standalone);
  3113. if (doc.children[0] instanceof XMLDeclaration) {
  3114. doc.children[0] = xmldec;
  3115. } else {
  3116. doc.children.unshift(xmldec);
  3117. }
  3118. return doc.root() || doc;
  3119. };
  3120. XMLNode.prototype.doctype = function(pubID, sysID) {
  3121. var child, doc, doctype, i, j, k, len, len1, ref1, ref2;
  3122. doc = this.document();
  3123. doctype = new XMLDocType(doc, pubID, sysID);
  3124. ref1 = doc.children;
  3125. for (i = j = 0, len = ref1.length; j < len; i = ++j) {
  3126. child = ref1[i];
  3127. if (child instanceof XMLDocType) {
  3128. doc.children[i] = doctype;
  3129. return doctype;
  3130. }
  3131. }
  3132. ref2 = doc.children;
  3133. for (i = k = 0, len1 = ref2.length; k < len1; i = ++k) {
  3134. child = ref2[i];
  3135. if (child.isRoot) {
  3136. doc.children.splice(i, 0, doctype);
  3137. return doctype;
  3138. }
  3139. }
  3140. doc.children.push(doctype);
  3141. return doctype;
  3142. };
  3143. XMLNode.prototype.up = function() {
  3144. if (this.isRoot) {
  3145. throw new Error("The root node has no parent. Use doc() if you need to get the document object.");
  3146. }
  3147. return this.parent;
  3148. };
  3149. XMLNode.prototype.root = function() {
  3150. var node;
  3151. node = this;
  3152. while (node) {
  3153. if (node.isDocument) {
  3154. return node.rootObject;
  3155. } else if (node.isRoot) {
  3156. return node;
  3157. } else {
  3158. node = node.parent;
  3159. }
  3160. }
  3161. };
  3162. XMLNode.prototype.document = function() {
  3163. var node;
  3164. node = this;
  3165. while (node) {
  3166. if (node.isDocument) {
  3167. return node;
  3168. } else {
  3169. node = node.parent;
  3170. }
  3171. }
  3172. };
  3173. XMLNode.prototype.end = function(options) {
  3174. return this.document().end(options);
  3175. };
  3176. XMLNode.prototype.prev = function() {
  3177. var i;
  3178. i = this.parent.children.indexOf(this);
  3179. if (i < 1) {
  3180. throw new Error("Already at the first node");
  3181. }
  3182. return this.parent.children[i - 1];
  3183. };
  3184. XMLNode.prototype.next = function() {
  3185. var i;
  3186. i = this.parent.children.indexOf(this);
  3187. if (i === -1 || i === this.parent.children.length - 1) {
  3188. throw new Error("Already at the last node");
  3189. }
  3190. return this.parent.children[i + 1];
  3191. };
  3192. XMLNode.prototype.importDocument = function(doc) {
  3193. var clonedRoot;
  3194. clonedRoot = doc.root().clone();
  3195. clonedRoot.parent = this;
  3196. clonedRoot.isRoot = false;
  3197. this.children.push(clonedRoot);
  3198. return this;
  3199. };
  3200. XMLNode.prototype.ele = function(name, attributes, text) {
  3201. return this.element(name, attributes, text);
  3202. };
  3203. XMLNode.prototype.nod = function(name, attributes, text) {
  3204. return this.node(name, attributes, text);
  3205. };
  3206. XMLNode.prototype.txt = function(value) {
  3207. return this.text(value);
  3208. };
  3209. XMLNode.prototype.dat = function(value) {
  3210. return this.cdata(value);
  3211. };
  3212. XMLNode.prototype.com = function(value) {
  3213. return this.comment(value);
  3214. };
  3215. XMLNode.prototype.ins = function(target, value) {
  3216. return this.instruction(target, value);
  3217. };
  3218. XMLNode.prototype.doc = function() {
  3219. return this.document();
  3220. };
  3221. XMLNode.prototype.dec = function(version, encoding, standalone) {
  3222. return this.declaration(version, encoding, standalone);
  3223. };
  3224. XMLNode.prototype.dtd = function(pubID, sysID) {
  3225. return this.doctype(pubID, sysID);
  3226. };
  3227. XMLNode.prototype.e = function(name, attributes, text) {
  3228. return this.element(name, attributes, text);
  3229. };
  3230. XMLNode.prototype.n = function(name, attributes, text) {
  3231. return this.node(name, attributes, text);
  3232. };
  3233. XMLNode.prototype.t = function(value) {
  3234. return this.text(value);
  3235. };
  3236. XMLNode.prototype.d = function(value) {
  3237. return this.cdata(value);
  3238. };
  3239. XMLNode.prototype.c = function(value) {
  3240. return this.comment(value);
  3241. };
  3242. XMLNode.prototype.r = function(value) {
  3243. return this.raw(value);
  3244. };
  3245. XMLNode.prototype.i = function(target, value) {
  3246. return this.instruction(target, value);
  3247. };
  3248. XMLNode.prototype.u = function() {
  3249. return this.up();
  3250. };
  3251. XMLNode.prototype.importXMLBuilder = function(doc) {
  3252. return this.importDocument(doc);
  3253. };
  3254. return XMLNode;
  3255. })();
  3256. }).call(this);
  3257. },{"./Utility":8,"./XMLCData":10,"./XMLComment":11,"./XMLDeclaration":16,"./XMLDocType":17,"./XMLElement":20,"./XMLProcessingInstruction":22,"./XMLRaw":23,"./XMLText":27}],22:[function(require,module,exports){
  3258. // Generated by CoffeeScript 1.12.7
  3259. (function() {
  3260. var XMLNode, XMLProcessingInstruction,
  3261. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  3262. hasProp = {}.hasOwnProperty;
  3263. XMLNode = require('./XMLNode');
  3264. module.exports = XMLProcessingInstruction = (function(superClass) {
  3265. extend(XMLProcessingInstruction, superClass);
  3266. function XMLProcessingInstruction(parent, target, value) {
  3267. XMLProcessingInstruction.__super__.constructor.call(this, parent);
  3268. if (target == null) {
  3269. throw new Error("Missing instruction target");
  3270. }
  3271. this.target = this.stringify.insTarget(target);
  3272. if (value) {
  3273. this.value = this.stringify.insValue(value);
  3274. }
  3275. }
  3276. XMLProcessingInstruction.prototype.clone = function() {
  3277. return Object.create(this);
  3278. };
  3279. XMLProcessingInstruction.prototype.toString = function(options) {
  3280. return this.options.writer.set(options).processingInstruction(this);
  3281. };
  3282. return XMLProcessingInstruction;
  3283. })(XMLNode);
  3284. }).call(this);
  3285. },{"./XMLNode":21}],23:[function(require,module,exports){
  3286. // Generated by CoffeeScript 1.12.7
  3287. (function() {
  3288. var XMLNode, XMLRaw,
  3289. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  3290. hasProp = {}.hasOwnProperty;
  3291. XMLNode = require('./XMLNode');
  3292. module.exports = XMLRaw = (function(superClass) {
  3293. extend(XMLRaw, superClass);
  3294. function XMLRaw(parent, text) {
  3295. XMLRaw.__super__.constructor.call(this, parent);
  3296. if (text == null) {
  3297. throw new Error("Missing raw text");
  3298. }
  3299. this.value = this.stringify.raw(text);
  3300. }
  3301. XMLRaw.prototype.clone = function() {
  3302. return Object.create(this);
  3303. };
  3304. XMLRaw.prototype.toString = function(options) {
  3305. return this.options.writer.set(options).raw(this);
  3306. };
  3307. return XMLRaw;
  3308. })(XMLNode);
  3309. }).call(this);
  3310. },{"./XMLNode":21}],24:[function(require,module,exports){
  3311. // Generated by CoffeeScript 1.12.7
  3312. (function() {
  3313. var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStreamWriter, XMLText, XMLWriterBase,
  3314. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  3315. hasProp = {}.hasOwnProperty;
  3316. XMLDeclaration = require('./XMLDeclaration');
  3317. XMLDocType = require('./XMLDocType');
  3318. XMLCData = require('./XMLCData');
  3319. XMLComment = require('./XMLComment');
  3320. XMLElement = require('./XMLElement');
  3321. XMLRaw = require('./XMLRaw');
  3322. XMLText = require('./XMLText');
  3323. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  3324. XMLDTDAttList = require('./XMLDTDAttList');
  3325. XMLDTDElement = require('./XMLDTDElement');
  3326. XMLDTDEntity = require('./XMLDTDEntity');
  3327. XMLDTDNotation = require('./XMLDTDNotation');
  3328. XMLWriterBase = require('./XMLWriterBase');
  3329. module.exports = XMLStreamWriter = (function(superClass) {
  3330. extend(XMLStreamWriter, superClass);
  3331. function XMLStreamWriter(stream, options) {
  3332. XMLStreamWriter.__super__.constructor.call(this, options);
  3333. this.stream = stream;
  3334. }
  3335. XMLStreamWriter.prototype.document = function(doc) {
  3336. var child, i, j, len, len1, ref, ref1, results;
  3337. ref = doc.children;
  3338. for (i = 0, len = ref.length; i < len; i++) {
  3339. child = ref[i];
  3340. child.isLastRootNode = false;
  3341. }
  3342. doc.children[doc.children.length - 1].isLastRootNode = true;
  3343. ref1 = doc.children;
  3344. results = [];
  3345. for (j = 0, len1 = ref1.length; j < len1; j++) {
  3346. child = ref1[j];
  3347. switch (false) {
  3348. case !(child instanceof XMLDeclaration):
  3349. results.push(this.declaration(child));
  3350. break;
  3351. case !(child instanceof XMLDocType):
  3352. results.push(this.docType(child));
  3353. break;
  3354. case !(child instanceof XMLComment):
  3355. results.push(this.comment(child));
  3356. break;
  3357. case !(child instanceof XMLProcessingInstruction):
  3358. results.push(this.processingInstruction(child));
  3359. break;
  3360. default:
  3361. results.push(this.element(child));
  3362. }
  3363. }
  3364. return results;
  3365. };
  3366. XMLStreamWriter.prototype.attribute = function(att) {
  3367. return this.stream.write(' ' + att.name + '="' + att.value + '"');
  3368. };
  3369. XMLStreamWriter.prototype.cdata = function(node, level) {
  3370. return this.stream.write(this.space(level) + '<![CDATA[' + node.text + ']]>' + this.endline(node));
  3371. };
  3372. XMLStreamWriter.prototype.comment = function(node, level) {
  3373. return this.stream.write(this.space(level) + '<!-- ' + node.text + ' -->' + this.endline(node));
  3374. };
  3375. XMLStreamWriter.prototype.declaration = function(node, level) {
  3376. this.stream.write(this.space(level));
  3377. this.stream.write('<?xml version="' + node.version + '"');
  3378. if (node.encoding != null) {
  3379. this.stream.write(' encoding="' + node.encoding + '"');
  3380. }
  3381. if (node.standalone != null) {
  3382. this.stream.write(' standalone="' + node.standalone + '"');
  3383. }
  3384. this.stream.write(this.spacebeforeslash + '?>');
  3385. return this.stream.write(this.endline(node));
  3386. };
  3387. XMLStreamWriter.prototype.docType = function(node, level) {
  3388. var child, i, len, ref;
  3389. level || (level = 0);
  3390. this.stream.write(this.space(level));
  3391. this.stream.write('<!DOCTYPE ' + node.root().name);
  3392. if (node.pubID && node.sysID) {
  3393. this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
  3394. } else if (node.sysID) {
  3395. this.stream.write(' SYSTEM "' + node.sysID + '"');
  3396. }
  3397. if (node.children.length > 0) {
  3398. this.stream.write(' [');
  3399. this.stream.write(this.endline(node));
  3400. ref = node.children;
  3401. for (i = 0, len = ref.length; i < len; i++) {
  3402. child = ref[i];
  3403. switch (false) {
  3404. case !(child instanceof XMLDTDAttList):
  3405. this.dtdAttList(child, level + 1);
  3406. break;
  3407. case !(child instanceof XMLDTDElement):
  3408. this.dtdElement(child, level + 1);
  3409. break;
  3410. case !(child instanceof XMLDTDEntity):
  3411. this.dtdEntity(child, level + 1);
  3412. break;
  3413. case !(child instanceof XMLDTDNotation):
  3414. this.dtdNotation(child, level + 1);
  3415. break;
  3416. case !(child instanceof XMLCData):
  3417. this.cdata(child, level + 1);
  3418. break;
  3419. case !(child instanceof XMLComment):
  3420. this.comment(child, level + 1);
  3421. break;
  3422. case !(child instanceof XMLProcessingInstruction):
  3423. this.processingInstruction(child, level + 1);
  3424. break;
  3425. default:
  3426. throw new Error("Unknown DTD node type: " + child.constructor.name);
  3427. }
  3428. }
  3429. this.stream.write(']');
  3430. }
  3431. this.stream.write(this.spacebeforeslash + '>');
  3432. return this.stream.write(this.endline(node));
  3433. };
  3434. XMLStreamWriter.prototype.element = function(node, level) {
  3435. var att, child, i, len, name, ref, ref1, space;
  3436. level || (level = 0);
  3437. space = this.space(level);
  3438. this.stream.write(space + '<' + node.name);
  3439. ref = node.attributes;
  3440. for (name in ref) {
  3441. if (!hasProp.call(ref, name)) continue;
  3442. att = ref[name];
  3443. this.attribute(att);
  3444. }
  3445. if (node.children.length === 0 || node.children.every(function(e) {
  3446. return e.value === '';
  3447. })) {
  3448. if (this.allowEmpty) {
  3449. this.stream.write('></' + node.name + '>');
  3450. } else {
  3451. this.stream.write(this.spacebeforeslash + '/>');
  3452. }
  3453. } else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) {
  3454. this.stream.write('>');
  3455. this.stream.write(node.children[0].value);
  3456. this.stream.write('</' + node.name + '>');
  3457. } else {
  3458. this.stream.write('>' + this.newline);
  3459. ref1 = node.children;
  3460. for (i = 0, len = ref1.length; i < len; i++) {
  3461. child = ref1[i];
  3462. switch (false) {
  3463. case !(child instanceof XMLCData):
  3464. this.cdata(child, level + 1);
  3465. break;
  3466. case !(child instanceof XMLComment):
  3467. this.comment(child, level + 1);
  3468. break;
  3469. case !(child instanceof XMLElement):
  3470. this.element(child, level + 1);
  3471. break;
  3472. case !(child instanceof XMLRaw):
  3473. this.raw(child, level + 1);
  3474. break;
  3475. case !(child instanceof XMLText):
  3476. this.text(child, level + 1);
  3477. break;
  3478. case !(child instanceof XMLProcessingInstruction):
  3479. this.processingInstruction(child, level + 1);
  3480. break;
  3481. default:
  3482. throw new Error("Unknown XML node type: " + child.constructor.name);
  3483. }
  3484. }
  3485. this.stream.write(space + '</' + node.name + '>');
  3486. }
  3487. return this.stream.write(this.endline(node));
  3488. };
  3489. XMLStreamWriter.prototype.processingInstruction = function(node, level) {
  3490. this.stream.write(this.space(level) + '<?' + node.target);
  3491. if (node.value) {
  3492. this.stream.write(' ' + node.value);
  3493. }
  3494. return this.stream.write(this.spacebeforeslash + '?>' + this.endline(node));
  3495. };
  3496. XMLStreamWriter.prototype.raw = function(node, level) {
  3497. return this.stream.write(this.space(level) + node.value + this.endline(node));
  3498. };
  3499. XMLStreamWriter.prototype.text = function(node, level) {
  3500. return this.stream.write(this.space(level) + node.value + this.endline(node));
  3501. };
  3502. XMLStreamWriter.prototype.dtdAttList = function(node, level) {
  3503. this.stream.write(this.space(level) + '<!ATTLIST ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType);
  3504. if (node.defaultValueType !== '#DEFAULT') {
  3505. this.stream.write(' ' + node.defaultValueType);
  3506. }
  3507. if (node.defaultValue) {
  3508. this.stream.write(' "' + node.defaultValue + '"');
  3509. }
  3510. return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
  3511. };
  3512. XMLStreamWriter.prototype.dtdElement = function(node, level) {
  3513. this.stream.write(this.space(level) + '<!ELEMENT ' + node.name + ' ' + node.value);
  3514. return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
  3515. };
  3516. XMLStreamWriter.prototype.dtdEntity = function(node, level) {
  3517. this.stream.write(this.space(level) + '<!ENTITY');
  3518. if (node.pe) {
  3519. this.stream.write(' %');
  3520. }
  3521. this.stream.write(' ' + node.name);
  3522. if (node.value) {
  3523. this.stream.write(' "' + node.value + '"');
  3524. } else {
  3525. if (node.pubID && node.sysID) {
  3526. this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
  3527. } else if (node.sysID) {
  3528. this.stream.write(' SYSTEM "' + node.sysID + '"');
  3529. }
  3530. if (node.nData) {
  3531. this.stream.write(' NDATA ' + node.nData);
  3532. }
  3533. }
  3534. return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
  3535. };
  3536. XMLStreamWriter.prototype.dtdNotation = function(node, level) {
  3537. this.stream.write(this.space(level) + '<!NOTATION ' + node.name);
  3538. if (node.pubID && node.sysID) {
  3539. this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
  3540. } else if (node.pubID) {
  3541. this.stream.write(' PUBLIC "' + node.pubID + '"');
  3542. } else if (node.sysID) {
  3543. this.stream.write(' SYSTEM "' + node.sysID + '"');
  3544. }
  3545. return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
  3546. };
  3547. XMLStreamWriter.prototype.endline = function(node) {
  3548. if (!node.isLastRootNode) {
  3549. return this.newline;
  3550. } else {
  3551. return '';
  3552. }
  3553. };
  3554. return XMLStreamWriter;
  3555. })(XMLWriterBase);
  3556. }).call(this);
  3557. },{"./XMLCData":10,"./XMLComment":11,"./XMLDTDAttList":12,"./XMLDTDElement":13,"./XMLDTDEntity":14,"./XMLDTDNotation":15,"./XMLDeclaration":16,"./XMLDocType":17,"./XMLElement":20,"./XMLProcessingInstruction":22,"./XMLRaw":23,"./XMLText":27,"./XMLWriterBase":28}],25:[function(require,module,exports){
  3558. // Generated by CoffeeScript 1.12.7
  3559. (function() {
  3560. var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLText, XMLWriterBase,
  3561. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  3562. hasProp = {}.hasOwnProperty;
  3563. XMLDeclaration = require('./XMLDeclaration');
  3564. XMLDocType = require('./XMLDocType');
  3565. XMLCData = require('./XMLCData');
  3566. XMLComment = require('./XMLComment');
  3567. XMLElement = require('./XMLElement');
  3568. XMLRaw = require('./XMLRaw');
  3569. XMLText = require('./XMLText');
  3570. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  3571. XMLDTDAttList = require('./XMLDTDAttList');
  3572. XMLDTDElement = require('./XMLDTDElement');
  3573. XMLDTDEntity = require('./XMLDTDEntity');
  3574. XMLDTDNotation = require('./XMLDTDNotation');
  3575. XMLWriterBase = require('./XMLWriterBase');
  3576. module.exports = XMLStringWriter = (function(superClass) {
  3577. extend(XMLStringWriter, superClass);
  3578. function XMLStringWriter(options) {
  3579. XMLStringWriter.__super__.constructor.call(this, options);
  3580. }
  3581. XMLStringWriter.prototype.document = function(doc) {
  3582. var child, i, len, r, ref;
  3583. this.textispresent = false;
  3584. r = '';
  3585. ref = doc.children;
  3586. for (i = 0, len = ref.length; i < len; i++) {
  3587. child = ref[i];
  3588. r += (function() {
  3589. switch (false) {
  3590. case !(child instanceof XMLDeclaration):
  3591. return this.declaration(child);
  3592. case !(child instanceof XMLDocType):
  3593. return this.docType(child);
  3594. case !(child instanceof XMLComment):
  3595. return this.comment(child);
  3596. case !(child instanceof XMLProcessingInstruction):
  3597. return this.processingInstruction(child);
  3598. default:
  3599. return this.element(child, 0);
  3600. }
  3601. }).call(this);
  3602. }
  3603. if (this.pretty && r.slice(-this.newline.length) === this.newline) {
  3604. r = r.slice(0, -this.newline.length);
  3605. }
  3606. return r;
  3607. };
  3608. XMLStringWriter.prototype.attribute = function(att) {
  3609. return ' ' + att.name + '="' + att.value + '"';
  3610. };
  3611. XMLStringWriter.prototype.cdata = function(node, level) {
  3612. return this.space(level) + '<![CDATA[' + node.text + ']]>' + this.newline;
  3613. };
  3614. XMLStringWriter.prototype.comment = function(node, level) {
  3615. return this.space(level) + '<!-- ' + node.text + ' -->' + this.newline;
  3616. };
  3617. XMLStringWriter.prototype.declaration = function(node, level) {
  3618. var r;
  3619. r = this.space(level);
  3620. r += '<?xml version="' + node.version + '"';
  3621. if (node.encoding != null) {
  3622. r += ' encoding="' + node.encoding + '"';
  3623. }
  3624. if (node.standalone != null) {
  3625. r += ' standalone="' + node.standalone + '"';
  3626. }
  3627. r += this.spacebeforeslash + '?>';
  3628. r += this.newline;
  3629. return r;
  3630. };
  3631. XMLStringWriter.prototype.docType = function(node, level) {
  3632. var child, i, len, r, ref;
  3633. level || (level = 0);
  3634. r = this.space(level);
  3635. r += '<!DOCTYPE ' + node.root().name;
  3636. if (node.pubID && node.sysID) {
  3637. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  3638. } else if (node.sysID) {
  3639. r += ' SYSTEM "' + node.sysID + '"';
  3640. }
  3641. if (node.children.length > 0) {
  3642. r += ' [';
  3643. r += this.newline;
  3644. ref = node.children;
  3645. for (i = 0, len = ref.length; i < len; i++) {
  3646. child = ref[i];
  3647. r += (function() {
  3648. switch (false) {
  3649. case !(child instanceof XMLDTDAttList):
  3650. return this.dtdAttList(child, level + 1);
  3651. case !(child instanceof XMLDTDElement):
  3652. return this.dtdElement(child, level + 1);
  3653. case !(child instanceof XMLDTDEntity):
  3654. return this.dtdEntity(child, level + 1);
  3655. case !(child instanceof XMLDTDNotation):
  3656. return this.dtdNotation(child, level + 1);
  3657. case !(child instanceof XMLCData):
  3658. return this.cdata(child, level + 1);
  3659. case !(child instanceof XMLComment):
  3660. return this.comment(child, level + 1);
  3661. case !(child instanceof XMLProcessingInstruction):
  3662. return this.processingInstruction(child, level + 1);
  3663. default:
  3664. throw new Error("Unknown DTD node type: " + child.constructor.name);
  3665. }
  3666. }).call(this);
  3667. }
  3668. r += ']';
  3669. }
  3670. r += this.spacebeforeslash + '>';
  3671. r += this.newline;
  3672. return r;
  3673. };
  3674. XMLStringWriter.prototype.element = function(node, level) {
  3675. var att, child, i, j, len, len1, name, r, ref, ref1, ref2, space, textispresentwasset;
  3676. level || (level = 0);
  3677. textispresentwasset = false;
  3678. if (this.textispresent) {
  3679. this.newline = '';
  3680. this.pretty = false;
  3681. } else {
  3682. this.newline = this.newlinedefault;
  3683. this.pretty = this.prettydefault;
  3684. }
  3685. space = this.space(level);
  3686. r = '';
  3687. r += space + '<' + node.name;
  3688. ref = node.attributes;
  3689. for (name in ref) {
  3690. if (!hasProp.call(ref, name)) continue;
  3691. att = ref[name];
  3692. r += this.attribute(att);
  3693. }
  3694. if (node.children.length === 0 || node.children.every(function(e) {
  3695. return e.value === '';
  3696. })) {
  3697. if (this.allowEmpty) {
  3698. r += '></' + node.name + '>' + this.newline;
  3699. } else {
  3700. r += this.spacebeforeslash + '/>' + this.newline;
  3701. }
  3702. } else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) {
  3703. r += '>';
  3704. r += node.children[0].value;
  3705. r += '</' + node.name + '>' + this.newline;
  3706. } else {
  3707. if (this.dontprettytextnodes) {
  3708. ref1 = node.children;
  3709. for (i = 0, len = ref1.length; i < len; i++) {
  3710. child = ref1[i];
  3711. if (child.value != null) {
  3712. this.textispresent++;
  3713. textispresentwasset = true;
  3714. break;
  3715. }
  3716. }
  3717. }
  3718. if (this.textispresent) {
  3719. this.newline = '';
  3720. this.pretty = false;
  3721. space = this.space(level);
  3722. }
  3723. r += '>' + this.newline;
  3724. ref2 = node.children;
  3725. for (j = 0, len1 = ref2.length; j < len1; j++) {
  3726. child = ref2[j];
  3727. r += (function() {
  3728. switch (false) {
  3729. case !(child instanceof XMLCData):
  3730. return this.cdata(child, level + 1);
  3731. case !(child instanceof XMLComment):
  3732. return this.comment(child, level + 1);
  3733. case !(child instanceof XMLElement):
  3734. return this.element(child, level + 1);
  3735. case !(child instanceof XMLRaw):
  3736. return this.raw(child, level + 1);
  3737. case !(child instanceof XMLText):
  3738. return this.text(child, level + 1);
  3739. case !(child instanceof XMLProcessingInstruction):
  3740. return this.processingInstruction(child, level + 1);
  3741. default:
  3742. throw new Error("Unknown XML node type: " + child.constructor.name);
  3743. }
  3744. }).call(this);
  3745. }
  3746. if (textispresentwasset) {
  3747. this.textispresent--;
  3748. }
  3749. if (!this.textispresent) {
  3750. this.newline = this.newlinedefault;
  3751. this.pretty = this.prettydefault;
  3752. }
  3753. r += space + '</' + node.name + '>' + this.newline;
  3754. }
  3755. return r;
  3756. };
  3757. XMLStringWriter.prototype.processingInstruction = function(node, level) {
  3758. var r;
  3759. r = this.space(level) + '<?' + node.target;
  3760. if (node.value) {
  3761. r += ' ' + node.value;
  3762. }
  3763. r += this.spacebeforeslash + '?>' + this.newline;
  3764. return r;
  3765. };
  3766. XMLStringWriter.prototype.raw = function(node, level) {
  3767. return this.space(level) + node.value + this.newline;
  3768. };
  3769. XMLStringWriter.prototype.text = function(node, level) {
  3770. return this.space(level) + node.value + this.newline;
  3771. };
  3772. XMLStringWriter.prototype.dtdAttList = function(node, level) {
  3773. var r;
  3774. r = this.space(level) + '<!ATTLIST ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType;
  3775. if (node.defaultValueType !== '#DEFAULT') {
  3776. r += ' ' + node.defaultValueType;
  3777. }
  3778. if (node.defaultValue) {
  3779. r += ' "' + node.defaultValue + '"';
  3780. }
  3781. r += this.spacebeforeslash + '>' + this.newline;
  3782. return r;
  3783. };
  3784. XMLStringWriter.prototype.dtdElement = function(node, level) {
  3785. return this.space(level) + '<!ELEMENT ' + node.name + ' ' + node.value + this.spacebeforeslash + '>' + this.newline;
  3786. };
  3787. XMLStringWriter.prototype.dtdEntity = function(node, level) {
  3788. var r;
  3789. r = this.space(level) + '<!ENTITY';
  3790. if (node.pe) {
  3791. r += ' %';
  3792. }
  3793. r += ' ' + node.name;
  3794. if (node.value) {
  3795. r += ' "' + node.value + '"';
  3796. } else {
  3797. if (node.pubID && node.sysID) {
  3798. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  3799. } else if (node.sysID) {
  3800. r += ' SYSTEM "' + node.sysID + '"';
  3801. }
  3802. if (node.nData) {
  3803. r += ' NDATA ' + node.nData;
  3804. }
  3805. }
  3806. r += this.spacebeforeslash + '>' + this.newline;
  3807. return r;
  3808. };
  3809. XMLStringWriter.prototype.dtdNotation = function(node, level) {
  3810. var r;
  3811. r = this.space(level) + '<!NOTATION ' + node.name;
  3812. if (node.pubID && node.sysID) {
  3813. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  3814. } else if (node.pubID) {
  3815. r += ' PUBLIC "' + node.pubID + '"';
  3816. } else if (node.sysID) {
  3817. r += ' SYSTEM "' + node.sysID + '"';
  3818. }
  3819. r += this.spacebeforeslash + '>' + this.newline;
  3820. return r;
  3821. };
  3822. XMLStringWriter.prototype.openNode = function(node, level) {
  3823. var att, name, r, ref;
  3824. level || (level = 0);
  3825. if (node instanceof XMLElement) {
  3826. r = this.space(level) + '<' + node.name;
  3827. ref = node.attributes;
  3828. for (name in ref) {
  3829. if (!hasProp.call(ref, name)) continue;
  3830. att = ref[name];
  3831. r += this.attribute(att);
  3832. }
  3833. r += (node.children ? '>' : '/>') + this.newline;
  3834. return r;
  3835. } else {
  3836. r = this.space(level) + '<!DOCTYPE ' + node.rootNodeName;
  3837. if (node.pubID && node.sysID) {
  3838. r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
  3839. } else if (node.sysID) {
  3840. r += ' SYSTEM "' + node.sysID + '"';
  3841. }
  3842. r += (node.children ? ' [' : '>') + this.newline;
  3843. return r;
  3844. }
  3845. };
  3846. XMLStringWriter.prototype.closeNode = function(node, level) {
  3847. level || (level = 0);
  3848. switch (false) {
  3849. case !(node instanceof XMLElement):
  3850. return this.space(level) + '</' + node.name + '>' + this.newline;
  3851. case !(node instanceof XMLDocType):
  3852. return this.space(level) + ']>' + this.newline;
  3853. }
  3854. };
  3855. return XMLStringWriter;
  3856. })(XMLWriterBase);
  3857. }).call(this);
  3858. },{"./XMLCData":10,"./XMLComment":11,"./XMLDTDAttList":12,"./XMLDTDElement":13,"./XMLDTDEntity":14,"./XMLDTDNotation":15,"./XMLDeclaration":16,"./XMLDocType":17,"./XMLElement":20,"./XMLProcessingInstruction":22,"./XMLRaw":23,"./XMLText":27,"./XMLWriterBase":28}],26:[function(require,module,exports){
  3859. // Generated by CoffeeScript 1.12.7
  3860. (function() {
  3861. var XMLStringifier,
  3862. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3863. hasProp = {}.hasOwnProperty;
  3864. module.exports = XMLStringifier = (function() {
  3865. function XMLStringifier(options) {
  3866. this.assertLegalChar = bind(this.assertLegalChar, this);
  3867. var key, ref, value;
  3868. options || (options = {});
  3869. this.noDoubleEncoding = options.noDoubleEncoding;
  3870. ref = options.stringify || {};
  3871. for (key in ref) {
  3872. if (!hasProp.call(ref, key)) continue;
  3873. value = ref[key];
  3874. this[key] = value;
  3875. }
  3876. }
  3877. XMLStringifier.prototype.eleName = function(val) {
  3878. val = '' + val || '';
  3879. return this.assertLegalChar(val);
  3880. };
  3881. XMLStringifier.prototype.eleText = function(val) {
  3882. val = '' + val || '';
  3883. return this.assertLegalChar(this.elEscape(val));
  3884. };
  3885. XMLStringifier.prototype.cdata = function(val) {
  3886. val = '' + val || '';
  3887. val = val.replace(']]>', ']]]]><![CDATA[>');
  3888. return this.assertLegalChar(val);
  3889. };
  3890. XMLStringifier.prototype.comment = function(val) {
  3891. val = '' + val || '';
  3892. if (val.match(/--/)) {
  3893. throw new Error("Comment text cannot contain double-hypen: " + val);
  3894. }
  3895. return this.assertLegalChar(val);
  3896. };
  3897. XMLStringifier.prototype.raw = function(val) {
  3898. return '' + val || '';
  3899. };
  3900. XMLStringifier.prototype.attName = function(val) {
  3901. return val = '' + val || '';
  3902. };
  3903. XMLStringifier.prototype.attValue = function(val) {
  3904. val = '' + val || '';
  3905. return this.attEscape(val);
  3906. };
  3907. XMLStringifier.prototype.insTarget = function(val) {
  3908. return '' + val || '';
  3909. };
  3910. XMLStringifier.prototype.insValue = function(val) {
  3911. val = '' + val || '';
  3912. if (val.match(/\?>/)) {
  3913. throw new Error("Invalid processing instruction value: " + val);
  3914. }
  3915. return val;
  3916. };
  3917. XMLStringifier.prototype.xmlVersion = function(val) {
  3918. val = '' + val || '';
  3919. if (!val.match(/1\.[0-9]+/)) {
  3920. throw new Error("Invalid version number: " + val);
  3921. }
  3922. return val;
  3923. };
  3924. XMLStringifier.prototype.xmlEncoding = function(val) {
  3925. val = '' + val || '';
  3926. if (!val.match(/^[A-Za-z](?:[A-Za-z0-9._-])*$/)) {
  3927. throw new Error("Invalid encoding: " + val);
  3928. }
  3929. return val;
  3930. };
  3931. XMLStringifier.prototype.xmlStandalone = function(val) {
  3932. if (val) {
  3933. return "yes";
  3934. } else {
  3935. return "no";
  3936. }
  3937. };
  3938. XMLStringifier.prototype.dtdPubID = function(val) {
  3939. return '' + val || '';
  3940. };
  3941. XMLStringifier.prototype.dtdSysID = function(val) {
  3942. return '' + val || '';
  3943. };
  3944. XMLStringifier.prototype.dtdElementValue = function(val) {
  3945. return '' + val || '';
  3946. };
  3947. XMLStringifier.prototype.dtdAttType = function(val) {
  3948. return '' + val || '';
  3949. };
  3950. XMLStringifier.prototype.dtdAttDefault = function(val) {
  3951. if (val != null) {
  3952. return '' + val || '';
  3953. } else {
  3954. return val;
  3955. }
  3956. };
  3957. XMLStringifier.prototype.dtdEntityValue = function(val) {
  3958. return '' + val || '';
  3959. };
  3960. XMLStringifier.prototype.dtdNData = function(val) {
  3961. return '' + val || '';
  3962. };
  3963. XMLStringifier.prototype.convertAttKey = '@';
  3964. XMLStringifier.prototype.convertPIKey = '?';
  3965. XMLStringifier.prototype.convertTextKey = '#text';
  3966. XMLStringifier.prototype.convertCDataKey = '#cdata';
  3967. XMLStringifier.prototype.convertCommentKey = '#comment';
  3968. XMLStringifier.prototype.convertRawKey = '#raw';
  3969. XMLStringifier.prototype.assertLegalChar = function(str) {
  3970. var res;
  3971. res = str.match(/[\0\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/);
  3972. if (res) {
  3973. throw new Error("Invalid character in string: " + str + " at index " + res.index);
  3974. }
  3975. return str;
  3976. };
  3977. XMLStringifier.prototype.elEscape = function(str) {
  3978. var ampregex;
  3979. ampregex = this.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
  3980. return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r/g, '&#xD;');
  3981. };
  3982. XMLStringifier.prototype.attEscape = function(str) {
  3983. var ampregex;
  3984. ampregex = this.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
  3985. return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/\t/g, '&#x9;').replace(/\n/g, '&#xA;').replace(/\r/g, '&#xD;');
  3986. };
  3987. return XMLStringifier;
  3988. })();
  3989. }).call(this);
  3990. },{}],27:[function(require,module,exports){
  3991. // Generated by CoffeeScript 1.12.7
  3992. (function() {
  3993. var XMLNode, XMLText,
  3994. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  3995. hasProp = {}.hasOwnProperty;
  3996. XMLNode = require('./XMLNode');
  3997. module.exports = XMLText = (function(superClass) {
  3998. extend(XMLText, superClass);
  3999. function XMLText(parent, text) {
  4000. XMLText.__super__.constructor.call(this, parent);
  4001. if (text == null) {
  4002. throw new Error("Missing element text");
  4003. }
  4004. this.value = this.stringify.eleText(text);
  4005. }
  4006. XMLText.prototype.clone = function() {
  4007. return Object.create(this);
  4008. };
  4009. XMLText.prototype.toString = function(options) {
  4010. return this.options.writer.set(options).text(this);
  4011. };
  4012. return XMLText;
  4013. })(XMLNode);
  4014. }).call(this);
  4015. },{"./XMLNode":21}],28:[function(require,module,exports){
  4016. // Generated by CoffeeScript 1.12.7
  4017. (function() {
  4018. var XMLWriterBase,
  4019. hasProp = {}.hasOwnProperty;
  4020. module.exports = XMLWriterBase = (function() {
  4021. function XMLWriterBase(options) {
  4022. var key, ref, ref1, ref2, ref3, ref4, ref5, ref6, value;
  4023. options || (options = {});
  4024. this.pretty = options.pretty || false;
  4025. this.allowEmpty = (ref = options.allowEmpty) != null ? ref : false;
  4026. if (this.pretty) {
  4027. this.indent = (ref1 = options.indent) != null ? ref1 : ' ';
  4028. this.newline = (ref2 = options.newline) != null ? ref2 : '\n';
  4029. this.offset = (ref3 = options.offset) != null ? ref3 : 0;
  4030. this.dontprettytextnodes = (ref4 = options.dontprettytextnodes) != null ? ref4 : 0;
  4031. } else {
  4032. this.indent = '';
  4033. this.newline = '';
  4034. this.offset = 0;
  4035. this.dontprettytextnodes = 0;
  4036. }
  4037. this.spacebeforeslash = (ref5 = options.spacebeforeslash) != null ? ref5 : '';
  4038. if (this.spacebeforeslash === true) {
  4039. this.spacebeforeslash = ' ';
  4040. }
  4041. this.newlinedefault = this.newline;
  4042. this.prettydefault = this.pretty;
  4043. ref6 = options.writer || {};
  4044. for (key in ref6) {
  4045. if (!hasProp.call(ref6, key)) continue;
  4046. value = ref6[key];
  4047. this[key] = value;
  4048. }
  4049. }
  4050. XMLWriterBase.prototype.set = function(options) {
  4051. var key, ref, value;
  4052. options || (options = {});
  4053. if ("pretty" in options) {
  4054. this.pretty = options.pretty;
  4055. }
  4056. if ("allowEmpty" in options) {
  4057. this.allowEmpty = options.allowEmpty;
  4058. }
  4059. if (this.pretty) {
  4060. this.indent = "indent" in options ? options.indent : ' ';
  4061. this.newline = "newline" in options ? options.newline : '\n';
  4062. this.offset = "offset" in options ? options.offset : 0;
  4063. this.dontprettytextnodes = "dontprettytextnodes" in options ? options.dontprettytextnodes : 0;
  4064. } else {
  4065. this.indent = '';
  4066. this.newline = '';
  4067. this.offset = 0;
  4068. this.dontprettytextnodes = 0;
  4069. }
  4070. this.spacebeforeslash = "spacebeforeslash" in options ? options.spacebeforeslash : '';
  4071. if (this.spacebeforeslash === true) {
  4072. this.spacebeforeslash = ' ';
  4073. }
  4074. this.newlinedefault = this.newline;
  4075. this.prettydefault = this.pretty;
  4076. ref = options.writer || {};
  4077. for (key in ref) {
  4078. if (!hasProp.call(ref, key)) continue;
  4079. value = ref[key];
  4080. this[key] = value;
  4081. }
  4082. return this;
  4083. };
  4084. XMLWriterBase.prototype.space = function(level) {
  4085. var indent;
  4086. if (this.pretty) {
  4087. indent = (level || 0) + this.offset + 1;
  4088. if (indent > 0) {
  4089. return new Array(indent).join(this.indent);
  4090. } else {
  4091. return '';
  4092. }
  4093. } else {
  4094. return '';
  4095. }
  4096. };
  4097. return XMLWriterBase;
  4098. })();
  4099. }).call(this);
  4100. },{}],29:[function(require,module,exports){
  4101. // Generated by CoffeeScript 1.12.7
  4102. (function() {
  4103. var XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction, ref;
  4104. ref = require('./Utility'), assign = ref.assign, isFunction = ref.isFunction;
  4105. XMLDocument = require('./XMLDocument');
  4106. XMLDocumentCB = require('./XMLDocumentCB');
  4107. XMLStringWriter = require('./XMLStringWriter');
  4108. XMLStreamWriter = require('./XMLStreamWriter');
  4109. module.exports.create = function(name, xmldec, doctype, options) {
  4110. var doc, root;
  4111. if (name == null) {
  4112. throw new Error("Root element needs a name");
  4113. }
  4114. options = assign({}, xmldec, doctype, options);
  4115. doc = new XMLDocument(options);
  4116. root = doc.element(name);
  4117. if (!options.headless) {
  4118. doc.declaration(options);
  4119. if ((options.pubID != null) || (options.sysID != null)) {
  4120. doc.doctype(options);
  4121. }
  4122. }
  4123. return root;
  4124. };
  4125. module.exports.begin = function(options, onData, onEnd) {
  4126. var ref1;
  4127. if (isFunction(options)) {
  4128. ref1 = [options, onData], onData = ref1[0], onEnd = ref1[1];
  4129. options = {};
  4130. }
  4131. if (onData) {
  4132. return new XMLDocumentCB(options, onData, onEnd);
  4133. } else {
  4134. return new XMLDocument(options);
  4135. }
  4136. };
  4137. module.exports.stringWriter = function(options) {
  4138. return new XMLStringWriter(options);
  4139. };
  4140. module.exports.streamWriter = function(stream, options) {
  4141. return new XMLStreamWriter(stream, options);
  4142. };
  4143. }).call(this);
  4144. },{"./Utility":8,"./XMLDocument":18,"./XMLDocumentCB":19,"./XMLStreamWriter":24,"./XMLStringWriter":25}],30:[function(require,module,exports){
  4145. function DOMParser(options){
  4146. this.options = options ||{locator:{}};
  4147. }
  4148. DOMParser.prototype.parseFromString = function(source,mimeType){
  4149. var options = this.options;
  4150. var sax = new XMLReader();
  4151. var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
  4152. var errorHandler = options.errorHandler;
  4153. var locator = options.locator;
  4154. var defaultNSMap = options.xmlns||{};
  4155. var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
  4156. if(locator){
  4157. domBuilder.setDocumentLocator(locator)
  4158. }
  4159. sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
  4160. sax.domBuilder = options.domBuilder || domBuilder;
  4161. if(/\/x?html?$/.test(mimeType)){
  4162. entityMap.nbsp = '\xa0';
  4163. entityMap.copy = '\xa9';
  4164. defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
  4165. }
  4166. defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
  4167. if(source){
  4168. sax.parse(source,defaultNSMap,entityMap);
  4169. }else{
  4170. sax.errorHandler.error("invalid doc source");
  4171. }
  4172. return domBuilder.doc;
  4173. }
  4174. function buildErrorHandler(errorImpl,domBuilder,locator){
  4175. if(!errorImpl){
  4176. if(domBuilder instanceof DOMHandler){
  4177. return domBuilder;
  4178. }
  4179. errorImpl = domBuilder ;
  4180. }
  4181. var errorHandler = {}
  4182. var isCallback = errorImpl instanceof Function;
  4183. locator = locator||{}
  4184. function build(key){
  4185. var fn = errorImpl[key];
  4186. if(!fn && isCallback){
  4187. fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
  4188. }
  4189. errorHandler[key] = fn && function(msg){
  4190. fn('[xmldom '+key+']\t'+msg+_locator(locator));
  4191. }||function(){};
  4192. }
  4193. build('warning');
  4194. build('error');
  4195. build('fatalError');
  4196. return errorHandler;
  4197. }
  4198. //console.log('#\n\n\n\n\n\n\n####')
  4199. /**
  4200. * +ContentHandler+ErrorHandler
  4201. * +LexicalHandler+EntityResolver2
  4202. * -DeclHandler-DTDHandler
  4203. *
  4204. * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
  4205. * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
  4206. * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
  4207. */
  4208. function DOMHandler() {
  4209. this.cdata = false;
  4210. }
  4211. function position(locator,node){
  4212. node.lineNumber = locator.lineNumber;
  4213. node.columnNumber = locator.columnNumber;
  4214. }
  4215. /**
  4216. * @see org.xml.sax.ContentHandler#startDocument
  4217. * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
  4218. */
  4219. DOMHandler.prototype = {
  4220. startDocument : function() {
  4221. this.doc = new DOMImplementation().createDocument(null, null, null);
  4222. if (this.locator) {
  4223. this.doc.documentURI = this.locator.systemId;
  4224. }
  4225. },
  4226. startElement:function(namespaceURI, localName, qName, attrs) {
  4227. var doc = this.doc;
  4228. var el = doc.createElementNS(namespaceURI, qName||localName);
  4229. var len = attrs.length;
  4230. appendElement(this, el);
  4231. this.currentElement = el;
  4232. this.locator && position(this.locator,el)
  4233. for (var i = 0 ; i < len; i++) {
  4234. var namespaceURI = attrs.getURI(i);
  4235. var value = attrs.getValue(i);
  4236. var qName = attrs.getQName(i);
  4237. var attr = doc.createAttributeNS(namespaceURI, qName);
  4238. this.locator &&position(attrs.getLocator(i),attr);
  4239. attr.value = attr.nodeValue = value;
  4240. el.setAttributeNode(attr)
  4241. }
  4242. },
  4243. endElement:function(namespaceURI, localName, qName) {
  4244. var current = this.currentElement
  4245. var tagName = current.tagName;
  4246. this.currentElement = current.parentNode;
  4247. },
  4248. startPrefixMapping:function(prefix, uri) {
  4249. },
  4250. endPrefixMapping:function(prefix) {
  4251. },
  4252. processingInstruction:function(target, data) {
  4253. var ins = this.doc.createProcessingInstruction(target, data);
  4254. this.locator && position(this.locator,ins)
  4255. appendElement(this, ins);
  4256. },
  4257. ignorableWhitespace:function(ch, start, length) {
  4258. },
  4259. characters:function(chars, start, length) {
  4260. chars = _toString.apply(this,arguments)
  4261. //console.log(chars)
  4262. if(chars){
  4263. if (this.cdata) {
  4264. var charNode = this.doc.createCDATASection(chars);
  4265. } else {
  4266. var charNode = this.doc.createTextNode(chars);
  4267. }
  4268. if(this.currentElement){
  4269. this.currentElement.appendChild(charNode);
  4270. }else if(/^\s*$/.test(chars)){
  4271. this.doc.appendChild(charNode);
  4272. //process xml
  4273. }
  4274. this.locator && position(this.locator,charNode)
  4275. }
  4276. },
  4277. skippedEntity:function(name) {
  4278. },
  4279. endDocument:function() {
  4280. this.doc.normalize();
  4281. },
  4282. setDocumentLocator:function (locator) {
  4283. if(this.locator = locator){// && !('lineNumber' in locator)){
  4284. locator.lineNumber = 0;
  4285. }
  4286. },
  4287. //LexicalHandler
  4288. comment:function(chars, start, length) {
  4289. chars = _toString.apply(this,arguments)
  4290. var comm = this.doc.createComment(chars);
  4291. this.locator && position(this.locator,comm)
  4292. appendElement(this, comm);
  4293. },
  4294. startCDATA:function() {
  4295. //used in characters() methods
  4296. this.cdata = true;
  4297. },
  4298. endCDATA:function() {
  4299. this.cdata = false;
  4300. },
  4301. startDTD:function(name, publicId, systemId) {
  4302. var impl = this.doc.implementation;
  4303. if (impl && impl.createDocumentType) {
  4304. var dt = impl.createDocumentType(name, publicId, systemId);
  4305. this.locator && position(this.locator,dt)
  4306. appendElement(this, dt);
  4307. }
  4308. },
  4309. /**
  4310. * @see org.xml.sax.ErrorHandler
  4311. * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
  4312. */
  4313. warning:function(error) {
  4314. console.warn('[xmldom warning]\t'+error,_locator(this.locator));
  4315. },
  4316. error:function(error) {
  4317. console.error('[xmldom error]\t'+error,_locator(this.locator));
  4318. },
  4319. fatalError:function(error) {
  4320. console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
  4321. throw error;
  4322. }
  4323. }
  4324. function _locator(l){
  4325. if(l){
  4326. return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
  4327. }
  4328. }
  4329. function _toString(chars,start,length){
  4330. if(typeof chars == 'string'){
  4331. return chars.substr(start,length)
  4332. }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
  4333. if(chars.length >= start+length || start){
  4334. return new java.lang.String(chars,start,length)+'';
  4335. }
  4336. return chars;
  4337. }
  4338. }
  4339. /*
  4340. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
  4341. * used method of org.xml.sax.ext.LexicalHandler:
  4342. * #comment(chars, start, length)
  4343. * #startCDATA()
  4344. * #endCDATA()
  4345. * #startDTD(name, publicId, systemId)
  4346. *
  4347. *
  4348. * IGNORED method of org.xml.sax.ext.LexicalHandler:
  4349. * #endDTD()
  4350. * #startEntity(name)
  4351. * #endEntity(name)
  4352. *
  4353. *
  4354. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
  4355. * IGNORED method of org.xml.sax.ext.DeclHandler
  4356. * #attributeDecl(eName, aName, type, mode, value)
  4357. * #elementDecl(name, model)
  4358. * #externalEntityDecl(name, publicId, systemId)
  4359. * #internalEntityDecl(name, value)
  4360. * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
  4361. * IGNORED method of org.xml.sax.EntityResolver2
  4362. * #resolveEntity(String name,String publicId,String baseURI,String systemId)
  4363. * #resolveEntity(publicId, systemId)
  4364. * #getExternalSubset(name, baseURI)
  4365. * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
  4366. * IGNORED method of org.xml.sax.DTDHandler
  4367. * #notationDecl(name, publicId, systemId) {};
  4368. * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
  4369. */
  4370. "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
  4371. DOMHandler.prototype[key] = function(){return null}
  4372. })
  4373. /* 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 */
  4374. function appendElement (hander,node) {
  4375. if (!hander.currentElement) {
  4376. hander.doc.appendChild(node);
  4377. } else {
  4378. hander.currentElement.appendChild(node);
  4379. }
  4380. }//appendChild and setAttributeNS are preformance key
  4381. //if(typeof require == 'function'){
  4382. var XMLReader = require('./sax').XMLReader;
  4383. var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
  4384. exports.XMLSerializer = require('./dom').XMLSerializer ;
  4385. exports.DOMParser = DOMParser;
  4386. //}
  4387. },{"./dom":31,"./sax":32}],31:[function(require,module,exports){
  4388. /*
  4389. * DOM Level 2
  4390. * Object DOMException
  4391. * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
  4392. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
  4393. */
  4394. function copy(src,dest){
  4395. for(var p in src){
  4396. dest[p] = src[p];
  4397. }
  4398. }
  4399. /**
  4400. ^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
  4401. ^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
  4402. */
  4403. function _extends(Class,Super){
  4404. var pt = Class.prototype;
  4405. if(Object.create){
  4406. var ppt = Object.create(Super.prototype)
  4407. pt.__proto__ = ppt;
  4408. }
  4409. if(!(pt instanceof Super)){
  4410. function t(){};
  4411. t.prototype = Super.prototype;
  4412. t = new t();
  4413. copy(pt,t);
  4414. Class.prototype = pt = t;
  4415. }
  4416. if(pt.constructor != Class){
  4417. if(typeof Class != 'function'){
  4418. console.error("unknow Class:"+Class)
  4419. }
  4420. pt.constructor = Class
  4421. }
  4422. }
  4423. var htmlns = 'http://www.w3.org/1999/xhtml' ;
  4424. // Node Types
  4425. var NodeType = {}
  4426. var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
  4427. var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
  4428. var TEXT_NODE = NodeType.TEXT_NODE = 3;
  4429. var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
  4430. var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
  4431. var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
  4432. var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
  4433. var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
  4434. var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
  4435. var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
  4436. var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
  4437. var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
  4438. // ExceptionCode
  4439. var ExceptionCode = {}
  4440. var ExceptionMessage = {};
  4441. var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
  4442. var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
  4443. var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
  4444. var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
  4445. var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
  4446. var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
  4447. var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
  4448. var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
  4449. var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
  4450. var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
  4451. //level2
  4452. var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
  4453. var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
  4454. var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
  4455. var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
  4456. var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
  4457. function DOMException(code, message) {
  4458. if(message instanceof Error){
  4459. var error = message;
  4460. }else{
  4461. error = this;
  4462. Error.call(this, ExceptionMessage[code]);
  4463. this.message = ExceptionMessage[code];
  4464. if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
  4465. }
  4466. error.code = code;
  4467. if(message) this.message = this.message + ": " + message;
  4468. return error;
  4469. };
  4470. DOMException.prototype = Error.prototype;
  4471. copy(ExceptionCode,DOMException)
  4472. /**
  4473. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
  4474. * 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.
  4475. * The items in the NodeList are accessible via an integral index, starting from 0.
  4476. */
  4477. function NodeList() {
  4478. };
  4479. NodeList.prototype = {
  4480. /**
  4481. * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
  4482. * @standard level1
  4483. */
  4484. length:0,
  4485. /**
  4486. * 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.
  4487. * @standard level1
  4488. * @param index unsigned long
  4489. * Index into the collection.
  4490. * @return Node
  4491. * The node at the indexth position in the NodeList, or null if that is not a valid index.
  4492. */
  4493. item: function(index) {
  4494. return this[index] || null;
  4495. },
  4496. toString:function(isHTML,nodeFilter){
  4497. for(var buf = [], i = 0;i<this.length;i++){
  4498. serializeToString(this[i],buf,isHTML,nodeFilter);
  4499. }
  4500. return buf.join('');
  4501. }
  4502. };
  4503. function LiveNodeList(node,refresh){
  4504. this._node = node;
  4505. this._refresh = refresh
  4506. _updateLiveList(this);
  4507. }
  4508. function _updateLiveList(list){
  4509. var inc = list._node._inc || list._node.ownerDocument._inc;
  4510. if(list._inc != inc){
  4511. var ls = list._refresh(list._node);
  4512. //console.log(ls.length)
  4513. __set__(list,'length',ls.length);
  4514. copy(ls,list);
  4515. list._inc = inc;
  4516. }
  4517. }
  4518. LiveNodeList.prototype.item = function(i){
  4519. _updateLiveList(this);
  4520. return this[i];
  4521. }
  4522. _extends(LiveNodeList,NodeList);
  4523. /**
  4524. *
  4525. * 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.
  4526. * NamedNodeMap objects in the DOM are live.
  4527. * used for attributes or DocumentType entities
  4528. */
  4529. function NamedNodeMap() {
  4530. };
  4531. function _findNodeIndex(list,node){
  4532. var i = list.length;
  4533. while(i--){
  4534. if(list[i] === node){return i}
  4535. }
  4536. }
  4537. function _addNamedNode(el,list,newAttr,oldAttr){
  4538. if(oldAttr){
  4539. list[_findNodeIndex(list,oldAttr)] = newAttr;
  4540. }else{
  4541. list[list.length++] = newAttr;
  4542. }
  4543. if(el){
  4544. newAttr.ownerElement = el;
  4545. var doc = el.ownerDocument;
  4546. if(doc){
  4547. oldAttr && _onRemoveAttribute(doc,el,oldAttr);
  4548. _onAddAttribute(doc,el,newAttr);
  4549. }
  4550. }
  4551. }
  4552. function _removeNamedNode(el,list,attr){
  4553. //console.log('remove attr:'+attr)
  4554. var i = _findNodeIndex(list,attr);
  4555. if(i>=0){
  4556. var lastIndex = list.length-1
  4557. while(i<lastIndex){
  4558. list[i] = list[++i]
  4559. }
  4560. list.length = lastIndex;
  4561. if(el){
  4562. var doc = el.ownerDocument;
  4563. if(doc){
  4564. _onRemoveAttribute(doc,el,attr);
  4565. attr.ownerElement = null;
  4566. }
  4567. }
  4568. }else{
  4569. throw DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
  4570. }
  4571. }
  4572. NamedNodeMap.prototype = {
  4573. length:0,
  4574. item:NodeList.prototype.item,
  4575. getNamedItem: function(key) {
  4576. // if(key.indexOf(':')>0 || key == 'xmlns'){
  4577. // return null;
  4578. // }
  4579. //console.log()
  4580. var i = this.length;
  4581. while(i--){
  4582. var attr = this[i];
  4583. //console.log(attr.nodeName,key)
  4584. if(attr.nodeName == key){
  4585. return attr;
  4586. }
  4587. }
  4588. },
  4589. setNamedItem: function(attr) {
  4590. var el = attr.ownerElement;
  4591. if(el && el!=this._ownerElement){
  4592. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  4593. }
  4594. var oldAttr = this.getNamedItem(attr.nodeName);
  4595. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  4596. return oldAttr;
  4597. },
  4598. /* returns Node */
  4599. setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
  4600. var el = attr.ownerElement, oldAttr;
  4601. if(el && el!=this._ownerElement){
  4602. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  4603. }
  4604. oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
  4605. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  4606. return oldAttr;
  4607. },
  4608. /* returns Node */
  4609. removeNamedItem: function(key) {
  4610. var attr = this.getNamedItem(key);
  4611. _removeNamedNode(this._ownerElement,this,attr);
  4612. return attr;
  4613. },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
  4614. //for level2
  4615. removeNamedItemNS:function(namespaceURI,localName){
  4616. var attr = this.getNamedItemNS(namespaceURI,localName);
  4617. _removeNamedNode(this._ownerElement,this,attr);
  4618. return attr;
  4619. },
  4620. getNamedItemNS: function(namespaceURI, localName) {
  4621. var i = this.length;
  4622. while(i--){
  4623. var node = this[i];
  4624. if(node.localName == localName && node.namespaceURI == namespaceURI){
  4625. return node;
  4626. }
  4627. }
  4628. return null;
  4629. }
  4630. };
  4631. /**
  4632. * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
  4633. */
  4634. function DOMImplementation(/* Object */ features) {
  4635. this._features = {};
  4636. if (features) {
  4637. for (var feature in features) {
  4638. this._features = features[feature];
  4639. }
  4640. }
  4641. };
  4642. DOMImplementation.prototype = {
  4643. hasFeature: function(/* string */ feature, /* string */ version) {
  4644. var versions = this._features[feature.toLowerCase()];
  4645. if (versions && (!version || version in versions)) {
  4646. return true;
  4647. } else {
  4648. return false;
  4649. }
  4650. },
  4651. // Introduced in DOM Level 2:
  4652. createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
  4653. var doc = new Document();
  4654. doc.implementation = this;
  4655. doc.childNodes = new NodeList();
  4656. doc.doctype = doctype;
  4657. if(doctype){
  4658. doc.appendChild(doctype);
  4659. }
  4660. if(qualifiedName){
  4661. var root = doc.createElementNS(namespaceURI,qualifiedName);
  4662. doc.appendChild(root);
  4663. }
  4664. return doc;
  4665. },
  4666. // Introduced in DOM Level 2:
  4667. createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
  4668. var node = new DocumentType();
  4669. node.name = qualifiedName;
  4670. node.nodeName = qualifiedName;
  4671. node.publicId = publicId;
  4672. node.systemId = systemId;
  4673. // Introduced in DOM Level 2:
  4674. //readonly attribute DOMString internalSubset;
  4675. //TODO:..
  4676. // readonly attribute NamedNodeMap entities;
  4677. // readonly attribute NamedNodeMap notations;
  4678. return node;
  4679. }
  4680. };
  4681. /**
  4682. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247
  4683. */
  4684. function Node() {
  4685. };
  4686. Node.prototype = {
  4687. firstChild : null,
  4688. lastChild : null,
  4689. previousSibling : null,
  4690. nextSibling : null,
  4691. attributes : null,
  4692. parentNode : null,
  4693. childNodes : null,
  4694. ownerDocument : null,
  4695. nodeValue : null,
  4696. namespaceURI : null,
  4697. prefix : null,
  4698. localName : null,
  4699. // Modified in DOM Level 2:
  4700. insertBefore:function(newChild, refChild){//raises
  4701. return _insertBefore(this,newChild,refChild);
  4702. },
  4703. replaceChild:function(newChild, oldChild){//raises
  4704. this.insertBefore(newChild,oldChild);
  4705. if(oldChild){
  4706. this.removeChild(oldChild);
  4707. }
  4708. },
  4709. removeChild:function(oldChild){
  4710. return _removeChild(this,oldChild);
  4711. },
  4712. appendChild:function(newChild){
  4713. return this.insertBefore(newChild,null);
  4714. },
  4715. hasChildNodes:function(){
  4716. return this.firstChild != null;
  4717. },
  4718. cloneNode:function(deep){
  4719. return cloneNode(this.ownerDocument||this,this,deep);
  4720. },
  4721. // Modified in DOM Level 2:
  4722. normalize:function(){
  4723. var child = this.firstChild;
  4724. while(child){
  4725. var next = child.nextSibling;
  4726. if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
  4727. this.removeChild(next);
  4728. child.appendData(next.data);
  4729. }else{
  4730. child.normalize();
  4731. child = next;
  4732. }
  4733. }
  4734. },
  4735. // Introduced in DOM Level 2:
  4736. isSupported:function(feature, version){
  4737. return this.ownerDocument.implementation.hasFeature(feature,version);
  4738. },
  4739. // Introduced in DOM Level 2:
  4740. hasAttributes:function(){
  4741. return this.attributes.length>0;
  4742. },
  4743. lookupPrefix:function(namespaceURI){
  4744. var el = this;
  4745. while(el){
  4746. var map = el._nsMap;
  4747. //console.dir(map)
  4748. if(map){
  4749. for(var n in map){
  4750. if(map[n] == namespaceURI){
  4751. return n;
  4752. }
  4753. }
  4754. }
  4755. el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
  4756. }
  4757. return null;
  4758. },
  4759. // Introduced in DOM Level 3:
  4760. lookupNamespaceURI:function(prefix){
  4761. var el = this;
  4762. while(el){
  4763. var map = el._nsMap;
  4764. //console.dir(map)
  4765. if(map){
  4766. if(prefix in map){
  4767. return map[prefix] ;
  4768. }
  4769. }
  4770. el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
  4771. }
  4772. return null;
  4773. },
  4774. // Introduced in DOM Level 3:
  4775. isDefaultNamespace:function(namespaceURI){
  4776. var prefix = this.lookupPrefix(namespaceURI);
  4777. return prefix == null;
  4778. }
  4779. };
  4780. function _xmlEncoder(c){
  4781. return c == '<' && '&lt;' ||
  4782. c == '>' && '&gt;' ||
  4783. c == '&' && '&amp;' ||
  4784. c == '"' && '&quot;' ||
  4785. '&#'+c.charCodeAt()+';'
  4786. }
  4787. copy(NodeType,Node);
  4788. copy(NodeType,Node.prototype);
  4789. /**
  4790. * @param callback return true for continue,false for break
  4791. * @return boolean true: break visit;
  4792. */
  4793. function _visitNode(node,callback){
  4794. if(callback(node)){
  4795. return true;
  4796. }
  4797. if(node = node.firstChild){
  4798. do{
  4799. if(_visitNode(node,callback)){return true}
  4800. }while(node=node.nextSibling)
  4801. }
  4802. }
  4803. function Document(){
  4804. }
  4805. function _onAddAttribute(doc,el,newAttr){
  4806. doc && doc._inc++;
  4807. var ns = newAttr.namespaceURI ;
  4808. if(ns == 'http://www.w3.org/2000/xmlns/'){
  4809. //update namespace
  4810. el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
  4811. }
  4812. }
  4813. function _onRemoveAttribute(doc,el,newAttr,remove){
  4814. doc && doc._inc++;
  4815. var ns = newAttr.namespaceURI ;
  4816. if(ns == 'http://www.w3.org/2000/xmlns/'){
  4817. //update namespace
  4818. delete el._nsMap[newAttr.prefix?newAttr.localName:'']
  4819. }
  4820. }
  4821. function _onUpdateChild(doc,el,newChild){
  4822. if(doc && doc._inc){
  4823. doc._inc++;
  4824. //update childNodes
  4825. var cs = el.childNodes;
  4826. if(newChild){
  4827. cs[cs.length++] = newChild;
  4828. }else{
  4829. //console.log(1)
  4830. var child = el.firstChild;
  4831. var i = 0;
  4832. while(child){
  4833. cs[i++] = child;
  4834. child =child.nextSibling;
  4835. }
  4836. cs.length = i;
  4837. }
  4838. }
  4839. }
  4840. /**
  4841. * attributes;
  4842. * children;
  4843. *
  4844. * writeable properties:
  4845. * nodeValue,Attr:value,CharacterData:data
  4846. * prefix
  4847. */
  4848. function _removeChild(parentNode,child){
  4849. var previous = child.previousSibling;
  4850. var next = child.nextSibling;
  4851. if(previous){
  4852. previous.nextSibling = next;
  4853. }else{
  4854. parentNode.firstChild = next
  4855. }
  4856. if(next){
  4857. next.previousSibling = previous;
  4858. }else{
  4859. parentNode.lastChild = previous;
  4860. }
  4861. _onUpdateChild(parentNode.ownerDocument,parentNode);
  4862. return child;
  4863. }
  4864. /**
  4865. * preformance key(refChild == null)
  4866. */
  4867. function _insertBefore(parentNode,newChild,nextChild){
  4868. var cp = newChild.parentNode;
  4869. if(cp){
  4870. cp.removeChild(newChild);//remove and update
  4871. }
  4872. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  4873. var newFirst = newChild.firstChild;
  4874. if (newFirst == null) {
  4875. return newChild;
  4876. }
  4877. var newLast = newChild.lastChild;
  4878. }else{
  4879. newFirst = newLast = newChild;
  4880. }
  4881. var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
  4882. newFirst.previousSibling = pre;
  4883. newLast.nextSibling = nextChild;
  4884. if(pre){
  4885. pre.nextSibling = newFirst;
  4886. }else{
  4887. parentNode.firstChild = newFirst;
  4888. }
  4889. if(nextChild == null){
  4890. parentNode.lastChild = newLast;
  4891. }else{
  4892. nextChild.previousSibling = newLast;
  4893. }
  4894. do{
  4895. newFirst.parentNode = parentNode;
  4896. }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
  4897. _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
  4898. //console.log(parentNode.lastChild.nextSibling == null)
  4899. if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
  4900. newChild.firstChild = newChild.lastChild = null;
  4901. }
  4902. return newChild;
  4903. }
  4904. function _appendSingleChild(parentNode,newChild){
  4905. var cp = newChild.parentNode;
  4906. if(cp){
  4907. var pre = parentNode.lastChild;
  4908. cp.removeChild(newChild);//remove and update
  4909. var pre = parentNode.lastChild;
  4910. }
  4911. var pre = parentNode.lastChild;
  4912. newChild.parentNode = parentNode;
  4913. newChild.previousSibling = pre;
  4914. newChild.nextSibling = null;
  4915. if(pre){
  4916. pre.nextSibling = newChild;
  4917. }else{
  4918. parentNode.firstChild = newChild;
  4919. }
  4920. parentNode.lastChild = newChild;
  4921. _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
  4922. return newChild;
  4923. //console.log("__aa",parentNode.lastChild.nextSibling == null)
  4924. }
  4925. Document.prototype = {
  4926. //implementation : null,
  4927. nodeName : '#document',
  4928. nodeType : DOCUMENT_NODE,
  4929. doctype : null,
  4930. documentElement : null,
  4931. _inc : 1,
  4932. insertBefore : function(newChild, refChild){//raises
  4933. if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
  4934. var child = newChild.firstChild;
  4935. while(child){
  4936. var next = child.nextSibling;
  4937. this.insertBefore(child,refChild);
  4938. child = next;
  4939. }
  4940. return newChild;
  4941. }
  4942. if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
  4943. this.documentElement = newChild;
  4944. }
  4945. return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
  4946. },
  4947. removeChild : function(oldChild){
  4948. if(this.documentElement == oldChild){
  4949. this.documentElement = null;
  4950. }
  4951. return _removeChild(this,oldChild);
  4952. },
  4953. // Introduced in DOM Level 2:
  4954. importNode : function(importedNode,deep){
  4955. return importNode(this,importedNode,deep);
  4956. },
  4957. // Introduced in DOM Level 2:
  4958. getElementById : function(id){
  4959. var rtv = null;
  4960. _visitNode(this.documentElement,function(node){
  4961. if(node.nodeType == ELEMENT_NODE){
  4962. if(node.getAttribute('id') == id){
  4963. rtv = node;
  4964. return true;
  4965. }
  4966. }
  4967. })
  4968. return rtv;
  4969. },
  4970. //document factory method:
  4971. createElement : function(tagName){
  4972. var node = new Element();
  4973. node.ownerDocument = this;
  4974. node.nodeName = tagName;
  4975. node.tagName = tagName;
  4976. node.childNodes = new NodeList();
  4977. var attrs = node.attributes = new NamedNodeMap();
  4978. attrs._ownerElement = node;
  4979. return node;
  4980. },
  4981. createDocumentFragment : function(){
  4982. var node = new DocumentFragment();
  4983. node.ownerDocument = this;
  4984. node.childNodes = new NodeList();
  4985. return node;
  4986. },
  4987. createTextNode : function(data){
  4988. var node = new Text();
  4989. node.ownerDocument = this;
  4990. node.appendData(data)
  4991. return node;
  4992. },
  4993. createComment : function(data){
  4994. var node = new Comment();
  4995. node.ownerDocument = this;
  4996. node.appendData(data)
  4997. return node;
  4998. },
  4999. createCDATASection : function(data){
  5000. var node = new CDATASection();
  5001. node.ownerDocument = this;
  5002. node.appendData(data)
  5003. return node;
  5004. },
  5005. createProcessingInstruction : function(target,data){
  5006. var node = new ProcessingInstruction();
  5007. node.ownerDocument = this;
  5008. node.tagName = node.target = target;
  5009. node.nodeValue= node.data = data;
  5010. return node;
  5011. },
  5012. createAttribute : function(name){
  5013. var node = new Attr();
  5014. node.ownerDocument = this;
  5015. node.name = name;
  5016. node.nodeName = name;
  5017. node.localName = name;
  5018. node.specified = true;
  5019. return node;
  5020. },
  5021. createEntityReference : function(name){
  5022. var node = new EntityReference();
  5023. node.ownerDocument = this;
  5024. node.nodeName = name;
  5025. return node;
  5026. },
  5027. // Introduced in DOM Level 2:
  5028. createElementNS : function(namespaceURI,qualifiedName){
  5029. var node = new Element();
  5030. var pl = qualifiedName.split(':');
  5031. var attrs = node.attributes = new NamedNodeMap();
  5032. node.childNodes = new NodeList();
  5033. node.ownerDocument = this;
  5034. node.nodeName = qualifiedName;
  5035. node.tagName = qualifiedName;
  5036. node.namespaceURI = namespaceURI;
  5037. if(pl.length == 2){
  5038. node.prefix = pl[0];
  5039. node.localName = pl[1];
  5040. }else{
  5041. //el.prefix = null;
  5042. node.localName = qualifiedName;
  5043. }
  5044. attrs._ownerElement = node;
  5045. return node;
  5046. },
  5047. // Introduced in DOM Level 2:
  5048. createAttributeNS : function(namespaceURI,qualifiedName){
  5049. var node = new Attr();
  5050. var pl = qualifiedName.split(':');
  5051. node.ownerDocument = this;
  5052. node.nodeName = qualifiedName;
  5053. node.name = qualifiedName;
  5054. node.namespaceURI = namespaceURI;
  5055. node.specified = true;
  5056. if(pl.length == 2){
  5057. node.prefix = pl[0];
  5058. node.localName = pl[1];
  5059. }else{
  5060. //el.prefix = null;
  5061. node.localName = qualifiedName;
  5062. }
  5063. return node;
  5064. }
  5065. };
  5066. _extends(Document,Node);
  5067. function Element() {
  5068. this._nsMap = {};
  5069. };
  5070. Element.prototype = {
  5071. nodeType : ELEMENT_NODE,
  5072. hasAttribute : function(name){
  5073. return this.getAttributeNode(name)!=null;
  5074. },
  5075. getAttribute : function(name){
  5076. var attr = this.getAttributeNode(name);
  5077. return attr && attr.value || '';
  5078. },
  5079. getAttributeNode : function(name){
  5080. return this.attributes.getNamedItem(name);
  5081. },
  5082. setAttribute : function(name, value){
  5083. var attr = this.ownerDocument.createAttribute(name);
  5084. attr.value = attr.nodeValue = "" + value;
  5085. this.setAttributeNode(attr)
  5086. },
  5087. removeAttribute : function(name){
  5088. var attr = this.getAttributeNode(name)
  5089. attr && this.removeAttributeNode(attr);
  5090. },
  5091. //four real opeartion method
  5092. appendChild:function(newChild){
  5093. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  5094. return this.insertBefore(newChild,null);
  5095. }else{
  5096. return _appendSingleChild(this,newChild);
  5097. }
  5098. },
  5099. setAttributeNode : function(newAttr){
  5100. return this.attributes.setNamedItem(newAttr);
  5101. },
  5102. setAttributeNodeNS : function(newAttr){
  5103. return this.attributes.setNamedItemNS(newAttr);
  5104. },
  5105. removeAttributeNode : function(oldAttr){
  5106. //console.log(this == oldAttr.ownerElement)
  5107. return this.attributes.removeNamedItem(oldAttr.nodeName);
  5108. },
  5109. //get real attribute name,and remove it by removeAttributeNode
  5110. removeAttributeNS : function(namespaceURI, localName){
  5111. var old = this.getAttributeNodeNS(namespaceURI, localName);
  5112. old && this.removeAttributeNode(old);
  5113. },
  5114. hasAttributeNS : function(namespaceURI, localName){
  5115. return this.getAttributeNodeNS(namespaceURI, localName)!=null;
  5116. },
  5117. getAttributeNS : function(namespaceURI, localName){
  5118. var attr = this.getAttributeNodeNS(namespaceURI, localName);
  5119. return attr && attr.value || '';
  5120. },
  5121. setAttributeNS : function(namespaceURI, qualifiedName, value){
  5122. var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
  5123. attr.value = attr.nodeValue = "" + value;
  5124. this.setAttributeNode(attr)
  5125. },
  5126. getAttributeNodeNS : function(namespaceURI, localName){
  5127. return this.attributes.getNamedItemNS(namespaceURI, localName);
  5128. },
  5129. getElementsByTagName : function(tagName){
  5130. return new LiveNodeList(this,function(base){
  5131. var ls = [];
  5132. _visitNode(base,function(node){
  5133. if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
  5134. ls.push(node);
  5135. }
  5136. });
  5137. return ls;
  5138. });
  5139. },
  5140. getElementsByTagNameNS : function(namespaceURI, localName){
  5141. return new LiveNodeList(this,function(base){
  5142. var ls = [];
  5143. _visitNode(base,function(node){
  5144. if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
  5145. ls.push(node);
  5146. }
  5147. });
  5148. return ls;
  5149. });
  5150. }
  5151. };
  5152. Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
  5153. Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
  5154. _extends(Element,Node);
  5155. function Attr() {
  5156. };
  5157. Attr.prototype.nodeType = ATTRIBUTE_NODE;
  5158. _extends(Attr,Node);
  5159. function CharacterData() {
  5160. };
  5161. CharacterData.prototype = {
  5162. data : '',
  5163. substringData : function(offset, count) {
  5164. return this.data.substring(offset, offset+count);
  5165. },
  5166. appendData: function(text) {
  5167. text = this.data+text;
  5168. this.nodeValue = this.data = text;
  5169. this.length = text.length;
  5170. },
  5171. insertData: function(offset,text) {
  5172. this.replaceData(offset,0,text);
  5173. },
  5174. appendChild:function(newChild){
  5175. throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
  5176. },
  5177. deleteData: function(offset, count) {
  5178. this.replaceData(offset,count,"");
  5179. },
  5180. replaceData: function(offset, count, text) {
  5181. var start = this.data.substring(0,offset);
  5182. var end = this.data.substring(offset+count);
  5183. text = start + text + end;
  5184. this.nodeValue = this.data = text;
  5185. this.length = text.length;
  5186. }
  5187. }
  5188. _extends(CharacterData,Node);
  5189. function Text() {
  5190. };
  5191. Text.prototype = {
  5192. nodeName : "#text",
  5193. nodeType : TEXT_NODE,
  5194. splitText : function(offset) {
  5195. var text = this.data;
  5196. var newText = text.substring(offset);
  5197. text = text.substring(0, offset);
  5198. this.data = this.nodeValue = text;
  5199. this.length = text.length;
  5200. var newNode = this.ownerDocument.createTextNode(newText);
  5201. if(this.parentNode){
  5202. this.parentNode.insertBefore(newNode, this.nextSibling);
  5203. }
  5204. return newNode;
  5205. }
  5206. }
  5207. _extends(Text,CharacterData);
  5208. function Comment() {
  5209. };
  5210. Comment.prototype = {
  5211. nodeName : "#comment",
  5212. nodeType : COMMENT_NODE
  5213. }
  5214. _extends(Comment,CharacterData);
  5215. function CDATASection() {
  5216. };
  5217. CDATASection.prototype = {
  5218. nodeName : "#cdata-section",
  5219. nodeType : CDATA_SECTION_NODE
  5220. }
  5221. _extends(CDATASection,CharacterData);
  5222. function DocumentType() {
  5223. };
  5224. DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
  5225. _extends(DocumentType,Node);
  5226. function Notation() {
  5227. };
  5228. Notation.prototype.nodeType = NOTATION_NODE;
  5229. _extends(Notation,Node);
  5230. function Entity() {
  5231. };
  5232. Entity.prototype.nodeType = ENTITY_NODE;
  5233. _extends(Entity,Node);
  5234. function EntityReference() {
  5235. };
  5236. EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
  5237. _extends(EntityReference,Node);
  5238. function DocumentFragment() {
  5239. };
  5240. DocumentFragment.prototype.nodeName = "#document-fragment";
  5241. DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
  5242. _extends(DocumentFragment,Node);
  5243. function ProcessingInstruction() {
  5244. }
  5245. ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
  5246. _extends(ProcessingInstruction,Node);
  5247. function XMLSerializer(){}
  5248. XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
  5249. return nodeSerializeToString.call(node,isHtml,nodeFilter);
  5250. }
  5251. Node.prototype.toString = nodeSerializeToString;
  5252. function nodeSerializeToString(isHtml,nodeFilter){
  5253. var buf = [];
  5254. var refNode = this.nodeType == 9?this.documentElement:this;
  5255. var prefix = refNode.prefix;
  5256. var uri = refNode.namespaceURI;
  5257. if(uri && prefix == null){
  5258. //console.log(prefix)
  5259. var prefix = refNode.lookupPrefix(uri);
  5260. if(prefix == null){
  5261. //isHTML = true;
  5262. var visibleNamespaces=[
  5263. {namespace:uri,prefix:null}
  5264. //{namespace:uri,prefix:''}
  5265. ]
  5266. }
  5267. }
  5268. serializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);
  5269. //console.log('###',this.nodeType,uri,prefix,buf.join(''))
  5270. return buf.join('');
  5271. }
  5272. function needNamespaceDefine(node,isHTML, visibleNamespaces) {
  5273. var prefix = node.prefix||'';
  5274. var uri = node.namespaceURI;
  5275. if (!prefix && !uri){
  5276. return false;
  5277. }
  5278. if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
  5279. || uri == 'http://www.w3.org/2000/xmlns/'){
  5280. return false;
  5281. }
  5282. var i = visibleNamespaces.length
  5283. //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
  5284. while (i--) {
  5285. var ns = visibleNamespaces[i];
  5286. // get namespace prefix
  5287. //console.log(node.nodeType,node.tagName,ns.prefix,prefix)
  5288. if (ns.prefix == prefix){
  5289. return ns.namespace != uri;
  5290. }
  5291. }
  5292. //console.log(isHTML,uri,prefix=='')
  5293. //if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
  5294. // return false;
  5295. //}
  5296. //node.flag = '11111'
  5297. //console.error(3,true,node.flag,node.prefix,node.namespaceURI)
  5298. return true;
  5299. }
  5300. function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
  5301. if(nodeFilter){
  5302. node = nodeFilter(node);
  5303. if(node){
  5304. if(typeof node == 'string'){
  5305. buf.push(node);
  5306. return;
  5307. }
  5308. }else{
  5309. return;
  5310. }
  5311. //buf.sort.apply(attrs, attributeSorter);
  5312. }
  5313. switch(node.nodeType){
  5314. case ELEMENT_NODE:
  5315. if (!visibleNamespaces) visibleNamespaces = [];
  5316. var startVisibleNamespaces = visibleNamespaces.length;
  5317. var attrs = node.attributes;
  5318. var len = attrs.length;
  5319. var child = node.firstChild;
  5320. var nodeName = node.tagName;
  5321. isHTML = (htmlns === node.namespaceURI) ||isHTML
  5322. buf.push('<',nodeName);
  5323. for(var i=0;i<len;i++){
  5324. // add namespaces for attributes
  5325. var attr = attrs.item(i);
  5326. if (attr.prefix == 'xmlns') {
  5327. visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });
  5328. }else if(attr.nodeName == 'xmlns'){
  5329. visibleNamespaces.push({ prefix: '', namespace: attr.value });
  5330. }
  5331. }
  5332. for(var i=0;i<len;i++){
  5333. var attr = attrs.item(i);
  5334. if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
  5335. var prefix = attr.prefix||'';
  5336. var uri = attr.namespaceURI;
  5337. var ns = prefix ? ' xmlns:' + prefix : " xmlns";
  5338. buf.push(ns, '="' , uri , '"');
  5339. visibleNamespaces.push({ prefix: prefix, namespace:uri });
  5340. }
  5341. serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
  5342. }
  5343. // add namespace for current node
  5344. if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
  5345. var prefix = node.prefix||'';
  5346. var uri = node.namespaceURI;
  5347. var ns = prefix ? ' xmlns:' + prefix : " xmlns";
  5348. buf.push(ns, '="' , uri , '"');
  5349. visibleNamespaces.push({ prefix: prefix, namespace:uri });
  5350. }
  5351. if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
  5352. buf.push('>');
  5353. //if is cdata child node
  5354. if(isHTML && /^script$/i.test(nodeName)){
  5355. while(child){
  5356. if(child.data){
  5357. buf.push(child.data);
  5358. }else{
  5359. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  5360. }
  5361. child = child.nextSibling;
  5362. }
  5363. }else
  5364. {
  5365. while(child){
  5366. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  5367. child = child.nextSibling;
  5368. }
  5369. }
  5370. buf.push('</',nodeName,'>');
  5371. }else{
  5372. buf.push('/>');
  5373. }
  5374. // remove added visible namespaces
  5375. //visibleNamespaces.length = startVisibleNamespaces;
  5376. return;
  5377. case DOCUMENT_NODE:
  5378. case DOCUMENT_FRAGMENT_NODE:
  5379. var child = node.firstChild;
  5380. while(child){
  5381. serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
  5382. child = child.nextSibling;
  5383. }
  5384. return;
  5385. case ATTRIBUTE_NODE:
  5386. return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
  5387. case TEXT_NODE:
  5388. return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
  5389. case CDATA_SECTION_NODE:
  5390. return buf.push( '<![CDATA[',node.data,']]>');
  5391. case COMMENT_NODE:
  5392. return buf.push( "<!--",node.data,"-->");
  5393. case DOCUMENT_TYPE_NODE:
  5394. var pubid = node.publicId;
  5395. var sysid = node.systemId;
  5396. buf.push('<!DOCTYPE ',node.name);
  5397. if(pubid){
  5398. buf.push(' PUBLIC "',pubid);
  5399. if (sysid && sysid!='.') {
  5400. buf.push( '" "',sysid);
  5401. }
  5402. buf.push('">');
  5403. }else if(sysid && sysid!='.'){
  5404. buf.push(' SYSTEM "',sysid,'">');
  5405. }else{
  5406. var sub = node.internalSubset;
  5407. if(sub){
  5408. buf.push(" [",sub,"]");
  5409. }
  5410. buf.push(">");
  5411. }
  5412. return;
  5413. case PROCESSING_INSTRUCTION_NODE:
  5414. return buf.push( "<?",node.target," ",node.data,"?>");
  5415. case ENTITY_REFERENCE_NODE:
  5416. return buf.push( '&',node.nodeName,';');
  5417. //case ENTITY_NODE:
  5418. //case NOTATION_NODE:
  5419. default:
  5420. buf.push('??',node.nodeName);
  5421. }
  5422. }
  5423. function importNode(doc,node,deep){
  5424. var node2;
  5425. switch (node.nodeType) {
  5426. case ELEMENT_NODE:
  5427. node2 = node.cloneNode(false);
  5428. node2.ownerDocument = doc;
  5429. //var attrs = node2.attributes;
  5430. //var len = attrs.length;
  5431. //for(var i=0;i<len;i++){
  5432. //node2.setAttributeNodeNS(importNode(doc,attrs.item(i),deep));
  5433. //}
  5434. case DOCUMENT_FRAGMENT_NODE:
  5435. break;
  5436. case ATTRIBUTE_NODE:
  5437. deep = true;
  5438. break;
  5439. //case ENTITY_REFERENCE_NODE:
  5440. //case PROCESSING_INSTRUCTION_NODE:
  5441. ////case TEXT_NODE:
  5442. //case CDATA_SECTION_NODE:
  5443. //case COMMENT_NODE:
  5444. // deep = false;
  5445. // break;
  5446. //case DOCUMENT_NODE:
  5447. //case DOCUMENT_TYPE_NODE:
  5448. //cannot be imported.
  5449. //case ENTITY_NODE:
  5450. //case NOTATION_NODE:
  5451. //can not hit in level3
  5452. //default:throw e;
  5453. }
  5454. if(!node2){
  5455. node2 = node.cloneNode(false);//false
  5456. }
  5457. node2.ownerDocument = doc;
  5458. node2.parentNode = null;
  5459. if(deep){
  5460. var child = node.firstChild;
  5461. while(child){
  5462. node2.appendChild(importNode(doc,child,deep));
  5463. child = child.nextSibling;
  5464. }
  5465. }
  5466. return node2;
  5467. }
  5468. //
  5469. //var _relationMap = {firstChild:1,lastChild:1,previousSibling:1,nextSibling:1,
  5470. // attributes:1,childNodes:1,parentNode:1,documentElement:1,doctype,};
  5471. function cloneNode(doc,node,deep){
  5472. var node2 = new node.constructor();
  5473. for(var n in node){
  5474. var v = node[n];
  5475. if(typeof v != 'object' ){
  5476. if(v != node2[n]){
  5477. node2[n] = v;
  5478. }
  5479. }
  5480. }
  5481. if(node.childNodes){
  5482. node2.childNodes = new NodeList();
  5483. }
  5484. node2.ownerDocument = doc;
  5485. switch (node2.nodeType) {
  5486. case ELEMENT_NODE:
  5487. var attrs = node.attributes;
  5488. var attrs2 = node2.attributes = new NamedNodeMap();
  5489. var len = attrs.length
  5490. attrs2._ownerElement = node2;
  5491. for(var i=0;i<len;i++){
  5492. node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
  5493. }
  5494. break;;
  5495. case ATTRIBUTE_NODE:
  5496. deep = true;
  5497. }
  5498. if(deep){
  5499. var child = node.firstChild;
  5500. while(child){
  5501. node2.appendChild(cloneNode(doc,child,deep));
  5502. child = child.nextSibling;
  5503. }
  5504. }
  5505. return node2;
  5506. }
  5507. function __set__(object,key,value){
  5508. object[key] = value
  5509. }
  5510. //do dynamic
  5511. try{
  5512. if(Object.defineProperty){
  5513. Object.defineProperty(LiveNodeList.prototype,'length',{
  5514. get:function(){
  5515. _updateLiveList(this);
  5516. return this.$$length;
  5517. }
  5518. });
  5519. Object.defineProperty(Node.prototype,'textContent',{
  5520. get:function(){
  5521. return getTextContent(this);
  5522. },
  5523. set:function(data){
  5524. switch(this.nodeType){
  5525. case ELEMENT_NODE:
  5526. case DOCUMENT_FRAGMENT_NODE:
  5527. while(this.firstChild){
  5528. this.removeChild(this.firstChild);
  5529. }
  5530. if(data || String(data)){
  5531. this.appendChild(this.ownerDocument.createTextNode(data));
  5532. }
  5533. break;
  5534. default:
  5535. //TODO:
  5536. this.data = data;
  5537. this.value = data;
  5538. this.nodeValue = data;
  5539. }
  5540. }
  5541. })
  5542. function getTextContent(node){
  5543. switch(node.nodeType){
  5544. case ELEMENT_NODE:
  5545. case DOCUMENT_FRAGMENT_NODE:
  5546. var buf = [];
  5547. node = node.firstChild;
  5548. while(node){
  5549. if(node.nodeType!==7 && node.nodeType !==8){
  5550. buf.push(getTextContent(node));
  5551. }
  5552. node = node.nextSibling;
  5553. }
  5554. return buf.join('');
  5555. default:
  5556. return node.nodeValue;
  5557. }
  5558. }
  5559. __set__ = function(object,key,value){
  5560. //console.log(value)
  5561. object['$$'+key] = value
  5562. }
  5563. }
  5564. }catch(e){//ie8
  5565. }
  5566. //if(typeof require == 'function'){
  5567. exports.DOMImplementation = DOMImplementation;
  5568. exports.XMLSerializer = XMLSerializer;
  5569. //}
  5570. },{}],32:[function(require,module,exports){
  5571. //[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]
  5572. //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
  5573. //[5] Name ::= NameStartChar (NameChar)*
  5574. 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
  5575. var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
  5576. var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
  5577. //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
  5578. //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(',')
  5579. //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
  5580. //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
  5581. var S_TAG = 0;//tag name offerring
  5582. var S_ATTR = 1;//attr name offerring
  5583. var S_ATTR_SPACE=2;//attr name end and space offer
  5584. var S_EQ = 3;//=space?
  5585. var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
  5586. var S_ATTR_END = 5;//attr value end and no space(quot end)
  5587. var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
  5588. var S_TAG_CLOSE = 7;//closed el<el />
  5589. function XMLReader(){
  5590. }
  5591. XMLReader.prototype = {
  5592. parse:function(source,defaultNSMap,entityMap){
  5593. var domBuilder = this.domBuilder;
  5594. domBuilder.startDocument();
  5595. _copy(defaultNSMap ,defaultNSMap = {})
  5596. parse(source,defaultNSMap,entityMap,
  5597. domBuilder,this.errorHandler);
  5598. domBuilder.endDocument();
  5599. }
  5600. }
  5601. function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
  5602. function fixedFromCharCode(code) {
  5603. // String.prototype.fromCharCode does not supports
  5604. // > 2 bytes unicode chars directly
  5605. if (code > 0xffff) {
  5606. code -= 0x10000;
  5607. var surrogate1 = 0xd800 + (code >> 10)
  5608. , surrogate2 = 0xdc00 + (code & 0x3ff);
  5609. return String.fromCharCode(surrogate1, surrogate2);
  5610. } else {
  5611. return String.fromCharCode(code);
  5612. }
  5613. }
  5614. function entityReplacer(a){
  5615. var k = a.slice(1,-1);
  5616. if(k in entityMap){
  5617. return entityMap[k];
  5618. }else if(k.charAt(0) === '#'){
  5619. return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
  5620. }else{
  5621. errorHandler.error('entity not found:'+a);
  5622. return a;
  5623. }
  5624. }
  5625. function appendText(end){//has some bugs
  5626. if(end>start){
  5627. var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
  5628. locator&&position(start);
  5629. domBuilder.characters(xt,0,end-start);
  5630. start = end
  5631. }
  5632. }
  5633. function position(p,m){
  5634. while(p>=lineEnd && (m = linePattern.exec(source))){
  5635. lineStart = m.index;
  5636. lineEnd = lineStart + m[0].length;
  5637. locator.lineNumber++;
  5638. //console.log('line++:',locator,startPos,endPos)
  5639. }
  5640. locator.columnNumber = p-lineStart+1;
  5641. }
  5642. var lineStart = 0;
  5643. var lineEnd = 0;
  5644. var linePattern = /.*(?:\r\n?|\n)|.*$/g
  5645. var locator = domBuilder.locator;
  5646. var parseStack = [{currentNSMap:defaultNSMapCopy}]
  5647. var closeMap = {};
  5648. var start = 0;
  5649. while(true){
  5650. try{
  5651. var tagStart = source.indexOf('<',start);
  5652. if(tagStart<0){
  5653. if(!source.substr(start).match(/^\s*$/)){
  5654. var doc = domBuilder.doc;
  5655. var text = doc.createTextNode(source.substr(start));
  5656. doc.appendChild(text);
  5657. domBuilder.currentElement = text;
  5658. }
  5659. return;
  5660. }
  5661. if(tagStart>start){
  5662. appendText(tagStart);
  5663. }
  5664. switch(source.charAt(tagStart+1)){
  5665. case '/':
  5666. var end = source.indexOf('>',tagStart+3);
  5667. var tagName = source.substring(tagStart+2,end);
  5668. var config = parseStack.pop();
  5669. if(end<0){
  5670. tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
  5671. //console.error('#@@@@@@'+tagName)
  5672. errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
  5673. end = tagStart+1+tagName.length;
  5674. }else if(tagName.match(/\s</)){
  5675. tagName = tagName.replace(/[\s<].*/,'');
  5676. errorHandler.error("end tag name: "+tagName+' maybe not complete');
  5677. end = tagStart+1+tagName.length;
  5678. }
  5679. //console.error(parseStack.length,parseStack)
  5680. //console.error(config);
  5681. var localNSMap = config.localNSMap;
  5682. var endMatch = config.tagName == tagName;
  5683. var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
  5684. if(endIgnoreCaseMach){
  5685. domBuilder.endElement(config.uri,config.localName,tagName);
  5686. if(localNSMap){
  5687. for(var prefix in localNSMap){
  5688. domBuilder.endPrefixMapping(prefix) ;
  5689. }
  5690. }
  5691. if(!endMatch){
  5692. errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
  5693. }
  5694. }else{
  5695. parseStack.push(config)
  5696. }
  5697. end++;
  5698. break;
  5699. // end elment
  5700. case '?':// <?...?>
  5701. locator&&position(tagStart);
  5702. end = parseInstruction(source,tagStart,domBuilder);
  5703. break;
  5704. case '!':// <!doctype,<![CDATA,<!--
  5705. locator&&position(tagStart);
  5706. end = parseDCC(source,tagStart,domBuilder,errorHandler);
  5707. break;
  5708. default:
  5709. locator&&position(tagStart);
  5710. var el = new ElementAttributes();
  5711. var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  5712. //elStartEnd
  5713. var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
  5714. var len = el.length;
  5715. if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
  5716. el.closed = true;
  5717. if(!entityMap.nbsp){
  5718. errorHandler.warning('unclosed xml attribute');
  5719. }
  5720. }
  5721. if(locator && len){
  5722. var locator2 = copyLocator(locator,{});
  5723. //try{//attribute position fixed
  5724. for(var i = 0;i<len;i++){
  5725. var a = el[i];
  5726. position(a.offset);
  5727. a.locator = copyLocator(locator,{});
  5728. }
  5729. //}catch(e){console.error('@@@@@'+e)}
  5730. domBuilder.locator = locator2
  5731. if(appendElement(el,domBuilder,currentNSMap)){
  5732. parseStack.push(el)
  5733. }
  5734. domBuilder.locator = locator;
  5735. }else{
  5736. if(appendElement(el,domBuilder,currentNSMap)){
  5737. parseStack.push(el)
  5738. }
  5739. }
  5740. if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
  5741. end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
  5742. }else{
  5743. end++;
  5744. }
  5745. }
  5746. }catch(e){
  5747. errorHandler.error('element parse error: '+e)
  5748. //errorHandler.error('element parse error: '+e);
  5749. end = -1;
  5750. //throw e;
  5751. }
  5752. if(end>start){
  5753. start = end;
  5754. }else{
  5755. //TODO: 这里有可能sax回退,有位置错误风险
  5756. appendText(Math.max(tagStart,start)+1);
  5757. }
  5758. }
  5759. }
  5760. function copyLocator(f,t){
  5761. t.lineNumber = f.lineNumber;
  5762. t.columnNumber = f.columnNumber;
  5763. return t;
  5764. }
  5765. /**
  5766. * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
  5767. * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
  5768. */
  5769. function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
  5770. var attrName;
  5771. var value;
  5772. var p = ++start;
  5773. var s = S_TAG;//status
  5774. while(true){
  5775. var c = source.charAt(p);
  5776. switch(c){
  5777. case '=':
  5778. if(s === S_ATTR){//attrName
  5779. attrName = source.slice(start,p);
  5780. s = S_EQ;
  5781. }else if(s === S_ATTR_SPACE){
  5782. s = S_EQ;
  5783. }else{
  5784. //fatalError: equal must after attrName or space after attrName
  5785. throw new Error('attribute equal must after attrName');
  5786. }
  5787. break;
  5788. case '\'':
  5789. case '"':
  5790. if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
  5791. ){//equal
  5792. if(s === S_ATTR){
  5793. errorHandler.warning('attribute value must after "="')
  5794. attrName = source.slice(start,p)
  5795. }
  5796. start = p+1;
  5797. p = source.indexOf(c,start)
  5798. if(p>0){
  5799. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  5800. el.add(attrName,value,start-1);
  5801. s = S_ATTR_END;
  5802. }else{
  5803. //fatalError: no end quot match
  5804. throw new Error('attribute value no end \''+c+'\' match');
  5805. }
  5806. }else if(s == S_ATTR_NOQUOT_VALUE){
  5807. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  5808. //console.log(attrName,value,start,p)
  5809. el.add(attrName,value,start);
  5810. //console.dir(el)
  5811. errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
  5812. start = p+1;
  5813. s = S_ATTR_END
  5814. }else{
  5815. //fatalError: no equal before
  5816. throw new Error('attribute value must after "="');
  5817. }
  5818. break;
  5819. case '/':
  5820. switch(s){
  5821. case S_TAG:
  5822. el.setTagName(source.slice(start,p));
  5823. case S_ATTR_END:
  5824. case S_TAG_SPACE:
  5825. case S_TAG_CLOSE:
  5826. s =S_TAG_CLOSE;
  5827. el.closed = true;
  5828. case S_ATTR_NOQUOT_VALUE:
  5829. case S_ATTR:
  5830. case S_ATTR_SPACE:
  5831. break;
  5832. //case S_EQ:
  5833. default:
  5834. throw new Error("attribute invalid close char('/')")
  5835. }
  5836. break;
  5837. case ''://end document
  5838. //throw new Error('unexpected end of input')
  5839. errorHandler.error('unexpected end of input');
  5840. if(s == S_TAG){
  5841. el.setTagName(source.slice(start,p));
  5842. }
  5843. return p;
  5844. case '>':
  5845. switch(s){
  5846. case S_TAG:
  5847. el.setTagName(source.slice(start,p));
  5848. case S_ATTR_END:
  5849. case S_TAG_SPACE:
  5850. case S_TAG_CLOSE:
  5851. break;//normal
  5852. case S_ATTR_NOQUOT_VALUE://Compatible state
  5853. case S_ATTR:
  5854. value = source.slice(start,p);
  5855. if(value.slice(-1) === '/'){
  5856. el.closed = true;
  5857. value = value.slice(0,-1)
  5858. }
  5859. case S_ATTR_SPACE:
  5860. if(s === S_ATTR_SPACE){
  5861. value = attrName;
  5862. }
  5863. if(s == S_ATTR_NOQUOT_VALUE){
  5864. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  5865. el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
  5866. }else{
  5867. if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
  5868. errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
  5869. }
  5870. el.add(value,value,start)
  5871. }
  5872. break;
  5873. case S_EQ:
  5874. throw new Error('attribute value missed!!');
  5875. }
  5876. // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
  5877. return p;
  5878. /*xml space '\x20' | #x9 | #xD | #xA; */
  5879. case '\u0080':
  5880. c = ' ';
  5881. default:
  5882. if(c<= ' '){//space
  5883. switch(s){
  5884. case S_TAG:
  5885. el.setTagName(source.slice(start,p));//tagName
  5886. s = S_TAG_SPACE;
  5887. break;
  5888. case S_ATTR:
  5889. attrName = source.slice(start,p)
  5890. s = S_ATTR_SPACE;
  5891. break;
  5892. case S_ATTR_NOQUOT_VALUE:
  5893. var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  5894. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  5895. el.add(attrName,value,start)
  5896. case S_ATTR_END:
  5897. s = S_TAG_SPACE;
  5898. break;
  5899. //case S_TAG_SPACE:
  5900. //case S_EQ:
  5901. //case S_ATTR_SPACE:
  5902. // void();break;
  5903. //case S_TAG_CLOSE:
  5904. //ignore warning
  5905. }
  5906. }else{//not space
  5907. //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
  5908. //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
  5909. switch(s){
  5910. //case S_TAG:void();break;
  5911. //case S_ATTR:void();break;
  5912. //case S_ATTR_NOQUOT_VALUE:void();break;
  5913. case S_ATTR_SPACE:
  5914. var tagName = el.tagName;
  5915. if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
  5916. errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
  5917. }
  5918. el.add(attrName,attrName,start);
  5919. start = p;
  5920. s = S_ATTR;
  5921. break;
  5922. case S_ATTR_END:
  5923. errorHandler.warning('attribute space is required"'+attrName+'"!!')
  5924. case S_TAG_SPACE:
  5925. s = S_ATTR;
  5926. start = p;
  5927. break;
  5928. case S_EQ:
  5929. s = S_ATTR_NOQUOT_VALUE;
  5930. start = p;
  5931. break;
  5932. case S_TAG_CLOSE:
  5933. throw new Error("elements closed character '/' and '>' must be connected to");
  5934. }
  5935. }
  5936. }//end outer switch
  5937. //console.log('p++',p)
  5938. p++;
  5939. }
  5940. }
  5941. /**
  5942. * @return true if has new namespace define
  5943. */
  5944. function appendElement(el,domBuilder,currentNSMap){
  5945. var tagName = el.tagName;
  5946. var localNSMap = null;
  5947. //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  5948. var i = el.length;
  5949. while(i--){
  5950. var a = el[i];
  5951. var qName = a.qName;
  5952. var value = a.value;
  5953. var nsp = qName.indexOf(':');
  5954. if(nsp>0){
  5955. var prefix = a.prefix = qName.slice(0,nsp);
  5956. var localName = qName.slice(nsp+1);
  5957. var nsPrefix = prefix === 'xmlns' && localName
  5958. }else{
  5959. localName = qName;
  5960. prefix = null
  5961. nsPrefix = qName === 'xmlns' && ''
  5962. }
  5963. //can not set prefix,because prefix !== ''
  5964. a.localName = localName ;
  5965. //prefix == null for no ns prefix attribute
  5966. if(nsPrefix !== false){//hack!!
  5967. if(localNSMap == null){
  5968. localNSMap = {}
  5969. //console.log(currentNSMap,0)
  5970. _copy(currentNSMap,currentNSMap={})
  5971. //console.log(currentNSMap,1)
  5972. }
  5973. currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
  5974. a.uri = 'http://www.w3.org/2000/xmlns/'
  5975. domBuilder.startPrefixMapping(nsPrefix, value)
  5976. }
  5977. }
  5978. var i = el.length;
  5979. while(i--){
  5980. a = el[i];
  5981. var prefix = a.prefix;
  5982. if(prefix){//no prefix attribute has no namespace
  5983. if(prefix === 'xml'){
  5984. a.uri = 'http://www.w3.org/XML/1998/namespace';
  5985. }if(prefix !== 'xmlns'){
  5986. a.uri = currentNSMap[prefix || '']
  5987. //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
  5988. }
  5989. }
  5990. }
  5991. var nsp = tagName.indexOf(':');
  5992. if(nsp>0){
  5993. prefix = el.prefix = tagName.slice(0,nsp);
  5994. localName = el.localName = tagName.slice(nsp+1);
  5995. }else{
  5996. prefix = null;//important!!
  5997. localName = el.localName = tagName;
  5998. }
  5999. //no prefix element has default namespace
  6000. var ns = el.uri = currentNSMap[prefix || ''];
  6001. domBuilder.startElement(ns,localName,tagName,el);
  6002. //endPrefixMapping and startPrefixMapping have not any help for dom builder
  6003. //localNSMap = null
  6004. if(el.closed){
  6005. domBuilder.endElement(ns,localName,tagName);
  6006. if(localNSMap){
  6007. for(prefix in localNSMap){
  6008. domBuilder.endPrefixMapping(prefix)
  6009. }
  6010. }
  6011. }else{
  6012. el.currentNSMap = currentNSMap;
  6013. el.localNSMap = localNSMap;
  6014. //parseStack.push(el);
  6015. return true;
  6016. }
  6017. }
  6018. function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
  6019. if(/^(?:script|textarea)$/i.test(tagName)){
  6020. var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
  6021. var text = source.substring(elStartEnd+1,elEndStart);
  6022. if(/[&<]/.test(text)){
  6023. if(/^script$/i.test(tagName)){
  6024. //if(!/\]\]>/.test(text)){
  6025. //lexHandler.startCDATA();
  6026. domBuilder.characters(text,0,text.length);
  6027. //lexHandler.endCDATA();
  6028. return elEndStart;
  6029. //}
  6030. }//}else{//text area
  6031. text = text.replace(/&#?\w+;/g,entityReplacer);
  6032. domBuilder.characters(text,0,text.length);
  6033. return elEndStart;
  6034. //}
  6035. }
  6036. }
  6037. return elStartEnd+1;
  6038. }
  6039. function fixSelfClosed(source,elStartEnd,tagName,closeMap){
  6040. //if(tagName in closeMap){
  6041. var pos = closeMap[tagName];
  6042. if(pos == null){
  6043. //console.log(tagName)
  6044. pos = source.lastIndexOf('</'+tagName+'>')
  6045. if(pos<elStartEnd){//忘记闭合
  6046. pos = source.lastIndexOf('</'+tagName)
  6047. }
  6048. closeMap[tagName] =pos
  6049. }
  6050. return pos<elStartEnd;
  6051. //}
  6052. }
  6053. function _copy(source,target){
  6054. for(var n in source){target[n] = source[n]}
  6055. }
  6056. function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
  6057. var next= source.charAt(start+2)
  6058. switch(next){
  6059. case '-':
  6060. if(source.charAt(start + 3) === '-'){
  6061. var end = source.indexOf('-->',start+4);
  6062. //append comment source.substring(4,end)//<!--
  6063. if(end>start){
  6064. domBuilder.comment(source,start+4,end-start-4);
  6065. return end+3;
  6066. }else{
  6067. errorHandler.error("Unclosed comment");
  6068. return -1;
  6069. }
  6070. }else{
  6071. //error
  6072. return -1;
  6073. }
  6074. default:
  6075. if(source.substr(start+3,6) == 'CDATA['){
  6076. var end = source.indexOf(']]>',start+9);
  6077. domBuilder.startCDATA();
  6078. domBuilder.characters(source,start+9,end-start-9);
  6079. domBuilder.endCDATA()
  6080. return end+3;
  6081. }
  6082. //<!DOCTYPE
  6083. //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
  6084. var matchs = split(source,start);
  6085. var len = matchs.length;
  6086. if(len>1 && /!doctype/i.test(matchs[0][0])){
  6087. var name = matchs[1][0];
  6088. var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
  6089. var sysid = len>4 && matchs[4][0];
  6090. var lastMatch = matchs[len-1]
  6091. domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
  6092. sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
  6093. domBuilder.endDTD();
  6094. return lastMatch.index+lastMatch[0].length
  6095. }
  6096. }
  6097. return -1;
  6098. }
  6099. function parseInstruction(source,start,domBuilder){
  6100. var end = source.indexOf('?>',start);
  6101. if(end){
  6102. var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
  6103. if(match){
  6104. var len = match[0].length;
  6105. domBuilder.processingInstruction(match[1], match[2]) ;
  6106. return end+2;
  6107. }else{//error
  6108. return -1;
  6109. }
  6110. }
  6111. return -1;
  6112. }
  6113. /**
  6114. * @param source
  6115. */
  6116. function ElementAttributes(source){
  6117. }
  6118. ElementAttributes.prototype = {
  6119. setTagName:function(tagName){
  6120. if(!tagNamePattern.test(tagName)){
  6121. throw new Error('invalid tagName:'+tagName)
  6122. }
  6123. this.tagName = tagName
  6124. },
  6125. add:function(qName,value,offset){
  6126. if(!tagNamePattern.test(qName)){
  6127. throw new Error('invalid attribute:'+qName)
  6128. }
  6129. this[this.length++] = {qName:qName,value:value,offset:offset}
  6130. },
  6131. length:0,
  6132. getLocalName:function(i){return this[i].localName},
  6133. getLocator:function(i){return this[i].locator},
  6134. getQName:function(i){return this[i].qName},
  6135. getURI:function(i){return this[i].uri},
  6136. getValue:function(i){return this[i].value}
  6137. // ,getIndex:function(uri, localName)){
  6138. // if(localName){
  6139. //
  6140. // }else{
  6141. // var qName = uri
  6142. // }
  6143. // },
  6144. // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
  6145. // getType:function(uri,localName){}
  6146. // getType:function(i){},
  6147. }
  6148. function _set_proto_(thiz,parent){
  6149. thiz.__proto__ = parent;
  6150. return thiz;
  6151. }
  6152. if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
  6153. _set_proto_ = function(thiz,parent){
  6154. function p(){};
  6155. p.prototype = parent;
  6156. p = new p();
  6157. for(parent in thiz){
  6158. p[parent] = thiz[parent];
  6159. }
  6160. return p;
  6161. }
  6162. }
  6163. function split(source,start){
  6164. var match;
  6165. var buf = [];
  6166. var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
  6167. reg.lastIndex = start;
  6168. reg.exec(source);//skip <
  6169. while(match = reg.exec(source)){
  6170. buf.push(match);
  6171. if(match[1])return buf;
  6172. }
  6173. }
  6174. exports.XMLReader = XMLReader;
  6175. },{}]},{},[1])(1)
  6176. });