zx-markdown-editor.umd.js 676 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["zx-markdown-editor"] = factory();
  8. else
  9. root["zx-markdown-editor"] = factory();
  10. })((typeof self !== 'undefined' ? self : this), function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "f4a0");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ 0:
  99. /***/ (function(module, exports) {
  100. /* (ignored) */
  101. /***/ }),
  102. /***/ "05cd":
  103. /***/ (function(module, exports) {
  104. /**
  105. * Slugger generates header id
  106. */
  107. module.exports = class Slugger {
  108. constructor() {
  109. this.seen = {};
  110. }
  111. /**
  112. * Convert string to unique id
  113. */
  114. slug(value) {
  115. let slug = value
  116. .toLowerCase()
  117. .trim()
  118. // remove html tags
  119. .replace(/<[!\/a-z].*?>/ig, '')
  120. // remove unwanted chars
  121. .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
  122. .replace(/\s/g, '-');
  123. if (this.seen.hasOwnProperty(slug)) {
  124. const originalSlug = slug;
  125. do {
  126. this.seen[originalSlug]++;
  127. slug = originalSlug + '-' + this.seen[originalSlug];
  128. } while (this.seen.hasOwnProperty(slug));
  129. }
  130. this.seen[slug] = 0;
  131. return slug;
  132. }
  133. };
  134. /***/ }),
  135. /***/ "064b":
  136. /***/ (function(module, exports) {
  137. // iterable DOM collections
  138. // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
  139. module.exports = {
  140. CSSRuleList: 0,
  141. CSSStyleDeclaration: 0,
  142. CSSValueList: 0,
  143. ClientRectList: 0,
  144. DOMRectList: 0,
  145. DOMStringList: 0,
  146. DOMTokenList: 1,
  147. DataTransferItemList: 0,
  148. FileList: 0,
  149. HTMLAllCollection: 0,
  150. HTMLCollection: 0,
  151. HTMLFormElement: 0,
  152. HTMLSelectElement: 0,
  153. MediaList: 0,
  154. MimeTypeArray: 0,
  155. NamedNodeMap: 0,
  156. NodeList: 1,
  157. PaintRequestList: 0,
  158. Plugin: 0,
  159. PluginArray: 0,
  160. SVGLengthList: 0,
  161. SVGNumberList: 0,
  162. SVGPathSegList: 0,
  163. SVGPointList: 0,
  164. SVGStringList: 0,
  165. SVGTransformList: 0,
  166. SourceBufferList: 0,
  167. StyleSheetList: 0,
  168. TextTrackCueList: 0,
  169. TextTrackList: 0,
  170. TouchList: 0
  171. };
  172. /***/ }),
  173. /***/ "0654":
  174. /***/ (function(module, exports, __webpack_require__) {
  175. /* WEBPACK VAR INJECTION */(function(__dirname) {/* globals chrome: false */
  176. /* globals __dirname: false */
  177. /* globals require: false */
  178. /* globals Buffer: false */
  179. /* globals module: false */
  180. /**
  181. * Typo is a JavaScript implementation of a spellchecker using hunspell-style
  182. * dictionaries.
  183. */
  184. var Typo;
  185. (function () {
  186. "use strict";
  187. /**
  188. * Typo constructor.
  189. *
  190. * @param {String} [dictionary] The locale code of the dictionary being used. e.g.,
  191. * "en_US". This is only used to auto-load dictionaries.
  192. * @param {String} [affData] The data from the dictionary's .aff file. If omitted
  193. * and Typo.js is being used in a Chrome extension, the .aff
  194. * file will be loaded automatically from
  195. * lib/typo/dictionaries/[dictionary]/[dictionary].aff
  196. * In other environments, it will be loaded from
  197. * [settings.dictionaryPath]/dictionaries/[dictionary]/[dictionary].aff
  198. * @param {String} [wordsData] The data from the dictionary's .dic file. If omitted
  199. * and Typo.js is being used in a Chrome extension, the .dic
  200. * file will be loaded automatically from
  201. * lib/typo/dictionaries/[dictionary]/[dictionary].dic
  202. * In other environments, it will be loaded from
  203. * [settings.dictionaryPath]/dictionaries/[dictionary]/[dictionary].dic
  204. * @param {Object} [settings] Constructor settings. Available properties are:
  205. * {String} [dictionaryPath]: path to load dictionary from in non-chrome
  206. * environment.
  207. * {Object} [flags]: flag information.
  208. * {Boolean} [asyncLoad]: If true, affData and wordsData will be loaded
  209. * asynchronously.
  210. * {Function} [loadedCallback]: Called when both affData and wordsData
  211. * have been loaded. Only used if asyncLoad is set to true. The parameter
  212. * is the instantiated Typo object.
  213. *
  214. * @returns {Typo} A Typo object.
  215. */
  216. Typo = function (dictionary, affData, wordsData, settings) {
  217. settings = settings || {};
  218. this.dictionary = null;
  219. this.rules = {};
  220. this.dictionaryTable = {};
  221. this.compoundRules = [];
  222. this.compoundRuleCodes = {};
  223. this.replacementTable = [];
  224. this.flags = settings.flags || {};
  225. this.memoized = {};
  226. this.loaded = false;
  227. var self = this;
  228. var path;
  229. // Loop-control variables.
  230. var i, j, _len, _jlen;
  231. if (dictionary) {
  232. self.dictionary = dictionary;
  233. // If the data is preloaded, just setup the Typo object.
  234. if (affData && wordsData) {
  235. setup();
  236. }
  237. // Loading data for Chrome extentions.
  238. else if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) {
  239. if (settings.dictionaryPath) {
  240. path = settings.dictionaryPath;
  241. }
  242. else {
  243. path = "typo/dictionaries";
  244. }
  245. if (!affData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".aff"), setAffData);
  246. if (!wordsData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".dic"), setWordsData);
  247. }
  248. else {
  249. if (settings.dictionaryPath) {
  250. path = settings.dictionaryPath;
  251. }
  252. else if (true) {
  253. path = __dirname + '/dictionaries';
  254. }
  255. else {}
  256. if (!affData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".aff", setAffData);
  257. if (!wordsData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".dic", setWordsData);
  258. }
  259. }
  260. function readDataFile(url, setFunc) {
  261. var response = self._readFile(url, null, settings.asyncLoad);
  262. if (settings.asyncLoad) {
  263. response.then(function(data) {
  264. setFunc(data);
  265. });
  266. }
  267. else {
  268. setFunc(response);
  269. }
  270. }
  271. function setAffData(data) {
  272. affData = data;
  273. if (wordsData) {
  274. setup();
  275. }
  276. }
  277. function setWordsData(data) {
  278. wordsData = data;
  279. if (affData) {
  280. setup();
  281. }
  282. }
  283. function setup() {
  284. self.rules = self._parseAFF(affData);
  285. // Save the rule codes that are used in compound rules.
  286. self.compoundRuleCodes = {};
  287. for (i = 0, _len = self.compoundRules.length; i < _len; i++) {
  288. var rule = self.compoundRules[i];
  289. for (j = 0, _jlen = rule.length; j < _jlen; j++) {
  290. self.compoundRuleCodes[rule[j]] = [];
  291. }
  292. }
  293. // If we add this ONLYINCOMPOUND flag to self.compoundRuleCodes, then _parseDIC
  294. // will do the work of saving the list of words that are compound-only.
  295. if ("ONLYINCOMPOUND" in self.flags) {
  296. self.compoundRuleCodes[self.flags.ONLYINCOMPOUND] = [];
  297. }
  298. self.dictionaryTable = self._parseDIC(wordsData);
  299. // Get rid of any codes from the compound rule codes that are never used
  300. // (or that were special regex characters). Not especially necessary...
  301. for (i in self.compoundRuleCodes) {
  302. if (self.compoundRuleCodes[i].length === 0) {
  303. delete self.compoundRuleCodes[i];
  304. }
  305. }
  306. // Build the full regular expressions for each compound rule.
  307. // I have a feeling (but no confirmation yet) that this method of
  308. // testing for compound words is probably slow.
  309. for (i = 0, _len = self.compoundRules.length; i < _len; i++) {
  310. var ruleText = self.compoundRules[i];
  311. var expressionText = "";
  312. for (j = 0, _jlen = ruleText.length; j < _jlen; j++) {
  313. var character = ruleText[j];
  314. if (character in self.compoundRuleCodes) {
  315. expressionText += "(" + self.compoundRuleCodes[character].join("|") + ")";
  316. }
  317. else {
  318. expressionText += character;
  319. }
  320. }
  321. self.compoundRules[i] = new RegExp(expressionText, "i");
  322. }
  323. self.loaded = true;
  324. if (settings.asyncLoad && settings.loadedCallback) {
  325. settings.loadedCallback(self);
  326. }
  327. }
  328. return this;
  329. };
  330. Typo.prototype = {
  331. /**
  332. * Loads a Typo instance from a hash of all of the Typo properties.
  333. *
  334. * @param object obj A hash of Typo properties, probably gotten from a JSON.parse(JSON.stringify(typo_instance)).
  335. */
  336. load : function (obj) {
  337. for (var i in obj) {
  338. if (obj.hasOwnProperty(i)) {
  339. this[i] = obj[i];
  340. }
  341. }
  342. return this;
  343. },
  344. /**
  345. * Read the contents of a file.
  346. *
  347. * @param {String} path The path (relative) to the file.
  348. * @param {String} [charset="ISO8859-1"] The expected charset of the file
  349. * @param {Boolean} async If true, the file will be read asynchronously. For node.js this does nothing, all
  350. * files are read synchronously.
  351. * @returns {String} The file data if async is false, otherwise a promise object. If running node.js, the data is
  352. * always returned.
  353. */
  354. _readFile : function (path, charset, async) {
  355. charset = charset || "utf8";
  356. if (typeof XMLHttpRequest !== 'undefined') {
  357. var promise;
  358. var req = new XMLHttpRequest();
  359. req.open("GET", path, async);
  360. if (async) {
  361. promise = new Promise(function(resolve, reject) {
  362. req.onload = function() {
  363. if (req.status === 200) {
  364. resolve(req.responseText);
  365. }
  366. else {
  367. reject(req.statusText);
  368. }
  369. };
  370. req.onerror = function() {
  371. reject(req.statusText);
  372. }
  373. });
  374. }
  375. if (req.overrideMimeType)
  376. req.overrideMimeType("text/plain; charset=" + charset);
  377. req.send(null);
  378. return async ? promise : req.responseText;
  379. }
  380. else if (true) {
  381. // Node.js
  382. var fs = __webpack_require__(0);
  383. try {
  384. if (fs.existsSync(path)) {
  385. return fs.readFileSync(path, charset);
  386. }
  387. else {
  388. console.log("Path " + path + " does not exist.");
  389. }
  390. } catch (e) {
  391. console.log(e);
  392. return '';
  393. }
  394. }
  395. },
  396. /**
  397. * Parse the rules out from a .aff file.
  398. *
  399. * @param {String} data The contents of the affix file.
  400. * @returns object The rules from the file.
  401. */
  402. _parseAFF : function (data) {
  403. var rules = {};
  404. var line, subline, numEntries, lineParts;
  405. var i, j, _len, _jlen;
  406. // Remove comment lines
  407. data = this._removeAffixComments(data);
  408. var lines = data.split(/\r?\n/);
  409. for (i = 0, _len = lines.length; i < _len; i++) {
  410. line = lines[i];
  411. var definitionParts = line.split(/\s+/);
  412. var ruleType = definitionParts[0];
  413. if (ruleType == "PFX" || ruleType == "SFX") {
  414. var ruleCode = definitionParts[1];
  415. var combineable = definitionParts[2];
  416. numEntries = parseInt(definitionParts[3], 10);
  417. var entries = [];
  418. for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) {
  419. subline = lines[j];
  420. lineParts = subline.split(/\s+/);
  421. var charactersToRemove = lineParts[2];
  422. var additionParts = lineParts[3].split("/");
  423. var charactersToAdd = additionParts[0];
  424. if (charactersToAdd === "0") charactersToAdd = "";
  425. var continuationClasses = this.parseRuleCodes(additionParts[1]);
  426. var regexToMatch = lineParts[4];
  427. var entry = {};
  428. entry.add = charactersToAdd;
  429. if (continuationClasses.length > 0) entry.continuationClasses = continuationClasses;
  430. if (regexToMatch !== ".") {
  431. if (ruleType === "SFX") {
  432. entry.match = new RegExp(regexToMatch + "$");
  433. }
  434. else {
  435. entry.match = new RegExp("^" + regexToMatch);
  436. }
  437. }
  438. if (charactersToRemove != "0") {
  439. if (ruleType === "SFX") {
  440. entry.remove = new RegExp(charactersToRemove + "$");
  441. }
  442. else {
  443. entry.remove = charactersToRemove;
  444. }
  445. }
  446. entries.push(entry);
  447. }
  448. rules[ruleCode] = { "type" : ruleType, "combineable" : (combineable == "Y"), "entries" : entries };
  449. i += numEntries;
  450. }
  451. else if (ruleType === "COMPOUNDRULE") {
  452. numEntries = parseInt(definitionParts[1], 10);
  453. for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) {
  454. line = lines[j];
  455. lineParts = line.split(/\s+/);
  456. this.compoundRules.push(lineParts[1]);
  457. }
  458. i += numEntries;
  459. }
  460. else if (ruleType === "REP") {
  461. lineParts = line.split(/\s+/);
  462. if (lineParts.length === 3) {
  463. this.replacementTable.push([ lineParts[1], lineParts[2] ]);
  464. }
  465. }
  466. else {
  467. // ONLYINCOMPOUND
  468. // COMPOUNDMIN
  469. // FLAG
  470. // KEEPCASE
  471. // NEEDAFFIX
  472. this.flags[ruleType] = definitionParts[1];
  473. }
  474. }
  475. return rules;
  476. },
  477. /**
  478. * Removes comment lines and then cleans up blank lines and trailing whitespace.
  479. *
  480. * @param {String} data The data from an affix file.
  481. * @return {String} The cleaned-up data.
  482. */
  483. _removeAffixComments : function (data) {
  484. // Remove comments
  485. // This used to remove any string starting with '#' up to the end of the line,
  486. // but some COMPOUNDRULE definitions include '#' as part of the rule.
  487. // I haven't seen any affix files that use comments on the same line as real data,
  488. // so I don't think this will break anything.
  489. data = data.replace(/^\s*#.*$/mg, "");
  490. // Trim each line
  491. data = data.replace(/^\s\s*/m, '').replace(/\s\s*$/m, '');
  492. // Remove blank lines.
  493. data = data.replace(/\n{2,}/g, "\n");
  494. // Trim the entire string
  495. data = data.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  496. return data;
  497. },
  498. /**
  499. * Parses the words out from the .dic file.
  500. *
  501. * @param {String} data The data from the dictionary file.
  502. * @returns object The lookup table containing all of the words and
  503. * word forms from the dictionary.
  504. */
  505. _parseDIC : function (data) {
  506. data = this._removeDicComments(data);
  507. var lines = data.split(/\r?\n/);
  508. var dictionaryTable = {};
  509. function addWord(word, rules) {
  510. // Some dictionaries will list the same word multiple times with different rule sets.
  511. if (!dictionaryTable.hasOwnProperty(word)) {
  512. dictionaryTable[word] = null;
  513. }
  514. if (rules.length > 0) {
  515. if (dictionaryTable[word] === null) {
  516. dictionaryTable[word] = [];
  517. }
  518. dictionaryTable[word].push(rules);
  519. }
  520. }
  521. // The first line is the number of words in the dictionary.
  522. for (var i = 1, _len = lines.length; i < _len; i++) {
  523. var line = lines[i];
  524. if (!line) {
  525. // Ignore empty lines.
  526. continue;
  527. }
  528. var parts = line.split("/", 2);
  529. var word = parts[0];
  530. // Now for each affix rule, generate that form of the word.
  531. if (parts.length > 1) {
  532. var ruleCodesArray = this.parseRuleCodes(parts[1]);
  533. // Save the ruleCodes for compound word situations.
  534. if (!("NEEDAFFIX" in this.flags) || ruleCodesArray.indexOf(this.flags.NEEDAFFIX) == -1) {
  535. addWord(word, ruleCodesArray);
  536. }
  537. for (var j = 0, _jlen = ruleCodesArray.length; j < _jlen; j++) {
  538. var code = ruleCodesArray[j];
  539. var rule = this.rules[code];
  540. if (rule) {
  541. var newWords = this._applyRule(word, rule);
  542. for (var ii = 0, _iilen = newWords.length; ii < _iilen; ii++) {
  543. var newWord = newWords[ii];
  544. addWord(newWord, []);
  545. if (rule.combineable) {
  546. for (var k = j + 1; k < _jlen; k++) {
  547. var combineCode = ruleCodesArray[k];
  548. var combineRule = this.rules[combineCode];
  549. if (combineRule) {
  550. if (combineRule.combineable && (rule.type != combineRule.type)) {
  551. var otherNewWords = this._applyRule(newWord, combineRule);
  552. for (var iii = 0, _iiilen = otherNewWords.length; iii < _iiilen; iii++) {
  553. var otherNewWord = otherNewWords[iii];
  554. addWord(otherNewWord, []);
  555. }
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562. if (code in this.compoundRuleCodes) {
  563. this.compoundRuleCodes[code].push(word);
  564. }
  565. }
  566. }
  567. else {
  568. addWord(word.trim(), []);
  569. }
  570. }
  571. return dictionaryTable;
  572. },
  573. /**
  574. * Removes comment lines and then cleans up blank lines and trailing whitespace.
  575. *
  576. * @param {String} data The data from a .dic file.
  577. * @return {String} The cleaned-up data.
  578. */
  579. _removeDicComments : function (data) {
  580. // I can't find any official documentation on it, but at least the de_DE
  581. // dictionary uses tab-indented lines as comments.
  582. // Remove comments
  583. data = data.replace(/^\t.*$/mg, "");
  584. return data;
  585. },
  586. parseRuleCodes : function (textCodes) {
  587. if (!textCodes) {
  588. return [];
  589. }
  590. else if (!("FLAG" in this.flags)) {
  591. return textCodes.split("");
  592. }
  593. else if (this.flags.FLAG === "long") {
  594. var flags = [];
  595. for (var i = 0, _len = textCodes.length; i < _len; i += 2) {
  596. flags.push(textCodes.substr(i, 2));
  597. }
  598. return flags;
  599. }
  600. else if (this.flags.FLAG === "num") {
  601. return textCodes.split(",");
  602. }
  603. },
  604. /**
  605. * Applies an affix rule to a word.
  606. *
  607. * @param {String} word The base word.
  608. * @param {Object} rule The affix rule.
  609. * @returns {String[]} The new words generated by the rule.
  610. */
  611. _applyRule : function (word, rule) {
  612. var entries = rule.entries;
  613. var newWords = [];
  614. for (var i = 0, _len = entries.length; i < _len; i++) {
  615. var entry = entries[i];
  616. if (!entry.match || word.match(entry.match)) {
  617. var newWord = word;
  618. if (entry.remove) {
  619. newWord = newWord.replace(entry.remove, "");
  620. }
  621. if (rule.type === "SFX") {
  622. newWord = newWord + entry.add;
  623. }
  624. else {
  625. newWord = entry.add + newWord;
  626. }
  627. newWords.push(newWord);
  628. if ("continuationClasses" in entry) {
  629. for (var j = 0, _jlen = entry.continuationClasses.length; j < _jlen; j++) {
  630. var continuationRule = this.rules[entry.continuationClasses[j]];
  631. if (continuationRule) {
  632. newWords = newWords.concat(this._applyRule(newWord, continuationRule));
  633. }
  634. /*
  635. else {
  636. // This shouldn't happen, but it does, at least in the de_DE dictionary.
  637. // I think the author mistakenly supplied lower-case rule codes instead
  638. // of upper-case.
  639. }
  640. */
  641. }
  642. }
  643. }
  644. }
  645. return newWords;
  646. },
  647. /**
  648. * Checks whether a word or a capitalization variant exists in the current dictionary.
  649. * The word is trimmed and several variations of capitalizations are checked.
  650. * If you want to check a word without any changes made to it, call checkExact()
  651. *
  652. * @see http://blog.stevenlevithan.com/archives/faster-trim-javascript re:trimming function
  653. *
  654. * @param {String} aWord The word to check.
  655. * @returns {Boolean}
  656. */
  657. check : function (aWord) {
  658. if (!this.loaded) {
  659. throw "Dictionary not loaded.";
  660. }
  661. // Remove leading and trailing whitespace
  662. var trimmedWord = aWord.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  663. if (this.checkExact(trimmedWord)) {
  664. return true;
  665. }
  666. // The exact word is not in the dictionary.
  667. if (trimmedWord.toUpperCase() === trimmedWord) {
  668. // The word was supplied in all uppercase.
  669. // Check for a capitalized form of the word.
  670. var capitalizedWord = trimmedWord[0] + trimmedWord.substring(1).toLowerCase();
  671. if (this.hasFlag(capitalizedWord, "KEEPCASE")) {
  672. // Capitalization variants are not allowed for this word.
  673. return false;
  674. }
  675. if (this.checkExact(capitalizedWord)) {
  676. return true;
  677. }
  678. }
  679. var lowercaseWord = trimmedWord.toLowerCase();
  680. if (lowercaseWord !== trimmedWord) {
  681. if (this.hasFlag(lowercaseWord, "KEEPCASE")) {
  682. // Capitalization variants are not allowed for this word.
  683. return false;
  684. }
  685. // Check for a lowercase form
  686. if (this.checkExact(lowercaseWord)) {
  687. return true;
  688. }
  689. }
  690. return false;
  691. },
  692. /**
  693. * Checks whether a word exists in the current dictionary.
  694. *
  695. * @param {String} word The word to check.
  696. * @returns {Boolean}
  697. */
  698. checkExact : function (word) {
  699. if (!this.loaded) {
  700. throw "Dictionary not loaded.";
  701. }
  702. var ruleCodes = this.dictionaryTable[word];
  703. var i, _len;
  704. if (typeof ruleCodes === 'undefined') {
  705. // Check if this might be a compound word.
  706. if ("COMPOUNDMIN" in this.flags && word.length >= this.flags.COMPOUNDMIN) {
  707. for (i = 0, _len = this.compoundRules.length; i < _len; i++) {
  708. if (word.match(this.compoundRules[i])) {
  709. return true;
  710. }
  711. }
  712. }
  713. }
  714. else if (ruleCodes === null) {
  715. // a null (but not undefined) value for an entry in the dictionary table
  716. // means that the word is in the dictionary but has no flags.
  717. return true;
  718. }
  719. else if (typeof ruleCodes === 'object') { // this.dictionary['hasOwnProperty'] will be a function.
  720. for (i = 0, _len = ruleCodes.length; i < _len; i++) {
  721. if (!this.hasFlag(word, "ONLYINCOMPOUND", ruleCodes[i])) {
  722. return true;
  723. }
  724. }
  725. }
  726. return false;
  727. },
  728. /**
  729. * Looks up whether a given word is flagged with a given flag.
  730. *
  731. * @param {String} word The word in question.
  732. * @param {String} flag The flag in question.
  733. * @return {Boolean}
  734. */
  735. hasFlag : function (word, flag, wordFlags) {
  736. if (!this.loaded) {
  737. throw "Dictionary not loaded.";
  738. }
  739. if (flag in this.flags) {
  740. if (typeof wordFlags === 'undefined') {
  741. wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]);
  742. }
  743. if (wordFlags && wordFlags.indexOf(this.flags[flag]) !== -1) {
  744. return true;
  745. }
  746. }
  747. return false;
  748. },
  749. /**
  750. * Returns a list of suggestions for a misspelled word.
  751. *
  752. * @see http://www.norvig.com/spell-correct.html for the basis of this suggestor.
  753. * This suggestor is primitive, but it works.
  754. *
  755. * @param {String} word The misspelling.
  756. * @param {Number} [limit=5] The maximum number of suggestions to return.
  757. * @returns {String[]} The array of suggestions.
  758. */
  759. alphabet : "",
  760. suggest : function (word, limit) {
  761. if (!this.loaded) {
  762. throw "Dictionary not loaded.";
  763. }
  764. limit = limit || 5;
  765. if (this.memoized.hasOwnProperty(word)) {
  766. var memoizedLimit = this.memoized[word]['limit'];
  767. // Only return the cached list if it's big enough or if there weren't enough suggestions
  768. // to fill a smaller limit.
  769. if (limit <= memoizedLimit || this.memoized[word]['suggestions'].length < memoizedLimit) {
  770. return this.memoized[word]['suggestions'].slice(0, limit);
  771. }
  772. }
  773. if (this.check(word)) return [];
  774. // Check the replacement table.
  775. for (var i = 0, _len = this.replacementTable.length; i < _len; i++) {
  776. var replacementEntry = this.replacementTable[i];
  777. if (word.indexOf(replacementEntry[0]) !== -1) {
  778. var correctedWord = word.replace(replacementEntry[0], replacementEntry[1]);
  779. if (this.check(correctedWord)) {
  780. return [ correctedWord ];
  781. }
  782. }
  783. }
  784. var self = this;
  785. self.alphabet = "abcdefghijklmnopqrstuvwxyz";
  786. /*
  787. if (!self.alphabet) {
  788. // Use the alphabet as implicitly defined by the words in the dictionary.
  789. var alphaHash = {};
  790. for (var i in self.dictionaryTable) {
  791. for (var j = 0, _len = i.length; j < _len; j++) {
  792. alphaHash[i[j]] = true;
  793. }
  794. }
  795. for (var i in alphaHash) {
  796. self.alphabet += i;
  797. }
  798. var alphaArray = self.alphabet.split("");
  799. alphaArray.sort();
  800. self.alphabet = alphaArray.join("");
  801. }
  802. */
  803. /**
  804. * 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`
  805. * The value of each entry is the number of unique ways that the resulting word can be made.
  806. *
  807. * @arg mixed words Either a hash keyed by words or a string word to operate on.
  808. * @arg bool known_only Whether this function should ignore strings that are not in the dictionary.
  809. */
  810. function edits1(words, known_only) {
  811. var rv = {};
  812. var i, j, _iilen, _len, _jlen, _edit;
  813. if (typeof words == 'string') {
  814. var word = words;
  815. words = {};
  816. words[word] = true;
  817. }
  818. for (var word in words) {
  819. for (i = 0, _len = word.length + 1; i < _len; i++) {
  820. var s = [ word.substring(0, i), word.substring(i) ];
  821. if (s[1]) {
  822. _edit = s[0] + s[1].substring(1);
  823. if (!known_only || self.check(_edit)) {
  824. if (!(_edit in rv)) {
  825. rv[_edit] = 1;
  826. }
  827. else {
  828. rv[_edit] += 1;
  829. }
  830. }
  831. }
  832. // Eliminate transpositions of identical letters
  833. if (s[1].length > 1 && s[1][1] !== s[1][0]) {
  834. _edit = s[0] + s[1][1] + s[1][0] + s[1].substring(2);
  835. if (!known_only || self.check(_edit)) {
  836. if (!(_edit in rv)) {
  837. rv[_edit] = 1;
  838. }
  839. else {
  840. rv[_edit] += 1;
  841. }
  842. }
  843. }
  844. if (s[1]) {
  845. for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) {
  846. // Eliminate replacement of a letter by itself
  847. if (self.alphabet[j] != s[1].substring(0,1)){
  848. _edit = s[0] + self.alphabet[j] + s[1].substring(1);
  849. if (!known_only || self.check(_edit)) {
  850. if (!(_edit in rv)) {
  851. rv[_edit] = 1;
  852. }
  853. else {
  854. rv[_edit] += 1;
  855. }
  856. }
  857. }
  858. }
  859. }
  860. if (s[1]) {
  861. for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) {
  862. _edit = s[0] + self.alphabet[j] + s[1];
  863. if (!known_only || self.check(_edit)) {
  864. if (!(_edit in rv)) {
  865. rv[_edit] = 1;
  866. }
  867. else {
  868. rv[_edit] += 1;
  869. }
  870. }
  871. }
  872. }
  873. }
  874. }
  875. return rv;
  876. }
  877. function correct(word) {
  878. // Get the edit-distance-1 and edit-distance-2 forms of this word.
  879. var ed1 = edits1(word);
  880. var ed2 = edits1(ed1, true);
  881. // Sort the edits based on how many different ways they were created.
  882. var weighted_corrections = ed2;
  883. for (var ed1word in ed1) {
  884. if (!self.check(ed1word)) {
  885. continue;
  886. }
  887. if (ed1word in weighted_corrections) {
  888. weighted_corrections[ed1word] += ed1[ed1word];
  889. }
  890. else {
  891. weighted_corrections[ed1word] = ed1[ed1word];
  892. }
  893. }
  894. var i, _len;
  895. var sorted_corrections = [];
  896. for (i in weighted_corrections) {
  897. if (weighted_corrections.hasOwnProperty(i)) {
  898. sorted_corrections.push([ i, weighted_corrections[i] ]);
  899. }
  900. }
  901. function sorter(a, b) {
  902. var a_val = a[1];
  903. var b_val = b[1];
  904. if (a_val < b_val) {
  905. return -1;
  906. } else if (a_val > b_val) {
  907. return 1;
  908. }
  909. // @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.
  910. return b[0].localeCompare(a[0]);
  911. }
  912. sorted_corrections.sort(sorter).reverse();
  913. var rv = [];
  914. var capitalization_scheme = "lowercase";
  915. if (word.toUpperCase() === word) {
  916. capitalization_scheme = "uppercase";
  917. }
  918. else if (word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase() === word) {
  919. capitalization_scheme = "capitalized";
  920. }
  921. var working_limit = limit;
  922. for (i = 0; i < Math.min(working_limit, sorted_corrections.length); i++) {
  923. if ("uppercase" === capitalization_scheme) {
  924. sorted_corrections[i][0] = sorted_corrections[i][0].toUpperCase();
  925. }
  926. else if ("capitalized" === capitalization_scheme) {
  927. sorted_corrections[i][0] = sorted_corrections[i][0].substr(0, 1).toUpperCase() + sorted_corrections[i][0].substr(1);
  928. }
  929. if (!self.hasFlag(sorted_corrections[i][0], "NOSUGGEST") && rv.indexOf(sorted_corrections[i][0]) == -1) {
  930. rv.push(sorted_corrections[i][0]);
  931. }
  932. else {
  933. // If one of the corrections is not eligible as a suggestion , make sure we still return the right number of suggestions.
  934. working_limit++;
  935. }
  936. }
  937. return rv;
  938. }
  939. this.memoized[word] = {
  940. 'suggestions': correct(word),
  941. 'limit': limit
  942. };
  943. return this.memoized[word]['suggestions'];
  944. }
  945. };
  946. })();
  947. // Support for use as a node.js module.
  948. if (true) {
  949. module.exports = Typo;
  950. }
  951. /* WEBPACK VAR INJECTION */}.call(this, "/"))
  952. /***/ }),
  953. /***/ "08ba":
  954. /***/ (function(module, exports, __webpack_require__) {
  955. var global = __webpack_require__("d890");
  956. var DOMIterables = __webpack_require__("064b");
  957. var forEach = __webpack_require__("3c10");
  958. var createNonEnumerableProperty = __webpack_require__("0fc1");
  959. for (var COLLECTION_NAME in DOMIterables) {
  960. var Collection = global[COLLECTION_NAME];
  961. var CollectionPrototype = Collection && Collection.prototype;
  962. // some Chrome versions have non-configurable methods on DOMTokenList
  963. if (CollectionPrototype && CollectionPrototype.forEach !== forEach) try {
  964. createNonEnumerableProperty(CollectionPrototype, 'forEach', forEach);
  965. } catch (error) {
  966. CollectionPrototype.forEach = forEach;
  967. }
  968. }
  969. /***/ }),
  970. /***/ "094f":
  971. /***/ (function(module, exports, __webpack_require__) {
  972. const Lexer = __webpack_require__("6c31");
  973. const Parser = __webpack_require__("7727");
  974. const Tokenizer = __webpack_require__("5a9c");
  975. const Renderer = __webpack_require__("155c");
  976. const TextRenderer = __webpack_require__("f5ef");
  977. const Slugger = __webpack_require__("05cd");
  978. const {
  979. merge,
  980. checkSanitizeDeprecation,
  981. escape
  982. } = __webpack_require__("322c");
  983. const {
  984. getDefaults,
  985. changeDefaults,
  986. defaults
  987. } = __webpack_require__("a8a2");
  988. /**
  989. * Marked
  990. */
  991. function marked(src, opt, callback) {
  992. // throw error in case of non string input
  993. if (typeof src === 'undefined' || src === null) {
  994. throw new Error('marked(): input parameter is undefined or null');
  995. }
  996. if (typeof src !== 'string') {
  997. throw new Error('marked(): input parameter is of type '
  998. + Object.prototype.toString.call(src) + ', string expected');
  999. }
  1000. if (callback || typeof opt === 'function') {
  1001. if (!callback) {
  1002. callback = opt;
  1003. opt = null;
  1004. }
  1005. opt = merge({}, marked.defaults, opt || {});
  1006. checkSanitizeDeprecation(opt);
  1007. const highlight = opt.highlight;
  1008. let tokens,
  1009. pending,
  1010. i = 0;
  1011. try {
  1012. tokens = Lexer.lex(src, opt);
  1013. } catch (e) {
  1014. return callback(e);
  1015. }
  1016. pending = tokens.length;
  1017. const done = function(err) {
  1018. if (err) {
  1019. opt.highlight = highlight;
  1020. return callback(err);
  1021. }
  1022. let out;
  1023. try {
  1024. out = Parser.parse(tokens, opt);
  1025. } catch (e) {
  1026. err = e;
  1027. }
  1028. opt.highlight = highlight;
  1029. return err
  1030. ? callback(err)
  1031. : callback(null, out);
  1032. };
  1033. if (!highlight || highlight.length < 3) {
  1034. return done();
  1035. }
  1036. delete opt.highlight;
  1037. if (!pending) return done();
  1038. for (; i < tokens.length; i++) {
  1039. (function(token) {
  1040. if (token.type !== 'code') {
  1041. return --pending || done();
  1042. }
  1043. return highlight(token.text, token.lang, function(err, code) {
  1044. if (err) return done(err);
  1045. if (code == null || code === token.text) {
  1046. return --pending || done();
  1047. }
  1048. token.text = code;
  1049. token.escaped = true;
  1050. --pending || done();
  1051. });
  1052. })(tokens[i]);
  1053. }
  1054. return;
  1055. }
  1056. try {
  1057. opt = merge({}, marked.defaults, opt || {});
  1058. checkSanitizeDeprecation(opt);
  1059. return Parser.parse(Lexer.lex(src, opt), opt);
  1060. } catch (e) {
  1061. e.message += '\nPlease report this to https://github.com/markedjs/marked.';
  1062. if ((opt || marked.defaults).silent) {
  1063. return '<p>An error occurred:</p><pre>'
  1064. + escape(e.message + '', true)
  1065. + '</pre>';
  1066. }
  1067. throw e;
  1068. }
  1069. }
  1070. /**
  1071. * Options
  1072. */
  1073. marked.options =
  1074. marked.setOptions = function(opt) {
  1075. merge(marked.defaults, opt);
  1076. changeDefaults(marked.defaults);
  1077. return marked;
  1078. };
  1079. marked.getDefaults = getDefaults;
  1080. marked.defaults = defaults;
  1081. /**
  1082. * Use Extension
  1083. */
  1084. marked.use = function(extension) {
  1085. const opts = merge({}, extension);
  1086. if (extension.renderer) {
  1087. const renderer = marked.defaults.renderer || new Renderer();
  1088. for (const prop in extension.renderer) {
  1089. const prevRenderer = renderer[prop];
  1090. renderer[prop] = (...args) => {
  1091. let ret = extension.renderer[prop].apply(renderer, args);
  1092. if (ret === false) {
  1093. ret = prevRenderer.apply(renderer, args);
  1094. }
  1095. return ret;
  1096. };
  1097. }
  1098. opts.renderer = renderer;
  1099. }
  1100. if (extension.tokenizer) {
  1101. const tokenizer = marked.defaults.tokenizer || new Tokenizer();
  1102. for (const prop in extension.tokenizer) {
  1103. const prevTokenizer = tokenizer[prop];
  1104. tokenizer[prop] = (...args) => {
  1105. let ret = extension.tokenizer[prop].apply(tokenizer, args);
  1106. if (ret === false) {
  1107. ret = prevTokenizer.apply(tokenizer, args);
  1108. }
  1109. return ret;
  1110. };
  1111. }
  1112. opts.tokenizer = tokenizer;
  1113. }
  1114. marked.setOptions(opts);
  1115. };
  1116. /**
  1117. * Expose
  1118. */
  1119. marked.Parser = Parser;
  1120. marked.parser = Parser.parse;
  1121. marked.Renderer = Renderer;
  1122. marked.TextRenderer = TextRenderer;
  1123. marked.Lexer = Lexer;
  1124. marked.lexer = Lexer.lex;
  1125. marked.Tokenizer = Tokenizer;
  1126. marked.Slugger = Slugger;
  1127. marked.parse = marked;
  1128. module.exports = marked;
  1129. /***/ }),
  1130. /***/ "0a60":
  1131. /***/ (function(module, exports) {
  1132. exports.f = Object.getOwnPropertySymbols;
  1133. /***/ }),
  1134. /***/ "0c3c":
  1135. /***/ (function(module, exports) {
  1136. module.exports = function (it) {
  1137. if (typeof it != 'function') {
  1138. throw TypeError(String(it) + ' is not a function');
  1139. } return it;
  1140. };
  1141. /***/ }),
  1142. /***/ "0e50":
  1143. /***/ (function(module, exports, __webpack_require__) {
  1144. // extracted by mini-css-extract-plugin
  1145. /***/ }),
  1146. /***/ "0fc1":
  1147. /***/ (function(module, exports, __webpack_require__) {
  1148. var DESCRIPTORS = __webpack_require__("1e2c");
  1149. var definePropertyModule = __webpack_require__("d910");
  1150. var createPropertyDescriptor = __webpack_require__("38b9");
  1151. module.exports = DESCRIPTORS ? function (object, key, value) {
  1152. return definePropertyModule.f(object, key, createPropertyDescriptor(1, value));
  1153. } : function (object, key, value) {
  1154. object[key] = value;
  1155. return object;
  1156. };
  1157. /***/ }),
  1158. /***/ "1025":
  1159. /***/ (function(module, exports, __webpack_require__) {
  1160. var store = __webpack_require__("3a08");
  1161. var functionToString = Function.toString;
  1162. // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
  1163. if (typeof store.inspectSource != 'function') {
  1164. store.inspectSource = function (it) {
  1165. return functionToString.call(it);
  1166. };
  1167. }
  1168. module.exports = store.inspectSource;
  1169. /***/ }),
  1170. /***/ "155c":
  1171. /***/ (function(module, exports, __webpack_require__) {
  1172. const { defaults } = __webpack_require__("a8a2");
  1173. const {
  1174. cleanUrl,
  1175. escape
  1176. } = __webpack_require__("322c");
  1177. /**
  1178. * Renderer
  1179. */
  1180. module.exports = class Renderer {
  1181. constructor(options) {
  1182. this.options = options || defaults;
  1183. }
  1184. code(code, infostring, escaped) {
  1185. const lang = (infostring || '').match(/\S*/)[0];
  1186. if (this.options.highlight) {
  1187. const out = this.options.highlight(code, lang);
  1188. if (out != null && out !== code) {
  1189. escaped = true;
  1190. code = out;
  1191. }
  1192. }
  1193. if (!lang) {
  1194. return '<pre><code>'
  1195. + (escaped ? code : escape(code, true))
  1196. + '</code></pre>';
  1197. }
  1198. return '<pre><code class="'
  1199. + this.options.langPrefix
  1200. + escape(lang, true)
  1201. + '">'
  1202. + (escaped ? code : escape(code, true))
  1203. + '</code></pre>\n';
  1204. }
  1205. blockquote(quote) {
  1206. return '<blockquote>\n' + quote + '</blockquote>\n';
  1207. }
  1208. html(html) {
  1209. return html;
  1210. }
  1211. heading(text, level, raw, slugger) {
  1212. if (this.options.headerIds) {
  1213. return '<h'
  1214. + level
  1215. + ' id="'
  1216. + this.options.headerPrefix
  1217. + slugger.slug(raw)
  1218. + '">'
  1219. + text
  1220. + '</h'
  1221. + level
  1222. + '>\n';
  1223. }
  1224. // ignore IDs
  1225. return '<h' + level + '>' + text + '</h' + level + '>\n';
  1226. }
  1227. hr() {
  1228. return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
  1229. }
  1230. list(body, ordered, start) {
  1231. const type = ordered ? 'ol' : 'ul',
  1232. startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
  1233. return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
  1234. }
  1235. listitem(text) {
  1236. return '<li>' + text + '</li>\n';
  1237. }
  1238. checkbox(checked) {
  1239. return '<input '
  1240. + (checked ? 'checked="" ' : '')
  1241. + 'disabled="" type="checkbox"'
  1242. + (this.options.xhtml ? ' /' : '')
  1243. + '> ';
  1244. }
  1245. paragraph(text) {
  1246. return '<p>' + text + '</p>\n';
  1247. }
  1248. table(header, body) {
  1249. if (body) body = '<tbody>' + body + '</tbody>';
  1250. return '<table>\n'
  1251. + '<thead>\n'
  1252. + header
  1253. + '</thead>\n'
  1254. + body
  1255. + '</table>\n';
  1256. }
  1257. tablerow(content) {
  1258. return '<tr>\n' + content + '</tr>\n';
  1259. }
  1260. tablecell(content, flags) {
  1261. const type = flags.header ? 'th' : 'td';
  1262. const tag = flags.align
  1263. ? '<' + type + ' align="' + flags.align + '">'
  1264. : '<' + type + '>';
  1265. return tag + content + '</' + type + '>\n';
  1266. }
  1267. // span level renderer
  1268. strong(text) {
  1269. return '<strong>' + text + '</strong>';
  1270. }
  1271. em(text) {
  1272. return '<em>' + text + '</em>';
  1273. }
  1274. codespan(text) {
  1275. return '<code>' + text + '</code>';
  1276. }
  1277. br() {
  1278. return this.options.xhtml ? '<br/>' : '<br>';
  1279. }
  1280. del(text) {
  1281. return '<del>' + text + '</del>';
  1282. }
  1283. link(href, title, text) {
  1284. href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
  1285. if (href === null) {
  1286. return text;
  1287. }
  1288. let out = '<a href="' + escape(href) + '"';
  1289. if (title) {
  1290. out += ' title="' + title + '"';
  1291. }
  1292. out += '>' + text + '</a>';
  1293. return out;
  1294. }
  1295. image(href, title, text) {
  1296. href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
  1297. if (href === null) {
  1298. return text;
  1299. }
  1300. let out = '<img src="' + href + '" alt="' + text + '"';
  1301. if (title) {
  1302. out += ' title="' + title + '"';
  1303. }
  1304. out += this.options.xhtml ? '/>' : '>';
  1305. return out;
  1306. }
  1307. text(text) {
  1308. return text;
  1309. }
  1310. };
  1311. /***/ }),
  1312. /***/ "18f6":
  1313. /***/ (function(module, exports) {
  1314. // IE8- don't enum bug keys
  1315. module.exports = [
  1316. 'constructor',
  1317. 'hasOwnProperty',
  1318. 'isPrototypeOf',
  1319. 'propertyIsEnumerable',
  1320. 'toLocaleString',
  1321. 'toString',
  1322. 'valueOf'
  1323. ];
  1324. /***/ }),
  1325. /***/ "1944":
  1326. /***/ (function(module, exports, __webpack_require__) {
  1327. var global = __webpack_require__("d890");
  1328. var createNonEnumerableProperty = __webpack_require__("0fc1");
  1329. var has = __webpack_require__("faa8");
  1330. var setGlobal = __webpack_require__("e4db");
  1331. var inspectSource = __webpack_require__("1025");
  1332. var InternalStateModule = __webpack_require__("b702");
  1333. var getInternalState = InternalStateModule.get;
  1334. var enforceInternalState = InternalStateModule.enforce;
  1335. var TEMPLATE = String(String).split('String');
  1336. (module.exports = function (O, key, value, options) {
  1337. var unsafe = options ? !!options.unsafe : false;
  1338. var simple = options ? !!options.enumerable : false;
  1339. var noTargetGet = options ? !!options.noTargetGet : false;
  1340. if (typeof value == 'function') {
  1341. if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
  1342. enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
  1343. }
  1344. if (O === global) {
  1345. if (simple) O[key] = value;
  1346. else setGlobal(key, value);
  1347. return;
  1348. } else if (!unsafe) {
  1349. delete O[key];
  1350. } else if (!noTargetGet && O[key]) {
  1351. simple = true;
  1352. }
  1353. if (simple) O[key] = value;
  1354. else createNonEnumerableProperty(O, key, value);
  1355. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  1356. })(Function.prototype, 'toString', function toString() {
  1357. return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
  1358. });
  1359. /***/ }),
  1360. /***/ "1b99":
  1361. /***/ (function(module, exports, __webpack_require__) {
  1362. var global = __webpack_require__("d890");
  1363. module.exports = global;
  1364. /***/ }),
  1365. /***/ "1bbd":
  1366. /***/ (function(module, exports, __webpack_require__) {
  1367. "use strict";
  1368. var toPrimitive = __webpack_require__("9f67");
  1369. var definePropertyModule = __webpack_require__("d910");
  1370. var createPropertyDescriptor = __webpack_require__("38b9");
  1371. module.exports = function (object, key, value) {
  1372. var propertyKey = toPrimitive(key);
  1373. if (propertyKey in object) definePropertyModule.f(object, propertyKey, createPropertyDescriptor(0, value));
  1374. else object[propertyKey] = value;
  1375. };
  1376. /***/ }),
  1377. /***/ "1c8b":
  1378. /***/ (function(module, exports, __webpack_require__) {
  1379. var global = __webpack_require__("d890");
  1380. var getOwnPropertyDescriptor = __webpack_require__("aa6b").f;
  1381. var createNonEnumerableProperty = __webpack_require__("0fc1");
  1382. var redefine = __webpack_require__("1944");
  1383. var setGlobal = __webpack_require__("e4db");
  1384. var copyConstructorProperties = __webpack_require__("c69d");
  1385. var isForced = __webpack_require__("e8d6");
  1386. /*
  1387. options.target - name of the target object
  1388. options.global - target is the global object
  1389. options.stat - export as static methods of target
  1390. options.proto - export as prototype methods of target
  1391. options.real - real prototype method for the `pure` version
  1392. options.forced - export even if the native feature is available
  1393. options.bind - bind methods to the target, required for the `pure` version
  1394. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  1395. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  1396. options.sham - add a flag to not completely full polyfills
  1397. options.enumerable - export as enumerable property
  1398. options.noTargetGet - prevent calling a getter on target
  1399. */
  1400. module.exports = function (options, source) {
  1401. var TARGET = options.target;
  1402. var GLOBAL = options.global;
  1403. var STATIC = options.stat;
  1404. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  1405. if (GLOBAL) {
  1406. target = global;
  1407. } else if (STATIC) {
  1408. target = global[TARGET] || setGlobal(TARGET, {});
  1409. } else {
  1410. target = (global[TARGET] || {}).prototype;
  1411. }
  1412. if (target) for (key in source) {
  1413. sourceProperty = source[key];
  1414. if (options.noTargetGet) {
  1415. descriptor = getOwnPropertyDescriptor(target, key);
  1416. targetProperty = descriptor && descriptor.value;
  1417. } else targetProperty = target[key];
  1418. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  1419. // contained in target
  1420. if (!FORCED && targetProperty !== undefined) {
  1421. if (typeof sourceProperty === typeof targetProperty) continue;
  1422. copyConstructorProperties(sourceProperty, targetProperty);
  1423. }
  1424. // add a flag to not completely full polyfills
  1425. if (options.sham || (targetProperty && targetProperty.sham)) {
  1426. createNonEnumerableProperty(sourceProperty, 'sham', true);
  1427. }
  1428. // extend global
  1429. redefine(target, key, sourceProperty, options);
  1430. }
  1431. };
  1432. /***/ }),
  1433. /***/ "1ca1":
  1434. /***/ (function(module, exports, __webpack_require__) {
  1435. var isObject = __webpack_require__("a719");
  1436. var isArray = __webpack_require__("74e7");
  1437. var wellKnownSymbol = __webpack_require__("90fb");
  1438. var SPECIES = wellKnownSymbol('species');
  1439. // `ArraySpeciesCreate` abstract operation
  1440. // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
  1441. module.exports = function (originalArray, length) {
  1442. var C;
  1443. if (isArray(originalArray)) {
  1444. C = originalArray.constructor;
  1445. // cross-realm fallback
  1446. if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
  1447. else if (isObject(C)) {
  1448. C = C[SPECIES];
  1449. if (C === null) C = undefined;
  1450. }
  1451. } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
  1452. };
  1453. /***/ }),
  1454. /***/ "1e2c":
  1455. /***/ (function(module, exports, __webpack_require__) {
  1456. var fails = __webpack_require__("efe2");
  1457. // Thank's IE8 for his funny defineProperty
  1458. module.exports = !fails(function () {
  1459. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  1460. });
  1461. /***/ }),
  1462. /***/ "1ea7":
  1463. /***/ (function(module, exports, __webpack_require__) {
  1464. var fails = __webpack_require__("efe2");
  1465. var wellKnownSymbol = __webpack_require__("90fb");
  1466. var V8_VERSION = __webpack_require__("f594");
  1467. var SPECIES = wellKnownSymbol('species');
  1468. module.exports = function (METHOD_NAME) {
  1469. // We can't use this feature detection in V8 since it causes
  1470. // deoptimization and serious performance degradation
  1471. // https://github.com/zloirock/core-js/issues/677
  1472. return V8_VERSION >= 51 || !fails(function () {
  1473. var array = [];
  1474. var constructor = array.constructor = {};
  1475. constructor[SPECIES] = function () {
  1476. return { foo: 1 };
  1477. };
  1478. return array[METHOD_NAME](Boolean).foo !== 1;
  1479. });
  1480. };
  1481. /***/ }),
  1482. /***/ "2039":
  1483. /***/ (function(module, exports, __webpack_require__) {
  1484. var DESCRIPTORS = __webpack_require__("1e2c");
  1485. var fails = __webpack_require__("efe2");
  1486. var createElement = __webpack_require__("ae25");
  1487. // Thank's IE8 for his funny defineProperty
  1488. module.exports = !DESCRIPTORS && !fails(function () {
  1489. return Object.defineProperty(createElement('div'), 'a', {
  1490. get: function () { return 7; }
  1491. }).a != 7;
  1492. });
  1493. /***/ }),
  1494. /***/ "2118":
  1495. /***/ (function(module, exports) {
  1496. var toString = {}.toString;
  1497. module.exports = function (it) {
  1498. return toString.call(it).slice(8, -1);
  1499. };
  1500. /***/ }),
  1501. /***/ "21ed":
  1502. /***/ (function(module, exports, __webpack_require__) {
  1503. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1504. // Distributed under an MIT license: https://codemirror.net/LICENSE
  1505. // Because sometimes you need to mark the selected *text*.
  1506. //
  1507. // Adds an option 'styleSelectedText' which, when enabled, gives
  1508. // selected text the CSS class given as option value, or
  1509. // "CodeMirror-selectedtext" when the value is not a string.
  1510. (function(mod) {
  1511. if (true) // CommonJS
  1512. mod(__webpack_require__("a564"));
  1513. else {}
  1514. })(function(CodeMirror) {
  1515. "use strict";
  1516. CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
  1517. var prev = old && old != CodeMirror.Init;
  1518. if (val && !prev) {
  1519. cm.state.markedSelection = [];
  1520. cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext";
  1521. reset(cm);
  1522. cm.on("cursorActivity", onCursorActivity);
  1523. cm.on("change", onChange);
  1524. } else if (!val && prev) {
  1525. cm.off("cursorActivity", onCursorActivity);
  1526. cm.off("change", onChange);
  1527. clear(cm);
  1528. cm.state.markedSelection = cm.state.markedSelectionStyle = null;
  1529. }
  1530. });
  1531. function onCursorActivity(cm) {
  1532. if (cm.state.markedSelection)
  1533. cm.operation(function() { update(cm); });
  1534. }
  1535. function onChange(cm) {
  1536. if (cm.state.markedSelection && cm.state.markedSelection.length)
  1537. cm.operation(function() { clear(cm); });
  1538. }
  1539. var CHUNK_SIZE = 8;
  1540. var Pos = CodeMirror.Pos;
  1541. var cmp = CodeMirror.cmpPos;
  1542. function coverRange(cm, from, to, addAt) {
  1543. if (cmp(from, to) == 0) return;
  1544. var array = cm.state.markedSelection;
  1545. var cls = cm.state.markedSelectionStyle;
  1546. for (var line = from.line;;) {
  1547. var start = line == from.line ? from : Pos(line, 0);
  1548. var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line;
  1549. var end = atEnd ? to : Pos(endLine, 0);
  1550. var mark = cm.markText(start, end, {className: cls});
  1551. if (addAt == null) array.push(mark);
  1552. else array.splice(addAt++, 0, mark);
  1553. if (atEnd) break;
  1554. line = endLine;
  1555. }
  1556. }
  1557. function clear(cm) {
  1558. var array = cm.state.markedSelection;
  1559. for (var i = 0; i < array.length; ++i) array[i].clear();
  1560. array.length = 0;
  1561. }
  1562. function reset(cm) {
  1563. clear(cm);
  1564. var ranges = cm.listSelections();
  1565. for (var i = 0; i < ranges.length; i++)
  1566. coverRange(cm, ranges[i].from(), ranges[i].to());
  1567. }
  1568. function update(cm) {
  1569. if (!cm.somethingSelected()) return clear(cm);
  1570. if (cm.listSelections().length > 1) return reset(cm);
  1571. var from = cm.getCursor("start"), to = cm.getCursor("end");
  1572. var array = cm.state.markedSelection;
  1573. if (!array.length) return coverRange(cm, from, to);
  1574. var coverStart = array[0].find(), coverEnd = array[array.length - 1].find();
  1575. if (!coverStart || !coverEnd || to.line - from.line <= CHUNK_SIZE ||
  1576. cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0)
  1577. return reset(cm);
  1578. while (cmp(from, coverStart.from) > 0) {
  1579. array.shift().clear();
  1580. coverStart = array[0].find();
  1581. }
  1582. if (cmp(from, coverStart.from) < 0) {
  1583. if (coverStart.to.line - from.line < CHUNK_SIZE) {
  1584. array.shift().clear();
  1585. coverRange(cm, from, coverStart.to, 0);
  1586. } else {
  1587. coverRange(cm, from, coverStart.from, 0);
  1588. }
  1589. }
  1590. while (cmp(to, coverEnd.to) < 0) {
  1591. array.pop().clear();
  1592. coverEnd = array[array.length - 1].find();
  1593. }
  1594. if (cmp(to, coverEnd.to) > 0) {
  1595. if (to.line - coverEnd.from.line < CHUNK_SIZE) {
  1596. array.pop().clear();
  1597. coverRange(cm, coverEnd.from, to);
  1598. } else {
  1599. coverRange(cm, coverEnd.to, to);
  1600. }
  1601. }
  1602. }
  1603. });
  1604. /***/ }),
  1605. /***/ "2732":
  1606. /***/ (function(module, exports) {
  1607. // `RequireObjectCoercible` abstract operation
  1608. // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
  1609. module.exports = function (it) {
  1610. if (it == undefined) throw TypeError("Can't call method on " + it);
  1611. return it;
  1612. };
  1613. /***/ }),
  1614. /***/ "27b3":
  1615. /***/ (function(module, exports, __webpack_require__) {
  1616. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1617. // Distributed under an MIT license: http://codemirror.net/LICENSE
  1618. var CodeMirror = __webpack_require__("a564");
  1619. CodeMirror.commands.tabAndIndentMarkdownList = function (cm) {
  1620. var ranges = cm.listSelections();
  1621. var pos = ranges[0].head;
  1622. var eolState = cm.getStateAfter(pos.line);
  1623. var inList = eolState.list !== false;
  1624. if (inList) {
  1625. cm.execCommand("indentMore");
  1626. return;
  1627. }
  1628. if (cm.options.indentWithTabs) {
  1629. cm.execCommand("insertTab");
  1630. }
  1631. else {
  1632. var spaces = Array(cm.options.tabSize + 1).join(" ");
  1633. cm.replaceSelection(spaces);
  1634. }
  1635. };
  1636. CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (cm) {
  1637. var ranges = cm.listSelections();
  1638. var pos = ranges[0].head;
  1639. var eolState = cm.getStateAfter(pos.line);
  1640. var inList = eolState.list !== false;
  1641. if (inList) {
  1642. cm.execCommand("indentLess");
  1643. return;
  1644. }
  1645. if (cm.options.indentWithTabs) {
  1646. cm.execCommand("insertTab");
  1647. }
  1648. else {
  1649. var spaces = Array(cm.options.tabSize + 1).join(" ");
  1650. cm.replaceSelection(spaces);
  1651. }
  1652. };
  1653. /***/ }),
  1654. /***/ "27b5":
  1655. /***/ (function(module, exports, __webpack_require__) {
  1656. var defineProperty = __webpack_require__("d910").f;
  1657. var has = __webpack_require__("faa8");
  1658. var wellKnownSymbol = __webpack_require__("90fb");
  1659. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  1660. module.exports = function (it, TAG, STATIC) {
  1661. if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) {
  1662. defineProperty(it, TO_STRING_TAG, { configurable: true, value: TAG });
  1663. }
  1664. };
  1665. /***/ }),
  1666. /***/ "31e2":
  1667. /***/ (function(module, exports, __webpack_require__) {
  1668. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1669. // Distributed under an MIT license: https://codemirror.net/LICENSE
  1670. (function(mod) {
  1671. if (true) // CommonJS
  1672. mod(__webpack_require__("a564"));
  1673. else {}
  1674. })(function(CodeMirror) {
  1675. "use strict";
  1676. CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
  1677. if (old == CodeMirror.Init) old = false;
  1678. if (!old == !val) return;
  1679. if (val) setFullscreen(cm);
  1680. else setNormal(cm);
  1681. });
  1682. function setFullscreen(cm) {
  1683. var wrap = cm.getWrapperElement();
  1684. cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
  1685. width: wrap.style.width, height: wrap.style.height};
  1686. wrap.style.width = "";
  1687. wrap.style.height = "auto";
  1688. wrap.className += " CodeMirror-fullscreen";
  1689. document.documentElement.style.overflow = "hidden";
  1690. cm.refresh();
  1691. }
  1692. function setNormal(cm) {
  1693. var wrap = cm.getWrapperElement();
  1694. wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
  1695. document.documentElement.style.overflow = "";
  1696. var info = cm.state.fullScreenRestore;
  1697. wrap.style.width = info.width; wrap.style.height = info.height;
  1698. window.scrollTo(info.scrollLeft, info.scrollTop);
  1699. cm.refresh();
  1700. }
  1701. });
  1702. /***/ }),
  1703. /***/ "322c":
  1704. /***/ (function(module, exports) {
  1705. /**
  1706. * Helpers
  1707. */
  1708. const escapeTest = /[&<>"']/;
  1709. const escapeReplace = /[&<>"']/g;
  1710. const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
  1711. const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
  1712. const escapeReplacements = {
  1713. '&': '&amp;',
  1714. '<': '&lt;',
  1715. '>': '&gt;',
  1716. '"': '&quot;',
  1717. "'": '&#39;'
  1718. };
  1719. const getEscapeReplacement = (ch) => escapeReplacements[ch];
  1720. function escape(html, encode) {
  1721. if (encode) {
  1722. if (escapeTest.test(html)) {
  1723. return html.replace(escapeReplace, getEscapeReplacement);
  1724. }
  1725. } else {
  1726. if (escapeTestNoEncode.test(html)) {
  1727. return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
  1728. }
  1729. }
  1730. return html;
  1731. }
  1732. const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
  1733. function unescape(html) {
  1734. // explicitly match decimal, hex, and named HTML entities
  1735. return html.replace(unescapeTest, (_, n) => {
  1736. n = n.toLowerCase();
  1737. if (n === 'colon') return ':';
  1738. if (n.charAt(0) === '#') {
  1739. return n.charAt(1) === 'x'
  1740. ? String.fromCharCode(parseInt(n.substring(2), 16))
  1741. : String.fromCharCode(+n.substring(1));
  1742. }
  1743. return '';
  1744. });
  1745. }
  1746. const caret = /(^|[^\[])\^/g;
  1747. function edit(regex, opt) {
  1748. regex = regex.source || regex;
  1749. opt = opt || '';
  1750. const obj = {
  1751. replace: (name, val) => {
  1752. val = val.source || val;
  1753. val = val.replace(caret, '$1');
  1754. regex = regex.replace(name, val);
  1755. return obj;
  1756. },
  1757. getRegex: () => {
  1758. return new RegExp(regex, opt);
  1759. }
  1760. };
  1761. return obj;
  1762. }
  1763. const nonWordAndColonTest = /[^\w:]/g;
  1764. const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
  1765. function cleanUrl(sanitize, base, href) {
  1766. if (sanitize) {
  1767. let prot;
  1768. try {
  1769. prot = decodeURIComponent(unescape(href))
  1770. .replace(nonWordAndColonTest, '')
  1771. .toLowerCase();
  1772. } catch (e) {
  1773. return null;
  1774. }
  1775. if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
  1776. return null;
  1777. }
  1778. }
  1779. if (base && !originIndependentUrl.test(href)) {
  1780. href = resolveUrl(base, href);
  1781. }
  1782. try {
  1783. href = encodeURI(href).replace(/%25/g, '%');
  1784. } catch (e) {
  1785. return null;
  1786. }
  1787. return href;
  1788. }
  1789. const baseUrls = {};
  1790. const justDomain = /^[^:]+:\/*[^/]*$/;
  1791. const protocol = /^([^:]+:)[\s\S]*$/;
  1792. const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
  1793. function resolveUrl(base, href) {
  1794. if (!baseUrls[' ' + base]) {
  1795. // we can ignore everything in base after the last slash of its path component,
  1796. // but we might need to add _that_
  1797. // https://tools.ietf.org/html/rfc3986#section-3
  1798. if (justDomain.test(base)) {
  1799. baseUrls[' ' + base] = base + '/';
  1800. } else {
  1801. baseUrls[' ' + base] = rtrim(base, '/', true);
  1802. }
  1803. }
  1804. base = baseUrls[' ' + base];
  1805. const relativeBase = base.indexOf(':') === -1;
  1806. if (href.substring(0, 2) === '//') {
  1807. if (relativeBase) {
  1808. return href;
  1809. }
  1810. return base.replace(protocol, '$1') + href;
  1811. } else if (href.charAt(0) === '/') {
  1812. if (relativeBase) {
  1813. return href;
  1814. }
  1815. return base.replace(domain, '$1') + href;
  1816. } else {
  1817. return base + href;
  1818. }
  1819. }
  1820. const noopTest = { exec: function noopTest() {} };
  1821. function merge(obj) {
  1822. let i = 1,
  1823. target,
  1824. key;
  1825. for (; i < arguments.length; i++) {
  1826. target = arguments[i];
  1827. for (key in target) {
  1828. if (Object.prototype.hasOwnProperty.call(target, key)) {
  1829. obj[key] = target[key];
  1830. }
  1831. }
  1832. }
  1833. return obj;
  1834. }
  1835. function splitCells(tableRow, count) {
  1836. // ensure that every cell-delimiting pipe has a space
  1837. // before it to distinguish it from an escaped pipe
  1838. const row = tableRow.replace(/\|/g, (match, offset, str) => {
  1839. let escaped = false,
  1840. curr = offset;
  1841. while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
  1842. if (escaped) {
  1843. // odd number of slashes means | is escaped
  1844. // so we leave it alone
  1845. return '|';
  1846. } else {
  1847. // add space before unescaped |
  1848. return ' |';
  1849. }
  1850. }),
  1851. cells = row.split(/ \|/);
  1852. let i = 0;
  1853. if (cells.length > count) {
  1854. cells.splice(count);
  1855. } else {
  1856. while (cells.length < count) cells.push('');
  1857. }
  1858. for (; i < cells.length; i++) {
  1859. // leading or trailing whitespace is ignored per the gfm spec
  1860. cells[i] = cells[i].trim().replace(/\\\|/g, '|');
  1861. }
  1862. return cells;
  1863. }
  1864. // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
  1865. // /c*$/ is vulnerable to REDOS.
  1866. // invert: Remove suffix of non-c chars instead. Default falsey.
  1867. function rtrim(str, c, invert) {
  1868. const l = str.length;
  1869. if (l === 0) {
  1870. return '';
  1871. }
  1872. // Length of suffix matching the invert condition.
  1873. let suffLen = 0;
  1874. // Step left until we fail to match the invert condition.
  1875. while (suffLen < l) {
  1876. const currChar = str.charAt(l - suffLen - 1);
  1877. if (currChar === c && !invert) {
  1878. suffLen++;
  1879. } else if (currChar !== c && invert) {
  1880. suffLen++;
  1881. } else {
  1882. break;
  1883. }
  1884. }
  1885. return str.substr(0, l - suffLen);
  1886. }
  1887. function findClosingBracket(str, b) {
  1888. if (str.indexOf(b[1]) === -1) {
  1889. return -1;
  1890. }
  1891. const l = str.length;
  1892. let level = 0,
  1893. i = 0;
  1894. for (; i < l; i++) {
  1895. if (str[i] === '\\') {
  1896. i++;
  1897. } else if (str[i] === b[0]) {
  1898. level++;
  1899. } else if (str[i] === b[1]) {
  1900. level--;
  1901. if (level < 0) {
  1902. return i;
  1903. }
  1904. }
  1905. }
  1906. return -1;
  1907. }
  1908. function checkSanitizeDeprecation(opt) {
  1909. if (opt && opt.sanitize && !opt.silent) {
  1910. 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');
  1911. }
  1912. }
  1913. module.exports = {
  1914. escape,
  1915. unescape,
  1916. edit,
  1917. cleanUrl,
  1918. resolveUrl,
  1919. noopTest,
  1920. merge,
  1921. splitCells,
  1922. rtrim,
  1923. findClosingBracket,
  1924. checkSanitizeDeprecation
  1925. };
  1926. /***/ }),
  1927. /***/ "3553":
  1928. /***/ (function(module, exports, __webpack_require__) {
  1929. var requireObjectCoercible = __webpack_require__("2732");
  1930. // `ToObject` abstract operation
  1931. // https://tc39.github.io/ecma262/#sec-toobject
  1932. module.exports = function (argument) {
  1933. return Object(requireObjectCoercible(argument));
  1934. };
  1935. /***/ }),
  1936. /***/ "3787":
  1937. /***/ (function(module, exports, __webpack_require__) {
  1938. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  1939. // Distributed under an MIT license: https://codemirror.net/LICENSE
  1940. (function(mod) {
  1941. if (true) // CommonJS
  1942. mod(__webpack_require__("a564"), __webpack_require__("fe5a"), __webpack_require__("d776"));
  1943. else {}
  1944. })(function(CodeMirror) {
  1945. "use strict";
  1946. 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
  1947. CodeMirror.defineMode("gfm", function(config, modeConfig) {
  1948. var codeDepth = 0;
  1949. function blankLine(state) {
  1950. state.code = false;
  1951. return null;
  1952. }
  1953. var gfmOverlay = {
  1954. startState: function() {
  1955. return {
  1956. code: false,
  1957. codeBlock: false,
  1958. ateSpace: false
  1959. };
  1960. },
  1961. copyState: function(s) {
  1962. return {
  1963. code: s.code,
  1964. codeBlock: s.codeBlock,
  1965. ateSpace: s.ateSpace
  1966. };
  1967. },
  1968. token: function(stream, state) {
  1969. state.combineTokens = null;
  1970. // Hack to prevent formatting override inside code blocks (block and inline)
  1971. if (state.codeBlock) {
  1972. if (stream.match(/^```+/)) {
  1973. state.codeBlock = false;
  1974. return null;
  1975. }
  1976. stream.skipToEnd();
  1977. return null;
  1978. }
  1979. if (stream.sol()) {
  1980. state.code = false;
  1981. }
  1982. if (stream.sol() && stream.match(/^```+/)) {
  1983. stream.skipToEnd();
  1984. state.codeBlock = true;
  1985. return null;
  1986. }
  1987. // If this block is changed, it may need to be updated in Markdown mode
  1988. if (stream.peek() === '`') {
  1989. stream.next();
  1990. var before = stream.pos;
  1991. stream.eatWhile('`');
  1992. var difference = 1 + stream.pos - before;
  1993. if (!state.code) {
  1994. codeDepth = difference;
  1995. state.code = true;
  1996. } else {
  1997. if (difference === codeDepth) { // Must be exact
  1998. state.code = false;
  1999. }
  2000. }
  2001. return null;
  2002. } else if (state.code) {
  2003. stream.next();
  2004. return null;
  2005. }
  2006. // Check if space. If so, links can be formatted later on
  2007. if (stream.eatSpace()) {
  2008. state.ateSpace = true;
  2009. return null;
  2010. }
  2011. if (stream.sol() || state.ateSpace) {
  2012. state.ateSpace = false;
  2013. if (modeConfig.gitHubSpice !== false) {
  2014. if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?=.{0,6}\d)(?:[a-f0-9]{7,40}\b)/)) {
  2015. // User/Project@SHA
  2016. // User@SHA
  2017. // SHA
  2018. state.combineTokens = true;
  2019. return "link";
  2020. } else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
  2021. // User/Project#Num
  2022. // User#Num
  2023. // #Num
  2024. state.combineTokens = true;
  2025. return "link";
  2026. }
  2027. }
  2028. }
  2029. if (stream.match(urlRE) &&
  2030. stream.string.slice(stream.start - 2, stream.start) != "](" &&
  2031. (stream.start == 0 || /\W/.test(stream.string.charAt(stream.start - 1)))) {
  2032. // URLs
  2033. // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
  2034. // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
  2035. // And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL
  2036. state.combineTokens = true;
  2037. return "link";
  2038. }
  2039. stream.next();
  2040. return null;
  2041. },
  2042. blankLine: blankLine
  2043. };
  2044. var markdownConfig = {
  2045. taskLists: true,
  2046. strikethrough: true,
  2047. emoji: true
  2048. };
  2049. for (var attr in modeConfig) {
  2050. markdownConfig[attr] = modeConfig[attr];
  2051. }
  2052. markdownConfig.name = "markdown";
  2053. return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);
  2054. }, "markdown");
  2055. CodeMirror.defineMIME("text/x-gfm", "gfm");
  2056. });
  2057. /***/ }),
  2058. /***/ "38b9":
  2059. /***/ (function(module, exports) {
  2060. module.exports = function (bitmap, value) {
  2061. return {
  2062. enumerable: !(bitmap & 1),
  2063. configurable: !(bitmap & 2),
  2064. writable: !(bitmap & 4),
  2065. value: value
  2066. };
  2067. };
  2068. /***/ }),
  2069. /***/ "3a08":
  2070. /***/ (function(module, exports, __webpack_require__) {
  2071. var global = __webpack_require__("d890");
  2072. var setGlobal = __webpack_require__("e4db");
  2073. var SHARED = '__core-js_shared__';
  2074. var store = global[SHARED] || setGlobal(SHARED, {});
  2075. module.exports = store;
  2076. /***/ }),
  2077. /***/ "3c10":
  2078. /***/ (function(module, exports, __webpack_require__) {
  2079. "use strict";
  2080. var $forEach = __webpack_require__("5dfd").forEach;
  2081. var arrayMethodIsStrict = __webpack_require__("d7e1");
  2082. var arrayMethodUsesToLength = __webpack_require__("ff9c");
  2083. var STRICT_METHOD = arrayMethodIsStrict('forEach');
  2084. var USES_TO_LENGTH = arrayMethodUsesToLength('forEach');
  2085. // `Array.prototype.forEach` method implementation
  2086. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  2087. module.exports = (!STRICT_METHOD || !USES_TO_LENGTH) ? function forEach(callbackfn /* , thisArg */) {
  2088. return $forEach(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  2089. } : [].forEach;
  2090. /***/ }),
  2091. /***/ "3da3":
  2092. /***/ (function(module, exports) {
  2093. var ceil = Math.ceil;
  2094. var floor = Math.floor;
  2095. // `ToInteger` abstract operation
  2096. // https://tc39.github.io/ecma262/#sec-tointeger
  2097. module.exports = function (argument) {
  2098. return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
  2099. };
  2100. /***/ }),
  2101. /***/ "4350":
  2102. /***/ (function(module, exports, __webpack_require__) {
  2103. var wellKnownSymbol = __webpack_require__("90fb");
  2104. exports.f = wellKnownSymbol;
  2105. /***/ }),
  2106. /***/ "45af":
  2107. /***/ (function(module, exports, __webpack_require__) {
  2108. var toIndexedObject = __webpack_require__("da10");
  2109. var toLength = __webpack_require__("d88d");
  2110. var toAbsoluteIndex = __webpack_require__("e1d6");
  2111. // `Array.prototype.{ indexOf, includes }` methods implementation
  2112. var createMethod = function (IS_INCLUDES) {
  2113. return function ($this, el, fromIndex) {
  2114. var O = toIndexedObject($this);
  2115. var length = toLength(O.length);
  2116. var index = toAbsoluteIndex(fromIndex, length);
  2117. var value;
  2118. // Array#includes uses SameValueZero equality algorithm
  2119. // eslint-disable-next-line no-self-compare
  2120. if (IS_INCLUDES && el != el) while (length > index) {
  2121. value = O[index++];
  2122. // eslint-disable-next-line no-self-compare
  2123. if (value != value) return true;
  2124. // Array#indexOf ignores holes, Array#includes - not
  2125. } else for (;length > index; index++) {
  2126. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  2127. } return !IS_INCLUDES && -1;
  2128. };
  2129. };
  2130. module.exports = {
  2131. // `Array.prototype.includes` method
  2132. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  2133. includes: createMethod(true),
  2134. // `Array.prototype.indexOf` method
  2135. // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
  2136. indexOf: createMethod(false)
  2137. };
  2138. /***/ }),
  2139. /***/ "4cd0":
  2140. /***/ (function(module, exports, __webpack_require__) {
  2141. "use strict";
  2142. // Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)
  2143. // Requires
  2144. var Typo = __webpack_require__("0654");
  2145. // Create function
  2146. function CodeMirrorSpellChecker(options) {
  2147. // Initialize
  2148. options = options || {};
  2149. // Verify
  2150. if(typeof options.codeMirrorInstance !== "function" || typeof options.codeMirrorInstance.defineMode !== "function") {
  2151. console.log("CodeMirror Spell Checker: You must provide an instance of CodeMirror via the option `codeMirrorInstance`");
  2152. return;
  2153. }
  2154. // Because some browsers don't support this functionality yet
  2155. if(!String.prototype.includes) {
  2156. String.prototype.includes = function() {
  2157. "use strict";
  2158. return String.prototype.indexOf.apply(this, arguments) !== -1;
  2159. };
  2160. }
  2161. // Define the new mode
  2162. options.codeMirrorInstance.defineMode("spell-checker", function(config) {
  2163. // Load AFF/DIC data
  2164. if(!CodeMirrorSpellChecker.aff_loading) {
  2165. CodeMirrorSpellChecker.aff_loading = true;
  2166. var xhr_aff = new XMLHttpRequest();
  2167. xhr_aff.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff", true);
  2168. xhr_aff.onload = function() {
  2169. if(xhr_aff.readyState === 4 && xhr_aff.status === 200) {
  2170. CodeMirrorSpellChecker.aff_data = xhr_aff.responseText;
  2171. CodeMirrorSpellChecker.num_loaded++;
  2172. if(CodeMirrorSpellChecker.num_loaded == 2) {
  2173. CodeMirrorSpellChecker.typo = new Typo("en_US", CodeMirrorSpellChecker.aff_data, CodeMirrorSpellChecker.dic_data, {
  2174. platform: "any"
  2175. });
  2176. }
  2177. }
  2178. };
  2179. xhr_aff.send(null);
  2180. }
  2181. if(!CodeMirrorSpellChecker.dic_loading) {
  2182. CodeMirrorSpellChecker.dic_loading = true;
  2183. var xhr_dic = new XMLHttpRequest();
  2184. xhr_dic.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic", true);
  2185. xhr_dic.onload = function() {
  2186. if(xhr_dic.readyState === 4 && xhr_dic.status === 200) {
  2187. CodeMirrorSpellChecker.dic_data = xhr_dic.responseText;
  2188. CodeMirrorSpellChecker.num_loaded++;
  2189. if(CodeMirrorSpellChecker.num_loaded == 2) {
  2190. CodeMirrorSpellChecker.typo = new Typo("en_US", CodeMirrorSpellChecker.aff_data, CodeMirrorSpellChecker.dic_data, {
  2191. platform: "any"
  2192. });
  2193. }
  2194. }
  2195. };
  2196. xhr_dic.send(null);
  2197. }
  2198. // Define what separates a word
  2199. var rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ";
  2200. // Create the overlay and such
  2201. var overlay = {
  2202. token: function(stream) {
  2203. var ch = stream.peek();
  2204. var word = "";
  2205. if(rx_word.includes(ch)) {
  2206. stream.next();
  2207. return null;
  2208. }
  2209. while((ch = stream.peek()) != null && !rx_word.includes(ch)) {
  2210. word += ch;
  2211. stream.next();
  2212. }
  2213. if(CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word))
  2214. return "spell-error"; // CSS class: cm-spell-error
  2215. return null;
  2216. }
  2217. };
  2218. var mode = options.codeMirrorInstance.getMode(
  2219. config, config.backdrop || "text/plain"
  2220. );
  2221. return options.codeMirrorInstance.overlayMode(mode, overlay, true);
  2222. });
  2223. }
  2224. // Initialize data globally to reduce memory consumption
  2225. CodeMirrorSpellChecker.num_loaded = 0;
  2226. CodeMirrorSpellChecker.aff_loading = false;
  2227. CodeMirrorSpellChecker.dic_loading = false;
  2228. CodeMirrorSpellChecker.aff_data = "";
  2229. CodeMirrorSpellChecker.dic_data = "";
  2230. CodeMirrorSpellChecker.typo;
  2231. // Export
  2232. module.exports = CodeMirrorSpellChecker;
  2233. /***/ }),
  2234. /***/ "4d02":
  2235. /***/ (function(module, exports, __webpack_require__) {
  2236. "use strict";
  2237. /*global require,module*/
  2238. var CodeMirror = __webpack_require__("a564");
  2239. __webpack_require__("7899");
  2240. __webpack_require__("27b3");
  2241. __webpack_require__("31e2");
  2242. __webpack_require__("fe5a");
  2243. __webpack_require__("d776");
  2244. __webpack_require__("f590");
  2245. __webpack_require__("21ed");
  2246. __webpack_require__("3787");
  2247. __webpack_require__("b2e0");
  2248. var CodeMirrorSpellChecker = __webpack_require__("4cd0");
  2249. var marked = __webpack_require__("094f");
  2250. // Some variables
  2251. var isMac = /Mac/.test(navigator.platform);
  2252. // Mapping of actions that can be bound to keyboard shortcuts or toolbar buttons
  2253. var bindings = {
  2254. "toggleBold": toggleBold,
  2255. "toggleItalic": toggleItalic,
  2256. "drawLink": drawLink,
  2257. "toggleHeadingSmaller": toggleHeadingSmaller,
  2258. "toggleHeadingBigger": toggleHeadingBigger,
  2259. "drawImage": drawImage,
  2260. "toggleBlockquote": toggleBlockquote,
  2261. "toggleOrderedList": toggleOrderedList,
  2262. "toggleUnorderedList": toggleUnorderedList,
  2263. "toggleCodeBlock": toggleCodeBlock,
  2264. "togglePreview": togglePreview,
  2265. "toggleStrikethrough": toggleStrikethrough,
  2266. "toggleHeading1": toggleHeading1,
  2267. "toggleHeading2": toggleHeading2,
  2268. "toggleHeading3": toggleHeading3,
  2269. "cleanBlock": cleanBlock,
  2270. "drawTable": drawTable,
  2271. "drawHorizontalRule": drawHorizontalRule,
  2272. "undo": undo,
  2273. "redo": redo,
  2274. "toggleSideBySide": toggleSideBySide,
  2275. "toggleFullScreen": toggleFullScreen
  2276. };
  2277. var shortcuts = {
  2278. "toggleBold": "Cmd-B",
  2279. "toggleItalic": "Cmd-I",
  2280. "drawLink": "Cmd-K",
  2281. "toggleHeadingSmaller": "Cmd-H",
  2282. "toggleHeadingBigger": "Shift-Cmd-H",
  2283. "cleanBlock": "Cmd-E",
  2284. "drawImage": "Cmd-Alt-I",
  2285. "toggleBlockquote": "Cmd-'",
  2286. "toggleOrderedList": "Cmd-Alt-L",
  2287. "toggleUnorderedList": "Cmd-L",
  2288. "toggleCodeBlock": "Cmd-Alt-C",
  2289. "togglePreview": "Cmd-P",
  2290. "toggleSideBySide": "F9",
  2291. "toggleFullScreen": "F11"
  2292. };
  2293. var getBindingName = function(f) {
  2294. for(var key in bindings) {
  2295. if(bindings[key] === f) {
  2296. return key;
  2297. }
  2298. }
  2299. return null;
  2300. };
  2301. var isMobile = function() {
  2302. var check = false;
  2303. (function(a) {
  2304. 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;
  2305. })(navigator.userAgent || navigator.vendor || window.opera);
  2306. return check;
  2307. };
  2308. /**
  2309. * Fix shortcut. Mac use Command, others use Ctrl.
  2310. */
  2311. function fixShortcut(name) {
  2312. if(isMac) {
  2313. name = name.replace("Ctrl", "Cmd");
  2314. } else {
  2315. name = name.replace("Cmd", "Ctrl");
  2316. }
  2317. return name;
  2318. }
  2319. /**
  2320. * Create icon element for toolbar.
  2321. */
  2322. function createIcon(options, enableTooltips, shortcuts) {
  2323. options = options || {};
  2324. var el = document.createElement("a");
  2325. enableTooltips = (enableTooltips == undefined) ? true : enableTooltips;
  2326. if(options.title && enableTooltips) {
  2327. el.title = createTootlip(options.title, options.action, shortcuts);
  2328. if(isMac) {
  2329. el.title = el.title.replace("Ctrl", "⌘");
  2330. el.title = el.title.replace("Alt", "⌥");
  2331. }
  2332. }
  2333. el.tabIndex = -1;
  2334. el.className = options.className;
  2335. return el;
  2336. }
  2337. function createSep() {
  2338. var el = document.createElement("i");
  2339. el.className = "separator";
  2340. el.innerHTML = "|";
  2341. return el;
  2342. }
  2343. function createTootlip(title, action, shortcuts) {
  2344. var actionName;
  2345. var tooltip = title;
  2346. if(action) {
  2347. actionName = getBindingName(action);
  2348. if(shortcuts[actionName]) {
  2349. tooltip += " (" + fixShortcut(shortcuts[actionName]) + ")";
  2350. }
  2351. }
  2352. return tooltip;
  2353. }
  2354. /**
  2355. * The state of CodeMirror at the given position.
  2356. */
  2357. function getState(cm, pos) {
  2358. pos = pos || cm.getCursor("start");
  2359. var stat = cm.getTokenAt(pos);
  2360. if(!stat.type) return {};
  2361. var types = stat.type.split(" ");
  2362. var ret = {},
  2363. data, text;
  2364. for(var i = 0; i < types.length; i++) {
  2365. data = types[i];
  2366. if(data === "strong") {
  2367. ret.bold = true;
  2368. } else if(data === "variable-2") {
  2369. text = cm.getLine(pos.line);
  2370. if(/^\s*\d+\.\s/.test(text)) {
  2371. ret["ordered-list"] = true;
  2372. } else {
  2373. ret["unordered-list"] = true;
  2374. }
  2375. } else if(data === "atom") {
  2376. ret.quote = true;
  2377. } else if(data === "em") {
  2378. ret.italic = true;
  2379. } else if(data === "quote") {
  2380. ret.quote = true;
  2381. } else if(data === "strikethrough") {
  2382. ret.strikethrough = true;
  2383. } else if(data === "comment") {
  2384. ret.code = true;
  2385. } else if(data === "link") {
  2386. ret.link = true;
  2387. } else if(data === "tag") {
  2388. ret.image = true;
  2389. } else if(data.match(/^header(\-[1-6])?$/)) {
  2390. ret[data.replace("header", "heading")] = true;
  2391. }
  2392. }
  2393. return ret;
  2394. }
  2395. // Saved overflow setting
  2396. var saved_overflow = "";
  2397. /**
  2398. * Toggle full screen of the editor.
  2399. */
  2400. function toggleFullScreen(editor) {
  2401. // Set fullscreen
  2402. var cm = editor.codemirror;
  2403. cm.setOption("fullScreen", !cm.getOption("fullScreen"));
  2404. // Prevent scrolling on body during fullscreen active
  2405. if(cm.getOption("fullScreen")) {
  2406. saved_overflow = document.body.style.overflow;
  2407. document.body.style.overflow = "hidden";
  2408. } else {
  2409. document.body.style.overflow = saved_overflow;
  2410. }
  2411. // Update toolbar class
  2412. var wrap = cm.getWrapperElement();
  2413. if(!/fullscreen/.test(wrap.previousSibling.className)) {
  2414. wrap.previousSibling.className += " fullscreen";
  2415. } else {
  2416. wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, "");
  2417. }
  2418. // Update toolbar button
  2419. var toolbarButton = editor.toolbarElements.fullscreen;
  2420. if(!/active/.test(toolbarButton.className)) {
  2421. toolbarButton.className += " active";
  2422. } else {
  2423. toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, "");
  2424. }
  2425. // Hide side by side if needed
  2426. var sidebyside = cm.getWrapperElement().nextSibling;
  2427. if(/editor-preview-active-side/.test(sidebyside.className))
  2428. toggleSideBySide(editor);
  2429. }
  2430. /**
  2431. * Action for toggling bold.
  2432. */
  2433. function toggleBold(editor) {
  2434. _toggleBlock(editor, "bold", editor.options.blockStyles.bold);
  2435. }
  2436. /**
  2437. * Action for toggling italic.
  2438. */
  2439. function toggleItalic(editor) {
  2440. _toggleBlock(editor, "italic", editor.options.blockStyles.italic);
  2441. }
  2442. /**
  2443. * Action for toggling strikethrough.
  2444. */
  2445. function toggleStrikethrough(editor) {
  2446. _toggleBlock(editor, "strikethrough", "~~");
  2447. }
  2448. /**
  2449. * Action for toggling code block.
  2450. */
  2451. function toggleCodeBlock(editor) {
  2452. var fenceCharsToInsert = editor.options.blockStyles.code;
  2453. function fencing_line(line) {
  2454. /* return true, if this is a ``` or ~~~ line */
  2455. if(typeof line !== "object") {
  2456. throw "fencing_line() takes a 'line' object (not a line number, or line text). Got: " + typeof line + ": " + line;
  2457. }
  2458. return line.styles && line.styles[2] && line.styles[2].indexOf("formatting-code-block") !== -1;
  2459. }
  2460. function token_state(token) {
  2461. // base goes an extra level deep when mode backdrops are used, e.g. spellchecker on
  2462. return token.state.base.base || token.state.base;
  2463. }
  2464. function code_type(cm, line_num, line, firstTok, lastTok) {
  2465. /*
  2466. * Return "single", "indented", "fenced" or false
  2467. *
  2468. * cm and line_num are required. Others are optional for efficiency
  2469. * To check in the middle of a line, pass in firstTok yourself.
  2470. */
  2471. line = line || cm.getLineHandle(line_num);
  2472. firstTok = firstTok || cm.getTokenAt({
  2473. line: line_num,
  2474. ch: 1
  2475. });
  2476. lastTok = lastTok || (!!line.text && cm.getTokenAt({
  2477. line: line_num,
  2478. ch: line.text.length - 1
  2479. }));
  2480. var types = firstTok.type ? firstTok.type.split(" ") : [];
  2481. if(lastTok && token_state(lastTok).indentedCode) {
  2482. // have to check last char, since first chars of first line aren"t marked as indented
  2483. return "indented";
  2484. } else if(types.indexOf("comment") === -1) {
  2485. // has to be after "indented" check, since first chars of first indented line aren"t marked as such
  2486. return false;
  2487. } else if(token_state(firstTok).fencedChars || token_state(lastTok).fencedChars || fencing_line(line)) {
  2488. return "fenced";
  2489. } else {
  2490. return "single";
  2491. }
  2492. }
  2493. function insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert) {
  2494. var start_line_sel = cur_start.line + 1,
  2495. end_line_sel = cur_end.line + 1,
  2496. sel_multi = cur_start.line !== cur_end.line,
  2497. repl_start = fenceCharsToInsert + "\n",
  2498. repl_end = "\n" + fenceCharsToInsert;
  2499. if(sel_multi) {
  2500. end_line_sel++;
  2501. }
  2502. // handle last char including \n or not
  2503. if(sel_multi && cur_end.ch === 0) {
  2504. repl_end = fenceCharsToInsert + "\n";
  2505. end_line_sel--;
  2506. }
  2507. _replaceSelection(cm, false, [repl_start, repl_end]);
  2508. cm.setSelection({
  2509. line: start_line_sel,
  2510. ch: 0
  2511. }, {
  2512. line: end_line_sel,
  2513. ch: 0
  2514. });
  2515. }
  2516. var cm = editor.codemirror,
  2517. cur_start = cm.getCursor("start"),
  2518. cur_end = cm.getCursor("end"),
  2519. tok = cm.getTokenAt({
  2520. line: cur_start.line,
  2521. ch: cur_start.ch || 1
  2522. }), // avoid ch 0 which is a cursor pos but not token
  2523. line = cm.getLineHandle(cur_start.line),
  2524. is_code = code_type(cm, cur_start.line, line, tok);
  2525. var block_start, block_end, lineCount;
  2526. if(is_code === "single") {
  2527. // similar to some SimpleMDE _toggleBlock logic
  2528. var start = line.text.slice(0, cur_start.ch).replace("`", ""),
  2529. end = line.text.slice(cur_start.ch).replace("`", "");
  2530. cm.replaceRange(start + end, {
  2531. line: cur_start.line,
  2532. ch: 0
  2533. }, {
  2534. line: cur_start.line,
  2535. ch: 99999999999999
  2536. });
  2537. cur_start.ch--;
  2538. if(cur_start !== cur_end) {
  2539. cur_end.ch--;
  2540. }
  2541. cm.setSelection(cur_start, cur_end);
  2542. cm.focus();
  2543. } else if(is_code === "fenced") {
  2544. if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) {
  2545. // use selection
  2546. // find the fenced line so we know what type it is (tilde, backticks, number of them)
  2547. for(block_start = cur_start.line; block_start >= 0; block_start--) {
  2548. line = cm.getLineHandle(block_start);
  2549. if(fencing_line(line)) {
  2550. break;
  2551. }
  2552. }
  2553. var fencedTok = cm.getTokenAt({
  2554. line: block_start,
  2555. ch: 1
  2556. });
  2557. var fence_chars = token_state(fencedTok).fencedChars;
  2558. var start_text, start_line;
  2559. var end_text, end_line;
  2560. // check for selection going up against fenced lines, in which case we don't want to add more fencing
  2561. if(fencing_line(cm.getLineHandle(cur_start.line))) {
  2562. start_text = "";
  2563. start_line = cur_start.line;
  2564. } else if(fencing_line(cm.getLineHandle(cur_start.line - 1))) {
  2565. start_text = "";
  2566. start_line = cur_start.line - 1;
  2567. } else {
  2568. start_text = fence_chars + "\n";
  2569. start_line = cur_start.line;
  2570. }
  2571. if(fencing_line(cm.getLineHandle(cur_end.line))) {
  2572. end_text = "";
  2573. end_line = cur_end.line;
  2574. if(cur_end.ch === 0) {
  2575. end_line += 1;
  2576. }
  2577. } else if(cur_end.ch !== 0 && fencing_line(cm.getLineHandle(cur_end.line + 1))) {
  2578. end_text = "";
  2579. end_line = cur_end.line + 1;
  2580. } else {
  2581. end_text = fence_chars + "\n";
  2582. end_line = cur_end.line + 1;
  2583. }
  2584. if(cur_end.ch === 0) {
  2585. // full last line selected, putting cursor at beginning of next
  2586. end_line -= 1;
  2587. }
  2588. cm.operation(function() {
  2589. // end line first, so that line numbers don't change
  2590. cm.replaceRange(end_text, {
  2591. line: end_line,
  2592. ch: 0
  2593. }, {
  2594. line: end_line + (end_text ? 0 : 1),
  2595. ch: 0
  2596. });
  2597. cm.replaceRange(start_text, {
  2598. line: start_line,
  2599. ch: 0
  2600. }, {
  2601. line: start_line + (start_text ? 0 : 1),
  2602. ch: 0
  2603. });
  2604. });
  2605. cm.setSelection({
  2606. line: start_line + (start_text ? 1 : 0),
  2607. ch: 0
  2608. }, {
  2609. line: end_line + (start_text ? 1 : -1),
  2610. ch: 0
  2611. });
  2612. cm.focus();
  2613. } else {
  2614. // no selection, search for ends of this fenced block
  2615. var search_from = cur_start.line;
  2616. if(fencing_line(cm.getLineHandle(cur_start.line))) { // gets a little tricky if cursor is right on a fenced line
  2617. if(code_type(cm, cur_start.line + 1) === "fenced") {
  2618. block_start = cur_start.line;
  2619. search_from = cur_start.line + 1; // for searching for "end"
  2620. } else {
  2621. block_end = cur_start.line;
  2622. search_from = cur_start.line - 1; // for searching for "start"
  2623. }
  2624. }
  2625. if(block_start === undefined) {
  2626. for(block_start = search_from; block_start >= 0; block_start--) {
  2627. line = cm.getLineHandle(block_start);
  2628. if(fencing_line(line)) {
  2629. break;
  2630. }
  2631. }
  2632. }
  2633. if(block_end === undefined) {
  2634. lineCount = cm.lineCount();
  2635. for(block_end = search_from; block_end < lineCount; block_end++) {
  2636. line = cm.getLineHandle(block_end);
  2637. if(fencing_line(line)) {
  2638. break;
  2639. }
  2640. }
  2641. }
  2642. cm.operation(function() {
  2643. cm.replaceRange("", {
  2644. line: block_start,
  2645. ch: 0
  2646. }, {
  2647. line: block_start + 1,
  2648. ch: 0
  2649. });
  2650. cm.replaceRange("", {
  2651. line: block_end - 1,
  2652. ch: 0
  2653. }, {
  2654. line: block_end,
  2655. ch: 0
  2656. });
  2657. });
  2658. cm.focus();
  2659. }
  2660. } else if(is_code === "indented") {
  2661. if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) {
  2662. // use selection
  2663. block_start = cur_start.line;
  2664. block_end = cur_end.line;
  2665. if(cur_end.ch === 0) {
  2666. block_end--;
  2667. }
  2668. } else {
  2669. // no selection, search for ends of this indented block
  2670. for(block_start = cur_start.line; block_start >= 0; block_start--) {
  2671. line = cm.getLineHandle(block_start);
  2672. if(line.text.match(/^\s*$/)) {
  2673. // empty or all whitespace - keep going
  2674. continue;
  2675. } else {
  2676. if(code_type(cm, block_start, line) !== "indented") {
  2677. block_start += 1;
  2678. break;
  2679. }
  2680. }
  2681. }
  2682. lineCount = cm.lineCount();
  2683. for(block_end = cur_start.line; block_end < lineCount; block_end++) {
  2684. line = cm.getLineHandle(block_end);
  2685. if(line.text.match(/^\s*$/)) {
  2686. // empty or all whitespace - keep going
  2687. continue;
  2688. } else {
  2689. if(code_type(cm, block_end, line) !== "indented") {
  2690. block_end -= 1;
  2691. break;
  2692. }
  2693. }
  2694. }
  2695. }
  2696. // if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to
  2697. // insert a blank line so that the next line(s) continue to be indented code
  2698. var next_line = cm.getLineHandle(block_end + 1),
  2699. next_line_last_tok = next_line && cm.getTokenAt({
  2700. line: block_end + 1,
  2701. ch: next_line.text.length - 1
  2702. }),
  2703. next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode;
  2704. if(next_line_indented) {
  2705. cm.replaceRange("\n", {
  2706. line: block_end + 1,
  2707. ch: 0
  2708. });
  2709. }
  2710. for(var i = block_start; i <= block_end; i++) {
  2711. cm.indentLine(i, "subtract"); // TODO: this doesn't get tracked in the history, so can't be undone :(
  2712. }
  2713. cm.focus();
  2714. } else {
  2715. // insert code formatting
  2716. var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0);
  2717. var sel_multi = cur_start.line !== cur_end.line;
  2718. if(no_sel_and_starting_of_line || sel_multi) {
  2719. insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert);
  2720. } else {
  2721. _replaceSelection(cm, false, ["`", "`"]);
  2722. }
  2723. }
  2724. }
  2725. /**
  2726. * Action for toggling blockquote.
  2727. */
  2728. function toggleBlockquote(editor) {
  2729. var cm = editor.codemirror;
  2730. _toggleLine(cm, "quote");
  2731. }
  2732. /**
  2733. * Action for toggling heading size: normal -> h1 -> h2 -> h3 -> h4 -> h5 -> h6 -> normal
  2734. */
  2735. function toggleHeadingSmaller(editor) {
  2736. var cm = editor.codemirror;
  2737. _toggleHeading(cm, "smaller");
  2738. }
  2739. /**
  2740. * Action for toggling heading size: normal -> h6 -> h5 -> h4 -> h3 -> h2 -> h1 -> normal
  2741. */
  2742. function toggleHeadingBigger(editor) {
  2743. var cm = editor.codemirror;
  2744. _toggleHeading(cm, "bigger");
  2745. }
  2746. /**
  2747. * Action for toggling heading size 1
  2748. */
  2749. function toggleHeading1(editor) {
  2750. var cm = editor.codemirror;
  2751. _toggleHeading(cm, undefined, 1);
  2752. }
  2753. /**
  2754. * Action for toggling heading size 2
  2755. */
  2756. function toggleHeading2(editor) {
  2757. var cm = editor.codemirror;
  2758. _toggleHeading(cm, undefined, 2);
  2759. }
  2760. /**
  2761. * Action for toggling heading size 3
  2762. */
  2763. function toggleHeading3(editor) {
  2764. var cm = editor.codemirror;
  2765. _toggleHeading(cm, undefined, 3);
  2766. }
  2767. /**
  2768. * Action for toggling ul.
  2769. */
  2770. function toggleUnorderedList(editor) {
  2771. var cm = editor.codemirror;
  2772. _toggleLine(cm, "unordered-list");
  2773. }
  2774. /**
  2775. * Action for toggling ol.
  2776. */
  2777. function toggleOrderedList(editor) {
  2778. var cm = editor.codemirror;
  2779. _toggleLine(cm, "ordered-list");
  2780. }
  2781. /**
  2782. * Action for clean block (remove headline, list, blockquote code, markers)
  2783. */
  2784. function cleanBlock(editor) {
  2785. var cm = editor.codemirror;
  2786. _cleanBlock(cm);
  2787. }
  2788. /**
  2789. * Action for drawing a link.
  2790. */
  2791. function drawLink(editor) {
  2792. var cm = editor.codemirror;
  2793. var stat = getState(cm);
  2794. var options = editor.options;
  2795. var url = "http://";
  2796. if(options.promptURLs) {
  2797. url = prompt(options.promptTexts.link);
  2798. if(!url) {
  2799. return false;
  2800. }
  2801. }
  2802. _replaceSelection(cm, stat.link, options.insertTexts.link, url);
  2803. }
  2804. /**
  2805. * Action for drawing an img.
  2806. */
  2807. function drawImage(editor) {
  2808. var cm = editor.codemirror;
  2809. var stat = getState(cm);
  2810. var options = editor.options;
  2811. var url = "http://";
  2812. if(options.promptURLs) {
  2813. url = prompt(options.promptTexts.image);
  2814. if(!url) {
  2815. return false;
  2816. }
  2817. }
  2818. _replaceSelection(cm, stat.image, options.insertTexts.image, url);
  2819. }
  2820. /**
  2821. * Action for drawing a table.
  2822. */
  2823. function drawTable(editor) {
  2824. var cm = editor.codemirror;
  2825. var stat = getState(cm);
  2826. var options = editor.options;
  2827. _replaceSelection(cm, stat.table, options.insertTexts.table);
  2828. }
  2829. /**
  2830. * Action for drawing a horizontal rule.
  2831. */
  2832. function drawHorizontalRule(editor) {
  2833. var cm = editor.codemirror;
  2834. var stat = getState(cm);
  2835. var options = editor.options;
  2836. _replaceSelection(cm, stat.image, options.insertTexts.horizontalRule);
  2837. }
  2838. /**
  2839. * Undo action.
  2840. */
  2841. function undo(editor) {
  2842. var cm = editor.codemirror;
  2843. cm.undo();
  2844. cm.focus();
  2845. }
  2846. /**
  2847. * Redo action.
  2848. */
  2849. function redo(editor) {
  2850. var cm = editor.codemirror;
  2851. cm.redo();
  2852. cm.focus();
  2853. }
  2854. /**
  2855. * Toggle side by side preview
  2856. */
  2857. function toggleSideBySide(editor) {
  2858. var cm = editor.codemirror;
  2859. var wrapper = cm.getWrapperElement();
  2860. var preview = wrapper.nextSibling;
  2861. var toolbarButton = editor.toolbarElements["side-by-side"];
  2862. var useSideBySideListener = false;
  2863. if(/editor-preview-active-side/.test(preview.className)) {
  2864. preview.className = preview.className.replace(
  2865. /\s*editor-preview-active-side\s*/g, ""
  2866. );
  2867. toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, "");
  2868. wrapper.className = wrapper.className.replace(/\s*CodeMirror-sided\s*/g, " ");
  2869. } else {
  2870. // When the preview button is clicked for the first time,
  2871. // give some time for the transition from editor.css to fire and the view to slide from right to left,
  2872. // instead of just appearing.
  2873. setTimeout(function() {
  2874. if(!cm.getOption("fullScreen"))
  2875. toggleFullScreen(editor);
  2876. preview.className += " editor-preview-active-side";
  2877. }, 1);
  2878. toolbarButton.className += " active";
  2879. wrapper.className += " CodeMirror-sided";
  2880. useSideBySideListener = true;
  2881. }
  2882. // Hide normal preview if active
  2883. var previewNormal = wrapper.lastChild;
  2884. if(/editor-preview-active/.test(previewNormal.className)) {
  2885. previewNormal.className = previewNormal.className.replace(
  2886. /\s*editor-preview-active\s*/g, ""
  2887. );
  2888. var toolbar = editor.toolbarElements.preview;
  2889. var toolbar_div = wrapper.previousSibling;
  2890. toolbar.className = toolbar.className.replace(/\s*active\s*/g, "");
  2891. toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, "");
  2892. }
  2893. var sideBySideRenderingFunction = function() {
  2894. preview.innerHTML = editor.options.previewRender(editor.value(), preview);
  2895. };
  2896. if(!cm.sideBySideRenderingFunction) {
  2897. cm.sideBySideRenderingFunction = sideBySideRenderingFunction;
  2898. }
  2899. if(useSideBySideListener) {
  2900. preview.innerHTML = editor.options.previewRender(editor.value(), preview);
  2901. cm.on("update", cm.sideBySideRenderingFunction);
  2902. } else {
  2903. cm.off("update", cm.sideBySideRenderingFunction);
  2904. }
  2905. // Refresh to fix selection being off (#309)
  2906. cm.refresh();
  2907. }
  2908. /**
  2909. * Preview action.
  2910. */
  2911. function togglePreview(editor) {
  2912. var cm = editor.codemirror;
  2913. var wrapper = cm.getWrapperElement();
  2914. var toolbar_div = wrapper.previousSibling;
  2915. var toolbar = editor.options.toolbar ? editor.toolbarElements.preview : false;
  2916. var preview = wrapper.lastChild;
  2917. if(!preview || !/editor-preview/.test(preview.className)) {
  2918. preview = document.createElement("div");
  2919. preview.className = "editor-preview";
  2920. wrapper.appendChild(preview);
  2921. }
  2922. if(/editor-preview-active/.test(preview.className)) {
  2923. preview.className = preview.className.replace(
  2924. /\s*editor-preview-active\s*/g, ""
  2925. );
  2926. if(toolbar) {
  2927. toolbar.className = toolbar.className.replace(/\s*active\s*/g, "");
  2928. toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, "");
  2929. }
  2930. } else {
  2931. // When the preview button is clicked for the first time,
  2932. // give some time for the transition from editor.css to fire and the view to slide from right to left,
  2933. // instead of just appearing.
  2934. setTimeout(function() {
  2935. preview.className += " editor-preview-active";
  2936. }, 1);
  2937. if(toolbar) {
  2938. toolbar.className += " active";
  2939. toolbar_div.className += " disabled-for-preview";
  2940. }
  2941. }
  2942. preview.innerHTML = editor.options.previewRender(editor.value(), preview);
  2943. // Turn off side by side if needed
  2944. var sidebyside = cm.getWrapperElement().nextSibling;
  2945. if(/editor-preview-active-side/.test(sidebyside.className))
  2946. toggleSideBySide(editor);
  2947. }
  2948. function _replaceSelection(cm, active, startEnd, url) {
  2949. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  2950. return;
  2951. var text;
  2952. var start = startEnd[0];
  2953. var end = startEnd[1];
  2954. var startPoint = cm.getCursor("start");
  2955. var endPoint = cm.getCursor("end");
  2956. if(url) {
  2957. end = end.replace("#url#", url);
  2958. }
  2959. if(active) {
  2960. text = cm.getLine(startPoint.line);
  2961. start = text.slice(0, startPoint.ch);
  2962. end = text.slice(startPoint.ch);
  2963. cm.replaceRange(start + end, {
  2964. line: startPoint.line,
  2965. ch: 0
  2966. });
  2967. } else {
  2968. text = cm.getSelection();
  2969. cm.replaceSelection(start + text + end);
  2970. startPoint.ch += start.length;
  2971. if(startPoint !== endPoint) {
  2972. endPoint.ch += start.length;
  2973. }
  2974. }
  2975. cm.setSelection(startPoint, endPoint);
  2976. cm.focus();
  2977. }
  2978. function _toggleHeading(cm, direction, size) {
  2979. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  2980. return;
  2981. var startPoint = cm.getCursor("start");
  2982. var endPoint = cm.getCursor("end");
  2983. for(var i = startPoint.line; i <= endPoint.line; i++) {
  2984. (function(i) {
  2985. var text = cm.getLine(i);
  2986. var currHeadingLevel = text.search(/[^#]/);
  2987. if(direction !== undefined) {
  2988. if(currHeadingLevel <= 0) {
  2989. if(direction == "bigger") {
  2990. text = "###### " + text;
  2991. } else {
  2992. text = "# " + text;
  2993. }
  2994. } else if(currHeadingLevel == 6 && direction == "smaller") {
  2995. text = text.substr(7);
  2996. } else if(currHeadingLevel == 1 && direction == "bigger") {
  2997. text = text.substr(2);
  2998. } else {
  2999. if(direction == "bigger") {
  3000. text = text.substr(1);
  3001. } else {
  3002. text = "#" + text;
  3003. }
  3004. }
  3005. } else {
  3006. if(size == 1) {
  3007. if(currHeadingLevel <= 0) {
  3008. text = "# " + text;
  3009. } else if(currHeadingLevel == size) {
  3010. text = text.substr(currHeadingLevel + 1);
  3011. } else {
  3012. text = "# " + text.substr(currHeadingLevel + 1);
  3013. }
  3014. } else if(size == 2) {
  3015. if(currHeadingLevel <= 0) {
  3016. text = "## " + text;
  3017. } else if(currHeadingLevel == size) {
  3018. text = text.substr(currHeadingLevel + 1);
  3019. } else {
  3020. text = "## " + text.substr(currHeadingLevel + 1);
  3021. }
  3022. } else {
  3023. if(currHeadingLevel <= 0) {
  3024. text = "### " + text;
  3025. } else if(currHeadingLevel == size) {
  3026. text = text.substr(currHeadingLevel + 1);
  3027. } else {
  3028. text = "### " + text.substr(currHeadingLevel + 1);
  3029. }
  3030. }
  3031. }
  3032. cm.replaceRange(text, {
  3033. line: i,
  3034. ch: 0
  3035. }, {
  3036. line: i,
  3037. ch: 99999999999999
  3038. });
  3039. })(i);
  3040. }
  3041. cm.focus();
  3042. }
  3043. function _toggleLine(cm, name) {
  3044. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  3045. return;
  3046. var stat = getState(cm);
  3047. var startPoint = cm.getCursor("start");
  3048. var endPoint = cm.getCursor("end");
  3049. var repl = {
  3050. "quote": /^(\s*)\>\s+/,
  3051. "unordered-list": /^(\s*)(\*|\-|\+)\s+/,
  3052. "ordered-list": /^(\s*)\d+\.\s+/
  3053. };
  3054. var map = {
  3055. "quote": "> ",
  3056. "unordered-list": "* ",
  3057. "ordered-list": "1. "
  3058. };
  3059. for(var i = startPoint.line; i <= endPoint.line; i++) {
  3060. (function(i) {
  3061. var text = cm.getLine(i);
  3062. if(stat[name]) {
  3063. text = text.replace(repl[name], "$1");
  3064. } else {
  3065. text = map[name] + text;
  3066. }
  3067. cm.replaceRange(text, {
  3068. line: i,
  3069. ch: 0
  3070. }, {
  3071. line: i,
  3072. ch: 99999999999999
  3073. });
  3074. })(i);
  3075. }
  3076. cm.focus();
  3077. }
  3078. function _toggleBlock(editor, type, start_chars, end_chars) {
  3079. if(/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className))
  3080. return;
  3081. end_chars = (typeof end_chars === "undefined") ? start_chars : end_chars;
  3082. var cm = editor.codemirror;
  3083. var stat = getState(cm);
  3084. var text;
  3085. var start = start_chars;
  3086. var end = end_chars;
  3087. var startPoint = cm.getCursor("start");
  3088. var endPoint = cm.getCursor("end");
  3089. if(stat[type]) {
  3090. text = cm.getLine(startPoint.line);
  3091. start = text.slice(0, startPoint.ch);
  3092. end = text.slice(startPoint.ch);
  3093. if(type == "bold") {
  3094. start = start.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/, "");
  3095. end = end.replace(/(\*\*|__)/, "");
  3096. } else if(type == "italic") {
  3097. start = start.replace(/(\*|_)(?![\s\S]*(\*|_))/, "");
  3098. end = end.replace(/(\*|_)/, "");
  3099. } else if(type == "strikethrough") {
  3100. start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, "");
  3101. end = end.replace(/(\*\*|~~)/, "");
  3102. }
  3103. cm.replaceRange(start + end, {
  3104. line: startPoint.line,
  3105. ch: 0
  3106. }, {
  3107. line: startPoint.line,
  3108. ch: 99999999999999
  3109. });
  3110. if(type == "bold" || type == "strikethrough") {
  3111. startPoint.ch -= 2;
  3112. if(startPoint !== endPoint) {
  3113. endPoint.ch -= 2;
  3114. }
  3115. } else if(type == "italic") {
  3116. startPoint.ch -= 1;
  3117. if(startPoint !== endPoint) {
  3118. endPoint.ch -= 1;
  3119. }
  3120. }
  3121. } else {
  3122. text = cm.getSelection();
  3123. if(type == "bold") {
  3124. text = text.split("**").join("");
  3125. text = text.split("__").join("");
  3126. } else if(type == "italic") {
  3127. text = text.split("*").join("");
  3128. text = text.split("_").join("");
  3129. } else if(type == "strikethrough") {
  3130. text = text.split("~~").join("");
  3131. }
  3132. cm.replaceSelection(start + text + end);
  3133. startPoint.ch += start_chars.length;
  3134. endPoint.ch = startPoint.ch + text.length;
  3135. }
  3136. cm.setSelection(startPoint, endPoint);
  3137. cm.focus();
  3138. }
  3139. function _cleanBlock(cm) {
  3140. if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
  3141. return;
  3142. var startPoint = cm.getCursor("start");
  3143. var endPoint = cm.getCursor("end");
  3144. var text;
  3145. for(var line = startPoint.line; line <= endPoint.line; line++) {
  3146. text = cm.getLine(line);
  3147. text = text.replace(/^[ ]*([# ]+|\*|\-|[> ]+|[0-9]+(.|\)))[ ]*/, "");
  3148. cm.replaceRange(text, {
  3149. line: line,
  3150. ch: 0
  3151. }, {
  3152. line: line,
  3153. ch: 99999999999999
  3154. });
  3155. }
  3156. }
  3157. // Merge the properties of one object into another.
  3158. function _mergeProperties(target, source) {
  3159. for(var property in source) {
  3160. if(source.hasOwnProperty(property)) {
  3161. if(source[property] instanceof Array) {
  3162. target[property] = source[property].concat(target[property] instanceof Array ? target[property] : []);
  3163. } else if(
  3164. source[property] !== null &&
  3165. typeof source[property] === "object" &&
  3166. source[property].constructor === Object
  3167. ) {
  3168. target[property] = _mergeProperties(target[property] || {}, source[property]);
  3169. } else {
  3170. target[property] = source[property];
  3171. }
  3172. }
  3173. }
  3174. return target;
  3175. }
  3176. // Merge an arbitrary number of objects into one.
  3177. function extend(target) {
  3178. for(var i = 1; i < arguments.length; i++) {
  3179. target = _mergeProperties(target, arguments[i]);
  3180. }
  3181. return target;
  3182. }
  3183. /* The right word count in respect for CJK. */
  3184. function wordCount(data) {
  3185. var pattern = /[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
  3186. var m = data.match(pattern);
  3187. var count = 0;
  3188. if(m === null) return count;
  3189. for(var i = 0; i < m.length; i++) {
  3190. if(m[i].charCodeAt(0) >= 0x4E00) {
  3191. count += m[i].length;
  3192. } else {
  3193. count += 1;
  3194. }
  3195. }
  3196. return count;
  3197. }
  3198. var toolbarBuiltInButtons = {
  3199. "bold": {
  3200. name: "bold",
  3201. action: toggleBold,
  3202. className: "fa fa-bold",
  3203. title: "Bold",
  3204. default: true
  3205. },
  3206. "italic": {
  3207. name: "italic",
  3208. action: toggleItalic,
  3209. className: "fa fa-italic",
  3210. title: "Italic",
  3211. default: true
  3212. },
  3213. "strikethrough": {
  3214. name: "strikethrough",
  3215. action: toggleStrikethrough,
  3216. className: "fa fa-strikethrough",
  3217. title: "Strikethrough"
  3218. },
  3219. "heading": {
  3220. name: "heading",
  3221. action: toggleHeadingSmaller,
  3222. className: "fa fa-header",
  3223. title: "Heading",
  3224. default: true
  3225. },
  3226. "heading-smaller": {
  3227. name: "heading-smaller",
  3228. action: toggleHeadingSmaller,
  3229. className: "fa fa-header fa-header-x fa-header-smaller",
  3230. title: "Smaller Heading"
  3231. },
  3232. "heading-bigger": {
  3233. name: "heading-bigger",
  3234. action: toggleHeadingBigger,
  3235. className: "fa fa-header fa-header-x fa-header-bigger",
  3236. title: "Bigger Heading"
  3237. },
  3238. "heading-1": {
  3239. name: "heading-1",
  3240. action: toggleHeading1,
  3241. className: "fa fa-header fa-header-x fa-header-1",
  3242. title: "Big Heading"
  3243. },
  3244. "heading-2": {
  3245. name: "heading-2",
  3246. action: toggleHeading2,
  3247. className: "fa fa-header fa-header-x fa-header-2",
  3248. title: "Medium Heading"
  3249. },
  3250. "heading-3": {
  3251. name: "heading-3",
  3252. action: toggleHeading3,
  3253. className: "fa fa-header fa-header-x fa-header-3",
  3254. title: "Small Heading"
  3255. },
  3256. "separator-1": {
  3257. name: "separator-1"
  3258. },
  3259. "code": {
  3260. name: "code",
  3261. action: toggleCodeBlock,
  3262. className: "fa fa-code",
  3263. title: "Code"
  3264. },
  3265. "quote": {
  3266. name: "quote",
  3267. action: toggleBlockquote,
  3268. className: "fa fa-quote-left",
  3269. title: "Quote",
  3270. default: true
  3271. },
  3272. "unordered-list": {
  3273. name: "unordered-list",
  3274. action: toggleUnorderedList,
  3275. className: "fa fa-list-ul",
  3276. title: "Generic List",
  3277. default: true
  3278. },
  3279. "ordered-list": {
  3280. name: "ordered-list",
  3281. action: toggleOrderedList,
  3282. className: "fa fa-list-ol",
  3283. title: "Numbered List",
  3284. default: true
  3285. },
  3286. "clean-block": {
  3287. name: "clean-block",
  3288. action: cleanBlock,
  3289. className: "fa fa-eraser fa-clean-block",
  3290. title: "Clean block"
  3291. },
  3292. "separator-2": {
  3293. name: "separator-2"
  3294. },
  3295. "link": {
  3296. name: "link",
  3297. action: drawLink,
  3298. className: "fa fa-link",
  3299. title: "Create Link",
  3300. default: true
  3301. },
  3302. "image": {
  3303. name: "image",
  3304. action: drawImage,
  3305. className: "fa fa-picture-o",
  3306. title: "Insert Image",
  3307. default: true
  3308. },
  3309. "table": {
  3310. name: "table",
  3311. action: drawTable,
  3312. className: "fa fa-table",
  3313. title: "Insert Table"
  3314. },
  3315. "horizontal-rule": {
  3316. name: "horizontal-rule",
  3317. action: drawHorizontalRule,
  3318. className: "fa fa-minus",
  3319. title: "Insert Horizontal Line"
  3320. },
  3321. "separator-3": {
  3322. name: "separator-3"
  3323. },
  3324. "preview": {
  3325. name: "preview",
  3326. action: togglePreview,
  3327. className: "fa fa-eye no-disable",
  3328. title: "Toggle Preview",
  3329. default: true
  3330. },
  3331. "side-by-side": {
  3332. name: "side-by-side",
  3333. action: toggleSideBySide,
  3334. className: "fa fa-columns no-disable no-mobile",
  3335. title: "Toggle Side by Side",
  3336. default: true
  3337. },
  3338. "fullscreen": {
  3339. name: "fullscreen",
  3340. action: toggleFullScreen,
  3341. className: "fa fa-arrows-alt no-disable no-mobile",
  3342. title: "Toggle Fullscreen",
  3343. default: true
  3344. },
  3345. "separator-4": {
  3346. name: "separator-4"
  3347. },
  3348. "guide": {
  3349. name: "guide",
  3350. action: "https://simplemde.com/markdown-guide",
  3351. className: "fa fa-question-circle",
  3352. title: "Markdown Guide",
  3353. default: true
  3354. },
  3355. "separator-5": {
  3356. name: "separator-5"
  3357. },
  3358. "undo": {
  3359. name: "undo",
  3360. action: undo,
  3361. className: "fa fa-undo no-disable",
  3362. title: "Undo"
  3363. },
  3364. "redo": {
  3365. name: "redo",
  3366. action: redo,
  3367. className: "fa fa-repeat no-disable",
  3368. title: "Redo"
  3369. }
  3370. };
  3371. var insertTexts = {
  3372. link: ["[", "](#url#)"],
  3373. image: ["![](", "#url#)"],
  3374. table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
  3375. horizontalRule: ["", "\n\n-----\n\n"]
  3376. };
  3377. var promptTexts = {
  3378. link: "URL for the link:",
  3379. image: "URL of the image:"
  3380. };
  3381. var blockStyles = {
  3382. "bold": "**",
  3383. "code": "```",
  3384. "italic": "*"
  3385. };
  3386. /**
  3387. * Interface of SimpleMDE.
  3388. */
  3389. function SimpleMDE(options) {
  3390. // Handle options parameter
  3391. options = options || {};
  3392. // Used later to refer to it"s parent
  3393. options.parent = this;
  3394. // Check if Font Awesome needs to be auto downloaded
  3395. var autoDownloadFA = true;
  3396. if(options.autoDownloadFontAwesome === false) {
  3397. autoDownloadFA = false;
  3398. }
  3399. if(options.autoDownloadFontAwesome !== true) {
  3400. var styleSheets = document.styleSheets;
  3401. for(var i = 0; i < styleSheets.length; i++) {
  3402. if(!styleSheets[i].href)
  3403. continue;
  3404. if(styleSheets[i].href.indexOf("//maxcdn.bootstrapcdn.com/font-awesome/") > -1) {
  3405. autoDownloadFA = false;
  3406. }
  3407. }
  3408. }
  3409. if(autoDownloadFA) {
  3410. var link = document.createElement("link");
  3411. link.rel = "stylesheet";
  3412. link.href = "https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css";
  3413. document.getElementsByTagName("head")[0].appendChild(link);
  3414. }
  3415. // Find the textarea to use
  3416. if(options.element) {
  3417. this.element = options.element;
  3418. } else if(options.element === null) {
  3419. // This means that the element option was specified, but no element was found
  3420. console.log("SimpleMDE: Error. No element was found.");
  3421. return;
  3422. }
  3423. // Handle toolbar
  3424. if(options.toolbar === undefined) {
  3425. // Initialize
  3426. options.toolbar = [];
  3427. // Loop over the built in buttons, to get the preferred order
  3428. for(var key in toolbarBuiltInButtons) {
  3429. if(toolbarBuiltInButtons.hasOwnProperty(key)) {
  3430. if(key.indexOf("separator-") != -1) {
  3431. options.toolbar.push("|");
  3432. }
  3433. if(toolbarBuiltInButtons[key].default === true || (options.showIcons && options.showIcons.constructor === Array && options.showIcons.indexOf(key) != -1)) {
  3434. options.toolbar.push(key);
  3435. }
  3436. }
  3437. }
  3438. }
  3439. // Handle status bar
  3440. if(!options.hasOwnProperty("status")) {
  3441. options.status = ["autosave", "lines", "words", "cursor"];
  3442. }
  3443. // Add default preview rendering function
  3444. if(!options.previewRender) {
  3445. options.previewRender = function(plainText) {
  3446. // Note: "this" refers to the options object
  3447. return this.parent.markdown(plainText);
  3448. };
  3449. }
  3450. // Set default options for parsing config
  3451. options.parsingConfig = extend({
  3452. highlightFormatting: true // needed for toggleCodeBlock to detect types of code
  3453. }, options.parsingConfig || {});
  3454. // Merging the insertTexts, with the given options
  3455. options.insertTexts = extend({}, insertTexts, options.insertTexts || {});
  3456. // Merging the promptTexts, with the given options
  3457. options.promptTexts = promptTexts;
  3458. // Merging the blockStyles, with the given options
  3459. options.blockStyles = extend({}, blockStyles, options.blockStyles || {});
  3460. // Merging the shortcuts, with the given options
  3461. options.shortcuts = extend({}, shortcuts, options.shortcuts || {});
  3462. // Change unique_id to uniqueId for backwards compatibility
  3463. if(options.autosave != undefined && options.autosave.unique_id != undefined && options.autosave.unique_id != "")
  3464. options.autosave.uniqueId = options.autosave.unique_id;
  3465. // Update this options
  3466. this.options = options;
  3467. // Auto render
  3468. this.render();
  3469. // The codemirror component is only available after rendering
  3470. // so, the setter for the initialValue can only run after
  3471. // the element has been rendered
  3472. if(options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) {
  3473. this.value(options.initialValue);
  3474. }
  3475. }
  3476. /**
  3477. * Default markdown render.
  3478. */
  3479. SimpleMDE.prototype.markdown = function(text) {
  3480. if(marked) {
  3481. // Initialize
  3482. var markedOptions = {};
  3483. // Update options
  3484. if(this.options && this.options.renderingConfig && this.options.renderingConfig.singleLineBreaks === false) {
  3485. markedOptions.breaks = false;
  3486. } else {
  3487. markedOptions.breaks = true;
  3488. }
  3489. if(this.options && this.options.renderingConfig && this.options.renderingConfig.codeSyntaxHighlighting === true && window.hljs) {
  3490. markedOptions.highlight = function(code) {
  3491. return window.hljs.highlightAuto(code).value;
  3492. };
  3493. }
  3494. // Set options
  3495. marked.setOptions(markedOptions);
  3496. // Return
  3497. return marked(text);
  3498. }
  3499. };
  3500. /**
  3501. * Render editor to the given element.
  3502. */
  3503. SimpleMDE.prototype.render = function(el) {
  3504. if(!el) {
  3505. el = this.element || document.getElementsByTagName("textarea")[0];
  3506. }
  3507. if(this._rendered && this._rendered === el) {
  3508. // Already rendered.
  3509. return;
  3510. }
  3511. this.element = el;
  3512. var options = this.options;
  3513. var self = this;
  3514. var keyMaps = {};
  3515. for(var key in options.shortcuts) {
  3516. // null stands for "do not bind this command"
  3517. if(options.shortcuts[key] !== null && bindings[key] !== null) {
  3518. (function(key) {
  3519. keyMaps[fixShortcut(options.shortcuts[key])] = function() {
  3520. bindings[key](self);
  3521. };
  3522. })(key);
  3523. }
  3524. }
  3525. keyMaps["Enter"] = "newlineAndIndentContinueMarkdownList";
  3526. keyMaps["Tab"] = "tabAndIndentMarkdownList";
  3527. keyMaps["Shift-Tab"] = "shiftTabAndUnindentMarkdownList";
  3528. keyMaps["Esc"] = function(cm) {
  3529. if(cm.getOption("fullScreen")) toggleFullScreen(self);
  3530. };
  3531. document.addEventListener("keydown", function(e) {
  3532. e = e || window.event;
  3533. if(e.keyCode == 27) {
  3534. if(self.codemirror.getOption("fullScreen")) toggleFullScreen(self);
  3535. }
  3536. }, false);
  3537. var mode, backdrop;
  3538. if(options.spellChecker !== false) {
  3539. mode = "spell-checker";
  3540. backdrop = options.parsingConfig;
  3541. backdrop.name = "gfm";
  3542. backdrop.gitHubSpice = false;
  3543. CodeMirrorSpellChecker({
  3544. codeMirrorInstance: CodeMirror
  3545. });
  3546. } else {
  3547. mode = options.parsingConfig;
  3548. mode.name = "gfm";
  3549. mode.gitHubSpice = false;
  3550. }
  3551. this.codemirror = CodeMirror.fromTextArea(el, {
  3552. mode: mode,
  3553. backdrop: backdrop,
  3554. theme: "paper",
  3555. tabSize: (options.tabSize != undefined) ? options.tabSize : 2,
  3556. indentUnit: (options.tabSize != undefined) ? options.tabSize : 2,
  3557. indentWithTabs: (options.indentWithTabs === false) ? false : true,
  3558. lineNumbers: false,
  3559. autofocus: (options.autofocus === true) ? true : false,
  3560. extraKeys: keyMaps,
  3561. lineWrapping: (options.lineWrapping === false) ? false : true,
  3562. allowDropFileTypes: ["text/plain"],
  3563. placeholder: options.placeholder || el.getAttribute("placeholder") || "",
  3564. styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : true
  3565. });
  3566. if(options.forceSync === true) {
  3567. var cm = this.codemirror;
  3568. cm.on("change", function() {
  3569. cm.save();
  3570. });
  3571. }
  3572. this.gui = {};
  3573. if(options.toolbar !== false) {
  3574. this.gui.toolbar = this.createToolbar();
  3575. }
  3576. if(options.status !== false) {
  3577. this.gui.statusbar = this.createStatusbar();
  3578. }
  3579. if(options.autosave != undefined && options.autosave.enabled === true) {
  3580. this.autosave();
  3581. }
  3582. this.gui.sideBySide = this.createSideBySide();
  3583. this._rendered = this.element;
  3584. // Fixes CodeMirror bug (#344)
  3585. var temp_cm = this.codemirror;
  3586. setTimeout(function() {
  3587. temp_cm.refresh();
  3588. }.bind(temp_cm), 0);
  3589. };
  3590. // 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.
  3591. function isLocalStorageAvailable() {
  3592. if(typeof localStorage === "object") {
  3593. try {
  3594. localStorage.setItem("smde_localStorage", 1);
  3595. localStorage.removeItem("smde_localStorage");
  3596. } catch(e) {
  3597. return false;
  3598. }
  3599. } else {
  3600. return false;
  3601. }
  3602. return true;
  3603. }
  3604. SimpleMDE.prototype.autosave = function() {
  3605. if(isLocalStorageAvailable()) {
  3606. var simplemde = this;
  3607. if(this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
  3608. console.log("SimpleMDE: You must set a uniqueId to use the autosave feature");
  3609. return;
  3610. }
  3611. if(simplemde.element.form != null && simplemde.element.form != undefined) {
  3612. simplemde.element.form.addEventListener("submit", function() {
  3613. localStorage.removeItem("smde_" + simplemde.options.autosave.uniqueId);
  3614. });
  3615. }
  3616. if(this.options.autosave.loaded !== true) {
  3617. if(typeof localStorage.getItem("smde_" + this.options.autosave.uniqueId) == "string" && localStorage.getItem("smde_" + this.options.autosave.uniqueId) != "") {
  3618. this.codemirror.setValue(localStorage.getItem("smde_" + this.options.autosave.uniqueId));
  3619. this.options.autosave.foundSavedValue = true;
  3620. }
  3621. this.options.autosave.loaded = true;
  3622. }
  3623. localStorage.setItem("smde_" + this.options.autosave.uniqueId, simplemde.value());
  3624. var el = document.getElementById("autosaved");
  3625. if(el != null && el != undefined && el != "") {
  3626. var d = new Date();
  3627. var hh = d.getHours();
  3628. var m = d.getMinutes();
  3629. var dd = "am";
  3630. var h = hh;
  3631. if(h >= 12) {
  3632. h = hh - 12;
  3633. dd = "pm";
  3634. }
  3635. if(h == 0) {
  3636. h = 12;
  3637. }
  3638. m = m < 10 ? "0" + m : m;
  3639. el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd;
  3640. }
  3641. this.autosaveTimeoutId = setTimeout(function() {
  3642. simplemde.autosave();
  3643. }, this.options.autosave.delay || 10000);
  3644. } else {
  3645. console.log("SimpleMDE: localStorage not available, cannot autosave");
  3646. }
  3647. };
  3648. SimpleMDE.prototype.clearAutosavedValue = function() {
  3649. if(isLocalStorageAvailable()) {
  3650. if(this.options.autosave == undefined || this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
  3651. console.log("SimpleMDE: You must set a uniqueId to clear the autosave value");
  3652. return;
  3653. }
  3654. localStorage.removeItem("smde_" + this.options.autosave.uniqueId);
  3655. } else {
  3656. console.log("SimpleMDE: localStorage not available, cannot autosave");
  3657. }
  3658. };
  3659. SimpleMDE.prototype.createSideBySide = function() {
  3660. var cm = this.codemirror;
  3661. var wrapper = cm.getWrapperElement();
  3662. var preview = wrapper.nextSibling;
  3663. if(!preview || !/editor-preview-side/.test(preview.className)) {
  3664. preview = document.createElement("div");
  3665. preview.className = "editor-preview-side";
  3666. wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);
  3667. }
  3668. // Syncs scroll editor -> preview
  3669. var cScroll = false;
  3670. var pScroll = false;
  3671. cm.on("scroll", function(v) {
  3672. if(cScroll) {
  3673. cScroll = false;
  3674. return;
  3675. }
  3676. pScroll = true;
  3677. var height = v.getScrollInfo().height - v.getScrollInfo().clientHeight;
  3678. var ratio = parseFloat(v.getScrollInfo().top) / height;
  3679. var move = (preview.scrollHeight - preview.clientHeight) * ratio;
  3680. preview.scrollTop = move;
  3681. });
  3682. // Syncs scroll preview -> editor
  3683. preview.onscroll = function() {
  3684. if(pScroll) {
  3685. pScroll = false;
  3686. return;
  3687. }
  3688. cScroll = true;
  3689. var height = preview.scrollHeight - preview.clientHeight;
  3690. var ratio = parseFloat(preview.scrollTop) / height;
  3691. var move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
  3692. cm.scrollTo(0, move);
  3693. };
  3694. return preview;
  3695. };
  3696. SimpleMDE.prototype.createToolbar = function(items) {
  3697. items = items || this.options.toolbar;
  3698. if(!items || items.length === 0) {
  3699. return;
  3700. }
  3701. var i;
  3702. for(i = 0; i < items.length; i++) {
  3703. if(toolbarBuiltInButtons[items[i]] != undefined) {
  3704. items[i] = toolbarBuiltInButtons[items[i]];
  3705. }
  3706. }
  3707. var bar = document.createElement("div");
  3708. bar.className = "editor-toolbar";
  3709. var self = this;
  3710. var toolbarData = {};
  3711. self.toolbar = items;
  3712. for(i = 0; i < items.length; i++) {
  3713. if(items[i].name == "guide" && self.options.toolbarGuideIcon === false)
  3714. continue;
  3715. if(self.options.hideIcons && self.options.hideIcons.indexOf(items[i].name) != -1)
  3716. continue;
  3717. // Fullscreen does not work well on mobile devices (even tablets)
  3718. // In the future, hopefully this can be resolved
  3719. if((items[i].name == "fullscreen" || items[i].name == "side-by-side") && isMobile())
  3720. continue;
  3721. // Don't include trailing separators
  3722. if(items[i] === "|") {
  3723. var nonSeparatorIconsFollow = false;
  3724. for(var x = (i + 1); x < items.length; x++) {
  3725. if(items[x] !== "|" && (!self.options.hideIcons || self.options.hideIcons.indexOf(items[x].name) == -1)) {
  3726. nonSeparatorIconsFollow = true;
  3727. }
  3728. }
  3729. if(!nonSeparatorIconsFollow)
  3730. continue;
  3731. }
  3732. // Create the icon and append to the toolbar
  3733. (function(item) {
  3734. var el;
  3735. if(item === "|") {
  3736. el = createSep();
  3737. } else {
  3738. el = createIcon(item, self.options.toolbarTips, self.options.shortcuts);
  3739. }
  3740. // bind events, special for info
  3741. if(item.action) {
  3742. if(typeof item.action === "function") {
  3743. el.onclick = function(e) {
  3744. e.preventDefault();
  3745. item.action(self);
  3746. };
  3747. } else if(typeof item.action === "string") {
  3748. el.href = item.action;
  3749. el.target = "_blank";
  3750. }
  3751. }
  3752. toolbarData[item.name || item] = el;
  3753. bar.appendChild(el);
  3754. })(items[i]);
  3755. }
  3756. self.toolbarElements = toolbarData;
  3757. var cm = this.codemirror;
  3758. cm.on("cursorActivity", function() {
  3759. var stat = getState(cm);
  3760. for(var key in toolbarData) {
  3761. (function(key) {
  3762. var el = toolbarData[key];
  3763. if(stat[key]) {
  3764. el.className += " active";
  3765. } else if(key != "fullscreen" && key != "side-by-side") {
  3766. el.className = el.className.replace(/\s*active\s*/g, "");
  3767. }
  3768. })(key);
  3769. }
  3770. });
  3771. var cmWrapper = cm.getWrapperElement();
  3772. cmWrapper.parentNode.insertBefore(bar, cmWrapper);
  3773. return bar;
  3774. };
  3775. SimpleMDE.prototype.createStatusbar = function(status) {
  3776. // Initialize
  3777. status = status || this.options.status;
  3778. var options = this.options;
  3779. var cm = this.codemirror;
  3780. // Make sure the status variable is valid
  3781. if(!status || status.length === 0)
  3782. return;
  3783. // Set up the built-in items
  3784. var items = [];
  3785. var i, onUpdate, defaultValue;
  3786. for(i = 0; i < status.length; i++) {
  3787. // Reset some values
  3788. onUpdate = undefined;
  3789. defaultValue = undefined;
  3790. // Handle if custom or not
  3791. if(typeof status[i] === "object") {
  3792. items.push({
  3793. className: status[i].className,
  3794. defaultValue: status[i].defaultValue,
  3795. onUpdate: status[i].onUpdate
  3796. });
  3797. } else {
  3798. var name = status[i];
  3799. if(name === "words") {
  3800. defaultValue = function(el) {
  3801. el.innerHTML = wordCount(cm.getValue());
  3802. };
  3803. onUpdate = function(el) {
  3804. el.innerHTML = wordCount(cm.getValue());
  3805. };
  3806. } else if(name === "lines") {
  3807. defaultValue = function(el) {
  3808. el.innerHTML = cm.lineCount();
  3809. };
  3810. onUpdate = function(el) {
  3811. el.innerHTML = cm.lineCount();
  3812. };
  3813. } else if(name === "cursor") {
  3814. defaultValue = function(el) {
  3815. el.innerHTML = "0:0";
  3816. };
  3817. onUpdate = function(el) {
  3818. var pos = cm.getCursor();
  3819. el.innerHTML = pos.line + ":" + pos.ch;
  3820. };
  3821. } else if(name === "autosave") {
  3822. defaultValue = function(el) {
  3823. if(options.autosave != undefined && options.autosave.enabled === true) {
  3824. el.setAttribute("id", "autosaved");
  3825. }
  3826. };
  3827. }
  3828. items.push({
  3829. className: name,
  3830. defaultValue: defaultValue,
  3831. onUpdate: onUpdate
  3832. });
  3833. }
  3834. }
  3835. // Create element for the status bar
  3836. var bar = document.createElement("div");
  3837. bar.className = "editor-statusbar";
  3838. // Create a new span for each item
  3839. for(i = 0; i < items.length; i++) {
  3840. // Store in temporary variable
  3841. var item = items[i];
  3842. // Create span element
  3843. var el = document.createElement("span");
  3844. el.className = item.className;
  3845. // Ensure the defaultValue is a function
  3846. if(typeof item.defaultValue === "function") {
  3847. item.defaultValue(el);
  3848. }
  3849. // Ensure the onUpdate is a function
  3850. if(typeof item.onUpdate === "function") {
  3851. // Create a closure around the span of the current action, then execute the onUpdate handler
  3852. this.codemirror.on("update", (function(el, item) {
  3853. return function() {
  3854. item.onUpdate(el);
  3855. };
  3856. }(el, item)));
  3857. }
  3858. // Append the item to the status bar
  3859. bar.appendChild(el);
  3860. }
  3861. // Insert the status bar into the DOM
  3862. var cmWrapper = this.codemirror.getWrapperElement();
  3863. cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
  3864. return bar;
  3865. };
  3866. /**
  3867. * Get or set the text content.
  3868. */
  3869. SimpleMDE.prototype.value = function(val) {
  3870. if(val === undefined) {
  3871. return this.codemirror.getValue();
  3872. } else {
  3873. this.codemirror.getDoc().setValue(val);
  3874. return this;
  3875. }
  3876. };
  3877. /**
  3878. * Bind static methods for exports.
  3879. */
  3880. SimpleMDE.toggleBold = toggleBold;
  3881. SimpleMDE.toggleItalic = toggleItalic;
  3882. SimpleMDE.toggleStrikethrough = toggleStrikethrough;
  3883. SimpleMDE.toggleBlockquote = toggleBlockquote;
  3884. SimpleMDE.toggleHeadingSmaller = toggleHeadingSmaller;
  3885. SimpleMDE.toggleHeadingBigger = toggleHeadingBigger;
  3886. SimpleMDE.toggleHeading1 = toggleHeading1;
  3887. SimpleMDE.toggleHeading2 = toggleHeading2;
  3888. SimpleMDE.toggleHeading3 = toggleHeading3;
  3889. SimpleMDE.toggleCodeBlock = toggleCodeBlock;
  3890. SimpleMDE.toggleUnorderedList = toggleUnorderedList;
  3891. SimpleMDE.toggleOrderedList = toggleOrderedList;
  3892. SimpleMDE.cleanBlock = cleanBlock;
  3893. SimpleMDE.drawLink = drawLink;
  3894. SimpleMDE.drawImage = drawImage;
  3895. SimpleMDE.drawTable = drawTable;
  3896. SimpleMDE.drawHorizontalRule = drawHorizontalRule;
  3897. SimpleMDE.undo = undo;
  3898. SimpleMDE.redo = redo;
  3899. SimpleMDE.togglePreview = togglePreview;
  3900. SimpleMDE.toggleSideBySide = toggleSideBySide;
  3901. SimpleMDE.toggleFullScreen = toggleFullScreen;
  3902. /**
  3903. * Bind instance methods for exports.
  3904. */
  3905. SimpleMDE.prototype.toggleBold = function() {
  3906. toggleBold(this);
  3907. };
  3908. SimpleMDE.prototype.toggleItalic = function() {
  3909. toggleItalic(this);
  3910. };
  3911. SimpleMDE.prototype.toggleStrikethrough = function() {
  3912. toggleStrikethrough(this);
  3913. };
  3914. SimpleMDE.prototype.toggleBlockquote = function() {
  3915. toggleBlockquote(this);
  3916. };
  3917. SimpleMDE.prototype.toggleHeadingSmaller = function() {
  3918. toggleHeadingSmaller(this);
  3919. };
  3920. SimpleMDE.prototype.toggleHeadingBigger = function() {
  3921. toggleHeadingBigger(this);
  3922. };
  3923. SimpleMDE.prototype.toggleHeading1 = function() {
  3924. toggleHeading1(this);
  3925. };
  3926. SimpleMDE.prototype.toggleHeading2 = function() {
  3927. toggleHeading2(this);
  3928. };
  3929. SimpleMDE.prototype.toggleHeading3 = function() {
  3930. toggleHeading3(this);
  3931. };
  3932. SimpleMDE.prototype.toggleCodeBlock = function() {
  3933. toggleCodeBlock(this);
  3934. };
  3935. SimpleMDE.prototype.toggleUnorderedList = function() {
  3936. toggleUnorderedList(this);
  3937. };
  3938. SimpleMDE.prototype.toggleOrderedList = function() {
  3939. toggleOrderedList(this);
  3940. };
  3941. SimpleMDE.prototype.cleanBlock = function() {
  3942. cleanBlock(this);
  3943. };
  3944. SimpleMDE.prototype.drawLink = function() {
  3945. drawLink(this);
  3946. };
  3947. SimpleMDE.prototype.drawImage = function() {
  3948. drawImage(this);
  3949. };
  3950. SimpleMDE.prototype.drawTable = function() {
  3951. drawTable(this);
  3952. };
  3953. SimpleMDE.prototype.drawHorizontalRule = function() {
  3954. drawHorizontalRule(this);
  3955. };
  3956. SimpleMDE.prototype.undo = function() {
  3957. undo(this);
  3958. };
  3959. SimpleMDE.prototype.redo = function() {
  3960. redo(this);
  3961. };
  3962. SimpleMDE.prototype.togglePreview = function() {
  3963. togglePreview(this);
  3964. };
  3965. SimpleMDE.prototype.toggleSideBySide = function() {
  3966. toggleSideBySide(this);
  3967. };
  3968. SimpleMDE.prototype.toggleFullScreen = function() {
  3969. toggleFullScreen(this);
  3970. };
  3971. SimpleMDE.prototype.isPreviewActive = function() {
  3972. var cm = this.codemirror;
  3973. var wrapper = cm.getWrapperElement();
  3974. var preview = wrapper.lastChild;
  3975. return /editor-preview-active/.test(preview.className);
  3976. };
  3977. SimpleMDE.prototype.isSideBySideActive = function() {
  3978. var cm = this.codemirror;
  3979. var wrapper = cm.getWrapperElement();
  3980. var preview = wrapper.nextSibling;
  3981. return /editor-preview-active-side/.test(preview.className);
  3982. };
  3983. SimpleMDE.prototype.isFullscreenActive = function() {
  3984. var cm = this.codemirror;
  3985. return cm.getOption("fullScreen");
  3986. };
  3987. SimpleMDE.prototype.getState = function() {
  3988. var cm = this.codemirror;
  3989. return getState(cm);
  3990. };
  3991. SimpleMDE.prototype.toTextArea = function() {
  3992. var cm = this.codemirror;
  3993. var wrapper = cm.getWrapperElement();
  3994. if(wrapper.parentNode) {
  3995. if(this.gui.toolbar) {
  3996. wrapper.parentNode.removeChild(this.gui.toolbar);
  3997. }
  3998. if(this.gui.statusbar) {
  3999. wrapper.parentNode.removeChild(this.gui.statusbar);
  4000. }
  4001. if(this.gui.sideBySide) {
  4002. wrapper.parentNode.removeChild(this.gui.sideBySide);
  4003. }
  4004. }
  4005. cm.toTextArea();
  4006. if(this.autosaveTimeoutId) {
  4007. clearTimeout(this.autosaveTimeoutId);
  4008. this.autosaveTimeoutId = undefined;
  4009. this.clearAutosavedValue();
  4010. }
  4011. };
  4012. module.exports = SimpleMDE;
  4013. /***/ }),
  4014. /***/ "4fda":
  4015. /***/ (function(module, exports, __webpack_require__) {
  4016. var getBuiltIn = __webpack_require__("6d7a");
  4017. module.exports = getBuiltIn('navigator', 'userAgent') || '';
  4018. /***/ }),
  4019. /***/ "508f":
  4020. /***/ (function(module, exports, __webpack_require__) {
  4021. // extracted by mini-css-extract-plugin
  4022. /***/ }),
  4023. /***/ "5a9c":
  4024. /***/ (function(module, exports, __webpack_require__) {
  4025. const { defaults } = __webpack_require__("a8a2");
  4026. const {
  4027. rtrim,
  4028. splitCells,
  4029. escape,
  4030. findClosingBracket
  4031. } = __webpack_require__("322c");
  4032. function outputLink(cap, link, raw) {
  4033. const href = link.href;
  4034. const title = link.title ? escape(link.title) : null;
  4035. if (cap[0].charAt(0) !== '!') {
  4036. return {
  4037. type: 'link',
  4038. raw,
  4039. href,
  4040. title,
  4041. text: cap[1]
  4042. };
  4043. } else {
  4044. return {
  4045. type: 'image',
  4046. raw,
  4047. text: escape(cap[1]),
  4048. href,
  4049. title
  4050. };
  4051. }
  4052. }
  4053. /**
  4054. * Tokenizer
  4055. */
  4056. module.exports = class Tokenizer {
  4057. constructor(options) {
  4058. this.options = options || defaults;
  4059. }
  4060. space(src) {
  4061. const cap = this.rules.block.newline.exec(src);
  4062. if (cap) {
  4063. if (cap[0].length > 1) {
  4064. return {
  4065. type: 'space',
  4066. raw: cap[0]
  4067. };
  4068. }
  4069. return { raw: '\n' };
  4070. }
  4071. }
  4072. code(src, tokens) {
  4073. const cap = this.rules.block.code.exec(src);
  4074. if (cap) {
  4075. const lastToken = tokens[tokens.length - 1];
  4076. // An indented code block cannot interrupt a paragraph.
  4077. if (lastToken && lastToken.type === 'paragraph') {
  4078. tokens.pop();
  4079. lastToken.text += '\n' + cap[0].trimRight();
  4080. lastToken.raw += '\n' + cap[0];
  4081. return lastToken;
  4082. } else {
  4083. const text = cap[0].replace(/^ {4}/gm, '');
  4084. return {
  4085. type: 'code',
  4086. raw: cap[0],
  4087. codeBlockStyle: 'indented',
  4088. text: !this.options.pedantic
  4089. ? rtrim(text, '\n')
  4090. : text
  4091. };
  4092. }
  4093. }
  4094. }
  4095. fences(src) {
  4096. const cap = this.rules.block.fences.exec(src);
  4097. if (cap) {
  4098. return {
  4099. type: 'code',
  4100. raw: cap[0],
  4101. lang: cap[2] ? cap[2].trim() : cap[2],
  4102. text: cap[3] || ''
  4103. };
  4104. }
  4105. }
  4106. heading(src) {
  4107. const cap = this.rules.block.heading.exec(src);
  4108. if (cap) {
  4109. return {
  4110. type: 'heading',
  4111. raw: cap[0],
  4112. depth: cap[1].length,
  4113. text: cap[2]
  4114. };
  4115. }
  4116. }
  4117. nptable(src) {
  4118. const cap = this.rules.block.nptable.exec(src);
  4119. if (cap) {
  4120. const item = {
  4121. type: 'table',
  4122. header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
  4123. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  4124. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
  4125. raw: cap[0]
  4126. };
  4127. if (item.header.length === item.align.length) {
  4128. let l = item.align.length;
  4129. let i;
  4130. for (i = 0; i < l; i++) {
  4131. if (/^ *-+: *$/.test(item.align[i])) {
  4132. item.align[i] = 'right';
  4133. } else if (/^ *:-+: *$/.test(item.align[i])) {
  4134. item.align[i] = 'center';
  4135. } else if (/^ *:-+ *$/.test(item.align[i])) {
  4136. item.align[i] = 'left';
  4137. } else {
  4138. item.align[i] = null;
  4139. }
  4140. }
  4141. l = item.cells.length;
  4142. for (i = 0; i < l; i++) {
  4143. item.cells[i] = splitCells(item.cells[i], item.header.length);
  4144. }
  4145. return item;
  4146. }
  4147. }
  4148. }
  4149. hr(src) {
  4150. const cap = this.rules.block.hr.exec(src);
  4151. if (cap) {
  4152. return {
  4153. type: 'hr',
  4154. raw: cap[0]
  4155. };
  4156. }
  4157. }
  4158. blockquote(src) {
  4159. const cap = this.rules.block.blockquote.exec(src);
  4160. if (cap) {
  4161. const text = cap[0].replace(/^ *> ?/gm, '');
  4162. return {
  4163. type: 'blockquote',
  4164. raw: cap[0],
  4165. text
  4166. };
  4167. }
  4168. }
  4169. list(src) {
  4170. const cap = this.rules.block.list.exec(src);
  4171. if (cap) {
  4172. let raw = cap[0];
  4173. const bull = cap[2];
  4174. const isordered = bull.length > 1;
  4175. const list = {
  4176. type: 'list',
  4177. raw,
  4178. ordered: isordered,
  4179. start: isordered ? +bull : '',
  4180. loose: false,
  4181. items: []
  4182. };
  4183. // Get each top-level item.
  4184. const itemMatch = cap[0].match(this.rules.block.item);
  4185. let next = false,
  4186. item,
  4187. space,
  4188. b,
  4189. addBack,
  4190. loose,
  4191. istask,
  4192. ischecked;
  4193. const l = itemMatch.length;
  4194. for (let i = 0; i < l; i++) {
  4195. item = itemMatch[i];
  4196. raw = item;
  4197. // Remove the list item's bullet
  4198. // so it is seen as the next token.
  4199. space = item.length;
  4200. item = item.replace(/^ *([*+-]|\d+\.) */, '');
  4201. // Outdent whatever the
  4202. // list item contains. Hacky.
  4203. if (~item.indexOf('\n ')) {
  4204. space -= item.length;
  4205. item = !this.options.pedantic
  4206. ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
  4207. : item.replace(/^ {1,4}/gm, '');
  4208. }
  4209. // Determine whether the next list item belongs here.
  4210. // Backpedal if it does not belong in this list.
  4211. if (i !== l - 1) {
  4212. b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
  4213. if (bull.length > 1 ? b.length === 1
  4214. : (b.length > 1 || (this.options.smartLists && b !== bull))) {
  4215. addBack = itemMatch.slice(i + 1).join('\n');
  4216. list.raw = list.raw.substring(0, list.raw.length - addBack.length);
  4217. i = l - 1;
  4218. }
  4219. }
  4220. // Determine whether item is loose or not.
  4221. // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
  4222. // for discount behavior.
  4223. loose = next || /\n\n(?!\s*$)/.test(item);
  4224. if (i !== l - 1) {
  4225. next = item.charAt(item.length - 1) === '\n';
  4226. if (!loose) loose = next;
  4227. }
  4228. if (loose) {
  4229. list.loose = true;
  4230. }
  4231. // Check for task list items
  4232. istask = /^\[[ xX]\] /.test(item);
  4233. ischecked = undefined;
  4234. if (istask) {
  4235. ischecked = item[1] !== ' ';
  4236. item = item.replace(/^\[[ xX]\] +/, '');
  4237. }
  4238. list.items.push({
  4239. raw,
  4240. task: istask,
  4241. checked: ischecked,
  4242. loose: loose,
  4243. text: item
  4244. });
  4245. }
  4246. return list;
  4247. }
  4248. }
  4249. html(src) {
  4250. const cap = this.rules.block.html.exec(src);
  4251. if (cap) {
  4252. return {
  4253. type: this.options.sanitize
  4254. ? 'paragraph'
  4255. : 'html',
  4256. raw: cap[0],
  4257. pre: !this.options.sanitizer
  4258. && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
  4259. text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0]
  4260. };
  4261. }
  4262. }
  4263. def(src) {
  4264. const cap = this.rules.block.def.exec(src);
  4265. if (cap) {
  4266. if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
  4267. const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
  4268. return {
  4269. tag,
  4270. raw: cap[0],
  4271. href: cap[2],
  4272. title: cap[3]
  4273. };
  4274. }
  4275. }
  4276. table(src) {
  4277. const cap = this.rules.block.table.exec(src);
  4278. if (cap) {
  4279. const item = {
  4280. type: 'table',
  4281. header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
  4282. align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
  4283. cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
  4284. };
  4285. if (item.header.length === item.align.length) {
  4286. item.raw = cap[0];
  4287. let l = item.align.length;
  4288. let i;
  4289. for (i = 0; i < l; i++) {
  4290. if (/^ *-+: *$/.test(item.align[i])) {
  4291. item.align[i] = 'right';
  4292. } else if (/^ *:-+: *$/.test(item.align[i])) {
  4293. item.align[i] = 'center';
  4294. } else if (/^ *:-+ *$/.test(item.align[i])) {
  4295. item.align[i] = 'left';
  4296. } else {
  4297. item.align[i] = null;
  4298. }
  4299. }
  4300. l = item.cells.length;
  4301. for (i = 0; i < l; i++) {
  4302. item.cells[i] = splitCells(
  4303. item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
  4304. item.header.length);
  4305. }
  4306. return item;
  4307. }
  4308. }
  4309. }
  4310. lheading(src) {
  4311. const cap = this.rules.block.lheading.exec(src);
  4312. if (cap) {
  4313. return {
  4314. type: 'heading',
  4315. raw: cap[0],
  4316. depth: cap[2].charAt(0) === '=' ? 1 : 2,
  4317. text: cap[1]
  4318. };
  4319. }
  4320. }
  4321. paragraph(src) {
  4322. const cap = this.rules.block.paragraph.exec(src);
  4323. if (cap) {
  4324. return {
  4325. type: 'paragraph',
  4326. raw: cap[0],
  4327. text: cap[1].charAt(cap[1].length - 1) === '\n'
  4328. ? cap[1].slice(0, -1)
  4329. : cap[1]
  4330. };
  4331. }
  4332. }
  4333. text(src) {
  4334. const cap = this.rules.block.text.exec(src);
  4335. if (cap) {
  4336. return {
  4337. type: 'text',
  4338. raw: cap[0],
  4339. text: cap[0]
  4340. };
  4341. }
  4342. }
  4343. escape(src) {
  4344. const cap = this.rules.inline.escape.exec(src);
  4345. if (cap) {
  4346. return {
  4347. type: 'escape',
  4348. raw: cap[0],
  4349. text: escape(cap[1])
  4350. };
  4351. }
  4352. }
  4353. tag(src, inLink, inRawBlock) {
  4354. const cap = this.rules.inline.tag.exec(src);
  4355. if (cap) {
  4356. if (!inLink && /^<a /i.test(cap[0])) {
  4357. inLink = true;
  4358. } else if (inLink && /^<\/a>/i.test(cap[0])) {
  4359. inLink = false;
  4360. }
  4361. if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  4362. inRawBlock = true;
  4363. } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
  4364. inRawBlock = false;
  4365. }
  4366. return {
  4367. type: this.options.sanitize
  4368. ? 'text'
  4369. : 'html',
  4370. raw: cap[0],
  4371. inLink,
  4372. inRawBlock,
  4373. text: this.options.sanitize
  4374. ? (this.options.sanitizer
  4375. ? this.options.sanitizer(cap[0])
  4376. : escape(cap[0]))
  4377. : cap[0]
  4378. };
  4379. }
  4380. }
  4381. link(src) {
  4382. const cap = this.rules.inline.link.exec(src);
  4383. if (cap) {
  4384. const lastParenIndex = findClosingBracket(cap[2], '()');
  4385. if (lastParenIndex > -1) {
  4386. const start = cap[0].indexOf('!') === 0 ? 5 : 4;
  4387. const linkLen = start + cap[1].length + lastParenIndex;
  4388. cap[2] = cap[2].substring(0, lastParenIndex);
  4389. cap[0] = cap[0].substring(0, linkLen).trim();
  4390. cap[3] = '';
  4391. }
  4392. let href = cap[2];
  4393. let title = '';
  4394. if (this.options.pedantic) {
  4395. const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
  4396. if (link) {
  4397. href = link[1];
  4398. title = link[3];
  4399. } else {
  4400. title = '';
  4401. }
  4402. } else {
  4403. title = cap[3] ? cap[3].slice(1, -1) : '';
  4404. }
  4405. href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
  4406. const token = outputLink(cap, {
  4407. href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
  4408. title: title ? title.replace(this.rules.inline._escapes, '$1') : title
  4409. }, cap[0]);
  4410. return token;
  4411. }
  4412. }
  4413. reflink(src, links) {
  4414. let cap;
  4415. if ((cap = this.rules.inline.reflink.exec(src))
  4416. || (cap = this.rules.inline.nolink.exec(src))) {
  4417. let link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
  4418. link = links[link.toLowerCase()];
  4419. if (!link || !link.href) {
  4420. const text = cap[0].charAt(0);
  4421. return {
  4422. type: 'text',
  4423. raw: text,
  4424. text
  4425. };
  4426. }
  4427. const token = outputLink(cap, link, cap[0]);
  4428. return token;
  4429. }
  4430. }
  4431. strong(src) {
  4432. const cap = this.rules.inline.strong.exec(src);
  4433. if (cap) {
  4434. return {
  4435. type: 'strong',
  4436. raw: cap[0],
  4437. text: cap[4] || cap[3] || cap[2] || cap[1]
  4438. };
  4439. }
  4440. }
  4441. em(src) {
  4442. const cap = this.rules.inline.em.exec(src);
  4443. if (cap) {
  4444. return {
  4445. type: 'em',
  4446. raw: cap[0],
  4447. text: cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]
  4448. };
  4449. }
  4450. }
  4451. codespan(src) {
  4452. const cap = this.rules.inline.code.exec(src);
  4453. if (cap) {
  4454. return {
  4455. type: 'codespan',
  4456. raw: cap[0],
  4457. text: escape(cap[2].trim(), true)
  4458. };
  4459. }
  4460. }
  4461. br(src) {
  4462. const cap = this.rules.inline.br.exec(src);
  4463. if (cap) {
  4464. return {
  4465. type: 'br',
  4466. raw: cap[0]
  4467. };
  4468. }
  4469. }
  4470. del(src) {
  4471. const cap = this.rules.inline.del.exec(src);
  4472. if (cap) {
  4473. return {
  4474. type: 'del',
  4475. raw: cap[0],
  4476. text: cap[1]
  4477. };
  4478. }
  4479. }
  4480. autolink(src, mangle) {
  4481. const cap = this.rules.inline.autolink.exec(src);
  4482. if (cap) {
  4483. let text, href;
  4484. if (cap[2] === '@') {
  4485. text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
  4486. href = 'mailto:' + text;
  4487. } else {
  4488. text = escape(cap[1]);
  4489. href = text;
  4490. }
  4491. return {
  4492. type: 'link',
  4493. raw: cap[0],
  4494. text,
  4495. href,
  4496. tokens: [
  4497. {
  4498. type: 'text',
  4499. raw: text,
  4500. text
  4501. }
  4502. ]
  4503. };
  4504. }
  4505. }
  4506. url(src, mangle) {
  4507. let cap;
  4508. if (cap = this.rules.inline.url.exec(src)) {
  4509. let text, href;
  4510. if (cap[2] === '@') {
  4511. text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
  4512. href = 'mailto:' + text;
  4513. } else {
  4514. // do extended autolink path validation
  4515. let prevCapZero;
  4516. do {
  4517. prevCapZero = cap[0];
  4518. cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
  4519. } while (prevCapZero !== cap[0]);
  4520. text = escape(cap[0]);
  4521. if (cap[1] === 'www.') {
  4522. href = 'http://' + text;
  4523. } else {
  4524. href = text;
  4525. }
  4526. }
  4527. return {
  4528. type: 'link',
  4529. raw: cap[0],
  4530. text,
  4531. href,
  4532. tokens: [
  4533. {
  4534. type: 'text',
  4535. raw: text,
  4536. text
  4537. }
  4538. ]
  4539. };
  4540. }
  4541. }
  4542. inlineText(src, inRawBlock, smartypants) {
  4543. const cap = this.rules.inline.text.exec(src);
  4544. if (cap) {
  4545. let text;
  4546. if (inRawBlock) {
  4547. text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0];
  4548. } else {
  4549. text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
  4550. }
  4551. return {
  4552. type: 'text',
  4553. raw: cap[0],
  4554. text
  4555. };
  4556. }
  4557. }
  4558. };
  4559. /***/ }),
  4560. /***/ "5dfd":
  4561. /***/ (function(module, exports, __webpack_require__) {
  4562. var bind = __webpack_require__("e349");
  4563. var IndexedObject = __webpack_require__("692f");
  4564. var toObject = __webpack_require__("3553");
  4565. var toLength = __webpack_require__("d88d");
  4566. var arraySpeciesCreate = __webpack_require__("1ca1");
  4567. var push = [].push;
  4568. // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
  4569. var createMethod = function (TYPE) {
  4570. var IS_MAP = TYPE == 1;
  4571. var IS_FILTER = TYPE == 2;
  4572. var IS_SOME = TYPE == 3;
  4573. var IS_EVERY = TYPE == 4;
  4574. var IS_FIND_INDEX = TYPE == 6;
  4575. var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
  4576. return function ($this, callbackfn, that, specificCreate) {
  4577. var O = toObject($this);
  4578. var self = IndexedObject(O);
  4579. var boundFunction = bind(callbackfn, that, 3);
  4580. var length = toLength(self.length);
  4581. var index = 0;
  4582. var create = specificCreate || arraySpeciesCreate;
  4583. var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
  4584. var value, result;
  4585. for (;length > index; index++) if (NO_HOLES || index in self) {
  4586. value = self[index];
  4587. result = boundFunction(value, index, O);
  4588. if (TYPE) {
  4589. if (IS_MAP) target[index] = result; // map
  4590. else if (result) switch (TYPE) {
  4591. case 3: return true; // some
  4592. case 5: return value; // find
  4593. case 6: return index; // findIndex
  4594. case 2: push.call(target, value); // filter
  4595. } else if (IS_EVERY) return false; // every
  4596. }
  4597. }
  4598. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
  4599. };
  4600. };
  4601. module.exports = {
  4602. // `Array.prototype.forEach` method
  4603. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  4604. forEach: createMethod(0),
  4605. // `Array.prototype.map` method
  4606. // https://tc39.github.io/ecma262/#sec-array.prototype.map
  4607. map: createMethod(1),
  4608. // `Array.prototype.filter` method
  4609. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  4610. filter: createMethod(2),
  4611. // `Array.prototype.some` method
  4612. // https://tc39.github.io/ecma262/#sec-array.prototype.some
  4613. some: createMethod(3),
  4614. // `Array.prototype.every` method
  4615. // https://tc39.github.io/ecma262/#sec-array.prototype.every
  4616. every: createMethod(4),
  4617. // `Array.prototype.find` method
  4618. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  4619. find: createMethod(5),
  4620. // `Array.prototype.findIndex` method
  4621. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  4622. findIndex: createMethod(6)
  4623. };
  4624. /***/ }),
  4625. /***/ "604f":
  4626. /***/ (function(module, exports, __webpack_require__) {
  4627. var global = __webpack_require__("d890");
  4628. var inspectSource = __webpack_require__("1025");
  4629. var WeakMap = global.WeakMap;
  4630. module.exports = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
  4631. /***/ }),
  4632. /***/ "692f":
  4633. /***/ (function(module, exports, __webpack_require__) {
  4634. var fails = __webpack_require__("efe2");
  4635. var classof = __webpack_require__("2118");
  4636. var split = ''.split;
  4637. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  4638. module.exports = fails(function () {
  4639. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  4640. // eslint-disable-next-line no-prototype-builtins
  4641. return !Object('z').propertyIsEnumerable(0);
  4642. }) ? function (it) {
  4643. return classof(it) == 'String' ? split.call(it, '') : Object(it);
  4644. } : Object;
  4645. /***/ }),
  4646. /***/ "6c31":
  4647. /***/ (function(module, exports, __webpack_require__) {
  4648. const Tokenizer = __webpack_require__("5a9c");
  4649. const { defaults } = __webpack_require__("a8a2");
  4650. const { block, inline } = __webpack_require__("ac30");
  4651. /**
  4652. * smartypants text replacement
  4653. */
  4654. function smartypants(text) {
  4655. return text
  4656. // em-dashes
  4657. .replace(/---/g, '\u2014')
  4658. // en-dashes
  4659. .replace(/--/g, '\u2013')
  4660. // opening singles
  4661. .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
  4662. // closing singles & apostrophes
  4663. .replace(/'/g, '\u2019')
  4664. // opening doubles
  4665. .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
  4666. // closing doubles
  4667. .replace(/"/g, '\u201d')
  4668. // ellipses
  4669. .replace(/\.{3}/g, '\u2026');
  4670. }
  4671. /**
  4672. * mangle email addresses
  4673. */
  4674. function mangle(text) {
  4675. let out = '',
  4676. i,
  4677. ch;
  4678. const l = text.length;
  4679. for (i = 0; i < l; i++) {
  4680. ch = text.charCodeAt(i);
  4681. if (Math.random() > 0.5) {
  4682. ch = 'x' + ch.toString(16);
  4683. }
  4684. out += '&#' + ch + ';';
  4685. }
  4686. return out;
  4687. }
  4688. /**
  4689. * Block Lexer
  4690. */
  4691. module.exports = class Lexer {
  4692. constructor(options) {
  4693. this.tokens = [];
  4694. this.tokens.links = Object.create(null);
  4695. this.options = options || defaults;
  4696. this.options.tokenizer = this.options.tokenizer || new Tokenizer();
  4697. this.tokenizer = this.options.tokenizer;
  4698. this.tokenizer.options = this.options;
  4699. const rules = {
  4700. block: block.normal,
  4701. inline: inline.normal
  4702. };
  4703. if (this.options.pedantic) {
  4704. rules.block = block.pedantic;
  4705. rules.inline = inline.pedantic;
  4706. } else if (this.options.gfm) {
  4707. rules.block = block.gfm;
  4708. if (this.options.breaks) {
  4709. rules.inline = inline.breaks;
  4710. } else {
  4711. rules.inline = inline.gfm;
  4712. }
  4713. }
  4714. this.tokenizer.rules = rules;
  4715. }
  4716. /**
  4717. * Expose Rules
  4718. */
  4719. static get rules() {
  4720. return {
  4721. block,
  4722. inline
  4723. };
  4724. }
  4725. /**
  4726. * Static Lex Method
  4727. */
  4728. static lex(src, options) {
  4729. const lexer = new Lexer(options);
  4730. return lexer.lex(src);
  4731. }
  4732. /**
  4733. * Preprocessing
  4734. */
  4735. lex(src) {
  4736. src = src
  4737. .replace(/\r\n|\r/g, '\n')
  4738. .replace(/\t/g, ' ');
  4739. this.blockTokens(src, this.tokens, true);
  4740. this.inline(this.tokens);
  4741. return this.tokens;
  4742. }
  4743. /**
  4744. * Lexing
  4745. */
  4746. blockTokens(src, tokens = [], top = true) {
  4747. src = src.replace(/^ +$/gm, '');
  4748. let token, i, l;
  4749. while (src) {
  4750. // newline
  4751. if (token = this.tokenizer.space(src)) {
  4752. src = src.substring(token.raw.length);
  4753. if (token.type) {
  4754. tokens.push(token);
  4755. }
  4756. continue;
  4757. }
  4758. // code
  4759. if (token = this.tokenizer.code(src, tokens)) {
  4760. src = src.substring(token.raw.length);
  4761. tokens.push(token);
  4762. continue;
  4763. }
  4764. // fences
  4765. if (token = this.tokenizer.fences(src)) {
  4766. src = src.substring(token.raw.length);
  4767. tokens.push(token);
  4768. continue;
  4769. }
  4770. // heading
  4771. if (token = this.tokenizer.heading(src)) {
  4772. src = src.substring(token.raw.length);
  4773. tokens.push(token);
  4774. continue;
  4775. }
  4776. // table no leading pipe (gfm)
  4777. if (token = this.tokenizer.nptable(src)) {
  4778. src = src.substring(token.raw.length);
  4779. tokens.push(token);
  4780. continue;
  4781. }
  4782. // hr
  4783. if (token = this.tokenizer.hr(src)) {
  4784. src = src.substring(token.raw.length);
  4785. tokens.push(token);
  4786. continue;
  4787. }
  4788. // blockquote
  4789. if (token = this.tokenizer.blockquote(src)) {
  4790. src = src.substring(token.raw.length);
  4791. token.tokens = this.blockTokens(token.text, [], top);
  4792. tokens.push(token);
  4793. continue;
  4794. }
  4795. // list
  4796. if (token = this.tokenizer.list(src)) {
  4797. src = src.substring(token.raw.length);
  4798. l = token.items.length;
  4799. for (i = 0; i < l; i++) {
  4800. token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
  4801. }
  4802. tokens.push(token);
  4803. continue;
  4804. }
  4805. // html
  4806. if (token = this.tokenizer.html(src)) {
  4807. src = src.substring(token.raw.length);
  4808. tokens.push(token);
  4809. continue;
  4810. }
  4811. // def
  4812. if (top && (token = this.tokenizer.def(src))) {
  4813. src = src.substring(token.raw.length);
  4814. if (!this.tokens.links[token.tag]) {
  4815. this.tokens.links[token.tag] = {
  4816. href: token.href,
  4817. title: token.title
  4818. };
  4819. }
  4820. continue;
  4821. }
  4822. // table (gfm)
  4823. if (token = this.tokenizer.table(src)) {
  4824. src = src.substring(token.raw.length);
  4825. tokens.push(token);
  4826. continue;
  4827. }
  4828. // lheading
  4829. if (token = this.tokenizer.lheading(src)) {
  4830. src = src.substring(token.raw.length);
  4831. tokens.push(token);
  4832. continue;
  4833. }
  4834. // top-level paragraph
  4835. if (top && (token = this.tokenizer.paragraph(src))) {
  4836. src = src.substring(token.raw.length);
  4837. tokens.push(token);
  4838. continue;
  4839. }
  4840. // text
  4841. if (token = this.tokenizer.text(src)) {
  4842. src = src.substring(token.raw.length);
  4843. tokens.push(token);
  4844. continue;
  4845. }
  4846. if (src) {
  4847. const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
  4848. if (this.options.silent) {
  4849. console.error(errMsg);
  4850. break;
  4851. } else {
  4852. throw new Error(errMsg);
  4853. }
  4854. }
  4855. }
  4856. return tokens;
  4857. }
  4858. inline(tokens) {
  4859. let i,
  4860. j,
  4861. k,
  4862. l2,
  4863. row,
  4864. token;
  4865. const l = tokens.length;
  4866. for (i = 0; i < l; i++) {
  4867. token = tokens[i];
  4868. switch (token.type) {
  4869. case 'paragraph':
  4870. case 'text':
  4871. case 'heading': {
  4872. token.tokens = [];
  4873. this.inlineTokens(token.text, token.tokens);
  4874. break;
  4875. }
  4876. case 'table': {
  4877. token.tokens = {
  4878. header: [],
  4879. cells: []
  4880. };
  4881. // header
  4882. l2 = token.header.length;
  4883. for (j = 0; j < l2; j++) {
  4884. token.tokens.header[j] = [];
  4885. this.inlineTokens(token.header[j], token.tokens.header[j]);
  4886. }
  4887. // cells
  4888. l2 = token.cells.length;
  4889. for (j = 0; j < l2; j++) {
  4890. row = token.cells[j];
  4891. token.tokens.cells[j] = [];
  4892. for (k = 0; k < row.length; k++) {
  4893. token.tokens.cells[j][k] = [];
  4894. this.inlineTokens(row[k], token.tokens.cells[j][k]);
  4895. }
  4896. }
  4897. break;
  4898. }
  4899. case 'blockquote': {
  4900. this.inline(token.tokens);
  4901. break;
  4902. }
  4903. case 'list': {
  4904. l2 = token.items.length;
  4905. for (j = 0; j < l2; j++) {
  4906. this.inline(token.items[j].tokens);
  4907. }
  4908. break;
  4909. }
  4910. default: {
  4911. // do nothing
  4912. }
  4913. }
  4914. }
  4915. return tokens;
  4916. }
  4917. /**
  4918. * Lexing/Compiling
  4919. */
  4920. inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) {
  4921. let token;
  4922. while (src) {
  4923. // escape
  4924. if (token = this.tokenizer.escape(src)) {
  4925. src = src.substring(token.raw.length);
  4926. tokens.push(token);
  4927. continue;
  4928. }
  4929. // tag
  4930. if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
  4931. src = src.substring(token.raw.length);
  4932. inLink = token.inLink;
  4933. inRawBlock = token.inRawBlock;
  4934. tokens.push(token);
  4935. continue;
  4936. }
  4937. // link
  4938. if (token = this.tokenizer.link(src)) {
  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. // reflink, nolink
  4947. if (token = this.tokenizer.reflink(src, this.tokens.links)) {
  4948. src = src.substring(token.raw.length);
  4949. if (token.type === 'link') {
  4950. token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
  4951. }
  4952. tokens.push(token);
  4953. continue;
  4954. }
  4955. // strong
  4956. if (token = this.tokenizer.strong(src)) {
  4957. src = src.substring(token.raw.length);
  4958. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  4959. tokens.push(token);
  4960. continue;
  4961. }
  4962. // em
  4963. if (token = this.tokenizer.em(src)) {
  4964. src = src.substring(token.raw.length);
  4965. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  4966. tokens.push(token);
  4967. continue;
  4968. }
  4969. // code
  4970. if (token = this.tokenizer.codespan(src)) {
  4971. src = src.substring(token.raw.length);
  4972. tokens.push(token);
  4973. continue;
  4974. }
  4975. // br
  4976. if (token = this.tokenizer.br(src)) {
  4977. src = src.substring(token.raw.length);
  4978. tokens.push(token);
  4979. continue;
  4980. }
  4981. // del (gfm)
  4982. if (token = this.tokenizer.del(src)) {
  4983. src = src.substring(token.raw.length);
  4984. token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
  4985. tokens.push(token);
  4986. continue;
  4987. }
  4988. // autolink
  4989. if (token = this.tokenizer.autolink(src, mangle)) {
  4990. src = src.substring(token.raw.length);
  4991. tokens.push(token);
  4992. continue;
  4993. }
  4994. // url (gfm)
  4995. if (!inLink && (token = this.tokenizer.url(src, mangle))) {
  4996. src = src.substring(token.raw.length);
  4997. tokens.push(token);
  4998. continue;
  4999. }
  5000. // text
  5001. if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
  5002. src = src.substring(token.raw.length);
  5003. tokens.push(token);
  5004. continue;
  5005. }
  5006. if (src) {
  5007. const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
  5008. if (this.options.silent) {
  5009. console.error(errMsg);
  5010. break;
  5011. } else {
  5012. throw new Error(errMsg);
  5013. }
  5014. }
  5015. }
  5016. return tokens;
  5017. }
  5018. };
  5019. /***/ }),
  5020. /***/ "6d28":
  5021. /***/ (function(module, exports, __webpack_require__) {
  5022. var IS_PURE = __webpack_require__("9b9d");
  5023. var store = __webpack_require__("3a08");
  5024. (module.exports = function (key, value) {
  5025. return store[key] || (store[key] = value !== undefined ? value : {});
  5026. })('versions', []).push({
  5027. version: '3.6.5',
  5028. mode: IS_PURE ? 'pure' : 'global',
  5029. copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
  5030. });
  5031. /***/ }),
  5032. /***/ "6d51":
  5033. /***/ (function(module, exports, __webpack_require__) {
  5034. var path = __webpack_require__("1b99");
  5035. var has = __webpack_require__("faa8");
  5036. var wrappedWellKnownSymbolModule = __webpack_require__("4350");
  5037. var defineProperty = __webpack_require__("d910").f;
  5038. module.exports = function (NAME) {
  5039. var Symbol = path.Symbol || (path.Symbol = {});
  5040. if (!has(Symbol, NAME)) defineProperty(Symbol, NAME, {
  5041. value: wrappedWellKnownSymbolModule.f(NAME)
  5042. });
  5043. };
  5044. /***/ }),
  5045. /***/ "6d60":
  5046. /***/ (function(module, exports, __webpack_require__) {
  5047. var anObject = __webpack_require__("857c");
  5048. var defineProperties = __webpack_require__("dbe8");
  5049. var enumBugKeys = __webpack_require__("18f6");
  5050. var hiddenKeys = __webpack_require__("d5a8");
  5051. var html = __webpack_require__("6fdf");
  5052. var documentCreateElement = __webpack_require__("ae25");
  5053. var sharedKey = __webpack_require__("7db2");
  5054. var GT = '>';
  5055. var LT = '<';
  5056. var PROTOTYPE = 'prototype';
  5057. var SCRIPT = 'script';
  5058. var IE_PROTO = sharedKey('IE_PROTO');
  5059. var EmptyConstructor = function () { /* empty */ };
  5060. var scriptTag = function (content) {
  5061. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  5062. };
  5063. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  5064. var NullProtoObjectViaActiveX = function (activeXDocument) {
  5065. activeXDocument.write(scriptTag(''));
  5066. activeXDocument.close();
  5067. var temp = activeXDocument.parentWindow.Object;
  5068. activeXDocument = null; // avoid memory leak
  5069. return temp;
  5070. };
  5071. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  5072. var NullProtoObjectViaIFrame = function () {
  5073. // Thrash, waste and sodomy: IE GC bug
  5074. var iframe = documentCreateElement('iframe');
  5075. var JS = 'java' + SCRIPT + ':';
  5076. var iframeDocument;
  5077. iframe.style.display = 'none';
  5078. html.appendChild(iframe);
  5079. // https://github.com/zloirock/core-js/issues/475
  5080. iframe.src = String(JS);
  5081. iframeDocument = iframe.contentWindow.document;
  5082. iframeDocument.open();
  5083. iframeDocument.write(scriptTag('document.F=Object'));
  5084. iframeDocument.close();
  5085. return iframeDocument.F;
  5086. };
  5087. // Check for document.domain and active x support
  5088. // No need to use active x approach when document.domain is not set
  5089. // see https://github.com/es-shims/es5-shim/issues/150
  5090. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  5091. // avoid IE GC bug
  5092. var activeXDocument;
  5093. var NullProtoObject = function () {
  5094. try {
  5095. /* global ActiveXObject */
  5096. activeXDocument = document.domain && new ActiveXObject('htmlfile');
  5097. } catch (error) { /* ignore */ }
  5098. NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
  5099. var length = enumBugKeys.length;
  5100. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  5101. return NullProtoObject();
  5102. };
  5103. hiddenKeys[IE_PROTO] = true;
  5104. // `Object.create` method
  5105. // https://tc39.github.io/ecma262/#sec-object.create
  5106. module.exports = Object.create || function create(O, Properties) {
  5107. var result;
  5108. if (O !== null) {
  5109. EmptyConstructor[PROTOTYPE] = anObject(O);
  5110. result = new EmptyConstructor();
  5111. EmptyConstructor[PROTOTYPE] = null;
  5112. // add "__proto__" for Object.getPrototypeOf polyfill
  5113. result[IE_PROTO] = O;
  5114. } else result = NullProtoObject();
  5115. return Properties === undefined ? result : defineProperties(result, Properties);
  5116. };
  5117. /***/ }),
  5118. /***/ "6d7a":
  5119. /***/ (function(module, exports, __webpack_require__) {
  5120. var path = __webpack_require__("1b99");
  5121. var global = __webpack_require__("d890");
  5122. var aFunction = function (variable) {
  5123. return typeof variable == 'function' ? variable : undefined;
  5124. };
  5125. module.exports = function (namespace, method) {
  5126. return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global[namespace])
  5127. : path[namespace] && path[namespace][method] || global[namespace] && global[namespace][method];
  5128. };
  5129. /***/ }),
  5130. /***/ "6d86":
  5131. /***/ (function(module, exports, __webpack_require__) {
  5132. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  5133. // Distributed under an MIT license: https://codemirror.net/LICENSE
  5134. (function(mod) {
  5135. if (true) // CommonJS
  5136. mod(__webpack_require__("a564"));
  5137. else {}
  5138. })(function(CodeMirror) {
  5139. "use strict";
  5140. CodeMirror.modeInfo = [
  5141. {name: "APL", mime: "text/apl", mode: "apl", ext: ["dyalog", "apl"]},
  5142. {name: "PGP", mimes: ["application/pgp", "application/pgp-encrypted", "application/pgp-keys", "application/pgp-signature"], mode: "asciiarmor", ext: ["asc", "pgp", "sig"]},
  5143. {name: "ASN.1", mime: "text/x-ttcn-asn", mode: "asn.1", ext: ["asn", "asn1"]},
  5144. {name: "Asterisk", mime: "text/x-asterisk", mode: "asterisk", file: /^extensions\.conf$/i},
  5145. {name: "Brainfuck", mime: "text/x-brainfuck", mode: "brainfuck", ext: ["b", "bf"]},
  5146. {name: "C", mime: "text/x-csrc", mode: "clike", ext: ["c", "h", "ino"]},
  5147. {name: "C++", mime: "text/x-c++src", mode: "clike", ext: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"], alias: ["cpp"]},
  5148. {name: "Cobol", mime: "text/x-cobol", mode: "cobol", ext: ["cob", "cpy"]},
  5149. {name: "C#", mime: "text/x-csharp", mode: "clike", ext: ["cs"], alias: ["csharp", "cs"]},
  5150. {name: "Clojure", mime: "text/x-clojure", mode: "clojure", ext: ["clj", "cljc", "cljx"]},
  5151. {name: "ClojureScript", mime: "text/x-clojurescript", mode: "clojure", ext: ["cljs"]},
  5152. {name: "Closure Stylesheets (GSS)", mime: "text/x-gss", mode: "css", ext: ["gss"]},
  5153. {name: "CMake", mime: "text/x-cmake", mode: "cmake", ext: ["cmake", "cmake.in"], file: /^CMakeLists.txt$/},
  5154. {name: "CoffeeScript", mimes: ["application/vnd.coffeescript", "text/coffeescript", "text/x-coffeescript"], mode: "coffeescript", ext: ["coffee"], alias: ["coffee", "coffee-script"]},
  5155. {name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp", ext: ["cl", "lisp", "el"], alias: ["lisp"]},
  5156. {name: "Cypher", mime: "application/x-cypher-query", mode: "cypher", ext: ["cyp", "cypher"]},
  5157. {name: "Cython", mime: "text/x-cython", mode: "python", ext: ["pyx", "pxd", "pxi"]},
  5158. {name: "Crystal", mime: "text/x-crystal", mode: "crystal", ext: ["cr"]},
  5159. {name: "CSS", mime: "text/css", mode: "css", ext: ["css"]},
  5160. {name: "CQL", mime: "text/x-cassandra", mode: "sql", ext: ["cql"]},
  5161. {name: "D", mime: "text/x-d", mode: "d", ext: ["d"]},
  5162. {name: "Dart", mimes: ["application/dart", "text/x-dart"], mode: "dart", ext: ["dart"]},
  5163. {name: "diff", mime: "text/x-diff", mode: "diff", ext: ["diff", "patch"]},
  5164. {name: "Django", mime: "text/x-django", mode: "django"},
  5165. {name: "Dockerfile", mime: "text/x-dockerfile", mode: "dockerfile", file: /^Dockerfile$/},
  5166. {name: "DTD", mime: "application/xml-dtd", mode: "dtd", ext: ["dtd"]},
  5167. {name: "Dylan", mime: "text/x-dylan", mode: "dylan", ext: ["dylan", "dyl", "intr"]},
  5168. {name: "EBNF", mime: "text/x-ebnf", mode: "ebnf"},
  5169. {name: "ECL", mime: "text/x-ecl", mode: "ecl", ext: ["ecl"]},
  5170. {name: "edn", mime: "application/edn", mode: "clojure", ext: ["edn"]},
  5171. {name: "Eiffel", mime: "text/x-eiffel", mode: "eiffel", ext: ["e"]},
  5172. {name: "Elm", mime: "text/x-elm", mode: "elm", ext: ["elm"]},
  5173. {name: "Embedded Javascript", mime: "application/x-ejs", mode: "htmlembedded", ext: ["ejs"]},
  5174. {name: "Embedded Ruby", mime: "application/x-erb", mode: "htmlembedded", ext: ["erb"]},
  5175. {name: "Erlang", mime: "text/x-erlang", mode: "erlang", ext: ["erl"]},
  5176. {name: "Esper", mime: "text/x-esper", mode: "sql"},
  5177. {name: "Factor", mime: "text/x-factor", mode: "factor", ext: ["factor"]},
  5178. {name: "FCL", mime: "text/x-fcl", mode: "fcl"},
  5179. {name: "Forth", mime: "text/x-forth", mode: "forth", ext: ["forth", "fth", "4th"]},
  5180. {name: "Fortran", mime: "text/x-fortran", mode: "fortran", ext: ["f", "for", "f77", "f90", "f95"]},
  5181. {name: "F#", mime: "text/x-fsharp", mode: "mllike", ext: ["fs"], alias: ["fsharp"]},
  5182. {name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]},
  5183. {name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]},
  5184. {name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history).md$/i},
  5185. {name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]},
  5186. {name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy", "gradle"], file: /^Jenkinsfile$/},
  5187. {name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]},
  5188. {name: "Haskell", mime: "text/x-haskell", mode: "haskell", ext: ["hs"]},
  5189. {name: "Haskell (Literate)", mime: "text/x-literate-haskell", mode: "haskell-literate", ext: ["lhs"]},
  5190. {name: "Haxe", mime: "text/x-haxe", mode: "haxe", ext: ["hx"]},
  5191. {name: "HXML", mime: "text/x-hxml", mode: "haxe", ext: ["hxml"]},
  5192. {name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded", ext: ["aspx"], alias: ["asp", "aspx"]},
  5193. {name: "HTML", mime: "text/html", mode: "htmlmixed", ext: ["html", "htm", "handlebars", "hbs"], alias: ["xhtml"]},
  5194. {name: "HTTP", mime: "message/http", mode: "http"},
  5195. {name: "IDL", mime: "text/x-idl", mode: "idl", ext: ["pro"]},
  5196. {name: "Pug", mime: "text/x-pug", mode: "pug", ext: ["jade", "pug"], alias: ["jade"]},
  5197. {name: "Java", mime: "text/x-java", mode: "clike", ext: ["java"]},
  5198. {name: "Java Server Pages", mime: "application/x-jsp", mode: "htmlembedded", ext: ["jsp"], alias: ["jsp"]},
  5199. {name: "JavaScript", mimes: ["text/javascript", "text/ecmascript", "application/javascript", "application/x-javascript", "application/ecmascript"],
  5200. mode: "javascript", ext: ["js"], alias: ["ecmascript", "js", "node"]},
  5201. {name: "JSON", mimes: ["application/json", "application/x-json"], mode: "javascript", ext: ["json", "map"], alias: ["json5"]},
  5202. {name: "JSON-LD", mime: "application/ld+json", mode: "javascript", ext: ["jsonld"], alias: ["jsonld"]},
  5203. {name: "JSX", mime: "text/jsx", mode: "jsx", ext: ["jsx"]},
  5204. {name: "Jinja2", mime: "text/jinja2", mode: "jinja2", ext: ["j2", "jinja", "jinja2"]},
  5205. {name: "Julia", mime: "text/x-julia", mode: "julia", ext: ["jl"]},
  5206. {name: "Kotlin", mime: "text/x-kotlin", mode: "clike", ext: ["kt"]},
  5207. {name: "LESS", mime: "text/x-less", mode: "css", ext: ["less"]},
  5208. {name: "LiveScript", mime: "text/x-livescript", mode: "livescript", ext: ["ls"], alias: ["ls"]},
  5209. {name: "Lua", mime: "text/x-lua", mode: "lua", ext: ["lua"]},
  5210. {name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]},
  5211. {name: "mIRC", mime: "text/mirc", mode: "mirc"},
  5212. {name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"},
  5213. {name: "Mathematica", mime: "text/x-mathematica", mode: "mathematica", ext: ["m", "nb", "wl", "wls"]},
  5214. {name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
  5215. {name: "MUMPS", mime: "text/x-mumps", mode: "mumps", ext: ["mps"]},
  5216. {name: "MS SQL", mime: "text/x-mssql", mode: "sql"},
  5217. {name: "mbox", mime: "application/mbox", mode: "mbox", ext: ["mbox"]},
  5218. {name: "MySQL", mime: "text/x-mysql", mode: "sql"},
  5219. {name: "Nginx", mime: "text/x-nginx-conf", mode: "nginx", file: /nginx.*\.conf$/i},
  5220. {name: "NSIS", mime: "text/x-nsis", mode: "nsis", ext: ["nsh", "nsi"]},
  5221. {name: "NTriples", mimes: ["application/n-triples", "application/n-quads", "text/n-triples"],
  5222. mode: "ntriples", ext: ["nt", "nq"]},
  5223. {name: "Objective-C", mime: "text/x-objectivec", mode: "clike", ext: ["m"], alias: ["objective-c", "objc"]},
  5224. {name: "Objective-C++", mime: "text/x-objectivec++", mode: "clike", ext: ["mm"], alias: ["objective-c++", "objc++"]},
  5225. {name: "OCaml", mime: "text/x-ocaml", mode: "mllike", ext: ["ml", "mli", "mll", "mly"]},
  5226. {name: "Octave", mime: "text/x-octave", mode: "octave", ext: ["m"]},
  5227. {name: "Oz", mime: "text/x-oz", mode: "oz", ext: ["oz"]},
  5228. {name: "Pascal", mime: "text/x-pascal", mode: "pascal", ext: ["p", "pas"]},
  5229. {name: "PEG.js", mime: "null", mode: "pegjs", ext: ["jsonld"]},
  5230. {name: "Perl", mime: "text/x-perl", mode: "perl", ext: ["pl", "pm"]},
  5231. {name: "PHP", mimes: ["text/x-php", "application/x-httpd-php", "application/x-httpd-php-open"], mode: "php", ext: ["php", "php3", "php4", "php5", "php7", "phtml"]},
  5232. {name: "Pig", mime: "text/x-pig", mode: "pig", ext: ["pig"]},
  5233. {name: "Plain Text", mime: "text/plain", mode: "null", ext: ["txt", "text", "conf", "def", "list", "log"]},
  5234. {name: "PLSQL", mime: "text/x-plsql", mode: "sql", ext: ["pls"]},
  5235. {name: "PostgreSQL", mime: "text/x-pgsql", mode: "sql"},
  5236. {name: "PowerShell", mime: "application/x-powershell", mode: "powershell", ext: ["ps1", "psd1", "psm1"]},
  5237. {name: "Properties files", mime: "text/x-properties", mode: "properties", ext: ["properties", "ini", "in"], alias: ["ini", "properties"]},
  5238. {name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]},
  5239. {name: "Python", mime: "text/x-python", mode: "python", ext: ["BUILD", "bzl", "py", "pyw"], file: /^(BUCK|BUILD)$/},
  5240. {name: "Puppet", mime: "text/x-puppet", mode: "puppet", ext: ["pp"]},
  5241. {name: "Q", mime: "text/x-q", mode: "q", ext: ["q"]},
  5242. {name: "R", mime: "text/x-rsrc", mode: "r", ext: ["r", "R"], alias: ["rscript"]},
  5243. {name: "reStructuredText", mime: "text/x-rst", mode: "rst", ext: ["rst"], alias: ["rst"]},
  5244. {name: "RPM Changes", mime: "text/x-rpm-changes", mode: "rpm"},
  5245. {name: "RPM Spec", mime: "text/x-rpm-spec", mode: "rpm", ext: ["spec"]},
  5246. {name: "Ruby", mime: "text/x-ruby", mode: "ruby", ext: ["rb"], alias: ["jruby", "macruby", "rake", "rb", "rbx"]},
  5247. {name: "Rust", mime: "text/x-rustsrc", mode: "rust", ext: ["rs"]},
  5248. {name: "SAS", mime: "text/x-sas", mode: "sas", ext: ["sas"]},
  5249. {name: "Sass", mime: "text/x-sass", mode: "sass", ext: ["sass"]},
  5250. {name: "Scala", mime: "text/x-scala", mode: "clike", ext: ["scala"]},
  5251. {name: "Scheme", mime: "text/x-scheme", mode: "scheme", ext: ["scm", "ss"]},
  5252. {name: "SCSS", mime: "text/x-scss", mode: "css", ext: ["scss"]},
  5253. {name: "Shell", mimes: ["text/x-sh", "application/x-sh"], mode: "shell", ext: ["sh", "ksh", "bash"], alias: ["bash", "sh", "zsh"], file: /^PKGBUILD$/},
  5254. {name: "Sieve", mime: "application/sieve", mode: "sieve", ext: ["siv", "sieve"]},
  5255. {name: "Slim", mimes: ["text/x-slim", "application/x-slim"], mode: "slim", ext: ["slim"]},
  5256. {name: "Smalltalk", mime: "text/x-stsrc", mode: "smalltalk", ext: ["st"]},
  5257. {name: "Smarty", mime: "text/x-smarty", mode: "smarty", ext: ["tpl"]},
  5258. {name: "Solr", mime: "text/x-solr", mode: "solr"},
  5259. {name: "SML", mime: "text/x-sml", mode: "mllike", ext: ["sml", "sig", "fun", "smackspec"]},
  5260. {name: "Soy", mime: "text/x-soy", mode: "soy", ext: ["soy"], alias: ["closure template"]},
  5261. {name: "SPARQL", mime: "application/sparql-query", mode: "sparql", ext: ["rq", "sparql"], alias: ["sparul"]},
  5262. {name: "Spreadsheet", mime: "text/x-spreadsheet", mode: "spreadsheet", alias: ["excel", "formula"]},
  5263. {name: "SQL", mime: "text/x-sql", mode: "sql", ext: ["sql"]},
  5264. {name: "SQLite", mime: "text/x-sqlite", mode: "sql"},
  5265. {name: "Squirrel", mime: "text/x-squirrel", mode: "clike", ext: ["nut"]},
  5266. {name: "Stylus", mime: "text/x-styl", mode: "stylus", ext: ["styl"]},
  5267. {name: "Swift", mime: "text/x-swift", mode: "swift", ext: ["swift"]},
  5268. {name: "sTeX", mime: "text/x-stex", mode: "stex"},
  5269. {name: "LaTeX", mime: "text/x-latex", mode: "stex", ext: ["text", "ltx", "tex"], alias: ["tex"]},
  5270. {name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog", ext: ["v", "sv", "svh"]},
  5271. {name: "Tcl", mime: "text/x-tcl", mode: "tcl", ext: ["tcl"]},
  5272. {name: "Textile", mime: "text/x-textile", mode: "textile", ext: ["textile"]},
  5273. {name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
  5274. {name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
  5275. {name: "TOML", mime: "text/x-toml", mode: "toml", ext: ["toml"]},
  5276. {name: "Tornado", mime: "text/x-tornado", mode: "tornado"},
  5277. {name: "troff", mime: "text/troff", mode: "troff", ext: ["1", "2", "3", "4", "5", "6", "7", "8", "9"]},
  5278. {name: "TTCN", mime: "text/x-ttcn", mode: "ttcn", ext: ["ttcn", "ttcn3", "ttcnpp"]},
  5279. {name: "TTCN_CFG", mime: "text/x-ttcn-cfg", mode: "ttcn-cfg", ext: ["cfg"]},
  5280. {name: "Turtle", mime: "text/turtle", mode: "turtle", ext: ["ttl"]},
  5281. {name: "TypeScript", mime: "application/typescript", mode: "javascript", ext: ["ts"], alias: ["ts"]},
  5282. {name: "TypeScript-JSX", mime: "text/typescript-jsx", mode: "jsx", ext: ["tsx"], alias: ["tsx"]},
  5283. {name: "Twig", mime: "text/x-twig", mode: "twig"},
  5284. {name: "Web IDL", mime: "text/x-webidl", mode: "webidl", ext: ["webidl"]},
  5285. {name: "VB.NET", mime: "text/x-vb", mode: "vb", ext: ["vb"]},
  5286. {name: "VBScript", mime: "text/vbscript", mode: "vbscript", ext: ["vbs"]},
  5287. {name: "Velocity", mime: "text/velocity", mode: "velocity", ext: ["vtl"]},
  5288. {name: "Verilog", mime: "text/x-verilog", mode: "verilog", ext: ["v"]},
  5289. {name: "VHDL", mime: "text/x-vhdl", mode: "vhdl", ext: ["vhd", "vhdl"]},
  5290. {name: "Vue.js Component", mimes: ["script/x-vue", "text/x-vue"], mode: "vue", ext: ["vue"]},
  5291. {name: "XML", mimes: ["application/xml", "text/xml"], mode: "xml", ext: ["xml", "xsl", "xsd", "svg"], alias: ["rss", "wsdl", "xsd"]},
  5292. {name: "XQuery", mime: "application/xquery", mode: "xquery", ext: ["xy", "xquery"]},
  5293. {name: "Yacas", mime: "text/x-yacas", mode: "yacas", ext: ["ys"]},
  5294. {name: "YAML", mimes: ["text/x-yaml", "text/yaml"], mode: "yaml", ext: ["yaml", "yml"], alias: ["yml"]},
  5295. {name: "Z80", mime: "text/x-z80", mode: "z80", ext: ["z80"]},
  5296. {name: "mscgen", mime: "text/x-mscgen", mode: "mscgen", ext: ["mscgen", "mscin", "msc"]},
  5297. {name: "xu", mime: "text/x-xu", mode: "mscgen", ext: ["xu"]},
  5298. {name: "msgenny", mime: "text/x-msgenny", mode: "mscgen", ext: ["msgenny"]}
  5299. ];
  5300. // Ensure all modes have a mime property for backwards compatibility
  5301. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5302. var info = CodeMirror.modeInfo[i];
  5303. if (info.mimes) info.mime = info.mimes[0];
  5304. }
  5305. CodeMirror.findModeByMIME = function(mime) {
  5306. mime = mime.toLowerCase();
  5307. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5308. var info = CodeMirror.modeInfo[i];
  5309. if (info.mime == mime) return info;
  5310. if (info.mimes) for (var j = 0; j < info.mimes.length; j++)
  5311. if (info.mimes[j] == mime) return info;
  5312. }
  5313. if (/\+xml$/.test(mime)) return CodeMirror.findModeByMIME("application/xml")
  5314. if (/\+json$/.test(mime)) return CodeMirror.findModeByMIME("application/json")
  5315. };
  5316. CodeMirror.findModeByExtension = function(ext) {
  5317. ext = ext.toLowerCase();
  5318. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5319. var info = CodeMirror.modeInfo[i];
  5320. if (info.ext) for (var j = 0; j < info.ext.length; j++)
  5321. if (info.ext[j] == ext) return info;
  5322. }
  5323. };
  5324. CodeMirror.findModeByFileName = function(filename) {
  5325. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5326. var info = CodeMirror.modeInfo[i];
  5327. if (info.file && info.file.test(filename)) return info;
  5328. }
  5329. var dot = filename.lastIndexOf(".");
  5330. var ext = dot > -1 && filename.substring(dot + 1, filename.length);
  5331. if (ext) return CodeMirror.findModeByExtension(ext);
  5332. };
  5333. CodeMirror.findModeByName = function(name) {
  5334. name = name.toLowerCase();
  5335. for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
  5336. var info = CodeMirror.modeInfo[i];
  5337. if (info.name.toLowerCase() == name) return info;
  5338. if (info.alias) for (var j = 0; j < info.alias.length; j++)
  5339. if (info.alias[j].toLowerCase() == name) return info;
  5340. }
  5341. };
  5342. });
  5343. /***/ }),
  5344. /***/ "6fdf":
  5345. /***/ (function(module, exports, __webpack_require__) {
  5346. var getBuiltIn = __webpack_require__("6d7a");
  5347. module.exports = getBuiltIn('document', 'documentElement');
  5348. /***/ }),
  5349. /***/ "74cb":
  5350. /***/ (function(module, exports, __webpack_require__) {
  5351. var NATIVE_SYMBOL = __webpack_require__("c54b");
  5352. module.exports = NATIVE_SYMBOL
  5353. // eslint-disable-next-line no-undef
  5354. && !Symbol.sham
  5355. // eslint-disable-next-line no-undef
  5356. && typeof Symbol.iterator == 'symbol';
  5357. /***/ }),
  5358. /***/ "74e7":
  5359. /***/ (function(module, exports, __webpack_require__) {
  5360. var classof = __webpack_require__("2118");
  5361. // `IsArray` abstract operation
  5362. // https://tc39.github.io/ecma262/#sec-isarray
  5363. module.exports = Array.isArray || function isArray(arg) {
  5364. return classof(arg) == 'Array';
  5365. };
  5366. /***/ }),
  5367. /***/ "7727":
  5368. /***/ (function(module, exports, __webpack_require__) {
  5369. const Renderer = __webpack_require__("155c");
  5370. const TextRenderer = __webpack_require__("f5ef");
  5371. const Slugger = __webpack_require__("05cd");
  5372. const { defaults } = __webpack_require__("a8a2");
  5373. const {
  5374. unescape
  5375. } = __webpack_require__("322c");
  5376. /**
  5377. * Parsing & Compiling
  5378. */
  5379. module.exports = class Parser {
  5380. constructor(options) {
  5381. this.options = options || defaults;
  5382. this.options.renderer = this.options.renderer || new Renderer();
  5383. this.renderer = this.options.renderer;
  5384. this.renderer.options = this.options;
  5385. this.textRenderer = new TextRenderer();
  5386. this.slugger = new Slugger();
  5387. }
  5388. /**
  5389. * Static Parse Method
  5390. */
  5391. static parse(tokens, options) {
  5392. const parser = new Parser(options);
  5393. return parser.parse(tokens);
  5394. }
  5395. /**
  5396. * Parse Loop
  5397. */
  5398. parse(tokens, top = true) {
  5399. let out = '',
  5400. i,
  5401. j,
  5402. k,
  5403. l2,
  5404. l3,
  5405. row,
  5406. cell,
  5407. header,
  5408. body,
  5409. token,
  5410. ordered,
  5411. start,
  5412. loose,
  5413. itemBody,
  5414. item,
  5415. checked,
  5416. task,
  5417. checkbox;
  5418. const l = tokens.length;
  5419. for (i = 0; i < l; i++) {
  5420. token = tokens[i];
  5421. switch (token.type) {
  5422. case 'space': {
  5423. continue;
  5424. }
  5425. case 'hr': {
  5426. out += this.renderer.hr();
  5427. continue;
  5428. }
  5429. case 'heading': {
  5430. out += this.renderer.heading(
  5431. this.parseInline(token.tokens),
  5432. token.depth,
  5433. unescape(this.parseInline(token.tokens, this.textRenderer)),
  5434. this.slugger);
  5435. continue;
  5436. }
  5437. case 'code': {
  5438. out += this.renderer.code(token.text,
  5439. token.lang,
  5440. token.escaped);
  5441. continue;
  5442. }
  5443. case 'table': {
  5444. header = '';
  5445. // header
  5446. cell = '';
  5447. l2 = token.header.length;
  5448. for (j = 0; j < l2; j++) {
  5449. cell += this.renderer.tablecell(
  5450. this.parseInline(token.tokens.header[j]),
  5451. { header: true, align: token.align[j] }
  5452. );
  5453. }
  5454. header += this.renderer.tablerow(cell);
  5455. body = '';
  5456. l2 = token.cells.length;
  5457. for (j = 0; j < l2; j++) {
  5458. row = token.tokens.cells[j];
  5459. cell = '';
  5460. l3 = row.length;
  5461. for (k = 0; k < l3; k++) {
  5462. cell += this.renderer.tablecell(
  5463. this.parseInline(row[k]),
  5464. { header: false, align: token.align[k] }
  5465. );
  5466. }
  5467. body += this.renderer.tablerow(cell);
  5468. }
  5469. out += this.renderer.table(header, body);
  5470. continue;
  5471. }
  5472. case 'blockquote': {
  5473. body = this.parse(token.tokens);
  5474. out += this.renderer.blockquote(body);
  5475. continue;
  5476. }
  5477. case 'list': {
  5478. ordered = token.ordered;
  5479. start = token.start;
  5480. loose = token.loose;
  5481. l2 = token.items.length;
  5482. body = '';
  5483. for (j = 0; j < l2; j++) {
  5484. item = token.items[j];
  5485. checked = item.checked;
  5486. task = item.task;
  5487. itemBody = '';
  5488. if (item.task) {
  5489. checkbox = this.renderer.checkbox(checked);
  5490. if (loose) {
  5491. if (item.tokens[0].type === 'text') {
  5492. item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
  5493. if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
  5494. item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
  5495. }
  5496. } else {
  5497. item.tokens.unshift({
  5498. type: 'text',
  5499. text: checkbox
  5500. });
  5501. }
  5502. } else {
  5503. itemBody += checkbox;
  5504. }
  5505. }
  5506. itemBody += this.parse(item.tokens, loose);
  5507. body += this.renderer.listitem(itemBody, task, checked);
  5508. }
  5509. out += this.renderer.list(body, ordered, start);
  5510. continue;
  5511. }
  5512. case 'html': {
  5513. // TODO parse inline content if parameter markdown=1
  5514. out += this.renderer.html(token.text);
  5515. continue;
  5516. }
  5517. case 'paragraph': {
  5518. out += this.renderer.paragraph(this.parseInline(token.tokens));
  5519. continue;
  5520. }
  5521. case 'text': {
  5522. body = token.tokens ? this.parseInline(token.tokens) : token.text;
  5523. while (i + 1 < l && tokens[i + 1].type === 'text') {
  5524. token = tokens[++i];
  5525. body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
  5526. }
  5527. out += top ? this.renderer.paragraph(body) : body;
  5528. continue;
  5529. }
  5530. default: {
  5531. const errMsg = 'Token with "' + token.type + '" type was not found.';
  5532. if (this.options.silent) {
  5533. console.error(errMsg);
  5534. return;
  5535. } else {
  5536. throw new Error(errMsg);
  5537. }
  5538. }
  5539. }
  5540. }
  5541. return out;
  5542. }
  5543. /**
  5544. * Parse Inline Tokens
  5545. */
  5546. parseInline(tokens, renderer) {
  5547. renderer = renderer || this.renderer;
  5548. let out = '',
  5549. i,
  5550. token;
  5551. const l = tokens.length;
  5552. for (i = 0; i < l; i++) {
  5553. token = tokens[i];
  5554. switch (token.type) {
  5555. case 'escape': {
  5556. out += renderer.text(token.text);
  5557. break;
  5558. }
  5559. case 'html': {
  5560. out += renderer.html(token.text);
  5561. break;
  5562. }
  5563. case 'link': {
  5564. out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
  5565. break;
  5566. }
  5567. case 'image': {
  5568. out += renderer.image(token.href, token.title, token.text);
  5569. break;
  5570. }
  5571. case 'strong': {
  5572. out += renderer.strong(this.parseInline(token.tokens, renderer));
  5573. break;
  5574. }
  5575. case 'em': {
  5576. out += renderer.em(this.parseInline(token.tokens, renderer));
  5577. break;
  5578. }
  5579. case 'codespan': {
  5580. out += renderer.codespan(token.text);
  5581. break;
  5582. }
  5583. case 'br': {
  5584. out += renderer.br();
  5585. break;
  5586. }
  5587. case 'del': {
  5588. out += renderer.del(this.parseInline(token.tokens, renderer));
  5589. break;
  5590. }
  5591. case 'text': {
  5592. out += renderer.text(token.text);
  5593. break;
  5594. }
  5595. default: {
  5596. const errMsg = 'Token with "' + token.type + '" type was not found.';
  5597. if (this.options.silent) {
  5598. console.error(errMsg);
  5599. return;
  5600. } else {
  5601. throw new Error(errMsg);
  5602. }
  5603. }
  5604. }
  5605. }
  5606. return out;
  5607. }
  5608. };
  5609. /***/ }),
  5610. /***/ "7899":
  5611. /***/ (function(module, exports, __webpack_require__) {
  5612. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  5613. // Distributed under an MIT license: https://codemirror.net/LICENSE
  5614. (function(mod) {
  5615. if (true) // CommonJS
  5616. mod(__webpack_require__("a564"));
  5617. else {}
  5618. })(function(CodeMirror) {
  5619. "use strict";
  5620. var listRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/,
  5621. emptyListRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/,
  5622. unorderedListRE = /[*+-]\s/;
  5623. CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
  5624. if (cm.getOption("disableInput")) return CodeMirror.Pass;
  5625. var ranges = cm.listSelections(), replacements = [];
  5626. for (var i = 0; i < ranges.length; i++) {
  5627. var pos = ranges[i].head;
  5628. // If we're not in Markdown mode, fall back to normal newlineAndIndent
  5629. var eolState = cm.getStateAfter(pos.line);
  5630. var inner = CodeMirror.innerMode(cm.getMode(), eolState);
  5631. if (inner.mode.name !== "markdown") {
  5632. cm.execCommand("newlineAndIndent");
  5633. return;
  5634. } else {
  5635. eolState = inner.state;
  5636. }
  5637. var inList = eolState.list !== false;
  5638. var inQuote = eolState.quote !== 0;
  5639. var line = cm.getLine(pos.line), match = listRE.exec(line);
  5640. var cursorBeforeBullet = /^\s*$/.test(line.slice(0, pos.ch));
  5641. if (!ranges[i].empty() || (!inList && !inQuote) || !match || cursorBeforeBullet) {
  5642. cm.execCommand("newlineAndIndent");
  5643. return;
  5644. }
  5645. if (emptyListRE.test(line)) {
  5646. var endOfQuote = inQuote && />\s*$/.test(line)
  5647. var endOfList = !/>\s*$/.test(line)
  5648. if (endOfQuote || endOfList) cm.replaceRange("", {
  5649. line: pos.line, ch: 0
  5650. }, {
  5651. line: pos.line, ch: pos.ch + 1
  5652. });
  5653. replacements[i] = "\n";
  5654. } else {
  5655. var indent = match[1], after = match[5];
  5656. var numbered = !(unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0);
  5657. var bullet = numbered ? (parseInt(match[3], 10) + 1) + match[4] : match[2].replace("x", " ");
  5658. replacements[i] = "\n" + indent + bullet + after;
  5659. if (numbered) incrementRemainingMarkdownListNumbers(cm, pos);
  5660. }
  5661. }
  5662. cm.replaceSelections(replacements);
  5663. };
  5664. // Auto-updating Markdown list numbers when a new item is added to the
  5665. // middle of a list
  5666. function incrementRemainingMarkdownListNumbers(cm, pos) {
  5667. var startLine = pos.line, lookAhead = 0, skipCount = 0;
  5668. var startItem = listRE.exec(cm.getLine(startLine)), startIndent = startItem[1];
  5669. do {
  5670. lookAhead += 1;
  5671. var nextLineNumber = startLine + lookAhead;
  5672. var nextLine = cm.getLine(nextLineNumber), nextItem = listRE.exec(nextLine);
  5673. if (nextItem) {
  5674. var nextIndent = nextItem[1];
  5675. var newNumber = (parseInt(startItem[3], 10) + lookAhead - skipCount);
  5676. var nextNumber = (parseInt(nextItem[3], 10)), itemNumber = nextNumber;
  5677. if (startIndent === nextIndent && !isNaN(nextNumber)) {
  5678. if (newNumber === nextNumber) itemNumber = nextNumber + 1;
  5679. if (newNumber > nextNumber) itemNumber = newNumber + 1;
  5680. cm.replaceRange(
  5681. nextLine.replace(listRE, nextIndent + itemNumber + nextItem[4] + nextItem[5]),
  5682. {
  5683. line: nextLineNumber, ch: 0
  5684. }, {
  5685. line: nextLineNumber, ch: nextLine.length
  5686. });
  5687. } else {
  5688. if (startIndent.length > nextIndent.length) return;
  5689. // This doesn't run if the next line immediatley indents, as it is
  5690. // not clear of the users intention (new indented item or same level)
  5691. if ((startIndent.length < nextIndent.length) && (lookAhead === 1)) return;
  5692. skipCount += 1;
  5693. }
  5694. }
  5695. } while (nextItem);
  5696. }
  5697. });
  5698. /***/ }),
  5699. /***/ "7db2":
  5700. /***/ (function(module, exports, __webpack_require__) {
  5701. var shared = __webpack_require__("6d28");
  5702. var uid = __webpack_require__("7e8b");
  5703. var keys = shared('keys');
  5704. module.exports = function (key) {
  5705. return keys[key] || (keys[key] = uid(key));
  5706. };
  5707. /***/ }),
  5708. /***/ "7e8b":
  5709. /***/ (function(module, exports) {
  5710. var id = 0;
  5711. var postfix = Math.random();
  5712. module.exports = function (key) {
  5713. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  5714. };
  5715. /***/ }),
  5716. /***/ "857c":
  5717. /***/ (function(module, exports, __webpack_require__) {
  5718. var isObject = __webpack_require__("a719");
  5719. module.exports = function (it) {
  5720. if (!isObject(it)) {
  5721. throw TypeError(String(it) + ' is not an object');
  5722. } return it;
  5723. };
  5724. /***/ }),
  5725. /***/ "8d44":
  5726. /***/ (function(module, exports, __webpack_require__) {
  5727. var getBuiltIn = __webpack_require__("6d7a");
  5728. var getOwnPropertyNamesModule = __webpack_require__("b338");
  5729. var getOwnPropertySymbolsModule = __webpack_require__("0a60");
  5730. var anObject = __webpack_require__("857c");
  5731. // all object keys, includes non-enumerable and symbols
  5732. module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  5733. var keys = getOwnPropertyNamesModule.f(anObject(it));
  5734. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  5735. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  5736. };
  5737. /***/ }),
  5738. /***/ "90fb":
  5739. /***/ (function(module, exports, __webpack_require__) {
  5740. var global = __webpack_require__("d890");
  5741. var shared = __webpack_require__("6d28");
  5742. var has = __webpack_require__("faa8");
  5743. var uid = __webpack_require__("7e8b");
  5744. var NATIVE_SYMBOL = __webpack_require__("c54b");
  5745. var USE_SYMBOL_AS_UID = __webpack_require__("74cb");
  5746. var WellKnownSymbolsStore = shared('wks');
  5747. var Symbol = global.Symbol;
  5748. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol : Symbol && Symbol.withoutSetter || uid;
  5749. module.exports = function (name) {
  5750. if (!has(WellKnownSymbolsStore, name)) {
  5751. if (NATIVE_SYMBOL && has(Symbol, name)) WellKnownSymbolsStore[name] = Symbol[name];
  5752. else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  5753. } return WellKnownSymbolsStore[name];
  5754. };
  5755. /***/ }),
  5756. /***/ "9b9d":
  5757. /***/ (function(module, exports) {
  5758. module.exports = false;
  5759. /***/ }),
  5760. /***/ "9edd":
  5761. /***/ (function(module, exports) {
  5762. var g;
  5763. // This works in non-strict mode
  5764. g = (function() {
  5765. return this;
  5766. })();
  5767. try {
  5768. // This works if eval is allowed (see CSP)
  5769. g = g || new Function("return this")();
  5770. } catch (e) {
  5771. // This works if the window reference is available
  5772. if (typeof window === "object") g = window;
  5773. }
  5774. // g can still be undefined, but nothing to do about it...
  5775. // We return undefined, instead of nothing here, so it's
  5776. // easier to handle this case. if(!global) { ...}
  5777. module.exports = g;
  5778. /***/ }),
  5779. /***/ "9f67":
  5780. /***/ (function(module, exports, __webpack_require__) {
  5781. var isObject = __webpack_require__("a719");
  5782. // `ToPrimitive` abstract operation
  5783. // https://tc39.github.io/ecma262/#sec-toprimitive
  5784. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  5785. // and the second argument - flag - preferred type is a string
  5786. module.exports = function (input, PREFERRED_STRING) {
  5787. if (!isObject(input)) return input;
  5788. var fn, val;
  5789. if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  5790. if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
  5791. if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  5792. throw TypeError("Can't convert object to primitive value");
  5793. };
  5794. /***/ }),
  5795. /***/ "a564":
  5796. /***/ (function(module, exports, __webpack_require__) {
  5797. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  5798. // Distributed under an MIT license: https://codemirror.net/LICENSE
  5799. // This is CodeMirror (https://codemirror.net), a code editor
  5800. // implemented in JavaScript on top of the browser's DOM.
  5801. //
  5802. // You can find some technical background for some of the code below
  5803. // at http://marijnhaverbeke.nl/blog/#cm-internals .
  5804. (function (global, factory) {
  5805. true ? module.exports = factory() :
  5806. undefined;
  5807. }(this, (function () { 'use strict';
  5808. // Kludges for bugs and behavior differences that can't be feature
  5809. // detected are enabled based on userAgent etc sniffing.
  5810. var userAgent = navigator.userAgent;
  5811. var platform = navigator.platform;
  5812. var gecko = /gecko\/\d/i.test(userAgent);
  5813. var ie_upto10 = /MSIE \d/.test(userAgent);
  5814. var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
  5815. var edge = /Edge\/(\d+)/.exec(userAgent);
  5816. var ie = ie_upto10 || ie_11up || edge;
  5817. var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
  5818. var webkit = !edge && /WebKit\//.test(userAgent);
  5819. var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
  5820. var chrome = !edge && /Chrome\//.test(userAgent);
  5821. var presto = /Opera\//.test(userAgent);
  5822. var safari = /Apple Computer/.test(navigator.vendor);
  5823. var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
  5824. var phantom = /PhantomJS/.test(userAgent);
  5825. var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
  5826. var android = /Android/.test(userAgent);
  5827. // This is woefully incomplete. Suggestions for alternative methods welcome.
  5828. var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
  5829. var mac = ios || /Mac/.test(platform);
  5830. var chromeOS = /\bCrOS\b/.test(userAgent);
  5831. var windows = /win/i.test(platform);
  5832. var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
  5833. if (presto_version) { presto_version = Number(presto_version[1]); }
  5834. if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
  5835. // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
  5836. var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
  5837. var captureRightClick = gecko || (ie && ie_version >= 9);
  5838. function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
  5839. var rmClass = function(node, cls) {
  5840. var current = node.className;
  5841. var match = classTest(cls).exec(current);
  5842. if (match) {
  5843. var after = current.slice(match.index + match[0].length);
  5844. node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
  5845. }
  5846. };
  5847. function removeChildren(e) {
  5848. for (var count = e.childNodes.length; count > 0; --count)
  5849. { e.removeChild(e.firstChild); }
  5850. return e
  5851. }
  5852. function removeChildrenAndAdd(parent, e) {
  5853. return removeChildren(parent).appendChild(e)
  5854. }
  5855. function elt(tag, content, className, style) {
  5856. var e = document.createElement(tag);
  5857. if (className) { e.className = className; }
  5858. if (style) { e.style.cssText = style; }
  5859. if (typeof content == "string") { e.appendChild(document.createTextNode(content)); }
  5860. else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } }
  5861. return e
  5862. }
  5863. // wrapper for elt, which removes the elt from the accessibility tree
  5864. function eltP(tag, content, className, style) {
  5865. var e = elt(tag, content, className, style);
  5866. e.setAttribute("role", "presentation");
  5867. return e
  5868. }
  5869. var range;
  5870. if (document.createRange) { range = function(node, start, end, endNode) {
  5871. var r = document.createRange();
  5872. r.setEnd(endNode || node, end);
  5873. r.setStart(node, start);
  5874. return r
  5875. }; }
  5876. else { range = function(node, start, end) {
  5877. var r = document.body.createTextRange();
  5878. try { r.moveToElementText(node.parentNode); }
  5879. catch(e) { return r }
  5880. r.collapse(true);
  5881. r.moveEnd("character", end);
  5882. r.moveStart("character", start);
  5883. return r
  5884. }; }
  5885. function contains(parent, child) {
  5886. if (child.nodeType == 3) // Android browser always returns false when child is a textnode
  5887. { child = child.parentNode; }
  5888. if (parent.contains)
  5889. { return parent.contains(child) }
  5890. do {
  5891. if (child.nodeType == 11) { child = child.host; }
  5892. if (child == parent) { return true }
  5893. } while (child = child.parentNode)
  5894. }
  5895. function activeElt() {
  5896. // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
  5897. // IE < 10 will throw when accessed while the page is loading or in an iframe.
  5898. // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
  5899. var activeElement;
  5900. try {
  5901. activeElement = document.activeElement;
  5902. } catch(e) {
  5903. activeElement = document.body || null;
  5904. }
  5905. while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
  5906. { activeElement = activeElement.shadowRoot.activeElement; }
  5907. return activeElement
  5908. }
  5909. function addClass(node, cls) {
  5910. var current = node.className;
  5911. if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; }
  5912. }
  5913. function joinClasses(a, b) {
  5914. var as = a.split(" ");
  5915. for (var i = 0; i < as.length; i++)
  5916. { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } }
  5917. return b
  5918. }
  5919. var selectInput = function(node) { node.select(); };
  5920. if (ios) // Mobile Safari apparently has a bug where select() is broken.
  5921. { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; }
  5922. else if (ie) // Suppress mysterious IE10 errors
  5923. { selectInput = function(node) { try { node.select(); } catch(_e) {} }; }
  5924. function bind(f) {
  5925. var args = Array.prototype.slice.call(arguments, 1);
  5926. return function(){return f.apply(null, args)}
  5927. }
  5928. function copyObj(obj, target, overwrite) {
  5929. if (!target) { target = {}; }
  5930. for (var prop in obj)
  5931. { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
  5932. { target[prop] = obj[prop]; } }
  5933. return target
  5934. }
  5935. // Counts the column offset in a string, taking tabs into account.
  5936. // Used mostly to find indentation.
  5937. function countColumn(string, end, tabSize, startIndex, startValue) {
  5938. if (end == null) {
  5939. end = string.search(/[^\s\u00a0]/);
  5940. if (end == -1) { end = string.length; }
  5941. }
  5942. for (var i = startIndex || 0, n = startValue || 0;;) {
  5943. var nextTab = string.indexOf("\t", i);
  5944. if (nextTab < 0 || nextTab >= end)
  5945. { return n + (end - i) }
  5946. n += nextTab - i;
  5947. n += tabSize - (n % tabSize);
  5948. i = nextTab + 1;
  5949. }
  5950. }
  5951. var Delayed = function() {
  5952. this.id = null;
  5953. this.f = null;
  5954. this.time = 0;
  5955. this.handler = bind(this.onTimeout, this);
  5956. };
  5957. Delayed.prototype.onTimeout = function (self) {
  5958. self.id = 0;
  5959. if (self.time <= +new Date) {
  5960. self.f();
  5961. } else {
  5962. setTimeout(self.handler, self.time - +new Date);
  5963. }
  5964. };
  5965. Delayed.prototype.set = function (ms, f) {
  5966. this.f = f;
  5967. var time = +new Date + ms;
  5968. if (!this.id || time < this.time) {
  5969. clearTimeout(this.id);
  5970. this.id = setTimeout(this.handler, ms);
  5971. this.time = time;
  5972. }
  5973. };
  5974. function indexOf(array, elt) {
  5975. for (var i = 0; i < array.length; ++i)
  5976. { if (array[i] == elt) { return i } }
  5977. return -1
  5978. }
  5979. // Number of pixels added to scroller and sizer to hide scrollbar
  5980. var scrollerGap = 30;
  5981. // Returned or thrown by various protocols to signal 'I'm not
  5982. // handling this'.
  5983. var Pass = {toString: function(){return "CodeMirror.Pass"}};
  5984. // Reused option objects for setSelection & friends
  5985. var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
  5986. // The inverse of countColumn -- find the offset that corresponds to
  5987. // a particular column.
  5988. function findColumn(string, goal, tabSize) {
  5989. for (var pos = 0, col = 0;;) {
  5990. var nextTab = string.indexOf("\t", pos);
  5991. if (nextTab == -1) { nextTab = string.length; }
  5992. var skipped = nextTab - pos;
  5993. if (nextTab == string.length || col + skipped >= goal)
  5994. { return pos + Math.min(skipped, goal - col) }
  5995. col += nextTab - pos;
  5996. col += tabSize - (col % tabSize);
  5997. pos = nextTab + 1;
  5998. if (col >= goal) { return pos }
  5999. }
  6000. }
  6001. var spaceStrs = [""];
  6002. function spaceStr(n) {
  6003. while (spaceStrs.length <= n)
  6004. { spaceStrs.push(lst(spaceStrs) + " "); }
  6005. return spaceStrs[n]
  6006. }
  6007. function lst(arr) { return arr[arr.length-1] }
  6008. function map(array, f) {
  6009. var out = [];
  6010. for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); }
  6011. return out
  6012. }
  6013. function insertSorted(array, value, score) {
  6014. var pos = 0, priority = score(value);
  6015. while (pos < array.length && score(array[pos]) <= priority) { pos++; }
  6016. array.splice(pos, 0, value);
  6017. }
  6018. function nothing() {}
  6019. function createObj(base, props) {
  6020. var inst;
  6021. if (Object.create) {
  6022. inst = Object.create(base);
  6023. } else {
  6024. nothing.prototype = base;
  6025. inst = new nothing();
  6026. }
  6027. if (props) { copyObj(props, inst); }
  6028. return inst
  6029. }
  6030. var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
  6031. function isWordCharBasic(ch) {
  6032. return /\w/.test(ch) || ch > "\x80" &&
  6033. (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
  6034. }
  6035. function isWordChar(ch, helper) {
  6036. if (!helper) { return isWordCharBasic(ch) }
  6037. if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
  6038. return helper.test(ch)
  6039. }
  6040. function isEmpty(obj) {
  6041. for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
  6042. return true
  6043. }
  6044. // Extending unicode characters. A series of a non-extending char +
  6045. // any number of extending chars is treated as a single unit as far
  6046. // as editing and measuring is concerned. This is not fully correct,
  6047. // since some scripts/fonts/browsers also treat other configurations
  6048. // of code points as a group.
  6049. 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]/;
  6050. function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
  6051. // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
  6052. function skipExtendingChars(str, pos, dir) {
  6053. while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; }
  6054. return pos
  6055. }
  6056. // Returns the value from the range [`from`; `to`] that satisfies
  6057. // `pred` and is closest to `from`. Assumes that at least `to`
  6058. // satisfies `pred`. Supports `from` being greater than `to`.
  6059. function findFirst(pred, from, to) {
  6060. // At any point we are certain `to` satisfies `pred`, don't know
  6061. // whether `from` does.
  6062. var dir = from > to ? -1 : 1;
  6063. for (;;) {
  6064. if (from == to) { return from }
  6065. var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
  6066. if (mid == from) { return pred(mid) ? from : to }
  6067. if (pred(mid)) { to = mid; }
  6068. else { from = mid + dir; }
  6069. }
  6070. }
  6071. // BIDI HELPERS
  6072. function iterateBidiSections(order, from, to, f) {
  6073. if (!order) { return f(from, to, "ltr", 0) }
  6074. var found = false;
  6075. for (var i = 0; i < order.length; ++i) {
  6076. var part = order[i];
  6077. if (part.from < to && part.to > from || from == to && part.to == from) {
  6078. f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i);
  6079. found = true;
  6080. }
  6081. }
  6082. if (!found) { f(from, to, "ltr"); }
  6083. }
  6084. var bidiOther = null;
  6085. function getBidiPartAt(order, ch, sticky) {
  6086. var found;
  6087. bidiOther = null;
  6088. for (var i = 0; i < order.length; ++i) {
  6089. var cur = order[i];
  6090. if (cur.from < ch && cur.to > ch) { return i }
  6091. if (cur.to == ch) {
  6092. if (cur.from != cur.to && sticky == "before") { found = i; }
  6093. else { bidiOther = i; }
  6094. }
  6095. if (cur.from == ch) {
  6096. if (cur.from != cur.to && sticky != "before") { found = i; }
  6097. else { bidiOther = i; }
  6098. }
  6099. }
  6100. return found != null ? found : bidiOther
  6101. }
  6102. // Bidirectional ordering algorithm
  6103. // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
  6104. // that this (partially) implements.
  6105. // One-char codes used for character types:
  6106. // L (L): Left-to-Right
  6107. // R (R): Right-to-Left
  6108. // r (AL): Right-to-Left Arabic
  6109. // 1 (EN): European Number
  6110. // + (ES): European Number Separator
  6111. // % (ET): European Number Terminator
  6112. // n (AN): Arabic Number
  6113. // , (CS): Common Number Separator
  6114. // m (NSM): Non-Spacing Mark
  6115. // b (BN): Boundary Neutral
  6116. // s (B): Paragraph Separator
  6117. // t (S): Segment Separator
  6118. // w (WS): Whitespace
  6119. // N (ON): Other Neutrals
  6120. // Returns null if characters are ordered as they appear
  6121. // (left-to-right), or an array of sections ({from, to, level}
  6122. // objects) in the order in which they occur visually.
  6123. var bidiOrdering = (function() {
  6124. // Character types for codepoints 0 to 0xff
  6125. var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
  6126. // Character types for codepoints 0x600 to 0x6f9
  6127. var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
  6128. function charType(code) {
  6129. if (code <= 0xf7) { return lowTypes.charAt(code) }
  6130. else if (0x590 <= code && code <= 0x5f4) { return "R" }
  6131. else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
  6132. else if (0x6ee <= code && code <= 0x8ac) { return "r" }
  6133. else if (0x2000 <= code && code <= 0x200b) { return "w" }
  6134. else if (code == 0x200c) { return "b" }
  6135. else { return "L" }
  6136. }
  6137. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
  6138. var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
  6139. function BidiSpan(level, from, to) {
  6140. this.level = level;
  6141. this.from = from; this.to = to;
  6142. }
  6143. return function(str, direction) {
  6144. var outerType = direction == "ltr" ? "L" : "R";
  6145. if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
  6146. var len = str.length, types = [];
  6147. for (var i = 0; i < len; ++i)
  6148. { types.push(charType(str.charCodeAt(i))); }
  6149. // W1. Examine each non-spacing mark (NSM) in the level run, and
  6150. // change the type of the NSM to the type of the previous
  6151. // character. If the NSM is at the start of the level run, it will
  6152. // get the type of sor.
  6153. for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
  6154. var type = types[i$1];
  6155. if (type == "m") { types[i$1] = prev; }
  6156. else { prev = type; }
  6157. }
  6158. // W2. Search backwards from each instance of a European number
  6159. // until the first strong type (R, L, AL, or sor) is found. If an
  6160. // AL is found, change the type of the European number to Arabic
  6161. // number.
  6162. // W3. Change all ALs to R.
  6163. for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
  6164. var type$1 = types[i$2];
  6165. if (type$1 == "1" && cur == "r") { types[i$2] = "n"; }
  6166. else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } }
  6167. }
  6168. // W4. A single European separator between two European numbers
  6169. // changes to a European number. A single common separator between
  6170. // two numbers of the same type changes to that type.
  6171. for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
  6172. var type$2 = types[i$3];
  6173. if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; }
  6174. else if (type$2 == "," && prev$1 == types[i$3+1] &&
  6175. (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; }
  6176. prev$1 = type$2;
  6177. }
  6178. // W5. A sequence of European terminators adjacent to European
  6179. // numbers changes to all European numbers.
  6180. // W6. Otherwise, separators and terminators change to Other
  6181. // Neutral.
  6182. for (var i$4 = 0; i$4 < len; ++i$4) {
  6183. var type$3 = types[i$4];
  6184. if (type$3 == ",") { types[i$4] = "N"; }
  6185. else if (type$3 == "%") {
  6186. var end = (void 0);
  6187. for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
  6188. var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
  6189. for (var j = i$4; j < end; ++j) { types[j] = replace; }
  6190. i$4 = end - 1;
  6191. }
  6192. }
  6193. // W7. Search backwards from each instance of a European number
  6194. // until the first strong type (R, L, or sor) is found. If an L is
  6195. // found, then change the type of the European number to L.
  6196. for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
  6197. var type$4 = types[i$5];
  6198. if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; }
  6199. else if (isStrong.test(type$4)) { cur$1 = type$4; }
  6200. }
  6201. // N1. A sequence of neutrals takes the direction of the
  6202. // surrounding strong text if the text on both sides has the same
  6203. // direction. European and Arabic numbers act as if they were R in
  6204. // terms of their influence on neutrals. Start-of-level-run (sor)
  6205. // and end-of-level-run (eor) are used at level run boundaries.
  6206. // N2. Any remaining neutrals take the embedding direction.
  6207. for (var i$6 = 0; i$6 < len; ++i$6) {
  6208. if (isNeutral.test(types[i$6])) {
  6209. var end$1 = (void 0);
  6210. for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
  6211. var before = (i$6 ? types[i$6-1] : outerType) == "L";
  6212. var after = (end$1 < len ? types[end$1] : outerType) == "L";
  6213. var replace$1 = before == after ? (before ? "L" : "R") : outerType;
  6214. for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; }
  6215. i$6 = end$1 - 1;
  6216. }
  6217. }
  6218. // Here we depart from the documented algorithm, in order to avoid
  6219. // building up an actual levels array. Since there are only three
  6220. // levels (0, 1, 2) in an implementation that doesn't take
  6221. // explicit embedding into account, we can build up the order on
  6222. // the fly, without following the level-based algorithm.
  6223. var order = [], m;
  6224. for (var i$7 = 0; i$7 < len;) {
  6225. if (countsAsLeft.test(types[i$7])) {
  6226. var start = i$7;
  6227. for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
  6228. order.push(new BidiSpan(0, start, i$7));
  6229. } else {
  6230. var pos = i$7, at = order.length, isRTL = direction == "rtl" ? 1 : 0;
  6231. for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
  6232. for (var j$2 = pos; j$2 < i$7;) {
  6233. if (countsAsNum.test(types[j$2])) {
  6234. if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); at += isRTL; }
  6235. var nstart = j$2;
  6236. for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
  6237. order.splice(at, 0, new BidiSpan(2, nstart, j$2));
  6238. at += isRTL;
  6239. pos = j$2;
  6240. } else { ++j$2; }
  6241. }
  6242. if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); }
  6243. }
  6244. }
  6245. if (direction == "ltr") {
  6246. if (order[0].level == 1 && (m = str.match(/^\s+/))) {
  6247. order[0].from = m[0].length;
  6248. order.unshift(new BidiSpan(0, 0, m[0].length));
  6249. }
  6250. if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
  6251. lst(order).to -= m[0].length;
  6252. order.push(new BidiSpan(0, len - m[0].length, len));
  6253. }
  6254. }
  6255. return direction == "rtl" ? order.reverse() : order
  6256. }
  6257. })();
  6258. // Get the bidi ordering for the given line (and cache it). Returns
  6259. // false for lines that are fully left-to-right, and an array of
  6260. // BidiSpan objects otherwise.
  6261. function getOrder(line, direction) {
  6262. var order = line.order;
  6263. if (order == null) { order = line.order = bidiOrdering(line.text, direction); }
  6264. return order
  6265. }
  6266. // EVENT HANDLING
  6267. // Lightweight event framework. on/off also work on DOM nodes,
  6268. // registering native DOM handlers.
  6269. var noHandlers = [];
  6270. var on = function(emitter, type, f) {
  6271. if (emitter.addEventListener) {
  6272. emitter.addEventListener(type, f, false);
  6273. } else if (emitter.attachEvent) {
  6274. emitter.attachEvent("on" + type, f);
  6275. } else {
  6276. var map = emitter._handlers || (emitter._handlers = {});
  6277. map[type] = (map[type] || noHandlers).concat(f);
  6278. }
  6279. };
  6280. function getHandlers(emitter, type) {
  6281. return emitter._handlers && emitter._handlers[type] || noHandlers
  6282. }
  6283. function off(emitter, type, f) {
  6284. if (emitter.removeEventListener) {
  6285. emitter.removeEventListener(type, f, false);
  6286. } else if (emitter.detachEvent) {
  6287. emitter.detachEvent("on" + type, f);
  6288. } else {
  6289. var map = emitter._handlers, arr = map && map[type];
  6290. if (arr) {
  6291. var index = indexOf(arr, f);
  6292. if (index > -1)
  6293. { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)); }
  6294. }
  6295. }
  6296. }
  6297. function signal(emitter, type /*, values...*/) {
  6298. var handlers = getHandlers(emitter, type);
  6299. if (!handlers.length) { return }
  6300. var args = Array.prototype.slice.call(arguments, 2);
  6301. for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); }
  6302. }
  6303. // The DOM events that CodeMirror handles can be overridden by
  6304. // registering a (non-DOM) handler on the editor for the event name,
  6305. // and preventDefault-ing the event in that handler.
  6306. function signalDOMEvent(cm, e, override) {
  6307. if (typeof e == "string")
  6308. { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; }
  6309. signal(cm, override || e.type, cm, e);
  6310. return e_defaultPrevented(e) || e.codemirrorIgnore
  6311. }
  6312. function signalCursorActivity(cm) {
  6313. var arr = cm._handlers && cm._handlers.cursorActivity;
  6314. if (!arr) { return }
  6315. var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
  6316. for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
  6317. { set.push(arr[i]); } }
  6318. }
  6319. function hasHandler(emitter, type) {
  6320. return getHandlers(emitter, type).length > 0
  6321. }
  6322. // Add on and off methods to a constructor's prototype, to make
  6323. // registering events on such objects more convenient.
  6324. function eventMixin(ctor) {
  6325. ctor.prototype.on = function(type, f) {on(this, type, f);};
  6326. ctor.prototype.off = function(type, f) {off(this, type, f);};
  6327. }
  6328. // Due to the fact that we still support jurassic IE versions, some
  6329. // compatibility wrappers are needed.
  6330. function e_preventDefault(e) {
  6331. if (e.preventDefault) { e.preventDefault(); }
  6332. else { e.returnValue = false; }
  6333. }
  6334. function e_stopPropagation(e) {
  6335. if (e.stopPropagation) { e.stopPropagation(); }
  6336. else { e.cancelBubble = true; }
  6337. }
  6338. function e_defaultPrevented(e) {
  6339. return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
  6340. }
  6341. function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
  6342. function e_target(e) {return e.target || e.srcElement}
  6343. function e_button(e) {
  6344. var b = e.which;
  6345. if (b == null) {
  6346. if (e.button & 1) { b = 1; }
  6347. else if (e.button & 2) { b = 3; }
  6348. else if (e.button & 4) { b = 2; }
  6349. }
  6350. if (mac && e.ctrlKey && b == 1) { b = 3; }
  6351. return b
  6352. }
  6353. // Detect drag-and-drop
  6354. var dragAndDrop = function() {
  6355. // There is *some* kind of drag-and-drop support in IE6-8, but I
  6356. // couldn't get it to work yet.
  6357. if (ie && ie_version < 9) { return false }
  6358. var div = elt('div');
  6359. return "draggable" in div || "dragDrop" in div
  6360. }();
  6361. var zwspSupported;
  6362. function zeroWidthElement(measure) {
  6363. if (zwspSupported == null) {
  6364. var test = elt("span", "\u200b");
  6365. removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
  6366. if (measure.firstChild.offsetHeight != 0)
  6367. { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); }
  6368. }
  6369. var node = zwspSupported ? elt("span", "\u200b") :
  6370. elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
  6371. node.setAttribute("cm-text", "");
  6372. return node
  6373. }
  6374. // Feature-detect IE's crummy client rect reporting for bidi text
  6375. var badBidiRects;
  6376. function hasBadBidiRects(measure) {
  6377. if (badBidiRects != null) { return badBidiRects }
  6378. var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
  6379. var r0 = range(txt, 0, 1).getBoundingClientRect();
  6380. var r1 = range(txt, 1, 2).getBoundingClientRect();
  6381. removeChildren(measure);
  6382. if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
  6383. return badBidiRects = (r1.right - r0.right < 3)
  6384. }
  6385. // See if "".split is the broken IE version, if so, provide an
  6386. // alternative way to split lines.
  6387. var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
  6388. var pos = 0, result = [], l = string.length;
  6389. while (pos <= l) {
  6390. var nl = string.indexOf("\n", pos);
  6391. if (nl == -1) { nl = string.length; }
  6392. var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
  6393. var rt = line.indexOf("\r");
  6394. if (rt != -1) {
  6395. result.push(line.slice(0, rt));
  6396. pos += rt + 1;
  6397. } else {
  6398. result.push(line);
  6399. pos = nl + 1;
  6400. }
  6401. }
  6402. return result
  6403. } : function (string) { return string.split(/\r\n?|\n/); };
  6404. var hasSelection = window.getSelection ? function (te) {
  6405. try { return te.selectionStart != te.selectionEnd }
  6406. catch(e) { return false }
  6407. } : function (te) {
  6408. var range;
  6409. try {range = te.ownerDocument.selection.createRange();}
  6410. catch(e) {}
  6411. if (!range || range.parentElement() != te) { return false }
  6412. return range.compareEndPoints("StartToEnd", range) != 0
  6413. };
  6414. var hasCopyEvent = (function () {
  6415. var e = elt("div");
  6416. if ("oncopy" in e) { return true }
  6417. e.setAttribute("oncopy", "return;");
  6418. return typeof e.oncopy == "function"
  6419. })();
  6420. var badZoomedRects = null;
  6421. function hasBadZoomedRects(measure) {
  6422. if (badZoomedRects != null) { return badZoomedRects }
  6423. var node = removeChildrenAndAdd(measure, elt("span", "x"));
  6424. var normal = node.getBoundingClientRect();
  6425. var fromRange = range(node, 0, 1).getBoundingClientRect();
  6426. return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
  6427. }
  6428. // Known modes, by name and by MIME
  6429. var modes = {}, mimeModes = {};
  6430. // Extra arguments are stored as the mode's dependencies, which is
  6431. // used by (legacy) mechanisms like loadmode.js to automatically
  6432. // load a mode. (Preferred mechanism is the require/define calls.)
  6433. function defineMode(name, mode) {
  6434. if (arguments.length > 2)
  6435. { mode.dependencies = Array.prototype.slice.call(arguments, 2); }
  6436. modes[name] = mode;
  6437. }
  6438. function defineMIME(mime, spec) {
  6439. mimeModes[mime] = spec;
  6440. }
  6441. // Given a MIME type, a {name, ...options} config object, or a name
  6442. // string, return a mode config object.
  6443. function resolveMode(spec) {
  6444. if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
  6445. spec = mimeModes[spec];
  6446. } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
  6447. var found = mimeModes[spec.name];
  6448. if (typeof found == "string") { found = {name: found}; }
  6449. spec = createObj(found, spec);
  6450. spec.name = found.name;
  6451. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
  6452. return resolveMode("application/xml")
  6453. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
  6454. return resolveMode("application/json")
  6455. }
  6456. if (typeof spec == "string") { return {name: spec} }
  6457. else { return spec || {name: "null"} }
  6458. }
  6459. // Given a mode spec (anything that resolveMode accepts), find and
  6460. // initialize an actual mode object.
  6461. function getMode(options, spec) {
  6462. spec = resolveMode(spec);
  6463. var mfactory = modes[spec.name];
  6464. if (!mfactory) { return getMode(options, "text/plain") }
  6465. var modeObj = mfactory(options, spec);
  6466. if (modeExtensions.hasOwnProperty(spec.name)) {
  6467. var exts = modeExtensions[spec.name];
  6468. for (var prop in exts) {
  6469. if (!exts.hasOwnProperty(prop)) { continue }
  6470. if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
  6471. modeObj[prop] = exts[prop];
  6472. }
  6473. }
  6474. modeObj.name = spec.name;
  6475. if (spec.helperType) { modeObj.helperType = spec.helperType; }
  6476. if (spec.modeProps) { for (var prop$1 in spec.modeProps)
  6477. { modeObj[prop$1] = spec.modeProps[prop$1]; } }
  6478. return modeObj
  6479. }
  6480. // This can be used to attach properties to mode objects from
  6481. // outside the actual mode definition.
  6482. var modeExtensions = {};
  6483. function extendMode(mode, properties) {
  6484. var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
  6485. copyObj(properties, exts);
  6486. }
  6487. function copyState(mode, state) {
  6488. if (state === true) { return state }
  6489. if (mode.copyState) { return mode.copyState(state) }
  6490. var nstate = {};
  6491. for (var n in state) {
  6492. var val = state[n];
  6493. if (val instanceof Array) { val = val.concat([]); }
  6494. nstate[n] = val;
  6495. }
  6496. return nstate
  6497. }
  6498. // Given a mode and a state (for that mode), find the inner mode and
  6499. // state at the position that the state refers to.
  6500. function innerMode(mode, state) {
  6501. var info;
  6502. while (mode.innerMode) {
  6503. info = mode.innerMode(state);
  6504. if (!info || info.mode == mode) { break }
  6505. state = info.state;
  6506. mode = info.mode;
  6507. }
  6508. return info || {mode: mode, state: state}
  6509. }
  6510. function startState(mode, a1, a2) {
  6511. return mode.startState ? mode.startState(a1, a2) : true
  6512. }
  6513. // STRING STREAM
  6514. // Fed to the mode parsers, provides helper functions to make
  6515. // parsers more succinct.
  6516. var StringStream = function(string, tabSize, lineOracle) {
  6517. this.pos = this.start = 0;
  6518. this.string = string;
  6519. this.tabSize = tabSize || 8;
  6520. this.lastColumnPos = this.lastColumnValue = 0;
  6521. this.lineStart = 0;
  6522. this.lineOracle = lineOracle;
  6523. };
  6524. StringStream.prototype.eol = function () {return this.pos >= this.string.length};
  6525. StringStream.prototype.sol = function () {return this.pos == this.lineStart};
  6526. StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
  6527. StringStream.prototype.next = function () {
  6528. if (this.pos < this.string.length)
  6529. { return this.string.charAt(this.pos++) }
  6530. };
  6531. StringStream.prototype.eat = function (match) {
  6532. var ch = this.string.charAt(this.pos);
  6533. var ok;
  6534. if (typeof match == "string") { ok = ch == match; }
  6535. else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
  6536. if (ok) {++this.pos; return ch}
  6537. };
  6538. StringStream.prototype.eatWhile = function (match) {
  6539. var start = this.pos;
  6540. while (this.eat(match)){}
  6541. return this.pos > start
  6542. };
  6543. StringStream.prototype.eatSpace = function () {
  6544. var start = this.pos;
  6545. while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; }
  6546. return this.pos > start
  6547. };
  6548. StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
  6549. StringStream.prototype.skipTo = function (ch) {
  6550. var found = this.string.indexOf(ch, this.pos);
  6551. if (found > -1) {this.pos = found; return true}
  6552. };
  6553. StringStream.prototype.backUp = function (n) {this.pos -= n;};
  6554. StringStream.prototype.column = function () {
  6555. if (this.lastColumnPos < this.start) {
  6556. this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
  6557. this.lastColumnPos = this.start;
  6558. }
  6559. return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
  6560. };
  6561. StringStream.prototype.indentation = function () {
  6562. return countColumn(this.string, null, this.tabSize) -
  6563. (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
  6564. };
  6565. StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
  6566. if (typeof pattern == "string") {
  6567. var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
  6568. var substr = this.string.substr(this.pos, pattern.length);
  6569. if (cased(substr) == cased(pattern)) {
  6570. if (consume !== false) { this.pos += pattern.length; }
  6571. return true
  6572. }
  6573. } else {
  6574. var match = this.string.slice(this.pos).match(pattern);
  6575. if (match && match.index > 0) { return null }
  6576. if (match && consume !== false) { this.pos += match[0].length; }
  6577. return match
  6578. }
  6579. };
  6580. StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
  6581. StringStream.prototype.hideFirstChars = function (n, inner) {
  6582. this.lineStart += n;
  6583. try { return inner() }
  6584. finally { this.lineStart -= n; }
  6585. };
  6586. StringStream.prototype.lookAhead = function (n) {
  6587. var oracle = this.lineOracle;
  6588. return oracle && oracle.lookAhead(n)
  6589. };
  6590. StringStream.prototype.baseToken = function () {
  6591. var oracle = this.lineOracle;
  6592. return oracle && oracle.baseToken(this.pos)
  6593. };
  6594. // Find the line object corresponding to the given line number.
  6595. function getLine(doc, n) {
  6596. n -= doc.first;
  6597. if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
  6598. var chunk = doc;
  6599. while (!chunk.lines) {
  6600. for (var i = 0;; ++i) {
  6601. var child = chunk.children[i], sz = child.chunkSize();
  6602. if (n < sz) { chunk = child; break }
  6603. n -= sz;
  6604. }
  6605. }
  6606. return chunk.lines[n]
  6607. }
  6608. // Get the part of a document between two positions, as an array of
  6609. // strings.
  6610. function getBetween(doc, start, end) {
  6611. var out = [], n = start.line;
  6612. doc.iter(start.line, end.line + 1, function (line) {
  6613. var text = line.text;
  6614. if (n == end.line) { text = text.slice(0, end.ch); }
  6615. if (n == start.line) { text = text.slice(start.ch); }
  6616. out.push(text);
  6617. ++n;
  6618. });
  6619. return out
  6620. }
  6621. // Get the lines between from and to, as array of strings.
  6622. function getLines(doc, from, to) {
  6623. var out = [];
  6624. doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value
  6625. return out
  6626. }
  6627. // Update the height of a line, propagating the height change
  6628. // upwards to parent nodes.
  6629. function updateLineHeight(line, height) {
  6630. var diff = height - line.height;
  6631. if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } }
  6632. }
  6633. // Given a line object, find its line number by walking up through
  6634. // its parent links.
  6635. function lineNo(line) {
  6636. if (line.parent == null) { return null }
  6637. var cur = line.parent, no = indexOf(cur.lines, line);
  6638. for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
  6639. for (var i = 0;; ++i) {
  6640. if (chunk.children[i] == cur) { break }
  6641. no += chunk.children[i].chunkSize();
  6642. }
  6643. }
  6644. return no + cur.first
  6645. }
  6646. // Find the line at the given vertical position, using the height
  6647. // information in the document tree.
  6648. function lineAtHeight(chunk, h) {
  6649. var n = chunk.first;
  6650. outer: do {
  6651. for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
  6652. var child = chunk.children[i$1], ch = child.height;
  6653. if (h < ch) { chunk = child; continue outer }
  6654. h -= ch;
  6655. n += child.chunkSize();
  6656. }
  6657. return n
  6658. } while (!chunk.lines)
  6659. var i = 0;
  6660. for (; i < chunk.lines.length; ++i) {
  6661. var line = chunk.lines[i], lh = line.height;
  6662. if (h < lh) { break }
  6663. h -= lh;
  6664. }
  6665. return n + i
  6666. }
  6667. function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
  6668. function lineNumberFor(options, i) {
  6669. return String(options.lineNumberFormatter(i + options.firstLineNumber))
  6670. }
  6671. // A Pos instance represents a position within the text.
  6672. function Pos(line, ch, sticky) {
  6673. if ( sticky === void 0 ) sticky = null;
  6674. if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
  6675. this.line = line;
  6676. this.ch = ch;
  6677. this.sticky = sticky;
  6678. }
  6679. // Compare two positions, return 0 if they are the same, a negative
  6680. // number when a is less, and a positive number otherwise.
  6681. function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
  6682. function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
  6683. function copyPos(x) {return Pos(x.line, x.ch)}
  6684. function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
  6685. function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
  6686. // Most of the external API clips given positions to make sure they
  6687. // actually exist within the document.
  6688. function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
  6689. function clipPos(doc, pos) {
  6690. if (pos.line < doc.first) { return Pos(doc.first, 0) }
  6691. var last = doc.first + doc.size - 1;
  6692. if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
  6693. return clipToLen(pos, getLine(doc, pos.line).text.length)
  6694. }
  6695. function clipToLen(pos, linelen) {
  6696. var ch = pos.ch;
  6697. if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
  6698. else if (ch < 0) { return Pos(pos.line, 0) }
  6699. else { return pos }
  6700. }
  6701. function clipPosArray(doc, array) {
  6702. var out = [];
  6703. for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); }
  6704. return out
  6705. }
  6706. var SavedContext = function(state, lookAhead) {
  6707. this.state = state;
  6708. this.lookAhead = lookAhead;
  6709. };
  6710. var Context = function(doc, state, line, lookAhead) {
  6711. this.state = state;
  6712. this.doc = doc;
  6713. this.line = line;
  6714. this.maxLookAhead = lookAhead || 0;
  6715. this.baseTokens = null;
  6716. this.baseTokenPos = 1;
  6717. };
  6718. Context.prototype.lookAhead = function (n) {
  6719. var line = this.doc.getLine(this.line + n);
  6720. if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n; }
  6721. return line
  6722. };
  6723. Context.prototype.baseToken = function (n) {
  6724. if (!this.baseTokens) { return null }
  6725. while (this.baseTokens[this.baseTokenPos] <= n)
  6726. { this.baseTokenPos += 2; }
  6727. var type = this.baseTokens[this.baseTokenPos + 1];
  6728. return {type: type && type.replace(/( |^)overlay .*/, ""),
  6729. size: this.baseTokens[this.baseTokenPos] - n}
  6730. };
  6731. Context.prototype.nextLine = function () {
  6732. this.line++;
  6733. if (this.maxLookAhead > 0) { this.maxLookAhead--; }
  6734. };
  6735. Context.fromSaved = function (doc, saved, line) {
  6736. if (saved instanceof SavedContext)
  6737. { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
  6738. else
  6739. { return new Context(doc, copyState(doc.mode, saved), line) }
  6740. };
  6741. Context.prototype.save = function (copy) {
  6742. var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
  6743. return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
  6744. };
  6745. // Compute a style array (an array starting with a mode generation
  6746. // -- for invalidation -- followed by pairs of end positions and
  6747. // style strings), which is used to highlight the tokens on the
  6748. // line.
  6749. function highlightLine(cm, line, context, forceToEnd) {
  6750. // A styles array always starts with a number identifying the
  6751. // mode/overlays that it is based on (for easy invalidation).
  6752. var st = [cm.state.modeGen], lineClasses = {};
  6753. // Compute the base array of styles
  6754. runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
  6755. lineClasses, forceToEnd);
  6756. var state = context.state;
  6757. // Run overlays, adjust style array.
  6758. var loop = function ( o ) {
  6759. context.baseTokens = st;
  6760. var overlay = cm.state.overlays[o], i = 1, at = 0;
  6761. context.state = true;
  6762. runMode(cm, line.text, overlay.mode, context, function (end, style) {
  6763. var start = i;
  6764. // Ensure there's a token end at the current position, and that i points at it
  6765. while (at < end) {
  6766. var i_end = st[i];
  6767. if (i_end > end)
  6768. { st.splice(i, 1, end, st[i+1], i_end); }
  6769. i += 2;
  6770. at = Math.min(end, i_end);
  6771. }
  6772. if (!style) { return }
  6773. if (overlay.opaque) {
  6774. st.splice(start, i - start, end, "overlay " + style);
  6775. i = start + 2;
  6776. } else {
  6777. for (; start < i; start += 2) {
  6778. var cur = st[start+1];
  6779. st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
  6780. }
  6781. }
  6782. }, lineClasses);
  6783. context.state = state;
  6784. context.baseTokens = null;
  6785. context.baseTokenPos = 1;
  6786. };
  6787. for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
  6788. return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
  6789. }
  6790. function getLineStyles(cm, line, updateFrontier) {
  6791. if (!line.styles || line.styles[0] != cm.state.modeGen) {
  6792. var context = getContextBefore(cm, lineNo(line));
  6793. var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
  6794. var result = highlightLine(cm, line, context);
  6795. if (resetState) { context.state = resetState; }
  6796. line.stateAfter = context.save(!resetState);
  6797. line.styles = result.styles;
  6798. if (result.classes) { line.styleClasses = result.classes; }
  6799. else if (line.styleClasses) { line.styleClasses = null; }
  6800. if (updateFrontier === cm.doc.highlightFrontier)
  6801. { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier); }
  6802. }
  6803. return line.styles
  6804. }
  6805. function getContextBefore(cm, n, precise) {
  6806. var doc = cm.doc, display = cm.display;
  6807. if (!doc.mode.startState) { return new Context(doc, true, n) }
  6808. var start = findStartLine(cm, n, precise);
  6809. var saved = start > doc.first && getLine(doc, start - 1).stateAfter;
  6810. var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);
  6811. doc.iter(start, n, function (line) {
  6812. processLine(cm, line.text, context);
  6813. var pos = context.line;
  6814. line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
  6815. context.nextLine();
  6816. });
  6817. if (precise) { doc.modeFrontier = context.line; }
  6818. return context
  6819. }
  6820. // Lightweight form of highlight -- proceed over this line and
  6821. // update state, but don't save a style array. Used for lines that
  6822. // aren't currently visible.
  6823. function processLine(cm, text, context, startAt) {
  6824. var mode = cm.doc.mode;
  6825. var stream = new StringStream(text, cm.options.tabSize, context);
  6826. stream.start = stream.pos = startAt || 0;
  6827. if (text == "") { callBlankLine(mode, context.state); }
  6828. while (!stream.eol()) {
  6829. readToken(mode, stream, context.state);
  6830. stream.start = stream.pos;
  6831. }
  6832. }
  6833. function callBlankLine(mode, state) {
  6834. if (mode.blankLine) { return mode.blankLine(state) }
  6835. if (!mode.innerMode) { return }
  6836. var inner = innerMode(mode, state);
  6837. if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
  6838. }
  6839. function readToken(mode, stream, state, inner) {
  6840. for (var i = 0; i < 10; i++) {
  6841. if (inner) { inner[0] = innerMode(mode, state).mode; }
  6842. var style = mode.token(stream, state);
  6843. if (stream.pos > stream.start) { return style }
  6844. }
  6845. throw new Error("Mode " + mode.name + " failed to advance stream.")
  6846. }
  6847. var Token = function(stream, type, state) {
  6848. this.start = stream.start; this.end = stream.pos;
  6849. this.string = stream.current();
  6850. this.type = type || null;
  6851. this.state = state;
  6852. };
  6853. // Utility for getTokenAt and getLineTokens
  6854. function takeToken(cm, pos, precise, asArray) {
  6855. var doc = cm.doc, mode = doc.mode, style;
  6856. pos = clipPos(doc, pos);
  6857. var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise);
  6858. var stream = new StringStream(line.text, cm.options.tabSize, context), tokens;
  6859. if (asArray) { tokens = []; }
  6860. while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
  6861. stream.start = stream.pos;
  6862. style = readToken(mode, stream, context.state);
  6863. if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))); }
  6864. }
  6865. return asArray ? tokens : new Token(stream, style, context.state)
  6866. }
  6867. function extractLineClasses(type, output) {
  6868. if (type) { for (;;) {
  6869. var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
  6870. if (!lineClass) { break }
  6871. type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
  6872. var prop = lineClass[1] ? "bgClass" : "textClass";
  6873. if (output[prop] == null)
  6874. { output[prop] = lineClass[2]; }
  6875. else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
  6876. { output[prop] += " " + lineClass[2]; }
  6877. } }
  6878. return type
  6879. }
  6880. // Run the given mode's parser over a line, calling f for each token.
  6881. function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
  6882. var flattenSpans = mode.flattenSpans;
  6883. if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; }
  6884. var curStart = 0, curStyle = null;
  6885. var stream = new StringStream(text, cm.options.tabSize, context), style;
  6886. var inner = cm.options.addModeClass && [null];
  6887. if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses); }
  6888. while (!stream.eol()) {
  6889. if (stream.pos > cm.options.maxHighlightLength) {
  6890. flattenSpans = false;
  6891. if (forceToEnd) { processLine(cm, text, context, stream.pos); }
  6892. stream.pos = text.length;
  6893. style = null;
  6894. } else {
  6895. style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
  6896. }
  6897. if (inner) {
  6898. var mName = inner[0].name;
  6899. if (mName) { style = "m-" + (style ? mName + " " + style : mName); }
  6900. }
  6901. if (!flattenSpans || curStyle != style) {
  6902. while (curStart < stream.start) {
  6903. curStart = Math.min(stream.start, curStart + 5000);
  6904. f(curStart, curStyle);
  6905. }
  6906. curStyle = style;
  6907. }
  6908. stream.start = stream.pos;
  6909. }
  6910. while (curStart < stream.pos) {
  6911. // Webkit seems to refuse to render text nodes longer than 57444
  6912. // characters, and returns inaccurate measurements in nodes
  6913. // starting around 5000 chars.
  6914. var pos = Math.min(stream.pos, curStart + 5000);
  6915. f(pos, curStyle);
  6916. curStart = pos;
  6917. }
  6918. }
  6919. // Finds the line to start with when starting a parse. Tries to
  6920. // find a line with a stateAfter, so that it can start with a
  6921. // valid state. If that fails, it returns the line with the
  6922. // smallest indentation, which tends to need the least context to
  6923. // parse correctly.
  6924. function findStartLine(cm, n, precise) {
  6925. var minindent, minline, doc = cm.doc;
  6926. var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
  6927. for (var search = n; search > lim; --search) {
  6928. if (search <= doc.first) { return doc.first }
  6929. var line = getLine(doc, search - 1), after = line.stateAfter;
  6930. if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
  6931. { return search }
  6932. var indented = countColumn(line.text, null, cm.options.tabSize);
  6933. if (minline == null || minindent > indented) {
  6934. minline = search - 1;
  6935. minindent = indented;
  6936. }
  6937. }
  6938. return minline
  6939. }
  6940. function retreatFrontier(doc, n) {
  6941. doc.modeFrontier = Math.min(doc.modeFrontier, n);
  6942. if (doc.highlightFrontier < n - 10) { return }
  6943. var start = doc.first;
  6944. for (var line = n - 1; line > start; line--) {
  6945. var saved = getLine(doc, line).stateAfter;
  6946. // change is on 3
  6947. // state on line 1 looked ahead 2 -- so saw 3
  6948. // test 1 + 2 < 3 should cover this
  6949. if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
  6950. start = line + 1;
  6951. break
  6952. }
  6953. }
  6954. doc.highlightFrontier = Math.min(doc.highlightFrontier, start);
  6955. }
  6956. // Optimize some code when these features are not used.
  6957. var sawReadOnlySpans = false, sawCollapsedSpans = false;
  6958. function seeReadOnlySpans() {
  6959. sawReadOnlySpans = true;
  6960. }
  6961. function seeCollapsedSpans() {
  6962. sawCollapsedSpans = true;
  6963. }
  6964. // TEXTMARKER SPANS
  6965. function MarkedSpan(marker, from, to) {
  6966. this.marker = marker;
  6967. this.from = from; this.to = to;
  6968. }
  6969. // Search an array of spans for a span matching the given marker.
  6970. function getMarkedSpanFor(spans, marker) {
  6971. if (spans) { for (var i = 0; i < spans.length; ++i) {
  6972. var span = spans[i];
  6973. if (span.marker == marker) { return span }
  6974. } }
  6975. }
  6976. // Remove a span from an array, returning undefined if no spans are
  6977. // left (we don't store arrays for lines without spans).
  6978. function removeMarkedSpan(spans, span) {
  6979. var r;
  6980. for (var i = 0; i < spans.length; ++i)
  6981. { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } }
  6982. return r
  6983. }
  6984. // Add a span to a line.
  6985. function addMarkedSpan(line, span) {
  6986. line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
  6987. span.marker.attachLine(line);
  6988. }
  6989. // Used for the algorithm that adjusts markers for a change in the
  6990. // document. These functions cut an array of spans at a given
  6991. // character position, returning an array of remaining chunks (or
  6992. // undefined if nothing remains).
  6993. function markedSpansBefore(old, startCh, isInsert) {
  6994. var nw;
  6995. if (old) { for (var i = 0; i < old.length; ++i) {
  6996. var span = old[i], marker = span.marker;
  6997. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
  6998. if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
  6999. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
  7000. ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
  7001. }
  7002. } }
  7003. return nw
  7004. }
  7005. function markedSpansAfter(old, endCh, isInsert) {
  7006. var nw;
  7007. if (old) { for (var i = 0; i < old.length; ++i) {
  7008. var span = old[i], marker = span.marker;
  7009. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
  7010. if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
  7011. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
  7012. ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
  7013. span.to == null ? null : span.to - endCh));
  7014. }
  7015. } }
  7016. return nw
  7017. }
  7018. // Given a change object, compute the new set of marker spans that
  7019. // cover the line in which the change took place. Removes spans
  7020. // entirely within the change, reconnects spans belonging to the
  7021. // same marker that appear on both sides of the change, and cuts off
  7022. // spans partially within the change. Returns an array of span
  7023. // arrays with one element for each line in (after) the change.
  7024. function stretchSpansOverChange(doc, change) {
  7025. if (change.full) { return null }
  7026. var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
  7027. var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
  7028. if (!oldFirst && !oldLast) { return null }
  7029. var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
  7030. // Get the spans that 'stick out' on both sides
  7031. var first = markedSpansBefore(oldFirst, startCh, isInsert);
  7032. var last = markedSpansAfter(oldLast, endCh, isInsert);
  7033. // Next, merge those two ends
  7034. var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
  7035. if (first) {
  7036. // Fix up .to properties of first
  7037. for (var i = 0; i < first.length; ++i) {
  7038. var span = first[i];
  7039. if (span.to == null) {
  7040. var found = getMarkedSpanFor(last, span.marker);
  7041. if (!found) { span.to = startCh; }
  7042. else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
  7043. }
  7044. }
  7045. }
  7046. if (last) {
  7047. // Fix up .from in last (or move them into first in case of sameLine)
  7048. for (var i$1 = 0; i$1 < last.length; ++i$1) {
  7049. var span$1 = last[i$1];
  7050. if (span$1.to != null) { span$1.to += offset; }
  7051. if (span$1.from == null) {
  7052. var found$1 = getMarkedSpanFor(first, span$1.marker);
  7053. if (!found$1) {
  7054. span$1.from = offset;
  7055. if (sameLine) { (first || (first = [])).push(span$1); }
  7056. }
  7057. } else {
  7058. span$1.from += offset;
  7059. if (sameLine) { (first || (first = [])).push(span$1); }
  7060. }
  7061. }
  7062. }
  7063. // Make sure we didn't create any zero-length spans
  7064. if (first) { first = clearEmptySpans(first); }
  7065. if (last && last != first) { last = clearEmptySpans(last); }
  7066. var newMarkers = [first];
  7067. if (!sameLine) {
  7068. // Fill gap with whole-line-spans
  7069. var gap = change.text.length - 2, gapMarkers;
  7070. if (gap > 0 && first)
  7071. { for (var i$2 = 0; i$2 < first.length; ++i$2)
  7072. { if (first[i$2].to == null)
  7073. { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
  7074. for (var i$3 = 0; i$3 < gap; ++i$3)
  7075. { newMarkers.push(gapMarkers); }
  7076. newMarkers.push(last);
  7077. }
  7078. return newMarkers
  7079. }
  7080. // Remove spans that are empty and don't have a clearWhenEmpty
  7081. // option of false.
  7082. function clearEmptySpans(spans) {
  7083. for (var i = 0; i < spans.length; ++i) {
  7084. var span = spans[i];
  7085. if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
  7086. { spans.splice(i--, 1); }
  7087. }
  7088. if (!spans.length) { return null }
  7089. return spans
  7090. }
  7091. // Used to 'clip' out readOnly ranges when making a change.
  7092. function removeReadOnlyRanges(doc, from, to) {
  7093. var markers = null;
  7094. doc.iter(from.line, to.line + 1, function (line) {
  7095. if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
  7096. var mark = line.markedSpans[i].marker;
  7097. if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
  7098. { (markers || (markers = [])).push(mark); }
  7099. } }
  7100. });
  7101. if (!markers) { return null }
  7102. var parts = [{from: from, to: to}];
  7103. for (var i = 0; i < markers.length; ++i) {
  7104. var mk = markers[i], m = mk.find(0);
  7105. for (var j = 0; j < parts.length; ++j) {
  7106. var p = parts[j];
  7107. if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
  7108. var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
  7109. if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
  7110. { newParts.push({from: p.from, to: m.from}); }
  7111. if (dto > 0 || !mk.inclusiveRight && !dto)
  7112. { newParts.push({from: m.to, to: p.to}); }
  7113. parts.splice.apply(parts, newParts);
  7114. j += newParts.length - 3;
  7115. }
  7116. }
  7117. return parts
  7118. }
  7119. // Connect or disconnect spans from a line.
  7120. function detachMarkedSpans(line) {
  7121. var spans = line.markedSpans;
  7122. if (!spans) { return }
  7123. for (var i = 0; i < spans.length; ++i)
  7124. { spans[i].marker.detachLine(line); }
  7125. line.markedSpans = null;
  7126. }
  7127. function attachMarkedSpans(line, spans) {
  7128. if (!spans) { return }
  7129. for (var i = 0; i < spans.length; ++i)
  7130. { spans[i].marker.attachLine(line); }
  7131. line.markedSpans = spans;
  7132. }
  7133. // Helpers used when computing which overlapping collapsed span
  7134. // counts as the larger one.
  7135. function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
  7136. function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
  7137. // Returns a number indicating which of two overlapping collapsed
  7138. // spans is larger (and thus includes the other). Falls back to
  7139. // comparing ids when the spans cover exactly the same range.
  7140. function compareCollapsedMarkers(a, b) {
  7141. var lenDiff = a.lines.length - b.lines.length;
  7142. if (lenDiff != 0) { return lenDiff }
  7143. var aPos = a.find(), bPos = b.find();
  7144. var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
  7145. if (fromCmp) { return -fromCmp }
  7146. var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
  7147. if (toCmp) { return toCmp }
  7148. return b.id - a.id
  7149. }
  7150. // Find out whether a line ends or starts in a collapsed span. If
  7151. // so, return the marker for that span.
  7152. function collapsedSpanAtSide(line, start) {
  7153. var sps = sawCollapsedSpans && line.markedSpans, found;
  7154. if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
  7155. sp = sps[i];
  7156. if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
  7157. (!found || compareCollapsedMarkers(found, sp.marker) < 0))
  7158. { found = sp.marker; }
  7159. } }
  7160. return found
  7161. }
  7162. function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
  7163. function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
  7164. function collapsedSpanAround(line, ch) {
  7165. var sps = sawCollapsedSpans && line.markedSpans, found;
  7166. if (sps) { for (var i = 0; i < sps.length; ++i) {
  7167. var sp = sps[i];
  7168. if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
  7169. (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker; }
  7170. } }
  7171. return found
  7172. }
  7173. // Test whether there exists a collapsed span that partially
  7174. // overlaps (covers the start or end, but not both) of a new span.
  7175. // Such overlap is not allowed.
  7176. function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
  7177. var line = getLine(doc, lineNo);
  7178. var sps = sawCollapsedSpans && line.markedSpans;
  7179. if (sps) { for (var i = 0; i < sps.length; ++i) {
  7180. var sp = sps[i];
  7181. if (!sp.marker.collapsed) { continue }
  7182. var found = sp.marker.find(0);
  7183. var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
  7184. var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
  7185. if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
  7186. if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
  7187. fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
  7188. { return true }
  7189. } }
  7190. }
  7191. // A visual line is a line as drawn on the screen. Folding, for
  7192. // example, can cause multiple logical lines to appear on the same
  7193. // visual line. This finds the start of the visual line that the
  7194. // given line is part of (usually that is the line itself).
  7195. function visualLine(line) {
  7196. var merged;
  7197. while (merged = collapsedSpanAtStart(line))
  7198. { line = merged.find(-1, true).line; }
  7199. return line
  7200. }
  7201. function visualLineEnd(line) {
  7202. var merged;
  7203. while (merged = collapsedSpanAtEnd(line))
  7204. { line = merged.find(1, true).line; }
  7205. return line
  7206. }
  7207. // Returns an array of logical lines that continue the visual line
  7208. // started by the argument, or undefined if there are no such lines.
  7209. function visualLineContinued(line) {
  7210. var merged, lines;
  7211. while (merged = collapsedSpanAtEnd(line)) {
  7212. line = merged.find(1, true).line
  7213. ;(lines || (lines = [])).push(line);
  7214. }
  7215. return lines
  7216. }
  7217. // Get the line number of the start of the visual line that the
  7218. // given line number is part of.
  7219. function visualLineNo(doc, lineN) {
  7220. var line = getLine(doc, lineN), vis = visualLine(line);
  7221. if (line == vis) { return lineN }
  7222. return lineNo(vis)
  7223. }
  7224. // Get the line number of the start of the next visual line after
  7225. // the given line.
  7226. function visualLineEndNo(doc, lineN) {
  7227. if (lineN > doc.lastLine()) { return lineN }
  7228. var line = getLine(doc, lineN), merged;
  7229. if (!lineIsHidden(doc, line)) { return lineN }
  7230. while (merged = collapsedSpanAtEnd(line))
  7231. { line = merged.find(1, true).line; }
  7232. return lineNo(line) + 1
  7233. }
  7234. // Compute whether a line is hidden. Lines count as hidden when they
  7235. // are part of a visual line that starts with another line, or when
  7236. // they are entirely covered by collapsed, non-widget span.
  7237. function lineIsHidden(doc, line) {
  7238. var sps = sawCollapsedSpans && line.markedSpans;
  7239. if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
  7240. sp = sps[i];
  7241. if (!sp.marker.collapsed) { continue }
  7242. if (sp.from == null) { return true }
  7243. if (sp.marker.widgetNode) { continue }
  7244. if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
  7245. { return true }
  7246. } }
  7247. }
  7248. function lineIsHiddenInner(doc, line, span) {
  7249. if (span.to == null) {
  7250. var end = span.marker.find(1, true);
  7251. return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
  7252. }
  7253. if (span.marker.inclusiveRight && span.to == line.text.length)
  7254. { return true }
  7255. for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
  7256. sp = line.markedSpans[i];
  7257. if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
  7258. (sp.to == null || sp.to != span.from) &&
  7259. (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
  7260. lineIsHiddenInner(doc, line, sp)) { return true }
  7261. }
  7262. }
  7263. // Find the height above the given line.
  7264. function heightAtLine(lineObj) {
  7265. lineObj = visualLine(lineObj);
  7266. var h = 0, chunk = lineObj.parent;
  7267. for (var i = 0; i < chunk.lines.length; ++i) {
  7268. var line = chunk.lines[i];
  7269. if (line == lineObj) { break }
  7270. else { h += line.height; }
  7271. }
  7272. for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
  7273. for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
  7274. var cur = p.children[i$1];
  7275. if (cur == chunk) { break }
  7276. else { h += cur.height; }
  7277. }
  7278. }
  7279. return h
  7280. }
  7281. // Compute the character length of a line, taking into account
  7282. // collapsed ranges (see markText) that might hide parts, and join
  7283. // other lines onto it.
  7284. function lineLength(line) {
  7285. if (line.height == 0) { return 0 }
  7286. var len = line.text.length, merged, cur = line;
  7287. while (merged = collapsedSpanAtStart(cur)) {
  7288. var found = merged.find(0, true);
  7289. cur = found.from.line;
  7290. len += found.from.ch - found.to.ch;
  7291. }
  7292. cur = line;
  7293. while (merged = collapsedSpanAtEnd(cur)) {
  7294. var found$1 = merged.find(0, true);
  7295. len -= cur.text.length - found$1.from.ch;
  7296. cur = found$1.to.line;
  7297. len += cur.text.length - found$1.to.ch;
  7298. }
  7299. return len
  7300. }
  7301. // Find the longest line in the document.
  7302. function findMaxLine(cm) {
  7303. var d = cm.display, doc = cm.doc;
  7304. d.maxLine = getLine(doc, doc.first);
  7305. d.maxLineLength = lineLength(d.maxLine);
  7306. d.maxLineChanged = true;
  7307. doc.iter(function (line) {
  7308. var len = lineLength(line);
  7309. if (len > d.maxLineLength) {
  7310. d.maxLineLength = len;
  7311. d.maxLine = line;
  7312. }
  7313. });
  7314. }
  7315. // LINE DATA STRUCTURE
  7316. // Line objects. These hold state related to a line, including
  7317. // highlighting info (the styles array).
  7318. var Line = function(text, markedSpans, estimateHeight) {
  7319. this.text = text;
  7320. attachMarkedSpans(this, markedSpans);
  7321. this.height = estimateHeight ? estimateHeight(this) : 1;
  7322. };
  7323. Line.prototype.lineNo = function () { return lineNo(this) };
  7324. eventMixin(Line);
  7325. // Change the content (text, markers) of a line. Automatically
  7326. // invalidates cached information and tries to re-estimate the
  7327. // line's height.
  7328. function updateLine(line, text, markedSpans, estimateHeight) {
  7329. line.text = text;
  7330. if (line.stateAfter) { line.stateAfter = null; }
  7331. if (line.styles) { line.styles = null; }
  7332. if (line.order != null) { line.order = null; }
  7333. detachMarkedSpans(line);
  7334. attachMarkedSpans(line, markedSpans);
  7335. var estHeight = estimateHeight ? estimateHeight(line) : 1;
  7336. if (estHeight != line.height) { updateLineHeight(line, estHeight); }
  7337. }
  7338. // Detach a line from the document tree and its markers.
  7339. function cleanUpLine(line) {
  7340. line.parent = null;
  7341. detachMarkedSpans(line);
  7342. }
  7343. // Convert a style as returned by a mode (either null, or a string
  7344. // containing one or more styles) to a CSS style. This is cached,
  7345. // and also looks for line-wide styles.
  7346. var styleToClassCache = {}, styleToClassCacheWithMode = {};
  7347. function interpretTokenStyle(style, options) {
  7348. if (!style || /^\s*$/.test(style)) { return null }
  7349. var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
  7350. return cache[style] ||
  7351. (cache[style] = style.replace(/\S+/g, "cm-$&"))
  7352. }
  7353. // Render the DOM representation of the text of a line. Also builds
  7354. // up a 'line map', which points at the DOM nodes that represent
  7355. // specific stretches of text, and is used by the measuring code.
  7356. // The returned object contains the DOM node, this map, and
  7357. // information about line-wide styles that were set by the mode.
  7358. function buildLineContent(cm, lineView) {
  7359. // The padding-right forces the element to have a 'border', which
  7360. // is needed on Webkit to be able to get line-level bounding
  7361. // rectangles for it (in measureChar).
  7362. var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
  7363. var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
  7364. col: 0, pos: 0, cm: cm,
  7365. trailingSpace: false,
  7366. splitSpaces: cm.getOption("lineWrapping")};
  7367. lineView.measure = {};
  7368. // Iterate over the logical lines that make up this visual line.
  7369. for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
  7370. var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0);
  7371. builder.pos = 0;
  7372. builder.addToken = buildToken;
  7373. // Optionally wire in some hacks into the token-rendering
  7374. // algorithm, to deal with browser quirks.
  7375. if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
  7376. { builder.addToken = buildTokenBadBidi(builder.addToken, order); }
  7377. builder.map = [];
  7378. var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
  7379. insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
  7380. if (line.styleClasses) {
  7381. if (line.styleClasses.bgClass)
  7382. { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); }
  7383. if (line.styleClasses.textClass)
  7384. { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); }
  7385. }
  7386. // Ensure at least a single node is present, for measuring.
  7387. if (builder.map.length == 0)
  7388. { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); }
  7389. // Store the map and a cache object for the current logical line
  7390. if (i == 0) {
  7391. lineView.measure.map = builder.map;
  7392. lineView.measure.cache = {};
  7393. } else {
  7394. (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
  7395. ;(lineView.measure.caches || (lineView.measure.caches = [])).push({});
  7396. }
  7397. }
  7398. // See issue #2901
  7399. if (webkit) {
  7400. var last = builder.content.lastChild;
  7401. if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
  7402. { builder.content.className = "cm-tab-wrap-hack"; }
  7403. }
  7404. signal(cm, "renderLine", cm, lineView.line, builder.pre);
  7405. if (builder.pre.className)
  7406. { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); }
  7407. return builder
  7408. }
  7409. function defaultSpecialCharPlaceholder(ch) {
  7410. var token = elt("span", "\u2022", "cm-invalidchar");
  7411. token.title = "\\u" + ch.charCodeAt(0).toString(16);
  7412. token.setAttribute("aria-label", token.title);
  7413. return token
  7414. }
  7415. // Build up the DOM representation for a single token, and add it to
  7416. // the line map. Takes care to render special characters separately.
  7417. function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
  7418. if (!text) { return }
  7419. var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
  7420. var special = builder.cm.state.specialChars, mustWrap = false;
  7421. var content;
  7422. if (!special.test(text)) {
  7423. builder.col += text.length;
  7424. content = document.createTextNode(displayText);
  7425. builder.map.push(builder.pos, builder.pos + text.length, content);
  7426. if (ie && ie_version < 9) { mustWrap = true; }
  7427. builder.pos += text.length;
  7428. } else {
  7429. content = document.createDocumentFragment();
  7430. var pos = 0;
  7431. while (true) {
  7432. special.lastIndex = pos;
  7433. var m = special.exec(text);
  7434. var skipped = m ? m.index - pos : text.length - pos;
  7435. if (skipped) {
  7436. var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
  7437. if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
  7438. else { content.appendChild(txt); }
  7439. builder.map.push(builder.pos, builder.pos + skipped, txt);
  7440. builder.col += skipped;
  7441. builder.pos += skipped;
  7442. }
  7443. if (!m) { break }
  7444. pos += skipped + 1;
  7445. var txt$1 = (void 0);
  7446. if (m[0] == "\t") {
  7447. var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
  7448. txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
  7449. txt$1.setAttribute("role", "presentation");
  7450. txt$1.setAttribute("cm-text", "\t");
  7451. builder.col += tabWidth;
  7452. } else if (m[0] == "\r" || m[0] == "\n") {
  7453. txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
  7454. txt$1.setAttribute("cm-text", m[0]);
  7455. builder.col += 1;
  7456. } else {
  7457. txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
  7458. txt$1.setAttribute("cm-text", m[0]);
  7459. if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
  7460. else { content.appendChild(txt$1); }
  7461. builder.col += 1;
  7462. }
  7463. builder.map.push(builder.pos, builder.pos + 1, txt$1);
  7464. builder.pos++;
  7465. }
  7466. }
  7467. builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
  7468. if (style || startStyle || endStyle || mustWrap || css) {
  7469. var fullStyle = style || "";
  7470. if (startStyle) { fullStyle += startStyle; }
  7471. if (endStyle) { fullStyle += endStyle; }
  7472. var token = elt("span", [content], fullStyle, css);
  7473. if (attributes) {
  7474. for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class")
  7475. { token.setAttribute(attr, attributes[attr]); } }
  7476. }
  7477. return builder.content.appendChild(token)
  7478. }
  7479. builder.content.appendChild(content);
  7480. }
  7481. // Change some spaces to NBSP to prevent the browser from collapsing
  7482. // trailing spaces at the end of a line when rendering text (issue #1362).
  7483. function splitSpaces(text, trailingBefore) {
  7484. if (text.length > 1 && !/ /.test(text)) { return text }
  7485. var spaceBefore = trailingBefore, result = "";
  7486. for (var i = 0; i < text.length; i++) {
  7487. var ch = text.charAt(i);
  7488. if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
  7489. { ch = "\u00a0"; }
  7490. result += ch;
  7491. spaceBefore = ch == " ";
  7492. }
  7493. return result
  7494. }
  7495. // Work around nonsense dimensions being reported for stretches of
  7496. // right-to-left text.
  7497. function buildTokenBadBidi(inner, order) {
  7498. return function (builder, text, style, startStyle, endStyle, css, attributes) {
  7499. style = style ? style + " cm-force-border" : "cm-force-border";
  7500. var start = builder.pos, end = start + text.length;
  7501. for (;;) {
  7502. // Find the part that overlaps with the start of this text
  7503. var part = (void 0);
  7504. for (var i = 0; i < order.length; i++) {
  7505. part = order[i];
  7506. if (part.to > start && part.from <= start) { break }
  7507. }
  7508. if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, css, attributes) }
  7509. inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);
  7510. startStyle = null;
  7511. text = text.slice(part.to - start);
  7512. start = part.to;
  7513. }
  7514. }
  7515. }
  7516. function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
  7517. var widget = !ignoreWidget && marker.widgetNode;
  7518. if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); }
  7519. if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
  7520. if (!widget)
  7521. { widget = builder.content.appendChild(document.createElement("span")); }
  7522. widget.setAttribute("cm-marker", marker.id);
  7523. }
  7524. if (widget) {
  7525. builder.cm.display.input.setUneditable(widget);
  7526. builder.content.appendChild(widget);
  7527. }
  7528. builder.pos += size;
  7529. builder.trailingSpace = false;
  7530. }
  7531. // Outputs a number of spans to make up a line, taking highlighting
  7532. // and marked text into account.
  7533. function insertLineContent(line, builder, styles) {
  7534. var spans = line.markedSpans, allText = line.text, at = 0;
  7535. if (!spans) {
  7536. for (var i$1 = 1; i$1 < styles.length; i$1+=2)
  7537. { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); }
  7538. return
  7539. }
  7540. var len = allText.length, pos = 0, i = 1, text = "", style, css;
  7541. var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes;
  7542. for (;;) {
  7543. if (nextChange == pos) { // Update current marker set
  7544. spanStyle = spanEndStyle = spanStartStyle = css = "";
  7545. attributes = null;
  7546. collapsed = null; nextChange = Infinity;
  7547. var foundBookmarks = [], endStyles = (void 0);
  7548. for (var j = 0; j < spans.length; ++j) {
  7549. var sp = spans[j], m = sp.marker;
  7550. if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
  7551. foundBookmarks.push(m);
  7552. } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
  7553. if (sp.to != null && sp.to != pos && nextChange > sp.to) {
  7554. nextChange = sp.to;
  7555. spanEndStyle = "";
  7556. }
  7557. if (m.className) { spanStyle += " " + m.className; }
  7558. if (m.css) { css = (css ? css + ";" : "") + m.css; }
  7559. if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; }
  7560. if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); }
  7561. // support for the old title property
  7562. // https://github.com/codemirror/CodeMirror/pull/5673
  7563. if (m.title) { (attributes || (attributes = {})).title = m.title; }
  7564. if (m.attributes) {
  7565. for (var attr in m.attributes)
  7566. { (attributes || (attributes = {}))[attr] = m.attributes[attr]; }
  7567. }
  7568. if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
  7569. { collapsed = sp; }
  7570. } else if (sp.from > pos && nextChange > sp.from) {
  7571. nextChange = sp.from;
  7572. }
  7573. }
  7574. if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
  7575. { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } }
  7576. if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
  7577. { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } }
  7578. if (collapsed && (collapsed.from || 0) == pos) {
  7579. buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
  7580. collapsed.marker, collapsed.from == null);
  7581. if (collapsed.to == null) { return }
  7582. if (collapsed.to == pos) { collapsed = false; }
  7583. }
  7584. }
  7585. if (pos >= len) { break }
  7586. var upto = Math.min(len, nextChange);
  7587. while (true) {
  7588. if (text) {
  7589. var end = pos + text.length;
  7590. if (!collapsed) {
  7591. var tokenText = end > upto ? text.slice(0, upto - pos) : text;
  7592. builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
  7593. spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", css, attributes);
  7594. }
  7595. if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
  7596. pos = end;
  7597. spanStartStyle = "";
  7598. }
  7599. text = allText.slice(at, at = styles[i++]);
  7600. style = interpretTokenStyle(styles[i++], builder.cm.options);
  7601. }
  7602. }
  7603. }
  7604. // These objects are used to represent the visible (currently drawn)
  7605. // part of the document. A LineView may correspond to multiple
  7606. // logical lines, if those are connected by collapsed ranges.
  7607. function LineView(doc, line, lineN) {
  7608. // The starting line
  7609. this.line = line;
  7610. // Continuing lines, if any
  7611. this.rest = visualLineContinued(line);
  7612. // Number of logical lines in this visual line
  7613. this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
  7614. this.node = this.text = null;
  7615. this.hidden = lineIsHidden(doc, line);
  7616. }
  7617. // Create a range of LineView objects for the given lines.
  7618. function buildViewArray(cm, from, to) {
  7619. var array = [], nextPos;
  7620. for (var pos = from; pos < to; pos = nextPos) {
  7621. var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
  7622. nextPos = pos + view.size;
  7623. array.push(view);
  7624. }
  7625. return array
  7626. }
  7627. var operationGroup = null;
  7628. function pushOperation(op) {
  7629. if (operationGroup) {
  7630. operationGroup.ops.push(op);
  7631. } else {
  7632. op.ownsGroup = operationGroup = {
  7633. ops: [op],
  7634. delayedCallbacks: []
  7635. };
  7636. }
  7637. }
  7638. function fireCallbacksForOps(group) {
  7639. // Calls delayed callbacks and cursorActivity handlers until no
  7640. // new ones appear
  7641. var callbacks = group.delayedCallbacks, i = 0;
  7642. do {
  7643. for (; i < callbacks.length; i++)
  7644. { callbacks[i].call(null); }
  7645. for (var j = 0; j < group.ops.length; j++) {
  7646. var op = group.ops[j];
  7647. if (op.cursorActivityHandlers)
  7648. { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
  7649. { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } }
  7650. }
  7651. } while (i < callbacks.length)
  7652. }
  7653. function finishOperation(op, endCb) {
  7654. var group = op.ownsGroup;
  7655. if (!group) { return }
  7656. try { fireCallbacksForOps(group); }
  7657. finally {
  7658. operationGroup = null;
  7659. endCb(group);
  7660. }
  7661. }
  7662. var orphanDelayedCallbacks = null;
  7663. // Often, we want to signal events at a point where we are in the
  7664. // middle of some work, but don't want the handler to start calling
  7665. // other methods on the editor, which might be in an inconsistent
  7666. // state or simply not expect any other events to happen.
  7667. // signalLater looks whether there are any handlers, and schedules
  7668. // them to be executed when the last operation ends, or, if no
  7669. // operation is active, when a timeout fires.
  7670. function signalLater(emitter, type /*, values...*/) {
  7671. var arr = getHandlers(emitter, type);
  7672. if (!arr.length) { return }
  7673. var args = Array.prototype.slice.call(arguments, 2), list;
  7674. if (operationGroup) {
  7675. list = operationGroup.delayedCallbacks;
  7676. } else if (orphanDelayedCallbacks) {
  7677. list = orphanDelayedCallbacks;
  7678. } else {
  7679. list = orphanDelayedCallbacks = [];
  7680. setTimeout(fireOrphanDelayed, 0);
  7681. }
  7682. var loop = function ( i ) {
  7683. list.push(function () { return arr[i].apply(null, args); });
  7684. };
  7685. for (var i = 0; i < arr.length; ++i)
  7686. loop( i );
  7687. }
  7688. function fireOrphanDelayed() {
  7689. var delayed = orphanDelayedCallbacks;
  7690. orphanDelayedCallbacks = null;
  7691. for (var i = 0; i < delayed.length; ++i) { delayed[i](); }
  7692. }
  7693. // When an aspect of a line changes, a string is added to
  7694. // lineView.changes. This updates the relevant part of the line's
  7695. // DOM structure.
  7696. function updateLineForChanges(cm, lineView, lineN, dims) {
  7697. for (var j = 0; j < lineView.changes.length; j++) {
  7698. var type = lineView.changes[j];
  7699. if (type == "text") { updateLineText(cm, lineView); }
  7700. else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); }
  7701. else if (type == "class") { updateLineClasses(cm, lineView); }
  7702. else if (type == "widget") { updateLineWidgets(cm, lineView, dims); }
  7703. }
  7704. lineView.changes = null;
  7705. }
  7706. // Lines with gutter elements, widgets or a background class need to
  7707. // be wrapped, and have the extra elements added to the wrapper div
  7708. function ensureLineWrapped(lineView) {
  7709. if (lineView.node == lineView.text) {
  7710. lineView.node = elt("div", null, null, "position: relative");
  7711. if (lineView.text.parentNode)
  7712. { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); }
  7713. lineView.node.appendChild(lineView.text);
  7714. if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; }
  7715. }
  7716. return lineView.node
  7717. }
  7718. function updateLineBackground(cm, lineView) {
  7719. var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
  7720. if (cls) { cls += " CodeMirror-linebackground"; }
  7721. if (lineView.background) {
  7722. if (cls) { lineView.background.className = cls; }
  7723. else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
  7724. } else if (cls) {
  7725. var wrap = ensureLineWrapped(lineView);
  7726. lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
  7727. cm.display.input.setUneditable(lineView.background);
  7728. }
  7729. }
  7730. // Wrapper around buildLineContent which will reuse the structure
  7731. // in display.externalMeasured when possible.
  7732. function getLineContent(cm, lineView) {
  7733. var ext = cm.display.externalMeasured;
  7734. if (ext && ext.line == lineView.line) {
  7735. cm.display.externalMeasured = null;
  7736. lineView.measure = ext.measure;
  7737. return ext.built
  7738. }
  7739. return buildLineContent(cm, lineView)
  7740. }
  7741. // Redraw the line's text. Interacts with the background and text
  7742. // classes because the mode may output tokens that influence these
  7743. // classes.
  7744. function updateLineText(cm, lineView) {
  7745. var cls = lineView.text.className;
  7746. var built = getLineContent(cm, lineView);
  7747. if (lineView.text == lineView.node) { lineView.node = built.pre; }
  7748. lineView.text.parentNode.replaceChild(built.pre, lineView.text);
  7749. lineView.text = built.pre;
  7750. if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
  7751. lineView.bgClass = built.bgClass;
  7752. lineView.textClass = built.textClass;
  7753. updateLineClasses(cm, lineView);
  7754. } else if (cls) {
  7755. lineView.text.className = cls;
  7756. }
  7757. }
  7758. function updateLineClasses(cm, lineView) {
  7759. updateLineBackground(cm, lineView);
  7760. if (lineView.line.wrapClass)
  7761. { ensureLineWrapped(lineView).className = lineView.line.wrapClass; }
  7762. else if (lineView.node != lineView.text)
  7763. { lineView.node.className = ""; }
  7764. var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
  7765. lineView.text.className = textClass || "";
  7766. }
  7767. function updateLineGutter(cm, lineView, lineN, dims) {
  7768. if (lineView.gutter) {
  7769. lineView.node.removeChild(lineView.gutter);
  7770. lineView.gutter = null;
  7771. }
  7772. if (lineView.gutterBackground) {
  7773. lineView.node.removeChild(lineView.gutterBackground);
  7774. lineView.gutterBackground = null;
  7775. }
  7776. if (lineView.line.gutterClass) {
  7777. var wrap = ensureLineWrapped(lineView);
  7778. lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
  7779. ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"));
  7780. cm.display.input.setUneditable(lineView.gutterBackground);
  7781. wrap.insertBefore(lineView.gutterBackground, lineView.text);
  7782. }
  7783. var markers = lineView.line.gutterMarkers;
  7784. if (cm.options.lineNumbers || markers) {
  7785. var wrap$1 = ensureLineWrapped(lineView);
  7786. var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
  7787. cm.display.input.setUneditable(gutterWrap);
  7788. wrap$1.insertBefore(gutterWrap, lineView.text);
  7789. if (lineView.line.gutterClass)
  7790. { gutterWrap.className += " " + lineView.line.gutterClass; }
  7791. if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
  7792. { lineView.lineNumber = gutterWrap.appendChild(
  7793. elt("div", lineNumberFor(cm.options, lineN),
  7794. "CodeMirror-linenumber CodeMirror-gutter-elt",
  7795. ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); }
  7796. if (markers) { for (var k = 0; k < cm.display.gutterSpecs.length; ++k) {
  7797. var id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id];
  7798. if (found)
  7799. { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
  7800. ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); }
  7801. } }
  7802. }
  7803. }
  7804. function updateLineWidgets(cm, lineView, dims) {
  7805. if (lineView.alignable) { lineView.alignable = null; }
  7806. var isWidget = classTest("CodeMirror-linewidget");
  7807. for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
  7808. next = node.nextSibling;
  7809. if (isWidget.test(node.className)) { lineView.node.removeChild(node); }
  7810. }
  7811. insertLineWidgets(cm, lineView, dims);
  7812. }
  7813. // Build a line's DOM representation from scratch
  7814. function buildLineElement(cm, lineView, lineN, dims) {
  7815. var built = getLineContent(cm, lineView);
  7816. lineView.text = lineView.node = built.pre;
  7817. if (built.bgClass) { lineView.bgClass = built.bgClass; }
  7818. if (built.textClass) { lineView.textClass = built.textClass; }
  7819. updateLineClasses(cm, lineView);
  7820. updateLineGutter(cm, lineView, lineN, dims);
  7821. insertLineWidgets(cm, lineView, dims);
  7822. return lineView.node
  7823. }
  7824. // A lineView may contain multiple logical lines (when merged by
  7825. // collapsed spans). The widgets for all of them need to be drawn.
  7826. function insertLineWidgets(cm, lineView, dims) {
  7827. insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
  7828. if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
  7829. { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } }
  7830. }
  7831. function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
  7832. if (!line.widgets) { return }
  7833. var wrap = ensureLineWrapped(lineView);
  7834. for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
  7835. var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""));
  7836. if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); }
  7837. positionLineWidget(widget, node, lineView, dims);
  7838. cm.display.input.setUneditable(node);
  7839. if (allowAbove && widget.above)
  7840. { wrap.insertBefore(node, lineView.gutter || lineView.text); }
  7841. else
  7842. { wrap.appendChild(node); }
  7843. signalLater(widget, "redraw");
  7844. }
  7845. }
  7846. function positionLineWidget(widget, node, lineView, dims) {
  7847. if (widget.noHScroll) {
  7848. (lineView.alignable || (lineView.alignable = [])).push(node);
  7849. var width = dims.wrapperWidth;
  7850. node.style.left = dims.fixedPos + "px";
  7851. if (!widget.coverGutter) {
  7852. width -= dims.gutterTotalWidth;
  7853. node.style.paddingLeft = dims.gutterTotalWidth + "px";
  7854. }
  7855. node.style.width = width + "px";
  7856. }
  7857. if (widget.coverGutter) {
  7858. node.style.zIndex = 5;
  7859. node.style.position = "relative";
  7860. if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; }
  7861. }
  7862. }
  7863. function widgetHeight(widget) {
  7864. if (widget.height != null) { return widget.height }
  7865. var cm = widget.doc.cm;
  7866. if (!cm) { return 0 }
  7867. if (!contains(document.body, widget.node)) {
  7868. var parentStyle = "position: relative;";
  7869. if (widget.coverGutter)
  7870. { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; }
  7871. if (widget.noHScroll)
  7872. { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; }
  7873. removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
  7874. }
  7875. return widget.height = widget.node.parentNode.offsetHeight
  7876. }
  7877. // Return true when the given mouse event happened in a widget
  7878. function eventInWidget(display, e) {
  7879. for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
  7880. if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
  7881. (n.parentNode == display.sizer && n != display.mover))
  7882. { return true }
  7883. }
  7884. }
  7885. // POSITION MEASUREMENT
  7886. function paddingTop(display) {return display.lineSpace.offsetTop}
  7887. function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
  7888. function paddingH(display) {
  7889. if (display.cachedPaddingH) { return display.cachedPaddingH }
  7890. var e = removeChildrenAndAdd(display.measure, elt("pre", "x", "CodeMirror-line-like"));
  7891. var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
  7892. var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
  7893. if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; }
  7894. return data
  7895. }
  7896. function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
  7897. function displayWidth(cm) {
  7898. return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
  7899. }
  7900. function displayHeight(cm) {
  7901. return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
  7902. }
  7903. // Ensure the lineView.wrapping.heights array is populated. This is
  7904. // an array of bottom offsets for the lines that make up a drawn
  7905. // line. When lineWrapping is on, there might be more than one
  7906. // height.
  7907. function ensureLineHeights(cm, lineView, rect) {
  7908. var wrapping = cm.options.lineWrapping;
  7909. var curWidth = wrapping && displayWidth(cm);
  7910. if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
  7911. var heights = lineView.measure.heights = [];
  7912. if (wrapping) {
  7913. lineView.measure.width = curWidth;
  7914. var rects = lineView.text.firstChild.getClientRects();
  7915. for (var i = 0; i < rects.length - 1; i++) {
  7916. var cur = rects[i], next = rects[i + 1];
  7917. if (Math.abs(cur.bottom - next.bottom) > 2)
  7918. { heights.push((cur.bottom + next.top) / 2 - rect.top); }
  7919. }
  7920. }
  7921. heights.push(rect.bottom - rect.top);
  7922. }
  7923. }
  7924. // Find a line map (mapping character offsets to text nodes) and a
  7925. // measurement cache for the given line number. (A line view might
  7926. // contain multiple lines when collapsed ranges are present.)
  7927. function mapFromLineView(lineView, line, lineN) {
  7928. if (lineView.line == line)
  7929. { return {map: lineView.measure.map, cache: lineView.measure.cache} }
  7930. for (var i = 0; i < lineView.rest.length; i++)
  7931. { if (lineView.rest[i] == line)
  7932. { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
  7933. for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
  7934. { if (lineNo(lineView.rest[i$1]) > lineN)
  7935. { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
  7936. }
  7937. // Render a line into the hidden node display.externalMeasured. Used
  7938. // when measurement is needed for a line that's not in the viewport.
  7939. function updateExternalMeasurement(cm, line) {
  7940. line = visualLine(line);
  7941. var lineN = lineNo(line);
  7942. var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
  7943. view.lineN = lineN;
  7944. var built = view.built = buildLineContent(cm, view);
  7945. view.text = built.pre;
  7946. removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
  7947. return view
  7948. }
  7949. // Get a {top, bottom, left, right} box (in line-local coordinates)
  7950. // for a given character.
  7951. function measureChar(cm, line, ch, bias) {
  7952. return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
  7953. }
  7954. // Find a line view that corresponds to the given line number.
  7955. function findViewForLine(cm, lineN) {
  7956. if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
  7957. { return cm.display.view[findViewIndex(cm, lineN)] }
  7958. var ext = cm.display.externalMeasured;
  7959. if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
  7960. { return ext }
  7961. }
  7962. // Measurement can be split in two steps, the set-up work that
  7963. // applies to the whole line, and the measurement of the actual
  7964. // character. Functions like coordsChar, that need to do a lot of
  7965. // measurements in a row, can thus ensure that the set-up work is
  7966. // only done once.
  7967. function prepareMeasureForLine(cm, line) {
  7968. var lineN = lineNo(line);
  7969. var view = findViewForLine(cm, lineN);
  7970. if (view && !view.text) {
  7971. view = null;
  7972. } else if (view && view.changes) {
  7973. updateLineForChanges(cm, view, lineN, getDimensions(cm));
  7974. cm.curOp.forceUpdate = true;
  7975. }
  7976. if (!view)
  7977. { view = updateExternalMeasurement(cm, line); }
  7978. var info = mapFromLineView(view, line, lineN);
  7979. return {
  7980. line: line, view: view, rect: null,
  7981. map: info.map, cache: info.cache, before: info.before,
  7982. hasHeights: false
  7983. }
  7984. }
  7985. // Given a prepared measurement object, measures the position of an
  7986. // actual character (or fetches it from the cache).
  7987. function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
  7988. if (prepared.before) { ch = -1; }
  7989. var key = ch + (bias || ""), found;
  7990. if (prepared.cache.hasOwnProperty(key)) {
  7991. found = prepared.cache[key];
  7992. } else {
  7993. if (!prepared.rect)
  7994. { prepared.rect = prepared.view.text.getBoundingClientRect(); }
  7995. if (!prepared.hasHeights) {
  7996. ensureLineHeights(cm, prepared.view, prepared.rect);
  7997. prepared.hasHeights = true;
  7998. }
  7999. found = measureCharInner(cm, prepared, ch, bias);
  8000. if (!found.bogus) { prepared.cache[key] = found; }
  8001. }
  8002. return {left: found.left, right: found.right,
  8003. top: varHeight ? found.rtop : found.top,
  8004. bottom: varHeight ? found.rbottom : found.bottom}
  8005. }
  8006. var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
  8007. function nodeAndOffsetInLineMap(map, ch, bias) {
  8008. var node, start, end, collapse, mStart, mEnd;
  8009. // First, search the line map for the text node corresponding to,
  8010. // or closest to, the target character.
  8011. for (var i = 0; i < map.length; i += 3) {
  8012. mStart = map[i];
  8013. mEnd = map[i + 1];
  8014. if (ch < mStart) {
  8015. start = 0; end = 1;
  8016. collapse = "left";
  8017. } else if (ch < mEnd) {
  8018. start = ch - mStart;
  8019. end = start + 1;
  8020. } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
  8021. end = mEnd - mStart;
  8022. start = end - 1;
  8023. if (ch >= mEnd) { collapse = "right"; }
  8024. }
  8025. if (start != null) {
  8026. node = map[i + 2];
  8027. if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
  8028. { collapse = bias; }
  8029. if (bias == "left" && start == 0)
  8030. { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
  8031. node = map[(i -= 3) + 2];
  8032. collapse = "left";
  8033. } }
  8034. if (bias == "right" && start == mEnd - mStart)
  8035. { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
  8036. node = map[(i += 3) + 2];
  8037. collapse = "right";
  8038. } }
  8039. break
  8040. }
  8041. }
  8042. return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
  8043. }
  8044. function getUsefulRect(rects, bias) {
  8045. var rect = nullRect;
  8046. if (bias == "left") { for (var i = 0; i < rects.length; i++) {
  8047. if ((rect = rects[i]).left != rect.right) { break }
  8048. } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
  8049. if ((rect = rects[i$1]).left != rect.right) { break }
  8050. } }
  8051. return rect
  8052. }
  8053. function measureCharInner(cm, prepared, ch, bias) {
  8054. var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
  8055. var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
  8056. var rect;
  8057. if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
  8058. for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
  8059. while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; }
  8060. while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; }
  8061. if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
  8062. { rect = node.parentNode.getBoundingClientRect(); }
  8063. else
  8064. { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); }
  8065. if (rect.left || rect.right || start == 0) { break }
  8066. end = start;
  8067. start = start - 1;
  8068. collapse = "right";
  8069. }
  8070. if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); }
  8071. } else { // If it is a widget, simply get the box for the whole widget.
  8072. if (start > 0) { collapse = bias = "right"; }
  8073. var rects;
  8074. if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
  8075. { rect = rects[bias == "right" ? rects.length - 1 : 0]; }
  8076. else
  8077. { rect = node.getBoundingClientRect(); }
  8078. }
  8079. if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
  8080. var rSpan = node.parentNode.getClientRects()[0];
  8081. if (rSpan)
  8082. { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; }
  8083. else
  8084. { rect = nullRect; }
  8085. }
  8086. var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
  8087. var mid = (rtop + rbot) / 2;
  8088. var heights = prepared.view.measure.heights;
  8089. var i = 0;
  8090. for (; i < heights.length - 1; i++)
  8091. { if (mid < heights[i]) { break } }
  8092. var top = i ? heights[i - 1] : 0, bot = heights[i];
  8093. var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
  8094. right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
  8095. top: top, bottom: bot};
  8096. if (!rect.left && !rect.right) { result.bogus = true; }
  8097. if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
  8098. return result
  8099. }
  8100. // Work around problem with bounding client rects on ranges being
  8101. // returned incorrectly when zoomed on IE10 and below.
  8102. function maybeUpdateRectForZooming(measure, rect) {
  8103. if (!window.screen || screen.logicalXDPI == null ||
  8104. screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
  8105. { return rect }
  8106. var scaleX = screen.logicalXDPI / screen.deviceXDPI;
  8107. var scaleY = screen.logicalYDPI / screen.deviceYDPI;
  8108. return {left: rect.left * scaleX, right: rect.right * scaleX,
  8109. top: rect.top * scaleY, bottom: rect.bottom * scaleY}
  8110. }
  8111. function clearLineMeasurementCacheFor(lineView) {
  8112. if (lineView.measure) {
  8113. lineView.measure.cache = {};
  8114. lineView.measure.heights = null;
  8115. if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
  8116. { lineView.measure.caches[i] = {}; } }
  8117. }
  8118. }
  8119. function clearLineMeasurementCache(cm) {
  8120. cm.display.externalMeasure = null;
  8121. removeChildren(cm.display.lineMeasure);
  8122. for (var i = 0; i < cm.display.view.length; i++)
  8123. { clearLineMeasurementCacheFor(cm.display.view[i]); }
  8124. }
  8125. function clearCaches(cm) {
  8126. clearLineMeasurementCache(cm);
  8127. cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
  8128. if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; }
  8129. cm.display.lineNumChars = null;
  8130. }
  8131. function pageScrollX() {
  8132. // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
  8133. // which causes page_Offset and bounding client rects to use
  8134. // different reference viewports and invalidate our calculations.
  8135. if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
  8136. return window.pageXOffset || (document.documentElement || document.body).scrollLeft
  8137. }
  8138. function pageScrollY() {
  8139. if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
  8140. return window.pageYOffset || (document.documentElement || document.body).scrollTop
  8141. }
  8142. function widgetTopHeight(lineObj) {
  8143. var height = 0;
  8144. if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
  8145. { height += widgetHeight(lineObj.widgets[i]); } } }
  8146. return height
  8147. }
  8148. // Converts a {top, bottom, left, right} box from line-local
  8149. // coordinates into another coordinate system. Context may be one of
  8150. // "line", "div" (display.lineDiv), "local"./null (editor), "window",
  8151. // or "page".
  8152. function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
  8153. if (!includeWidgets) {
  8154. var height = widgetTopHeight(lineObj);
  8155. rect.top += height; rect.bottom += height;
  8156. }
  8157. if (context == "line") { return rect }
  8158. if (!context) { context = "local"; }
  8159. var yOff = heightAtLine(lineObj);
  8160. if (context == "local") { yOff += paddingTop(cm.display); }
  8161. else { yOff -= cm.display.viewOffset; }
  8162. if (context == "page" || context == "window") {
  8163. var lOff = cm.display.lineSpace.getBoundingClientRect();
  8164. yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
  8165. var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
  8166. rect.left += xOff; rect.right += xOff;
  8167. }
  8168. rect.top += yOff; rect.bottom += yOff;
  8169. return rect
  8170. }
  8171. // Coverts a box from "div" coords to another coordinate system.
  8172. // Context may be "window", "page", "div", or "local"./null.
  8173. function fromCoordSystem(cm, coords, context) {
  8174. if (context == "div") { return coords }
  8175. var left = coords.left, top = coords.top;
  8176. // First move into "page" coordinate system
  8177. if (context == "page") {
  8178. left -= pageScrollX();
  8179. top -= pageScrollY();
  8180. } else if (context == "local" || !context) {
  8181. var localBox = cm.display.sizer.getBoundingClientRect();
  8182. left += localBox.left;
  8183. top += localBox.top;
  8184. }
  8185. var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
  8186. return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
  8187. }
  8188. function charCoords(cm, pos, context, lineObj, bias) {
  8189. if (!lineObj) { lineObj = getLine(cm.doc, pos.line); }
  8190. return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
  8191. }
  8192. // Returns a box for a given cursor position, which may have an
  8193. // 'other' property containing the position of the secondary cursor
  8194. // on a bidi boundary.
  8195. // A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
  8196. // and after `char - 1` in writing order of `char - 1`
  8197. // A cursor Pos(line, char, "after") is on the same visual line as `char`
  8198. // and before `char` in writing order of `char`
  8199. // Examples (upper-case letters are RTL, lower-case are LTR):
  8200. // Pos(0, 1, ...)
  8201. // before after
  8202. // ab a|b a|b
  8203. // aB a|B aB|
  8204. // Ab |Ab A|b
  8205. // AB B|A B|A
  8206. // Every position after the last character on a line is considered to stick
  8207. // to the last character on the line.
  8208. function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
  8209. lineObj = lineObj || getLine(cm.doc, pos.line);
  8210. if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
  8211. function get(ch, right) {
  8212. var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
  8213. if (right) { m.left = m.right; } else { m.right = m.left; }
  8214. return intoCoordSystem(cm, lineObj, m, context)
  8215. }
  8216. var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
  8217. if (ch >= lineObj.text.length) {
  8218. ch = lineObj.text.length;
  8219. sticky = "before";
  8220. } else if (ch <= 0) {
  8221. ch = 0;
  8222. sticky = "after";
  8223. }
  8224. if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
  8225. function getBidi(ch, partPos, invert) {
  8226. var part = order[partPos], right = part.level == 1;
  8227. return get(invert ? ch - 1 : ch, right != invert)
  8228. }
  8229. var partPos = getBidiPartAt(order, ch, sticky);
  8230. var other = bidiOther;
  8231. var val = getBidi(ch, partPos, sticky == "before");
  8232. if (other != null) { val.other = getBidi(ch, other, sticky != "before"); }
  8233. return val
  8234. }
  8235. // Used to cheaply estimate the coordinates for a position. Used for
  8236. // intermediate scroll updates.
  8237. function estimateCoords(cm, pos) {
  8238. var left = 0;
  8239. pos = clipPos(cm.doc, pos);
  8240. if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; }
  8241. var lineObj = getLine(cm.doc, pos.line);
  8242. var top = heightAtLine(lineObj) + paddingTop(cm.display);
  8243. return {left: left, right: left, top: top, bottom: top + lineObj.height}
  8244. }
  8245. // Positions returned by coordsChar contain some extra information.
  8246. // xRel is the relative x position of the input coordinates compared
  8247. // to the found position (so xRel > 0 means the coordinates are to
  8248. // the right of the character position, for example). When outside
  8249. // is true, that means the coordinates lie outside the line's
  8250. // vertical range.
  8251. function PosWithInfo(line, ch, sticky, outside, xRel) {
  8252. var pos = Pos(line, ch, sticky);
  8253. pos.xRel = xRel;
  8254. if (outside) { pos.outside = outside; }
  8255. return pos
  8256. }
  8257. // Compute the character position closest to the given coordinates.
  8258. // Input must be lineSpace-local ("div" coordinate system).
  8259. function coordsChar(cm, x, y) {
  8260. var doc = cm.doc;
  8261. y += cm.display.viewOffset;
  8262. if (y < 0) { return PosWithInfo(doc.first, 0, null, -1, -1) }
  8263. var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
  8264. if (lineN > last)
  8265. { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1) }
  8266. if (x < 0) { x = 0; }
  8267. var lineObj = getLine(doc, lineN);
  8268. for (;;) {
  8269. var found = coordsCharInner(cm, lineObj, lineN, x, y);
  8270. var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0));
  8271. if (!collapsed) { return found }
  8272. var rangeEnd = collapsed.find(1);
  8273. if (rangeEnd.line == lineN) { return rangeEnd }
  8274. lineObj = getLine(doc, lineN = rangeEnd.line);
  8275. }
  8276. }
  8277. function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
  8278. y -= widgetTopHeight(lineObj);
  8279. var end = lineObj.text.length;
  8280. var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0);
  8281. end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end);
  8282. return {begin: begin, end: end}
  8283. }
  8284. function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
  8285. if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
  8286. var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
  8287. return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
  8288. }
  8289. // Returns true if the given side of a box is after the given
  8290. // coordinates, in top-to-bottom, left-to-right order.
  8291. function boxIsAfter(box, x, y, left) {
  8292. return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
  8293. }
  8294. function coordsCharInner(cm, lineObj, lineNo, x, y) {
  8295. // Move y into line-local coordinate space
  8296. y -= heightAtLine(lineObj);
  8297. var preparedMeasure = prepareMeasureForLine(cm, lineObj);
  8298. // When directly calling `measureCharPrepared`, we have to adjust
  8299. // for the widgets at this line.
  8300. var widgetHeight = widgetTopHeight(lineObj);
  8301. var begin = 0, end = lineObj.text.length, ltr = true;
  8302. var order = getOrder(lineObj, cm.doc.direction);
  8303. // If the line isn't plain left-to-right text, first figure out
  8304. // which bidi section the coordinates fall into.
  8305. if (order) {
  8306. var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
  8307. (cm, lineObj, lineNo, preparedMeasure, order, x, y);
  8308. ltr = part.level != 1;
  8309. // The awkward -1 offsets are needed because findFirst (called
  8310. // on these below) will treat its first bound as inclusive,
  8311. // second as exclusive, but we want to actually address the
  8312. // characters in the part's range
  8313. begin = ltr ? part.from : part.to - 1;
  8314. end = ltr ? part.to : part.from - 1;
  8315. }
  8316. // A binary search to find the first character whose bounding box
  8317. // starts after the coordinates. If we run across any whose box wrap
  8318. // the coordinates, store that.
  8319. var chAround = null, boxAround = null;
  8320. var ch = findFirst(function (ch) {
  8321. var box = measureCharPrepared(cm, preparedMeasure, ch);
  8322. box.top += widgetHeight; box.bottom += widgetHeight;
  8323. if (!boxIsAfter(box, x, y, false)) { return false }
  8324. if (box.top <= y && box.left <= x) {
  8325. chAround = ch;
  8326. boxAround = box;
  8327. }
  8328. return true
  8329. }, begin, end);
  8330. var baseX, sticky, outside = false;
  8331. // If a box around the coordinates was found, use that
  8332. if (boxAround) {
  8333. // Distinguish coordinates nearer to the left or right side of the box
  8334. var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr;
  8335. ch = chAround + (atStart ? 0 : 1);
  8336. sticky = atStart ? "after" : "before";
  8337. baseX = atLeft ? boxAround.left : boxAround.right;
  8338. } else {
  8339. // (Adjust for extended bound, if necessary.)
  8340. if (!ltr && (ch == end || ch == begin)) { ch++; }
  8341. // To determine which side to associate with, get the box to the
  8342. // left of the character and compare it's vertical position to the
  8343. // coordinates
  8344. sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
  8345. (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ?
  8346. "after" : "before";
  8347. // Now get accurate coordinates for this place, in order to get a
  8348. // base X position
  8349. var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure);
  8350. baseX = coords.left;
  8351. outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0;
  8352. }
  8353. ch = skipExtendingChars(lineObj.text, ch, 1);
  8354. return PosWithInfo(lineNo, ch, sticky, outside, x - baseX)
  8355. }
  8356. function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {
  8357. // Bidi parts are sorted left-to-right, and in a non-line-wrapping
  8358. // situation, we can take this ordering to correspond to the visual
  8359. // ordering. This finds the first part whose end is after the given
  8360. // coordinates.
  8361. var index = findFirst(function (i) {
  8362. var part = order[i], ltr = part.level != 1;
  8363. return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"),
  8364. "line", lineObj, preparedMeasure), x, y, true)
  8365. }, 0, order.length - 1);
  8366. var part = order[index];
  8367. // If this isn't the first part, the part's start is also after
  8368. // the coordinates, and the coordinates aren't on the same line as
  8369. // that start, move one part back.
  8370. if (index > 0) {
  8371. var ltr = part.level != 1;
  8372. var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"),
  8373. "line", lineObj, preparedMeasure);
  8374. if (boxIsAfter(start, x, y, true) && start.top > y)
  8375. { part = order[index - 1]; }
  8376. }
  8377. return part
  8378. }
  8379. function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
  8380. // In a wrapped line, rtl text on wrapping boundaries can do things
  8381. // that don't correspond to the ordering in our `order` array at
  8382. // all, so a binary search doesn't work, and we want to return a
  8383. // part that only spans one line so that the binary search in
  8384. // coordsCharInner is safe. As such, we first find the extent of the
  8385. // wrapped line, and then do a flat search in which we discard any
  8386. // spans that aren't on the line.
  8387. var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
  8388. var begin = ref.begin;
  8389. var end = ref.end;
  8390. if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; }
  8391. var part = null, closestDist = null;
  8392. for (var i = 0; i < order.length; i++) {
  8393. var p = order[i];
  8394. if (p.from >= end || p.to <= begin) { continue }
  8395. var ltr = p.level != 1;
  8396. var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
  8397. // Weigh against spans ending before this, so that they are only
  8398. // picked if nothing ends after
  8399. var dist = endX < x ? x - endX + 1e9 : endX - x;
  8400. if (!part || closestDist > dist) {
  8401. part = p;
  8402. closestDist = dist;
  8403. }
  8404. }
  8405. if (!part) { part = order[order.length - 1]; }
  8406. // Clip the part to the wrapped line.
  8407. if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; }
  8408. if (part.to > end) { part = {from: part.from, to: end, level: part.level}; }
  8409. return part
  8410. }
  8411. var measureText;
  8412. // Compute the default text height.
  8413. function textHeight(display) {
  8414. if (display.cachedTextHeight != null) { return display.cachedTextHeight }
  8415. if (measureText == null) {
  8416. measureText = elt("pre", null, "CodeMirror-line-like");
  8417. // Measure a bunch of lines, for browsers that compute
  8418. // fractional heights.
  8419. for (var i = 0; i < 49; ++i) {
  8420. measureText.appendChild(document.createTextNode("x"));
  8421. measureText.appendChild(elt("br"));
  8422. }
  8423. measureText.appendChild(document.createTextNode("x"));
  8424. }
  8425. removeChildrenAndAdd(display.measure, measureText);
  8426. var height = measureText.offsetHeight / 50;
  8427. if (height > 3) { display.cachedTextHeight = height; }
  8428. removeChildren(display.measure);
  8429. return height || 1
  8430. }
  8431. // Compute the default character width.
  8432. function charWidth(display) {
  8433. if (display.cachedCharWidth != null) { return display.cachedCharWidth }
  8434. var anchor = elt("span", "xxxxxxxxxx");
  8435. var pre = elt("pre", [anchor], "CodeMirror-line-like");
  8436. removeChildrenAndAdd(display.measure, pre);
  8437. var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
  8438. if (width > 2) { display.cachedCharWidth = width; }
  8439. return width || 10
  8440. }
  8441. // Do a bulk-read of the DOM positions and sizes needed to draw the
  8442. // view, so that we don't interleave reading and writing to the DOM.
  8443. function getDimensions(cm) {
  8444. var d = cm.display, left = {}, width = {};
  8445. var gutterLeft = d.gutters.clientLeft;
  8446. for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
  8447. var id = cm.display.gutterSpecs[i].className;
  8448. left[id] = n.offsetLeft + n.clientLeft + gutterLeft;
  8449. width[id] = n.clientWidth;
  8450. }
  8451. return {fixedPos: compensateForHScroll(d),
  8452. gutterTotalWidth: d.gutters.offsetWidth,
  8453. gutterLeft: left,
  8454. gutterWidth: width,
  8455. wrapperWidth: d.wrapper.clientWidth}
  8456. }
  8457. // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
  8458. // but using getBoundingClientRect to get a sub-pixel-accurate
  8459. // result.
  8460. function compensateForHScroll(display) {
  8461. return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
  8462. }
  8463. // Returns a function that estimates the height of a line, to use as
  8464. // first approximation until the line becomes visible (and is thus
  8465. // properly measurable).
  8466. function estimateHeight(cm) {
  8467. var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
  8468. var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
  8469. return function (line) {
  8470. if (lineIsHidden(cm.doc, line)) { return 0 }
  8471. var widgetsHeight = 0;
  8472. if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
  8473. if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; }
  8474. } }
  8475. if (wrapping)
  8476. { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
  8477. else
  8478. { return widgetsHeight + th }
  8479. }
  8480. }
  8481. function estimateLineHeights(cm) {
  8482. var doc = cm.doc, est = estimateHeight(cm);
  8483. doc.iter(function (line) {
  8484. var estHeight = est(line);
  8485. if (estHeight != line.height) { updateLineHeight(line, estHeight); }
  8486. });
  8487. }
  8488. // Given a mouse event, find the corresponding position. If liberal
  8489. // is false, it checks whether a gutter or scrollbar was clicked,
  8490. // and returns null if it was. forRect is used by rectangular
  8491. // selections, and tries to estimate a character position even for
  8492. // coordinates beyond the right of the text.
  8493. function posFromMouse(cm, e, liberal, forRect) {
  8494. var display = cm.display;
  8495. if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
  8496. var x, y, space = display.lineSpace.getBoundingClientRect();
  8497. // Fails unpredictably on IE[67] when mouse is dragged around quickly.
  8498. try { x = e.clientX - space.left; y = e.clientY - space.top; }
  8499. catch (e) { return null }
  8500. var coords = coordsChar(cm, x, y), line;
  8501. if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
  8502. var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
  8503. coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
  8504. }
  8505. return coords
  8506. }
  8507. // Find the view element corresponding to a given line. Return null
  8508. // when the line isn't visible.
  8509. function findViewIndex(cm, n) {
  8510. if (n >= cm.display.viewTo) { return null }
  8511. n -= cm.display.viewFrom;
  8512. if (n < 0) { return null }
  8513. var view = cm.display.view;
  8514. for (var i = 0; i < view.length; i++) {
  8515. n -= view[i].size;
  8516. if (n < 0) { return i }
  8517. }
  8518. }
  8519. // Updates the display.view data structure for a given change to the
  8520. // document. From and to are in pre-change coordinates. Lendiff is
  8521. // the amount of lines added or subtracted by the change. This is
  8522. // used for changes that span multiple lines, or change the way
  8523. // lines are divided into visual lines. regLineChange (below)
  8524. // registers single-line changes.
  8525. function regChange(cm, from, to, lendiff) {
  8526. if (from == null) { from = cm.doc.first; }
  8527. if (to == null) { to = cm.doc.first + cm.doc.size; }
  8528. if (!lendiff) { lendiff = 0; }
  8529. var display = cm.display;
  8530. if (lendiff && to < display.viewTo &&
  8531. (display.updateLineNumbers == null || display.updateLineNumbers > from))
  8532. { display.updateLineNumbers = from; }
  8533. cm.curOp.viewChanged = true;
  8534. if (from >= display.viewTo) { // Change after
  8535. if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
  8536. { resetView(cm); }
  8537. } else if (to <= display.viewFrom) { // Change before
  8538. if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
  8539. resetView(cm);
  8540. } else {
  8541. display.viewFrom += lendiff;
  8542. display.viewTo += lendiff;
  8543. }
  8544. } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
  8545. resetView(cm);
  8546. } else if (from <= display.viewFrom) { // Top overlap
  8547. var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
  8548. if (cut) {
  8549. display.view = display.view.slice(cut.index);
  8550. display.viewFrom = cut.lineN;
  8551. display.viewTo += lendiff;
  8552. } else {
  8553. resetView(cm);
  8554. }
  8555. } else if (to >= display.viewTo) { // Bottom overlap
  8556. var cut$1 = viewCuttingPoint(cm, from, from, -1);
  8557. if (cut$1) {
  8558. display.view = display.view.slice(0, cut$1.index);
  8559. display.viewTo = cut$1.lineN;
  8560. } else {
  8561. resetView(cm);
  8562. }
  8563. } else { // Gap in the middle
  8564. var cutTop = viewCuttingPoint(cm, from, from, -1);
  8565. var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
  8566. if (cutTop && cutBot) {
  8567. display.view = display.view.slice(0, cutTop.index)
  8568. .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
  8569. .concat(display.view.slice(cutBot.index));
  8570. display.viewTo += lendiff;
  8571. } else {
  8572. resetView(cm);
  8573. }
  8574. }
  8575. var ext = display.externalMeasured;
  8576. if (ext) {
  8577. if (to < ext.lineN)
  8578. { ext.lineN += lendiff; }
  8579. else if (from < ext.lineN + ext.size)
  8580. { display.externalMeasured = null; }
  8581. }
  8582. }
  8583. // Register a change to a single line. Type must be one of "text",
  8584. // "gutter", "class", "widget"
  8585. function regLineChange(cm, line, type) {
  8586. cm.curOp.viewChanged = true;
  8587. var display = cm.display, ext = cm.display.externalMeasured;
  8588. if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
  8589. { display.externalMeasured = null; }
  8590. if (line < display.viewFrom || line >= display.viewTo) { return }
  8591. var lineView = display.view[findViewIndex(cm, line)];
  8592. if (lineView.node == null) { return }
  8593. var arr = lineView.changes || (lineView.changes = []);
  8594. if (indexOf(arr, type) == -1) { arr.push(type); }
  8595. }
  8596. // Clear the view.
  8597. function resetView(cm) {
  8598. cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
  8599. cm.display.view = [];
  8600. cm.display.viewOffset = 0;
  8601. }
  8602. function viewCuttingPoint(cm, oldN, newN, dir) {
  8603. var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
  8604. if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
  8605. { return {index: index, lineN: newN} }
  8606. var n = cm.display.viewFrom;
  8607. for (var i = 0; i < index; i++)
  8608. { n += view[i].size; }
  8609. if (n != oldN) {
  8610. if (dir > 0) {
  8611. if (index == view.length - 1) { return null }
  8612. diff = (n + view[index].size) - oldN;
  8613. index++;
  8614. } else {
  8615. diff = n - oldN;
  8616. }
  8617. oldN += diff; newN += diff;
  8618. }
  8619. while (visualLineNo(cm.doc, newN) != newN) {
  8620. if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
  8621. newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
  8622. index += dir;
  8623. }
  8624. return {index: index, lineN: newN}
  8625. }
  8626. // Force the view to cover a given range, adding empty view element
  8627. // or clipping off existing ones as needed.
  8628. function adjustView(cm, from, to) {
  8629. var display = cm.display, view = display.view;
  8630. if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
  8631. display.view = buildViewArray(cm, from, to);
  8632. display.viewFrom = from;
  8633. } else {
  8634. if (display.viewFrom > from)
  8635. { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); }
  8636. else if (display.viewFrom < from)
  8637. { display.view = display.view.slice(findViewIndex(cm, from)); }
  8638. display.viewFrom = from;
  8639. if (display.viewTo < to)
  8640. { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); }
  8641. else if (display.viewTo > to)
  8642. { display.view = display.view.slice(0, findViewIndex(cm, to)); }
  8643. }
  8644. display.viewTo = to;
  8645. }
  8646. // Count the number of lines in the view whose DOM representation is
  8647. // out of date (or nonexistent).
  8648. function countDirtyView(cm) {
  8649. var view = cm.display.view, dirty = 0;
  8650. for (var i = 0; i < view.length; i++) {
  8651. var lineView = view[i];
  8652. if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; }
  8653. }
  8654. return dirty
  8655. }
  8656. function updateSelection(cm) {
  8657. cm.display.input.showSelection(cm.display.input.prepareSelection());
  8658. }
  8659. function prepareSelection(cm, primary) {
  8660. if ( primary === void 0 ) primary = true;
  8661. var doc = cm.doc, result = {};
  8662. var curFragment = result.cursors = document.createDocumentFragment();
  8663. var selFragment = result.selection = document.createDocumentFragment();
  8664. for (var i = 0; i < doc.sel.ranges.length; i++) {
  8665. if (!primary && i == doc.sel.primIndex) { continue }
  8666. var range = doc.sel.ranges[i];
  8667. if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue }
  8668. var collapsed = range.empty();
  8669. if (collapsed || cm.options.showCursorWhenSelecting)
  8670. { drawSelectionCursor(cm, range.head, curFragment); }
  8671. if (!collapsed)
  8672. { drawSelectionRange(cm, range, selFragment); }
  8673. }
  8674. return result
  8675. }
  8676. // Draws a cursor for the given range
  8677. function drawSelectionCursor(cm, head, output) {
  8678. var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
  8679. var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
  8680. cursor.style.left = pos.left + "px";
  8681. cursor.style.top = pos.top + "px";
  8682. cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
  8683. if (pos.other) {
  8684. // Secondary cursor, shown when on a 'jump' in bi-directional text
  8685. var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
  8686. otherCursor.style.display = "";
  8687. otherCursor.style.left = pos.other.left + "px";
  8688. otherCursor.style.top = pos.other.top + "px";
  8689. otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
  8690. }
  8691. }
  8692. function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
  8693. // Draws the given range as a highlighted selection
  8694. function drawSelectionRange(cm, range, output) {
  8695. var display = cm.display, doc = cm.doc;
  8696. var fragment = document.createDocumentFragment();
  8697. var padding = paddingH(cm.display), leftSide = padding.left;
  8698. var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
  8699. var docLTR = doc.direction == "ltr";
  8700. function add(left, top, width, bottom) {
  8701. if (top < 0) { top = 0; }
  8702. top = Math.round(top);
  8703. bottom = Math.round(bottom);
  8704. 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")));
  8705. }
  8706. function drawForLine(line, fromArg, toArg) {
  8707. var lineObj = getLine(doc, line);
  8708. var lineLen = lineObj.text.length;
  8709. var start, end;
  8710. function coords(ch, bias) {
  8711. return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
  8712. }
  8713. function wrapX(pos, dir, side) {
  8714. var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
  8715. var prop = (dir == "ltr") == (side == "after") ? "left" : "right";
  8716. var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
  8717. return coords(ch, prop)[prop]
  8718. }
  8719. var order = getOrder(lineObj, doc.direction);
  8720. iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
  8721. var ltr = dir == "ltr";
  8722. var fromPos = coords(from, ltr ? "left" : "right");
  8723. var toPos = coords(to - 1, ltr ? "right" : "left");
  8724. var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
  8725. var first = i == 0, last = !order || i == order.length - 1;
  8726. if (toPos.top - fromPos.top <= 3) { // Single line
  8727. var openLeft = (docLTR ? openStart : openEnd) && first;
  8728. var openRight = (docLTR ? openEnd : openStart) && last;
  8729. var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
  8730. var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
  8731. add(left, fromPos.top, right - left, fromPos.bottom);
  8732. } else { // Multiple lines
  8733. var topLeft, topRight, botLeft, botRight;
  8734. if (ltr) {
  8735. topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
  8736. topRight = docLTR ? rightSide : wrapX(from, dir, "before");
  8737. botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
  8738. botRight = docLTR && openEnd && last ? rightSide : toPos.right;
  8739. } else {
  8740. topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
  8741. topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
  8742. botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
  8743. botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
  8744. }
  8745. add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
  8746. if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); }
  8747. add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
  8748. }
  8749. if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos; }
  8750. if (cmpCoords(toPos, start) < 0) { start = toPos; }
  8751. if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos; }
  8752. if (cmpCoords(toPos, end) < 0) { end = toPos; }
  8753. });
  8754. return {start: start, end: end}
  8755. }
  8756. var sFrom = range.from(), sTo = range.to();
  8757. if (sFrom.line == sTo.line) {
  8758. drawForLine(sFrom.line, sFrom.ch, sTo.ch);
  8759. } else {
  8760. var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
  8761. var singleVLine = visualLine(fromLine) == visualLine(toLine);
  8762. var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
  8763. var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
  8764. if (singleVLine) {
  8765. if (leftEnd.top < rightStart.top - 2) {
  8766. add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
  8767. add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
  8768. } else {
  8769. add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
  8770. }
  8771. }
  8772. if (leftEnd.bottom < rightStart.top)
  8773. { add(leftSide, leftEnd.bottom, null, rightStart.top); }
  8774. }
  8775. output.appendChild(fragment);
  8776. }
  8777. // Cursor-blinking
  8778. function restartBlink(cm) {
  8779. if (!cm.state.focused) { return }
  8780. var display = cm.display;
  8781. clearInterval(display.blinker);
  8782. var on = true;
  8783. display.cursorDiv.style.visibility = "";
  8784. if (cm.options.cursorBlinkRate > 0)
  8785. { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
  8786. cm.options.cursorBlinkRate); }
  8787. else if (cm.options.cursorBlinkRate < 0)
  8788. { display.cursorDiv.style.visibility = "hidden"; }
  8789. }
  8790. function ensureFocus(cm) {
  8791. if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
  8792. }
  8793. function delayBlurEvent(cm) {
  8794. cm.state.delayingBlurEvent = true;
  8795. setTimeout(function () { if (cm.state.delayingBlurEvent) {
  8796. cm.state.delayingBlurEvent = false;
  8797. onBlur(cm);
  8798. } }, 100);
  8799. }
  8800. function onFocus(cm, e) {
  8801. if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false; }
  8802. if (cm.options.readOnly == "nocursor") { return }
  8803. if (!cm.state.focused) {
  8804. signal(cm, "focus", cm, e);
  8805. cm.state.focused = true;
  8806. addClass(cm.display.wrapper, "CodeMirror-focused");
  8807. // This test prevents this from firing when a context
  8808. // menu is closed (since the input reset would kill the
  8809. // select-all detection hack)
  8810. if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
  8811. cm.display.input.reset();
  8812. if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730
  8813. }
  8814. cm.display.input.receivedFocus();
  8815. }
  8816. restartBlink(cm);
  8817. }
  8818. function onBlur(cm, e) {
  8819. if (cm.state.delayingBlurEvent) { return }
  8820. if (cm.state.focused) {
  8821. signal(cm, "blur", cm, e);
  8822. cm.state.focused = false;
  8823. rmClass(cm.display.wrapper, "CodeMirror-focused");
  8824. }
  8825. clearInterval(cm.display.blinker);
  8826. setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150);
  8827. }
  8828. // Read the actual heights of the rendered lines, and update their
  8829. // stored heights to match.
  8830. function updateHeightsInViewport(cm) {
  8831. var display = cm.display;
  8832. var prevBottom = display.lineDiv.offsetTop;
  8833. for (var i = 0; i < display.view.length; i++) {
  8834. var cur = display.view[i], wrapping = cm.options.lineWrapping;
  8835. var height = (void 0), width = 0;
  8836. if (cur.hidden) { continue }
  8837. if (ie && ie_version < 8) {
  8838. var bot = cur.node.offsetTop + cur.node.offsetHeight;
  8839. height = bot - prevBottom;
  8840. prevBottom = bot;
  8841. } else {
  8842. var box = cur.node.getBoundingClientRect();
  8843. height = box.bottom - box.top;
  8844. // Check that lines don't extend past the right of the current
  8845. // editor width
  8846. if (!wrapping && cur.text.firstChild)
  8847. { width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1; }
  8848. }
  8849. var diff = cur.line.height - height;
  8850. if (diff > .005 || diff < -.005) {
  8851. updateLineHeight(cur.line, height);
  8852. updateWidgetHeight(cur.line);
  8853. if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
  8854. { updateWidgetHeight(cur.rest[j]); } }
  8855. }
  8856. if (width > cm.display.sizerWidth) {
  8857. var chWidth = Math.ceil(width / charWidth(cm.display));
  8858. if (chWidth > cm.display.maxLineLength) {
  8859. cm.display.maxLineLength = chWidth;
  8860. cm.display.maxLine = cur.line;
  8861. cm.display.maxLineChanged = true;
  8862. }
  8863. }
  8864. }
  8865. }
  8866. // Read and store the height of line widgets associated with the
  8867. // given line.
  8868. function updateWidgetHeight(line) {
  8869. if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
  8870. var w = line.widgets[i], parent = w.node.parentNode;
  8871. if (parent) { w.height = parent.offsetHeight; }
  8872. } }
  8873. }
  8874. // Compute the lines that are visible in a given viewport (defaults
  8875. // the the current scroll position). viewport may contain top,
  8876. // height, and ensure (see op.scrollToPos) properties.
  8877. function visibleLines(display, doc, viewport) {
  8878. var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
  8879. top = Math.floor(top - paddingTop(display));
  8880. var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
  8881. var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
  8882. // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
  8883. // forces those lines into the viewport (if possible).
  8884. if (viewport && viewport.ensure) {
  8885. var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
  8886. if (ensureFrom < from) {
  8887. from = ensureFrom;
  8888. to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
  8889. } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
  8890. from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
  8891. to = ensureTo;
  8892. }
  8893. }
  8894. return {from: from, to: Math.max(to, from + 1)}
  8895. }
  8896. // SCROLLING THINGS INTO VIEW
  8897. // If an editor sits on the top or bottom of the window, partially
  8898. // scrolled out of view, this ensures that the cursor is visible.
  8899. function maybeScrollWindow(cm, rect) {
  8900. if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
  8901. var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
  8902. if (rect.top + box.top < 0) { doScroll = true; }
  8903. else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; }
  8904. if (doScroll != null && !phantom) {
  8905. 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;"));
  8906. cm.display.lineSpace.appendChild(scrollNode);
  8907. scrollNode.scrollIntoView(doScroll);
  8908. cm.display.lineSpace.removeChild(scrollNode);
  8909. }
  8910. }
  8911. // Scroll a given position into view (immediately), verifying that
  8912. // it actually became visible (as line heights are accurately
  8913. // measured, the position of something may 'drift' during drawing).
  8914. function scrollPosIntoView(cm, pos, end, margin) {
  8915. if (margin == null) { margin = 0; }
  8916. var rect;
  8917. if (!cm.options.lineWrapping && pos == end) {
  8918. // Set pos and end to the cursor positions around the character pos sticks to
  8919. // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
  8920. // If pos == Pos(_, 0, "before"), pos and end are unchanged
  8921. pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
  8922. end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
  8923. }
  8924. for (var limit = 0; limit < 5; limit++) {
  8925. var changed = false;
  8926. var coords = cursorCoords(cm, pos);
  8927. var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
  8928. rect = {left: Math.min(coords.left, endCoords.left),
  8929. top: Math.min(coords.top, endCoords.top) - margin,
  8930. right: Math.max(coords.left, endCoords.left),
  8931. bottom: Math.max(coords.bottom, endCoords.bottom) + margin};
  8932. var scrollPos = calculateScrollPos(cm, rect);
  8933. var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
  8934. if (scrollPos.scrollTop != null) {
  8935. updateScrollTop(cm, scrollPos.scrollTop);
  8936. if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; }
  8937. }
  8938. if (scrollPos.scrollLeft != null) {
  8939. setScrollLeft(cm, scrollPos.scrollLeft);
  8940. if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; }
  8941. }
  8942. if (!changed) { break }
  8943. }
  8944. return rect
  8945. }
  8946. // Scroll a given set of coordinates into view (immediately).
  8947. function scrollIntoView(cm, rect) {
  8948. var scrollPos = calculateScrollPos(cm, rect);
  8949. if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop); }
  8950. if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); }
  8951. }
  8952. // Calculate a new scroll position needed to scroll the given
  8953. // rectangle into view. Returns an object with scrollTop and
  8954. // scrollLeft properties. When these are undefined, the
  8955. // vertical/horizontal position does not need to be adjusted.
  8956. function calculateScrollPos(cm, rect) {
  8957. var display = cm.display, snapMargin = textHeight(cm.display);
  8958. if (rect.top < 0) { rect.top = 0; }
  8959. var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
  8960. var screen = displayHeight(cm), result = {};
  8961. if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; }
  8962. var docBottom = cm.doc.height + paddingVert(display);
  8963. var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
  8964. if (rect.top < screentop) {
  8965. result.scrollTop = atTop ? 0 : rect.top;
  8966. } else if (rect.bottom > screentop + screen) {
  8967. var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
  8968. if (newTop != screentop) { result.scrollTop = newTop; }
  8969. }
  8970. var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
  8971. var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
  8972. var tooWide = rect.right - rect.left > screenw;
  8973. if (tooWide) { rect.right = rect.left + screenw; }
  8974. if (rect.left < 10)
  8975. { result.scrollLeft = 0; }
  8976. else if (rect.left < screenleft)
  8977. { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)); }
  8978. else if (rect.right > screenw + screenleft - 3)
  8979. { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; }
  8980. return result
  8981. }
  8982. // Store a relative adjustment to the scroll position in the current
  8983. // operation (to be applied when the operation finishes).
  8984. function addToScrollTop(cm, top) {
  8985. if (top == null) { return }
  8986. resolveScrollToPos(cm);
  8987. cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
  8988. }
  8989. // Make sure that at the end of the operation the current cursor is
  8990. // shown.
  8991. function ensureCursorVisible(cm) {
  8992. resolveScrollToPos(cm);
  8993. var cur = cm.getCursor();
  8994. cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin};
  8995. }
  8996. function scrollToCoords(cm, x, y) {
  8997. if (x != null || y != null) { resolveScrollToPos(cm); }
  8998. if (x != null) { cm.curOp.scrollLeft = x; }
  8999. if (y != null) { cm.curOp.scrollTop = y; }
  9000. }
  9001. function scrollToRange(cm, range) {
  9002. resolveScrollToPos(cm);
  9003. cm.curOp.scrollToPos = range;
  9004. }
  9005. // When an operation has its scrollToPos property set, and another
  9006. // scroll action is applied before the end of the operation, this
  9007. // 'simulates' scrolling that position into view in a cheap way, so
  9008. // that the effect of intermediate scroll commands is not ignored.
  9009. function resolveScrollToPos(cm) {
  9010. var range = cm.curOp.scrollToPos;
  9011. if (range) {
  9012. cm.curOp.scrollToPos = null;
  9013. var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
  9014. scrollToCoordsRange(cm, from, to, range.margin);
  9015. }
  9016. }
  9017. function scrollToCoordsRange(cm, from, to, margin) {
  9018. var sPos = calculateScrollPos(cm, {
  9019. left: Math.min(from.left, to.left),
  9020. top: Math.min(from.top, to.top) - margin,
  9021. right: Math.max(from.right, to.right),
  9022. bottom: Math.max(from.bottom, to.bottom) + margin
  9023. });
  9024. scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
  9025. }
  9026. // Sync the scrollable area and scrollbars, ensure the viewport
  9027. // covers the visible area.
  9028. function updateScrollTop(cm, val) {
  9029. if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
  9030. if (!gecko) { updateDisplaySimple(cm, {top: val}); }
  9031. setScrollTop(cm, val, true);
  9032. if (gecko) { updateDisplaySimple(cm); }
  9033. startWorker(cm, 100);
  9034. }
  9035. function setScrollTop(cm, val, forceScroll) {
  9036. val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val));
  9037. if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
  9038. cm.doc.scrollTop = val;
  9039. cm.display.scrollbars.setScrollTop(val);
  9040. if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; }
  9041. }
  9042. // Sync scroller and scrollbar, ensure the gutter elements are
  9043. // aligned.
  9044. function setScrollLeft(cm, val, isScroller, forceScroll) {
  9045. val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth));
  9046. if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
  9047. cm.doc.scrollLeft = val;
  9048. alignHorizontally(cm);
  9049. if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; }
  9050. cm.display.scrollbars.setScrollLeft(val);
  9051. }
  9052. // SCROLLBARS
  9053. // Prepare DOM reads needed to update the scrollbars. Done in one
  9054. // shot to minimize update/measure roundtrips.
  9055. function measureForScrollbars(cm) {
  9056. var d = cm.display, gutterW = d.gutters.offsetWidth;
  9057. var docH = Math.round(cm.doc.height + paddingVert(cm.display));
  9058. return {
  9059. clientHeight: d.scroller.clientHeight,
  9060. viewHeight: d.wrapper.clientHeight,
  9061. scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
  9062. viewWidth: d.wrapper.clientWidth,
  9063. barLeft: cm.options.fixedGutter ? gutterW : 0,
  9064. docHeight: docH,
  9065. scrollHeight: docH + scrollGap(cm) + d.barHeight,
  9066. nativeBarWidth: d.nativeBarWidth,
  9067. gutterWidth: gutterW
  9068. }
  9069. }
  9070. var NativeScrollbars = function(place, scroll, cm) {
  9071. this.cm = cm;
  9072. var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
  9073. var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
  9074. vert.tabIndex = horiz.tabIndex = -1;
  9075. place(vert); place(horiz);
  9076. on(vert, "scroll", function () {
  9077. if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); }
  9078. });
  9079. on(horiz, "scroll", function () {
  9080. if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); }
  9081. });
  9082. this.checkedZeroWidth = false;
  9083. // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
  9084. if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; }
  9085. };
  9086. NativeScrollbars.prototype.update = function (measure) {
  9087. var needsH = measure.scrollWidth > measure.clientWidth + 1;
  9088. var needsV = measure.scrollHeight > measure.clientHeight + 1;
  9089. var sWidth = measure.nativeBarWidth;
  9090. if (needsV) {
  9091. this.vert.style.display = "block";
  9092. this.vert.style.bottom = needsH ? sWidth + "px" : "0";
  9093. var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
  9094. // A bug in IE8 can cause this value to be negative, so guard it.
  9095. this.vert.firstChild.style.height =
  9096. Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
  9097. } else {
  9098. this.vert.style.display = "";
  9099. this.vert.firstChild.style.height = "0";
  9100. }
  9101. if (needsH) {
  9102. this.horiz.style.display = "block";
  9103. this.horiz.style.right = needsV ? sWidth + "px" : "0";
  9104. this.horiz.style.left = measure.barLeft + "px";
  9105. var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
  9106. this.horiz.firstChild.style.width =
  9107. Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
  9108. } else {
  9109. this.horiz.style.display = "";
  9110. this.horiz.firstChild.style.width = "0";
  9111. }
  9112. if (!this.checkedZeroWidth && measure.clientHeight > 0) {
  9113. if (sWidth == 0) { this.zeroWidthHack(); }
  9114. this.checkedZeroWidth = true;
  9115. }
  9116. return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
  9117. };
  9118. NativeScrollbars.prototype.setScrollLeft = function (pos) {
  9119. if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; }
  9120. if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz"); }
  9121. };
  9122. NativeScrollbars.prototype.setScrollTop = function (pos) {
  9123. if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; }
  9124. if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert"); }
  9125. };
  9126. NativeScrollbars.prototype.zeroWidthHack = function () {
  9127. var w = mac && !mac_geMountainLion ? "12px" : "18px";
  9128. this.horiz.style.height = this.vert.style.width = w;
  9129. this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
  9130. this.disableHoriz = new Delayed;
  9131. this.disableVert = new Delayed;
  9132. };
  9133. NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
  9134. bar.style.pointerEvents = "auto";
  9135. function maybeDisable() {
  9136. // To find out whether the scrollbar is still visible, we
  9137. // check whether the element under the pixel in the bottom
  9138. // right corner of the scrollbar box is the scrollbar box
  9139. // itself (when the bar is still visible) or its filler child
  9140. // (when the bar is hidden). If it is still visible, we keep
  9141. // it enabled, if it's hidden, we disable pointer events.
  9142. var box = bar.getBoundingClientRect();
  9143. var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
  9144. : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
  9145. if (elt != bar) { bar.style.pointerEvents = "none"; }
  9146. else { delay.set(1000, maybeDisable); }
  9147. }
  9148. delay.set(1000, maybeDisable);
  9149. };
  9150. NativeScrollbars.prototype.clear = function () {
  9151. var parent = this.horiz.parentNode;
  9152. parent.removeChild(this.horiz);
  9153. parent.removeChild(this.vert);
  9154. };
  9155. var NullScrollbars = function () {};
  9156. NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
  9157. NullScrollbars.prototype.setScrollLeft = function () {};
  9158. NullScrollbars.prototype.setScrollTop = function () {};
  9159. NullScrollbars.prototype.clear = function () {};
  9160. function updateScrollbars(cm, measure) {
  9161. if (!measure) { measure = measureForScrollbars(cm); }
  9162. var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
  9163. updateScrollbarsInner(cm, measure);
  9164. for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
  9165. if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
  9166. { updateHeightsInViewport(cm); }
  9167. updateScrollbarsInner(cm, measureForScrollbars(cm));
  9168. startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
  9169. }
  9170. }
  9171. // Re-synchronize the fake scrollbars with the actual size of the
  9172. // content.
  9173. function updateScrollbarsInner(cm, measure) {
  9174. var d = cm.display;
  9175. var sizes = d.scrollbars.update(measure);
  9176. d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
  9177. d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
  9178. d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
  9179. if (sizes.right && sizes.bottom) {
  9180. d.scrollbarFiller.style.display = "block";
  9181. d.scrollbarFiller.style.height = sizes.bottom + "px";
  9182. d.scrollbarFiller.style.width = sizes.right + "px";
  9183. } else { d.scrollbarFiller.style.display = ""; }
  9184. if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
  9185. d.gutterFiller.style.display = "block";
  9186. d.gutterFiller.style.height = sizes.bottom + "px";
  9187. d.gutterFiller.style.width = measure.gutterWidth + "px";
  9188. } else { d.gutterFiller.style.display = ""; }
  9189. }
  9190. var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
  9191. function initScrollbars(cm) {
  9192. if (cm.display.scrollbars) {
  9193. cm.display.scrollbars.clear();
  9194. if (cm.display.scrollbars.addClass)
  9195. { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
  9196. }
  9197. cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
  9198. cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
  9199. // Prevent clicks in the scrollbars from killing focus
  9200. on(node, "mousedown", function () {
  9201. if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); }
  9202. });
  9203. node.setAttribute("cm-not-content", "true");
  9204. }, function (pos, axis) {
  9205. if (axis == "horizontal") { setScrollLeft(cm, pos); }
  9206. else { updateScrollTop(cm, pos); }
  9207. }, cm);
  9208. if (cm.display.scrollbars.addClass)
  9209. { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
  9210. }
  9211. // Operations are used to wrap a series of changes to the editor
  9212. // state in such a way that each change won't have to update the
  9213. // cursor and display (which would be awkward, slow, and
  9214. // error-prone). Instead, display updates are batched and then all
  9215. // combined and executed at once.
  9216. var nextOpId = 0;
  9217. // Start a new operation.
  9218. function startOperation(cm) {
  9219. cm.curOp = {
  9220. cm: cm,
  9221. viewChanged: false, // Flag that indicates that lines might need to be redrawn
  9222. startHeight: cm.doc.height, // Used to detect need to update scrollbar
  9223. forceUpdate: false, // Used to force a redraw
  9224. updateInput: 0, // Whether to reset the input textarea
  9225. typing: false, // Whether this reset should be careful to leave existing text (for compositing)
  9226. changeObjs: null, // Accumulated changes, for firing change events
  9227. cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
  9228. cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
  9229. selectionChanged: false, // Whether the selection needs to be redrawn
  9230. updateMaxLine: false, // Set when the widest line needs to be determined anew
  9231. scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
  9232. scrollToPos: null, // Used to scroll to a specific position
  9233. focus: false,
  9234. id: ++nextOpId // Unique ID
  9235. };
  9236. pushOperation(cm.curOp);
  9237. }
  9238. // Finish an operation, updating the display and signalling delayed events
  9239. function endOperation(cm) {
  9240. var op = cm.curOp;
  9241. if (op) { finishOperation(op, function (group) {
  9242. for (var i = 0; i < group.ops.length; i++)
  9243. { group.ops[i].cm.curOp = null; }
  9244. endOperations(group);
  9245. }); }
  9246. }
  9247. // The DOM updates done when an operation finishes are batched so
  9248. // that the minimum number of relayouts are required.
  9249. function endOperations(group) {
  9250. var ops = group.ops;
  9251. for (var i = 0; i < ops.length; i++) // Read DOM
  9252. { endOperation_R1(ops[i]); }
  9253. for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
  9254. { endOperation_W1(ops[i$1]); }
  9255. for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
  9256. { endOperation_R2(ops[i$2]); }
  9257. for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
  9258. { endOperation_W2(ops[i$3]); }
  9259. for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
  9260. { endOperation_finish(ops[i$4]); }
  9261. }
  9262. function endOperation_R1(op) {
  9263. var cm = op.cm, display = cm.display;
  9264. maybeClipScrollbars(cm);
  9265. if (op.updateMaxLine) { findMaxLine(cm); }
  9266. op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
  9267. op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
  9268. op.scrollToPos.to.line >= display.viewTo) ||
  9269. display.maxLineChanged && cm.options.lineWrapping;
  9270. op.update = op.mustUpdate &&
  9271. new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
  9272. }
  9273. function endOperation_W1(op) {
  9274. op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
  9275. }
  9276. function endOperation_R2(op) {
  9277. var cm = op.cm, display = cm.display;
  9278. if (op.updatedDisplay) { updateHeightsInViewport(cm); }
  9279. op.barMeasure = measureForScrollbars(cm);
  9280. // If the max line changed since it was last measured, measure it,
  9281. // and ensure the document's width matches it.
  9282. // updateDisplay_W2 will use these properties to do the actual resizing
  9283. if (display.maxLineChanged && !cm.options.lineWrapping) {
  9284. op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
  9285. cm.display.sizerWidth = op.adjustWidthTo;
  9286. op.barMeasure.scrollWidth =
  9287. Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
  9288. op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
  9289. }
  9290. if (op.updatedDisplay || op.selectionChanged)
  9291. { op.preparedSelection = display.input.prepareSelection(); }
  9292. }
  9293. function endOperation_W2(op) {
  9294. var cm = op.cm;
  9295. if (op.adjustWidthTo != null) {
  9296. cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
  9297. if (op.maxScrollLeft < cm.doc.scrollLeft)
  9298. { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); }
  9299. cm.display.maxLineChanged = false;
  9300. }
  9301. var takeFocus = op.focus && op.focus == activeElt();
  9302. if (op.preparedSelection)
  9303. { cm.display.input.showSelection(op.preparedSelection, takeFocus); }
  9304. if (op.updatedDisplay || op.startHeight != cm.doc.height)
  9305. { updateScrollbars(cm, op.barMeasure); }
  9306. if (op.updatedDisplay)
  9307. { setDocumentHeight(cm, op.barMeasure); }
  9308. if (op.selectionChanged) { restartBlink(cm); }
  9309. if (cm.state.focused && op.updateInput)
  9310. { cm.display.input.reset(op.typing); }
  9311. if (takeFocus) { ensureFocus(op.cm); }
  9312. }
  9313. function endOperation_finish(op) {
  9314. var cm = op.cm, display = cm.display, doc = cm.doc;
  9315. if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); }
  9316. // Abort mouse wheel delta measurement, when scrolling explicitly
  9317. if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
  9318. { display.wheelStartX = display.wheelStartY = null; }
  9319. // Propagate the scroll position to the actual DOM scroller
  9320. if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll); }
  9321. if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true); }
  9322. // If we need to scroll a specific position into view, do so.
  9323. if (op.scrollToPos) {
  9324. var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
  9325. clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
  9326. maybeScrollWindow(cm, rect);
  9327. }
  9328. // Fire events for markers that are hidden/unidden by editing or
  9329. // undoing
  9330. var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
  9331. if (hidden) { for (var i = 0; i < hidden.length; ++i)
  9332. { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } }
  9333. if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
  9334. { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } }
  9335. if (display.wrapper.offsetHeight)
  9336. { doc.scrollTop = cm.display.scroller.scrollTop; }
  9337. // Fire change events, and delayed event handlers
  9338. if (op.changeObjs)
  9339. { signal(cm, "changes", cm, op.changeObjs); }
  9340. if (op.update)
  9341. { op.update.finish(); }
  9342. }
  9343. // Run the given function in an operation
  9344. function runInOp(cm, f) {
  9345. if (cm.curOp) { return f() }
  9346. startOperation(cm);
  9347. try { return f() }
  9348. finally { endOperation(cm); }
  9349. }
  9350. // Wraps a function in an operation. Returns the wrapped function.
  9351. function operation(cm, f) {
  9352. return function() {
  9353. if (cm.curOp) { return f.apply(cm, arguments) }
  9354. startOperation(cm);
  9355. try { return f.apply(cm, arguments) }
  9356. finally { endOperation(cm); }
  9357. }
  9358. }
  9359. // Used to add methods to editor and doc instances, wrapping them in
  9360. // operations.
  9361. function methodOp(f) {
  9362. return function() {
  9363. if (this.curOp) { return f.apply(this, arguments) }
  9364. startOperation(this);
  9365. try { return f.apply(this, arguments) }
  9366. finally { endOperation(this); }
  9367. }
  9368. }
  9369. function docMethodOp(f) {
  9370. return function() {
  9371. var cm = this.cm;
  9372. if (!cm || cm.curOp) { return f.apply(this, arguments) }
  9373. startOperation(cm);
  9374. try { return f.apply(this, arguments) }
  9375. finally { endOperation(cm); }
  9376. }
  9377. }
  9378. // HIGHLIGHT WORKER
  9379. function startWorker(cm, time) {
  9380. if (cm.doc.highlightFrontier < cm.display.viewTo)
  9381. { cm.state.highlight.set(time, bind(highlightWorker, cm)); }
  9382. }
  9383. function highlightWorker(cm) {
  9384. var doc = cm.doc;
  9385. if (doc.highlightFrontier >= cm.display.viewTo) { return }
  9386. var end = +new Date + cm.options.workTime;
  9387. var context = getContextBefore(cm, doc.highlightFrontier);
  9388. var changedLines = [];
  9389. doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
  9390. if (context.line >= cm.display.viewFrom) { // Visible
  9391. var oldStyles = line.styles;
  9392. var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;
  9393. var highlighted = highlightLine(cm, line, context, true);
  9394. if (resetState) { context.state = resetState; }
  9395. line.styles = highlighted.styles;
  9396. var oldCls = line.styleClasses, newCls = highlighted.classes;
  9397. if (newCls) { line.styleClasses = newCls; }
  9398. else if (oldCls) { line.styleClasses = null; }
  9399. var ischange = !oldStyles || oldStyles.length != line.styles.length ||
  9400. oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
  9401. for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; }
  9402. if (ischange) { changedLines.push(context.line); }
  9403. line.stateAfter = context.save();
  9404. context.nextLine();
  9405. } else {
  9406. if (line.text.length <= cm.options.maxHighlightLength)
  9407. { processLine(cm, line.text, context); }
  9408. line.stateAfter = context.line % 5 == 0 ? context.save() : null;
  9409. context.nextLine();
  9410. }
  9411. if (+new Date > end) {
  9412. startWorker(cm, cm.options.workDelay);
  9413. return true
  9414. }
  9415. });
  9416. doc.highlightFrontier = context.line;
  9417. doc.modeFrontier = Math.max(doc.modeFrontier, context.line);
  9418. if (changedLines.length) { runInOp(cm, function () {
  9419. for (var i = 0; i < changedLines.length; i++)
  9420. { regLineChange(cm, changedLines[i], "text"); }
  9421. }); }
  9422. }
  9423. // DISPLAY DRAWING
  9424. var DisplayUpdate = function(cm, viewport, force) {
  9425. var display = cm.display;
  9426. this.viewport = viewport;
  9427. // Store some values that we'll need later (but don't want to force a relayout for)
  9428. this.visible = visibleLines(display, cm.doc, viewport);
  9429. this.editorIsHidden = !display.wrapper.offsetWidth;
  9430. this.wrapperHeight = display.wrapper.clientHeight;
  9431. this.wrapperWidth = display.wrapper.clientWidth;
  9432. this.oldDisplayWidth = displayWidth(cm);
  9433. this.force = force;
  9434. this.dims = getDimensions(cm);
  9435. this.events = [];
  9436. };
  9437. DisplayUpdate.prototype.signal = function (emitter, type) {
  9438. if (hasHandler(emitter, type))
  9439. { this.events.push(arguments); }
  9440. };
  9441. DisplayUpdate.prototype.finish = function () {
  9442. for (var i = 0; i < this.events.length; i++)
  9443. { signal.apply(null, this.events[i]); }
  9444. };
  9445. function maybeClipScrollbars(cm) {
  9446. var display = cm.display;
  9447. if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
  9448. display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
  9449. display.heightForcer.style.height = scrollGap(cm) + "px";
  9450. display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
  9451. display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
  9452. display.scrollbarsClipped = true;
  9453. }
  9454. }
  9455. function selectionSnapshot(cm) {
  9456. if (cm.hasFocus()) { return null }
  9457. var active = activeElt();
  9458. if (!active || !contains(cm.display.lineDiv, active)) { return null }
  9459. var result = {activeElt: active};
  9460. if (window.getSelection) {
  9461. var sel = window.getSelection();
  9462. if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
  9463. result.anchorNode = sel.anchorNode;
  9464. result.anchorOffset = sel.anchorOffset;
  9465. result.focusNode = sel.focusNode;
  9466. result.focusOffset = sel.focusOffset;
  9467. }
  9468. }
  9469. return result
  9470. }
  9471. function restoreSelection(snapshot) {
  9472. if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
  9473. snapshot.activeElt.focus();
  9474. if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
  9475. var sel = window.getSelection(), range = document.createRange();
  9476. range.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
  9477. range.collapse(false);
  9478. sel.removeAllRanges();
  9479. sel.addRange(range);
  9480. sel.extend(snapshot.focusNode, snapshot.focusOffset);
  9481. }
  9482. }
  9483. // Does the actual updating of the line display. Bails out
  9484. // (returning false) when there is nothing to be done and forced is
  9485. // false.
  9486. function updateDisplayIfNeeded(cm, update) {
  9487. var display = cm.display, doc = cm.doc;
  9488. if (update.editorIsHidden) {
  9489. resetView(cm);
  9490. return false
  9491. }
  9492. // Bail out if the visible area is already rendered and nothing changed.
  9493. if (!update.force &&
  9494. update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
  9495. (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
  9496. display.renderedView == display.view && countDirtyView(cm) == 0)
  9497. { return false }
  9498. if (maybeUpdateLineNumberWidth(cm)) {
  9499. resetView(cm);
  9500. update.dims = getDimensions(cm);
  9501. }
  9502. // Compute a suitable new viewport (from & to)
  9503. var end = doc.first + doc.size;
  9504. var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
  9505. var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
  9506. if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
  9507. if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
  9508. if (sawCollapsedSpans) {
  9509. from = visualLineNo(cm.doc, from);
  9510. to = visualLineEndNo(cm.doc, to);
  9511. }
  9512. var different = from != display.viewFrom || to != display.viewTo ||
  9513. display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
  9514. adjustView(cm, from, to);
  9515. display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
  9516. // Position the mover div to align with the current scroll position
  9517. cm.display.mover.style.top = display.viewOffset + "px";
  9518. var toUpdate = countDirtyView(cm);
  9519. if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
  9520. (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
  9521. { return false }
  9522. // For big changes, we hide the enclosing element during the
  9523. // update, since that speeds up the operations on most browsers.
  9524. var selSnapshot = selectionSnapshot(cm);
  9525. if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
  9526. patchDisplay(cm, display.updateLineNumbers, update.dims);
  9527. if (toUpdate > 4) { display.lineDiv.style.display = ""; }
  9528. display.renderedView = display.view;
  9529. // There might have been a widget with a focused element that got
  9530. // hidden or updated, if so re-focus it.
  9531. restoreSelection(selSnapshot);
  9532. // Prevent selection and cursors from interfering with the scroll
  9533. // width and height.
  9534. removeChildren(display.cursorDiv);
  9535. removeChildren(display.selectionDiv);
  9536. display.gutters.style.height = display.sizer.style.minHeight = 0;
  9537. if (different) {
  9538. display.lastWrapHeight = update.wrapperHeight;
  9539. display.lastWrapWidth = update.wrapperWidth;
  9540. startWorker(cm, 400);
  9541. }
  9542. display.updateLineNumbers = null;
  9543. return true
  9544. }
  9545. function postUpdateDisplay(cm, update) {
  9546. var viewport = update.viewport;
  9547. for (var first = true;; first = false) {
  9548. if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
  9549. // Clip forced viewport to actual scrollable area.
  9550. if (viewport && viewport.top != null)
  9551. { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; }
  9552. // Updated line heights might result in the drawn area not
  9553. // actually covering the viewport. Keep looping until it does.
  9554. update.visible = visibleLines(cm.display, cm.doc, viewport);
  9555. if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
  9556. { break }
  9557. } else if (first) {
  9558. update.visible = visibleLines(cm.display, cm.doc, viewport);
  9559. }
  9560. if (!updateDisplayIfNeeded(cm, update)) { break }
  9561. updateHeightsInViewport(cm);
  9562. var barMeasure = measureForScrollbars(cm);
  9563. updateSelection(cm);
  9564. updateScrollbars(cm, barMeasure);
  9565. setDocumentHeight(cm, barMeasure);
  9566. update.force = false;
  9567. }
  9568. update.signal(cm, "update", cm);
  9569. if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
  9570. update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
  9571. cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
  9572. }
  9573. }
  9574. function updateDisplaySimple(cm, viewport) {
  9575. var update = new DisplayUpdate(cm, viewport);
  9576. if (updateDisplayIfNeeded(cm, update)) {
  9577. updateHeightsInViewport(cm);
  9578. postUpdateDisplay(cm, update);
  9579. var barMeasure = measureForScrollbars(cm);
  9580. updateSelection(cm);
  9581. updateScrollbars(cm, barMeasure);
  9582. setDocumentHeight(cm, barMeasure);
  9583. update.finish();
  9584. }
  9585. }
  9586. // Sync the actual display DOM structure with display.view, removing
  9587. // nodes for lines that are no longer in view, and creating the ones
  9588. // that are not there yet, and updating the ones that are out of
  9589. // date.
  9590. function patchDisplay(cm, updateNumbersFrom, dims) {
  9591. var display = cm.display, lineNumbers = cm.options.lineNumbers;
  9592. var container = display.lineDiv, cur = container.firstChild;
  9593. function rm(node) {
  9594. var next = node.nextSibling;
  9595. // Works around a throw-scroll bug in OS X Webkit
  9596. if (webkit && mac && cm.display.currentWheelTarget == node)
  9597. { node.style.display = "none"; }
  9598. else
  9599. { node.parentNode.removeChild(node); }
  9600. return next
  9601. }
  9602. var view = display.view, lineN = display.viewFrom;
  9603. // Loop over the elements in the view, syncing cur (the DOM nodes
  9604. // in display.lineDiv) with the view as we go.
  9605. for (var i = 0; i < view.length; i++) {
  9606. var lineView = view[i];
  9607. if (lineView.hidden) ; else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
  9608. var node = buildLineElement(cm, lineView, lineN, dims);
  9609. container.insertBefore(node, cur);
  9610. } else { // Already drawn
  9611. while (cur != lineView.node) { cur = rm(cur); }
  9612. var updateNumber = lineNumbers && updateNumbersFrom != null &&
  9613. updateNumbersFrom <= lineN && lineView.lineNumber;
  9614. if (lineView.changes) {
  9615. if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; }
  9616. updateLineForChanges(cm, lineView, lineN, dims);
  9617. }
  9618. if (updateNumber) {
  9619. removeChildren(lineView.lineNumber);
  9620. lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
  9621. }
  9622. cur = lineView.node.nextSibling;
  9623. }
  9624. lineN += lineView.size;
  9625. }
  9626. while (cur) { cur = rm(cur); }
  9627. }
  9628. function updateGutterSpace(display) {
  9629. var width = display.gutters.offsetWidth;
  9630. display.sizer.style.marginLeft = width + "px";
  9631. }
  9632. function setDocumentHeight(cm, measure) {
  9633. cm.display.sizer.style.minHeight = measure.docHeight + "px";
  9634. cm.display.heightForcer.style.top = measure.docHeight + "px";
  9635. cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
  9636. }
  9637. // Re-align line numbers and gutter marks to compensate for
  9638. // horizontal scrolling.
  9639. function alignHorizontally(cm) {
  9640. var display = cm.display, view = display.view;
  9641. if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
  9642. var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
  9643. var gutterW = display.gutters.offsetWidth, left = comp + "px";
  9644. for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
  9645. if (cm.options.fixedGutter) {
  9646. if (view[i].gutter)
  9647. { view[i].gutter.style.left = left; }
  9648. if (view[i].gutterBackground)
  9649. { view[i].gutterBackground.style.left = left; }
  9650. }
  9651. var align = view[i].alignable;
  9652. if (align) { for (var j = 0; j < align.length; j++)
  9653. { align[j].style.left = left; } }
  9654. } }
  9655. if (cm.options.fixedGutter)
  9656. { display.gutters.style.left = (comp + gutterW) + "px"; }
  9657. }
  9658. // Used to ensure that the line number gutter is still the right
  9659. // size for the current document size. Returns true when an update
  9660. // is needed.
  9661. function maybeUpdateLineNumberWidth(cm) {
  9662. if (!cm.options.lineNumbers) { return false }
  9663. var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
  9664. if (last.length != display.lineNumChars) {
  9665. var test = display.measure.appendChild(elt("div", [elt("div", last)],
  9666. "CodeMirror-linenumber CodeMirror-gutter-elt"));
  9667. var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
  9668. display.lineGutter.style.width = "";
  9669. display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
  9670. display.lineNumWidth = display.lineNumInnerWidth + padding;
  9671. display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
  9672. display.lineGutter.style.width = display.lineNumWidth + "px";
  9673. updateGutterSpace(cm.display);
  9674. return true
  9675. }
  9676. return false
  9677. }
  9678. function getGutters(gutters, lineNumbers) {
  9679. var result = [], sawLineNumbers = false;
  9680. for (var i = 0; i < gutters.length; i++) {
  9681. var name = gutters[i], style = null;
  9682. if (typeof name != "string") { style = name.style; name = name.className; }
  9683. if (name == "CodeMirror-linenumbers") {
  9684. if (!lineNumbers) { continue }
  9685. else { sawLineNumbers = true; }
  9686. }
  9687. result.push({className: name, style: style});
  9688. }
  9689. if (lineNumbers && !sawLineNumbers) { result.push({className: "CodeMirror-linenumbers", style: null}); }
  9690. return result
  9691. }
  9692. // Rebuild the gutter elements, ensure the margin to the left of the
  9693. // code matches their width.
  9694. function renderGutters(display) {
  9695. var gutters = display.gutters, specs = display.gutterSpecs;
  9696. removeChildren(gutters);
  9697. display.lineGutter = null;
  9698. for (var i = 0; i < specs.length; ++i) {
  9699. var ref = specs[i];
  9700. var className = ref.className;
  9701. var style = ref.style;
  9702. var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + className));
  9703. if (style) { gElt.style.cssText = style; }
  9704. if (className == "CodeMirror-linenumbers") {
  9705. display.lineGutter = gElt;
  9706. gElt.style.width = (display.lineNumWidth || 1) + "px";
  9707. }
  9708. }
  9709. gutters.style.display = specs.length ? "" : "none";
  9710. updateGutterSpace(display);
  9711. }
  9712. function updateGutters(cm) {
  9713. renderGutters(cm.display);
  9714. regChange(cm);
  9715. alignHorizontally(cm);
  9716. }
  9717. // The display handles the DOM integration, both for input reading
  9718. // and content drawing. It holds references to DOM nodes and
  9719. // display-related state.
  9720. function Display(place, doc, input, options) {
  9721. var d = this;
  9722. this.input = input;
  9723. // Covers bottom-right square when both scrollbars are present.
  9724. d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
  9725. d.scrollbarFiller.setAttribute("cm-not-content", "true");
  9726. // Covers bottom of gutter when coverGutterNextToScrollbar is on
  9727. // and h scrollbar is present.
  9728. d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
  9729. d.gutterFiller.setAttribute("cm-not-content", "true");
  9730. // Will contain the actual code, positioned to cover the viewport.
  9731. d.lineDiv = eltP("div", null, "CodeMirror-code");
  9732. // Elements are added to these to represent selection and cursors.
  9733. d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
  9734. d.cursorDiv = elt("div", null, "CodeMirror-cursors");
  9735. // A visibility: hidden element used to find the size of things.
  9736. d.measure = elt("div", null, "CodeMirror-measure");
  9737. // When lines outside of the viewport are measured, they are drawn in this.
  9738. d.lineMeasure = elt("div", null, "CodeMirror-measure");
  9739. // Wraps everything that needs to exist inside the vertically-padded coordinate system
  9740. d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
  9741. null, "position: relative; outline: none");
  9742. var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
  9743. // Moved around its parent to cover visible view.
  9744. d.mover = elt("div", [lines], null, "position: relative");
  9745. // Set to the height of the document, allowing scrolling.
  9746. d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
  9747. d.sizerWidth = null;
  9748. // Behavior of elts with overflow: auto and padding is
  9749. // inconsistent across browsers. This is used to ensure the
  9750. // scrollable area is big enough.
  9751. d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
  9752. // Will contain the gutters, if any.
  9753. d.gutters = elt("div", null, "CodeMirror-gutters");
  9754. d.lineGutter = null;
  9755. // Actual scrollable element.
  9756. d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
  9757. d.scroller.setAttribute("tabIndex", "-1");
  9758. // The element in which the editor lives.
  9759. d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
  9760. // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
  9761. if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
  9762. if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; }
  9763. if (place) {
  9764. if (place.appendChild) { place.appendChild(d.wrapper); }
  9765. else { place(d.wrapper); }
  9766. }
  9767. // Current rendered range (may be bigger than the view window).
  9768. d.viewFrom = d.viewTo = doc.first;
  9769. d.reportedViewFrom = d.reportedViewTo = doc.first;
  9770. // Information about the rendered lines.
  9771. d.view = [];
  9772. d.renderedView = null;
  9773. // Holds info about a single rendered line when it was rendered
  9774. // for measurement, while not in view.
  9775. d.externalMeasured = null;
  9776. // Empty space (in pixels) above the view
  9777. d.viewOffset = 0;
  9778. d.lastWrapHeight = d.lastWrapWidth = 0;
  9779. d.updateLineNumbers = null;
  9780. d.nativeBarWidth = d.barHeight = d.barWidth = 0;
  9781. d.scrollbarsClipped = false;
  9782. // Used to only resize the line number gutter when necessary (when
  9783. // the amount of lines crosses a boundary that makes its width change)
  9784. d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
  9785. // Set to true when a non-horizontal-scrolling line widget is
  9786. // added. As an optimization, line widget aligning is skipped when
  9787. // this is false.
  9788. d.alignWidgets = false;
  9789. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  9790. // Tracks the maximum line length so that the horizontal scrollbar
  9791. // can be kept static when scrolling.
  9792. d.maxLine = null;
  9793. d.maxLineLength = 0;
  9794. d.maxLineChanged = false;
  9795. // Used for measuring wheel scrolling granularity
  9796. d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
  9797. // True when shift is held down.
  9798. d.shift = false;
  9799. // Used to track whether anything happened since the context menu
  9800. // was opened.
  9801. d.selForContextMenu = null;
  9802. d.activeTouch = null;
  9803. d.gutterSpecs = getGutters(options.gutters, options.lineNumbers);
  9804. renderGutters(d);
  9805. input.init(d);
  9806. }
  9807. // Since the delta values reported on mouse wheel events are
  9808. // unstandardized between browsers and even browser versions, and
  9809. // generally horribly unpredictable, this code starts by measuring
  9810. // the scroll effect that the first few mouse wheel events have,
  9811. // and, from that, detects the way it can convert deltas to pixel
  9812. // offsets afterwards.
  9813. //
  9814. // The reason we want to know the amount a wheel event will scroll
  9815. // is that it gives us a chance to update the display before the
  9816. // actual scrolling happens, reducing flickering.
  9817. var wheelSamples = 0, wheelPixelsPerUnit = null;
  9818. // Fill in a browser-detected starting value on browsers where we
  9819. // know one. These don't have to be accurate -- the result of them
  9820. // being wrong would just be a slight flicker on the first wheel
  9821. // scroll (if it is large enough).
  9822. if (ie) { wheelPixelsPerUnit = -.53; }
  9823. else if (gecko) { wheelPixelsPerUnit = 15; }
  9824. else if (chrome) { wheelPixelsPerUnit = -.7; }
  9825. else if (safari) { wheelPixelsPerUnit = -1/3; }
  9826. function wheelEventDelta(e) {
  9827. var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
  9828. if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; }
  9829. if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; }
  9830. else if (dy == null) { dy = e.wheelDelta; }
  9831. return {x: dx, y: dy}
  9832. }
  9833. function wheelEventPixels(e) {
  9834. var delta = wheelEventDelta(e);
  9835. delta.x *= wheelPixelsPerUnit;
  9836. delta.y *= wheelPixelsPerUnit;
  9837. return delta
  9838. }
  9839. function onScrollWheel(cm, e) {
  9840. var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
  9841. var display = cm.display, scroll = display.scroller;
  9842. // Quit if there's nothing to scroll here
  9843. var canScrollX = scroll.scrollWidth > scroll.clientWidth;
  9844. var canScrollY = scroll.scrollHeight > scroll.clientHeight;
  9845. if (!(dx && canScrollX || dy && canScrollY)) { return }
  9846. // Webkit browsers on OS X abort momentum scrolls when the target
  9847. // of the scroll event is removed from the scrollable element.
  9848. // This hack (see related code in patchDisplay) makes sure the
  9849. // element is kept around.
  9850. if (dy && mac && webkit) {
  9851. outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
  9852. for (var i = 0; i < view.length; i++) {
  9853. if (view[i].node == cur) {
  9854. cm.display.currentWheelTarget = cur;
  9855. break outer
  9856. }
  9857. }
  9858. }
  9859. }
  9860. // On some browsers, horizontal scrolling will cause redraws to
  9861. // happen before the gutter has been realigned, causing it to
  9862. // wriggle around in a most unseemly way. When we have an
  9863. // estimated pixels/delta value, we just handle horizontal
  9864. // scrolling entirely here. It'll be slightly off from native, but
  9865. // better than glitching out.
  9866. if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
  9867. if (dy && canScrollY)
  9868. { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); }
  9869. setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit));
  9870. // Only prevent default scrolling if vertical scrolling is
  9871. // actually possible. Otherwise, it causes vertical scroll
  9872. // jitter on OSX trackpads when deltaX is small and deltaY
  9873. // is large (issue #3579)
  9874. if (!dy || (dy && canScrollY))
  9875. { e_preventDefault(e); }
  9876. display.wheelStartX = null; // Abort measurement, if in progress
  9877. return
  9878. }
  9879. // 'Project' the visible viewport to cover the area that is being
  9880. // scrolled into view (if we know enough to estimate it).
  9881. if (dy && wheelPixelsPerUnit != null) {
  9882. var pixels = dy * wheelPixelsPerUnit;
  9883. var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
  9884. if (pixels < 0) { top = Math.max(0, top + pixels - 50); }
  9885. else { bot = Math.min(cm.doc.height, bot + pixels + 50); }
  9886. updateDisplaySimple(cm, {top: top, bottom: bot});
  9887. }
  9888. if (wheelSamples < 20) {
  9889. if (display.wheelStartX == null) {
  9890. display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
  9891. display.wheelDX = dx; display.wheelDY = dy;
  9892. setTimeout(function () {
  9893. if (display.wheelStartX == null) { return }
  9894. var movedX = scroll.scrollLeft - display.wheelStartX;
  9895. var movedY = scroll.scrollTop - display.wheelStartY;
  9896. var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
  9897. (movedX && display.wheelDX && movedX / display.wheelDX);
  9898. display.wheelStartX = display.wheelStartY = null;
  9899. if (!sample) { return }
  9900. wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
  9901. ++wheelSamples;
  9902. }, 200);
  9903. } else {
  9904. display.wheelDX += dx; display.wheelDY += dy;
  9905. }
  9906. }
  9907. }
  9908. // Selection objects are immutable. A new one is created every time
  9909. // the selection changes. A selection is one or more non-overlapping
  9910. // (and non-touching) ranges, sorted, and an integer that indicates
  9911. // which one is the primary selection (the one that's scrolled into
  9912. // view, that getCursor returns, etc).
  9913. var Selection = function(ranges, primIndex) {
  9914. this.ranges = ranges;
  9915. this.primIndex = primIndex;
  9916. };
  9917. Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
  9918. Selection.prototype.equals = function (other) {
  9919. if (other == this) { return true }
  9920. if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
  9921. for (var i = 0; i < this.ranges.length; i++) {
  9922. var here = this.ranges[i], there = other.ranges[i];
  9923. if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
  9924. }
  9925. return true
  9926. };
  9927. Selection.prototype.deepCopy = function () {
  9928. var out = [];
  9929. for (var i = 0; i < this.ranges.length; i++)
  9930. { out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head)); }
  9931. return new Selection(out, this.primIndex)
  9932. };
  9933. Selection.prototype.somethingSelected = function () {
  9934. for (var i = 0; i < this.ranges.length; i++)
  9935. { if (!this.ranges[i].empty()) { return true } }
  9936. return false
  9937. };
  9938. Selection.prototype.contains = function (pos, end) {
  9939. if (!end) { end = pos; }
  9940. for (var i = 0; i < this.ranges.length; i++) {
  9941. var range = this.ranges[i];
  9942. if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
  9943. { return i }
  9944. }
  9945. return -1
  9946. };
  9947. var Range = function(anchor, head) {
  9948. this.anchor = anchor; this.head = head;
  9949. };
  9950. Range.prototype.from = function () { return minPos(this.anchor, this.head) };
  9951. Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
  9952. Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
  9953. // Take an unsorted, potentially overlapping set of ranges, and
  9954. // build a selection out of it. 'Consumes' ranges array (modifying
  9955. // it).
  9956. function normalizeSelection(cm, ranges, primIndex) {
  9957. var mayTouch = cm && cm.options.selectionsMayTouch;
  9958. var prim = ranges[primIndex];
  9959. ranges.sort(function (a, b) { return cmp(a.from(), b.from()); });
  9960. primIndex = indexOf(ranges, prim);
  9961. for (var i = 1; i < ranges.length; i++) {
  9962. var cur = ranges[i], prev = ranges[i - 1];
  9963. var diff = cmp(prev.to(), cur.from());
  9964. if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
  9965. var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
  9966. var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
  9967. if (i <= primIndex) { --primIndex; }
  9968. ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
  9969. }
  9970. }
  9971. return new Selection(ranges, primIndex)
  9972. }
  9973. function simpleSelection(anchor, head) {
  9974. return new Selection([new Range(anchor, head || anchor)], 0)
  9975. }
  9976. // Compute the position of the end of a change (its 'to' property
  9977. // refers to the pre-change end).
  9978. function changeEnd(change) {
  9979. if (!change.text) { return change.to }
  9980. return Pos(change.from.line + change.text.length - 1,
  9981. lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
  9982. }
  9983. // Adjust a position to refer to the post-change position of the
  9984. // same text, or the end of the change if the change covers it.
  9985. function adjustForChange(pos, change) {
  9986. if (cmp(pos, change.from) < 0) { return pos }
  9987. if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
  9988. var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
  9989. if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; }
  9990. return Pos(line, ch)
  9991. }
  9992. function computeSelAfterChange(doc, change) {
  9993. var out = [];
  9994. for (var i = 0; i < doc.sel.ranges.length; i++) {
  9995. var range = doc.sel.ranges[i];
  9996. out.push(new Range(adjustForChange(range.anchor, change),
  9997. adjustForChange(range.head, change)));
  9998. }
  9999. return normalizeSelection(doc.cm, out, doc.sel.primIndex)
  10000. }
  10001. function offsetPos(pos, old, nw) {
  10002. if (pos.line == old.line)
  10003. { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
  10004. else
  10005. { return Pos(nw.line + (pos.line - old.line), pos.ch) }
  10006. }
  10007. // Used by replaceSelections to allow moving the selection to the
  10008. // start or around the replaced test. Hint may be "start" or "around".
  10009. function computeReplacedSel(doc, changes, hint) {
  10010. var out = [];
  10011. var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
  10012. for (var i = 0; i < changes.length; i++) {
  10013. var change = changes[i];
  10014. var from = offsetPos(change.from, oldPrev, newPrev);
  10015. var to = offsetPos(changeEnd(change), oldPrev, newPrev);
  10016. oldPrev = change.to;
  10017. newPrev = to;
  10018. if (hint == "around") {
  10019. var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
  10020. out[i] = new Range(inv ? to : from, inv ? from : to);
  10021. } else {
  10022. out[i] = new Range(from, from);
  10023. }
  10024. }
  10025. return new Selection(out, doc.sel.primIndex)
  10026. }
  10027. // Used to get the editor into a consistent state again when options change.
  10028. function loadMode(cm) {
  10029. cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
  10030. resetModeState(cm);
  10031. }
  10032. function resetModeState(cm) {
  10033. cm.doc.iter(function (line) {
  10034. if (line.stateAfter) { line.stateAfter = null; }
  10035. if (line.styles) { line.styles = null; }
  10036. });
  10037. cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
  10038. startWorker(cm, 100);
  10039. cm.state.modeGen++;
  10040. if (cm.curOp) { regChange(cm); }
  10041. }
  10042. // DOCUMENT DATA STRUCTURE
  10043. // By default, updates that start and end at the beginning of a line
  10044. // are treated specially, in order to make the association of line
  10045. // widgets and marker elements with the text behave more intuitive.
  10046. function isWholeLineUpdate(doc, change) {
  10047. return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
  10048. (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
  10049. }
  10050. // Perform a change on the document data structure.
  10051. function updateDoc(doc, change, markedSpans, estimateHeight) {
  10052. function spansFor(n) {return markedSpans ? markedSpans[n] : null}
  10053. function update(line, text, spans) {
  10054. updateLine(line, text, spans, estimateHeight);
  10055. signalLater(line, "change", line, change);
  10056. }
  10057. function linesFor(start, end) {
  10058. var result = [];
  10059. for (var i = start; i < end; ++i)
  10060. { result.push(new Line(text[i], spansFor(i), estimateHeight)); }
  10061. return result
  10062. }
  10063. var from = change.from, to = change.to, text = change.text;
  10064. var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
  10065. var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
  10066. // Adjust the line structure
  10067. if (change.full) {
  10068. doc.insert(0, linesFor(0, text.length));
  10069. doc.remove(text.length, doc.size - text.length);
  10070. } else if (isWholeLineUpdate(doc, change)) {
  10071. // This is a whole-line replace. Treated specially to make
  10072. // sure line objects move the way they are supposed to.
  10073. var added = linesFor(0, text.length - 1);
  10074. update(lastLine, lastLine.text, lastSpans);
  10075. if (nlines) { doc.remove(from.line, nlines); }
  10076. if (added.length) { doc.insert(from.line, added); }
  10077. } else if (firstLine == lastLine) {
  10078. if (text.length == 1) {
  10079. update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
  10080. } else {
  10081. var added$1 = linesFor(1, text.length - 1);
  10082. added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
  10083. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  10084. doc.insert(from.line + 1, added$1);
  10085. }
  10086. } else if (text.length == 1) {
  10087. update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
  10088. doc.remove(from.line + 1, nlines);
  10089. } else {
  10090. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  10091. update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
  10092. var added$2 = linesFor(1, text.length - 1);
  10093. if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); }
  10094. doc.insert(from.line + 1, added$2);
  10095. }
  10096. signalLater(doc, "change", doc, change);
  10097. }
  10098. // Call f for all linked documents.
  10099. function linkedDocs(doc, f, sharedHistOnly) {
  10100. function propagate(doc, skip, sharedHist) {
  10101. if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
  10102. var rel = doc.linked[i];
  10103. if (rel.doc == skip) { continue }
  10104. var shared = sharedHist && rel.sharedHist;
  10105. if (sharedHistOnly && !shared) { continue }
  10106. f(rel.doc, shared);
  10107. propagate(rel.doc, doc, shared);
  10108. } }
  10109. }
  10110. propagate(doc, null, true);
  10111. }
  10112. // Attach a document to an editor.
  10113. function attachDoc(cm, doc) {
  10114. if (doc.cm) { throw new Error("This document is already in use.") }
  10115. cm.doc = doc;
  10116. doc.cm = cm;
  10117. estimateLineHeights(cm);
  10118. loadMode(cm);
  10119. setDirectionClass(cm);
  10120. if (!cm.options.lineWrapping) { findMaxLine(cm); }
  10121. cm.options.mode = doc.modeOption;
  10122. regChange(cm);
  10123. }
  10124. function setDirectionClass(cm) {
  10125. (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
  10126. }
  10127. function directionChanged(cm) {
  10128. runInOp(cm, function () {
  10129. setDirectionClass(cm);
  10130. regChange(cm);
  10131. });
  10132. }
  10133. function History(startGen) {
  10134. // Arrays of change events and selections. Doing something adds an
  10135. // event to done and clears undo. Undoing moves events from done
  10136. // to undone, redoing moves them in the other direction.
  10137. this.done = []; this.undone = [];
  10138. this.undoDepth = Infinity;
  10139. // Used to track when changes can be merged into a single undo
  10140. // event
  10141. this.lastModTime = this.lastSelTime = 0;
  10142. this.lastOp = this.lastSelOp = null;
  10143. this.lastOrigin = this.lastSelOrigin = null;
  10144. // Used by the isClean() method
  10145. this.generation = this.maxGeneration = startGen || 1;
  10146. }
  10147. // Create a history change event from an updateDoc-style change
  10148. // object.
  10149. function historyChangeFromChange(doc, change) {
  10150. var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
  10151. attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
  10152. linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true);
  10153. return histChange
  10154. }
  10155. // Pop all selection events off the end of a history array. Stop at
  10156. // a change event.
  10157. function clearSelectionEvents(array) {
  10158. while (array.length) {
  10159. var last = lst(array);
  10160. if (last.ranges) { array.pop(); }
  10161. else { break }
  10162. }
  10163. }
  10164. // Find the top change event in the history. Pop off selection
  10165. // events that are in the way.
  10166. function lastChangeEvent(hist, force) {
  10167. if (force) {
  10168. clearSelectionEvents(hist.done);
  10169. return lst(hist.done)
  10170. } else if (hist.done.length && !lst(hist.done).ranges) {
  10171. return lst(hist.done)
  10172. } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
  10173. hist.done.pop();
  10174. return lst(hist.done)
  10175. }
  10176. }
  10177. // Register a change in the history. Merges changes that are within
  10178. // a single operation, or are close together with an origin that
  10179. // allows merging (starting with "+") into a single event.
  10180. function addChangeToHistory(doc, change, selAfter, opId) {
  10181. var hist = doc.history;
  10182. hist.undone.length = 0;
  10183. var time = +new Date, cur;
  10184. var last;
  10185. if ((hist.lastOp == opId ||
  10186. hist.lastOrigin == change.origin && change.origin &&
  10187. ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
  10188. change.origin.charAt(0) == "*")) &&
  10189. (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
  10190. // Merge this change into the last event
  10191. last = lst(cur.changes);
  10192. if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
  10193. // Optimized case for simple insertion -- don't want to add
  10194. // new changesets for every character typed
  10195. last.to = changeEnd(change);
  10196. } else {
  10197. // Add new sub-event
  10198. cur.changes.push(historyChangeFromChange(doc, change));
  10199. }
  10200. } else {
  10201. // Can not be merged, start a new event.
  10202. var before = lst(hist.done);
  10203. if (!before || !before.ranges)
  10204. { pushSelectionToHistory(doc.sel, hist.done); }
  10205. cur = {changes: [historyChangeFromChange(doc, change)],
  10206. generation: hist.generation};
  10207. hist.done.push(cur);
  10208. while (hist.done.length > hist.undoDepth) {
  10209. hist.done.shift();
  10210. if (!hist.done[0].ranges) { hist.done.shift(); }
  10211. }
  10212. }
  10213. hist.done.push(selAfter);
  10214. hist.generation = ++hist.maxGeneration;
  10215. hist.lastModTime = hist.lastSelTime = time;
  10216. hist.lastOp = hist.lastSelOp = opId;
  10217. hist.lastOrigin = hist.lastSelOrigin = change.origin;
  10218. if (!last) { signal(doc, "historyAdded"); }
  10219. }
  10220. function selectionEventCanBeMerged(doc, origin, prev, sel) {
  10221. var ch = origin.charAt(0);
  10222. return ch == "*" ||
  10223. ch == "+" &&
  10224. prev.ranges.length == sel.ranges.length &&
  10225. prev.somethingSelected() == sel.somethingSelected() &&
  10226. new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
  10227. }
  10228. // Called whenever the selection changes, sets the new selection as
  10229. // the pending selection in the history, and pushes the old pending
  10230. // selection into the 'done' array when it was significantly
  10231. // different (in number of selected ranges, emptiness, or time).
  10232. function addSelectionToHistory(doc, sel, opId, options) {
  10233. var hist = doc.history, origin = options && options.origin;
  10234. // A new event is started when the previous origin does not match
  10235. // the current, or the origins don't allow matching. Origins
  10236. // starting with * are always merged, those starting with + are
  10237. // merged when similar and close together in time.
  10238. if (opId == hist.lastSelOp ||
  10239. (origin && hist.lastSelOrigin == origin &&
  10240. (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
  10241. selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
  10242. { hist.done[hist.done.length - 1] = sel; }
  10243. else
  10244. { pushSelectionToHistory(sel, hist.done); }
  10245. hist.lastSelTime = +new Date;
  10246. hist.lastSelOrigin = origin;
  10247. hist.lastSelOp = opId;
  10248. if (options && options.clearRedo !== false)
  10249. { clearSelectionEvents(hist.undone); }
  10250. }
  10251. function pushSelectionToHistory(sel, dest) {
  10252. var top = lst(dest);
  10253. if (!(top && top.ranges && top.equals(sel)))
  10254. { dest.push(sel); }
  10255. }
  10256. // Used to store marked span information in the history.
  10257. function attachLocalSpans(doc, change, from, to) {
  10258. var existing = change["spans_" + doc.id], n = 0;
  10259. doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
  10260. if (line.markedSpans)
  10261. { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; }
  10262. ++n;
  10263. });
  10264. }
  10265. // When un/re-doing restores text containing marked spans, those
  10266. // that have been explicitly cleared should not be restored.
  10267. function removeClearedSpans(spans) {
  10268. if (!spans) { return null }
  10269. var out;
  10270. for (var i = 0; i < spans.length; ++i) {
  10271. if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } }
  10272. else if (out) { out.push(spans[i]); }
  10273. }
  10274. return !out ? spans : out.length ? out : null
  10275. }
  10276. // Retrieve and filter the old marked spans stored in a change event.
  10277. function getOldSpans(doc, change) {
  10278. var found = change["spans_" + doc.id];
  10279. if (!found) { return null }
  10280. var nw = [];
  10281. for (var i = 0; i < change.text.length; ++i)
  10282. { nw.push(removeClearedSpans(found[i])); }
  10283. return nw
  10284. }
  10285. // Used for un/re-doing changes from the history. Combines the
  10286. // result of computing the existing spans with the set of spans that
  10287. // existed in the history (so that deleting around a span and then
  10288. // undoing brings back the span).
  10289. function mergeOldSpans(doc, change) {
  10290. var old = getOldSpans(doc, change);
  10291. var stretched = stretchSpansOverChange(doc, change);
  10292. if (!old) { return stretched }
  10293. if (!stretched) { return old }
  10294. for (var i = 0; i < old.length; ++i) {
  10295. var oldCur = old[i], stretchCur = stretched[i];
  10296. if (oldCur && stretchCur) {
  10297. spans: for (var j = 0; j < stretchCur.length; ++j) {
  10298. var span = stretchCur[j];
  10299. for (var k = 0; k < oldCur.length; ++k)
  10300. { if (oldCur[k].marker == span.marker) { continue spans } }
  10301. oldCur.push(span);
  10302. }
  10303. } else if (stretchCur) {
  10304. old[i] = stretchCur;
  10305. }
  10306. }
  10307. return old
  10308. }
  10309. // Used both to provide a JSON-safe object in .getHistory, and, when
  10310. // detaching a document, to split the history in two
  10311. function copyHistoryArray(events, newGroup, instantiateSel) {
  10312. var copy = [];
  10313. for (var i = 0; i < events.length; ++i) {
  10314. var event = events[i];
  10315. if (event.ranges) {
  10316. copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
  10317. continue
  10318. }
  10319. var changes = event.changes, newChanges = [];
  10320. copy.push({changes: newChanges});
  10321. for (var j = 0; j < changes.length; ++j) {
  10322. var change = changes[j], m = (void 0);
  10323. newChanges.push({from: change.from, to: change.to, text: change.text});
  10324. if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
  10325. if (indexOf(newGroup, Number(m[1])) > -1) {
  10326. lst(newChanges)[prop] = change[prop];
  10327. delete change[prop];
  10328. }
  10329. } } }
  10330. }
  10331. }
  10332. return copy
  10333. }
  10334. // The 'scroll' parameter given to many of these indicated whether
  10335. // the new cursor position should be scrolled into view after
  10336. // modifying the selection.
  10337. // If shift is held or the extend flag is set, extends a range to
  10338. // include a given position (and optionally a second position).
  10339. // Otherwise, simply returns the range between the given positions.
  10340. // Used for cursor motion and such.
  10341. function extendRange(range, head, other, extend) {
  10342. if (extend) {
  10343. var anchor = range.anchor;
  10344. if (other) {
  10345. var posBefore = cmp(head, anchor) < 0;
  10346. if (posBefore != (cmp(other, anchor) < 0)) {
  10347. anchor = head;
  10348. head = other;
  10349. } else if (posBefore != (cmp(head, other) < 0)) {
  10350. head = other;
  10351. }
  10352. }
  10353. return new Range(anchor, head)
  10354. } else {
  10355. return new Range(other || head, head)
  10356. }
  10357. }
  10358. // Extend the primary selection range, discard the rest.
  10359. function extendSelection(doc, head, other, options, extend) {
  10360. if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); }
  10361. setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);
  10362. }
  10363. // Extend all selections (pos is an array of selections with length
  10364. // equal the number of selections)
  10365. function extendSelections(doc, heads, options) {
  10366. var out = [];
  10367. var extend = doc.cm && (doc.cm.display.shift || doc.extend);
  10368. for (var i = 0; i < doc.sel.ranges.length; i++)
  10369. { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); }
  10370. var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex);
  10371. setSelection(doc, newSel, options);
  10372. }
  10373. // Updates a single range in the selection.
  10374. function replaceOneSelection(doc, i, range, options) {
  10375. var ranges = doc.sel.ranges.slice(0);
  10376. ranges[i] = range;
  10377. setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options);
  10378. }
  10379. // Reset the selection to a single range.
  10380. function setSimpleSelection(doc, anchor, head, options) {
  10381. setSelection(doc, simpleSelection(anchor, head), options);
  10382. }
  10383. // Give beforeSelectionChange handlers a change to influence a
  10384. // selection update.
  10385. function filterSelectionChange(doc, sel, options) {
  10386. var obj = {
  10387. ranges: sel.ranges,
  10388. update: function(ranges) {
  10389. this.ranges = [];
  10390. for (var i = 0; i < ranges.length; i++)
  10391. { this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
  10392. clipPos(doc, ranges[i].head)); }
  10393. },
  10394. origin: options && options.origin
  10395. };
  10396. signal(doc, "beforeSelectionChange", doc, obj);
  10397. if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); }
  10398. if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) }
  10399. else { return sel }
  10400. }
  10401. function setSelectionReplaceHistory(doc, sel, options) {
  10402. var done = doc.history.done, last = lst(done);
  10403. if (last && last.ranges) {
  10404. done[done.length - 1] = sel;
  10405. setSelectionNoUndo(doc, sel, options);
  10406. } else {
  10407. setSelection(doc, sel, options);
  10408. }
  10409. }
  10410. // Set a new selection.
  10411. function setSelection(doc, sel, options) {
  10412. setSelectionNoUndo(doc, sel, options);
  10413. addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
  10414. }
  10415. function setSelectionNoUndo(doc, sel, options) {
  10416. if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
  10417. { sel = filterSelectionChange(doc, sel, options); }
  10418. var bias = options && options.bias ||
  10419. (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
  10420. setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
  10421. if (!(options && options.scroll === false) && doc.cm)
  10422. { ensureCursorVisible(doc.cm); }
  10423. }
  10424. function setSelectionInner(doc, sel) {
  10425. if (sel.equals(doc.sel)) { return }
  10426. doc.sel = sel;
  10427. if (doc.cm) {
  10428. doc.cm.curOp.updateInput = 1;
  10429. doc.cm.curOp.selectionChanged = true;
  10430. signalCursorActivity(doc.cm);
  10431. }
  10432. signalLater(doc, "cursorActivity", doc);
  10433. }
  10434. // Verify that the selection does not partially select any atomic
  10435. // marked ranges.
  10436. function reCheckSelection(doc) {
  10437. setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));
  10438. }
  10439. // Return a selection that does not partially select any atomic
  10440. // ranges.
  10441. function skipAtomicInSelection(doc, sel, bias, mayClear) {
  10442. var out;
  10443. for (var i = 0; i < sel.ranges.length; i++) {
  10444. var range = sel.ranges[i];
  10445. var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
  10446. var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
  10447. var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
  10448. if (out || newAnchor != range.anchor || newHead != range.head) {
  10449. if (!out) { out = sel.ranges.slice(0, i); }
  10450. out[i] = new Range(newAnchor, newHead);
  10451. }
  10452. }
  10453. return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
  10454. }
  10455. function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
  10456. var line = getLine(doc, pos.line);
  10457. if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
  10458. var sp = line.markedSpans[i], m = sp.marker;
  10459. // Determine if we should prevent the cursor being placed to the left/right of an atomic marker
  10460. // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it
  10461. // is with selectLeft/Right
  10462. var preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft;
  10463. var preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight;
  10464. if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
  10465. (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
  10466. if (mayClear) {
  10467. signal(m, "beforeCursorEnter");
  10468. if (m.explicitlyCleared) {
  10469. if (!line.markedSpans) { break }
  10470. else {--i; continue}
  10471. }
  10472. }
  10473. if (!m.atomic) { continue }
  10474. if (oldPos) {
  10475. var near = m.find(dir < 0 ? 1 : -1), diff = (void 0);
  10476. if (dir < 0 ? preventCursorRight : preventCursorLeft)
  10477. { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); }
  10478. if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
  10479. { return skipAtomicInner(doc, near, pos, dir, mayClear) }
  10480. }
  10481. var far = m.find(dir < 0 ? -1 : 1);
  10482. if (dir < 0 ? preventCursorLeft : preventCursorRight)
  10483. { far = movePos(doc, far, dir, far.line == pos.line ? line : null); }
  10484. return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
  10485. }
  10486. } }
  10487. return pos
  10488. }
  10489. // Ensure a given position is not inside an atomic range.
  10490. function skipAtomic(doc, pos, oldPos, bias, mayClear) {
  10491. var dir = bias || 1;
  10492. var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
  10493. (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
  10494. skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
  10495. (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
  10496. if (!found) {
  10497. doc.cantEdit = true;
  10498. return Pos(doc.first, 0)
  10499. }
  10500. return found
  10501. }
  10502. function movePos(doc, pos, dir, line) {
  10503. if (dir < 0 && pos.ch == 0) {
  10504. if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
  10505. else { return null }
  10506. } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
  10507. if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
  10508. else { return null }
  10509. } else {
  10510. return new Pos(pos.line, pos.ch + dir)
  10511. }
  10512. }
  10513. function selectAll(cm) {
  10514. cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
  10515. }
  10516. // UPDATING
  10517. // Allow "beforeChange" event handlers to influence a change
  10518. function filterChange(doc, change, update) {
  10519. var obj = {
  10520. canceled: false,
  10521. from: change.from,
  10522. to: change.to,
  10523. text: change.text,
  10524. origin: change.origin,
  10525. cancel: function () { return obj.canceled = true; }
  10526. };
  10527. if (update) { obj.update = function (from, to, text, origin) {
  10528. if (from) { obj.from = clipPos(doc, from); }
  10529. if (to) { obj.to = clipPos(doc, to); }
  10530. if (text) { obj.text = text; }
  10531. if (origin !== undefined) { obj.origin = origin; }
  10532. }; }
  10533. signal(doc, "beforeChange", doc, obj);
  10534. if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); }
  10535. if (obj.canceled) {
  10536. if (doc.cm) { doc.cm.curOp.updateInput = 2; }
  10537. return null
  10538. }
  10539. return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
  10540. }
  10541. // Apply a change to a document, and add it to the document's
  10542. // history, and propagating it to all linked documents.
  10543. function makeChange(doc, change, ignoreReadOnly) {
  10544. if (doc.cm) {
  10545. if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
  10546. if (doc.cm.state.suppressEdits) { return }
  10547. }
  10548. if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
  10549. change = filterChange(doc, change, true);
  10550. if (!change) { return }
  10551. }
  10552. // Possibly split or suppress the update based on the presence
  10553. // of read-only spans in its range.
  10554. var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
  10555. if (split) {
  10556. for (var i = split.length - 1; i >= 0; --i)
  10557. { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); }
  10558. } else {
  10559. makeChangeInner(doc, change);
  10560. }
  10561. }
  10562. function makeChangeInner(doc, change) {
  10563. if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
  10564. var selAfter = computeSelAfterChange(doc, change);
  10565. addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
  10566. makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
  10567. var rebased = [];
  10568. linkedDocs(doc, function (doc, sharedHist) {
  10569. if (!sharedHist && indexOf(rebased, doc.history) == -1) {
  10570. rebaseHist(doc.history, change);
  10571. rebased.push(doc.history);
  10572. }
  10573. makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
  10574. });
  10575. }
  10576. // Revert a change stored in a document's history.
  10577. function makeChangeFromHistory(doc, type, allowSelectionOnly) {
  10578. var suppress = doc.cm && doc.cm.state.suppressEdits;
  10579. if (suppress && !allowSelectionOnly) { return }
  10580. var hist = doc.history, event, selAfter = doc.sel;
  10581. var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
  10582. // Verify that there is a useable event (so that ctrl-z won't
  10583. // needlessly clear selection events)
  10584. var i = 0;
  10585. for (; i < source.length; i++) {
  10586. event = source[i];
  10587. if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
  10588. { break }
  10589. }
  10590. if (i == source.length) { return }
  10591. hist.lastOrigin = hist.lastSelOrigin = null;
  10592. for (;;) {
  10593. event = source.pop();
  10594. if (event.ranges) {
  10595. pushSelectionToHistory(event, dest);
  10596. if (allowSelectionOnly && !event.equals(doc.sel)) {
  10597. setSelection(doc, event, {clearRedo: false});
  10598. return
  10599. }
  10600. selAfter = event;
  10601. } else if (suppress) {
  10602. source.push(event);
  10603. return
  10604. } else { break }
  10605. }
  10606. // Build up a reverse change object to add to the opposite history
  10607. // stack (redo when undoing, and vice versa).
  10608. var antiChanges = [];
  10609. pushSelectionToHistory(selAfter, dest);
  10610. dest.push({changes: antiChanges, generation: hist.generation});
  10611. hist.generation = event.generation || ++hist.maxGeneration;
  10612. var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
  10613. var loop = function ( i ) {
  10614. var change = event.changes[i];
  10615. change.origin = type;
  10616. if (filter && !filterChange(doc, change, false)) {
  10617. source.length = 0;
  10618. return {}
  10619. }
  10620. antiChanges.push(historyChangeFromChange(doc, change));
  10621. var after = i ? computeSelAfterChange(doc, change) : lst(source);
  10622. makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
  10623. if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); }
  10624. var rebased = [];
  10625. // Propagate to the linked documents
  10626. linkedDocs(doc, function (doc, sharedHist) {
  10627. if (!sharedHist && indexOf(rebased, doc.history) == -1) {
  10628. rebaseHist(doc.history, change);
  10629. rebased.push(doc.history);
  10630. }
  10631. makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
  10632. });
  10633. };
  10634. for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
  10635. var returned = loop( i$1 );
  10636. if ( returned ) return returned.v;
  10637. }
  10638. }
  10639. // Sub-views need their line numbers shifted when text is added
  10640. // above or below them in the parent document.
  10641. function shiftDoc(doc, distance) {
  10642. if (distance == 0) { return }
  10643. doc.first += distance;
  10644. doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
  10645. Pos(range.anchor.line + distance, range.anchor.ch),
  10646. Pos(range.head.line + distance, range.head.ch)
  10647. ); }), doc.sel.primIndex);
  10648. if (doc.cm) {
  10649. regChange(doc.cm, doc.first, doc.first - distance, distance);
  10650. for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
  10651. { regLineChange(doc.cm, l, "gutter"); }
  10652. }
  10653. }
  10654. // More lower-level change function, handling only a single document
  10655. // (not linked ones).
  10656. function makeChangeSingleDoc(doc, change, selAfter, spans) {
  10657. if (doc.cm && !doc.cm.curOp)
  10658. { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
  10659. if (change.to.line < doc.first) {
  10660. shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
  10661. return
  10662. }
  10663. if (change.from.line > doc.lastLine()) { return }
  10664. // Clip the change to the size of this doc
  10665. if (change.from.line < doc.first) {
  10666. var shift = change.text.length - 1 - (doc.first - change.from.line);
  10667. shiftDoc(doc, shift);
  10668. change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
  10669. text: [lst(change.text)], origin: change.origin};
  10670. }
  10671. var last = doc.lastLine();
  10672. if (change.to.line > last) {
  10673. change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
  10674. text: [change.text[0]], origin: change.origin};
  10675. }
  10676. change.removed = getBetween(doc, change.from, change.to);
  10677. if (!selAfter) { selAfter = computeSelAfterChange(doc, change); }
  10678. if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); }
  10679. else { updateDoc(doc, change, spans); }
  10680. setSelectionNoUndo(doc, selAfter, sel_dontScroll);
  10681. if (doc.cantEdit && skipAtomic(doc, Pos(doc.firstLine(), 0)))
  10682. { doc.cantEdit = false; }
  10683. }
  10684. // Handle the interaction of a change to a document with the editor
  10685. // that this document is part of.
  10686. function makeChangeSingleDocInEditor(cm, change, spans) {
  10687. var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
  10688. var recomputeMaxLength = false, checkWidthStart = from.line;
  10689. if (!cm.options.lineWrapping) {
  10690. checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
  10691. doc.iter(checkWidthStart, to.line + 1, function (line) {
  10692. if (line == display.maxLine) {
  10693. recomputeMaxLength = true;
  10694. return true
  10695. }
  10696. });
  10697. }
  10698. if (doc.sel.contains(change.from, change.to) > -1)
  10699. { signalCursorActivity(cm); }
  10700. updateDoc(doc, change, spans, estimateHeight(cm));
  10701. if (!cm.options.lineWrapping) {
  10702. doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
  10703. var len = lineLength(line);
  10704. if (len > display.maxLineLength) {
  10705. display.maxLine = line;
  10706. display.maxLineLength = len;
  10707. display.maxLineChanged = true;
  10708. recomputeMaxLength = false;
  10709. }
  10710. });
  10711. if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; }
  10712. }
  10713. retreatFrontier(doc, from.line);
  10714. startWorker(cm, 400);
  10715. var lendiff = change.text.length - (to.line - from.line) - 1;
  10716. // Remember that these lines changed, for updating the display
  10717. if (change.full)
  10718. { regChange(cm); }
  10719. else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
  10720. { regLineChange(cm, from.line, "text"); }
  10721. else
  10722. { regChange(cm, from.line, to.line + 1, lendiff); }
  10723. var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
  10724. if (changeHandler || changesHandler) {
  10725. var obj = {
  10726. from: from, to: to,
  10727. text: change.text,
  10728. removed: change.removed,
  10729. origin: change.origin
  10730. };
  10731. if (changeHandler) { signalLater(cm, "change", cm, obj); }
  10732. if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); }
  10733. }
  10734. cm.display.selForContextMenu = null;
  10735. }
  10736. function replaceRange(doc, code, from, to, origin) {
  10737. var assign;
  10738. if (!to) { to = from; }
  10739. if (cmp(to, from) < 0) { (assign = [to, from], from = assign[0], to = assign[1]); }
  10740. if (typeof code == "string") { code = doc.splitLines(code); }
  10741. makeChange(doc, {from: from, to: to, text: code, origin: origin});
  10742. }
  10743. // Rebasing/resetting history to deal with externally-sourced changes
  10744. function rebaseHistSelSingle(pos, from, to, diff) {
  10745. if (to < pos.line) {
  10746. pos.line += diff;
  10747. } else if (from < pos.line) {
  10748. pos.line = from;
  10749. pos.ch = 0;
  10750. }
  10751. }
  10752. // Tries to rebase an array of history events given a change in the
  10753. // document. If the change touches the same lines as the event, the
  10754. // event, and everything 'behind' it, is discarded. If the change is
  10755. // before the event, the event's positions are updated. Uses a
  10756. // copy-on-write scheme for the positions, to avoid having to
  10757. // reallocate them all on every rebase, but also avoid problems with
  10758. // shared position objects being unsafely updated.
  10759. function rebaseHistArray(array, from, to, diff) {
  10760. for (var i = 0; i < array.length; ++i) {
  10761. var sub = array[i], ok = true;
  10762. if (sub.ranges) {
  10763. if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
  10764. for (var j = 0; j < sub.ranges.length; j++) {
  10765. rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
  10766. rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
  10767. }
  10768. continue
  10769. }
  10770. for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
  10771. var cur = sub.changes[j$1];
  10772. if (to < cur.from.line) {
  10773. cur.from = Pos(cur.from.line + diff, cur.from.ch);
  10774. cur.to = Pos(cur.to.line + diff, cur.to.ch);
  10775. } else if (from <= cur.to.line) {
  10776. ok = false;
  10777. break
  10778. }
  10779. }
  10780. if (!ok) {
  10781. array.splice(0, i + 1);
  10782. i = 0;
  10783. }
  10784. }
  10785. }
  10786. function rebaseHist(hist, change) {
  10787. var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
  10788. rebaseHistArray(hist.done, from, to, diff);
  10789. rebaseHistArray(hist.undone, from, to, diff);
  10790. }
  10791. // Utility for applying a change to a line by handle or number,
  10792. // returning the number and optionally registering the line as
  10793. // changed.
  10794. function changeLine(doc, handle, changeType, op) {
  10795. var no = handle, line = handle;
  10796. if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); }
  10797. else { no = lineNo(handle); }
  10798. if (no == null) { return null }
  10799. if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); }
  10800. return line
  10801. }
  10802. // The document is represented as a BTree consisting of leaves, with
  10803. // chunk of lines in them, and branches, with up to ten leaves or
  10804. // other branch nodes below them. The top node is always a branch
  10805. // node, and is the document object itself (meaning it has
  10806. // additional methods and properties).
  10807. //
  10808. // All nodes have parent links. The tree is used both to go from
  10809. // line numbers to line objects, and to go from objects to numbers.
  10810. // It also indexes by height, and is used to convert between height
  10811. // and line object, and to find the total height of the document.
  10812. //
  10813. // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
  10814. function LeafChunk(lines) {
  10815. this.lines = lines;
  10816. this.parent = null;
  10817. var height = 0;
  10818. for (var i = 0; i < lines.length; ++i) {
  10819. lines[i].parent = this;
  10820. height += lines[i].height;
  10821. }
  10822. this.height = height;
  10823. }
  10824. LeafChunk.prototype = {
  10825. chunkSize: function() { return this.lines.length },
  10826. // Remove the n lines at offset 'at'.
  10827. removeInner: function(at, n) {
  10828. for (var i = at, e = at + n; i < e; ++i) {
  10829. var line = this.lines[i];
  10830. this.height -= line.height;
  10831. cleanUpLine(line);
  10832. signalLater(line, "delete");
  10833. }
  10834. this.lines.splice(at, n);
  10835. },
  10836. // Helper used to collapse a small branch into a single leaf.
  10837. collapse: function(lines) {
  10838. lines.push.apply(lines, this.lines);
  10839. },
  10840. // Insert the given array of lines at offset 'at', count them as
  10841. // having the given height.
  10842. insertInner: function(at, lines, height) {
  10843. this.height += height;
  10844. this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
  10845. for (var i = 0; i < lines.length; ++i) { lines[i].parent = this; }
  10846. },
  10847. // Used to iterate over a part of the tree.
  10848. iterN: function(at, n, op) {
  10849. for (var e = at + n; at < e; ++at)
  10850. { if (op(this.lines[at])) { return true } }
  10851. }
  10852. };
  10853. function BranchChunk(children) {
  10854. this.children = children;
  10855. var size = 0, height = 0;
  10856. for (var i = 0; i < children.length; ++i) {
  10857. var ch = children[i];
  10858. size += ch.chunkSize(); height += ch.height;
  10859. ch.parent = this;
  10860. }
  10861. this.size = size;
  10862. this.height = height;
  10863. this.parent = null;
  10864. }
  10865. BranchChunk.prototype = {
  10866. chunkSize: function() { return this.size },
  10867. removeInner: function(at, n) {
  10868. this.size -= n;
  10869. for (var i = 0; i < this.children.length; ++i) {
  10870. var child = this.children[i], sz = child.chunkSize();
  10871. if (at < sz) {
  10872. var rm = Math.min(n, sz - at), oldHeight = child.height;
  10873. child.removeInner(at, rm);
  10874. this.height -= oldHeight - child.height;
  10875. if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
  10876. if ((n -= rm) == 0) { break }
  10877. at = 0;
  10878. } else { at -= sz; }
  10879. }
  10880. // If the result is smaller than 25 lines, ensure that it is a
  10881. // single leaf node.
  10882. if (this.size - n < 25 &&
  10883. (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
  10884. var lines = [];
  10885. this.collapse(lines);
  10886. this.children = [new LeafChunk(lines)];
  10887. this.children[0].parent = this;
  10888. }
  10889. },
  10890. collapse: function(lines) {
  10891. for (var i = 0; i < this.children.length; ++i) { this.children[i].collapse(lines); }
  10892. },
  10893. insertInner: function(at, lines, height) {
  10894. this.size += lines.length;
  10895. this.height += height;
  10896. for (var i = 0; i < this.children.length; ++i) {
  10897. var child = this.children[i], sz = child.chunkSize();
  10898. if (at <= sz) {
  10899. child.insertInner(at, lines, height);
  10900. if (child.lines && child.lines.length > 50) {
  10901. // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
  10902. // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
  10903. var remaining = child.lines.length % 25 + 25;
  10904. for (var pos = remaining; pos < child.lines.length;) {
  10905. var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
  10906. child.height -= leaf.height;
  10907. this.children.splice(++i, 0, leaf);
  10908. leaf.parent = this;
  10909. }
  10910. child.lines = child.lines.slice(0, remaining);
  10911. this.maybeSpill();
  10912. }
  10913. break
  10914. }
  10915. at -= sz;
  10916. }
  10917. },
  10918. // When a node has grown, check whether it should be split.
  10919. maybeSpill: function() {
  10920. if (this.children.length <= 10) { return }
  10921. var me = this;
  10922. do {
  10923. var spilled = me.children.splice(me.children.length - 5, 5);
  10924. var sibling = new BranchChunk(spilled);
  10925. if (!me.parent) { // Become the parent node
  10926. var copy = new BranchChunk(me.children);
  10927. copy.parent = me;
  10928. me.children = [copy, sibling];
  10929. me = copy;
  10930. } else {
  10931. me.size -= sibling.size;
  10932. me.height -= sibling.height;
  10933. var myIndex = indexOf(me.parent.children, me);
  10934. me.parent.children.splice(myIndex + 1, 0, sibling);
  10935. }
  10936. sibling.parent = me.parent;
  10937. } while (me.children.length > 10)
  10938. me.parent.maybeSpill();
  10939. },
  10940. iterN: function(at, n, op) {
  10941. for (var i = 0; i < this.children.length; ++i) {
  10942. var child = this.children[i], sz = child.chunkSize();
  10943. if (at < sz) {
  10944. var used = Math.min(n, sz - at);
  10945. if (child.iterN(at, used, op)) { return true }
  10946. if ((n -= used) == 0) { break }
  10947. at = 0;
  10948. } else { at -= sz; }
  10949. }
  10950. }
  10951. };
  10952. // Line widgets are block elements displayed above or below a line.
  10953. var LineWidget = function(doc, node, options) {
  10954. if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
  10955. { this[opt] = options[opt]; } } }
  10956. this.doc = doc;
  10957. this.node = node;
  10958. };
  10959. LineWidget.prototype.clear = function () {
  10960. var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
  10961. if (no == null || !ws) { return }
  10962. for (var i = 0; i < ws.length; ++i) { if (ws[i] == this) { ws.splice(i--, 1); } }
  10963. if (!ws.length) { line.widgets = null; }
  10964. var height = widgetHeight(this);
  10965. updateLineHeight(line, Math.max(0, line.height - height));
  10966. if (cm) {
  10967. runInOp(cm, function () {
  10968. adjustScrollWhenAboveVisible(cm, line, -height);
  10969. regLineChange(cm, no, "widget");
  10970. });
  10971. signalLater(cm, "lineWidgetCleared", cm, this, no);
  10972. }
  10973. };
  10974. LineWidget.prototype.changed = function () {
  10975. var this$1 = this;
  10976. var oldH = this.height, cm = this.doc.cm, line = this.line;
  10977. this.height = null;
  10978. var diff = widgetHeight(this) - oldH;
  10979. if (!diff) { return }
  10980. if (!lineIsHidden(this.doc, line)) { updateLineHeight(line, line.height + diff); }
  10981. if (cm) {
  10982. runInOp(cm, function () {
  10983. cm.curOp.forceUpdate = true;
  10984. adjustScrollWhenAboveVisible(cm, line, diff);
  10985. signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
  10986. });
  10987. }
  10988. };
  10989. eventMixin(LineWidget);
  10990. function adjustScrollWhenAboveVisible(cm, line, diff) {
  10991. if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
  10992. { addToScrollTop(cm, diff); }
  10993. }
  10994. function addLineWidget(doc, handle, node, options) {
  10995. var widget = new LineWidget(doc, node, options);
  10996. var cm = doc.cm;
  10997. if (cm && widget.noHScroll) { cm.display.alignWidgets = true; }
  10998. changeLine(doc, handle, "widget", function (line) {
  10999. var widgets = line.widgets || (line.widgets = []);
  11000. if (widget.insertAt == null) { widgets.push(widget); }
  11001. else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); }
  11002. widget.line = line;
  11003. if (cm && !lineIsHidden(doc, line)) {
  11004. var aboveVisible = heightAtLine(line) < doc.scrollTop;
  11005. updateLineHeight(line, line.height + widgetHeight(widget));
  11006. if (aboveVisible) { addToScrollTop(cm, widget.height); }
  11007. cm.curOp.forceUpdate = true;
  11008. }
  11009. return true
  11010. });
  11011. if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)); }
  11012. return widget
  11013. }
  11014. // TEXTMARKERS
  11015. // Created with markText and setBookmark methods. A TextMarker is a
  11016. // handle that can be used to clear or find a marked position in the
  11017. // document. Line objects hold arrays (markedSpans) containing
  11018. // {from, to, marker} object pointing to such marker objects, and
  11019. // indicating that such a marker is present on that line. Multiple
  11020. // lines may point to the same marker when it spans across lines.
  11021. // The spans will have null for their from/to properties when the
  11022. // marker continues beyond the start/end of the line. Markers have
  11023. // links back to the lines they currently touch.
  11024. // Collapsed markers have unique ids, in order to be able to order
  11025. // them, which is needed for uniquely determining an outer marker
  11026. // when they overlap (they may nest, but not partially overlap).
  11027. var nextMarkerId = 0;
  11028. var TextMarker = function(doc, type) {
  11029. this.lines = [];
  11030. this.type = type;
  11031. this.doc = doc;
  11032. this.id = ++nextMarkerId;
  11033. };
  11034. // Clear the marker.
  11035. TextMarker.prototype.clear = function () {
  11036. if (this.explicitlyCleared) { return }
  11037. var cm = this.doc.cm, withOp = cm && !cm.curOp;
  11038. if (withOp) { startOperation(cm); }
  11039. if (hasHandler(this, "clear")) {
  11040. var found = this.find();
  11041. if (found) { signalLater(this, "clear", found.from, found.to); }
  11042. }
  11043. var min = null, max = null;
  11044. for (var i = 0; i < this.lines.length; ++i) {
  11045. var line = this.lines[i];
  11046. var span = getMarkedSpanFor(line.markedSpans, this);
  11047. if (cm && !this.collapsed) { regLineChange(cm, lineNo(line), "text"); }
  11048. else if (cm) {
  11049. if (span.to != null) { max = lineNo(line); }
  11050. if (span.from != null) { min = lineNo(line); }
  11051. }
  11052. line.markedSpans = removeMarkedSpan(line.markedSpans, span);
  11053. if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
  11054. { updateLineHeight(line, textHeight(cm.display)); }
  11055. }
  11056. if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
  11057. var visual = visualLine(this.lines[i$1]), len = lineLength(visual);
  11058. if (len > cm.display.maxLineLength) {
  11059. cm.display.maxLine = visual;
  11060. cm.display.maxLineLength = len;
  11061. cm.display.maxLineChanged = true;
  11062. }
  11063. } }
  11064. if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); }
  11065. this.lines.length = 0;
  11066. this.explicitlyCleared = true;
  11067. if (this.atomic && this.doc.cantEdit) {
  11068. this.doc.cantEdit = false;
  11069. if (cm) { reCheckSelection(cm.doc); }
  11070. }
  11071. if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); }
  11072. if (withOp) { endOperation(cm); }
  11073. if (this.parent) { this.parent.clear(); }
  11074. };
  11075. // Find the position of the marker in the document. Returns a {from,
  11076. // to} object by default. Side can be passed to get a specific side
  11077. // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
  11078. // Pos objects returned contain a line object, rather than a line
  11079. // number (used to prevent looking up the same line twice).
  11080. TextMarker.prototype.find = function (side, lineObj) {
  11081. if (side == null && this.type == "bookmark") { side = 1; }
  11082. var from, to;
  11083. for (var i = 0; i < this.lines.length; ++i) {
  11084. var line = this.lines[i];
  11085. var span = getMarkedSpanFor(line.markedSpans, this);
  11086. if (span.from != null) {
  11087. from = Pos(lineObj ? line : lineNo(line), span.from);
  11088. if (side == -1) { return from }
  11089. }
  11090. if (span.to != null) {
  11091. to = Pos(lineObj ? line : lineNo(line), span.to);
  11092. if (side == 1) { return to }
  11093. }
  11094. }
  11095. return from && {from: from, to: to}
  11096. };
  11097. // Signals that the marker's widget changed, and surrounding layout
  11098. // should be recomputed.
  11099. TextMarker.prototype.changed = function () {
  11100. var this$1 = this;
  11101. var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
  11102. if (!pos || !cm) { return }
  11103. runInOp(cm, function () {
  11104. var line = pos.line, lineN = lineNo(pos.line);
  11105. var view = findViewForLine(cm, lineN);
  11106. if (view) {
  11107. clearLineMeasurementCacheFor(view);
  11108. cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
  11109. }
  11110. cm.curOp.updateMaxLine = true;
  11111. if (!lineIsHidden(widget.doc, line) && widget.height != null) {
  11112. var oldHeight = widget.height;
  11113. widget.height = null;
  11114. var dHeight = widgetHeight(widget) - oldHeight;
  11115. if (dHeight)
  11116. { updateLineHeight(line, line.height + dHeight); }
  11117. }
  11118. signalLater(cm, "markerChanged", cm, this$1);
  11119. });
  11120. };
  11121. TextMarker.prototype.attachLine = function (line) {
  11122. if (!this.lines.length && this.doc.cm) {
  11123. var op = this.doc.cm.curOp;
  11124. if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
  11125. { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); }
  11126. }
  11127. this.lines.push(line);
  11128. };
  11129. TextMarker.prototype.detachLine = function (line) {
  11130. this.lines.splice(indexOf(this.lines, line), 1);
  11131. if (!this.lines.length && this.doc.cm) {
  11132. var op = this.doc.cm.curOp
  11133. ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
  11134. }
  11135. };
  11136. eventMixin(TextMarker);
  11137. // Create a marker, wire it up to the right lines, and
  11138. function markText(doc, from, to, options, type) {
  11139. // Shared markers (across linked documents) are handled separately
  11140. // (markTextShared will call out to this again, once per
  11141. // document).
  11142. if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
  11143. // Ensure we are in an operation.
  11144. if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
  11145. var marker = new TextMarker(doc, type), diff = cmp(from, to);
  11146. if (options) { copyObj(options, marker, false); }
  11147. // Don't connect empty markers unless clearWhenEmpty is false
  11148. if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
  11149. { return marker }
  11150. if (marker.replacedWith) {
  11151. // Showing up as a widget implies collapsed (widget replaces text)
  11152. marker.collapsed = true;
  11153. marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
  11154. if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
  11155. if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
  11156. }
  11157. if (marker.collapsed) {
  11158. if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
  11159. from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
  11160. { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
  11161. seeCollapsedSpans();
  11162. }
  11163. if (marker.addToHistory)
  11164. { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
  11165. var curLine = from.line, cm = doc.cm, updateMaxLine;
  11166. doc.iter(curLine, to.line + 1, function (line) {
  11167. if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
  11168. { updateMaxLine = true; }
  11169. if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
  11170. addMarkedSpan(line, new MarkedSpan(marker,
  11171. curLine == from.line ? from.ch : null,
  11172. curLine == to.line ? to.ch : null));
  11173. ++curLine;
  11174. });
  11175. // lineIsHidden depends on the presence of the spans, so needs a second pass
  11176. if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
  11177. if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
  11178. }); }
  11179. if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
  11180. if (marker.readOnly) {
  11181. seeReadOnlySpans();
  11182. if (doc.history.done.length || doc.history.undone.length)
  11183. { doc.clearHistory(); }
  11184. }
  11185. if (marker.collapsed) {
  11186. marker.id = ++nextMarkerId;
  11187. marker.atomic = true;
  11188. }
  11189. if (cm) {
  11190. // Sync editor state
  11191. if (updateMaxLine) { cm.curOp.updateMaxLine = true; }
  11192. if (marker.collapsed)
  11193. { regChange(cm, from.line, to.line + 1); }
  11194. else if (marker.className || marker.startStyle || marker.endStyle || marker.css ||
  11195. marker.attributes || marker.title)
  11196. { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } }
  11197. if (marker.atomic) { reCheckSelection(cm.doc); }
  11198. signalLater(cm, "markerAdded", cm, marker);
  11199. }
  11200. return marker
  11201. }
  11202. // SHARED TEXTMARKERS
  11203. // A shared marker spans multiple linked documents. It is
  11204. // implemented as a meta-marker-object controlling multiple normal
  11205. // markers.
  11206. var SharedTextMarker = function(markers, primary) {
  11207. this.markers = markers;
  11208. this.primary = primary;
  11209. for (var i = 0; i < markers.length; ++i)
  11210. { markers[i].parent = this; }
  11211. };
  11212. SharedTextMarker.prototype.clear = function () {
  11213. if (this.explicitlyCleared) { return }
  11214. this.explicitlyCleared = true;
  11215. for (var i = 0; i < this.markers.length; ++i)
  11216. { this.markers[i].clear(); }
  11217. signalLater(this, "clear");
  11218. };
  11219. SharedTextMarker.prototype.find = function (side, lineObj) {
  11220. return this.primary.find(side, lineObj)
  11221. };
  11222. eventMixin(SharedTextMarker);
  11223. function markTextShared(doc, from, to, options, type) {
  11224. options = copyObj(options);
  11225. options.shared = false;
  11226. var markers = [markText(doc, from, to, options, type)], primary = markers[0];
  11227. var widget = options.widgetNode;
  11228. linkedDocs(doc, function (doc) {
  11229. if (widget) { options.widgetNode = widget.cloneNode(true); }
  11230. markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
  11231. for (var i = 0; i < doc.linked.length; ++i)
  11232. { if (doc.linked[i].isParent) { return } }
  11233. primary = lst(markers);
  11234. });
  11235. return new SharedTextMarker(markers, primary)
  11236. }
  11237. function findSharedMarkers(doc) {
  11238. return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
  11239. }
  11240. function copySharedMarkers(doc, markers) {
  11241. for (var i = 0; i < markers.length; i++) {
  11242. var marker = markers[i], pos = marker.find();
  11243. var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
  11244. if (cmp(mFrom, mTo)) {
  11245. var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
  11246. marker.markers.push(subMark);
  11247. subMark.parent = marker;
  11248. }
  11249. }
  11250. }
  11251. function detachSharedMarkers(markers) {
  11252. var loop = function ( i ) {
  11253. var marker = markers[i], linked = [marker.primary.doc];
  11254. linkedDocs(marker.primary.doc, function (d) { return linked.push(d); });
  11255. for (var j = 0; j < marker.markers.length; j++) {
  11256. var subMarker = marker.markers[j];
  11257. if (indexOf(linked, subMarker.doc) == -1) {
  11258. subMarker.parent = null;
  11259. marker.markers.splice(j--, 1);
  11260. }
  11261. }
  11262. };
  11263. for (var i = 0; i < markers.length; i++) loop( i );
  11264. }
  11265. var nextDocId = 0;
  11266. var Doc = function(text, mode, firstLine, lineSep, direction) {
  11267. if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
  11268. if (firstLine == null) { firstLine = 0; }
  11269. BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
  11270. this.first = firstLine;
  11271. this.scrollTop = this.scrollLeft = 0;
  11272. this.cantEdit = false;
  11273. this.cleanGeneration = 1;
  11274. this.modeFrontier = this.highlightFrontier = firstLine;
  11275. var start = Pos(firstLine, 0);
  11276. this.sel = simpleSelection(start);
  11277. this.history = new History(null);
  11278. this.id = ++nextDocId;
  11279. this.modeOption = mode;
  11280. this.lineSep = lineSep;
  11281. this.direction = (direction == "rtl") ? "rtl" : "ltr";
  11282. this.extend = false;
  11283. if (typeof text == "string") { text = this.splitLines(text); }
  11284. updateDoc(this, {from: start, to: start, text: text});
  11285. setSelection(this, simpleSelection(start), sel_dontScroll);
  11286. };
  11287. Doc.prototype = createObj(BranchChunk.prototype, {
  11288. constructor: Doc,
  11289. // Iterate over the document. Supports two forms -- with only one
  11290. // argument, it calls that for each line in the document. With
  11291. // three, it iterates over the range given by the first two (with
  11292. // the second being non-inclusive).
  11293. iter: function(from, to, op) {
  11294. if (op) { this.iterN(from - this.first, to - from, op); }
  11295. else { this.iterN(this.first, this.first + this.size, from); }
  11296. },
  11297. // Non-public interface for adding and removing lines.
  11298. insert: function(at, lines) {
  11299. var height = 0;
  11300. for (var i = 0; i < lines.length; ++i) { height += lines[i].height; }
  11301. this.insertInner(at - this.first, lines, height);
  11302. },
  11303. remove: function(at, n) { this.removeInner(at - this.first, n); },
  11304. // From here, the methods are part of the public interface. Most
  11305. // are also available from CodeMirror (editor) instances.
  11306. getValue: function(lineSep) {
  11307. var lines = getLines(this, this.first, this.first + this.size);
  11308. if (lineSep === false) { return lines }
  11309. return lines.join(lineSep || this.lineSeparator())
  11310. },
  11311. setValue: docMethodOp(function(code) {
  11312. var top = Pos(this.first, 0), last = this.first + this.size - 1;
  11313. makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
  11314. text: this.splitLines(code), origin: "setValue", full: true}, true);
  11315. if (this.cm) { scrollToCoords(this.cm, 0, 0); }
  11316. setSelection(this, simpleSelection(top), sel_dontScroll);
  11317. }),
  11318. replaceRange: function(code, from, to, origin) {
  11319. from = clipPos(this, from);
  11320. to = to ? clipPos(this, to) : from;
  11321. replaceRange(this, code, from, to, origin);
  11322. },
  11323. getRange: function(from, to, lineSep) {
  11324. var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
  11325. if (lineSep === false) { return lines }
  11326. return lines.join(lineSep || this.lineSeparator())
  11327. },
  11328. getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
  11329. getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
  11330. getLineNumber: function(line) {return lineNo(line)},
  11331. getLineHandleVisualStart: function(line) {
  11332. if (typeof line == "number") { line = getLine(this, line); }
  11333. return visualLine(line)
  11334. },
  11335. lineCount: function() {return this.size},
  11336. firstLine: function() {return this.first},
  11337. lastLine: function() {return this.first + this.size - 1},
  11338. clipPos: function(pos) {return clipPos(this, pos)},
  11339. getCursor: function(start) {
  11340. var range = this.sel.primary(), pos;
  11341. if (start == null || start == "head") { pos = range.head; }
  11342. else if (start == "anchor") { pos = range.anchor; }
  11343. else if (start == "end" || start == "to" || start === false) { pos = range.to(); }
  11344. else { pos = range.from(); }
  11345. return pos
  11346. },
  11347. listSelections: function() { return this.sel.ranges },
  11348. somethingSelected: function() {return this.sel.somethingSelected()},
  11349. setCursor: docMethodOp(function(line, ch, options) {
  11350. setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
  11351. }),
  11352. setSelection: docMethodOp(function(anchor, head, options) {
  11353. setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
  11354. }),
  11355. extendSelection: docMethodOp(function(head, other, options) {
  11356. extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
  11357. }),
  11358. extendSelections: docMethodOp(function(heads, options) {
  11359. extendSelections(this, clipPosArray(this, heads), options);
  11360. }),
  11361. extendSelectionsBy: docMethodOp(function(f, options) {
  11362. var heads = map(this.sel.ranges, f);
  11363. extendSelections(this, clipPosArray(this, heads), options);
  11364. }),
  11365. setSelections: docMethodOp(function(ranges, primary, options) {
  11366. if (!ranges.length) { return }
  11367. var out = [];
  11368. for (var i = 0; i < ranges.length; i++)
  11369. { out[i] = new Range(clipPos(this, ranges[i].anchor),
  11370. clipPos(this, ranges[i].head)); }
  11371. if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); }
  11372. setSelection(this, normalizeSelection(this.cm, out, primary), options);
  11373. }),
  11374. addSelection: docMethodOp(function(anchor, head, options) {
  11375. var ranges = this.sel.ranges.slice(0);
  11376. ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
  11377. setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);
  11378. }),
  11379. getSelection: function(lineSep) {
  11380. var ranges = this.sel.ranges, lines;
  11381. for (var i = 0; i < ranges.length; i++) {
  11382. var sel = getBetween(this, ranges[i].from(), ranges[i].to());
  11383. lines = lines ? lines.concat(sel) : sel;
  11384. }
  11385. if (lineSep === false) { return lines }
  11386. else { return lines.join(lineSep || this.lineSeparator()) }
  11387. },
  11388. getSelections: function(lineSep) {
  11389. var parts = [], ranges = this.sel.ranges;
  11390. for (var i = 0; i < ranges.length; i++) {
  11391. var sel = getBetween(this, ranges[i].from(), ranges[i].to());
  11392. if (lineSep !== false) { sel = sel.join(lineSep || this.lineSeparator()); }
  11393. parts[i] = sel;
  11394. }
  11395. return parts
  11396. },
  11397. replaceSelection: function(code, collapse, origin) {
  11398. var dup = [];
  11399. for (var i = 0; i < this.sel.ranges.length; i++)
  11400. { dup[i] = code; }
  11401. this.replaceSelections(dup, collapse, origin || "+input");
  11402. },
  11403. replaceSelections: docMethodOp(function(code, collapse, origin) {
  11404. var changes = [], sel = this.sel;
  11405. for (var i = 0; i < sel.ranges.length; i++) {
  11406. var range = sel.ranges[i];
  11407. changes[i] = {from: range.from(), to: range.to(), text: this.splitLines(code[i]), origin: origin};
  11408. }
  11409. var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
  11410. for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
  11411. { makeChange(this, changes[i$1]); }
  11412. if (newSel) { setSelectionReplaceHistory(this, newSel); }
  11413. else if (this.cm) { ensureCursorVisible(this.cm); }
  11414. }),
  11415. undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
  11416. redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
  11417. undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
  11418. redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
  11419. setExtending: function(val) {this.extend = val;},
  11420. getExtending: function() {return this.extend},
  11421. historySize: function() {
  11422. var hist = this.history, done = 0, undone = 0;
  11423. for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } }
  11424. for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } }
  11425. return {undo: done, redo: undone}
  11426. },
  11427. clearHistory: function() {
  11428. var this$1 = this;
  11429. this.history = new History(this.history.maxGeneration);
  11430. linkedDocs(this, function (doc) { return doc.history = this$1.history; }, true);
  11431. },
  11432. markClean: function() {
  11433. this.cleanGeneration = this.changeGeneration(true);
  11434. },
  11435. changeGeneration: function(forceSplit) {
  11436. if (forceSplit)
  11437. { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; }
  11438. return this.history.generation
  11439. },
  11440. isClean: function (gen) {
  11441. return this.history.generation == (gen || this.cleanGeneration)
  11442. },
  11443. getHistory: function() {
  11444. return {done: copyHistoryArray(this.history.done),
  11445. undone: copyHistoryArray(this.history.undone)}
  11446. },
  11447. setHistory: function(histData) {
  11448. var hist = this.history = new History(this.history.maxGeneration);
  11449. hist.done = copyHistoryArray(histData.done.slice(0), null, true);
  11450. hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
  11451. },
  11452. setGutterMarker: docMethodOp(function(line, gutterID, value) {
  11453. return changeLine(this, line, "gutter", function (line) {
  11454. var markers = line.gutterMarkers || (line.gutterMarkers = {});
  11455. markers[gutterID] = value;
  11456. if (!value && isEmpty(markers)) { line.gutterMarkers = null; }
  11457. return true
  11458. })
  11459. }),
  11460. clearGutter: docMethodOp(function(gutterID) {
  11461. var this$1 = this;
  11462. this.iter(function (line) {
  11463. if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
  11464. changeLine(this$1, line, "gutter", function () {
  11465. line.gutterMarkers[gutterID] = null;
  11466. if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; }
  11467. return true
  11468. });
  11469. }
  11470. });
  11471. }),
  11472. lineInfo: function(line) {
  11473. var n;
  11474. if (typeof line == "number") {
  11475. if (!isLine(this, line)) { return null }
  11476. n = line;
  11477. line = getLine(this, line);
  11478. if (!line) { return null }
  11479. } else {
  11480. n = lineNo(line);
  11481. if (n == null) { return null }
  11482. }
  11483. return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
  11484. textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
  11485. widgets: line.widgets}
  11486. },
  11487. addLineClass: docMethodOp(function(handle, where, cls) {
  11488. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
  11489. var prop = where == "text" ? "textClass"
  11490. : where == "background" ? "bgClass"
  11491. : where == "gutter" ? "gutterClass" : "wrapClass";
  11492. if (!line[prop]) { line[prop] = cls; }
  11493. else if (classTest(cls).test(line[prop])) { return false }
  11494. else { line[prop] += " " + cls; }
  11495. return true
  11496. })
  11497. }),
  11498. removeLineClass: docMethodOp(function(handle, where, cls) {
  11499. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
  11500. var prop = where == "text" ? "textClass"
  11501. : where == "background" ? "bgClass"
  11502. : where == "gutter" ? "gutterClass" : "wrapClass";
  11503. var cur = line[prop];
  11504. if (!cur) { return false }
  11505. else if (cls == null) { line[prop] = null; }
  11506. else {
  11507. var found = cur.match(classTest(cls));
  11508. if (!found) { return false }
  11509. var end = found.index + found[0].length;
  11510. line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
  11511. }
  11512. return true
  11513. })
  11514. }),
  11515. addLineWidget: docMethodOp(function(handle, node, options) {
  11516. return addLineWidget(this, handle, node, options)
  11517. }),
  11518. removeLineWidget: function(widget) { widget.clear(); },
  11519. markText: function(from, to, options) {
  11520. return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
  11521. },
  11522. setBookmark: function(pos, options) {
  11523. var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
  11524. insertLeft: options && options.insertLeft,
  11525. clearWhenEmpty: false, shared: options && options.shared,
  11526. handleMouseEvents: options && options.handleMouseEvents};
  11527. pos = clipPos(this, pos);
  11528. return markText(this, pos, pos, realOpts, "bookmark")
  11529. },
  11530. findMarksAt: function(pos) {
  11531. pos = clipPos(this, pos);
  11532. var markers = [], spans = getLine(this, pos.line).markedSpans;
  11533. if (spans) { for (var i = 0; i < spans.length; ++i) {
  11534. var span = spans[i];
  11535. if ((span.from == null || span.from <= pos.ch) &&
  11536. (span.to == null || span.to >= pos.ch))
  11537. { markers.push(span.marker.parent || span.marker); }
  11538. } }
  11539. return markers
  11540. },
  11541. findMarks: function(from, to, filter) {
  11542. from = clipPos(this, from); to = clipPos(this, to);
  11543. var found = [], lineNo = from.line;
  11544. this.iter(from.line, to.line + 1, function (line) {
  11545. var spans = line.markedSpans;
  11546. if (spans) { for (var i = 0; i < spans.length; i++) {
  11547. var span = spans[i];
  11548. if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
  11549. span.from == null && lineNo != from.line ||
  11550. span.from != null && lineNo == to.line && span.from >= to.ch) &&
  11551. (!filter || filter(span.marker)))
  11552. { found.push(span.marker.parent || span.marker); }
  11553. } }
  11554. ++lineNo;
  11555. });
  11556. return found
  11557. },
  11558. getAllMarks: function() {
  11559. var markers = [];
  11560. this.iter(function (line) {
  11561. var sps = line.markedSpans;
  11562. if (sps) { for (var i = 0; i < sps.length; ++i)
  11563. { if (sps[i].from != null) { markers.push(sps[i].marker); } } }
  11564. });
  11565. return markers
  11566. },
  11567. posFromIndex: function(off) {
  11568. var ch, lineNo = this.first, sepSize = this.lineSeparator().length;
  11569. this.iter(function (line) {
  11570. var sz = line.text.length + sepSize;
  11571. if (sz > off) { ch = off; return true }
  11572. off -= sz;
  11573. ++lineNo;
  11574. });
  11575. return clipPos(this, Pos(lineNo, ch))
  11576. },
  11577. indexFromPos: function (coords) {
  11578. coords = clipPos(this, coords);
  11579. var index = coords.ch;
  11580. if (coords.line < this.first || coords.ch < 0) { return 0 }
  11581. var sepSize = this.lineSeparator().length;
  11582. this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
  11583. index += line.text.length + sepSize;
  11584. });
  11585. return index
  11586. },
  11587. copy: function(copyHistory) {
  11588. var doc = new Doc(getLines(this, this.first, this.first + this.size),
  11589. this.modeOption, this.first, this.lineSep, this.direction);
  11590. doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
  11591. doc.sel = this.sel;
  11592. doc.extend = false;
  11593. if (copyHistory) {
  11594. doc.history.undoDepth = this.history.undoDepth;
  11595. doc.setHistory(this.getHistory());
  11596. }
  11597. return doc
  11598. },
  11599. linkedDoc: function(options) {
  11600. if (!options) { options = {}; }
  11601. var from = this.first, to = this.first + this.size;
  11602. if (options.from != null && options.from > from) { from = options.from; }
  11603. if (options.to != null && options.to < to) { to = options.to; }
  11604. var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
  11605. if (options.sharedHist) { copy.history = this.history
  11606. ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
  11607. copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
  11608. copySharedMarkers(copy, findSharedMarkers(this));
  11609. return copy
  11610. },
  11611. unlinkDoc: function(other) {
  11612. if (other instanceof CodeMirror) { other = other.doc; }
  11613. if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
  11614. var link = this.linked[i];
  11615. if (link.doc != other) { continue }
  11616. this.linked.splice(i, 1);
  11617. other.unlinkDoc(this);
  11618. detachSharedMarkers(findSharedMarkers(this));
  11619. break
  11620. } }
  11621. // If the histories were shared, split them again
  11622. if (other.history == this.history) {
  11623. var splitIds = [other.id];
  11624. linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true);
  11625. other.history = new History(null);
  11626. other.history.done = copyHistoryArray(this.history.done, splitIds);
  11627. other.history.undone = copyHistoryArray(this.history.undone, splitIds);
  11628. }
  11629. },
  11630. iterLinkedDocs: function(f) {linkedDocs(this, f);},
  11631. getMode: function() {return this.mode},
  11632. getEditor: function() {return this.cm},
  11633. splitLines: function(str) {
  11634. if (this.lineSep) { return str.split(this.lineSep) }
  11635. return splitLinesAuto(str)
  11636. },
  11637. lineSeparator: function() { return this.lineSep || "\n" },
  11638. setDirection: docMethodOp(function (dir) {
  11639. if (dir != "rtl") { dir = "ltr"; }
  11640. if (dir == this.direction) { return }
  11641. this.direction = dir;
  11642. this.iter(function (line) { return line.order = null; });
  11643. if (this.cm) { directionChanged(this.cm); }
  11644. })
  11645. });
  11646. // Public alias.
  11647. Doc.prototype.eachLine = Doc.prototype.iter;
  11648. // Kludge to work around strange IE behavior where it'll sometimes
  11649. // re-fire a series of drag-related events right after the drop (#1551)
  11650. var lastDrop = 0;
  11651. function onDrop(e) {
  11652. var cm = this;
  11653. clearDragCursor(cm);
  11654. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
  11655. { return }
  11656. e_preventDefault(e);
  11657. if (ie) { lastDrop = +new Date; }
  11658. var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
  11659. if (!pos || cm.isReadOnly()) { return }
  11660. // Might be a file drop, in which case we simply extract the text
  11661. // and insert it.
  11662. if (files && files.length && window.FileReader && window.File) {
  11663. var n = files.length, text = Array(n), read = 0;
  11664. var markAsReadAndPasteIfAllFilesAreRead = function () {
  11665. if (++read == n) {
  11666. operation(cm, function () {
  11667. pos = clipPos(cm.doc, pos);
  11668. var change = {from: pos, to: pos,
  11669. text: cm.doc.splitLines(
  11670. text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())),
  11671. origin: "paste"};
  11672. makeChange(cm.doc, change);
  11673. setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change))));
  11674. })();
  11675. }
  11676. };
  11677. var readTextFromFile = function (file, i) {
  11678. if (cm.options.allowDropFileTypes &&
  11679. indexOf(cm.options.allowDropFileTypes, file.type) == -1) {
  11680. markAsReadAndPasteIfAllFilesAreRead();
  11681. return
  11682. }
  11683. var reader = new FileReader;
  11684. reader.onerror = function () { return markAsReadAndPasteIfAllFilesAreRead(); };
  11685. reader.onload = function () {
  11686. var content = reader.result;
  11687. if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) {
  11688. markAsReadAndPasteIfAllFilesAreRead();
  11689. return
  11690. }
  11691. text[i] = content;
  11692. markAsReadAndPasteIfAllFilesAreRead();
  11693. };
  11694. reader.readAsText(file);
  11695. };
  11696. for (var i = 0; i < files.length; i++) { readTextFromFile(files[i], i); }
  11697. } else { // Normal drop
  11698. // Don't do a replace if the drop happened inside of the selected text.
  11699. if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
  11700. cm.state.draggingText(e);
  11701. // Ensure the editor is re-focused
  11702. setTimeout(function () { return cm.display.input.focus(); }, 20);
  11703. return
  11704. }
  11705. try {
  11706. var text$1 = e.dataTransfer.getData("Text");
  11707. if (text$1) {
  11708. var selected;
  11709. if (cm.state.draggingText && !cm.state.draggingText.copy)
  11710. { selected = cm.listSelections(); }
  11711. setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
  11712. if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
  11713. { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } }
  11714. cm.replaceSelection(text$1, "around", "paste");
  11715. cm.display.input.focus();
  11716. }
  11717. }
  11718. catch(e){}
  11719. }
  11720. }
  11721. function onDragStart(cm, e) {
  11722. if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
  11723. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
  11724. e.dataTransfer.setData("Text", cm.getSelection());
  11725. e.dataTransfer.effectAllowed = "copyMove";
  11726. // Use dummy image instead of default browsers image.
  11727. // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
  11728. if (e.dataTransfer.setDragImage && !safari) {
  11729. var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
  11730. img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  11731. if (presto) {
  11732. img.width = img.height = 1;
  11733. cm.display.wrapper.appendChild(img);
  11734. // Force a relayout, or Opera won't use our image for some obscure reason
  11735. img._top = img.offsetTop;
  11736. }
  11737. e.dataTransfer.setDragImage(img, 0, 0);
  11738. if (presto) { img.parentNode.removeChild(img); }
  11739. }
  11740. }
  11741. function onDragOver(cm, e) {
  11742. var pos = posFromMouse(cm, e);
  11743. if (!pos) { return }
  11744. var frag = document.createDocumentFragment();
  11745. drawSelectionCursor(cm, pos, frag);
  11746. if (!cm.display.dragCursor) {
  11747. cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
  11748. cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
  11749. }
  11750. removeChildrenAndAdd(cm.display.dragCursor, frag);
  11751. }
  11752. function clearDragCursor(cm) {
  11753. if (cm.display.dragCursor) {
  11754. cm.display.lineSpace.removeChild(cm.display.dragCursor);
  11755. cm.display.dragCursor = null;
  11756. }
  11757. }
  11758. // These must be handled carefully, because naively registering a
  11759. // handler for each editor will cause the editors to never be
  11760. // garbage collected.
  11761. function forEachCodeMirror(f) {
  11762. if (!document.getElementsByClassName) { return }
  11763. var byClass = document.getElementsByClassName("CodeMirror"), editors = [];
  11764. for (var i = 0; i < byClass.length; i++) {
  11765. var cm = byClass[i].CodeMirror;
  11766. if (cm) { editors.push(cm); }
  11767. }
  11768. if (editors.length) { editors[0].operation(function () {
  11769. for (var i = 0; i < editors.length; i++) { f(editors[i]); }
  11770. }); }
  11771. }
  11772. var globalsRegistered = false;
  11773. function ensureGlobalHandlers() {
  11774. if (globalsRegistered) { return }
  11775. registerGlobalHandlers();
  11776. globalsRegistered = true;
  11777. }
  11778. function registerGlobalHandlers() {
  11779. // When the window resizes, we need to refresh active editors.
  11780. var resizeTimer;
  11781. on(window, "resize", function () {
  11782. if (resizeTimer == null) { resizeTimer = setTimeout(function () {
  11783. resizeTimer = null;
  11784. forEachCodeMirror(onResize);
  11785. }, 100); }
  11786. });
  11787. // When the window loses focus, we want to show the editor as blurred
  11788. on(window, "blur", function () { return forEachCodeMirror(onBlur); });
  11789. }
  11790. // Called when the window resizes
  11791. function onResize(cm) {
  11792. var d = cm.display;
  11793. // Might be a text scaling operation, clear size caches.
  11794. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  11795. d.scrollbarsClipped = false;
  11796. cm.setSize();
  11797. }
  11798. var keyNames = {
  11799. 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
  11800. 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
  11801. 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
  11802. 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
  11803. 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 145: "ScrollLock",
  11804. 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
  11805. 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
  11806. 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
  11807. };
  11808. // Number keys
  11809. for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); }
  11810. // Alphabetic keys
  11811. for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); }
  11812. // Function keys
  11813. for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; }
  11814. var keyMap = {};
  11815. keyMap.basic = {
  11816. "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
  11817. "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
  11818. "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
  11819. "Tab": "defaultTab", "Shift-Tab": "indentAuto",
  11820. "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
  11821. "Esc": "singleSelection"
  11822. };
  11823. // Note that the save and find-related commands aren't defined by
  11824. // default. User code or addons can define them. Unknown commands
  11825. // are simply ignored.
  11826. keyMap.pcDefault = {
  11827. "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
  11828. "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
  11829. "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
  11830. "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
  11831. "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
  11832. "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
  11833. "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
  11834. "fallthrough": "basic"
  11835. };
  11836. // Very basic readline/emacs-style bindings, which are standard on Mac.
  11837. keyMap.emacsy = {
  11838. "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
  11839. "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
  11840. "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
  11841. "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
  11842. "Ctrl-O": "openLine"
  11843. };
  11844. keyMap.macDefault = {
  11845. "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
  11846. "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
  11847. "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
  11848. "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
  11849. "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
  11850. "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
  11851. "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
  11852. "fallthrough": ["basic", "emacsy"]
  11853. };
  11854. keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
  11855. // KEYMAP DISPATCH
  11856. function normalizeKeyName(name) {
  11857. var parts = name.split(/-(?!$)/);
  11858. name = parts[parts.length - 1];
  11859. var alt, ctrl, shift, cmd;
  11860. for (var i = 0; i < parts.length - 1; i++) {
  11861. var mod = parts[i];
  11862. if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; }
  11863. else if (/^a(lt)?$/i.test(mod)) { alt = true; }
  11864. else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; }
  11865. else if (/^s(hift)?$/i.test(mod)) { shift = true; }
  11866. else { throw new Error("Unrecognized modifier name: " + mod) }
  11867. }
  11868. if (alt) { name = "Alt-" + name; }
  11869. if (ctrl) { name = "Ctrl-" + name; }
  11870. if (cmd) { name = "Cmd-" + name; }
  11871. if (shift) { name = "Shift-" + name; }
  11872. return name
  11873. }
  11874. // This is a kludge to keep keymaps mostly working as raw objects
  11875. // (backwards compatibility) while at the same time support features
  11876. // like normalization and multi-stroke key bindings. It compiles a
  11877. // new normalized keymap, and then updates the old object to reflect
  11878. // this.
  11879. function normalizeKeyMap(keymap) {
  11880. var copy = {};
  11881. for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
  11882. var value = keymap[keyname];
  11883. if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
  11884. if (value == "...") { delete keymap[keyname]; continue }
  11885. var keys = map(keyname.split(" "), normalizeKeyName);
  11886. for (var i = 0; i < keys.length; i++) {
  11887. var val = (void 0), name = (void 0);
  11888. if (i == keys.length - 1) {
  11889. name = keys.join(" ");
  11890. val = value;
  11891. } else {
  11892. name = keys.slice(0, i + 1).join(" ");
  11893. val = "...";
  11894. }
  11895. var prev = copy[name];
  11896. if (!prev) { copy[name] = val; }
  11897. else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
  11898. }
  11899. delete keymap[keyname];
  11900. } }
  11901. for (var prop in copy) { keymap[prop] = copy[prop]; }
  11902. return keymap
  11903. }
  11904. function lookupKey(key, map, handle, context) {
  11905. map = getKeyMap(map);
  11906. var found = map.call ? map.call(key, context) : map[key];
  11907. if (found === false) { return "nothing" }
  11908. if (found === "...") { return "multi" }
  11909. if (found != null && handle(found)) { return "handled" }
  11910. if (map.fallthrough) {
  11911. if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
  11912. { return lookupKey(key, map.fallthrough, handle, context) }
  11913. for (var i = 0; i < map.fallthrough.length; i++) {
  11914. var result = lookupKey(key, map.fallthrough[i], handle, context);
  11915. if (result) { return result }
  11916. }
  11917. }
  11918. }
  11919. // Modifier key presses don't count as 'real' key presses for the
  11920. // purpose of keymap fallthrough.
  11921. function isModifierKey(value) {
  11922. var name = typeof value == "string" ? value : keyNames[value.keyCode];
  11923. return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
  11924. }
  11925. function addModifierNames(name, event, noShift) {
  11926. var base = name;
  11927. if (event.altKey && base != "Alt") { name = "Alt-" + name; }
  11928. if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; }
  11929. if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name; }
  11930. if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; }
  11931. return name
  11932. }
  11933. // Look up the name of a key as indicated by an event object.
  11934. function keyName(event, noShift) {
  11935. if (presto && event.keyCode == 34 && event["char"]) { return false }
  11936. var name = keyNames[event.keyCode];
  11937. if (name == null || event.altGraphKey) { return false }
  11938. // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
  11939. // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
  11940. if (event.keyCode == 3 && event.code) { name = event.code; }
  11941. return addModifierNames(name, event, noShift)
  11942. }
  11943. function getKeyMap(val) {
  11944. return typeof val == "string" ? keyMap[val] : val
  11945. }
  11946. // Helper for deleting text near the selection(s), used to implement
  11947. // backspace, delete, and similar functionality.
  11948. function deleteNearSelection(cm, compute) {
  11949. var ranges = cm.doc.sel.ranges, kill = [];
  11950. // Build up a set of ranges to kill first, merging overlapping
  11951. // ranges.
  11952. for (var i = 0; i < ranges.length; i++) {
  11953. var toKill = compute(ranges[i]);
  11954. while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
  11955. var replaced = kill.pop();
  11956. if (cmp(replaced.from, toKill.from) < 0) {
  11957. toKill.from = replaced.from;
  11958. break
  11959. }
  11960. }
  11961. kill.push(toKill);
  11962. }
  11963. // Next, remove those actual ranges.
  11964. runInOp(cm, function () {
  11965. for (var i = kill.length - 1; i >= 0; i--)
  11966. { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); }
  11967. ensureCursorVisible(cm);
  11968. });
  11969. }
  11970. function moveCharLogically(line, ch, dir) {
  11971. var target = skipExtendingChars(line.text, ch + dir, dir);
  11972. return target < 0 || target > line.text.length ? null : target
  11973. }
  11974. function moveLogically(line, start, dir) {
  11975. var ch = moveCharLogically(line, start.ch, dir);
  11976. return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
  11977. }
  11978. function endOfLine(visually, cm, lineObj, lineNo, dir) {
  11979. if (visually) {
  11980. if (cm.doc.direction == "rtl") { dir = -dir; }
  11981. var order = getOrder(lineObj, cm.doc.direction);
  11982. if (order) {
  11983. var part = dir < 0 ? lst(order) : order[0];
  11984. var moveInStorageOrder = (dir < 0) == (part.level == 1);
  11985. var sticky = moveInStorageOrder ? "after" : "before";
  11986. var ch;
  11987. // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
  11988. // it could be that the last bidi part is not on the last visual line,
  11989. // since visual lines contain content order-consecutive chunks.
  11990. // Thus, in rtl, we are looking for the first (content-order) character
  11991. // in the rtl chunk that is on the last line (that is, the same line
  11992. // as the last (content-order) character).
  11993. if (part.level > 0 || cm.doc.direction == "rtl") {
  11994. var prep = prepareMeasureForLine(cm, lineObj);
  11995. ch = dir < 0 ? lineObj.text.length - 1 : 0;
  11996. var targetTop = measureCharPrepared(cm, prep, ch).top;
  11997. ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch);
  11998. if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1); }
  11999. } else { ch = dir < 0 ? part.to : part.from; }
  12000. return new Pos(lineNo, ch, sticky)
  12001. }
  12002. }
  12003. return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
  12004. }
  12005. function moveVisually(cm, line, start, dir) {
  12006. var bidi = getOrder(line, cm.doc.direction);
  12007. if (!bidi) { return moveLogically(line, start, dir) }
  12008. if (start.ch >= line.text.length) {
  12009. start.ch = line.text.length;
  12010. start.sticky = "before";
  12011. } else if (start.ch <= 0) {
  12012. start.ch = 0;
  12013. start.sticky = "after";
  12014. }
  12015. var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
  12016. if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
  12017. // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
  12018. // nothing interesting happens.
  12019. return moveLogically(line, start, dir)
  12020. }
  12021. var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); };
  12022. var prep;
  12023. var getWrappedLineExtent = function (ch) {
  12024. if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
  12025. prep = prep || prepareMeasureForLine(cm, line);
  12026. return wrappedLineExtentChar(cm, line, prep, ch)
  12027. };
  12028. var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
  12029. if (cm.doc.direction == "rtl" || part.level == 1) {
  12030. var moveInStorageOrder = (part.level == 1) == (dir < 0);
  12031. var ch = mv(start, moveInStorageOrder ? 1 : -1);
  12032. if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
  12033. // Case 2: We move within an rtl part or in an rtl editor on the same visual line
  12034. var sticky = moveInStorageOrder ? "before" : "after";
  12035. return new Pos(start.line, ch, sticky)
  12036. }
  12037. }
  12038. // Case 3: Could not move within this bidi part in this visual line, so leave
  12039. // the current bidi part
  12040. var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
  12041. var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
  12042. ? new Pos(start.line, mv(ch, 1), "before")
  12043. : new Pos(start.line, ch, "after"); };
  12044. for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
  12045. var part = bidi[partPos];
  12046. var moveInStorageOrder = (dir > 0) == (part.level != 1);
  12047. var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
  12048. if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
  12049. ch = moveInStorageOrder ? part.from : mv(part.to, -1);
  12050. if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
  12051. }
  12052. };
  12053. // Case 3a: Look for other bidi parts on the same visual line
  12054. var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
  12055. if (res) { return res }
  12056. // Case 3b: Look for other bidi parts on the next visual line
  12057. var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
  12058. if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
  12059. res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
  12060. if (res) { return res }
  12061. }
  12062. // Case 4: Nowhere to move
  12063. return null
  12064. }
  12065. // Commands are parameter-less actions that can be performed on an
  12066. // editor, mostly used for keybindings.
  12067. var commands = {
  12068. selectAll: selectAll,
  12069. singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
  12070. killLine: function (cm) { return deleteNearSelection(cm, function (range) {
  12071. if (range.empty()) {
  12072. var len = getLine(cm.doc, range.head.line).text.length;
  12073. if (range.head.ch == len && range.head.line < cm.lastLine())
  12074. { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
  12075. else
  12076. { return {from: range.head, to: Pos(range.head.line, len)} }
  12077. } else {
  12078. return {from: range.from(), to: range.to()}
  12079. }
  12080. }); },
  12081. deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
  12082. from: Pos(range.from().line, 0),
  12083. to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
  12084. }); }); },
  12085. delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
  12086. from: Pos(range.from().line, 0), to: range.from()
  12087. }); }); },
  12088. delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
  12089. var top = cm.charCoords(range.head, "div").top + 5;
  12090. var leftPos = cm.coordsChar({left: 0, top: top}, "div");
  12091. return {from: leftPos, to: range.from()}
  12092. }); },
  12093. delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
  12094. var top = cm.charCoords(range.head, "div").top + 5;
  12095. var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
  12096. return {from: range.from(), to: rightPos }
  12097. }); },
  12098. undo: function (cm) { return cm.undo(); },
  12099. redo: function (cm) { return cm.redo(); },
  12100. undoSelection: function (cm) { return cm.undoSelection(); },
  12101. redoSelection: function (cm) { return cm.redoSelection(); },
  12102. goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
  12103. goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
  12104. goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
  12105. {origin: "+move", bias: 1}
  12106. ); },
  12107. goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
  12108. {origin: "+move", bias: 1}
  12109. ); },
  12110. goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
  12111. {origin: "+move", bias: -1}
  12112. ); },
  12113. goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
  12114. var top = cm.cursorCoords(range.head, "div").top + 5;
  12115. return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
  12116. }, sel_move); },
  12117. goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
  12118. var top = cm.cursorCoords(range.head, "div").top + 5;
  12119. return cm.coordsChar({left: 0, top: top}, "div")
  12120. }, sel_move); },
  12121. goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
  12122. var top = cm.cursorCoords(range.head, "div").top + 5;
  12123. var pos = cm.coordsChar({left: 0, top: top}, "div");
  12124. if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
  12125. return pos
  12126. }, sel_move); },
  12127. goLineUp: function (cm) { return cm.moveV(-1, "line"); },
  12128. goLineDown: function (cm) { return cm.moveV(1, "line"); },
  12129. goPageUp: function (cm) { return cm.moveV(-1, "page"); },
  12130. goPageDown: function (cm) { return cm.moveV(1, "page"); },
  12131. goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
  12132. goCharRight: function (cm) { return cm.moveH(1, "char"); },
  12133. goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
  12134. goColumnRight: function (cm) { return cm.moveH(1, "column"); },
  12135. goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
  12136. goGroupRight: function (cm) { return cm.moveH(1, "group"); },
  12137. goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
  12138. goWordRight: function (cm) { return cm.moveH(1, "word"); },
  12139. delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
  12140. delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
  12141. delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
  12142. delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
  12143. delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
  12144. delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
  12145. indentAuto: function (cm) { return cm.indentSelection("smart"); },
  12146. indentMore: function (cm) { return cm.indentSelection("add"); },
  12147. indentLess: function (cm) { return cm.indentSelection("subtract"); },
  12148. insertTab: function (cm) { return cm.replaceSelection("\t"); },
  12149. insertSoftTab: function (cm) {
  12150. var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
  12151. for (var i = 0; i < ranges.length; i++) {
  12152. var pos = ranges[i].from();
  12153. var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
  12154. spaces.push(spaceStr(tabSize - col % tabSize));
  12155. }
  12156. cm.replaceSelections(spaces);
  12157. },
  12158. defaultTab: function (cm) {
  12159. if (cm.somethingSelected()) { cm.indentSelection("add"); }
  12160. else { cm.execCommand("insertTab"); }
  12161. },
  12162. // Swap the two chars left and right of each selection's head.
  12163. // Move cursor behind the two swapped characters afterwards.
  12164. //
  12165. // Doesn't consider line feeds a character.
  12166. // Doesn't scan more than one line above to find a character.
  12167. // Doesn't do anything on an empty line.
  12168. // Doesn't do anything with non-empty selections.
  12169. transposeChars: function (cm) { return runInOp(cm, function () {
  12170. var ranges = cm.listSelections(), newSel = [];
  12171. for (var i = 0; i < ranges.length; i++) {
  12172. if (!ranges[i].empty()) { continue }
  12173. var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
  12174. if (line) {
  12175. if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); }
  12176. if (cur.ch > 0) {
  12177. cur = new Pos(cur.line, cur.ch + 1);
  12178. cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
  12179. Pos(cur.line, cur.ch - 2), cur, "+transpose");
  12180. } else if (cur.line > cm.doc.first) {
  12181. var prev = getLine(cm.doc, cur.line - 1).text;
  12182. if (prev) {
  12183. cur = new Pos(cur.line, 1);
  12184. cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
  12185. prev.charAt(prev.length - 1),
  12186. Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
  12187. }
  12188. }
  12189. }
  12190. newSel.push(new Range(cur, cur));
  12191. }
  12192. cm.setSelections(newSel);
  12193. }); },
  12194. newlineAndIndent: function (cm) { return runInOp(cm, function () {
  12195. var sels = cm.listSelections();
  12196. for (var i = sels.length - 1; i >= 0; i--)
  12197. { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); }
  12198. sels = cm.listSelections();
  12199. for (var i$1 = 0; i$1 < sels.length; i$1++)
  12200. { cm.indentLine(sels[i$1].from().line, null, true); }
  12201. ensureCursorVisible(cm);
  12202. }); },
  12203. openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
  12204. toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
  12205. };
  12206. function lineStart(cm, lineN) {
  12207. var line = getLine(cm.doc, lineN);
  12208. var visual = visualLine(line);
  12209. if (visual != line) { lineN = lineNo(visual); }
  12210. return endOfLine(true, cm, visual, lineN, 1)
  12211. }
  12212. function lineEnd(cm, lineN) {
  12213. var line = getLine(cm.doc, lineN);
  12214. var visual = visualLineEnd(line);
  12215. if (visual != line) { lineN = lineNo(visual); }
  12216. return endOfLine(true, cm, line, lineN, -1)
  12217. }
  12218. function lineStartSmart(cm, pos) {
  12219. var start = lineStart(cm, pos.line);
  12220. var line = getLine(cm.doc, start.line);
  12221. var order = getOrder(line, cm.doc.direction);
  12222. if (!order || order[0].level == 0) {
  12223. var firstNonWS = Math.max(start.ch, line.text.search(/\S/));
  12224. var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
  12225. return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
  12226. }
  12227. return start
  12228. }
  12229. // Run a handler that was bound to a key.
  12230. function doHandleBinding(cm, bound, dropShift) {
  12231. if (typeof bound == "string") {
  12232. bound = commands[bound];
  12233. if (!bound) { return false }
  12234. }
  12235. // Ensure previous input has been read, so that the handler sees a
  12236. // consistent view of the document
  12237. cm.display.input.ensurePolled();
  12238. var prevShift = cm.display.shift, done = false;
  12239. try {
  12240. if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
  12241. if (dropShift) { cm.display.shift = false; }
  12242. done = bound(cm) != Pass;
  12243. } finally {
  12244. cm.display.shift = prevShift;
  12245. cm.state.suppressEdits = false;
  12246. }
  12247. return done
  12248. }
  12249. function lookupKeyForEditor(cm, name, handle) {
  12250. for (var i = 0; i < cm.state.keyMaps.length; i++) {
  12251. var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
  12252. if (result) { return result }
  12253. }
  12254. return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
  12255. || lookupKey(name, cm.options.keyMap, handle, cm)
  12256. }
  12257. // Note that, despite the name, this function is also used to check
  12258. // for bound mouse clicks.
  12259. var stopSeq = new Delayed;
  12260. function dispatchKey(cm, name, e, handle) {
  12261. var seq = cm.state.keySeq;
  12262. if (seq) {
  12263. if (isModifierKey(name)) { return "handled" }
  12264. if (/\'$/.test(name))
  12265. { cm.state.keySeq = null; }
  12266. else
  12267. { stopSeq.set(50, function () {
  12268. if (cm.state.keySeq == seq) {
  12269. cm.state.keySeq = null;
  12270. cm.display.input.reset();
  12271. }
  12272. }); }
  12273. if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
  12274. }
  12275. return dispatchKeyInner(cm, name, e, handle)
  12276. }
  12277. function dispatchKeyInner(cm, name, e, handle) {
  12278. var result = lookupKeyForEditor(cm, name, handle);
  12279. if (result == "multi")
  12280. { cm.state.keySeq = name; }
  12281. if (result == "handled")
  12282. { signalLater(cm, "keyHandled", cm, name, e); }
  12283. if (result == "handled" || result == "multi") {
  12284. e_preventDefault(e);
  12285. restartBlink(cm);
  12286. }
  12287. return !!result
  12288. }
  12289. // Handle a key from the keydown event.
  12290. function handleKeyBinding(cm, e) {
  12291. var name = keyName(e, true);
  12292. if (!name) { return false }
  12293. if (e.shiftKey && !cm.state.keySeq) {
  12294. // First try to resolve full name (including 'Shift-'). Failing
  12295. // that, see if there is a cursor-motion command (starting with
  12296. // 'go') bound to the keyname without 'Shift-'.
  12297. return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
  12298. || dispatchKey(cm, name, e, function (b) {
  12299. if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
  12300. { return doHandleBinding(cm, b) }
  12301. })
  12302. } else {
  12303. return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
  12304. }
  12305. }
  12306. // Handle a key from the keypress event
  12307. function handleCharBinding(cm, e, ch) {
  12308. return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
  12309. }
  12310. var lastStoppedKey = null;
  12311. function onKeyDown(e) {
  12312. var cm = this;
  12313. cm.curOp.focus = activeElt();
  12314. if (signalDOMEvent(cm, e)) { return }
  12315. // IE does strange things with escape.
  12316. if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
  12317. var code = e.keyCode;
  12318. cm.display.shift = code == 16 || e.shiftKey;
  12319. var handled = handleKeyBinding(cm, e);
  12320. if (presto) {
  12321. lastStoppedKey = handled ? code : null;
  12322. // Opera has no cut event... we try to at least catch the key combo
  12323. if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
  12324. { cm.replaceSelection("", null, "cut"); }
  12325. }
  12326. if (gecko && !mac && !handled && code == 46 && e.shiftKey && !e.ctrlKey && document.execCommand)
  12327. { document.execCommand("cut"); }
  12328. // Turn mouse into crosshair when Alt is held on Mac.
  12329. if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
  12330. { showCrossHair(cm); }
  12331. }
  12332. function showCrossHair(cm) {
  12333. var lineDiv = cm.display.lineDiv;
  12334. addClass(lineDiv, "CodeMirror-crosshair");
  12335. function up(e) {
  12336. if (e.keyCode == 18 || !e.altKey) {
  12337. rmClass(lineDiv, "CodeMirror-crosshair");
  12338. off(document, "keyup", up);
  12339. off(document, "mouseover", up);
  12340. }
  12341. }
  12342. on(document, "keyup", up);
  12343. on(document, "mouseover", up);
  12344. }
  12345. function onKeyUp(e) {
  12346. if (e.keyCode == 16) { this.doc.sel.shift = false; }
  12347. signalDOMEvent(this, e);
  12348. }
  12349. function onKeyPress(e) {
  12350. var cm = this;
  12351. if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
  12352. var keyCode = e.keyCode, charCode = e.charCode;
  12353. if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
  12354. if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
  12355. var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
  12356. // Some browsers fire keypress events for backspace
  12357. if (ch == "\x08") { return }
  12358. if (handleCharBinding(cm, e, ch)) { return }
  12359. cm.display.input.onKeyPress(e);
  12360. }
  12361. var DOUBLECLICK_DELAY = 400;
  12362. var PastClick = function(time, pos, button) {
  12363. this.time = time;
  12364. this.pos = pos;
  12365. this.button = button;
  12366. };
  12367. PastClick.prototype.compare = function (time, pos, button) {
  12368. return this.time + DOUBLECLICK_DELAY > time &&
  12369. cmp(pos, this.pos) == 0 && button == this.button
  12370. };
  12371. var lastClick, lastDoubleClick;
  12372. function clickRepeat(pos, button) {
  12373. var now = +new Date;
  12374. if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
  12375. lastClick = lastDoubleClick = null;
  12376. return "triple"
  12377. } else if (lastClick && lastClick.compare(now, pos, button)) {
  12378. lastDoubleClick = new PastClick(now, pos, button);
  12379. lastClick = null;
  12380. return "double"
  12381. } else {
  12382. lastClick = new PastClick(now, pos, button);
  12383. lastDoubleClick = null;
  12384. return "single"
  12385. }
  12386. }
  12387. // A mouse down can be a single click, double click, triple click,
  12388. // start of selection drag, start of text drag, new cursor
  12389. // (ctrl-click), rectangle drag (alt-drag), or xwin
  12390. // middle-click-paste. Or it might be a click on something we should
  12391. // not interfere with, such as a scrollbar or widget.
  12392. function onMouseDown(e) {
  12393. var cm = this, display = cm.display;
  12394. if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
  12395. display.input.ensurePolled();
  12396. display.shift = e.shiftKey;
  12397. if (eventInWidget(display, e)) {
  12398. if (!webkit) {
  12399. // Briefly turn off draggability, to allow widgets to do
  12400. // normal dragging things.
  12401. display.scroller.draggable = false;
  12402. setTimeout(function () { return display.scroller.draggable = true; }, 100);
  12403. }
  12404. return
  12405. }
  12406. if (clickInGutter(cm, e)) { return }
  12407. var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single";
  12408. window.focus();
  12409. // #3261: make sure, that we're not starting a second selection
  12410. if (button == 1 && cm.state.selectingText)
  12411. { cm.state.selectingText(e); }
  12412. if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
  12413. if (button == 1) {
  12414. if (pos) { leftButtonDown(cm, pos, repeat, e); }
  12415. else if (e_target(e) == display.scroller) { e_preventDefault(e); }
  12416. } else if (button == 2) {
  12417. if (pos) { extendSelection(cm.doc, pos); }
  12418. setTimeout(function () { return display.input.focus(); }, 20);
  12419. } else if (button == 3) {
  12420. if (captureRightClick) { cm.display.input.onContextMenu(e); }
  12421. else { delayBlurEvent(cm); }
  12422. }
  12423. }
  12424. function handleMappedButton(cm, button, pos, repeat, event) {
  12425. var name = "Click";
  12426. if (repeat == "double") { name = "Double" + name; }
  12427. else if (repeat == "triple") { name = "Triple" + name; }
  12428. name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
  12429. return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
  12430. if (typeof bound == "string") { bound = commands[bound]; }
  12431. if (!bound) { return false }
  12432. var done = false;
  12433. try {
  12434. if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
  12435. done = bound(cm, pos) != Pass;
  12436. } finally {
  12437. cm.state.suppressEdits = false;
  12438. }
  12439. return done
  12440. })
  12441. }
  12442. function configureMouse(cm, repeat, event) {
  12443. var option = cm.getOption("configureMouse");
  12444. var value = option ? option(cm, repeat, event) : {};
  12445. if (value.unit == null) {
  12446. var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
  12447. value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
  12448. }
  12449. if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey; }
  12450. if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey; }
  12451. if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey); }
  12452. return value
  12453. }
  12454. function leftButtonDown(cm, pos, repeat, event) {
  12455. if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
  12456. else { cm.curOp.focus = activeElt(); }
  12457. var behavior = configureMouse(cm, repeat, event);
  12458. var sel = cm.doc.sel, contained;
  12459. if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
  12460. repeat == "single" && (contained = sel.contains(pos)) > -1 &&
  12461. (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
  12462. (cmp(contained.to(), pos) > 0 || pos.xRel < 0))
  12463. { leftButtonStartDrag(cm, event, pos, behavior); }
  12464. else
  12465. { leftButtonSelect(cm, event, pos, behavior); }
  12466. }
  12467. // Start a text drag. When it ends, see if any dragging actually
  12468. // happen, and treat as a click if it didn't.
  12469. function leftButtonStartDrag(cm, event, pos, behavior) {
  12470. var display = cm.display, moved = false;
  12471. var dragEnd = operation(cm, function (e) {
  12472. if (webkit) { display.scroller.draggable = false; }
  12473. cm.state.draggingText = false;
  12474. off(display.wrapper.ownerDocument, "mouseup", dragEnd);
  12475. off(display.wrapper.ownerDocument, "mousemove", mouseMove);
  12476. off(display.scroller, "dragstart", dragStart);
  12477. off(display.scroller, "drop", dragEnd);
  12478. if (!moved) {
  12479. e_preventDefault(e);
  12480. if (!behavior.addNew)
  12481. { extendSelection(cm.doc, pos, null, null, behavior.extend); }
  12482. // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
  12483. if (webkit || ie && ie_version == 9)
  12484. { setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus();}, 20); }
  12485. else
  12486. { display.input.focus(); }
  12487. }
  12488. });
  12489. var mouseMove = function(e2) {
  12490. moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
  12491. };
  12492. var dragStart = function () { return moved = true; };
  12493. // Let the drag handler handle this.
  12494. if (webkit) { display.scroller.draggable = true; }
  12495. cm.state.draggingText = dragEnd;
  12496. dragEnd.copy = !behavior.moveOnDrag;
  12497. // IE's approach to draggable
  12498. if (display.scroller.dragDrop) { display.scroller.dragDrop(); }
  12499. on(display.wrapper.ownerDocument, "mouseup", dragEnd);
  12500. on(display.wrapper.ownerDocument, "mousemove", mouseMove);
  12501. on(display.scroller, "dragstart", dragStart);
  12502. on(display.scroller, "drop", dragEnd);
  12503. delayBlurEvent(cm);
  12504. setTimeout(function () { return display.input.focus(); }, 20);
  12505. }
  12506. function rangeForUnit(cm, pos, unit) {
  12507. if (unit == "char") { return new Range(pos, pos) }
  12508. if (unit == "word") { return cm.findWordAt(pos) }
  12509. if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
  12510. var result = unit(cm, pos);
  12511. return new Range(result.from, result.to)
  12512. }
  12513. // Normal selection, as opposed to text dragging.
  12514. function leftButtonSelect(cm, event, start, behavior) {
  12515. var display = cm.display, doc = cm.doc;
  12516. e_preventDefault(event);
  12517. var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
  12518. if (behavior.addNew && !behavior.extend) {
  12519. ourIndex = doc.sel.contains(start);
  12520. if (ourIndex > -1)
  12521. { ourRange = ranges[ourIndex]; }
  12522. else
  12523. { ourRange = new Range(start, start); }
  12524. } else {
  12525. ourRange = doc.sel.primary();
  12526. ourIndex = doc.sel.primIndex;
  12527. }
  12528. if (behavior.unit == "rectangle") {
  12529. if (!behavior.addNew) { ourRange = new Range(start, start); }
  12530. start = posFromMouse(cm, event, true, true);
  12531. ourIndex = -1;
  12532. } else {
  12533. var range = rangeForUnit(cm, start, behavior.unit);
  12534. if (behavior.extend)
  12535. { ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend); }
  12536. else
  12537. { ourRange = range; }
  12538. }
  12539. if (!behavior.addNew) {
  12540. ourIndex = 0;
  12541. setSelection(doc, new Selection([ourRange], 0), sel_mouse);
  12542. startSel = doc.sel;
  12543. } else if (ourIndex == -1) {
  12544. ourIndex = ranges.length;
  12545. setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
  12546. {scroll: false, origin: "*mouse"});
  12547. } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
  12548. setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
  12549. {scroll: false, origin: "*mouse"});
  12550. startSel = doc.sel;
  12551. } else {
  12552. replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
  12553. }
  12554. var lastPos = start;
  12555. function extendTo(pos) {
  12556. if (cmp(lastPos, pos) == 0) { return }
  12557. lastPos = pos;
  12558. if (behavior.unit == "rectangle") {
  12559. var ranges = [], tabSize = cm.options.tabSize;
  12560. var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
  12561. var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
  12562. var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
  12563. for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
  12564. line <= end; line++) {
  12565. var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
  12566. if (left == right)
  12567. { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
  12568. else if (text.length > leftPos)
  12569. { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
  12570. }
  12571. if (!ranges.length) { ranges.push(new Range(start, start)); }
  12572. setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
  12573. {origin: "*mouse", scroll: false});
  12574. cm.scrollIntoView(pos);
  12575. } else {
  12576. var oldRange = ourRange;
  12577. var range = rangeForUnit(cm, pos, behavior.unit);
  12578. var anchor = oldRange.anchor, head;
  12579. if (cmp(range.anchor, anchor) > 0) {
  12580. head = range.head;
  12581. anchor = minPos(oldRange.from(), range.anchor);
  12582. } else {
  12583. head = range.anchor;
  12584. anchor = maxPos(oldRange.to(), range.head);
  12585. }
  12586. var ranges$1 = startSel.ranges.slice(0);
  12587. ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
  12588. setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
  12589. }
  12590. }
  12591. var editorSize = display.wrapper.getBoundingClientRect();
  12592. // Used to ensure timeout re-tries don't fire when another extend
  12593. // happened in the meantime (clearTimeout isn't reliable -- at
  12594. // least on Chrome, the timeouts still happen even when cleared,
  12595. // if the clear happens after their scheduled firing time).
  12596. var counter = 0;
  12597. function extend(e) {
  12598. var curCount = ++counter;
  12599. var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
  12600. if (!cur) { return }
  12601. if (cmp(cur, lastPos) != 0) {
  12602. cm.curOp.focus = activeElt();
  12603. extendTo(cur);
  12604. var visible = visibleLines(display, doc);
  12605. if (cur.line >= visible.to || cur.line < visible.from)
  12606. { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
  12607. } else {
  12608. var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
  12609. if (outside) { setTimeout(operation(cm, function () {
  12610. if (counter != curCount) { return }
  12611. display.scroller.scrollTop += outside;
  12612. extend(e);
  12613. }), 50); }
  12614. }
  12615. }
  12616. function done(e) {
  12617. cm.state.selectingText = false;
  12618. counter = Infinity;
  12619. // If e is null or undefined we interpret this as someone trying
  12620. // to explicitly cancel the selection rather than the user
  12621. // letting go of the mouse button.
  12622. if (e) {
  12623. e_preventDefault(e);
  12624. display.input.focus();
  12625. }
  12626. off(display.wrapper.ownerDocument, "mousemove", move);
  12627. off(display.wrapper.ownerDocument, "mouseup", up);
  12628. doc.history.lastSelOrigin = null;
  12629. }
  12630. var move = operation(cm, function (e) {
  12631. if (e.buttons === 0 || !e_button(e)) { done(e); }
  12632. else { extend(e); }
  12633. });
  12634. var up = operation(cm, done);
  12635. cm.state.selectingText = up;
  12636. on(display.wrapper.ownerDocument, "mousemove", move);
  12637. on(display.wrapper.ownerDocument, "mouseup", up);
  12638. }
  12639. // Used when mouse-selecting to adjust the anchor to the proper side
  12640. // of a bidi jump depending on the visual position of the head.
  12641. function bidiSimplify(cm, range) {
  12642. var anchor = range.anchor;
  12643. var head = range.head;
  12644. var anchorLine = getLine(cm.doc, anchor.line);
  12645. if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range }
  12646. var order = getOrder(anchorLine);
  12647. if (!order) { return range }
  12648. var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
  12649. if (part.from != anchor.ch && part.to != anchor.ch) { return range }
  12650. var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1);
  12651. if (boundary == 0 || boundary == order.length) { return range }
  12652. // Compute the relative visual position of the head compared to the
  12653. // anchor (<0 is to the left, >0 to the right)
  12654. var leftSide;
  12655. if (head.line != anchor.line) {
  12656. leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
  12657. } else {
  12658. var headIndex = getBidiPartAt(order, head.ch, head.sticky);
  12659. var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
  12660. if (headIndex == boundary - 1 || headIndex == boundary)
  12661. { leftSide = dir < 0; }
  12662. else
  12663. { leftSide = dir > 0; }
  12664. }
  12665. var usePart = order[boundary + (leftSide ? -1 : 0)];
  12666. var from = leftSide == (usePart.level == 1);
  12667. var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
  12668. return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
  12669. }
  12670. // Determines whether an event happened in the gutter, and fires the
  12671. // handlers for the corresponding event.
  12672. function gutterEvent(cm, e, type, prevent) {
  12673. var mX, mY;
  12674. if (e.touches) {
  12675. mX = e.touches[0].clientX;
  12676. mY = e.touches[0].clientY;
  12677. } else {
  12678. try { mX = e.clientX; mY = e.clientY; }
  12679. catch(e) { return false }
  12680. }
  12681. if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
  12682. if (prevent) { e_preventDefault(e); }
  12683. var display = cm.display;
  12684. var lineBox = display.lineDiv.getBoundingClientRect();
  12685. if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
  12686. mY -= lineBox.top - display.viewOffset;
  12687. for (var i = 0; i < cm.display.gutterSpecs.length; ++i) {
  12688. var g = display.gutters.childNodes[i];
  12689. if (g && g.getBoundingClientRect().right >= mX) {
  12690. var line = lineAtHeight(cm.doc, mY);
  12691. var gutter = cm.display.gutterSpecs[i];
  12692. signal(cm, type, cm, line, gutter.className, e);
  12693. return e_defaultPrevented(e)
  12694. }
  12695. }
  12696. }
  12697. function clickInGutter(cm, e) {
  12698. return gutterEvent(cm, e, "gutterClick", true)
  12699. }
  12700. // CONTEXT MENU HANDLING
  12701. // To make the context menu work, we need to briefly unhide the
  12702. // textarea (making it as unobtrusive as possible) to let the
  12703. // right-click take effect on it.
  12704. function onContextMenu(cm, e) {
  12705. if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
  12706. if (signalDOMEvent(cm, e, "contextmenu")) { return }
  12707. if (!captureRightClick) { cm.display.input.onContextMenu(e); }
  12708. }
  12709. function contextMenuInGutter(cm, e) {
  12710. if (!hasHandler(cm, "gutterContextMenu")) { return false }
  12711. return gutterEvent(cm, e, "gutterContextMenu", false)
  12712. }
  12713. function themeChanged(cm) {
  12714. cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
  12715. cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
  12716. clearCaches(cm);
  12717. }
  12718. var Init = {toString: function(){return "CodeMirror.Init"}};
  12719. var defaults = {};
  12720. var optionHandlers = {};
  12721. function defineOptions(CodeMirror) {
  12722. var optionHandlers = CodeMirror.optionHandlers;
  12723. function option(name, deflt, handle, notOnInit) {
  12724. CodeMirror.defaults[name] = deflt;
  12725. if (handle) { optionHandlers[name] =
  12726. notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
  12727. }
  12728. CodeMirror.defineOption = option;
  12729. // Passed to option handlers when there is no old value.
  12730. CodeMirror.Init = Init;
  12731. // These two are, on init, called from the constructor because they
  12732. // have to be initialized before the editor can start at all.
  12733. option("value", "", function (cm, val) { return cm.setValue(val); }, true);
  12734. option("mode", null, function (cm, val) {
  12735. cm.doc.modeOption = val;
  12736. loadMode(cm);
  12737. }, true);
  12738. option("indentUnit", 2, loadMode, true);
  12739. option("indentWithTabs", false);
  12740. option("smartIndent", true);
  12741. option("tabSize", 4, function (cm) {
  12742. resetModeState(cm);
  12743. clearCaches(cm);
  12744. regChange(cm);
  12745. }, true);
  12746. option("lineSeparator", null, function (cm, val) {
  12747. cm.doc.lineSep = val;
  12748. if (!val) { return }
  12749. var newBreaks = [], lineNo = cm.doc.first;
  12750. cm.doc.iter(function (line) {
  12751. for (var pos = 0;;) {
  12752. var found = line.text.indexOf(val, pos);
  12753. if (found == -1) { break }
  12754. pos = found + val.length;
  12755. newBreaks.push(Pos(lineNo, found));
  12756. }
  12757. lineNo++;
  12758. });
  12759. for (var i = newBreaks.length - 1; i >= 0; i--)
  12760. { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
  12761. });
  12762. option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, function (cm, val, old) {
  12763. cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
  12764. if (old != Init) { cm.refresh(); }
  12765. });
  12766. option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
  12767. option("electricChars", true);
  12768. option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
  12769. throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
  12770. }, true);
  12771. option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
  12772. option("autocorrect", false, function (cm, val) { return cm.getInputField().autocorrect = val; }, true);
  12773. option("autocapitalize", false, function (cm, val) { return cm.getInputField().autocapitalize = val; }, true);
  12774. option("rtlMoveVisually", !windows);
  12775. option("wholeLineUpdateBefore", true);
  12776. option("theme", "default", function (cm) {
  12777. themeChanged(cm);
  12778. updateGutters(cm);
  12779. }, true);
  12780. option("keyMap", "default", function (cm, val, old) {
  12781. var next = getKeyMap(val);
  12782. var prev = old != Init && getKeyMap(old);
  12783. if (prev && prev.detach) { prev.detach(cm, next); }
  12784. if (next.attach) { next.attach(cm, prev || null); }
  12785. });
  12786. option("extraKeys", null);
  12787. option("configureMouse", null);
  12788. option("lineWrapping", false, wrappingChanged, true);
  12789. option("gutters", [], function (cm, val) {
  12790. cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers);
  12791. updateGutters(cm);
  12792. }, true);
  12793. option("fixedGutter", true, function (cm, val) {
  12794. cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
  12795. cm.refresh();
  12796. }, true);
  12797. option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true);
  12798. option("scrollbarStyle", "native", function (cm) {
  12799. initScrollbars(cm);
  12800. updateScrollbars(cm);
  12801. cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
  12802. cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
  12803. }, true);
  12804. option("lineNumbers", false, function (cm, val) {
  12805. cm.display.gutterSpecs = getGutters(cm.options.gutters, val);
  12806. updateGutters(cm);
  12807. }, true);
  12808. option("firstLineNumber", 1, updateGutters, true);
  12809. option("lineNumberFormatter", function (integer) { return integer; }, updateGutters, true);
  12810. option("showCursorWhenSelecting", false, updateSelection, true);
  12811. option("resetSelectionOnContextMenu", true);
  12812. option("lineWiseCopyCut", true);
  12813. option("pasteLinesPerSelection", true);
  12814. option("selectionsMayTouch", false);
  12815. option("readOnly", false, function (cm, val) {
  12816. if (val == "nocursor") {
  12817. onBlur(cm);
  12818. cm.display.input.blur();
  12819. }
  12820. cm.display.input.readOnlyChanged(val);
  12821. });
  12822. option("screenReaderLabel", null, function (cm, val) {
  12823. val = (val === '') ? null : val;
  12824. cm.display.input.screenReaderLabelChanged(val);
  12825. });
  12826. option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true);
  12827. option("dragDrop", true, dragDropChanged);
  12828. option("allowDropFileTypes", null);
  12829. option("cursorBlinkRate", 530);
  12830. option("cursorScrollMargin", 0);
  12831. option("cursorHeight", 1, updateSelection, true);
  12832. option("singleCursorHeightPerLine", true, updateSelection, true);
  12833. option("workTime", 100);
  12834. option("workDelay", 100);
  12835. option("flattenSpans", true, resetModeState, true);
  12836. option("addModeClass", false, resetModeState, true);
  12837. option("pollInterval", 100);
  12838. option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; });
  12839. option("historyEventDelay", 1250);
  12840. option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true);
  12841. option("maxHighlightLength", 10000, resetModeState, true);
  12842. option("moveInputWithCursor", true, function (cm, val) {
  12843. if (!val) { cm.display.input.resetPosition(); }
  12844. });
  12845. option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; });
  12846. option("autofocus", null);
  12847. option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true);
  12848. option("phrases", null);
  12849. }
  12850. function dragDropChanged(cm, value, old) {
  12851. var wasOn = old && old != Init;
  12852. if (!value != !wasOn) {
  12853. var funcs = cm.display.dragFunctions;
  12854. var toggle = value ? on : off;
  12855. toggle(cm.display.scroller, "dragstart", funcs.start);
  12856. toggle(cm.display.scroller, "dragenter", funcs.enter);
  12857. toggle(cm.display.scroller, "dragover", funcs.over);
  12858. toggle(cm.display.scroller, "dragleave", funcs.leave);
  12859. toggle(cm.display.scroller, "drop", funcs.drop);
  12860. }
  12861. }
  12862. function wrappingChanged(cm) {
  12863. if (cm.options.lineWrapping) {
  12864. addClass(cm.display.wrapper, "CodeMirror-wrap");
  12865. cm.display.sizer.style.minWidth = "";
  12866. cm.display.sizerWidth = null;
  12867. } else {
  12868. rmClass(cm.display.wrapper, "CodeMirror-wrap");
  12869. findMaxLine(cm);
  12870. }
  12871. estimateLineHeights(cm);
  12872. regChange(cm);
  12873. clearCaches(cm);
  12874. setTimeout(function () { return updateScrollbars(cm); }, 100);
  12875. }
  12876. // A CodeMirror instance represents an editor. This is the object
  12877. // that user code is usually dealing with.
  12878. function CodeMirror(place, options) {
  12879. var this$1 = this;
  12880. if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
  12881. this.options = options = options ? copyObj(options) : {};
  12882. // Determine effective options based on given values and defaults.
  12883. copyObj(defaults, options, false);
  12884. var doc = options.value;
  12885. if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); }
  12886. else if (options.mode) { doc.modeOption = options.mode; }
  12887. this.doc = doc;
  12888. var input = new CodeMirror.inputStyles[options.inputStyle](this);
  12889. var display = this.display = new Display(place, doc, input, options);
  12890. display.wrapper.CodeMirror = this;
  12891. themeChanged(this);
  12892. if (options.lineWrapping)
  12893. { this.display.wrapper.className += " CodeMirror-wrap"; }
  12894. initScrollbars(this);
  12895. this.state = {
  12896. keyMaps: [], // stores maps added by addKeyMap
  12897. overlays: [], // highlighting overlays, as added by addOverlay
  12898. modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
  12899. overwrite: false,
  12900. delayingBlurEvent: false,
  12901. focused: false,
  12902. suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
  12903. pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll
  12904. selectingText: false,
  12905. draggingText: false,
  12906. highlight: new Delayed(), // stores highlight worker timeout
  12907. keySeq: null, // Unfinished key sequence
  12908. specialChars: null
  12909. };
  12910. if (options.autofocus && !mobile) { display.input.focus(); }
  12911. // Override magic textarea content restore that IE sometimes does
  12912. // on our hidden textarea on reload
  12913. if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); }
  12914. registerEventHandlers(this);
  12915. ensureGlobalHandlers();
  12916. startOperation(this);
  12917. this.curOp.forceUpdate = true;
  12918. attachDoc(this, doc);
  12919. if ((options.autofocus && !mobile) || this.hasFocus())
  12920. { setTimeout(bind(onFocus, this), 20); }
  12921. else
  12922. { onBlur(this); }
  12923. for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
  12924. { optionHandlers[opt](this, options[opt], Init); } }
  12925. maybeUpdateLineNumberWidth(this);
  12926. if (options.finishInit) { options.finishInit(this); }
  12927. for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this); }
  12928. endOperation(this);
  12929. // Suppress optimizelegibility in Webkit, since it breaks text
  12930. // measuring on line wrapping boundaries.
  12931. if (webkit && options.lineWrapping &&
  12932. getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
  12933. { display.lineDiv.style.textRendering = "auto"; }
  12934. }
  12935. // The default configuration options.
  12936. CodeMirror.defaults = defaults;
  12937. // Functions to run when options are changed.
  12938. CodeMirror.optionHandlers = optionHandlers;
  12939. // Attach the necessary event handlers when initializing the editor
  12940. function registerEventHandlers(cm) {
  12941. var d = cm.display;
  12942. on(d.scroller, "mousedown", operation(cm, onMouseDown));
  12943. // Older IE's will not fire a second mousedown for a double click
  12944. if (ie && ie_version < 11)
  12945. { on(d.scroller, "dblclick", operation(cm, function (e) {
  12946. if (signalDOMEvent(cm, e)) { return }
  12947. var pos = posFromMouse(cm, e);
  12948. if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
  12949. e_preventDefault(e);
  12950. var word = cm.findWordAt(pos);
  12951. extendSelection(cm.doc, word.anchor, word.head);
  12952. })); }
  12953. else
  12954. { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
  12955. // Some browsers fire contextmenu *after* opening the menu, at
  12956. // which point we can't mess with it anymore. Context menu is
  12957. // handled in onMouseDown for these browsers.
  12958. on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); });
  12959. on(d.input.getField(), "contextmenu", function (e) {
  12960. if (!d.scroller.contains(e.target)) { onContextMenu(cm, e); }
  12961. });
  12962. // Used to suppress mouse event handling when a touch happens
  12963. var touchFinished, prevTouch = {end: 0};
  12964. function finishTouch() {
  12965. if (d.activeTouch) {
  12966. touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
  12967. prevTouch = d.activeTouch;
  12968. prevTouch.end = +new Date;
  12969. }
  12970. }
  12971. function isMouseLikeTouchEvent(e) {
  12972. if (e.touches.length != 1) { return false }
  12973. var touch = e.touches[0];
  12974. return touch.radiusX <= 1 && touch.radiusY <= 1
  12975. }
  12976. function farAway(touch, other) {
  12977. if (other.left == null) { return true }
  12978. var dx = other.left - touch.left, dy = other.top - touch.top;
  12979. return dx * dx + dy * dy > 20 * 20
  12980. }
  12981. on(d.scroller, "touchstart", function (e) {
  12982. if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
  12983. d.input.ensurePolled();
  12984. clearTimeout(touchFinished);
  12985. var now = +new Date;
  12986. d.activeTouch = {start: now, moved: false,
  12987. prev: now - prevTouch.end <= 300 ? prevTouch : null};
  12988. if (e.touches.length == 1) {
  12989. d.activeTouch.left = e.touches[0].pageX;
  12990. d.activeTouch.top = e.touches[0].pageY;
  12991. }
  12992. }
  12993. });
  12994. on(d.scroller, "touchmove", function () {
  12995. if (d.activeTouch) { d.activeTouch.moved = true; }
  12996. });
  12997. on(d.scroller, "touchend", function (e) {
  12998. var touch = d.activeTouch;
  12999. if (touch && !eventInWidget(d, e) && touch.left != null &&
  13000. !touch.moved && new Date - touch.start < 300) {
  13001. var pos = cm.coordsChar(d.activeTouch, "page"), range;
  13002. if (!touch.prev || farAway(touch, touch.prev)) // Single tap
  13003. { range = new Range(pos, pos); }
  13004. else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
  13005. { range = cm.findWordAt(pos); }
  13006. else // Triple tap
  13007. { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); }
  13008. cm.setSelection(range.anchor, range.head);
  13009. cm.focus();
  13010. e_preventDefault(e);
  13011. }
  13012. finishTouch();
  13013. });
  13014. on(d.scroller, "touchcancel", finishTouch);
  13015. // Sync scrolling between fake scrollbars and real scrollable
  13016. // area, ensure viewport is updated when scrolling.
  13017. on(d.scroller, "scroll", function () {
  13018. if (d.scroller.clientHeight) {
  13019. updateScrollTop(cm, d.scroller.scrollTop);
  13020. setScrollLeft(cm, d.scroller.scrollLeft, true);
  13021. signal(cm, "scroll", cm);
  13022. }
  13023. });
  13024. // Listen to wheel events in order to try and update the viewport on time.
  13025. on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); });
  13026. on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); });
  13027. // Prevent wrapper from ever scrolling
  13028. on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
  13029. d.dragFunctions = {
  13030. enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }},
  13031. over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
  13032. start: function (e) { return onDragStart(cm, e); },
  13033. drop: operation(cm, onDrop),
  13034. leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
  13035. };
  13036. var inp = d.input.getField();
  13037. on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); });
  13038. on(inp, "keydown", operation(cm, onKeyDown));
  13039. on(inp, "keypress", operation(cm, onKeyPress));
  13040. on(inp, "focus", function (e) { return onFocus(cm, e); });
  13041. on(inp, "blur", function (e) { return onBlur(cm, e); });
  13042. }
  13043. var initHooks = [];
  13044. CodeMirror.defineInitHook = function (f) { return initHooks.push(f); };
  13045. // Indent the given line. The how parameter can be "smart",
  13046. // "add"/null, "subtract", or "prev". When aggressive is false
  13047. // (typically set to true for forced single-line indents), empty
  13048. // lines are not indented, and places where the mode returns Pass
  13049. // are left alone.
  13050. function indentLine(cm, n, how, aggressive) {
  13051. var doc = cm.doc, state;
  13052. if (how == null) { how = "add"; }
  13053. if (how == "smart") {
  13054. // Fall back to "prev" when the mode doesn't have an indentation
  13055. // method.
  13056. if (!doc.mode.indent) { how = "prev"; }
  13057. else { state = getContextBefore(cm, n).state; }
  13058. }
  13059. var tabSize = cm.options.tabSize;
  13060. var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
  13061. if (line.stateAfter) { line.stateAfter = null; }
  13062. var curSpaceString = line.text.match(/^\s*/)[0], indentation;
  13063. if (!aggressive && !/\S/.test(line.text)) {
  13064. indentation = 0;
  13065. how = "not";
  13066. } else if (how == "smart") {
  13067. indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
  13068. if (indentation == Pass || indentation > 150) {
  13069. if (!aggressive) { return }
  13070. how = "prev";
  13071. }
  13072. }
  13073. if (how == "prev") {
  13074. if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); }
  13075. else { indentation = 0; }
  13076. } else if (how == "add") {
  13077. indentation = curSpace + cm.options.indentUnit;
  13078. } else if (how == "subtract") {
  13079. indentation = curSpace - cm.options.indentUnit;
  13080. } else if (typeof how == "number") {
  13081. indentation = curSpace + how;
  13082. }
  13083. indentation = Math.max(0, indentation);
  13084. var indentString = "", pos = 0;
  13085. if (cm.options.indentWithTabs)
  13086. { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} }
  13087. if (pos < indentation) { indentString += spaceStr(indentation - pos); }
  13088. if (indentString != curSpaceString) {
  13089. replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
  13090. line.stateAfter = null;
  13091. return true
  13092. } else {
  13093. // Ensure that, if the cursor was in the whitespace at the start
  13094. // of the line, it is moved to the end of that space.
  13095. for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
  13096. var range = doc.sel.ranges[i$1];
  13097. if (range.head.line == n && range.head.ch < curSpaceString.length) {
  13098. var pos$1 = Pos(n, curSpaceString.length);
  13099. replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
  13100. break
  13101. }
  13102. }
  13103. }
  13104. }
  13105. // This will be set to a {lineWise: bool, text: [string]} object, so
  13106. // that, when pasting, we know what kind of selections the copied
  13107. // text was made out of.
  13108. var lastCopied = null;
  13109. function setLastCopied(newLastCopied) {
  13110. lastCopied = newLastCopied;
  13111. }
  13112. function applyTextInput(cm, inserted, deleted, sel, origin) {
  13113. var doc = cm.doc;
  13114. cm.display.shift = false;
  13115. if (!sel) { sel = doc.sel; }
  13116. var recent = +new Date - 200;
  13117. var paste = origin == "paste" || cm.state.pasteIncoming > recent;
  13118. var textLines = splitLinesAuto(inserted), multiPaste = null;
  13119. // When pasting N lines into N selections, insert one line per selection
  13120. if (paste && sel.ranges.length > 1) {
  13121. if (lastCopied && lastCopied.text.join("\n") == inserted) {
  13122. if (sel.ranges.length % lastCopied.text.length == 0) {
  13123. multiPaste = [];
  13124. for (var i = 0; i < lastCopied.text.length; i++)
  13125. { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
  13126. }
  13127. } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
  13128. multiPaste = map(textLines, function (l) { return [l]; });
  13129. }
  13130. }
  13131. var updateInput = cm.curOp.updateInput;
  13132. // Normal behavior is to insert the new text into every selection
  13133. for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
  13134. var range = sel.ranges[i$1];
  13135. var from = range.from(), to = range.to();
  13136. if (range.empty()) {
  13137. if (deleted && deleted > 0) // Handle deletion
  13138. { from = Pos(from.line, from.ch - deleted); }
  13139. else if (cm.state.overwrite && !paste) // Handle overwrite
  13140. { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
  13141. else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
  13142. { from = to = Pos(from.line, 0); }
  13143. }
  13144. var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
  13145. origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")};
  13146. makeChange(cm.doc, changeEvent);
  13147. signalLater(cm, "inputRead", cm, changeEvent);
  13148. }
  13149. if (inserted && !paste)
  13150. { triggerElectric(cm, inserted); }
  13151. ensureCursorVisible(cm);
  13152. if (cm.curOp.updateInput < 2) { cm.curOp.updateInput = updateInput; }
  13153. cm.curOp.typing = true;
  13154. cm.state.pasteIncoming = cm.state.cutIncoming = -1;
  13155. }
  13156. function handlePaste(e, cm) {
  13157. var pasted = e.clipboardData && e.clipboardData.getData("Text");
  13158. if (pasted) {
  13159. e.preventDefault();
  13160. if (!cm.isReadOnly() && !cm.options.disableInput)
  13161. { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); }
  13162. return true
  13163. }
  13164. }
  13165. function triggerElectric(cm, inserted) {
  13166. // When an 'electric' character is inserted, immediately trigger a reindent
  13167. if (!cm.options.electricChars || !cm.options.smartIndent) { return }
  13168. var sel = cm.doc.sel;
  13169. for (var i = sel.ranges.length - 1; i >= 0; i--) {
  13170. var range = sel.ranges[i];
  13171. if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue }
  13172. var mode = cm.getModeAt(range.head);
  13173. var indented = false;
  13174. if (mode.electricChars) {
  13175. for (var j = 0; j < mode.electricChars.length; j++)
  13176. { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
  13177. indented = indentLine(cm, range.head.line, "smart");
  13178. break
  13179. } }
  13180. } else if (mode.electricInput) {
  13181. if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
  13182. { indented = indentLine(cm, range.head.line, "smart"); }
  13183. }
  13184. if (indented) { signalLater(cm, "electricInput", cm, range.head.line); }
  13185. }
  13186. }
  13187. function copyableRanges(cm) {
  13188. var text = [], ranges = [];
  13189. for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
  13190. var line = cm.doc.sel.ranges[i].head.line;
  13191. var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
  13192. ranges.push(lineRange);
  13193. text.push(cm.getRange(lineRange.anchor, lineRange.head));
  13194. }
  13195. return {text: text, ranges: ranges}
  13196. }
  13197. function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
  13198. field.setAttribute("autocorrect", autocorrect ? "" : "off");
  13199. field.setAttribute("autocapitalize", autocapitalize ? "" : "off");
  13200. field.setAttribute("spellcheck", !!spellcheck);
  13201. }
  13202. function hiddenTextarea() {
  13203. var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
  13204. var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
  13205. // The textarea is kept positioned near the cursor to prevent the
  13206. // fact that it'll be scrolled into view on input from scrolling
  13207. // our fake cursor out of view. On webkit, when wrap=off, paste is
  13208. // very slow. So make the area wide instead.
  13209. if (webkit) { te.style.width = "1000px"; }
  13210. else { te.setAttribute("wrap", "off"); }
  13211. // If border: 0; -- iOS fails to open keyboard (issue #1287)
  13212. if (ios) { te.style.border = "1px solid black"; }
  13213. disableBrowserMagic(te);
  13214. return div
  13215. }
  13216. // The publicly visible API. Note that methodOp(f) means
  13217. // 'wrap f in an operation, performed on its `this` parameter'.
  13218. // This is not the complete set of editor methods. Most of the
  13219. // methods defined on the Doc type are also injected into
  13220. // CodeMirror.prototype, for backwards compatibility and
  13221. // convenience.
  13222. function addEditorMethods(CodeMirror) {
  13223. var optionHandlers = CodeMirror.optionHandlers;
  13224. var helpers = CodeMirror.helpers = {};
  13225. CodeMirror.prototype = {
  13226. constructor: CodeMirror,
  13227. focus: function(){window.focus(); this.display.input.focus();},
  13228. setOption: function(option, value) {
  13229. var options = this.options, old = options[option];
  13230. if (options[option] == value && option != "mode") { return }
  13231. options[option] = value;
  13232. if (optionHandlers.hasOwnProperty(option))
  13233. { operation(this, optionHandlers[option])(this, value, old); }
  13234. signal(this, "optionChange", this, option);
  13235. },
  13236. getOption: function(option) {return this.options[option]},
  13237. getDoc: function() {return this.doc},
  13238. addKeyMap: function(map, bottom) {
  13239. this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
  13240. },
  13241. removeKeyMap: function(map) {
  13242. var maps = this.state.keyMaps;
  13243. for (var i = 0; i < maps.length; ++i)
  13244. { if (maps[i] == map || maps[i].name == map) {
  13245. maps.splice(i, 1);
  13246. return true
  13247. } }
  13248. },
  13249. addOverlay: methodOp(function(spec, options) {
  13250. var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
  13251. if (mode.startState) { throw new Error("Overlays may not be stateful.") }
  13252. insertSorted(this.state.overlays,
  13253. {mode: mode, modeSpec: spec, opaque: options && options.opaque,
  13254. priority: (options && options.priority) || 0},
  13255. function (overlay) { return overlay.priority; });
  13256. this.state.modeGen++;
  13257. regChange(this);
  13258. }),
  13259. removeOverlay: methodOp(function(spec) {
  13260. var overlays = this.state.overlays;
  13261. for (var i = 0; i < overlays.length; ++i) {
  13262. var cur = overlays[i].modeSpec;
  13263. if (cur == spec || typeof spec == "string" && cur.name == spec) {
  13264. overlays.splice(i, 1);
  13265. this.state.modeGen++;
  13266. regChange(this);
  13267. return
  13268. }
  13269. }
  13270. }),
  13271. indentLine: methodOp(function(n, dir, aggressive) {
  13272. if (typeof dir != "string" && typeof dir != "number") {
  13273. if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; }
  13274. else { dir = dir ? "add" : "subtract"; }
  13275. }
  13276. if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); }
  13277. }),
  13278. indentSelection: methodOp(function(how) {
  13279. var ranges = this.doc.sel.ranges, end = -1;
  13280. for (var i = 0; i < ranges.length; i++) {
  13281. var range = ranges[i];
  13282. if (!range.empty()) {
  13283. var from = range.from(), to = range.to();
  13284. var start = Math.max(end, from.line);
  13285. end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
  13286. for (var j = start; j < end; ++j)
  13287. { indentLine(this, j, how); }
  13288. var newRanges = this.doc.sel.ranges;
  13289. if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
  13290. { replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); }
  13291. } else if (range.head.line > end) {
  13292. indentLine(this, range.head.line, how, true);
  13293. end = range.head.line;
  13294. if (i == this.doc.sel.primIndex) { ensureCursorVisible(this); }
  13295. }
  13296. }
  13297. }),
  13298. // Fetch the parser token for a given character. Useful for hacks
  13299. // that want to inspect the mode state (say, for completion).
  13300. getTokenAt: function(pos, precise) {
  13301. return takeToken(this, pos, precise)
  13302. },
  13303. getLineTokens: function(line, precise) {
  13304. return takeToken(this, Pos(line), precise, true)
  13305. },
  13306. getTokenTypeAt: function(pos) {
  13307. pos = clipPos(this.doc, pos);
  13308. var styles = getLineStyles(this, getLine(this.doc, pos.line));
  13309. var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
  13310. var type;
  13311. if (ch == 0) { type = styles[2]; }
  13312. else { for (;;) {
  13313. var mid = (before + after) >> 1;
  13314. if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; }
  13315. else if (styles[mid * 2 + 1] < ch) { before = mid + 1; }
  13316. else { type = styles[mid * 2 + 2]; break }
  13317. } }
  13318. var cut = type ? type.indexOf("overlay ") : -1;
  13319. return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
  13320. },
  13321. getModeAt: function(pos) {
  13322. var mode = this.doc.mode;
  13323. if (!mode.innerMode) { return mode }
  13324. return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
  13325. },
  13326. getHelper: function(pos, type) {
  13327. return this.getHelpers(pos, type)[0]
  13328. },
  13329. getHelpers: function(pos, type) {
  13330. var found = [];
  13331. if (!helpers.hasOwnProperty(type)) { return found }
  13332. var help = helpers[type], mode = this.getModeAt(pos);
  13333. if (typeof mode[type] == "string") {
  13334. if (help[mode[type]]) { found.push(help[mode[type]]); }
  13335. } else if (mode[type]) {
  13336. for (var i = 0; i < mode[type].length; i++) {
  13337. var val = help[mode[type][i]];
  13338. if (val) { found.push(val); }
  13339. }
  13340. } else if (mode.helperType && help[mode.helperType]) {
  13341. found.push(help[mode.helperType]);
  13342. } else if (help[mode.name]) {
  13343. found.push(help[mode.name]);
  13344. }
  13345. for (var i$1 = 0; i$1 < help._global.length; i$1++) {
  13346. var cur = help._global[i$1];
  13347. if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
  13348. { found.push(cur.val); }
  13349. }
  13350. return found
  13351. },
  13352. getStateAfter: function(line, precise) {
  13353. var doc = this.doc;
  13354. line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
  13355. return getContextBefore(this, line + 1, precise).state
  13356. },
  13357. cursorCoords: function(start, mode) {
  13358. var pos, range = this.doc.sel.primary();
  13359. if (start == null) { pos = range.head; }
  13360. else if (typeof start == "object") { pos = clipPos(this.doc, start); }
  13361. else { pos = start ? range.from() : range.to(); }
  13362. return cursorCoords(this, pos, mode || "page")
  13363. },
  13364. charCoords: function(pos, mode) {
  13365. return charCoords(this, clipPos(this.doc, pos), mode || "page")
  13366. },
  13367. coordsChar: function(coords, mode) {
  13368. coords = fromCoordSystem(this, coords, mode || "page");
  13369. return coordsChar(this, coords.left, coords.top)
  13370. },
  13371. lineAtHeight: function(height, mode) {
  13372. height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
  13373. return lineAtHeight(this.doc, height + this.display.viewOffset)
  13374. },
  13375. heightAtLine: function(line, mode, includeWidgets) {
  13376. var end = false, lineObj;
  13377. if (typeof line == "number") {
  13378. var last = this.doc.first + this.doc.size - 1;
  13379. if (line < this.doc.first) { line = this.doc.first; }
  13380. else if (line > last) { line = last; end = true; }
  13381. lineObj = getLine(this.doc, line);
  13382. } else {
  13383. lineObj = line;
  13384. }
  13385. return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
  13386. (end ? this.doc.height - heightAtLine(lineObj) : 0)
  13387. },
  13388. defaultTextHeight: function() { return textHeight(this.display) },
  13389. defaultCharWidth: function() { return charWidth(this.display) },
  13390. getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
  13391. addWidget: function(pos, node, scroll, vert, horiz) {
  13392. var display = this.display;
  13393. pos = cursorCoords(this, clipPos(this.doc, pos));
  13394. var top = pos.bottom, left = pos.left;
  13395. node.style.position = "absolute";
  13396. node.setAttribute("cm-ignore-events", "true");
  13397. this.display.input.setUneditable(node);
  13398. display.sizer.appendChild(node);
  13399. if (vert == "over") {
  13400. top = pos.top;
  13401. } else if (vert == "above" || vert == "near") {
  13402. var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
  13403. hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
  13404. // Default to positioning above (if specified and possible); otherwise default to positioning below
  13405. if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
  13406. { top = pos.top - node.offsetHeight; }
  13407. else if (pos.bottom + node.offsetHeight <= vspace)
  13408. { top = pos.bottom; }
  13409. if (left + node.offsetWidth > hspace)
  13410. { left = hspace - node.offsetWidth; }
  13411. }
  13412. node.style.top = top + "px";
  13413. node.style.left = node.style.right = "";
  13414. if (horiz == "right") {
  13415. left = display.sizer.clientWidth - node.offsetWidth;
  13416. node.style.right = "0px";
  13417. } else {
  13418. if (horiz == "left") { left = 0; }
  13419. else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; }
  13420. node.style.left = left + "px";
  13421. }
  13422. if (scroll)
  13423. { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); }
  13424. },
  13425. triggerOnKeyDown: methodOp(onKeyDown),
  13426. triggerOnKeyPress: methodOp(onKeyPress),
  13427. triggerOnKeyUp: onKeyUp,
  13428. triggerOnMouseDown: methodOp(onMouseDown),
  13429. execCommand: function(cmd) {
  13430. if (commands.hasOwnProperty(cmd))
  13431. { return commands[cmd].call(null, this) }
  13432. },
  13433. triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
  13434. findPosH: function(from, amount, unit, visually) {
  13435. var dir = 1;
  13436. if (amount < 0) { dir = -1; amount = -amount; }
  13437. var cur = clipPos(this.doc, from);
  13438. for (var i = 0; i < amount; ++i) {
  13439. cur = findPosH(this.doc, cur, dir, unit, visually);
  13440. if (cur.hitSide) { break }
  13441. }
  13442. return cur
  13443. },
  13444. moveH: methodOp(function(dir, unit) {
  13445. var this$1 = this;
  13446. this.extendSelectionsBy(function (range) {
  13447. if (this$1.display.shift || this$1.doc.extend || range.empty())
  13448. { return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) }
  13449. else
  13450. { return dir < 0 ? range.from() : range.to() }
  13451. }, sel_move);
  13452. }),
  13453. deleteH: methodOp(function(dir, unit) {
  13454. var sel = this.doc.sel, doc = this.doc;
  13455. if (sel.somethingSelected())
  13456. { doc.replaceSelection("", null, "+delete"); }
  13457. else
  13458. { deleteNearSelection(this, function (range) {
  13459. var other = findPosH(doc, range.head, dir, unit, false);
  13460. return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
  13461. }); }
  13462. }),
  13463. findPosV: function(from, amount, unit, goalColumn) {
  13464. var dir = 1, x = goalColumn;
  13465. if (amount < 0) { dir = -1; amount = -amount; }
  13466. var cur = clipPos(this.doc, from);
  13467. for (var i = 0; i < amount; ++i) {
  13468. var coords = cursorCoords(this, cur, "div");
  13469. if (x == null) { x = coords.left; }
  13470. else { coords.left = x; }
  13471. cur = findPosV(this, coords, dir, unit);
  13472. if (cur.hitSide) { break }
  13473. }
  13474. return cur
  13475. },
  13476. moveV: methodOp(function(dir, unit) {
  13477. var this$1 = this;
  13478. var doc = this.doc, goals = [];
  13479. var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
  13480. doc.extendSelectionsBy(function (range) {
  13481. if (collapse)
  13482. { return dir < 0 ? range.from() : range.to() }
  13483. var headPos = cursorCoords(this$1, range.head, "div");
  13484. if (range.goalColumn != null) { headPos.left = range.goalColumn; }
  13485. goals.push(headPos.left);
  13486. var pos = findPosV(this$1, headPos, dir, unit);
  13487. if (unit == "page" && range == doc.sel.primary())
  13488. { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); }
  13489. return pos
  13490. }, sel_move);
  13491. if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
  13492. { doc.sel.ranges[i].goalColumn = goals[i]; } }
  13493. }),
  13494. // Find the word at the given position (as returned by coordsChar).
  13495. findWordAt: function(pos) {
  13496. var doc = this.doc, line = getLine(doc, pos.line).text;
  13497. var start = pos.ch, end = pos.ch;
  13498. if (line) {
  13499. var helper = this.getHelper(pos, "wordChars");
  13500. if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; }
  13501. var startChar = line.charAt(start);
  13502. var check = isWordChar(startChar, helper)
  13503. ? function (ch) { return isWordChar(ch, helper); }
  13504. : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
  13505. : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); };
  13506. while (start > 0 && check(line.charAt(start - 1))) { --start; }
  13507. while (end < line.length && check(line.charAt(end))) { ++end; }
  13508. }
  13509. return new Range(Pos(pos.line, start), Pos(pos.line, end))
  13510. },
  13511. toggleOverwrite: function(value) {
  13512. if (value != null && value == this.state.overwrite) { return }
  13513. if (this.state.overwrite = !this.state.overwrite)
  13514. { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
  13515. else
  13516. { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
  13517. signal(this, "overwriteToggle", this, this.state.overwrite);
  13518. },
  13519. hasFocus: function() { return this.display.input.getField() == activeElt() },
  13520. isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
  13521. scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
  13522. getScrollInfo: function() {
  13523. var scroller = this.display.scroller;
  13524. return {left: scroller.scrollLeft, top: scroller.scrollTop,
  13525. height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
  13526. width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
  13527. clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
  13528. },
  13529. scrollIntoView: methodOp(function(range, margin) {
  13530. if (range == null) {
  13531. range = {from: this.doc.sel.primary().head, to: null};
  13532. if (margin == null) { margin = this.options.cursorScrollMargin; }
  13533. } else if (typeof range == "number") {
  13534. range = {from: Pos(range, 0), to: null};
  13535. } else if (range.from == null) {
  13536. range = {from: range, to: null};
  13537. }
  13538. if (!range.to) { range.to = range.from; }
  13539. range.margin = margin || 0;
  13540. if (range.from.line != null) {
  13541. scrollToRange(this, range);
  13542. } else {
  13543. scrollToCoordsRange(this, range.from, range.to, range.margin);
  13544. }
  13545. }),
  13546. setSize: methodOp(function(width, height) {
  13547. var this$1 = this;
  13548. var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; };
  13549. if (width != null) { this.display.wrapper.style.width = interpret(width); }
  13550. if (height != null) { this.display.wrapper.style.height = interpret(height); }
  13551. if (this.options.lineWrapping) { clearLineMeasurementCache(this); }
  13552. var lineNo = this.display.viewFrom;
  13553. this.doc.iter(lineNo, this.display.viewTo, function (line) {
  13554. if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
  13555. { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } }
  13556. ++lineNo;
  13557. });
  13558. this.curOp.forceUpdate = true;
  13559. signal(this, "refresh", this);
  13560. }),
  13561. operation: function(f){return runInOp(this, f)},
  13562. startOperation: function(){return startOperation(this)},
  13563. endOperation: function(){return endOperation(this)},
  13564. refresh: methodOp(function() {
  13565. var oldHeight = this.display.cachedTextHeight;
  13566. regChange(this);
  13567. this.curOp.forceUpdate = true;
  13568. clearCaches(this);
  13569. scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
  13570. updateGutterSpace(this.display);
  13571. if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5 || this.options.lineWrapping)
  13572. { estimateLineHeights(this); }
  13573. signal(this, "refresh", this);
  13574. }),
  13575. swapDoc: methodOp(function(doc) {
  13576. var old = this.doc;
  13577. old.cm = null;
  13578. // Cancel the current text selection if any (#5821)
  13579. if (this.state.selectingText) { this.state.selectingText(); }
  13580. attachDoc(this, doc);
  13581. clearCaches(this);
  13582. this.display.input.reset();
  13583. scrollToCoords(this, doc.scrollLeft, doc.scrollTop);
  13584. this.curOp.forceScroll = true;
  13585. signalLater(this, "swapDoc", this, old);
  13586. return old
  13587. }),
  13588. phrase: function(phraseText) {
  13589. var phrases = this.options.phrases;
  13590. return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText
  13591. },
  13592. getInputField: function(){return this.display.input.getField()},
  13593. getWrapperElement: function(){return this.display.wrapper},
  13594. getScrollerElement: function(){return this.display.scroller},
  13595. getGutterElement: function(){return this.display.gutters}
  13596. };
  13597. eventMixin(CodeMirror);
  13598. CodeMirror.registerHelper = function(type, name, value) {
  13599. if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; }
  13600. helpers[type][name] = value;
  13601. };
  13602. CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
  13603. CodeMirror.registerHelper(type, name, value);
  13604. helpers[type]._global.push({pred: predicate, val: value});
  13605. };
  13606. }
  13607. // Used for horizontal relative motion. Dir is -1 or 1 (left or
  13608. // right), unit can be "char", "column" (like char, but doesn't
  13609. // cross line boundaries), "word" (across next word), or "group" (to
  13610. // the start of next group of word or non-word-non-whitespace
  13611. // chars). The visually param controls whether, in right-to-left
  13612. // text, direction 1 means to move towards the next index in the
  13613. // string, or towards the character to the right of the current
  13614. // position. The resulting position will have a hitSide=true
  13615. // property if it reached the end of the document.
  13616. function findPosH(doc, pos, dir, unit, visually) {
  13617. var oldPos = pos;
  13618. var origDir = dir;
  13619. var lineObj = getLine(doc, pos.line);
  13620. var lineDir = visually && doc.direction == "rtl" ? -dir : dir;
  13621. function findNextLine() {
  13622. var l = pos.line + lineDir;
  13623. if (l < doc.first || l >= doc.first + doc.size) { return false }
  13624. pos = new Pos(l, pos.ch, pos.sticky);
  13625. return lineObj = getLine(doc, l)
  13626. }
  13627. function moveOnce(boundToLine) {
  13628. var next;
  13629. if (visually) {
  13630. next = moveVisually(doc.cm, lineObj, pos, dir);
  13631. } else {
  13632. next = moveLogically(lineObj, pos, dir);
  13633. }
  13634. if (next == null) {
  13635. if (!boundToLine && findNextLine())
  13636. { pos = endOfLine(visually, doc.cm, lineObj, pos.line, lineDir); }
  13637. else
  13638. { return false }
  13639. } else {
  13640. pos = next;
  13641. }
  13642. return true
  13643. }
  13644. if (unit == "char") {
  13645. moveOnce();
  13646. } else if (unit == "column") {
  13647. moveOnce(true);
  13648. } else if (unit == "word" || unit == "group") {
  13649. var sawType = null, group = unit == "group";
  13650. var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
  13651. for (var first = true;; first = false) {
  13652. if (dir < 0 && !moveOnce(!first)) { break }
  13653. var cur = lineObj.text.charAt(pos.ch) || "\n";
  13654. var type = isWordChar(cur, helper) ? "w"
  13655. : group && cur == "\n" ? "n"
  13656. : !group || /\s/.test(cur) ? null
  13657. : "p";
  13658. if (group && !first && !type) { type = "s"; }
  13659. if (sawType && sawType != type) {
  13660. if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
  13661. break
  13662. }
  13663. if (type) { sawType = type; }
  13664. if (dir > 0 && !moveOnce(!first)) { break }
  13665. }
  13666. }
  13667. var result = skipAtomic(doc, pos, oldPos, origDir, true);
  13668. if (equalCursorPos(oldPos, result)) { result.hitSide = true; }
  13669. return result
  13670. }
  13671. // For relative vertical movement. Dir may be -1 or 1. Unit can be
  13672. // "page" or "line". The resulting position will have a hitSide=true
  13673. // property if it reached the end of the document.
  13674. function findPosV(cm, pos, dir, unit) {
  13675. var doc = cm.doc, x = pos.left, y;
  13676. if (unit == "page") {
  13677. var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
  13678. var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
  13679. y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
  13680. } else if (unit == "line") {
  13681. y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
  13682. }
  13683. var target;
  13684. for (;;) {
  13685. target = coordsChar(cm, x, y);
  13686. if (!target.outside) { break }
  13687. if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
  13688. y += dir * 5;
  13689. }
  13690. return target
  13691. }
  13692. // CONTENTEDITABLE INPUT STYLE
  13693. var ContentEditableInput = function(cm) {
  13694. this.cm = cm;
  13695. this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
  13696. this.polling = new Delayed();
  13697. this.composing = null;
  13698. this.gracePeriod = false;
  13699. this.readDOMTimeout = null;
  13700. };
  13701. ContentEditableInput.prototype.init = function (display) {
  13702. var this$1 = this;
  13703. var input = this, cm = input.cm;
  13704. var div = input.div = display.lineDiv;
  13705. disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize);
  13706. on(div, "paste", function (e) {
  13707. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
  13708. // IE doesn't fire input events, so we schedule a read for the pasted content in this way
  13709. if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); }
  13710. });
  13711. on(div, "compositionstart", function (e) {
  13712. this$1.composing = {data: e.data, done: false};
  13713. });
  13714. on(div, "compositionupdate", function (e) {
  13715. if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; }
  13716. });
  13717. on(div, "compositionend", function (e) {
  13718. if (this$1.composing) {
  13719. if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); }
  13720. this$1.composing.done = true;
  13721. }
  13722. });
  13723. on(div, "touchstart", function () { return input.forceCompositionEnd(); });
  13724. on(div, "input", function () {
  13725. if (!this$1.composing) { this$1.readFromDOMSoon(); }
  13726. });
  13727. function onCopyCut(e) {
  13728. if (signalDOMEvent(cm, e)) { return }
  13729. if (cm.somethingSelected()) {
  13730. setLastCopied({lineWise: false, text: cm.getSelections()});
  13731. if (e.type == "cut") { cm.replaceSelection("", null, "cut"); }
  13732. } else if (!cm.options.lineWiseCopyCut) {
  13733. return
  13734. } else {
  13735. var ranges = copyableRanges(cm);
  13736. setLastCopied({lineWise: true, text: ranges.text});
  13737. if (e.type == "cut") {
  13738. cm.operation(function () {
  13739. cm.setSelections(ranges.ranges, 0, sel_dontScroll);
  13740. cm.replaceSelection("", null, "cut");
  13741. });
  13742. }
  13743. }
  13744. if (e.clipboardData) {
  13745. e.clipboardData.clearData();
  13746. var content = lastCopied.text.join("\n");
  13747. // iOS exposes the clipboard API, but seems to discard content inserted into it
  13748. e.clipboardData.setData("Text", content);
  13749. if (e.clipboardData.getData("Text") == content) {
  13750. e.preventDefault();
  13751. return
  13752. }
  13753. }
  13754. // Old-fashioned briefly-focus-a-textarea hack
  13755. var kludge = hiddenTextarea(), te = kludge.firstChild;
  13756. cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
  13757. te.value = lastCopied.text.join("\n");
  13758. var hadFocus = document.activeElement;
  13759. selectInput(te);
  13760. setTimeout(function () {
  13761. cm.display.lineSpace.removeChild(kludge);
  13762. hadFocus.focus();
  13763. if (hadFocus == div) { input.showPrimarySelection(); }
  13764. }, 50);
  13765. }
  13766. on(div, "copy", onCopyCut);
  13767. on(div, "cut", onCopyCut);
  13768. };
  13769. ContentEditableInput.prototype.screenReaderLabelChanged = function (label) {
  13770. // Label for screenreaders, accessibility
  13771. if(label) {
  13772. this.div.setAttribute('aria-label', label);
  13773. } else {
  13774. this.div.removeAttribute('aria-label');
  13775. }
  13776. };
  13777. ContentEditableInput.prototype.prepareSelection = function () {
  13778. var result = prepareSelection(this.cm, false);
  13779. result.focus = document.activeElement == this.div;
  13780. return result
  13781. };
  13782. ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
  13783. if (!info || !this.cm.display.view.length) { return }
  13784. if (info.focus || takeFocus) { this.showPrimarySelection(); }
  13785. this.showMultipleSelections(info);
  13786. };
  13787. ContentEditableInput.prototype.getSelection = function () {
  13788. return this.cm.display.wrapper.ownerDocument.getSelection()
  13789. };
  13790. ContentEditableInput.prototype.showPrimarySelection = function () {
  13791. var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary();
  13792. var from = prim.from(), to = prim.to();
  13793. if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
  13794. sel.removeAllRanges();
  13795. return
  13796. }
  13797. var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  13798. var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
  13799. if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
  13800. cmp(minPos(curAnchor, curFocus), from) == 0 &&
  13801. cmp(maxPos(curAnchor, curFocus), to) == 0)
  13802. { return }
  13803. var view = cm.display.view;
  13804. var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
  13805. {node: view[0].measure.map[2], offset: 0};
  13806. var end = to.line < cm.display.viewTo && posToDOM(cm, to);
  13807. if (!end) {
  13808. var measure = view[view.length - 1].measure;
  13809. var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
  13810. end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]};
  13811. }
  13812. if (!start || !end) {
  13813. sel.removeAllRanges();
  13814. return
  13815. }
  13816. var old = sel.rangeCount && sel.getRangeAt(0), rng;
  13817. try { rng = range(start.node, start.offset, end.offset, end.node); }
  13818. catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
  13819. if (rng) {
  13820. if (!gecko && cm.state.focused) {
  13821. sel.collapse(start.node, start.offset);
  13822. if (!rng.collapsed) {
  13823. sel.removeAllRanges();
  13824. sel.addRange(rng);
  13825. }
  13826. } else {
  13827. sel.removeAllRanges();
  13828. sel.addRange(rng);
  13829. }
  13830. if (old && sel.anchorNode == null) { sel.addRange(old); }
  13831. else if (gecko) { this.startGracePeriod(); }
  13832. }
  13833. this.rememberSelection();
  13834. };
  13835. ContentEditableInput.prototype.startGracePeriod = function () {
  13836. var this$1 = this;
  13837. clearTimeout(this.gracePeriod);
  13838. this.gracePeriod = setTimeout(function () {
  13839. this$1.gracePeriod = false;
  13840. if (this$1.selectionChanged())
  13841. { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); }
  13842. }, 20);
  13843. };
  13844. ContentEditableInput.prototype.showMultipleSelections = function (info) {
  13845. removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
  13846. removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
  13847. };
  13848. ContentEditableInput.prototype.rememberSelection = function () {
  13849. var sel = this.getSelection();
  13850. this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
  13851. this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
  13852. };
  13853. ContentEditableInput.prototype.selectionInEditor = function () {
  13854. var sel = this.getSelection();
  13855. if (!sel.rangeCount) { return false }
  13856. var node = sel.getRangeAt(0).commonAncestorContainer;
  13857. return contains(this.div, node)
  13858. };
  13859. ContentEditableInput.prototype.focus = function () {
  13860. if (this.cm.options.readOnly != "nocursor") {
  13861. if (!this.selectionInEditor() || document.activeElement != this.div)
  13862. { this.showSelection(this.prepareSelection(), true); }
  13863. this.div.focus();
  13864. }
  13865. };
  13866. ContentEditableInput.prototype.blur = function () { this.div.blur(); };
  13867. ContentEditableInput.prototype.getField = function () { return this.div };
  13868. ContentEditableInput.prototype.supportsTouch = function () { return true };
  13869. ContentEditableInput.prototype.receivedFocus = function () {
  13870. var input = this;
  13871. if (this.selectionInEditor())
  13872. { this.pollSelection(); }
  13873. else
  13874. { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); }
  13875. function poll() {
  13876. if (input.cm.state.focused) {
  13877. input.pollSelection();
  13878. input.polling.set(input.cm.options.pollInterval, poll);
  13879. }
  13880. }
  13881. this.polling.set(this.cm.options.pollInterval, poll);
  13882. };
  13883. ContentEditableInput.prototype.selectionChanged = function () {
  13884. var sel = this.getSelection();
  13885. return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
  13886. sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
  13887. };
  13888. ContentEditableInput.prototype.pollSelection = function () {
  13889. if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
  13890. var sel = this.getSelection(), cm = this.cm;
  13891. // On Android Chrome (version 56, at least), backspacing into an
  13892. // uneditable block element will put the cursor in that element,
  13893. // and then, because it's not editable, hide the virtual keyboard.
  13894. // Because Android doesn't allow us to actually detect backspace
  13895. // presses in a sane way, this code checks for when that happens
  13896. // and simulates a backspace press in this case.
  13897. if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) {
  13898. this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs});
  13899. this.blur();
  13900. this.focus();
  13901. return
  13902. }
  13903. if (this.composing) { return }
  13904. this.rememberSelection();
  13905. var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  13906. var head = domToPos(cm, sel.focusNode, sel.focusOffset);
  13907. if (anchor && head) { runInOp(cm, function () {
  13908. setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
  13909. if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; }
  13910. }); }
  13911. };
  13912. ContentEditableInput.prototype.pollContent = function () {
  13913. if (this.readDOMTimeout != null) {
  13914. clearTimeout(this.readDOMTimeout);
  13915. this.readDOMTimeout = null;
  13916. }
  13917. var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
  13918. var from = sel.from(), to = sel.to();
  13919. if (from.ch == 0 && from.line > cm.firstLine())
  13920. { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); }
  13921. if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
  13922. { to = Pos(to.line + 1, 0); }
  13923. if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
  13924. var fromIndex, fromLine, fromNode;
  13925. if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
  13926. fromLine = lineNo(display.view[0].line);
  13927. fromNode = display.view[0].node;
  13928. } else {
  13929. fromLine = lineNo(display.view[fromIndex].line);
  13930. fromNode = display.view[fromIndex - 1].node.nextSibling;
  13931. }
  13932. var toIndex = findViewIndex(cm, to.line);
  13933. var toLine, toNode;
  13934. if (toIndex == display.view.length - 1) {
  13935. toLine = display.viewTo - 1;
  13936. toNode = display.lineDiv.lastChild;
  13937. } else {
  13938. toLine = lineNo(display.view[toIndex + 1].line) - 1;
  13939. toNode = display.view[toIndex + 1].node.previousSibling;
  13940. }
  13941. if (!fromNode) { return false }
  13942. var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
  13943. var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
  13944. while (newText.length > 1 && oldText.length > 1) {
  13945. if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
  13946. else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
  13947. else { break }
  13948. }
  13949. var cutFront = 0, cutEnd = 0;
  13950. var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
  13951. while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
  13952. { ++cutFront; }
  13953. var newBot = lst(newText), oldBot = lst(oldText);
  13954. var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
  13955. oldBot.length - (oldText.length == 1 ? cutFront : 0));
  13956. while (cutEnd < maxCutEnd &&
  13957. newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
  13958. { ++cutEnd; }
  13959. // Try to move start of change to start of selection if ambiguous
  13960. if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
  13961. while (cutFront && cutFront > from.ch &&
  13962. newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
  13963. cutFront--;
  13964. cutEnd++;
  13965. }
  13966. }
  13967. newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
  13968. newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
  13969. var chFrom = Pos(fromLine, cutFront);
  13970. var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
  13971. if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
  13972. replaceRange(cm.doc, newText, chFrom, chTo, "+input");
  13973. return true
  13974. }
  13975. };
  13976. ContentEditableInput.prototype.ensurePolled = function () {
  13977. this.forceCompositionEnd();
  13978. };
  13979. ContentEditableInput.prototype.reset = function () {
  13980. this.forceCompositionEnd();
  13981. };
  13982. ContentEditableInput.prototype.forceCompositionEnd = function () {
  13983. if (!this.composing) { return }
  13984. clearTimeout(this.readDOMTimeout);
  13985. this.composing = null;
  13986. this.updateFromDOM();
  13987. this.div.blur();
  13988. this.div.focus();
  13989. };
  13990. ContentEditableInput.prototype.readFromDOMSoon = function () {
  13991. var this$1 = this;
  13992. if (this.readDOMTimeout != null) { return }
  13993. this.readDOMTimeout = setTimeout(function () {
  13994. this$1.readDOMTimeout = null;
  13995. if (this$1.composing) {
  13996. if (this$1.composing.done) { this$1.composing = null; }
  13997. else { return }
  13998. }
  13999. this$1.updateFromDOM();
  14000. }, 80);
  14001. };
  14002. ContentEditableInput.prototype.updateFromDOM = function () {
  14003. var this$1 = this;
  14004. if (this.cm.isReadOnly() || !this.pollContent())
  14005. { runInOp(this.cm, function () { return regChange(this$1.cm); }); }
  14006. };
  14007. ContentEditableInput.prototype.setUneditable = function (node) {
  14008. node.contentEditable = "false";
  14009. };
  14010. ContentEditableInput.prototype.onKeyPress = function (e) {
  14011. if (e.charCode == 0 || this.composing) { return }
  14012. e.preventDefault();
  14013. if (!this.cm.isReadOnly())
  14014. { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); }
  14015. };
  14016. ContentEditableInput.prototype.readOnlyChanged = function (val) {
  14017. this.div.contentEditable = String(val != "nocursor");
  14018. };
  14019. ContentEditableInput.prototype.onContextMenu = function () {};
  14020. ContentEditableInput.prototype.resetPosition = function () {};
  14021. ContentEditableInput.prototype.needsContentAttribute = true;
  14022. function posToDOM(cm, pos) {
  14023. var view = findViewForLine(cm, pos.line);
  14024. if (!view || view.hidden) { return null }
  14025. var line = getLine(cm.doc, pos.line);
  14026. var info = mapFromLineView(view, line, pos.line);
  14027. var order = getOrder(line, cm.doc.direction), side = "left";
  14028. if (order) {
  14029. var partPos = getBidiPartAt(order, pos.ch);
  14030. side = partPos % 2 ? "right" : "left";
  14031. }
  14032. var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
  14033. result.offset = result.collapse == "right" ? result.end : result.start;
  14034. return result
  14035. }
  14036. function isInGutter(node) {
  14037. for (var scan = node; scan; scan = scan.parentNode)
  14038. { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
  14039. return false
  14040. }
  14041. function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
  14042. function domTextBetween(cm, from, to, fromLine, toLine) {
  14043. var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false;
  14044. function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
  14045. function close() {
  14046. if (closing) {
  14047. text += lineSep;
  14048. if (extraLinebreak) { text += lineSep; }
  14049. closing = extraLinebreak = false;
  14050. }
  14051. }
  14052. function addText(str) {
  14053. if (str) {
  14054. close();
  14055. text += str;
  14056. }
  14057. }
  14058. function walk(node) {
  14059. if (node.nodeType == 1) {
  14060. var cmText = node.getAttribute("cm-text");
  14061. if (cmText) {
  14062. addText(cmText);
  14063. return
  14064. }
  14065. var markerID = node.getAttribute("cm-marker"), range;
  14066. if (markerID) {
  14067. var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
  14068. if (found.length && (range = found[0].find(0)))
  14069. { addText(getBetween(cm.doc, range.from, range.to).join(lineSep)); }
  14070. return
  14071. }
  14072. if (node.getAttribute("contenteditable") == "false") { return }
  14073. var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
  14074. if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
  14075. if (isBlock) { close(); }
  14076. for (var i = 0; i < node.childNodes.length; i++)
  14077. { walk(node.childNodes[i]); }
  14078. if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true; }
  14079. if (isBlock) { closing = true; }
  14080. } else if (node.nodeType == 3) {
  14081. addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
  14082. }
  14083. }
  14084. for (;;) {
  14085. walk(from);
  14086. if (from == to) { break }
  14087. from = from.nextSibling;
  14088. extraLinebreak = false;
  14089. }
  14090. return text
  14091. }
  14092. function domToPos(cm, node, offset) {
  14093. var lineNode;
  14094. if (node == cm.display.lineDiv) {
  14095. lineNode = cm.display.lineDiv.childNodes[offset];
  14096. if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
  14097. node = null; offset = 0;
  14098. } else {
  14099. for (lineNode = node;; lineNode = lineNode.parentNode) {
  14100. if (!lineNode || lineNode == cm.display.lineDiv) { return null }
  14101. if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
  14102. }
  14103. }
  14104. for (var i = 0; i < cm.display.view.length; i++) {
  14105. var lineView = cm.display.view[i];
  14106. if (lineView.node == lineNode)
  14107. { return locateNodeInLineView(lineView, node, offset) }
  14108. }
  14109. }
  14110. function locateNodeInLineView(lineView, node, offset) {
  14111. var wrapper = lineView.text.firstChild, bad = false;
  14112. if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
  14113. if (node == wrapper) {
  14114. bad = true;
  14115. node = wrapper.childNodes[offset];
  14116. offset = 0;
  14117. if (!node) {
  14118. var line = lineView.rest ? lst(lineView.rest) : lineView.line;
  14119. return badPos(Pos(lineNo(line), line.text.length), bad)
  14120. }
  14121. }
  14122. var textNode = node.nodeType == 3 ? node : null, topNode = node;
  14123. if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
  14124. textNode = node.firstChild;
  14125. if (offset) { offset = textNode.nodeValue.length; }
  14126. }
  14127. while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; }
  14128. var measure = lineView.measure, maps = measure.maps;
  14129. function find(textNode, topNode, offset) {
  14130. for (var i = -1; i < (maps ? maps.length : 0); i++) {
  14131. var map = i < 0 ? measure.map : maps[i];
  14132. for (var j = 0; j < map.length; j += 3) {
  14133. var curNode = map[j + 2];
  14134. if (curNode == textNode || curNode == topNode) {
  14135. var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
  14136. var ch = map[j] + offset;
  14137. if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)]; }
  14138. return Pos(line, ch)
  14139. }
  14140. }
  14141. }
  14142. }
  14143. var found = find(textNode, topNode, offset);
  14144. if (found) { return badPos(found, bad) }
  14145. // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
  14146. for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
  14147. found = find(after, after.firstChild, 0);
  14148. if (found)
  14149. { return badPos(Pos(found.line, found.ch - dist), bad) }
  14150. else
  14151. { dist += after.textContent.length; }
  14152. }
  14153. for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
  14154. found = find(before, before.firstChild, -1);
  14155. if (found)
  14156. { return badPos(Pos(found.line, found.ch + dist$1), bad) }
  14157. else
  14158. { dist$1 += before.textContent.length; }
  14159. }
  14160. }
  14161. // TEXTAREA INPUT STYLE
  14162. var TextareaInput = function(cm) {
  14163. this.cm = cm;
  14164. // See input.poll and input.reset
  14165. this.prevInput = "";
  14166. // Flag that indicates whether we expect input to appear real soon
  14167. // now (after some event like 'keypress' or 'input') and are
  14168. // polling intensively.
  14169. this.pollingFast = false;
  14170. // Self-resetting timeout for the poller
  14171. this.polling = new Delayed();
  14172. // Used to work around IE issue with selection being forgotten when focus moves away from textarea
  14173. this.hasSelection = false;
  14174. this.composing = null;
  14175. };
  14176. TextareaInput.prototype.init = function (display) {
  14177. var this$1 = this;
  14178. var input = this, cm = this.cm;
  14179. this.createField(display);
  14180. var te = this.textarea;
  14181. display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
  14182. // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
  14183. if (ios) { te.style.width = "0px"; }
  14184. on(te, "input", function () {
  14185. if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; }
  14186. input.poll();
  14187. });
  14188. on(te, "paste", function (e) {
  14189. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
  14190. cm.state.pasteIncoming = +new Date;
  14191. input.fastPoll();
  14192. });
  14193. function prepareCopyCut(e) {
  14194. if (signalDOMEvent(cm, e)) { return }
  14195. if (cm.somethingSelected()) {
  14196. setLastCopied({lineWise: false, text: cm.getSelections()});
  14197. } else if (!cm.options.lineWiseCopyCut) {
  14198. return
  14199. } else {
  14200. var ranges = copyableRanges(cm);
  14201. setLastCopied({lineWise: true, text: ranges.text});
  14202. if (e.type == "cut") {
  14203. cm.setSelections(ranges.ranges, null, sel_dontScroll);
  14204. } else {
  14205. input.prevInput = "";
  14206. te.value = ranges.text.join("\n");
  14207. selectInput(te);
  14208. }
  14209. }
  14210. if (e.type == "cut") { cm.state.cutIncoming = +new Date; }
  14211. }
  14212. on(te, "cut", prepareCopyCut);
  14213. on(te, "copy", prepareCopyCut);
  14214. on(display.scroller, "paste", function (e) {
  14215. if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
  14216. if (!te.dispatchEvent) {
  14217. cm.state.pasteIncoming = +new Date;
  14218. input.focus();
  14219. return
  14220. }
  14221. // Pass the `paste` event to the textarea so it's handled by its event listener.
  14222. var event = new Event("paste");
  14223. event.clipboardData = e.clipboardData;
  14224. te.dispatchEvent(event);
  14225. });
  14226. // Prevent normal selection in the editor (we handle our own)
  14227. on(display.lineSpace, "selectstart", function (e) {
  14228. if (!eventInWidget(display, e)) { e_preventDefault(e); }
  14229. });
  14230. on(te, "compositionstart", function () {
  14231. var start = cm.getCursor("from");
  14232. if (input.composing) { input.composing.range.clear(); }
  14233. input.composing = {
  14234. start: start,
  14235. range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
  14236. };
  14237. });
  14238. on(te, "compositionend", function () {
  14239. if (input.composing) {
  14240. input.poll();
  14241. input.composing.range.clear();
  14242. input.composing = null;
  14243. }
  14244. });
  14245. };
  14246. TextareaInput.prototype.createField = function (_display) {
  14247. // Wraps and hides input textarea
  14248. this.wrapper = hiddenTextarea();
  14249. // The semihidden textarea that is focused when the editor is
  14250. // focused, and receives input.
  14251. this.textarea = this.wrapper.firstChild;
  14252. };
  14253. TextareaInput.prototype.screenReaderLabelChanged = function (label) {
  14254. // Label for screenreaders, accessibility
  14255. if(label) {
  14256. this.textarea.setAttribute('aria-label', label);
  14257. } else {
  14258. this.textarea.removeAttribute('aria-label');
  14259. }
  14260. };
  14261. TextareaInput.prototype.prepareSelection = function () {
  14262. // Redraw the selection and/or cursor
  14263. var cm = this.cm, display = cm.display, doc = cm.doc;
  14264. var result = prepareSelection(cm);
  14265. // Move the hidden textarea near the cursor to prevent scrolling artifacts
  14266. if (cm.options.moveInputWithCursor) {
  14267. var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
  14268. var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
  14269. result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
  14270. headPos.top + lineOff.top - wrapOff.top));
  14271. result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
  14272. headPos.left + lineOff.left - wrapOff.left));
  14273. }
  14274. return result
  14275. };
  14276. TextareaInput.prototype.showSelection = function (drawn) {
  14277. var cm = this.cm, display = cm.display;
  14278. removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
  14279. removeChildrenAndAdd(display.selectionDiv, drawn.selection);
  14280. if (drawn.teTop != null) {
  14281. this.wrapper.style.top = drawn.teTop + "px";
  14282. this.wrapper.style.left = drawn.teLeft + "px";
  14283. }
  14284. };
  14285. // Reset the input to correspond to the selection (or to be empty,
  14286. // when not typing and nothing is selected)
  14287. TextareaInput.prototype.reset = function (typing) {
  14288. if (this.contextMenuPending || this.composing) { return }
  14289. var cm = this.cm;
  14290. if (cm.somethingSelected()) {
  14291. this.prevInput = "";
  14292. var content = cm.getSelection();
  14293. this.textarea.value = content;
  14294. if (cm.state.focused) { selectInput(this.textarea); }
  14295. if (ie && ie_version >= 9) { this.hasSelection = content; }
  14296. } else if (!typing) {
  14297. this.prevInput = this.textarea.value = "";
  14298. if (ie && ie_version >= 9) { this.hasSelection = null; }
  14299. }
  14300. };
  14301. TextareaInput.prototype.getField = function () { return this.textarea };
  14302. TextareaInput.prototype.supportsTouch = function () { return false };
  14303. TextareaInput.prototype.focus = function () {
  14304. if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
  14305. try { this.textarea.focus(); }
  14306. catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
  14307. }
  14308. };
  14309. TextareaInput.prototype.blur = function () { this.textarea.blur(); };
  14310. TextareaInput.prototype.resetPosition = function () {
  14311. this.wrapper.style.top = this.wrapper.style.left = 0;
  14312. };
  14313. TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); };
  14314. // Poll for input changes, using the normal rate of polling. This
  14315. // runs as long as the editor is focused.
  14316. TextareaInput.prototype.slowPoll = function () {
  14317. var this$1 = this;
  14318. if (this.pollingFast) { return }
  14319. this.polling.set(this.cm.options.pollInterval, function () {
  14320. this$1.poll();
  14321. if (this$1.cm.state.focused) { this$1.slowPoll(); }
  14322. });
  14323. };
  14324. // When an event has just come in that is likely to add or change
  14325. // something in the input textarea, we poll faster, to ensure that
  14326. // the change appears on the screen quickly.
  14327. TextareaInput.prototype.fastPoll = function () {
  14328. var missed = false, input = this;
  14329. input.pollingFast = true;
  14330. function p() {
  14331. var changed = input.poll();
  14332. if (!changed && !missed) {missed = true; input.polling.set(60, p);}
  14333. else {input.pollingFast = false; input.slowPoll();}
  14334. }
  14335. input.polling.set(20, p);
  14336. };
  14337. // Read input from the textarea, and update the document to match.
  14338. // When something is selected, it is present in the textarea, and
  14339. // selected (unless it is huge, in which case a placeholder is
  14340. // used). When nothing is selected, the cursor sits after previously
  14341. // seen text (can be empty), which is stored in prevInput (we must
  14342. // not reset the textarea when typing, because that breaks IME).
  14343. TextareaInput.prototype.poll = function () {
  14344. var this$1 = this;
  14345. var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
  14346. // Since this is called a *lot*, try to bail out as cheaply as
  14347. // possible when it is clear that nothing happened. hasSelection
  14348. // will be the case when there is a lot of text in the textarea,
  14349. // in which case reading its value would be expensive.
  14350. if (this.contextMenuPending || !cm.state.focused ||
  14351. (hasSelection(input) && !prevInput && !this.composing) ||
  14352. cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
  14353. { return false }
  14354. var text = input.value;
  14355. // If nothing changed, bail.
  14356. if (text == prevInput && !cm.somethingSelected()) { return false }
  14357. // Work around nonsensical selection resetting in IE9/10, and
  14358. // inexplicable appearance of private area unicode characters on
  14359. // some key combos in Mac (#2689).
  14360. if (ie && ie_version >= 9 && this.hasSelection === text ||
  14361. mac && /[\uf700-\uf7ff]/.test(text)) {
  14362. cm.display.input.reset();
  14363. return false
  14364. }
  14365. if (cm.doc.sel == cm.display.selForContextMenu) {
  14366. var first = text.charCodeAt(0);
  14367. if (first == 0x200b && !prevInput) { prevInput = "\u200b"; }
  14368. if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
  14369. }
  14370. // Find the part of the input that is actually new
  14371. var same = 0, l = Math.min(prevInput.length, text.length);
  14372. while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; }
  14373. runInOp(cm, function () {
  14374. applyTextInput(cm, text.slice(same), prevInput.length - same,
  14375. null, this$1.composing ? "*compose" : null);
  14376. // Don't leave long text in the textarea, since it makes further polling slow
  14377. if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; }
  14378. else { this$1.prevInput = text; }
  14379. if (this$1.composing) {
  14380. this$1.composing.range.clear();
  14381. this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
  14382. {className: "CodeMirror-composing"});
  14383. }
  14384. });
  14385. return true
  14386. };
  14387. TextareaInput.prototype.ensurePolled = function () {
  14388. if (this.pollingFast && this.poll()) { this.pollingFast = false; }
  14389. };
  14390. TextareaInput.prototype.onKeyPress = function () {
  14391. if (ie && ie_version >= 9) { this.hasSelection = null; }
  14392. this.fastPoll();
  14393. };
  14394. TextareaInput.prototype.onContextMenu = function (e) {
  14395. var input = this, cm = input.cm, display = cm.display, te = input.textarea;
  14396. if (input.contextMenuPending) { input.contextMenuPending(); }
  14397. var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
  14398. if (!pos || presto) { return } // Opera is difficult.
  14399. // Reset the current text selection only if the click is done outside of the selection
  14400. // and 'resetSelectionOnContextMenu' option is true.
  14401. var reset = cm.options.resetSelectionOnContextMenu;
  14402. if (reset && cm.doc.sel.contains(pos) == -1)
  14403. { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }
  14404. var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
  14405. var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect();
  14406. input.wrapper.style.cssText = "position: static";
  14407. 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);";
  14408. var oldScrollY;
  14409. if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712)
  14410. display.input.focus();
  14411. if (webkit) { window.scrollTo(null, oldScrollY); }
  14412. display.input.reset();
  14413. // Adds "Select all" to context menu in FF
  14414. if (!cm.somethingSelected()) { te.value = input.prevInput = " "; }
  14415. input.contextMenuPending = rehide;
  14416. display.selForContextMenu = cm.doc.sel;
  14417. clearTimeout(display.detectingSelectAll);
  14418. // Select-all will be greyed out if there's nothing to select, so
  14419. // this adds a zero-width space so that we can later check whether
  14420. // it got selected.
  14421. function prepareSelectAllHack() {
  14422. if (te.selectionStart != null) {
  14423. var selected = cm.somethingSelected();
  14424. var extval = "\u200b" + (selected ? te.value : "");
  14425. te.value = "\u21da"; // Used to catch context-menu undo
  14426. te.value = extval;
  14427. input.prevInput = selected ? "" : "\u200b";
  14428. te.selectionStart = 1; te.selectionEnd = extval.length;
  14429. // Re-set this, in case some other handler touched the
  14430. // selection in the meantime.
  14431. display.selForContextMenu = cm.doc.sel;
  14432. }
  14433. }
  14434. function rehide() {
  14435. if (input.contextMenuPending != rehide) { return }
  14436. input.contextMenuPending = false;
  14437. input.wrapper.style.cssText = oldWrapperCSS;
  14438. te.style.cssText = oldCSS;
  14439. if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); }
  14440. // Try to detect the user choosing select-all
  14441. if (te.selectionStart != null) {
  14442. if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); }
  14443. var i = 0, poll = function () {
  14444. if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
  14445. te.selectionEnd > 0 && input.prevInput == "\u200b") {
  14446. operation(cm, selectAll)(cm);
  14447. } else if (i++ < 10) {
  14448. display.detectingSelectAll = setTimeout(poll, 500);
  14449. } else {
  14450. display.selForContextMenu = null;
  14451. display.input.reset();
  14452. }
  14453. };
  14454. display.detectingSelectAll = setTimeout(poll, 200);
  14455. }
  14456. }
  14457. if (ie && ie_version >= 9) { prepareSelectAllHack(); }
  14458. if (captureRightClick) {
  14459. e_stop(e);
  14460. var mouseup = function () {
  14461. off(window, "mouseup", mouseup);
  14462. setTimeout(rehide, 20);
  14463. };
  14464. on(window, "mouseup", mouseup);
  14465. } else {
  14466. setTimeout(rehide, 50);
  14467. }
  14468. };
  14469. TextareaInput.prototype.readOnlyChanged = function (val) {
  14470. if (!val) { this.reset(); }
  14471. this.textarea.disabled = val == "nocursor";
  14472. };
  14473. TextareaInput.prototype.setUneditable = function () {};
  14474. TextareaInput.prototype.needsContentAttribute = false;
  14475. function fromTextArea(textarea, options) {
  14476. options = options ? copyObj(options) : {};
  14477. options.value = textarea.value;
  14478. if (!options.tabindex && textarea.tabIndex)
  14479. { options.tabindex = textarea.tabIndex; }
  14480. if (!options.placeholder && textarea.placeholder)
  14481. { options.placeholder = textarea.placeholder; }
  14482. // Set autofocus to true if this textarea is focused, or if it has
  14483. // autofocus and no other element is focused.
  14484. if (options.autofocus == null) {
  14485. var hasFocus = activeElt();
  14486. options.autofocus = hasFocus == textarea ||
  14487. textarea.getAttribute("autofocus") != null && hasFocus == document.body;
  14488. }
  14489. function save() {textarea.value = cm.getValue();}
  14490. var realSubmit;
  14491. if (textarea.form) {
  14492. on(textarea.form, "submit", save);
  14493. // Deplorable hack to make the submit method do the right thing.
  14494. if (!options.leaveSubmitMethodAlone) {
  14495. var form = textarea.form;
  14496. realSubmit = form.submit;
  14497. try {
  14498. var wrappedSubmit = form.submit = function () {
  14499. save();
  14500. form.submit = realSubmit;
  14501. form.submit();
  14502. form.submit = wrappedSubmit;
  14503. };
  14504. } catch(e) {}
  14505. }
  14506. }
  14507. options.finishInit = function (cm) {
  14508. cm.save = save;
  14509. cm.getTextArea = function () { return textarea; };
  14510. cm.toTextArea = function () {
  14511. cm.toTextArea = isNaN; // Prevent this from being ran twice
  14512. save();
  14513. textarea.parentNode.removeChild(cm.getWrapperElement());
  14514. textarea.style.display = "";
  14515. if (textarea.form) {
  14516. off(textarea.form, "submit", save);
  14517. if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function")
  14518. { textarea.form.submit = realSubmit; }
  14519. }
  14520. };
  14521. };
  14522. textarea.style.display = "none";
  14523. var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
  14524. options);
  14525. return cm
  14526. }
  14527. function addLegacyProps(CodeMirror) {
  14528. CodeMirror.off = off;
  14529. CodeMirror.on = on;
  14530. CodeMirror.wheelEventPixels = wheelEventPixels;
  14531. CodeMirror.Doc = Doc;
  14532. CodeMirror.splitLines = splitLinesAuto;
  14533. CodeMirror.countColumn = countColumn;
  14534. CodeMirror.findColumn = findColumn;
  14535. CodeMirror.isWordChar = isWordCharBasic;
  14536. CodeMirror.Pass = Pass;
  14537. CodeMirror.signal = signal;
  14538. CodeMirror.Line = Line;
  14539. CodeMirror.changeEnd = changeEnd;
  14540. CodeMirror.scrollbarModel = scrollbarModel;
  14541. CodeMirror.Pos = Pos;
  14542. CodeMirror.cmpPos = cmp;
  14543. CodeMirror.modes = modes;
  14544. CodeMirror.mimeModes = mimeModes;
  14545. CodeMirror.resolveMode = resolveMode;
  14546. CodeMirror.getMode = getMode;
  14547. CodeMirror.modeExtensions = modeExtensions;
  14548. CodeMirror.extendMode = extendMode;
  14549. CodeMirror.copyState = copyState;
  14550. CodeMirror.startState = startState;
  14551. CodeMirror.innerMode = innerMode;
  14552. CodeMirror.commands = commands;
  14553. CodeMirror.keyMap = keyMap;
  14554. CodeMirror.keyName = keyName;
  14555. CodeMirror.isModifierKey = isModifierKey;
  14556. CodeMirror.lookupKey = lookupKey;
  14557. CodeMirror.normalizeKeyMap = normalizeKeyMap;
  14558. CodeMirror.StringStream = StringStream;
  14559. CodeMirror.SharedTextMarker = SharedTextMarker;
  14560. CodeMirror.TextMarker = TextMarker;
  14561. CodeMirror.LineWidget = LineWidget;
  14562. CodeMirror.e_preventDefault = e_preventDefault;
  14563. CodeMirror.e_stopPropagation = e_stopPropagation;
  14564. CodeMirror.e_stop = e_stop;
  14565. CodeMirror.addClass = addClass;
  14566. CodeMirror.contains = contains;
  14567. CodeMirror.rmClass = rmClass;
  14568. CodeMirror.keyNames = keyNames;
  14569. }
  14570. // EDITOR CONSTRUCTOR
  14571. defineOptions(CodeMirror);
  14572. addEditorMethods(CodeMirror);
  14573. // Set up methods on CodeMirror's prototype to redirect to the editor's document.
  14574. var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
  14575. for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
  14576. { CodeMirror.prototype[prop] = (function(method) {
  14577. return function() {return method.apply(this.doc, arguments)}
  14578. })(Doc.prototype[prop]); } }
  14579. eventMixin(Doc);
  14580. CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
  14581. // Extra arguments are stored as the mode's dependencies, which is
  14582. // used by (legacy) mechanisms like loadmode.js to automatically
  14583. // load a mode. (Preferred mechanism is the require/define calls.)
  14584. CodeMirror.defineMode = function(name/*, mode, …*/) {
  14585. if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; }
  14586. defineMode.apply(this, arguments);
  14587. };
  14588. CodeMirror.defineMIME = defineMIME;
  14589. // Minimal default mode.
  14590. CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
  14591. CodeMirror.defineMIME("text/plain", "null");
  14592. // EXTENSIONS
  14593. CodeMirror.defineExtension = function (name, func) {
  14594. CodeMirror.prototype[name] = func;
  14595. };
  14596. CodeMirror.defineDocExtension = function (name, func) {
  14597. Doc.prototype[name] = func;
  14598. };
  14599. CodeMirror.fromTextArea = fromTextArea;
  14600. addLegacyProps(CodeMirror);
  14601. CodeMirror.version = "5.53.2";
  14602. return CodeMirror;
  14603. })));
  14604. /***/ }),
  14605. /***/ "a719":
  14606. /***/ (function(module, exports) {
  14607. module.exports = function (it) {
  14608. return typeof it === 'object' ? it !== null : typeof it === 'function';
  14609. };
  14610. /***/ }),
  14611. /***/ "a8a2":
  14612. /***/ (function(module, exports) {
  14613. function getDefaults() {
  14614. return {
  14615. baseUrl: null,
  14616. breaks: false,
  14617. gfm: true,
  14618. headerIds: true,
  14619. headerPrefix: '',
  14620. highlight: null,
  14621. langPrefix: 'language-',
  14622. mangle: true,
  14623. pedantic: false,
  14624. renderer: null,
  14625. sanitize: false,
  14626. sanitizer: null,
  14627. silent: false,
  14628. smartLists: false,
  14629. smartypants: false,
  14630. tokenizer: null,
  14631. xhtml: false
  14632. };
  14633. }
  14634. function changeDefaults(newDefaults) {
  14635. module.exports.defaults = newDefaults;
  14636. }
  14637. module.exports = {
  14638. defaults: getDefaults(),
  14639. getDefaults,
  14640. changeDefaults
  14641. };
  14642. /***/ }),
  14643. /***/ "aa6b":
  14644. /***/ (function(module, exports, __webpack_require__) {
  14645. var DESCRIPTORS = __webpack_require__("1e2c");
  14646. var propertyIsEnumerableModule = __webpack_require__("ef71");
  14647. var createPropertyDescriptor = __webpack_require__("38b9");
  14648. var toIndexedObject = __webpack_require__("da10");
  14649. var toPrimitive = __webpack_require__("9f67");
  14650. var has = __webpack_require__("faa8");
  14651. var IE8_DOM_DEFINE = __webpack_require__("2039");
  14652. var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  14653. // `Object.getOwnPropertyDescriptor` method
  14654. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
  14655. exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  14656. O = toIndexedObject(O);
  14657. P = toPrimitive(P, true);
  14658. if (IE8_DOM_DEFINE) try {
  14659. return nativeGetOwnPropertyDescriptor(O, P);
  14660. } catch (error) { /* empty */ }
  14661. if (has(O, P)) return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]);
  14662. };
  14663. /***/ }),
  14664. /***/ "ac30":
  14665. /***/ (function(module, exports, __webpack_require__) {
  14666. const {
  14667. noopTest,
  14668. edit,
  14669. merge
  14670. } = __webpack_require__("322c");
  14671. /**
  14672. * Block-Level Grammar
  14673. */
  14674. const block = {
  14675. newline: /^\n+/,
  14676. code: /^( {4}[^\n]+\n*)+/,
  14677. fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
  14678. hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
  14679. heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
  14680. blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
  14681. list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
  14682. html: '^ {0,3}(?:' // optional indentation
  14683. + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
  14684. + '|comment[^\\n]*(\\n+|$)' // (2)
  14685. + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
  14686. + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
  14687. + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
  14688. + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
  14689. + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
  14690. + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
  14691. + ')',
  14692. def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
  14693. nptable: noopTest,
  14694. table: noopTest,
  14695. lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
  14696. // regex template, placeholders will be replaced according to different paragraph
  14697. // interruption rules of commonmark and the original markdown spec:
  14698. _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
  14699. text: /^[^\n]+/
  14700. };
  14701. block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
  14702. block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
  14703. block.def = edit(block.def)
  14704. .replace('label', block._label)
  14705. .replace('title', block._title)
  14706. .getRegex();
  14707. block.bullet = /(?:[*+-]|\d{1,9}\.)/;
  14708. block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
  14709. block.item = edit(block.item, 'gm')
  14710. .replace(/bull/g, block.bullet)
  14711. .getRegex();
  14712. block.list = edit(block.list)
  14713. .replace(/bull/g, block.bullet)
  14714. .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
  14715. .replace('def', '\\n+(?=' + block.def.source + ')')
  14716. .getRegex();
  14717. block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
  14718. + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
  14719. + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
  14720. + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
  14721. + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
  14722. + '|track|ul';
  14723. block._comment = /<!--(?!-?>)[\s\S]*?-->/;
  14724. block.html = edit(block.html, 'i')
  14725. .replace('comment', block._comment)
  14726. .replace('tag', block._tag)
  14727. .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
  14728. .getRegex();
  14729. block.paragraph = edit(block._paragraph)
  14730. .replace('hr', block.hr)
  14731. .replace('heading', ' {0,3}#{1,6} ')
  14732. .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
  14733. .replace('blockquote', ' {0,3}>')
  14734. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  14735. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  14736. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  14737. .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
  14738. .getRegex();
  14739. block.blockquote = edit(block.blockquote)
  14740. .replace('paragraph', block.paragraph)
  14741. .getRegex();
  14742. /**
  14743. * Normal Block Grammar
  14744. */
  14745. block.normal = merge({}, block);
  14746. /**
  14747. * GFM Block Grammar
  14748. */
  14749. block.gfm = merge({}, block.normal, {
  14750. nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
  14751. + ' *([-:]+ *\\|[-| :]*)' // Align
  14752. + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells
  14753. table: '^ *\\|(.+)\\n' // Header
  14754. + ' *\\|?( *[-:]+[-| :]*)' // Align
  14755. + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
  14756. });
  14757. block.gfm.nptable = edit(block.gfm.nptable)
  14758. .replace('hr', block.hr)
  14759. .replace('heading', ' {0,3}#{1,6} ')
  14760. .replace('blockquote', ' {0,3}>')
  14761. .replace('code', ' {4}[^\\n]')
  14762. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  14763. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  14764. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  14765. .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
  14766. .getRegex();
  14767. block.gfm.table = edit(block.gfm.table)
  14768. .replace('hr', block.hr)
  14769. .replace('heading', ' {0,3}#{1,6} ')
  14770. .replace('blockquote', ' {0,3}>')
  14771. .replace('code', ' {4}[^\\n]')
  14772. .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
  14773. .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
  14774. .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
  14775. .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
  14776. .getRegex();
  14777. /**
  14778. * Pedantic grammar (original John Gruber's loose markdown specification)
  14779. */
  14780. block.pedantic = merge({}, block.normal, {
  14781. html: edit(
  14782. '^ *(?:comment *(?:\\n|\\s*$)'
  14783. + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
  14784. + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
  14785. .replace('comment', block._comment)
  14786. .replace(/tag/g, '(?!(?:'
  14787. + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
  14788. + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
  14789. + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
  14790. .getRegex(),
  14791. def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
  14792. heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
  14793. fences: noopTest, // fences not supported
  14794. paragraph: edit(block.normal._paragraph)
  14795. .replace('hr', block.hr)
  14796. .replace('heading', ' *#{1,6} *[^\n]')
  14797. .replace('lheading', block.lheading)
  14798. .replace('blockquote', ' {0,3}>')
  14799. .replace('|fences', '')
  14800. .replace('|list', '')
  14801. .replace('|html', '')
  14802. .getRegex()
  14803. });
  14804. /**
  14805. * Inline-Level Grammar
  14806. */
  14807. const inline = {
  14808. escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
  14809. autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
  14810. url: noopTest,
  14811. tag: '^comment'
  14812. + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
  14813. + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
  14814. + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
  14815. + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
  14816. + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
  14817. link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
  14818. reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
  14819. nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
  14820. strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
  14821. em: /^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,
  14822. code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  14823. br: /^( {2,}|\\)\n(?!\s*$)/,
  14824. del: noopTest,
  14825. text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
  14826. };
  14827. // list of punctuation marks from common mark spec
  14828. // without ` and ] to workaround Rule 17 (inline code blocks/links)
  14829. inline._punctuation = '!"#$%&\'()*+\\-./:;<=>?@\\[^_{|}~';
  14830. inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
  14831. inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
  14832. inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
  14833. 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])?)+(?![-_])/;
  14834. inline.autolink = edit(inline.autolink)
  14835. .replace('scheme', inline._scheme)
  14836. .replace('email', inline._email)
  14837. .getRegex();
  14838. inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
  14839. inline.tag = edit(inline.tag)
  14840. .replace('comment', block._comment)
  14841. .replace('attribute', inline._attribute)
  14842. .getRegex();
  14843. inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
  14844. inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
  14845. inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
  14846. inline.link = edit(inline.link)
  14847. .replace('label', inline._label)
  14848. .replace('href', inline._href)
  14849. .replace('title', inline._title)
  14850. .getRegex();
  14851. inline.reflink = edit(inline.reflink)
  14852. .replace('label', inline._label)
  14853. .getRegex();
  14854. /**
  14855. * Normal Inline Grammar
  14856. */
  14857. inline.normal = merge({}, inline);
  14858. /**
  14859. * Pedantic Inline Grammar
  14860. */
  14861. inline.pedantic = merge({}, inline.normal, {
  14862. strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  14863. em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
  14864. link: edit(/^!?\[(label)\]\((.*?)\)/)
  14865. .replace('label', inline._label)
  14866. .getRegex(),
  14867. reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
  14868. .replace('label', inline._label)
  14869. .getRegex()
  14870. });
  14871. /**
  14872. * GFM Inline Grammar
  14873. */
  14874. inline.gfm = merge({}, inline.normal, {
  14875. escape: edit(inline.escape).replace('])', '~|])').getRegex(),
  14876. _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
  14877. url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
  14878. _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
  14879. del: /^~+(?=\S)([\s\S]*?\S)~+/,
  14880. text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
  14881. });
  14882. inline.gfm.url = edit(inline.gfm.url, 'i')
  14883. .replace('email', inline.gfm._extended_email)
  14884. .getRegex();
  14885. /**
  14886. * GFM + Line Breaks Inline Grammar
  14887. */
  14888. inline.breaks = merge({}, inline.gfm, {
  14889. br: edit(inline.br).replace('{2,}', '*').getRegex(),
  14890. text: edit(inline.gfm.text)
  14891. .replace('\\b_', '\\b_| {2,}\\n')
  14892. .replace(/\{2,\}/g, '*')
  14893. .getRegex()
  14894. });
  14895. module.exports = {
  14896. block,
  14897. inline
  14898. };
  14899. /***/ }),
  14900. /***/ "ae25":
  14901. /***/ (function(module, exports, __webpack_require__) {
  14902. var global = __webpack_require__("d890");
  14903. var isObject = __webpack_require__("a719");
  14904. var document = global.document;
  14905. // typeof document.createElement is 'object' in old IE
  14906. var EXISTS = isObject(document) && isObject(document.createElement);
  14907. module.exports = function (it) {
  14908. return EXISTS ? document.createElement(it) : {};
  14909. };
  14910. /***/ }),
  14911. /***/ "b2e0":
  14912. /***/ (function(module, exports, __webpack_require__) {
  14913. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  14914. // Distributed under an MIT license: https://codemirror.net/LICENSE
  14915. (function(mod) {
  14916. if (true) // CommonJS
  14917. mod(__webpack_require__("a564"));
  14918. else {}
  14919. })(function(CodeMirror) {
  14920. "use strict";
  14921. var htmlConfig = {
  14922. autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
  14923. 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
  14924. 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
  14925. 'track': true, 'wbr': true, 'menuitem': true},
  14926. implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
  14927. 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
  14928. 'th': true, 'tr': true},
  14929. contextGrabbers: {
  14930. 'dd': {'dd': true, 'dt': true},
  14931. 'dt': {'dd': true, 'dt': true},
  14932. 'li': {'li': true},
  14933. 'option': {'option': true, 'optgroup': true},
  14934. 'optgroup': {'optgroup': true},
  14935. 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
  14936. 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
  14937. 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
  14938. 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
  14939. 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
  14940. 'rp': {'rp': true, 'rt': true},
  14941. 'rt': {'rp': true, 'rt': true},
  14942. 'tbody': {'tbody': true, 'tfoot': true},
  14943. 'td': {'td': true, 'th': true},
  14944. 'tfoot': {'tbody': true},
  14945. 'th': {'td': true, 'th': true},
  14946. 'thead': {'tbody': true, 'tfoot': true},
  14947. 'tr': {'tr': true}
  14948. },
  14949. doNotIndent: {"pre": true},
  14950. allowUnquoted: true,
  14951. allowMissing: true,
  14952. caseFold: true
  14953. }
  14954. var xmlConfig = {
  14955. autoSelfClosers: {},
  14956. implicitlyClosed: {},
  14957. contextGrabbers: {},
  14958. doNotIndent: {},
  14959. allowUnquoted: false,
  14960. allowMissing: false,
  14961. allowMissingTagName: false,
  14962. caseFold: false
  14963. }
  14964. CodeMirror.defineMode("xml", function(editorConf, config_) {
  14965. var indentUnit = editorConf.indentUnit
  14966. var config = {}
  14967. var defaults = config_.htmlMode ? htmlConfig : xmlConfig
  14968. for (var prop in defaults) config[prop] = defaults[prop]
  14969. for (var prop in config_) config[prop] = config_[prop]
  14970. // Return variables for tokenizers
  14971. var type, setStyle;
  14972. function inText(stream, state) {
  14973. function chain(parser) {
  14974. state.tokenize = parser;
  14975. return parser(stream, state);
  14976. }
  14977. var ch = stream.next();
  14978. if (ch == "<") {
  14979. if (stream.eat("!")) {
  14980. if (stream.eat("[")) {
  14981. if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
  14982. else return null;
  14983. } else if (stream.match("--")) {
  14984. return chain(inBlock("comment", "-->"));
  14985. } else if (stream.match("DOCTYPE", true, true)) {
  14986. stream.eatWhile(/[\w\._\-]/);
  14987. return chain(doctype(1));
  14988. } else {
  14989. return null;
  14990. }
  14991. } else if (stream.eat("?")) {
  14992. stream.eatWhile(/[\w\._\-]/);
  14993. state.tokenize = inBlock("meta", "?>");
  14994. return "meta";
  14995. } else {
  14996. type = stream.eat("/") ? "closeTag" : "openTag";
  14997. state.tokenize = inTag;
  14998. return "tag bracket";
  14999. }
  15000. } else if (ch == "&") {
  15001. var ok;
  15002. if (stream.eat("#")) {
  15003. if (stream.eat("x")) {
  15004. ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
  15005. } else {
  15006. ok = stream.eatWhile(/[\d]/) && stream.eat(";");
  15007. }
  15008. } else {
  15009. ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
  15010. }
  15011. return ok ? "atom" : "error";
  15012. } else {
  15013. stream.eatWhile(/[^&<]/);
  15014. return null;
  15015. }
  15016. }
  15017. inText.isInText = true;
  15018. function inTag(stream, state) {
  15019. var ch = stream.next();
  15020. if (ch == ">" || (ch == "/" && stream.eat(">"))) {
  15021. state.tokenize = inText;
  15022. type = ch == ">" ? "endTag" : "selfcloseTag";
  15023. return "tag bracket";
  15024. } else if (ch == "=") {
  15025. type = "equals";
  15026. return null;
  15027. } else if (ch == "<") {
  15028. state.tokenize = inText;
  15029. state.state = baseState;
  15030. state.tagName = state.tagStart = null;
  15031. var next = state.tokenize(stream, state);
  15032. return next ? next + " tag error" : "tag error";
  15033. } else if (/[\'\"]/.test(ch)) {
  15034. state.tokenize = inAttribute(ch);
  15035. state.stringStartCol = stream.column();
  15036. return state.tokenize(stream, state);
  15037. } else {
  15038. stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
  15039. return "word";
  15040. }
  15041. }
  15042. function inAttribute(quote) {
  15043. var closure = function(stream, state) {
  15044. while (!stream.eol()) {
  15045. if (stream.next() == quote) {
  15046. state.tokenize = inTag;
  15047. break;
  15048. }
  15049. }
  15050. return "string";
  15051. };
  15052. closure.isInAttribute = true;
  15053. return closure;
  15054. }
  15055. function inBlock(style, terminator) {
  15056. return function(stream, state) {
  15057. while (!stream.eol()) {
  15058. if (stream.match(terminator)) {
  15059. state.tokenize = inText;
  15060. break;
  15061. }
  15062. stream.next();
  15063. }
  15064. return style;
  15065. }
  15066. }
  15067. function doctype(depth) {
  15068. return function(stream, state) {
  15069. var ch;
  15070. while ((ch = stream.next()) != null) {
  15071. if (ch == "<") {
  15072. state.tokenize = doctype(depth + 1);
  15073. return state.tokenize(stream, state);
  15074. } else if (ch == ">") {
  15075. if (depth == 1) {
  15076. state.tokenize = inText;
  15077. break;
  15078. } else {
  15079. state.tokenize = doctype(depth - 1);
  15080. return state.tokenize(stream, state);
  15081. }
  15082. }
  15083. }
  15084. return "meta";
  15085. };
  15086. }
  15087. function Context(state, tagName, startOfLine) {
  15088. this.prev = state.context;
  15089. this.tagName = tagName;
  15090. this.indent = state.indented;
  15091. this.startOfLine = startOfLine;
  15092. if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
  15093. this.noIndent = true;
  15094. }
  15095. function popContext(state) {
  15096. if (state.context) state.context = state.context.prev;
  15097. }
  15098. function maybePopContext(state, nextTagName) {
  15099. var parentTagName;
  15100. while (true) {
  15101. if (!state.context) {
  15102. return;
  15103. }
  15104. parentTagName = state.context.tagName;
  15105. if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
  15106. !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
  15107. return;
  15108. }
  15109. popContext(state);
  15110. }
  15111. }
  15112. function baseState(type, stream, state) {
  15113. if (type == "openTag") {
  15114. state.tagStart = stream.column();
  15115. return tagNameState;
  15116. } else if (type == "closeTag") {
  15117. return closeTagNameState;
  15118. } else {
  15119. return baseState;
  15120. }
  15121. }
  15122. function tagNameState(type, stream, state) {
  15123. if (type == "word") {
  15124. state.tagName = stream.current();
  15125. setStyle = "tag";
  15126. return attrState;
  15127. } else if (config.allowMissingTagName && type == "endTag") {
  15128. setStyle = "tag bracket";
  15129. return attrState(type, stream, state);
  15130. } else {
  15131. setStyle = "error";
  15132. return tagNameState;
  15133. }
  15134. }
  15135. function closeTagNameState(type, stream, state) {
  15136. if (type == "word") {
  15137. var tagName = stream.current();
  15138. if (state.context && state.context.tagName != tagName &&
  15139. config.implicitlyClosed.hasOwnProperty(state.context.tagName))
  15140. popContext(state);
  15141. if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
  15142. setStyle = "tag";
  15143. return closeState;
  15144. } else {
  15145. setStyle = "tag error";
  15146. return closeStateErr;
  15147. }
  15148. } else if (config.allowMissingTagName && type == "endTag") {
  15149. setStyle = "tag bracket";
  15150. return closeState(type, stream, state);
  15151. } else {
  15152. setStyle = "error";
  15153. return closeStateErr;
  15154. }
  15155. }
  15156. function closeState(type, _stream, state) {
  15157. if (type != "endTag") {
  15158. setStyle = "error";
  15159. return closeState;
  15160. }
  15161. popContext(state);
  15162. return baseState;
  15163. }
  15164. function closeStateErr(type, stream, state) {
  15165. setStyle = "error";
  15166. return closeState(type, stream, state);
  15167. }
  15168. function attrState(type, _stream, state) {
  15169. if (type == "word") {
  15170. setStyle = "attribute";
  15171. return attrEqState;
  15172. } else if (type == "endTag" || type == "selfcloseTag") {
  15173. var tagName = state.tagName, tagStart = state.tagStart;
  15174. state.tagName = state.tagStart = null;
  15175. if (type == "selfcloseTag" ||
  15176. config.autoSelfClosers.hasOwnProperty(tagName)) {
  15177. maybePopContext(state, tagName);
  15178. } else {
  15179. maybePopContext(state, tagName);
  15180. state.context = new Context(state, tagName, tagStart == state.indented);
  15181. }
  15182. return baseState;
  15183. }
  15184. setStyle = "error";
  15185. return attrState;
  15186. }
  15187. function attrEqState(type, stream, state) {
  15188. if (type == "equals") return attrValueState;
  15189. if (!config.allowMissing) setStyle = "error";
  15190. return attrState(type, stream, state);
  15191. }
  15192. function attrValueState(type, stream, state) {
  15193. if (type == "string") return attrContinuedState;
  15194. if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
  15195. setStyle = "error";
  15196. return attrState(type, stream, state);
  15197. }
  15198. function attrContinuedState(type, stream, state) {
  15199. if (type == "string") return attrContinuedState;
  15200. return attrState(type, stream, state);
  15201. }
  15202. return {
  15203. startState: function(baseIndent) {
  15204. var state = {tokenize: inText,
  15205. state: baseState,
  15206. indented: baseIndent || 0,
  15207. tagName: null, tagStart: null,
  15208. context: null}
  15209. if (baseIndent != null) state.baseIndent = baseIndent
  15210. return state
  15211. },
  15212. token: function(stream, state) {
  15213. if (!state.tagName && stream.sol())
  15214. state.indented = stream.indentation();
  15215. if (stream.eatSpace()) return null;
  15216. type = null;
  15217. var style = state.tokenize(stream, state);
  15218. if ((style || type) && style != "comment") {
  15219. setStyle = null;
  15220. state.state = state.state(type || style, stream, state);
  15221. if (setStyle)
  15222. style = setStyle == "error" ? style + " error" : setStyle;
  15223. }
  15224. return style;
  15225. },
  15226. indent: function(state, textAfter, fullLine) {
  15227. var context = state.context;
  15228. // Indent multi-line strings (e.g. css).
  15229. if (state.tokenize.isInAttribute) {
  15230. if (state.tagStart == state.indented)
  15231. return state.stringStartCol + 1;
  15232. else
  15233. return state.indented + indentUnit;
  15234. }
  15235. if (context && context.noIndent) return CodeMirror.Pass;
  15236. if (state.tokenize != inTag && state.tokenize != inText)
  15237. return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
  15238. // Indent the starts of attribute names.
  15239. if (state.tagName) {
  15240. if (config.multilineTagIndentPastTag !== false)
  15241. return state.tagStart + state.tagName.length + 2;
  15242. else
  15243. return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
  15244. }
  15245. if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
  15246. var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
  15247. if (tagAfter && tagAfter[1]) { // Closing tag spotted
  15248. while (context) {
  15249. if (context.tagName == tagAfter[2]) {
  15250. context = context.prev;
  15251. break;
  15252. } else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
  15253. context = context.prev;
  15254. } else {
  15255. break;
  15256. }
  15257. }
  15258. } else if (tagAfter) { // Opening tag spotted
  15259. while (context) {
  15260. var grabbers = config.contextGrabbers[context.tagName];
  15261. if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
  15262. context = context.prev;
  15263. else
  15264. break;
  15265. }
  15266. }
  15267. while (context && context.prev && !context.startOfLine)
  15268. context = context.prev;
  15269. if (context) return context.indent + indentUnit;
  15270. else return state.baseIndent || 0;
  15271. },
  15272. electricInput: /<\/[\s\w:]+>$/,
  15273. blockCommentStart: "<!--",
  15274. blockCommentEnd: "-->",
  15275. configuration: config.htmlMode ? "html" : "xml",
  15276. helperType: config.htmlMode ? "html" : "xml",
  15277. skipAttribute: function(state) {
  15278. if (state.state == attrValueState)
  15279. state.state = attrState
  15280. },
  15281. xmlCurrentTag: function(state) {
  15282. return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null
  15283. },
  15284. xmlCurrentContext: function(state) {
  15285. var context = []
  15286. for (var cx = state.context; cx; cx = cx.prev)
  15287. if (cx.tagName) context.push(cx.tagName)
  15288. return context.reverse()
  15289. }
  15290. };
  15291. });
  15292. CodeMirror.defineMIME("text/xml", "xml");
  15293. CodeMirror.defineMIME("application/xml", "xml");
  15294. if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
  15295. CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
  15296. });
  15297. /***/ }),
  15298. /***/ "b338":
  15299. /***/ (function(module, exports, __webpack_require__) {
  15300. var internalObjectKeys = __webpack_require__("ead4");
  15301. var enumBugKeys = __webpack_require__("18f6");
  15302. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  15303. // `Object.getOwnPropertyNames` method
  15304. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  15305. exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  15306. return internalObjectKeys(O, hiddenKeys);
  15307. };
  15308. /***/ }),
  15309. /***/ "b702":
  15310. /***/ (function(module, exports, __webpack_require__) {
  15311. var NATIVE_WEAK_MAP = __webpack_require__("604f");
  15312. var global = __webpack_require__("d890");
  15313. var isObject = __webpack_require__("a719");
  15314. var createNonEnumerableProperty = __webpack_require__("0fc1");
  15315. var objectHas = __webpack_require__("faa8");
  15316. var sharedKey = __webpack_require__("7db2");
  15317. var hiddenKeys = __webpack_require__("d5a8");
  15318. var WeakMap = global.WeakMap;
  15319. var set, get, has;
  15320. var enforce = function (it) {
  15321. return has(it) ? get(it) : set(it, {});
  15322. };
  15323. var getterFor = function (TYPE) {
  15324. return function (it) {
  15325. var state;
  15326. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  15327. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  15328. } return state;
  15329. };
  15330. };
  15331. if (NATIVE_WEAK_MAP) {
  15332. var store = new WeakMap();
  15333. var wmget = store.get;
  15334. var wmhas = store.has;
  15335. var wmset = store.set;
  15336. set = function (it, metadata) {
  15337. wmset.call(store, it, metadata);
  15338. return metadata;
  15339. };
  15340. get = function (it) {
  15341. return wmget.call(store, it) || {};
  15342. };
  15343. has = function (it) {
  15344. return wmhas.call(store, it);
  15345. };
  15346. } else {
  15347. var STATE = sharedKey('state');
  15348. hiddenKeys[STATE] = true;
  15349. set = function (it, metadata) {
  15350. createNonEnumerableProperty(it, STATE, metadata);
  15351. return metadata;
  15352. };
  15353. get = function (it) {
  15354. return objectHas(it, STATE) ? it[STATE] : {};
  15355. };
  15356. has = function (it) {
  15357. return objectHas(it, STATE);
  15358. };
  15359. }
  15360. module.exports = {
  15361. set: set,
  15362. get: get,
  15363. has: has,
  15364. enforce: enforce,
  15365. getterFor: getterFor
  15366. };
  15367. /***/ }),
  15368. /***/ "b73f":
  15369. /***/ (function(module, exports, __webpack_require__) {
  15370. var $ = __webpack_require__("1c8b");
  15371. var fails = __webpack_require__("efe2");
  15372. var toIndexedObject = __webpack_require__("da10");
  15373. var nativeGetOwnPropertyDescriptor = __webpack_require__("aa6b").f;
  15374. var DESCRIPTORS = __webpack_require__("1e2c");
  15375. var FAILS_ON_PRIMITIVES = fails(function () { nativeGetOwnPropertyDescriptor(1); });
  15376. var FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES;
  15377. // `Object.getOwnPropertyDescriptor` method
  15378. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
  15379. $({ target: 'Object', stat: true, forced: FORCED, sham: !DESCRIPTORS }, {
  15380. getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {
  15381. return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);
  15382. }
  15383. });
  15384. /***/ }),
  15385. /***/ "bf84":
  15386. /***/ (function(module, exports, __webpack_require__) {
  15387. var $ = __webpack_require__("1c8b");
  15388. var DESCRIPTORS = __webpack_require__("1e2c");
  15389. var ownKeys = __webpack_require__("8d44");
  15390. var toIndexedObject = __webpack_require__("da10");
  15391. var getOwnPropertyDescriptorModule = __webpack_require__("aa6b");
  15392. var createProperty = __webpack_require__("1bbd");
  15393. // `Object.getOwnPropertyDescriptors` method
  15394. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
  15395. $({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {
  15396. getOwnPropertyDescriptors: function getOwnPropertyDescriptors(object) {
  15397. var O = toIndexedObject(object);
  15398. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  15399. var keys = ownKeys(O);
  15400. var result = {};
  15401. var index = 0;
  15402. var key, descriptor;
  15403. while (keys.length > index) {
  15404. descriptor = getOwnPropertyDescriptor(O, key = keys[index++]);
  15405. if (descriptor !== undefined) createProperty(result, key, descriptor);
  15406. }
  15407. return result;
  15408. }
  15409. });
  15410. /***/ }),
  15411. /***/ "c051":
  15412. /***/ (function(module, exports, __webpack_require__) {
  15413. var toIndexedObject = __webpack_require__("da10");
  15414. var nativeGetOwnPropertyNames = __webpack_require__("b338").f;
  15415. var toString = {}.toString;
  15416. var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames
  15417. ? Object.getOwnPropertyNames(window) : [];
  15418. var getWindowNames = function (it) {
  15419. try {
  15420. return nativeGetOwnPropertyNames(it);
  15421. } catch (error) {
  15422. return windowNames.slice();
  15423. }
  15424. };
  15425. // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
  15426. module.exports.f = function getOwnPropertyNames(it) {
  15427. return windowNames && toString.call(it) == '[object Window]'
  15428. ? getWindowNames(it)
  15429. : nativeGetOwnPropertyNames(toIndexedObject(it));
  15430. };
  15431. /***/ }),
  15432. /***/ "c54b":
  15433. /***/ (function(module, exports, __webpack_require__) {
  15434. var fails = __webpack_require__("efe2");
  15435. module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
  15436. // Chrome 38 Symbol has incorrect toString conversion
  15437. // eslint-disable-next-line no-undef
  15438. return !String(Symbol());
  15439. });
  15440. /***/ }),
  15441. /***/ "c59c":
  15442. /***/ (function(module, exports, __webpack_require__) {
  15443. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// addapted from the document.currentScript polyfill by Adam Miller
  15444. // MIT license
  15445. // source: https://github.com/amiller-gh/currentScript-polyfill
  15446. // added support for Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1620505
  15447. (function (root, factory) {
  15448. if (true) {
  15449. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  15450. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  15451. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  15452. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  15453. } else {}
  15454. }(typeof self !== 'undefined' ? self : this, function () {
  15455. function getCurrentScript () {
  15456. if (document.currentScript) {
  15457. return document.currentScript
  15458. }
  15459. // IE 8-10 support script readyState
  15460. // IE 11+ & Firefox support stack trace
  15461. try {
  15462. throw new Error();
  15463. }
  15464. catch (err) {
  15465. // Find the second match for the "at" string to get file src url from stack.
  15466. var ieStackRegExp = /.*at [^(]*\((.*):(.+):(.+)\)$/ig,
  15467. ffStackRegExp = /@([^@]*):(\d+):(\d+)\s*$/ig,
  15468. stackDetails = ieStackRegExp.exec(err.stack) || ffStackRegExp.exec(err.stack),
  15469. scriptLocation = (stackDetails && stackDetails[1]) || false,
  15470. line = (stackDetails && stackDetails[2]) || false,
  15471. currentLocation = document.location.href.replace(document.location.hash, ''),
  15472. pageSource,
  15473. inlineScriptSourceRegExp,
  15474. inlineScriptSource,
  15475. scripts = document.getElementsByTagName('script'); // Live NodeList collection
  15476. if (scriptLocation === currentLocation) {
  15477. pageSource = document.documentElement.outerHTML;
  15478. inlineScriptSourceRegExp = new RegExp('(?:[^\\n]+?\\n){0,' + (line - 2) + '}[^<]*<script>([\\d\\D]*?)<\\/script>[\\d\\D]*', 'i');
  15479. inlineScriptSource = pageSource.replace(inlineScriptSourceRegExp, '$1').trim();
  15480. }
  15481. for (var i = 0; i < scripts.length; i++) {
  15482. // If ready state is interactive, return the script tag
  15483. if (scripts[i].readyState === 'interactive') {
  15484. return scripts[i];
  15485. }
  15486. // If src matches, return the script tag
  15487. if (scripts[i].src === scriptLocation) {
  15488. return scripts[i];
  15489. }
  15490. // If inline source matches, return the script tag
  15491. if (
  15492. scriptLocation === currentLocation &&
  15493. scripts[i].innerHTML &&
  15494. scripts[i].innerHTML.trim() === inlineScriptSource
  15495. ) {
  15496. return scripts[i];
  15497. }
  15498. }
  15499. // If no match, return null
  15500. return null;
  15501. }
  15502. };
  15503. return getCurrentScript
  15504. }));
  15505. /***/ }),
  15506. /***/ "c69d":
  15507. /***/ (function(module, exports, __webpack_require__) {
  15508. var has = __webpack_require__("faa8");
  15509. var ownKeys = __webpack_require__("8d44");
  15510. var getOwnPropertyDescriptorModule = __webpack_require__("aa6b");
  15511. var definePropertyModule = __webpack_require__("d910");
  15512. module.exports = function (target, source) {
  15513. var keys = ownKeys(source);
  15514. var defineProperty = definePropertyModule.f;
  15515. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  15516. for (var i = 0; i < keys.length; i++) {
  15517. var key = keys[i];
  15518. if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  15519. }
  15520. };
  15521. /***/ }),
  15522. /***/ "cbab":
  15523. /***/ (function(module, exports, __webpack_require__) {
  15524. var internalObjectKeys = __webpack_require__("ead4");
  15525. var enumBugKeys = __webpack_require__("18f6");
  15526. // `Object.keys` method
  15527. // https://tc39.github.io/ecma262/#sec-object.keys
  15528. module.exports = Object.keys || function keys(O) {
  15529. return internalObjectKeys(O, enumBugKeys);
  15530. };
  15531. /***/ }),
  15532. /***/ "ccf5":
  15533. /***/ (function(module, exports, __webpack_require__) {
  15534. // extracted by mini-css-extract-plugin
  15535. /***/ }),
  15536. /***/ "d5a8":
  15537. /***/ (function(module, exports) {
  15538. module.exports = {};
  15539. /***/ }),
  15540. /***/ "d776":
  15541. /***/ (function(module, exports, __webpack_require__) {
  15542. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  15543. // Distributed under an MIT license: https://codemirror.net/LICENSE
  15544. // Utility function that allows modes to be combined. The mode given
  15545. // as the base argument takes care of most of the normal mode
  15546. // functionality, but a second (typically simple) mode is used, which
  15547. // can override the style of text. Both modes get to parse all of the
  15548. // text, but when both assign a non-null style to a piece of code, the
  15549. // overlay wins, unless the combine argument was true and not overridden,
  15550. // or state.overlay.combineTokens was true, in which case the styles are
  15551. // combined.
  15552. (function(mod) {
  15553. if (true) // CommonJS
  15554. mod(__webpack_require__("a564"));
  15555. else {}
  15556. })(function(CodeMirror) {
  15557. "use strict";
  15558. CodeMirror.overlayMode = function(base, overlay, combine) {
  15559. return {
  15560. startState: function() {
  15561. return {
  15562. base: CodeMirror.startState(base),
  15563. overlay: CodeMirror.startState(overlay),
  15564. basePos: 0, baseCur: null,
  15565. overlayPos: 0, overlayCur: null,
  15566. streamSeen: null
  15567. };
  15568. },
  15569. copyState: function(state) {
  15570. return {
  15571. base: CodeMirror.copyState(base, state.base),
  15572. overlay: CodeMirror.copyState(overlay, state.overlay),
  15573. basePos: state.basePos, baseCur: null,
  15574. overlayPos: state.overlayPos, overlayCur: null
  15575. };
  15576. },
  15577. token: function(stream, state) {
  15578. if (stream != state.streamSeen ||
  15579. Math.min(state.basePos, state.overlayPos) < stream.start) {
  15580. state.streamSeen = stream;
  15581. state.basePos = state.overlayPos = stream.start;
  15582. }
  15583. if (stream.start == state.basePos) {
  15584. state.baseCur = base.token(stream, state.base);
  15585. state.basePos = stream.pos;
  15586. }
  15587. if (stream.start == state.overlayPos) {
  15588. stream.pos = stream.start;
  15589. state.overlayCur = overlay.token(stream, state.overlay);
  15590. state.overlayPos = stream.pos;
  15591. }
  15592. stream.pos = Math.min(state.basePos, state.overlayPos);
  15593. // state.overlay.combineTokens always takes precedence over combine,
  15594. // unless set to null
  15595. if (state.overlayCur == null) return state.baseCur;
  15596. else if (state.baseCur != null &&
  15597. state.overlay.combineTokens ||
  15598. combine && state.overlay.combineTokens == null)
  15599. return state.baseCur + " " + state.overlayCur;
  15600. else return state.overlayCur;
  15601. },
  15602. indent: base.indent && function(state, textAfter, line) {
  15603. return base.indent(state.base, textAfter, line);
  15604. },
  15605. electricChars: base.electricChars,
  15606. innerMode: function(state) { return {state: state.base, mode: base}; },
  15607. blankLine: function(state) {
  15608. var baseToken, overlayToken;
  15609. if (base.blankLine) baseToken = base.blankLine(state.base);
  15610. if (overlay.blankLine) overlayToken = overlay.blankLine(state.overlay);
  15611. return overlayToken == null ?
  15612. baseToken :
  15613. (combine && baseToken != null ? baseToken + " " + overlayToken : overlayToken);
  15614. }
  15615. };
  15616. };
  15617. });
  15618. /***/ }),
  15619. /***/ "d7e1":
  15620. /***/ (function(module, exports, __webpack_require__) {
  15621. "use strict";
  15622. var fails = __webpack_require__("efe2");
  15623. module.exports = function (METHOD_NAME, argument) {
  15624. var method = [][METHOD_NAME];
  15625. return !!method && fails(function () {
  15626. // eslint-disable-next-line no-useless-call,no-throw-literal
  15627. method.call(null, argument || function () { throw 1; }, 1);
  15628. });
  15629. };
  15630. /***/ }),
  15631. /***/ "d88d":
  15632. /***/ (function(module, exports, __webpack_require__) {
  15633. var toInteger = __webpack_require__("3da3");
  15634. var min = Math.min;
  15635. // `ToLength` abstract operation
  15636. // https://tc39.github.io/ecma262/#sec-tolength
  15637. module.exports = function (argument) {
  15638. return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  15639. };
  15640. /***/ }),
  15641. /***/ "d890":
  15642. /***/ (function(module, exports, __webpack_require__) {
  15643. /* WEBPACK VAR INJECTION */(function(global) {var check = function (it) {
  15644. return it && it.Math == Math && it;
  15645. };
  15646. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  15647. module.exports =
  15648. // eslint-disable-next-line no-undef
  15649. check(typeof globalThis == 'object' && globalThis) ||
  15650. check(typeof window == 'object' && window) ||
  15651. check(typeof self == 'object' && self) ||
  15652. check(typeof global == 'object' && global) ||
  15653. // eslint-disable-next-line no-new-func
  15654. Function('return this')();
  15655. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("9edd")))
  15656. /***/ }),
  15657. /***/ "d910":
  15658. /***/ (function(module, exports, __webpack_require__) {
  15659. var DESCRIPTORS = __webpack_require__("1e2c");
  15660. var IE8_DOM_DEFINE = __webpack_require__("2039");
  15661. var anObject = __webpack_require__("857c");
  15662. var toPrimitive = __webpack_require__("9f67");
  15663. var nativeDefineProperty = Object.defineProperty;
  15664. // `Object.defineProperty` method
  15665. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  15666. exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
  15667. anObject(O);
  15668. P = toPrimitive(P, true);
  15669. anObject(Attributes);
  15670. if (IE8_DOM_DEFINE) try {
  15671. return nativeDefineProperty(O, P, Attributes);
  15672. } catch (error) { /* empty */ }
  15673. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  15674. if ('value' in Attributes) O[P] = Attributes.value;
  15675. return O;
  15676. };
  15677. /***/ }),
  15678. /***/ "da10":
  15679. /***/ (function(module, exports, __webpack_require__) {
  15680. // toObject with fallback for non-array-like ES3 strings
  15681. var IndexedObject = __webpack_require__("692f");
  15682. var requireObjectCoercible = __webpack_require__("2732");
  15683. module.exports = function (it) {
  15684. return IndexedObject(requireObjectCoercible(it));
  15685. };
  15686. /***/ }),
  15687. /***/ "dbb3":
  15688. /***/ (function(module, exports, __webpack_require__) {
  15689. "use strict";
  15690. var $ = __webpack_require__("1c8b");
  15691. var $filter = __webpack_require__("5dfd").filter;
  15692. var arrayMethodHasSpeciesSupport = __webpack_require__("1ea7");
  15693. var arrayMethodUsesToLength = __webpack_require__("ff9c");
  15694. var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');
  15695. // Edge 14- issue
  15696. var USES_TO_LENGTH = arrayMethodUsesToLength('filter');
  15697. // `Array.prototype.filter` method
  15698. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  15699. // with adding support of @@species
  15700. $({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH }, {
  15701. filter: function filter(callbackfn /* , thisArg */) {
  15702. return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  15703. }
  15704. });
  15705. /***/ }),
  15706. /***/ "dbe8":
  15707. /***/ (function(module, exports, __webpack_require__) {
  15708. var DESCRIPTORS = __webpack_require__("1e2c");
  15709. var definePropertyModule = __webpack_require__("d910");
  15710. var anObject = __webpack_require__("857c");
  15711. var objectKeys = __webpack_require__("cbab");
  15712. // `Object.defineProperties` method
  15713. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  15714. module.exports = DESCRIPTORS ? Object.defineProperties : function defineProperties(O, Properties) {
  15715. anObject(O);
  15716. var keys = objectKeys(Properties);
  15717. var length = keys.length;
  15718. var index = 0;
  15719. var key;
  15720. while (length > index) definePropertyModule.f(O, key = keys[index++], Properties[key]);
  15721. return O;
  15722. };
  15723. /***/ }),
  15724. /***/ "e1d6":
  15725. /***/ (function(module, exports, __webpack_require__) {
  15726. var toInteger = __webpack_require__("3da3");
  15727. var max = Math.max;
  15728. var min = Math.min;
  15729. // Helper for a popular repeating case of the spec:
  15730. // Let integer be ? ToInteger(index).
  15731. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  15732. module.exports = function (index, length) {
  15733. var integer = toInteger(index);
  15734. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  15735. };
  15736. /***/ }),
  15737. /***/ "e349":
  15738. /***/ (function(module, exports, __webpack_require__) {
  15739. var aFunction = __webpack_require__("0c3c");
  15740. // optional / simple context binding
  15741. module.exports = function (fn, that, length) {
  15742. aFunction(fn);
  15743. if (that === undefined) return fn;
  15744. switch (length) {
  15745. case 0: return function () {
  15746. return fn.call(that);
  15747. };
  15748. case 1: return function (a) {
  15749. return fn.call(that, a);
  15750. };
  15751. case 2: return function (a, b) {
  15752. return fn.call(that, a, b);
  15753. };
  15754. case 3: return function (a, b, c) {
  15755. return fn.call(that, a, b, c);
  15756. };
  15757. }
  15758. return function (/* ...args */) {
  15759. return fn.apply(that, arguments);
  15760. };
  15761. };
  15762. /***/ }),
  15763. /***/ "e4db":
  15764. /***/ (function(module, exports, __webpack_require__) {
  15765. var global = __webpack_require__("d890");
  15766. var createNonEnumerableProperty = __webpack_require__("0fc1");
  15767. module.exports = function (key, value) {
  15768. try {
  15769. createNonEnumerableProperty(global, key, value);
  15770. } catch (error) {
  15771. global[key] = value;
  15772. } return value;
  15773. };
  15774. /***/ }),
  15775. /***/ "e8d6":
  15776. /***/ (function(module, exports, __webpack_require__) {
  15777. var fails = __webpack_require__("efe2");
  15778. var replacement = /#|\.prototype\./;
  15779. var isForced = function (feature, detection) {
  15780. var value = data[normalize(feature)];
  15781. return value == POLYFILL ? true
  15782. : value == NATIVE ? false
  15783. : typeof detection == 'function' ? fails(detection)
  15784. : !!detection;
  15785. };
  15786. var normalize = isForced.normalize = function (string) {
  15787. return String(string).replace(replacement, '.').toLowerCase();
  15788. };
  15789. var data = isForced.data = {};
  15790. var NATIVE = isForced.NATIVE = 'N';
  15791. var POLYFILL = isForced.POLYFILL = 'P';
  15792. module.exports = isForced;
  15793. /***/ }),
  15794. /***/ "ead4":
  15795. /***/ (function(module, exports, __webpack_require__) {
  15796. var has = __webpack_require__("faa8");
  15797. var toIndexedObject = __webpack_require__("da10");
  15798. var indexOf = __webpack_require__("45af").indexOf;
  15799. var hiddenKeys = __webpack_require__("d5a8");
  15800. module.exports = function (object, names) {
  15801. var O = toIndexedObject(object);
  15802. var i = 0;
  15803. var result = [];
  15804. var key;
  15805. for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
  15806. // Don't enum bug & hidden keys
  15807. while (names.length > i) if (has(O, key = names[i++])) {
  15808. ~indexOf(result, key) || result.push(key);
  15809. }
  15810. return result;
  15811. };
  15812. /***/ }),
  15813. /***/ "ef71":
  15814. /***/ (function(module, exports, __webpack_require__) {
  15815. "use strict";
  15816. var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
  15817. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  15818. // Nashorn ~ JDK8 bug
  15819. var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
  15820. // `Object.prototype.propertyIsEnumerable` method implementation
  15821. // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
  15822. exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  15823. var descriptor = getOwnPropertyDescriptor(this, V);
  15824. return !!descriptor && descriptor.enumerable;
  15825. } : nativePropertyIsEnumerable;
  15826. /***/ }),
  15827. /***/ "efe2":
  15828. /***/ (function(module, exports) {
  15829. module.exports = function (exec) {
  15830. try {
  15831. return !!exec();
  15832. } catch (error) {
  15833. return true;
  15834. }
  15835. };
  15836. /***/ }),
  15837. /***/ "f3dd":
  15838. /***/ (function(module, exports, __webpack_require__) {
  15839. "use strict";
  15840. var $ = __webpack_require__("1c8b");
  15841. var global = __webpack_require__("d890");
  15842. var getBuiltIn = __webpack_require__("6d7a");
  15843. var IS_PURE = __webpack_require__("9b9d");
  15844. var DESCRIPTORS = __webpack_require__("1e2c");
  15845. var NATIVE_SYMBOL = __webpack_require__("c54b");
  15846. var USE_SYMBOL_AS_UID = __webpack_require__("74cb");
  15847. var fails = __webpack_require__("efe2");
  15848. var has = __webpack_require__("faa8");
  15849. var isArray = __webpack_require__("74e7");
  15850. var isObject = __webpack_require__("a719");
  15851. var anObject = __webpack_require__("857c");
  15852. var toObject = __webpack_require__("3553");
  15853. var toIndexedObject = __webpack_require__("da10");
  15854. var toPrimitive = __webpack_require__("9f67");
  15855. var createPropertyDescriptor = __webpack_require__("38b9");
  15856. var nativeObjectCreate = __webpack_require__("6d60");
  15857. var objectKeys = __webpack_require__("cbab");
  15858. var getOwnPropertyNamesModule = __webpack_require__("b338");
  15859. var getOwnPropertyNamesExternal = __webpack_require__("c051");
  15860. var getOwnPropertySymbolsModule = __webpack_require__("0a60");
  15861. var getOwnPropertyDescriptorModule = __webpack_require__("aa6b");
  15862. var definePropertyModule = __webpack_require__("d910");
  15863. var propertyIsEnumerableModule = __webpack_require__("ef71");
  15864. var createNonEnumerableProperty = __webpack_require__("0fc1");
  15865. var redefine = __webpack_require__("1944");
  15866. var shared = __webpack_require__("6d28");
  15867. var sharedKey = __webpack_require__("7db2");
  15868. var hiddenKeys = __webpack_require__("d5a8");
  15869. var uid = __webpack_require__("7e8b");
  15870. var wellKnownSymbol = __webpack_require__("90fb");
  15871. var wrappedWellKnownSymbolModule = __webpack_require__("4350");
  15872. var defineWellKnownSymbol = __webpack_require__("6d51");
  15873. var setToStringTag = __webpack_require__("27b5");
  15874. var InternalStateModule = __webpack_require__("b702");
  15875. var $forEach = __webpack_require__("5dfd").forEach;
  15876. var HIDDEN = sharedKey('hidden');
  15877. var SYMBOL = 'Symbol';
  15878. var PROTOTYPE = 'prototype';
  15879. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  15880. var setInternalState = InternalStateModule.set;
  15881. var getInternalState = InternalStateModule.getterFor(SYMBOL);
  15882. var ObjectPrototype = Object[PROTOTYPE];
  15883. var $Symbol = global.Symbol;
  15884. var $stringify = getBuiltIn('JSON', 'stringify');
  15885. var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  15886. var nativeDefineProperty = definePropertyModule.f;
  15887. var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
  15888. var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
  15889. var AllSymbols = shared('symbols');
  15890. var ObjectPrototypeSymbols = shared('op-symbols');
  15891. var StringToSymbolRegistry = shared('string-to-symbol-registry');
  15892. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  15893. var WellKnownSymbolsStore = shared('wks');
  15894. var QObject = global.QObject;
  15895. // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
  15896. var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
  15897. // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
  15898. var setSymbolDescriptor = DESCRIPTORS && fails(function () {
  15899. return nativeObjectCreate(nativeDefineProperty({}, 'a', {
  15900. get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
  15901. })).a != 7;
  15902. }) ? function (O, P, Attributes) {
  15903. var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
  15904. if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
  15905. nativeDefineProperty(O, P, Attributes);
  15906. if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
  15907. nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
  15908. }
  15909. } : nativeDefineProperty;
  15910. var wrap = function (tag, description) {
  15911. var symbol = AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]);
  15912. setInternalState(symbol, {
  15913. type: SYMBOL,
  15914. tag: tag,
  15915. description: description
  15916. });
  15917. if (!DESCRIPTORS) symbol.description = description;
  15918. return symbol;
  15919. };
  15920. var isSymbol = USE_SYMBOL_AS_UID ? function (it) {
  15921. return typeof it == 'symbol';
  15922. } : function (it) {
  15923. return Object(it) instanceof $Symbol;
  15924. };
  15925. var $defineProperty = function defineProperty(O, P, Attributes) {
  15926. if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
  15927. anObject(O);
  15928. var key = toPrimitive(P, true);
  15929. anObject(Attributes);
  15930. if (has(AllSymbols, key)) {
  15931. if (!Attributes.enumerable) {
  15932. if (!has(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
  15933. O[HIDDEN][key] = true;
  15934. } else {
  15935. if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
  15936. Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });
  15937. } return setSymbolDescriptor(O, key, Attributes);
  15938. } return nativeDefineProperty(O, key, Attributes);
  15939. };
  15940. var $defineProperties = function defineProperties(O, Properties) {
  15941. anObject(O);
  15942. var properties = toIndexedObject(Properties);
  15943. var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
  15944. $forEach(keys, function (key) {
  15945. if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]);
  15946. });
  15947. return O;
  15948. };
  15949. var $create = function create(O, Properties) {
  15950. return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);
  15951. };
  15952. var $propertyIsEnumerable = function propertyIsEnumerable(V) {
  15953. var P = toPrimitive(V, true);
  15954. var enumerable = nativePropertyIsEnumerable.call(this, P);
  15955. if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false;
  15956. return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true;
  15957. };
  15958. var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
  15959. var it = toIndexedObject(O);
  15960. var key = toPrimitive(P, true);
  15961. if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return;
  15962. var descriptor = nativeGetOwnPropertyDescriptor(it, key);
  15963. if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) {
  15964. descriptor.enumerable = true;
  15965. }
  15966. return descriptor;
  15967. };
  15968. var $getOwnPropertyNames = function getOwnPropertyNames(O) {
  15969. var names = nativeGetOwnPropertyNames(toIndexedObject(O));
  15970. var result = [];
  15971. $forEach(names, function (key) {
  15972. if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key);
  15973. });
  15974. return result;
  15975. };
  15976. var $getOwnPropertySymbols = function getOwnPropertySymbols(O) {
  15977. var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
  15978. var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
  15979. var result = [];
  15980. $forEach(names, function (key) {
  15981. if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) {
  15982. result.push(AllSymbols[key]);
  15983. }
  15984. });
  15985. return result;
  15986. };
  15987. // `Symbol` constructor
  15988. // https://tc39.github.io/ecma262/#sec-symbol-constructor
  15989. if (!NATIVE_SYMBOL) {
  15990. $Symbol = function Symbol() {
  15991. if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor');
  15992. var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]);
  15993. var tag = uid(description);
  15994. var setter = function (value) {
  15995. if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value);
  15996. if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
  15997. setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
  15998. };
  15999. if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
  16000. return wrap(tag, description);
  16001. };
  16002. redefine($Symbol[PROTOTYPE], 'toString', function toString() {
  16003. return getInternalState(this).tag;
  16004. });
  16005. redefine($Symbol, 'withoutSetter', function (description) {
  16006. return wrap(uid(description), description);
  16007. });
  16008. propertyIsEnumerableModule.f = $propertyIsEnumerable;
  16009. definePropertyModule.f = $defineProperty;
  16010. getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
  16011. getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
  16012. getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
  16013. wrappedWellKnownSymbolModule.f = function (name) {
  16014. return wrap(wellKnownSymbol(name), name);
  16015. };
  16016. if (DESCRIPTORS) {
  16017. // https://github.com/tc39/proposal-Symbol-description
  16018. nativeDefineProperty($Symbol[PROTOTYPE], 'description', {
  16019. configurable: true,
  16020. get: function description() {
  16021. return getInternalState(this).description;
  16022. }
  16023. });
  16024. if (!IS_PURE) {
  16025. redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });
  16026. }
  16027. }
  16028. }
  16029. $({ global: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {
  16030. Symbol: $Symbol
  16031. });
  16032. $forEach(objectKeys(WellKnownSymbolsStore), function (name) {
  16033. defineWellKnownSymbol(name);
  16034. });
  16035. $({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {
  16036. // `Symbol.for` method
  16037. // https://tc39.github.io/ecma262/#sec-symbol.for
  16038. 'for': function (key) {
  16039. var string = String(key);
  16040. if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
  16041. var symbol = $Symbol(string);
  16042. StringToSymbolRegistry[string] = symbol;
  16043. SymbolToStringRegistry[symbol] = string;
  16044. return symbol;
  16045. },
  16046. // `Symbol.keyFor` method
  16047. // https://tc39.github.io/ecma262/#sec-symbol.keyfor
  16048. keyFor: function keyFor(sym) {
  16049. if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol');
  16050. if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
  16051. },
  16052. useSetter: function () { USE_SETTER = true; },
  16053. useSimple: function () { USE_SETTER = false; }
  16054. });
  16055. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {
  16056. // `Object.create` method
  16057. // https://tc39.github.io/ecma262/#sec-object.create
  16058. create: $create,
  16059. // `Object.defineProperty` method
  16060. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  16061. defineProperty: $defineProperty,
  16062. // `Object.defineProperties` method
  16063. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  16064. defineProperties: $defineProperties,
  16065. // `Object.getOwnPropertyDescriptor` method
  16066. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
  16067. getOwnPropertyDescriptor: $getOwnPropertyDescriptor
  16068. });
  16069. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {
  16070. // `Object.getOwnPropertyNames` method
  16071. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  16072. getOwnPropertyNames: $getOwnPropertyNames,
  16073. // `Object.getOwnPropertySymbols` method
  16074. // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols
  16075. getOwnPropertySymbols: $getOwnPropertySymbols
  16076. });
  16077. // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
  16078. // https://bugs.chromium.org/p/v8/issues/detail?id=3443
  16079. $({ target: 'Object', stat: true, forced: fails(function () { getOwnPropertySymbolsModule.f(1); }) }, {
  16080. getOwnPropertySymbols: function getOwnPropertySymbols(it) {
  16081. return getOwnPropertySymbolsModule.f(toObject(it));
  16082. }
  16083. });
  16084. // `JSON.stringify` method behavior with symbols
  16085. // https://tc39.github.io/ecma262/#sec-json.stringify
  16086. if ($stringify) {
  16087. var FORCED_JSON_STRINGIFY = !NATIVE_SYMBOL || fails(function () {
  16088. var symbol = $Symbol();
  16089. // MS Edge converts symbol values to JSON as {}
  16090. return $stringify([symbol]) != '[null]'
  16091. // WebKit converts symbol values to JSON as null
  16092. || $stringify({ a: symbol }) != '{}'
  16093. // V8 throws on boxed symbols
  16094. || $stringify(Object(symbol)) != '{}';
  16095. });
  16096. $({ target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY }, {
  16097. // eslint-disable-next-line no-unused-vars
  16098. stringify: function stringify(it, replacer, space) {
  16099. var args = [it];
  16100. var index = 1;
  16101. var $replacer;
  16102. while (arguments.length > index) args.push(arguments[index++]);
  16103. $replacer = replacer;
  16104. if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined
  16105. if (!isArray(replacer)) replacer = function (key, value) {
  16106. if (typeof $replacer == 'function') value = $replacer.call(this, key, value);
  16107. if (!isSymbol(value)) return value;
  16108. };
  16109. args[1] = replacer;
  16110. return $stringify.apply(null, args);
  16111. }
  16112. });
  16113. }
  16114. // `Symbol.prototype[@@toPrimitive]` method
  16115. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive
  16116. if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) {
  16117. createNonEnumerableProperty($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf);
  16118. }
  16119. // `Symbol.prototype[@@toStringTag]` property
  16120. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag
  16121. setToStringTag($Symbol, SYMBOL);
  16122. hiddenKeys[HIDDEN] = true;
  16123. /***/ }),
  16124. /***/ "f4a0":
  16125. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  16126. "use strict";
  16127. // ESM COMPAT FLAG
  16128. __webpack_require__.r(__webpack_exports__);
  16129. // CONCATENATED MODULE: ./node_modules/_@vue_cli-service@4.3.1@@vue/cli-service/lib/commands/build/setPublicPath.js
  16130. // This file is imported into lib/wc client bundles.
  16131. if (typeof window !== 'undefined') {
  16132. var currentScript = window.document.currentScript
  16133. if (true) {
  16134. var getCurrentScript = __webpack_require__("c59c")
  16135. currentScript = getCurrentScript()
  16136. // for backward compatibility, because previously we directly included the polyfill
  16137. if (!('currentScript' in document)) {
  16138. Object.defineProperty(document, 'currentScript', { get: getCurrentScript })
  16139. }
  16140. }
  16141. var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
  16142. if (src) {
  16143. __webpack_require__.p = src[1] // eslint-disable-line
  16144. }
  16145. }
  16146. // Indicate to webpack that this file can be concatenated
  16147. /* harmony default export */ var setPublicPath = (null);
  16148. // 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&
  16149. 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"})])}
  16150. var staticRenderFns = []
  16151. // CONCATENATED MODULE: ./src/components/index.vue?vue&type=template&id=d2bcce84&
  16152. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.symbol.js
  16153. var es_symbol = __webpack_require__("f3dd");
  16154. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.array.filter.js
  16155. var es_array_filter = __webpack_require__("dbb3");
  16156. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.array.for-each.js
  16157. var es_array_for_each = __webpack_require__("fe59");
  16158. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.object.get-own-property-descriptor.js
  16159. var es_object_get_own_property_descriptor = __webpack_require__("b73f");
  16160. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.object.get-own-property-descriptors.js
  16161. var es_object_get_own_property_descriptors = __webpack_require__("bf84");
  16162. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/es.object.keys.js
  16163. var es_object_keys = __webpack_require__("fe8a");
  16164. // EXTERNAL MODULE: ./node_modules/_core-js@3.6.5@core-js/modules/web.dom-collections.for-each.js
  16165. var web_dom_collections_for_each = __webpack_require__("08ba");
  16166. // CONCATENATED MODULE: ./node_modules/_@babel_runtime@7.9.6@@babel/runtime/helpers/esm/defineProperty.js
  16167. function _defineProperty(obj, key, value) {
  16168. if (key in obj) {
  16169. Object.defineProperty(obj, key, {
  16170. value: value,
  16171. enumerable: true,
  16172. configurable: true,
  16173. writable: true
  16174. });
  16175. } else {
  16176. obj[key] = value;
  16177. }
  16178. return obj;
  16179. }
  16180. // CONCATENATED MODULE: ./node_modules/_@babel_runtime@7.9.6@@babel/runtime/helpers/esm/objectSpread2.js
  16181. function ownKeys(object, enumerableOnly) {
  16182. var keys = Object.keys(object);
  16183. if (Object.getOwnPropertySymbols) {
  16184. var symbols = Object.getOwnPropertySymbols(object);
  16185. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  16186. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  16187. });
  16188. keys.push.apply(keys, symbols);
  16189. }
  16190. return keys;
  16191. }
  16192. function _objectSpread2(target) {
  16193. for (var i = 1; i < arguments.length; i++) {
  16194. var source = arguments[i] != null ? arguments[i] : {};
  16195. if (i % 2) {
  16196. ownKeys(Object(source), true).forEach(function (key) {
  16197. _defineProperty(target, key, source[key]);
  16198. });
  16199. } else if (Object.getOwnPropertyDescriptors) {
  16200. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  16201. } else {
  16202. ownKeys(Object(source)).forEach(function (key) {
  16203. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  16204. });
  16205. }
  16206. }
  16207. return target;
  16208. }
  16209. // EXTERNAL MODULE: ./node_modules/_font-awesome@4.7.0@font-awesome/css/font-awesome.min.css
  16210. var font_awesome_min = __webpack_require__("508f");
  16211. // EXTERNAL MODULE: ./node_modules/_simplemde@1.11.2@simplemde/src/js/simplemde.js
  16212. var simplemde = __webpack_require__("4d02");
  16213. var simplemde_default = /*#__PURE__*/__webpack_require__.n(simplemde);
  16214. // EXTERNAL MODULE: ./node_modules/_simplemde@1.11.2@simplemde/dist/simplemde.min.css
  16215. var simplemde_min = __webpack_require__("ccf5");
  16216. // EXTERNAL MODULE: ./node_modules/_marked@1.0.0@marked/src/marked.js
  16217. var marked = __webpack_require__("094f");
  16218. var marked_default = /*#__PURE__*/__webpack_require__.n(marked);
  16219. // EXTERNAL MODULE: ./node_modules/_github-markdown-css@4.0.0@github-markdown-css/github-markdown.css
  16220. var github_markdown = __webpack_require__("0e50");
  16221. // 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&
  16222. //
  16223. //
  16224. //
  16225. //
  16226. //
  16227. /* harmony default export */ var componentsvue_type_script_lang_js_ = ({
  16228. name: "MarkdownEditor",
  16229. props: {
  16230. value: {
  16231. type: String,
  16232. default: ""
  16233. },
  16234. border: {
  16235. type: Boolean,
  16236. default: false
  16237. },
  16238. config: {
  16239. type: Object,
  16240. default: function _default() {
  16241. return {};
  16242. }
  16243. }
  16244. },
  16245. data: function data() {
  16246. return {
  16247. mde: null,
  16248. defaultConfig: {}
  16249. };
  16250. },
  16251. computed: {
  16252. classes: function classes() {
  16253. return [{
  16254. "i-mde-no-border": !this.border
  16255. }];
  16256. }
  16257. },
  16258. mounted: function mounted() {
  16259. this.init();
  16260. },
  16261. beforeDestroy: function beforeDestroy() {
  16262. this.mde = null;
  16263. },
  16264. methods: {
  16265. init: function init() {
  16266. var _this = this;
  16267. var config = Object.assign({}, this.defaultConfig, this.config);
  16268. this.mde = new simplemde_default.a(_objectSpread2(_objectSpread2({}, config), {}, {
  16269. initialValue: this.value,
  16270. element: this.$refs.mde,
  16271. autoDownloadFontAwesome: false
  16272. }));
  16273. this.mde.codemirror.on("change", function () {
  16274. _this.$emit("input", _this.mde.value());
  16275. _this.$emit("on-change", _this.mde.value());
  16276. var mdHtml = marked_default()(_this.mde.value() || "", {
  16277. renderer: new marked_default.a.Renderer(),
  16278. gfm: true,
  16279. tables: true,
  16280. breaks: false,
  16281. pedantic: false,
  16282. sanitize: false,
  16283. smartLists: true,
  16284. smartypants: false
  16285. });
  16286. _this.$emit("show-html", '<div class="markdown-body" >' + mdHtml + "</div>");
  16287. });
  16288. },
  16289. add: function add(val) {
  16290. if (this.mde) {
  16291. this.mde.value(this.value + val);
  16292. }
  16293. },
  16294. replace: function replace(val) {
  16295. if (this.mde) {
  16296. this.mde.value(val);
  16297. }
  16298. }
  16299. }
  16300. });
  16301. // CONCATENATED MODULE: ./src/components/index.vue?vue&type=script&lang=js&
  16302. /* harmony default export */ var src_componentsvue_type_script_lang_js_ = (componentsvue_type_script_lang_js_);
  16303. // CONCATENATED MODULE: ./node_modules/_vue-loader@15.9.2@vue-loader/lib/runtime/componentNormalizer.js
  16304. /* globals __VUE_SSR_CONTEXT__ */
  16305. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  16306. // This module is a runtime utility for cleaner component module output and will
  16307. // be included in the final webpack user bundle.
  16308. function normalizeComponent (
  16309. scriptExports,
  16310. render,
  16311. staticRenderFns,
  16312. functionalTemplate,
  16313. injectStyles,
  16314. scopeId,
  16315. moduleIdentifier, /* server only */
  16316. shadowMode /* vue-cli only */
  16317. ) {
  16318. // Vue.extend constructor export interop
  16319. var options = typeof scriptExports === 'function'
  16320. ? scriptExports.options
  16321. : scriptExports
  16322. // render functions
  16323. if (render) {
  16324. options.render = render
  16325. options.staticRenderFns = staticRenderFns
  16326. options._compiled = true
  16327. }
  16328. // functional template
  16329. if (functionalTemplate) {
  16330. options.functional = true
  16331. }
  16332. // scopedId
  16333. if (scopeId) {
  16334. options._scopeId = 'data-v-' + scopeId
  16335. }
  16336. var hook
  16337. if (moduleIdentifier) { // server build
  16338. hook = function (context) {
  16339. // 2.3 injection
  16340. context =
  16341. context || // cached call
  16342. (this.$vnode && this.$vnode.ssrContext) || // stateful
  16343. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  16344. // 2.2 with runInNewContext: true
  16345. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  16346. context = __VUE_SSR_CONTEXT__
  16347. }
  16348. // inject component styles
  16349. if (injectStyles) {
  16350. injectStyles.call(this, context)
  16351. }
  16352. // register component module identifier for async chunk inferrence
  16353. if (context && context._registeredComponents) {
  16354. context._registeredComponents.add(moduleIdentifier)
  16355. }
  16356. }
  16357. // used by ssr in case component is cached and beforeCreate
  16358. // never gets called
  16359. options._ssrRegister = hook
  16360. } else if (injectStyles) {
  16361. hook = shadowMode
  16362. ? function () {
  16363. injectStyles.call(
  16364. this,
  16365. (options.functional ? this.parent : this).$root.$options.shadowRoot
  16366. )
  16367. }
  16368. : injectStyles
  16369. }
  16370. if (hook) {
  16371. if (options.functional) {
  16372. // for template-only hot-reload because in that case the render fn doesn't
  16373. // go through the normalizer
  16374. options._injectStyles = hook
  16375. // register for functional component in vue file
  16376. var originalRender = options.render
  16377. options.render = function renderWithStyleInjection (h, context) {
  16378. hook.call(context)
  16379. return originalRender(h, context)
  16380. }
  16381. } else {
  16382. // inject component registration as beforeCreate hook
  16383. var existing = options.beforeCreate
  16384. options.beforeCreate = existing
  16385. ? [].concat(existing, hook)
  16386. : [hook]
  16387. }
  16388. }
  16389. return {
  16390. exports: scriptExports,
  16391. options: options
  16392. }
  16393. }
  16394. // CONCATENATED MODULE: ./src/components/index.vue
  16395. /* normalize component */
  16396. var component = normalizeComponent(
  16397. src_componentsvue_type_script_lang_js_,
  16398. render,
  16399. staticRenderFns,
  16400. false,
  16401. null,
  16402. null,
  16403. null
  16404. )
  16405. /* harmony default export */ var components = (component.exports);
  16406. // CONCATENATED MODULE: ./src/components/export.js
  16407. /* harmony default export */ var components_export = (components);
  16408. if (typeof window !== "undefined" && window.Vue) {
  16409. window.Vue.component("zx-markdown-editor", components);
  16410. }
  16411. // CONCATENATED MODULE: ./node_modules/_@vue_cli-service@4.3.1@@vue/cli-service/lib/commands/build/entry-lib.js
  16412. /* harmony default export */ var entry_lib = __webpack_exports__["default"] = (components_export);
  16413. /***/ }),
  16414. /***/ "f590":
  16415. /***/ (function(module, exports, __webpack_require__) {
  16416. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  16417. // Distributed under an MIT license: https://codemirror.net/LICENSE
  16418. (function(mod) {
  16419. if (true) // CommonJS
  16420. mod(__webpack_require__("a564"));
  16421. else {}
  16422. })(function(CodeMirror) {
  16423. CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
  16424. var prev = old && old != CodeMirror.Init;
  16425. if (val && !prev) {
  16426. cm.on("blur", onBlur);
  16427. cm.on("change", onChange);
  16428. cm.on("swapDoc", onChange);
  16429. onChange(cm);
  16430. } else if (!val && prev) {
  16431. cm.off("blur", onBlur);
  16432. cm.off("change", onChange);
  16433. cm.off("swapDoc", onChange);
  16434. clearPlaceholder(cm);
  16435. var wrapper = cm.getWrapperElement();
  16436. wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
  16437. }
  16438. if (val && !cm.hasFocus()) onBlur(cm);
  16439. });
  16440. function clearPlaceholder(cm) {
  16441. if (cm.state.placeholder) {
  16442. cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
  16443. cm.state.placeholder = null;
  16444. }
  16445. }
  16446. function setPlaceholder(cm) {
  16447. clearPlaceholder(cm);
  16448. var elt = cm.state.placeholder = document.createElement("pre");
  16449. elt.style.cssText = "height: 0; overflow: visible";
  16450. elt.style.direction = cm.getOption("direction");
  16451. elt.className = "CodeMirror-placeholder CodeMirror-line-like";
  16452. var placeHolder = cm.getOption("placeholder")
  16453. if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
  16454. elt.appendChild(placeHolder)
  16455. cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
  16456. }
  16457. function onBlur(cm) {
  16458. if (isEmpty(cm)) setPlaceholder(cm);
  16459. }
  16460. function onChange(cm) {
  16461. var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
  16462. wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
  16463. if (empty) setPlaceholder(cm);
  16464. else clearPlaceholder(cm);
  16465. }
  16466. function isEmpty(cm) {
  16467. return (cm.lineCount() === 1) && (cm.getLine(0) === "");
  16468. }
  16469. });
  16470. /***/ }),
  16471. /***/ "f594":
  16472. /***/ (function(module, exports, __webpack_require__) {
  16473. var global = __webpack_require__("d890");
  16474. var userAgent = __webpack_require__("4fda");
  16475. var process = global.process;
  16476. var versions = process && process.versions;
  16477. var v8 = versions && versions.v8;
  16478. var match, version;
  16479. if (v8) {
  16480. match = v8.split('.');
  16481. version = match[0] + match[1];
  16482. } else if (userAgent) {
  16483. match = userAgent.match(/Edge\/(\d+)/);
  16484. if (!match || match[1] >= 74) {
  16485. match = userAgent.match(/Chrome\/(\d+)/);
  16486. if (match) version = match[1];
  16487. }
  16488. }
  16489. module.exports = version && +version;
  16490. /***/ }),
  16491. /***/ "f5ef":
  16492. /***/ (function(module, exports) {
  16493. /**
  16494. * TextRenderer
  16495. * returns only the textual part of the token
  16496. */
  16497. module.exports = class TextRenderer {
  16498. // no need for block level renderers
  16499. strong(text) {
  16500. return text;
  16501. }
  16502. em(text) {
  16503. return text;
  16504. }
  16505. codespan(text) {
  16506. return text;
  16507. }
  16508. del(text) {
  16509. return text;
  16510. }
  16511. html(text) {
  16512. return text;
  16513. }
  16514. text(text) {
  16515. return text;
  16516. }
  16517. link(href, title, text) {
  16518. return '' + text;
  16519. }
  16520. image(href, title, text) {
  16521. return '' + text;
  16522. }
  16523. br() {
  16524. return '';
  16525. }
  16526. };
  16527. /***/ }),
  16528. /***/ "faa8":
  16529. /***/ (function(module, exports) {
  16530. var hasOwnProperty = {}.hasOwnProperty;
  16531. module.exports = function (it, key) {
  16532. return hasOwnProperty.call(it, key);
  16533. };
  16534. /***/ }),
  16535. /***/ "fe59":
  16536. /***/ (function(module, exports, __webpack_require__) {
  16537. "use strict";
  16538. var $ = __webpack_require__("1c8b");
  16539. var forEach = __webpack_require__("3c10");
  16540. // `Array.prototype.forEach` method
  16541. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  16542. $({ target: 'Array', proto: true, forced: [].forEach != forEach }, {
  16543. forEach: forEach
  16544. });
  16545. /***/ }),
  16546. /***/ "fe5a":
  16547. /***/ (function(module, exports, __webpack_require__) {
  16548. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  16549. // Distributed under an MIT license: https://codemirror.net/LICENSE
  16550. (function(mod) {
  16551. if (true) // CommonJS
  16552. mod(__webpack_require__("a564"), __webpack_require__("b2e0"), __webpack_require__("6d86"));
  16553. else {}
  16554. })(function(CodeMirror) {
  16555. "use strict";
  16556. CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
  16557. var htmlMode = CodeMirror.getMode(cmCfg, "text/html");
  16558. var htmlModeMissing = htmlMode.name == "null"
  16559. function getMode(name) {
  16560. if (CodeMirror.findModeByName) {
  16561. var found = CodeMirror.findModeByName(name);
  16562. if (found) name = found.mime || found.mimes[0];
  16563. }
  16564. var mode = CodeMirror.getMode(cmCfg, name);
  16565. return mode.name == "null" ? null : mode;
  16566. }
  16567. // Should characters that affect highlighting be highlighted separate?
  16568. // Does not include characters that will be output (such as `1.` and `-` for lists)
  16569. if (modeCfg.highlightFormatting === undefined)
  16570. modeCfg.highlightFormatting = false;
  16571. // Maximum number of nested blockquotes. Set to 0 for infinite nesting.
  16572. // Excess `>` will emit `error` token.
  16573. if (modeCfg.maxBlockquoteDepth === undefined)
  16574. modeCfg.maxBlockquoteDepth = 0;
  16575. // Turn on task lists? ("- [ ] " and "- [x] ")
  16576. if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
  16577. // Turn on strikethrough syntax
  16578. if (modeCfg.strikethrough === undefined)
  16579. modeCfg.strikethrough = false;
  16580. if (modeCfg.emoji === undefined)
  16581. modeCfg.emoji = false;
  16582. if (modeCfg.fencedCodeBlockHighlighting === undefined)
  16583. modeCfg.fencedCodeBlockHighlighting = true;
  16584. if (modeCfg.xml === undefined)
  16585. modeCfg.xml = true;
  16586. // Allow token types to be overridden by user-provided token types.
  16587. if (modeCfg.tokenTypeOverrides === undefined)
  16588. modeCfg.tokenTypeOverrides = {};
  16589. var tokenTypes = {
  16590. header: "header",
  16591. code: "comment",
  16592. quote: "quote",
  16593. list1: "variable-2",
  16594. list2: "variable-3",
  16595. list3: "keyword",
  16596. hr: "hr",
  16597. image: "image",
  16598. imageAltText: "image-alt-text",
  16599. imageMarker: "image-marker",
  16600. formatting: "formatting",
  16601. linkInline: "link",
  16602. linkEmail: "link",
  16603. linkText: "link",
  16604. linkHref: "string",
  16605. em: "em",
  16606. strong: "strong",
  16607. strikethrough: "strikethrough",
  16608. emoji: "builtin"
  16609. };
  16610. for (var tokenType in tokenTypes) {
  16611. if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {
  16612. tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];
  16613. }
  16614. }
  16615. var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
  16616. , listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/
  16617. , taskListRE = /^\[(x| )\](?=\s)/i // Must follow listRE
  16618. , atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
  16619. , setextHeaderRE = /^ {0,3}(?:\={1,}|-{2,})\s*$/
  16620. , textRE = /^[^#!\[\]*_\\<>` "'(~:]+/
  16621. , fencedCodeRE = /^(~~~+|```+)[ \t]*([\w+#-]*)[^\n`]*$/
  16622. , linkDefRE = /^\s*\[[^\]]+?\]:.*$/ // naive link-definition
  16623. , 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]/
  16624. , expandedTab = " " // CommonMark specifies tab as 4 spaces
  16625. function switchInline(stream, state, f) {
  16626. state.f = state.inline = f;
  16627. return f(stream, state);
  16628. }
  16629. function switchBlock(stream, state, f) {
  16630. state.f = state.block = f;
  16631. return f(stream, state);
  16632. }
  16633. function lineIsEmpty(line) {
  16634. return !line || !/\S/.test(line.string)
  16635. }
  16636. // Blocks
  16637. function blankLine(state) {
  16638. // Reset linkTitle state
  16639. state.linkTitle = false;
  16640. state.linkHref = false;
  16641. state.linkText = false;
  16642. // Reset EM state
  16643. state.em = false;
  16644. // Reset STRONG state
  16645. state.strong = false;
  16646. // Reset strikethrough state
  16647. state.strikethrough = false;
  16648. // Reset state.quote
  16649. state.quote = 0;
  16650. // Reset state.indentedCode
  16651. state.indentedCode = false;
  16652. if (state.f == htmlBlock) {
  16653. var exit = htmlModeMissing
  16654. if (!exit) {
  16655. var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
  16656. exit = inner.mode.name == "xml" && inner.state.tagStart === null &&
  16657. (!inner.state.context && inner.state.tokenize.isInText)
  16658. }
  16659. if (exit) {
  16660. state.f = inlineNormal;
  16661. state.block = blockNormal;
  16662. state.htmlState = null;
  16663. }
  16664. }
  16665. // Reset state.trailingSpace
  16666. state.trailingSpace = 0;
  16667. state.trailingSpaceNewLine = false;
  16668. // Mark this line as blank
  16669. state.prevLine = state.thisLine
  16670. state.thisLine = {stream: null}
  16671. return null;
  16672. }
  16673. function blockNormal(stream, state) {
  16674. var firstTokenOnLine = stream.column() === state.indentation;
  16675. var prevLineLineIsEmpty = lineIsEmpty(state.prevLine.stream);
  16676. var prevLineIsIndentedCode = state.indentedCode;
  16677. var prevLineIsHr = state.prevLine.hr;
  16678. var prevLineIsList = state.list !== false;
  16679. var maxNonCodeIndentation = (state.listStack[state.listStack.length - 1] || 0) + 3;
  16680. state.indentedCode = false;
  16681. var lineIndentation = state.indentation;
  16682. // compute once per line (on first token)
  16683. if (state.indentationDiff === null) {
  16684. state.indentationDiff = state.indentation;
  16685. if (prevLineIsList) {
  16686. state.list = null;
  16687. // While this list item's marker's indentation is less than the deepest
  16688. // list item's content's indentation,pop the deepest list item
  16689. // indentation off the stack, and update block indentation state
  16690. while (lineIndentation < state.listStack[state.listStack.length - 1]) {
  16691. state.listStack.pop();
  16692. if (state.listStack.length) {
  16693. state.indentation = state.listStack[state.listStack.length - 1];
  16694. // less than the first list's indent -> the line is no longer a list
  16695. } else {
  16696. state.list = false;
  16697. }
  16698. }
  16699. if (state.list !== false) {
  16700. state.indentationDiff = lineIndentation - state.listStack[state.listStack.length - 1]
  16701. }
  16702. }
  16703. }
  16704. // not comprehensive (currently only for setext detection purposes)
  16705. var allowsInlineContinuation = (
  16706. !prevLineLineIsEmpty && !prevLineIsHr && !state.prevLine.header &&
  16707. (!prevLineIsList || !prevLineIsIndentedCode) &&
  16708. !state.prevLine.fencedCodeEnd
  16709. );
  16710. var isHr = (state.list === false || prevLineIsHr || prevLineLineIsEmpty) &&
  16711. state.indentation <= maxNonCodeIndentation && stream.match(hrRE);
  16712. var match = null;
  16713. if (state.indentationDiff >= 4 && (prevLineIsIndentedCode || state.prevLine.fencedCodeEnd ||
  16714. state.prevLine.header || prevLineLineIsEmpty)) {
  16715. stream.skipToEnd();
  16716. state.indentedCode = true;
  16717. return tokenTypes.code;
  16718. } else if (stream.eatSpace()) {
  16719. return null;
  16720. } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
  16721. state.quote = 0;
  16722. state.header = match[1].length;
  16723. state.thisLine.header = true;
  16724. if (modeCfg.highlightFormatting) state.formatting = "header";
  16725. state.f = state.inline;
  16726. return getType(state);
  16727. } else if (state.indentation <= maxNonCodeIndentation && stream.eat('>')) {
  16728. state.quote = firstTokenOnLine ? 1 : state.quote + 1;
  16729. if (modeCfg.highlightFormatting) state.formatting = "quote";
  16730. stream.eatSpace();
  16731. return getType(state);
  16732. } else if (!isHr && !state.setext && firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(listRE))) {
  16733. var listType = match[1] ? "ol" : "ul";
  16734. state.indentation = lineIndentation + stream.current().length;
  16735. state.list = true;
  16736. state.quote = 0;
  16737. // Add this list item's content's indentation to the stack
  16738. state.listStack.push(state.indentation);
  16739. // Reset inline styles which shouldn't propagate aross list items
  16740. state.em = false;
  16741. state.strong = false;
  16742. state.code = false;
  16743. state.strikethrough = false;
  16744. if (modeCfg.taskLists && stream.match(taskListRE, false)) {
  16745. state.taskList = true;
  16746. }
  16747. state.f = state.inline;
  16748. if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
  16749. return getType(state);
  16750. } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedCodeRE, true))) {
  16751. state.quote = 0;
  16752. state.fencedEndRE = new RegExp(match[1] + "+ *$");
  16753. // try switching mode
  16754. state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2]);
  16755. if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
  16756. state.f = state.block = local;
  16757. if (modeCfg.highlightFormatting) state.formatting = "code-block";
  16758. state.code = -1
  16759. return getType(state);
  16760. // SETEXT has lowest block-scope precedence after HR, so check it after
  16761. // the others (code, blockquote, list...)
  16762. } else if (
  16763. // if setext set, indicates line after ---/===
  16764. state.setext || (
  16765. // line before ---/===
  16766. (!allowsInlineContinuation || !prevLineIsList) && !state.quote && state.list === false &&
  16767. !state.code && !isHr && !linkDefRE.test(stream.string) &&
  16768. (match = stream.lookAhead(1)) && (match = match.match(setextHeaderRE))
  16769. )
  16770. ) {
  16771. if ( !state.setext ) {
  16772. state.header = match[0].charAt(0) == '=' ? 1 : 2;
  16773. state.setext = state.header;
  16774. } else {
  16775. state.header = state.setext;
  16776. // has no effect on type so we can reset it now
  16777. state.setext = 0;
  16778. stream.skipToEnd();
  16779. if (modeCfg.highlightFormatting) state.formatting = "header";
  16780. }
  16781. state.thisLine.header = true;
  16782. state.f = state.inline;
  16783. return getType(state);
  16784. } else if (isHr) {
  16785. stream.skipToEnd();
  16786. state.hr = true;
  16787. state.thisLine.hr = true;
  16788. return tokenTypes.hr;
  16789. } else if (stream.peek() === '[') {
  16790. return switchInline(stream, state, footnoteLink);
  16791. }
  16792. return switchInline(stream, state, state.inline);
  16793. }
  16794. function htmlBlock(stream, state) {
  16795. var style = htmlMode.token(stream, state.htmlState);
  16796. if (!htmlModeMissing) {
  16797. var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
  16798. if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
  16799. (!inner.state.context && inner.state.tokenize.isInText)) ||
  16800. (state.md_inside && stream.current().indexOf(">") > -1)) {
  16801. state.f = inlineNormal;
  16802. state.block = blockNormal;
  16803. state.htmlState = null;
  16804. }
  16805. }
  16806. return style;
  16807. }
  16808. function local(stream, state) {
  16809. var currListInd = state.listStack[state.listStack.length - 1] || 0;
  16810. var hasExitedList = state.indentation < currListInd;
  16811. var maxFencedEndInd = currListInd + 3;
  16812. if (state.fencedEndRE && state.indentation <= maxFencedEndInd && (hasExitedList || stream.match(state.fencedEndRE))) {
  16813. if (modeCfg.highlightFormatting) state.formatting = "code-block";
  16814. var returnType;
  16815. if (!hasExitedList) returnType = getType(state)
  16816. state.localMode = state.localState = null;
  16817. state.block = blockNormal;
  16818. state.f = inlineNormal;
  16819. state.fencedEndRE = null;
  16820. state.code = 0
  16821. state.thisLine.fencedCodeEnd = true;
  16822. if (hasExitedList) return switchBlock(stream, state, state.block);
  16823. return returnType;
  16824. } else if (state.localMode) {
  16825. return state.localMode.token(stream, state.localState);
  16826. } else {
  16827. stream.skipToEnd();
  16828. return tokenTypes.code;
  16829. }
  16830. }
  16831. // Inline
  16832. function getType(state) {
  16833. var styles = [];
  16834. if (state.formatting) {
  16835. styles.push(tokenTypes.formatting);
  16836. if (typeof state.formatting === "string") state.formatting = [state.formatting];
  16837. for (var i = 0; i < state.formatting.length; i++) {
  16838. styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
  16839. if (state.formatting[i] === "header") {
  16840. styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
  16841. }
  16842. // Add `formatting-quote` and `formatting-quote-#` for blockquotes
  16843. // Add `error` instead if the maximum blockquote nesting depth is passed
  16844. if (state.formatting[i] === "quote") {
  16845. if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
  16846. styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
  16847. } else {
  16848. styles.push("error");
  16849. }
  16850. }
  16851. }
  16852. }
  16853. if (state.taskOpen) {
  16854. styles.push("meta");
  16855. return styles.length ? styles.join(' ') : null;
  16856. }
  16857. if (state.taskClosed) {
  16858. styles.push("property");
  16859. return styles.length ? styles.join(' ') : null;
  16860. }
  16861. if (state.linkHref) {
  16862. styles.push(tokenTypes.linkHref, "url");
  16863. } else { // Only apply inline styles to non-url text
  16864. if (state.strong) { styles.push(tokenTypes.strong); }
  16865. if (state.em) { styles.push(tokenTypes.em); }
  16866. if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
  16867. if (state.emoji) { styles.push(tokenTypes.emoji); }
  16868. if (state.linkText) { styles.push(tokenTypes.linkText); }
  16869. if (state.code) { styles.push(tokenTypes.code); }
  16870. if (state.image) { styles.push(tokenTypes.image); }
  16871. if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }
  16872. if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }
  16873. }
  16874. if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
  16875. if (state.quote) {
  16876. styles.push(tokenTypes.quote);
  16877. // Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
  16878. if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
  16879. styles.push(tokenTypes.quote + "-" + state.quote);
  16880. } else {
  16881. styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
  16882. }
  16883. }
  16884. if (state.list !== false) {
  16885. var listMod = (state.listStack.length - 1) % 3;
  16886. if (!listMod) {
  16887. styles.push(tokenTypes.list1);
  16888. } else if (listMod === 1) {
  16889. styles.push(tokenTypes.list2);
  16890. } else {
  16891. styles.push(tokenTypes.list3);
  16892. }
  16893. }
  16894. if (state.trailingSpaceNewLine) {
  16895. styles.push("trailing-space-new-line");
  16896. } else if (state.trailingSpace) {
  16897. styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
  16898. }
  16899. return styles.length ? styles.join(' ') : null;
  16900. }
  16901. function handleText(stream, state) {
  16902. if (stream.match(textRE, true)) {
  16903. return getType(state);
  16904. }
  16905. return undefined;
  16906. }
  16907. function inlineNormal(stream, state) {
  16908. var style = state.text(stream, state);
  16909. if (typeof style !== 'undefined')
  16910. return style;
  16911. if (state.list) { // List marker (*, +, -, 1., etc)
  16912. state.list = null;
  16913. return getType(state);
  16914. }
  16915. if (state.taskList) {
  16916. var taskOpen = stream.match(taskListRE, true)[1] === " ";
  16917. if (taskOpen) state.taskOpen = true;
  16918. else state.taskClosed = true;
  16919. if (modeCfg.highlightFormatting) state.formatting = "task";
  16920. state.taskList = false;
  16921. return getType(state);
  16922. }
  16923. state.taskOpen = false;
  16924. state.taskClosed = false;
  16925. if (state.header && stream.match(/^#+$/, true)) {
  16926. if (modeCfg.highlightFormatting) state.formatting = "header";
  16927. return getType(state);
  16928. }
  16929. var ch = stream.next();
  16930. // Matches link titles present on next line
  16931. if (state.linkTitle) {
  16932. state.linkTitle = false;
  16933. var matchCh = ch;
  16934. if (ch === '(') {
  16935. matchCh = ')';
  16936. }
  16937. matchCh = (matchCh+'').replace(/([.?*+^\[\]\\(){}|-])/g, "\\$1");
  16938. var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
  16939. if (stream.match(new RegExp(regex), true)) {
  16940. return tokenTypes.linkHref;
  16941. }
  16942. }
  16943. // If this block is changed, it may need to be updated in GFM mode
  16944. if (ch === '`') {
  16945. var previousFormatting = state.formatting;
  16946. if (modeCfg.highlightFormatting) state.formatting = "code";
  16947. stream.eatWhile('`');
  16948. var count = stream.current().length
  16949. if (state.code == 0 && (!state.quote || count == 1)) {
  16950. state.code = count
  16951. return getType(state)
  16952. } else if (count == state.code) { // Must be exact
  16953. var t = getType(state)
  16954. state.code = 0
  16955. return t
  16956. } else {
  16957. state.formatting = previousFormatting
  16958. return getType(state)
  16959. }
  16960. } else if (state.code) {
  16961. return getType(state);
  16962. }
  16963. if (ch === '\\') {
  16964. stream.next();
  16965. if (modeCfg.highlightFormatting) {
  16966. var type = getType(state);
  16967. var formattingEscape = tokenTypes.formatting + "-escape";
  16968. return type ? type + " " + formattingEscape : formattingEscape;
  16969. }
  16970. }
  16971. if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
  16972. state.imageMarker = true;
  16973. state.image = true;
  16974. if (modeCfg.highlightFormatting) state.formatting = "image";
  16975. return getType(state);
  16976. }
  16977. if (ch === '[' && state.imageMarker && stream.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/, false)) {
  16978. state.imageMarker = false;
  16979. state.imageAltText = true
  16980. if (modeCfg.highlightFormatting) state.formatting = "image";
  16981. return getType(state);
  16982. }
  16983. if (ch === ']' && state.imageAltText) {
  16984. if (modeCfg.highlightFormatting) state.formatting = "image";
  16985. var type = getType(state);
  16986. state.imageAltText = false;
  16987. state.image = false;
  16988. state.inline = state.f = linkHref;
  16989. return type;
  16990. }
  16991. if (ch === '[' && !state.image) {
  16992. if (state.linkText && stream.match(/^.*?\]/)) return getType(state)
  16993. state.linkText = true;
  16994. if (modeCfg.highlightFormatting) state.formatting = "link";
  16995. return getType(state);
  16996. }
  16997. if (ch === ']' && state.linkText) {
  16998. if (modeCfg.highlightFormatting) state.formatting = "link";
  16999. var type = getType(state);
  17000. state.linkText = false;
  17001. state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal
  17002. return type;
  17003. }
  17004. if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
  17005. state.f = state.inline = linkInline;
  17006. if (modeCfg.highlightFormatting) state.formatting = "link";
  17007. var type = getType(state);
  17008. if (type){
  17009. type += " ";
  17010. } else {
  17011. type = "";
  17012. }
  17013. return type + tokenTypes.linkInline;
  17014. }
  17015. if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
  17016. state.f = state.inline = linkInline;
  17017. if (modeCfg.highlightFormatting) state.formatting = "link";
  17018. var type = getType(state);
  17019. if (type){
  17020. type += " ";
  17021. } else {
  17022. type = "";
  17023. }
  17024. return type + tokenTypes.linkEmail;
  17025. }
  17026. if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {
  17027. var end = stream.string.indexOf(">", stream.pos);
  17028. if (end != -1) {
  17029. var atts = stream.string.substring(stream.start, end);
  17030. if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
  17031. }
  17032. stream.backUp(1);
  17033. state.htmlState = CodeMirror.startState(htmlMode);
  17034. return switchBlock(stream, state, htmlBlock);
  17035. }
  17036. if (modeCfg.xml && ch === '<' && stream.match(/^\/\w*?>/)) {
  17037. state.md_inside = false;
  17038. return "tag";
  17039. } else if (ch === "*" || ch === "_") {
  17040. var len = 1, before = stream.pos == 1 ? " " : stream.string.charAt(stream.pos - 2)
  17041. while (len < 3 && stream.eat(ch)) len++
  17042. var after = stream.peek() || " "
  17043. // See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis
  17044. var leftFlanking = !/\s/.test(after) && (!punctuation.test(after) || /\s/.test(before) || punctuation.test(before))
  17045. var rightFlanking = !/\s/.test(before) && (!punctuation.test(before) || /\s/.test(after) || punctuation.test(after))
  17046. var setEm = null, setStrong = null
  17047. if (len % 2) { // Em
  17048. if (!state.em && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
  17049. setEm = true
  17050. else if (state.em == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
  17051. setEm = false
  17052. }
  17053. if (len > 1) { // Strong
  17054. if (!state.strong && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
  17055. setStrong = true
  17056. else if (state.strong == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
  17057. setStrong = false
  17058. }
  17059. if (setStrong != null || setEm != null) {
  17060. if (modeCfg.highlightFormatting) state.formatting = setEm == null ? "strong" : setStrong == null ? "em" : "strong em"
  17061. if (setEm === true) state.em = ch
  17062. if (setStrong === true) state.strong = ch
  17063. var t = getType(state)
  17064. if (setEm === false) state.em = false
  17065. if (setStrong === false) state.strong = false
  17066. return t
  17067. }
  17068. } else if (ch === ' ') {
  17069. if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
  17070. if (stream.peek() === ' ') { // Surrounded by spaces, ignore
  17071. return getType(state);
  17072. } else { // Not surrounded by spaces, back up pointer
  17073. stream.backUp(1);
  17074. }
  17075. }
  17076. }
  17077. if (modeCfg.strikethrough) {
  17078. if (ch === '~' && stream.eatWhile(ch)) {
  17079. if (state.strikethrough) {// Remove strikethrough
  17080. if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
  17081. var t = getType(state);
  17082. state.strikethrough = false;
  17083. return t;
  17084. } else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
  17085. state.strikethrough = true;
  17086. if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
  17087. return getType(state);
  17088. }
  17089. } else if (ch === ' ') {
  17090. if (stream.match(/^~~/, true)) { // Probably surrounded by space
  17091. if (stream.peek() === ' ') { // Surrounded by spaces, ignore
  17092. return getType(state);
  17093. } else { // Not surrounded by spaces, back up pointer
  17094. stream.backUp(2);
  17095. }
  17096. }
  17097. }
  17098. }
  17099. if (modeCfg.emoji && ch === ":" && stream.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)) {
  17100. state.emoji = true;
  17101. if (modeCfg.highlightFormatting) state.formatting = "emoji";
  17102. var retType = getType(state);
  17103. state.emoji = false;
  17104. return retType;
  17105. }
  17106. if (ch === ' ') {
  17107. if (stream.match(/^ +$/, false)) {
  17108. state.trailingSpace++;
  17109. } else if (state.trailingSpace) {
  17110. state.trailingSpaceNewLine = true;
  17111. }
  17112. }
  17113. return getType(state);
  17114. }
  17115. function linkInline(stream, state) {
  17116. var ch = stream.next();
  17117. if (ch === ">") {
  17118. state.f = state.inline = inlineNormal;
  17119. if (modeCfg.highlightFormatting) state.formatting = "link";
  17120. var type = getType(state);
  17121. if (type){
  17122. type += " ";
  17123. } else {
  17124. type = "";
  17125. }
  17126. return type + tokenTypes.linkInline;
  17127. }
  17128. stream.match(/^[^>]+/, true);
  17129. return tokenTypes.linkInline;
  17130. }
  17131. function linkHref(stream, state) {
  17132. // Check if space, and return NULL if so (to avoid marking the space)
  17133. if(stream.eatSpace()){
  17134. return null;
  17135. }
  17136. var ch = stream.next();
  17137. if (ch === '(' || ch === '[') {
  17138. state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
  17139. if (modeCfg.highlightFormatting) state.formatting = "link-string";
  17140. state.linkHref = true;
  17141. return getType(state);
  17142. }
  17143. return 'error';
  17144. }
  17145. var linkRE = {
  17146. ")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
  17147. "]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/
  17148. }
  17149. function getLinkHrefInside(endChar) {
  17150. return function(stream, state) {
  17151. var ch = stream.next();
  17152. if (ch === endChar) {
  17153. state.f = state.inline = inlineNormal;
  17154. if (modeCfg.highlightFormatting) state.formatting = "link-string";
  17155. var returnState = getType(state);
  17156. state.linkHref = false;
  17157. return returnState;
  17158. }
  17159. stream.match(linkRE[endChar])
  17160. state.linkHref = true;
  17161. return getType(state);
  17162. };
  17163. }
  17164. function footnoteLink(stream, state) {
  17165. if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
  17166. state.f = footnoteLinkInside;
  17167. stream.next(); // Consume [
  17168. if (modeCfg.highlightFormatting) state.formatting = "link";
  17169. state.linkText = true;
  17170. return getType(state);
  17171. }
  17172. return switchInline(stream, state, inlineNormal);
  17173. }
  17174. function footnoteLinkInside(stream, state) {
  17175. if (stream.match(/^\]:/, true)) {
  17176. state.f = state.inline = footnoteUrl;
  17177. if (modeCfg.highlightFormatting) state.formatting = "link";
  17178. var returnType = getType(state);
  17179. state.linkText = false;
  17180. return returnType;
  17181. }
  17182. stream.match(/^([^\]\\]|\\.)+/, true);
  17183. return tokenTypes.linkText;
  17184. }
  17185. function footnoteUrl(stream, state) {
  17186. // Check if space, and return NULL if so (to avoid marking the space)
  17187. if(stream.eatSpace()){
  17188. return null;
  17189. }
  17190. // Match URL
  17191. stream.match(/^[^\s]+/, true);
  17192. // Check for link title
  17193. if (stream.peek() === undefined) { // End of line, set flag to check next line
  17194. state.linkTitle = true;
  17195. } else { // More content on line, check if link title
  17196. stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
  17197. }
  17198. state.f = state.inline = inlineNormal;
  17199. return tokenTypes.linkHref + " url";
  17200. }
  17201. var mode = {
  17202. startState: function() {
  17203. return {
  17204. f: blockNormal,
  17205. prevLine: {stream: null},
  17206. thisLine: {stream: null},
  17207. block: blockNormal,
  17208. htmlState: null,
  17209. indentation: 0,
  17210. inline: inlineNormal,
  17211. text: handleText,
  17212. formatting: false,
  17213. linkText: false,
  17214. linkHref: false,
  17215. linkTitle: false,
  17216. code: 0,
  17217. em: false,
  17218. strong: false,
  17219. header: 0,
  17220. setext: 0,
  17221. hr: false,
  17222. taskList: false,
  17223. list: false,
  17224. listStack: [],
  17225. quote: 0,
  17226. trailingSpace: 0,
  17227. trailingSpaceNewLine: false,
  17228. strikethrough: false,
  17229. emoji: false,
  17230. fencedEndRE: null
  17231. };
  17232. },
  17233. copyState: function(s) {
  17234. return {
  17235. f: s.f,
  17236. prevLine: s.prevLine,
  17237. thisLine: s.thisLine,
  17238. block: s.block,
  17239. htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
  17240. indentation: s.indentation,
  17241. localMode: s.localMode,
  17242. localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
  17243. inline: s.inline,
  17244. text: s.text,
  17245. formatting: false,
  17246. linkText: s.linkText,
  17247. linkTitle: s.linkTitle,
  17248. linkHref: s.linkHref,
  17249. code: s.code,
  17250. em: s.em,
  17251. strong: s.strong,
  17252. strikethrough: s.strikethrough,
  17253. emoji: s.emoji,
  17254. header: s.header,
  17255. setext: s.setext,
  17256. hr: s.hr,
  17257. taskList: s.taskList,
  17258. list: s.list,
  17259. listStack: s.listStack.slice(0),
  17260. quote: s.quote,
  17261. indentedCode: s.indentedCode,
  17262. trailingSpace: s.trailingSpace,
  17263. trailingSpaceNewLine: s.trailingSpaceNewLine,
  17264. md_inside: s.md_inside,
  17265. fencedEndRE: s.fencedEndRE
  17266. };
  17267. },
  17268. token: function(stream, state) {
  17269. // Reset state.formatting
  17270. state.formatting = false;
  17271. if (stream != state.thisLine.stream) {
  17272. state.header = 0;
  17273. state.hr = false;
  17274. if (stream.match(/^\s*$/, true)) {
  17275. blankLine(state);
  17276. return null;
  17277. }
  17278. state.prevLine = state.thisLine
  17279. state.thisLine = {stream: stream}
  17280. // Reset state.taskList
  17281. state.taskList = false;
  17282. // Reset state.trailingSpace
  17283. state.trailingSpace = 0;
  17284. state.trailingSpaceNewLine = false;
  17285. if (!state.localState) {
  17286. state.f = state.block;
  17287. if (state.f != htmlBlock) {
  17288. var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, expandedTab).length;
  17289. state.indentation = indentation;
  17290. state.indentationDiff = null;
  17291. if (indentation > 0) return null;
  17292. }
  17293. }
  17294. }
  17295. return state.f(stream, state);
  17296. },
  17297. innerMode: function(state) {
  17298. if (state.block == htmlBlock) return {state: state.htmlState, mode: htmlMode};
  17299. if (state.localState) return {state: state.localState, mode: state.localMode};
  17300. return {state: state, mode: mode};
  17301. },
  17302. indent: function(state, textAfter, line) {
  17303. if (state.block == htmlBlock && htmlMode.indent) return htmlMode.indent(state.htmlState, textAfter, line)
  17304. if (state.localState && state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line)
  17305. return CodeMirror.Pass
  17306. },
  17307. blankLine: blankLine,
  17308. getType: getType,
  17309. blockCommentStart: "<!--",
  17310. blockCommentEnd: "-->",
  17311. closeBrackets: "()[]{}''\"\"``",
  17312. fold: "markdown"
  17313. };
  17314. return mode;
  17315. }, "xml");
  17316. CodeMirror.defineMIME("text/markdown", "markdown");
  17317. CodeMirror.defineMIME("text/x-markdown", "markdown");
  17318. });
  17319. /***/ }),
  17320. /***/ "fe8a":
  17321. /***/ (function(module, exports, __webpack_require__) {
  17322. var $ = __webpack_require__("1c8b");
  17323. var toObject = __webpack_require__("3553");
  17324. var nativeKeys = __webpack_require__("cbab");
  17325. var fails = __webpack_require__("efe2");
  17326. var FAILS_ON_PRIMITIVES = fails(function () { nativeKeys(1); });
  17327. // `Object.keys` method
  17328. // https://tc39.github.io/ecma262/#sec-object.keys
  17329. $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
  17330. keys: function keys(it) {
  17331. return nativeKeys(toObject(it));
  17332. }
  17333. });
  17334. /***/ }),
  17335. /***/ "ff9c":
  17336. /***/ (function(module, exports, __webpack_require__) {
  17337. var DESCRIPTORS = __webpack_require__("1e2c");
  17338. var fails = __webpack_require__("efe2");
  17339. var has = __webpack_require__("faa8");
  17340. var defineProperty = Object.defineProperty;
  17341. var cache = {};
  17342. var thrower = function (it) { throw it; };
  17343. module.exports = function (METHOD_NAME, options) {
  17344. if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
  17345. if (!options) options = {};
  17346. var method = [][METHOD_NAME];
  17347. var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
  17348. var argument0 = has(options, 0) ? options[0] : thrower;
  17349. var argument1 = has(options, 1) ? options[1] : undefined;
  17350. return cache[METHOD_NAME] = !!method && !fails(function () {
  17351. if (ACCESSORS && !DESCRIPTORS) return true;
  17352. var O = { length: -1 };
  17353. if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
  17354. else O[1] = 1;
  17355. method.call(O, argument0, argument1);
  17356. });
  17357. };
  17358. /***/ })
  17359. /******/ });
  17360. });
  17361. //# sourceMappingURL=zx-markdown-editor.umd.js.map