jsoneditor.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377
  1. /*!
  2. * jsoneditor.js
  3. *
  4. * @brief
  5. * JSONEditor is a web-based tool to view, edit, format, and validate JSON.
  6. * It has various modes such as a tree editor, a code editor, and a plain text
  7. * editor.
  8. *
  9. * Supported browsers: Chrome, Firefox, Safari, Opera, Internet Explorer 8+
  10. *
  11. * @license
  12. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  13. * use this file except in compliance with the License. You may obtain a copy
  14. * of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  21. * License for the specific language governing permissions and limitations under
  22. * the License.
  23. *
  24. * Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org
  25. *
  26. * @author Jos de Jong, <wjosdejong@gmail.com>
  27. * @version 5.5.11
  28. * @date 2017-01-06
  29. */
  30. (function webpackUniversalModuleDefinition(root, factory) {
  31. if(typeof exports === 'object' && typeof module === 'object')
  32. module.exports = factory();
  33. else if(typeof define === 'function' && define.amd)
  34. define([], factory);
  35. else if(typeof exports === 'object')
  36. exports["JSONEditor"] = factory();
  37. else
  38. root["JSONEditor"] = factory();
  39. })(this, function() {
  40. return /******/ (function(modules) { // webpackBootstrap
  41. /******/ // The module cache
  42. /******/ var installedModules = {};
  43. /******/ // The require function
  44. /******/ function __webpack_require__(moduleId) {
  45. /******/ // Check if module is in cache
  46. /******/ if(installedModules[moduleId])
  47. /******/ return installedModules[moduleId].exports;
  48. /******/ // Create a new module (and put it into the cache)
  49. /******/ var module = installedModules[moduleId] = {
  50. /******/ exports: {},
  51. /******/ id: moduleId,
  52. /******/ loaded: false
  53. /******/ };
  54. /******/ // Execute the module function
  55. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  56. /******/ // Flag the module as loaded
  57. /******/ module.loaded = true;
  58. /******/ // Return the exports of the module
  59. /******/ return module.exports;
  60. /******/ }
  61. /******/ // expose the modules object (__webpack_modules__)
  62. /******/ __webpack_require__.m = modules;
  63. /******/ // expose the module cache
  64. /******/ __webpack_require__.c = installedModules;
  65. /******/ // __webpack_public_path__
  66. /******/ __webpack_require__.p = "";
  67. /******/ // Load entry module and return exports
  68. /******/ return __webpack_require__(0);
  69. /******/ })
  70. /************************************************************************/
  71. /******/ ([
  72. /* 0 */
  73. /***/ function(module, exports, __webpack_require__) {
  74. 'use strict';
  75. var Ajv;
  76. try {
  77. Ajv = __webpack_require__(1);
  78. }
  79. catch (err) {
  80. // no problem... when we need Ajv we will throw a neat exception
  81. }
  82. var treemode = __webpack_require__(51);
  83. var textmode = __webpack_require__(62);
  84. var util = __webpack_require__(54);
  85. /**
  86. * @constructor JSONEditor
  87. * @param {Element} container Container element
  88. * @param {Object} [options] Object with options. available options:
  89. * {String} mode Editor mode. Available values:
  90. * 'tree' (default), 'view',
  91. * 'form', 'text', and 'code'.
  92. * {function} onChange Callback method, triggered
  93. * on change of contents
  94. * {function} onError Callback method, triggered
  95. * when an error occurs
  96. * {Boolean} search Enable search box.
  97. * True by default
  98. * Only applicable for modes
  99. * 'tree', 'view', and 'form'
  100. * {Boolean} history Enable history (undo/redo).
  101. * True by default
  102. * Only applicable for modes
  103. * 'tree', 'view', and 'form'
  104. * {String} name Field name for the root node.
  105. * Only applicable for modes
  106. * 'tree', 'view', and 'form'
  107. * {Number} indentation Number of indentation
  108. * spaces. 4 by default.
  109. * Only applicable for
  110. * modes 'text' and 'code'
  111. * {boolean} escapeUnicode If true, unicode
  112. * characters are escaped.
  113. * false by default.
  114. * {boolean} sortObjectKeys If true, object keys are
  115. * sorted before display.
  116. * false by default.
  117. * @param {Object | undefined} json JSON object
  118. */
  119. function JSONEditor (container, options, json) {
  120. if (!(this instanceof JSONEditor)) {
  121. throw new Error('JSONEditor constructor called without "new".');
  122. }
  123. // check for unsupported browser (IE8 and older)
  124. var ieVersion = util.getInternetExplorerVersion();
  125. if (ieVersion != -1 && ieVersion < 9) {
  126. throw new Error('Unsupported browser, IE9 or newer required. ' +
  127. 'Please install the newest version of your browser.');
  128. }
  129. if (options) {
  130. // check for deprecated options
  131. if (options.error) {
  132. console.warn('Option "error" has been renamed to "onError"');
  133. options.onError = options.error;
  134. delete options.error;
  135. }
  136. if (options.change) {
  137. console.warn('Option "change" has been renamed to "onChange"');
  138. options.onChange = options.change;
  139. delete options.change;
  140. }
  141. if (options.editable) {
  142. console.warn('Option "editable" has been renamed to "onEditable"');
  143. options.onEditable = options.editable;
  144. delete options.editable;
  145. }
  146. // validate options
  147. if (options) {
  148. var VALID_OPTIONS = [
  149. 'ace', 'theme',
  150. 'ajv', 'schema',
  151. 'onChange', 'onEditable', 'onError', 'onModeChange',
  152. 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys'
  153. ];
  154. Object.keys(options).forEach(function (option) {
  155. if (VALID_OPTIONS.indexOf(option) === -1) {
  156. console.warn('Unknown option "' + option + '". This option will be ignored');
  157. }
  158. });
  159. }
  160. }
  161. if (arguments.length) {
  162. this._create(container, options, json);
  163. }
  164. }
  165. /**
  166. * Configuration for all registered modes. Example:
  167. * {
  168. * tree: {
  169. * mixin: TreeEditor,
  170. * data: 'json'
  171. * },
  172. * text: {
  173. * mixin: TextEditor,
  174. * data: 'text'
  175. * }
  176. * }
  177. *
  178. * @type { Object.<String, {mixin: Object, data: String} > }
  179. */
  180. JSONEditor.modes = {};
  181. // debounce interval for JSON schema vaidation in milliseconds
  182. JSONEditor.prototype.DEBOUNCE_INTERVAL = 150;
  183. /**
  184. * Create the JSONEditor
  185. * @param {Element} container Container element
  186. * @param {Object} [options] See description in constructor
  187. * @param {Object | undefined} json JSON object
  188. * @private
  189. */
  190. JSONEditor.prototype._create = function (container, options, json) {
  191. this.container = container;
  192. this.options = options || {};
  193. this.json = json || {};
  194. var mode = this.options.mode || 'tree';
  195. this.setMode(mode);
  196. };
  197. /**
  198. * Destroy the editor. Clean up DOM, event listeners, and web workers.
  199. */
  200. JSONEditor.prototype.destroy = function () {};
  201. /**
  202. * Set JSON object in editor
  203. * @param {Object | undefined} json JSON data
  204. */
  205. JSONEditor.prototype.set = function (json) {
  206. this.json = json;
  207. };
  208. /**
  209. * Get JSON from the editor
  210. * @returns {Object} json
  211. */
  212. JSONEditor.prototype.get = function () {
  213. return this.json;
  214. };
  215. /**
  216. * Set string containing JSON for the editor
  217. * @param {String | undefined} jsonText
  218. */
  219. JSONEditor.prototype.setText = function (jsonText) {
  220. this.json = util.parse(jsonText);
  221. };
  222. /**
  223. * Get stringified JSON contents from the editor
  224. * @returns {String} jsonText
  225. */
  226. JSONEditor.prototype.getText = function () {
  227. return JSON.stringify(this.json);
  228. };
  229. /**
  230. * Set a field name for the root node.
  231. * @param {String | undefined} name
  232. */
  233. JSONEditor.prototype.setName = function (name) {
  234. if (!this.options) {
  235. this.options = {};
  236. }
  237. this.options.name = name;
  238. };
  239. /**
  240. * Get the field name for the root node.
  241. * @return {String | undefined} name
  242. */
  243. JSONEditor.prototype.getName = function () {
  244. return this.options && this.options.name;
  245. };
  246. /**
  247. * Change the mode of the editor.
  248. * JSONEditor will be extended with all methods needed for the chosen mode.
  249. * @param {String} mode Available modes: 'tree' (default), 'view', 'form',
  250. * 'text', and 'code'.
  251. */
  252. JSONEditor.prototype.setMode = function (mode) {
  253. var container = this.container;
  254. var options = util.extend({}, this.options);
  255. var oldMode = options.mode;
  256. var data;
  257. var name;
  258. options.mode = mode;
  259. var config = JSONEditor.modes[mode];
  260. if (config) {
  261. try {
  262. var asText = (config.data == 'text');
  263. name = this.getName();
  264. data = this[asText ? 'getText' : 'get'](); // get text or json
  265. this.destroy();
  266. util.clear(this);
  267. util.extend(this, config.mixin);
  268. this.create(container, options);
  269. this.setName(name);
  270. this[asText ? 'setText' : 'set'](data); // set text or json
  271. if (typeof config.load === 'function') {
  272. try {
  273. config.load.call(this);
  274. }
  275. catch (err) {
  276. console.error(err);
  277. }
  278. }
  279. if (typeof options.onModeChange === 'function' && mode !== oldMode) {
  280. try {
  281. options.onModeChange(mode, oldMode);
  282. }
  283. catch (err) {
  284. console.error(err);
  285. }
  286. }
  287. }
  288. catch (err) {
  289. this._onError(err);
  290. }
  291. }
  292. else {
  293. throw new Error('Unknown mode "' + options.mode + '"');
  294. }
  295. };
  296. /**
  297. * Get the current mode
  298. * @return {string}
  299. */
  300. JSONEditor.prototype.getMode = function () {
  301. return this.options.mode;
  302. };
  303. /**
  304. * Throw an error. If an error callback is configured in options.error, this
  305. * callback will be invoked. Else, a regular error is thrown.
  306. * @param {Error} err
  307. * @private
  308. */
  309. JSONEditor.prototype._onError = function(err) {
  310. if (this.options && typeof this.options.onError === 'function') {
  311. this.options.onError(err);
  312. }
  313. else {
  314. throw err;
  315. }
  316. };
  317. /**
  318. * Set a JSON schema for validation of the JSON object.
  319. * To remove the schema, call JSONEditor.setSchema(null)
  320. * @param {Object | null} schema
  321. */
  322. JSONEditor.prototype.setSchema = function (schema) {
  323. // compile a JSON schema validator if a JSON schema is provided
  324. if (schema) {
  325. var ajv;
  326. try {
  327. // grab ajv from options if provided, else create a new instance
  328. ajv = this.options.ajv || Ajv({ allErrors: true, verbose: true });
  329. }
  330. catch (err) {
  331. console.warn('Failed to create an instance of Ajv, JSON Schema validation is not available. Please use a JSONEditor bundle including Ajv, or pass an instance of Ajv as via the configuration option `ajv`.');
  332. }
  333. if (ajv) {
  334. this.validateSchema = ajv.compile(schema);
  335. // add schema to the options, so that when switching to an other mode,
  336. // the set schema is not lost
  337. this.options.schema = schema;
  338. // validate now
  339. this.validate();
  340. }
  341. this.refresh(); // update DOM
  342. }
  343. else {
  344. // remove current schema
  345. this.validateSchema = null;
  346. this.options.schema = null;
  347. this.validate(); // to clear current error messages
  348. this.refresh(); // update DOM
  349. }
  350. };
  351. /**
  352. * Validate current JSON object against the configured JSON schema
  353. * Throws an exception when no JSON schema is configured
  354. */
  355. JSONEditor.prototype.validate = function () {
  356. // must be implemented by treemode and textmode
  357. };
  358. /**
  359. * Refresh the rendered contents
  360. */
  361. JSONEditor.prototype.refresh = function () {
  362. // can be implemented by treemode and textmode
  363. };
  364. /**
  365. * Register a plugin with one ore multiple modes for the JSON Editor.
  366. *
  367. * A mode is described as an object with properties:
  368. *
  369. * - `mode: String` The name of the mode.
  370. * - `mixin: Object` An object containing the mixin functions which
  371. * will be added to the JSONEditor. Must contain functions
  372. * create, get, getText, set, and setText. May have
  373. * additional functions.
  374. * When the JSONEditor switches to a mixin, all mixin
  375. * functions are added to the JSONEditor, and then
  376. * the function `create(container, options)` is executed.
  377. * - `data: 'text' | 'json'` The type of data that will be used to load the mixin.
  378. * - `[load: function]` An optional function called after the mixin
  379. * has been loaded.
  380. *
  381. * @param {Object | Array} mode A mode object or an array with multiple mode objects.
  382. */
  383. JSONEditor.registerMode = function (mode) {
  384. var i, prop;
  385. if (util.isArray(mode)) {
  386. // multiple modes
  387. for (i = 0; i < mode.length; i++) {
  388. JSONEditor.registerMode(mode[i]);
  389. }
  390. }
  391. else {
  392. // validate the new mode
  393. if (!('mode' in mode)) throw new Error('Property "mode" missing');
  394. if (!('mixin' in mode)) throw new Error('Property "mixin" missing');
  395. if (!('data' in mode)) throw new Error('Property "data" missing');
  396. var name = mode.mode;
  397. if (name in JSONEditor.modes) {
  398. throw new Error('Mode "' + name + '" already registered');
  399. }
  400. // validate the mixin
  401. if (typeof mode.mixin.create !== 'function') {
  402. throw new Error('Required function "create" missing on mixin');
  403. }
  404. var reserved = ['setMode', 'registerMode', 'modes'];
  405. for (i = 0; i < reserved.length; i++) {
  406. prop = reserved[i];
  407. if (prop in mode.mixin) {
  408. throw new Error('Reserved property "' + prop + '" not allowed in mixin');
  409. }
  410. }
  411. JSONEditor.modes[name] = mode;
  412. }
  413. };
  414. // register tree and text modes
  415. JSONEditor.registerMode(treemode);
  416. JSONEditor.registerMode(textmode);
  417. module.exports = JSONEditor;
  418. /***/ },
  419. /* 1 */
  420. /***/ function(module, exports, __webpack_require__) {
  421. 'use strict';
  422. var compileSchema = __webpack_require__(2)
  423. , resolve = __webpack_require__(3)
  424. , Cache = __webpack_require__(21)
  425. , SchemaObject = __webpack_require__(16)
  426. , stableStringify = __webpack_require__(12)
  427. , formats = __webpack_require__(22)
  428. , rules = __webpack_require__(23)
  429. , v5 = __webpack_require__(43)
  430. , util = __webpack_require__(11)
  431. , async = __webpack_require__(17)
  432. , co = __webpack_require__(19);
  433. module.exports = Ajv;
  434. Ajv.prototype.compileAsync = async.compile;
  435. Ajv.prototype.addKeyword = __webpack_require__(49);
  436. Ajv.ValidationError = __webpack_require__(20);
  437. var META_SCHEMA_ID = 'http://json-schema.org/draft-04/schema';
  438. var SCHEMA_URI_FORMAT = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i;
  439. function SCHEMA_URI_FORMAT_FUNC(str) {
  440. return SCHEMA_URI_FORMAT.test(str);
  441. }
  442. var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ];
  443. /**
  444. * Creates validator instance.
  445. * Usage: `Ajv(opts)`
  446. * @param {Object} opts optional options
  447. * @return {Object} ajv instance
  448. */
  449. function Ajv(opts) {
  450. if (!(this instanceof Ajv)) return new Ajv(opts);
  451. var self = this;
  452. opts = this._opts = util.copy(opts) || {};
  453. this._schemas = {};
  454. this._refs = {};
  455. this._formats = formats(opts.format);
  456. this._cache = opts.cache || new Cache;
  457. this._loadingSchemas = {};
  458. this.RULES = rules();
  459. // this is done on purpose, so that methods are bound to the instance
  460. // (without using bind) so that they can be used without the instance
  461. this.validate = validate;
  462. this.compile = compile;
  463. this.addSchema = addSchema;
  464. this.addMetaSchema = addMetaSchema;
  465. this.validateSchema = validateSchema;
  466. this.getSchema = getSchema;
  467. this.removeSchema = removeSchema;
  468. this.addFormat = addFormat;
  469. this.errorsText = errorsText;
  470. this._addSchema = _addSchema;
  471. this._compile = _compile;
  472. opts.loopRequired = opts.loopRequired || Infinity;
  473. if (opts.async || opts.transpile) async.setup(opts);
  474. if (opts.beautify === true) opts.beautify = { indent_size: 2 };
  475. if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
  476. this._metaOpts = getMetaSchemaOptions();
  477. addInitialSchemas();
  478. if (opts.formats) addInitialFormats();
  479. if (opts.v5) v5.enable(this);
  480. if (typeof opts.meta == 'object') addMetaSchema(opts.meta);
  481. /**
  482. * Validate data using schema
  483. * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize.
  484. * @param {String|Object} schemaKeyRef key, ref or schema object
  485. * @param {Any} data to be validated
  486. * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
  487. */
  488. function validate(schemaKeyRef, data) {
  489. var v;
  490. if (typeof schemaKeyRef == 'string') {
  491. v = getSchema(schemaKeyRef);
  492. if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
  493. } else {
  494. var schemaObj = _addSchema(schemaKeyRef);
  495. v = schemaObj.validate || _compile(schemaObj);
  496. }
  497. var valid = v(data);
  498. if (v.async) return self._opts.async == '*' ? co(valid) : valid;
  499. self.errors = v.errors;
  500. return valid;
  501. }
  502. /**
  503. * Create validating function for passed schema.
  504. * @param {Object} schema schema object
  505. * @return {Function} validating function
  506. */
  507. function compile(schema) {
  508. var schemaObj = _addSchema(schema);
  509. return schemaObj.validate || _compile(schemaObj);
  510. }
  511. /**
  512. * Adds schema to the instance.
  513. * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
  514. * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
  515. * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
  516. * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
  517. */
  518. function addSchema(schema, key, _skipValidation, _meta) {
  519. if (Array.isArray(schema)){
  520. for (var i=0; i<schema.length; i++) addSchema(schema[i], undefined, _skipValidation, _meta);
  521. return;
  522. }
  523. // can key/id have # inside?
  524. key = resolve.normalizeId(key || schema.id);
  525. checkUnique(key);
  526. var schemaObj = self._schemas[key] = _addSchema(schema, _skipValidation, true);
  527. schemaObj.meta = _meta;
  528. }
  529. /**
  530. * Add schema that will be used to validate other schemas
  531. * options in META_IGNORE_OPTIONS are alway set to false
  532. * @param {Object} schema schema object
  533. * @param {String} key optional schema key
  534. * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
  535. */
  536. function addMetaSchema(schema, key, skipValidation) {
  537. addSchema(schema, key, skipValidation, true);
  538. }
  539. /**
  540. * Validate schema
  541. * @param {Object} schema schema to validate
  542. * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
  543. * @return {Boolean} true if schema is valid
  544. */
  545. function validateSchema(schema, throwOrLogError) {
  546. var $schema = schema.$schema || self._opts.defaultMeta || defaultMeta();
  547. var currentUriFormat = self._formats.uri;
  548. self._formats.uri = typeof currentUriFormat == 'function'
  549. ? SCHEMA_URI_FORMAT_FUNC
  550. : SCHEMA_URI_FORMAT;
  551. var valid = validate($schema, schema);
  552. self._formats.uri = currentUriFormat;
  553. if (!valid && throwOrLogError) {
  554. var message = 'schema is invalid:' + errorsText();
  555. if (self._opts.validateSchema == 'log') console.error(message);
  556. else throw new Error(message);
  557. }
  558. return valid;
  559. }
  560. function defaultMeta() {
  561. var meta = self._opts.meta;
  562. self._opts.defaultMeta = typeof meta == 'object'
  563. ? meta.id || meta
  564. : self._opts.v5
  565. ? v5.META_SCHEMA_ID
  566. : META_SCHEMA_ID;
  567. return self._opts.defaultMeta;
  568. }
  569. /**
  570. * Get compiled schema from the instance by `key` or `ref`.
  571. * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
  572. * @return {Function} schema validating function (with property `schema`).
  573. */
  574. function getSchema(keyRef) {
  575. var schemaObj = _getSchemaObj(keyRef);
  576. switch (typeof schemaObj) {
  577. case 'object': return schemaObj.validate || _compile(schemaObj);
  578. case 'string': return getSchema(schemaObj);
  579. }
  580. }
  581. function _getSchemaObj(keyRef) {
  582. keyRef = resolve.normalizeId(keyRef);
  583. return self._schemas[keyRef] || self._refs[keyRef];
  584. }
  585. /**
  586. * Remove cached schema(s).
  587. * If no parameter is passed all schemas but meta-schemas are removed.
  588. * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
  589. * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
  590. * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
  591. */
  592. function removeSchema(schemaKeyRef) {
  593. switch (typeof schemaKeyRef) {
  594. case 'undefined':
  595. _removeAllSchemas(self._schemas);
  596. _removeAllSchemas(self._refs);
  597. self._cache.clear();
  598. return;
  599. case 'string':
  600. var schemaObj = _getSchemaObj(schemaKeyRef);
  601. if (schemaObj) self._cache.del(schemaObj.jsonStr);
  602. delete self._schemas[schemaKeyRef];
  603. delete self._refs[schemaKeyRef];
  604. return;
  605. case 'object':
  606. if (schemaKeyRef instanceof RegExp) {
  607. _removeAllSchemas(self._schemas, schemaKeyRef);
  608. _removeAllSchemas(self._refs, schemaKeyRef);
  609. return;
  610. }
  611. var jsonStr = stableStringify(schemaKeyRef);
  612. self._cache.del(jsonStr);
  613. var id = schemaKeyRef.id;
  614. if (id) {
  615. id = resolve.normalizeId(id);
  616. delete self._schemas[id];
  617. delete self._refs[id];
  618. }
  619. }
  620. }
  621. function _removeAllSchemas(schemas, regex) {
  622. for (var keyRef in schemas) {
  623. var schemaObj = schemas[keyRef];
  624. if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
  625. self._cache.del(schemaObj.jsonStr);
  626. delete schemas[keyRef];
  627. }
  628. }
  629. }
  630. function _addSchema(schema, skipValidation, shouldAddSchema) {
  631. if (typeof schema != 'object') throw new Error('schema should be object');
  632. var jsonStr = stableStringify(schema);
  633. var cached = self._cache.get(jsonStr);
  634. if (cached) return cached;
  635. shouldAddSchema = shouldAddSchema || self._opts.addUsedSchema !== false;
  636. var id = resolve.normalizeId(schema.id);
  637. if (id && shouldAddSchema) checkUnique(id);
  638. if (self._opts.validateSchema !== false && !skipValidation)
  639. validateSchema(schema, true);
  640. var localRefs = resolve.ids.call(self, schema);
  641. var schemaObj = new SchemaObject({
  642. id: id,
  643. schema: schema,
  644. localRefs: localRefs,
  645. jsonStr: jsonStr
  646. });
  647. if (id[0] != '#' && shouldAddSchema) self._refs[id] = schemaObj;
  648. self._cache.put(jsonStr, schemaObj);
  649. return schemaObj;
  650. }
  651. function _compile(schemaObj, root) {
  652. if (schemaObj.compiling) {
  653. schemaObj.validate = callValidate;
  654. callValidate.schema = schemaObj.schema;
  655. callValidate.errors = null;
  656. callValidate.root = root ? root : callValidate;
  657. if (schemaObj.schema.$async === true)
  658. callValidate.async = true;
  659. return callValidate;
  660. }
  661. schemaObj.compiling = true;
  662. var currentOpts;
  663. if (schemaObj.meta) {
  664. currentOpts = self._opts;
  665. self._opts = self._metaOpts;
  666. }
  667. var v;
  668. try { v = compileSchema.call(self, schemaObj.schema, root, schemaObj.localRefs); }
  669. finally {
  670. schemaObj.compiling = false;
  671. if (schemaObj.meta) self._opts = currentOpts;
  672. }
  673. schemaObj.validate = v;
  674. schemaObj.refs = v.refs;
  675. schemaObj.refVal = v.refVal;
  676. schemaObj.root = v.root;
  677. return v;
  678. function callValidate() {
  679. var _validate = schemaObj.validate;
  680. var result = _validate.apply(null, arguments);
  681. callValidate.errors = _validate.errors;
  682. return result;
  683. }
  684. }
  685. /**
  686. * Convert array of error message objects to string
  687. * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
  688. * @param {Object} options optional options with properties `separator` and `dataVar`.
  689. * @return {String} human readable string with all errors descriptions
  690. */
  691. function errorsText(errors, options) {
  692. errors = errors || self.errors;
  693. if (!errors) return 'No errors';
  694. options = options || {};
  695. var separator = options.separator === undefined ? ', ' : options.separator;
  696. var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
  697. var text = '';
  698. for (var i=0; i<errors.length; i++) {
  699. var e = errors[i];
  700. if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
  701. }
  702. return text.slice(0, -separator.length);
  703. }
  704. /**
  705. * Add custom format
  706. * @param {String} name format name
  707. * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
  708. */
  709. function addFormat(name, format) {
  710. if (typeof format == 'string') format = new RegExp(format);
  711. self._formats[name] = format;
  712. }
  713. function addInitialSchemas() {
  714. if (self._opts.meta !== false) {
  715. var metaSchema = __webpack_require__(50);
  716. addMetaSchema(metaSchema, META_SCHEMA_ID, true);
  717. self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
  718. }
  719. var optsSchemas = self._opts.schemas;
  720. if (!optsSchemas) return;
  721. if (Array.isArray(optsSchemas)) addSchema(optsSchemas);
  722. else for (var key in optsSchemas) addSchema(optsSchemas[key], key);
  723. }
  724. function addInitialFormats() {
  725. for (var name in self._opts.formats) {
  726. var format = self._opts.formats[name];
  727. addFormat(name, format);
  728. }
  729. }
  730. function checkUnique(id) {
  731. if (self._schemas[id] || self._refs[id])
  732. throw new Error('schema with key or id "' + id + '" already exists');
  733. }
  734. function getMetaSchemaOptions() {
  735. var metaOpts = util.copy(self._opts);
  736. for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
  737. delete metaOpts[META_IGNORE_OPTIONS[i]];
  738. return metaOpts;
  739. }
  740. }
  741. /***/ },
  742. /* 2 */
  743. /***/ function(module, exports, __webpack_require__) {
  744. 'use strict';
  745. var resolve = __webpack_require__(3)
  746. , util = __webpack_require__(11)
  747. , stableStringify = __webpack_require__(12)
  748. , async = __webpack_require__(17);
  749. var beautify = (function() { try { return __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"js-beautify\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())).js_beautify; } catch(e) {/*empty*/} })();
  750. var validateGenerator = __webpack_require__(18);
  751. module.exports = compile;
  752. /**
  753. * Compiles schema to validation function
  754. * @this Ajv
  755. * @param {Object} schema schema object
  756. * @param {Object} root object with information about the root schema for this schema
  757. * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
  758. * @param {String} baseId base ID for IDs in the schema
  759. * @return {Function} validation function
  760. */
  761. function compile(schema, root, localRefs, baseId) {
  762. /* jshint validthis: true, evil: true */
  763. /* eslint no-shadow: 0 */
  764. var self = this
  765. , opts = this._opts
  766. , refVal = [ undefined ]
  767. , refs = {}
  768. , patterns = []
  769. , patternsHash = {}
  770. , defaults = []
  771. , defaultsHash = {}
  772. , customRules = [];
  773. root = root || { schema: schema, refVal: refVal, refs: refs };
  774. var formats = this._formats;
  775. var RULES = this.RULES;
  776. return localCompile(schema, root, localRefs, baseId);
  777. function localCompile(_schema, _root, localRefs, baseId) {
  778. var isRoot = !_root || (_root && _root.schema == _schema);
  779. if (_root.schema != root.schema)
  780. return compile.call(self, _schema, _root, localRefs, baseId);
  781. var $async = _schema.$async === true;
  782. if ($async && !opts.transpile) async.setup(opts);
  783. var sourceCode = validateGenerator({
  784. isTop: true,
  785. schema: _schema,
  786. isRoot: isRoot,
  787. baseId: baseId,
  788. root: _root,
  789. schemaPath: '',
  790. errSchemaPath: '#',
  791. errorPath: '""',
  792. RULES: RULES,
  793. validate: validateGenerator,
  794. util: util,
  795. resolve: resolve,
  796. resolveRef: resolveRef,
  797. usePattern: usePattern,
  798. useDefault: useDefault,
  799. useCustomRule: useCustomRule,
  800. opts: opts,
  801. formats: formats,
  802. self: self
  803. });
  804. sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
  805. + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
  806. + sourceCode;
  807. if (opts.beautify) {
  808. /* istanbul ignore else */
  809. if (beautify) sourceCode = beautify(sourceCode, opts.beautify);
  810. else console.error('"npm install js-beautify" to use beautify option');
  811. }
  812. // console.log('\n\n\n *** \n', sourceCode);
  813. var validate, validateCode
  814. , transpile = opts._transpileFunc;
  815. try {
  816. validateCode = $async && transpile
  817. ? transpile(sourceCode)
  818. : sourceCode;
  819. eval(validateCode);
  820. refVal[0] = validate;
  821. } catch(e) {
  822. console.error('Error compiling schema, function code:', validateCode);
  823. throw e;
  824. }
  825. validate.schema = _schema;
  826. validate.errors = null;
  827. validate.refs = refs;
  828. validate.refVal = refVal;
  829. validate.root = isRoot ? validate : _root;
  830. if ($async) validate.async = true;
  831. validate.sourceCode = sourceCode;
  832. return validate;
  833. }
  834. function resolveRef(baseId, ref, isRoot) {
  835. ref = resolve.url(baseId, ref);
  836. var refIndex = refs[ref];
  837. var _refVal, refCode;
  838. if (refIndex !== undefined) {
  839. _refVal = refVal[refIndex];
  840. refCode = 'refVal[' + refIndex + ']';
  841. return resolvedRef(_refVal, refCode);
  842. }
  843. if (!isRoot) {
  844. var rootRefId = root.refs[ref];
  845. if (rootRefId !== undefined) {
  846. _refVal = root.refVal[rootRefId];
  847. refCode = addLocalRef(ref, _refVal);
  848. return resolvedRef(_refVal, refCode);
  849. }
  850. }
  851. refCode = addLocalRef(ref);
  852. var v = resolve.call(self, localCompile, root, ref);
  853. if (!v) {
  854. var localSchema = localRefs && localRefs[ref];
  855. if (localSchema) {
  856. v = resolve.inlineRef(localSchema, opts.inlineRefs)
  857. ? localSchema
  858. : compile.call(self, localSchema, root, localRefs, baseId);
  859. }
  860. }
  861. if (v) {
  862. replaceLocalRef(ref, v);
  863. return resolvedRef(v, refCode);
  864. }
  865. }
  866. function addLocalRef(ref, v) {
  867. var refId = refVal.length;
  868. refVal[refId] = v;
  869. refs[ref] = refId;
  870. return 'refVal' + refId;
  871. }
  872. function replaceLocalRef(ref, v) {
  873. var refId = refs[ref];
  874. refVal[refId] = v;
  875. }
  876. function resolvedRef(refVal, code) {
  877. return typeof refVal == 'object'
  878. ? { code: code, schema: refVal, inline: true }
  879. : { code: code, async: refVal && refVal.async };
  880. }
  881. function usePattern(regexStr) {
  882. var index = patternsHash[regexStr];
  883. if (index === undefined) {
  884. index = patternsHash[regexStr] = patterns.length;
  885. patterns[index] = regexStr;
  886. }
  887. return 'pattern' + index;
  888. }
  889. function useDefault(value) {
  890. switch (typeof value) {
  891. case 'boolean':
  892. case 'number':
  893. return '' + value;
  894. case 'string':
  895. return util.toQuotedString(value);
  896. case 'object':
  897. if (value === null) return 'null';
  898. var valueStr = stableStringify(value);
  899. var index = defaultsHash[valueStr];
  900. if (index === undefined) {
  901. index = defaultsHash[valueStr] = defaults.length;
  902. defaults[index] = value;
  903. }
  904. return 'default' + index;
  905. }
  906. }
  907. function useCustomRule(rule, schema, parentSchema, it) {
  908. var compile = rule.definition.compile
  909. , inline = rule.definition.inline
  910. , macro = rule.definition.macro;
  911. var validate;
  912. if (compile) {
  913. validate = compile.call(self, schema, parentSchema);
  914. } else if (macro) {
  915. validate = macro.call(self, schema, parentSchema);
  916. if (opts.validateSchema !== false) self.validateSchema(validate, true);
  917. } else if (inline) {
  918. validate = inline.call(self, it, rule.keyword, schema, parentSchema);
  919. } else {
  920. validate = rule.definition.validate;
  921. }
  922. var index = customRules.length;
  923. customRules[index] = validate;
  924. return {
  925. code: 'customRule' + index,
  926. validate: validate
  927. };
  928. }
  929. }
  930. function patternCode(i, patterns) {
  931. return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
  932. }
  933. function defaultCode(i) {
  934. return 'var default' + i + ' = defaults[' + i + '];';
  935. }
  936. function refValCode(i, refVal) {
  937. return refVal[i] ? 'var refVal' + i + ' = refVal[' + i + '];' : '';
  938. }
  939. function customRuleCode(i) {
  940. return 'var customRule' + i + ' = customRules[' + i + '];';
  941. }
  942. function vars(arr, statement) {
  943. if (!arr.length) return '';
  944. var code = '';
  945. for (var i=0; i<arr.length; i++)
  946. code += statement(i, arr);
  947. return code;
  948. }
  949. /*eslint-disable no-unused-vars */
  950. /**
  951. * Functions below are used inside compiled validations function
  952. */
  953. var co = __webpack_require__(19);
  954. var ucs2length = util.ucs2length;
  955. var equal = __webpack_require__(10);
  956. // this error is thrown by async schemas to return validation errors via exception
  957. var ValidationError = __webpack_require__(20);
  958. /*eslint-enable no-unused-vars */
  959. /***/ },
  960. /* 3 */
  961. /***/ function(module, exports, __webpack_require__) {
  962. 'use strict';
  963. var url = __webpack_require__(4)
  964. , equal = __webpack_require__(10)
  965. , util = __webpack_require__(11)
  966. , SchemaObject = __webpack_require__(16);
  967. module.exports = resolve;
  968. resolve.normalizeId = normalizeId;
  969. resolve.fullPath = getFullPath;
  970. resolve.url = resolveUrl;
  971. resolve.ids = resolveIds;
  972. resolve.inlineRef = inlineRef;
  973. /**
  974. * [resolve and compile the references ($ref)]
  975. * @this Ajv
  976. * @param {Function} compile reference to schema compilation funciton (localCompile)
  977. * @param {Object} root object with information about the root schema for the current schema
  978. * @param {String} ref reference to resolve
  979. * @return {Object|Function} schema object (if the schema can be inlined) or validation function
  980. */
  981. function resolve(compile, root, ref) {
  982. /* jshint validthis: true */
  983. var refVal = this._refs[ref];
  984. if (typeof refVal == 'string') {
  985. if (this._refs[refVal]) refVal = this._refs[refVal];
  986. else return resolve.call(this, compile, root, refVal);
  987. }
  988. refVal = refVal || this._schemas[ref];
  989. if (refVal instanceof SchemaObject) {
  990. return inlineRef(refVal.schema, this._opts.inlineRefs)
  991. ? refVal.schema
  992. : refVal.validate || this._compile(refVal);
  993. }
  994. var res = _resolve.call(this, root, ref);
  995. var schema, v, baseId;
  996. if (res) {
  997. schema = res.schema;
  998. root = res.root;
  999. baseId = res.baseId;
  1000. }
  1001. if (schema instanceof SchemaObject) {
  1002. v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
  1003. } else if (schema) {
  1004. v = inlineRef(schema, this._opts.inlineRefs)
  1005. ? schema
  1006. : compile.call(this, schema, root, undefined, baseId);
  1007. }
  1008. return v;
  1009. }
  1010. /* @this Ajv */
  1011. function _resolve(root, ref) {
  1012. /* jshint validthis: true */
  1013. var p = url.parse(ref, false, true)
  1014. , refPath = _getFullPath(p)
  1015. , baseId = getFullPath(root.schema.id);
  1016. if (refPath !== baseId) {
  1017. var id = normalizeId(refPath);
  1018. var refVal = this._refs[id];
  1019. if (typeof refVal == 'string') {
  1020. return resolveRecursive.call(this, root, refVal, p);
  1021. } else if (refVal instanceof SchemaObject) {
  1022. if (!refVal.validate) this._compile(refVal);
  1023. root = refVal;
  1024. } else {
  1025. refVal = this._schemas[id];
  1026. if (refVal instanceof SchemaObject) {
  1027. if (!refVal.validate) this._compile(refVal);
  1028. if (id == normalizeId(ref))
  1029. return { schema: refVal, root: root, baseId: baseId };
  1030. root = refVal;
  1031. }
  1032. }
  1033. if (!root.schema) return;
  1034. baseId = getFullPath(root.schema.id);
  1035. }
  1036. return getJsonPointer.call(this, p, baseId, root.schema, root);
  1037. }
  1038. /* @this Ajv */
  1039. function resolveRecursive(root, ref, parsedRef) {
  1040. /* jshint validthis: true */
  1041. var res = _resolve.call(this, root, ref);
  1042. if (res) {
  1043. var schema = res.schema;
  1044. var baseId = res.baseId;
  1045. root = res.root;
  1046. if (schema.id) baseId = resolveUrl(baseId, schema.id);
  1047. return getJsonPointer.call(this, parsedRef, baseId, schema, root);
  1048. }
  1049. }
  1050. var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
  1051. /* @this Ajv */
  1052. function getJsonPointer(parsedRef, baseId, schema, root) {
  1053. /* jshint validthis: true */
  1054. parsedRef.hash = parsedRef.hash || '';
  1055. if (parsedRef.hash.slice(0,2) != '#/') return;
  1056. var parts = parsedRef.hash.split('/');
  1057. for (var i = 1; i < parts.length; i++) {
  1058. var part = parts[i];
  1059. if (part) {
  1060. part = util.unescapeFragment(part);
  1061. schema = schema[part];
  1062. if (!schema) break;
  1063. if (schema.id && !PREVENT_SCOPE_CHANGE[part]) baseId = resolveUrl(baseId, schema.id);
  1064. if (schema.$ref) {
  1065. var $ref = resolveUrl(baseId, schema.$ref);
  1066. var res = _resolve.call(this, root, $ref);
  1067. if (res) {
  1068. schema = res.schema;
  1069. root = res.root;
  1070. baseId = res.baseId;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. if (schema && schema != root.schema)
  1076. return { schema: schema, root: root, baseId: baseId };
  1077. }
  1078. var SIMPLE_INLINED = util.toHash([
  1079. 'type', 'format', 'pattern',
  1080. 'maxLength', 'minLength',
  1081. 'maxProperties', 'minProperties',
  1082. 'maxItems', 'minItems',
  1083. 'maximum', 'minimum',
  1084. 'uniqueItems', 'multipleOf',
  1085. 'required', 'enum'
  1086. ]);
  1087. function inlineRef(schema, limit) {
  1088. if (limit === false) return false;
  1089. if (limit === undefined || limit === true) return checkNoRef(schema);
  1090. else if (limit) return countKeys(schema) <= limit;
  1091. }
  1092. function checkNoRef(schema) {
  1093. var item;
  1094. if (Array.isArray(schema)) {
  1095. for (var i=0; i<schema.length; i++) {
  1096. item = schema[i];
  1097. if (typeof item == 'object' && !checkNoRef(item)) return false;
  1098. }
  1099. } else {
  1100. for (var key in schema) {
  1101. if (key == '$ref') return false;
  1102. item = schema[key];
  1103. if (typeof item == 'object' && !checkNoRef(item)) return false;
  1104. }
  1105. }
  1106. return true;
  1107. }
  1108. function countKeys(schema) {
  1109. var count = 0, item;
  1110. if (Array.isArray(schema)) {
  1111. for (var i=0; i<schema.length; i++) {
  1112. item = schema[i];
  1113. if (typeof item == 'object') count += countKeys(item);
  1114. if (count == Infinity) return Infinity;
  1115. }
  1116. } else {
  1117. for (var key in schema) {
  1118. if (key == '$ref') return Infinity;
  1119. if (SIMPLE_INLINED[key]) {
  1120. count++;
  1121. } else {
  1122. item = schema[key];
  1123. if (typeof item == 'object') count += countKeys(item) + 1;
  1124. if (count == Infinity) return Infinity;
  1125. }
  1126. }
  1127. }
  1128. return count;
  1129. }
  1130. function getFullPath(id, normalize) {
  1131. if (normalize !== false) id = normalizeId(id);
  1132. var p = url.parse(id, false, true);
  1133. return _getFullPath(p);
  1134. }
  1135. function _getFullPath(p) {
  1136. return (p.protocol||'') + (p.protocol?'//':'') + (p.host||'') + (p.path||'') + '#';
  1137. }
  1138. var TRAILING_SLASH_HASH = /#\/?$/;
  1139. function normalizeId(id) {
  1140. return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
  1141. }
  1142. function resolveUrl(baseId, id) {
  1143. id = normalizeId(id);
  1144. return url.resolve(baseId, id);
  1145. }
  1146. /* @this Ajv */
  1147. function resolveIds(schema) {
  1148. /* eslint no-shadow: 0 */
  1149. /* jshint validthis: true */
  1150. var id = normalizeId(schema.id);
  1151. var localRefs = {};
  1152. _resolveIds.call(this, schema, getFullPath(id, false), id);
  1153. return localRefs;
  1154. function _resolveIds(schema, fullPath, baseId) {
  1155. /* jshint validthis: true */
  1156. if (Array.isArray(schema)) {
  1157. for (var i=0; i<schema.length; i++)
  1158. _resolveIds.call(this, schema[i], fullPath+'/'+i, baseId);
  1159. } else if (schema && typeof schema == 'object') {
  1160. if (typeof schema.id == 'string') {
  1161. var id = baseId = baseId
  1162. ? url.resolve(baseId, schema.id)
  1163. : schema.id;
  1164. id = normalizeId(id);
  1165. var refVal = this._refs[id];
  1166. if (typeof refVal == 'string') refVal = this._refs[refVal];
  1167. if (refVal && refVal.schema) {
  1168. if (!equal(schema, refVal.schema))
  1169. throw new Error('id "' + id + '" resolves to more than one schema');
  1170. } else if (id != normalizeId(fullPath)) {
  1171. if (id[0] == '#') {
  1172. if (localRefs[id] && !equal(schema, localRefs[id]))
  1173. throw new Error('id "' + id + '" resolves to more than one schema');
  1174. localRefs[id] = schema;
  1175. } else {
  1176. this._refs[id] = fullPath;
  1177. }
  1178. }
  1179. }
  1180. for (var key in schema)
  1181. _resolveIds.call(this, schema[key], fullPath+'/'+util.escapeFragment(key), baseId);
  1182. }
  1183. }
  1184. }
  1185. /***/ },
  1186. /* 4 */
  1187. /***/ function(module, exports, __webpack_require__) {
  1188. // Copyright Joyent, Inc. and other Node contributors.
  1189. //
  1190. // Permission is hereby granted, free of charge, to any person obtaining a
  1191. // copy of this software and associated documentation files (the
  1192. // "Software"), to deal in the Software without restriction, including
  1193. // without limitation the rights to use, copy, modify, merge, publish,
  1194. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1195. // persons to whom the Software is furnished to do so, subject to the
  1196. // following conditions:
  1197. //
  1198. // The above copyright notice and this permission notice shall be included
  1199. // in all copies or substantial portions of the Software.
  1200. //
  1201. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1202. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1203. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1204. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1205. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1206. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1207. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1208. var punycode = __webpack_require__(5);
  1209. exports.parse = urlParse;
  1210. exports.resolve = urlResolve;
  1211. exports.resolveObject = urlResolveObject;
  1212. exports.format = urlFormat;
  1213. exports.Url = Url;
  1214. function Url() {
  1215. this.protocol = null;
  1216. this.slashes = null;
  1217. this.auth = null;
  1218. this.host = null;
  1219. this.port = null;
  1220. this.hostname = null;
  1221. this.hash = null;
  1222. this.search = null;
  1223. this.query = null;
  1224. this.pathname = null;
  1225. this.path = null;
  1226. this.href = null;
  1227. }
  1228. // Reference: RFC 3986, RFC 1808, RFC 2396
  1229. // define these here so at least they only have to be
  1230. // compiled once on the first module load.
  1231. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  1232. portPattern = /:[0-9]*$/,
  1233. // RFC 2396: characters reserved for delimiting URLs.
  1234. // We actually just auto-escape these.
  1235. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  1236. // RFC 2396: characters not allowed for various reasons.
  1237. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  1238. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  1239. autoEscape = ['\''].concat(unwise),
  1240. // Characters that are never ever allowed in a hostname.
  1241. // Note that any invalid chars are also handled, but these
  1242. // are the ones that are *expected* to be seen, so we fast-path
  1243. // them.
  1244. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  1245. hostEndingChars = ['/', '?', '#'],
  1246. hostnameMaxLen = 255,
  1247. hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/,
  1248. hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/,
  1249. // protocols that can allow "unsafe" and "unwise" chars.
  1250. unsafeProtocol = {
  1251. 'javascript': true,
  1252. 'javascript:': true
  1253. },
  1254. // protocols that never have a hostname.
  1255. hostlessProtocol = {
  1256. 'javascript': true,
  1257. 'javascript:': true
  1258. },
  1259. // protocols that always contain a // bit.
  1260. slashedProtocol = {
  1261. 'http': true,
  1262. 'https': true,
  1263. 'ftp': true,
  1264. 'gopher': true,
  1265. 'file': true,
  1266. 'http:': true,
  1267. 'https:': true,
  1268. 'ftp:': true,
  1269. 'gopher:': true,
  1270. 'file:': true
  1271. },
  1272. querystring = __webpack_require__(7);
  1273. function urlParse(url, parseQueryString, slashesDenoteHost) {
  1274. if (url && isObject(url) && url instanceof Url) return url;
  1275. var u = new Url;
  1276. u.parse(url, parseQueryString, slashesDenoteHost);
  1277. return u;
  1278. }
  1279. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  1280. if (!isString(url)) {
  1281. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  1282. }
  1283. var rest = url;
  1284. // trim before proceeding.
  1285. // This is to support parse stuff like " http://foo.com \n"
  1286. rest = rest.trim();
  1287. var proto = protocolPattern.exec(rest);
  1288. if (proto) {
  1289. proto = proto[0];
  1290. var lowerProto = proto.toLowerCase();
  1291. this.protocol = lowerProto;
  1292. rest = rest.substr(proto.length);
  1293. }
  1294. // figure out if it's got a host
  1295. // user@server is *always* interpreted as a hostname, and url
  1296. // resolution will treat //foo/bar as host=foo,path=bar because that's
  1297. // how the browser resolves relative URLs.
  1298. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  1299. var slashes = rest.substr(0, 2) === '//';
  1300. if (slashes && !(proto && hostlessProtocol[proto])) {
  1301. rest = rest.substr(2);
  1302. this.slashes = true;
  1303. }
  1304. }
  1305. if (!hostlessProtocol[proto] &&
  1306. (slashes || (proto && !slashedProtocol[proto]))) {
  1307. // there's a hostname.
  1308. // the first instance of /, ?, ;, or # ends the host.
  1309. //
  1310. // If there is an @ in the hostname, then non-host chars *are* allowed
  1311. // to the left of the last @ sign, unless some host-ending character
  1312. // comes *before* the @-sign.
  1313. // URLs are obnoxious.
  1314. //
  1315. // ex:
  1316. // http://a@b@c/ => user:a@b host:c
  1317. // http://a@b?@c => user:a host:c path:/?@c
  1318. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  1319. // Review our test case against browsers more comprehensively.
  1320. // find the first instance of any hostEndingChars
  1321. var hostEnd = -1;
  1322. for (var i = 0; i < hostEndingChars.length; i++) {
  1323. var hec = rest.indexOf(hostEndingChars[i]);
  1324. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  1325. hostEnd = hec;
  1326. }
  1327. // at this point, either we have an explicit point where the
  1328. // auth portion cannot go past, or the last @ char is the decider.
  1329. var auth, atSign;
  1330. if (hostEnd === -1) {
  1331. // atSign can be anywhere.
  1332. atSign = rest.lastIndexOf('@');
  1333. } else {
  1334. // atSign must be in auth portion.
  1335. // http://a@b/c@d => host:b auth:a path:/c@d
  1336. atSign = rest.lastIndexOf('@', hostEnd);
  1337. }
  1338. // Now we have a portion which is definitely the auth.
  1339. // Pull that off.
  1340. if (atSign !== -1) {
  1341. auth = rest.slice(0, atSign);
  1342. rest = rest.slice(atSign + 1);
  1343. this.auth = decodeURIComponent(auth);
  1344. }
  1345. // the host is the remaining to the left of the first non-host char
  1346. hostEnd = -1;
  1347. for (var i = 0; i < nonHostChars.length; i++) {
  1348. var hec = rest.indexOf(nonHostChars[i]);
  1349. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  1350. hostEnd = hec;
  1351. }
  1352. // if we still have not hit it, then the entire thing is a host.
  1353. if (hostEnd === -1)
  1354. hostEnd = rest.length;
  1355. this.host = rest.slice(0, hostEnd);
  1356. rest = rest.slice(hostEnd);
  1357. // pull out port.
  1358. this.parseHost();
  1359. // we've indicated that there is a hostname,
  1360. // so even if it's empty, it has to be present.
  1361. this.hostname = this.hostname || '';
  1362. // if hostname begins with [ and ends with ]
  1363. // assume that it's an IPv6 address.
  1364. var ipv6Hostname = this.hostname[0] === '[' &&
  1365. this.hostname[this.hostname.length - 1] === ']';
  1366. // validate a little.
  1367. if (!ipv6Hostname) {
  1368. var hostparts = this.hostname.split(/\./);
  1369. for (var i = 0, l = hostparts.length; i < l; i++) {
  1370. var part = hostparts[i];
  1371. if (!part) continue;
  1372. if (!part.match(hostnamePartPattern)) {
  1373. var newpart = '';
  1374. for (var j = 0, k = part.length; j < k; j++) {
  1375. if (part.charCodeAt(j) > 127) {
  1376. // we replace non-ASCII char with a temporary placeholder
  1377. // we need this to make sure size of hostname is not
  1378. // broken by replacing non-ASCII by nothing
  1379. newpart += 'x';
  1380. } else {
  1381. newpart += part[j];
  1382. }
  1383. }
  1384. // we test again with ASCII char only
  1385. if (!newpart.match(hostnamePartPattern)) {
  1386. var validParts = hostparts.slice(0, i);
  1387. var notHost = hostparts.slice(i + 1);
  1388. var bit = part.match(hostnamePartStart);
  1389. if (bit) {
  1390. validParts.push(bit[1]);
  1391. notHost.unshift(bit[2]);
  1392. }
  1393. if (notHost.length) {
  1394. rest = '/' + notHost.join('.') + rest;
  1395. }
  1396. this.hostname = validParts.join('.');
  1397. break;
  1398. }
  1399. }
  1400. }
  1401. }
  1402. if (this.hostname.length > hostnameMaxLen) {
  1403. this.hostname = '';
  1404. } else {
  1405. // hostnames are always lower case.
  1406. this.hostname = this.hostname.toLowerCase();
  1407. }
  1408. if (!ipv6Hostname) {
  1409. // IDNA Support: Returns a puny coded representation of "domain".
  1410. // It only converts the part of the domain name that
  1411. // has non ASCII characters. I.e. it dosent matter if
  1412. // you call it with a domain that already is in ASCII.
  1413. var domainArray = this.hostname.split('.');
  1414. var newOut = [];
  1415. for (var i = 0; i < domainArray.length; ++i) {
  1416. var s = domainArray[i];
  1417. newOut.push(s.match(/[^A-Za-z0-9_-]/) ?
  1418. 'xn--' + punycode.encode(s) : s);
  1419. }
  1420. this.hostname = newOut.join('.');
  1421. }
  1422. var p = this.port ? ':' + this.port : '';
  1423. var h = this.hostname || '';
  1424. this.host = h + p;
  1425. this.href += this.host;
  1426. // strip [ and ] from the hostname
  1427. // the host field still retains them, though
  1428. if (ipv6Hostname) {
  1429. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  1430. if (rest[0] !== '/') {
  1431. rest = '/' + rest;
  1432. }
  1433. }
  1434. }
  1435. // now rest is set to the post-host stuff.
  1436. // chop off any delim chars.
  1437. if (!unsafeProtocol[lowerProto]) {
  1438. // First, make 100% sure that any "autoEscape" chars get
  1439. // escaped, even if encodeURIComponent doesn't think they
  1440. // need to be.
  1441. for (var i = 0, l = autoEscape.length; i < l; i++) {
  1442. var ae = autoEscape[i];
  1443. var esc = encodeURIComponent(ae);
  1444. if (esc === ae) {
  1445. esc = escape(ae);
  1446. }
  1447. rest = rest.split(ae).join(esc);
  1448. }
  1449. }
  1450. // chop off from the tail first.
  1451. var hash = rest.indexOf('#');
  1452. if (hash !== -1) {
  1453. // got a fragment string.
  1454. this.hash = rest.substr(hash);
  1455. rest = rest.slice(0, hash);
  1456. }
  1457. var qm = rest.indexOf('?');
  1458. if (qm !== -1) {
  1459. this.search = rest.substr(qm);
  1460. this.query = rest.substr(qm + 1);
  1461. if (parseQueryString) {
  1462. this.query = querystring.parse(this.query);
  1463. }
  1464. rest = rest.slice(0, qm);
  1465. } else if (parseQueryString) {
  1466. // no query string, but parseQueryString still requested
  1467. this.search = '';
  1468. this.query = {};
  1469. }
  1470. if (rest) this.pathname = rest;
  1471. if (slashedProtocol[lowerProto] &&
  1472. this.hostname && !this.pathname) {
  1473. this.pathname = '/';
  1474. }
  1475. //to support http.request
  1476. if (this.pathname || this.search) {
  1477. var p = this.pathname || '';
  1478. var s = this.search || '';
  1479. this.path = p + s;
  1480. }
  1481. // finally, reconstruct the href based on what has been validated.
  1482. this.href = this.format();
  1483. return this;
  1484. };
  1485. // format a parsed object into a url string
  1486. function urlFormat(obj) {
  1487. // ensure it's an object, and not a string url.
  1488. // If it's an obj, this is a no-op.
  1489. // this way, you can call url_format() on strings
  1490. // to clean up potentially wonky urls.
  1491. if (isString(obj)) obj = urlParse(obj);
  1492. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  1493. return obj.format();
  1494. }
  1495. Url.prototype.format = function() {
  1496. var auth = this.auth || '';
  1497. if (auth) {
  1498. auth = encodeURIComponent(auth);
  1499. auth = auth.replace(/%3A/i, ':');
  1500. auth += '@';
  1501. }
  1502. var protocol = this.protocol || '',
  1503. pathname = this.pathname || '',
  1504. hash = this.hash || '',
  1505. host = false,
  1506. query = '';
  1507. if (this.host) {
  1508. host = auth + this.host;
  1509. } else if (this.hostname) {
  1510. host = auth + (this.hostname.indexOf(':') === -1 ?
  1511. this.hostname :
  1512. '[' + this.hostname + ']');
  1513. if (this.port) {
  1514. host += ':' + this.port;
  1515. }
  1516. }
  1517. if (this.query &&
  1518. isObject(this.query) &&
  1519. Object.keys(this.query).length) {
  1520. query = querystring.stringify(this.query);
  1521. }
  1522. var search = this.search || (query && ('?' + query)) || '';
  1523. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  1524. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  1525. // unless they had them to begin with.
  1526. if (this.slashes ||
  1527. (!protocol || slashedProtocol[protocol]) && host !== false) {
  1528. host = '//' + (host || '');
  1529. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  1530. } else if (!host) {
  1531. host = '';
  1532. }
  1533. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  1534. if (search && search.charAt(0) !== '?') search = '?' + search;
  1535. pathname = pathname.replace(/[?#]/g, function(match) {
  1536. return encodeURIComponent(match);
  1537. });
  1538. search = search.replace('#', '%23');
  1539. return protocol + host + pathname + search + hash;
  1540. };
  1541. function urlResolve(source, relative) {
  1542. return urlParse(source, false, true).resolve(relative);
  1543. }
  1544. Url.prototype.resolve = function(relative) {
  1545. return this.resolveObject(urlParse(relative, false, true)).format();
  1546. };
  1547. function urlResolveObject(source, relative) {
  1548. if (!source) return relative;
  1549. return urlParse(source, false, true).resolveObject(relative);
  1550. }
  1551. Url.prototype.resolveObject = function(relative) {
  1552. if (isString(relative)) {
  1553. var rel = new Url();
  1554. rel.parse(relative, false, true);
  1555. relative = rel;
  1556. }
  1557. var result = new Url();
  1558. Object.keys(this).forEach(function(k) {
  1559. result[k] = this[k];
  1560. }, this);
  1561. // hash is always overridden, no matter what.
  1562. // even href="" will remove it.
  1563. result.hash = relative.hash;
  1564. // if the relative url is empty, then there's nothing left to do here.
  1565. if (relative.href === '') {
  1566. result.href = result.format();
  1567. return result;
  1568. }
  1569. // hrefs like //foo/bar always cut to the protocol.
  1570. if (relative.slashes && !relative.protocol) {
  1571. // take everything except the protocol from relative
  1572. Object.keys(relative).forEach(function(k) {
  1573. if (k !== 'protocol')
  1574. result[k] = relative[k];
  1575. });
  1576. //urlParse appends trailing / to urls like http://www.example.com
  1577. if (slashedProtocol[result.protocol] &&
  1578. result.hostname && !result.pathname) {
  1579. result.path = result.pathname = '/';
  1580. }
  1581. result.href = result.format();
  1582. return result;
  1583. }
  1584. if (relative.protocol && relative.protocol !== result.protocol) {
  1585. // if it's a known url protocol, then changing
  1586. // the protocol does weird things
  1587. // first, if it's not file:, then we MUST have a host,
  1588. // and if there was a path
  1589. // to begin with, then we MUST have a path.
  1590. // if it is file:, then the host is dropped,
  1591. // because that's known to be hostless.
  1592. // anything else is assumed to be absolute.
  1593. if (!slashedProtocol[relative.protocol]) {
  1594. Object.keys(relative).forEach(function(k) {
  1595. result[k] = relative[k];
  1596. });
  1597. result.href = result.format();
  1598. return result;
  1599. }
  1600. result.protocol = relative.protocol;
  1601. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  1602. var relPath = (relative.pathname || '').split('/');
  1603. while (relPath.length && !(relative.host = relPath.shift()));
  1604. if (!relative.host) relative.host = '';
  1605. if (!relative.hostname) relative.hostname = '';
  1606. if (relPath[0] !== '') relPath.unshift('');
  1607. if (relPath.length < 2) relPath.unshift('');
  1608. result.pathname = relPath.join('/');
  1609. } else {
  1610. result.pathname = relative.pathname;
  1611. }
  1612. result.search = relative.search;
  1613. result.query = relative.query;
  1614. result.host = relative.host || '';
  1615. result.auth = relative.auth;
  1616. result.hostname = relative.hostname || relative.host;
  1617. result.port = relative.port;
  1618. // to support http.request
  1619. if (result.pathname || result.search) {
  1620. var p = result.pathname || '';
  1621. var s = result.search || '';
  1622. result.path = p + s;
  1623. }
  1624. result.slashes = result.slashes || relative.slashes;
  1625. result.href = result.format();
  1626. return result;
  1627. }
  1628. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  1629. isRelAbs = (
  1630. relative.host ||
  1631. relative.pathname && relative.pathname.charAt(0) === '/'
  1632. ),
  1633. mustEndAbs = (isRelAbs || isSourceAbs ||
  1634. (result.host && relative.pathname)),
  1635. removeAllDots = mustEndAbs,
  1636. srcPath = result.pathname && result.pathname.split('/') || [],
  1637. relPath = relative.pathname && relative.pathname.split('/') || [],
  1638. psychotic = result.protocol && !slashedProtocol[result.protocol];
  1639. // if the url is a non-slashed url, then relative
  1640. // links like ../.. should be able
  1641. // to crawl up to the hostname, as well. This is strange.
  1642. // result.protocol has already been set by now.
  1643. // Later on, put the first path part into the host field.
  1644. if (psychotic) {
  1645. result.hostname = '';
  1646. result.port = null;
  1647. if (result.host) {
  1648. if (srcPath[0] === '') srcPath[0] = result.host;
  1649. else srcPath.unshift(result.host);
  1650. }
  1651. result.host = '';
  1652. if (relative.protocol) {
  1653. relative.hostname = null;
  1654. relative.port = null;
  1655. if (relative.host) {
  1656. if (relPath[0] === '') relPath[0] = relative.host;
  1657. else relPath.unshift(relative.host);
  1658. }
  1659. relative.host = null;
  1660. }
  1661. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  1662. }
  1663. if (isRelAbs) {
  1664. // it's absolute.
  1665. result.host = (relative.host || relative.host === '') ?
  1666. relative.host : result.host;
  1667. result.hostname = (relative.hostname || relative.hostname === '') ?
  1668. relative.hostname : result.hostname;
  1669. result.search = relative.search;
  1670. result.query = relative.query;
  1671. srcPath = relPath;
  1672. // fall through to the dot-handling below.
  1673. } else if (relPath.length) {
  1674. // it's relative
  1675. // throw away the existing file, and take the new path instead.
  1676. if (!srcPath) srcPath = [];
  1677. srcPath.pop();
  1678. srcPath = srcPath.concat(relPath);
  1679. result.search = relative.search;
  1680. result.query = relative.query;
  1681. } else if (!isNullOrUndefined(relative.search)) {
  1682. // just pull out the search.
  1683. // like href='?foo'.
  1684. // Put this after the other two cases because it simplifies the booleans
  1685. if (psychotic) {
  1686. result.hostname = result.host = srcPath.shift();
  1687. //occationaly the auth can get stuck only in host
  1688. //this especialy happens in cases like
  1689. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  1690. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  1691. result.host.split('@') : false;
  1692. if (authInHost) {
  1693. result.auth = authInHost.shift();
  1694. result.host = result.hostname = authInHost.shift();
  1695. }
  1696. }
  1697. result.search = relative.search;
  1698. result.query = relative.query;
  1699. //to support http.request
  1700. if (!isNull(result.pathname) || !isNull(result.search)) {
  1701. result.path = (result.pathname ? result.pathname : '') +
  1702. (result.search ? result.search : '');
  1703. }
  1704. result.href = result.format();
  1705. return result;
  1706. }
  1707. if (!srcPath.length) {
  1708. // no path at all. easy.
  1709. // we've already handled the other stuff above.
  1710. result.pathname = null;
  1711. //to support http.request
  1712. if (result.search) {
  1713. result.path = '/' + result.search;
  1714. } else {
  1715. result.path = null;
  1716. }
  1717. result.href = result.format();
  1718. return result;
  1719. }
  1720. // if a url ENDs in . or .., then it must get a trailing slash.
  1721. // however, if it ends in anything else non-slashy,
  1722. // then it must NOT get a trailing slash.
  1723. var last = srcPath.slice(-1)[0];
  1724. var hasTrailingSlash = (
  1725. (result.host || relative.host) && (last === '.' || last === '..') ||
  1726. last === '');
  1727. // strip single dots, resolve double dots to parent dir
  1728. // if the path tries to go above the root, `up` ends up > 0
  1729. var up = 0;
  1730. for (var i = srcPath.length; i >= 0; i--) {
  1731. last = srcPath[i];
  1732. if (last == '.') {
  1733. srcPath.splice(i, 1);
  1734. } else if (last === '..') {
  1735. srcPath.splice(i, 1);
  1736. up++;
  1737. } else if (up) {
  1738. srcPath.splice(i, 1);
  1739. up--;
  1740. }
  1741. }
  1742. // if the path is allowed to go above the root, restore leading ..s
  1743. if (!mustEndAbs && !removeAllDots) {
  1744. for (; up--; up) {
  1745. srcPath.unshift('..');
  1746. }
  1747. }
  1748. if (mustEndAbs && srcPath[0] !== '' &&
  1749. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  1750. srcPath.unshift('');
  1751. }
  1752. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  1753. srcPath.push('');
  1754. }
  1755. var isAbsolute = srcPath[0] === '' ||
  1756. (srcPath[0] && srcPath[0].charAt(0) === '/');
  1757. // put the host back
  1758. if (psychotic) {
  1759. result.hostname = result.host = isAbsolute ? '' :
  1760. srcPath.length ? srcPath.shift() : '';
  1761. //occationaly the auth can get stuck only in host
  1762. //this especialy happens in cases like
  1763. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  1764. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  1765. result.host.split('@') : false;
  1766. if (authInHost) {
  1767. result.auth = authInHost.shift();
  1768. result.host = result.hostname = authInHost.shift();
  1769. }
  1770. }
  1771. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  1772. if (mustEndAbs && !isAbsolute) {
  1773. srcPath.unshift('');
  1774. }
  1775. if (!srcPath.length) {
  1776. result.pathname = null;
  1777. result.path = null;
  1778. } else {
  1779. result.pathname = srcPath.join('/');
  1780. }
  1781. //to support request.http
  1782. if (!isNull(result.pathname) || !isNull(result.search)) {
  1783. result.path = (result.pathname ? result.pathname : '') +
  1784. (result.search ? result.search : '');
  1785. }
  1786. result.auth = relative.auth || result.auth;
  1787. result.slashes = result.slashes || relative.slashes;
  1788. result.href = result.format();
  1789. return result;
  1790. };
  1791. Url.prototype.parseHost = function() {
  1792. var host = this.host;
  1793. var port = portPattern.exec(host);
  1794. if (port) {
  1795. port = port[0];
  1796. if (port !== ':') {
  1797. this.port = port.substr(1);
  1798. }
  1799. host = host.substr(0, host.length - port.length);
  1800. }
  1801. if (host) this.hostname = host;
  1802. };
  1803. function isString(arg) {
  1804. return typeof arg === "string";
  1805. }
  1806. function isObject(arg) {
  1807. return typeof arg === 'object' && arg !== null;
  1808. }
  1809. function isNull(arg) {
  1810. return arg === null;
  1811. }
  1812. function isNullOrUndefined(arg) {
  1813. return arg == null;
  1814. }
  1815. /***/ },
  1816. /* 5 */
  1817. /***/ function(module, exports, __webpack_require__) {
  1818. var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module, global) {/*! https://mths.be/punycode v1.3.2 by @mathias */
  1819. ;(function(root) {
  1820. /** Detect free variables */
  1821. var freeExports = typeof exports == 'object' && exports &&
  1822. !exports.nodeType && exports;
  1823. var freeModule = typeof module == 'object' && module &&
  1824. !module.nodeType && module;
  1825. var freeGlobal = typeof global == 'object' && global;
  1826. if (
  1827. freeGlobal.global === freeGlobal ||
  1828. freeGlobal.window === freeGlobal ||
  1829. freeGlobal.self === freeGlobal
  1830. ) {
  1831. root = freeGlobal;
  1832. }
  1833. /**
  1834. * The `punycode` object.
  1835. * @name punycode
  1836. * @type Object
  1837. */
  1838. var punycode,
  1839. /** Highest positive signed 32-bit float value */
  1840. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  1841. /** Bootstring parameters */
  1842. base = 36,
  1843. tMin = 1,
  1844. tMax = 26,
  1845. skew = 38,
  1846. damp = 700,
  1847. initialBias = 72,
  1848. initialN = 128, // 0x80
  1849. delimiter = '-', // '\x2D'
  1850. /** Regular expressions */
  1851. regexPunycode = /^xn--/,
  1852. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  1853. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  1854. /** Error messages */
  1855. errors = {
  1856. 'overflow': 'Overflow: input needs wider integers to process',
  1857. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  1858. 'invalid-input': 'Invalid input'
  1859. },
  1860. /** Convenience shortcuts */
  1861. baseMinusTMin = base - tMin,
  1862. floor = Math.floor,
  1863. stringFromCharCode = String.fromCharCode,
  1864. /** Temporary variable */
  1865. key;
  1866. /*--------------------------------------------------------------------------*/
  1867. /**
  1868. * A generic error utility function.
  1869. * @private
  1870. * @param {String} type The error type.
  1871. * @returns {Error} Throws a `RangeError` with the applicable error message.
  1872. */
  1873. function error(type) {
  1874. throw RangeError(errors[type]);
  1875. }
  1876. /**
  1877. * A generic `Array#map` utility function.
  1878. * @private
  1879. * @param {Array} array The array to iterate over.
  1880. * @param {Function} callback The function that gets called for every array
  1881. * item.
  1882. * @returns {Array} A new array of values returned by the callback function.
  1883. */
  1884. function map(array, fn) {
  1885. var length = array.length;
  1886. var result = [];
  1887. while (length--) {
  1888. result[length] = fn(array[length]);
  1889. }
  1890. return result;
  1891. }
  1892. /**
  1893. * A simple `Array#map`-like wrapper to work with domain name strings or email
  1894. * addresses.
  1895. * @private
  1896. * @param {String} domain The domain name or email address.
  1897. * @param {Function} callback The function that gets called for every
  1898. * character.
  1899. * @returns {Array} A new string of characters returned by the callback
  1900. * function.
  1901. */
  1902. function mapDomain(string, fn) {
  1903. var parts = string.split('@');
  1904. var result = '';
  1905. if (parts.length > 1) {
  1906. // In email addresses, only the domain name should be punycoded. Leave
  1907. // the local part (i.e. everything up to `@`) intact.
  1908. result = parts[0] + '@';
  1909. string = parts[1];
  1910. }
  1911. // Avoid `split(regex)` for IE8 compatibility. See #17.
  1912. string = string.replace(regexSeparators, '\x2E');
  1913. var labels = string.split('.');
  1914. var encoded = map(labels, fn).join('.');
  1915. return result + encoded;
  1916. }
  1917. /**
  1918. * Creates an array containing the numeric code points of each Unicode
  1919. * character in the string. While JavaScript uses UCS-2 internally,
  1920. * this function will convert a pair of surrogate halves (each of which
  1921. * UCS-2 exposes as separate characters) into a single code point,
  1922. * matching UTF-16.
  1923. * @see `punycode.ucs2.encode`
  1924. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  1925. * @memberOf punycode.ucs2
  1926. * @name decode
  1927. * @param {String} string The Unicode input string (UCS-2).
  1928. * @returns {Array} The new array of code points.
  1929. */
  1930. function ucs2decode(string) {
  1931. var output = [],
  1932. counter = 0,
  1933. length = string.length,
  1934. value,
  1935. extra;
  1936. while (counter < length) {
  1937. value = string.charCodeAt(counter++);
  1938. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  1939. // high surrogate, and there is a next character
  1940. extra = string.charCodeAt(counter++);
  1941. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  1942. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  1943. } else {
  1944. // unmatched surrogate; only append this code unit, in case the next
  1945. // code unit is the high surrogate of a surrogate pair
  1946. output.push(value);
  1947. counter--;
  1948. }
  1949. } else {
  1950. output.push(value);
  1951. }
  1952. }
  1953. return output;
  1954. }
  1955. /**
  1956. * Creates a string based on an array of numeric code points.
  1957. * @see `punycode.ucs2.decode`
  1958. * @memberOf punycode.ucs2
  1959. * @name encode
  1960. * @param {Array} codePoints The array of numeric code points.
  1961. * @returns {String} The new Unicode string (UCS-2).
  1962. */
  1963. function ucs2encode(array) {
  1964. return map(array, function(value) {
  1965. var output = '';
  1966. if (value > 0xFFFF) {
  1967. value -= 0x10000;
  1968. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  1969. value = 0xDC00 | value & 0x3FF;
  1970. }
  1971. output += stringFromCharCode(value);
  1972. return output;
  1973. }).join('');
  1974. }
  1975. /**
  1976. * Converts a basic code point into a digit/integer.
  1977. * @see `digitToBasic()`
  1978. * @private
  1979. * @param {Number} codePoint The basic numeric code point value.
  1980. * @returns {Number} The numeric value of a basic code point (for use in
  1981. * representing integers) in the range `0` to `base - 1`, or `base` if
  1982. * the code point does not represent a value.
  1983. */
  1984. function basicToDigit(codePoint) {
  1985. if (codePoint - 48 < 10) {
  1986. return codePoint - 22;
  1987. }
  1988. if (codePoint - 65 < 26) {
  1989. return codePoint - 65;
  1990. }
  1991. if (codePoint - 97 < 26) {
  1992. return codePoint - 97;
  1993. }
  1994. return base;
  1995. }
  1996. /**
  1997. * Converts a digit/integer into a basic code point.
  1998. * @see `basicToDigit()`
  1999. * @private
  2000. * @param {Number} digit The numeric value of a basic code point.
  2001. * @returns {Number} The basic code point whose value (when used for
  2002. * representing integers) is `digit`, which needs to be in the range
  2003. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  2004. * used; else, the lowercase form is used. The behavior is undefined
  2005. * if `flag` is non-zero and `digit` has no uppercase form.
  2006. */
  2007. function digitToBasic(digit, flag) {
  2008. // 0..25 map to ASCII a..z or A..Z
  2009. // 26..35 map to ASCII 0..9
  2010. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  2011. }
  2012. /**
  2013. * Bias adaptation function as per section 3.4 of RFC 3492.
  2014. * http://tools.ietf.org/html/rfc3492#section-3.4
  2015. * @private
  2016. */
  2017. function adapt(delta, numPoints, firstTime) {
  2018. var k = 0;
  2019. delta = firstTime ? floor(delta / damp) : delta >> 1;
  2020. delta += floor(delta / numPoints);
  2021. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  2022. delta = floor(delta / baseMinusTMin);
  2023. }
  2024. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  2025. }
  2026. /**
  2027. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  2028. * symbols.
  2029. * @memberOf punycode
  2030. * @param {String} input The Punycode string of ASCII-only symbols.
  2031. * @returns {String} The resulting string of Unicode symbols.
  2032. */
  2033. function decode(input) {
  2034. // Don't use UCS-2
  2035. var output = [],
  2036. inputLength = input.length,
  2037. out,
  2038. i = 0,
  2039. n = initialN,
  2040. bias = initialBias,
  2041. basic,
  2042. j,
  2043. index,
  2044. oldi,
  2045. w,
  2046. k,
  2047. digit,
  2048. t,
  2049. /** Cached calculation results */
  2050. baseMinusT;
  2051. // Handle the basic code points: let `basic` be the number of input code
  2052. // points before the last delimiter, or `0` if there is none, then copy
  2053. // the first basic code points to the output.
  2054. basic = input.lastIndexOf(delimiter);
  2055. if (basic < 0) {
  2056. basic = 0;
  2057. }
  2058. for (j = 0; j < basic; ++j) {
  2059. // if it's not a basic code point
  2060. if (input.charCodeAt(j) >= 0x80) {
  2061. error('not-basic');
  2062. }
  2063. output.push(input.charCodeAt(j));
  2064. }
  2065. // Main decoding loop: start just after the last delimiter if any basic code
  2066. // points were copied; start at the beginning otherwise.
  2067. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  2068. // `index` is the index of the next character to be consumed.
  2069. // Decode a generalized variable-length integer into `delta`,
  2070. // which gets added to `i`. The overflow checking is easier
  2071. // if we increase `i` as we go, then subtract off its starting
  2072. // value at the end to obtain `delta`.
  2073. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  2074. if (index >= inputLength) {
  2075. error('invalid-input');
  2076. }
  2077. digit = basicToDigit(input.charCodeAt(index++));
  2078. if (digit >= base || digit > floor((maxInt - i) / w)) {
  2079. error('overflow');
  2080. }
  2081. i += digit * w;
  2082. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  2083. if (digit < t) {
  2084. break;
  2085. }
  2086. baseMinusT = base - t;
  2087. if (w > floor(maxInt / baseMinusT)) {
  2088. error('overflow');
  2089. }
  2090. w *= baseMinusT;
  2091. }
  2092. out = output.length + 1;
  2093. bias = adapt(i - oldi, out, oldi == 0);
  2094. // `i` was supposed to wrap around from `out` to `0`,
  2095. // incrementing `n` each time, so we'll fix that now:
  2096. if (floor(i / out) > maxInt - n) {
  2097. error('overflow');
  2098. }
  2099. n += floor(i / out);
  2100. i %= out;
  2101. // Insert `n` at position `i` of the output
  2102. output.splice(i++, 0, n);
  2103. }
  2104. return ucs2encode(output);
  2105. }
  2106. /**
  2107. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  2108. * Punycode string of ASCII-only symbols.
  2109. * @memberOf punycode
  2110. * @param {String} input The string of Unicode symbols.
  2111. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  2112. */
  2113. function encode(input) {
  2114. var n,
  2115. delta,
  2116. handledCPCount,
  2117. basicLength,
  2118. bias,
  2119. j,
  2120. m,
  2121. q,
  2122. k,
  2123. t,
  2124. currentValue,
  2125. output = [],
  2126. /** `inputLength` will hold the number of code points in `input`. */
  2127. inputLength,
  2128. /** Cached calculation results */
  2129. handledCPCountPlusOne,
  2130. baseMinusT,
  2131. qMinusT;
  2132. // Convert the input in UCS-2 to Unicode
  2133. input = ucs2decode(input);
  2134. // Cache the length
  2135. inputLength = input.length;
  2136. // Initialize the state
  2137. n = initialN;
  2138. delta = 0;
  2139. bias = initialBias;
  2140. // Handle the basic code points
  2141. for (j = 0; j < inputLength; ++j) {
  2142. currentValue = input[j];
  2143. if (currentValue < 0x80) {
  2144. output.push(stringFromCharCode(currentValue));
  2145. }
  2146. }
  2147. handledCPCount = basicLength = output.length;
  2148. // `handledCPCount` is the number of code points that have been handled;
  2149. // `basicLength` is the number of basic code points.
  2150. // Finish the basic string - if it is not empty - with a delimiter
  2151. if (basicLength) {
  2152. output.push(delimiter);
  2153. }
  2154. // Main encoding loop:
  2155. while (handledCPCount < inputLength) {
  2156. // All non-basic code points < n have been handled already. Find the next
  2157. // larger one:
  2158. for (m = maxInt, j = 0; j < inputLength; ++j) {
  2159. currentValue = input[j];
  2160. if (currentValue >= n && currentValue < m) {
  2161. m = currentValue;
  2162. }
  2163. }
  2164. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  2165. // but guard against overflow
  2166. handledCPCountPlusOne = handledCPCount + 1;
  2167. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  2168. error('overflow');
  2169. }
  2170. delta += (m - n) * handledCPCountPlusOne;
  2171. n = m;
  2172. for (j = 0; j < inputLength; ++j) {
  2173. currentValue = input[j];
  2174. if (currentValue < n && ++delta > maxInt) {
  2175. error('overflow');
  2176. }
  2177. if (currentValue == n) {
  2178. // Represent delta as a generalized variable-length integer
  2179. for (q = delta, k = base; /* no condition */; k += base) {
  2180. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  2181. if (q < t) {
  2182. break;
  2183. }
  2184. qMinusT = q - t;
  2185. baseMinusT = base - t;
  2186. output.push(
  2187. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  2188. );
  2189. q = floor(qMinusT / baseMinusT);
  2190. }
  2191. output.push(stringFromCharCode(digitToBasic(q, 0)));
  2192. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  2193. delta = 0;
  2194. ++handledCPCount;
  2195. }
  2196. }
  2197. ++delta;
  2198. ++n;
  2199. }
  2200. return output.join('');
  2201. }
  2202. /**
  2203. * Converts a Punycode string representing a domain name or an email address
  2204. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  2205. * it doesn't matter if you call it on a string that has already been
  2206. * converted to Unicode.
  2207. * @memberOf punycode
  2208. * @param {String} input The Punycoded domain name or email address to
  2209. * convert to Unicode.
  2210. * @returns {String} The Unicode representation of the given Punycode
  2211. * string.
  2212. */
  2213. function toUnicode(input) {
  2214. return mapDomain(input, function(string) {
  2215. return regexPunycode.test(string)
  2216. ? decode(string.slice(4).toLowerCase())
  2217. : string;
  2218. });
  2219. }
  2220. /**
  2221. * Converts a Unicode string representing a domain name or an email address to
  2222. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  2223. * i.e. it doesn't matter if you call it with a domain that's already in
  2224. * ASCII.
  2225. * @memberOf punycode
  2226. * @param {String} input The domain name or email address to convert, as a
  2227. * Unicode string.
  2228. * @returns {String} The Punycode representation of the given domain name or
  2229. * email address.
  2230. */
  2231. function toASCII(input) {
  2232. return mapDomain(input, function(string) {
  2233. return regexNonASCII.test(string)
  2234. ? 'xn--' + encode(string)
  2235. : string;
  2236. });
  2237. }
  2238. /*--------------------------------------------------------------------------*/
  2239. /** Define the public API */
  2240. punycode = {
  2241. /**
  2242. * A string representing the current Punycode.js version number.
  2243. * @memberOf punycode
  2244. * @type String
  2245. */
  2246. 'version': '1.3.2',
  2247. /**
  2248. * An object of methods to convert from JavaScript's internal character
  2249. * representation (UCS-2) to Unicode code points, and back.
  2250. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  2251. * @memberOf punycode
  2252. * @type Object
  2253. */
  2254. 'ucs2': {
  2255. 'decode': ucs2decode,
  2256. 'encode': ucs2encode
  2257. },
  2258. 'decode': decode,
  2259. 'encode': encode,
  2260. 'toASCII': toASCII,
  2261. 'toUnicode': toUnicode
  2262. };
  2263. /** Expose `punycode` */
  2264. // Some AMD build optimizers, like r.js, check for specific condition patterns
  2265. // like the following:
  2266. if (
  2267. true
  2268. ) {
  2269. !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
  2270. return punycode;
  2271. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2272. } else if (freeExports && freeModule) {
  2273. if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+
  2274. freeModule.exports = punycode;
  2275. } else { // in Narwhal or RingoJS v0.7.0-
  2276. for (key in punycode) {
  2277. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  2278. }
  2279. }
  2280. } else { // in Rhino or a web browser
  2281. root.punycode = punycode;
  2282. }
  2283. }(this));
  2284. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(6)(module), (function() { return this; }())))
  2285. /***/ },
  2286. /* 6 */
  2287. /***/ function(module, exports) {
  2288. module.exports = function(module) {
  2289. if(!module.webpackPolyfill) {
  2290. module.deprecate = function() {};
  2291. module.paths = [];
  2292. // module.parent = undefined by default
  2293. module.children = [];
  2294. module.webpackPolyfill = 1;
  2295. }
  2296. return module;
  2297. }
  2298. /***/ },
  2299. /* 7 */
  2300. /***/ function(module, exports, __webpack_require__) {
  2301. 'use strict';
  2302. exports.decode = exports.parse = __webpack_require__(8);
  2303. exports.encode = exports.stringify = __webpack_require__(9);
  2304. /***/ },
  2305. /* 8 */
  2306. /***/ function(module, exports) {
  2307. // Copyright Joyent, Inc. and other Node contributors.
  2308. //
  2309. // Permission is hereby granted, free of charge, to any person obtaining a
  2310. // copy of this software and associated documentation files (the
  2311. // "Software"), to deal in the Software without restriction, including
  2312. // without limitation the rights to use, copy, modify, merge, publish,
  2313. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2314. // persons to whom the Software is furnished to do so, subject to the
  2315. // following conditions:
  2316. //
  2317. // The above copyright notice and this permission notice shall be included
  2318. // in all copies or substantial portions of the Software.
  2319. //
  2320. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2321. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2322. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2323. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2324. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2325. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2326. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2327. 'use strict';
  2328. // If obj.hasOwnProperty has been overridden, then calling
  2329. // obj.hasOwnProperty(prop) will break.
  2330. // See: https://github.com/joyent/node/issues/1707
  2331. function hasOwnProperty(obj, prop) {
  2332. return Object.prototype.hasOwnProperty.call(obj, prop);
  2333. }
  2334. module.exports = function(qs, sep, eq, options) {
  2335. sep = sep || '&';
  2336. eq = eq || '=';
  2337. var obj = {};
  2338. if (typeof qs !== 'string' || qs.length === 0) {
  2339. return obj;
  2340. }
  2341. var regexp = /\+/g;
  2342. qs = qs.split(sep);
  2343. var maxKeys = 1000;
  2344. if (options && typeof options.maxKeys === 'number') {
  2345. maxKeys = options.maxKeys;
  2346. }
  2347. var len = qs.length;
  2348. // maxKeys <= 0 means that we should not limit keys count
  2349. if (maxKeys > 0 && len > maxKeys) {
  2350. len = maxKeys;
  2351. }
  2352. for (var i = 0; i < len; ++i) {
  2353. var x = qs[i].replace(regexp, '%20'),
  2354. idx = x.indexOf(eq),
  2355. kstr, vstr, k, v;
  2356. if (idx >= 0) {
  2357. kstr = x.substr(0, idx);
  2358. vstr = x.substr(idx + 1);
  2359. } else {
  2360. kstr = x;
  2361. vstr = '';
  2362. }
  2363. k = decodeURIComponent(kstr);
  2364. v = decodeURIComponent(vstr);
  2365. if (!hasOwnProperty(obj, k)) {
  2366. obj[k] = v;
  2367. } else if (Array.isArray(obj[k])) {
  2368. obj[k].push(v);
  2369. } else {
  2370. obj[k] = [obj[k], v];
  2371. }
  2372. }
  2373. return obj;
  2374. };
  2375. /***/ },
  2376. /* 9 */
  2377. /***/ function(module, exports) {
  2378. // Copyright Joyent, Inc. and other Node contributors.
  2379. //
  2380. // Permission is hereby granted, free of charge, to any person obtaining a
  2381. // copy of this software and associated documentation files (the
  2382. // "Software"), to deal in the Software without restriction, including
  2383. // without limitation the rights to use, copy, modify, merge, publish,
  2384. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2385. // persons to whom the Software is furnished to do so, subject to the
  2386. // following conditions:
  2387. //
  2388. // The above copyright notice and this permission notice shall be included
  2389. // in all copies or substantial portions of the Software.
  2390. //
  2391. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2392. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2393. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2394. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2395. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2396. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2397. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2398. 'use strict';
  2399. var stringifyPrimitive = function(v) {
  2400. switch (typeof v) {
  2401. case 'string':
  2402. return v;
  2403. case 'boolean':
  2404. return v ? 'true' : 'false';
  2405. case 'number':
  2406. return isFinite(v) ? v : '';
  2407. default:
  2408. return '';
  2409. }
  2410. };
  2411. module.exports = function(obj, sep, eq, name) {
  2412. sep = sep || '&';
  2413. eq = eq || '=';
  2414. if (obj === null) {
  2415. obj = undefined;
  2416. }
  2417. if (typeof obj === 'object') {
  2418. return Object.keys(obj).map(function(k) {
  2419. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  2420. if (Array.isArray(obj[k])) {
  2421. return obj[k].map(function(v) {
  2422. return ks + encodeURIComponent(stringifyPrimitive(v));
  2423. }).join(sep);
  2424. } else {
  2425. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  2426. }
  2427. }).join(sep);
  2428. }
  2429. if (!name) return '';
  2430. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  2431. encodeURIComponent(stringifyPrimitive(obj));
  2432. };
  2433. /***/ },
  2434. /* 10 */
  2435. /***/ function(module, exports) {
  2436. 'use strict';
  2437. module.exports = function equal(a, b) {
  2438. if (a === b) return true;
  2439. var arrA = Array.isArray(a)
  2440. , arrB = Array.isArray(b)
  2441. , i;
  2442. if (arrA && arrB) {
  2443. if (a.length != b.length) return false;
  2444. for (i = 0; i < a.length; i++)
  2445. if (!equal(a[i], b[i])) return false;
  2446. return true;
  2447. }
  2448. if (arrA != arrB) return false;
  2449. if (a && b && typeof a === 'object' && typeof b === 'object') {
  2450. var keys = Object.keys(a);
  2451. if (keys.length !== Object.keys(b).length) return false;
  2452. for (i = 0; i < keys.length; i++)
  2453. if (b[keys[i]] === undefined) return false;
  2454. for (i = 0; i < keys.length; i++)
  2455. if(!equal(a[keys[i]], b[keys[i]])) return false;
  2456. return true;
  2457. }
  2458. return false;
  2459. };
  2460. /***/ },
  2461. /* 11 */
  2462. /***/ function(module, exports, __webpack_require__) {
  2463. 'use strict';
  2464. module.exports = {
  2465. copy: copy,
  2466. checkDataType: checkDataType,
  2467. checkDataTypes: checkDataTypes,
  2468. coerceToTypes: coerceToTypes,
  2469. toHash: toHash,
  2470. getProperty: getProperty,
  2471. escapeQuotes: escapeQuotes,
  2472. ucs2length: ucs2length,
  2473. varOccurences: varOccurences,
  2474. varReplace: varReplace,
  2475. cleanUpCode: cleanUpCode,
  2476. cleanUpVarErrors: cleanUpVarErrors,
  2477. schemaHasRules: schemaHasRules,
  2478. stableStringify: __webpack_require__(12),
  2479. toQuotedString: toQuotedString,
  2480. getPathExpr: getPathExpr,
  2481. getPath: getPath,
  2482. getData: getData,
  2483. unescapeFragment: unescapeFragment,
  2484. escapeFragment: escapeFragment,
  2485. escapeJsonPointer: escapeJsonPointer
  2486. };
  2487. function copy(o, to) {
  2488. to = to || {};
  2489. for (var key in o) to[key] = o[key];
  2490. return to;
  2491. }
  2492. function checkDataType(dataType, data, negate) {
  2493. var EQUAL = negate ? ' !== ' : ' === '
  2494. , AND = negate ? ' || ' : ' && '
  2495. , OK = negate ? '!' : ''
  2496. , NOT = negate ? '' : '!';
  2497. switch (dataType) {
  2498. case 'null': return data + EQUAL + 'null';
  2499. case 'array': return OK + 'Array.isArray(' + data + ')';
  2500. case 'object': return '(' + OK + data + AND +
  2501. 'typeof ' + data + EQUAL + '"object"' + AND +
  2502. NOT + 'Array.isArray(' + data + '))';
  2503. case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
  2504. NOT + '(' + data + ' % 1))';
  2505. default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
  2506. }
  2507. }
  2508. function checkDataTypes(dataTypes, data) {
  2509. switch (dataTypes.length) {
  2510. case 1: return checkDataType(dataTypes[0], data, true);
  2511. default:
  2512. var code = '';
  2513. var types = toHash(dataTypes);
  2514. if (types.array && types.object) {
  2515. code = types.null ? '(': '(!' + data + ' || ';
  2516. code += 'typeof ' + data + ' !== "object")';
  2517. delete types.null;
  2518. delete types.array;
  2519. delete types.object;
  2520. }
  2521. if (types.number) delete types.integer;
  2522. for (var t in types)
  2523. code += (code ? ' && ' : '' ) + checkDataType(t, data, true);
  2524. return code;
  2525. }
  2526. }
  2527. var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
  2528. function coerceToTypes(dataTypes) {
  2529. if (Array.isArray(dataTypes)) {
  2530. var types = [];
  2531. for (var i=0; i<dataTypes.length; i++) {
  2532. var t = dataTypes[i];
  2533. if (COERCE_TO_TYPES[t]) types[types.length] = t;
  2534. }
  2535. if (types.length) return types;
  2536. } else if (COERCE_TO_TYPES[dataTypes]) {
  2537. return [dataTypes];
  2538. }
  2539. }
  2540. function toHash(arr) {
  2541. var hash = {};
  2542. for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
  2543. return hash;
  2544. }
  2545. var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
  2546. var SINGLE_QUOTE = /'|\\/g;
  2547. function getProperty(key) {
  2548. return typeof key == 'number'
  2549. ? '[' + key + ']'
  2550. : IDENTIFIER.test(key)
  2551. ? '.' + key
  2552. : "['" + key.replace(SINGLE_QUOTE, '\\$&') + "']";
  2553. }
  2554. function escapeQuotes(str) {
  2555. return str.replace(SINGLE_QUOTE, '\\$&');
  2556. }
  2557. // https://mathiasbynens.be/notes/javascript-encoding
  2558. // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
  2559. function ucs2length(str) {
  2560. var length = 0
  2561. , len = str.length
  2562. , pos = 0
  2563. , value;
  2564. while (pos < len) {
  2565. length++;
  2566. value = str.charCodeAt(pos++);
  2567. if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
  2568. // high surrogate, and there is a next character
  2569. value = str.charCodeAt(pos);
  2570. if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
  2571. }
  2572. }
  2573. return length;
  2574. }
  2575. function varOccurences(str, dataVar) {
  2576. dataVar += '[^0-9]';
  2577. var matches = str.match(new RegExp(dataVar, 'g'));
  2578. return matches ? matches.length : 0;
  2579. }
  2580. function varReplace(str, dataVar, expr) {
  2581. dataVar += '([^0-9])';
  2582. expr = expr.replace(/\$/g, '$$$$');
  2583. return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
  2584. }
  2585. var EMPTY_ELSE = /else\s*{\s*}/g
  2586. , EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g
  2587. , EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g;
  2588. function cleanUpCode(out) {
  2589. return out.replace(EMPTY_ELSE, '')
  2590. .replace(EMPTY_IF_NO_ELSE, '')
  2591. .replace(EMPTY_IF_WITH_ELSE, 'if (!($1))');
  2592. }
  2593. var ERRORS_REGEXP = /[^v\.]errors/g
  2594. , REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g
  2595. , REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g
  2596. , RETURN_VALID = 'return errors === 0;'
  2597. , RETURN_TRUE = 'validate.errors = null; return true;'
  2598. , RETURN_ASYNC = /if \(errors === 0\) return true;\s*else throw new ValidationError\(vErrors\);/
  2599. , RETURN_TRUE_ASYNC = 'return true;';
  2600. function cleanUpVarErrors(out, async) {
  2601. var matches = out.match(ERRORS_REGEXP);
  2602. if (!matches || matches.length !== 2) return out;
  2603. return async
  2604. ? out.replace(REMOVE_ERRORS_ASYNC, '')
  2605. .replace(RETURN_ASYNC, RETURN_TRUE_ASYNC)
  2606. : out.replace(REMOVE_ERRORS, '')
  2607. .replace(RETURN_VALID, RETURN_TRUE);
  2608. }
  2609. function schemaHasRules(schema, rules) {
  2610. for (var key in schema) if (rules[key]) return true;
  2611. }
  2612. function toQuotedString(str) {
  2613. return '\'' + escapeQuotes(str) + '\'';
  2614. }
  2615. function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
  2616. var path = jsonPointers // false by default
  2617. ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
  2618. : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
  2619. return joinPaths(currentPath, path);
  2620. }
  2621. function getPath(currentPath, prop, jsonPointers) {
  2622. var path = jsonPointers // false by default
  2623. ? toQuotedString('/' + escapeJsonPointer(prop))
  2624. : toQuotedString(getProperty(prop));
  2625. return joinPaths(currentPath, path);
  2626. }
  2627. var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
  2628. function getData($data, lvl, paths) {
  2629. var matches = $data.match(RELATIVE_JSON_POINTER);
  2630. if (!matches) throw new Error('Invalid relative JSON-pointer: ' + $data);
  2631. var up = +matches[1];
  2632. var jsonPointer = matches[2];
  2633. if (jsonPointer == '#') {
  2634. if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
  2635. return paths[lvl - up];
  2636. }
  2637. if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
  2638. var data = 'data' + ((lvl - up) || '');
  2639. if (!jsonPointer) return data;
  2640. var expr = data;
  2641. var segments = jsonPointer.split('/');
  2642. for (var i=0; i<segments.length; i++) {
  2643. var segment = segments[i];
  2644. if (segment) {
  2645. data += getProperty(unescapeJsonPointer(segment));
  2646. expr += ' && ' + data;
  2647. }
  2648. }
  2649. return expr;
  2650. }
  2651. function joinPaths (a, b) {
  2652. if (a == '""') return b;
  2653. return (a + ' + ' + b).replace(/' \+ '/g, '');
  2654. }
  2655. function unescapeFragment(str) {
  2656. return unescapeJsonPointer(decodeURIComponent(str));
  2657. }
  2658. function escapeFragment(str) {
  2659. return encodeURIComponent(escapeJsonPointer(str));
  2660. }
  2661. function escapeJsonPointer(str) {
  2662. return str.replace(/~/g, '~0').replace(/\//g, '~1');
  2663. }
  2664. function unescapeJsonPointer(str) {
  2665. return str.replace(/~1/g, '/').replace(/~0/g, '~');
  2666. }
  2667. /***/ },
  2668. /* 12 */
  2669. /***/ function(module, exports, __webpack_require__) {
  2670. var json = typeof JSON !== 'undefined' ? JSON : __webpack_require__(13);
  2671. module.exports = function (obj, opts) {
  2672. if (!opts) opts = {};
  2673. if (typeof opts === 'function') opts = { cmp: opts };
  2674. var space = opts.space || '';
  2675. if (typeof space === 'number') space = Array(space+1).join(' ');
  2676. var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
  2677. var replacer = opts.replacer || function(key, value) { return value; };
  2678. var cmp = opts.cmp && (function (f) {
  2679. return function (node) {
  2680. return function (a, b) {
  2681. var aobj = { key: a, value: node[a] };
  2682. var bobj = { key: b, value: node[b] };
  2683. return f(aobj, bobj);
  2684. };
  2685. };
  2686. })(opts.cmp);
  2687. var seen = [];
  2688. return (function stringify (parent, key, node, level) {
  2689. var indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
  2690. var colonSeparator = space ? ': ' : ':';
  2691. if (node && node.toJSON && typeof node.toJSON === 'function') {
  2692. node = node.toJSON();
  2693. }
  2694. node = replacer.call(parent, key, node);
  2695. if (node === undefined) {
  2696. return;
  2697. }
  2698. if (typeof node !== 'object' || node === null) {
  2699. return json.stringify(node);
  2700. }
  2701. if (isArray(node)) {
  2702. var out = [];
  2703. for (var i = 0; i < node.length; i++) {
  2704. var item = stringify(node, i, node[i], level+1) || json.stringify(null);
  2705. out.push(indent + space + item);
  2706. }
  2707. return '[' + out.join(',') + indent + ']';
  2708. }
  2709. else {
  2710. if (seen.indexOf(node) !== -1) {
  2711. if (cycles) return json.stringify('__cycle__');
  2712. throw new TypeError('Converting circular structure to JSON');
  2713. }
  2714. else seen.push(node);
  2715. var keys = objectKeys(node).sort(cmp && cmp(node));
  2716. var out = [];
  2717. for (var i = 0; i < keys.length; i++) {
  2718. var key = keys[i];
  2719. var value = stringify(node, key, node[key], level+1);
  2720. if(!value) continue;
  2721. var keyValue = json.stringify(key)
  2722. + colonSeparator
  2723. + value;
  2724. ;
  2725. out.push(indent + space + keyValue);
  2726. }
  2727. seen.splice(seen.indexOf(node), 1);
  2728. return '{' + out.join(',') + indent + '}';
  2729. }
  2730. })({ '': obj }, '', obj, 0);
  2731. };
  2732. var isArray = Array.isArray || function (x) {
  2733. return {}.toString.call(x) === '[object Array]';
  2734. };
  2735. var objectKeys = Object.keys || function (obj) {
  2736. var has = Object.prototype.hasOwnProperty || function () { return true };
  2737. var keys = [];
  2738. for (var key in obj) {
  2739. if (has.call(obj, key)) keys.push(key);
  2740. }
  2741. return keys;
  2742. };
  2743. /***/ },
  2744. /* 13 */
  2745. /***/ function(module, exports, __webpack_require__) {
  2746. exports.parse = __webpack_require__(14);
  2747. exports.stringify = __webpack_require__(15);
  2748. /***/ },
  2749. /* 14 */
  2750. /***/ function(module, exports) {
  2751. var at, // The index of the current character
  2752. ch, // The current character
  2753. escapee = {
  2754. '"': '"',
  2755. '\\': '\\',
  2756. '/': '/',
  2757. b: '\b',
  2758. f: '\f',
  2759. n: '\n',
  2760. r: '\r',
  2761. t: '\t'
  2762. },
  2763. text,
  2764. error = function (m) {
  2765. // Call error when something is wrong.
  2766. throw {
  2767. name: 'SyntaxError',
  2768. message: m,
  2769. at: at,
  2770. text: text
  2771. };
  2772. },
  2773. next = function (c) {
  2774. // If a c parameter is provided, verify that it matches the current character.
  2775. if (c && c !== ch) {
  2776. error("Expected '" + c + "' instead of '" + ch + "'");
  2777. }
  2778. // Get the next character. When there are no more characters,
  2779. // return the empty string.
  2780. ch = text.charAt(at);
  2781. at += 1;
  2782. return ch;
  2783. },
  2784. number = function () {
  2785. // Parse a number value.
  2786. var number,
  2787. string = '';
  2788. if (ch === '-') {
  2789. string = '-';
  2790. next('-');
  2791. }
  2792. while (ch >= '0' && ch <= '9') {
  2793. string += ch;
  2794. next();
  2795. }
  2796. if (ch === '.') {
  2797. string += '.';
  2798. while (next() && ch >= '0' && ch <= '9') {
  2799. string += ch;
  2800. }
  2801. }
  2802. if (ch === 'e' || ch === 'E') {
  2803. string += ch;
  2804. next();
  2805. if (ch === '-' || ch === '+') {
  2806. string += ch;
  2807. next();
  2808. }
  2809. while (ch >= '0' && ch <= '9') {
  2810. string += ch;
  2811. next();
  2812. }
  2813. }
  2814. number = +string;
  2815. if (!isFinite(number)) {
  2816. error("Bad number");
  2817. } else {
  2818. return number;
  2819. }
  2820. },
  2821. string = function () {
  2822. // Parse a string value.
  2823. var hex,
  2824. i,
  2825. string = '',
  2826. uffff;
  2827. // When parsing for string values, we must look for " and \ characters.
  2828. if (ch === '"') {
  2829. while (next()) {
  2830. if (ch === '"') {
  2831. next();
  2832. return string;
  2833. } else if (ch === '\\') {
  2834. next();
  2835. if (ch === 'u') {
  2836. uffff = 0;
  2837. for (i = 0; i < 4; i += 1) {
  2838. hex = parseInt(next(), 16);
  2839. if (!isFinite(hex)) {
  2840. break;
  2841. }
  2842. uffff = uffff * 16 + hex;
  2843. }
  2844. string += String.fromCharCode(uffff);
  2845. } else if (typeof escapee[ch] === 'string') {
  2846. string += escapee[ch];
  2847. } else {
  2848. break;
  2849. }
  2850. } else {
  2851. string += ch;
  2852. }
  2853. }
  2854. }
  2855. error("Bad string");
  2856. },
  2857. white = function () {
  2858. // Skip whitespace.
  2859. while (ch && ch <= ' ') {
  2860. next();
  2861. }
  2862. },
  2863. word = function () {
  2864. // true, false, or null.
  2865. switch (ch) {
  2866. case 't':
  2867. next('t');
  2868. next('r');
  2869. next('u');
  2870. next('e');
  2871. return true;
  2872. case 'f':
  2873. next('f');
  2874. next('a');
  2875. next('l');
  2876. next('s');
  2877. next('e');
  2878. return false;
  2879. case 'n':
  2880. next('n');
  2881. next('u');
  2882. next('l');
  2883. next('l');
  2884. return null;
  2885. }
  2886. error("Unexpected '" + ch + "'");
  2887. },
  2888. value, // Place holder for the value function.
  2889. array = function () {
  2890. // Parse an array value.
  2891. var array = [];
  2892. if (ch === '[') {
  2893. next('[');
  2894. white();
  2895. if (ch === ']') {
  2896. next(']');
  2897. return array; // empty array
  2898. }
  2899. while (ch) {
  2900. array.push(value());
  2901. white();
  2902. if (ch === ']') {
  2903. next(']');
  2904. return array;
  2905. }
  2906. next(',');
  2907. white();
  2908. }
  2909. }
  2910. error("Bad array");
  2911. },
  2912. object = function () {
  2913. // Parse an object value.
  2914. var key,
  2915. object = {};
  2916. if (ch === '{') {
  2917. next('{');
  2918. white();
  2919. if (ch === '}') {
  2920. next('}');
  2921. return object; // empty object
  2922. }
  2923. while (ch) {
  2924. key = string();
  2925. white();
  2926. next(':');
  2927. if (Object.hasOwnProperty.call(object, key)) {
  2928. error('Duplicate key "' + key + '"');
  2929. }
  2930. object[key] = value();
  2931. white();
  2932. if (ch === '}') {
  2933. next('}');
  2934. return object;
  2935. }
  2936. next(',');
  2937. white();
  2938. }
  2939. }
  2940. error("Bad object");
  2941. };
  2942. value = function () {
  2943. // Parse a JSON value. It could be an object, an array, a string, a number,
  2944. // or a word.
  2945. white();
  2946. switch (ch) {
  2947. case '{':
  2948. return object();
  2949. case '[':
  2950. return array();
  2951. case '"':
  2952. return string();
  2953. case '-':
  2954. return number();
  2955. default:
  2956. return ch >= '0' && ch <= '9' ? number() : word();
  2957. }
  2958. };
  2959. // Return the json_parse function. It will have access to all of the above
  2960. // functions and variables.
  2961. module.exports = function (source, reviver) {
  2962. var result;
  2963. text = source;
  2964. at = 0;
  2965. ch = ' ';
  2966. result = value();
  2967. white();
  2968. if (ch) {
  2969. error("Syntax error");
  2970. }
  2971. // If there is a reviver function, we recursively walk the new structure,
  2972. // passing each name/value pair to the reviver function for possible
  2973. // transformation, starting with a temporary root object that holds the result
  2974. // in an empty key. If there is not a reviver function, we simply return the
  2975. // result.
  2976. return typeof reviver === 'function' ? (function walk(holder, key) {
  2977. var k, v, value = holder[key];
  2978. if (value && typeof value === 'object') {
  2979. for (k in value) {
  2980. if (Object.prototype.hasOwnProperty.call(value, k)) {
  2981. v = walk(value, k);
  2982. if (v !== undefined) {
  2983. value[k] = v;
  2984. } else {
  2985. delete value[k];
  2986. }
  2987. }
  2988. }
  2989. }
  2990. return reviver.call(holder, key, value);
  2991. }({'': result}, '')) : result;
  2992. };
  2993. /***/ },
  2994. /* 15 */
  2995. /***/ function(module, exports) {
  2996. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  2997. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  2998. gap,
  2999. indent,
  3000. meta = { // table of character substitutions
  3001. '\b': '\\b',
  3002. '\t': '\\t',
  3003. '\n': '\\n',
  3004. '\f': '\\f',
  3005. '\r': '\\r',
  3006. '"' : '\\"',
  3007. '\\': '\\\\'
  3008. },
  3009. rep;
  3010. function quote(string) {
  3011. // If the string contains no control characters, no quote characters, and no
  3012. // backslash characters, then we can safely slap some quotes around it.
  3013. // Otherwise we must also replace the offending characters with safe escape
  3014. // sequences.
  3015. escapable.lastIndex = 0;
  3016. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  3017. var c = meta[a];
  3018. return typeof c === 'string' ? c :
  3019. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  3020. }) + '"' : '"' + string + '"';
  3021. }
  3022. function str(key, holder) {
  3023. // Produce a string from holder[key].
  3024. var i, // The loop counter.
  3025. k, // The member key.
  3026. v, // The member value.
  3027. length,
  3028. mind = gap,
  3029. partial,
  3030. value = holder[key];
  3031. // If the value has a toJSON method, call it to obtain a replacement value.
  3032. if (value && typeof value === 'object' &&
  3033. typeof value.toJSON === 'function') {
  3034. value = value.toJSON(key);
  3035. }
  3036. // If we were called with a replacer function, then call the replacer to
  3037. // obtain a replacement value.
  3038. if (typeof rep === 'function') {
  3039. value = rep.call(holder, key, value);
  3040. }
  3041. // What happens next depends on the value's type.
  3042. switch (typeof value) {
  3043. case 'string':
  3044. return quote(value);
  3045. case 'number':
  3046. // JSON numbers must be finite. Encode non-finite numbers as null.
  3047. return isFinite(value) ? String(value) : 'null';
  3048. case 'boolean':
  3049. case 'null':
  3050. // If the value is a boolean or null, convert it to a string. Note:
  3051. // typeof null does not produce 'null'. The case is included here in
  3052. // the remote chance that this gets fixed someday.
  3053. return String(value);
  3054. case 'object':
  3055. if (!value) return 'null';
  3056. gap += indent;
  3057. partial = [];
  3058. // Array.isArray
  3059. if (Object.prototype.toString.apply(value) === '[object Array]') {
  3060. length = value.length;
  3061. for (i = 0; i < length; i += 1) {
  3062. partial[i] = str(i, value) || 'null';
  3063. }
  3064. // Join all of the elements together, separated with commas, and
  3065. // wrap them in brackets.
  3066. v = partial.length === 0 ? '[]' : gap ?
  3067. '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
  3068. '[' + partial.join(',') + ']';
  3069. gap = mind;
  3070. return v;
  3071. }
  3072. // If the replacer is an array, use it to select the members to be
  3073. // stringified.
  3074. if (rep && typeof rep === 'object') {
  3075. length = rep.length;
  3076. for (i = 0; i < length; i += 1) {
  3077. k = rep[i];
  3078. if (typeof k === 'string') {
  3079. v = str(k, value);
  3080. if (v) {
  3081. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  3082. }
  3083. }
  3084. }
  3085. }
  3086. else {
  3087. // Otherwise, iterate through all of the keys in the object.
  3088. for (k in value) {
  3089. if (Object.prototype.hasOwnProperty.call(value, k)) {
  3090. v = str(k, value);
  3091. if (v) {
  3092. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  3093. }
  3094. }
  3095. }
  3096. }
  3097. // Join all of the member texts together, separated with commas,
  3098. // and wrap them in braces.
  3099. v = partial.length === 0 ? '{}' : gap ?
  3100. '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
  3101. '{' + partial.join(',') + '}';
  3102. gap = mind;
  3103. return v;
  3104. }
  3105. }
  3106. module.exports = function (value, replacer, space) {
  3107. var i;
  3108. gap = '';
  3109. indent = '';
  3110. // If the space parameter is a number, make an indent string containing that
  3111. // many spaces.
  3112. if (typeof space === 'number') {
  3113. for (i = 0; i < space; i += 1) {
  3114. indent += ' ';
  3115. }
  3116. }
  3117. // If the space parameter is a string, it will be used as the indent string.
  3118. else if (typeof space === 'string') {
  3119. indent = space;
  3120. }
  3121. // If there is a replacer, it must be a function or an array.
  3122. // Otherwise, throw an error.
  3123. rep = replacer;
  3124. if (replacer && typeof replacer !== 'function'
  3125. && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  3126. throw new Error('JSON.stringify');
  3127. }
  3128. // Make a fake root object containing our value under the key of ''.
  3129. // Return the result of stringifying the value.
  3130. return str('', {'': value});
  3131. };
  3132. /***/ },
  3133. /* 16 */
  3134. /***/ function(module, exports, __webpack_require__) {
  3135. 'use strict';
  3136. var util = __webpack_require__(11);
  3137. module.exports = SchemaObject;
  3138. function SchemaObject(obj) {
  3139. util.copy(obj, this);
  3140. }
  3141. /***/ },
  3142. /* 17 */
  3143. /***/ function(module, exports, __webpack_require__) {
  3144. 'use strict';
  3145. module.exports = {
  3146. setup: setupAsync,
  3147. compile: compileAsync
  3148. };
  3149. var util = __webpack_require__(11);
  3150. var ASYNC = {
  3151. '*': checkGenerators,
  3152. 'co*': checkGenerators,
  3153. 'es7': checkAsyncFunction
  3154. };
  3155. var TRANSPILE = {
  3156. 'nodent': getNodent,
  3157. 'regenerator': getRegenerator
  3158. };
  3159. var MODES = [
  3160. { async: 'co*' },
  3161. { async: 'es7', transpile: 'nodent' },
  3162. { async: 'co*', transpile: 'regenerator' }
  3163. ];
  3164. var regenerator, nodent;
  3165. function setupAsync(opts, required) {
  3166. if (required !== false) required = true;
  3167. var async = opts.async
  3168. , transpile = opts.transpile
  3169. , check;
  3170. switch (typeof transpile) {
  3171. case 'string':
  3172. var get = TRANSPILE[transpile];
  3173. if (!get) throw new Error('bad transpiler: ' + transpile);
  3174. return (opts._transpileFunc = get(opts, required));
  3175. case 'undefined':
  3176. case 'boolean':
  3177. if (typeof async == 'string') {
  3178. check = ASYNC[async];
  3179. if (!check) throw new Error('bad async mode: ' + async);
  3180. return (opts.transpile = check(opts, required));
  3181. }
  3182. for (var i=0; i<MODES.length; i++) {
  3183. var _opts = MODES[i];
  3184. if (setupAsync(_opts, false)) {
  3185. util.copy(_opts, opts);
  3186. return opts.transpile;
  3187. }
  3188. }
  3189. /* istanbul ignore next */
  3190. throw new Error('generators, nodent and regenerator are not available');
  3191. case 'function':
  3192. return (opts._transpileFunc = opts.transpile);
  3193. default:
  3194. throw new Error('bad transpiler: ' + transpile);
  3195. }
  3196. }
  3197. function checkGenerators(opts, required) {
  3198. /* jshint evil: true */
  3199. try {
  3200. eval('(function*(){})()');
  3201. return true;
  3202. } catch(e) {
  3203. /* istanbul ignore next */
  3204. if (required) throw new Error('generators not supported');
  3205. }
  3206. }
  3207. function checkAsyncFunction(opts, required) {
  3208. /* jshint evil: true */
  3209. try {
  3210. eval('(async function(){})()');
  3211. /* istanbul ignore next */
  3212. return true;
  3213. } catch(e) {
  3214. if (required) throw new Error('es7 async functions not supported');
  3215. }
  3216. }
  3217. function getRegenerator(opts, required) {
  3218. try {
  3219. if (!regenerator) {
  3220. regenerator = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"regenerator\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
  3221. regenerator.runtime();
  3222. }
  3223. if (!opts.async || opts.async === true)
  3224. opts.async = 'es7';
  3225. return regeneratorTranspile;
  3226. } catch(e) {
  3227. /* istanbul ignore next */
  3228. if (required) throw new Error('regenerator not available');
  3229. }
  3230. }
  3231. function regeneratorTranspile(code) {
  3232. return regenerator.compile(code).code;
  3233. }
  3234. function getNodent(opts, required) {
  3235. /* jshint evil: true */
  3236. try {
  3237. if (!nodent) nodent = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"nodent\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()))({ log: false, dontInstallRequireHook: true });
  3238. if (opts.async != 'es7') {
  3239. if (opts.async && opts.async !== true) console.warn('nodent transpiles only es7 async functions');
  3240. opts.async = 'es7';
  3241. }
  3242. return nodentTranspile;
  3243. } catch(e) {
  3244. /* istanbul ignore next */
  3245. if (required) throw new Error('nodent not available');
  3246. }
  3247. }
  3248. function nodentTranspile(code) {
  3249. return nodent.compile(code, '', { promises: true, sourcemap: false }).code;
  3250. }
  3251. /**
  3252. * Creates validating function for passed schema with asynchronous loading of missing schemas.
  3253. * `loadSchema` option should be a function that accepts schema uri and node-style callback.
  3254. * @this Ajv
  3255. * @param {Object} schema schema object
  3256. * @param {Function} callback node-style callback, it is always called with 2 parameters: error (or null) and validating function.
  3257. */
  3258. function compileAsync(schema, callback) {
  3259. /* eslint no-shadow: 0 */
  3260. /* jshint validthis: true */
  3261. var schemaObj;
  3262. var self = this;
  3263. try {
  3264. schemaObj = this._addSchema(schema);
  3265. } catch(e) {
  3266. setTimeout(function() { callback(e); });
  3267. return;
  3268. }
  3269. if (schemaObj.validate) {
  3270. setTimeout(function() { callback(null, schemaObj.validate); });
  3271. } else {
  3272. if (typeof this._opts.loadSchema != 'function')
  3273. throw new Error('options.loadSchema should be a function');
  3274. _compileAsync(schema, callback, true);
  3275. }
  3276. function _compileAsync(schema, callback, firstCall) {
  3277. var validate;
  3278. try { validate = self.compile(schema); }
  3279. catch(e) {
  3280. if (e.missingSchema) loadMissingSchema(e);
  3281. else deferCallback(e);
  3282. return;
  3283. }
  3284. deferCallback(null, validate);
  3285. function loadMissingSchema(e) {
  3286. var ref = e.missingSchema;
  3287. if (self._refs[ref] || self._schemas[ref])
  3288. return callback(new Error('Schema ' + ref + ' is loaded but' + e.missingRef + 'cannot be resolved'));
  3289. var _callbacks = self._loadingSchemas[ref];
  3290. if (_callbacks) {
  3291. if (typeof _callbacks == 'function')
  3292. self._loadingSchemas[ref] = [_callbacks, schemaLoaded];
  3293. else
  3294. _callbacks[_callbacks.length] = schemaLoaded;
  3295. } else {
  3296. self._loadingSchemas[ref] = schemaLoaded;
  3297. self._opts.loadSchema(ref, function (err, sch) {
  3298. var _callbacks = self._loadingSchemas[ref];
  3299. delete self._loadingSchemas[ref];
  3300. if (typeof _callbacks == 'function') {
  3301. _callbacks(err, sch);
  3302. } else {
  3303. for (var i=0; i<_callbacks.length; i++)
  3304. _callbacks[i](err, sch);
  3305. }
  3306. });
  3307. }
  3308. function schemaLoaded(err, sch) {
  3309. if (err) return callback(err);
  3310. if (!(self._refs[ref] || self._schemas[ref])) {
  3311. try {
  3312. self.addSchema(sch, ref);
  3313. } catch(e) {
  3314. callback(e);
  3315. return;
  3316. }
  3317. }
  3318. _compileAsync(schema, callback);
  3319. }
  3320. }
  3321. function deferCallback(err, validate) {
  3322. if (firstCall) setTimeout(function() { callback(err, validate); });
  3323. else return callback(err, validate);
  3324. }
  3325. }
  3326. }
  3327. /***/ },
  3328. /* 18 */
  3329. /***/ function(module, exports) {
  3330. 'use strict';
  3331. module.exports = function generate_validate(it, $keyword) {
  3332. var out = '';
  3333. var $async = it.schema.$async === true;
  3334. if (it.isTop) {
  3335. var $top = it.isTop,
  3336. $lvl = it.level = 0,
  3337. $dataLvl = it.dataLevel = 0,
  3338. $data = 'data';
  3339. it.rootId = it.resolve.fullPath(it.root.schema.id);
  3340. it.baseId = it.baseId || it.rootId;
  3341. if ($async) {
  3342. it.async = true;
  3343. var $es7 = it.opts.async == 'es7';
  3344. it.yieldAwait = $es7 ? 'await' : 'yield';
  3345. }
  3346. delete it.isTop;
  3347. it.dataPathArr = [undefined];
  3348. out += ' validate = ';
  3349. if ($async) {
  3350. if ($es7) {
  3351. out += ' (async function ';
  3352. } else {
  3353. if (it.opts.async == 'co*') {
  3354. out += 'co.wrap';
  3355. }
  3356. out += '(function* ';
  3357. }
  3358. } else {
  3359. out += ' (function ';
  3360. }
  3361. out += ' (data, dataPath, parentData, parentDataProperty) { \'use strict\'; var vErrors = null; ';
  3362. out += ' var errors = 0; ';
  3363. } else {
  3364. var $lvl = it.level,
  3365. $dataLvl = it.dataLevel,
  3366. $data = 'data' + ($dataLvl || '');
  3367. if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id);
  3368. if ($async && !it.async) throw new Error('async schema in sync schema');
  3369. out += ' var errs_' + ($lvl) + ' = errors;';
  3370. }
  3371. var $valid = 'valid' + $lvl,
  3372. $breakOnError = !it.opts.allErrors,
  3373. $closingBraces1 = '',
  3374. $closingBraces2 = '',
  3375. $errorKeyword;
  3376. var $typeSchema = it.schema.type,
  3377. $typeIsArray = Array.isArray($typeSchema);
  3378. if ($typeSchema && it.opts.coerceTypes) {
  3379. var $coerceToTypes = it.util.coerceToTypes($typeSchema);
  3380. if ($coerceToTypes) {
  3381. var $schemaPath = it.schemaPath + '.type',
  3382. $errSchemaPath = it.errSchemaPath + '/type',
  3383. $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
  3384. out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
  3385. var $dataType = 'dataType' + $lvl,
  3386. $coerced = 'coerced' + $lvl;
  3387. out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; var ' + ($coerced) + ' = undefined; ';
  3388. var $bracesCoercion = '';
  3389. var arr1 = $coerceToTypes;
  3390. if (arr1) {
  3391. var $type, $i = -1,
  3392. l1 = arr1.length - 1;
  3393. while ($i < l1) {
  3394. $type = arr1[$i += 1];
  3395. if ($i) {
  3396. out += ' if (' + ($coerced) + ' === undefined) { ';
  3397. $bracesCoercion += '}';
  3398. }
  3399. if ($type == 'string') {
  3400. out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
  3401. } else if ($type == 'number' || $type == 'integer') {
  3402. out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
  3403. if ($type == 'integer') {
  3404. out += ' && !(' + ($data) + ' % 1)';
  3405. }
  3406. out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
  3407. } else if ($type == 'boolean') {
  3408. out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
  3409. } else if ($type == 'null') {
  3410. out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
  3411. }
  3412. }
  3413. }
  3414. out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
  3415. var $$outStack = $$outStack || [];
  3416. $$outStack.push(out);
  3417. out = ''; /* istanbul ignore else */
  3418. if (it.createErrors !== false) {
  3419. out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \'';
  3420. if ($typeIsArray) {
  3421. out += '' + ($typeSchema.join(","));
  3422. } else {
  3423. out += '' + ($typeSchema);
  3424. }
  3425. out += '\' } ';
  3426. if (it.opts.messages !== false) {
  3427. out += ' , message: \'should be ';
  3428. if ($typeIsArray) {
  3429. out += '' + ($typeSchema.join(","));
  3430. } else {
  3431. out += '' + ($typeSchema);
  3432. }
  3433. out += '\' ';
  3434. }
  3435. if (it.opts.verbose) {
  3436. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3437. }
  3438. out += ' } ';
  3439. } else {
  3440. out += ' {} ';
  3441. }
  3442. var __err = out;
  3443. out = $$outStack.pop();
  3444. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3445. if (it.async) {
  3446. out += ' throw new ValidationError([' + (__err) + ']); ';
  3447. } else {
  3448. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3449. }
  3450. } else {
  3451. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3452. }
  3453. out += ' } else { ';
  3454. if ($dataLvl) {
  3455. var $parentData = 'data' + (($dataLvl - 1) || ''),
  3456. $dataProperty = it.dataPathArr[$dataLvl];
  3457. out += ' ' + ($data) + ' = ' + ($parentData) + '[' + ($dataProperty) + '] = ' + ($coerced) + '; ';
  3458. } else {
  3459. out += ' data = ' + ($coerced) + '; if (parentData !== undefined) parentData[parentDataProperty] = ' + ($coerced) + '; ';
  3460. }
  3461. out += ' } } ';
  3462. }
  3463. }
  3464. var arr2 = it.RULES;
  3465. if (arr2) {
  3466. var $rulesGroup, i2 = -1,
  3467. l2 = arr2.length - 1;
  3468. while (i2 < l2) {
  3469. $rulesGroup = arr2[i2 += 1];
  3470. if ($shouldUseGroup($rulesGroup)) {
  3471. if ($rulesGroup.type) {
  3472. out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
  3473. }
  3474. if (it.opts.useDefaults && !it.compositeRule) {
  3475. if ($rulesGroup.type == 'object' && it.schema.properties) {
  3476. var $schema = it.schema.properties,
  3477. $schemaKeys = Object.keys($schema);
  3478. var arr3 = $schemaKeys;
  3479. if (arr3) {
  3480. var $propertyKey, i3 = -1,
  3481. l3 = arr3.length - 1;
  3482. while (i3 < l3) {
  3483. $propertyKey = arr3[i3 += 1];
  3484. var $sch = $schema[$propertyKey];
  3485. if ($sch.default !== undefined) {
  3486. var $passData = $data + it.util.getProperty($propertyKey);
  3487. out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
  3488. if (it.opts.useDefaults == 'clone') {
  3489. out += ' ' + (JSON.stringify($sch.default)) + ' ';
  3490. } else {
  3491. out += ' ' + (it.useDefault($sch.default)) + ' ';
  3492. }
  3493. out += '; ';
  3494. }
  3495. }
  3496. }
  3497. } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
  3498. var arr4 = it.schema.items;
  3499. if (arr4) {
  3500. var $sch, $i = -1,
  3501. l4 = arr4.length - 1;
  3502. while ($i < l4) {
  3503. $sch = arr4[$i += 1];
  3504. if ($sch.default !== undefined) {
  3505. var $passData = $data + '[' + $i + ']';
  3506. out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
  3507. if (it.opts.useDefaults == 'clone') {
  3508. out += ' ' + (JSON.stringify($sch.default)) + ' ';
  3509. } else {
  3510. out += ' ' + (it.useDefault($sch.default)) + ' ';
  3511. }
  3512. out += '; ';
  3513. }
  3514. }
  3515. }
  3516. }
  3517. }
  3518. var arr5 = $rulesGroup.rules;
  3519. if (arr5) {
  3520. var $rule, i5 = -1,
  3521. l5 = arr5.length - 1;
  3522. while (i5 < l5) {
  3523. $rule = arr5[i5 += 1];
  3524. if ($shouldUseRule($rule)) {
  3525. if ($rule.custom) {
  3526. var $schema = it.schema[$rule.keyword],
  3527. $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it),
  3528. $ruleErrs = $ruleValidate.code + '.errors',
  3529. $schemaPath = it.schemaPath + '.' + $rule.keyword,
  3530. $errSchemaPath = it.errSchemaPath + '/' + $rule.keyword,
  3531. $errs = 'errs' + $lvl,
  3532. $i = 'i' + $lvl,
  3533. $ruleErr = 'ruleErr' + $lvl,
  3534. $rDef = $rule.definition,
  3535. $asyncKeyword = $rDef.async,
  3536. $inline = $rDef.inline,
  3537. $macro = $rDef.macro;
  3538. if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
  3539. if (!($inline || $macro)) {
  3540. out += '' + ($ruleErrs) + ' = null;';
  3541. }
  3542. out += 'var ' + ($errs) + ' = errors;var valid' + ($lvl) + ';';
  3543. if ($inline && $rDef.statements) {
  3544. out += ' ' + ($ruleValidate.validate);
  3545. } else if ($macro) {
  3546. var $it = it.util.copy(it);
  3547. $it.level++;
  3548. $it.schema = $ruleValidate.validate;
  3549. $it.schemaPath = '';
  3550. var $wasComposite = it.compositeRule;
  3551. it.compositeRule = $it.compositeRule = true;
  3552. var $code = it.validate($it).replace(/validate\.schema/g, $ruleValidate.code);
  3553. it.compositeRule = $it.compositeRule = $wasComposite;
  3554. out += ' ' + ($code);
  3555. } else if ($rDef.compile || $rDef.validate) {
  3556. var $$outStack = $$outStack || [];
  3557. $$outStack.push(out);
  3558. out = '';
  3559. out += ' ' + ($ruleValidate.code) + '.call( ';
  3560. if (it.opts.passContext) {
  3561. out += 'this';
  3562. } else {
  3563. out += 'self';
  3564. }
  3565. var $validateArgs = $ruleValidate.validate.length;
  3566. if ($rDef.compile || $rDef.schema === false) {
  3567. out += ' , ' + ($data) + ' ';
  3568. } else {
  3569. out += ' , validate.schema' + ($schemaPath) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
  3570. }
  3571. out += ' , (dataPath || \'\')';
  3572. if (it.errorPath != '""') {
  3573. out += ' + ' + (it.errorPath);
  3574. }
  3575. if ($dataLvl) {
  3576. out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' ';
  3577. } else {
  3578. out += ' , parentData , parentDataProperty ';
  3579. }
  3580. out += ' ) ';
  3581. var def_callRuleValidate = out;
  3582. out = $$outStack.pop();
  3583. if ($rDef.errors !== false) {
  3584. if ($asyncKeyword) {
  3585. $ruleErrs = 'customErrors' + $lvl;
  3586. out += ' var ' + ($ruleErrs) + ' = null; try { valid' + ($lvl) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { valid' + ($lvl) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
  3587. } else {
  3588. out += ' ' + ($ruleValidate.code) + '.errors = null; ';
  3589. }
  3590. }
  3591. }
  3592. out += 'if (! ';
  3593. if ($inline) {
  3594. if ($rDef.statements) {
  3595. out += ' valid' + ($lvl) + ' ';
  3596. } else {
  3597. out += ' (' + ($ruleValidate.validate) + ') ';
  3598. }
  3599. } else if ($macro) {
  3600. out += ' valid' + ($it.level) + ' ';
  3601. } else {
  3602. if ($asyncKeyword) {
  3603. if ($rDef.errors === false) {
  3604. out += ' (' + (it.yieldAwait) + (def_callRuleValidate) + ') ';
  3605. } else {
  3606. out += ' valid' + ($lvl) + ' ';
  3607. }
  3608. } else {
  3609. out += ' ' + (def_callRuleValidate) + ' ';
  3610. }
  3611. }
  3612. out += ') { ';
  3613. $errorKeyword = $rule.keyword;
  3614. var $$outStack = $$outStack || [];
  3615. $$outStack.push(out);
  3616. out = '';
  3617. var $$outStack = $$outStack || [];
  3618. $$outStack.push(out);
  3619. out = ''; /* istanbul ignore else */
  3620. if (it.createErrors !== false) {
  3621. out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { keyword: \'' + ($rule.keyword) + '\' } ';
  3622. if (it.opts.messages !== false) {
  3623. out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
  3624. }
  3625. if (it.opts.verbose) {
  3626. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3627. }
  3628. out += ' } ';
  3629. } else {
  3630. out += ' {} ';
  3631. }
  3632. var __err = out;
  3633. out = $$outStack.pop();
  3634. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3635. if (it.async) {
  3636. out += ' throw new ValidationError([' + (__err) + ']); ';
  3637. } else {
  3638. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3639. }
  3640. } else {
  3641. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3642. }
  3643. var def_customError = out;
  3644. out = $$outStack.pop();
  3645. if ($inline) {
  3646. if ($rDef.errors) {
  3647. if ($rDef.errors != 'full') {
  3648. out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) { ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; } if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
  3649. if (it.opts.verbose) {
  3650. out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  3651. }
  3652. out += ' } ';
  3653. }
  3654. } else {
  3655. if ($rDef.errors === false) {
  3656. out += ' ' + (def_customError) + ' ';
  3657. } else {
  3658. out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) { ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; } if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
  3659. if (it.opts.verbose) {
  3660. out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  3661. }
  3662. out += ' } } ';
  3663. }
  3664. }
  3665. } else if ($macro) {
  3666. out += ' var err = '; /* istanbul ignore else */
  3667. if (it.createErrors !== false) {
  3668. out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { keyword: \'' + ($rule.keyword) + '\' } ';
  3669. if (it.opts.messages !== false) {
  3670. out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
  3671. }
  3672. if (it.opts.verbose) {
  3673. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3674. }
  3675. out += ' } ';
  3676. } else {
  3677. out += ' {} ';
  3678. }
  3679. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3680. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3681. if (it.async) {
  3682. out += ' throw new ValidationError(vErrors); ';
  3683. } else {
  3684. out += ' validate.errors = vErrors; return false ';
  3685. }
  3686. }
  3687. } else {
  3688. if ($rDef.errors === false) {
  3689. out += ' ' + (def_customError) + ' ';
  3690. } else {
  3691. out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
  3692. if (it.opts.verbose) {
  3693. out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  3694. }
  3695. out += ' } } else { ' + (def_customError) + ' } ';
  3696. }
  3697. }
  3698. $errorKeyword = undefined;
  3699. out += ' } ';
  3700. if ($breakOnError) {
  3701. out += ' else { ';
  3702. }
  3703. } else {
  3704. out += ' ' + ($rule.code(it, $rule.keyword)) + ' ';
  3705. }
  3706. if ($breakOnError) {
  3707. $closingBraces1 += '}';
  3708. }
  3709. }
  3710. }
  3711. }
  3712. if ($breakOnError) {
  3713. out += ' ' + ($closingBraces1) + ' ';
  3714. $closingBraces1 = '';
  3715. }
  3716. if ($rulesGroup.type) {
  3717. out += ' } ';
  3718. if ($typeSchema && $typeSchema === $rulesGroup.type) {
  3719. var $typeChecked = true;
  3720. out += ' else { ';
  3721. var $schemaPath = it.schemaPath + '.type',
  3722. $errSchemaPath = it.errSchemaPath + '/type';
  3723. var $$outStack = $$outStack || [];
  3724. $$outStack.push(out);
  3725. out = ''; /* istanbul ignore else */
  3726. if (it.createErrors !== false) {
  3727. out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \'';
  3728. if ($typeIsArray) {
  3729. out += '' + ($typeSchema.join(","));
  3730. } else {
  3731. out += '' + ($typeSchema);
  3732. }
  3733. out += '\' } ';
  3734. if (it.opts.messages !== false) {
  3735. out += ' , message: \'should be ';
  3736. if ($typeIsArray) {
  3737. out += '' + ($typeSchema.join(","));
  3738. } else {
  3739. out += '' + ($typeSchema);
  3740. }
  3741. out += '\' ';
  3742. }
  3743. if (it.opts.verbose) {
  3744. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3745. }
  3746. out += ' } ';
  3747. } else {
  3748. out += ' {} ';
  3749. }
  3750. var __err = out;
  3751. out = $$outStack.pop();
  3752. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3753. if (it.async) {
  3754. out += ' throw new ValidationError([' + (__err) + ']); ';
  3755. } else {
  3756. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3757. }
  3758. } else {
  3759. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3760. }
  3761. out += ' } ';
  3762. }
  3763. }
  3764. if ($breakOnError) {
  3765. out += ' if (errors === ';
  3766. if ($top) {
  3767. out += '0';
  3768. } else {
  3769. out += 'errs_' + ($lvl);
  3770. }
  3771. out += ') { ';
  3772. $closingBraces2 += '}';
  3773. }
  3774. }
  3775. }
  3776. }
  3777. if ($typeSchema && !$typeChecked && !(it.opts.coerceTypes && $coerceToTypes)) {
  3778. var $schemaPath = it.schemaPath + '.type',
  3779. $errSchemaPath = it.errSchemaPath + '/type',
  3780. $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
  3781. out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
  3782. var $$outStack = $$outStack || [];
  3783. $$outStack.push(out);
  3784. out = ''; /* istanbul ignore else */
  3785. if (it.createErrors !== false) {
  3786. out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \'';
  3787. if ($typeIsArray) {
  3788. out += '' + ($typeSchema.join(","));
  3789. } else {
  3790. out += '' + ($typeSchema);
  3791. }
  3792. out += '\' } ';
  3793. if (it.opts.messages !== false) {
  3794. out += ' , message: \'should be ';
  3795. if ($typeIsArray) {
  3796. out += '' + ($typeSchema.join(","));
  3797. } else {
  3798. out += '' + ($typeSchema);
  3799. }
  3800. out += '\' ';
  3801. }
  3802. if (it.opts.verbose) {
  3803. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3804. }
  3805. out += ' } ';
  3806. } else {
  3807. out += ' {} ';
  3808. }
  3809. var __err = out;
  3810. out = $$outStack.pop();
  3811. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3812. if (it.async) {
  3813. out += ' throw new ValidationError([' + (__err) + ']); ';
  3814. } else {
  3815. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3816. }
  3817. } else {
  3818. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3819. }
  3820. out += ' }';
  3821. }
  3822. if ($breakOnError) {
  3823. out += ' ' + ($closingBraces2) + ' ';
  3824. }
  3825. if ($top) {
  3826. if ($async) {
  3827. out += ' if (errors === 0) return true; ';
  3828. out += ' else throw new ValidationError(vErrors); ';
  3829. } else {
  3830. out += ' validate.errors = vErrors; ';
  3831. out += ' return errors === 0; ';
  3832. }
  3833. out += ' });';
  3834. } else {
  3835. out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
  3836. }
  3837. out = it.util.cleanUpCode(out);
  3838. if ($top && $breakOnError) {
  3839. out = it.util.cleanUpVarErrors(out, $async);
  3840. }
  3841. function $shouldUseGroup($rulesGroup) {
  3842. for (var i = 0; i < $rulesGroup.rules.length; i++)
  3843. if ($shouldUseRule($rulesGroup.rules[i])) return true;
  3844. }
  3845. function $shouldUseRule($rule) {
  3846. return it.schema[$rule.keyword] !== undefined || ($rule.keyword == 'properties' && (it.schema.additionalProperties === false || typeof it.schema.additionalProperties == 'object' || (it.schema.patternProperties && Object.keys(it.schema.patternProperties).length) || (it.opts.v5 && it.schema.patternGroups && Object.keys(it.schema.patternGroups).length)));
  3847. }
  3848. return out;
  3849. }
  3850. /***/ },
  3851. /* 19 */
  3852. /***/ function(module, exports) {
  3853. /**
  3854. * slice() reference.
  3855. */
  3856. var slice = Array.prototype.slice;
  3857. /**
  3858. * Expose `co`.
  3859. */
  3860. module.exports = co['default'] = co.co = co;
  3861. /**
  3862. * Wrap the given generator `fn` into a
  3863. * function that returns a promise.
  3864. * This is a separate function so that
  3865. * every `co()` call doesn't create a new,
  3866. * unnecessary closure.
  3867. *
  3868. * @param {GeneratorFunction} fn
  3869. * @return {Function}
  3870. * @api public
  3871. */
  3872. co.wrap = function (fn) {
  3873. createPromise.__generatorFunction__ = fn;
  3874. return createPromise;
  3875. function createPromise() {
  3876. return co.call(this, fn.apply(this, arguments));
  3877. }
  3878. };
  3879. /**
  3880. * Execute the generator function or a generator
  3881. * and return a promise.
  3882. *
  3883. * @param {Function} fn
  3884. * @return {Promise}
  3885. * @api public
  3886. */
  3887. function co(gen) {
  3888. var ctx = this;
  3889. var args = slice.call(arguments, 1)
  3890. // we wrap everything in a promise to avoid promise chaining,
  3891. // which leads to memory leak errors.
  3892. // see https://github.com/tj/co/issues/180
  3893. return new Promise(function(resolve, reject) {
  3894. if (typeof gen === 'function') gen = gen.apply(ctx, args);
  3895. if (!gen || typeof gen.next !== 'function') return resolve(gen);
  3896. onFulfilled();
  3897. /**
  3898. * @param {Mixed} res
  3899. * @return {Promise}
  3900. * @api private
  3901. */
  3902. function onFulfilled(res) {
  3903. var ret;
  3904. try {
  3905. ret = gen.next(res);
  3906. } catch (e) {
  3907. return reject(e);
  3908. }
  3909. next(ret);
  3910. }
  3911. /**
  3912. * @param {Error} err
  3913. * @return {Promise}
  3914. * @api private
  3915. */
  3916. function onRejected(err) {
  3917. var ret;
  3918. try {
  3919. ret = gen.throw(err);
  3920. } catch (e) {
  3921. return reject(e);
  3922. }
  3923. next(ret);
  3924. }
  3925. /**
  3926. * Get the next value in the generator,
  3927. * return a promise.
  3928. *
  3929. * @param {Object} ret
  3930. * @return {Promise}
  3931. * @api private
  3932. */
  3933. function next(ret) {
  3934. if (ret.done) return resolve(ret.value);
  3935. var value = toPromise.call(ctx, ret.value);
  3936. if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
  3937. return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
  3938. + 'but the following object was passed: "' + String(ret.value) + '"'));
  3939. }
  3940. });
  3941. }
  3942. /**
  3943. * Convert a `yield`ed value into a promise.
  3944. *
  3945. * @param {Mixed} obj
  3946. * @return {Promise}
  3947. * @api private
  3948. */
  3949. function toPromise(obj) {
  3950. if (!obj) return obj;
  3951. if (isPromise(obj)) return obj;
  3952. if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
  3953. if ('function' == typeof obj) return thunkToPromise.call(this, obj);
  3954. if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
  3955. if (isObject(obj)) return objectToPromise.call(this, obj);
  3956. return obj;
  3957. }
  3958. /**
  3959. * Convert a thunk to a promise.
  3960. *
  3961. * @param {Function}
  3962. * @return {Promise}
  3963. * @api private
  3964. */
  3965. function thunkToPromise(fn) {
  3966. var ctx = this;
  3967. return new Promise(function (resolve, reject) {
  3968. fn.call(ctx, function (err, res) {
  3969. if (err) return reject(err);
  3970. if (arguments.length > 2) res = slice.call(arguments, 1);
  3971. resolve(res);
  3972. });
  3973. });
  3974. }
  3975. /**
  3976. * Convert an array of "yieldables" to a promise.
  3977. * Uses `Promise.all()` internally.
  3978. *
  3979. * @param {Array} obj
  3980. * @return {Promise}
  3981. * @api private
  3982. */
  3983. function arrayToPromise(obj) {
  3984. return Promise.all(obj.map(toPromise, this));
  3985. }
  3986. /**
  3987. * Convert an object of "yieldables" to a promise.
  3988. * Uses `Promise.all()` internally.
  3989. *
  3990. * @param {Object} obj
  3991. * @return {Promise}
  3992. * @api private
  3993. */
  3994. function objectToPromise(obj){
  3995. var results = new obj.constructor();
  3996. var keys = Object.keys(obj);
  3997. var promises = [];
  3998. for (var i = 0; i < keys.length; i++) {
  3999. var key = keys[i];
  4000. var promise = toPromise.call(this, obj[key]);
  4001. if (promise && isPromise(promise)) defer(promise, key);
  4002. else results[key] = obj[key];
  4003. }
  4004. return Promise.all(promises).then(function () {
  4005. return results;
  4006. });
  4007. function defer(promise, key) {
  4008. // predefine the key in the result
  4009. results[key] = undefined;
  4010. promises.push(promise.then(function (res) {
  4011. results[key] = res;
  4012. }));
  4013. }
  4014. }
  4015. /**
  4016. * Check if `obj` is a promise.
  4017. *
  4018. * @param {Object} obj
  4019. * @return {Boolean}
  4020. * @api private
  4021. */
  4022. function isPromise(obj) {
  4023. return 'function' == typeof obj.then;
  4024. }
  4025. /**
  4026. * Check if `obj` is a generator.
  4027. *
  4028. * @param {Mixed} obj
  4029. * @return {Boolean}
  4030. * @api private
  4031. */
  4032. function isGenerator(obj) {
  4033. return 'function' == typeof obj.next && 'function' == typeof obj.throw;
  4034. }
  4035. /**
  4036. * Check if `obj` is a generator function.
  4037. *
  4038. * @param {Mixed} obj
  4039. * @return {Boolean}
  4040. * @api private
  4041. */
  4042. function isGeneratorFunction(obj) {
  4043. var constructor = obj.constructor;
  4044. if (!constructor) return false;
  4045. if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true;
  4046. return isGenerator(constructor.prototype);
  4047. }
  4048. /**
  4049. * Check for plain object.
  4050. *
  4051. * @param {Mixed} val
  4052. * @return {Boolean}
  4053. * @api private
  4054. */
  4055. function isObject(val) {
  4056. return Object == val.constructor;
  4057. }
  4058. /***/ },
  4059. /* 20 */
  4060. /***/ function(module, exports) {
  4061. 'use strict';
  4062. module.exports = ValidationError;
  4063. function ValidationError(errors) {
  4064. this.message = 'validation failed';
  4065. this.errors = errors;
  4066. this.ajv = this.validation = true;
  4067. }
  4068. ValidationError.prototype = Object.create(Error.prototype);
  4069. ValidationError.prototype.constructor = ValidationError;
  4070. /***/ },
  4071. /* 21 */
  4072. /***/ function(module, exports) {
  4073. 'use strict';
  4074. var Cache = module.exports = function Cache() {
  4075. this._cache = {};
  4076. };
  4077. Cache.prototype.put = function Cache_put(key, value) {
  4078. this._cache[key] = value;
  4079. };
  4080. Cache.prototype.get = function Cache_get(key) {
  4081. return this._cache[key];
  4082. };
  4083. Cache.prototype.del = function Cache_del(key) {
  4084. delete this._cache[key];
  4085. };
  4086. Cache.prototype.clear = function Cache_clear() {
  4087. this._cache = {};
  4088. };
  4089. /***/ },
  4090. /* 22 */
  4091. /***/ function(module, exports, __webpack_require__) {
  4092. 'use strict';
  4093. var util = __webpack_require__(11);
  4094. var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/;
  4095. var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31];
  4096. var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i;
  4097. var HOSTNAME = /^[a-z](?:(?:[-0-9a-z]{0,61})?[0-9a-z])?(\.[a-z](?:(?:[-0-9a-z]{0,61})?[0-9a-z])?)*$/i;
  4098. var URI = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9a-f]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9a-f]{2})*)?$/i;
  4099. var UUID = /^(?:urn\:uuid\:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
  4100. var JSON_POINTER = /^(?:\/(?:[^~\/]|~0|~1)+)*(?:\/)?$|^\#(?:\/(?:[a-z0-9_\-\.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)+)*(?:\/)?$/i;
  4101. var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:\#|(?:\/(?:[^~\/]|~0|~1)+)*(?:\/)?)$/;
  4102. module.exports = formats;
  4103. function formats(mode) {
  4104. mode = mode == 'full' ? 'full' : 'fast';
  4105. var formatDefs = util.copy(formats[mode]);
  4106. for (var fName in formats.compare) {
  4107. formatDefs[fName] = {
  4108. validate: formatDefs[fName],
  4109. compare: formats.compare[fName]
  4110. };
  4111. }
  4112. return formatDefs;
  4113. }
  4114. formats.fast = {
  4115. // date: http://tools.ietf.org/html/rfc3339#section-5.6
  4116. date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
  4117. // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
  4118. time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i,
  4119. 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i,
  4120. // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
  4121. uri: /^(?:[a-z][a-z0-9+-.]*)?(?:\:|\/)\/?[^\s]*$/i,
  4122. // email (sources from jsen validator):
  4123. // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
  4124. // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
  4125. email: /^[a-z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
  4126. hostname: HOSTNAME,
  4127. // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
  4128. ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
  4129. // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
  4130. ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
  4131. regex: regex,
  4132. // uuid: http://tools.ietf.org/html/rfc4122
  4133. uuid: UUID,
  4134. // JSON-pointer: https://tools.ietf.org/html/rfc6901
  4135. // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
  4136. 'json-pointer': JSON_POINTER,
  4137. // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
  4138. 'relative-json-pointer': RELATIVE_JSON_POINTER
  4139. };
  4140. formats.full = {
  4141. date: date,
  4142. time: time,
  4143. 'date-time': date_time,
  4144. uri: uri,
  4145. email: /^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
  4146. hostname: hostname,
  4147. ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
  4148. ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
  4149. regex: regex,
  4150. uuid: UUID,
  4151. 'json-pointer': JSON_POINTER,
  4152. 'relative-json-pointer': RELATIVE_JSON_POINTER
  4153. };
  4154. formats.compare = {
  4155. date: compareDate,
  4156. time: compareTime,
  4157. 'date-time': compareDateTime
  4158. };
  4159. function date(str) {
  4160. // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
  4161. var matches = str.match(DATE);
  4162. if (!matches) return false;
  4163. var month = +matches[1];
  4164. var day = +matches[2];
  4165. return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month];
  4166. }
  4167. function time(str, full) {
  4168. var matches = str.match(TIME);
  4169. if (!matches) return false;
  4170. var hour = matches[1];
  4171. var minute = matches[2];
  4172. var second = matches[3];
  4173. var timeZone = matches[5];
  4174. return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone);
  4175. }
  4176. var DATE_TIME_SEPARATOR = /t|\s/i;
  4177. function date_time(str) {
  4178. // http://tools.ietf.org/html/rfc3339#section-5.6
  4179. var dateTime = str.split(DATE_TIME_SEPARATOR);
  4180. return date(dateTime[0]) && time(dateTime[1], true);
  4181. }
  4182. function hostname(str) {
  4183. // http://tools.ietf.org/html/rfc1034#section-3.5
  4184. return str.length <= 255 && HOSTNAME.test(str);
  4185. }
  4186. var NOT_URI_FRAGMENT = /\/|\:/;
  4187. function uri(str) {
  4188. // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
  4189. return NOT_URI_FRAGMENT.test(str) && URI.test(str);
  4190. }
  4191. function regex(str) {
  4192. try {
  4193. new RegExp(str);
  4194. return true;
  4195. } catch(e) {
  4196. return false;
  4197. }
  4198. }
  4199. function compareDate(d1, d2) {
  4200. if (!(d1 && d2)) return;
  4201. if (d1 > d2) return 1;
  4202. if (d1 < d2) return -1;
  4203. if (d1 === d2) return 0;
  4204. }
  4205. function compareTime(t1, t2) {
  4206. if (!(t1 && t2)) return;
  4207. t1 = t1.match(TIME);
  4208. t2 = t2.match(TIME);
  4209. if (!(t1 && t2)) return;
  4210. t1 = t1[1] + t1[2] + t1[3] + (t1[4]||'');
  4211. t2 = t2[1] + t2[2] + t2[3] + (t2[4]||'');
  4212. if (t1 > t2) return 1;
  4213. if (t1 < t2) return -1;
  4214. if (t1 === t2) return 0;
  4215. }
  4216. function compareDateTime(dt1, dt2) {
  4217. if (!(dt1 && dt2)) return;
  4218. dt1 = dt1.split(DATE_TIME_SEPARATOR);
  4219. dt2 = dt2.split(DATE_TIME_SEPARATOR);
  4220. var res = compareDate(dt1[0], dt2[0]);
  4221. if (res === undefined) return;
  4222. return res || compareTime(dt1[1], dt2[1]);
  4223. }
  4224. /***/ },
  4225. /* 23 */
  4226. /***/ function(module, exports, __webpack_require__) {
  4227. 'use strict';
  4228. var ruleModules = __webpack_require__(24)
  4229. , util = __webpack_require__(11);
  4230. module.exports = function rules() {
  4231. var RULES = [
  4232. { type: 'number',
  4233. rules: [ 'maximum', 'minimum', 'multipleOf'] },
  4234. { type: 'string',
  4235. rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
  4236. { type: 'array',
  4237. rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] },
  4238. { type: 'object',
  4239. rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] },
  4240. { rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
  4241. ];
  4242. RULES.all = [ 'type', 'additionalProperties', 'patternProperties' ];
  4243. RULES.keywords = [ 'additionalItems', '$schema', 'id', 'title', 'description', 'default' ];
  4244. RULES.types = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
  4245. RULES.forEach(function (group) {
  4246. group.rules = group.rules.map(function (keyword) {
  4247. RULES.all.push(keyword);
  4248. return {
  4249. keyword: keyword,
  4250. code: ruleModules[keyword]
  4251. };
  4252. });
  4253. });
  4254. RULES.keywords = util.toHash(RULES.all.concat(RULES.keywords));
  4255. RULES.all = util.toHash(RULES.all);
  4256. RULES.types = util.toHash(RULES.types);
  4257. return RULES;
  4258. };
  4259. /***/ },
  4260. /* 24 */
  4261. /***/ function(module, exports, __webpack_require__) {
  4262. 'use strict';
  4263. //all requires must be explicit because browserify won't work with dynamic requires
  4264. module.exports = {
  4265. '$ref': __webpack_require__(25),
  4266. allOf: __webpack_require__(26),
  4267. anyOf: __webpack_require__(27),
  4268. dependencies: __webpack_require__(28),
  4269. enum: __webpack_require__(29),
  4270. format: __webpack_require__(30),
  4271. items: __webpack_require__(31),
  4272. maximum: __webpack_require__(32),
  4273. minimum: __webpack_require__(32),
  4274. maxItems: __webpack_require__(33),
  4275. minItems: __webpack_require__(33),
  4276. maxLength: __webpack_require__(34),
  4277. minLength: __webpack_require__(34),
  4278. maxProperties: __webpack_require__(35),
  4279. minProperties: __webpack_require__(35),
  4280. multipleOf: __webpack_require__(36),
  4281. not: __webpack_require__(37),
  4282. oneOf: __webpack_require__(38),
  4283. pattern: __webpack_require__(39),
  4284. properties: __webpack_require__(40),
  4285. required: __webpack_require__(41),
  4286. uniqueItems: __webpack_require__(42),
  4287. validate: __webpack_require__(18)
  4288. };
  4289. /***/ },
  4290. /* 25 */
  4291. /***/ function(module, exports) {
  4292. 'use strict';
  4293. module.exports = function generate_ref(it, $keyword) {
  4294. var out = ' ';
  4295. var $lvl = it.level;
  4296. var $dataLvl = it.dataLevel;
  4297. var $schema = it.schema[$keyword];
  4298. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4299. var $breakOnError = !it.opts.allErrors;
  4300. var $errorKeyword;
  4301. var $data = 'data' + ($dataLvl || '');
  4302. var $valid = 'valid' + $lvl;
  4303. var $async, $refCode;
  4304. if ($schema == '#' || $schema == '#/') {
  4305. if (it.isRoot) {
  4306. $async = it.async;
  4307. $refCode = 'validate';
  4308. } else {
  4309. $async = it.root.schema.$async === true;
  4310. $refCode = 'root.refVal[0]';
  4311. }
  4312. } else {
  4313. var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
  4314. if ($refVal === undefined) {
  4315. var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId;
  4316. if (it.opts.missingRefs == 'fail') {
  4317. console.log($message);
  4318. var $$outStack = $$outStack || [];
  4319. $$outStack.push(out);
  4320. out = ''; /* istanbul ignore else */
  4321. if (it.createErrors !== false) {
  4322. out += ' { keyword: \'' + ($errorKeyword || '$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
  4323. if (it.opts.messages !== false) {
  4324. out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
  4325. }
  4326. if (it.opts.verbose) {
  4327. out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4328. }
  4329. out += ' } ';
  4330. } else {
  4331. out += ' {} ';
  4332. }
  4333. var __err = out;
  4334. out = $$outStack.pop();
  4335. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4336. if (it.async) {
  4337. out += ' throw new ValidationError([' + (__err) + ']); ';
  4338. } else {
  4339. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4340. }
  4341. } else {
  4342. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4343. }
  4344. if ($breakOnError) {
  4345. out += ' if (false) { ';
  4346. }
  4347. } else if (it.opts.missingRefs == 'ignore') {
  4348. console.log($message);
  4349. if ($breakOnError) {
  4350. out += ' if (true) { ';
  4351. }
  4352. } else {
  4353. var $error = new Error($message);
  4354. $error.missingRef = it.resolve.url(it.baseId, $schema);
  4355. $error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef));
  4356. throw $error;
  4357. }
  4358. } else if ($refVal.inline) {
  4359. var $it = it.util.copy(it);
  4360. $it.level++;
  4361. $it.schema = $refVal.schema;
  4362. $it.schemaPath = '';
  4363. $it.errSchemaPath = $schema;
  4364. var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
  4365. out += ' ' + ($code) + ' ';
  4366. if ($breakOnError) {
  4367. out += ' if (valid' + ($it.level) + ') { ';
  4368. }
  4369. } else {
  4370. $async = $refVal.async;
  4371. $refCode = $refVal.code;
  4372. }
  4373. }
  4374. if ($refCode) {
  4375. var $$outStack = $$outStack || [];
  4376. $$outStack.push(out);
  4377. out = '';
  4378. if (it.opts.passContext) {
  4379. out += ' ' + ($refCode) + '.call(this, ';
  4380. } else {
  4381. out += ' ' + ($refCode) + '( ';
  4382. }
  4383. out += ' ' + ($data) + ', (dataPath || \'\')';
  4384. if (it.errorPath != '""') {
  4385. out += ' + ' + (it.errorPath);
  4386. }
  4387. if ($dataLvl) {
  4388. out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' ';
  4389. } else {
  4390. out += ' , parentData , parentDataProperty ';
  4391. }
  4392. out += ') ';
  4393. var __callValidate = out;
  4394. out = $$outStack.pop();
  4395. if ($async) {
  4396. if (!it.async) throw new Error('async schema referenced by sync schema');
  4397. out += ' try { ';
  4398. if ($breakOnError) {
  4399. out += 'var ' + ($valid) + ' =';
  4400. }
  4401. out += ' ' + (it.yieldAwait) + ' ' + (__callValidate) + '; } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; } ';
  4402. if ($breakOnError) {
  4403. out += ' if (' + ($valid) + ') { ';
  4404. }
  4405. } else {
  4406. out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
  4407. if ($breakOnError) {
  4408. out += ' else { ';
  4409. }
  4410. }
  4411. }
  4412. return out;
  4413. }
  4414. /***/ },
  4415. /* 26 */
  4416. /***/ function(module, exports) {
  4417. 'use strict';
  4418. module.exports = function generate_allOf(it, $keyword) {
  4419. var out = ' ';
  4420. var $schema = it.schema[$keyword];
  4421. var $schemaPath = it.schemaPath + '.' + $keyword;
  4422. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4423. var $breakOnError = !it.opts.allErrors;
  4424. var $it = it.util.copy(it);
  4425. var $closingBraces = '';
  4426. $it.level++;
  4427. var arr1 = $schema;
  4428. if (arr1) {
  4429. var $sch, $i = -1,
  4430. l1 = arr1.length - 1;
  4431. while ($i < l1) {
  4432. $sch = arr1[$i += 1];
  4433. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  4434. $it.schema = $sch;
  4435. $it.schemaPath = $schemaPath + '[' + $i + ']';
  4436. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  4437. out += ' ' + (it.validate($it)) + ' ';
  4438. if ($breakOnError) {
  4439. out += ' if (valid' + ($it.level) + ') { ';
  4440. $closingBraces += '}';
  4441. }
  4442. }
  4443. }
  4444. }
  4445. if ($breakOnError) {
  4446. out += ' ' + ($closingBraces.slice(0, -1));
  4447. }
  4448. out = it.util.cleanUpCode(out);
  4449. return out;
  4450. }
  4451. /***/ },
  4452. /* 27 */
  4453. /***/ function(module, exports) {
  4454. 'use strict';
  4455. module.exports = function generate_anyOf(it, $keyword) {
  4456. var out = ' ';
  4457. var $lvl = it.level;
  4458. var $dataLvl = it.dataLevel;
  4459. var $schema = it.schema[$keyword];
  4460. var $schemaPath = it.schemaPath + '.' + $keyword;
  4461. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4462. var $breakOnError = !it.opts.allErrors;
  4463. var $errorKeyword;
  4464. var $data = 'data' + ($dataLvl || '');
  4465. var $valid = 'valid' + $lvl;
  4466. var $errs = 'errs__' + $lvl;
  4467. var $it = it.util.copy(it);
  4468. var $closingBraces = '';
  4469. $it.level++;
  4470. var $noEmptySchema = $schema.every(function($sch) {
  4471. return it.util.schemaHasRules($sch, it.RULES.all);
  4472. });
  4473. if ($noEmptySchema) {
  4474. out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
  4475. var $wasComposite = it.compositeRule;
  4476. it.compositeRule = $it.compositeRule = true;
  4477. var arr1 = $schema;
  4478. if (arr1) {
  4479. var $sch, $i = -1,
  4480. l1 = arr1.length - 1;
  4481. while ($i < l1) {
  4482. $sch = arr1[$i += 1];
  4483. $it.schema = $sch;
  4484. $it.schemaPath = $schemaPath + '[' + $i + ']';
  4485. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  4486. out += ' ' + (it.validate($it)) + ' ' + ($valid) + ' = ' + ($valid) + ' || valid' + ($it.level) + '; if (!' + ($valid) + ') { ';
  4487. $closingBraces += '}';
  4488. }
  4489. }
  4490. it.compositeRule = $it.compositeRule = $wasComposite;
  4491. out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
  4492. if (it.createErrors !== false) {
  4493. out += ' { keyword: \'' + ($errorKeyword || 'anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  4494. if (it.opts.messages !== false) {
  4495. out += ' , message: \'should match some schema in anyOf\' ';
  4496. }
  4497. if (it.opts.verbose) {
  4498. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4499. }
  4500. out += ' } ';
  4501. } else {
  4502. out += ' {} ';
  4503. }
  4504. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  4505. if (it.opts.allErrors) {
  4506. out += ' } ';
  4507. }
  4508. out = it.util.cleanUpCode(out);
  4509. } else {
  4510. if ($breakOnError) {
  4511. out += ' if (true) { ';
  4512. }
  4513. }
  4514. return out;
  4515. }
  4516. /***/ },
  4517. /* 28 */
  4518. /***/ function(module, exports) {
  4519. 'use strict';
  4520. module.exports = function generate_dependencies(it, $keyword) {
  4521. var out = ' ';
  4522. var $lvl = it.level;
  4523. var $dataLvl = it.dataLevel;
  4524. var $schema = it.schema[$keyword];
  4525. var $schemaPath = it.schemaPath + '.' + $keyword;
  4526. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4527. var $breakOnError = !it.opts.allErrors;
  4528. var $errorKeyword;
  4529. var $data = 'data' + ($dataLvl || '');
  4530. var $errs = 'errs__' + $lvl;
  4531. var $it = it.util.copy(it);
  4532. var $closingBraces = '';
  4533. $it.level++;
  4534. var $schemaDeps = {},
  4535. $propertyDeps = {};
  4536. for ($property in $schema) {
  4537. var $sch = $schema[$property];
  4538. var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
  4539. $deps[$property] = $sch;
  4540. }
  4541. out += 'var ' + ($errs) + ' = errors;';
  4542. var $currentErrorPath = it.errorPath;
  4543. out += 'var missing' + ($lvl) + ';';
  4544. for (var $property in $propertyDeps) {
  4545. $deps = $propertyDeps[$property];
  4546. out += ' if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined && ( ';
  4547. var arr1 = $deps;
  4548. if (arr1) {
  4549. var _$property, $i = -1,
  4550. l1 = arr1.length - 1;
  4551. while ($i < l1) {
  4552. _$property = arr1[$i += 1];
  4553. if ($i) {
  4554. out += ' || ';
  4555. }
  4556. var $prop = it.util.getProperty(_$property);
  4557. out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
  4558. }
  4559. }
  4560. out += ')) { ';
  4561. var $propertyPath = 'missing' + $lvl,
  4562. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  4563. if (it.opts._errorDataPathProperty) {
  4564. it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
  4565. }
  4566. var $$outStack = $$outStack || [];
  4567. $$outStack.push(out);
  4568. out = ''; /* istanbul ignore else */
  4569. if (it.createErrors !== false) {
  4570. out += ' { keyword: \'' + ($errorKeyword || 'dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
  4571. if (it.opts.messages !== false) {
  4572. out += ' , message: \'should have ';
  4573. if ($deps.length == 1) {
  4574. out += 'property ' + (it.util.escapeQuotes($deps[0]));
  4575. } else {
  4576. out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
  4577. }
  4578. out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
  4579. }
  4580. if (it.opts.verbose) {
  4581. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4582. }
  4583. out += ' } ';
  4584. } else {
  4585. out += ' {} ';
  4586. }
  4587. var __err = out;
  4588. out = $$outStack.pop();
  4589. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4590. if (it.async) {
  4591. out += ' throw new ValidationError([' + (__err) + ']); ';
  4592. } else {
  4593. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4594. }
  4595. } else {
  4596. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4597. }
  4598. out += ' } ';
  4599. if ($breakOnError) {
  4600. $closingBraces += '}';
  4601. out += ' else { ';
  4602. }
  4603. }
  4604. it.errorPath = $currentErrorPath;
  4605. for (var $property in $schemaDeps) {
  4606. var $sch = $schemaDeps[$property];
  4607. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  4608. out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '[\'' + ($property) + '\'] !== undefined) { ';
  4609. $it.schema = $sch;
  4610. $it.schemaPath = $schemaPath + it.util.getProperty($property);
  4611. $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
  4612. out += ' ' + (it.validate($it)) + ' } ';
  4613. if ($breakOnError) {
  4614. out += ' if (valid' + ($it.level) + ') { ';
  4615. $closingBraces += '}';
  4616. }
  4617. }
  4618. }
  4619. if ($breakOnError) {
  4620. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  4621. }
  4622. out = it.util.cleanUpCode(out);
  4623. return out;
  4624. }
  4625. /***/ },
  4626. /* 29 */
  4627. /***/ function(module, exports) {
  4628. 'use strict';
  4629. module.exports = function generate_enum(it, $keyword) {
  4630. var out = ' ';
  4631. var $lvl = it.level;
  4632. var $dataLvl = it.dataLevel;
  4633. var $schema = it.schema[$keyword];
  4634. var $schemaPath = it.schemaPath + '.' + $keyword;
  4635. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4636. var $breakOnError = !it.opts.allErrors;
  4637. var $errorKeyword;
  4638. var $data = 'data' + ($dataLvl || '');
  4639. var $valid = 'valid' + $lvl;
  4640. var $isData = it.opts.v5 && $schema.$data;
  4641. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  4642. if ($isData) {
  4643. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  4644. $schemaValue = 'schema' + $lvl;
  4645. }
  4646. var $i = 'i' + $lvl;
  4647. if (!$isData) {
  4648. out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
  4649. }
  4650. out += 'var ' + ($valid) + ';';
  4651. if ($isData) {
  4652. out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
  4653. }
  4654. out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<schema' + ($lvl) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', schema' + ($lvl) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
  4655. if ($isData) {
  4656. out += ' } ';
  4657. }
  4658. out += ' if (!' + ($valid) + ') { ';
  4659. var $$outStack = $$outStack || [];
  4660. $$outStack.push(out);
  4661. out = ''; /* istanbul ignore else */
  4662. if (it.createErrors !== false) {
  4663. out += ' { keyword: \'' + ($errorKeyword || 'enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  4664. if (it.opts.messages !== false) {
  4665. out += ' , message: \'should be equal to one of the allowed values\' ';
  4666. }
  4667. if (it.opts.verbose) {
  4668. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4669. }
  4670. out += ' } ';
  4671. } else {
  4672. out += ' {} ';
  4673. }
  4674. var __err = out;
  4675. out = $$outStack.pop();
  4676. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4677. if (it.async) {
  4678. out += ' throw new ValidationError([' + (__err) + ']); ';
  4679. } else {
  4680. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4681. }
  4682. } else {
  4683. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4684. }
  4685. out += ' }';
  4686. if ($breakOnError) {
  4687. out += ' else { ';
  4688. }
  4689. return out;
  4690. }
  4691. /***/ },
  4692. /* 30 */
  4693. /***/ function(module, exports) {
  4694. 'use strict';
  4695. module.exports = function generate_format(it, $keyword) {
  4696. var out = ' ';
  4697. var $lvl = it.level;
  4698. var $dataLvl = it.dataLevel;
  4699. var $schema = it.schema[$keyword];
  4700. var $schemaPath = it.schemaPath + '.' + $keyword;
  4701. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4702. var $breakOnError = !it.opts.allErrors;
  4703. var $errorKeyword;
  4704. var $data = 'data' + ($dataLvl || '');
  4705. if (it.opts.format === false) {
  4706. if ($breakOnError) {
  4707. out += ' if (true) { ';
  4708. }
  4709. return out;
  4710. }
  4711. var $isData = it.opts.v5 && $schema.$data;
  4712. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  4713. if ($isData) {
  4714. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  4715. $schemaValue = 'schema' + $lvl;
  4716. }
  4717. if ($isData) {
  4718. var $format = 'format' + $lvl;
  4719. out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var isObject' + ($lvl) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; if (isObject' + ($lvl) + ') { var async' + ($lvl) + ' = ' + ($format) + '.async; ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
  4720. if ($isData) {
  4721. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  4722. }
  4723. out += ' (' + ($format) + ' && !(typeof ' + ($format) + ' == \'function\' ? ';
  4724. if (it.async) {
  4725. out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
  4726. } else {
  4727. out += ' ' + ($format) + '(' + ($data) + ') ';
  4728. }
  4729. out += ' : ' + ($format) + '.test(' + ($data) + ')))) {';
  4730. } else {
  4731. var $format = it.formats[$schema];
  4732. if (!$format) {
  4733. if ($breakOnError) {
  4734. out += ' if (true) { ';
  4735. }
  4736. return out;
  4737. }
  4738. var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
  4739. if ($isObject) {
  4740. var $async = $format.async === true;
  4741. $format = $format.validate;
  4742. }
  4743. if ($async) {
  4744. if (!it.async) throw new Error('async format in sync schema');
  4745. var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
  4746. out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { ';
  4747. } else {
  4748. out += ' if (! ';
  4749. var $formatRef = 'formats' + it.util.getProperty($schema);
  4750. if ($isObject) $formatRef += '.validate';
  4751. if (typeof $format == 'function') {
  4752. out += ' ' + ($formatRef) + '(' + ($data) + ') ';
  4753. } else {
  4754. out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
  4755. }
  4756. out += ') { ';
  4757. }
  4758. }
  4759. var $$outStack = $$outStack || [];
  4760. $$outStack.push(out);
  4761. out = ''; /* istanbul ignore else */
  4762. if (it.createErrors !== false) {
  4763. out += ' { keyword: \'' + ($errorKeyword || 'format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { format: ';
  4764. if ($isData) {
  4765. out += '' + ($schemaValue);
  4766. } else {
  4767. out += '' + (it.util.toQuotedString($schema));
  4768. }
  4769. out += ' } ';
  4770. if (it.opts.messages !== false) {
  4771. out += ' , message: \'should match format "';
  4772. if ($isData) {
  4773. out += '\' + ' + ($schemaValue) + ' + \'';
  4774. } else {
  4775. out += '' + (it.util.escapeQuotes($schema));
  4776. }
  4777. out += '"\' ';
  4778. }
  4779. if (it.opts.verbose) {
  4780. out += ' , schema: ';
  4781. if ($isData) {
  4782. out += 'validate.schema' + ($schemaPath);
  4783. } else {
  4784. out += '' + (it.util.toQuotedString($schema));
  4785. }
  4786. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4787. }
  4788. out += ' } ';
  4789. } else {
  4790. out += ' {} ';
  4791. }
  4792. var __err = out;
  4793. out = $$outStack.pop();
  4794. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4795. if (it.async) {
  4796. out += ' throw new ValidationError([' + (__err) + ']); ';
  4797. } else {
  4798. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4799. }
  4800. } else {
  4801. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4802. }
  4803. out += ' } ';
  4804. if ($breakOnError) {
  4805. out += ' else { ';
  4806. }
  4807. return out;
  4808. }
  4809. /***/ },
  4810. /* 31 */
  4811. /***/ function(module, exports) {
  4812. 'use strict';
  4813. module.exports = function generate_items(it, $keyword) {
  4814. var out = ' ';
  4815. var $lvl = it.level;
  4816. var $dataLvl = it.dataLevel;
  4817. var $schema = it.schema[$keyword];
  4818. var $schemaPath = it.schemaPath + '.' + $keyword;
  4819. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4820. var $breakOnError = !it.opts.allErrors;
  4821. var $errorKeyword;
  4822. var $data = 'data' + ($dataLvl || '');
  4823. var $valid = 'valid' + $lvl;
  4824. var $errs = 'errs__' + $lvl;
  4825. var $it = it.util.copy(it);
  4826. var $closingBraces = '';
  4827. $it.level++;
  4828. var $dataNxt = $it.dataLevel = it.dataLevel + 1,
  4829. $nextData = 'data' + $dataNxt;
  4830. out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
  4831. if (Array.isArray($schema)) {
  4832. var $additionalItems = it.schema.additionalItems;
  4833. if ($additionalItems === false) {
  4834. out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
  4835. var $currErrSchemaPath = $errSchemaPath;
  4836. $errSchemaPath = it.errSchemaPath + '/additionalItems';
  4837. out += ' if (!' + ($valid) + ') { ';
  4838. var $$outStack = $$outStack || [];
  4839. $$outStack.push(out);
  4840. out = ''; /* istanbul ignore else */
  4841. if (it.createErrors !== false) {
  4842. out += ' { keyword: \'' + ($errorKeyword || 'additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schema.length) + ' } ';
  4843. if (it.opts.messages !== false) {
  4844. out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
  4845. }
  4846. if (it.opts.verbose) {
  4847. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4848. }
  4849. out += ' } ';
  4850. } else {
  4851. out += ' {} ';
  4852. }
  4853. var __err = out;
  4854. out = $$outStack.pop();
  4855. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4856. if (it.async) {
  4857. out += ' throw new ValidationError([' + (__err) + ']); ';
  4858. } else {
  4859. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4860. }
  4861. } else {
  4862. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4863. }
  4864. out += ' } ';
  4865. $errSchemaPath = $currErrSchemaPath;
  4866. if ($breakOnError) {
  4867. $closingBraces += '}';
  4868. out += ' else { ';
  4869. }
  4870. }
  4871. var arr1 = $schema;
  4872. if (arr1) {
  4873. var $sch, $i = -1,
  4874. l1 = arr1.length - 1;
  4875. while ($i < l1) {
  4876. $sch = arr1[$i += 1];
  4877. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  4878. out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
  4879. var $passData = $data + '[' + $i + ']';
  4880. $it.schema = $sch;
  4881. $it.schemaPath = $schemaPath + '[' + $i + ']';
  4882. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  4883. $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
  4884. $it.dataPathArr[$dataNxt] = $i;
  4885. var $code = it.validate($it);
  4886. if (it.util.varOccurences($code, $nextData) < 2) {
  4887. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  4888. } else {
  4889. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  4890. }
  4891. out += ' } ';
  4892. if ($breakOnError) {
  4893. out += ' if (valid' + ($it.level) + ') { ';
  4894. $closingBraces += '}';
  4895. }
  4896. }
  4897. }
  4898. }
  4899. if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) {
  4900. $it.schema = $additionalItems;
  4901. $it.schemaPath = it.schemaPath + '.additionalItems';
  4902. $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
  4903. out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var i' + ($lvl) + ' = ' + ($schema.length) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
  4904. $it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true);
  4905. var $passData = $data + '[i' + $lvl + ']';
  4906. $it.dataPathArr[$dataNxt] = 'i' + $lvl;
  4907. var $code = it.validate($it);
  4908. if (it.util.varOccurences($code, $nextData) < 2) {
  4909. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  4910. } else {
  4911. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  4912. }
  4913. if ($breakOnError) {
  4914. out += ' if (!valid' + ($it.level) + ') break; ';
  4915. }
  4916. out += ' } } ';
  4917. if ($breakOnError) {
  4918. out += ' if (valid' + ($it.level) + ') { ';
  4919. $closingBraces += '}';
  4920. }
  4921. }
  4922. } else if (it.util.schemaHasRules($schema, it.RULES.all)) {
  4923. $it.schema = $schema;
  4924. $it.schemaPath = $schemaPath;
  4925. $it.errSchemaPath = $errSchemaPath;
  4926. out += ' for (var i' + ($lvl) + ' = ' + (0) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
  4927. $it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true);
  4928. var $passData = $data + '[i' + $lvl + ']';
  4929. $it.dataPathArr[$dataNxt] = 'i' + $lvl;
  4930. var $code = it.validate($it);
  4931. if (it.util.varOccurences($code, $nextData) < 2) {
  4932. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  4933. } else {
  4934. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  4935. }
  4936. if ($breakOnError) {
  4937. out += ' if (!valid' + ($it.level) + ') break; ';
  4938. }
  4939. out += ' } ';
  4940. if ($breakOnError) {
  4941. out += ' if (valid' + ($it.level) + ') { ';
  4942. $closingBraces += '}';
  4943. }
  4944. }
  4945. if ($breakOnError) {
  4946. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  4947. }
  4948. out = it.util.cleanUpCode(out);
  4949. return out;
  4950. }
  4951. /***/ },
  4952. /* 32 */
  4953. /***/ function(module, exports) {
  4954. 'use strict';
  4955. module.exports = function generate__limit(it, $keyword) {
  4956. var out = ' ';
  4957. var $lvl = it.level;
  4958. var $dataLvl = it.dataLevel;
  4959. var $schema = it.schema[$keyword];
  4960. var $schemaPath = it.schemaPath + '.' + $keyword;
  4961. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  4962. var $breakOnError = !it.opts.allErrors;
  4963. var $errorKeyword;
  4964. var $data = 'data' + ($dataLvl || '');
  4965. var $isData = it.opts.v5 && $schema.$data;
  4966. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  4967. if ($isData) {
  4968. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  4969. $schemaValue = 'schema' + $lvl;
  4970. }
  4971. var $isMax = $keyword == 'maximum',
  4972. $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
  4973. $schemaExcl = it.schema[$exclusiveKeyword],
  4974. $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
  4975. $op = $isMax ? '<' : '>',
  4976. $notOp = $isMax ? '>' : '<';
  4977. if ($isDataExcl) {
  4978. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
  4979. $exclusive = 'exclusive' + $lvl,
  4980. $opExpr = 'op' + $lvl,
  4981. $opStr = '\' + ' + $opExpr + ' + \'';
  4982. out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
  4983. $schemaValueExcl = 'schemaExcl' + $lvl;
  4984. out += ' var exclusive' + ($lvl) + '; if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && typeof ' + ($schemaValueExcl) + ' != \'undefined\') { ';
  4985. var $errorKeyword = $exclusiveKeyword;
  4986. var $$outStack = $$outStack || [];
  4987. $$outStack.push(out);
  4988. out = ''; /* istanbul ignore else */
  4989. if (it.createErrors !== false) {
  4990. out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  4991. if (it.opts.messages !== false) {
  4992. out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
  4993. }
  4994. if (it.opts.verbose) {
  4995. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4996. }
  4997. out += ' } ';
  4998. } else {
  4999. out += ' {} ';
  5000. }
  5001. var __err = out;
  5002. out = $$outStack.pop();
  5003. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5004. if (it.async) {
  5005. out += ' throw new ValidationError([' + (__err) + ']); ';
  5006. } else {
  5007. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5008. }
  5009. } else {
  5010. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5011. }
  5012. out += ' } else if( ';
  5013. if ($isData) {
  5014. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  5015. }
  5016. out += ' ((exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ')) { var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
  5017. } else {
  5018. var $exclusive = $schemaExcl === true,
  5019. $opStr = $op;
  5020. if (!$exclusive) $opStr += '=';
  5021. var $opExpr = '\'' + $opStr + '\'';
  5022. out += ' if ( ';
  5023. if ($isData) {
  5024. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  5025. }
  5026. out += ' ' + ($data) + ' ' + ($notOp);
  5027. if ($exclusive) {
  5028. out += '=';
  5029. }
  5030. out += ' ' + ($schemaValue) + ') {';
  5031. }
  5032. var $errorKeyword = $keyword;
  5033. var $$outStack = $$outStack || [];
  5034. $$outStack.push(out);
  5035. out = ''; /* istanbul ignore else */
  5036. if (it.createErrors !== false) {
  5037. out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
  5038. if (it.opts.messages !== false) {
  5039. out += ' , message: \'should be ' + ($opStr) + ' ';
  5040. if ($isData) {
  5041. out += '\' + ' + ($schemaValue);
  5042. } else {
  5043. out += '' + ($schema) + '\'';
  5044. }
  5045. }
  5046. if (it.opts.verbose) {
  5047. out += ' , schema: ';
  5048. if ($isData) {
  5049. out += 'validate.schema' + ($schemaPath);
  5050. } else {
  5051. out += '' + ($schema);
  5052. }
  5053. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5054. }
  5055. out += ' } ';
  5056. } else {
  5057. out += ' {} ';
  5058. }
  5059. var __err = out;
  5060. out = $$outStack.pop();
  5061. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5062. if (it.async) {
  5063. out += ' throw new ValidationError([' + (__err) + ']); ';
  5064. } else {
  5065. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5066. }
  5067. } else {
  5068. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5069. }
  5070. out += ' } ';
  5071. if ($breakOnError) {
  5072. out += ' else { ';
  5073. }
  5074. return out;
  5075. }
  5076. /***/ },
  5077. /* 33 */
  5078. /***/ function(module, exports) {
  5079. 'use strict';
  5080. module.exports = function generate__limitItems(it, $keyword) {
  5081. var out = ' ';
  5082. var $lvl = it.level;
  5083. var $dataLvl = it.dataLevel;
  5084. var $schema = it.schema[$keyword];
  5085. var $schemaPath = it.schemaPath + '.' + $keyword;
  5086. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5087. var $breakOnError = !it.opts.allErrors;
  5088. var $errorKeyword;
  5089. var $data = 'data' + ($dataLvl || '');
  5090. var $isData = it.opts.v5 && $schema.$data;
  5091. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  5092. if ($isData) {
  5093. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  5094. $schemaValue = 'schema' + $lvl;
  5095. }
  5096. var $op = $keyword == 'maxItems' ? '>' : '<';
  5097. out += 'if ( ';
  5098. if ($isData) {
  5099. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  5100. }
  5101. out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
  5102. var $errorKeyword = $keyword;
  5103. var $$outStack = $$outStack || [];
  5104. $$outStack.push(out);
  5105. out = ''; /* istanbul ignore else */
  5106. if (it.createErrors !== false) {
  5107. out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } ';
  5108. if (it.opts.messages !== false) {
  5109. out += ' , message: \'should NOT have ';
  5110. if ($keyword == 'maxItems') {
  5111. out += 'more';
  5112. } else {
  5113. out += 'less';
  5114. }
  5115. out += ' than ';
  5116. if ($isData) {
  5117. out += '\' + ' + ($schemaValue) + ' + \'';
  5118. } else {
  5119. out += '' + ($schema);
  5120. }
  5121. out += ' items\' ';
  5122. }
  5123. if (it.opts.verbose) {
  5124. out += ' , schema: ';
  5125. if ($isData) {
  5126. out += 'validate.schema' + ($schemaPath);
  5127. } else {
  5128. out += '' + ($schema);
  5129. }
  5130. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5131. }
  5132. out += ' } ';
  5133. } else {
  5134. out += ' {} ';
  5135. }
  5136. var __err = out;
  5137. out = $$outStack.pop();
  5138. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5139. if (it.async) {
  5140. out += ' throw new ValidationError([' + (__err) + ']); ';
  5141. } else {
  5142. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5143. }
  5144. } else {
  5145. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5146. }
  5147. out += '} ';
  5148. if ($breakOnError) {
  5149. out += ' else { ';
  5150. }
  5151. return out;
  5152. }
  5153. /***/ },
  5154. /* 34 */
  5155. /***/ function(module, exports) {
  5156. 'use strict';
  5157. module.exports = function generate__limitLength(it, $keyword) {
  5158. var out = ' ';
  5159. var $lvl = it.level;
  5160. var $dataLvl = it.dataLevel;
  5161. var $schema = it.schema[$keyword];
  5162. var $schemaPath = it.schemaPath + '.' + $keyword;
  5163. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5164. var $breakOnError = !it.opts.allErrors;
  5165. var $errorKeyword;
  5166. var $data = 'data' + ($dataLvl || '');
  5167. var $isData = it.opts.v5 && $schema.$data;
  5168. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  5169. if ($isData) {
  5170. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  5171. $schemaValue = 'schema' + $lvl;
  5172. }
  5173. var $op = $keyword == 'maxLength' ? '>' : '<';
  5174. out += 'if ( ';
  5175. if ($isData) {
  5176. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  5177. }
  5178. if (it.opts.unicode === false) {
  5179. out += ' ' + ($data) + '.length ';
  5180. } else {
  5181. out += ' ucs2length(' + ($data) + ') ';
  5182. }
  5183. out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
  5184. var $errorKeyword = $keyword;
  5185. var $$outStack = $$outStack || [];
  5186. $$outStack.push(out);
  5187. out = ''; /* istanbul ignore else */
  5188. if (it.createErrors !== false) {
  5189. out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } ';
  5190. if (it.opts.messages !== false) {
  5191. out += ' , message: \'should NOT be ';
  5192. if ($keyword == 'maxLength') {
  5193. out += 'longer';
  5194. } else {
  5195. out += 'shorter';
  5196. }
  5197. out += ' than ';
  5198. if ($isData) {
  5199. out += '\' + ' + ($schemaValue) + ' + \'';
  5200. } else {
  5201. out += '' + ($schema);
  5202. }
  5203. out += ' characters\' ';
  5204. }
  5205. if (it.opts.verbose) {
  5206. out += ' , schema: ';
  5207. if ($isData) {
  5208. out += 'validate.schema' + ($schemaPath);
  5209. } else {
  5210. out += '' + ($schema);
  5211. }
  5212. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5213. }
  5214. out += ' } ';
  5215. } else {
  5216. out += ' {} ';
  5217. }
  5218. var __err = out;
  5219. out = $$outStack.pop();
  5220. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5221. if (it.async) {
  5222. out += ' throw new ValidationError([' + (__err) + ']); ';
  5223. } else {
  5224. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5225. }
  5226. } else {
  5227. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5228. }
  5229. out += '} ';
  5230. if ($breakOnError) {
  5231. out += ' else { ';
  5232. }
  5233. return out;
  5234. }
  5235. /***/ },
  5236. /* 35 */
  5237. /***/ function(module, exports) {
  5238. 'use strict';
  5239. module.exports = function generate__limitProperties(it, $keyword) {
  5240. var out = ' ';
  5241. var $lvl = it.level;
  5242. var $dataLvl = it.dataLevel;
  5243. var $schema = it.schema[$keyword];
  5244. var $schemaPath = it.schemaPath + '.' + $keyword;
  5245. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5246. var $breakOnError = !it.opts.allErrors;
  5247. var $errorKeyword;
  5248. var $data = 'data' + ($dataLvl || '');
  5249. var $isData = it.opts.v5 && $schema.$data;
  5250. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  5251. if ($isData) {
  5252. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  5253. $schemaValue = 'schema' + $lvl;
  5254. }
  5255. var $op = $keyword == 'maxProperties' ? '>' : '<';
  5256. out += 'if ( ';
  5257. if ($isData) {
  5258. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  5259. }
  5260. out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
  5261. var $errorKeyword = $keyword;
  5262. var $$outStack = $$outStack || [];
  5263. $$outStack.push(out);
  5264. out = ''; /* istanbul ignore else */
  5265. if (it.createErrors !== false) {
  5266. out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } ';
  5267. if (it.opts.messages !== false) {
  5268. out += ' , message: \'should NOT have ';
  5269. if ($keyword == 'maxProperties') {
  5270. out += 'more';
  5271. } else {
  5272. out += 'less';
  5273. }
  5274. out += ' than ';
  5275. if ($isData) {
  5276. out += '\' + ' + ($schemaValue) + ' + \'';
  5277. } else {
  5278. out += '' + ($schema);
  5279. }
  5280. out += ' properties\' ';
  5281. }
  5282. if (it.opts.verbose) {
  5283. out += ' , schema: ';
  5284. if ($isData) {
  5285. out += 'validate.schema' + ($schemaPath);
  5286. } else {
  5287. out += '' + ($schema);
  5288. }
  5289. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5290. }
  5291. out += ' } ';
  5292. } else {
  5293. out += ' {} ';
  5294. }
  5295. var __err = out;
  5296. out = $$outStack.pop();
  5297. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5298. if (it.async) {
  5299. out += ' throw new ValidationError([' + (__err) + ']); ';
  5300. } else {
  5301. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5302. }
  5303. } else {
  5304. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5305. }
  5306. out += '} ';
  5307. if ($breakOnError) {
  5308. out += ' else { ';
  5309. }
  5310. return out;
  5311. }
  5312. /***/ },
  5313. /* 36 */
  5314. /***/ function(module, exports) {
  5315. 'use strict';
  5316. module.exports = function generate_multipleOf(it, $keyword) {
  5317. var out = ' ';
  5318. var $lvl = it.level;
  5319. var $dataLvl = it.dataLevel;
  5320. var $schema = it.schema[$keyword];
  5321. var $schemaPath = it.schemaPath + '.' + $keyword;
  5322. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5323. var $breakOnError = !it.opts.allErrors;
  5324. var $errorKeyword;
  5325. var $data = 'data' + ($dataLvl || '');
  5326. var $isData = it.opts.v5 && $schema.$data;
  5327. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  5328. if ($isData) {
  5329. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  5330. $schemaValue = 'schema' + $lvl;
  5331. }
  5332. out += 'var division' + ($lvl) + ';if (';
  5333. if ($isData) {
  5334. out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
  5335. }
  5336. out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
  5337. if (it.opts.multipleOfPrecision) {
  5338. out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
  5339. } else {
  5340. out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
  5341. }
  5342. out += ' ) ';
  5343. if ($isData) {
  5344. out += ' ) ';
  5345. }
  5346. out += ' ) { ';
  5347. var $$outStack = $$outStack || [];
  5348. $$outStack.push(out);
  5349. out = ''; /* istanbul ignore else */
  5350. if (it.createErrors !== false) {
  5351. out += ' { keyword: \'' + ($errorKeyword || 'multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { multipleOf: ' + ($schemaValue) + ' } ';
  5352. if (it.opts.messages !== false) {
  5353. out += ' , message: \'should be multiple of ';
  5354. if ($isData) {
  5355. out += '\' + ' + ($schemaValue);
  5356. } else {
  5357. out += '' + ($schema) + '\'';
  5358. }
  5359. }
  5360. if (it.opts.verbose) {
  5361. out += ' , schema: ';
  5362. if ($isData) {
  5363. out += 'validate.schema' + ($schemaPath);
  5364. } else {
  5365. out += '' + ($schema);
  5366. }
  5367. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5368. }
  5369. out += ' } ';
  5370. } else {
  5371. out += ' {} ';
  5372. }
  5373. var __err = out;
  5374. out = $$outStack.pop();
  5375. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5376. if (it.async) {
  5377. out += ' throw new ValidationError([' + (__err) + ']); ';
  5378. } else {
  5379. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5380. }
  5381. } else {
  5382. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5383. }
  5384. out += '} ';
  5385. if ($breakOnError) {
  5386. out += ' else { ';
  5387. }
  5388. return out;
  5389. }
  5390. /***/ },
  5391. /* 37 */
  5392. /***/ function(module, exports) {
  5393. 'use strict';
  5394. module.exports = function generate_not(it, $keyword) {
  5395. var out = ' ';
  5396. var $lvl = it.level;
  5397. var $dataLvl = it.dataLevel;
  5398. var $schema = it.schema[$keyword];
  5399. var $schemaPath = it.schemaPath + '.' + $keyword;
  5400. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5401. var $breakOnError = !it.opts.allErrors;
  5402. var $errorKeyword;
  5403. var $data = 'data' + ($dataLvl || '');
  5404. var $errs = 'errs__' + $lvl;
  5405. var $it = it.util.copy(it);
  5406. $it.level++;
  5407. if (it.util.schemaHasRules($schema, it.RULES.all)) {
  5408. $it.schema = $schema;
  5409. $it.schemaPath = $schemaPath;
  5410. $it.errSchemaPath = $errSchemaPath;
  5411. out += ' var ' + ($errs) + ' = errors; ';
  5412. var $wasComposite = it.compositeRule;
  5413. it.compositeRule = $it.compositeRule = true;
  5414. $it.createErrors = false;
  5415. var $allErrorsOption;
  5416. if ($it.opts.allErrors) {
  5417. $allErrorsOption = $it.opts.allErrors;
  5418. $it.opts.allErrors = false;
  5419. }
  5420. out += ' ' + (it.validate($it)) + ' ';
  5421. $it.createErrors = true;
  5422. if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
  5423. it.compositeRule = $it.compositeRule = $wasComposite;
  5424. out += ' if (valid' + ($it.level) + ') { ';
  5425. var $$outStack = $$outStack || [];
  5426. $$outStack.push(out);
  5427. out = ''; /* istanbul ignore else */
  5428. if (it.createErrors !== false) {
  5429. out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  5430. if (it.opts.messages !== false) {
  5431. out += ' , message: \'should NOT be valid\' ';
  5432. }
  5433. if (it.opts.verbose) {
  5434. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5435. }
  5436. out += ' } ';
  5437. } else {
  5438. out += ' {} ';
  5439. }
  5440. var __err = out;
  5441. out = $$outStack.pop();
  5442. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5443. if (it.async) {
  5444. out += ' throw new ValidationError([' + (__err) + ']); ';
  5445. } else {
  5446. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5447. }
  5448. } else {
  5449. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5450. }
  5451. out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  5452. if (it.opts.allErrors) {
  5453. out += ' } ';
  5454. }
  5455. } else {
  5456. out += ' var err = '; /* istanbul ignore else */
  5457. if (it.createErrors !== false) {
  5458. out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  5459. if (it.opts.messages !== false) {
  5460. out += ' , message: \'should NOT be valid\' ';
  5461. }
  5462. if (it.opts.verbose) {
  5463. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5464. }
  5465. out += ' } ';
  5466. } else {
  5467. out += ' {} ';
  5468. }
  5469. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5470. if ($breakOnError) {
  5471. out += ' if (false) { ';
  5472. }
  5473. }
  5474. return out;
  5475. }
  5476. /***/ },
  5477. /* 38 */
  5478. /***/ function(module, exports) {
  5479. 'use strict';
  5480. module.exports = function generate_oneOf(it, $keyword) {
  5481. var out = ' ';
  5482. var $lvl = it.level;
  5483. var $dataLvl = it.dataLevel;
  5484. var $schema = it.schema[$keyword];
  5485. var $schemaPath = it.schemaPath + '.' + $keyword;
  5486. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5487. var $breakOnError = !it.opts.allErrors;
  5488. var $errorKeyword;
  5489. var $data = 'data' + ($dataLvl || '');
  5490. var $valid = 'valid' + $lvl;
  5491. var $errs = 'errs__' + $lvl;
  5492. var $it = it.util.copy(it);
  5493. var $closingBraces = '';
  5494. $it.level++;
  5495. out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false; ';
  5496. var $wasComposite = it.compositeRule;
  5497. it.compositeRule = $it.compositeRule = true;
  5498. var arr1 = $schema;
  5499. if (arr1) {
  5500. var $sch, $i = -1,
  5501. l1 = arr1.length - 1;
  5502. while ($i < l1) {
  5503. $sch = arr1[$i += 1];
  5504. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  5505. $it.schema = $sch;
  5506. $it.schemaPath = $schemaPath + '[' + $i + ']';
  5507. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  5508. out += ' ' + (it.validate($it)) + ' ';
  5509. } else {
  5510. out += ' var valid' + ($it.level) + ' = true; ';
  5511. }
  5512. if ($i) {
  5513. out += ' if (valid' + ($it.level) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
  5514. $closingBraces += '}';
  5515. }
  5516. out += ' if (valid' + ($it.level) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
  5517. }
  5518. }
  5519. it.compositeRule = $it.compositeRule = $wasComposite;
  5520. out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
  5521. var $$outStack = $$outStack || [];
  5522. $$outStack.push(out);
  5523. out = ''; /* istanbul ignore else */
  5524. if (it.createErrors !== false) {
  5525. out += ' { keyword: \'' + ($errorKeyword || 'oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  5526. if (it.opts.messages !== false) {
  5527. out += ' , message: \'should match exactly one schema in oneOf\' ';
  5528. }
  5529. if (it.opts.verbose) {
  5530. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5531. }
  5532. out += ' } ';
  5533. } else {
  5534. out += ' {} ';
  5535. }
  5536. var __err = out;
  5537. out = $$outStack.pop();
  5538. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5539. if (it.async) {
  5540. out += ' throw new ValidationError([' + (__err) + ']); ';
  5541. } else {
  5542. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5543. }
  5544. } else {
  5545. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5546. }
  5547. out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
  5548. if (it.opts.allErrors) {
  5549. out += ' } ';
  5550. }
  5551. return out;
  5552. }
  5553. /***/ },
  5554. /* 39 */
  5555. /***/ function(module, exports) {
  5556. 'use strict';
  5557. module.exports = function generate_pattern(it, $keyword) {
  5558. var out = ' ';
  5559. var $lvl = it.level;
  5560. var $dataLvl = it.dataLevel;
  5561. var $schema = it.schema[$keyword];
  5562. var $schemaPath = it.schemaPath + '.' + $keyword;
  5563. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5564. var $breakOnError = !it.opts.allErrors;
  5565. var $errorKeyword;
  5566. var $data = 'data' + ($dataLvl || '');
  5567. var $isData = it.opts.v5 && $schema.$data;
  5568. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  5569. if ($isData) {
  5570. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  5571. $schemaValue = 'schema' + $lvl;
  5572. }
  5573. var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
  5574. out += 'if ( ';
  5575. if ($isData) {
  5576. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  5577. }
  5578. out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
  5579. var $$outStack = $$outStack || [];
  5580. $$outStack.push(out);
  5581. out = ''; /* istanbul ignore else */
  5582. if (it.createErrors !== false) {
  5583. out += ' { keyword: \'' + ($errorKeyword || 'pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { pattern: ';
  5584. if ($isData) {
  5585. out += '' + ($schemaValue);
  5586. } else {
  5587. out += '' + (it.util.toQuotedString($schema));
  5588. }
  5589. out += ' } ';
  5590. if (it.opts.messages !== false) {
  5591. out += ' , message: \'should match pattern "';
  5592. if ($isData) {
  5593. out += '\' + ' + ($schemaValue) + ' + \'';
  5594. } else {
  5595. out += '' + (it.util.escapeQuotes($schema));
  5596. }
  5597. out += '"\' ';
  5598. }
  5599. if (it.opts.verbose) {
  5600. out += ' , schema: ';
  5601. if ($isData) {
  5602. out += 'validate.schema' + ($schemaPath);
  5603. } else {
  5604. out += '' + (it.util.toQuotedString($schema));
  5605. }
  5606. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5607. }
  5608. out += ' } ';
  5609. } else {
  5610. out += ' {} ';
  5611. }
  5612. var __err = out;
  5613. out = $$outStack.pop();
  5614. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5615. if (it.async) {
  5616. out += ' throw new ValidationError([' + (__err) + ']); ';
  5617. } else {
  5618. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5619. }
  5620. } else {
  5621. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5622. }
  5623. out += '} ';
  5624. if ($breakOnError) {
  5625. out += ' else { ';
  5626. }
  5627. return out;
  5628. }
  5629. /***/ },
  5630. /* 40 */
  5631. /***/ function(module, exports) {
  5632. 'use strict';
  5633. module.exports = function generate_properties(it, $keyword) {
  5634. var out = ' ';
  5635. var $lvl = it.level;
  5636. var $dataLvl = it.dataLevel;
  5637. var $schema = it.schema[$keyword];
  5638. var $schemaPath = it.schemaPath + '.' + $keyword;
  5639. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  5640. var $breakOnError = !it.opts.allErrors;
  5641. var $errorKeyword;
  5642. var $data = 'data' + ($dataLvl || '');
  5643. var $valid = 'valid' + $lvl;
  5644. var $errs = 'errs__' + $lvl;
  5645. var $it = it.util.copy(it);
  5646. var $closingBraces = '';
  5647. $it.level++;
  5648. var $dataNxt = $it.dataLevel = it.dataLevel + 1,
  5649. $nextData = 'data' + $dataNxt;
  5650. var $schemaKeys = Object.keys($schema || {}),
  5651. $pProperties = it.schema.patternProperties || {},
  5652. $pPropertyKeys = Object.keys($pProperties),
  5653. $aProperties = it.schema.additionalProperties,
  5654. $someProperties = $schemaKeys.length || $pPropertyKeys.length,
  5655. $noAdditional = $aProperties === false,
  5656. $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
  5657. $removeAdditional = it.opts.removeAdditional,
  5658. $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional;
  5659. var $required = it.schema.required;
  5660. if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required);
  5661. if (it.opts.v5) {
  5662. var $pgProperties = it.schema.patternGroups || {},
  5663. $pgPropertyKeys = Object.keys($pgProperties);
  5664. }
  5665. out += 'var ' + ($errs) + ' = errors;var valid' + ($it.level) + ' = true;';
  5666. if ($checkAdditional) {
  5667. out += ' for (var key' + ($lvl) + ' in ' + ($data) + ') { ';
  5668. if ($someProperties) {
  5669. out += ' var isAdditional' + ($lvl) + ' = !(false ';
  5670. if ($schemaKeys.length) {
  5671. if ($schemaKeys.length > 5) {
  5672. out += ' || validate.schema' + ($schemaPath) + '[key' + ($lvl) + '] ';
  5673. } else {
  5674. var arr1 = $schemaKeys;
  5675. if (arr1) {
  5676. var $propertyKey, i1 = -1,
  5677. l1 = arr1.length - 1;
  5678. while (i1 < l1) {
  5679. $propertyKey = arr1[i1 += 1];
  5680. out += ' || key' + ($lvl) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
  5681. }
  5682. }
  5683. }
  5684. }
  5685. if ($pPropertyKeys.length) {
  5686. var arr2 = $pPropertyKeys;
  5687. if (arr2) {
  5688. var $pProperty, $i = -1,
  5689. l2 = arr2.length - 1;
  5690. while ($i < l2) {
  5691. $pProperty = arr2[$i += 1];
  5692. out += ' || ' + (it.usePattern($pProperty)) + '.test(key' + ($lvl) + ') ';
  5693. }
  5694. }
  5695. }
  5696. if (it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length) {
  5697. var arr3 = $pgPropertyKeys;
  5698. if (arr3) {
  5699. var $pgProperty, $i = -1,
  5700. l3 = arr3.length - 1;
  5701. while ($i < l3) {
  5702. $pgProperty = arr3[$i += 1];
  5703. out += ' || ' + (it.usePattern($pgProperty)) + '.test(key' + ($lvl) + ') ';
  5704. }
  5705. }
  5706. }
  5707. out += ' ); if (isAdditional' + ($lvl) + ') { ';
  5708. }
  5709. if ($removeAdditional == 'all') {
  5710. out += ' delete ' + ($data) + '[key' + ($lvl) + ']; ';
  5711. } else {
  5712. var $currentErrorPath = it.errorPath;
  5713. var $additionalProperty = '\' + key' + $lvl + ' + \'';
  5714. if (it.opts._errorDataPathProperty) {
  5715. it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
  5716. }
  5717. if ($noAdditional) {
  5718. if ($removeAdditional) {
  5719. out += ' delete ' + ($data) + '[key' + ($lvl) + ']; ';
  5720. } else {
  5721. out += ' valid' + ($it.level) + ' = false; ';
  5722. var $currErrSchemaPath = $errSchemaPath;
  5723. $errSchemaPath = it.errSchemaPath + '/additionalProperties';
  5724. var $$outStack = $$outStack || [];
  5725. $$outStack.push(out);
  5726. out = ''; /* istanbul ignore else */
  5727. if (it.createErrors !== false) {
  5728. out += ' { keyword: \'' + ($errorKeyword || 'additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
  5729. if (it.opts.messages !== false) {
  5730. out += ' , message: \'should NOT have additional properties\' ';
  5731. }
  5732. if (it.opts.verbose) {
  5733. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5734. }
  5735. out += ' } ';
  5736. } else {
  5737. out += ' {} ';
  5738. }
  5739. var __err = out;
  5740. out = $$outStack.pop();
  5741. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5742. if (it.async) {
  5743. out += ' throw new ValidationError([' + (__err) + ']); ';
  5744. } else {
  5745. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5746. }
  5747. } else {
  5748. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5749. }
  5750. $errSchemaPath = $currErrSchemaPath;
  5751. if ($breakOnError) {
  5752. out += ' break; ';
  5753. }
  5754. }
  5755. } else if ($additionalIsSchema) {
  5756. if ($removeAdditional == 'failing') {
  5757. out += ' var ' + ($errs) + ' = errors; ';
  5758. var $wasComposite = it.compositeRule;
  5759. it.compositeRule = $it.compositeRule = true;
  5760. $it.schema = $aProperties;
  5761. $it.schemaPath = it.schemaPath + '.additionalProperties';
  5762. $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
  5763. $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
  5764. var $passData = $data + '[key' + $lvl + ']';
  5765. $it.dataPathArr[$dataNxt] = 'key' + $lvl;
  5766. var $code = it.validate($it);
  5767. if (it.util.varOccurences($code, $nextData) < 2) {
  5768. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  5769. } else {
  5770. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  5771. }
  5772. out += ' if (!valid' + ($it.level) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[key' + ($lvl) + ']; } ';
  5773. it.compositeRule = $it.compositeRule = $wasComposite;
  5774. } else {
  5775. $it.schema = $aProperties;
  5776. $it.schemaPath = it.schemaPath + '.additionalProperties';
  5777. $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
  5778. $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
  5779. var $passData = $data + '[key' + $lvl + ']';
  5780. $it.dataPathArr[$dataNxt] = 'key' + $lvl;
  5781. var $code = it.validate($it);
  5782. if (it.util.varOccurences($code, $nextData) < 2) {
  5783. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  5784. } else {
  5785. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  5786. }
  5787. if ($breakOnError) {
  5788. out += ' if (!valid' + ($it.level) + ') break; ';
  5789. }
  5790. }
  5791. }
  5792. it.errorPath = $currentErrorPath;
  5793. }
  5794. if ($someProperties) {
  5795. out += ' } ';
  5796. }
  5797. out += ' } ';
  5798. if ($breakOnError) {
  5799. out += ' if (valid' + ($it.level) + ') { ';
  5800. $closingBraces += '}';
  5801. }
  5802. }
  5803. var $useDefaults = it.opts.useDefaults && !it.compositeRule;
  5804. if ($schemaKeys.length) {
  5805. var arr4 = $schemaKeys;
  5806. if (arr4) {
  5807. var $propertyKey, i4 = -1,
  5808. l4 = arr4.length - 1;
  5809. while (i4 < l4) {
  5810. $propertyKey = arr4[i4 += 1];
  5811. var $sch = $schema[$propertyKey];
  5812. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  5813. var $prop = it.util.getProperty($propertyKey),
  5814. $passData = $data + $prop,
  5815. $hasDefault = $useDefaults && $sch.default !== undefined;
  5816. $it.schema = $sch;
  5817. $it.schemaPath = $schemaPath + $prop;
  5818. $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
  5819. $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
  5820. $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
  5821. var $code = it.validate($it);
  5822. if (it.util.varOccurences($code, $nextData) < 2) {
  5823. $code = it.util.varReplace($code, $nextData, $passData);
  5824. var $useData = $passData;
  5825. } else {
  5826. var $useData = $nextData;
  5827. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
  5828. }
  5829. if ($hasDefault) {
  5830. out += ' ' + ($code) + ' ';
  5831. } else {
  5832. if ($requiredHash && $requiredHash[$propertyKey]) {
  5833. out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = false; ';
  5834. var $currentErrorPath = it.errorPath,
  5835. $currErrSchemaPath = $errSchemaPath,
  5836. $missingProperty = it.util.escapeQuotes($propertyKey);
  5837. if (it.opts._errorDataPathProperty) {
  5838. it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
  5839. }
  5840. $errSchemaPath = it.errSchemaPath + '/required';
  5841. var $$outStack = $$outStack || [];
  5842. $$outStack.push(out);
  5843. out = ''; /* istanbul ignore else */
  5844. if (it.createErrors !== false) {
  5845. out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  5846. if (it.opts.messages !== false) {
  5847. out += ' , message: \'';
  5848. if (it.opts._errorDataPathProperty) {
  5849. out += 'is a required property';
  5850. } else {
  5851. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  5852. }
  5853. out += '\' ';
  5854. }
  5855. if (it.opts.verbose) {
  5856. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5857. }
  5858. out += ' } ';
  5859. } else {
  5860. out += ' {} ';
  5861. }
  5862. var __err = out;
  5863. out = $$outStack.pop();
  5864. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5865. if (it.async) {
  5866. out += ' throw new ValidationError([' + (__err) + ']); ';
  5867. } else {
  5868. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5869. }
  5870. } else {
  5871. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  5872. }
  5873. $errSchemaPath = $currErrSchemaPath;
  5874. it.errorPath = $currentErrorPath;
  5875. out += ' } else { ';
  5876. } else {
  5877. if ($breakOnError) {
  5878. out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = true; } else { ';
  5879. } else {
  5880. out += ' if (' + ($useData) + ' !== undefined) { ';
  5881. }
  5882. }
  5883. out += ' ' + ($code) + ' } ';
  5884. }
  5885. }
  5886. if ($breakOnError) {
  5887. out += ' if (valid' + ($it.level) + ') { ';
  5888. $closingBraces += '}';
  5889. }
  5890. }
  5891. }
  5892. }
  5893. var arr5 = $pPropertyKeys;
  5894. if (arr5) {
  5895. var $pProperty, i5 = -1,
  5896. l5 = arr5.length - 1;
  5897. while (i5 < l5) {
  5898. $pProperty = arr5[i5 += 1];
  5899. var $sch = $pProperties[$pProperty];
  5900. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  5901. $it.schema = $sch;
  5902. $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
  5903. $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
  5904. out += ' for (var key' + ($lvl) + ' in ' + ($data) + ') { if (' + (it.usePattern($pProperty)) + '.test(key' + ($lvl) + ')) { ';
  5905. $it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
  5906. var $passData = $data + '[key' + $lvl + ']';
  5907. $it.dataPathArr[$dataNxt] = 'key' + $lvl;
  5908. var $code = it.validate($it);
  5909. if (it.util.varOccurences($code, $nextData) < 2) {
  5910. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  5911. } else {
  5912. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  5913. }
  5914. if ($breakOnError) {
  5915. out += ' if (!valid' + ($it.level) + ') break; ';
  5916. }
  5917. out += ' } ';
  5918. if ($breakOnError) {
  5919. out += ' else valid' + ($it.level) + ' = true; ';
  5920. }
  5921. out += ' } ';
  5922. if ($breakOnError) {
  5923. out += ' if (valid' + ($it.level) + ') { ';
  5924. $closingBraces += '}';
  5925. }
  5926. }
  5927. }
  5928. }
  5929. if (it.opts.v5) {
  5930. var arr6 = $pgPropertyKeys;
  5931. if (arr6) {
  5932. var $pgProperty, i6 = -1,
  5933. l6 = arr6.length - 1;
  5934. while (i6 < l6) {
  5935. $pgProperty = arr6[i6 += 1];
  5936. var $pgSchema = $pgProperties[$pgProperty],
  5937. $sch = $pgSchema.schema;
  5938. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  5939. $it.schema = $sch;
  5940. $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
  5941. $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema';
  5942. out += ' var pgPropCount' + ($lvl) + ' = 0; for (var key' + ($lvl) + ' in ' + ($data) + ') { if (' + (it.usePattern($pgProperty)) + '.test(key' + ($lvl) + ')) { pgPropCount' + ($lvl) + '++; ';
  5943. $it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
  5944. var $passData = $data + '[key' + $lvl + ']';
  5945. $it.dataPathArr[$dataNxt] = 'key' + $lvl;
  5946. var $code = it.validate($it);
  5947. if (it.util.varOccurences($code, $nextData) < 2) {
  5948. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  5949. } else {
  5950. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  5951. }
  5952. if ($breakOnError) {
  5953. out += ' if (!valid' + ($it.level) + ') break; ';
  5954. }
  5955. out += ' } ';
  5956. if ($breakOnError) {
  5957. out += ' else valid' + ($it.level) + ' = true; ';
  5958. }
  5959. out += ' } ';
  5960. if ($breakOnError) {
  5961. out += ' if (valid' + ($it.level) + ') { ';
  5962. $closingBraces += '}';
  5963. }
  5964. var $pgMin = $pgSchema.minimum,
  5965. $pgMax = $pgSchema.maximum;
  5966. if ($pgMin !== undefined || $pgMax !== undefined) {
  5967. out += ' var ' + ($valid) + ' = true; ';
  5968. var $currErrSchemaPath = $errSchemaPath;
  5969. if ($pgMin !== undefined) {
  5970. var $limit = $pgMin,
  5971. $reason = 'minimum',
  5972. $moreOrLess = 'less';
  5973. out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; ';
  5974. $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum';
  5975. out += ' if (!' + ($valid) + ') { ';
  5976. var $$outStack = $$outStack || [];
  5977. $$outStack.push(out);
  5978. out = ''; /* istanbul ignore else */
  5979. if (it.createErrors !== false) {
  5980. out += ' { keyword: \'' + ($errorKeyword || 'patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
  5981. if (it.opts.messages !== false) {
  5982. out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
  5983. }
  5984. if (it.opts.verbose) {
  5985. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  5986. }
  5987. out += ' } ';
  5988. } else {
  5989. out += ' {} ';
  5990. }
  5991. var __err = out;
  5992. out = $$outStack.pop();
  5993. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  5994. if (it.async) {
  5995. out += ' throw new ValidationError([' + (__err) + ']); ';
  5996. } else {
  5997. out += ' validate.errors = [' + (__err) + ']; return false; ';
  5998. }
  5999. } else {
  6000. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6001. }
  6002. out += ' } ';
  6003. if ($pgMax !== undefined) {
  6004. out += ' else ';
  6005. }
  6006. }
  6007. if ($pgMax !== undefined) {
  6008. var $limit = $pgMax,
  6009. $reason = 'maximum',
  6010. $moreOrLess = 'more';
  6011. out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; ';
  6012. $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum';
  6013. out += ' if (!' + ($valid) + ') { ';
  6014. var $$outStack = $$outStack || [];
  6015. $$outStack.push(out);
  6016. out = ''; /* istanbul ignore else */
  6017. if (it.createErrors !== false) {
  6018. out += ' { keyword: \'' + ($errorKeyword || 'patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
  6019. if (it.opts.messages !== false) {
  6020. out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
  6021. }
  6022. if (it.opts.verbose) {
  6023. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6024. }
  6025. out += ' } ';
  6026. } else {
  6027. out += ' {} ';
  6028. }
  6029. var __err = out;
  6030. out = $$outStack.pop();
  6031. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6032. if (it.async) {
  6033. out += ' throw new ValidationError([' + (__err) + ']); ';
  6034. } else {
  6035. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6036. }
  6037. } else {
  6038. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6039. }
  6040. out += ' } ';
  6041. }
  6042. $errSchemaPath = $currErrSchemaPath;
  6043. if ($breakOnError) {
  6044. out += ' if (' + ($valid) + ') { ';
  6045. $closingBraces += '}';
  6046. }
  6047. }
  6048. }
  6049. }
  6050. }
  6051. }
  6052. if ($breakOnError) {
  6053. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  6054. }
  6055. out = it.util.cleanUpCode(out);
  6056. return out;
  6057. }
  6058. /***/ },
  6059. /* 41 */
  6060. /***/ function(module, exports) {
  6061. 'use strict';
  6062. module.exports = function generate_required(it, $keyword) {
  6063. var out = ' ';
  6064. var $lvl = it.level;
  6065. var $dataLvl = it.dataLevel;
  6066. var $schema = it.schema[$keyword];
  6067. var $schemaPath = it.schemaPath + '.' + $keyword;
  6068. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  6069. var $breakOnError = !it.opts.allErrors;
  6070. var $errorKeyword;
  6071. var $data = 'data' + ($dataLvl || '');
  6072. var $valid = 'valid' + $lvl;
  6073. var $isData = it.opts.v5 && $schema.$data;
  6074. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  6075. if ($isData) {
  6076. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  6077. $schemaValue = 'schema' + $lvl;
  6078. }
  6079. if (!$isData) {
  6080. if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
  6081. var $required = [];
  6082. var arr1 = $schema;
  6083. if (arr1) {
  6084. var $property, i1 = -1,
  6085. l1 = arr1.length - 1;
  6086. while (i1 < l1) {
  6087. $property = arr1[i1 += 1];
  6088. var $propertySch = it.schema.properties[$property];
  6089. if (!($propertySch && it.util.schemaHasRules($propertySch, it.RULES.all))) {
  6090. $required[$required.length] = $property;
  6091. }
  6092. }
  6093. }
  6094. } else {
  6095. var $required = $schema;
  6096. }
  6097. }
  6098. if ($isData || $required.length) {
  6099. var $currentErrorPath = it.errorPath,
  6100. $loopRequired = $isData || $required.length >= it.opts.loopRequired;
  6101. if ($breakOnError) {
  6102. out += ' var missing' + ($lvl) + '; ';
  6103. if ($loopRequired) {
  6104. if (!$isData) {
  6105. out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
  6106. }
  6107. var $i = 'i' + $lvl,
  6108. $propertyPath = 'schema' + $lvl + '[' + $i + ']',
  6109. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  6110. if (it.opts._errorDataPathProperty) {
  6111. it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
  6112. }
  6113. out += ' var ' + ($valid) + ' = true; ';
  6114. if ($isData) {
  6115. out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
  6116. }
  6117. out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] !== undefined; if (!' + ($valid) + ') break; } ';
  6118. if ($isData) {
  6119. out += ' } ';
  6120. }
  6121. out += ' if (!' + ($valid) + ') { ';
  6122. var $$outStack = $$outStack || [];
  6123. $$outStack.push(out);
  6124. out = ''; /* istanbul ignore else */
  6125. if (it.createErrors !== false) {
  6126. out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  6127. if (it.opts.messages !== false) {
  6128. out += ' , message: \'';
  6129. if (it.opts._errorDataPathProperty) {
  6130. out += 'is a required property';
  6131. } else {
  6132. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  6133. }
  6134. out += '\' ';
  6135. }
  6136. if (it.opts.verbose) {
  6137. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6138. }
  6139. out += ' } ';
  6140. } else {
  6141. out += ' {} ';
  6142. }
  6143. var __err = out;
  6144. out = $$outStack.pop();
  6145. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6146. if (it.async) {
  6147. out += ' throw new ValidationError([' + (__err) + ']); ';
  6148. } else {
  6149. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6150. }
  6151. } else {
  6152. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6153. }
  6154. out += ' } else { ';
  6155. } else {
  6156. out += ' if ( ';
  6157. var arr2 = $required;
  6158. if (arr2) {
  6159. var _$property, $i = -1,
  6160. l2 = arr2.length - 1;
  6161. while ($i < l2) {
  6162. _$property = arr2[$i += 1];
  6163. if ($i) {
  6164. out += ' || ';
  6165. }
  6166. var $prop = it.util.getProperty(_$property);
  6167. out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
  6168. }
  6169. }
  6170. out += ') { ';
  6171. var $propertyPath = 'missing' + $lvl,
  6172. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  6173. if (it.opts._errorDataPathProperty) {
  6174. it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
  6175. }
  6176. var $$outStack = $$outStack || [];
  6177. $$outStack.push(out);
  6178. out = ''; /* istanbul ignore else */
  6179. if (it.createErrors !== false) {
  6180. out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  6181. if (it.opts.messages !== false) {
  6182. out += ' , message: \'';
  6183. if (it.opts._errorDataPathProperty) {
  6184. out += 'is a required property';
  6185. } else {
  6186. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  6187. }
  6188. out += '\' ';
  6189. }
  6190. if (it.opts.verbose) {
  6191. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6192. }
  6193. out += ' } ';
  6194. } else {
  6195. out += ' {} ';
  6196. }
  6197. var __err = out;
  6198. out = $$outStack.pop();
  6199. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6200. if (it.async) {
  6201. out += ' throw new ValidationError([' + (__err) + ']); ';
  6202. } else {
  6203. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6204. }
  6205. } else {
  6206. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6207. }
  6208. out += ' } else { ';
  6209. }
  6210. } else {
  6211. if ($loopRequired) {
  6212. if (!$isData) {
  6213. out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
  6214. }
  6215. var $i = 'i' + $lvl,
  6216. $propertyPath = 'schema' + $lvl + '[' + $i + ']',
  6217. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  6218. if (it.opts._errorDataPathProperty) {
  6219. it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
  6220. }
  6221. if ($isData) {
  6222. out += ' if (schema' + ($lvl) + ' && !Array.isArray(schema' + ($lvl) + ')) { var err = '; /* istanbul ignore else */
  6223. if (it.createErrors !== false) {
  6224. out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  6225. if (it.opts.messages !== false) {
  6226. out += ' , message: \'';
  6227. if (it.opts._errorDataPathProperty) {
  6228. out += 'is a required property';
  6229. } else {
  6230. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  6231. }
  6232. out += '\' ';
  6233. }
  6234. if (it.opts.verbose) {
  6235. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6236. }
  6237. out += ' } ';
  6238. } else {
  6239. out += ' {} ';
  6240. }
  6241. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (schema' + ($lvl) + ' !== undefined) { ';
  6242. }
  6243. out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { if (' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] === undefined) { var err = '; /* istanbul ignore else */
  6244. if (it.createErrors !== false) {
  6245. out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  6246. if (it.opts.messages !== false) {
  6247. out += ' , message: \'';
  6248. if (it.opts._errorDataPathProperty) {
  6249. out += 'is a required property';
  6250. } else {
  6251. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  6252. }
  6253. out += '\' ';
  6254. }
  6255. if (it.opts.verbose) {
  6256. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6257. }
  6258. out += ' } ';
  6259. } else {
  6260. out += ' {} ';
  6261. }
  6262. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
  6263. if ($isData) {
  6264. out += ' } ';
  6265. }
  6266. } else {
  6267. var arr3 = $required;
  6268. if (arr3) {
  6269. var $property, $i = -1,
  6270. l3 = arr3.length - 1;
  6271. while ($i < l3) {
  6272. $property = arr3[$i += 1];
  6273. var $prop = it.util.getProperty($property),
  6274. $missingProperty = it.util.escapeQuotes($property);
  6275. if (it.opts._errorDataPathProperty) {
  6276. it.errorPath = it.util.getPath($currentErrorPath, $property, it.opts.jsonPointers);
  6277. }
  6278. out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = '; /* istanbul ignore else */
  6279. if (it.createErrors !== false) {
  6280. out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  6281. if (it.opts.messages !== false) {
  6282. out += ' , message: \'';
  6283. if (it.opts._errorDataPathProperty) {
  6284. out += 'is a required property';
  6285. } else {
  6286. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  6287. }
  6288. out += '\' ';
  6289. }
  6290. if (it.opts.verbose) {
  6291. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6292. }
  6293. out += ' } ';
  6294. } else {
  6295. out += ' {} ';
  6296. }
  6297. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  6298. }
  6299. }
  6300. }
  6301. }
  6302. it.errorPath = $currentErrorPath;
  6303. } else if ($breakOnError) {
  6304. out += ' if (true) {';
  6305. }
  6306. return out;
  6307. }
  6308. /***/ },
  6309. /* 42 */
  6310. /***/ function(module, exports) {
  6311. 'use strict';
  6312. module.exports = function generate_uniqueItems(it, $keyword) {
  6313. var out = ' ';
  6314. var $lvl = it.level;
  6315. var $dataLvl = it.dataLevel;
  6316. var $schema = it.schema[$keyword];
  6317. var $schemaPath = it.schemaPath + '.' + $keyword;
  6318. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  6319. var $breakOnError = !it.opts.allErrors;
  6320. var $errorKeyword;
  6321. var $data = 'data' + ($dataLvl || '');
  6322. var $valid = 'valid' + $lvl;
  6323. var $isData = it.opts.v5 && $schema.$data;
  6324. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  6325. if ($isData) {
  6326. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  6327. $schemaValue = 'schema' + $lvl;
  6328. }
  6329. if (($schema || $isData) && it.opts.uniqueItems !== false) {
  6330. if ($isData) {
  6331. out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
  6332. }
  6333. out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } ';
  6334. if ($isData) {
  6335. out += ' } ';
  6336. }
  6337. out += ' if (!' + ($valid) + ') { ';
  6338. var $$outStack = $$outStack || [];
  6339. $$outStack.push(out);
  6340. out = ''; /* istanbul ignore else */
  6341. if (it.createErrors !== false) {
  6342. out += ' { keyword: \'' + ($errorKeyword || 'uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { i: i, j: j } ';
  6343. if (it.opts.messages !== false) {
  6344. out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
  6345. }
  6346. if (it.opts.verbose) {
  6347. out += ' , schema: ';
  6348. if ($isData) {
  6349. out += 'validate.schema' + ($schemaPath);
  6350. } else {
  6351. out += '' + ($schema);
  6352. }
  6353. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6354. }
  6355. out += ' } ';
  6356. } else {
  6357. out += ' {} ';
  6358. }
  6359. var __err = out;
  6360. out = $$outStack.pop();
  6361. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6362. if (it.async) {
  6363. out += ' throw new ValidationError([' + (__err) + ']); ';
  6364. } else {
  6365. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6366. }
  6367. } else {
  6368. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6369. }
  6370. out += ' } ';
  6371. if ($breakOnError) {
  6372. out += ' else { ';
  6373. }
  6374. } else {
  6375. if ($breakOnError) {
  6376. out += ' if (true) { ';
  6377. }
  6378. }
  6379. return out;
  6380. }
  6381. /***/ },
  6382. /* 43 */
  6383. /***/ function(module, exports, __webpack_require__) {
  6384. 'use strict';
  6385. var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json';
  6386. module.exports = {
  6387. enable: enableV5,
  6388. META_SCHEMA_ID: META_SCHEMA_ID
  6389. };
  6390. function enableV5(ajv) {
  6391. var inlineFunctions = {
  6392. 'switch': __webpack_require__(44),
  6393. 'constant': __webpack_require__(45),
  6394. '_formatLimit': __webpack_require__(46),
  6395. 'patternRequired': __webpack_require__(47)
  6396. };
  6397. if (ajv._opts.meta !== false) {
  6398. var metaSchema = __webpack_require__(48);
  6399. ajv.addMetaSchema(metaSchema, META_SCHEMA_ID);
  6400. }
  6401. _addKeyword('constant');
  6402. ajv.addKeyword('contains', { type: 'array', macro: containsMacro });
  6403. _addKeyword('formatMaximum', 'string', inlineFunctions._formatLimit);
  6404. _addKeyword('formatMinimum', 'string', inlineFunctions._formatLimit);
  6405. ajv.addKeyword('exclusiveFormatMaximum');
  6406. ajv.addKeyword('exclusiveFormatMinimum');
  6407. ajv.addKeyword('patternGroups'); // implemented in properties.jst
  6408. _addKeyword('patternRequired', 'object');
  6409. _addKeyword('switch');
  6410. function _addKeyword(keyword, types, inlineFunc) {
  6411. var definition = {
  6412. inline: inlineFunc || inlineFunctions[keyword],
  6413. statements: true,
  6414. errors: 'full'
  6415. };
  6416. if (types) definition.type = types;
  6417. ajv.addKeyword(keyword, definition);
  6418. }
  6419. }
  6420. function containsMacro(schema) {
  6421. return {
  6422. not: { items: { not: schema } }
  6423. };
  6424. }
  6425. /***/ },
  6426. /* 44 */
  6427. /***/ function(module, exports) {
  6428. 'use strict';
  6429. module.exports = function generate_switch(it, $keyword) {
  6430. var out = ' ';
  6431. var $lvl = it.level;
  6432. var $dataLvl = it.dataLevel;
  6433. var $schema = it.schema[$keyword];
  6434. var $schemaPath = it.schemaPath + '.' + $keyword;
  6435. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  6436. var $breakOnError = !it.opts.allErrors;
  6437. var $errorKeyword;
  6438. var $data = 'data' + ($dataLvl || '');
  6439. var $valid = 'valid' + $lvl;
  6440. var $errs = 'errs__' + $lvl;
  6441. var $it = it.util.copy(it);
  6442. var $closingBraces = '';
  6443. $it.level++;
  6444. var $ifPassed = 'ifPassed' + it.level,
  6445. $shouldContinue;
  6446. out += 'var ' + ($ifPassed) + ';';
  6447. var arr1 = $schema;
  6448. if (arr1) {
  6449. var $sch, $caseIndex = -1,
  6450. l1 = arr1.length - 1;
  6451. while ($caseIndex < l1) {
  6452. $sch = arr1[$caseIndex += 1];
  6453. if ($caseIndex && !$shouldContinue) {
  6454. out += ' if (!' + ($ifPassed) + ') { ';
  6455. $closingBraces += '}';
  6456. }
  6457. if ($sch.if && it.util.schemaHasRules($sch.if, it.RULES.all)) {
  6458. out += ' var ' + ($errs) + ' = errors; ';
  6459. var $wasComposite = it.compositeRule;
  6460. it.compositeRule = $it.compositeRule = true;
  6461. $it.createErrors = false;
  6462. $it.schema = $sch.if;
  6463. $it.schemaPath = $schemaPath + '[' + $caseIndex + '].if';
  6464. $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/if';
  6465. out += ' ' + (it.validate($it)) + ' ';
  6466. $it.createErrors = true;
  6467. it.compositeRule = $it.compositeRule = $wasComposite;
  6468. out += ' ' + ($ifPassed) + ' = valid' + ($it.level) + '; if (' + ($ifPassed) + ') { ';
  6469. if (typeof $sch.then == 'boolean') {
  6470. if ($sch.then === false) {
  6471. var $$outStack = $$outStack || [];
  6472. $$outStack.push(out);
  6473. out = ''; /* istanbul ignore else */
  6474. if (it.createErrors !== false) {
  6475. out += ' { keyword: \'' + ($errorKeyword || 'switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { caseIndex: ' + ($caseIndex) + ' } ';
  6476. if (it.opts.messages !== false) {
  6477. out += ' , message: \'should pass "switch" keyword validation\' ';
  6478. }
  6479. if (it.opts.verbose) {
  6480. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6481. }
  6482. out += ' } ';
  6483. } else {
  6484. out += ' {} ';
  6485. }
  6486. var __err = out;
  6487. out = $$outStack.pop();
  6488. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6489. if (it.async) {
  6490. out += ' throw new ValidationError([' + (__err) + ']); ';
  6491. } else {
  6492. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6493. }
  6494. } else {
  6495. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6496. }
  6497. }
  6498. out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; ';
  6499. } else {
  6500. $it.schema = $sch.then;
  6501. $it.schemaPath = $schemaPath + '[' + $caseIndex + '].then';
  6502. $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then';
  6503. out += ' ' + (it.validate($it)) + ' ';
  6504. }
  6505. out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } } ';
  6506. } else {
  6507. out += ' ' + ($ifPassed) + ' = true; ';
  6508. if (typeof $sch.then == 'boolean') {
  6509. if ($sch.then === false) {
  6510. var $$outStack = $$outStack || [];
  6511. $$outStack.push(out);
  6512. out = ''; /* istanbul ignore else */
  6513. if (it.createErrors !== false) {
  6514. out += ' { keyword: \'' + ($errorKeyword || 'switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { caseIndex: ' + ($caseIndex) + ' } ';
  6515. if (it.opts.messages !== false) {
  6516. out += ' , message: \'should pass "switch" keyword validation\' ';
  6517. }
  6518. if (it.opts.verbose) {
  6519. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6520. }
  6521. out += ' } ';
  6522. } else {
  6523. out += ' {} ';
  6524. }
  6525. var __err = out;
  6526. out = $$outStack.pop();
  6527. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6528. if (it.async) {
  6529. out += ' throw new ValidationError([' + (__err) + ']); ';
  6530. } else {
  6531. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6532. }
  6533. } else {
  6534. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6535. }
  6536. }
  6537. out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; ';
  6538. } else {
  6539. $it.schema = $sch.then;
  6540. $it.schemaPath = $schemaPath + '[' + $caseIndex + '].then';
  6541. $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then';
  6542. out += ' ' + (it.validate($it)) + ' ';
  6543. }
  6544. }
  6545. $shouldContinue = $sch.continue
  6546. }
  6547. }
  6548. out += '' + ($closingBraces) + 'var ' + ($valid) + ' = valid' + ($it.level) + '; ';
  6549. out = it.util.cleanUpCode(out);
  6550. return out;
  6551. }
  6552. /***/ },
  6553. /* 45 */
  6554. /***/ function(module, exports) {
  6555. 'use strict';
  6556. module.exports = function generate_constant(it, $keyword) {
  6557. var out = ' ';
  6558. var $lvl = it.level;
  6559. var $dataLvl = it.dataLevel;
  6560. var $schema = it.schema[$keyword];
  6561. var $schemaPath = it.schemaPath + '.' + $keyword;
  6562. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  6563. var $breakOnError = !it.opts.allErrors;
  6564. var $errorKeyword;
  6565. var $data = 'data' + ($dataLvl || '');
  6566. var $valid = 'valid' + $lvl;
  6567. var $isData = it.opts.v5 && $schema.$data;
  6568. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  6569. if ($isData) {
  6570. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  6571. $schemaValue = 'schema' + $lvl;
  6572. }
  6573. if (!$isData) {
  6574. out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
  6575. }
  6576. out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
  6577. var $$outStack = $$outStack || [];
  6578. $$outStack.push(out);
  6579. out = ''; /* istanbul ignore else */
  6580. if (it.createErrors !== false) {
  6581. out += ' { keyword: \'' + ($errorKeyword || 'constant') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  6582. if (it.opts.messages !== false) {
  6583. out += ' , message: \'should be equal to constant\' ';
  6584. }
  6585. if (it.opts.verbose) {
  6586. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6587. }
  6588. out += ' } ';
  6589. } else {
  6590. out += ' {} ';
  6591. }
  6592. var __err = out;
  6593. out = $$outStack.pop();
  6594. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6595. if (it.async) {
  6596. out += ' throw new ValidationError([' + (__err) + ']); ';
  6597. } else {
  6598. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6599. }
  6600. } else {
  6601. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6602. }
  6603. out += ' }';
  6604. return out;
  6605. }
  6606. /***/ },
  6607. /* 46 */
  6608. /***/ function(module, exports) {
  6609. 'use strict';
  6610. module.exports = function generate__formatLimit(it, $keyword) {
  6611. var out = ' ';
  6612. var $lvl = it.level;
  6613. var $dataLvl = it.dataLevel;
  6614. var $schema = it.schema[$keyword];
  6615. var $schemaPath = it.schemaPath + '.' + $keyword;
  6616. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  6617. var $breakOnError = !it.opts.allErrors;
  6618. var $errorKeyword;
  6619. var $data = 'data' + ($dataLvl || '');
  6620. var $valid = 'valid' + $lvl;
  6621. out += 'var ' + ($valid) + ' = undefined;';
  6622. if (it.opts.format === false) {
  6623. out += ' ' + ($valid) + ' = true; ';
  6624. return out;
  6625. }
  6626. var $schemaFormat = it.schema.format,
  6627. $isDataFormat = it.opts.v5 && $schemaFormat.$data,
  6628. $closingBraces = '';
  6629. if ($isDataFormat) {
  6630. var $schemaValueFormat = it.util.getData($schemaFormat.$data, $dataLvl, it.dataPathArr),
  6631. $format = 'format' + $lvl,
  6632. $compare = 'compare' + $lvl;
  6633. out += ' var ' + ($format) + ' = formats[' + ($schemaValueFormat) + '] , ' + ($compare) + ' = ' + ($format) + ' && ' + ($format) + '.compare;';
  6634. } else {
  6635. var $format = it.formats[$schemaFormat];
  6636. if (!($format && $format.compare)) {
  6637. out += ' ' + ($valid) + ' = true; ';
  6638. return out;
  6639. }
  6640. var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare';
  6641. }
  6642. var $isMax = $keyword == 'formatMaximum',
  6643. $exclusiveKeyword = 'exclusiveFormat' + ($isMax ? 'Maximum' : 'Minimum'),
  6644. $schemaExcl = it.schema[$exclusiveKeyword],
  6645. $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
  6646. $op = $isMax ? '<' : '>',
  6647. $result = 'result' + $lvl;
  6648. var $isData = it.opts.v5 && $schema.$data;
  6649. var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
  6650. if ($isData) {
  6651. out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
  6652. $schemaValue = 'schema' + $lvl;
  6653. }
  6654. if ($isDataExcl) {
  6655. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
  6656. $exclusive = 'exclusive' + $lvl,
  6657. $opExpr = 'op' + $lvl,
  6658. $opStr = '\' + ' + $opExpr + ' + \'';
  6659. out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
  6660. $schemaValueExcl = 'schemaExcl' + $lvl;
  6661. out += ' if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && ' + ($schemaValueExcl) + ' !== undefined) { ' + ($valid) + ' = false; ';
  6662. var $errorKeyword = $exclusiveKeyword;
  6663. var $$outStack = $$outStack || [];
  6664. $$outStack.push(out);
  6665. out = ''; /* istanbul ignore else */
  6666. if (it.createErrors !== false) {
  6667. out += ' { keyword: \'' + ($errorKeyword || '_exclusiveFormatLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
  6668. if (it.opts.messages !== false) {
  6669. out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
  6670. }
  6671. if (it.opts.verbose) {
  6672. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6673. }
  6674. out += ' } ';
  6675. } else {
  6676. out += ' {} ';
  6677. }
  6678. var __err = out;
  6679. out = $$outStack.pop();
  6680. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6681. if (it.async) {
  6682. out += ' throw new ValidationError([' + (__err) + ']); ';
  6683. } else {
  6684. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6685. }
  6686. } else {
  6687. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6688. }
  6689. out += ' } ';
  6690. if ($breakOnError) {
  6691. $closingBraces += '}';
  6692. out += ' else { ';
  6693. }
  6694. if ($isData) {
  6695. out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
  6696. $closingBraces += '}';
  6697. }
  6698. if ($isDataFormat) {
  6699. out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
  6700. $closingBraces += '}';
  6701. }
  6702. out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', ';
  6703. if ($isData) {
  6704. out += '' + ($schemaValue);
  6705. } else {
  6706. out += '' + (it.util.toQuotedString($schema));
  6707. }
  6708. out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; var exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true; if (' + ($valid) + ' === undefined) { ' + ($valid) + ' = exclusive' + ($lvl) + ' ? ' + ($result) + ' ' + ($op) + ' 0 : ' + ($result) + ' ' + ($op) + '= 0; } if (!' + ($valid) + ') var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
  6709. } else {
  6710. var $exclusive = $schemaExcl === true,
  6711. $opStr = $op;
  6712. if (!$exclusive) $opStr += '=';
  6713. var $opExpr = '\'' + $opStr + '\'';
  6714. if ($isData) {
  6715. out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
  6716. $closingBraces += '}';
  6717. }
  6718. if ($isDataFormat) {
  6719. out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
  6720. $closingBraces += '}';
  6721. }
  6722. out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', ';
  6723. if ($isData) {
  6724. out += '' + ($schemaValue);
  6725. } else {
  6726. out += '' + (it.util.toQuotedString($schema));
  6727. }
  6728. out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; if (' + ($valid) + ' === undefined) ' + ($valid) + ' = ' + ($result) + ' ' + ($op);
  6729. if (!$exclusive) {
  6730. out += '=';
  6731. }
  6732. out += ' 0;';
  6733. }
  6734. out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
  6735. var $errorKeyword = $keyword;
  6736. var $$outStack = $$outStack || [];
  6737. $$outStack.push(out);
  6738. out = ''; /* istanbul ignore else */
  6739. if (it.createErrors !== false) {
  6740. out += ' { keyword: \'' + ($errorKeyword || '_formatLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ';
  6741. if ($isData) {
  6742. out += '' + ($schemaValue);
  6743. } else {
  6744. out += '' + (it.util.toQuotedString($schema));
  6745. }
  6746. out += ' } ';
  6747. if (it.opts.messages !== false) {
  6748. out += ' , message: \'should be ' + ($opStr) + ' "';
  6749. if ($isData) {
  6750. out += '\' + ' + ($schemaValue) + ' + \'';
  6751. } else {
  6752. out += '' + (it.util.escapeQuotes($schema));
  6753. }
  6754. out += '"\' ';
  6755. }
  6756. if (it.opts.verbose) {
  6757. out += ' , schema: ';
  6758. if ($isData) {
  6759. out += 'validate.schema' + ($schemaPath);
  6760. } else {
  6761. out += '' + (it.util.toQuotedString($schema));
  6762. }
  6763. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6764. }
  6765. out += ' } ';
  6766. } else {
  6767. out += ' {} ';
  6768. }
  6769. var __err = out;
  6770. out = $$outStack.pop();
  6771. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  6772. if (it.async) {
  6773. out += ' throw new ValidationError([' + (__err) + ']); ';
  6774. } else {
  6775. out += ' validate.errors = [' + (__err) + ']; return false; ';
  6776. }
  6777. } else {
  6778. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  6779. }
  6780. out += '}';
  6781. return out;
  6782. }
  6783. /***/ },
  6784. /* 47 */
  6785. /***/ function(module, exports) {
  6786. 'use strict';
  6787. module.exports = function generate_patternRequired(it, $keyword) {
  6788. var out = ' ';
  6789. var $lvl = it.level;
  6790. var $dataLvl = it.dataLevel;
  6791. var $schema = it.schema[$keyword];
  6792. var $schemaPath = it.schemaPath + '.' + $keyword;
  6793. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  6794. var $breakOnError = !it.opts.allErrors;
  6795. var $errorKeyword;
  6796. var $data = 'data' + ($dataLvl || '');
  6797. var $valid = 'valid' + $lvl;
  6798. var $key = 'key' + $lvl,
  6799. $matched = 'patternMatched' + $lvl,
  6800. $closingBraces = '';
  6801. out += 'var ' + ($valid) + ' = true;';
  6802. var arr1 = $schema;
  6803. if (arr1) {
  6804. var $pProperty, i1 = -1,
  6805. l1 = arr1.length - 1;
  6806. while (i1 < l1) {
  6807. $pProperty = arr1[i1 += 1];
  6808. out += ' var ' + ($matched) + ' = false; for (var ' + ($key) + ' in ' + ($data) + ') { ' + ($matched) + ' = ' + (it.usePattern($pProperty)) + '.test(' + ($key) + '); if (' + ($matched) + ') break; } ';
  6809. var $missingPattern = it.util.escapeQuotes($pProperty);
  6810. out += ' if (!' + ($matched) + ') { ' + ($valid) + ' = false; var err = '; /* istanbul ignore else */
  6811. if (it.createErrors !== false) {
  6812. out += ' { keyword: \'' + ($errorKeyword || 'patternRequired') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingPattern: \'' + ($missingPattern) + '\' } ';
  6813. if (it.opts.messages !== false) {
  6814. out += ' , message: \'should have property matching pattern \\\'' + ($missingPattern) + '\\\'\' ';
  6815. }
  6816. if (it.opts.verbose) {
  6817. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  6818. }
  6819. out += ' } ';
  6820. } else {
  6821. out += ' {} ';
  6822. }
  6823. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  6824. if ($breakOnError) {
  6825. $closingBraces += '}';
  6826. out += ' else { ';
  6827. }
  6828. }
  6829. }
  6830. out += '' + ($closingBraces);
  6831. return out;
  6832. }
  6833. /***/ },
  6834. /* 48 */
  6835. /***/ function(module, exports) {
  6836. module.exports = {
  6837. "id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#",
  6838. "$schema": "http://json-schema.org/draft-04/schema#",
  6839. "description": "Core schema meta-schema (v5 proposals)",
  6840. "definitions": {
  6841. "schemaArray": {
  6842. "type": "array",
  6843. "minItems": 1,
  6844. "items": {
  6845. "$ref": "#"
  6846. }
  6847. },
  6848. "positiveInteger": {
  6849. "type": "integer",
  6850. "minimum": 0
  6851. },
  6852. "positiveIntegerDefault0": {
  6853. "allOf": [
  6854. {
  6855. "$ref": "#/definitions/positiveInteger"
  6856. },
  6857. {
  6858. "default": 0
  6859. }
  6860. ]
  6861. },
  6862. "simpleTypes": {
  6863. "enum": [
  6864. "array",
  6865. "boolean",
  6866. "integer",
  6867. "null",
  6868. "number",
  6869. "object",
  6870. "string"
  6871. ]
  6872. },
  6873. "stringArray": {
  6874. "type": "array",
  6875. "items": {
  6876. "type": "string"
  6877. },
  6878. "minItems": 1,
  6879. "uniqueItems": true
  6880. },
  6881. "$data": {
  6882. "type": "object",
  6883. "required": [
  6884. "$data"
  6885. ],
  6886. "properties": {
  6887. "$data": {
  6888. "type": "string",
  6889. "format": "relative-json-pointer"
  6890. }
  6891. },
  6892. "additionalProperties": false
  6893. }
  6894. },
  6895. "type": "object",
  6896. "properties": {
  6897. "id": {
  6898. "type": "string",
  6899. "format": "uri"
  6900. },
  6901. "$schema": {
  6902. "type": "string",
  6903. "format": "uri"
  6904. },
  6905. "title": {
  6906. "type": "string"
  6907. },
  6908. "description": {
  6909. "type": "string"
  6910. },
  6911. "default": {},
  6912. "multipleOf": {
  6913. "anyOf": [
  6914. {
  6915. "type": "number",
  6916. "minimum": 0,
  6917. "exclusiveMinimum": true
  6918. },
  6919. {
  6920. "$ref": "#/definitions/$data"
  6921. }
  6922. ]
  6923. },
  6924. "maximum": {
  6925. "anyOf": [
  6926. {
  6927. "type": "number"
  6928. },
  6929. {
  6930. "$ref": "#/definitions/$data"
  6931. }
  6932. ]
  6933. },
  6934. "exclusiveMaximum": {
  6935. "anyOf": [
  6936. {
  6937. "type": "boolean",
  6938. "default": false
  6939. },
  6940. {
  6941. "$ref": "#/definitions/$data"
  6942. }
  6943. ]
  6944. },
  6945. "minimum": {
  6946. "anyOf": [
  6947. {
  6948. "type": "number"
  6949. },
  6950. {
  6951. "$ref": "#/definitions/$data"
  6952. }
  6953. ]
  6954. },
  6955. "exclusiveMinimum": {
  6956. "anyOf": [
  6957. {
  6958. "type": "boolean",
  6959. "default": false
  6960. },
  6961. {
  6962. "$ref": "#/definitions/$data"
  6963. }
  6964. ]
  6965. },
  6966. "maxLength": {
  6967. "anyOf": [
  6968. {
  6969. "$ref": "#/definitions/positiveInteger"
  6970. },
  6971. {
  6972. "$ref": "#/definitions/$data"
  6973. }
  6974. ]
  6975. },
  6976. "minLength": {
  6977. "anyOf": [
  6978. {
  6979. "$ref": "#/definitions/positiveIntegerDefault0"
  6980. },
  6981. {
  6982. "$ref": "#/definitions/$data"
  6983. }
  6984. ]
  6985. },
  6986. "pattern": {
  6987. "anyOf": [
  6988. {
  6989. "type": "string",
  6990. "format": "regex"
  6991. },
  6992. {
  6993. "$ref": "#/definitions/$data"
  6994. }
  6995. ]
  6996. },
  6997. "additionalItems": {
  6998. "anyOf": [
  6999. {
  7000. "type": "boolean"
  7001. },
  7002. {
  7003. "$ref": "#"
  7004. },
  7005. {
  7006. "$ref": "#/definitions/$data"
  7007. }
  7008. ],
  7009. "default": {}
  7010. },
  7011. "items": {
  7012. "anyOf": [
  7013. {
  7014. "$ref": "#"
  7015. },
  7016. {
  7017. "$ref": "#/definitions/schemaArray"
  7018. }
  7019. ],
  7020. "default": {}
  7021. },
  7022. "maxItems": {
  7023. "anyOf": [
  7024. {
  7025. "$ref": "#/definitions/positiveInteger"
  7026. },
  7027. {
  7028. "$ref": "#/definitions/$data"
  7029. }
  7030. ]
  7031. },
  7032. "minItems": {
  7033. "anyOf": [
  7034. {
  7035. "$ref": "#/definitions/positiveIntegerDefault0"
  7036. },
  7037. {
  7038. "$ref": "#/definitions/$data"
  7039. }
  7040. ]
  7041. },
  7042. "uniqueItems": {
  7043. "anyOf": [
  7044. {
  7045. "type": "boolean",
  7046. "default": false
  7047. },
  7048. {
  7049. "$ref": "#/definitions/$data"
  7050. }
  7051. ]
  7052. },
  7053. "maxProperties": {
  7054. "anyOf": [
  7055. {
  7056. "$ref": "#/definitions/positiveInteger"
  7057. },
  7058. {
  7059. "$ref": "#/definitions/$data"
  7060. }
  7061. ]
  7062. },
  7063. "minProperties": {
  7064. "anyOf": [
  7065. {
  7066. "$ref": "#/definitions/positiveIntegerDefault0"
  7067. },
  7068. {
  7069. "$ref": "#/definitions/$data"
  7070. }
  7071. ]
  7072. },
  7073. "required": {
  7074. "anyOf": [
  7075. {
  7076. "$ref": "#/definitions/stringArray"
  7077. },
  7078. {
  7079. "$ref": "#/definitions/$data"
  7080. }
  7081. ]
  7082. },
  7083. "additionalProperties": {
  7084. "anyOf": [
  7085. {
  7086. "type": "boolean"
  7087. },
  7088. {
  7089. "$ref": "#"
  7090. },
  7091. {
  7092. "$ref": "#/definitions/$data"
  7093. }
  7094. ],
  7095. "default": {}
  7096. },
  7097. "definitions": {
  7098. "type": "object",
  7099. "additionalProperties": {
  7100. "$ref": "#"
  7101. },
  7102. "default": {}
  7103. },
  7104. "properties": {
  7105. "type": "object",
  7106. "additionalProperties": {
  7107. "$ref": "#"
  7108. },
  7109. "default": {}
  7110. },
  7111. "patternProperties": {
  7112. "type": "object",
  7113. "additionalProperties": {
  7114. "$ref": "#"
  7115. },
  7116. "default": {}
  7117. },
  7118. "dependencies": {
  7119. "type": "object",
  7120. "additionalProperties": {
  7121. "anyOf": [
  7122. {
  7123. "$ref": "#"
  7124. },
  7125. {
  7126. "$ref": "#/definitions/stringArray"
  7127. }
  7128. ]
  7129. }
  7130. },
  7131. "enum": {
  7132. "anyOf": [
  7133. {
  7134. "type": "array",
  7135. "minItems": 1,
  7136. "uniqueItems": true
  7137. },
  7138. {
  7139. "$ref": "#/definitions/$data"
  7140. }
  7141. ]
  7142. },
  7143. "type": {
  7144. "anyOf": [
  7145. {
  7146. "$ref": "#/definitions/simpleTypes"
  7147. },
  7148. {
  7149. "type": "array",
  7150. "items": {
  7151. "$ref": "#/definitions/simpleTypes"
  7152. },
  7153. "minItems": 1,
  7154. "uniqueItems": true
  7155. }
  7156. ]
  7157. },
  7158. "allOf": {
  7159. "$ref": "#/definitions/schemaArray"
  7160. },
  7161. "anyOf": {
  7162. "$ref": "#/definitions/schemaArray"
  7163. },
  7164. "oneOf": {
  7165. "$ref": "#/definitions/schemaArray"
  7166. },
  7167. "not": {
  7168. "$ref": "#"
  7169. },
  7170. "format": {
  7171. "anyOf": [
  7172. {
  7173. "type": "string"
  7174. },
  7175. {
  7176. "$ref": "#/definitions/$data"
  7177. }
  7178. ]
  7179. },
  7180. "formatMaximum": {
  7181. "anyOf": [
  7182. {
  7183. "type": "string"
  7184. },
  7185. {
  7186. "$ref": "#/definitions/$data"
  7187. }
  7188. ]
  7189. },
  7190. "formatMinimum": {
  7191. "anyOf": [
  7192. {
  7193. "type": "string"
  7194. },
  7195. {
  7196. "$ref": "#/definitions/$data"
  7197. }
  7198. ]
  7199. },
  7200. "exclusiveFormatMaximum": {
  7201. "anyOf": [
  7202. {
  7203. "type": "boolean",
  7204. "default": false
  7205. },
  7206. {
  7207. "$ref": "#/definitions/$data"
  7208. }
  7209. ]
  7210. },
  7211. "exclusiveFormatMinimum": {
  7212. "anyOf": [
  7213. {
  7214. "type": "boolean",
  7215. "default": false
  7216. },
  7217. {
  7218. "$ref": "#/definitions/$data"
  7219. }
  7220. ]
  7221. },
  7222. "constant": {
  7223. "anyOf": [
  7224. {},
  7225. {
  7226. "$ref": "#/definitions/$data"
  7227. }
  7228. ]
  7229. },
  7230. "contains": {
  7231. "$ref": "#"
  7232. },
  7233. "patternGroups": {
  7234. "type": "object",
  7235. "additionalProperties": {
  7236. "type": "object",
  7237. "required": [
  7238. "schema"
  7239. ],
  7240. "properties": {
  7241. "maximum": {
  7242. "anyOf": [
  7243. {
  7244. "$ref": "#/definitions/positiveInteger"
  7245. },
  7246. {
  7247. "$ref": "#/definitions/$data"
  7248. }
  7249. ]
  7250. },
  7251. "minimum": {
  7252. "anyOf": [
  7253. {
  7254. "$ref": "#/definitions/positiveIntegerDefault0"
  7255. },
  7256. {
  7257. "$ref": "#/definitions/$data"
  7258. }
  7259. ]
  7260. },
  7261. "schema": {
  7262. "$ref": "#"
  7263. }
  7264. },
  7265. "additionalProperties": false
  7266. },
  7267. "default": {}
  7268. },
  7269. "switch": {
  7270. "type": "array",
  7271. "items": {
  7272. "required": [
  7273. "then"
  7274. ],
  7275. "properties": {
  7276. "if": {
  7277. "$ref": "#"
  7278. },
  7279. "then": {
  7280. "anyOf": [
  7281. {
  7282. "type": "boolean"
  7283. },
  7284. {
  7285. "$ref": "#"
  7286. }
  7287. ]
  7288. },
  7289. "continue": {
  7290. "type": "boolean"
  7291. }
  7292. },
  7293. "additionalProperties": false,
  7294. "dependencies": {
  7295. "continue": [
  7296. "if"
  7297. ]
  7298. }
  7299. }
  7300. }
  7301. },
  7302. "dependencies": {
  7303. "exclusiveMaximum": [
  7304. "maximum"
  7305. ],
  7306. "exclusiveMinimum": [
  7307. "minimum"
  7308. ],
  7309. "formatMaximum": [
  7310. "format"
  7311. ],
  7312. "formatMinimum": [
  7313. "format"
  7314. ],
  7315. "exclusiveFormatMaximum": [
  7316. "formatMaximum"
  7317. ],
  7318. "exclusiveFormatMinimum": [
  7319. "formatMinimum"
  7320. ]
  7321. },
  7322. "default": {}
  7323. };
  7324. /***/ },
  7325. /* 49 */
  7326. /***/ function(module, exports) {
  7327. 'use strict';
  7328. var IDENTIFIER = /^[a-z_$][a-z0-9_$]*$/i;
  7329. /**
  7330. * Define custom keyword
  7331. * @this Ajv
  7332. * @param {String} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
  7333. * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
  7334. */
  7335. module.exports = function addKeyword(keyword, definition) {
  7336. /* eslint no-shadow: 0 */
  7337. var self = this;
  7338. if (this.RULES.keywords[keyword])
  7339. throw new Error('Keyword ' + keyword + ' is already defined');
  7340. if (!IDENTIFIER.test(keyword))
  7341. throw new Error('Keyword ' + keyword + ' is not a valid identifier');
  7342. if (definition) {
  7343. var dataType = definition.type;
  7344. if (Array.isArray(dataType)) {
  7345. var i, len = dataType.length;
  7346. for (i=0; i<len; i++) checkDataType(dataType[i]);
  7347. for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition);
  7348. } else {
  7349. if (dataType) checkDataType(dataType);
  7350. _addRule(keyword, dataType, definition);
  7351. }
  7352. }
  7353. this.RULES.keywords[keyword] = true;
  7354. this.RULES.all[keyword] = true;
  7355. function _addRule(keyword, dataType, definition) {
  7356. var ruleGroup;
  7357. for (var i=0; i<self.RULES.length; i++) {
  7358. var rg = self.RULES[i];
  7359. if (rg.type == dataType) {
  7360. ruleGroup = rg;
  7361. break;
  7362. }
  7363. }
  7364. if (!ruleGroup) {
  7365. ruleGroup = { type: dataType, rules: [] };
  7366. self.RULES.push(ruleGroup);
  7367. }
  7368. var rule = { keyword: keyword, definition: definition, custom: true };
  7369. ruleGroup.rules.push(rule);
  7370. }
  7371. function checkDataType(dataType) {
  7372. if (!self.RULES.types[dataType]) throw new Error('Unknown type ' + dataType);
  7373. }
  7374. };
  7375. /***/ },
  7376. /* 50 */
  7377. /***/ function(module, exports) {
  7378. module.exports = {
  7379. "id": "http://json-schema.org/draft-04/schema#",
  7380. "$schema": "http://json-schema.org/draft-04/schema#",
  7381. "description": "Core schema meta-schema",
  7382. "definitions": {
  7383. "schemaArray": {
  7384. "type": "array",
  7385. "minItems": 1,
  7386. "items": {
  7387. "$ref": "#"
  7388. }
  7389. },
  7390. "positiveInteger": {
  7391. "type": "integer",
  7392. "minimum": 0
  7393. },
  7394. "positiveIntegerDefault0": {
  7395. "allOf": [
  7396. {
  7397. "$ref": "#/definitions/positiveInteger"
  7398. },
  7399. {
  7400. "default": 0
  7401. }
  7402. ]
  7403. },
  7404. "simpleTypes": {
  7405. "enum": [
  7406. "array",
  7407. "boolean",
  7408. "integer",
  7409. "null",
  7410. "number",
  7411. "object",
  7412. "string"
  7413. ]
  7414. },
  7415. "stringArray": {
  7416. "type": "array",
  7417. "items": {
  7418. "type": "string"
  7419. },
  7420. "minItems": 1,
  7421. "uniqueItems": true
  7422. }
  7423. },
  7424. "type": "object",
  7425. "properties": {
  7426. "id": {
  7427. "type": "string",
  7428. "format": "uri"
  7429. },
  7430. "$schema": {
  7431. "type": "string",
  7432. "format": "uri"
  7433. },
  7434. "title": {
  7435. "type": "string"
  7436. },
  7437. "description": {
  7438. "type": "string"
  7439. },
  7440. "default": {},
  7441. "multipleOf": {
  7442. "type": "number",
  7443. "minimum": 0,
  7444. "exclusiveMinimum": true
  7445. },
  7446. "maximum": {
  7447. "type": "number"
  7448. },
  7449. "exclusiveMaximum": {
  7450. "type": "boolean",
  7451. "default": false
  7452. },
  7453. "minimum": {
  7454. "type": "number"
  7455. },
  7456. "exclusiveMinimum": {
  7457. "type": "boolean",
  7458. "default": false
  7459. },
  7460. "maxLength": {
  7461. "$ref": "#/definitions/positiveInteger"
  7462. },
  7463. "minLength": {
  7464. "$ref": "#/definitions/positiveIntegerDefault0"
  7465. },
  7466. "pattern": {
  7467. "type": "string",
  7468. "format": "regex"
  7469. },
  7470. "additionalItems": {
  7471. "anyOf": [
  7472. {
  7473. "type": "boolean"
  7474. },
  7475. {
  7476. "$ref": "#"
  7477. }
  7478. ],
  7479. "default": {}
  7480. },
  7481. "items": {
  7482. "anyOf": [
  7483. {
  7484. "$ref": "#"
  7485. },
  7486. {
  7487. "$ref": "#/definitions/schemaArray"
  7488. }
  7489. ],
  7490. "default": {}
  7491. },
  7492. "maxItems": {
  7493. "$ref": "#/definitions/positiveInteger"
  7494. },
  7495. "minItems": {
  7496. "$ref": "#/definitions/positiveIntegerDefault0"
  7497. },
  7498. "uniqueItems": {
  7499. "type": "boolean",
  7500. "default": false
  7501. },
  7502. "maxProperties": {
  7503. "$ref": "#/definitions/positiveInteger"
  7504. },
  7505. "minProperties": {
  7506. "$ref": "#/definitions/positiveIntegerDefault0"
  7507. },
  7508. "required": {
  7509. "$ref": "#/definitions/stringArray"
  7510. },
  7511. "additionalProperties": {
  7512. "anyOf": [
  7513. {
  7514. "type": "boolean"
  7515. },
  7516. {
  7517. "$ref": "#"
  7518. }
  7519. ],
  7520. "default": {}
  7521. },
  7522. "definitions": {
  7523. "type": "object",
  7524. "additionalProperties": {
  7525. "$ref": "#"
  7526. },
  7527. "default": {}
  7528. },
  7529. "properties": {
  7530. "type": "object",
  7531. "additionalProperties": {
  7532. "$ref": "#"
  7533. },
  7534. "default": {}
  7535. },
  7536. "patternProperties": {
  7537. "type": "object",
  7538. "additionalProperties": {
  7539. "$ref": "#"
  7540. },
  7541. "default": {}
  7542. },
  7543. "dependencies": {
  7544. "type": "object",
  7545. "additionalProperties": {
  7546. "anyOf": [
  7547. {
  7548. "$ref": "#"
  7549. },
  7550. {
  7551. "$ref": "#/definitions/stringArray"
  7552. }
  7553. ]
  7554. }
  7555. },
  7556. "enum": {
  7557. "type": "array",
  7558. "minItems": 1,
  7559. "uniqueItems": true
  7560. },
  7561. "type": {
  7562. "anyOf": [
  7563. {
  7564. "$ref": "#/definitions/simpleTypes"
  7565. },
  7566. {
  7567. "type": "array",
  7568. "items": {
  7569. "$ref": "#/definitions/simpleTypes"
  7570. },
  7571. "minItems": 1,
  7572. "uniqueItems": true
  7573. }
  7574. ]
  7575. },
  7576. "allOf": {
  7577. "$ref": "#/definitions/schemaArray"
  7578. },
  7579. "anyOf": {
  7580. "$ref": "#/definitions/schemaArray"
  7581. },
  7582. "oneOf": {
  7583. "$ref": "#/definitions/schemaArray"
  7584. },
  7585. "not": {
  7586. "$ref": "#"
  7587. }
  7588. },
  7589. "dependencies": {
  7590. "exclusiveMaximum": [
  7591. "maximum"
  7592. ],
  7593. "exclusiveMinimum": [
  7594. "minimum"
  7595. ]
  7596. },
  7597. "default": {}
  7598. };
  7599. /***/ },
  7600. /* 51 */
  7601. /***/ function(module, exports, __webpack_require__) {
  7602. 'use strict';
  7603. var Highlighter = __webpack_require__(52);
  7604. var History = __webpack_require__(53);
  7605. var SearchBox = __webpack_require__(56);
  7606. var ContextMenu = __webpack_require__(57);
  7607. var Node = __webpack_require__(58);
  7608. var ModeSwitcher = __webpack_require__(61);
  7609. var util = __webpack_require__(54);
  7610. // create a mixin with the functions for tree mode
  7611. var treemode = {};
  7612. /**
  7613. * Create a tree editor
  7614. * @param {Element} container Container element
  7615. * @param {Object} [options] Object with options. available options:
  7616. * {String} mode Editor mode. Available values:
  7617. * 'tree' (default), 'view',
  7618. * and 'form'.
  7619. * {Boolean} search Enable search box.
  7620. * True by default
  7621. * {Boolean} history Enable history (undo/redo).
  7622. * True by default
  7623. * {function} onChange Callback method, triggered
  7624. * on change of contents
  7625. * {String} name Field name for the root node.
  7626. * {boolean} escapeUnicode If true, unicode
  7627. * characters are escaped.
  7628. * false by default.
  7629. * {Object} schema A JSON Schema for validation
  7630. * @private
  7631. */
  7632. treemode.create = function (container, options) {
  7633. if (!container) {
  7634. throw new Error('No container element provided.');
  7635. }
  7636. this.container = container;
  7637. this.dom = {};
  7638. this.highlighter = new Highlighter();
  7639. this.selection = undefined; // will hold the last input selection
  7640. this.multiselection = {
  7641. nodes: []
  7642. };
  7643. this.validateSchema = null; // will be set in .setSchema(schema)
  7644. this.errorNodes = [];
  7645. this.node = null;
  7646. this.focusTarget = null;
  7647. this._setOptions(options);
  7648. if (this.options.history && this.options.mode !== 'view') {
  7649. this.history = new History(this);
  7650. }
  7651. this._createFrame();
  7652. this._createTable();
  7653. };
  7654. /**
  7655. * Destroy the editor. Clean up DOM, event listeners, and web workers.
  7656. */
  7657. treemode.destroy = function () {
  7658. if (this.frame && this.container && this.frame.parentNode == this.container) {
  7659. this.container.removeChild(this.frame);
  7660. this.frame = null;
  7661. }
  7662. this.container = null;
  7663. this.dom = null;
  7664. this.clear();
  7665. this.node = null;
  7666. this.focusTarget = null;
  7667. this.selection = null;
  7668. this.multiselection = null;
  7669. this.errorNodes = null;
  7670. this.validateSchema = null;
  7671. this._debouncedValidate = null;
  7672. if (this.history) {
  7673. this.history.destroy();
  7674. this.history = null;
  7675. }
  7676. if (this.searchBox) {
  7677. this.searchBox.destroy();
  7678. this.searchBox = null;
  7679. }
  7680. if (this.modeSwitcher) {
  7681. this.modeSwitcher.destroy();
  7682. this.modeSwitcher = null;
  7683. }
  7684. };
  7685. /**
  7686. * Initialize and set default options
  7687. * @param {Object} [options] See description in constructor
  7688. * @private
  7689. */
  7690. treemode._setOptions = function (options) {
  7691. this.options = {
  7692. search: true,
  7693. history: true,
  7694. mode: 'tree',
  7695. name: undefined, // field name of root node
  7696. schema: null
  7697. };
  7698. // copy all options
  7699. if (options) {
  7700. for (var prop in options) {
  7701. if (options.hasOwnProperty(prop)) {
  7702. this.options[prop] = options[prop];
  7703. }
  7704. }
  7705. }
  7706. // compile a JSON schema validator if a JSON schema is provided
  7707. this.setSchema(this.options.schema);
  7708. // create a debounced validate function
  7709. this._debouncedValidate = util.debounce(this.validate.bind(this), this.DEBOUNCE_INTERVAL);
  7710. };
  7711. /**
  7712. * Set JSON object in editor
  7713. * @param {Object | undefined} json JSON data
  7714. * @param {String} [name] Optional field name for the root node.
  7715. * Can also be set using setName(name).
  7716. */
  7717. treemode.set = function (json, name) {
  7718. // adjust field name for root node
  7719. if (name) {
  7720. // TODO: deprecated since version 2.2.0. Cleanup some day.
  7721. console.warn('Second parameter "name" is deprecated. Use setName(name) instead.');
  7722. this.options.name = name;
  7723. }
  7724. // verify if json is valid JSON, ignore when a function
  7725. if (json instanceof Function || (json === undefined)) {
  7726. this.clear();
  7727. }
  7728. else {
  7729. this.content.removeChild(this.table); // Take the table offline
  7730. // replace the root node
  7731. var params = {
  7732. field: this.options.name,
  7733. value: json
  7734. };
  7735. var node = new Node(this, params);
  7736. this._setRoot(node);
  7737. // validate JSON schema (if configured)
  7738. this.validate();
  7739. // expand
  7740. var recurse = false;
  7741. this.node.expand(recurse);
  7742. this.content.appendChild(this.table); // Put the table online again
  7743. }
  7744. // TODO: maintain history, store last state and previous document
  7745. if (this.history) {
  7746. this.history.clear();
  7747. }
  7748. // clear search
  7749. if (this.searchBox) {
  7750. this.searchBox.clear();
  7751. }
  7752. };
  7753. /**
  7754. * Get JSON object from editor
  7755. * @return {Object | undefined} json
  7756. */
  7757. treemode.get = function () {
  7758. // remove focus from currently edited node
  7759. if (this.focusTarget) {
  7760. var node = Node.getNodeFromTarget(this.focusTarget);
  7761. if (node) {
  7762. node.blur();
  7763. }
  7764. }
  7765. if (this.node) {
  7766. return this.node.getValue();
  7767. }
  7768. else {
  7769. return undefined;
  7770. }
  7771. };
  7772. /**
  7773. * Get the text contents of the editor
  7774. * @return {String} jsonText
  7775. */
  7776. treemode.getText = function() {
  7777. return JSON.stringify(this.get());
  7778. };
  7779. /**
  7780. * Set the text contents of the editor
  7781. * @param {String} jsonText
  7782. */
  7783. treemode.setText = function(jsonText) {
  7784. this.set(util.parse(jsonText));
  7785. };
  7786. /**
  7787. * Set a field name for the root node.
  7788. * @param {String | undefined} name
  7789. */
  7790. treemode.setName = function (name) {
  7791. this.options.name = name;
  7792. if (this.node) {
  7793. this.node.updateField(this.options.name);
  7794. }
  7795. };
  7796. /**
  7797. * Get the field name for the root node.
  7798. * @return {String | undefined} name
  7799. */
  7800. treemode.getName = function () {
  7801. return this.options.name;
  7802. };
  7803. /**
  7804. * Set focus to the editor. Focus will be set to:
  7805. * - the first editable field or value, or else
  7806. * - to the expand button of the root node, or else
  7807. * - to the context menu button of the root node, or else
  7808. * - to the first button in the top menu
  7809. */
  7810. treemode.focus = function () {
  7811. var input = this.content.querySelector('[contenteditable=true]');
  7812. if (input) {
  7813. input.focus();
  7814. }
  7815. else if (this.node.dom.expand) {
  7816. this.node.dom.expand.focus();
  7817. }
  7818. else if (this.node.dom.menu) {
  7819. this.node.dom.menu.focus();
  7820. }
  7821. else {
  7822. // focus to the first button in the menu
  7823. input = this.frame.querySelector('button');
  7824. if (input) {
  7825. input.focus();
  7826. }
  7827. }
  7828. };
  7829. /**
  7830. * Remove the root node from the editor
  7831. */
  7832. treemode.clear = function () {
  7833. if (this.node) {
  7834. this.node.collapse();
  7835. this.tbody.removeChild(this.node.getDom());
  7836. delete this.node;
  7837. }
  7838. };
  7839. /**
  7840. * Set the root node for the json editor
  7841. * @param {Node} node
  7842. * @private
  7843. */
  7844. treemode._setRoot = function (node) {
  7845. this.clear();
  7846. this.node = node;
  7847. // append to the dom
  7848. this.tbody.appendChild(node.getDom());
  7849. };
  7850. /**
  7851. * Search text in all nodes
  7852. * The nodes will be expanded when the text is found one of its childs,
  7853. * else it will be collapsed. Searches are case insensitive.
  7854. * @param {String} text
  7855. * @return {Object[]} results Array with nodes containing the search results
  7856. * The result objects contains fields:
  7857. * - {Node} node,
  7858. * - {String} elem the dom element name where
  7859. * the result is found ('field' or
  7860. * 'value')
  7861. */
  7862. treemode.search = function (text) {
  7863. var results;
  7864. if (this.node) {
  7865. this.content.removeChild(this.table); // Take the table offline
  7866. results = this.node.search(text);
  7867. this.content.appendChild(this.table); // Put the table online again
  7868. }
  7869. else {
  7870. results = [];
  7871. }
  7872. return results;
  7873. };
  7874. /**
  7875. * Expand all nodes
  7876. */
  7877. treemode.expandAll = function () {
  7878. if (this.node) {
  7879. this.content.removeChild(this.table); // Take the table offline
  7880. this.node.expand();
  7881. this.content.appendChild(this.table); // Put the table online again
  7882. }
  7883. };
  7884. /**
  7885. * Collapse all nodes
  7886. */
  7887. treemode.collapseAll = function () {
  7888. if (this.node) {
  7889. this.content.removeChild(this.table); // Take the table offline
  7890. this.node.collapse();
  7891. this.content.appendChild(this.table); // Put the table online again
  7892. }
  7893. };
  7894. /**
  7895. * The method onChange is called whenever a field or value is changed, created,
  7896. * deleted, duplicated, etc.
  7897. * @param {String} action Change action. Available values: "editField",
  7898. * "editValue", "changeType", "appendNode",
  7899. * "removeNode", "duplicateNode", "moveNode", "expand",
  7900. * "collapse".
  7901. * @param {Object} params Object containing parameters describing the change.
  7902. * The parameters in params depend on the action (for
  7903. * example for "editValue" the Node, old value, and new
  7904. * value are provided). params contains all information
  7905. * needed to undo or redo the action.
  7906. * @private
  7907. */
  7908. treemode._onAction = function (action, params) {
  7909. // add an action to the history
  7910. if (this.history) {
  7911. this.history.add(action, params);
  7912. }
  7913. this._onChange();
  7914. };
  7915. /**
  7916. * Handle a change:
  7917. * - Validate JSON schema
  7918. * - Send a callback to the onChange listener if provided
  7919. * @private
  7920. */
  7921. treemode._onChange = function () {
  7922. // validate JSON schema (if configured)
  7923. this._debouncedValidate();
  7924. // trigger the onChange callback
  7925. if (this.options.onChange) {
  7926. try {
  7927. this.options.onChange();
  7928. }
  7929. catch (err) {
  7930. console.error('Error in onChange callback: ', err);
  7931. }
  7932. }
  7933. };
  7934. /**
  7935. * Validate current JSON object against the configured JSON schema
  7936. * Throws an exception when no JSON schema is configured
  7937. */
  7938. treemode.validate = function () {
  7939. // clear all current errors
  7940. if (this.errorNodes) {
  7941. this.errorNodes.forEach(function (node) {
  7942. node.setError(null);
  7943. });
  7944. }
  7945. var root = this.node;
  7946. if (!root) { // TODO: this should be redundant but is needed on mode switch
  7947. return;
  7948. }
  7949. // check for duplicate keys
  7950. var duplicateErrors = root.validate();
  7951. // validate the JSON
  7952. var schemaErrors = [];
  7953. if (this.validateSchema) {
  7954. var valid = this.validateSchema(root.getValue());
  7955. if (!valid) {
  7956. // apply all new errors
  7957. schemaErrors = this.validateSchema.errors
  7958. .map(function (error) {
  7959. return util.improveSchemaError(error);
  7960. })
  7961. .map(function findNode (error) {
  7962. return {
  7963. node: root.findNode(error.dataPath),
  7964. error: error
  7965. }
  7966. })
  7967. .filter(function hasNode (entry) {
  7968. return entry.node != null
  7969. });
  7970. }
  7971. }
  7972. // display the error in the nodes with a problem
  7973. this.errorNodes = duplicateErrors
  7974. .concat(schemaErrors)
  7975. .reduce(function expandParents (all, entry) {
  7976. // expand parents, then merge such that parents come first and
  7977. // original entries last
  7978. return entry.node
  7979. .findParents()
  7980. .map(function (parent) {
  7981. return {
  7982. node: parent,
  7983. child: entry.node,
  7984. error: {
  7985. message: parent.type === 'object'
  7986. ? 'Contains invalid properties' // object
  7987. : 'Contains invalid items' // array
  7988. }
  7989. };
  7990. })
  7991. .concat(all, [entry]);
  7992. }, [])
  7993. // TODO: dedupe the parent nodes
  7994. .map(function setError (entry) {
  7995. entry.node.setError(entry.error, entry.child);
  7996. return entry.node;
  7997. });
  7998. };
  7999. /**
  8000. * Refresh the rendered contents
  8001. */
  8002. treemode.refresh = function () {
  8003. if (this.node) {
  8004. this.node.updateDom({recurse: true});
  8005. }
  8006. };
  8007. /**
  8008. * Start autoscrolling when given mouse position is above the top of the
  8009. * editor contents, or below the bottom.
  8010. * @param {Number} mouseY Absolute mouse position in pixels
  8011. */
  8012. treemode.startAutoScroll = function (mouseY) {
  8013. var me = this;
  8014. var content = this.content;
  8015. var top = util.getAbsoluteTop(content);
  8016. var height = content.clientHeight;
  8017. var bottom = top + height;
  8018. var margin = 24;
  8019. var interval = 50; // ms
  8020. if ((mouseY < top + margin) && content.scrollTop > 0) {
  8021. this.autoScrollStep = ((top + margin) - mouseY) / 3;
  8022. }
  8023. else if (mouseY > bottom - margin &&
  8024. height + content.scrollTop < content.scrollHeight) {
  8025. this.autoScrollStep = ((bottom - margin) - mouseY) / 3;
  8026. }
  8027. else {
  8028. this.autoScrollStep = undefined;
  8029. }
  8030. if (this.autoScrollStep) {
  8031. if (!this.autoScrollTimer) {
  8032. this.autoScrollTimer = setInterval(function () {
  8033. if (me.autoScrollStep) {
  8034. content.scrollTop -= me.autoScrollStep;
  8035. }
  8036. else {
  8037. me.stopAutoScroll();
  8038. }
  8039. }, interval);
  8040. }
  8041. }
  8042. else {
  8043. this.stopAutoScroll();
  8044. }
  8045. };
  8046. /**
  8047. * Stop auto scrolling. Only applicable when scrolling
  8048. */
  8049. treemode.stopAutoScroll = function () {
  8050. if (this.autoScrollTimer) {
  8051. clearTimeout(this.autoScrollTimer);
  8052. delete this.autoScrollTimer;
  8053. }
  8054. if (this.autoScrollStep) {
  8055. delete this.autoScrollStep;
  8056. }
  8057. };
  8058. /**
  8059. * Set the focus to an element in the editor, set text selection, and
  8060. * set scroll position.
  8061. * @param {Object} selection An object containing fields:
  8062. * {Element | undefined} dom The dom element
  8063. * which has focus
  8064. * {Range | TextRange} range A text selection
  8065. * {Node[]} nodes Nodes in case of multi selection
  8066. * {Number} scrollTop Scroll position
  8067. */
  8068. treemode.setSelection = function (selection) {
  8069. if (!selection) {
  8070. return;
  8071. }
  8072. if ('scrollTop' in selection && this.content) {
  8073. // TODO: animated scroll
  8074. this.content.scrollTop = selection.scrollTop;
  8075. }
  8076. if (selection.nodes) {
  8077. // multi-select
  8078. this.select(selection.nodes);
  8079. }
  8080. if (selection.range) {
  8081. util.setSelectionOffset(selection.range);
  8082. }
  8083. if (selection.dom) {
  8084. selection.dom.focus();
  8085. }
  8086. };
  8087. /**
  8088. * Get the current focus
  8089. * @return {Object} selection An object containing fields:
  8090. * {Element | undefined} dom The dom element
  8091. * which has focus
  8092. * {Range | TextRange} range A text selection
  8093. * {Node[]} nodes Nodes in case of multi selection
  8094. * {Number} scrollTop Scroll position
  8095. */
  8096. treemode.getSelection = function () {
  8097. var range = util.getSelectionOffset();
  8098. if (range && range.container.nodeName !== 'DIV') { // filter on (editable) divs)
  8099. range = null;
  8100. }
  8101. return {
  8102. dom: this.focusTarget,
  8103. range: range,
  8104. nodes: this.multiselection.nodes.slice(0),
  8105. scrollTop: this.content ? this.content.scrollTop : 0
  8106. };
  8107. };
  8108. /**
  8109. * Adjust the scroll position such that given top position is shown at 1/4
  8110. * of the window height.
  8111. * @param {Number} top
  8112. * @param {function(boolean)} [callback] Callback, executed when animation is
  8113. * finished. The callback returns true
  8114. * when animation is finished, or false
  8115. * when not.
  8116. */
  8117. treemode.scrollTo = function (top, callback) {
  8118. var content = this.content;
  8119. if (content) {
  8120. var editor = this;
  8121. // cancel any running animation
  8122. if (editor.animateTimeout) {
  8123. clearTimeout(editor.animateTimeout);
  8124. delete editor.animateTimeout;
  8125. }
  8126. if (editor.animateCallback) {
  8127. editor.animateCallback(false);
  8128. delete editor.animateCallback;
  8129. }
  8130. // calculate final scroll position
  8131. var height = content.clientHeight;
  8132. var bottom = content.scrollHeight - height;
  8133. var finalScrollTop = Math.min(Math.max(top - height / 4, 0), bottom);
  8134. // animate towards the new scroll position
  8135. var animate = function () {
  8136. var scrollTop = content.scrollTop;
  8137. var diff = (finalScrollTop - scrollTop);
  8138. if (Math.abs(diff) > 3) {
  8139. content.scrollTop += diff / 3;
  8140. editor.animateCallback = callback;
  8141. editor.animateTimeout = setTimeout(animate, 50);
  8142. }
  8143. else {
  8144. // finished
  8145. if (callback) {
  8146. callback(true);
  8147. }
  8148. content.scrollTop = finalScrollTop;
  8149. delete editor.animateTimeout;
  8150. delete editor.animateCallback;
  8151. }
  8152. };
  8153. animate();
  8154. }
  8155. else {
  8156. if (callback) {
  8157. callback(false);
  8158. }
  8159. }
  8160. };
  8161. /**
  8162. * Create main frame
  8163. * @private
  8164. */
  8165. treemode._createFrame = function () {
  8166. // create the frame
  8167. this.frame = document.createElement('div');
  8168. this.frame.className = 'jsoneditor jsoneditor-mode-' + this.options.mode;
  8169. this.container.appendChild(this.frame);
  8170. // create one global event listener to handle all events from all nodes
  8171. var editor = this;
  8172. function onEvent(event) {
  8173. // when switching to mode "code" or "text" via the menu, some events
  8174. // are still fired whilst the _onEvent methods is already removed.
  8175. if (editor._onEvent) {
  8176. editor._onEvent(event);
  8177. }
  8178. }
  8179. this.frame.onclick = function (event) {
  8180. var target = event.target;// || event.srcElement;
  8181. onEvent(event);
  8182. // prevent default submit action of buttons when editor is located
  8183. // inside a form
  8184. if (target.nodeName == 'BUTTON') {
  8185. event.preventDefault();
  8186. }
  8187. };
  8188. this.frame.oninput = onEvent;
  8189. this.frame.onchange = onEvent;
  8190. this.frame.onkeydown = onEvent;
  8191. this.frame.onkeyup = onEvent;
  8192. this.frame.oncut = onEvent;
  8193. this.frame.onpaste = onEvent;
  8194. this.frame.onmousedown = onEvent;
  8195. this.frame.onmouseup = onEvent;
  8196. this.frame.onmouseover = onEvent;
  8197. this.frame.onmouseout = onEvent;
  8198. // Note: focus and blur events do not propagate, therefore they defined
  8199. // using an eventListener with useCapture=true
  8200. // see http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
  8201. util.addEventListener(this.frame, 'focus', onEvent, true);
  8202. util.addEventListener(this.frame, 'blur', onEvent, true);
  8203. this.frame.onfocusin = onEvent; // for IE
  8204. this.frame.onfocusout = onEvent; // for IE
  8205. // create menu
  8206. this.menu = document.createElement('div');
  8207. this.menu.className = 'jsoneditor-menu';
  8208. this.frame.appendChild(this.menu);
  8209. // create expand all button
  8210. var expandAll = document.createElement('button');
  8211. expandAll.type = 'button';
  8212. expandAll.className = 'jsoneditor-expand-all';
  8213. expandAll.title = 'Expand all fields';
  8214. expandAll.onclick = function () {
  8215. editor.expandAll();
  8216. };
  8217. this.menu.appendChild(expandAll);
  8218. // create expand all button
  8219. var collapseAll = document.createElement('button');
  8220. collapseAll.type = 'button';
  8221. collapseAll.title = 'Collapse all fields';
  8222. collapseAll.className = 'jsoneditor-collapse-all';
  8223. collapseAll.onclick = function () {
  8224. editor.collapseAll();
  8225. };
  8226. this.menu.appendChild(collapseAll);
  8227. // create undo/redo buttons
  8228. if (this.history) {
  8229. // create undo button
  8230. var undo = document.createElement('button');
  8231. undo.type = 'button';
  8232. undo.className = 'jsoneditor-undo jsoneditor-separator';
  8233. undo.title = 'Undo last action (Ctrl+Z)';
  8234. undo.onclick = function () {
  8235. editor._onUndo();
  8236. };
  8237. this.menu.appendChild(undo);
  8238. this.dom.undo = undo;
  8239. // create redo button
  8240. var redo = document.createElement('button');
  8241. redo.type = 'button';
  8242. redo.className = 'jsoneditor-redo';
  8243. redo.title = 'Redo (Ctrl+Shift+Z)';
  8244. redo.onclick = function () {
  8245. editor._onRedo();
  8246. };
  8247. this.menu.appendChild(redo);
  8248. this.dom.redo = redo;
  8249. // register handler for onchange of history
  8250. this.history.onChange = function () {
  8251. undo.disabled = !editor.history.canUndo();
  8252. redo.disabled = !editor.history.canRedo();
  8253. };
  8254. this.history.onChange();
  8255. }
  8256. // create mode box
  8257. if (this.options && this.options.modes && this.options.modes.length) {
  8258. var me = this;
  8259. this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) {
  8260. me.modeSwitcher.destroy();
  8261. // switch mode and restore focus
  8262. me.setMode(mode);
  8263. me.modeSwitcher.focus();
  8264. });
  8265. }
  8266. // create search box
  8267. if (this.options.search) {
  8268. this.searchBox = new SearchBox(this, this.menu);
  8269. }
  8270. };
  8271. /**
  8272. * Perform an undo action
  8273. * @private
  8274. */
  8275. treemode._onUndo = function () {
  8276. if (this.history) {
  8277. // undo last action
  8278. this.history.undo();
  8279. // fire change event
  8280. this._onChange();
  8281. }
  8282. };
  8283. /**
  8284. * Perform a redo action
  8285. * @private
  8286. */
  8287. treemode._onRedo = function () {
  8288. if (this.history) {
  8289. // redo last action
  8290. this.history.redo();
  8291. // fire change event
  8292. this._onChange();
  8293. }
  8294. };
  8295. /**
  8296. * Event handler
  8297. * @param event
  8298. * @private
  8299. */
  8300. treemode._onEvent = function (event) {
  8301. if (event.type == 'keydown') {
  8302. this._onKeyDown(event);
  8303. }
  8304. if (event.type == 'focus') {
  8305. this.focusTarget = event.target;
  8306. }
  8307. if (event.type == 'mousedown') {
  8308. this._startDragDistance(event);
  8309. }
  8310. if (event.type == 'mousemove' || event.type == 'mouseup' || event.type == 'click') {
  8311. this._updateDragDistance(event);
  8312. }
  8313. var node = Node.getNodeFromTarget(event.target);
  8314. if (node && node.selected) {
  8315. if (event.type == 'click') {
  8316. if (event.target == node.dom.menu) {
  8317. this.showContextMenu(event.target);
  8318. // stop propagation (else we will open the context menu of a single node)
  8319. return;
  8320. }
  8321. // deselect a multi selection
  8322. if (!event.hasMoved) {
  8323. this.deselect();
  8324. }
  8325. }
  8326. if (event.type == 'mousedown') {
  8327. // drag multiple nodes
  8328. Node.onDragStart(this.multiselection.nodes, event);
  8329. }
  8330. }
  8331. else {
  8332. if (event.type == 'mousedown') {
  8333. this.deselect();
  8334. if (node && event.target == node.dom.drag) {
  8335. // drag a singe node
  8336. Node.onDragStart(node, event);
  8337. }
  8338. else if (!node || (event.target != node.dom.field && event.target != node.dom.value && event.target != node.dom.select)) {
  8339. // select multiple nodes
  8340. this._onMultiSelectStart(event);
  8341. }
  8342. }
  8343. }
  8344. if (node) {
  8345. node.onEvent(event);
  8346. }
  8347. };
  8348. treemode._startDragDistance = function (event) {
  8349. this.dragDistanceEvent = {
  8350. initialTarget: event.target,
  8351. initialPageX: event.pageX,
  8352. initialPageY: event.pageY,
  8353. dragDistance: 0,
  8354. hasMoved: false
  8355. };
  8356. };
  8357. treemode._updateDragDistance = function (event) {
  8358. if (!this.dragDistanceEvent) {
  8359. this._startDragDistance(event);
  8360. }
  8361. var diffX = event.pageX - this.dragDistanceEvent.initialPageX;
  8362. var diffY = event.pageY - this.dragDistanceEvent.initialPageY;
  8363. this.dragDistanceEvent.dragDistance = Math.sqrt(diffX * diffX + diffY * diffY);
  8364. this.dragDistanceEvent.hasMoved =
  8365. this.dragDistanceEvent.hasMoved || this.dragDistanceEvent.dragDistance > 10;
  8366. event.dragDistance = this.dragDistanceEvent.dragDistance;
  8367. event.hasMoved = this.dragDistanceEvent.hasMoved;
  8368. return event.dragDistance;
  8369. };
  8370. /**
  8371. * Start multi selection of nodes by dragging the mouse
  8372. * @param event
  8373. * @private
  8374. */
  8375. treemode._onMultiSelectStart = function (event) {
  8376. var node = Node.getNodeFromTarget(event.target);
  8377. if (this.options.mode !== 'tree' || this.options.onEditable !== undefined) {
  8378. // dragging not allowed in modes 'view' and 'form'
  8379. // TODO: allow multiselection of items when option onEditable is specified
  8380. return;
  8381. }
  8382. this.multiselection = {
  8383. start: node || null,
  8384. end: null,
  8385. nodes: []
  8386. };
  8387. this._startDragDistance(event);
  8388. var editor = this;
  8389. if (!this.mousemove) {
  8390. this.mousemove = util.addEventListener(window, 'mousemove', function (event) {
  8391. editor._onMultiSelect(event);
  8392. });
  8393. }
  8394. if (!this.mouseup) {
  8395. this.mouseup = util.addEventListener(window, 'mouseup', function (event ) {
  8396. editor._onMultiSelectEnd(event);
  8397. });
  8398. }
  8399. };
  8400. /**
  8401. * Multiselect nodes by dragging
  8402. * @param event
  8403. * @private
  8404. */
  8405. treemode._onMultiSelect = function (event) {
  8406. event.preventDefault();
  8407. this._updateDragDistance(event);
  8408. if (!event.hasMoved) {
  8409. return;
  8410. }
  8411. var node = Node.getNodeFromTarget(event.target);
  8412. if (node) {
  8413. if (this.multiselection.start == null) {
  8414. this.multiselection.start = node;
  8415. }
  8416. this.multiselection.end = node;
  8417. }
  8418. // deselect previous selection
  8419. this.deselect();
  8420. // find the selected nodes in the range from first to last
  8421. var start = this.multiselection.start;
  8422. var end = this.multiselection.end || this.multiselection.start;
  8423. if (start && end) {
  8424. // find the top level childs, all having the same parent
  8425. this.multiselection.nodes = this._findTopLevelNodes(start, end);
  8426. this.select(this.multiselection.nodes);
  8427. }
  8428. };
  8429. /**
  8430. * End of multiselect nodes by dragging
  8431. * @param event
  8432. * @private
  8433. */
  8434. treemode._onMultiSelectEnd = function (event) {
  8435. // set focus to the context menu button of the first node
  8436. if (this.multiselection.nodes[0]) {
  8437. this.multiselection.nodes[0].dom.menu.focus();
  8438. }
  8439. this.multiselection.start = null;
  8440. this.multiselection.end = null;
  8441. // cleanup global event listeners
  8442. if (this.mousemove) {
  8443. util.removeEventListener(window, 'mousemove', this.mousemove);
  8444. delete this.mousemove;
  8445. }
  8446. if (this.mouseup) {
  8447. util.removeEventListener(window, 'mouseup', this.mouseup);
  8448. delete this.mouseup;
  8449. }
  8450. };
  8451. /**
  8452. * deselect currently selected nodes
  8453. * @param {boolean} [clearStartAndEnd=false] If true, the `start` and `end`
  8454. * state is cleared too.
  8455. */
  8456. treemode.deselect = function (clearStartAndEnd) {
  8457. this.multiselection.nodes.forEach(function (node) {
  8458. node.setSelected(false);
  8459. });
  8460. this.multiselection.nodes = [];
  8461. if (clearStartAndEnd) {
  8462. this.multiselection.start = null;
  8463. this.multiselection.end = null;
  8464. }
  8465. };
  8466. /**
  8467. * select nodes
  8468. * @param {Node[] | Node} nodes
  8469. */
  8470. treemode.select = function (nodes) {
  8471. if (!Array.isArray(nodes)) {
  8472. return this.select([nodes]);
  8473. }
  8474. if (nodes) {
  8475. this.deselect();
  8476. this.multiselection.nodes = nodes.slice(0);
  8477. var first = nodes[0];
  8478. nodes.forEach(function (node) {
  8479. node.setSelected(true, node === first);
  8480. });
  8481. }
  8482. };
  8483. /**
  8484. * From two arbitrary selected nodes, find their shared parent node.
  8485. * From that parent node, select the two child nodes in the brances going to
  8486. * nodes `start` and `end`, and select all childs in between.
  8487. * @param {Node} start
  8488. * @param {Node} end
  8489. * @return {Array.<Node>} Returns an ordered list with child nodes
  8490. * @private
  8491. */
  8492. treemode._findTopLevelNodes = function (start, end) {
  8493. var startPath = start.getNodePath();
  8494. var endPath = end.getNodePath();
  8495. var i = 0;
  8496. while (i < startPath.length && startPath[i] === endPath[i]) {
  8497. i++;
  8498. }
  8499. var root = startPath[i - 1];
  8500. var startChild = startPath[i];
  8501. var endChild = endPath[i];
  8502. if (!startChild || !endChild) {
  8503. if (root.parent) {
  8504. // startChild is a parent of endChild or vice versa
  8505. startChild = root;
  8506. endChild = root;
  8507. root = root.parent
  8508. }
  8509. else {
  8510. // we have selected the root node (which doesn't have a parent)
  8511. startChild = root.childs[0];
  8512. endChild = root.childs[root.childs.length - 1];
  8513. }
  8514. }
  8515. if (root && startChild && endChild) {
  8516. var startIndex = root.childs.indexOf(startChild);
  8517. var endIndex = root.childs.indexOf(endChild);
  8518. var firstIndex = Math.min(startIndex, endIndex);
  8519. var lastIndex = Math.max(startIndex, endIndex);
  8520. return root.childs.slice(firstIndex, lastIndex + 1);
  8521. }
  8522. else {
  8523. return [];
  8524. }
  8525. };
  8526. /**
  8527. * Event handler for keydown. Handles shortcut keys
  8528. * @param {Event} event
  8529. * @private
  8530. */
  8531. treemode._onKeyDown = function (event) {
  8532. var keynum = event.which || event.keyCode;
  8533. var ctrlKey = event.ctrlKey;
  8534. var shiftKey = event.shiftKey;
  8535. var handled = false;
  8536. if (keynum == 9) { // Tab or Shift+Tab
  8537. var me = this;
  8538. setTimeout(function () {
  8539. // select all text when moving focus to an editable div
  8540. util.selectContentEditable(me.focusTarget);
  8541. }, 0);
  8542. }
  8543. if (this.searchBox) {
  8544. if (ctrlKey && keynum == 70) { // Ctrl+F
  8545. this.searchBox.dom.search.focus();
  8546. this.searchBox.dom.search.select();
  8547. handled = true;
  8548. }
  8549. else if (keynum == 114 || (ctrlKey && keynum == 71)) { // F3 or Ctrl+G
  8550. var focus = true;
  8551. if (!shiftKey) {
  8552. // select next search result (F3 or Ctrl+G)
  8553. this.searchBox.next(focus);
  8554. }
  8555. else {
  8556. // select previous search result (Shift+F3 or Ctrl+Shift+G)
  8557. this.searchBox.previous(focus);
  8558. }
  8559. handled = true;
  8560. }
  8561. }
  8562. if (this.history) {
  8563. if (ctrlKey && !shiftKey && keynum == 90) { // Ctrl+Z
  8564. // undo
  8565. this._onUndo();
  8566. handled = true;
  8567. }
  8568. else if (ctrlKey && shiftKey && keynum == 90) { // Ctrl+Shift+Z
  8569. // redo
  8570. this._onRedo();
  8571. handled = true;
  8572. }
  8573. }
  8574. if (handled) {
  8575. event.preventDefault();
  8576. event.stopPropagation();
  8577. }
  8578. };
  8579. /**
  8580. * Create main table
  8581. * @private
  8582. */
  8583. treemode._createTable = function () {
  8584. var contentOuter = document.createElement('div');
  8585. contentOuter.className = 'jsoneditor-outer';
  8586. this.contentOuter = contentOuter;
  8587. this.content = document.createElement('div');
  8588. this.content.className = 'jsoneditor-tree';
  8589. contentOuter.appendChild(this.content);
  8590. this.table = document.createElement('table');
  8591. this.table.className = 'jsoneditor-tree';
  8592. this.content.appendChild(this.table);
  8593. // create colgroup where the first two columns don't have a fixed
  8594. // width, and the edit columns do have a fixed width
  8595. var col;
  8596. this.colgroupContent = document.createElement('colgroup');
  8597. if (this.options.mode === 'tree') {
  8598. col = document.createElement('col');
  8599. col.width = "24px";
  8600. this.colgroupContent.appendChild(col);
  8601. }
  8602. col = document.createElement('col');
  8603. col.width = "24px";
  8604. this.colgroupContent.appendChild(col);
  8605. col = document.createElement('col');
  8606. this.colgroupContent.appendChild(col);
  8607. this.table.appendChild(this.colgroupContent);
  8608. this.tbody = document.createElement('tbody');
  8609. this.table.appendChild(this.tbody);
  8610. this.frame.appendChild(contentOuter);
  8611. };
  8612. /**
  8613. * Show a contextmenu for this node.
  8614. * Used for multiselection
  8615. * @param {HTMLElement} anchor Anchor element to attache the context menu to.
  8616. * @param {function} [onClose] Callback method called when the context menu
  8617. * is being closed.
  8618. */
  8619. treemode.showContextMenu = function (anchor, onClose) {
  8620. var items = [];
  8621. var editor = this;
  8622. // create duplicate button
  8623. items.push({
  8624. text: 'Duplicate',
  8625. title: 'Duplicate selected fields (Ctrl+D)',
  8626. className: 'jsoneditor-duplicate',
  8627. click: function () {
  8628. Node.onDuplicate(editor.multiselection.nodes);
  8629. }
  8630. });
  8631. // create remove button
  8632. items.push({
  8633. text: 'Remove',
  8634. title: 'Remove selected fields (Ctrl+Del)',
  8635. className: 'jsoneditor-remove',
  8636. click: function () {
  8637. Node.onRemove(editor.multiselection.nodes);
  8638. }
  8639. });
  8640. var menu = new ContextMenu(items, {close: onClose});
  8641. menu.show(anchor, this.content);
  8642. };
  8643. // define modes
  8644. module.exports = [
  8645. {
  8646. mode: 'tree',
  8647. mixin: treemode,
  8648. data: 'json'
  8649. },
  8650. {
  8651. mode: 'view',
  8652. mixin: treemode,
  8653. data: 'json'
  8654. },
  8655. {
  8656. mode: 'form',
  8657. mixin: treemode,
  8658. data: 'json'
  8659. }
  8660. ];
  8661. /***/ },
  8662. /* 52 */
  8663. /***/ function(module, exports) {
  8664. 'use strict';
  8665. /**
  8666. * The highlighter can highlight/unhighlight a node, and
  8667. * animate the visibility of a context menu.
  8668. * @constructor Highlighter
  8669. */
  8670. function Highlighter () {
  8671. this.locked = false;
  8672. }
  8673. /**
  8674. * Hightlight given node and its childs
  8675. * @param {Node} node
  8676. */
  8677. Highlighter.prototype.highlight = function (node) {
  8678. if (this.locked) {
  8679. return;
  8680. }
  8681. if (this.node != node) {
  8682. // unhighlight current node
  8683. if (this.node) {
  8684. this.node.setHighlight(false);
  8685. }
  8686. // highlight new node
  8687. this.node = node;
  8688. this.node.setHighlight(true);
  8689. }
  8690. // cancel any current timeout
  8691. this._cancelUnhighlight();
  8692. };
  8693. /**
  8694. * Unhighlight currently highlighted node.
  8695. * Will be done after a delay
  8696. */
  8697. Highlighter.prototype.unhighlight = function () {
  8698. if (this.locked) {
  8699. return;
  8700. }
  8701. var me = this;
  8702. if (this.node) {
  8703. this._cancelUnhighlight();
  8704. // do the unhighlighting after a small delay, to prevent re-highlighting
  8705. // the same node when moving from the drag-icon to the contextmenu-icon
  8706. // or vice versa.
  8707. this.unhighlightTimer = setTimeout(function () {
  8708. me.node.setHighlight(false);
  8709. me.node = undefined;
  8710. me.unhighlightTimer = undefined;
  8711. }, 0);
  8712. }
  8713. };
  8714. /**
  8715. * Cancel an unhighlight action (if before the timeout of the unhighlight action)
  8716. * @private
  8717. */
  8718. Highlighter.prototype._cancelUnhighlight = function () {
  8719. if (this.unhighlightTimer) {
  8720. clearTimeout(this.unhighlightTimer);
  8721. this.unhighlightTimer = undefined;
  8722. }
  8723. };
  8724. /**
  8725. * Lock highlighting or unhighlighting nodes.
  8726. * methods highlight and unhighlight do not work while locked.
  8727. */
  8728. Highlighter.prototype.lock = function () {
  8729. this.locked = true;
  8730. };
  8731. /**
  8732. * Unlock highlighting or unhighlighting nodes
  8733. */
  8734. Highlighter.prototype.unlock = function () {
  8735. this.locked = false;
  8736. };
  8737. module.exports = Highlighter;
  8738. /***/ },
  8739. /* 53 */
  8740. /***/ function(module, exports, __webpack_require__) {
  8741. 'use strict';
  8742. var util = __webpack_require__(54);
  8743. /**
  8744. * @constructor History
  8745. * Store action history, enables undo and redo
  8746. * @param {JSONEditor} editor
  8747. */
  8748. function History (editor) {
  8749. this.editor = editor;
  8750. this.history = [];
  8751. this.index = -1;
  8752. this.clear();
  8753. // map with all supported actions
  8754. this.actions = {
  8755. 'editField': {
  8756. 'undo': function (params) {
  8757. params.node.updateField(params.oldValue);
  8758. },
  8759. 'redo': function (params) {
  8760. params.node.updateField(params.newValue);
  8761. }
  8762. },
  8763. 'editValue': {
  8764. 'undo': function (params) {
  8765. params.node.updateValue(params.oldValue);
  8766. },
  8767. 'redo': function (params) {
  8768. params.node.updateValue(params.newValue);
  8769. }
  8770. },
  8771. 'changeType': {
  8772. 'undo': function (params) {
  8773. params.node.changeType(params.oldType);
  8774. },
  8775. 'redo': function (params) {
  8776. params.node.changeType(params.newType);
  8777. }
  8778. },
  8779. 'appendNodes': {
  8780. 'undo': function (params) {
  8781. params.nodes.forEach(function (node) {
  8782. params.parent.removeChild(node);
  8783. });
  8784. },
  8785. 'redo': function (params) {
  8786. params.nodes.forEach(function (node) {
  8787. params.parent.appendChild(node);
  8788. });
  8789. }
  8790. },
  8791. 'insertBeforeNodes': {
  8792. 'undo': function (params) {
  8793. params.nodes.forEach(function (node) {
  8794. params.parent.removeChild(node);
  8795. });
  8796. },
  8797. 'redo': function (params) {
  8798. params.nodes.forEach(function (node) {
  8799. params.parent.insertBefore(node, params.beforeNode);
  8800. });
  8801. }
  8802. },
  8803. 'insertAfterNodes': {
  8804. 'undo': function (params) {
  8805. params.nodes.forEach(function (node) {
  8806. params.parent.removeChild(node);
  8807. });
  8808. },
  8809. 'redo': function (params) {
  8810. var afterNode = params.afterNode;
  8811. params.nodes.forEach(function (node) {
  8812. params.parent.insertAfter(params.node, afterNode);
  8813. afterNode = node;
  8814. });
  8815. }
  8816. },
  8817. 'removeNodes': {
  8818. 'undo': function (params) {
  8819. var parent = params.parent;
  8820. var beforeNode = parent.childs[params.index] || parent.append;
  8821. params.nodes.forEach(function (node) {
  8822. parent.insertBefore(node, beforeNode);
  8823. });
  8824. },
  8825. 'redo': function (params) {
  8826. params.nodes.forEach(function (node) {
  8827. params.parent.removeChild(node);
  8828. });
  8829. }
  8830. },
  8831. 'duplicateNodes': {
  8832. 'undo': function (params) {
  8833. params.nodes.forEach(function (node) {
  8834. params.parent.removeChild(node);
  8835. });
  8836. },
  8837. 'redo': function (params) {
  8838. var afterNode = params.afterNode;
  8839. params.nodes.forEach(function (node) {
  8840. params.parent.insertAfter(node, afterNode);
  8841. afterNode = node;
  8842. });
  8843. }
  8844. },
  8845. 'moveNodes': {
  8846. 'undo': function (params) {
  8847. params.nodes.forEach(function (node) {
  8848. params.oldBeforeNode.parent.moveBefore(node, params.oldBeforeNode);
  8849. });
  8850. },
  8851. 'redo': function (params) {
  8852. params.nodes.forEach(function (node) {
  8853. params.newBeforeNode.parent.moveBefore(node, params.newBeforeNode);
  8854. });
  8855. }
  8856. },
  8857. 'sort': {
  8858. 'undo': function (params) {
  8859. var node = params.node;
  8860. node.hideChilds();
  8861. node.sort = params.oldSort;
  8862. node.childs = params.oldChilds;
  8863. node.showChilds();
  8864. },
  8865. 'redo': function (params) {
  8866. var node = params.node;
  8867. node.hideChilds();
  8868. node.sort = params.newSort;
  8869. node.childs = params.newChilds;
  8870. node.showChilds();
  8871. }
  8872. }
  8873. // TODO: restore the original caret position and selection with each undo
  8874. // TODO: implement history for actions "expand", "collapse", "scroll", "setDocument"
  8875. };
  8876. }
  8877. /**
  8878. * The method onChange is executed when the History is changed, and can
  8879. * be overloaded.
  8880. */
  8881. History.prototype.onChange = function () {};
  8882. /**
  8883. * Add a new action to the history
  8884. * @param {String} action The executed action. Available actions: "editField",
  8885. * "editValue", "changeType", "appendNode",
  8886. * "removeNode", "duplicateNode", "moveNode"
  8887. * @param {Object} params Object containing parameters describing the change.
  8888. * The parameters in params depend on the action (for
  8889. * example for "editValue" the Node, old value, and new
  8890. * value are provided). params contains all information
  8891. * needed to undo or redo the action.
  8892. */
  8893. History.prototype.add = function (action, params) {
  8894. this.index++;
  8895. this.history[this.index] = {
  8896. 'action': action,
  8897. 'params': params,
  8898. 'timestamp': new Date()
  8899. };
  8900. // remove redo actions which are invalid now
  8901. if (this.index < this.history.length - 1) {
  8902. this.history.splice(this.index + 1, this.history.length - this.index - 1);
  8903. }
  8904. // fire onchange event
  8905. this.onChange();
  8906. };
  8907. /**
  8908. * Clear history
  8909. */
  8910. History.prototype.clear = function () {
  8911. this.history = [];
  8912. this.index = -1;
  8913. // fire onchange event
  8914. this.onChange();
  8915. };
  8916. /**
  8917. * Check if there is an action available for undo
  8918. * @return {Boolean} canUndo
  8919. */
  8920. History.prototype.canUndo = function () {
  8921. return (this.index >= 0);
  8922. };
  8923. /**
  8924. * Check if there is an action available for redo
  8925. * @return {Boolean} canRedo
  8926. */
  8927. History.prototype.canRedo = function () {
  8928. return (this.index < this.history.length - 1);
  8929. };
  8930. /**
  8931. * Undo the last action
  8932. */
  8933. History.prototype.undo = function () {
  8934. if (this.canUndo()) {
  8935. var obj = this.history[this.index];
  8936. if (obj) {
  8937. var action = this.actions[obj.action];
  8938. if (action && action.undo) {
  8939. action.undo(obj.params);
  8940. if (obj.params.oldSelection) {
  8941. this.editor.setSelection(obj.params.oldSelection);
  8942. }
  8943. }
  8944. else {
  8945. console.error(new Error('unknown action "' + obj.action + '"'));
  8946. }
  8947. }
  8948. this.index--;
  8949. // fire onchange event
  8950. this.onChange();
  8951. }
  8952. };
  8953. /**
  8954. * Redo the last action
  8955. */
  8956. History.prototype.redo = function () {
  8957. if (this.canRedo()) {
  8958. this.index++;
  8959. var obj = this.history[this.index];
  8960. if (obj) {
  8961. var action = this.actions[obj.action];
  8962. if (action && action.redo) {
  8963. action.redo(obj.params);
  8964. if (obj.params.newSelection) {
  8965. this.editor.setSelection(obj.params.newSelection);
  8966. }
  8967. }
  8968. else {
  8969. console.error(new Error('unknown action "' + obj.action + '"'));
  8970. }
  8971. }
  8972. // fire onchange event
  8973. this.onChange();
  8974. }
  8975. };
  8976. /**
  8977. * Destroy history
  8978. */
  8979. History.prototype.destroy = function () {
  8980. this.editor = null;
  8981. this.history = [];
  8982. this.index = -1;
  8983. };
  8984. module.exports = History;
  8985. /***/ },
  8986. /* 54 */
  8987. /***/ function(module, exports, __webpack_require__) {
  8988. 'use strict';
  8989. var jsonlint = __webpack_require__(55);
  8990. /**
  8991. * Parse JSON using the parser built-in in the browser.
  8992. * On exception, the jsonString is validated and a detailed error is thrown.
  8993. * @param {String} jsonString
  8994. * @return {JSON} json
  8995. */
  8996. exports.parse = function parse(jsonString) {
  8997. try {
  8998. return JSON.parse(jsonString);
  8999. }
  9000. catch (err) {
  9001. // try to throw a more detailed error message using validate
  9002. exports.validate(jsonString);
  9003. // rethrow the original error
  9004. throw err;
  9005. }
  9006. };
  9007. /**
  9008. * Sanitize a JSON-like string containing. For example changes JavaScript
  9009. * notation into JSON notation.
  9010. * This function for example changes a string like "{a: 2, 'b': {c: 'd'}"
  9011. * into '{"a": 2, "b": {"c": "d"}'
  9012. * @param {string} jsString
  9013. * @returns {string} json
  9014. */
  9015. exports.sanitize = function (jsString) {
  9016. // escape all single and double quotes inside strings
  9017. var chars = [];
  9018. var i = 0;
  9019. //If JSON starts with a function (characters/digits/"_-"), remove this function.
  9020. //This is useful for "stripping" JSONP objects to become JSON
  9021. //For example: /* some comment */ function_12321321 ( [{"a":"b"}] ); => [{"a":"b"}]
  9022. var match = jsString.match(/^\s*(\/\*(.|[\r\n])*?\*\/)?\s*[\da-zA-Z_$]+\s*\(([\s\S]*)\)\s*;?\s*$/);
  9023. if (match) {
  9024. jsString = match[3];
  9025. }
  9026. // helper functions to get the current/prev/next character
  9027. function curr () { return jsString.charAt(i); }
  9028. function next() { return jsString.charAt(i + 1); }
  9029. function prev() { return jsString.charAt(i - 1); }
  9030. // get the last parsed non-whitespace character
  9031. function lastNonWhitespace () {
  9032. var p = chars.length - 1;
  9033. while (p >= 0) {
  9034. var pp = chars[p];
  9035. if (pp !== ' ' && pp !== '\n' && pp !== '\r' && pp !== '\t') { // non whitespace
  9036. return pp;
  9037. }
  9038. p--;
  9039. }
  9040. return '';
  9041. }
  9042. // skip a block comment '/* ... */'
  9043. function skipBlockComment () {
  9044. i += 2;
  9045. while (i < jsString.length && (curr() !== '*' || next() !== '/')) {
  9046. i++;
  9047. }
  9048. i += 2;
  9049. }
  9050. // skip a comment '// ...'
  9051. function skipComment () {
  9052. i += 2;
  9053. while (i < jsString.length && (curr() !== '\n')) {
  9054. i++;
  9055. }
  9056. }
  9057. // parse single or double quoted string
  9058. function parseString(quote) {
  9059. chars.push('"');
  9060. i++;
  9061. var c = curr();
  9062. while (i < jsString.length && c !== quote) {
  9063. if (c === '"' && prev() !== '\\') {
  9064. // unescaped double quote, escape it
  9065. chars.push('\\');
  9066. }
  9067. // handle escape character
  9068. if (c === '\\') {
  9069. i++;
  9070. c = curr();
  9071. // remove the escape character when followed by a single quote ', not needed
  9072. if (c !== '\'') {
  9073. chars.push('\\');
  9074. }
  9075. }
  9076. chars.push(c);
  9077. i++;
  9078. c = curr();
  9079. }
  9080. if (c === quote) {
  9081. chars.push('"');
  9082. i++;
  9083. }
  9084. }
  9085. // parse an unquoted key
  9086. function parseKey() {
  9087. var specialValues = ['null', 'true', 'false'];
  9088. var key = '';
  9089. var c = curr();
  9090. var regexp = /[a-zA-Z_$\d]/; // letter, number, underscore, dollar character
  9091. while (regexp.test(c)) {
  9092. key += c;
  9093. i++;
  9094. c = curr();
  9095. }
  9096. if (specialValues.indexOf(key) === -1) {
  9097. chars.push('"' + key + '"');
  9098. }
  9099. else {
  9100. chars.push(key);
  9101. }
  9102. }
  9103. while(i < jsString.length) {
  9104. var c = curr();
  9105. if (c === '/' && next() === '*') {
  9106. skipBlockComment();
  9107. }
  9108. else if (c === '/' && next() === '/') {
  9109. skipComment();
  9110. }
  9111. else if (c === '\'' || c === '"') {
  9112. parseString(c);
  9113. }
  9114. else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) {
  9115. // an unquoted object key (like a in '{a:2}')
  9116. parseKey();
  9117. }
  9118. else {
  9119. chars.push(c);
  9120. i++;
  9121. }
  9122. }
  9123. return chars.join('');
  9124. };
  9125. /**
  9126. * Escape unicode characters.
  9127. * For example input '\u2661' (length 1) will output '\\u2661' (length 5).
  9128. * @param {string} text
  9129. * @return {string}
  9130. */
  9131. exports.escapeUnicodeChars = function (text) {
  9132. // see https://www.wikiwand.com/en/UTF-16
  9133. // note: we leave surrogate pairs as two individual chars,
  9134. // as JSON doesn't interpret them as a single unicode char.
  9135. return text.replace(/[\u007F-\uFFFF]/g, function(c) {
  9136. return '\\u'+('0000' + c.charCodeAt(0).toString(16)).slice(-4);
  9137. })
  9138. };
  9139. /**
  9140. * Validate a string containing a JSON object
  9141. * This method uses JSONLint to validate the String. If JSONLint is not
  9142. * available, the built-in JSON parser of the browser is used.
  9143. * @param {String} jsonString String with an (invalid) JSON object
  9144. * @throws Error
  9145. */
  9146. exports.validate = function validate(jsonString) {
  9147. if (typeof(jsonlint) != 'undefined') {
  9148. jsonlint.parse(jsonString);
  9149. }
  9150. else {
  9151. JSON.parse(jsonString);
  9152. }
  9153. };
  9154. /**
  9155. * Extend object a with the properties of object b
  9156. * @param {Object} a
  9157. * @param {Object} b
  9158. * @return {Object} a
  9159. */
  9160. exports.extend = function extend(a, b) {
  9161. for (var prop in b) {
  9162. if (b.hasOwnProperty(prop)) {
  9163. a[prop] = b[prop];
  9164. }
  9165. }
  9166. return a;
  9167. };
  9168. /**
  9169. * Remove all properties from object a
  9170. * @param {Object} a
  9171. * @return {Object} a
  9172. */
  9173. exports.clear = function clear (a) {
  9174. for (var prop in a) {
  9175. if (a.hasOwnProperty(prop)) {
  9176. delete a[prop];
  9177. }
  9178. }
  9179. return a;
  9180. };
  9181. /**
  9182. * Get the type of an object
  9183. * @param {*} object
  9184. * @return {String} type
  9185. */
  9186. exports.type = function type (object) {
  9187. if (object === null) {
  9188. return 'null';
  9189. }
  9190. if (object === undefined) {
  9191. return 'undefined';
  9192. }
  9193. if ((object instanceof Number) || (typeof object === 'number')) {
  9194. return 'number';
  9195. }
  9196. if ((object instanceof String) || (typeof object === 'string')) {
  9197. return 'string';
  9198. }
  9199. if ((object instanceof Boolean) || (typeof object === 'boolean')) {
  9200. return 'boolean';
  9201. }
  9202. if ((object instanceof RegExp) || (typeof object === 'regexp')) {
  9203. return 'regexp';
  9204. }
  9205. if (exports.isArray(object)) {
  9206. return 'array';
  9207. }
  9208. return 'object';
  9209. };
  9210. /**
  9211. * Test whether a text contains a url (matches when a string starts
  9212. * with 'http://*' or 'https://*' and has no whitespace characters)
  9213. * @param {String} text
  9214. */
  9215. var isUrlRegex = /^https?:\/\/\S+$/;
  9216. exports.isUrl = function isUrl (text) {
  9217. return (typeof text == 'string' || text instanceof String) &&
  9218. isUrlRegex.test(text);
  9219. };
  9220. /**
  9221. * Tes whether given object is an Array
  9222. * @param {*} obj
  9223. * @returns {boolean} returns true when obj is an array
  9224. */
  9225. exports.isArray = function (obj) {
  9226. return Object.prototype.toString.call(obj) === '[object Array]';
  9227. };
  9228. /**
  9229. * Retrieve the absolute left value of a DOM element
  9230. * @param {Element} elem A dom element, for example a div
  9231. * @return {Number} left The absolute left position of this element
  9232. * in the browser page.
  9233. */
  9234. exports.getAbsoluteLeft = function getAbsoluteLeft(elem) {
  9235. var rect = elem.getBoundingClientRect();
  9236. return rect.left + window.pageXOffset || document.scrollLeft || 0;
  9237. };
  9238. /**
  9239. * Retrieve the absolute top value of a DOM element
  9240. * @param {Element} elem A dom element, for example a div
  9241. * @return {Number} top The absolute top position of this element
  9242. * in the browser page.
  9243. */
  9244. exports.getAbsoluteTop = function getAbsoluteTop(elem) {
  9245. var rect = elem.getBoundingClientRect();
  9246. return rect.top + window.pageYOffset || document.scrollTop || 0;
  9247. };
  9248. /**
  9249. * add a className to the given elements style
  9250. * @param {Element} elem
  9251. * @param {String} className
  9252. */
  9253. exports.addClassName = function addClassName(elem, className) {
  9254. var classes = elem.className.split(' ');
  9255. if (classes.indexOf(className) == -1) {
  9256. classes.push(className); // add the class to the array
  9257. elem.className = classes.join(' ');
  9258. }
  9259. };
  9260. /**
  9261. * add a className to the given elements style
  9262. * @param {Element} elem
  9263. * @param {String} className
  9264. */
  9265. exports.removeClassName = function removeClassName(elem, className) {
  9266. var classes = elem.className.split(' ');
  9267. var index = classes.indexOf(className);
  9268. if (index != -1) {
  9269. classes.splice(index, 1); // remove the class from the array
  9270. elem.className = classes.join(' ');
  9271. }
  9272. };
  9273. /**
  9274. * Strip the formatting from the contents of a div
  9275. * the formatting from the div itself is not stripped, only from its childs.
  9276. * @param {Element} divElement
  9277. */
  9278. exports.stripFormatting = function stripFormatting(divElement) {
  9279. var childs = divElement.childNodes;
  9280. for (var i = 0, iMax = childs.length; i < iMax; i++) {
  9281. var child = childs[i];
  9282. // remove the style
  9283. if (child.style) {
  9284. // TODO: test if child.attributes does contain style
  9285. child.removeAttribute('style');
  9286. }
  9287. // remove all attributes
  9288. var attributes = child.attributes;
  9289. if (attributes) {
  9290. for (var j = attributes.length - 1; j >= 0; j--) {
  9291. var attribute = attributes[j];
  9292. if (attribute.specified === true) {
  9293. child.removeAttribute(attribute.name);
  9294. }
  9295. }
  9296. }
  9297. // recursively strip childs
  9298. exports.stripFormatting(child);
  9299. }
  9300. };
  9301. /**
  9302. * Set focus to the end of an editable div
  9303. * code from Nico Burns
  9304. * http://stackoverflow.com/users/140293/nico-burns
  9305. * http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity
  9306. * @param {Element} contentEditableElement A content editable div
  9307. */
  9308. exports.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
  9309. var range, selection;
  9310. if(document.createRange) {
  9311. range = document.createRange();//Create a range (a range is a like the selection but invisible)
  9312. range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
  9313. range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
  9314. selection = window.getSelection();//get the selection object (allows you to change selection)
  9315. selection.removeAllRanges();//remove any selections already made
  9316. selection.addRange(range);//make the range you have just created the visible selection
  9317. }
  9318. };
  9319. /**
  9320. * Select all text of a content editable div.
  9321. * http://stackoverflow.com/a/3806004/1262753
  9322. * @param {Element} contentEditableElement A content editable div
  9323. */
  9324. exports.selectContentEditable = function selectContentEditable(contentEditableElement) {
  9325. if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
  9326. return;
  9327. }
  9328. var sel, range;
  9329. if (window.getSelection && document.createRange) {
  9330. range = document.createRange();
  9331. range.selectNodeContents(contentEditableElement);
  9332. sel = window.getSelection();
  9333. sel.removeAllRanges();
  9334. sel.addRange(range);
  9335. }
  9336. };
  9337. /**
  9338. * Get text selection
  9339. * http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
  9340. * @return {Range | TextRange | null} range
  9341. */
  9342. exports.getSelection = function getSelection() {
  9343. if (window.getSelection) {
  9344. var sel = window.getSelection();
  9345. if (sel.getRangeAt && sel.rangeCount) {
  9346. return sel.getRangeAt(0);
  9347. }
  9348. }
  9349. return null;
  9350. };
  9351. /**
  9352. * Set text selection
  9353. * http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
  9354. * @param {Range | TextRange | null} range
  9355. */
  9356. exports.setSelection = function setSelection(range) {
  9357. if (range) {
  9358. if (window.getSelection) {
  9359. var sel = window.getSelection();
  9360. sel.removeAllRanges();
  9361. sel.addRange(range);
  9362. }
  9363. }
  9364. };
  9365. /**
  9366. * Get selected text range
  9367. * @return {Object} params object containing parameters:
  9368. * {Number} startOffset
  9369. * {Number} endOffset
  9370. * {Element} container HTML element holding the
  9371. * selected text element
  9372. * Returns null if no text selection is found
  9373. */
  9374. exports.getSelectionOffset = function getSelectionOffset() {
  9375. var range = exports.getSelection();
  9376. if (range && 'startOffset' in range && 'endOffset' in range &&
  9377. range.startContainer && (range.startContainer == range.endContainer)) {
  9378. return {
  9379. startOffset: range.startOffset,
  9380. endOffset: range.endOffset,
  9381. container: range.startContainer.parentNode
  9382. };
  9383. }
  9384. return null;
  9385. };
  9386. /**
  9387. * Set selected text range in given element
  9388. * @param {Object} params An object containing:
  9389. * {Element} container
  9390. * {Number} startOffset
  9391. * {Number} endOffset
  9392. */
  9393. exports.setSelectionOffset = function setSelectionOffset(params) {
  9394. if (document.createRange && window.getSelection) {
  9395. var selection = window.getSelection();
  9396. if(selection) {
  9397. var range = document.createRange();
  9398. if (!params.container.firstChild) {
  9399. params.container.appendChild(document.createTextNode(''));
  9400. }
  9401. // TODO: do not suppose that the first child of the container is a textnode,
  9402. // but recursively find the textnodes
  9403. range.setStart(params.container.firstChild, params.startOffset);
  9404. range.setEnd(params.container.firstChild, params.endOffset);
  9405. exports.setSelection(range);
  9406. }
  9407. }
  9408. };
  9409. /**
  9410. * Get the inner text of an HTML element (for example a div element)
  9411. * @param {Element} element
  9412. * @param {Object} [buffer]
  9413. * @return {String} innerText
  9414. */
  9415. exports.getInnerText = function getInnerText(element, buffer) {
  9416. var first = (buffer == undefined);
  9417. if (first) {
  9418. buffer = {
  9419. 'text': '',
  9420. 'flush': function () {
  9421. var text = this.text;
  9422. this.text = '';
  9423. return text;
  9424. },
  9425. 'set': function (text) {
  9426. this.text = text;
  9427. }
  9428. };
  9429. }
  9430. // text node
  9431. if (element.nodeValue) {
  9432. return buffer.flush() + element.nodeValue;
  9433. }
  9434. // divs or other HTML elements
  9435. if (element.hasChildNodes()) {
  9436. var childNodes = element.childNodes;
  9437. var innerText = '';
  9438. for (var i = 0, iMax = childNodes.length; i < iMax; i++) {
  9439. var child = childNodes[i];
  9440. if (child.nodeName == 'DIV' || child.nodeName == 'P') {
  9441. var prevChild = childNodes[i - 1];
  9442. var prevName = prevChild ? prevChild.nodeName : undefined;
  9443. if (prevName && prevName != 'DIV' && prevName != 'P' && prevName != 'BR') {
  9444. innerText += '\n';
  9445. buffer.flush();
  9446. }
  9447. innerText += exports.getInnerText(child, buffer);
  9448. buffer.set('\n');
  9449. }
  9450. else if (child.nodeName == 'BR') {
  9451. innerText += buffer.flush();
  9452. buffer.set('\n');
  9453. }
  9454. else {
  9455. innerText += exports.getInnerText(child, buffer);
  9456. }
  9457. }
  9458. return innerText;
  9459. }
  9460. else {
  9461. if (element.nodeName == 'P' && exports.getInternetExplorerVersion() != -1) {
  9462. // On Internet Explorer, a <p> with hasChildNodes()==false is
  9463. // rendered with a new line. Note that a <p> with
  9464. // hasChildNodes()==true is rendered without a new line
  9465. // Other browsers always ensure there is a <br> inside the <p>,
  9466. // and if not, the <p> does not render a new line
  9467. return buffer.flush();
  9468. }
  9469. }
  9470. // br or unknown
  9471. return '';
  9472. };
  9473. /**
  9474. * Returns the version of Internet Explorer or a -1
  9475. * (indicating the use of another browser).
  9476. * Source: http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx
  9477. * @return {Number} Internet Explorer version, or -1 in case of an other browser
  9478. */
  9479. exports.getInternetExplorerVersion = function getInternetExplorerVersion() {
  9480. if (_ieVersion == -1) {
  9481. var rv = -1; // Return value assumes failure.
  9482. if (navigator.appName == 'Microsoft Internet Explorer')
  9483. {
  9484. var ua = navigator.userAgent;
  9485. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  9486. if (re.exec(ua) != null) {
  9487. rv = parseFloat( RegExp.$1 );
  9488. }
  9489. }
  9490. _ieVersion = rv;
  9491. }
  9492. return _ieVersion;
  9493. };
  9494. /**
  9495. * Test whether the current browser is Firefox
  9496. * @returns {boolean} isFirefox
  9497. */
  9498. exports.isFirefox = function isFirefox () {
  9499. return (navigator.userAgent.indexOf("Firefox") != -1);
  9500. };
  9501. /**
  9502. * cached internet explorer version
  9503. * @type {Number}
  9504. * @private
  9505. */
  9506. var _ieVersion = -1;
  9507. /**
  9508. * Add and event listener. Works for all browsers
  9509. * @param {Element} element An html element
  9510. * @param {string} action The action, for example "click",
  9511. * without the prefix "on"
  9512. * @param {function} listener The callback function to be executed
  9513. * @param {boolean} [useCapture] false by default
  9514. * @return {function} the created event listener
  9515. */
  9516. exports.addEventListener = function addEventListener(element, action, listener, useCapture) {
  9517. if (element.addEventListener) {
  9518. if (useCapture === undefined)
  9519. useCapture = false;
  9520. if (action === "mousewheel" && exports.isFirefox()) {
  9521. action = "DOMMouseScroll"; // For Firefox
  9522. }
  9523. element.addEventListener(action, listener, useCapture);
  9524. return listener;
  9525. } else if (element.attachEvent) {
  9526. // Old IE browsers
  9527. var f = function () {
  9528. return listener.call(element, window.event);
  9529. };
  9530. element.attachEvent("on" + action, f);
  9531. return f;
  9532. }
  9533. };
  9534. /**
  9535. * Remove an event listener from an element
  9536. * @param {Element} element An html dom element
  9537. * @param {string} action The name of the event, for example "mousedown"
  9538. * @param {function} listener The listener function
  9539. * @param {boolean} [useCapture] false by default
  9540. */
  9541. exports.removeEventListener = function removeEventListener(element, action, listener, useCapture) {
  9542. if (element.removeEventListener) {
  9543. if (useCapture === undefined)
  9544. useCapture = false;
  9545. if (action === "mousewheel" && exports.isFirefox()) {
  9546. action = "DOMMouseScroll"; // For Firefox
  9547. }
  9548. element.removeEventListener(action, listener, useCapture);
  9549. } else if (element.detachEvent) {
  9550. // Old IE browsers
  9551. element.detachEvent("on" + action, listener);
  9552. }
  9553. };
  9554. /**
  9555. * Parse a JSON path like '.items[3].name' into an array
  9556. * @param {string} jsonPath
  9557. * @return {Array}
  9558. */
  9559. exports.parsePath = function parsePath(jsonPath) {
  9560. var prop, remainder;
  9561. if (jsonPath.length === 0) {
  9562. return [];
  9563. }
  9564. // find a match like '.prop'
  9565. var match = jsonPath.match(/^\.(\w+)/);
  9566. if (match) {
  9567. prop = match[1];
  9568. remainder = jsonPath.substr(prop.length + 1);
  9569. }
  9570. else if (jsonPath[0] === '[') {
  9571. // find a match like
  9572. var end = jsonPath.indexOf(']');
  9573. if (end === -1) {
  9574. throw new SyntaxError('Character ] expected in path');
  9575. }
  9576. if (end === 1) {
  9577. throw new SyntaxError('Index expected after [');
  9578. }
  9579. var value = jsonPath.substring(1, end);
  9580. if (value[0] === '\'') {
  9581. // ajv produces string prop names with single quotes, so we need
  9582. // to reformat them into valid double-quoted JSON strings
  9583. value = '\"' + value.substring(1, value.length - 1) + '\"';
  9584. }
  9585. prop = value === '*' ? value : JSON.parse(value); // parse string and number
  9586. remainder = jsonPath.substr(end + 1);
  9587. }
  9588. else {
  9589. throw new SyntaxError('Failed to parse path');
  9590. }
  9591. return [prop].concat(parsePath(remainder))
  9592. };
  9593. /**
  9594. * Improve the error message of a JSON schema error
  9595. * @param {Object} error
  9596. * @return {Object} The error
  9597. */
  9598. exports.improveSchemaError = function (error) {
  9599. if (error.keyword === 'enum' && Array.isArray(error.schema)) {
  9600. var enums = error.schema;
  9601. if (enums) {
  9602. enums = enums.map(function (value) {
  9603. return JSON.stringify(value);
  9604. });
  9605. if (enums.length > 5) {
  9606. var more = ['(' + (enums.length - 5) + ' more...)'];
  9607. enums = enums.slice(0, 5);
  9608. enums.push(more);
  9609. }
  9610. error.message = 'should be equal to one of: ' + enums.join(', ');
  9611. }
  9612. }
  9613. if (error.keyword === 'additionalProperties') {
  9614. error.message = 'should NOT have additional property: ' + error.params.additionalProperty;
  9615. }
  9616. return error;
  9617. };
  9618. /**
  9619. * Test whether the child rect fits completely inside the parent rect.
  9620. * @param {ClientRect} parent
  9621. * @param {ClientRect} child
  9622. * @param {number} margin
  9623. */
  9624. exports.insideRect = function (parent, child, margin) {
  9625. var _margin = margin !== undefined ? margin : 0;
  9626. return child.left - _margin >= parent.left
  9627. && child.right + _margin <= parent.right
  9628. && child.top - _margin >= parent.top
  9629. && child.bottom + _margin <= parent.bottom;
  9630. };
  9631. /**
  9632. * Returns a function, that, as long as it continues to be invoked, will not
  9633. * be triggered. The function will be called after it stops being called for
  9634. * N milliseconds.
  9635. *
  9636. * Source: https://davidwalsh.name/javascript-debounce-function
  9637. *
  9638. * @param {function} func
  9639. * @param {number} wait Number in milliseconds
  9640. * @param {boolean} [immediate=false] If `immediate` is passed, trigger the
  9641. * function on the leading edge, instead
  9642. * of the trailing.
  9643. * @return {function} Return the debounced function
  9644. */
  9645. exports.debounce = function debounce(func, wait, immediate) {
  9646. var timeout;
  9647. return function() {
  9648. var context = this, args = arguments;
  9649. var later = function() {
  9650. timeout = null;
  9651. if (!immediate) func.apply(context, args);
  9652. };
  9653. var callNow = immediate && !timeout;
  9654. clearTimeout(timeout);
  9655. timeout = setTimeout(later, wait);
  9656. if (callNow) func.apply(context, args);
  9657. };
  9658. };
  9659. /**
  9660. * Determines the difference between two texts.
  9661. * Can only detect one removed or inserted block of characters.
  9662. * @param {string} oldText
  9663. * @param {string} newText
  9664. * @return {{start: number, end: number}} Returns the start and end
  9665. * of the changed part in newText.
  9666. */
  9667. exports.textDiff = function textDiff(oldText, newText) {
  9668. var len = newText.length;
  9669. var start = 0;
  9670. var oldEnd = oldText.length;
  9671. var newEnd = newText.length;
  9672. while (newText.charAt(start) === oldText.charAt(start)
  9673. && start < len) {
  9674. start++;
  9675. }
  9676. while (newText.charAt(newEnd - 1) === oldText.charAt(oldEnd - 1)
  9677. && newEnd > start && oldEnd > 0) {
  9678. newEnd--;
  9679. oldEnd--;
  9680. }
  9681. return {start: start, end: newEnd};
  9682. };
  9683. /***/ },
  9684. /* 55 */
  9685. /***/ function(module, exports, __webpack_require__) {
  9686. /* Jison generated parser */
  9687. var jsonlint = (function(){
  9688. var parser = {trace: function trace() { },
  9689. yy: {},
  9690. symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
  9691. terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},
  9692. productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],
  9693. performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
  9694. var $0 = $$.length - 1;
  9695. switch (yystate) {
  9696. case 1: // replace escaped characters with actual character
  9697. this.$ = yytext.replace(/\\(\\|")/g, "$"+"1")
  9698. .replace(/\\n/g,'\n')
  9699. .replace(/\\r/g,'\r')
  9700. .replace(/\\t/g,'\t')
  9701. .replace(/\\v/g,'\v')
  9702. .replace(/\\f/g,'\f')
  9703. .replace(/\\b/g,'\b');
  9704. break;
  9705. case 2:this.$ = Number(yytext);
  9706. break;
  9707. case 3:this.$ = null;
  9708. break;
  9709. case 4:this.$ = true;
  9710. break;
  9711. case 5:this.$ = false;
  9712. break;
  9713. case 6:return this.$ = $$[$0-1];
  9714. break;
  9715. case 13:this.$ = {};
  9716. break;
  9717. case 14:this.$ = $$[$0-1];
  9718. break;
  9719. case 15:this.$ = [$$[$0-2], $$[$0]];
  9720. break;
  9721. case 16:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
  9722. break;
  9723. case 17:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1];
  9724. break;
  9725. case 18:this.$ = [];
  9726. break;
  9727. case 19:this.$ = $$[$0-1];
  9728. break;
  9729. case 20:this.$ = [$$[$0]];
  9730. break;
  9731. case 21:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
  9732. break;
  9733. }
  9734. },
  9735. table: [{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}],
  9736. defaultActions: {16:[2,6]},
  9737. parseError: function parseError(str, hash) {
  9738. throw new Error(str);
  9739. },
  9740. parse: function parse(input) {
  9741. var self = this,
  9742. stack = [0],
  9743. vstack = [null], // semantic value stack
  9744. lstack = [], // location stack
  9745. table = this.table,
  9746. yytext = '',
  9747. yylineno = 0,
  9748. yyleng = 0,
  9749. recovering = 0,
  9750. TERROR = 2,
  9751. EOF = 1;
  9752. //this.reductionCount = this.shiftCount = 0;
  9753. this.lexer.setInput(input);
  9754. this.lexer.yy = this.yy;
  9755. this.yy.lexer = this.lexer;
  9756. if (typeof this.lexer.yylloc == 'undefined')
  9757. this.lexer.yylloc = {};
  9758. var yyloc = this.lexer.yylloc;
  9759. lstack.push(yyloc);
  9760. if (typeof this.yy.parseError === 'function')
  9761. this.parseError = this.yy.parseError;
  9762. function popStack (n) {
  9763. stack.length = stack.length - 2*n;
  9764. vstack.length = vstack.length - n;
  9765. lstack.length = lstack.length - n;
  9766. }
  9767. function lex() {
  9768. var token;
  9769. token = self.lexer.lex() || 1; // $end = 1
  9770. // if token isn't its numeric value, convert
  9771. if (typeof token !== 'number') {
  9772. token = self.symbols_[token] || token;
  9773. }
  9774. return token;
  9775. }
  9776. var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
  9777. while (true) {
  9778. // retreive state number from top of stack
  9779. state = stack[stack.length-1];
  9780. // use default actions if available
  9781. if (this.defaultActions[state]) {
  9782. action = this.defaultActions[state];
  9783. } else {
  9784. if (symbol == null)
  9785. symbol = lex();
  9786. // read action for current state and first input
  9787. action = table[state] && table[state][symbol];
  9788. }
  9789. // handle parse error
  9790. _handle_error:
  9791. if (typeof action === 'undefined' || !action.length || !action[0]) {
  9792. if (!recovering) {
  9793. // Report error
  9794. expected = [];
  9795. for (p in table[state]) if (this.terminals_[p] && p > 2) {
  9796. expected.push("'"+this.terminals_[p]+"'");
  9797. }
  9798. var errStr = '';
  9799. if (this.lexer.showPosition) {
  9800. errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
  9801. } else {
  9802. errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
  9803. (symbol == 1 /*EOF*/ ? "end of input" :
  9804. ("'"+(this.terminals_[symbol] || symbol)+"'"));
  9805. }
  9806. this.parseError(errStr,
  9807. {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
  9808. }
  9809. // just recovered from another error
  9810. if (recovering == 3) {
  9811. if (symbol == EOF) {
  9812. throw new Error(errStr || 'Parsing halted.');
  9813. }
  9814. // discard current lookahead and grab another
  9815. yyleng = this.lexer.yyleng;
  9816. yytext = this.lexer.yytext;
  9817. yylineno = this.lexer.yylineno;
  9818. yyloc = this.lexer.yylloc;
  9819. symbol = lex();
  9820. }
  9821. // try to recover from error
  9822. while (1) {
  9823. // check for error recovery rule in this state
  9824. if ((TERROR.toString()) in table[state]) {
  9825. break;
  9826. }
  9827. if (state == 0) {
  9828. throw new Error(errStr || 'Parsing halted.');
  9829. }
  9830. popStack(1);
  9831. state = stack[stack.length-1];
  9832. }
  9833. preErrorSymbol = symbol; // save the lookahead token
  9834. symbol = TERROR; // insert generic error symbol as new lookahead
  9835. state = stack[stack.length-1];
  9836. action = table[state] && table[state][TERROR];
  9837. recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
  9838. }
  9839. // this shouldn't happen, unless resolve defaults are off
  9840. if (action[0] instanceof Array && action.length > 1) {
  9841. throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
  9842. }
  9843. switch (action[0]) {
  9844. case 1: // shift
  9845. //this.shiftCount++;
  9846. stack.push(symbol);
  9847. vstack.push(this.lexer.yytext);
  9848. lstack.push(this.lexer.yylloc);
  9849. stack.push(action[1]); // push state
  9850. symbol = null;
  9851. if (!preErrorSymbol) { // normal execution/no error
  9852. yyleng = this.lexer.yyleng;
  9853. yytext = this.lexer.yytext;
  9854. yylineno = this.lexer.yylineno;
  9855. yyloc = this.lexer.yylloc;
  9856. if (recovering > 0)
  9857. recovering--;
  9858. } else { // error just occurred, resume old lookahead f/ before error
  9859. symbol = preErrorSymbol;
  9860. preErrorSymbol = null;
  9861. }
  9862. break;
  9863. case 2: // reduce
  9864. //this.reductionCount++;
  9865. len = this.productions_[action[1]][1];
  9866. // perform semantic action
  9867. yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
  9868. // default location, uses first token for firsts, last for lasts
  9869. yyval._$ = {
  9870. first_line: lstack[lstack.length-(len||1)].first_line,
  9871. last_line: lstack[lstack.length-1].last_line,
  9872. first_column: lstack[lstack.length-(len||1)].first_column,
  9873. last_column: lstack[lstack.length-1].last_column
  9874. };
  9875. r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
  9876. if (typeof r !== 'undefined') {
  9877. return r;
  9878. }
  9879. // pop off stack
  9880. if (len) {
  9881. stack = stack.slice(0,-1*len*2);
  9882. vstack = vstack.slice(0, -1*len);
  9883. lstack = lstack.slice(0, -1*len);
  9884. }
  9885. stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
  9886. vstack.push(yyval.$);
  9887. lstack.push(yyval._$);
  9888. // goto new state = table[STATE][NONTERMINAL]
  9889. newState = table[stack[stack.length-2]][stack[stack.length-1]];
  9890. stack.push(newState);
  9891. break;
  9892. case 3: // accept
  9893. return true;
  9894. }
  9895. }
  9896. return true;
  9897. }};
  9898. /* Jison generated lexer */
  9899. var lexer = (function(){
  9900. var lexer = ({EOF:1,
  9901. parseError:function parseError(str, hash) {
  9902. if (this.yy.parseError) {
  9903. this.yy.parseError(str, hash);
  9904. } else {
  9905. throw new Error(str);
  9906. }
  9907. },
  9908. setInput:function (input) {
  9909. this._input = input;
  9910. this._more = this._less = this.done = false;
  9911. this.yylineno = this.yyleng = 0;
  9912. this.yytext = this.matched = this.match = '';
  9913. this.conditionStack = ['INITIAL'];
  9914. this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
  9915. return this;
  9916. },
  9917. input:function () {
  9918. var ch = this._input[0];
  9919. this.yytext+=ch;
  9920. this.yyleng++;
  9921. this.match+=ch;
  9922. this.matched+=ch;
  9923. var lines = ch.match(/\n/);
  9924. if (lines) this.yylineno++;
  9925. this._input = this._input.slice(1);
  9926. return ch;
  9927. },
  9928. unput:function (ch) {
  9929. this._input = ch + this._input;
  9930. return this;
  9931. },
  9932. more:function () {
  9933. this._more = true;
  9934. return this;
  9935. },
  9936. less:function (n) {
  9937. this._input = this.match.slice(n) + this._input;
  9938. },
  9939. pastInput:function () {
  9940. var past = this.matched.substr(0, this.matched.length - this.match.length);
  9941. return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
  9942. },
  9943. upcomingInput:function () {
  9944. var next = this.match;
  9945. if (next.length < 20) {
  9946. next += this._input.substr(0, 20-next.length);
  9947. }
  9948. return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
  9949. },
  9950. showPosition:function () {
  9951. var pre = this.pastInput();
  9952. var c = new Array(pre.length + 1).join("-");
  9953. return pre + this.upcomingInput() + "\n" + c+"^";
  9954. },
  9955. next:function () {
  9956. if (this.done) {
  9957. return this.EOF;
  9958. }
  9959. if (!this._input) this.done = true;
  9960. var token,
  9961. match,
  9962. tempMatch,
  9963. index,
  9964. col,
  9965. lines;
  9966. if (!this._more) {
  9967. this.yytext = '';
  9968. this.match = '';
  9969. }
  9970. var rules = this._currentRules();
  9971. for (var i=0;i < rules.length; i++) {
  9972. tempMatch = this._input.match(this.rules[rules[i]]);
  9973. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  9974. match = tempMatch;
  9975. index = i;
  9976. if (!this.options.flex) break;
  9977. }
  9978. }
  9979. if (match) {
  9980. lines = match[0].match(/\n.*/g);
  9981. if (lines) this.yylineno += lines.length;
  9982. this.yylloc = {first_line: this.yylloc.last_line,
  9983. last_line: this.yylineno+1,
  9984. first_column: this.yylloc.last_column,
  9985. last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
  9986. this.yytext += match[0];
  9987. this.match += match[0];
  9988. this.yyleng = this.yytext.length;
  9989. this._more = false;
  9990. this._input = this._input.slice(match[0].length);
  9991. this.matched += match[0];
  9992. token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
  9993. if (this.done && this._input) this.done = false;
  9994. if (token) return token;
  9995. else return;
  9996. }
  9997. if (this._input === "") {
  9998. return this.EOF;
  9999. } else {
  10000. this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
  10001. {text: "", token: null, line: this.yylineno});
  10002. }
  10003. },
  10004. lex:function lex() {
  10005. var r = this.next();
  10006. if (typeof r !== 'undefined') {
  10007. return r;
  10008. } else {
  10009. return this.lex();
  10010. }
  10011. },
  10012. begin:function begin(condition) {
  10013. this.conditionStack.push(condition);
  10014. },
  10015. popState:function popState() {
  10016. return this.conditionStack.pop();
  10017. },
  10018. _currentRules:function _currentRules() {
  10019. return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
  10020. },
  10021. topState:function () {
  10022. return this.conditionStack[this.conditionStack.length-2];
  10023. },
  10024. pushState:function begin(condition) {
  10025. this.begin(condition);
  10026. }});
  10027. lexer.options = {};
  10028. lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
  10029. var YYSTATE=YY_START
  10030. switch($avoiding_name_collisions) {
  10031. case 0:/* skip whitespace */
  10032. break;
  10033. case 1:return 6
  10034. break;
  10035. case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4
  10036. break;
  10037. case 3:return 17
  10038. break;
  10039. case 4:return 18
  10040. break;
  10041. case 5:return 23
  10042. break;
  10043. case 6:return 24
  10044. break;
  10045. case 7:return 22
  10046. break;
  10047. case 8:return 21
  10048. break;
  10049. case 9:return 10
  10050. break;
  10051. case 10:return 11
  10052. break;
  10053. case 11:return 8
  10054. break;
  10055. case 12:return 14
  10056. break;
  10057. case 13:return 'INVALID'
  10058. break;
  10059. }
  10060. };
  10061. lexer.rules = [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/];
  10062. lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}};
  10063. ;
  10064. return lexer;})()
  10065. parser.lexer = lexer;
  10066. return parser;
  10067. })();
  10068. if (true) {
  10069. exports.parser = jsonlint;
  10070. exports.parse = jsonlint.parse.bind(jsonlint);
  10071. }
  10072. /***/ },
  10073. /* 56 */
  10074. /***/ function(module, exports) {
  10075. 'use strict';
  10076. /**
  10077. * @constructor SearchBox
  10078. * Create a search box in given HTML container
  10079. * @param {JSONEditor} editor The JSON Editor to attach to
  10080. * @param {Element} container HTML container element of where to
  10081. * create the search box
  10082. */
  10083. function SearchBox (editor, container) {
  10084. var searchBox = this;
  10085. this.editor = editor;
  10086. this.timeout = undefined;
  10087. this.delay = 200; // ms
  10088. this.lastText = undefined;
  10089. this.dom = {};
  10090. this.dom.container = container;
  10091. var table = document.createElement('table');
  10092. this.dom.table = table;
  10093. table.className = 'jsoneditor-search';
  10094. container.appendChild(table);
  10095. var tbody = document.createElement('tbody');
  10096. this.dom.tbody = tbody;
  10097. table.appendChild(tbody);
  10098. var tr = document.createElement('tr');
  10099. tbody.appendChild(tr);
  10100. var td = document.createElement('td');
  10101. tr.appendChild(td);
  10102. var results = document.createElement('div');
  10103. this.dom.results = results;
  10104. results.className = 'jsoneditor-results';
  10105. td.appendChild(results);
  10106. td = document.createElement('td');
  10107. tr.appendChild(td);
  10108. var divInput = document.createElement('div');
  10109. this.dom.input = divInput;
  10110. divInput.className = 'jsoneditor-frame';
  10111. divInput.title = 'Search fields and values';
  10112. td.appendChild(divInput);
  10113. // table to contain the text input and search button
  10114. var tableInput = document.createElement('table');
  10115. divInput.appendChild(tableInput);
  10116. var tbodySearch = document.createElement('tbody');
  10117. tableInput.appendChild(tbodySearch);
  10118. tr = document.createElement('tr');
  10119. tbodySearch.appendChild(tr);
  10120. var refreshSearch = document.createElement('button');
  10121. refreshSearch.type = 'button';
  10122. refreshSearch.className = 'jsoneditor-refresh';
  10123. td = document.createElement('td');
  10124. td.appendChild(refreshSearch);
  10125. tr.appendChild(td);
  10126. var search = document.createElement('input');
  10127. // search.type = 'button';
  10128. this.dom.search = search;
  10129. search.oninput = function (event) {
  10130. searchBox._onDelayedSearch(event);
  10131. };
  10132. search.onchange = function (event) { // For IE 9
  10133. searchBox._onSearch();
  10134. };
  10135. search.onkeydown = function (event) {
  10136. searchBox._onKeyDown(event);
  10137. };
  10138. search.onkeyup = function (event) {
  10139. searchBox._onKeyUp(event);
  10140. };
  10141. refreshSearch.onclick = function (event) {
  10142. search.select();
  10143. };
  10144. // TODO: ESC in FF restores the last input, is a FF bug, https://bugzilla.mozilla.org/show_bug.cgi?id=598819
  10145. td = document.createElement('td');
  10146. td.appendChild(search);
  10147. tr.appendChild(td);
  10148. var searchNext = document.createElement('button');
  10149. searchNext.type = 'button';
  10150. searchNext.title = 'Next result (Enter)';
  10151. searchNext.className = 'jsoneditor-next';
  10152. searchNext.onclick = function () {
  10153. searchBox.next();
  10154. };
  10155. td = document.createElement('td');
  10156. td.appendChild(searchNext);
  10157. tr.appendChild(td);
  10158. var searchPrevious = document.createElement('button');
  10159. searchPrevious.type = 'button';
  10160. searchPrevious.title = 'Previous result (Shift+Enter)';
  10161. searchPrevious.className = 'jsoneditor-previous';
  10162. searchPrevious.onclick = function () {
  10163. searchBox.previous();
  10164. };
  10165. td = document.createElement('td');
  10166. td.appendChild(searchPrevious);
  10167. tr.appendChild(td);
  10168. }
  10169. /**
  10170. * Go to the next search result
  10171. * @param {boolean} [focus] If true, focus will be set to the next result
  10172. * focus is false by default.
  10173. */
  10174. SearchBox.prototype.next = function(focus) {
  10175. if (this.results != undefined) {
  10176. var index = (this.resultIndex != undefined) ? this.resultIndex + 1 : 0;
  10177. if (index > this.results.length - 1) {
  10178. index = 0;
  10179. }
  10180. this._setActiveResult(index, focus);
  10181. }
  10182. };
  10183. /**
  10184. * Go to the prevous search result
  10185. * @param {boolean} [focus] If true, focus will be set to the next result
  10186. * focus is false by default.
  10187. */
  10188. SearchBox.prototype.previous = function(focus) {
  10189. if (this.results != undefined) {
  10190. var max = this.results.length - 1;
  10191. var index = (this.resultIndex != undefined) ? this.resultIndex - 1 : max;
  10192. if (index < 0) {
  10193. index = max;
  10194. }
  10195. this._setActiveResult(index, focus);
  10196. }
  10197. };
  10198. /**
  10199. * Set new value for the current active result
  10200. * @param {Number} index
  10201. * @param {boolean} [focus] If true, focus will be set to the next result.
  10202. * focus is false by default.
  10203. * @private
  10204. */
  10205. SearchBox.prototype._setActiveResult = function(index, focus) {
  10206. // de-activate current active result
  10207. if (this.activeResult) {
  10208. var prevNode = this.activeResult.node;
  10209. var prevElem = this.activeResult.elem;
  10210. if (prevElem == 'field') {
  10211. delete prevNode.searchFieldActive;
  10212. }
  10213. else {
  10214. delete prevNode.searchValueActive;
  10215. }
  10216. prevNode.updateDom();
  10217. }
  10218. if (!this.results || !this.results[index]) {
  10219. // out of range, set to undefined
  10220. this.resultIndex = undefined;
  10221. this.activeResult = undefined;
  10222. return;
  10223. }
  10224. this.resultIndex = index;
  10225. // set new node active
  10226. var node = this.results[this.resultIndex].node;
  10227. var elem = this.results[this.resultIndex].elem;
  10228. if (elem == 'field') {
  10229. node.searchFieldActive = true;
  10230. }
  10231. else {
  10232. node.searchValueActive = true;
  10233. }
  10234. this.activeResult = this.results[this.resultIndex];
  10235. node.updateDom();
  10236. // TODO: not so nice that the focus is only set after the animation is finished
  10237. node.scrollTo(function () {
  10238. if (focus) {
  10239. node.focus(elem);
  10240. }
  10241. });
  10242. };
  10243. /**
  10244. * Cancel any running onDelayedSearch.
  10245. * @private
  10246. */
  10247. SearchBox.prototype._clearDelay = function() {
  10248. if (this.timeout != undefined) {
  10249. clearTimeout(this.timeout);
  10250. delete this.timeout;
  10251. }
  10252. };
  10253. /**
  10254. * Start a timer to execute a search after a short delay.
  10255. * Used for reducing the number of searches while typing.
  10256. * @param {Event} event
  10257. * @private
  10258. */
  10259. SearchBox.prototype._onDelayedSearch = function (event) {
  10260. // execute the search after a short delay (reduces the number of
  10261. // search actions while typing in the search text box)
  10262. this._clearDelay();
  10263. var searchBox = this;
  10264. this.timeout = setTimeout(function (event) {
  10265. searchBox._onSearch();
  10266. },
  10267. this.delay);
  10268. };
  10269. /**
  10270. * Handle onSearch event
  10271. * @param {boolean} [forceSearch] If true, search will be executed again even
  10272. * when the search text is not changed.
  10273. * Default is false.
  10274. * @private
  10275. */
  10276. SearchBox.prototype._onSearch = function (forceSearch) {
  10277. this._clearDelay();
  10278. var value = this.dom.search.value;
  10279. var text = (value.length > 0) ? value : undefined;
  10280. if (text != this.lastText || forceSearch) {
  10281. // only search again when changed
  10282. this.lastText = text;
  10283. this.results = this.editor.search(text);
  10284. this._setActiveResult(undefined);
  10285. // display search results
  10286. if (text != undefined) {
  10287. var resultCount = this.results.length;
  10288. switch (resultCount) {
  10289. case 0: this.dom.results.innerHTML = 'no&nbsp;results'; break;
  10290. case 1: this.dom.results.innerHTML = '1&nbsp;result'; break;
  10291. default: this.dom.results.innerHTML = resultCount + '&nbsp;results'; break;
  10292. }
  10293. }
  10294. else {
  10295. this.dom.results.innerHTML = '';
  10296. }
  10297. }
  10298. };
  10299. /**
  10300. * Handle onKeyDown event in the input box
  10301. * @param {Event} event
  10302. * @private
  10303. */
  10304. SearchBox.prototype._onKeyDown = function (event) {
  10305. var keynum = event.which;
  10306. if (keynum == 27) { // ESC
  10307. this.dom.search.value = ''; // clear search
  10308. this._onSearch();
  10309. event.preventDefault();
  10310. event.stopPropagation();
  10311. }
  10312. else if (keynum == 13) { // Enter
  10313. if (event.ctrlKey) {
  10314. // force to search again
  10315. this._onSearch(true);
  10316. }
  10317. else if (event.shiftKey) {
  10318. // move to the previous search result
  10319. this.previous();
  10320. }
  10321. else {
  10322. // move to the next search result
  10323. this.next();
  10324. }
  10325. event.preventDefault();
  10326. event.stopPropagation();
  10327. }
  10328. };
  10329. /**
  10330. * Handle onKeyUp event in the input box
  10331. * @param {Event} event
  10332. * @private
  10333. */
  10334. SearchBox.prototype._onKeyUp = function (event) {
  10335. var keynum = event.keyCode;
  10336. if (keynum != 27 && keynum != 13) { // !show and !Enter
  10337. this._onDelayedSearch(event); // For IE 9
  10338. }
  10339. };
  10340. /**
  10341. * Clear the search results
  10342. */
  10343. SearchBox.prototype.clear = function () {
  10344. this.dom.search.value = '';
  10345. this._onSearch();
  10346. };
  10347. /**
  10348. * Destroy the search box
  10349. */
  10350. SearchBox.prototype.destroy = function () {
  10351. this.editor = null;
  10352. this.dom.container.removeChild(this.dom.table);
  10353. this.dom = null;
  10354. this.results = null;
  10355. this.activeResult = null;
  10356. this._clearDelay();
  10357. };
  10358. module.exports = SearchBox;
  10359. /***/ },
  10360. /* 57 */
  10361. /***/ function(module, exports, __webpack_require__) {
  10362. 'use strict';
  10363. var util = __webpack_require__(54);
  10364. /**
  10365. * A context menu
  10366. * @param {Object[]} items Array containing the menu structure
  10367. * TODO: describe structure
  10368. * @param {Object} [options] Object with options. Available options:
  10369. * {function} close Callback called when the
  10370. * context menu is being closed.
  10371. * @constructor
  10372. */
  10373. function ContextMenu (items, options) {
  10374. this.dom = {};
  10375. var me = this;
  10376. var dom = this.dom;
  10377. this.anchor = undefined;
  10378. this.items = items;
  10379. this.eventListeners = {};
  10380. this.selection = undefined; // holds the selection before the menu was opened
  10381. this.onClose = options ? options.close : undefined;
  10382. // create root element
  10383. var root = document.createElement('div');
  10384. root.className = 'jsoneditor-contextmenu-root';
  10385. dom.root = root;
  10386. // create a container element
  10387. var menu = document.createElement('div');
  10388. menu.className = 'jsoneditor-contextmenu';
  10389. dom.menu = menu;
  10390. root.appendChild(menu);
  10391. // create a list to hold the menu items
  10392. var list = document.createElement('ul');
  10393. list.className = 'jsoneditor-menu';
  10394. menu.appendChild(list);
  10395. dom.list = list;
  10396. dom.items = []; // list with all buttons
  10397. // create a (non-visible) button to set the focus to the menu
  10398. var focusButton = document.createElement('button');
  10399. focusButton.type = 'button';
  10400. dom.focusButton = focusButton;
  10401. var li = document.createElement('li');
  10402. li.style.overflow = 'hidden';
  10403. li.style.height = '0';
  10404. li.appendChild(focusButton);
  10405. list.appendChild(li);
  10406. function createMenuItems (list, domItems, items) {
  10407. items.forEach(function (item) {
  10408. if (item.type == 'separator') {
  10409. // create a separator
  10410. var separator = document.createElement('div');
  10411. separator.className = 'jsoneditor-separator';
  10412. li = document.createElement('li');
  10413. li.appendChild(separator);
  10414. list.appendChild(li);
  10415. }
  10416. else {
  10417. var domItem = {};
  10418. // create a menu item
  10419. var li = document.createElement('li');
  10420. list.appendChild(li);
  10421. // create a button in the menu item
  10422. var button = document.createElement('button');
  10423. button.type = 'button';
  10424. button.className = item.className;
  10425. domItem.button = button;
  10426. if (item.title) {
  10427. button.title = item.title;
  10428. }
  10429. if (item.click) {
  10430. button.onclick = function (event) {
  10431. event.preventDefault();
  10432. me.hide();
  10433. item.click();
  10434. };
  10435. }
  10436. li.appendChild(button);
  10437. // create the contents of the button
  10438. if (item.submenu) {
  10439. // add the icon to the button
  10440. var divIcon = document.createElement('div');
  10441. divIcon.className = 'jsoneditor-icon';
  10442. button.appendChild(divIcon);
  10443. button.appendChild(document.createTextNode(item.text));
  10444. var buttonSubmenu;
  10445. if (item.click) {
  10446. // submenu and a button with a click handler
  10447. button.className += ' jsoneditor-default';
  10448. var buttonExpand = document.createElement('button');
  10449. buttonExpand.type = 'button';
  10450. domItem.buttonExpand = buttonExpand;
  10451. buttonExpand.className = 'jsoneditor-expand';
  10452. buttonExpand.innerHTML = '<div class="jsoneditor-expand"></div>';
  10453. li.appendChild(buttonExpand);
  10454. if (item.submenuTitle) {
  10455. buttonExpand.title = item.submenuTitle;
  10456. }
  10457. buttonSubmenu = buttonExpand;
  10458. }
  10459. else {
  10460. // submenu and a button without a click handler
  10461. var divExpand = document.createElement('div');
  10462. divExpand.className = 'jsoneditor-expand';
  10463. button.appendChild(divExpand);
  10464. buttonSubmenu = button;
  10465. }
  10466. // attach a handler to expand/collapse the submenu
  10467. buttonSubmenu.onclick = function (event) {
  10468. event.preventDefault();
  10469. me._onExpandItem(domItem);
  10470. buttonSubmenu.focus();
  10471. };
  10472. // create the submenu
  10473. var domSubItems = [];
  10474. domItem.subItems = domSubItems;
  10475. var ul = document.createElement('ul');
  10476. domItem.ul = ul;
  10477. ul.className = 'jsoneditor-menu';
  10478. ul.style.height = '0';
  10479. li.appendChild(ul);
  10480. createMenuItems(ul, domSubItems, item.submenu);
  10481. }
  10482. else {
  10483. // no submenu, just a button with clickhandler
  10484. button.innerHTML = '<div class="jsoneditor-icon"></div>' + item.text;
  10485. }
  10486. domItems.push(domItem);
  10487. }
  10488. });
  10489. }
  10490. createMenuItems(list, this.dom.items, items);
  10491. // TODO: when the editor is small, show the submenu on the right instead of inline?
  10492. // calculate the max height of the menu with one submenu expanded
  10493. this.maxHeight = 0; // height in pixels
  10494. items.forEach(function (item) {
  10495. var height = (items.length + (item.submenu ? item.submenu.length : 0)) * 24;
  10496. me.maxHeight = Math.max(me.maxHeight, height);
  10497. });
  10498. }
  10499. /**
  10500. * Get the currently visible buttons
  10501. * @return {Array.<HTMLElement>} buttons
  10502. * @private
  10503. */
  10504. ContextMenu.prototype._getVisibleButtons = function () {
  10505. var buttons = [];
  10506. var me = this;
  10507. this.dom.items.forEach(function (item) {
  10508. buttons.push(item.button);
  10509. if (item.buttonExpand) {
  10510. buttons.push(item.buttonExpand);
  10511. }
  10512. if (item.subItems && item == me.expandedItem) {
  10513. item.subItems.forEach(function (subItem) {
  10514. buttons.push(subItem.button);
  10515. if (subItem.buttonExpand) {
  10516. buttons.push(subItem.buttonExpand);
  10517. }
  10518. // TODO: change to fully recursive method
  10519. });
  10520. }
  10521. });
  10522. return buttons;
  10523. };
  10524. // currently displayed context menu, a singleton. We may only have one visible context menu
  10525. ContextMenu.visibleMenu = undefined;
  10526. /**
  10527. * Attach the menu to an anchor
  10528. * @param {HTMLElement} anchor Anchor where the menu will be attached
  10529. * as sibling.
  10530. * @param {HTMLElement} [contentWindow] The DIV with with the (scrollable) contents
  10531. */
  10532. ContextMenu.prototype.show = function (anchor, contentWindow) {
  10533. this.hide();
  10534. // determine whether to display the menu below or above the anchor
  10535. var showBelow = true;
  10536. if (contentWindow) {
  10537. var anchorRect = anchor.getBoundingClientRect();
  10538. var contentRect = contentWindow.getBoundingClientRect();
  10539. if (anchorRect.bottom + this.maxHeight < contentRect.bottom) {
  10540. // fits below -> show below
  10541. }
  10542. else if (anchorRect.top - this.maxHeight > contentRect.top) {
  10543. // fits above -> show above
  10544. showBelow = false;
  10545. }
  10546. else {
  10547. // doesn't fit above nor below -> show below
  10548. }
  10549. }
  10550. // position the menu
  10551. if (showBelow) {
  10552. // display the menu below the anchor
  10553. var anchorHeight = anchor.offsetHeight;
  10554. this.dom.menu.style.left = '0px';
  10555. this.dom.menu.style.top = anchorHeight + 'px';
  10556. this.dom.menu.style.bottom = '';
  10557. }
  10558. else {
  10559. // display the menu above the anchor
  10560. this.dom.menu.style.left = '0px';
  10561. this.dom.menu.style.top = '';
  10562. this.dom.menu.style.bottom = '0px';
  10563. }
  10564. // attach the menu to the parent of the anchor
  10565. var parent = anchor.parentNode;
  10566. parent.insertBefore(this.dom.root, parent.firstChild);
  10567. // create and attach event listeners
  10568. var me = this;
  10569. var list = this.dom.list;
  10570. this.eventListeners.mousedown = util.addEventListener(window, 'mousedown', function (event) {
  10571. // hide menu on click outside of the menu
  10572. var target = event.target;
  10573. if ((target != list) && !me._isChildOf(target, list)) {
  10574. me.hide();
  10575. event.stopPropagation();
  10576. event.preventDefault();
  10577. }
  10578. });
  10579. this.eventListeners.keydown = util.addEventListener(window, 'keydown', function (event) {
  10580. me._onKeyDown(event);
  10581. });
  10582. // move focus to the first button in the context menu
  10583. this.selection = util.getSelection();
  10584. this.anchor = anchor;
  10585. setTimeout(function () {
  10586. me.dom.focusButton.focus();
  10587. }, 0);
  10588. if (ContextMenu.visibleMenu) {
  10589. ContextMenu.visibleMenu.hide();
  10590. }
  10591. ContextMenu.visibleMenu = this;
  10592. };
  10593. /**
  10594. * Hide the context menu if visible
  10595. */
  10596. ContextMenu.prototype.hide = function () {
  10597. // remove the menu from the DOM
  10598. if (this.dom.root.parentNode) {
  10599. this.dom.root.parentNode.removeChild(this.dom.root);
  10600. if (this.onClose) {
  10601. this.onClose();
  10602. }
  10603. }
  10604. // remove all event listeners
  10605. // all event listeners are supposed to be attached to document.
  10606. for (var name in this.eventListeners) {
  10607. if (this.eventListeners.hasOwnProperty(name)) {
  10608. var fn = this.eventListeners[name];
  10609. if (fn) {
  10610. util.removeEventListener(window, name, fn);
  10611. }
  10612. delete this.eventListeners[name];
  10613. }
  10614. }
  10615. if (ContextMenu.visibleMenu == this) {
  10616. ContextMenu.visibleMenu = undefined;
  10617. }
  10618. };
  10619. /**
  10620. * Expand a submenu
  10621. * Any currently expanded submenu will be hided.
  10622. * @param {Object} domItem
  10623. * @private
  10624. */
  10625. ContextMenu.prototype._onExpandItem = function (domItem) {
  10626. var me = this;
  10627. var alreadyVisible = (domItem == this.expandedItem);
  10628. // hide the currently visible submenu
  10629. var expandedItem = this.expandedItem;
  10630. if (expandedItem) {
  10631. //var ul = expandedItem.ul;
  10632. expandedItem.ul.style.height = '0';
  10633. expandedItem.ul.style.padding = '';
  10634. setTimeout(function () {
  10635. if (me.expandedItem != expandedItem) {
  10636. expandedItem.ul.style.display = '';
  10637. util.removeClassName(expandedItem.ul.parentNode, 'jsoneditor-selected');
  10638. }
  10639. }, 300); // timeout duration must match the css transition duration
  10640. this.expandedItem = undefined;
  10641. }
  10642. if (!alreadyVisible) {
  10643. var ul = domItem.ul;
  10644. ul.style.display = 'block';
  10645. var height = ul.clientHeight; // force a reflow in Firefox
  10646. setTimeout(function () {
  10647. if (me.expandedItem == domItem) {
  10648. ul.style.height = (ul.childNodes.length * 24) + 'px';
  10649. ul.style.padding = '5px 10px';
  10650. }
  10651. }, 0);
  10652. util.addClassName(ul.parentNode, 'jsoneditor-selected');
  10653. this.expandedItem = domItem;
  10654. }
  10655. };
  10656. /**
  10657. * Handle onkeydown event
  10658. * @param {Event} event
  10659. * @private
  10660. */
  10661. ContextMenu.prototype._onKeyDown = function (event) {
  10662. var target = event.target;
  10663. var keynum = event.which;
  10664. var handled = false;
  10665. var buttons, targetIndex, prevButton, nextButton;
  10666. if (keynum == 27) { // ESC
  10667. // hide the menu on ESC key
  10668. // restore previous selection and focus
  10669. if (this.selection) {
  10670. util.setSelection(this.selection);
  10671. }
  10672. if (this.anchor) {
  10673. this.anchor.focus();
  10674. }
  10675. this.hide();
  10676. handled = true;
  10677. }
  10678. else if (keynum == 9) { // Tab
  10679. if (!event.shiftKey) { // Tab
  10680. buttons = this._getVisibleButtons();
  10681. targetIndex = buttons.indexOf(target);
  10682. if (targetIndex == buttons.length - 1) {
  10683. // move to first button
  10684. buttons[0].focus();
  10685. handled = true;
  10686. }
  10687. }
  10688. else { // Shift+Tab
  10689. buttons = this._getVisibleButtons();
  10690. targetIndex = buttons.indexOf(target);
  10691. if (targetIndex == 0) {
  10692. // move to last button
  10693. buttons[buttons.length - 1].focus();
  10694. handled = true;
  10695. }
  10696. }
  10697. }
  10698. else if (keynum == 37) { // Arrow Left
  10699. if (target.className == 'jsoneditor-expand') {
  10700. buttons = this._getVisibleButtons();
  10701. targetIndex = buttons.indexOf(target);
  10702. prevButton = buttons[targetIndex - 1];
  10703. if (prevButton) {
  10704. prevButton.focus();
  10705. }
  10706. }
  10707. handled = true;
  10708. }
  10709. else if (keynum == 38) { // Arrow Up
  10710. buttons = this._getVisibleButtons();
  10711. targetIndex = buttons.indexOf(target);
  10712. prevButton = buttons[targetIndex - 1];
  10713. if (prevButton && prevButton.className == 'jsoneditor-expand') {
  10714. // skip expand button
  10715. prevButton = buttons[targetIndex - 2];
  10716. }
  10717. if (!prevButton) {
  10718. // move to last button
  10719. prevButton = buttons[buttons.length - 1];
  10720. }
  10721. if (prevButton) {
  10722. prevButton.focus();
  10723. }
  10724. handled = true;
  10725. }
  10726. else if (keynum == 39) { // Arrow Right
  10727. buttons = this._getVisibleButtons();
  10728. targetIndex = buttons.indexOf(target);
  10729. nextButton = buttons[targetIndex + 1];
  10730. if (nextButton && nextButton.className == 'jsoneditor-expand') {
  10731. nextButton.focus();
  10732. }
  10733. handled = true;
  10734. }
  10735. else if (keynum == 40) { // Arrow Down
  10736. buttons = this._getVisibleButtons();
  10737. targetIndex = buttons.indexOf(target);
  10738. nextButton = buttons[targetIndex + 1];
  10739. if (nextButton && nextButton.className == 'jsoneditor-expand') {
  10740. // skip expand button
  10741. nextButton = buttons[targetIndex + 2];
  10742. }
  10743. if (!nextButton) {
  10744. // move to first button
  10745. nextButton = buttons[0];
  10746. }
  10747. if (nextButton) {
  10748. nextButton.focus();
  10749. handled = true;
  10750. }
  10751. handled = true;
  10752. }
  10753. // TODO: arrow left and right
  10754. if (handled) {
  10755. event.stopPropagation();
  10756. event.preventDefault();
  10757. }
  10758. };
  10759. /**
  10760. * Test if an element is a child of a parent element.
  10761. * @param {Element} child
  10762. * @param {Element} parent
  10763. * @return {boolean} isChild
  10764. */
  10765. ContextMenu.prototype._isChildOf = function (child, parent) {
  10766. var e = child.parentNode;
  10767. while (e) {
  10768. if (e == parent) {
  10769. return true;
  10770. }
  10771. e = e.parentNode;
  10772. }
  10773. return false;
  10774. };
  10775. module.exports = ContextMenu;
  10776. /***/ },
  10777. /* 58 */
  10778. /***/ function(module, exports, __webpack_require__) {
  10779. 'use strict';
  10780. var naturalSort = __webpack_require__(59);
  10781. var ContextMenu = __webpack_require__(57);
  10782. var appendNodeFactory = __webpack_require__(60);
  10783. var util = __webpack_require__(54);
  10784. /**
  10785. * @constructor Node
  10786. * Create a new Node
  10787. * @param {./treemode} editor
  10788. * @param {Object} [params] Can contain parameters:
  10789. * {string} field
  10790. * {boolean} fieldEditable
  10791. * {*} value
  10792. * {String} type Can have values 'auto', 'array',
  10793. * 'object', or 'string'.
  10794. */
  10795. function Node (editor, params) {
  10796. /** @type {./treemode} */
  10797. this.editor = editor;
  10798. this.dom = {};
  10799. this.expanded = false;
  10800. if(params && (params instanceof Object)) {
  10801. this.setField(params.field, params.fieldEditable);
  10802. this.setValue(params.value, params.type);
  10803. }
  10804. else {
  10805. this.setField('');
  10806. this.setValue(null);
  10807. }
  10808. this._debouncedOnChangeValue = util.debounce(this._onChangeValue.bind(this), Node.prototype.DEBOUNCE_INTERVAL);
  10809. this._debouncedOnChangeField = util.debounce(this._onChangeField.bind(this), Node.prototype.DEBOUNCE_INTERVAL);
  10810. }
  10811. // debounce interval for keyboard input in milliseconds
  10812. Node.prototype.DEBOUNCE_INTERVAL = 150;
  10813. /**
  10814. * Determine whether the field and/or value of this node are editable
  10815. * @private
  10816. */
  10817. Node.prototype._updateEditability = function () {
  10818. this.editable = {
  10819. field: true,
  10820. value: true
  10821. };
  10822. if (this.editor) {
  10823. this.editable.field = this.editor.options.mode === 'tree';
  10824. this.editable.value = this.editor.options.mode !== 'view';
  10825. if ((this.editor.options.mode === 'tree' || this.editor.options.mode === 'form') &&
  10826. (typeof this.editor.options.onEditable === 'function')) {
  10827. var editable = this.editor.options.onEditable({
  10828. field: this.field,
  10829. value: this.value,
  10830. path: this.getPath()
  10831. });
  10832. if (typeof editable === 'boolean') {
  10833. this.editable.field = editable;
  10834. this.editable.value = editable;
  10835. }
  10836. else {
  10837. if (typeof editable.field === 'boolean') this.editable.field = editable.field;
  10838. if (typeof editable.value === 'boolean') this.editable.value = editable.value;
  10839. }
  10840. }
  10841. }
  10842. };
  10843. /**
  10844. * Get the path of this node
  10845. * @return {String[]} Array containing the path to this node
  10846. */
  10847. Node.prototype.getPath = function () {
  10848. var node = this;
  10849. var path = [];
  10850. while (node) {
  10851. var field = !node.parent
  10852. ? undefined // do not add an (optional) field name of the root node
  10853. : (node.parent.type != 'array')
  10854. ? node.field
  10855. : node.index;
  10856. if (field !== undefined) {
  10857. path.unshift(field);
  10858. }
  10859. node = node.parent;
  10860. }
  10861. return path;
  10862. };
  10863. /**
  10864. * Find a Node from a JSON path like '.items[3].name'
  10865. * @param {string} jsonPath
  10866. * @return {Node | null} Returns the Node when found, returns null if not found
  10867. */
  10868. Node.prototype.findNode = function (jsonPath) {
  10869. var path = util.parsePath(jsonPath);
  10870. var node = this;
  10871. while (node && path.length > 0) {
  10872. var prop = path.shift();
  10873. if (typeof prop === 'number') {
  10874. if (node.type !== 'array') {
  10875. throw new Error('Cannot get child node at index ' + prop + ': node is no array');
  10876. }
  10877. node = node.childs[prop];
  10878. }
  10879. else { // string
  10880. if (node.type !== 'object') {
  10881. throw new Error('Cannot get child node ' + prop + ': node is no object');
  10882. }
  10883. node = node.childs.filter(function (child) {
  10884. return child.field === prop;
  10885. })[0];
  10886. }
  10887. }
  10888. return node;
  10889. };
  10890. /**
  10891. * Find all parents of this node. The parents are ordered from root node towards
  10892. * the original node.
  10893. * @return {Array.<Node>}
  10894. */
  10895. Node.prototype.findParents = function () {
  10896. var parents = [];
  10897. var parent = this.parent;
  10898. while (parent) {
  10899. parents.unshift(parent);
  10900. parent = parent.parent;
  10901. }
  10902. return parents;
  10903. };
  10904. /**
  10905. *
  10906. * @param {{dataPath: string, keyword: string, message: string, params: Object, schemaPath: string} | null} error
  10907. * @param {Node} [child] When this is the error of a parent node, pointing
  10908. * to an invalid child node, the child node itself
  10909. * can be provided. If provided, clicking the error
  10910. * icon will set focus to the invalid child node.
  10911. */
  10912. Node.prototype.setError = function (error, child) {
  10913. // ensure the dom exists
  10914. this.getDom();
  10915. this.error = error;
  10916. var tdError = this.dom.tdError;
  10917. if (error) {
  10918. if (!tdError) {
  10919. tdError = document.createElement('td');
  10920. this.dom.tdError = tdError;
  10921. this.dom.tdValue.parentNode.appendChild(tdError);
  10922. }
  10923. var popover = document.createElement('div');
  10924. popover.className = 'jsoneditor-popover jsoneditor-right';
  10925. popover.appendChild(document.createTextNode(error.message));
  10926. var button = document.createElement('button');
  10927. button.type = 'button';
  10928. button.className = 'jsoneditor-schema-error';
  10929. button.appendChild(popover);
  10930. // update the direction of the popover
  10931. button.onmouseover = button.onfocus = function updateDirection() {
  10932. var directions = ['right', 'above', 'below', 'left'];
  10933. for (var i = 0; i < directions.length; i++) {
  10934. var direction = directions[i];
  10935. popover.className = 'jsoneditor-popover jsoneditor-' + direction;
  10936. var contentRect = this.editor.content.getBoundingClientRect();
  10937. var popoverRect = popover.getBoundingClientRect();
  10938. var margin = 20; // account for a scroll bar
  10939. var fit = util.insideRect(contentRect, popoverRect, margin);
  10940. if (fit) {
  10941. break;
  10942. }
  10943. }
  10944. }.bind(this);
  10945. // when clicking the error icon, expand all nodes towards the invalid
  10946. // child node, and set focus to the child node
  10947. if (child) {
  10948. button.onclick = function showInvalidNode() {
  10949. child.findParents().forEach(function (parent) {
  10950. parent.expand(false);
  10951. });
  10952. child.scrollTo(function () {
  10953. child.focus();
  10954. });
  10955. };
  10956. }
  10957. // apply the error message to the node
  10958. while (tdError.firstChild) {
  10959. tdError.removeChild(tdError.firstChild);
  10960. }
  10961. tdError.appendChild(button);
  10962. }
  10963. else {
  10964. if (tdError) {
  10965. this.dom.tdError.parentNode.removeChild(this.dom.tdError);
  10966. delete this.dom.tdError;
  10967. }
  10968. }
  10969. };
  10970. /**
  10971. * Get the index of this node: the index in the list of childs where this
  10972. * node is part of
  10973. * @return {number} Returns the index, or -1 if this is the root node
  10974. */
  10975. Node.prototype.getIndex = function () {
  10976. return this.parent ? this.parent.childs.indexOf(this) : -1;
  10977. };
  10978. /**
  10979. * Set parent node
  10980. * @param {Node} parent
  10981. */
  10982. Node.prototype.setParent = function(parent) {
  10983. this.parent = parent;
  10984. };
  10985. /**
  10986. * Set field
  10987. * @param {String} field
  10988. * @param {boolean} [fieldEditable]
  10989. */
  10990. Node.prototype.setField = function(field, fieldEditable) {
  10991. this.field = field;
  10992. this.previousField = field;
  10993. this.fieldEditable = (fieldEditable === true);
  10994. };
  10995. /**
  10996. * Get field
  10997. * @return {String}
  10998. */
  10999. Node.prototype.getField = function() {
  11000. if (this.field === undefined) {
  11001. this._getDomField();
  11002. }
  11003. return this.field;
  11004. };
  11005. /**
  11006. * Set value. Value is a JSON structure or an element String, Boolean, etc.
  11007. * @param {*} value
  11008. * @param {String} [type] Specify the type of the value. Can be 'auto',
  11009. * 'array', 'object', or 'string'
  11010. */
  11011. Node.prototype.setValue = function(value, type) {
  11012. var childValue, child;
  11013. // first clear all current childs (if any)
  11014. var childs = this.childs;
  11015. if (childs) {
  11016. while (childs.length) {
  11017. this.removeChild(childs[0]);
  11018. }
  11019. }
  11020. // TODO: remove the DOM of this Node
  11021. this.type = this._getType(value);
  11022. // check if type corresponds with the provided type
  11023. if (type && type != this.type) {
  11024. if (type == 'string' && this.type == 'auto') {
  11025. this.type = type;
  11026. }
  11027. else {
  11028. throw new Error('Type mismatch: ' +
  11029. 'cannot cast value of type "' + this.type +
  11030. ' to the specified type "' + type + '"');
  11031. }
  11032. }
  11033. if (this.type == 'array') {
  11034. // array
  11035. this.childs = [];
  11036. for (var i = 0, iMax = value.length; i < iMax; i++) {
  11037. childValue = value[i];
  11038. if (childValue !== undefined && !(childValue instanceof Function)) {
  11039. // ignore undefined and functions
  11040. child = new Node(this.editor, {
  11041. value: childValue
  11042. });
  11043. this.appendChild(child);
  11044. }
  11045. }
  11046. this.value = '';
  11047. }
  11048. else if (this.type == 'object') {
  11049. // object
  11050. this.childs = [];
  11051. for (var childField in value) {
  11052. if (value.hasOwnProperty(childField)) {
  11053. childValue = value[childField];
  11054. if (childValue !== undefined && !(childValue instanceof Function)) {
  11055. // ignore undefined and functions
  11056. child = new Node(this.editor, {
  11057. field: childField,
  11058. value: childValue
  11059. });
  11060. this.appendChild(child);
  11061. }
  11062. }
  11063. }
  11064. this.value = '';
  11065. // sort object keys
  11066. if (this.editor.options.sortObjectKeys === true) {
  11067. this.sort('asc');
  11068. }
  11069. }
  11070. else {
  11071. // value
  11072. this.childs = undefined;
  11073. this.value = value;
  11074. }
  11075. this.previousValue = this.value;
  11076. };
  11077. /**
  11078. * Get value. Value is a JSON structure
  11079. * @return {*} value
  11080. */
  11081. Node.prototype.getValue = function() {
  11082. //var childs, i, iMax;
  11083. if (this.type == 'array') {
  11084. var arr = [];
  11085. this.childs.forEach (function (child) {
  11086. arr.push(child.getValue());
  11087. });
  11088. return arr;
  11089. }
  11090. else if (this.type == 'object') {
  11091. var obj = {};
  11092. this.childs.forEach (function (child) {
  11093. obj[child.getField()] = child.getValue();
  11094. });
  11095. return obj;
  11096. }
  11097. else {
  11098. if (this.value === undefined) {
  11099. this._getDomValue();
  11100. }
  11101. return this.value;
  11102. }
  11103. };
  11104. /**
  11105. * Get the nesting level of this node
  11106. * @return {Number} level
  11107. */
  11108. Node.prototype.getLevel = function() {
  11109. return (this.parent ? this.parent.getLevel() + 1 : 0);
  11110. };
  11111. /**
  11112. * Get path of the root node till the current node
  11113. * @return {Node[]} Returns an array with nodes
  11114. */
  11115. Node.prototype.getNodePath = function() {
  11116. var path = this.parent ? this.parent.getNodePath() : [];
  11117. path.push(this);
  11118. return path;
  11119. };
  11120. /**
  11121. * Create a clone of a node
  11122. * The complete state of a clone is copied, including whether it is expanded or
  11123. * not. The DOM elements are not cloned.
  11124. * @return {Node} clone
  11125. */
  11126. Node.prototype.clone = function() {
  11127. var clone = new Node(this.editor);
  11128. clone.type = this.type;
  11129. clone.field = this.field;
  11130. clone.fieldInnerText = this.fieldInnerText;
  11131. clone.fieldEditable = this.fieldEditable;
  11132. clone.value = this.value;
  11133. clone.valueInnerText = this.valueInnerText;
  11134. clone.expanded = this.expanded;
  11135. if (this.childs) {
  11136. // an object or array
  11137. var cloneChilds = [];
  11138. this.childs.forEach(function (child) {
  11139. var childClone = child.clone();
  11140. childClone.setParent(clone);
  11141. cloneChilds.push(childClone);
  11142. });
  11143. clone.childs = cloneChilds;
  11144. }
  11145. else {
  11146. // a value
  11147. clone.childs = undefined;
  11148. }
  11149. return clone;
  11150. };
  11151. /**
  11152. * Expand this node and optionally its childs.
  11153. * @param {boolean} [recurse] Optional recursion, true by default. When
  11154. * true, all childs will be expanded recursively
  11155. */
  11156. Node.prototype.expand = function(recurse) {
  11157. if (!this.childs) {
  11158. return;
  11159. }
  11160. // set this node expanded
  11161. this.expanded = true;
  11162. if (this.dom.expand) {
  11163. this.dom.expand.className = 'jsoneditor-expanded';
  11164. }
  11165. this.showChilds();
  11166. if (recurse !== false) {
  11167. this.childs.forEach(function (child) {
  11168. child.expand(recurse);
  11169. });
  11170. }
  11171. };
  11172. /**
  11173. * Collapse this node and optionally its childs.
  11174. * @param {boolean} [recurse] Optional recursion, true by default. When
  11175. * true, all childs will be collapsed recursively
  11176. */
  11177. Node.prototype.collapse = function(recurse) {
  11178. if (!this.childs) {
  11179. return;
  11180. }
  11181. this.hideChilds();
  11182. // collapse childs in case of recurse
  11183. if (recurse !== false) {
  11184. this.childs.forEach(function (child) {
  11185. child.collapse(recurse);
  11186. });
  11187. }
  11188. // make this node collapsed
  11189. if (this.dom.expand) {
  11190. this.dom.expand.className = 'jsoneditor-collapsed';
  11191. }
  11192. this.expanded = false;
  11193. };
  11194. /**
  11195. * Recursively show all childs when they are expanded
  11196. */
  11197. Node.prototype.showChilds = function() {
  11198. var childs = this.childs;
  11199. if (!childs) {
  11200. return;
  11201. }
  11202. if (!this.expanded) {
  11203. return;
  11204. }
  11205. var tr = this.dom.tr;
  11206. var table = tr ? tr.parentNode : undefined;
  11207. if (table) {
  11208. // show row with append button
  11209. var append = this.getAppend();
  11210. var nextTr = tr.nextSibling;
  11211. if (nextTr) {
  11212. table.insertBefore(append, nextTr);
  11213. }
  11214. else {
  11215. table.appendChild(append);
  11216. }
  11217. // show childs
  11218. this.childs.forEach(function (child) {
  11219. table.insertBefore(child.getDom(), append);
  11220. child.showChilds();
  11221. });
  11222. }
  11223. };
  11224. /**
  11225. * Hide the node with all its childs
  11226. */
  11227. Node.prototype.hide = function() {
  11228. var tr = this.dom.tr;
  11229. var table = tr ? tr.parentNode : undefined;
  11230. if (table) {
  11231. table.removeChild(tr);
  11232. }
  11233. this.hideChilds();
  11234. };
  11235. /**
  11236. * Recursively hide all childs
  11237. */
  11238. Node.prototype.hideChilds = function() {
  11239. var childs = this.childs;
  11240. if (!childs) {
  11241. return;
  11242. }
  11243. if (!this.expanded) {
  11244. return;
  11245. }
  11246. // hide append row
  11247. var append = this.getAppend();
  11248. if (append.parentNode) {
  11249. append.parentNode.removeChild(append);
  11250. }
  11251. // hide childs
  11252. this.childs.forEach(function (child) {
  11253. child.hide();
  11254. });
  11255. };
  11256. /**
  11257. * Add a new child to the node.
  11258. * Only applicable when Node value is of type array or object
  11259. * @param {Node} node
  11260. */
  11261. Node.prototype.appendChild = function(node) {
  11262. if (this._hasChilds()) {
  11263. // adjust the link to the parent
  11264. node.setParent(this);
  11265. node.fieldEditable = (this.type == 'object');
  11266. if (this.type == 'array') {
  11267. node.index = this.childs.length;
  11268. }
  11269. this.childs.push(node);
  11270. if (this.expanded) {
  11271. // insert into the DOM, before the appendRow
  11272. var newTr = node.getDom();
  11273. var appendTr = this.getAppend();
  11274. var table = appendTr ? appendTr.parentNode : undefined;
  11275. if (appendTr && table) {
  11276. table.insertBefore(newTr, appendTr);
  11277. }
  11278. node.showChilds();
  11279. }
  11280. this.updateDom({'updateIndexes': true});
  11281. node.updateDom({'recurse': true});
  11282. }
  11283. };
  11284. /**
  11285. * Move a node from its current parent to this node
  11286. * Only applicable when Node value is of type array or object
  11287. * @param {Node} node
  11288. * @param {Node} beforeNode
  11289. */
  11290. Node.prototype.moveBefore = function(node, beforeNode) {
  11291. if (this._hasChilds()) {
  11292. // create a temporary row, to prevent the scroll position from jumping
  11293. // when removing the node
  11294. var tbody = (this.dom.tr) ? this.dom.tr.parentNode : undefined;
  11295. if (tbody) {
  11296. var trTemp = document.createElement('tr');
  11297. trTemp.style.height = tbody.clientHeight + 'px';
  11298. tbody.appendChild(trTemp);
  11299. }
  11300. if (node.parent) {
  11301. node.parent.removeChild(node);
  11302. }
  11303. if (beforeNode instanceof AppendNode) {
  11304. this.appendChild(node);
  11305. }
  11306. else {
  11307. this.insertBefore(node, beforeNode);
  11308. }
  11309. if (tbody) {
  11310. tbody.removeChild(trTemp);
  11311. }
  11312. }
  11313. };
  11314. /**
  11315. * Move a node from its current parent to this node
  11316. * Only applicable when Node value is of type array or object.
  11317. * If index is out of range, the node will be appended to the end
  11318. * @param {Node} node
  11319. * @param {Number} index
  11320. */
  11321. Node.prototype.moveTo = function (node, index) {
  11322. if (node.parent == this) {
  11323. // same parent
  11324. var currentIndex = this.childs.indexOf(node);
  11325. if (currentIndex < index) {
  11326. // compensate the index for removal of the node itself
  11327. index++;
  11328. }
  11329. }
  11330. var beforeNode = this.childs[index] || this.append;
  11331. this.moveBefore(node, beforeNode);
  11332. };
  11333. /**
  11334. * Insert a new child before a given node
  11335. * Only applicable when Node value is of type array or object
  11336. * @param {Node} node
  11337. * @param {Node} beforeNode
  11338. */
  11339. Node.prototype.insertBefore = function(node, beforeNode) {
  11340. if (this._hasChilds()) {
  11341. if (beforeNode == this.append) {
  11342. // append to the child nodes
  11343. // adjust the link to the parent
  11344. node.setParent(this);
  11345. node.fieldEditable = (this.type == 'object');
  11346. this.childs.push(node);
  11347. }
  11348. else {
  11349. // insert before a child node
  11350. var index = this.childs.indexOf(beforeNode);
  11351. if (index == -1) {
  11352. throw new Error('Node not found');
  11353. }
  11354. // adjust the link to the parent
  11355. node.setParent(this);
  11356. node.fieldEditable = (this.type == 'object');
  11357. this.childs.splice(index, 0, node);
  11358. }
  11359. if (this.expanded) {
  11360. // insert into the DOM
  11361. var newTr = node.getDom();
  11362. var nextTr = beforeNode.getDom();
  11363. var table = nextTr ? nextTr.parentNode : undefined;
  11364. if (nextTr && table) {
  11365. table.insertBefore(newTr, nextTr);
  11366. }
  11367. node.showChilds();
  11368. }
  11369. this.updateDom({'updateIndexes': true});
  11370. node.updateDom({'recurse': true});
  11371. }
  11372. };
  11373. /**
  11374. * Insert a new child before a given node
  11375. * Only applicable when Node value is of type array or object
  11376. * @param {Node} node
  11377. * @param {Node} afterNode
  11378. */
  11379. Node.prototype.insertAfter = function(node, afterNode) {
  11380. if (this._hasChilds()) {
  11381. var index = this.childs.indexOf(afterNode);
  11382. var beforeNode = this.childs[index + 1];
  11383. if (beforeNode) {
  11384. this.insertBefore(node, beforeNode);
  11385. }
  11386. else {
  11387. this.appendChild(node);
  11388. }
  11389. }
  11390. };
  11391. /**
  11392. * Search in this node
  11393. * The node will be expanded when the text is found one of its childs, else
  11394. * it will be collapsed. Searches are case insensitive.
  11395. * @param {String} text
  11396. * @return {Node[]} results Array with nodes containing the search text
  11397. */
  11398. Node.prototype.search = function(text) {
  11399. var results = [];
  11400. var index;
  11401. var search = text ? text.toLowerCase() : undefined;
  11402. // delete old search data
  11403. delete this.searchField;
  11404. delete this.searchValue;
  11405. // search in field
  11406. if (this.field != undefined) {
  11407. var field = String(this.field).toLowerCase();
  11408. index = field.indexOf(search);
  11409. if (index != -1) {
  11410. this.searchField = true;
  11411. results.push({
  11412. 'node': this,
  11413. 'elem': 'field'
  11414. });
  11415. }
  11416. // update dom
  11417. this._updateDomField();
  11418. }
  11419. // search in value
  11420. if (this._hasChilds()) {
  11421. // array, object
  11422. // search the nodes childs
  11423. if (this.childs) {
  11424. var childResults = [];
  11425. this.childs.forEach(function (child) {
  11426. childResults = childResults.concat(child.search(text));
  11427. });
  11428. results = results.concat(childResults);
  11429. }
  11430. // update dom
  11431. if (search != undefined) {
  11432. var recurse = false;
  11433. if (childResults.length == 0) {
  11434. this.collapse(recurse);
  11435. }
  11436. else {
  11437. this.expand(recurse);
  11438. }
  11439. }
  11440. }
  11441. else {
  11442. // string, auto
  11443. if (this.value != undefined ) {
  11444. var value = String(this.value).toLowerCase();
  11445. index = value.indexOf(search);
  11446. if (index != -1) {
  11447. this.searchValue = true;
  11448. results.push({
  11449. 'node': this,
  11450. 'elem': 'value'
  11451. });
  11452. }
  11453. }
  11454. // update dom
  11455. this._updateDomValue();
  11456. }
  11457. return results;
  11458. };
  11459. /**
  11460. * Move the scroll position such that this node is in the visible area.
  11461. * The node will not get the focus
  11462. * @param {function(boolean)} [callback]
  11463. */
  11464. Node.prototype.scrollTo = function(callback) {
  11465. if (!this.dom.tr || !this.dom.tr.parentNode) {
  11466. // if the node is not visible, expand its parents
  11467. var parent = this.parent;
  11468. var recurse = false;
  11469. while (parent) {
  11470. parent.expand(recurse);
  11471. parent = parent.parent;
  11472. }
  11473. }
  11474. if (this.dom.tr && this.dom.tr.parentNode) {
  11475. this.editor.scrollTo(this.dom.tr.offsetTop, callback);
  11476. }
  11477. };
  11478. // stores the element name currently having the focus
  11479. Node.focusElement = undefined;
  11480. /**
  11481. * Set focus to this node
  11482. * @param {String} [elementName] The field name of the element to get the
  11483. * focus available values: 'drag', 'menu',
  11484. * 'expand', 'field', 'value' (default)
  11485. */
  11486. Node.prototype.focus = function(elementName) {
  11487. Node.focusElement = elementName;
  11488. if (this.dom.tr && this.dom.tr.parentNode) {
  11489. var dom = this.dom;
  11490. switch (elementName) {
  11491. case 'drag':
  11492. if (dom.drag) {
  11493. dom.drag.focus();
  11494. }
  11495. else {
  11496. dom.menu.focus();
  11497. }
  11498. break;
  11499. case 'menu':
  11500. dom.menu.focus();
  11501. break;
  11502. case 'expand':
  11503. if (this._hasChilds()) {
  11504. dom.expand.focus();
  11505. }
  11506. else if (dom.field && this.fieldEditable) {
  11507. dom.field.focus();
  11508. util.selectContentEditable(dom.field);
  11509. }
  11510. else if (dom.value && !this._hasChilds()) {
  11511. dom.value.focus();
  11512. util.selectContentEditable(dom.value);
  11513. }
  11514. else {
  11515. dom.menu.focus();
  11516. }
  11517. break;
  11518. case 'field':
  11519. if (dom.field && this.fieldEditable) {
  11520. dom.field.focus();
  11521. util.selectContentEditable(dom.field);
  11522. }
  11523. else if (dom.value && !this._hasChilds()) {
  11524. dom.value.focus();
  11525. util.selectContentEditable(dom.value);
  11526. }
  11527. else if (this._hasChilds()) {
  11528. dom.expand.focus();
  11529. }
  11530. else {
  11531. dom.menu.focus();
  11532. }
  11533. break;
  11534. case 'value':
  11535. default:
  11536. if (dom.value && !this._hasChilds()) {
  11537. dom.value.focus();
  11538. util.selectContentEditable(dom.value);
  11539. }
  11540. else if (dom.field && this.fieldEditable) {
  11541. dom.field.focus();
  11542. util.selectContentEditable(dom.field);
  11543. }
  11544. else if (this._hasChilds()) {
  11545. dom.expand.focus();
  11546. }
  11547. else {
  11548. dom.menu.focus();
  11549. }
  11550. break;
  11551. }
  11552. }
  11553. };
  11554. /**
  11555. * Select all text in an editable div after a delay of 0 ms
  11556. * @param {Element} editableDiv
  11557. */
  11558. Node.select = function(editableDiv) {
  11559. setTimeout(function () {
  11560. util.selectContentEditable(editableDiv);
  11561. }, 0);
  11562. };
  11563. /**
  11564. * Update the values from the DOM field and value of this node
  11565. */
  11566. Node.prototype.blur = function() {
  11567. // retrieve the actual field and value from the DOM.
  11568. this._getDomValue(false);
  11569. this._getDomField(false);
  11570. };
  11571. /**
  11572. * Check if given node is a child. The method will check recursively to find
  11573. * this node.
  11574. * @param {Node} node
  11575. * @return {boolean} containsNode
  11576. */
  11577. Node.prototype.containsNode = function(node) {
  11578. if (this == node) {
  11579. return true;
  11580. }
  11581. var childs = this.childs;
  11582. if (childs) {
  11583. // TODO: use the js5 Array.some() here?
  11584. for (var i = 0, iMax = childs.length; i < iMax; i++) {
  11585. if (childs[i].containsNode(node)) {
  11586. return true;
  11587. }
  11588. }
  11589. }
  11590. return false;
  11591. };
  11592. /**
  11593. * Move given node into this node
  11594. * @param {Node} node the childNode to be moved
  11595. * @param {Node} beforeNode node will be inserted before given
  11596. * node. If no beforeNode is given,
  11597. * the node is appended at the end
  11598. * @private
  11599. */
  11600. Node.prototype._move = function(node, beforeNode) {
  11601. if (node == beforeNode) {
  11602. // nothing to do...
  11603. return;
  11604. }
  11605. // check if this node is not a child of the node to be moved here
  11606. if (node.containsNode(this)) {
  11607. throw new Error('Cannot move a field into a child of itself');
  11608. }
  11609. // remove the original node
  11610. if (node.parent) {
  11611. node.parent.removeChild(node);
  11612. }
  11613. // create a clone of the node
  11614. var clone = node.clone();
  11615. node.clearDom();
  11616. // insert or append the node
  11617. if (beforeNode) {
  11618. this.insertBefore(clone, beforeNode);
  11619. }
  11620. else {
  11621. this.appendChild(clone);
  11622. }
  11623. /* TODO: adjust the field name (to prevent equal field names)
  11624. if (this.type == 'object') {
  11625. }
  11626. */
  11627. };
  11628. /**
  11629. * Remove a child from the node.
  11630. * Only applicable when Node value is of type array or object
  11631. * @param {Node} node The child node to be removed;
  11632. * @return {Node | undefined} node The removed node on success,
  11633. * else undefined
  11634. */
  11635. Node.prototype.removeChild = function(node) {
  11636. if (this.childs) {
  11637. var index = this.childs.indexOf(node);
  11638. if (index != -1) {
  11639. node.hide();
  11640. // delete old search results
  11641. delete node.searchField;
  11642. delete node.searchValue;
  11643. var removedNode = this.childs.splice(index, 1)[0];
  11644. removedNode.parent = null;
  11645. this.updateDom({'updateIndexes': true});
  11646. return removedNode;
  11647. }
  11648. }
  11649. return undefined;
  11650. };
  11651. /**
  11652. * Remove a child node node from this node
  11653. * This method is equal to Node.removeChild, except that _remove fire an
  11654. * onChange event.
  11655. * @param {Node} node
  11656. * @private
  11657. */
  11658. Node.prototype._remove = function (node) {
  11659. this.removeChild(node);
  11660. };
  11661. /**
  11662. * Change the type of the value of this Node
  11663. * @param {String} newType
  11664. */
  11665. Node.prototype.changeType = function (newType) {
  11666. var oldType = this.type;
  11667. if (oldType == newType) {
  11668. // type is not changed
  11669. return;
  11670. }
  11671. if ((newType == 'string' || newType == 'auto') &&
  11672. (oldType == 'string' || oldType == 'auto')) {
  11673. // this is an easy change
  11674. this.type = newType;
  11675. }
  11676. else {
  11677. // change from array to object, or from string/auto to object/array
  11678. var table = this.dom.tr ? this.dom.tr.parentNode : undefined;
  11679. var lastTr;
  11680. if (this.expanded) {
  11681. lastTr = this.getAppend();
  11682. }
  11683. else {
  11684. lastTr = this.getDom();
  11685. }
  11686. var nextTr = (lastTr && lastTr.parentNode) ? lastTr.nextSibling : undefined;
  11687. // hide current field and all its childs
  11688. this.hide();
  11689. this.clearDom();
  11690. // adjust the field and the value
  11691. this.type = newType;
  11692. // adjust childs
  11693. if (newType == 'object') {
  11694. if (!this.childs) {
  11695. this.childs = [];
  11696. }
  11697. this.childs.forEach(function (child, index) {
  11698. child.clearDom();
  11699. delete child.index;
  11700. child.fieldEditable = true;
  11701. if (child.field == undefined) {
  11702. child.field = '';
  11703. }
  11704. });
  11705. if (oldType == 'string' || oldType == 'auto') {
  11706. this.expanded = true;
  11707. }
  11708. }
  11709. else if (newType == 'array') {
  11710. if (!this.childs) {
  11711. this.childs = [];
  11712. }
  11713. this.childs.forEach(function (child, index) {
  11714. child.clearDom();
  11715. child.fieldEditable = false;
  11716. child.index = index;
  11717. });
  11718. if (oldType == 'string' || oldType == 'auto') {
  11719. this.expanded = true;
  11720. }
  11721. }
  11722. else {
  11723. this.expanded = false;
  11724. }
  11725. // create new DOM
  11726. if (table) {
  11727. if (nextTr) {
  11728. table.insertBefore(this.getDom(), nextTr);
  11729. }
  11730. else {
  11731. table.appendChild(this.getDom());
  11732. }
  11733. }
  11734. this.showChilds();
  11735. }
  11736. if (newType == 'auto' || newType == 'string') {
  11737. // cast value to the correct type
  11738. if (newType == 'string') {
  11739. this.value = String(this.value);
  11740. }
  11741. else {
  11742. this.value = this._stringCast(String(this.value));
  11743. }
  11744. this.focus();
  11745. }
  11746. this.updateDom({'updateIndexes': true});
  11747. };
  11748. /**
  11749. * Retrieve value from DOM
  11750. * @param {boolean} [silent] If true (default), no errors will be thrown in
  11751. * case of invalid data
  11752. * @private
  11753. */
  11754. Node.prototype._getDomValue = function(silent) {
  11755. if (this.dom.value && this.type != 'array' && this.type != 'object') {
  11756. this.valueInnerText = util.getInnerText(this.dom.value);
  11757. }
  11758. if (this.valueInnerText != undefined) {
  11759. try {
  11760. // retrieve the value
  11761. var value;
  11762. if (this.type == 'string') {
  11763. value = this._unescapeHTML(this.valueInnerText);
  11764. }
  11765. else {
  11766. var str = this._unescapeHTML(this.valueInnerText);
  11767. value = this._stringCast(str);
  11768. }
  11769. if (value !== this.value) {
  11770. this.value = value;
  11771. this._debouncedOnChangeValue();
  11772. }
  11773. }
  11774. catch (err) {
  11775. this.value = undefined;
  11776. // TODO: sent an action with the new, invalid value?
  11777. if (silent !== true) {
  11778. throw err;
  11779. }
  11780. }
  11781. }
  11782. };
  11783. /**
  11784. * Handle a changed value
  11785. * @private
  11786. */
  11787. Node.prototype._onChangeValue = function () {
  11788. // get current selection, then override the range such that we can select
  11789. // the added/removed text on undo/redo
  11790. var oldSelection = this.editor.getSelection();
  11791. if (oldSelection.range) {
  11792. var undoDiff = util.textDiff(String(this.value), String(this.previousValue));
  11793. oldSelection.range.startOffset = undoDiff.start;
  11794. oldSelection.range.endOffset = undoDiff.end;
  11795. }
  11796. var newSelection = this.editor.getSelection();
  11797. if (newSelection.range) {
  11798. var redoDiff = util.textDiff(String(this.previousValue), String(this.value));
  11799. newSelection.range.startOffset = redoDiff.start;
  11800. newSelection.range.endOffset = redoDiff.end;
  11801. }
  11802. this.editor._onAction('editValue', {
  11803. node: this,
  11804. oldValue: this.previousValue,
  11805. newValue: this.value,
  11806. oldSelection: oldSelection,
  11807. newSelection: newSelection
  11808. });
  11809. this.previousValue = this.value;
  11810. };
  11811. /**
  11812. * Handle a changed field
  11813. * @private
  11814. */
  11815. Node.prototype._onChangeField = function () {
  11816. // get current selection, then override the range such that we can select
  11817. // the added/removed text on undo/redo
  11818. var oldSelection = this.editor.getSelection();
  11819. if (oldSelection.range) {
  11820. var undoDiff = util.textDiff(this.field, this.previousField);
  11821. oldSelection.range.startOffset = undoDiff.start;
  11822. oldSelection.range.endOffset = undoDiff.end;
  11823. }
  11824. var newSelection = this.editor.getSelection();
  11825. if (newSelection.range) {
  11826. var redoDiff = util.textDiff(this.previousField, this.field);
  11827. newSelection.range.startOffset = redoDiff.start;
  11828. newSelection.range.endOffset = redoDiff.end;
  11829. }
  11830. this.editor._onAction('editField', {
  11831. node: this,
  11832. oldValue: this.previousField,
  11833. newValue: this.field,
  11834. oldSelection: oldSelection,
  11835. newSelection: newSelection
  11836. });
  11837. this.previousField = this.field;
  11838. };
  11839. /**
  11840. * Update dom value:
  11841. * - the text color of the value, depending on the type of the value
  11842. * - the height of the field, depending on the width
  11843. * - background color in case it is empty
  11844. * @private
  11845. */
  11846. Node.prototype._updateDomValue = function () {
  11847. var domValue = this.dom.value;
  11848. if (domValue) {
  11849. var classNames = ['jsoneditor-value'];
  11850. // set text color depending on value type
  11851. var value = this.value;
  11852. var type = (this.type == 'auto') ? util.type(value) : this.type;
  11853. var isUrl = type == 'string' && util.isUrl(value);
  11854. classNames.push('jsoneditor-' + type);
  11855. if (isUrl) {
  11856. classNames.push('jsoneditor-url');
  11857. }
  11858. // visual styling when empty
  11859. var isEmpty = (String(this.value) == '' && this.type != 'array' && this.type != 'object');
  11860. if (isEmpty) {
  11861. classNames.push('jsoneditor-empty');
  11862. }
  11863. // highlight when there is a search result
  11864. if (this.searchValueActive) {
  11865. classNames.push('jsoneditor-highlight-active');
  11866. }
  11867. if (this.searchValue) {
  11868. classNames.push('jsoneditor-highlight');
  11869. }
  11870. domValue.className = classNames.join(' ');
  11871. // update title
  11872. if (type == 'array' || type == 'object') {
  11873. var count = this.childs ? this.childs.length : 0;
  11874. domValue.title = this.type + ' containing ' + count + ' items';
  11875. }
  11876. else if (isUrl && this.editable.value) {
  11877. domValue.title = 'Ctrl+Click or Ctrl+Enter to open url in new window';
  11878. }
  11879. else {
  11880. domValue.title = '';
  11881. }
  11882. // show checkbox when the value is a boolean
  11883. if (type === 'boolean' && this.editable.value) {
  11884. if (!this.dom.checkbox) {
  11885. this.dom.checkbox = document.createElement('input');
  11886. this.dom.checkbox.type = 'checkbox';
  11887. this.dom.tdCheckbox = document.createElement('td');
  11888. this.dom.tdCheckbox.className = 'jsoneditor-tree';
  11889. this.dom.tdCheckbox.appendChild(this.dom.checkbox);
  11890. this.dom.tdValue.parentNode.insertBefore(this.dom.tdCheckbox, this.dom.tdValue);
  11891. }
  11892. this.dom.checkbox.checked = this.value;
  11893. }
  11894. else {
  11895. // cleanup checkbox when displayed
  11896. if (this.dom.tdCheckbox) {
  11897. this.dom.tdCheckbox.parentNode.removeChild(this.dom.tdCheckbox);
  11898. delete this.dom.tdCheckbox;
  11899. delete this.dom.checkbox;
  11900. }
  11901. }
  11902. if (this.enum && this.editable.value) {
  11903. // create select box when this node has an enum object
  11904. if (!this.dom.select) {
  11905. this.dom.select = document.createElement('select');
  11906. this.id = this.field + "_" + new Date().getUTCMilliseconds();
  11907. this.dom.select.id = this.id;
  11908. this.dom.select.name = this.dom.select.id;
  11909. //Create the default empty option
  11910. this.dom.select.option = document.createElement('option');
  11911. this.dom.select.option.value = '';
  11912. this.dom.select.option.innerHTML = '--';
  11913. this.dom.select.appendChild(this.dom.select.option);
  11914. //Iterate all enum values and add them as options
  11915. for(var i = 0; i < this.enum.length; i++) {
  11916. this.dom.select.option = document.createElement('option');
  11917. this.dom.select.option.value = this.enum[i];
  11918. this.dom.select.option.innerHTML = this.enum[i];
  11919. if(this.dom.select.option.value == this.value){
  11920. this.dom.select.option.selected = true;
  11921. }
  11922. this.dom.select.appendChild(this.dom.select.option);
  11923. }
  11924. this.dom.tdSelect = document.createElement('td');
  11925. this.dom.tdSelect.className = 'jsoneditor-tree';
  11926. this.dom.tdSelect.appendChild(this.dom.select);
  11927. this.dom.tdValue.parentNode.insertBefore(this.dom.tdSelect, this.dom.tdValue);
  11928. }
  11929. // If the enum is inside a composite type display
  11930. // both the simple input and the dropdown field
  11931. if(this.schema && (
  11932. !this.schema.hasOwnProperty("oneOf") &&
  11933. !this.schema.hasOwnProperty("anyOf") &&
  11934. !this.schema.hasOwnProperty("allOf"))
  11935. ) {
  11936. this.valueFieldHTML = this.dom.tdValue.innerHTML;
  11937. this.dom.tdValue.style.visibility = 'hidden';
  11938. this.dom.tdValue.innerHTML = '';
  11939. } else {
  11940. delete this.valueFieldHTML;
  11941. }
  11942. }
  11943. else {
  11944. // cleanup select box when displayed
  11945. if (this.dom.tdSelect) {
  11946. this.dom.tdSelect.parentNode.removeChild(this.dom.tdSelect);
  11947. delete this.dom.tdSelect;
  11948. delete this.dom.select;
  11949. this.dom.tdValue.innerHTML = this.valueFieldHTML;
  11950. this.dom.tdValue.style.visibility = '';
  11951. delete this.valueFieldHTML;
  11952. }
  11953. }
  11954. // strip formatting from the contents of the editable div
  11955. util.stripFormatting(domValue);
  11956. }
  11957. };
  11958. /**
  11959. * Update dom field:
  11960. * - the text color of the field, depending on the text
  11961. * - the height of the field, depending on the width
  11962. * - background color in case it is empty
  11963. * @private
  11964. */
  11965. Node.prototype._updateDomField = function () {
  11966. var domField = this.dom.field;
  11967. if (domField) {
  11968. // make backgound color lightgray when empty
  11969. var isEmpty = (String(this.field) == '' && this.parent.type != 'array');
  11970. if (isEmpty) {
  11971. util.addClassName(domField, 'jsoneditor-empty');
  11972. }
  11973. else {
  11974. util.removeClassName(domField, 'jsoneditor-empty');
  11975. }
  11976. // highlight when there is a search result
  11977. if (this.searchFieldActive) {
  11978. util.addClassName(domField, 'jsoneditor-highlight-active');
  11979. }
  11980. else {
  11981. util.removeClassName(domField, 'jsoneditor-highlight-active');
  11982. }
  11983. if (this.searchField) {
  11984. util.addClassName(domField, 'jsoneditor-highlight');
  11985. }
  11986. else {
  11987. util.removeClassName(domField, 'jsoneditor-highlight');
  11988. }
  11989. // strip formatting from the contents of the editable div
  11990. util.stripFormatting(domField);
  11991. }
  11992. };
  11993. /**
  11994. * Retrieve field from DOM
  11995. * @param {boolean} [silent] If true (default), no errors will be thrown in
  11996. * case of invalid data
  11997. * @private
  11998. */
  11999. Node.prototype._getDomField = function(silent) {
  12000. if (this.dom.field && this.fieldEditable) {
  12001. this.fieldInnerText = util.getInnerText(this.dom.field);
  12002. }
  12003. if (this.fieldInnerText != undefined) {
  12004. try {
  12005. var field = this._unescapeHTML(this.fieldInnerText);
  12006. if (field !== this.field) {
  12007. this.field = field;
  12008. this._debouncedOnChangeField();
  12009. }
  12010. }
  12011. catch (err) {
  12012. this.field = undefined;
  12013. // TODO: sent an action here, with the new, invalid value?
  12014. if (silent !== true) {
  12015. throw err;
  12016. }
  12017. }
  12018. }
  12019. };
  12020. /**
  12021. * Validate this node and all it's childs
  12022. * @return {Array.<{node: Node, error: {message: string}}>} Returns a list with duplicates
  12023. */
  12024. Node.prototype.validate = function () {
  12025. var errors = [];
  12026. // find duplicate keys
  12027. if (this.type === 'object') {
  12028. var keys = {};
  12029. var duplicateKeys = [];
  12030. for (var i = 0; i < this.childs.length; i++) {
  12031. var child = this.childs[i];
  12032. if (keys.hasOwnProperty(child.field)) {
  12033. duplicateKeys.push(child.field);
  12034. }
  12035. keys[child.field] = true;
  12036. }
  12037. if (duplicateKeys.length > 0) {
  12038. errors = this.childs
  12039. .filter(function (node) {
  12040. return duplicateKeys.indexOf(node.field) !== -1;
  12041. })
  12042. .map(function (node) {
  12043. return {
  12044. node: node,
  12045. error: {
  12046. message: 'duplicate key "' + node.field + '"'
  12047. }
  12048. }
  12049. });
  12050. }
  12051. }
  12052. // recurse over the childs
  12053. if (this.childs) {
  12054. for (var i = 0; i < this.childs.length; i++) {
  12055. var e = this.childs[i].validate();
  12056. if (e.length > 0) {
  12057. errors = errors.concat(e);
  12058. }
  12059. }
  12060. }
  12061. return errors;
  12062. };
  12063. /**
  12064. * Clear the dom of the node
  12065. */
  12066. Node.prototype.clearDom = function() {
  12067. // TODO: hide the node first?
  12068. //this.hide();
  12069. // TODO: recursively clear dom?
  12070. this.dom = {};
  12071. };
  12072. /**
  12073. * Get the HTML DOM TR element of the node.
  12074. * The dom will be generated when not yet created
  12075. * @return {Element} tr HTML DOM TR Element
  12076. */
  12077. Node.prototype.getDom = function() {
  12078. var dom = this.dom;
  12079. if (dom.tr) {
  12080. return dom.tr;
  12081. }
  12082. this._updateEditability();
  12083. // create row
  12084. dom.tr = document.createElement('tr');
  12085. dom.tr.node = this;
  12086. if (this.editor.options.mode === 'tree') { // note: we take here the global setting
  12087. var tdDrag = document.createElement('td');
  12088. if (this.editable.field) {
  12089. // create draggable area
  12090. if (this.parent) {
  12091. var domDrag = document.createElement('button');
  12092. domDrag.type = 'button';
  12093. dom.drag = domDrag;
  12094. domDrag.className = 'jsoneditor-dragarea';
  12095. domDrag.title = 'Drag to move this field (Alt+Shift+Arrows)';
  12096. tdDrag.appendChild(domDrag);
  12097. }
  12098. }
  12099. dom.tr.appendChild(tdDrag);
  12100. // create context menu
  12101. var tdMenu = document.createElement('td');
  12102. var menu = document.createElement('button');
  12103. menu.type = 'button';
  12104. dom.menu = menu;
  12105. menu.className = 'jsoneditor-contextmenu';
  12106. menu.title = 'Click to open the actions menu (Ctrl+M)';
  12107. tdMenu.appendChild(dom.menu);
  12108. dom.tr.appendChild(tdMenu);
  12109. }
  12110. // create tree and field
  12111. var tdField = document.createElement('td');
  12112. dom.tr.appendChild(tdField);
  12113. dom.tree = this._createDomTree();
  12114. tdField.appendChild(dom.tree);
  12115. this.updateDom({'updateIndexes': true});
  12116. return dom.tr;
  12117. };
  12118. /**
  12119. * DragStart event, fired on mousedown on the dragarea at the left side of a Node
  12120. * @param {Node[] | Node} nodes
  12121. * @param {Event} event
  12122. */
  12123. Node.onDragStart = function (nodes, event) {
  12124. if (!Array.isArray(nodes)) {
  12125. return Node.onDragStart([nodes], event);
  12126. }
  12127. if (nodes.length === 0) {
  12128. return;
  12129. }
  12130. var firstNode = nodes[0];
  12131. var lastNode = nodes[nodes.length - 1];
  12132. var draggedNode = Node.getNodeFromTarget(event.target);
  12133. var beforeNode = lastNode._nextSibling();
  12134. var editor = firstNode.editor;
  12135. // in case of multiple selected nodes, offsetY prevents the selection from
  12136. // jumping when you start dragging one of the lower down nodes in the selection
  12137. var offsetY = util.getAbsoluteTop(draggedNode.dom.tr) - util.getAbsoluteTop(firstNode.dom.tr);
  12138. if (!editor.mousemove) {
  12139. editor.mousemove = util.addEventListener(window, 'mousemove', function (event) {
  12140. Node.onDrag(nodes, event);
  12141. });
  12142. }
  12143. if (!editor.mouseup) {
  12144. editor.mouseup = util.addEventListener(window, 'mouseup',function (event ) {
  12145. Node.onDragEnd(nodes, event);
  12146. });
  12147. }
  12148. editor.highlighter.lock();
  12149. editor.drag = {
  12150. oldCursor: document.body.style.cursor,
  12151. oldSelection: editor.getSelection(),
  12152. oldBeforeNode: beforeNode,
  12153. mouseX: event.pageX,
  12154. offsetY: offsetY,
  12155. level: firstNode.getLevel()
  12156. };
  12157. document.body.style.cursor = 'move';
  12158. event.preventDefault();
  12159. };
  12160. /**
  12161. * Drag event, fired when moving the mouse while dragging a Node
  12162. * @param {Node[] | Node} nodes
  12163. * @param {Event} event
  12164. */
  12165. Node.onDrag = function (nodes, event) {
  12166. if (!Array.isArray(nodes)) {
  12167. return Node.onDrag([nodes], event);
  12168. }
  12169. if (nodes.length === 0) {
  12170. return;
  12171. }
  12172. // TODO: this method has grown too large. Split it in a number of methods
  12173. var editor = nodes[0].editor;
  12174. var mouseY = event.pageY - editor.drag.offsetY;
  12175. var mouseX = event.pageX;
  12176. var trThis, trPrev, trNext, trFirst, trLast, trRoot;
  12177. var nodePrev, nodeNext;
  12178. var topThis, topPrev, topFirst, heightThis, bottomNext, heightNext;
  12179. var moved = false;
  12180. // TODO: add an ESC option, which resets to the original position
  12181. // move up/down
  12182. var firstNode = nodes[0];
  12183. trThis = firstNode.dom.tr;
  12184. topThis = util.getAbsoluteTop(trThis);
  12185. heightThis = trThis.offsetHeight;
  12186. if (mouseY < topThis) {
  12187. // move up
  12188. trPrev = trThis;
  12189. do {
  12190. trPrev = trPrev.previousSibling;
  12191. nodePrev = Node.getNodeFromTarget(trPrev);
  12192. topPrev = trPrev ? util.getAbsoluteTop(trPrev) : 0;
  12193. }
  12194. while (trPrev && mouseY < topPrev);
  12195. if (nodePrev && !nodePrev.parent) {
  12196. nodePrev = undefined;
  12197. }
  12198. if (!nodePrev) {
  12199. // move to the first node
  12200. trRoot = trThis.parentNode.firstChild;
  12201. trPrev = trRoot ? trRoot.nextSibling : undefined;
  12202. nodePrev = Node.getNodeFromTarget(trPrev);
  12203. if (nodePrev == firstNode) {
  12204. nodePrev = undefined;
  12205. }
  12206. }
  12207. if (nodePrev) {
  12208. // check if mouseY is really inside the found node
  12209. trPrev = nodePrev.dom.tr;
  12210. topPrev = trPrev ? util.getAbsoluteTop(trPrev) : 0;
  12211. if (mouseY > topPrev + heightThis) {
  12212. nodePrev = undefined;
  12213. }
  12214. }
  12215. if (nodePrev) {
  12216. nodes.forEach(function (node) {
  12217. nodePrev.parent.moveBefore(node, nodePrev);
  12218. });
  12219. moved = true;
  12220. }
  12221. }
  12222. else {
  12223. // move down
  12224. var lastNode = nodes[nodes.length - 1];
  12225. trLast = (lastNode.expanded && lastNode.append) ? lastNode.append.getDom() : lastNode.dom.tr;
  12226. trFirst = trLast ? trLast.nextSibling : undefined;
  12227. if (trFirst) {
  12228. topFirst = util.getAbsoluteTop(trFirst);
  12229. trNext = trFirst;
  12230. do {
  12231. nodeNext = Node.getNodeFromTarget(trNext);
  12232. if (trNext) {
  12233. bottomNext = trNext.nextSibling ?
  12234. util.getAbsoluteTop(trNext.nextSibling) : 0;
  12235. heightNext = trNext ? (bottomNext - topFirst) : 0;
  12236. if (nodeNext.parent.childs.length == nodes.length &&
  12237. nodeNext.parent.childs[nodes.length - 1] == lastNode) {
  12238. // We are about to remove the last child of this parent,
  12239. // which will make the parents appendNode visible.
  12240. topThis += 27;
  12241. // TODO: dangerous to suppose the height of the appendNode a constant of 27 px.
  12242. }
  12243. }
  12244. trNext = trNext.nextSibling;
  12245. }
  12246. while (trNext && mouseY > topThis + heightNext);
  12247. if (nodeNext && nodeNext.parent) {
  12248. // calculate the desired level
  12249. var diffX = (mouseX - editor.drag.mouseX);
  12250. var diffLevel = Math.round(diffX / 24 / 2);
  12251. var level = editor.drag.level + diffLevel; // desired level
  12252. var levelNext = nodeNext.getLevel(); // level to be
  12253. // find the best fitting level (move upwards over the append nodes)
  12254. trPrev = nodeNext.dom.tr.previousSibling;
  12255. while (levelNext < level && trPrev) {
  12256. nodePrev = Node.getNodeFromTarget(trPrev);
  12257. var isDraggedNode = nodes.some(function (node) {
  12258. return node === nodePrev || nodePrev._isChildOf(node);
  12259. });
  12260. if (isDraggedNode) {
  12261. // neglect the dragged nodes themselves and their childs
  12262. }
  12263. else if (nodePrev instanceof AppendNode) {
  12264. var childs = nodePrev.parent.childs;
  12265. if (childs.length != nodes.length || childs[nodes.length - 1] != lastNode) {
  12266. // non-visible append node of a list of childs
  12267. // consisting of not only this node (else the
  12268. // append node will change into a visible "empty"
  12269. // text when removing this node).
  12270. nodeNext = Node.getNodeFromTarget(trPrev);
  12271. levelNext = nodeNext.getLevel();
  12272. }
  12273. else {
  12274. break;
  12275. }
  12276. }
  12277. else {
  12278. break;
  12279. }
  12280. trPrev = trPrev.previousSibling;
  12281. }
  12282. // move the node when its position is changed
  12283. if (trLast.nextSibling != nodeNext.dom.tr) {
  12284. nodes.forEach(function (node) {
  12285. nodeNext.parent.moveBefore(node, nodeNext);
  12286. });
  12287. moved = true;
  12288. }
  12289. }
  12290. }
  12291. }
  12292. if (moved) {
  12293. // update the dragging parameters when moved
  12294. editor.drag.mouseX = mouseX;
  12295. editor.drag.level = firstNode.getLevel();
  12296. }
  12297. // auto scroll when hovering around the top of the editor
  12298. editor.startAutoScroll(mouseY);
  12299. event.preventDefault();
  12300. };
  12301. /**
  12302. * Drag event, fired on mouseup after having dragged a node
  12303. * @param {Node[] | Node} nodes
  12304. * @param {Event} event
  12305. */
  12306. Node.onDragEnd = function (nodes, event) {
  12307. if (!Array.isArray(nodes)) {
  12308. return Node.onDrag([nodes], event);
  12309. }
  12310. if (nodes.length === 0) {
  12311. return;
  12312. }
  12313. var firstNode = nodes[0];
  12314. var editor = firstNode.editor;
  12315. var parent = firstNode.parent;
  12316. var firstIndex = parent.childs.indexOf(firstNode);
  12317. var beforeNode = parent.childs[firstIndex + nodes.length] || parent.append;
  12318. // set focus to the context menu button of the first node
  12319. if (nodes[0]) {
  12320. nodes[0].dom.menu.focus();
  12321. }
  12322. var params = {
  12323. nodes: nodes,
  12324. oldSelection: editor.drag.oldSelection,
  12325. newSelection: editor.getSelection(),
  12326. oldBeforeNode: editor.drag.oldBeforeNode,
  12327. newBeforeNode: beforeNode
  12328. };
  12329. if (params.oldBeforeNode != params.newBeforeNode) {
  12330. // only register this action if the node is actually moved to another place
  12331. editor._onAction('moveNodes', params);
  12332. }
  12333. document.body.style.cursor = editor.drag.oldCursor;
  12334. editor.highlighter.unlock();
  12335. nodes.forEach(function (node) {
  12336. if (event.target !== node.dom.drag && event.target !== node.dom.menu) {
  12337. editor.highlighter.unhighlight();
  12338. }
  12339. });
  12340. delete editor.drag;
  12341. if (editor.mousemove) {
  12342. util.removeEventListener(window, 'mousemove', editor.mousemove);
  12343. delete editor.mousemove;
  12344. }
  12345. if (editor.mouseup) {
  12346. util.removeEventListener(window, 'mouseup', editor.mouseup);
  12347. delete editor.mouseup;
  12348. }
  12349. // Stop any running auto scroll
  12350. editor.stopAutoScroll();
  12351. event.preventDefault();
  12352. };
  12353. /**
  12354. * Test if this node is a child of an other node
  12355. * @param {Node} node
  12356. * @return {boolean} isChild
  12357. * @private
  12358. */
  12359. Node.prototype._isChildOf = function (node) {
  12360. var n = this.parent;
  12361. while (n) {
  12362. if (n == node) {
  12363. return true;
  12364. }
  12365. n = n.parent;
  12366. }
  12367. return false;
  12368. };
  12369. /**
  12370. * Create an editable field
  12371. * @return {Element} domField
  12372. * @private
  12373. */
  12374. Node.prototype._createDomField = function () {
  12375. return document.createElement('div');
  12376. };
  12377. /**
  12378. * Set highlighting for this node and all its childs.
  12379. * Only applied to the currently visible (expanded childs)
  12380. * @param {boolean} highlight
  12381. */
  12382. Node.prototype.setHighlight = function (highlight) {
  12383. if (this.dom.tr) {
  12384. if (highlight) {
  12385. util.addClassName(this.dom.tr, 'jsoneditor-highlight');
  12386. }
  12387. else {
  12388. util.removeClassName(this.dom.tr, 'jsoneditor-highlight');
  12389. }
  12390. if (this.append) {
  12391. this.append.setHighlight(highlight);
  12392. }
  12393. if (this.childs) {
  12394. this.childs.forEach(function (child) {
  12395. child.setHighlight(highlight);
  12396. });
  12397. }
  12398. }
  12399. };
  12400. /**
  12401. * Select or deselect a node
  12402. * @param {boolean} selected
  12403. * @param {boolean} [isFirst]
  12404. */
  12405. Node.prototype.setSelected = function (selected, isFirst) {
  12406. this.selected = selected;
  12407. if (this.dom.tr) {
  12408. if (selected) {
  12409. util.addClassName(this.dom.tr, 'jsoneditor-selected');
  12410. }
  12411. else {
  12412. util.removeClassName(this.dom.tr, 'jsoneditor-selected');
  12413. }
  12414. if (isFirst) {
  12415. util.addClassName(this.dom.tr, 'jsoneditor-first');
  12416. }
  12417. else {
  12418. util.removeClassName(this.dom.tr, 'jsoneditor-first');
  12419. }
  12420. if (this.append) {
  12421. this.append.setSelected(selected);
  12422. }
  12423. if (this.childs) {
  12424. this.childs.forEach(function (child) {
  12425. child.setSelected(selected);
  12426. });
  12427. }
  12428. }
  12429. };
  12430. /**
  12431. * Update the value of the node. Only primitive types are allowed, no Object
  12432. * or Array is allowed.
  12433. * @param {String | Number | Boolean | null} value
  12434. */
  12435. Node.prototype.updateValue = function (value) {
  12436. this.value = value;
  12437. this.updateDom();
  12438. };
  12439. /**
  12440. * Update the field of the node.
  12441. * @param {String} field
  12442. */
  12443. Node.prototype.updateField = function (field) {
  12444. this.field = field;
  12445. this.updateDom();
  12446. };
  12447. /**
  12448. * Update the HTML DOM, optionally recursing through the childs
  12449. * @param {Object} [options] Available parameters:
  12450. * {boolean} [recurse] If true, the
  12451. * DOM of the childs will be updated recursively.
  12452. * False by default.
  12453. * {boolean} [updateIndexes] If true, the childs
  12454. * indexes of the node will be updated too. False by
  12455. * default.
  12456. */
  12457. Node.prototype.updateDom = function (options) {
  12458. // update level indentation
  12459. var domTree = this.dom.tree;
  12460. if (domTree) {
  12461. domTree.style.marginLeft = this.getLevel() * 24 + 'px';
  12462. }
  12463. // apply field to DOM
  12464. var domField = this.dom.field;
  12465. if (domField) {
  12466. if (this.fieldEditable) {
  12467. // parent is an object
  12468. domField.contentEditable = this.editable.field;
  12469. domField.spellcheck = false;
  12470. domField.className = 'jsoneditor-field';
  12471. }
  12472. else {
  12473. // parent is an array this is the root node
  12474. domField.className = 'jsoneditor-readonly';
  12475. }
  12476. var fieldText;
  12477. if (this.index != undefined) {
  12478. fieldText = this.index;
  12479. }
  12480. else if (this.field != undefined) {
  12481. fieldText = this.field;
  12482. }
  12483. else if (this._hasChilds()) {
  12484. fieldText = this.type;
  12485. }
  12486. else {
  12487. fieldText = '';
  12488. }
  12489. domField.innerHTML = this._escapeHTML(fieldText);
  12490. this._updateSchema();
  12491. }
  12492. // apply value to DOM
  12493. var domValue = this.dom.value;
  12494. if (domValue) {
  12495. var count = this.childs ? this.childs.length : 0;
  12496. if (this.type == 'array') {
  12497. domValue.innerHTML = '[' + count + ']';
  12498. util.addClassName(this.dom.tr, 'jsoneditor-expandable');
  12499. }
  12500. else if (this.type == 'object') {
  12501. domValue.innerHTML = '{' + count + '}';
  12502. util.addClassName(this.dom.tr, 'jsoneditor-expandable');
  12503. }
  12504. else {
  12505. domValue.innerHTML = this._escapeHTML(this.value);
  12506. util.removeClassName(this.dom.tr, 'jsoneditor-expandable');
  12507. }
  12508. }
  12509. // update field and value
  12510. this._updateDomField();
  12511. this._updateDomValue();
  12512. // update childs indexes
  12513. if (options && options.updateIndexes === true) {
  12514. // updateIndexes is true or undefined
  12515. this._updateDomIndexes();
  12516. }
  12517. if (options && options.recurse === true) {
  12518. // recurse is true or undefined. update childs recursively
  12519. if (this.childs) {
  12520. this.childs.forEach(function (child) {
  12521. child.updateDom(options);
  12522. });
  12523. }
  12524. }
  12525. // update row with append button
  12526. if (this.append) {
  12527. this.append.updateDom();
  12528. }
  12529. };
  12530. /**
  12531. * Locate the JSON schema of the node and check for any enum type
  12532. * @private
  12533. */
  12534. Node.prototype._updateSchema = function () {
  12535. //Locating the schema of the node and checking for any enum type
  12536. if(this.editor && this.editor.options) {
  12537. // find the part of the json schema matching this nodes path
  12538. this.schema = Node._findSchema(this.editor.options.schema, this.getPath());
  12539. if (this.schema) {
  12540. this.enum = Node._findEnum(this.schema);
  12541. }
  12542. else {
  12543. delete this.enum;
  12544. }
  12545. }
  12546. };
  12547. /**
  12548. * find an enum definition in a JSON schema, as property `enum` or inside
  12549. * one of the schemas composites (`oneOf`, `anyOf`, `allOf`)
  12550. * @param {Object} schema
  12551. * @return {Array | null} Returns the enum when found, null otherwise.
  12552. * @private
  12553. */
  12554. Node._findEnum = function (schema) {
  12555. if (schema.enum) {
  12556. return schema.enum;
  12557. }
  12558. var composite = schema.oneOf || schema.anyOf || schema.allOf;
  12559. if (composite) {
  12560. var match = composite.filter(function (entry) {return entry.enum});
  12561. if (match.length > 0) {
  12562. return match[0].enum;
  12563. }
  12564. }
  12565. return null
  12566. };
  12567. /**
  12568. * Return the part of a JSON schema matching given path.
  12569. * @param {Object} schema
  12570. * @param {Array.<string | number>} path
  12571. * @return {Object | null}
  12572. * @private
  12573. */
  12574. Node._findSchema = function (schema, path) {
  12575. var childSchema = schema;
  12576. for (var i = 0; i < path.length && childSchema; i++) {
  12577. var key = path[i];
  12578. if (typeof key === 'string' && childSchema.properties) {
  12579. childSchema = childSchema.properties[key] || null
  12580. }
  12581. else if (typeof key === 'number' && childSchema.items) {
  12582. childSchema = childSchema.items
  12583. }
  12584. }
  12585. return childSchema
  12586. };
  12587. /**
  12588. * Update the DOM of the childs of a node: update indexes and undefined field
  12589. * names.
  12590. * Only applicable when structure is an array or object
  12591. * @private
  12592. */
  12593. Node.prototype._updateDomIndexes = function () {
  12594. var domValue = this.dom.value;
  12595. var childs = this.childs;
  12596. if (domValue && childs) {
  12597. if (this.type == 'array') {
  12598. childs.forEach(function (child, index) {
  12599. child.index = index;
  12600. var childField = child.dom.field;
  12601. if (childField) {
  12602. childField.innerHTML = index;
  12603. }
  12604. });
  12605. }
  12606. else if (this.type == 'object') {
  12607. childs.forEach(function (child) {
  12608. if (child.index != undefined) {
  12609. delete child.index;
  12610. if (child.field == undefined) {
  12611. child.field = '';
  12612. }
  12613. }
  12614. });
  12615. }
  12616. }
  12617. };
  12618. /**
  12619. * Create an editable value
  12620. * @private
  12621. */
  12622. Node.prototype._createDomValue = function () {
  12623. var domValue;
  12624. if (this.type == 'array') {
  12625. domValue = document.createElement('div');
  12626. domValue.innerHTML = '[...]';
  12627. }
  12628. else if (this.type == 'object') {
  12629. domValue = document.createElement('div');
  12630. domValue.innerHTML = '{...}';
  12631. }
  12632. else {
  12633. if (!this.editable.value && util.isUrl(this.value)) {
  12634. // create a link in case of read-only editor and value containing an url
  12635. domValue = document.createElement('a');
  12636. domValue.href = this.value;
  12637. domValue.target = '_blank';
  12638. domValue.innerHTML = this._escapeHTML(this.value);
  12639. }
  12640. else {
  12641. // create an editable or read-only div
  12642. domValue = document.createElement('div');
  12643. domValue.contentEditable = this.editable.value;
  12644. domValue.spellcheck = false;
  12645. domValue.innerHTML = this._escapeHTML(this.value);
  12646. }
  12647. }
  12648. return domValue;
  12649. };
  12650. /**
  12651. * Create an expand/collapse button
  12652. * @return {Element} expand
  12653. * @private
  12654. */
  12655. Node.prototype._createDomExpandButton = function () {
  12656. // create expand button
  12657. var expand = document.createElement('button');
  12658. expand.type = 'button';
  12659. if (this._hasChilds()) {
  12660. expand.className = this.expanded ? 'jsoneditor-expanded' : 'jsoneditor-collapsed';
  12661. expand.title =
  12662. 'Click to expand/collapse this field (Ctrl+E). \n' +
  12663. 'Ctrl+Click to expand/collapse including all childs.';
  12664. }
  12665. else {
  12666. expand.className = 'jsoneditor-invisible';
  12667. expand.title = '';
  12668. }
  12669. return expand;
  12670. };
  12671. /**
  12672. * Create a DOM tree element, containing the expand/collapse button
  12673. * @return {Element} domTree
  12674. * @private
  12675. */
  12676. Node.prototype._createDomTree = function () {
  12677. var dom = this.dom;
  12678. var domTree = document.createElement('table');
  12679. var tbody = document.createElement('tbody');
  12680. domTree.style.borderCollapse = 'collapse'; // TODO: put in css
  12681. domTree.className = 'jsoneditor-values';
  12682. domTree.appendChild(tbody);
  12683. var tr = document.createElement('tr');
  12684. tbody.appendChild(tr);
  12685. // create expand button
  12686. var tdExpand = document.createElement('td');
  12687. tdExpand.className = 'jsoneditor-tree';
  12688. tr.appendChild(tdExpand);
  12689. dom.expand = this._createDomExpandButton();
  12690. tdExpand.appendChild(dom.expand);
  12691. dom.tdExpand = tdExpand;
  12692. // create the field
  12693. var tdField = document.createElement('td');
  12694. tdField.className = 'jsoneditor-tree';
  12695. tr.appendChild(tdField);
  12696. dom.field = this._createDomField();
  12697. tdField.appendChild(dom.field);
  12698. dom.tdField = tdField;
  12699. // create a separator
  12700. var tdSeparator = document.createElement('td');
  12701. tdSeparator.className = 'jsoneditor-tree';
  12702. tr.appendChild(tdSeparator);
  12703. if (this.type != 'object' && this.type != 'array') {
  12704. tdSeparator.appendChild(document.createTextNode(':'));
  12705. tdSeparator.className = 'jsoneditor-separator';
  12706. }
  12707. dom.tdSeparator = tdSeparator;
  12708. // create the value
  12709. var tdValue = document.createElement('td');
  12710. tdValue.className = 'jsoneditor-tree';
  12711. tr.appendChild(tdValue);
  12712. dom.value = this._createDomValue();
  12713. tdValue.appendChild(dom.value);
  12714. dom.tdValue = tdValue;
  12715. return domTree;
  12716. };
  12717. /**
  12718. * Handle an event. The event is caught centrally by the editor
  12719. * @param {Event} event
  12720. */
  12721. Node.prototype.onEvent = function (event) {
  12722. var type = event.type,
  12723. target = event.target || event.srcElement,
  12724. dom = this.dom,
  12725. node = this,
  12726. expandable = this._hasChilds();
  12727. // check if mouse is on menu or on dragarea.
  12728. // If so, highlight current row and its childs
  12729. if (target == dom.drag || target == dom.menu) {
  12730. if (type == 'mouseover') {
  12731. this.editor.highlighter.highlight(this);
  12732. }
  12733. else if (type == 'mouseout') {
  12734. this.editor.highlighter.unhighlight();
  12735. }
  12736. }
  12737. // context menu events
  12738. if (type == 'click' && target == dom.menu) {
  12739. var highlighter = node.editor.highlighter;
  12740. highlighter.highlight(node);
  12741. highlighter.lock();
  12742. util.addClassName(dom.menu, 'jsoneditor-selected');
  12743. this.showContextMenu(dom.menu, function () {
  12744. util.removeClassName(dom.menu, 'jsoneditor-selected');
  12745. highlighter.unlock();
  12746. highlighter.unhighlight();
  12747. });
  12748. }
  12749. // expand events
  12750. if (type == 'click') {
  12751. if (target == dom.expand ||
  12752. ((node.editor.options.mode === 'view' || node.editor.options.mode === 'form') && target.nodeName === 'DIV')) {
  12753. if (expandable) {
  12754. var recurse = event.ctrlKey; // with ctrl-key, expand/collapse all
  12755. this._onExpand(recurse);
  12756. }
  12757. }
  12758. }
  12759. // swap the value of a boolean when the checkbox displayed left is clicked
  12760. if (type == 'change' && target == dom.checkbox) {
  12761. this.dom.value.innerHTML = !this.value;
  12762. this._getDomValue();
  12763. }
  12764. // update the value of the node based on the selected option
  12765. if (type == 'change' && target == dom.select) {
  12766. this.dom.value.innerHTML = dom.select.value;
  12767. this._getDomValue();
  12768. this._updateDomValue();
  12769. }
  12770. // value events
  12771. var domValue = dom.value;
  12772. if (target == domValue) {
  12773. //noinspection FallthroughInSwitchStatementJS
  12774. switch (type) {
  12775. case 'blur':
  12776. case 'change':
  12777. this._getDomValue(true);
  12778. this._updateDomValue();
  12779. if (this.value) {
  12780. domValue.innerHTML = this._escapeHTML(this.value);
  12781. }
  12782. break;
  12783. case 'input':
  12784. //this._debouncedGetDomValue(true); // TODO
  12785. this._getDomValue(true);
  12786. this._updateDomValue();
  12787. break;
  12788. case 'keydown':
  12789. case 'mousedown':
  12790. // TODO: cleanup
  12791. this.editor.selection = this.editor.getSelection();
  12792. break;
  12793. case 'click':
  12794. if (event.ctrlKey || !this.editable.value) {
  12795. if (util.isUrl(this.value)) {
  12796. window.open(this.value, '_blank');
  12797. }
  12798. }
  12799. break;
  12800. case 'keyup':
  12801. //this._debouncedGetDomValue(true); // TODO
  12802. this._getDomValue(true);
  12803. this._updateDomValue();
  12804. break;
  12805. case 'cut':
  12806. case 'paste':
  12807. setTimeout(function () {
  12808. node._getDomValue(true);
  12809. node._updateDomValue();
  12810. }, 1);
  12811. break;
  12812. }
  12813. }
  12814. // field events
  12815. var domField = dom.field;
  12816. if (target == domField) {
  12817. switch (type) {
  12818. case 'blur':
  12819. case 'change':
  12820. this._getDomField(true);
  12821. this._updateDomField();
  12822. if (this.field) {
  12823. domField.innerHTML = this._escapeHTML(this.field);
  12824. }
  12825. break;
  12826. case 'input':
  12827. this._getDomField(true);
  12828. this._updateSchema();
  12829. this._updateDomField();
  12830. this._updateDomValue();
  12831. break;
  12832. case 'keydown':
  12833. case 'mousedown':
  12834. this.editor.selection = this.editor.getSelection();
  12835. break;
  12836. case 'keyup':
  12837. this._getDomField(true);
  12838. this._updateDomField();
  12839. break;
  12840. case 'cut':
  12841. case 'paste':
  12842. setTimeout(function () {
  12843. node._getDomField(true);
  12844. node._updateDomField();
  12845. }, 1);
  12846. break;
  12847. }
  12848. }
  12849. // focus
  12850. // when clicked in whitespace left or right from the field or value, set focus
  12851. var domTree = dom.tree;
  12852. if (target == domTree.parentNode && type == 'click' && !event.hasMoved) {
  12853. var left = (event.offsetX != undefined) ?
  12854. (event.offsetX < (this.getLevel() + 1) * 24) :
  12855. (event.pageX < util.getAbsoluteLeft(dom.tdSeparator));// for FF
  12856. if (left || expandable) {
  12857. // node is expandable when it is an object or array
  12858. if (domField) {
  12859. util.setEndOfContentEditable(domField);
  12860. domField.focus();
  12861. }
  12862. }
  12863. else {
  12864. if (domValue && !this.enum) {
  12865. util.setEndOfContentEditable(domValue);
  12866. domValue.focus();
  12867. }
  12868. }
  12869. }
  12870. if (((target == dom.tdExpand && !expandable) || target == dom.tdField || target == dom.tdSeparator) &&
  12871. (type == 'click' && !event.hasMoved)) {
  12872. if (domField) {
  12873. util.setEndOfContentEditable(domField);
  12874. domField.focus();
  12875. }
  12876. }
  12877. if (type == 'keydown') {
  12878. this.onKeyDown(event);
  12879. }
  12880. };
  12881. /**
  12882. * Key down event handler
  12883. * @param {Event} event
  12884. */
  12885. Node.prototype.onKeyDown = function (event) {
  12886. var keynum = event.which || event.keyCode;
  12887. var target = event.target || event.srcElement;
  12888. var ctrlKey = event.ctrlKey;
  12889. var shiftKey = event.shiftKey;
  12890. var altKey = event.altKey;
  12891. var handled = false;
  12892. var prevNode, nextNode, nextDom, nextDom2;
  12893. var editable = this.editor.options.mode === 'tree';
  12894. var oldSelection;
  12895. var oldBeforeNode;
  12896. var nodes;
  12897. var multiselection;
  12898. var selectedNodes = this.editor.multiselection.nodes.length > 0
  12899. ? this.editor.multiselection.nodes
  12900. : [this];
  12901. var firstNode = selectedNodes[0];
  12902. var lastNode = selectedNodes[selectedNodes.length - 1];
  12903. // console.log(ctrlKey, keynum, event.charCode); // TODO: cleanup
  12904. if (keynum == 13) { // Enter
  12905. if (target == this.dom.value) {
  12906. if (!this.editable.value || event.ctrlKey) {
  12907. if (util.isUrl(this.value)) {
  12908. window.open(this.value, '_blank');
  12909. handled = true;
  12910. }
  12911. }
  12912. }
  12913. else if (target == this.dom.expand) {
  12914. var expandable = this._hasChilds();
  12915. if (expandable) {
  12916. var recurse = event.ctrlKey; // with ctrl-key, expand/collapse all
  12917. this._onExpand(recurse);
  12918. target.focus();
  12919. handled = true;
  12920. }
  12921. }
  12922. }
  12923. else if (keynum == 68) { // D
  12924. if (ctrlKey && editable) { // Ctrl+D
  12925. Node.onDuplicate(selectedNodes);
  12926. handled = true;
  12927. }
  12928. }
  12929. else if (keynum == 69) { // E
  12930. if (ctrlKey) { // Ctrl+E and Ctrl+Shift+E
  12931. this._onExpand(shiftKey); // recurse = shiftKey
  12932. target.focus(); // TODO: should restore focus in case of recursing expand (which takes DOM offline)
  12933. handled = true;
  12934. }
  12935. }
  12936. else if (keynum == 77 && editable) { // M
  12937. if (ctrlKey) { // Ctrl+M
  12938. this.showContextMenu(target);
  12939. handled = true;
  12940. }
  12941. }
  12942. else if (keynum == 46 && editable) { // Del
  12943. if (ctrlKey) { // Ctrl+Del
  12944. Node.onRemove(selectedNodes);
  12945. handled = true;
  12946. }
  12947. }
  12948. else if (keynum == 45 && editable) { // Ins
  12949. if (ctrlKey && !shiftKey) { // Ctrl+Ins
  12950. this._onInsertBefore();
  12951. handled = true;
  12952. }
  12953. else if (ctrlKey && shiftKey) { // Ctrl+Shift+Ins
  12954. this._onInsertAfter();
  12955. handled = true;
  12956. }
  12957. }
  12958. else if (keynum == 35) { // End
  12959. if (altKey) { // Alt+End
  12960. // find the last node
  12961. var endNode = this._lastNode();
  12962. if (endNode) {
  12963. endNode.focus(Node.focusElement || this._getElementName(target));
  12964. }
  12965. handled = true;
  12966. }
  12967. }
  12968. else if (keynum == 36) { // Home
  12969. if (altKey) { // Alt+Home
  12970. // find the first node
  12971. var homeNode = this._firstNode();
  12972. if (homeNode) {
  12973. homeNode.focus(Node.focusElement || this._getElementName(target));
  12974. }
  12975. handled = true;
  12976. }
  12977. }
  12978. else if (keynum == 37) { // Arrow Left
  12979. if (altKey && !shiftKey) { // Alt + Arrow Left
  12980. // move to left element
  12981. var prevElement = this._previousElement(target);
  12982. if (prevElement) {
  12983. this.focus(this._getElementName(prevElement));
  12984. }
  12985. handled = true;
  12986. }
  12987. else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow left
  12988. if (lastNode.expanded) {
  12989. var appendDom = lastNode.getAppend();
  12990. nextDom = appendDom ? appendDom.nextSibling : undefined;
  12991. }
  12992. else {
  12993. var dom = lastNode.getDom();
  12994. nextDom = dom.nextSibling;
  12995. }
  12996. if (nextDom) {
  12997. nextNode = Node.getNodeFromTarget(nextDom);
  12998. nextDom2 = nextDom.nextSibling;
  12999. nextNode2 = Node.getNodeFromTarget(nextDom2);
  13000. if (nextNode && nextNode instanceof AppendNode &&
  13001. !(lastNode.parent.childs.length == 1) &&
  13002. nextNode2 && nextNode2.parent) {
  13003. oldSelection = this.editor.getSelection();
  13004. oldBeforeNode = lastNode._nextSibling();
  13005. selectedNodes.forEach(function (node) {
  13006. nextNode2.parent.moveBefore(node, nextNode2);
  13007. });
  13008. this.focus(Node.focusElement || this._getElementName(target));
  13009. this.editor._onAction('moveNodes', {
  13010. nodes: selectedNodes,
  13011. oldBeforeNode: oldBeforeNode,
  13012. newBeforeNode: nextNode2,
  13013. oldSelection: oldSelection,
  13014. newSelection: this.editor.getSelection()
  13015. });
  13016. }
  13017. }
  13018. }
  13019. }
  13020. else if (keynum == 38) { // Arrow Up
  13021. if (altKey && !shiftKey) { // Alt + Arrow Up
  13022. // find the previous node
  13023. prevNode = this._previousNode();
  13024. if (prevNode) {
  13025. this.editor.deselect(true);
  13026. prevNode.focus(Node.focusElement || this._getElementName(target));
  13027. }
  13028. handled = true;
  13029. }
  13030. else if (!altKey && ctrlKey && shiftKey && editable) { // Ctrl + Shift + Arrow Up
  13031. // select multiple nodes
  13032. prevNode = this._previousNode();
  13033. if (prevNode) {
  13034. multiselection = this.editor.multiselection;
  13035. multiselection.start = multiselection.start || this;
  13036. multiselection.end = prevNode;
  13037. nodes = this.editor._findTopLevelNodes(multiselection.start, multiselection.end);
  13038. this.editor.select(nodes);
  13039. prevNode.focus('field'); // select field as we know this always exists
  13040. }
  13041. handled = true;
  13042. }
  13043. else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Up
  13044. // find the previous node
  13045. prevNode = firstNode._previousNode();
  13046. if (prevNode && prevNode.parent) {
  13047. oldSelection = this.editor.getSelection();
  13048. oldBeforeNode = lastNode._nextSibling();
  13049. selectedNodes.forEach(function (node) {
  13050. prevNode.parent.moveBefore(node, prevNode);
  13051. });
  13052. this.focus(Node.focusElement || this._getElementName(target));
  13053. this.editor._onAction('moveNodes', {
  13054. nodes: selectedNodes,
  13055. oldBeforeNode: oldBeforeNode,
  13056. newBeforeNode: prevNode,
  13057. oldSelection: oldSelection,
  13058. newSelection: this.editor.getSelection()
  13059. });
  13060. }
  13061. handled = true;
  13062. }
  13063. }
  13064. else if (keynum == 39) { // Arrow Right
  13065. if (altKey && !shiftKey) { // Alt + Arrow Right
  13066. // move to right element
  13067. var nextElement = this._nextElement(target);
  13068. if (nextElement) {
  13069. this.focus(this._getElementName(nextElement));
  13070. }
  13071. handled = true;
  13072. }
  13073. else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Right
  13074. dom = firstNode.getDom();
  13075. var prevDom = dom.previousSibling;
  13076. if (prevDom) {
  13077. prevNode = Node.getNodeFromTarget(prevDom);
  13078. if (prevNode && prevNode.parent &&
  13079. (prevNode instanceof AppendNode)
  13080. && !prevNode.isVisible()) {
  13081. oldSelection = this.editor.getSelection();
  13082. oldBeforeNode = lastNode._nextSibling();
  13083. selectedNodes.forEach(function (node) {
  13084. prevNode.parent.moveBefore(node, prevNode);
  13085. });
  13086. this.focus(Node.focusElement || this._getElementName(target));
  13087. this.editor._onAction('moveNodes', {
  13088. nodes: selectedNodes,
  13089. oldBeforeNode: oldBeforeNode,
  13090. newBeforeNode: prevNode,
  13091. oldSelection: oldSelection,
  13092. newSelection: this.editor.getSelection()
  13093. });
  13094. }
  13095. }
  13096. }
  13097. }
  13098. else if (keynum == 40) { // Arrow Down
  13099. if (altKey && !shiftKey) { // Alt + Arrow Down
  13100. // find the next node
  13101. nextNode = this._nextNode();
  13102. if (nextNode) {
  13103. this.editor.deselect(true);
  13104. nextNode.focus(Node.focusElement || this._getElementName(target));
  13105. }
  13106. handled = true;
  13107. }
  13108. else if (!altKey && ctrlKey && shiftKey && editable) { // Ctrl + Shift + Arrow Down
  13109. // select multiple nodes
  13110. nextNode = this._nextNode();
  13111. if (nextNode) {
  13112. multiselection = this.editor.multiselection;
  13113. multiselection.start = multiselection.start || this;
  13114. multiselection.end = nextNode;
  13115. nodes = this.editor._findTopLevelNodes(multiselection.start, multiselection.end);
  13116. this.editor.select(nodes);
  13117. nextNode.focus('field'); // select field as we know this always exists
  13118. }
  13119. handled = true;
  13120. }
  13121. else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Down
  13122. // find the 2nd next node and move before that one
  13123. if (lastNode.expanded) {
  13124. nextNode = lastNode.append ? lastNode.append._nextNode() : undefined;
  13125. }
  13126. else {
  13127. nextNode = lastNode._nextNode();
  13128. }
  13129. var nextNode2 = nextNode && (nextNode._nextNode() || nextNode.parent.append);
  13130. if (nextNode2 && nextNode2.parent) {
  13131. oldSelection = this.editor.getSelection();
  13132. oldBeforeNode = lastNode._nextSibling();
  13133. selectedNodes.forEach(function (node) {
  13134. nextNode2.parent.moveBefore(node, nextNode2);
  13135. });
  13136. this.focus(Node.focusElement || this._getElementName(target));
  13137. this.editor._onAction('moveNodes', {
  13138. nodes: selectedNodes,
  13139. oldBeforeNode: oldBeforeNode,
  13140. newBeforeNode: nextNode2,
  13141. oldSelection: oldSelection,
  13142. newSelection: this.editor.getSelection()
  13143. });
  13144. }
  13145. handled = true;
  13146. }
  13147. }
  13148. if (handled) {
  13149. event.preventDefault();
  13150. event.stopPropagation();
  13151. }
  13152. };
  13153. /**
  13154. * Handle the expand event, when clicked on the expand button
  13155. * @param {boolean} recurse If true, child nodes will be expanded too
  13156. * @private
  13157. */
  13158. Node.prototype._onExpand = function (recurse) {
  13159. if (recurse) {
  13160. // Take the table offline
  13161. var table = this.dom.tr.parentNode; // TODO: not nice to access the main table like this
  13162. var frame = table.parentNode;
  13163. var scrollTop = frame.scrollTop;
  13164. frame.removeChild(table);
  13165. }
  13166. if (this.expanded) {
  13167. this.collapse(recurse);
  13168. }
  13169. else {
  13170. this.expand(recurse);
  13171. }
  13172. if (recurse) {
  13173. // Put the table online again
  13174. frame.appendChild(table);
  13175. frame.scrollTop = scrollTop;
  13176. }
  13177. };
  13178. /**
  13179. * Remove nodes
  13180. * @param {Node[] | Node} nodes
  13181. */
  13182. Node.onRemove = function(nodes) {
  13183. if (!Array.isArray(nodes)) {
  13184. return Node.onRemove([nodes]);
  13185. }
  13186. if (nodes && nodes.length > 0) {
  13187. var firstNode = nodes[0];
  13188. var parent = firstNode.parent;
  13189. var editor = firstNode.editor;
  13190. var firstIndex = firstNode.getIndex();
  13191. editor.highlighter.unhighlight();
  13192. // adjust the focus
  13193. var oldSelection = editor.getSelection();
  13194. Node.blurNodes(nodes);
  13195. var newSelection = editor.getSelection();
  13196. // remove the nodes
  13197. nodes.forEach(function (node) {
  13198. node.parent._remove(node);
  13199. });
  13200. // store history action
  13201. editor._onAction('removeNodes', {
  13202. nodes: nodes.slice(0), // store a copy of the array!
  13203. parent: parent,
  13204. index: firstIndex,
  13205. oldSelection: oldSelection,
  13206. newSelection: newSelection
  13207. });
  13208. }
  13209. };
  13210. /**
  13211. * Duplicate nodes
  13212. * duplicated nodes will be added right after the original nodes
  13213. * @param {Node[] | Node} nodes
  13214. */
  13215. Node.onDuplicate = function(nodes) {
  13216. if (!Array.isArray(nodes)) {
  13217. return Node.onDuplicate([nodes]);
  13218. }
  13219. if (nodes && nodes.length > 0) {
  13220. var lastNode = nodes[nodes.length - 1];
  13221. var parent = lastNode.parent;
  13222. var editor = lastNode.editor;
  13223. editor.deselect(editor.multiselection.nodes);
  13224. // duplicate the nodes
  13225. var oldSelection = editor.getSelection();
  13226. var afterNode = lastNode;
  13227. var clones = nodes.map(function (node) {
  13228. var clone = node.clone();
  13229. parent.insertAfter(clone, afterNode);
  13230. afterNode = clone;
  13231. return clone;
  13232. });
  13233. // set selection to the duplicated nodes
  13234. if (nodes.length === 1) {
  13235. clones[0].focus();
  13236. }
  13237. else {
  13238. editor.select(clones);
  13239. }
  13240. var newSelection = editor.getSelection();
  13241. editor._onAction('duplicateNodes', {
  13242. afterNode: lastNode,
  13243. nodes: clones,
  13244. parent: parent,
  13245. oldSelection: oldSelection,
  13246. newSelection: newSelection
  13247. });
  13248. }
  13249. };
  13250. /**
  13251. * Handle insert before event
  13252. * @param {String} [field]
  13253. * @param {*} [value]
  13254. * @param {String} [type] Can be 'auto', 'array', 'object', or 'string'
  13255. * @private
  13256. */
  13257. Node.prototype._onInsertBefore = function (field, value, type) {
  13258. var oldSelection = this.editor.getSelection();
  13259. var newNode = new Node(this.editor, {
  13260. field: (field != undefined) ? field : '',
  13261. value: (value != undefined) ? value : '',
  13262. type: type
  13263. });
  13264. newNode.expand(true);
  13265. this.parent.insertBefore(newNode, this);
  13266. this.editor.highlighter.unhighlight();
  13267. newNode.focus('field');
  13268. var newSelection = this.editor.getSelection();
  13269. this.editor._onAction('insertBeforeNodes', {
  13270. nodes: [newNode],
  13271. beforeNode: this,
  13272. parent: this.parent,
  13273. oldSelection: oldSelection,
  13274. newSelection: newSelection
  13275. });
  13276. };
  13277. /**
  13278. * Handle insert after event
  13279. * @param {String} [field]
  13280. * @param {*} [value]
  13281. * @param {String} [type] Can be 'auto', 'array', 'object', or 'string'
  13282. * @private
  13283. */
  13284. Node.prototype._onInsertAfter = function (field, value, type) {
  13285. var oldSelection = this.editor.getSelection();
  13286. var newNode = new Node(this.editor, {
  13287. field: (field != undefined) ? field : '',
  13288. value: (value != undefined) ? value : '',
  13289. type: type
  13290. });
  13291. newNode.expand(true);
  13292. this.parent.insertAfter(newNode, this);
  13293. this.editor.highlighter.unhighlight();
  13294. newNode.focus('field');
  13295. var newSelection = this.editor.getSelection();
  13296. this.editor._onAction('insertAfterNodes', {
  13297. nodes: [newNode],
  13298. afterNode: this,
  13299. parent: this.parent,
  13300. oldSelection: oldSelection,
  13301. newSelection: newSelection
  13302. });
  13303. };
  13304. /**
  13305. * Handle append event
  13306. * @param {String} [field]
  13307. * @param {*} [value]
  13308. * @param {String} [type] Can be 'auto', 'array', 'object', or 'string'
  13309. * @private
  13310. */
  13311. Node.prototype._onAppend = function (field, value, type) {
  13312. var oldSelection = this.editor.getSelection();
  13313. var newNode = new Node(this.editor, {
  13314. field: (field != undefined) ? field : '',
  13315. value: (value != undefined) ? value : '',
  13316. type: type
  13317. });
  13318. newNode.expand(true);
  13319. this.parent.appendChild(newNode);
  13320. this.editor.highlighter.unhighlight();
  13321. newNode.focus('field');
  13322. var newSelection = this.editor.getSelection();
  13323. this.editor._onAction('appendNodes', {
  13324. nodes: [newNode],
  13325. parent: this.parent,
  13326. oldSelection: oldSelection,
  13327. newSelection: newSelection
  13328. });
  13329. };
  13330. /**
  13331. * Change the type of the node's value
  13332. * @param {String} newType
  13333. * @private
  13334. */
  13335. Node.prototype._onChangeType = function (newType) {
  13336. var oldType = this.type;
  13337. if (newType != oldType) {
  13338. var oldSelection = this.editor.getSelection();
  13339. this.changeType(newType);
  13340. var newSelection = this.editor.getSelection();
  13341. this.editor._onAction('changeType', {
  13342. node: this,
  13343. oldType: oldType,
  13344. newType: newType,
  13345. oldSelection: oldSelection,
  13346. newSelection: newSelection
  13347. });
  13348. }
  13349. };
  13350. /**
  13351. * Sort the child's of the node. Only applicable when the node has type 'object'
  13352. * or 'array'.
  13353. * @param {String} direction Sorting direction. Available values: "asc", "desc"
  13354. * @private
  13355. */
  13356. Node.prototype.sort = function (direction) {
  13357. if (!this._hasChilds()) {
  13358. return;
  13359. }
  13360. var order = (direction == 'desc') ? -1 : 1;
  13361. var prop = (this.type == 'array') ? 'value': 'field';
  13362. this.hideChilds();
  13363. var oldChilds = this.childs;
  13364. var oldSortOrder = this.sortOrder;
  13365. // copy the array (the old one will be kept for an undo action
  13366. this.childs = this.childs.concat();
  13367. // sort the arrays
  13368. this.childs.sort(function (a, b) {
  13369. return order * naturalSort(a[prop], b[prop]);
  13370. });
  13371. this.sortOrder = (order == 1) ? 'asc' : 'desc';
  13372. this.editor._onAction('sort', {
  13373. node: this,
  13374. oldChilds: oldChilds,
  13375. oldSort: oldSortOrder,
  13376. newChilds: this.childs,
  13377. newSort: this.sortOrder
  13378. });
  13379. this.showChilds();
  13380. };
  13381. /**
  13382. * Create a table row with an append button.
  13383. * @return {HTMLElement | undefined} buttonAppend or undefined when inapplicable
  13384. */
  13385. Node.prototype.getAppend = function () {
  13386. if (!this.append) {
  13387. this.append = new AppendNode(this.editor);
  13388. this.append.setParent(this);
  13389. }
  13390. return this.append.getDom();
  13391. };
  13392. /**
  13393. * Find the node from an event target
  13394. * @param {Node} target
  13395. * @return {Node | undefined} node or undefined when not found
  13396. * @static
  13397. */
  13398. Node.getNodeFromTarget = function (target) {
  13399. while (target) {
  13400. if (target.node) {
  13401. return target.node;
  13402. }
  13403. target = target.parentNode;
  13404. }
  13405. return undefined;
  13406. };
  13407. /**
  13408. * Remove the focus of given nodes, and move the focus to the (a) node before,
  13409. * (b) the node after, or (c) the parent node.
  13410. * @param {Array.<Node> | Node} nodes
  13411. */
  13412. Node.blurNodes = function (nodes) {
  13413. if (!Array.isArray(nodes)) {
  13414. Node.blurNodes([nodes]);
  13415. return;
  13416. }
  13417. var firstNode = nodes[0];
  13418. var parent = firstNode.parent;
  13419. var firstIndex = firstNode.getIndex();
  13420. if (parent.childs[firstIndex + nodes.length]) {
  13421. parent.childs[firstIndex + nodes.length].focus();
  13422. }
  13423. else if (parent.childs[firstIndex - 1]) {
  13424. parent.childs[firstIndex - 1].focus();
  13425. }
  13426. else {
  13427. parent.focus();
  13428. }
  13429. };
  13430. /**
  13431. * Get the next sibling of current node
  13432. * @return {Node} nextSibling
  13433. * @private
  13434. */
  13435. Node.prototype._nextSibling = function () {
  13436. var index = this.parent.childs.indexOf(this);
  13437. return this.parent.childs[index + 1] || this.parent.append;
  13438. };
  13439. /**
  13440. * Get the previously rendered node
  13441. * @return {Node | null} previousNode
  13442. * @private
  13443. */
  13444. Node.prototype._previousNode = function () {
  13445. var prevNode = null;
  13446. var dom = this.getDom();
  13447. if (dom && dom.parentNode) {
  13448. // find the previous field
  13449. var prevDom = dom;
  13450. do {
  13451. prevDom = prevDom.previousSibling;
  13452. prevNode = Node.getNodeFromTarget(prevDom);
  13453. }
  13454. while (prevDom && (prevNode instanceof AppendNode && !prevNode.isVisible()));
  13455. }
  13456. return prevNode;
  13457. };
  13458. /**
  13459. * Get the next rendered node
  13460. * @return {Node | null} nextNode
  13461. * @private
  13462. */
  13463. Node.prototype._nextNode = function () {
  13464. var nextNode = null;
  13465. var dom = this.getDom();
  13466. if (dom && dom.parentNode) {
  13467. // find the previous field
  13468. var nextDom = dom;
  13469. do {
  13470. nextDom = nextDom.nextSibling;
  13471. nextNode = Node.getNodeFromTarget(nextDom);
  13472. }
  13473. while (nextDom && (nextNode instanceof AppendNode && !nextNode.isVisible()));
  13474. }
  13475. return nextNode;
  13476. };
  13477. /**
  13478. * Get the first rendered node
  13479. * @return {Node | null} firstNode
  13480. * @private
  13481. */
  13482. Node.prototype._firstNode = function () {
  13483. var firstNode = null;
  13484. var dom = this.getDom();
  13485. if (dom && dom.parentNode) {
  13486. var firstDom = dom.parentNode.firstChild;
  13487. firstNode = Node.getNodeFromTarget(firstDom);
  13488. }
  13489. return firstNode;
  13490. };
  13491. /**
  13492. * Get the last rendered node
  13493. * @return {Node | null} lastNode
  13494. * @private
  13495. */
  13496. Node.prototype._lastNode = function () {
  13497. var lastNode = null;
  13498. var dom = this.getDom();
  13499. if (dom && dom.parentNode) {
  13500. var lastDom = dom.parentNode.lastChild;
  13501. lastNode = Node.getNodeFromTarget(lastDom);
  13502. while (lastDom && (lastNode instanceof AppendNode && !lastNode.isVisible())) {
  13503. lastDom = lastDom.previousSibling;
  13504. lastNode = Node.getNodeFromTarget(lastDom);
  13505. }
  13506. }
  13507. return lastNode;
  13508. };
  13509. /**
  13510. * Get the next element which can have focus.
  13511. * @param {Element} elem
  13512. * @return {Element | null} nextElem
  13513. * @private
  13514. */
  13515. Node.prototype._previousElement = function (elem) {
  13516. var dom = this.dom;
  13517. // noinspection FallthroughInSwitchStatementJS
  13518. switch (elem) {
  13519. case dom.value:
  13520. if (this.fieldEditable) {
  13521. return dom.field;
  13522. }
  13523. // intentional fall through
  13524. case dom.field:
  13525. if (this._hasChilds()) {
  13526. return dom.expand;
  13527. }
  13528. // intentional fall through
  13529. case dom.expand:
  13530. return dom.menu;
  13531. case dom.menu:
  13532. if (dom.drag) {
  13533. return dom.drag;
  13534. }
  13535. // intentional fall through
  13536. default:
  13537. return null;
  13538. }
  13539. };
  13540. /**
  13541. * Get the next element which can have focus.
  13542. * @param {Element} elem
  13543. * @return {Element | null} nextElem
  13544. * @private
  13545. */
  13546. Node.prototype._nextElement = function (elem) {
  13547. var dom = this.dom;
  13548. // noinspection FallthroughInSwitchStatementJS
  13549. switch (elem) {
  13550. case dom.drag:
  13551. return dom.menu;
  13552. case dom.menu:
  13553. if (this._hasChilds()) {
  13554. return dom.expand;
  13555. }
  13556. // intentional fall through
  13557. case dom.expand:
  13558. if (this.fieldEditable) {
  13559. return dom.field;
  13560. }
  13561. // intentional fall through
  13562. case dom.field:
  13563. if (!this._hasChilds()) {
  13564. return dom.value;
  13565. }
  13566. default:
  13567. return null;
  13568. }
  13569. };
  13570. /**
  13571. * Get the dom name of given element. returns null if not found.
  13572. * For example when element == dom.field, "field" is returned.
  13573. * @param {Element} element
  13574. * @return {String | null} elementName Available elements with name: 'drag',
  13575. * 'menu', 'expand', 'field', 'value'
  13576. * @private
  13577. */
  13578. Node.prototype._getElementName = function (element) {
  13579. var dom = this.dom;
  13580. for (var name in dom) {
  13581. if (dom.hasOwnProperty(name)) {
  13582. if (dom[name] == element) {
  13583. return name;
  13584. }
  13585. }
  13586. }
  13587. return null;
  13588. };
  13589. /**
  13590. * Test if this node has childs. This is the case when the node is an object
  13591. * or array.
  13592. * @return {boolean} hasChilds
  13593. * @private
  13594. */
  13595. Node.prototype._hasChilds = function () {
  13596. return this.type == 'array' || this.type == 'object';
  13597. };
  13598. // titles with explanation for the different types
  13599. Node.TYPE_TITLES = {
  13600. 'auto': 'Field type "auto". ' +
  13601. 'The field type is automatically determined from the value ' +
  13602. 'and can be a string, number, boolean, or null.',
  13603. 'object': 'Field type "object". ' +
  13604. 'An object contains an unordered set of key/value pairs.',
  13605. 'array': 'Field type "array". ' +
  13606. 'An array contains an ordered collection of values.',
  13607. 'string': 'Field type "string". ' +
  13608. 'Field type is not determined from the value, ' +
  13609. 'but always returned as string.'
  13610. };
  13611. /**
  13612. * Show a contextmenu for this node
  13613. * @param {HTMLElement} anchor Anchor element to attach the context menu to
  13614. * as sibling.
  13615. * @param {function} [onClose] Callback method called when the context menu
  13616. * is being closed.
  13617. */
  13618. Node.prototype.showContextMenu = function (anchor, onClose) {
  13619. var node = this;
  13620. var titles = Node.TYPE_TITLES;
  13621. var items = [];
  13622. if (this.editable.value) {
  13623. items.push({
  13624. text: 'Type',
  13625. title: 'Change the type of this field',
  13626. className: 'jsoneditor-type-' + this.type,
  13627. submenu: [
  13628. {
  13629. text: 'Auto',
  13630. className: 'jsoneditor-type-auto' +
  13631. (this.type == 'auto' ? ' jsoneditor-selected' : ''),
  13632. title: titles.auto,
  13633. click: function () {
  13634. node._onChangeType('auto');
  13635. }
  13636. },
  13637. {
  13638. text: 'Array',
  13639. className: 'jsoneditor-type-array' +
  13640. (this.type == 'array' ? ' jsoneditor-selected' : ''),
  13641. title: titles.array,
  13642. click: function () {
  13643. node._onChangeType('array');
  13644. }
  13645. },
  13646. {
  13647. text: 'Object',
  13648. className: 'jsoneditor-type-object' +
  13649. (this.type == 'object' ? ' jsoneditor-selected' : ''),
  13650. title: titles.object,
  13651. click: function () {
  13652. node._onChangeType('object');
  13653. }
  13654. },
  13655. {
  13656. text: 'String',
  13657. className: 'jsoneditor-type-string' +
  13658. (this.type == 'string' ? ' jsoneditor-selected' : ''),
  13659. title: titles.string,
  13660. click: function () {
  13661. node._onChangeType('string');
  13662. }
  13663. }
  13664. ]
  13665. });
  13666. }
  13667. if (this._hasChilds()) {
  13668. var direction = ((this.sortOrder == 'asc') ? 'desc': 'asc');
  13669. items.push({
  13670. text: 'Sort',
  13671. title: 'Sort the childs of this ' + this.type,
  13672. className: 'jsoneditor-sort-' + direction,
  13673. click: function () {
  13674. node.sort(direction);
  13675. },
  13676. submenu: [
  13677. {
  13678. text: 'Ascending',
  13679. className: 'jsoneditor-sort-asc',
  13680. title: 'Sort the childs of this ' + this.type + ' in ascending order',
  13681. click: function () {
  13682. node.sort('asc');
  13683. }
  13684. },
  13685. {
  13686. text: 'Descending',
  13687. className: 'jsoneditor-sort-desc',
  13688. title: 'Sort the childs of this ' + this.type +' in descending order',
  13689. click: function () {
  13690. node.sort('desc');
  13691. }
  13692. }
  13693. ]
  13694. });
  13695. }
  13696. if (this.parent && this.parent._hasChilds()) {
  13697. if (items.length) {
  13698. // create a separator
  13699. items.push({
  13700. 'type': 'separator'
  13701. });
  13702. }
  13703. // create append button (for last child node only)
  13704. var childs = node.parent.childs;
  13705. if (node == childs[childs.length - 1]) {
  13706. items.push({
  13707. text: 'Append',
  13708. title: 'Append a new field with type \'auto\' after this field (Ctrl+Shift+Ins)',
  13709. submenuTitle: 'Select the type of the field to be appended',
  13710. className: 'jsoneditor-append',
  13711. click: function () {
  13712. node._onAppend('', '', 'auto');
  13713. },
  13714. submenu: [
  13715. {
  13716. text: 'Auto',
  13717. className: 'jsoneditor-type-auto',
  13718. title: titles.auto,
  13719. click: function () {
  13720. node._onAppend('', '', 'auto');
  13721. }
  13722. },
  13723. {
  13724. text: 'Array',
  13725. className: 'jsoneditor-type-array',
  13726. title: titles.array,
  13727. click: function () {
  13728. node._onAppend('', []);
  13729. }
  13730. },
  13731. {
  13732. text: 'Object',
  13733. className: 'jsoneditor-type-object',
  13734. title: titles.object,
  13735. click: function () {
  13736. node._onAppend('', {});
  13737. }
  13738. },
  13739. {
  13740. text: 'String',
  13741. className: 'jsoneditor-type-string',
  13742. title: titles.string,
  13743. click: function () {
  13744. node._onAppend('', '', 'string');
  13745. }
  13746. }
  13747. ]
  13748. });
  13749. }
  13750. // create insert button
  13751. items.push({
  13752. text: 'Insert',
  13753. title: 'Insert a new field with type \'auto\' before this field (Ctrl+Ins)',
  13754. submenuTitle: 'Select the type of the field to be inserted',
  13755. className: 'jsoneditor-insert',
  13756. click: function () {
  13757. node._onInsertBefore('', '', 'auto');
  13758. },
  13759. submenu: [
  13760. {
  13761. text: 'Auto',
  13762. className: 'jsoneditor-type-auto',
  13763. title: titles.auto,
  13764. click: function () {
  13765. node._onInsertBefore('', '', 'auto');
  13766. }
  13767. },
  13768. {
  13769. text: 'Array',
  13770. className: 'jsoneditor-type-array',
  13771. title: titles.array,
  13772. click: function () {
  13773. node._onInsertBefore('', []);
  13774. }
  13775. },
  13776. {
  13777. text: 'Object',
  13778. className: 'jsoneditor-type-object',
  13779. title: titles.object,
  13780. click: function () {
  13781. node._onInsertBefore('', {});
  13782. }
  13783. },
  13784. {
  13785. text: 'String',
  13786. className: 'jsoneditor-type-string',
  13787. title: titles.string,
  13788. click: function () {
  13789. node._onInsertBefore('', '', 'string');
  13790. }
  13791. }
  13792. ]
  13793. });
  13794. if (this.editable.field) {
  13795. // create duplicate button
  13796. items.push({
  13797. text: 'Duplicate',
  13798. title: 'Duplicate this field (Ctrl+D)',
  13799. className: 'jsoneditor-duplicate',
  13800. click: function () {
  13801. Node.onDuplicate(node);
  13802. }
  13803. });
  13804. // create remove button
  13805. items.push({
  13806. text: 'Remove',
  13807. title: 'Remove this field (Ctrl+Del)',
  13808. className: 'jsoneditor-remove',
  13809. click: function () {
  13810. Node.onRemove(node);
  13811. }
  13812. });
  13813. }
  13814. }
  13815. var menu = new ContextMenu(items, {close: onClose});
  13816. menu.show(anchor, this.editor.content);
  13817. };
  13818. /**
  13819. * get the type of a value
  13820. * @param {*} value
  13821. * @return {String} type Can be 'object', 'array', 'string', 'auto'
  13822. * @private
  13823. */
  13824. Node.prototype._getType = function(value) {
  13825. if (value instanceof Array) {
  13826. return 'array';
  13827. }
  13828. if (value instanceof Object) {
  13829. return 'object';
  13830. }
  13831. if (typeof(value) == 'string' && typeof(this._stringCast(value)) != 'string') {
  13832. return 'string';
  13833. }
  13834. return 'auto';
  13835. };
  13836. /**
  13837. * cast contents of a string to the correct type. This can be a string,
  13838. * a number, a boolean, etc
  13839. * @param {String} str
  13840. * @return {*} castedStr
  13841. * @private
  13842. */
  13843. Node.prototype._stringCast = function(str) {
  13844. var lower = str.toLowerCase(),
  13845. num = Number(str), // will nicely fail with '123ab'
  13846. numFloat = parseFloat(str); // will nicely fail with ' '
  13847. if (str == '') {
  13848. return '';
  13849. }
  13850. else if (lower == 'null') {
  13851. return null;
  13852. }
  13853. else if (lower == 'true') {
  13854. return true;
  13855. }
  13856. else if (lower == 'false') {
  13857. return false;
  13858. }
  13859. else if (!isNaN(num) && !isNaN(numFloat)) {
  13860. return num;
  13861. }
  13862. else {
  13863. return str;
  13864. }
  13865. };
  13866. /**
  13867. * escape a text, such that it can be displayed safely in an HTML element
  13868. * @param {String} text
  13869. * @return {String} escapedText
  13870. * @private
  13871. */
  13872. Node.prototype._escapeHTML = function (text) {
  13873. if (typeof text !== 'string') {
  13874. return String(text);
  13875. }
  13876. else {
  13877. var htmlEscaped = String(text)
  13878. .replace(/&/g, '&amp;') // must be replaced first!
  13879. .replace(/</g, '&lt;')
  13880. .replace(/>/g, '&gt;')
  13881. .replace(/ /g, ' &nbsp;') // replace double space with an nbsp and space
  13882. .replace(/^ /, '&nbsp;') // space at start
  13883. .replace(/ $/, '&nbsp;'); // space at end
  13884. var json = JSON.stringify(htmlEscaped);
  13885. var html = json.substring(1, json.length - 1);
  13886. if (this.editor.options.escapeUnicode === true) {
  13887. html = util.escapeUnicodeChars(html);
  13888. }
  13889. return html;
  13890. }
  13891. };
  13892. /**
  13893. * unescape a string.
  13894. * @param {String} escapedText
  13895. * @return {String} text
  13896. * @private
  13897. */
  13898. Node.prototype._unescapeHTML = function (escapedText) {
  13899. var json = '"' + this._escapeJSON(escapedText) + '"';
  13900. var htmlEscaped = util.parse(json);
  13901. return htmlEscaped
  13902. .replace(/&lt;/g, '<')
  13903. .replace(/&gt;/g, '>')
  13904. .replace(/&nbsp;|\u00A0/g, ' ')
  13905. .replace(/&amp;/g, '&'); // must be replaced last
  13906. };
  13907. /**
  13908. * escape a text to make it a valid JSON string. The method will:
  13909. * - replace unescaped double quotes with '\"'
  13910. * - replace unescaped backslash with '\\'
  13911. * - replace returns with '\n'
  13912. * @param {String} text
  13913. * @return {String} escapedText
  13914. * @private
  13915. */
  13916. Node.prototype._escapeJSON = function (text) {
  13917. // TODO: replace with some smart regex (only when a new solution is faster!)
  13918. var escaped = '';
  13919. var i = 0;
  13920. while (i < text.length) {
  13921. var c = text.charAt(i);
  13922. if (c == '\n') {
  13923. escaped += '\\n';
  13924. }
  13925. else if (c == '\\') {
  13926. escaped += c;
  13927. i++;
  13928. c = text.charAt(i);
  13929. if (c === '' || '"\\/bfnrtu'.indexOf(c) == -1) {
  13930. escaped += '\\'; // no valid escape character
  13931. }
  13932. escaped += c;
  13933. }
  13934. else if (c == '"') {
  13935. escaped += '\\"';
  13936. }
  13937. else {
  13938. escaped += c;
  13939. }
  13940. i++;
  13941. }
  13942. return escaped;
  13943. };
  13944. // TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode
  13945. var AppendNode = appendNodeFactory(Node);
  13946. module.exports = Node;
  13947. /***/ },
  13948. /* 59 */
  13949. /***/ function(module, exports) {
  13950. /*
  13951. * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
  13952. * Author: Jim Palmer (based on chunking idea from Dave Koelle)
  13953. */
  13954. /*jshint unused:false */
  13955. module.exports = function naturalSort (a, b) {
  13956. "use strict";
  13957. var re = /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,
  13958. sre = /(^[ ]*|[ ]*$)/g,
  13959. dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
  13960. hre = /^0x[0-9a-f]+$/i,
  13961. ore = /^0/,
  13962. i = function(s) { return naturalSort.insensitive && ('' + s).toLowerCase() || '' + s; },
  13963. // convert all to strings strip whitespace
  13964. x = i(a).replace(sre, '') || '',
  13965. y = i(b).replace(sre, '') || '',
  13966. // chunk/tokenize
  13967. xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
  13968. yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
  13969. // numeric, hex or date detection
  13970. xD = parseInt(x.match(hre), 16) || (xN.length !== 1 && x.match(dre) && Date.parse(x)),
  13971. yD = parseInt(y.match(hre), 16) || xD && y.match(dre) && Date.parse(y) || null,
  13972. oFxNcL, oFyNcL;
  13973. // first try and sort Hex codes or Dates
  13974. if (yD) {
  13975. if ( xD < yD ) { return -1; }
  13976. else if ( xD > yD ) { return 1; }
  13977. }
  13978. // natural sorting through split numeric strings and default strings
  13979. for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
  13980. // find floats not starting with '0', string or 0 if not defined (Clint Priest)
  13981. oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
  13982. oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
  13983. // handle numeric vs string comparison - number < string - (Kyle Adams)
  13984. if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; }
  13985. // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
  13986. else if (typeof oFxNcL !== typeof oFyNcL) {
  13987. oFxNcL += '';
  13988. oFyNcL += '';
  13989. }
  13990. if (oFxNcL < oFyNcL) { return -1; }
  13991. if (oFxNcL > oFyNcL) { return 1; }
  13992. }
  13993. return 0;
  13994. };
  13995. /***/ },
  13996. /* 60 */
  13997. /***/ function(module, exports, __webpack_require__) {
  13998. 'use strict';
  13999. var util = __webpack_require__(54);
  14000. var ContextMenu = __webpack_require__(57);
  14001. /**
  14002. * A factory function to create an AppendNode, which depends on a Node
  14003. * @param {Node} Node
  14004. */
  14005. function appendNodeFactory(Node) {
  14006. /**
  14007. * @constructor AppendNode
  14008. * @extends Node
  14009. * @param {TreeEditor} editor
  14010. * Create a new AppendNode. This is a special node which is created at the
  14011. * end of the list with childs for an object or array
  14012. */
  14013. function AppendNode (editor) {
  14014. /** @type {TreeEditor} */
  14015. this.editor = editor;
  14016. this.dom = {};
  14017. }
  14018. AppendNode.prototype = new Node();
  14019. /**
  14020. * Return a table row with an append button.
  14021. * @return {Element} dom TR element
  14022. */
  14023. AppendNode.prototype.getDom = function () {
  14024. // TODO: implement a new solution for the append node
  14025. var dom = this.dom;
  14026. if (dom.tr) {
  14027. return dom.tr;
  14028. }
  14029. this._updateEditability();
  14030. // a row for the append button
  14031. var trAppend = document.createElement('tr');
  14032. trAppend.node = this;
  14033. dom.tr = trAppend;
  14034. // TODO: consistent naming
  14035. if (this.editor.options.mode === 'tree') {
  14036. // a cell for the dragarea column
  14037. dom.tdDrag = document.createElement('td');
  14038. // create context menu
  14039. var tdMenu = document.createElement('td');
  14040. dom.tdMenu = tdMenu;
  14041. var menu = document.createElement('button');
  14042. menu.type = 'button';
  14043. menu.className = 'jsoneditor-contextmenu';
  14044. menu.title = 'Click to open the actions menu (Ctrl+M)';
  14045. dom.menu = menu;
  14046. tdMenu.appendChild(dom.menu);
  14047. }
  14048. // a cell for the contents (showing text 'empty')
  14049. var tdAppend = document.createElement('td');
  14050. var domText = document.createElement('div');
  14051. domText.innerHTML = '(empty)';
  14052. domText.className = 'jsoneditor-readonly';
  14053. tdAppend.appendChild(domText);
  14054. dom.td = tdAppend;
  14055. dom.text = domText;
  14056. this.updateDom();
  14057. return trAppend;
  14058. };
  14059. /**
  14060. * Update the HTML dom of the Node
  14061. */
  14062. AppendNode.prototype.updateDom = function () {
  14063. var dom = this.dom;
  14064. var tdAppend = dom.td;
  14065. if (tdAppend) {
  14066. tdAppend.style.paddingLeft = (this.getLevel() * 24 + 26) + 'px';
  14067. // TODO: not so nice hard coded offset
  14068. }
  14069. var domText = dom.text;
  14070. if (domText) {
  14071. domText.innerHTML = '(empty ' + this.parent.type + ')';
  14072. }
  14073. // attach or detach the contents of the append node:
  14074. // hide when the parent has childs, show when the parent has no childs
  14075. var trAppend = dom.tr;
  14076. if (!this.isVisible()) {
  14077. if (dom.tr.firstChild) {
  14078. if (dom.tdDrag) {
  14079. trAppend.removeChild(dom.tdDrag);
  14080. }
  14081. if (dom.tdMenu) {
  14082. trAppend.removeChild(dom.tdMenu);
  14083. }
  14084. trAppend.removeChild(tdAppend);
  14085. }
  14086. }
  14087. else {
  14088. if (!dom.tr.firstChild) {
  14089. if (dom.tdDrag) {
  14090. trAppend.appendChild(dom.tdDrag);
  14091. }
  14092. if (dom.tdMenu) {
  14093. trAppend.appendChild(dom.tdMenu);
  14094. }
  14095. trAppend.appendChild(tdAppend);
  14096. }
  14097. }
  14098. };
  14099. /**
  14100. * Check whether the AppendNode is currently visible.
  14101. * the AppendNode is visible when its parent has no childs (i.e. is empty).
  14102. * @return {boolean} isVisible
  14103. */
  14104. AppendNode.prototype.isVisible = function () {
  14105. return (this.parent.childs.length == 0);
  14106. };
  14107. /**
  14108. * Show a contextmenu for this node
  14109. * @param {HTMLElement} anchor The element to attach the menu to.
  14110. * @param {function} [onClose] Callback method called when the context menu
  14111. * is being closed.
  14112. */
  14113. AppendNode.prototype.showContextMenu = function (anchor, onClose) {
  14114. var node = this;
  14115. var titles = Node.TYPE_TITLES;
  14116. var items = [
  14117. // create append button
  14118. {
  14119. 'text': 'Append',
  14120. 'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)',
  14121. 'submenuTitle': 'Select the type of the field to be appended',
  14122. 'className': 'jsoneditor-insert',
  14123. 'click': function () {
  14124. node._onAppend('', '', 'auto');
  14125. },
  14126. 'submenu': [
  14127. {
  14128. 'text': 'Auto',
  14129. 'className': 'jsoneditor-type-auto',
  14130. 'title': titles.auto,
  14131. 'click': function () {
  14132. node._onAppend('', '', 'auto');
  14133. }
  14134. },
  14135. {
  14136. 'text': 'Array',
  14137. 'className': 'jsoneditor-type-array',
  14138. 'title': titles.array,
  14139. 'click': function () {
  14140. node._onAppend('', []);
  14141. }
  14142. },
  14143. {
  14144. 'text': 'Object',
  14145. 'className': 'jsoneditor-type-object',
  14146. 'title': titles.object,
  14147. 'click': function () {
  14148. node._onAppend('', {});
  14149. }
  14150. },
  14151. {
  14152. 'text': 'String',
  14153. 'className': 'jsoneditor-type-string',
  14154. 'title': titles.string,
  14155. 'click': function () {
  14156. node._onAppend('', '', 'string');
  14157. }
  14158. }
  14159. ]
  14160. }
  14161. ];
  14162. var menu = new ContextMenu(items, {close: onClose});
  14163. menu.show(anchor, this.editor.content);
  14164. };
  14165. /**
  14166. * Handle an event. The event is catched centrally by the editor
  14167. * @param {Event} event
  14168. */
  14169. AppendNode.prototype.onEvent = function (event) {
  14170. var type = event.type;
  14171. var target = event.target || event.srcElement;
  14172. var dom = this.dom;
  14173. // highlight the append nodes parent
  14174. var menu = dom.menu;
  14175. if (target == menu) {
  14176. if (type == 'mouseover') {
  14177. this.editor.highlighter.highlight(this.parent);
  14178. }
  14179. else if (type == 'mouseout') {
  14180. this.editor.highlighter.unhighlight();
  14181. }
  14182. }
  14183. // context menu events
  14184. if (type == 'click' && target == dom.menu) {
  14185. var highlighter = this.editor.highlighter;
  14186. highlighter.highlight(this.parent);
  14187. highlighter.lock();
  14188. util.addClassName(dom.menu, 'jsoneditor-selected');
  14189. this.showContextMenu(dom.menu, function () {
  14190. util.removeClassName(dom.menu, 'jsoneditor-selected');
  14191. highlighter.unlock();
  14192. highlighter.unhighlight();
  14193. });
  14194. }
  14195. if (type == 'keydown') {
  14196. this.onKeyDown(event);
  14197. }
  14198. };
  14199. return AppendNode;
  14200. }
  14201. module.exports = appendNodeFactory;
  14202. /***/ },
  14203. /* 61 */
  14204. /***/ function(module, exports, __webpack_require__) {
  14205. 'use strict';
  14206. var ContextMenu = __webpack_require__(57);
  14207. /**
  14208. * Create a select box to be used in the editor menu's, which allows to switch mode
  14209. * @param {HTMLElement} container
  14210. * @param {String[]} modes Available modes: 'code', 'form', 'text', 'tree', 'view'
  14211. * @param {String} current Available modes: 'code', 'form', 'text', 'tree', 'view'
  14212. * @param {function(mode: string)} onSwitch Callback invoked on switch
  14213. * @constructor
  14214. */
  14215. function ModeSwitcher(container, modes, current, onSwitch) {
  14216. // available modes
  14217. var availableModes = {
  14218. code: {
  14219. 'text': 'Code',
  14220. 'title': 'Switch to code highlighter',
  14221. 'click': function () {
  14222. onSwitch('code')
  14223. }
  14224. },
  14225. form: {
  14226. 'text': 'Form',
  14227. 'title': 'Switch to form editor',
  14228. 'click': function () {
  14229. onSwitch('form');
  14230. }
  14231. },
  14232. text: {
  14233. 'text': 'Text',
  14234. 'title': 'Switch to plain text editor',
  14235. 'click': function () {
  14236. onSwitch('text');
  14237. }
  14238. },
  14239. tree: {
  14240. 'text': 'Tree',
  14241. 'title': 'Switch to tree editor',
  14242. 'click': function () {
  14243. onSwitch('tree');
  14244. }
  14245. },
  14246. view: {
  14247. 'text': 'View',
  14248. 'title': 'Switch to tree view',
  14249. 'click': function () {
  14250. onSwitch('view');
  14251. }
  14252. }
  14253. };
  14254. // list the selected modes
  14255. var items = [];
  14256. for (var i = 0; i < modes.length; i++) {
  14257. var mode = modes[i];
  14258. var item = availableModes[mode];
  14259. if (!item) {
  14260. throw new Error('Unknown mode "' + mode + '"');
  14261. }
  14262. item.className = 'jsoneditor-type-modes' + ((current == mode) ? ' jsoneditor-selected' : '');
  14263. items.push(item);
  14264. }
  14265. // retrieve the title of current mode
  14266. var currentMode = availableModes[current];
  14267. if (!currentMode) {
  14268. throw new Error('Unknown mode "' + current + '"');
  14269. }
  14270. var currentTitle = currentMode.text;
  14271. // create the html element
  14272. var box = document.createElement('button');
  14273. box.type = 'button';
  14274. box.className = 'jsoneditor-modes jsoneditor-separator';
  14275. box.innerHTML = currentTitle + ' &#x25BE;';
  14276. box.title = 'Switch editor mode';
  14277. box.onclick = function () {
  14278. var menu = new ContextMenu(items);
  14279. menu.show(box);
  14280. };
  14281. var frame = document.createElement('div');
  14282. frame.className = 'jsoneditor-modes';
  14283. frame.style.position = 'relative';
  14284. frame.appendChild(box);
  14285. container.appendChild(frame);
  14286. this.dom = {
  14287. container: container,
  14288. box: box,
  14289. frame: frame
  14290. };
  14291. }
  14292. /**
  14293. * Set focus to switcher
  14294. */
  14295. ModeSwitcher.prototype.focus = function () {
  14296. this.dom.box.focus();
  14297. };
  14298. /**
  14299. * Destroy the ModeSwitcher, remove from DOM
  14300. */
  14301. ModeSwitcher.prototype.destroy = function () {
  14302. if (this.dom && this.dom.frame && this.dom.frame.parentNode) {
  14303. this.dom.frame.parentNode.removeChild(this.dom.frame);
  14304. }
  14305. this.dom = null;
  14306. };
  14307. module.exports = ModeSwitcher;
  14308. /***/ },
  14309. /* 62 */
  14310. /***/ function(module, exports, __webpack_require__) {
  14311. 'use strict';
  14312. var ace;
  14313. try {
  14314. ace = __webpack_require__(63);
  14315. }
  14316. catch (err) {
  14317. // failed to load ace, no problem, we will fall back to plain text
  14318. }
  14319. var ModeSwitcher = __webpack_require__(61);
  14320. var util = __webpack_require__(54);
  14321. // create a mixin with the functions for text mode
  14322. var textmode = {};
  14323. var MAX_ERRORS = 3; // maximum number of displayed errors at the bottom
  14324. var DEFAULT_THEME = 'ace/theme/jsoneditor';
  14325. /**
  14326. * Create a text editor
  14327. * @param {Element} container
  14328. * @param {Object} [options] Object with options. available options:
  14329. * {String} mode Available values:
  14330. * "text" (default)
  14331. * or "code".
  14332. * {Number} indentation Number of indentation
  14333. * spaces. 2 by default.
  14334. * {function} onChange Callback method
  14335. * triggered on change
  14336. * {function} onModeChange Callback method
  14337. * triggered after setMode
  14338. * {Object} ace A custom instance of
  14339. * Ace editor.
  14340. * {boolean} escapeUnicode If true, unicode
  14341. * characters are escaped.
  14342. * false by default.
  14343. * @private
  14344. */
  14345. textmode.create = function (container, options) {
  14346. // read options
  14347. options = options || {};
  14348. this.options = options;
  14349. // indentation
  14350. if (options.indentation) {
  14351. this.indentation = Number(options.indentation);
  14352. }
  14353. else {
  14354. this.indentation = 2; // number of spaces
  14355. }
  14356. // grab ace from options if provided
  14357. var _ace = options.ace ? options.ace : ace;
  14358. // determine mode
  14359. this.mode = (options.mode == 'code') ? 'code' : 'text';
  14360. if (this.mode == 'code') {
  14361. // verify whether Ace editor is available and supported
  14362. if (typeof _ace === 'undefined') {
  14363. this.mode = 'text';
  14364. console.warn('Failed to load Ace editor, falling back to plain text mode. Please use a JSONEditor bundle including Ace, or pass Ace as via the configuration option `ace`.');
  14365. }
  14366. }
  14367. // determine theme
  14368. this.theme = options.theme || DEFAULT_THEME;
  14369. if (this.theme === DEFAULT_THEME && window.ace) {
  14370. __webpack_require__(70);
  14371. }
  14372. var me = this;
  14373. this.container = container;
  14374. this.dom = {};
  14375. this.aceEditor = undefined; // ace code editor
  14376. this.textarea = undefined; // plain text editor (fallback when Ace is not available)
  14377. this.validateSchema = null;
  14378. // create a debounced validate function
  14379. this._debouncedValidate = util.debounce(this.validate.bind(this), this.DEBOUNCE_INTERVAL);
  14380. this.width = container.clientWidth;
  14381. this.height = container.clientHeight;
  14382. this.frame = document.createElement('div');
  14383. this.frame.className = 'jsoneditor jsoneditor-mode-' + this.options.mode;
  14384. this.frame.onclick = function (event) {
  14385. // prevent default submit action when the editor is located inside a form
  14386. event.preventDefault();
  14387. };
  14388. this.frame.onkeydown = function (event) {
  14389. me._onKeyDown(event);
  14390. };
  14391. // create menu
  14392. this.menu = document.createElement('div');
  14393. this.menu.className = 'jsoneditor-menu';
  14394. this.frame.appendChild(this.menu);
  14395. // create format button
  14396. var buttonFormat = document.createElement('button');
  14397. buttonFormat.type = 'button';
  14398. buttonFormat.className = 'jsoneditor-format';
  14399. buttonFormat.title = 'Format JSON data, with proper indentation and line feeds (Ctrl+\\)';
  14400. this.menu.appendChild(buttonFormat);
  14401. buttonFormat.onclick = function () {
  14402. try {
  14403. me.format();
  14404. me._onChange();
  14405. }
  14406. catch (err) {
  14407. me._onError(err);
  14408. }
  14409. };
  14410. // create compact button
  14411. var buttonCompact = document.createElement('button');
  14412. buttonCompact.type = 'button';
  14413. buttonCompact.className = 'jsoneditor-compact';
  14414. buttonCompact.title = 'Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)';
  14415. this.menu.appendChild(buttonCompact);
  14416. buttonCompact.onclick = function () {
  14417. try {
  14418. me.compact();
  14419. me._onChange();
  14420. }
  14421. catch (err) {
  14422. me._onError(err);
  14423. }
  14424. };
  14425. // create mode box
  14426. if (this.options && this.options.modes && this.options.modes.length) {
  14427. this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) {
  14428. // switch mode and restore focus
  14429. me.setMode(mode);
  14430. me.modeSwitcher.focus();
  14431. });
  14432. }
  14433. this.content = document.createElement('div');
  14434. this.content.className = 'jsoneditor-outer';
  14435. this.frame.appendChild(this.content);
  14436. this.container.appendChild(this.frame);
  14437. if (this.mode == 'code') {
  14438. this.editorDom = document.createElement('div');
  14439. this.editorDom.style.height = '100%'; // TODO: move to css
  14440. this.editorDom.style.width = '100%'; // TODO: move to css
  14441. this.content.appendChild(this.editorDom);
  14442. var aceEditor = _ace.edit(this.editorDom);
  14443. aceEditor.$blockScrolling = Infinity;
  14444. aceEditor.setTheme(this.theme);
  14445. aceEditor.setShowPrintMargin(false);
  14446. aceEditor.setFontSize(13);
  14447. aceEditor.getSession().setMode('ace/mode/json');
  14448. aceEditor.getSession().setTabSize(this.indentation);
  14449. aceEditor.getSession().setUseSoftTabs(true);
  14450. aceEditor.getSession().setUseWrapMode(true);
  14451. aceEditor.commands.bindKey('Ctrl-L', null); // disable Ctrl+L (is used by the browser to select the address bar)
  14452. aceEditor.commands.bindKey('Command-L', null); // disable Ctrl+L (is used by the browser to select the address bar)
  14453. this.aceEditor = aceEditor;
  14454. // TODO: deprecated since v5.0.0. Cleanup backward compatibility some day
  14455. if (!this.hasOwnProperty('editor')) {
  14456. Object.defineProperty(this, 'editor', {
  14457. get: function () {
  14458. console.warn('Property "editor" has been renamed to "aceEditor".');
  14459. return me.aceEditor;
  14460. },
  14461. set: function (aceEditor) {
  14462. console.warn('Property "editor" has been renamed to "aceEditor".');
  14463. me.aceEditor = aceEditor;
  14464. }
  14465. });
  14466. }
  14467. var poweredBy = document.createElement('a');
  14468. poweredBy.appendChild(document.createTextNode('powered by ace'));
  14469. poweredBy.href = 'http://ace.ajax.org';
  14470. poweredBy.target = '_blank';
  14471. poweredBy.className = 'jsoneditor-poweredBy';
  14472. poweredBy.onclick = function () {
  14473. // TODO: this anchor falls below the margin of the content,
  14474. // therefore the normal a.href does not work. We use a click event
  14475. // for now, but this should be fixed.
  14476. window.open(poweredBy.href, poweredBy.target);
  14477. };
  14478. this.menu.appendChild(poweredBy);
  14479. // register onchange event
  14480. aceEditor.on('change', this._onChange.bind(this));
  14481. }
  14482. else {
  14483. // load a plain text textarea
  14484. var textarea = document.createElement('textarea');
  14485. textarea.className = 'jsoneditor-text';
  14486. textarea.spellcheck = false;
  14487. this.content.appendChild(textarea);
  14488. this.textarea = textarea;
  14489. // register onchange event
  14490. if (this.textarea.oninput === null) {
  14491. this.textarea.oninput = this._onChange.bind(this);
  14492. }
  14493. else {
  14494. // oninput is undefined. For IE8-
  14495. this.textarea.onchange = this._onChange.bind(this);
  14496. }
  14497. }
  14498. this.setSchema(this.options.schema);
  14499. };
  14500. /**
  14501. * Handle a change:
  14502. * - Validate JSON schema
  14503. * - Send a callback to the onChange listener if provided
  14504. * @private
  14505. */
  14506. textmode._onChange = function () {
  14507. // validate JSON schema (if configured)
  14508. this._debouncedValidate();
  14509. // trigger the onChange callback
  14510. if (this.options.onChange) {
  14511. try {
  14512. this.options.onChange();
  14513. }
  14514. catch (err) {
  14515. console.error('Error in onChange callback: ', err);
  14516. }
  14517. }
  14518. };
  14519. /**
  14520. * Event handler for keydown. Handles shortcut keys
  14521. * @param {Event} event
  14522. * @private
  14523. */
  14524. textmode._onKeyDown = function (event) {
  14525. var keynum = event.which || event.keyCode;
  14526. var handled = false;
  14527. if (keynum == 220 && event.ctrlKey) {
  14528. if (event.shiftKey) { // Ctrl+Shift+\
  14529. this.compact();
  14530. this._onChange();
  14531. }
  14532. else { // Ctrl+\
  14533. this.format();
  14534. this._onChange();
  14535. }
  14536. handled = true;
  14537. }
  14538. if (handled) {
  14539. event.preventDefault();
  14540. event.stopPropagation();
  14541. }
  14542. };
  14543. /**
  14544. * Destroy the editor. Clean up DOM, event listeners, and web workers.
  14545. */
  14546. textmode.destroy = function () {
  14547. // remove old ace editor
  14548. if (this.aceEditor) {
  14549. this.aceEditor.destroy();
  14550. this.aceEditor = null;
  14551. }
  14552. if (this.frame && this.container && this.frame.parentNode == this.container) {
  14553. this.container.removeChild(this.frame);
  14554. }
  14555. if (this.modeSwitcher) {
  14556. this.modeSwitcher.destroy();
  14557. this.modeSwitcher = null;
  14558. }
  14559. this.textarea = null;
  14560. this._debouncedValidate = null;
  14561. };
  14562. /**
  14563. * Compact the code in the formatter
  14564. */
  14565. textmode.compact = function () {
  14566. var json = this.get();
  14567. var text = JSON.stringify(json);
  14568. this.setText(text);
  14569. };
  14570. /**
  14571. * Format the code in the formatter
  14572. */
  14573. textmode.format = function () {
  14574. var json = this.get();
  14575. var text = JSON.stringify(json, null, this.indentation);
  14576. this.setText(text);
  14577. };
  14578. /**
  14579. * Set focus to the formatter
  14580. */
  14581. textmode.focus = function () {
  14582. if (this.textarea) {
  14583. this.textarea.focus();
  14584. }
  14585. if (this.aceEditor) {
  14586. this.aceEditor.focus();
  14587. }
  14588. };
  14589. /**
  14590. * Resize the formatter
  14591. */
  14592. textmode.resize = function () {
  14593. if (this.aceEditor) {
  14594. var force = false;
  14595. this.aceEditor.resize(force);
  14596. }
  14597. };
  14598. /**
  14599. * Set json data in the formatter
  14600. * @param {Object} json
  14601. */
  14602. textmode.set = function(json) {
  14603. this.setText(JSON.stringify(json, null, this.indentation));
  14604. };
  14605. /**
  14606. * Get json data from the formatter
  14607. * @return {Object} json
  14608. */
  14609. textmode.get = function() {
  14610. var text = this.getText();
  14611. var json;
  14612. try {
  14613. json = util.parse(text); // this can throw an error
  14614. }
  14615. catch (err) {
  14616. // try to sanitize json, replace JavaScript notation with JSON notation
  14617. text = util.sanitize(text);
  14618. // try to parse again
  14619. json = util.parse(text); // this can throw an error
  14620. }
  14621. return json;
  14622. };
  14623. /**
  14624. * Get the text contents of the editor
  14625. * @return {String} jsonText
  14626. */
  14627. textmode.getText = function() {
  14628. if (this.textarea) {
  14629. return this.textarea.value;
  14630. }
  14631. if (this.aceEditor) {
  14632. return this.aceEditor.getValue();
  14633. }
  14634. return '';
  14635. };
  14636. /**
  14637. * Set the text contents of the editor
  14638. * @param {String} jsonText
  14639. */
  14640. textmode.setText = function(jsonText) {
  14641. var text;
  14642. if (this.options.escapeUnicode === true) {
  14643. text = util.escapeUnicodeChars(jsonText);
  14644. }
  14645. else {
  14646. text = jsonText;
  14647. }
  14648. if (this.textarea) {
  14649. this.textarea.value = text;
  14650. }
  14651. if (this.aceEditor) {
  14652. // prevent emitting onChange events while setting new text
  14653. var originalOnChange = this.options.onChange;
  14654. this.options.onChange = null;
  14655. this.aceEditor.setValue(text, -1);
  14656. this.options.onChange = originalOnChange;
  14657. }
  14658. // validate JSON schema
  14659. this.validate();
  14660. };
  14661. /**
  14662. * Validate current JSON object against the configured JSON schema
  14663. * Throws an exception when no JSON schema is configured
  14664. */
  14665. textmode.validate = function () {
  14666. // clear all current errors
  14667. if (this.dom.validationErrors) {
  14668. this.dom.validationErrors.parentNode.removeChild(this.dom.validationErrors);
  14669. this.dom.validationErrors = null;
  14670. this.content.style.marginBottom = '';
  14671. this.content.style.paddingBottom = '';
  14672. }
  14673. var doValidate = false;
  14674. var errors = [];
  14675. var json;
  14676. try {
  14677. json = this.get(); // this can fail when there is no valid json
  14678. doValidate = true;
  14679. }
  14680. catch (err) {
  14681. // no valid JSON, don't validate
  14682. }
  14683. // only validate the JSON when parsing the JSON succeeded
  14684. if (doValidate && this.validateSchema) {
  14685. var valid = this.validateSchema(json);
  14686. if (!valid) {
  14687. errors = this.validateSchema.errors.map(function (error) {
  14688. return util.improveSchemaError(error);
  14689. });
  14690. }
  14691. }
  14692. if (errors.length > 0) {
  14693. // limit the number of displayed errors
  14694. var limit = errors.length > MAX_ERRORS;
  14695. if (limit) {
  14696. errors = errors.slice(0, MAX_ERRORS);
  14697. var hidden = this.validateSchema.errors.length - MAX_ERRORS;
  14698. errors.push('(' + hidden + ' more errors...)')
  14699. }
  14700. var validationErrors = document.createElement('div');
  14701. validationErrors.innerHTML = '<table class="jsoneditor-text-errors">' +
  14702. '<tbody>' +
  14703. errors.map(function (error) {
  14704. var message;
  14705. if (typeof error === 'string') {
  14706. message = '<td colspan="2"><pre>' + error + '</pre></td>';
  14707. }
  14708. else {
  14709. message = '<td>' + error.dataPath + '</td>' +
  14710. '<td>' + error.message + '</td>';
  14711. }
  14712. return '<tr><td><button class="jsoneditor-schema-error"></button></td>' + message + '</tr>'
  14713. }).join('') +
  14714. '</tbody>' +
  14715. '</table>';
  14716. this.dom.validationErrors = validationErrors;
  14717. this.frame.appendChild(validationErrors);
  14718. var height = validationErrors.clientHeight;
  14719. this.content.style.marginBottom = (-height) + 'px';
  14720. this.content.style.paddingBottom = height + 'px';
  14721. }
  14722. // update the height of the ace editor
  14723. if (this.aceEditor) {
  14724. var force = false;
  14725. this.aceEditor.resize(force);
  14726. }
  14727. };
  14728. // define modes
  14729. module.exports = [
  14730. {
  14731. mode: 'text',
  14732. mixin: textmode,
  14733. data: 'text',
  14734. load: textmode.format
  14735. },
  14736. {
  14737. mode: 'code',
  14738. mixin: textmode,
  14739. data: 'text',
  14740. load: textmode.format
  14741. }
  14742. ];
  14743. /***/ },
  14744. /* 63 */
  14745. /***/ function(module, exports, __webpack_require__) {
  14746. // load brace
  14747. var ace = __webpack_require__(64);
  14748. // load required ace modules
  14749. __webpack_require__(67);
  14750. __webpack_require__(69);
  14751. module.exports = ace;
  14752. /***/ },
  14753. /* 64 */
  14754. /***/ function(module, exports, __webpack_require__) {
  14755. /* ***** BEGIN LICENSE BLOCK *****
  14756. * Distributed under the BSD license:
  14757. *
  14758. * Copyright (c) 2010, Ajax.org B.V.
  14759. * All rights reserved.
  14760. *
  14761. * Redistribution and use in source and binary forms, with or without
  14762. * modification, are permitted provided that the following conditions are met:
  14763. * * Redistributions of source code must retain the above copyright
  14764. * notice, this list of conditions and the following disclaimer.
  14765. * * Redistributions in binary form must reproduce the above copyright
  14766. * notice, this list of conditions and the following disclaimer in the
  14767. * documentation and/or other materials provided with the distribution.
  14768. * * Neither the name of Ajax.org B.V. nor the
  14769. * names of its contributors may be used to endorse or promote products
  14770. * derived from this software without specific prior written permission.
  14771. *
  14772. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14773. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14774. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  14775. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  14776. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14777. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  14778. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  14779. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14780. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  14781. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14782. *
  14783. * ***** END LICENSE BLOCK ***** */
  14784. /**
  14785. * Define a module along with a payload
  14786. * @param module a name for the payload
  14787. * @param payload a function to call with (acequire, exports, module) params
  14788. */
  14789. (function() {
  14790. var ACE_NAMESPACE = "ace";
  14791. var global = (function() { return this; })();
  14792. if (!global && typeof window != "undefined") global = window; // strict mode
  14793. if (!ACE_NAMESPACE && typeof acequirejs !== "undefined")
  14794. return;
  14795. var define = function(module, deps, payload) {
  14796. if (typeof module !== "string") {
  14797. if (define.original)
  14798. define.original.apply(this, arguments);
  14799. else {
  14800. console.error("dropping module because define wasn\'t a string.");
  14801. console.trace();
  14802. }
  14803. return;
  14804. }
  14805. if (arguments.length == 2)
  14806. payload = deps;
  14807. if (!define.modules[module]) {
  14808. define.payloads[module] = payload;
  14809. define.modules[module] = null;
  14810. }
  14811. };
  14812. define.modules = {};
  14813. define.payloads = {};
  14814. /**
  14815. * Get at functionality define()ed using the function above
  14816. */
  14817. var _acequire = function(parentId, module, callback) {
  14818. if (typeof module === "string") {
  14819. var payload = lookup(parentId, module);
  14820. if (payload != undefined) {
  14821. callback && callback();
  14822. return payload;
  14823. }
  14824. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  14825. var params = [];
  14826. for (var i = 0, l = module.length; i < l; ++i) {
  14827. var dep = lookup(parentId, module[i]);
  14828. if (dep == undefined && acequire.original)
  14829. return;
  14830. params.push(dep);
  14831. }
  14832. return callback && callback.apply(null, params) || true;
  14833. }
  14834. };
  14835. var acequire = function(module, callback) {
  14836. var packagedModule = _acequire("", module, callback);
  14837. if (packagedModule == undefined && acequire.original)
  14838. return acequire.original.apply(this, arguments);
  14839. return packagedModule;
  14840. };
  14841. var normalizeModule = function(parentId, moduleName) {
  14842. // normalize plugin acequires
  14843. if (moduleName.indexOf("!") !== -1) {
  14844. var chunks = moduleName.split("!");
  14845. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  14846. }
  14847. // normalize relative acequires
  14848. if (moduleName.charAt(0) == ".") {
  14849. var base = parentId.split("/").slice(0, -1).join("/");
  14850. moduleName = base + "/" + moduleName;
  14851. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  14852. var previous = moduleName;
  14853. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  14854. }
  14855. }
  14856. return moduleName;
  14857. };
  14858. /**
  14859. * Internal function to lookup moduleNames and resolve them by calling the
  14860. * definition function if needed.
  14861. */
  14862. var lookup = function(parentId, moduleName) {
  14863. moduleName = normalizeModule(parentId, moduleName);
  14864. var module = define.modules[moduleName];
  14865. if (!module) {
  14866. module = define.payloads[moduleName];
  14867. if (typeof module === 'function') {
  14868. var exports = {};
  14869. var mod = {
  14870. id: moduleName,
  14871. uri: '',
  14872. exports: exports,
  14873. packaged: true
  14874. };
  14875. var req = function(module, callback) {
  14876. return _acequire(moduleName, module, callback);
  14877. };
  14878. var returnValue = module(req, exports, mod);
  14879. exports = returnValue || mod.exports;
  14880. define.modules[moduleName] = exports;
  14881. delete define.payloads[moduleName];
  14882. }
  14883. module = define.modules[moduleName] = exports || module;
  14884. }
  14885. return module;
  14886. };
  14887. function exportAce(ns) {
  14888. var root = global;
  14889. if (ns) {
  14890. if (!global[ns])
  14891. global[ns] = {};
  14892. root = global[ns];
  14893. }
  14894. if (!root.define || !root.define.packaged) {
  14895. define.original = root.define;
  14896. root.define = define;
  14897. root.define.packaged = true;
  14898. }
  14899. if (!root.acequire || !root.acequire.packaged) {
  14900. acequire.original = root.acequire;
  14901. root.acequire = acequire;
  14902. root.acequire.packaged = true;
  14903. }
  14904. }
  14905. exportAce(ACE_NAMESPACE);
  14906. })();
  14907. ace.define("ace/lib/regexp",["require","exports","module"], function(acequire, exports, module) {
  14908. "use strict";
  14909. var real = {
  14910. exec: RegExp.prototype.exec,
  14911. test: RegExp.prototype.test,
  14912. match: String.prototype.match,
  14913. replace: String.prototype.replace,
  14914. split: String.prototype.split
  14915. },
  14916. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  14917. compliantLastIndexIncrement = function () {
  14918. var x = /^/g;
  14919. real.test.call(x, "");
  14920. return !x.lastIndex;
  14921. }();
  14922. if (compliantLastIndexIncrement && compliantExecNpcg)
  14923. return;
  14924. RegExp.prototype.exec = function (str) {
  14925. var match = real.exec.apply(this, arguments),
  14926. name, r2;
  14927. if ( typeof(str) == 'string' && match) {
  14928. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  14929. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  14930. real.replace.call(str.slice(match.index), r2, function () {
  14931. for (var i = 1; i < arguments.length - 2; i++) {
  14932. if (arguments[i] === undefined)
  14933. match[i] = undefined;
  14934. }
  14935. });
  14936. }
  14937. if (this._xregexp && this._xregexp.captureNames) {
  14938. for (var i = 1; i < match.length; i++) {
  14939. name = this._xregexp.captureNames[i - 1];
  14940. if (name)
  14941. match[name] = match[i];
  14942. }
  14943. }
  14944. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  14945. this.lastIndex--;
  14946. }
  14947. return match;
  14948. };
  14949. if (!compliantLastIndexIncrement) {
  14950. RegExp.prototype.test = function (str) {
  14951. var match = real.exec.call(this, str);
  14952. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  14953. this.lastIndex--;
  14954. return !!match;
  14955. };
  14956. }
  14957. function getNativeFlags (regex) {
  14958. return (regex.global ? "g" : "") +
  14959. (regex.ignoreCase ? "i" : "") +
  14960. (regex.multiline ? "m" : "") +
  14961. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  14962. (regex.sticky ? "y" : "");
  14963. }
  14964. function indexOf (array, item, from) {
  14965. if (Array.prototype.indexOf) // Use the native array method if available
  14966. return array.indexOf(item, from);
  14967. for (var i = from || 0; i < array.length; i++) {
  14968. if (array[i] === item)
  14969. return i;
  14970. }
  14971. return -1;
  14972. }
  14973. });
  14974. ace.define("ace/lib/es5-shim",["require","exports","module"], function(acequire, exports, module) {
  14975. function Empty() {}
  14976. if (!Function.prototype.bind) {
  14977. Function.prototype.bind = function bind(that) { // .length is 1
  14978. var target = this;
  14979. if (typeof target != "function") {
  14980. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  14981. }
  14982. var args = slice.call(arguments, 1); // for normal call
  14983. var bound = function () {
  14984. if (this instanceof bound) {
  14985. var result = target.apply(
  14986. this,
  14987. args.concat(slice.call(arguments))
  14988. );
  14989. if (Object(result) === result) {
  14990. return result;
  14991. }
  14992. return this;
  14993. } else {
  14994. return target.apply(
  14995. that,
  14996. args.concat(slice.call(arguments))
  14997. );
  14998. }
  14999. };
  15000. if(target.prototype) {
  15001. Empty.prototype = target.prototype;
  15002. bound.prototype = new Empty();
  15003. Empty.prototype = null;
  15004. }
  15005. return bound;
  15006. };
  15007. }
  15008. var call = Function.prototype.call;
  15009. var prototypeOfArray = Array.prototype;
  15010. var prototypeOfObject = Object.prototype;
  15011. var slice = prototypeOfArray.slice;
  15012. var _toString = call.bind(prototypeOfObject.toString);
  15013. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  15014. var defineGetter;
  15015. var defineSetter;
  15016. var lookupGetter;
  15017. var lookupSetter;
  15018. var supportsAccessors;
  15019. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  15020. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  15021. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  15022. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  15023. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  15024. }
  15025. if ([1,2].splice(0).length != 2) {
  15026. if(function() { // test IE < 9 to splice bug - see issue #138
  15027. function makeArray(l) {
  15028. var a = new Array(l+2);
  15029. a[0] = a[1] = 0;
  15030. return a;
  15031. }
  15032. var array = [], lengthBefore;
  15033. array.splice.apply(array, makeArray(20));
  15034. array.splice.apply(array, makeArray(26));
  15035. lengthBefore = array.length; //46
  15036. array.splice(5, 0, "XXX"); // add one element
  15037. lengthBefore + 1 == array.length
  15038. if (lengthBefore + 1 == array.length) {
  15039. return true;// has right splice implementation without bugs
  15040. }
  15041. }()) {//IE 6/7
  15042. var array_splice = Array.prototype.splice;
  15043. Array.prototype.splice = function(start, deleteCount) {
  15044. if (!arguments.length) {
  15045. return [];
  15046. } else {
  15047. return array_splice.apply(this, [
  15048. start === void 0 ? 0 : start,
  15049. deleteCount === void 0 ? (this.length - start) : deleteCount
  15050. ].concat(slice.call(arguments, 2)))
  15051. }
  15052. };
  15053. } else {//IE8
  15054. Array.prototype.splice = function(pos, removeCount){
  15055. var length = this.length;
  15056. if (pos > 0) {
  15057. if (pos > length)
  15058. pos = length;
  15059. } else if (pos == void 0) {
  15060. pos = 0;
  15061. } else if (pos < 0) {
  15062. pos = Math.max(length + pos, 0);
  15063. }
  15064. if (!(pos+removeCount < length))
  15065. removeCount = length - pos;
  15066. var removed = this.slice(pos, pos+removeCount);
  15067. var insert = slice.call(arguments, 2);
  15068. var add = insert.length;
  15069. if (pos === length) {
  15070. if (add) {
  15071. this.push.apply(this, insert);
  15072. }
  15073. } else {
  15074. var remove = Math.min(removeCount, length - pos);
  15075. var tailOldPos = pos + remove;
  15076. var tailNewPos = tailOldPos + add - remove;
  15077. var tailCount = length - tailOldPos;
  15078. var lengthAfterRemove = length - remove;
  15079. if (tailNewPos < tailOldPos) { // case A
  15080. for (var i = 0; i < tailCount; ++i) {
  15081. this[tailNewPos+i] = this[tailOldPos+i];
  15082. }
  15083. } else if (tailNewPos > tailOldPos) { // case B
  15084. for (i = tailCount; i--; ) {
  15085. this[tailNewPos+i] = this[tailOldPos+i];
  15086. }
  15087. } // else, add == remove (nothing to do)
  15088. if (add && pos === lengthAfterRemove) {
  15089. this.length = lengthAfterRemove; // truncate array
  15090. this.push.apply(this, insert);
  15091. } else {
  15092. this.length = lengthAfterRemove + add; // reserves space
  15093. for (i = 0; i < add; ++i) {
  15094. this[pos+i] = insert[i];
  15095. }
  15096. }
  15097. }
  15098. return removed;
  15099. };
  15100. }
  15101. }
  15102. if (!Array.isArray) {
  15103. Array.isArray = function isArray(obj) {
  15104. return _toString(obj) == "[object Array]";
  15105. };
  15106. }
  15107. var boxedString = Object("a"),
  15108. splitString = boxedString[0] != "a" || !(0 in boxedString);
  15109. if (!Array.prototype.forEach) {
  15110. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  15111. var object = toObject(this),
  15112. self = splitString && _toString(this) == "[object String]" ?
  15113. this.split("") :
  15114. object,
  15115. thisp = arguments[1],
  15116. i = -1,
  15117. length = self.length >>> 0;
  15118. if (_toString(fun) != "[object Function]") {
  15119. throw new TypeError(); // TODO message
  15120. }
  15121. while (++i < length) {
  15122. if (i in self) {
  15123. fun.call(thisp, self[i], i, object);
  15124. }
  15125. }
  15126. };
  15127. }
  15128. if (!Array.prototype.map) {
  15129. Array.prototype.map = function map(fun /*, thisp*/) {
  15130. var object = toObject(this),
  15131. self = splitString && _toString(this) == "[object String]" ?
  15132. this.split("") :
  15133. object,
  15134. length = self.length >>> 0,
  15135. result = Array(length),
  15136. thisp = arguments[1];
  15137. if (_toString(fun) != "[object Function]") {
  15138. throw new TypeError(fun + " is not a function");
  15139. }
  15140. for (var i = 0; i < length; i++) {
  15141. if (i in self)
  15142. result[i] = fun.call(thisp, self[i], i, object);
  15143. }
  15144. return result;
  15145. };
  15146. }
  15147. if (!Array.prototype.filter) {
  15148. Array.prototype.filter = function filter(fun /*, thisp */) {
  15149. var object = toObject(this),
  15150. self = splitString && _toString(this) == "[object String]" ?
  15151. this.split("") :
  15152. object,
  15153. length = self.length >>> 0,
  15154. result = [],
  15155. value,
  15156. thisp = arguments[1];
  15157. if (_toString(fun) != "[object Function]") {
  15158. throw new TypeError(fun + " is not a function");
  15159. }
  15160. for (var i = 0; i < length; i++) {
  15161. if (i in self) {
  15162. value = self[i];
  15163. if (fun.call(thisp, value, i, object)) {
  15164. result.push(value);
  15165. }
  15166. }
  15167. }
  15168. return result;
  15169. };
  15170. }
  15171. if (!Array.prototype.every) {
  15172. Array.prototype.every = function every(fun /*, thisp */) {
  15173. var object = toObject(this),
  15174. self = splitString && _toString(this) == "[object String]" ?
  15175. this.split("") :
  15176. object,
  15177. length = self.length >>> 0,
  15178. thisp = arguments[1];
  15179. if (_toString(fun) != "[object Function]") {
  15180. throw new TypeError(fun + " is not a function");
  15181. }
  15182. for (var i = 0; i < length; i++) {
  15183. if (i in self && !fun.call(thisp, self[i], i, object)) {
  15184. return false;
  15185. }
  15186. }
  15187. return true;
  15188. };
  15189. }
  15190. if (!Array.prototype.some) {
  15191. Array.prototype.some = function some(fun /*, thisp */) {
  15192. var object = toObject(this),
  15193. self = splitString && _toString(this) == "[object String]" ?
  15194. this.split("") :
  15195. object,
  15196. length = self.length >>> 0,
  15197. thisp = arguments[1];
  15198. if (_toString(fun) != "[object Function]") {
  15199. throw new TypeError(fun + " is not a function");
  15200. }
  15201. for (var i = 0; i < length; i++) {
  15202. if (i in self && fun.call(thisp, self[i], i, object)) {
  15203. return true;
  15204. }
  15205. }
  15206. return false;
  15207. };
  15208. }
  15209. if (!Array.prototype.reduce) {
  15210. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  15211. var object = toObject(this),
  15212. self = splitString && _toString(this) == "[object String]" ?
  15213. this.split("") :
  15214. object,
  15215. length = self.length >>> 0;
  15216. if (_toString(fun) != "[object Function]") {
  15217. throw new TypeError(fun + " is not a function");
  15218. }
  15219. if (!length && arguments.length == 1) {
  15220. throw new TypeError("reduce of empty array with no initial value");
  15221. }
  15222. var i = 0;
  15223. var result;
  15224. if (arguments.length >= 2) {
  15225. result = arguments[1];
  15226. } else {
  15227. do {
  15228. if (i in self) {
  15229. result = self[i++];
  15230. break;
  15231. }
  15232. if (++i >= length) {
  15233. throw new TypeError("reduce of empty array with no initial value");
  15234. }
  15235. } while (true);
  15236. }
  15237. for (; i < length; i++) {
  15238. if (i in self) {
  15239. result = fun.call(void 0, result, self[i], i, object);
  15240. }
  15241. }
  15242. return result;
  15243. };
  15244. }
  15245. if (!Array.prototype.reduceRight) {
  15246. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  15247. var object = toObject(this),
  15248. self = splitString && _toString(this) == "[object String]" ?
  15249. this.split("") :
  15250. object,
  15251. length = self.length >>> 0;
  15252. if (_toString(fun) != "[object Function]") {
  15253. throw new TypeError(fun + " is not a function");
  15254. }
  15255. if (!length && arguments.length == 1) {
  15256. throw new TypeError("reduceRight of empty array with no initial value");
  15257. }
  15258. var result, i = length - 1;
  15259. if (arguments.length >= 2) {
  15260. result = arguments[1];
  15261. } else {
  15262. do {
  15263. if (i in self) {
  15264. result = self[i--];
  15265. break;
  15266. }
  15267. if (--i < 0) {
  15268. throw new TypeError("reduceRight of empty array with no initial value");
  15269. }
  15270. } while (true);
  15271. }
  15272. do {
  15273. if (i in this) {
  15274. result = fun.call(void 0, result, self[i], i, object);
  15275. }
  15276. } while (i--);
  15277. return result;
  15278. };
  15279. }
  15280. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  15281. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  15282. var self = splitString && _toString(this) == "[object String]" ?
  15283. this.split("") :
  15284. toObject(this),
  15285. length = self.length >>> 0;
  15286. if (!length) {
  15287. return -1;
  15288. }
  15289. var i = 0;
  15290. if (arguments.length > 1) {
  15291. i = toInteger(arguments[1]);
  15292. }
  15293. i = i >= 0 ? i : Math.max(0, length + i);
  15294. for (; i < length; i++) {
  15295. if (i in self && self[i] === sought) {
  15296. return i;
  15297. }
  15298. }
  15299. return -1;
  15300. };
  15301. }
  15302. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  15303. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  15304. var self = splitString && _toString(this) == "[object String]" ?
  15305. this.split("") :
  15306. toObject(this),
  15307. length = self.length >>> 0;
  15308. if (!length) {
  15309. return -1;
  15310. }
  15311. var i = length - 1;
  15312. if (arguments.length > 1) {
  15313. i = Math.min(i, toInteger(arguments[1]));
  15314. }
  15315. i = i >= 0 ? i : length - Math.abs(i);
  15316. for (; i >= 0; i--) {
  15317. if (i in self && sought === self[i]) {
  15318. return i;
  15319. }
  15320. }
  15321. return -1;
  15322. };
  15323. }
  15324. if (!Object.getPrototypeOf) {
  15325. Object.getPrototypeOf = function getPrototypeOf(object) {
  15326. return object.__proto__ || (
  15327. object.constructor ?
  15328. object.constructor.prototype :
  15329. prototypeOfObject
  15330. );
  15331. };
  15332. }
  15333. if (!Object.getOwnPropertyDescriptor) {
  15334. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  15335. "non-object: ";
  15336. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  15337. if ((typeof object != "object" && typeof object != "function") || object === null)
  15338. throw new TypeError(ERR_NON_OBJECT + object);
  15339. if (!owns(object, property))
  15340. return;
  15341. var descriptor, getter, setter;
  15342. descriptor = { enumerable: true, configurable: true };
  15343. if (supportsAccessors) {
  15344. var prototype = object.__proto__;
  15345. object.__proto__ = prototypeOfObject;
  15346. var getter = lookupGetter(object, property);
  15347. var setter = lookupSetter(object, property);
  15348. object.__proto__ = prototype;
  15349. if (getter || setter) {
  15350. if (getter) descriptor.get = getter;
  15351. if (setter) descriptor.set = setter;
  15352. return descriptor;
  15353. }
  15354. }
  15355. descriptor.value = object[property];
  15356. return descriptor;
  15357. };
  15358. }
  15359. if (!Object.getOwnPropertyNames) {
  15360. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  15361. return Object.keys(object);
  15362. };
  15363. }
  15364. if (!Object.create) {
  15365. var createEmpty;
  15366. if (Object.prototype.__proto__ === null) {
  15367. createEmpty = function () {
  15368. return { "__proto__": null };
  15369. };
  15370. } else {
  15371. createEmpty = function () {
  15372. var empty = {};
  15373. for (var i in empty)
  15374. empty[i] = null;
  15375. empty.constructor =
  15376. empty.hasOwnProperty =
  15377. empty.propertyIsEnumerable =
  15378. empty.isPrototypeOf =
  15379. empty.toLocaleString =
  15380. empty.toString =
  15381. empty.valueOf =
  15382. empty.__proto__ = null;
  15383. return empty;
  15384. }
  15385. }
  15386. Object.create = function create(prototype, properties) {
  15387. var object;
  15388. if (prototype === null) {
  15389. object = createEmpty();
  15390. } else {
  15391. if (typeof prototype != "object")
  15392. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  15393. var Type = function () {};
  15394. Type.prototype = prototype;
  15395. object = new Type();
  15396. object.__proto__ = prototype;
  15397. }
  15398. if (properties !== void 0)
  15399. Object.defineProperties(object, properties);
  15400. return object;
  15401. };
  15402. }
  15403. function doesDefinePropertyWork(object) {
  15404. try {
  15405. Object.defineProperty(object, "sentinel", {});
  15406. return "sentinel" in object;
  15407. } catch (exception) {
  15408. }
  15409. }
  15410. if (Object.defineProperty) {
  15411. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  15412. var definePropertyWorksOnDom = typeof document == "undefined" ||
  15413. doesDefinePropertyWork(document.createElement("div"));
  15414. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  15415. var definePropertyFallback = Object.defineProperty;
  15416. }
  15417. }
  15418. if (!Object.defineProperty || definePropertyFallback) {
  15419. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  15420. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  15421. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  15422. "on this javascript engine";
  15423. Object.defineProperty = function defineProperty(object, property, descriptor) {
  15424. if ((typeof object != "object" && typeof object != "function") || object === null)
  15425. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  15426. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  15427. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  15428. if (definePropertyFallback) {
  15429. try {
  15430. return definePropertyFallback.call(Object, object, property, descriptor);
  15431. } catch (exception) {
  15432. }
  15433. }
  15434. if (owns(descriptor, "value")) {
  15435. if (supportsAccessors && (lookupGetter(object, property) ||
  15436. lookupSetter(object, property)))
  15437. {
  15438. var prototype = object.__proto__;
  15439. object.__proto__ = prototypeOfObject;
  15440. delete object[property];
  15441. object[property] = descriptor.value;
  15442. object.__proto__ = prototype;
  15443. } else {
  15444. object[property] = descriptor.value;
  15445. }
  15446. } else {
  15447. if (!supportsAccessors)
  15448. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  15449. if (owns(descriptor, "get"))
  15450. defineGetter(object, property, descriptor.get);
  15451. if (owns(descriptor, "set"))
  15452. defineSetter(object, property, descriptor.set);
  15453. }
  15454. return object;
  15455. };
  15456. }
  15457. if (!Object.defineProperties) {
  15458. Object.defineProperties = function defineProperties(object, properties) {
  15459. for (var property in properties) {
  15460. if (owns(properties, property))
  15461. Object.defineProperty(object, property, properties[property]);
  15462. }
  15463. return object;
  15464. };
  15465. }
  15466. if (!Object.seal) {
  15467. Object.seal = function seal(object) {
  15468. return object;
  15469. };
  15470. }
  15471. if (!Object.freeze) {
  15472. Object.freeze = function freeze(object) {
  15473. return object;
  15474. };
  15475. }
  15476. try {
  15477. Object.freeze(function () {});
  15478. } catch (exception) {
  15479. Object.freeze = (function freeze(freezeObject) {
  15480. return function freeze(object) {
  15481. if (typeof object == "function") {
  15482. return object;
  15483. } else {
  15484. return freezeObject(object);
  15485. }
  15486. };
  15487. })(Object.freeze);
  15488. }
  15489. if (!Object.preventExtensions) {
  15490. Object.preventExtensions = function preventExtensions(object) {
  15491. return object;
  15492. };
  15493. }
  15494. if (!Object.isSealed) {
  15495. Object.isSealed = function isSealed(object) {
  15496. return false;
  15497. };
  15498. }
  15499. if (!Object.isFrozen) {
  15500. Object.isFrozen = function isFrozen(object) {
  15501. return false;
  15502. };
  15503. }
  15504. if (!Object.isExtensible) {
  15505. Object.isExtensible = function isExtensible(object) {
  15506. if (Object(object) === object) {
  15507. throw new TypeError(); // TODO message
  15508. }
  15509. var name = '';
  15510. while (owns(object, name)) {
  15511. name += '?';
  15512. }
  15513. object[name] = true;
  15514. var returnValue = owns(object, name);
  15515. delete object[name];
  15516. return returnValue;
  15517. };
  15518. }
  15519. if (!Object.keys) {
  15520. var hasDontEnumBug = true,
  15521. dontEnums = [
  15522. "toString",
  15523. "toLocaleString",
  15524. "valueOf",
  15525. "hasOwnProperty",
  15526. "isPrototypeOf",
  15527. "propertyIsEnumerable",
  15528. "constructor"
  15529. ],
  15530. dontEnumsLength = dontEnums.length;
  15531. for (var key in {"toString": null}) {
  15532. hasDontEnumBug = false;
  15533. }
  15534. Object.keys = function keys(object) {
  15535. if (
  15536. (typeof object != "object" && typeof object != "function") ||
  15537. object === null
  15538. ) {
  15539. throw new TypeError("Object.keys called on a non-object");
  15540. }
  15541. var keys = [];
  15542. for (var name in object) {
  15543. if (owns(object, name)) {
  15544. keys.push(name);
  15545. }
  15546. }
  15547. if (hasDontEnumBug) {
  15548. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  15549. var dontEnum = dontEnums[i];
  15550. if (owns(object, dontEnum)) {
  15551. keys.push(dontEnum);
  15552. }
  15553. }
  15554. }
  15555. return keys;
  15556. };
  15557. }
  15558. if (!Date.now) {
  15559. Date.now = function now() {
  15560. return new Date().getTime();
  15561. };
  15562. }
  15563. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  15564. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  15565. "\u2029\uFEFF";
  15566. if (!String.prototype.trim || ws.trim()) {
  15567. ws = "[" + ws + "]";
  15568. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  15569. trimEndRegexp = new RegExp(ws + ws + "*$");
  15570. String.prototype.trim = function trim() {
  15571. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  15572. };
  15573. }
  15574. function toInteger(n) {
  15575. n = +n;
  15576. if (n !== n) { // isNaN
  15577. n = 0;
  15578. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  15579. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  15580. }
  15581. return n;
  15582. }
  15583. function isPrimitive(input) {
  15584. var type = typeof input;
  15585. return (
  15586. input === null ||
  15587. type === "undefined" ||
  15588. type === "boolean" ||
  15589. type === "number" ||
  15590. type === "string"
  15591. );
  15592. }
  15593. function toPrimitive(input) {
  15594. var val, valueOf, toString;
  15595. if (isPrimitive(input)) {
  15596. return input;
  15597. }
  15598. valueOf = input.valueOf;
  15599. if (typeof valueOf === "function") {
  15600. val = valueOf.call(input);
  15601. if (isPrimitive(val)) {
  15602. return val;
  15603. }
  15604. }
  15605. toString = input.toString;
  15606. if (typeof toString === "function") {
  15607. val = toString.call(input);
  15608. if (isPrimitive(val)) {
  15609. return val;
  15610. }
  15611. }
  15612. throw new TypeError();
  15613. }
  15614. var toObject = function (o) {
  15615. if (o == null) { // this matches both null and undefined
  15616. throw new TypeError("can't convert "+o+" to object");
  15617. }
  15618. return Object(o);
  15619. };
  15620. });
  15621. ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(acequire, exports, module) {
  15622. "use strict";
  15623. acequire("./regexp");
  15624. acequire("./es5-shim");
  15625. });
  15626. ace.define("ace/lib/dom",["require","exports","module"], function(acequire, exports, module) {
  15627. "use strict";
  15628. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  15629. exports.getDocumentHead = function(doc) {
  15630. if (!doc)
  15631. doc = document;
  15632. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  15633. };
  15634. exports.createElement = function(tag, ns) {
  15635. return document.createElementNS ?
  15636. document.createElementNS(ns || XHTML_NS, tag) :
  15637. document.createElement(tag);
  15638. };
  15639. exports.hasCssClass = function(el, name) {
  15640. var classes = (el.className || "").split(/\s+/g);
  15641. return classes.indexOf(name) !== -1;
  15642. };
  15643. exports.addCssClass = function(el, name) {
  15644. if (!exports.hasCssClass(el, name)) {
  15645. el.className += " " + name;
  15646. }
  15647. };
  15648. exports.removeCssClass = function(el, name) {
  15649. var classes = el.className.split(/\s+/g);
  15650. while (true) {
  15651. var index = classes.indexOf(name);
  15652. if (index == -1) {
  15653. break;
  15654. }
  15655. classes.splice(index, 1);
  15656. }
  15657. el.className = classes.join(" ");
  15658. };
  15659. exports.toggleCssClass = function(el, name) {
  15660. var classes = el.className.split(/\s+/g), add = true;
  15661. while (true) {
  15662. var index = classes.indexOf(name);
  15663. if (index == -1) {
  15664. break;
  15665. }
  15666. add = false;
  15667. classes.splice(index, 1);
  15668. }
  15669. if (add)
  15670. classes.push(name);
  15671. el.className = classes.join(" ");
  15672. return add;
  15673. };
  15674. exports.setCssClass = function(node, className, include) {
  15675. if (include) {
  15676. exports.addCssClass(node, className);
  15677. } else {
  15678. exports.removeCssClass(node, className);
  15679. }
  15680. };
  15681. exports.hasCssString = function(id, doc) {
  15682. var index = 0, sheets;
  15683. doc = doc || document;
  15684. if (doc.createStyleSheet && (sheets = doc.styleSheets)) {
  15685. while (index < sheets.length)
  15686. if (sheets[index++].owningElement.id === id) return true;
  15687. } else if ((sheets = doc.getElementsByTagName("style"))) {
  15688. while (index < sheets.length)
  15689. if (sheets[index++].id === id) return true;
  15690. }
  15691. return false;
  15692. };
  15693. exports.importCssString = function importCssString(cssText, id, doc) {
  15694. doc = doc || document;
  15695. if (id && exports.hasCssString(id, doc))
  15696. return null;
  15697. var style;
  15698. if (id)
  15699. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  15700. if (doc.createStyleSheet) {
  15701. style = doc.createStyleSheet();
  15702. style.cssText = cssText;
  15703. if (id)
  15704. style.owningElement.id = id;
  15705. } else {
  15706. style = exports.createElement("style");
  15707. style.appendChild(doc.createTextNode(cssText));
  15708. if (id)
  15709. style.id = id;
  15710. exports.getDocumentHead(doc).appendChild(style);
  15711. }
  15712. };
  15713. exports.importCssStylsheet = function(uri, doc) {
  15714. if (doc.createStyleSheet) {
  15715. doc.createStyleSheet(uri);
  15716. } else {
  15717. var link = exports.createElement('link');
  15718. link.rel = 'stylesheet';
  15719. link.href = uri;
  15720. exports.getDocumentHead(doc).appendChild(link);
  15721. }
  15722. };
  15723. exports.getInnerWidth = function(element) {
  15724. return (
  15725. parseInt(exports.computedStyle(element, "paddingLeft"), 10) +
  15726. parseInt(exports.computedStyle(element, "paddingRight"), 10) +
  15727. element.clientWidth
  15728. );
  15729. };
  15730. exports.getInnerHeight = function(element) {
  15731. return (
  15732. parseInt(exports.computedStyle(element, "paddingTop"), 10) +
  15733. parseInt(exports.computedStyle(element, "paddingBottom"), 10) +
  15734. element.clientHeight
  15735. );
  15736. };
  15737. exports.scrollbarWidth = function(document) {
  15738. var inner = exports.createElement("ace_inner");
  15739. inner.style.width = "100%";
  15740. inner.style.minWidth = "0px";
  15741. inner.style.height = "200px";
  15742. inner.style.display = "block";
  15743. var outer = exports.createElement("ace_outer");
  15744. var style = outer.style;
  15745. style.position = "absolute";
  15746. style.left = "-10000px";
  15747. style.overflow = "hidden";
  15748. style.width = "200px";
  15749. style.minWidth = "0px";
  15750. style.height = "150px";
  15751. style.display = "block";
  15752. outer.appendChild(inner);
  15753. var body = document.documentElement;
  15754. body.appendChild(outer);
  15755. var noScrollbar = inner.offsetWidth;
  15756. style.overflow = "scroll";
  15757. var withScrollbar = inner.offsetWidth;
  15758. if (noScrollbar == withScrollbar) {
  15759. withScrollbar = outer.clientWidth;
  15760. }
  15761. body.removeChild(outer);
  15762. return noScrollbar-withScrollbar;
  15763. };
  15764. if (typeof document == "undefined") {
  15765. exports.importCssString = function() {};
  15766. return;
  15767. }
  15768. if (window.pageYOffset !== undefined) {
  15769. exports.getPageScrollTop = function() {
  15770. return window.pageYOffset;
  15771. };
  15772. exports.getPageScrollLeft = function() {
  15773. return window.pageXOffset;
  15774. };
  15775. }
  15776. else {
  15777. exports.getPageScrollTop = function() {
  15778. return document.body.scrollTop;
  15779. };
  15780. exports.getPageScrollLeft = function() {
  15781. return document.body.scrollLeft;
  15782. };
  15783. }
  15784. if (window.getComputedStyle)
  15785. exports.computedStyle = function(element, style) {
  15786. if (style)
  15787. return (window.getComputedStyle(element, "") || {})[style] || "";
  15788. return window.getComputedStyle(element, "") || {};
  15789. };
  15790. else
  15791. exports.computedStyle = function(element, style) {
  15792. if (style)
  15793. return element.currentStyle[style];
  15794. return element.currentStyle;
  15795. };
  15796. exports.setInnerHtml = function(el, innerHtml) {
  15797. var element = el.cloneNode(false);//document.createElement("div");
  15798. element.innerHTML = innerHtml;
  15799. el.parentNode.replaceChild(element, el);
  15800. return element;
  15801. };
  15802. if ("textContent" in document.documentElement) {
  15803. exports.setInnerText = function(el, innerText) {
  15804. el.textContent = innerText;
  15805. };
  15806. exports.getInnerText = function(el) {
  15807. return el.textContent;
  15808. };
  15809. }
  15810. else {
  15811. exports.setInnerText = function(el, innerText) {
  15812. el.innerText = innerText;
  15813. };
  15814. exports.getInnerText = function(el) {
  15815. return el.innerText;
  15816. };
  15817. }
  15818. exports.getParentWindow = function(document) {
  15819. return document.defaultView || document.parentWindow;
  15820. };
  15821. });
  15822. ace.define("ace/lib/oop",["require","exports","module"], function(acequire, exports, module) {
  15823. "use strict";
  15824. exports.inherits = function(ctor, superCtor) {
  15825. ctor.super_ = superCtor;
  15826. ctor.prototype = Object.create(superCtor.prototype, {
  15827. constructor: {
  15828. value: ctor,
  15829. enumerable: false,
  15830. writable: true,
  15831. configurable: true
  15832. }
  15833. });
  15834. };
  15835. exports.mixin = function(obj, mixin) {
  15836. for (var key in mixin) {
  15837. obj[key] = mixin[key];
  15838. }
  15839. return obj;
  15840. };
  15841. exports.implement = function(proto, mixin) {
  15842. exports.mixin(proto, mixin);
  15843. };
  15844. });
  15845. ace.define("ace/lib/keys",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop"], function(acequire, exports, module) {
  15846. "use strict";
  15847. acequire("./fixoldbrowsers");
  15848. var oop = acequire("./oop");
  15849. var Keys = (function() {
  15850. var ret = {
  15851. MODIFIER_KEYS: {
  15852. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  15853. },
  15854. KEY_MODS: {
  15855. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  15856. "super": 8, "meta": 8, "command": 8, "cmd": 8
  15857. },
  15858. FUNCTION_KEYS : {
  15859. 8 : "Backspace",
  15860. 9 : "Tab",
  15861. 13 : "Return",
  15862. 19 : "Pause",
  15863. 27 : "Esc",
  15864. 32 : "Space",
  15865. 33 : "PageUp",
  15866. 34 : "PageDown",
  15867. 35 : "End",
  15868. 36 : "Home",
  15869. 37 : "Left",
  15870. 38 : "Up",
  15871. 39 : "Right",
  15872. 40 : "Down",
  15873. 44 : "Print",
  15874. 45 : "Insert",
  15875. 46 : "Delete",
  15876. 96 : "Numpad0",
  15877. 97 : "Numpad1",
  15878. 98 : "Numpad2",
  15879. 99 : "Numpad3",
  15880. 100: "Numpad4",
  15881. 101: "Numpad5",
  15882. 102: "Numpad6",
  15883. 103: "Numpad7",
  15884. 104: "Numpad8",
  15885. 105: "Numpad9",
  15886. '-13': "NumpadEnter",
  15887. 112: "F1",
  15888. 113: "F2",
  15889. 114: "F3",
  15890. 115: "F4",
  15891. 116: "F5",
  15892. 117: "F6",
  15893. 118: "F7",
  15894. 119: "F8",
  15895. 120: "F9",
  15896. 121: "F10",
  15897. 122: "F11",
  15898. 123: "F12",
  15899. 144: "Numlock",
  15900. 145: "Scrolllock"
  15901. },
  15902. PRINTABLE_KEYS: {
  15903. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  15904. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  15905. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  15906. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  15907. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  15908. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  15909. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  15910. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  15911. }
  15912. };
  15913. var name, i;
  15914. for (i in ret.FUNCTION_KEYS) {
  15915. name = ret.FUNCTION_KEYS[i].toLowerCase();
  15916. ret[name] = parseInt(i, 10);
  15917. }
  15918. for (i in ret.PRINTABLE_KEYS) {
  15919. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  15920. ret[name] = parseInt(i, 10);
  15921. }
  15922. oop.mixin(ret, ret.MODIFIER_KEYS);
  15923. oop.mixin(ret, ret.PRINTABLE_KEYS);
  15924. oop.mixin(ret, ret.FUNCTION_KEYS);
  15925. ret.enter = ret["return"];
  15926. ret.escape = ret.esc;
  15927. ret.del = ret["delete"];
  15928. ret[173] = '-';
  15929. (function() {
  15930. var mods = ["cmd", "ctrl", "alt", "shift"];
  15931. for (var i = Math.pow(2, mods.length); i--;) {
  15932. ret.KEY_MODS[i] = mods.filter(function(x) {
  15933. return i & ret.KEY_MODS[x];
  15934. }).join("-") + "-";
  15935. }
  15936. })();
  15937. ret.KEY_MODS[0] = "";
  15938. ret.KEY_MODS[-1] = "input-";
  15939. return ret;
  15940. })();
  15941. oop.mixin(exports, Keys);
  15942. exports.keyCodeToString = function(keyCode) {
  15943. var keyString = Keys[keyCode];
  15944. if (typeof keyString != "string")
  15945. keyString = String.fromCharCode(keyCode);
  15946. return keyString.toLowerCase();
  15947. };
  15948. });
  15949. ace.define("ace/lib/useragent",["require","exports","module"], function(acequire, exports, module) {
  15950. "use strict";
  15951. exports.OS = {
  15952. LINUX: "LINUX",
  15953. MAC: "MAC",
  15954. WINDOWS: "WINDOWS"
  15955. };
  15956. exports.getOS = function() {
  15957. if (exports.isMac) {
  15958. return exports.OS.MAC;
  15959. } else if (exports.isLinux) {
  15960. return exports.OS.LINUX;
  15961. } else {
  15962. return exports.OS.WINDOWS;
  15963. }
  15964. };
  15965. if (typeof navigator != "object")
  15966. return;
  15967. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  15968. var ua = navigator.userAgent;
  15969. exports.isWin = (os == "win");
  15970. exports.isMac = (os == "mac");
  15971. exports.isLinux = (os == "linux");
  15972. exports.isIE =
  15973. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  15974. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  15975. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  15976. exports.isOldIE = exports.isIE && exports.isIE < 9;
  15977. exports.isGecko = exports.isMozilla = (window.Controllers || window.controllers) && window.navigator.product === "Gecko";
  15978. exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv\:(\d+)/)||[])[1], 10) < 4;
  15979. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  15980. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  15981. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  15982. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  15983. exports.isIPad = ua.indexOf("iPad") >= 0;
  15984. exports.isTouchPad = ua.indexOf("TouchPad") >= 0;
  15985. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  15986. });
  15987. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(acequire, exports, module) {
  15988. "use strict";
  15989. var keys = acequire("./keys");
  15990. var useragent = acequire("./useragent");
  15991. var pressedKeys = null;
  15992. var ts = 0;
  15993. exports.addListener = function(elem, type, callback) {
  15994. if (elem.addEventListener) {
  15995. return elem.addEventListener(type, callback, false);
  15996. }
  15997. if (elem.attachEvent) {
  15998. var wrapper = function() {
  15999. callback.call(elem, window.event);
  16000. };
  16001. callback._wrapper = wrapper;
  16002. elem.attachEvent("on" + type, wrapper);
  16003. }
  16004. };
  16005. exports.removeListener = function(elem, type, callback) {
  16006. if (elem.removeEventListener) {
  16007. return elem.removeEventListener(type, callback, false);
  16008. }
  16009. if (elem.detachEvent) {
  16010. elem.detachEvent("on" + type, callback._wrapper || callback);
  16011. }
  16012. };
  16013. exports.stopEvent = function(e) {
  16014. exports.stopPropagation(e);
  16015. exports.preventDefault(e);
  16016. return false;
  16017. };
  16018. exports.stopPropagation = function(e) {
  16019. if (e.stopPropagation)
  16020. e.stopPropagation();
  16021. else
  16022. e.cancelBubble = true;
  16023. };
  16024. exports.preventDefault = function(e) {
  16025. if (e.preventDefault)
  16026. e.preventDefault();
  16027. else
  16028. e.returnValue = false;
  16029. };
  16030. exports.getButton = function(e) {
  16031. if (e.type == "dblclick")
  16032. return 0;
  16033. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  16034. return 2;
  16035. if (e.preventDefault) {
  16036. return e.button;
  16037. }
  16038. else {
  16039. return {1:0, 2:2, 4:1}[e.button];
  16040. }
  16041. };
  16042. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  16043. function onMouseUp(e) {
  16044. eventHandler && eventHandler(e);
  16045. releaseCaptureHandler && releaseCaptureHandler(e);
  16046. exports.removeListener(document, "mousemove", eventHandler, true);
  16047. exports.removeListener(document, "mouseup", onMouseUp, true);
  16048. exports.removeListener(document, "dragstart", onMouseUp, true);
  16049. }
  16050. exports.addListener(document, "mousemove", eventHandler, true);
  16051. exports.addListener(document, "mouseup", onMouseUp, true);
  16052. exports.addListener(document, "dragstart", onMouseUp, true);
  16053. return onMouseUp;
  16054. };
  16055. exports.addTouchMoveListener = function (el, callback) {
  16056. if ("ontouchmove" in el) {
  16057. var startx, starty;
  16058. exports.addListener(el, "touchstart", function (e) {
  16059. var touchObj = e.changedTouches[0];
  16060. startx = touchObj.clientX;
  16061. starty = touchObj.clientY;
  16062. });
  16063. exports.addListener(el, "touchmove", function (e) {
  16064. var factor = 1,
  16065. touchObj = e.changedTouches[0];
  16066. e.wheelX = -(touchObj.clientX - startx) / factor;
  16067. e.wheelY = -(touchObj.clientY - starty) / factor;
  16068. startx = touchObj.clientX;
  16069. starty = touchObj.clientY;
  16070. callback(e);
  16071. });
  16072. }
  16073. };
  16074. exports.addMouseWheelListener = function(el, callback) {
  16075. if ("onmousewheel" in el) {
  16076. exports.addListener(el, "mousewheel", function(e) {
  16077. var factor = 8;
  16078. if (e.wheelDeltaX !== undefined) {
  16079. e.wheelX = -e.wheelDeltaX / factor;
  16080. e.wheelY = -e.wheelDeltaY / factor;
  16081. } else {
  16082. e.wheelX = 0;
  16083. e.wheelY = -e.wheelDelta / factor;
  16084. }
  16085. callback(e);
  16086. });
  16087. } else if ("onwheel" in el) {
  16088. exports.addListener(el, "wheel", function(e) {
  16089. var factor = 0.35;
  16090. switch (e.deltaMode) {
  16091. case e.DOM_DELTA_PIXEL:
  16092. e.wheelX = e.deltaX * factor || 0;
  16093. e.wheelY = e.deltaY * factor || 0;
  16094. break;
  16095. case e.DOM_DELTA_LINE:
  16096. case e.DOM_DELTA_PAGE:
  16097. e.wheelX = (e.deltaX || 0) * 5;
  16098. e.wheelY = (e.deltaY || 0) * 5;
  16099. break;
  16100. }
  16101. callback(e);
  16102. });
  16103. } else {
  16104. exports.addListener(el, "DOMMouseScroll", function(e) {
  16105. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  16106. e.wheelX = (e.detail || 0) * 5;
  16107. e.wheelY = 0;
  16108. } else {
  16109. e.wheelX = 0;
  16110. e.wheelY = (e.detail || 0) * 5;
  16111. }
  16112. callback(e);
  16113. });
  16114. }
  16115. };
  16116. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  16117. var clicks = 0;
  16118. var startX, startY, timer;
  16119. var eventNames = {
  16120. 2: "dblclick",
  16121. 3: "tripleclick",
  16122. 4: "quadclick"
  16123. };
  16124. function onMousedown(e) {
  16125. if (exports.getButton(e) !== 0) {
  16126. clicks = 0;
  16127. } else if (e.detail > 1) {
  16128. clicks++;
  16129. if (clicks > 4)
  16130. clicks = 1;
  16131. } else {
  16132. clicks = 1;
  16133. }
  16134. if (useragent.isIE) {
  16135. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  16136. if (!timer || isNewClick)
  16137. clicks = 1;
  16138. if (timer)
  16139. clearTimeout(timer);
  16140. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  16141. if (clicks == 1) {
  16142. startX = e.clientX;
  16143. startY = e.clientY;
  16144. }
  16145. }
  16146. e._clicks = clicks;
  16147. eventHandler[callbackName]("mousedown", e);
  16148. if (clicks > 4)
  16149. clicks = 0;
  16150. else if (clicks > 1)
  16151. return eventHandler[callbackName](eventNames[clicks], e);
  16152. }
  16153. function onDblclick(e) {
  16154. clicks = 2;
  16155. if (timer)
  16156. clearTimeout(timer);
  16157. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  16158. eventHandler[callbackName]("mousedown", e);
  16159. eventHandler[callbackName](eventNames[clicks], e);
  16160. }
  16161. if (!Array.isArray(elements))
  16162. elements = [elements];
  16163. elements.forEach(function(el) {
  16164. exports.addListener(el, "mousedown", onMousedown);
  16165. if (useragent.isOldIE)
  16166. exports.addListener(el, "dblclick", onDblclick);
  16167. });
  16168. };
  16169. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  16170. ? function(e) {
  16171. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  16172. }
  16173. : function(e) {
  16174. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  16175. };
  16176. exports.getModifierString = function(e) {
  16177. return keys.KEY_MODS[getModifierHash(e)];
  16178. };
  16179. function normalizeCommandKeys(callback, e, keyCode) {
  16180. var hashId = getModifierHash(e);
  16181. if (!useragent.isMac && pressedKeys) {
  16182. if (pressedKeys.OSKey)
  16183. hashId |= 8;
  16184. if (pressedKeys.altGr) {
  16185. if ((3 & hashId) != 3)
  16186. pressedKeys.altGr = 0;
  16187. else
  16188. return;
  16189. }
  16190. if (keyCode === 18 || keyCode === 17) {
  16191. var location = "location" in e ? e.location : e.keyLocation;
  16192. if (keyCode === 17 && location === 1) {
  16193. if (pressedKeys[keyCode] == 1)
  16194. ts = e.timeStamp;
  16195. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  16196. var dt = e.timeStamp - ts;
  16197. if (dt < 50)
  16198. pressedKeys.altGr = true;
  16199. }
  16200. }
  16201. }
  16202. if (keyCode in keys.MODIFIER_KEYS) {
  16203. keyCode = -1;
  16204. }
  16205. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  16206. keyCode = -1;
  16207. }
  16208. if (!hashId && keyCode === 13) {
  16209. var location = "location" in e ? e.location : e.keyLocation;
  16210. if (location === 3) {
  16211. callback(e, hashId, -keyCode);
  16212. if (e.defaultPrevented)
  16213. return;
  16214. }
  16215. }
  16216. if (useragent.isChromeOS && hashId & 8) {
  16217. callback(e, hashId, keyCode);
  16218. if (e.defaultPrevented)
  16219. return;
  16220. else
  16221. hashId &= ~8;
  16222. }
  16223. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  16224. return false;
  16225. }
  16226. return callback(e, hashId, keyCode);
  16227. }
  16228. exports.addCommandKeyListener = function(el, callback) {
  16229. var addListener = exports.addListener;
  16230. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  16231. var lastKeyDownKeyCode = null;
  16232. addListener(el, "keydown", function(e) {
  16233. lastKeyDownKeyCode = e.keyCode;
  16234. });
  16235. addListener(el, "keypress", function(e) {
  16236. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  16237. });
  16238. } else {
  16239. var lastDefaultPrevented = null;
  16240. addListener(el, "keydown", function(e) {
  16241. var keyCode = e.keyCode;
  16242. pressedKeys[keyCode] = (pressedKeys[keyCode] || 0) + 1;
  16243. if (keyCode == 91 || keyCode == 92) {
  16244. pressedKeys.OSKey = true;
  16245. } else if (pressedKeys.OSKey) {
  16246. if (e.timeStamp - pressedKeys.lastT > 200 && pressedKeys.count == 1)
  16247. resetPressedKeys();
  16248. }
  16249. if (pressedKeys[keyCode] == 1)
  16250. pressedKeys.count++;
  16251. pressedKeys.lastT = e.timeStamp;
  16252. var result = normalizeCommandKeys(callback, e, keyCode);
  16253. lastDefaultPrevented = e.defaultPrevented;
  16254. return result;
  16255. });
  16256. addListener(el, "keypress", function(e) {
  16257. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  16258. exports.stopEvent(e);
  16259. lastDefaultPrevented = null;
  16260. }
  16261. });
  16262. addListener(el, "keyup", function(e) {
  16263. var keyCode = e.keyCode;
  16264. if (!pressedKeys[keyCode]) {
  16265. resetPressedKeys();
  16266. } else {
  16267. pressedKeys.count = Math.max(pressedKeys.count - 1, 0);
  16268. }
  16269. if (keyCode == 91 || keyCode == 92) {
  16270. pressedKeys.OSKey = false;
  16271. }
  16272. pressedKeys[keyCode] = null;
  16273. });
  16274. if (!pressedKeys) {
  16275. resetPressedKeys();
  16276. addListener(window, "focus", resetPressedKeys);
  16277. }
  16278. }
  16279. };
  16280. function resetPressedKeys() {
  16281. pressedKeys = Object.create(null);
  16282. pressedKeys.count = 0;
  16283. pressedKeys.lastT = 0;
  16284. }
  16285. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  16286. var postMessageId = 1;
  16287. exports.nextTick = function(callback, win) {
  16288. win = win || window;
  16289. var messageName = "zero-timeout-message-" + postMessageId;
  16290. exports.addListener(win, "message", function listener(e) {
  16291. if (e.data == messageName) {
  16292. exports.stopPropagation(e);
  16293. exports.removeListener(win, "message", listener);
  16294. callback();
  16295. }
  16296. });
  16297. win.postMessage(messageName, "*");
  16298. };
  16299. }
  16300. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  16301. || window.mozRequestAnimationFrame
  16302. || window.webkitRequestAnimationFrame
  16303. || window.msRequestAnimationFrame
  16304. || window.oRequestAnimationFrame);
  16305. if (exports.nextFrame)
  16306. exports.nextFrame = exports.nextFrame.bind(window);
  16307. else
  16308. exports.nextFrame = function(callback) {
  16309. setTimeout(callback, 17);
  16310. };
  16311. });
  16312. ace.define("ace/lib/lang",["require","exports","module"], function(acequire, exports, module) {
  16313. "use strict";
  16314. exports.last = function(a) {
  16315. return a[a.length - 1];
  16316. };
  16317. exports.stringReverse = function(string) {
  16318. return string.split("").reverse().join("");
  16319. };
  16320. exports.stringRepeat = function (string, count) {
  16321. var result = '';
  16322. while (count > 0) {
  16323. if (count & 1)
  16324. result += string;
  16325. if (count >>= 1)
  16326. string += string;
  16327. }
  16328. return result;
  16329. };
  16330. var trimBeginRegexp = /^\s\s*/;
  16331. var trimEndRegexp = /\s\s*$/;
  16332. exports.stringTrimLeft = function (string) {
  16333. return string.replace(trimBeginRegexp, '');
  16334. };
  16335. exports.stringTrimRight = function (string) {
  16336. return string.replace(trimEndRegexp, '');
  16337. };
  16338. exports.copyObject = function(obj) {
  16339. var copy = {};
  16340. for (var key in obj) {
  16341. copy[key] = obj[key];
  16342. }
  16343. return copy;
  16344. };
  16345. exports.copyArray = function(array){
  16346. var copy = [];
  16347. for (var i=0, l=array.length; i<l; i++) {
  16348. if (array[i] && typeof array[i] == "object")
  16349. copy[i] = this.copyObject( array[i] );
  16350. else
  16351. copy[i] = array[i];
  16352. }
  16353. return copy;
  16354. };
  16355. exports.deepCopy = function deepCopy(obj) {
  16356. if (typeof obj !== "object" || !obj)
  16357. return obj;
  16358. var copy;
  16359. if (Array.isArray(obj)) {
  16360. copy = [];
  16361. for (var key = 0; key < obj.length; key++) {
  16362. copy[key] = deepCopy(obj[key]);
  16363. }
  16364. return copy;
  16365. }
  16366. var cons = obj.constructor;
  16367. if (cons === RegExp)
  16368. return obj;
  16369. copy = cons();
  16370. for (var key in obj) {
  16371. copy[key] = deepCopy(obj[key]);
  16372. }
  16373. return copy;
  16374. };
  16375. exports.arrayToMap = function(arr) {
  16376. var map = {};
  16377. for (var i=0; i<arr.length; i++) {
  16378. map[arr[i]] = 1;
  16379. }
  16380. return map;
  16381. };
  16382. exports.createMap = function(props) {
  16383. var map = Object.create(null);
  16384. for (var i in props) {
  16385. map[i] = props[i];
  16386. }
  16387. return map;
  16388. };
  16389. exports.arrayRemove = function(array, value) {
  16390. for (var i = 0; i <= array.length; i++) {
  16391. if (value === array[i]) {
  16392. array.splice(i, 1);
  16393. }
  16394. }
  16395. };
  16396. exports.escapeRegExp = function(str) {
  16397. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  16398. };
  16399. exports.escapeHTML = function(str) {
  16400. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  16401. };
  16402. exports.getMatchOffsets = function(string, regExp) {
  16403. var matches = [];
  16404. string.replace(regExp, function(str) {
  16405. matches.push({
  16406. offset: arguments[arguments.length-2],
  16407. length: str.length
  16408. });
  16409. });
  16410. return matches;
  16411. };
  16412. exports.deferredCall = function(fcn) {
  16413. var timer = null;
  16414. var callback = function() {
  16415. timer = null;
  16416. fcn();
  16417. };
  16418. var deferred = function(timeout) {
  16419. deferred.cancel();
  16420. timer = setTimeout(callback, timeout || 0);
  16421. return deferred;
  16422. };
  16423. deferred.schedule = deferred;
  16424. deferred.call = function() {
  16425. this.cancel();
  16426. fcn();
  16427. return deferred;
  16428. };
  16429. deferred.cancel = function() {
  16430. clearTimeout(timer);
  16431. timer = null;
  16432. return deferred;
  16433. };
  16434. deferred.isPending = function() {
  16435. return timer;
  16436. };
  16437. return deferred;
  16438. };
  16439. exports.delayedCall = function(fcn, defaultTimeout) {
  16440. var timer = null;
  16441. var callback = function() {
  16442. timer = null;
  16443. fcn();
  16444. };
  16445. var _self = function(timeout) {
  16446. if (timer == null)
  16447. timer = setTimeout(callback, timeout || defaultTimeout);
  16448. };
  16449. _self.delay = function(timeout) {
  16450. timer && clearTimeout(timer);
  16451. timer = setTimeout(callback, timeout || defaultTimeout);
  16452. };
  16453. _self.schedule = _self;
  16454. _self.call = function() {
  16455. this.cancel();
  16456. fcn();
  16457. };
  16458. _self.cancel = function() {
  16459. timer && clearTimeout(timer);
  16460. timer = null;
  16461. };
  16462. _self.isPending = function() {
  16463. return timer;
  16464. };
  16465. return _self;
  16466. };
  16467. });
  16468. ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang"], function(acequire, exports, module) {
  16469. "use strict";
  16470. var event = acequire("../lib/event");
  16471. var useragent = acequire("../lib/useragent");
  16472. var dom = acequire("../lib/dom");
  16473. var lang = acequire("../lib/lang");
  16474. var BROKEN_SETDATA = useragent.isChrome < 18;
  16475. var USE_IE_MIME_TYPE = useragent.isIE;
  16476. var TextInput = function(parentNode, host) {
  16477. var text = dom.createElement("textarea");
  16478. text.className = "ace_text-input";
  16479. if (useragent.isTouchPad)
  16480. text.setAttribute("x-palm-disable-auto-cap", true);
  16481. text.setAttribute("wrap", "off");
  16482. text.setAttribute("autocorrect", "off");
  16483. text.setAttribute("autocapitalize", "off");
  16484. text.setAttribute("spellcheck", false);
  16485. text.style.opacity = "0";
  16486. if (useragent.isOldIE) text.style.top = "-1000px";
  16487. parentNode.insertBefore(text, parentNode.firstChild);
  16488. var PLACEHOLDER = "\x01\x01";
  16489. var copied = false;
  16490. var pasted = false;
  16491. var inComposition = false;
  16492. var tempStyle = '';
  16493. var isSelectionEmpty = true;
  16494. try { var isFocused = document.activeElement === text; } catch(e) {}
  16495. event.addListener(text, "blur", function(e) {
  16496. host.onBlur(e);
  16497. isFocused = false;
  16498. });
  16499. event.addListener(text, "focus", function(e) {
  16500. isFocused = true;
  16501. host.onFocus(e);
  16502. resetSelection();
  16503. });
  16504. this.focus = function() {
  16505. if (tempStyle) return text.focus();
  16506. var top = text.style.top;
  16507. text.style.position = "fixed";
  16508. text.style.top = "0px";
  16509. text.focus();
  16510. setTimeout(function() {
  16511. text.style.position = "";
  16512. if (text.style.top == "0px")
  16513. text.style.top = top;
  16514. }, 0);
  16515. };
  16516. this.blur = function() {
  16517. text.blur();
  16518. };
  16519. this.isFocused = function() {
  16520. return isFocused;
  16521. };
  16522. var syncSelection = lang.delayedCall(function() {
  16523. isFocused && resetSelection(isSelectionEmpty);
  16524. });
  16525. var syncValue = lang.delayedCall(function() {
  16526. if (!inComposition) {
  16527. text.value = PLACEHOLDER;
  16528. isFocused && resetSelection();
  16529. }
  16530. });
  16531. function resetSelection(isEmpty) {
  16532. if (inComposition)
  16533. return;
  16534. inComposition = true;
  16535. if (inputHandler) {
  16536. selectionStart = 0;
  16537. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  16538. } else {
  16539. var selectionStart = isEmpty ? 2 : 1;
  16540. var selectionEnd = 2;
  16541. }
  16542. try {
  16543. text.setSelectionRange(selectionStart, selectionEnd);
  16544. } catch(e){}
  16545. inComposition = false;
  16546. }
  16547. function resetValue() {
  16548. if (inComposition)
  16549. return;
  16550. text.value = PLACEHOLDER;
  16551. if (useragent.isWebKit)
  16552. syncValue.schedule();
  16553. }
  16554. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  16555. if (host.selection.isEmpty() != isSelectionEmpty) {
  16556. isSelectionEmpty = !isSelectionEmpty;
  16557. syncSelection.schedule();
  16558. }
  16559. });
  16560. resetValue();
  16561. if (isFocused)
  16562. host.onFocus();
  16563. var isAllSelected = function(text) {
  16564. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  16565. };
  16566. if (!text.setSelectionRange && text.createTextRange) {
  16567. text.setSelectionRange = function(selectionStart, selectionEnd) {
  16568. var range = this.createTextRange();
  16569. range.collapse(true);
  16570. range.moveStart('character', selectionStart);
  16571. range.moveEnd('character', selectionEnd);
  16572. range.select();
  16573. };
  16574. isAllSelected = function(text) {
  16575. try {
  16576. var range = text.ownerDocument.selection.createRange();
  16577. }catch(e) {}
  16578. if (!range || range.parentElement() != text) return false;
  16579. return range.text == text.value;
  16580. }
  16581. }
  16582. if (useragent.isOldIE) {
  16583. var inPropertyChange = false;
  16584. var onPropertyChange = function(e){
  16585. if (inPropertyChange)
  16586. return;
  16587. var data = text.value;
  16588. if (inComposition || !data || data == PLACEHOLDER)
  16589. return;
  16590. if (e && data == PLACEHOLDER[0])
  16591. return syncProperty.schedule();
  16592. sendText(data);
  16593. inPropertyChange = true;
  16594. resetValue();
  16595. inPropertyChange = false;
  16596. };
  16597. var syncProperty = lang.delayedCall(onPropertyChange);
  16598. event.addListener(text, "propertychange", onPropertyChange);
  16599. var keytable = { 13:1, 27:1 };
  16600. event.addListener(text, "keyup", function (e) {
  16601. if (inComposition && (!text.value || keytable[e.keyCode]))
  16602. setTimeout(onCompositionEnd, 0);
  16603. if ((text.value.charCodeAt(0)||0) < 129) {
  16604. return syncProperty.call();
  16605. }
  16606. inComposition ? onCompositionUpdate() : onCompositionStart();
  16607. });
  16608. event.addListener(text, "keydown", function (e) {
  16609. syncProperty.schedule(50);
  16610. });
  16611. }
  16612. var onSelect = function(e) {
  16613. if (copied) {
  16614. copied = false;
  16615. } else if (isAllSelected(text)) {
  16616. host.selectAll();
  16617. resetSelection();
  16618. } else if (inputHandler) {
  16619. resetSelection(host.selection.isEmpty());
  16620. }
  16621. };
  16622. var inputHandler = null;
  16623. this.setInputHandler = function(cb) {inputHandler = cb};
  16624. this.getInputHandler = function() {return inputHandler};
  16625. var afterContextMenu = false;
  16626. var sendText = function(data) {
  16627. if (inputHandler) {
  16628. data = inputHandler(data);
  16629. inputHandler = null;
  16630. }
  16631. if (pasted) {
  16632. resetSelection();
  16633. if (data)
  16634. host.onPaste(data);
  16635. pasted = false;
  16636. } else if (data == PLACEHOLDER.charAt(0)) {
  16637. if (afterContextMenu)
  16638. host.execCommand("del", {source: "ace"});
  16639. else // some versions of android do not fire keydown when pressing backspace
  16640. host.execCommand("backspace", {source: "ace"});
  16641. } else {
  16642. if (data.substring(0, 2) == PLACEHOLDER)
  16643. data = data.substr(2);
  16644. else if (data.charAt(0) == PLACEHOLDER.charAt(0))
  16645. data = data.substr(1);
  16646. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  16647. data = data.slice(0, -1);
  16648. if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  16649. data = data.slice(0, -1);
  16650. if (data)
  16651. host.onTextInput(data);
  16652. }
  16653. if (afterContextMenu)
  16654. afterContextMenu = false;
  16655. };
  16656. var onInput = function(e) {
  16657. if (inComposition)
  16658. return;
  16659. var data = text.value;
  16660. sendText(data);
  16661. resetValue();
  16662. };
  16663. var handleClipboardData = function(e, data) {
  16664. var clipboardData = e.clipboardData || window.clipboardData;
  16665. if (!clipboardData || BROKEN_SETDATA)
  16666. return;
  16667. var mime = USE_IE_MIME_TYPE ? "Text" : "text/plain";
  16668. if (data) {
  16669. return clipboardData.setData(mime, data) !== false;
  16670. } else {
  16671. return clipboardData.getData(mime);
  16672. }
  16673. };
  16674. var doCopy = function(e, isCut) {
  16675. var data = host.getCopyText();
  16676. if (!data)
  16677. return event.preventDefault(e);
  16678. if (handleClipboardData(e, data)) {
  16679. isCut ? host.onCut() : host.onCopy();
  16680. event.preventDefault(e);
  16681. } else {
  16682. copied = true;
  16683. text.value = data;
  16684. text.select();
  16685. setTimeout(function(){
  16686. copied = false;
  16687. resetValue();
  16688. resetSelection();
  16689. isCut ? host.onCut() : host.onCopy();
  16690. });
  16691. }
  16692. };
  16693. var onCut = function(e) {
  16694. doCopy(e, true);
  16695. };
  16696. var onCopy = function(e) {
  16697. doCopy(e, false);
  16698. };
  16699. var onPaste = function(e) {
  16700. var data = handleClipboardData(e);
  16701. if (typeof data == "string") {
  16702. if (data)
  16703. host.onPaste(data, e);
  16704. if (useragent.isIE)
  16705. setTimeout(resetSelection);
  16706. event.preventDefault(e);
  16707. }
  16708. else {
  16709. text.value = "";
  16710. pasted = true;
  16711. }
  16712. };
  16713. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  16714. event.addListener(text, "select", onSelect);
  16715. event.addListener(text, "input", onInput);
  16716. event.addListener(text, "cut", onCut);
  16717. event.addListener(text, "copy", onCopy);
  16718. event.addListener(text, "paste", onPaste);
  16719. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)){
  16720. event.addListener(parentNode, "keydown", function(e) {
  16721. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  16722. return;
  16723. switch (e.keyCode) {
  16724. case 67:
  16725. onCopy(e);
  16726. break;
  16727. case 86:
  16728. onPaste(e);
  16729. break;
  16730. case 88:
  16731. onCut(e);
  16732. break;
  16733. }
  16734. });
  16735. }
  16736. var onCompositionStart = function(e) {
  16737. if (inComposition || !host.onCompositionStart || host.$readOnly)
  16738. return;
  16739. inComposition = {};
  16740. host.onCompositionStart();
  16741. setTimeout(onCompositionUpdate, 0);
  16742. host.on("mousedown", onCompositionEnd);
  16743. if (!host.selection.isEmpty()) {
  16744. host.insert("");
  16745. host.session.markUndoGroup();
  16746. host.selection.clearSelection();
  16747. }
  16748. host.session.markUndoGroup();
  16749. };
  16750. var onCompositionUpdate = function() {
  16751. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  16752. return;
  16753. var val = text.value.replace(/\x01/g, "");
  16754. if (inComposition.lastValue === val) return;
  16755. host.onCompositionUpdate(val);
  16756. if (inComposition.lastValue)
  16757. host.undo();
  16758. inComposition.lastValue = val;
  16759. if (inComposition.lastValue) {
  16760. var r = host.selection.getRange();
  16761. host.insert(inComposition.lastValue);
  16762. host.session.markUndoGroup();
  16763. inComposition.range = host.selection.getRange();
  16764. host.selection.setRange(r);
  16765. host.selection.clearSelection();
  16766. }
  16767. };
  16768. var onCompositionEnd = function(e) {
  16769. if (!host.onCompositionEnd || host.$readOnly) return;
  16770. var c = inComposition;
  16771. inComposition = false;
  16772. var timer = setTimeout(function() {
  16773. timer = null;
  16774. var str = text.value.replace(/\x01/g, "");
  16775. if (inComposition)
  16776. return;
  16777. else if (str == c.lastValue)
  16778. resetValue();
  16779. else if (!c.lastValue && str) {
  16780. resetValue();
  16781. sendText(str);
  16782. }
  16783. });
  16784. inputHandler = function compositionInputHandler(str) {
  16785. if (timer)
  16786. clearTimeout(timer);
  16787. str = str.replace(/\x01/g, "");
  16788. if (str == c.lastValue)
  16789. return "";
  16790. if (c.lastValue && timer)
  16791. host.undo();
  16792. return str;
  16793. };
  16794. host.onCompositionEnd();
  16795. host.removeListener("mousedown", onCompositionEnd);
  16796. if (e.type == "compositionend" && c.range) {
  16797. host.selection.setRange(c.range);
  16798. }
  16799. };
  16800. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  16801. event.addListener(text, "compositionstart", onCompositionStart);
  16802. if (useragent.isGecko) {
  16803. event.addListener(text, "text", function(){syncComposition.schedule()});
  16804. } else {
  16805. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  16806. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  16807. }
  16808. event.addListener(text, "compositionend", onCompositionEnd);
  16809. this.getElement = function() {
  16810. return text;
  16811. };
  16812. this.setReadOnly = function(readOnly) {
  16813. text.readOnly = readOnly;
  16814. };
  16815. this.onContextMenu = function(e) {
  16816. afterContextMenu = true;
  16817. resetSelection(host.selection.isEmpty());
  16818. host._emit("nativecontextmenu", {target: host, domEvent: e});
  16819. this.moveToMouse(e, true);
  16820. };
  16821. this.moveToMouse = function(e, bringToFront) {
  16822. if (!bringToFront && useragent.isOldIE)
  16823. return;
  16824. if (!tempStyle)
  16825. tempStyle = text.style.cssText;
  16826. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  16827. + "height:" + text.style.height + ";"
  16828. + (useragent.isIE ? "opacity:0.1;" : "");
  16829. var rect = host.container.getBoundingClientRect();
  16830. var style = dom.computedStyle(host.container);
  16831. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  16832. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  16833. var maxTop = rect.bottom - top - text.clientHeight -2;
  16834. var move = function(e) {
  16835. text.style.left = e.clientX - left - 2 + "px";
  16836. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  16837. };
  16838. move(e);
  16839. if (e.type != "mousedown")
  16840. return;
  16841. if (host.renderer.$keepTextAreaAtCursor)
  16842. host.renderer.$keepTextAreaAtCursor = null;
  16843. clearTimeout(closeTimeout);
  16844. if (useragent.isWin && !useragent.isOldIE)
  16845. event.capture(host.container, move, onContextMenuClose);
  16846. };
  16847. this.onContextMenuClose = onContextMenuClose;
  16848. var closeTimeout;
  16849. function onContextMenuClose() {
  16850. clearTimeout(closeTimeout);
  16851. closeTimeout = setTimeout(function () {
  16852. if (tempStyle) {
  16853. text.style.cssText = tempStyle;
  16854. tempStyle = '';
  16855. }
  16856. if (host.renderer.$keepTextAreaAtCursor == null) {
  16857. host.renderer.$keepTextAreaAtCursor = true;
  16858. host.renderer.$moveTextAreaToCursor();
  16859. }
  16860. }, useragent.isOldIE ? 200 : 0);
  16861. }
  16862. var onContextMenu = function(e) {
  16863. host.textInput.onContextMenu(e);
  16864. onContextMenuClose();
  16865. };
  16866. event.addListener(text, "mouseup", onContextMenu);
  16867. event.addListener(text, "mousedown", function(e) {
  16868. e.preventDefault();
  16869. onContextMenuClose();
  16870. });
  16871. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  16872. event.addListener(text, "contextmenu", onContextMenu);
  16873. };
  16874. exports.TextInput = TextInput;
  16875. });
  16876. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) {
  16877. "use strict";
  16878. var dom = acequire("../lib/dom");
  16879. var event = acequire("../lib/event");
  16880. var useragent = acequire("../lib/useragent");
  16881. var DRAG_OFFSET = 0; // pixels
  16882. function DefaultHandlers(mouseHandler) {
  16883. mouseHandler.$clickSelection = null;
  16884. var editor = mouseHandler.editor;
  16885. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  16886. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  16887. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  16888. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  16889. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  16890. editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
  16891. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  16892. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  16893. exports.forEach(function(x) {
  16894. mouseHandler[x] = this[x];
  16895. }, this);
  16896. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  16897. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  16898. }
  16899. (function() {
  16900. this.onMouseDown = function(ev) {
  16901. var inSelection = ev.inSelection();
  16902. var pos = ev.getDocumentPosition();
  16903. this.mousedownEvent = ev;
  16904. var editor = this.editor;
  16905. var button = ev.getButton();
  16906. if (button !== 0) {
  16907. var selectionRange = editor.getSelectionRange();
  16908. var selectionEmpty = selectionRange.isEmpty();
  16909. editor.$blockScrolling++;
  16910. if (selectionEmpty || button == 1)
  16911. editor.selection.moveToPosition(pos);
  16912. editor.$blockScrolling--;
  16913. if (button == 2)
  16914. editor.textInput.onContextMenu(ev.domEvent);
  16915. return; // stopping event here breaks contextmenu on ff mac
  16916. }
  16917. this.mousedownEvent.time = Date.now();
  16918. if (inSelection && !editor.isFocused()) {
  16919. editor.focus();
  16920. if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
  16921. this.setState("focusWait");
  16922. this.captureMouse(ev);
  16923. return;
  16924. }
  16925. }
  16926. this.captureMouse(ev);
  16927. this.startSelect(pos, ev.domEvent._clicks > 1);
  16928. return ev.preventDefault();
  16929. };
  16930. this.startSelect = function(pos, waitForClickSelection) {
  16931. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  16932. var editor = this.editor;
  16933. editor.$blockScrolling++;
  16934. if (this.mousedownEvent.getShiftKey())
  16935. editor.selection.selectToPosition(pos);
  16936. else if (!waitForClickSelection)
  16937. editor.selection.moveToPosition(pos);
  16938. if (!waitForClickSelection)
  16939. this.select();
  16940. if (editor.renderer.scroller.setCapture) {
  16941. editor.renderer.scroller.setCapture();
  16942. }
  16943. editor.setStyle("ace_selecting");
  16944. this.setState("select");
  16945. editor.$blockScrolling--;
  16946. };
  16947. this.select = function() {
  16948. var anchor, editor = this.editor;
  16949. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  16950. editor.$blockScrolling++;
  16951. if (this.$clickSelection) {
  16952. var cmp = this.$clickSelection.comparePoint(cursor);
  16953. if (cmp == -1) {
  16954. anchor = this.$clickSelection.end;
  16955. } else if (cmp == 1) {
  16956. anchor = this.$clickSelection.start;
  16957. } else {
  16958. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  16959. cursor = orientedRange.cursor;
  16960. anchor = orientedRange.anchor;
  16961. }
  16962. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  16963. }
  16964. editor.selection.selectToPosition(cursor);
  16965. editor.$blockScrolling--;
  16966. editor.renderer.scrollCursorIntoView();
  16967. };
  16968. this.extendSelectionBy = function(unitName) {
  16969. var anchor, editor = this.editor;
  16970. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  16971. var range = editor.selection[unitName](cursor.row, cursor.column);
  16972. editor.$blockScrolling++;
  16973. if (this.$clickSelection) {
  16974. var cmpStart = this.$clickSelection.comparePoint(range.start);
  16975. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  16976. if (cmpStart == -1 && cmpEnd <= 0) {
  16977. anchor = this.$clickSelection.end;
  16978. if (range.end.row != cursor.row || range.end.column != cursor.column)
  16979. cursor = range.start;
  16980. } else if (cmpEnd == 1 && cmpStart >= 0) {
  16981. anchor = this.$clickSelection.start;
  16982. if (range.start.row != cursor.row || range.start.column != cursor.column)
  16983. cursor = range.end;
  16984. } else if (cmpStart == -1 && cmpEnd == 1) {
  16985. cursor = range.end;
  16986. anchor = range.start;
  16987. } else {
  16988. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  16989. cursor = orientedRange.cursor;
  16990. anchor = orientedRange.anchor;
  16991. }
  16992. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  16993. }
  16994. editor.selection.selectToPosition(cursor);
  16995. editor.$blockScrolling--;
  16996. editor.renderer.scrollCursorIntoView();
  16997. };
  16998. this.selectEnd =
  16999. this.selectAllEnd =
  17000. this.selectByWordsEnd =
  17001. this.selectByLinesEnd = function() {
  17002. this.$clickSelection = null;
  17003. this.editor.unsetStyle("ace_selecting");
  17004. if (this.editor.renderer.scroller.releaseCapture) {
  17005. this.editor.renderer.scroller.releaseCapture();
  17006. }
  17007. };
  17008. this.focusWait = function() {
  17009. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  17010. var time = Date.now();
  17011. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)
  17012. this.startSelect(this.mousedownEvent.getDocumentPosition());
  17013. };
  17014. this.onDoubleClick = function(ev) {
  17015. var pos = ev.getDocumentPosition();
  17016. var editor = this.editor;
  17017. var session = editor.session;
  17018. var range = session.getBracketRange(pos);
  17019. if (range) {
  17020. if (range.isEmpty()) {
  17021. range.start.column--;
  17022. range.end.column++;
  17023. }
  17024. this.setState("select");
  17025. } else {
  17026. range = editor.selection.getWordRange(pos.row, pos.column);
  17027. this.setState("selectByWords");
  17028. }
  17029. this.$clickSelection = range;
  17030. this.select();
  17031. };
  17032. this.onTripleClick = function(ev) {
  17033. var pos = ev.getDocumentPosition();
  17034. var editor = this.editor;
  17035. this.setState("selectByLines");
  17036. var range = editor.getSelectionRange();
  17037. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  17038. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  17039. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  17040. } else {
  17041. this.$clickSelection = editor.selection.getLineRange(pos.row);
  17042. }
  17043. this.select();
  17044. };
  17045. this.onQuadClick = function(ev) {
  17046. var editor = this.editor;
  17047. editor.selectAll();
  17048. this.$clickSelection = editor.getSelectionRange();
  17049. this.setState("selectAll");
  17050. };
  17051. this.onMouseWheel = function(ev) {
  17052. if (ev.getAccelKey())
  17053. return;
  17054. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  17055. ev.wheelX = ev.wheelY;
  17056. ev.wheelY = 0;
  17057. }
  17058. var t = ev.domEvent.timeStamp;
  17059. var dt = t - (this.$lastScrollTime||0);
  17060. var editor = this.editor;
  17061. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  17062. if (isScrolable || dt < 200) {
  17063. this.$lastScrollTime = t;
  17064. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  17065. return ev.stop();
  17066. }
  17067. };
  17068. this.onTouchMove = function (ev) {
  17069. var t = ev.domEvent.timeStamp;
  17070. var dt = t - (this.$lastScrollTime || 0);
  17071. var editor = this.editor;
  17072. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  17073. if (isScrolable || dt < 200) {
  17074. this.$lastScrollTime = t;
  17075. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  17076. return ev.stop();
  17077. }
  17078. };
  17079. }).call(DefaultHandlers.prototype);
  17080. exports.DefaultHandlers = DefaultHandlers;
  17081. function calcDistance(ax, ay, bx, by) {
  17082. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  17083. }
  17084. function calcRangeOrientation(range, cursor) {
  17085. if (range.start.row == range.end.row)
  17086. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  17087. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  17088. var cmp = cursor.column - 4;
  17089. else
  17090. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  17091. if (cmp < 0)
  17092. return {cursor: range.start, anchor: range.end};
  17093. else
  17094. return {cursor: range.end, anchor: range.start};
  17095. }
  17096. });
  17097. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(acequire, exports, module) {
  17098. "use strict";
  17099. var oop = acequire("./lib/oop");
  17100. var dom = acequire("./lib/dom");
  17101. function Tooltip (parentNode) {
  17102. this.isOpen = false;
  17103. this.$element = null;
  17104. this.$parentNode = parentNode;
  17105. }
  17106. (function() {
  17107. this.$init = function() {
  17108. this.$element = dom.createElement("div");
  17109. this.$element.className = "ace_tooltip";
  17110. this.$element.style.display = "none";
  17111. this.$parentNode.appendChild(this.$element);
  17112. return this.$element;
  17113. };
  17114. this.getElement = function() {
  17115. return this.$element || this.$init();
  17116. };
  17117. this.setText = function(text) {
  17118. dom.setInnerText(this.getElement(), text);
  17119. };
  17120. this.setHtml = function(html) {
  17121. this.getElement().innerHTML = html;
  17122. };
  17123. this.setPosition = function(x, y) {
  17124. this.getElement().style.left = x + "px";
  17125. this.getElement().style.top = y + "px";
  17126. };
  17127. this.setClassName = function(className) {
  17128. dom.addCssClass(this.getElement(), className);
  17129. };
  17130. this.show = function(text, x, y) {
  17131. if (text != null)
  17132. this.setText(text);
  17133. if (x != null && y != null)
  17134. this.setPosition(x, y);
  17135. if (!this.isOpen) {
  17136. this.getElement().style.display = "block";
  17137. this.isOpen = true;
  17138. }
  17139. };
  17140. this.hide = function() {
  17141. if (this.isOpen) {
  17142. this.getElement().style.display = "none";
  17143. this.isOpen = false;
  17144. }
  17145. };
  17146. this.getHeight = function() {
  17147. return this.getElement().offsetHeight;
  17148. };
  17149. this.getWidth = function() {
  17150. return this.getElement().offsetWidth;
  17151. };
  17152. }).call(Tooltip.prototype);
  17153. exports.Tooltip = Tooltip;
  17154. });
  17155. ace.define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(acequire, exports, module) {
  17156. "use strict";
  17157. var dom = acequire("../lib/dom");
  17158. var oop = acequire("../lib/oop");
  17159. var event = acequire("../lib/event");
  17160. var Tooltip = acequire("../tooltip").Tooltip;
  17161. function GutterHandler(mouseHandler) {
  17162. var editor = mouseHandler.editor;
  17163. var gutter = editor.renderer.$gutterLayer;
  17164. var tooltip = new GutterTooltip(editor.container);
  17165. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  17166. if (!editor.isFocused() || e.getButton() != 0)
  17167. return;
  17168. var gutterRegion = gutter.getRegion(e);
  17169. if (gutterRegion == "foldWidgets")
  17170. return;
  17171. var row = e.getDocumentPosition().row;
  17172. var selection = editor.session.selection;
  17173. if (e.getShiftKey())
  17174. selection.selectTo(row, 0);
  17175. else {
  17176. if (e.domEvent.detail == 2) {
  17177. editor.selectAll();
  17178. return e.preventDefault();
  17179. }
  17180. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  17181. }
  17182. mouseHandler.setState("selectByLines");
  17183. mouseHandler.captureMouse(e);
  17184. return e.preventDefault();
  17185. });
  17186. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  17187. function showTooltip() {
  17188. var row = mouseEvent.getDocumentPosition().row;
  17189. var annotation = gutter.$annotations[row];
  17190. if (!annotation)
  17191. return hideTooltip();
  17192. var maxRow = editor.session.getLength();
  17193. if (row == maxRow) {
  17194. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  17195. var pos = mouseEvent.$pos;
  17196. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  17197. return hideTooltip();
  17198. }
  17199. if (tooltipAnnotation == annotation)
  17200. return;
  17201. tooltipAnnotation = annotation.text.join("<br/>");
  17202. tooltip.setHtml(tooltipAnnotation);
  17203. tooltip.show();
  17204. editor.on("mousewheel", hideTooltip);
  17205. if (mouseHandler.$tooltipFollowsMouse) {
  17206. moveTooltip(mouseEvent);
  17207. } else {
  17208. var gutterElement = mouseEvent.domEvent.target;
  17209. var rect = gutterElement.getBoundingClientRect();
  17210. var style = tooltip.getElement().style;
  17211. style.left = rect.right + "px";
  17212. style.top = rect.bottom + "px";
  17213. }
  17214. }
  17215. function hideTooltip() {
  17216. if (tooltipTimeout)
  17217. tooltipTimeout = clearTimeout(tooltipTimeout);
  17218. if (tooltipAnnotation) {
  17219. tooltip.hide();
  17220. tooltipAnnotation = null;
  17221. editor.removeEventListener("mousewheel", hideTooltip);
  17222. }
  17223. }
  17224. function moveTooltip(e) {
  17225. tooltip.setPosition(e.x, e.y);
  17226. }
  17227. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  17228. var target = e.domEvent.target || e.domEvent.srcElement;
  17229. if (dom.hasCssClass(target, "ace_fold-widget"))
  17230. return hideTooltip();
  17231. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  17232. moveTooltip(e);
  17233. mouseEvent = e;
  17234. if (tooltipTimeout)
  17235. return;
  17236. tooltipTimeout = setTimeout(function() {
  17237. tooltipTimeout = null;
  17238. if (mouseEvent && !mouseHandler.isMousePressed)
  17239. showTooltip();
  17240. else
  17241. hideTooltip();
  17242. }, 50);
  17243. });
  17244. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  17245. mouseEvent = null;
  17246. if (!tooltipAnnotation || tooltipTimeout)
  17247. return;
  17248. tooltipTimeout = setTimeout(function() {
  17249. tooltipTimeout = null;
  17250. hideTooltip();
  17251. }, 50);
  17252. });
  17253. editor.on("changeSession", hideTooltip);
  17254. }
  17255. function GutterTooltip(parentNode) {
  17256. Tooltip.call(this, parentNode);
  17257. }
  17258. oop.inherits(GutterTooltip, Tooltip);
  17259. (function(){
  17260. this.setPosition = function(x, y) {
  17261. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  17262. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  17263. var width = this.getWidth();
  17264. var height = this.getHeight();
  17265. x += 15;
  17266. y += 15;
  17267. if (x + width > windowWidth) {
  17268. x -= (x + width) - windowWidth;
  17269. }
  17270. if (y + height > windowHeight) {
  17271. y -= 20 + height;
  17272. }
  17273. Tooltip.prototype.setPosition.call(this, x, y);
  17274. };
  17275. }).call(GutterTooltip.prototype);
  17276. exports.GutterHandler = GutterHandler;
  17277. });
  17278. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) {
  17279. "use strict";
  17280. var event = acequire("../lib/event");
  17281. var useragent = acequire("../lib/useragent");
  17282. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  17283. this.domEvent = domEvent;
  17284. this.editor = editor;
  17285. this.x = this.clientX = domEvent.clientX;
  17286. this.y = this.clientY = domEvent.clientY;
  17287. this.$pos = null;
  17288. this.$inSelection = null;
  17289. this.propagationStopped = false;
  17290. this.defaultPrevented = false;
  17291. };
  17292. (function() {
  17293. this.stopPropagation = function() {
  17294. event.stopPropagation(this.domEvent);
  17295. this.propagationStopped = true;
  17296. };
  17297. this.preventDefault = function() {
  17298. event.preventDefault(this.domEvent);
  17299. this.defaultPrevented = true;
  17300. };
  17301. this.stop = function() {
  17302. this.stopPropagation();
  17303. this.preventDefault();
  17304. };
  17305. this.getDocumentPosition = function() {
  17306. if (this.$pos)
  17307. return this.$pos;
  17308. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  17309. return this.$pos;
  17310. };
  17311. this.inSelection = function() {
  17312. if (this.$inSelection !== null)
  17313. return this.$inSelection;
  17314. var editor = this.editor;
  17315. var selectionRange = editor.getSelectionRange();
  17316. if (selectionRange.isEmpty())
  17317. this.$inSelection = false;
  17318. else {
  17319. var pos = this.getDocumentPosition();
  17320. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  17321. }
  17322. return this.$inSelection;
  17323. };
  17324. this.getButton = function() {
  17325. return event.getButton(this.domEvent);
  17326. };
  17327. this.getShiftKey = function() {
  17328. return this.domEvent.shiftKey;
  17329. };
  17330. this.getAccelKey = useragent.isMac
  17331. ? function() { return this.domEvent.metaKey; }
  17332. : function() { return this.domEvent.ctrlKey; };
  17333. }).call(MouseEvent.prototype);
  17334. });
  17335. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) {
  17336. "use strict";
  17337. var dom = acequire("../lib/dom");
  17338. var event = acequire("../lib/event");
  17339. var useragent = acequire("../lib/useragent");
  17340. var AUTOSCROLL_DELAY = 200;
  17341. var SCROLL_CURSOR_DELAY = 200;
  17342. var SCROLL_CURSOR_HYSTERESIS = 5;
  17343. function DragdropHandler(mouseHandler) {
  17344. var editor = mouseHandler.editor;
  17345. var blankImage = dom.createElement("img");
  17346. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  17347. if (useragent.isOpera)
  17348. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  17349. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  17350. exports.forEach(function(x) {
  17351. mouseHandler[x] = this[x];
  17352. }, this);
  17353. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  17354. var mouseTarget = editor.container;
  17355. var dragSelectionMarker, x, y;
  17356. var timerId, range;
  17357. var dragCursor, counter = 0;
  17358. var dragOperation;
  17359. var isInternal;
  17360. var autoScrollStartTime;
  17361. var cursorMovedTime;
  17362. var cursorPointOnCaretMoved;
  17363. this.onDragStart = function(e) {
  17364. if (this.cancelDrag || !mouseTarget.draggable) {
  17365. var self = this;
  17366. setTimeout(function(){
  17367. self.startSelect();
  17368. self.captureMouse(e);
  17369. }, 0);
  17370. return e.preventDefault();
  17371. }
  17372. range = editor.getSelectionRange();
  17373. var dataTransfer = e.dataTransfer;
  17374. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  17375. if (useragent.isOpera) {
  17376. editor.container.appendChild(blankImage);
  17377. blankImage.scrollTop = 0;
  17378. }
  17379. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  17380. if (useragent.isOpera) {
  17381. editor.container.removeChild(blankImage);
  17382. }
  17383. dataTransfer.clearData();
  17384. dataTransfer.setData("Text", editor.session.getTextRange());
  17385. isInternal = true;
  17386. this.setState("drag");
  17387. };
  17388. this.onDragEnd = function(e) {
  17389. mouseTarget.draggable = false;
  17390. isInternal = false;
  17391. this.setState(null);
  17392. if (!editor.getReadOnly()) {
  17393. var dropEffect = e.dataTransfer.dropEffect;
  17394. if (!dragOperation && dropEffect == "move")
  17395. editor.session.remove(editor.getSelectionRange());
  17396. editor.renderer.$cursorLayer.setBlinking(true);
  17397. }
  17398. this.editor.unsetStyle("ace_dragging");
  17399. this.editor.renderer.setCursorStyle("");
  17400. };
  17401. this.onDragEnter = function(e) {
  17402. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  17403. return;
  17404. x = e.clientX;
  17405. y = e.clientY;
  17406. if (!dragSelectionMarker)
  17407. addDragMarker();
  17408. counter++;
  17409. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  17410. return event.preventDefault(e);
  17411. };
  17412. this.onDragOver = function(e) {
  17413. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  17414. return;
  17415. x = e.clientX;
  17416. y = e.clientY;
  17417. if (!dragSelectionMarker) {
  17418. addDragMarker();
  17419. counter++;
  17420. }
  17421. if (onMouseMoveTimer !== null)
  17422. onMouseMoveTimer = null;
  17423. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  17424. return event.preventDefault(e);
  17425. };
  17426. this.onDragLeave = function(e) {
  17427. counter--;
  17428. if (counter <= 0 && dragSelectionMarker) {
  17429. clearDragMarker();
  17430. dragOperation = null;
  17431. return event.preventDefault(e);
  17432. }
  17433. };
  17434. this.onDrop = function(e) {
  17435. if (!dragCursor)
  17436. return;
  17437. var dataTransfer = e.dataTransfer;
  17438. if (isInternal) {
  17439. switch (dragOperation) {
  17440. case "move":
  17441. if (range.contains(dragCursor.row, dragCursor.column)) {
  17442. range = {
  17443. start: dragCursor,
  17444. end: dragCursor
  17445. };
  17446. } else {
  17447. range = editor.moveText(range, dragCursor);
  17448. }
  17449. break;
  17450. case "copy":
  17451. range = editor.moveText(range, dragCursor, true);
  17452. break;
  17453. }
  17454. } else {
  17455. var dropData = dataTransfer.getData('Text');
  17456. range = {
  17457. start: dragCursor,
  17458. end: editor.session.insert(dragCursor, dropData)
  17459. };
  17460. editor.focus();
  17461. dragOperation = null;
  17462. }
  17463. clearDragMarker();
  17464. return event.preventDefault(e);
  17465. };
  17466. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  17467. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  17468. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  17469. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  17470. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  17471. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  17472. function scrollCursorIntoView(cursor, prevCursor) {
  17473. var now = Date.now();
  17474. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  17475. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  17476. if (!cursorMovedTime || vMovement || hMovement) {
  17477. editor.$blockScrolling += 1;
  17478. editor.moveCursorToPosition(cursor);
  17479. editor.$blockScrolling -= 1;
  17480. cursorMovedTime = now;
  17481. cursorPointOnCaretMoved = {x: x, y: y};
  17482. } else {
  17483. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  17484. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  17485. cursorMovedTime = null;
  17486. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  17487. editor.renderer.scrollCursorIntoView();
  17488. cursorMovedTime = null;
  17489. }
  17490. }
  17491. }
  17492. function autoScroll(cursor, prevCursor) {
  17493. var now = Date.now();
  17494. var lineHeight = editor.renderer.layerConfig.lineHeight;
  17495. var characterWidth = editor.renderer.layerConfig.characterWidth;
  17496. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  17497. var offsets = {
  17498. x: {
  17499. left: x - editorRect.left,
  17500. right: editorRect.right - x
  17501. },
  17502. y: {
  17503. top: y - editorRect.top,
  17504. bottom: editorRect.bottom - y
  17505. }
  17506. };
  17507. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  17508. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  17509. var scrollCursor = {row: cursor.row, column: cursor.column};
  17510. if (nearestXOffset / characterWidth <= 2) {
  17511. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  17512. }
  17513. if (nearestYOffset / lineHeight <= 1) {
  17514. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  17515. }
  17516. var vScroll = cursor.row != scrollCursor.row;
  17517. var hScroll = cursor.column != scrollCursor.column;
  17518. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  17519. if (vScroll || (hScroll && !vMovement)) {
  17520. if (!autoScrollStartTime)
  17521. autoScrollStartTime = now;
  17522. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  17523. editor.renderer.scrollCursorIntoView(scrollCursor);
  17524. } else {
  17525. autoScrollStartTime = null;
  17526. }
  17527. }
  17528. function onDragInterval() {
  17529. var prevCursor = dragCursor;
  17530. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  17531. scrollCursorIntoView(dragCursor, prevCursor);
  17532. autoScroll(dragCursor, prevCursor);
  17533. }
  17534. function addDragMarker() {
  17535. range = editor.selection.toOrientedRange();
  17536. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  17537. editor.clearSelection();
  17538. if (editor.isFocused())
  17539. editor.renderer.$cursorLayer.setBlinking(false);
  17540. clearInterval(timerId);
  17541. onDragInterval();
  17542. timerId = setInterval(onDragInterval, 20);
  17543. counter = 0;
  17544. event.addListener(document, "mousemove", onMouseMove);
  17545. }
  17546. function clearDragMarker() {
  17547. clearInterval(timerId);
  17548. editor.session.removeMarker(dragSelectionMarker);
  17549. dragSelectionMarker = null;
  17550. editor.$blockScrolling += 1;
  17551. editor.selection.fromOrientedRange(range);
  17552. editor.$blockScrolling -= 1;
  17553. if (editor.isFocused() && !isInternal)
  17554. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  17555. range = null;
  17556. dragCursor = null;
  17557. counter = 0;
  17558. autoScrollStartTime = null;
  17559. cursorMovedTime = null;
  17560. event.removeListener(document, "mousemove", onMouseMove);
  17561. }
  17562. var onMouseMoveTimer = null;
  17563. function onMouseMove() {
  17564. if (onMouseMoveTimer == null) {
  17565. onMouseMoveTimer = setTimeout(function() {
  17566. if (onMouseMoveTimer != null && dragSelectionMarker)
  17567. clearDragMarker();
  17568. }, 20);
  17569. }
  17570. }
  17571. function canAccept(dataTransfer) {
  17572. var types = dataTransfer.types;
  17573. return !types || Array.prototype.some.call(types, function(type) {
  17574. return type == 'text/plain' || type == 'Text';
  17575. });
  17576. }
  17577. function getDropEffect(e) {
  17578. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  17579. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  17580. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  17581. var effectAllowed = "uninitialized";
  17582. try {
  17583. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  17584. } catch (e) {}
  17585. var dropEffect = "none";
  17586. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  17587. dropEffect = "copy";
  17588. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  17589. dropEffect = "move";
  17590. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  17591. dropEffect = "copy";
  17592. return dropEffect;
  17593. }
  17594. }
  17595. (function() {
  17596. this.dragWait = function() {
  17597. var interval = Date.now() - this.mousedownEvent.time;
  17598. if (interval > this.editor.getDragDelay())
  17599. this.startDrag();
  17600. };
  17601. this.dragWaitEnd = function() {
  17602. var target = this.editor.container;
  17603. target.draggable = false;
  17604. this.startSelect(this.mousedownEvent.getDocumentPosition());
  17605. this.selectEnd();
  17606. };
  17607. this.dragReadyEnd = function(e) {
  17608. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  17609. this.editor.unsetStyle("ace_dragging");
  17610. this.editor.renderer.setCursorStyle("");
  17611. this.dragWaitEnd();
  17612. };
  17613. this.startDrag = function(){
  17614. this.cancelDrag = false;
  17615. var editor = this.editor;
  17616. var target = editor.container;
  17617. target.draggable = true;
  17618. editor.renderer.$cursorLayer.setBlinking(false);
  17619. editor.setStyle("ace_dragging");
  17620. var cursorStyle = useragent.isWin ? "default" : "move";
  17621. editor.renderer.setCursorStyle(cursorStyle);
  17622. this.setState("dragReady");
  17623. };
  17624. this.onMouseDrag = function(e) {
  17625. var target = this.editor.container;
  17626. if (useragent.isIE && this.state == "dragReady") {
  17627. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  17628. if (distance > 3)
  17629. target.dragDrop();
  17630. }
  17631. if (this.state === "dragWait") {
  17632. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  17633. if (distance > 0) {
  17634. target.draggable = false;
  17635. this.startSelect(this.mousedownEvent.getDocumentPosition());
  17636. }
  17637. }
  17638. };
  17639. this.onMouseDown = function(e) {
  17640. if (!this.$dragEnabled)
  17641. return;
  17642. this.mousedownEvent = e;
  17643. var editor = this.editor;
  17644. var inSelection = e.inSelection();
  17645. var button = e.getButton();
  17646. var clickCount = e.domEvent.detail || 1;
  17647. if (clickCount === 1 && button === 0 && inSelection) {
  17648. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  17649. return;
  17650. this.mousedownEvent.time = Date.now();
  17651. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  17652. if ("unselectable" in eventTarget)
  17653. eventTarget.unselectable = "on";
  17654. if (editor.getDragDelay()) {
  17655. if (useragent.isWebKit) {
  17656. this.cancelDrag = true;
  17657. var mouseTarget = editor.container;
  17658. mouseTarget.draggable = true;
  17659. }
  17660. this.setState("dragWait");
  17661. } else {
  17662. this.startDrag();
  17663. }
  17664. this.captureMouse(e, this.onMouseDrag.bind(this));
  17665. e.defaultPrevented = true;
  17666. }
  17667. };
  17668. }).call(DragdropHandler.prototype);
  17669. function calcDistance(ax, ay, bx, by) {
  17670. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  17671. }
  17672. exports.DragdropHandler = DragdropHandler;
  17673. });
  17674. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(acequire, exports, module) {
  17675. "use strict";
  17676. var dom = acequire("./dom");
  17677. exports.get = function (url, callback) {
  17678. var xhr = new XMLHttpRequest();
  17679. xhr.open('GET', url, true);
  17680. xhr.onreadystatechange = function () {
  17681. if (xhr.readyState === 4) {
  17682. callback(xhr.responseText);
  17683. }
  17684. };
  17685. xhr.send(null);
  17686. };
  17687. exports.loadScript = function(path, callback) {
  17688. var head = dom.getDocumentHead();
  17689. var s = document.createElement('script');
  17690. s.src = path;
  17691. head.appendChild(s);
  17692. s.onload = s.onreadystatechange = function(_, isAbort) {
  17693. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  17694. s = s.onload = s.onreadystatechange = null;
  17695. if (!isAbort)
  17696. callback();
  17697. }
  17698. };
  17699. };
  17700. exports.qualifyURL = function(url) {
  17701. var a = document.createElement('a');
  17702. a.href = url;
  17703. return a.href;
  17704. }
  17705. });
  17706. ace.define("ace/lib/event_emitter",["require","exports","module"], function(acequire, exports, module) {
  17707. "use strict";
  17708. var EventEmitter = {};
  17709. var stopPropagation = function() { this.propagationStopped = true; };
  17710. var preventDefault = function() { this.defaultPrevented = true; };
  17711. EventEmitter._emit =
  17712. EventEmitter._dispatchEvent = function(eventName, e) {
  17713. this._eventRegistry || (this._eventRegistry = {});
  17714. this._defaultHandlers || (this._defaultHandlers = {});
  17715. var listeners = this._eventRegistry[eventName] || [];
  17716. var defaultHandler = this._defaultHandlers[eventName];
  17717. if (!listeners.length && !defaultHandler)
  17718. return;
  17719. if (typeof e != "object" || !e)
  17720. e = {};
  17721. if (!e.type)
  17722. e.type = eventName;
  17723. if (!e.stopPropagation)
  17724. e.stopPropagation = stopPropagation;
  17725. if (!e.preventDefault)
  17726. e.preventDefault = preventDefault;
  17727. listeners = listeners.slice();
  17728. for (var i=0; i<listeners.length; i++) {
  17729. listeners[i](e, this);
  17730. if (e.propagationStopped)
  17731. break;
  17732. }
  17733. if (defaultHandler && !e.defaultPrevented)
  17734. return defaultHandler(e, this);
  17735. };
  17736. EventEmitter._signal = function(eventName, e) {
  17737. var listeners = (this._eventRegistry || {})[eventName];
  17738. if (!listeners)
  17739. return;
  17740. listeners = listeners.slice();
  17741. for (var i=0; i<listeners.length; i++)
  17742. listeners[i](e, this);
  17743. };
  17744. EventEmitter.once = function(eventName, callback) {
  17745. var _self = this;
  17746. callback && this.addEventListener(eventName, function newCallback() {
  17747. _self.removeEventListener(eventName, newCallback);
  17748. callback.apply(null, arguments);
  17749. });
  17750. };
  17751. EventEmitter.setDefaultHandler = function(eventName, callback) {
  17752. var handlers = this._defaultHandlers
  17753. if (!handlers)
  17754. handlers = this._defaultHandlers = {_disabled_: {}};
  17755. if (handlers[eventName]) {
  17756. var old = handlers[eventName];
  17757. var disabled = handlers._disabled_[eventName];
  17758. if (!disabled)
  17759. handlers._disabled_[eventName] = disabled = [];
  17760. disabled.push(old);
  17761. var i = disabled.indexOf(callback);
  17762. if (i != -1)
  17763. disabled.splice(i, 1);
  17764. }
  17765. handlers[eventName] = callback;
  17766. };
  17767. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  17768. var handlers = this._defaultHandlers
  17769. if (!handlers)
  17770. return;
  17771. var disabled = handlers._disabled_[eventName];
  17772. if (handlers[eventName] == callback) {
  17773. var old = handlers[eventName];
  17774. if (disabled)
  17775. this.setDefaultHandler(eventName, disabled.pop());
  17776. } else if (disabled) {
  17777. var i = disabled.indexOf(callback);
  17778. if (i != -1)
  17779. disabled.splice(i, 1);
  17780. }
  17781. };
  17782. EventEmitter.on =
  17783. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  17784. this._eventRegistry = this._eventRegistry || {};
  17785. var listeners = this._eventRegistry[eventName];
  17786. if (!listeners)
  17787. listeners = this._eventRegistry[eventName] = [];
  17788. if (listeners.indexOf(callback) == -1)
  17789. listeners[capturing ? "unshift" : "push"](callback);
  17790. return callback;
  17791. };
  17792. EventEmitter.off =
  17793. EventEmitter.removeListener =
  17794. EventEmitter.removeEventListener = function(eventName, callback) {
  17795. this._eventRegistry = this._eventRegistry || {};
  17796. var listeners = this._eventRegistry[eventName];
  17797. if (!listeners)
  17798. return;
  17799. var index = listeners.indexOf(callback);
  17800. if (index !== -1)
  17801. listeners.splice(index, 1);
  17802. };
  17803. EventEmitter.removeAllListeners = function(eventName) {
  17804. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  17805. };
  17806. exports.EventEmitter = EventEmitter;
  17807. });
  17808. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(acequire, exports, module) {
  17809. "no use strict";
  17810. var oop = acequire("./oop");
  17811. var EventEmitter = acequire("./event_emitter").EventEmitter;
  17812. var optionsProvider = {
  17813. setOptions: function(optList) {
  17814. Object.keys(optList).forEach(function(key) {
  17815. this.setOption(key, optList[key]);
  17816. }, this);
  17817. },
  17818. getOptions: function(optionNames) {
  17819. var result = {};
  17820. if (!optionNames) {
  17821. optionNames = Object.keys(this.$options);
  17822. } else if (!Array.isArray(optionNames)) {
  17823. result = optionNames;
  17824. optionNames = Object.keys(result);
  17825. }
  17826. optionNames.forEach(function(key) {
  17827. result[key] = this.getOption(key);
  17828. }, this);
  17829. return result;
  17830. },
  17831. setOption: function(name, value) {
  17832. if (this["$" + name] === value)
  17833. return;
  17834. var opt = this.$options[name];
  17835. if (!opt) {
  17836. return warn('misspelled option "' + name + '"');
  17837. }
  17838. if (opt.forwardTo)
  17839. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  17840. if (!opt.handlesSet)
  17841. this["$" + name] = value;
  17842. if (opt && opt.set)
  17843. opt.set.call(this, value);
  17844. },
  17845. getOption: function(name) {
  17846. var opt = this.$options[name];
  17847. if (!opt) {
  17848. return warn('misspelled option "' + name + '"');
  17849. }
  17850. if (opt.forwardTo)
  17851. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  17852. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  17853. }
  17854. };
  17855. function warn(message) {
  17856. if (typeof console != "undefined" && console.warn)
  17857. console.warn.apply(console, arguments);
  17858. }
  17859. function reportError(msg, data) {
  17860. var e = new Error(msg);
  17861. e.data = data;
  17862. if (typeof console == "object" && console.error)
  17863. console.error(e);
  17864. setTimeout(function() { throw e; });
  17865. }
  17866. var AppConfig = function() {
  17867. this.$defaultOptions = {};
  17868. };
  17869. (function() {
  17870. oop.implement(this, EventEmitter);
  17871. this.defineOptions = function(obj, path, options) {
  17872. if (!obj.$options)
  17873. this.$defaultOptions[path] = obj.$options = {};
  17874. Object.keys(options).forEach(function(key) {
  17875. var opt = options[key];
  17876. if (typeof opt == "string")
  17877. opt = {forwardTo: opt};
  17878. opt.name || (opt.name = key);
  17879. obj.$options[opt.name] = opt;
  17880. if ("initialValue" in opt)
  17881. obj["$" + opt.name] = opt.initialValue;
  17882. });
  17883. oop.implement(obj, optionsProvider);
  17884. return this;
  17885. };
  17886. this.resetOptions = function(obj) {
  17887. Object.keys(obj.$options).forEach(function(key) {
  17888. var opt = obj.$options[key];
  17889. if ("value" in opt)
  17890. obj.setOption(key, opt.value);
  17891. });
  17892. };
  17893. this.setDefaultValue = function(path, name, value) {
  17894. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  17895. if (opts[name]) {
  17896. if (opts.forwardTo)
  17897. this.setDefaultValue(opts.forwardTo, name, value);
  17898. else
  17899. opts[name].value = value;
  17900. }
  17901. };
  17902. this.setDefaultValues = function(path, optionHash) {
  17903. Object.keys(optionHash).forEach(function(key) {
  17904. this.setDefaultValue(path, key, optionHash[key]);
  17905. }, this);
  17906. };
  17907. this.warn = warn;
  17908. this.reportError = reportError;
  17909. }).call(AppConfig.prototype);
  17910. exports.AppConfig = AppConfig;
  17911. });
  17912. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(acequire, exports, module) {
  17913. "no use strict";
  17914. var lang = acequire("./lib/lang");
  17915. var oop = acequire("./lib/oop");
  17916. var net = acequire("./lib/net");
  17917. var AppConfig = acequire("./lib/app_config").AppConfig;
  17918. module.exports = exports = new AppConfig();
  17919. var global = (function() {
  17920. return this || typeof window != "undefined" && window;
  17921. })();
  17922. var options = {
  17923. packaged: false,
  17924. workerPath: null,
  17925. modePath: null,
  17926. themePath: null,
  17927. basePath: "",
  17928. suffix: ".js",
  17929. $moduleUrls: {}
  17930. };
  17931. exports.get = function(key) {
  17932. if (!options.hasOwnProperty(key))
  17933. throw new Error("Unknown config key: " + key);
  17934. return options[key];
  17935. };
  17936. exports.set = function(key, value) {
  17937. if (!options.hasOwnProperty(key))
  17938. throw new Error("Unknown config key: " + key);
  17939. options[key] = value;
  17940. };
  17941. exports.all = function() {
  17942. return lang.copyObject(options);
  17943. };
  17944. exports.moduleUrl = function(name, component) {
  17945. if (options.$moduleUrls[name])
  17946. return options.$moduleUrls[name];
  17947. var parts = name.split("/");
  17948. component = component || parts[parts.length - 2] || "";
  17949. var sep = component == "snippets" ? "/" : "-";
  17950. var base = parts[parts.length - 1];
  17951. if (component == "worker" && sep == "-") {
  17952. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  17953. base = base.replace(re, "");
  17954. }
  17955. if ((!base || base == component) && parts.length > 1)
  17956. base = parts[parts.length - 2];
  17957. var path = options[component + "Path"];
  17958. if (path == null) {
  17959. path = options.basePath;
  17960. } else if (sep == "/") {
  17961. component = sep = "";
  17962. }
  17963. if (path && path.slice(-1) != "/")
  17964. path += "/";
  17965. return path + component + sep + base + this.get("suffix");
  17966. };
  17967. exports.setModuleUrl = function(name, subst) {
  17968. return options.$moduleUrls[name] = subst;
  17969. };
  17970. exports.$loading = {};
  17971. exports.loadModule = function(moduleName, onLoad) {
  17972. var module, moduleType;
  17973. if (Array.isArray(moduleName)) {
  17974. moduleType = moduleName[0];
  17975. moduleName = moduleName[1];
  17976. }
  17977. try {
  17978. module = acequire(moduleName);
  17979. } catch (e) {}
  17980. if (module && !exports.$loading[moduleName])
  17981. return onLoad && onLoad(module);
  17982. if (!exports.$loading[moduleName])
  17983. exports.$loading[moduleName] = [];
  17984. exports.$loading[moduleName].push(onLoad);
  17985. if (exports.$loading[moduleName].length > 1)
  17986. return;
  17987. var afterLoad = function() {
  17988. acequire([moduleName], function(module) {
  17989. exports._emit("load.module", {name: moduleName, module: module});
  17990. var listeners = exports.$loading[moduleName];
  17991. exports.$loading[moduleName] = null;
  17992. listeners.forEach(function(onLoad) {
  17993. onLoad && onLoad(module);
  17994. });
  17995. });
  17996. };
  17997. if (!exports.get("packaged"))
  17998. return afterLoad();
  17999. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  18000. };
  18001. init(true);function init(packaged) {
  18002. if (!global || !global.document)
  18003. return;
  18004. options.packaged = packaged || acequire.packaged || module.packaged || (global.define && __webpack_require__(65).packaged);
  18005. var scriptOptions = {};
  18006. var scriptUrl = "";
  18007. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  18008. var currentDocument = currentScript && currentScript.ownerDocument || document;
  18009. var scripts = currentDocument.getElementsByTagName("script");
  18010. for (var i=0; i<scripts.length; i++) {
  18011. var script = scripts[i];
  18012. var src = script.src || script.getAttribute("src");
  18013. if (!src)
  18014. continue;
  18015. var attributes = script.attributes;
  18016. for (var j=0, l=attributes.length; j < l; j++) {
  18017. var attr = attributes[j];
  18018. if (attr.name.indexOf("data-ace-") === 0) {
  18019. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  18020. }
  18021. }
  18022. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  18023. if (m)
  18024. scriptUrl = m[1];
  18025. }
  18026. if (scriptUrl) {
  18027. scriptOptions.base = scriptOptions.base || scriptUrl;
  18028. scriptOptions.packaged = true;
  18029. }
  18030. scriptOptions.basePath = scriptOptions.base;
  18031. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  18032. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  18033. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  18034. delete scriptOptions.base;
  18035. for (var key in scriptOptions)
  18036. if (typeof scriptOptions[key] !== "undefined")
  18037. exports.set(key, scriptOptions[key]);
  18038. }
  18039. exports.init = init;
  18040. function deHyphenate(str) {
  18041. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  18042. }
  18043. });
  18044. ace.define("ace/mouse/mouse_handler",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/mouse/default_handlers","ace/mouse/default_gutter_handler","ace/mouse/mouse_event","ace/mouse/dragdrop_handler","ace/config"], function(acequire, exports, module) {
  18045. "use strict";
  18046. var event = acequire("../lib/event");
  18047. var useragent = acequire("../lib/useragent");
  18048. var DefaultHandlers = acequire("./default_handlers").DefaultHandlers;
  18049. var DefaultGutterHandler = acequire("./default_gutter_handler").GutterHandler;
  18050. var MouseEvent = acequire("./mouse_event").MouseEvent;
  18051. var DragdropHandler = acequire("./dragdrop_handler").DragdropHandler;
  18052. var config = acequire("../config");
  18053. var MouseHandler = function(editor) {
  18054. var _self = this;
  18055. this.editor = editor;
  18056. new DefaultHandlers(this);
  18057. new DefaultGutterHandler(this);
  18058. new DragdropHandler(this);
  18059. var focusEditor = function(e) {
  18060. var windowBlurred = !document.hasFocus || !document.hasFocus()
  18061. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement())
  18062. if (windowBlurred)
  18063. window.focus();
  18064. editor.focus();
  18065. };
  18066. var mouseTarget = editor.renderer.getMouseEventTarget();
  18067. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  18068. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  18069. event.addMultiMouseDownListener([
  18070. mouseTarget,
  18071. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  18072. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  18073. editor.textInput && editor.textInput.getElement()
  18074. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  18075. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  18076. event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
  18077. var gutterEl = editor.renderer.$gutter;
  18078. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  18079. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  18080. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  18081. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  18082. event.addListener(mouseTarget, "mousedown", focusEditor);
  18083. event.addListener(gutterEl, "mousedown", focusEditor);
  18084. if (useragent.isIE && editor.renderer.scrollBarV) {
  18085. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  18086. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  18087. }
  18088. editor.on("mousemove", function(e){
  18089. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  18090. return;
  18091. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  18092. var range = editor.session.selection.getRange();
  18093. var renderer = editor.renderer;
  18094. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  18095. renderer.setCursorStyle("default");
  18096. } else {
  18097. renderer.setCursorStyle("");
  18098. }
  18099. });
  18100. };
  18101. (function() {
  18102. this.onMouseEvent = function(name, e) {
  18103. this.editor._emit(name, new MouseEvent(e, this.editor));
  18104. };
  18105. this.onMouseMove = function(name, e) {
  18106. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  18107. if (!listeners || !listeners.length)
  18108. return;
  18109. this.editor._emit(name, new MouseEvent(e, this.editor));
  18110. };
  18111. this.onMouseWheel = function(name, e) {
  18112. var mouseEvent = new MouseEvent(e, this.editor);
  18113. mouseEvent.speed = this.$scrollSpeed * 2;
  18114. mouseEvent.wheelX = e.wheelX;
  18115. mouseEvent.wheelY = e.wheelY;
  18116. this.editor._emit(name, mouseEvent);
  18117. };
  18118. this.onTouchMove = function (name, e) {
  18119. var mouseEvent = new MouseEvent(e, this.editor);
  18120. mouseEvent.speed = 1;//this.$scrollSpeed * 2;
  18121. mouseEvent.wheelX = e.wheelX;
  18122. mouseEvent.wheelY = e.wheelY;
  18123. this.editor._emit(name, mouseEvent);
  18124. };
  18125. this.setState = function(state) {
  18126. this.state = state;
  18127. };
  18128. this.captureMouse = function(ev, mouseMoveHandler) {
  18129. this.x = ev.x;
  18130. this.y = ev.y;
  18131. this.isMousePressed = true;
  18132. var renderer = this.editor.renderer;
  18133. if (renderer.$keepTextAreaAtCursor)
  18134. renderer.$keepTextAreaAtCursor = null;
  18135. var self = this;
  18136. var onMouseMove = function(e) {
  18137. if (!e) return;
  18138. if (useragent.isWebKit && !e.which && self.releaseMouse)
  18139. return self.releaseMouse();
  18140. self.x = e.clientX;
  18141. self.y = e.clientY;
  18142. mouseMoveHandler && mouseMoveHandler(e);
  18143. self.mouseEvent = new MouseEvent(e, self.editor);
  18144. self.$mouseMoved = true;
  18145. };
  18146. var onCaptureEnd = function(e) {
  18147. clearInterval(timerId);
  18148. onCaptureInterval();
  18149. self[self.state + "End"] && self[self.state + "End"](e);
  18150. self.state = "";
  18151. if (renderer.$keepTextAreaAtCursor == null) {
  18152. renderer.$keepTextAreaAtCursor = true;
  18153. renderer.$moveTextAreaToCursor();
  18154. }
  18155. self.isMousePressed = false;
  18156. self.$onCaptureMouseMove = self.releaseMouse = null;
  18157. e && self.onMouseEvent("mouseup", e);
  18158. };
  18159. var onCaptureInterval = function() {
  18160. self[self.state] && self[self.state]();
  18161. self.$mouseMoved = false;
  18162. };
  18163. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  18164. return setTimeout(function() {onCaptureEnd(ev);});
  18165. }
  18166. self.$onCaptureMouseMove = onMouseMove;
  18167. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  18168. var timerId = setInterval(onCaptureInterval, 20);
  18169. };
  18170. this.releaseMouse = null;
  18171. this.cancelContextMenu = function() {
  18172. var stop = function(e) {
  18173. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  18174. return;
  18175. this.editor.off("nativecontextmenu", stop);
  18176. if (e && e.domEvent)
  18177. event.stopEvent(e.domEvent);
  18178. }.bind(this);
  18179. setTimeout(stop, 10);
  18180. this.editor.on("nativecontextmenu", stop);
  18181. };
  18182. }).call(MouseHandler.prototype);
  18183. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  18184. scrollSpeed: {initialValue: 2},
  18185. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  18186. dragEnabled: {initialValue: true},
  18187. focusTimout: {initialValue: 0},
  18188. tooltipFollowsMouse: {initialValue: true}
  18189. });
  18190. exports.MouseHandler = MouseHandler;
  18191. });
  18192. ace.define("ace/mouse/fold_handler",["require","exports","module"], function(acequire, exports, module) {
  18193. "use strict";
  18194. function FoldHandler(editor) {
  18195. editor.on("click", function(e) {
  18196. var position = e.getDocumentPosition();
  18197. var session = editor.session;
  18198. var fold = session.getFoldAt(position.row, position.column, 1);
  18199. if (fold) {
  18200. if (e.getAccelKey())
  18201. session.removeFold(fold);
  18202. else
  18203. session.expandFold(fold);
  18204. e.stop();
  18205. }
  18206. });
  18207. editor.on("gutterclick", function(e) {
  18208. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  18209. if (gutterRegion == "foldWidgets") {
  18210. var row = e.getDocumentPosition().row;
  18211. var session = editor.session;
  18212. if (session.foldWidgets && session.foldWidgets[row])
  18213. editor.session.onFoldWidgetClick(row, e);
  18214. if (!editor.isFocused())
  18215. editor.focus();
  18216. e.stop();
  18217. }
  18218. });
  18219. editor.on("gutterdblclick", function(e) {
  18220. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  18221. if (gutterRegion == "foldWidgets") {
  18222. var row = e.getDocumentPosition().row;
  18223. var session = editor.session;
  18224. var data = session.getParentFoldRangeData(row, true);
  18225. var range = data.range || data.firstRange;
  18226. if (range) {
  18227. row = range.start.row;
  18228. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  18229. if (fold) {
  18230. session.removeFold(fold);
  18231. } else {
  18232. session.addFold("...", range);
  18233. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  18234. }
  18235. }
  18236. e.stop();
  18237. }
  18238. });
  18239. }
  18240. exports.FoldHandler = FoldHandler;
  18241. });
  18242. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(acequire, exports, module) {
  18243. "use strict";
  18244. var keyUtil = acequire("../lib/keys");
  18245. var event = acequire("../lib/event");
  18246. var KeyBinding = function(editor) {
  18247. this.$editor = editor;
  18248. this.$data = {editor: editor};
  18249. this.$handlers = [];
  18250. this.setDefaultHandler(editor.commands);
  18251. };
  18252. (function() {
  18253. this.setDefaultHandler = function(kb) {
  18254. this.removeKeyboardHandler(this.$defaultHandler);
  18255. this.$defaultHandler = kb;
  18256. this.addKeyboardHandler(kb, 0);
  18257. };
  18258. this.setKeyboardHandler = function(kb) {
  18259. var h = this.$handlers;
  18260. if (h[h.length - 1] == kb)
  18261. return;
  18262. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  18263. this.removeKeyboardHandler(h[h.length - 1]);
  18264. this.addKeyboardHandler(kb, 1);
  18265. };
  18266. this.addKeyboardHandler = function(kb, pos) {
  18267. if (!kb)
  18268. return;
  18269. if (typeof kb == "function" && !kb.handleKeyboard)
  18270. kb.handleKeyboard = kb;
  18271. var i = this.$handlers.indexOf(kb);
  18272. if (i != -1)
  18273. this.$handlers.splice(i, 1);
  18274. if (pos == undefined)
  18275. this.$handlers.push(kb);
  18276. else
  18277. this.$handlers.splice(pos, 0, kb);
  18278. if (i == -1 && kb.attach)
  18279. kb.attach(this.$editor);
  18280. };
  18281. this.removeKeyboardHandler = function(kb) {
  18282. var i = this.$handlers.indexOf(kb);
  18283. if (i == -1)
  18284. return false;
  18285. this.$handlers.splice(i, 1);
  18286. kb.detach && kb.detach(this.$editor);
  18287. return true;
  18288. };
  18289. this.getKeyboardHandler = function() {
  18290. return this.$handlers[this.$handlers.length - 1];
  18291. };
  18292. this.getStatusText = function() {
  18293. var data = this.$data;
  18294. var editor = data.editor;
  18295. return this.$handlers.map(function(h) {
  18296. return h.getStatusText && h.getStatusText(editor, data) || "";
  18297. }).filter(Boolean).join(" ");
  18298. };
  18299. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  18300. var toExecute;
  18301. var success = false;
  18302. var commands = this.$editor.commands;
  18303. for (var i = this.$handlers.length; i--;) {
  18304. toExecute = this.$handlers[i].handleKeyboard(
  18305. this.$data, hashId, keyString, keyCode, e
  18306. );
  18307. if (!toExecute || !toExecute.command)
  18308. continue;
  18309. if (toExecute.command == "null") {
  18310. success = true;
  18311. } else {
  18312. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  18313. }
  18314. if (success && e && hashId != -1 &&
  18315. toExecute.passEvent != true && toExecute.command.passEvent != true
  18316. ) {
  18317. event.stopEvent(e);
  18318. }
  18319. if (success)
  18320. break;
  18321. }
  18322. if (!success && hashId == -1) {
  18323. toExecute = {command: "insertstring"};
  18324. success = commands.exec("insertstring", this.$editor, keyString);
  18325. }
  18326. if (success)
  18327. this.$editor._signal("keyboardActivity", toExecute);
  18328. return success;
  18329. };
  18330. this.onCommandKey = function(e, hashId, keyCode) {
  18331. var keyString = keyUtil.keyCodeToString(keyCode);
  18332. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  18333. };
  18334. this.onTextInput = function(text) {
  18335. this.$callKeyboardHandlers(-1, text);
  18336. };
  18337. }).call(KeyBinding.prototype);
  18338. exports.KeyBinding = KeyBinding;
  18339. });
  18340. ace.define("ace/range",["require","exports","module"], function(acequire, exports, module) {
  18341. "use strict";
  18342. var comparePoints = function(p1, p2) {
  18343. return p1.row - p2.row || p1.column - p2.column;
  18344. };
  18345. var Range = function(startRow, startColumn, endRow, endColumn) {
  18346. this.start = {
  18347. row: startRow,
  18348. column: startColumn
  18349. };
  18350. this.end = {
  18351. row: endRow,
  18352. column: endColumn
  18353. };
  18354. };
  18355. (function() {
  18356. this.isEqual = function(range) {
  18357. return this.start.row === range.start.row &&
  18358. this.end.row === range.end.row &&
  18359. this.start.column === range.start.column &&
  18360. this.end.column === range.end.column;
  18361. };
  18362. this.toString = function() {
  18363. return ("Range: [" + this.start.row + "/" + this.start.column +
  18364. "] -> [" + this.end.row + "/" + this.end.column + "]");
  18365. };
  18366. this.contains = function(row, column) {
  18367. return this.compare(row, column) == 0;
  18368. };
  18369. this.compareRange = function(range) {
  18370. var cmp,
  18371. end = range.end,
  18372. start = range.start;
  18373. cmp = this.compare(end.row, end.column);
  18374. if (cmp == 1) {
  18375. cmp = this.compare(start.row, start.column);
  18376. if (cmp == 1) {
  18377. return 2;
  18378. } else if (cmp == 0) {
  18379. return 1;
  18380. } else {
  18381. return 0;
  18382. }
  18383. } else if (cmp == -1) {
  18384. return -2;
  18385. } else {
  18386. cmp = this.compare(start.row, start.column);
  18387. if (cmp == -1) {
  18388. return -1;
  18389. } else if (cmp == 1) {
  18390. return 42;
  18391. } else {
  18392. return 0;
  18393. }
  18394. }
  18395. };
  18396. this.comparePoint = function(p) {
  18397. return this.compare(p.row, p.column);
  18398. };
  18399. this.containsRange = function(range) {
  18400. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  18401. };
  18402. this.intersects = function(range) {
  18403. var cmp = this.compareRange(range);
  18404. return (cmp == -1 || cmp == 0 || cmp == 1);
  18405. };
  18406. this.isEnd = function(row, column) {
  18407. return this.end.row == row && this.end.column == column;
  18408. };
  18409. this.isStart = function(row, column) {
  18410. return this.start.row == row && this.start.column == column;
  18411. };
  18412. this.setStart = function(row, column) {
  18413. if (typeof row == "object") {
  18414. this.start.column = row.column;
  18415. this.start.row = row.row;
  18416. } else {
  18417. this.start.row = row;
  18418. this.start.column = column;
  18419. }
  18420. };
  18421. this.setEnd = function(row, column) {
  18422. if (typeof row == "object") {
  18423. this.end.column = row.column;
  18424. this.end.row = row.row;
  18425. } else {
  18426. this.end.row = row;
  18427. this.end.column = column;
  18428. }
  18429. };
  18430. this.inside = function(row, column) {
  18431. if (this.compare(row, column) == 0) {
  18432. if (this.isEnd(row, column) || this.isStart(row, column)) {
  18433. return false;
  18434. } else {
  18435. return true;
  18436. }
  18437. }
  18438. return false;
  18439. };
  18440. this.insideStart = function(row, column) {
  18441. if (this.compare(row, column) == 0) {
  18442. if (this.isEnd(row, column)) {
  18443. return false;
  18444. } else {
  18445. return true;
  18446. }
  18447. }
  18448. return false;
  18449. };
  18450. this.insideEnd = function(row, column) {
  18451. if (this.compare(row, column) == 0) {
  18452. if (this.isStart(row, column)) {
  18453. return false;
  18454. } else {
  18455. return true;
  18456. }
  18457. }
  18458. return false;
  18459. };
  18460. this.compare = function(row, column) {
  18461. if (!this.isMultiLine()) {
  18462. if (row === this.start.row) {
  18463. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  18464. }
  18465. }
  18466. if (row < this.start.row)
  18467. return -1;
  18468. if (row > this.end.row)
  18469. return 1;
  18470. if (this.start.row === row)
  18471. return column >= this.start.column ? 0 : -1;
  18472. if (this.end.row === row)
  18473. return column <= this.end.column ? 0 : 1;
  18474. return 0;
  18475. };
  18476. this.compareStart = function(row, column) {
  18477. if (this.start.row == row && this.start.column == column) {
  18478. return -1;
  18479. } else {
  18480. return this.compare(row, column);
  18481. }
  18482. };
  18483. this.compareEnd = function(row, column) {
  18484. if (this.end.row == row && this.end.column == column) {
  18485. return 1;
  18486. } else {
  18487. return this.compare(row, column);
  18488. }
  18489. };
  18490. this.compareInside = function(row, column) {
  18491. if (this.end.row == row && this.end.column == column) {
  18492. return 1;
  18493. } else if (this.start.row == row && this.start.column == column) {
  18494. return -1;
  18495. } else {
  18496. return this.compare(row, column);
  18497. }
  18498. };
  18499. this.clipRows = function(firstRow, lastRow) {
  18500. if (this.end.row > lastRow)
  18501. var end = {row: lastRow + 1, column: 0};
  18502. else if (this.end.row < firstRow)
  18503. var end = {row: firstRow, column: 0};
  18504. if (this.start.row > lastRow)
  18505. var start = {row: lastRow + 1, column: 0};
  18506. else if (this.start.row < firstRow)
  18507. var start = {row: firstRow, column: 0};
  18508. return Range.fromPoints(start || this.start, end || this.end);
  18509. };
  18510. this.extend = function(row, column) {
  18511. var cmp = this.compare(row, column);
  18512. if (cmp == 0)
  18513. return this;
  18514. else if (cmp == -1)
  18515. var start = {row: row, column: column};
  18516. else
  18517. var end = {row: row, column: column};
  18518. return Range.fromPoints(start || this.start, end || this.end);
  18519. };
  18520. this.isEmpty = function() {
  18521. return (this.start.row === this.end.row && this.start.column === this.end.column);
  18522. };
  18523. this.isMultiLine = function() {
  18524. return (this.start.row !== this.end.row);
  18525. };
  18526. this.clone = function() {
  18527. return Range.fromPoints(this.start, this.end);
  18528. };
  18529. this.collapseRows = function() {
  18530. if (this.end.column == 0)
  18531. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  18532. else
  18533. return new Range(this.start.row, 0, this.end.row, 0)
  18534. };
  18535. this.toScreenRange = function(session) {
  18536. var screenPosStart = session.documentToScreenPosition(this.start);
  18537. var screenPosEnd = session.documentToScreenPosition(this.end);
  18538. return new Range(
  18539. screenPosStart.row, screenPosStart.column,
  18540. screenPosEnd.row, screenPosEnd.column
  18541. );
  18542. };
  18543. this.moveBy = function(row, column) {
  18544. this.start.row += row;
  18545. this.start.column += column;
  18546. this.end.row += row;
  18547. this.end.column += column;
  18548. };
  18549. }).call(Range.prototype);
  18550. Range.fromPoints = function(start, end) {
  18551. return new Range(start.row, start.column, end.row, end.column);
  18552. };
  18553. Range.comparePoints = comparePoints;
  18554. Range.comparePoints = function(p1, p2) {
  18555. return p1.row - p2.row || p1.column - p2.column;
  18556. };
  18557. exports.Range = Range;
  18558. });
  18559. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(acequire, exports, module) {
  18560. "use strict";
  18561. var oop = acequire("./lib/oop");
  18562. var lang = acequire("./lib/lang");
  18563. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  18564. var Range = acequire("./range").Range;
  18565. var Selection = function(session) {
  18566. this.session = session;
  18567. this.doc = session.getDocument();
  18568. this.clearSelection();
  18569. this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
  18570. this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
  18571. var self = this;
  18572. this.lead.on("change", function(e) {
  18573. self._emit("changeCursor");
  18574. if (!self.$isEmpty)
  18575. self._emit("changeSelection");
  18576. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  18577. self.$desiredColumn = null;
  18578. });
  18579. this.selectionAnchor.on("change", function() {
  18580. if (!self.$isEmpty)
  18581. self._emit("changeSelection");
  18582. });
  18583. };
  18584. (function() {
  18585. oop.implement(this, EventEmitter);
  18586. this.isEmpty = function() {
  18587. return (this.$isEmpty || (
  18588. this.anchor.row == this.lead.row &&
  18589. this.anchor.column == this.lead.column
  18590. ));
  18591. };
  18592. this.isMultiLine = function() {
  18593. if (this.isEmpty()) {
  18594. return false;
  18595. }
  18596. return this.getRange().isMultiLine();
  18597. };
  18598. this.getCursor = function() {
  18599. return this.lead.getPosition();
  18600. };
  18601. this.setSelectionAnchor = function(row, column) {
  18602. this.anchor.setPosition(row, column);
  18603. if (this.$isEmpty) {
  18604. this.$isEmpty = false;
  18605. this._emit("changeSelection");
  18606. }
  18607. };
  18608. this.getSelectionAnchor = function() {
  18609. if (this.$isEmpty)
  18610. return this.getSelectionLead();
  18611. else
  18612. return this.anchor.getPosition();
  18613. };
  18614. this.getSelectionLead = function() {
  18615. return this.lead.getPosition();
  18616. };
  18617. this.shiftSelection = function(columns) {
  18618. if (this.$isEmpty) {
  18619. this.moveCursorTo(this.lead.row, this.lead.column + columns);
  18620. return;
  18621. }
  18622. var anchor = this.getSelectionAnchor();
  18623. var lead = this.getSelectionLead();
  18624. var isBackwards = this.isBackwards();
  18625. if (!isBackwards || anchor.column !== 0)
  18626. this.setSelectionAnchor(anchor.row, anchor.column + columns);
  18627. if (isBackwards || lead.column !== 0) {
  18628. this.$moveSelection(function() {
  18629. this.moveCursorTo(lead.row, lead.column + columns);
  18630. });
  18631. }
  18632. };
  18633. this.isBackwards = function() {
  18634. var anchor = this.anchor;
  18635. var lead = this.lead;
  18636. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  18637. };
  18638. this.getRange = function() {
  18639. var anchor = this.anchor;
  18640. var lead = this.lead;
  18641. if (this.isEmpty())
  18642. return Range.fromPoints(lead, lead);
  18643. if (this.isBackwards()) {
  18644. return Range.fromPoints(lead, anchor);
  18645. }
  18646. else {
  18647. return Range.fromPoints(anchor, lead);
  18648. }
  18649. };
  18650. this.clearSelection = function() {
  18651. if (!this.$isEmpty) {
  18652. this.$isEmpty = true;
  18653. this._emit("changeSelection");
  18654. }
  18655. };
  18656. this.selectAll = function() {
  18657. var lastRow = this.doc.getLength() - 1;
  18658. this.setSelectionAnchor(0, 0);
  18659. this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
  18660. };
  18661. this.setRange =
  18662. this.setSelectionRange = function(range, reverse) {
  18663. if (reverse) {
  18664. this.setSelectionAnchor(range.end.row, range.end.column);
  18665. this.selectTo(range.start.row, range.start.column);
  18666. } else {
  18667. this.setSelectionAnchor(range.start.row, range.start.column);
  18668. this.selectTo(range.end.row, range.end.column);
  18669. }
  18670. if (this.getRange().isEmpty())
  18671. this.$isEmpty = true;
  18672. this.$desiredColumn = null;
  18673. };
  18674. this.$moveSelection = function(mover) {
  18675. var lead = this.lead;
  18676. if (this.$isEmpty)
  18677. this.setSelectionAnchor(lead.row, lead.column);
  18678. mover.call(this);
  18679. };
  18680. this.selectTo = function(row, column) {
  18681. this.$moveSelection(function() {
  18682. this.moveCursorTo(row, column);
  18683. });
  18684. };
  18685. this.selectToPosition = function(pos) {
  18686. this.$moveSelection(function() {
  18687. this.moveCursorToPosition(pos);
  18688. });
  18689. };
  18690. this.moveTo = function(row, column) {
  18691. this.clearSelection();
  18692. this.moveCursorTo(row, column);
  18693. };
  18694. this.moveToPosition = function(pos) {
  18695. this.clearSelection();
  18696. this.moveCursorToPosition(pos);
  18697. };
  18698. this.selectUp = function() {
  18699. this.$moveSelection(this.moveCursorUp);
  18700. };
  18701. this.selectDown = function() {
  18702. this.$moveSelection(this.moveCursorDown);
  18703. };
  18704. this.selectRight = function() {
  18705. this.$moveSelection(this.moveCursorRight);
  18706. };
  18707. this.selectLeft = function() {
  18708. this.$moveSelection(this.moveCursorLeft);
  18709. };
  18710. this.selectLineStart = function() {
  18711. this.$moveSelection(this.moveCursorLineStart);
  18712. };
  18713. this.selectLineEnd = function() {
  18714. this.$moveSelection(this.moveCursorLineEnd);
  18715. };
  18716. this.selectFileEnd = function() {
  18717. this.$moveSelection(this.moveCursorFileEnd);
  18718. };
  18719. this.selectFileStart = function() {
  18720. this.$moveSelection(this.moveCursorFileStart);
  18721. };
  18722. this.selectWordRight = function() {
  18723. this.$moveSelection(this.moveCursorWordRight);
  18724. };
  18725. this.selectWordLeft = function() {
  18726. this.$moveSelection(this.moveCursorWordLeft);
  18727. };
  18728. this.getWordRange = function(row, column) {
  18729. if (typeof column == "undefined") {
  18730. var cursor = row || this.lead;
  18731. row = cursor.row;
  18732. column = cursor.column;
  18733. }
  18734. return this.session.getWordRange(row, column);
  18735. };
  18736. this.selectWord = function() {
  18737. this.setSelectionRange(this.getWordRange());
  18738. };
  18739. this.selectAWord = function() {
  18740. var cursor = this.getCursor();
  18741. var range = this.session.getAWordRange(cursor.row, cursor.column);
  18742. this.setSelectionRange(range);
  18743. };
  18744. this.getLineRange = function(row, excludeLastChar) {
  18745. var rowStart = typeof row == "number" ? row : this.lead.row;
  18746. var rowEnd;
  18747. var foldLine = this.session.getFoldLine(rowStart);
  18748. if (foldLine) {
  18749. rowStart = foldLine.start.row;
  18750. rowEnd = foldLine.end.row;
  18751. } else {
  18752. rowEnd = rowStart;
  18753. }
  18754. if (excludeLastChar === true)
  18755. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  18756. else
  18757. return new Range(rowStart, 0, rowEnd + 1, 0);
  18758. };
  18759. this.selectLine = function() {
  18760. this.setSelectionRange(this.getLineRange());
  18761. };
  18762. this.moveCursorUp = function() {
  18763. this.moveCursorBy(-1, 0);
  18764. };
  18765. this.moveCursorDown = function() {
  18766. this.moveCursorBy(1, 0);
  18767. };
  18768. this.moveCursorLeft = function() {
  18769. var cursor = this.lead.getPosition(),
  18770. fold;
  18771. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  18772. this.moveCursorTo(fold.start.row, fold.start.column);
  18773. } else if (cursor.column === 0) {
  18774. if (cursor.row > 0) {
  18775. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  18776. }
  18777. }
  18778. else {
  18779. var tabSize = this.session.getTabSize();
  18780. if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column-tabSize, cursor.column).split(" ").length-1 == tabSize)
  18781. this.moveCursorBy(0, -tabSize);
  18782. else
  18783. this.moveCursorBy(0, -1);
  18784. }
  18785. };
  18786. this.moveCursorRight = function() {
  18787. var cursor = this.lead.getPosition(),
  18788. fold;
  18789. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  18790. this.moveCursorTo(fold.end.row, fold.end.column);
  18791. }
  18792. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  18793. if (this.lead.row < this.doc.getLength() - 1) {
  18794. this.moveCursorTo(this.lead.row + 1, 0);
  18795. }
  18796. }
  18797. else {
  18798. var tabSize = this.session.getTabSize();
  18799. var cursor = this.lead;
  18800. if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize)
  18801. this.moveCursorBy(0, tabSize);
  18802. else
  18803. this.moveCursorBy(0, 1);
  18804. }
  18805. };
  18806. this.moveCursorLineStart = function() {
  18807. var row = this.lead.row;
  18808. var column = this.lead.column;
  18809. var screenRow = this.session.documentToScreenRow(row, column);
  18810. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  18811. var beforeCursor = this.session.getDisplayLine(
  18812. row, null, firstColumnPosition.row,
  18813. firstColumnPosition.column
  18814. );
  18815. var leadingSpace = beforeCursor.match(/^\s*/);
  18816. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  18817. firstColumnPosition.column += leadingSpace[0].length;
  18818. this.moveCursorToPosition(firstColumnPosition);
  18819. };
  18820. this.moveCursorLineEnd = function() {
  18821. var lead = this.lead;
  18822. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  18823. if (this.lead.column == lineEnd.column) {
  18824. var line = this.session.getLine(lineEnd.row);
  18825. if (lineEnd.column == line.length) {
  18826. var textEnd = line.search(/\s+$/);
  18827. if (textEnd > 0)
  18828. lineEnd.column = textEnd;
  18829. }
  18830. }
  18831. this.moveCursorTo(lineEnd.row, lineEnd.column);
  18832. };
  18833. this.moveCursorFileEnd = function() {
  18834. var row = this.doc.getLength() - 1;
  18835. var column = this.doc.getLine(row).length;
  18836. this.moveCursorTo(row, column);
  18837. };
  18838. this.moveCursorFileStart = function() {
  18839. this.moveCursorTo(0, 0);
  18840. };
  18841. this.moveCursorLongWordRight = function() {
  18842. var row = this.lead.row;
  18843. var column = this.lead.column;
  18844. var line = this.doc.getLine(row);
  18845. var rightOfCursor = line.substring(column);
  18846. var match;
  18847. this.session.nonTokenRe.lastIndex = 0;
  18848. this.session.tokenRe.lastIndex = 0;
  18849. var fold = this.session.getFoldAt(row, column, 1);
  18850. if (fold) {
  18851. this.moveCursorTo(fold.end.row, fold.end.column);
  18852. return;
  18853. }
  18854. if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
  18855. column += this.session.nonTokenRe.lastIndex;
  18856. this.session.nonTokenRe.lastIndex = 0;
  18857. rightOfCursor = line.substring(column);
  18858. }
  18859. if (column >= line.length) {
  18860. this.moveCursorTo(row, line.length);
  18861. this.moveCursorRight();
  18862. if (row < this.doc.getLength() - 1)
  18863. this.moveCursorWordRight();
  18864. return;
  18865. }
  18866. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  18867. column += this.session.tokenRe.lastIndex;
  18868. this.session.tokenRe.lastIndex = 0;
  18869. }
  18870. this.moveCursorTo(row, column);
  18871. };
  18872. this.moveCursorLongWordLeft = function() {
  18873. var row = this.lead.row;
  18874. var column = this.lead.column;
  18875. var fold;
  18876. if (fold = this.session.getFoldAt(row, column, -1)) {
  18877. this.moveCursorTo(fold.start.row, fold.start.column);
  18878. return;
  18879. }
  18880. var str = this.session.getFoldStringAt(row, column, -1);
  18881. if (str == null) {
  18882. str = this.doc.getLine(row).substring(0, column);
  18883. }
  18884. var leftOfCursor = lang.stringReverse(str);
  18885. var match;
  18886. this.session.nonTokenRe.lastIndex = 0;
  18887. this.session.tokenRe.lastIndex = 0;
  18888. if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
  18889. column -= this.session.nonTokenRe.lastIndex;
  18890. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  18891. this.session.nonTokenRe.lastIndex = 0;
  18892. }
  18893. if (column <= 0) {
  18894. this.moveCursorTo(row, 0);
  18895. this.moveCursorLeft();
  18896. if (row > 0)
  18897. this.moveCursorWordLeft();
  18898. return;
  18899. }
  18900. if (match = this.session.tokenRe.exec(leftOfCursor)) {
  18901. column -= this.session.tokenRe.lastIndex;
  18902. this.session.tokenRe.lastIndex = 0;
  18903. }
  18904. this.moveCursorTo(row, column);
  18905. };
  18906. this.$shortWordEndIndex = function(rightOfCursor) {
  18907. var match, index = 0, ch;
  18908. var whitespaceRe = /\s/;
  18909. var tokenRe = this.session.tokenRe;
  18910. tokenRe.lastIndex = 0;
  18911. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  18912. index = this.session.tokenRe.lastIndex;
  18913. } else {
  18914. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  18915. index ++;
  18916. if (index < 1) {
  18917. tokenRe.lastIndex = 0;
  18918. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  18919. tokenRe.lastIndex = 0;
  18920. index ++;
  18921. if (whitespaceRe.test(ch)) {
  18922. if (index > 2) {
  18923. index--;
  18924. break;
  18925. } else {
  18926. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  18927. index ++;
  18928. if (index > 2)
  18929. break;
  18930. }
  18931. }
  18932. }
  18933. }
  18934. }
  18935. tokenRe.lastIndex = 0;
  18936. return index;
  18937. };
  18938. this.moveCursorShortWordRight = function() {
  18939. var row = this.lead.row;
  18940. var column = this.lead.column;
  18941. var line = this.doc.getLine(row);
  18942. var rightOfCursor = line.substring(column);
  18943. var fold = this.session.getFoldAt(row, column, 1);
  18944. if (fold)
  18945. return this.moveCursorTo(fold.end.row, fold.end.column);
  18946. if (column == line.length) {
  18947. var l = this.doc.getLength();
  18948. do {
  18949. row++;
  18950. rightOfCursor = this.doc.getLine(row);
  18951. } while (row < l && /^\s*$/.test(rightOfCursor));
  18952. if (!/^\s+/.test(rightOfCursor))
  18953. rightOfCursor = "";
  18954. column = 0;
  18955. }
  18956. var index = this.$shortWordEndIndex(rightOfCursor);
  18957. this.moveCursorTo(row, column + index);
  18958. };
  18959. this.moveCursorShortWordLeft = function() {
  18960. var row = this.lead.row;
  18961. var column = this.lead.column;
  18962. var fold;
  18963. if (fold = this.session.getFoldAt(row, column, -1))
  18964. return this.moveCursorTo(fold.start.row, fold.start.column);
  18965. var line = this.session.getLine(row).substring(0, column);
  18966. if (column === 0) {
  18967. do {
  18968. row--;
  18969. line = this.doc.getLine(row);
  18970. } while (row > 0 && /^\s*$/.test(line));
  18971. column = line.length;
  18972. if (!/\s+$/.test(line))
  18973. line = "";
  18974. }
  18975. var leftOfCursor = lang.stringReverse(line);
  18976. var index = this.$shortWordEndIndex(leftOfCursor);
  18977. return this.moveCursorTo(row, column - index);
  18978. };
  18979. this.moveCursorWordRight = function() {
  18980. if (this.session.$selectLongWords)
  18981. this.moveCursorLongWordRight();
  18982. else
  18983. this.moveCursorShortWordRight();
  18984. };
  18985. this.moveCursorWordLeft = function() {
  18986. if (this.session.$selectLongWords)
  18987. this.moveCursorLongWordLeft();
  18988. else
  18989. this.moveCursorShortWordLeft();
  18990. };
  18991. this.moveCursorBy = function(rows, chars) {
  18992. var screenPos = this.session.documentToScreenPosition(
  18993. this.lead.row,
  18994. this.lead.column
  18995. );
  18996. if (chars === 0) {
  18997. if (this.$desiredColumn)
  18998. screenPos.column = this.$desiredColumn;
  18999. else
  19000. this.$desiredColumn = screenPos.column;
  19001. }
  19002. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
  19003. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  19004. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  19005. if (docPos.row > 0 || rows > 0)
  19006. docPos.row++;
  19007. }
  19008. }
  19009. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  19010. };
  19011. this.moveCursorToPosition = function(position) {
  19012. this.moveCursorTo(position.row, position.column);
  19013. };
  19014. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  19015. var fold = this.session.getFoldAt(row, column, 1);
  19016. if (fold) {
  19017. row = fold.start.row;
  19018. column = fold.start.column;
  19019. }
  19020. this.$keepDesiredColumnOnChange = true;
  19021. this.lead.setPosition(row, column);
  19022. this.$keepDesiredColumnOnChange = false;
  19023. if (!keepDesiredColumn)
  19024. this.$desiredColumn = null;
  19025. };
  19026. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  19027. var pos = this.session.screenToDocumentPosition(row, column);
  19028. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  19029. };
  19030. this.detach = function() {
  19031. this.lead.detach();
  19032. this.anchor.detach();
  19033. this.session = this.doc = null;
  19034. };
  19035. this.fromOrientedRange = function(range) {
  19036. this.setSelectionRange(range, range.cursor == range.start);
  19037. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  19038. };
  19039. this.toOrientedRange = function(range) {
  19040. var r = this.getRange();
  19041. if (range) {
  19042. range.start.column = r.start.column;
  19043. range.start.row = r.start.row;
  19044. range.end.column = r.end.column;
  19045. range.end.row = r.end.row;
  19046. } else {
  19047. range = r;
  19048. }
  19049. range.cursor = this.isBackwards() ? range.start : range.end;
  19050. range.desiredColumn = this.$desiredColumn;
  19051. return range;
  19052. };
  19053. this.getRangeOfMovements = function(func) {
  19054. var start = this.getCursor();
  19055. try {
  19056. func(this);
  19057. var end = this.getCursor();
  19058. return Range.fromPoints(start,end);
  19059. } catch(e) {
  19060. return Range.fromPoints(start,start);
  19061. } finally {
  19062. this.moveCursorToPosition(start);
  19063. }
  19064. };
  19065. this.toJSON = function() {
  19066. if (this.rangeCount) {
  19067. var data = this.ranges.map(function(r) {
  19068. var r1 = r.clone();
  19069. r1.isBackwards = r.cursor == r.start;
  19070. return r1;
  19071. });
  19072. } else {
  19073. var data = this.getRange();
  19074. data.isBackwards = this.isBackwards();
  19075. }
  19076. return data;
  19077. };
  19078. this.fromJSON = function(data) {
  19079. if (data.start == undefined) {
  19080. if (this.rangeList) {
  19081. this.toSingleRange(data[0]);
  19082. for (var i = data.length; i--; ) {
  19083. var r = Range.fromPoints(data[i].start, data[i].end);
  19084. if (data[i].isBackwards)
  19085. r.cursor = r.start;
  19086. this.addRange(r, true);
  19087. }
  19088. return;
  19089. } else
  19090. data = data[0];
  19091. }
  19092. if (this.rangeList)
  19093. this.toSingleRange(data);
  19094. this.setSelectionRange(data, data.isBackwards);
  19095. };
  19096. this.isEqual = function(data) {
  19097. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  19098. return false;
  19099. if (!data.length || !this.ranges)
  19100. return this.getRange().isEqual(data);
  19101. for (var i = this.ranges.length; i--; ) {
  19102. if (!this.ranges[i].isEqual(data[i]))
  19103. return false;
  19104. }
  19105. return true;
  19106. };
  19107. }).call(Selection.prototype);
  19108. exports.Selection = Selection;
  19109. });
  19110. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(acequire, exports, module) {
  19111. "use strict";
  19112. var config = acequire("./config");
  19113. var MAX_TOKEN_COUNT = 2000;
  19114. var Tokenizer = function(rules) {
  19115. this.states = rules;
  19116. this.regExps = {};
  19117. this.matchMappings = {};
  19118. for (var key in this.states) {
  19119. var state = this.states[key];
  19120. var ruleRegExps = [];
  19121. var matchTotal = 0;
  19122. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  19123. var flag = "g";
  19124. var splitterRurles = [];
  19125. for (var i = 0; i < state.length; i++) {
  19126. var rule = state[i];
  19127. if (rule.defaultToken)
  19128. mapping.defaultToken = rule.defaultToken;
  19129. if (rule.caseInsensitive)
  19130. flag = "gi";
  19131. if (rule.regex == null)
  19132. continue;
  19133. if (rule.regex instanceof RegExp)
  19134. rule.regex = rule.regex.toString().slice(1, -1);
  19135. var adjustedregex = rule.regex;
  19136. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  19137. if (Array.isArray(rule.token)) {
  19138. if (rule.token.length == 1 || matchcount == 1) {
  19139. rule.token = rule.token[0];
  19140. } else if (matchcount - 1 != rule.token.length) {
  19141. this.reportError("number of classes and regexp groups doesn't match", {
  19142. rule: rule,
  19143. groupCount: matchcount - 1
  19144. });
  19145. rule.token = rule.token[0];
  19146. } else {
  19147. rule.tokenArray = rule.token;
  19148. rule.token = null;
  19149. rule.onMatch = this.$arrayTokens;
  19150. }
  19151. } else if (typeof rule.token == "function" && !rule.onMatch) {
  19152. if (matchcount > 1)
  19153. rule.onMatch = this.$applyToken;
  19154. else
  19155. rule.onMatch = rule.token;
  19156. }
  19157. if (matchcount > 1) {
  19158. if (/\\\d/.test(rule.regex)) {
  19159. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  19160. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  19161. });
  19162. } else {
  19163. matchcount = 1;
  19164. adjustedregex = this.removeCapturingGroups(rule.regex);
  19165. }
  19166. if (!rule.splitRegex && typeof rule.token != "string")
  19167. splitterRurles.push(rule); // flag will be known only at the very end
  19168. }
  19169. mapping[matchTotal] = i;
  19170. matchTotal += matchcount;
  19171. ruleRegExps.push(adjustedregex);
  19172. if (!rule.onMatch)
  19173. rule.onMatch = null;
  19174. }
  19175. if (!ruleRegExps.length) {
  19176. mapping[0] = 0;
  19177. ruleRegExps.push("$");
  19178. }
  19179. splitterRurles.forEach(function(rule) {
  19180. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  19181. }, this);
  19182. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  19183. }
  19184. };
  19185. (function() {
  19186. this.$setMaxTokenCount = function(m) {
  19187. MAX_TOKEN_COUNT = m | 0;
  19188. };
  19189. this.$applyToken = function(str) {
  19190. var values = this.splitRegex.exec(str).slice(1);
  19191. var types = this.token.apply(this, values);
  19192. if (typeof types === "string")
  19193. return [{type: types, value: str}];
  19194. var tokens = [];
  19195. for (var i = 0, l = types.length; i < l; i++) {
  19196. if (values[i])
  19197. tokens[tokens.length] = {
  19198. type: types[i],
  19199. value: values[i]
  19200. };
  19201. }
  19202. return tokens;
  19203. };
  19204. this.$arrayTokens = function(str) {
  19205. if (!str)
  19206. return [];
  19207. var values = this.splitRegex.exec(str);
  19208. if (!values)
  19209. return "text";
  19210. var tokens = [];
  19211. var types = this.tokenArray;
  19212. for (var i = 0, l = types.length; i < l; i++) {
  19213. if (values[i + 1])
  19214. tokens[tokens.length] = {
  19215. type: types[i],
  19216. value: values[i + 1]
  19217. };
  19218. }
  19219. return tokens;
  19220. };
  19221. this.removeCapturingGroups = function(src) {
  19222. var r = src.replace(
  19223. /\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g,
  19224. function(x, y) {return y ? "(?:" : x;}
  19225. );
  19226. return r;
  19227. };
  19228. this.createSplitterRegexp = function(src, flag) {
  19229. if (src.indexOf("(?=") != -1) {
  19230. var stack = 0;
  19231. var inChClass = false;
  19232. var lastCapture = {};
  19233. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  19234. m, esc, parenOpen, parenClose, square, index
  19235. ) {
  19236. if (inChClass) {
  19237. inChClass = square != "]";
  19238. } else if (square) {
  19239. inChClass = true;
  19240. } else if (parenClose) {
  19241. if (stack == lastCapture.stack) {
  19242. lastCapture.end = index+1;
  19243. lastCapture.stack = -1;
  19244. }
  19245. stack--;
  19246. } else if (parenOpen) {
  19247. stack++;
  19248. if (parenOpen.length != 1) {
  19249. lastCapture.stack = stack
  19250. lastCapture.start = index;
  19251. }
  19252. }
  19253. return m;
  19254. });
  19255. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  19256. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  19257. }
  19258. if (src.charAt(0) != "^") src = "^" + src;
  19259. if (src.charAt(src.length - 1) != "$") src += "$";
  19260. return new RegExp(src, (flag||"").replace("g", ""));
  19261. };
  19262. this.getLineTokens = function(line, startState) {
  19263. if (startState && typeof startState != "string") {
  19264. var stack = startState.slice(0);
  19265. startState = stack[0];
  19266. if (startState === "#tmp") {
  19267. stack.shift()
  19268. startState = stack.shift()
  19269. }
  19270. } else
  19271. var stack = [];
  19272. var currentState = startState || "start";
  19273. var state = this.states[currentState];
  19274. if (!state) {
  19275. currentState = "start";
  19276. state = this.states[currentState];
  19277. }
  19278. var mapping = this.matchMappings[currentState];
  19279. var re = this.regExps[currentState];
  19280. re.lastIndex = 0;
  19281. var match, tokens = [];
  19282. var lastIndex = 0;
  19283. var matchAttempts = 0;
  19284. var token = {type: null, value: ""};
  19285. while (match = re.exec(line)) {
  19286. var type = mapping.defaultToken;
  19287. var rule = null;
  19288. var value = match[0];
  19289. var index = re.lastIndex;
  19290. if (index - value.length > lastIndex) {
  19291. var skipped = line.substring(lastIndex, index - value.length);
  19292. if (token.type == type) {
  19293. token.value += skipped;
  19294. } else {
  19295. if (token.type)
  19296. tokens.push(token);
  19297. token = {type: type, value: skipped};
  19298. }
  19299. }
  19300. for (var i = 0; i < match.length-2; i++) {
  19301. if (match[i + 1] === undefined)
  19302. continue;
  19303. rule = state[mapping[i]];
  19304. if (rule.onMatch)
  19305. type = rule.onMatch(value, currentState, stack);
  19306. else
  19307. type = rule.token;
  19308. if (rule.next) {
  19309. if (typeof rule.next == "string") {
  19310. currentState = rule.next;
  19311. } else {
  19312. currentState = rule.next(currentState, stack);
  19313. }
  19314. state = this.states[currentState];
  19315. if (!state) {
  19316. this.reportError("state doesn't exist", currentState);
  19317. currentState = "start";
  19318. state = this.states[currentState];
  19319. }
  19320. mapping = this.matchMappings[currentState];
  19321. lastIndex = index;
  19322. re = this.regExps[currentState];
  19323. re.lastIndex = index;
  19324. }
  19325. break;
  19326. }
  19327. if (value) {
  19328. if (typeof type === "string") {
  19329. if ((!rule || rule.merge !== false) && token.type === type) {
  19330. token.value += value;
  19331. } else {
  19332. if (token.type)
  19333. tokens.push(token);
  19334. token = {type: type, value: value};
  19335. }
  19336. } else if (type) {
  19337. if (token.type)
  19338. tokens.push(token);
  19339. token = {type: null, value: ""};
  19340. for (var i = 0; i < type.length; i++)
  19341. tokens.push(type[i]);
  19342. }
  19343. }
  19344. if (lastIndex == line.length)
  19345. break;
  19346. lastIndex = index;
  19347. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  19348. if (matchAttempts > 2 * line.length) {
  19349. this.reportError("infinite loop with in ace tokenizer", {
  19350. startState: startState,
  19351. line: line
  19352. });
  19353. }
  19354. while (lastIndex < line.length) {
  19355. if (token.type)
  19356. tokens.push(token);
  19357. token = {
  19358. value: line.substring(lastIndex, lastIndex += 2000),
  19359. type: "overflow"
  19360. };
  19361. }
  19362. currentState = "start";
  19363. stack = [];
  19364. break;
  19365. }
  19366. }
  19367. if (token.type)
  19368. tokens.push(token);
  19369. if (stack.length > 1) {
  19370. if (stack[0] !== currentState)
  19371. stack.unshift("#tmp", currentState);
  19372. }
  19373. return {
  19374. tokens : tokens,
  19375. state : stack.length ? stack : currentState
  19376. };
  19377. };
  19378. this.reportError = config.reportError;
  19379. }).call(Tokenizer.prototype);
  19380. exports.Tokenizer = Tokenizer;
  19381. });
  19382. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(acequire, exports, module) {
  19383. "use strict";
  19384. var lang = acequire("../lib/lang");
  19385. var TextHighlightRules = function() {
  19386. this.$rules = {
  19387. "start" : [{
  19388. token : "empty_line",
  19389. regex : '^$'
  19390. }, {
  19391. defaultToken : "text"
  19392. }]
  19393. };
  19394. };
  19395. (function() {
  19396. this.addRules = function(rules, prefix) {
  19397. if (!prefix) {
  19398. for (var key in rules)
  19399. this.$rules[key] = rules[key];
  19400. return;
  19401. }
  19402. for (var key in rules) {
  19403. var state = rules[key];
  19404. for (var i = 0; i < state.length; i++) {
  19405. var rule = state[i];
  19406. if (rule.next || rule.onMatch) {
  19407. if (typeof rule.next == "string") {
  19408. if (rule.next.indexOf(prefix) !== 0)
  19409. rule.next = prefix + rule.next;
  19410. }
  19411. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  19412. rule.nextState = prefix + rule.nextState;
  19413. }
  19414. }
  19415. this.$rules[prefix + key] = state;
  19416. }
  19417. };
  19418. this.getRules = function() {
  19419. return this.$rules;
  19420. };
  19421. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  19422. var embedRules = typeof HighlightRules == "function"
  19423. ? new HighlightRules().getRules()
  19424. : HighlightRules;
  19425. if (states) {
  19426. for (var i = 0; i < states.length; i++)
  19427. states[i] = prefix + states[i];
  19428. } else {
  19429. states = [];
  19430. for (var key in embedRules)
  19431. states.push(prefix + key);
  19432. }
  19433. this.addRules(embedRules, prefix);
  19434. if (escapeRules) {
  19435. var addRules = Array.prototype[append ? "push" : "unshift"];
  19436. for (var i = 0; i < states.length; i++)
  19437. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  19438. }
  19439. if (!this.$embeds)
  19440. this.$embeds = [];
  19441. this.$embeds.push(prefix);
  19442. };
  19443. this.getEmbeds = function() {
  19444. return this.$embeds;
  19445. };
  19446. var pushState = function(currentState, stack) {
  19447. if (currentState != "start" || stack.length)
  19448. stack.unshift(this.nextState, currentState);
  19449. return this.nextState;
  19450. };
  19451. var popState = function(currentState, stack) {
  19452. stack.shift();
  19453. return stack.shift() || "start";
  19454. };
  19455. this.normalizeRules = function() {
  19456. var id = 0;
  19457. var rules = this.$rules;
  19458. function processState(key) {
  19459. var state = rules[key];
  19460. state.processed = true;
  19461. for (var i = 0; i < state.length; i++) {
  19462. var rule = state[i];
  19463. if (!rule.regex && rule.start) {
  19464. rule.regex = rule.start;
  19465. if (!rule.next)
  19466. rule.next = [];
  19467. rule.next.push({
  19468. defaultToken: rule.token
  19469. }, {
  19470. token: rule.token + ".end",
  19471. regex: rule.end || rule.start,
  19472. next: "pop"
  19473. });
  19474. rule.token = rule.token + ".start";
  19475. rule.push = true;
  19476. }
  19477. var next = rule.next || rule.push;
  19478. if (next && Array.isArray(next)) {
  19479. var stateName = rule.stateName;
  19480. if (!stateName) {
  19481. stateName = rule.token;
  19482. if (typeof stateName != "string")
  19483. stateName = stateName[0] || "";
  19484. if (rules[stateName])
  19485. stateName += id++;
  19486. }
  19487. rules[stateName] = next;
  19488. rule.next = stateName;
  19489. processState(stateName);
  19490. } else if (next == "pop") {
  19491. rule.next = popState;
  19492. }
  19493. if (rule.push) {
  19494. rule.nextState = rule.next || rule.push;
  19495. rule.next = pushState;
  19496. delete rule.push;
  19497. }
  19498. if (rule.rules) {
  19499. for (var r in rule.rules) {
  19500. if (rules[r]) {
  19501. if (rules[r].push)
  19502. rules[r].push.apply(rules[r], rule.rules[r]);
  19503. } else {
  19504. rules[r] = rule.rules[r];
  19505. }
  19506. }
  19507. }
  19508. if (rule.include || typeof rule == "string") {
  19509. var includeName = rule.include || rule;
  19510. var toInsert = rules[includeName];
  19511. } else if (Array.isArray(rule))
  19512. toInsert = rule;
  19513. if (toInsert) {
  19514. var args = [i, 1].concat(toInsert);
  19515. if (rule.noEscape)
  19516. args = args.filter(function(x) {return !x.next;});
  19517. state.splice.apply(state, args);
  19518. i--;
  19519. toInsert = null;
  19520. }
  19521. if (rule.keywordMap) {
  19522. rule.token = this.createKeywordMapper(
  19523. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  19524. );
  19525. delete rule.defaultToken;
  19526. }
  19527. }
  19528. }
  19529. Object.keys(rules).forEach(processState, this);
  19530. };
  19531. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  19532. var keywords = Object.create(null);
  19533. Object.keys(map).forEach(function(className) {
  19534. var a = map[className];
  19535. if (ignoreCase)
  19536. a = a.toLowerCase();
  19537. var list = a.split(splitChar || "|");
  19538. for (var i = list.length; i--; )
  19539. keywords[list[i]] = className;
  19540. });
  19541. if (Object.getPrototypeOf(keywords)) {
  19542. keywords.__proto__ = null;
  19543. }
  19544. this.$keywordList = Object.keys(keywords);
  19545. map = null;
  19546. return ignoreCase
  19547. ? function(value) {return keywords[value.toLowerCase()] || defaultToken }
  19548. : function(value) {return keywords[value] || defaultToken };
  19549. };
  19550. this.getKeywords = function() {
  19551. return this.$keywords;
  19552. };
  19553. }).call(TextHighlightRules.prototype);
  19554. exports.TextHighlightRules = TextHighlightRules;
  19555. });
  19556. ace.define("ace/mode/behaviour",["require","exports","module"], function(acequire, exports, module) {
  19557. "use strict";
  19558. var Behaviour = function() {
  19559. this.$behaviours = {};
  19560. };
  19561. (function () {
  19562. this.add = function (name, action, callback) {
  19563. switch (undefined) {
  19564. case this.$behaviours:
  19565. this.$behaviours = {};
  19566. case this.$behaviours[name]:
  19567. this.$behaviours[name] = {};
  19568. }
  19569. this.$behaviours[name][action] = callback;
  19570. }
  19571. this.addBehaviours = function (behaviours) {
  19572. for (var key in behaviours) {
  19573. for (var action in behaviours[key]) {
  19574. this.add(key, action, behaviours[key][action]);
  19575. }
  19576. }
  19577. }
  19578. this.remove = function (name) {
  19579. if (this.$behaviours && this.$behaviours[name]) {
  19580. delete this.$behaviours[name];
  19581. }
  19582. }
  19583. this.inherit = function (mode, filter) {
  19584. if (typeof mode === "function") {
  19585. var behaviours = new mode().getBehaviours(filter);
  19586. } else {
  19587. var behaviours = mode.getBehaviours(filter);
  19588. }
  19589. this.addBehaviours(behaviours);
  19590. }
  19591. this.getBehaviours = function (filter) {
  19592. if (!filter) {
  19593. return this.$behaviours;
  19594. } else {
  19595. var ret = {}
  19596. for (var i = 0; i < filter.length; i++) {
  19597. if (this.$behaviours[filter[i]]) {
  19598. ret[filter[i]] = this.$behaviours[filter[i]];
  19599. }
  19600. }
  19601. return ret;
  19602. }
  19603. }
  19604. }).call(Behaviour.prototype);
  19605. exports.Behaviour = Behaviour;
  19606. });
  19607. ace.define("ace/unicode",["require","exports","module"], function(acequire, exports, module) {
  19608. "use strict";
  19609. exports.packages = {};
  19610. addUnicodePackage({
  19611. L: "0041-005A0061-007A00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D03860388-038A038C038E-03A103A3-03F503F7-0481048A-05250531-055605590561-058705D0-05EA05F0-05F20621-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280904-0939093D09500958-0961097109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510D0-10FA10FC1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209421022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2D00-2D252D30-2D652D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A65FA662-A66EA67F-A697A6A0-A6E5A717-A71FA722-A788A78BA78CA7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  19612. Ll: "0061-007A00AA00B500BA00DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F0521052305250561-05871D00-1D2B1D62-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7C2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2D00-2D25A641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CFB00-FB06FB13-FB17FF41-FF5A",
  19613. Lu: "0041-005A00C0-00D600D8-00DE01000102010401060108010A010C010E01100112011401160118011A011C011E01200122012401260128012A012C012E01300132013401360139013B013D013F0141014301450147014A014C014E01500152015401560158015A015C015E01600162016401660168016A016C016E017001720174017601780179017B017D018101820184018601870189-018B018E-0191019301940196-0198019C019D019F01A001A201A401A601A701A901AC01AE01AF01B1-01B301B501B701B801BC01C401C701CA01CD01CF01D101D301D501D701D901DB01DE01E001E201E401E601E801EA01EC01EE01F101F401F6-01F801FA01FC01FE02000202020402060208020A020C020E02100212021402160218021A021C021E02200222022402260228022A022C022E02300232023A023B023D023E02410243-02460248024A024C024E03700372037603860388-038A038C038E038F0391-03A103A3-03AB03CF03D2-03D403D803DA03DC03DE03E003E203E403E603E803EA03EC03EE03F403F703F903FA03FD-042F04600462046404660468046A046C046E04700472047404760478047A047C047E0480048A048C048E04900492049404960498049A049C049E04A004A204A404A604A804AA04AC04AE04B004B204B404B604B804BA04BC04BE04C004C104C304C504C704C904CB04CD04D004D204D404D604D804DA04DC04DE04E004E204E404E604E804EA04EC04EE04F004F204F404F604F804FA04FC04FE05000502050405060508050A050C050E05100512051405160518051A051C051E0520052205240531-055610A0-10C51E001E021E041E061E081E0A1E0C1E0E1E101E121E141E161E181E1A1E1C1E1E1E201E221E241E261E281E2A1E2C1E2E1E301E321E341E361E381E3A1E3C1E3E1E401E421E441E461E481E4A1E4C1E4E1E501E521E541E561E581E5A1E5C1E5E1E601E621E641E661E681E6A1E6C1E6E1E701E721E741E761E781E7A1E7C1E7E1E801E821E841E861E881E8A1E8C1E8E1E901E921E941E9E1EA01EA21EA41EA61EA81EAA1EAC1EAE1EB01EB21EB41EB61EB81EBA1EBC1EBE1EC01EC21EC41EC61EC81ECA1ECC1ECE1ED01ED21ED41ED61ED81EDA1EDC1EDE1EE01EE21EE41EE61EE81EEA1EEC1EEE1EF01EF21EF41EF61EF81EFA1EFC1EFE1F08-1F0F1F18-1F1D1F28-1F2F1F38-1F3F1F48-1F4D1F591F5B1F5D1F5F1F68-1F6F1FB8-1FBB1FC8-1FCB1FD8-1FDB1FE8-1FEC1FF8-1FFB21022107210B-210D2110-211221152119-211D212421262128212A-212D2130-2133213E213F214521832C00-2C2E2C602C62-2C642C672C692C6B2C6D-2C702C722C752C7E-2C802C822C842C862C882C8A2C8C2C8E2C902C922C942C962C982C9A2C9C2C9E2CA02CA22CA42CA62CA82CAA2CAC2CAE2CB02CB22CB42CB62CB82CBA2CBC2CBE2CC02CC22CC42CC62CC82CCA2CCC2CCE2CD02CD22CD42CD62CD82CDA2CDC2CDE2CE02CE22CEB2CEDA640A642A644A646A648A64AA64CA64EA650A652A654A656A658A65AA65CA65EA662A664A666A668A66AA66CA680A682A684A686A688A68AA68CA68EA690A692A694A696A722A724A726A728A72AA72CA72EA732A734A736A738A73AA73CA73EA740A742A744A746A748A74AA74CA74EA750A752A754A756A758A75AA75CA75EA760A762A764A766A768A76AA76CA76EA779A77BA77DA77EA780A782A784A786A78BFF21-FF3A",
  19614. Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
  19615. Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
  19616. Lo: "01BB01C0-01C3029405D0-05EA05F0-05F20621-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150904-0939093D09500958-096109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF12135-21382D30-2D652D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  19617. M: "0300-036F0483-04890591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DE-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0903093C093E-094E0951-0955096209630981-098309BC09BE-09C409C709C809CB-09CD09D709E209E30A01-0A030A3C0A3E-0A420A470A480A4B-0A4D0A510A700A710A750A81-0A830ABC0ABE-0AC50AC7-0AC90ACB-0ACD0AE20AE30B01-0B030B3C0B3E-0B440B470B480B4B-0B4D0B560B570B620B630B820BBE-0BC20BC6-0BC80BCA-0BCD0BD70C01-0C030C3E-0C440C46-0C480C4A-0C4D0C550C560C620C630C820C830CBC0CBE-0CC40CC6-0CC80CCA-0CCD0CD50CD60CE20CE30D020D030D3E-0D440D46-0D480D4A-0D4D0D570D620D630D820D830DCA0DCF-0DD40DD60DD8-0DDF0DF20DF30E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F3E0F3F0F71-0F840F860F870F90-0F970F99-0FBC0FC6102B-103E1056-1059105E-10601062-10641067-106D1071-10741082-108D108F109A-109D135F1712-17141732-1734175217531772177317B6-17D317DD180B-180D18A91920-192B1930-193B19B0-19C019C819C91A17-1A1B1A55-1A5E1A60-1A7C1A7F1B00-1B041B34-1B441B6B-1B731B80-1B821BA1-1BAA1C24-1C371CD0-1CD21CD4-1CE81CED1CF21DC0-1DE61DFD-1DFF20D0-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66F-A672A67CA67DA6F0A6F1A802A806A80BA823-A827A880A881A8B4-A8C4A8E0-A8F1A926-A92DA947-A953A980-A983A9B3-A9C0AA29-AA36AA43AA4CAA4DAA7BAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE3-ABEAABECABEDFB1EFE00-FE0FFE20-FE26",
  19618. Mn: "0300-036F0483-04870591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DF-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0902093C0941-0948094D0951-095509620963098109BC09C1-09C409CD09E209E30A010A020A3C0A410A420A470A480A4B-0A4D0A510A700A710A750A810A820ABC0AC1-0AC50AC70AC80ACD0AE20AE30B010B3C0B3F0B41-0B440B4D0B560B620B630B820BC00BCD0C3E-0C400C46-0C480C4A-0C4D0C550C560C620C630CBC0CBF0CC60CCC0CCD0CE20CE30D41-0D440D4D0D620D630DCA0DD2-0DD40DD60E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F71-0F7E0F80-0F840F860F870F90-0F970F99-0FBC0FC6102D-10301032-10371039103A103D103E10581059105E-10601071-1074108210851086108D109D135F1712-17141732-1734175217531772177317B7-17BD17C617C9-17D317DD180B-180D18A91920-19221927192819321939-193B1A171A181A561A58-1A5E1A601A621A65-1A6C1A73-1A7C1A7F1B00-1B031B341B36-1B3A1B3C1B421B6B-1B731B801B811BA2-1BA51BA81BA91C2C-1C331C361C371CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF20D0-20DC20E120E5-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66FA67CA67DA6F0A6F1A802A806A80BA825A826A8C4A8E0-A8F1A926-A92DA947-A951A980-A982A9B3A9B6-A9B9A9BCAA29-AA2EAA31AA32AA35AA36AA43AA4CAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE5ABE8ABEDFB1EFE00-FE0FFE20-FE26",
  19619. Mc: "0903093E-09400949-094C094E0982098309BE-09C009C709C809CB09CC09D70A030A3E-0A400A830ABE-0AC00AC90ACB0ACC0B020B030B3E0B400B470B480B4B0B4C0B570BBE0BBF0BC10BC20BC6-0BC80BCA-0BCC0BD70C01-0C030C41-0C440C820C830CBE0CC0-0CC40CC70CC80CCA0CCB0CD50CD60D020D030D3E-0D400D46-0D480D4A-0D4C0D570D820D830DCF-0DD10DD8-0DDF0DF20DF30F3E0F3F0F7F102B102C10311038103B103C105610571062-10641067-106D108310841087-108C108F109A-109C17B617BE-17C517C717C81923-19261929-192B193019311933-193819B0-19C019C819C91A19-1A1B1A551A571A611A631A641A6D-1A721B041B351B3B1B3D-1B411B431B441B821BA11BA61BA71BAA1C24-1C2B1C341C351CE11CF2A823A824A827A880A881A8B4-A8C3A952A953A983A9B4A9B5A9BAA9BBA9BD-A9C0AA2FAA30AA33AA34AA4DAA7BABE3ABE4ABE6ABE7ABE9ABEAABEC",
  19620. Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
  19621. N: "0030-003900B200B300B900BC-00BE0660-066906F0-06F907C0-07C90966-096F09E6-09EF09F4-09F90A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BF20C66-0C6F0C78-0C7E0CE6-0CEF0D66-0D750E50-0E590ED0-0ED90F20-0F331040-10491090-10991369-137C16EE-16F017E0-17E917F0-17F91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C5920702074-20792080-20892150-21822185-21892460-249B24EA-24FF2776-27932CFD30073021-30293038-303A3192-31953220-32293251-325F3280-328932B1-32BFA620-A629A6E6-A6EFA830-A835A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  19622. Nd: "0030-00390660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  19623. Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
  19624. No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
  19625. P: "0021-00230025-002A002C-002F003A003B003F0040005B-005D005F007B007D00A100AB00B700BB00BF037E0387055A-055F0589058A05BE05C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F3A-0F3D0F850FD0-0FD4104A-104F10FB1361-13681400166D166E169B169C16EB-16ED1735173617D4-17D617D8-17DA1800-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD32010-20272030-20432045-20512053-205E207D207E208D208E2329232A2768-277527C527C627E6-27EF2983-299829D8-29DB29FC29FD2CF9-2CFC2CFE2CFF2E00-2E2E2E302E313001-30033008-30113014-301F3030303D30A030FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFD3EFD3FFE10-FE19FE30-FE52FE54-FE61FE63FE68FE6AFE6BFF01-FF03FF05-FF0AFF0C-FF0FFF1AFF1BFF1FFF20FF3B-FF3DFF3FFF5BFF5DFF5F-FF65",
  19626. Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
  19627. Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
  19628. Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
  19629. Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
  19630. Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
  19631. Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
  19632. Po: "0021-00230025-0027002A002C002E002F003A003B003F0040005C00A100B700BF037E0387055A-055F058905C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F850FD0-0FD4104A-104F10FB1361-1368166D166E16EB-16ED1735173617D4-17D617D8-17DA1800-18051807-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD3201620172020-20272030-2038203B-203E2041-20432047-205120532055-205E2CF9-2CFC2CFE2CFF2E002E012E06-2E082E0B2E0E-2E162E182E192E1B2E1E2E1F2E2A-2E2E2E302E313001-3003303D30FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFE10-FE16FE19FE30FE45FE46FE49-FE4CFE50-FE52FE54-FE57FE5F-FE61FE68FE6AFE6BFF01-FF03FF05-FF07FF0AFF0CFF0EFF0FFF1AFF1BFF1FFF20FF3CFF61FF64FF65",
  19633. S: "0024002B003C-003E005E0060007C007E00A2-00A900AC00AE-00B100B400B600B800D700F702C2-02C502D2-02DF02E5-02EB02ED02EF-02FF03750384038503F604820606-0608060B060E060F06E906FD06FE07F609F209F309FA09FB0AF10B700BF3-0BFA0C7F0CF10CF20D790E3F0F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-139917DB194019E0-19FF1B61-1B6A1B74-1B7C1FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE20442052207A-207C208A-208C20A0-20B8210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B2140-2144214A-214D214F2190-2328232B-23E82400-24262440-244A249C-24E92500-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE27C0-27C427C7-27CA27CC27D0-27E527F0-29822999-29D729DC-29FB29FE-2B4C2B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F309B309C319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A700-A716A720A721A789A78AA828-A82BA836-A839AA77-AA79FB29FDFCFDFDFE62FE64-FE66FE69FF04FF0BFF1C-FF1EFF3EFF40FF5CFF5EFFE0-FFE6FFE8-FFEEFFFCFFFD",
  19634. Sm: "002B003C-003E007C007E00AC00B100D700F703F60606-060820442052207A-207C208A-208C2140-2144214B2190-2194219A219B21A021A321A621AE21CE21CF21D221D421F4-22FF2308-230B23202321237C239B-23B323DC-23E125B725C125F8-25FF266F27C0-27C427C7-27CA27CC27D0-27E527F0-27FF2900-29822999-29D729DC-29FB29FE-2AFF2B30-2B442B47-2B4CFB29FE62FE64-FE66FF0BFF1C-FF1EFF5CFF5EFFE2FFE9-FFEC",
  19635. Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
  19636. Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
  19637. So: "00A600A700A900AE00B000B60482060E060F06E906FD06FE07F609FA0B700BF3-0BF80BFA0C7F0CF10CF20D790F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-1399194019E0-19FF1B61-1B6A1B74-1B7C210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B214A214C214D214F2195-2199219C-219F21A121A221A421A521A7-21AD21AF-21CD21D021D121D321D5-21F32300-2307230C-231F2322-2328232B-237B237D-239A23B4-23DB23E2-23E82400-24262440-244A249C-24E92500-25B625B8-25C025C2-25F72600-266E2670-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE2800-28FF2B00-2B2F2B452B462B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A828-A82BA836A837A839AA77-AA79FDFDFFE4FFE8FFEDFFEEFFFCFFFD",
  19638. Z: "002000A01680180E2000-200A20282029202F205F3000",
  19639. Zs: "002000A01680180E2000-200A202F205F3000",
  19640. Zl: "2028",
  19641. Zp: "2029",
  19642. C: "0000-001F007F-009F00AD03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-0605061C061D0620065F06DD070E070F074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17B417B517DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF200B-200F202A-202E2060-206F20722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-F8FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFD-FF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFFBFFFEFFFF",
  19643. Cc: "0000-001F007F-009F",
  19644. Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
  19645. Co: "E000-F8FF",
  19646. Cs: "D800-DFFF",
  19647. Cn: "03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-05FF06040605061C061D0620065F070E074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF2065-206920722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-D7FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFDFEFEFF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFF8FFFEFFFF"
  19648. });
  19649. function addUnicodePackage (pack) {
  19650. var codePoint = /\w{4}/g;
  19651. for (var name in pack)
  19652. exports.packages[name] = pack[name].replace(codePoint, "\\u$&");
  19653. }
  19654. });
  19655. ace.define("ace/token_iterator",["require","exports","module"], function(acequire, exports, module) {
  19656. "use strict";
  19657. var TokenIterator = function(session, initialRow, initialColumn) {
  19658. this.$session = session;
  19659. this.$row = initialRow;
  19660. this.$rowTokens = session.getTokens(initialRow);
  19661. var token = session.getTokenAt(initialRow, initialColumn);
  19662. this.$tokenIndex = token ? token.index : -1;
  19663. };
  19664. (function() {
  19665. this.stepBackward = function() {
  19666. this.$tokenIndex -= 1;
  19667. while (this.$tokenIndex < 0) {
  19668. this.$row -= 1;
  19669. if (this.$row < 0) {
  19670. this.$row = 0;
  19671. return null;
  19672. }
  19673. this.$rowTokens = this.$session.getTokens(this.$row);
  19674. this.$tokenIndex = this.$rowTokens.length - 1;
  19675. }
  19676. return this.$rowTokens[this.$tokenIndex];
  19677. };
  19678. this.stepForward = function() {
  19679. this.$tokenIndex += 1;
  19680. var rowCount;
  19681. while (this.$tokenIndex >= this.$rowTokens.length) {
  19682. this.$row += 1;
  19683. if (!rowCount)
  19684. rowCount = this.$session.getLength();
  19685. if (this.$row >= rowCount) {
  19686. this.$row = rowCount - 1;
  19687. return null;
  19688. }
  19689. this.$rowTokens = this.$session.getTokens(this.$row);
  19690. this.$tokenIndex = 0;
  19691. }
  19692. return this.$rowTokens[this.$tokenIndex];
  19693. };
  19694. this.getCurrentToken = function () {
  19695. return this.$rowTokens[this.$tokenIndex];
  19696. };
  19697. this.getCurrentTokenRow = function () {
  19698. return this.$row;
  19699. };
  19700. this.getCurrentTokenColumn = function() {
  19701. var rowTokens = this.$rowTokens;
  19702. var tokenIndex = this.$tokenIndex;
  19703. var column = rowTokens[tokenIndex].start;
  19704. if (column !== undefined)
  19705. return column;
  19706. column = 0;
  19707. while (tokenIndex > 0) {
  19708. tokenIndex -= 1;
  19709. column += rowTokens[tokenIndex].value.length;
  19710. }
  19711. return column;
  19712. };
  19713. this.getCurrentTokenPosition = function() {
  19714. return {row: this.$row, column: this.getCurrentTokenColumn()};
  19715. };
  19716. }).call(TokenIterator.prototype);
  19717. exports.TokenIterator = TokenIterator;
  19718. });
  19719. ace.define("ace/mode/text",["require","exports","module","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(acequire, exports, module) {
  19720. "use strict";
  19721. var Tokenizer = acequire("../tokenizer").Tokenizer;
  19722. var TextHighlightRules = acequire("./text_highlight_rules").TextHighlightRules;
  19723. var Behaviour = acequire("./behaviour").Behaviour;
  19724. var unicode = acequire("../unicode");
  19725. var lang = acequire("../lib/lang");
  19726. var TokenIterator = acequire("../token_iterator").TokenIterator;
  19727. var Range = acequire("../range").Range;
  19728. var Mode = function() {
  19729. this.HighlightRules = TextHighlightRules;
  19730. this.$behaviour = new Behaviour();
  19731. };
  19732. (function() {
  19733. this.tokenRe = new RegExp("^["
  19734. + unicode.packages.L
  19735. + unicode.packages.Mn + unicode.packages.Mc
  19736. + unicode.packages.Nd
  19737. + unicode.packages.Pc + "\\$_]+", "g"
  19738. );
  19739. this.nonTokenRe = new RegExp("^(?:[^"
  19740. + unicode.packages.L
  19741. + unicode.packages.Mn + unicode.packages.Mc
  19742. + unicode.packages.Nd
  19743. + unicode.packages.Pc + "\\$_]|\\s])+", "g"
  19744. );
  19745. this.getTokenizer = function() {
  19746. if (!this.$tokenizer) {
  19747. this.$highlightRules = this.$highlightRules || new this.HighlightRules();
  19748. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  19749. }
  19750. return this.$tokenizer;
  19751. };
  19752. this.lineCommentStart = "";
  19753. this.blockComment = "";
  19754. this.toggleCommentLines = function(state, session, startRow, endRow) {
  19755. var doc = session.doc;
  19756. var ignoreBlankLines = true;
  19757. var shouldRemove = true;
  19758. var minIndent = Infinity;
  19759. var tabSize = session.getTabSize();
  19760. var insertAtTabStop = false;
  19761. if (!this.lineCommentStart) {
  19762. if (!this.blockComment)
  19763. return false;
  19764. var lineCommentStart = this.blockComment.start;
  19765. var lineCommentEnd = this.blockComment.end;
  19766. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  19767. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  19768. var comment = function(line, i) {
  19769. if (testRemove(line, i))
  19770. return;
  19771. if (!ignoreBlankLines || /\S/.test(line)) {
  19772. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  19773. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  19774. }
  19775. };
  19776. var uncomment = function(line, i) {
  19777. var m;
  19778. if (m = line.match(regexpEnd))
  19779. doc.removeInLine(i, line.length - m[0].length, line.length);
  19780. if (m = line.match(regexpStart))
  19781. doc.removeInLine(i, m[1].length, m[0].length);
  19782. };
  19783. var testRemove = function(line, row) {
  19784. if (regexpStart.test(line))
  19785. return true;
  19786. var tokens = session.getTokens(row);
  19787. for (var i = 0; i < tokens.length; i++) {
  19788. if (tokens[i].type === "comment")
  19789. return true;
  19790. }
  19791. };
  19792. } else {
  19793. if (Array.isArray(this.lineCommentStart)) {
  19794. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  19795. var lineCommentStart = this.lineCommentStart[0];
  19796. } else {
  19797. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  19798. var lineCommentStart = this.lineCommentStart;
  19799. }
  19800. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  19801. insertAtTabStop = session.getUseSoftTabs();
  19802. var uncomment = function(line, i) {
  19803. var m = line.match(regexpStart);
  19804. if (!m) return;
  19805. var start = m[1].length, end = m[0].length;
  19806. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  19807. end--;
  19808. doc.removeInLine(i, start, end);
  19809. };
  19810. var commentWithSpace = lineCommentStart + " ";
  19811. var comment = function(line, i) {
  19812. if (!ignoreBlankLines || /\S/.test(line)) {
  19813. if (shouldInsertSpace(line, minIndent, minIndent))
  19814. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  19815. else
  19816. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  19817. }
  19818. };
  19819. var testRemove = function(line, i) {
  19820. return regexpStart.test(line);
  19821. };
  19822. var shouldInsertSpace = function(line, before, after) {
  19823. var spaces = 0;
  19824. while (before-- && line.charAt(before) == " ")
  19825. spaces++;
  19826. if (spaces % tabSize != 0)
  19827. return false;
  19828. var spaces = 0;
  19829. while (line.charAt(after++) == " ")
  19830. spaces++;
  19831. if (tabSize > 2)
  19832. return spaces % tabSize != tabSize - 1;
  19833. else
  19834. return spaces % tabSize == 0;
  19835. return true;
  19836. };
  19837. }
  19838. function iter(fun) {
  19839. for (var i = startRow; i <= endRow; i++)
  19840. fun(doc.getLine(i), i);
  19841. }
  19842. var minEmptyLength = Infinity;
  19843. iter(function(line, i) {
  19844. var indent = line.search(/\S/);
  19845. if (indent !== -1) {
  19846. if (indent < minIndent)
  19847. minIndent = indent;
  19848. if (shouldRemove && !testRemove(line, i))
  19849. shouldRemove = false;
  19850. } else if (minEmptyLength > line.length) {
  19851. minEmptyLength = line.length;
  19852. }
  19853. });
  19854. if (minIndent == Infinity) {
  19855. minIndent = minEmptyLength;
  19856. ignoreBlankLines = false;
  19857. shouldRemove = false;
  19858. }
  19859. if (insertAtTabStop && minIndent % tabSize != 0)
  19860. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  19861. iter(shouldRemove ? uncomment : comment);
  19862. };
  19863. this.toggleBlockComment = function(state, session, range, cursor) {
  19864. var comment = this.blockComment;
  19865. if (!comment)
  19866. return;
  19867. if (!comment.start && comment[0])
  19868. comment = comment[0];
  19869. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  19870. var token = iterator.getCurrentToken();
  19871. var sel = session.selection;
  19872. var initialRange = session.selection.toOrientedRange();
  19873. var startRow, colDiff;
  19874. if (token && /comment/.test(token.type)) {
  19875. var startRange, endRange;
  19876. while (token && /comment/.test(token.type)) {
  19877. var i = token.value.indexOf(comment.start);
  19878. if (i != -1) {
  19879. var row = iterator.getCurrentTokenRow();
  19880. var column = iterator.getCurrentTokenColumn() + i;
  19881. startRange = new Range(row, column, row, column + comment.start.length);
  19882. break;
  19883. }
  19884. token = iterator.stepBackward();
  19885. }
  19886. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  19887. var token = iterator.getCurrentToken();
  19888. while (token && /comment/.test(token.type)) {
  19889. var i = token.value.indexOf(comment.end);
  19890. if (i != -1) {
  19891. var row = iterator.getCurrentTokenRow();
  19892. var column = iterator.getCurrentTokenColumn() + i;
  19893. endRange = new Range(row, column, row, column + comment.end.length);
  19894. break;
  19895. }
  19896. token = iterator.stepForward();
  19897. }
  19898. if (endRange)
  19899. session.remove(endRange);
  19900. if (startRange) {
  19901. session.remove(startRange);
  19902. startRow = startRange.start.row;
  19903. colDiff = -comment.start.length;
  19904. }
  19905. } else {
  19906. colDiff = comment.start.length;
  19907. startRow = range.start.row;
  19908. session.insert(range.end, comment.end);
  19909. session.insert(range.start, comment.start);
  19910. }
  19911. if (initialRange.start.row == startRow)
  19912. initialRange.start.column += colDiff;
  19913. if (initialRange.end.row == startRow)
  19914. initialRange.end.column += colDiff;
  19915. session.selection.fromOrientedRange(initialRange);
  19916. };
  19917. this.getNextLineIndent = function(state, line, tab) {
  19918. return this.$getIndent(line);
  19919. };
  19920. this.checkOutdent = function(state, line, input) {
  19921. return false;
  19922. };
  19923. this.autoOutdent = function(state, doc, row) {
  19924. };
  19925. this.$getIndent = function(line) {
  19926. return line.match(/^\s*/)[0];
  19927. };
  19928. this.createWorker = function(session) {
  19929. return null;
  19930. };
  19931. this.createModeDelegates = function (mapping) {
  19932. this.$embeds = [];
  19933. this.$modes = {};
  19934. for (var i in mapping) {
  19935. if (mapping[i]) {
  19936. this.$embeds.push(i);
  19937. this.$modes[i] = new mapping[i]();
  19938. }
  19939. }
  19940. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  19941. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  19942. for (var i = 0; i < delegations.length; i++) {
  19943. (function(scope) {
  19944. var functionName = delegations[i];
  19945. var defaultHandler = scope[functionName];
  19946. scope[delegations[i]] = function() {
  19947. return this.$delegator(functionName, arguments, defaultHandler);
  19948. };
  19949. }(this));
  19950. }
  19951. };
  19952. this.$delegator = function(method, args, defaultHandler) {
  19953. var state = args[0];
  19954. if (typeof state != "string")
  19955. state = state[0];
  19956. for (var i = 0; i < this.$embeds.length; i++) {
  19957. if (!this.$modes[this.$embeds[i]]) continue;
  19958. var split = state.split(this.$embeds[i]);
  19959. if (!split[0] && split[1]) {
  19960. args[0] = split[1];
  19961. var mode = this.$modes[this.$embeds[i]];
  19962. return mode[method].apply(mode, args);
  19963. }
  19964. }
  19965. var ret = defaultHandler.apply(this, args);
  19966. return defaultHandler ? ret : undefined;
  19967. };
  19968. this.transformAction = function(state, action, editor, session, param) {
  19969. if (this.$behaviour) {
  19970. var behaviours = this.$behaviour.getBehaviours();
  19971. for (var key in behaviours) {
  19972. if (behaviours[key][action]) {
  19973. var ret = behaviours[key][action].apply(this, arguments);
  19974. if (ret) {
  19975. return ret;
  19976. }
  19977. }
  19978. }
  19979. }
  19980. };
  19981. this.getKeywords = function(append) {
  19982. if (!this.completionKeywords) {
  19983. var rules = this.$tokenizer.rules;
  19984. var completionKeywords = [];
  19985. for (var rule in rules) {
  19986. var ruleItr = rules[rule];
  19987. for (var r = 0, l = ruleItr.length; r < l; r++) {
  19988. if (typeof ruleItr[r].token === "string") {
  19989. if (/keyword|support|storage/.test(ruleItr[r].token))
  19990. completionKeywords.push(ruleItr[r].regex);
  19991. }
  19992. else if (typeof ruleItr[r].token === "object") {
  19993. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  19994. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  19995. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  19996. completionKeywords.push(rule.substr(1, rule.length - 2));
  19997. }
  19998. }
  19999. }
  20000. }
  20001. }
  20002. this.completionKeywords = completionKeywords;
  20003. }
  20004. if (!append)
  20005. return this.$keywordList;
  20006. return completionKeywords.concat(this.$keywordList || []);
  20007. };
  20008. this.$createKeywordList = function() {
  20009. if (!this.$highlightRules)
  20010. this.getTokenizer();
  20011. return this.$keywordList = this.$highlightRules.$keywordList || [];
  20012. };
  20013. this.getCompletions = function(state, session, pos, prefix) {
  20014. var keywords = this.$keywordList || this.$createKeywordList();
  20015. return keywords.map(function(word) {
  20016. return {
  20017. name: word,
  20018. value: word,
  20019. score: 0,
  20020. meta: "keyword"
  20021. };
  20022. });
  20023. };
  20024. this.$id = "ace/mode/text";
  20025. }).call(Mode.prototype);
  20026. exports.Mode = Mode;
  20027. });
  20028. ace.define("ace/apply_delta",["require","exports","module"], function(acequire, exports, module) {
  20029. "use strict";
  20030. function throwDeltaError(delta, errorText){
  20031. console.log("Invalid Delta:", delta);
  20032. throw "Invalid Delta: " + errorText;
  20033. }
  20034. function positionInDocument(docLines, position) {
  20035. return position.row >= 0 && position.row < docLines.length &&
  20036. position.column >= 0 && position.column <= docLines[position.row].length;
  20037. }
  20038. function validateDelta(docLines, delta) {
  20039. if (delta.action != "insert" && delta.action != "remove")
  20040. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  20041. if (!(delta.lines instanceof Array))
  20042. throwDeltaError(delta, "delta.lines must be an Array");
  20043. if (!delta.start || !delta.end)
  20044. throwDeltaError(delta, "delta.start/end must be an present");
  20045. var start = delta.start;
  20046. if (!positionInDocument(docLines, delta.start))
  20047. throwDeltaError(delta, "delta.start must be contained in document");
  20048. var end = delta.end;
  20049. if (delta.action == "remove" && !positionInDocument(docLines, end))
  20050. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  20051. var numRangeRows = end.row - start.row;
  20052. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  20053. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  20054. throwDeltaError(delta, "delta.range must match delta lines");
  20055. }
  20056. exports.applyDelta = function(docLines, delta, doNotValidate) {
  20057. var row = delta.start.row;
  20058. var startColumn = delta.start.column;
  20059. var line = docLines[row] || "";
  20060. switch (delta.action) {
  20061. case "insert":
  20062. var lines = delta.lines;
  20063. if (lines.length === 1) {
  20064. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  20065. } else {
  20066. var args = [row, 1].concat(delta.lines);
  20067. docLines.splice.apply(docLines, args);
  20068. docLines[row] = line.substring(0, startColumn) + docLines[row];
  20069. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  20070. }
  20071. break;
  20072. case "remove":
  20073. var endColumn = delta.end.column;
  20074. var endRow = delta.end.row;
  20075. if (row === endRow) {
  20076. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  20077. } else {
  20078. docLines.splice(
  20079. row, endRow - row + 1,
  20080. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  20081. );
  20082. }
  20083. break;
  20084. }
  20085. }
  20086. });
  20087. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(acequire, exports, module) {
  20088. "use strict";
  20089. var oop = acequire("./lib/oop");
  20090. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  20091. var Anchor = exports.Anchor = function(doc, row, column) {
  20092. this.$onChange = this.onChange.bind(this);
  20093. this.attach(doc);
  20094. if (typeof column == "undefined")
  20095. this.setPosition(row.row, row.column);
  20096. else
  20097. this.setPosition(row, column);
  20098. };
  20099. (function() {
  20100. oop.implement(this, EventEmitter);
  20101. this.getPosition = function() {
  20102. return this.$clipPositionToDocument(this.row, this.column);
  20103. };
  20104. this.getDocument = function() {
  20105. return this.document;
  20106. };
  20107. this.$insertRight = false;
  20108. this.onChange = function(delta) {
  20109. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  20110. return;
  20111. if (delta.start.row > this.row)
  20112. return;
  20113. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  20114. this.setPosition(point.row, point.column, true);
  20115. };
  20116. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  20117. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  20118. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  20119. }
  20120. function $getTransformedPoint(delta, point, moveIfEqual) {
  20121. var deltaIsInsert = delta.action == "insert";
  20122. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  20123. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  20124. var deltaStart = delta.start;
  20125. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  20126. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  20127. return {
  20128. row: point.row,
  20129. column: point.column
  20130. };
  20131. }
  20132. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  20133. return {
  20134. row: point.row + deltaRowShift,
  20135. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  20136. };
  20137. }
  20138. return {
  20139. row: deltaStart.row,
  20140. column: deltaStart.column
  20141. };
  20142. }
  20143. this.setPosition = function(row, column, noClip) {
  20144. var pos;
  20145. if (noClip) {
  20146. pos = {
  20147. row: row,
  20148. column: column
  20149. };
  20150. } else {
  20151. pos = this.$clipPositionToDocument(row, column);
  20152. }
  20153. if (this.row == pos.row && this.column == pos.column)
  20154. return;
  20155. var old = {
  20156. row: this.row,
  20157. column: this.column
  20158. };
  20159. this.row = pos.row;
  20160. this.column = pos.column;
  20161. this._signal("change", {
  20162. old: old,
  20163. value: pos
  20164. });
  20165. };
  20166. this.detach = function() {
  20167. this.document.removeEventListener("change", this.$onChange);
  20168. };
  20169. this.attach = function(doc) {
  20170. this.document = doc || this.document;
  20171. this.document.on("change", this.$onChange);
  20172. };
  20173. this.$clipPositionToDocument = function(row, column) {
  20174. var pos = {};
  20175. if (row >= this.document.getLength()) {
  20176. pos.row = Math.max(0, this.document.getLength() - 1);
  20177. pos.column = this.document.getLine(pos.row).length;
  20178. }
  20179. else if (row < 0) {
  20180. pos.row = 0;
  20181. pos.column = 0;
  20182. }
  20183. else {
  20184. pos.row = row;
  20185. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  20186. }
  20187. if (column < 0)
  20188. pos.column = 0;
  20189. return pos;
  20190. };
  20191. }).call(Anchor.prototype);
  20192. });
  20193. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(acequire, exports, module) {
  20194. "use strict";
  20195. var oop = acequire("./lib/oop");
  20196. var applyDelta = acequire("./apply_delta").applyDelta;
  20197. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  20198. var Range = acequire("./range").Range;
  20199. var Anchor = acequire("./anchor").Anchor;
  20200. var Document = function(textOrLines) {
  20201. this.$lines = [""];
  20202. if (textOrLines.length === 0) {
  20203. this.$lines = [""];
  20204. } else if (Array.isArray(textOrLines)) {
  20205. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  20206. } else {
  20207. this.insert({row: 0, column:0}, textOrLines);
  20208. }
  20209. };
  20210. (function() {
  20211. oop.implement(this, EventEmitter);
  20212. this.setValue = function(text) {
  20213. var len = this.getLength() - 1;
  20214. this.remove(new Range(0, 0, len, this.getLine(len).length));
  20215. this.insert({row: 0, column: 0}, text);
  20216. };
  20217. this.getValue = function() {
  20218. return this.getAllLines().join(this.getNewLineCharacter());
  20219. };
  20220. this.createAnchor = function(row, column) {
  20221. return new Anchor(this, row, column);
  20222. };
  20223. if ("aaa".split(/a/).length === 0) {
  20224. this.$split = function(text) {
  20225. return text.replace(/\r\n|\r/g, "\n").split("\n");
  20226. };
  20227. } else {
  20228. this.$split = function(text) {
  20229. return text.split(/\r\n|\r|\n/);
  20230. };
  20231. }
  20232. this.$detectNewLine = function(text) {
  20233. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  20234. this.$autoNewLine = match ? match[1] : "\n";
  20235. this._signal("changeNewLineMode");
  20236. };
  20237. this.getNewLineCharacter = function() {
  20238. switch (this.$newLineMode) {
  20239. case "windows":
  20240. return "\r\n";
  20241. case "unix":
  20242. return "\n";
  20243. default:
  20244. return this.$autoNewLine || "\n";
  20245. }
  20246. };
  20247. this.$autoNewLine = "";
  20248. this.$newLineMode = "auto";
  20249. this.setNewLineMode = function(newLineMode) {
  20250. if (this.$newLineMode === newLineMode)
  20251. return;
  20252. this.$newLineMode = newLineMode;
  20253. this._signal("changeNewLineMode");
  20254. };
  20255. this.getNewLineMode = function() {
  20256. return this.$newLineMode;
  20257. };
  20258. this.isNewLine = function(text) {
  20259. return (text == "\r\n" || text == "\r" || text == "\n");
  20260. };
  20261. this.getLine = function(row) {
  20262. return this.$lines[row] || "";
  20263. };
  20264. this.getLines = function(firstRow, lastRow) {
  20265. return this.$lines.slice(firstRow, lastRow + 1);
  20266. };
  20267. this.getAllLines = function() {
  20268. return this.getLines(0, this.getLength());
  20269. };
  20270. this.getLength = function() {
  20271. return this.$lines.length;
  20272. };
  20273. this.getTextRange = function(range) {
  20274. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  20275. };
  20276. this.getLinesForRange = function(range) {
  20277. var lines;
  20278. if (range.start.row === range.end.row) {
  20279. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  20280. } else {
  20281. lines = this.getLines(range.start.row, range.end.row);
  20282. lines[0] = (lines[0] || "").substring(range.start.column);
  20283. var l = lines.length - 1;
  20284. if (range.end.row - range.start.row == l)
  20285. lines[l] = lines[l].substring(0, range.end.column);
  20286. }
  20287. return lines;
  20288. };
  20289. this.insertLines = function(row, lines) {
  20290. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  20291. return this.insertFullLines(row, lines);
  20292. };
  20293. this.removeLines = function(firstRow, lastRow) {
  20294. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  20295. return this.removeFullLines(firstRow, lastRow);
  20296. };
  20297. this.insertNewLine = function(position) {
  20298. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, [\'\', \'\']) instead.");
  20299. return this.insertMergedLines(position, ["", ""]);
  20300. };
  20301. this.insert = function(position, text) {
  20302. if (this.getLength() <= 1)
  20303. this.$detectNewLine(text);
  20304. return this.insertMergedLines(position, this.$split(text));
  20305. };
  20306. this.insertInLine = function(position, text) {
  20307. var start = this.clippedPos(position.row, position.column);
  20308. var end = this.pos(position.row, position.column + text.length);
  20309. this.applyDelta({
  20310. start: start,
  20311. end: end,
  20312. action: "insert",
  20313. lines: [text]
  20314. }, true);
  20315. return this.clonePos(end);
  20316. };
  20317. this.clippedPos = function(row, column) {
  20318. var length = this.getLength();
  20319. if (row === undefined) {
  20320. row = length;
  20321. } else if (row < 0) {
  20322. row = 0;
  20323. } else if (row >= length) {
  20324. row = length - 1;
  20325. column = undefined;
  20326. }
  20327. var line = this.getLine(row);
  20328. if (column == undefined)
  20329. column = line.length;
  20330. column = Math.min(Math.max(column, 0), line.length);
  20331. return {row: row, column: column};
  20332. };
  20333. this.clonePos = function(pos) {
  20334. return {row: pos.row, column: pos.column};
  20335. };
  20336. this.pos = function(row, column) {
  20337. return {row: row, column: column};
  20338. };
  20339. this.$clipPosition = function(position) {
  20340. var length = this.getLength();
  20341. if (position.row >= length) {
  20342. position.row = Math.max(0, length - 1);
  20343. position.column = this.getLine(length - 1).length;
  20344. } else {
  20345. position.row = Math.max(0, position.row);
  20346. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  20347. }
  20348. return position;
  20349. };
  20350. this.insertFullLines = function(row, lines) {
  20351. row = Math.min(Math.max(row, 0), this.getLength());
  20352. var column = 0;
  20353. if (row < this.getLength()) {
  20354. lines = lines.concat([""]);
  20355. column = 0;
  20356. } else {
  20357. lines = [""].concat(lines);
  20358. row--;
  20359. column = this.$lines[row].length;
  20360. }
  20361. this.insertMergedLines({row: row, column: column}, lines);
  20362. };
  20363. this.insertMergedLines = function(position, lines) {
  20364. var start = this.clippedPos(position.row, position.column);
  20365. var end = {
  20366. row: start.row + lines.length - 1,
  20367. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  20368. };
  20369. this.applyDelta({
  20370. start: start,
  20371. end: end,
  20372. action: "insert",
  20373. lines: lines
  20374. });
  20375. return this.clonePos(end);
  20376. };
  20377. this.remove = function(range) {
  20378. var start = this.clippedPos(range.start.row, range.start.column);
  20379. var end = this.clippedPos(range.end.row, range.end.column);
  20380. this.applyDelta({
  20381. start: start,
  20382. end: end,
  20383. action: "remove",
  20384. lines: this.getLinesForRange({start: start, end: end})
  20385. });
  20386. return this.clonePos(start);
  20387. };
  20388. this.removeInLine = function(row, startColumn, endColumn) {
  20389. var start = this.clippedPos(row, startColumn);
  20390. var end = this.clippedPos(row, endColumn);
  20391. this.applyDelta({
  20392. start: start,
  20393. end: end,
  20394. action: "remove",
  20395. lines: this.getLinesForRange({start: start, end: end})
  20396. }, true);
  20397. return this.clonePos(start);
  20398. };
  20399. this.removeFullLines = function(firstRow, lastRow) {
  20400. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  20401. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  20402. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  20403. var deleteLastNewLine = lastRow < this.getLength() - 1;
  20404. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  20405. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  20406. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  20407. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  20408. var range = new Range(startRow, startCol, endRow, endCol);
  20409. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  20410. this.applyDelta({
  20411. start: range.start,
  20412. end: range.end,
  20413. action: "remove",
  20414. lines: this.getLinesForRange(range)
  20415. });
  20416. return deletedLines;
  20417. };
  20418. this.removeNewLine = function(row) {
  20419. if (row < this.getLength() - 1 && row >= 0) {
  20420. this.applyDelta({
  20421. start: this.pos(row, this.getLine(row).length),
  20422. end: this.pos(row + 1, 0),
  20423. action: "remove",
  20424. lines: ["", ""]
  20425. });
  20426. }
  20427. };
  20428. this.replace = function(range, text) {
  20429. if (!(range instanceof Range))
  20430. range = Range.fromPoints(range.start, range.end);
  20431. if (text.length === 0 && range.isEmpty())
  20432. return range.start;
  20433. if (text == this.getTextRange(range))
  20434. return range.end;
  20435. this.remove(range);
  20436. var end;
  20437. if (text) {
  20438. end = this.insert(range.start, text);
  20439. }
  20440. else {
  20441. end = range.start;
  20442. }
  20443. return end;
  20444. };
  20445. this.applyDeltas = function(deltas) {
  20446. for (var i=0; i<deltas.length; i++) {
  20447. this.applyDelta(deltas[i]);
  20448. }
  20449. };
  20450. this.revertDeltas = function(deltas) {
  20451. for (var i=deltas.length-1; i>=0; i--) {
  20452. this.revertDelta(deltas[i]);
  20453. }
  20454. };
  20455. this.applyDelta = function(delta, doNotValidate) {
  20456. var isInsert = delta.action == "insert";
  20457. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  20458. : !Range.comparePoints(delta.start, delta.end)) {
  20459. return;
  20460. }
  20461. if (isInsert && delta.lines.length > 20000)
  20462. this.$splitAndapplyLargeDelta(delta, 20000);
  20463. applyDelta(this.$lines, delta, doNotValidate);
  20464. this._signal("change", delta);
  20465. };
  20466. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  20467. var lines = delta.lines;
  20468. var l = lines.length;
  20469. var row = delta.start.row;
  20470. var column = delta.start.column;
  20471. var from = 0, to = 0;
  20472. do {
  20473. from = to;
  20474. to += MAX - 1;
  20475. var chunk = lines.slice(from, to);
  20476. if (to > l) {
  20477. delta.lines = chunk;
  20478. delta.start.row = row + from;
  20479. delta.start.column = column;
  20480. break;
  20481. }
  20482. chunk.push("");
  20483. this.applyDelta({
  20484. start: this.pos(row + from, column),
  20485. end: this.pos(row + to, column = 0),
  20486. action: delta.action,
  20487. lines: chunk
  20488. }, true);
  20489. } while(true);
  20490. };
  20491. this.revertDelta = function(delta) {
  20492. this.applyDelta({
  20493. start: this.clonePos(delta.start),
  20494. end: this.clonePos(delta.end),
  20495. action: (delta.action == "insert" ? "remove" : "insert"),
  20496. lines: delta.lines.slice()
  20497. });
  20498. };
  20499. this.indexToPosition = function(index, startRow) {
  20500. var lines = this.$lines || this.getAllLines();
  20501. var newlineLength = this.getNewLineCharacter().length;
  20502. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  20503. index -= lines[i].length + newlineLength;
  20504. if (index < 0)
  20505. return {row: i, column: index + lines[i].length + newlineLength};
  20506. }
  20507. return {row: l-1, column: lines[l-1].length};
  20508. };
  20509. this.positionToIndex = function(pos, startRow) {
  20510. var lines = this.$lines || this.getAllLines();
  20511. var newlineLength = this.getNewLineCharacter().length;
  20512. var index = 0;
  20513. var row = Math.min(pos.row, lines.length);
  20514. for (var i = startRow || 0; i < row; ++i)
  20515. index += lines[i].length + newlineLength;
  20516. return index + pos.column;
  20517. };
  20518. }).call(Document.prototype);
  20519. exports.Document = Document;
  20520. });
  20521. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(acequire, exports, module) {
  20522. "use strict";
  20523. var oop = acequire("./lib/oop");
  20524. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  20525. var BackgroundTokenizer = function(tokenizer, editor) {
  20526. this.running = false;
  20527. this.lines = [];
  20528. this.states = [];
  20529. this.currentLine = 0;
  20530. this.tokenizer = tokenizer;
  20531. var self = this;
  20532. this.$worker = function() {
  20533. if (!self.running) { return; }
  20534. var workerStart = new Date();
  20535. var currentLine = self.currentLine;
  20536. var endLine = -1;
  20537. var doc = self.doc;
  20538. var startLine = currentLine;
  20539. while (self.lines[currentLine])
  20540. currentLine++;
  20541. var len = doc.getLength();
  20542. var processedLines = 0;
  20543. self.running = false;
  20544. while (currentLine < len) {
  20545. self.$tokenizeRow(currentLine);
  20546. endLine = currentLine;
  20547. do {
  20548. currentLine++;
  20549. } while (self.lines[currentLine]);
  20550. processedLines ++;
  20551. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  20552. self.running = setTimeout(self.$worker, 20);
  20553. break;
  20554. }
  20555. }
  20556. self.currentLine = currentLine;
  20557. if (startLine <= endLine)
  20558. self.fireUpdateEvent(startLine, endLine);
  20559. };
  20560. };
  20561. (function(){
  20562. oop.implement(this, EventEmitter);
  20563. this.setTokenizer = function(tokenizer) {
  20564. this.tokenizer = tokenizer;
  20565. this.lines = [];
  20566. this.states = [];
  20567. this.start(0);
  20568. };
  20569. this.setDocument = function(doc) {
  20570. this.doc = doc;
  20571. this.lines = [];
  20572. this.states = [];
  20573. this.stop();
  20574. };
  20575. this.fireUpdateEvent = function(firstRow, lastRow) {
  20576. var data = {
  20577. first: firstRow,
  20578. last: lastRow
  20579. };
  20580. this._signal("update", {data: data});
  20581. };
  20582. this.start = function(startRow) {
  20583. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  20584. this.lines.splice(this.currentLine, this.lines.length);
  20585. this.states.splice(this.currentLine, this.states.length);
  20586. this.stop();
  20587. this.running = setTimeout(this.$worker, 700);
  20588. };
  20589. this.scheduleStart = function() {
  20590. if (!this.running)
  20591. this.running = setTimeout(this.$worker, 700);
  20592. }
  20593. this.$updateOnChange = function(delta) {
  20594. var startRow = delta.start.row;
  20595. var len = delta.end.row - startRow;
  20596. if (len === 0) {
  20597. this.lines[startRow] = null;
  20598. } else if (delta.action == "remove") {
  20599. this.lines.splice(startRow, len + 1, null);
  20600. this.states.splice(startRow, len + 1, null);
  20601. } else {
  20602. var args = Array(len + 1);
  20603. args.unshift(startRow, 1);
  20604. this.lines.splice.apply(this.lines, args);
  20605. this.states.splice.apply(this.states, args);
  20606. }
  20607. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  20608. this.stop();
  20609. };
  20610. this.stop = function() {
  20611. if (this.running)
  20612. clearTimeout(this.running);
  20613. this.running = false;
  20614. };
  20615. this.getTokens = function(row) {
  20616. return this.lines[row] || this.$tokenizeRow(row);
  20617. };
  20618. this.getState = function(row) {
  20619. if (this.currentLine == row)
  20620. this.$tokenizeRow(row);
  20621. return this.states[row] || "start";
  20622. };
  20623. this.$tokenizeRow = function(row) {
  20624. var line = this.doc.getLine(row);
  20625. var state = this.states[row - 1];
  20626. var data = this.tokenizer.getLineTokens(line, state, row);
  20627. if (this.states[row] + "" !== data.state + "") {
  20628. this.states[row] = data.state;
  20629. this.lines[row + 1] = null;
  20630. if (this.currentLine > row + 1)
  20631. this.currentLine = row + 1;
  20632. } else if (this.currentLine == row) {
  20633. this.currentLine = row + 1;
  20634. }
  20635. return this.lines[row] = data.tokens;
  20636. };
  20637. }).call(BackgroundTokenizer.prototype);
  20638. exports.BackgroundTokenizer = BackgroundTokenizer;
  20639. });
  20640. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(acequire, exports, module) {
  20641. "use strict";
  20642. var lang = acequire("./lib/lang");
  20643. var oop = acequire("./lib/oop");
  20644. var Range = acequire("./range").Range;
  20645. var SearchHighlight = function(regExp, clazz, type) {
  20646. this.setRegexp(regExp);
  20647. this.clazz = clazz;
  20648. this.type = type || "text";
  20649. };
  20650. (function() {
  20651. this.MAX_RANGES = 500;
  20652. this.setRegexp = function(regExp) {
  20653. if (this.regExp+"" == regExp+"")
  20654. return;
  20655. this.regExp = regExp;
  20656. this.cache = [];
  20657. };
  20658. this.update = function(html, markerLayer, session, config) {
  20659. if (!this.regExp)
  20660. return;
  20661. var start = config.firstRow, end = config.lastRow;
  20662. for (var i = start; i <= end; i++) {
  20663. var ranges = this.cache[i];
  20664. if (ranges == null) {
  20665. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  20666. if (ranges.length > this.MAX_RANGES)
  20667. ranges = ranges.slice(0, this.MAX_RANGES);
  20668. ranges = ranges.map(function(match) {
  20669. return new Range(i, match.offset, i, match.offset + match.length);
  20670. });
  20671. this.cache[i] = ranges.length ? ranges : "";
  20672. }
  20673. for (var j = ranges.length; j --; ) {
  20674. markerLayer.drawSingleLineMarker(
  20675. html, ranges[j].toScreenRange(session), this.clazz, config);
  20676. }
  20677. }
  20678. };
  20679. }).call(SearchHighlight.prototype);
  20680. exports.SearchHighlight = SearchHighlight;
  20681. });
  20682. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(acequire, exports, module) {
  20683. "use strict";
  20684. var Range = acequire("../range").Range;
  20685. function FoldLine(foldData, folds) {
  20686. this.foldData = foldData;
  20687. if (Array.isArray(folds)) {
  20688. this.folds = folds;
  20689. } else {
  20690. folds = this.folds = [ folds ];
  20691. }
  20692. var last = folds[folds.length - 1];
  20693. this.range = new Range(folds[0].start.row, folds[0].start.column,
  20694. last.end.row, last.end.column);
  20695. this.start = this.range.start;
  20696. this.end = this.range.end;
  20697. this.folds.forEach(function(fold) {
  20698. fold.setFoldLine(this);
  20699. }, this);
  20700. }
  20701. (function() {
  20702. this.shiftRow = function(shift) {
  20703. this.start.row += shift;
  20704. this.end.row += shift;
  20705. this.folds.forEach(function(fold) {
  20706. fold.start.row += shift;
  20707. fold.end.row += shift;
  20708. });
  20709. };
  20710. this.addFold = function(fold) {
  20711. if (fold.sameRow) {
  20712. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  20713. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  20714. }
  20715. this.folds.push(fold);
  20716. this.folds.sort(function(a, b) {
  20717. return -a.range.compareEnd(b.start.row, b.start.column);
  20718. });
  20719. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  20720. this.end.row = fold.end.row;
  20721. this.end.column = fold.end.column;
  20722. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  20723. this.start.row = fold.start.row;
  20724. this.start.column = fold.start.column;
  20725. }
  20726. } else if (fold.start.row == this.end.row) {
  20727. this.folds.push(fold);
  20728. this.end.row = fold.end.row;
  20729. this.end.column = fold.end.column;
  20730. } else if (fold.end.row == this.start.row) {
  20731. this.folds.unshift(fold);
  20732. this.start.row = fold.start.row;
  20733. this.start.column = fold.start.column;
  20734. } else {
  20735. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  20736. }
  20737. fold.foldLine = this;
  20738. };
  20739. this.containsRow = function(row) {
  20740. return row >= this.start.row && row <= this.end.row;
  20741. };
  20742. this.walk = function(callback, endRow, endColumn) {
  20743. var lastEnd = 0,
  20744. folds = this.folds,
  20745. fold,
  20746. cmp, stop, isNewRow = true;
  20747. if (endRow == null) {
  20748. endRow = this.end.row;
  20749. endColumn = this.end.column;
  20750. }
  20751. for (var i = 0; i < folds.length; i++) {
  20752. fold = folds[i];
  20753. cmp = fold.range.compareStart(endRow, endColumn);
  20754. if (cmp == -1) {
  20755. callback(null, endRow, endColumn, lastEnd, isNewRow);
  20756. return;
  20757. }
  20758. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  20759. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  20760. if (stop || cmp === 0) {
  20761. return;
  20762. }
  20763. isNewRow = !fold.sameRow;
  20764. lastEnd = fold.end.column;
  20765. }
  20766. callback(null, endRow, endColumn, lastEnd, isNewRow);
  20767. };
  20768. this.getNextFoldTo = function(row, column) {
  20769. var fold, cmp;
  20770. for (var i = 0; i < this.folds.length; i++) {
  20771. fold = this.folds[i];
  20772. cmp = fold.range.compareEnd(row, column);
  20773. if (cmp == -1) {
  20774. return {
  20775. fold: fold,
  20776. kind: "after"
  20777. };
  20778. } else if (cmp === 0) {
  20779. return {
  20780. fold: fold,
  20781. kind: "inside"
  20782. };
  20783. }
  20784. }
  20785. return null;
  20786. };
  20787. this.addRemoveChars = function(row, column, len) {
  20788. var ret = this.getNextFoldTo(row, column),
  20789. fold, folds;
  20790. if (ret) {
  20791. fold = ret.fold;
  20792. if (ret.kind == "inside"
  20793. && fold.start.column != column
  20794. && fold.start.row != row)
  20795. {
  20796. window.console && window.console.log(row, column, fold);
  20797. } else if (fold.start.row == row) {
  20798. folds = this.folds;
  20799. var i = folds.indexOf(fold);
  20800. if (i === 0) {
  20801. this.start.column += len;
  20802. }
  20803. for (i; i < folds.length; i++) {
  20804. fold = folds[i];
  20805. fold.start.column += len;
  20806. if (!fold.sameRow) {
  20807. return;
  20808. }
  20809. fold.end.column += len;
  20810. }
  20811. this.end.column += len;
  20812. }
  20813. }
  20814. };
  20815. this.split = function(row, column) {
  20816. var pos = this.getNextFoldTo(row, column);
  20817. if (!pos || pos.kind == "inside")
  20818. return null;
  20819. var fold = pos.fold;
  20820. var folds = this.folds;
  20821. var foldData = this.foldData;
  20822. var i = folds.indexOf(fold);
  20823. var foldBefore = folds[i - 1];
  20824. this.end.row = foldBefore.end.row;
  20825. this.end.column = foldBefore.end.column;
  20826. folds = folds.splice(i, folds.length - i);
  20827. var newFoldLine = new FoldLine(foldData, folds);
  20828. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  20829. return newFoldLine;
  20830. };
  20831. this.merge = function(foldLineNext) {
  20832. var folds = foldLineNext.folds;
  20833. for (var i = 0; i < folds.length; i++) {
  20834. this.addFold(folds[i]);
  20835. }
  20836. var foldData = this.foldData;
  20837. foldData.splice(foldData.indexOf(foldLineNext), 1);
  20838. };
  20839. this.toString = function() {
  20840. var ret = [this.range.toString() + ": [" ];
  20841. this.folds.forEach(function(fold) {
  20842. ret.push(" " + fold.toString());
  20843. });
  20844. ret.push("]");
  20845. return ret.join("\n");
  20846. };
  20847. this.idxToPosition = function(idx) {
  20848. var lastFoldEndColumn = 0;
  20849. for (var i = 0; i < this.folds.length; i++) {
  20850. var fold = this.folds[i];
  20851. idx -= fold.start.column - lastFoldEndColumn;
  20852. if (idx < 0) {
  20853. return {
  20854. row: fold.start.row,
  20855. column: fold.start.column + idx
  20856. };
  20857. }
  20858. idx -= fold.placeholder.length;
  20859. if (idx < 0) {
  20860. return fold.start;
  20861. }
  20862. lastFoldEndColumn = fold.end.column;
  20863. }
  20864. return {
  20865. row: this.end.row,
  20866. column: this.end.column + idx
  20867. };
  20868. };
  20869. }).call(FoldLine.prototype);
  20870. exports.FoldLine = FoldLine;
  20871. });
  20872. ace.define("ace/range_list",["require","exports","module","ace/range"], function(acequire, exports, module) {
  20873. "use strict";
  20874. var Range = acequire("./range").Range;
  20875. var comparePoints = Range.comparePoints;
  20876. var RangeList = function() {
  20877. this.ranges = [];
  20878. };
  20879. (function() {
  20880. this.comparePoints = comparePoints;
  20881. this.pointIndex = function(pos, excludeEdges, startIndex) {
  20882. var list = this.ranges;
  20883. for (var i = startIndex || 0; i < list.length; i++) {
  20884. var range = list[i];
  20885. var cmpEnd = comparePoints(pos, range.end);
  20886. if (cmpEnd > 0)
  20887. continue;
  20888. var cmpStart = comparePoints(pos, range.start);
  20889. if (cmpEnd === 0)
  20890. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  20891. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  20892. return i;
  20893. return -i-1;
  20894. }
  20895. return -i - 1;
  20896. };
  20897. this.add = function(range) {
  20898. var excludeEdges = !range.isEmpty();
  20899. var startIndex = this.pointIndex(range.start, excludeEdges);
  20900. if (startIndex < 0)
  20901. startIndex = -startIndex - 1;
  20902. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  20903. if (endIndex < 0)
  20904. endIndex = -endIndex - 1;
  20905. else
  20906. endIndex++;
  20907. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  20908. };
  20909. this.addList = function(list) {
  20910. var removed = [];
  20911. for (var i = list.length; i--; ) {
  20912. removed.push.apply(removed, this.add(list[i]));
  20913. }
  20914. return removed;
  20915. };
  20916. this.substractPoint = function(pos) {
  20917. var i = this.pointIndex(pos);
  20918. if (i >= 0)
  20919. return this.ranges.splice(i, 1);
  20920. };
  20921. this.merge = function() {
  20922. var removed = [];
  20923. var list = this.ranges;
  20924. list = list.sort(function(a, b) {
  20925. return comparePoints(a.start, b.start);
  20926. });
  20927. var next = list[0], range;
  20928. for (var i = 1; i < list.length; i++) {
  20929. range = next;
  20930. next = list[i];
  20931. var cmp = comparePoints(range.end, next.start);
  20932. if (cmp < 0)
  20933. continue;
  20934. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  20935. continue;
  20936. if (comparePoints(range.end, next.end) < 0) {
  20937. range.end.row = next.end.row;
  20938. range.end.column = next.end.column;
  20939. }
  20940. list.splice(i, 1);
  20941. removed.push(next);
  20942. next = range;
  20943. i--;
  20944. }
  20945. this.ranges = list;
  20946. return removed;
  20947. };
  20948. this.contains = function(row, column) {
  20949. return this.pointIndex({row: row, column: column}) >= 0;
  20950. };
  20951. this.containsPoint = function(pos) {
  20952. return this.pointIndex(pos) >= 0;
  20953. };
  20954. this.rangeAtPoint = function(pos) {
  20955. var i = this.pointIndex(pos);
  20956. if (i >= 0)
  20957. return this.ranges[i];
  20958. };
  20959. this.clipRows = function(startRow, endRow) {
  20960. var list = this.ranges;
  20961. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  20962. return [];
  20963. var startIndex = this.pointIndex({row: startRow, column: 0});
  20964. if (startIndex < 0)
  20965. startIndex = -startIndex - 1;
  20966. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  20967. if (endIndex < 0)
  20968. endIndex = -endIndex - 1;
  20969. var clipped = [];
  20970. for (var i = startIndex; i < endIndex; i++) {
  20971. clipped.push(list[i]);
  20972. }
  20973. return clipped;
  20974. };
  20975. this.removeAll = function() {
  20976. return this.ranges.splice(0, this.ranges.length);
  20977. };
  20978. this.attach = function(session) {
  20979. if (this.session)
  20980. this.detach();
  20981. this.session = session;
  20982. this.onChange = this.$onChange.bind(this);
  20983. this.session.on('change', this.onChange);
  20984. };
  20985. this.detach = function() {
  20986. if (!this.session)
  20987. return;
  20988. this.session.removeListener('change', this.onChange);
  20989. this.session = null;
  20990. };
  20991. this.$onChange = function(delta) {
  20992. if (delta.action == "insert"){
  20993. var start = delta.start;
  20994. var end = delta.end;
  20995. } else {
  20996. var end = delta.start;
  20997. var start = delta.end;
  20998. }
  20999. var startRow = start.row;
  21000. var endRow = end.row;
  21001. var lineDif = endRow - startRow;
  21002. var colDiff = -start.column + end.column;
  21003. var ranges = this.ranges;
  21004. for (var i = 0, n = ranges.length; i < n; i++) {
  21005. var r = ranges[i];
  21006. if (r.end.row < startRow)
  21007. continue;
  21008. if (r.start.row > startRow)
  21009. break;
  21010. if (r.start.row == startRow && r.start.column >= start.column ) {
  21011. if (r.start.column == start.column && this.$insertRight) {
  21012. } else {
  21013. r.start.column += colDiff;
  21014. r.start.row += lineDif;
  21015. }
  21016. }
  21017. if (r.end.row == startRow && r.end.column >= start.column) {
  21018. if (r.end.column == start.column && this.$insertRight) {
  21019. continue;
  21020. }
  21021. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  21022. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  21023. r.end.column -= colDiff;
  21024. }
  21025. r.end.column += colDiff;
  21026. r.end.row += lineDif;
  21027. }
  21028. }
  21029. if (lineDif != 0 && i < n) {
  21030. for (; i < n; i++) {
  21031. var r = ranges[i];
  21032. r.start.row += lineDif;
  21033. r.end.row += lineDif;
  21034. }
  21035. }
  21036. };
  21037. }).call(RangeList.prototype);
  21038. exports.RangeList = RangeList;
  21039. });
  21040. ace.define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(acequire, exports, module) {
  21041. "use strict";
  21042. var Range = acequire("../range").Range;
  21043. var RangeList = acequire("../range_list").RangeList;
  21044. var oop = acequire("../lib/oop")
  21045. var Fold = exports.Fold = function(range, placeholder) {
  21046. this.foldLine = null;
  21047. this.placeholder = placeholder;
  21048. this.range = range;
  21049. this.start = range.start;
  21050. this.end = range.end;
  21051. this.sameRow = range.start.row == range.end.row;
  21052. this.subFolds = this.ranges = [];
  21053. };
  21054. oop.inherits(Fold, RangeList);
  21055. (function() {
  21056. this.toString = function() {
  21057. return '"' + this.placeholder + '" ' + this.range.toString();
  21058. };
  21059. this.setFoldLine = function(foldLine) {
  21060. this.foldLine = foldLine;
  21061. this.subFolds.forEach(function(fold) {
  21062. fold.setFoldLine(foldLine);
  21063. });
  21064. };
  21065. this.clone = function() {
  21066. var range = this.range.clone();
  21067. var fold = new Fold(range, this.placeholder);
  21068. this.subFolds.forEach(function(subFold) {
  21069. fold.subFolds.push(subFold.clone());
  21070. });
  21071. fold.collapseChildren = this.collapseChildren;
  21072. return fold;
  21073. };
  21074. this.addSubFold = function(fold) {
  21075. if (this.range.isEqual(fold))
  21076. return;
  21077. if (!this.range.containsRange(fold))
  21078. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  21079. consumeRange(fold, this.start);
  21080. var row = fold.start.row, column = fold.start.column;
  21081. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  21082. cmp = this.subFolds[i].range.compare(row, column);
  21083. if (cmp != 1)
  21084. break;
  21085. }
  21086. var afterStart = this.subFolds[i];
  21087. if (cmp == 0)
  21088. return afterStart.addSubFold(fold);
  21089. var row = fold.range.end.row, column = fold.range.end.column;
  21090. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  21091. cmp = this.subFolds[j].range.compare(row, column);
  21092. if (cmp != 1)
  21093. break;
  21094. }
  21095. var afterEnd = this.subFolds[j];
  21096. if (cmp == 0)
  21097. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  21098. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  21099. fold.setFoldLine(this.foldLine);
  21100. return fold;
  21101. };
  21102. this.restoreRange = function(range) {
  21103. return restoreRange(range, this.start);
  21104. };
  21105. }).call(Fold.prototype);
  21106. function consumePoint(point, anchor) {
  21107. point.row -= anchor.row;
  21108. if (point.row == 0)
  21109. point.column -= anchor.column;
  21110. }
  21111. function consumeRange(range, anchor) {
  21112. consumePoint(range.start, anchor);
  21113. consumePoint(range.end, anchor);
  21114. }
  21115. function restorePoint(point, anchor) {
  21116. if (point.row == 0)
  21117. point.column += anchor.column;
  21118. point.row += anchor.row;
  21119. }
  21120. function restoreRange(range, anchor) {
  21121. restorePoint(range.start, anchor);
  21122. restorePoint(range.end, anchor);
  21123. }
  21124. });
  21125. ace.define("ace/edit_session/folding",["require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(acequire, exports, module) {
  21126. "use strict";
  21127. var Range = acequire("../range").Range;
  21128. var FoldLine = acequire("./fold_line").FoldLine;
  21129. var Fold = acequire("./fold").Fold;
  21130. var TokenIterator = acequire("../token_iterator").TokenIterator;
  21131. function Folding() {
  21132. this.getFoldAt = function(row, column, side) {
  21133. var foldLine = this.getFoldLine(row);
  21134. if (!foldLine)
  21135. return null;
  21136. var folds = foldLine.folds;
  21137. for (var i = 0; i < folds.length; i++) {
  21138. var fold = folds[i];
  21139. if (fold.range.contains(row, column)) {
  21140. if (side == 1 && fold.range.isEnd(row, column)) {
  21141. continue;
  21142. } else if (side == -1 && fold.range.isStart(row, column)) {
  21143. continue;
  21144. }
  21145. return fold;
  21146. }
  21147. }
  21148. };
  21149. this.getFoldsInRange = function(range) {
  21150. var start = range.start;
  21151. var end = range.end;
  21152. var foldLines = this.$foldData;
  21153. var foundFolds = [];
  21154. start.column += 1;
  21155. end.column -= 1;
  21156. for (var i = 0; i < foldLines.length; i++) {
  21157. var cmp = foldLines[i].range.compareRange(range);
  21158. if (cmp == 2) {
  21159. continue;
  21160. }
  21161. else if (cmp == -2) {
  21162. break;
  21163. }
  21164. var folds = foldLines[i].folds;
  21165. for (var j = 0; j < folds.length; j++) {
  21166. var fold = folds[j];
  21167. cmp = fold.range.compareRange(range);
  21168. if (cmp == -2) {
  21169. break;
  21170. } else if (cmp == 2) {
  21171. continue;
  21172. } else
  21173. if (cmp == 42) {
  21174. break;
  21175. }
  21176. foundFolds.push(fold);
  21177. }
  21178. }
  21179. start.column -= 1;
  21180. end.column += 1;
  21181. return foundFolds;
  21182. };
  21183. this.getFoldsInRangeList = function(ranges) {
  21184. if (Array.isArray(ranges)) {
  21185. var folds = [];
  21186. ranges.forEach(function(range) {
  21187. folds = folds.concat(this.getFoldsInRange(range));
  21188. }, this);
  21189. } else {
  21190. var folds = this.getFoldsInRange(ranges);
  21191. }
  21192. return folds;
  21193. };
  21194. this.getAllFolds = function() {
  21195. var folds = [];
  21196. var foldLines = this.$foldData;
  21197. for (var i = 0; i < foldLines.length; i++)
  21198. for (var j = 0; j < foldLines[i].folds.length; j++)
  21199. folds.push(foldLines[i].folds[j]);
  21200. return folds;
  21201. };
  21202. this.getFoldStringAt = function(row, column, trim, foldLine) {
  21203. foldLine = foldLine || this.getFoldLine(row);
  21204. if (!foldLine)
  21205. return null;
  21206. var lastFold = {
  21207. end: { column: 0 }
  21208. };
  21209. var str, fold;
  21210. for (var i = 0; i < foldLine.folds.length; i++) {
  21211. fold = foldLine.folds[i];
  21212. var cmp = fold.range.compareEnd(row, column);
  21213. if (cmp == -1) {
  21214. str = this
  21215. .getLine(fold.start.row)
  21216. .substring(lastFold.end.column, fold.start.column);
  21217. break;
  21218. }
  21219. else if (cmp === 0) {
  21220. return null;
  21221. }
  21222. lastFold = fold;
  21223. }
  21224. if (!str)
  21225. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  21226. if (trim == -1)
  21227. return str.substring(0, column - lastFold.end.column);
  21228. else if (trim == 1)
  21229. return str.substring(column - lastFold.end.column);
  21230. else
  21231. return str;
  21232. };
  21233. this.getFoldLine = function(docRow, startFoldLine) {
  21234. var foldData = this.$foldData;
  21235. var i = 0;
  21236. if (startFoldLine)
  21237. i = foldData.indexOf(startFoldLine);
  21238. if (i == -1)
  21239. i = 0;
  21240. for (i; i < foldData.length; i++) {
  21241. var foldLine = foldData[i];
  21242. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  21243. return foldLine;
  21244. } else if (foldLine.end.row > docRow) {
  21245. return null;
  21246. }
  21247. }
  21248. return null;
  21249. };
  21250. this.getNextFoldLine = function(docRow, startFoldLine) {
  21251. var foldData = this.$foldData;
  21252. var i = 0;
  21253. if (startFoldLine)
  21254. i = foldData.indexOf(startFoldLine);
  21255. if (i == -1)
  21256. i = 0;
  21257. for (i; i < foldData.length; i++) {
  21258. var foldLine = foldData[i];
  21259. if (foldLine.end.row >= docRow) {
  21260. return foldLine;
  21261. }
  21262. }
  21263. return null;
  21264. };
  21265. this.getFoldedRowCount = function(first, last) {
  21266. var foldData = this.$foldData, rowCount = last-first+1;
  21267. for (var i = 0; i < foldData.length; i++) {
  21268. var foldLine = foldData[i],
  21269. end = foldLine.end.row,
  21270. start = foldLine.start.row;
  21271. if (end >= last) {
  21272. if (start < last) {
  21273. if (start >= first)
  21274. rowCount -= last-start;
  21275. else
  21276. rowCount = 0; // in one fold
  21277. }
  21278. break;
  21279. } else if (end >= first){
  21280. if (start >= first) // fold inside range
  21281. rowCount -= end-start;
  21282. else
  21283. rowCount -= end-first+1;
  21284. }
  21285. }
  21286. return rowCount;
  21287. };
  21288. this.$addFoldLine = function(foldLine) {
  21289. this.$foldData.push(foldLine);
  21290. this.$foldData.sort(function(a, b) {
  21291. return a.start.row - b.start.row;
  21292. });
  21293. return foldLine;
  21294. };
  21295. this.addFold = function(placeholder, range) {
  21296. var foldData = this.$foldData;
  21297. var added = false;
  21298. var fold;
  21299. if (placeholder instanceof Fold)
  21300. fold = placeholder;
  21301. else {
  21302. fold = new Fold(range, placeholder);
  21303. fold.collapseChildren = range.collapseChildren;
  21304. }
  21305. this.$clipRangeToDocument(fold.range);
  21306. var startRow = fold.start.row;
  21307. var startColumn = fold.start.column;
  21308. var endRow = fold.end.row;
  21309. var endColumn = fold.end.column;
  21310. if (!(startRow < endRow ||
  21311. startRow == endRow && startColumn <= endColumn - 2))
  21312. throw new Error("The range has to be at least 2 characters width");
  21313. var startFold = this.getFoldAt(startRow, startColumn, 1);
  21314. var endFold = this.getFoldAt(endRow, endColumn, -1);
  21315. if (startFold && endFold == startFold)
  21316. return startFold.addSubFold(fold);
  21317. if (startFold && !startFold.range.isStart(startRow, startColumn))
  21318. this.removeFold(startFold);
  21319. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  21320. this.removeFold(endFold);
  21321. var folds = this.getFoldsInRange(fold.range);
  21322. if (folds.length > 0) {
  21323. this.removeFolds(folds);
  21324. folds.forEach(function(subFold) {
  21325. fold.addSubFold(subFold);
  21326. });
  21327. }
  21328. for (var i = 0; i < foldData.length; i++) {
  21329. var foldLine = foldData[i];
  21330. if (endRow == foldLine.start.row) {
  21331. foldLine.addFold(fold);
  21332. added = true;
  21333. break;
  21334. } else if (startRow == foldLine.end.row) {
  21335. foldLine.addFold(fold);
  21336. added = true;
  21337. if (!fold.sameRow) {
  21338. var foldLineNext = foldData[i + 1];
  21339. if (foldLineNext && foldLineNext.start.row == endRow) {
  21340. foldLine.merge(foldLineNext);
  21341. break;
  21342. }
  21343. }
  21344. break;
  21345. } else if (endRow <= foldLine.start.row) {
  21346. break;
  21347. }
  21348. }
  21349. if (!added)
  21350. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  21351. if (this.$useWrapMode)
  21352. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  21353. else
  21354. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  21355. this.$modified = true;
  21356. this._signal("changeFold", { data: fold, action: "add" });
  21357. return fold;
  21358. };
  21359. this.addFolds = function(folds) {
  21360. folds.forEach(function(fold) {
  21361. this.addFold(fold);
  21362. }, this);
  21363. };
  21364. this.removeFold = function(fold) {
  21365. var foldLine = fold.foldLine;
  21366. var startRow = foldLine.start.row;
  21367. var endRow = foldLine.end.row;
  21368. var foldLines = this.$foldData;
  21369. var folds = foldLine.folds;
  21370. if (folds.length == 1) {
  21371. foldLines.splice(foldLines.indexOf(foldLine), 1);
  21372. } else
  21373. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  21374. folds.pop();
  21375. foldLine.end.row = folds[folds.length - 1].end.row;
  21376. foldLine.end.column = folds[folds.length - 1].end.column;
  21377. } else
  21378. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  21379. folds.shift();
  21380. foldLine.start.row = folds[0].start.row;
  21381. foldLine.start.column = folds[0].start.column;
  21382. } else
  21383. if (fold.sameRow) {
  21384. folds.splice(folds.indexOf(fold), 1);
  21385. } else
  21386. {
  21387. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  21388. folds = newFoldLine.folds;
  21389. folds.shift();
  21390. newFoldLine.start.row = folds[0].start.row;
  21391. newFoldLine.start.column = folds[0].start.column;
  21392. }
  21393. if (!this.$updating) {
  21394. if (this.$useWrapMode)
  21395. this.$updateWrapData(startRow, endRow);
  21396. else
  21397. this.$updateRowLengthCache(startRow, endRow);
  21398. }
  21399. this.$modified = true;
  21400. this._signal("changeFold", { data: fold, action: "remove" });
  21401. };
  21402. this.removeFolds = function(folds) {
  21403. var cloneFolds = [];
  21404. for (var i = 0; i < folds.length; i++) {
  21405. cloneFolds.push(folds[i]);
  21406. }
  21407. cloneFolds.forEach(function(fold) {
  21408. this.removeFold(fold);
  21409. }, this);
  21410. this.$modified = true;
  21411. };
  21412. this.expandFold = function(fold) {
  21413. this.removeFold(fold);
  21414. fold.subFolds.forEach(function(subFold) {
  21415. fold.restoreRange(subFold);
  21416. this.addFold(subFold);
  21417. }, this);
  21418. if (fold.collapseChildren > 0) {
  21419. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  21420. }
  21421. fold.subFolds = [];
  21422. };
  21423. this.expandFolds = function(folds) {
  21424. folds.forEach(function(fold) {
  21425. this.expandFold(fold);
  21426. }, this);
  21427. };
  21428. this.unfold = function(location, expandInner) {
  21429. var range, folds;
  21430. if (location == null) {
  21431. range = new Range(0, 0, this.getLength(), 0);
  21432. expandInner = true;
  21433. } else if (typeof location == "number")
  21434. range = new Range(location, 0, location, this.getLine(location).length);
  21435. else if ("row" in location)
  21436. range = Range.fromPoints(location, location);
  21437. else
  21438. range = location;
  21439. folds = this.getFoldsInRangeList(range);
  21440. if (expandInner) {
  21441. this.removeFolds(folds);
  21442. } else {
  21443. var subFolds = folds;
  21444. while (subFolds.length) {
  21445. this.expandFolds(subFolds);
  21446. subFolds = this.getFoldsInRangeList(range);
  21447. }
  21448. }
  21449. if (folds.length)
  21450. return folds;
  21451. };
  21452. this.isRowFolded = function(docRow, startFoldRow) {
  21453. return !!this.getFoldLine(docRow, startFoldRow);
  21454. };
  21455. this.getRowFoldEnd = function(docRow, startFoldRow) {
  21456. var foldLine = this.getFoldLine(docRow, startFoldRow);
  21457. return foldLine ? foldLine.end.row : docRow;
  21458. };
  21459. this.getRowFoldStart = function(docRow, startFoldRow) {
  21460. var foldLine = this.getFoldLine(docRow, startFoldRow);
  21461. return foldLine ? foldLine.start.row : docRow;
  21462. };
  21463. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  21464. if (startRow == null)
  21465. startRow = foldLine.start.row;
  21466. if (startColumn == null)
  21467. startColumn = 0;
  21468. if (endRow == null)
  21469. endRow = foldLine.end.row;
  21470. if (endColumn == null)
  21471. endColumn = this.getLine(endRow).length;
  21472. var doc = this.doc;
  21473. var textLine = "";
  21474. foldLine.walk(function(placeholder, row, column, lastColumn) {
  21475. if (row < startRow)
  21476. return;
  21477. if (row == startRow) {
  21478. if (column < startColumn)
  21479. return;
  21480. lastColumn = Math.max(startColumn, lastColumn);
  21481. }
  21482. if (placeholder != null) {
  21483. textLine += placeholder;
  21484. } else {
  21485. textLine += doc.getLine(row).substring(lastColumn, column);
  21486. }
  21487. }, endRow, endColumn);
  21488. return textLine;
  21489. };
  21490. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  21491. var foldLine = this.getFoldLine(row);
  21492. if (!foldLine) {
  21493. var line;
  21494. line = this.doc.getLine(row);
  21495. return line.substring(startColumn || 0, endColumn || line.length);
  21496. } else {
  21497. return this.getFoldDisplayLine(
  21498. foldLine, row, endColumn, startRow, startColumn);
  21499. }
  21500. };
  21501. this.$cloneFoldData = function() {
  21502. var fd = [];
  21503. fd = this.$foldData.map(function(foldLine) {
  21504. var folds = foldLine.folds.map(function(fold) {
  21505. return fold.clone();
  21506. });
  21507. return new FoldLine(fd, folds);
  21508. });
  21509. return fd;
  21510. };
  21511. this.toggleFold = function(tryToUnfold) {
  21512. var selection = this.selection;
  21513. var range = selection.getRange();
  21514. var fold;
  21515. var bracketPos;
  21516. if (range.isEmpty()) {
  21517. var cursor = range.start;
  21518. fold = this.getFoldAt(cursor.row, cursor.column);
  21519. if (fold) {
  21520. this.expandFold(fold);
  21521. return;
  21522. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  21523. if (range.comparePoint(bracketPos) == 1) {
  21524. range.end = bracketPos;
  21525. } else {
  21526. range.start = bracketPos;
  21527. range.start.column++;
  21528. range.end.column--;
  21529. }
  21530. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  21531. if (range.comparePoint(bracketPos) == 1)
  21532. range.end = bracketPos;
  21533. else
  21534. range.start = bracketPos;
  21535. range.start.column++;
  21536. } else {
  21537. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  21538. }
  21539. } else {
  21540. var folds = this.getFoldsInRange(range);
  21541. if (tryToUnfold && folds.length) {
  21542. this.expandFolds(folds);
  21543. return;
  21544. } else if (folds.length == 1 ) {
  21545. fold = folds[0];
  21546. }
  21547. }
  21548. if (!fold)
  21549. fold = this.getFoldAt(range.start.row, range.start.column);
  21550. if (fold && fold.range.toString() == range.toString()) {
  21551. this.expandFold(fold);
  21552. return;
  21553. }
  21554. var placeholder = "...";
  21555. if (!range.isMultiLine()) {
  21556. placeholder = this.getTextRange(range);
  21557. if (placeholder.length < 4)
  21558. return;
  21559. placeholder = placeholder.trim().substring(0, 2) + "..";
  21560. }
  21561. this.addFold(placeholder, range);
  21562. };
  21563. this.getCommentFoldRange = function(row, column, dir) {
  21564. var iterator = new TokenIterator(this, row, column);
  21565. var token = iterator.getCurrentToken();
  21566. if (token && /^comment|string/.test(token.type)) {
  21567. var range = new Range();
  21568. var re = new RegExp(token.type.replace(/\..*/, "\\."));
  21569. if (dir != 1) {
  21570. do {
  21571. token = iterator.stepBackward();
  21572. } while (token && re.test(token.type));
  21573. iterator.stepForward();
  21574. }
  21575. range.start.row = iterator.getCurrentTokenRow();
  21576. range.start.column = iterator.getCurrentTokenColumn() + 2;
  21577. iterator = new TokenIterator(this, row, column);
  21578. if (dir != -1) {
  21579. do {
  21580. token = iterator.stepForward();
  21581. } while (token && re.test(token.type));
  21582. token = iterator.stepBackward();
  21583. } else
  21584. token = iterator.getCurrentToken();
  21585. range.end.row = iterator.getCurrentTokenRow();
  21586. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  21587. return range;
  21588. }
  21589. };
  21590. this.foldAll = function(startRow, endRow, depth) {
  21591. if (depth == undefined)
  21592. depth = 100000; // JSON.stringify doesn't hanle Infinity
  21593. var foldWidgets = this.foldWidgets;
  21594. if (!foldWidgets)
  21595. return; // mode doesn't support folding
  21596. endRow = endRow || this.getLength();
  21597. startRow = startRow || 0;
  21598. for (var row = startRow; row < endRow; row++) {
  21599. if (foldWidgets[row] == null)
  21600. foldWidgets[row] = this.getFoldWidget(row);
  21601. if (foldWidgets[row] != "start")
  21602. continue;
  21603. var range = this.getFoldWidgetRange(row);
  21604. if (range && range.isMultiLine()
  21605. && range.end.row <= endRow
  21606. && range.start.row >= startRow
  21607. ) {
  21608. row = range.end.row;
  21609. try {
  21610. var fold = this.addFold("...", range);
  21611. if (fold)
  21612. fold.collapseChildren = depth;
  21613. } catch(e) {}
  21614. }
  21615. }
  21616. };
  21617. this.$foldStyles = {
  21618. "manual": 1,
  21619. "markbegin": 1,
  21620. "markbeginend": 1
  21621. };
  21622. this.$foldStyle = "markbegin";
  21623. this.setFoldStyle = function(style) {
  21624. if (!this.$foldStyles[style])
  21625. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  21626. if (this.$foldStyle == style)
  21627. return;
  21628. this.$foldStyle = style;
  21629. if (style == "manual")
  21630. this.unfold();
  21631. var mode = this.$foldMode;
  21632. this.$setFolding(null);
  21633. this.$setFolding(mode);
  21634. };
  21635. this.$setFolding = function(foldMode) {
  21636. if (this.$foldMode == foldMode)
  21637. return;
  21638. this.$foldMode = foldMode;
  21639. this.off('change', this.$updateFoldWidgets);
  21640. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  21641. this._signal("changeAnnotation");
  21642. if (!foldMode || this.$foldStyle == "manual") {
  21643. this.foldWidgets = null;
  21644. return;
  21645. }
  21646. this.foldWidgets = [];
  21647. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  21648. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  21649. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  21650. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  21651. this.on('change', this.$updateFoldWidgets);
  21652. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  21653. };
  21654. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  21655. var fw = this.foldWidgets;
  21656. if (!fw || (ignoreCurrent && fw[row]))
  21657. return {};
  21658. var i = row - 1, firstRange;
  21659. while (i >= 0) {
  21660. var c = fw[i];
  21661. if (c == null)
  21662. c = fw[i] = this.getFoldWidget(i);
  21663. if (c == "start") {
  21664. var range = this.getFoldWidgetRange(i);
  21665. if (!firstRange)
  21666. firstRange = range;
  21667. if (range && range.end.row >= row)
  21668. break;
  21669. }
  21670. i--;
  21671. }
  21672. return {
  21673. range: i !== -1 && range,
  21674. firstRange: firstRange
  21675. };
  21676. };
  21677. this.onFoldWidgetClick = function(row, e) {
  21678. e = e.domEvent;
  21679. var options = {
  21680. children: e.shiftKey,
  21681. all: e.ctrlKey || e.metaKey,
  21682. siblings: e.altKey
  21683. };
  21684. var range = this.$toggleFoldWidget(row, options);
  21685. if (!range) {
  21686. var el = (e.target || e.srcElement);
  21687. if (el && /ace_fold-widget/.test(el.className))
  21688. el.className += " ace_invalid";
  21689. }
  21690. };
  21691. this.$toggleFoldWidget = function(row, options) {
  21692. if (!this.getFoldWidget)
  21693. return;
  21694. var type = this.getFoldWidget(row);
  21695. var line = this.getLine(row);
  21696. var dir = type === "end" ? -1 : 1;
  21697. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  21698. if (fold) {
  21699. if (options.children || options.all)
  21700. this.removeFold(fold);
  21701. else
  21702. this.expandFold(fold);
  21703. return;
  21704. }
  21705. var range = this.getFoldWidgetRange(row, true);
  21706. if (range && !range.isMultiLine()) {
  21707. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  21708. if (fold && range.isEqual(fold.range)) {
  21709. this.removeFold(fold);
  21710. return;
  21711. }
  21712. }
  21713. if (options.siblings) {
  21714. var data = this.getParentFoldRangeData(row);
  21715. if (data.range) {
  21716. var startRow = data.range.start.row + 1;
  21717. var endRow = data.range.end.row;
  21718. }
  21719. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  21720. } else if (options.children) {
  21721. endRow = range ? range.end.row : this.getLength();
  21722. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  21723. } else if (range) {
  21724. if (options.all)
  21725. range.collapseChildren = 10000;
  21726. this.addFold("...", range);
  21727. }
  21728. return range;
  21729. };
  21730. this.toggleFoldWidget = function(toggleParent) {
  21731. var row = this.selection.getCursor().row;
  21732. row = this.getRowFoldStart(row);
  21733. var range = this.$toggleFoldWidget(row, {});
  21734. if (range)
  21735. return;
  21736. var data = this.getParentFoldRangeData(row, true);
  21737. range = data.range || data.firstRange;
  21738. if (range) {
  21739. row = range.start.row;
  21740. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  21741. if (fold) {
  21742. this.removeFold(fold);
  21743. } else {
  21744. this.addFold("...", range);
  21745. }
  21746. }
  21747. };
  21748. this.updateFoldWidgets = function(delta) {
  21749. var firstRow = delta.start.row;
  21750. var len = delta.end.row - firstRow;
  21751. if (len === 0) {
  21752. this.foldWidgets[firstRow] = null;
  21753. } else if (delta.action == 'remove') {
  21754. this.foldWidgets.splice(firstRow, len + 1, null);
  21755. } else {
  21756. var args = Array(len + 1);
  21757. args.unshift(firstRow, 1);
  21758. this.foldWidgets.splice.apply(this.foldWidgets, args);
  21759. }
  21760. };
  21761. this.tokenizerUpdateFoldWidgets = function(e) {
  21762. var rows = e.data;
  21763. if (rows.first != rows.last) {
  21764. if (this.foldWidgets.length > rows.first)
  21765. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  21766. }
  21767. };
  21768. }
  21769. exports.Folding = Folding;
  21770. });
  21771. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(acequire, exports, module) {
  21772. "use strict";
  21773. var TokenIterator = acequire("../token_iterator").TokenIterator;
  21774. var Range = acequire("../range").Range;
  21775. function BracketMatch() {
  21776. this.findMatchingBracket = function(position, chr) {
  21777. if (position.column == 0) return null;
  21778. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  21779. if (charBeforeCursor == "") return null;
  21780. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  21781. if (!match)
  21782. return null;
  21783. if (match[1])
  21784. return this.$findClosingBracket(match[1], position);
  21785. else
  21786. return this.$findOpeningBracket(match[2], position);
  21787. };
  21788. this.getBracketRange = function(pos) {
  21789. var line = this.getLine(pos.row);
  21790. var before = true, range;
  21791. var chr = line.charAt(pos.column-1);
  21792. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  21793. if (!match) {
  21794. chr = line.charAt(pos.column);
  21795. pos = {row: pos.row, column: pos.column + 1};
  21796. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  21797. before = false;
  21798. }
  21799. if (!match)
  21800. return null;
  21801. if (match[1]) {
  21802. var bracketPos = this.$findClosingBracket(match[1], pos);
  21803. if (!bracketPos)
  21804. return null;
  21805. range = Range.fromPoints(pos, bracketPos);
  21806. if (!before) {
  21807. range.end.column++;
  21808. range.start.column--;
  21809. }
  21810. range.cursor = range.end;
  21811. } else {
  21812. var bracketPos = this.$findOpeningBracket(match[2], pos);
  21813. if (!bracketPos)
  21814. return null;
  21815. range = Range.fromPoints(bracketPos, pos);
  21816. if (!before) {
  21817. range.start.column++;
  21818. range.end.column--;
  21819. }
  21820. range.cursor = range.start;
  21821. }
  21822. return range;
  21823. };
  21824. this.$brackets = {
  21825. ")": "(",
  21826. "(": ")",
  21827. "]": "[",
  21828. "[": "]",
  21829. "{": "}",
  21830. "}": "{"
  21831. };
  21832. this.$findOpeningBracket = function(bracket, position, typeRe) {
  21833. var openBracket = this.$brackets[bracket];
  21834. var depth = 1;
  21835. var iterator = new TokenIterator(this, position.row, position.column);
  21836. var token = iterator.getCurrentToken();
  21837. if (!token)
  21838. token = iterator.stepForward();
  21839. if (!token)
  21840. return;
  21841. if (!typeRe){
  21842. typeRe = new RegExp(
  21843. "(\\.?" +
  21844. token.type.replace(".", "\\.").replace("rparen", ".paren")
  21845. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  21846. + ")+"
  21847. );
  21848. }
  21849. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  21850. var value = token.value;
  21851. while (true) {
  21852. while (valueIndex >= 0) {
  21853. var chr = value.charAt(valueIndex);
  21854. if (chr == openBracket) {
  21855. depth -= 1;
  21856. if (depth == 0) {
  21857. return {row: iterator.getCurrentTokenRow(),
  21858. column: valueIndex + iterator.getCurrentTokenColumn()};
  21859. }
  21860. }
  21861. else if (chr == bracket) {
  21862. depth += 1;
  21863. }
  21864. valueIndex -= 1;
  21865. }
  21866. do {
  21867. token = iterator.stepBackward();
  21868. } while (token && !typeRe.test(token.type));
  21869. if (token == null)
  21870. break;
  21871. value = token.value;
  21872. valueIndex = value.length - 1;
  21873. }
  21874. return null;
  21875. };
  21876. this.$findClosingBracket = function(bracket, position, typeRe) {
  21877. var closingBracket = this.$brackets[bracket];
  21878. var depth = 1;
  21879. var iterator = new TokenIterator(this, position.row, position.column);
  21880. var token = iterator.getCurrentToken();
  21881. if (!token)
  21882. token = iterator.stepForward();
  21883. if (!token)
  21884. return;
  21885. if (!typeRe){
  21886. typeRe = new RegExp(
  21887. "(\\.?" +
  21888. token.type.replace(".", "\\.").replace("lparen", ".paren")
  21889. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  21890. + ")+"
  21891. );
  21892. }
  21893. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  21894. while (true) {
  21895. var value = token.value;
  21896. var valueLength = value.length;
  21897. while (valueIndex < valueLength) {
  21898. var chr = value.charAt(valueIndex);
  21899. if (chr == closingBracket) {
  21900. depth -= 1;
  21901. if (depth == 0) {
  21902. return {row: iterator.getCurrentTokenRow(),
  21903. column: valueIndex + iterator.getCurrentTokenColumn()};
  21904. }
  21905. }
  21906. else if (chr == bracket) {
  21907. depth += 1;
  21908. }
  21909. valueIndex += 1;
  21910. }
  21911. do {
  21912. token = iterator.stepForward();
  21913. } while (token && !typeRe.test(token.type));
  21914. if (token == null)
  21915. break;
  21916. valueIndex = 0;
  21917. }
  21918. return null;
  21919. };
  21920. }
  21921. exports.BracketMatch = BracketMatch;
  21922. });
  21923. ace.define("ace/edit_session",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/config","ace/lib/event_emitter","ace/selection","ace/mode/text","ace/range","ace/document","ace/background_tokenizer","ace/search_highlight","ace/edit_session/folding","ace/edit_session/bracket_match"], function(acequire, exports, module) {
  21924. "use strict";
  21925. var oop = acequire("./lib/oop");
  21926. var lang = acequire("./lib/lang");
  21927. var config = acequire("./config");
  21928. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  21929. var Selection = acequire("./selection").Selection;
  21930. var TextMode = acequire("./mode/text").Mode;
  21931. var Range = acequire("./range").Range;
  21932. var Document = acequire("./document").Document;
  21933. var BackgroundTokenizer = acequire("./background_tokenizer").BackgroundTokenizer;
  21934. var SearchHighlight = acequire("./search_highlight").SearchHighlight;
  21935. var EditSession = function(text, mode) {
  21936. this.$breakpoints = [];
  21937. this.$decorations = [];
  21938. this.$frontMarkers = {};
  21939. this.$backMarkers = {};
  21940. this.$markerId = 1;
  21941. this.$undoSelect = true;
  21942. this.$foldData = [];
  21943. this.$foldData.toString = function() {
  21944. return this.join("\n");
  21945. };
  21946. this.on("changeFold", this.onChangeFold.bind(this));
  21947. this.$onChange = this.onChange.bind(this);
  21948. if (typeof text != "object" || !text.getLine)
  21949. text = new Document(text);
  21950. this.setDocument(text);
  21951. this.selection = new Selection(this);
  21952. config.resetOptions(this);
  21953. this.setMode(mode);
  21954. config._signal("session", this);
  21955. };
  21956. (function() {
  21957. oop.implement(this, EventEmitter);
  21958. this.setDocument = function(doc) {
  21959. if (this.doc)
  21960. this.doc.removeListener("change", this.$onChange);
  21961. this.doc = doc;
  21962. doc.on("change", this.$onChange);
  21963. if (this.bgTokenizer)
  21964. this.bgTokenizer.setDocument(this.getDocument());
  21965. this.resetCaches();
  21966. };
  21967. this.getDocument = function() {
  21968. return this.doc;
  21969. };
  21970. this.$resetRowCache = function(docRow) {
  21971. if (!docRow) {
  21972. this.$docRowCache = [];
  21973. this.$screenRowCache = [];
  21974. return;
  21975. }
  21976. var l = this.$docRowCache.length;
  21977. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  21978. if (l > i) {
  21979. this.$docRowCache.splice(i, l);
  21980. this.$screenRowCache.splice(i, l);
  21981. }
  21982. };
  21983. this.$getRowCacheIndex = function(cacheArray, val) {
  21984. var low = 0;
  21985. var hi = cacheArray.length - 1;
  21986. while (low <= hi) {
  21987. var mid = (low + hi) >> 1;
  21988. var c = cacheArray[mid];
  21989. if (val > c)
  21990. low = mid + 1;
  21991. else if (val < c)
  21992. hi = mid - 1;
  21993. else
  21994. return mid;
  21995. }
  21996. return low -1;
  21997. };
  21998. this.resetCaches = function() {
  21999. this.$modified = true;
  22000. this.$wrapData = [];
  22001. this.$rowLengthCache = [];
  22002. this.$resetRowCache(0);
  22003. if (this.bgTokenizer)
  22004. this.bgTokenizer.start(0);
  22005. };
  22006. this.onChangeFold = function(e) {
  22007. var fold = e.data;
  22008. this.$resetRowCache(fold.start.row);
  22009. };
  22010. this.onChange = function(delta) {
  22011. this.$modified = true;
  22012. this.$resetRowCache(delta.start.row);
  22013. var removedFolds = this.$updateInternalDataOnChange(delta);
  22014. if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
  22015. this.$deltasDoc.push(delta);
  22016. if (removedFolds && removedFolds.length != 0) {
  22017. this.$deltasFold.push({
  22018. action: "removeFolds",
  22019. folds: removedFolds
  22020. });
  22021. }
  22022. this.$informUndoManager.schedule();
  22023. }
  22024. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  22025. this._signal("change", delta);
  22026. };
  22027. this.setValue = function(text) {
  22028. this.doc.setValue(text);
  22029. this.selection.moveTo(0, 0);
  22030. this.$resetRowCache(0);
  22031. this.$deltas = [];
  22032. this.$deltasDoc = [];
  22033. this.$deltasFold = [];
  22034. this.setUndoManager(this.$undoManager);
  22035. this.getUndoManager().reset();
  22036. };
  22037. this.getValue =
  22038. this.toString = function() {
  22039. return this.doc.getValue();
  22040. };
  22041. this.getSelection = function() {
  22042. return this.selection;
  22043. };
  22044. this.getState = function(row) {
  22045. return this.bgTokenizer.getState(row);
  22046. };
  22047. this.getTokens = function(row) {
  22048. return this.bgTokenizer.getTokens(row);
  22049. };
  22050. this.getTokenAt = function(row, column) {
  22051. var tokens = this.bgTokenizer.getTokens(row);
  22052. var token, c = 0;
  22053. if (column == null) {
  22054. i = tokens.length - 1;
  22055. c = this.getLine(row).length;
  22056. } else {
  22057. for (var i = 0; i < tokens.length; i++) {
  22058. c += tokens[i].value.length;
  22059. if (c >= column)
  22060. break;
  22061. }
  22062. }
  22063. token = tokens[i];
  22064. if (!token)
  22065. return null;
  22066. token.index = i;
  22067. token.start = c - token.value.length;
  22068. return token;
  22069. };
  22070. this.setUndoManager = function(undoManager) {
  22071. this.$undoManager = undoManager;
  22072. this.$deltas = [];
  22073. this.$deltasDoc = [];
  22074. this.$deltasFold = [];
  22075. if (this.$informUndoManager)
  22076. this.$informUndoManager.cancel();
  22077. if (undoManager) {
  22078. var self = this;
  22079. this.$syncInformUndoManager = function() {
  22080. self.$informUndoManager.cancel();
  22081. if (self.$deltasFold.length) {
  22082. self.$deltas.push({
  22083. group: "fold",
  22084. deltas: self.$deltasFold
  22085. });
  22086. self.$deltasFold = [];
  22087. }
  22088. if (self.$deltasDoc.length) {
  22089. self.$deltas.push({
  22090. group: "doc",
  22091. deltas: self.$deltasDoc
  22092. });
  22093. self.$deltasDoc = [];
  22094. }
  22095. if (self.$deltas.length > 0) {
  22096. undoManager.execute({
  22097. action: "aceupdate",
  22098. args: [self.$deltas, self],
  22099. merge: self.mergeUndoDeltas
  22100. });
  22101. }
  22102. self.mergeUndoDeltas = false;
  22103. self.$deltas = [];
  22104. };
  22105. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  22106. }
  22107. };
  22108. this.markUndoGroup = function() {
  22109. if (this.$syncInformUndoManager)
  22110. this.$syncInformUndoManager();
  22111. };
  22112. this.$defaultUndoManager = {
  22113. undo: function() {},
  22114. redo: function() {},
  22115. reset: function() {}
  22116. };
  22117. this.getUndoManager = function() {
  22118. return this.$undoManager || this.$defaultUndoManager;
  22119. };
  22120. this.getTabString = function() {
  22121. if (this.getUseSoftTabs()) {
  22122. return lang.stringRepeat(" ", this.getTabSize());
  22123. } else {
  22124. return "\t";
  22125. }
  22126. };
  22127. this.setUseSoftTabs = function(val) {
  22128. this.setOption("useSoftTabs", val);
  22129. };
  22130. this.getUseSoftTabs = function() {
  22131. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  22132. };
  22133. this.setTabSize = function(tabSize) {
  22134. this.setOption("tabSize", tabSize);
  22135. };
  22136. this.getTabSize = function() {
  22137. return this.$tabSize;
  22138. };
  22139. this.isTabStop = function(position) {
  22140. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  22141. };
  22142. this.$overwrite = false;
  22143. this.setOverwrite = function(overwrite) {
  22144. this.setOption("overwrite", overwrite);
  22145. };
  22146. this.getOverwrite = function() {
  22147. return this.$overwrite;
  22148. };
  22149. this.toggleOverwrite = function() {
  22150. this.setOverwrite(!this.$overwrite);
  22151. };
  22152. this.addGutterDecoration = function(row, className) {
  22153. if (!this.$decorations[row])
  22154. this.$decorations[row] = "";
  22155. this.$decorations[row] += " " + className;
  22156. this._signal("changeBreakpoint", {});
  22157. };
  22158. this.removeGutterDecoration = function(row, className) {
  22159. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  22160. this._signal("changeBreakpoint", {});
  22161. };
  22162. this.getBreakpoints = function() {
  22163. return this.$breakpoints;
  22164. };
  22165. this.setBreakpoints = function(rows) {
  22166. this.$breakpoints = [];
  22167. for (var i=0; i<rows.length; i++) {
  22168. this.$breakpoints[rows[i]] = "ace_breakpoint";
  22169. }
  22170. this._signal("changeBreakpoint", {});
  22171. };
  22172. this.clearBreakpoints = function() {
  22173. this.$breakpoints = [];
  22174. this._signal("changeBreakpoint", {});
  22175. };
  22176. this.setBreakpoint = function(row, className) {
  22177. if (className === undefined)
  22178. className = "ace_breakpoint";
  22179. if (className)
  22180. this.$breakpoints[row] = className;
  22181. else
  22182. delete this.$breakpoints[row];
  22183. this._signal("changeBreakpoint", {});
  22184. };
  22185. this.clearBreakpoint = function(row) {
  22186. delete this.$breakpoints[row];
  22187. this._signal("changeBreakpoint", {});
  22188. };
  22189. this.addMarker = function(range, clazz, type, inFront) {
  22190. var id = this.$markerId++;
  22191. var marker = {
  22192. range : range,
  22193. type : type || "line",
  22194. renderer: typeof type == "function" ? type : null,
  22195. clazz : clazz,
  22196. inFront: !!inFront,
  22197. id: id
  22198. };
  22199. if (inFront) {
  22200. this.$frontMarkers[id] = marker;
  22201. this._signal("changeFrontMarker");
  22202. } else {
  22203. this.$backMarkers[id] = marker;
  22204. this._signal("changeBackMarker");
  22205. }
  22206. return id;
  22207. };
  22208. this.addDynamicMarker = function(marker, inFront) {
  22209. if (!marker.update)
  22210. return;
  22211. var id = this.$markerId++;
  22212. marker.id = id;
  22213. marker.inFront = !!inFront;
  22214. if (inFront) {
  22215. this.$frontMarkers[id] = marker;
  22216. this._signal("changeFrontMarker");
  22217. } else {
  22218. this.$backMarkers[id] = marker;
  22219. this._signal("changeBackMarker");
  22220. }
  22221. return marker;
  22222. };
  22223. this.removeMarker = function(markerId) {
  22224. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  22225. if (!marker)
  22226. return;
  22227. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  22228. if (marker) {
  22229. delete (markers[markerId]);
  22230. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  22231. }
  22232. };
  22233. this.getMarkers = function(inFront) {
  22234. return inFront ? this.$frontMarkers : this.$backMarkers;
  22235. };
  22236. this.highlight = function(re) {
  22237. if (!this.$searchHighlight) {
  22238. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  22239. this.$searchHighlight = this.addDynamicMarker(highlight);
  22240. }
  22241. this.$searchHighlight.setRegexp(re);
  22242. };
  22243. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  22244. if (typeof endRow != "number") {
  22245. clazz = endRow;
  22246. endRow = startRow;
  22247. }
  22248. if (!clazz)
  22249. clazz = "ace_step";
  22250. var range = new Range(startRow, 0, endRow, Infinity);
  22251. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  22252. return range;
  22253. };
  22254. this.setAnnotations = function(annotations) {
  22255. this.$annotations = annotations;
  22256. this._signal("changeAnnotation", {});
  22257. };
  22258. this.getAnnotations = function() {
  22259. return this.$annotations || [];
  22260. };
  22261. this.clearAnnotations = function() {
  22262. this.setAnnotations([]);
  22263. };
  22264. this.$detectNewLine = function(text) {
  22265. var match = text.match(/^.*?(\r?\n)/m);
  22266. if (match) {
  22267. this.$autoNewLine = match[1];
  22268. } else {
  22269. this.$autoNewLine = "\n";
  22270. }
  22271. };
  22272. this.getWordRange = function(row, column) {
  22273. var line = this.getLine(row);
  22274. var inToken = false;
  22275. if (column > 0)
  22276. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  22277. if (!inToken)
  22278. inToken = !!line.charAt(column).match(this.tokenRe);
  22279. if (inToken)
  22280. var re = this.tokenRe;
  22281. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  22282. var re = /\s/;
  22283. else
  22284. var re = this.nonTokenRe;
  22285. var start = column;
  22286. if (start > 0) {
  22287. do {
  22288. start--;
  22289. }
  22290. while (start >= 0 && line.charAt(start).match(re));
  22291. start++;
  22292. }
  22293. var end = column;
  22294. while (end < line.length && line.charAt(end).match(re)) {
  22295. end++;
  22296. }
  22297. return new Range(row, start, row, end);
  22298. };
  22299. this.getAWordRange = function(row, column) {
  22300. var wordRange = this.getWordRange(row, column);
  22301. var line = this.getLine(wordRange.end.row);
  22302. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  22303. wordRange.end.column += 1;
  22304. }
  22305. return wordRange;
  22306. };
  22307. this.setNewLineMode = function(newLineMode) {
  22308. this.doc.setNewLineMode(newLineMode);
  22309. };
  22310. this.getNewLineMode = function() {
  22311. return this.doc.getNewLineMode();
  22312. };
  22313. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  22314. this.getUseWorker = function() { return this.$useWorker; };
  22315. this.onReloadTokenizer = function(e) {
  22316. var rows = e.data;
  22317. this.bgTokenizer.start(rows.first);
  22318. this._signal("tokenizerUpdate", e);
  22319. };
  22320. this.$modes = {};
  22321. this.$mode = null;
  22322. this.$modeId = null;
  22323. this.setMode = function(mode, cb) {
  22324. if (mode && typeof mode === "object") {
  22325. if (mode.getTokenizer)
  22326. return this.$onChangeMode(mode);
  22327. var options = mode;
  22328. var path = options.path;
  22329. } else {
  22330. path = mode || "ace/mode/text";
  22331. }
  22332. if (!this.$modes["ace/mode/text"])
  22333. this.$modes["ace/mode/text"] = new TextMode();
  22334. if (this.$modes[path] && !options) {
  22335. this.$onChangeMode(this.$modes[path]);
  22336. cb && cb();
  22337. return;
  22338. }
  22339. this.$modeId = path;
  22340. config.loadModule(["mode", path], function(m) {
  22341. if (this.$modeId !== path)
  22342. return cb && cb();
  22343. if (this.$modes[path] && !options) {
  22344. this.$onChangeMode(this.$modes[path]);
  22345. } else if (m && m.Mode) {
  22346. m = new m.Mode(options);
  22347. if (!options) {
  22348. this.$modes[path] = m;
  22349. m.$id = path;
  22350. }
  22351. this.$onChangeMode(m);
  22352. }
  22353. cb && cb();
  22354. }.bind(this));
  22355. if (!this.$mode)
  22356. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  22357. };
  22358. this.$onChangeMode = function(mode, $isPlaceholder) {
  22359. if (!$isPlaceholder)
  22360. this.$modeId = mode.$id;
  22361. if (this.$mode === mode)
  22362. return;
  22363. this.$mode = mode;
  22364. this.$stopWorker();
  22365. if (this.$useWorker)
  22366. this.$startWorker();
  22367. var tokenizer = mode.getTokenizer();
  22368. if(tokenizer.addEventListener !== undefined) {
  22369. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  22370. tokenizer.addEventListener("update", onReloadTokenizer);
  22371. }
  22372. if (!this.bgTokenizer) {
  22373. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  22374. var _self = this;
  22375. this.bgTokenizer.addEventListener("update", function(e) {
  22376. _self._signal("tokenizerUpdate", e);
  22377. });
  22378. } else {
  22379. this.bgTokenizer.setTokenizer(tokenizer);
  22380. }
  22381. this.bgTokenizer.setDocument(this.getDocument());
  22382. this.tokenRe = mode.tokenRe;
  22383. this.nonTokenRe = mode.nonTokenRe;
  22384. if (!$isPlaceholder) {
  22385. if (mode.attachToSession)
  22386. mode.attachToSession(this);
  22387. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  22388. this.$setFolding(mode.foldingRules);
  22389. this.bgTokenizer.start(0);
  22390. this._emit("changeMode");
  22391. }
  22392. };
  22393. this.$stopWorker = function() {
  22394. if (this.$worker) {
  22395. this.$worker.terminate();
  22396. this.$worker = null;
  22397. }
  22398. };
  22399. this.$startWorker = function() {
  22400. try {
  22401. this.$worker = this.$mode.createWorker(this);
  22402. } catch (e) {
  22403. config.warn("Could not load worker", e);
  22404. this.$worker = null;
  22405. }
  22406. };
  22407. this.getMode = function() {
  22408. return this.$mode;
  22409. };
  22410. this.$scrollTop = 0;
  22411. this.setScrollTop = function(scrollTop) {
  22412. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  22413. return;
  22414. this.$scrollTop = scrollTop;
  22415. this._signal("changeScrollTop", scrollTop);
  22416. };
  22417. this.getScrollTop = function() {
  22418. return this.$scrollTop;
  22419. };
  22420. this.$scrollLeft = 0;
  22421. this.setScrollLeft = function(scrollLeft) {
  22422. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  22423. return;
  22424. this.$scrollLeft = scrollLeft;
  22425. this._signal("changeScrollLeft", scrollLeft);
  22426. };
  22427. this.getScrollLeft = function() {
  22428. return this.$scrollLeft;
  22429. };
  22430. this.getScreenWidth = function() {
  22431. this.$computeWidth();
  22432. if (this.lineWidgets)
  22433. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  22434. return this.screenWidth;
  22435. };
  22436. this.getLineWidgetMaxWidth = function() {
  22437. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  22438. var width = 0;
  22439. this.lineWidgets.forEach(function(w) {
  22440. if (w && w.screenWidth > width)
  22441. width = w.screenWidth;
  22442. });
  22443. return this.lineWidgetWidth = width;
  22444. };
  22445. this.$computeWidth = function(force) {
  22446. if (this.$modified || force) {
  22447. this.$modified = false;
  22448. if (this.$useWrapMode)
  22449. return this.screenWidth = this.$wrapLimit;
  22450. var lines = this.doc.getAllLines();
  22451. var cache = this.$rowLengthCache;
  22452. var longestScreenLine = 0;
  22453. var foldIndex = 0;
  22454. var foldLine = this.$foldData[foldIndex];
  22455. var foldStart = foldLine ? foldLine.start.row : Infinity;
  22456. var len = lines.length;
  22457. for (var i = 0; i < len; i++) {
  22458. if (i > foldStart) {
  22459. i = foldLine.end.row + 1;
  22460. if (i >= len)
  22461. break;
  22462. foldLine = this.$foldData[foldIndex++];
  22463. foldStart = foldLine ? foldLine.start.row : Infinity;
  22464. }
  22465. if (cache[i] == null)
  22466. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  22467. if (cache[i] > longestScreenLine)
  22468. longestScreenLine = cache[i];
  22469. }
  22470. this.screenWidth = longestScreenLine;
  22471. }
  22472. };
  22473. this.getLine = function(row) {
  22474. return this.doc.getLine(row);
  22475. };
  22476. this.getLines = function(firstRow, lastRow) {
  22477. return this.doc.getLines(firstRow, lastRow);
  22478. };
  22479. this.getLength = function() {
  22480. return this.doc.getLength();
  22481. };
  22482. this.getTextRange = function(range) {
  22483. return this.doc.getTextRange(range || this.selection.getRange());
  22484. };
  22485. this.insert = function(position, text) {
  22486. return this.doc.insert(position, text);
  22487. };
  22488. this.remove = function(range) {
  22489. return this.doc.remove(range);
  22490. };
  22491. this.removeFullLines = function(firstRow, lastRow){
  22492. return this.doc.removeFullLines(firstRow, lastRow);
  22493. };
  22494. this.undoChanges = function(deltas, dontSelect) {
  22495. if (!deltas.length)
  22496. return;
  22497. this.$fromUndo = true;
  22498. var lastUndoRange = null;
  22499. for (var i = deltas.length - 1; i != -1; i--) {
  22500. var delta = deltas[i];
  22501. if (delta.group == "doc") {
  22502. this.doc.revertDeltas(delta.deltas);
  22503. lastUndoRange =
  22504. this.$getUndoSelection(delta.deltas, true, lastUndoRange);
  22505. } else {
  22506. delta.deltas.forEach(function(foldDelta) {
  22507. this.addFolds(foldDelta.folds);
  22508. }, this);
  22509. }
  22510. }
  22511. this.$fromUndo = false;
  22512. lastUndoRange &&
  22513. this.$undoSelect &&
  22514. !dontSelect &&
  22515. this.selection.setSelectionRange(lastUndoRange);
  22516. return lastUndoRange;
  22517. };
  22518. this.redoChanges = function(deltas, dontSelect) {
  22519. if (!deltas.length)
  22520. return;
  22521. this.$fromUndo = true;
  22522. var lastUndoRange = null;
  22523. for (var i = 0; i < deltas.length; i++) {
  22524. var delta = deltas[i];
  22525. if (delta.group == "doc") {
  22526. this.doc.applyDeltas(delta.deltas);
  22527. lastUndoRange =
  22528. this.$getUndoSelection(delta.deltas, false, lastUndoRange);
  22529. }
  22530. }
  22531. this.$fromUndo = false;
  22532. lastUndoRange &&
  22533. this.$undoSelect &&
  22534. !dontSelect &&
  22535. this.selection.setSelectionRange(lastUndoRange);
  22536. return lastUndoRange;
  22537. };
  22538. this.setUndoSelect = function(enable) {
  22539. this.$undoSelect = enable;
  22540. };
  22541. this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
  22542. function isInsert(delta) {
  22543. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  22544. }
  22545. var delta = deltas[0];
  22546. var range, point;
  22547. var lastDeltaIsInsert = false;
  22548. if (isInsert(delta)) {
  22549. range = Range.fromPoints(delta.start, delta.end);
  22550. lastDeltaIsInsert = true;
  22551. } else {
  22552. range = Range.fromPoints(delta.start, delta.start);
  22553. lastDeltaIsInsert = false;
  22554. }
  22555. for (var i = 1; i < deltas.length; i++) {
  22556. delta = deltas[i];
  22557. if (isInsert(delta)) {
  22558. point = delta.start;
  22559. if (range.compare(point.row, point.column) == -1) {
  22560. range.setStart(point);
  22561. }
  22562. point = delta.end;
  22563. if (range.compare(point.row, point.column) == 1) {
  22564. range.setEnd(point);
  22565. }
  22566. lastDeltaIsInsert = true;
  22567. } else {
  22568. point = delta.start;
  22569. if (range.compare(point.row, point.column) == -1) {
  22570. range = Range.fromPoints(delta.start, delta.start);
  22571. }
  22572. lastDeltaIsInsert = false;
  22573. }
  22574. }
  22575. if (lastUndoRange != null) {
  22576. if (Range.comparePoints(lastUndoRange.start, range.start) === 0) {
  22577. lastUndoRange.start.column += range.end.column - range.start.column;
  22578. lastUndoRange.end.column += range.end.column - range.start.column;
  22579. }
  22580. var cmp = lastUndoRange.compareRange(range);
  22581. if (cmp == 1) {
  22582. range.setStart(lastUndoRange.start);
  22583. } else if (cmp == -1) {
  22584. range.setEnd(lastUndoRange.end);
  22585. }
  22586. }
  22587. return range;
  22588. };
  22589. this.replace = function(range, text) {
  22590. return this.doc.replace(range, text);
  22591. };
  22592. this.moveText = function(fromRange, toPosition, copy) {
  22593. var text = this.getTextRange(fromRange);
  22594. var folds = this.getFoldsInRange(fromRange);
  22595. var toRange = Range.fromPoints(toPosition, toPosition);
  22596. if (!copy) {
  22597. this.remove(fromRange);
  22598. var rowDiff = fromRange.start.row - fromRange.end.row;
  22599. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  22600. if (collDiff) {
  22601. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  22602. toRange.start.column += collDiff;
  22603. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  22604. toRange.end.column += collDiff;
  22605. }
  22606. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  22607. toRange.start.row += rowDiff;
  22608. toRange.end.row += rowDiff;
  22609. }
  22610. }
  22611. toRange.end = this.insert(toRange.start, text);
  22612. if (folds.length) {
  22613. var oldStart = fromRange.start;
  22614. var newStart = toRange.start;
  22615. var rowDiff = newStart.row - oldStart.row;
  22616. var collDiff = newStart.column - oldStart.column;
  22617. this.addFolds(folds.map(function(x) {
  22618. x = x.clone();
  22619. if (x.start.row == oldStart.row)
  22620. x.start.column += collDiff;
  22621. if (x.end.row == oldStart.row)
  22622. x.end.column += collDiff;
  22623. x.start.row += rowDiff;
  22624. x.end.row += rowDiff;
  22625. return x;
  22626. }));
  22627. }
  22628. return toRange;
  22629. };
  22630. this.indentRows = function(startRow, endRow, indentString) {
  22631. indentString = indentString.replace(/\t/g, this.getTabString());
  22632. for (var row=startRow; row<=endRow; row++)
  22633. this.doc.insertInLine({row: row, column: 0}, indentString);
  22634. };
  22635. this.outdentRows = function (range) {
  22636. var rowRange = range.collapseRows();
  22637. var deleteRange = new Range(0, 0, 0, 0);
  22638. var size = this.getTabSize();
  22639. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  22640. var line = this.getLine(i);
  22641. deleteRange.start.row = i;
  22642. deleteRange.end.row = i;
  22643. for (var j = 0; j < size; ++j)
  22644. if (line.charAt(j) != ' ')
  22645. break;
  22646. if (j < size && line.charAt(j) == '\t') {
  22647. deleteRange.start.column = j;
  22648. deleteRange.end.column = j + 1;
  22649. } else {
  22650. deleteRange.start.column = 0;
  22651. deleteRange.end.column = j;
  22652. }
  22653. this.remove(deleteRange);
  22654. }
  22655. };
  22656. this.$moveLines = function(firstRow, lastRow, dir) {
  22657. firstRow = this.getRowFoldStart(firstRow);
  22658. lastRow = this.getRowFoldEnd(lastRow);
  22659. if (dir < 0) {
  22660. var row = this.getRowFoldStart(firstRow + dir);
  22661. if (row < 0) return 0;
  22662. var diff = row-firstRow;
  22663. } else if (dir > 0) {
  22664. var row = this.getRowFoldEnd(lastRow + dir);
  22665. if (row > this.doc.getLength()-1) return 0;
  22666. var diff = row-lastRow;
  22667. } else {
  22668. firstRow = this.$clipRowToDocument(firstRow);
  22669. lastRow = this.$clipRowToDocument(lastRow);
  22670. var diff = lastRow - firstRow + 1;
  22671. }
  22672. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  22673. var folds = this.getFoldsInRange(range).map(function(x){
  22674. x = x.clone();
  22675. x.start.row += diff;
  22676. x.end.row += diff;
  22677. return x;
  22678. });
  22679. var lines = dir == 0
  22680. ? this.doc.getLines(firstRow, lastRow)
  22681. : this.doc.removeFullLines(firstRow, lastRow);
  22682. this.doc.insertFullLines(firstRow+diff, lines);
  22683. folds.length && this.addFolds(folds);
  22684. return diff;
  22685. };
  22686. this.moveLinesUp = function(firstRow, lastRow) {
  22687. return this.$moveLines(firstRow, lastRow, -1);
  22688. };
  22689. this.moveLinesDown = function(firstRow, lastRow) {
  22690. return this.$moveLines(firstRow, lastRow, 1);
  22691. };
  22692. this.duplicateLines = function(firstRow, lastRow) {
  22693. return this.$moveLines(firstRow, lastRow, 0);
  22694. };
  22695. this.$clipRowToDocument = function(row) {
  22696. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  22697. };
  22698. this.$clipColumnToRow = function(row, column) {
  22699. if (column < 0)
  22700. return 0;
  22701. return Math.min(this.doc.getLine(row).length, column);
  22702. };
  22703. this.$clipPositionToDocument = function(row, column) {
  22704. column = Math.max(0, column);
  22705. if (row < 0) {
  22706. row = 0;
  22707. column = 0;
  22708. } else {
  22709. var len = this.doc.getLength();
  22710. if (row >= len) {
  22711. row = len - 1;
  22712. column = this.doc.getLine(len-1).length;
  22713. } else {
  22714. column = Math.min(this.doc.getLine(row).length, column);
  22715. }
  22716. }
  22717. return {
  22718. row: row,
  22719. column: column
  22720. };
  22721. };
  22722. this.$clipRangeToDocument = function(range) {
  22723. if (range.start.row < 0) {
  22724. range.start.row = 0;
  22725. range.start.column = 0;
  22726. } else {
  22727. range.start.column = this.$clipColumnToRow(
  22728. range.start.row,
  22729. range.start.column
  22730. );
  22731. }
  22732. var len = this.doc.getLength() - 1;
  22733. if (range.end.row > len) {
  22734. range.end.row = len;
  22735. range.end.column = this.doc.getLine(len).length;
  22736. } else {
  22737. range.end.column = this.$clipColumnToRow(
  22738. range.end.row,
  22739. range.end.column
  22740. );
  22741. }
  22742. return range;
  22743. };
  22744. this.$wrapLimit = 80;
  22745. this.$useWrapMode = false;
  22746. this.$wrapLimitRange = {
  22747. min : null,
  22748. max : null
  22749. };
  22750. this.setUseWrapMode = function(useWrapMode) {
  22751. if (useWrapMode != this.$useWrapMode) {
  22752. this.$useWrapMode = useWrapMode;
  22753. this.$modified = true;
  22754. this.$resetRowCache(0);
  22755. if (useWrapMode) {
  22756. var len = this.getLength();
  22757. this.$wrapData = Array(len);
  22758. this.$updateWrapData(0, len - 1);
  22759. }
  22760. this._signal("changeWrapMode");
  22761. }
  22762. };
  22763. this.getUseWrapMode = function() {
  22764. return this.$useWrapMode;
  22765. };
  22766. this.setWrapLimitRange = function(min, max) {
  22767. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  22768. this.$wrapLimitRange = { min: min, max: max };
  22769. this.$modified = true;
  22770. if (this.$useWrapMode)
  22771. this._signal("changeWrapMode");
  22772. }
  22773. };
  22774. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  22775. var limits = this.$wrapLimitRange;
  22776. if (limits.max < 0)
  22777. limits = {min: $printMargin, max: $printMargin};
  22778. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  22779. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  22780. this.$wrapLimit = wrapLimit;
  22781. this.$modified = true;
  22782. if (this.$useWrapMode) {
  22783. this.$updateWrapData(0, this.getLength() - 1);
  22784. this.$resetRowCache(0);
  22785. this._signal("changeWrapLimit");
  22786. }
  22787. return true;
  22788. }
  22789. return false;
  22790. };
  22791. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  22792. if (min)
  22793. wrapLimit = Math.max(min, wrapLimit);
  22794. if (max)
  22795. wrapLimit = Math.min(max, wrapLimit);
  22796. return wrapLimit;
  22797. };
  22798. this.getWrapLimit = function() {
  22799. return this.$wrapLimit;
  22800. };
  22801. this.setWrapLimit = function (limit) {
  22802. this.setWrapLimitRange(limit, limit);
  22803. };
  22804. this.getWrapLimitRange = function() {
  22805. return {
  22806. min : this.$wrapLimitRange.min,
  22807. max : this.$wrapLimitRange.max
  22808. };
  22809. };
  22810. this.$updateInternalDataOnChange = function(delta) {
  22811. var useWrapMode = this.$useWrapMode;
  22812. var action = delta.action;
  22813. var start = delta.start;
  22814. var end = delta.end;
  22815. var firstRow = start.row;
  22816. var lastRow = end.row;
  22817. var len = lastRow - firstRow;
  22818. var removedFolds = null;
  22819. this.$updating = true;
  22820. if (len != 0) {
  22821. if (action === "remove") {
  22822. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  22823. var foldLines = this.$foldData;
  22824. removedFolds = this.getFoldsInRange(delta);
  22825. this.removeFolds(removedFolds);
  22826. var foldLine = this.getFoldLine(end.row);
  22827. var idx = 0;
  22828. if (foldLine) {
  22829. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  22830. foldLine.shiftRow(-len);
  22831. var foldLineBefore = this.getFoldLine(firstRow);
  22832. if (foldLineBefore && foldLineBefore !== foldLine) {
  22833. foldLineBefore.merge(foldLine);
  22834. foldLine = foldLineBefore;
  22835. }
  22836. idx = foldLines.indexOf(foldLine) + 1;
  22837. }
  22838. for (idx; idx < foldLines.length; idx++) {
  22839. var foldLine = foldLines[idx];
  22840. if (foldLine.start.row >= end.row) {
  22841. foldLine.shiftRow(-len);
  22842. }
  22843. }
  22844. lastRow = firstRow;
  22845. } else {
  22846. var args = Array(len);
  22847. args.unshift(firstRow, 0);
  22848. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
  22849. arr.splice.apply(arr, args);
  22850. var foldLines = this.$foldData;
  22851. var foldLine = this.getFoldLine(firstRow);
  22852. var idx = 0;
  22853. if (foldLine) {
  22854. var cmp = foldLine.range.compareInside(start.row, start.column);
  22855. if (cmp == 0) {
  22856. foldLine = foldLine.split(start.row, start.column);
  22857. if (foldLine) {
  22858. foldLine.shiftRow(len);
  22859. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  22860. }
  22861. } else
  22862. if (cmp == -1) {
  22863. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  22864. foldLine.shiftRow(len);
  22865. }
  22866. idx = foldLines.indexOf(foldLine) + 1;
  22867. }
  22868. for (idx; idx < foldLines.length; idx++) {
  22869. var foldLine = foldLines[idx];
  22870. if (foldLine.start.row >= firstRow) {
  22871. foldLine.shiftRow(len);
  22872. }
  22873. }
  22874. }
  22875. } else {
  22876. len = Math.abs(delta.start.column - delta.end.column);
  22877. if (action === "remove") {
  22878. removedFolds = this.getFoldsInRange(delta);
  22879. this.removeFolds(removedFolds);
  22880. len = -len;
  22881. }
  22882. var foldLine = this.getFoldLine(firstRow);
  22883. if (foldLine) {
  22884. foldLine.addRemoveChars(firstRow, start.column, len);
  22885. }
  22886. }
  22887. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  22888. console.error("doc.getLength() and $wrapData.length have to be the same!");
  22889. }
  22890. this.$updating = false;
  22891. if (useWrapMode)
  22892. this.$updateWrapData(firstRow, lastRow);
  22893. else
  22894. this.$updateRowLengthCache(firstRow, lastRow);
  22895. return removedFolds;
  22896. };
  22897. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  22898. this.$rowLengthCache[firstRow] = null;
  22899. this.$rowLengthCache[lastRow] = null;
  22900. };
  22901. this.$updateWrapData = function(firstRow, lastRow) {
  22902. var lines = this.doc.getAllLines();
  22903. var tabSize = this.getTabSize();
  22904. var wrapData = this.$wrapData;
  22905. var wrapLimit = this.$wrapLimit;
  22906. var tokens;
  22907. var foldLine;
  22908. var row = firstRow;
  22909. lastRow = Math.min(lastRow, lines.length - 1);
  22910. while (row <= lastRow) {
  22911. foldLine = this.getFoldLine(row, foldLine);
  22912. if (!foldLine) {
  22913. tokens = this.$getDisplayTokens(lines[row]);
  22914. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  22915. row ++;
  22916. } else {
  22917. tokens = [];
  22918. foldLine.walk(function(placeholder, row, column, lastColumn) {
  22919. var walkTokens;
  22920. if (placeholder != null) {
  22921. walkTokens = this.$getDisplayTokens(
  22922. placeholder, tokens.length);
  22923. walkTokens[0] = PLACEHOLDER_START;
  22924. for (var i = 1; i < walkTokens.length; i++) {
  22925. walkTokens[i] = PLACEHOLDER_BODY;
  22926. }
  22927. } else {
  22928. walkTokens = this.$getDisplayTokens(
  22929. lines[row].substring(lastColumn, column),
  22930. tokens.length);
  22931. }
  22932. tokens = tokens.concat(walkTokens);
  22933. }.bind(this),
  22934. foldLine.end.row,
  22935. lines[foldLine.end.row].length + 1
  22936. );
  22937. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  22938. row = foldLine.end.row + 1;
  22939. }
  22940. }
  22941. };
  22942. var CHAR = 1,
  22943. CHAR_EXT = 2,
  22944. PLACEHOLDER_START = 3,
  22945. PLACEHOLDER_BODY = 4,
  22946. PUNCTUATION = 9,
  22947. SPACE = 10,
  22948. TAB = 11,
  22949. TAB_SPACE = 12;
  22950. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  22951. if (tokens.length == 0) {
  22952. return [];
  22953. }
  22954. var splits = [];
  22955. var displayLength = tokens.length;
  22956. var lastSplit = 0, lastDocSplit = 0;
  22957. var isCode = this.$wrapAsCode;
  22958. var indentedSoftWrap = this.$indentedSoftWrap;
  22959. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  22960. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  22961. function getWrapIndent() {
  22962. var indentation = 0;
  22963. if (maxIndent === 0)
  22964. return indentation;
  22965. if (indentedSoftWrap) {
  22966. for (var i = 0; i < tokens.length; i++) {
  22967. var token = tokens[i];
  22968. if (token == SPACE)
  22969. indentation += 1;
  22970. else if (token == TAB)
  22971. indentation += tabSize;
  22972. else if (token == TAB_SPACE)
  22973. continue;
  22974. else
  22975. break;
  22976. }
  22977. }
  22978. if (isCode && indentedSoftWrap !== false)
  22979. indentation += tabSize;
  22980. return Math.min(indentation, maxIndent);
  22981. }
  22982. function addSplit(screenPos) {
  22983. var displayed = tokens.slice(lastSplit, screenPos);
  22984. var len = displayed.length;
  22985. displayed.join("")
  22986. .replace(/12/g, function() {
  22987. len -= 1;
  22988. })
  22989. .replace(/2/g, function() {
  22990. len -= 1;
  22991. });
  22992. if (!splits.length) {
  22993. indent = getWrapIndent();
  22994. splits.indent = indent;
  22995. }
  22996. lastDocSplit += len;
  22997. splits.push(lastDocSplit);
  22998. lastSplit = screenPos;
  22999. }
  23000. var indent = 0;
  23001. while (displayLength - lastSplit > wrapLimit - indent) {
  23002. var split = lastSplit + wrapLimit - indent;
  23003. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  23004. addSplit(split);
  23005. continue;
  23006. }
  23007. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  23008. for (split; split != lastSplit - 1; split--) {
  23009. if (tokens[split] == PLACEHOLDER_START) {
  23010. break;
  23011. }
  23012. }
  23013. if (split > lastSplit) {
  23014. addSplit(split);
  23015. continue;
  23016. }
  23017. split = lastSplit + wrapLimit;
  23018. for (split; split < tokens.length; split++) {
  23019. if (tokens[split] != PLACEHOLDER_BODY) {
  23020. break;
  23021. }
  23022. }
  23023. if (split == tokens.length) {
  23024. break; // Breaks the while-loop.
  23025. }
  23026. addSplit(split);
  23027. continue;
  23028. }
  23029. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  23030. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  23031. split --;
  23032. }
  23033. if (isCode) {
  23034. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  23035. split --;
  23036. }
  23037. while (split > minSplit && tokens[split] == PUNCTUATION) {
  23038. split --;
  23039. }
  23040. } else {
  23041. while (split > minSplit && tokens[split] < SPACE) {
  23042. split --;
  23043. }
  23044. }
  23045. if (split > minSplit) {
  23046. addSplit(++split);
  23047. continue;
  23048. }
  23049. split = lastSplit + wrapLimit;
  23050. if (tokens[split] == CHAR_EXT)
  23051. split--;
  23052. addSplit(split - indent);
  23053. }
  23054. return splits;
  23055. };
  23056. this.$getDisplayTokens = function(str, offset) {
  23057. var arr = [];
  23058. var tabSize;
  23059. offset = offset || 0;
  23060. for (var i = 0; i < str.length; i++) {
  23061. var c = str.charCodeAt(i);
  23062. if (c == 9) {
  23063. tabSize = this.getScreenTabSize(arr.length + offset);
  23064. arr.push(TAB);
  23065. for (var n = 1; n < tabSize; n++) {
  23066. arr.push(TAB_SPACE);
  23067. }
  23068. }
  23069. else if (c == 32) {
  23070. arr.push(SPACE);
  23071. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  23072. arr.push(PUNCTUATION);
  23073. }
  23074. else if (c >= 0x1100 && isFullWidth(c)) {
  23075. arr.push(CHAR, CHAR_EXT);
  23076. } else {
  23077. arr.push(CHAR);
  23078. }
  23079. }
  23080. return arr;
  23081. };
  23082. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  23083. if (maxScreenColumn == 0)
  23084. return [0, 0];
  23085. if (maxScreenColumn == null)
  23086. maxScreenColumn = Infinity;
  23087. screenColumn = screenColumn || 0;
  23088. var c, column;
  23089. for (column = 0; column < str.length; column++) {
  23090. c = str.charCodeAt(column);
  23091. if (c == 9) {
  23092. screenColumn += this.getScreenTabSize(screenColumn);
  23093. }
  23094. else if (c >= 0x1100 && isFullWidth(c)) {
  23095. screenColumn += 2;
  23096. } else {
  23097. screenColumn += 1;
  23098. }
  23099. if (screenColumn > maxScreenColumn) {
  23100. break;
  23101. }
  23102. }
  23103. return [screenColumn, column];
  23104. };
  23105. this.lineWidgets = null;
  23106. this.getRowLength = function(row) {
  23107. if (this.lineWidgets)
  23108. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  23109. else
  23110. h = 0
  23111. if (!this.$useWrapMode || !this.$wrapData[row]) {
  23112. return 1 + h;
  23113. } else {
  23114. return this.$wrapData[row].length + 1 + h;
  23115. }
  23116. };
  23117. this.getRowLineCount = function(row) {
  23118. if (!this.$useWrapMode || !this.$wrapData[row]) {
  23119. return 1;
  23120. } else {
  23121. return this.$wrapData[row].length + 1;
  23122. }
  23123. };
  23124. this.getRowWrapIndent = function(screenRow) {
  23125. if (this.$useWrapMode) {
  23126. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  23127. var splits = this.$wrapData[pos.row];
  23128. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  23129. } else {
  23130. return 0;
  23131. }
  23132. }
  23133. this.getScreenLastRowColumn = function(screenRow) {
  23134. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  23135. return this.documentToScreenColumn(pos.row, pos.column);
  23136. };
  23137. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  23138. var screenRow = this.documentToScreenRow(docRow, docColumn);
  23139. return this.getScreenLastRowColumn(screenRow);
  23140. };
  23141. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  23142. var screenRow = this.documentToScreenRow(docRow, docColumn);
  23143. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  23144. };
  23145. this.getRowSplitData = function(row) {
  23146. if (!this.$useWrapMode) {
  23147. return undefined;
  23148. } else {
  23149. return this.$wrapData[row];
  23150. }
  23151. };
  23152. this.getScreenTabSize = function(screenColumn) {
  23153. return this.$tabSize - screenColumn % this.$tabSize;
  23154. };
  23155. this.screenToDocumentRow = function(screenRow, screenColumn) {
  23156. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  23157. };
  23158. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  23159. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  23160. };
  23161. this.screenToDocumentPosition = function(screenRow, screenColumn) {
  23162. if (screenRow < 0)
  23163. return {row: 0, column: 0};
  23164. var line;
  23165. var docRow = 0;
  23166. var docColumn = 0;
  23167. var column;
  23168. var row = 0;
  23169. var rowLength = 0;
  23170. var rowCache = this.$screenRowCache;
  23171. var i = this.$getRowCacheIndex(rowCache, screenRow);
  23172. var l = rowCache.length;
  23173. if (l && i >= 0) {
  23174. var row = rowCache[i];
  23175. var docRow = this.$docRowCache[i];
  23176. var doCache = screenRow > rowCache[l - 1];
  23177. } else {
  23178. var doCache = !l;
  23179. }
  23180. var maxRow = this.getLength() - 1;
  23181. var foldLine = this.getNextFoldLine(docRow);
  23182. var foldStart = foldLine ? foldLine.start.row : Infinity;
  23183. while (row <= screenRow) {
  23184. rowLength = this.getRowLength(docRow);
  23185. if (row + rowLength > screenRow || docRow >= maxRow) {
  23186. break;
  23187. } else {
  23188. row += rowLength;
  23189. docRow++;
  23190. if (docRow > foldStart) {
  23191. docRow = foldLine.end.row+1;
  23192. foldLine = this.getNextFoldLine(docRow, foldLine);
  23193. foldStart = foldLine ? foldLine.start.row : Infinity;
  23194. }
  23195. }
  23196. if (doCache) {
  23197. this.$docRowCache.push(docRow);
  23198. this.$screenRowCache.push(row);
  23199. }
  23200. }
  23201. if (foldLine && foldLine.start.row <= docRow) {
  23202. line = this.getFoldDisplayLine(foldLine);
  23203. docRow = foldLine.start.row;
  23204. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  23205. return {
  23206. row: maxRow,
  23207. column: this.getLine(maxRow).length
  23208. };
  23209. } else {
  23210. line = this.getLine(docRow);
  23211. foldLine = null;
  23212. }
  23213. var wrapIndent = 0;
  23214. if (this.$useWrapMode) {
  23215. var splits = this.$wrapData[docRow];
  23216. if (splits) {
  23217. var splitIndex = Math.floor(screenRow - row);
  23218. column = splits[splitIndex];
  23219. if(splitIndex > 0 && splits.length) {
  23220. wrapIndent = splits.indent;
  23221. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  23222. line = line.substring(docColumn);
  23223. }
  23224. }
  23225. }
  23226. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  23227. if (this.$useWrapMode && docColumn >= column)
  23228. docColumn = column - 1;
  23229. if (foldLine)
  23230. return foldLine.idxToPosition(docColumn);
  23231. return {row: docRow, column: docColumn};
  23232. };
  23233. this.documentToScreenPosition = function(docRow, docColumn) {
  23234. if (typeof docColumn === "undefined")
  23235. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  23236. else
  23237. pos = this.$clipPositionToDocument(docRow, docColumn);
  23238. docRow = pos.row;
  23239. docColumn = pos.column;
  23240. var screenRow = 0;
  23241. var foldStartRow = null;
  23242. var fold = null;
  23243. fold = this.getFoldAt(docRow, docColumn, 1);
  23244. if (fold) {
  23245. docRow = fold.start.row;
  23246. docColumn = fold.start.column;
  23247. }
  23248. var rowEnd, row = 0;
  23249. var rowCache = this.$docRowCache;
  23250. var i = this.$getRowCacheIndex(rowCache, docRow);
  23251. var l = rowCache.length;
  23252. if (l && i >= 0) {
  23253. var row = rowCache[i];
  23254. var screenRow = this.$screenRowCache[i];
  23255. var doCache = docRow > rowCache[l - 1];
  23256. } else {
  23257. var doCache = !l;
  23258. }
  23259. var foldLine = this.getNextFoldLine(row);
  23260. var foldStart = foldLine ?foldLine.start.row :Infinity;
  23261. while (row < docRow) {
  23262. if (row >= foldStart) {
  23263. rowEnd = foldLine.end.row + 1;
  23264. if (rowEnd > docRow)
  23265. break;
  23266. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  23267. foldStart = foldLine ?foldLine.start.row :Infinity;
  23268. }
  23269. else {
  23270. rowEnd = row + 1;
  23271. }
  23272. screenRow += this.getRowLength(row);
  23273. row = rowEnd;
  23274. if (doCache) {
  23275. this.$docRowCache.push(row);
  23276. this.$screenRowCache.push(screenRow);
  23277. }
  23278. }
  23279. var textLine = "";
  23280. if (foldLine && row >= foldStart) {
  23281. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  23282. foldStartRow = foldLine.start.row;
  23283. } else {
  23284. textLine = this.getLine(docRow).substring(0, docColumn);
  23285. foldStartRow = docRow;
  23286. }
  23287. var wrapIndent = 0;
  23288. if (this.$useWrapMode) {
  23289. var wrapRow = this.$wrapData[foldStartRow];
  23290. if (wrapRow) {
  23291. var screenRowOffset = 0;
  23292. while (textLine.length >= wrapRow[screenRowOffset]) {
  23293. screenRow ++;
  23294. screenRowOffset++;
  23295. }
  23296. textLine = textLine.substring(
  23297. wrapRow[screenRowOffset - 1] || 0, textLine.length
  23298. );
  23299. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  23300. }
  23301. }
  23302. return {
  23303. row: screenRow,
  23304. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  23305. };
  23306. };
  23307. this.documentToScreenColumn = function(row, docColumn) {
  23308. return this.documentToScreenPosition(row, docColumn).column;
  23309. };
  23310. this.documentToScreenRow = function(docRow, docColumn) {
  23311. return this.documentToScreenPosition(docRow, docColumn).row;
  23312. };
  23313. this.getScreenLength = function() {
  23314. var screenRows = 0;
  23315. var fold = null;
  23316. if (!this.$useWrapMode) {
  23317. screenRows = this.getLength();
  23318. var foldData = this.$foldData;
  23319. for (var i = 0; i < foldData.length; i++) {
  23320. fold = foldData[i];
  23321. screenRows -= fold.end.row - fold.start.row;
  23322. }
  23323. } else {
  23324. var lastRow = this.$wrapData.length;
  23325. var row = 0, i = 0;
  23326. var fold = this.$foldData[i++];
  23327. var foldStart = fold ? fold.start.row :Infinity;
  23328. while (row < lastRow) {
  23329. var splits = this.$wrapData[row];
  23330. screenRows += splits ? splits.length + 1 : 1;
  23331. row ++;
  23332. if (row > foldStart) {
  23333. row = fold.end.row+1;
  23334. fold = this.$foldData[i++];
  23335. foldStart = fold ?fold.start.row :Infinity;
  23336. }
  23337. }
  23338. }
  23339. if (this.lineWidgets)
  23340. screenRows += this.$getWidgetScreenLength();
  23341. return screenRows;
  23342. };
  23343. this.$setFontMetrics = function(fm) {
  23344. if (!this.$enableVarChar) return;
  23345. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  23346. if (maxScreenColumn === 0)
  23347. return [0, 0];
  23348. if (!maxScreenColumn)
  23349. maxScreenColumn = Infinity;
  23350. screenColumn = screenColumn || 0;
  23351. var c, column;
  23352. for (column = 0; column < str.length; column++) {
  23353. c = str.charAt(column);
  23354. if (c === "\t") {
  23355. screenColumn += this.getScreenTabSize(screenColumn);
  23356. } else {
  23357. screenColumn += fm.getCharacterWidth(c);
  23358. }
  23359. if (screenColumn > maxScreenColumn) {
  23360. break;
  23361. }
  23362. }
  23363. return [screenColumn, column];
  23364. };
  23365. };
  23366. this.destroy = function() {
  23367. if (this.bgTokenizer) {
  23368. this.bgTokenizer.setDocument(null);
  23369. this.bgTokenizer = null;
  23370. }
  23371. this.$stopWorker();
  23372. };
  23373. function isFullWidth(c) {
  23374. if (c < 0x1100)
  23375. return false;
  23376. return c >= 0x1100 && c <= 0x115F ||
  23377. c >= 0x11A3 && c <= 0x11A7 ||
  23378. c >= 0x11FA && c <= 0x11FF ||
  23379. c >= 0x2329 && c <= 0x232A ||
  23380. c >= 0x2E80 && c <= 0x2E99 ||
  23381. c >= 0x2E9B && c <= 0x2EF3 ||
  23382. c >= 0x2F00 && c <= 0x2FD5 ||
  23383. c >= 0x2FF0 && c <= 0x2FFB ||
  23384. c >= 0x3000 && c <= 0x303E ||
  23385. c >= 0x3041 && c <= 0x3096 ||
  23386. c >= 0x3099 && c <= 0x30FF ||
  23387. c >= 0x3105 && c <= 0x312D ||
  23388. c >= 0x3131 && c <= 0x318E ||
  23389. c >= 0x3190 && c <= 0x31BA ||
  23390. c >= 0x31C0 && c <= 0x31E3 ||
  23391. c >= 0x31F0 && c <= 0x321E ||
  23392. c >= 0x3220 && c <= 0x3247 ||
  23393. c >= 0x3250 && c <= 0x32FE ||
  23394. c >= 0x3300 && c <= 0x4DBF ||
  23395. c >= 0x4E00 && c <= 0xA48C ||
  23396. c >= 0xA490 && c <= 0xA4C6 ||
  23397. c >= 0xA960 && c <= 0xA97C ||
  23398. c >= 0xAC00 && c <= 0xD7A3 ||
  23399. c >= 0xD7B0 && c <= 0xD7C6 ||
  23400. c >= 0xD7CB && c <= 0xD7FB ||
  23401. c >= 0xF900 && c <= 0xFAFF ||
  23402. c >= 0xFE10 && c <= 0xFE19 ||
  23403. c >= 0xFE30 && c <= 0xFE52 ||
  23404. c >= 0xFE54 && c <= 0xFE66 ||
  23405. c >= 0xFE68 && c <= 0xFE6B ||
  23406. c >= 0xFF01 && c <= 0xFF60 ||
  23407. c >= 0xFFE0 && c <= 0xFFE6;
  23408. }
  23409. }).call(EditSession.prototype);
  23410. acequire("./edit_session/folding").Folding.call(EditSession.prototype);
  23411. acequire("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  23412. config.defineOptions(EditSession.prototype, "session", {
  23413. wrap: {
  23414. set: function(value) {
  23415. if (!value || value == "off")
  23416. value = false;
  23417. else if (value == "free")
  23418. value = true;
  23419. else if (value == "printMargin")
  23420. value = -1;
  23421. else if (typeof value == "string")
  23422. value = parseInt(value, 10) || false;
  23423. if (this.$wrap == value)
  23424. return;
  23425. this.$wrap = value;
  23426. if (!value) {
  23427. this.setUseWrapMode(false);
  23428. } else {
  23429. var col = typeof value == "number" ? value : null;
  23430. this.setWrapLimitRange(col, col);
  23431. this.setUseWrapMode(true);
  23432. }
  23433. },
  23434. get: function() {
  23435. if (this.getUseWrapMode()) {
  23436. if (this.$wrap == -1)
  23437. return "printMargin";
  23438. if (!this.getWrapLimitRange().min)
  23439. return "free";
  23440. return this.$wrap;
  23441. }
  23442. return "off";
  23443. },
  23444. handlesSet: true
  23445. },
  23446. wrapMethod: {
  23447. set: function(val) {
  23448. val = val == "auto"
  23449. ? this.$mode.type != "text"
  23450. : val != "text";
  23451. if (val != this.$wrapAsCode) {
  23452. this.$wrapAsCode = val;
  23453. if (this.$useWrapMode) {
  23454. this.$modified = true;
  23455. this.$resetRowCache(0);
  23456. this.$updateWrapData(0, this.getLength() - 1);
  23457. }
  23458. }
  23459. },
  23460. initialValue: "auto"
  23461. },
  23462. indentedSoftWrap: { initialValue: true },
  23463. firstLineNumber: {
  23464. set: function() {this._signal("changeBreakpoint");},
  23465. initialValue: 1
  23466. },
  23467. useWorker: {
  23468. set: function(useWorker) {
  23469. this.$useWorker = useWorker;
  23470. this.$stopWorker();
  23471. if (useWorker)
  23472. this.$startWorker();
  23473. },
  23474. initialValue: true
  23475. },
  23476. useSoftTabs: {initialValue: true},
  23477. tabSize: {
  23478. set: function(tabSize) {
  23479. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  23480. this.$modified = true;
  23481. this.$rowLengthCache = [];
  23482. this.$tabSize = tabSize;
  23483. this._signal("changeTabSize");
  23484. },
  23485. initialValue: 4,
  23486. handlesSet: true
  23487. },
  23488. overwrite: {
  23489. set: function(val) {this._signal("changeOverwrite");},
  23490. initialValue: false
  23491. },
  23492. newLineMode: {
  23493. set: function(val) {this.doc.setNewLineMode(val)},
  23494. get: function() {return this.doc.getNewLineMode()},
  23495. handlesSet: true
  23496. },
  23497. mode: {
  23498. set: function(val) { this.setMode(val) },
  23499. get: function() { return this.$modeId }
  23500. }
  23501. });
  23502. exports.EditSession = EditSession;
  23503. });
  23504. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(acequire, exports, module) {
  23505. "use strict";
  23506. var lang = acequire("./lib/lang");
  23507. var oop = acequire("./lib/oop");
  23508. var Range = acequire("./range").Range;
  23509. var Search = function() {
  23510. this.$options = {};
  23511. };
  23512. (function() {
  23513. this.set = function(options) {
  23514. oop.mixin(this.$options, options);
  23515. return this;
  23516. };
  23517. this.getOptions = function() {
  23518. return lang.copyObject(this.$options);
  23519. };
  23520. this.setOptions = function(options) {
  23521. this.$options = options;
  23522. };
  23523. this.find = function(session) {
  23524. var options = this.$options;
  23525. var iterator = this.$matchIterator(session, options);
  23526. if (!iterator)
  23527. return false;
  23528. var firstRange = null;
  23529. iterator.forEach(function(range, row, offset) {
  23530. if (!range.start) {
  23531. var column = range.offset + (offset || 0);
  23532. firstRange = new Range(row, column, row, column + range.length);
  23533. if (!range.length && options.start && options.start.start
  23534. && options.skipCurrent != false && firstRange.isEqual(options.start)
  23535. ) {
  23536. firstRange = null;
  23537. return false;
  23538. }
  23539. } else
  23540. firstRange = range;
  23541. return true;
  23542. });
  23543. return firstRange;
  23544. };
  23545. this.findAll = function(session) {
  23546. var options = this.$options;
  23547. if (!options.needle)
  23548. return [];
  23549. this.$assembleRegExp(options);
  23550. var range = options.range;
  23551. var lines = range
  23552. ? session.getLines(range.start.row, range.end.row)
  23553. : session.doc.getAllLines();
  23554. var ranges = [];
  23555. var re = options.re;
  23556. if (options.$isMultiLine) {
  23557. var len = re.length;
  23558. var maxRow = lines.length - len;
  23559. var prevRange;
  23560. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  23561. for (var j = 0; j < len; j++)
  23562. if (lines[row + j].search(re[j]) == -1)
  23563. continue outer;
  23564. var startLine = lines[row];
  23565. var line = lines[row + len - 1];
  23566. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  23567. var endIndex = line.match(re[len - 1])[0].length;
  23568. if (prevRange && prevRange.end.row === row &&
  23569. prevRange.end.column > startIndex
  23570. ) {
  23571. continue;
  23572. }
  23573. ranges.push(prevRange = new Range(
  23574. row, startIndex, row + len - 1, endIndex
  23575. ));
  23576. if (len > 2)
  23577. row = row + len - 2;
  23578. }
  23579. } else {
  23580. for (var i = 0; i < lines.length; i++) {
  23581. var matches = lang.getMatchOffsets(lines[i], re);
  23582. for (var j = 0; j < matches.length; j++) {
  23583. var match = matches[j];
  23584. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  23585. }
  23586. }
  23587. }
  23588. if (range) {
  23589. var startColumn = range.start.column;
  23590. var endColumn = range.start.column;
  23591. var i = 0, j = ranges.length - 1;
  23592. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  23593. i++;
  23594. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  23595. j--;
  23596. ranges = ranges.slice(i, j + 1);
  23597. for (i = 0, j = ranges.length; i < j; i++) {
  23598. ranges[i].start.row += range.start.row;
  23599. ranges[i].end.row += range.start.row;
  23600. }
  23601. }
  23602. return ranges;
  23603. };
  23604. this.replace = function(input, replacement) {
  23605. var options = this.$options;
  23606. var re = this.$assembleRegExp(options);
  23607. if (options.$isMultiLine)
  23608. return replacement;
  23609. if (!re)
  23610. return;
  23611. var match = re.exec(input);
  23612. if (!match || match[0].length != input.length)
  23613. return null;
  23614. replacement = input.replace(re, replacement);
  23615. if (options.preserveCase) {
  23616. replacement = replacement.split("");
  23617. for (var i = Math.min(input.length, input.length); i--; ) {
  23618. var ch = input[i];
  23619. if (ch && ch.toLowerCase() != ch)
  23620. replacement[i] = replacement[i].toUpperCase();
  23621. else
  23622. replacement[i] = replacement[i].toLowerCase();
  23623. }
  23624. replacement = replacement.join("");
  23625. }
  23626. return replacement;
  23627. };
  23628. this.$matchIterator = function(session, options) {
  23629. var re = this.$assembleRegExp(options);
  23630. if (!re)
  23631. return false;
  23632. var callback;
  23633. if (options.$isMultiLine) {
  23634. var len = re.length;
  23635. var matchIterator = function(line, row, offset) {
  23636. var startIndex = line.search(re[0]);
  23637. if (startIndex == -1)
  23638. return;
  23639. for (var i = 1; i < len; i++) {
  23640. line = session.getLine(row + i);
  23641. if (line.search(re[i]) == -1)
  23642. return;
  23643. }
  23644. var endIndex = line.match(re[len - 1])[0].length;
  23645. var range = new Range(row, startIndex, row + len - 1, endIndex);
  23646. if (re.offset == 1) {
  23647. range.start.row--;
  23648. range.start.column = Number.MAX_VALUE;
  23649. } else if (offset)
  23650. range.start.column += offset;
  23651. if (callback(range))
  23652. return true;
  23653. };
  23654. } else if (options.backwards) {
  23655. var matchIterator = function(line, row, startIndex) {
  23656. var matches = lang.getMatchOffsets(line, re);
  23657. for (var i = matches.length-1; i >= 0; i--)
  23658. if (callback(matches[i], row, startIndex))
  23659. return true;
  23660. };
  23661. } else {
  23662. var matchIterator = function(line, row, startIndex) {
  23663. var matches = lang.getMatchOffsets(line, re);
  23664. for (var i = 0; i < matches.length; i++)
  23665. if (callback(matches[i], row, startIndex))
  23666. return true;
  23667. };
  23668. }
  23669. var lineIterator = this.$lineIterator(session, options);
  23670. return {
  23671. forEach: function(_callback) {
  23672. callback = _callback;
  23673. lineIterator.forEach(matchIterator);
  23674. }
  23675. };
  23676. };
  23677. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  23678. if (options.needle instanceof RegExp)
  23679. return options.re = options.needle;
  23680. var needle = options.needle;
  23681. if (!options.needle)
  23682. return options.re = false;
  23683. if (!options.regExp)
  23684. needle = lang.escapeRegExp(needle);
  23685. if (options.wholeWord)
  23686. needle = "\\b" + needle + "\\b";
  23687. var modifier = options.caseSensitive ? "gm" : "gmi";
  23688. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  23689. if (options.$isMultiLine)
  23690. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  23691. try {
  23692. var re = new RegExp(needle, modifier);
  23693. } catch(e) {
  23694. re = false;
  23695. }
  23696. return options.re = re;
  23697. };
  23698. this.$assembleMultilineRegExp = function(needle, modifier) {
  23699. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  23700. var re = [];
  23701. for (var i = 0; i < parts.length; i++) try {
  23702. re.push(new RegExp(parts[i], modifier));
  23703. } catch(e) {
  23704. return false;
  23705. }
  23706. if (parts[0] == "") {
  23707. re.shift();
  23708. re.offset = 1;
  23709. } else {
  23710. re.offset = 0;
  23711. }
  23712. return re;
  23713. };
  23714. this.$lineIterator = function(session, options) {
  23715. var backwards = options.backwards == true;
  23716. var skipCurrent = options.skipCurrent != false;
  23717. var range = options.range;
  23718. var start = options.start;
  23719. if (!start)
  23720. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  23721. if (start.start)
  23722. start = start[skipCurrent != backwards ? "end" : "start"];
  23723. var firstRow = range ? range.start.row : 0;
  23724. var lastRow = range ? range.end.row : session.getLength() - 1;
  23725. var forEach = backwards ? function(callback) {
  23726. var row = start.row;
  23727. var line = session.getLine(row).substring(0, start.column);
  23728. if (callback(line, row))
  23729. return;
  23730. for (row--; row >= firstRow; row--)
  23731. if (callback(session.getLine(row), row))
  23732. return;
  23733. if (options.wrap == false)
  23734. return;
  23735. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  23736. if (callback(session.getLine(row), row))
  23737. return;
  23738. } : function(callback) {
  23739. var row = start.row;
  23740. var line = session.getLine(row).substr(start.column);
  23741. if (callback(line, row, start.column))
  23742. return;
  23743. for (row = row+1; row <= lastRow; row++)
  23744. if (callback(session.getLine(row), row))
  23745. return;
  23746. if (options.wrap == false)
  23747. return;
  23748. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  23749. if (callback(session.getLine(row), row))
  23750. return;
  23751. };
  23752. return {forEach: forEach};
  23753. };
  23754. }).call(Search.prototype);
  23755. exports.Search = Search;
  23756. });
  23757. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(acequire, exports, module) {
  23758. "use strict";
  23759. var keyUtil = acequire("../lib/keys");
  23760. var useragent = acequire("../lib/useragent");
  23761. var KEY_MODS = keyUtil.KEY_MODS;
  23762. function HashHandler(config, platform) {
  23763. this.platform = platform || (useragent.isMac ? "mac" : "win");
  23764. this.commands = {};
  23765. this.commandKeyBinding = {};
  23766. this.addCommands(config);
  23767. this.$singleCommand = true;
  23768. }
  23769. function MultiHashHandler(config, platform) {
  23770. HashHandler.call(this, config, platform);
  23771. this.$singleCommand = false;
  23772. }
  23773. MultiHashHandler.prototype = HashHandler.prototype;
  23774. (function() {
  23775. this.addCommand = function(command) {
  23776. if (this.commands[command.name])
  23777. this.removeCommand(command);
  23778. this.commands[command.name] = command;
  23779. if (command.bindKey)
  23780. this._buildKeyHash(command);
  23781. };
  23782. this.removeCommand = function(command, keepCommand) {
  23783. var name = command && (typeof command === 'string' ? command : command.name);
  23784. command = this.commands[name];
  23785. if (!keepCommand)
  23786. delete this.commands[name];
  23787. var ckb = this.commandKeyBinding;
  23788. for (var keyId in ckb) {
  23789. var cmdGroup = ckb[keyId];
  23790. if (cmdGroup == command) {
  23791. delete ckb[keyId];
  23792. } else if (Array.isArray(cmdGroup)) {
  23793. var i = cmdGroup.indexOf(command);
  23794. if (i != -1) {
  23795. cmdGroup.splice(i, 1);
  23796. if (cmdGroup.length == 1)
  23797. ckb[keyId] = cmdGroup[0];
  23798. }
  23799. }
  23800. }
  23801. };
  23802. this.bindKey = function(key, command, position) {
  23803. if (typeof key == "object" && key) {
  23804. if (position == undefined)
  23805. position = key.position;
  23806. key = key[this.platform];
  23807. }
  23808. if (!key)
  23809. return;
  23810. if (typeof command == "function")
  23811. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  23812. key.split("|").forEach(function(keyPart) {
  23813. var chain = "";
  23814. if (keyPart.indexOf(" ") != -1) {
  23815. var parts = keyPart.split(/\s+/);
  23816. keyPart = parts.pop();
  23817. parts.forEach(function(keyPart) {
  23818. var binding = this.parseKeys(keyPart);
  23819. var id = KEY_MODS[binding.hashId] + binding.key;
  23820. chain += (chain ? " " : "") + id;
  23821. this._addCommandToBinding(chain, "chainKeys");
  23822. }, this);
  23823. chain += " ";
  23824. }
  23825. var binding = this.parseKeys(keyPart);
  23826. var id = KEY_MODS[binding.hashId] + binding.key;
  23827. this._addCommandToBinding(chain + id, command, position);
  23828. }, this);
  23829. };
  23830. function getPosition(command) {
  23831. return typeof command == "object" && command.bindKey
  23832. && command.bindKey.position || 0;
  23833. }
  23834. this._addCommandToBinding = function(keyId, command, position) {
  23835. var ckb = this.commandKeyBinding, i;
  23836. if (!command) {
  23837. delete ckb[keyId];
  23838. } else if (!ckb[keyId] || this.$singleCommand) {
  23839. ckb[keyId] = command;
  23840. } else {
  23841. if (!Array.isArray(ckb[keyId])) {
  23842. ckb[keyId] = [ckb[keyId]];
  23843. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  23844. ckb[keyId].splice(i, 1);
  23845. }
  23846. if (typeof position != "number") {
  23847. if (position || command.isDefault)
  23848. position = -100;
  23849. else
  23850. position = getPosition(command);
  23851. }
  23852. var commands = ckb[keyId];
  23853. for (i = 0; i < commands.length; i++) {
  23854. var other = commands[i];
  23855. var otherPos = getPosition(other);
  23856. if (otherPos > position)
  23857. break;
  23858. }
  23859. commands.splice(i, 0, command);
  23860. }
  23861. };
  23862. this.addCommands = function(commands) {
  23863. commands && Object.keys(commands).forEach(function(name) {
  23864. var command = commands[name];
  23865. if (!command)
  23866. return;
  23867. if (typeof command === "string")
  23868. return this.bindKey(command, name);
  23869. if (typeof command === "function")
  23870. command = { exec: command };
  23871. if (typeof command !== "object")
  23872. return;
  23873. if (!command.name)
  23874. command.name = name;
  23875. this.addCommand(command);
  23876. }, this);
  23877. };
  23878. this.removeCommands = function(commands) {
  23879. Object.keys(commands).forEach(function(name) {
  23880. this.removeCommand(commands[name]);
  23881. }, this);
  23882. };
  23883. this.bindKeys = function(keyList) {
  23884. Object.keys(keyList).forEach(function(key) {
  23885. this.bindKey(key, keyList[key]);
  23886. }, this);
  23887. };
  23888. this._buildKeyHash = function(command) {
  23889. this.bindKey(command.bindKey, command);
  23890. };
  23891. this.parseKeys = function(keys) {
  23892. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
  23893. var key = parts.pop();
  23894. var keyCode = keyUtil[key];
  23895. if (keyUtil.FUNCTION_KEYS[keyCode])
  23896. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  23897. else if (!parts.length)
  23898. return {key: key, hashId: -1};
  23899. else if (parts.length == 1 && parts[0] == "shift")
  23900. return {key: key.toUpperCase(), hashId: -1};
  23901. var hashId = 0;
  23902. for (var i = parts.length; i--;) {
  23903. var modifier = keyUtil.KEY_MODS[parts[i]];
  23904. if (modifier == null) {
  23905. if (typeof console != "undefined")
  23906. console.error("invalid modifier " + parts[i] + " in " + keys);
  23907. return false;
  23908. }
  23909. hashId |= modifier;
  23910. }
  23911. return {key: key, hashId: hashId};
  23912. };
  23913. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  23914. var key = KEY_MODS[hashId] + keyString;
  23915. return this.commandKeyBinding[key];
  23916. };
  23917. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  23918. if (keyCode < 0) return;
  23919. var key = KEY_MODS[hashId] + keyString;
  23920. var command = this.commandKeyBinding[key];
  23921. if (data.$keyChain) {
  23922. data.$keyChain += " " + key;
  23923. command = this.commandKeyBinding[data.$keyChain] || command;
  23924. }
  23925. if (command) {
  23926. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  23927. data.$keyChain = data.$keyChain || key;
  23928. return {command: "null"};
  23929. }
  23930. }
  23931. if (data.$keyChain) {
  23932. if ((!hashId || hashId == 4) && keyString.length == 1)
  23933. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  23934. else if (hashId == -1 || keyCode > 0)
  23935. data.$keyChain = ""; // reset keyChain
  23936. }
  23937. return {command: command};
  23938. };
  23939. this.getStatusText = function(editor, data) {
  23940. return data.$keyChain || "";
  23941. };
  23942. }).call(HashHandler.prototype);
  23943. exports.HashHandler = HashHandler;
  23944. exports.MultiHashHandler = MultiHashHandler;
  23945. });
  23946. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(acequire, exports, module) {
  23947. "use strict";
  23948. var oop = acequire("../lib/oop");
  23949. var MultiHashHandler = acequire("../keyboard/hash_handler").MultiHashHandler;
  23950. var EventEmitter = acequire("../lib/event_emitter").EventEmitter;
  23951. var CommandManager = function(platform, commands) {
  23952. MultiHashHandler.call(this, commands, platform);
  23953. this.byName = this.commands;
  23954. this.setDefaultHandler("exec", function(e) {
  23955. return e.command.exec(e.editor, e.args || {});
  23956. });
  23957. };
  23958. oop.inherits(CommandManager, MultiHashHandler);
  23959. (function() {
  23960. oop.implement(this, EventEmitter);
  23961. this.exec = function(command, editor, args) {
  23962. if (Array.isArray(command)) {
  23963. for (var i = command.length; i--; ) {
  23964. if (this.exec(command[i], editor, args)) return true;
  23965. }
  23966. return false;
  23967. }
  23968. if (typeof command === "string")
  23969. command = this.commands[command];
  23970. if (!command)
  23971. return false;
  23972. if (editor && editor.$readOnly && !command.readOnly)
  23973. return false;
  23974. var e = {editor: editor, command: command, args: args};
  23975. e.returnValue = this._emit("exec", e);
  23976. this._signal("afterExec", e);
  23977. return e.returnValue === false ? false : true;
  23978. };
  23979. this.toggleRecording = function(editor) {
  23980. if (this.$inReplay)
  23981. return;
  23982. editor && editor._emit("changeStatus");
  23983. if (this.recording) {
  23984. this.macro.pop();
  23985. this.removeEventListener("exec", this.$addCommandToMacro);
  23986. if (!this.macro.length)
  23987. this.macro = this.oldMacro;
  23988. return this.recording = false;
  23989. }
  23990. if (!this.$addCommandToMacro) {
  23991. this.$addCommandToMacro = function(e) {
  23992. this.macro.push([e.command, e.args]);
  23993. }.bind(this);
  23994. }
  23995. this.oldMacro = this.macro;
  23996. this.macro = [];
  23997. this.on("exec", this.$addCommandToMacro);
  23998. return this.recording = true;
  23999. };
  24000. this.replay = function(editor) {
  24001. if (this.$inReplay || !this.macro)
  24002. return;
  24003. if (this.recording)
  24004. return this.toggleRecording(editor);
  24005. try {
  24006. this.$inReplay = true;
  24007. this.macro.forEach(function(x) {
  24008. if (typeof x == "string")
  24009. this.exec(x, editor);
  24010. else
  24011. this.exec(x[0], editor, x[1]);
  24012. }, this);
  24013. } finally {
  24014. this.$inReplay = false;
  24015. }
  24016. };
  24017. this.trimMacro = function(m) {
  24018. return m.map(function(x){
  24019. if (typeof x[0] != "string")
  24020. x[0] = x[0].name;
  24021. if (!x[1])
  24022. x = x[0];
  24023. return x;
  24024. });
  24025. };
  24026. }).call(CommandManager.prototype);
  24027. exports.CommandManager = CommandManager;
  24028. });
  24029. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(acequire, exports, module) {
  24030. "use strict";
  24031. var lang = acequire("../lib/lang");
  24032. var config = acequire("../config");
  24033. var Range = acequire("../range").Range;
  24034. function bindKey(win, mac) {
  24035. return {win: win, mac: mac};
  24036. }
  24037. exports.commands = [{
  24038. name: "showSettingsMenu",
  24039. bindKey: bindKey("Ctrl-,", "Command-,"),
  24040. exec: function(editor) {
  24041. config.loadModule("ace/ext/settings_menu", function(module) {
  24042. module.init(editor);
  24043. editor.showSettingsMenu();
  24044. });
  24045. },
  24046. readOnly: true
  24047. }, {
  24048. name: "goToNextError",
  24049. bindKey: bindKey("Alt-E", "Ctrl-E"),
  24050. exec: function(editor) {
  24051. config.loadModule("ace/ext/error_marker", function(module) {
  24052. module.showErrorMarker(editor, 1);
  24053. });
  24054. },
  24055. scrollIntoView: "animate",
  24056. readOnly: true
  24057. }, {
  24058. name: "goToPreviousError",
  24059. bindKey: bindKey("Alt-Shift-E", "Ctrl-Shift-E"),
  24060. exec: function(editor) {
  24061. config.loadModule("ace/ext/error_marker", function(module) {
  24062. module.showErrorMarker(editor, -1);
  24063. });
  24064. },
  24065. scrollIntoView: "animate",
  24066. readOnly: true
  24067. }, {
  24068. name: "selectall",
  24069. bindKey: bindKey("Ctrl-A", "Command-A"),
  24070. exec: function(editor) { editor.selectAll(); },
  24071. readOnly: true
  24072. }, {
  24073. name: "centerselection",
  24074. bindKey: bindKey(null, "Ctrl-L"),
  24075. exec: function(editor) { editor.centerSelection(); },
  24076. readOnly: true
  24077. }, {
  24078. name: "gotoline",
  24079. bindKey: bindKey("Ctrl-L", "Command-L"),
  24080. exec: function(editor) {
  24081. var line = parseInt(prompt("Enter line number:"), 10);
  24082. if (!isNaN(line)) {
  24083. editor.gotoLine(line);
  24084. }
  24085. },
  24086. readOnly: true
  24087. }, {
  24088. name: "fold",
  24089. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  24090. exec: function(editor) { editor.session.toggleFold(false); },
  24091. multiSelectAction: "forEach",
  24092. scrollIntoView: "center",
  24093. readOnly: true
  24094. }, {
  24095. name: "unfold",
  24096. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  24097. exec: function(editor) { editor.session.toggleFold(true); },
  24098. multiSelectAction: "forEach",
  24099. scrollIntoView: "center",
  24100. readOnly: true
  24101. }, {
  24102. name: "toggleFoldWidget",
  24103. bindKey: bindKey("F2", "F2"),
  24104. exec: function(editor) { editor.session.toggleFoldWidget(); },
  24105. multiSelectAction: "forEach",
  24106. scrollIntoView: "center",
  24107. readOnly: true
  24108. }, {
  24109. name: "toggleParentFoldWidget",
  24110. bindKey: bindKey("Alt-F2", "Alt-F2"),
  24111. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  24112. multiSelectAction: "forEach",
  24113. scrollIntoView: "center",
  24114. readOnly: true
  24115. }, {
  24116. name: "foldall",
  24117. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  24118. exec: function(editor) { editor.session.foldAll(); },
  24119. scrollIntoView: "center",
  24120. readOnly: true
  24121. }, {
  24122. name: "foldOther",
  24123. bindKey: bindKey("Alt-0", "Command-Option-0"),
  24124. exec: function(editor) {
  24125. editor.session.foldAll();
  24126. editor.session.unfold(editor.selection.getAllRanges());
  24127. },
  24128. scrollIntoView: "center",
  24129. readOnly: true
  24130. }, {
  24131. name: "unfoldall",
  24132. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  24133. exec: function(editor) { editor.session.unfold(); },
  24134. scrollIntoView: "center",
  24135. readOnly: true
  24136. }, {
  24137. name: "findnext",
  24138. bindKey: bindKey("Ctrl-K", "Command-G"),
  24139. exec: function(editor) { editor.findNext(); },
  24140. multiSelectAction: "forEach",
  24141. scrollIntoView: "center",
  24142. readOnly: true
  24143. }, {
  24144. name: "findprevious",
  24145. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  24146. exec: function(editor) { editor.findPrevious(); },
  24147. multiSelectAction: "forEach",
  24148. scrollIntoView: "center",
  24149. readOnly: true
  24150. }, {
  24151. name: "selectOrFindNext",
  24152. bindKey: bindKey("Alt-K", "Ctrl-G"),
  24153. exec: function(editor) {
  24154. if (editor.selection.isEmpty())
  24155. editor.selection.selectWord();
  24156. else
  24157. editor.findNext();
  24158. },
  24159. readOnly: true
  24160. }, {
  24161. name: "selectOrFindPrevious",
  24162. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  24163. exec: function(editor) {
  24164. if (editor.selection.isEmpty())
  24165. editor.selection.selectWord();
  24166. else
  24167. editor.findPrevious();
  24168. },
  24169. readOnly: true
  24170. }, {
  24171. name: "find",
  24172. bindKey: bindKey("Ctrl-F", "Command-F"),
  24173. exec: function(editor) {
  24174. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  24175. },
  24176. readOnly: true
  24177. }, {
  24178. name: "overwrite",
  24179. bindKey: "Insert",
  24180. exec: function(editor) { editor.toggleOverwrite(); },
  24181. readOnly: true
  24182. }, {
  24183. name: "selecttostart",
  24184. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
  24185. exec: function(editor) { editor.getSelection().selectFileStart(); },
  24186. multiSelectAction: "forEach",
  24187. readOnly: true,
  24188. scrollIntoView: "animate",
  24189. aceCommandGroup: "fileJump"
  24190. }, {
  24191. name: "gotostart",
  24192. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  24193. exec: function(editor) { editor.navigateFileStart(); },
  24194. multiSelectAction: "forEach",
  24195. readOnly: true,
  24196. scrollIntoView: "animate",
  24197. aceCommandGroup: "fileJump"
  24198. }, {
  24199. name: "selectup",
  24200. bindKey: bindKey("Shift-Up", "Shift-Up"),
  24201. exec: function(editor) { editor.getSelection().selectUp(); },
  24202. multiSelectAction: "forEach",
  24203. scrollIntoView: "cursor",
  24204. readOnly: true
  24205. }, {
  24206. name: "golineup",
  24207. bindKey: bindKey("Up", "Up|Ctrl-P"),
  24208. exec: function(editor, args) { editor.navigateUp(args.times); },
  24209. multiSelectAction: "forEach",
  24210. scrollIntoView: "cursor",
  24211. readOnly: true
  24212. }, {
  24213. name: "selecttoend",
  24214. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
  24215. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  24216. multiSelectAction: "forEach",
  24217. readOnly: true,
  24218. scrollIntoView: "animate",
  24219. aceCommandGroup: "fileJump"
  24220. }, {
  24221. name: "gotoend",
  24222. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  24223. exec: function(editor) { editor.navigateFileEnd(); },
  24224. multiSelectAction: "forEach",
  24225. readOnly: true,
  24226. scrollIntoView: "animate",
  24227. aceCommandGroup: "fileJump"
  24228. }, {
  24229. name: "selectdown",
  24230. bindKey: bindKey("Shift-Down", "Shift-Down"),
  24231. exec: function(editor) { editor.getSelection().selectDown(); },
  24232. multiSelectAction: "forEach",
  24233. scrollIntoView: "cursor",
  24234. readOnly: true
  24235. }, {
  24236. name: "golinedown",
  24237. bindKey: bindKey("Down", "Down|Ctrl-N"),
  24238. exec: function(editor, args) { editor.navigateDown(args.times); },
  24239. multiSelectAction: "forEach",
  24240. scrollIntoView: "cursor",
  24241. readOnly: true
  24242. }, {
  24243. name: "selectwordleft",
  24244. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  24245. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  24246. multiSelectAction: "forEach",
  24247. scrollIntoView: "cursor",
  24248. readOnly: true
  24249. }, {
  24250. name: "gotowordleft",
  24251. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  24252. exec: function(editor) { editor.navigateWordLeft(); },
  24253. multiSelectAction: "forEach",
  24254. scrollIntoView: "cursor",
  24255. readOnly: true
  24256. }, {
  24257. name: "selecttolinestart",
  24258. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
  24259. exec: function(editor) { editor.getSelection().selectLineStart(); },
  24260. multiSelectAction: "forEach",
  24261. scrollIntoView: "cursor",
  24262. readOnly: true
  24263. }, {
  24264. name: "gotolinestart",
  24265. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  24266. exec: function(editor) { editor.navigateLineStart(); },
  24267. multiSelectAction: "forEach",
  24268. scrollIntoView: "cursor",
  24269. readOnly: true
  24270. }, {
  24271. name: "selectleft",
  24272. bindKey: bindKey("Shift-Left", "Shift-Left"),
  24273. exec: function(editor) { editor.getSelection().selectLeft(); },
  24274. multiSelectAction: "forEach",
  24275. scrollIntoView: "cursor",
  24276. readOnly: true
  24277. }, {
  24278. name: "gotoleft",
  24279. bindKey: bindKey("Left", "Left|Ctrl-B"),
  24280. exec: function(editor, args) { editor.navigateLeft(args.times); },
  24281. multiSelectAction: "forEach",
  24282. scrollIntoView: "cursor",
  24283. readOnly: true
  24284. }, {
  24285. name: "selectwordright",
  24286. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  24287. exec: function(editor) { editor.getSelection().selectWordRight(); },
  24288. multiSelectAction: "forEach",
  24289. scrollIntoView: "cursor",
  24290. readOnly: true
  24291. }, {
  24292. name: "gotowordright",
  24293. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  24294. exec: function(editor) { editor.navigateWordRight(); },
  24295. multiSelectAction: "forEach",
  24296. scrollIntoView: "cursor",
  24297. readOnly: true
  24298. }, {
  24299. name: "selecttolineend",
  24300. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
  24301. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  24302. multiSelectAction: "forEach",
  24303. scrollIntoView: "cursor",
  24304. readOnly: true
  24305. }, {
  24306. name: "gotolineend",
  24307. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  24308. exec: function(editor) { editor.navigateLineEnd(); },
  24309. multiSelectAction: "forEach",
  24310. scrollIntoView: "cursor",
  24311. readOnly: true
  24312. }, {
  24313. name: "selectright",
  24314. bindKey: bindKey("Shift-Right", "Shift-Right"),
  24315. exec: function(editor) { editor.getSelection().selectRight(); },
  24316. multiSelectAction: "forEach",
  24317. scrollIntoView: "cursor",
  24318. readOnly: true
  24319. }, {
  24320. name: "gotoright",
  24321. bindKey: bindKey("Right", "Right|Ctrl-F"),
  24322. exec: function(editor, args) { editor.navigateRight(args.times); },
  24323. multiSelectAction: "forEach",
  24324. scrollIntoView: "cursor",
  24325. readOnly: true
  24326. }, {
  24327. name: "selectpagedown",
  24328. bindKey: "Shift-PageDown",
  24329. exec: function(editor) { editor.selectPageDown(); },
  24330. readOnly: true
  24331. }, {
  24332. name: "pagedown",
  24333. bindKey: bindKey(null, "Option-PageDown"),
  24334. exec: function(editor) { editor.scrollPageDown(); },
  24335. readOnly: true
  24336. }, {
  24337. name: "gotopagedown",
  24338. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  24339. exec: function(editor) { editor.gotoPageDown(); },
  24340. readOnly: true
  24341. }, {
  24342. name: "selectpageup",
  24343. bindKey: "Shift-PageUp",
  24344. exec: function(editor) { editor.selectPageUp(); },
  24345. readOnly: true
  24346. }, {
  24347. name: "pageup",
  24348. bindKey: bindKey(null, "Option-PageUp"),
  24349. exec: function(editor) { editor.scrollPageUp(); },
  24350. readOnly: true
  24351. }, {
  24352. name: "gotopageup",
  24353. bindKey: "PageUp",
  24354. exec: function(editor) { editor.gotoPageUp(); },
  24355. readOnly: true
  24356. }, {
  24357. name: "scrollup",
  24358. bindKey: bindKey("Ctrl-Up", null),
  24359. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  24360. readOnly: true
  24361. }, {
  24362. name: "scrolldown",
  24363. bindKey: bindKey("Ctrl-Down", null),
  24364. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  24365. readOnly: true
  24366. }, {
  24367. name: "selectlinestart",
  24368. bindKey: "Shift-Home",
  24369. exec: function(editor) { editor.getSelection().selectLineStart(); },
  24370. multiSelectAction: "forEach",
  24371. scrollIntoView: "cursor",
  24372. readOnly: true
  24373. }, {
  24374. name: "selectlineend",
  24375. bindKey: "Shift-End",
  24376. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  24377. multiSelectAction: "forEach",
  24378. scrollIntoView: "cursor",
  24379. readOnly: true
  24380. }, {
  24381. name: "togglerecording",
  24382. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  24383. exec: function(editor) { editor.commands.toggleRecording(editor); },
  24384. readOnly: true
  24385. }, {
  24386. name: "replaymacro",
  24387. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  24388. exec: function(editor) { editor.commands.replay(editor); },
  24389. readOnly: true
  24390. }, {
  24391. name: "jumptomatching",
  24392. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  24393. exec: function(editor) { editor.jumpToMatching(); },
  24394. multiSelectAction: "forEach",
  24395. scrollIntoView: "animate",
  24396. readOnly: true
  24397. }, {
  24398. name: "selecttomatching",
  24399. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  24400. exec: function(editor) { editor.jumpToMatching(true); },
  24401. multiSelectAction: "forEach",
  24402. scrollIntoView: "animate",
  24403. readOnly: true
  24404. }, {
  24405. name: "expandToMatching",
  24406. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  24407. exec: function(editor) { editor.jumpToMatching(true, true); },
  24408. multiSelectAction: "forEach",
  24409. scrollIntoView: "animate",
  24410. readOnly: true
  24411. }, {
  24412. name: "passKeysToBrowser",
  24413. bindKey: bindKey(null, null),
  24414. exec: function() {},
  24415. passEvent: true,
  24416. readOnly: true
  24417. }, {
  24418. name: "copy",
  24419. exec: function(editor) {
  24420. },
  24421. readOnly: true
  24422. },
  24423. {
  24424. name: "cut",
  24425. exec: function(editor) {
  24426. var range = editor.getSelectionRange();
  24427. editor._emit("cut", range);
  24428. if (!editor.selection.isEmpty()) {
  24429. editor.session.remove(range);
  24430. editor.clearSelection();
  24431. }
  24432. },
  24433. scrollIntoView: "cursor",
  24434. multiSelectAction: "forEach"
  24435. }, {
  24436. name: "paste",
  24437. exec: function(editor, args) {
  24438. editor.$handlePaste(args);
  24439. },
  24440. scrollIntoView: "cursor"
  24441. }, {
  24442. name: "removeline",
  24443. bindKey: bindKey("Ctrl-D", "Command-D"),
  24444. exec: function(editor) { editor.removeLines(); },
  24445. scrollIntoView: "cursor",
  24446. multiSelectAction: "forEachLine"
  24447. }, {
  24448. name: "duplicateSelection",
  24449. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  24450. exec: function(editor) { editor.duplicateSelection(); },
  24451. scrollIntoView: "cursor",
  24452. multiSelectAction: "forEach"
  24453. }, {
  24454. name: "sortlines",
  24455. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  24456. exec: function(editor) { editor.sortLines(); },
  24457. scrollIntoView: "selection",
  24458. multiSelectAction: "forEachLine"
  24459. }, {
  24460. name: "togglecomment",
  24461. bindKey: bindKey("Ctrl-/", "Command-/"),
  24462. exec: function(editor) { editor.toggleCommentLines(); },
  24463. multiSelectAction: "forEachLine",
  24464. scrollIntoView: "selectionPart"
  24465. }, {
  24466. name: "toggleBlockComment",
  24467. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  24468. exec: function(editor) { editor.toggleBlockComment(); },
  24469. multiSelectAction: "forEach",
  24470. scrollIntoView: "selectionPart"
  24471. }, {
  24472. name: "modifyNumberUp",
  24473. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  24474. exec: function(editor) { editor.modifyNumber(1); },
  24475. scrollIntoView: "cursor",
  24476. multiSelectAction: "forEach"
  24477. }, {
  24478. name: "modifyNumberDown",
  24479. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  24480. exec: function(editor) { editor.modifyNumber(-1); },
  24481. scrollIntoView: "cursor",
  24482. multiSelectAction: "forEach"
  24483. }, {
  24484. name: "replace",
  24485. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  24486. exec: function(editor) {
  24487. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  24488. }
  24489. }, {
  24490. name: "undo",
  24491. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  24492. exec: function(editor) { editor.undo(); }
  24493. }, {
  24494. name: "redo",
  24495. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  24496. exec: function(editor) { editor.redo(); }
  24497. }, {
  24498. name: "copylinesup",
  24499. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  24500. exec: function(editor) { editor.copyLinesUp(); },
  24501. scrollIntoView: "cursor"
  24502. }, {
  24503. name: "movelinesup",
  24504. bindKey: bindKey("Alt-Up", "Option-Up"),
  24505. exec: function(editor) { editor.moveLinesUp(); },
  24506. scrollIntoView: "cursor"
  24507. }, {
  24508. name: "copylinesdown",
  24509. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  24510. exec: function(editor) { editor.copyLinesDown(); },
  24511. scrollIntoView: "cursor"
  24512. }, {
  24513. name: "movelinesdown",
  24514. bindKey: bindKey("Alt-Down", "Option-Down"),
  24515. exec: function(editor) { editor.moveLinesDown(); },
  24516. scrollIntoView: "cursor"
  24517. }, {
  24518. name: "del",
  24519. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  24520. exec: function(editor) { editor.remove("right"); },
  24521. multiSelectAction: "forEach",
  24522. scrollIntoView: "cursor"
  24523. }, {
  24524. name: "backspace",
  24525. bindKey: bindKey(
  24526. "Shift-Backspace|Backspace",
  24527. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  24528. ),
  24529. exec: function(editor) { editor.remove("left"); },
  24530. multiSelectAction: "forEach",
  24531. scrollIntoView: "cursor"
  24532. }, {
  24533. name: "cut_or_delete",
  24534. bindKey: bindKey("Shift-Delete", null),
  24535. exec: function(editor) {
  24536. if (editor.selection.isEmpty()) {
  24537. editor.remove("left");
  24538. } else {
  24539. return false;
  24540. }
  24541. },
  24542. multiSelectAction: "forEach",
  24543. scrollIntoView: "cursor"
  24544. }, {
  24545. name: "removetolinestart",
  24546. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  24547. exec: function(editor) { editor.removeToLineStart(); },
  24548. multiSelectAction: "forEach",
  24549. scrollIntoView: "cursor"
  24550. }, {
  24551. name: "removetolineend",
  24552. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  24553. exec: function(editor) { editor.removeToLineEnd(); },
  24554. multiSelectAction: "forEach",
  24555. scrollIntoView: "cursor"
  24556. }, {
  24557. name: "removewordleft",
  24558. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  24559. exec: function(editor) { editor.removeWordLeft(); },
  24560. multiSelectAction: "forEach",
  24561. scrollIntoView: "cursor"
  24562. }, {
  24563. name: "removewordright",
  24564. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  24565. exec: function(editor) { editor.removeWordRight(); },
  24566. multiSelectAction: "forEach",
  24567. scrollIntoView: "cursor"
  24568. }, {
  24569. name: "outdent",
  24570. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  24571. exec: function(editor) { editor.blockOutdent(); },
  24572. multiSelectAction: "forEach",
  24573. scrollIntoView: "selectionPart"
  24574. }, {
  24575. name: "indent",
  24576. bindKey: bindKey("Tab", "Tab"),
  24577. exec: function(editor) { editor.indent(); },
  24578. multiSelectAction: "forEach",
  24579. scrollIntoView: "selectionPart"
  24580. }, {
  24581. name: "blockoutdent",
  24582. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  24583. exec: function(editor) { editor.blockOutdent(); },
  24584. multiSelectAction: "forEachLine",
  24585. scrollIntoView: "selectionPart"
  24586. }, {
  24587. name: "blockindent",
  24588. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  24589. exec: function(editor) { editor.blockIndent(); },
  24590. multiSelectAction: "forEachLine",
  24591. scrollIntoView: "selectionPart"
  24592. }, {
  24593. name: "insertstring",
  24594. exec: function(editor, str) { editor.insert(str); },
  24595. multiSelectAction: "forEach",
  24596. scrollIntoView: "cursor"
  24597. }, {
  24598. name: "inserttext",
  24599. exec: function(editor, args) {
  24600. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  24601. },
  24602. multiSelectAction: "forEach",
  24603. scrollIntoView: "cursor"
  24604. }, {
  24605. name: "splitline",
  24606. bindKey: bindKey(null, "Ctrl-O"),
  24607. exec: function(editor) { editor.splitLine(); },
  24608. multiSelectAction: "forEach",
  24609. scrollIntoView: "cursor"
  24610. }, {
  24611. name: "transposeletters",
  24612. bindKey: bindKey("Ctrl-T", "Ctrl-T"),
  24613. exec: function(editor) { editor.transposeLetters(); },
  24614. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  24615. scrollIntoView: "cursor"
  24616. }, {
  24617. name: "touppercase",
  24618. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  24619. exec: function(editor) { editor.toUpperCase(); },
  24620. multiSelectAction: "forEach",
  24621. scrollIntoView: "cursor"
  24622. }, {
  24623. name: "tolowercase",
  24624. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  24625. exec: function(editor) { editor.toLowerCase(); },
  24626. multiSelectAction: "forEach",
  24627. scrollIntoView: "cursor"
  24628. }, {
  24629. name: "expandtoline",
  24630. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  24631. exec: function(editor) {
  24632. var range = editor.selection.getRange();
  24633. range.start.column = range.end.column = 0;
  24634. range.end.row++;
  24635. editor.selection.setRange(range, false);
  24636. },
  24637. multiSelectAction: "forEach",
  24638. scrollIntoView: "cursor",
  24639. readOnly: true
  24640. }, {
  24641. name: "joinlines",
  24642. bindKey: bindKey(null, null),
  24643. exec: function(editor) {
  24644. var isBackwards = editor.selection.isBackwards();
  24645. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  24646. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  24647. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  24648. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  24649. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  24650. var insertLine = editor.session.doc.getLine(selectionStart.row);
  24651. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  24652. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  24653. if (curLine.length !== 0) {
  24654. curLine = " " + curLine;
  24655. }
  24656. insertLine += curLine;
  24657. }
  24658. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  24659. insertLine += editor.session.doc.getNewLineCharacter();
  24660. }
  24661. editor.clearSelection();
  24662. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  24663. if (selectedCount > 0) {
  24664. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  24665. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  24666. } else {
  24667. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  24668. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  24669. }
  24670. },
  24671. multiSelectAction: "forEach",
  24672. readOnly: true
  24673. }, {
  24674. name: "invertSelection",
  24675. bindKey: bindKey(null, null),
  24676. exec: function(editor) {
  24677. var endRow = editor.session.doc.getLength() - 1;
  24678. var endCol = editor.session.doc.getLine(endRow).length;
  24679. var ranges = editor.selection.rangeList.ranges;
  24680. var newRanges = [];
  24681. if (ranges.length < 1) {
  24682. ranges = [editor.selection.getRange()];
  24683. }
  24684. for (var i = 0; i < ranges.length; i++) {
  24685. if (i == (ranges.length - 1)) {
  24686. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  24687. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  24688. }
  24689. }
  24690. if (i === 0) {
  24691. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  24692. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  24693. }
  24694. } else {
  24695. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  24696. }
  24697. }
  24698. editor.exitMultiSelectMode();
  24699. editor.clearSelection();
  24700. for(var i = 0; i < newRanges.length; i++) {
  24701. editor.selection.addRange(newRanges[i], false);
  24702. }
  24703. },
  24704. readOnly: true,
  24705. scrollIntoView: "none"
  24706. }];
  24707. });
  24708. ace.define("ace/editor",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/keyboard/textinput","ace/mouse/mouse_handler","ace/mouse/fold_handler","ace/keyboard/keybinding","ace/edit_session","ace/search","ace/range","ace/lib/event_emitter","ace/commands/command_manager","ace/commands/default_commands","ace/config","ace/token_iterator"], function(acequire, exports, module) {
  24709. "use strict";
  24710. acequire("./lib/fixoldbrowsers");
  24711. var oop = acequire("./lib/oop");
  24712. var dom = acequire("./lib/dom");
  24713. var lang = acequire("./lib/lang");
  24714. var useragent = acequire("./lib/useragent");
  24715. var TextInput = acequire("./keyboard/textinput").TextInput;
  24716. var MouseHandler = acequire("./mouse/mouse_handler").MouseHandler;
  24717. var FoldHandler = acequire("./mouse/fold_handler").FoldHandler;
  24718. var KeyBinding = acequire("./keyboard/keybinding").KeyBinding;
  24719. var EditSession = acequire("./edit_session").EditSession;
  24720. var Search = acequire("./search").Search;
  24721. var Range = acequire("./range").Range;
  24722. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  24723. var CommandManager = acequire("./commands/command_manager").CommandManager;
  24724. var defaultCommands = acequire("./commands/default_commands").commands;
  24725. var config = acequire("./config");
  24726. var TokenIterator = acequire("./token_iterator").TokenIterator;
  24727. var Editor = function(renderer, session) {
  24728. var container = renderer.getContainerElement();
  24729. this.container = container;
  24730. this.renderer = renderer;
  24731. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  24732. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  24733. this.renderer.textarea = this.textInput.getElement();
  24734. this.keyBinding = new KeyBinding(this);
  24735. this.$mouseHandler = new MouseHandler(this);
  24736. new FoldHandler(this);
  24737. this.$blockScrolling = 0;
  24738. this.$search = new Search().set({
  24739. wrap: true
  24740. });
  24741. this.$historyTracker = this.$historyTracker.bind(this);
  24742. this.commands.on("exec", this.$historyTracker);
  24743. this.$initOperationListeners();
  24744. this._$emitInputEvent = lang.delayedCall(function() {
  24745. this._signal("input", {});
  24746. if (this.session && this.session.bgTokenizer)
  24747. this.session.bgTokenizer.scheduleStart();
  24748. }.bind(this));
  24749. this.on("change", function(_, _self) {
  24750. _self._$emitInputEvent.schedule(31);
  24751. });
  24752. this.setSession(session || new EditSession(""));
  24753. config.resetOptions(this);
  24754. config._signal("editor", this);
  24755. };
  24756. (function(){
  24757. oop.implement(this, EventEmitter);
  24758. this.$initOperationListeners = function() {
  24759. function last(a) {return a[a.length - 1]}
  24760. this.selections = [];
  24761. this.commands.on("exec", this.startOperation.bind(this), true);
  24762. this.commands.on("afterExec", this.endOperation.bind(this), true);
  24763. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
  24764. this.on("change", function() {
  24765. this.curOp || this.startOperation();
  24766. this.curOp.docChanged = true;
  24767. }.bind(this), true);
  24768. this.on("changeSelection", function() {
  24769. this.curOp || this.startOperation();
  24770. this.curOp.selectionChanged = true;
  24771. }.bind(this), true);
  24772. };
  24773. this.curOp = null;
  24774. this.prevOp = {};
  24775. this.startOperation = function(commadEvent) {
  24776. if (this.curOp) {
  24777. if (!commadEvent || this.curOp.command)
  24778. return;
  24779. this.prevOp = this.curOp;
  24780. }
  24781. if (!commadEvent) {
  24782. this.previousCommand = null;
  24783. commadEvent = {};
  24784. }
  24785. this.$opResetTimer.schedule();
  24786. this.curOp = {
  24787. command: commadEvent.command || {},
  24788. args: commadEvent.args,
  24789. scrollTop: this.renderer.scrollTop
  24790. };
  24791. if (this.curOp.command.name && this.curOp.command.scrollIntoView !== undefined)
  24792. this.$blockScrolling++;
  24793. };
  24794. this.endOperation = function(e) {
  24795. if (this.curOp) {
  24796. if (e && e.returnValue === false)
  24797. return this.curOp = null;
  24798. this._signal("beforeEndOperation");
  24799. var command = this.curOp.command;
  24800. if (command.name && this.$blockScrolling > 0)
  24801. this.$blockScrolling--;
  24802. var scrollIntoView = command && command.scrollIntoView;
  24803. if (scrollIntoView) {
  24804. switch (scrollIntoView) {
  24805. case "center-animate":
  24806. scrollIntoView = "animate";
  24807. case "center":
  24808. this.renderer.scrollCursorIntoView(null, 0.5);
  24809. break;
  24810. case "animate":
  24811. case "cursor":
  24812. this.renderer.scrollCursorIntoView();
  24813. break;
  24814. case "selectionPart":
  24815. var range = this.selection.getRange();
  24816. var config = this.renderer.layerConfig;
  24817. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  24818. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  24819. }
  24820. break;
  24821. default:
  24822. break;
  24823. }
  24824. if (scrollIntoView == "animate")
  24825. this.renderer.animateScrolling(this.curOp.scrollTop);
  24826. }
  24827. this.prevOp = this.curOp;
  24828. this.curOp = null;
  24829. }
  24830. };
  24831. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  24832. this.$historyTracker = function(e) {
  24833. if (!this.$mergeUndoDeltas)
  24834. return;
  24835. var prev = this.prevOp;
  24836. var mergeableCommands = this.$mergeableCommands;
  24837. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  24838. if (e.command.name == "insertstring") {
  24839. var text = e.args;
  24840. if (this.mergeNextCommand === undefined)
  24841. this.mergeNextCommand = true;
  24842. shouldMerge = shouldMerge
  24843. && this.mergeNextCommand // previous command allows to coalesce with
  24844. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  24845. this.mergeNextCommand = true;
  24846. } else {
  24847. shouldMerge = shouldMerge
  24848. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  24849. }
  24850. if (
  24851. this.$mergeUndoDeltas != "always"
  24852. && Date.now() - this.sequenceStartTime > 2000
  24853. ) {
  24854. shouldMerge = false; // the sequence is too long
  24855. }
  24856. if (shouldMerge)
  24857. this.session.mergeUndoDeltas = true;
  24858. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  24859. this.sequenceStartTime = Date.now();
  24860. };
  24861. this.setKeyboardHandler = function(keyboardHandler, cb) {
  24862. if (keyboardHandler && typeof keyboardHandler === "string") {
  24863. this.$keybindingId = keyboardHandler;
  24864. var _self = this;
  24865. config.loadModule(["keybinding", keyboardHandler], function(module) {
  24866. if (_self.$keybindingId == keyboardHandler)
  24867. _self.keyBinding.setKeyboardHandler(module && module.handler);
  24868. cb && cb();
  24869. });
  24870. } else {
  24871. this.$keybindingId = null;
  24872. this.keyBinding.setKeyboardHandler(keyboardHandler);
  24873. cb && cb();
  24874. }
  24875. };
  24876. this.getKeyboardHandler = function() {
  24877. return this.keyBinding.getKeyboardHandler();
  24878. };
  24879. this.setSession = function(session) {
  24880. if (this.session == session)
  24881. return;
  24882. if (this.curOp) this.endOperation();
  24883. this.curOp = {};
  24884. var oldSession = this.session;
  24885. if (oldSession) {
  24886. this.session.off("change", this.$onDocumentChange);
  24887. this.session.off("changeMode", this.$onChangeMode);
  24888. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  24889. this.session.off("changeTabSize", this.$onChangeTabSize);
  24890. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  24891. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  24892. this.session.off("changeFold", this.$onChangeFold);
  24893. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  24894. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  24895. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  24896. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  24897. this.session.off("changeOverwrite", this.$onCursorChange);
  24898. this.session.off("changeScrollTop", this.$onScrollTopChange);
  24899. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  24900. var selection = this.session.getSelection();
  24901. selection.off("changeCursor", this.$onCursorChange);
  24902. selection.off("changeSelection", this.$onSelectionChange);
  24903. }
  24904. this.session = session;
  24905. if (session) {
  24906. this.$onDocumentChange = this.onDocumentChange.bind(this);
  24907. session.on("change", this.$onDocumentChange);
  24908. this.renderer.setSession(session);
  24909. this.$onChangeMode = this.onChangeMode.bind(this);
  24910. session.on("changeMode", this.$onChangeMode);
  24911. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  24912. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  24913. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  24914. session.on("changeTabSize", this.$onChangeTabSize);
  24915. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  24916. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  24917. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  24918. session.on("changeWrapMode", this.$onChangeWrapMode);
  24919. this.$onChangeFold = this.onChangeFold.bind(this);
  24920. session.on("changeFold", this.$onChangeFold);
  24921. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  24922. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  24923. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  24924. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  24925. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  24926. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  24927. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  24928. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  24929. this.$onCursorChange = this.onCursorChange.bind(this);
  24930. this.session.on("changeOverwrite", this.$onCursorChange);
  24931. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  24932. this.session.on("changeScrollTop", this.$onScrollTopChange);
  24933. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  24934. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  24935. this.selection = session.getSelection();
  24936. this.selection.on("changeCursor", this.$onCursorChange);
  24937. this.$onSelectionChange = this.onSelectionChange.bind(this);
  24938. this.selection.on("changeSelection", this.$onSelectionChange);
  24939. this.onChangeMode();
  24940. this.$blockScrolling += 1;
  24941. this.onCursorChange();
  24942. this.$blockScrolling -= 1;
  24943. this.onScrollTopChange();
  24944. this.onScrollLeftChange();
  24945. this.onSelectionChange();
  24946. this.onChangeFrontMarker();
  24947. this.onChangeBackMarker();
  24948. this.onChangeBreakpoint();
  24949. this.onChangeAnnotation();
  24950. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  24951. this.renderer.updateFull();
  24952. } else {
  24953. this.selection = null;
  24954. this.renderer.setSession(session);
  24955. }
  24956. this._signal("changeSession", {
  24957. session: session,
  24958. oldSession: oldSession
  24959. });
  24960. this.curOp = null;
  24961. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  24962. session && session._signal("changeEditor", {editor: this});
  24963. };
  24964. this.getSession = function() {
  24965. return this.session;
  24966. };
  24967. this.setValue = function(val, cursorPos) {
  24968. this.session.doc.setValue(val);
  24969. if (!cursorPos)
  24970. this.selectAll();
  24971. else if (cursorPos == 1)
  24972. this.navigateFileEnd();
  24973. else if (cursorPos == -1)
  24974. this.navigateFileStart();
  24975. return val;
  24976. };
  24977. this.getValue = function() {
  24978. return this.session.getValue();
  24979. };
  24980. this.getSelection = function() {
  24981. return this.selection;
  24982. };
  24983. this.resize = function(force) {
  24984. this.renderer.onResize(force);
  24985. };
  24986. this.setTheme = function(theme, cb) {
  24987. this.renderer.setTheme(theme, cb);
  24988. };
  24989. this.getTheme = function() {
  24990. return this.renderer.getTheme();
  24991. };
  24992. this.setStyle = function(style) {
  24993. this.renderer.setStyle(style);
  24994. };
  24995. this.unsetStyle = function(style) {
  24996. this.renderer.unsetStyle(style);
  24997. };
  24998. this.getFontSize = function () {
  24999. return this.getOption("fontSize") ||
  25000. dom.computedStyle(this.container, "fontSize");
  25001. };
  25002. this.setFontSize = function(size) {
  25003. this.setOption("fontSize", size);
  25004. };
  25005. this.$highlightBrackets = function() {
  25006. if (this.session.$bracketHighlight) {
  25007. this.session.removeMarker(this.session.$bracketHighlight);
  25008. this.session.$bracketHighlight = null;
  25009. }
  25010. if (this.$highlightPending) {
  25011. return;
  25012. }
  25013. var self = this;
  25014. this.$highlightPending = true;
  25015. setTimeout(function() {
  25016. self.$highlightPending = false;
  25017. var session = self.session;
  25018. if (!session || !session.bgTokenizer) return;
  25019. var pos = session.findMatchingBracket(self.getCursorPosition());
  25020. if (pos) {
  25021. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  25022. } else if (session.$mode.getMatching) {
  25023. var range = session.$mode.getMatching(self.session);
  25024. }
  25025. if (range)
  25026. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  25027. }, 50);
  25028. };
  25029. this.$highlightTags = function() {
  25030. if (this.$highlightTagPending)
  25031. return;
  25032. var self = this;
  25033. this.$highlightTagPending = true;
  25034. setTimeout(function() {
  25035. self.$highlightTagPending = false;
  25036. var session = self.session;
  25037. if (!session || !session.bgTokenizer) return;
  25038. var pos = self.getCursorPosition();
  25039. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  25040. var token = iterator.getCurrentToken();
  25041. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  25042. session.removeMarker(session.$tagHighlight);
  25043. session.$tagHighlight = null;
  25044. return;
  25045. }
  25046. if (token.type.indexOf("tag-open") != -1) {
  25047. token = iterator.stepForward();
  25048. if (!token)
  25049. return;
  25050. }
  25051. var tag = token.value;
  25052. var depth = 0;
  25053. var prevToken = iterator.stepBackward();
  25054. if (prevToken.value == '<'){
  25055. do {
  25056. prevToken = token;
  25057. token = iterator.stepForward();
  25058. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  25059. if (prevToken.value === '<'){
  25060. depth++;
  25061. } else if (prevToken.value === '</'){
  25062. depth--;
  25063. }
  25064. }
  25065. } while (token && depth >= 0);
  25066. } else {
  25067. do {
  25068. token = prevToken;
  25069. prevToken = iterator.stepBackward();
  25070. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  25071. if (prevToken.value === '<') {
  25072. depth++;
  25073. } else if (prevToken.value === '</') {
  25074. depth--;
  25075. }
  25076. }
  25077. } while (prevToken && depth <= 0);
  25078. iterator.stepForward();
  25079. }
  25080. if (!token) {
  25081. session.removeMarker(session.$tagHighlight);
  25082. session.$tagHighlight = null;
  25083. return;
  25084. }
  25085. var row = iterator.getCurrentTokenRow();
  25086. var column = iterator.getCurrentTokenColumn();
  25087. var range = new Range(row, column, row, column+token.value.length);
  25088. if (session.$tagHighlight && range.compareRange(session.$backMarkers[session.$tagHighlight].range)!==0) {
  25089. session.removeMarker(session.$tagHighlight);
  25090. session.$tagHighlight = null;
  25091. }
  25092. if (range && !session.$tagHighlight)
  25093. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  25094. }, 50);
  25095. };
  25096. this.focus = function() {
  25097. var _self = this;
  25098. setTimeout(function() {
  25099. _self.textInput.focus();
  25100. });
  25101. this.textInput.focus();
  25102. };
  25103. this.isFocused = function() {
  25104. return this.textInput.isFocused();
  25105. };
  25106. this.blur = function() {
  25107. this.textInput.blur();
  25108. };
  25109. this.onFocus = function(e) {
  25110. if (this.$isFocused)
  25111. return;
  25112. this.$isFocused = true;
  25113. this.renderer.showCursor();
  25114. this.renderer.visualizeFocus();
  25115. this._emit("focus", e);
  25116. };
  25117. this.onBlur = function(e) {
  25118. if (!this.$isFocused)
  25119. return;
  25120. this.$isFocused = false;
  25121. this.renderer.hideCursor();
  25122. this.renderer.visualizeBlur();
  25123. this._emit("blur", e);
  25124. };
  25125. this.$cursorChange = function() {
  25126. this.renderer.updateCursor();
  25127. };
  25128. this.onDocumentChange = function(delta) {
  25129. var wrap = this.session.$useWrapMode;
  25130. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  25131. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  25132. this._signal("change", delta);
  25133. this.$cursorChange();
  25134. this.$updateHighlightActiveLine();
  25135. };
  25136. this.onTokenizerUpdate = function(e) {
  25137. var rows = e.data;
  25138. this.renderer.updateLines(rows.first, rows.last);
  25139. };
  25140. this.onScrollTopChange = function() {
  25141. this.renderer.scrollToY(this.session.getScrollTop());
  25142. };
  25143. this.onScrollLeftChange = function() {
  25144. this.renderer.scrollToX(this.session.getScrollLeft());
  25145. };
  25146. this.onCursorChange = function() {
  25147. this.$cursorChange();
  25148. if (!this.$blockScrolling) {
  25149. config.warn("Automatically scrolling cursor into view after selection change",
  25150. "this will be disabled in the next version",
  25151. "set editor.$blockScrolling = Infinity to disable this message"
  25152. );
  25153. this.renderer.scrollCursorIntoView();
  25154. }
  25155. this.$highlightBrackets();
  25156. this.$highlightTags();
  25157. this.$updateHighlightActiveLine();
  25158. this._signal("changeSelection");
  25159. };
  25160. this.$updateHighlightActiveLine = function() {
  25161. var session = this.getSession();
  25162. var highlight;
  25163. if (this.$highlightActiveLine) {
  25164. if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
  25165. highlight = this.getCursorPosition();
  25166. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  25167. highlight = false;
  25168. }
  25169. if (session.$highlightLineMarker && !highlight) {
  25170. session.removeMarker(session.$highlightLineMarker.id);
  25171. session.$highlightLineMarker = null;
  25172. } else if (!session.$highlightLineMarker && highlight) {
  25173. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  25174. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  25175. session.$highlightLineMarker = range;
  25176. } else if (highlight) {
  25177. session.$highlightLineMarker.start.row = highlight.row;
  25178. session.$highlightLineMarker.end.row = highlight.row;
  25179. session.$highlightLineMarker.start.column = highlight.column;
  25180. session._signal("changeBackMarker");
  25181. }
  25182. };
  25183. this.onSelectionChange = function(e) {
  25184. var session = this.session;
  25185. if (session.$selectionMarker) {
  25186. session.removeMarker(session.$selectionMarker);
  25187. }
  25188. session.$selectionMarker = null;
  25189. if (!this.selection.isEmpty()) {
  25190. var range = this.selection.getRange();
  25191. var style = this.getSelectionStyle();
  25192. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  25193. } else {
  25194. this.$updateHighlightActiveLine();
  25195. }
  25196. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  25197. this.session.highlight(re);
  25198. this._signal("changeSelection");
  25199. };
  25200. this.$getSelectionHighLightRegexp = function() {
  25201. var session = this.session;
  25202. var selection = this.getSelectionRange();
  25203. if (selection.isEmpty() || selection.isMultiLine())
  25204. return;
  25205. var startOuter = selection.start.column - 1;
  25206. var endOuter = selection.end.column + 1;
  25207. var line = session.getLine(selection.start.row);
  25208. var lineCols = line.length;
  25209. var needle = line.substring(Math.max(startOuter, 0),
  25210. Math.min(endOuter, lineCols));
  25211. if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
  25212. (endOuter <= lineCols && /[\w\d]$/.test(needle)))
  25213. return;
  25214. needle = line.substring(selection.start.column, selection.end.column);
  25215. if (!/^[\w\d]+$/.test(needle))
  25216. return;
  25217. var re = this.$search.$assembleRegExp({
  25218. wholeWord: true,
  25219. caseSensitive: true,
  25220. needle: needle
  25221. });
  25222. return re;
  25223. };
  25224. this.onChangeFrontMarker = function() {
  25225. this.renderer.updateFrontMarkers();
  25226. };
  25227. this.onChangeBackMarker = function() {
  25228. this.renderer.updateBackMarkers();
  25229. };
  25230. this.onChangeBreakpoint = function() {
  25231. this.renderer.updateBreakpoints();
  25232. };
  25233. this.onChangeAnnotation = function() {
  25234. this.renderer.setAnnotations(this.session.getAnnotations());
  25235. };
  25236. this.onChangeMode = function(e) {
  25237. this.renderer.updateText();
  25238. this._emit("changeMode", e);
  25239. };
  25240. this.onChangeWrapLimit = function() {
  25241. this.renderer.updateFull();
  25242. };
  25243. this.onChangeWrapMode = function() {
  25244. this.renderer.onResize(true);
  25245. };
  25246. this.onChangeFold = function() {
  25247. this.$updateHighlightActiveLine();
  25248. this.renderer.updateFull();
  25249. };
  25250. this.getSelectedText = function() {
  25251. return this.session.getTextRange(this.getSelectionRange());
  25252. };
  25253. this.getCopyText = function() {
  25254. var text = this.getSelectedText();
  25255. this._signal("copy", text);
  25256. return text;
  25257. };
  25258. this.onCopy = function() {
  25259. this.commands.exec("copy", this);
  25260. };
  25261. this.onCut = function() {
  25262. this.commands.exec("cut", this);
  25263. };
  25264. this.onPaste = function(text, event) {
  25265. var e = {text: text, event: event};
  25266. this.commands.exec("paste", this, e);
  25267. };
  25268. this.$handlePaste = function(e) {
  25269. if (typeof e == "string")
  25270. e = {text: e};
  25271. this._signal("paste", e);
  25272. var text = e.text;
  25273. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  25274. this.insert(text);
  25275. } else {
  25276. var lines = text.split(/\r\n|\r|\n/);
  25277. var ranges = this.selection.rangeList.ranges;
  25278. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  25279. return this.commands.exec("insertstring", this, text);
  25280. for (var i = ranges.length; i--;) {
  25281. var range = ranges[i];
  25282. if (!range.isEmpty())
  25283. this.session.remove(range);
  25284. this.session.insert(range.start, lines[i]);
  25285. }
  25286. }
  25287. };
  25288. this.execCommand = function(command, args) {
  25289. return this.commands.exec(command, this, args);
  25290. };
  25291. this.insert = function(text, pasted) {
  25292. var session = this.session;
  25293. var mode = session.getMode();
  25294. var cursor = this.getCursorPosition();
  25295. if (this.getBehavioursEnabled() && !pasted) {
  25296. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  25297. if (transform) {
  25298. if (text !== transform.text) {
  25299. this.session.mergeUndoDeltas = false;
  25300. this.$mergeNextCommand = false;
  25301. }
  25302. text = transform.text;
  25303. }
  25304. }
  25305. if (text == "\t")
  25306. text = this.session.getTabString();
  25307. if (!this.selection.isEmpty()) {
  25308. var range = this.getSelectionRange();
  25309. cursor = this.session.remove(range);
  25310. this.clearSelection();
  25311. }
  25312. else if (this.session.getOverwrite()) {
  25313. var range = new Range.fromPoints(cursor, cursor);
  25314. range.end.column += text.length;
  25315. this.session.remove(range);
  25316. }
  25317. if (text == "\n" || text == "\r\n") {
  25318. var line = session.getLine(cursor.row);
  25319. if (cursor.column > line.search(/\S|$/)) {
  25320. var d = line.substr(cursor.column).search(/\S|$/);
  25321. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  25322. }
  25323. }
  25324. this.clearSelection();
  25325. var start = cursor.column;
  25326. var lineState = session.getState(cursor.row);
  25327. var line = session.getLine(cursor.row);
  25328. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  25329. var end = session.insert(cursor, text);
  25330. if (transform && transform.selection) {
  25331. if (transform.selection.length == 2) { // Transform relative to the current column
  25332. this.selection.setSelectionRange(
  25333. new Range(cursor.row, start + transform.selection[0],
  25334. cursor.row, start + transform.selection[1]));
  25335. } else { // Transform relative to the current row.
  25336. this.selection.setSelectionRange(
  25337. new Range(cursor.row + transform.selection[0],
  25338. transform.selection[1],
  25339. cursor.row + transform.selection[2],
  25340. transform.selection[3]));
  25341. }
  25342. }
  25343. if (session.getDocument().isNewLine(text)) {
  25344. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  25345. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  25346. }
  25347. if (shouldOutdent)
  25348. mode.autoOutdent(lineState, session, cursor.row);
  25349. };
  25350. this.onTextInput = function(text) {
  25351. this.keyBinding.onTextInput(text);
  25352. };
  25353. this.onCommandKey = function(e, hashId, keyCode) {
  25354. this.keyBinding.onCommandKey(e, hashId, keyCode);
  25355. };
  25356. this.setOverwrite = function(overwrite) {
  25357. this.session.setOverwrite(overwrite);
  25358. };
  25359. this.getOverwrite = function() {
  25360. return this.session.getOverwrite();
  25361. };
  25362. this.toggleOverwrite = function() {
  25363. this.session.toggleOverwrite();
  25364. };
  25365. this.setScrollSpeed = function(speed) {
  25366. this.setOption("scrollSpeed", speed);
  25367. };
  25368. this.getScrollSpeed = function() {
  25369. return this.getOption("scrollSpeed");
  25370. };
  25371. this.setDragDelay = function(dragDelay) {
  25372. this.setOption("dragDelay", dragDelay);
  25373. };
  25374. this.getDragDelay = function() {
  25375. return this.getOption("dragDelay");
  25376. };
  25377. this.setSelectionStyle = function(val) {
  25378. this.setOption("selectionStyle", val);
  25379. };
  25380. this.getSelectionStyle = function() {
  25381. return this.getOption("selectionStyle");
  25382. };
  25383. this.setHighlightActiveLine = function(shouldHighlight) {
  25384. this.setOption("highlightActiveLine", shouldHighlight);
  25385. };
  25386. this.getHighlightActiveLine = function() {
  25387. return this.getOption("highlightActiveLine");
  25388. };
  25389. this.setHighlightGutterLine = function(shouldHighlight) {
  25390. this.setOption("highlightGutterLine", shouldHighlight);
  25391. };
  25392. this.getHighlightGutterLine = function() {
  25393. return this.getOption("highlightGutterLine");
  25394. };
  25395. this.setHighlightSelectedWord = function(shouldHighlight) {
  25396. this.setOption("highlightSelectedWord", shouldHighlight);
  25397. };
  25398. this.getHighlightSelectedWord = function() {
  25399. return this.$highlightSelectedWord;
  25400. };
  25401. this.setAnimatedScroll = function(shouldAnimate){
  25402. this.renderer.setAnimatedScroll(shouldAnimate);
  25403. };
  25404. this.getAnimatedScroll = function(){
  25405. return this.renderer.getAnimatedScroll();
  25406. };
  25407. this.setShowInvisibles = function(showInvisibles) {
  25408. this.renderer.setShowInvisibles(showInvisibles);
  25409. };
  25410. this.getShowInvisibles = function() {
  25411. return this.renderer.getShowInvisibles();
  25412. };
  25413. this.setDisplayIndentGuides = function(display) {
  25414. this.renderer.setDisplayIndentGuides(display);
  25415. };
  25416. this.getDisplayIndentGuides = function() {
  25417. return this.renderer.getDisplayIndentGuides();
  25418. };
  25419. this.setShowPrintMargin = function(showPrintMargin) {
  25420. this.renderer.setShowPrintMargin(showPrintMargin);
  25421. };
  25422. this.getShowPrintMargin = function() {
  25423. return this.renderer.getShowPrintMargin();
  25424. };
  25425. this.setPrintMarginColumn = function(showPrintMargin) {
  25426. this.renderer.setPrintMarginColumn(showPrintMargin);
  25427. };
  25428. this.getPrintMarginColumn = function() {
  25429. return this.renderer.getPrintMarginColumn();
  25430. };
  25431. this.setReadOnly = function(readOnly) {
  25432. this.setOption("readOnly", readOnly);
  25433. };
  25434. this.getReadOnly = function() {
  25435. return this.getOption("readOnly");
  25436. };
  25437. this.setBehavioursEnabled = function (enabled) {
  25438. this.setOption("behavioursEnabled", enabled);
  25439. };
  25440. this.getBehavioursEnabled = function () {
  25441. return this.getOption("behavioursEnabled");
  25442. };
  25443. this.setWrapBehavioursEnabled = function (enabled) {
  25444. this.setOption("wrapBehavioursEnabled", enabled);
  25445. };
  25446. this.getWrapBehavioursEnabled = function () {
  25447. return this.getOption("wrapBehavioursEnabled");
  25448. };
  25449. this.setShowFoldWidgets = function(show) {
  25450. this.setOption("showFoldWidgets", show);
  25451. };
  25452. this.getShowFoldWidgets = function() {
  25453. return this.getOption("showFoldWidgets");
  25454. };
  25455. this.setFadeFoldWidgets = function(fade) {
  25456. this.setOption("fadeFoldWidgets", fade);
  25457. };
  25458. this.getFadeFoldWidgets = function() {
  25459. return this.getOption("fadeFoldWidgets");
  25460. };
  25461. this.remove = function(dir) {
  25462. if (this.selection.isEmpty()){
  25463. if (dir == "left")
  25464. this.selection.selectLeft();
  25465. else
  25466. this.selection.selectRight();
  25467. }
  25468. var range = this.getSelectionRange();
  25469. if (this.getBehavioursEnabled()) {
  25470. var session = this.session;
  25471. var state = session.getState(range.start.row);
  25472. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  25473. if (range.end.column === 0) {
  25474. var text = session.getTextRange(range);
  25475. if (text[text.length - 1] == "\n") {
  25476. var line = session.getLine(range.end.row);
  25477. if (/^\s+$/.test(line)) {
  25478. range.end.column = line.length;
  25479. }
  25480. }
  25481. }
  25482. if (new_range)
  25483. range = new_range;
  25484. }
  25485. this.session.remove(range);
  25486. this.clearSelection();
  25487. };
  25488. this.removeWordRight = function() {
  25489. if (this.selection.isEmpty())
  25490. this.selection.selectWordRight();
  25491. this.session.remove(this.getSelectionRange());
  25492. this.clearSelection();
  25493. };
  25494. this.removeWordLeft = function() {
  25495. if (this.selection.isEmpty())
  25496. this.selection.selectWordLeft();
  25497. this.session.remove(this.getSelectionRange());
  25498. this.clearSelection();
  25499. };
  25500. this.removeToLineStart = function() {
  25501. if (this.selection.isEmpty())
  25502. this.selection.selectLineStart();
  25503. this.session.remove(this.getSelectionRange());
  25504. this.clearSelection();
  25505. };
  25506. this.removeToLineEnd = function() {
  25507. if (this.selection.isEmpty())
  25508. this.selection.selectLineEnd();
  25509. var range = this.getSelectionRange();
  25510. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  25511. range.end.column = 0;
  25512. range.end.row++;
  25513. }
  25514. this.session.remove(range);
  25515. this.clearSelection();
  25516. };
  25517. this.splitLine = function() {
  25518. if (!this.selection.isEmpty()) {
  25519. this.session.remove(this.getSelectionRange());
  25520. this.clearSelection();
  25521. }
  25522. var cursor = this.getCursorPosition();
  25523. this.insert("\n");
  25524. this.moveCursorToPosition(cursor);
  25525. };
  25526. this.transposeLetters = function() {
  25527. if (!this.selection.isEmpty()) {
  25528. return;
  25529. }
  25530. var cursor = this.getCursorPosition();
  25531. var column = cursor.column;
  25532. if (column === 0)
  25533. return;
  25534. var line = this.session.getLine(cursor.row);
  25535. var swap, range;
  25536. if (column < line.length) {
  25537. swap = line.charAt(column) + line.charAt(column-1);
  25538. range = new Range(cursor.row, column-1, cursor.row, column+1);
  25539. }
  25540. else {
  25541. swap = line.charAt(column-1) + line.charAt(column-2);
  25542. range = new Range(cursor.row, column-2, cursor.row, column);
  25543. }
  25544. this.session.replace(range, swap);
  25545. };
  25546. this.toLowerCase = function() {
  25547. var originalRange = this.getSelectionRange();
  25548. if (this.selection.isEmpty()) {
  25549. this.selection.selectWord();
  25550. }
  25551. var range = this.getSelectionRange();
  25552. var text = this.session.getTextRange(range);
  25553. this.session.replace(range, text.toLowerCase());
  25554. this.selection.setSelectionRange(originalRange);
  25555. };
  25556. this.toUpperCase = function() {
  25557. var originalRange = this.getSelectionRange();
  25558. if (this.selection.isEmpty()) {
  25559. this.selection.selectWord();
  25560. }
  25561. var range = this.getSelectionRange();
  25562. var text = this.session.getTextRange(range);
  25563. this.session.replace(range, text.toUpperCase());
  25564. this.selection.setSelectionRange(originalRange);
  25565. };
  25566. this.indent = function() {
  25567. var session = this.session;
  25568. var range = this.getSelectionRange();
  25569. if (range.start.row < range.end.row) {
  25570. var rows = this.$getSelectedRows();
  25571. session.indentRows(rows.first, rows.last, "\t");
  25572. return;
  25573. } else if (range.start.column < range.end.column) {
  25574. var text = session.getTextRange(range);
  25575. if (!/^\s+$/.test(text)) {
  25576. var rows = this.$getSelectedRows();
  25577. session.indentRows(rows.first, rows.last, "\t");
  25578. return;
  25579. }
  25580. }
  25581. var line = session.getLine(range.start.row);
  25582. var position = range.start;
  25583. var size = session.getTabSize();
  25584. var column = session.documentToScreenColumn(position.row, position.column);
  25585. if (this.session.getUseSoftTabs()) {
  25586. var count = (size - column % size);
  25587. var indentString = lang.stringRepeat(" ", count);
  25588. } else {
  25589. var count = column % size;
  25590. while (line[range.start.column] == " " && count) {
  25591. range.start.column--;
  25592. count--;
  25593. }
  25594. this.selection.setSelectionRange(range);
  25595. indentString = "\t";
  25596. }
  25597. return this.insert(indentString);
  25598. };
  25599. this.blockIndent = function() {
  25600. var rows = this.$getSelectedRows();
  25601. this.session.indentRows(rows.first, rows.last, "\t");
  25602. };
  25603. this.blockOutdent = function() {
  25604. var selection = this.session.getSelection();
  25605. this.session.outdentRows(selection.getRange());
  25606. };
  25607. this.sortLines = function() {
  25608. var rows = this.$getSelectedRows();
  25609. var session = this.session;
  25610. var lines = [];
  25611. for (i = rows.first; i <= rows.last; i++)
  25612. lines.push(session.getLine(i));
  25613. lines.sort(function(a, b) {
  25614. if (a.toLowerCase() < b.toLowerCase()) return -1;
  25615. if (a.toLowerCase() > b.toLowerCase()) return 1;
  25616. return 0;
  25617. });
  25618. var deleteRange = new Range(0, 0, 0, 0);
  25619. for (var i = rows.first; i <= rows.last; i++) {
  25620. var line = session.getLine(i);
  25621. deleteRange.start.row = i;
  25622. deleteRange.end.row = i;
  25623. deleteRange.end.column = line.length;
  25624. session.replace(deleteRange, lines[i-rows.first]);
  25625. }
  25626. };
  25627. this.toggleCommentLines = function() {
  25628. var state = this.session.getState(this.getCursorPosition().row);
  25629. var rows = this.$getSelectedRows();
  25630. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  25631. };
  25632. this.toggleBlockComment = function() {
  25633. var cursor = this.getCursorPosition();
  25634. var state = this.session.getState(cursor.row);
  25635. var range = this.getSelectionRange();
  25636. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  25637. };
  25638. this.getNumberAt = function(row, column) {
  25639. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  25640. _numberRx.lastIndex = 0;
  25641. var s = this.session.getLine(row);
  25642. while (_numberRx.lastIndex < column) {
  25643. var m = _numberRx.exec(s);
  25644. if(m.index <= column && m.index+m[0].length >= column){
  25645. var number = {
  25646. value: m[0],
  25647. start: m.index,
  25648. end: m.index+m[0].length
  25649. };
  25650. return number;
  25651. }
  25652. }
  25653. return null;
  25654. };
  25655. this.modifyNumber = function(amount) {
  25656. var row = this.selection.getCursor().row;
  25657. var column = this.selection.getCursor().column;
  25658. var charRange = new Range(row, column-1, row, column);
  25659. var c = this.session.getTextRange(charRange);
  25660. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  25661. var nr = this.getNumberAt(row, column);
  25662. if (nr) {
  25663. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  25664. var decimals = nr.start + nr.value.length - fp;
  25665. var t = parseFloat(nr.value);
  25666. t *= Math.pow(10, decimals);
  25667. if(fp !== nr.end && column < fp){
  25668. amount *= Math.pow(10, nr.end - column - 1);
  25669. } else {
  25670. amount *= Math.pow(10, nr.end - column);
  25671. }
  25672. t += amount;
  25673. t /= Math.pow(10, decimals);
  25674. var nnr = t.toFixed(decimals);
  25675. var replaceRange = new Range(row, nr.start, row, nr.end);
  25676. this.session.replace(replaceRange, nnr);
  25677. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  25678. }
  25679. }
  25680. };
  25681. this.removeLines = function() {
  25682. var rows = this.$getSelectedRows();
  25683. this.session.removeFullLines(rows.first, rows.last);
  25684. this.clearSelection();
  25685. };
  25686. this.duplicateSelection = function() {
  25687. var sel = this.selection;
  25688. var doc = this.session;
  25689. var range = sel.getRange();
  25690. var reverse = sel.isBackwards();
  25691. if (range.isEmpty()) {
  25692. var row = range.start.row;
  25693. doc.duplicateLines(row, row);
  25694. } else {
  25695. var point = reverse ? range.start : range.end;
  25696. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  25697. range.start = point;
  25698. range.end = endPoint;
  25699. sel.setSelectionRange(range, reverse);
  25700. }
  25701. };
  25702. this.moveLinesDown = function() {
  25703. this.$moveLines(1, false);
  25704. };
  25705. this.moveLinesUp = function() {
  25706. this.$moveLines(-1, false);
  25707. };
  25708. this.moveText = function(range, toPosition, copy) {
  25709. return this.session.moveText(range, toPosition, copy);
  25710. };
  25711. this.copyLinesUp = function() {
  25712. this.$moveLines(-1, true);
  25713. };
  25714. this.copyLinesDown = function() {
  25715. this.$moveLines(1, true);
  25716. };
  25717. this.$moveLines = function(dir, copy) {
  25718. var rows, moved;
  25719. var selection = this.selection;
  25720. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  25721. var range = selection.toOrientedRange();
  25722. rows = this.$getSelectedRows(range);
  25723. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  25724. if (copy && dir == -1) moved = 0;
  25725. range.moveBy(moved, 0);
  25726. selection.fromOrientedRange(range);
  25727. } else {
  25728. var ranges = selection.rangeList.ranges;
  25729. selection.rangeList.detach(this.session);
  25730. this.inVirtualSelectionMode = true;
  25731. var diff = 0;
  25732. var totalDiff = 0;
  25733. var l = ranges.length;
  25734. for (var i = 0; i < l; i++) {
  25735. var rangeIndex = i;
  25736. ranges[i].moveBy(diff, 0);
  25737. rows = this.$getSelectedRows(ranges[i]);
  25738. var first = rows.first;
  25739. var last = rows.last;
  25740. while (++i < l) {
  25741. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  25742. var subRows = this.$getSelectedRows(ranges[i]);
  25743. if (copy && subRows.first != last)
  25744. break;
  25745. else if (!copy && subRows.first > last + 1)
  25746. break;
  25747. last = subRows.last;
  25748. }
  25749. i--;
  25750. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  25751. if (copy && dir == -1) rangeIndex = i + 1;
  25752. while (rangeIndex <= i) {
  25753. ranges[rangeIndex].moveBy(diff, 0);
  25754. rangeIndex++;
  25755. }
  25756. if (!copy) diff = 0;
  25757. totalDiff += diff;
  25758. }
  25759. selection.fromOrientedRange(selection.ranges[0]);
  25760. selection.rangeList.attach(this.session);
  25761. this.inVirtualSelectionMode = false;
  25762. }
  25763. };
  25764. this.$getSelectedRows = function(range) {
  25765. range = (range || this.getSelectionRange()).collapseRows();
  25766. return {
  25767. first: this.session.getRowFoldStart(range.start.row),
  25768. last: this.session.getRowFoldEnd(range.end.row)
  25769. };
  25770. };
  25771. this.onCompositionStart = function(text) {
  25772. this.renderer.showComposition(this.getCursorPosition());
  25773. };
  25774. this.onCompositionUpdate = function(text) {
  25775. this.renderer.setCompositionText(text);
  25776. };
  25777. this.onCompositionEnd = function() {
  25778. this.renderer.hideComposition();
  25779. };
  25780. this.getFirstVisibleRow = function() {
  25781. return this.renderer.getFirstVisibleRow();
  25782. };
  25783. this.getLastVisibleRow = function() {
  25784. return this.renderer.getLastVisibleRow();
  25785. };
  25786. this.isRowVisible = function(row) {
  25787. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  25788. };
  25789. this.isRowFullyVisible = function(row) {
  25790. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  25791. };
  25792. this.$getVisibleRowCount = function() {
  25793. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  25794. };
  25795. this.$moveByPage = function(dir, select) {
  25796. var renderer = this.renderer;
  25797. var config = this.renderer.layerConfig;
  25798. var rows = dir * Math.floor(config.height / config.lineHeight);
  25799. this.$blockScrolling++;
  25800. if (select === true) {
  25801. this.selection.$moveSelection(function(){
  25802. this.moveCursorBy(rows, 0);
  25803. });
  25804. } else if (select === false) {
  25805. this.selection.moveCursorBy(rows, 0);
  25806. this.selection.clearSelection();
  25807. }
  25808. this.$blockScrolling--;
  25809. var scrollTop = renderer.scrollTop;
  25810. renderer.scrollBy(0, rows * config.lineHeight);
  25811. if (select != null)
  25812. renderer.scrollCursorIntoView(null, 0.5);
  25813. renderer.animateScrolling(scrollTop);
  25814. };
  25815. this.selectPageDown = function() {
  25816. this.$moveByPage(1, true);
  25817. };
  25818. this.selectPageUp = function() {
  25819. this.$moveByPage(-1, true);
  25820. };
  25821. this.gotoPageDown = function() {
  25822. this.$moveByPage(1, false);
  25823. };
  25824. this.gotoPageUp = function() {
  25825. this.$moveByPage(-1, false);
  25826. };
  25827. this.scrollPageDown = function() {
  25828. this.$moveByPage(1);
  25829. };
  25830. this.scrollPageUp = function() {
  25831. this.$moveByPage(-1);
  25832. };
  25833. this.scrollToRow = function(row) {
  25834. this.renderer.scrollToRow(row);
  25835. };
  25836. this.scrollToLine = function(line, center, animate, callback) {
  25837. this.renderer.scrollToLine(line, center, animate, callback);
  25838. };
  25839. this.centerSelection = function() {
  25840. var range = this.getSelectionRange();
  25841. var pos = {
  25842. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  25843. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  25844. };
  25845. this.renderer.alignCursor(pos, 0.5);
  25846. };
  25847. this.getCursorPosition = function() {
  25848. return this.selection.getCursor();
  25849. };
  25850. this.getCursorPositionScreen = function() {
  25851. return this.session.documentToScreenPosition(this.getCursorPosition());
  25852. };
  25853. this.getSelectionRange = function() {
  25854. return this.selection.getRange();
  25855. };
  25856. this.selectAll = function() {
  25857. this.$blockScrolling += 1;
  25858. this.selection.selectAll();
  25859. this.$blockScrolling -= 1;
  25860. };
  25861. this.clearSelection = function() {
  25862. this.selection.clearSelection();
  25863. };
  25864. this.moveCursorTo = function(row, column) {
  25865. this.selection.moveCursorTo(row, column);
  25866. };
  25867. this.moveCursorToPosition = function(pos) {
  25868. this.selection.moveCursorToPosition(pos);
  25869. };
  25870. this.jumpToMatching = function(select, expand) {
  25871. var cursor = this.getCursorPosition();
  25872. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  25873. var prevToken = iterator.getCurrentToken();
  25874. var token = prevToken || iterator.stepForward();
  25875. if (!token) return;
  25876. var matchType;
  25877. var found = false;
  25878. var depth = {};
  25879. var i = cursor.column - token.start;
  25880. var bracketType;
  25881. var brackets = {
  25882. ")": "(",
  25883. "(": "(",
  25884. "]": "[",
  25885. "[": "[",
  25886. "{": "{",
  25887. "}": "{"
  25888. };
  25889. do {
  25890. if (token.value.match(/[{}()\[\]]/g)) {
  25891. for (; i < token.value.length && !found; i++) {
  25892. if (!brackets[token.value[i]]) {
  25893. continue;
  25894. }
  25895. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  25896. if (isNaN(depth[bracketType])) {
  25897. depth[bracketType] = 0;
  25898. }
  25899. switch (token.value[i]) {
  25900. case '(':
  25901. case '[':
  25902. case '{':
  25903. depth[bracketType]++;
  25904. break;
  25905. case ')':
  25906. case ']':
  25907. case '}':
  25908. depth[bracketType]--;
  25909. if (depth[bracketType] === -1) {
  25910. matchType = 'bracket';
  25911. found = true;
  25912. }
  25913. break;
  25914. }
  25915. }
  25916. }
  25917. else if (token && token.type.indexOf('tag-name') !== -1) {
  25918. if (isNaN(depth[token.value])) {
  25919. depth[token.value] = 0;
  25920. }
  25921. if (prevToken.value === '<') {
  25922. depth[token.value]++;
  25923. }
  25924. else if (prevToken.value === '</') {
  25925. depth[token.value]--;
  25926. }
  25927. if (depth[token.value] === -1) {
  25928. matchType = 'tag';
  25929. found = true;
  25930. }
  25931. }
  25932. if (!found) {
  25933. prevToken = token;
  25934. token = iterator.stepForward();
  25935. i = 0;
  25936. }
  25937. } while (token && !found);
  25938. if (!matchType)
  25939. return;
  25940. var range, pos;
  25941. if (matchType === 'bracket') {
  25942. range = this.session.getBracketRange(cursor);
  25943. if (!range) {
  25944. range = new Range(
  25945. iterator.getCurrentTokenRow(),
  25946. iterator.getCurrentTokenColumn() + i - 1,
  25947. iterator.getCurrentTokenRow(),
  25948. iterator.getCurrentTokenColumn() + i - 1
  25949. );
  25950. pos = range.start;
  25951. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  25952. range = this.session.getBracketRange(pos);
  25953. }
  25954. }
  25955. else if (matchType === 'tag') {
  25956. if (token && token.type.indexOf('tag-name') !== -1)
  25957. var tag = token.value;
  25958. else
  25959. return;
  25960. range = new Range(
  25961. iterator.getCurrentTokenRow(),
  25962. iterator.getCurrentTokenColumn() - 2,
  25963. iterator.getCurrentTokenRow(),
  25964. iterator.getCurrentTokenColumn() - 2
  25965. );
  25966. if (range.compare(cursor.row, cursor.column) === 0) {
  25967. found = false;
  25968. do {
  25969. token = prevToken;
  25970. prevToken = iterator.stepBackward();
  25971. if (prevToken) {
  25972. if (prevToken.type.indexOf('tag-close') !== -1) {
  25973. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  25974. }
  25975. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  25976. if (prevToken.value === '<') {
  25977. depth[tag]++;
  25978. }
  25979. else if (prevToken.value === '</') {
  25980. depth[tag]--;
  25981. }
  25982. if (depth[tag] === 0)
  25983. found = true;
  25984. }
  25985. }
  25986. } while (prevToken && !found);
  25987. }
  25988. if (token && token.type.indexOf('tag-name')) {
  25989. pos = range.start;
  25990. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  25991. pos = range.end;
  25992. }
  25993. }
  25994. pos = range && range.cursor || pos;
  25995. if (pos) {
  25996. if (select) {
  25997. if (range && expand) {
  25998. this.selection.setRange(range);
  25999. } else if (range && range.isEqual(this.getSelectionRange())) {
  26000. this.clearSelection();
  26001. } else {
  26002. this.selection.selectTo(pos.row, pos.column);
  26003. }
  26004. } else {
  26005. this.selection.moveTo(pos.row, pos.column);
  26006. }
  26007. }
  26008. };
  26009. this.gotoLine = function(lineNumber, column, animate) {
  26010. this.selection.clearSelection();
  26011. this.session.unfold({row: lineNumber - 1, column: column || 0});
  26012. this.$blockScrolling += 1;
  26013. this.exitMultiSelectMode && this.exitMultiSelectMode();
  26014. this.moveCursorTo(lineNumber - 1, column || 0);
  26015. this.$blockScrolling -= 1;
  26016. if (!this.isRowFullyVisible(lineNumber - 1))
  26017. this.scrollToLine(lineNumber - 1, true, animate);
  26018. };
  26019. this.navigateTo = function(row, column) {
  26020. this.selection.moveTo(row, column);
  26021. };
  26022. this.navigateUp = function(times) {
  26023. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  26024. var selectionStart = this.selection.anchor.getPosition();
  26025. return this.moveCursorToPosition(selectionStart);
  26026. }
  26027. this.selection.clearSelection();
  26028. this.selection.moveCursorBy(-times || -1, 0);
  26029. };
  26030. this.navigateDown = function(times) {
  26031. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  26032. var selectionEnd = this.selection.anchor.getPosition();
  26033. return this.moveCursorToPosition(selectionEnd);
  26034. }
  26035. this.selection.clearSelection();
  26036. this.selection.moveCursorBy(times || 1, 0);
  26037. };
  26038. this.navigateLeft = function(times) {
  26039. if (!this.selection.isEmpty()) {
  26040. var selectionStart = this.getSelectionRange().start;
  26041. this.moveCursorToPosition(selectionStart);
  26042. }
  26043. else {
  26044. times = times || 1;
  26045. while (times--) {
  26046. this.selection.moveCursorLeft();
  26047. }
  26048. }
  26049. this.clearSelection();
  26050. };
  26051. this.navigateRight = function(times) {
  26052. if (!this.selection.isEmpty()) {
  26053. var selectionEnd = this.getSelectionRange().end;
  26054. this.moveCursorToPosition(selectionEnd);
  26055. }
  26056. else {
  26057. times = times || 1;
  26058. while (times--) {
  26059. this.selection.moveCursorRight();
  26060. }
  26061. }
  26062. this.clearSelection();
  26063. };
  26064. this.navigateLineStart = function() {
  26065. this.selection.moveCursorLineStart();
  26066. this.clearSelection();
  26067. };
  26068. this.navigateLineEnd = function() {
  26069. this.selection.moveCursorLineEnd();
  26070. this.clearSelection();
  26071. };
  26072. this.navigateFileEnd = function() {
  26073. this.selection.moveCursorFileEnd();
  26074. this.clearSelection();
  26075. };
  26076. this.navigateFileStart = function() {
  26077. this.selection.moveCursorFileStart();
  26078. this.clearSelection();
  26079. };
  26080. this.navigateWordRight = function() {
  26081. this.selection.moveCursorWordRight();
  26082. this.clearSelection();
  26083. };
  26084. this.navigateWordLeft = function() {
  26085. this.selection.moveCursorWordLeft();
  26086. this.clearSelection();
  26087. };
  26088. this.replace = function(replacement, options) {
  26089. if (options)
  26090. this.$search.set(options);
  26091. var range = this.$search.find(this.session);
  26092. var replaced = 0;
  26093. if (!range)
  26094. return replaced;
  26095. if (this.$tryReplace(range, replacement)) {
  26096. replaced = 1;
  26097. }
  26098. if (range !== null) {
  26099. this.selection.setSelectionRange(range);
  26100. this.renderer.scrollSelectionIntoView(range.start, range.end);
  26101. }
  26102. return replaced;
  26103. };
  26104. this.replaceAll = function(replacement, options) {
  26105. if (options) {
  26106. this.$search.set(options);
  26107. }
  26108. var ranges = this.$search.findAll(this.session);
  26109. var replaced = 0;
  26110. if (!ranges.length)
  26111. return replaced;
  26112. this.$blockScrolling += 1;
  26113. var selection = this.getSelectionRange();
  26114. this.selection.moveTo(0, 0);
  26115. for (var i = ranges.length - 1; i >= 0; --i) {
  26116. if(this.$tryReplace(ranges[i], replacement)) {
  26117. replaced++;
  26118. }
  26119. }
  26120. this.selection.setSelectionRange(selection);
  26121. this.$blockScrolling -= 1;
  26122. return replaced;
  26123. };
  26124. this.$tryReplace = function(range, replacement) {
  26125. var input = this.session.getTextRange(range);
  26126. replacement = this.$search.replace(input, replacement);
  26127. if (replacement !== null) {
  26128. range.end = this.session.replace(range, replacement);
  26129. return range;
  26130. } else {
  26131. return null;
  26132. }
  26133. };
  26134. this.getLastSearchOptions = function() {
  26135. return this.$search.getOptions();
  26136. };
  26137. this.find = function(needle, options, animate) {
  26138. if (!options)
  26139. options = {};
  26140. if (typeof needle == "string" || needle instanceof RegExp)
  26141. options.needle = needle;
  26142. else if (typeof needle == "object")
  26143. oop.mixin(options, needle);
  26144. var range = this.selection.getRange();
  26145. if (options.needle == null) {
  26146. needle = this.session.getTextRange(range)
  26147. || this.$search.$options.needle;
  26148. if (!needle) {
  26149. range = this.session.getWordRange(range.start.row, range.start.column);
  26150. needle = this.session.getTextRange(range);
  26151. }
  26152. this.$search.set({needle: needle});
  26153. }
  26154. this.$search.set(options);
  26155. if (!options.start)
  26156. this.$search.set({start: range});
  26157. var newRange = this.$search.find(this.session);
  26158. if (options.preventScroll)
  26159. return newRange;
  26160. if (newRange) {
  26161. this.revealRange(newRange, animate);
  26162. return newRange;
  26163. }
  26164. if (options.backwards)
  26165. range.start = range.end;
  26166. else
  26167. range.end = range.start;
  26168. this.selection.setRange(range);
  26169. };
  26170. this.findNext = function(options, animate) {
  26171. this.find({skipCurrent: true, backwards: false}, options, animate);
  26172. };
  26173. this.findPrevious = function(options, animate) {
  26174. this.find(options, {skipCurrent: true, backwards: true}, animate);
  26175. };
  26176. this.revealRange = function(range, animate) {
  26177. this.$blockScrolling += 1;
  26178. this.session.unfold(range);
  26179. this.selection.setSelectionRange(range);
  26180. this.$blockScrolling -= 1;
  26181. var scrollTop = this.renderer.scrollTop;
  26182. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  26183. if (animate !== false)
  26184. this.renderer.animateScrolling(scrollTop);
  26185. };
  26186. this.undo = function() {
  26187. this.$blockScrolling++;
  26188. this.session.getUndoManager().undo();
  26189. this.$blockScrolling--;
  26190. this.renderer.scrollCursorIntoView(null, 0.5);
  26191. };
  26192. this.redo = function() {
  26193. this.$blockScrolling++;
  26194. this.session.getUndoManager().redo();
  26195. this.$blockScrolling--;
  26196. this.renderer.scrollCursorIntoView(null, 0.5);
  26197. };
  26198. this.destroy = function() {
  26199. this.renderer.destroy();
  26200. this._signal("destroy", this);
  26201. if (this.session) {
  26202. this.session.destroy();
  26203. }
  26204. };
  26205. this.setAutoScrollEditorIntoView = function(enable) {
  26206. if (!enable)
  26207. return;
  26208. var rect;
  26209. var self = this;
  26210. var shouldScroll = false;
  26211. if (!this.$scrollAnchor)
  26212. this.$scrollAnchor = document.createElement("div");
  26213. var scrollAnchor = this.$scrollAnchor;
  26214. scrollAnchor.style.cssText = "position:absolute";
  26215. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  26216. var onChangeSelection = this.on("changeSelection", function() {
  26217. shouldScroll = true;
  26218. });
  26219. var onBeforeRender = this.renderer.on("beforeRender", function() {
  26220. if (shouldScroll)
  26221. rect = self.renderer.container.getBoundingClientRect();
  26222. });
  26223. var onAfterRender = this.renderer.on("afterRender", function() {
  26224. if (shouldScroll && rect && (self.isFocused()
  26225. || self.searchBox && self.searchBox.isFocused())
  26226. ) {
  26227. var renderer = self.renderer;
  26228. var pos = renderer.$cursorLayer.$pixelPos;
  26229. var config = renderer.layerConfig;
  26230. var top = pos.top - config.offset;
  26231. if (pos.top >= 0 && top + rect.top < 0) {
  26232. shouldScroll = true;
  26233. } else if (pos.top < config.height &&
  26234. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  26235. shouldScroll = false;
  26236. } else {
  26237. shouldScroll = null;
  26238. }
  26239. if (shouldScroll != null) {
  26240. scrollAnchor.style.top = top + "px";
  26241. scrollAnchor.style.left = pos.left + "px";
  26242. scrollAnchor.style.height = config.lineHeight + "px";
  26243. scrollAnchor.scrollIntoView(shouldScroll);
  26244. }
  26245. shouldScroll = rect = null;
  26246. }
  26247. });
  26248. this.setAutoScrollEditorIntoView = function(enable) {
  26249. if (enable)
  26250. return;
  26251. delete this.setAutoScrollEditorIntoView;
  26252. this.off("changeSelection", onChangeSelection);
  26253. this.renderer.off("afterRender", onAfterRender);
  26254. this.renderer.off("beforeRender", onBeforeRender);
  26255. };
  26256. };
  26257. this.$resetCursorStyle = function() {
  26258. var style = this.$cursorStyle || "ace";
  26259. var cursorLayer = this.renderer.$cursorLayer;
  26260. if (!cursorLayer)
  26261. return;
  26262. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  26263. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  26264. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  26265. };
  26266. }).call(Editor.prototype);
  26267. config.defineOptions(Editor.prototype, "editor", {
  26268. selectionStyle: {
  26269. set: function(style) {
  26270. this.onSelectionChange();
  26271. this._signal("changeSelectionStyle", {data: style});
  26272. },
  26273. initialValue: "line"
  26274. },
  26275. highlightActiveLine: {
  26276. set: function() {this.$updateHighlightActiveLine();},
  26277. initialValue: true
  26278. },
  26279. highlightSelectedWord: {
  26280. set: function(shouldHighlight) {this.$onSelectionChange();},
  26281. initialValue: true
  26282. },
  26283. readOnly: {
  26284. set: function(readOnly) {
  26285. this.$resetCursorStyle();
  26286. },
  26287. initialValue: false
  26288. },
  26289. cursorStyle: {
  26290. set: function(val) { this.$resetCursorStyle(); },
  26291. values: ["ace", "slim", "smooth", "wide"],
  26292. initialValue: "ace"
  26293. },
  26294. mergeUndoDeltas: {
  26295. values: [false, true, "always"],
  26296. initialValue: true
  26297. },
  26298. behavioursEnabled: {initialValue: true},
  26299. wrapBehavioursEnabled: {initialValue: true},
  26300. autoScrollEditorIntoView: {
  26301. set: function(val) {this.setAutoScrollEditorIntoView(val)}
  26302. },
  26303. keyboardHandler: {
  26304. set: function(val) { this.setKeyboardHandler(val); },
  26305. get: function() { return this.keybindingId; },
  26306. handlesSet: true
  26307. },
  26308. hScrollBarAlwaysVisible: "renderer",
  26309. vScrollBarAlwaysVisible: "renderer",
  26310. highlightGutterLine: "renderer",
  26311. animatedScroll: "renderer",
  26312. showInvisibles: "renderer",
  26313. showPrintMargin: "renderer",
  26314. printMarginColumn: "renderer",
  26315. printMargin: "renderer",
  26316. fadeFoldWidgets: "renderer",
  26317. showFoldWidgets: "renderer",
  26318. showLineNumbers: "renderer",
  26319. showGutter: "renderer",
  26320. displayIndentGuides: "renderer",
  26321. fontSize: "renderer",
  26322. fontFamily: "renderer",
  26323. maxLines: "renderer",
  26324. minLines: "renderer",
  26325. scrollPastEnd: "renderer",
  26326. fixedWidthGutter: "renderer",
  26327. theme: "renderer",
  26328. scrollSpeed: "$mouseHandler",
  26329. dragDelay: "$mouseHandler",
  26330. dragEnabled: "$mouseHandler",
  26331. focusTimout: "$mouseHandler",
  26332. tooltipFollowsMouse: "$mouseHandler",
  26333. firstLineNumber: "session",
  26334. overwrite: "session",
  26335. newLineMode: "session",
  26336. useWorker: "session",
  26337. useSoftTabs: "session",
  26338. tabSize: "session",
  26339. wrap: "session",
  26340. indentedSoftWrap: "session",
  26341. foldStyle: "session",
  26342. mode: "session"
  26343. });
  26344. exports.Editor = Editor;
  26345. });
  26346. ace.define("ace/undomanager",["require","exports","module"], function(acequire, exports, module) {
  26347. "use strict";
  26348. var UndoManager = function() {
  26349. this.reset();
  26350. };
  26351. (function() {
  26352. this.execute = function(options) {
  26353. var deltaSets = options.args[0];
  26354. this.$doc = options.args[1];
  26355. if (options.merge && this.hasUndo()){
  26356. this.dirtyCounter--;
  26357. deltaSets = this.$undoStack.pop().concat(deltaSets);
  26358. }
  26359. this.$undoStack.push(deltaSets);
  26360. this.$redoStack = [];
  26361. if (this.dirtyCounter < 0) {
  26362. this.dirtyCounter = NaN;
  26363. }
  26364. this.dirtyCounter++;
  26365. };
  26366. this.undo = function(dontSelect) {
  26367. var deltaSets = this.$undoStack.pop();
  26368. var undoSelectionRange = null;
  26369. if (deltaSets) {
  26370. undoSelectionRange = this.$doc.undoChanges(deltaSets, dontSelect);
  26371. this.$redoStack.push(deltaSets);
  26372. this.dirtyCounter--;
  26373. }
  26374. return undoSelectionRange;
  26375. };
  26376. this.redo = function(dontSelect) {
  26377. var deltaSets = this.$redoStack.pop();
  26378. var redoSelectionRange = null;
  26379. if (deltaSets) {
  26380. redoSelectionRange =
  26381. this.$doc.redoChanges(this.$deserializeDeltas(deltaSets), dontSelect);
  26382. this.$undoStack.push(deltaSets);
  26383. this.dirtyCounter++;
  26384. }
  26385. return redoSelectionRange;
  26386. };
  26387. this.reset = function() {
  26388. this.$undoStack = [];
  26389. this.$redoStack = [];
  26390. this.dirtyCounter = 0;
  26391. };
  26392. this.hasUndo = function() {
  26393. return this.$undoStack.length > 0;
  26394. };
  26395. this.hasRedo = function() {
  26396. return this.$redoStack.length > 0;
  26397. };
  26398. this.markClean = function() {
  26399. this.dirtyCounter = 0;
  26400. };
  26401. this.isClean = function() {
  26402. return this.dirtyCounter === 0;
  26403. };
  26404. this.$serializeDeltas = function(deltaSets) {
  26405. return cloneDeltaSetsObj(deltaSets, $serializeDelta);
  26406. };
  26407. this.$deserializeDeltas = function(deltaSets) {
  26408. return cloneDeltaSetsObj(deltaSets, $deserializeDelta);
  26409. };
  26410. function $serializeDelta(delta){
  26411. return {
  26412. action: delta.action,
  26413. start: delta.start,
  26414. end: delta.end,
  26415. lines: delta.lines.length == 1 ? null : delta.lines,
  26416. text: delta.lines.length == 1 ? delta.lines[0] : null
  26417. };
  26418. }
  26419. function $deserializeDelta(delta) {
  26420. return {
  26421. action: delta.action,
  26422. start: delta.start,
  26423. end: delta.end,
  26424. lines: delta.lines || [delta.text]
  26425. };
  26426. }
  26427. function cloneDeltaSetsObj(deltaSets_old, fnGetModifiedDelta) {
  26428. var deltaSets_new = new Array(deltaSets_old.length);
  26429. for (var i = 0; i < deltaSets_old.length; i++) {
  26430. var deltaSet_old = deltaSets_old[i];
  26431. var deltaSet_new = { group: deltaSet_old.group, deltas: new Array(deltaSet_old.length)};
  26432. for (var j = 0; j < deltaSet_old.deltas.length; j++) {
  26433. var delta_old = deltaSet_old.deltas[j];
  26434. deltaSet_new.deltas[j] = fnGetModifiedDelta(delta_old);
  26435. }
  26436. deltaSets_new[i] = deltaSet_new;
  26437. }
  26438. return deltaSets_new;
  26439. }
  26440. }).call(UndoManager.prototype);
  26441. exports.UndoManager = UndoManager;
  26442. });
  26443. ace.define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter"], function(acequire, exports, module) {
  26444. "use strict";
  26445. var dom = acequire("../lib/dom");
  26446. var oop = acequire("../lib/oop");
  26447. var lang = acequire("../lib/lang");
  26448. var EventEmitter = acequire("../lib/event_emitter").EventEmitter;
  26449. var Gutter = function(parentEl) {
  26450. this.element = dom.createElement("div");
  26451. this.element.className = "ace_layer ace_gutter-layer";
  26452. parentEl.appendChild(this.element);
  26453. this.setShowFoldWidgets(this.$showFoldWidgets);
  26454. this.gutterWidth = 0;
  26455. this.$annotations = [];
  26456. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  26457. this.$cells = [];
  26458. };
  26459. (function() {
  26460. oop.implement(this, EventEmitter);
  26461. this.setSession = function(session) {
  26462. if (this.session)
  26463. this.session.removeEventListener("change", this.$updateAnnotations);
  26464. this.session = session;
  26465. if (session)
  26466. session.on("change", this.$updateAnnotations);
  26467. };
  26468. this.addGutterDecoration = function(row, className){
  26469. if (window.console)
  26470. console.warn && console.warn("deprecated use session.addGutterDecoration");
  26471. this.session.addGutterDecoration(row, className);
  26472. };
  26473. this.removeGutterDecoration = function(row, className){
  26474. if (window.console)
  26475. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  26476. this.session.removeGutterDecoration(row, className);
  26477. };
  26478. this.setAnnotations = function(annotations) {
  26479. this.$annotations = [];
  26480. for (var i = 0; i < annotations.length; i++) {
  26481. var annotation = annotations[i];
  26482. var row = annotation.row;
  26483. var rowInfo = this.$annotations[row];
  26484. if (!rowInfo)
  26485. rowInfo = this.$annotations[row] = {text: []};
  26486. var annoText = annotation.text;
  26487. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  26488. if (rowInfo.text.indexOf(annoText) === -1)
  26489. rowInfo.text.push(annoText);
  26490. var type = annotation.type;
  26491. if (type == "error")
  26492. rowInfo.className = " ace_error";
  26493. else if (type == "warning" && rowInfo.className != " ace_error")
  26494. rowInfo.className = " ace_warning";
  26495. else if (type == "info" && (!rowInfo.className))
  26496. rowInfo.className = " ace_info";
  26497. }
  26498. };
  26499. this.$updateAnnotations = function (delta) {
  26500. if (!this.$annotations.length)
  26501. return;
  26502. var firstRow = delta.start.row;
  26503. var len = delta.end.row - firstRow;
  26504. if (len === 0) {
  26505. } else if (delta.action == 'remove') {
  26506. this.$annotations.splice(firstRow, len + 1, null);
  26507. } else {
  26508. var args = new Array(len + 1);
  26509. args.unshift(firstRow, 1);
  26510. this.$annotations.splice.apply(this.$annotations, args);
  26511. }
  26512. };
  26513. this.update = function(config) {
  26514. var session = this.session;
  26515. var firstRow = config.firstRow;
  26516. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  26517. session.getLength() - 1);
  26518. var fold = session.getNextFoldLine(firstRow);
  26519. var foldStart = fold ? fold.start.row : Infinity;
  26520. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  26521. var breakpoints = session.$breakpoints;
  26522. var decorations = session.$decorations;
  26523. var firstLineNumber = session.$firstLineNumber;
  26524. var lastLineNumber = 0;
  26525. var gutterRenderer = session.gutterRenderer || this.$renderer;
  26526. var cell = null;
  26527. var index = -1;
  26528. var row = firstRow;
  26529. while (true) {
  26530. if (row > foldStart) {
  26531. row = fold.end.row + 1;
  26532. fold = session.getNextFoldLine(row, fold);
  26533. foldStart = fold ? fold.start.row : Infinity;
  26534. }
  26535. if (row > lastRow) {
  26536. while (this.$cells.length > index + 1) {
  26537. cell = this.$cells.pop();
  26538. this.element.removeChild(cell.element);
  26539. }
  26540. break;
  26541. }
  26542. cell = this.$cells[++index];
  26543. if (!cell) {
  26544. cell = {element: null, textNode: null, foldWidget: null};
  26545. cell.element = dom.createElement("div");
  26546. cell.textNode = document.createTextNode('');
  26547. cell.element.appendChild(cell.textNode);
  26548. this.element.appendChild(cell.element);
  26549. this.$cells[index] = cell;
  26550. }
  26551. var className = "ace_gutter-cell ";
  26552. if (breakpoints[row])
  26553. className += breakpoints[row];
  26554. if (decorations[row])
  26555. className += decorations[row];
  26556. if (this.$annotations[row])
  26557. className += this.$annotations[row].className;
  26558. if (cell.element.className != className)
  26559. cell.element.className = className;
  26560. var height = session.getRowLength(row) * config.lineHeight + "px";
  26561. if (height != cell.element.style.height)
  26562. cell.element.style.height = height;
  26563. if (foldWidgets) {
  26564. var c = foldWidgets[row];
  26565. if (c == null)
  26566. c = foldWidgets[row] = session.getFoldWidget(row);
  26567. }
  26568. if (c) {
  26569. if (!cell.foldWidget) {
  26570. cell.foldWidget = dom.createElement("span");
  26571. cell.element.appendChild(cell.foldWidget);
  26572. }
  26573. var className = "ace_fold-widget ace_" + c;
  26574. if (c == "start" && row == foldStart && row < fold.end.row)
  26575. className += " ace_closed";
  26576. else
  26577. className += " ace_open";
  26578. if (cell.foldWidget.className != className)
  26579. cell.foldWidget.className = className;
  26580. var height = config.lineHeight + "px";
  26581. if (cell.foldWidget.style.height != height)
  26582. cell.foldWidget.style.height = height;
  26583. } else {
  26584. if (cell.foldWidget) {
  26585. cell.element.removeChild(cell.foldWidget);
  26586. cell.foldWidget = null;
  26587. }
  26588. }
  26589. var text = lastLineNumber = gutterRenderer
  26590. ? gutterRenderer.getText(session, row)
  26591. : row + firstLineNumber;
  26592. if (text != cell.textNode.data)
  26593. cell.textNode.data = text;
  26594. row++;
  26595. }
  26596. this.element.style.height = config.minHeight + "px";
  26597. if (this.$fixedWidth || session.$useWrapMode)
  26598. lastLineNumber = session.getLength() + firstLineNumber;
  26599. var gutterWidth = gutterRenderer
  26600. ? gutterRenderer.getWidth(session, lastLineNumber, config)
  26601. : lastLineNumber.toString().length * config.characterWidth;
  26602. var padding = this.$padding || this.$computePadding();
  26603. gutterWidth += padding.left + padding.right;
  26604. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  26605. this.gutterWidth = gutterWidth;
  26606. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  26607. this._emit("changeGutterWidth", gutterWidth);
  26608. }
  26609. };
  26610. this.$fixedWidth = false;
  26611. this.$showLineNumbers = true;
  26612. this.$renderer = "";
  26613. this.setShowLineNumbers = function(show) {
  26614. this.$renderer = !show && {
  26615. getWidth: function() {return ""},
  26616. getText: function() {return ""}
  26617. };
  26618. };
  26619. this.getShowLineNumbers = function() {
  26620. return this.$showLineNumbers;
  26621. };
  26622. this.$showFoldWidgets = true;
  26623. this.setShowFoldWidgets = function(show) {
  26624. if (show)
  26625. dom.addCssClass(this.element, "ace_folding-enabled");
  26626. else
  26627. dom.removeCssClass(this.element, "ace_folding-enabled");
  26628. this.$showFoldWidgets = show;
  26629. this.$padding = null;
  26630. };
  26631. this.getShowFoldWidgets = function() {
  26632. return this.$showFoldWidgets;
  26633. };
  26634. this.$computePadding = function() {
  26635. if (!this.element.firstChild)
  26636. return {left: 0, right: 0};
  26637. var style = dom.computedStyle(this.element.firstChild);
  26638. this.$padding = {};
  26639. this.$padding.left = parseInt(style.paddingLeft) + 1 || 0;
  26640. this.$padding.right = parseInt(style.paddingRight) || 0;
  26641. return this.$padding;
  26642. };
  26643. this.getRegion = function(point) {
  26644. var padding = this.$padding || this.$computePadding();
  26645. var rect = this.element.getBoundingClientRect();
  26646. if (point.x < padding.left + rect.left)
  26647. return "markers";
  26648. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  26649. return "foldWidgets";
  26650. };
  26651. }).call(Gutter.prototype);
  26652. exports.Gutter = Gutter;
  26653. });
  26654. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(acequire, exports, module) {
  26655. "use strict";
  26656. var Range = acequire("../range").Range;
  26657. var dom = acequire("../lib/dom");
  26658. var Marker = function(parentEl) {
  26659. this.element = dom.createElement("div");
  26660. this.element.className = "ace_layer ace_marker-layer";
  26661. parentEl.appendChild(this.element);
  26662. };
  26663. (function() {
  26664. this.$padding = 0;
  26665. this.setPadding = function(padding) {
  26666. this.$padding = padding;
  26667. };
  26668. this.setSession = function(session) {
  26669. this.session = session;
  26670. };
  26671. this.setMarkers = function(markers) {
  26672. this.markers = markers;
  26673. };
  26674. this.update = function(config) {
  26675. var config = config || this.config;
  26676. if (!config)
  26677. return;
  26678. this.config = config;
  26679. var html = [];
  26680. for (var key in this.markers) {
  26681. var marker = this.markers[key];
  26682. if (!marker.range) {
  26683. marker.update(html, this, this.session, config);
  26684. continue;
  26685. }
  26686. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  26687. if (range.isEmpty()) continue;
  26688. range = range.toScreenRange(this.session);
  26689. if (marker.renderer) {
  26690. var top = this.$getTop(range.start.row, config);
  26691. var left = this.$padding + range.start.column * config.characterWidth;
  26692. marker.renderer(html, range, left, top, config);
  26693. } else if (marker.type == "fullLine") {
  26694. this.drawFullLineMarker(html, range, marker.clazz, config);
  26695. } else if (marker.type == "screenLine") {
  26696. this.drawScreenLineMarker(html, range, marker.clazz, config);
  26697. } else if (range.isMultiLine()) {
  26698. if (marker.type == "text")
  26699. this.drawTextMarker(html, range, marker.clazz, config);
  26700. else
  26701. this.drawMultiLineMarker(html, range, marker.clazz, config);
  26702. } else {
  26703. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  26704. }
  26705. }
  26706. this.element.innerHTML = html.join("");
  26707. };
  26708. this.$getTop = function(row, layerConfig) {
  26709. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  26710. };
  26711. function getBorderClass(tl, tr, br, bl) {
  26712. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  26713. }
  26714. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  26715. var session = this.session;
  26716. var start = range.start.row;
  26717. var end = range.end.row;
  26718. var row = start;
  26719. var prev = 0;
  26720. var curr = 0;
  26721. var next = session.getScreenLastRowColumn(row);
  26722. var lineRange = new Range(row, range.start.column, row, curr);
  26723. for (; row <= end; row++) {
  26724. lineRange.start.row = lineRange.end.row = row;
  26725. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  26726. lineRange.end.column = next;
  26727. prev = curr;
  26728. curr = next;
  26729. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  26730. this.drawSingleLineMarker(stringBuilder, lineRange,
  26731. clazz + (row == start ? " ace_start" : "") + " ace_br"
  26732. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  26733. layerConfig, row == end ? 0 : 1, extraStyle);
  26734. }
  26735. };
  26736. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  26737. var padding = this.$padding;
  26738. var height = config.lineHeight;
  26739. var top = this.$getTop(range.start.row, config);
  26740. var left = padding + range.start.column * config.characterWidth;
  26741. extraStyle = extraStyle || "";
  26742. stringBuilder.push(
  26743. "<div class='", clazz, " ace_br1 ace_start' style='",
  26744. "height:", height, "px;",
  26745. "right:0;",
  26746. "top:", top, "px;",
  26747. "left:", left, "px;", extraStyle, "'></div>"
  26748. );
  26749. top = this.$getTop(range.end.row, config);
  26750. var width = range.end.column * config.characterWidth;
  26751. stringBuilder.push(
  26752. "<div class='", clazz, " ace_br12' style='",
  26753. "height:", height, "px;",
  26754. "width:", width, "px;",
  26755. "top:", top, "px;",
  26756. "left:", padding, "px;", extraStyle, "'></div>"
  26757. );
  26758. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  26759. if (height <= 0)
  26760. return;
  26761. top = this.$getTop(range.start.row + 1, config);
  26762. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  26763. stringBuilder.push(
  26764. "<div class='", clazz, (radiusClass ? " ace_br" + radiusClass : ""), "' style='",
  26765. "height:", height, "px;",
  26766. "right:0;",
  26767. "top:", top, "px;",
  26768. "left:", padding, "px;", extraStyle, "'></div>"
  26769. );
  26770. };
  26771. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  26772. var height = config.lineHeight;
  26773. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  26774. var top = this.$getTop(range.start.row, config);
  26775. var left = this.$padding + range.start.column * config.characterWidth;
  26776. stringBuilder.push(
  26777. "<div class='", clazz, "' style='",
  26778. "height:", height, "px;",
  26779. "width:", width, "px;",
  26780. "top:", top, "px;",
  26781. "left:", left, "px;", extraStyle || "", "'></div>"
  26782. );
  26783. };
  26784. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  26785. var top = this.$getTop(range.start.row, config);
  26786. var height = config.lineHeight;
  26787. if (range.start.row != range.end.row)
  26788. height += this.$getTop(range.end.row, config) - top;
  26789. stringBuilder.push(
  26790. "<div class='", clazz, "' style='",
  26791. "height:", height, "px;",
  26792. "top:", top, "px;",
  26793. "left:0;right:0;", extraStyle || "", "'></div>"
  26794. );
  26795. };
  26796. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  26797. var top = this.$getTop(range.start.row, config);
  26798. var height = config.lineHeight;
  26799. stringBuilder.push(
  26800. "<div class='", clazz, "' style='",
  26801. "height:", height, "px;",
  26802. "top:", top, "px;",
  26803. "left:0;right:0;", extraStyle || "", "'></div>"
  26804. );
  26805. };
  26806. }).call(Marker.prototype);
  26807. exports.Marker = Marker;
  26808. });
  26809. ace.define("ace/layer/text",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/lib/event_emitter"], function(acequire, exports, module) {
  26810. "use strict";
  26811. var oop = acequire("../lib/oop");
  26812. var dom = acequire("../lib/dom");
  26813. var lang = acequire("../lib/lang");
  26814. var useragent = acequire("../lib/useragent");
  26815. var EventEmitter = acequire("../lib/event_emitter").EventEmitter;
  26816. var Text = function(parentEl) {
  26817. this.element = dom.createElement("div");
  26818. this.element.className = "ace_layer ace_text-layer";
  26819. parentEl.appendChild(this.element);
  26820. this.$updateEolChar = this.$updateEolChar.bind(this);
  26821. };
  26822. (function() {
  26823. oop.implement(this, EventEmitter);
  26824. this.EOF_CHAR = "\xB6";
  26825. this.EOL_CHAR_LF = "\xAC";
  26826. this.EOL_CHAR_CRLF = "\xa4";
  26827. this.EOL_CHAR = this.EOL_CHAR_LF;
  26828. this.TAB_CHAR = "\u2014"; //"\u21E5";
  26829. this.SPACE_CHAR = "\xB7";
  26830. this.$padding = 0;
  26831. this.$updateEolChar = function() {
  26832. var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
  26833. ? this.EOL_CHAR_LF
  26834. : this.EOL_CHAR_CRLF;
  26835. if (this.EOL_CHAR != EOL_CHAR) {
  26836. this.EOL_CHAR = EOL_CHAR;
  26837. return true;
  26838. }
  26839. }
  26840. this.setPadding = function(padding) {
  26841. this.$padding = padding;
  26842. this.element.style.padding = "0 " + padding + "px";
  26843. };
  26844. this.getLineHeight = function() {
  26845. return this.$fontMetrics.$characterSize.height || 0;
  26846. };
  26847. this.getCharacterWidth = function() {
  26848. return this.$fontMetrics.$characterSize.width || 0;
  26849. };
  26850. this.$setFontMetrics = function(measure) {
  26851. this.$fontMetrics = measure;
  26852. this.$fontMetrics.on("changeCharacterSize", function(e) {
  26853. this._signal("changeCharacterSize", e);
  26854. }.bind(this));
  26855. this.$pollSizeChanges();
  26856. }
  26857. this.checkForSizeChanges = function() {
  26858. this.$fontMetrics.checkForSizeChanges();
  26859. };
  26860. this.$pollSizeChanges = function() {
  26861. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  26862. };
  26863. this.setSession = function(session) {
  26864. this.session = session;
  26865. if (session)
  26866. this.$computeTabString();
  26867. };
  26868. this.showInvisibles = false;
  26869. this.setShowInvisibles = function(showInvisibles) {
  26870. if (this.showInvisibles == showInvisibles)
  26871. return false;
  26872. this.showInvisibles = showInvisibles;
  26873. this.$computeTabString();
  26874. return true;
  26875. };
  26876. this.displayIndentGuides = true;
  26877. this.setDisplayIndentGuides = function(display) {
  26878. if (this.displayIndentGuides == display)
  26879. return false;
  26880. this.displayIndentGuides = display;
  26881. this.$computeTabString();
  26882. return true;
  26883. };
  26884. this.$tabStrings = [];
  26885. this.onChangeTabSize =
  26886. this.$computeTabString = function() {
  26887. var tabSize = this.session.getTabSize();
  26888. this.tabSize = tabSize;
  26889. var tabStr = this.$tabStrings = [0];
  26890. for (var i = 1; i < tabSize + 1; i++) {
  26891. if (this.showInvisibles) {
  26892. tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
  26893. + lang.stringRepeat(this.TAB_CHAR, i)
  26894. + "</span>");
  26895. } else {
  26896. tabStr.push(lang.stringRepeat(" ", i));
  26897. }
  26898. }
  26899. if (this.displayIndentGuides) {
  26900. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  26901. var className = "ace_indent-guide";
  26902. var spaceClass = "";
  26903. var tabClass = "";
  26904. if (this.showInvisibles) {
  26905. className += " ace_invisible";
  26906. spaceClass = " ace_invisible_space";
  26907. tabClass = " ace_invisible_tab";
  26908. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  26909. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  26910. } else{
  26911. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  26912. var tabContent = spaceContent;
  26913. }
  26914. this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>";
  26915. this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>";
  26916. }
  26917. };
  26918. this.updateLines = function(config, firstRow, lastRow) {
  26919. if (this.config.lastRow != config.lastRow ||
  26920. this.config.firstRow != config.firstRow) {
  26921. this.scrollLines(config);
  26922. }
  26923. this.config = config;
  26924. var first = Math.max(firstRow, config.firstRow);
  26925. var last = Math.min(lastRow, config.lastRow);
  26926. var lineElements = this.element.childNodes;
  26927. var lineElementsIdx = 0;
  26928. for (var row = config.firstRow; row < first; row++) {
  26929. var foldLine = this.session.getFoldLine(row);
  26930. if (foldLine) {
  26931. if (foldLine.containsRow(first)) {
  26932. first = foldLine.start.row;
  26933. break;
  26934. } else {
  26935. row = foldLine.end.row;
  26936. }
  26937. }
  26938. lineElementsIdx ++;
  26939. }
  26940. var row = first;
  26941. var foldLine = this.session.getNextFoldLine(row);
  26942. var foldStart = foldLine ? foldLine.start.row : Infinity;
  26943. while (true) {
  26944. if (row > foldStart) {
  26945. row = foldLine.end.row+1;
  26946. foldLine = this.session.getNextFoldLine(row, foldLine);
  26947. foldStart = foldLine ? foldLine.start.row :Infinity;
  26948. }
  26949. if (row > last)
  26950. break;
  26951. var lineElement = lineElements[lineElementsIdx++];
  26952. if (lineElement) {
  26953. var html = [];
  26954. this.$renderLine(
  26955. html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
  26956. );
  26957. lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  26958. lineElement.innerHTML = html.join("");
  26959. }
  26960. row++;
  26961. }
  26962. };
  26963. this.scrollLines = function(config) {
  26964. var oldConfig = this.config;
  26965. this.config = config;
  26966. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  26967. return this.update(config);
  26968. if (config.lastRow < oldConfig.firstRow)
  26969. return this.update(config);
  26970. var el = this.element;
  26971. if (oldConfig.firstRow < config.firstRow)
  26972. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  26973. el.removeChild(el.firstChild);
  26974. if (oldConfig.lastRow > config.lastRow)
  26975. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  26976. el.removeChild(el.lastChild);
  26977. if (config.firstRow < oldConfig.firstRow) {
  26978. var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
  26979. if (el.firstChild)
  26980. el.insertBefore(fragment, el.firstChild);
  26981. else
  26982. el.appendChild(fragment);
  26983. }
  26984. if (config.lastRow > oldConfig.lastRow) {
  26985. var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
  26986. el.appendChild(fragment);
  26987. }
  26988. };
  26989. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  26990. var fragment = this.element.ownerDocument.createDocumentFragment();
  26991. var row = firstRow;
  26992. var foldLine = this.session.getNextFoldLine(row);
  26993. var foldStart = foldLine ? foldLine.start.row : Infinity;
  26994. while (true) {
  26995. if (row > foldStart) {
  26996. row = foldLine.end.row+1;
  26997. foldLine = this.session.getNextFoldLine(row, foldLine);
  26998. foldStart = foldLine ? foldLine.start.row : Infinity;
  26999. }
  27000. if (row > lastRow)
  27001. break;
  27002. var container = dom.createElement("div");
  27003. var html = [];
  27004. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  27005. container.innerHTML = html.join("");
  27006. if (this.$useLineGroups()) {
  27007. container.className = 'ace_line_group';
  27008. fragment.appendChild(container);
  27009. container.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  27010. } else {
  27011. while(container.firstChild)
  27012. fragment.appendChild(container.firstChild);
  27013. }
  27014. row++;
  27015. }
  27016. return fragment;
  27017. };
  27018. this.update = function(config) {
  27019. this.config = config;
  27020. var html = [];
  27021. var firstRow = config.firstRow, lastRow = config.lastRow;
  27022. var row = firstRow;
  27023. var foldLine = this.session.getNextFoldLine(row);
  27024. var foldStart = foldLine ? foldLine.start.row : Infinity;
  27025. while (true) {
  27026. if (row > foldStart) {
  27027. row = foldLine.end.row+1;
  27028. foldLine = this.session.getNextFoldLine(row, foldLine);
  27029. foldStart = foldLine ? foldLine.start.row :Infinity;
  27030. }
  27031. if (row > lastRow)
  27032. break;
  27033. if (this.$useLineGroups())
  27034. html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>")
  27035. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  27036. if (this.$useLineGroups())
  27037. html.push("</div>"); // end the line group
  27038. row++;
  27039. }
  27040. this.element.innerHTML = html.join("");
  27041. };
  27042. this.$textToken = {
  27043. "text": true,
  27044. "rparen": true,
  27045. "lparen": true
  27046. };
  27047. this.$renderToken = function(stringBuilder, screenColumn, token, value) {
  27048. var self = this;
  27049. var replaceReg = /\t|&|<|>|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF\uFFF9-\uFFFC])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
  27050. var replaceFunc = function(c, a, b, tabIdx, idx4) {
  27051. if (a) {
  27052. return self.showInvisibles
  27053. ? "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>"
  27054. : c;
  27055. } else if (c == "&") {
  27056. return "&#38;";
  27057. } else if (c == "<") {
  27058. return "&#60;";
  27059. } else if (c == ">") {
  27060. return "&#62;";
  27061. } else if (c == "\t") {
  27062. var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
  27063. screenColumn += tabSize - 1;
  27064. return self.$tabStrings[tabSize];
  27065. } else if (c == "\u3000") {
  27066. var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  27067. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  27068. screenColumn += 1;
  27069. return "<span class='" + classToUse + "' style='width:" +
  27070. (self.config.characterWidth * 2) +
  27071. "px'>" + space + "</span>";
  27072. } else if (b) {
  27073. return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>";
  27074. } else {
  27075. screenColumn += 1;
  27076. return "<span class='ace_cjk' style='width:" +
  27077. (self.config.characterWidth * 2) +
  27078. "px'>" + c + "</span>";
  27079. }
  27080. };
  27081. var output = value.replace(replaceReg, replaceFunc);
  27082. if (!this.$textToken[token.type]) {
  27083. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  27084. var style = "";
  27085. if (token.type == "fold")
  27086. style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
  27087. stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
  27088. }
  27089. else {
  27090. stringBuilder.push(output);
  27091. }
  27092. return screenColumn + value.length;
  27093. };
  27094. this.renderIndentGuide = function(stringBuilder, value, max) {
  27095. var cols = value.search(this.$indentGuideRe);
  27096. if (cols <= 0 || cols >= max)
  27097. return value;
  27098. if (value[0] == " ") {
  27099. cols -= cols % this.tabSize;
  27100. stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize));
  27101. return value.substr(cols);
  27102. } else if (value[0] == "\t") {
  27103. stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols));
  27104. return value.substr(cols);
  27105. }
  27106. return value;
  27107. };
  27108. this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
  27109. var chars = 0;
  27110. var split = 0;
  27111. var splitChars = splits[0];
  27112. var screenColumn = 0;
  27113. for (var i = 0; i < tokens.length; i++) {
  27114. var token = tokens[i];
  27115. var value = token.value;
  27116. if (i == 0 && this.displayIndentGuides) {
  27117. chars = value.length;
  27118. value = this.renderIndentGuide(stringBuilder, value, splitChars);
  27119. if (!value)
  27120. continue;
  27121. chars -= value.length;
  27122. }
  27123. if (chars + value.length < splitChars) {
  27124. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  27125. chars += value.length;
  27126. } else {
  27127. while (chars + value.length >= splitChars) {
  27128. screenColumn = this.$renderToken(
  27129. stringBuilder, screenColumn,
  27130. token, value.substring(0, splitChars - chars)
  27131. );
  27132. value = value.substring(splitChars - chars);
  27133. chars = splitChars;
  27134. if (!onlyContents) {
  27135. stringBuilder.push("</div>",
  27136. "<div class='ace_line' style='height:",
  27137. this.config.lineHeight, "px'>"
  27138. );
  27139. }
  27140. stringBuilder.push(lang.stringRepeat("\xa0", splits.indent));
  27141. split ++;
  27142. screenColumn = 0;
  27143. splitChars = splits[split] || Number.MAX_VALUE;
  27144. }
  27145. if (value.length != 0) {
  27146. chars += value.length;
  27147. screenColumn = this.$renderToken(
  27148. stringBuilder, screenColumn, token, value
  27149. );
  27150. }
  27151. }
  27152. }
  27153. };
  27154. this.$renderSimpleLine = function(stringBuilder, tokens) {
  27155. var screenColumn = 0;
  27156. var token = tokens[0];
  27157. var value = token.value;
  27158. if (this.displayIndentGuides)
  27159. value = this.renderIndentGuide(stringBuilder, value);
  27160. if (value)
  27161. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  27162. for (var i = 1; i < tokens.length; i++) {
  27163. token = tokens[i];
  27164. value = token.value;
  27165. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  27166. }
  27167. };
  27168. this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
  27169. if (!foldLine && foldLine != false)
  27170. foldLine = this.session.getFoldLine(row);
  27171. if (foldLine)
  27172. var tokens = this.$getFoldLineTokens(row, foldLine);
  27173. else
  27174. var tokens = this.session.getTokens(row);
  27175. if (!onlyContents) {
  27176. stringBuilder.push(
  27177. "<div class='ace_line' style='height:",
  27178. this.config.lineHeight * (
  27179. this.$useLineGroups() ? 1 :this.session.getRowLength(row)
  27180. ), "px'>"
  27181. );
  27182. }
  27183. if (tokens.length) {
  27184. var splits = this.session.getRowSplitData(row);
  27185. if (splits && splits.length)
  27186. this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
  27187. else
  27188. this.$renderSimpleLine(stringBuilder, tokens);
  27189. }
  27190. if (this.showInvisibles) {
  27191. if (foldLine)
  27192. row = foldLine.end.row
  27193. stringBuilder.push(
  27194. "<span class='ace_invisible ace_invisible_eol'>",
  27195. row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
  27196. "</span>"
  27197. );
  27198. }
  27199. if (!onlyContents)
  27200. stringBuilder.push("</div>");
  27201. };
  27202. this.$getFoldLineTokens = function(row, foldLine) {
  27203. var session = this.session;
  27204. var renderTokens = [];
  27205. function addTokens(tokens, from, to) {
  27206. var idx = 0, col = 0;
  27207. while ((col + tokens[idx].value.length) < from) {
  27208. col += tokens[idx].value.length;
  27209. idx++;
  27210. if (idx == tokens.length)
  27211. return;
  27212. }
  27213. if (col != from) {
  27214. var value = tokens[idx].value.substring(from - col);
  27215. if (value.length > (to - from))
  27216. value = value.substring(0, to - from);
  27217. renderTokens.push({
  27218. type: tokens[idx].type,
  27219. value: value
  27220. });
  27221. col = from + value.length;
  27222. idx += 1;
  27223. }
  27224. while (col < to && idx < tokens.length) {
  27225. var value = tokens[idx].value;
  27226. if (value.length + col > to) {
  27227. renderTokens.push({
  27228. type: tokens[idx].type,
  27229. value: value.substring(0, to - col)
  27230. });
  27231. } else
  27232. renderTokens.push(tokens[idx]);
  27233. col += value.length;
  27234. idx += 1;
  27235. }
  27236. }
  27237. var tokens = session.getTokens(row);
  27238. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  27239. if (placeholder != null) {
  27240. renderTokens.push({
  27241. type: "fold",
  27242. value: placeholder
  27243. });
  27244. } else {
  27245. if (isNewRow)
  27246. tokens = session.getTokens(row);
  27247. if (tokens.length)
  27248. addTokens(tokens, lastColumn, column);
  27249. }
  27250. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  27251. return renderTokens;
  27252. };
  27253. this.$useLineGroups = function() {
  27254. return this.session.getUseWrapMode();
  27255. };
  27256. this.destroy = function() {
  27257. clearInterval(this.$pollSizeChangesTimer);
  27258. if (this.$measureNode)
  27259. this.$measureNode.parentNode.removeChild(this.$measureNode);
  27260. delete this.$measureNode;
  27261. };
  27262. }).call(Text.prototype);
  27263. exports.Text = Text;
  27264. });
  27265. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(acequire, exports, module) {
  27266. "use strict";
  27267. var dom = acequire("../lib/dom");
  27268. var isIE8;
  27269. var Cursor = function(parentEl) {
  27270. this.element = dom.createElement("div");
  27271. this.element.className = "ace_layer ace_cursor-layer";
  27272. parentEl.appendChild(this.element);
  27273. if (isIE8 === undefined)
  27274. isIE8 = !("opacity" in this.element.style);
  27275. this.isVisible = false;
  27276. this.isBlinking = true;
  27277. this.blinkInterval = 1000;
  27278. this.smoothBlinking = false;
  27279. this.cursors = [];
  27280. this.cursor = this.addCursor();
  27281. dom.addCssClass(this.element, "ace_hidden-cursors");
  27282. this.$updateCursors = (isIE8
  27283. ? this.$updateVisibility
  27284. : this.$updateOpacity).bind(this);
  27285. };
  27286. (function() {
  27287. this.$updateVisibility = function(val) {
  27288. var cursors = this.cursors;
  27289. for (var i = cursors.length; i--; )
  27290. cursors[i].style.visibility = val ? "" : "hidden";
  27291. };
  27292. this.$updateOpacity = function(val) {
  27293. var cursors = this.cursors;
  27294. for (var i = cursors.length; i--; )
  27295. cursors[i].style.opacity = val ? "" : "0";
  27296. };
  27297. this.$padding = 0;
  27298. this.setPadding = function(padding) {
  27299. this.$padding = padding;
  27300. };
  27301. this.setSession = function(session) {
  27302. this.session = session;
  27303. };
  27304. this.setBlinking = function(blinking) {
  27305. if (blinking != this.isBlinking){
  27306. this.isBlinking = blinking;
  27307. this.restartTimer();
  27308. }
  27309. };
  27310. this.setBlinkInterval = function(blinkInterval) {
  27311. if (blinkInterval != this.blinkInterval){
  27312. this.blinkInterval = blinkInterval;
  27313. this.restartTimer();
  27314. }
  27315. };
  27316. this.setSmoothBlinking = function(smoothBlinking) {
  27317. if (smoothBlinking != this.smoothBlinking && !isIE8) {
  27318. this.smoothBlinking = smoothBlinking;
  27319. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  27320. this.$updateCursors(true);
  27321. this.$updateCursors = (this.$updateOpacity).bind(this);
  27322. this.restartTimer();
  27323. }
  27324. };
  27325. this.addCursor = function() {
  27326. var el = dom.createElement("div");
  27327. el.className = "ace_cursor";
  27328. this.element.appendChild(el);
  27329. this.cursors.push(el);
  27330. return el;
  27331. };
  27332. this.removeCursor = function() {
  27333. if (this.cursors.length > 1) {
  27334. var el = this.cursors.pop();
  27335. el.parentNode.removeChild(el);
  27336. return el;
  27337. }
  27338. };
  27339. this.hideCursor = function() {
  27340. this.isVisible = false;
  27341. dom.addCssClass(this.element, "ace_hidden-cursors");
  27342. this.restartTimer();
  27343. };
  27344. this.showCursor = function() {
  27345. this.isVisible = true;
  27346. dom.removeCssClass(this.element, "ace_hidden-cursors");
  27347. this.restartTimer();
  27348. };
  27349. this.restartTimer = function() {
  27350. var update = this.$updateCursors;
  27351. clearInterval(this.intervalId);
  27352. clearTimeout(this.timeoutId);
  27353. if (this.smoothBlinking) {
  27354. dom.removeCssClass(this.element, "ace_smooth-blinking");
  27355. }
  27356. update(true);
  27357. if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
  27358. return;
  27359. if (this.smoothBlinking) {
  27360. setTimeout(function(){
  27361. dom.addCssClass(this.element, "ace_smooth-blinking");
  27362. }.bind(this));
  27363. }
  27364. var blink = function(){
  27365. this.timeoutId = setTimeout(function() {
  27366. update(false);
  27367. }, 0.6 * this.blinkInterval);
  27368. }.bind(this);
  27369. this.intervalId = setInterval(function() {
  27370. update(true);
  27371. blink();
  27372. }, this.blinkInterval);
  27373. blink();
  27374. };
  27375. this.getPixelPosition = function(position, onScreen) {
  27376. if (!this.config || !this.session)
  27377. return {left : 0, top : 0};
  27378. if (!position)
  27379. position = this.session.selection.getCursor();
  27380. var pos = this.session.documentToScreenPosition(position);
  27381. var cursorLeft = this.$padding + pos.column * this.config.characterWidth;
  27382. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  27383. this.config.lineHeight;
  27384. return {left : cursorLeft, top : cursorTop};
  27385. };
  27386. this.update = function(config) {
  27387. this.config = config;
  27388. var selections = this.session.$selectionMarkers;
  27389. var i = 0, cursorIndex = 0;
  27390. if (selections === undefined || selections.length === 0){
  27391. selections = [{cursor: null}];
  27392. }
  27393. for (var i = 0, n = selections.length; i < n; i++) {
  27394. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  27395. if ((pixelPos.top > config.height + config.offset ||
  27396. pixelPos.top < 0) && i > 1) {
  27397. continue;
  27398. }
  27399. var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
  27400. if (!this.drawCursor) {
  27401. style.left = pixelPos.left + "px";
  27402. style.top = pixelPos.top + "px";
  27403. style.width = config.characterWidth + "px";
  27404. style.height = config.lineHeight + "px";
  27405. } else {
  27406. this.drawCursor(style, pixelPos, config, selections[i], this.session);
  27407. }
  27408. }
  27409. while (this.cursors.length > cursorIndex)
  27410. this.removeCursor();
  27411. var overwrite = this.session.getOverwrite();
  27412. this.$setOverwrite(overwrite);
  27413. this.$pixelPos = pixelPos;
  27414. this.restartTimer();
  27415. };
  27416. this.drawCursor = null;
  27417. this.$setOverwrite = function(overwrite) {
  27418. if (overwrite != this.overwrite) {
  27419. this.overwrite = overwrite;
  27420. if (overwrite)
  27421. dom.addCssClass(this.element, "ace_overwrite-cursors");
  27422. else
  27423. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  27424. }
  27425. };
  27426. this.destroy = function() {
  27427. clearInterval(this.intervalId);
  27428. clearTimeout(this.timeoutId);
  27429. };
  27430. }).call(Cursor.prototype);
  27431. exports.Cursor = Cursor;
  27432. });
  27433. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(acequire, exports, module) {
  27434. "use strict";
  27435. var oop = acequire("./lib/oop");
  27436. var dom = acequire("./lib/dom");
  27437. var event = acequire("./lib/event");
  27438. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  27439. var ScrollBar = function(parent) {
  27440. this.element = dom.createElement("div");
  27441. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  27442. this.inner = dom.createElement("div");
  27443. this.inner.className = "ace_scrollbar-inner";
  27444. this.element.appendChild(this.inner);
  27445. parent.appendChild(this.element);
  27446. this.setVisible(false);
  27447. this.skipEvent = false;
  27448. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  27449. event.addListener(this.element, "mousedown", event.preventDefault);
  27450. };
  27451. (function() {
  27452. oop.implement(this, EventEmitter);
  27453. this.setVisible = function(isVisible) {
  27454. this.element.style.display = isVisible ? "" : "none";
  27455. this.isVisible = isVisible;
  27456. };
  27457. }).call(ScrollBar.prototype);
  27458. var VScrollBar = function(parent, renderer) {
  27459. ScrollBar.call(this, parent);
  27460. this.scrollTop = 0;
  27461. renderer.$scrollbarWidth =
  27462. this.width = dom.scrollbarWidth(parent.ownerDocument);
  27463. this.inner.style.width =
  27464. this.element.style.width = (this.width || 15) + 5 + "px";
  27465. };
  27466. oop.inherits(VScrollBar, ScrollBar);
  27467. (function() {
  27468. this.classSuffix = '-v';
  27469. this.onScroll = function() {
  27470. if (!this.skipEvent) {
  27471. this.scrollTop = this.element.scrollTop;
  27472. this._emit("scroll", {data: this.scrollTop});
  27473. }
  27474. this.skipEvent = false;
  27475. };
  27476. this.getWidth = function() {
  27477. return this.isVisible ? this.width : 0;
  27478. };
  27479. this.setHeight = function(height) {
  27480. this.element.style.height = height + "px";
  27481. };
  27482. this.setInnerHeight = function(height) {
  27483. this.inner.style.height = height + "px";
  27484. };
  27485. this.setScrollHeight = function(height) {
  27486. this.inner.style.height = height + "px";
  27487. };
  27488. this.setScrollTop = function(scrollTop) {
  27489. if (this.scrollTop != scrollTop) {
  27490. this.skipEvent = true;
  27491. this.scrollTop = this.element.scrollTop = scrollTop;
  27492. }
  27493. };
  27494. }).call(VScrollBar.prototype);
  27495. var HScrollBar = function(parent, renderer) {
  27496. ScrollBar.call(this, parent);
  27497. this.scrollLeft = 0;
  27498. this.height = renderer.$scrollbarWidth;
  27499. this.inner.style.height =
  27500. this.element.style.height = (this.height || 15) + 5 + "px";
  27501. };
  27502. oop.inherits(HScrollBar, ScrollBar);
  27503. (function() {
  27504. this.classSuffix = '-h';
  27505. this.onScroll = function() {
  27506. if (!this.skipEvent) {
  27507. this.scrollLeft = this.element.scrollLeft;
  27508. this._emit("scroll", {data: this.scrollLeft});
  27509. }
  27510. this.skipEvent = false;
  27511. };
  27512. this.getHeight = function() {
  27513. return this.isVisible ? this.height : 0;
  27514. };
  27515. this.setWidth = function(width) {
  27516. this.element.style.width = width + "px";
  27517. };
  27518. this.setInnerWidth = function(width) {
  27519. this.inner.style.width = width + "px";
  27520. };
  27521. this.setScrollWidth = function(width) {
  27522. this.inner.style.width = width + "px";
  27523. };
  27524. this.setScrollLeft = function(scrollLeft) {
  27525. if (this.scrollLeft != scrollLeft) {
  27526. this.skipEvent = true;
  27527. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  27528. }
  27529. };
  27530. }).call(HScrollBar.prototype);
  27531. exports.ScrollBar = VScrollBar; // backward compatibility
  27532. exports.ScrollBarV = VScrollBar; // backward compatibility
  27533. exports.ScrollBarH = HScrollBar; // backward compatibility
  27534. exports.VScrollBar = VScrollBar;
  27535. exports.HScrollBar = HScrollBar;
  27536. });
  27537. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(acequire, exports, module) {
  27538. "use strict";
  27539. var event = acequire("./lib/event");
  27540. var RenderLoop = function(onRender, win) {
  27541. this.onRender = onRender;
  27542. this.pending = false;
  27543. this.changes = 0;
  27544. this.window = win || window;
  27545. };
  27546. (function() {
  27547. this.schedule = function(change) {
  27548. this.changes = this.changes | change;
  27549. if (!this.pending && this.changes) {
  27550. this.pending = true;
  27551. var _self = this;
  27552. event.nextFrame(function() {
  27553. _self.pending = false;
  27554. var changes;
  27555. while (changes = _self.changes) {
  27556. _self.changes = 0;
  27557. _self.onRender(changes);
  27558. }
  27559. }, this.window);
  27560. }
  27561. };
  27562. }).call(RenderLoop.prototype);
  27563. exports.RenderLoop = RenderLoop;
  27564. });
  27565. ace.define("ace/layer/font_metrics",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/lib/event_emitter"], function(acequire, exports, module) {
  27566. var oop = acequire("../lib/oop");
  27567. var dom = acequire("../lib/dom");
  27568. var lang = acequire("../lib/lang");
  27569. var useragent = acequire("../lib/useragent");
  27570. var EventEmitter = acequire("../lib/event_emitter").EventEmitter;
  27571. var CHAR_COUNT = 0;
  27572. var FontMetrics = exports.FontMetrics = function(parentEl) {
  27573. this.el = dom.createElement("div");
  27574. this.$setMeasureNodeStyles(this.el.style, true);
  27575. this.$main = dom.createElement("div");
  27576. this.$setMeasureNodeStyles(this.$main.style);
  27577. this.$measureNode = dom.createElement("div");
  27578. this.$setMeasureNodeStyles(this.$measureNode.style);
  27579. this.el.appendChild(this.$main);
  27580. this.el.appendChild(this.$measureNode);
  27581. parentEl.appendChild(this.el);
  27582. if (!CHAR_COUNT)
  27583. this.$testFractionalRect();
  27584. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  27585. this.$characterSize = {width: 0, height: 0};
  27586. this.checkForSizeChanges();
  27587. };
  27588. (function() {
  27589. oop.implement(this, EventEmitter);
  27590. this.$characterSize = {width: 0, height: 0};
  27591. this.$testFractionalRect = function() {
  27592. var el = dom.createElement("div");
  27593. this.$setMeasureNodeStyles(el.style);
  27594. el.style.width = "0.2px";
  27595. document.documentElement.appendChild(el);
  27596. var w = el.getBoundingClientRect().width;
  27597. if (w > 0 && w < 1)
  27598. CHAR_COUNT = 50;
  27599. else
  27600. CHAR_COUNT = 100;
  27601. el.parentNode.removeChild(el);
  27602. };
  27603. this.$setMeasureNodeStyles = function(style, isRoot) {
  27604. style.width = style.height = "auto";
  27605. style.left = style.top = "0px";
  27606. style.visibility = "hidden";
  27607. style.position = "absolute";
  27608. style.whiteSpace = "pre";
  27609. if (useragent.isIE < 8) {
  27610. style["font-family"] = "inherit";
  27611. } else {
  27612. style.font = "inherit";
  27613. }
  27614. style.overflow = isRoot ? "hidden" : "visible";
  27615. };
  27616. this.checkForSizeChanges = function() {
  27617. var size = this.$measureSizes();
  27618. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  27619. this.$measureNode.style.fontWeight = "bold";
  27620. var boldSize = this.$measureSizes();
  27621. this.$measureNode.style.fontWeight = "";
  27622. this.$characterSize = size;
  27623. this.charSizes = Object.create(null);
  27624. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  27625. this._emit("changeCharacterSize", {data: size});
  27626. }
  27627. };
  27628. this.$pollSizeChanges = function() {
  27629. if (this.$pollSizeChangesTimer)
  27630. return this.$pollSizeChangesTimer;
  27631. var self = this;
  27632. return this.$pollSizeChangesTimer = setInterval(function() {
  27633. self.checkForSizeChanges();
  27634. }, 500);
  27635. };
  27636. this.setPolling = function(val) {
  27637. if (val) {
  27638. this.$pollSizeChanges();
  27639. } else if (this.$pollSizeChangesTimer) {
  27640. clearInterval(this.$pollSizeChangesTimer);
  27641. this.$pollSizeChangesTimer = 0;
  27642. }
  27643. };
  27644. this.$measureSizes = function() {
  27645. if (CHAR_COUNT === 50) {
  27646. var rect = null;
  27647. try {
  27648. rect = this.$measureNode.getBoundingClientRect();
  27649. } catch(e) {
  27650. rect = {width: 0, height:0 };
  27651. }
  27652. var size = {
  27653. height: rect.height,
  27654. width: rect.width / CHAR_COUNT
  27655. };
  27656. } else {
  27657. var size = {
  27658. height: this.$measureNode.clientHeight,
  27659. width: this.$measureNode.clientWidth / CHAR_COUNT
  27660. };
  27661. }
  27662. if (size.width === 0 || size.height === 0)
  27663. return null;
  27664. return size;
  27665. };
  27666. this.$measureCharWidth = function(ch) {
  27667. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  27668. var rect = this.$main.getBoundingClientRect();
  27669. return rect.width / CHAR_COUNT;
  27670. };
  27671. this.getCharacterWidth = function(ch) {
  27672. var w = this.charSizes[ch];
  27673. if (w === undefined) {
  27674. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  27675. }
  27676. return w;
  27677. };
  27678. this.destroy = function() {
  27679. clearInterval(this.$pollSizeChangesTimer);
  27680. if (this.el && this.el.parentNode)
  27681. this.el.parentNode.removeChild(this.el);
  27682. };
  27683. }).call(FontMetrics.prototype);
  27684. });
  27685. ace.define("ace/virtual_renderer",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/config","ace/lib/useragent","ace/layer/gutter","ace/layer/marker","ace/layer/text","ace/layer/cursor","ace/scrollbar","ace/scrollbar","ace/renderloop","ace/layer/font_metrics","ace/lib/event_emitter"], function(acequire, exports, module) {
  27686. "use strict";
  27687. var oop = acequire("./lib/oop");
  27688. var dom = acequire("./lib/dom");
  27689. var config = acequire("./config");
  27690. var useragent = acequire("./lib/useragent");
  27691. var GutterLayer = acequire("./layer/gutter").Gutter;
  27692. var MarkerLayer = acequire("./layer/marker").Marker;
  27693. var TextLayer = acequire("./layer/text").Text;
  27694. var CursorLayer = acequire("./layer/cursor").Cursor;
  27695. var HScrollBar = acequire("./scrollbar").HScrollBar;
  27696. var VScrollBar = acequire("./scrollbar").VScrollBar;
  27697. var RenderLoop = acequire("./renderloop").RenderLoop;
  27698. var FontMetrics = acequire("./layer/font_metrics").FontMetrics;
  27699. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  27700. var editorCss = ".ace_editor {\
  27701. position: relative;\
  27702. overflow: hidden;\
  27703. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  27704. direction: ltr;\
  27705. }\
  27706. .ace_scroller {\
  27707. position: absolute;\
  27708. overflow: hidden;\
  27709. top: 0;\
  27710. bottom: 0;\
  27711. background-color: inherit;\
  27712. -ms-user-select: none;\
  27713. -moz-user-select: none;\
  27714. -webkit-user-select: none;\
  27715. user-select: none;\
  27716. cursor: text;\
  27717. }\
  27718. .ace_content {\
  27719. position: absolute;\
  27720. -moz-box-sizing: border-box;\
  27721. -webkit-box-sizing: border-box;\
  27722. box-sizing: border-box;\
  27723. min-width: 100%;\
  27724. }\
  27725. .ace_dragging .ace_scroller:before{\
  27726. position: absolute;\
  27727. top: 0;\
  27728. left: 0;\
  27729. right: 0;\
  27730. bottom: 0;\
  27731. content: '';\
  27732. background: rgba(250, 250, 250, 0.01);\
  27733. z-index: 1000;\
  27734. }\
  27735. .ace_dragging.ace_dark .ace_scroller:before{\
  27736. background: rgba(0, 0, 0, 0.01);\
  27737. }\
  27738. .ace_selecting, .ace_selecting * {\
  27739. cursor: text !important;\
  27740. }\
  27741. .ace_gutter {\
  27742. position: absolute;\
  27743. overflow : hidden;\
  27744. width: auto;\
  27745. top: 0;\
  27746. bottom: 0;\
  27747. left: 0;\
  27748. cursor: default;\
  27749. z-index: 4;\
  27750. -ms-user-select: none;\
  27751. -moz-user-select: none;\
  27752. -webkit-user-select: none;\
  27753. user-select: none;\
  27754. }\
  27755. .ace_gutter-active-line {\
  27756. position: absolute;\
  27757. left: 0;\
  27758. right: 0;\
  27759. }\
  27760. .ace_scroller.ace_scroll-left {\
  27761. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  27762. }\
  27763. .ace_gutter-cell {\
  27764. padding-left: 19px;\
  27765. padding-right: 6px;\
  27766. background-repeat: no-repeat;\
  27767. }\
  27768. .ace_gutter-cell.ace_error {\
  27769. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABOFBMVEX/////////QRswFAb/Ui4wFAYwFAYwFAaWGAfDRymzOSH/PxswFAb/SiUwFAYwFAbUPRvjQiDllog5HhHdRybsTi3/Tyv9Tir+Syj/UC3////XurebMBIwFAb/RSHbPx/gUzfdwL3kzMivKBAwFAbbvbnhPx66NhowFAYwFAaZJg8wFAaxKBDZurf/RB6mMxb/SCMwFAYwFAbxQB3+RB4wFAb/Qhy4Oh+4QifbNRcwFAYwFAYwFAb/QRzdNhgwFAYwFAbav7v/Uy7oaE68MBK5LxLewr/r2NXewLswFAaxJw4wFAbkPRy2PyYwFAaxKhLm1tMwFAazPiQwFAaUGAb/QBrfOx3bvrv/VC/maE4wFAbRPBq6MRO8Qynew8Dp2tjfwb0wFAbx6eju5+by6uns4uH9/f36+vr/GkHjAAAAYnRSTlMAGt+64rnWu/bo8eAA4InH3+DwoN7j4eLi4xP99Nfg4+b+/u9B/eDs1MD1mO7+4PHg2MXa347g7vDizMLN4eG+Pv7i5evs/v79yu7S3/DV7/498Yv24eH+4ufQ3Ozu/v7+y13sRqwAAADLSURBVHjaZc/XDsFgGIBhtDrshlitmk2IrbHFqL2pvXf/+78DPokj7+Fz9qpU/9UXJIlhmPaTaQ6QPaz0mm+5gwkgovcV6GZzd5JtCQwgsxoHOvJO15kleRLAnMgHFIESUEPmawB9ngmelTtipwwfASilxOLyiV5UVUyVAfbG0cCPHig+GBkzAENHS0AstVF6bacZIOzgLmxsHbt2OecNgJC83JERmePUYq8ARGkJx6XtFsdddBQgZE2nPR6CICZhawjA4Fb/chv+399kfR+MMMDGOQAAAABJRU5ErkJggg==\");\
  27770. background-repeat: no-repeat;\
  27771. background-position: 2px center;\
  27772. }\
  27773. .ace_gutter-cell.ace_warning {\
  27774. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAmVBMVEX///8AAAD///8AAAAAAABPSzb/5sAAAAB/blH/73z/ulkAAAAAAAD85pkAAAAAAAACAgP/vGz/rkDerGbGrV7/pkQICAf////e0IsAAAD/oED/qTvhrnUAAAD/yHD/njcAAADuv2r/nz//oTj/p064oGf/zHAAAAA9Nir/tFIAAAD/tlTiuWf/tkIAAACynXEAAAAAAAAtIRW7zBpBAAAAM3RSTlMAABR1m7RXO8Ln31Z36zT+neXe5OzooRDfn+TZ4p3h2hTf4t3k3ucyrN1K5+Xaks52Sfs9CXgrAAAAjklEQVR42o3PbQ+CIBQFYEwboPhSYgoYunIqqLn6/z8uYdH8Vmdnu9vz4WwXgN/xTPRD2+sgOcZjsge/whXZgUaYYvT8QnuJaUrjrHUQreGczuEafQCO/SJTufTbroWsPgsllVhq3wJEk2jUSzX3CUEDJC84707djRc5MTAQxoLgupWRwW6UB5fS++NV8AbOZgnsC7BpEAAAAABJRU5ErkJggg==\");\
  27775. background-position: 2px center;\
  27776. }\
  27777. .ace_gutter-cell.ace_info {\
  27778. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  27779. background-position: 2px center;\
  27780. }\
  27781. .ace_dark .ace_gutter-cell.ace_info {\
  27782. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  27783. }\
  27784. .ace_scrollbar {\
  27785. position: absolute;\
  27786. right: 0;\
  27787. bottom: 0;\
  27788. z-index: 6;\
  27789. }\
  27790. .ace_scrollbar-inner {\
  27791. position: absolute;\
  27792. cursor: text;\
  27793. left: 0;\
  27794. top: 0;\
  27795. }\
  27796. .ace_scrollbar-v{\
  27797. overflow-x: hidden;\
  27798. overflow-y: scroll;\
  27799. top: 0;\
  27800. }\
  27801. .ace_scrollbar-h {\
  27802. overflow-x: scroll;\
  27803. overflow-y: hidden;\
  27804. left: 0;\
  27805. }\
  27806. .ace_print-margin {\
  27807. position: absolute;\
  27808. height: 100%;\
  27809. }\
  27810. .ace_text-input {\
  27811. position: absolute;\
  27812. z-index: 0;\
  27813. width: 0.5em;\
  27814. height: 1em;\
  27815. opacity: 0;\
  27816. background: transparent;\
  27817. -moz-appearance: none;\
  27818. appearance: none;\
  27819. border: none;\
  27820. resize: none;\
  27821. outline: none;\
  27822. overflow: hidden;\
  27823. font: inherit;\
  27824. padding: 0 1px;\
  27825. margin: 0 -1px;\
  27826. text-indent: -1em;\
  27827. -ms-user-select: text;\
  27828. -moz-user-select: text;\
  27829. -webkit-user-select: text;\
  27830. user-select: text;\
  27831. white-space: pre!important;\
  27832. }\
  27833. .ace_text-input.ace_composition {\
  27834. background: inherit;\
  27835. color: inherit;\
  27836. z-index: 1000;\
  27837. opacity: 1;\
  27838. text-indent: 0;\
  27839. }\
  27840. .ace_layer {\
  27841. z-index: 1;\
  27842. position: absolute;\
  27843. overflow: hidden;\
  27844. word-wrap: normal;\
  27845. white-space: pre;\
  27846. height: 100%;\
  27847. width: 100%;\
  27848. -moz-box-sizing: border-box;\
  27849. -webkit-box-sizing: border-box;\
  27850. box-sizing: border-box;\
  27851. pointer-events: none;\
  27852. }\
  27853. .ace_gutter-layer {\
  27854. position: relative;\
  27855. width: auto;\
  27856. text-align: right;\
  27857. pointer-events: auto;\
  27858. }\
  27859. .ace_text-layer {\
  27860. font: inherit !important;\
  27861. }\
  27862. .ace_cjk {\
  27863. display: inline-block;\
  27864. text-align: center;\
  27865. }\
  27866. .ace_cursor-layer {\
  27867. z-index: 4;\
  27868. }\
  27869. .ace_cursor {\
  27870. z-index: 4;\
  27871. position: absolute;\
  27872. -moz-box-sizing: border-box;\
  27873. -webkit-box-sizing: border-box;\
  27874. box-sizing: border-box;\
  27875. border-left: 2px solid;\
  27876. transform: translatez(0);\
  27877. }\
  27878. .ace_slim-cursors .ace_cursor {\
  27879. border-left-width: 1px;\
  27880. }\
  27881. .ace_overwrite-cursors .ace_cursor {\
  27882. border-left-width: 0;\
  27883. border-bottom: 1px solid;\
  27884. }\
  27885. .ace_hidden-cursors .ace_cursor {\
  27886. opacity: 0.2;\
  27887. }\
  27888. .ace_smooth-blinking .ace_cursor {\
  27889. -webkit-transition: opacity 0.18s;\
  27890. transition: opacity 0.18s;\
  27891. }\
  27892. .ace_editor.ace_multiselect .ace_cursor {\
  27893. border-left-width: 1px;\
  27894. }\
  27895. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  27896. position: absolute;\
  27897. z-index: 3;\
  27898. }\
  27899. .ace_marker-layer .ace_selection {\
  27900. position: absolute;\
  27901. z-index: 5;\
  27902. }\
  27903. .ace_marker-layer .ace_bracket {\
  27904. position: absolute;\
  27905. z-index: 6;\
  27906. }\
  27907. .ace_marker-layer .ace_active-line {\
  27908. position: absolute;\
  27909. z-index: 2;\
  27910. }\
  27911. .ace_marker-layer .ace_selected-word {\
  27912. position: absolute;\
  27913. z-index: 4;\
  27914. -moz-box-sizing: border-box;\
  27915. -webkit-box-sizing: border-box;\
  27916. box-sizing: border-box;\
  27917. }\
  27918. .ace_line .ace_fold {\
  27919. -moz-box-sizing: border-box;\
  27920. -webkit-box-sizing: border-box;\
  27921. box-sizing: border-box;\
  27922. display: inline-block;\
  27923. height: 11px;\
  27924. margin-top: -2px;\
  27925. vertical-align: middle;\
  27926. background-image:\
  27927. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  27928. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  27929. background-repeat: no-repeat, repeat-x;\
  27930. background-position: center center, top left;\
  27931. color: transparent;\
  27932. border: 1px solid black;\
  27933. border-radius: 2px;\
  27934. cursor: pointer;\
  27935. pointer-events: auto;\
  27936. }\
  27937. .ace_dark .ace_fold {\
  27938. }\
  27939. .ace_fold:hover{\
  27940. background-image:\
  27941. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  27942. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  27943. }\
  27944. .ace_tooltip {\
  27945. background-color: #FFF;\
  27946. background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));\
  27947. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  27948. border: 1px solid gray;\
  27949. border-radius: 1px;\
  27950. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  27951. color: black;\
  27952. max-width: 100%;\
  27953. padding: 3px 4px;\
  27954. position: fixed;\
  27955. z-index: 999999;\
  27956. -moz-box-sizing: border-box;\
  27957. -webkit-box-sizing: border-box;\
  27958. box-sizing: border-box;\
  27959. cursor: default;\
  27960. white-space: pre;\
  27961. word-wrap: break-word;\
  27962. line-height: normal;\
  27963. font-style: normal;\
  27964. font-weight: normal;\
  27965. letter-spacing: normal;\
  27966. pointer-events: none;\
  27967. }\
  27968. .ace_folding-enabled > .ace_gutter-cell {\
  27969. padding-right: 13px;\
  27970. }\
  27971. .ace_fold-widget {\
  27972. -moz-box-sizing: border-box;\
  27973. -webkit-box-sizing: border-box;\
  27974. box-sizing: border-box;\
  27975. margin: 0 -12px 0 1px;\
  27976. display: none;\
  27977. width: 11px;\
  27978. vertical-align: top;\
  27979. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  27980. background-repeat: no-repeat;\
  27981. background-position: center;\
  27982. border-radius: 3px;\
  27983. border: 1px solid transparent;\
  27984. cursor: pointer;\
  27985. }\
  27986. .ace_folding-enabled .ace_fold-widget {\
  27987. display: inline-block; \
  27988. }\
  27989. .ace_fold-widget.ace_end {\
  27990. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  27991. }\
  27992. .ace_fold-widget.ace_closed {\
  27993. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  27994. }\
  27995. .ace_fold-widget:hover {\
  27996. border: 1px solid rgba(0, 0, 0, 0.3);\
  27997. background-color: rgba(255, 255, 255, 0.2);\
  27998. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  27999. }\
  28000. .ace_fold-widget:active {\
  28001. border: 1px solid rgba(0, 0, 0, 0.4);\
  28002. background-color: rgba(0, 0, 0, 0.05);\
  28003. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  28004. }\
  28005. .ace_dark .ace_fold-widget {\
  28006. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  28007. }\
  28008. .ace_dark .ace_fold-widget.ace_end {\
  28009. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  28010. }\
  28011. .ace_dark .ace_fold-widget.ace_closed {\
  28012. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  28013. }\
  28014. .ace_dark .ace_fold-widget:hover {\
  28015. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  28016. background-color: rgba(255, 255, 255, 0.1);\
  28017. }\
  28018. .ace_dark .ace_fold-widget:active {\
  28019. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  28020. }\
  28021. .ace_fold-widget.ace_invalid {\
  28022. background-color: #FFB4B4;\
  28023. border-color: #DE5555;\
  28024. }\
  28025. .ace_fade-fold-widgets .ace_fold-widget {\
  28026. -webkit-transition: opacity 0.4s ease 0.05s;\
  28027. transition: opacity 0.4s ease 0.05s;\
  28028. opacity: 0;\
  28029. }\
  28030. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  28031. -webkit-transition: opacity 0.05s ease 0.05s;\
  28032. transition: opacity 0.05s ease 0.05s;\
  28033. opacity:1;\
  28034. }\
  28035. .ace_underline {\
  28036. text-decoration: underline;\
  28037. }\
  28038. .ace_bold {\
  28039. font-weight: bold;\
  28040. }\
  28041. .ace_nobold .ace_bold {\
  28042. font-weight: normal;\
  28043. }\
  28044. .ace_italic {\
  28045. font-style: italic;\
  28046. }\
  28047. .ace_error-marker {\
  28048. background-color: rgba(255, 0, 0,0.2);\
  28049. position: absolute;\
  28050. z-index: 9;\
  28051. }\
  28052. .ace_highlight-marker {\
  28053. background-color: rgba(255, 255, 0,0.2);\
  28054. position: absolute;\
  28055. z-index: 8;\
  28056. }\
  28057. .ace_br1 {border-top-left-radius : 3px;}\
  28058. .ace_br2 {border-top-right-radius : 3px;}\
  28059. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  28060. .ace_br4 {border-bottom-right-radius: 3px;}\
  28061. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  28062. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  28063. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  28064. .ace_br8 {border-bottom-left-radius : 3px;}\
  28065. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  28066. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  28067. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  28068. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  28069. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  28070. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  28071. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  28072. ";
  28073. dom.importCssString(editorCss, "ace_editor.css");
  28074. var VirtualRenderer = function(container, theme) {
  28075. var _self = this;
  28076. this.container = container || dom.createElement("div");
  28077. this.$keepTextAreaAtCursor = !useragent.isOldIE;
  28078. dom.addCssClass(this.container, "ace_editor");
  28079. this.setTheme(theme);
  28080. this.$gutter = dom.createElement("div");
  28081. this.$gutter.className = "ace_gutter";
  28082. this.container.appendChild(this.$gutter);
  28083. this.scroller = dom.createElement("div");
  28084. this.scroller.className = "ace_scroller";
  28085. this.container.appendChild(this.scroller);
  28086. this.content = dom.createElement("div");
  28087. this.content.className = "ace_content";
  28088. this.scroller.appendChild(this.content);
  28089. this.$gutterLayer = new GutterLayer(this.$gutter);
  28090. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  28091. this.$markerBack = new MarkerLayer(this.content);
  28092. var textLayer = this.$textLayer = new TextLayer(this.content);
  28093. this.canvas = textLayer.element;
  28094. this.$markerFront = new MarkerLayer(this.content);
  28095. this.$cursorLayer = new CursorLayer(this.content);
  28096. this.$horizScroll = false;
  28097. this.$vScroll = false;
  28098. this.scrollBar =
  28099. this.scrollBarV = new VScrollBar(this.container, this);
  28100. this.scrollBarH = new HScrollBar(this.container, this);
  28101. this.scrollBarV.addEventListener("scroll", function(e) {
  28102. if (!_self.$scrollAnimation)
  28103. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  28104. });
  28105. this.scrollBarH.addEventListener("scroll", function(e) {
  28106. if (!_self.$scrollAnimation)
  28107. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  28108. });
  28109. this.scrollTop = 0;
  28110. this.scrollLeft = 0;
  28111. this.cursorPos = {
  28112. row : 0,
  28113. column : 0
  28114. };
  28115. this.$fontMetrics = new FontMetrics(this.container);
  28116. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  28117. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  28118. _self.updateCharacterSize();
  28119. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  28120. _self._signal("changeCharacterSize", e);
  28121. });
  28122. this.$size = {
  28123. width: 0,
  28124. height: 0,
  28125. scrollerHeight: 0,
  28126. scrollerWidth: 0,
  28127. $dirty: true
  28128. };
  28129. this.layerConfig = {
  28130. width : 1,
  28131. padding : 0,
  28132. firstRow : 0,
  28133. firstRowScreen: 0,
  28134. lastRow : 0,
  28135. lineHeight : 0,
  28136. characterWidth : 0,
  28137. minHeight : 1,
  28138. maxHeight : 1,
  28139. offset : 0,
  28140. height : 1,
  28141. gutterOffset: 1
  28142. };
  28143. this.scrollMargin = {
  28144. left: 0,
  28145. right: 0,
  28146. top: 0,
  28147. bottom: 0,
  28148. v: 0,
  28149. h: 0
  28150. };
  28151. this.$loop = new RenderLoop(
  28152. this.$renderChanges.bind(this),
  28153. this.container.ownerDocument.defaultView
  28154. );
  28155. this.$loop.schedule(this.CHANGE_FULL);
  28156. this.updateCharacterSize();
  28157. this.setPadding(4);
  28158. config.resetOptions(this);
  28159. config._emit("renderer", this);
  28160. };
  28161. (function() {
  28162. this.CHANGE_CURSOR = 1;
  28163. this.CHANGE_MARKER = 2;
  28164. this.CHANGE_GUTTER = 4;
  28165. this.CHANGE_SCROLL = 8;
  28166. this.CHANGE_LINES = 16;
  28167. this.CHANGE_TEXT = 32;
  28168. this.CHANGE_SIZE = 64;
  28169. this.CHANGE_MARKER_BACK = 128;
  28170. this.CHANGE_MARKER_FRONT = 256;
  28171. this.CHANGE_FULL = 512;
  28172. this.CHANGE_H_SCROLL = 1024;
  28173. oop.implement(this, EventEmitter);
  28174. this.updateCharacterSize = function() {
  28175. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  28176. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  28177. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  28178. }
  28179. this.layerConfig.characterWidth =
  28180. this.characterWidth = this.$textLayer.getCharacterWidth();
  28181. this.layerConfig.lineHeight =
  28182. this.lineHeight = this.$textLayer.getLineHeight();
  28183. this.$updatePrintMargin();
  28184. };
  28185. this.setSession = function(session) {
  28186. if (this.session)
  28187. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  28188. this.session = session;
  28189. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  28190. session.setScrollTop(-this.scrollMargin.top);
  28191. this.$cursorLayer.setSession(session);
  28192. this.$markerBack.setSession(session);
  28193. this.$markerFront.setSession(session);
  28194. this.$gutterLayer.setSession(session);
  28195. this.$textLayer.setSession(session);
  28196. if (!session)
  28197. return;
  28198. this.$loop.schedule(this.CHANGE_FULL);
  28199. this.session.$setFontMetrics(this.$fontMetrics);
  28200. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  28201. this.onChangeNewLineMode()
  28202. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  28203. };
  28204. this.updateLines = function(firstRow, lastRow, force) {
  28205. if (lastRow === undefined)
  28206. lastRow = Infinity;
  28207. if (!this.$changedLines) {
  28208. this.$changedLines = {
  28209. firstRow: firstRow,
  28210. lastRow: lastRow
  28211. };
  28212. }
  28213. else {
  28214. if (this.$changedLines.firstRow > firstRow)
  28215. this.$changedLines.firstRow = firstRow;
  28216. if (this.$changedLines.lastRow < lastRow)
  28217. this.$changedLines.lastRow = lastRow;
  28218. }
  28219. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  28220. if (force)
  28221. this.$changedLines.lastRow = this.layerConfig.lastRow;
  28222. else
  28223. return;
  28224. }
  28225. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  28226. return;
  28227. this.$loop.schedule(this.CHANGE_LINES);
  28228. };
  28229. this.onChangeNewLineMode = function() {
  28230. this.$loop.schedule(this.CHANGE_TEXT);
  28231. this.$textLayer.$updateEolChar();
  28232. };
  28233. this.onChangeTabSize = function() {
  28234. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  28235. this.$textLayer.onChangeTabSize();
  28236. };
  28237. this.updateText = function() {
  28238. this.$loop.schedule(this.CHANGE_TEXT);
  28239. };
  28240. this.updateFull = function(force) {
  28241. if (force)
  28242. this.$renderChanges(this.CHANGE_FULL, true);
  28243. else
  28244. this.$loop.schedule(this.CHANGE_FULL);
  28245. };
  28246. this.updateFontSize = function() {
  28247. this.$textLayer.checkForSizeChanges();
  28248. };
  28249. this.$changes = 0;
  28250. this.$updateSizeAsync = function() {
  28251. if (this.$loop.pending)
  28252. this.$size.$dirty = true;
  28253. else
  28254. this.onResize();
  28255. };
  28256. this.onResize = function(force, gutterWidth, width, height) {
  28257. if (this.resizing > 2)
  28258. return;
  28259. else if (this.resizing > 0)
  28260. this.resizing++;
  28261. else
  28262. this.resizing = force ? 1 : 0;
  28263. var el = this.container;
  28264. if (!height)
  28265. height = el.clientHeight || el.scrollHeight;
  28266. if (!width)
  28267. width = el.clientWidth || el.scrollWidth;
  28268. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  28269. if (!this.$size.scrollerHeight || (!width && !height))
  28270. return this.resizing = 0;
  28271. if (force)
  28272. this.$gutterLayer.$padding = null;
  28273. if (force)
  28274. this.$renderChanges(changes | this.$changes, true);
  28275. else
  28276. this.$loop.schedule(changes | this.$changes);
  28277. if (this.resizing)
  28278. this.resizing = 0;
  28279. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  28280. };
  28281. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  28282. height -= (this.$extraHeight || 0);
  28283. var changes = 0;
  28284. var size = this.$size;
  28285. var oldSize = {
  28286. width: size.width,
  28287. height: size.height,
  28288. scrollerHeight: size.scrollerHeight,
  28289. scrollerWidth: size.scrollerWidth
  28290. };
  28291. if (height && (force || size.height != height)) {
  28292. size.height = height;
  28293. changes |= this.CHANGE_SIZE;
  28294. size.scrollerHeight = size.height;
  28295. if (this.$horizScroll)
  28296. size.scrollerHeight -= this.scrollBarH.getHeight();
  28297. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  28298. changes = changes | this.CHANGE_SCROLL;
  28299. }
  28300. if (width && (force || size.width != width)) {
  28301. changes |= this.CHANGE_SIZE;
  28302. size.width = width;
  28303. if (gutterWidth == null)
  28304. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  28305. this.gutterWidth = gutterWidth;
  28306. this.scrollBarH.element.style.left =
  28307. this.scroller.style.left = gutterWidth + "px";
  28308. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
  28309. this.scrollBarH.element.style.right =
  28310. this.scroller.style.right = this.scrollBarV.getWidth() + "px";
  28311. this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
  28312. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
  28313. changes |= this.CHANGE_FULL;
  28314. }
  28315. size.$dirty = !width || !height;
  28316. if (changes)
  28317. this._signal("resize", oldSize);
  28318. return changes;
  28319. };
  28320. this.onGutterResize = function() {
  28321. var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  28322. if (gutterWidth != this.gutterWidth)
  28323. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  28324. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  28325. this.$loop.schedule(this.CHANGE_FULL);
  28326. } else if (this.$size.$dirty) {
  28327. this.$loop.schedule(this.CHANGE_FULL);
  28328. } else {
  28329. this.$computeLayerConfig();
  28330. this.$loop.schedule(this.CHANGE_MARKER);
  28331. }
  28332. };
  28333. this.adjustWrapLimit = function() {
  28334. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  28335. var limit = Math.floor(availableWidth / this.characterWidth);
  28336. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  28337. };
  28338. this.setAnimatedScroll = function(shouldAnimate){
  28339. this.setOption("animatedScroll", shouldAnimate);
  28340. };
  28341. this.getAnimatedScroll = function() {
  28342. return this.$animatedScroll;
  28343. };
  28344. this.setShowInvisibles = function(showInvisibles) {
  28345. this.setOption("showInvisibles", showInvisibles);
  28346. };
  28347. this.getShowInvisibles = function() {
  28348. return this.getOption("showInvisibles");
  28349. };
  28350. this.getDisplayIndentGuides = function() {
  28351. return this.getOption("displayIndentGuides");
  28352. };
  28353. this.setDisplayIndentGuides = function(display) {
  28354. this.setOption("displayIndentGuides", display);
  28355. };
  28356. this.setShowPrintMargin = function(showPrintMargin) {
  28357. this.setOption("showPrintMargin", showPrintMargin);
  28358. };
  28359. this.getShowPrintMargin = function() {
  28360. return this.getOption("showPrintMargin");
  28361. };
  28362. this.setPrintMarginColumn = function(showPrintMargin) {
  28363. this.setOption("printMarginColumn", showPrintMargin);
  28364. };
  28365. this.getPrintMarginColumn = function() {
  28366. return this.getOption("printMarginColumn");
  28367. };
  28368. this.getShowGutter = function(){
  28369. return this.getOption("showGutter");
  28370. };
  28371. this.setShowGutter = function(show){
  28372. return this.setOption("showGutter", show);
  28373. };
  28374. this.getFadeFoldWidgets = function(){
  28375. return this.getOption("fadeFoldWidgets")
  28376. };
  28377. this.setFadeFoldWidgets = function(show) {
  28378. this.setOption("fadeFoldWidgets", show);
  28379. };
  28380. this.setHighlightGutterLine = function(shouldHighlight) {
  28381. this.setOption("highlightGutterLine", shouldHighlight);
  28382. };
  28383. this.getHighlightGutterLine = function() {
  28384. return this.getOption("highlightGutterLine");
  28385. };
  28386. this.$updateGutterLineHighlight = function() {
  28387. var pos = this.$cursorLayer.$pixelPos;
  28388. var height = this.layerConfig.lineHeight;
  28389. if (this.session.getUseWrapMode()) {
  28390. var cursor = this.session.selection.getCursor();
  28391. cursor.column = 0;
  28392. pos = this.$cursorLayer.getPixelPosition(cursor, true);
  28393. height *= this.session.getRowLength(cursor.row);
  28394. }
  28395. this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px";
  28396. this.$gutterLineHighlight.style.height = height + "px";
  28397. };
  28398. this.$updatePrintMargin = function() {
  28399. if (!this.$showPrintMargin && !this.$printMarginEl)
  28400. return;
  28401. if (!this.$printMarginEl) {
  28402. var containerEl = dom.createElement("div");
  28403. containerEl.className = "ace_layer ace_print-margin-layer";
  28404. this.$printMarginEl = dom.createElement("div");
  28405. this.$printMarginEl.className = "ace_print-margin";
  28406. containerEl.appendChild(this.$printMarginEl);
  28407. this.content.insertBefore(containerEl, this.content.firstChild);
  28408. }
  28409. var style = this.$printMarginEl.style;
  28410. style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
  28411. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  28412. if (this.session && this.session.$wrap == -1)
  28413. this.adjustWrapLimit();
  28414. };
  28415. this.getContainerElement = function() {
  28416. return this.container;
  28417. };
  28418. this.getMouseEventTarget = function() {
  28419. return this.scroller;
  28420. };
  28421. this.getTextAreaContainer = function() {
  28422. return this.container;
  28423. };
  28424. this.$moveTextAreaToCursor = function() {
  28425. if (!this.$keepTextAreaAtCursor)
  28426. return;
  28427. var config = this.layerConfig;
  28428. var posTop = this.$cursorLayer.$pixelPos.top;
  28429. var posLeft = this.$cursorLayer.$pixelPos.left;
  28430. posTop -= config.offset;
  28431. var style = this.textarea.style;
  28432. var h = this.lineHeight;
  28433. if (posTop < 0 || posTop > config.height - h) {
  28434. style.top = style.left = "0";
  28435. return;
  28436. }
  28437. var w = this.characterWidth;
  28438. if (this.$composition) {
  28439. var val = this.textarea.value.replace(/^\x01+/, "");
  28440. w *= (this.session.$getStringScreenWidth(val)[0]+2);
  28441. h += 2;
  28442. }
  28443. posLeft -= this.scrollLeft;
  28444. if (posLeft > this.$size.scrollerWidth - w)
  28445. posLeft = this.$size.scrollerWidth - w;
  28446. posLeft += this.gutterWidth;
  28447. style.height = h + "px";
  28448. style.width = w + "px";
  28449. style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px";
  28450. style.top = Math.min(posTop, this.$size.height - h) + "px";
  28451. };
  28452. this.getFirstVisibleRow = function() {
  28453. return this.layerConfig.firstRow;
  28454. };
  28455. this.getFirstFullyVisibleRow = function() {
  28456. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  28457. };
  28458. this.getLastFullyVisibleRow = function() {
  28459. var config = this.layerConfig;
  28460. var lastRow = config.lastRow
  28461. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  28462. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  28463. return lastRow - 1;
  28464. return lastRow;
  28465. };
  28466. this.getLastVisibleRow = function() {
  28467. return this.layerConfig.lastRow;
  28468. };
  28469. this.$padding = null;
  28470. this.setPadding = function(padding) {
  28471. this.$padding = padding;
  28472. this.$textLayer.setPadding(padding);
  28473. this.$cursorLayer.setPadding(padding);
  28474. this.$markerFront.setPadding(padding);
  28475. this.$markerBack.setPadding(padding);
  28476. this.$loop.schedule(this.CHANGE_FULL);
  28477. this.$updatePrintMargin();
  28478. };
  28479. this.setScrollMargin = function(top, bottom, left, right) {
  28480. var sm = this.scrollMargin;
  28481. sm.top = top|0;
  28482. sm.bottom = bottom|0;
  28483. sm.right = right|0;
  28484. sm.left = left|0;
  28485. sm.v = sm.top + sm.bottom;
  28486. sm.h = sm.left + sm.right;
  28487. if (sm.top && this.scrollTop <= 0 && this.session)
  28488. this.session.setScrollTop(-sm.top);
  28489. this.updateFull();
  28490. };
  28491. this.getHScrollBarAlwaysVisible = function() {
  28492. return this.$hScrollBarAlwaysVisible;
  28493. };
  28494. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  28495. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  28496. };
  28497. this.getVScrollBarAlwaysVisible = function() {
  28498. return this.$vScrollBarAlwaysVisible;
  28499. };
  28500. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  28501. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  28502. };
  28503. this.$updateScrollBarV = function() {
  28504. var scrollHeight = this.layerConfig.maxHeight;
  28505. var scrollerHeight = this.$size.scrollerHeight;
  28506. if (!this.$maxLines && this.$scrollPastEnd) {
  28507. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  28508. if (this.scrollTop > scrollHeight - scrollerHeight) {
  28509. scrollHeight = this.scrollTop + scrollerHeight;
  28510. this.scrollBarV.scrollTop = null;
  28511. }
  28512. }
  28513. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  28514. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  28515. };
  28516. this.$updateScrollBarH = function() {
  28517. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  28518. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  28519. };
  28520. this.$frozen = false;
  28521. this.freeze = function() {
  28522. this.$frozen = true;
  28523. };
  28524. this.unfreeze = function() {
  28525. this.$frozen = false;
  28526. };
  28527. this.$renderChanges = function(changes, force) {
  28528. if (this.$changes) {
  28529. changes |= this.$changes;
  28530. this.$changes = 0;
  28531. }
  28532. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  28533. this.$changes |= changes;
  28534. return;
  28535. }
  28536. if (this.$size.$dirty) {
  28537. this.$changes |= changes;
  28538. return this.onResize(true);
  28539. }
  28540. if (!this.lineHeight) {
  28541. this.$textLayer.checkForSizeChanges();
  28542. }
  28543. this._signal("beforeRender");
  28544. var config = this.layerConfig;
  28545. if (changes & this.CHANGE_FULL ||
  28546. changes & this.CHANGE_SIZE ||
  28547. changes & this.CHANGE_TEXT ||
  28548. changes & this.CHANGE_LINES ||
  28549. changes & this.CHANGE_SCROLL ||
  28550. changes & this.CHANGE_H_SCROLL
  28551. ) {
  28552. changes |= this.$computeLayerConfig();
  28553. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  28554. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  28555. if (st > 0) {
  28556. this.scrollTop = st;
  28557. changes = changes | this.CHANGE_SCROLL;
  28558. changes |= this.$computeLayerConfig();
  28559. }
  28560. }
  28561. config = this.layerConfig;
  28562. this.$updateScrollBarV();
  28563. if (changes & this.CHANGE_H_SCROLL)
  28564. this.$updateScrollBarH();
  28565. this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
  28566. this.content.style.marginTop = (-config.offset) + "px";
  28567. this.content.style.width = config.width + 2 * this.$padding + "px";
  28568. this.content.style.height = config.minHeight + "px";
  28569. }
  28570. if (changes & this.CHANGE_H_SCROLL) {
  28571. this.content.style.marginLeft = -this.scrollLeft + "px";
  28572. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  28573. }
  28574. if (changes & this.CHANGE_FULL) {
  28575. this.$textLayer.update(config);
  28576. if (this.$showGutter)
  28577. this.$gutterLayer.update(config);
  28578. this.$markerBack.update(config);
  28579. this.$markerFront.update(config);
  28580. this.$cursorLayer.update(config);
  28581. this.$moveTextAreaToCursor();
  28582. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  28583. this._signal("afterRender");
  28584. return;
  28585. }
  28586. if (changes & this.CHANGE_SCROLL) {
  28587. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  28588. this.$textLayer.update(config);
  28589. else
  28590. this.$textLayer.scrollLines(config);
  28591. if (this.$showGutter)
  28592. this.$gutterLayer.update(config);
  28593. this.$markerBack.update(config);
  28594. this.$markerFront.update(config);
  28595. this.$cursorLayer.update(config);
  28596. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  28597. this.$moveTextAreaToCursor();
  28598. this._signal("afterRender");
  28599. return;
  28600. }
  28601. if (changes & this.CHANGE_TEXT) {
  28602. this.$textLayer.update(config);
  28603. if (this.$showGutter)
  28604. this.$gutterLayer.update(config);
  28605. }
  28606. else if (changes & this.CHANGE_LINES) {
  28607. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  28608. this.$gutterLayer.update(config);
  28609. }
  28610. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  28611. if (this.$showGutter)
  28612. this.$gutterLayer.update(config);
  28613. }
  28614. if (changes & this.CHANGE_CURSOR) {
  28615. this.$cursorLayer.update(config);
  28616. this.$moveTextAreaToCursor();
  28617. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  28618. }
  28619. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  28620. this.$markerFront.update(config);
  28621. }
  28622. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  28623. this.$markerBack.update(config);
  28624. }
  28625. this._signal("afterRender");
  28626. };
  28627. this.$autosize = function() {
  28628. var height = this.session.getScreenLength() * this.lineHeight;
  28629. var maxHeight = this.$maxLines * this.lineHeight;
  28630. var desiredHeight = Math.max(
  28631. (this.$minLines||1) * this.lineHeight,
  28632. Math.min(maxHeight, height)
  28633. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  28634. if (this.$horizScroll)
  28635. desiredHeight += this.scrollBarH.getHeight();
  28636. var vScroll = height > maxHeight;
  28637. if (desiredHeight != this.desiredHeight ||
  28638. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  28639. if (vScroll != this.$vScroll) {
  28640. this.$vScroll = vScroll;
  28641. this.scrollBarV.setVisible(vScroll);
  28642. }
  28643. var w = this.container.clientWidth;
  28644. this.container.style.height = desiredHeight + "px";
  28645. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  28646. this.desiredHeight = desiredHeight;
  28647. this._signal("autosize");
  28648. }
  28649. };
  28650. this.$computeLayerConfig = function() {
  28651. var session = this.session;
  28652. var size = this.$size;
  28653. var hideScrollbars = size.height <= 2 * this.lineHeight;
  28654. var screenLines = this.session.getScreenLength();
  28655. var maxHeight = screenLines * this.lineHeight;
  28656. var longestLine = this.$getLongestLine();
  28657. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  28658. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  28659. var hScrollChanged = this.$horizScroll !== horizScroll;
  28660. if (hScrollChanged) {
  28661. this.$horizScroll = horizScroll;
  28662. this.scrollBarH.setVisible(horizScroll);
  28663. }
  28664. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  28665. if (this.$maxLines && this.lineHeight > 1)
  28666. this.$autosize();
  28667. var offset = this.scrollTop % this.lineHeight;
  28668. var minHeight = size.scrollerHeight + this.lineHeight;
  28669. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  28670. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  28671. : 0;
  28672. maxHeight += scrollPastEnd;
  28673. var sm = this.scrollMargin;
  28674. this.session.setScrollTop(Math.max(-sm.top,
  28675. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  28676. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  28677. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  28678. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  28679. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  28680. var vScrollChanged = vScrollBefore !== vScroll;
  28681. if (vScrollChanged) {
  28682. this.$vScroll = vScroll;
  28683. this.scrollBarV.setVisible(vScroll);
  28684. }
  28685. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  28686. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  28687. var lastRow = firstRow + lineCount;
  28688. var firstRowScreen, firstRowHeight;
  28689. var lineHeight = this.lineHeight;
  28690. firstRow = session.screenToDocumentRow(firstRow, 0);
  28691. var foldLine = session.getFoldLine(firstRow);
  28692. if (foldLine) {
  28693. firstRow = foldLine.start.row;
  28694. }
  28695. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  28696. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  28697. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  28698. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  28699. firstRowHeight;
  28700. offset = this.scrollTop - firstRowScreen * lineHeight;
  28701. var changes = 0;
  28702. if (this.layerConfig.width != longestLine)
  28703. changes = this.CHANGE_H_SCROLL;
  28704. if (hScrollChanged || vScrollChanged) {
  28705. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  28706. this._signal("scrollbarVisibilityChanged");
  28707. if (vScrollChanged)
  28708. longestLine = this.$getLongestLine();
  28709. }
  28710. this.layerConfig = {
  28711. width : longestLine,
  28712. padding : this.$padding,
  28713. firstRow : firstRow,
  28714. firstRowScreen: firstRowScreen,
  28715. lastRow : lastRow,
  28716. lineHeight : lineHeight,
  28717. characterWidth : this.characterWidth,
  28718. minHeight : minHeight,
  28719. maxHeight : maxHeight,
  28720. offset : offset,
  28721. gutterOffset : Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)),
  28722. height : this.$size.scrollerHeight
  28723. };
  28724. return changes;
  28725. };
  28726. this.$updateLines = function() {
  28727. var firstRow = this.$changedLines.firstRow;
  28728. var lastRow = this.$changedLines.lastRow;
  28729. this.$changedLines = null;
  28730. var layerConfig = this.layerConfig;
  28731. if (firstRow > layerConfig.lastRow + 1) { return; }
  28732. if (lastRow < layerConfig.firstRow) { return; }
  28733. if (lastRow === Infinity) {
  28734. if (this.$showGutter)
  28735. this.$gutterLayer.update(layerConfig);
  28736. this.$textLayer.update(layerConfig);
  28737. return;
  28738. }
  28739. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  28740. return true;
  28741. };
  28742. this.$getLongestLine = function() {
  28743. var charCount = this.session.getScreenWidth();
  28744. if (this.showInvisibles && !this.session.$useWrapMode)
  28745. charCount += 1;
  28746. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  28747. };
  28748. this.updateFrontMarkers = function() {
  28749. this.$markerFront.setMarkers(this.session.getMarkers(true));
  28750. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  28751. };
  28752. this.updateBackMarkers = function() {
  28753. this.$markerBack.setMarkers(this.session.getMarkers());
  28754. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  28755. };
  28756. this.addGutterDecoration = function(row, className){
  28757. this.$gutterLayer.addGutterDecoration(row, className);
  28758. };
  28759. this.removeGutterDecoration = function(row, className){
  28760. this.$gutterLayer.removeGutterDecoration(row, className);
  28761. };
  28762. this.updateBreakpoints = function(rows) {
  28763. this.$loop.schedule(this.CHANGE_GUTTER);
  28764. };
  28765. this.setAnnotations = function(annotations) {
  28766. this.$gutterLayer.setAnnotations(annotations);
  28767. this.$loop.schedule(this.CHANGE_GUTTER);
  28768. };
  28769. this.updateCursor = function() {
  28770. this.$loop.schedule(this.CHANGE_CURSOR);
  28771. };
  28772. this.hideCursor = function() {
  28773. this.$cursorLayer.hideCursor();
  28774. };
  28775. this.showCursor = function() {
  28776. this.$cursorLayer.showCursor();
  28777. };
  28778. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  28779. this.scrollCursorIntoView(anchor, offset);
  28780. this.scrollCursorIntoView(lead, offset);
  28781. };
  28782. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  28783. if (this.$size.scrollerHeight === 0)
  28784. return;
  28785. var pos = this.$cursorLayer.getPixelPosition(cursor);
  28786. var left = pos.left;
  28787. var top = pos.top;
  28788. var topMargin = $viewMargin && $viewMargin.top || 0;
  28789. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  28790. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  28791. if (scrollTop + topMargin > top) {
  28792. if (offset && scrollTop + topMargin > top + this.lineHeight)
  28793. top -= offset * this.$size.scrollerHeight;
  28794. if (top === 0)
  28795. top = -this.scrollMargin.top;
  28796. this.session.setScrollTop(top);
  28797. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  28798. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  28799. top += offset * this.$size.scrollerHeight;
  28800. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  28801. }
  28802. var scrollLeft = this.scrollLeft;
  28803. if (scrollLeft > left) {
  28804. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  28805. left = -this.scrollMargin.left;
  28806. this.session.setScrollLeft(left);
  28807. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  28808. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  28809. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  28810. this.session.setScrollLeft(0);
  28811. }
  28812. };
  28813. this.getScrollTop = function() {
  28814. return this.session.getScrollTop();
  28815. };
  28816. this.getScrollLeft = function() {
  28817. return this.session.getScrollLeft();
  28818. };
  28819. this.getScrollTopRow = function() {
  28820. return this.scrollTop / this.lineHeight;
  28821. };
  28822. this.getScrollBottomRow = function() {
  28823. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  28824. };
  28825. this.scrollToRow = function(row) {
  28826. this.session.setScrollTop(row * this.lineHeight);
  28827. };
  28828. this.alignCursor = function(cursor, alignment) {
  28829. if (typeof cursor == "number")
  28830. cursor = {row: cursor, column: 0};
  28831. var pos = this.$cursorLayer.getPixelPosition(cursor);
  28832. var h = this.$size.scrollerHeight - this.lineHeight;
  28833. var offset = pos.top - h * (alignment || 0);
  28834. this.session.setScrollTop(offset);
  28835. return offset;
  28836. };
  28837. this.STEPS = 8;
  28838. this.$calcSteps = function(fromValue, toValue){
  28839. var i = 0;
  28840. var l = this.STEPS;
  28841. var steps = [];
  28842. var func = function(t, x_min, dx) {
  28843. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  28844. };
  28845. for (i = 0; i < l; ++i)
  28846. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  28847. return steps;
  28848. };
  28849. this.scrollToLine = function(line, center, animate, callback) {
  28850. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  28851. var offset = pos.top;
  28852. if (center)
  28853. offset -= this.$size.scrollerHeight / 2;
  28854. var initialScroll = this.scrollTop;
  28855. this.session.setScrollTop(offset);
  28856. if (animate !== false)
  28857. this.animateScrolling(initialScroll, callback);
  28858. };
  28859. this.animateScrolling = function(fromValue, callback) {
  28860. var toValue = this.scrollTop;
  28861. if (!this.$animatedScroll)
  28862. return;
  28863. var _self = this;
  28864. if (fromValue == toValue)
  28865. return;
  28866. if (this.$scrollAnimation) {
  28867. var oldSteps = this.$scrollAnimation.steps;
  28868. if (oldSteps.length) {
  28869. fromValue = oldSteps[0];
  28870. if (fromValue == toValue)
  28871. return;
  28872. }
  28873. }
  28874. var steps = _self.$calcSteps(fromValue, toValue);
  28875. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  28876. clearInterval(this.$timer);
  28877. _self.session.setScrollTop(steps.shift());
  28878. _self.session.$scrollTop = toValue;
  28879. this.$timer = setInterval(function() {
  28880. if (steps.length) {
  28881. _self.session.setScrollTop(steps.shift());
  28882. _self.session.$scrollTop = toValue;
  28883. } else if (toValue != null) {
  28884. _self.session.$scrollTop = -1;
  28885. _self.session.setScrollTop(toValue);
  28886. toValue = null;
  28887. } else {
  28888. _self.$timer = clearInterval(_self.$timer);
  28889. _self.$scrollAnimation = null;
  28890. callback && callback();
  28891. }
  28892. }, 10);
  28893. };
  28894. this.scrollToY = function(scrollTop) {
  28895. if (this.scrollTop !== scrollTop) {
  28896. this.$loop.schedule(this.CHANGE_SCROLL);
  28897. this.scrollTop = scrollTop;
  28898. }
  28899. };
  28900. this.scrollToX = function(scrollLeft) {
  28901. if (this.scrollLeft !== scrollLeft)
  28902. this.scrollLeft = scrollLeft;
  28903. this.$loop.schedule(this.CHANGE_H_SCROLL);
  28904. };
  28905. this.scrollTo = function(x, y) {
  28906. this.session.setScrollTop(y);
  28907. this.session.setScrollLeft(y);
  28908. };
  28909. this.scrollBy = function(deltaX, deltaY) {
  28910. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  28911. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  28912. };
  28913. this.isScrollableBy = function(deltaX, deltaY) {
  28914. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  28915. return true;
  28916. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  28917. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  28918. return true;
  28919. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  28920. return true;
  28921. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  28922. - this.layerConfig.width < -1 + this.scrollMargin.right)
  28923. return true;
  28924. };
  28925. this.pixelToScreenCoordinates = function(x, y) {
  28926. var canvasPos = this.scroller.getBoundingClientRect();
  28927. var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth;
  28928. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  28929. var col = Math.round(offset);
  28930. return {row: row, column: col, side: offset - col > 0 ? 1 : -1};
  28931. };
  28932. this.screenToTextCoordinates = function(x, y) {
  28933. var canvasPos = this.scroller.getBoundingClientRect();
  28934. var col = Math.round(
  28935. (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
  28936. );
  28937. var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
  28938. return this.session.screenToDocumentPosition(row, Math.max(col, 0));
  28939. };
  28940. this.textToScreenCoordinates = function(row, column) {
  28941. var canvasPos = this.scroller.getBoundingClientRect();
  28942. var pos = this.session.documentToScreenPosition(row, column);
  28943. var x = this.$padding + Math.round(pos.column * this.characterWidth);
  28944. var y = pos.row * this.lineHeight;
  28945. return {
  28946. pageX: canvasPos.left + x - this.scrollLeft,
  28947. pageY: canvasPos.top + y - this.scrollTop
  28948. };
  28949. };
  28950. this.visualizeFocus = function() {
  28951. dom.addCssClass(this.container, "ace_focus");
  28952. };
  28953. this.visualizeBlur = function() {
  28954. dom.removeCssClass(this.container, "ace_focus");
  28955. };
  28956. this.showComposition = function(position) {
  28957. if (!this.$composition)
  28958. this.$composition = {
  28959. keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
  28960. cssText: this.textarea.style.cssText
  28961. };
  28962. this.$keepTextAreaAtCursor = true;
  28963. dom.addCssClass(this.textarea, "ace_composition");
  28964. this.textarea.style.cssText = "";
  28965. this.$moveTextAreaToCursor();
  28966. };
  28967. this.setCompositionText = function(text) {
  28968. this.$moveTextAreaToCursor();
  28969. };
  28970. this.hideComposition = function() {
  28971. if (!this.$composition)
  28972. return;
  28973. dom.removeCssClass(this.textarea, "ace_composition");
  28974. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  28975. this.textarea.style.cssText = this.$composition.cssText;
  28976. this.$composition = null;
  28977. };
  28978. this.setTheme = function(theme, cb) {
  28979. var _self = this;
  28980. this.$themeId = theme;
  28981. _self._dispatchEvent('themeChange',{theme:theme});
  28982. if (!theme || typeof theme == "string") {
  28983. var moduleName = theme || this.$options.theme.initialValue;
  28984. config.loadModule(["theme", moduleName], afterLoad);
  28985. } else {
  28986. afterLoad(theme);
  28987. }
  28988. function afterLoad(module) {
  28989. if (_self.$themeId != theme)
  28990. return cb && cb();
  28991. if (!module.cssClass)
  28992. return;
  28993. dom.importCssString(
  28994. module.cssText,
  28995. module.cssClass,
  28996. _self.container.ownerDocument
  28997. );
  28998. if (_self.theme)
  28999. dom.removeCssClass(_self.container, _self.theme.cssClass);
  29000. var padding = "padding" in module ? module.padding
  29001. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  29002. if (_self.$padding && padding != _self.$padding)
  29003. _self.setPadding(padding);
  29004. _self.$theme = module.cssClass;
  29005. _self.theme = module;
  29006. dom.addCssClass(_self.container, module.cssClass);
  29007. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  29008. if (_self.$size) {
  29009. _self.$size.width = 0;
  29010. _self.$updateSizeAsync();
  29011. }
  29012. _self._dispatchEvent('themeLoaded', {theme:module});
  29013. cb && cb();
  29014. }
  29015. };
  29016. this.getTheme = function() {
  29017. return this.$themeId;
  29018. };
  29019. this.setStyle = function(style, include) {
  29020. dom.setCssClass(this.container, style, include !== false);
  29021. };
  29022. this.unsetStyle = function(style) {
  29023. dom.removeCssClass(this.container, style);
  29024. };
  29025. this.setCursorStyle = function(style) {
  29026. if (this.scroller.style.cursor != style)
  29027. this.scroller.style.cursor = style;
  29028. };
  29029. this.setMouseCursor = function(cursorStyle) {
  29030. this.scroller.style.cursor = cursorStyle;
  29031. };
  29032. this.destroy = function() {
  29033. this.$textLayer.destroy();
  29034. this.$cursorLayer.destroy();
  29035. };
  29036. }).call(VirtualRenderer.prototype);
  29037. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  29038. animatedScroll: {initialValue: false},
  29039. showInvisibles: {
  29040. set: function(value) {
  29041. if (this.$textLayer.setShowInvisibles(value))
  29042. this.$loop.schedule(this.CHANGE_TEXT);
  29043. },
  29044. initialValue: false
  29045. },
  29046. showPrintMargin: {
  29047. set: function() { this.$updatePrintMargin(); },
  29048. initialValue: true
  29049. },
  29050. printMarginColumn: {
  29051. set: function() { this.$updatePrintMargin(); },
  29052. initialValue: 80
  29053. },
  29054. printMargin: {
  29055. set: function(val) {
  29056. if (typeof val == "number")
  29057. this.$printMarginColumn = val;
  29058. this.$showPrintMargin = !!val;
  29059. this.$updatePrintMargin();
  29060. },
  29061. get: function() {
  29062. return this.$showPrintMargin && this.$printMarginColumn;
  29063. }
  29064. },
  29065. showGutter: {
  29066. set: function(show){
  29067. this.$gutter.style.display = show ? "block" : "none";
  29068. this.$loop.schedule(this.CHANGE_FULL);
  29069. this.onGutterResize();
  29070. },
  29071. initialValue: true
  29072. },
  29073. fadeFoldWidgets: {
  29074. set: function(show) {
  29075. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  29076. },
  29077. initialValue: false
  29078. },
  29079. showFoldWidgets: {
  29080. set: function(show) {this.$gutterLayer.setShowFoldWidgets(show)},
  29081. initialValue: true
  29082. },
  29083. showLineNumbers: {
  29084. set: function(show) {
  29085. this.$gutterLayer.setShowLineNumbers(show);
  29086. this.$loop.schedule(this.CHANGE_GUTTER);
  29087. },
  29088. initialValue: true
  29089. },
  29090. displayIndentGuides: {
  29091. set: function(show) {
  29092. if (this.$textLayer.setDisplayIndentGuides(show))
  29093. this.$loop.schedule(this.CHANGE_TEXT);
  29094. },
  29095. initialValue: true
  29096. },
  29097. highlightGutterLine: {
  29098. set: function(shouldHighlight) {
  29099. if (!this.$gutterLineHighlight) {
  29100. this.$gutterLineHighlight = dom.createElement("div");
  29101. this.$gutterLineHighlight.className = "ace_gutter-active-line";
  29102. this.$gutter.appendChild(this.$gutterLineHighlight);
  29103. return;
  29104. }
  29105. this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
  29106. if (this.$cursorLayer.$pixelPos)
  29107. this.$updateGutterLineHighlight();
  29108. },
  29109. initialValue: false,
  29110. value: true
  29111. },
  29112. hScrollBarAlwaysVisible: {
  29113. set: function(val) {
  29114. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  29115. this.$loop.schedule(this.CHANGE_SCROLL);
  29116. },
  29117. initialValue: false
  29118. },
  29119. vScrollBarAlwaysVisible: {
  29120. set: function(val) {
  29121. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  29122. this.$loop.schedule(this.CHANGE_SCROLL);
  29123. },
  29124. initialValue: false
  29125. },
  29126. fontSize: {
  29127. set: function(size) {
  29128. if (typeof size == "number")
  29129. size = size + "px";
  29130. this.container.style.fontSize = size;
  29131. this.updateFontSize();
  29132. },
  29133. initialValue: 12
  29134. },
  29135. fontFamily: {
  29136. set: function(name) {
  29137. this.container.style.fontFamily = name;
  29138. this.updateFontSize();
  29139. }
  29140. },
  29141. maxLines: {
  29142. set: function(val) {
  29143. this.updateFull();
  29144. }
  29145. },
  29146. minLines: {
  29147. set: function(val) {
  29148. this.updateFull();
  29149. }
  29150. },
  29151. scrollPastEnd: {
  29152. set: function(val) {
  29153. val = +val || 0;
  29154. if (this.$scrollPastEnd == val)
  29155. return;
  29156. this.$scrollPastEnd = val;
  29157. this.$loop.schedule(this.CHANGE_SCROLL);
  29158. },
  29159. initialValue: 0,
  29160. handlesSet: true
  29161. },
  29162. fixedWidthGutter: {
  29163. set: function(val) {
  29164. this.$gutterLayer.$fixedWidth = !!val;
  29165. this.$loop.schedule(this.CHANGE_GUTTER);
  29166. }
  29167. },
  29168. theme: {
  29169. set: function(val) { this.setTheme(val) },
  29170. get: function() { return this.$themeId || this.theme; },
  29171. initialValue: "./theme/textmate",
  29172. handlesSet: true
  29173. }
  29174. });
  29175. exports.VirtualRenderer = VirtualRenderer;
  29176. });
  29177. ace.define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(acequire, exports, module) {
  29178. "use strict";
  29179. var oop = acequire("../lib/oop");
  29180. var net = acequire("../lib/net");
  29181. var EventEmitter = acequire("../lib/event_emitter").EventEmitter;
  29182. var config = acequire("../config");
  29183. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl) {
  29184. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  29185. this.changeListener = this.changeListener.bind(this);
  29186. this.onMessage = this.onMessage.bind(this);
  29187. if (acequire.nameToUrl && !acequire.toUrl)
  29188. acequire.toUrl = acequire.nameToUrl;
  29189. if (config.get("packaged") || !acequire.toUrl) {
  29190. workerUrl = workerUrl || config.moduleUrl(mod.id, "worker")
  29191. } else {
  29192. var normalizePath = this.$normalizePath;
  29193. workerUrl = workerUrl || normalizePath(acequire.toUrl("ace/worker/worker.js", null, "_"));
  29194. var tlns = {};
  29195. topLevelNamespaces.forEach(function(ns) {
  29196. tlns[ns] = normalizePath(acequire.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  29197. });
  29198. }
  29199. try {
  29200. var workerSrc = mod.src;
  29201. var Blob = __webpack_require__(66);
  29202. var blob = new Blob([ workerSrc ], { type: 'application/javascript' });
  29203. var blobUrl = (window.URL || window.webkitURL).createObjectURL(blob);
  29204. this.$worker = new Worker(blobUrl);
  29205. } catch(e) {
  29206. if (e instanceof window.DOMException) {
  29207. var blob = this.$workerBlob(workerUrl);
  29208. var URL = window.URL || window.webkitURL;
  29209. var blobURL = URL.createObjectURL(blob);
  29210. this.$worker = new Worker(blobURL);
  29211. URL.revokeObjectURL(blobURL);
  29212. } else {
  29213. throw e;
  29214. }
  29215. }
  29216. this.$worker.postMessage({
  29217. init : true,
  29218. tlns : tlns,
  29219. module : mod.id,
  29220. classname : classname
  29221. });
  29222. this.callbackId = 1;
  29223. this.callbacks = {};
  29224. this.$worker.onmessage = this.onMessage;
  29225. };
  29226. (function(){
  29227. oop.implement(this, EventEmitter);
  29228. this.onMessage = function(e) {
  29229. var msg = e.data;
  29230. switch(msg.type) {
  29231. case "event":
  29232. this._signal(msg.name, {data: msg.data});
  29233. break;
  29234. case "call":
  29235. var callback = this.callbacks[msg.id];
  29236. if (callback) {
  29237. callback(msg.data);
  29238. delete this.callbacks[msg.id];
  29239. }
  29240. break;
  29241. case "error":
  29242. this.reportError(msg.data);
  29243. break;
  29244. case "log":
  29245. window.console && console.log && console.log.apply(console, msg.data);
  29246. break;
  29247. }
  29248. };
  29249. this.reportError = function(err) {
  29250. window.console && console.error && console.error(err);
  29251. };
  29252. this.$normalizePath = function(path) {
  29253. return net.qualifyURL(path);
  29254. };
  29255. this.terminate = function() {
  29256. this._signal("terminate", {});
  29257. this.deltaQueue = null;
  29258. this.$worker.terminate();
  29259. this.$worker = null;
  29260. if (this.$doc)
  29261. this.$doc.off("change", this.changeListener);
  29262. this.$doc = null;
  29263. };
  29264. this.send = function(cmd, args) {
  29265. this.$worker.postMessage({command: cmd, args: args});
  29266. };
  29267. this.call = function(cmd, args, callback) {
  29268. if (callback) {
  29269. var id = this.callbackId++;
  29270. this.callbacks[id] = callback;
  29271. args.push(id);
  29272. }
  29273. this.send(cmd, args);
  29274. };
  29275. this.emit = function(event, data) {
  29276. try {
  29277. this.$worker.postMessage({event: event, data: {data: data.data}});
  29278. }
  29279. catch(ex) {
  29280. console.error(ex.stack);
  29281. }
  29282. };
  29283. this.attachToDocument = function(doc) {
  29284. if(this.$doc)
  29285. this.terminate();
  29286. this.$doc = doc;
  29287. this.call("setValue", [doc.getValue()]);
  29288. doc.on("change", this.changeListener);
  29289. };
  29290. this.changeListener = function(delta) {
  29291. if (!this.deltaQueue) {
  29292. this.deltaQueue = [];
  29293. setTimeout(this.$sendDeltaQueue, 0);
  29294. }
  29295. if (delta.action == "insert")
  29296. this.deltaQueue.push(delta.start, delta.lines);
  29297. else
  29298. this.deltaQueue.push(delta.start, delta.end);
  29299. };
  29300. this.$sendDeltaQueue = function() {
  29301. var q = this.deltaQueue;
  29302. if (!q) return;
  29303. this.deltaQueue = null;
  29304. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  29305. this.call("setValue", [this.$doc.getValue()]);
  29306. } else
  29307. this.emit("change", {data: q});
  29308. };
  29309. this.$workerBlob = function(workerUrl) {
  29310. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  29311. try {
  29312. return new Blob([script], {"type": "application/javascript"});
  29313. } catch (e) { // Backwards-compatibility
  29314. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  29315. var blobBuilder = new BlobBuilder();
  29316. blobBuilder.append(script);
  29317. return blobBuilder.getBlob("application/javascript");
  29318. }
  29319. };
  29320. }).call(WorkerClient.prototype);
  29321. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  29322. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  29323. this.changeListener = this.changeListener.bind(this);
  29324. this.callbackId = 1;
  29325. this.callbacks = {};
  29326. this.messageBuffer = [];
  29327. var main = null;
  29328. var emitSync = false;
  29329. var sender = Object.create(EventEmitter);
  29330. var _self = this;
  29331. this.$worker = {};
  29332. this.$worker.terminate = function() {};
  29333. this.$worker.postMessage = function(e) {
  29334. _self.messageBuffer.push(e);
  29335. if (main) {
  29336. if (emitSync)
  29337. setTimeout(processNext);
  29338. else
  29339. processNext();
  29340. }
  29341. };
  29342. this.setEmitSync = function(val) { emitSync = val };
  29343. var processNext = function() {
  29344. var msg = _self.messageBuffer.shift();
  29345. if (msg.command)
  29346. main[msg.command].apply(main, msg.args);
  29347. else if (msg.event)
  29348. sender._signal(msg.event, msg.data);
  29349. };
  29350. sender.postMessage = function(msg) {
  29351. _self.onMessage({data: msg});
  29352. };
  29353. sender.callback = function(data, callbackId) {
  29354. this.postMessage({type: "call", id: callbackId, data: data});
  29355. };
  29356. sender.emit = function(name, data) {
  29357. this.postMessage({type: "event", name: name, data: data});
  29358. };
  29359. config.loadModule(["worker", mod], function(Main) {
  29360. main = new Main[classname](sender);
  29361. while (_self.messageBuffer.length)
  29362. processNext();
  29363. });
  29364. };
  29365. UIWorkerClient.prototype = WorkerClient.prototype;
  29366. exports.UIWorkerClient = UIWorkerClient;
  29367. exports.WorkerClient = WorkerClient;
  29368. });
  29369. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(acequire, exports, module) {
  29370. "use strict";
  29371. var Range = acequire("./range").Range;
  29372. var EventEmitter = acequire("./lib/event_emitter").EventEmitter;
  29373. var oop = acequire("./lib/oop");
  29374. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  29375. var _self = this;
  29376. this.length = length;
  29377. this.session = session;
  29378. this.doc = session.getDocument();
  29379. this.mainClass = mainClass;
  29380. this.othersClass = othersClass;
  29381. this.$onUpdate = this.onUpdate.bind(this);
  29382. this.doc.on("change", this.$onUpdate);
  29383. this.$others = others;
  29384. this.$onCursorChange = function() {
  29385. setTimeout(function() {
  29386. _self.onCursorChange();
  29387. });
  29388. };
  29389. this.$pos = pos;
  29390. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  29391. this.$undoStackDepth = undoStack.length;
  29392. this.setup();
  29393. session.selection.on("changeCursor", this.$onCursorChange);
  29394. };
  29395. (function() {
  29396. oop.implement(this, EventEmitter);
  29397. this.setup = function() {
  29398. var _self = this;
  29399. var doc = this.doc;
  29400. var session = this.session;
  29401. this.selectionBefore = session.selection.toJSON();
  29402. if (session.selection.inMultiSelectMode)
  29403. session.selection.toSingleRange();
  29404. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  29405. var pos = this.pos;
  29406. pos.$insertRight = true;
  29407. pos.detach();
  29408. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  29409. this.others = [];
  29410. this.$others.forEach(function(other) {
  29411. var anchor = doc.createAnchor(other.row, other.column);
  29412. anchor.$insertRight = true;
  29413. anchor.detach();
  29414. _self.others.push(anchor);
  29415. });
  29416. session.setUndoSelect(false);
  29417. };
  29418. this.showOtherMarkers = function() {
  29419. if (this.othersActive) return;
  29420. var session = this.session;
  29421. var _self = this;
  29422. this.othersActive = true;
  29423. this.others.forEach(function(anchor) {
  29424. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  29425. });
  29426. };
  29427. this.hideOtherMarkers = function() {
  29428. if (!this.othersActive) return;
  29429. this.othersActive = false;
  29430. for (var i = 0; i < this.others.length; i++) {
  29431. this.session.removeMarker(this.others[i].markerId);
  29432. }
  29433. };
  29434. this.onUpdate = function(delta) {
  29435. if (this.$updating)
  29436. return this.updateAnchors(delta);
  29437. var range = delta;
  29438. if (range.start.row !== range.end.row) return;
  29439. if (range.start.row !== this.pos.row) return;
  29440. this.$updating = true;
  29441. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  29442. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  29443. var distanceFromStart = range.start.column - this.pos.column;
  29444. this.updateAnchors(delta);
  29445. if (inMainRange)
  29446. this.length += lengthDiff;
  29447. if (inMainRange && !this.session.$fromUndo) {
  29448. if (delta.action === 'insert') {
  29449. for (var i = this.others.length - 1; i >= 0; i--) {
  29450. var otherPos = this.others[i];
  29451. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  29452. this.doc.insertMergedLines(newPos, delta.lines);
  29453. }
  29454. } else if (delta.action === 'remove') {
  29455. for (var i = this.others.length - 1; i >= 0; i--) {
  29456. var otherPos = this.others[i];
  29457. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  29458. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  29459. }
  29460. }
  29461. }
  29462. this.$updating = false;
  29463. this.updateMarkers();
  29464. };
  29465. this.updateAnchors = function(delta) {
  29466. this.pos.onChange(delta);
  29467. for (var i = this.others.length; i--;)
  29468. this.others[i].onChange(delta);
  29469. this.updateMarkers();
  29470. };
  29471. this.updateMarkers = function() {
  29472. if (this.$updating)
  29473. return;
  29474. var _self = this;
  29475. var session = this.session;
  29476. var updateMarker = function(pos, className) {
  29477. session.removeMarker(pos.markerId);
  29478. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  29479. };
  29480. updateMarker(this.pos, this.mainClass);
  29481. for (var i = this.others.length; i--;)
  29482. updateMarker(this.others[i], this.othersClass);
  29483. };
  29484. this.onCursorChange = function(event) {
  29485. if (this.$updating || !this.session) return;
  29486. var pos = this.session.selection.getCursor();
  29487. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  29488. this.showOtherMarkers();
  29489. this._emit("cursorEnter", event);
  29490. } else {
  29491. this.hideOtherMarkers();
  29492. this._emit("cursorLeave", event);
  29493. }
  29494. };
  29495. this.detach = function() {
  29496. this.session.removeMarker(this.pos && this.pos.markerId);
  29497. this.hideOtherMarkers();
  29498. this.doc.removeEventListener("change", this.$onUpdate);
  29499. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  29500. this.session.setUndoSelect(true);
  29501. this.session = null;
  29502. };
  29503. this.cancel = function() {
  29504. if (this.$undoStackDepth === -1)
  29505. return;
  29506. var undoManager = this.session.getUndoManager();
  29507. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  29508. for (var i = 0; i < undosRequired; i++) {
  29509. undoManager.undo(true);
  29510. }
  29511. if (this.selectionBefore)
  29512. this.session.selection.fromJSON(this.selectionBefore);
  29513. };
  29514. }).call(PlaceHolder.prototype);
  29515. exports.PlaceHolder = PlaceHolder;
  29516. });
  29517. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) {
  29518. var event = acequire("../lib/event");
  29519. var useragent = acequire("../lib/useragent");
  29520. function isSamePoint(p1, p2) {
  29521. return p1.row == p2.row && p1.column == p2.column;
  29522. }
  29523. function onMouseDown(e) {
  29524. var ev = e.domEvent;
  29525. var alt = ev.altKey;
  29526. var shift = ev.shiftKey;
  29527. var ctrl = ev.ctrlKey;
  29528. var accel = e.getAccelKey();
  29529. var button = e.getButton();
  29530. if (ctrl && useragent.isMac)
  29531. button = ev.button;
  29532. if (e.editor.inMultiSelectMode && button == 2) {
  29533. e.editor.textInput.onContextMenu(e.domEvent);
  29534. return;
  29535. }
  29536. if (!ctrl && !alt && !accel) {
  29537. if (button === 0 && e.editor.inMultiSelectMode)
  29538. e.editor.exitMultiSelectMode();
  29539. return;
  29540. }
  29541. if (button !== 0)
  29542. return;
  29543. var editor = e.editor;
  29544. var selection = editor.selection;
  29545. var isMultiSelect = editor.inMultiSelectMode;
  29546. var pos = e.getDocumentPosition();
  29547. var cursor = selection.getCursor();
  29548. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  29549. var mouseX = e.x, mouseY = e.y;
  29550. var onMouseSelection = function(e) {
  29551. mouseX = e.clientX;
  29552. mouseY = e.clientY;
  29553. };
  29554. var session = editor.session;
  29555. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  29556. var screenCursor = screenAnchor;
  29557. var selectionMode;
  29558. if (editor.$mouseHandler.$enableJumpToDef) {
  29559. if (ctrl && alt || accel && alt)
  29560. selectionMode = shift ? "block" : "add";
  29561. else if (alt && editor.$blockSelectEnabled)
  29562. selectionMode = "block";
  29563. } else {
  29564. if (accel && !alt) {
  29565. selectionMode = "add";
  29566. if (!isMultiSelect && shift)
  29567. return;
  29568. } else if (alt && editor.$blockSelectEnabled) {
  29569. selectionMode = "block";
  29570. }
  29571. }
  29572. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  29573. editor.$mouseHandler.cancelContextMenu();
  29574. }
  29575. if (selectionMode == "add") {
  29576. if (!isMultiSelect && inSelection)
  29577. return; // dragging
  29578. if (!isMultiSelect) {
  29579. var range = selection.toOrientedRange();
  29580. editor.addSelectionMarker(range);
  29581. }
  29582. var oldRange = selection.rangeList.rangeAtPoint(pos);
  29583. editor.$blockScrolling++;
  29584. editor.inVirtualSelectionMode = true;
  29585. if (shift) {
  29586. oldRange = null;
  29587. range = selection.ranges[0] || range;
  29588. editor.removeSelectionMarker(range);
  29589. }
  29590. editor.once("mouseup", function() {
  29591. var tmpSel = selection.toOrientedRange();
  29592. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  29593. selection.substractPoint(tmpSel.cursor);
  29594. else {
  29595. if (shift) {
  29596. selection.substractPoint(range.cursor);
  29597. } else if (range) {
  29598. editor.removeSelectionMarker(range);
  29599. selection.addRange(range);
  29600. }
  29601. selection.addRange(tmpSel);
  29602. }
  29603. editor.$blockScrolling--;
  29604. editor.inVirtualSelectionMode = false;
  29605. });
  29606. } else if (selectionMode == "block") {
  29607. e.stop();
  29608. editor.inVirtualSelectionMode = true;
  29609. var initialRange;
  29610. var rectSel = [];
  29611. var blockSelect = function() {
  29612. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  29613. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
  29614. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  29615. return;
  29616. screenCursor = newCursor;
  29617. editor.$blockScrolling++;
  29618. editor.selection.moveToPosition(cursor);
  29619. editor.renderer.scrollCursorIntoView();
  29620. editor.removeSelectionMarkers(rectSel);
  29621. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  29622. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  29623. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  29624. rectSel.forEach(editor.addSelectionMarker, editor);
  29625. editor.updateSelectionMarkers();
  29626. editor.$blockScrolling--;
  29627. };
  29628. editor.$blockScrolling++;
  29629. if (isMultiSelect && !accel) {
  29630. selection.toSingleRange();
  29631. } else if (!isMultiSelect && accel) {
  29632. initialRange = selection.toOrientedRange();
  29633. editor.addSelectionMarker(initialRange);
  29634. }
  29635. if (shift)
  29636. screenAnchor = session.documentToScreenPosition(selection.lead);
  29637. else
  29638. selection.moveToPosition(pos);
  29639. editor.$blockScrolling--;
  29640. screenCursor = {row: -1, column: -1};
  29641. var onMouseSelectionEnd = function(e) {
  29642. clearInterval(timerId);
  29643. editor.removeSelectionMarkers(rectSel);
  29644. if (!rectSel.length)
  29645. rectSel = [selection.toOrientedRange()];
  29646. editor.$blockScrolling++;
  29647. if (initialRange) {
  29648. editor.removeSelectionMarker(initialRange);
  29649. selection.toSingleRange(initialRange);
  29650. }
  29651. for (var i = 0; i < rectSel.length; i++)
  29652. selection.addRange(rectSel[i]);
  29653. editor.inVirtualSelectionMode = false;
  29654. editor.$mouseHandler.$clickSelection = null;
  29655. editor.$blockScrolling--;
  29656. };
  29657. var onSelectionInterval = blockSelect;
  29658. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  29659. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  29660. return e.preventDefault();
  29661. }
  29662. }
  29663. exports.onMouseDown = onMouseDown;
  29664. });
  29665. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(acequire, exports, module) {
  29666. exports.defaultCommands = [{
  29667. name: "addCursorAbove",
  29668. exec: function(editor) { editor.selectMoreLines(-1); },
  29669. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  29670. scrollIntoView: "cursor",
  29671. readOnly: true
  29672. }, {
  29673. name: "addCursorBelow",
  29674. exec: function(editor) { editor.selectMoreLines(1); },
  29675. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  29676. scrollIntoView: "cursor",
  29677. readOnly: true
  29678. }, {
  29679. name: "addCursorAboveSkipCurrent",
  29680. exec: function(editor) { editor.selectMoreLines(-1, true); },
  29681. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  29682. scrollIntoView: "cursor",
  29683. readOnly: true
  29684. }, {
  29685. name: "addCursorBelowSkipCurrent",
  29686. exec: function(editor) { editor.selectMoreLines(1, true); },
  29687. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  29688. scrollIntoView: "cursor",
  29689. readOnly: true
  29690. }, {
  29691. name: "selectMoreBefore",
  29692. exec: function(editor) { editor.selectMore(-1); },
  29693. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  29694. scrollIntoView: "cursor",
  29695. readOnly: true
  29696. }, {
  29697. name: "selectMoreAfter",
  29698. exec: function(editor) { editor.selectMore(1); },
  29699. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  29700. scrollIntoView: "cursor",
  29701. readOnly: true
  29702. }, {
  29703. name: "selectNextBefore",
  29704. exec: function(editor) { editor.selectMore(-1, true); },
  29705. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  29706. scrollIntoView: "cursor",
  29707. readOnly: true
  29708. }, {
  29709. name: "selectNextAfter",
  29710. exec: function(editor) { editor.selectMore(1, true); },
  29711. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  29712. scrollIntoView: "cursor",
  29713. readOnly: true
  29714. }, {
  29715. name: "splitIntoLines",
  29716. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  29717. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  29718. readOnly: true
  29719. }, {
  29720. name: "alignCursors",
  29721. exec: function(editor) { editor.alignCursors(); },
  29722. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  29723. scrollIntoView: "cursor"
  29724. }, {
  29725. name: "findAll",
  29726. exec: function(editor) { editor.findAll(); },
  29727. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  29728. scrollIntoView: "cursor",
  29729. readOnly: true
  29730. }];
  29731. exports.multiSelectCommands = [{
  29732. name: "singleSelection",
  29733. bindKey: "esc",
  29734. exec: function(editor) { editor.exitMultiSelectMode(); },
  29735. scrollIntoView: "cursor",
  29736. readOnly: true,
  29737. isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
  29738. }];
  29739. var HashHandler = acequire("../keyboard/hash_handler").HashHandler;
  29740. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  29741. });
  29742. ace.define("ace/multi_select",["require","exports","module","ace/range_list","ace/range","ace/selection","ace/mouse/multi_select_handler","ace/lib/event","ace/lib/lang","ace/commands/multi_select_commands","ace/search","ace/edit_session","ace/editor","ace/config"], function(acequire, exports, module) {
  29743. var RangeList = acequire("./range_list").RangeList;
  29744. var Range = acequire("./range").Range;
  29745. var Selection = acequire("./selection").Selection;
  29746. var onMouseDown = acequire("./mouse/multi_select_handler").onMouseDown;
  29747. var event = acequire("./lib/event");
  29748. var lang = acequire("./lib/lang");
  29749. var commands = acequire("./commands/multi_select_commands");
  29750. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  29751. var Search = acequire("./search").Search;
  29752. var search = new Search();
  29753. function find(session, needle, dir) {
  29754. search.$options.wrap = true;
  29755. search.$options.needle = needle;
  29756. search.$options.backwards = dir == -1;
  29757. return search.find(session);
  29758. }
  29759. var EditSession = acequire("./edit_session").EditSession;
  29760. (function() {
  29761. this.getSelectionMarkers = function() {
  29762. return this.$selectionMarkers;
  29763. };
  29764. }).call(EditSession.prototype);
  29765. (function() {
  29766. this.ranges = null;
  29767. this.rangeList = null;
  29768. this.addRange = function(range, $blockChangeEvents) {
  29769. if (!range)
  29770. return;
  29771. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  29772. var oldRange = this.toOrientedRange();
  29773. this.rangeList.add(oldRange);
  29774. this.rangeList.add(range);
  29775. if (this.rangeList.ranges.length != 2) {
  29776. this.rangeList.removeAll();
  29777. return $blockChangeEvents || this.fromOrientedRange(range);
  29778. }
  29779. this.rangeList.removeAll();
  29780. this.rangeList.add(oldRange);
  29781. this.$onAddRange(oldRange);
  29782. }
  29783. if (!range.cursor)
  29784. range.cursor = range.end;
  29785. var removed = this.rangeList.add(range);
  29786. this.$onAddRange(range);
  29787. if (removed.length)
  29788. this.$onRemoveRange(removed);
  29789. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  29790. this._signal("multiSelect");
  29791. this.inMultiSelectMode = true;
  29792. this.session.$undoSelect = false;
  29793. this.rangeList.attach(this.session);
  29794. }
  29795. return $blockChangeEvents || this.fromOrientedRange(range);
  29796. };
  29797. this.toSingleRange = function(range) {
  29798. range = range || this.ranges[0];
  29799. var removed = this.rangeList.removeAll();
  29800. if (removed.length)
  29801. this.$onRemoveRange(removed);
  29802. range && this.fromOrientedRange(range);
  29803. };
  29804. this.substractPoint = function(pos) {
  29805. var removed = this.rangeList.substractPoint(pos);
  29806. if (removed) {
  29807. this.$onRemoveRange(removed);
  29808. return removed[0];
  29809. }
  29810. };
  29811. this.mergeOverlappingRanges = function() {
  29812. var removed = this.rangeList.merge();
  29813. if (removed.length)
  29814. this.$onRemoveRange(removed);
  29815. else if(this.ranges[0])
  29816. this.fromOrientedRange(this.ranges[0]);
  29817. };
  29818. this.$onAddRange = function(range) {
  29819. this.rangeCount = this.rangeList.ranges.length;
  29820. this.ranges.unshift(range);
  29821. this._signal("addRange", {range: range});
  29822. };
  29823. this.$onRemoveRange = function(removed) {
  29824. this.rangeCount = this.rangeList.ranges.length;
  29825. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  29826. var lastRange = this.rangeList.ranges.pop();
  29827. removed.push(lastRange);
  29828. this.rangeCount = 0;
  29829. }
  29830. for (var i = removed.length; i--; ) {
  29831. var index = this.ranges.indexOf(removed[i]);
  29832. this.ranges.splice(index, 1);
  29833. }
  29834. this._signal("removeRange", {ranges: removed});
  29835. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  29836. this.inMultiSelectMode = false;
  29837. this._signal("singleSelect");
  29838. this.session.$undoSelect = true;
  29839. this.rangeList.detach(this.session);
  29840. }
  29841. lastRange = lastRange || this.ranges[0];
  29842. if (lastRange && !lastRange.isEqual(this.getRange()))
  29843. this.fromOrientedRange(lastRange);
  29844. };
  29845. this.$initRangeList = function() {
  29846. if (this.rangeList)
  29847. return;
  29848. this.rangeList = new RangeList();
  29849. this.ranges = [];
  29850. this.rangeCount = 0;
  29851. };
  29852. this.getAllRanges = function() {
  29853. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  29854. };
  29855. this.splitIntoLines = function () {
  29856. if (this.rangeCount > 1) {
  29857. var ranges = this.rangeList.ranges;
  29858. var lastRange = ranges[ranges.length - 1];
  29859. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  29860. this.toSingleRange();
  29861. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  29862. } else {
  29863. var range = this.getRange();
  29864. var isBackwards = this.isBackwards();
  29865. var startRow = range.start.row;
  29866. var endRow = range.end.row;
  29867. if (startRow == endRow) {
  29868. if (isBackwards)
  29869. var start = range.end, end = range.start;
  29870. else
  29871. var start = range.start, end = range.end;
  29872. this.addRange(Range.fromPoints(end, end));
  29873. this.addRange(Range.fromPoints(start, start));
  29874. return;
  29875. }
  29876. var rectSel = [];
  29877. var r = this.getLineRange(startRow, true);
  29878. r.start.column = range.start.column;
  29879. rectSel.push(r);
  29880. for (var i = startRow + 1; i < endRow; i++)
  29881. rectSel.push(this.getLineRange(i, true));
  29882. r = this.getLineRange(endRow, true);
  29883. r.end.column = range.end.column;
  29884. rectSel.push(r);
  29885. rectSel.forEach(this.addRange, this);
  29886. }
  29887. };
  29888. this.toggleBlockSelection = function () {
  29889. if (this.rangeCount > 1) {
  29890. var ranges = this.rangeList.ranges;
  29891. var lastRange = ranges[ranges.length - 1];
  29892. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  29893. this.toSingleRange();
  29894. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  29895. } else {
  29896. var cursor = this.session.documentToScreenPosition(this.selectionLead);
  29897. var anchor = this.session.documentToScreenPosition(this.selectionAnchor);
  29898. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  29899. rectSel.forEach(this.addRange, this);
  29900. }
  29901. };
  29902. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  29903. var rectSel = [];
  29904. var xBackwards = screenCursor.column < screenAnchor.column;
  29905. if (xBackwards) {
  29906. var startColumn = screenCursor.column;
  29907. var endColumn = screenAnchor.column;
  29908. } else {
  29909. var startColumn = screenAnchor.column;
  29910. var endColumn = screenCursor.column;
  29911. }
  29912. var yBackwards = screenCursor.row < screenAnchor.row;
  29913. if (yBackwards) {
  29914. var startRow = screenCursor.row;
  29915. var endRow = screenAnchor.row;
  29916. } else {
  29917. var startRow = screenAnchor.row;
  29918. var endRow = screenCursor.row;
  29919. }
  29920. if (startColumn < 0)
  29921. startColumn = 0;
  29922. if (startRow < 0)
  29923. startRow = 0;
  29924. if (startRow == endRow)
  29925. includeEmptyLines = true;
  29926. for (var row = startRow; row <= endRow; row++) {
  29927. var range = Range.fromPoints(
  29928. this.session.screenToDocumentPosition(row, startColumn),
  29929. this.session.screenToDocumentPosition(row, endColumn)
  29930. );
  29931. if (range.isEmpty()) {
  29932. if (docEnd && isSamePoint(range.end, docEnd))
  29933. break;
  29934. var docEnd = range.end;
  29935. }
  29936. range.cursor = xBackwards ? range.start : range.end;
  29937. rectSel.push(range);
  29938. }
  29939. if (yBackwards)
  29940. rectSel.reverse();
  29941. if (!includeEmptyLines) {
  29942. var end = rectSel.length - 1;
  29943. while (rectSel[end].isEmpty() && end > 0)
  29944. end--;
  29945. if (end > 0) {
  29946. var start = 0;
  29947. while (rectSel[start].isEmpty())
  29948. start++;
  29949. }
  29950. for (var i = end; i >= start; i--) {
  29951. if (rectSel[i].isEmpty())
  29952. rectSel.splice(i, 1);
  29953. }
  29954. }
  29955. return rectSel;
  29956. };
  29957. }).call(Selection.prototype);
  29958. var Editor = acequire("./editor").Editor;
  29959. (function() {
  29960. this.updateSelectionMarkers = function() {
  29961. this.renderer.updateCursor();
  29962. this.renderer.updateBackMarkers();
  29963. };
  29964. this.addSelectionMarker = function(orientedRange) {
  29965. if (!orientedRange.cursor)
  29966. orientedRange.cursor = orientedRange.end;
  29967. var style = this.getSelectionStyle();
  29968. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  29969. this.session.$selectionMarkers.push(orientedRange);
  29970. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  29971. return orientedRange;
  29972. };
  29973. this.removeSelectionMarker = function(range) {
  29974. if (!range.marker)
  29975. return;
  29976. this.session.removeMarker(range.marker);
  29977. var index = this.session.$selectionMarkers.indexOf(range);
  29978. if (index != -1)
  29979. this.session.$selectionMarkers.splice(index, 1);
  29980. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  29981. };
  29982. this.removeSelectionMarkers = function(ranges) {
  29983. var markerList = this.session.$selectionMarkers;
  29984. for (var i = ranges.length; i--; ) {
  29985. var range = ranges[i];
  29986. if (!range.marker)
  29987. continue;
  29988. this.session.removeMarker(range.marker);
  29989. var index = markerList.indexOf(range);
  29990. if (index != -1)
  29991. markerList.splice(index, 1);
  29992. }
  29993. this.session.selectionMarkerCount = markerList.length;
  29994. };
  29995. this.$onAddRange = function(e) {
  29996. this.addSelectionMarker(e.range);
  29997. this.renderer.updateCursor();
  29998. this.renderer.updateBackMarkers();
  29999. };
  30000. this.$onRemoveRange = function(e) {
  30001. this.removeSelectionMarkers(e.ranges);
  30002. this.renderer.updateCursor();
  30003. this.renderer.updateBackMarkers();
  30004. };
  30005. this.$onMultiSelect = function(e) {
  30006. if (this.inMultiSelectMode)
  30007. return;
  30008. this.inMultiSelectMode = true;
  30009. this.setStyle("ace_multiselect");
  30010. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  30011. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  30012. this.renderer.updateCursor();
  30013. this.renderer.updateBackMarkers();
  30014. };
  30015. this.$onSingleSelect = function(e) {
  30016. if (this.session.multiSelect.inVirtualMode)
  30017. return;
  30018. this.inMultiSelectMode = false;
  30019. this.unsetStyle("ace_multiselect");
  30020. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  30021. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  30022. this.renderer.updateCursor();
  30023. this.renderer.updateBackMarkers();
  30024. this._emit("changeSelection");
  30025. };
  30026. this.$onMultiSelectExec = function(e) {
  30027. var command = e.command;
  30028. var editor = e.editor;
  30029. if (!editor.multiSelect)
  30030. return;
  30031. if (!command.multiSelectAction) {
  30032. var result = command.exec(editor, e.args || {});
  30033. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  30034. editor.multiSelect.mergeOverlappingRanges();
  30035. } else if (command.multiSelectAction == "forEach") {
  30036. result = editor.forEachSelection(command, e.args);
  30037. } else if (command.multiSelectAction == "forEachLine") {
  30038. result = editor.forEachSelection(command, e.args, true);
  30039. } else if (command.multiSelectAction == "single") {
  30040. editor.exitMultiSelectMode();
  30041. result = command.exec(editor, e.args || {});
  30042. } else {
  30043. result = command.multiSelectAction(editor, e.args || {});
  30044. }
  30045. return result;
  30046. };
  30047. this.forEachSelection = function(cmd, args, options) {
  30048. if (this.inVirtualSelectionMode)
  30049. return;
  30050. var keepOrder = options && options.keepOrder;
  30051. var $byLines = options == true || options && options.$byLines
  30052. var session = this.session;
  30053. var selection = this.selection;
  30054. var rangeList = selection.rangeList;
  30055. var ranges = (keepOrder ? selection : rangeList).ranges;
  30056. var result;
  30057. if (!ranges.length)
  30058. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  30059. var reg = selection._eventRegistry;
  30060. selection._eventRegistry = {};
  30061. var tmpSel = new Selection(session);
  30062. this.inVirtualSelectionMode = true;
  30063. for (var i = ranges.length; i--;) {
  30064. if ($byLines) {
  30065. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  30066. i--;
  30067. }
  30068. tmpSel.fromOrientedRange(ranges[i]);
  30069. tmpSel.index = i;
  30070. this.selection = session.selection = tmpSel;
  30071. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  30072. if (!result && cmdResult !== undefined)
  30073. result = cmdResult;
  30074. tmpSel.toOrientedRange(ranges[i]);
  30075. }
  30076. tmpSel.detach();
  30077. this.selection = session.selection = selection;
  30078. this.inVirtualSelectionMode = false;
  30079. selection._eventRegistry = reg;
  30080. selection.mergeOverlappingRanges();
  30081. var anim = this.renderer.$scrollAnimation;
  30082. this.onCursorChange();
  30083. this.onSelectionChange();
  30084. if (anim && anim.from == anim.to)
  30085. this.renderer.animateScrolling(anim.from);
  30086. return result;
  30087. };
  30088. this.exitMultiSelectMode = function() {
  30089. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  30090. return;
  30091. this.multiSelect.toSingleRange();
  30092. };
  30093. this.getSelectedText = function() {
  30094. var text = "";
  30095. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  30096. var ranges = this.multiSelect.rangeList.ranges;
  30097. var buf = [];
  30098. for (var i = 0; i < ranges.length; i++) {
  30099. buf.push(this.session.getTextRange(ranges[i]));
  30100. }
  30101. var nl = this.session.getDocument().getNewLineCharacter();
  30102. text = buf.join(nl);
  30103. if (text.length == (buf.length - 1) * nl.length)
  30104. text = "";
  30105. } else if (!this.selection.isEmpty()) {
  30106. text = this.session.getTextRange(this.getSelectionRange());
  30107. }
  30108. return text;
  30109. };
  30110. this.$checkMultiselectChange = function(e, anchor) {
  30111. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  30112. var range = this.multiSelect.ranges[0];
  30113. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  30114. return;
  30115. var pos = anchor == this.multiSelect.anchor
  30116. ? range.cursor == range.start ? range.end : range.start
  30117. : range.cursor;
  30118. if (pos.row != anchor.row
  30119. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  30120. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  30121. }
  30122. };
  30123. this.findAll = function(needle, options, additive) {
  30124. options = options || {};
  30125. options.needle = needle || options.needle;
  30126. if (options.needle == undefined) {
  30127. var range = this.selection.isEmpty()
  30128. ? this.selection.getWordRange()
  30129. : this.selection.getRange();
  30130. options.needle = this.session.getTextRange(range);
  30131. }
  30132. this.$search.set(options);
  30133. var ranges = this.$search.findAll(this.session);
  30134. if (!ranges.length)
  30135. return 0;
  30136. this.$blockScrolling += 1;
  30137. var selection = this.multiSelect;
  30138. if (!additive)
  30139. selection.toSingleRange(ranges[0]);
  30140. for (var i = ranges.length; i--; )
  30141. selection.addRange(ranges[i], true);
  30142. if (range && selection.rangeList.rangeAtPoint(range.start))
  30143. selection.addRange(range, true);
  30144. this.$blockScrolling -= 1;
  30145. return ranges.length;
  30146. };
  30147. this.selectMoreLines = function(dir, skip) {
  30148. var range = this.selection.toOrientedRange();
  30149. var isBackwards = range.cursor == range.end;
  30150. var screenLead = this.session.documentToScreenPosition(range.cursor);
  30151. if (this.selection.$desiredColumn)
  30152. screenLead.column = this.selection.$desiredColumn;
  30153. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  30154. if (!range.isEmpty()) {
  30155. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  30156. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  30157. } else {
  30158. var anchor = lead;
  30159. }
  30160. if (isBackwards) {
  30161. var newRange = Range.fromPoints(lead, anchor);
  30162. newRange.cursor = newRange.start;
  30163. } else {
  30164. var newRange = Range.fromPoints(anchor, lead);
  30165. newRange.cursor = newRange.end;
  30166. }
  30167. newRange.desiredColumn = screenLead.column;
  30168. if (!this.selection.inMultiSelectMode) {
  30169. this.selection.addRange(range);
  30170. } else {
  30171. if (skip)
  30172. var toRemove = range.cursor;
  30173. }
  30174. this.selection.addRange(newRange);
  30175. if (toRemove)
  30176. this.selection.substractPoint(toRemove);
  30177. };
  30178. this.transposeSelections = function(dir) {
  30179. var session = this.session;
  30180. var sel = session.multiSelect;
  30181. var all = sel.ranges;
  30182. for (var i = all.length; i--; ) {
  30183. var range = all[i];
  30184. if (range.isEmpty()) {
  30185. var tmp = session.getWordRange(range.start.row, range.start.column);
  30186. range.start.row = tmp.start.row;
  30187. range.start.column = tmp.start.column;
  30188. range.end.row = tmp.end.row;
  30189. range.end.column = tmp.end.column;
  30190. }
  30191. }
  30192. sel.mergeOverlappingRanges();
  30193. var words = [];
  30194. for (var i = all.length; i--; ) {
  30195. var range = all[i];
  30196. words.unshift(session.getTextRange(range));
  30197. }
  30198. if (dir < 0)
  30199. words.unshift(words.pop());
  30200. else
  30201. words.push(words.shift());
  30202. for (var i = all.length; i--; ) {
  30203. var range = all[i];
  30204. var tmp = range.clone();
  30205. session.replace(range, words[i]);
  30206. range.start.row = tmp.start.row;
  30207. range.start.column = tmp.start.column;
  30208. }
  30209. };
  30210. this.selectMore = function(dir, skip, stopAtFirst) {
  30211. var session = this.session;
  30212. var sel = session.multiSelect;
  30213. var range = sel.toOrientedRange();
  30214. if (range.isEmpty()) {
  30215. range = session.getWordRange(range.start.row, range.start.column);
  30216. range.cursor = dir == -1 ? range.start : range.end;
  30217. this.multiSelect.addRange(range);
  30218. if (stopAtFirst)
  30219. return;
  30220. }
  30221. var needle = session.getTextRange(range);
  30222. var newRange = find(session, needle, dir);
  30223. if (newRange) {
  30224. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  30225. this.$blockScrolling += 1;
  30226. this.session.unfold(newRange);
  30227. this.multiSelect.addRange(newRange);
  30228. this.$blockScrolling -= 1;
  30229. this.renderer.scrollCursorIntoView(null, 0.5);
  30230. }
  30231. if (skip)
  30232. this.multiSelect.substractPoint(range.cursor);
  30233. };
  30234. this.alignCursors = function() {
  30235. var session = this.session;
  30236. var sel = session.multiSelect;
  30237. var ranges = sel.ranges;
  30238. var row = -1;
  30239. var sameRowRanges = ranges.filter(function(r) {
  30240. if (r.cursor.row == row)
  30241. return true;
  30242. row = r.cursor.row;
  30243. });
  30244. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  30245. var range = this.selection.getRange();
  30246. var fr = range.start.row, lr = range.end.row;
  30247. var guessRange = fr == lr;
  30248. if (guessRange) {
  30249. var max = this.session.getLength();
  30250. var line;
  30251. do {
  30252. line = this.session.getLine(lr);
  30253. } while (/[=:]/.test(line) && ++lr < max);
  30254. do {
  30255. line = this.session.getLine(fr);
  30256. } while (/[=:]/.test(line) && --fr > 0);
  30257. if (fr < 0) fr = 0;
  30258. if (lr >= max) lr = max - 1;
  30259. }
  30260. var lines = this.session.removeFullLines(fr, lr);
  30261. lines = this.$reAlignText(lines, guessRange);
  30262. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  30263. if (!guessRange) {
  30264. range.start.column = 0;
  30265. range.end.column = lines[lines.length - 1].length;
  30266. }
  30267. this.selection.setRange(range);
  30268. } else {
  30269. sameRowRanges.forEach(function(r) {
  30270. sel.substractPoint(r.cursor);
  30271. });
  30272. var maxCol = 0;
  30273. var minSpace = Infinity;
  30274. var spaceOffsets = ranges.map(function(r) {
  30275. var p = r.cursor;
  30276. var line = session.getLine(p.row);
  30277. var spaceOffset = line.substr(p.column).search(/\S/g);
  30278. if (spaceOffset == -1)
  30279. spaceOffset = 0;
  30280. if (p.column > maxCol)
  30281. maxCol = p.column;
  30282. if (spaceOffset < minSpace)
  30283. minSpace = spaceOffset;
  30284. return spaceOffset;
  30285. });
  30286. ranges.forEach(function(r, i) {
  30287. var p = r.cursor;
  30288. var l = maxCol - p.column;
  30289. var d = spaceOffsets[i] - minSpace;
  30290. if (l > d)
  30291. session.insert(p, lang.stringRepeat(" ", l - d));
  30292. else
  30293. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  30294. r.start.column = r.end.column = maxCol;
  30295. r.start.row = r.end.row = p.row;
  30296. r.cursor = r.end;
  30297. });
  30298. sel.fromOrientedRange(ranges[0]);
  30299. this.renderer.updateCursor();
  30300. this.renderer.updateBackMarkers();
  30301. }
  30302. };
  30303. this.$reAlignText = function(lines, forceLeft) {
  30304. var isLeftAligned = true, isRightAligned = true;
  30305. var startW, textW, endW;
  30306. return lines.map(function(line) {
  30307. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  30308. if (!m)
  30309. return [line];
  30310. if (startW == null) {
  30311. startW = m[1].length;
  30312. textW = m[2].length;
  30313. endW = m[3].length;
  30314. return m;
  30315. }
  30316. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  30317. isRightAligned = false;
  30318. if (startW != m[1].length)
  30319. isLeftAligned = false;
  30320. if (startW > m[1].length)
  30321. startW = m[1].length;
  30322. if (textW < m[2].length)
  30323. textW = m[2].length;
  30324. if (endW > m[3].length)
  30325. endW = m[3].length;
  30326. return m;
  30327. }).map(forceLeft ? alignLeft :
  30328. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  30329. function spaces(n) {
  30330. return lang.stringRepeat(" ", n);
  30331. }
  30332. function alignLeft(m) {
  30333. return !m[2] ? m[0] : spaces(startW) + m[2]
  30334. + spaces(textW - m[2].length + endW)
  30335. + m[4].replace(/^([=:])\s+/, "$1 ");
  30336. }
  30337. function alignRight(m) {
  30338. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  30339. + spaces(endW, " ")
  30340. + m[4].replace(/^([=:])\s+/, "$1 ");
  30341. }
  30342. function unAlign(m) {
  30343. return !m[2] ? m[0] : spaces(startW) + m[2]
  30344. + spaces(endW)
  30345. + m[4].replace(/^([=:])\s+/, "$1 ");
  30346. }
  30347. };
  30348. }).call(Editor.prototype);
  30349. function isSamePoint(p1, p2) {
  30350. return p1.row == p2.row && p1.column == p2.column;
  30351. }
  30352. exports.onSessionChange = function(e) {
  30353. var session = e.session;
  30354. if (session && !session.multiSelect) {
  30355. session.$selectionMarkers = [];
  30356. session.selection.$initRangeList();
  30357. session.multiSelect = session.selection;
  30358. }
  30359. this.multiSelect = session && session.multiSelect;
  30360. var oldSession = e.oldSession;
  30361. if (oldSession) {
  30362. oldSession.multiSelect.off("addRange", this.$onAddRange);
  30363. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  30364. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  30365. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  30366. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  30367. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  30368. }
  30369. if (session) {
  30370. session.multiSelect.on("addRange", this.$onAddRange);
  30371. session.multiSelect.on("removeRange", this.$onRemoveRange);
  30372. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  30373. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  30374. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  30375. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  30376. }
  30377. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  30378. if (session.selection.inMultiSelectMode)
  30379. this.$onMultiSelect();
  30380. else
  30381. this.$onSingleSelect();
  30382. }
  30383. };
  30384. function MultiSelect(editor) {
  30385. if (editor.$multiselectOnSessionChange)
  30386. return;
  30387. editor.$onAddRange = editor.$onAddRange.bind(editor);
  30388. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  30389. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  30390. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  30391. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  30392. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  30393. editor.$multiselectOnSessionChange(editor);
  30394. editor.on("changeSession", editor.$multiselectOnSessionChange);
  30395. editor.on("mousedown", onMouseDown);
  30396. editor.commands.addCommands(commands.defaultCommands);
  30397. addAltCursorListeners(editor);
  30398. }
  30399. function addAltCursorListeners(editor){
  30400. var el = editor.textInput.getElement();
  30401. var altCursor = false;
  30402. event.addListener(el, "keydown", function(e) {
  30403. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  30404. if (editor.$blockSelectEnabled && altDown) {
  30405. if (!altCursor) {
  30406. editor.renderer.setMouseCursor("crosshair");
  30407. altCursor = true;
  30408. }
  30409. } else if (altCursor) {
  30410. reset();
  30411. }
  30412. });
  30413. event.addListener(el, "keyup", reset);
  30414. event.addListener(el, "blur", reset);
  30415. function reset(e) {
  30416. if (altCursor) {
  30417. editor.renderer.setMouseCursor("");
  30418. altCursor = false;
  30419. }
  30420. }
  30421. }
  30422. exports.MultiSelect = MultiSelect;
  30423. acequire("./config").defineOptions(Editor.prototype, "editor", {
  30424. enableMultiselect: {
  30425. set: function(val) {
  30426. MultiSelect(this);
  30427. if (val) {
  30428. this.on("changeSession", this.$multiselectOnSessionChange);
  30429. this.on("mousedown", onMouseDown);
  30430. } else {
  30431. this.off("changeSession", this.$multiselectOnSessionChange);
  30432. this.off("mousedown", onMouseDown);
  30433. }
  30434. },
  30435. value: true
  30436. },
  30437. enableBlockSelect: {
  30438. set: function(val) {
  30439. this.$blockSelectEnabled = val;
  30440. },
  30441. value: true
  30442. }
  30443. });
  30444. });
  30445. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(acequire, exports, module) {
  30446. "use strict";
  30447. var Range = acequire("../../range").Range;
  30448. var FoldMode = exports.FoldMode = function() {};
  30449. (function() {
  30450. this.foldingStartMarker = null;
  30451. this.foldingStopMarker = null;
  30452. this.getFoldWidget = function(session, foldStyle, row) {
  30453. var line = session.getLine(row);
  30454. if (this.foldingStartMarker.test(line))
  30455. return "start";
  30456. if (foldStyle == "markbeginend"
  30457. && this.foldingStopMarker
  30458. && this.foldingStopMarker.test(line))
  30459. return "end";
  30460. return "";
  30461. };
  30462. this.getFoldWidgetRange = function(session, foldStyle, row) {
  30463. return null;
  30464. };
  30465. this.indentationBlock = function(session, row, column) {
  30466. var re = /\S/;
  30467. var line = session.getLine(row);
  30468. var startLevel = line.search(re);
  30469. if (startLevel == -1)
  30470. return;
  30471. var startColumn = column || line.length;
  30472. var maxRow = session.getLength();
  30473. var startRow = row;
  30474. var endRow = row;
  30475. while (++row < maxRow) {
  30476. var level = session.getLine(row).search(re);
  30477. if (level == -1)
  30478. continue;
  30479. if (level <= startLevel)
  30480. break;
  30481. endRow = row;
  30482. }
  30483. if (endRow > startRow) {
  30484. var endColumn = session.getLine(endRow).length;
  30485. return new Range(startRow, startColumn, endRow, endColumn);
  30486. }
  30487. };
  30488. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  30489. var start = {row: row, column: column + 1};
  30490. var end = session.$findClosingBracket(bracket, start, typeRe);
  30491. if (!end)
  30492. return;
  30493. var fw = session.foldWidgets[end.row];
  30494. if (fw == null)
  30495. fw = session.getFoldWidget(end.row);
  30496. if (fw == "start" && end.row > start.row) {
  30497. end.row --;
  30498. end.column = session.getLine(end.row).length;
  30499. }
  30500. return Range.fromPoints(start, end);
  30501. };
  30502. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  30503. var end = {row: row, column: column};
  30504. var start = session.$findOpeningBracket(bracket, end);
  30505. if (!start)
  30506. return;
  30507. start.column++;
  30508. end.column--;
  30509. return Range.fromPoints(start, end);
  30510. };
  30511. }).call(FoldMode.prototype);
  30512. });
  30513. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(acequire, exports, module) {
  30514. "use strict";
  30515. exports.isDark = false;
  30516. exports.cssClass = "ace-tm";
  30517. exports.cssText = ".ace-tm .ace_gutter {\
  30518. background: #f0f0f0;\
  30519. color: #333;\
  30520. }\
  30521. .ace-tm .ace_print-margin {\
  30522. width: 1px;\
  30523. background: #e8e8e8;\
  30524. }\
  30525. .ace-tm .ace_fold {\
  30526. background-color: #6B72E6;\
  30527. }\
  30528. .ace-tm {\
  30529. background-color: #FFFFFF;\
  30530. color: black;\
  30531. }\
  30532. .ace-tm .ace_cursor {\
  30533. color: black;\
  30534. }\
  30535. .ace-tm .ace_invisible {\
  30536. color: rgb(191, 191, 191);\
  30537. }\
  30538. .ace-tm .ace_storage,\
  30539. .ace-tm .ace_keyword {\
  30540. color: blue;\
  30541. }\
  30542. .ace-tm .ace_constant {\
  30543. color: rgb(197, 6, 11);\
  30544. }\
  30545. .ace-tm .ace_constant.ace_buildin {\
  30546. color: rgb(88, 72, 246);\
  30547. }\
  30548. .ace-tm .ace_constant.ace_language {\
  30549. color: rgb(88, 92, 246);\
  30550. }\
  30551. .ace-tm .ace_constant.ace_library {\
  30552. color: rgb(6, 150, 14);\
  30553. }\
  30554. .ace-tm .ace_invalid {\
  30555. background-color: rgba(255, 0, 0, 0.1);\
  30556. color: red;\
  30557. }\
  30558. .ace-tm .ace_support.ace_function {\
  30559. color: rgb(60, 76, 114);\
  30560. }\
  30561. .ace-tm .ace_support.ace_constant {\
  30562. color: rgb(6, 150, 14);\
  30563. }\
  30564. .ace-tm .ace_support.ace_type,\
  30565. .ace-tm .ace_support.ace_class {\
  30566. color: rgb(109, 121, 222);\
  30567. }\
  30568. .ace-tm .ace_keyword.ace_operator {\
  30569. color: rgb(104, 118, 135);\
  30570. }\
  30571. .ace-tm .ace_string {\
  30572. color: rgb(3, 106, 7);\
  30573. }\
  30574. .ace-tm .ace_comment {\
  30575. color: rgb(76, 136, 107);\
  30576. }\
  30577. .ace-tm .ace_comment.ace_doc {\
  30578. color: rgb(0, 102, 255);\
  30579. }\
  30580. .ace-tm .ace_comment.ace_doc.ace_tag {\
  30581. color: rgb(128, 159, 191);\
  30582. }\
  30583. .ace-tm .ace_constant.ace_numeric {\
  30584. color: rgb(0, 0, 205);\
  30585. }\
  30586. .ace-tm .ace_variable {\
  30587. color: rgb(49, 132, 149);\
  30588. }\
  30589. .ace-tm .ace_xml-pe {\
  30590. color: rgb(104, 104, 91);\
  30591. }\
  30592. .ace-tm .ace_entity.ace_name.ace_function {\
  30593. color: #0000A2;\
  30594. }\
  30595. .ace-tm .ace_heading {\
  30596. color: rgb(12, 7, 255);\
  30597. }\
  30598. .ace-tm .ace_list {\
  30599. color:rgb(185, 6, 144);\
  30600. }\
  30601. .ace-tm .ace_meta.ace_tag {\
  30602. color:rgb(0, 22, 142);\
  30603. }\
  30604. .ace-tm .ace_string.ace_regex {\
  30605. color: rgb(255, 0, 0)\
  30606. }\
  30607. .ace-tm .ace_marker-layer .ace_selection {\
  30608. background: rgb(181, 213, 255);\
  30609. }\
  30610. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  30611. box-shadow: 0 0 3px 0px white;\
  30612. }\
  30613. .ace-tm .ace_marker-layer .ace_step {\
  30614. background: rgb(252, 255, 0);\
  30615. }\
  30616. .ace-tm .ace_marker-layer .ace_stack {\
  30617. background: rgb(164, 229, 101);\
  30618. }\
  30619. .ace-tm .ace_marker-layer .ace_bracket {\
  30620. margin: -1px 0 0 -1px;\
  30621. border: 1px solid rgb(192, 192, 192);\
  30622. }\
  30623. .ace-tm .ace_marker-layer .ace_active-line {\
  30624. background: rgba(0, 0, 0, 0.07);\
  30625. }\
  30626. .ace-tm .ace_gutter-active-line {\
  30627. background-color : #dcdcdc;\
  30628. }\
  30629. .ace-tm .ace_marker-layer .ace_selected-word {\
  30630. background: rgb(250, 250, 255);\
  30631. border: 1px solid rgb(200, 200, 250);\
  30632. }\
  30633. .ace-tm .ace_indent-guide {\
  30634. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  30635. }\
  30636. ";
  30637. var dom = acequire("../lib/dom");
  30638. dom.importCssString(exports.cssText, exports.cssClass);
  30639. });
  30640. ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(acequire, exports, module) {
  30641. "use strict";
  30642. var oop = acequire("./lib/oop");
  30643. var dom = acequire("./lib/dom");
  30644. var Range = acequire("./range").Range;
  30645. function LineWidgets(session) {
  30646. this.session = session;
  30647. this.session.widgetManager = this;
  30648. this.session.getRowLength = this.getRowLength;
  30649. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  30650. this.updateOnChange = this.updateOnChange.bind(this);
  30651. this.renderWidgets = this.renderWidgets.bind(this);
  30652. this.measureWidgets = this.measureWidgets.bind(this);
  30653. this.session._changedWidgets = [];
  30654. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  30655. this.session.on("change", this.updateOnChange);
  30656. this.session.on("changeFold", this.updateOnFold);
  30657. this.session.on("changeEditor", this.$onChangeEditor);
  30658. }
  30659. (function() {
  30660. this.getRowLength = function(row) {
  30661. var h;
  30662. if (this.lineWidgets)
  30663. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  30664. else
  30665. h = 0;
  30666. if (!this.$useWrapMode || !this.$wrapData[row]) {
  30667. return 1 + h;
  30668. } else {
  30669. return this.$wrapData[row].length + 1 + h;
  30670. }
  30671. };
  30672. this.$getWidgetScreenLength = function() {
  30673. var screenRows = 0;
  30674. this.lineWidgets.forEach(function(w){
  30675. if (w && w.rowCount && !w.hidden)
  30676. screenRows += w.rowCount;
  30677. });
  30678. return screenRows;
  30679. };
  30680. this.$onChangeEditor = function(e) {
  30681. this.attach(e.editor);
  30682. };
  30683. this.attach = function(editor) {
  30684. if (editor && editor.widgetManager && editor.widgetManager != this)
  30685. editor.widgetManager.detach();
  30686. if (this.editor == editor)
  30687. return;
  30688. this.detach();
  30689. this.editor = editor;
  30690. if (editor) {
  30691. editor.widgetManager = this;
  30692. editor.renderer.on("beforeRender", this.measureWidgets);
  30693. editor.renderer.on("afterRender", this.renderWidgets);
  30694. }
  30695. };
  30696. this.detach = function(e) {
  30697. var editor = this.editor;
  30698. if (!editor)
  30699. return;
  30700. this.editor = null;
  30701. editor.widgetManager = null;
  30702. editor.renderer.off("beforeRender", this.measureWidgets);
  30703. editor.renderer.off("afterRender", this.renderWidgets);
  30704. var lineWidgets = this.session.lineWidgets;
  30705. lineWidgets && lineWidgets.forEach(function(w) {
  30706. if (w && w.el && w.el.parentNode) {
  30707. w._inDocument = false;
  30708. w.el.parentNode.removeChild(w.el);
  30709. }
  30710. });
  30711. };
  30712. this.updateOnFold = function(e, session) {
  30713. var lineWidgets = session.lineWidgets;
  30714. if (!lineWidgets || !e.action)
  30715. return;
  30716. var fold = e.data;
  30717. var start = fold.start.row;
  30718. var end = fold.end.row;
  30719. var hide = e.action == "add";
  30720. for (var i = start + 1; i < end; i++) {
  30721. if (lineWidgets[i])
  30722. lineWidgets[i].hidden = hide;
  30723. }
  30724. if (lineWidgets[end]) {
  30725. if (hide) {
  30726. if (!lineWidgets[start])
  30727. lineWidgets[start] = lineWidgets[end];
  30728. else
  30729. lineWidgets[end].hidden = hide;
  30730. } else {
  30731. if (lineWidgets[start] == lineWidgets[end])
  30732. lineWidgets[start] = undefined;
  30733. lineWidgets[end].hidden = hide;
  30734. }
  30735. }
  30736. };
  30737. this.updateOnChange = function(delta) {
  30738. var lineWidgets = this.session.lineWidgets;
  30739. if (!lineWidgets) return;
  30740. var startRow = delta.start.row;
  30741. var len = delta.end.row - startRow;
  30742. if (len === 0) {
  30743. } else if (delta.action == 'remove') {
  30744. var removed = lineWidgets.splice(startRow + 1, len);
  30745. removed.forEach(function(w) {
  30746. w && this.removeLineWidget(w);
  30747. }, this);
  30748. this.$updateRows();
  30749. } else {
  30750. var args = new Array(len);
  30751. args.unshift(startRow, 0);
  30752. lineWidgets.splice.apply(lineWidgets, args);
  30753. this.$updateRows();
  30754. }
  30755. };
  30756. this.$updateRows = function() {
  30757. var lineWidgets = this.session.lineWidgets;
  30758. if (!lineWidgets) return;
  30759. var noWidgets = true;
  30760. lineWidgets.forEach(function(w, i) {
  30761. if (w) {
  30762. noWidgets = false;
  30763. w.row = i;
  30764. while (w.$oldWidget) {
  30765. w.$oldWidget.row = i;
  30766. w = w.$oldWidget;
  30767. }
  30768. }
  30769. });
  30770. if (noWidgets)
  30771. this.session.lineWidgets = null;
  30772. };
  30773. this.addLineWidget = function(w) {
  30774. if (!this.session.lineWidgets)
  30775. this.session.lineWidgets = new Array(this.session.getLength());
  30776. var old = this.session.lineWidgets[w.row];
  30777. if (old) {
  30778. w.$oldWidget = old;
  30779. if (old.el && old.el.parentNode) {
  30780. old.el.parentNode.removeChild(old.el);
  30781. old._inDocument = false;
  30782. }
  30783. }
  30784. this.session.lineWidgets[w.row] = w;
  30785. w.session = this.session;
  30786. var renderer = this.editor.renderer;
  30787. if (w.html && !w.el) {
  30788. w.el = dom.createElement("div");
  30789. w.el.innerHTML = w.html;
  30790. }
  30791. if (w.el) {
  30792. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  30793. w.el.style.position = "absolute";
  30794. w.el.style.zIndex = 5;
  30795. renderer.container.appendChild(w.el);
  30796. w._inDocument = true;
  30797. }
  30798. if (!w.coverGutter) {
  30799. w.el.style.zIndex = 3;
  30800. }
  30801. if (!w.pixelHeight) {
  30802. w.pixelHeight = w.el.offsetHeight;
  30803. }
  30804. if (w.rowCount == null) {
  30805. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  30806. }
  30807. var fold = this.session.getFoldAt(w.row, 0);
  30808. w.$fold = fold;
  30809. if (fold) {
  30810. var lineWidgets = this.session.lineWidgets;
  30811. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  30812. lineWidgets[fold.start.row] = w;
  30813. else
  30814. w.hidden = true;
  30815. }
  30816. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  30817. this.$updateRows();
  30818. this.renderWidgets(null, renderer);
  30819. this.onWidgetChanged(w);
  30820. return w;
  30821. };
  30822. this.removeLineWidget = function(w) {
  30823. w._inDocument = false;
  30824. w.session = null;
  30825. if (w.el && w.el.parentNode)
  30826. w.el.parentNode.removeChild(w.el);
  30827. if (w.editor && w.editor.destroy) try {
  30828. w.editor.destroy();
  30829. } catch(e){}
  30830. if (this.session.lineWidgets) {
  30831. var w1 = this.session.lineWidgets[w.row]
  30832. if (w1 == w) {
  30833. this.session.lineWidgets[w.row] = w.$oldWidget;
  30834. if (w.$oldWidget)
  30835. this.onWidgetChanged(w.$oldWidget);
  30836. } else {
  30837. while (w1) {
  30838. if (w1.$oldWidget == w) {
  30839. w1.$oldWidget = w.$oldWidget;
  30840. break;
  30841. }
  30842. w1 = w1.$oldWidget;
  30843. }
  30844. }
  30845. }
  30846. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  30847. this.$updateRows();
  30848. };
  30849. this.getWidgetsAtRow = function(row) {
  30850. var lineWidgets = this.session.lineWidgets;
  30851. var w = lineWidgets && lineWidgets[row];
  30852. var list = [];
  30853. while (w) {
  30854. list.push(w);
  30855. w = w.$oldWidget;
  30856. }
  30857. return list;
  30858. };
  30859. this.onWidgetChanged = function(w) {
  30860. this.session._changedWidgets.push(w);
  30861. this.editor && this.editor.renderer.updateFull();
  30862. };
  30863. this.measureWidgets = function(e, renderer) {
  30864. var changedWidgets = this.session._changedWidgets;
  30865. var config = renderer.layerConfig;
  30866. if (!changedWidgets || !changedWidgets.length) return;
  30867. var min = Infinity;
  30868. for (var i = 0; i < changedWidgets.length; i++) {
  30869. var w = changedWidgets[i];
  30870. if (!w || !w.el) continue;
  30871. if (w.session != this.session) continue;
  30872. if (!w._inDocument) {
  30873. if (this.session.lineWidgets[w.row] != w)
  30874. continue;
  30875. w._inDocument = true;
  30876. renderer.container.appendChild(w.el);
  30877. }
  30878. w.h = w.el.offsetHeight;
  30879. if (!w.fixedWidth) {
  30880. w.w = w.el.offsetWidth;
  30881. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  30882. }
  30883. var rowCount = w.h / config.lineHeight;
  30884. if (w.coverLine) {
  30885. rowCount -= this.session.getRowLineCount(w.row);
  30886. if (rowCount < 0)
  30887. rowCount = 0;
  30888. }
  30889. if (w.rowCount != rowCount) {
  30890. w.rowCount = rowCount;
  30891. if (w.row < min)
  30892. min = w.row;
  30893. }
  30894. }
  30895. if (min != Infinity) {
  30896. this.session._emit("changeFold", {data:{start:{row: min}}});
  30897. this.session.lineWidgetWidth = null;
  30898. }
  30899. this.session._changedWidgets = [];
  30900. };
  30901. this.renderWidgets = function(e, renderer) {
  30902. var config = renderer.layerConfig;
  30903. var lineWidgets = this.session.lineWidgets;
  30904. if (!lineWidgets)
  30905. return;
  30906. var first = Math.min(this.firstRow, config.firstRow);
  30907. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  30908. while (first > 0 && !lineWidgets[first])
  30909. first--;
  30910. this.firstRow = config.firstRow;
  30911. this.lastRow = config.lastRow;
  30912. renderer.$cursorLayer.config = config;
  30913. for (var i = first; i <= last; i++) {
  30914. var w = lineWidgets[i];
  30915. if (!w || !w.el) continue;
  30916. if (w.hidden) {
  30917. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  30918. continue;
  30919. }
  30920. if (!w._inDocument) {
  30921. w._inDocument = true;
  30922. renderer.container.appendChild(w.el);
  30923. }
  30924. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  30925. if (!w.coverLine)
  30926. top += config.lineHeight * this.session.getRowLineCount(w.row);
  30927. w.el.style.top = top - config.offset + "px";
  30928. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  30929. if (!w.fixedWidth)
  30930. left -= renderer.scrollLeft;
  30931. w.el.style.left = left + "px";
  30932. if (w.fullWidth && w.screenWidth) {
  30933. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  30934. }
  30935. if (w.fixedWidth) {
  30936. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  30937. } else {
  30938. w.el.style.right = "";
  30939. }
  30940. }
  30941. };
  30942. }).call(LineWidgets.prototype);
  30943. exports.LineWidgets = LineWidgets;
  30944. });
  30945. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(acequire, exports, module) {
  30946. "use strict";
  30947. var LineWidgets = acequire("../line_widgets").LineWidgets;
  30948. var dom = acequire("../lib/dom");
  30949. var Range = acequire("../range").Range;
  30950. function binarySearch(array, needle, comparator) {
  30951. var first = 0;
  30952. var last = array.length - 1;
  30953. while (first <= last) {
  30954. var mid = (first + last) >> 1;
  30955. var c = comparator(needle, array[mid]);
  30956. if (c > 0)
  30957. first = mid + 1;
  30958. else if (c < 0)
  30959. last = mid - 1;
  30960. else
  30961. return mid;
  30962. }
  30963. return -(first + 1);
  30964. }
  30965. function findAnnotations(session, row, dir) {
  30966. var annotations = session.getAnnotations().sort(Range.comparePoints);
  30967. if (!annotations.length)
  30968. return;
  30969. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  30970. if (i < 0)
  30971. i = -i - 1;
  30972. if (i >= annotations.length)
  30973. i = dir > 0 ? 0 : annotations.length - 1;
  30974. else if (i === 0 && dir < 0)
  30975. i = annotations.length - 1;
  30976. var annotation = annotations[i];
  30977. if (!annotation || !dir)
  30978. return;
  30979. if (annotation.row === row) {
  30980. do {
  30981. annotation = annotations[i += dir];
  30982. } while (annotation && annotation.row === row);
  30983. if (!annotation)
  30984. return annotations.slice();
  30985. }
  30986. var matched = [];
  30987. row = annotation.row;
  30988. do {
  30989. matched[dir < 0 ? "unshift" : "push"](annotation);
  30990. annotation = annotations[i += dir];
  30991. } while (annotation && annotation.row == row);
  30992. return matched.length && matched;
  30993. }
  30994. exports.showErrorMarker = function(editor, dir) {
  30995. var session = editor.session;
  30996. if (!session.widgetManager) {
  30997. session.widgetManager = new LineWidgets(session);
  30998. session.widgetManager.attach(editor);
  30999. }
  31000. var pos = editor.getCursorPosition();
  31001. var row = pos.row;
  31002. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  31003. return w.type == "errorMarker";
  31004. })[0];
  31005. if (oldWidget) {
  31006. oldWidget.destroy();
  31007. } else {
  31008. row -= dir;
  31009. }
  31010. var annotations = findAnnotations(session, row, dir);
  31011. var gutterAnno;
  31012. if (annotations) {
  31013. var annotation = annotations[0];
  31014. pos.column = (annotation.pos && typeof annotation.column != "number"
  31015. ? annotation.pos.sc
  31016. : annotation.column) || 0;
  31017. pos.row = annotation.row;
  31018. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  31019. } else if (oldWidget) {
  31020. return;
  31021. } else {
  31022. gutterAnno = {
  31023. text: ["Looks good!"],
  31024. className: "ace_ok"
  31025. };
  31026. }
  31027. editor.session.unfold(pos.row);
  31028. editor.selection.moveToPosition(pos);
  31029. var w = {
  31030. row: pos.row,
  31031. fixedWidth: true,
  31032. coverGutter: true,
  31033. el: dom.createElement("div"),
  31034. type: "errorMarker"
  31035. };
  31036. var el = w.el.appendChild(dom.createElement("div"));
  31037. var arrow = w.el.appendChild(dom.createElement("div"));
  31038. arrow.className = "error_widget_arrow " + gutterAnno.className;
  31039. var left = editor.renderer.$cursorLayer
  31040. .getPixelPosition(pos).left;
  31041. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  31042. w.el.className = "error_widget_wrapper";
  31043. el.className = "error_widget " + gutterAnno.className;
  31044. el.innerHTML = gutterAnno.text.join("<br>");
  31045. el.appendChild(dom.createElement("div"));
  31046. var kb = function(_, hashId, keyString) {
  31047. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  31048. w.destroy();
  31049. return {command: "null"};
  31050. }
  31051. };
  31052. w.destroy = function() {
  31053. if (editor.$mouseHandler.isMousePressed)
  31054. return;
  31055. editor.keyBinding.removeKeyboardHandler(kb);
  31056. session.widgetManager.removeLineWidget(w);
  31057. editor.off("changeSelection", w.destroy);
  31058. editor.off("changeSession", w.destroy);
  31059. editor.off("mouseup", w.destroy);
  31060. editor.off("change", w.destroy);
  31061. };
  31062. editor.keyBinding.addKeyboardHandler(kb);
  31063. editor.on("changeSelection", w.destroy);
  31064. editor.on("changeSession", w.destroy);
  31065. editor.on("mouseup", w.destroy);
  31066. editor.on("change", w.destroy);
  31067. editor.session.widgetManager.addLineWidget(w);
  31068. w.el.onmousedown = editor.focus.bind(editor);
  31069. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  31070. };
  31071. dom.importCssString("\
  31072. .error_widget_wrapper {\
  31073. background: inherit;\
  31074. color: inherit;\
  31075. border:none\
  31076. }\
  31077. .error_widget {\
  31078. border-top: solid 2px;\
  31079. border-bottom: solid 2px;\
  31080. margin: 5px 0;\
  31081. padding: 10px 40px;\
  31082. white-space: pre-wrap;\
  31083. }\
  31084. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  31085. border-color: #ff5a5a\
  31086. }\
  31087. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  31088. border-color: #F1D817\
  31089. }\
  31090. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  31091. border-color: #5a5a5a\
  31092. }\
  31093. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  31094. border-color: #5aaa5a\
  31095. }\
  31096. .error_widget_arrow {\
  31097. position: absolute;\
  31098. border: solid 5px;\
  31099. border-top-color: transparent!important;\
  31100. border-right-color: transparent!important;\
  31101. border-left-color: transparent!important;\
  31102. top: -5px;\
  31103. }\
  31104. ", "");
  31105. });
  31106. ace.define("ace/ace",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/dom","ace/lib/event","ace/editor","ace/edit_session","ace/undomanager","ace/virtual_renderer","ace/worker/worker_client","ace/keyboard/hash_handler","ace/placeholder","ace/multi_select","ace/mode/folding/fold_mode","ace/theme/textmate","ace/ext/error_marker","ace/config"], function(acequire, exports, module) {
  31107. "use strict";
  31108. acequire("./lib/fixoldbrowsers");
  31109. var dom = acequire("./lib/dom");
  31110. var event = acequire("./lib/event");
  31111. var Editor = acequire("./editor").Editor;
  31112. var EditSession = acequire("./edit_session").EditSession;
  31113. var UndoManager = acequire("./undomanager").UndoManager;
  31114. var Renderer = acequire("./virtual_renderer").VirtualRenderer;
  31115. acequire("./worker/worker_client");
  31116. acequire("./keyboard/hash_handler");
  31117. acequire("./placeholder");
  31118. acequire("./multi_select");
  31119. acequire("./mode/folding/fold_mode");
  31120. acequire("./theme/textmate");
  31121. acequire("./ext/error_marker");
  31122. exports.config = acequire("./config");
  31123. exports.acequire = acequire;
  31124. exports.edit = function(el) {
  31125. if (typeof el == "string") {
  31126. var _id = el;
  31127. el = document.getElementById(_id);
  31128. if (!el)
  31129. throw new Error("ace.edit can't find div #" + _id);
  31130. }
  31131. if (el && el.env && el.env.editor instanceof Editor)
  31132. return el.env.editor;
  31133. var value = "";
  31134. if (el && /input|textarea/i.test(el.tagName)) {
  31135. var oldNode = el;
  31136. value = oldNode.value;
  31137. el = dom.createElement("pre");
  31138. oldNode.parentNode.replaceChild(el, oldNode);
  31139. } else if (el) {
  31140. value = dom.getInnerText(el);
  31141. el.innerHTML = "";
  31142. }
  31143. var doc = exports.createEditSession(value);
  31144. var editor = new Editor(new Renderer(el));
  31145. editor.setSession(doc);
  31146. var env = {
  31147. document: doc,
  31148. editor: editor,
  31149. onResize: editor.resize.bind(editor, null)
  31150. };
  31151. if (oldNode) env.textarea = oldNode;
  31152. event.addListener(window, "resize", env.onResize);
  31153. editor.on("destroy", function() {
  31154. event.removeListener(window, "resize", env.onResize);
  31155. env.editor.container.env = null; // prevent memory leak on old ie
  31156. });
  31157. editor.container.env = editor.env = env;
  31158. return editor;
  31159. };
  31160. exports.createEditSession = function(text, mode) {
  31161. var doc = new EditSession(text, mode);
  31162. doc.setUndoManager(new UndoManager());
  31163. return doc;
  31164. }
  31165. exports.EditSession = EditSession;
  31166. exports.UndoManager = UndoManager;
  31167. exports.version = "1.2.3";
  31168. });
  31169. (function() {
  31170. ace.acequire(["ace/ace"], function(a) {
  31171. a && a.config.init(true);
  31172. if (!window.ace)
  31173. window.ace = a;
  31174. for (var key in a) if (a.hasOwnProperty(key))
  31175. window.ace[key] = a[key];
  31176. });
  31177. })();
  31178. module.exports = window.ace.acequire("ace/ace");
  31179. /***/ },
  31180. /* 65 */
  31181. /***/ function(module, exports) {
  31182. module.exports = function() { throw new Error("define cannot be used indirect"); };
  31183. /***/ },
  31184. /* 66 */
  31185. /***/ function(module, exports) {
  31186. /* WEBPACK VAR INJECTION */(function(global) {module.exports = get_blob()
  31187. function get_blob() {
  31188. if(global.Blob) {
  31189. try {
  31190. new Blob(['asdf'], {type: 'text/plain'})
  31191. return Blob
  31192. } catch(err) {}
  31193. }
  31194. var Builder = global.WebKitBlobBuilder ||
  31195. global.MozBlobBuilder ||
  31196. global.MSBlobBuilder
  31197. return function(parts, bag) {
  31198. var builder = new Builder
  31199. , endings = bag.endings
  31200. , type = bag.type
  31201. if(endings) for(var i = 0, len = parts.length; i < len; ++i) {
  31202. builder.append(parts[i], endings)
  31203. } else for(var i = 0, len = parts.length; i < len; ++i) {
  31204. builder.append(parts[i])
  31205. }
  31206. return type ? builder.getBlob(type) : builder.getBlob()
  31207. }
  31208. }
  31209. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  31210. /***/ },
  31211. /* 67 */
  31212. /***/ function(module, exports, __webpack_require__) {
  31213. ace.define("ace/mode/json_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(acequire, exports, module) {
  31214. "use strict";
  31215. var oop = acequire("../lib/oop");
  31216. var TextHighlightRules = acequire("./text_highlight_rules").TextHighlightRules;
  31217. var JsonHighlightRules = function() {
  31218. this.$rules = {
  31219. "start" : [
  31220. {
  31221. token : "variable", // single line
  31222. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)'
  31223. }, {
  31224. token : "string", // single line
  31225. regex : '"',
  31226. next : "string"
  31227. }, {
  31228. token : "constant.numeric", // hex
  31229. regex : "0[xX][0-9a-fA-F]+\\b"
  31230. }, {
  31231. token : "constant.numeric", // float
  31232. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  31233. }, {
  31234. token : "constant.language.boolean",
  31235. regex : "(?:true|false)\\b"
  31236. }, {
  31237. token : "invalid.illegal", // single quoted strings are not allowed
  31238. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  31239. }, {
  31240. token : "invalid.illegal", // comments are not allowed
  31241. regex : "\\/\\/.*$"
  31242. }, {
  31243. token : "paren.lparen",
  31244. regex : "[[({]"
  31245. }, {
  31246. token : "paren.rparen",
  31247. regex : "[\\])}]"
  31248. }, {
  31249. token : "text",
  31250. regex : "\\s+"
  31251. }
  31252. ],
  31253. "string" : [
  31254. {
  31255. token : "constant.language.escape",
  31256. regex : /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|["\\\/bfnrt])/
  31257. }, {
  31258. token : "string",
  31259. regex : '[^"\\\\]+'
  31260. }, {
  31261. token : "string",
  31262. regex : '"',
  31263. next : "start"
  31264. }, {
  31265. token : "string",
  31266. regex : "",
  31267. next : "start"
  31268. }
  31269. ]
  31270. };
  31271. };
  31272. oop.inherits(JsonHighlightRules, TextHighlightRules);
  31273. exports.JsonHighlightRules = JsonHighlightRules;
  31274. });
  31275. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(acequire, exports, module) {
  31276. "use strict";
  31277. var Range = acequire("../range").Range;
  31278. var MatchingBraceOutdent = function() {};
  31279. (function() {
  31280. this.checkOutdent = function(line, input) {
  31281. if (! /^\s+$/.test(line))
  31282. return false;
  31283. return /^\s*\}/.test(input);
  31284. };
  31285. this.autoOutdent = function(doc, row) {
  31286. var line = doc.getLine(row);
  31287. var match = line.match(/^(\s*\})/);
  31288. if (!match) return 0;
  31289. var column = match[1].length;
  31290. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  31291. if (!openBracePos || openBracePos.row == row) return 0;
  31292. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  31293. doc.replace(new Range(row, 0, row, column-1), indent);
  31294. };
  31295. this.$getIndent = function(line) {
  31296. return line.match(/^\s*/)[0];
  31297. };
  31298. }).call(MatchingBraceOutdent.prototype);
  31299. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  31300. });
  31301. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(acequire, exports, module) {
  31302. "use strict";
  31303. var oop = acequire("../../lib/oop");
  31304. var Behaviour = acequire("../behaviour").Behaviour;
  31305. var TokenIterator = acequire("../../token_iterator").TokenIterator;
  31306. var lang = acequire("../../lib/lang");
  31307. var SAFE_INSERT_IN_TOKENS =
  31308. ["text", "paren.rparen", "punctuation.operator"];
  31309. var SAFE_INSERT_BEFORE_TOKENS =
  31310. ["text", "paren.rparen", "punctuation.operator", "comment"];
  31311. var context;
  31312. var contextCache = {};
  31313. var initContext = function(editor) {
  31314. var id = -1;
  31315. if (editor.multiSelect) {
  31316. id = editor.selection.index;
  31317. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  31318. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  31319. }
  31320. if (contextCache[id])
  31321. return context = contextCache[id];
  31322. context = contextCache[id] = {
  31323. autoInsertedBrackets: 0,
  31324. autoInsertedRow: -1,
  31325. autoInsertedLineEnd: "",
  31326. maybeInsertedBrackets: 0,
  31327. maybeInsertedRow: -1,
  31328. maybeInsertedLineStart: "",
  31329. maybeInsertedLineEnd: ""
  31330. };
  31331. };
  31332. var getWrapped = function(selection, selected, opening, closing) {
  31333. var rowDiff = selection.end.row - selection.start.row;
  31334. return {
  31335. text: opening + selected + closing,
  31336. selection: [
  31337. 0,
  31338. selection.start.column + 1,
  31339. rowDiff,
  31340. selection.end.column + (rowDiff ? 0 : 1)
  31341. ]
  31342. };
  31343. };
  31344. var CstyleBehaviour = function() {
  31345. this.add("braces", "insertion", function(state, action, editor, session, text) {
  31346. var cursor = editor.getCursorPosition();
  31347. var line = session.doc.getLine(cursor.row);
  31348. if (text == '{') {
  31349. initContext(editor);
  31350. var selection = editor.getSelectionRange();
  31351. var selected = session.doc.getTextRange(selection);
  31352. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  31353. return getWrapped(selection, selected, '{', '}');
  31354. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  31355. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  31356. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  31357. return {
  31358. text: '{}',
  31359. selection: [1, 1]
  31360. };
  31361. } else {
  31362. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  31363. return {
  31364. text: '{',
  31365. selection: [1, 1]
  31366. };
  31367. }
  31368. }
  31369. } else if (text == '}') {
  31370. initContext(editor);
  31371. var rightChar = line.substring(cursor.column, cursor.column + 1);
  31372. if (rightChar == '}') {
  31373. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  31374. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  31375. CstyleBehaviour.popAutoInsertedClosing();
  31376. return {
  31377. text: '',
  31378. selection: [1, 1]
  31379. };
  31380. }
  31381. }
  31382. } else if (text == "\n" || text == "\r\n") {
  31383. initContext(editor);
  31384. var closing = "";
  31385. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  31386. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  31387. CstyleBehaviour.clearMaybeInsertedClosing();
  31388. }
  31389. var rightChar = line.substring(cursor.column, cursor.column + 1);
  31390. if (rightChar === '}') {
  31391. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  31392. if (!openBracePos)
  31393. return null;
  31394. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  31395. } else if (closing) {
  31396. var next_indent = this.$getIndent(line);
  31397. } else {
  31398. CstyleBehaviour.clearMaybeInsertedClosing();
  31399. return;
  31400. }
  31401. var indent = next_indent + session.getTabString();
  31402. return {
  31403. text: '\n' + indent + '\n' + next_indent + closing,
  31404. selection: [1, indent.length, 1, indent.length]
  31405. };
  31406. } else {
  31407. CstyleBehaviour.clearMaybeInsertedClosing();
  31408. }
  31409. });
  31410. this.add("braces", "deletion", function(state, action, editor, session, range) {
  31411. var selected = session.doc.getTextRange(range);
  31412. if (!range.isMultiLine() && selected == '{') {
  31413. initContext(editor);
  31414. var line = session.doc.getLine(range.start.row);
  31415. var rightChar = line.substring(range.end.column, range.end.column + 1);
  31416. if (rightChar == '}') {
  31417. range.end.column++;
  31418. return range;
  31419. } else {
  31420. context.maybeInsertedBrackets--;
  31421. }
  31422. }
  31423. });
  31424. this.add("parens", "insertion", function(state, action, editor, session, text) {
  31425. if (text == '(') {
  31426. initContext(editor);
  31427. var selection = editor.getSelectionRange();
  31428. var selected = session.doc.getTextRange(selection);
  31429. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  31430. return getWrapped(selection, selected, '(', ')');
  31431. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  31432. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  31433. return {
  31434. text: '()',
  31435. selection: [1, 1]
  31436. };
  31437. }
  31438. } else if (text == ')') {
  31439. initContext(editor);
  31440. var cursor = editor.getCursorPosition();
  31441. var line = session.doc.getLine(cursor.row);
  31442. var rightChar = line.substring(cursor.column, cursor.column + 1);
  31443. if (rightChar == ')') {
  31444. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  31445. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  31446. CstyleBehaviour.popAutoInsertedClosing();
  31447. return {
  31448. text: '',
  31449. selection: [1, 1]
  31450. };
  31451. }
  31452. }
  31453. }
  31454. });
  31455. this.add("parens", "deletion", function(state, action, editor, session, range) {
  31456. var selected = session.doc.getTextRange(range);
  31457. if (!range.isMultiLine() && selected == '(') {
  31458. initContext(editor);
  31459. var line = session.doc.getLine(range.start.row);
  31460. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  31461. if (rightChar == ')') {
  31462. range.end.column++;
  31463. return range;
  31464. }
  31465. }
  31466. });
  31467. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  31468. if (text == '[') {
  31469. initContext(editor);
  31470. var selection = editor.getSelectionRange();
  31471. var selected = session.doc.getTextRange(selection);
  31472. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  31473. return getWrapped(selection, selected, '[', ']');
  31474. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  31475. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  31476. return {
  31477. text: '[]',
  31478. selection: [1, 1]
  31479. };
  31480. }
  31481. } else if (text == ']') {
  31482. initContext(editor);
  31483. var cursor = editor.getCursorPosition();
  31484. var line = session.doc.getLine(cursor.row);
  31485. var rightChar = line.substring(cursor.column, cursor.column + 1);
  31486. if (rightChar == ']') {
  31487. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  31488. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  31489. CstyleBehaviour.popAutoInsertedClosing();
  31490. return {
  31491. text: '',
  31492. selection: [1, 1]
  31493. };
  31494. }
  31495. }
  31496. }
  31497. });
  31498. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  31499. var selected = session.doc.getTextRange(range);
  31500. if (!range.isMultiLine() && selected == '[') {
  31501. initContext(editor);
  31502. var line = session.doc.getLine(range.start.row);
  31503. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  31504. if (rightChar == ']') {
  31505. range.end.column++;
  31506. return range;
  31507. }
  31508. }
  31509. });
  31510. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  31511. if (text == '"' || text == "'") {
  31512. initContext(editor);
  31513. var quote = text;
  31514. var selection = editor.getSelectionRange();
  31515. var selected = session.doc.getTextRange(selection);
  31516. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  31517. return getWrapped(selection, selected, quote, quote);
  31518. } else if (!selected) {
  31519. var cursor = editor.getCursorPosition();
  31520. var line = session.doc.getLine(cursor.row);
  31521. var leftChar = line.substring(cursor.column-1, cursor.column);
  31522. var rightChar = line.substring(cursor.column, cursor.column + 1);
  31523. var token = session.getTokenAt(cursor.row, cursor.column);
  31524. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  31525. if (leftChar == "\\" && token && /escape/.test(token.type))
  31526. return null;
  31527. var stringBefore = token && /string|escape/.test(token.type);
  31528. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  31529. var pair;
  31530. if (rightChar == quote) {
  31531. pair = stringBefore !== stringAfter;
  31532. } else {
  31533. if (stringBefore && !stringAfter)
  31534. return null; // wrap string with different quote
  31535. if (stringBefore && stringAfter)
  31536. return null; // do not pair quotes inside strings
  31537. var wordRe = session.$mode.tokenRe;
  31538. wordRe.lastIndex = 0;
  31539. var isWordBefore = wordRe.test(leftChar);
  31540. wordRe.lastIndex = 0;
  31541. var isWordAfter = wordRe.test(leftChar);
  31542. if (isWordBefore || isWordAfter)
  31543. return null; // before or after alphanumeric
  31544. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  31545. return null; // there is rightChar and it isn't closing
  31546. pair = true;
  31547. }
  31548. return {
  31549. text: pair ? quote + quote : "",
  31550. selection: [1,1]
  31551. };
  31552. }
  31553. }
  31554. });
  31555. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  31556. var selected = session.doc.getTextRange(range);
  31557. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  31558. initContext(editor);
  31559. var line = session.doc.getLine(range.start.row);
  31560. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  31561. if (rightChar == selected) {
  31562. range.end.column++;
  31563. return range;
  31564. }
  31565. }
  31566. });
  31567. };
  31568. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  31569. var cursor = editor.getCursorPosition();
  31570. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  31571. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  31572. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  31573. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  31574. return false;
  31575. }
  31576. iterator.stepForward();
  31577. return iterator.getCurrentTokenRow() !== cursor.row ||
  31578. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  31579. };
  31580. CstyleBehaviour.$matchTokenType = function(token, types) {
  31581. return types.indexOf(token.type || token) > -1;
  31582. };
  31583. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  31584. var cursor = editor.getCursorPosition();
  31585. var line = session.doc.getLine(cursor.row);
  31586. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  31587. context.autoInsertedBrackets = 0;
  31588. context.autoInsertedRow = cursor.row;
  31589. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  31590. context.autoInsertedBrackets++;
  31591. };
  31592. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  31593. var cursor = editor.getCursorPosition();
  31594. var line = session.doc.getLine(cursor.row);
  31595. if (!this.isMaybeInsertedClosing(cursor, line))
  31596. context.maybeInsertedBrackets = 0;
  31597. context.maybeInsertedRow = cursor.row;
  31598. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  31599. context.maybeInsertedLineEnd = line.substr(cursor.column);
  31600. context.maybeInsertedBrackets++;
  31601. };
  31602. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  31603. return context.autoInsertedBrackets > 0 &&
  31604. cursor.row === context.autoInsertedRow &&
  31605. bracket === context.autoInsertedLineEnd[0] &&
  31606. line.substr(cursor.column) === context.autoInsertedLineEnd;
  31607. };
  31608. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  31609. return context.maybeInsertedBrackets > 0 &&
  31610. cursor.row === context.maybeInsertedRow &&
  31611. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  31612. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  31613. };
  31614. CstyleBehaviour.popAutoInsertedClosing = function() {
  31615. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  31616. context.autoInsertedBrackets--;
  31617. };
  31618. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  31619. if (context) {
  31620. context.maybeInsertedBrackets = 0;
  31621. context.maybeInsertedRow = -1;
  31622. }
  31623. };
  31624. oop.inherits(CstyleBehaviour, Behaviour);
  31625. exports.CstyleBehaviour = CstyleBehaviour;
  31626. });
  31627. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(acequire, exports, module) {
  31628. "use strict";
  31629. var oop = acequire("../../lib/oop");
  31630. var Range = acequire("../../range").Range;
  31631. var BaseFoldMode = acequire("./fold_mode").FoldMode;
  31632. var FoldMode = exports.FoldMode = function(commentRegex) {
  31633. if (commentRegex) {
  31634. this.foldingStartMarker = new RegExp(
  31635. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  31636. );
  31637. this.foldingStopMarker = new RegExp(
  31638. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  31639. );
  31640. }
  31641. };
  31642. oop.inherits(FoldMode, BaseFoldMode);
  31643. (function() {
  31644. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  31645. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  31646. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  31647. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  31648. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  31649. this._getFoldWidgetBase = this.getFoldWidget;
  31650. this.getFoldWidget = function(session, foldStyle, row) {
  31651. var line = session.getLine(row);
  31652. if (this.singleLineBlockCommentRe.test(line)) {
  31653. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  31654. return "";
  31655. }
  31656. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  31657. if (!fw && this.startRegionRe.test(line))
  31658. return "start"; // lineCommentRegionStart
  31659. return fw;
  31660. };
  31661. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  31662. var line = session.getLine(row);
  31663. if (this.startRegionRe.test(line))
  31664. return this.getCommentRegionBlock(session, line, row);
  31665. var match = line.match(this.foldingStartMarker);
  31666. if (match) {
  31667. var i = match.index;
  31668. if (match[1])
  31669. return this.openingBracketBlock(session, match[1], row, i);
  31670. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  31671. if (range && !range.isMultiLine()) {
  31672. if (forceMultiline) {
  31673. range = this.getSectionRange(session, row);
  31674. } else if (foldStyle != "all")
  31675. range = null;
  31676. }
  31677. return range;
  31678. }
  31679. if (foldStyle === "markbegin")
  31680. return;
  31681. var match = line.match(this.foldingStopMarker);
  31682. if (match) {
  31683. var i = match.index + match[0].length;
  31684. if (match[1])
  31685. return this.closingBracketBlock(session, match[1], row, i);
  31686. return session.getCommentFoldRange(row, i, -1);
  31687. }
  31688. };
  31689. this.getSectionRange = function(session, row) {
  31690. var line = session.getLine(row);
  31691. var startIndent = line.search(/\S/);
  31692. var startRow = row;
  31693. var startColumn = line.length;
  31694. row = row + 1;
  31695. var endRow = row;
  31696. var maxRow = session.getLength();
  31697. while (++row < maxRow) {
  31698. line = session.getLine(row);
  31699. var indent = line.search(/\S/);
  31700. if (indent === -1)
  31701. continue;
  31702. if (startIndent > indent)
  31703. break;
  31704. var subRange = this.getFoldWidgetRange(session, "all", row);
  31705. if (subRange) {
  31706. if (subRange.start.row <= startRow) {
  31707. break;
  31708. } else if (subRange.isMultiLine()) {
  31709. row = subRange.end.row;
  31710. } else if (startIndent == indent) {
  31711. break;
  31712. }
  31713. }
  31714. endRow = row;
  31715. }
  31716. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  31717. };
  31718. this.getCommentRegionBlock = function(session, line, row) {
  31719. var startColumn = line.search(/\s*$/);
  31720. var maxRow = session.getLength();
  31721. var startRow = row;
  31722. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  31723. var depth = 1;
  31724. while (++row < maxRow) {
  31725. line = session.getLine(row);
  31726. var m = re.exec(line);
  31727. if (!m) continue;
  31728. if (m[1]) depth--;
  31729. else depth++;
  31730. if (!depth) break;
  31731. }
  31732. var endRow = row;
  31733. if (endRow > startRow) {
  31734. return new Range(startRow, startColumn, endRow, line.length);
  31735. }
  31736. };
  31737. }).call(FoldMode.prototype);
  31738. });
  31739. ace.define("ace/mode/json",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/json_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/worker/worker_client"], function(acequire, exports, module) {
  31740. "use strict";
  31741. var oop = acequire("../lib/oop");
  31742. var TextMode = acequire("./text").Mode;
  31743. var HighlightRules = acequire("./json_highlight_rules").JsonHighlightRules;
  31744. var MatchingBraceOutdent = acequire("./matching_brace_outdent").MatchingBraceOutdent;
  31745. var CstyleBehaviour = acequire("./behaviour/cstyle").CstyleBehaviour;
  31746. var CStyleFoldMode = acequire("./folding/cstyle").FoldMode;
  31747. var WorkerClient = acequire("../worker/worker_client").WorkerClient;
  31748. var Mode = function() {
  31749. this.HighlightRules = HighlightRules;
  31750. this.$outdent = new MatchingBraceOutdent();
  31751. this.$behaviour = new CstyleBehaviour();
  31752. this.foldingRules = new CStyleFoldMode();
  31753. };
  31754. oop.inherits(Mode, TextMode);
  31755. (function() {
  31756. this.getNextLineIndent = function(state, line, tab) {
  31757. var indent = this.$getIndent(line);
  31758. if (state == "start") {
  31759. var match = line.match(/^.*[\{\(\[]\s*$/);
  31760. if (match) {
  31761. indent += tab;
  31762. }
  31763. }
  31764. return indent;
  31765. };
  31766. this.checkOutdent = function(state, line, input) {
  31767. return this.$outdent.checkOutdent(line, input);
  31768. };
  31769. this.autoOutdent = function(state, doc, row) {
  31770. this.$outdent.autoOutdent(doc, row);
  31771. };
  31772. this.createWorker = function(session) {
  31773. var worker = new WorkerClient(["ace"], __webpack_require__(68), "JsonWorker");
  31774. worker.attachToDocument(session.getDocument());
  31775. worker.on("annotate", function(e) {
  31776. session.setAnnotations(e.data);
  31777. });
  31778. worker.on("terminate", function() {
  31779. session.clearAnnotations();
  31780. });
  31781. return worker;
  31782. };
  31783. this.$id = "ace/mode/json";
  31784. }).call(Mode.prototype);
  31785. exports.Mode = Mode;
  31786. });
  31787. /***/ },
  31788. /* 68 */
  31789. /***/ function(module, exports) {
  31790. module.exports.id = 'ace/mode/json_worker';
  31791. module.exports.src = "\"no use strict\";(function(window){function resolveModuleId(id,paths){for(var testPath=id,tail=\"\";testPath;){var alias=paths[testPath];if(\"string\"==typeof alias)return alias+tail;if(alias)return alias.location.replace(/\\/*$/,\"/\")+(tail||alias.main||alias.name);if(alias===!1)return\"\";var i=testPath.lastIndexOf(\"/\");if(-1===i)break;tail=testPath.substr(i)+tail,testPath=testPath.slice(0,i)}return id}if(!(void 0!==window.window&&window.document||window.acequire&&window.define)){window.console||(window.console=function(){var msgs=Array.prototype.slice.call(arguments,0);postMessage({type:\"log\",data:msgs})},window.console.error=window.console.warn=window.console.log=window.console.trace=window.console),window.window=window,window.ace=window,window.onerror=function(message,file,line,col,err){postMessage({type:\"error\",data:{message:message,data:err.data,file:file,line:line,col:col,stack:err.stack}})},window.normalizeModule=function(parentId,moduleName){if(-1!==moduleName.indexOf(\"!\")){var chunks=moduleName.split(\"!\");return window.normalizeModule(parentId,chunks[0])+\"!\"+window.normalizeModule(parentId,chunks[1])}if(\".\"==moduleName.charAt(0)){var base=parentId.split(\"/\").slice(0,-1).join(\"/\");for(moduleName=(base?base+\"/\":\"\")+moduleName;-1!==moduleName.indexOf(\".\")&&previous!=moduleName;){var previous=moduleName;moduleName=moduleName.replace(/^\\.\\//,\"\").replace(/\\/\\.\\//,\"/\").replace(/[^\\/]+\\/\\.\\.\\//,\"\")}}return moduleName},window.acequire=function acequire(parentId,id){if(id||(id=parentId,parentId=null),!id.charAt)throw Error(\"worker.js acequire() accepts only (parentId, id) as arguments\");id=window.normalizeModule(parentId,id);var module=window.acequire.modules[id];if(module)return module.initialized||(module.initialized=!0,module.exports=module.factory().exports),module.exports;if(!window.acequire.tlns)return console.log(\"unable to load \"+id);var path=resolveModuleId(id,window.acequire.tlns);return\".js\"!=path.slice(-3)&&(path+=\".js\"),window.acequire.id=id,window.acequire.modules[id]={},importScripts(path),window.acequire(parentId,id)},window.acequire.modules={},window.acequire.tlns={},window.define=function(id,deps,factory){if(2==arguments.length?(factory=deps,\"string\"!=typeof id&&(deps=id,id=window.acequire.id)):1==arguments.length&&(factory=id,deps=[],id=window.acequire.id),\"function\"!=typeof factory)return window.acequire.modules[id]={exports:factory,initialized:!0},void 0;deps.length||(deps=[\"require\",\"exports\",\"module\"]);var req=function(childId){return window.acequire(id,childId)};window.acequire.modules[id]={exports:{},factory:function(){var module=this,returnExports=factory.apply(this,deps.map(function(dep){switch(dep){case\"require\":return req;case\"exports\":return module.exports;case\"module\":return module;default:return req(dep)}}));return returnExports&&(module.exports=returnExports),module}}},window.define.amd={},acequire.tlns={},window.initBaseUrls=function(topLevelNamespaces){for(var i in topLevelNamespaces)acequire.tlns[i]=topLevelNamespaces[i]},window.initSender=function(){var EventEmitter=window.acequire(\"ace/lib/event_emitter\").EventEmitter,oop=window.acequire(\"ace/lib/oop\"),Sender=function(){};return function(){oop.implement(this,EventEmitter),this.callback=function(data,callbackId){postMessage({type:\"call\",id:callbackId,data:data})},this.emit=function(name,data){postMessage({type:\"event\",name:name,data:data})}}.call(Sender.prototype),new Sender};var main=window.main=null,sender=window.sender=null;window.onmessage=function(e){var msg=e.data;if(msg.event&&sender)sender._signal(msg.event,msg.data);else if(msg.command)if(main[msg.command])main[msg.command].apply(main,msg.args);else{if(!window[msg.command])throw Error(\"Unknown command:\"+msg.command);window[msg.command].apply(window,msg.args)}else if(msg.init){window.initBaseUrls(msg.tlns),acequire(\"ace/lib/es5-shim\"),sender=window.sender=window.initSender();var clazz=acequire(msg.module)[msg.classname];main=window.main=new clazz(sender)}}}})(this),ace.define(\"ace/lib/oop\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";exports.inherits=function(ctor,superCtor){ctor.super_=superCtor,ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:!1,writable:!0,configurable:!0}})},exports.mixin=function(obj,mixin){for(var key in mixin)obj[key]=mixin[key];return obj},exports.implement=function(proto,mixin){exports.mixin(proto,mixin)}}),ace.define(\"ace/range\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";var comparePoints=function(p1,p2){return p1.row-p2.row||p1.column-p2.column},Range=function(startRow,startColumn,endRow,endColumn){this.start={row:startRow,column:startColumn},this.end={row:endRow,column:endColumn}};(function(){this.isEqual=function(range){return this.start.row===range.start.row&&this.end.row===range.end.row&&this.start.column===range.start.column&&this.end.column===range.end.column},this.toString=function(){return\"Range: [\"+this.start.row+\"/\"+this.start.column+\"] -> [\"+this.end.row+\"/\"+this.end.column+\"]\"},this.contains=function(row,column){return 0==this.compare(row,column)},this.compareRange=function(range){var cmp,end=range.end,start=range.start;return cmp=this.compare(end.row,end.column),1==cmp?(cmp=this.compare(start.row,start.column),1==cmp?2:0==cmp?1:0):-1==cmp?-2:(cmp=this.compare(start.row,start.column),-1==cmp?-1:1==cmp?42:0)},this.comparePoint=function(p){return this.compare(p.row,p.column)},this.containsRange=function(range){return 0==this.comparePoint(range.start)&&0==this.comparePoint(range.end)},this.intersects=function(range){var cmp=this.compareRange(range);return-1==cmp||0==cmp||1==cmp},this.isEnd=function(row,column){return this.end.row==row&&this.end.column==column},this.isStart=function(row,column){return this.start.row==row&&this.start.column==column},this.setStart=function(row,column){\"object\"==typeof row?(this.start.column=row.column,this.start.row=row.row):(this.start.row=row,this.start.column=column)},this.setEnd=function(row,column){\"object\"==typeof row?(this.end.column=row.column,this.end.row=row.row):(this.end.row=row,this.end.column=column)},this.inside=function(row,column){return 0==this.compare(row,column)?this.isEnd(row,column)||this.isStart(row,column)?!1:!0:!1},this.insideStart=function(row,column){return 0==this.compare(row,column)?this.isEnd(row,column)?!1:!0:!1},this.insideEnd=function(row,column){return 0==this.compare(row,column)?this.isStart(row,column)?!1:!0:!1},this.compare=function(row,column){return this.isMultiLine()||row!==this.start.row?this.start.row>row?-1:row>this.end.row?1:this.start.row===row?column>=this.start.column?0:-1:this.end.row===row?this.end.column>=column?0:1:0:this.start.column>column?-1:column>this.end.column?1:0},this.compareStart=function(row,column){return this.start.row==row&&this.start.column==column?-1:this.compare(row,column)},this.compareEnd=function(row,column){return this.end.row==row&&this.end.column==column?1:this.compare(row,column)},this.compareInside=function(row,column){return this.end.row==row&&this.end.column==column?1:this.start.row==row&&this.start.column==column?-1:this.compare(row,column)},this.clipRows=function(firstRow,lastRow){if(this.end.row>lastRow)var end={row:lastRow+1,column:0};else if(firstRow>this.end.row)var end={row:firstRow,column:0};if(this.start.row>lastRow)var start={row:lastRow+1,column:0};else if(firstRow>this.start.row)var start={row:firstRow,column:0};return Range.fromPoints(start||this.start,end||this.end)},this.extend=function(row,column){var cmp=this.compare(row,column);if(0==cmp)return this;if(-1==cmp)var start={row:row,column:column};else var end={row:row,column:column};return Range.fromPoints(start||this.start,end||this.end)},this.isEmpty=function(){return this.start.row===this.end.row&&this.start.column===this.end.column},this.isMultiLine=function(){return this.start.row!==this.end.row},this.clone=function(){return Range.fromPoints(this.start,this.end)},this.collapseRows=function(){return 0==this.end.column?new Range(this.start.row,0,Math.max(this.start.row,this.end.row-1),0):new Range(this.start.row,0,this.end.row,0)},this.toScreenRange=function(session){var screenPosStart=session.documentToScreenPosition(this.start),screenPosEnd=session.documentToScreenPosition(this.end);return new Range(screenPosStart.row,screenPosStart.column,screenPosEnd.row,screenPosEnd.column)},this.moveBy=function(row,column){this.start.row+=row,this.start.column+=column,this.end.row+=row,this.end.column+=column}}).call(Range.prototype),Range.fromPoints=function(start,end){return new Range(start.row,start.column,end.row,end.column)},Range.comparePoints=comparePoints,Range.comparePoints=function(p1,p2){return p1.row-p2.row||p1.column-p2.column},exports.Range=Range}),ace.define(\"ace/apply_delta\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";exports.applyDelta=function(docLines,delta){var row=delta.start.row,startColumn=delta.start.column,line=docLines[row]||\"\";switch(delta.action){case\"insert\":var lines=delta.lines;if(1===lines.length)docLines[row]=line.substring(0,startColumn)+delta.lines[0]+line.substring(startColumn);else{var args=[row,1].concat(delta.lines);docLines.splice.apply(docLines,args),docLines[row]=line.substring(0,startColumn)+docLines[row],docLines[row+delta.lines.length-1]+=line.substring(startColumn)}break;case\"remove\":var endColumn=delta.end.column,endRow=delta.end.row;row===endRow?docLines[row]=line.substring(0,startColumn)+line.substring(endColumn):docLines.splice(row,endRow-row+1,line.substring(0,startColumn)+docLines[endRow].substring(endColumn))}}}),ace.define(\"ace/lib/event_emitter\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";var EventEmitter={},stopPropagation=function(){this.propagationStopped=!0},preventDefault=function(){this.defaultPrevented=!0};EventEmitter._emit=EventEmitter._dispatchEvent=function(eventName,e){this._eventRegistry||(this._eventRegistry={}),this._defaultHandlers||(this._defaultHandlers={});var listeners=this._eventRegistry[eventName]||[],defaultHandler=this._defaultHandlers[eventName];if(listeners.length||defaultHandler){\"object\"==typeof e&&e||(e={}),e.type||(e.type=eventName),e.stopPropagation||(e.stopPropagation=stopPropagation),e.preventDefault||(e.preventDefault=preventDefault),listeners=listeners.slice();for(var i=0;listeners.length>i&&(listeners[i](e,this),!e.propagationStopped);i++);return defaultHandler&&!e.defaultPrevented?defaultHandler(e,this):void 0}},EventEmitter._signal=function(eventName,e){var listeners=(this._eventRegistry||{})[eventName];if(listeners){listeners=listeners.slice();for(var i=0;listeners.length>i;i++)listeners[i](e,this)}},EventEmitter.once=function(eventName,callback){var _self=this;callback&&this.addEventListener(eventName,function newCallback(){_self.removeEventListener(eventName,newCallback),callback.apply(null,arguments)})},EventEmitter.setDefaultHandler=function(eventName,callback){var handlers=this._defaultHandlers;if(handlers||(handlers=this._defaultHandlers={_disabled_:{}}),handlers[eventName]){var old=handlers[eventName],disabled=handlers._disabled_[eventName];disabled||(handlers._disabled_[eventName]=disabled=[]),disabled.push(old);var i=disabled.indexOf(callback);-1!=i&&disabled.splice(i,1)}handlers[eventName]=callback},EventEmitter.removeDefaultHandler=function(eventName,callback){var handlers=this._defaultHandlers;if(handlers){var disabled=handlers._disabled_[eventName];if(handlers[eventName]==callback)handlers[eventName],disabled&&this.setDefaultHandler(eventName,disabled.pop());else if(disabled){var i=disabled.indexOf(callback);-1!=i&&disabled.splice(i,1)}}},EventEmitter.on=EventEmitter.addEventListener=function(eventName,callback,capturing){this._eventRegistry=this._eventRegistry||{};var listeners=this._eventRegistry[eventName];return listeners||(listeners=this._eventRegistry[eventName]=[]),-1==listeners.indexOf(callback)&&listeners[capturing?\"unshift\":\"push\"](callback),callback},EventEmitter.off=EventEmitter.removeListener=EventEmitter.removeEventListener=function(eventName,callback){this._eventRegistry=this._eventRegistry||{};var listeners=this._eventRegistry[eventName];if(listeners){var index=listeners.indexOf(callback);-1!==index&&listeners.splice(index,1)}},EventEmitter.removeAllListeners=function(eventName){this._eventRegistry&&(this._eventRegistry[eventName]=[])},exports.EventEmitter=EventEmitter}),ace.define(\"ace/anchor\",[\"require\",\"exports\",\"module\",\"ace/lib/oop\",\"ace/lib/event_emitter\"],function(acequire,exports){\"use strict\";var oop=acequire(\"./lib/oop\"),EventEmitter=acequire(\"./lib/event_emitter\").EventEmitter,Anchor=exports.Anchor=function(doc,row,column){this.$onChange=this.onChange.bind(this),this.attach(doc),column===void 0?this.setPosition(row.row,row.column):this.setPosition(row,column)};(function(){function $pointsInOrder(point1,point2,equalPointsInOrder){var bColIsAfter=equalPointsInOrder?point1.column<=point2.column:point1.column<point2.column;return point1.row<point2.row||point1.row==point2.row&&bColIsAfter}function $getTransformedPoint(delta,point,moveIfEqual){var deltaIsInsert=\"insert\"==delta.action,deltaRowShift=(deltaIsInsert?1:-1)*(delta.end.row-delta.start.row),deltaColShift=(deltaIsInsert?1:-1)*(delta.end.column-delta.start.column),deltaStart=delta.start,deltaEnd=deltaIsInsert?deltaStart:delta.end;return $pointsInOrder(point,deltaStart,moveIfEqual)?{row:point.row,column:point.column}:$pointsInOrder(deltaEnd,point,!moveIfEqual)?{row:point.row+deltaRowShift,column:point.column+(point.row==deltaEnd.row?deltaColShift:0)}:{row:deltaStart.row,column:deltaStart.column}}oop.implement(this,EventEmitter),this.getPosition=function(){return this.$clipPositionToDocument(this.row,this.column)},this.getDocument=function(){return this.document},this.$insertRight=!1,this.onChange=function(delta){if(!(delta.start.row==delta.end.row&&delta.start.row!=this.row||delta.start.row>this.row)){var point=$getTransformedPoint(delta,{row:this.row,column:this.column},this.$insertRight);this.setPosition(point.row,point.column,!0)}},this.setPosition=function(row,column,noClip){var pos;if(pos=noClip?{row:row,column:column}:this.$clipPositionToDocument(row,column),this.row!=pos.row||this.column!=pos.column){var old={row:this.row,column:this.column};this.row=pos.row,this.column=pos.column,this._signal(\"change\",{old:old,value:pos})}},this.detach=function(){this.document.removeEventListener(\"change\",this.$onChange)},this.attach=function(doc){this.document=doc||this.document,this.document.on(\"change\",this.$onChange)},this.$clipPositionToDocument=function(row,column){var pos={};return row>=this.document.getLength()?(pos.row=Math.max(0,this.document.getLength()-1),pos.column=this.document.getLine(pos.row).length):0>row?(pos.row=0,pos.column=0):(pos.row=row,pos.column=Math.min(this.document.getLine(pos.row).length,Math.max(0,column))),0>column&&(pos.column=0),pos}}).call(Anchor.prototype)}),ace.define(\"ace/document\",[\"require\",\"exports\",\"module\",\"ace/lib/oop\",\"ace/apply_delta\",\"ace/lib/event_emitter\",\"ace/range\",\"ace/anchor\"],function(acequire,exports){\"use strict\";var oop=acequire(\"./lib/oop\"),applyDelta=acequire(\"./apply_delta\").applyDelta,EventEmitter=acequire(\"./lib/event_emitter\").EventEmitter,Range=acequire(\"./range\").Range,Anchor=acequire(\"./anchor\").Anchor,Document=function(textOrLines){this.$lines=[\"\"],0===textOrLines.length?this.$lines=[\"\"]:Array.isArray(textOrLines)?this.insertMergedLines({row:0,column:0},textOrLines):this.insert({row:0,column:0},textOrLines)};(function(){oop.implement(this,EventEmitter),this.setValue=function(text){var len=this.getLength()-1;this.remove(new Range(0,0,len,this.getLine(len).length)),this.insert({row:0,column:0},text)},this.getValue=function(){return this.getAllLines().join(this.getNewLineCharacter())},this.createAnchor=function(row,column){return new Anchor(this,row,column)},this.$split=0===\"aaa\".split(/a/).length?function(text){return text.replace(/\\r\\n|\\r/g,\"\\n\").split(\"\\n\")}:function(text){return text.split(/\\r\\n|\\r|\\n/)},this.$detectNewLine=function(text){var match=text.match(/^.*?(\\r\\n|\\r|\\n)/m);this.$autoNewLine=match?match[1]:\"\\n\",this._signal(\"changeNewLineMode\")},this.getNewLineCharacter=function(){switch(this.$newLineMode){case\"windows\":return\"\\r\\n\";case\"unix\":return\"\\n\";default:return this.$autoNewLine||\"\\n\"}},this.$autoNewLine=\"\",this.$newLineMode=\"auto\",this.setNewLineMode=function(newLineMode){this.$newLineMode!==newLineMode&&(this.$newLineMode=newLineMode,this._signal(\"changeNewLineMode\"))},this.getNewLineMode=function(){return this.$newLineMode},this.isNewLine=function(text){return\"\\r\\n\"==text||\"\\r\"==text||\"\\n\"==text},this.getLine=function(row){return this.$lines[row]||\"\"},this.getLines=function(firstRow,lastRow){return this.$lines.slice(firstRow,lastRow+1)},this.getAllLines=function(){return this.getLines(0,this.getLength())},this.getLength=function(){return this.$lines.length},this.getTextRange=function(range){return this.getLinesForRange(range).join(this.getNewLineCharacter())},this.getLinesForRange=function(range){var lines;if(range.start.row===range.end.row)lines=[this.getLine(range.start.row).substring(range.start.column,range.end.column)];else{lines=this.getLines(range.start.row,range.end.row),lines[0]=(lines[0]||\"\").substring(range.start.column);var l=lines.length-1;range.end.row-range.start.row==l&&(lines[l]=lines[l].substring(0,range.end.column))}return lines},this.insertLines=function(row,lines){return console.warn(\"Use of document.insertLines is deprecated. Use the insertFullLines method instead.\"),this.insertFullLines(row,lines)},this.removeLines=function(firstRow,lastRow){return console.warn(\"Use of document.removeLines is deprecated. Use the removeFullLines method instead.\"),this.removeFullLines(firstRow,lastRow)},this.insertNewLine=function(position){return console.warn(\"Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.\"),this.insertMergedLines(position,[\"\",\"\"])},this.insert=function(position,text){return 1>=this.getLength()&&this.$detectNewLine(text),this.insertMergedLines(position,this.$split(text))},this.insertInLine=function(position,text){var start=this.clippedPos(position.row,position.column),end=this.pos(position.row,position.column+text.length);return this.applyDelta({start:start,end:end,action:\"insert\",lines:[text]},!0),this.clonePos(end)},this.clippedPos=function(row,column){var length=this.getLength();void 0===row?row=length:0>row?row=0:row>=length&&(row=length-1,column=void 0);var line=this.getLine(row);return void 0==column&&(column=line.length),column=Math.min(Math.max(column,0),line.length),{row:row,column:column}},this.clonePos=function(pos){return{row:pos.row,column:pos.column}},this.pos=function(row,column){return{row:row,column:column}},this.$clipPosition=function(position){var length=this.getLength();return position.row>=length?(position.row=Math.max(0,length-1),position.column=this.getLine(length-1).length):(position.row=Math.max(0,position.row),position.column=Math.min(Math.max(position.column,0),this.getLine(position.row).length)),position},this.insertFullLines=function(row,lines){row=Math.min(Math.max(row,0),this.getLength());var column=0;this.getLength()>row?(lines=lines.concat([\"\"]),column=0):(lines=[\"\"].concat(lines),row--,column=this.$lines[row].length),this.insertMergedLines({row:row,column:column},lines)},this.insertMergedLines=function(position,lines){var start=this.clippedPos(position.row,position.column),end={row:start.row+lines.length-1,column:(1==lines.length?start.column:0)+lines[lines.length-1].length};return this.applyDelta({start:start,end:end,action:\"insert\",lines:lines}),this.clonePos(end)},this.remove=function(range){var start=this.clippedPos(range.start.row,range.start.column),end=this.clippedPos(range.end.row,range.end.column);return this.applyDelta({start:start,end:end,action:\"remove\",lines:this.getLinesForRange({start:start,end:end})}),this.clonePos(start)},this.removeInLine=function(row,startColumn,endColumn){var start=this.clippedPos(row,startColumn),end=this.clippedPos(row,endColumn);return this.applyDelta({start:start,end:end,action:\"remove\",lines:this.getLinesForRange({start:start,end:end})},!0),this.clonePos(start)},this.removeFullLines=function(firstRow,lastRow){firstRow=Math.min(Math.max(0,firstRow),this.getLength()-1),lastRow=Math.min(Math.max(0,lastRow),this.getLength()-1);var deleteFirstNewLine=lastRow==this.getLength()-1&&firstRow>0,deleteLastNewLine=this.getLength()-1>lastRow,startRow=deleteFirstNewLine?firstRow-1:firstRow,startCol=deleteFirstNewLine?this.getLine(startRow).length:0,endRow=deleteLastNewLine?lastRow+1:lastRow,endCol=deleteLastNewLine?0:this.getLine(endRow).length,range=new Range(startRow,startCol,endRow,endCol),deletedLines=this.$lines.slice(firstRow,lastRow+1);return this.applyDelta({start:range.start,end:range.end,action:\"remove\",lines:this.getLinesForRange(range)}),deletedLines},this.removeNewLine=function(row){this.getLength()-1>row&&row>=0&&this.applyDelta({start:this.pos(row,this.getLine(row).length),end:this.pos(row+1,0),action:\"remove\",lines:[\"\",\"\"]})},this.replace=function(range,text){if(range instanceof Range||(range=Range.fromPoints(range.start,range.end)),0===text.length&&range.isEmpty())return range.start;if(text==this.getTextRange(range))return range.end;this.remove(range);var end;return end=text?this.insert(range.start,text):range.start},this.applyDeltas=function(deltas){for(var i=0;deltas.length>i;i++)this.applyDelta(deltas[i])},this.revertDeltas=function(deltas){for(var i=deltas.length-1;i>=0;i--)this.revertDelta(deltas[i])},this.applyDelta=function(delta,doNotValidate){var isInsert=\"insert\"==delta.action;(isInsert?1>=delta.lines.length&&!delta.lines[0]:!Range.comparePoints(delta.start,delta.end))||(isInsert&&delta.lines.length>2e4&&this.$splitAndapplyLargeDelta(delta,2e4),applyDelta(this.$lines,delta,doNotValidate),this._signal(\"change\",delta))},this.$splitAndapplyLargeDelta=function(delta,MAX){for(var lines=delta.lines,l=lines.length,row=delta.start.row,column=delta.start.column,from=0,to=0;;){from=to,to+=MAX-1;var chunk=lines.slice(from,to);if(to>l){delta.lines=chunk,delta.start.row=row+from,delta.start.column=column;break}chunk.push(\"\"),this.applyDelta({start:this.pos(row+from,column),end:this.pos(row+to,column=0),action:delta.action,lines:chunk},!0)}},this.revertDelta=function(delta){this.applyDelta({start:this.clonePos(delta.start),end:this.clonePos(delta.end),action:\"insert\"==delta.action?\"remove\":\"insert\",lines:delta.lines.slice()})},this.indexToPosition=function(index,startRow){for(var lines=this.$lines||this.getAllLines(),newlineLength=this.getNewLineCharacter().length,i=startRow||0,l=lines.length;l>i;i++)if(index-=lines[i].length+newlineLength,0>index)return{row:i,column:index+lines[i].length+newlineLength};return{row:l-1,column:lines[l-1].length}},this.positionToIndex=function(pos,startRow){for(var lines=this.$lines||this.getAllLines(),newlineLength=this.getNewLineCharacter().length,index=0,row=Math.min(pos.row,lines.length),i=startRow||0;row>i;++i)index+=lines[i].length+newlineLength;return index+pos.column}}).call(Document.prototype),exports.Document=Document}),ace.define(\"ace/lib/lang\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";exports.last=function(a){return a[a.length-1]},exports.stringReverse=function(string){return string.split(\"\").reverse().join(\"\")},exports.stringRepeat=function(string,count){for(var result=\"\";count>0;)1&count&&(result+=string),(count>>=1)&&(string+=string);return result};var trimBeginRegexp=/^\\s\\s*/,trimEndRegexp=/\\s\\s*$/;exports.stringTrimLeft=function(string){return string.replace(trimBeginRegexp,\"\")},exports.stringTrimRight=function(string){return string.replace(trimEndRegexp,\"\")},exports.copyObject=function(obj){var copy={};for(var key in obj)copy[key]=obj[key];return copy},exports.copyArray=function(array){for(var copy=[],i=0,l=array.length;l>i;i++)copy[i]=array[i]&&\"object\"==typeof array[i]?this.copyObject(array[i]):array[i];return copy},exports.deepCopy=function deepCopy(obj){if(\"object\"!=typeof obj||!obj)return obj;var copy;if(Array.isArray(obj)){copy=[];for(var key=0;obj.length>key;key++)copy[key]=deepCopy(obj[key]);return copy}var cons=obj.constructor;if(cons===RegExp)return obj;copy=cons();for(var key in obj)copy[key]=deepCopy(obj[key]);return copy},exports.arrayToMap=function(arr){for(var map={},i=0;arr.length>i;i++)map[arr[i]]=1;return map},exports.createMap=function(props){var map=Object.create(null);for(var i in props)map[i]=props[i];return map},exports.arrayRemove=function(array,value){for(var i=0;array.length>=i;i++)value===array[i]&&array.splice(i,1)},exports.escapeRegExp=function(str){return str.replace(/([.*+?^${}()|[\\]\\/\\\\])/g,\"\\\\$1\")},exports.escapeHTML=function(str){return str.replace(/&/g,\"&#38;\").replace(/\"/g,\"&#34;\").replace(/'/g,\"&#39;\").replace(/</g,\"&#60;\")},exports.getMatchOffsets=function(string,regExp){var matches=[];return string.replace(regExp,function(str){matches.push({offset:arguments[arguments.length-2],length:str.length})}),matches},exports.deferredCall=function(fcn){var timer=null,callback=function(){timer=null,fcn()},deferred=function(timeout){return deferred.cancel(),timer=setTimeout(callback,timeout||0),deferred};return deferred.schedule=deferred,deferred.call=function(){return this.cancel(),fcn(),deferred},deferred.cancel=function(){return clearTimeout(timer),timer=null,deferred},deferred.isPending=function(){return timer},deferred},exports.delayedCall=function(fcn,defaultTimeout){var timer=null,callback=function(){timer=null,fcn()},_self=function(timeout){null==timer&&(timer=setTimeout(callback,timeout||defaultTimeout))};return _self.delay=function(timeout){timer&&clearTimeout(timer),timer=setTimeout(callback,timeout||defaultTimeout)},_self.schedule=_self,_self.call=function(){this.cancel(),fcn()},_self.cancel=function(){timer&&clearTimeout(timer),timer=null},_self.isPending=function(){return timer},_self}}),ace.define(\"ace/worker/mirror\",[\"require\",\"exports\",\"module\",\"ace/range\",\"ace/document\",\"ace/lib/lang\"],function(acequire,exports){\"use strict\";acequire(\"../range\").Range;var Document=acequire(\"../document\").Document,lang=acequire(\"../lib/lang\"),Mirror=exports.Mirror=function(sender){this.sender=sender;var doc=this.doc=new Document(\"\"),deferredUpdate=this.deferredUpdate=lang.delayedCall(this.onUpdate.bind(this)),_self=this;sender.on(\"change\",function(e){var data=e.data;if(data[0].start)doc.applyDeltas(data);else for(var i=0;data.length>i;i+=2){if(Array.isArray(data[i+1]))var d={action:\"insert\",start:data[i],lines:data[i+1]};else var d={action:\"remove\",start:data[i],end:data[i+1]};doc.applyDelta(d,!0)}return _self.$timeout?deferredUpdate.schedule(_self.$timeout):(_self.onUpdate(),void 0)})};(function(){this.$timeout=500,this.setTimeout=function(timeout){this.$timeout=timeout},this.setValue=function(value){this.doc.setValue(value),this.deferredUpdate.schedule(this.$timeout)},this.getValue=function(callbackId){this.sender.callback(this.doc.getValue(),callbackId)},this.onUpdate=function(){},this.isPending=function(){return this.deferredUpdate.isPending()}}).call(Mirror.prototype)}),ace.define(\"ace/mode/json/json_parse\",[\"require\",\"exports\",\"module\"],function(){\"use strict\";var at,ch,text,value,escapee={'\"':'\"',\"\\\\\":\"\\\\\",\"/\":\"/\",b:\"\\b\",f:\"\\f\",n:\"\\n\",r:\"\\r\",t:\"\t\"},error=function(m){throw{name:\"SyntaxError\",message:m,at:at,text:text}},next=function(c){return c&&c!==ch&&error(\"Expected '\"+c+\"' instead of '\"+ch+\"'\"),ch=text.charAt(at),at+=1,ch},number=function(){var number,string=\"\";for(\"-\"===ch&&(string=\"-\",next(\"-\"));ch>=\"0\"&&\"9\">=ch;)string+=ch,next();if(\".\"===ch)for(string+=\".\";next()&&ch>=\"0\"&&\"9\">=ch;)string+=ch;if(\"e\"===ch||\"E\"===ch)for(string+=ch,next(),(\"-\"===ch||\"+\"===ch)&&(string+=ch,next());ch>=\"0\"&&\"9\">=ch;)string+=ch,next();return number=+string,isNaN(number)?(error(\"Bad number\"),void 0):number},string=function(){var hex,i,uffff,string=\"\";if('\"'===ch)for(;next();){if('\"'===ch)return next(),string;if(\"\\\\\"===ch)if(next(),\"u\"===ch){for(uffff=0,i=0;4>i&&(hex=parseInt(next(),16),isFinite(hex));i+=1)uffff=16*uffff+hex;string+=String.fromCharCode(uffff)}else{if(\"string\"!=typeof escapee[ch])break;string+=escapee[ch]}else string+=ch}error(\"Bad string\")},white=function(){for(;ch&&\" \">=ch;)next()},word=function(){switch(ch){case\"t\":return next(\"t\"),next(\"r\"),next(\"u\"),next(\"e\"),!0;case\"f\":return next(\"f\"),next(\"a\"),next(\"l\"),next(\"s\"),next(\"e\"),!1;case\"n\":return next(\"n\"),next(\"u\"),next(\"l\"),next(\"l\"),null}error(\"Unexpected '\"+ch+\"'\")},array=function(){var array=[];if(\"[\"===ch){if(next(\"[\"),white(),\"]\"===ch)return next(\"]\"),array;for(;ch;){if(array.push(value()),white(),\"]\"===ch)return next(\"]\"),array;next(\",\"),white()}}error(\"Bad array\")},object=function(){var key,object={};if(\"{\"===ch){if(next(\"{\"),white(),\"}\"===ch)return next(\"}\"),object;for(;ch;){if(key=string(),white(),next(\":\"),Object.hasOwnProperty.call(object,key)&&error('Duplicate key \"'+key+'\"'),object[key]=value(),white(),\"}\"===ch)return next(\"}\"),object;next(\",\"),white()}}error(\"Bad object\")};return value=function(){switch(white(),ch){case\"{\":return object();case\"[\":return array();case'\"':return string();case\"-\":return number();default:return ch>=\"0\"&&\"9\">=ch?number():word()}},function(source,reviver){var result;return text=source,at=0,ch=\" \",result=value(),white(),ch&&error(\"Syntax error\"),\"function\"==typeof reviver?function walk(holder,key){var k,v,value=holder[key];if(value&&\"object\"==typeof value)for(k in value)Object.hasOwnProperty.call(value,k)&&(v=walk(value,k),void 0!==v?value[k]=v:delete value[k]);return reviver.call(holder,key,value)}({\"\":result},\"\"):result}}),ace.define(\"ace/mode/json_worker\",[\"require\",\"exports\",\"module\",\"ace/lib/oop\",\"ace/worker/mirror\",\"ace/mode/json/json_parse\"],function(acequire,exports){\"use strict\";var oop=acequire(\"../lib/oop\"),Mirror=acequire(\"../worker/mirror\").Mirror,parse=acequire(\"./json/json_parse\"),JsonWorker=exports.JsonWorker=function(sender){Mirror.call(this,sender),this.setTimeout(200)};oop.inherits(JsonWorker,Mirror),function(){this.onUpdate=function(){var value=this.doc.getValue(),errors=[];try{value&&parse(value)}catch(e){var pos=this.doc.indexToPosition(e.at-1);errors.push({row:pos.row,column:pos.column,text:e.message,type:\"error\"})}this.sender.emit(\"annotate\",errors)}}.call(JsonWorker.prototype)}),ace.define(\"ace/lib/es5-shim\",[\"require\",\"exports\",\"module\"],function(){function Empty(){}function doesDefinePropertyWork(object){try{return Object.defineProperty(object,\"sentinel\",{}),\"sentinel\"in object}catch(exception){}}function toInteger(n){return n=+n,n!==n?n=0:0!==n&&n!==1/0&&n!==-(1/0)&&(n=(n>0||-1)*Math.floor(Math.abs(n))),n}Function.prototype.bind||(Function.prototype.bind=function(that){var target=this;if(\"function\"!=typeof target)throw new TypeError(\"Function.prototype.bind called on incompatible \"+target);var args=slice.call(arguments,1),bound=function(){if(this instanceof bound){var result=target.apply(this,args.concat(slice.call(arguments)));return Object(result)===result?result:this}return target.apply(that,args.concat(slice.call(arguments)))};return target.prototype&&(Empty.prototype=target.prototype,bound.prototype=new Empty,Empty.prototype=null),bound});var defineGetter,defineSetter,lookupGetter,lookupSetter,supportsAccessors,call=Function.prototype.call,prototypeOfArray=Array.prototype,prototypeOfObject=Object.prototype,slice=prototypeOfArray.slice,_toString=call.bind(prototypeOfObject.toString),owns=call.bind(prototypeOfObject.hasOwnProperty);if((supportsAccessors=owns(prototypeOfObject,\"__defineGetter__\"))&&(defineGetter=call.bind(prototypeOfObject.__defineGetter__),defineSetter=call.bind(prototypeOfObject.__defineSetter__),lookupGetter=call.bind(prototypeOfObject.__lookupGetter__),lookupSetter=call.bind(prototypeOfObject.__lookupSetter__)),2!=[1,2].splice(0).length)if(function(){function makeArray(l){var a=Array(l+2);return a[0]=a[1]=0,a}var lengthBefore,array=[];return array.splice.apply(array,makeArray(20)),array.splice.apply(array,makeArray(26)),lengthBefore=array.length,array.splice(5,0,\"XXX\"),lengthBefore+1==array.length,lengthBefore+1==array.length?!0:void 0\n}()){var array_splice=Array.prototype.splice;Array.prototype.splice=function(start,deleteCount){return arguments.length?array_splice.apply(this,[void 0===start?0:start,void 0===deleteCount?this.length-start:deleteCount].concat(slice.call(arguments,2))):[]}}else Array.prototype.splice=function(pos,removeCount){var length=this.length;pos>0?pos>length&&(pos=length):void 0==pos?pos=0:0>pos&&(pos=Math.max(length+pos,0)),length>pos+removeCount||(removeCount=length-pos);var removed=this.slice(pos,pos+removeCount),insert=slice.call(arguments,2),add=insert.length;if(pos===length)add&&this.push.apply(this,insert);else{var remove=Math.min(removeCount,length-pos),tailOldPos=pos+remove,tailNewPos=tailOldPos+add-remove,tailCount=length-tailOldPos,lengthAfterRemove=length-remove;if(tailOldPos>tailNewPos)for(var i=0;tailCount>i;++i)this[tailNewPos+i]=this[tailOldPos+i];else if(tailNewPos>tailOldPos)for(i=tailCount;i--;)this[tailNewPos+i]=this[tailOldPos+i];if(add&&pos===lengthAfterRemove)this.length=lengthAfterRemove,this.push.apply(this,insert);else for(this.length=lengthAfterRemove+add,i=0;add>i;++i)this[pos+i]=insert[i]}return removed};Array.isArray||(Array.isArray=function(obj){return\"[object Array]\"==_toString(obj)});var boxedString=Object(\"a\"),splitString=\"a\"!=boxedString[0]||!(0 in boxedString);if(Array.prototype.forEach||(Array.prototype.forEach=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,thisp=arguments[1],i=-1,length=self.length>>>0;if(\"[object Function]\"!=_toString(fun))throw new TypeError;for(;length>++i;)i in self&&fun.call(thisp,self[i],i,object)}),Array.prototype.map||(Array.prototype.map=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,result=Array(length),thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)i in self&&(result[i]=fun.call(thisp,self[i],i,object));return result}),Array.prototype.filter||(Array.prototype.filter=function(fun){var value,object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,result=[],thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)i in self&&(value=self[i],fun.call(thisp,value,i,object)&&result.push(value));return result}),Array.prototype.every||(Array.prototype.every=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)if(i in self&&!fun.call(thisp,self[i],i,object))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)if(i in self&&fun.call(thisp,self[i],i,object))return!0;return!1}),Array.prototype.reduce||(Array.prototype.reduce=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0;if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");if(!length&&1==arguments.length)throw new TypeError(\"reduce of empty array with no initial value\");var result,i=0;if(arguments.length>=2)result=arguments[1];else for(;;){if(i in self){result=self[i++];break}if(++i>=length)throw new TypeError(\"reduce of empty array with no initial value\")}for(;length>i;i++)i in self&&(result=fun.call(void 0,result,self[i],i,object));return result}),Array.prototype.reduceRight||(Array.prototype.reduceRight=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0;if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");if(!length&&1==arguments.length)throw new TypeError(\"reduceRight of empty array with no initial value\");var result,i=length-1;if(arguments.length>=2)result=arguments[1];else for(;;){if(i in self){result=self[i--];break}if(0>--i)throw new TypeError(\"reduceRight of empty array with no initial value\")}do i in this&&(result=fun.call(void 0,result,self[i],i,object));while(i--);return result}),Array.prototype.indexOf&&-1==[0,1].indexOf(1,2)||(Array.prototype.indexOf=function(sought){var self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):toObject(this),length=self.length>>>0;if(!length)return-1;var i=0;for(arguments.length>1&&(i=toInteger(arguments[1])),i=i>=0?i:Math.max(0,length+i);length>i;i++)if(i in self&&self[i]===sought)return i;return-1}),Array.prototype.lastIndexOf&&-1==[0,1].lastIndexOf(0,-3)||(Array.prototype.lastIndexOf=function(sought){var self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):toObject(this),length=self.length>>>0;if(!length)return-1;var i=length-1;for(arguments.length>1&&(i=Math.min(i,toInteger(arguments[1]))),i=i>=0?i:length-Math.abs(i);i>=0;i--)if(i in self&&sought===self[i])return i;return-1}),Object.getPrototypeOf||(Object.getPrototypeOf=function(object){return object.__proto__||(object.constructor?object.constructor.prototype:prototypeOfObject)}),!Object.getOwnPropertyDescriptor){var ERR_NON_OBJECT=\"Object.getOwnPropertyDescriptor called on a non-object: \";Object.getOwnPropertyDescriptor=function(object,property){if(\"object\"!=typeof object&&\"function\"!=typeof object||null===object)throw new TypeError(ERR_NON_OBJECT+object);if(owns(object,property)){var descriptor,getter,setter;if(descriptor={enumerable:!0,configurable:!0},supportsAccessors){var prototype=object.__proto__;object.__proto__=prototypeOfObject;var getter=lookupGetter(object,property),setter=lookupSetter(object,property);if(object.__proto__=prototype,getter||setter)return getter&&(descriptor.get=getter),setter&&(descriptor.set=setter),descriptor}return descriptor.value=object[property],descriptor}}}if(Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(object){return Object.keys(object)}),!Object.create){var createEmpty;createEmpty=null===Object.prototype.__proto__?function(){return{__proto__:null}}:function(){var empty={};for(var i in empty)empty[i]=null;return empty.constructor=empty.hasOwnProperty=empty.propertyIsEnumerable=empty.isPrototypeOf=empty.toLocaleString=empty.toString=empty.valueOf=empty.__proto__=null,empty},Object.create=function(prototype,properties){var object;if(null===prototype)object=createEmpty();else{if(\"object\"!=typeof prototype)throw new TypeError(\"typeof prototype[\"+typeof prototype+\"] != 'object'\");var Type=function(){};Type.prototype=prototype,object=new Type,object.__proto__=prototype}return void 0!==properties&&Object.defineProperties(object,properties),object}}if(Object.defineProperty){var definePropertyWorksOnObject=doesDefinePropertyWork({}),definePropertyWorksOnDom=\"undefined\"==typeof document||doesDefinePropertyWork(document.createElement(\"div\"));if(!definePropertyWorksOnObject||!definePropertyWorksOnDom)var definePropertyFallback=Object.defineProperty}if(!Object.defineProperty||definePropertyFallback){var ERR_NON_OBJECT_DESCRIPTOR=\"Property description must be an object: \",ERR_NON_OBJECT_TARGET=\"Object.defineProperty called on non-object: \",ERR_ACCESSORS_NOT_SUPPORTED=\"getters & setters can not be defined on this javascript engine\";Object.defineProperty=function(object,property,descriptor){if(\"object\"!=typeof object&&\"function\"!=typeof object||null===object)throw new TypeError(ERR_NON_OBJECT_TARGET+object);if(\"object\"!=typeof descriptor&&\"function\"!=typeof descriptor||null===descriptor)throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR+descriptor);if(definePropertyFallback)try{return definePropertyFallback.call(Object,object,property,descriptor)}catch(exception){}if(owns(descriptor,\"value\"))if(supportsAccessors&&(lookupGetter(object,property)||lookupSetter(object,property))){var prototype=object.__proto__;object.__proto__=prototypeOfObject,delete object[property],object[property]=descriptor.value,object.__proto__=prototype}else object[property]=descriptor.value;else{if(!supportsAccessors)throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);owns(descriptor,\"get\")&&defineGetter(object,property,descriptor.get),owns(descriptor,\"set\")&&defineSetter(object,property,descriptor.set)}return object}}Object.defineProperties||(Object.defineProperties=function(object,properties){for(var property in properties)owns(properties,property)&&Object.defineProperty(object,property,properties[property]);return object}),Object.seal||(Object.seal=function(object){return object}),Object.freeze||(Object.freeze=function(object){return object});try{Object.freeze(function(){})}catch(exception){Object.freeze=function(freezeObject){return function(object){return\"function\"==typeof object?object:freezeObject(object)}}(Object.freeze)}if(Object.preventExtensions||(Object.preventExtensions=function(object){return object}),Object.isSealed||(Object.isSealed=function(){return!1}),Object.isFrozen||(Object.isFrozen=function(){return!1}),Object.isExtensible||(Object.isExtensible=function(object){if(Object(object)===object)throw new TypeError;for(var name=\"\";owns(object,name);)name+=\"?\";object[name]=!0;var returnValue=owns(object,name);return delete object[name],returnValue}),!Object.keys){var hasDontEnumBug=!0,dontEnums=[\"toString\",\"toLocaleString\",\"valueOf\",\"hasOwnProperty\",\"isPrototypeOf\",\"propertyIsEnumerable\",\"constructor\"],dontEnumsLength=dontEnums.length;for(var key in{toString:null})hasDontEnumBug=!1;Object.keys=function(object){if(\"object\"!=typeof object&&\"function\"!=typeof object||null===object)throw new TypeError(\"Object.keys called on a non-object\");var keys=[];for(var name in object)owns(object,name)&&keys.push(name);if(hasDontEnumBug)for(var i=0,ii=dontEnumsLength;ii>i;i++){var dontEnum=dontEnums[i];owns(object,dontEnum)&&keys.push(dontEnum)}return keys}}Date.now||(Date.now=function(){return(new Date).getTime()});var ws=\"\t\\n\u000b\\f\\r   ᠎              \\u2028\\u2029\";if(!String.prototype.trim||ws.trim()){ws=\"[\"+ws+\"]\";var trimBeginRegexp=RegExp(\"^\"+ws+ws+\"*\"),trimEndRegexp=RegExp(ws+ws+\"*$\");String.prototype.trim=function(){return(this+\"\").replace(trimBeginRegexp,\"\").replace(trimEndRegexp,\"\")}}var toObject=function(o){if(null==o)throw new TypeError(\"can't convert \"+o+\" to object\");return Object(o)}});";
  31792. /***/ },
  31793. /* 69 */
  31794. /***/ function(module, exports) {
  31795. ace.define("ace/ext/searchbox",["require","exports","module","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/keyboard/hash_handler","ace/lib/keys"], function(acequire, exports, module) {
  31796. "use strict";
  31797. var dom = acequire("../lib/dom");
  31798. var lang = acequire("../lib/lang");
  31799. var event = acequire("../lib/event");
  31800. var searchboxCss = "\
  31801. .ace_search {\
  31802. background-color: #ddd;\
  31803. border: 1px solid #cbcbcb;\
  31804. border-top: 0 none;\
  31805. max-width: 325px;\
  31806. overflow: hidden;\
  31807. margin: 0;\
  31808. padding: 4px;\
  31809. padding-right: 6px;\
  31810. padding-bottom: 0;\
  31811. position: absolute;\
  31812. top: 0px;\
  31813. z-index: 99;\
  31814. white-space: normal;\
  31815. }\
  31816. .ace_search.left {\
  31817. border-left: 0 none;\
  31818. border-radius: 0px 0px 5px 0px;\
  31819. left: 0;\
  31820. }\
  31821. .ace_search.right {\
  31822. border-radius: 0px 0px 0px 5px;\
  31823. border-right: 0 none;\
  31824. right: 0;\
  31825. }\
  31826. .ace_search_form, .ace_replace_form {\
  31827. border-radius: 3px;\
  31828. border: 1px solid #cbcbcb;\
  31829. float: left;\
  31830. margin-bottom: 4px;\
  31831. overflow: hidden;\
  31832. }\
  31833. .ace_search_form.ace_nomatch {\
  31834. outline: 1px solid red;\
  31835. }\
  31836. .ace_search_field {\
  31837. background-color: white;\
  31838. border-right: 1px solid #cbcbcb;\
  31839. border: 0 none;\
  31840. -webkit-box-sizing: border-box;\
  31841. -moz-box-sizing: border-box;\
  31842. box-sizing: border-box;\
  31843. float: left;\
  31844. height: 22px;\
  31845. outline: 0;\
  31846. padding: 0 7px;\
  31847. width: 214px;\
  31848. margin: 0;\
  31849. }\
  31850. .ace_searchbtn,\
  31851. .ace_replacebtn {\
  31852. background: #fff;\
  31853. border: 0 none;\
  31854. border-left: 1px solid #dcdcdc;\
  31855. cursor: pointer;\
  31856. float: left;\
  31857. height: 22px;\
  31858. margin: 0;\
  31859. position: relative;\
  31860. }\
  31861. .ace_searchbtn:last-child,\
  31862. .ace_replacebtn:last-child {\
  31863. border-top-right-radius: 3px;\
  31864. border-bottom-right-radius: 3px;\
  31865. }\
  31866. .ace_searchbtn:disabled {\
  31867. background: none;\
  31868. cursor: default;\
  31869. }\
  31870. .ace_searchbtn {\
  31871. background-position: 50% 50%;\
  31872. background-repeat: no-repeat;\
  31873. width: 27px;\
  31874. }\
  31875. .ace_searchbtn.prev {\
  31876. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAYAAAB4ka1VAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADFJREFUeNpiSU1NZUAC/6E0I0yACYskCpsJiySKIiY0SUZk40FyTEgCjGgKwTRAgAEAQJUIPCE+qfkAAAAASUVORK5CYII=); \
  31877. }\
  31878. .ace_searchbtn.next {\
  31879. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAYAAAB4ka1VAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADRJREFUeNpiTE1NZQCC/0DMyIAKwGJMUAYDEo3M/s+EpvM/mkKwCQxYjIeLMaELoLMBAgwAU7UJObTKsvAAAAAASUVORK5CYII=); \
  31880. }\
  31881. .ace_searchbtn_close {\
  31882. background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAcCAYAAABRVo5BAAAAZ0lEQVR42u2SUQrAMAhDvazn8OjZBilCkYVVxiis8H4CT0VrAJb4WHT3C5xU2a2IQZXJjiQIRMdkEoJ5Q2yMqpfDIo+XY4k6h+YXOyKqTIj5REaxloNAd0xiKmAtsTHqW8sR2W5f7gCu5nWFUpVjZwAAAABJRU5ErkJggg==) no-repeat 50% 0;\
  31883. border-radius: 50%;\
  31884. border: 0 none;\
  31885. color: #656565;\
  31886. cursor: pointer;\
  31887. float: right;\
  31888. font: 16px/16px Arial;\
  31889. height: 14px;\
  31890. margin: 5px 1px 9px 5px;\
  31891. padding: 0;\
  31892. text-align: center;\
  31893. width: 14px;\
  31894. }\
  31895. .ace_searchbtn_close:hover {\
  31896. background-color: #656565;\
  31897. background-position: 50% 100%;\
  31898. color: white;\
  31899. }\
  31900. .ace_replacebtn.prev {\
  31901. width: 54px\
  31902. }\
  31903. .ace_replacebtn.next {\
  31904. width: 27px\
  31905. }\
  31906. .ace_button {\
  31907. margin-left: 2px;\
  31908. cursor: pointer;\
  31909. -webkit-user-select: none;\
  31910. -moz-user-select: none;\
  31911. -o-user-select: none;\
  31912. -ms-user-select: none;\
  31913. user-select: none;\
  31914. overflow: hidden;\
  31915. opacity: 0.7;\
  31916. border: 1px solid rgba(100,100,100,0.23);\
  31917. padding: 1px;\
  31918. -moz-box-sizing: border-box;\
  31919. box-sizing: border-box;\
  31920. color: black;\
  31921. }\
  31922. .ace_button:hover {\
  31923. background-color: #eee;\
  31924. opacity:1;\
  31925. }\
  31926. .ace_button:active {\
  31927. background-color: #ddd;\
  31928. }\
  31929. .ace_button.checked {\
  31930. border-color: #3399ff;\
  31931. opacity:1;\
  31932. }\
  31933. .ace_search_options{\
  31934. margin-bottom: 3px;\
  31935. text-align: right;\
  31936. -webkit-user-select: none;\
  31937. -moz-user-select: none;\
  31938. -o-user-select: none;\
  31939. -ms-user-select: none;\
  31940. user-select: none;\
  31941. }";
  31942. var HashHandler = acequire("../keyboard/hash_handler").HashHandler;
  31943. var keyUtil = acequire("../lib/keys");
  31944. dom.importCssString(searchboxCss, "ace_searchbox");
  31945. var html = '<div class="ace_search right">\
  31946. <button type="button" action="hide" class="ace_searchbtn_close"></button>\
  31947. <div class="ace_search_form">\
  31948. <input class="ace_search_field" placeholder="Search for" spellcheck="false"></input>\
  31949. <button type="button" action="findNext" class="ace_searchbtn next"></button>\
  31950. <button type="button" action="findPrev" class="ace_searchbtn prev"></button>\
  31951. <button type="button" action="findAll" class="ace_searchbtn" title="Alt-Enter">All</button>\
  31952. </div>\
  31953. <div class="ace_replace_form">\
  31954. <input class="ace_search_field" placeholder="Replace with" spellcheck="false"></input>\
  31955. <button type="button" action="replaceAndFindNext" class="ace_replacebtn">Replace</button>\
  31956. <button type="button" action="replaceAll" class="ace_replacebtn">All</button>\
  31957. </div>\
  31958. <div class="ace_search_options">\
  31959. <span action="toggleRegexpMode" class="ace_button" title="RegExp Search">.*</span>\
  31960. <span action="toggleCaseSensitive" class="ace_button" title="CaseSensitive Search">Aa</span>\
  31961. <span action="toggleWholeWords" class="ace_button" title="Whole Word Search">\\b</span>\
  31962. </div>\
  31963. </div>'.replace(/>\s+/g, ">");
  31964. var SearchBox = function(editor, range, showReplaceForm) {
  31965. var div = dom.createElement("div");
  31966. div.innerHTML = html;
  31967. this.element = div.firstChild;
  31968. this.$init();
  31969. this.setEditor(editor);
  31970. };
  31971. (function() {
  31972. this.setEditor = function(editor) {
  31973. editor.searchBox = this;
  31974. editor.container.appendChild(this.element);
  31975. this.editor = editor;
  31976. };
  31977. this.$initElements = function(sb) {
  31978. this.searchBox = sb.querySelector(".ace_search_form");
  31979. this.replaceBox = sb.querySelector(".ace_replace_form");
  31980. this.searchOptions = sb.querySelector(".ace_search_options");
  31981. this.regExpOption = sb.querySelector("[action=toggleRegexpMode]");
  31982. this.caseSensitiveOption = sb.querySelector("[action=toggleCaseSensitive]");
  31983. this.wholeWordOption = sb.querySelector("[action=toggleWholeWords]");
  31984. this.searchInput = this.searchBox.querySelector(".ace_search_field");
  31985. this.replaceInput = this.replaceBox.querySelector(".ace_search_field");
  31986. };
  31987. this.$init = function() {
  31988. var sb = this.element;
  31989. this.$initElements(sb);
  31990. var _this = this;
  31991. event.addListener(sb, "mousedown", function(e) {
  31992. setTimeout(function(){
  31993. _this.activeInput.focus();
  31994. }, 0);
  31995. event.stopPropagation(e);
  31996. });
  31997. event.addListener(sb, "click", function(e) {
  31998. var t = e.target || e.srcElement;
  31999. var action = t.getAttribute("action");
  32000. if (action && _this[action])
  32001. _this[action]();
  32002. else if (_this.$searchBarKb.commands[action])
  32003. _this.$searchBarKb.commands[action].exec(_this);
  32004. event.stopPropagation(e);
  32005. });
  32006. event.addCommandKeyListener(sb, function(e, hashId, keyCode) {
  32007. var keyString = keyUtil.keyCodeToString(keyCode);
  32008. var command = _this.$searchBarKb.findKeyCommand(hashId, keyString);
  32009. if (command && command.exec) {
  32010. command.exec(_this);
  32011. event.stopEvent(e);
  32012. }
  32013. });
  32014. this.$onChange = lang.delayedCall(function() {
  32015. _this.find(false, false);
  32016. });
  32017. event.addListener(this.searchInput, "input", function() {
  32018. _this.$onChange.schedule(20);
  32019. });
  32020. event.addListener(this.searchInput, "focus", function() {
  32021. _this.activeInput = _this.searchInput;
  32022. _this.searchInput.value && _this.highlight();
  32023. });
  32024. event.addListener(this.replaceInput, "focus", function() {
  32025. _this.activeInput = _this.replaceInput;
  32026. _this.searchInput.value && _this.highlight();
  32027. });
  32028. };
  32029. this.$closeSearchBarKb = new HashHandler([{
  32030. bindKey: "Esc",
  32031. name: "closeSearchBar",
  32032. exec: function(editor) {
  32033. editor.searchBox.hide();
  32034. }
  32035. }]);
  32036. this.$searchBarKb = new HashHandler();
  32037. this.$searchBarKb.bindKeys({
  32038. "Ctrl-f|Command-f": function(sb) {
  32039. var isReplace = sb.isReplace = !sb.isReplace;
  32040. sb.replaceBox.style.display = isReplace ? "" : "none";
  32041. sb.searchInput.focus();
  32042. },
  32043. "Ctrl-H|Command-Option-F": function(sb) {
  32044. sb.replaceBox.style.display = "";
  32045. sb.replaceInput.focus();
  32046. },
  32047. "Ctrl-G|Command-G": function(sb) {
  32048. sb.findNext();
  32049. },
  32050. "Ctrl-Shift-G|Command-Shift-G": function(sb) {
  32051. sb.findPrev();
  32052. },
  32053. "esc": function(sb) {
  32054. setTimeout(function() { sb.hide();});
  32055. },
  32056. "Return": function(sb) {
  32057. if (sb.activeInput == sb.replaceInput)
  32058. sb.replace();
  32059. sb.findNext();
  32060. },
  32061. "Shift-Return": function(sb) {
  32062. if (sb.activeInput == sb.replaceInput)
  32063. sb.replace();
  32064. sb.findPrev();
  32065. },
  32066. "Alt-Return": function(sb) {
  32067. if (sb.activeInput == sb.replaceInput)
  32068. sb.replaceAll();
  32069. sb.findAll();
  32070. },
  32071. "Tab": function(sb) {
  32072. (sb.activeInput == sb.replaceInput ? sb.searchInput : sb.replaceInput).focus();
  32073. }
  32074. });
  32075. this.$searchBarKb.addCommands([{
  32076. name: "toggleRegexpMode",
  32077. bindKey: {win: "Alt-R|Alt-/", mac: "Ctrl-Alt-R|Ctrl-Alt-/"},
  32078. exec: function(sb) {
  32079. sb.regExpOption.checked = !sb.regExpOption.checked;
  32080. sb.$syncOptions();
  32081. }
  32082. }, {
  32083. name: "toggleCaseSensitive",
  32084. bindKey: {win: "Alt-C|Alt-I", mac: "Ctrl-Alt-R|Ctrl-Alt-I"},
  32085. exec: function(sb) {
  32086. sb.caseSensitiveOption.checked = !sb.caseSensitiveOption.checked;
  32087. sb.$syncOptions();
  32088. }
  32089. }, {
  32090. name: "toggleWholeWords",
  32091. bindKey: {win: "Alt-B|Alt-W", mac: "Ctrl-Alt-B|Ctrl-Alt-W"},
  32092. exec: function(sb) {
  32093. sb.wholeWordOption.checked = !sb.wholeWordOption.checked;
  32094. sb.$syncOptions();
  32095. }
  32096. }]);
  32097. this.$syncOptions = function() {
  32098. dom.setCssClass(this.regExpOption, "checked", this.regExpOption.checked);
  32099. dom.setCssClass(this.wholeWordOption, "checked", this.wholeWordOption.checked);
  32100. dom.setCssClass(this.caseSensitiveOption, "checked", this.caseSensitiveOption.checked);
  32101. this.find(false, false);
  32102. };
  32103. this.highlight = function(re) {
  32104. this.editor.session.highlight(re || this.editor.$search.$options.re);
  32105. this.editor.renderer.updateBackMarkers()
  32106. };
  32107. this.find = function(skipCurrent, backwards, preventScroll) {
  32108. var range = this.editor.find(this.searchInput.value, {
  32109. skipCurrent: skipCurrent,
  32110. backwards: backwards,
  32111. wrap: true,
  32112. regExp: this.regExpOption.checked,
  32113. caseSensitive: this.caseSensitiveOption.checked,
  32114. wholeWord: this.wholeWordOption.checked,
  32115. preventScroll: preventScroll
  32116. });
  32117. var noMatch = !range && this.searchInput.value;
  32118. dom.setCssClass(this.searchBox, "ace_nomatch", noMatch);
  32119. this.editor._emit("findSearchBox", { match: !noMatch });
  32120. this.highlight();
  32121. };
  32122. this.findNext = function() {
  32123. this.find(true, false);
  32124. };
  32125. this.findPrev = function() {
  32126. this.find(true, true);
  32127. };
  32128. this.findAll = function(){
  32129. var range = this.editor.findAll(this.searchInput.value, {
  32130. regExp: this.regExpOption.checked,
  32131. caseSensitive: this.caseSensitiveOption.checked,
  32132. wholeWord: this.wholeWordOption.checked
  32133. });
  32134. var noMatch = !range && this.searchInput.value;
  32135. dom.setCssClass(this.searchBox, "ace_nomatch", noMatch);
  32136. this.editor._emit("findSearchBox", { match: !noMatch });
  32137. this.highlight();
  32138. this.hide();
  32139. };
  32140. this.replace = function() {
  32141. if (!this.editor.getReadOnly())
  32142. this.editor.replace(this.replaceInput.value);
  32143. };
  32144. this.replaceAndFindNext = function() {
  32145. if (!this.editor.getReadOnly()) {
  32146. this.editor.replace(this.replaceInput.value);
  32147. this.findNext()
  32148. }
  32149. };
  32150. this.replaceAll = function() {
  32151. if (!this.editor.getReadOnly())
  32152. this.editor.replaceAll(this.replaceInput.value);
  32153. };
  32154. this.hide = function() {
  32155. this.element.style.display = "none";
  32156. this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb);
  32157. this.editor.focus();
  32158. };
  32159. this.show = function(value, isReplace) {
  32160. this.element.style.display = "";
  32161. this.replaceBox.style.display = isReplace ? "" : "none";
  32162. this.isReplace = isReplace;
  32163. if (value)
  32164. this.searchInput.value = value;
  32165. this.find(false, false, true);
  32166. this.searchInput.focus();
  32167. this.searchInput.select();
  32168. this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb);
  32169. };
  32170. this.isFocused = function() {
  32171. var el = document.activeElement;
  32172. return el == this.searchInput || el == this.replaceInput;
  32173. }
  32174. }).call(SearchBox.prototype);
  32175. exports.SearchBox = SearchBox;
  32176. exports.Search = function(editor, isReplace) {
  32177. var sb = editor.searchBox || new SearchBox(editor);
  32178. sb.show(editor.session.getTextRange(), isReplace);
  32179. };
  32180. });
  32181. (function() {
  32182. ace.acequire(["ace/ext/searchbox"], function() {});
  32183. })();
  32184. /***/ },
  32185. /* 70 */
  32186. /***/ function(module, exports) {
  32187. /* ***** BEGIN LICENSE BLOCK *****
  32188. * Distributed under the BSD license:
  32189. *
  32190. * Copyright (c) 2010, Ajax.org B.V.
  32191. * All rights reserved.
  32192. *
  32193. * Redistribution and use in source and binary forms, with or without
  32194. * modification, are permitted provided that the following conditions are met:
  32195. * * Redistributions of source code must retain the above copyright
  32196. * notice, this list of conditions and the following disclaimer.
  32197. * * Redistributions in binary form must reproduce the above copyright
  32198. * notice, this list of conditions and the following disclaimer in the
  32199. * documentation and/or other materials provided with the distribution.
  32200. * * Neither the name of Ajax.org B.V. nor the
  32201. * names of its contributors may be used to endorse or promote products
  32202. * derived from this software without specific prior written permission.
  32203. *
  32204. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  32205. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  32206. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32207. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  32208. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32209. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32210. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  32211. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32212. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32213. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32214. *
  32215. * ***** END LICENSE BLOCK ***** */
  32216. ace.define('ace/theme/jsoneditor', ['require', 'exports', 'module', 'ace/lib/dom'], function(acequire, exports, module) {
  32217. exports.isDark = false;
  32218. exports.cssClass = "ace-jsoneditor";
  32219. exports.cssText = ".ace-jsoneditor .ace_gutter {\
  32220. background: #ebebeb;\
  32221. color: #333\
  32222. }\
  32223. \
  32224. .ace-jsoneditor.ace_editor {\
  32225. font-family: droid sans mono, consolas, monospace, courier new, courier, sans-serif;\
  32226. line-height: 1.3;\
  32227. }\
  32228. .ace-jsoneditor .ace_print-margin {\
  32229. width: 1px;\
  32230. background: #e8e8e8\
  32231. }\
  32232. .ace-jsoneditor .ace_scroller {\
  32233. background-color: #FFFFFF\
  32234. }\
  32235. .ace-jsoneditor .ace_text-layer {\
  32236. color: gray\
  32237. }\
  32238. .ace-jsoneditor .ace_variable {\
  32239. color: #1a1a1a\
  32240. }\
  32241. .ace-jsoneditor .ace_cursor {\
  32242. border-left: 2px solid #000000\
  32243. }\
  32244. .ace-jsoneditor .ace_overwrite-cursors .ace_cursor {\
  32245. border-left: 0px;\
  32246. border-bottom: 1px solid #000000\
  32247. }\
  32248. .ace-jsoneditor .ace_marker-layer .ace_selection {\
  32249. background: lightgray\
  32250. }\
  32251. .ace-jsoneditor.ace_multiselect .ace_selection.ace_start {\
  32252. box-shadow: 0 0 3px 0px #FFFFFF;\
  32253. border-radius: 2px\
  32254. }\
  32255. .ace-jsoneditor .ace_marker-layer .ace_step {\
  32256. background: rgb(255, 255, 0)\
  32257. }\
  32258. .ace-jsoneditor .ace_marker-layer .ace_bracket {\
  32259. margin: -1px 0 0 -1px;\
  32260. border: 1px solid #BFBFBF\
  32261. }\
  32262. .ace-jsoneditor .ace_marker-layer .ace_active-line {\
  32263. background: #FFFBD1\
  32264. }\
  32265. .ace-jsoneditor .ace_gutter-active-line {\
  32266. background-color : #dcdcdc\
  32267. }\
  32268. .ace-jsoneditor .ace_marker-layer .ace_selected-word {\
  32269. border: 1px solid lightgray\
  32270. }\
  32271. .ace-jsoneditor .ace_invisible {\
  32272. color: #BFBFBF\
  32273. }\
  32274. .ace-jsoneditor .ace_keyword,\
  32275. .ace-jsoneditor .ace_meta,\
  32276. .ace-jsoneditor .ace_support.ace_constant.ace_property-value {\
  32277. color: #AF956F\
  32278. }\
  32279. .ace-jsoneditor .ace_keyword.ace_operator {\
  32280. color: #484848\
  32281. }\
  32282. .ace-jsoneditor .ace_keyword.ace_other.ace_unit {\
  32283. color: #96DC5F\
  32284. }\
  32285. .ace-jsoneditor .ace_constant.ace_language {\
  32286. color: darkorange\
  32287. }\
  32288. .ace-jsoneditor .ace_constant.ace_numeric {\
  32289. color: red\
  32290. }\
  32291. .ace-jsoneditor .ace_constant.ace_character.ace_entity {\
  32292. color: #BF78CC\
  32293. }\
  32294. .ace-jsoneditor .ace_invalid {\
  32295. color: #FFFFFF;\
  32296. background-color: #FF002A;\
  32297. }\
  32298. .ace-jsoneditor .ace_fold {\
  32299. background-color: #AF956F;\
  32300. border-color: #000000\
  32301. }\
  32302. .ace-jsoneditor .ace_storage,\
  32303. .ace-jsoneditor .ace_support.ace_class,\
  32304. .ace-jsoneditor .ace_support.ace_function,\
  32305. .ace-jsoneditor .ace_support.ace_other,\
  32306. .ace-jsoneditor .ace_support.ace_type {\
  32307. color: #C52727\
  32308. }\
  32309. .ace-jsoneditor .ace_string {\
  32310. color: green\
  32311. }\
  32312. .ace-jsoneditor .ace_comment {\
  32313. color: #BCC8BA\
  32314. }\
  32315. .ace-jsoneditor .ace_entity.ace_name.ace_tag,\
  32316. .ace-jsoneditor .ace_entity.ace_other.ace_attribute-name {\
  32317. color: #606060\
  32318. }\
  32319. .ace-jsoneditor .ace_markup.ace_underline {\
  32320. text-decoration: underline\
  32321. }\
  32322. .ace-jsoneditor .ace_indent-guide {\
  32323. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y\
  32324. }";
  32325. var dom = acequire("../lib/dom");
  32326. dom.importCssString(exports.cssText, exports.cssClass);
  32327. });
  32328. /***/ }
  32329. /******/ ])
  32330. });
  32331. ;