zx-markdown-editor.common.js 676 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = "f4a0");
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, exports) {
  91. /* (ignored) */
  92. /***/ }),
  93. /***/ "05cd":
  94. /***/ (function(module, exports) {
  95. /**
  96. * Slugger generates header id
  97. */
  98. module.exports = class Slugger {
  99. constructor() {
  100. this.seen = {};
  101. }
  102. /**
  103. * Convert string to unique id
  104. */
  105. slug(value) {
  106. let slug = value
  107. .toLowerCase()
  108. .trim()
  109. // remove html tags
  110. .replace(/<[!\/a-z].*?>/ig, '')
  111. // remove unwanted chars
  112. .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
  113. .replace(/\s/g, '-');
  114. if (this.seen.hasOwnProperty(slug)) {
  115. const originalSlug = slug;
  116. do {
  117. this.seen[originalSlug]++;
  118. slug = originalSlug + '-' + this.seen[originalSlug];
  119. } while (this.seen.hasOwnProperty(slug));
  120. }
  121. this.seen[slug] = 0;
  122. return slug;
  123. }
  124. };
  125. /***/ }),
  126. /***/ "064b":
  127. /***/ (function(module, exports) {
  128. // iterable DOM collections
  129. // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
  130. module.exports = {
  131. CSSRuleList: 0,
  132. CSSStyleDeclaration: 0,
  133. CSSValueList: 0,
  134. ClientRectList: 0,
  135. DOMRectList: 0,
  136. DOMStringList: 0,
  137. DOMTokenList: 1,
  138. DataTransferItemList: 0,
  139. FileList: 0,
  140. HTMLAllCollection: 0,
  141. HTMLCollection: 0,
  142. HTMLFormElement: 0,
  143. HTMLSelectElement: 0,
  144. MediaList: 0,
  145. MimeTypeArray: 0,
  146. NamedNodeMap: 0,
  147. NodeList: 1,
  148. PaintRequestList: 0,
  149. Plugin: 0,
  150. PluginArray: 0,
  151. SVGLengthList: 0,
  152. SVGNumberList: 0,
  153. SVGPathSegList: 0,
  154. SVGPointList: 0,
  155. SVGStringList: 0,
  156. SVGTransformList: 0,
  157. SourceBufferList: 0,
  158. StyleSheetList: 0,
  159. TextTrackCueList: 0,
  160. TextTrackList: 0,
  161. TouchList: 0
  162. };
  163. /***/ }),
  164. /***/ "0654":
  165. /***/ (function(module, exports, __webpack_require__) {
  166. /* WEBPACK VAR INJECTION */(function(__dirname) {/* globals chrome: false */
  167. /* globals __dirname: false */
  168. /* globals require: false */
  169. /* globals Buffer: false */
  170. /* globals module: false */
  171. /**
  172. * Typo is a JavaScript implementation of a spellchecker using hunspell-style
  173. * dictionaries.
  174. */
  175. var Typo;
  176. (function () {
  177. "use strict";
  178. /**
  179. * Typo constructor.
  180. *
  181. * @param {String} [dictionary] The locale code of the dictionary being used. e.g.,
  182. * "en_US". This is only used to auto-load dictionaries.
  183. * @param {String} [affData] The data from the dictionary's .aff file. If omitted
  184. * and Typo.js is being used in a Chrome extension, the .aff
  185. * file will be loaded automatically from
  186. * lib/typo/dictionaries/[dictionary]/[dictionary].aff
  187. * In other environments, it will be loaded from
  188. * [settings.dictionaryPath]/dictionaries/[dictionary]/[dictionary].aff
  189. * @param {String} [wordsData] The data from the dictionary's .dic file. If omitted
  190. * and Typo.js is being used in a Chrome extension, the .dic
  191. * file will be loaded automatically from
  192. * lib/typo/dictionaries/[dictionary]/[dictionary].dic
  193. * In other environments, it will be loaded from
  194. * [settings.dictionaryPath]/dictionaries/[dictionary]/[dictionary].dic
  195. * @param {Object} [settings] Constructor settings. Available properties are:
  196. * {String} [dictionaryPath]: path to load dictionary from in non-chrome
  197. * environment.
  198. * {Object} [flags]: flag information.
  199. * {Boolean} [asyncLoad]: If true, affData and wordsData will be loaded
  200. * asynchronously.
  201. * {Function} [loadedCallback]: Called when both affData and wordsData
  202. * have been loaded. Only used if asyncLoad is set to true. The parameter
  203. * is the instantiated Typo object.
  204. *
  205. * @returns {Typo} A Typo object.
  206. */
  207. Typo = function (dictionary, affData, wordsData, settings) {
  208. settings = settings || {};
  209. this.dictionary = null;
  210. this.rules = {};
  211. this.dictionaryTable = {};
  212. this.compoundRules = [];
  213. this.compoundRuleCodes = {};
  214. this.replacementTable = [];
  215. this.flags = settings.flags || {};
  216. this.memoized = {};
  217. this.loaded = false;
  218. var self = this;
  219. var path;
  220. // Loop-control variables.
  221. var i, j, _len, _jlen;
  222. if (dictionary) {
  223. self.dictionary = dictionary;
  224. // If the data is preloaded, just setup the Typo object.
  225. if (affData && wordsData) {
  226. setup();
  227. }
  228. // Loading data for Chrome extentions.
  229. else if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) {
  230. if (settings.dictionaryPath) {
  231. path = settings.dictionaryPath;
  232. }
  233. else {
  234. path = "typo/dictionaries";
  235. }
  236. if (!affData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".aff"), setAffData);
  237. if (!wordsData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".dic"), setWordsData);
  238. }
  239. else {
  240. if (settings.dictionaryPath) {
  241. path = settings.dictionaryPath;
  242. }
  243. else if (true) {
  244. path = __dirname + '/dictionaries';
  245. }
  246. else {}
  247. if (!affData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".aff", setAffData);
  248. if (!wordsData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".dic", setWordsData);
  249. }
  250. }
  251. function readDataFile(url, setFunc) {
  252. var response = self._readFile(url, null, settings.asyncLoad);
  253. if (settings.asyncLoad) {
  254. response.then(function(data) {
  255. setFunc(data);
  256. });
  257. }
  258. else {
  259. setFunc(response);
  260. }
  261. }
  262. function setAffData(data) {
  263. affData = data;
  264. if (wordsData) {
  265. setup();
  266. }
  267. }
  268. function setWordsData(data) {
  269. wordsData = data;
  270. if (affData) {
  271. setup();
  272. }
  273. }
  274. function setup() {
  275. self.rules = self._parseAFF(affData);
  276. // Save the rule codes that are used in compound rules.
  277. self.compoundRuleCodes = {};
  278. for (i = 0, _len = self.compoundRules.length; i < _len; i++) {
  279. var rule = self.compoundRules[i];
  280. for (j = 0, _jlen = rule.length; j < _jlen; j++) {
  281. self.compoundRuleCodes[rule[j]] = [];
  282. }
  283. }
  284. // If we add this ONLYINCOMPOUND flag to self.compoundRuleCodes, then _parseDIC
  285. // will do the work of saving the list of words that are compound-only.
  286. if ("ONLYINCOMPOUND" in self.flags) {
  287. self.compoundRuleCodes[self.flags.ONLYINCOMPOUND] = [];
  288. }
  289. self.dictionaryTable = self._parseDIC(wordsData);
  290. // Get rid of any codes from the compound rule codes that are never used
  291. // (or that were special regex characters). Not especially necessary...
  292. for (i in self.compoundRuleCodes) {
  293. if (self.compoundRuleCodes[i].length === 0) {
  294. delete self.compoundRuleCodes[i];
  295. }
  296. }
  297. // Build the full regular expressions for each compound rule.
  298. // I have a feeling (but no confirmation yet) that this method of
  299. // testing for compound words is probably slow.
  300. for (i = 0, _len = self.compoundRules.length; i < _len; i++) {
  301. var ruleText = self.compoundRules[i];
  302. var expressionText = "";
  303. for (j = 0, _jlen = ruleText.length; j < _jlen; j++) {
  304. var character = ruleText[j];
  305. if (character in self.compoundRuleCodes) {
  306. expressionText += "(" + self.compoundRuleCodes[character].join("|") + ")";
  307. }
  308. else {
  309. expressionText += character;
  310. }
  311. }
  312. self.compoundRules[i] = new RegExp(expressionText, "i");
  313. }
  314. self.loaded = true;
  315. if (settings.asyncLoad && settings.loadedCallback) {
  316. settings.loadedCallback(self);
  317. }
  318. }
  319. return this;
  320. };
  321. Typo.prototype = {
  322. /**
  323. * Loads a Typo instance from a hash of all of the Typo properties.
  324. *
  325. * @param object obj A hash of Typo properties, probably gotten from a JSON.parse(JSON.stringify(typo_instance)).
  326. */
  327. load : function (obj) {
  328. for (var i in obj) {
  329. if (obj.hasOwnProperty(i)) {
  330. this[i] = obj[i];
  331. }
  332. }
  333. return this;
  334. },
  335. /**
  336. * Read the contents of a file.
  337. *
  338. * @param {String} path The path (relative) to the file.
  339. * @param {String} [charset="ISO8859-1"] The expected charset of the file
  340. * @param {Boolean} async If true, the file will be read asynchronously. For node.js this does nothing, all
  341. * files are read synchronously.
  342. * @returns {String} The file data if async is false, otherwise a promise object. If running node.js, the data is
  343. * always returned.
  344. */
  345. _readFile : function (path, charset, async) {
  346. charset = charset || "utf8";
  347. if (typeof XMLHttpRequest !== 'undefined') {
  348. var promise;
  349. var req = new XMLHttpRequest();
  350. req.open("GET", path, async);
  351. if (async) {
  352. promise = new Promise(function(resolve, reject) {
  353. req.onload = function() {
  354. if (req.status === 200) {
  355. resolve(req.responseText);
  356. }
  357. else {
  358. reject(req.statusText);
  359. }
  360. };
  361. req.onerror = function() {
  362. reject(req.statusText);
  363. }
  364. });
  365. }
  366. if (req.overrideMimeType)
  367. req.overrideMimeType("text/plain; charset=" + charset);
  368. req.send(null);
  369. return async ? promise : req.responseText;
  370. }
  371. else if (true) {
  372. // Node.js
  373. var fs = __webpack_require__(0);
  374. try {
  375. if (fs.existsSync(path)) {
  376. return fs.readFileSync(path, charset);
  377. }
  378. else {
  379. console.log("Path " + path + " does not exist.");
  380. }
  381. } catch (e) {
  382. console.log(e);
  383. return '';
  384. }
  385. }
  386. },
  387. /**
  388. * Parse the rules out from a .aff file.
  389. *
  390. * @param {String} data The contents of the affix file.
  391. * @returns object The rules from the file.
  392. */
  393. _parseAFF : function (data) {
  394. var rules = {};
  395. var line, subline, numEntries, lineParts;
  396. var i, j, _len, _jlen;
  397. // Remove comment lines
  398. data = this._removeAffixComments(data);
  399. var lines = data.split(/\r?\n/);
  400. for (i = 0, _len = lines.length; i < _len; i++) {
  401. line = lines[i];
  402. var definitionParts = line.split(/\s+/);
  403. var ruleType = definitionParts[0];
  404. if (ruleType == "PFX" || ruleType == "SFX") {
  405. var ruleCode = definitionParts[1];
  406. var combineable = definitionParts[2];
  407. numEntries = parseInt(definitionParts[3], 10);
  408. var entries = [];
  409. for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) {
  410. subline = lines[j];
  411. lineParts = subline.split(/\s+/);
  412. var charactersToRemove = lineParts[2];
  413. var additionParts = lineParts[3].split("/");
  414. var charactersToAdd = additionParts[0];
  415. if (charactersToAdd === "0") charactersToAdd = "";
  416. var continuationClasses = this.parseRuleCodes(additionParts[1]);
  417. var regexToMatch = lineParts[4];
  418. var entry = {};
  419. entry.add = charactersToAdd;
  420. if (continuationClasses.length > 0) entry.continuationClasses = continuationClasses;
  421. if (regexToMatch !== ".") {
  422. if (ruleType === "SFX") {
  423. entry.match = new RegExp(regexToMatch + "$");
  424. }
  425. else {
  426. entry.match = new RegExp("^" + regexToMatch);
  427. }
  428. }
  429. if (charactersToRemove != "0") {
  430. if (ruleType === "SFX") {
  431. entry.remove = new RegExp(charactersToRemove + "$");
  432. }
  433. else {
  434. entry.remove = charactersToRemove;
  435. }
  436. }
  437. entries.push(entry);
  438. }
  439. rules[ruleCode] = { "type" : ruleType, "combineable" : (combineable == "Y"), "entries" : entries };
  440. i += numEntries;
  441. }
  442. else if (ruleType === "COMPOUNDRULE") {
  443. numEntries = parseInt(definitionParts[1], 10);
  444. for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) {
  445. line = lines[j];
  446. lineParts = line.split(/\s+/);
  447. this.compoundRules.push(lineParts[1]);
  448. }
  449. i += numEntries;
  450. }
  451. else if (ruleType === "REP") {
  452. lineParts = line.split(/\s+/);
  453. if (lineParts.length === 3) {
  454. this.replacementTable.push([ lineParts[1], lineParts[2] ]);
  455. }
  456. }
  457. else {
  458. // ONLYINCOMPOUND
  459. // COMPOUNDMIN
  460. // FLAG
  461. // KEEPCASE
  462. // NEEDAFFIX
  463. this.flags[ruleType] = definitionParts[1];
  464. }
  465. }
  466. return rules;
  467. },
  468. /**
  469. * Removes comment lines and then cleans up blank lines and trailing whitespace.
  470. *
  471. * @param {String} data The data from an affix file.
  472. * @return {String} The cleaned-up data.
  473. */
  474. _removeAffixComments : function (data) {
  475. // Remove comments
  476. // This used to remove any string starting with '#' up to the end of the line,
  477. // but some COMPOUNDRULE definitions include '#' as part of the rule.
  478. // I haven't seen any affix files that use comments on the same line as real data,
  479. // so I don't think this will break anything.
  480. data = data.replace(/^\s*#.*$/mg, "");
  481. // Trim each line
  482. data = data.replace(/^\s\s*/m, '').replace(/\s\s*$/m, '');
  483. // Remove blank lines.
  484. data = data.replace(/\n{2,}/g, "\n");
  485. // Trim the entire string
  486. data = data.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  487. return data;
  488. },
  489. /**
  490. * Parses the words out from the .dic file.
  491. *
  492. * @param {String} data The data from the dictionary file.
  493. * @returns object The lookup table containing all of the words and
  494. * word forms from the dictionary.
  495. */
  496. _parseDIC : function (data) {
  497. data = this._removeDicComments(data);
  498. var lines = data.split(/\r?\n/);
  499. var dictionaryTable = {};
  500. function addWord(word, rules) {
  501. // Some dictionaries will list the same word multiple times with different rule sets.
  502. if (!dictionaryTable.hasOwnProperty(word)) {
  503. dictionaryTable[word] = null;
  504. }
  505. if (rules.length > 0) {
  506. if (dictionaryTable[word] === null) {
  507. dictionaryTable[word] = [];
  508. }
  509. dictionaryTable[word].push(rules);
  510. }
  511. }
  512. // The first line is the number of words in the dictionary.
  513. for (var i = 1, _len = lines.length; i < _len; i++) {
  514. var line = lines[i];
  515. if (!line) {
  516. // Ignore empty lines.
  517. continue;
  518. }
  519. var parts = line.split("/", 2);
  520. var word = parts[0];
  521. // Now for each affix rule, generate that form of the word.
  522. if (parts.length > 1) {
  523. var ruleCodesArray = this.parseRuleCodes(parts[1]);
  524. // Save the ruleCodes for compound word situations.
  525. if (!("NEEDAFFIX" in this.flags) || ruleCodesArray.indexOf(this.flags.NEEDAFFIX) == -1) {
  526. addWord(word, ruleCodesArray);
  527. }
  528. for (var j = 0, _jlen = ruleCodesArray.length; j < _jlen; j++) {
  529. var code = ruleCodesArray[j];
  530. var rule = this.rules[code];
  531. if (rule) {
  532. var newWords = this._applyRule(word, rule);
  533. for (var ii = 0, _iilen = newWords.length; ii < _iilen; ii++) {
  534. var newWord = newWords[ii];
  535. addWord(newWord, []);
  536. if (rule.combineable) {
  537. for (var k = j + 1; k < _jlen; k++) {
  538. var combineCode = ruleCodesArray[k];
  539. var combineRule = this.rules[combineCode];
  540. if (combineRule) {
  541. if (combineRule.combineable && (rule.type != combineRule.type)) {
  542. var otherNewWords = this._applyRule(newWord, combineRule);
  543. for (var iii = 0, _iiilen = otherNewWords.length; iii < _iiilen; iii++) {
  544. var otherNewWord = otherNewWords[iii];
  545. addWord(otherNewWord, []);
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. if (code in this.compoundRuleCodes) {
  554. this.compoundRuleCodes[code].push(word);
  555. }
  556. }
  557. }
  558. else {
  559. addWord(word.trim(), []);
  560. }
  561. }
  562. return dictionaryTable;
  563. },
  564. /**
  565. * Removes comment lines and then cleans up blank lines and trailing whitespace.
  566. *
  567. * @param {String} data The data from a .dic file.
  568. * @return {String} The cleaned-up data.
  569. */
  570. _removeDicComments : function (data) {
  571. // I can't find any official documentation on it, but at least the de_DE
  572. // dictionary uses tab-indented lines as comments.
  573. // Remove comments
  574. data = data.replace(/^\t.*$/mg, "");
  575. return data;
  576. },
  577. parseRuleCodes : function (textCodes) {
  578. if (!textCodes) {
  579. return [];
  580. }
  581. else if (!("FLAG" in this.flags)) {
  582. return textCodes.split("");
  583. }
  584. else if (this.flags.FLAG === "long") {
  585. var flags = [];
  586. for (var i = 0, _len = textCodes.length; i < _len; i += 2) {
  587. flags.push(textCodes.substr(i, 2));
  588. }
  589. return flags;
  590. }
  591. else if (this.flags.FLAG === "num") {
  592. return textCodes.split(",");
  593. }
  594. },
  595. /**
  596. * Applies an affix rule to a word.
  597. *
  598. * @param {String} word The base word.
  599. * @param {Object} rule The affix rule.
  600. * @returns {String[]} The new words generated by the rule.
  601. */
  602. _applyRule : function (word, rule) {
  603. var entries = rule.entries;
  604. var newWords = [];
  605. for (var i = 0, _len = entries.length; i < _len; i++) {
  606. var entry = entries[i];
  607. if (!entry.match || word.match(entry.match)) {
  608. var newWord = word;
  609. if (entry.remove) {
  610. newWord = newWord.replace(entry.remove, "");
  611. }
  612. if (rule.type === "SFX") {
  613. newWord = newWord + entry.add;
  614. }
  615. else {
  616. newWord = entry.add + newWord;
  617. }
  618. newWords.push(newWord);
  619. if ("continuationClasses" in entry) {
  620. for (var j = 0, _jlen = entry.continuationClasses.length; j < _jlen; j++) {
  621. var continuationRule = this.rules[entry.continuationClasses[j]];
  622. if (continuationRule) {
  623. newWords = newWords.concat(this._applyRule(newWord, continuationRule));
  624. }
  625. /*
  626. else {
  627. // This shouldn't happen, but it does, at least in the de_DE dictionary.
  628. // I think the author mistakenly supplied lower-case rule codes instead
  629. // of upper-case.
  630. }
  631. */
  632. }
  633. }
  634. }
  635. }
  636. return newWords;
  637. },
  638. /**
  639. * Checks whether a word or a capitalization variant exists in the current dictionary.
  640. * The word is trimmed and several variations of capitalizations are checked.
  641. * If you want to check a word without any changes made to it, call checkExact()
  642. *
  643. * @see http://blog.stevenlevithan.com/archives/faster-trim-javascript re:trimming function
  644. *
  645. * @param {String} aWord The word to check.
  646. * @returns {Boolean}
  647. */
  648. check : function (aWord) {
  649. if (!this.loaded) {
  650. throw "Dictionary not loaded.";
  651. }
  652. // Remove leading and trailing whitespace
  653. var trimmedWord = aWord.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  654. if (this.checkExact(trimmedWord)) {
  655. return true;
  656. }
  657. // The exact word is not in the dictionary.
  658. if (trimmedWord.toUpperCase() === trimmedWord) {
  659. // The word was supplied in all uppercase.
  660. // Check for a capitalized form of the word.
  661. var capitalizedWord = trimmedWord[0] + trimmedWord.substring(1).toLowerCase();
  662. if (this.hasFlag(capitalizedWord, "KEEPCASE")) {
  663. // Capitalization variants are not allowed for this word.
  664. return false;
  665. }
  666. if (this.checkExact(capitalizedWord)) {
  667. return true;
  668. }
  669. }
  670. var lowercaseWord = trimmedWord.toLowerCase();
  671. if (lowercaseWord !== trimmedWord) {
  672. if (this.hasFlag(lowercaseWord, "KEEPCASE")) {
  673. // Capitalization variants are not allowed for this word.
  674. return false;
  675. }
  676. // Check for a lowercase form
  677. if (this.checkExact(lowercaseWord)) {
  678. return true;
  679. }
  680. }
  681. return false;
  682. },
  683. /**
  684. * Checks whether a word exists in the current dictionary.
  685. *
  686. * @param {String} word The word to check.
  687. * @returns {Boolean}
  688. */
  689. checkExact : function (word) {
  690. if (!this.loaded) {
  691. throw "Dictionary not loaded.";
  692. }
  693. var ruleCodes = this.dictionaryTable[word];
  694. var i, _len;
  695. if (typeof ruleCodes === 'undefined') {
  696. // Check if this might be a compound word.
  697. if ("COMPOUNDMIN" in this.flags && word.length >= this.flags.COMPOUNDMIN) {
  698. for (i = 0, _len = this.compoundRules.length; i < _len; i++) {
  699. if (word.match(this.compoundRules[i])) {
  700. return true;
  701. }
  702. }
  703. }
  704. }
  705. else if (ruleCodes === null) {
  706. // a null (but not undefined) value for an entry in the dictionary table
  707. // means that the word is in the dictionary but has no flags.
  708. return true;
  709. }
  710. else if (typeof ruleCodes === 'object') { // this.dictionary['hasOwnProperty'] will be a function.
  711. for (i = 0, _len = ruleCodes.length; i < _len; i++) {
  712. if (!this.hasFlag(word, "ONLYINCOMPOUND", ruleCodes[i])) {
  713. return true;
  714. }
  715. }
  716. }
  717. return false;
  718. },
  719. /**
  720. * Looks up whether a given word is flagged with a given flag.
  721. *
  722. * @param {String} word The word in question.
  723. * @param {String} flag The flag in question.
  724. * @return {Boolean}
  725. */
  726. hasFlag : function (word, flag, wordFlags) {
  727. if (!this.loaded) {
  728. throw "Dictionary not loaded.";
  729. }
  730. if (flag in this.flags) {
  731. if (typeof wordFlags === 'undefined') {
  732. wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]);
  733. }
  734. if (wordFlags && wordFlags.indexOf(this.flags[flag]) !== -1) {
  735. return true;
  736. }
  737. }
  738. return false;
  739. },
  740. /**
  741. * Returns a list of suggestions for a misspelled word.
  742. *
  743. * @see http://www.norvig.com/spell-correct.html for the basis of this suggestor.
  744. * This suggestor is primitive, but it works.
  745. *
  746. * @param {String} word The misspelling.
  747. * @param {Number} [limit=5] The maximum number of suggestions to return.
  748. * @returns {String[]} The array of suggestions.
  749. */
  750. alphabet : "",
  751. suggest : function (word, limit) {
  752. if (!this.loaded) {
  753. throw "Dictionary not loaded.";
  754. }
  755. limit = limit || 5;
  756. if (this.memoized.hasOwnProperty(word)) {
  757. var memoizedLimit = this.memoized[word]['limit'];
  758. // Only return the cached list if it's big enough or if there weren't enough suggestions
  759. // to fill a smaller limit.
  760. if (limit <= memoizedLimit || this.memoized[word]['suggestions'].length < memoizedLimit) {
  761. return this.memoized[word]['suggestions'].slice(0, limit);
  762. }
  763. }
  764. if (this.check(word)) return [];
  765. // Check the replacement table.
  766. for (var i = 0, _len = this.replacementTable.length; i < _len; i++) {
  767. var replacementEntry = this.replacementTable[i];
  768. if (word.indexOf(replacementEntry[0]) !== -1) {
  769. var correctedWord = word.replace(replacementEntry[0], replacementEntry[1]);
  770. if (this.check(correctedWord)) {
  771. return [ correctedWord ];
  772. }
  773. }
  774. }
  775. var self = this;
  776. self.alphabet = "abcdefghijklmnopqrstuvwxyz";
  777. /*
  778. if (!self.alphabet) {
  779. // Use the alphabet as implicitly defined by the words in the dictionary.
  780. var alphaHash = {};
  781. for (var i in self.dictionaryTable) {
  782. for (var j = 0, _len = i.length; j < _len; j++) {
  783. alphaHash[i[j]] = true;
  784. }
  785. }
  786. for (var i in alphaHash) {
  787. self.alphabet += i;
  788. }
  789. var alphaArray = self.alphabet.split("");
  790. alphaArray.sort();
  791. self.alphabet = alphaArray.join("");
  792. }
  793. */
  794. /**
  795. * Returns a hash keyed by all of the strings that can be made by making a single edit to the word (or words in) `words`
  796. * The value of each entry is the number of unique ways that the resulting word can be made.
  797. *
  798. * @arg mixed words Either a hash keyed by words or a string word to operate on.
  799. * @arg bool known_only Whether this function should ignore strings that are not in the dictionary.
  800. */
  801. function edits1(words, known_only) {
  802. var rv = {};
  803. var i, j, _iilen, _len, _jlen, _edit;
  804. if (typeof words == 'string') {
  805. var word = words;
  806. words = {};
  807. words[word] = true;
  808. }
  809. for (var word in words) {
  810. for (i = 0, _len = word.length + 1; i < _len; i++) {
  811. var s = [ word.substring(0, i), word.substring(i) ];
  812. if (s[1]) {
  813. _edit = s[0] + s[1].substring(1);
  814. if (!known_only || self.check(_edit)) {
  815. if (!(_edit in rv)) {
  816. rv[_edit] = 1;
  817. }
  818. else {
  819. rv[_edit] += 1;
  820. }
  821. }
  822. }
  823. // Eliminate transpositions of identical letters
  824. if (s[1].length > 1 && s[1][1] !== s[1][0]) {
  825. _edit = s[0] + s[1][1] + s[1][0] + s[1].substring(2);
  826. if (!known_only || self.check(_edit)) {
  827. if (!(_edit in rv)) {
  828. rv[_edit] = 1;
  829. }
  830. else {
  831. rv[_edit] += 1;
  832. }
  833. }
  834. }
  835. if (s[1]) {
  836. for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) {
  837. // Eliminate replacement of a letter by itself
  838. if (self.alphabet[j] != s[1].substring(0,1)){
  839. _edit = s[0] + self.alphabet[j] + s[1].substring(1);
  840. if (!known_only || self.check(_edit)) {
  841. if (!(_edit in rv)) {
  842. rv[_edit] = 1;
  843. }
  844. else {
  845. rv[_edit] += 1;
  846. }
  847. }
  848. }
  849. }
  850. }
  851. if (s[1]) {
  852. for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) {
  853. _edit = s[0] + self.alphabet[j] + s[1];
  854. if (!known_only || self.check(_edit)) {
  855. if (!(_edit in rv)) {
  856. rv[_edit] = 1;
  857. }
  858. else {
  859. rv[_edit] += 1;
  860. }
  861. }
  862. }
  863. }
  864. }
  865. }
  866. return rv;
  867. }
  868. function correct(word) {
  869. // Get the edit-distance-1 and edit-distance-2 forms of this word.
  870. var ed1 = edits1(word);
  871. var ed2 = edits1(ed1, true);
  872. // Sort the edits based on how many different ways they were created.
  873. var weighted_corrections = ed2;
  874. for (var ed1word in ed1) {
  875. if (!self.check(ed1word)) {
  876. continue;
  877. }
  878. if (ed1word in weighted_corrections) {
  879. weighted_corrections[ed1word] += ed1[ed1word];
  880. }
  881. else {
  882. weighted_corrections[ed1word] = ed1[ed1word];
  883. }
  884. }
  885. var i, _len;
  886. var sorted_corrections = [];
  887. for (i in weighted_corrections) {
  888. if (weighted_corrections.hasOwnProperty(i)) {
  889. sorted_corrections.push([ i, weighted_corrections[i] ]);
  890. }
  891. }
  892. function sorter(a, b) {
  893. var a_val = a[1];
  894. var b_val = b[1];
  895. if (a_val < b_val) {
  896. return -1;
  897. } else if (a_val > b_val) {
  898. return 1;
  899. }
  900. // @todo If a and b are equally weighted, add our own weight based on something like the key locations on this language's default keyboard.
  901. return b[0].localeCompare(a[0]);
  902. }
  903. sorted_corrections.sort(sorter).reverse();
  904. var rv = [];
  905. var capitalization_scheme = "lowercase";
  906. if (word.toUpperCase() === word) {
  907. capitalization_scheme = "uppercase";
  908. }
  909. else if (word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase() === word) {
  910. capitalization_scheme = "capitalized";
  911. }
  912. var working_limit = limit;
  913. for (i = 0; i < Math.min(working_limit, sorted_corrections.length); i++) {
  914. if ("uppercase" === capitalization_scheme) {
  915. sorted_corrections[i][0] = sorted_corrections[i][0].toUpperCase();
  916. }
  917. else if ("capitalized" === capitalization_scheme) {
  918. sorted_corrections[i][0] = sorted_corrections[i][0].substr(0, 1).toUpperCase() + sorted_corrections[i][0].substr(1);
  919. }
  920. if (!self.hasFlag(sorted_corrections[i][0], "NOSUGGEST") && rv.indexOf(sorted_corrections[i][0]) == -1) {
  921. rv.push(sorted_corrections[i][0]);
  922. }
  923. else {
  924. // If one of the corrections is not eligible as a suggestion , make sure we still return the right number of suggestions.
  925. working_limit++;
  926. }
  927. }
  928. return rv;
  929. }
  930. this.memoized[word] = {
  931. 'suggestions': correct(word),
  932. 'limit': limit
  933. };
  934. return this.memoized[word]['suggestions'];
  935. }
  936. };
  937. })();
  938. // Support for use as a node.js module.
  939. if (true) {
  940. module.exports = Typo;
  941. }
  942. /* WEBPACK VAR INJECTION */}.call(this, "/"))
  943. /***/ }),
  944. /***/ "08ba":
  945. /***/ (function(module, exports, __webpack_require__) {
  946. var global = __webpack_require__("d890");
  947. var DOMIterables = __webpack_require__("064b");
  948. var forEach = __webpack_require__("3c10");
  949. var createNonEnumerableProperty = __webpack_require__("0fc1");
  950. for (var COLLECTION_NAME in DOMIterables) {
  951. var Collection = global[COLLECTION_NAME];
  952. var CollectionPrototype = Collection && Collection.prototype;
  953. // some Chrome versions have non-configurable methods on DOMTokenList
  954. if (CollectionPrototype && CollectionPrototype.forEach !== forEach) try {
  955. createNonEnumerableProperty(CollectionPrototype, 'forEach', forEach);
  956. } catch (error) {
  957. CollectionPrototype.forEach = forEach;
  958. }
  959. }
  960. /***/ }),
  961. /***/ "094f":
  962. /***/ (function(module, exports, __webpack_require__) {
  963. const Lexer = __webpack_require__("6c31");
  964. const Parser = __webpack_require__("7727");
  965. const Tokenizer = __webpack_require__("5a9c");
  966. const Renderer = __webpack_require__("155c");
  967. const TextRenderer = __webpack_require__("f5ef");
  968. const Slugger = __webpack_require__("05cd");
  969. const {
  970. merge,
  971. checkSanitizeDeprecation,
  972. escape
  973. } = __webpack_require__("322c");
  974. const {
  975. getDefaults,
  976. changeDefaults,
  977. defaults
  978. } = __webpack_require__("a8a2");
  979. /**
  980. * Marked
  981. */
  982. function marked(src, opt, callback) {
  983. // throw error in case of non string input
  984. if (typeof src === 'undefined' || src === null) {
  985. throw new Error('marked(): input parameter is undefined or null');
  986. }
  987. if (typeof src !== 'string') {
  988. throw new Error('marked(): input parameter is of type '
  989. + Object.prototype.toString.call(src) + ', string expected');
  990. }
  991. if (callback || typeof opt === 'function') {
  992. if (!callback) {
  993. callback = opt;
  994. opt = null;
  995. }
  996. opt = merge({}, marked.defaults, opt || {});
  997. checkSanitizeDeprecation(opt);
  998. const highlight = opt.highlight;
  999. let tokens,
  1000. pending,
  1001. i = 0;
  1002. try {
  1003. tokens = Lexer.lex(src, opt);
  1004. } catch (e) {
  1005. return callback(e);
  1006. }
  1007. pending = tokens.length;
  1008. const done = function(err) {
  1009. if (err) {
  1010. opt.highlight = highlight;
  1011. return callback(err);
  1012. }
  1013. let out;
  1014. try {
  1015. out = Parser.parse(tokens, opt);
  1016. } catch (e) {
  1017. err = e;
  1018. }
  1019. opt.highlight = highlight;
  1020. return err
  1021. ? callback(err)
  1022. : callback(null, out);
  1023. };
  1024. if (!highlight || highlight.length < 3) {
  1025. return done();
  1026. }
  1027. delete opt.highlight;
  1028. if (!pending) return done();
  1029. for (; i < tokens.length; i++) {
  1030. (function(token) {
  1031. if (token.type !== 'code') {
  1032. return --pending || done();
  1033. }
  1034. return highlight(token.text, token.lang, function(err, code) {
  1035. if (err) return done(err);
  1036. if (code == null || code === token.text) {
  1037. return --pending || done();
  1038. }
  1039. token.text = code;
  1040. token.escaped = true;
  1041. --pending || done();
  1042. });
  1043. })(tokens[i]);
  1044. }
  1045. return;
  1046. }
  1047. try {
  1048. opt = merge({}, marked.defaults, opt || {});
  1049. checkSanitizeDeprecation(opt);
  1050. return Parser.parse(Lexer.lex(src, opt), opt);
  1051. } catch (e) {
  1052. e.message += '\nPlease report this to https://github.com/markedjs/marked.';
  1053. if ((opt || marked.defaults).silent) {
  1054. return '<p>An error occurred:</p><pre>'
  1055. + escape(e.message + '', true)
  1056. + '</pre>';
  1057. }
  1058. throw e;
  1059. }
  1060. }
  1061. /**
  1062. * Options
  1063. */
  1064. marked.options =
  1065. marked.setOptions = function(opt) {
  1066. merge(marked.defaults, opt);
  1067. changeDefaults(marked.defaults);
  1068. return marked;
  1069. };
  1070. marked.getDefaults = getDefaults;
  1071. marked.defaults = defaults;
  1072. /**
  1073. * Use Extension
  1074. */
  1075. marked.use = function(extension) {
  1076. const opts = merge({}, extension);
  1077. if (extension.renderer) {
  1078. const renderer = marked.defaults.renderer || new Renderer();
  1079. for (const prop in extension.renderer) {
  1080. const prevRenderer = renderer[prop];
  1081. renderer[prop] = (...args) => {
  1082. let ret = extension.renderer[prop].apply(renderer, args);
  1083. if (ret === false) {
  1084. ret = prevRenderer.apply(renderer, args);
  1085. }
  1086. return ret;
  1087. };
  1088. }
  1089. opts.renderer = renderer;
  1090. }
  1091. if (extension.tokenizer) {
  1092. const tokenizer = marked.defaults.tokenizer || new Tokenizer();
  1093. for (const prop in extension.tokenizer) {
  1094. const prevTokenizer = tokenizer[prop];
  1095. tokenizer[prop] = (...args) => {
  1096. let ret = extension.tokenizer[prop].apply(tokenizer, args);
  1097. if (ret === false) {
  1098. ret = prevTokenizer.apply(tokenizer, args);
  1099. }
  1100. return ret;
  1101. };
  1102. }
  1103. opts.tokenizer = tokenizer;
  1104. }
  1105. marked.setOptions(opts);
  1106. };
  1107. /**
  1108. * Expose
  1109. */
  1110. marked.Parser = Parser;
  1111. marked.parser = Parser.parse;
  1112. marked.Renderer = Renderer;
  1113. marked.TextRenderer = TextRenderer;
  1114. marked.Lexer = Lexer;
  1115. marked.lexer = Lexer.lex;
  1116. marked.Tokenizer = Tokenizer;
  1117. marked.Slugger = Slugger;
  1118. marked.parse = marked;
  1119. module.exports = marked;
  1120. /***/ }),
  1121. /***/ "0a60":
  1122. /***/ (function(module, exports) {
  1123. exports.f = Object.getOwnPropertySymbols;
  1124. /***/ }),
  1125. /***/ "0c3c":
  1126. /***/ (function(module, exports) {
  1127. module.exports = function (it) {
  1128. if (typeof it != 'function') {
  1129. throw TypeError(String(it) + ' is not a function');
  1130. } return it;
  1131. };
  1132. /***/ }),
  1133. /***/ "0e50":
  1134. /***/ (function(module, exports, __webpack_require__) {
  1135. // extracted by mini-css-extract-plugin
  1136. /***/ }),
  1137. /***/ "0fc1":
  1138. /***/ (function(module, exports, __webpack_require__) {
  1139. var DESCRIPTORS = __webpack_require__("1e2c");
  1140. var definePropertyModule = __webpack_require__("d910");
  1141. var createPropertyDescriptor = __webpack_require__("38b9");
  1142. module.exports = DESCRIPTORS ? function (object, key, value) {
  1143. return definePropertyModule.f(object, key, createPropertyDescriptor(1, value));
  1144. } : function (object, key, value) {
  1145. object[key] = value;
  1146. return object;
  1147. };
  1148. /***/ }),
  1149. /***/ "1025":
  1150. /***/ (function(module, exports, __webpack_require__) {
  1151. var store = __webpack_require__("3a08");
  1152. var functionToString = Function.toString;
  1153. // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
  1154. if (typeof store.inspectSource != 'function') {
  1155. store.inspectSource = function (it) {
  1156. return functionToString.call(it);
  1157. };
  1158. }
  1159. module.exports = store.inspectSource;
  1160. /***/ }),
  1161. /***/ "155c":
  1162. /***/ (function(module, exports, __webpack_require__) {
  1163. const { defaults } = __webpack_require__("a8a2");
  1164. const {
  1165. cleanUrl,
  1166. escape
  1167. } = __webpack_require__("322c");
  1168. /**
  1169. * Renderer
  1170. */
  1171. module.exports = class Renderer {
  1172. constructor(options) {
  1173. this.options = options || defaults;
  1174. }
  1175. code(code, infostring, escaped) {
  1176. const lang = (infostring || '').match(/\S*/)[0];
  1177. if (this.options.highlight) {
  1178. const out = this.options.highlight(code, lang);
  1179. if (out != null && out !== code) {
  1180. escaped = true;
  1181. code = out;
  1182. }
  1183. }
  1184. if (!lang) {
  1185. return '<pre><code>'
  1186. + (escaped ? code : escape(code, true))
  1187. + '</code></pre>';
  1188. }
  1189. return '<pre><code class="'
  1190. + this.options.langPrefix
  1191. + escape(lang, true)
  1192. + '">'
  1193. + (escaped ? code : escape(code, true))
  1194. + '</code></pre>\n';
  1195. }
  1196. blockquote(quote) {
  1197. return '<blockquote>\n' + quote + '</blockquote>\n';
  1198. }
  1199. html(html) {
  1200. return html;
  1201. }
  1202. heading(text, level, raw, slugger) {
  1203. if (this.options.headerIds) {
  1204. return '<h'
  1205. + level
  1206. + ' id="'
  1207. + this.options.headerPrefix
  1208. + slugger.slug(raw)
  1209. + '">'
  1210. + text
  1211. + '</h'
  1212. + level
  1213. + '>\n';
  1214. }
  1215. // ignore IDs
  1216. return '<h' + level + '>' + text + '</h' + level + '>\n';
  1217. }
  1218. hr() {
  1219. return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
  1220. }
  1221. list(body, ordered, start) {
  1222. const type = ordered ? 'ol' : 'ul',
  1223. startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
  1224. return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
  1225. }
  1226. listitem(text) {
  1227. return '<li>' + text + '</li>\n';
  1228. }
  1229. checkbox(checked) {
  1230. return '<input '
  1231. + (checked ? 'checked="" ' : '')
  1232. + 'disabled="" type="checkbox"'
  1233. + (this.options.xhtml ? ' /' : '')
  1234. + '> ';
  1235. }
  1236. paragraph(text) {
  1237. return '<p>' + text + '</p>\n';
  1238. }
  1239. table(header, body) {
  1240. if (body) body = '<tbody>' + body + '</tbody>';
  1241. return '<table>\n'
  1242. + '<thead>\n'
  1243. + header
  1244. + '</thead>\n'
  1245. + body
  1246. + '</table>\n';
  1247. }
  1248. tablerow(content) {
  1249. return '<tr>\n' + content + '</tr>\n';
  1250. }
  1251. tablecell(content, flags) {
  1252. const type = flags.header ? 'th' : 'td';
  1253. const tag = flags.align
  1254. ? '<' + type + ' align="' + flags.align + '">'
  1255. : '<' + type + '>';
  1256. return tag + content + '</' + type + '>\n';
  1257. }
  1258. // span level renderer
  1259. strong(text) {
  1260. return '<strong>' + text + '</strong>';
  1261. }
  1262. em(text) {
  1263. return '<em>' + text + '</em>';
  1264. }
  1265. codespan(text) {
  1266. return '<code>' + text + '</code>';
  1267. }
  1268. br() {
  1269. return this.options.xhtml ? '<br/>' : '<br>';
  1270. }
  1271. del(text) {
  1272. return '<del>' + text + '</del>';
  1273. }
  1274. link(href, title, text) {
  1275. href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
  1276. if (href === null) {
  1277. return text;
  1278. }
  1279. let out = '<a href="' + escape(href) + '"';
  1280. if (title) {
  1281. out += ' title="' + title + '"';
  1282. }
  1283. out += '>' + text + '</a>';
  1284. return out;
  1285. }
  1286. image(href, title, text) {
  1287. href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
  1288. if (href === null) {
  1289. return text;
  1290. }
  1291. let out = '<img src="' + href + '" alt="' + text + '"';
  1292. if (title) {
  1293. out += ' title="' + title + '"';
  1294. }
  1295. out += this.options.xhtml ? '/>' : '>';
  1296. return out;
  1297. }
  1298. text(text) {
  1299. return text;
  1300. }
  1301. };
  1302. /***/ }),
  1303. /***/ "18f6":
  1304. /***/ (function(module, exports) {
  1305. // IE8- don't enum bug keys
  1306. module.exports = [
  1307. 'constructor',
  1308. 'hasOwnProperty',
  1309. 'isPrototypeOf',
  1310. 'propertyIsEnumerable',
  1311. 'toLocaleString',
  1312. 'toString',
  1313. 'valueOf'
  1314. ];
  1315. /***/ }),
  1316. /***/ "1944":
  1317. /***/ (function(module, exports, __webpack_require__) {
  1318. var global = __webpack_require__("d890");
  1319. var createNonEnumerableProperty = __webpack_require__("0fc1");
  1320. var has = __webpack_require__("faa8");
  1321. var setGlobal = __webpack_require__("e4db");
  1322. var inspectSource = __webpack_require__("1025");
  1323. var InternalStateModule = __webpack_require__("b702");
  1324. var getInternalState = InternalStateModule.get;
  1325. var enforceInternalState = InternalStateModule.enforce;
  1326. var TEMPLATE = String(String).split('String');
  1327. (module.exports = function (O, key, value, options) {
  1328. var unsafe = options ? !!options.unsafe : false;
  1329. var simple = options ? !!options.enumerable : false;
  1330. var noTargetGet = options ? !!options.noTargetGet : false;
  1331. if (typeof value == 'function') {
  1332. if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
  1333. enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
  1334. }
  1335. if (O === global) {
  1336. if (simple) O[key] = value;
  1337. else setGlobal(key, value);
  1338. return;
  1339. } else if (!unsafe) {
  1340. delete O[key];
  1341. } else if (!noTargetGet && O[key]) {
  1342. simple = true;
  1343. }
  1344. if (simple) O[key] = value;
  1345. else createNonEnumerableProperty(O, key, value);
  1346. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  1347. })(Function.prototype, 'toString', function toString() {
  1348. return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
  1349. });
  1350. /***/ }),
  1351. /***/ "1b99":
  1352. /***/ (function(module, exports, __webpack_require__) {
  1353. var global = __webpack_require__("d890");
  1354. module.exports = global;
  1355. /***/ }),
  1356. /***/ "1bbd":
  1357. /***/ (function(module, exports, __webpack_require__) {
  1358. "use strict";
  1359. var toPrimitive = __webpack_require__("9f67");
  1360. var definePropertyModule = __webpack_require__("d910");
  1361. var createPropertyDescriptor = __webpack_require__("38b9");
  1362. module.exports = function (object, key, value) {
  1363. var propertyKey = toPrimitive(key);
  1364. if (propertyKey in object) definePropertyModule.f(object, propertyKey, createPropertyDescriptor(0, value));
  1365. else object[propertyKey] = value;
  1366. };
  1367. /***/ }),
  1368. /***/ "1c8b":
  1369. /***/ (function(module, exports, __webpack_require__) {
  1370. var global = __webpack_require__("d890");
  1371. var getOwnPropertyDescriptor = __webpack_require__("aa6b").f;
  1372. var createNonEnumerableProperty = __webpack_require__("0fc1");
  1373. var redefine = __webpack_require__("1944");
  1374. var setGlobal = __webpack_require__("e4db");
  1375. var copyConstructorProperties = __webpack_require__("c69d");
  1376. var isForced = __webpack_require__("e8d6");
  1377. /*
  1378. options.target - name of the target object
  1379. options.global - target is the global object
  1380. options.stat - export as static methods of target
  1381. options.proto - export as prototype methods of target
  1382. options.real - real prototype method for the `pure` version
  1383. options.forced - export even if the native feature is available
  1384. options.bind - bind methods to the target, required for the `pure` version
  1385. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  1386. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  1387. options.sham - add a flag to not completely full polyfills
  1388. options.enumerable - export as enumerable property
  1389. options.noTargetGet - prevent calling a getter on target
  1390. */
  1391. module.exports = function (options, source) {
  1392. var TARGET = options.target;
  1393. var GLOBAL = options.global;
  1394. var STATIC = options.stat;
  1395. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  1396. if (GLOBAL) {
  1397. target = global;
  1398. } else if (STATIC) {
  1399. target = global[TARGET] || setGlobal(TARGET, {});
  1400. } else {
  1401. target = (global[TARGET] || {}).prototype;
  1402. }
  1403. if (target) for (key in source) {
  1404. sourceProperty = source[key];
  1405. if (options.noTargetGet) {
  1406. descriptor = getOwnPropertyDescriptor(target, key);
  1407. targetProperty = descriptor && descriptor.value;
  1408. } else targetProperty = target[key];
  1409. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  1410. // contained in target
  1411. if (!FORCED && targetProperty !== undefined) {
  1412. if (typeof sourceProperty === typeof targetProperty) continue;
  1413. copyConstructorProperties(sourceProperty, targetProperty);
  1414. }
  1415. // add a flag to not completely full polyfills
  1416. if (options.sham || (targetProperty && targetProperty.sham)) {
  1417. createNonEnumerableProperty(sourceProperty, 'sham', true);
  1418. }
  1419. // extend global
  1420. redefine(target, key, sourceProperty, options);
  1421. }
  1422. };
  1423. /***/ }),
  1424. /***/ "1ca1":
  1425. /***/ (function(module, exports, __webpack_require__) {
  1426. var isObject = __webpack_require__("a719");
  1427. var isArray = __webpack_require__("74e7");
  1428. var wellKnownSymbol = __webpack_require__("90fb");
  1429. var SPECIES = wellKnownSymbol('species');
  1430. // `ArraySpeciesCreate` abstract operation
  1431. // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
  1432. module.exports = function (originalArray, length) {
  1433. var C;
  1434. if (isArray(originalArray)) {
  1435. C = originalArray.constructor;
  1436. // cross-realm fallback
  1437. if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
  1438. else if (isObject(C)) {
  1439. C = C[SPECIES];
  1440. if (C === null) C = undefined;
  1441. }
  1442. } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
  1443. };
  1444. /***/ }),
  1445. /***/ "1e2c":
  1446. /***/ (function(module, exports, __webpack_require__) {
  1447. var fails = __webpack_require__("efe2");
  1448. // Thank's IE8 for his funny defineProperty
  1449. module.exports = !fails(function () {
  1450. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  1451. });
  1452. /***/ }),
  1453. /***/ "1ea7":
  1454. /***/ (function(module, exports, __webpack_require__) {
  1455. var fails = __webpack_require__("efe2");
  1456. var wellKnownSymbol = __webpack_require__("90fb");
  1457. var V8_VERSION = __webpack_require__("f594");
  1458. var SPECIES = wellKnownSymbol('species');
  1459. module.exports = function (METHOD_NAME) {
  1460. // We can't use this feature detection in V8 since it causes
  1461. // deoptimization and serious performance degradation
  1462. // https://github.com/zloirock/core-js/issues/677
  1463. return V8_VERSION >= 51 || !fails(function () {
  1464. var array = [];
  1465. var constructor = array.constructor = {};
  1466. constructor[SPECIES] = function () {
  1467. return { foo: 1 };
  1468. };
  1469. return array[METHOD_NAME](Boolean).foo !== 1;
  1470. });
  1471. };
  1472. /***/ }),
  1473. /***/ "2039":
  1474. /***/ (function(module, exports, __webpack_require__) {
  1475. var DESCRIPTORS = __webpack_require__("1e2c");
  1476. var fails = __webpack_require__("efe2");
  1477. var createElement = __webpack_require__("ae25");
  1478. // Thank's IE8 for his funny defineProperty
  1479. module.exports = !DESCRIPTORS && !fails(function () {
  1480. return Object.defineProperty(createElement('div'), 'a', {
  1481. get: function () { return 7; }
  1482. }).a != 7;
  1483. });
  1484. /***/ }),
  1485. /***/ "2118":
  1486. /***/ (function(module, exports) {
  1487. var toString = {}.toString;
  1488. module.exports = function (it) {
  1489. return toString.call(it).slice(8, -1);
  1490. };
  1491. /***/ }),
  1492. /***/ "21ed":
  1493. /***/ (function(module, exports, __webpack_require__) {
  1494. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1495. // Distributed under an MIT license: https://codemirror.net/LICENSE
  1496. // Because sometimes you need to mark the selected *text*.
  1497. //
  1498. // Adds an option 'styleSelectedText' which, when enabled, gives
  1499. // selected text the CSS class given as option value, or
  1500. // "CodeMirror-selectedtext" when the value is not a string.
  1501. (function(mod) {
  1502. if (true) // CommonJS
  1503. mod(__webpack_require__("a564"));
  1504. else {}
  1505. })(function(CodeMirror) {
  1506. "use strict";
  1507. CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
  1508. var prev = old && old != CodeMirror.Init;
  1509. if (val && !prev) {
  1510. cm.state.markedSelection = [];
  1511. cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext";
  1512. reset(cm);
  1513. cm.on("cursorActivity", onCursorActivity);
  1514. cm.on("change", onChange);
  1515. } else if (!val && prev) {
  1516. cm.off("cursorActivity", onCursorActivity);
  1517. cm.off("change", onChange);
  1518. clear(cm);
  1519. cm.state.markedSelection = cm.state.markedSelectionStyle = null;
  1520. }
  1521. });
  1522. function onCursorActivity(cm) {
  1523. if (cm.state.markedSelection)
  1524. cm.operation(function() { update(cm); });
  1525. }
  1526. function onChange(cm) {
  1527. if (cm.state.markedSelection && cm.state.markedSelection.length)
  1528. cm.operation(function() { clear(cm); });
  1529. }
  1530. var CHUNK_SIZE = 8;
  1531. var Pos = CodeMirror.Pos;
  1532. var cmp = CodeMirror.cmpPos;
  1533. function coverRange(cm, from, to, addAt) {
  1534. if (cmp(from, to) == 0) return;
  1535. var array = cm.state.markedSelection;
  1536. var cls = cm.state.markedSelectionStyle;
  1537. for (var line = from.line;;) {
  1538. var start = line == from.line ? from : Pos(line, 0);
  1539. var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line;
  1540. var end = atEnd ? to : Pos(endLine, 0);
  1541. var mark = cm.markText(start, end, {className: cls});
  1542. if (addAt == null) array.push(mark);
  1543. else array.splice(addAt++, 0, mark);
  1544. if (atEnd) break;
  1545. line = endLine;
  1546. }
  1547. }
  1548. function clear(cm) {
  1549. var array = cm.state.markedSelection;
  1550. for (var i = 0; i < array.length; ++i) array[i].clear();
  1551. array.length = 0;
  1552. }
  1553. function reset(cm) {
  1554. clear(cm);
  1555. var ranges = cm.listSelections();
  1556. for (var i = 0; i < ranges.length; i++)
  1557. coverRange(cm, ranges[i].from(), ranges[i].to());
  1558. }
  1559. function update(cm) {
  1560. if (!cm.somethingSelected()) return clear(cm);
  1561. if (cm.listSelections().length > 1) return reset(cm);
  1562. var from = cm.getCursor("start"), to = cm.getCursor("end");
  1563. var array = cm.state.markedSelection;
  1564. if (!array.length) return coverRange(cm, from, to);
  1565. var coverStart = array[0].find(), coverEnd = array[array.length - 1].find();
  1566. if (!coverStart || !coverEnd || to.line - from.line <= CHUNK_SIZE ||
  1567. cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0)
  1568. return reset(cm);
  1569. while (cmp(from, coverStart.from) > 0) {
  1570. array.shift().clear();
  1571. coverStart = array[0].find();
  1572. }
  1573. if (cmp(from, coverStart.from) < 0) {
  1574. if (coverStart.to.line - from.line < CHUNK_SIZE) {
  1575. array.shift().clear();
  1576. coverRange(cm, from, coverStart.to, 0);
  1577. } else {
  1578. coverRange(cm, from, coverStart.from, 0);
  1579. }
  1580. }
  1581. while (cmp(to, coverEnd.to) < 0) {
  1582. array.pop().clear();
  1583. coverEnd = array[array.length - 1].find();
  1584. }
  1585. if (cmp(to, coverEnd.to) > 0) {
  1586. if (to.line - coverEnd.from.line < CHUNK_SIZE) {
  1587. array.pop().clear();
  1588. coverRange(cm, coverEnd.from, to);
  1589. } else {
  1590. coverRange(cm, coverEnd.to, to);
  1591. }
  1592. }
  1593. }
  1594. });
  1595. /***/ }),
  1596. /***/ "2732":
  1597. /***/ (function(module, exports) {
  1598. // `RequireObjectCoercible` abstract operation
  1599. // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
  1600. module.exports = function (it) {
  1601. if (it == undefined) throw TypeError("Can't call method on " + it);
  1602. return it;
  1603. };
  1604. /***/ }),
  1605. /***/ "27b3":
  1606. /***/ (function(module, exports, __webpack_require__) {
  1607. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1608. // Distributed under an MIT license: http://codemirror.net/LICENSE
  1609. var CodeMirror = __webpack_require__("a564");
  1610. CodeMirror.commands.tabAndIndentMarkdownList = function (cm) {
  1611. var ranges = cm.listSelections();
  1612. var pos = ranges[0].head;
  1613. var eolState = cm.getStateAfter(pos.line);
  1614. var inList = eolState.list !== false;
  1615. if (inList) {
  1616. cm.execCommand("indentMore");
  1617. return;
  1618. }
  1619. if (cm.options.indentWithTabs) {
  1620. cm.execCommand("insertTab");
  1621. }
  1622. else {
  1623. var spaces = Array(cm.options.tabSize + 1).join(" ");
  1624. cm.replaceSelection(spaces);
  1625. }
  1626. };
  1627. CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (cm) {
  1628. var ranges = cm.listSelections();
  1629. var pos = ranges[0].head;
  1630. var eolState = cm.getStateAfter(pos.line);
  1631. var inList = eolState.list !== false;
  1632. if (inList) {
  1633. cm.execCommand("indentLess");
  1634. return;
  1635. }
  1636. if (cm.options.indentWithTabs) {
  1637. cm.execCommand("insertTab");
  1638. }
  1639. else {
  1640. var spaces = Array(cm.options.tabSize + 1).join(" ");
  1641. cm.replaceSelection(spaces);
  1642. }
  1643. };
  1644. /***/ }),
  1645. /***/ "27b5":
  1646. /***/ (function(module, exports, __webpack_require__) {
  1647. var defineProperty = __webpack_require__("d910").f;
  1648. var has = __webpack_require__("faa8");
  1649. var wellKnownSymbol = __webpack_require__("90fb");
  1650. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  1651. module.exports = function (it, TAG, STATIC) {
  1652. if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) {
  1653. defineProperty(it, TO_STRING_TAG, { configurable: true, value: TAG });
  1654. }
  1655. };
  1656. /***/ }),
  1657. /***/ "31e2":
  1658. /***/ (function(module, exports, __webpack_require__) {
  1659. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1660. // Distributed under an MIT license: https://codemirror.net/LICENSE
  1661. (function(mod) {
  1662. if (true) // CommonJS
  1663. mod(__webpack_require__("a564"));
  1664. else {}
  1665. })(function(CodeMirror) {
  1666. "use strict";
  1667. CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
  1668. if (old == CodeMirror.Init) old = false;
  1669. if (!old == !val) return;
  1670. if (val) setFullscreen(cm);
  1671. else setNormal(cm);
  1672. });
  1673. function setFullscreen(cm) {
  1674. var wrap = cm.getWrapperElement();
  1675. cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
  1676. width: wrap.style.width, height: wrap.style.height};
  1677. wrap.style.width = "";
  1678. wrap.style.height = "auto";
  1679. wrap.className += " CodeMirror-fullscreen";
  1680. document.documentElement.style.overflow = "hidden";
  1681. cm.refresh();
  1682. }
  1683. function setNormal(cm) {
  1684. var wrap = cm.getWrapperElement();
  1685. wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
  1686. document.documentElement.style.overflow = "";
  1687. var info = cm.state.fullScreenRestore;
  1688. wrap.style.width = info.width; wrap.style.height = info.height;
  1689. window.scrollTo(info.scrollLeft, info.scrollTop);
  1690. cm.refresh();
  1691. }
  1692. });
  1693. /***/ }),
  1694. /***/ "322c":
  1695. /***/ (function(module, exports) {
  1696. /**
  1697. * Helpers
  1698. */
  1699. const escapeTest = /[&<>"']/;
  1700. const escapeReplace = /[&<>"']/g;
  1701. const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
  1702. const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
  1703. const escapeReplacements = {
  1704. '&': '&amp;',
  1705. '<': '&lt;',
  1706. '>': '&gt;',
  1707. '"': '&quot;',
  1708. "'": '&#39;'
  1709. };
  1710. const getEscapeReplacement = (ch) => escapeReplacements[ch];
  1711. function escape(html, encode) {
  1712. if (encode) {
  1713. if (escapeTest.test(html)) {
  1714. return html.replace(escapeReplace, getEscapeReplacement);
  1715. }
  1716. } else {
  1717. if (escapeTestNoEncode.test(html)) {
  1718. return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
  1719. }
  1720. }
  1721. return html;
  1722. }
  1723. const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
  1724. function unescape(html) {
  1725. // explicitly match decimal, hex, and named HTML entities
  1726. return html.replace(unescapeTest, (_, n) => {
  1727. n = n.toLowerCase();
  1728. if (n === 'colon') return ':';
  1729. if (n.charAt(0) === '#') {
  1730. return n.charAt(1) === 'x'
  1731. ? String.fromCharCode(parseInt(n.substring(2), 16))
  1732. : String.fromCharCode(+n.substring(1));
  1733. }
  1734. return '';
  1735. });
  1736. }
  1737. const caret = /(^|[^\[])\^/g;
  1738. function edit(regex, opt) {
  1739. regex = regex.source || regex;
  1740. opt = opt || '';
  1741. const obj = {
  1742. replace: (name, val) => {
  1743. val = val.source || val;
  1744. val = val.replace(caret, '$1');
  1745. regex = regex.replace(name, val);
  1746. return obj;
  1747. },
  1748. getRegex: () => {
  1749. return new RegExp(regex, opt);
  1750. }
  1751. };
  1752. return obj;
  1753. }
  1754. const nonWordAndColonTest = /[^\w:]/g;
  1755. const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
  1756. function cleanUrl(sanitize, base, href) {
  1757. if (sanitize) {
  1758. let prot;
  1759. try {
  1760. prot = decodeURIComponent(unescape(href))
  1761. .replace(nonWordAndColonTest, '')
  1762. .toLowerCase();
  1763. } catch (e) {
  1764. return null;
  1765. }
  1766. if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
  1767. return null;
  1768. }
  1769. }
  1770. if (base && !originIndependentUrl.test(href)) {
  1771. href = resolveUrl(base, href);
  1772. }
  1773. try {
  1774. href = encodeURI(href).replace(/%25/g, '%');
  1775. } catch (e) {
  1776. return null;
  1777. }
  1778. return href;
  1779. }
  1780. const baseUrls = {};
  1781. const justDomain = /^[^:]+:\/*[^/]*$/;
  1782. const protocol = /^([^:]+:)[\s\S]*$/;
  1783. const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
  1784. function resolveUrl(base, href) {
  1785. if (!baseUrls[' ' + base]) {
  1786. // we can ignore everything in base after the last slash of its path component,
  1787. // but we might need to add _that_
  1788. // https://tools.ietf.org/html/rfc3986#section-3
  1789. if (justDomain.test(base)) {
  1790. baseUrls[' ' + base] = base + '/';
  1791. } else {
  1792. baseUrls[' ' + base] = rtrim(base, '/', true);
  1793. }
  1794. }
  1795. base = baseUrls[' ' + base];
  1796. const relativeBase = base.indexOf(':') === -1;
  1797. if (href.substring(0, 2) === '//') {
  1798. if (relativeBase) {
  1799. return href;
  1800. }
  1801. return base.replace(protocol, '$1') + href;
  1802. } else if (href.charAt(0) === '/') {
  1803. if (relativeBase) {
  1804. return href;
  1805. }
  1806. return base.replace(domain, '$1') + href;
  1807. } else {
  1808. return base + href;
  1809. }
  1810. }
  1811. const noopTest = { exec: function noopTest() {} };
  1812. function merge(obj) {
  1813. let i = 1,
  1814. target,
  1815. key;
  1816. for (; i < arguments.length; i++) {
  1817. target = arguments[i];
  1818. for (key in target) {
  1819. if (Object.prototype.hasOwnProperty.call(target, key)) {
  1820. obj[key] = target[key];
  1821. }
  1822. }
  1823. }
  1824. return obj;
  1825. }
  1826. function splitCells(tableRow, count) {
  1827. // ensure that every cell-delimiting pipe has a space
  1828. // before it to distinguish it from an escaped pipe
  1829. const row = tableRow.replace(/\|/g, (match, offset, str) => {
  1830. let escaped = false,
  1831. curr = offset;
  1832. while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
  1833. if (escaped) {
  1834. // odd number of slashes means | is escaped
  1835. // so we leave it alone
  1836. return '|';
  1837. } else {
  1838. // add space before unescaped |
  1839. return ' |';
  1840. }
  1841. }),
  1842. cells = row.split(/ \|/);
  1843. let i = 0;
  1844. if (cells.length > count) {
  1845. cells.splice(count);
  1846. } else {
  1847. while (cells.length < count) cells.push('');
  1848. }
  1849. for (; i < cells.length; i++) {
  1850. // leading or trailing whitespace is ignored per the gfm spec
  1851. cells[i] = cells[i].trim().replace(/\\\|/g, '|');
  1852. }
  1853. return cells;
  1854. }
  1855. // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
  1856. // /c*$/ is vulnerable to REDOS.
  1857. // invert: Remove suffix of non-c chars instead. Default falsey.
  1858. function rtrim(str, c, invert) {
  1859. const l = str.length;
  1860. if (l === 0) {
  1861. return '';
  1862. }
  1863. // Length of suffix matching the invert condition.
  1864. let suffLen = 0;
  1865. // Step left until we fail to match the invert condition.
  1866. while (suffLen < l) {
  1867. const currChar = str.charAt(l - suffLen - 1);
  1868. if (currChar === c && !invert) {
  1869. suffLen++;
  1870. } else if (currChar !== c && invert) {
  1871. suffLen++;
  1872. } else {
  1873. break;
  1874. }
  1875. }
  1876. return str.substr(0, l - suffLen);
  1877. }
  1878. function findClosingBracket(str, b) {
  1879. if (str.indexOf(b[1]) === -1) {
  1880. return -1;
  1881. }
  1882. const l = str.length;
  1883. let level = 0,
  1884. i = 0;
  1885. for (; i < l; i++) {
  1886. if (str[i] === '\\') {
  1887. i++;
  1888. } else if (str[i] === b[0]) {
  1889. level++;
  1890. } else if (str[i] === b[1]) {
  1891. level--;
  1892. if (level < 0) {
  1893. return i;
  1894. }
  1895. }
  1896. }
  1897. return -1;
  1898. }
  1899. function checkSanitizeDeprecation(opt) {
  1900. if (opt && opt.sanitize && !opt.silent) {
  1901. console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
  1902. }
  1903. }
  1904. module.exports = {
  1905. escape,
  1906. unescape,
  1907. edit,
  1908. cleanUrl,
  1909. resolveUrl,
  1910. noopTest,
  1911. merge,
  1912. splitCells,
  1913. rtrim,
  1914. findClosingBracket,
  1915. checkSanitizeDeprecation
  1916. };
  1917. /***/ }),
  1918. /***/ "3553":
  1919. /***/ (function(module, exports, __webpack_require__) {
  1920. var requireObjectCoercible = __webpack_require__("2732");
  1921. // `ToObject` abstract operation
  1922. // https://tc39.github.io/ecma262/#sec-toobject
  1923. module.exports = function (argument) {
  1924. return Object(requireObjectCoercible(argument));
  1925. };
  1926. /***/ }),
  1927. /***/ "3787":
  1928. /***/ (function(module, exports, __webpack_require__) {
  1929. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1930. // Distributed under an MIT license: https://codemirror.net/LICENSE
  1931. (function(mod) {
  1932. if (true) // CommonJS
  1933. mod(__webpack_require__("a564"), __webpack_require__("fe5a"), __webpack_require__("d776"));
  1934. else {}
  1935. })(function(CodeMirror) {
  1936. "use strict";
  1937. var urlRE = /^((?:(?:aaas?|about|acap|adiumxtra|af[ps]|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|cap|chrome(?:-extension)?|cid|coap|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-(?:playcontainer|playsingle)|dns|doi|dtn|dvb|ed2k|facetime|feed|file|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|hcp|https?|iax|icap|icon|im|imap|info|ipn|ipp|irc[6s]?|iris(?:\.beep|\.lwz|\.xpc|\.xpcs)?|itms|jar|javascript|jms|keyparc|lastfm|ldaps?|magnet|mailto|maps|market|message|mid|mms|ms-help|msnim|msrps?|mtqp|mumble|mupdate|mvn|news|nfs|nih?|nntp|notes|oid|opaquelocktoken|palm|paparazzi|platform|pop|pres|proxy|psyc|query|res(?:ource)?|rmi|rsync|rtmp|rtsp|secondlife|service|session|sftp|sgn|shttp|sieve|sips?|skype|sm[bs]|snmp|soap\.beeps?|soldat|spotify|ssh|steam|svn|tag|teamspeak|tel(?:net)?|tftp|things|thismessage|tip|tn3270|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|view-source|webcal|wss?|wtai|wyciwyg|xcon(?:-userid)?|xfire|xmlrpc\.beeps?|xmpp|xri|ymsgr|z39\.50[rs]?):(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i
  1938. CodeMirror.defineMode("gfm", function(config, modeConfig) {
  1939. var codeDepth = 0;
  1940. function blankLine(state) {
  1941. state.code = false;
  1942. return null;
  1943. }
  1944. var gfmOverlay = {
  1945. startState: function() {
  1946. return {
  1947. code: false,
  1948. codeBlock: false,
  1949. ateSpace: false
  1950. };
  1951. },
  1952. copyState: function(s) {
  1953. return {
  1954. code: s.code,
  1955. codeBlock: s.codeBlock,
  1956. ateSpace: s.ateSpace
  1957. };
  1958. },
  1959. token: function(stream, state) {
  1960. state.combineTokens = null;
  1961. // Hack to prevent formatting override inside code blocks (block and inline)
  1962. if (state.codeBlock) {
  1963. if (stream.match(/^```+/)) {
  1964. state.codeBlock = false;
  1965. return null;
  1966. }
  1967. stream.skipToEnd();
  1968. return null;
  1969. }
  1970. if (stream.sol()) {
  1971. state.code = false;
  1972. }
  1973. if (stream.sol() && stream.match(/^```+/)) {
  1974. stream.skipToEnd();
  1975. state.codeBlock = true;
  1976. return null;
  1977. }
  1978. // If this block is changed, it may need to be updated in Markdown mode
  1979. if (stream.peek() === '`') {
  1980. stream.next();
  1981. var before = stream.pos;
  1982. stream.eatWhile('`');
  1983. var difference = 1 + stream.pos - before;
  1984. if (!state.code) {
  1985. codeDepth = difference;
  1986. state.code = true;
  1987. } else {
  1988. if (difference === codeDepth) { // Must be exact
  1989. state.code = false;
  1990. }
  1991. }
  1992. return null;
  1993. } else if (state.code) {
  1994. stream.next();
  1995. return null;
  1996. }
  1997. // Check if space. If so, links can be formatted later on
  1998. if (stream.eatSpace()) {
  1999. state.ateSpace = true;
  2000. return null;
  2001. }
  2002. if (stream.sol() || state.ateSpace) {
  2003. state.ateSpace = false;
  2004. if (modeConfig.gitHubSpice !== false) {
  2005. if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?=.{0,6}\d)(?:[a-f0-9]{7,40}\b)/)) {
  2006. // User/Project@SHA
  2007. // User@SHA
  2008. // SHA
  2009. state.combineTokens = true;
  2010. return "link";
  2011. } else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
  2012. // User/Project#Num
  2013. // User#Num
  2014. // #Num
  2015. state.combineTokens = true;
  2016. return "link";
  2017. }
  2018. }
  2019. }
  2020. if (stream.match(urlRE) &&
  2021. stream.string.slice(stream.start - 2, stream.start) != "](" &&
  2022. (stream.start == 0 || /\W/.test(stream.string.charAt(stream.start - 1)))) {
  2023. // URLs
  2024. // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
  2025. // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
  2026. // And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL
  2027. state.combineTokens = true;
  2028. return "link";
  2029. }
  2030. stream.next();
  2031. return null;
  2032. },
  2033. blankLine: blankLine
  2034. };
  2035. var markdownConfig = {
  2036. taskLists: true,
  2037. strikethrough: true,
  2038. emoji: true
  2039. };
  2040. for (var attr in modeConfig) {
  2041. markdownConfig[attr] = modeConfig[attr];
  2042. }
  2043. markdownConfig.name = "markdown";
  2044. return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);
  2045. }, "markdown");
  2046. CodeMirror.defineMIME("text/x-gfm", "gfm");
  2047. });
  2048. /***/ }),
  2049. /***/ "38b9":
  2050. /***/ (function(module, exports) {
  2051. module.exports = function (bitmap, value) {
  2052. return {
  2053. enumerable: !(bitmap & 1),
  2054. configurable: !(bitmap & 2),
  2055. writable: !(bitmap & 4),
  2056. value: value
  2057. };
  2058. };
  2059. /***/ }),
  2060. /***/ "3a08":
  2061. /***/ (function(module, exports, __webpack_require__) {
  2062. var global = __webpack_require__("d890");
  2063. var setGlobal = __webpack_require__("e4db");
  2064. var SHARED = '__core-js_shared__';
  2065. var store = global[SHARED] || setGlobal(SHARED, {});
  2066. module.exports = store;
  2067. /***/ }),
  2068. /***/ "3c10":
  2069. /***/ (function(module, exports, __webpack_require__) {
  2070. "use strict";
  2071. var $forEach = __webpack_require__("5dfd").forEach;
  2072. var arrayMethodIsStrict = __webpack_require__("d7e1");
  2073. var arrayMethodUsesToLength = __webpack_require__("ff9c");
  2074. var STRICT_METHOD = arrayMethodIsStrict('forEach');
  2075. var USES_TO_LENGTH = arrayMethodUsesToLength('forEach');
  2076. // `Array.prototype.forEach` method implementation
  2077. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  2078. module.exports = (!STRICT_METHOD || !USES_TO_LENGTH) ? function forEach(callbackfn /* , thisArg */) {
  2079. return $forEach(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  2080. } : [].forEach;
  2081. /***/ }),
  2082. /***/ "3da3":
  2083. /***/ (function(module, exports) {
  2084. var ceil = Math.ceil;
  2085. var floor = Math.floor;
  2086. // `ToInteger` abstract operation
  2087. // https://tc39.github.io/ecma262/#sec-tointeger
  2088. module.exports = function (argument) {
  2089. return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
  2090. };
  2091. /***/ }),
  2092. /***/ "4350":
  2093. /***/ (function(module, exports, __webpack_require__) {
  2094. var wellKnownSymbol = __webpack_require__("90fb");
  2095. exports.f = wellKnownSymbol;
  2096. /***/ }),
  2097. /***/ "45af":
  2098. /***/ (function(module, exports, __webpack_require__) {
  2099. var toIndexedObject = __webpack_require__("da10");
  2100. var toLength = __webpack_require__("d88d");
  2101. var toAbsoluteIndex = __webpack_require__("e1d6");
  2102. // `Array.prototype.{ indexOf, includes }` methods implementation
  2103. var createMethod = function (IS_INCLUDES) {
  2104. return function ($this, el, fromIndex) {
  2105. var O = toIndexedObject($this);
  2106. var length = toLength(O.length);
  2107. var index = toAbsoluteIndex(fromIndex, length);
  2108. var value;
  2109. // Array#includes uses SameValueZero equality algorithm
  2110. // eslint-disable-next-line no-self-compare
  2111. if (IS_INCLUDES && el != el) while (length > index) {
  2112. value = O[index++];
  2113. // eslint-disable-next-line no-self-compare
  2114. if (value != value) return true;
  2115. // Array#indexOf ignores holes, Array#includes - not
  2116. } else for (;length > index; index++) {
  2117. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  2118. } return !IS_INCLUDES && -1;
  2119. };
  2120. };
  2121. module.exports = {
  2122. // `Array.prototype.includes` method
  2123. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  2124. includes: createMethod(true),
  2125. // `Array.prototype.indexOf` method
  2126. // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
  2127. indexOf: createMethod(false)
  2128. };
  2129. /***/ }),
  2130. /***/ "4cd0":
  2131. /***/ (function(module, exports, __webpack_require__) {
  2132. "use strict";
  2133. // Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)
  2134. // Requires
  2135. var Typo = __webpack_require__("0654");
  2136. // Create function
  2137. function CodeMirrorSpellChecker(options) {
  2138. // Initialize
  2139. options = options || {};
  2140. // Verify
  2141. if(typeof options.codeMirrorInstance !== "function" || typeof options.codeMirrorInstance.defineMode !== "function") {
  2142. console.log("CodeMirror Spell Checker: You must provide an instance of CodeMirror via the option `codeMirrorInstance`");
  2143. return;
  2144. }
  2145. // Because some browsers don't support this functionality yet
  2146. if(!String.prototype.includes) {
  2147. String.prototype.includes = function() {
  2148. "use strict";
  2149. return String.prototype.indexOf.apply(this, arguments) !== -1;
  2150. };
  2151. }
  2152. // Define the new mode
  2153. options.codeMirrorInstance.defineMode("spell-checker", function(config) {
  2154. // Load AFF/DIC data
  2155. if(!CodeMirrorSpellChecker.aff_loading) {
  2156. CodeMirrorSpellChecker.aff_loading = true;
  2157. var xhr_aff = new XMLHttpRequest();
  2158. xhr_aff.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff", true);
  2159. xhr_aff.onload = function() {
  2160. if(xhr_aff.readyState === 4 && xhr_aff.status === 200) {
  2161. CodeMirrorSpellChecker.aff_data = xhr_aff.responseText;
  2162. CodeMirrorSpellChecker.num_loaded++;
  2163. if(CodeMirrorSpellChecker.num_loaded == 2) {
  2164. CodeMirrorSpellChecker.typo = new Typo("en_US", CodeMirrorSpellChecker.aff_data, CodeMirrorSpellChecker.dic_data, {
  2165. platform: "any"
  2166. });
  2167. }
  2168. }
  2169. };
  2170. xhr_aff.send(null);
  2171. }
  2172. if(!CodeMirrorSpellChecker.dic_loading) {
  2173. CodeMirrorSpellChecker.dic_loading = true;
  2174. var xhr_dic = new XMLHttpRequest();
  2175. xhr_dic.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic", true);
  2176. xhr_dic.onload = function() {
  2177. if(xhr_dic.readyState === 4 && xhr_dic.status === 200) {
  2178. CodeMirrorSpellChecker.dic_data = xhr_dic.responseText;
  2179. CodeMirrorSpellChecker.num_loaded++;
  2180. if(CodeMirrorSpellChecker.num_loaded == 2) {
  2181. CodeMirrorSpellChecker.typo = new Typo("en_US", CodeMirrorSpellChecker.aff_data, CodeMirrorSpellChecker.dic_data, {
  2182. platform: "any"
  2183. });
  2184. }
  2185. }
  2186. };
  2187. xhr_dic.send(null);
  2188. }
  2189. // Define what separates a word
  2190. var rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ";
  2191. // Create the overlay and such
  2192. var overlay = {
  2193. token: function(stream) {
  2194. var ch = stream.peek();
  2195. var word = "";
  2196. if(rx_word.includes(ch)) {
  2197. stream.next();
  2198. return null;
  2199. }
  2200. while((ch = stream.peek()) != null && !rx_word.includes(ch)) {
  2201. word += ch;
  2202. stream.next();
  2203. }
  2204. if(CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word))
  2205. return "spell-error"; // CSS class: cm-spell-error
  2206. return null;
  2207. }
  2208. };
  2209. var mode = options.codeMirrorInstance.getMode(
  2210. config, config.backdrop || "text/plain"
  2211. );
  2212. return options.codeMirrorInstance.overlayMode(mode, overlay, true);
  2213. });
  2214. }
  2215. // Initialize data globally to reduce memory consumption
  2216. CodeMirrorSpellChecker.num_loaded = 0;
  2217. CodeMirrorSpellChecker.aff_loading = false;
  2218. CodeMirrorSpellChecker.dic_loading = false;
  2219. CodeMirrorSpellChecker.aff_data = "";
  2220. CodeMirrorSpellChecker.dic_data = "";
  2221. CodeMirrorSpellChecker.typo;
  2222. // Export
  2223. module.exports = CodeMirrorSpellChecker;
  2224. /***/ }),
  2225. /***/ "4d02":
  2226. /***/ (function(module, exports, __webpack_require__) {
  2227. "use strict";
  2228. /*global require,module*/
  2229. var CodeMirror = __webpack_require__("a564");
  2230. __webpack_require__("7899");
  2231. __webpack_require__("27b3");
  2232. __webpack_require__("31e2");
  2233. __webpack_require__("fe5a");
  2234. __webpack_require__("d776");
  2235. __webpack_require__("f590");
  2236. __webpack_require__("21ed");
  2237. __webpack_require__("3787");
  2238. __webpack_require__("b2e0");
  2239. var CodeMirrorSpellChecker = __webpack_require__("4cd0");
  2240. var marked = __webpack_require__("094f");
  2241. // Some variables
  2242. var isMac = /Mac/.test(navigator.platform);
  2243. // Mapping of actions that can be bound to keyboard shortcuts or toolbar buttons
  2244. var bindings = {
  2245. "toggleBold": toggleBold,
  2246. "toggleItalic": toggleItalic,
  2247. "drawLink": drawLink,
  2248. "toggleHeadingSmaller": toggleHeadingSmaller,
  2249. "toggleHeadingBigger": toggleHeadingBigger,
  2250. "drawImage": drawImage,
  2251. "toggleBlockquote": toggleBlockquote,
  2252. "toggleOrderedList": toggleOrderedList,
  2253. "toggleUnorderedList": toggleUnorderedList,
  2254. "toggleCodeBlock": toggleCodeBlock,
  2255. "togglePreview": togglePreview,
  2256. "toggleStrikethrough": toggleStrikethrough,
  2257. "toggleHeading1": toggleHeading1,
  2258. "toggleHeading2": toggleHeading2,
  2259. "toggleHeading3": toggleHeading3,
  2260. "cleanBlock": cleanBlock,
  2261. "drawTable": drawTable,
  2262. "drawHorizontalRule": drawHorizontalRule,
  2263. "undo": undo,
  2264. "redo": redo,
  2265. "toggleSideBySide": toggleSideBySide,
  2266. "toggleFullScreen": toggleFullScreen
  2267. };
  2268. var shortcuts = {
  2269. "toggleBold": "Cmd-B",
  2270. "toggleItalic": "Cmd-I",
  2271. "drawLink": "Cmd-K",
  2272. "toggleHeadingSmaller": "Cmd-H",
  2273. "toggleHeadingBigger": "Shift-Cmd-H",
  2274. "cleanBlock": "Cmd-E",
  2275. "drawImage": "Cmd-Alt-I",
  2276. "toggleBlockquote": "Cmd-'",
  2277. "toggleOrderedList": "Cmd-Alt-L",
  2278. "toggleUnorderedList": "Cmd-L",
  2279. "toggleCodeBlock": "Cmd-Alt-C",
  2280. "togglePreview": "Cmd-P",
  2281. "toggleSideBySide": "F9",
  2282. "toggleFullScreen": "F11"
  2283. };
  2284. var getBindingName = function(f) {
  2285. for(var key in bindings) {
  2286. if(bindings[key] === f) {
  2287. return key;
  2288. }
  2289. }
  2290. return null;
  2291. };
  2292. var isMobile = function() {
  2293. var check = false;
  2294. (function(a) {
  2295. if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true;
  2296. })(navigator.userAgent || navigator.vendor || window.opera);
  2297. return check;
  2298. };
  2299. /**
  2300. * Fix shortcut. Mac use Command, others use Ctrl.
  2301. */
  2302. function fixShortcut(name) {
  2303. if(isMac) {
  2304. name = name.replace("Ctrl", "Cmd");
  2305. } else {
  2306. name = name.replace("Cmd", "Ctrl");
  2307. }
  2308. return name;
  2309. }
  2310. /**
  2311. * Create icon element for toolbar.
  2312. */
  2313. function createIcon(options, enableTooltips, shortcuts) {
  2314. options = options || {};
  2315. var el = document.createElement("a");
  2316. enableTooltips = (enableTooltips == undefined) ? true : enableTooltips;
  2317. if(options.title && enableTooltips) {
  2318. el.title = createTootlip(options.title, options.action, shortcuts);
  2319. if(isMac) {
  2320. el.title = el.title.replace("Ctrl", "⌘");
  2321. el.title = el.title.replace("Alt", "⌥");
  2322. }
  2323. }
  2324. el.tabIndex = -1;
  2325. el.className = options.className;
  2326. return el;
  2327. }
  2328. function createSep() {
  2329. var el = document.createElement("i");
  2330. el.className = "separator";
  2331. el.innerHTML = "|";
  2332. return el;
  2333. }
  2334. function createTootlip(title, action, shortcuts) {
  2335. var actionName;
  2336. var tooltip = title;
  2337. if(action) {
  2338. actionName = getBindingName(action);
  2339. if(shortcuts[actionName]) {
  2340. tooltip += " (" + fixShortcut(shortcuts[actionName]) + ")";
  2341. }
  2342. }
  2343. return tooltip;
  2344. }
  2345. /**
  2346. * The state of CodeMirror at the given position.
  2347. */
  2348. function getState(cm, pos) {
  2349. pos = pos || cm.getCursor("start");
  2350. var stat = cm.getTokenAt(pos);
  2351. if(!stat.type) return {};
  2352. var types = stat.type.split(" ");
  2353. var ret = {},
  2354. data, text;
  2355. for(var i = 0; i < types.length; i++) {
  2356. data = types[i];
  2357. if(data === "strong") {
  2358. ret.bold = true;
  2359. } else if(data === "variable-2") {
  2360. text = cm.getLine(pos.line);
  2361. if(/^\s*\d+\.\s/.test(text)) {
  2362. ret["ordered-list"] = true;
  2363. } else {
  2364. ret["unordered-list"] = true;
  2365. }
  2366. } else if(data === "atom") {
  2367. ret.quote = true;
  2368. } else if(data === "em") {
  2369. ret.italic = true;
  2370. } else if(data === "quote") {
  2371. ret.quote = true;
  2372. } else if(data === "strikethrough") {
  2373. ret.strikethrough = true;
  2374. } else if(data === "comment") {
  2375. ret.code = true;
  2376. } else if(data === "link") {
  2377. ret.link = true;
  2378. } else if(data === "tag") {
  2379. ret.image = true;
  2380. } else if(data.match(/^header(\-[1-6])?$/)) {
  2381. ret[data.replace("header", "heading")] = true;
  2382. }
  2383. }
  2384. return ret;
  2385. }
  2386. // Saved overflow setting
  2387. var saved_overflow = "";
  2388. /**
  2389. * Toggle full screen of the editor.
  2390. */
  2391. function toggleFullScreen(editor) {
  2392. // Set fullscreen
  2393. var cm = editor.codemirror;
  2394. cm.setOption("fullScreen", !cm.getOption("fullScreen"));
  2395. // Prevent scrolling on body during fullscreen active
  2396. if(cm.getOption("fullScreen")) {
  2397. saved_overflow = document.body.style.overflow;
  2398. document.body.style.overflow = "hidden";
  2399. } else {
  2400. document.body.style.overflow = saved_overflow;
  2401. }
  2402. // Update toolbar class
  2403. var wrap = cm.getWrapperElement();
  2404. if(!/fullscreen/.test(wrap.previousSibling.className)) {
  2405. wrap.previousSibling.className += " fullscreen";
  2406. } else {
  2407. wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, "");
  2408. }
  2409. // Update toolbar button
  2410. var toolbarButton = editor.toolbarElements.fullscreen;
  2411. if(!/active/.test(toolbarButton.className)) {
  2412. toolbarButton.className += " active";
  2413. } else {
  2414. toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, "");
  2415. }
  2416. // Hide side by side if needed
  2417. var sidebyside = cm.getWrapperElement().nextSibling;
  2418. if(/editor-preview-active-side/.test(sidebyside.className))
  2419. toggleSideBySide(editor);
  2420. }
  2421. /**
  2422. * Action for toggling bold.
  2423. */
  2424. function toggleBold(editor) {
  2425. _toggleBlock(editor, "bold", editor.options.blockStyles.bold);
  2426. }
  2427. /**
  2428. * Action for toggling italic.
  2429. */
  2430. function toggleItalic(editor) {
  2431. _toggleBlock(editor, "italic", editor.options.blockStyles.italic);
  2432. }
  2433. /**
  2434. * Action for toggling strikethrough.
  2435. */
  2436. function toggleStrikethrough(editor) {
  2437. _toggleBlock(editor, "strikethrough", "~~");
  2438. }
  2439. /**
  2440. * Action for toggling code block.
  2441. */
  2442. function toggleCodeBlock(editor) {
  2443. var fenceCharsToInsert = editor.options.blockStyles.code;
  2444. function fencing_line(line) {
  2445. /* return true, if this is a ``` or ~~~ line */
  2446. if(typeof line !== "object") {
  2447. throw "fencing_line() takes a 'line' object (not a line number, or line text). Got: " + typeof line + ": " + line;
  2448. }
  2449. return line.styles && line.styles[2] && line.styles[2].indexOf("formatting-code-block") !== -1;
  2450. }
  2451. function token_state(token) {
  2452. // base goes an extra level deep when mode backdrops are used, e.g. spellchecker on
  2453. return token.state.base.base || token.state.base;
  2454. }
  2455. function code_type(cm, line_num, line, firstTok, lastTok) {
  2456. /*
  2457. * Return "single", "indented", "fenced" or false
  2458. *
  2459. * cm and line_num are required. Others are optional for efficiency
  2460. * To check in the middle of a line, pass in firstTok yourself.
  2461. */
  2462. line = line || cm.getLineHandle(line_num);
  2463. firstTok = firstTok || cm.getTokenAt({
  2464. line: line_num,
  2465. ch: 1
  2466. });
  2467. lastTok = lastTok || (!!line.text && cm.getTokenAt({
  2468. line: line_num,
  2469. ch: line.text.length - 1
  2470. }));
  2471. var types = firstTok.type ? firstTok.type.split(" ") : [];
  2472. if(lastTok && token_state(lastTok).indentedCode) {
  2473. // have to check last char, since first chars of first line aren"t marked as indented
  2474. return "indented";
  2475. } else if(types.indexOf("comment") === -1) {
  2476. // has to be after "indented" check, since first chars of first indented line aren"t marked as such
  2477. return false;
  2478. } else if(token_state(firstTok).fencedChars || token_state(lastTok).fencedChars || fencing_line(line)) {
  2479. return "fenced";
  2480. } else {
  2481. return "single";
  2482. }
  2483. }
  2484. function insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert) {
  2485. var start_line_sel = cur_start.line + 1,
  2486. end_line_sel = cur_end.line + 1,
  2487. sel_multi = cur_start.line !== cur_end.line,
  2488. repl_start = fenceCharsToInsert + "\n",
  2489. repl_end = "\n" + fenceCharsToInsert;
  2490. if(sel_multi) {
  2491. end_line_sel++;
  2492. }
  2493. // handle last char including \n or not
  2494. if(sel_multi && cur_end.ch === 0) {
  2495. repl_end = fenceCharsToInsert + "\n";
  2496. end_line_sel--;
  2497. }
  2498. _replaceSelection(cm, false, [repl_start, repl_end]);
  2499. cm.setSelection({
  2500. line: start_line_sel,
  2501. ch: 0
  2502. }, {
  2503. line: end_line_sel,
  2504. ch: 0
  2505. });
  2506. }
  2507. var cm = editor.codemirror,
  2508. cur_start = cm.getCursor("start"),
  2509. cur_end = cm.getCursor("end"),
  2510. tok = cm.getTokenAt({
  2511. line: cur_start.line,
  2512. ch: cur_start.ch || 1
  2513. }), // avoid ch 0 which is a cursor pos but not token
  2514. line = cm.getLineHandle(cur_start.line),
  2515. is_code = code_type(cm, cur_start.line, line, tok);
  2516. var block_start, block_end, lineCount;
  2517. if(is_code === "single") {
  2518. // similar to some SimpleMDE _toggleBlock logic
  2519. var start = line.text.slice(0, cur_start.ch).replace("`", ""),
  2520. end = line.text.slice(cur_start.ch).replace("`", "");
  2521. cm.replaceRange(start + end, {
  2522. line: cur_start.line,
  2523. ch: 0
  2524. }, {
  2525. line: cur_start.line,
  2526. ch: 99999999999999
  2527. });
  2528. cur_start.ch--;
  2529. if(cur_start !== cur_end) {
  2530. cur_end.ch--;
  2531. }
  2532. cm.setSelection(cur_start, cur_end);
  2533. cm.focus();
  2534. } else if(is_code === "fenced") {
  2535. if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) {
  2536. // use selection
  2537. // find the fenced line so we know what type it is (tilde, backticks, number of them)
  2538. for(block_start = cur_start.line; block_start >= 0; block_start--) {
  2539. line = cm.getLineHandle(block_start);
  2540. if(fencing_line(line)) {
  2541. break;
  2542. }
  2543. }
  2544. var fencedTok = cm.getTokenAt({
  2545. line: block_start,
  2546. ch: 1
  2547. });
  2548. var fence_chars = token_state(fencedTok).fencedChars;
  2549. var start_text, start_line;
  2550. var end_text, end_line;
  2551. // check for selection going up against fenced lines, in which case we don't want to add more fencing
  2552. if(fencing_line(cm.getLineHandle(cur_start.line))) {
  2553. start_text = "";
  2554. start_line = cur_start.line;
  2555. } else if(fencing_line(cm.getLineHandle(cur_start.line - 1))) {
  2556. start_text = "";
  2557. start_line = cur_start.line - 1;
  2558. } else {
  2559. start_text = fence_chars + "\n";
  2560. start_line = cur_start.line;
  2561. }
  2562. if(fencing_line(cm.getLineHandle(cur_end.line))) {
  2563. end_text = "";
  2564. end_line = cur_end.line;
  2565. if(cur_end.ch === 0) {
  2566. end_line += 1;
  2567. }
  2568. } else if(cur_end.ch !== 0 && fencing_line(cm.getLineHandle(cur_end.line + 1))) {
  2569. end_text = "";
  2570. end_line = cur_end.line + 1;
  2571. } else {
  2572. end_text = fence_chars + "\n";
  2573. end_line = cur_end.line + 1;
  2574. }
  2575. if(cur_end.ch === 0) {
  2576. // full last line selected, putting cursor at beginning of next
  2577. end_line -= 1;
  2578. }
  2579. cm.operation(function() {
  2580. // end line first, so that line numbers don't change
  2581. cm.replaceRange(end_text, {
  2582. line: end_line,
  2583. ch: 0
  2584. }, {
  2585. line: end_line + (end_text ? 0 : 1),
  2586. ch: 0
  2587. });
  2588. cm.replaceRange(start_text, {
  2589. line: start_line,
  2590. ch: 0
  2591. }, {
  2592. line: start_line + (start_text ? 0 : 1),
  2593. ch: 0
  2594. });
  2595. });
  2596. cm.setSelection({
  2597. line: start_line + (start_text ? 1 : 0),
  2598. ch: 0
  2599. }, {
  2600. line: end_line + (start_text ? 1 : -1),
  2601. ch: 0
  2602. });
  2603. cm.focus();
  2604. } else {
  2605. // no selection, search for ends of this fenced block
  2606. var search_from = cur_start.line;
  2607. if(fencing_line(cm.getLineHandle(cur_start.line))) { // gets a little tricky if cursor is right on a fenced line
  2608. if(code_type(cm, cur_start.line + 1) === "fenced") {
  2609. block_start = cur_start.line;
  2610. search_from = cur_start.line + 1; // for searching for "end"
  2611. } else {
  2612. block_end = cur_start.line;
  2613. search_from = cur_start.line - 1; // for searching for "start"
  2614. }
  2615. }
  2616. if(block_start === undefined) {
  2617. for(block_start = search_from; block_start >= 0; block_start--) {
  2618. line = cm.getLineHandle(block_start);
  2619. if(fencing_line(line)) {
  2620. break;
  2621. }
  2622. }
  2623. }
  2624. if(block_end === undefined) {
  2625. lineCount = cm.lineCount();
  2626. for(block_end = search_from; block_end < lineCount; block_end++) {
  2627. line = cm.getLineHandle(block_end);
  2628. if(fencing_line(line)) {
  2629. break;
  2630. }
  2631. }
  2632. }
  2633. cm.operation(function() {
  2634. cm.replaceRange("", {
  2635. line: block_start,
  2636. ch: 0
  2637. }, {
  2638. line: block_start + 1,
  2639. ch: 0
  2640. });
  2641. cm.replaceRange("", {
  2642. line: block_end - 1,
  2643. ch: 0
  2644. }, {
  2645. line: block_end,
  2646. ch: 0
  2647. });
  2648. });
  2649. cm.focus();
  2650. }
  2651. } else if(is_code === "indented") {
  2652. if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) {
  2653. // use selection
  2654. block_start = cur_start.line;
  2655. block_end = cur_end.line;
  2656. if(cur_end.ch === 0) {
  2657. block_end--;
  2658. }
  2659. } else {
  2660. // no selection, search for ends of this indented block
  2661. for(block_start = cur_start.line; block_start >= 0; block_start--) {
  2662. line = cm.getLineHandle(block_start);
  2663. if(line.text.match(/^\s*$/)) {
  2664. // empty or all whitespace - keep going
  2665. continue;
  2666. } else {
  2667. if(code_type(cm, block_start, line) !== "indented") {
  2668. block_start += 1;
  2669. break;
  2670. }
  2671. }
  2672. }
  2673. lineCount = cm.lineCount();
  2674. for(block_end = cur_start.line; block_end < lineCount; block_end++) {
  2675. line = cm.getLineHandle(block_end);
  2676. if(line.text.match(/^\s*$/)) {
  2677. // empty or all whitespace - keep going
  2678. continue;
  2679. } else {
  2680. if(code_type(cm, block_end, line) !== "indented") {
  2681. block_end -= 1;
  2682. break;
  2683. }
  2684. }
  2685. }
  2686. }
  2687. // if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to
  2688. // insert a blank line so that the next line(s) continue to be indented code
  2689. var next_line = cm.getLineHandle(block_end + 1),
  2690. next_line_last_tok = next_line && cm.getTokenAt({
  2691. line: block_end + 1,
  2692. ch: next_line.text.length - 1
  2693. }),
  2694. next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode;
  2695. if(next_line_indented) {
  2696. cm.replaceRange("\n", {
  2697. line: block_end + 1,
  2698. ch: 0
  2699. });
  2700. }
  2701. for(var i = block_start; i <= block_end; i++) {
  2702. cm.indentLine(i, "subtract"); // TODO: this doesn't get tracked in the history, so can't be undone :(
  2703. }
  2704. cm.focus();
  2705. } else {
  2706. // insert code formatting
  2707. var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0);
  2708. var sel_multi = cur_start.line !== cur_end.line;
  2709. if(no_sel_and_starting_of_line || sel_multi) {
  2710. insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert);
  2711. } else {
  2712. _replaceSelection(cm, false, ["`", "`"]);
  2713. }
  2714. }
  2715. }
  2716. /**
  2717. * Action for toggling blockquote.
  2718. */
  2719. function toggleBlockquote(editor) {
  2720. var cm = editor.codemirror;
  2721. _toggleLine(cm, "quote");
  2722. }
  2723. /**
  2724. * Action for toggling heading size: normal -> h1 -> h2 -> h3 -> h4 -> h5 -> h6 -> normal
  2725. */
  2726. function toggleHeadingSmaller(editor) {
  2727. var cm = editor.codemirror;
  2728. _toggleHeading(cm, "smaller");
  2729. }
  2730. /**
  2731. * Action for toggling heading size: normal -> h6 -> h5 -> h4 -> h3 -> h2 -> h1 -> normal
  2732. */
  2733. function toggleHeadingBigger(editor) {
  2734. var cm = editor.codemirror;
  2735. _toggleHeading(cm, "bigger");
  2736. }
  2737. /**
  2738. * Action for toggling heading size 1
  2739. */
  2740. function toggleHeading1(editor) {
  2741. var cm = editor.codemirror;
  2742. _toggleHeading(cm, undefined, 1);
  2743. }
  2744. /**
  2745. * Action for toggling heading size 2
  2746. */
  2747. function toggleHeading2(editor) {
  2748. var cm = editor.codemirror;
  2749. _toggleHeading(cm, undefined, 2);
  2750. }
  2751. /**
  2752. * Action for toggling heading size 3
  2753. */
  2754. function toggleHeading3(editor) {
  2755. var cm = editor.codemirror;
  2756. _toggleHeading(cm, undefined, 3);
  2757. }
  2758. /**
  2759. * Action for toggling ul.
  2760. */
  2761. function toggleUnorderedList(editor) {
  2762. var cm = editor.codemirror;
  2763. _toggleLine(cm, "unordered-list");
  2764. }
  2765. /**
  2766. * Action for toggling ol.
  2767. */
  2768. function toggleOrderedList(editor) {
  2769. var cm = editor.codemirror;
  2770. _toggleLine(cm, "ordered-list");
  2771. }
  2772. /**
  2773. * Action for clean block (remove headline, list, blockquote code, markers)
  2774. */
  2775. function cleanBlock(editor) {
  2776. var cm = editor.codemirror;
  2777. _cleanBlock(cm);
  2778. }
  2779. /**
  2780. * Action for drawing a link.
  2781. */
  2782. function drawLink(editor) {
  2783. var cm = editor.codemirror;
  2784. var stat = getState(cm);
  2785. var options = editor.options;
  2786. var url = "http://";
  2787. if(options.promptURLs) {
  2788. url = prompt(options.promptTexts.link);
  2789. if(!url) {
  2790. return false;
  2791. }
  2792. }
  2793. _replaceSelection(cm, stat.link, options.insertTexts.link, url);
  2794. }
  2795. /**
  2796. * Action for drawing an img.
  2797. */
  2798. function drawImage(editor) {
  2799. var cm = editor.codemirror;
  2800. var stat = getState(cm);
  2801. var options = editor.options;
  2802. var url = "http://";
  2803. if(options.promptURLs) {
  2804. url = prompt(options.promptTexts.image);
  2805. if(!url) {
  2806. return false;
  2807. }
  2808. }
  2809. _replaceSelection(cm, stat.image, options.insertTexts.image, url);
  2810. }
  2811. /**
  2812. * Action for drawing a table.
  2813. */
  2814. function drawTable(editor) {
  2815. var cm = editor.codemirror;
  2816. var stat = getState(cm);
  2817. var options = editor.options;
  2818. _replaceSelection(cm, stat.table, options.insertTexts.table);
  2819. }
  2820. /**
  2821. * Action for drawing a horizontal rule.
  2822. */
  2823. function drawHorizontalRule(editor) {
  2824. var cm = editor.codemirror;
  2825. var stat = getState(cm);
  2826. var options = editor.options;
  2827. _replaceSelection(cm, stat.image, options.insertTexts.horizontalRule);
  2828. }
  2829. /**
  2830. * Undo action.
  2831. */
  2832. function undo(editor) {
  2833. var cm = editor.codemirror;
  2834. cm.undo();
  2835. cm.focus();
  2836. }
  2837. /**
  2838. * Redo action.
  2839. */
  2840. function redo(editor) {
  2841. var cm = editor.codemirror;
  2842. cm.redo();
  2843. cm.focus();
  2844. }
  2845. /**
  2846. * Toggle side by side preview
  2847. */
  2848. function toggleSideBySide(editor) {
  2849. var cm = editor.codemirror;
  2850. var wrapper = cm.getWrapperElement();
  2851. var preview = wrapper.nextSibling;
  2852. var toolbarButton = editor.toolbarElements["side-by-side"];
  2853. var useSideBySideListener = false;
  2854. if(/editor-preview-active-side/.test(preview.className)) {
  2855. preview.className = preview.className.replace(
  2856. /\s*editor-preview-active-side\s*/g, ""
  2857. );
  2858. toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, "");
  2859. wrapper.className = wrapper.className.replace(/\s*CodeMirror-sided\s*/g, " ");
  2860. } else {
  2861. // When the preview button is clicked for the first time,
  2862. // give some time for the transition from editor.css to fire and the view to slide from right to left,
  2863. // instead of just appearing.
  2864. setTimeout(function() {
  2865. if(!cm.getOption("fullScreen"))
  2866. toggleFullScreen(editor);
  2867. preview.className += " editor-preview-active-side";
  2868. }, 1);
  2869. toolbarButton.className += " active";
  2870. wrapper.className += " CodeMirror-sided";
  2871. useSideBySideListener = true;
  2872. }
  2873. // Hide normal preview if active
  2874. var previewNormal = wrapper.lastChild;
  2875. if(/editor-preview-active/.test(previewNormal.className)) {
  2876. previewNormal.className = previewNormal.className.replace(
  2877. /\s*editor-preview-active\s*/g, ""
  2878. );
  2879. var toolbar = editor.toolbarElements.preview;
  2880. var toolbar_div = wrapper.previousSibling;
  2881. toolbar.className = toolbar.className.replace(/\s*active\s*/g, "");
  2882. toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, "");
  2883. }
  2884. var sideBySideRenderingFunction = function() {
  2885. preview.innerHTML = editor.options.previewRender(editor.value(), preview);
  2886. };
  2887. if(!cm.sideBySideRenderingFunction) {
  2888. cm.sideBySideRenderingFunction = sideBySideRenderingFunction;
  2889. }
  2890. if(useSideBySideListener) {
  2891. preview.innerHTML = editor.options.previewRender(editor.value(), preview);
  2892. cm.on("update", cm.sideBySideRenderingFunction);
  2893. } else {
  2894. cm.off("update", cm.sideBySideRenderingFunction);
  2895. }
  2896. // Refresh to fix selection being off (#309)
  2897. cm.refresh();
  2898. }
  2899. /**
  2900. * Preview action.
  2901. */
  2902. function togglePreview(editor) {
  2903. var cm = editor.codemirror;
  2904. var wrapper = cm.getWrapperElement();
  2905. var toolbar_div = wrapper.previousSibling;
  2906. var toolbar = editor.options.toolbar ? editor.toolbarElements.preview : false;
  2907. var preview = wrapper.lastChild;
  2908. if(!preview || !/editor-preview/.test(preview.className)) {
  2909. preview = document.createElement("div");
  2910. preview.className = "editor-preview";
  2911. wrapper.appendChild(preview);
  2912. }
  2913. if(/editor-preview-active/.test(preview.className)) {
  2914. preview.className = preview.className.replace(
  2915. /\s*editor-preview-active\s*/g, ""
  2916. );
  2917. if(toolbar) {
  2918. toolbar.className = toolbar.className.replace(/\s*active\s*/g, "");
  2919. toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, "");
  2920. }
  2921. } else {
  2922. // When the preview button is clicked for the first time,
  2923. // give some time for the transition from editor.css to fire and the view to slide from right to left,
  2924. // instead of just appearing.
  2925. setTimeout(function() {
  2926. preview.className += " editor-preview-active";
  2927. }, 1);
  2928. if(toolbar) {
  2929. toolbar.className += " active";
  2930. toolbar_div.className += " disabled-for-preview";
  2931. }
  2932. }
  2933. preview.innerHTML = editor.options.previewRender(editor.value(), preview);
  2934. // Turn off side by side if needed
  2935. var sidebyside = cm.getWrapperElement().nextSibling;
  2936. if(/editor-preview-active-side/.test(sidebyside.className))
  2937. toggleSideBySide(editor);
  2938. }
  2939. function _replaceSelection(cm, active, startEnd, url) {
  2940. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  2941. return;
  2942. var text;
  2943. var start = startEnd[0];
  2944. var end = startEnd[1];
  2945. var startPoint = cm.getCursor("start");
  2946. var endPoint = cm.getCursor("end");
  2947. if(url) {
  2948. end = end.replace("#url#", url);
  2949. }
  2950. if(active) {
  2951. text = cm.getLine(startPoint.line);
  2952. start = text.slice(0, startPoint.ch);
  2953. end = text.slice(startPoint.ch);
  2954. cm.replaceRange(start + end, {
  2955. line: startPoint.line,
  2956. ch: 0
  2957. });
  2958. } else {
  2959. text = cm.getSelection();
  2960. cm.replaceSelection(start + text + end);
  2961. startPoint.ch += start.length;
  2962. if(startPoint !== endPoint) {
  2963. endPoint.ch += start.length;
  2964. }
  2965. }
  2966. cm.setSelection(startPoint, endPoint);
  2967. cm.focus();
  2968. }
  2969. function _toggleHeading(cm, direction, size) {
  2970. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  2971. return;
  2972. var startPoint = cm.getCursor("start");
  2973. var endPoint = cm.getCursor("end");
  2974. for(var i = startPoint.line; i <= endPoint.line; i++) {
  2975. (function(i) {
  2976. var text = cm.getLine(i);
  2977. var currHeadingLevel = text.search(/[^#]/);
  2978. if(direction !== undefined) {
  2979. if(currHeadingLevel <= 0) {
  2980. if(direction == "bigger") {
  2981. text = "###### " + text;
  2982. } else {
  2983. text = "# " + text;
  2984. }
  2985. } else if(currHeadingLevel == 6 && direction == "smaller") {
  2986. text = text.substr(7);
  2987. } else if(currHeadingLevel == 1 && direction == "bigger") {
  2988. text = text.substr(2);
  2989. } else {
  2990. if(direction == "bigger") {
  2991. text = text.substr(1);
  2992. } else {
  2993. text = "#" + text;
  2994. }
  2995. }
  2996. } else {
  2997. if(size == 1) {
  2998. if(currHeadingLevel <= 0) {
  2999. text = "# " + text;
  3000. } else if(currHeadingLevel == size) {
  3001. text = text.substr(currHeadingLevel + 1);
  3002. } else {
  3003. text = "# " + text.substr(currHeadingLevel + 1);
  3004. }
  3005. } else if(size == 2) {
  3006. if(currHeadingLevel <= 0) {
  3007. text = "## " + text;
  3008. } else if(currHeadingLevel == size) {
  3009. text = text.substr(currHeadingLevel + 1);
  3010. } else {
  3011. text = "## " + text.substr(currHeadingLevel + 1);
  3012. }
  3013. } else {
  3014. if(currHeadingLevel <= 0) {
  3015. text = "### " + text;
  3016. } else if(currHeadingLevel == size) {
  3017. text = text.substr(currHeadingLevel + 1);
  3018. } else {
  3019. text = "### " + text.substr(currHeadingLevel + 1);
  3020. }
  3021. }
  3022. }
  3023. cm.replaceRange(text, {
  3024. line: i,
  3025. ch: 0
  3026. }, {
  3027. line: i,
  3028. ch: 99999999999999
  3029. });
  3030. })(i);
  3031. }
  3032. cm.focus();
  3033. }
  3034. function _toggleLine(cm, name) {
  3035. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  3036. return;
  3037. var stat = getState(cm);
  3038. var startPoint = cm.getCursor("start");
  3039. var endPoint = cm.getCursor("end");
  3040. var repl = {
  3041. "quote": /^(\s*)\>\s+/,
  3042. "unordered-list": /^(\s*)(\*|\-|\+)\s+/,
  3043. "ordered-list": /^(\s*)\d+\.\s+/
  3044. };
  3045. var map = {
  3046. "quote": "> ",
  3047. "unordered-list": "* ",
  3048. "ordered-list": "1. "
  3049. };
  3050. for(var i = startPoint.line; i <= endPoint.line; i++) {
  3051. (function(i) {
  3052. var text = cm.getLine(i);
  3053. if(stat[name]) {
  3054. text = text.replace(repl[name], "$1");
  3055. } else {
  3056. text = map[name] + text;
  3057. }
  3058. cm.replaceRange(text, {
  3059. line: i,
  3060. ch: 0
  3061. }, {
  3062. line: i,
  3063. ch: 99999999999999
  3064. });
  3065. })(i);
  3066. }
  3067. cm.focus();
  3068. }
  3069. function _toggleBlock(editor, type, start_chars, end_chars) {
  3070. if(/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className))
  3071. return;
  3072. end_chars = (typeof end_chars === "undefined") ? start_chars : end_chars;
  3073. var cm = editor.codemirror;
  3074. var stat = getState(cm);
  3075. var text;
  3076. var start = start_chars;
  3077. var end = end_chars;
  3078. var startPoint = cm.getCursor("start");
  3079. var endPoint = cm.getCursor("end");
  3080. if(stat[type]) {
  3081. text = cm.getLine(startPoint.line);
  3082. start = text.slice(0, startPoint.ch);
  3083. end = text.slice(startPoint.ch);
  3084. if(type == "bold") {
  3085. start = start.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/, "");
  3086. end = end.replace(/(\*\*|__)/, "");
  3087. } else if(type == "italic") {
  3088. start = start.replace(/(\*|_)(?![\s\S]*(\*|_))/, "");
  3089. end = end.replace(/(\*|_)/, "");
  3090. } else if(type == "strikethrough") {
  3091. start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, "");
  3092. end = end.replace(/(\*\*|~~)/, "");
  3093. }
  3094. cm.replaceRange(start + end, {
  3095. line: startPoint.line,
  3096. ch: 0
  3097. }, {
  3098. line: startPoint.line,
  3099. ch: 99999999999999
  3100. });
  3101. if(type == "bold" || type == "strikethrough") {
  3102. startPoint.ch -= 2;
  3103. if(startPoint !== endPoint) {
  3104. endPoint.ch -= 2;
  3105. }
  3106. } else if(type == "italic") {
  3107. startPoint.ch -= 1;
  3108. if(startPoint !== endPoint) {
  3109. endPoint.ch -= 1;
  3110. }
  3111. }
  3112. } else {
  3113. text = cm.getSelection();
  3114. if(type == "bold") {
  3115. text = text.split("**").join("");
  3116. text = text.split("__").join("");
  3117. } else if(type == "italic") {
  3118. text = text.split("*").join("");
  3119. text = text.split("_").join("");
  3120. } else if(type == "strikethrough") {
  3121. text = text.split("~~").join("");
  3122. }
  3123. cm.replaceSelection(start + text + end);
  3124. startPoint.ch += start_chars.length;
  3125. endPoint.ch = startPoint.ch + text.length;
  3126. }
  3127. cm.setSelection(startPoint, endPoint);
  3128. cm.focus();
  3129. }
  3130. function _cleanBlock(cm) {
  3131. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  3132. return;
  3133. var startPoint = cm.getCursor("start");
  3134. var endPoint = cm.getCursor("end");
  3135. var text;
  3136. for(var line = startPoint.line; line <= endPoint.line; line++) {
  3137. text = cm.getLine(line);
  3138. text = text.replace(/^[ ]*([# ]+|\*|\-|[> ]+|[0-9]+(.|\)))[ ]*/, "");
  3139. cm.replaceRange(text, {
  3140. line: line,
  3141. ch: 0
  3142. }, {
  3143. line: line,
  3144. ch: 99999999999999
  3145. });
  3146. }
  3147. }
  3148. // Merge the properties of one object into another.
  3149. function _mergeProperties(target, source) {
  3150. for(var property in source) {
  3151. if(source.hasOwnProperty(property)) {
  3152. if(source[property] instanceof Array) {
  3153. target[property] = source[property].concat(target[property] instanceof Array ? target[property] : []);
  3154. } else if(
  3155. source[property] !== null &&
  3156. typeof source[property] === "object" &&
  3157. source[property].constructor === Object
  3158. ) {
  3159. target[property] = _mergeProperties(target[property] || {}, source[property]);
  3160. } else {
  3161. target[property] = source[property];
  3162. }
  3163. }
  3164. }
  3165. return target;
  3166. }
  3167. // Merge an arbitrary number of objects into one.
  3168. function extend(target) {
  3169. for(var i = 1; i < arguments.length; i++) {
  3170. target = _mergeProperties(target, arguments[i]);
  3171. }
  3172. return target;
  3173. }
  3174. /* The right word count in respect for CJK. */
  3175. function wordCount(data) {
  3176. var pattern = /[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
  3177. var m = data.match(pattern);
  3178. var count = 0;
  3179. if(m === null) return count;
  3180. for(var i = 0; i < m.length; i++) {
  3181. if(m[i].charCodeAt(0) >= 0x4E00) {
  3182. count += m[i].length;
  3183. } else {
  3184. count += 1;
  3185. }
  3186. }
  3187. return count;
  3188. }
  3189. var toolbarBuiltInButtons = {
  3190. "bold": {
  3191. name: "bold",
  3192. action: toggleBold,
  3193. className: "fa fa-bold",
  3194. title: "Bold",
  3195. default: true
  3196. },
  3197. "italic": {
  3198. name: "italic",
  3199. action: toggleItalic,
  3200. className: "fa fa-italic",
  3201. title: "Italic",
  3202. default: true
  3203. },
  3204. "strikethrough": {
  3205. name: "strikethrough",
  3206. action: toggleStrikethrough,
  3207. className: "fa fa-strikethrough",
  3208. title: "Strikethrough"
  3209. },
  3210. "heading": {
  3211. name: "heading",
  3212. action: toggleHeadingSmaller,
  3213. className: "fa fa-header",
  3214. title: "Heading",
  3215. default: true
  3216. },
  3217. "heading-smaller": {
  3218. name: "heading-smaller",
  3219. action: toggleHeadingSmaller,
  3220. className: "fa fa-header fa-header-x fa-header-smaller",
  3221. title: "Smaller Heading"
  3222. },
  3223. "heading-bigger": {
  3224. name: "heading-bigger",
  3225. action: toggleHeadingBigger,
  3226. className: "fa fa-header fa-header-x fa-header-bigger",
  3227. title: "Bigger Heading"
  3228. },
  3229. "heading-1": {
  3230. name: "heading-1",
  3231. action: toggleHeading1,
  3232. className: "fa fa-header fa-header-x fa-header-1",
  3233. title: "Big Heading"
  3234. },
  3235. "heading-2": {
  3236. name: "heading-2",
  3237. action: toggleHeading2,
  3238. className: "fa fa-header fa-header-x fa-header-2",
  3239. title: "Medium Heading"
  3240. },
  3241. "heading-3": {
  3242. name: "heading-3",
  3243. action: toggleHeading3,
  3244. className: "fa fa-header fa-header-x fa-header-3",
  3245. title: "Small Heading"
  3246. },
  3247. "separator-1": {
  3248. name: "separator-1"
  3249. },
  3250. "code": {
  3251. name: "code",
  3252. action: toggleCodeBlock,
  3253. className: "fa fa-code",
  3254. title: "Code"
  3255. },
  3256. "quote": {
  3257. name: "quote",
  3258. action: toggleBlockquote,
  3259. className: "fa fa-quote-left",
  3260. title: "Quote",
  3261. default: true
  3262. },
  3263. "unordered-list": {
  3264. name: "unordered-list",
  3265. action: toggleUnorderedList,
  3266. className: "fa fa-list-ul",
  3267. title: "Generic List",
  3268. default: true
  3269. },
  3270. "ordered-list": {
  3271. name: "ordered-list",
  3272. action: toggleOrderedList,
  3273. className: "fa fa-list-ol",
  3274. title: "Numbered List",
  3275. default: true
  3276. },
  3277. "clean-block": {
  3278. name: "clean-block",
  3279. action: cleanBlock,
  3280. className: "fa fa-eraser fa-clean-block",
  3281. title: "Clean block"
  3282. },
  3283. "separator-2": {
  3284. name: "separator-2"
  3285. },
  3286. "link": {
  3287. name: "link",
  3288. action: drawLink,
  3289. className: "fa fa-link",
  3290. title: "Create Link",
  3291. default: true
  3292. },
  3293. "image": {
  3294. name: "image",
  3295. action: drawImage,
  3296. className: "fa fa-picture-o",
  3297. title: "Insert Image",
  3298. default: true
  3299. },
  3300. "table": {
  3301. name: "table",
  3302. action: drawTable,
  3303. className: "fa fa-table",
  3304. title: "Insert Table"
  3305. },
  3306. "horizontal-rule": {
  3307. name: "horizontal-rule",
  3308. action: drawHorizontalRule,
  3309. className: "fa fa-minus",
  3310. title: "Insert Horizontal Line"
  3311. },
  3312. "separator-3": {
  3313. name: "separator-3"
  3314. },
  3315. "preview": {
  3316. name: "preview",
  3317. action: togglePreview,
  3318. className: "fa fa-eye no-disable",
  3319. title: "Toggle Preview",
  3320. default: true
  3321. },
  3322. "side-by-side": {
  3323. name: "side-by-side",
  3324. action: toggleSideBySide,
  3325. className: "fa fa-columns no-disable no-mobile",
  3326. title: "Toggle Side by Side",
  3327. default: true
  3328. },
  3329. "fullscreen": {
  3330. name: "fullscreen",
  3331. action: toggleFullScreen,
  3332. className: "fa fa-arrows-alt no-disable no-mobile",
  3333. title: "Toggle Fullscreen",
  3334. default: true
  3335. },
  3336. "separator-4": {
  3337. name: "separator-4"
  3338. },
  3339. "guide": {
  3340. name: "guide",
  3341. action: "https://simplemde.com/markdown-guide",
  3342. className: "fa fa-question-circle",
  3343. title: "Markdown Guide",
  3344. default: true
  3345. },
  3346. "separator-5": {
  3347. name: "separator-5"
  3348. },
  3349. "undo": {
  3350. name: "undo",
  3351. action: undo,
  3352. className: "fa fa-undo no-disable",
  3353. title: "Undo"
  3354. },
  3355. "redo": {
  3356. name: "redo",
  3357. action: redo,
  3358. className: "fa fa-repeat no-disable",
  3359. title: "Redo"
  3360. }
  3361. };
  3362. var insertTexts = {
  3363. link: ["[", "](#url#)"],
  3364. image: ["![](", "#url#)"],
  3365. table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
  3366. horizontalRule: ["", "\n\n-----\n\n"]
  3367. };
  3368. var promptTexts = {
  3369. link: "URL for the link:",
  3370. image: "URL of the image:"
  3371. };
  3372. var blockStyles = {
  3373. "bold": "**",
  3374. "code": "```",
  3375. "italic": "*"
  3376. };
  3377. /**
  3378. * Interface of SimpleMDE.
  3379. */
  3380. function SimpleMDE(options) {
  3381. // Handle options parameter
  3382. options = options || {};
  3383. // Used later to refer to it"s parent
  3384. options.parent = this;
  3385. // Check if Font Awesome needs to be auto downloaded
  3386. var autoDownloadFA = true;
  3387. if(options.autoDownloadFontAwesome === false) {
  3388. autoDownloadFA = false;
  3389. }
  3390. if(options.autoDownloadFontAwesome !== true) {
  3391. var styleSheets = document.styleSheets;
  3392. for(var i = 0; i < styleSheets.length; i++) {
  3393. if(!styleSheets[i].href)
  3394. continue;
  3395. if(styleSheets[i].href.indexOf("//maxcdn.bootstrapcdn.com/font-awesome/") > -1) {
  3396. autoDownloadFA = false;
  3397. }
  3398. }
  3399. }
  3400. if(autoDownloadFA) {
  3401. var link = document.createElement("link");
  3402. link.rel = "stylesheet";
  3403. link.href = "https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css";
  3404. document.getElementsByTagName("head")[0].appendChild(link);
  3405. }
  3406. // Find the textarea to use
  3407. if(options.element) {
  3408. this.element = options.element;
  3409. } else if(options.element === null) {
  3410. // This means that the element option was specified, but no element was found
  3411. console.log("SimpleMDE: Error. No element was found.");
  3412. return;
  3413. }
  3414. // Handle toolbar
  3415. if(options.toolbar === undefined) {
  3416. // Initialize
  3417. options.toolbar = [];
  3418. // Loop over the built in buttons, to get the preferred order
  3419. for(var key in toolbarBuiltInButtons) {
  3420. if(toolbarBuiltInButtons.hasOwnProperty(key)) {
  3421. if(key.indexOf("separator-") != -1) {
  3422. options.toolbar.push("|");
  3423. }
  3424. if(toolbarBuiltInButtons[key].default === true || (options.showIcons && options.showIcons.constructor === Array && options.showIcons.indexOf(key) != -1)) {
  3425. options.toolbar.push(key);
  3426. }
  3427. }
  3428. }
  3429. }
  3430. // Handle status bar
  3431. if(!options.hasOwnProperty("status")) {
  3432. options.status = ["autosave", "lines", "words", "cursor"];
  3433. }
  3434. // Add default preview rendering function
  3435. if(!options.previewRender) {
  3436. options.previewRender = function(plainText) {
  3437. // Note: "this" refers to the options object
  3438. return this.parent.markdown(plainText);
  3439. };
  3440. }
  3441. // Set default options for parsing config
  3442. options.parsingConfig = extend({
  3443. highlightFormatting: true // needed for toggleCodeBlock to detect types of code
  3444. }, options.parsingConfig || {});
  3445. // Merging the insertTexts, with the given options
  3446. options.insertTexts = extend({}, insertTexts, options.insertTexts || {});
  3447. // Merging the promptTexts, with the given options
  3448. options.promptTexts = promptTexts;
  3449. // Merging the blockStyles, with the given options
  3450. options.blockStyles = extend({}, blockStyles, options.blockStyles || {});
  3451. // Merging the shortcuts, with the given options
  3452. options.shortcuts = extend({}, shortcuts, options.shortcuts || {});
  3453. // Change unique_id to uniqueId for backwards compatibility
  3454. if(options.autosave != undefined && options.autosave.unique_id != undefined && options.autosave.unique_id != "")
  3455. options.autosave.uniqueId = options.autosave.unique_id;
  3456. // Update this options
  3457. this.options = options;
  3458. // Auto render
  3459. this.render();
  3460. // The codemirror component is only available after rendering
  3461. // so, the setter for the initialValue can only run after
  3462. // the element has been rendered
  3463. if(options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) {
  3464. this.value(options.initialValue);
  3465. }
  3466. }
  3467. /**
  3468. * Default markdown render.
  3469. */
  3470. SimpleMDE.prototype.markdown = function(text) {
  3471. if(marked) {
  3472. // Initialize
  3473. var markedOptions = {};
  3474. // Update options
  3475. if(this.options && this.options.renderingConfig && this.options.renderingConfig.singleLineBreaks === false) {
  3476. markedOptions.breaks = false;
  3477. } else {
  3478. markedOptions.breaks = true;
  3479. }
  3480. if(this.options && this.options.renderingConfig && this.options.renderingConfig.codeSyntaxHighlighting === true && window.hljs) {
  3481. markedOptions.highlight = function(code) {
  3482. return window.hljs.highlightAuto(code).value;
  3483. };
  3484. }
  3485. // Set options
  3486. marked.setOptions(markedOptions);
  3487. // Return
  3488. return marked(text);
  3489. }
  3490. };
  3491. /**
  3492. * Render editor to the given element.
  3493. */
  3494. SimpleMDE.prototype.render = function(el) {
  3495. if(!el) {
  3496. el = this.element || document.getElementsByTagName("textarea")[0];
  3497. }
  3498. if(this._rendered && this._rendered === el) {
  3499. // Already rendered.
  3500. return;
  3501. }
  3502. this.element = el;
  3503. var options = this.options;
  3504. var self = this;
  3505. var keyMaps = {};
  3506. for(var key in options.shortcuts) {
  3507. // null stands for "do not bind this command"
  3508. if(options.shortcuts[key] !== null && bindings[key] !== null) {
  3509. (function(key) {
  3510. keyMaps[fixShortcut(options.shortcuts[key])] = function() {
  3511. bindings[key](self);
  3512. };
  3513. })(key);
  3514. }
  3515. }
  3516. keyMaps["Enter"] = "newlineAndIndentContinueMarkdownList";
  3517. keyMaps["Tab"] = "tabAndIndentMarkdownList";
  3518. keyMaps["Shift-Tab"] = "shiftTabAndUnindentMarkdownList";
  3519. keyMaps["Esc"] = function(cm) {
  3520. if(cm.getOption("fullScreen")) toggleFullScreen(self);
  3521. };
  3522. document.addEventListener("keydown", function(e) {
  3523. e = e || window.event;
  3524. if(e.keyCode == 27) {
  3525. if(self.codemirror.getOption("fullScreen")) toggleFullScreen(self);
  3526. }
  3527. }, false);
  3528. var mode, backdrop;
  3529. if(options.spellChecker !== false) {
  3530. mode = "spell-checker";
  3531. backdrop = options.parsingConfig;
  3532. backdrop.name = "gfm";
  3533. backdrop.gitHubSpice = false;
  3534. CodeMirrorSpellChecker({
  3535. codeMirrorInstance: CodeMirror
  3536. });
  3537. } else {
  3538. mode = options.parsingConfig;
  3539. mode.name = "gfm";
  3540. mode.gitHubSpice = false;
  3541. }
  3542. this.codemirror = CodeMirror.fromTextArea(el, {
  3543. mode: mode,
  3544. backdrop: backdrop,
  3545. theme: "paper",
  3546. tabSize: (options.tabSize != undefined) ? options.tabSize : 2,
  3547. indentUnit: (options.tabSize != undefined) ? options.tabSize : 2,
  3548. indentWithTabs: (options.indentWithTabs === false) ? false : true,
  3549. lineNumbers: false,
  3550. autofocus: (options.autofocus === true) ? true : false,
  3551. extraKeys: keyMaps,
  3552. lineWrapping: (options.lineWrapping === false) ? false : true,
  3553. allowDropFileTypes: ["text/plain"],
  3554. placeholder: options.placeholder || el.getAttribute("placeholder") || "",
  3555. styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : true
  3556. });
  3557. if(options.forceSync === true) {
  3558. var cm = this.codemirror;
  3559. cm.on("change", function() {
  3560. cm.save();
  3561. });
  3562. }
  3563. this.gui = {};
  3564. if(options.toolbar !== false) {
  3565. this.gui.toolbar = this.createToolbar();
  3566. }
  3567. if(options.status !== false) {
  3568. this.gui.statusbar = this.createStatusbar();
  3569. }
  3570. if(options.autosave != undefined && options.autosave.enabled === true) {
  3571. this.autosave();
  3572. }
  3573. this.gui.sideBySide = this.createSideBySide();
  3574. this._rendered = this.element;
  3575. // Fixes CodeMirror bug (#344)
  3576. var temp_cm = this.codemirror;
  3577. setTimeout(function() {
  3578. temp_cm.refresh();
  3579. }.bind(temp_cm), 0);
  3580. };
  3581. // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem throw QuotaExceededError. We're going to detect this and set a variable accordingly.
  3582. function isLocalStorageAvailable() {
  3583. if(typeof localStorage === "object") {
  3584. try {
  3585. localStorage.setItem("smde_localStorage", 1);
  3586. localStorage.removeItem("smde_localStorage");
  3587. } catch(e) {
  3588. return false;
  3589. }
  3590. } else {
  3591. return false;
  3592. }
  3593. return true;
  3594. }
  3595. SimpleMDE.prototype.autosave = function() {
  3596. if(isLocalStorageAvailable()) {
  3597. var simplemde = this;
  3598. if(this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
  3599. console.log("SimpleMDE: You must set a uniqueId to use the autosave feature");
  3600. return;
  3601. }
  3602. if(simplemde.element.form != null && simplemde.element.form != undefined) {
  3603. simplemde.element.form.addEventListener("submit", function() {
  3604. localStorage.removeItem("smde_" + simplemde.options.autosave.uniqueId);
  3605. });
  3606. }
  3607. if(this.options.autosave.loaded !== true) {
  3608. if(typeof localStorage.getItem("smde_" + this.options.autosave.uniqueId) == "string" && localStorage.getItem("smde_" + this.options.autosave.uniqueId) != "") {
  3609. this.codemirror.setValue(localStorage.getItem("smde_" + this.options.autosave.uniqueId));
  3610. this.options.autosave.foundSavedValue = true;
  3611. }
  3612. this.options.autosave.loaded = true;
  3613. }
  3614. localStorage.setItem("smde_" + this.options.autosave.uniqueId, simplemde.value());
  3615. var el = document.getElementById("autosaved");
  3616. if(el != null && el != undefined && el != "") {
  3617. var d = new Date();
  3618. var hh = d.getHours();
  3619. var m = d.getMinutes();
  3620. var dd = "am";
  3621. var h = hh;
  3622. if(h >= 12) {
  3623. h = hh - 12;
  3624. dd = "pm";
  3625. }
  3626. if(h == 0) {
  3627. h = 12;
  3628. }
  3629. m = m < 10 ? "0" + m : m;
  3630. el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd;
  3631. }
  3632. this.autosaveTimeoutId = setTimeout(function() {
  3633. simplemde.autosave();
  3634. }, this.options.autosave.delay || 10000);
  3635. } else {
  3636. console.log("SimpleMDE: localStorage not available, cannot autosave");
  3637. }
  3638. };
  3639. SimpleMDE.prototype.clearAutosavedValue = function() {
  3640. if(isLocalStorageAvailable()) {
  3641. if(this.options.autosave == undefined || this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
  3642. console.log("SimpleMDE: You must set a uniqueId to clear the autosave value");
  3643. return;
  3644. }
  3645. localStorage.removeItem("smde_" + this.options.autosave.uniqueId);
  3646. } else {
  3647. console.log("SimpleMDE: localStorage not available, cannot autosave");
  3648. }
  3649. };
  3650. SimpleMDE.prototype.createSideBySide = function() {
  3651. var cm = this.codemirror;
  3652. var wrapper = cm.getWrapperElement();
  3653. var preview = wrapper.nextSibling;
  3654. if(!preview || !/editor-preview-side/.test(preview.className)) {
  3655. preview = document.createElement("div");
  3656. preview.className = "editor-preview-side";
  3657. wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);
  3658. }
  3659. // Syncs scroll editor -> preview
  3660. var cScroll = false;
  3661. var pScroll = false;
  3662. cm.on("scroll", function(v) {
  3663. if(cScroll) {
  3664. cScroll = false;
  3665. return;
  3666. }
  3667. pScroll = true;
  3668. var height = v.getScrollInfo().height - v.getScrollInfo().clientHeight;
  3669. var ratio = parseFloat(v.getScrollInfo().top) / height;
  3670. var move = (preview.scrollHeight - preview.clientHeight) * ratio;
  3671. preview.scrollTop = move;
  3672. });
  3673. // Syncs scroll preview -> editor
  3674. preview.onscroll = function() {
  3675. if(pScroll) {
  3676. pScroll = false;
  3677. return;
  3678. }
  3679. cScroll = true;
  3680. var height = preview.scrollHeight - preview.clientHeight;
  3681. var ratio = parseFloat(preview.scrollTop) / height;
  3682. var move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
  3683. cm.scrollTo(0, move);
  3684. };
  3685. return preview;
  3686. };
  3687. SimpleMDE.prototype.createToolbar = function(items) {
  3688. items = items || this.options.toolbar;
  3689. if(!items || items.length === 0) {
  3690. return;
  3691. }
  3692. var i;
  3693. for(i = 0; i < items.length; i++) {
  3694. if(toolbarBuiltInButtons[items[i]] != undefined) {
  3695. items[i] = toolbarBuiltInButtons[items[i]];
  3696. }
  3697. }
  3698. var bar = document.createElement("div");
  3699. bar.className = "editor-toolbar";
  3700. var self = this;
  3701. var toolbarData = {};
  3702. self.toolbar = items;
  3703. for(i = 0; i < items.length; i++) {
  3704. if(items[i].name == "guide" && self.options.toolbarGuideIcon === false)
  3705. continue;
  3706. if(self.options.hideIcons && self.options.hideIcons.indexOf(items[i].name) != -1)
  3707. continue;
  3708. // Fullscreen does not work well on mobile devices (even tablets)
  3709. // In the future, hopefully this can be resolved
  3710. if((items[i].name == "fullscreen" || items[i].name == "side-by-side") && isMobile())
  3711. continue;
  3712. // Don't include trailing separators
  3713. if(items[i] === "|") {
  3714. var nonSeparatorIconsFollow = false;
  3715. for(var x = (i + 1); x < items.length; x++) {
  3716. if(items[x] !== "|" && (!self.options.hideIcons || self.options.hideIcons.indexOf(items[x].name) == -1)) {
  3717. nonSeparatorIconsFollow = true;
  3718. }
  3719. }
  3720. if(!nonSeparatorIconsFollow)
  3721. continue;
  3722. }
  3723. // Create the icon and append to the toolbar
  3724. (function(item) {
  3725. var el;
  3726. if(item === "|") {
  3727. el = createSep();
  3728. } else {
  3729. el = createIcon(item, self.options.toolbarTips, self.options.shortcuts);
  3730. }
  3731. // bind events, special for info
  3732. if(item.action) {
  3733. if(typeof item.action === "function") {
  3734. el.onclick = function(e) {
  3735. e.preventDefault();
  3736. item.action(self);
  3737. };
  3738. } else if(typeof item.action === "string") {
  3739. el.href = item.action;
  3740. el.target = "_blank";
  3741. }
  3742. }
  3743. toolbarData[item.name || item] = el;
  3744. bar.appendChild(el);
  3745. })(items[i]);
  3746. }
  3747. self.toolbarElements = toolbarData;
  3748. var cm = this.codemirror;
  3749. cm.on("cursorActivity", function() {
  3750. var stat = getState(cm);
  3751. for(var key in toolbarData) {
  3752. (function(key) {
  3753. var el = toolbarData[key];
  3754. if(stat[key]) {
  3755. el.className += " active";
  3756. } else if(key != "fullscreen" && key != "side-by-side") {
  3757. el.className = el.className.replace(/\s*active\s*/g, "");
  3758. }
  3759. })(key);
  3760. }
  3761. });
  3762. var cmWrapper = cm.getWrapperElement();
  3763. cmWrapper.parentNode.insertBefore(bar, cmWrapper);
  3764. return bar;
  3765. };
  3766. SimpleMDE.prototype.createStatusbar = function(status) {
  3767. // Initialize
  3768. status = status || this.options.status;
  3769. var options = this.options;
  3770. var cm = this.codemirror;
  3771. // Make sure the status variable is valid
  3772. if(!status || status.length === 0)
  3773. return;
  3774. // Set up the built-in items
  3775. var items = [];
  3776. var i, onUpdate, defaultValue;
  3777. for(i = 0; i < status.length; i++) {
  3778. // Reset some values
  3779. onUpdate = undefined;
  3780. defaultValue = undefined;
  3781. // Handle if custom or not
  3782. if(typeof status[i] === "object") {
  3783. items.push({
  3784. className: status[i].className,
  3785. defaultValue: status[i].defaultValue,
  3786. onUpdate: status[i].onUpdate
  3787. });
  3788. } else {
  3789. var name = status[i];
  3790. if(name === "words") {
  3791. defaultValue = function(el) {
  3792. el.innerHTML = wordCount(cm.getValue());
  3793. };
  3794. onUpdate = function(el) {
  3795. el.innerHTML = wordCount(cm.getValue());
  3796. };
  3797. } else if(name === "lines") {
  3798. defaultValue = function(el) {
  3799. el.innerHTML = cm.lineCount();
  3800. };
  3801. onUpdate = function(el) {
  3802. el.innerHTML = cm.lineCount();
  3803. };
  3804. } else if(name === "cursor") {
  3805. defaultValue = function(el) {
  3806. el.innerHTML = "0:0";
  3807. };
  3808. onUpdate = function(el) {
  3809. var pos = cm.getCursor();
  3810. el.innerHTML = pos.line + ":" + pos.ch;
  3811. };
  3812. } else if(name === "autosave") {
  3813. defaultValue = function(el) {
  3814. if(options.autosave != undefined && options.autosave.enabled === true) {
  3815. el.setAttribute("id", "autosaved");
  3816. }
  3817. };
  3818. }
  3819. items.push({
  3820. className: name,
  3821. defaultValue: defaultValue,
  3822. onUpdate: onUpdate
  3823. });
  3824. }
  3825. }
  3826. // Create element for the status bar
  3827. var bar = document.createElement("div");
  3828. bar.className = "editor-statusbar";
  3829. // Create a new span for each item
  3830. for(i = 0; i < items.length; i++) {
  3831. // Store in temporary variable
  3832. var item = items[i];
  3833. // Create span element
  3834. var el = document.createElement("span");
  3835. el.className = item.className;
  3836. // Ensure the defaultValue is a function
  3837. if(typeof item.defaultValue === "function") {
  3838. item.defaultValue(el);
  3839. }
  3840. // Ensure the onUpdate is a function
  3841. if(typeof item.onUpdate === "function") {
  3842. // Create a closure around the span of the current action, then execute the onUpdate handler
  3843. this.codemirror.on("update", (function(el, item) {
  3844. return function() {
  3845. item.onUpdate(el);
  3846. };
  3847. }(el, item)));
  3848. }
  3849. // Append the item to the status bar
  3850. bar.appendChild(el);
  3851. }
  3852. // Insert the status bar into the DOM
  3853. var cmWrapper = this.codemirror.getWrapperElement();
  3854. cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
  3855. return bar;
  3856. };
  3857. /**
  3858. * Get or set the text content.
  3859. */
  3860. SimpleMDE.prototype.value = function(val) {
  3861. if(val === undefined) {
  3862. return this.codemirror.getValue();
  3863. } else {
  3864. this.codemirror.getDoc().setValue(val);
  3865. return this;
  3866. }
  3867. };
  3868. /**
  3869. * Bind static methods for exports.
  3870. */
  3871. SimpleMDE.toggleBold = toggleBold;
  3872. SimpleMDE.toggleItalic = toggleItalic;
  3873. SimpleMDE.toggleStrikethrough = toggleStrikethrough;
  3874. SimpleMDE.toggleBlockquote = toggleBlockquote;
  3875. SimpleMDE.toggleHeadingSmaller = toggleHeadingSmaller;
  3876. SimpleMDE.toggleHeadingBigger = toggleHeadingBigger;
  3877. SimpleMDE.toggleHeading1 = toggleHeading1;
  3878. SimpleMDE.toggleHeading2 = toggleHeading2;
  3879. SimpleMDE.toggleHeading3 = toggleHeading3;
  3880. SimpleMDE.toggleCodeBlock = toggleCodeBlock;
  3881. SimpleMDE.toggleUnorderedList = toggleUnorderedList;
  3882. SimpleMDE.toggleOrderedList = toggleOrderedList;
  3883. SimpleMDE.cleanBlock = cleanBlock;
  3884. SimpleMDE.drawLink = drawLink;
  3885. SimpleMDE.drawImage = drawImage;
  3886. SimpleMDE.drawTable = drawTable;
  3887. SimpleMDE.drawHorizontalRule = drawHorizontalRule;
  3888. SimpleMDE.undo = undo;
  3889. SimpleMDE.redo = redo;
  3890. SimpleMDE.togglePreview = togglePreview;
  3891. SimpleMDE.toggleSideBySide = toggleSideBySide;
  3892. SimpleMDE.toggleFullScreen = toggleFullScreen;
  3893. /**
  3894. * Bind instance methods for exports.
  3895. */
  3896. SimpleMDE.prototype.toggleBold = function() {
  3897. toggleBold(this);
  3898. };
  3899. SimpleMDE.prototype.toggleItalic = function() {
  3900. toggleItalic(this);
  3901. };
  3902. SimpleMDE.prototype.toggleStrikethrough = function() {
  3903. toggleStrikethrough(this);
  3904. };
  3905. SimpleMDE.prototype.toggleBlockquote = function() {
  3906. toggleBlockquote(this);
  3907. };
  3908. SimpleMDE.prototype.toggleHeadingSmaller = function() {
  3909. toggleHeadingSmaller(this);
  3910. };
  3911. SimpleMDE.prototype.toggleHeadingBigger = function() {
  3912. toggleHeadingBigger(this);
  3913. };
  3914. SimpleMDE.prototype.toggleHeading1 = function() {
  3915. toggleHeading1(this);
  3916. };
  3917. SimpleMDE.prototype.toggleHeading2 = function() {
  3918. toggleHeading2(this);
  3919. };
  3920. SimpleMDE.prototype.toggleHeading3 = function() {
  3921. toggleHeading3(this);
  3922. };
  3923. SimpleMDE.prototype.toggleCodeBlock = function() {
  3924. toggleCodeBlock(this);
  3925. };
  3926. SimpleMDE.prototype.toggleUnorderedList = function() {
  3927. toggleUnorderedList(this);
  3928. };
  3929. SimpleMDE.prototype.toggleOrderedList = function() {
  3930. toggleOrderedList(this);
  3931. };
  3932. SimpleMDE.prototype.cleanBlock = function() {
  3933. cleanBlock(this);
  3934. };
  3935. SimpleMDE.prototype.drawLink = function() {
  3936. drawLink(this);
  3937. };
  3938. SimpleMDE.prototype.drawImage = function() {
  3939. drawImage(this);
  3940. };
  3941. SimpleMDE.prototype.drawTable = function() {
  3942. drawTable(this);
  3943. };
  3944. SimpleMDE.prototype.drawHorizontalRule = function() {
  3945. drawHorizontalRule(this);
  3946. };
  3947. SimpleMDE.prototype.undo = function() {
  3948. undo(this);
  3949. };
  3950. SimpleMDE.prototype.redo = function() {
  3951. redo(this);
  3952. };
  3953. SimpleMDE.prototype.togglePreview = function() {
  3954. togglePreview(this);
  3955. };
  3956. SimpleMDE.prototype.toggleSideBySide = function() {
  3957. toggleSideBySide(this);
  3958. };
  3959. SimpleMDE.prototype.toggleFullScreen = function() {
  3960. toggleFullScreen(this);
  3961. };
  3962. SimpleMDE.prototype.isPreviewActive = function() {
  3963. var cm = this.codemirror;
  3964. var wrapper = cm.getWrapperElement();
  3965. var preview = wrapper.lastChild;
  3966. return /editor-preview-active/.test(preview.className);
  3967. };
  3968. SimpleMDE.prototype.isSideBySideActive = function() {
  3969. var cm = this.codemirror;
  3970. var wrapper = cm.getWrapperElement();
  3971. var preview = wrapper.nextSibling;
  3972. return /editor-preview-active-side/.test(preview.className);
  3973. };
  3974. SimpleMDE.prototype.isFullscreenActive = function() {
  3975. var cm = this.codemirror;
  3976. return cm.getOption("fullScreen");
  3977. };
  3978. SimpleMDE.prototype.getState = function() {
  3979. var cm = this.codemirror;
  3980. return getState(cm);
  3981. };
  3982. SimpleMDE.prototype.toTextArea = function() {
  3983. var cm = this.codemirror;
  3984. var wrapper = cm.getWrapperElement();
  3985. if(wrapper.parentNode) {
  3986. if(this.gui.toolbar) {
  3987. wrapper.parentNode.removeChild(this.gui.toolbar);
  3988. }
  3989. if(this.gui.statusbar) {
  3990. wrapper.parentNode.removeChild(this.gui.statusbar);
  3991. }
  3992. if(this.gui.sideBySide) {
  3993. wrapper.parentNode.removeChild(this.gui.sideBySide);
  3994. }
  3995. }
  3996. cm.toTextArea();
  3997. if(this.autosaveTimeoutId) {
  3998. clearTimeout(this.autosaveTimeoutId);
  3999. this.autosaveTimeoutId = undefined;
  4000. this.clearAutosavedValue();
  4001. }
  4002. };
  4003. module.exports = SimpleMDE;
  4004. /***/ }),
  4005. /***/ "4fda":
  4006. /***/ (function(module, exports, __webpack_require__) {
  4007. var getBuiltIn = __webpack_require__("6d7a");
  4008. module.exports = getBuiltIn('navigator', 'userAgent') || '';
  4009. /***/ }),
  4010. /***/ "508f":
  4011. /***/ (function(module, exports, __webpack_require__) {
  4012. // extracted by mini-css-extract-plugin
  4013. /***/ }),
  4014. /***/ "5a9c":
  4015. /***/ (function(module, exports, __webpack_require__) {
  4016. const { defaults } = __webpack_require__("a8a2");
  4017. const {
  4018. rtrim,
  4019. splitCells,
  4020. escape,
  4021. findClosingBracket
  4022. } = __webpack_require__("322c");
  4023. function outputLink(cap, link, raw) {
  4024. const href = link.href;
  4025. const title = link.title ? escape(link.title) : null;
  4026. if (cap[0].charAt(0) !== '!') {
  4027. return {
  4028. type: 'link',
  4029. raw,
  4030. href,
  4031. title,
  4032. text: cap[1]
  4033. };
  4034. } else {
  4035. return {
  4036. type: 'image',
  4037. raw,
  4038. text: escape(cap[1]),
  4039. href,
  4040. title
  4041. };
  4042. }
  4043. }
  4044. /**
  4045. * Tokenizer
  4046. */
  4047. module.exports = class Tokenizer {
  4048. constructor(options) {
  4049. this.options = options || defaults;
  4050. }
  4051. space(src) {
  4052. const cap = this.rules.block.newline.exec(src);
  4053. if (cap) {
  4054. if (cap[0].length > 1) {
  4055. return {
  4056. type: 'space',
  4057. raw: cap[0]
  4058. };
  4059. }
  4060. return { raw: '\n' };
  4061. }
  4062. }
  4063. code(src, tokens) {
  4064. const cap = this.rules.block.code.exec(src);
  4065. if (cap) {
  4066. const lastToken = tokens[tokens.length - 1];
  4067. // An indented code block cannot interrupt a paragraph.
  4068. if (lastToken && lastToken.type === 'paragraph') {
  4069. tokens.pop();
  4070. lastToken.text += '\n' + cap[0].trimRight();
  4071. lastToken.raw += '\n' + cap[0];
  4072. return lastToken;
  4073. } else {
  4074. const text = cap[0].replace(/^ {4}/gm, '');
  4075. return {
  4076. type: 'code',
  4077. raw: cap[0],
  4078. codeBlockStyle: 'indented',
  4079. text: !this.options.pedantic
  4080. ? rtrim(text, '\n')
  4081. : text
  4082. };
  4083. }
  4084. }
  4085. }
  4086. fences(src) {
  4087. const cap = this.rules.block.fences.exec(src);
  4088. if (cap) {
  4089. return {
  4090. type: 'code',
  4091. raw: cap[0],
  4092. lang: cap[2] ? cap[2].trim() : cap[2],
  4093. text: cap[3] || ''
  4094. };
  4095. }
  4096. }
  4097. heading(src) {
  4098. const cap = this.rules.block.heading.exec(src);
  4099. if (cap) {
  4100. return {
  4101. type: 'heading',
  4102. raw: cap[0],
  4103. depth: cap[1].length,
  4104. text: cap[2]
  4105. };
  4106. }
  4107. }
  4108. nptable(src) {
  4109. const cap = this.rules.block.nptable.exec(src);
  4110. if (cap) {
  4111. const item = {
  4112. type: 'table',
  4113. header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
  4114. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  4115. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
  4116. raw: cap[0]
  4117. };
  4118. if (item.header.length === item.align.length) {
  4119. let l = item.align.length;
  4120. let i;
  4121. for (i = 0; i < l; i++) {
  4122. if (/^ *-+: *$/.test(item.align[i])) {
  4123. item.align[i] = 'right';
  4124. } else if (/^ *:-+: *$/.test(item.align[i])) {
  4125. item.align[i] = 'center';
  4126. } else if (/^ *:-+ *$/.test(item.align[i])) {
  4127. item.align[i] = 'left';
  4128. } else {
  4129. item.align[i] = null;
  4130. }
  4131. }
  4132. l = item.cells.length;
  4133. for (i = 0; i < l; i++) {
  4134. item.cells[i] = splitCells(item.cells[i], item.header.length);
  4135. }
  4136. return item;
  4137. }
  4138. }
  4139. }
  4140. hr(src) {
  4141. const cap = this.rules.block.hr.exec(src);
  4142. if (cap) {
  4143. return {
  4144. type: 'hr',
  4145. raw: cap[0]
  4146. };
  4147. }
  4148. }
  4149. blockquote(src) {
  4150. const cap = this.rules.block.blockquote.exec(src);
  4151. if (cap) {
  4152. const text = cap[0].replace(/^ *> ?/gm, '');
  4153. return {
  4154. type: 'blockquote',
  4155. raw: cap[0],
  4156. text
  4157. };
  4158. }
  4159. }
  4160. list(src) {
  4161. const cap = this.rules.block.list.exec(src);
  4162. if (cap) {
  4163. let raw = cap[0];
  4164. const bull = cap[2];
  4165. const isordered = bull.length > 1;
  4166. const list = {
  4167. type: 'list',
  4168. raw,
  4169. ordered: isordered,
  4170. start: isordered ? +bull : '',
  4171. loose: false,
  4172. items: []
  4173. };
  4174. // Get each top-level item.
  4175. const itemMatch = cap[0].match(this.rules.block.item);
  4176. let next = false,
  4177. item,
  4178. space,
  4179. b,
  4180. addBack,
  4181. loose,
  4182. istask,
  4183. ischecked;
  4184. const l = itemMatch.length;
  4185. for (let i = 0; i < l; i++) {
  4186. item = itemMatch[i];
  4187. raw = item;
  4188. // Remove the list item's bullet
  4189. // so it is seen as the next token.
  4190. space = item.length;
  4191. item = item.replace(/^ *([*+-]|\d+\.) */, '');
  4192. // Outdent whatever the
  4193. // list item contains. Hacky.
  4194. if (~item.indexOf('\n ')) {
  4195. space -= item.length;
  4196. item = !this.options.pedantic
  4197. ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
  4198. : item.replace(/^ {1,4}/gm, '');
  4199. }
  4200. // Determine whether the next list item belongs here.
  4201. // Backpedal if it does not belong in this list.
  4202. if (i !== l - 1) {
  4203. b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
  4204. if (bull.length > 1 ? b.length === 1
  4205. : (b.length > 1 || (this.options.smartLists && b !== bull))) {
  4206. addBack = itemMatch.slice(i + 1).join('\n');
  4207. list.raw = list.raw.substring(0, list.raw.length - addBack.length);
  4208. i = l - 1;
  4209. }
  4210. }
  4211. // Determine whether item is loose or not.
  4212. // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
  4213. // for discount behavior.
  4214. loose = next || /\n\n(?!\s*$)/.test(item);
  4215. if (i !== l - 1) {
  4216. next = item.charAt(item.length - 1) === '\n';
  4217. if (!loose) loose = next;
  4218. }
  4219. if (loose) {
  4220. list.loose = true;
  4221. }
  4222. // Check for task list items
  4223. istask = /^\[[ xX]\] /.test(item);
  4224. ischecked = undefined;
  4225. if (istask) {
  4226. ischecked = item[1] !== ' ';
  4227. item = item.replace(/^\[[ xX]\] +/, '');
  4228. }
  4229. list.items.push({
  4230. raw,
  4231. task: istask,
  4232. checked: ischecked,
  4233. loose: loose,
  4234. text: item
  4235. });
  4236. }
  4237. return list;
  4238. }
  4239. }
  4240. html(src) {
  4241. const cap = this.rules.block.html.exec(src);
  4242. if (cap) {
  4243. return {
  4244. type: this.options.sanitize
  4245. ? 'paragraph'
  4246. : 'html',
  4247. raw: cap[0],
  4248. pre: !this.options.sanitizer
  4249. && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
  4250. text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0]
  4251. };
  4252. }
  4253. }
  4254. def(src) {
  4255. const cap = this.rules.block.def.exec(src);
  4256. if (cap) {
  4257. if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
  4258. const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
  4259. return {
  4260. tag,
  4261. raw: cap[0],
  4262. href: cap[2],
  4263. title: cap[3]
  4264. };
  4265. }
  4266. }
  4267. table(src) {
  4268. const cap = this.rules.block.table.exec(src);
  4269. if (cap) {
  4270. const item = {
  4271. type: 'table',
  4272. header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
  4273. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  4274. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
  4275. };
  4276. if (item.header.length === item.align.length) {
  4277. item.raw = cap[0];
  4278. let l = item.align.length;
  4279. let i;
  4280. for (i = 0; i < l; i++) {
  4281. if (/^ *-+: *$/.test(item.align[i])) {
  4282. item.align[i] = 'right';
  4283. } else if (/^ *:-+: *$/.test(item.align[i])) {
  4284. item.align[i] = 'center';
  4285. } else if (/^ *:-+ *$/.test(item.align[i])) {
  4286. item.align[i] = 'left';
  4287. } else {
  4288. item.align[i] = null;
  4289. }
  4290. }
  4291. l = item.cells.length;
  4292. for (i = 0; i < l; i++) {
  4293. item.cells[i] = splitCells(
  4294. item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
  4295. item.header.length);
  4296. }
  4297. return item;
  4298. }
  4299. }
  4300. }
  4301. lheading(src) {
  4302. const cap = this.rules.block.lheading.exec(src);
  4303. if (cap) {
  4304. return {
  4305. type: 'heading',
  4306. raw: cap[0],
  4307. depth: cap[2].charAt(0) === '=' ? 1 : 2,
  4308. text: cap[1]
  4309. };
  4310. }
  4311. }
  4312. paragraph(src) {
  4313. const cap = this.rules.block.paragraph.exec(src);
  4314. if (cap) {
  4315. return {
  4316. type: 'paragraph',
  4317. raw: cap[0],
  4318. text: cap[1].charAt(cap[1].length - 1) === '\n'
  4319. ? cap[1].slice(0, -1)
  4320. : cap[1]
  4321. };
  4322. }
  4323. }
  4324. text(src) {
  4325. const cap = this.rules.block.text.exec(src);
  4326. if (cap) {
  4327. return {
  4328. type: 'text',
  4329. raw: cap[0],
  4330. text: cap[0]
  4331. };
  4332. }
  4333. }
  4334. escape(src) {
  4335. const cap = this.rules.inline.escape.exec(src);
  4336. if (cap) {
  4337. return {
  4338. type: 'escape',
  4339. raw: cap[0],
  4340. text: escape(cap[1])
  4341. };
  4342. }
  4343. }
  4344. tag(src, inLink, inRawBlock) {
  4345. const cap = this.rules.inline.tag.exec(src);
  4346. if (cap) {
  4347. if (!inLink && /^<a /i.test(cap[0])) {
  4348. inLink = true;
  4349. } else if (inLink && /^<\/a>/i.test(cap[0])) {
  4350. inLink = false;
  4351. }
  4352. if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  4353. inRawBlock = true;
  4354. } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  4355. inRawBlock = false;
  4356. }
  4357. return {
  4358. type: this.options.sanitize
  4359. ? 'text'
  4360. : 'html',
  4361. raw: cap[0],
  4362. inLink,
  4363. inRawBlock,
  4364. text: this.options.sanitize
  4365. ? (this.options.sanitizer
  4366. ? this.options.sanitizer(cap[0])
  4367. : escape(cap[0]))
  4368. : cap[0]
  4369. };
  4370. }
  4371. }
  4372. link(src) {
  4373. const cap = this.rules.inline.link.exec(src);
  4374. if (cap) {
  4375. const lastParenIndex = findClosingBracket(cap[2], '()');
  4376. if (lastParenIndex > -1) {
  4377. const start = cap[0].indexOf('!') === 0 ? 5 : 4;
  4378. const linkLen = start + cap[1].length + lastParenIndex;
  4379. cap[2] = cap[2].substring(0, lastParenIndex);
  4380. cap[0] = cap[0].substring(0, linkLen).trim();
  4381. cap[3] = '';
  4382. }
  4383. let href = cap[2];
  4384. let title = '';
  4385. if (this.options.pedantic) {
  4386. const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
  4387. if (link) {
  4388. href = link[1];
  4389. title = link[3];
  4390. } else {
  4391. title = '';
  4392. }
  4393. } else {
  4394. title = cap[3] ? cap[3].slice(1, -1) : '';
  4395. }
  4396. href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
  4397. const token = outputLink(cap, {
  4398. href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
  4399. title: title ? title.replace(this.rules.inline._escapes, '$1') : title
  4400. }, cap[0]);
  4401. return token;
  4402. }
  4403. }
  4404. reflink(src, links) {
  4405. let cap;
  4406. if ((cap = this.rules.inline.reflink.exec(src))
  4407. || (cap = this.rules.inline.nolink.exec(src))) {
  4408. let link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
  4409. link = links[link.toLowerCase()];
  4410. if (!link || !link.href) {
  4411. const text = cap[0].charAt(0);
  4412. return {
  4413. type: 'text',
  4414. raw: text,
  4415. text
  4416. };
  4417. }
  4418. const token = outputLink(cap, link, cap[0]);
  4419. return token;
  4420. }
  4421. }
  4422. strong(src) {
  4423. const cap = this.rules.inline.strong.exec(src);
  4424. if (cap) {
  4425. return {
  4426. type: 'strong',
  4427. raw: cap[0],
  4428. text: cap[4] || cap[3] || cap[2] || cap[1]
  4429. };
  4430. }
  4431. }
  4432. em(src) {
  4433. const cap = this.rules.inline.em.exec(src);
  4434. if (cap) {
  4435. return {
  4436. type: 'em',
  4437. raw: cap[0],
  4438. text: cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]
  4439. };
  4440. }
  4441. }
  4442. codespan(src) {
  4443. const cap = this.rules.inline.code.exec(src);
  4444. if (cap) {
  4445. return {
  4446. type: 'codespan',
  4447. raw: cap[0],
  4448. text: escape(cap[2].trim(), true)
  4449. };
  4450. }
  4451. }
  4452. br(src) {
  4453. const cap = this.rules.inline.br.exec(src);
  4454. if (cap) {
  4455. return {
  4456. type: 'br',
  4457. raw: cap[0]
  4458. };
  4459. }
  4460. }
  4461. del(src) {
  4462. const cap = this.rules.inline.del.exec(src);
  4463. if (cap) {
  4464. return {
  4465. type: 'del',
  4466. raw: cap[0],
  4467. text: cap[1]
  4468. };
  4469. }
  4470. }
  4471. autolink(src, mangle) {
  4472. const cap = this.rules.inline.autolink.exec(src);
  4473. if (cap) {
  4474. let text, href;
  4475. if (cap[2] === '@') {
  4476. text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
  4477. href = 'mailto:' + text;
  4478. } else {
  4479. text = escape(cap[1]);
  4480. href = text;
  4481. }
  4482. return {
  4483. type: 'link',
  4484. raw: cap[0],
  4485. text,
  4486. href,
  4487. tokens: [
  4488. {
  4489. type: 'text',
  4490. raw: text,
  4491. text
  4492. }
  4493. ]
  4494. };
  4495. }
  4496. }
  4497. url(src, mangle) {
  4498. let cap;
  4499. if (cap = this.rules.inline.url.exec(src)) {
  4500. let text, href;
  4501. if (cap[2] === '@') {
  4502. text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
  4503. href = 'mailto:' + text;
  4504. } else {
  4505. // do extended autolink path validation
  4506. let prevCapZero;
  4507. do {
  4508. prevCapZero = cap[0];
  4509. cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
  4510. } while (prevCapZero !== cap[0]);
  4511. text = escape(cap[0]);
  4512. if (cap[1] === 'www.') {
  4513. href = 'http://' + text;
  4514. } else {
  4515. href = text;
  4516. }
  4517. }
  4518. return {
  4519. type: 'link',
  4520. raw: cap[0],
  4521. text,
  4522. href,
  4523. tokens: [
  4524. {
  4525. type: 'text',
  4526. raw: text,
  4527. text
  4528. }
  4529. ]
  4530. };
  4531. }
  4532. }
  4533. inlineText(src, inRawBlock, smartypants) {
  4534. const cap = this.rules.inline.text.exec(src);
  4535. if (cap) {
  4536. let text;
  4537. if (inRawBlock) {
  4538. text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0];
  4539. } else {
  4540. text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
  4541. }
  4542. return {
  4543. type: 'text',
  4544. raw: cap[0],
  4545. text
  4546. };
  4547. }
  4548. }
  4549. };
  4550. /***/ }),
  4551. /***/ "5dfd":
  4552. /***/ (function(module, exports, __webpack_require__) {
  4553. var bind = __webpack_require__("e349");
  4554. var IndexedObject = __webpack_require__("692f");
  4555. var toObject = __webpack_require__("3553");
  4556. var toLength = __webpack_require__("d88d");
  4557. var arraySpeciesCreate = __webpack_require__("1ca1");
  4558. var push = [].push;
  4559. // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
  4560. var createMethod = function (TYPE) {
  4561. var IS_MAP = TYPE == 1;
  4562. var IS_FILTER = TYPE == 2;
  4563. var IS_SOME = TYPE == 3;
  4564. var IS_EVERY = TYPE == 4;
  4565. var IS_FIND_INDEX = TYPE == 6;
  4566. var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
  4567. return function ($this, callbackfn, that, specificCreate) {
  4568. var O = toObject($this);
  4569. var self = IndexedObject(O);
  4570. var boundFunction = bind(callbackfn, that, 3);
  4571. var length = toLength(self.length);
  4572. var index = 0;
  4573. var create = specificCreate || arraySpeciesCreate;
  4574. var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
  4575. var value, result;
  4576. for (;length > index; index++) if (NO_HOLES || index in self) {
  4577. value = self[index];
  4578. result = boundFunction(value, index, O);
  4579. if (TYPE) {
  4580. if (IS_MAP) target[index] = result; // map
  4581. else if (result) switch (TYPE) {
  4582. case 3: return true; // some
  4583. case 5: return value; // find
  4584. case 6: return index; // findIndex
  4585. case 2: push.call(target, value); // filter
  4586. } else if (IS_EVERY) return false; // every
  4587. }
  4588. }
  4589. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
  4590. };
  4591. };
  4592. module.exports = {
  4593. // `Array.prototype.forEach` method
  4594. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  4595. forEach: createMethod(0),
  4596. // `Array.prototype.map` method
  4597. // https://tc39.github.io/ecma262/#sec-array.prototype.map
  4598. map: createMethod(1),
  4599. // `Array.prototype.filter` method
  4600. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  4601. filter: createMethod(2),
  4602. // `Array.prototype.some` method
  4603. // https://tc39.github.io/ecma262/#sec-array.prototype.some
  4604. some: createMethod(3),
  4605. // `Array.prototype.every` method
  4606. // https://tc39.github.io/ecma262/#sec-array.prototype.every
  4607. every: createMethod(4),
  4608. // `Array.prototype.find` method
  4609. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  4610. find: createMethod(5),
  4611. // `Array.prototype.findIndex` method
  4612. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  4613. findIndex: createMethod(6)
  4614. };
  4615. /***/ }),
  4616. /***/ "604f":
  4617. /***/ (function(module, exports, __webpack_require__) {
  4618. var global = __webpack_require__("d890");
  4619. var inspectSource = __webpack_require__("1025");
  4620. var WeakMap = global.WeakMap;
  4621. module.exports = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
  4622. /***/ }),
  4623. /***/ "692f":
  4624. /***/ (function(module, exports, __webpack_require__) {
  4625. var fails = __webpack_require__("efe2");
  4626. var classof = __webpack_require__("2118");
  4627. var split = ''.split;
  4628. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  4629. module.exports = fails(function () {
  4630. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  4631. // eslint-disable-next-line no-prototype-builtins
  4632. return !Object('z').propertyIsEnumerable(0);
  4633. }) ? function (it) {
  4634. return classof(it) == 'String' ? split.call(it, '') : Object(it);
  4635. } : Object;
  4636. /***/ }),
  4637. /***/ "6c31":
  4638. /***/ (function(module, exports, __webpack_require__) {
  4639. const Tokenizer = __webpack_require__("5a9c");
  4640. const { defaults } = __webpack_require__("a8a2");
  4641. const { block, inline } = __webpack_require__("ac30");
  4642. /**
  4643. * smartypants text replacement
  4644. */
  4645. function smartypants(text) {
  4646. return text
  4647. // em-dashes
  4648. .replace(/---/g, '\u2014')
  4649. // en-dashes
  4650. .replace(/--/g, '\u2013')
  4651. // opening singles
  4652. .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
  4653. // closing singles & apostrophes
  4654. .replace(/'/g, '\u2019')
  4655. // opening doubles
  4656. .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
  4657. // closing doubles
  4658. .replace(/"/g, '\u201d')
  4659. // ellipses
  4660. .replace(/\.{3}/g, '\u2026');
  4661. }
  4662. /**
  4663. * mangle email addresses
  4664. */
  4665. function mangle(text) {
  4666. let out = '',
  4667. i,
  4668. ch;
  4669. const l = text.length;
  4670. for (i = 0; i < l; i++) {
  4671. ch = text.charCodeAt(i);
  4672. if (Math.random() > 0.5) {
  4673. ch = 'x' + ch.toString(16);
  4674. }
  4675. out += '&#' + ch + ';';
  4676. }
  4677. return out;
  4678. }
  4679. /**
  4680. * Block Lexer
  4681. */
  4682. module.exports = class Lexer {
  4683. constructor(options) {
  4684. this.tokens = [];
  4685. this.tokens.links = Object.create(null);
  4686. this.options = options || defaults;
  4687. this.options.tokenizer = this.options.tokenizer || new Tokenizer();
  4688. this.tokenizer = this.options.tokenizer;
  4689. this.tokenizer.options = this.options;
  4690. const rules = {
  4691. block: block.normal,
  4692. inline: inline.normal
  4693. };
  4694. if (this.options.pedantic) {
  4695. rules.block = block.pedantic;
  4696. rules.inline = inline.pedantic;
  4697. } else if (this.options.gfm) {
  4698. rules.block = block.gfm;
  4699. if (this.options.breaks) {
  4700. rules.inline = inline.breaks;
  4701. } else {
  4702. rules.inline = inline.gfm;
  4703. }
  4704. }
  4705. this.tokenizer.rules = rules;
  4706. }
  4707. /**
  4708. * Expose Rules
  4709. */
  4710. static get rules() {
  4711. return {
  4712. block,
  4713. inline
  4714. };
  4715. }
  4716. /**
  4717. * Static Lex Method
  4718. */
  4719. static lex(src, options) {
  4720. const lexer = new Lexer(options);
  4721. return lexer.lex(src);
  4722. }
  4723. /**
  4724. * Preprocessing
  4725. */
  4726. lex(src) {
  4727. src = src
  4728. .replace(/\r\n|\r/g, '\n')
  4729. .replace(/\t/g, ' ');
  4730. this.blockTokens(src, this.tokens, true);
  4731. this.inline(this.tokens);
  4732. return this.tokens;
  4733. }
  4734. /**
  4735. * Lexing
  4736. */
  4737. blockTokens(src, tokens = [], top = true) {
  4738. src = src.replace(/^ +$/gm, '');
  4739. let token, i, l;
  4740. while (src) {
  4741. // newline
  4742. if (token = this.tokenizer.space(src)) {
  4743. src = src.substring(token.raw.length);
  4744. if (token.type) {
  4745. tokens.push(token);
  4746. }
  4747. continue;
  4748. }
  4749. // code
  4750. if (token = this.tokenizer.code(src, tokens)) {
  4751. src = src.substring(token.raw.length);
  4752. tokens.push(token);
  4753. continue;
  4754. }
  4755. // fences
  4756. if (token = this.tokenizer.fences(src)) {
  4757. src = src.substring(token.raw.length);
  4758. tokens.push(token);
  4759. continue;
  4760. }
  4761. // heading
  4762. if (token = this.tokenizer.heading(src)) {
  4763. src = src.substring(token.raw.length);
  4764. tokens.push(token);
  4765. continue;
  4766. }
  4767. // table no leading pipe (gfm)
  4768. if (token = this.tokenizer.nptable(src)) {
  4769. src = src.substring(token.raw.length);
  4770. tokens.push(token);
  4771. continue;
  4772. }
  4773. // hr
  4774. if (token = this.tokenizer.hr(src)) {
  4775. src = src.substring(token.raw.length);
  4776. tokens.push(token);
  4777. continue;
  4778. }
  4779. // blockquote
  4780. if (token = this.tokenizer.blockquote(src)) {
  4781. src = src.substring(token.raw.length);
  4782. token.tokens = this.blockTokens(token.text, [], top);
  4783. tokens.push(token);
  4784. continue;
  4785. }
  4786. // list
  4787. if (token = this.tokenizer.list(src)) {
  4788. src = src.substring(token.raw.length);
  4789. l = token.items.length;
  4790. for (i = 0; i < l; i++) {
  4791. token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
  4792. }
  4793. tokens.push(token);
  4794. continue;
  4795. }
  4796. // html
  4797. if (token = this.tokenizer.html(src)) {
  4798. src = src.substring(token.raw.length);
  4799. tokens.push(token);
  4800. continue;
  4801. }
  4802. // def
  4803. if (top && (token = this.tokenizer.def(src))) {
  4804. src = src.substring(token.raw.length);
  4805. if (!this.tokens.links[token.tag]) {
  4806. this.tokens.links[token.tag] = {
  4807. href: token.href,
  4808. title: token.title
  4809. };
  4810. }
  4811. continue;
  4812. }
  4813. // table (gfm)
  4814. if (token = this.tokenizer.table(src)) {
  4815. src = src.substring(token.raw.length);
  4816. tokens.push(token);
  4817. continue;
  4818. }
  4819. // lheading
  4820. if (token = this.tokenizer.lheading(src)) {
  4821. src = src.substring(token.raw.length);
  4822. tokens.push(token);
  4823. continue;
  4824. }
  4825. // top-level paragraph
  4826. if (top && (token = this.tokenizer.paragraph(src))) {
  4827. src = src.substring(token.raw.length);
  4828. tokens.push(token);
  4829. continue;
  4830. }
  4831. // text
  4832. if (token = this.tokenizer.text(src)) {
  4833. src = src.substring(token.raw.length);
  4834. tokens.push(token);
  4835. continue;
  4836. }
  4837. if (src) {
  4838. const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
  4839. if (this.options.silent) {
  4840. console.error(errMsg);
  4841. break;
  4842. } else {
  4843. throw new Error(errMsg);
  4844. }
  4845. }
  4846. }
  4847. return tokens;
  4848. }
  4849. inline(tokens) {
  4850. let i,
  4851. j,
  4852. k,
  4853. l2,
  4854. row,
  4855. token;
  4856. const l = tokens.length;
  4857. for (i = 0; i < l; i++) {
  4858. token = tokens[i];
  4859. switch (token.type) {
  4860. case 'paragraph':
  4861. case 'text':
  4862. case 'heading': {
  4863. token.tokens = [];
  4864. this.inlineTokens(token.text, token.tokens);
  4865. break;
  4866. }
  4867. case 'table': {
  4868. token.tokens = {
  4869. header: [],
  4870. cells: []
  4871. };
  4872. // header
  4873. l2 = token.header.length;
  4874. for (j = 0; j < l2; j++) {
  4875. token.tokens.header[j] = [];
  4876. this.inlineTokens(token.header[j], token.tokens.header[j]);
  4877. }
  4878. // cells
  4879. l2 = token.cells.length;
  4880. for (j = 0; j < l2; j++) {
  4881. row = token.cells[j];
  4882. token.tokens.cells[j] = [];
  4883. for (k = 0; k < row.length; k++) {
  4884. token.tokens.cells[j][k] = [];
  4885. this.inlineTokens(row[k], token.tokens.cells[j][k]);
  4886. }
  4887. }
  4888. break;
  4889. }
  4890. case 'blockquote': {
  4891. this.inline(token.tokens);
  4892. break;
  4893. }
  4894. case 'list': {
  4895. l2 = token.items.length;
  4896. for (j = 0; j < l2; j++) {
  4897. this.inline(token.items[j].tokens);
  4898. }
  4899. break;
  4900. }
  4901. default: {
  4902. // do nothing
  4903. }
  4904. }
  4905. }
  4906. return tokens;
  4907. }
  4908. /**
  4909. * Lexing/Compiling
  4910. */
  4911. inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) {
  4912. let token;
  4913. while (src) {
  4914. // escape
  4915. if (token = this.tokenizer.escape(src)) {
  4916. src = src.substring(token.raw.length);
  4917. tokens.push(token);
  4918. continue;
  4919. }
  4920. // tag
  4921. if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
  4922. src = src.substring(token.raw.length);
  4923. inLink = token.inLink;
  4924. inRawBlock = token.inRawBlock;
  4925. tokens.push(token);
  4926. continue;
  4927. }
  4928. // link
  4929. if (token = this.tokenizer.link(src)) {
  4930. src = src.substring(token.raw.length);
  4931. if (token.type === 'link') {
  4932. token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
  4933. }
  4934. tokens.push(token);
  4935. continue;
  4936. }
  4937. // reflink, nolink
  4938. if (token = this.tokenizer.reflink(src, this.tokens.links)) {
  4939. src = src.substring(token.raw.length);
  4940. if (token.type === 'link') {
  4941. token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
  4942. }
  4943. tokens.push(token);
  4944. continue;
  4945. }
  4946. // strong
  4947. if (token = this.tokenizer.strong(src)) {
  4948. src = src.substring(token.raw.length);
  4949. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  4950. tokens.push(token);
  4951. continue;
  4952. }
  4953. // em
  4954. if (token = this.tokenizer.em(src)) {
  4955. src = src.substring(token.raw.length);
  4956. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  4957. tokens.push(token);
  4958. continue;
  4959. }
  4960. // code
  4961. if (token = this.tokenizer.codespan(src)) {
  4962. src = src.substring(token.raw.length);
  4963. tokens.push(token);
  4964. continue;
  4965. }
  4966. // br
  4967. if (token = this.tokenizer.br(src)) {
  4968. src = src.substring(token.raw.length);
  4969. tokens.push(token);
  4970. continue;
  4971. }
  4972. // del (gfm)
  4973. if (token = this.tokenizer.del(src)) {
  4974. src = src.substring(token.raw.length);
  4975. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  4976. tokens.push(token);
  4977. continue;
  4978. }
  4979. // autolink
  4980. if (token = this.tokenizer.autolink(src, mangle)) {
  4981. src = src.substring(token.raw.length);
  4982. tokens.push(token);
  4983. continue;
  4984. }
  4985. // url (gfm)
  4986. if (!inLink && (token = this.tokenizer.url(src, mangle))) {
  4987. src = src.substring(token.raw.length);
  4988. tokens.push(token);
  4989. continue;
  4990. }
  4991. // text
  4992. if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
  4993. src = src.substring(token.raw.length);
  4994. tokens.push(token);
  4995. continue;
  4996. }
  4997. if (src) {
  4998. const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
  4999. if (this.options.silent) {
  5000. console.error(errMsg);
  5001. break;
  5002. } else {
  5003. throw new Error(errMsg);
  5004. }
  5005. }
  5006. }
  5007. return tokens;
  5008. }
  5009. };
  5010. /***/ }),
  5011. /***/ "6d28":
  5012. /***/ (function(module, exports, __webpack_require__) {
  5013. var IS_PURE = __webpack_require__("9b9d");
  5014. var store = __webpack_require__("3a08");
  5015. (module.exports = function (key, value) {
  5016. return store[key] || (store[key] = value !== undefined ? value : {});
  5017. })('versions', []).push({
  5018. version: '3.6.5',
  5019. mode: IS_PURE ? 'pure' : 'global',
  5020. copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
  5021. });
  5022. /***/ }),
  5023. /***/ "6d51":
  5024. /***/ (function(module, exports, __webpack_require__) {
  5025. var path = __webpack_require__("1b99");
  5026. var has = __webpack_require__("faa8");
  5027. var wrappedWellKnownSymbolModule = __webpack_require__("4350");
  5028. var defineProperty = __webpack_require__("d910").f;
  5029. module.exports = function (NAME) {
  5030. var Symbol = path.Symbol || (path.Symbol = {});
  5031. if (!has(Symbol, NAME)) defineProperty(Symbol, NAME, {
  5032. value: wrappedWellKnownSymbolModule.f(NAME)
  5033. });
  5034. };
  5035. /***/ }),
  5036. /***/ "6d60":
  5037. /***/ (function(module, exports, __webpack_require__) {
  5038. var anObject = __webpack_require__("857c");
  5039. var defineProperties = __webpack_require__("dbe8");
  5040. var enumBugKeys = __webpack_require__("18f6");
  5041. var hiddenKeys = __webpack_require__("d5a8");
  5042. var html = __webpack_require__("6fdf");
  5043. var documentCreateElement = __webpack_require__("ae25");
  5044. var sharedKey = __webpack_require__("7db2");
  5045. var GT = '>';
  5046. var LT = '<';
  5047. var PROTOTYPE = 'prototype';
  5048. var SCRIPT = 'script';
  5049. var IE_PROTO = sharedKey('IE_PROTO');
  5050. var EmptyConstructor = function () { /* empty */ };
  5051. var scriptTag = function (content) {
  5052. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  5053. };
  5054. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  5055. var NullProtoObjectViaActiveX = function (activeXDocument) {
  5056. activeXDocument.write(scriptTag(''));
  5057. activeXDocument.close();
  5058. var temp = activeXDocument.parentWindow.Object;
  5059. activeXDocument = null; // avoid memory leak
  5060. return temp;
  5061. };
  5062. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  5063. var NullProtoObjectViaIFrame = function () {
  5064. // Thrash, waste and sodomy: IE GC bug
  5065. var iframe = documentCreateElement('iframe');
  5066. var JS = 'java' + SCRIPT + ':';
  5067. var iframeDocument;
  5068. iframe.style.display = 'none';
  5069. html.appendChild(iframe);
  5070. // https://github.com/zloirock/core-js/issues/475
  5071. iframe.src = String(JS);
  5072. iframeDocument = iframe.contentWindow.document;
  5073. iframeDocument.open();
  5074. iframeDocument.write(scriptTag('document.F=Object'));
  5075. iframeDocument.close();
  5076. return iframeDocument.F;
  5077. };
  5078. // Check for document.domain and active x support
  5079. // No need to use active x approach when document.domain is not set
  5080. // see https://github.com/es-shims/es5-shim/issues/150
  5081. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  5082. // avoid IE GC bug
  5083. var activeXDocument;
  5084. var NullProtoObject = function () {
  5085. try {
  5086. /* global ActiveXObject */
  5087. activeXDocument = document.domain && new ActiveXObject('htmlfile');
  5088. } catch (error) { /* ignore */ }
  5089. NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
  5090. var length = enumBugKeys.length;
  5091. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  5092. return NullProtoObject();
  5093. };
  5094. hiddenKeys[IE_PROTO] = true;
  5095. // `Object.create` method
  5096. // https://tc39.github.io/ecma262/#sec-object.create
  5097. module.exports = Object.create || function create(O, Properties) {
  5098. var result;
  5099. if (O !== null) {
  5100. EmptyConstructor[PROTOTYPE] = anObject(O);
  5101. result = new EmptyConstructor();
  5102. EmptyConstructor[PROTOTYPE] = null;
  5103. // add "__proto__" for Object.getPrototypeOf polyfill
  5104. result[IE_PROTO] = O;
  5105. } else result = NullProtoObject();
  5106. return Properties === undefined ? result : defineProperties(result, Properties);
  5107. };
  5108. /***/ }),
  5109. /***/ "6d7a":
  5110. /***/ (function(module, exports, __webpack_require__) {
  5111. var path = __webpack_require__("1b99");
  5112. var global = __webpack_require__("d890");
  5113. var aFunction = function (variable) {
  5114. return typeof variable == 'function' ? variable : undefined;
  5115. };
  5116. module.exports = function (namespace, method) {
  5117. return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global[namespace])
  5118. : path[namespace] && path[namespace][method] || global[namespace] && global[namespace][method];
  5119. };
  5120. /***/ }),
  5121. /***/ "6d86":
  5122. /***/ (function(module, exports, __webpack_require__) {
  5123. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  5124. // Distributed under an MIT license: https://codemirror.net/LICENSE
  5125. (function(mod) {
  5126. if (true) // CommonJS
  5127. mod(__webpack_require__("a564"));
  5128. else {}
  5129. })(function(CodeMirror) {
  5130. "use strict";
  5131. CodeMirror.modeInfo = [
  5132. {name: "APL", mime: "text/apl", mode: "apl", ext: ["dyalog", "apl"]},
  5133. {name: "PGP", mimes: ["application/pgp", "application/pgp-encrypted", "application/pgp-keys", "application/pgp-signature"], mode: "asciiarmor", ext: ["asc", "pgp", "sig"]},
  5134. {name: "ASN.1", mime: "text/x-ttcn-asn", mode: "asn.1", ext: ["asn", "asn1"]},
  5135. {name: "Asterisk", mime: "text/x-asterisk", mode: "asterisk", file: /^extensions\.conf$/i},
  5136. {name: "Brainfuck", mime: "text/x-brainfuck", mode: "brainfuck", ext: ["b", "bf"]},
  5137. {name: "C", mime: "text/x-csrc", mode: "clike", ext: ["c", "h", "ino"]},
  5138. {name: "C++", mime: "text/x-c++src", mode: "clike", ext: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"], alias: ["cpp"]},
  5139. {name: "Cobol", mime: "text/x-cobol", mode: "cobol", ext: ["cob", "cpy"]},
  5140. {name: "C#", mime: "text/x-csharp", mode: "clike", ext: ["cs"], alias: ["csharp", "cs"]},
  5141. {name: "Clojure", mime: "text/x-clojure", mode: "clojure", ext: ["clj", "cljc", "cljx"]},
  5142. {name: "ClojureScript", mime: "text/x-clojurescript", mode: "clojure", ext: ["cljs"]},
  5143. {name: "Closure Stylesheets (GSS)", mime: "text/x-gss", mode: "css", ext: ["gss"]},
  5144. {name: "CMake", mime: "text/x-cmake", mode: "cmake", ext: ["cmake", "cmake.in"], file: /^CMakeLists.txt$/},
  5145. {name: "CoffeeScript", mimes: ["application/vnd.coffeescript", "text/coffeescript", "text/x-coffeescript"], mode: "coffeescript", ext: ["coffee"], alias: ["coffee", "coffee-script"]},
  5146. {name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp", ext: ["cl", "lisp", "el"], alias: ["lisp"]},
  5147. {name: "Cypher", mime: "application/x-cypher-query", mode: "cypher", ext: ["cyp", "cypher"]},
  5148. {name: "Cython", mime: "text/x-cython", mode: "python", ext: ["pyx", "pxd", "pxi"]},
  5149. {name: "Crystal", mime: "text/x-crystal", mode: "crystal", ext: ["cr"]},
  5150. {name: "CSS", mime: "text/css", mode: "css", ext: ["css"]},
  5151. {name: "CQL", mime: "text/x-cassandra", mode: "sql", ext: ["cql"]},
  5152. {name: "D", mime: "text/x-d", mode: "d", ext: ["d"]},
  5153. {name: "Dart", mimes: ["application/dart", "text/x-dart"], mode: "dart", ext: ["dart"]},
  5154. {name: "diff", mime: "text/x-diff", mode: "diff", ext: ["diff", "patch"]},
  5155. {name: "Django", mime: "text/x-django", mode: "django"},
  5156. {name: "Dockerfile", mime: "text/x-dockerfile", mode: "dockerfile", file: /^Dockerfile$/},
  5157. {name: "DTD", mime: "application/xml-dtd", mode: "dtd", ext: ["dtd"]},
  5158. {name: "Dylan", mime: "text/x-dylan", mode: "dylan", ext: ["dylan", "dyl", "intr"]},
  5159. {name: "EBNF", mime: "text/x-ebnf", mode: "ebnf"},
  5160. {name: "ECL", mime: "text/x-ecl", mode: "ecl", ext: ["ecl"]},
  5161. {name: "edn", mime: "application/edn", mode: "clojure", ext: ["edn"]},
  5162. {name: "Eiffel", mime: "text/x-eiffel", mode: "eiffel", ext: ["e"]},
  5163. {name: "Elm", mime: "text/x-elm", mode: "elm", ext: ["elm"]},
  5164. {name: "Embedded Javascript", mime: "application/x-ejs", mode: "htmlembedded", ext: ["ejs"]},
  5165. {name: "Embedded Ruby", mime: "application/x-erb", mode: "htmlembedded", ext: ["erb"]},
  5166. {name: "Erlang", mime: "text/x-erlang", mode: "erlang", ext: ["erl"]},
  5167. {name: "Esper", mime: "text/x-esper", mode: "sql"},
  5168. {name: "Factor", mime: "text/x-factor", mode: "factor", ext: ["factor"]},
  5169. {name: "FCL", mime: "text/x-fcl", mode: "fcl"},
  5170. {name: "Forth", mime: "text/x-forth", mode: "forth", ext: ["forth", "fth", "4th"]},
  5171. {name: "Fortran", mime: "text/x-fortran", mode: "fortran", ext: ["f", "for", "f77", "f90", "f95"]},
  5172. {name: "F#", mime: "text/x-fsharp", mode: "mllike", ext: ["fs"], alias: ["fsharp"]},
  5173. {name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]},
  5174. {name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]},
  5175. {name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history).md$/i},
  5176. {name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]},
  5177. {name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy", "gradle"], file: /^Jenkinsfile$/},
  5178. {name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]},
  5179. {name: "Haskell", mime: "text/x-haskell", mode: "haskell", ext: ["hs"]},
  5180. {name: "Haskell (Literate)", mime: "text/x-literate-haskell", mode: "haskell-literate", ext: ["lhs"]},
  5181. {name: "Haxe", mime: "text/x-haxe", mode: "haxe", ext: ["hx"]},
  5182. {name: "HXML", mime: "text/x-hxml", mode: "haxe", ext: ["hxml"]},
  5183. {name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded", ext: ["aspx"], alias: ["asp", "aspx"]},
  5184. {name: "HTML", mime: "text/html", mode: "htmlmixed", ext: ["html", "htm", "handlebars", "hbs"], alias: ["xhtml"]},
  5185. {name: "HTTP", mime: "message/http", mode: "http"},
  5186. {name: "IDL", mime: "text/x-idl", mode: "idl", ext: ["pro"]},
  5187. {name: "Pug", mime: "text/x-pug", mode: "pug", ext: ["jade", "pug"], alias: ["jade"]},
  5188. {name: "Java", mime: "text/x-java", mode: "clike", ext: ["java"]},
  5189. {name: "Java Server Pages", mime: "application/x-jsp", mode: "htmlembedded", ext: ["jsp"], alias: ["jsp"]},
  5190. {name: "JavaScript", mimes: ["text/javascript", "text/ecmascript", "application/javascript", "application/x-javascript", "application/ecmascript"],
  5191. mode: "javascript", ext: ["js"], alias: ["ecmascript", "js", "node"]},
  5192. {name: "JSON", mimes: ["application/json", "application/x-json"], mode: "javascript", ext: ["json", "map"], alias: ["json5"]},
  5193. {name: "JSON-LD", mime: "application/ld+json", mode: "javascript", ext: ["jsonld"], alias: ["jsonld"]},
  5194. {name: "JSX", mime: "text/jsx", mode: "jsx", ext: ["jsx"]},
  5195. {name: "Jinja2", mime: "text/jinja2", mode: "jinja2", ext: ["j2", "jinja", "jinja2"]},
  5196. {name: "Julia", mime: "text/x-julia", mode: "julia", ext: ["jl"]},
  5197. {name: "Kotlin", mime: "text/x-kotlin", mode: "clike", ext: ["kt"]},
  5198. {name: "LESS", mime: "text/x-less", mode: "css", ext: ["less"]},
  5199. {name: "LiveScript", mime: "text/x-livescript", mode: "livescript", ext: ["ls"], alias: ["ls"]},
  5200. {name: "Lua", mime: "text/x-lua", mode: "lua", ext: ["lua"]},
  5201. {name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]},
  5202. {name: "mIRC", mime: "text/mirc", mode: "mirc"},
  5203. {name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"},
  5204. {name: "Mathematica", mime: "text/x-mathematica", mode: "mathematica", ext: ["m", "nb", "wl", "wls"]},
  5205. {name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
  5206. {name: "MUMPS", mime: "text/x-mumps", mode: "mumps", ext: ["mps"]},
  5207. {name: "MS SQL", mime: "text/x-mssql", mode: "sql"},
  5208. {name: "mbox", mime: "application/mbox", mode: "mbox", ext: ["mbox"]},
  5209. {name: "MySQL", mime: "text/x-mysql", mode: "sql"},
  5210. {name: "Nginx", mime: "text/x-nginx-conf", mode: "nginx", file: /nginx.*\.conf$/i},
  5211. {name: "NSIS", mime: "text/x-nsis", mode: "nsis", ext: ["nsh", "nsi"]},
  5212. {name: "NTriples", mimes: ["application/n-triples", "application/n-quads", "text/n-triples"],
  5213. mode: "ntriples", ext: ["nt", "nq"]},
  5214. {name: "Objective-C", mime: "text/x-objectivec", mode: "clike", ext: ["m"], alias: ["objective-c", "objc"]},
  5215. {name: "Objective-C++", mime: "text/x-objectivec++", mode: "clike", ext: ["mm"], alias: ["objective-c++", "objc++"]},
  5216. {name: "OCaml", mime: "text/x-ocaml", mode: "mllike", ext: ["ml", "mli", "mll", "mly"]},
  5217. {name: "Octave", mime: "text/x-octave", mode: "octave", ext: ["m"]},
  5218. {name: "Oz", mime: "text/x-oz", mode: "oz", ext: ["oz"]},
  5219. {name: "Pascal", mime: "text/x-pascal", mode: "pascal", ext: ["p", "pas"]},
  5220. {name: "PEG.js", mime: "null", mode: "pegjs", ext: ["jsonld"]},
  5221. {name: "Perl", mime: "text/x-perl", mode: "perl", ext: ["pl", "pm"]},
  5222. {name: "PHP", mimes: ["text/x-php", "application/x-httpd-php", "application/x-httpd-php-open"], mode: "php", ext: ["php", "php3", "php4", "php5", "php7", "phtml"]},
  5223. {name: "Pig", mime: "text/x-pig", mode: "pig", ext: ["pig"]},
  5224. {name: "Plain Text", mime: "text/plain", mode: "null", ext: ["txt", "text", "conf", "def", "list", "log"]},
  5225. {name: "PLSQL", mime: "text/x-plsql", mode: "sql", ext: ["pls"]},
  5226. {name: "PostgreSQL", mime: "text/x-pgsql", mode: "sql"},
  5227. {name: "PowerShell", mime: "application/x-powershell", mode: "powershell", ext: ["ps1", "psd1", "psm1"]},
  5228. {name: "Properties files", mime: "text/x-properties", mode: "properties", ext: ["properties", "ini", "in"], alias: ["ini", "properties"]},
  5229. {name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]},
  5230. {name: "Python", mime: "text/x-python", mode: "python", ext: ["BUILD", "bzl", "py", "pyw"], file: /^(BUCK|BUILD)$/},
  5231. {name: "Puppet", mime: "text/x-puppet", mode: "puppet", ext: ["pp"]},
  5232. {name: "Q", mime: "text/x-q", mode: "q", ext: ["q"]},
  5233. {name: "R", mime: "text/x-rsrc", mode: "r", ext: ["r", "R"], alias: ["rscript"]},
  5234. {name: "reStructuredText", mime: "text/x-rst", mode: "rst", ext: ["rst"], alias: ["rst"]},
  5235. {name: "RPM Changes", mime: "text/x-rpm-changes", mode: "rpm"},
  5236. {name: "RPM Spec", mime: "text/x-rpm-spec", mode: "rpm", ext: ["spec"]},
  5237. {name: "Ruby", mime: "text/x-ruby", mode: "ruby", ext: ["rb"], alias: ["jruby", "macruby", "rake", "rb", "rbx"]},
  5238. {name: "Rust", mime: "text/x-rustsrc", mode: "rust", ext: ["rs"]},
  5239. {name: "SAS", mime: "text/x-sas", mode: "sas", ext: ["sas"]},
  5240. {name: "Sass", mime: "text/x-sass", mode: "sass", ext: ["sass"]},
  5241. {name: "Scala", mime: "text/x-scala", mode: "clike", ext: ["scala"]},
  5242. {name: "Scheme", mime: "text/x-scheme", mode: "scheme", ext: ["scm", "ss"]},
  5243. {name: "SCSS", mime: "text/x-scss", mode: "css", ext: ["scss"]},
  5244. {name: "Shell", mimes: ["text/x-sh", "application/x-sh"], mode: "shell", ext: ["sh", "ksh", "bash"], alias: ["bash", "sh", "zsh"], file: /^PKGBUILD$/},
  5245. {name: "Sieve", mime: "application/sieve", mode: "sieve", ext: ["siv", "sieve"]},
  5246. {name: "Slim", mimes: ["text/x-slim", "application/x-slim"], mode: "slim", ext: ["slim"]},
  5247. {name: "Smalltalk", mime: "text/x-stsrc", mode: "smalltalk", ext: ["st"]},
  5248. {name: "Smarty", mime: "text/x-smarty", mode: "smarty", ext: ["tpl"]},
  5249. {name: "Solr", mime: "text/x-solr", mode: "solr"},
  5250. {name: "SML", mime: "text/x-sml", mode: "mllike", ext: ["sml", "sig", "fun", "smackspec"]},
  5251. {name: "Soy", mime: "text/x-soy", mode: "soy", ext: ["soy"], alias: ["closure template"]},
  5252. {name: "SPARQL", mime: "application/sparql-query", mode: "sparql", ext: ["rq", "sparql"], alias: ["sparul"]},
  5253. {name: "Spreadsheet", mime: "text/x-spreadsheet", mode: "spreadsheet", alias: ["excel", "formula"]},
  5254. {name: "SQL", mime: "text/x-sql", mode: "sql", ext: ["sql"]},
  5255. {name: "SQLite", mime: "text/x-sqlite", mode: "sql"},
  5256. {name: "Squirrel", mime: "text/x-squirrel", mode: "clike", ext: ["nut"]},
  5257. {name: "Stylus", mime: "text/x-styl", mode: "stylus", ext: ["styl"]},
  5258. {name: "Swift", mime: "text/x-swift", mode: "swift", ext: ["swift"]},
  5259. {name: "sTeX", mime: "text/x-stex", mode: "stex"},
  5260. {name: "LaTeX", mime: "text/x-latex", mode: "stex", ext: ["text", "ltx", "tex"], alias: ["tex"]},
  5261. {name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog", ext: ["v", "sv", "svh"]},
  5262. {name: "Tcl", mime: "text/x-tcl", mode: "tcl", ext: ["tcl"]},
  5263. {name: "Textile", mime: "text/x-textile", mode: "textile", ext: ["textile"]},
  5264. {name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
  5265. {name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
  5266. {name: "TOML", mime: "text/x-toml", mode: "toml", ext: ["toml"]},
  5267. {name: "Tornado", mime: "text/x-tornado", mode: "tornado"},
  5268. {name: "troff", mime: "text/troff", mode: "troff", ext: ["1", "2", "3", "4", "5", "6", "7", "8", "9"]},
  5269. {name: "TTCN", mime: "text/x-ttcn", mode: "ttcn", ext: ["ttcn", "ttcn3", "ttcnpp"]},
  5270. {name: "TTCN_CFG", mime: "text/x-ttcn-cfg", mode: "ttcn-cfg", ext: ["cfg"]},
  5271. {name: "Turtle", mime: "text/turtle", mode: "turtle", ext: ["ttl"]},
  5272. {name: "TypeScript", mime: "application/typescript", mode: "javascript", ext: ["ts"], alias: ["ts"]},
  5273. {name: "TypeScript-JSX", mime: "text/typescript-jsx", mode: "jsx", ext: ["tsx"], alias: ["tsx"]},
  5274. {name: "Twig", mime: "text/x-twig", mode: "twig"},
  5275. {name: "Web IDL", mime: "text/x-webidl", mode: "webidl", ext: ["webidl"]},
  5276. {name: "VB.NET", mime: "text/x-vb", mode: "vb", ext: ["vb"]},
  5277. {name: "VBScript", mime: "text/vbscript", mode: "vbscript", ext: ["vbs"]},
  5278. {name: "Velocity", mime: "text/velocity", mode: "velocity", ext: ["vtl"]},
  5279. {name: "Verilog", mime: "text/x-verilog", mode: "verilog", ext: ["v"]},
  5280. {name: "VHDL", mime: "text/x-vhdl", mode: "vhdl", ext: ["vhd", "vhdl"]},
  5281. {name: "Vue.js Component", mimes: ["script/x-vue", "text/x-vue"], mode: "vue", ext: ["vue"]},
  5282. {name: "XML", mimes: ["application/xml", "text/xml"], mode: "xml", ext: ["xml", "xsl", "xsd", "svg"], alias: ["rss", "wsdl", "xsd"]},
  5283. {name: "XQuery", mime: "application/xquery", mode: "xquery", ext: ["xy", "xquery"]},
  5284. {name: "Yacas", mime: "text/x-yacas", mode: "yacas", ext: ["ys"]},
  5285. {name: "YAML", mimes: ["text/x-yaml", "text/yaml"], mode: "yaml", ext: ["yaml", "yml"], alias: ["yml"]},
  5286. {name: "Z80", mime: "text/x-z80", mode: "z80", ext: ["z80"]},
  5287. {name: "mscgen", mime: "text/x-mscgen", mode: "mscgen", ext: ["mscgen", "mscin", "msc"]},
  5288. {name: "xu", mime: "text/x-xu", mode: "mscgen", ext: ["xu"]},
  5289. {name: "msgenny", mime: "text/x-msgenny", mode: "mscgen", ext: ["msgenny"]}
  5290. ];
  5291. // Ensure all modes have a mime property for backwards compatibility
  5292. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5293. var info = CodeMirror.modeInfo[i];
  5294. if (info.mimes) info.mime = info.mimes[0];
  5295. }
  5296. CodeMirror.findModeByMIME = function(mime) {
  5297. mime = mime.toLowerCase();
  5298. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5299. var info = CodeMirror.modeInfo[i];
  5300. if (info.mime == mime) return info;
  5301. if (info.mimes) for (var j = 0; j < info.mimes.length; j++)
  5302. if (info.mimes[j] == mime) return info;
  5303. }
  5304. if (/\+xml$/.test(mime)) return CodeMirror.findModeByMIME("application/xml")
  5305. if (/\+json$/.test(mime)) return CodeMirror.findModeByMIME("application/json")
  5306. };
  5307. CodeMirror.findModeByExtension = function(ext) {
  5308. ext = ext.toLowerCase();
  5309. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5310. var info = CodeMirror.modeInfo[i];
  5311. if (info.ext) for (var j = 0; j < info.ext.length; j++)
  5312. if (info.ext[j] == ext) return info;
  5313. }
  5314. };
  5315. CodeMirror.findModeByFileName = function(filename) {
  5316. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5317. var info = CodeMirror.modeInfo[i];
  5318. if (info.file && info.file.test(filename)) return info;
  5319. }
  5320. var dot = filename.lastIndexOf(".");
  5321. var ext = dot > -1 && filename.substring(dot + 1, filename.length);
  5322. if (ext) return CodeMirror.findModeByExtension(ext);
  5323. };
  5324. CodeMirror.findModeByName = function(name) {
  5325. name = name.toLowerCase();
  5326. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5327. var info = CodeMirror.modeInfo[i];
  5328. if (info.name.toLowerCase() == name) return info;
  5329. if (info.alias) for (var j = 0; j < info.alias.length; j++)
  5330. if (info.alias[j].toLowerCase() == name) return info;
  5331. }
  5332. };
  5333. });
  5334. /***/ }),
  5335. /***/ "6fdf":
  5336. /***/ (function(module, exports, __webpack_require__) {
  5337. var getBuiltIn = __webpack_require__("6d7a");
  5338. module.exports = getBuiltIn('document', 'documentElement');
  5339. /***/ }),
  5340. /***/ "74cb":
  5341. /***/ (function(module, exports, __webpack_require__) {
  5342. var NATIVE_SYMBOL = __webpack_require__("c54b");
  5343. module.exports = NATIVE_SYMBOL
  5344. // eslint-disable-next-line no-undef
  5345. && !Symbol.sham
  5346. // eslint-disable-next-line no-undef
  5347. && typeof Symbol.iterator == 'symbol';
  5348. /***/ }),
  5349. /***/ "74e7":
  5350. /***/ (function(module, exports, __webpack_require__) {
  5351. var classof = __webpack_require__("2118");
  5352. // `IsArray` abstract operation
  5353. // https://tc39.github.io/ecma262/#sec-isarray
  5354. module.exports = Array.isArray || function isArray(arg) {
  5355. return classof(arg) == 'Array';
  5356. };
  5357. /***/ }),
  5358. /***/ "7727":
  5359. /***/ (function(module, exports, __webpack_require__) {
  5360. const Renderer = __webpack_require__("155c");
  5361. const TextRenderer = __webpack_require__("f5ef");
  5362. const Slugger = __webpack_require__("05cd");
  5363. const { defaults } = __webpack_require__("a8a2");
  5364. const {
  5365. unescape
  5366. } = __webpack_require__("322c");
  5367. /**
  5368. * Parsing & Compiling
  5369. */
  5370. module.exports = class Parser {
  5371. constructor(options) {
  5372. this.options = options || defaults;
  5373. this.options.renderer = this.options.renderer || new Renderer();
  5374. this.renderer = this.options.renderer;
  5375. this.renderer.options = this.options;
  5376. this.textRenderer = new TextRenderer();
  5377. this.slugger = new Slugger();
  5378. }
  5379. /**
  5380. * Static Parse Method
  5381. */
  5382. static parse(tokens, options) {
  5383. const parser = new Parser(options);
  5384. return parser.parse(tokens);
  5385. }
  5386. /**
  5387. * Parse Loop
  5388. */
  5389. parse(tokens, top = true) {
  5390. let out = '',
  5391. i,
  5392. j,
  5393. k,
  5394. l2,
  5395. l3,
  5396. row,
  5397. cell,
  5398. header,
  5399. body,
  5400. token,
  5401. ordered,
  5402. start,
  5403. loose,
  5404. itemBody,
  5405. item,
  5406. checked,
  5407. task,
  5408. checkbox;
  5409. const l = tokens.length;
  5410. for (i = 0; i < l; i++) {
  5411. token = tokens[i];
  5412. switch (token.type) {
  5413. case 'space': {
  5414. continue;
  5415. }
  5416. case 'hr': {
  5417. out += this.renderer.hr();
  5418. continue;
  5419. }
  5420. case 'heading': {
  5421. out += this.renderer.heading(
  5422. this.parseInline(token.tokens),
  5423. token.depth,
  5424. unescape(this.parseInline(token.tokens, this.textRenderer)),
  5425. this.slugger);
  5426. continue;
  5427. }
  5428. case 'code': {
  5429. out += this.renderer.code(token.text,
  5430. token.lang,
  5431. token.escaped);
  5432. continue;
  5433. }
  5434. case 'table': {
  5435. header = '';
  5436. // header
  5437. cell = '';
  5438. l2 = token.header.length;
  5439. for (j = 0; j < l2; j++) {
  5440. cell += this.renderer.tablecell(
  5441. this.parseInline(token.tokens.header[j]),
  5442. { header: true, align: token.align[j] }
  5443. );
  5444. }
  5445. header += this.renderer.tablerow(cell);
  5446. body = '';
  5447. l2 = token.cells.length;
  5448. for (j = 0; j < l2; j++) {
  5449. row = token.tokens.cells[j];
  5450. cell = '';
  5451. l3 = row.length;
  5452. for (k = 0; k < l3; k++) {
  5453. cell += this.renderer.tablecell(
  5454. this.parseInline(row[k]),
  5455. { header: false, align: token.align[k] }
  5456. );
  5457. }
  5458. body += this.renderer.tablerow(cell);
  5459. }
  5460. out += this.renderer.table(header, body);
  5461. continue;
  5462. }
  5463. case 'blockquote': {
  5464. body = this.parse(token.tokens);
  5465. out += this.renderer.blockquote(body);
  5466. continue;
  5467. }
  5468. case 'list': {
  5469. ordered = token.ordered;
  5470. start = token.start;
  5471. loose = token.loose;
  5472. l2 = token.items.length;
  5473. body = '';
  5474. for (j = 0; j < l2; j++) {
  5475. item = token.items[j];
  5476. checked = item.checked;
  5477. task = item.task;
  5478. itemBody = '';
  5479. if (item.task) {
  5480. checkbox = this.renderer.checkbox(checked);
  5481. if (loose) {
  5482. if (item.tokens[0].type === 'text') {
  5483. item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
  5484. if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
  5485. item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
  5486. }
  5487. } else {
  5488. item.tokens.unshift({
  5489. type: 'text',
  5490. text: checkbox
  5491. });
  5492. }
  5493. } else {
  5494. itemBody += checkbox;
  5495. }
  5496. }
  5497. itemBody += this.parse(item.tokens, loose);
  5498. body += this.renderer.listitem(itemBody, task, checked);
  5499. }
  5500. out += this.renderer.list(body, ordered, start);
  5501. continue;
  5502. }
  5503. case 'html': {
  5504. // TODO parse inline content if parameter markdown=1
  5505. out += this.renderer.html(token.text);
  5506. continue;
  5507. }
  5508. case 'paragraph': {
  5509. out += this.renderer.paragraph(this.parseInline(token.tokens));
  5510. continue;
  5511. }
  5512. case 'text': {
  5513. body = token.tokens ? this.parseInline(token.tokens) : token.text;
  5514. while (i + 1 < l && tokens[i + 1].type === 'text') {
  5515. token = tokens[++i];
  5516. body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
  5517. }
  5518. out += top ? this.renderer.paragraph(body) : body;
  5519. continue;
  5520. }
  5521. default: {
  5522. const errMsg = 'Token with "' + token.type + '" type was not found.';
  5523. if (this.options.silent) {
  5524. console.error(errMsg);
  5525. return;
  5526. } else {
  5527. throw new Error(errMsg);
  5528. }
  5529. }
  5530. }
  5531. }
  5532. return out;
  5533. }
  5534. /**
  5535. * Parse Inline Tokens
  5536. */
  5537. parseInline(tokens, renderer) {
  5538. renderer = renderer || this.renderer;
  5539. let out = '',
  5540. i,
  5541. token;
  5542. const l = tokens.length;
  5543. for (i = 0; i < l; i++) {
  5544. token = tokens[i];
  5545. switch (token.type) {
  5546. case 'escape': {
  5547. out += renderer.text(token.text);
  5548. break;
  5549. }
  5550. case 'html': {
  5551. out += renderer.html(token.text);
  5552. break;
  5553. }
  5554. case 'link': {
  5555. out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
  5556. break;
  5557. }
  5558. case 'image': {
  5559. out += renderer.image(token.href, token.title, token.text);
  5560. break;
  5561. }
  5562. case 'strong': {
  5563. out += renderer.strong(this.parseInline(token.tokens, renderer));
  5564. break;
  5565. }
  5566. case 'em': {
  5567. out += renderer.em(this.parseInline(token.tokens, renderer));
  5568. break;
  5569. }
  5570. case 'codespan': {
  5571. out += renderer.codespan(token.text);
  5572. break;
  5573. }
  5574. case 'br': {
  5575. out += renderer.br();
  5576. break;
  5577. }
  5578. case 'del': {
  5579. out += renderer.del(this.parseInline(token.tokens, renderer));
  5580. break;
  5581. }
  5582. case 'text': {
  5583. out += renderer.text(token.text);
  5584. break;
  5585. }
  5586. default: {
  5587. const errMsg = 'Token with "' + token.type + '" type was not found.';
  5588. if (this.options.silent) {
  5589. console.error(errMsg);
  5590. return;
  5591. } else {
  5592. throw new Error(errMsg);
  5593. }
  5594. }
  5595. }
  5596. }
  5597. return out;
  5598. }
  5599. };
  5600. /***/ }),
  5601. /***/ "7899":
  5602. /***/ (function(module, exports, __webpack_require__) {
  5603. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  5604. // Distributed under an MIT license: https://codemirror.net/LICENSE
  5605. (function(mod) {
  5606. if (true) // CommonJS
  5607. mod(__webpack_require__("a564"));
  5608. else {}
  5609. })(function(CodeMirror) {
  5610. "use strict";
  5611. var listRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/,
  5612. emptyListRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/,
  5613. unorderedListRE = /[*+-]\s/;
  5614. CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
  5615. if (cm.getOption("disableInput")) return CodeMirror.Pass;
  5616. var ranges = cm.listSelections(), replacements = [];
  5617. for (var i = 0; i < ranges.length; i++) {
  5618. var pos = ranges[i].head;
  5619. // If we're not in Markdown mode, fall back to normal newlineAndIndent
  5620. var eolState = cm.getStateAfter(pos.line);
  5621. var inner = CodeMirror.innerMode(cm.getMode(), eolState);
  5622. if (inner.mode.name !== "markdown") {
  5623. cm.execCommand("newlineAndIndent");
  5624. return;
  5625. } else {
  5626. eolState = inner.state;
  5627. }
  5628. var inList = eolState.list !== false;
  5629. var inQuote = eolState.quote !== 0;
  5630. var line = cm.getLine(pos.line), match = listRE.exec(line);
  5631. var cursorBeforeBullet = /^\s*$/.test(line.slice(0, pos.ch));
  5632. if (!ranges[i].empty() || (!inList && !inQuote) || !match || cursorBeforeBullet) {
  5633. cm.execCommand("newlineAndIndent");
  5634. return;
  5635. }
  5636. if (emptyListRE.test(line)) {
  5637. var endOfQuote = inQuote && />\s*$/.test(line)
  5638. var endOfList = !/>\s*$/.test(line)
  5639. if (endOfQuote || endOfList) cm.replaceRange("", {
  5640. line: pos.line, ch: 0
  5641. }, {
  5642. line: pos.line, ch: pos.ch + 1
  5643. });
  5644. replacements[i] = "\n";
  5645. } else {
  5646. var indent = match[1], after = match[5];
  5647. var numbered = !(unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0);
  5648. var bullet = numbered ? (parseInt(match[3], 10) + 1) + match[4] : match[2].replace("x", " ");
  5649. replacements[i] = "\n" + indent + bullet + after;
  5650. if (numbered) incrementRemainingMarkdownListNumbers(cm, pos);
  5651. }
  5652. }
  5653. cm.replaceSelections(replacements);
  5654. };
  5655. // Auto-updating Markdown list numbers when a new item is added to the
  5656. // middle of a list
  5657. function incrementRemainingMarkdownListNumbers(cm, pos) {
  5658. var startLine = pos.line, lookAhead = 0, skipCount = 0;
  5659. var startItem = listRE.exec(cm.getLine(startLine)), startIndent = startItem[1];
  5660. do {
  5661. lookAhead += 1;
  5662. var nextLineNumber = startLine + lookAhead;
  5663. var nextLine = cm.getLine(nextLineNumber), nextItem = listRE.exec(nextLine);
  5664. if (nextItem) {
  5665. var nextIndent = nextItem[1];
  5666. var newNumber = (parseInt(startItem[3], 10) + lookAhead - skipCount);
  5667. var nextNumber = (parseInt(nextItem[3], 10)), itemNumber = nextNumber;
  5668. if (startIndent === nextIndent && !isNaN(nextNumber)) {
  5669. if (newNumber === nextNumber) itemNumber = nextNumber + 1;
  5670. if (newNumber > nextNumber) itemNumber = newNumber + 1;
  5671. cm.replaceRange(
  5672. nextLine.replace(listRE, nextIndent + itemNumber + nextItem[4] + nextItem[5]),
  5673. {
  5674. line: nextLineNumber, ch: 0
  5675. }, {
  5676. line: nextLineNumber, ch: nextLine.length
  5677. });
  5678. } else {
  5679. if (startIndent.length > nextIndent.length) return;
  5680. // This doesn't run if the next line immediatley indents, as it is
  5681. // not clear of the users intention (new indented item or same level)
  5682. if ((startIndent.length < nextIndent.length) && (lookAhead === 1)) return;
  5683. skipCount += 1;
  5684. }
  5685. }
  5686. } while (nextItem);
  5687. }
  5688. });
  5689. /***/ }),
  5690. /***/ "7db2":
  5691. /***/ (function(module, exports, __webpack_require__) {
  5692. var shared = __webpack_require__("6d28");
  5693. var uid = __webpack_require__("7e8b");
  5694. var keys = shared('keys');
  5695. module.exports = function (key) {
  5696. return keys[key] || (keys[key] = uid(key));
  5697. };
  5698. /***/ }),
  5699. /***/ "7e8b":
  5700. /***/ (function(module, exports) {
  5701. var id = 0;
  5702. var postfix = Math.random();
  5703. module.exports = function (key) {
  5704. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  5705. };
  5706. /***/ }),
  5707. /***/ "857c":
  5708. /***/ (function(module, exports, __webpack_require__) {
  5709. var isObject = __webpack_require__("a719");
  5710. module.exports = function (it) {
  5711. if (!isObject(it)) {
  5712. throw TypeError(String(it) + ' is not an object');
  5713. } return it;
  5714. };
  5715. /***/ }),
  5716. /***/ "8d44":
  5717. /***/ (function(module, exports, __webpack_require__) {
  5718. var getBuiltIn = __webpack_require__("6d7a");
  5719. var getOwnPropertyNamesModule = __webpack_require__("b338");
  5720. var getOwnPropertySymbolsModule = __webpack_require__("0a60");
  5721. var anObject = __webpack_require__("857c");
  5722. // all object keys, includes non-enumerable and symbols
  5723. module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  5724. var keys = getOwnPropertyNamesModule.f(anObject(it));
  5725. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  5726. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  5727. };
  5728. /***/ }),
  5729. /***/ "90fb":
  5730. /***/ (function(module, exports, __webpack_require__) {
  5731. var global = __webpack_require__("d890");
  5732. var shared = __webpack_require__("6d28");
  5733. var has = __webpack_require__("faa8");
  5734. var uid = __webpack_require__("7e8b");
  5735. var NATIVE_SYMBOL = __webpack_require__("c54b");
  5736. var USE_SYMBOL_AS_UID = __webpack_require__("74cb");
  5737. var WellKnownSymbolsStore = shared('wks');
  5738. var Symbol = global.Symbol;
  5739. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol : Symbol && Symbol.withoutSetter || uid;
  5740. module.exports = function (name) {
  5741. if (!has(WellKnownSymbolsStore, name)) {
  5742. if (NATIVE_SYMBOL && has(Symbol, name)) WellKnownSymbolsStore[name] = Symbol[name];
  5743. else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  5744. } return WellKnownSymbolsStore[name];
  5745. };
  5746. /***/ }),
  5747. /***/ "9b9d":
  5748. /***/ (function(module, exports) {
  5749. module.exports = false;
  5750. /***/ }),
  5751. /***/ "9edd":
  5752. /***/ (function(module, exports) {
  5753. var g;
  5754. // This works in non-strict mode
  5755. g = (function() {
  5756. return this;
  5757. })();
  5758. try {
  5759. // This works if eval is allowed (see CSP)
  5760. g = g || new Function("return this")();
  5761. } catch (e) {
  5762. // This works if the window reference is available
  5763. if (typeof window === "object") g = window;
  5764. }
  5765. // g can still be undefined, but nothing to do about it...
  5766. // We return undefined, instead of nothing here, so it's
  5767. // easier to handle this case. if(!global) { ...}
  5768. module.exports = g;
  5769. /***/ }),
  5770. /***/ "9f67":
  5771. /***/ (function(module, exports, __webpack_require__) {
  5772. var isObject = __webpack_require__("a719");
  5773. // `ToPrimitive` abstract operation
  5774. // https://tc39.github.io/ecma262/#sec-toprimitive
  5775. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  5776. // and the second argument - flag - preferred type is a string
  5777. module.exports = function (input, PREFERRED_STRING) {
  5778. if (!isObject(input)) return input;
  5779. var fn, val;
  5780. if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  5781. if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
  5782. if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  5783. throw TypeError("Can't convert object to primitive value");
  5784. };
  5785. /***/ }),
  5786. /***/ "a564":
  5787. /***/ (function(module, exports, __webpack_require__) {
  5788. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  5789. // Distributed under an MIT license: https://codemirror.net/LICENSE
  5790. // This is CodeMirror (https://codemirror.net), a code editor
  5791. // implemented in JavaScript on top of the browser's DOM.
  5792. //
  5793. // You can find some technical background for some of the code below
  5794. // at http://marijnhaverbeke.nl/blog/#cm-internals .
  5795. (function (global, factory) {
  5796. true ? module.exports = factory() :
  5797. undefined;
  5798. }(this, (function () { 'use strict';
  5799. // Kludges for bugs and behavior differences that can't be feature
  5800. // detected are enabled based on userAgent etc sniffing.
  5801. var userAgent = navigator.userAgent;
  5802. var platform = navigator.platform;
  5803. var gecko = /gecko\/\d/i.test(userAgent);
  5804. var ie_upto10 = /MSIE \d/.test(userAgent);
  5805. var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
  5806. var edge = /Edge\/(\d+)/.exec(userAgent);
  5807. var ie = ie_upto10 || ie_11up || edge;
  5808. var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
  5809. var webkit = !edge && /WebKit\//.test(userAgent);
  5810. var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
  5811. var chrome = !edge && /Chrome\//.test(userAgent);
  5812. var presto = /Opera\//.test(userAgent);
  5813. var safari = /Apple Computer/.test(navigator.vendor);
  5814. var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
  5815. var phantom = /PhantomJS/.test(userAgent);
  5816. var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
  5817. var android = /Android/.test(userAgent);
  5818. // This is woefully incomplete. Suggestions for alternative methods welcome.
  5819. var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
  5820. var mac = ios || /Mac/.test(platform);
  5821. var chromeOS = /\bCrOS\b/.test(userAgent);
  5822. var windows = /win/i.test(platform);
  5823. var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
  5824. if (presto_version) { presto_version = Number(presto_version[1]); }
  5825. if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
  5826. // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
  5827. var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
  5828. var captureRightClick = gecko || (ie && ie_version >= 9);
  5829. function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
  5830. var rmClass = function(node, cls) {
  5831. var current = node.className;
  5832. var match = classTest(cls).exec(current);
  5833. if (match) {
  5834. var after = current.slice(match.index + match[0].length);
  5835. node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
  5836. }
  5837. };
  5838. function removeChildren(e) {
  5839. for (var count = e.childNodes.length; count > 0; --count)
  5840. { e.removeChild(e.firstChild); }
  5841. return e
  5842. }
  5843. function removeChildrenAndAdd(parent, e) {
  5844. return removeChildren(parent).appendChild(e)
  5845. }
  5846. function elt(tag, content, className, style) {
  5847. var e = document.createElement(tag);
  5848. if (className) { e.className = className; }
  5849. if (style) { e.style.cssText = style; }
  5850. if (typeof content == "string") { e.appendChild(document.createTextNode(content)); }
  5851. else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } }
  5852. return e
  5853. }
  5854. // wrapper for elt, which removes the elt from the accessibility tree
  5855. function eltP(tag, content, className, style) {
  5856. var e = elt(tag, content, className, style);
  5857. e.setAttribute("role", "presentation");
  5858. return e
  5859. }
  5860. var range;
  5861. if (document.createRange) { range = function(node, start, end, endNode) {
  5862. var r = document.createRange();
  5863. r.setEnd(endNode || node, end);
  5864. r.setStart(node, start);
  5865. return r
  5866. }; }
  5867. else { range = function(node, start, end) {
  5868. var r = document.body.createTextRange();
  5869. try { r.moveToElementText(node.parentNode); }
  5870. catch(e) { return r }
  5871. r.collapse(true);
  5872. r.moveEnd("character", end);
  5873. r.moveStart("character", start);
  5874. return r
  5875. }; }
  5876. function contains(parent, child) {
  5877. if (child.nodeType == 3) // Android browser always returns false when child is a textnode
  5878. { child = child.parentNode; }
  5879. if (parent.contains)
  5880. { return parent.contains(child) }
  5881. do {
  5882. if (child.nodeType == 11) { child = child.host; }
  5883. if (child == parent) { return true }
  5884. } while (child = child.parentNode)
  5885. }
  5886. function activeElt() {
  5887. // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
  5888. // IE < 10 will throw when accessed while the page is loading or in an iframe.
  5889. // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
  5890. var activeElement;
  5891. try {
  5892. activeElement = document.activeElement;
  5893. } catch(e) {
  5894. activeElement = document.body || null;
  5895. }
  5896. while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
  5897. { activeElement = activeElement.shadowRoot.activeElement; }
  5898. return activeElement
  5899. }
  5900. function addClass(node, cls) {
  5901. var current = node.className;
  5902. if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; }
  5903. }
  5904. function joinClasses(a, b) {
  5905. var as = a.split(" ");
  5906. for (var i = 0; i < as.length; i++)
  5907. { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } }
  5908. return b
  5909. }
  5910. var selectInput = function(node) { node.select(); };
  5911. if (ios) // Mobile Safari apparently has a bug where select() is broken.
  5912. { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; }
  5913. else if (ie) // Suppress mysterious IE10 errors
  5914. { selectInput = function(node) { try { node.select(); } catch(_e) {} }; }
  5915. function bind(f) {
  5916. var args = Array.prototype.slice.call(arguments, 1);
  5917. return function(){return f.apply(null, args)}
  5918. }
  5919. function copyObj(obj, target, overwrite) {
  5920. if (!target) { target = {}; }
  5921. for (var prop in obj)
  5922. { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
  5923. { target[prop] = obj[prop]; } }
  5924. return target
  5925. }
  5926. // Counts the column offset in a string, taking tabs into account.
  5927. // Used mostly to find indentation.
  5928. function countColumn(string, end, tabSize, startIndex, startValue) {
  5929. if (end == null) {
  5930. end = string.search(/[^\s\u00a0]/);
  5931. if (end == -1) { end = string.length; }
  5932. }
  5933. for (var i = startIndex || 0, n = startValue || 0;;) {
  5934. var nextTab = string.indexOf("\t", i);
  5935. if (nextTab < 0 || nextTab >= end)
  5936. { return n + (end - i) }
  5937. n += nextTab - i;
  5938. n += tabSize - (n % tabSize);
  5939. i = nextTab + 1;
  5940. }
  5941. }
  5942. var Delayed = function() {
  5943. this.id = null;
  5944. this.f = null;
  5945. this.time = 0;
  5946. this.handler = bind(this.onTimeout, this);
  5947. };
  5948. Delayed.prototype.onTimeout = function (self) {
  5949. self.id = 0;
  5950. if (self.time <= +new Date) {
  5951. self.f();
  5952. } else {
  5953. setTimeout(self.handler, self.time - +new Date);
  5954. }
  5955. };
  5956. Delayed.prototype.set = function (ms, f) {
  5957. this.f = f;
  5958. var time = +new Date + ms;
  5959. if (!this.id || time < this.time) {
  5960. clearTimeout(this.id);
  5961. this.id = setTimeout(this.handler, ms);
  5962. this.time = time;
  5963. }
  5964. };
  5965. function indexOf(array, elt) {
  5966. for (var i = 0; i < array.length; ++i)
  5967. { if (array[i] == elt) { return i } }
  5968. return -1
  5969. }
  5970. // Number of pixels added to scroller and sizer to hide scrollbar
  5971. var scrollerGap = 30;
  5972. // Returned or thrown by various protocols to signal 'I'm not
  5973. // handling this'.
  5974. var Pass = {toString: function(){return "CodeMirror.Pass"}};
  5975. // Reused option objects for setSelection & friends
  5976. var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
  5977. // The inverse of countColumn -- find the offset that corresponds to
  5978. // a particular column.
  5979. function findColumn(string, goal, tabSize) {
  5980. for (var pos = 0, col = 0;;) {
  5981. var nextTab = string.indexOf("\t", pos);
  5982. if (nextTab == -1) { nextTab = string.length; }
  5983. var skipped = nextTab - pos;
  5984. if (nextTab == string.length || col + skipped >= goal)
  5985. { return pos + Math.min(skipped, goal - col) }
  5986. col += nextTab - pos;
  5987. col += tabSize - (col % tabSize);
  5988. pos = nextTab + 1;
  5989. if (col >= goal) { return pos }
  5990. }
  5991. }
  5992. var spaceStrs = [""];
  5993. function spaceStr(n) {
  5994. while (spaceStrs.length <= n)
  5995. { spaceStrs.push(lst(spaceStrs) + " "); }
  5996. return spaceStrs[n]
  5997. }
  5998. function lst(arr) { return arr[arr.length-1] }
  5999. function map(array, f) {
  6000. var out = [];
  6001. for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); }
  6002. return out
  6003. }
  6004. function insertSorted(array, value, score) {
  6005. var pos = 0, priority = score(value);
  6006. while (pos < array.length && score(array[pos]) <= priority) { pos++; }
  6007. array.splice(pos, 0, value);
  6008. }
  6009. function nothing() {}
  6010. function createObj(base, props) {
  6011. var inst;
  6012. if (Object.create) {
  6013. inst = Object.create(base);
  6014. } else {
  6015. nothing.prototype = base;
  6016. inst = new nothing();
  6017. }
  6018. if (props) { copyObj(props, inst); }
  6019. return inst
  6020. }
  6021. var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
  6022. function isWordCharBasic(ch) {
  6023. return /\w/.test(ch) || ch > "\x80" &&
  6024. (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
  6025. }
  6026. function isWordChar(ch, helper) {
  6027. if (!helper) { return isWordCharBasic(ch) }
  6028. if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
  6029. return helper.test(ch)
  6030. }
  6031. function isEmpty(obj) {
  6032. for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
  6033. return true
  6034. }
  6035. // Extending unicode characters. A series of a non-extending char +
  6036. // any number of extending chars is treated as a single unit as far
  6037. // as editing and measuring is concerned. This is not fully correct,
  6038. // since some scripts/fonts/browsers also treat other configurations
  6039. // of code points as a group.
  6040. var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
  6041. function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
  6042. // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
  6043. function skipExtendingChars(str, pos, dir) {
  6044. while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; }
  6045. return pos
  6046. }
  6047. // Returns the value from the range [`from`; `to`] that satisfies
  6048. // `pred` and is closest to `from`. Assumes that at least `to`
  6049. // satisfies `pred`. Supports `from` being greater than `to`.
  6050. function findFirst(pred, from, to) {
  6051. // At any point we are certain `to` satisfies `pred`, don't know
  6052. // whether `from` does.
  6053. var dir = from > to ? -1 : 1;
  6054. for (;;) {
  6055. if (from == to) { return from }
  6056. var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
  6057. if (mid == from) { return pred(mid) ? from : to }
  6058. if (pred(mid)) { to = mid; }
  6059. else { from = mid + dir; }
  6060. }
  6061. }
  6062. // BIDI HELPERS
  6063. function iterateBidiSections(order, from, to, f) {
  6064. if (!order) { return f(from, to, "ltr", 0) }
  6065. var found = false;
  6066. for (var i = 0; i < order.length; ++i) {
  6067. var part = order[i];
  6068. if (part.from < to && part.to > from || from == to && part.to == from) {
  6069. f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i);
  6070. found = true;
  6071. }
  6072. }
  6073. if (!found) { f(from, to, "ltr"); }
  6074. }
  6075. var bidiOther = null;
  6076. function getBidiPartAt(order, ch, sticky) {
  6077. var found;
  6078. bidiOther = null;
  6079. for (var i = 0; i < order.length; ++i) {
  6080. var cur = order[i];
  6081. if (cur.from < ch && cur.to > ch) { return i }
  6082. if (cur.to == ch) {
  6083. if (cur.from != cur.to && sticky == "before") { found = i; }
  6084. else { bidiOther = i; }
  6085. }
  6086. if (cur.from == ch) {
  6087. if (cur.from != cur.to && sticky != "before") { found = i; }
  6088. else { bidiOther = i; }
  6089. }
  6090. }
  6091. return found != null ? found : bidiOther
  6092. }
  6093. // Bidirectional ordering algorithm
  6094. // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
  6095. // that this (partially) implements.
  6096. // One-char codes used for character types:
  6097. // L (L): Left-to-Right
  6098. // R (R): Right-to-Left
  6099. // r (AL): Right-to-Left Arabic
  6100. // 1 (EN): European Number
  6101. // + (ES): European Number Separator
  6102. // % (ET): European Number Terminator
  6103. // n (AN): Arabic Number
  6104. // , (CS): Common Number Separator
  6105. // m (NSM): Non-Spacing Mark
  6106. // b (BN): Boundary Neutral
  6107. // s (B): Paragraph Separator
  6108. // t (S): Segment Separator
  6109. // w (WS): Whitespace
  6110. // N (ON): Other Neutrals
  6111. // Returns null if characters are ordered as they appear
  6112. // (left-to-right), or an array of sections ({from, to, level}
  6113. // objects) in the order in which they occur visually.
  6114. var bidiOrdering = (function() {
  6115. // Character types for codepoints 0 to 0xff
  6116. var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
  6117. // Character types for codepoints 0x600 to 0x6f9
  6118. var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
  6119. function charType(code) {
  6120. if (code <= 0xf7) { return lowTypes.charAt(code) }
  6121. else if (0x590 <= code && code <= 0x5f4) { return "R" }
  6122. else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
  6123. else if (0x6ee <= code && code <= 0x8ac) { return "r" }
  6124. else if (0x2000 <= code && code <= 0x200b) { return "w" }
  6125. else if (code == 0x200c) { return "b" }
  6126. else { return "L" }
  6127. }
  6128. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
  6129. var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
  6130. function BidiSpan(level, from, to) {
  6131. this.level = level;
  6132. this.from = from; this.to = to;
  6133. }
  6134. return function(str, direction) {
  6135. var outerType = direction == "ltr" ? "L" : "R";
  6136. if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
  6137. var len = str.length, types = [];
  6138. for (var i = 0; i < len; ++i)
  6139. { types.push(charType(str.charCodeAt(i))); }
  6140. // W1. Examine each non-spacing mark (NSM) in the level run, and
  6141. // change the type of the NSM to the type of the previous
  6142. // character. If the NSM is at the start of the level run, it will
  6143. // get the type of sor.
  6144. for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
  6145. var type = types[i$1];
  6146. if (type == "m") { types[i$1] = prev; }
  6147. else { prev = type; }
  6148. }
  6149. // W2. Search backwards from each instance of a European number
  6150. // until the first strong type (R, L, AL, or sor) is found. If an
  6151. // AL is found, change the type of the European number to Arabic
  6152. // number.
  6153. // W3. Change all ALs to R.
  6154. for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
  6155. var type$1 = types[i$2];
  6156. if (type$1 == "1" && cur == "r") { types[i$2] = "n"; }
  6157. else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } }
  6158. }
  6159. // W4. A single European separator between two European numbers
  6160. // changes to a European number. A single common separator between
  6161. // two numbers of the same type changes to that type.
  6162. for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
  6163. var type$2 = types[i$3];
  6164. if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; }
  6165. else if (type$2 == "," && prev$1 == types[i$3+1] &&
  6166. (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; }
  6167. prev$1 = type$2;
  6168. }
  6169. // W5. A sequence of European terminators adjacent to European
  6170. // numbers changes to all European numbers.
  6171. // W6. Otherwise, separators and terminators change to Other
  6172. // Neutral.
  6173. for (var i$4 = 0; i$4 < len; ++i$4) {
  6174. var type$3 = types[i$4];
  6175. if (type$3 == ",") { types[i$4] = "N"; }
  6176. else if (type$3 == "%") {
  6177. var end = (void 0);
  6178. for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
  6179. var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
  6180. for (var j = i$4; j < end; ++j) { types[j] = replace; }
  6181. i$4 = end - 1;
  6182. }
  6183. }
  6184. // W7. Search backwards from each instance of a European number
  6185. // until the first strong type (R, L, or sor) is found. If an L is
  6186. // found, then change the type of the European number to L.
  6187. for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
  6188. var type$4 = types[i$5];
  6189. if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; }
  6190. else if (isStrong.test(type$4)) { cur$1 = type$4; }
  6191. }
  6192. // N1. A sequence of neutrals takes the direction of the
  6193. // surrounding strong text if the text on both sides has the same
  6194. // direction. European and Arabic numbers act as if they were R in
  6195. // terms of their influence on neutrals. Start-of-level-run (sor)
  6196. // and end-of-level-run (eor) are used at level run boundaries.
  6197. // N2. Any remaining neutrals take the embedding direction.
  6198. for (var i$6 = 0; i$6 < len; ++i$6) {
  6199. if (isNeutral.test(types[i$6])) {
  6200. var end$1 = (void 0);
  6201. for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
  6202. var before = (i$6 ? types[i$6-1] : outerType) == "L";
  6203. var after = (end$1 < len ? types[end$1] : outerType) == "L";
  6204. var replace$1 = before == after ? (before ? "L" : "R") : outerType;
  6205. for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; }
  6206. i$6 = end$1 - 1;
  6207. }
  6208. }
  6209. // Here we depart from the documented algorithm, in order to avoid
  6210. // building up an actual levels array. Since there are only three
  6211. // levels (0, 1, 2) in an implementation that doesn't take
  6212. // explicit embedding into account, we can build up the order on
  6213. // the fly, without following the level-based algorithm.
  6214. var order = [], m;
  6215. for (var i$7 = 0; i$7 < len;) {
  6216. if (countsAsLeft.test(types[i$7])) {
  6217. var start = i$7;
  6218. for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
  6219. order.push(new BidiSpan(0, start, i$7));
  6220. } else {
  6221. var pos = i$7, at = order.length, isRTL = direction == "rtl" ? 1 : 0;
  6222. for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
  6223. for (var j$2 = pos; j$2 < i$7;) {
  6224. if (countsAsNum.test(types[j$2])) {
  6225. if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); at += isRTL; }
  6226. var nstart = j$2;
  6227. for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
  6228. order.splice(at, 0, new BidiSpan(2, nstart, j$2));
  6229. at += isRTL;
  6230. pos = j$2;
  6231. } else { ++j$2; }
  6232. }
  6233. if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); }
  6234. }
  6235. }
  6236. if (direction == "ltr") {
  6237. if (order[0].level == 1 && (m = str.match(/^\s+/))) {
  6238. order[0].from = m[0].length;
  6239. order.unshift(new BidiSpan(0, 0, m[0].length));
  6240. }
  6241. if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
  6242. lst(order).to -= m[0].length;
  6243. order.push(new BidiSpan(0, len - m[0].length, len));
  6244. }
  6245. }
  6246. return direction == "rtl" ? order.reverse() : order
  6247. }
  6248. })();
  6249. // Get the bidi ordering for the given line (and cache it). Returns
  6250. // false for lines that are fully left-to-right, and an array of
  6251. // BidiSpan objects otherwise.
  6252. function getOrder(line, direction) {
  6253. var order = line.order;
  6254. if (order == null) { order = line.order = bidiOrdering(line.text, direction); }
  6255. return order
  6256. }
  6257. // EVENT HANDLING
  6258. // Lightweight event framework. on/off also work on DOM nodes,
  6259. // registering native DOM handlers.
  6260. var noHandlers = [];
  6261. var on = function(emitter, type, f) {
  6262. if (emitter.addEventListener) {
  6263. emitter.addEventListener(type, f, false);
  6264. } else if (emitter.attachEvent) {
  6265. emitter.attachEvent("on" + type, f);
  6266. } else {
  6267. var map = emitter._handlers || (emitter._handlers = {});
  6268. map[type] = (map[type] || noHandlers).concat(f);
  6269. }
  6270. };
  6271. function getHandlers(emitter, type) {
  6272. return emitter._handlers && emitter._handlers[type] || noHandlers
  6273. }
  6274. function off(emitter, type, f) {
  6275. if (emitter.removeEventListener) {
  6276. emitter.removeEventListener(type, f, false);
  6277. } else if (emitter.detachEvent) {
  6278. emitter.detachEvent("on" + type, f);
  6279. } else {
  6280. var map = emitter._handlers, arr = map && map[type];
  6281. if (arr) {
  6282. var index = indexOf(arr, f);
  6283. if (index > -1)
  6284. { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)); }
  6285. }
  6286. }
  6287. }
  6288. function signal(emitter, type /*, values...*/) {
  6289. var handlers = getHandlers(emitter, type);
  6290. if (!handlers.length) { return }
  6291. var args = Array.prototype.slice.call(arguments, 2);
  6292. for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); }
  6293. }
  6294. // The DOM events that CodeMirror handles can be overridden by
  6295. // registering a (non-DOM) handler on the editor for the event name,
  6296. // and preventDefault-ing the event in that handler.
  6297. function signalDOMEvent(cm, e, override) {
  6298. if (typeof e == "string")
  6299. { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; }
  6300. signal(cm, override || e.type, cm, e);
  6301. return e_defaultPrevented(e) || e.codemirrorIgnore
  6302. }
  6303. function signalCursorActivity(cm) {
  6304. var arr = cm._handlers && cm._handlers.cursorActivity;
  6305. if (!arr) { return }
  6306. var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
  6307. for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
  6308. { set.push(arr[i]); } }
  6309. }
  6310. function hasHandler(emitter, type) {
  6311. return getHandlers(emitter, type).length > 0
  6312. }
  6313. // Add on and off methods to a constructor's prototype, to make
  6314. // registering events on such objects more convenient.
  6315. function eventMixin(ctor) {
  6316. ctor.prototype.on = function(type, f) {on(this, type, f);};
  6317. ctor.prototype.off = function(type, f) {off(this, type, f);};
  6318. }
  6319. // Due to the fact that we still support jurassic IE versions, some
  6320. // compatibility wrappers are needed.
  6321. function e_preventDefault(e) {
  6322. if (e.preventDefault) { e.preventDefault(); }
  6323. else { e.returnValue = false; }
  6324. }
  6325. function e_stopPropagation(e) {
  6326. if (e.stopPropagation) { e.stopPropagation(); }
  6327. else { e.cancelBubble = true; }
  6328. }
  6329. function e_defaultPrevented(e) {
  6330. return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
  6331. }
  6332. function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
  6333. function e_target(e) {return e.target || e.srcElement}
  6334. function e_button(e) {
  6335. var b = e.which;
  6336. if (b == null) {
  6337. if (e.button & 1) { b = 1; }
  6338. else if (e.button & 2) { b = 3; }
  6339. else if (e.button & 4) { b = 2; }
  6340. }
  6341. if (mac && e.ctrlKey && b == 1) { b = 3; }
  6342. return b
  6343. }
  6344. // Detect drag-and-drop
  6345. var dragAndDrop = function() {
  6346. // There is *some* kind of drag-and-drop support in IE6-8, but I
  6347. // couldn't get it to work yet.
  6348. if (ie && ie_version < 9) { return false }
  6349. var div = elt('div');
  6350. return "draggable" in div || "dragDrop" in div
  6351. }();
  6352. var zwspSupported;
  6353. function zeroWidthElement(measure) {
  6354. if (zwspSupported == null) {
  6355. var test = elt("span", "\u200b");
  6356. removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
  6357. if (measure.firstChild.offsetHeight != 0)
  6358. { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); }
  6359. }
  6360. var node = zwspSupported ? elt("span", "\u200b") :
  6361. elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
  6362. node.setAttribute("cm-text", "");
  6363. return node
  6364. }
  6365. // Feature-detect IE's crummy client rect reporting for bidi text
  6366. var badBidiRects;
  6367. function hasBadBidiRects(measure) {
  6368. if (badBidiRects != null) { return badBidiRects }
  6369. var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
  6370. var r0 = range(txt, 0, 1).getBoundingClientRect();
  6371. var r1 = range(txt, 1, 2).getBoundingClientRect();
  6372. removeChildren(measure);
  6373. if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
  6374. return badBidiRects = (r1.right - r0.right < 3)
  6375. }
  6376. // See if "".split is the broken IE version, if so, provide an
  6377. // alternative way to split lines.
  6378. var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
  6379. var pos = 0, result = [], l = string.length;
  6380. while (pos <= l) {
  6381. var nl = string.indexOf("\n", pos);
  6382. if (nl == -1) { nl = string.length; }
  6383. var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
  6384. var rt = line.indexOf("\r");
  6385. if (rt != -1) {
  6386. result.push(line.slice(0, rt));
  6387. pos += rt + 1;
  6388. } else {
  6389. result.push(line);
  6390. pos = nl + 1;
  6391. }
  6392. }
  6393. return result
  6394. } : function (string) { return string.split(/\r\n?|\n/); };
  6395. var hasSelection = window.getSelection ? function (te) {
  6396. try { return te.selectionStart != te.selectionEnd }
  6397. catch(e) { return false }
  6398. } : function (te) {
  6399. var range;
  6400. try {range = te.ownerDocument.selection.createRange();}
  6401. catch(e) {}
  6402. if (!range || range.parentElement() != te) { return false }
  6403. return range.compareEndPoints("StartToEnd", range) != 0
  6404. };
  6405. var hasCopyEvent = (function () {
  6406. var e = elt("div");
  6407. if ("oncopy" in e) { return true }
  6408. e.setAttribute("oncopy", "return;");
  6409. return typeof e.oncopy == "function"
  6410. })();
  6411. var badZoomedRects = null;
  6412. function hasBadZoomedRects(measure) {
  6413. if (badZoomedRects != null) { return badZoomedRects }
  6414. var node = removeChildrenAndAdd(measure, elt("span", "x"));
  6415. var normal = node.getBoundingClientRect();
  6416. var fromRange = range(node, 0, 1).getBoundingClientRect();
  6417. return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
  6418. }
  6419. // Known modes, by name and by MIME
  6420. var modes = {}, mimeModes = {};
  6421. // Extra arguments are stored as the mode's dependencies, which is
  6422. // used by (legacy) mechanisms like loadmode.js to automatically
  6423. // load a mode. (Preferred mechanism is the require/define calls.)
  6424. function defineMode(name, mode) {
  6425. if (arguments.length > 2)
  6426. { mode.dependencies = Array.prototype.slice.call(arguments, 2); }
  6427. modes[name] = mode;
  6428. }
  6429. function defineMIME(mime, spec) {
  6430. mimeModes[mime] = spec;
  6431. }
  6432. // Given a MIME type, a {name, ...options} config object, or a name
  6433. // string, return a mode config object.
  6434. function resolveMode(spec) {
  6435. if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
  6436. spec = mimeModes[spec];
  6437. } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
  6438. var found = mimeModes[spec.name];
  6439. if (typeof found == "string") { found = {name: found}; }
  6440. spec = createObj(found, spec);
  6441. spec.name = found.name;
  6442. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
  6443. return resolveMode("application/xml")
  6444. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
  6445. return resolveMode("application/json")
  6446. }
  6447. if (typeof spec == "string") { return {name: spec} }
  6448. else { return spec || {name: "null"} }
  6449. }
  6450. // Given a mode spec (anything that resolveMode accepts), find and
  6451. // initialize an actual mode object.
  6452. function getMode(options, spec) {
  6453. spec = resolveMode(spec);
  6454. var mfactory = modes[spec.name];
  6455. if (!mfactory) { return getMode(options, "text/plain") }
  6456. var modeObj = mfactory(options, spec);
  6457. if (modeExtensions.hasOwnProperty(spec.name)) {
  6458. var exts = modeExtensions[spec.name];
  6459. for (var prop in exts) {
  6460. if (!exts.hasOwnProperty(prop)) { continue }
  6461. if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
  6462. modeObj[prop] = exts[prop];
  6463. }
  6464. }
  6465. modeObj.name = spec.name;
  6466. if (spec.helperType) { modeObj.helperType = spec.helperType; }
  6467. if (spec.modeProps) { for (var prop$1 in spec.modeProps)
  6468. { modeObj[prop$1] = spec.modeProps[prop$1]; } }
  6469. return modeObj
  6470. }
  6471. // This can be used to attach properties to mode objects from
  6472. // outside the actual mode definition.
  6473. var modeExtensions = {};
  6474. function extendMode(mode, properties) {
  6475. var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
  6476. copyObj(properties, exts);
  6477. }
  6478. function copyState(mode, state) {
  6479. if (state === true) { return state }
  6480. if (mode.copyState) { return mode.copyState(state) }
  6481. var nstate = {};
  6482. for (var n in state) {
  6483. var val = state[n];
  6484. if (val instanceof Array) { val = val.concat([]); }
  6485. nstate[n] = val;
  6486. }
  6487. return nstate
  6488. }
  6489. // Given a mode and a state (for that mode), find the inner mode and
  6490. // state at the position that the state refers to.
  6491. function innerMode(mode, state) {
  6492. var info;
  6493. while (mode.innerMode) {
  6494. info = mode.innerMode(state);
  6495. if (!info || info.mode == mode) { break }
  6496. state = info.state;
  6497. mode = info.mode;
  6498. }
  6499. return info || {mode: mode, state: state}
  6500. }
  6501. function startState(mode, a1, a2) {
  6502. return mode.startState ? mode.startState(a1, a2) : true
  6503. }
  6504. // STRING STREAM
  6505. // Fed to the mode parsers, provides helper functions to make
  6506. // parsers more succinct.
  6507. var StringStream = function(string, tabSize, lineOracle) {
  6508. this.pos = this.start = 0;
  6509. this.string = string;
  6510. this.tabSize = tabSize || 8;
  6511. this.lastColumnPos = this.lastColumnValue = 0;
  6512. this.lineStart = 0;
  6513. this.lineOracle = lineOracle;
  6514. };
  6515. StringStream.prototype.eol = function () {return this.pos >= this.string.length};
  6516. StringStream.prototype.sol = function () {return this.pos == this.lineStart};
  6517. StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
  6518. StringStream.prototype.next = function () {
  6519. if (this.pos < this.string.length)
  6520. { return this.string.charAt(this.pos++) }
  6521. };
  6522. StringStream.prototype.eat = function (match) {
  6523. var ch = this.string.charAt(this.pos);
  6524. var ok;
  6525. if (typeof match == "string") { ok = ch == match; }
  6526. else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
  6527. if (ok) {++this.pos; return ch}
  6528. };
  6529. StringStream.prototype.eatWhile = function (match) {
  6530. var start = this.pos;
  6531. while (this.eat(match)){}
  6532. return this.pos > start
  6533. };
  6534. StringStream.prototype.eatSpace = function () {
  6535. var start = this.pos;
  6536. while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; }
  6537. return this.pos > start
  6538. };
  6539. StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
  6540. StringStream.prototype.skipTo = function (ch) {
  6541. var found = this.string.indexOf(ch, this.pos);
  6542. if (found > -1) {this.pos = found; return true}
  6543. };
  6544. StringStream.prototype.backUp = function (n) {this.pos -= n;};
  6545. StringStream.prototype.column = function () {
  6546. if (this.lastColumnPos < this.start) {
  6547. this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
  6548. this.lastColumnPos = this.start;
  6549. }
  6550. return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
  6551. };
  6552. StringStream.prototype.indentation = function () {
  6553. return countColumn(this.string, null, this.tabSize) -
  6554. (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
  6555. };
  6556. StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
  6557. if (typeof pattern == "string") {
  6558. var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
  6559. var substr = this.string.substr(this.pos, pattern.length);
  6560. if (cased(substr) == cased(pattern)) {
  6561. if (consume !== false) { this.pos += pattern.length; }
  6562. return true
  6563. }
  6564. } else {
  6565. var match = this.string.slice(this.pos).match(pattern);
  6566. if (match && match.index > 0) { return null }
  6567. if (match && consume !== false) { this.pos += match[0].length; }
  6568. return match
  6569. }
  6570. };
  6571. StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
  6572. StringStream.prototype.hideFirstChars = function (n, inner) {
  6573. this.lineStart += n;
  6574. try { return inner() }
  6575. finally { this.lineStart -= n; }
  6576. };
  6577. StringStream.prototype.lookAhead = function (n) {
  6578. var oracle = this.lineOracle;
  6579. return oracle && oracle.lookAhead(n)
  6580. };
  6581. StringStream.prototype.baseToken = function () {
  6582. var oracle = this.lineOracle;
  6583. return oracle && oracle.baseToken(this.pos)
  6584. };
  6585. // Find the line object corresponding to the given line number.
  6586. function getLine(doc, n) {
  6587. n -= doc.first;
  6588. if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
  6589. var chunk = doc;
  6590. while (!chunk.lines) {
  6591. for (var i = 0;; ++i) {
  6592. var child = chunk.children[i], sz = child.chunkSize();
  6593. if (n < sz) { chunk = child; break }
  6594. n -= sz;
  6595. }
  6596. }
  6597. return chunk.lines[n]
  6598. }
  6599. // Get the part of a document between two positions, as an array of
  6600. // strings.
  6601. function getBetween(doc, start, end) {
  6602. var out = [], n = start.line;
  6603. doc.iter(start.line, end.line + 1, function (line) {
  6604. var text = line.text;
  6605. if (n == end.line) { text = text.slice(0, end.ch); }
  6606. if (n == start.line) { text = text.slice(start.ch); }
  6607. out.push(text);
  6608. ++n;
  6609. });
  6610. return out
  6611. }
  6612. // Get the lines between from and to, as array of strings.
  6613. function getLines(doc, from, to) {
  6614. var out = [];
  6615. doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value
  6616. return out
  6617. }
  6618. // Update the height of a line, propagating the height change
  6619. // upwards to parent nodes.
  6620. function updateLineHeight(line, height) {
  6621. var diff = height - line.height;
  6622. if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } }
  6623. }
  6624. // Given a line object, find its line number by walking up through
  6625. // its parent links.
  6626. function lineNo(line) {
  6627. if (line.parent == null) { return null }
  6628. var cur = line.parent, no = indexOf(cur.lines, line);
  6629. for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
  6630. for (var i = 0;; ++i) {
  6631. if (chunk.children[i] == cur) { break }
  6632. no += chunk.children[i].chunkSize();
  6633. }
  6634. }
  6635. return no + cur.first
  6636. }
  6637. // Find the line at the given vertical position, using the height
  6638. // information in the document tree.
  6639. function lineAtHeight(chunk, h) {
  6640. var n = chunk.first;
  6641. outer: do {
  6642. for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
  6643. var child = chunk.children[i$1], ch = child.height;
  6644. if (h < ch) { chunk = child; continue outer }
  6645. h -= ch;
  6646. n += child.chunkSize();
  6647. }
  6648. return n
  6649. } while (!chunk.lines)
  6650. var i = 0;
  6651. for (; i < chunk.lines.length; ++i) {
  6652. var line = chunk.lines[i], lh = line.height;
  6653. if (h < lh) { break }
  6654. h -= lh;
  6655. }
  6656. return n + i
  6657. }
  6658. function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
  6659. function lineNumberFor(options, i) {
  6660. return String(options.lineNumberFormatter(i + options.firstLineNumber))
  6661. }
  6662. // A Pos instance represents a position within the text.
  6663. function Pos(line, ch, sticky) {
  6664. if ( sticky === void 0 ) sticky = null;
  6665. if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
  6666. this.line = line;
  6667. this.ch = ch;
  6668. this.sticky = sticky;
  6669. }
  6670. // Compare two positions, return 0 if they are the same, a negative
  6671. // number when a is less, and a positive number otherwise.
  6672. function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
  6673. function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
  6674. function copyPos(x) {return Pos(x.line, x.ch)}
  6675. function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
  6676. function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
  6677. // Most of the external API clips given positions to make sure they
  6678. // actually exist within the document.
  6679. function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
  6680. function clipPos(doc, pos) {
  6681. if (pos.line < doc.first) { return Pos(doc.first, 0) }
  6682. var last = doc.first + doc.size - 1;
  6683. if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
  6684. return clipToLen(pos, getLine(doc, pos.line).text.length)
  6685. }
  6686. function clipToLen(pos, linelen) {
  6687. var ch = pos.ch;
  6688. if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
  6689. else if (ch < 0) { return Pos(pos.line, 0) }
  6690. else { return pos }
  6691. }
  6692. function clipPosArray(doc, array) {
  6693. var out = [];
  6694. for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); }
  6695. return out
  6696. }
  6697. var SavedContext = function(state, lookAhead) {
  6698. this.state = state;
  6699. this.lookAhead = lookAhead;
  6700. };
  6701. var Context = function(doc, state, line, lookAhead) {
  6702. this.state = state;
  6703. this.doc = doc;
  6704. this.line = line;
  6705. this.maxLookAhead = lookAhead || 0;
  6706. this.baseTokens = null;
  6707. this.baseTokenPos = 1;
  6708. };
  6709. Context.prototype.lookAhead = function (n) {
  6710. var line = this.doc.getLine(this.line + n);
  6711. if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n; }
  6712. return line
  6713. };
  6714. Context.prototype.baseToken = function (n) {
  6715. if (!this.baseTokens) { return null }
  6716. while (this.baseTokens[this.baseTokenPos] <= n)
  6717. { this.baseTokenPos += 2; }
  6718. var type = this.baseTokens[this.baseTokenPos + 1];
  6719. return {type: type && type.replace(/( |^)overlay .*/, ""),
  6720. size: this.baseTokens[this.baseTokenPos] - n}
  6721. };
  6722. Context.prototype.nextLine = function () {
  6723. this.line++;
  6724. if (this.maxLookAhead > 0) { this.maxLookAhead--; }
  6725. };
  6726. Context.fromSaved = function (doc, saved, line) {
  6727. if (saved instanceof SavedContext)
  6728. { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
  6729. else
  6730. { return new Context(doc, copyState(doc.mode, saved), line) }
  6731. };
  6732. Context.prototype.save = function (copy) {
  6733. var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
  6734. return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
  6735. };
  6736. // Compute a style array (an array starting with a mode generation
  6737. // -- for invalidation -- followed by pairs of end positions and
  6738. // style strings), which is used to highlight the tokens on the
  6739. // line.
  6740. function highlightLine(cm, line, context, forceToEnd) {
  6741. // A styles array always starts with a number identifying the
  6742. // mode/overlays that it is based on (for easy invalidation).
  6743. var st = [cm.state.modeGen], lineClasses = {};
  6744. // Compute the base array of styles
  6745. runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
  6746. lineClasses, forceToEnd);
  6747. var state = context.state;
  6748. // Run overlays, adjust style array.
  6749. var loop = function ( o ) {
  6750. context.baseTokens = st;
  6751. var overlay = cm.state.overlays[o], i = 1, at = 0;
  6752. context.state = true;
  6753. runMode(cm, line.text, overlay.mode, context, function (end, style) {
  6754. var start = i;
  6755. // Ensure there's a token end at the current position, and that i points at it
  6756. while (at < end) {
  6757. var i_end = st[i];
  6758. if (i_end > end)
  6759. { st.splice(i, 1, end, st[i+1], i_end); }
  6760. i += 2;
  6761. at = Math.min(end, i_end);
  6762. }
  6763. if (!style) { return }
  6764. if (overlay.opaque) {
  6765. st.splice(start, i - start, end, "overlay " + style);
  6766. i = start + 2;
  6767. } else {
  6768. for (; start < i; start += 2) {
  6769. var cur = st[start+1];
  6770. st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
  6771. }
  6772. }
  6773. }, lineClasses);
  6774. context.state = state;
  6775. context.baseTokens = null;
  6776. context.baseTokenPos = 1;
  6777. };
  6778. for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
  6779. return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
  6780. }
  6781. function getLineStyles(cm, line, updateFrontier) {
  6782. if (!line.styles || line.styles[0] != cm.state.modeGen) {
  6783. var context = getContextBefore(cm, lineNo(line));
  6784. var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
  6785. var result = highlightLine(cm, line, context);
  6786. if (resetState) { context.state = resetState; }
  6787. line.stateAfter = context.save(!resetState);
  6788. line.styles = result.styles;
  6789. if (result.classes) { line.styleClasses = result.classes; }
  6790. else if (line.styleClasses) { line.styleClasses = null; }
  6791. if (updateFrontier === cm.doc.highlightFrontier)
  6792. { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier); }
  6793. }
  6794. return line.styles
  6795. }
  6796. function getContextBefore(cm, n, precise) {
  6797. var doc = cm.doc, display = cm.display;
  6798. if (!doc.mode.startState) { return new Context(doc, true, n) }
  6799. var start = findStartLine(cm, n, precise);
  6800. var saved = start > doc.first && getLine(doc, start - 1).stateAfter;
  6801. var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);
  6802. doc.iter(start, n, function (line) {
  6803. processLine(cm, line.text, context);
  6804. var pos = context.line;
  6805. line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
  6806. context.nextLine();
  6807. });
  6808. if (precise) { doc.modeFrontier = context.line; }
  6809. return context
  6810. }
  6811. // Lightweight form of highlight -- proceed over this line and
  6812. // update state, but don't save a style array. Used for lines that
  6813. // aren't currently visible.
  6814. function processLine(cm, text, context, startAt) {
  6815. var mode = cm.doc.mode;
  6816. var stream = new StringStream(text, cm.options.tabSize, context);
  6817. stream.start = stream.pos = startAt || 0;
  6818. if (text == "") { callBlankLine(mode, context.state); }
  6819. while (!stream.eol()) {
  6820. readToken(mode, stream, context.state);
  6821. stream.start = stream.pos;
  6822. }
  6823. }
  6824. function callBlankLine(mode, state) {
  6825. if (mode.blankLine) { return mode.blankLine(state) }
  6826. if (!mode.innerMode) { return }
  6827. var inner = innerMode(mode, state);
  6828. if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
  6829. }
  6830. function readToken(mode, stream, state, inner) {
  6831. for (var i = 0; i < 10; i++) {
  6832. if (inner) { inner[0] = innerMode(mode, state).mode; }
  6833. var style = mode.token(stream, state);
  6834. if (stream.pos > stream.start) { return style }
  6835. }
  6836. throw new Error("Mode " + mode.name + " failed to advance stream.")
  6837. }
  6838. var Token = function(stream, type, state) {
  6839. this.start = stream.start; this.end = stream.pos;
  6840. this.string = stream.current();
  6841. this.type = type || null;
  6842. this.state = state;
  6843. };
  6844. // Utility for getTokenAt and getLineTokens
  6845. function takeToken(cm, pos, precise, asArray) {
  6846. var doc = cm.doc, mode = doc.mode, style;
  6847. pos = clipPos(doc, pos);
  6848. var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise);
  6849. var stream = new StringStream(line.text, cm.options.tabSize, context), tokens;
  6850. if (asArray) { tokens = []; }
  6851. while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
  6852. stream.start = stream.pos;
  6853. style = readToken(mode, stream, context.state);
  6854. if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))); }
  6855. }
  6856. return asArray ? tokens : new Token(stream, style, context.state)
  6857. }
  6858. function extractLineClasses(type, output) {
  6859. if (type) { for (;;) {
  6860. var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
  6861. if (!lineClass) { break }
  6862. type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
  6863. var prop = lineClass[1] ? "bgClass" : "textClass";
  6864. if (output[prop] == null)
  6865. { output[prop] = lineClass[2]; }
  6866. else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
  6867. { output[prop] += " " + lineClass[2]; }
  6868. } }
  6869. return type
  6870. }
  6871. // Run the given mode's parser over a line, calling f for each token.
  6872. function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
  6873. var flattenSpans = mode.flattenSpans;
  6874. if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; }
  6875. var curStart = 0, curStyle = null;
  6876. var stream = new StringStream(text, cm.options.tabSize, context), style;
  6877. var inner = cm.options.addModeClass && [null];
  6878. if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses); }
  6879. while (!stream.eol()) {
  6880. if (stream.pos > cm.options.maxHighlightLength) {
  6881. flattenSpans = false;
  6882. if (forceToEnd) { processLine(cm, text, context, stream.pos); }
  6883. stream.pos = text.length;
  6884. style = null;
  6885. } else {
  6886. style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
  6887. }
  6888. if (inner) {
  6889. var mName = inner[0].name;
  6890. if (mName) { style = "m-" + (style ? mName + " " + style : mName); }
  6891. }
  6892. if (!flattenSpans || curStyle != style) {
  6893. while (curStart < stream.start) {
  6894. curStart = Math.min(stream.start, curStart + 5000);
  6895. f(curStart, curStyle);
  6896. }
  6897. curStyle = style;
  6898. }
  6899. stream.start = stream.pos;
  6900. }
  6901. while (curStart < stream.pos) {
  6902. // Webkit seems to refuse to render text nodes longer than 57444
  6903. // characters, and returns inaccurate measurements in nodes
  6904. // starting around 5000 chars.
  6905. var pos = Math.min(stream.pos, curStart + 5000);
  6906. f(pos, curStyle);
  6907. curStart = pos;
  6908. }
  6909. }
  6910. // Finds the line to start with when starting a parse. Tries to
  6911. // find a line with a stateAfter, so that it can start with a
  6912. // valid state. If that fails, it returns the line with the
  6913. // smallest indentation, which tends to need the least context to
  6914. // parse correctly.
  6915. function findStartLine(cm, n, precise) {
  6916. var minindent, minline, doc = cm.doc;
  6917. var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
  6918. for (var search = n; search > lim; --search) {
  6919. if (search <= doc.first) { return doc.first }
  6920. var line = getLine(doc, search - 1), after = line.stateAfter;
  6921. if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
  6922. { return search }
  6923. var indented = countColumn(line.text, null, cm.options.tabSize);
  6924. if (minline == null || minindent > indented) {
  6925. minline = search - 1;
  6926. minindent = indented;
  6927. }
  6928. }
  6929. return minline
  6930. }
  6931. function retreatFrontier(doc, n) {
  6932. doc.modeFrontier = Math.min(doc.modeFrontier, n);
  6933. if (doc.highlightFrontier < n - 10) { return }
  6934. var start = doc.first;
  6935. for (var line = n - 1; line > start; line--) {
  6936. var saved = getLine(doc, line).stateAfter;
  6937. // change is on 3
  6938. // state on line 1 looked ahead 2 -- so saw 3
  6939. // test 1 + 2 < 3 should cover this
  6940. if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
  6941. start = line + 1;
  6942. break
  6943. }
  6944. }
  6945. doc.highlightFrontier = Math.min(doc.highlightFrontier, start);
  6946. }
  6947. // Optimize some code when these features are not used.
  6948. var sawReadOnlySpans = false, sawCollapsedSpans = false;
  6949. function seeReadOnlySpans() {
  6950. sawReadOnlySpans = true;
  6951. }
  6952. function seeCollapsedSpans() {
  6953. sawCollapsedSpans = true;
  6954. }
  6955. // TEXTMARKER SPANS
  6956. function MarkedSpan(marker, from, to) {
  6957. this.marker = marker;
  6958. this.from = from; this.to = to;
  6959. }
  6960. // Search an array of spans for a span matching the given marker.
  6961. function getMarkedSpanFor(spans, marker) {
  6962. if (spans) { for (var i = 0; i < spans.length; ++i) {
  6963. var span = spans[i];
  6964. if (span.marker == marker) { return span }
  6965. } }
  6966. }
  6967. // Remove a span from an array, returning undefined if no spans are
  6968. // left (we don't store arrays for lines without spans).
  6969. function removeMarkedSpan(spans, span) {
  6970. var r;
  6971. for (var i = 0; i < spans.length; ++i)
  6972. { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } }
  6973. return r
  6974. }
  6975. // Add a span to a line.
  6976. function addMarkedSpan(line, span) {
  6977. line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
  6978. span.marker.attachLine(line);
  6979. }
  6980. // Used for the algorithm that adjusts markers for a change in the
  6981. // document. These functions cut an array of spans at a given
  6982. // character position, returning an array of remaining chunks (or
  6983. // undefined if nothing remains).
  6984. function markedSpansBefore(old, startCh, isInsert) {
  6985. var nw;
  6986. if (old) { for (var i = 0; i < old.length; ++i) {
  6987. var span = old[i], marker = span.marker;
  6988. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
  6989. if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
  6990. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
  6991. ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
  6992. }
  6993. } }
  6994. return nw
  6995. }
  6996. function markedSpansAfter(old, endCh, isInsert) {
  6997. var nw;
  6998. if (old) { for (var i = 0; i < old.length; ++i) {
  6999. var span = old[i], marker = span.marker;
  7000. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
  7001. if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
  7002. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
  7003. ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
  7004. span.to == null ? null : span.to - endCh));
  7005. }
  7006. } }
  7007. return nw
  7008. }
  7009. // Given a change object, compute the new set of marker spans that
  7010. // cover the line in which the change took place. Removes spans
  7011. // entirely within the change, reconnects spans belonging to the
  7012. // same marker that appear on both sides of the change, and cuts off
  7013. // spans partially within the change. Returns an array of span
  7014. // arrays with one element for each line in (after) the change.
  7015. function stretchSpansOverChange(doc, change) {
  7016. if (change.full) { return null }
  7017. var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
  7018. var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
  7019. if (!oldFirst && !oldLast) { return null }
  7020. var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
  7021. // Get the spans that 'stick out' on both sides
  7022. var first = markedSpansBefore(oldFirst, startCh, isInsert);
  7023. var last = markedSpansAfter(oldLast, endCh, isInsert);
  7024. // Next, merge those two ends
  7025. var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
  7026. if (first) {
  7027. // Fix up .to properties of first
  7028. for (var i = 0; i < first.length; ++i) {
  7029. var span = first[i];
  7030. if (span.to == null) {
  7031. var found = getMarkedSpanFor(last, span.marker);
  7032. if (!found) { span.to = startCh; }
  7033. else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
  7034. }
  7035. }
  7036. }
  7037. if (last) {
  7038. // Fix up .from in last (or move them into first in case of sameLine)
  7039. for (var i$1 = 0; i$1 < last.length; ++i$1) {
  7040. var span$1 = last[i$1];
  7041. if (span$1.to != null) { span$1.to += offset; }
  7042. if (span$1.from == null) {
  7043. var found$1 = getMarkedSpanFor(first, span$1.marker);
  7044. if (!found$1) {
  7045. span$1.from = offset;
  7046. if (sameLine) { (first || (first = [])).push(span$1); }
  7047. }
  7048. } else {
  7049. span$1.from += offset;
  7050. if (sameLine) { (first || (first = [])).push(span$1); }
  7051. }
  7052. }
  7053. }
  7054. // Make sure we didn't create any zero-length spans
  7055. if (first) { first = clearEmptySpans(first); }
  7056. if (last && last != first) { last = clearEmptySpans(last); }
  7057. var newMarkers = [first];
  7058. if (!sameLine) {
  7059. // Fill gap with whole-line-spans
  7060. var gap = change.text.length - 2, gapMarkers;
  7061. if (gap > 0 && first)
  7062. { for (var i$2 = 0; i$2 < first.length; ++i$2)
  7063. { if (first[i$2].to == null)
  7064. { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
  7065. for (var i$3 = 0; i$3 < gap; ++i$3)
  7066. { newMarkers.push(gapMarkers); }
  7067. newMarkers.push(last);
  7068. }
  7069. return newMarkers
  7070. }
  7071. // Remove spans that are empty and don't have a clearWhenEmpty
  7072. // option of false.
  7073. function clearEmptySpans(spans) {
  7074. for (var i = 0; i < spans.length; ++i) {
  7075. var span = spans[i];
  7076. if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
  7077. { spans.splice(i--, 1); }
  7078. }
  7079. if (!spans.length) { return null }
  7080. return spans
  7081. }
  7082. // Used to 'clip' out readOnly ranges when making a change.
  7083. function removeReadOnlyRanges(doc, from, to) {
  7084. var markers = null;
  7085. doc.iter(from.line, to.line + 1, function (line) {
  7086. if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
  7087. var mark = line.markedSpans[i].marker;
  7088. if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
  7089. { (markers || (markers = [])).push(mark); }
  7090. } }
  7091. });
  7092. if (!markers) { return null }
  7093. var parts = [{from: from, to: to}];
  7094. for (var i = 0; i < markers.length; ++i) {
  7095. var mk = markers[i], m = mk.find(0);
  7096. for (var j = 0; j < parts.length; ++j) {
  7097. var p = parts[j];
  7098. if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
  7099. var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
  7100. if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
  7101. { newParts.push({from: p.from, to: m.from}); }
  7102. if (dto > 0 || !mk.inclusiveRight && !dto)
  7103. { newParts.push({from: m.to, to: p.to}); }
  7104. parts.splice.apply(parts, newParts);
  7105. j += newParts.length - 3;
  7106. }
  7107. }
  7108. return parts
  7109. }
  7110. // Connect or disconnect spans from a line.
  7111. function detachMarkedSpans(line) {
  7112. var spans = line.markedSpans;
  7113. if (!spans) { return }
  7114. for (var i = 0; i < spans.length; ++i)
  7115. { spans[i].marker.detachLine(line); }
  7116. line.markedSpans = null;
  7117. }
  7118. function attachMarkedSpans(line, spans) {
  7119. if (!spans) { return }
  7120. for (var i = 0; i < spans.length; ++i)
  7121. { spans[i].marker.attachLine(line); }
  7122. line.markedSpans = spans;
  7123. }
  7124. // Helpers used when computing which overlapping collapsed span
  7125. // counts as the larger one.
  7126. function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
  7127. function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
  7128. // Returns a number indicating which of two overlapping collapsed
  7129. // spans is larger (and thus includes the other). Falls back to
  7130. // comparing ids when the spans cover exactly the same range.
  7131. function compareCollapsedMarkers(a, b) {
  7132. var lenDiff = a.lines.length - b.lines.length;
  7133. if (lenDiff != 0) { return lenDiff }
  7134. var aPos = a.find(), bPos = b.find();
  7135. var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
  7136. if (fromCmp) { return -fromCmp }
  7137. var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
  7138. if (toCmp) { return toCmp }
  7139. return b.id - a.id
  7140. }
  7141. // Find out whether a line ends or starts in a collapsed span. If
  7142. // so, return the marker for that span.
  7143. function collapsedSpanAtSide(line, start) {
  7144. var sps = sawCollapsedSpans && line.markedSpans, found;
  7145. if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
  7146. sp = sps[i];
  7147. if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
  7148. (!found || compareCollapsedMarkers(found, sp.marker) < 0))
  7149. { found = sp.marker; }
  7150. } }
  7151. return found
  7152. }
  7153. function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
  7154. function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
  7155. function collapsedSpanAround(line, ch) {
  7156. var sps = sawCollapsedSpans && line.markedSpans, found;
  7157. if (sps) { for (var i = 0; i < sps.length; ++i) {
  7158. var sp = sps[i];
  7159. if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
  7160. (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker; }
  7161. } }
  7162. return found
  7163. }
  7164. // Test whether there exists a collapsed span that partially
  7165. // overlaps (covers the start or end, but not both) of a new span.
  7166. // Such overlap is not allowed.
  7167. function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
  7168. var line = getLine(doc, lineNo);
  7169. var sps = sawCollapsedSpans && line.markedSpans;
  7170. if (sps) { for (var i = 0; i < sps.length; ++i) {
  7171. var sp = sps[i];
  7172. if (!sp.marker.collapsed) { continue }
  7173. var found = sp.marker.find(0);
  7174. var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
  7175. var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
  7176. if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
  7177. if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
  7178. fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
  7179. { return true }
  7180. } }
  7181. }
  7182. // A visual line is a line as drawn on the screen. Folding, for
  7183. // example, can cause multiple logical lines to appear on the same
  7184. // visual line. This finds the start of the visual line that the
  7185. // given line is part of (usually that is the line itself).
  7186. function visualLine(line) {
  7187. var merged;
  7188. while (merged = collapsedSpanAtStart(line))
  7189. { line = merged.find(-1, true).line; }
  7190. return line
  7191. }
  7192. function visualLineEnd(line) {
  7193. var merged;
  7194. while (merged = collapsedSpanAtEnd(line))
  7195. { line = merged.find(1, true).line; }
  7196. return line
  7197. }
  7198. // Returns an array of logical lines that continue the visual line
  7199. // started by the argument, or undefined if there are no such lines.
  7200. function visualLineContinued(line) {
  7201. var merged, lines;
  7202. while (merged = collapsedSpanAtEnd(line)) {
  7203. line = merged.find(1, true).line
  7204. ;(lines || (lines = [])).push(line);
  7205. }
  7206. return lines
  7207. }
  7208. // Get the line number of the start of the visual line that the
  7209. // given line number is part of.
  7210. function visualLineNo(doc, lineN) {
  7211. var line = getLine(doc, lineN), vis = visualLine(line);
  7212. if (line == vis) { return lineN }
  7213. return lineNo(vis)
  7214. }
  7215. // Get the line number of the start of the next visual line after
  7216. // the given line.
  7217. function visualLineEndNo(doc, lineN) {
  7218. if (lineN > doc.lastLine()) { return lineN }
  7219. var line = getLine(doc, lineN), merged;
  7220. if (!lineIsHidden(doc, line)) { return lineN }
  7221. while (merged = collapsedSpanAtEnd(line))
  7222. { line = merged.find(1, true).line; }
  7223. return lineNo(line) + 1
  7224. }
  7225. // Compute whether a line is hidden. Lines count as hidden when they
  7226. // are part of a visual line that starts with another line, or when
  7227. // they are entirely covered by collapsed, non-widget span.
  7228. function lineIsHidden(doc, line) {
  7229. var sps = sawCollapsedSpans && line.markedSpans;
  7230. if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
  7231. sp = sps[i];
  7232. if (!sp.marker.collapsed) { continue }
  7233. if (sp.from == null) { return true }
  7234. if (sp.marker.widgetNode) { continue }
  7235. if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
  7236. { return true }
  7237. } }
  7238. }
  7239. function lineIsHiddenInner(doc, line, span) {
  7240. if (span.to == null) {
  7241. var end = span.marker.find(1, true);
  7242. return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
  7243. }
  7244. if (span.marker.inclusiveRight && span.to == line.text.length)
  7245. { return true }
  7246. for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
  7247. sp = line.markedSpans[i];
  7248. if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
  7249. (sp.to == null || sp.to != span.from) &&
  7250. (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
  7251. lineIsHiddenInner(doc, line, sp)) { return true }
  7252. }
  7253. }
  7254. // Find the height above the given line.
  7255. function heightAtLine(lineObj) {
  7256. lineObj = visualLine(lineObj);
  7257. var h = 0, chunk = lineObj.parent;
  7258. for (var i = 0; i < chunk.lines.length; ++i) {
  7259. var line = chunk.lines[i];
  7260. if (line == lineObj) { break }
  7261. else { h += line.height; }
  7262. }
  7263. for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
  7264. for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
  7265. var cur = p.children[i$1];
  7266. if (cur == chunk) { break }
  7267. else { h += cur.height; }
  7268. }
  7269. }
  7270. return h
  7271. }
  7272. // Compute the character length of a line, taking into account
  7273. // collapsed ranges (see markText) that might hide parts, and join
  7274. // other lines onto it.
  7275. function lineLength(line) {
  7276. if (line.height == 0) { return 0 }
  7277. var len = line.text.length, merged, cur = line;
  7278. while (merged = collapsedSpanAtStart(cur)) {
  7279. var found = merged.find(0, true);
  7280. cur = found.from.line;
  7281. len += found.from.ch - found.to.ch;
  7282. }
  7283. cur = line;
  7284. while (merged = collapsedSpanAtEnd(cur)) {
  7285. var found$1 = merged.find(0, true);
  7286. len -= cur.text.length - found$1.from.ch;
  7287. cur = found$1.to.line;
  7288. len += cur.text.length - found$1.to.ch;
  7289. }
  7290. return len
  7291. }
  7292. // Find the longest line in the document.
  7293. function findMaxLine(cm) {
  7294. var d = cm.display, doc = cm.doc;
  7295. d.maxLine = getLine(doc, doc.first);
  7296. d.maxLineLength = lineLength(d.maxLine);
  7297. d.maxLineChanged = true;
  7298. doc.iter(function (line) {
  7299. var len = lineLength(line);
  7300. if (len > d.maxLineLength) {
  7301. d.maxLineLength = len;
  7302. d.maxLine = line;
  7303. }
  7304. });
  7305. }
  7306. // LINE DATA STRUCTURE
  7307. // Line objects. These hold state related to a line, including
  7308. // highlighting info (the styles array).
  7309. var Line = function(text, markedSpans, estimateHeight) {
  7310. this.text = text;
  7311. attachMarkedSpans(this, markedSpans);
  7312. this.height = estimateHeight ? estimateHeight(this) : 1;
  7313. };
  7314. Line.prototype.lineNo = function () { return lineNo(this) };
  7315. eventMixin(Line);
  7316. // Change the content (text, markers) of a line. Automatically
  7317. // invalidates cached information and tries to re-estimate the
  7318. // line's height.
  7319. function updateLine(line, text, markedSpans, estimateHeight) {
  7320. line.text = text;
  7321. if (line.stateAfter) { line.stateAfter = null; }
  7322. if (line.styles) { line.styles = null; }
  7323. if (line.order != null) { line.order = null; }
  7324. detachMarkedSpans(line);
  7325. attachMarkedSpans(line, markedSpans);
  7326. var estHeight = estimateHeight ? estimateHeight(line) : 1;
  7327. if (estHeight != line.height) { updateLineHeight(line, estHeight); }
  7328. }
  7329. // Detach a line from the document tree and its markers.
  7330. function cleanUpLine(line) {
  7331. line.parent = null;
  7332. detachMarkedSpans(line);
  7333. }
  7334. // Convert a style as returned by a mode (either null, or a string
  7335. // containing one or more styles) to a CSS style. This is cached,
  7336. // and also looks for line-wide styles.
  7337. var styleToClassCache = {}, styleToClassCacheWithMode = {};
  7338. function interpretTokenStyle(style, options) {
  7339. if (!style || /^\s*$/.test(style)) { return null }
  7340. var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
  7341. return cache[style] ||
  7342. (cache[style] = style.replace(/\S+/g, "cm-$&"))
  7343. }
  7344. // Render the DOM representation of the text of a line. Also builds
  7345. // up a 'line map', which points at the DOM nodes that represent
  7346. // specific stretches of text, and is used by the measuring code.
  7347. // The returned object contains the DOM node, this map, and
  7348. // information about line-wide styles that were set by the mode.
  7349. function buildLineContent(cm, lineView) {
  7350. // The padding-right forces the element to have a 'border', which
  7351. // is needed on Webkit to be able to get line-level bounding
  7352. // rectangles for it (in measureChar).
  7353. var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
  7354. var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
  7355. col: 0, pos: 0, cm: cm,
  7356. trailingSpace: false,
  7357. splitSpaces: cm.getOption("lineWrapping")};
  7358. lineView.measure = {};
  7359. // Iterate over the logical lines that make up this visual line.
  7360. for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
  7361. var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0);
  7362. builder.pos = 0;
  7363. builder.addToken = buildToken;
  7364. // Optionally wire in some hacks into the token-rendering
  7365. // algorithm, to deal with browser quirks.
  7366. if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
  7367. { builder.addToken = buildTokenBadBidi(builder.addToken, order); }
  7368. builder.map = [];
  7369. var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
  7370. insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
  7371. if (line.styleClasses) {
  7372. if (line.styleClasses.bgClass)
  7373. { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); }
  7374. if (line.styleClasses.textClass)
  7375. { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); }
  7376. }
  7377. // Ensure at least a single node is present, for measuring.
  7378. if (builder.map.length == 0)
  7379. { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); }
  7380. // Store the map and a cache object for the current logical line
  7381. if (i == 0) {
  7382. lineView.measure.map = builder.map;
  7383. lineView.measure.cache = {};
  7384. } else {
  7385. (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
  7386. ;(lineView.measure.caches || (lineView.measure.caches = [])).push({});
  7387. }
  7388. }
  7389. // See issue #2901
  7390. if (webkit) {
  7391. var last = builder.content.lastChild;
  7392. if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
  7393. { builder.content.className = "cm-tab-wrap-hack"; }
  7394. }
  7395. signal(cm, "renderLine", cm, lineView.line, builder.pre);
  7396. if (builder.pre.className)
  7397. { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); }
  7398. return builder
  7399. }
  7400. function defaultSpecialCharPlaceholder(ch) {
  7401. var token = elt("span", "\u2022", "cm-invalidchar");
  7402. token.title = "\\u" + ch.charCodeAt(0).toString(16);
  7403. token.setAttribute("aria-label", token.title);
  7404. return token
  7405. }
  7406. // Build up the DOM representation for a single token, and add it to
  7407. // the line map. Takes care to render special characters separately.
  7408. function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
  7409. if (!text) { return }
  7410. var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
  7411. var special = builder.cm.state.specialChars, mustWrap = false;
  7412. var content;
  7413. if (!special.test(text)) {
  7414. builder.col += text.length;
  7415. content = document.createTextNode(displayText);
  7416. builder.map.push(builder.pos, builder.pos + text.length, content);
  7417. if (ie && ie_version < 9) { mustWrap = true; }
  7418. builder.pos += text.length;
  7419. } else {
  7420. content = document.createDocumentFragment();
  7421. var pos = 0;
  7422. while (true) {
  7423. special.lastIndex = pos;
  7424. var m = special.exec(text);
  7425. var skipped = m ? m.index - pos : text.length - pos;
  7426. if (skipped) {
  7427. var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
  7428. if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
  7429. else { content.appendChild(txt); }
  7430. builder.map.push(builder.pos, builder.pos + skipped, txt);
  7431. builder.col += skipped;
  7432. builder.pos += skipped;
  7433. }
  7434. if (!m) { break }
  7435. pos += skipped + 1;
  7436. var txt$1 = (void 0);
  7437. if (m[0] == "\t") {
  7438. var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
  7439. txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
  7440. txt$1.setAttribute("role", "presentation");
  7441. txt$1.setAttribute("cm-text", "\t");
  7442. builder.col += tabWidth;
  7443. } else if (m[0] == "\r" || m[0] == "\n") {
  7444. txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
  7445. txt$1.setAttribute("cm-text", m[0]);
  7446. builder.col += 1;
  7447. } else {
  7448. txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
  7449. txt$1.setAttribute("cm-text", m[0]);
  7450. if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
  7451. else { content.appendChild(txt$1); }
  7452. builder.col += 1;
  7453. }
  7454. builder.map.push(builder.pos, builder.pos + 1, txt$1);
  7455. builder.pos++;
  7456. }
  7457. }
  7458. builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
  7459. if (style || startStyle || endStyle || mustWrap || css) {
  7460. var fullStyle = style || "";
  7461. if (startStyle) { fullStyle += startStyle; }
  7462. if (endStyle) { fullStyle += endStyle; }
  7463. var token = elt("span", [content], fullStyle, css);
  7464. if (attributes) {
  7465. for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class")
  7466. { token.setAttribute(attr, attributes[attr]); } }
  7467. }
  7468. return builder.content.appendChild(token)
  7469. }
  7470. builder.content.appendChild(content);
  7471. }
  7472. // Change some spaces to NBSP to prevent the browser from collapsing
  7473. // trailing spaces at the end of a line when rendering text (issue #1362).
  7474. function splitSpaces(text, trailingBefore) {
  7475. if (text.length > 1 && !/ /.test(text)) { return text }
  7476. var spaceBefore = trailingBefore, result = "";
  7477. for (var i = 0; i < text.length; i++) {
  7478. var ch = text.charAt(i);
  7479. if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
  7480. { ch = "\u00a0"; }
  7481. result += ch;
  7482. spaceBefore = ch == " ";
  7483. }
  7484. return result
  7485. }
  7486. // Work around nonsense dimensions being reported for stretches of
  7487. // right-to-left text.
  7488. function buildTokenBadBidi(inner, order) {
  7489. return function (builder, text, style, startStyle, endStyle, css, attributes) {
  7490. style = style ? style + " cm-force-border" : "cm-force-border";
  7491. var start = builder.pos, end = start + text.length;
  7492. for (;;) {
  7493. // Find the part that overlaps with the start of this text
  7494. var part = (void 0);
  7495. for (var i = 0; i < order.length; i++) {
  7496. part = order[i];
  7497. if (part.to > start && part.from <= start) { break }
  7498. }
  7499. if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, css, attributes) }
  7500. inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);
  7501. startStyle = null;
  7502. text = text.slice(part.to - start);
  7503. start = part.to;
  7504. }
  7505. }
  7506. }
  7507. function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
  7508. var widget = !ignoreWidget && marker.widgetNode;
  7509. if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); }
  7510. if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
  7511. if (!widget)
  7512. { widget = builder.content.appendChild(document.createElement("span")); }
  7513. widget.setAttribute("cm-marker", marker.id);
  7514. }
  7515. if (widget) {
  7516. builder.cm.display.input.setUneditable(widget);
  7517. builder.content.appendChild(widget);
  7518. }
  7519. builder.pos += size;
  7520. builder.trailingSpace = false;
  7521. }
  7522. // Outputs a number of spans to make up a line, taking highlighting
  7523. // and marked text into account.
  7524. function insertLineContent(line, builder, styles) {
  7525. var spans = line.markedSpans, allText = line.text, at = 0;
  7526. if (!spans) {
  7527. for (var i$1 = 1; i$1 < styles.length; i$1+=2)
  7528. { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); }
  7529. return
  7530. }
  7531. var len = allText.length, pos = 0, i = 1, text = "", style, css;
  7532. var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes;
  7533. for (;;) {
  7534. if (nextChange == pos) { // Update current marker set
  7535. spanStyle = spanEndStyle = spanStartStyle = css = "";
  7536. attributes = null;
  7537. collapsed = null; nextChange = Infinity;
  7538. var foundBookmarks = [], endStyles = (void 0);
  7539. for (var j = 0; j < spans.length; ++j) {
  7540. var sp = spans[j], m = sp.marker;
  7541. if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
  7542. foundBookmarks.push(m);
  7543. } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
  7544. if (sp.to != null && sp.to != pos && nextChange > sp.to) {
  7545. nextChange = sp.to;
  7546. spanEndStyle = "";
  7547. }
  7548. if (m.className) { spanStyle += " " + m.className; }
  7549. if (m.css) { css = (css ? css + ";" : "") + m.css; }
  7550. if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; }
  7551. if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); }
  7552. // support for the old title property
  7553. // https://github.com/codemirror/CodeMirror/pull/5673
  7554. if (m.title) { (attributes || (attributes = {})).title = m.title; }
  7555. if (m.attributes) {
  7556. for (var attr in m.attributes)
  7557. { (attributes || (attributes = {}))[attr] = m.attributes[attr]; }
  7558. }
  7559. if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
  7560. { collapsed = sp; }
  7561. } else if (sp.from > pos && nextChange > sp.from) {
  7562. nextChange = sp.from;
  7563. }
  7564. }
  7565. if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
  7566. { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } }
  7567. if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
  7568. { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } }
  7569. if (collapsed && (collapsed.from || 0) == pos) {
  7570. buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
  7571. collapsed.marker, collapsed.from == null);
  7572. if (collapsed.to == null) { return }
  7573. if (collapsed.to == pos) { collapsed = false; }
  7574. }
  7575. }
  7576. if (pos >= len) { break }
  7577. var upto = Math.min(len, nextChange);
  7578. while (true) {
  7579. if (text) {
  7580. var end = pos + text.length;
  7581. if (!collapsed) {
  7582. var tokenText = end > upto ? text.slice(0, upto - pos) : text;
  7583. builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
  7584. spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", css, attributes);
  7585. }
  7586. if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
  7587. pos = end;
  7588. spanStartStyle = "";
  7589. }
  7590. text = allText.slice(at, at = styles[i++]);
  7591. style = interpretTokenStyle(styles[i++], builder.cm.options);
  7592. }
  7593. }
  7594. }
  7595. // These objects are used to represent the visible (currently drawn)
  7596. // part of the document. A LineView may correspond to multiple
  7597. // logical lines, if those are connected by collapsed ranges.
  7598. function LineView(doc, line, lineN) {
  7599. // The starting line
  7600. this.line = line;
  7601. // Continuing lines, if any
  7602. this.rest = visualLineContinued(line);
  7603. // Number of logical lines in this visual line
  7604. this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
  7605. this.node = this.text = null;
  7606. this.hidden = lineIsHidden(doc, line);
  7607. }
  7608. // Create a range of LineView objects for the given lines.
  7609. function buildViewArray(cm, from, to) {
  7610. var array = [], nextPos;
  7611. for (var pos = from; pos < to; pos = nextPos) {
  7612. var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
  7613. nextPos = pos + view.size;
  7614. array.push(view);
  7615. }
  7616. return array
  7617. }
  7618. var operationGroup = null;
  7619. function pushOperation(op) {
  7620. if (operationGroup) {
  7621. operationGroup.ops.push(op);
  7622. } else {
  7623. op.ownsGroup = operationGroup = {
  7624. ops: [op],
  7625. delayedCallbacks: []
  7626. };
  7627. }
  7628. }
  7629. function fireCallbacksForOps(group) {
  7630. // Calls delayed callbacks and cursorActivity handlers until no
  7631. // new ones appear
  7632. var callbacks = group.delayedCallbacks, i = 0;
  7633. do {
  7634. for (; i < callbacks.length; i++)
  7635. { callbacks[i].call(null); }
  7636. for (var j = 0; j < group.ops.length; j++) {
  7637. var op = group.ops[j];
  7638. if (op.cursorActivityHandlers)
  7639. { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
  7640. { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } }
  7641. }
  7642. } while (i < callbacks.length)
  7643. }
  7644. function finishOperation(op, endCb) {
  7645. var group = op.ownsGroup;
  7646. if (!group) { return }
  7647. try { fireCallbacksForOps(group); }
  7648. finally {
  7649. operationGroup = null;
  7650. endCb(group);
  7651. }
  7652. }
  7653. var orphanDelayedCallbacks = null;
  7654. // Often, we want to signal events at a point where we are in the
  7655. // middle of some work, but don't want the handler to start calling
  7656. // other methods on the editor, which might be in an inconsistent
  7657. // state or simply not expect any other events to happen.
  7658. // signalLater looks whether there are any handlers, and schedules
  7659. // them to be executed when the last operation ends, or, if no
  7660. // operation is active, when a timeout fires.
  7661. function signalLater(emitter, type /*, values...*/) {
  7662. var arr = getHandlers(emitter, type);
  7663. if (!arr.length) { return }
  7664. var args = Array.prototype.slice.call(arguments, 2), list;
  7665. if (operationGroup) {
  7666. list = operationGroup.delayedCallbacks;
  7667. } else if (orphanDelayedCallbacks) {
  7668. list = orphanDelayedCallbacks;
  7669. } else {
  7670. list = orphanDelayedCallbacks = [];
  7671. setTimeout(fireOrphanDelayed, 0);
  7672. }
  7673. var loop = function ( i ) {
  7674. list.push(function () { return arr[i].apply(null, args); });
  7675. };
  7676. for (var i = 0; i < arr.length; ++i)
  7677. loop( i );
  7678. }
  7679. function fireOrphanDelayed() {
  7680. var delayed = orphanDelayedCallbacks;
  7681. orphanDelayedCallbacks = null;
  7682. for (var i = 0; i < delayed.length; ++i) { delayed[i](); }
  7683. }
  7684. // When an aspect of a line changes, a string is added to
  7685. // lineView.changes. This updates the relevant part of the line's
  7686. // DOM structure.
  7687. function updateLineForChanges(cm, lineView, lineN, dims) {
  7688. for (var j = 0; j < lineView.changes.length; j++) {
  7689. var type = lineView.changes[j];
  7690. if (type == "text") { updateLineText(cm, lineView); }
  7691. else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); }
  7692. else if (type == "class") { updateLineClasses(cm, lineView); }
  7693. else if (type == "widget") { updateLineWidgets(cm, lineView, dims); }
  7694. }
  7695. lineView.changes = null;
  7696. }
  7697. // Lines with gutter elements, widgets or a background class need to
  7698. // be wrapped, and have the extra elements added to the wrapper div
  7699. function ensureLineWrapped(lineView) {
  7700. if (lineView.node == lineView.text) {
  7701. lineView.node = elt("div", null, null, "position: relative");
  7702. if (lineView.text.parentNode)
  7703. { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); }
  7704. lineView.node.appendChild(lineView.text);
  7705. if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; }
  7706. }
  7707. return lineView.node
  7708. }
  7709. function updateLineBackground(cm, lineView) {
  7710. var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
  7711. if (cls) { cls += " CodeMirror-linebackground"; }
  7712. if (lineView.background) {
  7713. if (cls) { lineView.background.className = cls; }
  7714. else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
  7715. } else if (cls) {
  7716. var wrap = ensureLineWrapped(lineView);
  7717. lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
  7718. cm.display.input.setUneditable(lineView.background);
  7719. }
  7720. }
  7721. // Wrapper around buildLineContent which will reuse the structure
  7722. // in display.externalMeasured when possible.
  7723. function getLineContent(cm, lineView) {
  7724. var ext = cm.display.externalMeasured;
  7725. if (ext && ext.line == lineView.line) {
  7726. cm.display.externalMeasured = null;
  7727. lineView.measure = ext.measure;
  7728. return ext.built
  7729. }
  7730. return buildLineContent(cm, lineView)
  7731. }
  7732. // Redraw the line's text. Interacts with the background and text
  7733. // classes because the mode may output tokens that influence these
  7734. // classes.
  7735. function updateLineText(cm, lineView) {
  7736. var cls = lineView.text.className;
  7737. var built = getLineContent(cm, lineView);
  7738. if (lineView.text == lineView.node) { lineView.node = built.pre; }
  7739. lineView.text.parentNode.replaceChild(built.pre, lineView.text);
  7740. lineView.text = built.pre;
  7741. if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
  7742. lineView.bgClass = built.bgClass;
  7743. lineView.textClass = built.textClass;
  7744. updateLineClasses(cm, lineView);
  7745. } else if (cls) {
  7746. lineView.text.className = cls;
  7747. }
  7748. }
  7749. function updateLineClasses(cm, lineView) {
  7750. updateLineBackground(cm, lineView);
  7751. if (lineView.line.wrapClass)
  7752. { ensureLineWrapped(lineView).className = lineView.line.wrapClass; }
  7753. else if (lineView.node != lineView.text)
  7754. { lineView.node.className = ""; }
  7755. var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
  7756. lineView.text.className = textClass || "";
  7757. }
  7758. function updateLineGutter(cm, lineView, lineN, dims) {
  7759. if (lineView.gutter) {
  7760. lineView.node.removeChild(lineView.gutter);
  7761. lineView.gutter = null;
  7762. }
  7763. if (lineView.gutterBackground) {
  7764. lineView.node.removeChild(lineView.gutterBackground);
  7765. lineView.gutterBackground = null;
  7766. }
  7767. if (lineView.line.gutterClass) {
  7768. var wrap = ensureLineWrapped(lineView);
  7769. lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
  7770. ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"));
  7771. cm.display.input.setUneditable(lineView.gutterBackground);
  7772. wrap.insertBefore(lineView.gutterBackground, lineView.text);
  7773. }
  7774. var markers = lineView.line.gutterMarkers;
  7775. if (cm.options.lineNumbers || markers) {
  7776. var wrap$1 = ensureLineWrapped(lineView);
  7777. var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
  7778. cm.display.input.setUneditable(gutterWrap);
  7779. wrap$1.insertBefore(gutterWrap, lineView.text);
  7780. if (lineView.line.gutterClass)
  7781. { gutterWrap.className += " " + lineView.line.gutterClass; }
  7782. if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
  7783. { lineView.lineNumber = gutterWrap.appendChild(
  7784. elt("div", lineNumberFor(cm.options, lineN),
  7785. "CodeMirror-linenumber CodeMirror-gutter-elt",
  7786. ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); }
  7787. if (markers) { for (var k = 0; k < cm.display.gutterSpecs.length; ++k) {
  7788. var id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id];
  7789. if (found)
  7790. { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
  7791. ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); }
  7792. } }
  7793. }
  7794. }
  7795. function updateLineWidgets(cm, lineView, dims) {
  7796. if (lineView.alignable) { lineView.alignable = null; }
  7797. var isWidget = classTest("CodeMirror-linewidget");
  7798. for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
  7799. next = node.nextSibling;
  7800. if (isWidget.test(node.className)) { lineView.node.removeChild(node); }
  7801. }
  7802. insertLineWidgets(cm, lineView, dims);
  7803. }
  7804. // Build a line's DOM representation from scratch
  7805. function buildLineElement(cm, lineView, lineN, dims) {
  7806. var built = getLineContent(cm, lineView);
  7807. lineView.text = lineView.node = built.pre;
  7808. if (built.bgClass) { lineView.bgClass = built.bgClass; }
  7809. if (built.textClass) { lineView.textClass = built.textClass; }
  7810. updateLineClasses(cm, lineView);
  7811. updateLineGutter(cm, lineView, lineN, dims);
  7812. insertLineWidgets(cm, lineView, dims);
  7813. return lineView.node
  7814. }
  7815. // A lineView may contain multiple logical lines (when merged by
  7816. // collapsed spans). The widgets for all of them need to be drawn.
  7817. function insertLineWidgets(cm, lineView, dims) {
  7818. insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
  7819. if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
  7820. { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } }
  7821. }
  7822. function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
  7823. if (!line.widgets) { return }
  7824. var wrap = ensureLineWrapped(lineView);
  7825. for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
  7826. var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""));
  7827. if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); }
  7828. positionLineWidget(widget, node, lineView, dims);
  7829. cm.display.input.setUneditable(node);
  7830. if (allowAbove && widget.above)
  7831. { wrap.insertBefore(node, lineView.gutter || lineView.text); }
  7832. else
  7833. { wrap.appendChild(node); }
  7834. signalLater(widget, "redraw");
  7835. }
  7836. }
  7837. function positionLineWidget(widget, node, lineView, dims) {
  7838. if (widget.noHScroll) {
  7839. (lineView.alignable || (lineView.alignable = [])).push(node);
  7840. var width = dims.wrapperWidth;
  7841. node.style.left = dims.fixedPos + "px";
  7842. if (!widget.coverGutter) {
  7843. width -= dims.gutterTotalWidth;
  7844. node.style.paddingLeft = dims.gutterTotalWidth + "px";
  7845. }
  7846. node.style.width = width + "px";
  7847. }
  7848. if (widget.coverGutter) {
  7849. node.style.zIndex = 5;
  7850. node.style.position = "relative";
  7851. if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; }
  7852. }
  7853. }
  7854. function widgetHeight(widget) {
  7855. if (widget.height != null) { return widget.height }
  7856. var cm = widget.doc.cm;
  7857. if (!cm) { return 0 }
  7858. if (!contains(document.body, widget.node)) {
  7859. var parentStyle = "position: relative;";
  7860. if (widget.coverGutter)
  7861. { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; }
  7862. if (widget.noHScroll)
  7863. { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; }
  7864. removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
  7865. }
  7866. return widget.height = widget.node.parentNode.offsetHeight
  7867. }
  7868. // Return true when the given mouse event happened in a widget
  7869. function eventInWidget(display, e) {
  7870. for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
  7871. if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
  7872. (n.parentNode == display.sizer && n != display.mover))
  7873. { return true }
  7874. }
  7875. }
  7876. // POSITION MEASUREMENT
  7877. function paddingTop(display) {return display.lineSpace.offsetTop}
  7878. function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
  7879. function paddingH(display) {
  7880. if (display.cachedPaddingH) { return display.cachedPaddingH }
  7881. var e = removeChildrenAndAdd(display.measure, elt("pre", "x", "CodeMirror-line-like"));
  7882. var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
  7883. var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
  7884. if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; }
  7885. return data
  7886. }
  7887. function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
  7888. function displayWidth(cm) {
  7889. return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
  7890. }
  7891. function displayHeight(cm) {
  7892. return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
  7893. }
  7894. // Ensure the lineView.wrapping.heights array is populated. This is
  7895. // an array of bottom offsets for the lines that make up a drawn
  7896. // line. When lineWrapping is on, there might be more than one
  7897. // height.
  7898. function ensureLineHeights(cm, lineView, rect) {
  7899. var wrapping = cm.options.lineWrapping;
  7900. var curWidth = wrapping && displayWidth(cm);
  7901. if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
  7902. var heights = lineView.measure.heights = [];
  7903. if (wrapping) {
  7904. lineView.measure.width = curWidth;
  7905. var rects = lineView.text.firstChild.getClientRects();
  7906. for (var i = 0; i < rects.length - 1; i++) {
  7907. var cur = rects[i], next = rects[i + 1];
  7908. if (Math.abs(cur.bottom - next.bottom) > 2)
  7909. { heights.push((cur.bottom + next.top) / 2 - rect.top); }
  7910. }
  7911. }
  7912. heights.push(rect.bottom - rect.top);
  7913. }
  7914. }
  7915. // Find a line map (mapping character offsets to text nodes) and a
  7916. // measurement cache for the given line number. (A line view might
  7917. // contain multiple lines when collapsed ranges are present.)
  7918. function mapFromLineView(lineView, line, lineN) {
  7919. if (lineView.line == line)
  7920. { return {map: lineView.measure.map, cache: lineView.measure.cache} }
  7921. for (var i = 0; i < lineView.rest.length; i++)
  7922. { if (lineView.rest[i] == line)
  7923. { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
  7924. for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
  7925. { if (lineNo(lineView.rest[i$1]) > lineN)
  7926. { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
  7927. }
  7928. // Render a line into the hidden node display.externalMeasured. Used
  7929. // when measurement is needed for a line that's not in the viewport.
  7930. function updateExternalMeasurement(cm, line) {
  7931. line = visualLine(line);
  7932. var lineN = lineNo(line);
  7933. var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
  7934. view.lineN = lineN;
  7935. var built = view.built = buildLineContent(cm, view);
  7936. view.text = built.pre;
  7937. removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
  7938. return view
  7939. }
  7940. // Get a {top, bottom, left, right} box (in line-local coordinates)
  7941. // for a given character.
  7942. function measureChar(cm, line, ch, bias) {
  7943. return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
  7944. }
  7945. // Find a line view that corresponds to the given line number.
  7946. function findViewForLine(cm, lineN) {
  7947. if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
  7948. { return cm.display.view[findViewIndex(cm, lineN)] }
  7949. var ext = cm.display.externalMeasured;
  7950. if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
  7951. { return ext }
  7952. }
  7953. // Measurement can be split in two steps, the set-up work that
  7954. // applies to the whole line, and the measurement of the actual
  7955. // character. Functions like coordsChar, that need to do a lot of
  7956. // measurements in a row, can thus ensure that the set-up work is
  7957. // only done once.
  7958. function prepareMeasureForLine(cm, line) {
  7959. var lineN = lineNo(line);
  7960. var view = findViewForLine(cm, lineN);
  7961. if (view && !view.text) {
  7962. view = null;
  7963. } else if (view && view.changes) {
  7964. updateLineForChanges(cm, view, lineN, getDimensions(cm));
  7965. cm.curOp.forceUpdate = true;
  7966. }
  7967. if (!view)
  7968. { view = updateExternalMeasurement(cm, line); }
  7969. var info = mapFromLineView(view, line, lineN);
  7970. return {
  7971. line: line, view: view, rect: null,
  7972. map: info.map, cache: info.cache, before: info.before,
  7973. hasHeights: false
  7974. }
  7975. }
  7976. // Given a prepared measurement object, measures the position of an
  7977. // actual character (or fetches it from the cache).
  7978. function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
  7979. if (prepared.before) { ch = -1; }
  7980. var key = ch + (bias || ""), found;
  7981. if (prepared.cache.hasOwnProperty(key)) {
  7982. found = prepared.cache[key];
  7983. } else {
  7984. if (!prepared.rect)
  7985. { prepared.rect = prepared.view.text.getBoundingClientRect(); }
  7986. if (!prepared.hasHeights) {
  7987. ensureLineHeights(cm, prepared.view, prepared.rect);
  7988. prepared.hasHeights = true;
  7989. }
  7990. found = measureCharInner(cm, prepared, ch, bias);
  7991. if (!found.bogus) { prepared.cache[key] = found; }
  7992. }
  7993. return {left: found.left, right: found.right,
  7994. top: varHeight ? found.rtop : found.top,
  7995. bottom: varHeight ? found.rbottom : found.bottom}
  7996. }
  7997. var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
  7998. function nodeAndOffsetInLineMap(map, ch, bias) {
  7999. var node, start, end, collapse, mStart, mEnd;
  8000. // First, search the line map for the text node corresponding to,
  8001. // or closest to, the target character.
  8002. for (var i = 0; i < map.length; i += 3) {
  8003. mStart = map[i];
  8004. mEnd = map[i + 1];
  8005. if (ch < mStart) {
  8006. start = 0; end = 1;
  8007. collapse = "left";
  8008. } else if (ch < mEnd) {
  8009. start = ch - mStart;
  8010. end = start + 1;
  8011. } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
  8012. end = mEnd - mStart;
  8013. start = end - 1;
  8014. if (ch >= mEnd) { collapse = "right"; }
  8015. }
  8016. if (start != null) {
  8017. node = map[i + 2];
  8018. if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
  8019. { collapse = bias; }
  8020. if (bias == "left" && start == 0)
  8021. { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
  8022. node = map[(i -= 3) + 2];
  8023. collapse = "left";
  8024. } }
  8025. if (bias == "right" && start == mEnd - mStart)
  8026. { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
  8027. node = map[(i += 3) + 2];
  8028. collapse = "right";
  8029. } }
  8030. break
  8031. }
  8032. }
  8033. return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
  8034. }
  8035. function getUsefulRect(rects, bias) {
  8036. var rect = nullRect;
  8037. if (bias == "left") { for (var i = 0; i < rects.length; i++) {
  8038. if ((rect = rects[i]).left != rect.right) { break }
  8039. } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
  8040. if ((rect = rects[i$1]).left != rect.right) { break }
  8041. } }
  8042. return rect
  8043. }
  8044. function measureCharInner(cm, prepared, ch, bias) {
  8045. var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
  8046. var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
  8047. var rect;
  8048. if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
  8049. for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
  8050. while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; }
  8051. while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; }
  8052. if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
  8053. { rect = node.parentNode.getBoundingClientRect(); }
  8054. else
  8055. { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); }
  8056. if (rect.left || rect.right || start == 0) { break }
  8057. end = start;
  8058. start = start - 1;
  8059. collapse = "right";
  8060. }
  8061. if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); }
  8062. } else { // If it is a widget, simply get the box for the whole widget.
  8063. if (start > 0) { collapse = bias = "right"; }
  8064. var rects;
  8065. if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
  8066. { rect = rects[bias == "right" ? rects.length - 1 : 0]; }
  8067. else
  8068. { rect = node.getBoundingClientRect(); }
  8069. }
  8070. if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
  8071. var rSpan = node.parentNode.getClientRects()[0];
  8072. if (rSpan)
  8073. { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; }
  8074. else
  8075. { rect = nullRect; }
  8076. }
  8077. var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
  8078. var mid = (rtop + rbot) / 2;
  8079. var heights = prepared.view.measure.heights;
  8080. var i = 0;
  8081. for (; i < heights.length - 1; i++)
  8082. { if (mid < heights[i]) { break } }
  8083. var top = i ? heights[i - 1] : 0, bot = heights[i];
  8084. var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
  8085. right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
  8086. top: top, bottom: bot};
  8087. if (!rect.left && !rect.right) { result.bogus = true; }
  8088. if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
  8089. return result
  8090. }
  8091. // Work around problem with bounding client rects on ranges being
  8092. // returned incorrectly when zoomed on IE10 and below.
  8093. function maybeUpdateRectForZooming(measure, rect) {
  8094. if (!window.screen || screen.logicalXDPI == null ||
  8095. screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
  8096. { return rect }
  8097. var scaleX = screen.logicalXDPI / screen.deviceXDPI;
  8098. var scaleY = screen.logicalYDPI / screen.deviceYDPI;
  8099. return {left: rect.left * scaleX, right: rect.right * scaleX,
  8100. top: rect.top * scaleY, bottom: rect.bottom * scaleY}
  8101. }
  8102. function clearLineMeasurementCacheFor(lineView) {
  8103. if (lineView.measure) {
  8104. lineView.measure.cache = {};
  8105. lineView.measure.heights = null;
  8106. if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
  8107. { lineView.measure.caches[i] = {}; } }
  8108. }
  8109. }
  8110. function clearLineMeasurementCache(cm) {
  8111. cm.display.externalMeasure = null;
  8112. removeChildren(cm.display.lineMeasure);
  8113. for (var i = 0; i < cm.display.view.length; i++)
  8114. { clearLineMeasurementCacheFor(cm.display.view[i]); }
  8115. }
  8116. function clearCaches(cm) {
  8117. clearLineMeasurementCache(cm);
  8118. cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
  8119. if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; }
  8120. cm.display.lineNumChars = null;
  8121. }
  8122. function pageScrollX() {
  8123. // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
  8124. // which causes page_Offset and bounding client rects to use
  8125. // different reference viewports and invalidate our calculations.
  8126. if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
  8127. return window.pageXOffset || (document.documentElement || document.body).scrollLeft
  8128. }
  8129. function pageScrollY() {
  8130. if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
  8131. return window.pageYOffset || (document.documentElement || document.body).scrollTop
  8132. }
  8133. function widgetTopHeight(lineObj) {
  8134. var height = 0;
  8135. if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
  8136. { height += widgetHeight(lineObj.widgets[i]); } } }
  8137. return height
  8138. }
  8139. // Converts a {top, bottom, left, right} box from line-local
  8140. // coordinates into another coordinate system. Context may be one of
  8141. // "line", "div" (display.lineDiv), "local"./null (editor), "window",
  8142. // or "page".
  8143. function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
  8144. if (!includeWidgets) {
  8145. var height = widgetTopHeight(lineObj);
  8146. rect.top += height; rect.bottom += height;
  8147. }
  8148. if (context == "line") { return rect }
  8149. if (!context) { context = "local"; }
  8150. var yOff = heightAtLine(lineObj);
  8151. if (context == "local") { yOff += paddingTop(cm.display); }
  8152. else { yOff -= cm.display.viewOffset; }
  8153. if (context == "page" || context == "window") {
  8154. var lOff = cm.display.lineSpace.getBoundingClientRect();
  8155. yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
  8156. var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
  8157. rect.left += xOff; rect.right += xOff;
  8158. }
  8159. rect.top += yOff; rect.bottom += yOff;
  8160. return rect
  8161. }
  8162. // Coverts a box from "div" coords to another coordinate system.
  8163. // Context may be "window", "page", "div", or "local"./null.
  8164. function fromCoordSystem(cm, coords, context) {
  8165. if (context == "div") { return coords }
  8166. var left = coords.left, top = coords.top;
  8167. // First move into "page" coordinate system
  8168. if (context == "page") {
  8169. left -= pageScrollX();
  8170. top -= pageScrollY();
  8171. } else if (context == "local" || !context) {
  8172. var localBox = cm.display.sizer.getBoundingClientRect();
  8173. left += localBox.left;
  8174. top += localBox.top;
  8175. }
  8176. var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
  8177. return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
  8178. }
  8179. function charCoords(cm, pos, context, lineObj, bias) {
  8180. if (!lineObj) { lineObj = getLine(cm.doc, pos.line); }
  8181. return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
  8182. }
  8183. // Returns a box for a given cursor position, which may have an
  8184. // 'other' property containing the position of the secondary cursor
  8185. // on a bidi boundary.
  8186. // A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
  8187. // and after `char - 1` in writing order of `char - 1`
  8188. // A cursor Pos(line, char, "after") is on the same visual line as `char`
  8189. // and before `char` in writing order of `char`
  8190. // Examples (upper-case letters are RTL, lower-case are LTR):
  8191. // Pos(0, 1, ...)
  8192. // before after
  8193. // ab a|b a|b
  8194. // aB a|B aB|
  8195. // Ab |Ab A|b
  8196. // AB B|A B|A
  8197. // Every position after the last character on a line is considered to stick
  8198. // to the last character on the line.
  8199. function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
  8200. lineObj = lineObj || getLine(cm.doc, pos.line);
  8201. if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
  8202. function get(ch, right) {
  8203. var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
  8204. if (right) { m.left = m.right; } else { m.right = m.left; }
  8205. return intoCoordSystem(cm, lineObj, m, context)
  8206. }
  8207. var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
  8208. if (ch >= lineObj.text.length) {
  8209. ch = lineObj.text.length;
  8210. sticky = "before";
  8211. } else if (ch <= 0) {
  8212. ch = 0;
  8213. sticky = "after";
  8214. }
  8215. if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
  8216. function getBidi(ch, partPos, invert) {
  8217. var part = order[partPos], right = part.level == 1;
  8218. return get(invert ? ch - 1 : ch, right != invert)
  8219. }
  8220. var partPos = getBidiPartAt(order, ch, sticky);
  8221. var other = bidiOther;
  8222. var val = getBidi(ch, partPos, sticky == "before");
  8223. if (other != null) { val.other = getBidi(ch, other, sticky != "before"); }
  8224. return val
  8225. }
  8226. // Used to cheaply estimate the coordinates for a position. Used for
  8227. // intermediate scroll updates.
  8228. function estimateCoords(cm, pos) {
  8229. var left = 0;
  8230. pos = clipPos(cm.doc, pos);
  8231. if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; }
  8232. var lineObj = getLine(cm.doc, pos.line);
  8233. var top = heightAtLine(lineObj) + paddingTop(cm.display);
  8234. return {left: left, right: left, top: top, bottom: top + lineObj.height}
  8235. }
  8236. // Positions returned by coordsChar contain some extra information.
  8237. // xRel is the relative x position of the input coordinates compared
  8238. // to the found position (so xRel > 0 means the coordinates are to
  8239. // the right of the character position, for example). When outside
  8240. // is true, that means the coordinates lie outside the line's
  8241. // vertical range.
  8242. function PosWithInfo(line, ch, sticky, outside, xRel) {
  8243. var pos = Pos(line, ch, sticky);
  8244. pos.xRel = xRel;
  8245. if (outside) { pos.outside = outside; }
  8246. return pos
  8247. }
  8248. // Compute the character position closest to the given coordinates.
  8249. // Input must be lineSpace-local ("div" coordinate system).
  8250. function coordsChar(cm, x, y) {
  8251. var doc = cm.doc;
  8252. y += cm.display.viewOffset;
  8253. if (y < 0) { return PosWithInfo(doc.first, 0, null, -1, -1) }
  8254. var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
  8255. if (lineN > last)
  8256. { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1) }
  8257. if (x < 0) { x = 0; }
  8258. var lineObj = getLine(doc, lineN);
  8259. for (;;) {
  8260. var found = coordsCharInner(cm, lineObj, lineN, x, y);
  8261. var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0));
  8262. if (!collapsed) { return found }
  8263. var rangeEnd = collapsed.find(1);
  8264. if (rangeEnd.line == lineN) { return rangeEnd }
  8265. lineObj = getLine(doc, lineN = rangeEnd.line);
  8266. }
  8267. }
  8268. function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
  8269. y -= widgetTopHeight(lineObj);
  8270. var end = lineObj.text.length;
  8271. var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0);
  8272. end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end);
  8273. return {begin: begin, end: end}
  8274. }
  8275. function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
  8276. if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
  8277. var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
  8278. return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
  8279. }
  8280. // Returns true if the given side of a box is after the given
  8281. // coordinates, in top-to-bottom, left-to-right order.
  8282. function boxIsAfter(box, x, y, left) {
  8283. return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
  8284. }
  8285. function coordsCharInner(cm, lineObj, lineNo, x, y) {
  8286. // Move y into line-local coordinate space
  8287. y -= heightAtLine(lineObj);
  8288. var preparedMeasure = prepareMeasureForLine(cm, lineObj);
  8289. // When directly calling `measureCharPrepared`, we have to adjust
  8290. // for the widgets at this line.
  8291. var widgetHeight = widgetTopHeight(lineObj);
  8292. var begin = 0, end = lineObj.text.length, ltr = true;
  8293. var order = getOrder(lineObj, cm.doc.direction);
  8294. // If the line isn't plain left-to-right text, first figure out
  8295. // which bidi section the coordinates fall into.
  8296. if (order) {
  8297. var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
  8298. (cm, lineObj, lineNo, preparedMeasure, order, x, y);
  8299. ltr = part.level != 1;
  8300. // The awkward -1 offsets are needed because findFirst (called
  8301. // on these below) will treat its first bound as inclusive,
  8302. // second as exclusive, but we want to actually address the
  8303. // characters in the part's range
  8304. begin = ltr ? part.from : part.to - 1;
  8305. end = ltr ? part.to : part.from - 1;
  8306. }
  8307. // A binary search to find the first character whose bounding box
  8308. // starts after the coordinates. If we run across any whose box wrap
  8309. // the coordinates, store that.
  8310. var chAround = null, boxAround = null;
  8311. var ch = findFirst(function (ch) {
  8312. var box = measureCharPrepared(cm, preparedMeasure, ch);
  8313. box.top += widgetHeight; box.bottom += widgetHeight;
  8314. if (!boxIsAfter(box, x, y, false)) { return false }
  8315. if (box.top <= y && box.left <= x) {
  8316. chAround = ch;
  8317. boxAround = box;
  8318. }
  8319. return true
  8320. }, begin, end);
  8321. var baseX, sticky, outside = false;
  8322. // If a box around the coordinates was found, use that
  8323. if (boxAround) {
  8324. // Distinguish coordinates nearer to the left or right side of the box
  8325. var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr;
  8326. ch = chAround + (atStart ? 0 : 1);
  8327. sticky = atStart ? "after" : "before";
  8328. baseX = atLeft ? boxAround.left : boxAround.right;
  8329. } else {
  8330. // (Adjust for extended bound, if necessary.)
  8331. if (!ltr && (ch == end || ch == begin)) { ch++; }
  8332. // To determine which side to associate with, get the box to the
  8333. // left of the character and compare it's vertical position to the
  8334. // coordinates
  8335. sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
  8336. (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ?
  8337. "after" : "before";
  8338. // Now get accurate coordinates for this place, in order to get a
  8339. // base X position
  8340. var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure);
  8341. baseX = coords.left;
  8342. outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0;
  8343. }
  8344. ch = skipExtendingChars(lineObj.text, ch, 1);
  8345. return PosWithInfo(lineNo, ch, sticky, outside, x - baseX)
  8346. }
  8347. function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {
  8348. // Bidi parts are sorted left-to-right, and in a non-line-wrapping
  8349. // situation, we can take this ordering to correspond to the visual
  8350. // ordering. This finds the first part whose end is after the given
  8351. // coordinates.
  8352. var index = findFirst(function (i) {
  8353. var part = order[i], ltr = part.level != 1;
  8354. return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"),
  8355. "line", lineObj, preparedMeasure), x, y, true)
  8356. }, 0, order.length - 1);
  8357. var part = order[index];
  8358. // If this isn't the first part, the part's start is also after
  8359. // the coordinates, and the coordinates aren't on the same line as
  8360. // that start, move one part back.
  8361. if (index > 0) {
  8362. var ltr = part.level != 1;
  8363. var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"),
  8364. "line", lineObj, preparedMeasure);
  8365. if (boxIsAfter(start, x, y, true) && start.top > y)
  8366. { part = order[index - 1]; }
  8367. }
  8368. return part
  8369. }
  8370. function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
  8371. // In a wrapped line, rtl text on wrapping boundaries can do things
  8372. // that don't correspond to the ordering in our `order` array at
  8373. // all, so a binary search doesn't work, and we want to return a
  8374. // part that only spans one line so that the binary search in
  8375. // coordsCharInner is safe. As such, we first find the extent of the
  8376. // wrapped line, and then do a flat search in which we discard any
  8377. // spans that aren't on the line.
  8378. var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
  8379. var begin = ref.begin;
  8380. var end = ref.end;
  8381. if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; }
  8382. var part = null, closestDist = null;
  8383. for (var i = 0; i < order.length; i++) {
  8384. var p = order[i];
  8385. if (p.from >= end || p.to <= begin) { continue }
  8386. var ltr = p.level != 1;
  8387. var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
  8388. // Weigh against spans ending before this, so that they are only
  8389. // picked if nothing ends after
  8390. var dist = endX < x ? x - endX + 1e9 : endX - x;
  8391. if (!part || closestDist > dist) {
  8392. part = p;
  8393. closestDist = dist;
  8394. }
  8395. }
  8396. if (!part) { part = order[order.length - 1]; }
  8397. // Clip the part to the wrapped line.
  8398. if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; }
  8399. if (part.to > end) { part = {from: part.from, to: end, level: part.level}; }
  8400. return part
  8401. }
  8402. var measureText;
  8403. // Compute the default text height.
  8404. function textHeight(display) {
  8405. if (display.cachedTextHeight != null) { return display.cachedTextHeight }
  8406. if (measureText == null) {
  8407. measureText = elt("pre", null, "CodeMirror-line-like");
  8408. // Measure a bunch of lines, for browsers that compute
  8409. // fractional heights.
  8410. for (var i = 0; i < 49; ++i) {
  8411. measureText.appendChild(document.createTextNode("x"));
  8412. measureText.appendChild(elt("br"));
  8413. }
  8414. measureText.appendChild(document.createTextNode("x"));
  8415. }
  8416. removeChildrenAndAdd(display.measure, measureText);
  8417. var height = measureText.offsetHeight / 50;
  8418. if (height > 3) { display.cachedTextHeight = height; }
  8419. removeChildren(display.measure);
  8420. return height || 1
  8421. }
  8422. // Compute the default character width.
  8423. function charWidth(display) {
  8424. if (display.cachedCharWidth != null) { return display.cachedCharWidth }
  8425. var anchor = elt("span", "xxxxxxxxxx");
  8426. var pre = elt("pre", [anchor], "CodeMirror-line-like");
  8427. removeChildrenAndAdd(display.measure, pre);
  8428. var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
  8429. if (width > 2) { display.cachedCharWidth = width; }
  8430. return width || 10
  8431. }
  8432. // Do a bulk-read of the DOM positions and sizes needed to draw the
  8433. // view, so that we don't interleave reading and writing to the DOM.
  8434. function getDimensions(cm) {
  8435. var d = cm.display, left = {}, width = {};
  8436. var gutterLeft = d.gutters.clientLeft;
  8437. for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
  8438. var id = cm.display.gutterSpecs[i].className;
  8439. left[id] = n.offsetLeft + n.clientLeft + gutterLeft;
  8440. width[id] = n.clientWidth;
  8441. }
  8442. return {fixedPos: compensateForHScroll(d),
  8443. gutterTotalWidth: d.gutters.offsetWidth,
  8444. gutterLeft: left,
  8445. gutterWidth: width,
  8446. wrapperWidth: d.wrapper.clientWidth}
  8447. }
  8448. // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
  8449. // but using getBoundingClientRect to get a sub-pixel-accurate
  8450. // result.
  8451. function compensateForHScroll(display) {
  8452. return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
  8453. }
  8454. // Returns a function that estimates the height of a line, to use as
  8455. // first approximation until the line becomes visible (and is thus
  8456. // properly measurable).
  8457. function estimateHeight(cm) {
  8458. var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
  8459. var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
  8460. return function (line) {
  8461. if (lineIsHidden(cm.doc, line)) { return 0 }
  8462. var widgetsHeight = 0;
  8463. if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
  8464. if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; }
  8465. } }
  8466. if (wrapping)
  8467. { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
  8468. else
  8469. { return widgetsHeight + th }
  8470. }
  8471. }
  8472. function estimateLineHeights(cm) {
  8473. var doc = cm.doc, est = estimateHeight(cm);
  8474. doc.iter(function (line) {
  8475. var estHeight = est(line);
  8476. if (estHeight != line.height) { updateLineHeight(line, estHeight); }
  8477. });
  8478. }
  8479. // Given a mouse event, find the corresponding position. If liberal
  8480. // is false, it checks whether a gutter or scrollbar was clicked,
  8481. // and returns null if it was. forRect is used by rectangular
  8482. // selections, and tries to estimate a character position even for
  8483. // coordinates beyond the right of the text.
  8484. function posFromMouse(cm, e, liberal, forRect) {
  8485. var display = cm.display;
  8486. if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
  8487. var x, y, space = display.lineSpace.getBoundingClientRect();
  8488. // Fails unpredictably on IE[67] when mouse is dragged around quickly.
  8489. try { x = e.clientX - space.left; y = e.clientY - space.top; }
  8490. catch (e) { return null }
  8491. var coords = coordsChar(cm, x, y), line;
  8492. if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
  8493. var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
  8494. coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
  8495. }
  8496. return coords
  8497. }
  8498. // Find the view element corresponding to a given line. Return null
  8499. // when the line isn't visible.
  8500. function findViewIndex(cm, n) {
  8501. if (n >= cm.display.viewTo) { return null }
  8502. n -= cm.display.viewFrom;
  8503. if (n < 0) { return null }
  8504. var view = cm.display.view;
  8505. for (var i = 0; i < view.length; i++) {
  8506. n -= view[i].size;
  8507. if (n < 0) { return i }
  8508. }
  8509. }
  8510. // Updates the display.view data structure for a given change to the
  8511. // document. From and to are in pre-change coordinates. Lendiff is
  8512. // the amount of lines added or subtracted by the change. This is
  8513. // used for changes that span multiple lines, or change the way
  8514. // lines are divided into visual lines. regLineChange (below)
  8515. // registers single-line changes.
  8516. function regChange(cm, from, to, lendiff) {
  8517. if (from == null) { from = cm.doc.first; }
  8518. if (to == null) { to = cm.doc.first + cm.doc.size; }
  8519. if (!lendiff) { lendiff = 0; }
  8520. var display = cm.display;
  8521. if (lendiff && to < display.viewTo &&
  8522. (display.updateLineNumbers == null || display.updateLineNumbers > from))
  8523. { display.updateLineNumbers = from; }
  8524. cm.curOp.viewChanged = true;
  8525. if (from >= display.viewTo) { // Change after
  8526. if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
  8527. { resetView(cm); }
  8528. } else if (to <= display.viewFrom) { // Change before
  8529. if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
  8530. resetView(cm);
  8531. } else {
  8532. display.viewFrom += lendiff;
  8533. display.viewTo += lendiff;
  8534. }
  8535. } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
  8536. resetView(cm);
  8537. } else if (from <= display.viewFrom) { // Top overlap
  8538. var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
  8539. if (cut) {
  8540. display.view = display.view.slice(cut.index);
  8541. display.viewFrom = cut.lineN;
  8542. display.viewTo += lendiff;
  8543. } else {
  8544. resetView(cm);
  8545. }
  8546. } else if (to >= display.viewTo) { // Bottom overlap
  8547. var cut$1 = viewCuttingPoint(cm, from, from, -1);
  8548. if (cut$1) {
  8549. display.view = display.view.slice(0, cut$1.index);
  8550. display.viewTo = cut$1.lineN;
  8551. } else {
  8552. resetView(cm);
  8553. }
  8554. } else { // Gap in the middle
  8555. var cutTop = viewCuttingPoint(cm, from, from, -1);
  8556. var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
  8557. if (cutTop && cutBot) {
  8558. display.view = display.view.slice(0, cutTop.index)
  8559. .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
  8560. .concat(display.view.slice(cutBot.index));
  8561. display.viewTo += lendiff;
  8562. } else {
  8563. resetView(cm);
  8564. }
  8565. }
  8566. var ext = display.externalMeasured;
  8567. if (ext) {
  8568. if (to < ext.lineN)
  8569. { ext.lineN += lendiff; }
  8570. else if (from < ext.lineN + ext.size)
  8571. { display.externalMeasured = null; }
  8572. }
  8573. }
  8574. // Register a change to a single line. Type must be one of "text",
  8575. // "gutter", "class", "widget"
  8576. function regLineChange(cm, line, type) {
  8577. cm.curOp.viewChanged = true;
  8578. var display = cm.display, ext = cm.display.externalMeasured;
  8579. if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
  8580. { display.externalMeasured = null; }
  8581. if (line < display.viewFrom || line >= display.viewTo) { return }
  8582. var lineView = display.view[findViewIndex(cm, line)];
  8583. if (lineView.node == null) { return }
  8584. var arr = lineView.changes || (lineView.changes = []);
  8585. if (indexOf(arr, type) == -1) { arr.push(type); }
  8586. }
  8587. // Clear the view.
  8588. function resetView(cm) {
  8589. cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
  8590. cm.display.view = [];
  8591. cm.display.viewOffset = 0;
  8592. }
  8593. function viewCuttingPoint(cm, oldN, newN, dir) {
  8594. var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
  8595. if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
  8596. { return {index: index, lineN: newN} }
  8597. var n = cm.display.viewFrom;
  8598. for (var i = 0; i < index; i++)
  8599. { n += view[i].size; }
  8600. if (n != oldN) {
  8601. if (dir > 0) {
  8602. if (index == view.length - 1) { return null }
  8603. diff = (n + view[index].size) - oldN;
  8604. index++;
  8605. } else {
  8606. diff = n - oldN;
  8607. }
  8608. oldN += diff; newN += diff;
  8609. }
  8610. while (visualLineNo(cm.doc, newN) != newN) {
  8611. if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
  8612. newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
  8613. index += dir;
  8614. }
  8615. return {index: index, lineN: newN}
  8616. }
  8617. // Force the view to cover a given range, adding empty view element
  8618. // or clipping off existing ones as needed.
  8619. function adjustView(cm, from, to) {
  8620. var display = cm.display, view = display.view;
  8621. if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
  8622. display.view = buildViewArray(cm, from, to);
  8623. display.viewFrom = from;
  8624. } else {
  8625. if (display.viewFrom > from)
  8626. { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); }
  8627. else if (display.viewFrom < from)
  8628. { display.view = display.view.slice(findViewIndex(cm, from)); }
  8629. display.viewFrom = from;
  8630. if (display.viewTo < to)
  8631. { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); }
  8632. else if (display.viewTo > to)
  8633. { display.view = display.view.slice(0, findViewIndex(cm, to)); }
  8634. }
  8635. display.viewTo = to;
  8636. }
  8637. // Count the number of lines in the view whose DOM representation is
  8638. // out of date (or nonexistent).
  8639. function countDirtyView(cm) {
  8640. var view = cm.display.view, dirty = 0;
  8641. for (var i = 0; i < view.length; i++) {
  8642. var lineView = view[i];
  8643. if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; }
  8644. }
  8645. return dirty
  8646. }
  8647. function updateSelection(cm) {
  8648. cm.display.input.showSelection(cm.display.input.prepareSelection());
  8649. }
  8650. function prepareSelection(cm, primary) {
  8651. if ( primary === void 0 ) primary = true;
  8652. var doc = cm.doc, result = {};
  8653. var curFragment = result.cursors = document.createDocumentFragment();
  8654. var selFragment = result.selection = document.createDocumentFragment();
  8655. for (var i = 0; i < doc.sel.ranges.length; i++) {
  8656. if (!primary && i == doc.sel.primIndex) { continue }
  8657. var range = doc.sel.ranges[i];
  8658. if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue }
  8659. var collapsed = range.empty();
  8660. if (collapsed || cm.options.showCursorWhenSelecting)
  8661. { drawSelectionCursor(cm, range.head, curFragment); }
  8662. if (!collapsed)
  8663. { drawSelectionRange(cm, range, selFragment); }
  8664. }
  8665. return result
  8666. }
  8667. // Draws a cursor for the given range
  8668. function drawSelectionCursor(cm, head, output) {
  8669. var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
  8670. var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
  8671. cursor.style.left = pos.left + "px";
  8672. cursor.style.top = pos.top + "px";
  8673. cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
  8674. if (pos.other) {
  8675. // Secondary cursor, shown when on a 'jump' in bi-directional text
  8676. var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
  8677. otherCursor.style.display = "";
  8678. otherCursor.style.left = pos.other.left + "px";
  8679. otherCursor.style.top = pos.other.top + "px";
  8680. otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
  8681. }
  8682. }
  8683. function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
  8684. // Draws the given range as a highlighted selection
  8685. function drawSelectionRange(cm, range, output) {
  8686. var display = cm.display, doc = cm.doc;
  8687. var fragment = document.createDocumentFragment();
  8688. var padding = paddingH(cm.display), leftSide = padding.left;
  8689. var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
  8690. var docLTR = doc.direction == "ltr";
  8691. function add(left, top, width, bottom) {
  8692. if (top < 0) { top = 0; }
  8693. top = Math.round(top);
  8694. bottom = Math.round(bottom);
  8695. fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")));
  8696. }
  8697. function drawForLine(line, fromArg, toArg) {
  8698. var lineObj = getLine(doc, line);
  8699. var lineLen = lineObj.text.length;
  8700. var start, end;
  8701. function coords(ch, bias) {
  8702. return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
  8703. }
  8704. function wrapX(pos, dir, side) {
  8705. var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
  8706. var prop = (dir == "ltr") == (side == "after") ? "left" : "right";
  8707. var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
  8708. return coords(ch, prop)[prop]
  8709. }
  8710. var order = getOrder(lineObj, doc.direction);
  8711. iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
  8712. var ltr = dir == "ltr";
  8713. var fromPos = coords(from, ltr ? "left" : "right");
  8714. var toPos = coords(to - 1, ltr ? "right" : "left");
  8715. var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
  8716. var first = i == 0, last = !order || i == order.length - 1;
  8717. if (toPos.top - fromPos.top <= 3) { // Single line
  8718. var openLeft = (docLTR ? openStart : openEnd) && first;
  8719. var openRight = (docLTR ? openEnd : openStart) && last;
  8720. var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
  8721. var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
  8722. add(left, fromPos.top, right - left, fromPos.bottom);
  8723. } else { // Multiple lines
  8724. var topLeft, topRight, botLeft, botRight;
  8725. if (ltr) {
  8726. topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
  8727. topRight = docLTR ? rightSide : wrapX(from, dir, "before");
  8728. botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
  8729. botRight = docLTR && openEnd && last ? rightSide : toPos.right;
  8730. } else {
  8731. topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
  8732. topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
  8733. botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
  8734. botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
  8735. }
  8736. add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
  8737. if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); }
  8738. add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
  8739. }
  8740. if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos; }
  8741. if (cmpCoords(toPos, start) < 0) { start = toPos; }
  8742. if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos; }
  8743. if (cmpCoords(toPos, end) < 0) { end = toPos; }
  8744. });
  8745. return {start: start, end: end}
  8746. }
  8747. var sFrom = range.from(), sTo = range.to();
  8748. if (sFrom.line == sTo.line) {
  8749. drawForLine(sFrom.line, sFrom.ch, sTo.ch);
  8750. } else {
  8751. var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
  8752. var singleVLine = visualLine(fromLine) == visualLine(toLine);
  8753. var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
  8754. var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
  8755. if (singleVLine) {
  8756. if (leftEnd.top < rightStart.top - 2) {
  8757. add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
  8758. add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
  8759. } else {
  8760. add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
  8761. }
  8762. }
  8763. if (leftEnd.bottom < rightStart.top)
  8764. { add(leftSide, leftEnd.bottom, null, rightStart.top); }
  8765. }
  8766. output.appendChild(fragment);
  8767. }
  8768. // Cursor-blinking
  8769. function restartBlink(cm) {
  8770. if (!cm.state.focused) { return }
  8771. var display = cm.display;
  8772. clearInterval(display.blinker);
  8773. var on = true;
  8774. display.cursorDiv.style.visibility = "";
  8775. if (cm.options.cursorBlinkRate > 0)
  8776. { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
  8777. cm.options.cursorBlinkRate); }
  8778. else if (cm.options.cursorBlinkRate < 0)
  8779. { display.cursorDiv.style.visibility = "hidden"; }
  8780. }
  8781. function ensureFocus(cm) {
  8782. if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
  8783. }
  8784. function delayBlurEvent(cm) {
  8785. cm.state.delayingBlurEvent = true;
  8786. setTimeout(function () { if (cm.state.delayingBlurEvent) {
  8787. cm.state.delayingBlurEvent = false;
  8788. onBlur(cm);
  8789. } }, 100);
  8790. }
  8791. function onFocus(cm, e) {
  8792. if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false; }
  8793. if (cm.options.readOnly == "nocursor") { return }
  8794. if (!cm.state.focused) {
  8795. signal(cm, "focus", cm, e);
  8796. cm.state.focused = true;
  8797. addClass(cm.display.wrapper, "CodeMirror-focused");
  8798. // This test prevents this from firing when a context
  8799. // menu is closed (since the input reset would kill the
  8800. // select-all detection hack)
  8801. if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
  8802. cm.display.input.reset();
  8803. if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730
  8804. }
  8805. cm.display.input.receivedFocus();
  8806. }
  8807. restartBlink(cm);
  8808. }
  8809. function onBlur(cm, e) {
  8810. if (cm.state.delayingBlurEvent) { return }
  8811. if (cm.state.focused) {
  8812. signal(cm, "blur", cm, e);
  8813. cm.state.focused = false;
  8814. rmClass(cm.display.wrapper, "CodeMirror-focused");
  8815. }
  8816. clearInterval(cm.display.blinker);
  8817. setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150);
  8818. }
  8819. // Read the actual heights of the rendered lines, and update their
  8820. // stored heights to match.
  8821. function updateHeightsInViewport(cm) {
  8822. var display = cm.display;
  8823. var prevBottom = display.lineDiv.offsetTop;
  8824. for (var i = 0; i < display.view.length; i++) {
  8825. var cur = display.view[i], wrapping = cm.options.lineWrapping;
  8826. var height = (void 0), width = 0;
  8827. if (cur.hidden) { continue }
  8828. if (ie && ie_version < 8) {
  8829. var bot = cur.node.offsetTop + cur.node.offsetHeight;
  8830. height = bot - prevBottom;
  8831. prevBottom = bot;
  8832. } else {
  8833. var box = cur.node.getBoundingClientRect();
  8834. height = box.bottom - box.top;
  8835. // Check that lines don't extend past the right of the current
  8836. // editor width
  8837. if (!wrapping && cur.text.firstChild)
  8838. { width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1; }
  8839. }
  8840. var diff = cur.line.height - height;
  8841. if (diff > .005 || diff < -.005) {
  8842. updateLineHeight(cur.line, height);
  8843. updateWidgetHeight(cur.line);
  8844. if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
  8845. { updateWidgetHeight(cur.rest[j]); } }
  8846. }
  8847. if (width > cm.display.sizerWidth) {
  8848. var chWidth = Math.ceil(width / charWidth(cm.display));
  8849. if (chWidth > cm.display.maxLineLength) {
  8850. cm.display.maxLineLength = chWidth;
  8851. cm.display.maxLine = cur.line;
  8852. cm.display.maxLineChanged = true;
  8853. }
  8854. }
  8855. }
  8856. }
  8857. // Read and store the height of line widgets associated with the
  8858. // given line.
  8859. function updateWidgetHeight(line) {
  8860. if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
  8861. var w = line.widgets[i], parent = w.node.parentNode;
  8862. if (parent) { w.height = parent.offsetHeight; }
  8863. } }
  8864. }
  8865. // Compute the lines that are visible in a given viewport (defaults
  8866. // the the current scroll position). viewport may contain top,
  8867. // height, and ensure (see op.scrollToPos) properties.
  8868. function visibleLines(display, doc, viewport) {
  8869. var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
  8870. top = Math.floor(top - paddingTop(display));
  8871. var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
  8872. var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
  8873. // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
  8874. // forces those lines into the viewport (if possible).
  8875. if (viewport && viewport.ensure) {
  8876. var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
  8877. if (ensureFrom < from) {
  8878. from = ensureFrom;
  8879. to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
  8880. } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
  8881. from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
  8882. to = ensureTo;
  8883. }
  8884. }
  8885. return {from: from, to: Math.max(to, from + 1)}
  8886. }
  8887. // SCROLLING THINGS INTO VIEW
  8888. // If an editor sits on the top or bottom of the window, partially
  8889. // scrolled out of view, this ensures that the cursor is visible.
  8890. function maybeScrollWindow(cm, rect) {
  8891. if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
  8892. var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
  8893. if (rect.top + box.top < 0) { doScroll = true; }
  8894. else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; }
  8895. if (doScroll != null && !phantom) {
  8896. var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"));
  8897. cm.display.lineSpace.appendChild(scrollNode);
  8898. scrollNode.scrollIntoView(doScroll);
  8899. cm.display.lineSpace.removeChild(scrollNode);
  8900. }
  8901. }
  8902. // Scroll a given position into view (immediately), verifying that
  8903. // it actually became visible (as line heights are accurately
  8904. // measured, the position of something may 'drift' during drawing).
  8905. function scrollPosIntoView(cm, pos, end, margin) {
  8906. if (margin == null) { margin = 0; }
  8907. var rect;
  8908. if (!cm.options.lineWrapping && pos == end) {
  8909. // Set pos and end to the cursor positions around the character pos sticks to
  8910. // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
  8911. // If pos == Pos(_, 0, "before"), pos and end are unchanged
  8912. pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
  8913. end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
  8914. }
  8915. for (var limit = 0; limit < 5; limit++) {
  8916. var changed = false;
  8917. var coords = cursorCoords(cm, pos);
  8918. var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
  8919. rect = {left: Math.min(coords.left, endCoords.left),
  8920. top: Math.min(coords.top, endCoords.top) - margin,
  8921. right: Math.max(coords.left, endCoords.left),
  8922. bottom: Math.max(coords.bottom, endCoords.bottom) + margin};
  8923. var scrollPos = calculateScrollPos(cm, rect);
  8924. var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
  8925. if (scrollPos.scrollTop != null) {
  8926. updateScrollTop(cm, scrollPos.scrollTop);
  8927. if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; }
  8928. }
  8929. if (scrollPos.scrollLeft != null) {
  8930. setScrollLeft(cm, scrollPos.scrollLeft);
  8931. if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; }
  8932. }
  8933. if (!changed) { break }
  8934. }
  8935. return rect
  8936. }
  8937. // Scroll a given set of coordinates into view (immediately).
  8938. function scrollIntoView(cm, rect) {
  8939. var scrollPos = calculateScrollPos(cm, rect);
  8940. if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop); }
  8941. if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); }
  8942. }
  8943. // Calculate a new scroll position needed to scroll the given
  8944. // rectangle into view. Returns an object with scrollTop and
  8945. // scrollLeft properties. When these are undefined, the
  8946. // vertical/horizontal position does not need to be adjusted.
  8947. function calculateScrollPos(cm, rect) {
  8948. var display = cm.display, snapMargin = textHeight(cm.display);
  8949. if (rect.top < 0) { rect.top = 0; }
  8950. var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
  8951. var screen = displayHeight(cm), result = {};
  8952. if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; }
  8953. var docBottom = cm.doc.height + paddingVert(display);
  8954. var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
  8955. if (rect.top < screentop) {
  8956. result.scrollTop = atTop ? 0 : rect.top;
  8957. } else if (rect.bottom > screentop + screen) {
  8958. var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
  8959. if (newTop != screentop) { result.scrollTop = newTop; }
  8960. }
  8961. var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
  8962. var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
  8963. var tooWide = rect.right - rect.left > screenw;
  8964. if (tooWide) { rect.right = rect.left + screenw; }
  8965. if (rect.left < 10)
  8966. { result.scrollLeft = 0; }
  8967. else if (rect.left < screenleft)
  8968. { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)); }
  8969. else if (rect.right > screenw + screenleft - 3)
  8970. { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; }
  8971. return result
  8972. }
  8973. // Store a relative adjustment to the scroll position in the current
  8974. // operation (to be applied when the operation finishes).
  8975. function addToScrollTop(cm, top) {
  8976. if (top == null) { return }
  8977. resolveScrollToPos(cm);
  8978. cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
  8979. }
  8980. // Make sure that at the end of the operation the current cursor is
  8981. // shown.
  8982. function ensureCursorVisible(cm) {
  8983. resolveScrollToPos(cm);
  8984. var cur = cm.getCursor();
  8985. cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin};
  8986. }
  8987. function scrollToCoords(cm, x, y) {
  8988. if (x != null || y != null) { resolveScrollToPos(cm); }
  8989. if (x != null) { cm.curOp.scrollLeft = x; }
  8990. if (y != null) { cm.curOp.scrollTop = y; }
  8991. }
  8992. function scrollToRange(cm, range) {
  8993. resolveScrollToPos(cm);
  8994. cm.curOp.scrollToPos = range;
  8995. }
  8996. // When an operation has its scrollToPos property set, and another
  8997. // scroll action is applied before the end of the operation, this
  8998. // 'simulates' scrolling that position into view in a cheap way, so
  8999. // that the effect of intermediate scroll commands is not ignored.
  9000. function resolveScrollToPos(cm) {
  9001. var range = cm.curOp.scrollToPos;
  9002. if (range) {
  9003. cm.curOp.scrollToPos = null;
  9004. var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
  9005. scrollToCoordsRange(cm, from, to, range.margin);
  9006. }
  9007. }
  9008. function scrollToCoordsRange(cm, from, to, margin) {
  9009. var sPos = calculateScrollPos(cm, {
  9010. left: Math.min(from.left, to.left),
  9011. top: Math.min(from.top, to.top) - margin,
  9012. right: Math.max(from.right, to.right),
  9013. bottom: Math.max(from.bottom, to.bottom) + margin
  9014. });
  9015. scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
  9016. }
  9017. // Sync the scrollable area and scrollbars, ensure the viewport
  9018. // covers the visible area.
  9019. function updateScrollTop(cm, val) {
  9020. if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
  9021. if (!gecko) { updateDisplaySimple(cm, {top: val}); }
  9022. setScrollTop(cm, val, true);
  9023. if (gecko) { updateDisplaySimple(cm); }
  9024. startWorker(cm, 100);
  9025. }
  9026. function setScrollTop(cm, val, forceScroll) {
  9027. val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val));
  9028. if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
  9029. cm.doc.scrollTop = val;
  9030. cm.display.scrollbars.setScrollTop(val);
  9031. if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; }
  9032. }
  9033. // Sync scroller and scrollbar, ensure the gutter elements are
  9034. // aligned.
  9035. function setScrollLeft(cm, val, isScroller, forceScroll) {
  9036. val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth));
  9037. if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
  9038. cm.doc.scrollLeft = val;
  9039. alignHorizontally(cm);
  9040. if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; }
  9041. cm.display.scrollbars.setScrollLeft(val);
  9042. }
  9043. // SCROLLBARS
  9044. // Prepare DOM reads needed to update the scrollbars. Done in one
  9045. // shot to minimize update/measure roundtrips.
  9046. function measureForScrollbars(cm) {
  9047. var d = cm.display, gutterW = d.gutters.offsetWidth;
  9048. var docH = Math.round(cm.doc.height + paddingVert(cm.display));
  9049. return {
  9050. clientHeight: d.scroller.clientHeight,
  9051. viewHeight: d.wrapper.clientHeight,
  9052. scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
  9053. viewWidth: d.wrapper.clientWidth,
  9054. barLeft: cm.options.fixedGutter ? gutterW : 0,
  9055. docHeight: docH,
  9056. scrollHeight: docH + scrollGap(cm) + d.barHeight,
  9057. nativeBarWidth: d.nativeBarWidth,
  9058. gutterWidth: gutterW
  9059. }
  9060. }
  9061. var NativeScrollbars = function(place, scroll, cm) {
  9062. this.cm = cm;
  9063. var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
  9064. var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
  9065. vert.tabIndex = horiz.tabIndex = -1;
  9066. place(vert); place(horiz);
  9067. on(vert, "scroll", function () {
  9068. if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); }
  9069. });
  9070. on(horiz, "scroll", function () {
  9071. if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); }
  9072. });
  9073. this.checkedZeroWidth = false;
  9074. // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
  9075. if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; }
  9076. };
  9077. NativeScrollbars.prototype.update = function (measure) {
  9078. var needsH = measure.scrollWidth > measure.clientWidth + 1;
  9079. var needsV = measure.scrollHeight > measure.clientHeight + 1;
  9080. var sWidth = measure.nativeBarWidth;
  9081. if (needsV) {
  9082. this.vert.style.display = "block";
  9083. this.vert.style.bottom = needsH ? sWidth + "px" : "0";
  9084. var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
  9085. // A bug in IE8 can cause this value to be negative, so guard it.
  9086. this.vert.firstChild.style.height =
  9087. Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
  9088. } else {
  9089. this.vert.style.display = "";
  9090. this.vert.firstChild.style.height = "0";
  9091. }
  9092. if (needsH) {
  9093. this.horiz.style.display = "block";
  9094. this.horiz.style.right = needsV ? sWidth + "px" : "0";
  9095. this.horiz.style.left = measure.barLeft + "px";
  9096. var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
  9097. this.horiz.firstChild.style.width =
  9098. Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
  9099. } else {
  9100. this.horiz.style.display = "";
  9101. this.horiz.firstChild.style.width = "0";
  9102. }
  9103. if (!this.checkedZeroWidth && measure.clientHeight > 0) {
  9104. if (sWidth == 0) { this.zeroWidthHack(); }
  9105. this.checkedZeroWidth = true;
  9106. }
  9107. return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
  9108. };
  9109. NativeScrollbars.prototype.setScrollLeft = function (pos) {
  9110. if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; }
  9111. if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz"); }
  9112. };
  9113. NativeScrollbars.prototype.setScrollTop = function (pos) {
  9114. if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; }
  9115. if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert"); }
  9116. };
  9117. NativeScrollbars.prototype.zeroWidthHack = function () {
  9118. var w = mac && !mac_geMountainLion ? "12px" : "18px";
  9119. this.horiz.style.height = this.vert.style.width = w;
  9120. this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
  9121. this.disableHoriz = new Delayed;
  9122. this.disableVert = new Delayed;
  9123. };
  9124. NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
  9125. bar.style.pointerEvents = "auto";
  9126. function maybeDisable() {
  9127. // To find out whether the scrollbar is still visible, we
  9128. // check whether the element under the pixel in the bottom
  9129. // right corner of the scrollbar box is the scrollbar box
  9130. // itself (when the bar is still visible) or its filler child
  9131. // (when the bar is hidden). If it is still visible, we keep
  9132. // it enabled, if it's hidden, we disable pointer events.
  9133. var box = bar.getBoundingClientRect();
  9134. var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
  9135. : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
  9136. if (elt != bar) { bar.style.pointerEvents = "none"; }
  9137. else { delay.set(1000, maybeDisable); }
  9138. }
  9139. delay.set(1000, maybeDisable);
  9140. };
  9141. NativeScrollbars.prototype.clear = function () {
  9142. var parent = this.horiz.parentNode;
  9143. parent.removeChild(this.horiz);
  9144. parent.removeChild(this.vert);
  9145. };
  9146. var NullScrollbars = function () {};
  9147. NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
  9148. NullScrollbars.prototype.setScrollLeft = function () {};
  9149. NullScrollbars.prototype.setScrollTop = function () {};
  9150. NullScrollbars.prototype.clear = function () {};
  9151. function updateScrollbars(cm, measure) {
  9152. if (!measure) { measure = measureForScrollbars(cm); }
  9153. var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
  9154. updateScrollbarsInner(cm, measure);
  9155. for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
  9156. if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
  9157. { updateHeightsInViewport(cm); }
  9158. updateScrollbarsInner(cm, measureForScrollbars(cm));
  9159. startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
  9160. }
  9161. }
  9162. // Re-synchronize the fake scrollbars with the actual size of the
  9163. // content.
  9164. function updateScrollbarsInner(cm, measure) {
  9165. var d = cm.display;
  9166. var sizes = d.scrollbars.update(measure);
  9167. d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
  9168. d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
  9169. d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
  9170. if (sizes.right && sizes.bottom) {
  9171. d.scrollbarFiller.style.display = "block";
  9172. d.scrollbarFiller.style.height = sizes.bottom + "px";
  9173. d.scrollbarFiller.style.width = sizes.right + "px";
  9174. } else { d.scrollbarFiller.style.display = ""; }
  9175. if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
  9176. d.gutterFiller.style.display = "block";
  9177. d.gutterFiller.style.height = sizes.bottom + "px";
  9178. d.gutterFiller.style.width = measure.gutterWidth + "px";
  9179. } else { d.gutterFiller.style.display = ""; }
  9180. }
  9181. var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
  9182. function initScrollbars(cm) {
  9183. if (cm.display.scrollbars) {
  9184. cm.display.scrollbars.clear();
  9185. if (cm.display.scrollbars.addClass)
  9186. { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
  9187. }
  9188. cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
  9189. cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
  9190. // Prevent clicks in the scrollbars from killing focus
  9191. on(node, "mousedown", function () {
  9192. if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); }
  9193. });
  9194. node.setAttribute("cm-not-content", "true");
  9195. }, function (pos, axis) {
  9196. if (axis == "horizontal") { setScrollLeft(cm, pos); }
  9197. else { updateScrollTop(cm, pos); }
  9198. }, cm);
  9199. if (cm.display.scrollbars.addClass)
  9200. { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
  9201. }
  9202. // Operations are used to wrap a series of changes to the editor
  9203. // state in such a way that each change won't have to update the
  9204. // cursor and display (which would be awkward, slow, and
  9205. // error-prone). Instead, display updates are batched and then all
  9206. // combined and executed at once.
  9207. var nextOpId = 0;
  9208. // Start a new operation.
  9209. function startOperation(cm) {
  9210. cm.curOp = {
  9211. cm: cm,
  9212. viewChanged: false, // Flag that indicates that lines might need to be redrawn
  9213. startHeight: cm.doc.height, // Used to detect need to update scrollbar
  9214. forceUpdate: false, // Used to force a redraw
  9215. updateInput: 0, // Whether to reset the input textarea
  9216. typing: false, // Whether this reset should be careful to leave existing text (for compositing)
  9217. changeObjs: null, // Accumulated changes, for firing change events
  9218. cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
  9219. cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
  9220. selectionChanged: false, // Whether the selection needs to be redrawn
  9221. updateMaxLine: false, // Set when the widest line needs to be determined anew
  9222. scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
  9223. scrollToPos: null, // Used to scroll to a specific position
  9224. focus: false,
  9225. id: ++nextOpId // Unique ID
  9226. };
  9227. pushOperation(cm.curOp);
  9228. }
  9229. // Finish an operation, updating the display and signalling delayed events
  9230. function endOperation(cm) {
  9231. var op = cm.curOp;
  9232. if (op) { finishOperation(op, function (group) {
  9233. for (var i = 0; i < group.ops.length; i++)
  9234. { group.ops[i].cm.curOp = null; }
  9235. endOperations(group);
  9236. }); }
  9237. }
  9238. // The DOM updates done when an operation finishes are batched so
  9239. // that the minimum number of relayouts are required.
  9240. function endOperations(group) {
  9241. var ops = group.ops;
  9242. for (var i = 0; i < ops.length; i++) // Read DOM
  9243. { endOperation_R1(ops[i]); }
  9244. for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
  9245. { endOperation_W1(ops[i$1]); }
  9246. for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
  9247. { endOperation_R2(ops[i$2]); }
  9248. for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
  9249. { endOperation_W2(ops[i$3]); }
  9250. for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
  9251. { endOperation_finish(ops[i$4]); }
  9252. }
  9253. function endOperation_R1(op) {
  9254. var cm = op.cm, display = cm.display;
  9255. maybeClipScrollbars(cm);
  9256. if (op.updateMaxLine) { findMaxLine(cm); }
  9257. op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
  9258. op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
  9259. op.scrollToPos.to.line >= display.viewTo) ||
  9260. display.maxLineChanged && cm.options.lineWrapping;
  9261. op.update = op.mustUpdate &&
  9262. new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
  9263. }
  9264. function endOperation_W1(op) {
  9265. op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
  9266. }
  9267. function endOperation_R2(op) {
  9268. var cm = op.cm, display = cm.display;
  9269. if (op.updatedDisplay) { updateHeightsInViewport(cm); }
  9270. op.barMeasure = measureForScrollbars(cm);
  9271. // If the max line changed since it was last measured, measure it,
  9272. // and ensure the document's width matches it.
  9273. // updateDisplay_W2 will use these properties to do the actual resizing
  9274. if (display.maxLineChanged && !cm.options.lineWrapping) {
  9275. op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
  9276. cm.display.sizerWidth = op.adjustWidthTo;
  9277. op.barMeasure.scrollWidth =
  9278. Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
  9279. op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
  9280. }
  9281. if (op.updatedDisplay || op.selectionChanged)
  9282. { op.preparedSelection = display.input.prepareSelection(); }
  9283. }
  9284. function endOperation_W2(op) {
  9285. var cm = op.cm;
  9286. if (op.adjustWidthTo != null) {
  9287. cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
  9288. if (op.maxScrollLeft < cm.doc.scrollLeft)
  9289. { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); }
  9290. cm.display.maxLineChanged = false;
  9291. }
  9292. var takeFocus = op.focus && op.focus == activeElt();
  9293. if (op.preparedSelection)
  9294. { cm.display.input.showSelection(op.preparedSelection, takeFocus); }
  9295. if (op.updatedDisplay || op.startHeight != cm.doc.height)
  9296. { updateScrollbars(cm, op.barMeasure); }
  9297. if (op.updatedDisplay)
  9298. { setDocumentHeight(cm, op.barMeasure); }
  9299. if (op.selectionChanged) { restartBlink(cm); }
  9300. if (cm.state.focused && op.updateInput)
  9301. { cm.display.input.reset(op.typing); }
  9302. if (takeFocus) { ensureFocus(op.cm); }
  9303. }
  9304. function endOperation_finish(op) {
  9305. var cm = op.cm, display = cm.display, doc = cm.doc;
  9306. if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); }
  9307. // Abort mouse wheel delta measurement, when scrolling explicitly
  9308. if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
  9309. { display.wheelStartX = display.wheelStartY = null; }
  9310. // Propagate the scroll position to the actual DOM scroller
  9311. if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll); }
  9312. if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true); }
  9313. // If we need to scroll a specific position into view, do so.
  9314. if (op.scrollToPos) {
  9315. var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
  9316. clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
  9317. maybeScrollWindow(cm, rect);
  9318. }
  9319. // Fire events for markers that are hidden/unidden by editing or
  9320. // undoing
  9321. var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
  9322. if (hidden) { for (var i = 0; i < hidden.length; ++i)
  9323. { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } }
  9324. if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
  9325. { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } }
  9326. if (display.wrapper.offsetHeight)
  9327. { doc.scrollTop = cm.display.scroller.scrollTop; }
  9328. // Fire change events, and delayed event handlers
  9329. if (op.changeObjs)
  9330. { signal(cm, "changes", cm, op.changeObjs); }
  9331. if (op.update)
  9332. { op.update.finish(); }
  9333. }
  9334. // Run the given function in an operation
  9335. function runInOp(cm, f) {
  9336. if (cm.curOp) { return f() }
  9337. startOperation(cm);
  9338. try { return f() }
  9339. finally { endOperation(cm); }
  9340. }
  9341. // Wraps a function in an operation. Returns the wrapped function.
  9342. function operation(cm, f) {
  9343. return function() {
  9344. if (cm.curOp) { return f.apply(cm, arguments) }
  9345. startOperation(cm);
  9346. try { return f.apply(cm, arguments) }
  9347. finally { endOperation(cm); }
  9348. }
  9349. }
  9350. // Used to add methods to editor and doc instances, wrapping them in
  9351. // operations.
  9352. function methodOp(f) {
  9353. return function() {
  9354. if (this.curOp) { return f.apply(this, arguments) }
  9355. startOperation(this);
  9356. try { return f.apply(this, arguments) }
  9357. finally { endOperation(this); }
  9358. }
  9359. }
  9360. function docMethodOp(f) {
  9361. return function() {
  9362. var cm = this.cm;
  9363. if (!cm || cm.curOp) { return f.apply(this, arguments) }
  9364. startOperation(cm);
  9365. try { return f.apply(this, arguments) }
  9366. finally { endOperation(cm); }
  9367. }
  9368. }
  9369. // HIGHLIGHT WORKER
  9370. function startWorker(cm, time) {
  9371. if (cm.doc.highlightFrontier < cm.display.viewTo)
  9372. { cm.state.highlight.set(time, bind(highlightWorker, cm)); }
  9373. }
  9374. function highlightWorker(cm) {
  9375. var doc = cm.doc;
  9376. if (doc.highlightFrontier >= cm.display.viewTo) { return }
  9377. var end = +new Date + cm.options.workTime;
  9378. var context = getContextBefore(cm, doc.highlightFrontier);
  9379. var changedLines = [];
  9380. doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
  9381. if (context.line >= cm.display.viewFrom) { // Visible
  9382. var oldStyles = line.styles;
  9383. var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;
  9384. var highlighted = highlightLine(cm, line, context, true);
  9385. if (resetState) { context.state = resetState; }
  9386. line.styles = highlighted.styles;
  9387. var oldCls = line.styleClasses, newCls = highlighted.classes;
  9388. if (newCls) { line.styleClasses = newCls; }
  9389. else if (oldCls) { line.styleClasses = null; }
  9390. var ischange = !oldStyles || oldStyles.length != line.styles.length ||
  9391. oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
  9392. for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; }
  9393. if (ischange) { changedLines.push(context.line); }
  9394. line.stateAfter = context.save();
  9395. context.nextLine();
  9396. } else {
  9397. if (line.text.length <= cm.options.maxHighlightLength)
  9398. { processLine(cm, line.text, context); }
  9399. line.stateAfter = context.line % 5 == 0 ? context.save() : null;
  9400. context.nextLine();
  9401. }
  9402. if (+new Date > end) {
  9403. startWorker(cm, cm.options.workDelay);
  9404. return true
  9405. }
  9406. });
  9407. doc.highlightFrontier = context.line;
  9408. doc.modeFrontier = Math.max(doc.modeFrontier, context.line);
  9409. if (changedLines.length) { runInOp(cm, function () {
  9410. for (var i = 0; i < changedLines.length; i++)
  9411. { regLineChange(cm, changedLines[i], "text"); }
  9412. }); }
  9413. }
  9414. // DISPLAY DRAWING
  9415. var DisplayUpdate = function(cm, viewport, force) {
  9416. var display = cm.display;
  9417. this.viewport = viewport;
  9418. // Store some values that we'll need later (but don't want to force a relayout for)
  9419. this.visible = visibleLines(display, cm.doc, viewport);
  9420. this.editorIsHidden = !display.wrapper.offsetWidth;
  9421. this.wrapperHeight = display.wrapper.clientHeight;
  9422. this.wrapperWidth = display.wrapper.clientWidth;
  9423. this.oldDisplayWidth = displayWidth(cm);
  9424. this.force = force;
  9425. this.dims = getDimensions(cm);
  9426. this.events = [];
  9427. };
  9428. DisplayUpdate.prototype.signal = function (emitter, type) {
  9429. if (hasHandler(emitter, type))
  9430. { this.events.push(arguments); }
  9431. };
  9432. DisplayUpdate.prototype.finish = function () {
  9433. for (var i = 0; i < this.events.length; i++)
  9434. { signal.apply(null, this.events[i]); }
  9435. };
  9436. function maybeClipScrollbars(cm) {
  9437. var display = cm.display;
  9438. if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
  9439. display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
  9440. display.heightForcer.style.height = scrollGap(cm) + "px";
  9441. display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
  9442. display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
  9443. display.scrollbarsClipped = true;
  9444. }
  9445. }
  9446. function selectionSnapshot(cm) {
  9447. if (cm.hasFocus()) { return null }
  9448. var active = activeElt();
  9449. if (!active || !contains(cm.display.lineDiv, active)) { return null }
  9450. var result = {activeElt: active};
  9451. if (window.getSelection) {
  9452. var sel = window.getSelection();
  9453. if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
  9454. result.anchorNode = sel.anchorNode;
  9455. result.anchorOffset = sel.anchorOffset;
  9456. result.focusNode = sel.focusNode;
  9457. result.focusOffset = sel.focusOffset;
  9458. }
  9459. }
  9460. return result
  9461. }
  9462. function restoreSelection(snapshot) {
  9463. if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
  9464. snapshot.activeElt.focus();
  9465. if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
  9466. var sel = window.getSelection(), range = document.createRange();
  9467. range.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
  9468. range.collapse(false);
  9469. sel.removeAllRanges();
  9470. sel.addRange(range);
  9471. sel.extend(snapshot.focusNode, snapshot.focusOffset);
  9472. }
  9473. }
  9474. // Does the actual updating of the line display. Bails out
  9475. // (returning false) when there is nothing to be done and forced is
  9476. // false.
  9477. function updateDisplayIfNeeded(cm, update) {
  9478. var display = cm.display, doc = cm.doc;
  9479. if (update.editorIsHidden) {
  9480. resetView(cm);
  9481. return false
  9482. }
  9483. // Bail out if the visible area is already rendered and nothing changed.
  9484. if (!update.force &&
  9485. update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
  9486. (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
  9487. display.renderedView == display.view && countDirtyView(cm) == 0)
  9488. { return false }
  9489. if (maybeUpdateLineNumberWidth(cm)) {
  9490. resetView(cm);
  9491. update.dims = getDimensions(cm);
  9492. }
  9493. // Compute a suitable new viewport (from & to)
  9494. var end = doc.first + doc.size;
  9495. var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
  9496. var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
  9497. if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
  9498. if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
  9499. if (sawCollapsedSpans) {
  9500. from = visualLineNo(cm.doc, from);
  9501. to = visualLineEndNo(cm.doc, to);
  9502. }
  9503. var different = from != display.viewFrom || to != display.viewTo ||
  9504. display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
  9505. adjustView(cm, from, to);
  9506. display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
  9507. // Position the mover div to align with the current scroll position
  9508. cm.display.mover.style.top = display.viewOffset + "px";
  9509. var toUpdate = countDirtyView(cm);
  9510. if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
  9511. (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
  9512. { return false }
  9513. // For big changes, we hide the enclosing element during the
  9514. // update, since that speeds up the operations on most browsers.
  9515. var selSnapshot = selectionSnapshot(cm);
  9516. if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
  9517. patchDisplay(cm, display.updateLineNumbers, update.dims);
  9518. if (toUpdate > 4) { display.lineDiv.style.display = ""; }
  9519. display.renderedView = display.view;
  9520. // There might have been a widget with a focused element that got
  9521. // hidden or updated, if so re-focus it.
  9522. restoreSelection(selSnapshot);
  9523. // Prevent selection and cursors from interfering with the scroll
  9524. // width and height.
  9525. removeChildren(display.cursorDiv);
  9526. removeChildren(display.selectionDiv);
  9527. display.gutters.style.height = display.sizer.style.minHeight = 0;
  9528. if (different) {
  9529. display.lastWrapHeight = update.wrapperHeight;
  9530. display.lastWrapWidth = update.wrapperWidth;
  9531. startWorker(cm, 400);
  9532. }
  9533. display.updateLineNumbers = null;
  9534. return true
  9535. }
  9536. function postUpdateDisplay(cm, update) {
  9537. var viewport = update.viewport;
  9538. for (var first = true;; first = false) {
  9539. if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
  9540. // Clip forced viewport to actual scrollable area.
  9541. if (viewport && viewport.top != null)
  9542. { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; }
  9543. // Updated line heights might result in the drawn area not
  9544. // actually covering the viewport. Keep looping until it does.
  9545. update.visible = visibleLines(cm.display, cm.doc, viewport);
  9546. if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
  9547. { break }
  9548. } else if (first) {
  9549. update.visible = visibleLines(cm.display, cm.doc, viewport);
  9550. }
  9551. if (!updateDisplayIfNeeded(cm, update)) { break }
  9552. updateHeightsInViewport(cm);
  9553. var barMeasure = measureForScrollbars(cm);
  9554. updateSelection(cm);
  9555. updateScrollbars(cm, barMeasure);
  9556. setDocumentHeight(cm, barMeasure);
  9557. update.force = false;
  9558. }
  9559. update.signal(cm, "update", cm);
  9560. if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
  9561. update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
  9562. cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
  9563. }
  9564. }
  9565. function updateDisplaySimple(cm, viewport) {
  9566. var update = new DisplayUpdate(cm, viewport);
  9567. if (updateDisplayIfNeeded(cm, update)) {
  9568. updateHeightsInViewport(cm);
  9569. postUpdateDisplay(cm, update);
  9570. var barMeasure = measureForScrollbars(cm);
  9571. updateSelection(cm);
  9572. updateScrollbars(cm, barMeasure);
  9573. setDocumentHeight(cm, barMeasure);
  9574. update.finish();
  9575. }
  9576. }
  9577. // Sync the actual display DOM structure with display.view, removing
  9578. // nodes for lines that are no longer in view, and creating the ones
  9579. // that are not there yet, and updating the ones that are out of
  9580. // date.
  9581. function patchDisplay(cm, updateNumbersFrom, dims) {
  9582. var display = cm.display, lineNumbers = cm.options.lineNumbers;
  9583. var container = display.lineDiv, cur = container.firstChild;
  9584. function rm(node) {
  9585. var next = node.nextSibling;
  9586. // Works around a throw-scroll bug in OS X Webkit
  9587. if (webkit && mac && cm.display.currentWheelTarget == node)
  9588. { node.style.display = "none"; }
  9589. else
  9590. { node.parentNode.removeChild(node); }
  9591. return next
  9592. }
  9593. var view = display.view, lineN = display.viewFrom;
  9594. // Loop over the elements in the view, syncing cur (the DOM nodes
  9595. // in display.lineDiv) with the view as we go.
  9596. for (var i = 0; i < view.length; i++) {
  9597. var lineView = view[i];
  9598. if (lineView.hidden) ; else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
  9599. var node = buildLineElement(cm, lineView, lineN, dims);
  9600. container.insertBefore(node, cur);
  9601. } else { // Already drawn
  9602. while (cur != lineView.node) { cur = rm(cur); }
  9603. var updateNumber = lineNumbers && updateNumbersFrom != null &&
  9604. updateNumbersFrom <= lineN && lineView.lineNumber;
  9605. if (lineView.changes) {
  9606. if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; }
  9607. updateLineForChanges(cm, lineView, lineN, dims);
  9608. }
  9609. if (updateNumber) {
  9610. removeChildren(lineView.lineNumber);
  9611. lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
  9612. }
  9613. cur = lineView.node.nextSibling;
  9614. }
  9615. lineN += lineView.size;
  9616. }
  9617. while (cur) { cur = rm(cur); }
  9618. }
  9619. function updateGutterSpace(display) {
  9620. var width = display.gutters.offsetWidth;
  9621. display.sizer.style.marginLeft = width + "px";
  9622. }
  9623. function setDocumentHeight(cm, measure) {
  9624. cm.display.sizer.style.minHeight = measure.docHeight + "px";
  9625. cm.display.heightForcer.style.top = measure.docHeight + "px";
  9626. cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
  9627. }
  9628. // Re-align line numbers and gutter marks to compensate for
  9629. // horizontal scrolling.
  9630. function alignHorizontally(cm) {
  9631. var display = cm.display, view = display.view;
  9632. if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
  9633. var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
  9634. var gutterW = display.gutters.offsetWidth, left = comp + "px";
  9635. for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
  9636. if (cm.options.fixedGutter) {
  9637. if (view[i].gutter)
  9638. { view[i].gutter.style.left = left; }
  9639. if (view[i].gutterBackground)
  9640. { view[i].gutterBackground.style.left = left; }
  9641. }
  9642. var align = view[i].alignable;
  9643. if (align) { for (var j = 0; j < align.length; j++)
  9644. { align[j].style.left = left; } }
  9645. } }
  9646. if (cm.options.fixedGutter)
  9647. { display.gutters.style.left = (comp + gutterW) + "px"; }
  9648. }
  9649. // Used to ensure that the line number gutter is still the right
  9650. // size for the current document size. Returns true when an update
  9651. // is needed.
  9652. function maybeUpdateLineNumberWidth(cm) {
  9653. if (!cm.options.lineNumbers) { return false }
  9654. var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
  9655. if (last.length != display.lineNumChars) {
  9656. var test = display.measure.appendChild(elt("div", [elt("div", last)],
  9657. "CodeMirror-linenumber CodeMirror-gutter-elt"));
  9658. var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
  9659. display.lineGutter.style.width = "";
  9660. display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
  9661. display.lineNumWidth = display.lineNumInnerWidth + padding;
  9662. display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
  9663. display.lineGutter.style.width = display.lineNumWidth + "px";
  9664. updateGutterSpace(cm.display);
  9665. return true
  9666. }
  9667. return false
  9668. }
  9669. function getGutters(gutters, lineNumbers) {
  9670. var result = [], sawLineNumbers = false;
  9671. for (var i = 0; i < gutters.length; i++) {
  9672. var name = gutters[i], style = null;
  9673. if (typeof name != "string") { style = name.style; name = name.className; }
  9674. if (name == "CodeMirror-linenumbers") {
  9675. if (!lineNumbers) { continue }
  9676. else { sawLineNumbers = true; }
  9677. }
  9678. result.push({className: name, style: style});
  9679. }
  9680. if (lineNumbers && !sawLineNumbers) { result.push({className: "CodeMirror-linenumbers", style: null}); }
  9681. return result
  9682. }
  9683. // Rebuild the gutter elements, ensure the margin to the left of the
  9684. // code matches their width.
  9685. function renderGutters(display) {
  9686. var gutters = display.gutters, specs = display.gutterSpecs;
  9687. removeChildren(gutters);
  9688. display.lineGutter = null;
  9689. for (var i = 0; i < specs.length; ++i) {
  9690. var ref = specs[i];
  9691. var className = ref.className;
  9692. var style = ref.style;
  9693. var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + className));
  9694. if (style) { gElt.style.cssText = style; }
  9695. if (className == "CodeMirror-linenumbers") {
  9696. display.lineGutter = gElt;
  9697. gElt.style.width = (display.lineNumWidth || 1) + "px";
  9698. }
  9699. }
  9700. gutters.style.display = specs.length ? "" : "none";
  9701. updateGutterSpace(display);
  9702. }
  9703. function updateGutters(cm) {
  9704. renderGutters(cm.display);
  9705. regChange(cm);
  9706. alignHorizontally(cm);
  9707. }
  9708. // The display handles the DOM integration, both for input reading
  9709. // and content drawing. It holds references to DOM nodes and
  9710. // display-related state.
  9711. function Display(place, doc, input, options) {
  9712. var d = this;
  9713. this.input = input;
  9714. // Covers bottom-right square when both scrollbars are present.
  9715. d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
  9716. d.scrollbarFiller.setAttribute("cm-not-content", "true");
  9717. // Covers bottom of gutter when coverGutterNextToScrollbar is on
  9718. // and h scrollbar is present.
  9719. d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
  9720. d.gutterFiller.setAttribute("cm-not-content", "true");
  9721. // Will contain the actual code, positioned to cover the viewport.
  9722. d.lineDiv = eltP("div", null, "CodeMirror-code");
  9723. // Elements are added to these to represent selection and cursors.
  9724. d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
  9725. d.cursorDiv = elt("div", null, "CodeMirror-cursors");
  9726. // A visibility: hidden element used to find the size of things.
  9727. d.measure = elt("div", null, "CodeMirror-measure");
  9728. // When lines outside of the viewport are measured, they are drawn in this.
  9729. d.lineMeasure = elt("div", null, "CodeMirror-measure");
  9730. // Wraps everything that needs to exist inside the vertically-padded coordinate system
  9731. d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
  9732. null, "position: relative; outline: none");
  9733. var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
  9734. // Moved around its parent to cover visible view.
  9735. d.mover = elt("div", [lines], null, "position: relative");
  9736. // Set to the height of the document, allowing scrolling.
  9737. d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
  9738. d.sizerWidth = null;
  9739. // Behavior of elts with overflow: auto and padding is
  9740. // inconsistent across browsers. This is used to ensure the
  9741. // scrollable area is big enough.
  9742. d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
  9743. // Will contain the gutters, if any.
  9744. d.gutters = elt("div", null, "CodeMirror-gutters");
  9745. d.lineGutter = null;
  9746. // Actual scrollable element.
  9747. d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
  9748. d.scroller.setAttribute("tabIndex", "-1");
  9749. // The element in which the editor lives.
  9750. d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
  9751. // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
  9752. if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
  9753. if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; }
  9754. if (place) {
  9755. if (place.appendChild) { place.appendChild(d.wrapper); }
  9756. else { place(d.wrapper); }
  9757. }
  9758. // Current rendered range (may be bigger than the view window).
  9759. d.viewFrom = d.viewTo = doc.first;
  9760. d.reportedViewFrom = d.reportedViewTo = doc.first;
  9761. // Information about the rendered lines.
  9762. d.view = [];
  9763. d.renderedView = null;
  9764. // Holds info about a single rendered line when it was rendered
  9765. // for measurement, while not in view.
  9766. d.externalMeasured = null;
  9767. // Empty space (in pixels) above the view
  9768. d.viewOffset = 0;
  9769. d.lastWrapHeight = d.lastWrapWidth = 0;
  9770. d.updateLineNumbers = null;
  9771. d.nativeBarWidth = d.barHeight = d.barWidth = 0;
  9772. d.scrollbarsClipped = false;
  9773. // Used to only resize the line number gutter when necessary (when
  9774. // the amount of lines crosses a boundary that makes its width change)
  9775. d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
  9776. // Set to true when a non-horizontal-scrolling line widget is
  9777. // added. As an optimization, line widget aligning is skipped when
  9778. // this is false.
  9779. d.alignWidgets = false;
  9780. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  9781. // Tracks the maximum line length so that the horizontal scrollbar
  9782. // can be kept static when scrolling.
  9783. d.maxLine = null;
  9784. d.maxLineLength = 0;
  9785. d.maxLineChanged = false;
  9786. // Used for measuring wheel scrolling granularity
  9787. d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
  9788. // True when shift is held down.
  9789. d.shift = false;
  9790. // Used to track whether anything happened since the context menu
  9791. // was opened.
  9792. d.selForContextMenu = null;
  9793. d.activeTouch = null;
  9794. d.gutterSpecs = getGutters(options.gutters, options.lineNumbers);
  9795. renderGutters(d);
  9796. input.init(d);
  9797. }
  9798. // Since the delta values reported on mouse wheel events are
  9799. // unstandardized between browsers and even browser versions, and
  9800. // generally horribly unpredictable, this code starts by measuring
  9801. // the scroll effect that the first few mouse wheel events have,
  9802. // and, from that, detects the way it can convert deltas to pixel
  9803. // offsets afterwards.
  9804. //
  9805. // The reason we want to know the amount a wheel event will scroll
  9806. // is that it gives us a chance to update the display before the
  9807. // actual scrolling happens, reducing flickering.
  9808. var wheelSamples = 0, wheelPixelsPerUnit = null;
  9809. // Fill in a browser-detected starting value on browsers where we
  9810. // know one. These don't have to be accurate -- the result of them
  9811. // being wrong would just be a slight flicker on the first wheel
  9812. // scroll (if it is large enough).
  9813. if (ie) { wheelPixelsPerUnit = -.53; }
  9814. else if (gecko) { wheelPixelsPerUnit = 15; }
  9815. else if (chrome) { wheelPixelsPerUnit = -.7; }
  9816. else if (safari) { wheelPixelsPerUnit = -1/3; }
  9817. function wheelEventDelta(e) {
  9818. var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
  9819. if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; }
  9820. if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; }
  9821. else if (dy == null) { dy = e.wheelDelta; }
  9822. return {x: dx, y: dy}
  9823. }
  9824. function wheelEventPixels(e) {
  9825. var delta = wheelEventDelta(e);
  9826. delta.x *= wheelPixelsPerUnit;
  9827. delta.y *= wheelPixelsPerUnit;
  9828. return delta
  9829. }
  9830. function onScrollWheel(cm, e) {
  9831. var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
  9832. var display = cm.display, scroll = display.scroller;
  9833. // Quit if there's nothing to scroll here
  9834. var canScrollX = scroll.scrollWidth > scroll.clientWidth;
  9835. var canScrollY = scroll.scrollHeight > scroll.clientHeight;
  9836. if (!(dx && canScrollX || dy && canScrollY)) { return }
  9837. // Webkit browsers on OS X abort momentum scrolls when the target
  9838. // of the scroll event is removed from the scrollable element.
  9839. // This hack (see related code in patchDisplay) makes sure the
  9840. // element is kept around.
  9841. if (dy && mac && webkit) {
  9842. outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
  9843. for (var i = 0; i < view.length; i++) {
  9844. if (view[i].node == cur) {
  9845. cm.display.currentWheelTarget = cur;
  9846. break outer
  9847. }
  9848. }
  9849. }
  9850. }
  9851. // On some browsers, horizontal scrolling will cause redraws to
  9852. // happen before the gutter has been realigned, causing it to
  9853. // wriggle around in a most unseemly way. When we have an
  9854. // estimated pixels/delta value, we just handle horizontal
  9855. // scrolling entirely here. It'll be slightly off from native, but
  9856. // better than glitching out.
  9857. if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
  9858. if (dy && canScrollY)
  9859. { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); }
  9860. setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit));
  9861. // Only prevent default scrolling if vertical scrolling is
  9862. // actually possible. Otherwise, it causes vertical scroll
  9863. // jitter on OSX trackpads when deltaX is small and deltaY
  9864. // is large (issue #3579)
  9865. if (!dy || (dy && canScrollY))
  9866. { e_preventDefault(e); }
  9867. display.wheelStartX = null; // Abort measurement, if in progress
  9868. return
  9869. }
  9870. // 'Project' the visible viewport to cover the area that is being
  9871. // scrolled into view (if we know enough to estimate it).
  9872. if (dy && wheelPixelsPerUnit != null) {
  9873. var pixels = dy * wheelPixelsPerUnit;
  9874. var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
  9875. if (pixels < 0) { top = Math.max(0, top + pixels - 50); }
  9876. else { bot = Math.min(cm.doc.height, bot + pixels + 50); }
  9877. updateDisplaySimple(cm, {top: top, bottom: bot});
  9878. }
  9879. if (wheelSamples < 20) {
  9880. if (display.wheelStartX == null) {
  9881. display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
  9882. display.wheelDX = dx; display.wheelDY = dy;
  9883. setTimeout(function () {
  9884. if (display.wheelStartX == null) { return }
  9885. var movedX = scroll.scrollLeft - display.wheelStartX;
  9886. var movedY = scroll.scrollTop - display.wheelStartY;
  9887. var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
  9888. (movedX && display.wheelDX && movedX / display.wheelDX);
  9889. display.wheelStartX = display.wheelStartY = null;
  9890. if (!sample) { return }
  9891. wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
  9892. ++wheelSamples;
  9893. }, 200);
  9894. } else {
  9895. display.wheelDX += dx; display.wheelDY += dy;
  9896. }
  9897. }
  9898. }
  9899. // Selection objects are immutable. A new one is created every time
  9900. // the selection changes. A selection is one or more non-overlapping
  9901. // (and non-touching) ranges, sorted, and an integer that indicates
  9902. // which one is the primary selection (the one that's scrolled into
  9903. // view, that getCursor returns, etc).
  9904. var Selection = function(ranges, primIndex) {
  9905. this.ranges = ranges;
  9906. this.primIndex = primIndex;
  9907. };
  9908. Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
  9909. Selection.prototype.equals = function (other) {
  9910. if (other == this) { return true }
  9911. if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
  9912. for (var i = 0; i < this.ranges.length; i++) {
  9913. var here = this.ranges[i], there = other.ranges[i];
  9914. if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
  9915. }
  9916. return true
  9917. };
  9918. Selection.prototype.deepCopy = function () {
  9919. var out = [];
  9920. for (var i = 0; i < this.ranges.length; i++)
  9921. { out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head)); }
  9922. return new Selection(out, this.primIndex)
  9923. };
  9924. Selection.prototype.somethingSelected = function () {
  9925. for (var i = 0; i < this.ranges.length; i++)
  9926. { if (!this.ranges[i].empty()) { return true } }
  9927. return false
  9928. };
  9929. Selection.prototype.contains = function (pos, end) {
  9930. if (!end) { end = pos; }
  9931. for (var i = 0; i < this.ranges.length; i++) {
  9932. var range = this.ranges[i];
  9933. if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
  9934. { return i }
  9935. }
  9936. return -1
  9937. };
  9938. var Range = function(anchor, head) {
  9939. this.anchor = anchor; this.head = head;
  9940. };
  9941. Range.prototype.from = function () { return minPos(this.anchor, this.head) };
  9942. Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
  9943. Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
  9944. // Take an unsorted, potentially overlapping set of ranges, and
  9945. // build a selection out of it. 'Consumes' ranges array (modifying
  9946. // it).
  9947. function normalizeSelection(cm, ranges, primIndex) {
  9948. var mayTouch = cm && cm.options.selectionsMayTouch;
  9949. var prim = ranges[primIndex];
  9950. ranges.sort(function (a, b) { return cmp(a.from(), b.from()); });
  9951. primIndex = indexOf(ranges, prim);
  9952. for (var i = 1; i < ranges.length; i++) {
  9953. var cur = ranges[i], prev = ranges[i - 1];
  9954. var diff = cmp(prev.to(), cur.from());
  9955. if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
  9956. var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
  9957. var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
  9958. if (i <= primIndex) { --primIndex; }
  9959. ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
  9960. }
  9961. }
  9962. return new Selection(ranges, primIndex)
  9963. }
  9964. function simpleSelection(anchor, head) {
  9965. return new Selection([new Range(anchor, head || anchor)], 0)
  9966. }
  9967. // Compute the position of the end of a change (its 'to' property
  9968. // refers to the pre-change end).
  9969. function changeEnd(change) {
  9970. if (!change.text) { return change.to }
  9971. return Pos(change.from.line + change.text.length - 1,
  9972. lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
  9973. }
  9974. // Adjust a position to refer to the post-change position of the
  9975. // same text, or the end of the change if the change covers it.
  9976. function adjustForChange(pos, change) {
  9977. if (cmp(pos, change.from) < 0) { return pos }
  9978. if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
  9979. var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
  9980. if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; }
  9981. return Pos(line, ch)
  9982. }
  9983. function computeSelAfterChange(doc, change) {
  9984. var out = [];
  9985. for (var i = 0; i < doc.sel.ranges.length; i++) {
  9986. var range = doc.sel.ranges[i];
  9987. out.push(new Range(adjustForChange(range.anchor, change),
  9988. adjustForChange(range.head, change)));
  9989. }
  9990. return normalizeSelection(doc.cm, out, doc.sel.primIndex)
  9991. }
  9992. function offsetPos(pos, old, nw) {
  9993. if (pos.line == old.line)
  9994. { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
  9995. else
  9996. { return Pos(nw.line + (pos.line - old.line), pos.ch) }
  9997. }
  9998. // Used by replaceSelections to allow moving the selection to the
  9999. // start or around the replaced test. Hint may be "start" or "around".
  10000. function computeReplacedSel(doc, changes, hint) {
  10001. var out = [];
  10002. var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
  10003. for (var i = 0; i < changes.length; i++) {
  10004. var change = changes[i];
  10005. var from = offsetPos(change.from, oldPrev, newPrev);
  10006. var to = offsetPos(changeEnd(change), oldPrev, newPrev);
  10007. oldPrev = change.to;
  10008. newPrev = to;
  10009. if (hint == "around") {
  10010. var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
  10011. out[i] = new Range(inv ? to : from, inv ? from : to);
  10012. } else {
  10013. out[i] = new Range(from, from);
  10014. }
  10015. }
  10016. return new Selection(out, doc.sel.primIndex)
  10017. }
  10018. // Used to get the editor into a consistent state again when options change.
  10019. function loadMode(cm) {
  10020. cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
  10021. resetModeState(cm);
  10022. }
  10023. function resetModeState(cm) {
  10024. cm.doc.iter(function (line) {
  10025. if (line.stateAfter) { line.stateAfter = null; }
  10026. if (line.styles) { line.styles = null; }
  10027. });
  10028. cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
  10029. startWorker(cm, 100);
  10030. cm.state.modeGen++;
  10031. if (cm.curOp) { regChange(cm); }
  10032. }
  10033. // DOCUMENT DATA STRUCTURE
  10034. // By default, updates that start and end at the beginning of a line
  10035. // are treated specially, in order to make the association of line
  10036. // widgets and marker elements with the text behave more intuitive.
  10037. function isWholeLineUpdate(doc, change) {
  10038. return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
  10039. (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
  10040. }
  10041. // Perform a change on the document data structure.
  10042. function updateDoc(doc, change, markedSpans, estimateHeight) {
  10043. function spansFor(n) {return markedSpans ? markedSpans[n] : null}
  10044. function update(line, text, spans) {
  10045. updateLine(line, text, spans, estimateHeight);
  10046. signalLater(line, "change", line, change);
  10047. }
  10048. function linesFor(start, end) {
  10049. var result = [];
  10050. for (var i = start; i < end; ++i)
  10051. { result.push(new Line(text[i], spansFor(i), estimateHeight)); }
  10052. return result
  10053. }
  10054. var from = change.from, to = change.to, text = change.text;
  10055. var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
  10056. var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
  10057. // Adjust the line structure
  10058. if (change.full) {
  10059. doc.insert(0, linesFor(0, text.length));
  10060. doc.remove(text.length, doc.size - text.length);
  10061. } else if (isWholeLineUpdate(doc, change)) {
  10062. // This is a whole-line replace. Treated specially to make
  10063. // sure line objects move the way they are supposed to.
  10064. var added = linesFor(0, text.length - 1);
  10065. update(lastLine, lastLine.text, lastSpans);
  10066. if (nlines) { doc.remove(from.line, nlines); }
  10067. if (added.length) { doc.insert(from.line, added); }
  10068. } else if (firstLine == lastLine) {
  10069. if (text.length == 1) {
  10070. update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
  10071. } else {
  10072. var added$1 = linesFor(1, text.length - 1);
  10073. added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
  10074. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  10075. doc.insert(from.line + 1, added$1);
  10076. }
  10077. } else if (text.length == 1) {
  10078. update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
  10079. doc.remove(from.line + 1, nlines);
  10080. } else {
  10081. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  10082. update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
  10083. var added$2 = linesFor(1, text.length - 1);
  10084. if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); }
  10085. doc.insert(from.line + 1, added$2);
  10086. }
  10087. signalLater(doc, "change", doc, change);
  10088. }
  10089. // Call f for all linked documents.
  10090. function linkedDocs(doc, f, sharedHistOnly) {
  10091. function propagate(doc, skip, sharedHist) {
  10092. if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
  10093. var rel = doc.linked[i];
  10094. if (rel.doc == skip) { continue }
  10095. var shared = sharedHist && rel.sharedHist;
  10096. if (sharedHistOnly && !shared) { continue }
  10097. f(rel.doc, shared);
  10098. propagate(rel.doc, doc, shared);
  10099. } }
  10100. }
  10101. propagate(doc, null, true);
  10102. }
  10103. // Attach a document to an editor.
  10104. function attachDoc(cm, doc) {
  10105. if (doc.cm) { throw new Error("This document is already in use.") }
  10106. cm.doc = doc;
  10107. doc.cm = cm;
  10108. estimateLineHeights(cm);
  10109. loadMode(cm);
  10110. setDirectionClass(cm);
  10111. if (!cm.options.lineWrapping) { findMaxLine(cm); }
  10112. cm.options.mode = doc.modeOption;
  10113. regChange(cm);
  10114. }
  10115. function setDirectionClass(cm) {
  10116. (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
  10117. }
  10118. function directionChanged(cm) {
  10119. runInOp(cm, function () {
  10120. setDirectionClass(cm);
  10121. regChange(cm);
  10122. });
  10123. }
  10124. function History(startGen) {
  10125. // Arrays of change events and selections. Doing something adds an
  10126. // event to done and clears undo. Undoing moves events from done
  10127. // to undone, redoing moves them in the other direction.
  10128. this.done = []; this.undone = [];
  10129. this.undoDepth = Infinity;
  10130. // Used to track when changes can be merged into a single undo
  10131. // event
  10132. this.lastModTime = this.lastSelTime = 0;
  10133. this.lastOp = this.lastSelOp = null;
  10134. this.lastOrigin = this.lastSelOrigin = null;
  10135. // Used by the isClean() method
  10136. this.generation = this.maxGeneration = startGen || 1;
  10137. }
  10138. // Create a history change event from an updateDoc-style change
  10139. // object.
  10140. function historyChangeFromChange(doc, change) {
  10141. var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
  10142. attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
  10143. linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true);
  10144. return histChange
  10145. }
  10146. // Pop all selection events off the end of a history array. Stop at
  10147. // a change event.
  10148. function clearSelectionEvents(array) {
  10149. while (array.length) {
  10150. var last = lst(array);
  10151. if (last.ranges) { array.pop(); }
  10152. else { break }
  10153. }
  10154. }
  10155. // Find the top change event in the history. Pop off selection
  10156. // events that are in the way.
  10157. function lastChangeEvent(hist, force) {
  10158. if (force) {
  10159. clearSelectionEvents(hist.done);
  10160. return lst(hist.done)
  10161. } else if (hist.done.length && !lst(hist.done).ranges) {
  10162. return lst(hist.done)
  10163. } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
  10164. hist.done.pop();
  10165. return lst(hist.done)
  10166. }
  10167. }
  10168. // Register a change in the history. Merges changes that are within
  10169. // a single operation, or are close together with an origin that
  10170. // allows merging (starting with "+") into a single event.
  10171. function addChangeToHistory(doc, change, selAfter, opId) {
  10172. var hist = doc.history;
  10173. hist.undone.length = 0;
  10174. var time = +new Date, cur;
  10175. var last;
  10176. if ((hist.lastOp == opId ||
  10177. hist.lastOrigin == change.origin && change.origin &&
  10178. ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
  10179. change.origin.charAt(0) == "*")) &&
  10180. (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
  10181. // Merge this change into the last event
  10182. last = lst(cur.changes);
  10183. if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
  10184. // Optimized case for simple insertion -- don't want to add
  10185. // new changesets for every character typed
  10186. last.to = changeEnd(change);
  10187. } else {
  10188. // Add new sub-event
  10189. cur.changes.push(historyChangeFromChange(doc, change));
  10190. }
  10191. } else {
  10192. // Can not be merged, start a new event.
  10193. var before = lst(hist.done);
  10194. if (!before || !before.ranges)
  10195. { pushSelectionToHistory(doc.sel, hist.done); }
  10196. cur = {changes: [historyChangeFromChange(doc, change)],
  10197. generation: hist.generation};
  10198. hist.done.push(cur);
  10199. while (hist.done.length > hist.undoDepth) {
  10200. hist.done.shift();
  10201. if (!hist.done[0].ranges) { hist.done.shift(); }
  10202. }
  10203. }
  10204. hist.done.push(selAfter);
  10205. hist.generation = ++hist.maxGeneration;
  10206. hist.lastModTime = hist.lastSelTime = time;
  10207. hist.lastOp = hist.lastSelOp = opId;
  10208. hist.lastOrigin = hist.lastSelOrigin = change.origin;
  10209. if (!last) { signal(doc, "historyAdded"); }
  10210. }
  10211. function selectionEventCanBeMerged(doc, origin, prev, sel) {
  10212. var ch = origin.charAt(0);
  10213. return ch == "*" ||
  10214. ch == "+" &&
  10215. prev.ranges.length == sel.ranges.length &&
  10216. prev.somethingSelected() == sel.somethingSelected() &&
  10217. new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
  10218. }
  10219. // Called whenever the selection changes, sets the new selection as
  10220. // the pending selection in the history, and pushes the old pending
  10221. // selection into the 'done' array when it was significantly
  10222. // different (in number of selected ranges, emptiness, or time).
  10223. function addSelectionToHistory(doc, sel, opId, options) {
  10224. var hist = doc.history, origin = options && options.origin;
  10225. // A new event is started when the previous origin does not match
  10226. // the current, or the origins don't allow matching. Origins
  10227. // starting with * are always merged, those starting with + are
  10228. // merged when similar and close together in time.
  10229. if (opId == hist.lastSelOp ||
  10230. (origin && hist.lastSelOrigin == origin &&
  10231. (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
  10232. selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
  10233. { hist.done[hist.done.length - 1] = sel; }
  10234. else
  10235. { pushSelectionToHistory(sel, hist.done); }
  10236. hist.lastSelTime = +new Date;
  10237. hist.lastSelOrigin = origin;
  10238. hist.lastSelOp = opId;
  10239. if (options && options.clearRedo !== false)
  10240. { clearSelectionEvents(hist.undone); }
  10241. }
  10242. function pushSelectionToHistory(sel, dest) {
  10243. var top = lst(dest);
  10244. if (!(top && top.ranges && top.equals(sel)))
  10245. { dest.push(sel); }
  10246. }
  10247. // Used to store marked span information in the history.
  10248. function attachLocalSpans(doc, change, from, to) {
  10249. var existing = change["spans_" + doc.id], n = 0;
  10250. doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
  10251. if (line.markedSpans)
  10252. { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; }
  10253. ++n;
  10254. });
  10255. }
  10256. // When un/re-doing restores text containing marked spans, those
  10257. // that have been explicitly cleared should not be restored.
  10258. function removeClearedSpans(spans) {
  10259. if (!spans) { return null }
  10260. var out;
  10261. for (var i = 0; i < spans.length; ++i) {
  10262. if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } }
  10263. else if (out) { out.push(spans[i]); }
  10264. }
  10265. return !out ? spans : out.length ? out : null
  10266. }
  10267. // Retrieve and filter the old marked spans stored in a change event.
  10268. function getOldSpans(doc, change) {
  10269. var found = change["spans_" + doc.id];
  10270. if (!found) { return null }
  10271. var nw = [];
  10272. for (var i = 0; i < change.text.length; ++i)
  10273. { nw.push(removeClearedSpans(found[i])); }
  10274. return nw
  10275. }
  10276. // Used for un/re-doing changes from the history. Combines the
  10277. // result of computing the existing spans with the set of spans that
  10278. // existed in the history (so that deleting around a span and then
  10279. // undoing brings back the span).
  10280. function mergeOldSpans(doc, change) {
  10281. var old = getOldSpans(doc, change);
  10282. var stretched = stretchSpansOverChange(doc, change);
  10283. if (!old) { return stretched }
  10284. if (!stretched) { return old }
  10285. for (var i = 0; i < old.length; ++i) {
  10286. var oldCur = old[i], stretchCur = stretched[i];
  10287. if (oldCur && stretchCur) {
  10288. spans: for (var j = 0; j < stretchCur.length; ++j) {
  10289. var span = stretchCur[j];
  10290. for (var k = 0; k < oldCur.length; ++k)
  10291. { if (oldCur[k].marker == span.marker) { continue spans } }
  10292. oldCur.push(span);
  10293. }
  10294. } else if (stretchCur) {
  10295. old[i] = stretchCur;
  10296. }
  10297. }
  10298. return old
  10299. }
  10300. // Used both to provide a JSON-safe object in .getHistory, and, when
  10301. // detaching a document, to split the history in two
  10302. function copyHistoryArray(events, newGroup, instantiateSel) {
  10303. var copy = [];
  10304. for (var i = 0; i < events.length; ++i) {
  10305. var event = events[i];
  10306. if (event.ranges) {
  10307. copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
  10308. continue
  10309. }
  10310. var changes = event.changes, newChanges = [];
  10311. copy.push({changes: newChanges});
  10312. for (var j = 0; j < changes.length; ++j) {
  10313. var change = changes[j], m = (void 0);
  10314. newChanges.push({from: change.from, to: change.to, text: change.text});
  10315. if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
  10316. if (indexOf(newGroup, Number(m[1])) > -1) {
  10317. lst(newChanges)[prop] = change[prop];
  10318. delete change[prop];
  10319. }
  10320. } } }
  10321. }
  10322. }
  10323. return copy
  10324. }
  10325. // The 'scroll' parameter given to many of these indicated whether
  10326. // the new cursor position should be scrolled into view after
  10327. // modifying the selection.
  10328. // If shift is held or the extend flag is set, extends a range to
  10329. // include a given position (and optionally a second position).
  10330. // Otherwise, simply returns the range between the given positions.
  10331. // Used for cursor motion and such.
  10332. function extendRange(range, head, other, extend) {
  10333. if (extend) {
  10334. var anchor = range.anchor;
  10335. if (other) {
  10336. var posBefore = cmp(head, anchor) < 0;
  10337. if (posBefore != (cmp(other, anchor) < 0)) {
  10338. anchor = head;
  10339. head = other;
  10340. } else if (posBefore != (cmp(head, other) < 0)) {
  10341. head = other;
  10342. }
  10343. }
  10344. return new Range(anchor, head)
  10345. } else {
  10346. return new Range(other || head, head)
  10347. }
  10348. }
  10349. // Extend the primary selection range, discard the rest.
  10350. function extendSelection(doc, head, other, options, extend) {
  10351. if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); }
  10352. setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);
  10353. }
  10354. // Extend all selections (pos is an array of selections with length
  10355. // equal the number of selections)
  10356. function extendSelections(doc, heads, options) {
  10357. var out = [];
  10358. var extend = doc.cm && (doc.cm.display.shift || doc.extend);
  10359. for (var i = 0; i < doc.sel.ranges.length; i++)
  10360. { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); }
  10361. var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex);
  10362. setSelection(doc, newSel, options);
  10363. }
  10364. // Updates a single range in the selection.
  10365. function replaceOneSelection(doc, i, range, options) {
  10366. var ranges = doc.sel.ranges.slice(0);
  10367. ranges[i] = range;
  10368. setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options);
  10369. }
  10370. // Reset the selection to a single range.
  10371. function setSimpleSelection(doc, anchor, head, options) {
  10372. setSelection(doc, simpleSelection(anchor, head), options);
  10373. }
  10374. // Give beforeSelectionChange handlers a change to influence a
  10375. // selection update.
  10376. function filterSelectionChange(doc, sel, options) {
  10377. var obj = {
  10378. ranges: sel.ranges,
  10379. update: function(ranges) {
  10380. this.ranges = [];
  10381. for (var i = 0; i < ranges.length; i++)
  10382. { this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
  10383. clipPos(doc, ranges[i].head)); }
  10384. },
  10385. origin: options && options.origin
  10386. };
  10387. signal(doc, "beforeSelectionChange", doc, obj);
  10388. if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); }
  10389. if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) }
  10390. else { return sel }
  10391. }
  10392. function setSelectionReplaceHistory(doc, sel, options) {
  10393. var done = doc.history.done, last = lst(done);
  10394. if (last && last.ranges) {
  10395. done[done.length - 1] = sel;
  10396. setSelectionNoUndo(doc, sel, options);
  10397. } else {
  10398. setSelection(doc, sel, options);
  10399. }
  10400. }
  10401. // Set a new selection.
  10402. function setSelection(doc, sel, options) {
  10403. setSelectionNoUndo(doc, sel, options);
  10404. addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
  10405. }
  10406. function setSelectionNoUndo(doc, sel, options) {
  10407. if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
  10408. { sel = filterSelectionChange(doc, sel, options); }
  10409. var bias = options && options.bias ||
  10410. (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
  10411. setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
  10412. if (!(options && options.scroll === false) && doc.cm)
  10413. { ensureCursorVisible(doc.cm); }
  10414. }
  10415. function setSelectionInner(doc, sel) {
  10416. if (sel.equals(doc.sel)) { return }
  10417. doc.sel = sel;
  10418. if (doc.cm) {
  10419. doc.cm.curOp.updateInput = 1;
  10420. doc.cm.curOp.selectionChanged = true;
  10421. signalCursorActivity(doc.cm);
  10422. }
  10423. signalLater(doc, "cursorActivity", doc);
  10424. }
  10425. // Verify that the selection does not partially select any atomic
  10426. // marked ranges.
  10427. function reCheckSelection(doc) {
  10428. setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));
  10429. }
  10430. // Return a selection that does not partially select any atomic
  10431. // ranges.
  10432. function skipAtomicInSelection(doc, sel, bias, mayClear) {
  10433. var out;
  10434. for (var i = 0; i < sel.ranges.length; i++) {
  10435. var range = sel.ranges[i];
  10436. var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
  10437. var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
  10438. var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
  10439. if (out || newAnchor != range.anchor || newHead != range.head) {
  10440. if (!out) { out = sel.ranges.slice(0, i); }
  10441. out[i] = new Range(newAnchor, newHead);
  10442. }
  10443. }
  10444. return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
  10445. }
  10446. function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
  10447. var line = getLine(doc, pos.line);
  10448. if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
  10449. var sp = line.markedSpans[i], m = sp.marker;
  10450. // Determine if we should prevent the cursor being placed to the left/right of an atomic marker
  10451. // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it
  10452. // is with selectLeft/Right
  10453. var preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft;
  10454. var preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight;
  10455. if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
  10456. (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
  10457. if (mayClear) {
  10458. signal(m, "beforeCursorEnter");
  10459. if (m.explicitlyCleared) {
  10460. if (!line.markedSpans) { break }
  10461. else {--i; continue}
  10462. }
  10463. }
  10464. if (!m.atomic) { continue }
  10465. if (oldPos) {
  10466. var near = m.find(dir < 0 ? 1 : -1), diff = (void 0);
  10467. if (dir < 0 ? preventCursorRight : preventCursorLeft)
  10468. { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); }
  10469. if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
  10470. { return skipAtomicInner(doc, near, pos, dir, mayClear) }
  10471. }
  10472. var far = m.find(dir < 0 ? -1 : 1);
  10473. if (dir < 0 ? preventCursorLeft : preventCursorRight)
  10474. { far = movePos(doc, far, dir, far.line == pos.line ? line : null); }
  10475. return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
  10476. }
  10477. } }
  10478. return pos
  10479. }
  10480. // Ensure a given position is not inside an atomic range.
  10481. function skipAtomic(doc, pos, oldPos, bias, mayClear) {
  10482. var dir = bias || 1;
  10483. var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
  10484. (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
  10485. skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
  10486. (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
  10487. if (!found) {
  10488. doc.cantEdit = true;
  10489. return Pos(doc.first, 0)
  10490. }
  10491. return found
  10492. }
  10493. function movePos(doc, pos, dir, line) {
  10494. if (dir < 0 && pos.ch == 0) {
  10495. if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
  10496. else { return null }
  10497. } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
  10498. if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
  10499. else { return null }
  10500. } else {
  10501. return new Pos(pos.line, pos.ch + dir)
  10502. }
  10503. }
  10504. function selectAll(cm) {
  10505. cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
  10506. }
  10507. // UPDATING
  10508. // Allow "beforeChange" event handlers to influence a change
  10509. function filterChange(doc, change, update) {
  10510. var obj = {
  10511. canceled: false,
  10512. from: change.from,
  10513. to: change.to,
  10514. text: change.text,
  10515. origin: change.origin,
  10516. cancel: function () { return obj.canceled = true; }
  10517. };
  10518. if (update) { obj.update = function (from, to, text, origin) {
  10519. if (from) { obj.from = clipPos(doc, from); }
  10520. if (to) { obj.to = clipPos(doc, to); }
  10521. if (text) { obj.text = text; }
  10522. if (origin !== undefined) { obj.origin = origin; }
  10523. }; }
  10524. signal(doc, "beforeChange", doc, obj);
  10525. if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); }
  10526. if (obj.canceled) {
  10527. if (doc.cm) { doc.cm.curOp.updateInput = 2; }
  10528. return null
  10529. }
  10530. return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
  10531. }
  10532. // Apply a change to a document, and add it to the document's
  10533. // history, and propagating it to all linked documents.
  10534. function makeChange(doc, change, ignoreReadOnly) {
  10535. if (doc.cm) {
  10536. if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
  10537. if (doc.cm.state.suppressEdits) { return }
  10538. }
  10539. if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
  10540. change = filterChange(doc, change, true);
  10541. if (!change) { return }
  10542. }
  10543. // Possibly split or suppress the update based on the presence
  10544. // of read-only spans in its range.
  10545. var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
  10546. if (split) {
  10547. for (var i = split.length - 1; i >= 0; --i)
  10548. { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); }
  10549. } else {
  10550. makeChangeInner(doc, change);
  10551. }
  10552. }
  10553. function makeChangeInner(doc, change) {
  10554. if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
  10555. var selAfter = computeSelAfterChange(doc, change);
  10556. addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
  10557. makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
  10558. var rebased = [];
  10559. linkedDocs(doc, function (doc, sharedHist) {
  10560. if (!sharedHist && indexOf(rebased, doc.history) == -1) {
  10561. rebaseHist(doc.history, change);
  10562. rebased.push(doc.history);
  10563. }
  10564. makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
  10565. });
  10566. }
  10567. // Revert a change stored in a document's history.
  10568. function makeChangeFromHistory(doc, type, allowSelectionOnly) {
  10569. var suppress = doc.cm && doc.cm.state.suppressEdits;
  10570. if (suppress && !allowSelectionOnly) { return }
  10571. var hist = doc.history, event, selAfter = doc.sel;
  10572. var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
  10573. // Verify that there is a useable event (so that ctrl-z won't
  10574. // needlessly clear selection events)
  10575. var i = 0;
  10576. for (; i < source.length; i++) {
  10577. event = source[i];
  10578. if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
  10579. { break }
  10580. }
  10581. if (i == source.length) { return }
  10582. hist.lastOrigin = hist.lastSelOrigin = null;
  10583. for (;;) {
  10584. event = source.pop();
  10585. if (event.ranges) {
  10586. pushSelectionToHistory(event, dest);
  10587. if (allowSelectionOnly && !event.equals(doc.sel)) {
  10588. setSelection(doc, event, {clearRedo: false});
  10589. return
  10590. }
  10591. selAfter = event;
  10592. } else if (suppress) {
  10593. source.push(event);
  10594. return
  10595. } else { break }
  10596. }
  10597. // Build up a reverse change object to add to the opposite history
  10598. // stack (redo when undoing, and vice versa).
  10599. var antiChanges = [];
  10600. pushSelectionToHistory(selAfter, dest);
  10601. dest.push({changes: antiChanges, generation: hist.generation});
  10602. hist.generation = event.generation || ++hist.maxGeneration;
  10603. var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
  10604. var loop = function ( i ) {
  10605. var change = event.changes[i];
  10606. change.origin = type;
  10607. if (filter && !filterChange(doc, change, false)) {
  10608. source.length = 0;
  10609. return {}
  10610. }
  10611. antiChanges.push(historyChangeFromChange(doc, change));
  10612. var after = i ? computeSelAfterChange(doc, change) : lst(source);
  10613. makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
  10614. if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); }
  10615. var rebased = [];
  10616. // Propagate to the linked documents
  10617. linkedDocs(doc, function (doc, sharedHist) {
  10618. if (!sharedHist && indexOf(rebased, doc.history) == -1) {
  10619. rebaseHist(doc.history, change);
  10620. rebased.push(doc.history);
  10621. }
  10622. makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
  10623. });
  10624. };
  10625. for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
  10626. var returned = loop( i$1 );
  10627. if ( returned ) return returned.v;
  10628. }
  10629. }
  10630. // Sub-views need their line numbers shifted when text is added
  10631. // above or below them in the parent document.
  10632. function shiftDoc(doc, distance) {
  10633. if (distance == 0) { return }
  10634. doc.first += distance;
  10635. doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
  10636. Pos(range.anchor.line + distance, range.anchor.ch),
  10637. Pos(range.head.line + distance, range.head.ch)
  10638. ); }), doc.sel.primIndex);
  10639. if (doc.cm) {
  10640. regChange(doc.cm, doc.first, doc.first - distance, distance);
  10641. for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
  10642. { regLineChange(doc.cm, l, "gutter"); }
  10643. }
  10644. }
  10645. // More lower-level change function, handling only a single document
  10646. // (not linked ones).
  10647. function makeChangeSingleDoc(doc, change, selAfter, spans) {
  10648. if (doc.cm && !doc.cm.curOp)
  10649. { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
  10650. if (change.to.line < doc.first) {
  10651. shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
  10652. return
  10653. }
  10654. if (change.from.line > doc.lastLine()) { return }
  10655. // Clip the change to the size of this doc
  10656. if (change.from.line < doc.first) {
  10657. var shift = change.text.length - 1 - (doc.first - change.from.line);
  10658. shiftDoc(doc, shift);
  10659. change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
  10660. text: [lst(change.text)], origin: change.origin};
  10661. }
  10662. var last = doc.lastLine();
  10663. if (change.to.line > last) {
  10664. change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
  10665. text: [change.text[0]], origin: change.origin};
  10666. }
  10667. change.removed = getBetween(doc, change.from, change.to);
  10668. if (!selAfter) { selAfter = computeSelAfterChange(doc, change); }
  10669. if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); }
  10670. else { updateDoc(doc, change, spans); }
  10671. setSelectionNoUndo(doc, selAfter, sel_dontScroll);
  10672. if (doc.cantEdit && skipAtomic(doc, Pos(doc.firstLine(), 0)))
  10673. { doc.cantEdit = false; }
  10674. }
  10675. // Handle the interaction of a change to a document with the editor
  10676. // that this document is part of.
  10677. function makeChangeSingleDocInEditor(cm, change, spans) {
  10678. var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
  10679. var recomputeMaxLength = false, checkWidthStart = from.line;
  10680. if (!cm.options.lineWrapping) {
  10681. checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
  10682. doc.iter(checkWidthStart, to.line + 1, function (line) {
  10683. if (line == display.maxLine) {
  10684. recomputeMaxLength = true;
  10685. return true
  10686. }
  10687. });
  10688. }
  10689. if (doc.sel.contains(change.from, change.to) > -1)
  10690. { signalCursorActivity(cm); }
  10691. updateDoc(doc, change, spans, estimateHeight(cm));
  10692. if (!cm.options.lineWrapping) {
  10693. doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
  10694. var len = lineLength(line);
  10695. if (len > display.maxLineLength) {
  10696. display.maxLine = line;
  10697. display.maxLineLength = len;
  10698. display.maxLineChanged = true;
  10699. recomputeMaxLength = false;
  10700. }
  10701. });
  10702. if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; }
  10703. }
  10704. retreatFrontier(doc, from.line);
  10705. startWorker(cm, 400);
  10706. var lendiff = change.text.length - (to.line - from.line) - 1;
  10707. // Remember that these lines changed, for updating the display
  10708. if (change.full)
  10709. { regChange(cm); }
  10710. else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
  10711. { regLineChange(cm, from.line, "text"); }
  10712. else
  10713. { regChange(cm, from.line, to.line + 1, lendiff); }
  10714. var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
  10715. if (changeHandler || changesHandler) {
  10716. var obj = {
  10717. from: from, to: to,
  10718. text: change.text,
  10719. removed: change.removed,
  10720. origin: change.origin
  10721. };
  10722. if (changeHandler) { signalLater(cm, "change", cm, obj); }
  10723. if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); }
  10724. }
  10725. cm.display.selForContextMenu = null;
  10726. }
  10727. function replaceRange(doc, code, from, to, origin) {
  10728. var assign;
  10729. if (!to) { to = from; }
  10730. if (cmp(to, from) < 0) { (assign = [to, from], from = assign[0], to = assign[1]); }
  10731. if (typeof code == "string") { code = doc.splitLines(code); }
  10732. makeChange(doc, {from: from, to: to, text: code, origin: origin});
  10733. }
  10734. // Rebasing/resetting history to deal with externally-sourced changes
  10735. function rebaseHistSelSingle(pos, from, to, diff) {
  10736. if (to < pos.line) {
  10737. pos.line += diff;
  10738. } else if (from < pos.line) {
  10739. pos.line = from;
  10740. pos.ch = 0;
  10741. }
  10742. }
  10743. // Tries to rebase an array of history events given a change in the
  10744. // document. If the change touches the same lines as the event, the
  10745. // event, and everything 'behind' it, is discarded. If the change is
  10746. // before the event, the event's positions are updated. Uses a
  10747. // copy-on-write scheme for the positions, to avoid having to
  10748. // reallocate them all on every rebase, but also avoid problems with
  10749. // shared position objects being unsafely updated.
  10750. function rebaseHistArray(array, from, to, diff) {
  10751. for (var i = 0; i < array.length; ++i) {
  10752. var sub = array[i], ok = true;
  10753. if (sub.ranges) {
  10754. if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
  10755. for (var j = 0; j < sub.ranges.length; j++) {
  10756. rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
  10757. rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
  10758. }
  10759. continue
  10760. }
  10761. for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
  10762. var cur = sub.changes[j$1];
  10763. if (to < cur.from.line) {
  10764. cur.from = Pos(cur.from.line + diff, cur.from.ch);
  10765. cur.to = Pos(cur.to.line + diff, cur.to.ch);
  10766. } else if (from <= cur.to.line) {
  10767. ok = false;
  10768. break
  10769. }
  10770. }
  10771. if (!ok) {
  10772. array.splice(0, i + 1);
  10773. i = 0;
  10774. }
  10775. }
  10776. }
  10777. function rebaseHist(hist, change) {
  10778. var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
  10779. rebaseHistArray(hist.done, from, to, diff);
  10780. rebaseHistArray(hist.undone, from, to, diff);
  10781. }
  10782. // Utility for applying a change to a line by handle or number,
  10783. // returning the number and optionally registering the line as
  10784. // changed.
  10785. function changeLine(doc, handle, changeType, op) {
  10786. var no = handle, line = handle;
  10787. if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); }
  10788. else { no = lineNo(handle); }
  10789. if (no == null) { return null }
  10790. if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); }
  10791. return line
  10792. }
  10793. // The document is represented as a BTree consisting of leaves, with
  10794. // chunk of lines in them, and branches, with up to ten leaves or
  10795. // other branch nodes below them. The top node is always a branch
  10796. // node, and is the document object itself (meaning it has
  10797. // additional methods and properties).
  10798. //
  10799. // All nodes have parent links. The tree is used both to go from
  10800. // line numbers to line objects, and to go from objects to numbers.
  10801. // It also indexes by height, and is used to convert between height
  10802. // and line object, and to find the total height of the document.
  10803. //
  10804. // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
  10805. function LeafChunk(lines) {
  10806. this.lines = lines;
  10807. this.parent = null;
  10808. var height = 0;
  10809. for (var i = 0; i < lines.length; ++i) {
  10810. lines[i].parent = this;
  10811. height += lines[i].height;
  10812. }
  10813. this.height = height;
  10814. }
  10815. LeafChunk.prototype = {
  10816. chunkSize: function() { return this.lines.length },
  10817. // Remove the n lines at offset 'at'.
  10818. removeInner: function(at, n) {
  10819. for (var i = at, e = at + n; i < e; ++i) {
  10820. var line = this.lines[i];
  10821. this.height -= line.height;
  10822. cleanUpLine(line);
  10823. signalLater(line, "delete");
  10824. }
  10825. this.lines.splice(at, n);
  10826. },
  10827. // Helper used to collapse a small branch into a single leaf.
  10828. collapse: function(lines) {
  10829. lines.push.apply(lines, this.lines);
  10830. },
  10831. // Insert the given array of lines at offset 'at', count them as
  10832. // having the given height.
  10833. insertInner: function(at, lines, height) {
  10834. this.height += height;
  10835. this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
  10836. for (var i = 0; i < lines.length; ++i) { lines[i].parent = this; }
  10837. },
  10838. // Used to iterate over a part of the tree.
  10839. iterN: function(at, n, op) {
  10840. for (var e = at + n; at < e; ++at)
  10841. { if (op(this.lines[at])) { return true } }
  10842. }
  10843. };
  10844. function BranchChunk(children) {
  10845. this.children = children;
  10846. var size = 0, height = 0;
  10847. for (var i = 0; i < children.length; ++i) {
  10848. var ch = children[i];
  10849. size += ch.chunkSize(); height += ch.height;
  10850. ch.parent = this;
  10851. }
  10852. this.size = size;
  10853. this.height = height;
  10854. this.parent = null;
  10855. }
  10856. BranchChunk.prototype = {
  10857. chunkSize: function() { return this.size },
  10858. removeInner: function(at, n) {
  10859. this.size -= n;
  10860. for (var i = 0; i < this.children.length; ++i) {
  10861. var child = this.children[i], sz = child.chunkSize();
  10862. if (at < sz) {
  10863. var rm = Math.min(n, sz - at), oldHeight = child.height;
  10864. child.removeInner(at, rm);
  10865. this.height -= oldHeight - child.height;
  10866. if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
  10867. if ((n -= rm) == 0) { break }
  10868. at = 0;
  10869. } else { at -= sz; }
  10870. }
  10871. // If the result is smaller than 25 lines, ensure that it is a
  10872. // single leaf node.
  10873. if (this.size - n < 25 &&
  10874. (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
  10875. var lines = [];
  10876. this.collapse(lines);
  10877. this.children = [new LeafChunk(lines)];
  10878. this.children[0].parent = this;
  10879. }
  10880. },
  10881. collapse: function(lines) {
  10882. for (var i = 0; i < this.children.length; ++i) { this.children[i].collapse(lines); }
  10883. },
  10884. insertInner: function(at, lines, height) {
  10885. this.size += lines.length;
  10886. this.height += height;
  10887. for (var i = 0; i < this.children.length; ++i) {
  10888. var child = this.children[i], sz = child.chunkSize();
  10889. if (at <= sz) {
  10890. child.insertInner(at, lines, height);
  10891. if (child.lines && child.lines.length > 50) {
  10892. // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
  10893. // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
  10894. var remaining = child.lines.length % 25 + 25;
  10895. for (var pos = remaining; pos < child.lines.length;) {
  10896. var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
  10897. child.height -= leaf.height;
  10898. this.children.splice(++i, 0, leaf);
  10899. leaf.parent = this;
  10900. }
  10901. child.lines = child.lines.slice(0, remaining);
  10902. this.maybeSpill();
  10903. }
  10904. break
  10905. }
  10906. at -= sz;
  10907. }
  10908. },
  10909. // When a node has grown, check whether it should be split.
  10910. maybeSpill: function() {
  10911. if (this.children.length <= 10) { return }
  10912. var me = this;
  10913. do {
  10914. var spilled = me.children.splice(me.children.length - 5, 5);
  10915. var sibling = new BranchChunk(spilled);
  10916. if (!me.parent) { // Become the parent node
  10917. var copy = new BranchChunk(me.children);
  10918. copy.parent = me;
  10919. me.children = [copy, sibling];
  10920. me = copy;
  10921. } else {
  10922. me.size -= sibling.size;
  10923. me.height -= sibling.height;
  10924. var myIndex = indexOf(me.parent.children, me);
  10925. me.parent.children.splice(myIndex + 1, 0, sibling);
  10926. }
  10927. sibling.parent = me.parent;
  10928. } while (me.children.length > 10)
  10929. me.parent.maybeSpill();
  10930. },
  10931. iterN: function(at, n, op) {
  10932. for (var i = 0; i < this.children.length; ++i) {
  10933. var child = this.children[i], sz = child.chunkSize();
  10934. if (at < sz) {
  10935. var used = Math.min(n, sz - at);
  10936. if (child.iterN(at, used, op)) { return true }
  10937. if ((n -= used) == 0) { break }
  10938. at = 0;
  10939. } else { at -= sz; }
  10940. }
  10941. }
  10942. };
  10943. // Line widgets are block elements displayed above or below a line.
  10944. var LineWidget = function(doc, node, options) {
  10945. if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
  10946. { this[opt] = options[opt]; } } }
  10947. this.doc = doc;
  10948. this.node = node;
  10949. };
  10950. LineWidget.prototype.clear = function () {
  10951. var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
  10952. if (no == null || !ws) { return }
  10953. for (var i = 0; i < ws.length; ++i) { if (ws[i] == this) { ws.splice(i--, 1); } }
  10954. if (!ws.length) { line.widgets = null; }
  10955. var height = widgetHeight(this);
  10956. updateLineHeight(line, Math.max(0, line.height - height));
  10957. if (cm) {
  10958. runInOp(cm, function () {
  10959. adjustScrollWhenAboveVisible(cm, line, -height);
  10960. regLineChange(cm, no, "widget");
  10961. });
  10962. signalLater(cm, "lineWidgetCleared", cm, this, no);
  10963. }
  10964. };
  10965. LineWidget.prototype.changed = function () {
  10966. var this$1 = this;
  10967. var oldH = this.height, cm = this.doc.cm, line = this.line;
  10968. this.height = null;
  10969. var diff = widgetHeight(this) - oldH;
  10970. if (!diff) { return }
  10971. if (!lineIsHidden(this.doc, line)) { updateLineHeight(line, line.height + diff); }
  10972. if (cm) {
  10973. runInOp(cm, function () {
  10974. cm.curOp.forceUpdate = true;
  10975. adjustScrollWhenAboveVisible(cm, line, diff);
  10976. signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
  10977. });
  10978. }
  10979. };
  10980. eventMixin(LineWidget);
  10981. function adjustScrollWhenAboveVisible(cm, line, diff) {
  10982. if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
  10983. { addToScrollTop(cm, diff); }
  10984. }
  10985. function addLineWidget(doc, handle, node, options) {
  10986. var widget = new LineWidget(doc, node, options);
  10987. var cm = doc.cm;
  10988. if (cm && widget.noHScroll) { cm.display.alignWidgets = true; }
  10989. changeLine(doc, handle, "widget", function (line) {
  10990. var widgets = line.widgets || (line.widgets = []);
  10991. if (widget.insertAt == null) { widgets.push(widget); }
  10992. else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); }
  10993. widget.line = line;
  10994. if (cm && !lineIsHidden(doc, line)) {
  10995. var aboveVisible = heightAtLine(line) < doc.scrollTop;
  10996. updateLineHeight(line, line.height + widgetHeight(widget));
  10997. if (aboveVisible) { addToScrollTop(cm, widget.height); }
  10998. cm.curOp.forceUpdate = true;
  10999. }
  11000. return true
  11001. });
  11002. if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)); }
  11003. return widget
  11004. }
  11005. // TEXTMARKERS
  11006. // Created with markText and setBookmark methods. A TextMarker is a
  11007. // handle that can be used to clear or find a marked position in the
  11008. // document. Line objects hold arrays (markedSpans) containing
  11009. // {from, to, marker} object pointing to such marker objects, and
  11010. // indicating that such a marker is present on that line. Multiple
  11011. // lines may point to the same marker when it spans across lines.
  11012. // The spans will have null for their from/to properties when the
  11013. // marker continues beyond the start/end of the line. Markers have
  11014. // links back to the lines they currently touch.
  11015. // Collapsed markers have unique ids, in order to be able to order
  11016. // them, which is needed for uniquely determining an outer marker
  11017. // when they overlap (they may nest, but not partially overlap).
  11018. var nextMarkerId = 0;
  11019. var TextMarker = function(doc, type) {
  11020. this.lines = [];
  11021. this.type = type;
  11022. this.doc = doc;
  11023. this.id = ++nextMarkerId;
  11024. };
  11025. // Clear the marker.
  11026. TextMarker.prototype.clear = function () {
  11027. if (this.explicitlyCleared) { return }
  11028. var cm = this.doc.cm, withOp = cm && !cm.curOp;
  11029. if (withOp) { startOperation(cm); }
  11030. if (hasHandler(this, "clear")) {
  11031. var found = this.find();
  11032. if (found) { signalLater(this, "clear", found.from, found.to); }
  11033. }
  11034. var min = null, max = null;
  11035. for (var i = 0; i < this.lines.length; ++i) {
  11036. var line = this.lines[i];
  11037. var span = getMarkedSpanFor(line.markedSpans, this);
  11038. if (cm && !this.collapsed) { regLineChange(cm, lineNo(line), "text"); }
  11039. else if (cm) {
  11040. if (span.to != null) { max = lineNo(line); }
  11041. if (span.from != null) { min = lineNo(line); }
  11042. }
  11043. line.markedSpans = removeMarkedSpan(line.markedSpans, span);
  11044. if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
  11045. { updateLineHeight(line, textHeight(cm.display)); }
  11046. }
  11047. if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
  11048. var visual = visualLine(this.lines[i$1]), len = lineLength(visual);
  11049. if (len > cm.display.maxLineLength) {
  11050. cm.display.maxLine = visual;
  11051. cm.display.maxLineLength = len;
  11052. cm.display.maxLineChanged = true;
  11053. }
  11054. } }
  11055. if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); }
  11056. this.lines.length = 0;
  11057. this.explicitlyCleared = true;
  11058. if (this.atomic && this.doc.cantEdit) {
  11059. this.doc.cantEdit = false;
  11060. if (cm) { reCheckSelection(cm.doc); }
  11061. }
  11062. if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); }
  11063. if (withOp) { endOperation(cm); }
  11064. if (this.parent) { this.parent.clear(); }
  11065. };
  11066. // Find the position of the marker in the document. Returns a {from,
  11067. // to} object by default. Side can be passed to get a specific side
  11068. // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
  11069. // Pos objects returned contain a line object, rather than a line
  11070. // number (used to prevent looking up the same line twice).
  11071. TextMarker.prototype.find = function (side, lineObj) {
  11072. if (side == null && this.type == "bookmark") { side = 1; }
  11073. var from, to;
  11074. for (var i = 0; i < this.lines.length; ++i) {
  11075. var line = this.lines[i];
  11076. var span = getMarkedSpanFor(line.markedSpans, this);
  11077. if (span.from != null) {
  11078. from = Pos(lineObj ? line : lineNo(line), span.from);
  11079. if (side == -1) { return from }
  11080. }
  11081. if (span.to != null) {
  11082. to = Pos(lineObj ? line : lineNo(line), span.to);
  11083. if (side == 1) { return to }
  11084. }
  11085. }
  11086. return from && {from: from, to: to}
  11087. };
  11088. // Signals that the marker's widget changed, and surrounding layout
  11089. // should be recomputed.
  11090. TextMarker.prototype.changed = function () {
  11091. var this$1 = this;
  11092. var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
  11093. if (!pos || !cm) { return }
  11094. runInOp(cm, function () {
  11095. var line = pos.line, lineN = lineNo(pos.line);
  11096. var view = findViewForLine(cm, lineN);
  11097. if (view) {
  11098. clearLineMeasurementCacheFor(view);
  11099. cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
  11100. }
  11101. cm.curOp.updateMaxLine = true;
  11102. if (!lineIsHidden(widget.doc, line) && widget.height != null) {
  11103. var oldHeight = widget.height;
  11104. widget.height = null;
  11105. var dHeight = widgetHeight(widget) - oldHeight;
  11106. if (dHeight)
  11107. { updateLineHeight(line, line.height + dHeight); }
  11108. }
  11109. signalLater(cm, "markerChanged", cm, this$1);
  11110. });
  11111. };
  11112. TextMarker.prototype.attachLine = function (line) {
  11113. if (!this.lines.length && this.doc.cm) {
  11114. var op = this.doc.cm.curOp;
  11115. if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
  11116. { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); }
  11117. }
  11118. this.lines.push(line);
  11119. };
  11120. TextMarker.prototype.detachLine = function (line) {
  11121. this.lines.splice(indexOf(this.lines, line), 1);
  11122. if (!this.lines.length && this.doc.cm) {
  11123. var op = this.doc.cm.curOp
  11124. ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
  11125. }
  11126. };
  11127. eventMixin(TextMarker);
  11128. // Create a marker, wire it up to the right lines, and
  11129. function markText(doc, from, to, options, type) {
  11130. // Shared markers (across linked documents) are handled separately
  11131. // (markTextShared will call out to this again, once per
  11132. // document).
  11133. if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
  11134. // Ensure we are in an operation.
  11135. if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
  11136. var marker = new TextMarker(doc, type), diff = cmp(from, to);
  11137. if (options) { copyObj(options, marker, false); }
  11138. // Don't connect empty markers unless clearWhenEmpty is false
  11139. if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
  11140. { return marker }
  11141. if (marker.replacedWith) {
  11142. // Showing up as a widget implies collapsed (widget replaces text)
  11143. marker.collapsed = true;
  11144. marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
  11145. if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
  11146. if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
  11147. }
  11148. if (marker.collapsed) {
  11149. if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
  11150. from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
  11151. { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
  11152. seeCollapsedSpans();
  11153. }
  11154. if (marker.addToHistory)
  11155. { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
  11156. var curLine = from.line, cm = doc.cm, updateMaxLine;
  11157. doc.iter(curLine, to.line + 1, function (line) {
  11158. if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
  11159. { updateMaxLine = true; }
  11160. if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
  11161. addMarkedSpan(line, new MarkedSpan(marker,
  11162. curLine == from.line ? from.ch : null,
  11163. curLine == to.line ? to.ch : null));
  11164. ++curLine;
  11165. });
  11166. // lineIsHidden depends on the presence of the spans, so needs a second pass
  11167. if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
  11168. if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
  11169. }); }
  11170. if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
  11171. if (marker.readOnly) {
  11172. seeReadOnlySpans();
  11173. if (doc.history.done.length || doc.history.undone.length)
  11174. { doc.clearHistory(); }
  11175. }
  11176. if (marker.collapsed) {
  11177. marker.id = ++nextMarkerId;
  11178. marker.atomic = true;
  11179. }
  11180. if (cm) {
  11181. // Sync editor state
  11182. if (updateMaxLine) { cm.curOp.updateMaxLine = true; }
  11183. if (marker.collapsed)
  11184. { regChange(cm, from.line, to.line + 1); }
  11185. else if (marker.className || marker.startStyle || marker.endStyle || marker.css ||
  11186. marker.attributes || marker.title)
  11187. { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } }
  11188. if (marker.atomic) { reCheckSelection(cm.doc); }
  11189. signalLater(cm, "markerAdded", cm, marker);
  11190. }
  11191. return marker
  11192. }
  11193. // SHARED TEXTMARKERS
  11194. // A shared marker spans multiple linked documents. It is
  11195. // implemented as a meta-marker-object controlling multiple normal
  11196. // markers.
  11197. var SharedTextMarker = function(markers, primary) {
  11198. this.markers = markers;
  11199. this.primary = primary;
  11200. for (var i = 0; i < markers.length; ++i)
  11201. { markers[i].parent = this; }
  11202. };
  11203. SharedTextMarker.prototype.clear = function () {
  11204. if (this.explicitlyCleared) { return }
  11205. this.explicitlyCleared = true;
  11206. for (var i = 0; i < this.markers.length; ++i)
  11207. { this.markers[i].clear(); }
  11208. signalLater(this, "clear");
  11209. };
  11210. SharedTextMarker.prototype.find = function (side, lineObj) {
  11211. return this.primary.find(side, lineObj)
  11212. };
  11213. eventMixin(SharedTextMarker);
  11214. function markTextShared(doc, from, to, options, type) {
  11215. options = copyObj(options);
  11216. options.shared = false;
  11217. var markers = [markText(doc, from, to, options, type)], primary = markers[0];
  11218. var widget = options.widgetNode;
  11219. linkedDocs(doc, function (doc) {
  11220. if (widget) { options.widgetNode = widget.cloneNode(true); }
  11221. markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
  11222. for (var i = 0; i < doc.linked.length; ++i)
  11223. { if (doc.linked[i].isParent) { return } }
  11224. primary = lst(markers);
  11225. });
  11226. return new SharedTextMarker(markers, primary)
  11227. }
  11228. function findSharedMarkers(doc) {
  11229. return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
  11230. }
  11231. function copySharedMarkers(doc, markers) {
  11232. for (var i = 0; i < markers.length; i++) {
  11233. var marker = markers[i], pos = marker.find();
  11234. var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
  11235. if (cmp(mFrom, mTo)) {
  11236. var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
  11237. marker.markers.push(subMark);
  11238. subMark.parent = marker;
  11239. }
  11240. }
  11241. }
  11242. function detachSharedMarkers(markers) {
  11243. var loop = function ( i ) {
  11244. var marker = markers[i], linked = [marker.primary.doc];
  11245. linkedDocs(marker.primary.doc, function (d) { return linked.push(d); });
  11246. for (var j = 0; j < marker.markers.length; j++) {
  11247. var subMarker = marker.markers[j];
  11248. if (indexOf(linked, subMarker.doc) == -1) {
  11249. subMarker.parent = null;
  11250. marker.markers.splice(j--, 1);
  11251. }
  11252. }
  11253. };
  11254. for (var i = 0; i < markers.length; i++) loop( i );
  11255. }
  11256. var nextDocId = 0;
  11257. var Doc = function(text, mode, firstLine, lineSep, direction) {
  11258. if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
  11259. if (firstLine == null) { firstLine = 0; }
  11260. BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
  11261. this.first = firstLine;
  11262. this.scrollTop = this.scrollLeft = 0;
  11263. this.cantEdit = false;
  11264. this.cleanGeneration = 1;
  11265. this.modeFrontier = this.highlightFrontier = firstLine;
  11266. var start = Pos(firstLine, 0);
  11267. this.sel = simpleSelection(start);
  11268. this.history = new History(null);
  11269. this.id = ++nextDocId;
  11270. this.modeOption = mode;
  11271. this.lineSep = lineSep;
  11272. this.direction = (direction == "rtl") ? "rtl" : "ltr";
  11273. this.extend = false;
  11274. if (typeof text == "string") { text = this.splitLines(text); }
  11275. updateDoc(this, {from: start, to: start, text: text});
  11276. setSelection(this, simpleSelection(start), sel_dontScroll);
  11277. };
  11278. Doc.prototype = createObj(BranchChunk.prototype, {
  11279. constructor: Doc,
  11280. // Iterate over the document. Supports two forms -- with only one
  11281. // argument, it calls that for each line in the document. With
  11282. // three, it iterates over the range given by the first two (with
  11283. // the second being non-inclusive).
  11284. iter: function(from, to, op) {
  11285. if (op) { this.iterN(from - this.first, to - from, op); }
  11286. else { this.iterN(this.first, this.first + this.size, from); }
  11287. },
  11288. // Non-public interface for adding and removing lines.
  11289. insert: function(at, lines) {
  11290. var height = 0;
  11291. for (var i = 0; i < lines.length; ++i) { height += lines[i].height; }
  11292. this.insertInner(at - this.first, lines, height);
  11293. },
  11294. remove: function(at, n) { this.removeInner(at - this.first, n); },
  11295. // From here, the methods are part of the public interface. Most
  11296. // are also available from CodeMirror (editor) instances.
  11297. getValue: function(lineSep) {
  11298. var lines = getLines(this, this.first, this.first + this.size);
  11299. if (lineSep === false) { return lines }
  11300. return lines.join(lineSep || this.lineSeparator())
  11301. },
  11302. setValue: docMethodOp(function(code) {
  11303. var top = Pos(this.first, 0), last = this.first + this.size - 1;
  11304. makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
  11305. text: this.splitLines(code), origin: "setValue", full: true}, true);
  11306. if (this.cm) { scrollToCoords(this.cm, 0, 0); }
  11307. setSelection(this, simpleSelection(top), sel_dontScroll);
  11308. }),
  11309. replaceRange: function(code, from, to, origin) {
  11310. from = clipPos(this, from);
  11311. to = to ? clipPos(this, to) : from;
  11312. replaceRange(this, code, from, to, origin);
  11313. },
  11314. getRange: function(from, to, lineSep) {
  11315. var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
  11316. if (lineSep === false) { return lines }
  11317. return lines.join(lineSep || this.lineSeparator())
  11318. },
  11319. getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
  11320. getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
  11321. getLineNumber: function(line) {return lineNo(line)},
  11322. getLineHandleVisualStart: function(line) {
  11323. if (typeof line == "number") { line = getLine(this, line); }
  11324. return visualLine(line)
  11325. },
  11326. lineCount: function() {return this.size},
  11327. firstLine: function() {return this.first},
  11328. lastLine: function() {return this.first + this.size - 1},
  11329. clipPos: function(pos) {return clipPos(this, pos)},
  11330. getCursor: function(start) {
  11331. var range = this.sel.primary(), pos;
  11332. if (start == null || start == "head") { pos = range.head; }
  11333. else if (start == "anchor") { pos = range.anchor; }
  11334. else if (start == "end" || start == "to" || start === false) { pos = range.to(); }
  11335. else { pos = range.from(); }
  11336. return pos
  11337. },
  11338. listSelections: function() { return this.sel.ranges },
  11339. somethingSelected: function() {return this.sel.somethingSelected()},
  11340. setCursor: docMethodOp(function(line, ch, options) {
  11341. setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
  11342. }),
  11343. setSelection: docMethodOp(function(anchor, head, options) {
  11344. setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
  11345. }),
  11346. extendSelection: docMethodOp(function(head, other, options) {
  11347. extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
  11348. }),
  11349. extendSelections: docMethodOp(function(heads, options) {
  11350. extendSelections(this, clipPosArray(this, heads), options);
  11351. }),
  11352. extendSelectionsBy: docMethodOp(function(f, options) {
  11353. var heads = map(this.sel.ranges, f);
  11354. extendSelections(this, clipPosArray(this, heads), options);
  11355. }),
  11356. setSelections: docMethodOp(function(ranges, primary, options) {
  11357. if (!ranges.length) { return }
  11358. var out = [];
  11359. for (var i = 0; i < ranges.length; i++)
  11360. { out[i] = new Range(clipPos(this, ranges[i].anchor),
  11361. clipPos(this, ranges[i].head)); }
  11362. if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); }
  11363. setSelection(this, normalizeSelection(this.cm, out, primary), options);
  11364. }),
  11365. addSelection: docMethodOp(function(anchor, head, options) {
  11366. var ranges = this.sel.ranges.slice(0);
  11367. ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
  11368. setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);
  11369. }),
  11370. getSelection: function(lineSep) {
  11371. var ranges = this.sel.ranges, lines;
  11372. for (var i = 0; i < ranges.length; i++) {
  11373. var sel = getBetween(this, ranges[i].from(), ranges[i].to());
  11374. lines = lines ? lines.concat(sel) : sel;
  11375. }
  11376. if (lineSep === false) { return lines }
  11377. else { return lines.join(lineSep || this.lineSeparator()) }
  11378. },
  11379. getSelections: function(lineSep) {
  11380. var parts = [], ranges = this.sel.ranges;
  11381. for (var i = 0; i < ranges.length; i++) {
  11382. var sel = getBetween(this, ranges[i].from(), ranges[i].to());
  11383. if (lineSep !== false) { sel = sel.join(lineSep || this.lineSeparator()); }
  11384. parts[i] = sel;
  11385. }
  11386. return parts
  11387. },
  11388. replaceSelection: function(code, collapse, origin) {
  11389. var dup = [];
  11390. for (var i = 0; i < this.sel.ranges.length; i++)
  11391. { dup[i] = code; }
  11392. this.replaceSelections(dup, collapse, origin || "+input");
  11393. },
  11394. replaceSelections: docMethodOp(function(code, collapse, origin) {
  11395. var changes = [], sel = this.sel;
  11396. for (var i = 0; i < sel.ranges.length; i++) {
  11397. var range = sel.ranges[i];
  11398. changes[i] = {from: range.from(), to: range.to(), text: this.splitLines(code[i]), origin: origin};
  11399. }
  11400. var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
  11401. for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
  11402. { makeChange(this, changes[i$1]); }
  11403. if (newSel) { setSelectionReplaceHistory(this, newSel); }
  11404. else if (this.cm) { ensureCursorVisible(this.cm); }
  11405. }),
  11406. undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
  11407. redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
  11408. undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
  11409. redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
  11410. setExtending: function(val) {this.extend = val;},
  11411. getExtending: function() {return this.extend},
  11412. historySize: function() {
  11413. var hist = this.history, done = 0, undone = 0;
  11414. for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } }
  11415. for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } }
  11416. return {undo: done, redo: undone}
  11417. },
  11418. clearHistory: function() {
  11419. var this$1 = this;
  11420. this.history = new History(this.history.maxGeneration);
  11421. linkedDocs(this, function (doc) { return doc.history = this$1.history; }, true);
  11422. },
  11423. markClean: function() {
  11424. this.cleanGeneration = this.changeGeneration(true);
  11425. },
  11426. changeGeneration: function(forceSplit) {
  11427. if (forceSplit)
  11428. { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; }
  11429. return this.history.generation
  11430. },
  11431. isClean: function (gen) {
  11432. return this.history.generation == (gen || this.cleanGeneration)
  11433. },
  11434. getHistory: function() {
  11435. return {done: copyHistoryArray(this.history.done),
  11436. undone: copyHistoryArray(this.history.undone)}
  11437. },
  11438. setHistory: function(histData) {
  11439. var hist = this.history = new History(this.history.maxGeneration);
  11440. hist.done = copyHistoryArray(histData.done.slice(0), null, true);
  11441. hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
  11442. },
  11443. setGutterMarker: docMethodOp(function(line, gutterID, value) {
  11444. return changeLine(this, line, "gutter", function (line) {
  11445. var markers = line.gutterMarkers || (line.gutterMarkers = {});
  11446. markers[gutterID] = value;
  11447. if (!value && isEmpty(markers)) { line.gutterMarkers = null; }
  11448. return true
  11449. })
  11450. }),
  11451. clearGutter: docMethodOp(function(gutterID) {
  11452. var this$1 = this;
  11453. this.iter(function (line) {
  11454. if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
  11455. changeLine(this$1, line, "gutter", function () {
  11456. line.gutterMarkers[gutterID] = null;
  11457. if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; }
  11458. return true
  11459. });
  11460. }
  11461. });
  11462. }),
  11463. lineInfo: function(line) {
  11464. var n;
  11465. if (typeof line == "number") {
  11466. if (!isLine(this, line)) { return null }
  11467. n = line;
  11468. line = getLine(this, line);
  11469. if (!line) { return null }
  11470. } else {
  11471. n = lineNo(line);
  11472. if (n == null) { return null }
  11473. }
  11474. return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
  11475. textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
  11476. widgets: line.widgets}
  11477. },
  11478. addLineClass: docMethodOp(function(handle, where, cls) {
  11479. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
  11480. var prop = where == "text" ? "textClass"
  11481. : where == "background" ? "bgClass"
  11482. : where == "gutter" ? "gutterClass" : "wrapClass";
  11483. if (!line[prop]) { line[prop] = cls; }
  11484. else if (classTest(cls).test(line[prop])) { return false }
  11485. else { line[prop] += " " + cls; }
  11486. return true
  11487. })
  11488. }),
  11489. removeLineClass: docMethodOp(function(handle, where, cls) {
  11490. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
  11491. var prop = where == "text" ? "textClass"
  11492. : where == "background" ? "bgClass"
  11493. : where == "gutter" ? "gutterClass" : "wrapClass";
  11494. var cur = line[prop];
  11495. if (!cur) { return false }
  11496. else if (cls == null) { line[prop] = null; }
  11497. else {
  11498. var found = cur.match(classTest(cls));
  11499. if (!found) { return false }
  11500. var end = found.index + found[0].length;
  11501. line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
  11502. }
  11503. return true
  11504. })
  11505. }),
  11506. addLineWidget: docMethodOp(function(handle, node, options) {
  11507. return addLineWidget(this, handle, node, options)
  11508. }),
  11509. removeLineWidget: function(widget) { widget.clear(); },
  11510. markText: function(from, to, options) {
  11511. return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
  11512. },
  11513. setBookmark: function(pos, options) {
  11514. var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
  11515. insertLeft: options && options.insertLeft,
  11516. clearWhenEmpty: false, shared: options && options.shared,
  11517. handleMouseEvents: options && options.handleMouseEvents};
  11518. pos = clipPos(this, pos);
  11519. return markText(this, pos, pos, realOpts, "bookmark")
  11520. },
  11521. findMarksAt: function(pos) {
  11522. pos = clipPos(this, pos);
  11523. var markers = [], spans = getLine(this, pos.line).markedSpans;
  11524. if (spans) { for (var i = 0; i < spans.length; ++i) {
  11525. var span = spans[i];
  11526. if ((span.from == null || span.from <= pos.ch) &&
  11527. (span.to == null || span.to >= pos.ch))
  11528. { markers.push(span.marker.parent || span.marker); }
  11529. } }
  11530. return markers
  11531. },
  11532. findMarks: function(from, to, filter) {
  11533. from = clipPos(this, from); to = clipPos(this, to);
  11534. var found = [], lineNo = from.line;
  11535. this.iter(from.line, to.line + 1, function (line) {
  11536. var spans = line.markedSpans;
  11537. if (spans) { for (var i = 0; i < spans.length; i++) {
  11538. var span = spans[i];
  11539. if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
  11540. span.from == null && lineNo != from.line ||
  11541. span.from != null && lineNo == to.line && span.from >= to.ch) &&
  11542. (!filter || filter(span.marker)))
  11543. { found.push(span.marker.parent || span.marker); }
  11544. } }
  11545. ++lineNo;
  11546. });
  11547. return found
  11548. },
  11549. getAllMarks: function() {
  11550. var markers = [];
  11551. this.iter(function (line) {
  11552. var sps = line.markedSpans;
  11553. if (sps) { for (var i = 0; i < sps.length; ++i)
  11554. { if (sps[i].from != null) { markers.push(sps[i].marker); } } }
  11555. });
  11556. return markers
  11557. },
  11558. posFromIndex: function(off) {
  11559. var ch, lineNo = this.first, sepSize = this.lineSeparator().length;
  11560. this.iter(function (line) {
  11561. var sz = line.text.length + sepSize;
  11562. if (sz > off) { ch = off; return true }
  11563. off -= sz;
  11564. ++lineNo;
  11565. });
  11566. return clipPos(this, Pos(lineNo, ch))
  11567. },
  11568. indexFromPos: function (coords) {
  11569. coords = clipPos(this, coords);
  11570. var index = coords.ch;
  11571. if (coords.line < this.first || coords.ch < 0) { return 0 }
  11572. var sepSize = this.lineSeparator().length;
  11573. this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
  11574. index += line.text.length + sepSize;
  11575. });
  11576. return index
  11577. },
  11578. copy: function(copyHistory) {
  11579. var doc = new Doc(getLines(this, this.first, this.first + this.size),
  11580. this.modeOption, this.first, this.lineSep, this.direction);
  11581. doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
  11582. doc.sel = this.sel;
  11583. doc.extend = false;
  11584. if (copyHistory) {
  11585. doc.history.undoDepth = this.history.undoDepth;
  11586. doc.setHistory(this.getHistory());
  11587. }
  11588. return doc
  11589. },
  11590. linkedDoc: function(options) {
  11591. if (!options) { options = {}; }
  11592. var from = this.first, to = this.first + this.size;
  11593. if (options.from != null && options.from > from) { from = options.from; }
  11594. if (options.to != null && options.to < to) { to = options.to; }
  11595. var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
  11596. if (options.sharedHist) { copy.history = this.history
  11597. ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
  11598. copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
  11599. copySharedMarkers(copy, findSharedMarkers(this));
  11600. return copy
  11601. },
  11602. unlinkDoc: function(other) {
  11603. if (other instanceof CodeMirror) { other = other.doc; }
  11604. if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
  11605. var link = this.linked[i];
  11606. if (link.doc != other) { continue }
  11607. this.linked.splice(i, 1);
  11608. other.unlinkDoc(this);
  11609. detachSharedMarkers(findSharedMarkers(this));
  11610. break
  11611. } }
  11612. // If the histories were shared, split them again
  11613. if (other.history == this.history) {
  11614. var splitIds = [other.id];
  11615. linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true);
  11616. other.history = new History(null);
  11617. other.history.done = copyHistoryArray(this.history.done, splitIds);
  11618. other.history.undone = copyHistoryArray(this.history.undone, splitIds);
  11619. }
  11620. },
  11621. iterLinkedDocs: function(f) {linkedDocs(this, f);},
  11622. getMode: function() {return this.mode},
  11623. getEditor: function() {return this.cm},
  11624. splitLines: function(str) {
  11625. if (this.lineSep) { return str.split(this.lineSep) }
  11626. return splitLinesAuto(str)
  11627. },
  11628. lineSeparator: function() { return this.lineSep || "\n" },
  11629. setDirection: docMethodOp(function (dir) {
  11630. if (dir != "rtl") { dir = "ltr"; }
  11631. if (dir == this.direction) { return }
  11632. this.direction = dir;
  11633. this.iter(function (line) { return line.order = null; });
  11634. if (this.cm) { directionChanged(this.cm); }
  11635. })
  11636. });
  11637. // Public alias.
  11638. Doc.prototype.eachLine = Doc.prototype.iter;
  11639. // Kludge to work around strange IE behavior where it'll sometimes
  11640. // re-fire a series of drag-related events right after the drop (#1551)
  11641. var lastDrop = 0;
  11642. function onDrop(e) {
  11643. var cm = this;
  11644. clearDragCursor(cm);
  11645. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
  11646. { return }
  11647. e_preventDefault(e);
  11648. if (ie) { lastDrop = +new Date; }
  11649. var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
  11650. if (!pos || cm.isReadOnly()) { return }
  11651. // Might be a file drop, in which case we simply extract the text
  11652. // and insert it.
  11653. if (files && files.length && window.FileReader && window.File) {
  11654. var n = files.length, text = Array(n), read = 0;
  11655. var markAsReadAndPasteIfAllFilesAreRead = function () {
  11656. if (++read == n) {
  11657. operation(cm, function () {
  11658. pos = clipPos(cm.doc, pos);
  11659. var change = {from: pos, to: pos,
  11660. text: cm.doc.splitLines(
  11661. text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())),
  11662. origin: "paste"};
  11663. makeChange(cm.doc, change);
  11664. setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change))));
  11665. })();
  11666. }
  11667. };
  11668. var readTextFromFile = function (file, i) {
  11669. if (cm.options.allowDropFileTypes &&
  11670. indexOf(cm.options.allowDropFileTypes, file.type) == -1) {
  11671. markAsReadAndPasteIfAllFilesAreRead();
  11672. return
  11673. }
  11674. var reader = new FileReader;
  11675. reader.onerror = function () { return markAsReadAndPasteIfAllFilesAreRead(); };
  11676. reader.onload = function () {
  11677. var content = reader.result;
  11678. if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) {
  11679. markAsReadAndPasteIfAllFilesAreRead();
  11680. return
  11681. }
  11682. text[i] = content;
  11683. markAsReadAndPasteIfAllFilesAreRead();
  11684. };
  11685. reader.readAsText(file);
  11686. };
  11687. for (var i = 0; i < files.length; i++) { readTextFromFile(files[i], i); }
  11688. } else { // Normal drop
  11689. // Don't do a replace if the drop happened inside of the selected text.
  11690. if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
  11691. cm.state.draggingText(e);
  11692. // Ensure the editor is re-focused
  11693. setTimeout(function () { return cm.display.input.focus(); }, 20);
  11694. return
  11695. }
  11696. try {
  11697. var text$1 = e.dataTransfer.getData("Text");
  11698. if (text$1) {
  11699. var selected;
  11700. if (cm.state.draggingText && !cm.state.draggingText.copy)
  11701. { selected = cm.listSelections(); }
  11702. setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
  11703. if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
  11704. { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } }
  11705. cm.replaceSelection(text$1, "around", "paste");
  11706. cm.display.input.focus();
  11707. }
  11708. }
  11709. catch(e){}
  11710. }
  11711. }
  11712. function onDragStart(cm, e) {
  11713. if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
  11714. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
  11715. e.dataTransfer.setData("Text", cm.getSelection());
  11716. e.dataTransfer.effectAllowed = "copyMove";
  11717. // Use dummy image instead of default browsers image.
  11718. // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
  11719. if (e.dataTransfer.setDragImage && !safari) {
  11720. var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
  11721. img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  11722. if (presto) {
  11723. img.width = img.height = 1;
  11724. cm.display.wrapper.appendChild(img);
  11725. // Force a relayout, or Opera won't use our image for some obscure reason
  11726. img._top = img.offsetTop;
  11727. }
  11728. e.dataTransfer.setDragImage(img, 0, 0);
  11729. if (presto) { img.parentNode.removeChild(img); }
  11730. }
  11731. }
  11732. function onDragOver(cm, e) {
  11733. var pos = posFromMouse(cm, e);
  11734. if (!pos) { return }
  11735. var frag = document.createDocumentFragment();
  11736. drawSelectionCursor(cm, pos, frag);
  11737. if (!cm.display.dragCursor) {
  11738. cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
  11739. cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
  11740. }
  11741. removeChildrenAndAdd(cm.display.dragCursor, frag);
  11742. }
  11743. function clearDragCursor(cm) {
  11744. if (cm.display.dragCursor) {
  11745. cm.display.lineSpace.removeChild(cm.display.dragCursor);
  11746. cm.display.dragCursor = null;
  11747. }
  11748. }
  11749. // These must be handled carefully, because naively registering a
  11750. // handler for each editor will cause the editors to never be
  11751. // garbage collected.
  11752. function forEachCodeMirror(f) {
  11753. if (!document.getElementsByClassName) { return }
  11754. var byClass = document.getElementsByClassName("CodeMirror"), editors = [];
  11755. for (var i = 0; i < byClass.length; i++) {
  11756. var cm = byClass[i].CodeMirror;
  11757. if (cm) { editors.push(cm); }
  11758. }
  11759. if (editors.length) { editors[0].operation(function () {
  11760. for (var i = 0; i < editors.length; i++) { f(editors[i]); }
  11761. }); }
  11762. }
  11763. var globalsRegistered = false;
  11764. function ensureGlobalHandlers() {
  11765. if (globalsRegistered) { return }
  11766. registerGlobalHandlers();
  11767. globalsRegistered = true;
  11768. }
  11769. function registerGlobalHandlers() {
  11770. // When the window resizes, we need to refresh active editors.
  11771. var resizeTimer;
  11772. on(window, "resize", function () {
  11773. if (resizeTimer == null) { resizeTimer = setTimeout(function () {
  11774. resizeTimer = null;
  11775. forEachCodeMirror(onResize);
  11776. }, 100); }
  11777. });
  11778. // When the window loses focus, we want to show the editor as blurred
  11779. on(window, "blur", function () { return forEachCodeMirror(onBlur); });
  11780. }
  11781. // Called when the window resizes
  11782. function onResize(cm) {
  11783. var d = cm.display;
  11784. // Might be a text scaling operation, clear size caches.
  11785. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  11786. d.scrollbarsClipped = false;
  11787. cm.setSize();
  11788. }
  11789. var keyNames = {
  11790. 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
  11791. 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
  11792. 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
  11793. 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
  11794. 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 145: "ScrollLock",
  11795. 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
  11796. 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
  11797. 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
  11798. };
  11799. // Number keys
  11800. for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); }
  11801. // Alphabetic keys
  11802. for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); }
  11803. // Function keys
  11804. for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; }
  11805. var keyMap = {};
  11806. keyMap.basic = {
  11807. "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
  11808. "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
  11809. "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
  11810. "Tab": "defaultTab", "Shift-Tab": "indentAuto",
  11811. "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
  11812. "Esc": "singleSelection"
  11813. };
  11814. // Note that the save and find-related commands aren't defined by
  11815. // default. User code or addons can define them. Unknown commands
  11816. // are simply ignored.
  11817. keyMap.pcDefault = {
  11818. "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
  11819. "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
  11820. "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
  11821. "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
  11822. "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
  11823. "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
  11824. "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
  11825. "fallthrough": "basic"
  11826. };
  11827. // Very basic readline/emacs-style bindings, which are standard on Mac.
  11828. keyMap.emacsy = {
  11829. "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
  11830. "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
  11831. "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
  11832. "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
  11833. "Ctrl-O": "openLine"
  11834. };
  11835. keyMap.macDefault = {
  11836. "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
  11837. "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
  11838. "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
  11839. "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
  11840. "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
  11841. "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
  11842. "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
  11843. "fallthrough": ["basic", "emacsy"]
  11844. };
  11845. keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
  11846. // KEYMAP DISPATCH
  11847. function normalizeKeyName(name) {
  11848. var parts = name.split(/-(?!$)/);
  11849. name = parts[parts.length - 1];
  11850. var alt, ctrl, shift, cmd;
  11851. for (var i = 0; i < parts.length - 1; i++) {
  11852. var mod = parts[i];
  11853. if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; }
  11854. else if (/^a(lt)?$/i.test(mod)) { alt = true; }
  11855. else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; }
  11856. else if (/^s(hift)?$/i.test(mod)) { shift = true; }
  11857. else { throw new Error("Unrecognized modifier name: " + mod) }
  11858. }
  11859. if (alt) { name = "Alt-" + name; }
  11860. if (ctrl) { name = "Ctrl-" + name; }
  11861. if (cmd) { name = "Cmd-" + name; }
  11862. if (shift) { name = "Shift-" + name; }
  11863. return name
  11864. }
  11865. // This is a kludge to keep keymaps mostly working as raw objects
  11866. // (backwards compatibility) while at the same time support features
  11867. // like normalization and multi-stroke key bindings. It compiles a
  11868. // new normalized keymap, and then updates the old object to reflect
  11869. // this.
  11870. function normalizeKeyMap(keymap) {
  11871. var copy = {};
  11872. for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
  11873. var value = keymap[keyname];
  11874. if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
  11875. if (value == "...") { delete keymap[keyname]; continue }
  11876. var keys = map(keyname.split(" "), normalizeKeyName);
  11877. for (var i = 0; i < keys.length; i++) {
  11878. var val = (void 0), name = (void 0);
  11879. if (i == keys.length - 1) {
  11880. name = keys.join(" ");
  11881. val = value;
  11882. } else {
  11883. name = keys.slice(0, i + 1).join(" ");
  11884. val = "...";
  11885. }
  11886. var prev = copy[name];
  11887. if (!prev) { copy[name] = val; }
  11888. else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
  11889. }
  11890. delete keymap[keyname];
  11891. } }
  11892. for (var prop in copy) { keymap[prop] = copy[prop]; }
  11893. return keymap
  11894. }
  11895. function lookupKey(key, map, handle, context) {
  11896. map = getKeyMap(map);
  11897. var found = map.call ? map.call(key, context) : map[key];
  11898. if (found === false) { return "nothing" }
  11899. if (found === "...") { return "multi" }
  11900. if (found != null && handle(found)) { return "handled" }
  11901. if (map.fallthrough) {
  11902. if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
  11903. { return lookupKey(key, map.fallthrough, handle, context) }
  11904. for (var i = 0; i < map.fallthrough.length; i++) {
  11905. var result = lookupKey(key, map.fallthrough[i], handle, context);
  11906. if (result) { return result }
  11907. }
  11908. }
  11909. }
  11910. // Modifier key presses don't count as 'real' key presses for the
  11911. // purpose of keymap fallthrough.
  11912. function isModifierKey(value) {
  11913. var name = typeof value == "string" ? value : keyNames[value.keyCode];
  11914. return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
  11915. }
  11916. function addModifierNames(name, event, noShift) {
  11917. var base = name;
  11918. if (event.altKey && base != "Alt") { name = "Alt-" + name; }
  11919. if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; }
  11920. if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name; }
  11921. if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; }
  11922. return name
  11923. }
  11924. // Look up the name of a key as indicated by an event object.
  11925. function keyName(event, noShift) {
  11926. if (presto && event.keyCode == 34 && event["char"]) { return false }
  11927. var name = keyNames[event.keyCode];
  11928. if (name == null || event.altGraphKey) { return false }
  11929. // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
  11930. // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
  11931. if (event.keyCode == 3 && event.code) { name = event.code; }
  11932. return addModifierNames(name, event, noShift)
  11933. }
  11934. function getKeyMap(val) {
  11935. return typeof val == "string" ? keyMap[val] : val
  11936. }
  11937. // Helper for deleting text near the selection(s), used to implement
  11938. // backspace, delete, and similar functionality.
  11939. function deleteNearSelection(cm, compute) {
  11940. var ranges = cm.doc.sel.ranges, kill = [];
  11941. // Build up a set of ranges to kill first, merging overlapping
  11942. // ranges.
  11943. for (var i = 0; i < ranges.length; i++) {
  11944. var toKill = compute(ranges[i]);
  11945. while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
  11946. var replaced = kill.pop();
  11947. if (cmp(replaced.from, toKill.from) < 0) {
  11948. toKill.from = replaced.from;
  11949. break
  11950. }
  11951. }
  11952. kill.push(toKill);
  11953. }
  11954. // Next, remove those actual ranges.
  11955. runInOp(cm, function () {
  11956. for (var i = kill.length - 1; i >= 0; i--)
  11957. { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); }
  11958. ensureCursorVisible(cm);
  11959. });
  11960. }
  11961. function moveCharLogically(line, ch, dir) {
  11962. var target = skipExtendingChars(line.text, ch + dir, dir);
  11963. return target < 0 || target > line.text.length ? null : target
  11964. }
  11965. function moveLogically(line, start, dir) {
  11966. var ch = moveCharLogically(line, start.ch, dir);
  11967. return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
  11968. }
  11969. function endOfLine(visually, cm, lineObj, lineNo, dir) {
  11970. if (visually) {
  11971. if (cm.doc.direction == "rtl") { dir = -dir; }
  11972. var order = getOrder(lineObj, cm.doc.direction);
  11973. if (order) {
  11974. var part = dir < 0 ? lst(order) : order[0];
  11975. var moveInStorageOrder = (dir < 0) == (part.level == 1);
  11976. var sticky = moveInStorageOrder ? "after" : "before";
  11977. var ch;
  11978. // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
  11979. // it could be that the last bidi part is not on the last visual line,
  11980. // since visual lines contain content order-consecutive chunks.
  11981. // Thus, in rtl, we are looking for the first (content-order) character
  11982. // in the rtl chunk that is on the last line (that is, the same line
  11983. // as the last (content-order) character).
  11984. if (part.level > 0 || cm.doc.direction == "rtl") {
  11985. var prep = prepareMeasureForLine(cm, lineObj);
  11986. ch = dir < 0 ? lineObj.text.length - 1 : 0;
  11987. var targetTop = measureCharPrepared(cm, prep, ch).top;
  11988. ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch);
  11989. if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1); }
  11990. } else { ch = dir < 0 ? part.to : part.from; }
  11991. return new Pos(lineNo, ch, sticky)
  11992. }
  11993. }
  11994. return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
  11995. }
  11996. function moveVisually(cm, line, start, dir) {
  11997. var bidi = getOrder(line, cm.doc.direction);
  11998. if (!bidi) { return moveLogically(line, start, dir) }
  11999. if (start.ch >= line.text.length) {
  12000. start.ch = line.text.length;
  12001. start.sticky = "before";
  12002. } else if (start.ch <= 0) {
  12003. start.ch = 0;
  12004. start.sticky = "after";
  12005. }
  12006. var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
  12007. if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
  12008. // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
  12009. // nothing interesting happens.
  12010. return moveLogically(line, start, dir)
  12011. }
  12012. var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); };
  12013. var prep;
  12014. var getWrappedLineExtent = function (ch) {
  12015. if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
  12016. prep = prep || prepareMeasureForLine(cm, line);
  12017. return wrappedLineExtentChar(cm, line, prep, ch)
  12018. };
  12019. var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
  12020. if (cm.doc.direction == "rtl" || part.level == 1) {
  12021. var moveInStorageOrder = (part.level == 1) == (dir < 0);
  12022. var ch = mv(start, moveInStorageOrder ? 1 : -1);
  12023. if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
  12024. // Case 2: We move within an rtl part or in an rtl editor on the same visual line
  12025. var sticky = moveInStorageOrder ? "before" : "after";
  12026. return new Pos(start.line, ch, sticky)
  12027. }
  12028. }
  12029. // Case 3: Could not move within this bidi part in this visual line, so leave
  12030. // the current bidi part
  12031. var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
  12032. var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
  12033. ? new Pos(start.line, mv(ch, 1), "before")
  12034. : new Pos(start.line, ch, "after"); };
  12035. for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
  12036. var part = bidi[partPos];
  12037. var moveInStorageOrder = (dir > 0) == (part.level != 1);
  12038. var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
  12039. if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
  12040. ch = moveInStorageOrder ? part.from : mv(part.to, -1);
  12041. if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
  12042. }
  12043. };
  12044. // Case 3a: Look for other bidi parts on the same visual line
  12045. var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
  12046. if (res) { return res }
  12047. // Case 3b: Look for other bidi parts on the next visual line
  12048. var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
  12049. if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
  12050. res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
  12051. if (res) { return res }
  12052. }
  12053. // Case 4: Nowhere to move
  12054. return null
  12055. }
  12056. // Commands are parameter-less actions that can be performed on an
  12057. // editor, mostly used for keybindings.
  12058. var commands = {
  12059. selectAll: selectAll,
  12060. singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
  12061. killLine: function (cm) { return deleteNearSelection(cm, function (range) {
  12062. if (range.empty()) {
  12063. var len = getLine(cm.doc, range.head.line).text.length;
  12064. if (range.head.ch == len && range.head.line < cm.lastLine())
  12065. { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
  12066. else
  12067. { return {from: range.head, to: Pos(range.head.line, len)} }
  12068. } else {
  12069. return {from: range.from(), to: range.to()}
  12070. }
  12071. }); },
  12072. deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
  12073. from: Pos(range.from().line, 0),
  12074. to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
  12075. }); }); },
  12076. delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
  12077. from: Pos(range.from().line, 0), to: range.from()
  12078. }); }); },
  12079. delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
  12080. var top = cm.charCoords(range.head, "div").top + 5;
  12081. var leftPos = cm.coordsChar({left: 0, top: top}, "div");
  12082. return {from: leftPos, to: range.from()}
  12083. }); },
  12084. delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
  12085. var top = cm.charCoords(range.head, "div").top + 5;
  12086. var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
  12087. return {from: range.from(), to: rightPos }
  12088. }); },
  12089. undo: function (cm) { return cm.undo(); },
  12090. redo: function (cm) { return cm.redo(); },
  12091. undoSelection: function (cm) { return cm.undoSelection(); },
  12092. redoSelection: function (cm) { return cm.redoSelection(); },
  12093. goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
  12094. goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
  12095. goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
  12096. {origin: "+move", bias: 1}
  12097. ); },
  12098. goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
  12099. {origin: "+move", bias: 1}
  12100. ); },
  12101. goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
  12102. {origin: "+move", bias: -1}
  12103. ); },
  12104. goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
  12105. var top = cm.cursorCoords(range.head, "div").top + 5;
  12106. return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
  12107. }, sel_move); },
  12108. goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
  12109. var top = cm.cursorCoords(range.head, "div").top + 5;
  12110. return cm.coordsChar({left: 0, top: top}, "div")
  12111. }, sel_move); },
  12112. goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
  12113. var top = cm.cursorCoords(range.head, "div").top + 5;
  12114. var pos = cm.coordsChar({left: 0, top: top}, "div");
  12115. if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
  12116. return pos
  12117. }, sel_move); },
  12118. goLineUp: function (cm) { return cm.moveV(-1, "line"); },
  12119. goLineDown: function (cm) { return cm.moveV(1, "line"); },
  12120. goPageUp: function (cm) { return cm.moveV(-1, "page"); },
  12121. goPageDown: function (cm) { return cm.moveV(1, "page"); },
  12122. goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
  12123. goCharRight: function (cm) { return cm.moveH(1, "char"); },
  12124. goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
  12125. goColumnRight: function (cm) { return cm.moveH(1, "column"); },
  12126. goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
  12127. goGroupRight: function (cm) { return cm.moveH(1, "group"); },
  12128. goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
  12129. goWordRight: function (cm) { return cm.moveH(1, "word"); },
  12130. delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
  12131. delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
  12132. delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
  12133. delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
  12134. delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
  12135. delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
  12136. indentAuto: function (cm) { return cm.indentSelection("smart"); },
  12137. indentMore: function (cm) { return cm.indentSelection("add"); },
  12138. indentLess: function (cm) { return cm.indentSelection("subtract"); },
  12139. insertTab: function (cm) { return cm.replaceSelection("\t"); },
  12140. insertSoftTab: function (cm) {
  12141. var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
  12142. for (var i = 0; i < ranges.length; i++) {
  12143. var pos = ranges[i].from();
  12144. var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
  12145. spaces.push(spaceStr(tabSize - col % tabSize));
  12146. }
  12147. cm.replaceSelections(spaces);
  12148. },
  12149. defaultTab: function (cm) {
  12150. if (cm.somethingSelected()) { cm.indentSelection("add"); }
  12151. else { cm.execCommand("insertTab"); }
  12152. },
  12153. // Swap the two chars left and right of each selection's head.
  12154. // Move cursor behind the two swapped characters afterwards.
  12155. //
  12156. // Doesn't consider line feeds a character.
  12157. // Doesn't scan more than one line above to find a character.
  12158. // Doesn't do anything on an empty line.
  12159. // Doesn't do anything with non-empty selections.
  12160. transposeChars: function (cm) { return runInOp(cm, function () {
  12161. var ranges = cm.listSelections(), newSel = [];
  12162. for (var i = 0; i < ranges.length; i++) {
  12163. if (!ranges[i].empty()) { continue }
  12164. var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
  12165. if (line) {
  12166. if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); }
  12167. if (cur.ch > 0) {
  12168. cur = new Pos(cur.line, cur.ch + 1);
  12169. cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
  12170. Pos(cur.line, cur.ch - 2), cur, "+transpose");
  12171. } else if (cur.line > cm.doc.first) {
  12172. var prev = getLine(cm.doc, cur.line - 1).text;
  12173. if (prev) {
  12174. cur = new Pos(cur.line, 1);
  12175. cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
  12176. prev.charAt(prev.length - 1),
  12177. Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
  12178. }
  12179. }
  12180. }
  12181. newSel.push(new Range(cur, cur));
  12182. }
  12183. cm.setSelections(newSel);
  12184. }); },
  12185. newlineAndIndent: function (cm) { return runInOp(cm, function () {
  12186. var sels = cm.listSelections();
  12187. for (var i = sels.length - 1; i >= 0; i--)
  12188. { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); }
  12189. sels = cm.listSelections();
  12190. for (var i$1 = 0; i$1 < sels.length; i$1++)
  12191. { cm.indentLine(sels[i$1].from().line, null, true); }
  12192. ensureCursorVisible(cm);
  12193. }); },
  12194. openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
  12195. toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
  12196. };
  12197. function lineStart(cm, lineN) {
  12198. var line = getLine(cm.doc, lineN);
  12199. var visual = visualLine(line);
  12200. if (visual != line) { lineN = lineNo(visual); }
  12201. return endOfLine(true, cm, visual, lineN, 1)
  12202. }
  12203. function lineEnd(cm, lineN) {
  12204. var line = getLine(cm.doc, lineN);
  12205. var visual = visualLineEnd(line);
  12206. if (visual != line) { lineN = lineNo(visual); }
  12207. return endOfLine(true, cm, line, lineN, -1)
  12208. }
  12209. function lineStartSmart(cm, pos) {
  12210. var start = lineStart(cm, pos.line);
  12211. var line = getLine(cm.doc, start.line);
  12212. var order = getOrder(line, cm.doc.direction);
  12213. if (!order || order[0].level == 0) {
  12214. var firstNonWS = Math.max(start.ch, line.text.search(/\S/));
  12215. var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
  12216. return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
  12217. }
  12218. return start
  12219. }
  12220. // Run a handler that was bound to a key.
  12221. function doHandleBinding(cm, bound, dropShift) {
  12222. if (typeof bound == "string") {
  12223. bound = commands[bound];
  12224. if (!bound) { return false }
  12225. }
  12226. // Ensure previous input has been read, so that the handler sees a
  12227. // consistent view of the document
  12228. cm.display.input.ensurePolled();
  12229. var prevShift = cm.display.shift, done = false;
  12230. try {
  12231. if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
  12232. if (dropShift) { cm.display.shift = false; }
  12233. done = bound(cm) != Pass;
  12234. } finally {
  12235. cm.display.shift = prevShift;
  12236. cm.state.suppressEdits = false;
  12237. }
  12238. return done
  12239. }
  12240. function lookupKeyForEditor(cm, name, handle) {
  12241. for (var i = 0; i < cm.state.keyMaps.length; i++) {
  12242. var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
  12243. if (result) { return result }
  12244. }
  12245. return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
  12246. || lookupKey(name, cm.options.keyMap, handle, cm)
  12247. }
  12248. // Note that, despite the name, this function is also used to check
  12249. // for bound mouse clicks.
  12250. var stopSeq = new Delayed;
  12251. function dispatchKey(cm, name, e, handle) {
  12252. var seq = cm.state.keySeq;
  12253. if (seq) {
  12254. if (isModifierKey(name)) { return "handled" }
  12255. if (/\'$/.test(name))
  12256. { cm.state.keySeq = null; }
  12257. else
  12258. { stopSeq.set(50, function () {
  12259. if (cm.state.keySeq == seq) {
  12260. cm.state.keySeq = null;
  12261. cm.display.input.reset();
  12262. }
  12263. }); }
  12264. if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
  12265. }
  12266. return dispatchKeyInner(cm, name, e, handle)
  12267. }
  12268. function dispatchKeyInner(cm, name, e, handle) {
  12269. var result = lookupKeyForEditor(cm, name, handle);
  12270. if (result == "multi")
  12271. { cm.state.keySeq = name; }
  12272. if (result == "handled")
  12273. { signalLater(cm, "keyHandled", cm, name, e); }
  12274. if (result == "handled" || result == "multi") {
  12275. e_preventDefault(e);
  12276. restartBlink(cm);
  12277. }
  12278. return !!result
  12279. }
  12280. // Handle a key from the keydown event.
  12281. function handleKeyBinding(cm, e) {
  12282. var name = keyName(e, true);
  12283. if (!name) { return false }
  12284. if (e.shiftKey && !cm.state.keySeq) {
  12285. // First try to resolve full name (including 'Shift-'). Failing
  12286. // that, see if there is a cursor-motion command (starting with
  12287. // 'go') bound to the keyname without 'Shift-'.
  12288. return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
  12289. || dispatchKey(cm, name, e, function (b) {
  12290. if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
  12291. { return doHandleBinding(cm, b) }
  12292. })
  12293. } else {
  12294. return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
  12295. }
  12296. }
  12297. // Handle a key from the keypress event
  12298. function handleCharBinding(cm, e, ch) {
  12299. return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
  12300. }
  12301. var lastStoppedKey = null;
  12302. function onKeyDown(e) {
  12303. var cm = this;
  12304. cm.curOp.focus = activeElt();
  12305. if (signalDOMEvent(cm, e)) { return }
  12306. // IE does strange things with escape.
  12307. if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
  12308. var code = e.keyCode;
  12309. cm.display.shift = code == 16 || e.shiftKey;
  12310. var handled = handleKeyBinding(cm, e);
  12311. if (presto) {
  12312. lastStoppedKey = handled ? code : null;
  12313. // Opera has no cut event... we try to at least catch the key combo
  12314. if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
  12315. { cm.replaceSelection("", null, "cut"); }
  12316. }
  12317. if (gecko && !mac && !handled && code == 46 && e.shiftKey && !e.ctrlKey && document.execCommand)
  12318. { document.execCommand("cut"); }
  12319. // Turn mouse into crosshair when Alt is held on Mac.
  12320. if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
  12321. { showCrossHair(cm); }
  12322. }
  12323. function showCrossHair(cm) {
  12324. var lineDiv = cm.display.lineDiv;
  12325. addClass(lineDiv, "CodeMirror-crosshair");
  12326. function up(e) {
  12327. if (e.keyCode == 18 || !e.altKey) {
  12328. rmClass(lineDiv, "CodeMirror-crosshair");
  12329. off(document, "keyup", up);
  12330. off(document, "mouseover", up);
  12331. }
  12332. }
  12333. on(document, "keyup", up);
  12334. on(document, "mouseover", up);
  12335. }
  12336. function onKeyUp(e) {
  12337. if (e.keyCode == 16) { this.doc.sel.shift = false; }
  12338. signalDOMEvent(this, e);
  12339. }
  12340. function onKeyPress(e) {
  12341. var cm = this;
  12342. if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
  12343. var keyCode = e.keyCode, charCode = e.charCode;
  12344. if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
  12345. if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
  12346. var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
  12347. // Some browsers fire keypress events for backspace
  12348. if (ch == "\x08") { return }
  12349. if (handleCharBinding(cm, e, ch)) { return }
  12350. cm.display.input.onKeyPress(e);
  12351. }
  12352. var DOUBLECLICK_DELAY = 400;
  12353. var PastClick = function(time, pos, button) {
  12354. this.time = time;
  12355. this.pos = pos;
  12356. this.button = button;
  12357. };
  12358. PastClick.prototype.compare = function (time, pos, button) {
  12359. return this.time + DOUBLECLICK_DELAY > time &&
  12360. cmp(pos, this.pos) == 0 && button == this.button
  12361. };
  12362. var lastClick, lastDoubleClick;
  12363. function clickRepeat(pos, button) {
  12364. var now = +new Date;
  12365. if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
  12366. lastClick = lastDoubleClick = null;
  12367. return "triple"
  12368. } else if (lastClick && lastClick.compare(now, pos, button)) {
  12369. lastDoubleClick = new PastClick(now, pos, button);
  12370. lastClick = null;
  12371. return "double"
  12372. } else {
  12373. lastClick = new PastClick(now, pos, button);
  12374. lastDoubleClick = null;
  12375. return "single"
  12376. }
  12377. }
  12378. // A mouse down can be a single click, double click, triple click,
  12379. // start of selection drag, start of text drag, new cursor
  12380. // (ctrl-click), rectangle drag (alt-drag), or xwin
  12381. // middle-click-paste. Or it might be a click on something we should
  12382. // not interfere with, such as a scrollbar or widget.
  12383. function onMouseDown(e) {
  12384. var cm = this, display = cm.display;
  12385. if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
  12386. display.input.ensurePolled();
  12387. display.shift = e.shiftKey;
  12388. if (eventInWidget(display, e)) {
  12389. if (!webkit) {
  12390. // Briefly turn off draggability, to allow widgets to do
  12391. // normal dragging things.
  12392. display.scroller.draggable = false;
  12393. setTimeout(function () { return display.scroller.draggable = true; }, 100);
  12394. }
  12395. return
  12396. }
  12397. if (clickInGutter(cm, e)) { return }
  12398. var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single";
  12399. window.focus();
  12400. // #3261: make sure, that we're not starting a second selection
  12401. if (button == 1 && cm.state.selectingText)
  12402. { cm.state.selectingText(e); }
  12403. if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
  12404. if (button == 1) {
  12405. if (pos) { leftButtonDown(cm, pos, repeat, e); }
  12406. else if (e_target(e) == display.scroller) { e_preventDefault(e); }
  12407. } else if (button == 2) {
  12408. if (pos) { extendSelection(cm.doc, pos); }
  12409. setTimeout(function () { return display.input.focus(); }, 20);
  12410. } else if (button == 3) {
  12411. if (captureRightClick) { cm.display.input.onContextMenu(e); }
  12412. else { delayBlurEvent(cm); }
  12413. }
  12414. }
  12415. function handleMappedButton(cm, button, pos, repeat, event) {
  12416. var name = "Click";
  12417. if (repeat == "double") { name = "Double" + name; }
  12418. else if (repeat == "triple") { name = "Triple" + name; }
  12419. name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
  12420. return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
  12421. if (typeof bound == "string") { bound = commands[bound]; }
  12422. if (!bound) { return false }
  12423. var done = false;
  12424. try {
  12425. if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
  12426. done = bound(cm, pos) != Pass;
  12427. } finally {
  12428. cm.state.suppressEdits = false;
  12429. }
  12430. return done
  12431. })
  12432. }
  12433. function configureMouse(cm, repeat, event) {
  12434. var option = cm.getOption("configureMouse");
  12435. var value = option ? option(cm, repeat, event) : {};
  12436. if (value.unit == null) {
  12437. var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
  12438. value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
  12439. }
  12440. if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey; }
  12441. if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey; }
  12442. if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey); }
  12443. return value
  12444. }
  12445. function leftButtonDown(cm, pos, repeat, event) {
  12446. if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
  12447. else { cm.curOp.focus = activeElt(); }
  12448. var behavior = configureMouse(cm, repeat, event);
  12449. var sel = cm.doc.sel, contained;
  12450. if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
  12451. repeat == "single" && (contained = sel.contains(pos)) > -1 &&
  12452. (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
  12453. (cmp(contained.to(), pos) > 0 || pos.xRel < 0))
  12454. { leftButtonStartDrag(cm, event, pos, behavior); }
  12455. else
  12456. { leftButtonSelect(cm, event, pos, behavior); }
  12457. }
  12458. // Start a text drag. When it ends, see if any dragging actually
  12459. // happen, and treat as a click if it didn't.
  12460. function leftButtonStartDrag(cm, event, pos, behavior) {
  12461. var display = cm.display, moved = false;
  12462. var dragEnd = operation(cm, function (e) {
  12463. if (webkit) { display.scroller.draggable = false; }
  12464. cm.state.draggingText = false;
  12465. off(display.wrapper.ownerDocument, "mouseup", dragEnd);
  12466. off(display.wrapper.ownerDocument, "mousemove", mouseMove);
  12467. off(display.scroller, "dragstart", dragStart);
  12468. off(display.scroller, "drop", dragEnd);
  12469. if (!moved) {
  12470. e_preventDefault(e);
  12471. if (!behavior.addNew)
  12472. { extendSelection(cm.doc, pos, null, null, behavior.extend); }
  12473. // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
  12474. if (webkit || ie && ie_version == 9)
  12475. { setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus();}, 20); }
  12476. else
  12477. { display.input.focus(); }
  12478. }
  12479. });
  12480. var mouseMove = function(e2) {
  12481. moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
  12482. };
  12483. var dragStart = function () { return moved = true; };
  12484. // Let the drag handler handle this.
  12485. if (webkit) { display.scroller.draggable = true; }
  12486. cm.state.draggingText = dragEnd;
  12487. dragEnd.copy = !behavior.moveOnDrag;
  12488. // IE's approach to draggable
  12489. if (display.scroller.dragDrop) { display.scroller.dragDrop(); }
  12490. on(display.wrapper.ownerDocument, "mouseup", dragEnd);
  12491. on(display.wrapper.ownerDocument, "mousemove", mouseMove);
  12492. on(display.scroller, "dragstart", dragStart);
  12493. on(display.scroller, "drop", dragEnd);
  12494. delayBlurEvent(cm);
  12495. setTimeout(function () { return display.input.focus(); }, 20);
  12496. }
  12497. function rangeForUnit(cm, pos, unit) {
  12498. if (unit == "char") { return new Range(pos, pos) }
  12499. if (unit == "word") { return cm.findWordAt(pos) }
  12500. if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
  12501. var result = unit(cm, pos);
  12502. return new Range(result.from, result.to)
  12503. }
  12504. // Normal selection, as opposed to text dragging.
  12505. function leftButtonSelect(cm, event, start, behavior) {
  12506. var display = cm.display, doc = cm.doc;
  12507. e_preventDefault(event);
  12508. var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
  12509. if (behavior.addNew && !behavior.extend) {
  12510. ourIndex = doc.sel.contains(start);
  12511. if (ourIndex > -1)
  12512. { ourRange = ranges[ourIndex]; }
  12513. else
  12514. { ourRange = new Range(start, start); }
  12515. } else {
  12516. ourRange = doc.sel.primary();
  12517. ourIndex = doc.sel.primIndex;
  12518. }
  12519. if (behavior.unit == "rectangle") {
  12520. if (!behavior.addNew) { ourRange = new Range(start, start); }
  12521. start = posFromMouse(cm, event, true, true);
  12522. ourIndex = -1;
  12523. } else {
  12524. var range = rangeForUnit(cm, start, behavior.unit);
  12525. if (behavior.extend)
  12526. { ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend); }
  12527. else
  12528. { ourRange = range; }
  12529. }
  12530. if (!behavior.addNew) {
  12531. ourIndex = 0;
  12532. setSelection(doc, new Selection([ourRange], 0), sel_mouse);
  12533. startSel = doc.sel;
  12534. } else if (ourIndex == -1) {
  12535. ourIndex = ranges.length;
  12536. setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
  12537. {scroll: false, origin: "*mouse"});
  12538. } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
  12539. setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
  12540. {scroll: false, origin: "*mouse"});
  12541. startSel = doc.sel;
  12542. } else {
  12543. replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
  12544. }
  12545. var lastPos = start;
  12546. function extendTo(pos) {
  12547. if (cmp(lastPos, pos) == 0) { return }
  12548. lastPos = pos;
  12549. if (behavior.unit == "rectangle") {
  12550. var ranges = [], tabSize = cm.options.tabSize;
  12551. var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
  12552. var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
  12553. var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
  12554. for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
  12555. line <= end; line++) {
  12556. var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
  12557. if (left == right)
  12558. { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
  12559. else if (text.length > leftPos)
  12560. { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
  12561. }
  12562. if (!ranges.length) { ranges.push(new Range(start, start)); }
  12563. setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
  12564. {origin: "*mouse", scroll: false});
  12565. cm.scrollIntoView(pos);
  12566. } else {
  12567. var oldRange = ourRange;
  12568. var range = rangeForUnit(cm, pos, behavior.unit);
  12569. var anchor = oldRange.anchor, head;
  12570. if (cmp(range.anchor, anchor) > 0) {
  12571. head = range.head;
  12572. anchor = minPos(oldRange.from(), range.anchor);
  12573. } else {
  12574. head = range.anchor;
  12575. anchor = maxPos(oldRange.to(), range.head);
  12576. }
  12577. var ranges$1 = startSel.ranges.slice(0);
  12578. ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
  12579. setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
  12580. }
  12581. }
  12582. var editorSize = display.wrapper.getBoundingClientRect();
  12583. // Used to ensure timeout re-tries don't fire when another extend
  12584. // happened in the meantime (clearTimeout isn't reliable -- at
  12585. // least on Chrome, the timeouts still happen even when cleared,
  12586. // if the clear happens after their scheduled firing time).
  12587. var counter = 0;
  12588. function extend(e) {
  12589. var curCount = ++counter;
  12590. var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
  12591. if (!cur) { return }
  12592. if (cmp(cur, lastPos) != 0) {
  12593. cm.curOp.focus = activeElt();
  12594. extendTo(cur);
  12595. var visible = visibleLines(display, doc);
  12596. if (cur.line >= visible.to || cur.line < visible.from)
  12597. { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
  12598. } else {
  12599. var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
  12600. if (outside) { setTimeout(operation(cm, function () {
  12601. if (counter != curCount) { return }
  12602. display.scroller.scrollTop += outside;
  12603. extend(e);
  12604. }), 50); }
  12605. }
  12606. }
  12607. function done(e) {
  12608. cm.state.selectingText = false;
  12609. counter = Infinity;
  12610. // If e is null or undefined we interpret this as someone trying
  12611. // to explicitly cancel the selection rather than the user
  12612. // letting go of the mouse button.
  12613. if (e) {
  12614. e_preventDefault(e);
  12615. display.input.focus();
  12616. }
  12617. off(display.wrapper.ownerDocument, "mousemove", move);
  12618. off(display.wrapper.ownerDocument, "mouseup", up);
  12619. doc.history.lastSelOrigin = null;
  12620. }
  12621. var move = operation(cm, function (e) {
  12622. if (e.buttons === 0 || !e_button(e)) { done(e); }
  12623. else { extend(e); }
  12624. });
  12625. var up = operation(cm, done);
  12626. cm.state.selectingText = up;
  12627. on(display.wrapper.ownerDocument, "mousemove", move);
  12628. on(display.wrapper.ownerDocument, "mouseup", up);
  12629. }
  12630. // Used when mouse-selecting to adjust the anchor to the proper side
  12631. // of a bidi jump depending on the visual position of the head.
  12632. function bidiSimplify(cm, range) {
  12633. var anchor = range.anchor;
  12634. var head = range.head;
  12635. var anchorLine = getLine(cm.doc, anchor.line);
  12636. if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range }
  12637. var order = getOrder(anchorLine);
  12638. if (!order) { return range }
  12639. var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
  12640. if (part.from != anchor.ch && part.to != anchor.ch) { return range }
  12641. var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1);
  12642. if (boundary == 0 || boundary == order.length) { return range }
  12643. // Compute the relative visual position of the head compared to the
  12644. // anchor (<0 is to the left, >0 to the right)
  12645. var leftSide;
  12646. if (head.line != anchor.line) {
  12647. leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
  12648. } else {
  12649. var headIndex = getBidiPartAt(order, head.ch, head.sticky);
  12650. var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
  12651. if (headIndex == boundary - 1 || headIndex == boundary)
  12652. { leftSide = dir < 0; }
  12653. else
  12654. { leftSide = dir > 0; }
  12655. }
  12656. var usePart = order[boundary + (leftSide ? -1 : 0)];
  12657. var from = leftSide == (usePart.level == 1);
  12658. var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
  12659. return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
  12660. }
  12661. // Determines whether an event happened in the gutter, and fires the
  12662. // handlers for the corresponding event.
  12663. function gutterEvent(cm, e, type, prevent) {
  12664. var mX, mY;
  12665. if (e.touches) {
  12666. mX = e.touches[0].clientX;
  12667. mY = e.touches[0].clientY;
  12668. } else {
  12669. try { mX = e.clientX; mY = e.clientY; }
  12670. catch(e) { return false }
  12671. }
  12672. if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
  12673. if (prevent) { e_preventDefault(e); }
  12674. var display = cm.display;
  12675. var lineBox = display.lineDiv.getBoundingClientRect();
  12676. if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
  12677. mY -= lineBox.top - display.viewOffset;
  12678. for (var i = 0; i < cm.display.gutterSpecs.length; ++i) {
  12679. var g = display.gutters.childNodes[i];
  12680. if (g && g.getBoundingClientRect().right >= mX) {
  12681. var line = lineAtHeight(cm.doc, mY);
  12682. var gutter = cm.display.gutterSpecs[i];
  12683. signal(cm, type, cm, line, gutter.className, e);
  12684. return e_defaultPrevented(e)
  12685. }
  12686. }
  12687. }
  12688. function clickInGutter(cm, e) {
  12689. return gutterEvent(cm, e, "gutterClick", true)
  12690. }
  12691. // CONTEXT MENU HANDLING
  12692. // To make the context menu work, we need to briefly unhide the
  12693. // textarea (making it as unobtrusive as possible) to let the
  12694. // right-click take effect on it.
  12695. function onContextMenu(cm, e) {
  12696. if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
  12697. if (signalDOMEvent(cm, e, "contextmenu")) { return }
  12698. if (!captureRightClick) { cm.display.input.onContextMenu(e); }
  12699. }
  12700. function contextMenuInGutter(cm, e) {
  12701. if (!hasHandler(cm, "gutterContextMenu")) { return false }
  12702. return gutterEvent(cm, e, "gutterContextMenu", false)
  12703. }
  12704. function themeChanged(cm) {
  12705. cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
  12706. cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
  12707. clearCaches(cm);
  12708. }
  12709. var Init = {toString: function(){return "CodeMirror.Init"}};
  12710. var defaults = {};
  12711. var optionHandlers = {};
  12712. function defineOptions(CodeMirror) {
  12713. var optionHandlers = CodeMirror.optionHandlers;
  12714. function option(name, deflt, handle, notOnInit) {
  12715. CodeMirror.defaults[name] = deflt;
  12716. if (handle) { optionHandlers[name] =
  12717. notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
  12718. }
  12719. CodeMirror.defineOption = option;
  12720. // Passed to option handlers when there is no old value.
  12721. CodeMirror.Init = Init;
  12722. // These two are, on init, called from the constructor because they
  12723. // have to be initialized before the editor can start at all.
  12724. option("value", "", function (cm, val) { return cm.setValue(val); }, true);
  12725. option("mode", null, function (cm, val) {
  12726. cm.doc.modeOption = val;
  12727. loadMode(cm);
  12728. }, true);
  12729. option("indentUnit", 2, loadMode, true);
  12730. option("indentWithTabs", false);
  12731. option("smartIndent", true);
  12732. option("tabSize", 4, function (cm) {
  12733. resetModeState(cm);
  12734. clearCaches(cm);
  12735. regChange(cm);
  12736. }, true);
  12737. option("lineSeparator", null, function (cm, val) {
  12738. cm.doc.lineSep = val;
  12739. if (!val) { return }
  12740. var newBreaks = [], lineNo = cm.doc.first;
  12741. cm.doc.iter(function (line) {
  12742. for (var pos = 0;;) {
  12743. var found = line.text.indexOf(val, pos);
  12744. if (found == -1) { break }
  12745. pos = found + val.length;
  12746. newBreaks.push(Pos(lineNo, found));
  12747. }
  12748. lineNo++;
  12749. });
  12750. for (var i = newBreaks.length - 1; i >= 0; i--)
  12751. { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
  12752. });
  12753. option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, function (cm, val, old) {
  12754. cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
  12755. if (old != Init) { cm.refresh(); }
  12756. });
  12757. option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
  12758. option("electricChars", true);
  12759. option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
  12760. throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
  12761. }, true);
  12762. option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
  12763. option("autocorrect", false, function (cm, val) { return cm.getInputField().autocorrect = val; }, true);
  12764. option("autocapitalize", false, function (cm, val) { return cm.getInputField().autocapitalize = val; }, true);
  12765. option("rtlMoveVisually", !windows);
  12766. option("wholeLineUpdateBefore", true);
  12767. option("theme", "default", function (cm) {
  12768. themeChanged(cm);
  12769. updateGutters(cm);
  12770. }, true);
  12771. option("keyMap", "default", function (cm, val, old) {
  12772. var next = getKeyMap(val);
  12773. var prev = old != Init && getKeyMap(old);
  12774. if (prev && prev.detach) { prev.detach(cm, next); }
  12775. if (next.attach) { next.attach(cm, prev || null); }
  12776. });
  12777. option("extraKeys", null);
  12778. option("configureMouse", null);
  12779. option("lineWrapping", false, wrappingChanged, true);
  12780. option("gutters", [], function (cm, val) {
  12781. cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers);
  12782. updateGutters(cm);
  12783. }, true);
  12784. option("fixedGutter", true, function (cm, val) {
  12785. cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
  12786. cm.refresh();
  12787. }, true);
  12788. option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true);
  12789. option("scrollbarStyle", "native", function (cm) {
  12790. initScrollbars(cm);
  12791. updateScrollbars(cm);
  12792. cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
  12793. cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
  12794. }, true);
  12795. option("lineNumbers", false, function (cm, val) {
  12796. cm.display.gutterSpecs = getGutters(cm.options.gutters, val);
  12797. updateGutters(cm);
  12798. }, true);
  12799. option("firstLineNumber", 1, updateGutters, true);
  12800. option("lineNumberFormatter", function (integer) { return integer; }, updateGutters, true);
  12801. option("showCursorWhenSelecting", false, updateSelection, true);
  12802. option("resetSelectionOnContextMenu", true);
  12803. option("lineWiseCopyCut", true);
  12804. option("pasteLinesPerSelection", true);
  12805. option("selectionsMayTouch", false);
  12806. option("readOnly", false, function (cm, val) {
  12807. if (val == "nocursor") {
  12808. onBlur(cm);
  12809. cm.display.input.blur();
  12810. }
  12811. cm.display.input.readOnlyChanged(val);
  12812. });
  12813. option("screenReaderLabel", null, function (cm, val) {
  12814. val = (val === '') ? null : val;
  12815. cm.display.input.screenReaderLabelChanged(val);
  12816. });
  12817. option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true);
  12818. option("dragDrop", true, dragDropChanged);
  12819. option("allowDropFileTypes", null);
  12820. option("cursorBlinkRate", 530);
  12821. option("cursorScrollMargin", 0);
  12822. option("cursorHeight", 1, updateSelection, true);
  12823. option("singleCursorHeightPerLine", true, updateSelection, true);
  12824. option("workTime", 100);
  12825. option("workDelay", 100);
  12826. option("flattenSpans", true, resetModeState, true);
  12827. option("addModeClass", false, resetModeState, true);
  12828. option("pollInterval", 100);
  12829. option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; });
  12830. option("historyEventDelay", 1250);
  12831. option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true);
  12832. option("maxHighlightLength", 10000, resetModeState, true);
  12833. option("moveInputWithCursor", true, function (cm, val) {
  12834. if (!val) { cm.display.input.resetPosition(); }
  12835. });
  12836. option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; });
  12837. option("autofocus", null);
  12838. option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true);
  12839. option("phrases", null);
  12840. }
  12841. function dragDropChanged(cm, value, old) {
  12842. var wasOn = old && old != Init;
  12843. if (!value != !wasOn) {
  12844. var funcs = cm.display.dragFunctions;
  12845. var toggle = value ? on : off;
  12846. toggle(cm.display.scroller, "dragstart", funcs.start);
  12847. toggle(cm.display.scroller, "dragenter", funcs.enter);
  12848. toggle(cm.display.scroller, "dragover", funcs.over);
  12849. toggle(cm.display.scroller, "dragleave", funcs.leave);
  12850. toggle(cm.display.scroller, "drop", funcs.drop);
  12851. }
  12852. }
  12853. function wrappingChanged(cm) {
  12854. if (cm.options.lineWrapping) {
  12855. addClass(cm.display.wrapper, "CodeMirror-wrap");
  12856. cm.display.sizer.style.minWidth = "";
  12857. cm.display.sizerWidth = null;
  12858. } else {
  12859. rmClass(cm.display.wrapper, "CodeMirror-wrap");
  12860. findMaxLine(cm);
  12861. }
  12862. estimateLineHeights(cm);
  12863. regChange(cm);
  12864. clearCaches(cm);
  12865. setTimeout(function () { return updateScrollbars(cm); }, 100);
  12866. }
  12867. // A CodeMirror instance represents an editor. This is the object
  12868. // that user code is usually dealing with.
  12869. function CodeMirror(place, options) {
  12870. var this$1 = this;
  12871. if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
  12872. this.options = options = options ? copyObj(options) : {};
  12873. // Determine effective options based on given values and defaults.
  12874. copyObj(defaults, options, false);
  12875. var doc = options.value;
  12876. if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); }
  12877. else if (options.mode) { doc.modeOption = options.mode; }
  12878. this.doc = doc;
  12879. var input = new CodeMirror.inputStyles[options.inputStyle](this);
  12880. var display = this.display = new Display(place, doc, input, options);
  12881. display.wrapper.CodeMirror = this;
  12882. themeChanged(this);
  12883. if (options.lineWrapping)
  12884. { this.display.wrapper.className += " CodeMirror-wrap"; }
  12885. initScrollbars(this);
  12886. this.state = {
  12887. keyMaps: [], // stores maps added by addKeyMap
  12888. overlays: [], // highlighting overlays, as added by addOverlay
  12889. modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
  12890. overwrite: false,
  12891. delayingBlurEvent: false,
  12892. focused: false,
  12893. suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
  12894. pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll
  12895. selectingText: false,
  12896. draggingText: false,
  12897. highlight: new Delayed(), // stores highlight worker timeout
  12898. keySeq: null, // Unfinished key sequence
  12899. specialChars: null
  12900. };
  12901. if (options.autofocus && !mobile) { display.input.focus(); }
  12902. // Override magic textarea content restore that IE sometimes does
  12903. // on our hidden textarea on reload
  12904. if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); }
  12905. registerEventHandlers(this);
  12906. ensureGlobalHandlers();
  12907. startOperation(this);
  12908. this.curOp.forceUpdate = true;
  12909. attachDoc(this, doc);
  12910. if ((options.autofocus && !mobile) || this.hasFocus())
  12911. { setTimeout(bind(onFocus, this), 20); }
  12912. else
  12913. { onBlur(this); }
  12914. for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
  12915. { optionHandlers[opt](this, options[opt], Init); } }
  12916. maybeUpdateLineNumberWidth(this);
  12917. if (options.finishInit) { options.finishInit(this); }
  12918. for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this); }
  12919. endOperation(this);
  12920. // Suppress optimizelegibility in Webkit, since it breaks text
  12921. // measuring on line wrapping boundaries.
  12922. if (webkit && options.lineWrapping &&
  12923. getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
  12924. { display.lineDiv.style.textRendering = "auto"; }
  12925. }
  12926. // The default configuration options.
  12927. CodeMirror.defaults = defaults;
  12928. // Functions to run when options are changed.
  12929. CodeMirror.optionHandlers = optionHandlers;
  12930. // Attach the necessary event handlers when initializing the editor
  12931. function registerEventHandlers(cm) {
  12932. var d = cm.display;
  12933. on(d.scroller, "mousedown", operation(cm, onMouseDown));
  12934. // Older IE's will not fire a second mousedown for a double click
  12935. if (ie && ie_version < 11)
  12936. { on(d.scroller, "dblclick", operation(cm, function (e) {
  12937. if (signalDOMEvent(cm, e)) { return }
  12938. var pos = posFromMouse(cm, e);
  12939. if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
  12940. e_preventDefault(e);
  12941. var word = cm.findWordAt(pos);
  12942. extendSelection(cm.doc, word.anchor, word.head);
  12943. })); }
  12944. else
  12945. { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
  12946. // Some browsers fire contextmenu *after* opening the menu, at
  12947. // which point we can't mess with it anymore. Context menu is
  12948. // handled in onMouseDown for these browsers.
  12949. on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); });
  12950. on(d.input.getField(), "contextmenu", function (e) {
  12951. if (!d.scroller.contains(e.target)) { onContextMenu(cm, e); }
  12952. });
  12953. // Used to suppress mouse event handling when a touch happens
  12954. var touchFinished, prevTouch = {end: 0};
  12955. function finishTouch() {
  12956. if (d.activeTouch) {
  12957. touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
  12958. prevTouch = d.activeTouch;
  12959. prevTouch.end = +new Date;
  12960. }
  12961. }
  12962. function isMouseLikeTouchEvent(e) {
  12963. if (e.touches.length != 1) { return false }
  12964. var touch = e.touches[0];
  12965. return touch.radiusX <= 1 && touch.radiusY <= 1
  12966. }
  12967. function farAway(touch, other) {
  12968. if (other.left == null) { return true }
  12969. var dx = other.left - touch.left, dy = other.top - touch.top;
  12970. return dx * dx + dy * dy > 20 * 20
  12971. }
  12972. on(d.scroller, "touchstart", function (e) {
  12973. if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
  12974. d.input.ensurePolled();
  12975. clearTimeout(touchFinished);
  12976. var now = +new Date;
  12977. d.activeTouch = {start: now, moved: false,
  12978. prev: now - prevTouch.end <= 300 ? prevTouch : null};
  12979. if (e.touches.length == 1) {
  12980. d.activeTouch.left = e.touches[0].pageX;
  12981. d.activeTouch.top = e.touches[0].pageY;
  12982. }
  12983. }
  12984. });
  12985. on(d.scroller, "touchmove", function () {
  12986. if (d.activeTouch) { d.activeTouch.moved = true; }
  12987. });
  12988. on(d.scroller, "touchend", function (e) {
  12989. var touch = d.activeTouch;
  12990. if (touch && !eventInWidget(d, e) && touch.left != null &&
  12991. !touch.moved && new Date - touch.start < 300) {
  12992. var pos = cm.coordsChar(d.activeTouch, "page"), range;
  12993. if (!touch.prev || farAway(touch, touch.prev)) // Single tap
  12994. { range = new Range(pos, pos); }
  12995. else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
  12996. { range = cm.findWordAt(pos); }
  12997. else // Triple tap
  12998. { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); }
  12999. cm.setSelection(range.anchor, range.head);
  13000. cm.focus();
  13001. e_preventDefault(e);
  13002. }
  13003. finishTouch();
  13004. });
  13005. on(d.scroller, "touchcancel", finishTouch);
  13006. // Sync scrolling between fake scrollbars and real scrollable
  13007. // area, ensure viewport is updated when scrolling.
  13008. on(d.scroller, "scroll", function () {
  13009. if (d.scroller.clientHeight) {
  13010. updateScrollTop(cm, d.scroller.scrollTop);
  13011. setScrollLeft(cm, d.scroller.scrollLeft, true);
  13012. signal(cm, "scroll", cm);
  13013. }
  13014. });
  13015. // Listen to wheel events in order to try and update the viewport on time.
  13016. on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); });
  13017. on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); });
  13018. // Prevent wrapper from ever scrolling
  13019. on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
  13020. d.dragFunctions = {
  13021. enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }},
  13022. over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
  13023. start: function (e) { return onDragStart(cm, e); },
  13024. drop: operation(cm, onDrop),
  13025. leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
  13026. };
  13027. var inp = d.input.getField();
  13028. on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); });
  13029. on(inp, "keydown", operation(cm, onKeyDown));
  13030. on(inp, "keypress", operation(cm, onKeyPress));
  13031. on(inp, "focus", function (e) { return onFocus(cm, e); });
  13032. on(inp, "blur", function (e) { return onBlur(cm, e); });
  13033. }
  13034. var initHooks = [];
  13035. CodeMirror.defineInitHook = function (f) { return initHooks.push(f); };
  13036. // Indent the given line. The how parameter can be "smart",
  13037. // "add"/null, "subtract", or "prev". When aggressive is false
  13038. // (typically set to true for forced single-line indents), empty
  13039. // lines are not indented, and places where the mode returns Pass
  13040. // are left alone.
  13041. function indentLine(cm, n, how, aggressive) {
  13042. var doc = cm.doc, state;
  13043. if (how == null) { how = "add"; }
  13044. if (how == "smart") {
  13045. // Fall back to "prev" when the mode doesn't have an indentation
  13046. // method.
  13047. if (!doc.mode.indent) { how = "prev"; }
  13048. else { state = getContextBefore(cm, n).state; }
  13049. }
  13050. var tabSize = cm.options.tabSize;
  13051. var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
  13052. if (line.stateAfter) { line.stateAfter = null; }
  13053. var curSpaceString = line.text.match(/^\s*/)[0], indentation;
  13054. if (!aggressive && !/\S/.test(line.text)) {
  13055. indentation = 0;
  13056. how = "not";
  13057. } else if (how == "smart") {
  13058. indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
  13059. if (indentation == Pass || indentation > 150) {
  13060. if (!aggressive) { return }
  13061. how = "prev";
  13062. }
  13063. }
  13064. if (how == "prev") {
  13065. if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); }
  13066. else { indentation = 0; }
  13067. } else if (how == "add") {
  13068. indentation = curSpace + cm.options.indentUnit;
  13069. } else if (how == "subtract") {
  13070. indentation = curSpace - cm.options.indentUnit;
  13071. } else if (typeof how == "number") {
  13072. indentation = curSpace + how;
  13073. }
  13074. indentation = Math.max(0, indentation);
  13075. var indentString = "", pos = 0;
  13076. if (cm.options.indentWithTabs)
  13077. { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} }
  13078. if (pos < indentation) { indentString += spaceStr(indentation - pos); }
  13079. if (indentString != curSpaceString) {
  13080. replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
  13081. line.stateAfter = null;
  13082. return true
  13083. } else {
  13084. // Ensure that, if the cursor was in the whitespace at the start
  13085. // of the line, it is moved to the end of that space.
  13086. for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
  13087. var range = doc.sel.ranges[i$1];
  13088. if (range.head.line == n && range.head.ch < curSpaceString.length) {
  13089. var pos$1 = Pos(n, curSpaceString.length);
  13090. replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
  13091. break
  13092. }
  13093. }
  13094. }
  13095. }
  13096. // This will be set to a {lineWise: bool, text: [string]} object, so
  13097. // that, when pasting, we know what kind of selections the copied
  13098. // text was made out of.
  13099. var lastCopied = null;
  13100. function setLastCopied(newLastCopied) {
  13101. lastCopied = newLastCopied;
  13102. }
  13103. function applyTextInput(cm, inserted, deleted, sel, origin) {
  13104. var doc = cm.doc;
  13105. cm.display.shift = false;
  13106. if (!sel) { sel = doc.sel; }
  13107. var recent = +new Date - 200;
  13108. var paste = origin == "paste" || cm.state.pasteIncoming > recent;
  13109. var textLines = splitLinesAuto(inserted), multiPaste = null;
  13110. // When pasting N lines into N selections, insert one line per selection
  13111. if (paste && sel.ranges.length > 1) {
  13112. if (lastCopied && lastCopied.text.join("\n") == inserted) {
  13113. if (sel.ranges.length % lastCopied.text.length == 0) {
  13114. multiPaste = [];
  13115. for (var i = 0; i < lastCopied.text.length; i++)
  13116. { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
  13117. }
  13118. } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
  13119. multiPaste = map(textLines, function (l) { return [l]; });
  13120. }
  13121. }
  13122. var updateInput = cm.curOp.updateInput;
  13123. // Normal behavior is to insert the new text into every selection
  13124. for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
  13125. var range = sel.ranges[i$1];
  13126. var from = range.from(), to = range.to();
  13127. if (range.empty()) {
  13128. if (deleted && deleted > 0) // Handle deletion
  13129. { from = Pos(from.line, from.ch - deleted); }
  13130. else if (cm.state.overwrite && !paste) // Handle overwrite
  13131. { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
  13132. else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
  13133. { from = to = Pos(from.line, 0); }
  13134. }
  13135. var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
  13136. origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")};
  13137. makeChange(cm.doc, changeEvent);
  13138. signalLater(cm, "inputRead", cm, changeEvent);
  13139. }
  13140. if (inserted && !paste)
  13141. { triggerElectric(cm, inserted); }
  13142. ensureCursorVisible(cm);
  13143. if (cm.curOp.updateInput < 2) { cm.curOp.updateInput = updateInput; }
  13144. cm.curOp.typing = true;
  13145. cm.state.pasteIncoming = cm.state.cutIncoming = -1;
  13146. }
  13147. function handlePaste(e, cm) {
  13148. var pasted = e.clipboardData && e.clipboardData.getData("Text");
  13149. if (pasted) {
  13150. e.preventDefault();
  13151. if (!cm.isReadOnly() && !cm.options.disableInput)
  13152. { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); }
  13153. return true
  13154. }
  13155. }
  13156. function triggerElectric(cm, inserted) {
  13157. // When an 'electric' character is inserted, immediately trigger a reindent
  13158. if (!cm.options.electricChars || !cm.options.smartIndent) { return }
  13159. var sel = cm.doc.sel;
  13160. for (var i = sel.ranges.length - 1; i >= 0; i--) {
  13161. var range = sel.ranges[i];
  13162. if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue }
  13163. var mode = cm.getModeAt(range.head);
  13164. var indented = false;
  13165. if (mode.electricChars) {
  13166. for (var j = 0; j < mode.electricChars.length; j++)
  13167. { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
  13168. indented = indentLine(cm, range.head.line, "smart");
  13169. break
  13170. } }
  13171. } else if (mode.electricInput) {
  13172. if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
  13173. { indented = indentLine(cm, range.head.line, "smart"); }
  13174. }
  13175. if (indented) { signalLater(cm, "electricInput", cm, range.head.line); }
  13176. }
  13177. }
  13178. function copyableRanges(cm) {
  13179. var text = [], ranges = [];
  13180. for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
  13181. var line = cm.doc.sel.ranges[i].head.line;
  13182. var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
  13183. ranges.push(lineRange);
  13184. text.push(cm.getRange(lineRange.anchor, lineRange.head));
  13185. }
  13186. return {text: text, ranges: ranges}
  13187. }
  13188. function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
  13189. field.setAttribute("autocorrect", autocorrect ? "" : "off");
  13190. field.setAttribute("autocapitalize", autocapitalize ? "" : "off");
  13191. field.setAttribute("spellcheck", !!spellcheck);
  13192. }
  13193. function hiddenTextarea() {
  13194. var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
  13195. var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
  13196. // The textarea is kept positioned near the cursor to prevent the
  13197. // fact that it'll be scrolled into view on input from scrolling
  13198. // our fake cursor out of view. On webkit, when wrap=off, paste is
  13199. // very slow. So make the area wide instead.
  13200. if (webkit) { te.style.width = "1000px"; }
  13201. else { te.setAttribute("wrap", "off"); }
  13202. // If border: 0; -- iOS fails to open keyboard (issue #1287)
  13203. if (ios) { te.style.border = "1px solid black"; }
  13204. disableBrowserMagic(te);
  13205. return div
  13206. }
  13207. // The publicly visible API. Note that methodOp(f) means
  13208. // 'wrap f in an operation, performed on its `this` parameter'.
  13209. // This is not the complete set of editor methods. Most of the
  13210. // methods defined on the Doc type are also injected into
  13211. // CodeMirror.prototype, for backwards compatibility and
  13212. // convenience.
  13213. function addEditorMethods(CodeMirror) {
  13214. var optionHandlers = CodeMirror.optionHandlers;
  13215. var helpers = CodeMirror.helpers = {};
  13216. CodeMirror.prototype = {
  13217. constructor: CodeMirror,
  13218. focus: function(){window.focus(); this.display.input.focus();},
  13219. setOption: function(option, value) {
  13220. var options = this.options, old = options[option];
  13221. if (options[option] == value && option != "mode") { return }
  13222. options[option] = value;
  13223. if (optionHandlers.hasOwnProperty(option))
  13224. { operation(this, optionHandlers[option])(this, value, old); }
  13225. signal(this, "optionChange", this, option);
  13226. },
  13227. getOption: function(option) {return this.options[option]},
  13228. getDoc: function() {return this.doc},
  13229. addKeyMap: function(map, bottom) {
  13230. this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
  13231. },
  13232. removeKeyMap: function(map) {
  13233. var maps = this.state.keyMaps;
  13234. for (var i = 0; i < maps.length; ++i)
  13235. { if (maps[i] == map || maps[i].name == map) {
  13236. maps.splice(i, 1);
  13237. return true
  13238. } }
  13239. },
  13240. addOverlay: methodOp(function(spec, options) {
  13241. var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
  13242. if (mode.startState) { throw new Error("Overlays may not be stateful.") }
  13243. insertSorted(this.state.overlays,
  13244. {mode: mode, modeSpec: spec, opaque: options && options.opaque,
  13245. priority: (options && options.priority) || 0},
  13246. function (overlay) { return overlay.priority; });
  13247. this.state.modeGen++;
  13248. regChange(this);
  13249. }),
  13250. removeOverlay: methodOp(function(spec) {
  13251. var overlays = this.state.overlays;
  13252. for (var i = 0; i < overlays.length; ++i) {
  13253. var cur = overlays[i].modeSpec;
  13254. if (cur == spec || typeof spec == "string" && cur.name == spec) {
  13255. overlays.splice(i, 1);
  13256. this.state.modeGen++;
  13257. regChange(this);
  13258. return
  13259. }
  13260. }
  13261. }),
  13262. indentLine: methodOp(function(n, dir, aggressive) {
  13263. if (typeof dir != "string" && typeof dir != "number") {
  13264. if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; }
  13265. else { dir = dir ? "add" : "subtract"; }
  13266. }
  13267. if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); }
  13268. }),
  13269. indentSelection: methodOp(function(how) {
  13270. var ranges = this.doc.sel.ranges, end = -1;
  13271. for (var i = 0; i < ranges.length; i++) {
  13272. var range = ranges[i];
  13273. if (!range.empty()) {
  13274. var from = range.from(), to = range.to();
  13275. var start = Math.max(end, from.line);
  13276. end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
  13277. for (var j = start; j < end; ++j)
  13278. { indentLine(this, j, how); }
  13279. var newRanges = this.doc.sel.ranges;
  13280. if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
  13281. { replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); }
  13282. } else if (range.head.line > end) {
  13283. indentLine(this, range.head.line, how, true);
  13284. end = range.head.line;
  13285. if (i == this.doc.sel.primIndex) { ensureCursorVisible(this); }
  13286. }
  13287. }
  13288. }),
  13289. // Fetch the parser token for a given character. Useful for hacks
  13290. // that want to inspect the mode state (say, for completion).
  13291. getTokenAt: function(pos, precise) {
  13292. return takeToken(this, pos, precise)
  13293. },
  13294. getLineTokens: function(line, precise) {
  13295. return takeToken(this, Pos(line), precise, true)
  13296. },
  13297. getTokenTypeAt: function(pos) {
  13298. pos = clipPos(this.doc, pos);
  13299. var styles = getLineStyles(this, getLine(this.doc, pos.line));
  13300. var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
  13301. var type;
  13302. if (ch == 0) { type = styles[2]; }
  13303. else { for (;;) {
  13304. var mid = (before + after) >> 1;
  13305. if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; }
  13306. else if (styles[mid * 2 + 1] < ch) { before = mid + 1; }
  13307. else { type = styles[mid * 2 + 2]; break }
  13308. } }
  13309. var cut = type ? type.indexOf("overlay ") : -1;
  13310. return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
  13311. },
  13312. getModeAt: function(pos) {
  13313. var mode = this.doc.mode;
  13314. if (!mode.innerMode) { return mode }
  13315. return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
  13316. },
  13317. getHelper: function(pos, type) {
  13318. return this.getHelpers(pos, type)[0]
  13319. },
  13320. getHelpers: function(pos, type) {
  13321. var found = [];
  13322. if (!helpers.hasOwnProperty(type)) { return found }
  13323. var help = helpers[type], mode = this.getModeAt(pos);
  13324. if (typeof mode[type] == "string") {
  13325. if (help[mode[type]]) { found.push(help[mode[type]]); }
  13326. } else if (mode[type]) {
  13327. for (var i = 0; i < mode[type].length; i++) {
  13328. var val = help[mode[type][i]];
  13329. if (val) { found.push(val); }
  13330. }
  13331. } else if (mode.helperType && help[mode.helperType]) {
  13332. found.push(help[mode.helperType]);
  13333. } else if (help[mode.name]) {
  13334. found.push(help[mode.name]);
  13335. }
  13336. for (var i$1 = 0; i$1 < help._global.length; i$1++) {
  13337. var cur = help._global[i$1];
  13338. if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
  13339. { found.push(cur.val); }
  13340. }
  13341. return found
  13342. },
  13343. getStateAfter: function(line, precise) {
  13344. var doc = this.doc;
  13345. line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
  13346. return getContextBefore(this, line + 1, precise).state
  13347. },
  13348. cursorCoords: function(start, mode) {
  13349. var pos, range = this.doc.sel.primary();
  13350. if (start == null) { pos = range.head; }
  13351. else if (typeof start == "object") { pos = clipPos(this.doc, start); }
  13352. else { pos = start ? range.from() : range.to(); }
  13353. return cursorCoords(this, pos, mode || "page")
  13354. },
  13355. charCoords: function(pos, mode) {
  13356. return charCoords(this, clipPos(this.doc, pos), mode || "page")
  13357. },
  13358. coordsChar: function(coords, mode) {
  13359. coords = fromCoordSystem(this, coords, mode || "page");
  13360. return coordsChar(this, coords.left, coords.top)
  13361. },
  13362. lineAtHeight: function(height, mode) {
  13363. height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
  13364. return lineAtHeight(this.doc, height + this.display.viewOffset)
  13365. },
  13366. heightAtLine: function(line, mode, includeWidgets) {
  13367. var end = false, lineObj;
  13368. if (typeof line == "number") {
  13369. var last = this.doc.first + this.doc.size - 1;
  13370. if (line < this.doc.first) { line = this.doc.first; }
  13371. else if (line > last) { line = last; end = true; }
  13372. lineObj = getLine(this.doc, line);
  13373. } else {
  13374. lineObj = line;
  13375. }
  13376. return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
  13377. (end ? this.doc.height - heightAtLine(lineObj) : 0)
  13378. },
  13379. defaultTextHeight: function() { return textHeight(this.display) },
  13380. defaultCharWidth: function() { return charWidth(this.display) },
  13381. getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
  13382. addWidget: function(pos, node, scroll, vert, horiz) {
  13383. var display = this.display;
  13384. pos = cursorCoords(this, clipPos(this.doc, pos));
  13385. var top = pos.bottom, left = pos.left;
  13386. node.style.position = "absolute";
  13387. node.setAttribute("cm-ignore-events", "true");
  13388. this.display.input.setUneditable(node);
  13389. display.sizer.appendChild(node);
  13390. if (vert == "over") {
  13391. top = pos.top;
  13392. } else if (vert == "above" || vert == "near") {
  13393. var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
  13394. hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
  13395. // Default to positioning above (if specified and possible); otherwise default to positioning below
  13396. if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
  13397. { top = pos.top - node.offsetHeight; }
  13398. else if (pos.bottom + node.offsetHeight <= vspace)
  13399. { top = pos.bottom; }
  13400. if (left + node.offsetWidth > hspace)
  13401. { left = hspace - node.offsetWidth; }
  13402. }
  13403. node.style.top = top + "px";
  13404. node.style.left = node.style.right = "";
  13405. if (horiz == "right") {
  13406. left = display.sizer.clientWidth - node.offsetWidth;
  13407. node.style.right = "0px";
  13408. } else {
  13409. if (horiz == "left") { left = 0; }
  13410. else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; }
  13411. node.style.left = left + "px";
  13412. }
  13413. if (scroll)
  13414. { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); }
  13415. },
  13416. triggerOnKeyDown: methodOp(onKeyDown),
  13417. triggerOnKeyPress: methodOp(onKeyPress),
  13418. triggerOnKeyUp: onKeyUp,
  13419. triggerOnMouseDown: methodOp(onMouseDown),
  13420. execCommand: function(cmd) {
  13421. if (commands.hasOwnProperty(cmd))
  13422. { return commands[cmd].call(null, this) }
  13423. },
  13424. triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
  13425. findPosH: function(from, amount, unit, visually) {
  13426. var dir = 1;
  13427. if (amount < 0) { dir = -1; amount = -amount; }
  13428. var cur = clipPos(this.doc, from);
  13429. for (var i = 0; i < amount; ++i) {
  13430. cur = findPosH(this.doc, cur, dir, unit, visually);
  13431. if (cur.hitSide) { break }
  13432. }
  13433. return cur
  13434. },
  13435. moveH: methodOp(function(dir, unit) {
  13436. var this$1 = this;
  13437. this.extendSelectionsBy(function (range) {
  13438. if (this$1.display.shift || this$1.doc.extend || range.empty())
  13439. { return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) }
  13440. else
  13441. { return dir < 0 ? range.from() : range.to() }
  13442. }, sel_move);
  13443. }),
  13444. deleteH: methodOp(function(dir, unit) {
  13445. var sel = this.doc.sel, doc = this.doc;
  13446. if (sel.somethingSelected())
  13447. { doc.replaceSelection("", null, "+delete"); }
  13448. else
  13449. { deleteNearSelection(this, function (range) {
  13450. var other = findPosH(doc, range.head, dir, unit, false);
  13451. return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
  13452. }); }
  13453. }),
  13454. findPosV: function(from, amount, unit, goalColumn) {
  13455. var dir = 1, x = goalColumn;
  13456. if (amount < 0) { dir = -1; amount = -amount; }
  13457. var cur = clipPos(this.doc, from);
  13458. for (var i = 0; i < amount; ++i) {
  13459. var coords = cursorCoords(this, cur, "div");
  13460. if (x == null) { x = coords.left; }
  13461. else { coords.left = x; }
  13462. cur = findPosV(this, coords, dir, unit);
  13463. if (cur.hitSide) { break }
  13464. }
  13465. return cur
  13466. },
  13467. moveV: methodOp(function(dir, unit) {
  13468. var this$1 = this;
  13469. var doc = this.doc, goals = [];
  13470. var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
  13471. doc.extendSelectionsBy(function (range) {
  13472. if (collapse)
  13473. { return dir < 0 ? range.from() : range.to() }
  13474. var headPos = cursorCoords(this$1, range.head, "div");
  13475. if (range.goalColumn != null) { headPos.left = range.goalColumn; }
  13476. goals.push(headPos.left);
  13477. var pos = findPosV(this$1, headPos, dir, unit);
  13478. if (unit == "page" && range == doc.sel.primary())
  13479. { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); }
  13480. return pos
  13481. }, sel_move);
  13482. if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
  13483. { doc.sel.ranges[i].goalColumn = goals[i]; } }
  13484. }),
  13485. // Find the word at the given position (as returned by coordsChar).
  13486. findWordAt: function(pos) {
  13487. var doc = this.doc, line = getLine(doc, pos.line).text;
  13488. var start = pos.ch, end = pos.ch;
  13489. if (line) {
  13490. var helper = this.getHelper(pos, "wordChars");
  13491. if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; }
  13492. var startChar = line.charAt(start);
  13493. var check = isWordChar(startChar, helper)
  13494. ? function (ch) { return isWordChar(ch, helper); }
  13495. : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
  13496. : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); };
  13497. while (start > 0 && check(line.charAt(start - 1))) { --start; }
  13498. while (end < line.length && check(line.charAt(end))) { ++end; }
  13499. }
  13500. return new Range(Pos(pos.line, start), Pos(pos.line, end))
  13501. },
  13502. toggleOverwrite: function(value) {
  13503. if (value != null && value == this.state.overwrite) { return }
  13504. if (this.state.overwrite = !this.state.overwrite)
  13505. { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
  13506. else
  13507. { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
  13508. signal(this, "overwriteToggle", this, this.state.overwrite);
  13509. },
  13510. hasFocus: function() { return this.display.input.getField() == activeElt() },
  13511. isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
  13512. scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
  13513. getScrollInfo: function() {
  13514. var scroller = this.display.scroller;
  13515. return {left: scroller.scrollLeft, top: scroller.scrollTop,
  13516. height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
  13517. width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
  13518. clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
  13519. },
  13520. scrollIntoView: methodOp(function(range, margin) {
  13521. if (range == null) {
  13522. range = {from: this.doc.sel.primary().head, to: null};
  13523. if (margin == null) { margin = this.options.cursorScrollMargin; }
  13524. } else if (typeof range == "number") {
  13525. range = {from: Pos(range, 0), to: null};
  13526. } else if (range.from == null) {
  13527. range = {from: range, to: null};
  13528. }
  13529. if (!range.to) { range.to = range.from; }
  13530. range.margin = margin || 0;
  13531. if (range.from.line != null) {
  13532. scrollToRange(this, range);
  13533. } else {
  13534. scrollToCoordsRange(this, range.from, range.to, range.margin);
  13535. }
  13536. }),
  13537. setSize: methodOp(function(width, height) {
  13538. var this$1 = this;
  13539. var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; };
  13540. if (width != null) { this.display.wrapper.style.width = interpret(width); }
  13541. if (height != null) { this.display.wrapper.style.height = interpret(height); }
  13542. if (this.options.lineWrapping) { clearLineMeasurementCache(this); }
  13543. var lineNo = this.display.viewFrom;
  13544. this.doc.iter(lineNo, this.display.viewTo, function (line) {
  13545. if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
  13546. { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } }
  13547. ++lineNo;
  13548. });
  13549. this.curOp.forceUpdate = true;
  13550. signal(this, "refresh", this);
  13551. }),
  13552. operation: function(f){return runInOp(this, f)},
  13553. startOperation: function(){return startOperation(this)},
  13554. endOperation: function(){return endOperation(this)},
  13555. refresh: methodOp(function() {
  13556. var oldHeight = this.display.cachedTextHeight;
  13557. regChange(this);
  13558. this.curOp.forceUpdate = true;
  13559. clearCaches(this);
  13560. scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
  13561. updateGutterSpace(this.display);
  13562. if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5 || this.options.lineWrapping)
  13563. { estimateLineHeights(this); }
  13564. signal(this, "refresh", this);
  13565. }),
  13566. swapDoc: methodOp(function(doc) {
  13567. var old = this.doc;
  13568. old.cm = null;
  13569. // Cancel the current text selection if any (#5821)
  13570. if (this.state.selectingText) { this.state.selectingText(); }
  13571. attachDoc(this, doc);
  13572. clearCaches(this);
  13573. this.display.input.reset();
  13574. scrollToCoords(this, doc.scrollLeft, doc.scrollTop);
  13575. this.curOp.forceScroll = true;
  13576. signalLater(this, "swapDoc", this, old);
  13577. return old
  13578. }),
  13579. phrase: function(phraseText) {
  13580. var phrases = this.options.phrases;
  13581. return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText
  13582. },
  13583. getInputField: function(){return this.display.input.getField()},
  13584. getWrapperElement: function(){return this.display.wrapper},
  13585. getScrollerElement: function(){return this.display.scroller},
  13586. getGutterElement: function(){return this.display.gutters}
  13587. };
  13588. eventMixin(CodeMirror);
  13589. CodeMirror.registerHelper = function(type, name, value) {
  13590. if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; }
  13591. helpers[type][name] = value;
  13592. };
  13593. CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
  13594. CodeMirror.registerHelper(type, name, value);
  13595. helpers[type]._global.push({pred: predicate, val: value});
  13596. };
  13597. }
  13598. // Used for horizontal relative motion. Dir is -1 or 1 (left or
  13599. // right), unit can be "char", "column" (like char, but doesn't
  13600. // cross line boundaries), "word" (across next word), or "group" (to
  13601. // the start of next group of word or non-word-non-whitespace
  13602. // chars). The visually param controls whether, in right-to-left
  13603. // text, direction 1 means to move towards the next index in the
  13604. // string, or towards the character to the right of the current
  13605. // position. The resulting position will have a hitSide=true
  13606. // property if it reached the end of the document.
  13607. function findPosH(doc, pos, dir, unit, visually) {
  13608. var oldPos = pos;
  13609. var origDir = dir;
  13610. var lineObj = getLine(doc, pos.line);
  13611. var lineDir = visually && doc.direction == "rtl" ? -dir : dir;
  13612. function findNextLine() {
  13613. var l = pos.line + lineDir;
  13614. if (l < doc.first || l >= doc.first + doc.size) { return false }
  13615. pos = new Pos(l, pos.ch, pos.sticky);
  13616. return lineObj = getLine(doc, l)
  13617. }
  13618. function moveOnce(boundToLine) {
  13619. var next;
  13620. if (visually) {
  13621. next = moveVisually(doc.cm, lineObj, pos, dir);
  13622. } else {
  13623. next = moveLogically(lineObj, pos, dir);
  13624. }
  13625. if (next == null) {
  13626. if (!boundToLine && findNextLine())
  13627. { pos = endOfLine(visually, doc.cm, lineObj, pos.line, lineDir); }
  13628. else
  13629. { return false }
  13630. } else {
  13631. pos = next;
  13632. }
  13633. return true
  13634. }
  13635. if (unit == "char") {
  13636. moveOnce();
  13637. } else if (unit == "column") {
  13638. moveOnce(true);
  13639. } else if (unit == "word" || unit == "group") {
  13640. var sawType = null, group = unit == "group";
  13641. var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
  13642. for (var first = true;; first = false) {
  13643. if (dir < 0 && !moveOnce(!first)) { break }
  13644. var cur = lineObj.text.charAt(pos.ch) || "\n";
  13645. var type = isWordChar(cur, helper) ? "w"
  13646. : group && cur == "\n" ? "n"
  13647. : !group || /\s/.test(cur) ? null
  13648. : "p";
  13649. if (group && !first && !type) { type = "s"; }
  13650. if (sawType && sawType != type) {
  13651. if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
  13652. break
  13653. }
  13654. if (type) { sawType = type; }
  13655. if (dir > 0 && !moveOnce(!first)) { break }
  13656. }
  13657. }
  13658. var result = skipAtomic(doc, pos, oldPos, origDir, true);
  13659. if (equalCursorPos(oldPos, result)) { result.hitSide = true; }
  13660. return result
  13661. }
  13662. // For relative vertical movement. Dir may be -1 or 1. Unit can be
  13663. // "page" or "line". The resulting position will have a hitSide=true
  13664. // property if it reached the end of the document.
  13665. function findPosV(cm, pos, dir, unit) {
  13666. var doc = cm.doc, x = pos.left, y;
  13667. if (unit == "page") {
  13668. var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
  13669. var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
  13670. y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
  13671. } else if (unit == "line") {
  13672. y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
  13673. }
  13674. var target;
  13675. for (;;) {
  13676. target = coordsChar(cm, x, y);
  13677. if (!target.outside) { break }
  13678. if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
  13679. y += dir * 5;
  13680. }
  13681. return target
  13682. }
  13683. // CONTENTEDITABLE INPUT STYLE
  13684. var ContentEditableInput = function(cm) {
  13685. this.cm = cm;
  13686. this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
  13687. this.polling = new Delayed();
  13688. this.composing = null;
  13689. this.gracePeriod = false;
  13690. this.readDOMTimeout = null;
  13691. };
  13692. ContentEditableInput.prototype.init = function (display) {
  13693. var this$1 = this;
  13694. var input = this, cm = input.cm;
  13695. var div = input.div = display.lineDiv;
  13696. disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize);
  13697. on(div, "paste", function (e) {
  13698. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
  13699. // IE doesn't fire input events, so we schedule a read for the pasted content in this way
  13700. if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); }
  13701. });
  13702. on(div, "compositionstart", function (e) {
  13703. this$1.composing = {data: e.data, done: false};
  13704. });
  13705. on(div, "compositionupdate", function (e) {
  13706. if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; }
  13707. });
  13708. on(div, "compositionend", function (e) {
  13709. if (this$1.composing) {
  13710. if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); }
  13711. this$1.composing.done = true;
  13712. }
  13713. });
  13714. on(div, "touchstart", function () { return input.forceCompositionEnd(); });
  13715. on(div, "input", function () {
  13716. if (!this$1.composing) { this$1.readFromDOMSoon(); }
  13717. });
  13718. function onCopyCut(e) {
  13719. if (signalDOMEvent(cm, e)) { return }
  13720. if (cm.somethingSelected()) {
  13721. setLastCopied({lineWise: false, text: cm.getSelections()});
  13722. if (e.type == "cut") { cm.replaceSelection("", null, "cut"); }
  13723. } else if (!cm.options.lineWiseCopyCut) {
  13724. return
  13725. } else {
  13726. var ranges = copyableRanges(cm);
  13727. setLastCopied({lineWise: true, text: ranges.text});
  13728. if (e.type == "cut") {
  13729. cm.operation(function () {
  13730. cm.setSelections(ranges.ranges, 0, sel_dontScroll);
  13731. cm.replaceSelection("", null, "cut");
  13732. });
  13733. }
  13734. }
  13735. if (e.clipboardData) {
  13736. e.clipboardData.clearData();
  13737. var content = lastCopied.text.join("\n");
  13738. // iOS exposes the clipboard API, but seems to discard content inserted into it
  13739. e.clipboardData.setData("Text", content);
  13740. if (e.clipboardData.getData("Text") == content) {
  13741. e.preventDefault();
  13742. return
  13743. }
  13744. }
  13745. // Old-fashioned briefly-focus-a-textarea hack
  13746. var kludge = hiddenTextarea(), te = kludge.firstChild;
  13747. cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
  13748. te.value = lastCopied.text.join("\n");
  13749. var hadFocus = document.activeElement;
  13750. selectInput(te);
  13751. setTimeout(function () {
  13752. cm.display.lineSpace.removeChild(kludge);
  13753. hadFocus.focus();
  13754. if (hadFocus == div) { input.showPrimarySelection(); }
  13755. }, 50);
  13756. }
  13757. on(div, "copy", onCopyCut);
  13758. on(div, "cut", onCopyCut);
  13759. };
  13760. ContentEditableInput.prototype.screenReaderLabelChanged = function (label) {
  13761. // Label for screenreaders, accessibility
  13762. if(label) {
  13763. this.div.setAttribute('aria-label', label);
  13764. } else {
  13765. this.div.removeAttribute('aria-label');
  13766. }
  13767. };
  13768. ContentEditableInput.prototype.prepareSelection = function () {
  13769. var result = prepareSelection(this.cm, false);
  13770. result.focus = document.activeElement == this.div;
  13771. return result
  13772. };
  13773. ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
  13774. if (!info || !this.cm.display.view.length) { return }
  13775. if (info.focus || takeFocus) { this.showPrimarySelection(); }
  13776. this.showMultipleSelections(info);
  13777. };
  13778. ContentEditableInput.prototype.getSelection = function () {
  13779. return this.cm.display.wrapper.ownerDocument.getSelection()
  13780. };
  13781. ContentEditableInput.prototype.showPrimarySelection = function () {
  13782. var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary();
  13783. var from = prim.from(), to = prim.to();
  13784. if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
  13785. sel.removeAllRanges();
  13786. return
  13787. }
  13788. var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  13789. var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
  13790. if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
  13791. cmp(minPos(curAnchor, curFocus), from) == 0 &&
  13792. cmp(maxPos(curAnchor, curFocus), to) == 0)
  13793. { return }
  13794. var view = cm.display.view;
  13795. var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
  13796. {node: view[0].measure.map[2], offset: 0};
  13797. var end = to.line < cm.display.viewTo && posToDOM(cm, to);
  13798. if (!end) {
  13799. var measure = view[view.length - 1].measure;
  13800. var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
  13801. end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]};
  13802. }
  13803. if (!start || !end) {
  13804. sel.removeAllRanges();
  13805. return
  13806. }
  13807. var old = sel.rangeCount && sel.getRangeAt(0), rng;
  13808. try { rng = range(start.node, start.offset, end.offset, end.node); }
  13809. catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
  13810. if (rng) {
  13811. if (!gecko && cm.state.focused) {
  13812. sel.collapse(start.node, start.offset);
  13813. if (!rng.collapsed) {
  13814. sel.removeAllRanges();
  13815. sel.addRange(rng);
  13816. }
  13817. } else {
  13818. sel.removeAllRanges();
  13819. sel.addRange(rng);
  13820. }
  13821. if (old && sel.anchorNode == null) { sel.addRange(old); }
  13822. else if (gecko) { this.startGracePeriod(); }
  13823. }
  13824. this.rememberSelection();
  13825. };
  13826. ContentEditableInput.prototype.startGracePeriod = function () {
  13827. var this$1 = this;
  13828. clearTimeout(this.gracePeriod);
  13829. this.gracePeriod = setTimeout(function () {
  13830. this$1.gracePeriod = false;
  13831. if (this$1.selectionChanged())
  13832. { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); }
  13833. }, 20);
  13834. };
  13835. ContentEditableInput.prototype.showMultipleSelections = function (info) {
  13836. removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
  13837. removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
  13838. };
  13839. ContentEditableInput.prototype.rememberSelection = function () {
  13840. var sel = this.getSelection();
  13841. this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
  13842. this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
  13843. };
  13844. ContentEditableInput.prototype.selectionInEditor = function () {
  13845. var sel = this.getSelection();
  13846. if (!sel.rangeCount) { return false }
  13847. var node = sel.getRangeAt(0).commonAncestorContainer;
  13848. return contains(this.div, node)
  13849. };
  13850. ContentEditableInput.prototype.focus = function () {
  13851. if (this.cm.options.readOnly != "nocursor") {
  13852. if (!this.selectionInEditor() || document.activeElement != this.div)
  13853. { this.showSelection(this.prepareSelection(), true); }
  13854. this.div.focus();
  13855. }
  13856. };
  13857. ContentEditableInput.prototype.blur = function () { this.div.blur(); };
  13858. ContentEditableInput.prototype.getField = function () { return this.div };
  13859. ContentEditableInput.prototype.supportsTouch = function () { return true };
  13860. ContentEditableInput.prototype.receivedFocus = function () {
  13861. var input = this;
  13862. if (this.selectionInEditor())
  13863. { this.pollSelection(); }
  13864. else
  13865. { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); }
  13866. function poll() {
  13867. if (input.cm.state.focused) {
  13868. input.pollSelection();
  13869. input.polling.set(input.cm.options.pollInterval, poll);
  13870. }
  13871. }
  13872. this.polling.set(this.cm.options.pollInterval, poll);
  13873. };
  13874. ContentEditableInput.prototype.selectionChanged = function () {
  13875. var sel = this.getSelection();
  13876. return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
  13877. sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
  13878. };
  13879. ContentEditableInput.prototype.pollSelection = function () {
  13880. if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
  13881. var sel = this.getSelection(), cm = this.cm;
  13882. // On Android Chrome (version 56, at least), backspacing into an
  13883. // uneditable block element will put the cursor in that element,
  13884. // and then, because it's not editable, hide the virtual keyboard.
  13885. // Because Android doesn't allow us to actually detect backspace
  13886. // presses in a sane way, this code checks for when that happens
  13887. // and simulates a backspace press in this case.
  13888. if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) {
  13889. this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs});
  13890. this.blur();
  13891. this.focus();
  13892. return
  13893. }
  13894. if (this.composing) { return }
  13895. this.rememberSelection();
  13896. var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  13897. var head = domToPos(cm, sel.focusNode, sel.focusOffset);
  13898. if (anchor && head) { runInOp(cm, function () {
  13899. setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
  13900. if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; }
  13901. }); }
  13902. };
  13903. ContentEditableInput.prototype.pollContent = function () {
  13904. if (this.readDOMTimeout != null) {
  13905. clearTimeout(this.readDOMTimeout);
  13906. this.readDOMTimeout = null;
  13907. }
  13908. var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
  13909. var from = sel.from(), to = sel.to();
  13910. if (from.ch == 0 && from.line > cm.firstLine())
  13911. { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); }
  13912. if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
  13913. { to = Pos(to.line + 1, 0); }
  13914. if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
  13915. var fromIndex, fromLine, fromNode;
  13916. if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
  13917. fromLine = lineNo(display.view[0].line);
  13918. fromNode = display.view[0].node;
  13919. } else {
  13920. fromLine = lineNo(display.view[fromIndex].line);
  13921. fromNode = display.view[fromIndex - 1].node.nextSibling;
  13922. }
  13923. var toIndex = findViewIndex(cm, to.line);
  13924. var toLine, toNode;
  13925. if (toIndex == display.view.length - 1) {
  13926. toLine = display.viewTo - 1;
  13927. toNode = display.lineDiv.lastChild;
  13928. } else {
  13929. toLine = lineNo(display.view[toIndex + 1].line) - 1;
  13930. toNode = display.view[toIndex + 1].node.previousSibling;
  13931. }
  13932. if (!fromNode) { return false }
  13933. var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
  13934. var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
  13935. while (newText.length > 1 && oldText.length > 1) {
  13936. if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
  13937. else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
  13938. else { break }
  13939. }
  13940. var cutFront = 0, cutEnd = 0;
  13941. var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
  13942. while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
  13943. { ++cutFront; }
  13944. var newBot = lst(newText), oldBot = lst(oldText);
  13945. var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
  13946. oldBot.length - (oldText.length == 1 ? cutFront : 0));
  13947. while (cutEnd < maxCutEnd &&
  13948. newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
  13949. { ++cutEnd; }
  13950. // Try to move start of change to start of selection if ambiguous
  13951. if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
  13952. while (cutFront && cutFront > from.ch &&
  13953. newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
  13954. cutFront--;
  13955. cutEnd++;
  13956. }
  13957. }
  13958. newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
  13959. newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
  13960. var chFrom = Pos(fromLine, cutFront);
  13961. var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
  13962. if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
  13963. replaceRange(cm.doc, newText, chFrom, chTo, "+input");
  13964. return true
  13965. }
  13966. };
  13967. ContentEditableInput.prototype.ensurePolled = function () {
  13968. this.forceCompositionEnd();
  13969. };
  13970. ContentEditableInput.prototype.reset = function () {
  13971. this.forceCompositionEnd();
  13972. };
  13973. ContentEditableInput.prototype.forceCompositionEnd = function () {
  13974. if (!this.composing) { return }
  13975. clearTimeout(this.readDOMTimeout);
  13976. this.composing = null;
  13977. this.updateFromDOM();
  13978. this.div.blur();
  13979. this.div.focus();
  13980. };
  13981. ContentEditableInput.prototype.readFromDOMSoon = function () {
  13982. var this$1 = this;
  13983. if (this.readDOMTimeout != null) { return }
  13984. this.readDOMTimeout = setTimeout(function () {
  13985. this$1.readDOMTimeout = null;
  13986. if (this$1.composing) {
  13987. if (this$1.composing.done) { this$1.composing = null; }
  13988. else { return }
  13989. }
  13990. this$1.updateFromDOM();
  13991. }, 80);
  13992. };
  13993. ContentEditableInput.prototype.updateFromDOM = function () {
  13994. var this$1 = this;
  13995. if (this.cm.isReadOnly() || !this.pollContent())
  13996. { runInOp(this.cm, function () { return regChange(this$1.cm); }); }
  13997. };
  13998. ContentEditableInput.prototype.setUneditable = function (node) {
  13999. node.contentEditable = "false";
  14000. };
  14001. ContentEditableInput.prototype.onKeyPress = function (e) {
  14002. if (e.charCode == 0 || this.composing) { return }
  14003. e.preventDefault();
  14004. if (!this.cm.isReadOnly())
  14005. { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); }
  14006. };
  14007. ContentEditableInput.prototype.readOnlyChanged = function (val) {
  14008. this.div.contentEditable = String(val != "nocursor");
  14009. };
  14010. ContentEditableInput.prototype.onContextMenu = function () {};
  14011. ContentEditableInput.prototype.resetPosition = function () {};
  14012. ContentEditableInput.prototype.needsContentAttribute = true;
  14013. function posToDOM(cm, pos) {
  14014. var view = findViewForLine(cm, pos.line);
  14015. if (!view || view.hidden) { return null }
  14016. var line = getLine(cm.doc, pos.line);
  14017. var info = mapFromLineView(view, line, pos.line);
  14018. var order = getOrder(line, cm.doc.direction), side = "left";
  14019. if (order) {
  14020. var partPos = getBidiPartAt(order, pos.ch);
  14021. side = partPos % 2 ? "right" : "left";
  14022. }
  14023. var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
  14024. result.offset = result.collapse == "right" ? result.end : result.start;
  14025. return result
  14026. }
  14027. function isInGutter(node) {
  14028. for (var scan = node; scan; scan = scan.parentNode)
  14029. { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
  14030. return false
  14031. }
  14032. function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
  14033. function domTextBetween(cm, from, to, fromLine, toLine) {
  14034. var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false;
  14035. function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
  14036. function close() {
  14037. if (closing) {
  14038. text += lineSep;
  14039. if (extraLinebreak) { text += lineSep; }
  14040. closing = extraLinebreak = false;
  14041. }
  14042. }
  14043. function addText(str) {
  14044. if (str) {
  14045. close();
  14046. text += str;
  14047. }
  14048. }
  14049. function walk(node) {
  14050. if (node.nodeType == 1) {
  14051. var cmText = node.getAttribute("cm-text");
  14052. if (cmText) {
  14053. addText(cmText);
  14054. return
  14055. }
  14056. var markerID = node.getAttribute("cm-marker"), range;
  14057. if (markerID) {
  14058. var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
  14059. if (found.length && (range = found[0].find(0)))
  14060. { addText(getBetween(cm.doc, range.from, range.to).join(lineSep)); }
  14061. return
  14062. }
  14063. if (node.getAttribute("contenteditable") == "false") { return }
  14064. var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
  14065. if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
  14066. if (isBlock) { close(); }
  14067. for (var i = 0; i < node.childNodes.length; i++)
  14068. { walk(node.childNodes[i]); }
  14069. if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true; }
  14070. if (isBlock) { closing = true; }
  14071. } else if (node.nodeType == 3) {
  14072. addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
  14073. }
  14074. }
  14075. for (;;) {
  14076. walk(from);
  14077. if (from == to) { break }
  14078. from = from.nextSibling;
  14079. extraLinebreak = false;
  14080. }
  14081. return text
  14082. }
  14083. function domToPos(cm, node, offset) {
  14084. var lineNode;
  14085. if (node == cm.display.lineDiv) {
  14086. lineNode = cm.display.lineDiv.childNodes[offset];
  14087. if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
  14088. node = null; offset = 0;
  14089. } else {
  14090. for (lineNode = node;; lineNode = lineNode.parentNode) {
  14091. if (!lineNode || lineNode == cm.display.lineDiv) { return null }
  14092. if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
  14093. }
  14094. }
  14095. for (var i = 0; i < cm.display.view.length; i++) {
  14096. var lineView = cm.display.view[i];
  14097. if (lineView.node == lineNode)
  14098. { return locateNodeInLineView(lineView, node, offset) }
  14099. }
  14100. }
  14101. function locateNodeInLineView(lineView, node, offset) {
  14102. var wrapper = lineView.text.firstChild, bad = false;
  14103. if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
  14104. if (node == wrapper) {
  14105. bad = true;
  14106. node = wrapper.childNodes[offset];
  14107. offset = 0;
  14108. if (!node) {
  14109. var line = lineView.rest ? lst(lineView.rest) : lineView.line;
  14110. return badPos(Pos(lineNo(line), line.text.length), bad)
  14111. }
  14112. }
  14113. var textNode = node.nodeType == 3 ? node : null, topNode = node;
  14114. if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
  14115. textNode = node.firstChild;
  14116. if (offset) { offset = textNode.nodeValue.length; }
  14117. }
  14118. while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; }
  14119. var measure = lineView.measure, maps = measure.maps;
  14120. function find(textNode, topNode, offset) {
  14121. for (var i = -1; i < (maps ? maps.length : 0); i++) {
  14122. var map = i < 0 ? measure.map : maps[i];
  14123. for (var j = 0; j < map.length; j += 3) {
  14124. var curNode = map[j + 2];
  14125. if (curNode == textNode || curNode == topNode) {
  14126. var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
  14127. var ch = map[j] + offset;
  14128. if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)]; }
  14129. return Pos(line, ch)
  14130. }
  14131. }
  14132. }
  14133. }
  14134. var found = find(textNode, topNode, offset);
  14135. if (found) { return badPos(found, bad) }
  14136. // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
  14137. for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
  14138. found = find(after, after.firstChild, 0);
  14139. if (found)
  14140. { return badPos(Pos(found.line, found.ch - dist), bad) }
  14141. else
  14142. { dist += after.textContent.length; }
  14143. }
  14144. for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
  14145. found = find(before, before.firstChild, -1);
  14146. if (found)
  14147. { return badPos(Pos(found.line, found.ch + dist$1), bad) }
  14148. else
  14149. { dist$1 += before.textContent.length; }
  14150. }
  14151. }
  14152. // TEXTAREA INPUT STYLE
  14153. var TextareaInput = function(cm) {
  14154. this.cm = cm;
  14155. // See input.poll and input.reset
  14156. this.prevInput = "";
  14157. // Flag that indicates whether we expect input to appear real soon
  14158. // now (after some event like 'keypress' or 'input') and are
  14159. // polling intensively.
  14160. this.pollingFast = false;
  14161. // Self-resetting timeout for the poller
  14162. this.polling = new Delayed();
  14163. // Used to work around IE issue with selection being forgotten when focus moves away from textarea
  14164. this.hasSelection = false;
  14165. this.composing = null;
  14166. };
  14167. TextareaInput.prototype.init = function (display) {
  14168. var this$1 = this;
  14169. var input = this, cm = this.cm;
  14170. this.createField(display);
  14171. var te = this.textarea;
  14172. display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
  14173. // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
  14174. if (ios) { te.style.width = "0px"; }
  14175. on(te, "input", function () {
  14176. if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; }
  14177. input.poll();
  14178. });
  14179. on(te, "paste", function (e) {
  14180. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
  14181. cm.state.pasteIncoming = +new Date;
  14182. input.fastPoll();
  14183. });
  14184. function prepareCopyCut(e) {
  14185. if (signalDOMEvent(cm, e)) { return }
  14186. if (cm.somethingSelected()) {
  14187. setLastCopied({lineWise: false, text: cm.getSelections()});
  14188. } else if (!cm.options.lineWiseCopyCut) {
  14189. return
  14190. } else {
  14191. var ranges = copyableRanges(cm);
  14192. setLastCopied({lineWise: true, text: ranges.text});
  14193. if (e.type == "cut") {
  14194. cm.setSelections(ranges.ranges, null, sel_dontScroll);
  14195. } else {
  14196. input.prevInput = "";
  14197. te.value = ranges.text.join("\n");
  14198. selectInput(te);
  14199. }
  14200. }
  14201. if (e.type == "cut") { cm.state.cutIncoming = +new Date; }
  14202. }
  14203. on(te, "cut", prepareCopyCut);
  14204. on(te, "copy", prepareCopyCut);
  14205. on(display.scroller, "paste", function (e) {
  14206. if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
  14207. if (!te.dispatchEvent) {
  14208. cm.state.pasteIncoming = +new Date;
  14209. input.focus();
  14210. return
  14211. }
  14212. // Pass the `paste` event to the textarea so it's handled by its event listener.
  14213. var event = new Event("paste");
  14214. event.clipboardData = e.clipboardData;
  14215. te.dispatchEvent(event);
  14216. });
  14217. // Prevent normal selection in the editor (we handle our own)
  14218. on(display.lineSpace, "selectstart", function (e) {
  14219. if (!eventInWidget(display, e)) { e_preventDefault(e); }
  14220. });
  14221. on(te, "compositionstart", function () {
  14222. var start = cm.getCursor("from");
  14223. if (input.composing) { input.composing.range.clear(); }
  14224. input.composing = {
  14225. start: start,
  14226. range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
  14227. };
  14228. });
  14229. on(te, "compositionend", function () {
  14230. if (input.composing) {
  14231. input.poll();
  14232. input.composing.range.clear();
  14233. input.composing = null;
  14234. }
  14235. });
  14236. };
  14237. TextareaInput.prototype.createField = function (_display) {
  14238. // Wraps and hides input textarea
  14239. this.wrapper = hiddenTextarea();
  14240. // The semihidden textarea that is focused when the editor is
  14241. // focused, and receives input.
  14242. this.textarea = this.wrapper.firstChild;
  14243. };
  14244. TextareaInput.prototype.screenReaderLabelChanged = function (label) {
  14245. // Label for screenreaders, accessibility
  14246. if(label) {
  14247. this.textarea.setAttribute('aria-label', label);
  14248. } else {
  14249. this.textarea.removeAttribute('aria-label');
  14250. }
  14251. };
  14252. TextareaInput.prototype.prepareSelection = function () {
  14253. // Redraw the selection and/or cursor
  14254. var cm = this.cm, display = cm.display, doc = cm.doc;
  14255. var result = prepareSelection(cm);
  14256. // Move the hidden textarea near the cursor to prevent scrolling artifacts
  14257. if (cm.options.moveInputWithCursor) {
  14258. var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
  14259. var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
  14260. result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
  14261. headPos.top + lineOff.top - wrapOff.top));
  14262. result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
  14263. headPos.left + lineOff.left - wrapOff.left));
  14264. }
  14265. return result
  14266. };
  14267. TextareaInput.prototype.showSelection = function (drawn) {
  14268. var cm = this.cm, display = cm.display;
  14269. removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
  14270. removeChildrenAndAdd(display.selectionDiv, drawn.selection);
  14271. if (drawn.teTop != null) {
  14272. this.wrapper.style.top = drawn.teTop + "px";
  14273. this.wrapper.style.left = drawn.teLeft + "px";
  14274. }
  14275. };
  14276. // Reset the input to correspond to the selection (or to be empty,
  14277. // when not typing and nothing is selected)
  14278. TextareaInput.prototype.reset = function (typing) {
  14279. if (this.contextMenuPending || this.composing) { return }
  14280. var cm = this.cm;
  14281. if (cm.somethingSelected()) {
  14282. this.prevInput = "";
  14283. var content = cm.getSelection();
  14284. this.textarea.value = content;
  14285. if (cm.state.focused) { selectInput(this.textarea); }
  14286. if (ie && ie_version >= 9) { this.hasSelection = content; }
  14287. } else if (!typing) {
  14288. this.prevInput = this.textarea.value = "";
  14289. if (ie && ie_version >= 9) { this.hasSelection = null; }
  14290. }
  14291. };
  14292. TextareaInput.prototype.getField = function () { return this.textarea };
  14293. TextareaInput.prototype.supportsTouch = function () { return false };
  14294. TextareaInput.prototype.focus = function () {
  14295. if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
  14296. try { this.textarea.focus(); }
  14297. catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
  14298. }
  14299. };
  14300. TextareaInput.prototype.blur = function () { this.textarea.blur(); };
  14301. TextareaInput.prototype.resetPosition = function () {
  14302. this.wrapper.style.top = this.wrapper.style.left = 0;
  14303. };
  14304. TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); };
  14305. // Poll for input changes, using the normal rate of polling. This
  14306. // runs as long as the editor is focused.
  14307. TextareaInput.prototype.slowPoll = function () {
  14308. var this$1 = this;
  14309. if (this.pollingFast) { return }
  14310. this.polling.set(this.cm.options.pollInterval, function () {
  14311. this$1.poll();
  14312. if (this$1.cm.state.focused) { this$1.slowPoll(); }
  14313. });
  14314. };
  14315. // When an event has just come in that is likely to add or change
  14316. // something in the input textarea, we poll faster, to ensure that
  14317. // the change appears on the screen quickly.
  14318. TextareaInput.prototype.fastPoll = function () {
  14319. var missed = false, input = this;
  14320. input.pollingFast = true;
  14321. function p() {
  14322. var changed = input.poll();
  14323. if (!changed && !missed) {missed = true; input.polling.set(60, p);}
  14324. else {input.pollingFast = false; input.slowPoll();}
  14325. }
  14326. input.polling.set(20, p);
  14327. };
  14328. // Read input from the textarea, and update the document to match.
  14329. // When something is selected, it is present in the textarea, and
  14330. // selected (unless it is huge, in which case a placeholder is
  14331. // used). When nothing is selected, the cursor sits after previously
  14332. // seen text (can be empty), which is stored in prevInput (we must
  14333. // not reset the textarea when typing, because that breaks IME).
  14334. TextareaInput.prototype.poll = function () {
  14335. var this$1 = this;
  14336. var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
  14337. // Since this is called a *lot*, try to bail out as cheaply as
  14338. // possible when it is clear that nothing happened. hasSelection
  14339. // will be the case when there is a lot of text in the textarea,
  14340. // in which case reading its value would be expensive.
  14341. if (this.contextMenuPending || !cm.state.focused ||
  14342. (hasSelection(input) && !prevInput && !this.composing) ||
  14343. cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
  14344. { return false }
  14345. var text = input.value;
  14346. // If nothing changed, bail.
  14347. if (text == prevInput && !cm.somethingSelected()) { return false }
  14348. // Work around nonsensical selection resetting in IE9/10, and
  14349. // inexplicable appearance of private area unicode characters on
  14350. // some key combos in Mac (#2689).
  14351. if (ie && ie_version >= 9 && this.hasSelection === text ||
  14352. mac && /[\uf700-\uf7ff]/.test(text)) {
  14353. cm.display.input.reset();
  14354. return false
  14355. }
  14356. if (cm.doc.sel == cm.display.selForContextMenu) {
  14357. var first = text.charCodeAt(0);
  14358. if (first == 0x200b && !prevInput) { prevInput = "\u200b"; }
  14359. if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
  14360. }
  14361. // Find the part of the input that is actually new
  14362. var same = 0, l = Math.min(prevInput.length, text.length);
  14363. while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; }
  14364. runInOp(cm, function () {
  14365. applyTextInput(cm, text.slice(same), prevInput.length - same,
  14366. null, this$1.composing ? "*compose" : null);
  14367. // Don't leave long text in the textarea, since it makes further polling slow
  14368. if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; }
  14369. else { this$1.prevInput = text; }
  14370. if (this$1.composing) {
  14371. this$1.composing.range.clear();
  14372. this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
  14373. {className: "CodeMirror-composing"});
  14374. }
  14375. });
  14376. return true
  14377. };
  14378. TextareaInput.prototype.ensurePolled = function () {
  14379. if (this.pollingFast && this.poll()) { this.pollingFast = false; }
  14380. };
  14381. TextareaInput.prototype.onKeyPress = function () {
  14382. if (ie && ie_version >= 9) { this.hasSelection = null; }
  14383. this.fastPoll();
  14384. };
  14385. TextareaInput.prototype.onContextMenu = function (e) {
  14386. var input = this, cm = input.cm, display = cm.display, te = input.textarea;
  14387. if (input.contextMenuPending) { input.contextMenuPending(); }
  14388. var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
  14389. if (!pos || presto) { return } // Opera is difficult.
  14390. // Reset the current text selection only if the click is done outside of the selection
  14391. // and 'resetSelectionOnContextMenu' option is true.
  14392. var reset = cm.options.resetSelectionOnContextMenu;
  14393. if (reset && cm.doc.sel.contains(pos) == -1)
  14394. { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }
  14395. var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
  14396. var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect();
  14397. input.wrapper.style.cssText = "position: static";
  14398. te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
  14399. var oldScrollY;
  14400. if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712)
  14401. display.input.focus();
  14402. if (webkit) { window.scrollTo(null, oldScrollY); }
  14403. display.input.reset();
  14404. // Adds "Select all" to context menu in FF
  14405. if (!cm.somethingSelected()) { te.value = input.prevInput = " "; }
  14406. input.contextMenuPending = rehide;
  14407. display.selForContextMenu = cm.doc.sel;
  14408. clearTimeout(display.detectingSelectAll);
  14409. // Select-all will be greyed out if there's nothing to select, so
  14410. // this adds a zero-width space so that we can later check whether
  14411. // it got selected.
  14412. function prepareSelectAllHack() {
  14413. if (te.selectionStart != null) {
  14414. var selected = cm.somethingSelected();
  14415. var extval = "\u200b" + (selected ? te.value : "");
  14416. te.value = "\u21da"; // Used to catch context-menu undo
  14417. te.value = extval;
  14418. input.prevInput = selected ? "" : "\u200b";
  14419. te.selectionStart = 1; te.selectionEnd = extval.length;
  14420. // Re-set this, in case some other handler touched the
  14421. // selection in the meantime.
  14422. display.selForContextMenu = cm.doc.sel;
  14423. }
  14424. }
  14425. function rehide() {
  14426. if (input.contextMenuPending != rehide) { return }
  14427. input.contextMenuPending = false;
  14428. input.wrapper.style.cssText = oldWrapperCSS;
  14429. te.style.cssText = oldCSS;
  14430. if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); }
  14431. // Try to detect the user choosing select-all
  14432. if (te.selectionStart != null) {
  14433. if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); }
  14434. var i = 0, poll = function () {
  14435. if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
  14436. te.selectionEnd > 0 && input.prevInput == "\u200b") {
  14437. operation(cm, selectAll)(cm);
  14438. } else if (i++ < 10) {
  14439. display.detectingSelectAll = setTimeout(poll, 500);
  14440. } else {
  14441. display.selForContextMenu = null;
  14442. display.input.reset();
  14443. }
  14444. };
  14445. display.detectingSelectAll = setTimeout(poll, 200);
  14446. }
  14447. }
  14448. if (ie && ie_version >= 9) { prepareSelectAllHack(); }
  14449. if (captureRightClick) {
  14450. e_stop(e);
  14451. var mouseup = function () {
  14452. off(window, "mouseup", mouseup);
  14453. setTimeout(rehide, 20);
  14454. };
  14455. on(window, "mouseup", mouseup);
  14456. } else {
  14457. setTimeout(rehide, 50);
  14458. }
  14459. };
  14460. TextareaInput.prototype.readOnlyChanged = function (val) {
  14461. if (!val) { this.reset(); }
  14462. this.textarea.disabled = val == "nocursor";
  14463. };
  14464. TextareaInput.prototype.setUneditable = function () {};
  14465. TextareaInput.prototype.needsContentAttribute = false;
  14466. function fromTextArea(textarea, options) {
  14467. options = options ? copyObj(options) : {};
  14468. options.value = textarea.value;
  14469. if (!options.tabindex && textarea.tabIndex)
  14470. { options.tabindex = textarea.tabIndex; }
  14471. if (!options.placeholder && textarea.placeholder)
  14472. { options.placeholder = textarea.placeholder; }
  14473. // Set autofocus to true if this textarea is focused, or if it has
  14474. // autofocus and no other element is focused.
  14475. if (options.autofocus == null) {
  14476. var hasFocus = activeElt();
  14477. options.autofocus = hasFocus == textarea ||
  14478. textarea.getAttribute("autofocus") != null && hasFocus == document.body;
  14479. }
  14480. function save() {textarea.value = cm.getValue();}
  14481. var realSubmit;
  14482. if (textarea.form) {
  14483. on(textarea.form, "submit", save);
  14484. // Deplorable hack to make the submit method do the right thing.
  14485. if (!options.leaveSubmitMethodAlone) {
  14486. var form = textarea.form;
  14487. realSubmit = form.submit;
  14488. try {
  14489. var wrappedSubmit = form.submit = function () {
  14490. save();
  14491. form.submit = realSubmit;
  14492. form.submit();
  14493. form.submit = wrappedSubmit;
  14494. };
  14495. } catch(e) {}
  14496. }
  14497. }
  14498. options.finishInit = function (cm) {
  14499. cm.save = save;
  14500. cm.getTextArea = function () { return textarea; };
  14501. cm.toTextArea = function () {
  14502. cm.toTextArea = isNaN; // Prevent this from being ran twice
  14503. save();
  14504. textarea.parentNode.removeChild(cm.getWrapperElement());
  14505. textarea.style.display = "";
  14506. if (textarea.form) {
  14507. off(textarea.form, "submit", save);
  14508. if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function")
  14509. { textarea.form.submit = realSubmit; }
  14510. }
  14511. };
  14512. };
  14513. textarea.style.display = "none";
  14514. var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
  14515. options);
  14516. return cm
  14517. }
  14518. function addLegacyProps(CodeMirror) {
  14519. CodeMirror.off = off;
  14520. CodeMirror.on = on;
  14521. CodeMirror.wheelEventPixels = wheelEventPixels;
  14522. CodeMirror.Doc = Doc;
  14523. CodeMirror.splitLines = splitLinesAuto;
  14524. CodeMirror.countColumn = countColumn;
  14525. CodeMirror.findColumn = findColumn;
  14526. CodeMirror.isWordChar = isWordCharBasic;
  14527. CodeMirror.Pass = Pass;
  14528. CodeMirror.signal = signal;
  14529. CodeMirror.Line = Line;
  14530. CodeMirror.changeEnd = changeEnd;
  14531. CodeMirror.scrollbarModel = scrollbarModel;
  14532. CodeMirror.Pos = Pos;
  14533. CodeMirror.cmpPos = cmp;
  14534. CodeMirror.modes = modes;
  14535. CodeMirror.mimeModes = mimeModes;
  14536. CodeMirror.resolveMode = resolveMode;
  14537. CodeMirror.getMode = getMode;
  14538. CodeMirror.modeExtensions = modeExtensions;
  14539. CodeMirror.extendMode = extendMode;
  14540. CodeMirror.copyState = copyState;
  14541. CodeMirror.startState = startState;
  14542. CodeMirror.innerMode = innerMode;
  14543. CodeMirror.commands = commands;
  14544. CodeMirror.keyMap = keyMap;
  14545. CodeMirror.keyName = keyName;
  14546. CodeMirror.isModifierKey = isModifierKey;
  14547. CodeMirror.lookupKey = lookupKey;
  14548. CodeMirror.normalizeKeyMap = normalizeKeyMap;
  14549. CodeMirror.StringStream = StringStream;
  14550. CodeMirror.SharedTextMarker = SharedTextMarker;
  14551. CodeMirror.TextMarker = TextMarker;
  14552. CodeMirror.LineWidget = LineWidget;
  14553. CodeMirror.e_preventDefault = e_preventDefault;
  14554. CodeMirror.e_stopPropagation = e_stopPropagation;
  14555. CodeMirror.e_stop = e_stop;
  14556. CodeMirror.addClass = addClass;
  14557. CodeMirror.contains = contains;
  14558. CodeMirror.rmClass = rmClass;
  14559. CodeMirror.keyNames = keyNames;
  14560. }
  14561. // EDITOR CONSTRUCTOR
  14562. defineOptions(CodeMirror);
  14563. addEditorMethods(CodeMirror);
  14564. // Set up methods on CodeMirror's prototype to redirect to the editor's document.
  14565. var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
  14566. for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
  14567. { CodeMirror.prototype[prop] = (function(method) {
  14568. return function() {return method.apply(this.doc, arguments)}
  14569. })(Doc.prototype[prop]); } }
  14570. eventMixin(Doc);
  14571. CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
  14572. // Extra arguments are stored as the mode's dependencies, which is
  14573. // used by (legacy) mechanisms like loadmode.js to automatically
  14574. // load a mode. (Preferred mechanism is the require/define calls.)
  14575. CodeMirror.defineMode = function(name/*, mode, …*/) {
  14576. if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; }
  14577. defineMode.apply(this, arguments);
  14578. };
  14579. CodeMirror.defineMIME = defineMIME;
  14580. // Minimal default mode.
  14581. CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
  14582. CodeMirror.defineMIME("text/plain", "null");
  14583. // EXTENSIONS
  14584. CodeMirror.defineExtension = function (name, func) {
  14585. CodeMirror.prototype[name] = func;
  14586. };
  14587. CodeMirror.defineDocExtension = function (name, func) {
  14588. Doc.prototype[name] = func;
  14589. };
  14590. CodeMirror.fromTextArea = fromTextArea;
  14591. addLegacyProps(CodeMirror);
  14592. CodeMirror.version = "5.53.2";
  14593. return CodeMirror;
  14594. })));
  14595. /***/ }),
  14596. /***/ "a719":
  14597. /***/ (function(module, exports) {
  14598. module.exports = function (it) {
  14599. return typeof it === 'object' ? it !== null : typeof it === 'function';
  14600. };
  14601. /***/ }),
  14602. /***/ "a8a2":
  14603. /***/ (function(module, exports) {
  14604. function getDefaults() {
  14605. return {
  14606. baseUrl: null,
  14607. breaks: false,
  14608. gfm: true,
  14609. headerIds: true,
  14610. headerPrefix: '',
  14611. highlight: null,
  14612. langPrefix: 'language-',
  14613. mangle: true,
  14614. pedantic: false,
  14615. renderer: null,
  14616. sanitize: false,
  14617. sanitizer: null,
  14618. silent: false,
  14619. smartLists: false,
  14620. smartypants: false,
  14621. tokenizer: null,
  14622. xhtml: false
  14623. };
  14624. }
  14625. function changeDefaults(newDefaults) {
  14626. module.exports.defaults = newDefaults;
  14627. }
  14628. module.exports = {
  14629. defaults: getDefaults(),
  14630. getDefaults,
  14631. changeDefaults
  14632. };
  14633. /***/ }),
  14634. /***/ "aa6b":
  14635. /***/ (function(module, exports, __webpack_require__) {
  14636. var DESCRIPTORS = __webpack_require__("1e2c");
  14637. var propertyIsEnumerableModule = __webpack_require__("ef71");
  14638. var createPropertyDescriptor = __webpack_require__("38b9");
  14639. var toIndexedObject = __webpack_require__("da10");
  14640. var toPrimitive = __webpack_require__("9f67");
  14641. var has = __webpack_require__("faa8");
  14642. var IE8_DOM_DEFINE = __webpack_require__("2039");
  14643. var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  14644. // `Object.getOwnPropertyDescriptor` method
  14645. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
  14646. exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  14647. O = toIndexedObject(O);
  14648. P = toPrimitive(P, true);
  14649. if (IE8_DOM_DEFINE) try {
  14650. return nativeGetOwnPropertyDescriptor(O, P);
  14651. } catch (error) { /* empty */ }
  14652. if (has(O, P)) return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]);
  14653. };
  14654. /***/ }),
  14655. /***/ "ac30":
  14656. /***/ (function(module, exports, __webpack_require__) {
  14657. const {
  14658. noopTest,
  14659. edit,
  14660. merge
  14661. } = __webpack_require__("322c");
  14662. /**
  14663. * Block-Level Grammar
  14664. */
  14665. const block = {
  14666. newline: /^\n+/,
  14667. code: /^( {4}[^\n]+\n*)+/,
  14668. fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
  14669. hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
  14670. heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
  14671. blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
  14672. list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
  14673. html: '^ {0,3}(?:' // optional indentation
  14674. + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
  14675. + '|comment[^\\n]*(\\n+|$)' // (2)
  14676. + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
  14677. + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
  14678. + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
  14679. + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
  14680. + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
  14681. + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
  14682. + ')',
  14683. def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
  14684. nptable: noopTest,
  14685. table: noopTest,
  14686. lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
  14687. // regex template, placeholders will be replaced according to different paragraph
  14688. // interruption rules of commonmark and the original markdown spec:
  14689. _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
  14690. text: /^[^\n]+/
  14691. };
  14692. block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
  14693. block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
  14694. block.def = edit(block.def)
  14695. .replace('label', block._label)
  14696. .replace('title', block._title)
  14697. .getRegex();
  14698. block.bullet = /(?:[*+-]|\d{1,9}\.)/;
  14699. block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
  14700. block.item = edit(block.item, 'gm')
  14701. .replace(/bull/g, block.bullet)
  14702. .getRegex();
  14703. block.list = edit(block.list)
  14704. .replace(/bull/g, block.bullet)
  14705. .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
  14706. .replace('def', '\\n+(?=' + block.def.source + ')')
  14707. .getRegex();
  14708. block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
  14709. + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
  14710. + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
  14711. + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
  14712. + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
  14713. + '|track|ul';
  14714. block._comment = /<!--(?!-?>)[\s\S]*?-->/;
  14715. block.html = edit(block.html, 'i')
  14716. .replace('comment', block._comment)
  14717. .replace('tag', block._tag)
  14718. .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
  14719. .getRegex();
  14720. block.paragraph = edit(block._paragraph)
  14721. .replace('hr', block.hr)
  14722. .replace('heading', ' {0,3}#{1,6} ')
  14723. .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
  14724. .replace('blockquote', ' {0,3}>')
  14725. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  14726. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  14727. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  14728. .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
  14729. .getRegex();
  14730. block.blockquote = edit(block.blockquote)
  14731. .replace('paragraph', block.paragraph)
  14732. .getRegex();
  14733. /**
  14734. * Normal Block Grammar
  14735. */
  14736. block.normal = merge({}, block);
  14737. /**
  14738. * GFM Block Grammar
  14739. */
  14740. block.gfm = merge({}, block.normal, {
  14741. nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
  14742. + ' *([-:]+ *\\|[-| :]*)' // Align
  14743. + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells
  14744. table: '^ *\\|(.+)\\n' // Header
  14745. + ' *\\|?( *[-:]+[-| :]*)' // Align
  14746. + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
  14747. });
  14748. block.gfm.nptable = edit(block.gfm.nptable)
  14749. .replace('hr', block.hr)
  14750. .replace('heading', ' {0,3}#{1,6} ')
  14751. .replace('blockquote', ' {0,3}>')
  14752. .replace('code', ' {4}[^\\n]')
  14753. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  14754. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  14755. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  14756. .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
  14757. .getRegex();
  14758. block.gfm.table = edit(block.gfm.table)
  14759. .replace('hr', block.hr)
  14760. .replace('heading', ' {0,3}#{1,6} ')
  14761. .replace('blockquote', ' {0,3}>')
  14762. .replace('code', ' {4}[^\\n]')
  14763. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  14764. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  14765. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  14766. .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
  14767. .getRegex();
  14768. /**
  14769. * Pedantic grammar (original John Gruber's loose markdown specification)
  14770. */
  14771. block.pedantic = merge({}, block.normal, {
  14772. html: edit(
  14773. '^ *(?:comment *(?:\\n|\\s*$)'
  14774. + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
  14775. + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
  14776. .replace('comment', block._comment)
  14777. .replace(/tag/g, '(?!(?:'
  14778. + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
  14779. + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
  14780. + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
  14781. .getRegex(),
  14782. def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
  14783. heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
  14784. fences: noopTest, // fences not supported
  14785. paragraph: edit(block.normal._paragraph)
  14786. .replace('hr', block.hr)
  14787. .replace('heading', ' *#{1,6} *[^\n]')
  14788. .replace('lheading', block.lheading)
  14789. .replace('blockquote', ' {0,3}>')
  14790. .replace('|fences', '')
  14791. .replace('|list', '')
  14792. .replace('|html', '')
  14793. .getRegex()
  14794. });
  14795. /**
  14796. * Inline-Level Grammar
  14797. */
  14798. const inline = {
  14799. escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
  14800. autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
  14801. url: noopTest,
  14802. tag: '^comment'
  14803. + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
  14804. + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
  14805. + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
  14806. + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
  14807. + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
  14808. link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
  14809. reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
  14810. nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
  14811. strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
  14812. em: /^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,
  14813. code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  14814. br: /^( {2,}|\\)\n(?!\s*$)/,
  14815. del: noopTest,
  14816. text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
  14817. };
  14818. // list of punctuation marks from common mark spec
  14819. // without ` and ] to workaround Rule 17 (inline code blocks/links)
  14820. inline._punctuation = '!"#$%&\'()*+\\-./:;<=>?@\\[^_{|}~';
  14821. inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
  14822. inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
  14823. inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
  14824. inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
  14825. inline.autolink = edit(inline.autolink)
  14826. .replace('scheme', inline._scheme)
  14827. .replace('email', inline._email)
  14828. .getRegex();
  14829. inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
  14830. inline.tag = edit(inline.tag)
  14831. .replace('comment', block._comment)
  14832. .replace('attribute', inline._attribute)
  14833. .getRegex();
  14834. inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
  14835. inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
  14836. inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
  14837. inline.link = edit(inline.link)
  14838. .replace('label', inline._label)
  14839. .replace('href', inline._href)
  14840. .replace('title', inline._title)
  14841. .getRegex();
  14842. inline.reflink = edit(inline.reflink)
  14843. .replace('label', inline._label)
  14844. .getRegex();
  14845. /**
  14846. * Normal Inline Grammar
  14847. */
  14848. inline.normal = merge({}, inline);
  14849. /**
  14850. * Pedantic Inline Grammar
  14851. */
  14852. inline.pedantic = merge({}, inline.normal, {
  14853. strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  14854. em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
  14855. link: edit(/^!?\[(label)\]\((.*?)\)/)
  14856. .replace('label', inline._label)
  14857. .getRegex(),
  14858. reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
  14859. .replace('label', inline._label)
  14860. .getRegex()
  14861. });
  14862. /**
  14863. * GFM Inline Grammar
  14864. */
  14865. inline.gfm = merge({}, inline.normal, {
  14866. escape: edit(inline.escape).replace('])', '~|])').getRegex(),
  14867. _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
  14868. url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
  14869. _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
  14870. del: /^~+(?=\S)([\s\S]*?\S)~+/,
  14871. text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
  14872. });
  14873. inline.gfm.url = edit(inline.gfm.url, 'i')
  14874. .replace('email', inline.gfm._extended_email)
  14875. .getRegex();
  14876. /**
  14877. * GFM + Line Breaks Inline Grammar
  14878. */
  14879. inline.breaks = merge({}, inline.gfm, {
  14880. br: edit(inline.br).replace('{2,}', '*').getRegex(),
  14881. text: edit(inline.gfm.text)
  14882. .replace('\\b_', '\\b_| {2,}\\n')
  14883. .replace(/\{2,\}/g, '*')
  14884. .getRegex()
  14885. });
  14886. module.exports = {
  14887. block,
  14888. inline
  14889. };
  14890. /***/ }),
  14891. /***/ "ae25":
  14892. /***/ (function(module, exports, __webpack_require__) {
  14893. var global = __webpack_require__("d890");
  14894. var isObject = __webpack_require__("a719");
  14895. var document = global.document;
  14896. // typeof document.createElement is 'object' in old IE
  14897. var EXISTS = isObject(document) && isObject(document.createElement);
  14898. module.exports = function (it) {
  14899. return EXISTS ? document.createElement(it) : {};
  14900. };
  14901. /***/ }),
  14902. /***/ "b2e0":
  14903. /***/ (function(module, exports, __webpack_require__) {
  14904. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  14905. // Distributed under an MIT license: https://codemirror.net/LICENSE
  14906. (function(mod) {
  14907. if (true) // CommonJS
  14908. mod(__webpack_require__("a564"));
  14909. else {}
  14910. })(function(CodeMirror) {
  14911. "use strict";
  14912. var htmlConfig = {
  14913. autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
  14914. 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
  14915. 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
  14916. 'track': true, 'wbr': true, 'menuitem': true},
  14917. implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
  14918. 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
  14919. 'th': true, 'tr': true},
  14920. contextGrabbers: {
  14921. 'dd': {'dd': true, 'dt': true},
  14922. 'dt': {'dd': true, 'dt': true},
  14923. 'li': {'li': true},
  14924. 'option': {'option': true, 'optgroup': true},
  14925. 'optgroup': {'optgroup': true},
  14926. 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
  14927. 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
  14928. 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
  14929. 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
  14930. 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
  14931. 'rp': {'rp': true, 'rt': true},
  14932. 'rt': {'rp': true, 'rt': true},
  14933. 'tbody': {'tbody': true, 'tfoot': true},
  14934. 'td': {'td': true, 'th': true},
  14935. 'tfoot': {'tbody': true},
  14936. 'th': {'td': true, 'th': true},
  14937. 'thead': {'tbody': true, 'tfoot': true},
  14938. 'tr': {'tr': true}
  14939. },
  14940. doNotIndent: {"pre": true},
  14941. allowUnquoted: true,
  14942. allowMissing: true,
  14943. caseFold: true
  14944. }
  14945. var xmlConfig = {
  14946. autoSelfClosers: {},
  14947. implicitlyClosed: {},
  14948. contextGrabbers: {},
  14949. doNotIndent: {},
  14950. allowUnquoted: false,
  14951. allowMissing: false,
  14952. allowMissingTagName: false,
  14953. caseFold: false
  14954. }
  14955. CodeMirror.defineMode("xml", function(editorConf, config_) {
  14956. var indentUnit = editorConf.indentUnit
  14957. var config = {}
  14958. var defaults = config_.htmlMode ? htmlConfig : xmlConfig
  14959. for (var prop in defaults) config[prop] = defaults[prop]
  14960. for (var prop in config_) config[prop] = config_[prop]
  14961. // Return variables for tokenizers
  14962. var type, setStyle;
  14963. function inText(stream, state) {
  14964. function chain(parser) {
  14965. state.tokenize = parser;
  14966. return parser(stream, state);
  14967. }
  14968. var ch = stream.next();
  14969. if (ch == "<") {
  14970. if (stream.eat("!")) {
  14971. if (stream.eat("[")) {
  14972. if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
  14973. else return null;
  14974. } else if (stream.match("--")) {
  14975. return chain(inBlock("comment", "-->"));
  14976. } else if (stream.match("DOCTYPE", true, true)) {
  14977. stream.eatWhile(/[\w\._\-]/);
  14978. return chain(doctype(1));
  14979. } else {
  14980. return null;
  14981. }
  14982. } else if (stream.eat("?")) {
  14983. stream.eatWhile(/[\w\._\-]/);
  14984. state.tokenize = inBlock("meta", "?>");
  14985. return "meta";
  14986. } else {
  14987. type = stream.eat("/") ? "closeTag" : "openTag";
  14988. state.tokenize = inTag;
  14989. return "tag bracket";
  14990. }
  14991. } else if (ch == "&") {
  14992. var ok;
  14993. if (stream.eat("#")) {
  14994. if (stream.eat("x")) {
  14995. ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
  14996. } else {
  14997. ok = stream.eatWhile(/[\d]/) && stream.eat(";");
  14998. }
  14999. } else {
  15000. ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
  15001. }
  15002. return ok ? "atom" : "error";
  15003. } else {
  15004. stream.eatWhile(/[^&<]/);
  15005. return null;
  15006. }
  15007. }
  15008. inText.isInText = true;
  15009. function inTag(stream, state) {
  15010. var ch = stream.next();
  15011. if (ch == ">" || (ch == "/" && stream.eat(">"))) {
  15012. state.tokenize = inText;
  15013. type = ch == ">" ? "endTag" : "selfcloseTag";
  15014. return "tag bracket";
  15015. } else if (ch == "=") {
  15016. type = "equals";
  15017. return null;
  15018. } else if (ch == "<") {
  15019. state.tokenize = inText;
  15020. state.state = baseState;
  15021. state.tagName = state.tagStart = null;
  15022. var next = state.tokenize(stream, state);
  15023. return next ? next + " tag error" : "tag error";
  15024. } else if (/[\'\"]/.test(ch)) {
  15025. state.tokenize = inAttribute(ch);
  15026. state.stringStartCol = stream.column();
  15027. return state.tokenize(stream, state);
  15028. } else {
  15029. stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
  15030. return "word";
  15031. }
  15032. }
  15033. function inAttribute(quote) {
  15034. var closure = function(stream, state) {
  15035. while (!stream.eol()) {
  15036. if (stream.next() == quote) {
  15037. state.tokenize = inTag;
  15038. break;
  15039. }
  15040. }
  15041. return "string";
  15042. };
  15043. closure.isInAttribute = true;
  15044. return closure;
  15045. }
  15046. function inBlock(style, terminator) {
  15047. return function(stream, state) {
  15048. while (!stream.eol()) {
  15049. if (stream.match(terminator)) {
  15050. state.tokenize = inText;
  15051. break;
  15052. }
  15053. stream.next();
  15054. }
  15055. return style;
  15056. }
  15057. }
  15058. function doctype(depth) {
  15059. return function(stream, state) {
  15060. var ch;
  15061. while ((ch = stream.next()) != null) {
  15062. if (ch == "<") {
  15063. state.tokenize = doctype(depth + 1);
  15064. return state.tokenize(stream, state);
  15065. } else if (ch == ">") {
  15066. if (depth == 1) {
  15067. state.tokenize = inText;
  15068. break;
  15069. } else {
  15070. state.tokenize = doctype(depth - 1);
  15071. return state.tokenize(stream, state);
  15072. }
  15073. }
  15074. }
  15075. return "meta";
  15076. };
  15077. }
  15078. function Context(state, tagName, startOfLine) {
  15079. this.prev = state.context;
  15080. this.tagName = tagName;
  15081. this.indent = state.indented;
  15082. this.startOfLine = startOfLine;
  15083. if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
  15084. this.noIndent = true;
  15085. }
  15086. function popContext(state) {
  15087. if (state.context) state.context = state.context.prev;
  15088. }
  15089. function maybePopContext(state, nextTagName) {
  15090. var parentTagName;
  15091. while (true) {
  15092. if (!state.context) {
  15093. return;
  15094. }
  15095. parentTagName = state.context.tagName;
  15096. if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
  15097. !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
  15098. return;
  15099. }
  15100. popContext(state);
  15101. }
  15102. }
  15103. function baseState(type, stream, state) {
  15104. if (type == "openTag") {
  15105. state.tagStart = stream.column();
  15106. return tagNameState;
  15107. } else if (type == "closeTag") {
  15108. return closeTagNameState;
  15109. } else {
  15110. return baseState;
  15111. }
  15112. }
  15113. function tagNameState(type, stream, state) {
  15114. if (type == "word") {
  15115. state.tagName = stream.current();
  15116. setStyle = "tag";
  15117. return attrState;
  15118. } else if (config.allowMissingTagName && type == "endTag") {
  15119. setStyle = "tag bracket";
  15120. return attrState(type, stream, state);
  15121. } else {
  15122. setStyle = "error";
  15123. return tagNameState;
  15124. }
  15125. }
  15126. function closeTagNameState(type, stream, state) {
  15127. if (type == "word") {
  15128. var tagName = stream.current();
  15129. if (state.context && state.context.tagName != tagName &&
  15130. config.implicitlyClosed.hasOwnProperty(state.context.tagName))
  15131. popContext(state);
  15132. if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
  15133. setStyle = "tag";
  15134. return closeState;
  15135. } else {
  15136. setStyle = "tag error";
  15137. return closeStateErr;
  15138. }
  15139. } else if (config.allowMissingTagName && type == "endTag") {
  15140. setStyle = "tag bracket";
  15141. return closeState(type, stream, state);
  15142. } else {
  15143. setStyle = "error";
  15144. return closeStateErr;
  15145. }
  15146. }
  15147. function closeState(type, _stream, state) {
  15148. if (type != "endTag") {
  15149. setStyle = "error";
  15150. return closeState;
  15151. }
  15152. popContext(state);
  15153. return baseState;
  15154. }
  15155. function closeStateErr(type, stream, state) {
  15156. setStyle = "error";
  15157. return closeState(type, stream, state);
  15158. }
  15159. function attrState(type, _stream, state) {
  15160. if (type == "word") {
  15161. setStyle = "attribute";
  15162. return attrEqState;
  15163. } else if (type == "endTag" || type == "selfcloseTag") {
  15164. var tagName = state.tagName, tagStart = state.tagStart;
  15165. state.tagName = state.tagStart = null;
  15166. if (type == "selfcloseTag" ||
  15167. config.autoSelfClosers.hasOwnProperty(tagName)) {
  15168. maybePopContext(state, tagName);
  15169. } else {
  15170. maybePopContext(state, tagName);
  15171. state.context = new Context(state, tagName, tagStart == state.indented);
  15172. }
  15173. return baseState;
  15174. }
  15175. setStyle = "error";
  15176. return attrState;
  15177. }
  15178. function attrEqState(type, stream, state) {
  15179. if (type == "equals") return attrValueState;
  15180. if (!config.allowMissing) setStyle = "error";
  15181. return attrState(type, stream, state);
  15182. }
  15183. function attrValueState(type, stream, state) {
  15184. if (type == "string") return attrContinuedState;
  15185. if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
  15186. setStyle = "error";
  15187. return attrState(type, stream, state);
  15188. }
  15189. function attrContinuedState(type, stream, state) {
  15190. if (type == "string") return attrContinuedState;
  15191. return attrState(type, stream, state);
  15192. }
  15193. return {
  15194. startState: function(baseIndent) {
  15195. var state = {tokenize: inText,
  15196. state: baseState,
  15197. indented: baseIndent || 0,
  15198. tagName: null, tagStart: null,
  15199. context: null}
  15200. if (baseIndent != null) state.baseIndent = baseIndent
  15201. return state
  15202. },
  15203. token: function(stream, state) {
  15204. if (!state.tagName && stream.sol())
  15205. state.indented = stream.indentation();
  15206. if (stream.eatSpace()) return null;
  15207. type = null;
  15208. var style = state.tokenize(stream, state);
  15209. if ((style || type) && style != "comment") {
  15210. setStyle = null;
  15211. state.state = state.state(type || style, stream, state);
  15212. if (setStyle)
  15213. style = setStyle == "error" ? style + " error" : setStyle;
  15214. }
  15215. return style;
  15216. },
  15217. indent: function(state, textAfter, fullLine) {
  15218. var context = state.context;
  15219. // Indent multi-line strings (e.g. css).
  15220. if (state.tokenize.isInAttribute) {
  15221. if (state.tagStart == state.indented)
  15222. return state.stringStartCol + 1;
  15223. else
  15224. return state.indented + indentUnit;
  15225. }
  15226. if (context && context.noIndent) return CodeMirror.Pass;
  15227. if (state.tokenize != inTag && state.tokenize != inText)
  15228. return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
  15229. // Indent the starts of attribute names.
  15230. if (state.tagName) {
  15231. if (config.multilineTagIndentPastTag !== false)
  15232. return state.tagStart + state.tagName.length + 2;
  15233. else
  15234. return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
  15235. }
  15236. if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
  15237. var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
  15238. if (tagAfter && tagAfter[1]) { // Closing tag spotted
  15239. while (context) {
  15240. if (context.tagName == tagAfter[2]) {
  15241. context = context.prev;
  15242. break;
  15243. } else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
  15244. context = context.prev;
  15245. } else {
  15246. break;
  15247. }
  15248. }
  15249. } else if (tagAfter) { // Opening tag spotted
  15250. while (context) {
  15251. var grabbers = config.contextGrabbers[context.tagName];
  15252. if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
  15253. context = context.prev;
  15254. else
  15255. break;
  15256. }
  15257. }
  15258. while (context && context.prev && !context.startOfLine)
  15259. context = context.prev;
  15260. if (context) return context.indent + indentUnit;
  15261. else return state.baseIndent || 0;
  15262. },
  15263. electricInput: /<\/[\s\w:]+>$/,
  15264. blockCommentStart: "<!--",
  15265. blockCommentEnd: "-->",
  15266. configuration: config.htmlMode ? "html" : "xml",
  15267. helperType: config.htmlMode ? "html" : "xml",
  15268. skipAttribute: function(state) {
  15269. if (state.state == attrValueState)
  15270. state.state = attrState
  15271. },
  15272. xmlCurrentTag: function(state) {
  15273. return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null
  15274. },
  15275. xmlCurrentContext: function(state) {
  15276. var context = []
  15277. for (var cx = state.context; cx; cx = cx.prev)
  15278. if (cx.tagName) context.push(cx.tagName)
  15279. return context.reverse()
  15280. }
  15281. };
  15282. });
  15283. CodeMirror.defineMIME("text/xml", "xml");
  15284. CodeMirror.defineMIME("application/xml", "xml");
  15285. if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
  15286. CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
  15287. });
  15288. /***/ }),
  15289. /***/ "b338":
  15290. /***/ (function(module, exports, __webpack_require__) {
  15291. var internalObjectKeys = __webpack_require__("ead4");
  15292. var enumBugKeys = __webpack_require__("18f6");
  15293. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  15294. // `Object.getOwnPropertyNames` method
  15295. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  15296. exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  15297. return internalObjectKeys(O, hiddenKeys);
  15298. };
  15299. /***/ }),
  15300. /***/ "b702":
  15301. /***/ (function(module, exports, __webpack_require__) {
  15302. var NATIVE_WEAK_MAP = __webpack_require__("604f");
  15303. var global = __webpack_require__("d890");
  15304. var isObject = __webpack_require__("a719");
  15305. var createNonEnumerableProperty = __webpack_require__("0fc1");
  15306. var objectHas = __webpack_require__("faa8");
  15307. var sharedKey = __webpack_require__("7db2");
  15308. var hiddenKeys = __webpack_require__("d5a8");
  15309. var WeakMap = global.WeakMap;
  15310. var set, get, has;
  15311. var enforce = function (it) {
  15312. return has(it) ? get(it) : set(it, {});
  15313. };
  15314. var getterFor = function (TYPE) {
  15315. return function (it) {
  15316. var state;
  15317. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  15318. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  15319. } return state;
  15320. };
  15321. };
  15322. if (NATIVE_WEAK_MAP) {
  15323. var store = new WeakMap();
  15324. var wmget = store.get;
  15325. var wmhas = store.has;
  15326. var wmset = store.set;
  15327. set = function (it, metadata) {
  15328. wmset.call(store, it, metadata);
  15329. return metadata;
  15330. };
  15331. get = function (it) {
  15332. return wmget.call(store, it) || {};
  15333. };
  15334. has = function (it) {
  15335. return wmhas.call(store, it);
  15336. };
  15337. } else {
  15338. var STATE = sharedKey('state');
  15339. hiddenKeys[STATE] = true;
  15340. set = function (it, metadata) {
  15341. createNonEnumerableProperty(it, STATE, metadata);
  15342. return metadata;
  15343. };
  15344. get = function (it) {
  15345. return objectHas(it, STATE) ? it[STATE] : {};
  15346. };
  15347. has = function (it) {
  15348. return objectHas(it, STATE);
  15349. };
  15350. }
  15351. module.exports = {
  15352. set: set,
  15353. get: get,
  15354. has: has,
  15355. enforce: enforce,
  15356. getterFor: getterFor
  15357. };
  15358. /***/ }),
  15359. /***/ "b73f":
  15360. /***/ (function(module, exports, __webpack_require__) {
  15361. var $ = __webpack_require__("1c8b");
  15362. var fails = __webpack_require__("efe2");
  15363. var toIndexedObject = __webpack_require__("da10");
  15364. var nativeGetOwnPropertyDescriptor = __webpack_require__("aa6b").f;
  15365. var DESCRIPTORS = __webpack_require__("1e2c");
  15366. var FAILS_ON_PRIMITIVES = fails(function () { nativeGetOwnPropertyDescriptor(1); });
  15367. var FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES;
  15368. // `Object.getOwnPropertyDescriptor` method
  15369. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
  15370. $({ target: 'Object', stat: true, forced: FORCED, sham: !DESCRIPTORS }, {
  15371. getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {
  15372. return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);
  15373. }
  15374. });
  15375. /***/ }),
  15376. /***/ "bf84":
  15377. /***/ (function(module, exports, __webpack_require__) {
  15378. var $ = __webpack_require__("1c8b");
  15379. var DESCRIPTORS = __webpack_require__("1e2c");
  15380. var ownKeys = __webpack_require__("8d44");
  15381. var toIndexedObject = __webpack_require__("da10");
  15382. var getOwnPropertyDescriptorModule = __webpack_require__("aa6b");
  15383. var createProperty = __webpack_require__("1bbd");
  15384. // `Object.getOwnPropertyDescriptors` method
  15385. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
  15386. $({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {
  15387. getOwnPropertyDescriptors: function getOwnPropertyDescriptors(object) {
  15388. var O = toIndexedObject(object);
  15389. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  15390. var keys = ownKeys(O);
  15391. var result = {};
  15392. var index = 0;
  15393. var key, descriptor;
  15394. while (keys.length > index) {
  15395. descriptor = getOwnPropertyDescriptor(O, key = keys[index++]);
  15396. if (descriptor !== undefined) createProperty(result, key, descriptor);
  15397. }
  15398. return result;
  15399. }
  15400. });
  15401. /***/ }),
  15402. /***/ "c051":
  15403. /***/ (function(module, exports, __webpack_require__) {
  15404. var toIndexedObject = __webpack_require__("da10");
  15405. var nativeGetOwnPropertyNames = __webpack_require__("b338").f;
  15406. var toString = {}.toString;
  15407. var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames
  15408. ? Object.getOwnPropertyNames(window) : [];
  15409. var getWindowNames = function (it) {
  15410. try {
  15411. return nativeGetOwnPropertyNames(it);
  15412. } catch (error) {
  15413. return windowNames.slice();
  15414. }
  15415. };
  15416. // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
  15417. module.exports.f = function getOwnPropertyNames(it) {
  15418. return windowNames && toString.call(it) == '[object Window]'
  15419. ? getWindowNames(it)
  15420. : nativeGetOwnPropertyNames(toIndexedObject(it));
  15421. };
  15422. /***/ }),
  15423. /***/ "c54b":
  15424. /***/ (function(module, exports, __webpack_require__) {
  15425. var fails = __webpack_require__("efe2");
  15426. module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
  15427. // Chrome 38 Symbol has incorrect toString conversion
  15428. // eslint-disable-next-line no-undef
  15429. return !String(Symbol());
  15430. });
  15431. /***/ }),
  15432. /***/ "c59c":
  15433. /***/ (function(module, exports, __webpack_require__) {
  15434. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// addapted from the document.currentScript polyfill by Adam Miller
  15435. // MIT license
  15436. // source: https://github.com/amiller-gh/currentScript-polyfill
  15437. // added support for Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1620505
  15438. (function (root, factory) {
  15439. if (true) {
  15440. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  15441. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  15442. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  15443. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  15444. } else {}
  15445. }(typeof self !== 'undefined' ? self : this, function () {
  15446. function getCurrentScript () {
  15447. if (document.currentScript) {
  15448. return document.currentScript
  15449. }
  15450. // IE 8-10 support script readyState
  15451. // IE 11+ & Firefox support stack trace
  15452. try {
  15453. throw new Error();
  15454. }
  15455. catch (err) {
  15456. // Find the second match for the "at" string to get file src url from stack.
  15457. var ieStackRegExp = /.*at [^(]*\((.*):(.+):(.+)\)$/ig,
  15458. ffStackRegExp = /@([^@]*):(\d+):(\d+)\s*$/ig,
  15459. stackDetails = ieStackRegExp.exec(err.stack) || ffStackRegExp.exec(err.stack),
  15460. scriptLocation = (stackDetails && stackDetails[1]) || false,
  15461. line = (stackDetails && stackDetails[2]) || false,
  15462. currentLocation = document.location.href.replace(document.location.hash, ''),
  15463. pageSource,
  15464. inlineScriptSourceRegExp,
  15465. inlineScriptSource,
  15466. scripts = document.getElementsByTagName('script'); // Live NodeList collection
  15467. if (scriptLocation === currentLocation) {
  15468. pageSource = document.documentElement.outerHTML;
  15469. inlineScriptSourceRegExp = new RegExp('(?:[^\\n]+?\\n){0,' + (line - 2) + '}[^<]*<script>([\\d\\D]*?)<\\/script>[\\d\\D]*', 'i');
  15470. inlineScriptSource = pageSource.replace(inlineScriptSourceRegExp, '$1').trim();
  15471. }
  15472. for (var i = 0; i < scripts.length; i++) {
  15473. // If ready state is interactive, return the script tag
  15474. if (scripts[i].readyState === 'interactive') {
  15475. return scripts[i];
  15476. }
  15477. // If src matches, return the script tag
  15478. if (scripts[i].src === scriptLocation) {
  15479. return scripts[i];
  15480. }
  15481. // If inline source matches, return the script tag
  15482. if (
  15483. scriptLocation === currentLocation &&
  15484. scripts[i].innerHTML &&
  15485. scripts[i].innerHTML.trim() === inlineScriptSource
  15486. ) {
  15487. return scripts[i];
  15488. }
  15489. }
  15490. // If no match, return null
  15491. return null;
  15492. }
  15493. };
  15494. return getCurrentScript
  15495. }));
  15496. /***/ }),
  15497. /***/ "c69d":
  15498. /***/ (function(module, exports, __webpack_require__) {
  15499. var has = __webpack_require__("faa8");
  15500. var ownKeys = __webpack_require__("8d44");
  15501. var getOwnPropertyDescriptorModule = __webpack_require__("aa6b");
  15502. var definePropertyModule = __webpack_require__("d910");
  15503. module.exports = function (target, source) {
  15504. var keys = ownKeys(source);
  15505. var defineProperty = definePropertyModule.f;
  15506. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  15507. for (var i = 0; i < keys.length; i++) {
  15508. var key = keys[i];
  15509. if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  15510. }
  15511. };
  15512. /***/ }),
  15513. /***/ "cbab":
  15514. /***/ (function(module, exports, __webpack_require__) {
  15515. var internalObjectKeys = __webpack_require__("ead4");
  15516. var enumBugKeys = __webpack_require__("18f6");
  15517. // `Object.keys` method
  15518. // https://tc39.github.io/ecma262/#sec-object.keys
  15519. module.exports = Object.keys || function keys(O) {
  15520. return internalObjectKeys(O, enumBugKeys);
  15521. };
  15522. /***/ }),
  15523. /***/ "ccf5":
  15524. /***/ (function(module, exports, __webpack_require__) {
  15525. // extracted by mini-css-extract-plugin
  15526. /***/ }),
  15527. /***/ "d5a8":
  15528. /***/ (function(module, exports) {
  15529. module.exports = {};
  15530. /***/ }),
  15531. /***/ "d776":
  15532. /***/ (function(module, exports, __webpack_require__) {
  15533. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  15534. // Distributed under an MIT license: https://codemirror.net/LICENSE
  15535. // Utility function that allows modes to be combined. The mode given
  15536. // as the base argument takes care of most of the normal mode
  15537. // functionality, but a second (typically simple) mode is used, which
  15538. // can override the style of text. Both modes get to parse all of the
  15539. // text, but when both assign a non-null style to a piece of code, the
  15540. // overlay wins, unless the combine argument was true and not overridden,
  15541. // or state.overlay.combineTokens was true, in which case the styles are
  15542. // combined.
  15543. (function(mod) {
  15544. if (true) // CommonJS
  15545. mod(__webpack_require__("a564"));
  15546. else {}
  15547. })(function(CodeMirror) {
  15548. "use strict";
  15549. CodeMirror.overlayMode = function(base, overlay, combine) {
  15550. return {
  15551. startState: function() {
  15552. return {
  15553. base: CodeMirror.startState(base),
  15554. overlay: CodeMirror.startState(overlay),
  15555. basePos: 0, baseCur: null,
  15556. overlayPos: 0, overlayCur: null,
  15557. streamSeen: null
  15558. };
  15559. },
  15560. copyState: function(state) {
  15561. return {
  15562. base: CodeMirror.copyState(base, state.base),
  15563. overlay: CodeMirror.copyState(overlay, state.overlay),
  15564. basePos: state.basePos, baseCur: null,
  15565. overlayPos: state.overlayPos, overlayCur: null
  15566. };
  15567. },
  15568. token: function(stream, state) {
  15569. if (stream != state.streamSeen ||
  15570. Math.min(state.basePos, state.overlayPos) < stream.start) {
  15571. state.streamSeen = stream;
  15572. state.basePos = state.overlayPos = stream.start;
  15573. }
  15574. if (stream.start == state.basePos) {
  15575. state.baseCur = base.token(stream, state.base);
  15576. state.basePos = stream.pos;
  15577. }
  15578. if (stream.start == state.overlayPos) {
  15579. stream.pos = stream.start;
  15580. state.overlayCur = overlay.token(stream, state.overlay);
  15581. state.overlayPos = stream.pos;
  15582. }
  15583. stream.pos = Math.min(state.basePos, state.overlayPos);
  15584. // state.overlay.combineTokens always takes precedence over combine,
  15585. // unless set to null
  15586. if (state.overlayCur == null) return state.baseCur;
  15587. else if (state.baseCur != null &&
  15588. state.overlay.combineTokens ||
  15589. combine && state.overlay.combineTokens == null)
  15590. return state.baseCur + " " + state.overlayCur;
  15591. else return state.overlayCur;
  15592. },
  15593. indent: base.indent && function(state, textAfter, line) {
  15594. return base.indent(state.base, textAfter, line);
  15595. },
  15596. electricChars: base.electricChars,
  15597. innerMode: function(state) { return {state: state.base, mode: base}; },
  15598. blankLine: function(state) {
  15599. var baseToken, overlayToken;
  15600. if (base.blankLine) baseToken = base.blankLine(state.base);
  15601. if (overlay.blankLine) overlayToken = overlay.blankLine(state.overlay);
  15602. return overlayToken == null ?
  15603. baseToken :
  15604. (combine && baseToken != null ? baseToken + " " + overlayToken : overlayToken);
  15605. }
  15606. };
  15607. };
  15608. });
  15609. /***/ }),
  15610. /***/ "d7e1":
  15611. /***/ (function(module, exports, __webpack_require__) {
  15612. "use strict";
  15613. var fails = __webpack_require__("efe2");
  15614. module.exports = function (METHOD_NAME, argument) {
  15615. var method = [][METHOD_NAME];
  15616. return !!method && fails(function () {
  15617. // eslint-disable-next-line no-useless-call,no-throw-literal
  15618. method.call(null, argument || function () { throw 1; }, 1);
  15619. });
  15620. };
  15621. /***/ }),
  15622. /***/ "d88d":
  15623. /***/ (function(module, exports, __webpack_require__) {
  15624. var toInteger = __webpack_require__("3da3");
  15625. var min = Math.min;
  15626. // `ToLength` abstract operation
  15627. // https://tc39.github.io/ecma262/#sec-tolength
  15628. module.exports = function (argument) {
  15629. return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  15630. };
  15631. /***/ }),
  15632. /***/ "d890":
  15633. /***/ (function(module, exports, __webpack_require__) {
  15634. /* WEBPACK VAR INJECTION */(function(global) {var check = function (it) {
  15635. return it && it.Math == Math && it;
  15636. };
  15637. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  15638. module.exports =
  15639. // eslint-disable-next-line no-undef
  15640. check(typeof globalThis == 'object' && globalThis) ||
  15641. check(typeof window == 'object' && window) ||
  15642. check(typeof self == 'object' && self) ||
  15643. check(typeof global == 'object' && global) ||
  15644. // eslint-disable-next-line no-new-func
  15645. Function('return this')();
  15646. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("9edd")))
  15647. /***/ }),
  15648. /***/ "d910":
  15649. /***/ (function(module, exports, __webpack_require__) {
  15650. var DESCRIPTORS = __webpack_require__("1e2c");
  15651. var IE8_DOM_DEFINE = __webpack_require__("2039");
  15652. var anObject = __webpack_require__("857c");
  15653. var toPrimitive = __webpack_require__("9f67");
  15654. var nativeDefineProperty = Object.defineProperty;
  15655. // `Object.defineProperty` method
  15656. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  15657. exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
  15658. anObject(O);
  15659. P = toPrimitive(P, true);
  15660. anObject(Attributes);
  15661. if (IE8_DOM_DEFINE) try {
  15662. return nativeDefineProperty(O, P, Attributes);
  15663. } catch (error) { /* empty */ }
  15664. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  15665. if ('value' in Attributes) O[P] = Attributes.value;
  15666. return O;
  15667. };
  15668. /***/ }),
  15669. /***/ "da10":
  15670. /***/ (function(module, exports, __webpack_require__) {
  15671. // toObject with fallback for non-array-like ES3 strings
  15672. var IndexedObject = __webpack_require__("692f");
  15673. var requireObjectCoercible = __webpack_require__("2732");
  15674. module.exports = function (it) {
  15675. return IndexedObject(requireObjectCoercible(it));
  15676. };
  15677. /***/ }),
  15678. /***/ "dbb3":
  15679. /***/ (function(module, exports, __webpack_require__) {
  15680. "use strict";
  15681. var $ = __webpack_require__("1c8b");
  15682. var $filter = __webpack_require__("5dfd").filter;
  15683. var arrayMethodHasSpeciesSupport = __webpack_require__("1ea7");
  15684. var arrayMethodUsesToLength = __webpack_require__("ff9c");
  15685. var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');
  15686. // Edge 14- issue
  15687. var USES_TO_LENGTH = arrayMethodUsesToLength('filter');
  15688. // `Array.prototype.filter` method
  15689. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  15690. // with adding support of @@species
  15691. $({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH }, {
  15692. filter: function filter(callbackfn /* , thisArg */) {
  15693. return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  15694. }
  15695. });
  15696. /***/ }),
  15697. /***/ "dbe8":
  15698. /***/ (function(module, exports, __webpack_require__) {
  15699. var DESCRIPTORS = __webpack_require__("1e2c");
  15700. var definePropertyModule = __webpack_require__("d910");
  15701. var anObject = __webpack_require__("857c");
  15702. var objectKeys = __webpack_require__("cbab");
  15703. // `Object.defineProperties` method
  15704. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  15705. module.exports = DESCRIPTORS ? Object.defineProperties : function defineProperties(O, Properties) {
  15706. anObject(O);
  15707. var keys = objectKeys(Properties);
  15708. var length = keys.length;
  15709. var index = 0;
  15710. var key;
  15711. while (length > index) definePropertyModule.f(O, key = keys[index++], Properties[key]);
  15712. return O;
  15713. };
  15714. /***/ }),
  15715. /***/ "e1d6":
  15716. /***/ (function(module, exports, __webpack_require__) {
  15717. var toInteger = __webpack_require__("3da3");
  15718. var max = Math.max;
  15719. var min = Math.min;
  15720. // Helper for a popular repeating case of the spec:
  15721. // Let integer be ? ToInteger(index).
  15722. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  15723. module.exports = function (index, length) {
  15724. var integer = toInteger(index);
  15725. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  15726. };
  15727. /***/ }),
  15728. /***/ "e349":
  15729. /***/ (function(module, exports, __webpack_require__) {
  15730. var aFunction = __webpack_require__("0c3c");
  15731. // optional / simple context binding
  15732. module.exports = function (fn, that, length) {
  15733. aFunction(fn);
  15734. if (that === undefined) return fn;
  15735. switch (length) {
  15736. case 0: return function () {
  15737. return fn.call(that);
  15738. };
  15739. case 1: return function (a) {
  15740. return fn.call(that, a);
  15741. };
  15742. case 2: return function (a, b) {
  15743. return fn.call(that, a, b);
  15744. };
  15745. case 3: return function (a, b, c) {
  15746. return fn.call(that, a, b, c);
  15747. };
  15748. }
  15749. return function (/* ...args */) {
  15750. return fn.apply(that, arguments);
  15751. };
  15752. };
  15753. /***/ }),
  15754. /***/ "e4db":
  15755. /***/ (function(module, exports, __webpack_require__) {
  15756. var global = __webpack_require__("d890");
  15757. var createNonEnumerableProperty = __webpack_require__("0fc1");
  15758. module.exports = function (key, value) {
  15759. try {
  15760. createNonEnumerableProperty(global, key, value);
  15761. } catch (error) {
  15762. global[key] = value;
  15763. } return value;
  15764. };
  15765. /***/ }),
  15766. /***/ "e8d6":
  15767. /***/ (function(module, exports, __webpack_require__) {
  15768. var fails = __webpack_require__("efe2");
  15769. var replacement = /#|\.prototype\./;
  15770. var isForced = function (feature, detection) {
  15771. var value = data[normalize(feature)];
  15772. return value == POLYFILL ? true
  15773. : value == NATIVE ? false
  15774. : typeof detection == 'function' ? fails(detection)
  15775. : !!detection;
  15776. };
  15777. var normalize = isForced.normalize = function (string) {
  15778. return String(string).replace(replacement, '.').toLowerCase();
  15779. };
  15780. var data = isForced.data = {};
  15781. var NATIVE = isForced.NATIVE = 'N';
  15782. var POLYFILL = isForced.POLYFILL = 'P';
  15783. module.exports = isForced;
  15784. /***/ }),
  15785. /***/ "ead4":
  15786. /***/ (function(module, exports, __webpack_require__) {
  15787. var has = __webpack_require__("faa8");
  15788. var toIndexedObject = __webpack_require__("da10");
  15789. var indexOf = __webpack_require__("45af").indexOf;
  15790. var hiddenKeys = __webpack_require__("d5a8");
  15791. module.exports = function (object, names) {
  15792. var O = toIndexedObject(object);
  15793. var i = 0;
  15794. var result = [];
  15795. var key;
  15796. for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
  15797. // Don't enum bug & hidden keys
  15798. while (names.length > i) if (has(O, key = names[i++])) {
  15799. ~indexOf(result, key) || result.push(key);
  15800. }
  15801. return result;
  15802. };
  15803. /***/ }),
  15804. /***/ "ef71":
  15805. /***/ (function(module, exports, __webpack_require__) {
  15806. "use strict";
  15807. var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
  15808. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  15809. // Nashorn ~ JDK8 bug
  15810. var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
  15811. // `Object.prototype.propertyIsEnumerable` method implementation
  15812. // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
  15813. exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  15814. var descriptor = getOwnPropertyDescriptor(this, V);
  15815. return !!descriptor && descriptor.enumerable;
  15816. } : nativePropertyIsEnumerable;
  15817. /***/ }),
  15818. /***/ "efe2":
  15819. /***/ (function(module, exports) {
  15820. module.exports = function (exec) {
  15821. try {
  15822. return !!exec();
  15823. } catch (error) {
  15824. return true;
  15825. }
  15826. };
  15827. /***/ }),
  15828. /***/ "f3dd":
  15829. /***/ (function(module, exports, __webpack_require__) {
  15830. "use strict";
  15831. var $ = __webpack_require__("1c8b");
  15832. var global = __webpack_require__("d890");
  15833. var getBuiltIn = __webpack_require__("6d7a");
  15834. var IS_PURE = __webpack_require__("9b9d");
  15835. var DESCRIPTORS = __webpack_require__("1e2c");
  15836. var NATIVE_SYMBOL = __webpack_require__("c54b");
  15837. var USE_SYMBOL_AS_UID = __webpack_require__("74cb");
  15838. var fails = __webpack_require__("efe2");
  15839. var has = __webpack_require__("faa8");
  15840. var isArray = __webpack_require__("74e7");
  15841. var isObject = __webpack_require__("a719");
  15842. var anObject = __webpack_require__("857c");
  15843. var toObject = __webpack_require__("3553");
  15844. var toIndexedObject = __webpack_require__("da10");
  15845. var toPrimitive = __webpack_require__("9f67");
  15846. var createPropertyDescriptor = __webpack_require__("38b9");
  15847. var nativeObjectCreate = __webpack_require__("6d60");
  15848. var objectKeys = __webpack_require__("cbab");
  15849. var getOwnPropertyNamesModule = __webpack_require__("b338");
  15850. var getOwnPropertyNamesExternal = __webpack_require__("c051");
  15851. var getOwnPropertySymbolsModule = __webpack_require__("0a60");
  15852. var getOwnPropertyDescriptorModule = __webpack_require__("aa6b");
  15853. var definePropertyModule = __webpack_require__("d910");
  15854. var propertyIsEnumerableModule = __webpack_require__("ef71");
  15855. var createNonEnumerableProperty = __webpack_require__("0fc1");
  15856. var redefine = __webpack_require__("1944");
  15857. var shared = __webpack_require__("6d28");
  15858. var sharedKey = __webpack_require__("7db2");
  15859. var hiddenKeys = __webpack_require__("d5a8");
  15860. var uid = __webpack_require__("7e8b");
  15861. var wellKnownSymbol = __webpack_require__("90fb");
  15862. var wrappedWellKnownSymbolModule = __webpack_require__("4350");
  15863. var defineWellKnownSymbol = __webpack_require__("6d51");
  15864. var setToStringTag = __webpack_require__("27b5");
  15865. var InternalStateModule = __webpack_require__("b702");
  15866. var $forEach = __webpack_require__("5dfd").forEach;
  15867. var HIDDEN = sharedKey('hidden');
  15868. var SYMBOL = 'Symbol';
  15869. var PROTOTYPE = 'prototype';
  15870. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  15871. var setInternalState = InternalStateModule.set;
  15872. var getInternalState = InternalStateModule.getterFor(SYMBOL);
  15873. var ObjectPrototype = Object[PROTOTYPE];
  15874. var $Symbol = global.Symbol;
  15875. var $stringify = getBuiltIn('JSON', 'stringify');
  15876. var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  15877. var nativeDefineProperty = definePropertyModule.f;
  15878. var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
  15879. var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
  15880. var AllSymbols = shared('symbols');
  15881. var ObjectPrototypeSymbols = shared('op-symbols');
  15882. var StringToSymbolRegistry = shared('string-to-symbol-registry');
  15883. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  15884. var WellKnownSymbolsStore = shared('wks');
  15885. var QObject = global.QObject;
  15886. // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
  15887. var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
  15888. // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
  15889. var setSymbolDescriptor = DESCRIPTORS && fails(function () {
  15890. return nativeObjectCreate(nativeDefineProperty({}, 'a', {
  15891. get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
  15892. })).a != 7;
  15893. }) ? function (O, P, Attributes) {
  15894. var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
  15895. if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
  15896. nativeDefineProperty(O, P, Attributes);
  15897. if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
  15898. nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
  15899. }
  15900. } : nativeDefineProperty;
  15901. var wrap = function (tag, description) {
  15902. var symbol = AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]);
  15903. setInternalState(symbol, {
  15904. type: SYMBOL,
  15905. tag: tag,
  15906. description: description
  15907. });
  15908. if (!DESCRIPTORS) symbol.description = description;
  15909. return symbol;
  15910. };
  15911. var isSymbol = USE_SYMBOL_AS_UID ? function (it) {
  15912. return typeof it == 'symbol';
  15913. } : function (it) {
  15914. return Object(it) instanceof $Symbol;
  15915. };
  15916. var $defineProperty = function defineProperty(O, P, Attributes) {
  15917. if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
  15918. anObject(O);
  15919. var key = toPrimitive(P, true);
  15920. anObject(Attributes);
  15921. if (has(AllSymbols, key)) {
  15922. if (!Attributes.enumerable) {
  15923. if (!has(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
  15924. O[HIDDEN][key] = true;
  15925. } else {
  15926. if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
  15927. Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });
  15928. } return setSymbolDescriptor(O, key, Attributes);
  15929. } return nativeDefineProperty(O, key, Attributes);
  15930. };
  15931. var $defineProperties = function defineProperties(O, Properties) {
  15932. anObject(O);
  15933. var properties = toIndexedObject(Properties);
  15934. var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
  15935. $forEach(keys, function (key) {
  15936. if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]);
  15937. });
  15938. return O;
  15939. };
  15940. var $create = function create(O, Properties) {
  15941. return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);
  15942. };
  15943. var $propertyIsEnumerable = function propertyIsEnumerable(V) {
  15944. var P = toPrimitive(V, true);
  15945. var enumerable = nativePropertyIsEnumerable.call(this, P);
  15946. if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false;
  15947. return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true;
  15948. };
  15949. var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
  15950. var it = toIndexedObject(O);
  15951. var key = toPrimitive(P, true);
  15952. if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return;
  15953. var descriptor = nativeGetOwnPropertyDescriptor(it, key);
  15954. if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) {
  15955. descriptor.enumerable = true;
  15956. }
  15957. return descriptor;
  15958. };
  15959. var $getOwnPropertyNames = function getOwnPropertyNames(O) {
  15960. var names = nativeGetOwnPropertyNames(toIndexedObject(O));
  15961. var result = [];
  15962. $forEach(names, function (key) {
  15963. if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key);
  15964. });
  15965. return result;
  15966. };
  15967. var $getOwnPropertySymbols = function getOwnPropertySymbols(O) {
  15968. var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
  15969. var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
  15970. var result = [];
  15971. $forEach(names, function (key) {
  15972. if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) {
  15973. result.push(AllSymbols[key]);
  15974. }
  15975. });
  15976. return result;
  15977. };
  15978. // `Symbol` constructor
  15979. // https://tc39.github.io/ecma262/#sec-symbol-constructor
  15980. if (!NATIVE_SYMBOL) {
  15981. $Symbol = function Symbol() {
  15982. if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor');
  15983. var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]);
  15984. var tag = uid(description);
  15985. var setter = function (value) {
  15986. if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value);
  15987. if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
  15988. setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
  15989. };
  15990. if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
  15991. return wrap(tag, description);
  15992. };
  15993. redefine($Symbol[PROTOTYPE], 'toString', function toString() {
  15994. return getInternalState(this).tag;
  15995. });
  15996. redefine($Symbol, 'withoutSetter', function (description) {
  15997. return wrap(uid(description), description);
  15998. });
  15999. propertyIsEnumerableModule.f = $propertyIsEnumerable;
  16000. definePropertyModule.f = $defineProperty;
  16001. getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
  16002. getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
  16003. getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
  16004. wrappedWellKnownSymbolModule.f = function (name) {
  16005. return wrap(wellKnownSymbol(name), name);
  16006. };
  16007. if (DESCRIPTORS) {
  16008. // https://github.com/tc39/proposal-Symbol-description
  16009. nativeDefineProperty($Symbol[PROTOTYPE], 'description', {
  16010. configurable: true,
  16011. get: function description() {
  16012. return getInternalState(this).description;
  16013. }
  16014. });
  16015. if (!IS_PURE) {
  16016. redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });
  16017. }
  16018. }
  16019. }
  16020. $({ global: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {
  16021. Symbol: $Symbol
  16022. });
  16023. $forEach(objectKeys(WellKnownSymbolsStore), function (name) {
  16024. defineWellKnownSymbol(name);
  16025. });
  16026. $({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {
  16027. // `Symbol.for` method
  16028. // https://tc39.github.io/ecma262/#sec-symbol.for
  16029. 'for': function (key) {
  16030. var string = String(key);
  16031. if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
  16032. var symbol = $Symbol(string);
  16033. StringToSymbolRegistry[string] = symbol;
  16034. SymbolToStringRegistry[symbol] = string;
  16035. return symbol;
  16036. },
  16037. // `Symbol.keyFor` method
  16038. // https://tc39.github.io/ecma262/#sec-symbol.keyfor
  16039. keyFor: function keyFor(sym) {
  16040. if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol');
  16041. if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
  16042. },
  16043. useSetter: function () { USE_SETTER = true; },
  16044. useSimple: function () { USE_SETTER = false; }
  16045. });
  16046. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {
  16047. // `Object.create` method
  16048. // https://tc39.github.io/ecma262/#sec-object.create
  16049. create: $create,
  16050. // `Object.defineProperty` method
  16051. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  16052. defineProperty: $defineProperty,
  16053. // `Object.defineProperties` method
  16054. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  16055. defineProperties: $defineProperties,
  16056. // `Object.getOwnPropertyDescriptor` method
  16057. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
  16058. getOwnPropertyDescriptor: $getOwnPropertyDescriptor
  16059. });
  16060. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {
  16061. // `Object.getOwnPropertyNames` method
  16062. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  16063. getOwnPropertyNames: $getOwnPropertyNames,
  16064. // `Object.getOwnPropertySymbols` method
  16065. // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols
  16066. getOwnPropertySymbols: $getOwnPropertySymbols
  16067. });
  16068. // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
  16069. // https://bugs.chromium.org/p/v8/issues/detail?id=3443
  16070. $({ target: 'Object', stat: true, forced: fails(function () { getOwnPropertySymbolsModule.f(1); }) }, {
  16071. getOwnPropertySymbols: function getOwnPropertySymbols(it) {
  16072. return getOwnPropertySymbolsModule.f(toObject(it));
  16073. }
  16074. });
  16075. // `JSON.stringify` method behavior with symbols
  16076. // https://tc39.github.io/ecma262/#sec-json.stringify
  16077. if ($stringify) {
  16078. var FORCED_JSON_STRINGIFY = !NATIVE_SYMBOL || fails(function () {
  16079. var symbol = $Symbol();
  16080. // MS Edge converts symbol values to JSON as {}
  16081. return $stringify([symbol]) != '[null]'
  16082. // WebKit converts symbol values to JSON as null
  16083. || $stringify({ a: symbol }) != '{}'
  16084. // V8 throws on boxed symbols
  16085. || $stringify(Object(symbol)) != '{}';
  16086. });
  16087. $({ target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY }, {
  16088. // eslint-disable-next-line no-unused-vars
  16089. stringify: function stringify(it, replacer, space) {
  16090. var args = [it];
  16091. var index = 1;
  16092. var $replacer;
  16093. while (arguments.length > index) args.push(arguments[index++]);
  16094. $replacer = replacer;
  16095. if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined
  16096. if (!isArray(replacer)) replacer = function (key, value) {
  16097. if (typeof $replacer == 'function') value = $replacer.call(this, key, value);
  16098. if (!isSymbol(value)) return value;
  16099. };
  16100. args[1] = replacer;
  16101. return $stringify.apply(null, args);
  16102. }
  16103. });
  16104. }
  16105. // `Symbol.prototype[@@toPrimitive]` method
  16106. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive
  16107. if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) {
  16108. createNonEnumerableProperty($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf);
  16109. }
  16110. // `Symbol.prototype[@@toStringTag]` property
  16111. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag
  16112. setToStringTag($Symbol, SYMBOL);
  16113. hiddenKeys[HIDDEN] = true;
  16114. /***/ }),
  16115. /***/ "f4a0":
  16116. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  16117. "use strict";
  16118. // ESM COMPAT FLAG
  16119. __webpack_require__.r(__webpack_exports__);
  16120. // CONCATENATED MODULE: ./node_modules/_@vue_cli-service@4.3.1@@vue/cli-service/lib/commands/build/setPublicPath.js
  16121. // This file is imported into lib/wc client bundles.
  16122. if (typeof window !== 'undefined') {
  16123. var currentScript = window.document.currentScript
  16124. if (true) {
  16125. var getCurrentScript = __webpack_require__("c59c")
  16126. currentScript = getCurrentScript()
  16127. // for backward compatibility, because previously we directly included the polyfill
  16128. if (!('currentScript' in document)) {
  16129. Object.defineProperty(document, 'currentScript', { get: getCurrentScript })
  16130. }
  16131. }
  16132. var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
  16133. if (src) {
  16134. __webpack_require__.p = src[1] // eslint-disable-line
  16135. }
  16136. }
  16137. // Indicate to webpack that this file can be concatenated
  16138. /* harmony default export */ var setPublicPath = (null);
  16139. // CONCATENATED MODULE: ./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"4c89fd45-vue-loader-template"}!./node_modules/_vue-loader@15.9.2@vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js??ref--0-0!./node_modules/_vue-loader@15.9.2@vue-loader/lib??vue-loader-options!./src/components/index.vue?vue&type=template&id=d2bcce84&
  16140. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"simple-mde",class:_vm.classes},[_c('textarea',{ref:"mde"})])}
  16141. var staticRenderFns = []
  16142. // CONCATENATED MODULE: ./src/components/index.vue?vue&type=template&id=d2bcce84&
  16143. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.symbol.js
  16144. var es_symbol = __webpack_require__("f3dd");
  16145. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.array.filter.js
  16146. var es_array_filter = __webpack_require__("dbb3");
  16147. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.array.for-each.js
  16148. var es_array_for_each = __webpack_require__("fe59");
  16149. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.object.get-own-property-descriptor.js
  16150. var es_object_get_own_property_descriptor = __webpack_require__("b73f");
  16151. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.object.get-own-property-descriptors.js
  16152. var es_object_get_own_property_descriptors = __webpack_require__("bf84");
  16153. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.object.keys.js
  16154. var es_object_keys = __webpack_require__("fe8a");
  16155. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/web.dom-collections.for-each.js
  16156. var web_dom_collections_for_each = __webpack_require__("08ba");
  16157. // CONCATENATED MODULE: ./node_modules/_@babel_runtime@7.9.6@@babel/runtime/helpers/esm/defineProperty.js
  16158. function _defineProperty(obj, key, value) {
  16159. if (key in obj) {
  16160. Object.defineProperty(obj, key, {
  16161. value: value,
  16162. enumerable: true,
  16163. configurable: true,
  16164. writable: true
  16165. });
  16166. } else {
  16167. obj[key] = value;
  16168. }
  16169. return obj;
  16170. }
  16171. // CONCATENATED MODULE: ./node_modules/_@babel_runtime@7.9.6@@babel/runtime/helpers/esm/objectSpread2.js
  16172. function ownKeys(object, enumerableOnly) {
  16173. var keys = Object.keys(object);
  16174. if (Object.getOwnPropertySymbols) {
  16175. var symbols = Object.getOwnPropertySymbols(object);
  16176. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  16177. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  16178. });
  16179. keys.push.apply(keys, symbols);
  16180. }
  16181. return keys;
  16182. }
  16183. function _objectSpread2(target) {
  16184. for (var i = 1; i < arguments.length; i++) {
  16185. var source = arguments[i] != null ? arguments[i] : {};
  16186. if (i % 2) {
  16187. ownKeys(Object(source), true).forEach(function (key) {
  16188. _defineProperty(target, key, source[key]);
  16189. });
  16190. } else if (Object.getOwnPropertyDescriptors) {
  16191. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  16192. } else {
  16193. ownKeys(Object(source)).forEach(function (key) {
  16194. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  16195. });
  16196. }
  16197. }
  16198. return target;
  16199. }
  16200. // EXTERNAL MODULE: ./node_modules/_font-awesome@4.7.0@font-awesome/css/font-awesome.min.css
  16201. var font_awesome_min = __webpack_require__("508f");
  16202. // EXTERNAL MODULE: ./node_modules/_simplemde@1.11.2@simplemde/src/js/simplemde.js
  16203. var simplemde = __webpack_require__("4d02");
  16204. var simplemde_default = /*#__PURE__*/__webpack_require__.n(simplemde);
  16205. // EXTERNAL MODULE: ./node_modules/_simplemde@1.11.2@simplemde/dist/simplemde.min.css
  16206. var simplemde_min = __webpack_require__("ccf5");
  16207. // EXTERNAL MODULE: ./node_modules/_marked@1.0.0@marked/src/marked.js
  16208. var marked = __webpack_require__("094f");
  16209. var marked_default = /*#__PURE__*/__webpack_require__.n(marked);
  16210. // EXTERNAL MODULE: ./node_modules/_github-markdown-css@4.0.0@github-markdown-css/github-markdown.css
  16211. var github_markdown = __webpack_require__("0e50");
  16212. // CONCATENATED MODULE: ./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js??ref--12-0!./node_modules/_thread-loader@2.1.3@thread-loader/dist/cjs.js!./node_modules/_babel-loader@8.1.0@babel-loader/lib!./node_modules/_cache-loader@4.1.0@cache-loader/dist/cjs.js??ref--0-0!./node_modules/_vue-loader@15.9.2@vue-loader/lib??vue-loader-options!./src/components/index.vue?vue&type=script&lang=js&
  16213. //
  16214. //
  16215. //
  16216. //
  16217. //
  16218. /* harmony default export */ var componentsvue_type_script_lang_js_ = ({
  16219. name: "MarkdownEditor",
  16220. props: {
  16221. value: {
  16222. type: String,
  16223. default: ""
  16224. },
  16225. border: {
  16226. type: Boolean,
  16227. default: false
  16228. },
  16229. config: {
  16230. type: Object,
  16231. default: function _default() {
  16232. return {};
  16233. }
  16234. }
  16235. },
  16236. data: function data() {
  16237. return {
  16238. mde: null,
  16239. defaultConfig: {}
  16240. };
  16241. },
  16242. computed: {
  16243. classes: function classes() {
  16244. return [{
  16245. "i-mde-no-border": !this.border
  16246. }];
  16247. }
  16248. },
  16249. mounted: function mounted() {
  16250. this.init();
  16251. },
  16252. beforeDestroy: function beforeDestroy() {
  16253. this.mde = null;
  16254. },
  16255. methods: {
  16256. init: function init() {
  16257. var _this = this;
  16258. var config = Object.assign({}, this.defaultConfig, this.config);
  16259. this.mde = new simplemde_default.a(_objectSpread2(_objectSpread2({}, config), {}, {
  16260. initialValue: this.value,
  16261. element: this.$refs.mde,
  16262. autoDownloadFontAwesome: false
  16263. }));
  16264. this.mde.codemirror.on("change", function () {
  16265. _this.$emit("input", _this.mde.value());
  16266. _this.$emit("on-change", _this.mde.value());
  16267. var mdHtml = marked_default()(_this.mde.value() || "", {
  16268. renderer: new marked_default.a.Renderer(),
  16269. gfm: true,
  16270. tables: true,
  16271. breaks: false,
  16272. pedantic: false,
  16273. sanitize: false,
  16274. smartLists: true,
  16275. smartypants: false
  16276. });
  16277. _this.$emit("show-html", '<div class="markdown-body" >' + mdHtml + "</div>");
  16278. });
  16279. },
  16280. add: function add(val) {
  16281. if (this.mde) {
  16282. this.mde.value(this.value + val);
  16283. }
  16284. },
  16285. replace: function replace(val) {
  16286. if (this.mde) {
  16287. this.mde.value(val);
  16288. }
  16289. }
  16290. }
  16291. });
  16292. // CONCATENATED MODULE: ./src/components/index.vue?vue&type=script&lang=js&
  16293. /* harmony default export */ var src_componentsvue_type_script_lang_js_ = (componentsvue_type_script_lang_js_);
  16294. // CONCATENATED MODULE: ./node_modules/_vue-loader@15.9.2@vue-loader/lib/runtime/componentNormalizer.js
  16295. /* globals __VUE_SSR_CONTEXT__ */
  16296. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  16297. // This module is a runtime utility for cleaner component module output and will
  16298. // be included in the final webpack user bundle.
  16299. function normalizeComponent (
  16300. scriptExports,
  16301. render,
  16302. staticRenderFns,
  16303. functionalTemplate,
  16304. injectStyles,
  16305. scopeId,
  16306. moduleIdentifier, /* server only */
  16307. shadowMode /* vue-cli only */
  16308. ) {
  16309. // Vue.extend constructor export interop
  16310. var options = typeof scriptExports === 'function'
  16311. ? scriptExports.options
  16312. : scriptExports
  16313. // render functions
  16314. if (render) {
  16315. options.render = render
  16316. options.staticRenderFns = staticRenderFns
  16317. options._compiled = true
  16318. }
  16319. // functional template
  16320. if (functionalTemplate) {
  16321. options.functional = true
  16322. }
  16323. // scopedId
  16324. if (scopeId) {
  16325. options._scopeId = 'data-v-' + scopeId
  16326. }
  16327. var hook
  16328. if (moduleIdentifier) { // server build
  16329. hook = function (context) {
  16330. // 2.3 injection
  16331. context =
  16332. context || // cached call
  16333. (this.$vnode && this.$vnode.ssrContext) || // stateful
  16334. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  16335. // 2.2 with runInNewContext: true
  16336. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  16337. context = __VUE_SSR_CONTEXT__
  16338. }
  16339. // inject component styles
  16340. if (injectStyles) {
  16341. injectStyles.call(this, context)
  16342. }
  16343. // register component module identifier for async chunk inferrence
  16344. if (context && context._registeredComponents) {
  16345. context._registeredComponents.add(moduleIdentifier)
  16346. }
  16347. }
  16348. // used by ssr in case component is cached and beforeCreate
  16349. // never gets called
  16350. options._ssrRegister = hook
  16351. } else if (injectStyles) {
  16352. hook = shadowMode
  16353. ? function () {
  16354. injectStyles.call(
  16355. this,
  16356. (options.functional ? this.parent : this).$root.$options.shadowRoot
  16357. )
  16358. }
  16359. : injectStyles
  16360. }
  16361. if (hook) {
  16362. if (options.functional) {
  16363. // for template-only hot-reload because in that case the render fn doesn't
  16364. // go through the normalizer
  16365. options._injectStyles = hook
  16366. // register for functional component in vue file
  16367. var originalRender = options.render
  16368. options.render = function renderWithStyleInjection (h, context) {
  16369. hook.call(context)
  16370. return originalRender(h, context)
  16371. }
  16372. } else {
  16373. // inject component registration as beforeCreate hook
  16374. var existing = options.beforeCreate
  16375. options.beforeCreate = existing
  16376. ? [].concat(existing, hook)
  16377. : [hook]
  16378. }
  16379. }
  16380. return {
  16381. exports: scriptExports,
  16382. options: options
  16383. }
  16384. }
  16385. // CONCATENATED MODULE: ./src/components/index.vue
  16386. /* normalize component */
  16387. var component = normalizeComponent(
  16388. src_componentsvue_type_script_lang_js_,
  16389. render,
  16390. staticRenderFns,
  16391. false,
  16392. null,
  16393. null,
  16394. null
  16395. )
  16396. /* harmony default export */ var components = (component.exports);
  16397. // CONCATENATED MODULE: ./src/components/export.js
  16398. /* harmony default export */ var components_export = (components);
  16399. if (typeof window !== "undefined" && window.Vue) {
  16400. window.Vue.component("zx-markdown-editor", components);
  16401. }
  16402. // CONCATENATED MODULE: ./node_modules/_@vue_cli-service@4.3.1@@vue/cli-service/lib/commands/build/entry-lib.js
  16403. /* harmony default export */ var entry_lib = __webpack_exports__["default"] = (components_export);
  16404. /***/ }),
  16405. /***/ "f590":
  16406. /***/ (function(module, exports, __webpack_require__) {
  16407. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  16408. // Distributed under an MIT license: https://codemirror.net/LICENSE
  16409. (function(mod) {
  16410. if (true) // CommonJS
  16411. mod(__webpack_require__("a564"));
  16412. else {}
  16413. })(function(CodeMirror) {
  16414. CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
  16415. var prev = old && old != CodeMirror.Init;
  16416. if (val && !prev) {
  16417. cm.on("blur", onBlur);
  16418. cm.on("change", onChange);
  16419. cm.on("swapDoc", onChange);
  16420. onChange(cm);
  16421. } else if (!val && prev) {
  16422. cm.off("blur", onBlur);
  16423. cm.off("change", onChange);
  16424. cm.off("swapDoc", onChange);
  16425. clearPlaceholder(cm);
  16426. var wrapper = cm.getWrapperElement();
  16427. wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
  16428. }
  16429. if (val && !cm.hasFocus()) onBlur(cm);
  16430. });
  16431. function clearPlaceholder(cm) {
  16432. if (cm.state.placeholder) {
  16433. cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
  16434. cm.state.placeholder = null;
  16435. }
  16436. }
  16437. function setPlaceholder(cm) {
  16438. clearPlaceholder(cm);
  16439. var elt = cm.state.placeholder = document.createElement("pre");
  16440. elt.style.cssText = "height: 0; overflow: visible";
  16441. elt.style.direction = cm.getOption("direction");
  16442. elt.className = "CodeMirror-placeholder CodeMirror-line-like";
  16443. var placeHolder = cm.getOption("placeholder")
  16444. if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
  16445. elt.appendChild(placeHolder)
  16446. cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
  16447. }
  16448. function onBlur(cm) {
  16449. if (isEmpty(cm)) setPlaceholder(cm);
  16450. }
  16451. function onChange(cm) {
  16452. var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
  16453. wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
  16454. if (empty) setPlaceholder(cm);
  16455. else clearPlaceholder(cm);
  16456. }
  16457. function isEmpty(cm) {
  16458. return (cm.lineCount() === 1) && (cm.getLine(0) === "");
  16459. }
  16460. });
  16461. /***/ }),
  16462. /***/ "f594":
  16463. /***/ (function(module, exports, __webpack_require__) {
  16464. var global = __webpack_require__("d890");
  16465. var userAgent = __webpack_require__("4fda");
  16466. var process = global.process;
  16467. var versions = process && process.versions;
  16468. var v8 = versions && versions.v8;
  16469. var match, version;
  16470. if (v8) {
  16471. match = v8.split('.');
  16472. version = match[0] + match[1];
  16473. } else if (userAgent) {
  16474. match = userAgent.match(/Edge\/(\d+)/);
  16475. if (!match || match[1] >= 74) {
  16476. match = userAgent.match(/Chrome\/(\d+)/);
  16477. if (match) version = match[1];
  16478. }
  16479. }
  16480. module.exports = version && +version;
  16481. /***/ }),
  16482. /***/ "f5ef":
  16483. /***/ (function(module, exports) {
  16484. /**
  16485. * TextRenderer
  16486. * returns only the textual part of the token
  16487. */
  16488. module.exports = class TextRenderer {
  16489. // no need for block level renderers
  16490. strong(text) {
  16491. return text;
  16492. }
  16493. em(text) {
  16494. return text;
  16495. }
  16496. codespan(text) {
  16497. return text;
  16498. }
  16499. del(text) {
  16500. return text;
  16501. }
  16502. html(text) {
  16503. return text;
  16504. }
  16505. text(text) {
  16506. return text;
  16507. }
  16508. link(href, title, text) {
  16509. return '' + text;
  16510. }
  16511. image(href, title, text) {
  16512. return '' + text;
  16513. }
  16514. br() {
  16515. return '';
  16516. }
  16517. };
  16518. /***/ }),
  16519. /***/ "faa8":
  16520. /***/ (function(module, exports) {
  16521. var hasOwnProperty = {}.hasOwnProperty;
  16522. module.exports = function (it, key) {
  16523. return hasOwnProperty.call(it, key);
  16524. };
  16525. /***/ }),
  16526. /***/ "fe59":
  16527. /***/ (function(module, exports, __webpack_require__) {
  16528. "use strict";
  16529. var $ = __webpack_require__("1c8b");
  16530. var forEach = __webpack_require__("3c10");
  16531. // `Array.prototype.forEach` method
  16532. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  16533. $({ target: 'Array', proto: true, forced: [].forEach != forEach }, {
  16534. forEach: forEach
  16535. });
  16536. /***/ }),
  16537. /***/ "fe5a":
  16538. /***/ (function(module, exports, __webpack_require__) {
  16539. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  16540. // Distributed under an MIT license: https://codemirror.net/LICENSE
  16541. (function(mod) {
  16542. if (true) // CommonJS
  16543. mod(__webpack_require__("a564"), __webpack_require__("b2e0"), __webpack_require__("6d86"));
  16544. else {}
  16545. })(function(CodeMirror) {
  16546. "use strict";
  16547. CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
  16548. var htmlMode = CodeMirror.getMode(cmCfg, "text/html");
  16549. var htmlModeMissing = htmlMode.name == "null"
  16550. function getMode(name) {
  16551. if (CodeMirror.findModeByName) {
  16552. var found = CodeMirror.findModeByName(name);
  16553. if (found) name = found.mime || found.mimes[0];
  16554. }
  16555. var mode = CodeMirror.getMode(cmCfg, name);
  16556. return mode.name == "null" ? null : mode;
  16557. }
  16558. // Should characters that affect highlighting be highlighted separate?
  16559. // Does not include characters that will be output (such as `1.` and `-` for lists)
  16560. if (modeCfg.highlightFormatting === undefined)
  16561. modeCfg.highlightFormatting = false;
  16562. // Maximum number of nested blockquotes. Set to 0 for infinite nesting.
  16563. // Excess `>` will emit `error` token.
  16564. if (modeCfg.maxBlockquoteDepth === undefined)
  16565. modeCfg.maxBlockquoteDepth = 0;
  16566. // Turn on task lists? ("- [ ] " and "- [x] ")
  16567. if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
  16568. // Turn on strikethrough syntax
  16569. if (modeCfg.strikethrough === undefined)
  16570. modeCfg.strikethrough = false;
  16571. if (modeCfg.emoji === undefined)
  16572. modeCfg.emoji = false;
  16573. if (modeCfg.fencedCodeBlockHighlighting === undefined)
  16574. modeCfg.fencedCodeBlockHighlighting = true;
  16575. if (modeCfg.xml === undefined)
  16576. modeCfg.xml = true;
  16577. // Allow token types to be overridden by user-provided token types.
  16578. if (modeCfg.tokenTypeOverrides === undefined)
  16579. modeCfg.tokenTypeOverrides = {};
  16580. var tokenTypes = {
  16581. header: "header",
  16582. code: "comment",
  16583. quote: "quote",
  16584. list1: "variable-2",
  16585. list2: "variable-3",
  16586. list3: "keyword",
  16587. hr: "hr",
  16588. image: "image",
  16589. imageAltText: "image-alt-text",
  16590. imageMarker: "image-marker",
  16591. formatting: "formatting",
  16592. linkInline: "link",
  16593. linkEmail: "link",
  16594. linkText: "link",
  16595. linkHref: "string",
  16596. em: "em",
  16597. strong: "strong",
  16598. strikethrough: "strikethrough",
  16599. emoji: "builtin"
  16600. };
  16601. for (var tokenType in tokenTypes) {
  16602. if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {
  16603. tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];
  16604. }
  16605. }
  16606. var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
  16607. , listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/
  16608. , taskListRE = /^\[(x| )\](?=\s)/i // Must follow listRE
  16609. , atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
  16610. , setextHeaderRE = /^ {0,3}(?:\={1,}|-{2,})\s*$/
  16611. , textRE = /^[^#!\[\]*_\\<>` "'(~:]+/
  16612. , fencedCodeRE = /^(~~~+|```+)[ \t]*([\w+#-]*)[^\n`]*$/
  16613. , linkDefRE = /^\s*\[[^\]]+?\]:.*$/ // naive link-definition
  16614. , punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/
  16615. , expandedTab = " " // CommonMark specifies tab as 4 spaces
  16616. function switchInline(stream, state, f) {
  16617. state.f = state.inline = f;
  16618. return f(stream, state);
  16619. }
  16620. function switchBlock(stream, state, f) {
  16621. state.f = state.block = f;
  16622. return f(stream, state);
  16623. }
  16624. function lineIsEmpty(line) {
  16625. return !line || !/\S/.test(line.string)
  16626. }
  16627. // Blocks
  16628. function blankLine(state) {
  16629. // Reset linkTitle state
  16630. state.linkTitle = false;
  16631. state.linkHref = false;
  16632. state.linkText = false;
  16633. // Reset EM state
  16634. state.em = false;
  16635. // Reset STRONG state
  16636. state.strong = false;
  16637. // Reset strikethrough state
  16638. state.strikethrough = false;
  16639. // Reset state.quote
  16640. state.quote = 0;
  16641. // Reset state.indentedCode
  16642. state.indentedCode = false;
  16643. if (state.f == htmlBlock) {
  16644. var exit = htmlModeMissing
  16645. if (!exit) {
  16646. var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
  16647. exit = inner.mode.name == "xml" && inner.state.tagStart === null &&
  16648. (!inner.state.context && inner.state.tokenize.isInText)
  16649. }
  16650. if (exit) {
  16651. state.f = inlineNormal;
  16652. state.block = blockNormal;
  16653. state.htmlState = null;
  16654. }
  16655. }
  16656. // Reset state.trailingSpace
  16657. state.trailingSpace = 0;
  16658. state.trailingSpaceNewLine = false;
  16659. // Mark this line as blank
  16660. state.prevLine = state.thisLine
  16661. state.thisLine = {stream: null}
  16662. return null;
  16663. }
  16664. function blockNormal(stream, state) {
  16665. var firstTokenOnLine = stream.column() === state.indentation;
  16666. var prevLineLineIsEmpty = lineIsEmpty(state.prevLine.stream);
  16667. var prevLineIsIndentedCode = state.indentedCode;
  16668. var prevLineIsHr = state.prevLine.hr;
  16669. var prevLineIsList = state.list !== false;
  16670. var maxNonCodeIndentation = (state.listStack[state.listStack.length - 1] || 0) + 3;
  16671. state.indentedCode = false;
  16672. var lineIndentation = state.indentation;
  16673. // compute once per line (on first token)
  16674. if (state.indentationDiff === null) {
  16675. state.indentationDiff = state.indentation;
  16676. if (prevLineIsList) {
  16677. state.list = null;
  16678. // While this list item's marker's indentation is less than the deepest
  16679. // list item's content's indentation,pop the deepest list item
  16680. // indentation off the stack, and update block indentation state
  16681. while (lineIndentation < state.listStack[state.listStack.length - 1]) {
  16682. state.listStack.pop();
  16683. if (state.listStack.length) {
  16684. state.indentation = state.listStack[state.listStack.length - 1];
  16685. // less than the first list's indent -> the line is no longer a list
  16686. } else {
  16687. state.list = false;
  16688. }
  16689. }
  16690. if (state.list !== false) {
  16691. state.indentationDiff = lineIndentation - state.listStack[state.listStack.length - 1]
  16692. }
  16693. }
  16694. }
  16695. // not comprehensive (currently only for setext detection purposes)
  16696. var allowsInlineContinuation = (
  16697. !prevLineLineIsEmpty && !prevLineIsHr && !state.prevLine.header &&
  16698. (!prevLineIsList || !prevLineIsIndentedCode) &&
  16699. !state.prevLine.fencedCodeEnd
  16700. );
  16701. var isHr = (state.list === false || prevLineIsHr || prevLineLineIsEmpty) &&
  16702. state.indentation <= maxNonCodeIndentation && stream.match(hrRE);
  16703. var match = null;
  16704. if (state.indentationDiff >= 4 && (prevLineIsIndentedCode || state.prevLine.fencedCodeEnd ||
  16705. state.prevLine.header || prevLineLineIsEmpty)) {
  16706. stream.skipToEnd();
  16707. state.indentedCode = true;
  16708. return tokenTypes.code;
  16709. } else if (stream.eatSpace()) {
  16710. return null;
  16711. } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
  16712. state.quote = 0;
  16713. state.header = match[1].length;
  16714. state.thisLine.header = true;
  16715. if (modeCfg.highlightFormatting) state.formatting = "header";
  16716. state.f = state.inline;
  16717. return getType(state);
  16718. } else if (state.indentation <= maxNonCodeIndentation && stream.eat('>')) {
  16719. state.quote = firstTokenOnLine ? 1 : state.quote + 1;
  16720. if (modeCfg.highlightFormatting) state.formatting = "quote";
  16721. stream.eatSpace();
  16722. return getType(state);
  16723. } else if (!isHr && !state.setext && firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(listRE))) {
  16724. var listType = match[1] ? "ol" : "ul";
  16725. state.indentation = lineIndentation + stream.current().length;
  16726. state.list = true;
  16727. state.quote = 0;
  16728. // Add this list item's content's indentation to the stack
  16729. state.listStack.push(state.indentation);
  16730. // Reset inline styles which shouldn't propagate aross list items
  16731. state.em = false;
  16732. state.strong = false;
  16733. state.code = false;
  16734. state.strikethrough = false;
  16735. if (modeCfg.taskLists && stream.match(taskListRE, false)) {
  16736. state.taskList = true;
  16737. }
  16738. state.f = state.inline;
  16739. if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
  16740. return getType(state);
  16741. } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedCodeRE, true))) {
  16742. state.quote = 0;
  16743. state.fencedEndRE = new RegExp(match[1] + "+ *$");
  16744. // try switching mode
  16745. state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2]);
  16746. if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
  16747. state.f = state.block = local;
  16748. if (modeCfg.highlightFormatting) state.formatting = "code-block";
  16749. state.code = -1
  16750. return getType(state);
  16751. // SETEXT has lowest block-scope precedence after HR, so check it after
  16752. // the others (code, blockquote, list...)
  16753. } else if (
  16754. // if setext set, indicates line after ---/===
  16755. state.setext || (
  16756. // line before ---/===
  16757. (!allowsInlineContinuation || !prevLineIsList) && !state.quote && state.list === false &&
  16758. !state.code && !isHr && !linkDefRE.test(stream.string) &&
  16759. (match = stream.lookAhead(1)) && (match = match.match(setextHeaderRE))
  16760. )
  16761. ) {
  16762. if ( !state.setext ) {
  16763. state.header = match[0].charAt(0) == '=' ? 1 : 2;
  16764. state.setext = state.header;
  16765. } else {
  16766. state.header = state.setext;
  16767. // has no effect on type so we can reset it now
  16768. state.setext = 0;
  16769. stream.skipToEnd();
  16770. if (modeCfg.highlightFormatting) state.formatting = "header";
  16771. }
  16772. state.thisLine.header = true;
  16773. state.f = state.inline;
  16774. return getType(state);
  16775. } else if (isHr) {
  16776. stream.skipToEnd();
  16777. state.hr = true;
  16778. state.thisLine.hr = true;
  16779. return tokenTypes.hr;
  16780. } else if (stream.peek() === '[') {
  16781. return switchInline(stream, state, footnoteLink);
  16782. }
  16783. return switchInline(stream, state, state.inline);
  16784. }
  16785. function htmlBlock(stream, state) {
  16786. var style = htmlMode.token(stream, state.htmlState);
  16787. if (!htmlModeMissing) {
  16788. var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
  16789. if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
  16790. (!inner.state.context && inner.state.tokenize.isInText)) ||
  16791. (state.md_inside && stream.current().indexOf(">") > -1)) {
  16792. state.f = inlineNormal;
  16793. state.block = blockNormal;
  16794. state.htmlState = null;
  16795. }
  16796. }
  16797. return style;
  16798. }
  16799. function local(stream, state) {
  16800. var currListInd = state.listStack[state.listStack.length - 1] || 0;
  16801. var hasExitedList = state.indentation < currListInd;
  16802. var maxFencedEndInd = currListInd + 3;
  16803. if (state.fencedEndRE && state.indentation <= maxFencedEndInd && (hasExitedList || stream.match(state.fencedEndRE))) {
  16804. if (modeCfg.highlightFormatting) state.formatting = "code-block";
  16805. var returnType;
  16806. if (!hasExitedList) returnType = getType(state)
  16807. state.localMode = state.localState = null;
  16808. state.block = blockNormal;
  16809. state.f = inlineNormal;
  16810. state.fencedEndRE = null;
  16811. state.code = 0
  16812. state.thisLine.fencedCodeEnd = true;
  16813. if (hasExitedList) return switchBlock(stream, state, state.block);
  16814. return returnType;
  16815. } else if (state.localMode) {
  16816. return state.localMode.token(stream, state.localState);
  16817. } else {
  16818. stream.skipToEnd();
  16819. return tokenTypes.code;
  16820. }
  16821. }
  16822. // Inline
  16823. function getType(state) {
  16824. var styles = [];
  16825. if (state.formatting) {
  16826. styles.push(tokenTypes.formatting);
  16827. if (typeof state.formatting === "string") state.formatting = [state.formatting];
  16828. for (var i = 0; i < state.formatting.length; i++) {
  16829. styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
  16830. if (state.formatting[i] === "header") {
  16831. styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
  16832. }
  16833. // Add `formatting-quote` and `formatting-quote-#` for blockquotes
  16834. // Add `error` instead if the maximum blockquote nesting depth is passed
  16835. if (state.formatting[i] === "quote") {
  16836. if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
  16837. styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
  16838. } else {
  16839. styles.push("error");
  16840. }
  16841. }
  16842. }
  16843. }
  16844. if (state.taskOpen) {
  16845. styles.push("meta");
  16846. return styles.length ? styles.join(' ') : null;
  16847. }
  16848. if (state.taskClosed) {
  16849. styles.push("property");
  16850. return styles.length ? styles.join(' ') : null;
  16851. }
  16852. if (state.linkHref) {
  16853. styles.push(tokenTypes.linkHref, "url");
  16854. } else { // Only apply inline styles to non-url text
  16855. if (state.strong) { styles.push(tokenTypes.strong); }
  16856. if (state.em) { styles.push(tokenTypes.em); }
  16857. if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
  16858. if (state.emoji) { styles.push(tokenTypes.emoji); }
  16859. if (state.linkText) { styles.push(tokenTypes.linkText); }
  16860. if (state.code) { styles.push(tokenTypes.code); }
  16861. if (state.image) { styles.push(tokenTypes.image); }
  16862. if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }
  16863. if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }
  16864. }
  16865. if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
  16866. if (state.quote) {
  16867. styles.push(tokenTypes.quote);
  16868. // Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
  16869. if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
  16870. styles.push(tokenTypes.quote + "-" + state.quote);
  16871. } else {
  16872. styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
  16873. }
  16874. }
  16875. if (state.list !== false) {
  16876. var listMod = (state.listStack.length - 1) % 3;
  16877. if (!listMod) {
  16878. styles.push(tokenTypes.list1);
  16879. } else if (listMod === 1) {
  16880. styles.push(tokenTypes.list2);
  16881. } else {
  16882. styles.push(tokenTypes.list3);
  16883. }
  16884. }
  16885. if (state.trailingSpaceNewLine) {
  16886. styles.push("trailing-space-new-line");
  16887. } else if (state.trailingSpace) {
  16888. styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
  16889. }
  16890. return styles.length ? styles.join(' ') : null;
  16891. }
  16892. function handleText(stream, state) {
  16893. if (stream.match(textRE, true)) {
  16894. return getType(state);
  16895. }
  16896. return undefined;
  16897. }
  16898. function inlineNormal(stream, state) {
  16899. var style = state.text(stream, state);
  16900. if (typeof style !== 'undefined')
  16901. return style;
  16902. if (state.list) { // List marker (*, +, -, 1., etc)
  16903. state.list = null;
  16904. return getType(state);
  16905. }
  16906. if (state.taskList) {
  16907. var taskOpen = stream.match(taskListRE, true)[1] === " ";
  16908. if (taskOpen) state.taskOpen = true;
  16909. else state.taskClosed = true;
  16910. if (modeCfg.highlightFormatting) state.formatting = "task";
  16911. state.taskList = false;
  16912. return getType(state);
  16913. }
  16914. state.taskOpen = false;
  16915. state.taskClosed = false;
  16916. if (state.header && stream.match(/^#+$/, true)) {
  16917. if (modeCfg.highlightFormatting) state.formatting = "header";
  16918. return getType(state);
  16919. }
  16920. var ch = stream.next();
  16921. // Matches link titles present on next line
  16922. if (state.linkTitle) {
  16923. state.linkTitle = false;
  16924. var matchCh = ch;
  16925. if (ch === '(') {
  16926. matchCh = ')';
  16927. }
  16928. matchCh = (matchCh+'').replace(/([.?*+^\[\]\\(){}|-])/g, "\\$1");
  16929. var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
  16930. if (stream.match(new RegExp(regex), true)) {
  16931. return tokenTypes.linkHref;
  16932. }
  16933. }
  16934. // If this block is changed, it may need to be updated in GFM mode
  16935. if (ch === '`') {
  16936. var previousFormatting = state.formatting;
  16937. if (modeCfg.highlightFormatting) state.formatting = "code";
  16938. stream.eatWhile('`');
  16939. var count = stream.current().length
  16940. if (state.code == 0 && (!state.quote || count == 1)) {
  16941. state.code = count
  16942. return getType(state)
  16943. } else if (count == state.code) { // Must be exact
  16944. var t = getType(state)
  16945. state.code = 0
  16946. return t
  16947. } else {
  16948. state.formatting = previousFormatting
  16949. return getType(state)
  16950. }
  16951. } else if (state.code) {
  16952. return getType(state);
  16953. }
  16954. if (ch === '\\') {
  16955. stream.next();
  16956. if (modeCfg.highlightFormatting) {
  16957. var type = getType(state);
  16958. var formattingEscape = tokenTypes.formatting + "-escape";
  16959. return type ? type + " " + formattingEscape : formattingEscape;
  16960. }
  16961. }
  16962. if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
  16963. state.imageMarker = true;
  16964. state.image = true;
  16965. if (modeCfg.highlightFormatting) state.formatting = "image";
  16966. return getType(state);
  16967. }
  16968. if (ch === '[' && state.imageMarker && stream.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/, false)) {
  16969. state.imageMarker = false;
  16970. state.imageAltText = true
  16971. if (modeCfg.highlightFormatting) state.formatting = "image";
  16972. return getType(state);
  16973. }
  16974. if (ch === ']' && state.imageAltText) {
  16975. if (modeCfg.highlightFormatting) state.formatting = "image";
  16976. var type = getType(state);
  16977. state.imageAltText = false;
  16978. state.image = false;
  16979. state.inline = state.f = linkHref;
  16980. return type;
  16981. }
  16982. if (ch === '[' && !state.image) {
  16983. if (state.linkText && stream.match(/^.*?\]/)) return getType(state)
  16984. state.linkText = true;
  16985. if (modeCfg.highlightFormatting) state.formatting = "link";
  16986. return getType(state);
  16987. }
  16988. if (ch === ']' && state.linkText) {
  16989. if (modeCfg.highlightFormatting) state.formatting = "link";
  16990. var type = getType(state);
  16991. state.linkText = false;
  16992. state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal
  16993. return type;
  16994. }
  16995. if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
  16996. state.f = state.inline = linkInline;
  16997. if (modeCfg.highlightFormatting) state.formatting = "link";
  16998. var type = getType(state);
  16999. if (type){
  17000. type += " ";
  17001. } else {
  17002. type = "";
  17003. }
  17004. return type + tokenTypes.linkInline;
  17005. }
  17006. if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
  17007. state.f = state.inline = linkInline;
  17008. if (modeCfg.highlightFormatting) state.formatting = "link";
  17009. var type = getType(state);
  17010. if (type){
  17011. type += " ";
  17012. } else {
  17013. type = "";
  17014. }
  17015. return type + tokenTypes.linkEmail;
  17016. }
  17017. if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {
  17018. var end = stream.string.indexOf(">", stream.pos);
  17019. if (end != -1) {
  17020. var atts = stream.string.substring(stream.start, end);
  17021. if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
  17022. }
  17023. stream.backUp(1);
  17024. state.htmlState = CodeMirror.startState(htmlMode);
  17025. return switchBlock(stream, state, htmlBlock);
  17026. }
  17027. if (modeCfg.xml && ch === '<' && stream.match(/^\/\w*?>/)) {
  17028. state.md_inside = false;
  17029. return "tag";
  17030. } else if (ch === "*" || ch === "_") {
  17031. var len = 1, before = stream.pos == 1 ? " " : stream.string.charAt(stream.pos - 2)
  17032. while (len < 3 && stream.eat(ch)) len++
  17033. var after = stream.peek() || " "
  17034. // See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis
  17035. var leftFlanking = !/\s/.test(after) && (!punctuation.test(after) || /\s/.test(before) || punctuation.test(before))
  17036. var rightFlanking = !/\s/.test(before) && (!punctuation.test(before) || /\s/.test(after) || punctuation.test(after))
  17037. var setEm = null, setStrong = null
  17038. if (len % 2) { // Em
  17039. if (!state.em && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
  17040. setEm = true
  17041. else if (state.em == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
  17042. setEm = false
  17043. }
  17044. if (len > 1) { // Strong
  17045. if (!state.strong && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
  17046. setStrong = true
  17047. else if (state.strong == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
  17048. setStrong = false
  17049. }
  17050. if (setStrong != null || setEm != null) {
  17051. if (modeCfg.highlightFormatting) state.formatting = setEm == null ? "strong" : setStrong == null ? "em" : "strong em"
  17052. if (setEm === true) state.em = ch
  17053. if (setStrong === true) state.strong = ch
  17054. var t = getType(state)
  17055. if (setEm === false) state.em = false
  17056. if (setStrong === false) state.strong = false
  17057. return t
  17058. }
  17059. } else if (ch === ' ') {
  17060. if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
  17061. if (stream.peek() === ' ') { // Surrounded by spaces, ignore
  17062. return getType(state);
  17063. } else { // Not surrounded by spaces, back up pointer
  17064. stream.backUp(1);
  17065. }
  17066. }
  17067. }
  17068. if (modeCfg.strikethrough) {
  17069. if (ch === '~' && stream.eatWhile(ch)) {
  17070. if (state.strikethrough) {// Remove strikethrough
  17071. if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
  17072. var t = getType(state);
  17073. state.strikethrough = false;
  17074. return t;
  17075. } else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
  17076. state.strikethrough = true;
  17077. if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
  17078. return getType(state);
  17079. }
  17080. } else if (ch === ' ') {
  17081. if (stream.match(/^~~/, true)) { // Probably surrounded by space
  17082. if (stream.peek() === ' ') { // Surrounded by spaces, ignore
  17083. return getType(state);
  17084. } else { // Not surrounded by spaces, back up pointer
  17085. stream.backUp(2);
  17086. }
  17087. }
  17088. }
  17089. }
  17090. if (modeCfg.emoji && ch === ":" && stream.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)) {
  17091. state.emoji = true;
  17092. if (modeCfg.highlightFormatting) state.formatting = "emoji";
  17093. var retType = getType(state);
  17094. state.emoji = false;
  17095. return retType;
  17096. }
  17097. if (ch === ' ') {
  17098. if (stream.match(/^ +$/, false)) {
  17099. state.trailingSpace++;
  17100. } else if (state.trailingSpace) {
  17101. state.trailingSpaceNewLine = true;
  17102. }
  17103. }
  17104. return getType(state);
  17105. }
  17106. function linkInline(stream, state) {
  17107. var ch = stream.next();
  17108. if (ch === ">") {
  17109. state.f = state.inline = inlineNormal;
  17110. if (modeCfg.highlightFormatting) state.formatting = "link";
  17111. var type = getType(state);
  17112. if (type){
  17113. type += " ";
  17114. } else {
  17115. type = "";
  17116. }
  17117. return type + tokenTypes.linkInline;
  17118. }
  17119. stream.match(/^[^>]+/, true);
  17120. return tokenTypes.linkInline;
  17121. }
  17122. function linkHref(stream, state) {
  17123. // Check if space, and return NULL if so (to avoid marking the space)
  17124. if(stream.eatSpace()){
  17125. return null;
  17126. }
  17127. var ch = stream.next();
  17128. if (ch === '(' || ch === '[') {
  17129. state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
  17130. if (modeCfg.highlightFormatting) state.formatting = "link-string";
  17131. state.linkHref = true;
  17132. return getType(state);
  17133. }
  17134. return 'error';
  17135. }
  17136. var linkRE = {
  17137. ")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
  17138. "]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/
  17139. }
  17140. function getLinkHrefInside(endChar) {
  17141. return function(stream, state) {
  17142. var ch = stream.next();
  17143. if (ch === endChar) {
  17144. state.f = state.inline = inlineNormal;
  17145. if (modeCfg.highlightFormatting) state.formatting = "link-string";
  17146. var returnState = getType(state);
  17147. state.linkHref = false;
  17148. return returnState;
  17149. }
  17150. stream.match(linkRE[endChar])
  17151. state.linkHref = true;
  17152. return getType(state);
  17153. };
  17154. }
  17155. function footnoteLink(stream, state) {
  17156. if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
  17157. state.f = footnoteLinkInside;
  17158. stream.next(); // Consume [
  17159. if (modeCfg.highlightFormatting) state.formatting = "link";
  17160. state.linkText = true;
  17161. return getType(state);
  17162. }
  17163. return switchInline(stream, state, inlineNormal);
  17164. }
  17165. function footnoteLinkInside(stream, state) {
  17166. if (stream.match(/^\]:/, true)) {
  17167. state.f = state.inline = footnoteUrl;
  17168. if (modeCfg.highlightFormatting) state.formatting = "link";
  17169. var returnType = getType(state);
  17170. state.linkText = false;
  17171. return returnType;
  17172. }
  17173. stream.match(/^([^\]\\]|\\.)+/, true);
  17174. return tokenTypes.linkText;
  17175. }
  17176. function footnoteUrl(stream, state) {
  17177. // Check if space, and return NULL if so (to avoid marking the space)
  17178. if(stream.eatSpace()){
  17179. return null;
  17180. }
  17181. // Match URL
  17182. stream.match(/^[^\s]+/, true);
  17183. // Check for link title
  17184. if (stream.peek() === undefined) { // End of line, set flag to check next line
  17185. state.linkTitle = true;
  17186. } else { // More content on line, check if link title
  17187. stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
  17188. }
  17189. state.f = state.inline = inlineNormal;
  17190. return tokenTypes.linkHref + " url";
  17191. }
  17192. var mode = {
  17193. startState: function() {
  17194. return {
  17195. f: blockNormal,
  17196. prevLine: {stream: null},
  17197. thisLine: {stream: null},
  17198. block: blockNormal,
  17199. htmlState: null,
  17200. indentation: 0,
  17201. inline: inlineNormal,
  17202. text: handleText,
  17203. formatting: false,
  17204. linkText: false,
  17205. linkHref: false,
  17206. linkTitle: false,
  17207. code: 0,
  17208. em: false,
  17209. strong: false,
  17210. header: 0,
  17211. setext: 0,
  17212. hr: false,
  17213. taskList: false,
  17214. list: false,
  17215. listStack: [],
  17216. quote: 0,
  17217. trailingSpace: 0,
  17218. trailingSpaceNewLine: false,
  17219. strikethrough: false,
  17220. emoji: false,
  17221. fencedEndRE: null
  17222. };
  17223. },
  17224. copyState: function(s) {
  17225. return {
  17226. f: s.f,
  17227. prevLine: s.prevLine,
  17228. thisLine: s.thisLine,
  17229. block: s.block,
  17230. htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
  17231. indentation: s.indentation,
  17232. localMode: s.localMode,
  17233. localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
  17234. inline: s.inline,
  17235. text: s.text,
  17236. formatting: false,
  17237. linkText: s.linkText,
  17238. linkTitle: s.linkTitle,
  17239. linkHref: s.linkHref,
  17240. code: s.code,
  17241. em: s.em,
  17242. strong: s.strong,
  17243. strikethrough: s.strikethrough,
  17244. emoji: s.emoji,
  17245. header: s.header,
  17246. setext: s.setext,
  17247. hr: s.hr,
  17248. taskList: s.taskList,
  17249. list: s.list,
  17250. listStack: s.listStack.slice(0),
  17251. quote: s.quote,
  17252. indentedCode: s.indentedCode,
  17253. trailingSpace: s.trailingSpace,
  17254. trailingSpaceNewLine: s.trailingSpaceNewLine,
  17255. md_inside: s.md_inside,
  17256. fencedEndRE: s.fencedEndRE
  17257. };
  17258. },
  17259. token: function(stream, state) {
  17260. // Reset state.formatting
  17261. state.formatting = false;
  17262. if (stream != state.thisLine.stream) {
  17263. state.header = 0;
  17264. state.hr = false;
  17265. if (stream.match(/^\s*$/, true)) {
  17266. blankLine(state);
  17267. return null;
  17268. }
  17269. state.prevLine = state.thisLine
  17270. state.thisLine = {stream: stream}
  17271. // Reset state.taskList
  17272. state.taskList = false;
  17273. // Reset state.trailingSpace
  17274. state.trailingSpace = 0;
  17275. state.trailingSpaceNewLine = false;
  17276. if (!state.localState) {
  17277. state.f = state.block;
  17278. if (state.f != htmlBlock) {
  17279. var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, expandedTab).length;
  17280. state.indentation = indentation;
  17281. state.indentationDiff = null;
  17282. if (indentation > 0) return null;
  17283. }
  17284. }
  17285. }
  17286. return state.f(stream, state);
  17287. },
  17288. innerMode: function(state) {
  17289. if (state.block == htmlBlock) return {state: state.htmlState, mode: htmlMode};
  17290. if (state.localState) return {state: state.localState, mode: state.localMode};
  17291. return {state: state, mode: mode};
  17292. },
  17293. indent: function(state, textAfter, line) {
  17294. if (state.block == htmlBlock && htmlMode.indent) return htmlMode.indent(state.htmlState, textAfter, line)
  17295. if (state.localState && state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line)
  17296. return CodeMirror.Pass
  17297. },
  17298. blankLine: blankLine,
  17299. getType: getType,
  17300. blockCommentStart: "<!--",
  17301. blockCommentEnd: "-->",
  17302. closeBrackets: "()[]{}''\"\"``",
  17303. fold: "markdown"
  17304. };
  17305. return mode;
  17306. }, "xml");
  17307. CodeMirror.defineMIME("text/markdown", "markdown");
  17308. CodeMirror.defineMIME("text/x-markdown", "markdown");
  17309. });
  17310. /***/ }),
  17311. /***/ "fe8a":
  17312. /***/ (function(module, exports, __webpack_require__) {
  17313. var $ = __webpack_require__("1c8b");
  17314. var toObject = __webpack_require__("3553");
  17315. var nativeKeys = __webpack_require__("cbab");
  17316. var fails = __webpack_require__("efe2");
  17317. var FAILS_ON_PRIMITIVES = fails(function () { nativeKeys(1); });
  17318. // `Object.keys` method
  17319. // https://tc39.github.io/ecma262/#sec-object.keys
  17320. $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
  17321. keys: function keys(it) {
  17322. return nativeKeys(toObject(it));
  17323. }
  17324. });
  17325. /***/ }),
  17326. /***/ "ff9c":
  17327. /***/ (function(module, exports, __webpack_require__) {
  17328. var DESCRIPTORS = __webpack_require__("1e2c");
  17329. var fails = __webpack_require__("efe2");
  17330. var has = __webpack_require__("faa8");
  17331. var defineProperty = Object.defineProperty;
  17332. var cache = {};
  17333. var thrower = function (it) { throw it; };
  17334. module.exports = function (METHOD_NAME, options) {
  17335. if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
  17336. if (!options) options = {};
  17337. var method = [][METHOD_NAME];
  17338. var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
  17339. var argument0 = has(options, 0) ? options[0] : thrower;
  17340. var argument1 = has(options, 1) ? options[1] : undefined;
  17341. return cache[METHOD_NAME] = !!method && !fails(function () {
  17342. if (ACCESSORS && !DESCRIPTORS) return true;
  17343. var O = { length: -1 };
  17344. if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
  17345. else O[1] = 1;
  17346. method.call(O, argument0, argument1);
  17347. });
  17348. };
  17349. /***/ })
  17350. /******/ });
  17351. //# sourceMappingURL=zx-markdown-editor.common.js.map