tinymce.js 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.10.2 (2021-11-17)
  8. */
  9. ;(function () {
  10. 'use strict'
  11. var typeOf$1 = function (x) {
  12. if (x === null) {
  13. return 'null'
  14. }
  15. if (x === undefined) {
  16. return 'undefined'
  17. }
  18. var t = typeof x
  19. if (
  20. t === 'object' &&
  21. (Array.prototype.isPrototypeOf(x) ||
  22. (x.constructor && x.constructor.name === 'Array'))
  23. ) {
  24. return 'array'
  25. }
  26. if (
  27. t === 'object' &&
  28. (String.prototype.isPrototypeOf(x) ||
  29. (x.constructor && x.constructor.name === 'String'))
  30. ) {
  31. return 'string'
  32. }
  33. return t
  34. }
  35. var isEquatableType = function (x) {
  36. return (
  37. [
  38. 'undefined',
  39. 'boolean',
  40. 'number',
  41. 'string',
  42. 'function',
  43. 'xml',
  44. 'null',
  45. ].indexOf(x) !== -1
  46. )
  47. }
  48. var sort$1 = function (xs, compareFn) {
  49. var clone = Array.prototype.slice.call(xs)
  50. return clone.sort(compareFn)
  51. }
  52. var contramap = function (eqa, f) {
  53. return eq$2(function (x, y) {
  54. return eqa.eq(f(x), f(y))
  55. })
  56. }
  57. var eq$2 = function (f) {
  58. return { eq: f }
  59. }
  60. var tripleEq = eq$2(function (x, y) {
  61. return x === y
  62. })
  63. var eqString = tripleEq
  64. var eqArray = function (eqa) {
  65. return eq$2(function (x, y) {
  66. if (x.length !== y.length) {
  67. return false
  68. }
  69. var len = x.length
  70. for (var i = 0; i < len; i++) {
  71. if (!eqa.eq(x[i], y[i])) {
  72. return false
  73. }
  74. }
  75. return true
  76. })
  77. }
  78. var eqSortedArray = function (eqa, compareFn) {
  79. return contramap(eqArray(eqa), function (xs) {
  80. return sort$1(xs, compareFn)
  81. })
  82. }
  83. var eqRecord = function (eqa) {
  84. return eq$2(function (x, y) {
  85. var kx = Object.keys(x)
  86. var ky = Object.keys(y)
  87. if (!eqSortedArray(eqString).eq(kx, ky)) {
  88. return false
  89. }
  90. var len = kx.length
  91. for (var i = 0; i < len; i++) {
  92. var q = kx[i]
  93. if (!eqa.eq(x[q], y[q])) {
  94. return false
  95. }
  96. }
  97. return true
  98. })
  99. }
  100. var eqAny = eq$2(function (x, y) {
  101. if (x === y) {
  102. return true
  103. }
  104. var tx = typeOf$1(x)
  105. var ty = typeOf$1(y)
  106. if (tx !== ty) {
  107. return false
  108. }
  109. if (isEquatableType(tx)) {
  110. return x === y
  111. } else if (tx === 'array') {
  112. return eqArray(eqAny).eq(x, y)
  113. } else if (tx === 'object') {
  114. return eqRecord(eqAny).eq(x, y)
  115. }
  116. return false
  117. })
  118. var typeOf = function (x) {
  119. var t = typeof x
  120. if (x === null) {
  121. return 'null'
  122. } else if (
  123. t === 'object' &&
  124. (Array.prototype.isPrototypeOf(x) ||
  125. (x.constructor && x.constructor.name === 'Array'))
  126. ) {
  127. return 'array'
  128. } else if (
  129. t === 'object' &&
  130. (String.prototype.isPrototypeOf(x) ||
  131. (x.constructor && x.constructor.name === 'String'))
  132. ) {
  133. return 'string'
  134. } else {
  135. return t
  136. }
  137. }
  138. var isType$1 = function (type) {
  139. return function (value) {
  140. return typeOf(value) === type
  141. }
  142. }
  143. var isSimpleType = function (type) {
  144. return function (value) {
  145. return typeof value === type
  146. }
  147. }
  148. var eq$1 = function (t) {
  149. return function (a) {
  150. return t === a
  151. }
  152. }
  153. var isString$1 = isType$1('string')
  154. var isObject = isType$1('object')
  155. var isArray$1 = isType$1('array')
  156. var isNull = eq$1(null)
  157. var isBoolean = isSimpleType('boolean')
  158. var isUndefined = eq$1(undefined)
  159. var isNullable = function (a) {
  160. return a === null || a === undefined
  161. }
  162. var isNonNullable = function (a) {
  163. return !isNullable(a)
  164. }
  165. var isFunction = isSimpleType('function')
  166. var isNumber = isSimpleType('number')
  167. var noop = function () {}
  168. var compose = function (fa, fb) {
  169. return function () {
  170. var args = []
  171. for (var _i = 0; _i < arguments.length; _i++) {
  172. args[_i] = arguments[_i]
  173. }
  174. return fa(fb.apply(null, args))
  175. }
  176. }
  177. var compose1 = function (fbc, fab) {
  178. return function (a) {
  179. return fbc(fab(a))
  180. }
  181. }
  182. var constant = function (value) {
  183. return function () {
  184. return value
  185. }
  186. }
  187. var identity = function (x) {
  188. return x
  189. }
  190. var tripleEquals = function (a, b) {
  191. return a === b
  192. }
  193. function curry(fn) {
  194. var initialArgs = []
  195. for (var _i = 1; _i < arguments.length; _i++) {
  196. initialArgs[_i - 1] = arguments[_i]
  197. }
  198. return function () {
  199. var restArgs = []
  200. for (var _i = 0; _i < arguments.length; _i++) {
  201. restArgs[_i] = arguments[_i]
  202. }
  203. var all = initialArgs.concat(restArgs)
  204. return fn.apply(null, all)
  205. }
  206. }
  207. var not = function (f) {
  208. return function (t) {
  209. return !f(t)
  210. }
  211. }
  212. var die = function (msg) {
  213. return function () {
  214. throw new Error(msg)
  215. }
  216. }
  217. var apply = function (f) {
  218. return f()
  219. }
  220. var call = function (f) {
  221. f()
  222. }
  223. var never = constant(false)
  224. var always = constant(true)
  225. var none = function () {
  226. return NONE
  227. }
  228. var NONE = (function () {
  229. var call = function (thunk) {
  230. return thunk()
  231. }
  232. var id = identity
  233. var me = {
  234. fold: function (n, _s) {
  235. return n()
  236. },
  237. isSome: never,
  238. isNone: always,
  239. getOr: id,
  240. getOrThunk: call,
  241. getOrDie: function (msg) {
  242. throw new Error(msg || 'error: getOrDie called on none.')
  243. },
  244. getOrNull: constant(null),
  245. getOrUndefined: constant(undefined),
  246. or: id,
  247. orThunk: call,
  248. map: none,
  249. each: noop,
  250. bind: none,
  251. exists: never,
  252. forall: always,
  253. filter: function () {
  254. return none()
  255. },
  256. toArray: function () {
  257. return []
  258. },
  259. toString: constant('none()'),
  260. }
  261. return me
  262. })()
  263. var some = function (a) {
  264. var constant_a = constant(a)
  265. var self = function () {
  266. return me
  267. }
  268. var bind = function (f) {
  269. return f(a)
  270. }
  271. var me = {
  272. fold: function (n, s) {
  273. return s(a)
  274. },
  275. isSome: always,
  276. isNone: never,
  277. getOr: constant_a,
  278. getOrThunk: constant_a,
  279. getOrDie: constant_a,
  280. getOrNull: constant_a,
  281. getOrUndefined: constant_a,
  282. or: self,
  283. orThunk: self,
  284. map: function (f) {
  285. return some(f(a))
  286. },
  287. each: function (f) {
  288. f(a)
  289. },
  290. bind: bind,
  291. exists: bind,
  292. forall: bind,
  293. filter: function (f) {
  294. return f(a) ? me : NONE
  295. },
  296. toArray: function () {
  297. return [a]
  298. },
  299. toString: function () {
  300. return 'some(' + a + ')'
  301. },
  302. }
  303. return me
  304. }
  305. var from$1 = function (value) {
  306. return value === null || value === undefined ? NONE : some(value)
  307. }
  308. var Optional = {
  309. some: some,
  310. none: none,
  311. from: from$1,
  312. }
  313. var nativeSlice = Array.prototype.slice
  314. var nativeIndexOf = Array.prototype.indexOf
  315. var nativePush = Array.prototype.push
  316. var rawIndexOf = function (ts, t) {
  317. return nativeIndexOf.call(ts, t)
  318. }
  319. var indexOf$2 = function (xs, x) {
  320. var r = rawIndexOf(xs, x)
  321. return r === -1 ? Optional.none() : Optional.some(r)
  322. }
  323. var contains$3 = function (xs, x) {
  324. return rawIndexOf(xs, x) > -1
  325. }
  326. var exists = function (xs, pred) {
  327. for (var i = 0, len = xs.length; i < len; i++) {
  328. var x = xs[i]
  329. if (pred(x, i)) {
  330. return true
  331. }
  332. }
  333. return false
  334. }
  335. var map$3 = function (xs, f) {
  336. var len = xs.length
  337. var r = new Array(len)
  338. for (var i = 0; i < len; i++) {
  339. var x = xs[i]
  340. r[i] = f(x, i)
  341. }
  342. return r
  343. }
  344. var each$k = function (xs, f) {
  345. for (var i = 0, len = xs.length; i < len; i++) {
  346. var x = xs[i]
  347. f(x, i)
  348. }
  349. }
  350. var eachr = function (xs, f) {
  351. for (var i = xs.length - 1; i >= 0; i--) {
  352. var x = xs[i]
  353. f(x, i)
  354. }
  355. }
  356. var partition = function (xs, pred) {
  357. var pass = []
  358. var fail = []
  359. for (var i = 0, len = xs.length; i < len; i++) {
  360. var x = xs[i]
  361. var arr = pred(x, i) ? pass : fail
  362. arr.push(x)
  363. }
  364. return {
  365. pass: pass,
  366. fail: fail,
  367. }
  368. }
  369. var filter$4 = function (xs, pred) {
  370. var r = []
  371. for (var i = 0, len = xs.length; i < len; i++) {
  372. var x = xs[i]
  373. if (pred(x, i)) {
  374. r.push(x)
  375. }
  376. }
  377. return r
  378. }
  379. var foldr = function (xs, f, acc) {
  380. eachr(xs, function (x, i) {
  381. acc = f(acc, x, i)
  382. })
  383. return acc
  384. }
  385. var foldl = function (xs, f, acc) {
  386. each$k(xs, function (x, i) {
  387. acc = f(acc, x, i)
  388. })
  389. return acc
  390. }
  391. var findUntil$1 = function (xs, pred, until) {
  392. for (var i = 0, len = xs.length; i < len; i++) {
  393. var x = xs[i]
  394. if (pred(x, i)) {
  395. return Optional.some(x)
  396. } else if (until(x, i)) {
  397. break
  398. }
  399. }
  400. return Optional.none()
  401. }
  402. var find$3 = function (xs, pred) {
  403. return findUntil$1(xs, pred, never)
  404. }
  405. var findIndex$2 = function (xs, pred) {
  406. for (var i = 0, len = xs.length; i < len; i++) {
  407. var x = xs[i]
  408. if (pred(x, i)) {
  409. return Optional.some(i)
  410. }
  411. }
  412. return Optional.none()
  413. }
  414. var flatten = function (xs) {
  415. var r = []
  416. for (var i = 0, len = xs.length; i < len; ++i) {
  417. if (!isArray$1(xs[i])) {
  418. throw new Error(
  419. 'Arr.flatten item ' + i + ' was not an array, input: ' + xs
  420. )
  421. }
  422. nativePush.apply(r, xs[i])
  423. }
  424. return r
  425. }
  426. var bind = function (xs, f) {
  427. return flatten(map$3(xs, f))
  428. }
  429. var forall = function (xs, pred) {
  430. for (var i = 0, len = xs.length; i < len; ++i) {
  431. var x = xs[i]
  432. if (pred(x, i) !== true) {
  433. return false
  434. }
  435. }
  436. return true
  437. }
  438. var reverse = function (xs) {
  439. var r = nativeSlice.call(xs, 0)
  440. r.reverse()
  441. return r
  442. }
  443. var difference = function (a1, a2) {
  444. return filter$4(a1, function (x) {
  445. return !contains$3(a2, x)
  446. })
  447. }
  448. var mapToObject = function (xs, f) {
  449. var r = {}
  450. for (var i = 0, len = xs.length; i < len; i++) {
  451. var x = xs[i]
  452. r[String(x)] = f(x, i)
  453. }
  454. return r
  455. }
  456. var sort = function (xs, comparator) {
  457. var copy = nativeSlice.call(xs, 0)
  458. copy.sort(comparator)
  459. return copy
  460. }
  461. var get$a = function (xs, i) {
  462. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none()
  463. }
  464. var head = function (xs) {
  465. return get$a(xs, 0)
  466. }
  467. var last$2 = function (xs) {
  468. return get$a(xs, xs.length - 1)
  469. }
  470. var from = isFunction(Array.from)
  471. ? Array.from
  472. : function (x) {
  473. return nativeSlice.call(x)
  474. }
  475. var findMap = function (arr, f) {
  476. for (var i = 0; i < arr.length; i++) {
  477. var r = f(arr[i], i)
  478. if (r.isSome()) {
  479. return r
  480. }
  481. }
  482. return Optional.none()
  483. }
  484. var keys = Object.keys
  485. var hasOwnProperty$1 = Object.hasOwnProperty
  486. var each$j = function (obj, f) {
  487. var props = keys(obj)
  488. for (var k = 0, len = props.length; k < len; k++) {
  489. var i = props[k]
  490. var x = obj[i]
  491. f(x, i)
  492. }
  493. }
  494. var map$2 = function (obj, f) {
  495. return tupleMap(obj, function (x, i) {
  496. return {
  497. k: i,
  498. v: f(x, i),
  499. }
  500. })
  501. }
  502. var tupleMap = function (obj, f) {
  503. var r = {}
  504. each$j(obj, function (x, i) {
  505. var tuple = f(x, i)
  506. r[tuple.k] = tuple.v
  507. })
  508. return r
  509. }
  510. var objAcc = function (r) {
  511. return function (x, i) {
  512. r[i] = x
  513. }
  514. }
  515. var internalFilter = function (obj, pred, onTrue, onFalse) {
  516. var r = {}
  517. each$j(obj, function (x, i) {
  518. ;(pred(x, i) ? onTrue : onFalse)(x, i)
  519. })
  520. return r
  521. }
  522. var bifilter = function (obj, pred) {
  523. var t = {}
  524. var f = {}
  525. internalFilter(obj, pred, objAcc(t), objAcc(f))
  526. return {
  527. t: t,
  528. f: f,
  529. }
  530. }
  531. var filter$3 = function (obj, pred) {
  532. var t = {}
  533. internalFilter(obj, pred, objAcc(t), noop)
  534. return t
  535. }
  536. var mapToArray = function (obj, f) {
  537. var r = []
  538. each$j(obj, function (value, name) {
  539. r.push(f(value, name))
  540. })
  541. return r
  542. }
  543. var values = function (obj) {
  544. return mapToArray(obj, identity)
  545. }
  546. var get$9 = function (obj, key) {
  547. return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none()
  548. }
  549. var has$2 = function (obj, key) {
  550. return hasOwnProperty$1.call(obj, key)
  551. }
  552. var hasNonNullableKey = function (obj, key) {
  553. return has$2(obj, key) && obj[key] !== undefined && obj[key] !== null
  554. }
  555. var equal$1 = function (a1, a2, eq) {
  556. if (eq === void 0) {
  557. eq = eqAny
  558. }
  559. return eqRecord(eq).eq(a1, a2)
  560. }
  561. var isArray = Array.isArray
  562. var toArray$1 = function (obj) {
  563. if (!isArray(obj)) {
  564. var array = []
  565. for (var i = 0, l = obj.length; i < l; i++) {
  566. array[i] = obj[i]
  567. }
  568. return array
  569. } else {
  570. return obj
  571. }
  572. }
  573. var each$i = function (o, cb, s) {
  574. var n, l
  575. if (!o) {
  576. return false
  577. }
  578. s = s || o
  579. if (o.length !== undefined) {
  580. for (n = 0, l = o.length; n < l; n++) {
  581. if (cb.call(s, o[n], n, o) === false) {
  582. return false
  583. }
  584. }
  585. } else {
  586. for (n in o) {
  587. if (has$2(o, n)) {
  588. if (cb.call(s, o[n], n, o) === false) {
  589. return false
  590. }
  591. }
  592. }
  593. }
  594. return true
  595. }
  596. var map$1 = function (array, callback) {
  597. var out = []
  598. each$i(array, function (item, index) {
  599. out.push(callback(item, index, array))
  600. })
  601. return out
  602. }
  603. var filter$2 = function (a, f) {
  604. var o = []
  605. each$i(a, function (v, index) {
  606. if (!f || f(v, index, a)) {
  607. o.push(v)
  608. }
  609. })
  610. return o
  611. }
  612. var indexOf$1 = function (a, v) {
  613. if (a) {
  614. for (var i = 0, l = a.length; i < l; i++) {
  615. if (a[i] === v) {
  616. return i
  617. }
  618. }
  619. }
  620. return -1
  621. }
  622. var reduce = function (collection, iteratee, accumulator, thisArg) {
  623. var acc = isUndefined(accumulator) ? collection[0] : accumulator
  624. for (var i = 0; i < collection.length; i++) {
  625. acc = iteratee.call(thisArg, acc, collection[i], i)
  626. }
  627. return acc
  628. }
  629. var findIndex$1 = function (array, predicate, thisArg) {
  630. var i, l
  631. for (i = 0, l = array.length; i < l; i++) {
  632. if (predicate.call(thisArg, array[i], i, array)) {
  633. return i
  634. }
  635. }
  636. return -1
  637. }
  638. var last$1 = function (collection) {
  639. return collection[collection.length - 1]
  640. }
  641. var __assign = function () {
  642. __assign =
  643. Object.assign ||
  644. function __assign(t) {
  645. for (var s, i = 1, n = arguments.length; i < n; i++) {
  646. s = arguments[i]
  647. for (var p in s)
  648. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]
  649. }
  650. return t
  651. }
  652. return __assign.apply(this, arguments)
  653. }
  654. function __rest(s, e) {
  655. var t = {}
  656. for (var p in s)
  657. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  658. t[p] = s[p]
  659. if (s != null && typeof Object.getOwnPropertySymbols === 'function')
  660. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  661. if (
  662. e.indexOf(p[i]) < 0 &&
  663. Object.prototype.propertyIsEnumerable.call(s, p[i])
  664. )
  665. t[p[i]] = s[p[i]]
  666. }
  667. return t
  668. }
  669. function __spreadArray(to, from, pack) {
  670. if (pack || arguments.length === 2)
  671. for (var i = 0, l = from.length, ar; i < l; i++) {
  672. if (ar || !(i in from)) {
  673. if (!ar) ar = Array.prototype.slice.call(from, 0, i)
  674. ar[i] = from[i]
  675. }
  676. }
  677. return to.concat(ar || Array.prototype.slice.call(from))
  678. }
  679. var cached = function (f) {
  680. var called = false
  681. var r
  682. return function () {
  683. var args = []
  684. for (var _i = 0; _i < arguments.length; _i++) {
  685. args[_i] = arguments[_i]
  686. }
  687. if (!called) {
  688. called = true
  689. r = f.apply(null, args)
  690. }
  691. return r
  692. }
  693. }
  694. var DeviceType = function (os, browser, userAgent, mediaMatch) {
  695. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true
  696. var isiPhone = os.isiOS() && !isiPad
  697. var isMobile = os.isiOS() || os.isAndroid()
  698. var isTouch = isMobile || mediaMatch('(pointer:coarse)')
  699. var isTablet =
  700. isiPad ||
  701. (!isiPhone && isMobile && mediaMatch('(min-device-width:768px)'))
  702. var isPhone = isiPhone || (isMobile && !isTablet)
  703. var iOSwebview =
  704. browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false
  705. var isDesktop = !isPhone && !isTablet && !iOSwebview
  706. return {
  707. isiPad: constant(isiPad),
  708. isiPhone: constant(isiPhone),
  709. isTablet: constant(isTablet),
  710. isPhone: constant(isPhone),
  711. isTouch: constant(isTouch),
  712. isAndroid: os.isAndroid,
  713. isiOS: os.isiOS,
  714. isWebView: constant(iOSwebview),
  715. isDesktop: constant(isDesktop),
  716. }
  717. }
  718. var firstMatch = function (regexes, s) {
  719. for (var i = 0; i < regexes.length; i++) {
  720. var x = regexes[i]
  721. if (x.test(s)) {
  722. return x
  723. }
  724. }
  725. return undefined
  726. }
  727. var find$2 = function (regexes, agent) {
  728. var r = firstMatch(regexes, agent)
  729. if (!r) {
  730. return {
  731. major: 0,
  732. minor: 0,
  733. }
  734. }
  735. var group = function (i) {
  736. return Number(agent.replace(r, '$' + i))
  737. }
  738. return nu$4(group(1), group(2))
  739. }
  740. var detect$3 = function (versionRegexes, agent) {
  741. var cleanedAgent = String(agent).toLowerCase()
  742. if (versionRegexes.length === 0) {
  743. return unknown$2()
  744. }
  745. return find$2(versionRegexes, cleanedAgent)
  746. }
  747. var unknown$2 = function () {
  748. return nu$4(0, 0)
  749. }
  750. var nu$4 = function (major, minor) {
  751. return {
  752. major: major,
  753. minor: minor,
  754. }
  755. }
  756. var Version = {
  757. nu: nu$4,
  758. detect: detect$3,
  759. unknown: unknown$2,
  760. }
  761. var detectBrowser$1 = function (browsers, userAgentData) {
  762. return findMap(userAgentData.brands, function (uaBrand) {
  763. var lcBrand = uaBrand.brand.toLowerCase()
  764. return find$3(browsers, function (browser) {
  765. var _a
  766. return (
  767. lcBrand ===
  768. ((_a = browser.brand) === null || _a === void 0
  769. ? void 0
  770. : _a.toLowerCase())
  771. )
  772. }).map(function (info) {
  773. return {
  774. current: info.name,
  775. version: Version.nu(parseInt(uaBrand.version, 10), 0),
  776. }
  777. })
  778. })
  779. }
  780. var detect$2 = function (candidates, userAgent) {
  781. var agent = String(userAgent).toLowerCase()
  782. return find$3(candidates, function (candidate) {
  783. return candidate.search(agent)
  784. })
  785. }
  786. var detectBrowser = function (browsers, userAgent) {
  787. return detect$2(browsers, userAgent).map(function (browser) {
  788. var version = Version.detect(browser.versionRegexes, userAgent)
  789. return {
  790. current: browser.name,
  791. version: version,
  792. }
  793. })
  794. }
  795. var detectOs = function (oses, userAgent) {
  796. return detect$2(oses, userAgent).map(function (os) {
  797. var version = Version.detect(os.versionRegexes, userAgent)
  798. return {
  799. current: os.name,
  800. version: version,
  801. }
  802. })
  803. }
  804. var removeFromStart = function (str, numChars) {
  805. return str.substring(numChars)
  806. }
  807. var checkRange = function (str, substr, start) {
  808. return (
  809. substr === '' ||
  810. (str.length >= substr.length &&
  811. str.substr(start, start + substr.length) === substr)
  812. )
  813. }
  814. var removeLeading = function (str, prefix) {
  815. return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str
  816. }
  817. var contains$2 = function (str, substr) {
  818. return str.indexOf(substr) !== -1
  819. }
  820. var startsWith = function (str, prefix) {
  821. return checkRange(str, prefix, 0)
  822. }
  823. var blank = function (r) {
  824. return function (s) {
  825. return s.replace(r, '')
  826. }
  827. }
  828. var trim$4 = blank(/^\s+|\s+$/g)
  829. var lTrim = blank(/^\s+/g)
  830. var rTrim = blank(/\s+$/g)
  831. var isNotEmpty = function (s) {
  832. return s.length > 0
  833. }
  834. var isEmpty$3 = function (s) {
  835. return !isNotEmpty(s)
  836. }
  837. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/
  838. var checkContains = function (target) {
  839. return function (uastring) {
  840. return contains$2(uastring, target)
  841. }
  842. }
  843. var browsers = [
  844. {
  845. name: 'Edge',
  846. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  847. search: function (uastring) {
  848. return (
  849. contains$2(uastring, 'edge/') &&
  850. contains$2(uastring, 'chrome') &&
  851. contains$2(uastring, 'safari') &&
  852. contains$2(uastring, 'applewebkit')
  853. )
  854. },
  855. },
  856. {
  857. name: 'Chrome',
  858. brand: 'Chromium',
  859. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/, normalVersionRegex],
  860. search: function (uastring) {
  861. return (
  862. contains$2(uastring, 'chrome') && !contains$2(uastring, 'chromeframe')
  863. )
  864. },
  865. },
  866. {
  867. name: 'IE',
  868. versionRegexes: [
  869. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  870. /.*?rv:([0-9]+)\.([0-9]+).*/,
  871. ],
  872. search: function (uastring) {
  873. return contains$2(uastring, 'msie') || contains$2(uastring, 'trident')
  874. },
  875. },
  876. {
  877. name: 'Opera',
  878. versionRegexes: [normalVersionRegex, /.*?opera\/([0-9]+)\.([0-9]+).*/],
  879. search: checkContains('opera'),
  880. },
  881. {
  882. name: 'Firefox',
  883. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  884. search: checkContains('firefox'),
  885. },
  886. {
  887. name: 'Safari',
  888. versionRegexes: [normalVersionRegex, /.*?cpu os ([0-9]+)_([0-9]+).*/],
  889. search: function (uastring) {
  890. return (
  891. (contains$2(uastring, 'safari') || contains$2(uastring, 'mobile/')) &&
  892. contains$2(uastring, 'applewebkit')
  893. )
  894. },
  895. },
  896. ]
  897. var oses = [
  898. {
  899. name: 'Windows',
  900. search: checkContains('win'),
  901. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/],
  902. },
  903. {
  904. name: 'iOS',
  905. search: function (uastring) {
  906. return contains$2(uastring, 'iphone') || contains$2(uastring, 'ipad')
  907. },
  908. versionRegexes: [
  909. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  910. /.*cpu os ([0-9]+)_([0-9]+).*/,
  911. /.*cpu iphone os ([0-9]+)_([0-9]+).*/,
  912. ],
  913. },
  914. {
  915. name: 'Android',
  916. search: checkContains('android'),
  917. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/],
  918. },
  919. {
  920. name: 'OSX',
  921. search: checkContains('mac os x'),
  922. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/],
  923. },
  924. {
  925. name: 'Linux',
  926. search: checkContains('linux'),
  927. versionRegexes: [],
  928. },
  929. {
  930. name: 'Solaris',
  931. search: checkContains('sunos'),
  932. versionRegexes: [],
  933. },
  934. {
  935. name: 'FreeBSD',
  936. search: checkContains('freebsd'),
  937. versionRegexes: [],
  938. },
  939. {
  940. name: 'ChromeOS',
  941. search: checkContains('cros'),
  942. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/],
  943. },
  944. ]
  945. var PlatformInfo = {
  946. browsers: constant(browsers),
  947. oses: constant(oses),
  948. }
  949. var edge = 'Edge'
  950. var chrome = 'Chrome'
  951. var ie$1 = 'IE'
  952. var opera = 'Opera'
  953. var firefox = 'Firefox'
  954. var safari = 'Safari'
  955. var unknown$1 = function () {
  956. return nu$3({
  957. current: undefined,
  958. version: Version.unknown(),
  959. })
  960. }
  961. var nu$3 = function (info) {
  962. var current = info.current
  963. var version = info.version
  964. var isBrowser = function (name) {
  965. return function () {
  966. return current === name
  967. }
  968. }
  969. return {
  970. current: current,
  971. version: version,
  972. isEdge: isBrowser(edge),
  973. isChrome: isBrowser(chrome),
  974. isIE: isBrowser(ie$1),
  975. isOpera: isBrowser(opera),
  976. isFirefox: isBrowser(firefox),
  977. isSafari: isBrowser(safari),
  978. }
  979. }
  980. var Browser = {
  981. unknown: unknown$1,
  982. nu: nu$3,
  983. edge: constant(edge),
  984. chrome: constant(chrome),
  985. ie: constant(ie$1),
  986. opera: constant(opera),
  987. firefox: constant(firefox),
  988. safari: constant(safari),
  989. }
  990. var windows = 'Windows'
  991. var ios = 'iOS'
  992. var android = 'Android'
  993. var linux = 'Linux'
  994. var osx = 'OSX'
  995. var solaris = 'Solaris'
  996. var freebsd = 'FreeBSD'
  997. var chromeos = 'ChromeOS'
  998. var unknown = function () {
  999. return nu$2({
  1000. current: undefined,
  1001. version: Version.unknown(),
  1002. })
  1003. }
  1004. var nu$2 = function (info) {
  1005. var current = info.current
  1006. var version = info.version
  1007. var isOS = function (name) {
  1008. return function () {
  1009. return current === name
  1010. }
  1011. }
  1012. return {
  1013. current: current,
  1014. version: version,
  1015. isWindows: isOS(windows),
  1016. isiOS: isOS(ios),
  1017. isAndroid: isOS(android),
  1018. isOSX: isOS(osx),
  1019. isLinux: isOS(linux),
  1020. isSolaris: isOS(solaris),
  1021. isFreeBSD: isOS(freebsd),
  1022. isChromeOS: isOS(chromeos),
  1023. }
  1024. }
  1025. var OperatingSystem = {
  1026. unknown: unknown,
  1027. nu: nu$2,
  1028. windows: constant(windows),
  1029. ios: constant(ios),
  1030. android: constant(android),
  1031. linux: constant(linux),
  1032. osx: constant(osx),
  1033. solaris: constant(solaris),
  1034. freebsd: constant(freebsd),
  1035. chromeos: constant(chromeos),
  1036. }
  1037. var detect$1 = function (userAgent, userAgentDataOpt, mediaMatch) {
  1038. var browsers = PlatformInfo.browsers()
  1039. var oses = PlatformInfo.oses()
  1040. var browser = userAgentDataOpt
  1041. .bind(function (userAgentData) {
  1042. return detectBrowser$1(browsers, userAgentData)
  1043. })
  1044. .orThunk(function () {
  1045. return detectBrowser(browsers, userAgent)
  1046. })
  1047. .fold(Browser.unknown, Browser.nu)
  1048. var os = detectOs(oses, userAgent).fold(
  1049. OperatingSystem.unknown,
  1050. OperatingSystem.nu
  1051. )
  1052. var deviceType = DeviceType(os, browser, userAgent, mediaMatch)
  1053. return {
  1054. browser: browser,
  1055. os: os,
  1056. deviceType: deviceType,
  1057. }
  1058. }
  1059. var PlatformDetection = { detect: detect$1 }
  1060. var mediaMatch = function (query) {
  1061. return window.matchMedia(query).matches
  1062. }
  1063. var platform$2 = cached(function () {
  1064. return PlatformDetection.detect(
  1065. navigator.userAgent,
  1066. Optional.from(navigator.userAgentData),
  1067. mediaMatch
  1068. )
  1069. })
  1070. var detect = function () {
  1071. return platform$2()
  1072. }
  1073. var userAgent = navigator.userAgent
  1074. var platform$1 = detect()
  1075. var browser$4 = platform$1.browser
  1076. var os = platform$1.os
  1077. var deviceType = platform$1.deviceType
  1078. var webkit = /WebKit/.test(userAgent) && !browser$4.isEdge()
  1079. var fileApi =
  1080. 'FormData' in window &&
  1081. 'FileReader' in window &&
  1082. 'URL' in window &&
  1083. !!URL.createObjectURL
  1084. var windowsPhone = userAgent.indexOf('Windows Phone') !== -1
  1085. var Env = {
  1086. opera: browser$4.isOpera(),
  1087. webkit: webkit,
  1088. ie:
  1089. browser$4.isIE() || browser$4.isEdge() ? browser$4.version.major : false,
  1090. gecko: browser$4.isFirefox(),
  1091. mac: os.isOSX() || os.isiOS(),
  1092. iOS: deviceType.isiPad() || deviceType.isiPhone(),
  1093. android: os.isAndroid(),
  1094. contentEditable: true,
  1095. transparentSrc:
  1096. 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  1097. caretAfter: true,
  1098. range: window.getSelection && 'Range' in window,
  1099. documentMode: browser$4.isIE() ? document.documentMode || 7 : 10,
  1100. fileApi: fileApi,
  1101. ceFalse: true,
  1102. cacheSuffix: null,
  1103. container: null,
  1104. experimentalShadowDom: false,
  1105. canHaveCSP: !browser$4.isIE(),
  1106. desktop: deviceType.isDesktop(),
  1107. windowsPhone: windowsPhone,
  1108. browser: {
  1109. current: browser$4.current,
  1110. version: browser$4.version,
  1111. isChrome: browser$4.isChrome,
  1112. isEdge: browser$4.isEdge,
  1113. isFirefox: browser$4.isFirefox,
  1114. isIE: browser$4.isIE,
  1115. isOpera: browser$4.isOpera,
  1116. isSafari: browser$4.isSafari,
  1117. },
  1118. os: {
  1119. current: os.current,
  1120. version: os.version,
  1121. isAndroid: os.isAndroid,
  1122. isChromeOS: os.isChromeOS,
  1123. isFreeBSD: os.isFreeBSD,
  1124. isiOS: os.isiOS,
  1125. isLinux: os.isLinux,
  1126. isOSX: os.isOSX,
  1127. isSolaris: os.isSolaris,
  1128. isWindows: os.isWindows,
  1129. },
  1130. deviceType: {
  1131. isDesktop: deviceType.isDesktop,
  1132. isiPad: deviceType.isiPad,
  1133. isiPhone: deviceType.isiPhone,
  1134. isPhone: deviceType.isPhone,
  1135. isTablet: deviceType.isTablet,
  1136. isTouch: deviceType.isTouch,
  1137. isWebView: deviceType.isWebView,
  1138. },
  1139. }
  1140. var whiteSpaceRegExp$2 = /^\s*|\s*$/g
  1141. var trim$3 = function (str) {
  1142. return str === null || str === undefined
  1143. ? ''
  1144. : ('' + str).replace(whiteSpaceRegExp$2, '')
  1145. }
  1146. var is$3 = function (obj, type) {
  1147. if (!type) {
  1148. return obj !== undefined
  1149. }
  1150. if (type === 'array' && isArray(obj)) {
  1151. return true
  1152. }
  1153. return typeof obj === type
  1154. }
  1155. var makeMap$4 = function (items, delim, map) {
  1156. var i
  1157. items = items || []
  1158. delim = delim || ','
  1159. if (typeof items === 'string') {
  1160. items = items.split(delim)
  1161. }
  1162. map = map || {}
  1163. i = items.length
  1164. while (i--) {
  1165. map[items[i]] = {}
  1166. }
  1167. return map
  1168. }
  1169. var hasOwnProperty = has$2
  1170. var create$9 = function (s, p, root) {
  1171. var self = this
  1172. var sp,
  1173. scn,
  1174. c,
  1175. de = 0
  1176. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s)
  1177. var cn = s[3].match(/(^|\.)(\w+)$/i)[2]
  1178. var ns = self.createNS(s[3].replace(/\.\w+$/, ''), root)
  1179. if (ns[cn]) {
  1180. return
  1181. }
  1182. if (s[2] === 'static') {
  1183. ns[cn] = p
  1184. if (this.onCreate) {
  1185. this.onCreate(s[2], s[3], ns[cn])
  1186. }
  1187. return
  1188. }
  1189. if (!p[cn]) {
  1190. p[cn] = function () {}
  1191. de = 1
  1192. }
  1193. ns[cn] = p[cn]
  1194. self.extend(ns[cn].prototype, p)
  1195. if (s[5]) {
  1196. sp = self.resolve(s[5]).prototype
  1197. scn = s[5].match(/\.(\w+)$/i)[1]
  1198. c = ns[cn]
  1199. if (de) {
  1200. ns[cn] = function () {
  1201. return sp[scn].apply(this, arguments)
  1202. }
  1203. } else {
  1204. ns[cn] = function () {
  1205. this.parent = sp[scn]
  1206. return c.apply(this, arguments)
  1207. }
  1208. }
  1209. ns[cn].prototype[cn] = ns[cn]
  1210. self.each(sp, function (f, n) {
  1211. ns[cn].prototype[n] = sp[n]
  1212. })
  1213. self.each(p, function (f, n) {
  1214. if (sp[n]) {
  1215. ns[cn].prototype[n] = function () {
  1216. this.parent = sp[n]
  1217. return f.apply(this, arguments)
  1218. }
  1219. } else {
  1220. if (n !== cn) {
  1221. ns[cn].prototype[n] = f
  1222. }
  1223. }
  1224. })
  1225. }
  1226. self.each(p.static, function (f, n) {
  1227. ns[cn][n] = f
  1228. })
  1229. }
  1230. var extend$6 = function (obj) {
  1231. var exts = []
  1232. for (var _i = 1; _i < arguments.length; _i++) {
  1233. exts[_i - 1] = arguments[_i]
  1234. }
  1235. for (var i = 0; i < exts.length; i++) {
  1236. var ext = exts[i]
  1237. for (var name_1 in ext) {
  1238. if (has$2(ext, name_1)) {
  1239. var value = ext[name_1]
  1240. if (value !== undefined) {
  1241. obj[name_1] = value
  1242. }
  1243. }
  1244. }
  1245. }
  1246. return obj
  1247. }
  1248. var walk$3 = function (o, f, n, s) {
  1249. s = s || this
  1250. if (o) {
  1251. if (n) {
  1252. o = o[n]
  1253. }
  1254. each$i(o, function (o, i) {
  1255. if (f.call(s, o, i, n) === false) {
  1256. return false
  1257. }
  1258. walk$3(o, f, n, s)
  1259. })
  1260. }
  1261. }
  1262. var createNS = function (n, o) {
  1263. var i, v
  1264. o = o || window
  1265. n = n.split('.')
  1266. for (i = 0; i < n.length; i++) {
  1267. v = n[i]
  1268. if (!o[v]) {
  1269. o[v] = {}
  1270. }
  1271. o = o[v]
  1272. }
  1273. return o
  1274. }
  1275. var resolve$3 = function (n, o) {
  1276. var i, l
  1277. o = o || window
  1278. n = n.split('.')
  1279. for (i = 0, l = n.length; i < l; i++) {
  1280. o = o[n[i]]
  1281. if (!o) {
  1282. break
  1283. }
  1284. }
  1285. return o
  1286. }
  1287. var explode$4 = function (s, d) {
  1288. if (!s || is$3(s, 'array')) {
  1289. return s
  1290. }
  1291. return map$1(s.split(d || ','), trim$3)
  1292. }
  1293. var _addCacheSuffix = function (url) {
  1294. var cacheSuffix = Env.cacheSuffix
  1295. if (cacheSuffix) {
  1296. url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix
  1297. }
  1298. return url
  1299. }
  1300. var Tools = {
  1301. trim: trim$3,
  1302. isArray: isArray,
  1303. is: is$3,
  1304. toArray: toArray$1,
  1305. makeMap: makeMap$4,
  1306. each: each$i,
  1307. map: map$1,
  1308. grep: filter$2,
  1309. inArray: indexOf$1,
  1310. hasOwn: hasOwnProperty,
  1311. extend: extend$6,
  1312. create: create$9,
  1313. walk: walk$3,
  1314. createNS: createNS,
  1315. resolve: resolve$3,
  1316. explode: explode$4,
  1317. _addCacheSuffix: _addCacheSuffix,
  1318. }
  1319. var fromHtml$1 = function (html, scope) {
  1320. var doc = scope || document
  1321. var div = doc.createElement('div')
  1322. div.innerHTML = html
  1323. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  1324. console.error('HTML does not have a single root node', html)
  1325. throw new Error('HTML must have a single root node')
  1326. }
  1327. return fromDom$2(div.childNodes[0])
  1328. }
  1329. var fromTag = function (tag, scope) {
  1330. var doc = scope || document
  1331. var node = doc.createElement(tag)
  1332. return fromDom$2(node)
  1333. }
  1334. var fromText = function (text, scope) {
  1335. var doc = scope || document
  1336. var node = doc.createTextNode(text)
  1337. return fromDom$2(node)
  1338. }
  1339. var fromDom$2 = function (node) {
  1340. if (node === null || node === undefined) {
  1341. throw new Error('Node cannot be null or undefined')
  1342. }
  1343. return { dom: node }
  1344. }
  1345. var fromPoint$1 = function (docElm, x, y) {
  1346. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$2)
  1347. }
  1348. var SugarElement = {
  1349. fromHtml: fromHtml$1,
  1350. fromTag: fromTag,
  1351. fromText: fromText,
  1352. fromDom: fromDom$2,
  1353. fromPoint: fromPoint$1,
  1354. }
  1355. var toArray = function (target, f) {
  1356. var r = []
  1357. var recurse = function (e) {
  1358. r.push(e)
  1359. return f(e)
  1360. }
  1361. var cur = f(target)
  1362. do {
  1363. cur = cur.bind(recurse)
  1364. } while (cur.isSome())
  1365. return r
  1366. }
  1367. var compareDocumentPosition = function (a, b, match) {
  1368. return (a.compareDocumentPosition(b) & match) !== 0
  1369. }
  1370. var documentPositionContainedBy = function (a, b) {
  1371. return compareDocumentPosition(a, b, Node.DOCUMENT_POSITION_CONTAINED_BY)
  1372. }
  1373. var COMMENT = 8
  1374. var DOCUMENT = 9
  1375. var DOCUMENT_FRAGMENT = 11
  1376. var ELEMENT = 1
  1377. var TEXT = 3
  1378. var is$2 = function (element, selector) {
  1379. var dom = element.dom
  1380. if (dom.nodeType !== ELEMENT) {
  1381. return false
  1382. } else {
  1383. var elem = dom
  1384. if (elem.matches !== undefined) {
  1385. return elem.matches(selector)
  1386. } else if (elem.msMatchesSelector !== undefined) {
  1387. return elem.msMatchesSelector(selector)
  1388. } else if (elem.webkitMatchesSelector !== undefined) {
  1389. return elem.webkitMatchesSelector(selector)
  1390. } else if (elem.mozMatchesSelector !== undefined) {
  1391. return elem.mozMatchesSelector(selector)
  1392. } else {
  1393. throw new Error('Browser lacks native selectors')
  1394. }
  1395. }
  1396. }
  1397. var bypassSelector = function (dom) {
  1398. return (
  1399. (dom.nodeType !== ELEMENT &&
  1400. dom.nodeType !== DOCUMENT &&
  1401. dom.nodeType !== DOCUMENT_FRAGMENT) ||
  1402. dom.childElementCount === 0
  1403. )
  1404. }
  1405. var all = function (selector, scope) {
  1406. var base = scope === undefined ? document : scope.dom
  1407. return bypassSelector(base)
  1408. ? []
  1409. : map$3(base.querySelectorAll(selector), SugarElement.fromDom)
  1410. }
  1411. var one = function (selector, scope) {
  1412. var base = scope === undefined ? document : scope.dom
  1413. return bypassSelector(base)
  1414. ? Optional.none()
  1415. : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom)
  1416. }
  1417. var eq = function (e1, e2) {
  1418. return e1.dom === e2.dom
  1419. }
  1420. var regularContains = function (e1, e2) {
  1421. var d1 = e1.dom
  1422. var d2 = e2.dom
  1423. return d1 === d2 ? false : d1.contains(d2)
  1424. }
  1425. var ieContains = function (e1, e2) {
  1426. return documentPositionContainedBy(e1.dom, e2.dom)
  1427. }
  1428. var contains$1 = function (e1, e2) {
  1429. return detect().browser.isIE()
  1430. ? ieContains(e1, e2)
  1431. : regularContains(e1, e2)
  1432. }
  1433. typeof window !== 'undefined' ? window : Function('return this;')()
  1434. var name = function (element) {
  1435. var r = element.dom.nodeName
  1436. return r.toLowerCase()
  1437. }
  1438. var type = function (element) {
  1439. return element.dom.nodeType
  1440. }
  1441. var isType = function (t) {
  1442. return function (element) {
  1443. return type(element) === t
  1444. }
  1445. }
  1446. var isComment$1 = function (element) {
  1447. return type(element) === COMMENT || name(element) === '#comment'
  1448. }
  1449. var isElement$6 = isType(ELEMENT)
  1450. var isText$8 = isType(TEXT)
  1451. var isDocument$2 = isType(DOCUMENT)
  1452. var isDocumentFragment$1 = isType(DOCUMENT_FRAGMENT)
  1453. var isTag = function (tag) {
  1454. return function (e) {
  1455. return isElement$6(e) && name(e) === tag
  1456. }
  1457. }
  1458. var owner$1 = function (element) {
  1459. return SugarElement.fromDom(element.dom.ownerDocument)
  1460. }
  1461. var documentOrOwner = function (dos) {
  1462. return isDocument$2(dos) ? dos : owner$1(dos)
  1463. }
  1464. var documentElement = function (element) {
  1465. return SugarElement.fromDom(documentOrOwner(element).dom.documentElement)
  1466. }
  1467. var defaultView = function (element) {
  1468. return SugarElement.fromDom(documentOrOwner(element).dom.defaultView)
  1469. }
  1470. var parent = function (element) {
  1471. return Optional.from(element.dom.parentNode).map(SugarElement.fromDom)
  1472. }
  1473. var parents$1 = function (element, isRoot) {
  1474. var stop = isFunction(isRoot) ? isRoot : never
  1475. var dom = element.dom
  1476. var ret = []
  1477. while (dom.parentNode !== null && dom.parentNode !== undefined) {
  1478. var rawParent = dom.parentNode
  1479. var p = SugarElement.fromDom(rawParent)
  1480. ret.push(p)
  1481. if (stop(p) === true) {
  1482. break
  1483. } else {
  1484. dom = rawParent
  1485. }
  1486. }
  1487. return ret
  1488. }
  1489. var siblings = function (element) {
  1490. var filterSelf = function (elements) {
  1491. return filter$4(elements, function (x) {
  1492. return !eq(element, x)
  1493. })
  1494. }
  1495. return parent(element).map(children).map(filterSelf).getOr([])
  1496. }
  1497. var prevSibling = function (element) {
  1498. return Optional.from(element.dom.previousSibling).map(SugarElement.fromDom)
  1499. }
  1500. var nextSibling = function (element) {
  1501. return Optional.from(element.dom.nextSibling).map(SugarElement.fromDom)
  1502. }
  1503. var prevSiblings = function (element) {
  1504. return reverse(toArray(element, prevSibling))
  1505. }
  1506. var nextSiblings = function (element) {
  1507. return toArray(element, nextSibling)
  1508. }
  1509. var children = function (element) {
  1510. return map$3(element.dom.childNodes, SugarElement.fromDom)
  1511. }
  1512. var child$1 = function (element, index) {
  1513. var cs = element.dom.childNodes
  1514. return Optional.from(cs[index]).map(SugarElement.fromDom)
  1515. }
  1516. var firstChild = function (element) {
  1517. return child$1(element, 0)
  1518. }
  1519. var lastChild = function (element) {
  1520. return child$1(element, element.dom.childNodes.length - 1)
  1521. }
  1522. var childNodesCount = function (element) {
  1523. return element.dom.childNodes.length
  1524. }
  1525. var getHead = function (doc) {
  1526. var b = doc.dom.head
  1527. if (b === null || b === undefined) {
  1528. throw new Error('Head is not available yet')
  1529. }
  1530. return SugarElement.fromDom(b)
  1531. }
  1532. var isShadowRoot = function (dos) {
  1533. return isDocumentFragment$1(dos) && isNonNullable(dos.dom.host)
  1534. }
  1535. var supported =
  1536. isFunction(Element.prototype.attachShadow) &&
  1537. isFunction(Node.prototype.getRootNode)
  1538. var isSupported$1 = constant(supported)
  1539. var getRootNode = supported
  1540. ? function (e) {
  1541. return SugarElement.fromDom(e.dom.getRootNode())
  1542. }
  1543. : documentOrOwner
  1544. var getStyleContainer = function (dos) {
  1545. return isShadowRoot(dos) ? dos : getHead(documentOrOwner(dos))
  1546. }
  1547. var getShadowRoot = function (e) {
  1548. var r = getRootNode(e)
  1549. return isShadowRoot(r) ? Optional.some(r) : Optional.none()
  1550. }
  1551. var getShadowHost = function (e) {
  1552. return SugarElement.fromDom(e.dom.host)
  1553. }
  1554. var getOriginalEventTarget = function (event) {
  1555. if (isSupported$1() && isNonNullable(event.target)) {
  1556. var el = SugarElement.fromDom(event.target)
  1557. if (isElement$6(el) && isOpenShadowHost(el)) {
  1558. if (event.composed && event.composedPath) {
  1559. var composedPath = event.composedPath()
  1560. if (composedPath) {
  1561. return head(composedPath)
  1562. }
  1563. }
  1564. }
  1565. }
  1566. return Optional.from(event.target)
  1567. }
  1568. var isOpenShadowHost = function (element) {
  1569. return isNonNullable(element.dom.shadowRoot)
  1570. }
  1571. var before$4 = function (marker, element) {
  1572. var parent$1 = parent(marker)
  1573. parent$1.each(function (v) {
  1574. v.dom.insertBefore(element.dom, marker.dom)
  1575. })
  1576. }
  1577. var after$3 = function (marker, element) {
  1578. var sibling = nextSibling(marker)
  1579. sibling.fold(
  1580. function () {
  1581. var parent$1 = parent(marker)
  1582. parent$1.each(function (v) {
  1583. append$1(v, element)
  1584. })
  1585. },
  1586. function (v) {
  1587. before$4(v, element)
  1588. }
  1589. )
  1590. }
  1591. var prepend = function (parent, element) {
  1592. var firstChild$1 = firstChild(parent)
  1593. firstChild$1.fold(
  1594. function () {
  1595. append$1(parent, element)
  1596. },
  1597. function (v) {
  1598. parent.dom.insertBefore(element.dom, v.dom)
  1599. }
  1600. )
  1601. }
  1602. var append$1 = function (parent, element) {
  1603. parent.dom.appendChild(element.dom)
  1604. }
  1605. var wrap$3 = function (element, wrapper) {
  1606. before$4(element, wrapper)
  1607. append$1(wrapper, element)
  1608. }
  1609. var before$3 = function (marker, elements) {
  1610. each$k(elements, function (x) {
  1611. before$4(marker, x)
  1612. })
  1613. }
  1614. var append = function (parent, elements) {
  1615. each$k(elements, function (x) {
  1616. append$1(parent, x)
  1617. })
  1618. }
  1619. var empty = function (element) {
  1620. element.dom.textContent = ''
  1621. each$k(children(element), function (rogue) {
  1622. remove$7(rogue)
  1623. })
  1624. }
  1625. var remove$7 = function (element) {
  1626. var dom = element.dom
  1627. if (dom.parentNode !== null) {
  1628. dom.parentNode.removeChild(dom)
  1629. }
  1630. }
  1631. var unwrap = function (wrapper) {
  1632. var children$1 = children(wrapper)
  1633. if (children$1.length > 0) {
  1634. before$3(wrapper, children$1)
  1635. }
  1636. remove$7(wrapper)
  1637. }
  1638. var inBody = function (element) {
  1639. var dom = isText$8(element) ? element.dom.parentNode : element.dom
  1640. if (dom === undefined || dom === null || dom.ownerDocument === null) {
  1641. return false
  1642. }
  1643. var doc = dom.ownerDocument
  1644. return getShadowRoot(SugarElement.fromDom(dom)).fold(function () {
  1645. return doc.body.contains(dom)
  1646. }, compose1(inBody, getShadowHost))
  1647. }
  1648. var r = function (left, top) {
  1649. var translate = function (x, y) {
  1650. return r(left + x, top + y)
  1651. }
  1652. return {
  1653. left: left,
  1654. top: top,
  1655. translate: translate,
  1656. }
  1657. }
  1658. var SugarPosition = r
  1659. var boxPosition = function (dom) {
  1660. var box = dom.getBoundingClientRect()
  1661. return SugarPosition(box.left, box.top)
  1662. }
  1663. var firstDefinedOrZero = function (a, b) {
  1664. if (a !== undefined) {
  1665. return a
  1666. } else {
  1667. return b !== undefined ? b : 0
  1668. }
  1669. }
  1670. var absolute = function (element) {
  1671. var doc = element.dom.ownerDocument
  1672. var body = doc.body
  1673. var win = doc.defaultView
  1674. var html = doc.documentElement
  1675. if (body === element.dom) {
  1676. return SugarPosition(body.offsetLeft, body.offsetTop)
  1677. }
  1678. var scrollTop = firstDefinedOrZero(
  1679. win === null || win === void 0 ? void 0 : win.pageYOffset,
  1680. html.scrollTop
  1681. )
  1682. var scrollLeft = firstDefinedOrZero(
  1683. win === null || win === void 0 ? void 0 : win.pageXOffset,
  1684. html.scrollLeft
  1685. )
  1686. var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop)
  1687. var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft)
  1688. return viewport(element).translate(
  1689. scrollLeft - clientLeft,
  1690. scrollTop - clientTop
  1691. )
  1692. }
  1693. var viewport = function (element) {
  1694. var dom = element.dom
  1695. var doc = dom.ownerDocument
  1696. var body = doc.body
  1697. if (body === dom) {
  1698. return SugarPosition(body.offsetLeft, body.offsetTop)
  1699. }
  1700. if (!inBody(element)) {
  1701. return SugarPosition(0, 0)
  1702. }
  1703. return boxPosition(dom)
  1704. }
  1705. var get$8 = function (_DOC) {
  1706. var doc = _DOC !== undefined ? _DOC.dom : document
  1707. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft
  1708. var y = doc.body.scrollTop || doc.documentElement.scrollTop
  1709. return SugarPosition(x, y)
  1710. }
  1711. var to = function (x, y, _DOC) {
  1712. var doc = _DOC !== undefined ? _DOC.dom : document
  1713. var win = doc.defaultView
  1714. if (win) {
  1715. win.scrollTo(x, y)
  1716. }
  1717. }
  1718. var intoView = function (element, alignToTop) {
  1719. var isSafari = detect().browser.isSafari()
  1720. if (isSafari && isFunction(element.dom.scrollIntoViewIfNeeded)) {
  1721. element.dom.scrollIntoViewIfNeeded(false)
  1722. } else {
  1723. element.dom.scrollIntoView(alignToTop)
  1724. }
  1725. }
  1726. var get$7 = function (_win) {
  1727. var win = _win === undefined ? window : _win
  1728. if (detect().browser.isFirefox()) {
  1729. return Optional.none()
  1730. } else {
  1731. return Optional.from(win['visualViewport'])
  1732. }
  1733. }
  1734. var bounds = function (x, y, width, height) {
  1735. return {
  1736. x: x,
  1737. y: y,
  1738. width: width,
  1739. height: height,
  1740. right: x + width,
  1741. bottom: y + height,
  1742. }
  1743. }
  1744. var getBounds = function (_win) {
  1745. var win = _win === undefined ? window : _win
  1746. var doc = win.document
  1747. var scroll = get$8(SugarElement.fromDom(doc))
  1748. return get$7(win).fold(
  1749. function () {
  1750. var html = win.document.documentElement
  1751. var width = html.clientWidth
  1752. var height = html.clientHeight
  1753. return bounds(scroll.left, scroll.top, width, height)
  1754. },
  1755. function (visualViewport) {
  1756. return bounds(
  1757. Math.max(visualViewport.pageLeft, scroll.left),
  1758. Math.max(visualViewport.pageTop, scroll.top),
  1759. visualViewport.width,
  1760. visualViewport.height
  1761. )
  1762. }
  1763. )
  1764. }
  1765. var isNodeType = function (type) {
  1766. return function (node) {
  1767. return !!node && node.nodeType === type
  1768. }
  1769. }
  1770. var isRestrictedNode = function (node) {
  1771. return !!node && !Object.getPrototypeOf(node)
  1772. }
  1773. var isElement$5 = isNodeType(1)
  1774. var matchNodeNames = function (names) {
  1775. var lowercasedNames = names.map(function (s) {
  1776. return s.toLowerCase()
  1777. })
  1778. return function (node) {
  1779. if (node && node.nodeName) {
  1780. var nodeName = node.nodeName.toLowerCase()
  1781. return contains$3(lowercasedNames, nodeName)
  1782. }
  1783. return false
  1784. }
  1785. }
  1786. var matchStyleValues = function (name, values) {
  1787. var items = values.toLowerCase().split(' ')
  1788. return function (node) {
  1789. if (isElement$5(node)) {
  1790. for (var i = 0; i < items.length; i++) {
  1791. var computed = node.ownerDocument.defaultView.getComputedStyle(
  1792. node,
  1793. null
  1794. )
  1795. var cssValue = computed ? computed.getPropertyValue(name) : null
  1796. if (cssValue === items[i]) {
  1797. return true
  1798. }
  1799. }
  1800. }
  1801. return false
  1802. }
  1803. }
  1804. var hasAttribute = function (attrName) {
  1805. return function (node) {
  1806. return isElement$5(node) && node.hasAttribute(attrName)
  1807. }
  1808. }
  1809. var hasAttributeValue = function (attrName, attrValue) {
  1810. return function (node) {
  1811. return isElement$5(node) && node.getAttribute(attrName) === attrValue
  1812. }
  1813. }
  1814. var isBogus$2 = function (node) {
  1815. return isElement$5(node) && node.hasAttribute('data-mce-bogus')
  1816. }
  1817. var isBogusAll$1 = function (node) {
  1818. return isElement$5(node) && node.getAttribute('data-mce-bogus') === 'all'
  1819. }
  1820. var isTable$3 = function (node) {
  1821. return isElement$5(node) && node.tagName === 'TABLE'
  1822. }
  1823. var hasContentEditableState = function (value) {
  1824. return function (node) {
  1825. if (isElement$5(node)) {
  1826. if (node.contentEditable === value) {
  1827. return true
  1828. }
  1829. if (node.getAttribute('data-mce-contenteditable') === value) {
  1830. return true
  1831. }
  1832. }
  1833. return false
  1834. }
  1835. }
  1836. var isTextareaOrInput = matchNodeNames(['textarea', 'input'])
  1837. var isText$7 = isNodeType(3)
  1838. var isComment = isNodeType(8)
  1839. var isDocument$1 = isNodeType(9)
  1840. var isDocumentFragment = isNodeType(11)
  1841. var isBr$5 = matchNodeNames(['br'])
  1842. var isImg = matchNodeNames(['img'])
  1843. var isContentEditableTrue$4 = hasContentEditableState('true')
  1844. var isContentEditableFalse$b = hasContentEditableState('false')
  1845. var isTableCell$5 = matchNodeNames(['td', 'th'])
  1846. var isMedia$2 = matchNodeNames(['video', 'audio', 'object', 'embed'])
  1847. var is$1 = function (lhs, rhs, comparator) {
  1848. if (comparator === void 0) {
  1849. comparator = tripleEquals
  1850. }
  1851. return lhs.exists(function (left) {
  1852. return comparator(left, rhs)
  1853. })
  1854. }
  1855. var cat = function (arr) {
  1856. var r = []
  1857. var push = function (x) {
  1858. r.push(x)
  1859. }
  1860. for (var i = 0; i < arr.length; i++) {
  1861. arr[i].each(push)
  1862. }
  1863. return r
  1864. }
  1865. var lift2 = function (oa, ob, f) {
  1866. return oa.isSome() && ob.isSome()
  1867. ? Optional.some(f(oa.getOrDie(), ob.getOrDie()))
  1868. : Optional.none()
  1869. }
  1870. var lift3 = function (oa, ob, oc, f) {
  1871. return oa.isSome() && ob.isSome() && oc.isSome()
  1872. ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie()))
  1873. : Optional.none()
  1874. }
  1875. var someIf = function (b, a) {
  1876. return b ? Optional.some(a) : Optional.none()
  1877. }
  1878. var isSupported = function (dom) {
  1879. return dom.style !== undefined && isFunction(dom.style.getPropertyValue)
  1880. }
  1881. var rawSet = function (dom, key, value) {
  1882. if (isString$1(value) || isBoolean(value) || isNumber(value)) {
  1883. dom.setAttribute(key, value + '')
  1884. } else {
  1885. console.error(
  1886. 'Invalid call to Attribute.set. Key ',
  1887. key,
  1888. ':: Value ',
  1889. value,
  1890. ':: Element ',
  1891. dom
  1892. )
  1893. throw new Error('Attribute value was not simple')
  1894. }
  1895. }
  1896. var set$1 = function (element, key, value) {
  1897. rawSet(element.dom, key, value)
  1898. }
  1899. var setAll$1 = function (element, attrs) {
  1900. var dom = element.dom
  1901. each$j(attrs, function (v, k) {
  1902. rawSet(dom, k, v)
  1903. })
  1904. }
  1905. var get$6 = function (element, key) {
  1906. var v = element.dom.getAttribute(key)
  1907. return v === null ? undefined : v
  1908. }
  1909. var getOpt = function (element, key) {
  1910. return Optional.from(get$6(element, key))
  1911. }
  1912. var has$1 = function (element, key) {
  1913. var dom = element.dom
  1914. return dom && dom.hasAttribute ? dom.hasAttribute(key) : false
  1915. }
  1916. var remove$6 = function (element, key) {
  1917. element.dom.removeAttribute(key)
  1918. }
  1919. var clone$3 = function (element) {
  1920. return foldl(
  1921. element.dom.attributes,
  1922. function (acc, attr) {
  1923. acc[attr.name] = attr.value
  1924. return acc
  1925. },
  1926. {}
  1927. )
  1928. }
  1929. var internalSet = function (dom, property, value) {
  1930. if (!isString$1(value)) {
  1931. console.error(
  1932. 'Invalid call to CSS.set. Property ',
  1933. property,
  1934. ':: Value ',
  1935. value,
  1936. ':: Element ',
  1937. dom
  1938. )
  1939. throw new Error('CSS value must be a string: ' + value)
  1940. }
  1941. if (isSupported(dom)) {
  1942. dom.style.setProperty(property, value)
  1943. }
  1944. }
  1945. var setAll = function (element, css) {
  1946. var dom = element.dom
  1947. each$j(css, function (v, k) {
  1948. internalSet(dom, k, v)
  1949. })
  1950. }
  1951. var get$5 = function (element, property) {
  1952. var dom = element.dom
  1953. var styles = window.getComputedStyle(dom)
  1954. var r = styles.getPropertyValue(property)
  1955. return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r
  1956. }
  1957. var getUnsafeProperty = function (dom, property) {
  1958. return isSupported(dom) ? dom.style.getPropertyValue(property) : ''
  1959. }
  1960. var getRaw = function (element, property) {
  1961. var dom = element.dom
  1962. var raw = getUnsafeProperty(dom, property)
  1963. return Optional.from(raw).filter(function (r) {
  1964. return r.length > 0
  1965. })
  1966. }
  1967. var getAllRaw = function (element) {
  1968. var css = {}
  1969. var dom = element.dom
  1970. if (isSupported(dom)) {
  1971. for (var i = 0; i < dom.style.length; i++) {
  1972. var ruleName = dom.style.item(i)
  1973. css[ruleName] = dom.style[ruleName]
  1974. }
  1975. }
  1976. return css
  1977. }
  1978. var reflow = function (e) {
  1979. return e.dom.offsetWidth
  1980. }
  1981. var browser$3 = detect().browser
  1982. var firstElement = function (nodes) {
  1983. return find$3(nodes, isElement$6)
  1984. }
  1985. var getTableCaptionDeltaY = function (elm) {
  1986. if (browser$3.isFirefox() && name(elm) === 'table') {
  1987. return firstElement(children(elm))
  1988. .filter(function (elm) {
  1989. return name(elm) === 'caption'
  1990. })
  1991. .bind(function (caption) {
  1992. return firstElement(nextSiblings(caption)).map(function (body) {
  1993. var bodyTop = body.dom.offsetTop
  1994. var captionTop = caption.dom.offsetTop
  1995. var captionHeight = caption.dom.offsetHeight
  1996. return bodyTop <= captionTop ? -captionHeight : 0
  1997. })
  1998. })
  1999. .getOr(0)
  2000. } else {
  2001. return 0
  2002. }
  2003. }
  2004. var hasChild = function (elm, child) {
  2005. return elm.children && contains$3(elm.children, child)
  2006. }
  2007. var getPos = function (body, elm, rootElm) {
  2008. var x = 0,
  2009. y = 0
  2010. var doc = body.ownerDocument
  2011. rootElm = rootElm ? rootElm : body
  2012. if (elm) {
  2013. if (
  2014. rootElm === body &&
  2015. elm.getBoundingClientRect &&
  2016. get$5(SugarElement.fromDom(body), 'position') === 'static'
  2017. ) {
  2018. var pos = elm.getBoundingClientRect()
  2019. x =
  2020. pos.left +
  2021. (doc.documentElement.scrollLeft || body.scrollLeft) -
  2022. doc.documentElement.clientLeft
  2023. y =
  2024. pos.top +
  2025. (doc.documentElement.scrollTop || body.scrollTop) -
  2026. doc.documentElement.clientTop
  2027. return {
  2028. x: x,
  2029. y: y,
  2030. }
  2031. }
  2032. var offsetParent = elm
  2033. while (
  2034. offsetParent &&
  2035. offsetParent !== rootElm &&
  2036. offsetParent.nodeType &&
  2037. !hasChild(offsetParent, rootElm)
  2038. ) {
  2039. var castOffsetParent = offsetParent
  2040. x += castOffsetParent.offsetLeft || 0
  2041. y += castOffsetParent.offsetTop || 0
  2042. offsetParent = castOffsetParent.offsetParent
  2043. }
  2044. offsetParent = elm.parentNode
  2045. while (
  2046. offsetParent &&
  2047. offsetParent !== rootElm &&
  2048. offsetParent.nodeType &&
  2049. !hasChild(offsetParent, rootElm)
  2050. ) {
  2051. x -= offsetParent.scrollLeft || 0
  2052. y -= offsetParent.scrollTop || 0
  2053. offsetParent = offsetParent.parentNode
  2054. }
  2055. y += getTableCaptionDeltaY(SugarElement.fromDom(elm))
  2056. }
  2057. return {
  2058. x: x,
  2059. y: y,
  2060. }
  2061. }
  2062. var exports$1 = {},
  2063. module$1 = { exports: exports$1 }
  2064. ;(function (define, exports, module, require) {
  2065. ;(function (global, factory) {
  2066. typeof exports === 'object' && typeof module !== 'undefined'
  2067. ? (module.exports = factory())
  2068. : typeof define === 'function' && define.amd
  2069. ? define(factory)
  2070. : ((global =
  2071. typeof globalThis !== 'undefined' ? globalThis : global || self),
  2072. (global.EphoxContactWrapper = factory()))
  2073. })(this, function () {
  2074. var commonjsGlobal =
  2075. typeof globalThis !== 'undefined'
  2076. ? globalThis
  2077. : typeof window !== 'undefined'
  2078. ? window
  2079. : typeof global !== 'undefined'
  2080. ? global
  2081. : typeof self !== 'undefined'
  2082. ? self
  2083. : {}
  2084. var promise = { exports: {} }
  2085. ;(function (module) {
  2086. ;(function (root) {
  2087. var setTimeoutFunc = setTimeout
  2088. function noop() {}
  2089. function bind(fn, thisArg) {
  2090. return function () {
  2091. fn.apply(thisArg, arguments)
  2092. }
  2093. }
  2094. function Promise(fn) {
  2095. if (typeof this !== 'object')
  2096. throw new TypeError('Promises must be constructed via new')
  2097. if (typeof fn !== 'function') throw new TypeError('not a function')
  2098. this._state = 0
  2099. this._handled = false
  2100. this._value = undefined
  2101. this._deferreds = []
  2102. doResolve(fn, this)
  2103. }
  2104. function handle(self, deferred) {
  2105. while (self._state === 3) {
  2106. self = self._value
  2107. }
  2108. if (self._state === 0) {
  2109. self._deferreds.push(deferred)
  2110. return
  2111. }
  2112. self._handled = true
  2113. Promise._immediateFn(function () {
  2114. var cb =
  2115. self._state === 1 ? deferred.onFulfilled : deferred.onRejected
  2116. if (cb === null) {
  2117. ;(self._state === 1 ? resolve : reject)(
  2118. deferred.promise,
  2119. self._value
  2120. )
  2121. return
  2122. }
  2123. var ret
  2124. try {
  2125. ret = cb(self._value)
  2126. } catch (e) {
  2127. reject(deferred.promise, e)
  2128. return
  2129. }
  2130. resolve(deferred.promise, ret)
  2131. })
  2132. }
  2133. function resolve(self, newValue) {
  2134. try {
  2135. if (newValue === self)
  2136. throw new TypeError('A promise cannot be resolved with itself.')
  2137. if (
  2138. newValue &&
  2139. (typeof newValue === 'object' || typeof newValue === 'function')
  2140. ) {
  2141. var then = newValue.then
  2142. if (newValue instanceof Promise) {
  2143. self._state = 3
  2144. self._value = newValue
  2145. finale(self)
  2146. return
  2147. } else if (typeof then === 'function') {
  2148. doResolve(bind(then, newValue), self)
  2149. return
  2150. }
  2151. }
  2152. self._state = 1
  2153. self._value = newValue
  2154. finale(self)
  2155. } catch (e) {
  2156. reject(self, e)
  2157. }
  2158. }
  2159. function reject(self, newValue) {
  2160. self._state = 2
  2161. self._value = newValue
  2162. finale(self)
  2163. }
  2164. function finale(self) {
  2165. if (self._state === 2 && self._deferreds.length === 0) {
  2166. Promise._immediateFn(function () {
  2167. if (!self._handled) {
  2168. Promise._unhandledRejectionFn(self._value)
  2169. }
  2170. })
  2171. }
  2172. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  2173. handle(self, self._deferreds[i])
  2174. }
  2175. self._deferreds = null
  2176. }
  2177. function Handler(onFulfilled, onRejected, promise) {
  2178. this.onFulfilled =
  2179. typeof onFulfilled === 'function' ? onFulfilled : null
  2180. this.onRejected =
  2181. typeof onRejected === 'function' ? onRejected : null
  2182. this.promise = promise
  2183. }
  2184. function doResolve(fn, self) {
  2185. var done = false
  2186. try {
  2187. fn(
  2188. function (value) {
  2189. if (done) return
  2190. done = true
  2191. resolve(self, value)
  2192. },
  2193. function (reason) {
  2194. if (done) return
  2195. done = true
  2196. reject(self, reason)
  2197. }
  2198. )
  2199. } catch (ex) {
  2200. if (done) return
  2201. done = true
  2202. reject(self, ex)
  2203. }
  2204. }
  2205. Promise.prototype['catch'] = function (onRejected) {
  2206. return this.then(null, onRejected)
  2207. }
  2208. Promise.prototype.then = function (onFulfilled, onRejected) {
  2209. var prom = new this.constructor(noop)
  2210. handle(this, new Handler(onFulfilled, onRejected, prom))
  2211. return prom
  2212. }
  2213. Promise.all = function (arr) {
  2214. var args = Array.prototype.slice.call(arr)
  2215. return new Promise(function (resolve, reject) {
  2216. if (args.length === 0) return resolve([])
  2217. var remaining = args.length
  2218. function res(i, val) {
  2219. try {
  2220. if (
  2221. val &&
  2222. (typeof val === 'object' || typeof val === 'function')
  2223. ) {
  2224. var then = val.then
  2225. if (typeof then === 'function') {
  2226. then.call(
  2227. val,
  2228. function (val) {
  2229. res(i, val)
  2230. },
  2231. reject
  2232. )
  2233. return
  2234. }
  2235. }
  2236. args[i] = val
  2237. if (--remaining === 0) {
  2238. resolve(args)
  2239. }
  2240. } catch (ex) {
  2241. reject(ex)
  2242. }
  2243. }
  2244. for (var i = 0; i < args.length; i++) {
  2245. res(i, args[i])
  2246. }
  2247. })
  2248. }
  2249. Promise.resolve = function (value) {
  2250. if (
  2251. value &&
  2252. typeof value === 'object' &&
  2253. value.constructor === Promise
  2254. ) {
  2255. return value
  2256. }
  2257. return new Promise(function (resolve) {
  2258. resolve(value)
  2259. })
  2260. }
  2261. Promise.reject = function (value) {
  2262. return new Promise(function (resolve, reject) {
  2263. reject(value)
  2264. })
  2265. }
  2266. Promise.race = function (values) {
  2267. return new Promise(function (resolve, reject) {
  2268. for (var i = 0, len = values.length; i < len; i++) {
  2269. values[i].then(resolve, reject)
  2270. }
  2271. })
  2272. }
  2273. Promise._immediateFn =
  2274. typeof setImmediate === 'function'
  2275. ? function (fn) {
  2276. setImmediate(fn)
  2277. }
  2278. : function (fn) {
  2279. setTimeoutFunc(fn, 0)
  2280. }
  2281. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  2282. if (typeof console !== 'undefined' && console) {
  2283. console.warn('Possible Unhandled Promise Rejection:', err)
  2284. }
  2285. }
  2286. Promise._setImmediateFn = function _setImmediateFn(fn) {
  2287. Promise._immediateFn = fn
  2288. }
  2289. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(
  2290. fn
  2291. ) {
  2292. Promise._unhandledRejectionFn = fn
  2293. }
  2294. if (module.exports) {
  2295. module.exports = Promise
  2296. } else if (!root.Promise) {
  2297. root.Promise = Promise
  2298. }
  2299. })(commonjsGlobal)
  2300. })(promise)
  2301. var promisePolyfill = promise.exports
  2302. var Global = (function () {
  2303. if (typeof window !== 'undefined') {
  2304. return window
  2305. } else {
  2306. return Function('return this;')()
  2307. }
  2308. })()
  2309. var promisePolyfill_1 = { boltExport: Global.Promise || promisePolyfill }
  2310. return promisePolyfill_1
  2311. })
  2312. })(undefined, exports$1, module$1)
  2313. var Promise$1 = module$1.exports.boltExport
  2314. var nu$1 = function (baseFn) {
  2315. var data = Optional.none()
  2316. var callbacks = []
  2317. var map = function (f) {
  2318. return nu$1(function (nCallback) {
  2319. get(function (data) {
  2320. nCallback(f(data))
  2321. })
  2322. })
  2323. }
  2324. var get = function (nCallback) {
  2325. if (isReady()) {
  2326. call(nCallback)
  2327. } else {
  2328. callbacks.push(nCallback)
  2329. }
  2330. }
  2331. var set = function (x) {
  2332. if (!isReady()) {
  2333. data = Optional.some(x)
  2334. run(callbacks)
  2335. callbacks = []
  2336. }
  2337. }
  2338. var isReady = function () {
  2339. return data.isSome()
  2340. }
  2341. var run = function (cbs) {
  2342. each$k(cbs, call)
  2343. }
  2344. var call = function (cb) {
  2345. data.each(function (x) {
  2346. setTimeout(function () {
  2347. cb(x)
  2348. }, 0)
  2349. })
  2350. }
  2351. baseFn(set)
  2352. return {
  2353. get: get,
  2354. map: map,
  2355. isReady: isReady,
  2356. }
  2357. }
  2358. var pure$1 = function (a) {
  2359. return nu$1(function (callback) {
  2360. callback(a)
  2361. })
  2362. }
  2363. var LazyValue = {
  2364. nu: nu$1,
  2365. pure: pure$1,
  2366. }
  2367. var errorReporter = function (err) {
  2368. setTimeout(function () {
  2369. throw err
  2370. }, 0)
  2371. }
  2372. var make = function (run) {
  2373. var get = function (callback) {
  2374. run().then(callback, errorReporter)
  2375. }
  2376. var map = function (fab) {
  2377. return make(function () {
  2378. return run().then(fab)
  2379. })
  2380. }
  2381. var bind = function (aFutureB) {
  2382. return make(function () {
  2383. return run().then(function (v) {
  2384. return aFutureB(v).toPromise()
  2385. })
  2386. })
  2387. }
  2388. var anonBind = function (futureB) {
  2389. return make(function () {
  2390. return run().then(function () {
  2391. return futureB.toPromise()
  2392. })
  2393. })
  2394. }
  2395. var toLazy = function () {
  2396. return LazyValue.nu(get)
  2397. }
  2398. var toCached = function () {
  2399. var cache = null
  2400. return make(function () {
  2401. if (cache === null) {
  2402. cache = run()
  2403. }
  2404. return cache
  2405. })
  2406. }
  2407. var toPromise = run
  2408. return {
  2409. map: map,
  2410. bind: bind,
  2411. anonBind: anonBind,
  2412. toLazy: toLazy,
  2413. toCached: toCached,
  2414. toPromise: toPromise,
  2415. get: get,
  2416. }
  2417. }
  2418. var nu = function (baseFn) {
  2419. return make(function () {
  2420. return new Promise$1(baseFn)
  2421. })
  2422. }
  2423. var pure = function (a) {
  2424. return make(function () {
  2425. return Promise$1.resolve(a)
  2426. })
  2427. }
  2428. var Future = {
  2429. nu: nu,
  2430. pure: pure,
  2431. }
  2432. var par$1 = function (asyncValues, nu) {
  2433. return nu(function (callback) {
  2434. var r = []
  2435. var count = 0
  2436. var cb = function (i) {
  2437. return function (value) {
  2438. r[i] = value
  2439. count++
  2440. if (count >= asyncValues.length) {
  2441. callback(r)
  2442. }
  2443. }
  2444. }
  2445. if (asyncValues.length === 0) {
  2446. callback([])
  2447. } else {
  2448. each$k(asyncValues, function (asyncValue, i) {
  2449. asyncValue.get(cb(i))
  2450. })
  2451. }
  2452. })
  2453. }
  2454. var par = function (futures) {
  2455. return par$1(futures, Future.nu)
  2456. }
  2457. var value$1 = function (o) {
  2458. var or = function (_opt) {
  2459. return value$1(o)
  2460. }
  2461. var orThunk = function (_f) {
  2462. return value$1(o)
  2463. }
  2464. var map = function (f) {
  2465. return value$1(f(o))
  2466. }
  2467. var mapError = function (_f) {
  2468. return value$1(o)
  2469. }
  2470. var each = function (f) {
  2471. f(o)
  2472. }
  2473. var bind = function (f) {
  2474. return f(o)
  2475. }
  2476. var fold = function (_, onValue) {
  2477. return onValue(o)
  2478. }
  2479. var exists = function (f) {
  2480. return f(o)
  2481. }
  2482. var forall = function (f) {
  2483. return f(o)
  2484. }
  2485. var toOptional = function () {
  2486. return Optional.some(o)
  2487. }
  2488. return {
  2489. isValue: always,
  2490. isError: never,
  2491. getOr: constant(o),
  2492. getOrThunk: constant(o),
  2493. getOrDie: constant(o),
  2494. or: or,
  2495. orThunk: orThunk,
  2496. fold: fold,
  2497. map: map,
  2498. mapError: mapError,
  2499. each: each,
  2500. bind: bind,
  2501. exists: exists,
  2502. forall: forall,
  2503. toOptional: toOptional,
  2504. }
  2505. }
  2506. var error = function (message) {
  2507. var getOrThunk = function (f) {
  2508. return f()
  2509. }
  2510. var getOrDie = function () {
  2511. return die(String(message))()
  2512. }
  2513. var or = identity
  2514. var orThunk = function (f) {
  2515. return f()
  2516. }
  2517. var map = function (_f) {
  2518. return error(message)
  2519. }
  2520. var mapError = function (f) {
  2521. return error(f(message))
  2522. }
  2523. var bind = function (_f) {
  2524. return error(message)
  2525. }
  2526. var fold = function (onError, _) {
  2527. return onError(message)
  2528. }
  2529. return {
  2530. isValue: never,
  2531. isError: always,
  2532. getOr: identity,
  2533. getOrThunk: getOrThunk,
  2534. getOrDie: getOrDie,
  2535. or: or,
  2536. orThunk: orThunk,
  2537. fold: fold,
  2538. map: map,
  2539. mapError: mapError,
  2540. each: noop,
  2541. bind: bind,
  2542. exists: never,
  2543. forall: always,
  2544. toOptional: Optional.none,
  2545. }
  2546. }
  2547. var fromOption = function (opt, err) {
  2548. return opt.fold(function () {
  2549. return error(err)
  2550. }, value$1)
  2551. }
  2552. var Result = {
  2553. value: value$1,
  2554. error: error,
  2555. fromOption: fromOption,
  2556. }
  2557. var generate$1 = function (cases) {
  2558. if (!isArray$1(cases)) {
  2559. throw new Error('cases must be an array')
  2560. }
  2561. if (cases.length === 0) {
  2562. throw new Error('there must be at least one case')
  2563. }
  2564. var constructors = []
  2565. var adt = {}
  2566. each$k(cases, function (acase, count) {
  2567. var keys$1 = keys(acase)
  2568. if (keys$1.length !== 1) {
  2569. throw new Error('one and only one name per case')
  2570. }
  2571. var key = keys$1[0]
  2572. var value = acase[key]
  2573. if (adt[key] !== undefined) {
  2574. throw new Error('duplicate key detected:' + key)
  2575. } else if (key === 'cata') {
  2576. throw new Error('cannot have a case named cata (sorry)')
  2577. } else if (!isArray$1(value)) {
  2578. throw new Error('case arguments must be an array')
  2579. }
  2580. constructors.push(key)
  2581. adt[key] = function () {
  2582. var args = []
  2583. for (var _i = 0; _i < arguments.length; _i++) {
  2584. args[_i] = arguments[_i]
  2585. }
  2586. var argLength = args.length
  2587. if (argLength !== value.length) {
  2588. throw new Error(
  2589. 'Wrong number of arguments to case ' +
  2590. key +
  2591. '. Expected ' +
  2592. value.length +
  2593. ' (' +
  2594. value +
  2595. '), got ' +
  2596. argLength
  2597. )
  2598. }
  2599. var match = function (branches) {
  2600. var branchKeys = keys(branches)
  2601. if (constructors.length !== branchKeys.length) {
  2602. throw new Error(
  2603. 'Wrong number of arguments to match. Expected: ' +
  2604. constructors.join(',') +
  2605. '\nActual: ' +
  2606. branchKeys.join(',')
  2607. )
  2608. }
  2609. var allReqd = forall(constructors, function (reqKey) {
  2610. return contains$3(branchKeys, reqKey)
  2611. })
  2612. if (!allReqd) {
  2613. throw new Error(
  2614. 'Not all branches were specified when using match. Specified: ' +
  2615. branchKeys.join(', ') +
  2616. '\nRequired: ' +
  2617. constructors.join(', ')
  2618. )
  2619. }
  2620. return branches[key].apply(null, args)
  2621. }
  2622. return {
  2623. fold: function () {
  2624. var foldArgs = []
  2625. for (var _i = 0; _i < arguments.length; _i++) {
  2626. foldArgs[_i] = arguments[_i]
  2627. }
  2628. if (foldArgs.length !== cases.length) {
  2629. throw new Error(
  2630. 'Wrong number of arguments to fold. Expected ' +
  2631. cases.length +
  2632. ', got ' +
  2633. foldArgs.length
  2634. )
  2635. }
  2636. var target = foldArgs[count]
  2637. return target.apply(null, args)
  2638. },
  2639. match: match,
  2640. log: function (label) {
  2641. console.log(label, {
  2642. constructors: constructors,
  2643. constructor: key,
  2644. params: args,
  2645. })
  2646. },
  2647. }
  2648. }
  2649. })
  2650. return adt
  2651. }
  2652. var Adt = { generate: generate$1 }
  2653. Adt.generate([
  2654. {
  2655. bothErrors: ['error1', 'error2'],
  2656. },
  2657. {
  2658. firstError: ['error1', 'value2'],
  2659. },
  2660. {
  2661. secondError: ['value1', 'error2'],
  2662. },
  2663. {
  2664. bothValues: ['value1', 'value2'],
  2665. },
  2666. ])
  2667. var unite = function (result) {
  2668. return result.fold(identity, identity)
  2669. }
  2670. function ClosestOrAncestor(is, ancestor, scope, a, isRoot) {
  2671. if (is(scope, a)) {
  2672. return Optional.some(scope)
  2673. } else if (isFunction(isRoot) && isRoot(scope)) {
  2674. return Optional.none()
  2675. } else {
  2676. return ancestor(scope, a, isRoot)
  2677. }
  2678. }
  2679. var ancestor$3 = function (scope, predicate, isRoot) {
  2680. var element = scope.dom
  2681. var stop = isFunction(isRoot) ? isRoot : never
  2682. while (element.parentNode) {
  2683. element = element.parentNode
  2684. var el = SugarElement.fromDom(element)
  2685. if (predicate(el)) {
  2686. return Optional.some(el)
  2687. } else if (stop(el)) {
  2688. break
  2689. }
  2690. }
  2691. return Optional.none()
  2692. }
  2693. var closest$3 = function (scope, predicate, isRoot) {
  2694. var is = function (s, test) {
  2695. return test(s)
  2696. }
  2697. return ClosestOrAncestor(is, ancestor$3, scope, predicate, isRoot)
  2698. }
  2699. var sibling$2 = function (scope, predicate) {
  2700. var element = scope.dom
  2701. if (!element.parentNode) {
  2702. return Optional.none()
  2703. }
  2704. return child(SugarElement.fromDom(element.parentNode), function (x) {
  2705. return !eq(scope, x) && predicate(x)
  2706. })
  2707. }
  2708. var child = function (scope, predicate) {
  2709. var pred = function (node) {
  2710. return predicate(SugarElement.fromDom(node))
  2711. }
  2712. var result = find$3(scope.dom.childNodes, pred)
  2713. return result.map(SugarElement.fromDom)
  2714. }
  2715. var ancestor$2 = function (scope, selector, isRoot) {
  2716. return ancestor$3(
  2717. scope,
  2718. function (e) {
  2719. return is$2(e, selector)
  2720. },
  2721. isRoot
  2722. )
  2723. }
  2724. var descendant = function (scope, selector) {
  2725. return one(selector, scope)
  2726. }
  2727. var closest$2 = function (scope, selector, isRoot) {
  2728. var is = function (element, selector) {
  2729. return is$2(element, selector)
  2730. }
  2731. return ClosestOrAncestor(is, ancestor$2, scope, selector, isRoot)
  2732. }
  2733. var promiseObj = window.Promise ? window.Promise : Promise$1
  2734. var requestAnimationFramePromise
  2735. var requestAnimationFrame = function (callback, element) {
  2736. var requestAnimationFrameFunc = window.requestAnimationFrame
  2737. var vendors = ['ms', 'moz', 'webkit']
  2738. var featurefill = function (cb) {
  2739. window.setTimeout(cb, 0)
  2740. }
  2741. for (var i = 0; i < vendors.length && !requestAnimationFrameFunc; i++) {
  2742. requestAnimationFrameFunc = window[vendors[i] + 'RequestAnimationFrame']
  2743. }
  2744. if (!requestAnimationFrameFunc) {
  2745. requestAnimationFrameFunc = featurefill
  2746. }
  2747. requestAnimationFrameFunc(callback, element)
  2748. }
  2749. var wrappedSetTimeout = function (callback, time) {
  2750. if (typeof time !== 'number') {
  2751. time = 0
  2752. }
  2753. return setTimeout(callback, time)
  2754. }
  2755. var wrappedSetInterval = function (callback, time) {
  2756. if (typeof time !== 'number') {
  2757. time = 1
  2758. }
  2759. return setInterval(callback, time)
  2760. }
  2761. var wrappedClearTimeout = function (id) {
  2762. return clearTimeout(id)
  2763. }
  2764. var wrappedClearInterval = function (id) {
  2765. return clearInterval(id)
  2766. }
  2767. var debounce = function (callback, time) {
  2768. var timer
  2769. var func = function () {
  2770. var args = []
  2771. for (var _i = 0; _i < arguments.length; _i++) {
  2772. args[_i] = arguments[_i]
  2773. }
  2774. clearTimeout(timer)
  2775. timer = wrappedSetTimeout(function () {
  2776. callback.apply(this, args)
  2777. }, time)
  2778. }
  2779. func.stop = function () {
  2780. clearTimeout(timer)
  2781. }
  2782. return func
  2783. }
  2784. var Delay = {
  2785. requestAnimationFrame: function (callback, element) {
  2786. if (requestAnimationFramePromise) {
  2787. requestAnimationFramePromise.then(callback)
  2788. return
  2789. }
  2790. requestAnimationFramePromise = new promiseObj(function (resolve) {
  2791. if (!element) {
  2792. element = document.body
  2793. }
  2794. requestAnimationFrame(resolve, element)
  2795. }).then(callback)
  2796. },
  2797. setTimeout: wrappedSetTimeout,
  2798. setInterval: wrappedSetInterval,
  2799. setEditorTimeout: function (editor, callback, time) {
  2800. return wrappedSetTimeout(function () {
  2801. if (!editor.removed) {
  2802. callback()
  2803. }
  2804. }, time)
  2805. },
  2806. setEditorInterval: function (editor, callback, time) {
  2807. var timer = wrappedSetInterval(function () {
  2808. if (!editor.removed) {
  2809. callback()
  2810. } else {
  2811. clearInterval(timer)
  2812. }
  2813. }, time)
  2814. return timer
  2815. },
  2816. debounce: debounce,
  2817. throttle: debounce,
  2818. clearInterval: wrappedClearInterval,
  2819. clearTimeout: wrappedClearTimeout,
  2820. }
  2821. var StyleSheetLoader = function (documentOrShadowRoot, settings) {
  2822. if (settings === void 0) {
  2823. settings = {}
  2824. }
  2825. var idCount = 0
  2826. var loadedStates = {}
  2827. var edos = SugarElement.fromDom(documentOrShadowRoot)
  2828. var doc = documentOrOwner(edos)
  2829. var maxLoadTime = settings.maxLoadTime || 5000
  2830. var _setReferrerPolicy = function (referrerPolicy) {
  2831. settings.referrerPolicy = referrerPolicy
  2832. }
  2833. var addStyle = function (element) {
  2834. append$1(getStyleContainer(edos), element)
  2835. }
  2836. var removeStyle = function (id) {
  2837. var styleContainer = getStyleContainer(edos)
  2838. descendant(styleContainer, '#' + id).each(remove$7)
  2839. }
  2840. var getOrCreateState = function (url) {
  2841. return get$9(loadedStates, url).getOrThunk(function () {
  2842. return {
  2843. id: 'mce-u' + idCount++,
  2844. passed: [],
  2845. failed: [],
  2846. count: 0,
  2847. }
  2848. })
  2849. }
  2850. var load = function (url, success, failure) {
  2851. var link
  2852. var urlWithSuffix = Tools._addCacheSuffix(url)
  2853. var state = getOrCreateState(urlWithSuffix)
  2854. loadedStates[urlWithSuffix] = state
  2855. state.count++
  2856. var resolve = function (callbacks, status) {
  2857. var i = callbacks.length
  2858. while (i--) {
  2859. callbacks[i]()
  2860. }
  2861. state.status = status
  2862. state.passed = []
  2863. state.failed = []
  2864. if (link) {
  2865. link.onload = null
  2866. link.onerror = null
  2867. link = null
  2868. }
  2869. }
  2870. var passed = function () {
  2871. return resolve(state.passed, 2)
  2872. }
  2873. var failed = function () {
  2874. return resolve(state.failed, 3)
  2875. }
  2876. var wait = function (testCallback, waitCallback) {
  2877. if (!testCallback()) {
  2878. if (Date.now() - startTime < maxLoadTime) {
  2879. Delay.setTimeout(waitCallback)
  2880. } else {
  2881. failed()
  2882. }
  2883. }
  2884. }
  2885. var waitForWebKitLinkLoaded = function () {
  2886. wait(function () {
  2887. var styleSheets = documentOrShadowRoot.styleSheets
  2888. var i = styleSheets.length
  2889. while (i--) {
  2890. var styleSheet = styleSheets[i]
  2891. var owner = styleSheet.ownerNode
  2892. if (owner && owner.id === link.id) {
  2893. passed()
  2894. return true
  2895. }
  2896. }
  2897. return false
  2898. }, waitForWebKitLinkLoaded)
  2899. }
  2900. if (success) {
  2901. state.passed.push(success)
  2902. }
  2903. if (failure) {
  2904. state.failed.push(failure)
  2905. }
  2906. if (state.status === 1) {
  2907. return
  2908. }
  2909. if (state.status === 2) {
  2910. passed()
  2911. return
  2912. }
  2913. if (state.status === 3) {
  2914. failed()
  2915. return
  2916. }
  2917. state.status = 1
  2918. var linkElem = SugarElement.fromTag('link', doc.dom)
  2919. setAll$1(linkElem, {
  2920. rel: 'stylesheet',
  2921. type: 'text/css',
  2922. id: state.id,
  2923. })
  2924. var startTime = Date.now()
  2925. if (settings.contentCssCors) {
  2926. set$1(linkElem, 'crossOrigin', 'anonymous')
  2927. }
  2928. if (settings.referrerPolicy) {
  2929. set$1(linkElem, 'referrerpolicy', settings.referrerPolicy)
  2930. }
  2931. link = linkElem.dom
  2932. link.onload = waitForWebKitLinkLoaded
  2933. link.onerror = failed
  2934. addStyle(linkElem)
  2935. set$1(linkElem, 'href', urlWithSuffix)
  2936. }
  2937. var loadF = function (url) {
  2938. return Future.nu(function (resolve) {
  2939. load(
  2940. url,
  2941. compose(resolve, constant(Result.value(url))),
  2942. compose(resolve, constant(Result.error(url)))
  2943. )
  2944. })
  2945. }
  2946. var loadAll = function (urls, success, failure) {
  2947. par(map$3(urls, loadF)).get(function (result) {
  2948. var parts = partition(result, function (r) {
  2949. return r.isValue()
  2950. })
  2951. if (parts.fail.length > 0) {
  2952. failure(parts.fail.map(unite))
  2953. } else {
  2954. success(parts.pass.map(unite))
  2955. }
  2956. })
  2957. }
  2958. var unload = function (url) {
  2959. var urlWithSuffix = Tools._addCacheSuffix(url)
  2960. get$9(loadedStates, urlWithSuffix).each(function (state) {
  2961. var count = --state.count
  2962. if (count === 0) {
  2963. delete loadedStates[urlWithSuffix]
  2964. removeStyle(state.id)
  2965. }
  2966. })
  2967. }
  2968. var unloadAll = function (urls) {
  2969. each$k(urls, function (url) {
  2970. unload(url)
  2971. })
  2972. }
  2973. return {
  2974. load: load,
  2975. loadAll: loadAll,
  2976. unload: unload,
  2977. unloadAll: unloadAll,
  2978. _setReferrerPolicy: _setReferrerPolicy,
  2979. }
  2980. }
  2981. var create$8 = function () {
  2982. var map = new WeakMap()
  2983. var forElement = function (referenceElement, settings) {
  2984. var root = getRootNode(referenceElement)
  2985. var rootDom = root.dom
  2986. return Optional.from(map.get(rootDom)).getOrThunk(function () {
  2987. var sl = StyleSheetLoader(rootDom, settings)
  2988. map.set(rootDom, sl)
  2989. return sl
  2990. })
  2991. }
  2992. return { forElement: forElement }
  2993. }
  2994. var instance = create$8()
  2995. var DomTreeWalker = (function () {
  2996. function DomTreeWalker(startNode, rootNode) {
  2997. this.node = startNode
  2998. this.rootNode = rootNode
  2999. this.current = this.current.bind(this)
  3000. this.next = this.next.bind(this)
  3001. this.prev = this.prev.bind(this)
  3002. this.prev2 = this.prev2.bind(this)
  3003. }
  3004. DomTreeWalker.prototype.current = function () {
  3005. return this.node
  3006. }
  3007. DomTreeWalker.prototype.next = function (shallow) {
  3008. this.node = this.findSibling(
  3009. this.node,
  3010. 'firstChild',
  3011. 'nextSibling',
  3012. shallow
  3013. )
  3014. return this.node
  3015. }
  3016. DomTreeWalker.prototype.prev = function (shallow) {
  3017. this.node = this.findSibling(
  3018. this.node,
  3019. 'lastChild',
  3020. 'previousSibling',
  3021. shallow
  3022. )
  3023. return this.node
  3024. }
  3025. DomTreeWalker.prototype.prev2 = function (shallow) {
  3026. this.node = this.findPreviousNode(
  3027. this.node,
  3028. 'lastChild',
  3029. 'previousSibling',
  3030. shallow
  3031. )
  3032. return this.node
  3033. }
  3034. DomTreeWalker.prototype.findSibling = function (
  3035. node,
  3036. startName,
  3037. siblingName,
  3038. shallow
  3039. ) {
  3040. var sibling, parent
  3041. if (node) {
  3042. if (!shallow && node[startName]) {
  3043. return node[startName]
  3044. }
  3045. if (node !== this.rootNode) {
  3046. sibling = node[siblingName]
  3047. if (sibling) {
  3048. return sibling
  3049. }
  3050. for (
  3051. parent = node.parentNode;
  3052. parent && parent !== this.rootNode;
  3053. parent = parent.parentNode
  3054. ) {
  3055. sibling = parent[siblingName]
  3056. if (sibling) {
  3057. return sibling
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. DomTreeWalker.prototype.findPreviousNode = function (
  3064. node,
  3065. startName,
  3066. siblingName,
  3067. shallow
  3068. ) {
  3069. var sibling, parent, child
  3070. if (node) {
  3071. sibling = node[siblingName]
  3072. if (this.rootNode && sibling === this.rootNode) {
  3073. return
  3074. }
  3075. if (sibling) {
  3076. if (!shallow) {
  3077. for (child = sibling[startName]; child; child = child[startName]) {
  3078. if (!child[startName]) {
  3079. return child
  3080. }
  3081. }
  3082. }
  3083. return sibling
  3084. }
  3085. parent = node.parentNode
  3086. if (parent && parent !== this.rootNode) {
  3087. return parent
  3088. }
  3089. }
  3090. }
  3091. return DomTreeWalker
  3092. })()
  3093. var blocks = [
  3094. 'article',
  3095. 'aside',
  3096. 'details',
  3097. 'div',
  3098. 'dt',
  3099. 'figcaption',
  3100. 'footer',
  3101. 'form',
  3102. 'fieldset',
  3103. 'header',
  3104. 'hgroup',
  3105. 'html',
  3106. 'main',
  3107. 'nav',
  3108. 'section',
  3109. 'summary',
  3110. 'body',
  3111. 'p',
  3112. 'dl',
  3113. 'multicol',
  3114. 'dd',
  3115. 'figure',
  3116. 'address',
  3117. 'center',
  3118. 'blockquote',
  3119. 'h1',
  3120. 'h2',
  3121. 'h3',
  3122. 'h4',
  3123. 'h5',
  3124. 'h6',
  3125. 'listing',
  3126. 'xmp',
  3127. 'pre',
  3128. 'plaintext',
  3129. 'menu',
  3130. 'dir',
  3131. 'ul',
  3132. 'ol',
  3133. 'li',
  3134. 'hr',
  3135. 'table',
  3136. 'tbody',
  3137. 'thead',
  3138. 'tfoot',
  3139. 'th',
  3140. 'tr',
  3141. 'td',
  3142. 'caption',
  3143. ]
  3144. var tableCells = ['td', 'th']
  3145. var tableSections = ['thead', 'tbody', 'tfoot']
  3146. var textBlocks = [
  3147. 'h1',
  3148. 'h2',
  3149. 'h3',
  3150. 'h4',
  3151. 'h5',
  3152. 'h6',
  3153. 'p',
  3154. 'div',
  3155. 'address',
  3156. 'pre',
  3157. 'form',
  3158. 'blockquote',
  3159. 'center',
  3160. 'dir',
  3161. 'fieldset',
  3162. 'header',
  3163. 'footer',
  3164. 'article',
  3165. 'section',
  3166. 'hgroup',
  3167. 'aside',
  3168. 'nav',
  3169. 'figure',
  3170. ]
  3171. var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
  3172. var listItems$1 = ['li', 'dd', 'dt']
  3173. var lists = ['ul', 'ol', 'dl']
  3174. var wsElements = ['pre', 'script', 'textarea', 'style']
  3175. var lazyLookup = function (items) {
  3176. var lookup
  3177. return function (node) {
  3178. lookup = lookup ? lookup : mapToObject(items, always)
  3179. return has$2(lookup, name(node))
  3180. }
  3181. }
  3182. var isHeading = lazyLookup(headings)
  3183. var isBlock$2 = lazyLookup(blocks)
  3184. var isTable$2 = function (node) {
  3185. return name(node) === 'table'
  3186. }
  3187. var isInline$1 = function (node) {
  3188. return isElement$6(node) && !isBlock$2(node)
  3189. }
  3190. var isBr$4 = function (node) {
  3191. return isElement$6(node) && name(node) === 'br'
  3192. }
  3193. var isTextBlock$2 = lazyLookup(textBlocks)
  3194. var isList = lazyLookup(lists)
  3195. var isListItem = lazyLookup(listItems$1)
  3196. var isTableSection = lazyLookup(tableSections)
  3197. var isTableCell$4 = lazyLookup(tableCells)
  3198. var isWsPreserveElement = lazyLookup(wsElements)
  3199. var ancestor$1 = function (scope, selector, isRoot) {
  3200. return ancestor$2(scope, selector, isRoot).isSome()
  3201. }
  3202. var zeroWidth = '\uFEFF'
  3203. var nbsp = '\xA0'
  3204. var isZwsp$1 = function (char) {
  3205. return char === zeroWidth
  3206. }
  3207. var removeZwsp = function (s) {
  3208. return s.replace(/\uFEFF/g, '')
  3209. }
  3210. var ZWSP$1 = zeroWidth
  3211. var isZwsp = isZwsp$1
  3212. var trim$2 = removeZwsp
  3213. var isElement$4 = isElement$5
  3214. var isText$6 = isText$7
  3215. var isCaretContainerBlock$1 = function (node) {
  3216. if (isText$6(node)) {
  3217. node = node.parentNode
  3218. }
  3219. return isElement$4(node) && node.hasAttribute('data-mce-caret')
  3220. }
  3221. var isCaretContainerInline = function (node) {
  3222. return isText$6(node) && isZwsp(node.data)
  3223. }
  3224. var isCaretContainer$2 = function (node) {
  3225. return isCaretContainerBlock$1(node) || isCaretContainerInline(node)
  3226. }
  3227. var hasContent = function (node) {
  3228. return node.firstChild !== node.lastChild || !isBr$5(node.firstChild)
  3229. }
  3230. var insertInline$1 = function (node, before) {
  3231. var doc = node.ownerDocument
  3232. var textNode = doc.createTextNode(ZWSP$1)
  3233. var parentNode = node.parentNode
  3234. if (!before) {
  3235. var sibling = node.nextSibling
  3236. if (isText$6(sibling)) {
  3237. if (isCaretContainer$2(sibling)) {
  3238. return sibling
  3239. }
  3240. if (startsWithCaretContainer$1(sibling)) {
  3241. sibling.splitText(1)
  3242. return sibling
  3243. }
  3244. }
  3245. if (node.nextSibling) {
  3246. parentNode.insertBefore(textNode, node.nextSibling)
  3247. } else {
  3248. parentNode.appendChild(textNode)
  3249. }
  3250. } else {
  3251. var sibling = node.previousSibling
  3252. if (isText$6(sibling)) {
  3253. if (isCaretContainer$2(sibling)) {
  3254. return sibling
  3255. }
  3256. if (endsWithCaretContainer$1(sibling)) {
  3257. return sibling.splitText(sibling.data.length - 1)
  3258. }
  3259. }
  3260. parentNode.insertBefore(textNode, node)
  3261. }
  3262. return textNode
  3263. }
  3264. var isBeforeInline = function (pos) {
  3265. var container = pos.container()
  3266. if (!isText$7(container)) {
  3267. return false
  3268. }
  3269. return (
  3270. container.data.charAt(pos.offset()) === ZWSP$1 ||
  3271. (pos.isAtStart() && isCaretContainerInline(container.previousSibling))
  3272. )
  3273. }
  3274. var isAfterInline = function (pos) {
  3275. var container = pos.container()
  3276. if (!isText$7(container)) {
  3277. return false
  3278. }
  3279. return (
  3280. container.data.charAt(pos.offset() - 1) === ZWSP$1 ||
  3281. (pos.isAtEnd() && isCaretContainerInline(container.nextSibling))
  3282. )
  3283. }
  3284. var createBogusBr = function () {
  3285. var br = document.createElement('br')
  3286. br.setAttribute('data-mce-bogus', '1')
  3287. return br
  3288. }
  3289. var insertBlock$1 = function (blockName, node, before) {
  3290. var doc = node.ownerDocument
  3291. var blockNode = doc.createElement(blockName)
  3292. blockNode.setAttribute('data-mce-caret', before ? 'before' : 'after')
  3293. blockNode.setAttribute('data-mce-bogus', 'all')
  3294. blockNode.appendChild(createBogusBr())
  3295. var parentNode = node.parentNode
  3296. if (!before) {
  3297. if (node.nextSibling) {
  3298. parentNode.insertBefore(blockNode, node.nextSibling)
  3299. } else {
  3300. parentNode.appendChild(blockNode)
  3301. }
  3302. } else {
  3303. parentNode.insertBefore(blockNode, node)
  3304. }
  3305. return blockNode
  3306. }
  3307. var startsWithCaretContainer$1 = function (node) {
  3308. return isText$6(node) && node.data[0] === ZWSP$1
  3309. }
  3310. var endsWithCaretContainer$1 = function (node) {
  3311. return isText$6(node) && node.data[node.data.length - 1] === ZWSP$1
  3312. }
  3313. var trimBogusBr = function (elm) {
  3314. var brs = elm.getElementsByTagName('br')
  3315. var lastBr = brs[brs.length - 1]
  3316. if (isBogus$2(lastBr)) {
  3317. lastBr.parentNode.removeChild(lastBr)
  3318. }
  3319. }
  3320. var showCaretContainerBlock = function (caretContainer) {
  3321. if (caretContainer && caretContainer.hasAttribute('data-mce-caret')) {
  3322. trimBogusBr(caretContainer)
  3323. caretContainer.removeAttribute('data-mce-caret')
  3324. caretContainer.removeAttribute('data-mce-bogus')
  3325. caretContainer.removeAttribute('style')
  3326. caretContainer.removeAttribute('_moz_abspos')
  3327. return caretContainer
  3328. }
  3329. return null
  3330. }
  3331. var isRangeInCaretContainerBlock = function (range) {
  3332. return isCaretContainerBlock$1(range.startContainer)
  3333. }
  3334. var isContentEditableTrue$3 = isContentEditableTrue$4
  3335. var isContentEditableFalse$a = isContentEditableFalse$b
  3336. var isBr$3 = isBr$5
  3337. var isText$5 = isText$7
  3338. var isInvalidTextElement = matchNodeNames(['script', 'style', 'textarea'])
  3339. var isAtomicInline = matchNodeNames([
  3340. 'img',
  3341. 'input',
  3342. 'textarea',
  3343. 'hr',
  3344. 'iframe',
  3345. 'video',
  3346. 'audio',
  3347. 'object',
  3348. 'embed',
  3349. ])
  3350. var isTable$1 = matchNodeNames(['table'])
  3351. var isCaretContainer$1 = isCaretContainer$2
  3352. var isCaretCandidate$3 = function (node) {
  3353. if (isCaretContainer$1(node)) {
  3354. return false
  3355. }
  3356. if (isText$5(node)) {
  3357. return !isInvalidTextElement(node.parentNode)
  3358. }
  3359. return (
  3360. isAtomicInline(node) ||
  3361. isBr$3(node) ||
  3362. isTable$1(node) ||
  3363. isNonUiContentEditableFalse(node)
  3364. )
  3365. }
  3366. var isUnselectable = function (node) {
  3367. return isElement$5(node) && node.getAttribute('unselectable') === 'true'
  3368. }
  3369. var isNonUiContentEditableFalse = function (node) {
  3370. return isUnselectable(node) === false && isContentEditableFalse$a(node)
  3371. }
  3372. var isInEditable = function (node, root) {
  3373. for (
  3374. node = node.parentNode;
  3375. node && node !== root;
  3376. node = node.parentNode
  3377. ) {
  3378. if (isNonUiContentEditableFalse(node)) {
  3379. return false
  3380. }
  3381. if (isContentEditableTrue$3(node)) {
  3382. return true
  3383. }
  3384. }
  3385. return true
  3386. }
  3387. var isAtomicContentEditableFalse = function (node) {
  3388. if (!isNonUiContentEditableFalse(node)) {
  3389. return false
  3390. }
  3391. return (
  3392. foldl(
  3393. from(node.getElementsByTagName('*')),
  3394. function (result, elm) {
  3395. return result || isContentEditableTrue$3(elm)
  3396. },
  3397. false
  3398. ) !== true
  3399. )
  3400. }
  3401. var isAtomic$1 = function (node) {
  3402. return isAtomicInline(node) || isAtomicContentEditableFalse(node)
  3403. }
  3404. var isEditableCaretCandidate$1 = function (node, root) {
  3405. return isCaretCandidate$3(node) && isInEditable(node, root)
  3406. }
  3407. var whiteSpaceRegExp$1 = /^[ \t\r\n]*$/
  3408. var isWhitespaceText = function (text) {
  3409. return whiteSpaceRegExp$1.test(text)
  3410. }
  3411. var hasWhitespacePreserveParent = function (node, rootNode) {
  3412. var rootElement = SugarElement.fromDom(rootNode)
  3413. var startNode = SugarElement.fromDom(node)
  3414. return ancestor$1(startNode, 'pre,code', curry(eq, rootElement))
  3415. }
  3416. var isWhitespace = function (node, rootNode) {
  3417. return (
  3418. isText$7(node) &&
  3419. isWhitespaceText(node.data) &&
  3420. hasWhitespacePreserveParent(node, rootNode) === false
  3421. )
  3422. }
  3423. var isNamedAnchor = function (node) {
  3424. return (
  3425. isElement$5(node) &&
  3426. node.nodeName === 'A' &&
  3427. !node.hasAttribute('href') &&
  3428. (node.hasAttribute('name') || node.hasAttribute('id'))
  3429. )
  3430. }
  3431. var isContent$1 = function (node, rootNode) {
  3432. return (
  3433. (isCaretCandidate$3(node) && isWhitespace(node, rootNode) === false) ||
  3434. isNamedAnchor(node) ||
  3435. isBookmark(node)
  3436. )
  3437. }
  3438. var isBookmark = hasAttribute('data-mce-bookmark')
  3439. var isBogus$1 = hasAttribute('data-mce-bogus')
  3440. var isBogusAll = hasAttributeValue('data-mce-bogus', 'all')
  3441. var isEmptyNode = function (targetNode, skipBogus) {
  3442. var brCount = 0
  3443. if (isContent$1(targetNode, targetNode)) {
  3444. return false
  3445. } else {
  3446. var node = targetNode.firstChild
  3447. if (!node) {
  3448. return true
  3449. }
  3450. var walker = new DomTreeWalker(node, targetNode)
  3451. do {
  3452. if (skipBogus) {
  3453. if (isBogusAll(node)) {
  3454. node = walker.next(true)
  3455. continue
  3456. }
  3457. if (isBogus$1(node)) {
  3458. node = walker.next()
  3459. continue
  3460. }
  3461. }
  3462. if (isBr$5(node)) {
  3463. brCount++
  3464. node = walker.next()
  3465. continue
  3466. }
  3467. if (isContent$1(node, targetNode)) {
  3468. return false
  3469. }
  3470. node = walker.next()
  3471. } while (node)
  3472. return brCount <= 1
  3473. }
  3474. }
  3475. var isEmpty$2 = function (elm, skipBogus) {
  3476. if (skipBogus === void 0) {
  3477. skipBogus = true
  3478. }
  3479. return isEmptyNode(elm.dom, skipBogus)
  3480. }
  3481. var isSpan = function (node) {
  3482. return node.nodeName.toLowerCase() === 'span'
  3483. }
  3484. var isInlineContent = function (node, root) {
  3485. return (
  3486. isNonNullable(node) &&
  3487. (isContent$1(node, root) || isInline$1(SugarElement.fromDom(node)))
  3488. )
  3489. }
  3490. var surroundedByInlineContent = function (node, root) {
  3491. var prev = new DomTreeWalker(node, root).prev(false)
  3492. var next = new DomTreeWalker(node, root).next(false)
  3493. var prevIsInline = isUndefined(prev) || isInlineContent(prev, root)
  3494. var nextIsInline = isUndefined(next) || isInlineContent(next, root)
  3495. return prevIsInline && nextIsInline
  3496. }
  3497. var isBookmarkNode$2 = function (node) {
  3498. return isSpan(node) && node.getAttribute('data-mce-type') === 'bookmark'
  3499. }
  3500. var isKeepTextNode = function (node, root) {
  3501. return (
  3502. isText$7(node) &&
  3503. node.data.length > 0 &&
  3504. surroundedByInlineContent(node, root)
  3505. )
  3506. }
  3507. var isKeepElement = function (node) {
  3508. return isElement$5(node) ? node.childNodes.length > 0 : false
  3509. }
  3510. var isDocument = function (node) {
  3511. return isDocumentFragment(node) || isDocument$1(node)
  3512. }
  3513. var trimNode = function (dom, node, root) {
  3514. var rootNode = root || node
  3515. if (isElement$5(node) && isBookmarkNode$2(node)) {
  3516. return node
  3517. }
  3518. var children = node.childNodes
  3519. for (var i = children.length - 1; i >= 0; i--) {
  3520. trimNode(dom, children[i], rootNode)
  3521. }
  3522. if (isElement$5(node)) {
  3523. var currentChildren = node.childNodes
  3524. if (
  3525. currentChildren.length === 1 &&
  3526. isBookmarkNode$2(currentChildren[0])
  3527. ) {
  3528. node.parentNode.insertBefore(currentChildren[0], node)
  3529. }
  3530. }
  3531. if (
  3532. !isDocument(node) &&
  3533. !isContent$1(node, rootNode) &&
  3534. !isKeepElement(node) &&
  3535. !isKeepTextNode(node, rootNode)
  3536. ) {
  3537. dom.remove(node)
  3538. }
  3539. return node
  3540. }
  3541. var makeMap$3 = Tools.makeMap
  3542. var attrsCharsRegExp =
  3543. /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g
  3544. var textCharsRegExp =
  3545. /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g
  3546. var rawCharsRegExp = /[<>&\"\']/g
  3547. var entityRegExp = /&#([a-z0-9]+);?|&([a-z0-9]+);/gi
  3548. var asciiMap = {
  3549. 128: '\u20AC',
  3550. 130: '\u201A',
  3551. 131: '\u0192',
  3552. 132: '\u201E',
  3553. 133: '\u2026',
  3554. 134: '\u2020',
  3555. 135: '\u2021',
  3556. 136: '\u02c6',
  3557. 137: '\u2030',
  3558. 138: '\u0160',
  3559. 139: '\u2039',
  3560. 140: '\u0152',
  3561. 142: '\u017d',
  3562. 145: '\u2018',
  3563. 146: '\u2019',
  3564. 147: '\u201C',
  3565. 148: '\u201D',
  3566. 149: '\u2022',
  3567. 150: '\u2013',
  3568. 151: '\u2014',
  3569. 152: '\u02DC',
  3570. 153: '\u2122',
  3571. 154: '\u0161',
  3572. 155: '\u203A',
  3573. 156: '\u0153',
  3574. 158: '\u017e',
  3575. 159: '\u0178',
  3576. }
  3577. var baseEntities = {
  3578. '"': '&quot;',
  3579. "'": '&#39;',
  3580. '<': '&lt;',
  3581. '>': '&gt;',
  3582. '&': '&amp;',
  3583. '`': '&#96;',
  3584. }
  3585. var reverseEntities = {
  3586. '&lt;': '<',
  3587. '&gt;': '>',
  3588. '&amp;': '&',
  3589. '&quot;': '"',
  3590. '&apos;': "'",
  3591. }
  3592. var nativeDecode = function (text) {
  3593. var elm = SugarElement.fromTag('div').dom
  3594. elm.innerHTML = text
  3595. return elm.textContent || elm.innerText || text
  3596. }
  3597. var buildEntitiesLookup = function (items, radix) {
  3598. var i, chr, entity
  3599. var lookup = {}
  3600. if (items) {
  3601. items = items.split(',')
  3602. radix = radix || 10
  3603. for (i = 0; i < items.length; i += 2) {
  3604. chr = String.fromCharCode(parseInt(items[i], radix))
  3605. if (!baseEntities[chr]) {
  3606. entity = '&' + items[i + 1] + ';'
  3607. lookup[chr] = entity
  3608. lookup[entity] = chr
  3609. }
  3610. }
  3611. return lookup
  3612. }
  3613. }
  3614. var namedEntities = buildEntitiesLookup(
  3615. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  3616. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  3617. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  3618. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  3619. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  3620. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  3621. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  3622. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  3623. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  3624. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  3625. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  3626. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  3627. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  3628. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  3629. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  3630. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  3631. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  3632. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  3633. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  3634. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  3635. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  3636. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  3637. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  3638. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  3639. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro',
  3640. 32
  3641. )
  3642. var encodeRaw = function (text, attr) {
  3643. return text.replace(
  3644. attr ? attrsCharsRegExp : textCharsRegExp,
  3645. function (chr) {
  3646. return baseEntities[chr] || chr
  3647. }
  3648. )
  3649. }
  3650. var encodeAllRaw = function (text) {
  3651. return ('' + text).replace(rawCharsRegExp, function (chr) {
  3652. return baseEntities[chr] || chr
  3653. })
  3654. }
  3655. var encodeNumeric = function (text, attr) {
  3656. return text.replace(
  3657. attr ? attrsCharsRegExp : textCharsRegExp,
  3658. function (chr) {
  3659. if (chr.length > 1) {
  3660. return (
  3661. '&#' +
  3662. ((chr.charCodeAt(0) - 55296) * 1024 +
  3663. (chr.charCodeAt(1) - 56320) +
  3664. 65536) +
  3665. ';'
  3666. )
  3667. }
  3668. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';'
  3669. }
  3670. )
  3671. }
  3672. var encodeNamed = function (text, attr, entities) {
  3673. entities = entities || namedEntities
  3674. return text.replace(
  3675. attr ? attrsCharsRegExp : textCharsRegExp,
  3676. function (chr) {
  3677. return baseEntities[chr] || entities[chr] || chr
  3678. }
  3679. )
  3680. }
  3681. var getEncodeFunc = function (name, entities) {
  3682. var entitiesMap = buildEntitiesLookup(entities) || namedEntities
  3683. var encodeNamedAndNumeric = function (text, attr) {
  3684. return text.replace(
  3685. attr ? attrsCharsRegExp : textCharsRegExp,
  3686. function (chr) {
  3687. if (baseEntities[chr] !== undefined) {
  3688. return baseEntities[chr]
  3689. }
  3690. if (entitiesMap[chr] !== undefined) {
  3691. return entitiesMap[chr]
  3692. }
  3693. if (chr.length > 1) {
  3694. return (
  3695. '&#' +
  3696. ((chr.charCodeAt(0) - 55296) * 1024 +
  3697. (chr.charCodeAt(1) - 56320) +
  3698. 65536) +
  3699. ';'
  3700. )
  3701. }
  3702. return '&#' + chr.charCodeAt(0) + ';'
  3703. }
  3704. )
  3705. }
  3706. var encodeCustomNamed = function (text, attr) {
  3707. return encodeNamed(text, attr, entitiesMap)
  3708. }
  3709. var nameMap = makeMap$3(name.replace(/\+/g, ','))
  3710. if (nameMap.named && nameMap.numeric) {
  3711. return encodeNamedAndNumeric
  3712. }
  3713. if (nameMap.named) {
  3714. if (entities) {
  3715. return encodeCustomNamed
  3716. }
  3717. return encodeNamed
  3718. }
  3719. if (nameMap.numeric) {
  3720. return encodeNumeric
  3721. }
  3722. return encodeRaw
  3723. }
  3724. var decode = function (text) {
  3725. return text.replace(entityRegExp, function (all, numeric) {
  3726. if (numeric) {
  3727. if (numeric.charAt(0).toLowerCase() === 'x') {
  3728. numeric = parseInt(numeric.substr(1), 16)
  3729. } else {
  3730. numeric = parseInt(numeric, 10)
  3731. }
  3732. if (numeric > 65535) {
  3733. numeric -= 65536
  3734. return String.fromCharCode(
  3735. 55296 + (numeric >> 10),
  3736. 56320 + (numeric & 1023)
  3737. )
  3738. }
  3739. return asciiMap[numeric] || String.fromCharCode(numeric)
  3740. }
  3741. return reverseEntities[all] || namedEntities[all] || nativeDecode(all)
  3742. })
  3743. }
  3744. var Entities = {
  3745. encodeRaw: encodeRaw,
  3746. encodeAllRaw: encodeAllRaw,
  3747. encodeNumeric: encodeNumeric,
  3748. encodeNamed: encodeNamed,
  3749. getEncodeFunc: getEncodeFunc,
  3750. decode: decode,
  3751. }
  3752. var mapCache = {},
  3753. dummyObj = {}
  3754. var makeMap$2 = Tools.makeMap,
  3755. each$h = Tools.each,
  3756. extend$5 = Tools.extend,
  3757. explode$3 = Tools.explode,
  3758. inArray$2 = Tools.inArray
  3759. var split$1 = function (items, delim) {
  3760. items = Tools.trim(items)
  3761. return items ? items.split(delim || ' ') : []
  3762. }
  3763. var compileSchema = function (type) {
  3764. var schema = {}
  3765. var globalAttributes, blockContent
  3766. var phrasingContent, flowContent, html4BlockContent, html4PhrasingContent
  3767. var add = function (name, attributes, children) {
  3768. var ni, attributesOrder, element
  3769. var arrayToMap = function (array, obj) {
  3770. var map = {}
  3771. var i, l
  3772. for (i = 0, l = array.length; i < l; i++) {
  3773. map[array[i]] = obj || {}
  3774. }
  3775. return map
  3776. }
  3777. children = children || []
  3778. attributes = attributes || ''
  3779. if (typeof children === 'string') {
  3780. children = split$1(children)
  3781. }
  3782. var names = split$1(name)
  3783. ni = names.length
  3784. while (ni--) {
  3785. attributesOrder = split$1([globalAttributes, attributes].join(' '))
  3786. element = {
  3787. attributes: arrayToMap(attributesOrder),
  3788. attributesOrder: attributesOrder,
  3789. children: arrayToMap(children, dummyObj),
  3790. }
  3791. schema[names[ni]] = element
  3792. }
  3793. }
  3794. var addAttrs = function (name, attributes) {
  3795. var ni, schemaItem, i, l
  3796. var names = split$1(name)
  3797. ni = names.length
  3798. var attrs = split$1(attributes)
  3799. while (ni--) {
  3800. schemaItem = schema[names[ni]]
  3801. for (i = 0, l = attrs.length; i < l; i++) {
  3802. schemaItem.attributes[attrs[i]] = {}
  3803. schemaItem.attributesOrder.push(attrs[i])
  3804. }
  3805. }
  3806. }
  3807. if (mapCache[type]) {
  3808. return mapCache[type]
  3809. }
  3810. globalAttributes = 'id accesskey class dir lang style tabindex title role'
  3811. blockContent =
  3812. 'address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul'
  3813. phrasingContent =
  3814. 'a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd ' +
  3815. 'label map noscript object q s samp script select small span strong sub sup ' +
  3816. 'textarea u var #text #comment'
  3817. if (type !== 'html4') {
  3818. globalAttributes +=
  3819. ' contenteditable contextmenu draggable dropzone ' +
  3820. 'hidden spellcheck translate'
  3821. blockContent +=
  3822. ' article aside details dialog figure main header footer hgroup section nav'
  3823. phrasingContent +=
  3824. ' audio canvas command datalist mark meter output picture ' +
  3825. 'progress time wbr video ruby bdi keygen'
  3826. }
  3827. if (type !== 'html5-strict') {
  3828. globalAttributes += ' xml:lang'
  3829. html4PhrasingContent = 'acronym applet basefont big font strike tt'
  3830. phrasingContent = [phrasingContent, html4PhrasingContent].join(' ')
  3831. each$h(split$1(html4PhrasingContent), function (name) {
  3832. add(name, '', phrasingContent)
  3833. })
  3834. html4BlockContent = 'center dir isindex noframes'
  3835. blockContent = [blockContent, html4BlockContent].join(' ')
  3836. flowContent = [blockContent, phrasingContent].join(' ')
  3837. each$h(split$1(html4BlockContent), function (name) {
  3838. add(name, '', flowContent)
  3839. })
  3840. }
  3841. flowContent = flowContent || [blockContent, phrasingContent].join(' ')
  3842. add('html', 'manifest', 'head body')
  3843. add('head', '', 'base command link meta noscript script style title')
  3844. add('title hr noscript br')
  3845. add('base', 'href target')
  3846. add('link', 'href rel media hreflang type sizes hreflang')
  3847. add('meta', 'name http-equiv content charset')
  3848. add('style', 'media type scoped')
  3849. add('script', 'src async defer type charset')
  3850. add(
  3851. 'body',
  3852. 'onafterprint onbeforeprint onbeforeunload onblur onerror onfocus ' +
  3853. 'onhashchange onload onmessage onoffline ononline onpagehide onpageshow ' +
  3854. 'onpopstate onresize onscroll onstorage onunload',
  3855. flowContent
  3856. )
  3857. add('address dt dd div caption', '', flowContent)
  3858. add(
  3859. 'h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn',
  3860. '',
  3861. phrasingContent
  3862. )
  3863. add('blockquote', 'cite', flowContent)
  3864. add('ol', 'reversed start type', 'li')
  3865. add('ul', '', 'li')
  3866. add('li', 'value', flowContent)
  3867. add('dl', '', 'dt dd')
  3868. add('a', 'href target rel media hreflang type', phrasingContent)
  3869. add('q', 'cite', phrasingContent)
  3870. add('ins del', 'cite datetime', flowContent)
  3871. add('img', 'src sizes srcset alt usemap ismap width height')
  3872. add('iframe', 'src name width height', flowContent)
  3873. add('embed', 'src type width height')
  3874. add(
  3875. 'object',
  3876. 'data type typemustmatch name usemap form width height',
  3877. [flowContent, 'param'].join(' ')
  3878. )
  3879. add('param', 'name value')
  3880. add('map', 'name', [flowContent, 'area'].join(' '))
  3881. add('area', 'alt coords shape href target rel media hreflang type')
  3882. add(
  3883. 'table',
  3884. 'border',
  3885. 'caption colgroup thead tfoot tbody tr' + (type === 'html4' ? ' col' : '')
  3886. )
  3887. add('colgroup', 'span', 'col')
  3888. add('col', 'span')
  3889. add('tbody thead tfoot', '', 'tr')
  3890. add('tr', '', 'td th')
  3891. add('td', 'colspan rowspan headers', flowContent)
  3892. add('th', 'colspan rowspan headers scope abbr', flowContent)
  3893. add(
  3894. 'form',
  3895. 'accept-charset action autocomplete enctype method name novalidate target',
  3896. flowContent
  3897. )
  3898. add('fieldset', 'disabled form name', [flowContent, 'legend'].join(' '))
  3899. add('label', 'form for', phrasingContent)
  3900. add(
  3901. 'input',
  3902. 'accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate ' +
  3903. 'formtarget height list max maxlength min multiple name pattern readonly required size src step type value width'
  3904. )
  3905. add(
  3906. 'button',
  3907. 'disabled form formaction formenctype formmethod formnovalidate formtarget name type value',
  3908. type === 'html4' ? flowContent : phrasingContent
  3909. )
  3910. add(
  3911. 'select',
  3912. 'disabled form multiple name required size',
  3913. 'option optgroup'
  3914. )
  3915. add('optgroup', 'disabled label', 'option')
  3916. add('option', 'disabled label selected value')
  3917. add(
  3918. 'textarea',
  3919. 'cols dirname disabled form maxlength name readonly required rows wrap'
  3920. )
  3921. add('menu', 'type label', [flowContent, 'li'].join(' '))
  3922. add('noscript', '', flowContent)
  3923. if (type !== 'html4') {
  3924. add('wbr')
  3925. add('ruby', '', [phrasingContent, 'rt rp'].join(' '))
  3926. add('figcaption', '', flowContent)
  3927. add('mark rt rp summary bdi', '', phrasingContent)
  3928. add('canvas', 'width height', flowContent)
  3929. add(
  3930. 'video',
  3931. 'src crossorigin poster preload autoplay mediagroup loop ' +
  3932. 'muted controls width height buffered',
  3933. [flowContent, 'track source'].join(' ')
  3934. )
  3935. add(
  3936. 'audio',
  3937. 'src crossorigin preload autoplay mediagroup loop muted controls ' +
  3938. 'buffered volume',
  3939. [flowContent, 'track source'].join(' ')
  3940. )
  3941. add('picture', '', 'img source')
  3942. add('source', 'src srcset type media sizes')
  3943. add('track', 'kind src srclang label default')
  3944. add('datalist', '', [phrasingContent, 'option'].join(' '))
  3945. add('article section nav aside main header footer', '', flowContent)
  3946. add('hgroup', '', 'h1 h2 h3 h4 h5 h6')
  3947. add('figure', '', [flowContent, 'figcaption'].join(' '))
  3948. add('time', 'datetime', phrasingContent)
  3949. add('dialog', 'open', flowContent)
  3950. add('command', 'type label icon disabled checked radiogroup command')
  3951. add('output', 'for form name', phrasingContent)
  3952. add('progress', 'value max', phrasingContent)
  3953. add('meter', 'value min max low high optimum', phrasingContent)
  3954. add('details', 'open', [flowContent, 'summary'].join(' '))
  3955. add('keygen', 'autofocus challenge disabled form keytype name')
  3956. }
  3957. if (type !== 'html5-strict') {
  3958. addAttrs('script', 'language xml:space')
  3959. addAttrs('style', 'xml:space')
  3960. addAttrs(
  3961. 'object',
  3962. 'declare classid code codebase codetype archive standby align border hspace vspace'
  3963. )
  3964. addAttrs('embed', 'align name hspace vspace')
  3965. addAttrs('param', 'valuetype type')
  3966. addAttrs('a', 'charset name rev shape coords')
  3967. addAttrs('br', 'clear')
  3968. addAttrs(
  3969. 'applet',
  3970. 'codebase archive code object alt name width height align hspace vspace'
  3971. )
  3972. addAttrs('img', 'name longdesc align border hspace vspace')
  3973. addAttrs(
  3974. 'iframe',
  3975. 'longdesc frameborder marginwidth marginheight scrolling align'
  3976. )
  3977. addAttrs('font basefont', 'size color face')
  3978. addAttrs('input', 'usemap align')
  3979. addAttrs('select')
  3980. addAttrs('textarea')
  3981. addAttrs('h1 h2 h3 h4 h5 h6 div p legend caption', 'align')
  3982. addAttrs('ul', 'type compact')
  3983. addAttrs('li', 'type')
  3984. addAttrs('ol dl menu dir', 'compact')
  3985. addAttrs('pre', 'width xml:space')
  3986. addAttrs('hr', 'align noshade size width')
  3987. addAttrs('isindex', 'prompt')
  3988. addAttrs(
  3989. 'table',
  3990. 'summary width frame rules cellspacing cellpadding align bgcolor'
  3991. )
  3992. addAttrs('col', 'width align char charoff valign')
  3993. addAttrs('colgroup', 'width align char charoff valign')
  3994. addAttrs('thead', 'align char charoff valign')
  3995. addAttrs('tr', 'align char charoff valign bgcolor')
  3996. addAttrs(
  3997. 'th',
  3998. 'axis align char charoff valign nowrap bgcolor width height'
  3999. )
  4000. addAttrs('form', 'accept')
  4001. addAttrs(
  4002. 'td',
  4003. 'abbr axis scope align char charoff valign nowrap bgcolor width height'
  4004. )
  4005. addAttrs('tfoot', 'align char charoff valign')
  4006. addAttrs('tbody', 'align char charoff valign')
  4007. addAttrs('area', 'nohref')
  4008. addAttrs('body', 'background bgcolor text link vlink alink')
  4009. }
  4010. if (type !== 'html4') {
  4011. addAttrs('input button select textarea', 'autofocus')
  4012. addAttrs('input textarea', 'placeholder')
  4013. addAttrs('a', 'download')
  4014. addAttrs('link script img', 'crossorigin')
  4015. addAttrs('img', 'loading')
  4016. addAttrs('iframe', 'sandbox seamless allowfullscreen loading')
  4017. }
  4018. each$h(split$1('a form meter progress dfn'), function (name) {
  4019. if (schema[name]) {
  4020. delete schema[name].children[name]
  4021. }
  4022. })
  4023. delete schema.caption.children.table
  4024. delete schema.script
  4025. mapCache[type] = schema
  4026. return schema
  4027. }
  4028. var compileElementMap = function (value, mode) {
  4029. var styles
  4030. if (value) {
  4031. styles = {}
  4032. if (typeof value === 'string') {
  4033. value = { '*': value }
  4034. }
  4035. each$h(value, function (value, key) {
  4036. styles[key] = styles[key.toUpperCase()] =
  4037. mode === 'map' ? makeMap$2(value, /[, ]/) : explode$3(value, /[, ]/)
  4038. })
  4039. }
  4040. return styles
  4041. }
  4042. var Schema = function (settings) {
  4043. var elements = {}
  4044. var children = {}
  4045. var patternElements = []
  4046. var customElementsMap = {},
  4047. specialElements = {}
  4048. var createLookupTable = function (option, defaultValue, extendWith) {
  4049. var value = settings[option]
  4050. if (!value) {
  4051. value = mapCache[option]
  4052. if (!value) {
  4053. value = makeMap$2(
  4054. defaultValue,
  4055. ' ',
  4056. makeMap$2(defaultValue.toUpperCase(), ' ')
  4057. )
  4058. value = extend$5(value, extendWith)
  4059. mapCache[option] = value
  4060. }
  4061. } else {
  4062. value = makeMap$2(value, /[, ]/, makeMap$2(value.toUpperCase(), /[, ]/))
  4063. }
  4064. return value
  4065. }
  4066. settings = settings || {}
  4067. var schemaItems = compileSchema(settings.schema)
  4068. if (settings.verify_html === false) {
  4069. settings.valid_elements = '*[*]'
  4070. }
  4071. var validStyles = compileElementMap(settings.valid_styles)
  4072. var invalidStyles = compileElementMap(settings.invalid_styles, 'map')
  4073. var validClasses = compileElementMap(settings.valid_classes, 'map')
  4074. var whiteSpaceElementsMap = createLookupTable(
  4075. 'whitespace_elements',
  4076. 'pre script noscript style textarea video audio iframe object code'
  4077. )
  4078. var selfClosingElementsMap = createLookupTable(
  4079. 'self_closing_elements',
  4080. 'colgroup dd dt li option p td tfoot th thead tr'
  4081. )
  4082. var shortEndedElementsMap = createLookupTable(
  4083. 'short_ended_elements',
  4084. 'area base basefont br col frame hr img input isindex link ' +
  4085. 'meta param embed source wbr track'
  4086. )
  4087. var boolAttrMap = createLookupTable(
  4088. 'boolean_attributes',
  4089. 'checked compact declare defer disabled ismap multiple nohref noresize ' +
  4090. 'noshade nowrap readonly selected autoplay loop controls'
  4091. )
  4092. var nonEmptyOrMoveCaretBeforeOnEnter =
  4093. 'td th iframe video audio object script code'
  4094. var nonEmptyElementsMap = createLookupTable(
  4095. 'non_empty_elements',
  4096. nonEmptyOrMoveCaretBeforeOnEnter + ' pre',
  4097. shortEndedElementsMap
  4098. )
  4099. var moveCaretBeforeOnEnterElementsMap = createLookupTable(
  4100. 'move_caret_before_on_enter_elements',
  4101. nonEmptyOrMoveCaretBeforeOnEnter + ' table',
  4102. shortEndedElementsMap
  4103. )
  4104. var textBlockElementsMap = createLookupTable(
  4105. 'text_block_elements',
  4106. 'h1 h2 h3 h4 h5 h6 p div address pre form ' +
  4107. 'blockquote center dir fieldset header footer article section hgroup aside main nav figure'
  4108. )
  4109. var blockElementsMap = createLookupTable(
  4110. 'block_elements',
  4111. 'hr table tbody thead tfoot ' +
  4112. 'th tr td li ol ul caption dl dt dd noscript menu isindex option ' +
  4113. 'datalist select optgroup figcaption details summary',
  4114. textBlockElementsMap
  4115. )
  4116. var textInlineElementsMap = createLookupTable(
  4117. 'text_inline_elements',
  4118. 'span strong b em i font strike u var cite ' +
  4119. 'dfn code mark q sup sub samp'
  4120. )
  4121. each$h(
  4122. (
  4123. settings.special ||
  4124. 'script noscript iframe noframes noembed title style textarea xmp'
  4125. ).split(' '),
  4126. function (name) {
  4127. specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi')
  4128. }
  4129. )
  4130. var patternToRegExp = function (str) {
  4131. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$')
  4132. }
  4133. var addValidElements = function (validElements) {
  4134. var ei,
  4135. el,
  4136. ai,
  4137. al,
  4138. matches,
  4139. element,
  4140. attr,
  4141. attrData,
  4142. elementName,
  4143. attrName,
  4144. attrType,
  4145. attributes,
  4146. attributesOrder,
  4147. prefix,
  4148. outputName,
  4149. globalAttributes,
  4150. globalAttributesOrder,
  4151. value
  4152. var elementRuleRegExp =
  4153. /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)])?$/,
  4154. attrRuleRegExp = /^([!\-])?(\w+[\\:]:\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  4155. hasPatternsRegExp = /[*?+]/
  4156. if (validElements) {
  4157. var validElementsArr = split$1(validElements, ',')
  4158. if (elements['@']) {
  4159. globalAttributes = elements['@'].attributes
  4160. globalAttributesOrder = elements['@'].attributesOrder
  4161. }
  4162. for (ei = 0, el = validElementsArr.length; ei < el; ei++) {
  4163. matches = elementRuleRegExp.exec(validElementsArr[ei])
  4164. if (matches) {
  4165. prefix = matches[1]
  4166. elementName = matches[2]
  4167. outputName = matches[3]
  4168. attrData = matches[5]
  4169. attributes = {}
  4170. attributesOrder = []
  4171. element = {
  4172. attributes: attributes,
  4173. attributesOrder: attributesOrder,
  4174. }
  4175. if (prefix === '#') {
  4176. element.paddEmpty = true
  4177. }
  4178. if (prefix === '-') {
  4179. element.removeEmpty = true
  4180. }
  4181. if (matches[4] === '!') {
  4182. element.removeEmptyAttrs = true
  4183. }
  4184. if (globalAttributes) {
  4185. each$j(globalAttributes, function (value, key) {
  4186. attributes[key] = value
  4187. })
  4188. attributesOrder.push.apply(attributesOrder, globalAttributesOrder)
  4189. }
  4190. if (attrData) {
  4191. attrData = split$1(attrData, '|')
  4192. for (ai = 0, al = attrData.length; ai < al; ai++) {
  4193. matches = attrRuleRegExp.exec(attrData[ai])
  4194. if (matches) {
  4195. attr = {}
  4196. attrType = matches[1]
  4197. attrName = matches[2].replace(/[\\:]:/g, ':')
  4198. prefix = matches[3]
  4199. value = matches[4]
  4200. if (attrType === '!') {
  4201. element.attributesRequired =
  4202. element.attributesRequired || []
  4203. element.attributesRequired.push(attrName)
  4204. attr.required = true
  4205. }
  4206. if (attrType === '-') {
  4207. delete attributes[attrName]
  4208. attributesOrder.splice(
  4209. inArray$2(attributesOrder, attrName),
  4210. 1
  4211. )
  4212. continue
  4213. }
  4214. if (prefix) {
  4215. if (prefix === '=') {
  4216. element.attributesDefault =
  4217. element.attributesDefault || []
  4218. element.attributesDefault.push({
  4219. name: attrName,
  4220. value: value,
  4221. })
  4222. attr.defaultValue = value
  4223. }
  4224. if (prefix === ':') {
  4225. element.attributesForced = element.attributesForced || []
  4226. element.attributesForced.push({
  4227. name: attrName,
  4228. value: value,
  4229. })
  4230. attr.forcedValue = value
  4231. }
  4232. if (prefix === '<') {
  4233. attr.validValues = makeMap$2(value, '?')
  4234. }
  4235. }
  4236. if (hasPatternsRegExp.test(attrName)) {
  4237. element.attributePatterns = element.attributePatterns || []
  4238. attr.pattern = patternToRegExp(attrName)
  4239. element.attributePatterns.push(attr)
  4240. } else {
  4241. if (!attributes[attrName]) {
  4242. attributesOrder.push(attrName)
  4243. }
  4244. attributes[attrName] = attr
  4245. }
  4246. }
  4247. }
  4248. }
  4249. if (!globalAttributes && elementName === '@') {
  4250. globalAttributes = attributes
  4251. globalAttributesOrder = attributesOrder
  4252. }
  4253. if (outputName) {
  4254. element.outputName = elementName
  4255. elements[outputName] = element
  4256. }
  4257. if (hasPatternsRegExp.test(elementName)) {
  4258. element.pattern = patternToRegExp(elementName)
  4259. patternElements.push(element)
  4260. } else {
  4261. elements[elementName] = element
  4262. }
  4263. }
  4264. }
  4265. }
  4266. }
  4267. var setValidElements = function (validElements) {
  4268. elements = {}
  4269. patternElements = []
  4270. addValidElements(validElements)
  4271. each$h(schemaItems, function (element, name) {
  4272. children[name] = element.children
  4273. })
  4274. }
  4275. var addCustomElements = function (customElements) {
  4276. var customElementRegExp = /^(~)?(.+)$/
  4277. if (customElements) {
  4278. mapCache.text_block_elements = mapCache.block_elements = null
  4279. each$h(split$1(customElements, ','), function (rule) {
  4280. var matches = customElementRegExp.exec(rule),
  4281. inline = matches[1] === '~',
  4282. cloneName = inline ? 'span' : 'div',
  4283. name = matches[2]
  4284. children[name] = children[cloneName]
  4285. customElementsMap[name] = cloneName
  4286. if (!inline) {
  4287. blockElementsMap[name.toUpperCase()] = {}
  4288. blockElementsMap[name] = {}
  4289. }
  4290. if (!elements[name]) {
  4291. var customRule = elements[cloneName]
  4292. customRule = extend$5({}, customRule)
  4293. delete customRule.removeEmptyAttrs
  4294. delete customRule.removeEmpty
  4295. elements[name] = customRule
  4296. }
  4297. each$h(children, function (element, elmName) {
  4298. if (element[cloneName]) {
  4299. children[elmName] = element = extend$5({}, children[elmName])
  4300. element[name] = element[cloneName]
  4301. }
  4302. })
  4303. })
  4304. }
  4305. }
  4306. var addValidChildren = function (validChildren) {
  4307. var childRuleRegExp =
  4308. /^([+\-]?)([A-Za-z0-9_\-.\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]+)\[([^\]]+)]$/
  4309. mapCache[settings.schema] = null
  4310. if (validChildren) {
  4311. each$h(split$1(validChildren, ','), function (rule) {
  4312. var matches = childRuleRegExp.exec(rule)
  4313. var parent, prefix
  4314. if (matches) {
  4315. prefix = matches[1]
  4316. if (prefix) {
  4317. parent = children[matches[2]]
  4318. } else {
  4319. parent = children[matches[2]] = { '#comment': {} }
  4320. }
  4321. parent = children[matches[2]]
  4322. each$h(split$1(matches[3], '|'), function (child) {
  4323. if (prefix === '-') {
  4324. delete parent[child]
  4325. } else {
  4326. parent[child] = {}
  4327. }
  4328. })
  4329. }
  4330. })
  4331. }
  4332. }
  4333. var getElementRule = function (name) {
  4334. var element = elements[name],
  4335. i
  4336. if (element) {
  4337. return element
  4338. }
  4339. i = patternElements.length
  4340. while (i--) {
  4341. element = patternElements[i]
  4342. if (element.pattern.test(name)) {
  4343. return element
  4344. }
  4345. }
  4346. }
  4347. if (!settings.valid_elements) {
  4348. each$h(schemaItems, function (element, name) {
  4349. elements[name] = {
  4350. attributes: element.attributes,
  4351. attributesOrder: element.attributesOrder,
  4352. }
  4353. children[name] = element.children
  4354. })
  4355. if (settings.schema !== 'html5') {
  4356. each$h(split$1('strong/b em/i'), function (item) {
  4357. var items = split$1(item, '/')
  4358. elements[items[1]].outputName = items[0]
  4359. })
  4360. }
  4361. each$h(
  4362. split$1(
  4363. 'ol ul sub sup blockquote span font a table tbody strong em b i'
  4364. ),
  4365. function (name) {
  4366. if (elements[name]) {
  4367. elements[name].removeEmpty = true
  4368. }
  4369. }
  4370. )
  4371. each$h(
  4372. split$1('p h1 h2 h3 h4 h5 h6 th td pre div address caption li'),
  4373. function (name) {
  4374. elements[name].paddEmpty = true
  4375. }
  4376. )
  4377. each$h(split$1('span'), function (name) {
  4378. elements[name].removeEmptyAttrs = true
  4379. })
  4380. } else {
  4381. setValidElements(settings.valid_elements)
  4382. }
  4383. addCustomElements(settings.custom_elements)
  4384. addValidChildren(settings.valid_children)
  4385. addValidElements(settings.extended_valid_elements)
  4386. addValidChildren('+ol[ul|ol],+ul[ul|ol]')
  4387. each$h(
  4388. {
  4389. dd: 'dl',
  4390. dt: 'dl',
  4391. li: 'ul ol',
  4392. td: 'tr',
  4393. th: 'tr',
  4394. tr: 'tbody thead tfoot',
  4395. tbody: 'table',
  4396. thead: 'table',
  4397. tfoot: 'table',
  4398. legend: 'fieldset',
  4399. area: 'map',
  4400. param: 'video audio object',
  4401. },
  4402. function (parents, item) {
  4403. if (elements[item]) {
  4404. elements[item].parentsRequired = split$1(parents)
  4405. }
  4406. }
  4407. )
  4408. if (settings.invalid_elements) {
  4409. each$h(explode$3(settings.invalid_elements), function (item) {
  4410. if (elements[item]) {
  4411. delete elements[item]
  4412. }
  4413. })
  4414. }
  4415. if (!getElementRule('span')) {
  4416. addValidElements('span[!data-mce-type|*]')
  4417. }
  4418. var getValidStyles = constant(validStyles)
  4419. var getInvalidStyles = constant(invalidStyles)
  4420. var getValidClasses = constant(validClasses)
  4421. var getBoolAttrs = constant(boolAttrMap)
  4422. var getBlockElements = constant(blockElementsMap)
  4423. var getTextBlockElements = constant(textBlockElementsMap)
  4424. var getTextInlineElements = constant(textInlineElementsMap)
  4425. var getShortEndedElements = constant(shortEndedElementsMap)
  4426. var getSelfClosingElements = constant(selfClosingElementsMap)
  4427. var getNonEmptyElements = constant(nonEmptyElementsMap)
  4428. var getMoveCaretBeforeOnEnterElements = constant(
  4429. moveCaretBeforeOnEnterElementsMap
  4430. )
  4431. var getWhiteSpaceElements = constant(whiteSpaceElementsMap)
  4432. var getSpecialElements = constant(specialElements)
  4433. var isValidChild = function (name, child) {
  4434. var parent = children[name.toLowerCase()]
  4435. return !!(parent && parent[child.toLowerCase()])
  4436. }
  4437. var isValid = function (name, attr) {
  4438. var attrPatterns, i
  4439. var rule = getElementRule(name)
  4440. if (rule) {
  4441. if (attr) {
  4442. if (rule.attributes[attr]) {
  4443. return true
  4444. }
  4445. attrPatterns = rule.attributePatterns
  4446. if (attrPatterns) {
  4447. i = attrPatterns.length
  4448. while (i--) {
  4449. if (attrPatterns[i].pattern.test(name)) {
  4450. return true
  4451. }
  4452. }
  4453. }
  4454. } else {
  4455. return true
  4456. }
  4457. }
  4458. return false
  4459. }
  4460. var getCustomElements = constant(customElementsMap)
  4461. return {
  4462. children: children,
  4463. elements: elements,
  4464. getValidStyles: getValidStyles,
  4465. getValidClasses: getValidClasses,
  4466. getBlockElements: getBlockElements,
  4467. getInvalidStyles: getInvalidStyles,
  4468. getShortEndedElements: getShortEndedElements,
  4469. getTextBlockElements: getTextBlockElements,
  4470. getTextInlineElements: getTextInlineElements,
  4471. getBoolAttrs: getBoolAttrs,
  4472. getElementRule: getElementRule,
  4473. getSelfClosingElements: getSelfClosingElements,
  4474. getNonEmptyElements: getNonEmptyElements,
  4475. getMoveCaretBeforeOnEnterElements: getMoveCaretBeforeOnEnterElements,
  4476. getWhiteSpaceElements: getWhiteSpaceElements,
  4477. getSpecialElements: getSpecialElements,
  4478. isValidChild: isValidChild,
  4479. isValid: isValid,
  4480. getCustomElements: getCustomElements,
  4481. addValidElements: addValidElements,
  4482. setValidElements: setValidElements,
  4483. addCustomElements: addCustomElements,
  4484. addValidChildren: addValidChildren,
  4485. }
  4486. }
  4487. var toHex = function (match, r, g, b) {
  4488. var hex = function (val) {
  4489. val = parseInt(val, 10).toString(16)
  4490. return val.length > 1 ? val : '0' + val
  4491. }
  4492. return '#' + hex(r) + hex(g) + hex(b)
  4493. }
  4494. var Styles = function (settings, schema) {
  4495. var _this = this
  4496. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi
  4497. var urlOrStrRegExp =
  4498. /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi
  4499. var styleRegExp = /\s*([^:]+):\s*([^;]+);?/g
  4500. var trimRightRegExp = /\s+$/
  4501. var i
  4502. var encodingLookup = {}
  4503. var validStyles
  4504. var invalidStyles
  4505. var invisibleChar = zeroWidth
  4506. settings = settings || {}
  4507. if (schema) {
  4508. validStyles = schema.getValidStyles()
  4509. invalidStyles = schema.getInvalidStyles()
  4510. }
  4511. var encodingItems = ('\\" \\\' \\; \\: ; : ' + invisibleChar).split(' ')
  4512. for (i = 0; i < encodingItems.length; i++) {
  4513. encodingLookup[encodingItems[i]] = invisibleChar + i
  4514. encodingLookup[invisibleChar + i] = encodingItems[i]
  4515. }
  4516. return {
  4517. toHex: function (color) {
  4518. return color.replace(rgbRegExp, toHex)
  4519. },
  4520. parse: function (css) {
  4521. var styles = {}
  4522. var matches, name, value, isEncoded
  4523. var urlConverter = settings.url_converter
  4524. var urlConverterScope = settings.url_converter_scope || _this
  4525. var compress = function (prefix, suffix, noJoin) {
  4526. var top = styles[prefix + '-top' + suffix]
  4527. if (!top) {
  4528. return
  4529. }
  4530. var right = styles[prefix + '-right' + suffix]
  4531. if (!right) {
  4532. return
  4533. }
  4534. var bottom = styles[prefix + '-bottom' + suffix]
  4535. if (!bottom) {
  4536. return
  4537. }
  4538. var left = styles[prefix + '-left' + suffix]
  4539. if (!left) {
  4540. return
  4541. }
  4542. var box = [top, right, bottom, left]
  4543. i = box.length - 1
  4544. while (i--) {
  4545. if (box[i] !== box[i + 1]) {
  4546. break
  4547. }
  4548. }
  4549. if (i > -1 && noJoin) {
  4550. return
  4551. }
  4552. styles[prefix + suffix] = i === -1 ? box[0] : box.join(' ')
  4553. delete styles[prefix + '-top' + suffix]
  4554. delete styles[prefix + '-right' + suffix]
  4555. delete styles[prefix + '-bottom' + suffix]
  4556. delete styles[prefix + '-left' + suffix]
  4557. }
  4558. var canCompress = function (key) {
  4559. var value = styles[key],
  4560. i
  4561. if (!value) {
  4562. return
  4563. }
  4564. value = value.split(' ')
  4565. i = value.length
  4566. while (i--) {
  4567. if (value[i] !== value[0]) {
  4568. return false
  4569. }
  4570. }
  4571. styles[key] = value[0]
  4572. return true
  4573. }
  4574. var compress2 = function (target, a, b, c) {
  4575. if (!canCompress(a)) {
  4576. return
  4577. }
  4578. if (!canCompress(b)) {
  4579. return
  4580. }
  4581. if (!canCompress(c)) {
  4582. return
  4583. }
  4584. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c]
  4585. delete styles[a]
  4586. delete styles[b]
  4587. delete styles[c]
  4588. }
  4589. var encode = function (str) {
  4590. isEncoded = true
  4591. return encodingLookup[str]
  4592. }
  4593. var decode = function (str, keepSlashes) {
  4594. if (isEncoded) {
  4595. str = str.replace(/\uFEFF[0-9]/g, function (str) {
  4596. return encodingLookup[str]
  4597. })
  4598. }
  4599. if (!keepSlashes) {
  4600. str = str.replace(/\\([\'\";:])/g, '$1')
  4601. }
  4602. return str
  4603. }
  4604. var decodeSingleHexSequence = function (escSeq) {
  4605. return String.fromCharCode(parseInt(escSeq.slice(1), 16))
  4606. }
  4607. var decodeHexSequences = function (value) {
  4608. return value.replace(/\\[0-9a-f]+/gi, decodeSingleHexSequence)
  4609. }
  4610. var processUrl = function (match, url, url2, url3, str, str2) {
  4611. str = str || str2
  4612. if (str) {
  4613. str = decode(str)
  4614. return "'" + str.replace(/\'/g, "\\'") + "'"
  4615. }
  4616. url = decode(url || url2 || url3)
  4617. if (!settings.allow_script_urls) {
  4618. var scriptUrl = url.replace(/[\s\r\n]+/g, '')
  4619. if (/(java|vb)script:/i.test(scriptUrl)) {
  4620. return ''
  4621. }
  4622. if (
  4623. !settings.allow_svg_data_urls &&
  4624. /^data:image\/svg/i.test(scriptUrl)
  4625. ) {
  4626. return ''
  4627. }
  4628. }
  4629. if (urlConverter) {
  4630. url = urlConverter.call(urlConverterScope, url, 'style')
  4631. }
  4632. return "url('" + url.replace(/\'/g, "\\'") + "')"
  4633. }
  4634. if (css) {
  4635. css = css.replace(/[\u0000-\u001F]/g, '')
  4636. css = css
  4637. .replace(/\\[\"\';:\uFEFF]/g, encode)
  4638. .replace(/\"[^\"]+\"|\'[^\']+\'/g, function (str) {
  4639. return str.replace(/[;:]/g, encode)
  4640. })
  4641. while ((matches = styleRegExp.exec(css))) {
  4642. styleRegExp.lastIndex = matches.index + matches[0].length
  4643. name = matches[1].replace(trimRightRegExp, '').toLowerCase()
  4644. value = matches[2].replace(trimRightRegExp, '')
  4645. if (name && value) {
  4646. name = decodeHexSequences(name)
  4647. value = decodeHexSequences(value)
  4648. if (
  4649. name.indexOf(invisibleChar) !== -1 ||
  4650. name.indexOf('"') !== -1
  4651. ) {
  4652. continue
  4653. }
  4654. if (
  4655. !settings.allow_script_urls &&
  4656. (name === 'behavior' || /expression\s*\(|\/\*|\*\//.test(value))
  4657. ) {
  4658. continue
  4659. }
  4660. if (name === 'font-weight' && value === '700') {
  4661. value = 'bold'
  4662. } else if (name === 'color' || name === 'background-color') {
  4663. value = value.toLowerCase()
  4664. }
  4665. value = value.replace(rgbRegExp, toHex)
  4666. value = value.replace(urlOrStrRegExp, processUrl)
  4667. styles[name] = isEncoded ? decode(value, true) : value
  4668. }
  4669. }
  4670. compress('border', '', true)
  4671. compress('border', '-width')
  4672. compress('border', '-color')
  4673. compress('border', '-style')
  4674. compress('padding', '')
  4675. compress('margin', '')
  4676. compress2('border', 'border-width', 'border-style', 'border-color')
  4677. if (styles.border === 'medium none') {
  4678. delete styles.border
  4679. }
  4680. if (styles['border-image'] === 'none') {
  4681. delete styles['border-image']
  4682. }
  4683. }
  4684. return styles
  4685. },
  4686. serialize: function (styles, elementName) {
  4687. var css = ''
  4688. var serializeStyles = function (name) {
  4689. var value
  4690. var styleList = validStyles[name]
  4691. if (styleList) {
  4692. for (var i_1 = 0, l = styleList.length; i_1 < l; i_1++) {
  4693. name = styleList[i_1]
  4694. value = styles[name]
  4695. if (value) {
  4696. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';'
  4697. }
  4698. }
  4699. }
  4700. }
  4701. var isValid = function (name, elementName) {
  4702. var styleMap = invalidStyles['*']
  4703. if (styleMap && styleMap[name]) {
  4704. return false
  4705. }
  4706. styleMap = invalidStyles[elementName]
  4707. return !(styleMap && styleMap[name])
  4708. }
  4709. if (elementName && validStyles) {
  4710. serializeStyles('*')
  4711. serializeStyles(elementName)
  4712. } else {
  4713. each$j(styles, function (value, name) {
  4714. if (value && (!invalidStyles || isValid(name, elementName))) {
  4715. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';'
  4716. }
  4717. })
  4718. }
  4719. return css
  4720. },
  4721. }
  4722. }
  4723. var deprecated = {
  4724. keyLocation: true,
  4725. layerX: true,
  4726. layerY: true,
  4727. returnValue: true,
  4728. webkitMovementX: true,
  4729. webkitMovementY: true,
  4730. keyIdentifier: true,
  4731. mozPressure: true,
  4732. }
  4733. var isNativeEvent = function (event) {
  4734. return event instanceof Event || isFunction(event.initEvent)
  4735. }
  4736. var hasIsDefaultPrevented = function (event) {
  4737. return (
  4738. event.isDefaultPrevented === always || event.isDefaultPrevented === never
  4739. )
  4740. }
  4741. var needsNormalizing = function (event) {
  4742. return isNullable(event.preventDefault) || isNativeEvent(event)
  4743. }
  4744. var clone$2 = function (originalEvent, data) {
  4745. var event = data !== null && data !== void 0 ? data : {}
  4746. for (var name_1 in originalEvent) {
  4747. if (!has$2(deprecated, name_1)) {
  4748. event[name_1] = originalEvent[name_1]
  4749. }
  4750. }
  4751. if (isNonNullable(event.composedPath)) {
  4752. event.composedPath = function () {
  4753. return originalEvent.composedPath()
  4754. }
  4755. }
  4756. return event
  4757. }
  4758. var normalize$3 = function (type, originalEvent, fallbackTarget, data) {
  4759. var _a
  4760. var event = clone$2(originalEvent, data)
  4761. event.type = type
  4762. if (isNullable(event.target)) {
  4763. event.target =
  4764. (_a = event.srcElement) !== null && _a !== void 0 ? _a : fallbackTarget
  4765. }
  4766. if (needsNormalizing(originalEvent)) {
  4767. event.preventDefault = function () {
  4768. event.defaultPrevented = true
  4769. event.isDefaultPrevented = always
  4770. if (isFunction(originalEvent.preventDefault)) {
  4771. originalEvent.preventDefault()
  4772. } else if (isNativeEvent(originalEvent)) {
  4773. originalEvent.returnValue = false
  4774. }
  4775. }
  4776. event.stopPropagation = function () {
  4777. event.cancelBubble = true
  4778. event.isPropagationStopped = always
  4779. if (isFunction(originalEvent.stopPropagation)) {
  4780. originalEvent.stopPropagation()
  4781. } else if (isNativeEvent(originalEvent)) {
  4782. originalEvent.cancelBubble = true
  4783. }
  4784. }
  4785. event.stopImmediatePropagation = function () {
  4786. event.isImmediatePropagationStopped = always
  4787. event.stopPropagation()
  4788. }
  4789. if (!hasIsDefaultPrevented(event)) {
  4790. event.isDefaultPrevented =
  4791. event.defaultPrevented === true ? always : never
  4792. event.isPropagationStopped =
  4793. event.cancelBubble === true ? always : never
  4794. event.isImmediatePropagationStopped = never
  4795. }
  4796. }
  4797. return event
  4798. }
  4799. var eventExpandoPrefix = 'mce-data-'
  4800. var mouseEventRe = /^(?:mouse|contextmenu)|click/
  4801. var addEvent = function (target, name, callback, capture) {
  4802. if (target.addEventListener) {
  4803. target.addEventListener(name, callback, capture || false)
  4804. } else if (target.attachEvent) {
  4805. target.attachEvent('on' + name, callback)
  4806. }
  4807. }
  4808. var removeEvent = function (target, name, callback, capture) {
  4809. if (target.removeEventListener) {
  4810. target.removeEventListener(name, callback, capture || false)
  4811. } else if (target.detachEvent) {
  4812. target.detachEvent('on' + name, callback)
  4813. }
  4814. }
  4815. var isMouseEvent = function (event) {
  4816. return isNonNullable(event) && mouseEventRe.test(event.type)
  4817. }
  4818. var fix = function (originalEvent, data) {
  4819. var event = normalize$3(originalEvent.type, originalEvent, document, data)
  4820. if (
  4821. isMouseEvent(originalEvent) &&
  4822. isUndefined(originalEvent.pageX) &&
  4823. !isUndefined(originalEvent.clientX)
  4824. ) {
  4825. var eventDoc = event.target.ownerDocument || document
  4826. var doc = eventDoc.documentElement
  4827. var body = eventDoc.body
  4828. var mouseEvent = event
  4829. mouseEvent.pageX =
  4830. originalEvent.clientX +
  4831. ((doc && doc.scrollLeft) || (body && body.scrollLeft) || 0) -
  4832. ((doc && doc.clientLeft) || (body && body.clientLeft) || 0)
  4833. mouseEvent.pageY =
  4834. originalEvent.clientY +
  4835. ((doc && doc.scrollTop) || (body && body.scrollTop) || 0) -
  4836. ((doc && doc.clientTop) || (body && body.clientTop) || 0)
  4837. }
  4838. if (isUndefined(event.metaKey)) {
  4839. event.metaKey = false
  4840. }
  4841. return event
  4842. }
  4843. var bindOnReady = function (win, callback, eventUtils) {
  4844. var doc = win.document,
  4845. event = { type: 'ready' }
  4846. if (eventUtils.domLoaded) {
  4847. callback(event)
  4848. return
  4849. }
  4850. var isDocReady = function () {
  4851. return (
  4852. doc.readyState === 'complete' ||
  4853. (doc.readyState === 'interactive' && doc.body)
  4854. )
  4855. }
  4856. var readyHandler = function () {
  4857. removeEvent(win, 'DOMContentLoaded', readyHandler)
  4858. removeEvent(win, 'load', readyHandler)
  4859. if (!eventUtils.domLoaded) {
  4860. eventUtils.domLoaded = true
  4861. callback(event)
  4862. }
  4863. win = null
  4864. }
  4865. if (isDocReady()) {
  4866. readyHandler()
  4867. } else {
  4868. addEvent(win, 'DOMContentLoaded', readyHandler)
  4869. }
  4870. if (!eventUtils.domLoaded) {
  4871. addEvent(win, 'load', readyHandler)
  4872. }
  4873. }
  4874. var EventUtils = (function () {
  4875. function EventUtils() {
  4876. this.domLoaded = false
  4877. this.events = {}
  4878. this.count = 1
  4879. this.expando = eventExpandoPrefix + (+new Date()).toString(32)
  4880. this.hasMouseEnterLeave = 'onmouseenter' in document.documentElement
  4881. this.hasFocusIn = 'onfocusin' in document.documentElement
  4882. this.count = 1
  4883. }
  4884. EventUtils.prototype.bind = function (target, names, callback, scope) {
  4885. var self = this
  4886. var id, callbackList, i, name, fakeName, nativeHandler, capture
  4887. var win = window
  4888. var defaultNativeHandler = function (evt) {
  4889. self.executeHandlers(fix(evt || win.event), id)
  4890. }
  4891. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4892. return
  4893. }
  4894. if (!target[self.expando]) {
  4895. id = self.count++
  4896. target[self.expando] = id
  4897. self.events[id] = {}
  4898. } else {
  4899. id = target[self.expando]
  4900. }
  4901. scope = scope || target
  4902. var namesList = names.split(' ')
  4903. i = namesList.length
  4904. while (i--) {
  4905. name = namesList[i]
  4906. nativeHandler = defaultNativeHandler
  4907. fakeName = capture = false
  4908. if (name === 'DOMContentLoaded') {
  4909. name = 'ready'
  4910. }
  4911. if (
  4912. self.domLoaded &&
  4913. name === 'ready' &&
  4914. target.readyState === 'complete'
  4915. ) {
  4916. callback.call(scope, fix({ type: name }))
  4917. continue
  4918. }
  4919. if (!self.hasMouseEnterLeave) {
  4920. fakeName = self.mouseEnterLeave[name]
  4921. if (fakeName) {
  4922. nativeHandler = function (evt) {
  4923. var current = evt.currentTarget
  4924. var related = evt.relatedTarget
  4925. if (related && current.contains) {
  4926. related = current.contains(related)
  4927. } else {
  4928. while (related && related !== current) {
  4929. related = related.parentNode
  4930. }
  4931. }
  4932. if (!related) {
  4933. evt = fix(evt || win.event)
  4934. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter'
  4935. evt.target = current
  4936. self.executeHandlers(evt, id)
  4937. }
  4938. }
  4939. }
  4940. }
  4941. if (!self.hasFocusIn && (name === 'focusin' || name === 'focusout')) {
  4942. capture = true
  4943. fakeName = name === 'focusin' ? 'focus' : 'blur'
  4944. nativeHandler = function (evt) {
  4945. evt = fix(evt || win.event)
  4946. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout'
  4947. self.executeHandlers(evt, id)
  4948. }
  4949. }
  4950. callbackList = self.events[id][name]
  4951. if (!callbackList) {
  4952. self.events[id][name] = callbackList = [
  4953. {
  4954. func: callback,
  4955. scope: scope,
  4956. },
  4957. ]
  4958. callbackList.fakeName = fakeName
  4959. callbackList.capture = capture
  4960. callbackList.nativeHandler = nativeHandler
  4961. if (name === 'ready') {
  4962. bindOnReady(target, nativeHandler, self)
  4963. } else {
  4964. addEvent(target, fakeName || name, nativeHandler, capture)
  4965. }
  4966. } else {
  4967. if (name === 'ready' && self.domLoaded) {
  4968. callback(fix({ type: name }))
  4969. } else {
  4970. callbackList.push({
  4971. func: callback,
  4972. scope: scope,
  4973. })
  4974. }
  4975. }
  4976. }
  4977. target = callbackList = null
  4978. return callback
  4979. }
  4980. EventUtils.prototype.unbind = function (target, names, callback) {
  4981. var callbackList, i, ci, name, eventMap
  4982. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4983. return this
  4984. }
  4985. var id = target[this.expando]
  4986. if (id) {
  4987. eventMap = this.events[id]
  4988. if (names) {
  4989. var namesList = names.split(' ')
  4990. i = namesList.length
  4991. while (i--) {
  4992. name = namesList[i]
  4993. callbackList = eventMap[name]
  4994. if (callbackList) {
  4995. if (callback) {
  4996. ci = callbackList.length
  4997. while (ci--) {
  4998. if (callbackList[ci].func === callback) {
  4999. var nativeHandler = callbackList.nativeHandler
  5000. var fakeName = callbackList.fakeName,
  5001. capture = callbackList.capture
  5002. callbackList = callbackList
  5003. .slice(0, ci)
  5004. .concat(callbackList.slice(ci + 1))
  5005. callbackList.nativeHandler = nativeHandler
  5006. callbackList.fakeName = fakeName
  5007. callbackList.capture = capture
  5008. eventMap[name] = callbackList
  5009. }
  5010. }
  5011. }
  5012. if (!callback || callbackList.length === 0) {
  5013. delete eventMap[name]
  5014. removeEvent(
  5015. target,
  5016. callbackList.fakeName || name,
  5017. callbackList.nativeHandler,
  5018. callbackList.capture
  5019. )
  5020. }
  5021. }
  5022. }
  5023. } else {
  5024. each$j(eventMap, function (callbackList, name) {
  5025. removeEvent(
  5026. target,
  5027. callbackList.fakeName || name,
  5028. callbackList.nativeHandler,
  5029. callbackList.capture
  5030. )
  5031. })
  5032. eventMap = {}
  5033. }
  5034. for (name in eventMap) {
  5035. if (has$2(eventMap, name)) {
  5036. return this
  5037. }
  5038. }
  5039. delete this.events[id]
  5040. try {
  5041. delete target[this.expando]
  5042. } catch (ex) {
  5043. target[this.expando] = null
  5044. }
  5045. }
  5046. return this
  5047. }
  5048. EventUtils.prototype.fire = function (target, name, args) {
  5049. var id
  5050. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  5051. return this
  5052. }
  5053. var event = fix(
  5054. {
  5055. type: name,
  5056. target: target,
  5057. },
  5058. args
  5059. )
  5060. do {
  5061. id = target[this.expando]
  5062. if (id) {
  5063. this.executeHandlers(event, id)
  5064. }
  5065. target =
  5066. target.parentNode ||
  5067. target.ownerDocument ||
  5068. target.defaultView ||
  5069. target.parentWindow
  5070. } while (target && !event.isPropagationStopped())
  5071. return this
  5072. }
  5073. EventUtils.prototype.clean = function (target) {
  5074. var i, children
  5075. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  5076. return this
  5077. }
  5078. if (target[this.expando]) {
  5079. this.unbind(target)
  5080. }
  5081. if (!target.getElementsByTagName) {
  5082. target = target.document
  5083. }
  5084. if (target && target.getElementsByTagName) {
  5085. this.unbind(target)
  5086. children = target.getElementsByTagName('*')
  5087. i = children.length
  5088. while (i--) {
  5089. target = children[i]
  5090. if (target[this.expando]) {
  5091. this.unbind(target)
  5092. }
  5093. }
  5094. }
  5095. return this
  5096. }
  5097. EventUtils.prototype.destroy = function () {
  5098. this.events = {}
  5099. }
  5100. EventUtils.prototype.cancel = function (e) {
  5101. if (e) {
  5102. e.preventDefault()
  5103. e.stopImmediatePropagation()
  5104. }
  5105. return false
  5106. }
  5107. EventUtils.prototype.executeHandlers = function (evt, id) {
  5108. var container = this.events[id]
  5109. var callbackList = container && container[evt.type]
  5110. if (callbackList) {
  5111. for (var i = 0, l = callbackList.length; i < l; i++) {
  5112. var callback = callbackList[i]
  5113. if (callback && callback.func.call(callback.scope, evt) === false) {
  5114. evt.preventDefault()
  5115. }
  5116. if (evt.isImmediatePropagationStopped()) {
  5117. return
  5118. }
  5119. }
  5120. }
  5121. }
  5122. EventUtils.Event = new EventUtils()
  5123. return EventUtils
  5124. })()
  5125. var support,
  5126. Expr,
  5127. getText,
  5128. isXML,
  5129. tokenize,
  5130. compile,
  5131. select$1,
  5132. outermostContext,
  5133. sortInput,
  5134. hasDuplicate,
  5135. setDocument,
  5136. document$1,
  5137. docElem,
  5138. documentIsHTML,
  5139. rbuggyQSA,
  5140. rbuggyMatches,
  5141. matches,
  5142. contains,
  5143. expando = 'sizzle' + -new Date(),
  5144. preferredDoc = window.document,
  5145. dirruns = 0,
  5146. done = 0,
  5147. classCache = createCache(),
  5148. tokenCache = createCache(),
  5149. compilerCache = createCache(),
  5150. sortOrder = function (a, b) {
  5151. if (a === b) {
  5152. hasDuplicate = true
  5153. }
  5154. return 0
  5155. },
  5156. strundefined = typeof undefined,
  5157. MAX_NEGATIVE = 1 << 31,
  5158. hasOwn = {}.hasOwnProperty,
  5159. arr = [],
  5160. pop = arr.pop,
  5161. push_native = arr.push,
  5162. push$1 = arr.push,
  5163. slice$1 = arr.slice,
  5164. indexOf =
  5165. arr.indexOf ||
  5166. function (elem) {
  5167. var i = 0,
  5168. len = this.length
  5169. for (; i < len; i++) {
  5170. if (this[i] === elem) {
  5171. return i
  5172. }
  5173. }
  5174. return -1
  5175. },
  5176. booleans =
  5177. 'checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped',
  5178. whitespace = '[\\x20\\t\\r\\n\\f]',
  5179. identifier = '(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+',
  5180. attributes =
  5181. '\\[' +
  5182. whitespace +
  5183. '*(' +
  5184. identifier +
  5185. ')(?:' +
  5186. whitespace +
  5187. '*([*^$|!~]?=)' +
  5188. whitespace +
  5189. '*(?:\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)"|(' +
  5190. identifier +
  5191. '))|)' +
  5192. whitespace +
  5193. '*\\]',
  5194. pseudos =
  5195. ':(' +
  5196. identifier +
  5197. ')(?:\\((' +
  5198. '(\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)")|' +
  5199. '((?:\\\\.|[^\\\\()[\\]]|' +
  5200. attributes +
  5201. ')*)|' +
  5202. '.*' +
  5203. ')\\)|)',
  5204. rtrim = new RegExp(
  5205. '^' + whitespace + '+|((?:^|[^\\\\])(?:\\\\.)*)' + whitespace + '+$',
  5206. 'g'
  5207. ),
  5208. rcomma = new RegExp('^' + whitespace + '*,' + whitespace + '*'),
  5209. rcombinators = new RegExp(
  5210. '^' + whitespace + '*([>+~]|' + whitespace + ')' + whitespace + '*'
  5211. ),
  5212. rattributeQuotes = new RegExp(
  5213. '=' + whitespace + '*([^\\]\'"]*?)' + whitespace + '*\\]',
  5214. 'g'
  5215. ),
  5216. rpseudo = new RegExp(pseudos),
  5217. ridentifier = new RegExp('^' + identifier + '$'),
  5218. matchExpr = {
  5219. ID: new RegExp('^#(' + identifier + ')'),
  5220. CLASS: new RegExp('^\\.(' + identifier + ')'),
  5221. TAG: new RegExp('^(' + identifier + '|[*])'),
  5222. ATTR: new RegExp('^' + attributes),
  5223. PSEUDO: new RegExp('^' + pseudos),
  5224. CHILD: new RegExp(
  5225. '^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(' +
  5226. whitespace +
  5227. '*(even|odd|(([+-]|)(\\d*)n|)' +
  5228. whitespace +
  5229. '*(?:([+-]|)' +
  5230. whitespace +
  5231. '*(\\d+)|))' +
  5232. whitespace +
  5233. '*\\)|)',
  5234. 'i'
  5235. ),
  5236. bool: new RegExp('^(?:' + booleans + ')$', 'i'),
  5237. needsContext: new RegExp(
  5238. '^' +
  5239. whitespace +
  5240. '*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(' +
  5241. whitespace +
  5242. '*((?:-\\d)?\\d*)' +
  5243. whitespace +
  5244. '*\\)|)(?=[^-]|$)',
  5245. 'i'
  5246. ),
  5247. },
  5248. rinputs = /^(?:input|select|textarea|button)$/i,
  5249. rheader = /^h\d$/i,
  5250. rnative = /^[^{]+\{\s*\[native \w/,
  5251. rquickExpr$1 = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
  5252. rsibling = /[+~]/,
  5253. rescape = /'|\\/g,
  5254. runescape = new RegExp(
  5255. '\\\\([\\da-f]{1,6}' + whitespace + '?|(' + whitespace + ')|.)',
  5256. 'ig'
  5257. ),
  5258. funescape = function (_, escaped, escapedWhitespace) {
  5259. var high = '0x' + escaped - 65536
  5260. return high !== high || escapedWhitespace
  5261. ? escaped
  5262. : high < 0
  5263. ? String.fromCharCode(high + 65536)
  5264. : String.fromCharCode((high >> 10) | 55296, (high & 1023) | 56320)
  5265. }
  5266. try {
  5267. push$1.apply(
  5268. (arr = slice$1.call(preferredDoc.childNodes)),
  5269. preferredDoc.childNodes
  5270. )
  5271. arr[preferredDoc.childNodes.length].nodeType
  5272. } catch (e) {
  5273. push$1 = {
  5274. apply: arr.length
  5275. ? function (target, els) {
  5276. push_native.apply(target, slice$1.call(els))
  5277. }
  5278. : function (target, els) {
  5279. var j = target.length,
  5280. i = 0
  5281. while ((target[j++] = els[i++])) {}
  5282. target.length = j - 1
  5283. },
  5284. }
  5285. }
  5286. var Sizzle = function (selector, context, results, seed) {
  5287. var match, elem, m, nodeType, i, groups, old, nid, newContext, newSelector
  5288. if (
  5289. (context ? context.ownerDocument || context : preferredDoc) !== document$1
  5290. ) {
  5291. setDocument(context)
  5292. }
  5293. context = context || document$1
  5294. results = results || []
  5295. if (!selector || typeof selector !== 'string') {
  5296. return results
  5297. }
  5298. if ((nodeType = context.nodeType) !== 1 && nodeType !== 9) {
  5299. return []
  5300. }
  5301. if (documentIsHTML && !seed) {
  5302. if ((match = rquickExpr$1.exec(selector))) {
  5303. if ((m = match[1])) {
  5304. if (nodeType === 9) {
  5305. elem = context.getElementById(m)
  5306. if (elem && elem.parentNode) {
  5307. if (elem.id === m) {
  5308. results.push(elem)
  5309. return results
  5310. }
  5311. } else {
  5312. return results
  5313. }
  5314. } else {
  5315. if (
  5316. context.ownerDocument &&
  5317. (elem = context.ownerDocument.getElementById(m)) &&
  5318. contains(context, elem) &&
  5319. elem.id === m
  5320. ) {
  5321. results.push(elem)
  5322. return results
  5323. }
  5324. }
  5325. } else if (match[2]) {
  5326. push$1.apply(results, context.getElementsByTagName(selector))
  5327. return results
  5328. } else if ((m = match[3]) && support.getElementsByClassName) {
  5329. push$1.apply(results, context.getElementsByClassName(m))
  5330. return results
  5331. }
  5332. }
  5333. if (support.qsa && (!rbuggyQSA || !rbuggyQSA.test(selector))) {
  5334. nid = old = expando
  5335. newContext = context
  5336. newSelector = nodeType === 9 && selector
  5337. if (nodeType === 1 && context.nodeName.toLowerCase() !== 'object') {
  5338. groups = tokenize(selector)
  5339. if ((old = context.getAttribute('id'))) {
  5340. nid = old.replace(rescape, '\\$&')
  5341. } else {
  5342. context.setAttribute('id', nid)
  5343. }
  5344. nid = "[id='" + nid + "'] "
  5345. i = groups.length
  5346. while (i--) {
  5347. groups[i] = nid + toSelector(groups[i])
  5348. }
  5349. newContext =
  5350. (rsibling.test(selector) && testContext(context.parentNode)) ||
  5351. context
  5352. newSelector = groups.join(',')
  5353. }
  5354. if (newSelector) {
  5355. try {
  5356. push$1.apply(results, newContext.querySelectorAll(newSelector))
  5357. return results
  5358. } catch (qsaError) {
  5359. } finally {
  5360. if (!old) {
  5361. context.removeAttribute('id')
  5362. }
  5363. }
  5364. }
  5365. }
  5366. }
  5367. return select$1(selector.replace(rtrim, '$1'), context, results, seed)
  5368. }
  5369. function createCache() {
  5370. var keys = []
  5371. function cache(key, value) {
  5372. if (keys.push(key + ' ') > Expr.cacheLength) {
  5373. delete cache[keys.shift()]
  5374. }
  5375. return (cache[key + ' '] = value)
  5376. }
  5377. return cache
  5378. }
  5379. function markFunction(fn) {
  5380. fn[expando] = true
  5381. return fn
  5382. }
  5383. function siblingCheck(a, b) {
  5384. var cur = b && a,
  5385. diff =
  5386. cur &&
  5387. a.nodeType === 1 &&
  5388. b.nodeType === 1 &&
  5389. (~b.sourceIndex || MAX_NEGATIVE) - (~a.sourceIndex || MAX_NEGATIVE)
  5390. if (diff) {
  5391. return diff
  5392. }
  5393. if (cur) {
  5394. while ((cur = cur.nextSibling)) {
  5395. if (cur === b) {
  5396. return -1
  5397. }
  5398. }
  5399. }
  5400. return a ? 1 : -1
  5401. }
  5402. function createInputPseudo(type) {
  5403. return function (elem) {
  5404. var name = elem.nodeName.toLowerCase()
  5405. return name === 'input' && elem.type === type
  5406. }
  5407. }
  5408. function createButtonPseudo(type) {
  5409. return function (elem) {
  5410. var name = elem.nodeName.toLowerCase()
  5411. return (name === 'input' || name === 'button') && elem.type === type
  5412. }
  5413. }
  5414. function createPositionalPseudo(fn) {
  5415. return markFunction(function (argument) {
  5416. argument = +argument
  5417. return markFunction(function (seed, matches) {
  5418. var j,
  5419. matchIndexes = fn([], seed.length, argument),
  5420. i = matchIndexes.length
  5421. while (i--) {
  5422. if (seed[(j = matchIndexes[i])]) {
  5423. seed[j] = !(matches[j] = seed[j])
  5424. }
  5425. }
  5426. })
  5427. })
  5428. }
  5429. function testContext(context) {
  5430. return (
  5431. context && typeof context.getElementsByTagName !== strundefined && context
  5432. )
  5433. }
  5434. support = Sizzle.support = {}
  5435. isXML = Sizzle.isXML = function (elem) {
  5436. var documentElement = elem && (elem.ownerDocument || elem).documentElement
  5437. return documentElement ? documentElement.nodeName !== 'HTML' : false
  5438. }
  5439. setDocument = Sizzle.setDocument = function (node) {
  5440. var hasCompare,
  5441. doc = node ? node.ownerDocument || node : preferredDoc,
  5442. parent = doc.defaultView
  5443. function getTop(win) {
  5444. try {
  5445. return win.top
  5446. } catch (ex) {}
  5447. return null
  5448. }
  5449. if (doc === document$1 || doc.nodeType !== 9 || !doc.documentElement) {
  5450. return document$1
  5451. }
  5452. document$1 = doc
  5453. docElem = doc.documentElement
  5454. documentIsHTML = !isXML(doc)
  5455. if (parent && parent !== getTop(parent)) {
  5456. if (parent.addEventListener) {
  5457. parent.addEventListener(
  5458. 'unload',
  5459. function () {
  5460. setDocument()
  5461. },
  5462. false
  5463. )
  5464. } else if (parent.attachEvent) {
  5465. parent.attachEvent('onunload', function () {
  5466. setDocument()
  5467. })
  5468. }
  5469. }
  5470. support.attributes = true
  5471. support.getElementsByTagName = true
  5472. support.getElementsByClassName = rnative.test(doc.getElementsByClassName)
  5473. support.getById = true
  5474. Expr.find.ID = function (id, context) {
  5475. if (typeof context.getElementById !== strundefined && documentIsHTML) {
  5476. var m = context.getElementById(id)
  5477. return m && m.parentNode ? [m] : []
  5478. }
  5479. }
  5480. Expr.filter.ID = function (id) {
  5481. var attrId = id.replace(runescape, funescape)
  5482. return function (elem) {
  5483. return elem.getAttribute('id') === attrId
  5484. }
  5485. }
  5486. Expr.find.TAG = support.getElementsByTagName
  5487. ? function (tag, context) {
  5488. if (typeof context.getElementsByTagName !== strundefined) {
  5489. return context.getElementsByTagName(tag)
  5490. }
  5491. }
  5492. : function (tag, context) {
  5493. var elem,
  5494. tmp = [],
  5495. i = 0,
  5496. results = context.getElementsByTagName(tag)
  5497. if (tag === '*') {
  5498. while ((elem = results[i++])) {
  5499. if (elem.nodeType === 1) {
  5500. tmp.push(elem)
  5501. }
  5502. }
  5503. return tmp
  5504. }
  5505. return results
  5506. }
  5507. Expr.find.CLASS =
  5508. support.getElementsByClassName &&
  5509. function (className, context) {
  5510. if (documentIsHTML) {
  5511. return context.getElementsByClassName(className)
  5512. }
  5513. }
  5514. rbuggyMatches = []
  5515. rbuggyQSA = []
  5516. support.disconnectedMatch = true
  5517. rbuggyQSA = rbuggyQSA.length && new RegExp(rbuggyQSA.join('|'))
  5518. rbuggyMatches = rbuggyMatches.length && new RegExp(rbuggyMatches.join('|'))
  5519. hasCompare = rnative.test(docElem.compareDocumentPosition)
  5520. contains =
  5521. hasCompare || rnative.test(docElem.contains)
  5522. ? function (a, b) {
  5523. var adown = a.nodeType === 9 ? a.documentElement : a,
  5524. bup = b && b.parentNode
  5525. return (
  5526. a === bup ||
  5527. !!(
  5528. bup &&
  5529. bup.nodeType === 1 &&
  5530. (adown.contains
  5531. ? adown.contains(bup)
  5532. : a.compareDocumentPosition &&
  5533. a.compareDocumentPosition(bup) & 16)
  5534. )
  5535. )
  5536. }
  5537. : function (a, b) {
  5538. if (b) {
  5539. while ((b = b.parentNode)) {
  5540. if (b === a) {
  5541. return true
  5542. }
  5543. }
  5544. }
  5545. return false
  5546. }
  5547. sortOrder = hasCompare
  5548. ? function (a, b) {
  5549. if (a === b) {
  5550. hasDuplicate = true
  5551. return 0
  5552. }
  5553. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition
  5554. if (compare) {
  5555. return compare
  5556. }
  5557. compare =
  5558. (a.ownerDocument || a) === (b.ownerDocument || b)
  5559. ? a.compareDocumentPosition(b)
  5560. : 1
  5561. if (
  5562. compare & 1 ||
  5563. (!support.sortDetached && b.compareDocumentPosition(a) === compare)
  5564. ) {
  5565. if (
  5566. a === doc ||
  5567. (a.ownerDocument === preferredDoc && contains(preferredDoc, a))
  5568. ) {
  5569. return -1
  5570. }
  5571. if (
  5572. b === doc ||
  5573. (b.ownerDocument === preferredDoc && contains(preferredDoc, b))
  5574. ) {
  5575. return 1
  5576. }
  5577. return sortInput
  5578. ? indexOf.call(sortInput, a) - indexOf.call(sortInput, b)
  5579. : 0
  5580. }
  5581. return compare & 4 ? -1 : 1
  5582. }
  5583. : function (a, b) {
  5584. if (a === b) {
  5585. hasDuplicate = true
  5586. return 0
  5587. }
  5588. var cur,
  5589. i = 0,
  5590. aup = a.parentNode,
  5591. bup = b.parentNode,
  5592. ap = [a],
  5593. bp = [b]
  5594. if (!aup || !bup) {
  5595. return a === doc
  5596. ? -1
  5597. : b === doc
  5598. ? 1
  5599. : aup
  5600. ? -1
  5601. : bup
  5602. ? 1
  5603. : sortInput
  5604. ? indexOf.call(sortInput, a) - indexOf.call(sortInput, b)
  5605. : 0
  5606. } else if (aup === bup) {
  5607. return siblingCheck(a, b)
  5608. }
  5609. cur = a
  5610. while ((cur = cur.parentNode)) {
  5611. ap.unshift(cur)
  5612. }
  5613. cur = b
  5614. while ((cur = cur.parentNode)) {
  5615. bp.unshift(cur)
  5616. }
  5617. while (ap[i] === bp[i]) {
  5618. i++
  5619. }
  5620. return i
  5621. ? siblingCheck(ap[i], bp[i])
  5622. : ap[i] === preferredDoc
  5623. ? -1
  5624. : bp[i] === preferredDoc
  5625. ? 1
  5626. : 0
  5627. }
  5628. return doc
  5629. }
  5630. Sizzle.matches = function (expr, elements) {
  5631. return Sizzle(expr, null, null, elements)
  5632. }
  5633. Sizzle.matchesSelector = function (elem, expr) {
  5634. if ((elem.ownerDocument || elem) !== document$1) {
  5635. setDocument(elem)
  5636. }
  5637. expr = expr.replace(rattributeQuotes, "='$1']")
  5638. if (
  5639. support.matchesSelector &&
  5640. documentIsHTML &&
  5641. (!rbuggyMatches || !rbuggyMatches.test(expr)) &&
  5642. (!rbuggyQSA || !rbuggyQSA.test(expr))
  5643. ) {
  5644. try {
  5645. var ret = matches.call(elem, expr)
  5646. if (
  5647. ret ||
  5648. support.disconnectedMatch ||
  5649. (elem.document && elem.document.nodeType !== 11)
  5650. ) {
  5651. return ret
  5652. }
  5653. } catch (e) {}
  5654. }
  5655. return Sizzle(expr, document$1, null, [elem]).length > 0
  5656. }
  5657. Sizzle.contains = function (context, elem) {
  5658. if ((context.ownerDocument || context) !== document$1) {
  5659. setDocument(context)
  5660. }
  5661. return contains(context, elem)
  5662. }
  5663. Sizzle.attr = function (elem, name) {
  5664. if ((elem.ownerDocument || elem) !== document$1) {
  5665. setDocument(elem)
  5666. }
  5667. var fn = Expr.attrHandle[name.toLowerCase()],
  5668. val =
  5669. fn && hasOwn.call(Expr.attrHandle, name.toLowerCase())
  5670. ? fn(elem, name, !documentIsHTML)
  5671. : undefined
  5672. return val !== undefined
  5673. ? val
  5674. : support.attributes || !documentIsHTML
  5675. ? elem.getAttribute(name)
  5676. : (val = elem.getAttributeNode(name)) && val.specified
  5677. ? val.value
  5678. : null
  5679. }
  5680. Sizzle.error = function (msg) {
  5681. throw new Error('Syntax error, unrecognized expression: ' + msg)
  5682. }
  5683. Sizzle.uniqueSort = function (results) {
  5684. var elem,
  5685. duplicates = [],
  5686. j = 0,
  5687. i = 0
  5688. hasDuplicate = !support.detectDuplicates
  5689. sortInput = !support.sortStable && results.slice(0)
  5690. results.sort(sortOrder)
  5691. if (hasDuplicate) {
  5692. while ((elem = results[i++])) {
  5693. if (elem === results[i]) {
  5694. j = duplicates.push(i)
  5695. }
  5696. }
  5697. while (j--) {
  5698. results.splice(duplicates[j], 1)
  5699. }
  5700. }
  5701. sortInput = null
  5702. return results
  5703. }
  5704. getText = Sizzle.getText = function (elem) {
  5705. var node,
  5706. ret = '',
  5707. i = 0,
  5708. nodeType = elem.nodeType
  5709. if (!nodeType) {
  5710. while ((node = elem[i++])) {
  5711. ret += getText(node)
  5712. }
  5713. } else if (nodeType === 1 || nodeType === 9 || nodeType === 11) {
  5714. if (typeof elem.textContent === 'string') {
  5715. return elem.textContent
  5716. } else {
  5717. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  5718. ret += getText(elem)
  5719. }
  5720. }
  5721. } else if (nodeType === 3 || nodeType === 4) {
  5722. return elem.nodeValue
  5723. }
  5724. return ret
  5725. }
  5726. Expr = Sizzle.selectors = {
  5727. cacheLength: 50,
  5728. createPseudo: markFunction,
  5729. match: matchExpr,
  5730. attrHandle: {},
  5731. find: {},
  5732. relative: {
  5733. '>': {
  5734. dir: 'parentNode',
  5735. first: true,
  5736. },
  5737. ' ': { dir: 'parentNode' },
  5738. '+': {
  5739. dir: 'previousSibling',
  5740. first: true,
  5741. },
  5742. '~': { dir: 'previousSibling' },
  5743. },
  5744. preFilter: {
  5745. ATTR: function (match) {
  5746. match[1] = match[1].replace(runescape, funescape)
  5747. match[3] = (match[3] || match[4] || match[5] || '').replace(
  5748. runescape,
  5749. funescape
  5750. )
  5751. if (match[2] === '~=') {
  5752. match[3] = ' ' + match[3] + ' '
  5753. }
  5754. return match.slice(0, 4)
  5755. },
  5756. CHILD: function (match) {
  5757. match[1] = match[1].toLowerCase()
  5758. if (match[1].slice(0, 3) === 'nth') {
  5759. if (!match[3]) {
  5760. Sizzle.error(match[0])
  5761. }
  5762. match[4] = +(match[4]
  5763. ? match[5] + (match[6] || 1)
  5764. : 2 * (match[3] === 'even' || match[3] === 'odd'))
  5765. match[5] = +(match[7] + match[8] || match[3] === 'odd')
  5766. } else if (match[3]) {
  5767. Sizzle.error(match[0])
  5768. }
  5769. return match
  5770. },
  5771. PSEUDO: function (match) {
  5772. var excess,
  5773. unquoted = !match[6] && match[2]
  5774. if (matchExpr.CHILD.test(match[0])) {
  5775. return null
  5776. }
  5777. if (match[3]) {
  5778. match[2] = match[4] || match[5] || ''
  5779. } else if (
  5780. unquoted &&
  5781. rpseudo.test(unquoted) &&
  5782. (excess = tokenize(unquoted, true)) &&
  5783. (excess =
  5784. unquoted.indexOf(')', unquoted.length - excess) - unquoted.length)
  5785. ) {
  5786. match[0] = match[0].slice(0, excess)
  5787. match[2] = unquoted.slice(0, excess)
  5788. }
  5789. return match.slice(0, 3)
  5790. },
  5791. },
  5792. filter: {
  5793. TAG: function (nodeNameSelector) {
  5794. var nodeName = nodeNameSelector
  5795. .replace(runescape, funescape)
  5796. .toLowerCase()
  5797. return nodeNameSelector === '*'
  5798. ? function () {
  5799. return true
  5800. }
  5801. : function (elem) {
  5802. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName
  5803. }
  5804. },
  5805. CLASS: function (className) {
  5806. var pattern = classCache[className + ' ']
  5807. return (
  5808. pattern ||
  5809. ((pattern = new RegExp(
  5810. '(^|' + whitespace + ')' + className + '(' + whitespace + '|$)'
  5811. )) &&
  5812. classCache(className, function (elem) {
  5813. return pattern.test(
  5814. (typeof elem.className === 'string' && elem.className) ||
  5815. (typeof elem.getAttribute !== strundefined &&
  5816. elem.getAttribute('class')) ||
  5817. ''
  5818. )
  5819. }))
  5820. )
  5821. },
  5822. ATTR: function (name, operator, check) {
  5823. return function (elem) {
  5824. var result = Sizzle.attr(elem, name)
  5825. if (result == null) {
  5826. return operator === '!='
  5827. }
  5828. if (!operator) {
  5829. return true
  5830. }
  5831. result += ''
  5832. return operator === '='
  5833. ? result === check
  5834. : operator === '!='
  5835. ? result !== check
  5836. : operator === '^='
  5837. ? check && result.indexOf(check) === 0
  5838. : operator === '*='
  5839. ? check && result.indexOf(check) > -1
  5840. : operator === '$='
  5841. ? check && result.slice(-check.length) === check
  5842. : operator === '~='
  5843. ? (' ' + result + ' ').indexOf(check) > -1
  5844. : operator === '|='
  5845. ? result === check ||
  5846. result.slice(0, check.length + 1) === check + '-'
  5847. : false
  5848. }
  5849. },
  5850. CHILD: function (type, what, argument, first, last) {
  5851. var simple = type.slice(0, 3) !== 'nth',
  5852. forward = type.slice(-4) !== 'last',
  5853. ofType = what === 'of-type'
  5854. return first === 1 && last === 0
  5855. ? function (elem) {
  5856. return !!elem.parentNode
  5857. }
  5858. : function (elem, context, xml) {
  5859. var cache,
  5860. outerCache,
  5861. node,
  5862. diff,
  5863. nodeIndex,
  5864. start,
  5865. dir = simple !== forward ? 'nextSibling' : 'previousSibling',
  5866. parent = elem.parentNode,
  5867. name = ofType && elem.nodeName.toLowerCase(),
  5868. useCache = !xml && !ofType
  5869. if (parent) {
  5870. if (simple) {
  5871. while (dir) {
  5872. node = elem
  5873. while ((node = node[dir])) {
  5874. if (
  5875. ofType
  5876. ? node.nodeName.toLowerCase() === name
  5877. : node.nodeType === 1
  5878. ) {
  5879. return false
  5880. }
  5881. }
  5882. start = dir = type === 'only' && !start && 'nextSibling'
  5883. }
  5884. return true
  5885. }
  5886. start = [forward ? parent.firstChild : parent.lastChild]
  5887. if (forward && useCache) {
  5888. outerCache = parent[expando] || (parent[expando] = {})
  5889. cache = outerCache[type] || []
  5890. nodeIndex = cache[0] === dirruns && cache[1]
  5891. diff = cache[0] === dirruns && cache[2]
  5892. node = nodeIndex && parent.childNodes[nodeIndex]
  5893. while (
  5894. (node =
  5895. (++nodeIndex && node && node[dir]) ||
  5896. (diff = nodeIndex = 0) ||
  5897. start.pop())
  5898. ) {
  5899. if (node.nodeType === 1 && ++diff && node === elem) {
  5900. outerCache[type] = [dirruns, nodeIndex, diff]
  5901. break
  5902. }
  5903. }
  5904. } else if (
  5905. useCache &&
  5906. (cache = (elem[expando] || (elem[expando] = {}))[type]) &&
  5907. cache[0] === dirruns
  5908. ) {
  5909. diff = cache[1]
  5910. } else {
  5911. while (
  5912. (node =
  5913. (++nodeIndex && node && node[dir]) ||
  5914. (diff = nodeIndex = 0) ||
  5915. start.pop())
  5916. ) {
  5917. if (
  5918. (ofType
  5919. ? node.nodeName.toLowerCase() === name
  5920. : node.nodeType === 1) &&
  5921. ++diff
  5922. ) {
  5923. if (useCache) {
  5924. ;(node[expando] || (node[expando] = {}))[type] = [
  5925. dirruns,
  5926. diff,
  5927. ]
  5928. }
  5929. if (node === elem) {
  5930. break
  5931. }
  5932. }
  5933. }
  5934. }
  5935. diff -= last
  5936. return (
  5937. diff === first || (diff % first === 0 && diff / first >= 0)
  5938. )
  5939. }
  5940. }
  5941. },
  5942. PSEUDO: function (pseudo, argument) {
  5943. var args,
  5944. fn =
  5945. Expr.pseudos[pseudo] ||
  5946. Expr.setFilters[pseudo.toLowerCase()] ||
  5947. Sizzle.error('unsupported pseudo: ' + pseudo)
  5948. if (fn[expando]) {
  5949. return fn(argument)
  5950. }
  5951. if (fn.length > 1) {
  5952. args = [pseudo, pseudo, '', argument]
  5953. return Expr.setFilters.hasOwnProperty(pseudo.toLowerCase())
  5954. ? markFunction(function (seed, matches) {
  5955. var idx,
  5956. matched = fn(seed, argument),
  5957. i = matched.length
  5958. while (i--) {
  5959. idx = indexOf.call(seed, matched[i])
  5960. seed[idx] = !(matches[idx] = matched[i])
  5961. }
  5962. })
  5963. : function (elem) {
  5964. return fn(elem, 0, args)
  5965. }
  5966. }
  5967. return fn
  5968. },
  5969. },
  5970. pseudos: {
  5971. not: markFunction(function (selector) {
  5972. var input = [],
  5973. results = [],
  5974. matcher = compile(selector.replace(rtrim, '$1'))
  5975. return matcher[expando]
  5976. ? markFunction(function (seed, matches, context, xml) {
  5977. var elem,
  5978. unmatched = matcher(seed, null, xml, []),
  5979. i = seed.length
  5980. while (i--) {
  5981. if ((elem = unmatched[i])) {
  5982. seed[i] = !(matches[i] = elem)
  5983. }
  5984. }
  5985. })
  5986. : function (elem, context, xml) {
  5987. input[0] = elem
  5988. matcher(input, null, xml, results)
  5989. input[0] = null
  5990. return !results.pop()
  5991. }
  5992. }),
  5993. has: markFunction(function (selector) {
  5994. return function (elem) {
  5995. return Sizzle(selector, elem).length > 0
  5996. }
  5997. }),
  5998. contains: markFunction(function (text) {
  5999. text = text.replace(runescape, funescape)
  6000. return function (elem) {
  6001. return (
  6002. (elem.textContent || elem.innerText || getText(elem)).indexOf(
  6003. text
  6004. ) > -1
  6005. )
  6006. }
  6007. }),
  6008. lang: markFunction(function (lang) {
  6009. if (!ridentifier.test(lang || '')) {
  6010. Sizzle.error('unsupported lang: ' + lang)
  6011. }
  6012. lang = lang.replace(runescape, funescape).toLowerCase()
  6013. return function (elem) {
  6014. var elemLang
  6015. do {
  6016. if (
  6017. (elemLang = documentIsHTML
  6018. ? elem.lang
  6019. : elem.getAttribute('xml:lang') || elem.getAttribute('lang'))
  6020. ) {
  6021. elemLang = elemLang.toLowerCase()
  6022. return elemLang === lang || elemLang.indexOf(lang + '-') === 0
  6023. }
  6024. } while ((elem = elem.parentNode) && elem.nodeType === 1)
  6025. return false
  6026. }
  6027. }),
  6028. target: function (elem) {
  6029. var hash = window.location && window.location.hash
  6030. return hash && hash.slice(1) === elem.id
  6031. },
  6032. root: function (elem) {
  6033. return elem === docElem
  6034. },
  6035. focus: function (elem) {
  6036. return (
  6037. elem === document$1.activeElement &&
  6038. (!document$1.hasFocus || document$1.hasFocus()) &&
  6039. !!(elem.type || elem.href || ~elem.tabIndex)
  6040. )
  6041. },
  6042. enabled: function (elem) {
  6043. return elem.disabled === false
  6044. },
  6045. disabled: function (elem) {
  6046. return elem.disabled === true
  6047. },
  6048. checked: function (elem) {
  6049. var nodeName = elem.nodeName.toLowerCase()
  6050. return (
  6051. (nodeName === 'input' && !!elem.checked) ||
  6052. (nodeName === 'option' && !!elem.selected)
  6053. )
  6054. },
  6055. selected: function (elem) {
  6056. if (elem.parentNode) {
  6057. elem.parentNode.selectedIndex
  6058. }
  6059. return elem.selected === true
  6060. },
  6061. empty: function (elem) {
  6062. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  6063. if (elem.nodeType < 6) {
  6064. return false
  6065. }
  6066. }
  6067. return true
  6068. },
  6069. parent: function (elem) {
  6070. return !Expr.pseudos.empty(elem)
  6071. },
  6072. header: function (elem) {
  6073. return rheader.test(elem.nodeName)
  6074. },
  6075. input: function (elem) {
  6076. return rinputs.test(elem.nodeName)
  6077. },
  6078. button: function (elem) {
  6079. var name = elem.nodeName.toLowerCase()
  6080. return (name === 'input' && elem.type === 'button') || name === 'button'
  6081. },
  6082. text: function (elem) {
  6083. var attr
  6084. return (
  6085. elem.nodeName.toLowerCase() === 'input' &&
  6086. elem.type === 'text' &&
  6087. ((attr = elem.getAttribute('type')) == null ||
  6088. attr.toLowerCase() === 'text')
  6089. )
  6090. },
  6091. first: createPositionalPseudo(function () {
  6092. return [0]
  6093. }),
  6094. last: createPositionalPseudo(function (matchIndexes, length) {
  6095. return [length - 1]
  6096. }),
  6097. eq: createPositionalPseudo(function (matchIndexes, length, argument) {
  6098. return [argument < 0 ? argument + length : argument]
  6099. }),
  6100. even: createPositionalPseudo(function (matchIndexes, length) {
  6101. var i = 0
  6102. for (; i < length; i += 2) {
  6103. matchIndexes.push(i)
  6104. }
  6105. return matchIndexes
  6106. }),
  6107. odd: createPositionalPseudo(function (matchIndexes, length) {
  6108. var i = 1
  6109. for (; i < length; i += 2) {
  6110. matchIndexes.push(i)
  6111. }
  6112. return matchIndexes
  6113. }),
  6114. lt: createPositionalPseudo(function (matchIndexes, length, argument) {
  6115. var i = argument < 0 ? argument + length : argument
  6116. for (; --i >= 0; ) {
  6117. matchIndexes.push(i)
  6118. }
  6119. return matchIndexes
  6120. }),
  6121. gt: createPositionalPseudo(function (matchIndexes, length, argument) {
  6122. var i = argument < 0 ? argument + length : argument
  6123. for (; ++i < length; ) {
  6124. matchIndexes.push(i)
  6125. }
  6126. return matchIndexes
  6127. }),
  6128. },
  6129. }
  6130. Expr.pseudos.nth = Expr.pseudos.eq
  6131. each$k(['radio', 'checkbox', 'file', 'password', 'image'], function (i) {
  6132. Expr.pseudos[i] = createInputPseudo(i)
  6133. })
  6134. each$k(['submit', 'reset'], function (i) {
  6135. Expr.pseudos[i] = createButtonPseudo(i)
  6136. })
  6137. function setFilters() {}
  6138. setFilters.prototype = Expr.filters = Expr.pseudos
  6139. Expr.setFilters = new setFilters()
  6140. tokenize = Sizzle.tokenize = function (selector, parseOnly) {
  6141. var matched,
  6142. match,
  6143. tokens,
  6144. type,
  6145. soFar,
  6146. groups,
  6147. preFilters,
  6148. cached = tokenCache[selector + ' ']
  6149. if (cached) {
  6150. return parseOnly ? 0 : cached.slice(0)
  6151. }
  6152. soFar = selector
  6153. groups = []
  6154. preFilters = Expr.preFilter
  6155. while (soFar) {
  6156. if (!matched || (match = rcomma.exec(soFar))) {
  6157. if (match) {
  6158. soFar = soFar.slice(match[0].length) || soFar
  6159. }
  6160. groups.push((tokens = []))
  6161. }
  6162. matched = false
  6163. if ((match = rcombinators.exec(soFar))) {
  6164. matched = match.shift()
  6165. tokens.push({
  6166. value: matched,
  6167. type: match[0].replace(rtrim, ' '),
  6168. })
  6169. soFar = soFar.slice(matched.length)
  6170. }
  6171. for (type in Expr.filter) {
  6172. if (!Expr.filter.hasOwnProperty(type)) {
  6173. continue
  6174. }
  6175. if (
  6176. (match = matchExpr[type].exec(soFar)) &&
  6177. (!preFilters[type] || (match = preFilters[type](match)))
  6178. ) {
  6179. matched = match.shift()
  6180. tokens.push({
  6181. value: matched,
  6182. type: type,
  6183. matches: match,
  6184. })
  6185. soFar = soFar.slice(matched.length)
  6186. }
  6187. }
  6188. if (!matched) {
  6189. break
  6190. }
  6191. }
  6192. return parseOnly
  6193. ? soFar.length
  6194. : soFar
  6195. ? Sizzle.error(selector)
  6196. : tokenCache(selector, groups).slice(0)
  6197. }
  6198. function toSelector(tokens) {
  6199. var i = 0,
  6200. len = tokens.length,
  6201. selector = ''
  6202. for (; i < len; i++) {
  6203. selector += tokens[i].value
  6204. }
  6205. return selector
  6206. }
  6207. function addCombinator(matcher, combinator, base) {
  6208. var dir = combinator.dir,
  6209. checkNonElements = base && dir === 'parentNode',
  6210. doneName = done++
  6211. return combinator.first
  6212. ? function (elem, context, xml) {
  6213. while ((elem = elem[dir])) {
  6214. if (elem.nodeType === 1 || checkNonElements) {
  6215. return matcher(elem, context, xml)
  6216. }
  6217. }
  6218. }
  6219. : function (elem, context, xml) {
  6220. var oldCache,
  6221. outerCache,
  6222. newCache = [dirruns, doneName]
  6223. if (xml) {
  6224. while ((elem = elem[dir])) {
  6225. if (elem.nodeType === 1 || checkNonElements) {
  6226. if (matcher(elem, context, xml)) {
  6227. return true
  6228. }
  6229. }
  6230. }
  6231. } else {
  6232. while ((elem = elem[dir])) {
  6233. if (elem.nodeType === 1 || checkNonElements) {
  6234. outerCache = elem[expando] || (elem[expando] = {})
  6235. if (
  6236. (oldCache = outerCache[dir]) &&
  6237. oldCache[0] === dirruns &&
  6238. oldCache[1] === doneName
  6239. ) {
  6240. return (newCache[2] = oldCache[2])
  6241. } else {
  6242. outerCache[dir] = newCache
  6243. if ((newCache[2] = matcher(elem, context, xml))) {
  6244. return true
  6245. }
  6246. }
  6247. }
  6248. }
  6249. }
  6250. }
  6251. }
  6252. function elementMatcher(matchers) {
  6253. return matchers.length > 1
  6254. ? function (elem, context, xml) {
  6255. var i = matchers.length
  6256. while (i--) {
  6257. if (!matchers[i](elem, context, xml)) {
  6258. return false
  6259. }
  6260. }
  6261. return true
  6262. }
  6263. : matchers[0]
  6264. }
  6265. function multipleContexts(selector, contexts, results) {
  6266. var i = 0,
  6267. len = contexts.length
  6268. for (; i < len; i++) {
  6269. Sizzle(selector, contexts[i], results)
  6270. }
  6271. return results
  6272. }
  6273. function condense(unmatched, map, filter, context, xml) {
  6274. var elem,
  6275. newUnmatched = [],
  6276. i = 0,
  6277. len = unmatched.length,
  6278. mapped = map != null
  6279. for (; i < len; i++) {
  6280. if ((elem = unmatched[i])) {
  6281. if (!filter || filter(elem, context, xml)) {
  6282. newUnmatched.push(elem)
  6283. if (mapped) {
  6284. map.push(i)
  6285. }
  6286. }
  6287. }
  6288. }
  6289. return newUnmatched
  6290. }
  6291. function setMatcher(
  6292. preFilter,
  6293. selector,
  6294. matcher,
  6295. postFilter,
  6296. postFinder,
  6297. postSelector
  6298. ) {
  6299. if (postFilter && !postFilter[expando]) {
  6300. postFilter = setMatcher(postFilter)
  6301. }
  6302. if (postFinder && !postFinder[expando]) {
  6303. postFinder = setMatcher(postFinder, postSelector)
  6304. }
  6305. return markFunction(function (seed, results, context, xml) {
  6306. var temp,
  6307. i,
  6308. elem,
  6309. preMap = [],
  6310. postMap = [],
  6311. preexisting = results.length,
  6312. elems =
  6313. seed ||
  6314. multipleContexts(
  6315. selector || '*',
  6316. context.nodeType ? [context] : context,
  6317. []
  6318. ),
  6319. matcherIn =
  6320. preFilter && (seed || !selector)
  6321. ? condense(elems, preMap, preFilter, context, xml)
  6322. : elems,
  6323. matcherOut = matcher
  6324. ? postFinder || (seed ? preFilter : preexisting || postFilter)
  6325. ? []
  6326. : results
  6327. : matcherIn
  6328. if (matcher) {
  6329. matcher(matcherIn, matcherOut, context, xml)
  6330. }
  6331. if (postFilter) {
  6332. temp = condense(matcherOut, postMap)
  6333. postFilter(temp, [], context, xml)
  6334. i = temp.length
  6335. while (i--) {
  6336. if ((elem = temp[i])) {
  6337. matcherOut[postMap[i]] = !(matcherIn[postMap[i]] = elem)
  6338. }
  6339. }
  6340. }
  6341. if (seed) {
  6342. if (postFinder || preFilter) {
  6343. if (postFinder) {
  6344. temp = []
  6345. i = matcherOut.length
  6346. while (i--) {
  6347. if ((elem = matcherOut[i])) {
  6348. temp.push((matcherIn[i] = elem))
  6349. }
  6350. }
  6351. postFinder(null, (matcherOut = []), temp, xml)
  6352. }
  6353. i = matcherOut.length
  6354. while (i--) {
  6355. if (
  6356. (elem = matcherOut[i]) &&
  6357. (temp = postFinder ? indexOf.call(seed, elem) : preMap[i]) > -1
  6358. ) {
  6359. seed[temp] = !(results[temp] = elem)
  6360. }
  6361. }
  6362. }
  6363. } else {
  6364. matcherOut = condense(
  6365. matcherOut === results
  6366. ? matcherOut.splice(preexisting, matcherOut.length)
  6367. : matcherOut
  6368. )
  6369. if (postFinder) {
  6370. postFinder(null, results, matcherOut, xml)
  6371. } else {
  6372. push$1.apply(results, matcherOut)
  6373. }
  6374. }
  6375. })
  6376. }
  6377. function matcherFromTokens(tokens) {
  6378. var checkContext,
  6379. matcher,
  6380. j,
  6381. len = tokens.length,
  6382. leadingRelative = Expr.relative[tokens[0].type],
  6383. implicitRelative = leadingRelative || Expr.relative[' '],
  6384. i = leadingRelative ? 1 : 0,
  6385. matchContext = addCombinator(
  6386. function (elem) {
  6387. return elem === checkContext
  6388. },
  6389. implicitRelative,
  6390. true
  6391. ),
  6392. matchAnyContext = addCombinator(
  6393. function (elem) {
  6394. return indexOf.call(checkContext, elem) > -1
  6395. },
  6396. implicitRelative,
  6397. true
  6398. ),
  6399. matchers = [
  6400. function (elem, context, xml) {
  6401. var ret =
  6402. (!leadingRelative && (xml || context !== outermostContext)) ||
  6403. ((checkContext = context).nodeType
  6404. ? matchContext(elem, context, xml)
  6405. : matchAnyContext(elem, context, xml))
  6406. checkContext = null
  6407. return ret
  6408. },
  6409. ]
  6410. for (; i < len; i++) {
  6411. if ((matcher = Expr.relative[tokens[i].type])) {
  6412. matchers = [addCombinator(elementMatcher(matchers), matcher)]
  6413. } else {
  6414. matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches)
  6415. if (matcher[expando]) {
  6416. j = ++i
  6417. for (; j < len; j++) {
  6418. if (Expr.relative[tokens[j].type]) {
  6419. break
  6420. }
  6421. }
  6422. return setMatcher(
  6423. i > 1 && elementMatcher(matchers),
  6424. i > 1 &&
  6425. toSelector(
  6426. tokens
  6427. .slice(0, i - 1)
  6428. .concat({ value: tokens[i - 2].type === ' ' ? '*' : '' })
  6429. ).replace(rtrim, '$1'),
  6430. matcher,
  6431. i < j && matcherFromTokens(tokens.slice(i, j)),
  6432. j < len && matcherFromTokens((tokens = tokens.slice(j))),
  6433. j < len && toSelector(tokens)
  6434. )
  6435. }
  6436. matchers.push(matcher)
  6437. }
  6438. }
  6439. return elementMatcher(matchers)
  6440. }
  6441. function matcherFromGroupMatchers(elementMatchers, setMatchers) {
  6442. var bySet = setMatchers.length > 0,
  6443. byElement = elementMatchers.length > 0,
  6444. superMatcher = function (seed, context, xml, results, outermost) {
  6445. var elem,
  6446. j,
  6447. matcher,
  6448. matchedCount = 0,
  6449. i = '0',
  6450. unmatched = seed && [],
  6451. setMatched = [],
  6452. contextBackup = outermostContext,
  6453. elems = seed || (byElement && Expr.find.TAG('*', outermost)),
  6454. dirrunsUnique = (dirruns +=
  6455. contextBackup == null ? 1 : Math.random() || 0.1),
  6456. len = elems.length
  6457. if (outermost) {
  6458. outermostContext = context !== document$1 && context
  6459. }
  6460. for (; i !== len && (elem = elems[i]) != null; i++) {
  6461. if (byElement && elem) {
  6462. j = 0
  6463. while ((matcher = elementMatchers[j++])) {
  6464. if (matcher(elem, context, xml)) {
  6465. results.push(elem)
  6466. break
  6467. }
  6468. }
  6469. if (outermost) {
  6470. dirruns = dirrunsUnique
  6471. }
  6472. }
  6473. if (bySet) {
  6474. if ((elem = !matcher && elem)) {
  6475. matchedCount--
  6476. }
  6477. if (seed) {
  6478. unmatched.push(elem)
  6479. }
  6480. }
  6481. }
  6482. matchedCount += i
  6483. if (bySet && i !== matchedCount) {
  6484. j = 0
  6485. while ((matcher = setMatchers[j++])) {
  6486. matcher(unmatched, setMatched, context, xml)
  6487. }
  6488. if (seed) {
  6489. if (matchedCount > 0) {
  6490. while (i--) {
  6491. if (!(unmatched[i] || setMatched[i])) {
  6492. setMatched[i] = pop.call(results)
  6493. }
  6494. }
  6495. }
  6496. setMatched = condense(setMatched)
  6497. }
  6498. push$1.apply(results, setMatched)
  6499. if (
  6500. outermost &&
  6501. !seed &&
  6502. setMatched.length > 0 &&
  6503. matchedCount + setMatchers.length > 1
  6504. ) {
  6505. Sizzle.uniqueSort(results)
  6506. }
  6507. }
  6508. if (outermost) {
  6509. dirruns = dirrunsUnique
  6510. outermostContext = contextBackup
  6511. }
  6512. return unmatched
  6513. }
  6514. return bySet ? markFunction(superMatcher) : superMatcher
  6515. }
  6516. compile = Sizzle.compile = function (selector, match) {
  6517. var i,
  6518. setMatchers = [],
  6519. elementMatchers = [],
  6520. cached = compilerCache[selector + ' ']
  6521. if (!cached) {
  6522. if (!match) {
  6523. match = tokenize(selector)
  6524. }
  6525. i = match.length
  6526. while (i--) {
  6527. cached = matcherFromTokens(match[i])
  6528. if (cached[expando]) {
  6529. setMatchers.push(cached)
  6530. } else {
  6531. elementMatchers.push(cached)
  6532. }
  6533. }
  6534. cached = compilerCache(
  6535. selector,
  6536. matcherFromGroupMatchers(elementMatchers, setMatchers)
  6537. )
  6538. cached.selector = selector
  6539. }
  6540. return cached
  6541. }
  6542. select$1 = Sizzle.select = function (selector, context, results, seed) {
  6543. var i,
  6544. tokens,
  6545. token,
  6546. type,
  6547. find,
  6548. compiled = typeof selector === 'function' && selector,
  6549. match = !seed && tokenize((selector = compiled.selector || selector))
  6550. results = results || []
  6551. if (match.length === 1) {
  6552. tokens = match[0] = match[0].slice(0)
  6553. if (
  6554. tokens.length > 2 &&
  6555. (token = tokens[0]).type === 'ID' &&
  6556. support.getById &&
  6557. context.nodeType === 9 &&
  6558. documentIsHTML &&
  6559. Expr.relative[tokens[1].type]
  6560. ) {
  6561. context = (Expr.find.ID(
  6562. token.matches[0].replace(runescape, funescape),
  6563. context
  6564. ) || [])[0]
  6565. if (!context) {
  6566. return results
  6567. } else if (compiled) {
  6568. context = context.parentNode
  6569. }
  6570. selector = selector.slice(tokens.shift().value.length)
  6571. }
  6572. i = matchExpr.needsContext.test(selector) ? 0 : tokens.length
  6573. while (i--) {
  6574. token = tokens[i]
  6575. if (Expr.relative[(type = token.type)]) {
  6576. break
  6577. }
  6578. if ((find = Expr.find[type])) {
  6579. if (
  6580. (seed = find(
  6581. token.matches[0].replace(runescape, funescape),
  6582. (rsibling.test(tokens[0].type) &&
  6583. testContext(context.parentNode)) ||
  6584. context
  6585. ))
  6586. ) {
  6587. tokens.splice(i, 1)
  6588. selector = seed.length && toSelector(tokens)
  6589. if (!selector) {
  6590. push$1.apply(results, seed)
  6591. return results
  6592. }
  6593. break
  6594. }
  6595. }
  6596. }
  6597. }
  6598. ;(compiled || compile(selector, match))(
  6599. seed,
  6600. context,
  6601. !documentIsHTML,
  6602. results,
  6603. (rsibling.test(selector) && testContext(context.parentNode)) || context
  6604. )
  6605. return results
  6606. }
  6607. support.sortStable = expando.split('').sort(sortOrder).join('') === expando
  6608. support.detectDuplicates = !!hasDuplicate
  6609. setDocument()
  6610. support.sortDetached = true
  6611. var doc = document
  6612. var push = Array.prototype.push
  6613. var slice = Array.prototype.slice
  6614. var rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/
  6615. var Event$1 = EventUtils.Event
  6616. var skipUniques = Tools.makeMap('children,contents,next,prev')
  6617. var isDefined = function (obj) {
  6618. return typeof obj !== 'undefined'
  6619. }
  6620. var isString = function (obj) {
  6621. return typeof obj === 'string'
  6622. }
  6623. var isWindow = function (obj) {
  6624. return obj && obj === obj.window
  6625. }
  6626. var createFragment$1 = function (html, fragDoc) {
  6627. fragDoc = fragDoc || doc
  6628. var container = fragDoc.createElement('div')
  6629. var frag = fragDoc.createDocumentFragment()
  6630. container.innerHTML = html
  6631. var node
  6632. while ((node = container.firstChild)) {
  6633. frag.appendChild(node)
  6634. }
  6635. return frag
  6636. }
  6637. var domManipulate = function (targetNodes, sourceItem, callback, reverse) {
  6638. var i
  6639. if (isString(sourceItem)) {
  6640. sourceItem = createFragment$1(
  6641. sourceItem,
  6642. getElementDocument(targetNodes[0])
  6643. )
  6644. } else if (sourceItem.length && !sourceItem.nodeType) {
  6645. sourceItem = DomQuery.makeArray(sourceItem)
  6646. if (reverse) {
  6647. for (i = sourceItem.length - 1; i >= 0; i--) {
  6648. domManipulate(targetNodes, sourceItem[i], callback, reverse)
  6649. }
  6650. } else {
  6651. for (i = 0; i < sourceItem.length; i++) {
  6652. domManipulate(targetNodes, sourceItem[i], callback, reverse)
  6653. }
  6654. }
  6655. return targetNodes
  6656. }
  6657. if (sourceItem.nodeType) {
  6658. i = targetNodes.length
  6659. while (i--) {
  6660. callback.call(targetNodes[i], sourceItem)
  6661. }
  6662. }
  6663. return targetNodes
  6664. }
  6665. var hasClass = function (node, className) {
  6666. return (
  6667. node &&
  6668. className &&
  6669. (' ' + node.className + ' ').indexOf(' ' + className + ' ') !== -1
  6670. )
  6671. }
  6672. var wrap$2 = function (elements, wrapper, all) {
  6673. var lastParent, newWrapper
  6674. wrapper = DomQuery(wrapper)[0]
  6675. elements.each(function () {
  6676. var self = this
  6677. if (!all || lastParent !== self.parentNode) {
  6678. lastParent = self.parentNode
  6679. newWrapper = wrapper.cloneNode(false)
  6680. self.parentNode.insertBefore(newWrapper, self)
  6681. newWrapper.appendChild(self)
  6682. } else {
  6683. newWrapper.appendChild(self)
  6684. }
  6685. })
  6686. return elements
  6687. }
  6688. var numericCssMap = Tools.makeMap(
  6689. 'fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom',
  6690. ' '
  6691. )
  6692. var booleanMap = Tools.makeMap(
  6693. 'checked compact declare defer disabled ismap multiple nohref noshade nowrap readonly selected',
  6694. ' '
  6695. )
  6696. var propFix = {
  6697. for: 'htmlFor',
  6698. class: 'className',
  6699. readonly: 'readOnly',
  6700. }
  6701. var cssFix = { float: 'cssFloat' }
  6702. var attrHooks = {},
  6703. cssHooks = {}
  6704. var DomQueryConstructor = function (selector, context) {
  6705. return new DomQuery.fn.init(selector, context)
  6706. }
  6707. var inArray$1 = function (item, array) {
  6708. var i
  6709. if (array.indexOf) {
  6710. return array.indexOf(item)
  6711. }
  6712. i = array.length
  6713. while (i--) {
  6714. if (array[i] === item) {
  6715. return i
  6716. }
  6717. }
  6718. return -1
  6719. }
  6720. var whiteSpaceRegExp = /^\s*|\s*$/g
  6721. var trim$1 = function (str) {
  6722. return str === null || str === undefined
  6723. ? ''
  6724. : ('' + str).replace(whiteSpaceRegExp, '')
  6725. }
  6726. var each$g = function (obj, callback) {
  6727. var length, key, i, value
  6728. if (obj) {
  6729. length = obj.length
  6730. if (length === undefined) {
  6731. for (key in obj) {
  6732. if (obj.hasOwnProperty(key)) {
  6733. value = obj[key]
  6734. if (callback.call(value, key, value) === false) {
  6735. break
  6736. }
  6737. }
  6738. }
  6739. } else {
  6740. for (i = 0; i < length; i++) {
  6741. value = obj[i]
  6742. if (callback.call(value, i, value) === false) {
  6743. break
  6744. }
  6745. }
  6746. }
  6747. }
  6748. return obj
  6749. }
  6750. var grep$2 = function (array, callback) {
  6751. var out = []
  6752. each$g(array, function (i, item) {
  6753. if (callback(item, i)) {
  6754. out.push(item)
  6755. }
  6756. })
  6757. return out
  6758. }
  6759. var getElementDocument = function (element) {
  6760. if (!element) {
  6761. return doc
  6762. }
  6763. if (element.nodeType === 9) {
  6764. return element
  6765. }
  6766. return element.ownerDocument
  6767. }
  6768. DomQueryConstructor.fn = DomQueryConstructor.prototype = {
  6769. constructor: DomQueryConstructor,
  6770. selector: '',
  6771. context: null,
  6772. length: 0,
  6773. init: function (selector, context) {
  6774. var self = this
  6775. var match, node
  6776. if (!selector) {
  6777. return self
  6778. }
  6779. if (selector.nodeType) {
  6780. self.context = self[0] = selector
  6781. self.length = 1
  6782. return self
  6783. }
  6784. if (context && context.nodeType) {
  6785. self.context = context
  6786. } else {
  6787. if (context) {
  6788. return DomQuery(selector).attr(context)
  6789. }
  6790. self.context = context = document
  6791. }
  6792. if (isString(selector)) {
  6793. self.selector = selector
  6794. if (
  6795. selector.charAt(0) === '<' &&
  6796. selector.charAt(selector.length - 1) === '>' &&
  6797. selector.length >= 3
  6798. ) {
  6799. match = [null, selector, null]
  6800. } else {
  6801. match = rquickExpr.exec(selector)
  6802. }
  6803. if (match) {
  6804. if (match[1]) {
  6805. node = createFragment$1(
  6806. selector,
  6807. getElementDocument(context)
  6808. ).firstChild
  6809. while (node) {
  6810. push.call(self, node)
  6811. node = node.nextSibling
  6812. }
  6813. } else {
  6814. node = getElementDocument(context).getElementById(match[2])
  6815. if (!node) {
  6816. return self
  6817. }
  6818. if (node.id !== match[2]) {
  6819. return self.find(selector)
  6820. }
  6821. self.length = 1
  6822. self[0] = node
  6823. }
  6824. } else {
  6825. return DomQuery(context).find(selector)
  6826. }
  6827. } else {
  6828. this.add(selector, false)
  6829. }
  6830. return self
  6831. },
  6832. toArray: function () {
  6833. return Tools.toArray(this)
  6834. },
  6835. add: function (items, sort) {
  6836. var self = this
  6837. var nodes, i
  6838. if (isString(items)) {
  6839. return self.add(DomQuery(items))
  6840. }
  6841. if (sort !== false) {
  6842. nodes = DomQuery.unique(
  6843. self.toArray().concat(DomQuery.makeArray(items))
  6844. )
  6845. self.length = nodes.length
  6846. for (i = 0; i < nodes.length; i++) {
  6847. self[i] = nodes[i]
  6848. }
  6849. } else {
  6850. push.apply(self, DomQuery.makeArray(items))
  6851. }
  6852. return self
  6853. },
  6854. attr: function (name, value) {
  6855. var self = this
  6856. var hook
  6857. if (typeof name === 'object') {
  6858. each$g(name, function (name, value) {
  6859. self.attr(name, value)
  6860. })
  6861. } else if (isDefined(value)) {
  6862. this.each(function () {
  6863. var hook
  6864. if (this.nodeType === 1) {
  6865. hook = attrHooks[name]
  6866. if (hook && hook.set) {
  6867. hook.set(this, value)
  6868. return
  6869. }
  6870. if (value === null) {
  6871. this.removeAttribute(name, 2)
  6872. } else {
  6873. this.setAttribute(name, value, 2)
  6874. }
  6875. }
  6876. })
  6877. } else {
  6878. if (self[0] && self[0].nodeType === 1) {
  6879. hook = attrHooks[name]
  6880. if (hook && hook.get) {
  6881. return hook.get(self[0], name)
  6882. }
  6883. if (booleanMap[name]) {
  6884. return self.prop(name) ? name : undefined
  6885. }
  6886. value = self[0].getAttribute(name, 2)
  6887. if (value === null) {
  6888. value = undefined
  6889. }
  6890. }
  6891. return value
  6892. }
  6893. return self
  6894. },
  6895. removeAttr: function (name) {
  6896. return this.attr(name, null)
  6897. },
  6898. prop: function (name, value) {
  6899. var self = this
  6900. name = propFix[name] || name
  6901. if (typeof name === 'object') {
  6902. each$g(name, function (name, value) {
  6903. self.prop(name, value)
  6904. })
  6905. } else if (isDefined(value)) {
  6906. this.each(function () {
  6907. if (this.nodeType === 1) {
  6908. this[name] = value
  6909. }
  6910. })
  6911. } else {
  6912. if (self[0] && self[0].nodeType && name in self[0]) {
  6913. return self[0][name]
  6914. }
  6915. return value
  6916. }
  6917. return self
  6918. },
  6919. css: function (name, value) {
  6920. var self = this
  6921. var elm, hook
  6922. var camel = function (name) {
  6923. return name.replace(/-(\D)/g, function (a, b) {
  6924. return b.toUpperCase()
  6925. })
  6926. }
  6927. var dashed = function (name) {
  6928. return name.replace(/[A-Z]/g, function (a) {
  6929. return '-' + a
  6930. })
  6931. }
  6932. if (typeof name === 'object') {
  6933. each$g(name, function (name, value) {
  6934. self.css(name, value)
  6935. })
  6936. } else {
  6937. if (isDefined(value)) {
  6938. name = camel(name)
  6939. if (typeof value === 'number' && !numericCssMap[name]) {
  6940. value = value.toString() + 'px'
  6941. }
  6942. self.each(function () {
  6943. var style = this.style
  6944. hook = cssHooks[name]
  6945. if (hook && hook.set) {
  6946. hook.set(this, value)
  6947. return
  6948. }
  6949. try {
  6950. this.style[cssFix[name] || name] = value
  6951. } catch (ex) {}
  6952. if (value === null || value === '') {
  6953. if (style.removeProperty) {
  6954. style.removeProperty(dashed(name))
  6955. } else {
  6956. style.removeAttribute(name)
  6957. }
  6958. }
  6959. })
  6960. } else {
  6961. elm = self[0]
  6962. hook = cssHooks[name]
  6963. if (hook && hook.get) {
  6964. return hook.get(elm)
  6965. }
  6966. if (elm.ownerDocument.defaultView) {
  6967. try {
  6968. return elm.ownerDocument.defaultView
  6969. .getComputedStyle(elm, null)
  6970. .getPropertyValue(dashed(name))
  6971. } catch (ex) {
  6972. return undefined
  6973. }
  6974. } else if (elm.currentStyle) {
  6975. return elm.currentStyle[camel(name)]
  6976. } else {
  6977. return ''
  6978. }
  6979. }
  6980. }
  6981. return self
  6982. },
  6983. remove: function () {
  6984. var self = this
  6985. var node,
  6986. i = this.length
  6987. while (i--) {
  6988. node = self[i]
  6989. Event$1.clean(node)
  6990. if (node.parentNode) {
  6991. node.parentNode.removeChild(node)
  6992. }
  6993. }
  6994. return this
  6995. },
  6996. empty: function () {
  6997. var self = this
  6998. var node,
  6999. i = this.length
  7000. while (i--) {
  7001. node = self[i]
  7002. while (node.firstChild) {
  7003. node.removeChild(node.firstChild)
  7004. }
  7005. }
  7006. return this
  7007. },
  7008. html: function (value) {
  7009. var self = this
  7010. var i
  7011. if (isDefined(value)) {
  7012. i = self.length
  7013. try {
  7014. while (i--) {
  7015. self[i].innerHTML = value
  7016. }
  7017. } catch (ex) {
  7018. DomQuery(self[i]).empty().append(value)
  7019. }
  7020. return self
  7021. }
  7022. return self[0] ? self[0].innerHTML : ''
  7023. },
  7024. text: function (value) {
  7025. var self = this
  7026. var i
  7027. if (isDefined(value)) {
  7028. i = self.length
  7029. while (i--) {
  7030. if ('innerText' in self[i]) {
  7031. self[i].innerText = value
  7032. } else {
  7033. self[0].textContent = value
  7034. }
  7035. }
  7036. return self
  7037. }
  7038. return self[0] ? self[0].innerText || self[0].textContent : ''
  7039. },
  7040. append: function () {
  7041. return domManipulate(this, arguments, function (node) {
  7042. if (this.nodeType === 1 || (this.host && this.host.nodeType === 1)) {
  7043. this.appendChild(node)
  7044. }
  7045. })
  7046. },
  7047. prepend: function () {
  7048. return domManipulate(
  7049. this,
  7050. arguments,
  7051. function (node) {
  7052. if (this.nodeType === 1 || (this.host && this.host.nodeType === 1)) {
  7053. this.insertBefore(node, this.firstChild)
  7054. }
  7055. },
  7056. true
  7057. )
  7058. },
  7059. before: function () {
  7060. var self = this
  7061. if (self[0] && self[0].parentNode) {
  7062. return domManipulate(self, arguments, function (node) {
  7063. this.parentNode.insertBefore(node, this)
  7064. })
  7065. }
  7066. return self
  7067. },
  7068. after: function () {
  7069. var self = this
  7070. if (self[0] && self[0].parentNode) {
  7071. return domManipulate(
  7072. self,
  7073. arguments,
  7074. function (node) {
  7075. this.parentNode.insertBefore(node, this.nextSibling)
  7076. },
  7077. true
  7078. )
  7079. }
  7080. return self
  7081. },
  7082. appendTo: function (val) {
  7083. DomQuery(val).append(this)
  7084. return this
  7085. },
  7086. prependTo: function (val) {
  7087. DomQuery(val).prepend(this)
  7088. return this
  7089. },
  7090. replaceWith: function (content) {
  7091. return this.before(content).remove()
  7092. },
  7093. wrap: function (content) {
  7094. return wrap$2(this, content)
  7095. },
  7096. wrapAll: function (content) {
  7097. return wrap$2(this, content, true)
  7098. },
  7099. wrapInner: function (content) {
  7100. this.each(function () {
  7101. DomQuery(this).contents().wrapAll(content)
  7102. })
  7103. return this
  7104. },
  7105. unwrap: function () {
  7106. return this.parent().each(function () {
  7107. DomQuery(this).replaceWith(this.childNodes)
  7108. })
  7109. },
  7110. clone: function () {
  7111. var result = []
  7112. this.each(function () {
  7113. result.push(this.cloneNode(true))
  7114. })
  7115. return DomQuery(result)
  7116. },
  7117. addClass: function (className) {
  7118. return this.toggleClass(className, true)
  7119. },
  7120. removeClass: function (className) {
  7121. return this.toggleClass(className, false)
  7122. },
  7123. toggleClass: function (className, state) {
  7124. var self = this
  7125. if (typeof className !== 'string') {
  7126. return self
  7127. }
  7128. if (className.indexOf(' ') !== -1) {
  7129. each$g(className.split(' '), function () {
  7130. self.toggleClass(this, state)
  7131. })
  7132. } else {
  7133. self.each(function (index, node) {
  7134. var classState = hasClass(node, className)
  7135. if (classState !== state) {
  7136. var existingClassName = node.className
  7137. if (classState) {
  7138. node.className = trim$1(
  7139. (' ' + existingClassName + ' ').replace(
  7140. ' ' + className + ' ',
  7141. ' '
  7142. )
  7143. )
  7144. } else {
  7145. node.className += existingClassName ? ' ' + className : className
  7146. }
  7147. }
  7148. })
  7149. }
  7150. return self
  7151. },
  7152. hasClass: function (className) {
  7153. return hasClass(this[0], className)
  7154. },
  7155. each: function (callback) {
  7156. return each$g(this, callback)
  7157. },
  7158. on: function (name, callback) {
  7159. return this.each(function () {
  7160. Event$1.bind(this, name, callback)
  7161. })
  7162. },
  7163. off: function (name, callback) {
  7164. return this.each(function () {
  7165. Event$1.unbind(this, name, callback)
  7166. })
  7167. },
  7168. trigger: function (name) {
  7169. return this.each(function () {
  7170. if (typeof name === 'object') {
  7171. Event$1.fire(this, name.type, name)
  7172. } else {
  7173. Event$1.fire(this, name)
  7174. }
  7175. })
  7176. },
  7177. show: function () {
  7178. return this.css('display', '')
  7179. },
  7180. hide: function () {
  7181. return this.css('display', 'none')
  7182. },
  7183. slice: function () {
  7184. return DomQuery(slice.apply(this, arguments))
  7185. },
  7186. eq: function (index) {
  7187. return index === -1 ? this.slice(index) : this.slice(index, +index + 1)
  7188. },
  7189. first: function () {
  7190. return this.eq(0)
  7191. },
  7192. last: function () {
  7193. return this.eq(-1)
  7194. },
  7195. find: function (selector) {
  7196. var i, l
  7197. var ret = []
  7198. for (i = 0, l = this.length; i < l; i++) {
  7199. DomQuery.find(selector, this[i], ret)
  7200. }
  7201. return DomQuery(ret)
  7202. },
  7203. filter: function (selector) {
  7204. if (typeof selector === 'function') {
  7205. return DomQuery(
  7206. grep$2(this.toArray(), function (item, i) {
  7207. return selector(i, item)
  7208. })
  7209. )
  7210. }
  7211. return DomQuery(DomQuery.filter(selector, this.toArray()))
  7212. },
  7213. closest: function (selector) {
  7214. var result = []
  7215. if (selector instanceof DomQuery) {
  7216. selector = selector[0]
  7217. }
  7218. this.each(function (i, node) {
  7219. while (node) {
  7220. if (typeof selector === 'string' && DomQuery(node).is(selector)) {
  7221. result.push(node)
  7222. break
  7223. } else if (node === selector) {
  7224. result.push(node)
  7225. break
  7226. }
  7227. node = node.parentNode
  7228. }
  7229. })
  7230. return DomQuery(result)
  7231. },
  7232. offset: function (offset) {
  7233. var elm, doc, docElm
  7234. var x = 0,
  7235. y = 0,
  7236. pos
  7237. if (!offset) {
  7238. elm = this[0]
  7239. if (elm) {
  7240. doc = elm.ownerDocument
  7241. docElm = doc.documentElement
  7242. if (elm.getBoundingClientRect) {
  7243. pos = elm.getBoundingClientRect()
  7244. x =
  7245. pos.left +
  7246. (docElm.scrollLeft || doc.body.scrollLeft) -
  7247. docElm.clientLeft
  7248. y =
  7249. pos.top +
  7250. (docElm.scrollTop || doc.body.scrollTop) -
  7251. docElm.clientTop
  7252. }
  7253. }
  7254. return {
  7255. left: x,
  7256. top: y,
  7257. }
  7258. }
  7259. return this.css(offset)
  7260. },
  7261. push: push,
  7262. sort: Array.prototype.sort,
  7263. splice: Array.prototype.splice,
  7264. }
  7265. Tools.extend(DomQueryConstructor, {
  7266. extend: Tools.extend,
  7267. makeArray: function (object) {
  7268. if (isWindow(object) || object.nodeType) {
  7269. return [object]
  7270. }
  7271. return Tools.toArray(object)
  7272. },
  7273. inArray: inArray$1,
  7274. isArray: Tools.isArray,
  7275. each: each$g,
  7276. trim: trim$1,
  7277. grep: grep$2,
  7278. find: Sizzle,
  7279. expr: Sizzle.selectors,
  7280. unique: Sizzle.uniqueSort,
  7281. text: Sizzle.getText,
  7282. contains: Sizzle.contains,
  7283. filter: function (expr, elems, not) {
  7284. var i = elems.length
  7285. if (not) {
  7286. expr = ':not(' + expr + ')'
  7287. }
  7288. while (i--) {
  7289. if (elems[i].nodeType !== 1) {
  7290. elems.splice(i, 1)
  7291. }
  7292. }
  7293. if (elems.length === 1) {
  7294. elems = DomQuery.find.matchesSelector(elems[0], expr) ? [elems[0]] : []
  7295. } else {
  7296. elems = DomQuery.find.matches(expr, elems)
  7297. }
  7298. return elems
  7299. },
  7300. })
  7301. var dir = function (el, prop, until) {
  7302. var matched = []
  7303. var cur = el[prop]
  7304. if (typeof until !== 'string' && until instanceof DomQuery) {
  7305. until = until[0]
  7306. }
  7307. while (cur && cur.nodeType !== 9) {
  7308. if (until !== undefined) {
  7309. if (cur === until) {
  7310. break
  7311. }
  7312. if (typeof until === 'string' && DomQuery(cur).is(until)) {
  7313. break
  7314. }
  7315. }
  7316. if (cur.nodeType === 1) {
  7317. matched.push(cur)
  7318. }
  7319. cur = cur[prop]
  7320. }
  7321. return matched
  7322. }
  7323. var sibling$1 = function (node, siblingName, nodeType, until) {
  7324. var result = []
  7325. if (until instanceof DomQuery) {
  7326. until = until[0]
  7327. }
  7328. for (; node; node = node[siblingName]) {
  7329. if (nodeType && node.nodeType !== nodeType) {
  7330. continue
  7331. }
  7332. if (until !== undefined) {
  7333. if (node === until) {
  7334. break
  7335. }
  7336. if (typeof until === 'string' && DomQuery(node).is(until)) {
  7337. break
  7338. }
  7339. }
  7340. result.push(node)
  7341. }
  7342. return result
  7343. }
  7344. var firstSibling = function (node, siblingName, nodeType) {
  7345. for (node = node[siblingName]; node; node = node[siblingName]) {
  7346. if (node.nodeType === nodeType) {
  7347. return node
  7348. }
  7349. }
  7350. return null
  7351. }
  7352. each$g(
  7353. {
  7354. parent: function (node) {
  7355. var parent = node.parentNode
  7356. return parent && parent.nodeType !== 11 ? parent : null
  7357. },
  7358. parents: function (node) {
  7359. return dir(node, 'parentNode')
  7360. },
  7361. next: function (node) {
  7362. return firstSibling(node, 'nextSibling', 1)
  7363. },
  7364. prev: function (node) {
  7365. return firstSibling(node, 'previousSibling', 1)
  7366. },
  7367. children: function (node) {
  7368. return sibling$1(node.firstChild, 'nextSibling', 1)
  7369. },
  7370. contents: function (node) {
  7371. return Tools.toArray(
  7372. (node.nodeName === 'iframe'
  7373. ? node.contentDocument || node.contentWindow.document
  7374. : node
  7375. ).childNodes
  7376. )
  7377. },
  7378. },
  7379. function (name, fn) {
  7380. DomQueryConstructor.fn[name] = function (selector) {
  7381. var self = this
  7382. var result = []
  7383. self.each(function () {
  7384. var nodes = fn.call(result, this, selector, result)
  7385. if (nodes) {
  7386. if (DomQuery.isArray(nodes)) {
  7387. result.push.apply(result, nodes)
  7388. } else {
  7389. result.push(nodes)
  7390. }
  7391. }
  7392. })
  7393. if (this.length > 1) {
  7394. if (!skipUniques[name]) {
  7395. result = DomQuery.unique(result)
  7396. }
  7397. if (name.indexOf('parents') === 0) {
  7398. result = result.reverse()
  7399. }
  7400. }
  7401. var wrappedResult = DomQuery(result)
  7402. if (selector) {
  7403. return wrappedResult.filter(selector)
  7404. }
  7405. return wrappedResult
  7406. }
  7407. }
  7408. )
  7409. each$g(
  7410. {
  7411. parentsUntil: function (node, until) {
  7412. return dir(node, 'parentNode', until)
  7413. },
  7414. nextUntil: function (node, until) {
  7415. return sibling$1(node, 'nextSibling', 1, until).slice(1)
  7416. },
  7417. prevUntil: function (node, until) {
  7418. return sibling$1(node, 'previousSibling', 1, until).slice(1)
  7419. },
  7420. },
  7421. function (name, fn) {
  7422. DomQueryConstructor.fn[name] = function (selector, filter) {
  7423. var self = this
  7424. var result = []
  7425. self.each(function () {
  7426. var nodes = fn.call(result, this, selector, result)
  7427. if (nodes) {
  7428. if (DomQuery.isArray(nodes)) {
  7429. result.push.apply(result, nodes)
  7430. } else {
  7431. result.push(nodes)
  7432. }
  7433. }
  7434. })
  7435. if (this.length > 1) {
  7436. result = DomQuery.unique(result)
  7437. if (name.indexOf('parents') === 0 || name === 'prevUntil') {
  7438. result = result.reverse()
  7439. }
  7440. }
  7441. var wrappedResult = DomQuery(result)
  7442. if (filter) {
  7443. return wrappedResult.filter(filter)
  7444. }
  7445. return wrappedResult
  7446. }
  7447. }
  7448. )
  7449. DomQueryConstructor.fn.is = function (selector) {
  7450. return !!selector && this.filter(selector).length > 0
  7451. }
  7452. DomQueryConstructor.fn.init.prototype = DomQueryConstructor.fn
  7453. DomQueryConstructor.overrideDefaults = function (callback) {
  7454. var defaults
  7455. var sub = function (selector, context) {
  7456. defaults = defaults || callback()
  7457. if (arguments.length === 0) {
  7458. selector = defaults.element
  7459. }
  7460. if (!context) {
  7461. context = defaults.context
  7462. }
  7463. return new sub.fn.init(selector, context)
  7464. }
  7465. DomQuery.extend(sub, this)
  7466. return sub
  7467. }
  7468. DomQueryConstructor.attrHooks = attrHooks
  7469. DomQueryConstructor.cssHooks = cssHooks
  7470. var DomQuery = DomQueryConstructor
  7471. var each$f = Tools.each
  7472. var grep$1 = Tools.grep
  7473. var isIE = Env.ie
  7474. var simpleSelectorRe = /^([a-z0-9],?)+$/i
  7475. var setupAttrHooks = function (styles, settings, getContext) {
  7476. var keepValues = settings.keep_values
  7477. var keepUrlHook = {
  7478. set: function ($elm, value, name) {
  7479. if (settings.url_converter && value !== null) {
  7480. value = settings.url_converter.call(
  7481. settings.url_converter_scope || getContext(),
  7482. value,
  7483. name,
  7484. $elm[0]
  7485. )
  7486. }
  7487. $elm.attr('data-mce-' + name, value).attr(name, value)
  7488. },
  7489. get: function ($elm, name) {
  7490. return $elm.attr('data-mce-' + name) || $elm.attr(name)
  7491. },
  7492. }
  7493. var attrHooks = {
  7494. style: {
  7495. set: function ($elm, value) {
  7496. if (value !== null && typeof value === 'object') {
  7497. $elm.css(value)
  7498. return
  7499. }
  7500. if (keepValues) {
  7501. $elm.attr('data-mce-style', value)
  7502. }
  7503. if (value !== null && typeof value === 'string') {
  7504. $elm.removeAttr('style')
  7505. $elm.css(styles.parse(value))
  7506. } else {
  7507. $elm.attr('style', value)
  7508. }
  7509. },
  7510. get: function ($elm) {
  7511. var value = $elm.attr('data-mce-style') || $elm.attr('style')
  7512. value = styles.serialize(styles.parse(value), $elm[0].nodeName)
  7513. return value
  7514. },
  7515. },
  7516. }
  7517. if (keepValues) {
  7518. attrHooks.href = attrHooks.src = keepUrlHook
  7519. }
  7520. return attrHooks
  7521. }
  7522. var updateInternalStyleAttr = function (styles, $elm) {
  7523. var rawValue = $elm.attr('style')
  7524. var value = styles.serialize(styles.parse(rawValue), $elm[0].nodeName)
  7525. if (!value) {
  7526. value = null
  7527. }
  7528. $elm.attr('data-mce-style', value)
  7529. }
  7530. var findNodeIndex = function (node, normalized) {
  7531. var idx = 0,
  7532. lastNodeType,
  7533. nodeType
  7534. if (node) {
  7535. for (
  7536. lastNodeType = node.nodeType, node = node.previousSibling;
  7537. node;
  7538. node = node.previousSibling
  7539. ) {
  7540. nodeType = node.nodeType
  7541. if (normalized && nodeType === 3) {
  7542. if (nodeType === lastNodeType || !node.nodeValue.length) {
  7543. continue
  7544. }
  7545. }
  7546. idx++
  7547. lastNodeType = nodeType
  7548. }
  7549. }
  7550. return idx
  7551. }
  7552. var DOMUtils = function (doc, settings) {
  7553. if (settings === void 0) {
  7554. settings = {}
  7555. }
  7556. var addedStyles = {}
  7557. var win = window
  7558. var files = {}
  7559. var counter = 0
  7560. var stdMode = true
  7561. var boxModel = true
  7562. var styleSheetLoader = instance.forElement(SugarElement.fromDom(doc), {
  7563. contentCssCors: settings.contentCssCors,
  7564. referrerPolicy: settings.referrerPolicy,
  7565. })
  7566. var boundEvents = []
  7567. var schema = settings.schema ? settings.schema : Schema({})
  7568. var styles = Styles(
  7569. {
  7570. url_converter: settings.url_converter,
  7571. url_converter_scope: settings.url_converter_scope,
  7572. },
  7573. settings.schema
  7574. )
  7575. var events = settings.ownEvents ? new EventUtils() : EventUtils.Event
  7576. var blockElementsMap = schema.getBlockElements()
  7577. var $ = DomQuery.overrideDefaults(function () {
  7578. return {
  7579. context: doc,
  7580. element: self.getRoot(),
  7581. }
  7582. })
  7583. var isBlock = function (node) {
  7584. if (typeof node === 'string') {
  7585. return !!blockElementsMap[node]
  7586. } else if (node) {
  7587. var type = node.nodeType
  7588. if (type) {
  7589. return !!(type === 1 && blockElementsMap[node.nodeName])
  7590. }
  7591. }
  7592. return false
  7593. }
  7594. var get = function (elm) {
  7595. return elm && doc && isString$1(elm) ? doc.getElementById(elm) : elm
  7596. }
  7597. var $$ = function (elm) {
  7598. return $(typeof elm === 'string' ? get(elm) : elm)
  7599. }
  7600. var getAttrib = function (elm, name, defaultVal) {
  7601. var hook, value
  7602. var $elm = $$(elm)
  7603. if ($elm.length) {
  7604. hook = attrHooks[name]
  7605. if (hook && hook.get) {
  7606. value = hook.get($elm, name)
  7607. } else {
  7608. value = $elm.attr(name)
  7609. }
  7610. }
  7611. if (typeof value === 'undefined') {
  7612. value = defaultVal || ''
  7613. }
  7614. return value
  7615. }
  7616. var getAttribs = function (elm) {
  7617. var node = get(elm)
  7618. if (!node) {
  7619. return []
  7620. }
  7621. return node.attributes
  7622. }
  7623. var setAttrib = function (elm, name, value) {
  7624. if (value === '') {
  7625. value = null
  7626. }
  7627. var $elm = $$(elm)
  7628. var originalValue = $elm.attr(name)
  7629. if (!$elm.length) {
  7630. return
  7631. }
  7632. var hook = attrHooks[name]
  7633. if (hook && hook.set) {
  7634. hook.set($elm, value, name)
  7635. } else {
  7636. $elm.attr(name, value)
  7637. }
  7638. if (originalValue !== value && settings.onSetAttrib) {
  7639. settings.onSetAttrib({
  7640. attrElm: $elm,
  7641. attrName: name,
  7642. attrValue: value,
  7643. })
  7644. }
  7645. }
  7646. var clone = function (node, deep) {
  7647. if (!isIE || node.nodeType !== 1 || deep) {
  7648. return node.cloneNode(deep)
  7649. } else {
  7650. var clone_1 = doc.createElement(node.nodeName)
  7651. each$f(getAttribs(node), function (attr) {
  7652. setAttrib(clone_1, attr.nodeName, getAttrib(node, attr.nodeName))
  7653. })
  7654. return clone_1
  7655. }
  7656. }
  7657. var getRoot = function () {
  7658. return settings.root_element || doc.body
  7659. }
  7660. var getViewPort = function (argWin) {
  7661. var vp = getBounds(argWin)
  7662. return {
  7663. x: vp.x,
  7664. y: vp.y,
  7665. w: vp.width,
  7666. h: vp.height,
  7667. }
  7668. }
  7669. var getPos$1 = function (elm, rootElm) {
  7670. return getPos(doc.body, get(elm), rootElm)
  7671. }
  7672. var setStyle = function (elm, name, value) {
  7673. var $elm = isString$1(name) ? $$(elm).css(name, value) : $$(elm).css(name)
  7674. if (settings.update_styles) {
  7675. updateInternalStyleAttr(styles, $elm)
  7676. }
  7677. }
  7678. var setStyles = function (elm, stylesArg) {
  7679. var $elm = $$(elm).css(stylesArg)
  7680. if (settings.update_styles) {
  7681. updateInternalStyleAttr(styles, $elm)
  7682. }
  7683. }
  7684. var getStyle = function (elm, name, computed) {
  7685. var $elm = $$(elm)
  7686. if (computed) {
  7687. return $elm.css(name)
  7688. }
  7689. name = name.replace(/-(\D)/g, function (a, b) {
  7690. return b.toUpperCase()
  7691. })
  7692. if (name === 'float') {
  7693. name = Env.browser.isIE() ? 'styleFloat' : 'cssFloat'
  7694. }
  7695. return $elm[0] && $elm[0].style ? $elm[0].style[name] : undefined
  7696. }
  7697. var getSize = function (elm) {
  7698. var w, h
  7699. elm = get(elm)
  7700. w = getStyle(elm, 'width')
  7701. h = getStyle(elm, 'height')
  7702. if (w.indexOf('px') === -1) {
  7703. w = 0
  7704. }
  7705. if (h.indexOf('px') === -1) {
  7706. h = 0
  7707. }
  7708. return {
  7709. w: parseInt(w, 10) || elm.offsetWidth || elm.clientWidth,
  7710. h: parseInt(h, 10) || elm.offsetHeight || elm.clientHeight,
  7711. }
  7712. }
  7713. var getRect = function (elm) {
  7714. elm = get(elm)
  7715. var pos = getPos$1(elm)
  7716. var size = getSize(elm)
  7717. return {
  7718. x: pos.x,
  7719. y: pos.y,
  7720. w: size.w,
  7721. h: size.h,
  7722. }
  7723. }
  7724. var is = function (elm, selector) {
  7725. var i
  7726. if (!elm) {
  7727. return false
  7728. }
  7729. if (!Array.isArray(elm)) {
  7730. if (selector === '*') {
  7731. return elm.nodeType === 1
  7732. }
  7733. if (simpleSelectorRe.test(selector)) {
  7734. var selectors = selector.toLowerCase().split(/,/)
  7735. var elmName = elm.nodeName.toLowerCase()
  7736. for (i = selectors.length - 1; i >= 0; i--) {
  7737. if (selectors[i] === elmName) {
  7738. return true
  7739. }
  7740. }
  7741. return false
  7742. }
  7743. if (elm.nodeType && elm.nodeType !== 1) {
  7744. return false
  7745. }
  7746. }
  7747. var elms = !Array.isArray(elm) ? [elm] : elm
  7748. return (
  7749. Sizzle(selector, elms[0].ownerDocument || elms[0], null, elms).length >
  7750. 0
  7751. )
  7752. }
  7753. var getParents = function (elm, selector, root, collect) {
  7754. var result = []
  7755. var selectorVal
  7756. var node = get(elm)
  7757. collect = collect === undefined
  7758. root =
  7759. root || (getRoot().nodeName !== 'BODY' ? getRoot().parentNode : null)
  7760. if (Tools.is(selector, 'string')) {
  7761. selectorVal = selector
  7762. if (selector === '*') {
  7763. selector = function (node) {
  7764. return node.nodeType === 1
  7765. }
  7766. } else {
  7767. selector = function (node) {
  7768. return is(node, selectorVal)
  7769. }
  7770. }
  7771. }
  7772. while (node) {
  7773. if (
  7774. node === root ||
  7775. isNullable(node.nodeType) ||
  7776. isDocument$1(node) ||
  7777. isDocumentFragment(node)
  7778. ) {
  7779. break
  7780. }
  7781. if (!selector || (typeof selector === 'function' && selector(node))) {
  7782. if (collect) {
  7783. result.push(node)
  7784. } else {
  7785. return [node]
  7786. }
  7787. }
  7788. node = node.parentNode
  7789. }
  7790. return collect ? result : null
  7791. }
  7792. var getParent = function (node, selector, root) {
  7793. var parents = getParents(node, selector, root, false)
  7794. return parents && parents.length > 0 ? parents[0] : null
  7795. }
  7796. var _findSib = function (node, selector, name) {
  7797. var func = selector
  7798. if (node) {
  7799. if (typeof selector === 'string') {
  7800. func = function (node) {
  7801. return is(node, selector)
  7802. }
  7803. }
  7804. for (node = node[name]; node; node = node[name]) {
  7805. if (typeof func === 'function' && func(node)) {
  7806. return node
  7807. }
  7808. }
  7809. }
  7810. return null
  7811. }
  7812. var getNext = function (node, selector) {
  7813. return _findSib(node, selector, 'nextSibling')
  7814. }
  7815. var getPrev = function (node, selector) {
  7816. return _findSib(node, selector, 'previousSibling')
  7817. }
  7818. var select = function (selector, scope) {
  7819. return Sizzle(selector, get(scope) || settings.root_element || doc, [])
  7820. }
  7821. var run = function (elm, func, scope) {
  7822. var result
  7823. var node = typeof elm === 'string' ? get(elm) : elm
  7824. if (!node) {
  7825. return false
  7826. }
  7827. if (Tools.isArray(node) && (node.length || node.length === 0)) {
  7828. result = []
  7829. each$f(node, function (elm, i) {
  7830. if (elm) {
  7831. result.push(
  7832. func.call(scope, typeof elm === 'string' ? get(elm) : elm, i)
  7833. )
  7834. }
  7835. })
  7836. return result
  7837. }
  7838. var context = scope ? scope : this
  7839. return func.call(context, node)
  7840. }
  7841. var setAttribs = function (elm, attrs) {
  7842. $$(elm).each(function (i, node) {
  7843. each$f(attrs, function (value, name) {
  7844. setAttrib(node, name, value)
  7845. })
  7846. })
  7847. }
  7848. var setHTML = function (elm, html) {
  7849. var $elm = $$(elm)
  7850. if (isIE) {
  7851. $elm.each(function (i, target) {
  7852. if (target.canHaveHTML === false) {
  7853. return
  7854. }
  7855. while (target.firstChild) {
  7856. target.removeChild(target.firstChild)
  7857. }
  7858. try {
  7859. target.innerHTML = '<br>' + html
  7860. target.removeChild(target.firstChild)
  7861. } catch (ex) {
  7862. DomQuery('<div></div>')
  7863. .html('<br>' + html)
  7864. .contents()
  7865. .slice(1)
  7866. .appendTo(target)
  7867. }
  7868. return html
  7869. })
  7870. } else {
  7871. $elm.html(html)
  7872. }
  7873. }
  7874. var add = function (parentElm, name, attrs, html, create) {
  7875. return run(parentElm, function (parentElm) {
  7876. var newElm = typeof name === 'string' ? doc.createElement(name) : name
  7877. setAttribs(newElm, attrs)
  7878. if (html) {
  7879. if (typeof html !== 'string' && html.nodeType) {
  7880. newElm.appendChild(html)
  7881. } else if (typeof html === 'string') {
  7882. setHTML(newElm, html)
  7883. }
  7884. }
  7885. return !create ? parentElm.appendChild(newElm) : newElm
  7886. })
  7887. }
  7888. var create = function (name, attrs, html) {
  7889. return add(doc.createElement(name), name, attrs, html, true)
  7890. }
  7891. var decode = Entities.decode
  7892. var encode = Entities.encodeAllRaw
  7893. var createHTML = function (name, attrs, html) {
  7894. var outHtml = '',
  7895. key
  7896. outHtml += '<' + name
  7897. for (key in attrs) {
  7898. if (hasNonNullableKey(attrs, key)) {
  7899. outHtml += ' ' + key + '="' + encode(attrs[key]) + '"'
  7900. }
  7901. }
  7902. if (typeof html !== 'undefined') {
  7903. return outHtml + '>' + html + '</' + name + '>'
  7904. }
  7905. return outHtml + ' />'
  7906. }
  7907. var createFragment = function (html) {
  7908. var node
  7909. var container = doc.createElement('div')
  7910. var frag = doc.createDocumentFragment()
  7911. frag.appendChild(container)
  7912. if (html) {
  7913. container.innerHTML = html
  7914. }
  7915. while ((node = container.firstChild)) {
  7916. frag.appendChild(node)
  7917. }
  7918. frag.removeChild(container)
  7919. return frag
  7920. }
  7921. var remove = function (node, keepChildren) {
  7922. var $node = $$(node)
  7923. if (keepChildren) {
  7924. $node
  7925. .each(function () {
  7926. var child
  7927. while ((child = this.firstChild)) {
  7928. if (child.nodeType === 3 && child.data.length === 0) {
  7929. this.removeChild(child)
  7930. } else {
  7931. this.parentNode.insertBefore(child, this)
  7932. }
  7933. }
  7934. })
  7935. .remove()
  7936. } else {
  7937. $node.remove()
  7938. }
  7939. return $node.length > 1 ? $node.toArray() : $node[0]
  7940. }
  7941. var removeAllAttribs = function (e) {
  7942. return run(e, function (e) {
  7943. var i
  7944. var attrs = e.attributes
  7945. for (i = attrs.length - 1; i >= 0; i--) {
  7946. e.removeAttributeNode(attrs.item(i))
  7947. }
  7948. })
  7949. }
  7950. var parseStyle = function (cssText) {
  7951. return styles.parse(cssText)
  7952. }
  7953. var serializeStyle = function (stylesArg, name) {
  7954. return styles.serialize(stylesArg, name)
  7955. }
  7956. var addStyle = function (cssText) {
  7957. var head, styleElm
  7958. if (self !== DOMUtils.DOM && doc === document) {
  7959. if (addedStyles[cssText]) {
  7960. return
  7961. }
  7962. addedStyles[cssText] = true
  7963. }
  7964. styleElm = doc.getElementById('mceDefaultStyles')
  7965. if (!styleElm) {
  7966. styleElm = doc.createElement('style')
  7967. styleElm.id = 'mceDefaultStyles'
  7968. styleElm.type = 'text/css'
  7969. head = doc.getElementsByTagName('head')[0]
  7970. if (head.firstChild) {
  7971. head.insertBefore(styleElm, head.firstChild)
  7972. } else {
  7973. head.appendChild(styleElm)
  7974. }
  7975. }
  7976. if (styleElm.styleSheet) {
  7977. styleElm.styleSheet.cssText += cssText
  7978. } else {
  7979. styleElm.appendChild(doc.createTextNode(cssText))
  7980. }
  7981. }
  7982. var loadCSS = function (urls) {
  7983. if (!urls) {
  7984. urls = ''
  7985. }
  7986. each$k(urls.split(','), function (url) {
  7987. files[url] = true
  7988. styleSheetLoader.load(url, noop)
  7989. })
  7990. }
  7991. var toggleClass = function (elm, cls, state) {
  7992. $$(elm)
  7993. .toggleClass(cls, state)
  7994. .each(function () {
  7995. if (this.className === '') {
  7996. DomQuery(this).attr('class', null)
  7997. }
  7998. })
  7999. }
  8000. var addClass = function (elm, cls) {
  8001. $$(elm).addClass(cls)
  8002. }
  8003. var removeClass = function (elm, cls) {
  8004. toggleClass(elm, cls, false)
  8005. }
  8006. var hasClass = function (elm, cls) {
  8007. return $$(elm).hasClass(cls)
  8008. }
  8009. var show = function (elm) {
  8010. $$(elm).show()
  8011. }
  8012. var hide = function (elm) {
  8013. $$(elm).hide()
  8014. }
  8015. var isHidden = function (elm) {
  8016. return $$(elm).css('display') === 'none'
  8017. }
  8018. var uniqueId = function (prefix) {
  8019. return (!prefix ? 'mce_' : prefix) + counter++
  8020. }
  8021. var getOuterHTML = function (elm) {
  8022. var node = typeof elm === 'string' ? get(elm) : elm
  8023. return isElement$5(node)
  8024. ? node.outerHTML
  8025. : DomQuery('<div></div>').append(DomQuery(node).clone()).html()
  8026. }
  8027. var setOuterHTML = function (elm, html) {
  8028. $$(elm).each(function () {
  8029. try {
  8030. if ('outerHTML' in this) {
  8031. this.outerHTML = html
  8032. return
  8033. }
  8034. } catch (ex) {}
  8035. remove(DomQuery(this).html(html), true)
  8036. })
  8037. }
  8038. var insertAfter = function (node, reference) {
  8039. var referenceNode = get(reference)
  8040. return run(node, function (node) {
  8041. var parent = referenceNode.parentNode
  8042. var nextSibling = referenceNode.nextSibling
  8043. if (nextSibling) {
  8044. parent.insertBefore(node, nextSibling)
  8045. } else {
  8046. parent.appendChild(node)
  8047. }
  8048. return node
  8049. })
  8050. }
  8051. var replace = function (newElm, oldElm, keepChildren) {
  8052. return run(oldElm, function (oldElm) {
  8053. if (Tools.is(oldElm, 'array')) {
  8054. newElm = newElm.cloneNode(true)
  8055. }
  8056. if (keepChildren) {
  8057. each$f(grep$1(oldElm.childNodes), function (node) {
  8058. newElm.appendChild(node)
  8059. })
  8060. }
  8061. return oldElm.parentNode.replaceChild(newElm, oldElm)
  8062. })
  8063. }
  8064. var rename = function (elm, name) {
  8065. var newElm
  8066. if (elm.nodeName !== name.toUpperCase()) {
  8067. newElm = create(name)
  8068. each$f(getAttribs(elm), function (attrNode) {
  8069. setAttrib(
  8070. newElm,
  8071. attrNode.nodeName,
  8072. getAttrib(elm, attrNode.nodeName)
  8073. )
  8074. })
  8075. replace(newElm, elm, true)
  8076. }
  8077. return newElm || elm
  8078. }
  8079. var findCommonAncestor = function (a, b) {
  8080. var ps = a,
  8081. pe
  8082. while (ps) {
  8083. pe = b
  8084. while (pe && ps !== pe) {
  8085. pe = pe.parentNode
  8086. }
  8087. if (ps === pe) {
  8088. break
  8089. }
  8090. ps = ps.parentNode
  8091. }
  8092. if (!ps && a.ownerDocument) {
  8093. return a.ownerDocument.documentElement
  8094. }
  8095. return ps
  8096. }
  8097. var toHex = function (rgbVal) {
  8098. return styles.toHex(Tools.trim(rgbVal))
  8099. }
  8100. var isNonEmptyElement = function (node) {
  8101. if (isElement$5(node)) {
  8102. var isNamedAnchor =
  8103. node.nodeName.toLowerCase() === 'a' &&
  8104. !getAttrib(node, 'href') &&
  8105. getAttrib(node, 'id')
  8106. if (
  8107. getAttrib(node, 'name') ||
  8108. getAttrib(node, 'data-mce-bookmark') ||
  8109. isNamedAnchor
  8110. ) {
  8111. return true
  8112. }
  8113. }
  8114. return false
  8115. }
  8116. var isEmpty = function (node, elements) {
  8117. var type,
  8118. name,
  8119. brCount = 0
  8120. if (isNonEmptyElement(node)) {
  8121. return false
  8122. }
  8123. node = node.firstChild
  8124. if (node) {
  8125. var walker = new DomTreeWalker(node, node.parentNode)
  8126. var whitespace = schema ? schema.getWhiteSpaceElements() : {}
  8127. elements = elements || (schema ? schema.getNonEmptyElements() : null)
  8128. do {
  8129. type = node.nodeType
  8130. if (isElement$5(node)) {
  8131. var bogusVal = node.getAttribute('data-mce-bogus')
  8132. if (bogusVal) {
  8133. node = walker.next(bogusVal === 'all')
  8134. continue
  8135. }
  8136. name = node.nodeName.toLowerCase()
  8137. if (elements && elements[name]) {
  8138. if (name === 'br') {
  8139. brCount++
  8140. node = walker.next()
  8141. continue
  8142. }
  8143. return false
  8144. }
  8145. if (isNonEmptyElement(node)) {
  8146. return false
  8147. }
  8148. }
  8149. if (type === 8) {
  8150. return false
  8151. }
  8152. if (type === 3 && !isWhitespaceText(node.nodeValue)) {
  8153. return false
  8154. }
  8155. if (
  8156. type === 3 &&
  8157. node.parentNode &&
  8158. whitespace[node.parentNode.nodeName] &&
  8159. isWhitespaceText(node.nodeValue)
  8160. ) {
  8161. return false
  8162. }
  8163. node = walker.next()
  8164. } while (node)
  8165. }
  8166. return brCount <= 1
  8167. }
  8168. var createRng = function () {
  8169. return doc.createRange()
  8170. }
  8171. var split = function (parentElm, splitElm, replacementElm) {
  8172. var range = createRng()
  8173. var beforeFragment
  8174. var afterFragment
  8175. var parentNode
  8176. if (parentElm && splitElm) {
  8177. range.setStart(parentElm.parentNode, findNodeIndex(parentElm))
  8178. range.setEnd(splitElm.parentNode, findNodeIndex(splitElm))
  8179. beforeFragment = range.extractContents()
  8180. range = createRng()
  8181. range.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1)
  8182. range.setEnd(parentElm.parentNode, findNodeIndex(parentElm) + 1)
  8183. afterFragment = range.extractContents()
  8184. parentNode = parentElm.parentNode
  8185. parentNode.insertBefore(trimNode(self, beforeFragment), parentElm)
  8186. if (replacementElm) {
  8187. parentNode.insertBefore(replacementElm, parentElm)
  8188. } else {
  8189. parentNode.insertBefore(splitElm, parentElm)
  8190. }
  8191. parentNode.insertBefore(trimNode(self, afterFragment), parentElm)
  8192. remove(parentElm)
  8193. return replacementElm || splitElm
  8194. }
  8195. }
  8196. var bind = function (target, name, func, scope) {
  8197. if (Tools.isArray(target)) {
  8198. var i = target.length
  8199. var rv = []
  8200. while (i--) {
  8201. rv[i] = bind(target[i], name, func, scope)
  8202. }
  8203. return rv
  8204. }
  8205. if (settings.collect && (target === doc || target === win)) {
  8206. boundEvents.push([target, name, func, scope])
  8207. }
  8208. var output = events.bind(target, name, func, scope || self)
  8209. return output
  8210. }
  8211. var unbind = function (target, name, func) {
  8212. if (Tools.isArray(target)) {
  8213. var i = target.length
  8214. var rv = []
  8215. while (i--) {
  8216. rv[i] = unbind(target[i], name, func)
  8217. }
  8218. return rv
  8219. } else {
  8220. if (boundEvents.length > 0 && (target === doc || target === win)) {
  8221. var i = boundEvents.length
  8222. while (i--) {
  8223. var item = boundEvents[i]
  8224. if (
  8225. target === item[0] &&
  8226. (!name || name === item[1]) &&
  8227. (!func || func === item[2])
  8228. ) {
  8229. events.unbind(item[0], item[1], item[2])
  8230. }
  8231. }
  8232. }
  8233. return events.unbind(target, name, func)
  8234. }
  8235. }
  8236. var fire = function (target, name, evt) {
  8237. return events.fire(target, name, evt)
  8238. }
  8239. var getContentEditable = function (node) {
  8240. if (node && isElement$5(node)) {
  8241. var contentEditable = node.getAttribute('data-mce-contenteditable')
  8242. if (contentEditable && contentEditable !== 'inherit') {
  8243. return contentEditable
  8244. }
  8245. return node.contentEditable !== 'inherit' ? node.contentEditable : null
  8246. } else {
  8247. return null
  8248. }
  8249. }
  8250. var getContentEditableParent = function (node) {
  8251. var root = getRoot()
  8252. var state = null
  8253. for (; node && node !== root; node = node.parentNode) {
  8254. state = getContentEditable(node)
  8255. if (state !== null) {
  8256. break
  8257. }
  8258. }
  8259. return state
  8260. }
  8261. var destroy = function () {
  8262. if (boundEvents.length > 0) {
  8263. var i = boundEvents.length
  8264. while (i--) {
  8265. var item = boundEvents[i]
  8266. events.unbind(item[0], item[1], item[2])
  8267. }
  8268. }
  8269. each$j(files, function (_, url) {
  8270. styleSheetLoader.unload(url)
  8271. delete files[url]
  8272. })
  8273. if (Sizzle.setDocument) {
  8274. Sizzle.setDocument()
  8275. }
  8276. }
  8277. var isChildOf = function (node, parent) {
  8278. if (!isIE) {
  8279. return node === parent || parent.contains(node)
  8280. } else {
  8281. while (node) {
  8282. if (parent === node) {
  8283. return true
  8284. }
  8285. node = node.parentNode
  8286. }
  8287. return false
  8288. }
  8289. }
  8290. var dumpRng = function (r) {
  8291. return (
  8292. 'startContainer: ' +
  8293. r.startContainer.nodeName +
  8294. ', startOffset: ' +
  8295. r.startOffset +
  8296. ', endContainer: ' +
  8297. r.endContainer.nodeName +
  8298. ', endOffset: ' +
  8299. r.endOffset
  8300. )
  8301. }
  8302. var self = {
  8303. doc: doc,
  8304. settings: settings,
  8305. win: win,
  8306. files: files,
  8307. stdMode: stdMode,
  8308. boxModel: boxModel,
  8309. styleSheetLoader: styleSheetLoader,
  8310. boundEvents: boundEvents,
  8311. styles: styles,
  8312. schema: schema,
  8313. events: events,
  8314. isBlock: isBlock,
  8315. $: $,
  8316. $$: $$,
  8317. root: null,
  8318. clone: clone,
  8319. getRoot: getRoot,
  8320. getViewPort: getViewPort,
  8321. getRect: getRect,
  8322. getSize: getSize,
  8323. getParent: getParent,
  8324. getParents: getParents,
  8325. get: get,
  8326. getNext: getNext,
  8327. getPrev: getPrev,
  8328. select: select,
  8329. is: is,
  8330. add: add,
  8331. create: create,
  8332. createHTML: createHTML,
  8333. createFragment: createFragment,
  8334. remove: remove,
  8335. setStyle: setStyle,
  8336. getStyle: getStyle,
  8337. setStyles: setStyles,
  8338. removeAllAttribs: removeAllAttribs,
  8339. setAttrib: setAttrib,
  8340. setAttribs: setAttribs,
  8341. getAttrib: getAttrib,
  8342. getPos: getPos$1,
  8343. parseStyle: parseStyle,
  8344. serializeStyle: serializeStyle,
  8345. addStyle: addStyle,
  8346. loadCSS: loadCSS,
  8347. addClass: addClass,
  8348. removeClass: removeClass,
  8349. hasClass: hasClass,
  8350. toggleClass: toggleClass,
  8351. show: show,
  8352. hide: hide,
  8353. isHidden: isHidden,
  8354. uniqueId: uniqueId,
  8355. setHTML: setHTML,
  8356. getOuterHTML: getOuterHTML,
  8357. setOuterHTML: setOuterHTML,
  8358. decode: decode,
  8359. encode: encode,
  8360. insertAfter: insertAfter,
  8361. replace: replace,
  8362. rename: rename,
  8363. findCommonAncestor: findCommonAncestor,
  8364. toHex: toHex,
  8365. run: run,
  8366. getAttribs: getAttribs,
  8367. isEmpty: isEmpty,
  8368. createRng: createRng,
  8369. nodeIndex: findNodeIndex,
  8370. split: split,
  8371. bind: bind,
  8372. unbind: unbind,
  8373. fire: fire,
  8374. getContentEditable: getContentEditable,
  8375. getContentEditableParent: getContentEditableParent,
  8376. destroy: destroy,
  8377. isChildOf: isChildOf,
  8378. dumpRng: dumpRng,
  8379. }
  8380. var attrHooks = setupAttrHooks(styles, settings, constant(self))
  8381. return self
  8382. }
  8383. DOMUtils.DOM = DOMUtils(document)
  8384. DOMUtils.nodeIndex = findNodeIndex
  8385. var DOM$a = DOMUtils.DOM
  8386. var each$e = Tools.each,
  8387. grep = Tools.grep
  8388. var QUEUED = 0
  8389. var LOADING = 1
  8390. var LOADED = 2
  8391. var FAILED = 3
  8392. var ScriptLoader = (function () {
  8393. function ScriptLoader(settings) {
  8394. if (settings === void 0) {
  8395. settings = {}
  8396. }
  8397. this.states = {}
  8398. this.queue = []
  8399. this.scriptLoadedCallbacks = {}
  8400. this.queueLoadedCallbacks = []
  8401. this.loading = 0
  8402. this.settings = settings
  8403. }
  8404. ScriptLoader.prototype._setReferrerPolicy = function (referrerPolicy) {
  8405. this.settings.referrerPolicy = referrerPolicy
  8406. }
  8407. ScriptLoader.prototype.loadScript = function (url, success, failure) {
  8408. var dom = DOM$a
  8409. var elm
  8410. var cleanup = function () {
  8411. dom.remove(id)
  8412. if (elm) {
  8413. elm.onerror = elm.onload = elm = null
  8414. }
  8415. }
  8416. var done = function () {
  8417. cleanup()
  8418. success()
  8419. }
  8420. var error = function () {
  8421. cleanup()
  8422. if (isFunction(failure)) {
  8423. failure()
  8424. } else {
  8425. if (typeof console !== 'undefined' && console.log) {
  8426. console.log('Failed to load script: ' + url)
  8427. }
  8428. }
  8429. }
  8430. var id = dom.uniqueId()
  8431. elm = document.createElement('script')
  8432. elm.id = id
  8433. elm.type = 'text/javascript'
  8434. elm.src = Tools._addCacheSuffix(url)
  8435. if (this.settings.referrerPolicy) {
  8436. dom.setAttrib(elm, 'referrerpolicy', this.settings.referrerPolicy)
  8437. }
  8438. elm.onload = done
  8439. elm.onerror = error
  8440. ;(document.getElementsByTagName('head')[0] || document.body).appendChild(
  8441. elm
  8442. )
  8443. }
  8444. ScriptLoader.prototype.isDone = function (url) {
  8445. return this.states[url] === LOADED
  8446. }
  8447. ScriptLoader.prototype.markDone = function (url) {
  8448. this.states[url] = LOADED
  8449. }
  8450. ScriptLoader.prototype.add = function (url, success, scope, failure) {
  8451. var state = this.states[url]
  8452. this.queue.push(url)
  8453. if (state === undefined) {
  8454. this.states[url] = QUEUED
  8455. }
  8456. if (success) {
  8457. if (!this.scriptLoadedCallbacks[url]) {
  8458. this.scriptLoadedCallbacks[url] = []
  8459. }
  8460. this.scriptLoadedCallbacks[url].push({
  8461. success: success,
  8462. failure: failure,
  8463. scope: scope || this,
  8464. })
  8465. }
  8466. }
  8467. ScriptLoader.prototype.load = function (url, success, scope, failure) {
  8468. return this.add(url, success, scope, failure)
  8469. }
  8470. ScriptLoader.prototype.remove = function (url) {
  8471. delete this.states[url]
  8472. delete this.scriptLoadedCallbacks[url]
  8473. }
  8474. ScriptLoader.prototype.loadQueue = function (success, scope, failure) {
  8475. this.loadScripts(this.queue, success, scope, failure)
  8476. }
  8477. ScriptLoader.prototype.loadScripts = function (
  8478. scripts,
  8479. success,
  8480. scope,
  8481. failure
  8482. ) {
  8483. var self = this
  8484. var failures = []
  8485. var execCallbacks = function (name, url) {
  8486. each$e(self.scriptLoadedCallbacks[url], function (callback) {
  8487. if (isFunction(callback[name])) {
  8488. callback[name].call(callback.scope)
  8489. }
  8490. })
  8491. self.scriptLoadedCallbacks[url] = undefined
  8492. }
  8493. self.queueLoadedCallbacks.push({
  8494. success: success,
  8495. failure: failure,
  8496. scope: scope || this,
  8497. })
  8498. var loadScripts = function () {
  8499. var loadingScripts = grep(scripts)
  8500. scripts.length = 0
  8501. each$e(loadingScripts, function (url) {
  8502. if (self.states[url] === LOADED) {
  8503. execCallbacks('success', url)
  8504. return
  8505. }
  8506. if (self.states[url] === FAILED) {
  8507. execCallbacks('failure', url)
  8508. return
  8509. }
  8510. if (self.states[url] !== LOADING) {
  8511. self.states[url] = LOADING
  8512. self.loading++
  8513. self.loadScript(
  8514. url,
  8515. function () {
  8516. self.states[url] = LOADED
  8517. self.loading--
  8518. execCallbacks('success', url)
  8519. loadScripts()
  8520. },
  8521. function () {
  8522. self.states[url] = FAILED
  8523. self.loading--
  8524. failures.push(url)
  8525. execCallbacks('failure', url)
  8526. loadScripts()
  8527. }
  8528. )
  8529. }
  8530. })
  8531. if (!self.loading) {
  8532. var notifyCallbacks = self.queueLoadedCallbacks.slice(0)
  8533. self.queueLoadedCallbacks.length = 0
  8534. each$e(notifyCallbacks, function (callback) {
  8535. if (failures.length === 0) {
  8536. if (isFunction(callback.success)) {
  8537. callback.success.call(callback.scope)
  8538. }
  8539. } else {
  8540. if (isFunction(callback.failure)) {
  8541. callback.failure.call(callback.scope, failures)
  8542. }
  8543. }
  8544. })
  8545. }
  8546. }
  8547. loadScripts()
  8548. }
  8549. ScriptLoader.ScriptLoader = new ScriptLoader()
  8550. return ScriptLoader
  8551. })()
  8552. var Cell = function (initial) {
  8553. var value = initial
  8554. var get = function () {
  8555. return value
  8556. }
  8557. var set = function (v) {
  8558. value = v
  8559. }
  8560. return {
  8561. get: get,
  8562. set: set,
  8563. }
  8564. }
  8565. var isRaw = function (str) {
  8566. return isObject(str) && has$2(str, 'raw')
  8567. }
  8568. var isTokenised = function (str) {
  8569. return isArray$1(str) && str.length > 1
  8570. }
  8571. var data = {}
  8572. var currentCode = Cell('en')
  8573. var getLanguageData = function () {
  8574. return get$9(data, currentCode.get())
  8575. }
  8576. var getData = function () {
  8577. return map$2(data, function (value) {
  8578. return __assign({}, value)
  8579. })
  8580. }
  8581. var setCode = function (newCode) {
  8582. if (newCode) {
  8583. currentCode.set(newCode)
  8584. }
  8585. }
  8586. var getCode = function () {
  8587. return currentCode.get()
  8588. }
  8589. var add$4 = function (code, items) {
  8590. var langData = data[code]
  8591. if (!langData) {
  8592. data[code] = langData = {}
  8593. }
  8594. each$j(items, function (translation, name) {
  8595. langData[name.toLowerCase()] = translation
  8596. })
  8597. }
  8598. var translate = function (text) {
  8599. var langData = getLanguageData().getOr({})
  8600. var toString = function (obj) {
  8601. if (isFunction(obj)) {
  8602. return Object.prototype.toString.call(obj)
  8603. }
  8604. return !isEmpty(obj) ? '' + obj : ''
  8605. }
  8606. var isEmpty = function (text) {
  8607. return text === '' || text === null || text === undefined
  8608. }
  8609. var getLangData = function (text) {
  8610. var textstr = toString(text)
  8611. return get$9(langData, textstr.toLowerCase()).map(toString).getOr(textstr)
  8612. }
  8613. var removeContext = function (str) {
  8614. return str.replace(/{context:\w+}$/, '')
  8615. }
  8616. if (isEmpty(text)) {
  8617. return ''
  8618. }
  8619. if (isRaw(text)) {
  8620. return toString(text.raw)
  8621. }
  8622. if (isTokenised(text)) {
  8623. var values_1 = text.slice(1)
  8624. var substitued = getLangData(text[0]).replace(
  8625. /\{([0-9]+)\}/g,
  8626. function ($1, $2) {
  8627. return has$2(values_1, $2) ? toString(values_1[$2]) : $1
  8628. }
  8629. )
  8630. return removeContext(substitued)
  8631. }
  8632. return removeContext(getLangData(text))
  8633. }
  8634. var isRtl$1 = function () {
  8635. return getLanguageData()
  8636. .bind(function (items) {
  8637. return get$9(items, '_dir')
  8638. })
  8639. .exists(function (dir) {
  8640. return dir === 'rtl'
  8641. })
  8642. }
  8643. var hasCode = function (code) {
  8644. return has$2(data, code)
  8645. }
  8646. var I18n = {
  8647. getData: getData,
  8648. setCode: setCode,
  8649. getCode: getCode,
  8650. add: add$4,
  8651. translate: translate,
  8652. isRtl: isRtl$1,
  8653. hasCode: hasCode,
  8654. }
  8655. var AddOnManager = function () {
  8656. var items = []
  8657. var urls = {}
  8658. var lookup = {}
  8659. var _listeners = []
  8660. var runListeners = function (name, state) {
  8661. var matchedListeners = filter$4(_listeners, function (listener) {
  8662. return listener.name === name && listener.state === state
  8663. })
  8664. each$k(matchedListeners, function (listener) {
  8665. return listener.callback()
  8666. })
  8667. }
  8668. var get = function (name) {
  8669. if (lookup[name]) {
  8670. return lookup[name].instance
  8671. }
  8672. return undefined
  8673. }
  8674. var dependencies = function (name) {
  8675. var result
  8676. if (lookup[name]) {
  8677. result = lookup[name].dependencies
  8678. }
  8679. return result || []
  8680. }
  8681. var requireLangPack = function (name, languages) {
  8682. if (AddOnManager.languageLoad !== false) {
  8683. waitFor(
  8684. name,
  8685. function () {
  8686. var language = I18n.getCode()
  8687. var wrappedLanguages = ',' + (languages || '') + ','
  8688. if (
  8689. !language ||
  8690. (languages &&
  8691. wrappedLanguages.indexOf(',' + language + ',') === -1)
  8692. ) {
  8693. return
  8694. }
  8695. ScriptLoader.ScriptLoader.add(
  8696. urls[name] + '/langs/' + language + '.js'
  8697. )
  8698. },
  8699. 'loaded'
  8700. )
  8701. }
  8702. }
  8703. var add = function (id, addOn, dependencies) {
  8704. var addOnConstructor = addOn
  8705. items.push(addOnConstructor)
  8706. lookup[id] = {
  8707. instance: addOnConstructor,
  8708. dependencies: dependencies,
  8709. }
  8710. runListeners(id, 'added')
  8711. return addOnConstructor
  8712. }
  8713. var remove = function (name) {
  8714. delete urls[name]
  8715. delete lookup[name]
  8716. }
  8717. var createUrl = function (baseUrl, dep) {
  8718. if (typeof dep === 'object') {
  8719. return dep
  8720. }
  8721. return typeof baseUrl === 'string'
  8722. ? {
  8723. prefix: '',
  8724. resource: dep,
  8725. suffix: '',
  8726. }
  8727. : {
  8728. prefix: baseUrl.prefix,
  8729. resource: dep,
  8730. suffix: baseUrl.suffix,
  8731. }
  8732. }
  8733. var addComponents = function (pluginName, scripts) {
  8734. var pluginUrl = urls[pluginName]
  8735. each$k(scripts, function (script) {
  8736. ScriptLoader.ScriptLoader.add(pluginUrl + '/' + script)
  8737. })
  8738. }
  8739. var loadDependencies = function (name, addOnUrl, success, scope) {
  8740. var deps = dependencies(name)
  8741. each$k(deps, function (dep) {
  8742. var newUrl = createUrl(addOnUrl, dep)
  8743. load(newUrl.resource, newUrl, undefined, undefined)
  8744. })
  8745. if (success) {
  8746. if (scope) {
  8747. success.call(scope)
  8748. } else {
  8749. success.call(ScriptLoader)
  8750. }
  8751. }
  8752. }
  8753. var load = function (name, addOnUrl, success, scope, failure) {
  8754. if (urls[name]) {
  8755. return
  8756. }
  8757. var urlString =
  8758. typeof addOnUrl === 'string'
  8759. ? addOnUrl
  8760. : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix
  8761. if (urlString.indexOf('/') !== 0 && urlString.indexOf('://') === -1) {
  8762. urlString = AddOnManager.baseURL + '/' + urlString
  8763. }
  8764. urls[name] = urlString.substring(0, urlString.lastIndexOf('/'))
  8765. var done = function () {
  8766. runListeners(name, 'loaded')
  8767. loadDependencies(name, addOnUrl, success, scope)
  8768. }
  8769. if (lookup[name]) {
  8770. done()
  8771. } else {
  8772. ScriptLoader.ScriptLoader.add(urlString, done, scope, failure)
  8773. }
  8774. }
  8775. var waitFor = function (name, callback, state) {
  8776. if (state === void 0) {
  8777. state = 'added'
  8778. }
  8779. if (has$2(lookup, name) && state === 'added') {
  8780. callback()
  8781. } else if (has$2(urls, name) && state === 'loaded') {
  8782. callback()
  8783. } else {
  8784. _listeners.push({
  8785. name: name,
  8786. state: state,
  8787. callback: callback,
  8788. })
  8789. }
  8790. }
  8791. return {
  8792. items: items,
  8793. urls: urls,
  8794. lookup: lookup,
  8795. _listeners: _listeners,
  8796. get: get,
  8797. dependencies: dependencies,
  8798. requireLangPack: requireLangPack,
  8799. add: add,
  8800. remove: remove,
  8801. createUrl: createUrl,
  8802. addComponents: addComponents,
  8803. load: load,
  8804. waitFor: waitFor,
  8805. }
  8806. }
  8807. AddOnManager.languageLoad = true
  8808. AddOnManager.baseURL = ''
  8809. AddOnManager.PluginManager = AddOnManager()
  8810. AddOnManager.ThemeManager = AddOnManager()
  8811. var singleton = function (doRevoke) {
  8812. var subject = Cell(Optional.none())
  8813. var revoke = function () {
  8814. return subject.get().each(doRevoke)
  8815. }
  8816. var clear = function () {
  8817. revoke()
  8818. subject.set(Optional.none())
  8819. }
  8820. var isSet = function () {
  8821. return subject.get().isSome()
  8822. }
  8823. var get = function () {
  8824. return subject.get()
  8825. }
  8826. var set = function (s) {
  8827. revoke()
  8828. subject.set(Optional.some(s))
  8829. }
  8830. return {
  8831. clear: clear,
  8832. isSet: isSet,
  8833. get: get,
  8834. set: set,
  8835. }
  8836. }
  8837. var value = function () {
  8838. var subject = singleton(noop)
  8839. var on = function (f) {
  8840. return subject.get().each(f)
  8841. }
  8842. return __assign(__assign({}, subject), { on: on })
  8843. }
  8844. var first = function (fn, rate) {
  8845. var timer = null
  8846. var cancel = function () {
  8847. if (!isNull(timer)) {
  8848. clearTimeout(timer)
  8849. timer = null
  8850. }
  8851. }
  8852. var throttle = function () {
  8853. var args = []
  8854. for (var _i = 0; _i < arguments.length; _i++) {
  8855. args[_i] = arguments[_i]
  8856. }
  8857. if (isNull(timer)) {
  8858. timer = setTimeout(function () {
  8859. timer = null
  8860. fn.apply(null, args)
  8861. }, rate)
  8862. }
  8863. }
  8864. return {
  8865. cancel: cancel,
  8866. throttle: throttle,
  8867. }
  8868. }
  8869. var last = function (fn, rate) {
  8870. var timer = null
  8871. var cancel = function () {
  8872. if (!isNull(timer)) {
  8873. clearTimeout(timer)
  8874. timer = null
  8875. }
  8876. }
  8877. var throttle = function () {
  8878. var args = []
  8879. for (var _i = 0; _i < arguments.length; _i++) {
  8880. args[_i] = arguments[_i]
  8881. }
  8882. cancel()
  8883. timer = setTimeout(function () {
  8884. timer = null
  8885. fn.apply(null, args)
  8886. }, rate)
  8887. }
  8888. return {
  8889. cancel: cancel,
  8890. throttle: throttle,
  8891. }
  8892. }
  8893. var read$4 = function (element, attr) {
  8894. var value = get$6(element, attr)
  8895. return value === undefined || value === '' ? [] : value.split(' ')
  8896. }
  8897. var add$3 = function (element, attr, id) {
  8898. var old = read$4(element, attr)
  8899. var nu = old.concat([id])
  8900. set$1(element, attr, nu.join(' '))
  8901. return true
  8902. }
  8903. var remove$5 = function (element, attr, id) {
  8904. var nu = filter$4(read$4(element, attr), function (v) {
  8905. return v !== id
  8906. })
  8907. if (nu.length > 0) {
  8908. set$1(element, attr, nu.join(' '))
  8909. } else {
  8910. remove$6(element, attr)
  8911. }
  8912. return false
  8913. }
  8914. var supports = function (element) {
  8915. return element.dom.classList !== undefined
  8916. }
  8917. var get$4 = function (element) {
  8918. return read$4(element, 'class')
  8919. }
  8920. var add$2 = function (element, clazz) {
  8921. return add$3(element, 'class', clazz)
  8922. }
  8923. var remove$4 = function (element, clazz) {
  8924. return remove$5(element, 'class', clazz)
  8925. }
  8926. var add$1 = function (element, clazz) {
  8927. if (supports(element)) {
  8928. element.dom.classList.add(clazz)
  8929. } else {
  8930. add$2(element, clazz)
  8931. }
  8932. }
  8933. var cleanClass = function (element) {
  8934. var classList = supports(element) ? element.dom.classList : get$4(element)
  8935. if (classList.length === 0) {
  8936. remove$6(element, 'class')
  8937. }
  8938. }
  8939. var remove$3 = function (element, clazz) {
  8940. if (supports(element)) {
  8941. var classList = element.dom.classList
  8942. classList.remove(clazz)
  8943. } else {
  8944. remove$4(element, clazz)
  8945. }
  8946. cleanClass(element)
  8947. }
  8948. var has = function (element, clazz) {
  8949. return supports(element) && element.dom.classList.contains(clazz)
  8950. }
  8951. var descendants$1 = function (scope, predicate) {
  8952. var result = []
  8953. each$k(children(scope), function (x) {
  8954. if (predicate(x)) {
  8955. result = result.concat([x])
  8956. }
  8957. result = result.concat(descendants$1(x, predicate))
  8958. })
  8959. return result
  8960. }
  8961. var descendants = function (scope, selector) {
  8962. return all(selector, scope)
  8963. }
  8964. var annotation = constant('mce-annotation')
  8965. var dataAnnotation = constant('data-mce-annotation')
  8966. var dataAnnotationId = constant('data-mce-annotation-uid')
  8967. var identify = function (editor, annotationName) {
  8968. var rng = editor.selection.getRng()
  8969. var start = SugarElement.fromDom(rng.startContainer)
  8970. var root = SugarElement.fromDom(editor.getBody())
  8971. var selector = annotationName.fold(
  8972. function () {
  8973. return '.' + annotation()
  8974. },
  8975. function (an) {
  8976. return '[' + dataAnnotation() + '="' + an + '"]'
  8977. }
  8978. )
  8979. var newStart = child$1(start, rng.startOffset).getOr(start)
  8980. var closest = closest$2(newStart, selector, function (n) {
  8981. return eq(n, root)
  8982. })
  8983. var getAttr = function (c, property) {
  8984. if (has$1(c, property)) {
  8985. return Optional.some(get$6(c, property))
  8986. } else {
  8987. return Optional.none()
  8988. }
  8989. }
  8990. return closest.bind(function (c) {
  8991. return getAttr(c, '' + dataAnnotationId()).bind(function (uid) {
  8992. return getAttr(c, '' + dataAnnotation()).map(function (name) {
  8993. var elements = findMarkers(editor, uid)
  8994. return {
  8995. uid: uid,
  8996. name: name,
  8997. elements: elements,
  8998. }
  8999. })
  9000. })
  9001. })
  9002. }
  9003. var isAnnotation = function (elem) {
  9004. return isElement$6(elem) && has(elem, annotation())
  9005. }
  9006. var findMarkers = function (editor, uid) {
  9007. var body = SugarElement.fromDom(editor.getBody())
  9008. return descendants(body, '[' + dataAnnotationId() + '="' + uid + '"]')
  9009. }
  9010. var findAll = function (editor, name) {
  9011. var body = SugarElement.fromDom(editor.getBody())
  9012. var markers = descendants(body, '[' + dataAnnotation() + '="' + name + '"]')
  9013. var directory = {}
  9014. each$k(markers, function (m) {
  9015. var uid = get$6(m, dataAnnotationId())
  9016. var nodesAlready = get$9(directory, uid).getOr([])
  9017. directory[uid] = nodesAlready.concat([m])
  9018. })
  9019. return directory
  9020. }
  9021. var setup$n = function (editor, _registry) {
  9022. var changeCallbacks = Cell({})
  9023. var initData = function () {
  9024. return {
  9025. listeners: [],
  9026. previous: value(),
  9027. }
  9028. }
  9029. var withCallbacks = function (name, f) {
  9030. updateCallbacks(name, function (data) {
  9031. f(data)
  9032. return data
  9033. })
  9034. }
  9035. var updateCallbacks = function (name, f) {
  9036. var callbackMap = changeCallbacks.get()
  9037. var data = get$9(callbackMap, name).getOrThunk(initData)
  9038. var outputData = f(data)
  9039. callbackMap[name] = outputData
  9040. changeCallbacks.set(callbackMap)
  9041. }
  9042. var fireCallbacks = function (name, uid, elements) {
  9043. withCallbacks(name, function (data) {
  9044. each$k(data.listeners, function (f) {
  9045. return f(true, name, {
  9046. uid: uid,
  9047. nodes: map$3(elements, function (elem) {
  9048. return elem.dom
  9049. }),
  9050. })
  9051. })
  9052. })
  9053. }
  9054. var fireNoAnnotation = function (name) {
  9055. withCallbacks(name, function (data) {
  9056. each$k(data.listeners, function (f) {
  9057. return f(false, name)
  9058. })
  9059. })
  9060. }
  9061. var onNodeChange = last(function () {
  9062. var callbackMap = changeCallbacks.get()
  9063. var annotations = sort(keys(callbackMap))
  9064. each$k(annotations, function (name) {
  9065. updateCallbacks(name, function (data) {
  9066. var prev = data.previous.get()
  9067. identify(editor, Optional.some(name)).fold(
  9068. function () {
  9069. if (prev.isSome()) {
  9070. fireNoAnnotation(name)
  9071. data.previous.clear()
  9072. }
  9073. },
  9074. function (_a) {
  9075. var uid = _a.uid,
  9076. name = _a.name,
  9077. elements = _a.elements
  9078. if (!is$1(prev, uid)) {
  9079. fireCallbacks(name, uid, elements)
  9080. data.previous.set(uid)
  9081. }
  9082. }
  9083. )
  9084. return {
  9085. previous: data.previous,
  9086. listeners: data.listeners,
  9087. }
  9088. })
  9089. })
  9090. }, 30)
  9091. editor.on('remove', function () {
  9092. onNodeChange.cancel()
  9093. })
  9094. editor.on('NodeChange', function () {
  9095. onNodeChange.throttle()
  9096. })
  9097. var addListener = function (name, f) {
  9098. updateCallbacks(name, function (data) {
  9099. return {
  9100. previous: data.previous,
  9101. listeners: data.listeners.concat([f]),
  9102. }
  9103. })
  9104. }
  9105. return { addListener: addListener }
  9106. }
  9107. var setup$m = function (editor, registry) {
  9108. var identifyParserNode = function (span) {
  9109. return Optional.from(span.attr(dataAnnotation())).bind(registry.lookup)
  9110. }
  9111. editor.on('init', function () {
  9112. editor.serializer.addNodeFilter('span', function (spans) {
  9113. each$k(spans, function (span) {
  9114. identifyParserNode(span).each(function (settings) {
  9115. if (settings.persistent === false) {
  9116. span.unwrap()
  9117. }
  9118. })
  9119. })
  9120. })
  9121. })
  9122. }
  9123. var create$7 = function () {
  9124. var annotations = {}
  9125. var register = function (name, settings) {
  9126. annotations[name] = {
  9127. name: name,
  9128. settings: settings,
  9129. }
  9130. }
  9131. var lookup = function (name) {
  9132. return get$9(annotations, name).map(function (a) {
  9133. return a.settings
  9134. })
  9135. }
  9136. return {
  9137. register: register,
  9138. lookup: lookup,
  9139. }
  9140. }
  9141. var unique = 0
  9142. var generate = function (prefix) {
  9143. var date = new Date()
  9144. var time = date.getTime()
  9145. var random = Math.floor(Math.random() * 1000000000)
  9146. unique++
  9147. return prefix + '_' + random + unique + String(time)
  9148. }
  9149. var add = function (element, classes) {
  9150. each$k(classes, function (x) {
  9151. add$1(element, x)
  9152. })
  9153. }
  9154. var fromHtml = function (html, scope) {
  9155. var doc = scope || document
  9156. var div = doc.createElement('div')
  9157. div.innerHTML = html
  9158. return children(SugarElement.fromDom(div))
  9159. }
  9160. var fromDom$1 = function (nodes) {
  9161. return map$3(nodes, SugarElement.fromDom)
  9162. }
  9163. var get$3 = function (element) {
  9164. return element.dom.innerHTML
  9165. }
  9166. var set = function (element, content) {
  9167. var owner = owner$1(element)
  9168. var docDom = owner.dom
  9169. var fragment = SugarElement.fromDom(docDom.createDocumentFragment())
  9170. var contentElements = fromHtml(content, docDom)
  9171. append(fragment, contentElements)
  9172. empty(element)
  9173. append$1(element, fragment)
  9174. }
  9175. var clone$1 = function (original, isDeep) {
  9176. return SugarElement.fromDom(original.dom.cloneNode(isDeep))
  9177. }
  9178. var shallow = function (original) {
  9179. return clone$1(original, false)
  9180. }
  9181. var deep$1 = function (original) {
  9182. return clone$1(original, true)
  9183. }
  9184. var TextWalker = function (startNode, rootNode, isBoundary) {
  9185. if (isBoundary === void 0) {
  9186. isBoundary = never
  9187. }
  9188. var walker = new DomTreeWalker(startNode, rootNode)
  9189. var walk = function (direction) {
  9190. var next
  9191. do {
  9192. next = walker[direction]()
  9193. } while (next && !isText$7(next) && !isBoundary(next))
  9194. return Optional.from(next).filter(isText$7)
  9195. }
  9196. return {
  9197. current: function () {
  9198. return Optional.from(walker.current()).filter(isText$7)
  9199. },
  9200. next: function () {
  9201. return walk('next')
  9202. },
  9203. prev: function () {
  9204. return walk('prev')
  9205. },
  9206. prev2: function () {
  9207. return walk('prev2')
  9208. },
  9209. }
  9210. }
  9211. var TextSeeker = function (dom, isBoundary) {
  9212. var isBlockBoundary = isBoundary
  9213. ? isBoundary
  9214. : function (node) {
  9215. return (
  9216. dom.isBlock(node) || isBr$5(node) || isContentEditableFalse$b(node)
  9217. )
  9218. }
  9219. var walk = function (node, offset, walker, process) {
  9220. if (isText$7(node)) {
  9221. var newOffset = process(node, offset, node.data)
  9222. if (newOffset !== -1) {
  9223. return Optional.some({
  9224. container: node,
  9225. offset: newOffset,
  9226. })
  9227. }
  9228. }
  9229. return walker().bind(function (next) {
  9230. return walk(next.container, next.offset, walker, process)
  9231. })
  9232. }
  9233. var backwards = function (node, offset, process, root) {
  9234. var walker = TextWalker(node, root, isBlockBoundary)
  9235. return walk(
  9236. node,
  9237. offset,
  9238. function () {
  9239. return walker.prev().map(function (prev) {
  9240. return {
  9241. container: prev,
  9242. offset: prev.length,
  9243. }
  9244. })
  9245. },
  9246. process
  9247. ).getOrNull()
  9248. }
  9249. var forwards = function (node, offset, process, root) {
  9250. var walker = TextWalker(node, root, isBlockBoundary)
  9251. return walk(
  9252. node,
  9253. offset,
  9254. function () {
  9255. return walker.next().map(function (next) {
  9256. return {
  9257. container: next,
  9258. offset: 0,
  9259. }
  9260. })
  9261. },
  9262. process
  9263. ).getOrNull()
  9264. }
  9265. return {
  9266. backwards: backwards,
  9267. forwards: forwards,
  9268. }
  9269. }
  9270. var round$2 = Math.round
  9271. var clone = function (rect) {
  9272. if (!rect) {
  9273. return {
  9274. left: 0,
  9275. top: 0,
  9276. bottom: 0,
  9277. right: 0,
  9278. width: 0,
  9279. height: 0,
  9280. }
  9281. }
  9282. return {
  9283. left: round$2(rect.left),
  9284. top: round$2(rect.top),
  9285. bottom: round$2(rect.bottom),
  9286. right: round$2(rect.right),
  9287. width: round$2(rect.width),
  9288. height: round$2(rect.height),
  9289. }
  9290. }
  9291. var collapse = function (rect, toStart) {
  9292. rect = clone(rect)
  9293. if (toStart) {
  9294. rect.right = rect.left
  9295. } else {
  9296. rect.left = rect.left + rect.width
  9297. rect.right = rect.left
  9298. }
  9299. rect.width = 0
  9300. return rect
  9301. }
  9302. var isEqual = function (rect1, rect2) {
  9303. return (
  9304. rect1.left === rect2.left &&
  9305. rect1.top === rect2.top &&
  9306. rect1.bottom === rect2.bottom &&
  9307. rect1.right === rect2.right
  9308. )
  9309. }
  9310. var isValidOverflow = function (overflowY, rect1, rect2) {
  9311. return (
  9312. overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2
  9313. )
  9314. }
  9315. var isAbove$1 = function (rect1, rect2) {
  9316. var halfHeight = Math.min(rect2.height / 2, rect1.height / 2)
  9317. if (rect1.bottom - halfHeight < rect2.top) {
  9318. return true
  9319. }
  9320. if (rect1.top > rect2.bottom) {
  9321. return false
  9322. }
  9323. return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2)
  9324. }
  9325. var isBelow$1 = function (rect1, rect2) {
  9326. if (rect1.top > rect2.bottom) {
  9327. return true
  9328. }
  9329. if (rect1.bottom < rect2.top) {
  9330. return false
  9331. }
  9332. return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2)
  9333. }
  9334. var containsXY = function (rect, clientX, clientY) {
  9335. return (
  9336. clientX >= rect.left &&
  9337. clientX <= rect.right &&
  9338. clientY >= rect.top &&
  9339. clientY <= rect.bottom
  9340. )
  9341. }
  9342. var clamp$2 = function (value, min, max) {
  9343. return Math.min(Math.max(value, min), max)
  9344. }
  9345. var getSelectedNode = function (range) {
  9346. var startContainer = range.startContainer,
  9347. startOffset = range.startOffset
  9348. if (startContainer.hasChildNodes() && range.endOffset === startOffset + 1) {
  9349. return startContainer.childNodes[startOffset]
  9350. }
  9351. return null
  9352. }
  9353. var getNode$1 = function (container, offset) {
  9354. if (isElement$5(container) && container.hasChildNodes()) {
  9355. var childNodes = container.childNodes
  9356. var safeOffset = clamp$2(offset, 0, childNodes.length - 1)
  9357. return childNodes[safeOffset]
  9358. } else {
  9359. return container
  9360. }
  9361. }
  9362. var getNodeUnsafe = function (container, offset) {
  9363. if (offset < 0 && isElement$5(container) && container.hasChildNodes()) {
  9364. return undefined
  9365. } else {
  9366. return getNode$1(container, offset)
  9367. }
  9368. }
  9369. var extendingChars = new RegExp(
  9370. '[\u0300-\u036f\u0483-\u0487\u0488-\u0489\u0591-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u061a' +
  9371. '\u064b-\u065f\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0' +
  9372. '\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0902\u093a\u093c' +
  9373. '\u0941-\u0948\u094d\u0951-\u0957\u0962-\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2-\u09e3' +
  9374. '\u0a01-\u0a02\u0a3c\u0a41-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a51\u0a70-\u0a71\u0a75\u0a81-\u0a82\u0abc' +
  9375. '\u0ac1-\u0ac5\u0ac7-\u0ac8\u0acd\u0ae2-\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57' +
  9376. '\u0b62-\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c00\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56' +
  9377. '\u0c62-\u0c63\u0c81\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc-\u0ccd\u0cd5-\u0cd6\u0ce2-\u0ce3\u0d01\u0d3e\u0d41-\u0d44' +
  9378. '\u0d4d\u0d57\u0d62-\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9' +
  9379. '\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86-\u0f87\u0f8d-\u0f97' +
  9380. '\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039-\u103a\u103d-\u103e\u1058-\u1059\u105e-\u1060\u1071-\u1074' +
  9381. '\u1082\u1085-\u1086\u108d\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b4-\u17b5' +
  9382. '\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193b\u1a17-\u1a18' +
  9383. '\u1a1b\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1ab0-\u1abd\u1ABE\u1b00-\u1b03\u1b34' +
  9384. '\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80-\u1b81\u1ba2-\u1ba5\u1ba8-\u1ba9\u1bab-\u1bad\u1be6\u1be8-\u1be9' +
  9385. '\u1bed\u1bef-\u1bf1\u1c2c-\u1c33\u1c36-\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1cf4\u1cf8-\u1cf9' +
  9386. '\u1dc0-\u1df5\u1dfc-\u1dff\u200c-\u200d\u20d0-\u20dc\u20DD-\u20E0\u20e1\u20E2-\u20E4\u20e5-\u20f0\u2cef-\u2cf1' +
  9387. '\u2d7f\u2de0-\u2dff\u302a-\u302d\u302e-\u302f\u3099-\u309a\ua66f\uA670-\uA672\ua674-\ua67d\ua69e-\ua69f\ua6f0-\ua6f1' +
  9388. '\ua802\ua806\ua80b\ua825-\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc' +
  9389. '\ua9e5\uaa29-\uaa2e\uaa31-\uaa32\uaa35-\uaa36\uaa43\uaa4c\uaa7c\uaab0\uaab2-\uaab4\uaab7-\uaab8\uaabe-\uaabf\uaac1' +
  9390. '\uaaec-\uaaed\uaaf6\uabe5\uabe8\uabed\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\uff9e-\uff9f]'
  9391. )
  9392. var isExtendingChar = function (ch) {
  9393. return (
  9394. typeof ch === 'string' &&
  9395. ch.charCodeAt(0) >= 768 &&
  9396. extendingChars.test(ch)
  9397. )
  9398. }
  9399. var or = function () {
  9400. var args = []
  9401. for (var _i = 0; _i < arguments.length; _i++) {
  9402. args[_i] = arguments[_i]
  9403. }
  9404. return function (x) {
  9405. for (var i = 0; i < args.length; i++) {
  9406. if (args[i](x)) {
  9407. return true
  9408. }
  9409. }
  9410. return false
  9411. }
  9412. }
  9413. var and = function () {
  9414. var args = []
  9415. for (var _i = 0; _i < arguments.length; _i++) {
  9416. args[_i] = arguments[_i]
  9417. }
  9418. return function (x) {
  9419. for (var i = 0; i < args.length; i++) {
  9420. if (!args[i](x)) {
  9421. return false
  9422. }
  9423. }
  9424. return true
  9425. }
  9426. }
  9427. var isElement$3 = isElement$5
  9428. var isCaretCandidate$2 = isCaretCandidate$3
  9429. var isBlock$1 = matchStyleValues('display', 'block table')
  9430. var isFloated = matchStyleValues('float', 'left right')
  9431. var isValidElementCaretCandidate = and(
  9432. isElement$3,
  9433. isCaretCandidate$2,
  9434. not(isFloated)
  9435. )
  9436. var isNotPre = not(matchStyleValues('white-space', 'pre pre-line pre-wrap'))
  9437. var isText$4 = isText$7
  9438. var isBr$2 = isBr$5
  9439. var nodeIndex$1 = DOMUtils.nodeIndex
  9440. var resolveIndex$1 = getNodeUnsafe
  9441. var createRange$1 = function (doc) {
  9442. return 'createRange' in doc ? doc.createRange() : DOMUtils.DOM.createRng()
  9443. }
  9444. var isWhiteSpace$1 = function (chr) {
  9445. return chr && /[\r\n\t ]/.test(chr)
  9446. }
  9447. var isRange = function (rng) {
  9448. return !!rng.setStart && !!rng.setEnd
  9449. }
  9450. var isHiddenWhiteSpaceRange = function (range) {
  9451. var container = range.startContainer
  9452. var offset = range.startOffset
  9453. if (
  9454. isWhiteSpace$1(range.toString()) &&
  9455. isNotPre(container.parentNode) &&
  9456. isText$7(container)
  9457. ) {
  9458. var text = container.data
  9459. if (
  9460. isWhiteSpace$1(text[offset - 1]) ||
  9461. isWhiteSpace$1(text[offset + 1])
  9462. ) {
  9463. return true
  9464. }
  9465. }
  9466. return false
  9467. }
  9468. var getBrClientRect = function (brNode) {
  9469. var doc = brNode.ownerDocument
  9470. var rng = createRange$1(doc)
  9471. var nbsp$1 = doc.createTextNode(nbsp)
  9472. var parentNode = brNode.parentNode
  9473. parentNode.insertBefore(nbsp$1, brNode)
  9474. rng.setStart(nbsp$1, 0)
  9475. rng.setEnd(nbsp$1, 1)
  9476. var clientRect = clone(rng.getBoundingClientRect())
  9477. parentNode.removeChild(nbsp$1)
  9478. return clientRect
  9479. }
  9480. var getBoundingClientRectWebKitText = function (rng) {
  9481. var sc = rng.startContainer
  9482. var ec = rng.endContainer
  9483. var so = rng.startOffset
  9484. var eo = rng.endOffset
  9485. if (sc === ec && isText$7(ec) && so === 0 && eo === 1) {
  9486. var newRng = rng.cloneRange()
  9487. newRng.setEndAfter(ec)
  9488. return getBoundingClientRect$1(newRng)
  9489. } else {
  9490. return null
  9491. }
  9492. }
  9493. var isZeroRect = function (r) {
  9494. return r.left === 0 && r.right === 0 && r.top === 0 && r.bottom === 0
  9495. }
  9496. var getBoundingClientRect$1 = function (item) {
  9497. var clientRect
  9498. var clientRects = item.getClientRects()
  9499. if (clientRects.length > 0) {
  9500. clientRect = clone(clientRects[0])
  9501. } else {
  9502. clientRect = clone(item.getBoundingClientRect())
  9503. }
  9504. if (!isRange(item) && isBr$2(item) && isZeroRect(clientRect)) {
  9505. return getBrClientRect(item)
  9506. }
  9507. if (isZeroRect(clientRect) && isRange(item)) {
  9508. return getBoundingClientRectWebKitText(item)
  9509. }
  9510. return clientRect
  9511. }
  9512. var collapseAndInflateWidth = function (clientRect, toStart) {
  9513. var newClientRect = collapse(clientRect, toStart)
  9514. newClientRect.width = 1
  9515. newClientRect.right = newClientRect.left + 1
  9516. return newClientRect
  9517. }
  9518. var getCaretPositionClientRects = function (caretPosition) {
  9519. var clientRects = []
  9520. var addUniqueAndValidRect = function (clientRect) {
  9521. if (clientRect.height === 0) {
  9522. return
  9523. }
  9524. if (clientRects.length > 0) {
  9525. if (isEqual(clientRect, clientRects[clientRects.length - 1])) {
  9526. return
  9527. }
  9528. }
  9529. clientRects.push(clientRect)
  9530. }
  9531. var addCharacterOffset = function (container, offset) {
  9532. var range = createRange$1(container.ownerDocument)
  9533. if (offset < container.data.length) {
  9534. if (isExtendingChar(container.data[offset])) {
  9535. return clientRects
  9536. }
  9537. if (isExtendingChar(container.data[offset - 1])) {
  9538. range.setStart(container, offset)
  9539. range.setEnd(container, offset + 1)
  9540. if (!isHiddenWhiteSpaceRange(range)) {
  9541. addUniqueAndValidRect(
  9542. collapseAndInflateWidth(getBoundingClientRect$1(range), false)
  9543. )
  9544. return clientRects
  9545. }
  9546. }
  9547. }
  9548. if (offset > 0) {
  9549. range.setStart(container, offset - 1)
  9550. range.setEnd(container, offset)
  9551. if (!isHiddenWhiteSpaceRange(range)) {
  9552. addUniqueAndValidRect(
  9553. collapseAndInflateWidth(getBoundingClientRect$1(range), false)
  9554. )
  9555. }
  9556. }
  9557. if (offset < container.data.length) {
  9558. range.setStart(container, offset)
  9559. range.setEnd(container, offset + 1)
  9560. if (!isHiddenWhiteSpaceRange(range)) {
  9561. addUniqueAndValidRect(
  9562. collapseAndInflateWidth(getBoundingClientRect$1(range), true)
  9563. )
  9564. }
  9565. }
  9566. }
  9567. var container = caretPosition.container()
  9568. var offset = caretPosition.offset()
  9569. if (isText$4(container)) {
  9570. addCharacterOffset(container, offset)
  9571. return clientRects
  9572. }
  9573. if (isElement$3(container)) {
  9574. if (caretPosition.isAtEnd()) {
  9575. var node = resolveIndex$1(container, offset)
  9576. if (isText$4(node)) {
  9577. addCharacterOffset(node, node.data.length)
  9578. }
  9579. if (isValidElementCaretCandidate(node) && !isBr$2(node)) {
  9580. addUniqueAndValidRect(
  9581. collapseAndInflateWidth(getBoundingClientRect$1(node), false)
  9582. )
  9583. }
  9584. } else {
  9585. var node = resolveIndex$1(container, offset)
  9586. if (isText$4(node)) {
  9587. addCharacterOffset(node, 0)
  9588. }
  9589. if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) {
  9590. addUniqueAndValidRect(
  9591. collapseAndInflateWidth(getBoundingClientRect$1(node), false)
  9592. )
  9593. return clientRects
  9594. }
  9595. var beforeNode = resolveIndex$1(
  9596. caretPosition.container(),
  9597. caretPosition.offset() - 1
  9598. )
  9599. if (isValidElementCaretCandidate(beforeNode) && !isBr$2(beforeNode)) {
  9600. if (
  9601. isBlock$1(beforeNode) ||
  9602. isBlock$1(node) ||
  9603. !isValidElementCaretCandidate(node)
  9604. ) {
  9605. addUniqueAndValidRect(
  9606. collapseAndInflateWidth(
  9607. getBoundingClientRect$1(beforeNode),
  9608. false
  9609. )
  9610. )
  9611. }
  9612. }
  9613. if (isValidElementCaretCandidate(node)) {
  9614. addUniqueAndValidRect(
  9615. collapseAndInflateWidth(getBoundingClientRect$1(node), true)
  9616. )
  9617. }
  9618. }
  9619. }
  9620. return clientRects
  9621. }
  9622. var CaretPosition = function (container, offset, clientRects) {
  9623. var isAtStart = function () {
  9624. if (isText$4(container)) {
  9625. return offset === 0
  9626. }
  9627. return offset === 0
  9628. }
  9629. var isAtEnd = function () {
  9630. if (isText$4(container)) {
  9631. return offset >= container.data.length
  9632. }
  9633. return offset >= container.childNodes.length
  9634. }
  9635. var toRange = function () {
  9636. var range = createRange$1(container.ownerDocument)
  9637. range.setStart(container, offset)
  9638. range.setEnd(container, offset)
  9639. return range
  9640. }
  9641. var getClientRects = function () {
  9642. if (!clientRects) {
  9643. clientRects = getCaretPositionClientRects(
  9644. CaretPosition(container, offset)
  9645. )
  9646. }
  9647. return clientRects
  9648. }
  9649. var isVisible = function () {
  9650. return getClientRects().length > 0
  9651. }
  9652. var isEqual = function (caretPosition) {
  9653. return (
  9654. caretPosition &&
  9655. container === caretPosition.container() &&
  9656. offset === caretPosition.offset()
  9657. )
  9658. }
  9659. var getNode = function (before) {
  9660. return resolveIndex$1(container, before ? offset - 1 : offset)
  9661. }
  9662. return {
  9663. container: constant(container),
  9664. offset: constant(offset),
  9665. toRange: toRange,
  9666. getClientRects: getClientRects,
  9667. isVisible: isVisible,
  9668. isAtStart: isAtStart,
  9669. isAtEnd: isAtEnd,
  9670. isEqual: isEqual,
  9671. getNode: getNode,
  9672. }
  9673. }
  9674. CaretPosition.fromRangeStart = function (range) {
  9675. return CaretPosition(range.startContainer, range.startOffset)
  9676. }
  9677. CaretPosition.fromRangeEnd = function (range) {
  9678. return CaretPosition(range.endContainer, range.endOffset)
  9679. }
  9680. CaretPosition.after = function (node) {
  9681. return CaretPosition(node.parentNode, nodeIndex$1(node) + 1)
  9682. }
  9683. CaretPosition.before = function (node) {
  9684. return CaretPosition(node.parentNode, nodeIndex$1(node))
  9685. }
  9686. CaretPosition.isAbove = function (pos1, pos2) {
  9687. return lift2(
  9688. head(pos2.getClientRects()),
  9689. last$2(pos1.getClientRects()),
  9690. isAbove$1
  9691. ).getOr(false)
  9692. }
  9693. CaretPosition.isBelow = function (pos1, pos2) {
  9694. return lift2(
  9695. last$2(pos2.getClientRects()),
  9696. head(pos1.getClientRects()),
  9697. isBelow$1
  9698. ).getOr(false)
  9699. }
  9700. CaretPosition.isAtStart = function (pos) {
  9701. return pos ? pos.isAtStart() : false
  9702. }
  9703. CaretPosition.isAtEnd = function (pos) {
  9704. return pos ? pos.isAtEnd() : false
  9705. }
  9706. CaretPosition.isTextPosition = function (pos) {
  9707. return pos ? isText$7(pos.container()) : false
  9708. }
  9709. CaretPosition.isElementPosition = function (pos) {
  9710. return CaretPosition.isTextPosition(pos) === false
  9711. }
  9712. var trimEmptyTextNode$1 = function (dom, node) {
  9713. if (isText$7(node) && node.data.length === 0) {
  9714. dom.remove(node)
  9715. }
  9716. }
  9717. var insertNode = function (dom, rng, node) {
  9718. rng.insertNode(node)
  9719. trimEmptyTextNode$1(dom, node.previousSibling)
  9720. trimEmptyTextNode$1(dom, node.nextSibling)
  9721. }
  9722. var insertFragment = function (dom, rng, frag) {
  9723. var firstChild = Optional.from(frag.firstChild)
  9724. var lastChild = Optional.from(frag.lastChild)
  9725. rng.insertNode(frag)
  9726. firstChild.each(function (child) {
  9727. return trimEmptyTextNode$1(dom, child.previousSibling)
  9728. })
  9729. lastChild.each(function (child) {
  9730. return trimEmptyTextNode$1(dom, child.nextSibling)
  9731. })
  9732. }
  9733. var rangeInsertNode = function (dom, rng, node) {
  9734. if (isDocumentFragment(node)) {
  9735. insertFragment(dom, rng, node)
  9736. } else {
  9737. insertNode(dom, rng, node)
  9738. }
  9739. }
  9740. var isText$3 = isText$7
  9741. var isBogus = isBogus$2
  9742. var nodeIndex = DOMUtils.nodeIndex
  9743. var normalizedParent = function (node) {
  9744. var parentNode = node.parentNode
  9745. if (isBogus(parentNode)) {
  9746. return normalizedParent(parentNode)
  9747. }
  9748. return parentNode
  9749. }
  9750. var getChildNodes = function (node) {
  9751. if (!node) {
  9752. return []
  9753. }
  9754. return reduce(
  9755. node.childNodes,
  9756. function (result, node) {
  9757. if (isBogus(node) && node.nodeName !== 'BR') {
  9758. result = result.concat(getChildNodes(node))
  9759. } else {
  9760. result.push(node)
  9761. }
  9762. return result
  9763. },
  9764. []
  9765. )
  9766. }
  9767. var normalizedTextOffset = function (node, offset) {
  9768. while ((node = node.previousSibling)) {
  9769. if (!isText$3(node)) {
  9770. break
  9771. }
  9772. offset += node.data.length
  9773. }
  9774. return offset
  9775. }
  9776. var equal = function (a) {
  9777. return function (b) {
  9778. return a === b
  9779. }
  9780. }
  9781. var normalizedNodeIndex = function (node) {
  9782. var nodes, index
  9783. nodes = getChildNodes(normalizedParent(node))
  9784. index = findIndex$1(nodes, equal(node), node)
  9785. nodes = nodes.slice(0, index + 1)
  9786. var numTextFragments = reduce(
  9787. nodes,
  9788. function (result, node, i) {
  9789. if (isText$3(node) && isText$3(nodes[i - 1])) {
  9790. result++
  9791. }
  9792. return result
  9793. },
  9794. 0
  9795. )
  9796. nodes = filter$2(nodes, matchNodeNames([node.nodeName]))
  9797. index = findIndex$1(nodes, equal(node), node)
  9798. return index - numTextFragments
  9799. }
  9800. var createPathItem = function (node) {
  9801. var name
  9802. if (isText$3(node)) {
  9803. name = 'text()'
  9804. } else {
  9805. name = node.nodeName.toLowerCase()
  9806. }
  9807. return name + '[' + normalizedNodeIndex(node) + ']'
  9808. }
  9809. var parentsUntil$1 = function (root, node, predicate) {
  9810. var parents = []
  9811. for (node = node.parentNode; node !== root; node = node.parentNode) {
  9812. if (predicate && predicate(node)) {
  9813. break
  9814. }
  9815. parents.push(node)
  9816. }
  9817. return parents
  9818. }
  9819. var create$6 = function (root, caretPosition) {
  9820. var container,
  9821. offset,
  9822. path = [],
  9823. outputOffset,
  9824. childNodes,
  9825. parents
  9826. container = caretPosition.container()
  9827. offset = caretPosition.offset()
  9828. if (isText$3(container)) {
  9829. outputOffset = normalizedTextOffset(container, offset)
  9830. } else {
  9831. childNodes = container.childNodes
  9832. if (offset >= childNodes.length) {
  9833. outputOffset = 'after'
  9834. offset = childNodes.length - 1
  9835. } else {
  9836. outputOffset = 'before'
  9837. }
  9838. container = childNodes[offset]
  9839. }
  9840. path.push(createPathItem(container))
  9841. parents = parentsUntil$1(root, container)
  9842. parents = filter$2(parents, not(isBogus$2))
  9843. path = path.concat(
  9844. map$1(parents, function (node) {
  9845. return createPathItem(node)
  9846. })
  9847. )
  9848. return path.reverse().join('/') + ',' + outputOffset
  9849. }
  9850. var resolvePathItem = function (node, name, index) {
  9851. var nodes = getChildNodes(node)
  9852. nodes = filter$2(nodes, function (node, index) {
  9853. return !isText$3(node) || !isText$3(nodes[index - 1])
  9854. })
  9855. nodes = filter$2(nodes, matchNodeNames([name]))
  9856. return nodes[index]
  9857. }
  9858. var findTextPosition = function (container, offset) {
  9859. var node = container,
  9860. targetOffset = 0,
  9861. dataLen
  9862. while (isText$3(node)) {
  9863. dataLen = node.data.length
  9864. if (offset >= targetOffset && offset <= targetOffset + dataLen) {
  9865. container = node
  9866. offset = offset - targetOffset
  9867. break
  9868. }
  9869. if (!isText$3(node.nextSibling)) {
  9870. container = node
  9871. offset = dataLen
  9872. break
  9873. }
  9874. targetOffset += dataLen
  9875. node = node.nextSibling
  9876. }
  9877. if (isText$3(container) && offset > container.data.length) {
  9878. offset = container.data.length
  9879. }
  9880. return CaretPosition(container, offset)
  9881. }
  9882. var resolve$2 = function (root, path) {
  9883. var offset
  9884. if (!path) {
  9885. return null
  9886. }
  9887. var parts = path.split(',')
  9888. var paths = parts[0].split('/')
  9889. offset = parts.length > 1 ? parts[1] : 'before'
  9890. var container = reduce(
  9891. paths,
  9892. function (result, value) {
  9893. var match = /([\w\-\(\)]+)\[([0-9]+)\]/.exec(value)
  9894. if (!match) {
  9895. return null
  9896. }
  9897. if (match[1] === 'text()') {
  9898. match[1] = '#text'
  9899. }
  9900. return resolvePathItem(result, match[1], parseInt(match[2], 10))
  9901. },
  9902. root
  9903. )
  9904. if (!container) {
  9905. return null
  9906. }
  9907. if (!isText$3(container)) {
  9908. if (offset === 'after') {
  9909. offset = nodeIndex(container) + 1
  9910. } else {
  9911. offset = nodeIndex(container)
  9912. }
  9913. return CaretPosition(container.parentNode, offset)
  9914. }
  9915. return findTextPosition(container, parseInt(offset, 10))
  9916. }
  9917. var isContentEditableFalse$9 = isContentEditableFalse$b
  9918. var getNormalizedTextOffset = function (trim, container, offset) {
  9919. var node, trimmedOffset
  9920. trimmedOffset = trim(container.data.slice(0, offset)).length
  9921. for (
  9922. node = container.previousSibling;
  9923. node && isText$7(node);
  9924. node = node.previousSibling
  9925. ) {
  9926. trimmedOffset += trim(node.data).length
  9927. }
  9928. return trimmedOffset
  9929. }
  9930. var getPoint = function (dom, trim, normalized, rng, start) {
  9931. var container = rng[start ? 'startContainer' : 'endContainer']
  9932. var offset = rng[start ? 'startOffset' : 'endOffset']
  9933. var point = []
  9934. var childNodes,
  9935. after = 0
  9936. var root = dom.getRoot()
  9937. if (isText$7(container)) {
  9938. point.push(
  9939. normalized ? getNormalizedTextOffset(trim, container, offset) : offset
  9940. )
  9941. } else {
  9942. childNodes = container.childNodes
  9943. if (offset >= childNodes.length && childNodes.length) {
  9944. after = 1
  9945. offset = Math.max(0, childNodes.length - 1)
  9946. }
  9947. point.push(dom.nodeIndex(childNodes[offset], normalized) + after)
  9948. }
  9949. for (; container && container !== root; container = container.parentNode) {
  9950. point.push(dom.nodeIndex(container, normalized))
  9951. }
  9952. return point
  9953. }
  9954. var getLocation = function (trim, selection, normalized, rng) {
  9955. var dom = selection.dom,
  9956. bookmark = {}
  9957. bookmark.start = getPoint(dom, trim, normalized, rng, true)
  9958. if (!selection.isCollapsed()) {
  9959. bookmark.end = getPoint(dom, trim, normalized, rng, false)
  9960. }
  9961. if (isRangeInCaretContainerBlock(rng)) {
  9962. bookmark.isFakeCaret = true
  9963. }
  9964. return bookmark
  9965. }
  9966. var findIndex = function (dom, name, element) {
  9967. var count = 0
  9968. Tools.each(dom.select(name), function (node) {
  9969. if (node.getAttribute('data-mce-bogus') === 'all') {
  9970. return
  9971. }
  9972. if (node === element) {
  9973. return false
  9974. }
  9975. count++
  9976. })
  9977. return count
  9978. }
  9979. var moveEndPoint$1 = function (rng, start) {
  9980. var container, offset, childNodes
  9981. var prefix = start ? 'start' : 'end'
  9982. container = rng[prefix + 'Container']
  9983. offset = rng[prefix + 'Offset']
  9984. if (isElement$5(container) && container.nodeName === 'TR') {
  9985. childNodes = container.childNodes
  9986. container =
  9987. childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)]
  9988. if (container) {
  9989. offset = start ? 0 : container.childNodes.length
  9990. rng['set' + (start ? 'Start' : 'End')](container, offset)
  9991. }
  9992. }
  9993. }
  9994. var normalizeTableCellSelection = function (rng) {
  9995. moveEndPoint$1(rng, true)
  9996. moveEndPoint$1(rng, false)
  9997. return rng
  9998. }
  9999. var findSibling = function (node, offset) {
  10000. var sibling
  10001. if (isElement$5(node)) {
  10002. node = getNode$1(node, offset)
  10003. if (isContentEditableFalse$9(node)) {
  10004. return node
  10005. }
  10006. }
  10007. if (isCaretContainer$2(node)) {
  10008. if (isText$7(node) && isCaretContainerBlock$1(node)) {
  10009. node = node.parentNode
  10010. }
  10011. sibling = node.previousSibling
  10012. if (isContentEditableFalse$9(sibling)) {
  10013. return sibling
  10014. }
  10015. sibling = node.nextSibling
  10016. if (isContentEditableFalse$9(sibling)) {
  10017. return sibling
  10018. }
  10019. }
  10020. }
  10021. var findAdjacentContentEditableFalseElm = function (rng) {
  10022. return (
  10023. findSibling(rng.startContainer, rng.startOffset) ||
  10024. findSibling(rng.endContainer, rng.endOffset)
  10025. )
  10026. }
  10027. var getOffsetBookmark = function (trim, normalized, selection) {
  10028. var element = selection.getNode()
  10029. var name = element ? element.nodeName : null
  10030. var rng = selection.getRng()
  10031. if (isContentEditableFalse$9(element) || name === 'IMG') {
  10032. return {
  10033. name: name,
  10034. index: findIndex(selection.dom, name, element),
  10035. }
  10036. }
  10037. var sibling = findAdjacentContentEditableFalseElm(rng)
  10038. if (sibling) {
  10039. name = sibling.tagName
  10040. return {
  10041. name: name,
  10042. index: findIndex(selection.dom, name, sibling),
  10043. }
  10044. }
  10045. return getLocation(trim, selection, normalized, rng)
  10046. }
  10047. var getCaretBookmark = function (selection) {
  10048. var rng = selection.getRng()
  10049. return {
  10050. start: create$6(
  10051. selection.dom.getRoot(),
  10052. CaretPosition.fromRangeStart(rng)
  10053. ),
  10054. end: create$6(selection.dom.getRoot(), CaretPosition.fromRangeEnd(rng)),
  10055. }
  10056. }
  10057. var getRangeBookmark = function (selection) {
  10058. return { rng: selection.getRng() }
  10059. }
  10060. var createBookmarkSpan = function (dom, id, filled) {
  10061. var args = {
  10062. 'data-mce-type': 'bookmark',
  10063. id: id,
  10064. style: 'overflow:hidden;line-height:0px',
  10065. }
  10066. return filled
  10067. ? dom.create('span', args, '&#xFEFF;')
  10068. : dom.create('span', args)
  10069. }
  10070. var getPersistentBookmark = function (selection, filled) {
  10071. var dom = selection.dom
  10072. var rng = selection.getRng()
  10073. var id = dom.uniqueId()
  10074. var collapsed = selection.isCollapsed()
  10075. var element = selection.getNode()
  10076. var name = element.nodeName
  10077. if (name === 'IMG') {
  10078. return {
  10079. name: name,
  10080. index: findIndex(dom, name, element),
  10081. }
  10082. }
  10083. var rng2 = normalizeTableCellSelection(rng.cloneRange())
  10084. if (!collapsed) {
  10085. rng2.collapse(false)
  10086. var endBookmarkNode = createBookmarkSpan(dom, id + '_end', filled)
  10087. rangeInsertNode(dom, rng2, endBookmarkNode)
  10088. }
  10089. rng = normalizeTableCellSelection(rng)
  10090. rng.collapse(true)
  10091. var startBookmarkNode = createBookmarkSpan(dom, id + '_start', filled)
  10092. rangeInsertNode(dom, rng, startBookmarkNode)
  10093. selection.moveToBookmark({
  10094. id: id,
  10095. keep: true,
  10096. })
  10097. return { id: id }
  10098. }
  10099. var getBookmark$2 = function (selection, type, normalized) {
  10100. if (type === 2) {
  10101. return getOffsetBookmark(trim$2, normalized, selection)
  10102. } else if (type === 3) {
  10103. return getCaretBookmark(selection)
  10104. } else if (type) {
  10105. return getRangeBookmark(selection)
  10106. } else {
  10107. return getPersistentBookmark(selection, false)
  10108. }
  10109. }
  10110. var getUndoBookmark = curry(getOffsetBookmark, identity, true)
  10111. var DOM$9 = DOMUtils.DOM
  10112. var defaultPreviewStyles =
  10113. 'font-family font-size font-weight font-style text-decoration text-transform color background-color border border-radius outline text-shadow'
  10114. var getBodySetting = function (editor, name, defaultValue) {
  10115. var value = editor.getParam(name, defaultValue)
  10116. if (value.indexOf('=') !== -1) {
  10117. var bodyObj = editor.getParam(name, '', 'hash')
  10118. return get$9(bodyObj, editor.id).getOr(defaultValue)
  10119. } else {
  10120. return value
  10121. }
  10122. }
  10123. var getIframeAttrs = function (editor) {
  10124. return editor.getParam('iframe_attrs', {})
  10125. }
  10126. var getDocType = function (editor) {
  10127. return editor.getParam('doctype', '<!DOCTYPE html>')
  10128. }
  10129. var getDocumentBaseUrl = function (editor) {
  10130. return editor.getParam('document_base_url', '')
  10131. }
  10132. var getBodyId = function (editor) {
  10133. return getBodySetting(editor, 'body_id', 'tinymce')
  10134. }
  10135. var getBodyClass = function (editor) {
  10136. return getBodySetting(editor, 'body_class', '')
  10137. }
  10138. var getContentSecurityPolicy = function (editor) {
  10139. return editor.getParam('content_security_policy', '')
  10140. }
  10141. var shouldPutBrInPre$1 = function (editor) {
  10142. return editor.getParam('br_in_pre', true)
  10143. }
  10144. var getForcedRootBlock = function (editor) {
  10145. if (editor.getParam('force_p_newlines', false)) {
  10146. return 'p'
  10147. }
  10148. var block = editor.getParam('forced_root_block', 'p')
  10149. if (block === false) {
  10150. return ''
  10151. } else if (block === true) {
  10152. return 'p'
  10153. } else {
  10154. return block
  10155. }
  10156. }
  10157. var getForcedRootBlockAttrs = function (editor) {
  10158. return editor.getParam('forced_root_block_attrs', {})
  10159. }
  10160. var getBrNewLineSelector = function (editor) {
  10161. return editor.getParam(
  10162. 'br_newline_selector',
  10163. '.mce-toc h2,figcaption,caption'
  10164. )
  10165. }
  10166. var getNoNewLineSelector = function (editor) {
  10167. return editor.getParam('no_newline_selector', '')
  10168. }
  10169. var shouldKeepStyles = function (editor) {
  10170. return editor.getParam('keep_styles', true)
  10171. }
  10172. var shouldEndContainerOnEmptyBlock = function (editor) {
  10173. return editor.getParam('end_container_on_empty_block', false)
  10174. }
  10175. var getFontStyleValues = function (editor) {
  10176. return Tools.explode(
  10177. editor.getParam(
  10178. 'font_size_style_values',
  10179. 'xx-small,x-small,small,medium,large,x-large,xx-large'
  10180. )
  10181. )
  10182. }
  10183. var getFontSizeClasses = function (editor) {
  10184. return Tools.explode(editor.getParam('font_size_classes', ''))
  10185. }
  10186. var getImagesDataImgFilter = function (editor) {
  10187. return editor.getParam('images_dataimg_filter', always, 'function')
  10188. }
  10189. var isAutomaticUploadsEnabled = function (editor) {
  10190. return editor.getParam('automatic_uploads', true, 'boolean')
  10191. }
  10192. var shouldReuseFileName = function (editor) {
  10193. return editor.getParam('images_reuse_filename', false, 'boolean')
  10194. }
  10195. var shouldReplaceBlobUris = function (editor) {
  10196. return editor.getParam('images_replace_blob_uris', true, 'boolean')
  10197. }
  10198. var getIconPackName = function (editor) {
  10199. return editor.getParam('icons', '', 'string')
  10200. }
  10201. var getIconsUrl = function (editor) {
  10202. return editor.getParam('icons_url', '', 'string')
  10203. }
  10204. var getImageUploadUrl = function (editor) {
  10205. return editor.getParam('images_upload_url', '', 'string')
  10206. }
  10207. var getImageUploadBasePath = function (editor) {
  10208. return editor.getParam('images_upload_base_path', '', 'string')
  10209. }
  10210. var getImagesUploadCredentials = function (editor) {
  10211. return editor.getParam('images_upload_credentials', false, 'boolean')
  10212. }
  10213. var getImagesUploadHandler = function (editor) {
  10214. return editor.getParam('images_upload_handler', null, 'function')
  10215. }
  10216. var shouldUseContentCssCors = function (editor) {
  10217. return editor.getParam('content_css_cors', false, 'boolean')
  10218. }
  10219. var getReferrerPolicy = function (editor) {
  10220. return editor.getParam('referrer_policy', '', 'string')
  10221. }
  10222. var getLanguageCode = function (editor) {
  10223. return editor.getParam('language', 'en', 'string')
  10224. }
  10225. var getLanguageUrl = function (editor) {
  10226. return editor.getParam('language_url', '', 'string')
  10227. }
  10228. var shouldIndentUseMargin = function (editor) {
  10229. return editor.getParam('indent_use_margin', false)
  10230. }
  10231. var getIndentation = function (editor) {
  10232. return editor.getParam('indentation', '40px', 'string')
  10233. }
  10234. var getContentCss = function (editor) {
  10235. var contentCss = editor.getParam('content_css')
  10236. if (isString$1(contentCss)) {
  10237. return map$3(contentCss.split(','), trim$4)
  10238. } else if (isArray$1(contentCss)) {
  10239. return contentCss
  10240. } else if (contentCss === false || editor.inline) {
  10241. return []
  10242. } else {
  10243. return ['default']
  10244. }
  10245. }
  10246. var getFontCss = function (editor) {
  10247. var fontCss = editor.getParam('font_css', [])
  10248. return isArray$1(fontCss) ? fontCss : map$3(fontCss.split(','), trim$4)
  10249. }
  10250. var getDirectionality = function (editor) {
  10251. return editor.getParam('directionality', I18n.isRtl() ? 'rtl' : undefined)
  10252. }
  10253. var getInlineBoundarySelector = function (editor) {
  10254. return editor.getParam(
  10255. 'inline_boundaries_selector',
  10256. 'a[href],code,.mce-annotation',
  10257. 'string'
  10258. )
  10259. }
  10260. var getObjectResizing = function (editor) {
  10261. var selector = editor.getParam('object_resizing')
  10262. if (selector === false || Env.iOS) {
  10263. return false
  10264. } else {
  10265. return isString$1(selector)
  10266. ? selector
  10267. : 'table,img,figure.image,div,video,iframe'
  10268. }
  10269. }
  10270. var getResizeImgProportional = function (editor) {
  10271. return editor.getParam('resize_img_proportional', true, 'boolean')
  10272. }
  10273. var getPlaceholder = function (editor) {
  10274. return editor.getParam(
  10275. 'placeholder',
  10276. DOM$9.getAttrib(editor.getElement(), 'placeholder'),
  10277. 'string'
  10278. )
  10279. }
  10280. var getEventRoot = function (editor) {
  10281. return editor.getParam('event_root')
  10282. }
  10283. var getServiceMessage = function (editor) {
  10284. return editor.getParam('service_message')
  10285. }
  10286. var getTheme = function (editor) {
  10287. return editor.getParam('theme')
  10288. }
  10289. var shouldValidate = function (editor) {
  10290. return editor.getParam('validate')
  10291. }
  10292. var isInlineBoundariesEnabled = function (editor) {
  10293. return editor.getParam('inline_boundaries') !== false
  10294. }
  10295. var getFormats = function (editor) {
  10296. return editor.getParam('formats')
  10297. }
  10298. var getPreviewStyles = function (editor) {
  10299. var style = editor.getParam('preview_styles', defaultPreviewStyles)
  10300. if (isString$1(style)) {
  10301. return style
  10302. } else {
  10303. return ''
  10304. }
  10305. }
  10306. var canFormatEmptyLines = function (editor) {
  10307. return editor.getParam('format_empty_lines', false, 'boolean')
  10308. }
  10309. var getCustomUiSelector = function (editor) {
  10310. return editor.getParam('custom_ui_selector', '', 'string')
  10311. }
  10312. var getThemeUrl = function (editor) {
  10313. return editor.getParam('theme_url')
  10314. }
  10315. var isInline = function (editor) {
  10316. return editor.getParam('inline')
  10317. }
  10318. var hasHiddenInput = function (editor) {
  10319. return editor.getParam('hidden_input')
  10320. }
  10321. var shouldPatchSubmit = function (editor) {
  10322. return editor.getParam('submit_patch')
  10323. }
  10324. var isEncodingXml = function (editor) {
  10325. return editor.getParam('encoding') === 'xml'
  10326. }
  10327. var shouldAddFormSubmitTrigger = function (editor) {
  10328. return editor.getParam('add_form_submit_trigger')
  10329. }
  10330. var shouldAddUnloadTrigger = function (editor) {
  10331. return editor.getParam('add_unload_trigger')
  10332. }
  10333. var hasForcedRootBlock = function (editor) {
  10334. return getForcedRootBlock(editor) !== ''
  10335. }
  10336. var getCustomUndoRedoLevels = function (editor) {
  10337. return editor.getParam('custom_undo_redo_levels', 0, 'number')
  10338. }
  10339. var shouldDisableNodeChange = function (editor) {
  10340. return editor.getParam('disable_nodechange')
  10341. }
  10342. var isReadOnly$1 = function (editor) {
  10343. return editor.getParam('readonly')
  10344. }
  10345. var hasContentCssCors = function (editor) {
  10346. return editor.getParam('content_css_cors')
  10347. }
  10348. var getPlugins = function (editor) {
  10349. return editor.getParam('plugins', '', 'string')
  10350. }
  10351. var getExternalPlugins$1 = function (editor) {
  10352. return editor.getParam('external_plugins')
  10353. }
  10354. var shouldBlockUnsupportedDrop = function (editor) {
  10355. return editor.getParam('block_unsupported_drop', true, 'boolean')
  10356. }
  10357. var isVisualAidsEnabled = function (editor) {
  10358. return editor.getParam('visual', true, 'boolean')
  10359. }
  10360. var getVisualAidsTableClass = function (editor) {
  10361. return editor.getParam('visual_table_class', 'mce-item-table', 'string')
  10362. }
  10363. var getVisualAidsAnchorClass = function (editor) {
  10364. return editor.getParam('visual_anchor_class', 'mce-item-anchor', 'string')
  10365. }
  10366. var getIframeAriaText = function (editor) {
  10367. return editor.getParam(
  10368. 'iframe_aria_text',
  10369. 'Rich Text Area. Press ALT-0 for help.',
  10370. 'string'
  10371. )
  10372. }
  10373. var isElement$2 = isElement$5
  10374. var isText$2 = isText$7
  10375. var removeNode$1 = function (node) {
  10376. var parentNode = node.parentNode
  10377. if (parentNode) {
  10378. parentNode.removeChild(node)
  10379. }
  10380. }
  10381. var trimCount = function (text) {
  10382. var trimmedText = trim$2(text)
  10383. return {
  10384. count: text.length - trimmedText.length,
  10385. text: trimmedText,
  10386. }
  10387. }
  10388. var deleteZwspChars = function (caretContainer) {
  10389. var idx
  10390. while ((idx = caretContainer.data.lastIndexOf(ZWSP$1)) !== -1) {
  10391. caretContainer.deleteData(idx, 1)
  10392. }
  10393. }
  10394. var removeUnchanged = function (caretContainer, pos) {
  10395. remove$2(caretContainer)
  10396. return pos
  10397. }
  10398. var removeTextAndReposition = function (caretContainer, pos) {
  10399. var before = trimCount(caretContainer.data.substr(0, pos.offset()))
  10400. var after = trimCount(caretContainer.data.substr(pos.offset()))
  10401. var text = before.text + after.text
  10402. if (text.length > 0) {
  10403. deleteZwspChars(caretContainer)
  10404. return CaretPosition(caretContainer, pos.offset() - before.count)
  10405. } else {
  10406. return pos
  10407. }
  10408. }
  10409. var removeElementAndReposition = function (caretContainer, pos) {
  10410. var parentNode = pos.container()
  10411. var newPosition = indexOf$2(from(parentNode.childNodes), caretContainer)
  10412. .map(function (index) {
  10413. return index < pos.offset()
  10414. ? CaretPosition(parentNode, pos.offset() - 1)
  10415. : pos
  10416. })
  10417. .getOr(pos)
  10418. remove$2(caretContainer)
  10419. return newPosition
  10420. }
  10421. var removeTextCaretContainer = function (caretContainer, pos) {
  10422. return isText$2(caretContainer) && pos.container() === caretContainer
  10423. ? removeTextAndReposition(caretContainer, pos)
  10424. : removeUnchanged(caretContainer, pos)
  10425. }
  10426. var removeElementCaretContainer = function (caretContainer, pos) {
  10427. return pos.container() === caretContainer.parentNode
  10428. ? removeElementAndReposition(caretContainer, pos)
  10429. : removeUnchanged(caretContainer, pos)
  10430. }
  10431. var removeAndReposition = function (container, pos) {
  10432. return CaretPosition.isTextPosition(pos)
  10433. ? removeTextCaretContainer(container, pos)
  10434. : removeElementCaretContainer(container, pos)
  10435. }
  10436. var remove$2 = function (caretContainerNode) {
  10437. if (
  10438. isElement$2(caretContainerNode) &&
  10439. isCaretContainer$2(caretContainerNode)
  10440. ) {
  10441. if (hasContent(caretContainerNode)) {
  10442. caretContainerNode.removeAttribute('data-mce-caret')
  10443. } else {
  10444. removeNode$1(caretContainerNode)
  10445. }
  10446. }
  10447. if (isText$2(caretContainerNode)) {
  10448. deleteZwspChars(caretContainerNode)
  10449. if (caretContainerNode.data.length === 0) {
  10450. removeNode$1(caretContainerNode)
  10451. }
  10452. }
  10453. }
  10454. var browser$2 = detect().browser
  10455. var isContentEditableFalse$8 = isContentEditableFalse$b
  10456. var isMedia$1 = isMedia$2
  10457. var isTableCell$3 = isTableCell$5
  10458. var inlineFakeCaretSelector =
  10459. '*[contentEditable=false],video,audio,embed,object'
  10460. var getAbsoluteClientRect = function (root, element, before) {
  10461. var clientRect = collapse(element.getBoundingClientRect(), before)
  10462. var scrollX
  10463. var scrollY
  10464. if (root.tagName === 'BODY') {
  10465. var docElm = root.ownerDocument.documentElement
  10466. scrollX = root.scrollLeft || docElm.scrollLeft
  10467. scrollY = root.scrollTop || docElm.scrollTop
  10468. } else {
  10469. var rootRect = root.getBoundingClientRect()
  10470. scrollX = root.scrollLeft - rootRect.left
  10471. scrollY = root.scrollTop - rootRect.top
  10472. }
  10473. clientRect.left += scrollX
  10474. clientRect.right += scrollX
  10475. clientRect.top += scrollY
  10476. clientRect.bottom += scrollY
  10477. clientRect.width = 1
  10478. var margin = element.offsetWidth - element.clientWidth
  10479. if (margin > 0) {
  10480. if (before) {
  10481. margin *= -1
  10482. }
  10483. clientRect.left += margin
  10484. clientRect.right += margin
  10485. }
  10486. return clientRect
  10487. }
  10488. var trimInlineCaretContainers = function (root) {
  10489. var fakeCaretTargetNodes = descendants(
  10490. SugarElement.fromDom(root),
  10491. inlineFakeCaretSelector
  10492. )
  10493. for (var i = 0; i < fakeCaretTargetNodes.length; i++) {
  10494. var node = fakeCaretTargetNodes[i].dom
  10495. var sibling = node.previousSibling
  10496. if (endsWithCaretContainer$1(sibling)) {
  10497. var data = sibling.data
  10498. if (data.length === 1) {
  10499. sibling.parentNode.removeChild(sibling)
  10500. } else {
  10501. sibling.deleteData(data.length - 1, 1)
  10502. }
  10503. }
  10504. sibling = node.nextSibling
  10505. if (startsWithCaretContainer$1(sibling)) {
  10506. var data = sibling.data
  10507. if (data.length === 1) {
  10508. sibling.parentNode.removeChild(sibling)
  10509. } else {
  10510. sibling.deleteData(0, 1)
  10511. }
  10512. }
  10513. }
  10514. }
  10515. var FakeCaret = function (editor, root, isBlock, hasFocus) {
  10516. var lastVisualCaret = value()
  10517. var cursorInterval
  10518. var caretContainerNode
  10519. var rootBlock = getForcedRootBlock(editor)
  10520. var caretBlock = rootBlock.length > 0 ? rootBlock : 'p'
  10521. var show = function (before, element) {
  10522. var rng
  10523. hide()
  10524. if (isTableCell$3(element)) {
  10525. return null
  10526. }
  10527. if (isBlock(element)) {
  10528. caretContainerNode = insertBlock$1(caretBlock, element, before)
  10529. var clientRect = getAbsoluteClientRect(root, element, before)
  10530. DomQuery(caretContainerNode).css('top', clientRect.top)
  10531. var caret = DomQuery(
  10532. '<div class="mce-visual-caret" data-mce-bogus="all"></div>'
  10533. )
  10534. .css(__assign({}, clientRect))
  10535. .appendTo(root)[0]
  10536. lastVisualCaret.set({
  10537. caret: caret,
  10538. element: element,
  10539. before: before,
  10540. })
  10541. if (before) {
  10542. DomQuery(caret).addClass('mce-visual-caret-before')
  10543. }
  10544. startBlink()
  10545. rng = element.ownerDocument.createRange()
  10546. rng.setStart(caretContainerNode, 0)
  10547. rng.setEnd(caretContainerNode, 0)
  10548. } else {
  10549. caretContainerNode = insertInline$1(element, before)
  10550. rng = element.ownerDocument.createRange()
  10551. if (isInlineFakeCaretTarget(caretContainerNode.nextSibling)) {
  10552. rng.setStart(caretContainerNode, 0)
  10553. rng.setEnd(caretContainerNode, 0)
  10554. } else {
  10555. rng.setStart(caretContainerNode, 1)
  10556. rng.setEnd(caretContainerNode, 1)
  10557. }
  10558. return rng
  10559. }
  10560. return rng
  10561. }
  10562. var hide = function () {
  10563. trimInlineCaretContainers(root)
  10564. if (caretContainerNode) {
  10565. remove$2(caretContainerNode)
  10566. caretContainerNode = null
  10567. }
  10568. lastVisualCaret.on(function (caretState) {
  10569. DomQuery(caretState.caret).remove()
  10570. lastVisualCaret.clear()
  10571. })
  10572. if (cursorInterval) {
  10573. Delay.clearInterval(cursorInterval)
  10574. cursorInterval = undefined
  10575. }
  10576. }
  10577. var startBlink = function () {
  10578. cursorInterval = Delay.setInterval(function () {
  10579. if (hasFocus()) {
  10580. DomQuery('div.mce-visual-caret', root).toggleClass(
  10581. 'mce-visual-caret-hidden'
  10582. )
  10583. } else {
  10584. DomQuery('div.mce-visual-caret', root).addClass(
  10585. 'mce-visual-caret-hidden'
  10586. )
  10587. }
  10588. }, 500)
  10589. }
  10590. var reposition = function () {
  10591. lastVisualCaret.on(function (caretState) {
  10592. var clientRect = getAbsoluteClientRect(
  10593. root,
  10594. caretState.element,
  10595. caretState.before
  10596. )
  10597. DomQuery(caretState.caret).css(__assign({}, clientRect))
  10598. })
  10599. }
  10600. var destroy = function () {
  10601. return Delay.clearInterval(cursorInterval)
  10602. }
  10603. var getCss = function () {
  10604. return (
  10605. '.mce-visual-caret {' +
  10606. 'position: absolute;' +
  10607. 'background-color: black;' +
  10608. 'background-color: currentcolor;' +
  10609. '}' +
  10610. '.mce-visual-caret-hidden {' +
  10611. 'display: none;' +
  10612. '}' +
  10613. '*[data-mce-caret] {' +
  10614. 'position: absolute;' +
  10615. 'left: -1000px;' +
  10616. 'right: auto;' +
  10617. 'top: 0;' +
  10618. 'margin: 0;' +
  10619. 'padding: 0;' +
  10620. '}'
  10621. )
  10622. }
  10623. return {
  10624. show: show,
  10625. hide: hide,
  10626. getCss: getCss,
  10627. reposition: reposition,
  10628. destroy: destroy,
  10629. }
  10630. }
  10631. var isFakeCaretTableBrowser = function () {
  10632. return browser$2.isIE() || browser$2.isEdge() || browser$2.isFirefox()
  10633. }
  10634. var isInlineFakeCaretTarget = function (node) {
  10635. return isContentEditableFalse$8(node) || isMedia$1(node)
  10636. }
  10637. var isFakeCaretTarget = function (node) {
  10638. return (
  10639. isInlineFakeCaretTarget(node) ||
  10640. (isTable$3(node) && isFakeCaretTableBrowser())
  10641. )
  10642. }
  10643. var isContentEditableFalse$7 = isContentEditableFalse$b
  10644. var isMedia = isMedia$2
  10645. var isBlockLike = matchStyleValues(
  10646. 'display',
  10647. 'block table table-cell table-caption list-item'
  10648. )
  10649. var isCaretContainer = isCaretContainer$2
  10650. var isCaretContainerBlock = isCaretContainerBlock$1
  10651. var isElement$1 = isElement$5
  10652. var isCaretCandidate$1 = isCaretCandidate$3
  10653. var isForwards = function (direction) {
  10654. return direction > 0
  10655. }
  10656. var isBackwards = function (direction) {
  10657. return direction < 0
  10658. }
  10659. var skipCaretContainers = function (walk, shallow) {
  10660. var node
  10661. while ((node = walk(shallow))) {
  10662. if (!isCaretContainerBlock(node)) {
  10663. return node
  10664. }
  10665. }
  10666. return null
  10667. }
  10668. var findNode$1 = function (node, direction, predicateFn, rootNode, shallow) {
  10669. var walker = new DomTreeWalker(node, rootNode)
  10670. var isCefOrCaretContainer =
  10671. isContentEditableFalse$7(node) || isCaretContainerBlock(node)
  10672. if (isBackwards(direction)) {
  10673. if (isCefOrCaretContainer) {
  10674. node = skipCaretContainers(walker.prev.bind(walker), true)
  10675. if (predicateFn(node)) {
  10676. return node
  10677. }
  10678. }
  10679. while ((node = skipCaretContainers(walker.prev.bind(walker), shallow))) {
  10680. if (predicateFn(node)) {
  10681. return node
  10682. }
  10683. }
  10684. }
  10685. if (isForwards(direction)) {
  10686. if (isCefOrCaretContainer) {
  10687. node = skipCaretContainers(walker.next.bind(walker), true)
  10688. if (predicateFn(node)) {
  10689. return node
  10690. }
  10691. }
  10692. while ((node = skipCaretContainers(walker.next.bind(walker), shallow))) {
  10693. if (predicateFn(node)) {
  10694. return node
  10695. }
  10696. }
  10697. }
  10698. return null
  10699. }
  10700. var getParentBlock$2 = function (node, rootNode) {
  10701. while (node && node !== rootNode) {
  10702. if (isBlockLike(node)) {
  10703. return node
  10704. }
  10705. node = node.parentNode
  10706. }
  10707. return null
  10708. }
  10709. var isInSameBlock = function (caretPosition1, caretPosition2, rootNode) {
  10710. return (
  10711. getParentBlock$2(caretPosition1.container(), rootNode) ===
  10712. getParentBlock$2(caretPosition2.container(), rootNode)
  10713. )
  10714. }
  10715. var getChildNodeAtRelativeOffset = function (relativeOffset, caretPosition) {
  10716. if (!caretPosition) {
  10717. return null
  10718. }
  10719. var container = caretPosition.container()
  10720. var offset = caretPosition.offset()
  10721. if (!isElement$1(container)) {
  10722. return null
  10723. }
  10724. return container.childNodes[offset + relativeOffset]
  10725. }
  10726. var beforeAfter = function (before, node) {
  10727. var range = node.ownerDocument.createRange()
  10728. if (before) {
  10729. range.setStartBefore(node)
  10730. range.setEndBefore(node)
  10731. } else {
  10732. range.setStartAfter(node)
  10733. range.setEndAfter(node)
  10734. }
  10735. return range
  10736. }
  10737. var isNodesInSameBlock = function (root, node1, node2) {
  10738. return getParentBlock$2(node1, root) === getParentBlock$2(node2, root)
  10739. }
  10740. var lean = function (left, root, node) {
  10741. var siblingName = left ? 'previousSibling' : 'nextSibling'
  10742. while (node && node !== root) {
  10743. var sibling = node[siblingName]
  10744. if (isCaretContainer(sibling)) {
  10745. sibling = sibling[siblingName]
  10746. }
  10747. if (isContentEditableFalse$7(sibling) || isMedia(sibling)) {
  10748. if (isNodesInSameBlock(root, sibling, node)) {
  10749. return sibling
  10750. }
  10751. break
  10752. }
  10753. if (isCaretCandidate$1(sibling)) {
  10754. break
  10755. }
  10756. node = node.parentNode
  10757. }
  10758. return null
  10759. }
  10760. var before$2 = curry(beforeAfter, true)
  10761. var after$2 = curry(beforeAfter, false)
  10762. var normalizeRange = function (direction, root, range) {
  10763. var node
  10764. var leanLeft = curry(lean, true, root)
  10765. var leanRight = curry(lean, false, root)
  10766. var container = range.startContainer
  10767. var offset = range.startOffset
  10768. if (isCaretContainerBlock$1(container)) {
  10769. if (!isElement$1(container)) {
  10770. container = container.parentNode
  10771. }
  10772. var location_1 = container.getAttribute('data-mce-caret')
  10773. if (location_1 === 'before') {
  10774. node = container.nextSibling
  10775. if (isFakeCaretTarget(node)) {
  10776. return before$2(node)
  10777. }
  10778. }
  10779. if (location_1 === 'after') {
  10780. node = container.previousSibling
  10781. if (isFakeCaretTarget(node)) {
  10782. return after$2(node)
  10783. }
  10784. }
  10785. }
  10786. if (!range.collapsed) {
  10787. return range
  10788. }
  10789. if (isText$7(container)) {
  10790. if (isCaretContainer(container)) {
  10791. if (direction === 1) {
  10792. node = leanRight(container)
  10793. if (node) {
  10794. return before$2(node)
  10795. }
  10796. node = leanLeft(container)
  10797. if (node) {
  10798. return after$2(node)
  10799. }
  10800. }
  10801. if (direction === -1) {
  10802. node = leanLeft(container)
  10803. if (node) {
  10804. return after$2(node)
  10805. }
  10806. node = leanRight(container)
  10807. if (node) {
  10808. return before$2(node)
  10809. }
  10810. }
  10811. return range
  10812. }
  10813. if (
  10814. endsWithCaretContainer$1(container) &&
  10815. offset >= container.data.length - 1
  10816. ) {
  10817. if (direction === 1) {
  10818. node = leanRight(container)
  10819. if (node) {
  10820. return before$2(node)
  10821. }
  10822. }
  10823. return range
  10824. }
  10825. if (startsWithCaretContainer$1(container) && offset <= 1) {
  10826. if (direction === -1) {
  10827. node = leanLeft(container)
  10828. if (node) {
  10829. return after$2(node)
  10830. }
  10831. }
  10832. return range
  10833. }
  10834. if (offset === container.data.length) {
  10835. node = leanRight(container)
  10836. if (node) {
  10837. return before$2(node)
  10838. }
  10839. return range
  10840. }
  10841. if (offset === 0) {
  10842. node = leanLeft(container)
  10843. if (node) {
  10844. return after$2(node)
  10845. }
  10846. return range
  10847. }
  10848. }
  10849. return range
  10850. }
  10851. var getRelativeCefElm = function (forward, caretPosition) {
  10852. return Optional.from(
  10853. getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition)
  10854. ).filter(isContentEditableFalse$7)
  10855. }
  10856. var getNormalizedRangeEndPoint = function (direction, root, range) {
  10857. var normalizedRange = normalizeRange(direction, root, range)
  10858. if (direction === -1) {
  10859. return CaretPosition.fromRangeStart(normalizedRange)
  10860. }
  10861. return CaretPosition.fromRangeEnd(normalizedRange)
  10862. }
  10863. var getElementFromPosition = function (pos) {
  10864. return Optional.from(pos.getNode()).map(SugarElement.fromDom)
  10865. }
  10866. var getElementFromPrevPosition = function (pos) {
  10867. return Optional.from(pos.getNode(true)).map(SugarElement.fromDom)
  10868. }
  10869. var getVisualCaretPosition = function (walkFn, caretPosition) {
  10870. while ((caretPosition = walkFn(caretPosition))) {
  10871. if (caretPosition.isVisible()) {
  10872. return caretPosition
  10873. }
  10874. }
  10875. return caretPosition
  10876. }
  10877. var isMoveInsideSameBlock = function (from, to) {
  10878. var inSameBlock = isInSameBlock(from, to)
  10879. if (!inSameBlock && isBr$5(from.getNode())) {
  10880. return true
  10881. }
  10882. return inSameBlock
  10883. }
  10884. var HDirection
  10885. ;(function (HDirection) {
  10886. HDirection[(HDirection['Backwards'] = -1)] = 'Backwards'
  10887. HDirection[(HDirection['Forwards'] = 1)] = 'Forwards'
  10888. })(HDirection || (HDirection = {}))
  10889. var isContentEditableFalse$6 = isContentEditableFalse$b
  10890. var isText$1 = isText$7
  10891. var isElement = isElement$5
  10892. var isBr$1 = isBr$5
  10893. var isCaretCandidate = isCaretCandidate$3
  10894. var isAtomic = isAtomic$1
  10895. var isEditableCaretCandidate = isEditableCaretCandidate$1
  10896. var getParents$3 = function (node, root) {
  10897. var parents = []
  10898. while (node && node !== root) {
  10899. parents.push(node)
  10900. node = node.parentNode
  10901. }
  10902. return parents
  10903. }
  10904. var nodeAtIndex = function (container, offset) {
  10905. if (container.hasChildNodes() && offset < container.childNodes.length) {
  10906. return container.childNodes[offset]
  10907. }
  10908. return null
  10909. }
  10910. var getCaretCandidatePosition = function (direction, node) {
  10911. if (isForwards(direction)) {
  10912. if (
  10913. isCaretCandidate(node.previousSibling) &&
  10914. !isText$1(node.previousSibling)
  10915. ) {
  10916. return CaretPosition.before(node)
  10917. }
  10918. if (isText$1(node)) {
  10919. return CaretPosition(node, 0)
  10920. }
  10921. }
  10922. if (isBackwards(direction)) {
  10923. if (isCaretCandidate(node.nextSibling) && !isText$1(node.nextSibling)) {
  10924. return CaretPosition.after(node)
  10925. }
  10926. if (isText$1(node)) {
  10927. return CaretPosition(node, node.data.length)
  10928. }
  10929. }
  10930. if (isBackwards(direction)) {
  10931. if (isBr$1(node)) {
  10932. return CaretPosition.before(node)
  10933. }
  10934. return CaretPosition.after(node)
  10935. }
  10936. return CaretPosition.before(node)
  10937. }
  10938. var moveForwardFromBr = function (root, nextNode) {
  10939. var nextSibling = nextNode.nextSibling
  10940. if (nextSibling && isCaretCandidate(nextSibling)) {
  10941. if (isText$1(nextSibling)) {
  10942. return CaretPosition(nextSibling, 0)
  10943. } else {
  10944. return CaretPosition.before(nextSibling)
  10945. }
  10946. } else {
  10947. return findCaretPosition$1(
  10948. HDirection.Forwards,
  10949. CaretPosition.after(nextNode),
  10950. root
  10951. )
  10952. }
  10953. }
  10954. var findCaretPosition$1 = function (direction, startPos, root) {
  10955. var node
  10956. var nextNode
  10957. var innerNode
  10958. var caretPosition
  10959. if (!isElement(root) || !startPos) {
  10960. return null
  10961. }
  10962. if (startPos.isEqual(CaretPosition.after(root)) && root.lastChild) {
  10963. caretPosition = CaretPosition.after(root.lastChild)
  10964. if (
  10965. isBackwards(direction) &&
  10966. isCaretCandidate(root.lastChild) &&
  10967. isElement(root.lastChild)
  10968. ) {
  10969. return isBr$1(root.lastChild)
  10970. ? CaretPosition.before(root.lastChild)
  10971. : caretPosition
  10972. }
  10973. } else {
  10974. caretPosition = startPos
  10975. }
  10976. var container = caretPosition.container()
  10977. var offset = caretPosition.offset()
  10978. if (isText$1(container)) {
  10979. if (isBackwards(direction) && offset > 0) {
  10980. return CaretPosition(container, --offset)
  10981. }
  10982. if (isForwards(direction) && offset < container.length) {
  10983. return CaretPosition(container, ++offset)
  10984. }
  10985. node = container
  10986. } else {
  10987. if (isBackwards(direction) && offset > 0) {
  10988. nextNode = nodeAtIndex(container, offset - 1)
  10989. if (isCaretCandidate(nextNode)) {
  10990. if (!isAtomic(nextNode)) {
  10991. innerNode = findNode$1(
  10992. nextNode,
  10993. direction,
  10994. isEditableCaretCandidate,
  10995. nextNode
  10996. )
  10997. if (innerNode) {
  10998. if (isText$1(innerNode)) {
  10999. return CaretPosition(innerNode, innerNode.data.length)
  11000. }
  11001. return CaretPosition.after(innerNode)
  11002. }
  11003. }
  11004. if (isText$1(nextNode)) {
  11005. return CaretPosition(nextNode, nextNode.data.length)
  11006. }
  11007. return CaretPosition.before(nextNode)
  11008. }
  11009. }
  11010. if (isForwards(direction) && offset < container.childNodes.length) {
  11011. nextNode = nodeAtIndex(container, offset)
  11012. if (isCaretCandidate(nextNode)) {
  11013. if (isBr$1(nextNode)) {
  11014. return moveForwardFromBr(root, nextNode)
  11015. }
  11016. if (!isAtomic(nextNode)) {
  11017. innerNode = findNode$1(
  11018. nextNode,
  11019. direction,
  11020. isEditableCaretCandidate,
  11021. nextNode
  11022. )
  11023. if (innerNode) {
  11024. if (isText$1(innerNode)) {
  11025. return CaretPosition(innerNode, 0)
  11026. }
  11027. return CaretPosition.before(innerNode)
  11028. }
  11029. }
  11030. if (isText$1(nextNode)) {
  11031. return CaretPosition(nextNode, 0)
  11032. }
  11033. return CaretPosition.after(nextNode)
  11034. }
  11035. }
  11036. node = nextNode ? nextNode : caretPosition.getNode()
  11037. }
  11038. if (
  11039. (isForwards(direction) && caretPosition.isAtEnd()) ||
  11040. (isBackwards(direction) && caretPosition.isAtStart())
  11041. ) {
  11042. node = findNode$1(node, direction, always, root, true)
  11043. if (isEditableCaretCandidate(node, root)) {
  11044. return getCaretCandidatePosition(direction, node)
  11045. }
  11046. }
  11047. nextNode = findNode$1(node, direction, isEditableCaretCandidate, root)
  11048. var rootContentEditableFalseElm = last$1(
  11049. filter$4(getParents$3(container, root), isContentEditableFalse$6)
  11050. )
  11051. if (
  11052. rootContentEditableFalseElm &&
  11053. (!nextNode || !rootContentEditableFalseElm.contains(nextNode))
  11054. ) {
  11055. if (isForwards(direction)) {
  11056. caretPosition = CaretPosition.after(rootContentEditableFalseElm)
  11057. } else {
  11058. caretPosition = CaretPosition.before(rootContentEditableFalseElm)
  11059. }
  11060. return caretPosition
  11061. }
  11062. if (nextNode) {
  11063. return getCaretCandidatePosition(direction, nextNode)
  11064. }
  11065. return null
  11066. }
  11067. var CaretWalker = function (root) {
  11068. return {
  11069. next: function (caretPosition) {
  11070. return findCaretPosition$1(HDirection.Forwards, caretPosition, root)
  11071. },
  11072. prev: function (caretPosition) {
  11073. return findCaretPosition$1(HDirection.Backwards, caretPosition, root)
  11074. },
  11075. }
  11076. }
  11077. var walkToPositionIn = function (forward, root, start) {
  11078. var position = forward
  11079. ? CaretPosition.before(start)
  11080. : CaretPosition.after(start)
  11081. return fromPosition(forward, root, position)
  11082. }
  11083. var afterElement = function (node) {
  11084. return isBr$5(node) ? CaretPosition.before(node) : CaretPosition.after(node)
  11085. }
  11086. var isBeforeOrStart = function (position) {
  11087. if (CaretPosition.isTextPosition(position)) {
  11088. return position.offset() === 0
  11089. } else {
  11090. return isCaretCandidate$3(position.getNode())
  11091. }
  11092. }
  11093. var isAfterOrEnd = function (position) {
  11094. if (CaretPosition.isTextPosition(position)) {
  11095. var container = position.container()
  11096. return position.offset() === container.data.length
  11097. } else {
  11098. return isCaretCandidate$3(position.getNode(true))
  11099. }
  11100. }
  11101. var isBeforeAfterSameElement = function (from, to) {
  11102. return (
  11103. !CaretPosition.isTextPosition(from) &&
  11104. !CaretPosition.isTextPosition(to) &&
  11105. from.getNode() === to.getNode(true)
  11106. )
  11107. }
  11108. var isAtBr = function (position) {
  11109. return !CaretPosition.isTextPosition(position) && isBr$5(position.getNode())
  11110. }
  11111. var shouldSkipPosition = function (forward, from, to) {
  11112. if (forward) {
  11113. return (
  11114. !isBeforeAfterSameElement(from, to) &&
  11115. !isAtBr(from) &&
  11116. isAfterOrEnd(from) &&
  11117. isBeforeOrStart(to)
  11118. )
  11119. } else {
  11120. return (
  11121. !isBeforeAfterSameElement(to, from) &&
  11122. isBeforeOrStart(from) &&
  11123. isAfterOrEnd(to)
  11124. )
  11125. }
  11126. }
  11127. var fromPosition = function (forward, root, pos) {
  11128. var walker = CaretWalker(root)
  11129. return Optional.from(forward ? walker.next(pos) : walker.prev(pos))
  11130. }
  11131. var navigate = function (forward, root, from) {
  11132. return fromPosition(forward, root, from).bind(function (to) {
  11133. if (
  11134. isInSameBlock(from, to, root) &&
  11135. shouldSkipPosition(forward, from, to)
  11136. ) {
  11137. return fromPosition(forward, root, to)
  11138. } else {
  11139. return Optional.some(to)
  11140. }
  11141. })
  11142. }
  11143. var navigateIgnore = function (forward, root, from, ignoreFilter) {
  11144. return navigate(forward, root, from).bind(function (pos) {
  11145. return ignoreFilter(pos)
  11146. ? navigateIgnore(forward, root, pos, ignoreFilter)
  11147. : Optional.some(pos)
  11148. })
  11149. }
  11150. var positionIn = function (forward, element) {
  11151. var startNode = forward ? element.firstChild : element.lastChild
  11152. if (isText$7(startNode)) {
  11153. return Optional.some(
  11154. CaretPosition(startNode, forward ? 0 : startNode.data.length)
  11155. )
  11156. } else if (startNode) {
  11157. if (isCaretCandidate$3(startNode)) {
  11158. return Optional.some(
  11159. forward ? CaretPosition.before(startNode) : afterElement(startNode)
  11160. )
  11161. } else {
  11162. return walkToPositionIn(forward, element, startNode)
  11163. }
  11164. } else {
  11165. return Optional.none()
  11166. }
  11167. }
  11168. var nextPosition = curry(fromPosition, true)
  11169. var prevPosition = curry(fromPosition, false)
  11170. var firstPositionIn = curry(positionIn, true)
  11171. var lastPositionIn = curry(positionIn, false)
  11172. var CARET_ID$1 = '_mce_caret'
  11173. var isCaretNode = function (node) {
  11174. return isElement$5(node) && node.id === CARET_ID$1
  11175. }
  11176. var getParentCaretContainer = function (body, node) {
  11177. while (node && node !== body) {
  11178. if (node.id === CARET_ID$1) {
  11179. return node
  11180. }
  11181. node = node.parentNode
  11182. }
  11183. return null
  11184. }
  11185. var isStringPathBookmark = function (bookmark) {
  11186. return isString$1(bookmark.start)
  11187. }
  11188. var isRangeBookmark = function (bookmark) {
  11189. return has$2(bookmark, 'rng')
  11190. }
  11191. var isIdBookmark = function (bookmark) {
  11192. return has$2(bookmark, 'id')
  11193. }
  11194. var isIndexBookmark = function (bookmark) {
  11195. return has$2(bookmark, 'name')
  11196. }
  11197. var isPathBookmark = function (bookmark) {
  11198. return Tools.isArray(bookmark.start)
  11199. }
  11200. var addBogus = function (dom, node) {
  11201. if (isElement$5(node) && dom.isBlock(node) && !node.innerHTML && !Env.ie) {
  11202. node.innerHTML = '<br data-mce-bogus="1" />'
  11203. }
  11204. return node
  11205. }
  11206. var resolveCaretPositionBookmark = function (dom, bookmark) {
  11207. var pos
  11208. var rng = dom.createRng()
  11209. pos = resolve$2(dom.getRoot(), bookmark.start)
  11210. rng.setStart(pos.container(), pos.offset())
  11211. pos = resolve$2(dom.getRoot(), bookmark.end)
  11212. rng.setEnd(pos.container(), pos.offset())
  11213. return rng
  11214. }
  11215. var insertZwsp = function (node, rng) {
  11216. var textNode = node.ownerDocument.createTextNode(ZWSP$1)
  11217. node.appendChild(textNode)
  11218. rng.setStart(textNode, 0)
  11219. rng.setEnd(textNode, 0)
  11220. }
  11221. var isEmpty$1 = function (node) {
  11222. return node.hasChildNodes() === false
  11223. }
  11224. var tryFindRangePosition = function (node, rng) {
  11225. return lastPositionIn(node).fold(never, function (pos) {
  11226. rng.setStart(pos.container(), pos.offset())
  11227. rng.setEnd(pos.container(), pos.offset())
  11228. return true
  11229. })
  11230. }
  11231. var padEmptyCaretContainer = function (root, node, rng) {
  11232. if (isEmpty$1(node) && getParentCaretContainer(root, node)) {
  11233. insertZwsp(node, rng)
  11234. return true
  11235. } else {
  11236. return false
  11237. }
  11238. }
  11239. var setEndPoint = function (dom, start, bookmark, rng) {
  11240. var point = bookmark[start ? 'start' : 'end']
  11241. var i, node, offset, children
  11242. var root = dom.getRoot()
  11243. if (point) {
  11244. offset = point[0]
  11245. for (node = root, i = point.length - 1; i >= 1; i--) {
  11246. children = node.childNodes
  11247. if (padEmptyCaretContainer(root, node, rng)) {
  11248. return true
  11249. }
  11250. if (point[i] > children.length - 1) {
  11251. if (padEmptyCaretContainer(root, node, rng)) {
  11252. return true
  11253. }
  11254. return tryFindRangePosition(node, rng)
  11255. }
  11256. node = children[point[i]]
  11257. }
  11258. if (node.nodeType === 3) {
  11259. offset = Math.min(point[0], node.nodeValue.length)
  11260. }
  11261. if (node.nodeType === 1) {
  11262. offset = Math.min(point[0], node.childNodes.length)
  11263. }
  11264. if (start) {
  11265. rng.setStart(node, offset)
  11266. } else {
  11267. rng.setEnd(node, offset)
  11268. }
  11269. }
  11270. return true
  11271. }
  11272. var isValidTextNode = function (node) {
  11273. return isText$7(node) && node.data.length > 0
  11274. }
  11275. var restoreEndPoint = function (dom, suffix, bookmark) {
  11276. var marker = dom.get(bookmark.id + '_' + suffix),
  11277. node,
  11278. idx,
  11279. next,
  11280. prev
  11281. var keep = bookmark.keep
  11282. var container, offset
  11283. if (marker) {
  11284. node = marker.parentNode
  11285. if (suffix === 'start') {
  11286. if (!keep) {
  11287. idx = dom.nodeIndex(marker)
  11288. } else {
  11289. if (marker.hasChildNodes()) {
  11290. node = marker.firstChild
  11291. idx = 1
  11292. } else if (isValidTextNode(marker.nextSibling)) {
  11293. node = marker.nextSibling
  11294. idx = 0
  11295. } else if (isValidTextNode(marker.previousSibling)) {
  11296. node = marker.previousSibling
  11297. idx = marker.previousSibling.data.length
  11298. } else {
  11299. node = marker.parentNode
  11300. idx = dom.nodeIndex(marker) + 1
  11301. }
  11302. }
  11303. container = node
  11304. offset = idx
  11305. } else {
  11306. if (!keep) {
  11307. idx = dom.nodeIndex(marker)
  11308. } else {
  11309. if (marker.hasChildNodes()) {
  11310. node = marker.firstChild
  11311. idx = 1
  11312. } else if (isValidTextNode(marker.previousSibling)) {
  11313. node = marker.previousSibling
  11314. idx = marker.previousSibling.data.length
  11315. } else {
  11316. node = marker.parentNode
  11317. idx = dom.nodeIndex(marker)
  11318. }
  11319. }
  11320. container = node
  11321. offset = idx
  11322. }
  11323. if (!keep) {
  11324. prev = marker.previousSibling
  11325. next = marker.nextSibling
  11326. Tools.each(Tools.grep(marker.childNodes), function (node) {
  11327. if (isText$7(node)) {
  11328. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '')
  11329. }
  11330. })
  11331. while ((marker = dom.get(bookmark.id + '_' + suffix))) {
  11332. dom.remove(marker, true)
  11333. }
  11334. if (
  11335. prev &&
  11336. next &&
  11337. prev.nodeType === next.nodeType &&
  11338. isText$7(prev) &&
  11339. !Env.opera
  11340. ) {
  11341. idx = prev.nodeValue.length
  11342. prev.appendData(next.nodeValue)
  11343. dom.remove(next)
  11344. container = prev
  11345. offset = idx
  11346. }
  11347. }
  11348. return Optional.some(CaretPosition(container, offset))
  11349. } else {
  11350. return Optional.none()
  11351. }
  11352. }
  11353. var resolvePaths = function (dom, bookmark) {
  11354. var rng = dom.createRng()
  11355. if (
  11356. setEndPoint(dom, true, bookmark, rng) &&
  11357. setEndPoint(dom, false, bookmark, rng)
  11358. ) {
  11359. return Optional.some(rng)
  11360. } else {
  11361. return Optional.none()
  11362. }
  11363. }
  11364. var resolveId = function (dom, bookmark) {
  11365. var startPos = restoreEndPoint(dom, 'start', bookmark)
  11366. var endPos = restoreEndPoint(dom, 'end', bookmark)
  11367. return lift2(startPos, endPos.or(startPos), function (spos, epos) {
  11368. var rng = dom.createRng()
  11369. rng.setStart(addBogus(dom, spos.container()), spos.offset())
  11370. rng.setEnd(addBogus(dom, epos.container()), epos.offset())
  11371. return rng
  11372. })
  11373. }
  11374. var resolveIndex = function (dom, bookmark) {
  11375. return Optional.from(dom.select(bookmark.name)[bookmark.index]).map(
  11376. function (elm) {
  11377. var rng = dom.createRng()
  11378. rng.selectNode(elm)
  11379. return rng
  11380. }
  11381. )
  11382. }
  11383. var resolve$1 = function (selection, bookmark) {
  11384. var dom = selection.dom
  11385. if (bookmark) {
  11386. if (isPathBookmark(bookmark)) {
  11387. return resolvePaths(dom, bookmark)
  11388. } else if (isStringPathBookmark(bookmark)) {
  11389. return Optional.some(resolveCaretPositionBookmark(dom, bookmark))
  11390. } else if (isIdBookmark(bookmark)) {
  11391. return resolveId(dom, bookmark)
  11392. } else if (isIndexBookmark(bookmark)) {
  11393. return resolveIndex(dom, bookmark)
  11394. } else if (isRangeBookmark(bookmark)) {
  11395. return Optional.some(bookmark.rng)
  11396. }
  11397. }
  11398. return Optional.none()
  11399. }
  11400. var getBookmark$1 = function (selection, type, normalized) {
  11401. return getBookmark$2(selection, type, normalized)
  11402. }
  11403. var moveToBookmark = function (selection, bookmark) {
  11404. resolve$1(selection, bookmark).each(function (rng) {
  11405. selection.setRng(rng)
  11406. })
  11407. }
  11408. var isBookmarkNode$1 = function (node) {
  11409. return (
  11410. isElement$5(node) &&
  11411. node.tagName === 'SPAN' &&
  11412. node.getAttribute('data-mce-type') === 'bookmark'
  11413. )
  11414. }
  11415. var is = function (expected) {
  11416. return function (actual) {
  11417. return expected === actual
  11418. }
  11419. }
  11420. var isNbsp = is(nbsp)
  11421. var isWhiteSpace = function (chr) {
  11422. return chr !== '' && ' \f\n\r\t\x0B'.indexOf(chr) !== -1
  11423. }
  11424. var isContent = function (chr) {
  11425. return !isWhiteSpace(chr) && !isNbsp(chr)
  11426. }
  11427. var isNode = function (node) {
  11428. return !!node.nodeType
  11429. }
  11430. var isInlineBlock = function (node) {
  11431. return node && /^(IMG)$/.test(node.nodeName)
  11432. }
  11433. var moveStart = function (dom, selection, rng) {
  11434. var offset = rng.startOffset
  11435. var container = rng.startContainer
  11436. if (container === rng.endContainer) {
  11437. if (isInlineBlock(container.childNodes[offset])) {
  11438. return
  11439. }
  11440. }
  11441. if (isElement$5(container)) {
  11442. var nodes = container.childNodes
  11443. var walker = void 0
  11444. if (offset < nodes.length) {
  11445. container = nodes[offset]
  11446. walker = new DomTreeWalker(
  11447. container,
  11448. dom.getParent(container, dom.isBlock)
  11449. )
  11450. } else {
  11451. container = nodes[nodes.length - 1]
  11452. walker = new DomTreeWalker(
  11453. container,
  11454. dom.getParent(container, dom.isBlock)
  11455. )
  11456. walker.next(true)
  11457. }
  11458. for (var node = walker.current(); node; node = walker.next()) {
  11459. if (isText$7(node) && !isWhiteSpaceNode$1(node)) {
  11460. rng.setStart(node, 0)
  11461. selection.setRng(rng)
  11462. return
  11463. }
  11464. }
  11465. }
  11466. }
  11467. var getNonWhiteSpaceSibling = function (node, next, inc) {
  11468. if (node) {
  11469. var nextName = next ? 'nextSibling' : 'previousSibling'
  11470. for (node = inc ? node : node[nextName]; node; node = node[nextName]) {
  11471. if (isElement$5(node) || !isWhiteSpaceNode$1(node)) {
  11472. return node
  11473. }
  11474. }
  11475. }
  11476. }
  11477. var isTextBlock$1 = function (editor, name) {
  11478. if (isNode(name)) {
  11479. name = name.nodeName
  11480. }
  11481. return !!editor.schema.getTextBlockElements()[name.toLowerCase()]
  11482. }
  11483. var isValid = function (ed, parent, child) {
  11484. return ed.schema.isValidChild(parent, child)
  11485. }
  11486. var isWhiteSpaceNode$1 = function (node, allowSpaces) {
  11487. if (allowSpaces === void 0) {
  11488. allowSpaces = false
  11489. }
  11490. if (isNonNullable(node) && isText$7(node)) {
  11491. var data = allowSpaces ? node.data.replace(/ /g, '\xA0') : node.data
  11492. return isWhitespaceText(data)
  11493. } else {
  11494. return false
  11495. }
  11496. }
  11497. var isEmptyTextNode$1 = function (node) {
  11498. return isNonNullable(node) && isText$7(node) && node.length === 0
  11499. }
  11500. var replaceVars = function (value, vars) {
  11501. if (isFunction(value)) {
  11502. value = value(vars)
  11503. } else if (isNonNullable(vars)) {
  11504. value = value.replace(/%(\w+)/g, function (str, name) {
  11505. return vars[name] || str
  11506. })
  11507. }
  11508. return value
  11509. }
  11510. var isEq$5 = function (str1, str2) {
  11511. str1 = str1 || ''
  11512. str2 = str2 || ''
  11513. str1 = '' + (str1.nodeName || str1)
  11514. str2 = '' + (str2.nodeName || str2)
  11515. return str1.toLowerCase() === str2.toLowerCase()
  11516. }
  11517. var normalizeStyleValue = function (dom, value, name) {
  11518. if (name === 'color' || name === 'backgroundColor') {
  11519. value = dom.toHex(value)
  11520. }
  11521. if (name === 'fontWeight' && value === 700) {
  11522. value = 'bold'
  11523. }
  11524. if (name === 'fontFamily') {
  11525. value = value.replace(/[\'\"]/g, '').replace(/,\s+/g, ',')
  11526. }
  11527. return '' + value
  11528. }
  11529. var getStyle = function (dom, node, name) {
  11530. return normalizeStyleValue(dom, dom.getStyle(node, name), name)
  11531. }
  11532. var getTextDecoration = function (dom, node) {
  11533. var decoration
  11534. dom.getParent(node, function (n) {
  11535. decoration = dom.getStyle(n, 'text-decoration')
  11536. return decoration && decoration !== 'none'
  11537. })
  11538. return decoration
  11539. }
  11540. var getParents$2 = function (dom, node, selector) {
  11541. return dom.getParents(node, selector, dom.getRoot())
  11542. }
  11543. var isVariableFormatName = function (editor, formatName) {
  11544. var hasVariableValues = function (format) {
  11545. var isVariableValue = function (val) {
  11546. return val.length > 1 && val.charAt(0) === '%'
  11547. }
  11548. return exists(['styles', 'attributes'], function (key) {
  11549. return get$9(format, key).exists(function (field) {
  11550. var fieldValues = isArray$1(field) ? field : values(field)
  11551. return exists(fieldValues, isVariableValue)
  11552. })
  11553. })
  11554. }
  11555. return exists(editor.formatter.get(formatName), hasVariableValues)
  11556. }
  11557. var areSimilarFormats = function (editor, formatName, otherFormatName) {
  11558. var validKeys = [
  11559. 'inline',
  11560. 'block',
  11561. 'selector',
  11562. 'attributes',
  11563. 'styles',
  11564. 'classes',
  11565. ]
  11566. var filterObj = function (format) {
  11567. return filter$3(format, function (_, key) {
  11568. return exists(validKeys, function (validKey) {
  11569. return validKey === key
  11570. })
  11571. })
  11572. }
  11573. return exists(editor.formatter.get(formatName), function (fmt1) {
  11574. var filteredFmt1 = filterObj(fmt1)
  11575. return exists(editor.formatter.get(otherFormatName), function (fmt2) {
  11576. var filteredFmt2 = filterObj(fmt2)
  11577. return equal$1(filteredFmt1, filteredFmt2)
  11578. })
  11579. })
  11580. }
  11581. var isBlockFormat = function (format) {
  11582. return hasNonNullableKey(format, 'block')
  11583. }
  11584. var isSelectorFormat = function (format) {
  11585. return hasNonNullableKey(format, 'selector')
  11586. }
  11587. var isInlineFormat = function (format) {
  11588. return hasNonNullableKey(format, 'inline')
  11589. }
  11590. var isMixedFormat = function (format) {
  11591. return (
  11592. isSelectorFormat(format) &&
  11593. isInlineFormat(format) &&
  11594. is$1(get$9(format, 'mixed'), true)
  11595. )
  11596. }
  11597. var shouldExpandToSelector = function (format) {
  11598. return (
  11599. isSelectorFormat(format) &&
  11600. format.expand !== false &&
  11601. !isInlineFormat(format)
  11602. )
  11603. }
  11604. var isBookmarkNode = isBookmarkNode$1
  11605. var getParents$1 = getParents$2
  11606. var isWhiteSpaceNode = isWhiteSpaceNode$1
  11607. var isTextBlock = isTextBlock$1
  11608. var isBogusBr = function (node) {
  11609. return (
  11610. isBr$5(node) && node.getAttribute('data-mce-bogus') && !node.nextSibling
  11611. )
  11612. }
  11613. var findParentContentEditable = function (dom, node) {
  11614. var parent = node
  11615. while (parent) {
  11616. if (isElement$5(parent) && dom.getContentEditable(parent)) {
  11617. return dom.getContentEditable(parent) === 'false' ? parent : node
  11618. }
  11619. parent = parent.parentNode
  11620. }
  11621. return node
  11622. }
  11623. var walkText = function (start, node, offset, predicate) {
  11624. var str = node.data
  11625. for (var i = offset; start ? i >= 0 : i < str.length; start ? i-- : i++) {
  11626. if (predicate(str.charAt(i))) {
  11627. return start ? i + 1 : i
  11628. }
  11629. }
  11630. return -1
  11631. }
  11632. var findSpace = function (start, node, offset) {
  11633. return walkText(start, node, offset, function (c) {
  11634. return isNbsp(c) || isWhiteSpace(c)
  11635. })
  11636. }
  11637. var findContent = function (start, node, offset) {
  11638. return walkText(start, node, offset, isContent)
  11639. }
  11640. var findWordEndPoint = function (
  11641. dom,
  11642. body,
  11643. container,
  11644. offset,
  11645. start,
  11646. includeTrailingSpaces
  11647. ) {
  11648. var lastTextNode
  11649. var rootNode = dom.getParent(container, dom.isBlock) || body
  11650. var walk = function (container, offset, pred) {
  11651. var textSeeker = TextSeeker(dom)
  11652. var walker = start ? textSeeker.backwards : textSeeker.forwards
  11653. return Optional.from(
  11654. walker(
  11655. container,
  11656. offset,
  11657. function (text, textOffset) {
  11658. if (isBookmarkNode(text.parentNode)) {
  11659. return -1
  11660. } else {
  11661. lastTextNode = text
  11662. return pred(start, text, textOffset)
  11663. }
  11664. },
  11665. rootNode
  11666. )
  11667. )
  11668. }
  11669. var spaceResult = walk(container, offset, findSpace)
  11670. return spaceResult
  11671. .bind(function (result) {
  11672. return includeTrailingSpaces
  11673. ? walk(
  11674. result.container,
  11675. result.offset + (start ? -1 : 0),
  11676. findContent
  11677. )
  11678. : Optional.some(result)
  11679. })
  11680. .orThunk(function () {
  11681. return lastTextNode
  11682. ? Optional.some({
  11683. container: lastTextNode,
  11684. offset: start ? 0 : lastTextNode.length,
  11685. })
  11686. : Optional.none()
  11687. })
  11688. }
  11689. var findSelectorEndPoint = function (
  11690. dom,
  11691. formatList,
  11692. rng,
  11693. container,
  11694. siblingName
  11695. ) {
  11696. if (
  11697. isText$7(container) &&
  11698. isEmpty$3(container.data) &&
  11699. container[siblingName]
  11700. ) {
  11701. container = container[siblingName]
  11702. }
  11703. var parents = getParents$1(dom, container)
  11704. for (var i = 0; i < parents.length; i++) {
  11705. for (var y = 0; y < formatList.length; y++) {
  11706. var curFormat = formatList[y]
  11707. if (
  11708. isNonNullable(curFormat.collapsed) &&
  11709. curFormat.collapsed !== rng.collapsed
  11710. ) {
  11711. continue
  11712. }
  11713. if (
  11714. isSelectorFormat(curFormat) &&
  11715. dom.is(parents[i], curFormat.selector)
  11716. ) {
  11717. return parents[i]
  11718. }
  11719. }
  11720. }
  11721. return container
  11722. }
  11723. var findBlockEndPoint = function (
  11724. editor,
  11725. formatList,
  11726. container,
  11727. siblingName
  11728. ) {
  11729. var node = container
  11730. var dom = editor.dom
  11731. var root = dom.getRoot()
  11732. var format = formatList[0]
  11733. if (isBlockFormat(format)) {
  11734. node = format.wrapper
  11735. ? null
  11736. : dom.getParent(container, format.block, root)
  11737. }
  11738. if (!node) {
  11739. var scopeRoot = dom.getParent(container, 'LI,TD,TH')
  11740. node = dom.getParent(
  11741. isText$7(container) ? container.parentNode : container,
  11742. function (node) {
  11743. return node !== root && isTextBlock(editor, node)
  11744. },
  11745. scopeRoot
  11746. )
  11747. }
  11748. if (node && isBlockFormat(format) && format.wrapper) {
  11749. node = getParents$1(dom, node, 'ul,ol').reverse()[0] || node
  11750. }
  11751. if (!node) {
  11752. node = container
  11753. while (node[siblingName] && !dom.isBlock(node[siblingName])) {
  11754. node = node[siblingName]
  11755. if (isEq$5(node, 'br')) {
  11756. break
  11757. }
  11758. }
  11759. }
  11760. return node || container
  11761. }
  11762. var isAtBlockBoundary$1 = function (dom, root, container, siblingName) {
  11763. var parent = container.parentNode
  11764. if (isNonNullable(container[siblingName])) {
  11765. return false
  11766. } else if (parent === root || isNullable(parent) || dom.isBlock(parent)) {
  11767. return true
  11768. } else {
  11769. return isAtBlockBoundary$1(dom, root, parent, siblingName)
  11770. }
  11771. }
  11772. var findParentContainer = function (
  11773. dom,
  11774. formatList,
  11775. container,
  11776. offset,
  11777. start
  11778. ) {
  11779. var parent = container
  11780. var siblingName = start ? 'previousSibling' : 'nextSibling'
  11781. var root = dom.getRoot()
  11782. if (isText$7(container) && !isWhiteSpaceNode(container)) {
  11783. if (start ? offset > 0 : offset < container.data.length) {
  11784. return container
  11785. }
  11786. }
  11787. while (true) {
  11788. if (!formatList[0].block_expand && dom.isBlock(parent)) {
  11789. return parent
  11790. }
  11791. for (
  11792. var sibling = parent[siblingName];
  11793. sibling;
  11794. sibling = sibling[siblingName]
  11795. ) {
  11796. var allowSpaces =
  11797. isText$7(sibling) &&
  11798. !isAtBlockBoundary$1(dom, root, sibling, siblingName)
  11799. if (
  11800. !isBookmarkNode(sibling) &&
  11801. !isBogusBr(sibling) &&
  11802. !isWhiteSpaceNode(sibling, allowSpaces)
  11803. ) {
  11804. return parent
  11805. }
  11806. }
  11807. if (parent === root || parent.parentNode === root) {
  11808. container = parent
  11809. break
  11810. }
  11811. parent = parent.parentNode
  11812. }
  11813. return container
  11814. }
  11815. var isSelfOrParentBookmark = function (container) {
  11816. return isBookmarkNode(container.parentNode) || isBookmarkNode(container)
  11817. }
  11818. var expandRng = function (editor, rng, formatList, includeTrailingSpace) {
  11819. if (includeTrailingSpace === void 0) {
  11820. includeTrailingSpace = false
  11821. }
  11822. var startContainer = rng.startContainer,
  11823. startOffset = rng.startOffset,
  11824. endContainer = rng.endContainer,
  11825. endOffset = rng.endOffset
  11826. var dom = editor.dom
  11827. var format = formatList[0]
  11828. if (isElement$5(startContainer) && startContainer.hasChildNodes()) {
  11829. startContainer = getNode$1(startContainer, startOffset)
  11830. if (isText$7(startContainer)) {
  11831. startOffset = 0
  11832. }
  11833. }
  11834. if (isElement$5(endContainer) && endContainer.hasChildNodes()) {
  11835. endContainer = getNode$1(
  11836. endContainer,
  11837. rng.collapsed ? endOffset : endOffset - 1
  11838. )
  11839. if (isText$7(endContainer)) {
  11840. endOffset = endContainer.nodeValue.length
  11841. }
  11842. }
  11843. startContainer = findParentContentEditable(dom, startContainer)
  11844. endContainer = findParentContentEditable(dom, endContainer)
  11845. if (isSelfOrParentBookmark(startContainer)) {
  11846. startContainer = isBookmarkNode(startContainer)
  11847. ? startContainer
  11848. : startContainer.parentNode
  11849. if (rng.collapsed) {
  11850. startContainer = startContainer.previousSibling || startContainer
  11851. } else {
  11852. startContainer = startContainer.nextSibling || startContainer
  11853. }
  11854. if (isText$7(startContainer)) {
  11855. startOffset = rng.collapsed ? startContainer.length : 0
  11856. }
  11857. }
  11858. if (isSelfOrParentBookmark(endContainer)) {
  11859. endContainer = isBookmarkNode(endContainer)
  11860. ? endContainer
  11861. : endContainer.parentNode
  11862. if (rng.collapsed) {
  11863. endContainer = endContainer.nextSibling || endContainer
  11864. } else {
  11865. endContainer = endContainer.previousSibling || endContainer
  11866. }
  11867. if (isText$7(endContainer)) {
  11868. endOffset = rng.collapsed ? 0 : endContainer.length
  11869. }
  11870. }
  11871. if (rng.collapsed) {
  11872. var startPoint = findWordEndPoint(
  11873. dom,
  11874. editor.getBody(),
  11875. startContainer,
  11876. startOffset,
  11877. true,
  11878. includeTrailingSpace
  11879. )
  11880. startPoint.each(function (_a) {
  11881. var container = _a.container,
  11882. offset = _a.offset
  11883. startContainer = container
  11884. startOffset = offset
  11885. })
  11886. var endPoint = findWordEndPoint(
  11887. dom,
  11888. editor.getBody(),
  11889. endContainer,
  11890. endOffset,
  11891. false,
  11892. includeTrailingSpace
  11893. )
  11894. endPoint.each(function (_a) {
  11895. var container = _a.container,
  11896. offset = _a.offset
  11897. endContainer = container
  11898. endOffset = offset
  11899. })
  11900. }
  11901. if (isInlineFormat(format) || format.block_expand) {
  11902. if (
  11903. !isInlineFormat(format) ||
  11904. !isText$7(startContainer) ||
  11905. startOffset === 0
  11906. ) {
  11907. startContainer = findParentContainer(
  11908. dom,
  11909. formatList,
  11910. startContainer,
  11911. startOffset,
  11912. true
  11913. )
  11914. }
  11915. if (
  11916. !isInlineFormat(format) ||
  11917. !isText$7(endContainer) ||
  11918. endOffset === endContainer.nodeValue.length
  11919. ) {
  11920. endContainer = findParentContainer(
  11921. dom,
  11922. formatList,
  11923. endContainer,
  11924. endOffset,
  11925. false
  11926. )
  11927. }
  11928. }
  11929. if (shouldExpandToSelector(format)) {
  11930. startContainer = findSelectorEndPoint(
  11931. dom,
  11932. formatList,
  11933. rng,
  11934. startContainer,
  11935. 'previousSibling'
  11936. )
  11937. endContainer = findSelectorEndPoint(
  11938. dom,
  11939. formatList,
  11940. rng,
  11941. endContainer,
  11942. 'nextSibling'
  11943. )
  11944. }
  11945. if (isBlockFormat(format) || isSelectorFormat(format)) {
  11946. startContainer = findBlockEndPoint(
  11947. editor,
  11948. formatList,
  11949. startContainer,
  11950. 'previousSibling'
  11951. )
  11952. endContainer = findBlockEndPoint(
  11953. editor,
  11954. formatList,
  11955. endContainer,
  11956. 'nextSibling'
  11957. )
  11958. if (isBlockFormat(format)) {
  11959. if (!dom.isBlock(startContainer)) {
  11960. startContainer = findParentContainer(
  11961. dom,
  11962. formatList,
  11963. startContainer,
  11964. startOffset,
  11965. true
  11966. )
  11967. }
  11968. if (!dom.isBlock(endContainer)) {
  11969. endContainer = findParentContainer(
  11970. dom,
  11971. formatList,
  11972. endContainer,
  11973. endOffset,
  11974. false
  11975. )
  11976. }
  11977. }
  11978. }
  11979. if (isElement$5(startContainer)) {
  11980. startOffset = dom.nodeIndex(startContainer)
  11981. startContainer = startContainer.parentNode
  11982. }
  11983. if (isElement$5(endContainer)) {
  11984. endOffset = dom.nodeIndex(endContainer) + 1
  11985. endContainer = endContainer.parentNode
  11986. }
  11987. return {
  11988. startContainer: startContainer,
  11989. startOffset: startOffset,
  11990. endContainer: endContainer,
  11991. endOffset: endOffset,
  11992. }
  11993. }
  11994. var walk$2 = function (dom, rng, callback) {
  11995. var startOffset = rng.startOffset
  11996. var startContainer = getNode$1(rng.startContainer, startOffset)
  11997. var endOffset = rng.endOffset
  11998. var endContainer = getNode$1(rng.endContainer, endOffset - 1)
  11999. var exclude = function (nodes) {
  12000. var firstNode = nodes[0]
  12001. if (
  12002. isText$7(firstNode) &&
  12003. firstNode === startContainer &&
  12004. startOffset >= firstNode.data.length
  12005. ) {
  12006. nodes.splice(0, 1)
  12007. }
  12008. var lastNode = nodes[nodes.length - 1]
  12009. if (
  12010. endOffset === 0 &&
  12011. nodes.length > 0 &&
  12012. lastNode === endContainer &&
  12013. isText$7(lastNode)
  12014. ) {
  12015. nodes.splice(nodes.length - 1, 1)
  12016. }
  12017. return nodes
  12018. }
  12019. var collectSiblings = function (node, name, endNode) {
  12020. var siblings = []
  12021. for (; node && node !== endNode; node = node[name]) {
  12022. siblings.push(node)
  12023. }
  12024. return siblings
  12025. }
  12026. var findEndPoint = function (node, root) {
  12027. return dom.getParent(
  12028. node,
  12029. function (node) {
  12030. return node.parentNode === root
  12031. },
  12032. root
  12033. )
  12034. }
  12035. var walkBoundary = function (startNode, endNode, next) {
  12036. var siblingName = next ? 'nextSibling' : 'previousSibling'
  12037. for (
  12038. var node = startNode, parent_1 = node.parentNode;
  12039. node && node !== endNode;
  12040. node = parent_1
  12041. ) {
  12042. parent_1 = node.parentNode
  12043. var siblings_1 = collectSiblings(
  12044. node === startNode ? node : node[siblingName],
  12045. siblingName
  12046. )
  12047. if (siblings_1.length) {
  12048. if (!next) {
  12049. siblings_1.reverse()
  12050. }
  12051. callback(exclude(siblings_1))
  12052. }
  12053. }
  12054. }
  12055. if (startContainer === endContainer) {
  12056. return callback(exclude([startContainer]))
  12057. }
  12058. var ancestor = dom.findCommonAncestor(startContainer, endContainer)
  12059. if (dom.isChildOf(startContainer, endContainer)) {
  12060. return walkBoundary(startContainer, ancestor, true)
  12061. }
  12062. if (dom.isChildOf(endContainer, startContainer)) {
  12063. return walkBoundary(endContainer, ancestor)
  12064. }
  12065. var startPoint = findEndPoint(startContainer, ancestor) || startContainer
  12066. var endPoint = findEndPoint(endContainer, ancestor) || endContainer
  12067. walkBoundary(startContainer, startPoint, true)
  12068. var siblings = collectSiblings(
  12069. startPoint === startContainer ? startPoint : startPoint.nextSibling,
  12070. 'nextSibling',
  12071. endPoint === endContainer ? endPoint.nextSibling : endPoint
  12072. )
  12073. if (siblings.length) {
  12074. callback(exclude(siblings))
  12075. }
  12076. walkBoundary(endContainer, endPoint)
  12077. }
  12078. var getRanges = function (selection) {
  12079. var ranges = []
  12080. if (selection) {
  12081. for (var i = 0; i < selection.rangeCount; i++) {
  12082. ranges.push(selection.getRangeAt(i))
  12083. }
  12084. }
  12085. return ranges
  12086. }
  12087. var getSelectedNodes = function (ranges) {
  12088. return bind(ranges, function (range) {
  12089. var node = getSelectedNode(range)
  12090. return node ? [SugarElement.fromDom(node)] : []
  12091. })
  12092. }
  12093. var hasMultipleRanges = function (selection) {
  12094. return getRanges(selection).length > 1
  12095. }
  12096. var getCellsFromRanges = function (ranges) {
  12097. return filter$4(getSelectedNodes(ranges), isTableCell$4)
  12098. }
  12099. var getCellsFromElement = function (elm) {
  12100. return descendants(elm, 'td[data-mce-selected],th[data-mce-selected]')
  12101. }
  12102. var getCellsFromElementOrRanges = function (ranges, element) {
  12103. var selectedCells = getCellsFromElement(element)
  12104. return selectedCells.length > 0 ? selectedCells : getCellsFromRanges(ranges)
  12105. }
  12106. var getCellsFromEditor = function (editor) {
  12107. return getCellsFromElementOrRanges(
  12108. getRanges(editor.selection.getSel()),
  12109. SugarElement.fromDom(editor.getBody())
  12110. )
  12111. }
  12112. var getClosestTable = function (cell, isRoot) {
  12113. return ancestor$2(cell, 'table', isRoot)
  12114. }
  12115. var getStartNode = function (rng) {
  12116. var sc = rng.startContainer,
  12117. so = rng.startOffset
  12118. if (isText$7(sc)) {
  12119. return so === 0
  12120. ? Optional.some(SugarElement.fromDom(sc))
  12121. : Optional.none()
  12122. } else {
  12123. return Optional.from(sc.childNodes[so]).map(SugarElement.fromDom)
  12124. }
  12125. }
  12126. var getEndNode = function (rng) {
  12127. var ec = rng.endContainer,
  12128. eo = rng.endOffset
  12129. if (isText$7(ec)) {
  12130. return eo === ec.data.length
  12131. ? Optional.some(SugarElement.fromDom(ec))
  12132. : Optional.none()
  12133. } else {
  12134. return Optional.from(ec.childNodes[eo - 1]).map(SugarElement.fromDom)
  12135. }
  12136. }
  12137. var getFirstChildren = function (node) {
  12138. return firstChild(node).fold(constant([node]), function (child) {
  12139. return [node].concat(getFirstChildren(child))
  12140. })
  12141. }
  12142. var getLastChildren$1 = function (node) {
  12143. return lastChild(node).fold(constant([node]), function (child) {
  12144. if (name(child) === 'br') {
  12145. return prevSibling(child)
  12146. .map(function (sibling) {
  12147. return [node].concat(getLastChildren$1(sibling))
  12148. })
  12149. .getOr([])
  12150. } else {
  12151. return [node].concat(getLastChildren$1(child))
  12152. }
  12153. })
  12154. }
  12155. var hasAllContentsSelected = function (elm, rng) {
  12156. return lift2(
  12157. getStartNode(rng),
  12158. getEndNode(rng),
  12159. function (startNode, endNode) {
  12160. var start = find$3(getFirstChildren(elm), curry(eq, startNode))
  12161. var end = find$3(getLastChildren$1(elm), curry(eq, endNode))
  12162. return start.isSome() && end.isSome()
  12163. }
  12164. ).getOr(false)
  12165. }
  12166. var moveEndPoint = function (dom, rng, node, start) {
  12167. var root = node,
  12168. walker = new DomTreeWalker(node, root)
  12169. var moveCaretBeforeOnEnterElementsMap = filter$3(
  12170. dom.schema.getMoveCaretBeforeOnEnterElements(),
  12171. function (_, name) {
  12172. return !contains$3(['td', 'th', 'table'], name.toLowerCase())
  12173. }
  12174. )
  12175. do {
  12176. if (isText$7(node) && Tools.trim(node.nodeValue).length !== 0) {
  12177. if (start) {
  12178. rng.setStart(node, 0)
  12179. } else {
  12180. rng.setEnd(node, node.nodeValue.length)
  12181. }
  12182. return
  12183. }
  12184. if (moveCaretBeforeOnEnterElementsMap[node.nodeName]) {
  12185. if (start) {
  12186. rng.setStartBefore(node)
  12187. } else {
  12188. if (node.nodeName === 'BR') {
  12189. rng.setEndBefore(node)
  12190. } else {
  12191. rng.setEndAfter(node)
  12192. }
  12193. }
  12194. return
  12195. }
  12196. } while ((node = start ? walker.next() : walker.prev()))
  12197. if (root.nodeName === 'BODY') {
  12198. if (start) {
  12199. rng.setStart(root, 0)
  12200. } else {
  12201. rng.setEnd(root, root.childNodes.length)
  12202. }
  12203. }
  12204. }
  12205. var hasAnyRanges = function (editor) {
  12206. var sel = editor.selection.getSel()
  12207. return sel && sel.rangeCount > 0
  12208. }
  12209. var runOnRanges = function (editor, executor) {
  12210. var fakeSelectionNodes = getCellsFromEditor(editor)
  12211. if (fakeSelectionNodes.length > 0) {
  12212. each$k(fakeSelectionNodes, function (elem) {
  12213. var node = elem.dom
  12214. var fakeNodeRng = editor.dom.createRng()
  12215. fakeNodeRng.setStartBefore(node)
  12216. fakeNodeRng.setEndAfter(node)
  12217. executor(fakeNodeRng, true)
  12218. })
  12219. } else {
  12220. executor(editor.selection.getRng(), false)
  12221. }
  12222. }
  12223. var preserve = function (selection, fillBookmark, executor) {
  12224. var bookmark = getPersistentBookmark(selection, fillBookmark)
  12225. executor(bookmark)
  12226. selection.moveToBookmark(bookmark)
  12227. }
  12228. var NodeValue = function (is, name) {
  12229. var get = function (element) {
  12230. if (!is(element)) {
  12231. throw new Error(
  12232. 'Can only get ' + name + ' value of a ' + name + ' node'
  12233. )
  12234. }
  12235. return getOption(element).getOr('')
  12236. }
  12237. var getOption = function (element) {
  12238. return is(element)
  12239. ? Optional.from(element.dom.nodeValue)
  12240. : Optional.none()
  12241. }
  12242. var set = function (element, value) {
  12243. if (!is(element)) {
  12244. throw new Error(
  12245. 'Can only set raw ' + name + ' value of a ' + name + ' node'
  12246. )
  12247. }
  12248. element.dom.nodeValue = value
  12249. }
  12250. return {
  12251. get: get,
  12252. getOption: getOption,
  12253. set: set,
  12254. }
  12255. }
  12256. var api$1 = NodeValue(isText$8, 'text')
  12257. var get$2 = function (element) {
  12258. return api$1.get(element)
  12259. }
  12260. var isZeroWidth = function (elem) {
  12261. return isText$8(elem) && get$2(elem) === ZWSP$1
  12262. }
  12263. var context = function (editor, elem, wrapName, nodeName) {
  12264. return parent(elem).fold(
  12265. function () {
  12266. return 'skipping'
  12267. },
  12268. function (parent) {
  12269. if (nodeName === 'br' || isZeroWidth(elem)) {
  12270. return 'valid'
  12271. } else if (isAnnotation(elem)) {
  12272. return 'existing'
  12273. } else if (isCaretNode(elem.dom)) {
  12274. return 'caret'
  12275. } else if (
  12276. !isValid(editor, wrapName, nodeName) ||
  12277. !isValid(editor, name(parent), wrapName)
  12278. ) {
  12279. return 'invalid-child'
  12280. } else {
  12281. return 'valid'
  12282. }
  12283. }
  12284. )
  12285. }
  12286. var applyWordGrab = function (editor, rng) {
  12287. var r = expandRng(editor, rng, [{ inline: 'span' }])
  12288. rng.setStart(r.startContainer, r.startOffset)
  12289. rng.setEnd(r.endContainer, r.endOffset)
  12290. editor.selection.setRng(rng)
  12291. }
  12292. var makeAnnotation = function (eDoc, _a, annotationName, decorate) {
  12293. var _b = _a.uid,
  12294. uid = _b === void 0 ? generate('mce-annotation') : _b,
  12295. data = __rest(_a, ['uid'])
  12296. var master = SugarElement.fromTag('span', eDoc)
  12297. add$1(master, annotation())
  12298. set$1(master, '' + dataAnnotationId(), uid)
  12299. set$1(master, '' + dataAnnotation(), annotationName)
  12300. var _c = decorate(uid, data),
  12301. _d = _c.attributes,
  12302. attributes = _d === void 0 ? {} : _d,
  12303. _e = _c.classes,
  12304. classes = _e === void 0 ? [] : _e
  12305. setAll$1(master, attributes)
  12306. add(master, classes)
  12307. return master
  12308. }
  12309. var annotate = function (editor, rng, annotationName, decorate, data) {
  12310. var newWrappers = []
  12311. var master = makeAnnotation(editor.getDoc(), data, annotationName, decorate)
  12312. var wrapper = value()
  12313. var finishWrapper = function () {
  12314. wrapper.clear()
  12315. }
  12316. var getOrOpenWrapper = function () {
  12317. return wrapper.get().getOrThunk(function () {
  12318. var nu = shallow(master)
  12319. newWrappers.push(nu)
  12320. wrapper.set(nu)
  12321. return nu
  12322. })
  12323. }
  12324. var processElements = function (elems) {
  12325. each$k(elems, processElement)
  12326. }
  12327. var processElement = function (elem) {
  12328. var ctx = context(editor, elem, 'span', name(elem))
  12329. switch (ctx) {
  12330. case 'invalid-child': {
  12331. finishWrapper()
  12332. var children$1 = children(elem)
  12333. processElements(children$1)
  12334. finishWrapper()
  12335. break
  12336. }
  12337. case 'valid': {
  12338. var w = getOrOpenWrapper()
  12339. wrap$3(elem, w)
  12340. break
  12341. }
  12342. }
  12343. }
  12344. var processNodes = function (nodes) {
  12345. var elems = map$3(nodes, SugarElement.fromDom)
  12346. processElements(elems)
  12347. }
  12348. walk$2(editor.dom, rng, function (nodes) {
  12349. finishWrapper()
  12350. processNodes(nodes)
  12351. })
  12352. return newWrappers
  12353. }
  12354. var annotateWithBookmark = function (editor, name, settings, data) {
  12355. editor.undoManager.transact(function () {
  12356. var selection = editor.selection
  12357. var initialRng = selection.getRng()
  12358. var hasFakeSelection = getCellsFromEditor(editor).length > 0
  12359. if (initialRng.collapsed && !hasFakeSelection) {
  12360. applyWordGrab(editor, initialRng)
  12361. }
  12362. if (selection.getRng().collapsed && !hasFakeSelection) {
  12363. var wrapper = makeAnnotation(
  12364. editor.getDoc(),
  12365. data,
  12366. name,
  12367. settings.decorate
  12368. )
  12369. set(wrapper, nbsp)
  12370. selection.getRng().insertNode(wrapper.dom)
  12371. selection.select(wrapper.dom)
  12372. } else {
  12373. preserve(selection, false, function () {
  12374. runOnRanges(editor, function (selectionRng) {
  12375. annotate(editor, selectionRng, name, settings.decorate, data)
  12376. })
  12377. })
  12378. }
  12379. })
  12380. }
  12381. var Annotator = function (editor) {
  12382. var registry = create$7()
  12383. setup$m(editor, registry)
  12384. var changes = setup$n(editor)
  12385. return {
  12386. register: function (name, settings) {
  12387. registry.register(name, settings)
  12388. },
  12389. annotate: function (name, data) {
  12390. registry.lookup(name).each(function (settings) {
  12391. annotateWithBookmark(editor, name, settings, data)
  12392. })
  12393. },
  12394. annotationChanged: function (name, callback) {
  12395. changes.addListener(name, callback)
  12396. },
  12397. remove: function (name) {
  12398. identify(editor, Optional.some(name)).each(function (_a) {
  12399. var elements = _a.elements
  12400. each$k(elements, unwrap)
  12401. })
  12402. },
  12403. getAll: function (name) {
  12404. var directory = findAll(editor, name)
  12405. return map$2(directory, function (elems) {
  12406. return map$3(elems, function (elem) {
  12407. return elem.dom
  12408. })
  12409. })
  12410. },
  12411. }
  12412. }
  12413. var BookmarkManager = function (selection) {
  12414. return {
  12415. getBookmark: curry(getBookmark$1, selection),
  12416. moveToBookmark: curry(moveToBookmark, selection),
  12417. }
  12418. }
  12419. BookmarkManager.isBookmarkNode = isBookmarkNode$1
  12420. var getContentEditableRoot$1 = function (root, node) {
  12421. while (node && node !== root) {
  12422. if (isContentEditableTrue$4(node) || isContentEditableFalse$b(node)) {
  12423. return node
  12424. }
  12425. node = node.parentNode
  12426. }
  12427. return null
  12428. }
  12429. var isXYWithinRange = function (clientX, clientY, range) {
  12430. if (range.collapsed) {
  12431. return false
  12432. }
  12433. if (
  12434. Env.browser.isIE() &&
  12435. range.startOffset === range.endOffset - 1 &&
  12436. range.startContainer === range.endContainer
  12437. ) {
  12438. var elm = range.startContainer.childNodes[range.startOffset]
  12439. if (isElement$5(elm)) {
  12440. return exists(elm.getClientRects(), function (rect) {
  12441. return containsXY(rect, clientX, clientY)
  12442. })
  12443. }
  12444. }
  12445. return exists(range.getClientRects(), function (rect) {
  12446. return containsXY(rect, clientX, clientY)
  12447. })
  12448. }
  12449. var firePreProcess = function (editor, args) {
  12450. return editor.fire('PreProcess', args)
  12451. }
  12452. var firePostProcess = function (editor, args) {
  12453. return editor.fire('PostProcess', args)
  12454. }
  12455. var fireRemove = function (editor) {
  12456. return editor.fire('remove')
  12457. }
  12458. var fireDetach = function (editor) {
  12459. return editor.fire('detach')
  12460. }
  12461. var fireSwitchMode = function (editor, mode) {
  12462. return editor.fire('SwitchMode', { mode: mode })
  12463. }
  12464. var fireObjectResizeStart = function (editor, target, width, height, origin) {
  12465. editor.fire('ObjectResizeStart', {
  12466. target: target,
  12467. width: width,
  12468. height: height,
  12469. origin: origin,
  12470. })
  12471. }
  12472. var fireObjectResized = function (editor, target, width, height, origin) {
  12473. editor.fire('ObjectResized', {
  12474. target: target,
  12475. width: width,
  12476. height: height,
  12477. origin: origin,
  12478. })
  12479. }
  12480. var firePreInit = function (editor) {
  12481. return editor.fire('PreInit')
  12482. }
  12483. var firePostRender = function (editor) {
  12484. return editor.fire('PostRender')
  12485. }
  12486. var fireInit = function (editor) {
  12487. return editor.fire('Init')
  12488. }
  12489. var firePlaceholderToggle = function (editor, state) {
  12490. return editor.fire('PlaceholderToggle', { state: state })
  12491. }
  12492. var fireError = function (editor, errorType, error) {
  12493. return editor.fire(errorType, error)
  12494. }
  12495. var fireFormatApply = function (editor, format, node, vars) {
  12496. return editor.fire('FormatApply', {
  12497. format: format,
  12498. node: node,
  12499. vars: vars,
  12500. })
  12501. }
  12502. var fireFormatRemove = function (editor, format, node, vars) {
  12503. return editor.fire('FormatRemove', {
  12504. format: format,
  12505. node: node,
  12506. vars: vars,
  12507. })
  12508. }
  12509. var VK = {
  12510. BACKSPACE: 8,
  12511. DELETE: 46,
  12512. DOWN: 40,
  12513. ENTER: 13,
  12514. ESC: 27,
  12515. LEFT: 37,
  12516. RIGHT: 39,
  12517. SPACEBAR: 32,
  12518. TAB: 9,
  12519. UP: 38,
  12520. PAGE_UP: 33,
  12521. PAGE_DOWN: 34,
  12522. END: 35,
  12523. HOME: 36,
  12524. modifierPressed: function (e) {
  12525. return e.shiftKey || e.ctrlKey || e.altKey || VK.metaKeyPressed(e)
  12526. },
  12527. metaKeyPressed: function (e) {
  12528. return Env.mac ? e.metaKey : e.ctrlKey && !e.altKey
  12529. },
  12530. }
  12531. var isContentEditableFalse$5 = isContentEditableFalse$b
  12532. var ControlSelection = function (selection, editor) {
  12533. var elementSelectionAttr = 'data-mce-selected'
  12534. var dom = editor.dom,
  12535. each = Tools.each
  12536. var selectedElm,
  12537. selectedElmGhost,
  12538. resizeHelper,
  12539. selectedHandle,
  12540. resizeBackdrop
  12541. var startX,
  12542. startY,
  12543. selectedElmX,
  12544. selectedElmY,
  12545. startW,
  12546. startH,
  12547. ratio,
  12548. resizeStarted
  12549. var width, height
  12550. var editableDoc = editor.getDoc(),
  12551. rootDocument = document
  12552. var abs = Math.abs,
  12553. round = Math.round,
  12554. rootElement = editor.getBody()
  12555. var startScrollWidth, startScrollHeight
  12556. var resizeHandles = {
  12557. nw: [0, 0, -1, -1],
  12558. ne: [1, 0, 1, -1],
  12559. se: [1, 1, 1, 1],
  12560. sw: [0, 1, -1, 1],
  12561. }
  12562. var isImage = function (elm) {
  12563. return (
  12564. elm && (elm.nodeName === 'IMG' || editor.dom.is(elm, 'figure.image'))
  12565. )
  12566. }
  12567. var isMedia = function (elm) {
  12568. return isMedia$2(elm) || dom.hasClass(elm, 'mce-preview-object')
  12569. }
  12570. var isEventOnImageOutsideRange = function (evt, range) {
  12571. if (evt.type === 'longpress' || evt.type.indexOf('touch') === 0) {
  12572. var touch = evt.touches[0]
  12573. return (
  12574. isImage(evt.target) &&
  12575. !isXYWithinRange(touch.clientX, touch.clientY, range)
  12576. )
  12577. } else {
  12578. return (
  12579. isImage(evt.target) &&
  12580. !isXYWithinRange(evt.clientX, evt.clientY, range)
  12581. )
  12582. }
  12583. }
  12584. var contextMenuSelectImage = function (evt) {
  12585. var target = evt.target
  12586. if (
  12587. isEventOnImageOutsideRange(evt, editor.selection.getRng()) &&
  12588. !evt.isDefaultPrevented()
  12589. ) {
  12590. editor.selection.select(target)
  12591. }
  12592. }
  12593. var getResizeTargets = function (elm) {
  12594. if (dom.is(elm, 'figure.image')) {
  12595. return [elm.querySelector('img')]
  12596. } else if (
  12597. dom.hasClass(elm, 'mce-preview-object') &&
  12598. isNonNullable(elm.firstElementChild)
  12599. ) {
  12600. return [elm, elm.firstElementChild]
  12601. } else {
  12602. return [elm]
  12603. }
  12604. }
  12605. var isResizable = function (elm) {
  12606. var selector = getObjectResizing(editor)
  12607. if (!selector) {
  12608. return false
  12609. }
  12610. if (elm.getAttribute('data-mce-resize') === 'false') {
  12611. return false
  12612. }
  12613. if (elm === editor.getBody()) {
  12614. return false
  12615. }
  12616. if (dom.hasClass(elm, 'mce-preview-object')) {
  12617. return is$2(SugarElement.fromDom(elm.firstElementChild), selector)
  12618. } else {
  12619. return is$2(SugarElement.fromDom(elm), selector)
  12620. }
  12621. }
  12622. var createGhostElement = function (elm) {
  12623. if (isMedia(elm)) {
  12624. return dom.create('img', { src: Env.transparentSrc })
  12625. } else {
  12626. return elm.cloneNode(true)
  12627. }
  12628. }
  12629. var setSizeProp = function (element, name, value) {
  12630. if (isNonNullable(value)) {
  12631. var targets = getResizeTargets(element)
  12632. each$k(targets, function (target) {
  12633. if (
  12634. target.style[name] ||
  12635. !editor.schema.isValid(target.nodeName.toLowerCase(), name)
  12636. ) {
  12637. dom.setStyle(target, name, value)
  12638. } else {
  12639. dom.setAttrib(target, name, '' + value)
  12640. }
  12641. })
  12642. }
  12643. }
  12644. var setGhostElmSize = function (ghostElm, width, height) {
  12645. setSizeProp(ghostElm, 'width', width)
  12646. setSizeProp(ghostElm, 'height', height)
  12647. }
  12648. var resizeGhostElement = function (e) {
  12649. var deltaX, deltaY, proportional
  12650. var resizeHelperX, resizeHelperY
  12651. deltaX = e.screenX - startX
  12652. deltaY = e.screenY - startY
  12653. width = deltaX * selectedHandle[2] + startW
  12654. height = deltaY * selectedHandle[3] + startH
  12655. width = width < 5 ? 5 : width
  12656. height = height < 5 ? 5 : height
  12657. if (
  12658. (isImage(selectedElm) || isMedia(selectedElm)) &&
  12659. getResizeImgProportional(editor) !== false
  12660. ) {
  12661. proportional = !VK.modifierPressed(e)
  12662. } else {
  12663. proportional = VK.modifierPressed(e)
  12664. }
  12665. if (proportional) {
  12666. if (abs(deltaX) > abs(deltaY)) {
  12667. height = round(width * ratio)
  12668. width = round(height / ratio)
  12669. } else {
  12670. width = round(height / ratio)
  12671. height = round(width * ratio)
  12672. }
  12673. }
  12674. setGhostElmSize(selectedElmGhost, width, height)
  12675. resizeHelperX = selectedHandle.startPos.x + deltaX
  12676. resizeHelperY = selectedHandle.startPos.y + deltaY
  12677. resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0
  12678. resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0
  12679. dom.setStyles(resizeHelper, {
  12680. left: resizeHelperX,
  12681. top: resizeHelperY,
  12682. display: 'block',
  12683. })
  12684. resizeHelper.innerHTML = width + ' &times; ' + height
  12685. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  12686. dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width))
  12687. }
  12688. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  12689. dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height))
  12690. }
  12691. deltaX = rootElement.scrollWidth - startScrollWidth
  12692. deltaY = rootElement.scrollHeight - startScrollHeight
  12693. if (deltaX + deltaY !== 0) {
  12694. dom.setStyles(resizeHelper, {
  12695. left: resizeHelperX - deltaX,
  12696. top: resizeHelperY - deltaY,
  12697. })
  12698. }
  12699. if (!resizeStarted) {
  12700. fireObjectResizeStart(
  12701. editor,
  12702. selectedElm,
  12703. startW,
  12704. startH,
  12705. 'corner-' + selectedHandle.name
  12706. )
  12707. resizeStarted = true
  12708. }
  12709. }
  12710. var endGhostResize = function () {
  12711. var wasResizeStarted = resizeStarted
  12712. resizeStarted = false
  12713. if (wasResizeStarted) {
  12714. setSizeProp(selectedElm, 'width', width)
  12715. setSizeProp(selectedElm, 'height', height)
  12716. }
  12717. dom.unbind(editableDoc, 'mousemove', resizeGhostElement)
  12718. dom.unbind(editableDoc, 'mouseup', endGhostResize)
  12719. if (rootDocument !== editableDoc) {
  12720. dom.unbind(rootDocument, 'mousemove', resizeGhostElement)
  12721. dom.unbind(rootDocument, 'mouseup', endGhostResize)
  12722. }
  12723. dom.remove(selectedElmGhost)
  12724. dom.remove(resizeHelper)
  12725. dom.remove(resizeBackdrop)
  12726. showResizeRect(selectedElm)
  12727. if (wasResizeStarted) {
  12728. fireObjectResized(
  12729. editor,
  12730. selectedElm,
  12731. width,
  12732. height,
  12733. 'corner-' + selectedHandle.name
  12734. )
  12735. dom.setAttrib(selectedElm, 'style', dom.getAttrib(selectedElm, 'style'))
  12736. }
  12737. editor.nodeChanged()
  12738. }
  12739. var showResizeRect = function (targetElm) {
  12740. unbindResizeHandleEvents()
  12741. var position = dom.getPos(targetElm, rootElement)
  12742. var selectedElmX = position.x
  12743. var selectedElmY = position.y
  12744. var rect = targetElm.getBoundingClientRect()
  12745. var targetWidth = rect.width || rect.right - rect.left
  12746. var targetHeight = rect.height || rect.bottom - rect.top
  12747. if (selectedElm !== targetElm) {
  12748. hideResizeRect()
  12749. selectedElm = targetElm
  12750. width = height = 0
  12751. }
  12752. var e = editor.fire('ObjectSelected', { target: targetElm })
  12753. var selectedValue = dom.getAttrib(selectedElm, elementSelectionAttr, '1')
  12754. if (isResizable(targetElm) && !e.isDefaultPrevented()) {
  12755. each(resizeHandles, function (handle, name) {
  12756. var handleElm
  12757. var startDrag = function (e) {
  12758. var target = getResizeTargets(selectedElm)[0]
  12759. startX = e.screenX
  12760. startY = e.screenY
  12761. startW = target.clientWidth
  12762. startH = target.clientHeight
  12763. ratio = startH / startW
  12764. selectedHandle = handle
  12765. selectedHandle.name = name
  12766. selectedHandle.startPos = {
  12767. x: targetWidth * handle[0] + selectedElmX,
  12768. y: targetHeight * handle[1] + selectedElmY,
  12769. }
  12770. startScrollWidth = rootElement.scrollWidth
  12771. startScrollHeight = rootElement.scrollHeight
  12772. resizeBackdrop = dom.add(rootElement, 'div', {
  12773. class: 'mce-resize-backdrop',
  12774. 'data-mce-bogus': 'all',
  12775. })
  12776. dom.setStyles(resizeBackdrop, {
  12777. position: 'fixed',
  12778. left: '0',
  12779. top: '0',
  12780. width: '100%',
  12781. height: '100%',
  12782. })
  12783. selectedElmGhost = createGhostElement(selectedElm)
  12784. dom.addClass(selectedElmGhost, 'mce-clonedresizable')
  12785. dom.setAttrib(selectedElmGhost, 'data-mce-bogus', 'all')
  12786. selectedElmGhost.contentEditable = 'false'
  12787. dom.setStyles(selectedElmGhost, {
  12788. left: selectedElmX,
  12789. top: selectedElmY,
  12790. margin: 0,
  12791. })
  12792. setGhostElmSize(selectedElmGhost, targetWidth, targetHeight)
  12793. selectedElmGhost.removeAttribute(elementSelectionAttr)
  12794. rootElement.appendChild(selectedElmGhost)
  12795. dom.bind(editableDoc, 'mousemove', resizeGhostElement)
  12796. dom.bind(editableDoc, 'mouseup', endGhostResize)
  12797. if (rootDocument !== editableDoc) {
  12798. dom.bind(rootDocument, 'mousemove', resizeGhostElement)
  12799. dom.bind(rootDocument, 'mouseup', endGhostResize)
  12800. }
  12801. resizeHelper = dom.add(
  12802. rootElement,
  12803. 'div',
  12804. {
  12805. class: 'mce-resize-helper',
  12806. 'data-mce-bogus': 'all',
  12807. },
  12808. startW + ' &times; ' + startH
  12809. )
  12810. }
  12811. handleElm = dom.get('mceResizeHandle' + name)
  12812. if (handleElm) {
  12813. dom.remove(handleElm)
  12814. }
  12815. handleElm = dom.add(rootElement, 'div', {
  12816. id: 'mceResizeHandle' + name,
  12817. 'data-mce-bogus': 'all',
  12818. class: 'mce-resizehandle',
  12819. unselectable: true,
  12820. style: 'cursor:' + name + '-resize; margin:0; padding:0',
  12821. })
  12822. if (Env.ie === 11) {
  12823. handleElm.contentEditable = false
  12824. }
  12825. dom.bind(handleElm, 'mousedown', function (e) {
  12826. e.stopImmediatePropagation()
  12827. e.preventDefault()
  12828. startDrag(e)
  12829. })
  12830. handle.elm = handleElm
  12831. dom.setStyles(handleElm, {
  12832. left:
  12833. targetWidth * handle[0] +
  12834. selectedElmX -
  12835. handleElm.offsetWidth / 2,
  12836. top:
  12837. targetHeight * handle[1] +
  12838. selectedElmY -
  12839. handleElm.offsetHeight / 2,
  12840. })
  12841. })
  12842. } else {
  12843. hideResizeRect()
  12844. }
  12845. if (!dom.getAttrib(selectedElm, elementSelectionAttr)) {
  12846. selectedElm.setAttribute(elementSelectionAttr, selectedValue)
  12847. }
  12848. }
  12849. var hideResizeRect = function () {
  12850. unbindResizeHandleEvents()
  12851. if (selectedElm) {
  12852. selectedElm.removeAttribute(elementSelectionAttr)
  12853. }
  12854. each$j(resizeHandles, function (value, name) {
  12855. var handleElm = dom.get('mceResizeHandle' + name)
  12856. if (handleElm) {
  12857. dom.unbind(handleElm)
  12858. dom.remove(handleElm)
  12859. }
  12860. })
  12861. }
  12862. var updateResizeRect = function (e) {
  12863. var startElm, controlElm
  12864. var isChildOrEqual = function (node, parent) {
  12865. if (node) {
  12866. do {
  12867. if (node === parent) {
  12868. return true
  12869. }
  12870. } while ((node = node.parentNode))
  12871. }
  12872. }
  12873. if (resizeStarted || editor.removed) {
  12874. return
  12875. }
  12876. each(
  12877. dom.select('img[data-mce-selected],hr[data-mce-selected]'),
  12878. function (img) {
  12879. img.removeAttribute(elementSelectionAttr)
  12880. }
  12881. )
  12882. controlElm = e.type === 'mousedown' ? e.target : selection.getNode()
  12883. controlElm = dom
  12884. .$(controlElm)
  12885. .closest('table,img,figure.image,hr,video,span.mce-preview-object')[0]
  12886. if (isChildOrEqual(controlElm, rootElement)) {
  12887. disableGeckoResize()
  12888. startElm = selection.getStart(true)
  12889. if (
  12890. isChildOrEqual(startElm, controlElm) &&
  12891. isChildOrEqual(selection.getEnd(true), controlElm)
  12892. ) {
  12893. showResizeRect(controlElm)
  12894. return
  12895. }
  12896. }
  12897. hideResizeRect()
  12898. }
  12899. var isWithinContentEditableFalse = function (elm) {
  12900. return isContentEditableFalse$5(
  12901. getContentEditableRoot$1(editor.getBody(), elm)
  12902. )
  12903. }
  12904. var unbindResizeHandleEvents = function () {
  12905. each$j(resizeHandles, function (handle) {
  12906. if (handle.elm) {
  12907. dom.unbind(handle.elm)
  12908. delete handle.elm
  12909. }
  12910. })
  12911. }
  12912. var disableGeckoResize = function () {
  12913. try {
  12914. editor.getDoc().execCommand('enableObjectResizing', false, 'false')
  12915. } catch (ex) {}
  12916. }
  12917. editor.on('init', function () {
  12918. disableGeckoResize()
  12919. if (Env.browser.isIE() || Env.browser.isEdge()) {
  12920. editor.on('mousedown click', function (e) {
  12921. var target = e.target,
  12922. nodeName = target.nodeName
  12923. if (
  12924. !resizeStarted &&
  12925. /^(TABLE|IMG|HR)$/.test(nodeName) &&
  12926. !isWithinContentEditableFalse(target)
  12927. ) {
  12928. if (e.button !== 2) {
  12929. editor.selection.select(target, nodeName === 'TABLE')
  12930. }
  12931. if (e.type === 'mousedown') {
  12932. editor.nodeChanged()
  12933. }
  12934. }
  12935. })
  12936. var handleMSControlSelect_1 = function (e) {
  12937. var delayedSelect = function (node) {
  12938. Delay.setEditorTimeout(editor, function () {
  12939. return editor.selection.select(node)
  12940. })
  12941. }
  12942. if (isWithinContentEditableFalse(e.target) || isMedia$2(e.target)) {
  12943. e.preventDefault()
  12944. delayedSelect(e.target)
  12945. return
  12946. }
  12947. if (/^(TABLE|IMG|HR)$/.test(e.target.nodeName)) {
  12948. e.preventDefault()
  12949. if (e.target.tagName === 'IMG') {
  12950. delayedSelect(e.target)
  12951. }
  12952. }
  12953. }
  12954. dom.bind(rootElement, 'mscontrolselect', handleMSControlSelect_1)
  12955. editor.on('remove', function () {
  12956. return dom.unbind(
  12957. rootElement,
  12958. 'mscontrolselect',
  12959. handleMSControlSelect_1
  12960. )
  12961. })
  12962. }
  12963. var throttledUpdateResizeRect = Delay.throttle(function (e) {
  12964. if (!editor.composing) {
  12965. updateResizeRect(e)
  12966. }
  12967. })
  12968. editor.on(
  12969. 'nodechange ResizeEditor ResizeWindow ResizeContent drop FullscreenStateChanged',
  12970. throttledUpdateResizeRect
  12971. )
  12972. editor.on('keyup compositionend', function (e) {
  12973. if (selectedElm && selectedElm.nodeName === 'TABLE') {
  12974. throttledUpdateResizeRect(e)
  12975. }
  12976. })
  12977. editor.on('hide blur', hideResizeRect)
  12978. editor.on('contextmenu longpress', contextMenuSelectImage, true)
  12979. })
  12980. editor.on('remove', unbindResizeHandleEvents)
  12981. var destroy = function () {
  12982. selectedElm = selectedElmGhost = resizeBackdrop = null
  12983. }
  12984. return {
  12985. isResizable: isResizable,
  12986. showResizeRect: showResizeRect,
  12987. hideResizeRect: hideResizeRect,
  12988. updateResizeRect: updateResizeRect,
  12989. destroy: destroy,
  12990. }
  12991. }
  12992. var hasCeProperty = function (node) {
  12993. return isContentEditableTrue$4(node) || isContentEditableFalse$b(node)
  12994. }
  12995. var findParent$1 = function (node, rootNode, predicate) {
  12996. while (node && node !== rootNode) {
  12997. if (predicate(node)) {
  12998. return node
  12999. }
  13000. node = node.parentNode
  13001. }
  13002. return null
  13003. }
  13004. var findClosestIeRange = function (clientX, clientY, doc) {
  13005. var rects
  13006. var element = doc.elementFromPoint(clientX, clientY)
  13007. var rng = doc.body.createTextRange()
  13008. if (!element || element.tagName === 'HTML') {
  13009. element = doc.body
  13010. }
  13011. rng.moveToElementText(element)
  13012. rects = Tools.toArray(rng.getClientRects())
  13013. rects = rects.sort(function (a, b) {
  13014. a = Math.abs(Math.max(a.top - clientY, a.bottom - clientY))
  13015. b = Math.abs(Math.max(b.top - clientY, b.bottom - clientY))
  13016. return a - b
  13017. })
  13018. if (rects.length > 0) {
  13019. clientY = (rects[0].bottom + rects[0].top) / 2
  13020. try {
  13021. rng.moveToPoint(clientX, clientY)
  13022. rng.collapse(true)
  13023. return rng
  13024. } catch (ex) {}
  13025. }
  13026. return null
  13027. }
  13028. var moveOutOfContentEditableFalse = function (rng, rootNode) {
  13029. var parentElement = rng && rng.parentElement ? rng.parentElement() : null
  13030. return isContentEditableFalse$b(
  13031. findParent$1(parentElement, rootNode, hasCeProperty)
  13032. )
  13033. ? null
  13034. : rng
  13035. }
  13036. var fromPoint = function (clientX, clientY, doc) {
  13037. var rng, point
  13038. var pointDoc = doc
  13039. if (pointDoc.caretPositionFromPoint) {
  13040. point = pointDoc.caretPositionFromPoint(clientX, clientY)
  13041. if (point) {
  13042. rng = doc.createRange()
  13043. rng.setStart(point.offsetNode, point.offset)
  13044. rng.collapse(true)
  13045. }
  13046. } else if (pointDoc.caretRangeFromPoint) {
  13047. rng = pointDoc.caretRangeFromPoint(clientX, clientY)
  13048. } else if (pointDoc.body.createTextRange) {
  13049. rng = pointDoc.body.createTextRange()
  13050. try {
  13051. rng.moveToPoint(clientX, clientY)
  13052. rng.collapse(true)
  13053. } catch (ex) {
  13054. rng = findClosestIeRange(clientX, clientY, doc)
  13055. }
  13056. return moveOutOfContentEditableFalse(rng, doc.body)
  13057. }
  13058. return rng
  13059. }
  13060. var isEq$4 = function (rng1, rng2) {
  13061. return (
  13062. rng1 &&
  13063. rng2 &&
  13064. rng1.startContainer === rng2.startContainer &&
  13065. rng1.startOffset === rng2.startOffset &&
  13066. rng1.endContainer === rng2.endContainer &&
  13067. rng1.endOffset === rng2.endOffset
  13068. )
  13069. }
  13070. var findParent = function (node, rootNode, predicate) {
  13071. while (node && node !== rootNode) {
  13072. if (predicate(node)) {
  13073. return node
  13074. }
  13075. node = node.parentNode
  13076. }
  13077. return null
  13078. }
  13079. var hasParent$1 = function (node, rootNode, predicate) {
  13080. return findParent(node, rootNode, predicate) !== null
  13081. }
  13082. var hasParentWithName = function (node, rootNode, name) {
  13083. return hasParent$1(node, rootNode, function (node) {
  13084. return node.nodeName === name
  13085. })
  13086. }
  13087. var isTable = function (node) {
  13088. return node && node.nodeName === 'TABLE'
  13089. }
  13090. var isTableCell$2 = function (node) {
  13091. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName)
  13092. }
  13093. var isCeFalseCaretContainer = function (node, rootNode) {
  13094. return (
  13095. isCaretContainer$2(node) &&
  13096. hasParent$1(node, rootNode, isCaretNode) === false
  13097. )
  13098. }
  13099. var hasBrBeforeAfter = function (dom, node, left) {
  13100. var walker = new DomTreeWalker(
  13101. node,
  13102. dom.getParent(node.parentNode, dom.isBlock) || dom.getRoot()
  13103. )
  13104. while ((node = walker[left ? 'prev' : 'next']())) {
  13105. if (isBr$5(node)) {
  13106. return true
  13107. }
  13108. }
  13109. }
  13110. var isPrevNode = function (node, name) {
  13111. return node.previousSibling && node.previousSibling.nodeName === name
  13112. }
  13113. var hasContentEditableFalseParent = function (body, node) {
  13114. while (node && node !== body) {
  13115. if (isContentEditableFalse$b(node)) {
  13116. return true
  13117. }
  13118. node = node.parentNode
  13119. }
  13120. return false
  13121. }
  13122. var findTextNodeRelative = function (
  13123. dom,
  13124. isAfterNode,
  13125. collapsed,
  13126. left,
  13127. startNode
  13128. ) {
  13129. var lastInlineElement
  13130. var body = dom.getRoot()
  13131. var node
  13132. var nonEmptyElementsMap = dom.schema.getNonEmptyElements()
  13133. var parentBlockContainer =
  13134. dom.getParent(startNode.parentNode, dom.isBlock) || body
  13135. if (
  13136. left &&
  13137. isBr$5(startNode) &&
  13138. isAfterNode &&
  13139. dom.isEmpty(parentBlockContainer)
  13140. ) {
  13141. return Optional.some(
  13142. CaretPosition(startNode.parentNode, dom.nodeIndex(startNode))
  13143. )
  13144. }
  13145. var walker = new DomTreeWalker(startNode, parentBlockContainer)
  13146. while ((node = walker[left ? 'prev' : 'next']())) {
  13147. if (
  13148. dom.getContentEditableParent(node) === 'false' ||
  13149. isCeFalseCaretContainer(node, body)
  13150. ) {
  13151. return Optional.none()
  13152. }
  13153. if (isText$7(node) && node.nodeValue.length > 0) {
  13154. if (hasParentWithName(node, body, 'A') === false) {
  13155. return Optional.some(
  13156. CaretPosition(node, left ? node.nodeValue.length : 0)
  13157. )
  13158. }
  13159. return Optional.none()
  13160. }
  13161. if (
  13162. dom.isBlock(node) ||
  13163. nonEmptyElementsMap[node.nodeName.toLowerCase()]
  13164. ) {
  13165. return Optional.none()
  13166. }
  13167. lastInlineElement = node
  13168. }
  13169. if (collapsed && lastInlineElement) {
  13170. return Optional.some(CaretPosition(lastInlineElement, 0))
  13171. }
  13172. return Optional.none()
  13173. }
  13174. var normalizeEndPoint = function (dom, collapsed, start, rng) {
  13175. var container, offset
  13176. var body = dom.getRoot()
  13177. var node
  13178. var directionLeft,
  13179. normalized = false
  13180. container = rng[(start ? 'start' : 'end') + 'Container']
  13181. offset = rng[(start ? 'start' : 'end') + 'Offset']
  13182. var isAfterNode =
  13183. isElement$5(container) && offset === container.childNodes.length
  13184. var nonEmptyElementsMap = dom.schema.getNonEmptyElements()
  13185. directionLeft = start
  13186. if (isCaretContainer$2(container)) {
  13187. return Optional.none()
  13188. }
  13189. if (isElement$5(container) && offset > container.childNodes.length - 1) {
  13190. directionLeft = false
  13191. }
  13192. if (isDocument$1(container)) {
  13193. container = body
  13194. offset = 0
  13195. }
  13196. if (container === body) {
  13197. if (directionLeft) {
  13198. node = container.childNodes[offset > 0 ? offset - 1 : 0]
  13199. if (node) {
  13200. if (isCaretContainer$2(node)) {
  13201. return Optional.none()
  13202. }
  13203. if (nonEmptyElementsMap[node.nodeName] || isTable(node)) {
  13204. return Optional.none()
  13205. }
  13206. }
  13207. }
  13208. if (container.hasChildNodes()) {
  13209. offset = Math.min(
  13210. !directionLeft && offset > 0 ? offset - 1 : offset,
  13211. container.childNodes.length - 1
  13212. )
  13213. container = container.childNodes[offset]
  13214. offset = isText$7(container) && isAfterNode ? container.data.length : 0
  13215. if (!collapsed && container === body.lastChild && isTable(container)) {
  13216. return Optional.none()
  13217. }
  13218. if (
  13219. hasContentEditableFalseParent(body, container) ||
  13220. isCaretContainer$2(container)
  13221. ) {
  13222. return Optional.none()
  13223. }
  13224. if (container.hasChildNodes() && isTable(container) === false) {
  13225. node = container
  13226. var walker = new DomTreeWalker(container, body)
  13227. do {
  13228. if (isContentEditableFalse$b(node) || isCaretContainer$2(node)) {
  13229. normalized = false
  13230. break
  13231. }
  13232. if (isText$7(node) && node.nodeValue.length > 0) {
  13233. offset = directionLeft ? 0 : node.nodeValue.length
  13234. container = node
  13235. normalized = true
  13236. break
  13237. }
  13238. if (
  13239. nonEmptyElementsMap[node.nodeName.toLowerCase()] &&
  13240. !isTableCell$2(node)
  13241. ) {
  13242. offset = dom.nodeIndex(node)
  13243. container = node.parentNode
  13244. if (!directionLeft) {
  13245. offset++
  13246. }
  13247. normalized = true
  13248. break
  13249. }
  13250. } while ((node = directionLeft ? walker.next() : walker.prev()))
  13251. }
  13252. }
  13253. }
  13254. if (collapsed) {
  13255. if (isText$7(container) && offset === 0) {
  13256. findTextNodeRelative(dom, isAfterNode, collapsed, true, container).each(
  13257. function (pos) {
  13258. container = pos.container()
  13259. offset = pos.offset()
  13260. normalized = true
  13261. }
  13262. )
  13263. }
  13264. if (isElement$5(container)) {
  13265. node = container.childNodes[offset]
  13266. if (!node) {
  13267. node = container.childNodes[offset - 1]
  13268. }
  13269. if (
  13270. node &&
  13271. isBr$5(node) &&
  13272. !isPrevNode(node, 'A') &&
  13273. !hasBrBeforeAfter(dom, node, false) &&
  13274. !hasBrBeforeAfter(dom, node, true)
  13275. ) {
  13276. findTextNodeRelative(dom, isAfterNode, collapsed, true, node).each(
  13277. function (pos) {
  13278. container = pos.container()
  13279. offset = pos.offset()
  13280. normalized = true
  13281. }
  13282. )
  13283. }
  13284. }
  13285. }
  13286. if (
  13287. directionLeft &&
  13288. !collapsed &&
  13289. isText$7(container) &&
  13290. offset === container.nodeValue.length
  13291. ) {
  13292. findTextNodeRelative(dom, isAfterNode, collapsed, false, container).each(
  13293. function (pos) {
  13294. container = pos.container()
  13295. offset = pos.offset()
  13296. normalized = true
  13297. }
  13298. )
  13299. }
  13300. return normalized
  13301. ? Optional.some(CaretPosition(container, offset))
  13302. : Optional.none()
  13303. }
  13304. var normalize$2 = function (dom, rng) {
  13305. var collapsed = rng.collapsed,
  13306. normRng = rng.cloneRange()
  13307. var startPos = CaretPosition.fromRangeStart(rng)
  13308. normalizeEndPoint(dom, collapsed, true, normRng).each(function (pos) {
  13309. if (!collapsed || !CaretPosition.isAbove(startPos, pos)) {
  13310. normRng.setStart(pos.container(), pos.offset())
  13311. }
  13312. })
  13313. if (!collapsed) {
  13314. normalizeEndPoint(dom, collapsed, false, normRng).each(function (pos) {
  13315. normRng.setEnd(pos.container(), pos.offset())
  13316. })
  13317. }
  13318. if (collapsed) {
  13319. normRng.collapse(true)
  13320. }
  13321. return isEq$4(rng, normRng) ? Optional.none() : Optional.some(normRng)
  13322. }
  13323. var splitText = function (node, offset) {
  13324. return node.splitText(offset)
  13325. }
  13326. var split = function (rng) {
  13327. var startContainer = rng.startContainer,
  13328. startOffset = rng.startOffset,
  13329. endContainer = rng.endContainer,
  13330. endOffset = rng.endOffset
  13331. if (startContainer === endContainer && isText$7(startContainer)) {
  13332. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  13333. endContainer = splitText(startContainer, startOffset)
  13334. startContainer = endContainer.previousSibling
  13335. if (endOffset > startOffset) {
  13336. endOffset = endOffset - startOffset
  13337. startContainer = endContainer = splitText(
  13338. endContainer,
  13339. endOffset
  13340. ).previousSibling
  13341. endOffset = endContainer.nodeValue.length
  13342. startOffset = 0
  13343. } else {
  13344. endOffset = 0
  13345. }
  13346. }
  13347. } else {
  13348. if (
  13349. isText$7(startContainer) &&
  13350. startOffset > 0 &&
  13351. startOffset < startContainer.nodeValue.length
  13352. ) {
  13353. startContainer = splitText(startContainer, startOffset)
  13354. startOffset = 0
  13355. }
  13356. if (
  13357. isText$7(endContainer) &&
  13358. endOffset > 0 &&
  13359. endOffset < endContainer.nodeValue.length
  13360. ) {
  13361. endContainer = splitText(endContainer, endOffset).previousSibling
  13362. endOffset = endContainer.nodeValue.length
  13363. }
  13364. }
  13365. return {
  13366. startContainer: startContainer,
  13367. startOffset: startOffset,
  13368. endContainer: endContainer,
  13369. endOffset: endOffset,
  13370. }
  13371. }
  13372. var RangeUtils = function (dom) {
  13373. var walk = function (rng, callback) {
  13374. return walk$2(dom, rng, callback)
  13375. }
  13376. var split$1 = split
  13377. var normalize = function (rng) {
  13378. return normalize$2(dom, rng).fold(never, function (normalizedRng) {
  13379. rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset)
  13380. rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset)
  13381. return true
  13382. })
  13383. }
  13384. return {
  13385. walk: walk,
  13386. split: split$1,
  13387. normalize: normalize,
  13388. }
  13389. }
  13390. RangeUtils.compareRanges = isEq$4
  13391. RangeUtils.getCaretRangeFromPoint = fromPoint
  13392. RangeUtils.getSelectedNode = getSelectedNode
  13393. RangeUtils.getNode = getNode$1
  13394. var Dimension = function (name, getOffset) {
  13395. var set = function (element, h) {
  13396. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  13397. throw new Error(
  13398. name + '.set accepts only positive integer values. Value was ' + h
  13399. )
  13400. }
  13401. var dom = element.dom
  13402. if (isSupported(dom)) {
  13403. dom.style[name] = h + 'px'
  13404. }
  13405. }
  13406. var get = function (element) {
  13407. var r = getOffset(element)
  13408. if (r <= 0 || r === null) {
  13409. var css = get$5(element, name)
  13410. return parseFloat(css) || 0
  13411. }
  13412. return r
  13413. }
  13414. var getOuter = get
  13415. var aggregate = function (element, properties) {
  13416. return foldl(
  13417. properties,
  13418. function (acc, property) {
  13419. var val = get$5(element, property)
  13420. var value = val === undefined ? 0 : parseInt(val, 10)
  13421. return isNaN(value) ? acc : acc + value
  13422. },
  13423. 0
  13424. )
  13425. }
  13426. var max = function (element, value, properties) {
  13427. var cumulativeInclusions = aggregate(element, properties)
  13428. var absoluteMax =
  13429. value > cumulativeInclusions ? value - cumulativeInclusions : 0
  13430. return absoluteMax
  13431. }
  13432. return {
  13433. set: set,
  13434. get: get,
  13435. getOuter: getOuter,
  13436. aggregate: aggregate,
  13437. max: max,
  13438. }
  13439. }
  13440. var api = Dimension('height', function (element) {
  13441. var dom = element.dom
  13442. return inBody(element)
  13443. ? dom.getBoundingClientRect().height
  13444. : dom.offsetHeight
  13445. })
  13446. var get$1 = function (element) {
  13447. return api.get(element)
  13448. }
  13449. var walkUp = function (navigation, doc) {
  13450. var frame = navigation.view(doc)
  13451. return frame.fold(constant([]), function (f) {
  13452. var parent = navigation.owner(f)
  13453. var rest = walkUp(navigation, parent)
  13454. return [f].concat(rest)
  13455. })
  13456. }
  13457. var pathTo = function (element, navigation) {
  13458. var d = navigation.owner(element)
  13459. return walkUp(navigation, d)
  13460. }
  13461. var view = function (doc) {
  13462. var _a
  13463. var element =
  13464. doc.dom === document
  13465. ? Optional.none()
  13466. : Optional.from(
  13467. (_a = doc.dom.defaultView) === null || _a === void 0
  13468. ? void 0
  13469. : _a.frameElement
  13470. )
  13471. return element.map(SugarElement.fromDom)
  13472. }
  13473. var owner = function (element) {
  13474. return documentOrOwner(element)
  13475. }
  13476. var Navigation = /*#__PURE__*/ Object.freeze({
  13477. __proto__: null,
  13478. view: view,
  13479. owner: owner,
  13480. })
  13481. var find$1 = function (element) {
  13482. var doc = SugarElement.fromDom(document)
  13483. var scroll = get$8(doc)
  13484. var frames = pathTo(element, Navigation)
  13485. var offset = viewport(element)
  13486. var r = foldr(
  13487. frames,
  13488. function (b, a) {
  13489. var loc = viewport(a)
  13490. return {
  13491. left: b.left + loc.left,
  13492. top: b.top + loc.top,
  13493. }
  13494. },
  13495. {
  13496. left: 0,
  13497. top: 0,
  13498. }
  13499. )
  13500. return SugarPosition(
  13501. r.left + offset.left + scroll.left,
  13502. r.top + offset.top + scroll.top
  13503. )
  13504. }
  13505. var excludeFromDescend = function (element) {
  13506. return name(element) === 'textarea'
  13507. }
  13508. var fireScrollIntoViewEvent = function (editor, data) {
  13509. var scrollEvent = editor.fire('ScrollIntoView', data)
  13510. return scrollEvent.isDefaultPrevented()
  13511. }
  13512. var fireAfterScrollIntoViewEvent = function (editor, data) {
  13513. editor.fire('AfterScrollIntoView', data)
  13514. }
  13515. var descend = function (element, offset) {
  13516. var children$1 = children(element)
  13517. if (children$1.length === 0 || excludeFromDescend(element)) {
  13518. return {
  13519. element: element,
  13520. offset: offset,
  13521. }
  13522. } else if (
  13523. offset < children$1.length &&
  13524. !excludeFromDescend(children$1[offset])
  13525. ) {
  13526. return {
  13527. element: children$1[offset],
  13528. offset: 0,
  13529. }
  13530. } else {
  13531. var last = children$1[children$1.length - 1]
  13532. if (excludeFromDescend(last)) {
  13533. return {
  13534. element: element,
  13535. offset: offset,
  13536. }
  13537. } else {
  13538. if (name(last) === 'img') {
  13539. return {
  13540. element: last,
  13541. offset: 1,
  13542. }
  13543. } else if (isText$8(last)) {
  13544. return {
  13545. element: last,
  13546. offset: get$2(last).length,
  13547. }
  13548. } else {
  13549. return {
  13550. element: last,
  13551. offset: children(last).length,
  13552. }
  13553. }
  13554. }
  13555. }
  13556. }
  13557. var markerInfo = function (element, cleanupFun) {
  13558. var pos = absolute(element)
  13559. var height = get$1(element)
  13560. return {
  13561. element: element,
  13562. bottom: pos.top + height,
  13563. height: height,
  13564. pos: pos,
  13565. cleanup: cleanupFun,
  13566. }
  13567. }
  13568. var createMarker = function (element, offset) {
  13569. var startPoint = descend(element, offset)
  13570. var span = SugarElement.fromHtml(
  13571. '<span data-mce-bogus="all" style="display: inline-block;">' +
  13572. ZWSP$1 +
  13573. '</span>'
  13574. )
  13575. before$4(startPoint.element, span)
  13576. return markerInfo(span, function () {
  13577. return remove$7(span)
  13578. })
  13579. }
  13580. var elementMarker = function (element) {
  13581. return markerInfo(SugarElement.fromDom(element), noop)
  13582. }
  13583. var withMarker = function (editor, f, rng, alignToTop) {
  13584. preserveWith(
  13585. editor,
  13586. function (_s, _e) {
  13587. return applyWithMarker(editor, f, rng, alignToTop)
  13588. },
  13589. rng
  13590. )
  13591. }
  13592. var withScrollEvents = function (editor, doc, f, marker, alignToTop) {
  13593. var data = {
  13594. elm: marker.element.dom,
  13595. alignToTop: alignToTop,
  13596. }
  13597. if (fireScrollIntoViewEvent(editor, data)) {
  13598. return
  13599. }
  13600. var scrollTop = get$8(doc).top
  13601. f(doc, scrollTop, marker, alignToTop)
  13602. fireAfterScrollIntoViewEvent(editor, data)
  13603. }
  13604. var applyWithMarker = function (editor, f, rng, alignToTop) {
  13605. var body = SugarElement.fromDom(editor.getBody())
  13606. var doc = SugarElement.fromDom(editor.getDoc())
  13607. reflow(body)
  13608. var marker = createMarker(
  13609. SugarElement.fromDom(rng.startContainer),
  13610. rng.startOffset
  13611. )
  13612. withScrollEvents(editor, doc, f, marker, alignToTop)
  13613. marker.cleanup()
  13614. }
  13615. var withElement = function (editor, element, f, alignToTop) {
  13616. var doc = SugarElement.fromDom(editor.getDoc())
  13617. withScrollEvents(editor, doc, f, elementMarker(element), alignToTop)
  13618. }
  13619. var preserveWith = function (editor, f, rng) {
  13620. var startElement = rng.startContainer
  13621. var startOffset = rng.startOffset
  13622. var endElement = rng.endContainer
  13623. var endOffset = rng.endOffset
  13624. f(SugarElement.fromDom(startElement), SugarElement.fromDom(endElement))
  13625. var newRng = editor.dom.createRng()
  13626. newRng.setStart(startElement, startOffset)
  13627. newRng.setEnd(endElement, endOffset)
  13628. editor.selection.setRng(rng)
  13629. }
  13630. var scrollToMarker = function (marker, viewHeight, alignToTop, doc) {
  13631. var pos = marker.pos
  13632. if (alignToTop) {
  13633. to(pos.left, pos.top, doc)
  13634. } else {
  13635. var y = pos.top - viewHeight + marker.height
  13636. to(pos.left, y, doc)
  13637. }
  13638. }
  13639. var intoWindowIfNeeded = function (
  13640. doc,
  13641. scrollTop,
  13642. viewHeight,
  13643. marker,
  13644. alignToTop
  13645. ) {
  13646. var viewportBottom = viewHeight + scrollTop
  13647. var markerTop = marker.pos.top
  13648. var markerBottom = marker.bottom
  13649. var largerThanViewport = markerBottom - markerTop >= viewHeight
  13650. if (markerTop < scrollTop) {
  13651. scrollToMarker(marker, viewHeight, alignToTop !== false, doc)
  13652. } else if (markerTop > viewportBottom) {
  13653. var align = largerThanViewport
  13654. ? alignToTop !== false
  13655. : alignToTop === true
  13656. scrollToMarker(marker, viewHeight, align, doc)
  13657. } else if (markerBottom > viewportBottom && !largerThanViewport) {
  13658. scrollToMarker(marker, viewHeight, alignToTop === true, doc)
  13659. }
  13660. }
  13661. var intoWindow = function (doc, scrollTop, marker, alignToTop) {
  13662. var viewHeight = doc.dom.defaultView.innerHeight
  13663. intoWindowIfNeeded(doc, scrollTop, viewHeight, marker, alignToTop)
  13664. }
  13665. var intoFrame = function (doc, scrollTop, marker, alignToTop) {
  13666. var frameViewHeight = doc.dom.defaultView.innerHeight
  13667. intoWindowIfNeeded(doc, scrollTop, frameViewHeight, marker, alignToTop)
  13668. var op = find$1(marker.element)
  13669. var viewportBounds = getBounds(window)
  13670. if (op.top < viewportBounds.y) {
  13671. intoView(marker.element, alignToTop !== false)
  13672. } else if (op.top > viewportBounds.bottom) {
  13673. intoView(marker.element, alignToTop === true)
  13674. }
  13675. }
  13676. var rangeIntoWindow = function (editor, rng, alignToTop) {
  13677. return withMarker(editor, intoWindow, rng, alignToTop)
  13678. }
  13679. var elementIntoWindow = function (editor, element, alignToTop) {
  13680. return withElement(editor, element, intoWindow, alignToTop)
  13681. }
  13682. var rangeIntoFrame = function (editor, rng, alignToTop) {
  13683. return withMarker(editor, intoFrame, rng, alignToTop)
  13684. }
  13685. var elementIntoFrame = function (editor, element, alignToTop) {
  13686. return withElement(editor, element, intoFrame, alignToTop)
  13687. }
  13688. var scrollElementIntoView = function (editor, element, alignToTop) {
  13689. var scroller = editor.inline ? elementIntoWindow : elementIntoFrame
  13690. scroller(editor, element, alignToTop)
  13691. }
  13692. var scrollRangeIntoView = function (editor, rng, alignToTop) {
  13693. var scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame
  13694. scroller(editor, rng, alignToTop)
  13695. }
  13696. var getDocument = function () {
  13697. return SugarElement.fromDom(document)
  13698. }
  13699. var focus$1 = function (element) {
  13700. return element.dom.focus()
  13701. }
  13702. var hasFocus$1 = function (element) {
  13703. var root = getRootNode(element).dom
  13704. return element.dom === root.activeElement
  13705. }
  13706. var active = function (root) {
  13707. if (root === void 0) {
  13708. root = getDocument()
  13709. }
  13710. return Optional.from(root.dom.activeElement).map(SugarElement.fromDom)
  13711. }
  13712. var search = function (element) {
  13713. return active(getRootNode(element)).filter(function (e) {
  13714. return element.dom.contains(e.dom)
  13715. })
  13716. }
  13717. var create$5 = function (start, soffset, finish, foffset) {
  13718. return {
  13719. start: start,
  13720. soffset: soffset,
  13721. finish: finish,
  13722. foffset: foffset,
  13723. }
  13724. }
  13725. var SimRange = { create: create$5 }
  13726. var adt$1 = Adt.generate([
  13727. { before: ['element'] },
  13728. {
  13729. on: ['element', 'offset'],
  13730. },
  13731. { after: ['element'] },
  13732. ])
  13733. var cata = function (subject, onBefore, onOn, onAfter) {
  13734. return subject.fold(onBefore, onOn, onAfter)
  13735. }
  13736. var getStart$2 = function (situ) {
  13737. return situ.fold(identity, identity, identity)
  13738. }
  13739. var before$1 = adt$1.before
  13740. var on = adt$1.on
  13741. var after$1 = adt$1.after
  13742. var Situ = {
  13743. before: before$1,
  13744. on: on,
  13745. after: after$1,
  13746. cata: cata,
  13747. getStart: getStart$2,
  13748. }
  13749. var adt = Adt.generate([
  13750. { domRange: ['rng'] },
  13751. {
  13752. relative: ['startSitu', 'finishSitu'],
  13753. },
  13754. {
  13755. exact: ['start', 'soffset', 'finish', 'foffset'],
  13756. },
  13757. ])
  13758. var exactFromRange = function (simRange) {
  13759. return adt.exact(
  13760. simRange.start,
  13761. simRange.soffset,
  13762. simRange.finish,
  13763. simRange.foffset
  13764. )
  13765. }
  13766. var getStart$1 = function (selection) {
  13767. return selection.match({
  13768. domRange: function (rng) {
  13769. return SugarElement.fromDom(rng.startContainer)
  13770. },
  13771. relative: function (startSitu, _finishSitu) {
  13772. return Situ.getStart(startSitu)
  13773. },
  13774. exact: function (start, _soffset, _finish, _foffset) {
  13775. return start
  13776. },
  13777. })
  13778. }
  13779. var domRange = adt.domRange
  13780. var relative = adt.relative
  13781. var exact = adt.exact
  13782. var getWin = function (selection) {
  13783. var start = getStart$1(selection)
  13784. return defaultView(start)
  13785. }
  13786. var range = SimRange.create
  13787. var SimSelection = {
  13788. domRange: domRange,
  13789. relative: relative,
  13790. exact: exact,
  13791. exactFromRange: exactFromRange,
  13792. getWin: getWin,
  13793. range: range,
  13794. }
  13795. var browser$1 = detect().browser
  13796. var clamp$1 = function (offset, element) {
  13797. var max = isText$8(element)
  13798. ? get$2(element).length
  13799. : children(element).length + 1
  13800. if (offset > max) {
  13801. return max
  13802. } else if (offset < 0) {
  13803. return 0
  13804. }
  13805. return offset
  13806. }
  13807. var normalizeRng = function (rng) {
  13808. return SimSelection.range(
  13809. rng.start,
  13810. clamp$1(rng.soffset, rng.start),
  13811. rng.finish,
  13812. clamp$1(rng.foffset, rng.finish)
  13813. )
  13814. }
  13815. var isOrContains = function (root, elm) {
  13816. return (
  13817. !isRestrictedNode(elm.dom) && (contains$1(root, elm) || eq(root, elm))
  13818. )
  13819. }
  13820. var isRngInRoot = function (root) {
  13821. return function (rng) {
  13822. return isOrContains(root, rng.start) && isOrContains(root, rng.finish)
  13823. }
  13824. }
  13825. var shouldStore = function (editor) {
  13826. return editor.inline === true || browser$1.isIE()
  13827. }
  13828. var nativeRangeToSelectionRange = function (r) {
  13829. return SimSelection.range(
  13830. SugarElement.fromDom(r.startContainer),
  13831. r.startOffset,
  13832. SugarElement.fromDom(r.endContainer),
  13833. r.endOffset
  13834. )
  13835. }
  13836. var readRange = function (win) {
  13837. var selection = win.getSelection()
  13838. var rng =
  13839. !selection || selection.rangeCount === 0
  13840. ? Optional.none()
  13841. : Optional.from(selection.getRangeAt(0))
  13842. return rng.map(nativeRangeToSelectionRange)
  13843. }
  13844. var getBookmark = function (root) {
  13845. var win = defaultView(root)
  13846. return readRange(win.dom).filter(isRngInRoot(root))
  13847. }
  13848. var validate = function (root, bookmark) {
  13849. return Optional.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng)
  13850. }
  13851. var bookmarkToNativeRng = function (bookmark) {
  13852. var rng = document.createRange()
  13853. try {
  13854. rng.setStart(bookmark.start.dom, bookmark.soffset)
  13855. rng.setEnd(bookmark.finish.dom, bookmark.foffset)
  13856. return Optional.some(rng)
  13857. } catch (_) {
  13858. return Optional.none()
  13859. }
  13860. }
  13861. var store = function (editor) {
  13862. var newBookmark = shouldStore(editor)
  13863. ? getBookmark(SugarElement.fromDom(editor.getBody()))
  13864. : Optional.none()
  13865. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark
  13866. }
  13867. var storeNative = function (editor, rng) {
  13868. var root = SugarElement.fromDom(editor.getBody())
  13869. var range = shouldStore(editor) ? Optional.from(rng) : Optional.none()
  13870. var newBookmark = range
  13871. .map(nativeRangeToSelectionRange)
  13872. .filter(isRngInRoot(root))
  13873. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark
  13874. }
  13875. var getRng = function (editor) {
  13876. var bookmark = editor.bookmark ? editor.bookmark : Optional.none()
  13877. return bookmark
  13878. .bind(function (x) {
  13879. return validate(SugarElement.fromDom(editor.getBody()), x)
  13880. })
  13881. .bind(bookmarkToNativeRng)
  13882. }
  13883. var restore = function (editor) {
  13884. getRng(editor).each(function (rng) {
  13885. return editor.selection.setRng(rng)
  13886. })
  13887. }
  13888. var isEditorUIElement$1 = function (elm) {
  13889. var className = elm.className.toString()
  13890. return className.indexOf('tox-') !== -1 || className.indexOf('mce-') !== -1
  13891. }
  13892. var FocusManager = { isEditorUIElement: isEditorUIElement$1 }
  13893. var isManualNodeChange = function (e) {
  13894. return e.type === 'nodechange' && e.selectionChange
  13895. }
  13896. var registerPageMouseUp = function (editor, throttledStore) {
  13897. var mouseUpPage = function () {
  13898. throttledStore.throttle()
  13899. }
  13900. DOMUtils.DOM.bind(document, 'mouseup', mouseUpPage)
  13901. editor.on('remove', function () {
  13902. DOMUtils.DOM.unbind(document, 'mouseup', mouseUpPage)
  13903. })
  13904. }
  13905. var registerFocusOut = function (editor) {
  13906. editor.on('focusout', function () {
  13907. store(editor)
  13908. })
  13909. }
  13910. var registerMouseUp = function (editor, throttledStore) {
  13911. editor.on('mouseup touchend', function (_e) {
  13912. throttledStore.throttle()
  13913. })
  13914. }
  13915. var registerEditorEvents = function (editor, throttledStore) {
  13916. var browser = detect().browser
  13917. if (browser.isIE()) {
  13918. registerFocusOut(editor)
  13919. } else {
  13920. registerMouseUp(editor, throttledStore)
  13921. }
  13922. editor.on('keyup NodeChange', function (e) {
  13923. if (!isManualNodeChange(e)) {
  13924. store(editor)
  13925. }
  13926. })
  13927. }
  13928. var register$3 = function (editor) {
  13929. var throttledStore = first(function () {
  13930. store(editor)
  13931. }, 0)
  13932. editor.on('init', function () {
  13933. if (editor.inline) {
  13934. registerPageMouseUp(editor, throttledStore)
  13935. }
  13936. registerEditorEvents(editor, throttledStore)
  13937. })
  13938. editor.on('remove', function () {
  13939. throttledStore.cancel()
  13940. })
  13941. }
  13942. var documentFocusInHandler
  13943. var DOM$8 = DOMUtils.DOM
  13944. var isEditorUIElement = function (elm) {
  13945. return FocusManager.isEditorUIElement(elm)
  13946. }
  13947. var isEditorContentAreaElement = function (elm) {
  13948. var classList = elm.classList
  13949. if (classList !== undefined) {
  13950. return (
  13951. classList.contains('tox-edit-area') ||
  13952. classList.contains('tox-edit-area__iframe') ||
  13953. classList.contains('mce-content-body')
  13954. )
  13955. } else {
  13956. return false
  13957. }
  13958. }
  13959. var isUIElement = function (editor, elm) {
  13960. var customSelector = getCustomUiSelector(editor)
  13961. var parent = DOM$8.getParent(elm, function (elm) {
  13962. return (
  13963. isEditorUIElement(elm) ||
  13964. (customSelector ? editor.dom.is(elm, customSelector) : false)
  13965. )
  13966. })
  13967. return parent !== null
  13968. }
  13969. var getActiveElement = function (editor) {
  13970. try {
  13971. var root = getRootNode(SugarElement.fromDom(editor.getElement()))
  13972. return active(root).fold(
  13973. function () {
  13974. return document.body
  13975. },
  13976. function (x) {
  13977. return x.dom
  13978. }
  13979. )
  13980. } catch (ex) {
  13981. return document.body
  13982. }
  13983. }
  13984. var registerEvents$1 = function (editorManager, e) {
  13985. var editor = e.editor
  13986. register$3(editor)
  13987. editor.on('focusin', function () {
  13988. var focusedEditor = editorManager.focusedEditor
  13989. if (focusedEditor !== editor) {
  13990. if (focusedEditor) {
  13991. focusedEditor.fire('blur', { focusedEditor: editor })
  13992. }
  13993. editorManager.setActive(editor)
  13994. editorManager.focusedEditor = editor
  13995. editor.fire('focus', { blurredEditor: focusedEditor })
  13996. editor.focus(true)
  13997. }
  13998. })
  13999. editor.on('focusout', function () {
  14000. Delay.setEditorTimeout(editor, function () {
  14001. var focusedEditor = editorManager.focusedEditor
  14002. if (
  14003. !isUIElement(editor, getActiveElement(editor)) &&
  14004. focusedEditor === editor
  14005. ) {
  14006. editor.fire('blur', { focusedEditor: null })
  14007. editorManager.focusedEditor = null
  14008. }
  14009. })
  14010. })
  14011. if (!documentFocusInHandler) {
  14012. documentFocusInHandler = function (e) {
  14013. var activeEditor = editorManager.activeEditor
  14014. if (activeEditor) {
  14015. getOriginalEventTarget(e).each(function (target) {
  14016. if (target.ownerDocument === document) {
  14017. if (
  14018. target !== document.body &&
  14019. !isUIElement(activeEditor, target) &&
  14020. editorManager.focusedEditor === activeEditor
  14021. ) {
  14022. activeEditor.fire('blur', { focusedEditor: null })
  14023. editorManager.focusedEditor = null
  14024. }
  14025. }
  14026. })
  14027. }
  14028. }
  14029. DOM$8.bind(document, 'focusin', documentFocusInHandler)
  14030. }
  14031. }
  14032. var unregisterDocumentEvents = function (editorManager, e) {
  14033. if (editorManager.focusedEditor === e.editor) {
  14034. editorManager.focusedEditor = null
  14035. }
  14036. if (!editorManager.activeEditor) {
  14037. DOM$8.unbind(document, 'focusin', documentFocusInHandler)
  14038. documentFocusInHandler = null
  14039. }
  14040. }
  14041. var setup$l = function (editorManager) {
  14042. editorManager.on('AddEditor', curry(registerEvents$1, editorManager))
  14043. editorManager.on(
  14044. 'RemoveEditor',
  14045. curry(unregisterDocumentEvents, editorManager)
  14046. )
  14047. }
  14048. var getContentEditableHost = function (editor, node) {
  14049. return editor.dom.getParent(node, function (node) {
  14050. return editor.dom.getContentEditable(node) === 'true'
  14051. })
  14052. }
  14053. var getCollapsedNode = function (rng) {
  14054. return rng.collapsed
  14055. ? Optional.from(getNode$1(rng.startContainer, rng.startOffset)).map(
  14056. SugarElement.fromDom
  14057. )
  14058. : Optional.none()
  14059. }
  14060. var getFocusInElement = function (root, rng) {
  14061. return getCollapsedNode(rng).bind(function (node) {
  14062. if (isTableSection(node)) {
  14063. return Optional.some(node)
  14064. } else if (contains$1(root, node) === false) {
  14065. return Optional.some(root)
  14066. } else {
  14067. return Optional.none()
  14068. }
  14069. })
  14070. }
  14071. var normalizeSelection$1 = function (editor, rng) {
  14072. getFocusInElement(SugarElement.fromDom(editor.getBody()), rng)
  14073. .bind(function (elm) {
  14074. return firstPositionIn(elm.dom)
  14075. })
  14076. .fold(
  14077. function () {
  14078. editor.selection.normalize()
  14079. return
  14080. },
  14081. function (caretPos) {
  14082. return editor.selection.setRng(caretPos.toRange())
  14083. }
  14084. )
  14085. }
  14086. var focusBody = function (body) {
  14087. if (body.setActive) {
  14088. try {
  14089. body.setActive()
  14090. } catch (ex) {
  14091. body.focus()
  14092. }
  14093. } else {
  14094. body.focus()
  14095. }
  14096. }
  14097. var hasElementFocus = function (elm) {
  14098. return hasFocus$1(elm) || search(elm).isSome()
  14099. }
  14100. var hasIframeFocus = function (editor) {
  14101. return (
  14102. editor.iframeElement &&
  14103. hasFocus$1(SugarElement.fromDom(editor.iframeElement))
  14104. )
  14105. }
  14106. var hasInlineFocus = function (editor) {
  14107. var rawBody = editor.getBody()
  14108. return rawBody && hasElementFocus(SugarElement.fromDom(rawBody))
  14109. }
  14110. var hasUiFocus = function (editor) {
  14111. var dos = getRootNode(SugarElement.fromDom(editor.getElement()))
  14112. return active(dos)
  14113. .filter(function (elem) {
  14114. return (
  14115. !isEditorContentAreaElement(elem.dom) && isUIElement(editor, elem.dom)
  14116. )
  14117. })
  14118. .isSome()
  14119. }
  14120. var hasFocus = function (editor) {
  14121. return editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor)
  14122. }
  14123. var hasEditorOrUiFocus = function (editor) {
  14124. return hasFocus(editor) || hasUiFocus(editor)
  14125. }
  14126. var focusEditor = function (editor) {
  14127. var selection = editor.selection
  14128. var body = editor.getBody()
  14129. var rng = selection.getRng()
  14130. editor.quirks.refreshContentEditable()
  14131. if (editor.bookmark !== undefined && hasFocus(editor) === false) {
  14132. getRng(editor).each(function (bookmarkRng) {
  14133. editor.selection.setRng(bookmarkRng)
  14134. rng = bookmarkRng
  14135. })
  14136. }
  14137. var contentEditableHost = getContentEditableHost(
  14138. editor,
  14139. selection.getNode()
  14140. )
  14141. if (editor.$.contains(body, contentEditableHost)) {
  14142. focusBody(contentEditableHost)
  14143. normalizeSelection$1(editor, rng)
  14144. activateEditor(editor)
  14145. return
  14146. }
  14147. if (!editor.inline) {
  14148. if (!Env.opera) {
  14149. focusBody(body)
  14150. }
  14151. editor.getWin().focus()
  14152. }
  14153. if (Env.gecko || editor.inline) {
  14154. focusBody(body)
  14155. normalizeSelection$1(editor, rng)
  14156. }
  14157. activateEditor(editor)
  14158. }
  14159. var activateEditor = function (editor) {
  14160. return editor.editorManager.setActive(editor)
  14161. }
  14162. var focus = function (editor, skipFocus) {
  14163. if (editor.removed) {
  14164. return
  14165. }
  14166. if (skipFocus) {
  14167. activateEditor(editor)
  14168. } else {
  14169. focusEditor(editor)
  14170. }
  14171. }
  14172. var getEndpointElement = function (root, rng, start, real, resolve) {
  14173. var container = start ? rng.startContainer : rng.endContainer
  14174. var offset = start ? rng.startOffset : rng.endOffset
  14175. return Optional.from(container)
  14176. .map(SugarElement.fromDom)
  14177. .map(function (elm) {
  14178. return !real || !rng.collapsed
  14179. ? child$1(elm, resolve(elm, offset)).getOr(elm)
  14180. : elm
  14181. })
  14182. .bind(function (elm) {
  14183. return isElement$6(elm)
  14184. ? Optional.some(elm)
  14185. : parent(elm).filter(isElement$6)
  14186. })
  14187. .map(function (elm) {
  14188. return elm.dom
  14189. })
  14190. .getOr(root)
  14191. }
  14192. var getStart = function (root, rng, real) {
  14193. return getEndpointElement(root, rng, true, real, function (elm, offset) {
  14194. return Math.min(childNodesCount(elm), offset)
  14195. })
  14196. }
  14197. var getEnd = function (root, rng, real) {
  14198. return getEndpointElement(root, rng, false, real, function (elm, offset) {
  14199. return offset > 0 ? offset - 1 : offset
  14200. })
  14201. }
  14202. var skipEmptyTextNodes = function (node, forwards) {
  14203. var orig = node
  14204. while (node && isText$7(node) && node.length === 0) {
  14205. node = forwards ? node.nextSibling : node.previousSibling
  14206. }
  14207. return node || orig
  14208. }
  14209. var getNode = function (root, rng) {
  14210. var elm, startContainer, endContainer
  14211. if (!rng) {
  14212. return root
  14213. }
  14214. startContainer = rng.startContainer
  14215. endContainer = rng.endContainer
  14216. var startOffset = rng.startOffset
  14217. var endOffset = rng.endOffset
  14218. elm = rng.commonAncestorContainer
  14219. if (!rng.collapsed) {
  14220. if (startContainer === endContainer) {
  14221. if (endOffset - startOffset < 2) {
  14222. if (startContainer.hasChildNodes()) {
  14223. elm = startContainer.childNodes[startOffset]
  14224. }
  14225. }
  14226. }
  14227. if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
  14228. if (startContainer.length === startOffset) {
  14229. startContainer = skipEmptyTextNodes(startContainer.nextSibling, true)
  14230. } else {
  14231. startContainer = startContainer.parentNode
  14232. }
  14233. if (endOffset === 0) {
  14234. endContainer = skipEmptyTextNodes(endContainer.previousSibling, false)
  14235. } else {
  14236. endContainer = endContainer.parentNode
  14237. }
  14238. if (startContainer && startContainer === endContainer) {
  14239. return startContainer
  14240. }
  14241. }
  14242. }
  14243. if (elm && elm.nodeType === 3) {
  14244. return elm.parentNode
  14245. }
  14246. return elm
  14247. }
  14248. var getSelectedBlocks = function (dom, rng, startElm, endElm) {
  14249. var node
  14250. var selectedBlocks = []
  14251. var root = dom.getRoot()
  14252. startElm = dom.getParent(
  14253. startElm || getStart(root, rng, rng.collapsed),
  14254. dom.isBlock
  14255. )
  14256. endElm = dom.getParent(
  14257. endElm || getEnd(root, rng, rng.collapsed),
  14258. dom.isBlock
  14259. )
  14260. if (startElm && startElm !== root) {
  14261. selectedBlocks.push(startElm)
  14262. }
  14263. if (startElm && endElm && startElm !== endElm) {
  14264. node = startElm
  14265. var walker = new DomTreeWalker(startElm, root)
  14266. while ((node = walker.next()) && node !== endElm) {
  14267. if (dom.isBlock(node)) {
  14268. selectedBlocks.push(node)
  14269. }
  14270. }
  14271. }
  14272. if (endElm && startElm !== endElm && endElm !== root) {
  14273. selectedBlocks.push(endElm)
  14274. }
  14275. return selectedBlocks
  14276. }
  14277. var select = function (dom, node, content) {
  14278. return Optional.from(node).map(function (node) {
  14279. var idx = dom.nodeIndex(node)
  14280. var rng = dom.createRng()
  14281. rng.setStart(node.parentNode, idx)
  14282. rng.setEnd(node.parentNode, idx + 1)
  14283. if (content) {
  14284. moveEndPoint(dom, rng, node, true)
  14285. moveEndPoint(dom, rng, node, false)
  14286. }
  14287. return rng
  14288. })
  14289. }
  14290. var processRanges = function (editor, ranges) {
  14291. return map$3(ranges, function (range) {
  14292. var evt = editor.fire('GetSelectionRange', { range: range })
  14293. return evt.range !== range ? evt.range : range
  14294. })
  14295. }
  14296. var typeLookup = {
  14297. '#text': 3,
  14298. '#comment': 8,
  14299. '#cdata': 4,
  14300. '#pi': 7,
  14301. '#doctype': 10,
  14302. '#document-fragment': 11,
  14303. }
  14304. var walk$1 = function (node, root, prev) {
  14305. var startName = prev ? 'lastChild' : 'firstChild'
  14306. var siblingName = prev ? 'prev' : 'next'
  14307. if (node[startName]) {
  14308. return node[startName]
  14309. }
  14310. if (node !== root) {
  14311. var sibling = node[siblingName]
  14312. if (sibling) {
  14313. return sibling
  14314. }
  14315. for (
  14316. var parent_1 = node.parent;
  14317. parent_1 && parent_1 !== root;
  14318. parent_1 = parent_1.parent
  14319. ) {
  14320. sibling = parent_1[siblingName]
  14321. if (sibling) {
  14322. return sibling
  14323. }
  14324. }
  14325. }
  14326. }
  14327. var isEmptyTextNode = function (node) {
  14328. if (!isWhitespaceText(node.value)) {
  14329. return false
  14330. }
  14331. var parentNode = node.parent
  14332. if (
  14333. parentNode &&
  14334. (parentNode.name !== 'span' || parentNode.attr('style')) &&
  14335. /^[ ]+$/.test(node.value)
  14336. ) {
  14337. return false
  14338. }
  14339. return true
  14340. }
  14341. var isNonEmptyElement = function (node) {
  14342. var isNamedAnchor =
  14343. node.name === 'a' && !node.attr('href') && node.attr('id')
  14344. return (
  14345. node.attr('name') ||
  14346. (node.attr('id') && !node.firstChild) ||
  14347. node.attr('data-mce-bookmark') ||
  14348. isNamedAnchor
  14349. )
  14350. }
  14351. var AstNode = (function () {
  14352. function AstNode(name, type) {
  14353. this.name = name
  14354. this.type = type
  14355. if (type === 1) {
  14356. this.attributes = []
  14357. this.attributes.map = {}
  14358. }
  14359. }
  14360. AstNode.create = function (name, attrs) {
  14361. var node = new AstNode(name, typeLookup[name] || 1)
  14362. if (attrs) {
  14363. each$j(attrs, function (value, attrName) {
  14364. node.attr(attrName, value)
  14365. })
  14366. }
  14367. return node
  14368. }
  14369. AstNode.prototype.replace = function (node) {
  14370. var self = this
  14371. if (node.parent) {
  14372. node.remove()
  14373. }
  14374. self.insert(node, self)
  14375. self.remove()
  14376. return self
  14377. }
  14378. AstNode.prototype.attr = function (name, value) {
  14379. var self = this
  14380. var attrs
  14381. if (typeof name !== 'string') {
  14382. if (name !== undefined && name !== null) {
  14383. each$j(name, function (value, key) {
  14384. self.attr(key, value)
  14385. })
  14386. }
  14387. return self
  14388. }
  14389. if ((attrs = self.attributes)) {
  14390. if (value !== undefined) {
  14391. if (value === null) {
  14392. if (name in attrs.map) {
  14393. delete attrs.map[name]
  14394. var i = attrs.length
  14395. while (i--) {
  14396. if (attrs[i].name === name) {
  14397. attrs.splice(i, 1)
  14398. return self
  14399. }
  14400. }
  14401. }
  14402. return self
  14403. }
  14404. if (name in attrs.map) {
  14405. var i = attrs.length
  14406. while (i--) {
  14407. if (attrs[i].name === name) {
  14408. attrs[i].value = value
  14409. break
  14410. }
  14411. }
  14412. } else {
  14413. attrs.push({
  14414. name: name,
  14415. value: value,
  14416. })
  14417. }
  14418. attrs.map[name] = value
  14419. return self
  14420. }
  14421. return attrs.map[name]
  14422. }
  14423. }
  14424. AstNode.prototype.clone = function () {
  14425. var self = this
  14426. var clone = new AstNode(self.name, self.type)
  14427. var selfAttrs
  14428. if ((selfAttrs = self.attributes)) {
  14429. var cloneAttrs = []
  14430. cloneAttrs.map = {}
  14431. for (var i = 0, l = selfAttrs.length; i < l; i++) {
  14432. var selfAttr = selfAttrs[i]
  14433. if (selfAttr.name !== 'id') {
  14434. cloneAttrs[cloneAttrs.length] = {
  14435. name: selfAttr.name,
  14436. value: selfAttr.value,
  14437. }
  14438. cloneAttrs.map[selfAttr.name] = selfAttr.value
  14439. }
  14440. }
  14441. clone.attributes = cloneAttrs
  14442. }
  14443. clone.value = self.value
  14444. clone.shortEnded = self.shortEnded
  14445. return clone
  14446. }
  14447. AstNode.prototype.wrap = function (wrapper) {
  14448. var self = this
  14449. self.parent.insert(wrapper, self)
  14450. wrapper.append(self)
  14451. return self
  14452. }
  14453. AstNode.prototype.unwrap = function () {
  14454. var self = this
  14455. for (var node = self.firstChild; node; ) {
  14456. var next = node.next
  14457. self.insert(node, self, true)
  14458. node = next
  14459. }
  14460. self.remove()
  14461. }
  14462. AstNode.prototype.remove = function () {
  14463. var self = this,
  14464. parent = self.parent,
  14465. next = self.next,
  14466. prev = self.prev
  14467. if (parent) {
  14468. if (parent.firstChild === self) {
  14469. parent.firstChild = next
  14470. if (next) {
  14471. next.prev = null
  14472. }
  14473. } else {
  14474. prev.next = next
  14475. }
  14476. if (parent.lastChild === self) {
  14477. parent.lastChild = prev
  14478. if (prev) {
  14479. prev.next = null
  14480. }
  14481. } else {
  14482. next.prev = prev
  14483. }
  14484. self.parent = self.next = self.prev = null
  14485. }
  14486. return self
  14487. }
  14488. AstNode.prototype.append = function (node) {
  14489. var self = this
  14490. if (node.parent) {
  14491. node.remove()
  14492. }
  14493. var last = self.lastChild
  14494. if (last) {
  14495. last.next = node
  14496. node.prev = last
  14497. self.lastChild = node
  14498. } else {
  14499. self.lastChild = self.firstChild = node
  14500. }
  14501. node.parent = self
  14502. return node
  14503. }
  14504. AstNode.prototype.insert = function (node, refNode, before) {
  14505. if (node.parent) {
  14506. node.remove()
  14507. }
  14508. var parent = refNode.parent || this
  14509. if (before) {
  14510. if (refNode === parent.firstChild) {
  14511. parent.firstChild = node
  14512. } else {
  14513. refNode.prev.next = node
  14514. }
  14515. node.prev = refNode.prev
  14516. node.next = refNode
  14517. refNode.prev = node
  14518. } else {
  14519. if (refNode === parent.lastChild) {
  14520. parent.lastChild = node
  14521. } else {
  14522. refNode.next.prev = node
  14523. }
  14524. node.next = refNode.next
  14525. node.prev = refNode
  14526. refNode.next = node
  14527. }
  14528. node.parent = parent
  14529. return node
  14530. }
  14531. AstNode.prototype.getAll = function (name) {
  14532. var self = this
  14533. var collection = []
  14534. for (var node = self.firstChild; node; node = walk$1(node, self)) {
  14535. if (node.name === name) {
  14536. collection.push(node)
  14537. }
  14538. }
  14539. return collection
  14540. }
  14541. AstNode.prototype.children = function () {
  14542. var self = this
  14543. var collection = []
  14544. for (var node = self.firstChild; node; node = node.next) {
  14545. collection.push(node)
  14546. }
  14547. return collection
  14548. }
  14549. AstNode.prototype.empty = function () {
  14550. var self = this
  14551. if (self.firstChild) {
  14552. var nodes = []
  14553. for (var node = self.firstChild; node; node = walk$1(node, self)) {
  14554. nodes.push(node)
  14555. }
  14556. var i = nodes.length
  14557. while (i--) {
  14558. var node = nodes[i]
  14559. node.parent =
  14560. node.firstChild =
  14561. node.lastChild =
  14562. node.next =
  14563. node.prev =
  14564. null
  14565. }
  14566. }
  14567. self.firstChild = self.lastChild = null
  14568. return self
  14569. }
  14570. AstNode.prototype.isEmpty = function (elements, whitespace, predicate) {
  14571. if (whitespace === void 0) {
  14572. whitespace = {}
  14573. }
  14574. var self = this
  14575. var node = self.firstChild
  14576. if (isNonEmptyElement(self)) {
  14577. return false
  14578. }
  14579. if (node) {
  14580. do {
  14581. if (node.type === 1) {
  14582. if (node.attr('data-mce-bogus')) {
  14583. continue
  14584. }
  14585. if (elements[node.name]) {
  14586. return false
  14587. }
  14588. if (isNonEmptyElement(node)) {
  14589. return false
  14590. }
  14591. }
  14592. if (node.type === 8) {
  14593. return false
  14594. }
  14595. if (node.type === 3 && !isEmptyTextNode(node)) {
  14596. return false
  14597. }
  14598. if (
  14599. node.type === 3 &&
  14600. node.parent &&
  14601. whitespace[node.parent.name] &&
  14602. isWhitespaceText(node.value)
  14603. ) {
  14604. return false
  14605. }
  14606. if (predicate && predicate(node)) {
  14607. return false
  14608. }
  14609. } while ((node = walk$1(node, self)))
  14610. }
  14611. return true
  14612. }
  14613. AstNode.prototype.walk = function (prev) {
  14614. return walk$1(this, null, prev)
  14615. }
  14616. return AstNode
  14617. })()
  14618. var extractBase64DataUris = function (html) {
  14619. var dataImageUri = /data:[^;]+;base64,([a-z0-9\+\/=\s]+)/gi
  14620. var chunks = []
  14621. var uris = {}
  14622. var prefix = generate('img')
  14623. var matches
  14624. var index = 0
  14625. var count = 0
  14626. while ((matches = dataImageUri.exec(html))) {
  14627. var uri = matches[0]
  14628. var imageId = prefix + '_' + count++
  14629. uris[imageId] = uri
  14630. if (index < matches.index) {
  14631. chunks.push(html.substr(index, matches.index - index))
  14632. }
  14633. chunks.push(imageId)
  14634. index = matches.index + uri.length
  14635. }
  14636. var re = new RegExp(prefix + '_[0-9]+', 'g')
  14637. if (index === 0) {
  14638. return {
  14639. prefix: prefix,
  14640. uris: uris,
  14641. html: html,
  14642. re: re,
  14643. }
  14644. } else {
  14645. if (index < html.length) {
  14646. chunks.push(html.substr(index))
  14647. }
  14648. return {
  14649. prefix: prefix,
  14650. uris: uris,
  14651. html: chunks.join(''),
  14652. re: re,
  14653. }
  14654. }
  14655. }
  14656. var restoreDataUris = function (html, result) {
  14657. return html.replace(result.re, function (imageId) {
  14658. return get$9(result.uris, imageId).getOr(imageId)
  14659. })
  14660. }
  14661. var parseDataUri$1 = function (uri) {
  14662. var matches = /data:([^;]+);base64,([a-z0-9\+\/=\s]+)/i.exec(uri)
  14663. if (matches) {
  14664. return Optional.some({
  14665. type: matches[1],
  14666. data: decodeURIComponent(matches[2]),
  14667. })
  14668. } else {
  14669. return Optional.none()
  14670. }
  14671. }
  14672. var each$d = Tools.each,
  14673. trim = Tools.trim
  14674. var queryParts =
  14675. 'source protocol authority userInfo user password host port relative path directory file query anchor'.split(
  14676. ' '
  14677. )
  14678. var DEFAULT_PORTS = {
  14679. ftp: 21,
  14680. http: 80,
  14681. https: 443,
  14682. mailto: 25,
  14683. }
  14684. var safeSvgDataUrlElements = ['img', 'video']
  14685. var blockSvgDataUris = function (allowSvgDataUrls, tagName) {
  14686. if (isNonNullable(allowSvgDataUrls)) {
  14687. return !allowSvgDataUrls
  14688. } else {
  14689. return isNonNullable(tagName)
  14690. ? !contains$3(safeSvgDataUrlElements, tagName)
  14691. : true
  14692. }
  14693. }
  14694. var isInvalidUri = function (settings, uri, tagName) {
  14695. if (settings.allow_html_data_urls) {
  14696. return false
  14697. } else if (/^data:image\//i.test(uri)) {
  14698. return (
  14699. blockSvgDataUris(settings.allow_svg_data_urls, tagName) &&
  14700. /^data:image\/svg\+xml/i.test(uri)
  14701. )
  14702. } else {
  14703. return /^data:/i.test(uri)
  14704. }
  14705. }
  14706. var URI = (function () {
  14707. function URI(url, settings) {
  14708. url = trim(url)
  14709. this.settings = settings || {}
  14710. var baseUri = this.settings.base_uri
  14711. var self = this
  14712. if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
  14713. self.source = url
  14714. return
  14715. }
  14716. var isProtocolRelative = url.indexOf('//') === 0
  14717. if (url.indexOf('/') === 0 && !isProtocolRelative) {
  14718. url =
  14719. (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url
  14720. }
  14721. if (!/^[\w\-]*:?\/\//.test(url)) {
  14722. var baseUrl = this.settings.base_uri
  14723. ? this.settings.base_uri.path
  14724. : new URI(document.location.href).directory
  14725. if (this.settings.base_uri && this.settings.base_uri.protocol == '') {
  14726. url = '//mce_host' + self.toAbsPath(baseUrl, url)
  14727. } else {
  14728. var match = /([^#?]*)([#?]?.*)/.exec(url)
  14729. url =
  14730. ((baseUri && baseUri.protocol) || 'http') +
  14731. '://mce_host' +
  14732. self.toAbsPath(baseUrl, match[1]) +
  14733. match[2]
  14734. }
  14735. }
  14736. url = url.replace(/@@/g, '(mce_at)')
  14737. var urlMatch =
  14738. /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?(\[[a-zA-Z0-9:.%]+\]|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(
  14739. url
  14740. )
  14741. each$d(queryParts, function (v, i) {
  14742. var part = urlMatch[i]
  14743. if (part) {
  14744. part = part.replace(/\(mce_at\)/g, '@@')
  14745. }
  14746. self[v] = part
  14747. })
  14748. if (baseUri) {
  14749. if (!self.protocol) {
  14750. self.protocol = baseUri.protocol
  14751. }
  14752. if (!self.userInfo) {
  14753. self.userInfo = baseUri.userInfo
  14754. }
  14755. if (!self.port && self.host === 'mce_host') {
  14756. self.port = baseUri.port
  14757. }
  14758. if (!self.host || self.host === 'mce_host') {
  14759. self.host = baseUri.host
  14760. }
  14761. self.source = ''
  14762. }
  14763. if (isProtocolRelative) {
  14764. self.protocol = ''
  14765. }
  14766. }
  14767. URI.parseDataUri = function (uri) {
  14768. var type
  14769. var uriComponents = decodeURIComponent(uri).split(',')
  14770. var matches = /data:([^;]+)/.exec(uriComponents[0])
  14771. if (matches) {
  14772. type = matches[1]
  14773. }
  14774. return {
  14775. type: type,
  14776. data: uriComponents[1],
  14777. }
  14778. }
  14779. URI.isDomSafe = function (uri, context, options) {
  14780. if (options === void 0) {
  14781. options = {}
  14782. }
  14783. if (options.allow_script_urls) {
  14784. return true
  14785. } else {
  14786. var decodedUri = Entities.decode(uri).replace(/[\s\u0000-\u001F]+/g, '')
  14787. try {
  14788. decodedUri = decodeURIComponent(decodedUri)
  14789. } catch (ex) {
  14790. decodedUri = unescape(decodedUri)
  14791. }
  14792. if (/((java|vb)script|mhtml):/i.test(decodedUri)) {
  14793. return false
  14794. }
  14795. return !isInvalidUri(options, decodedUri, context)
  14796. }
  14797. }
  14798. URI.getDocumentBaseUrl = function (loc) {
  14799. var baseUrl
  14800. if (loc.protocol.indexOf('http') !== 0 && loc.protocol !== 'file:') {
  14801. baseUrl = loc.href
  14802. } else {
  14803. baseUrl = loc.protocol + '//' + loc.host + loc.pathname
  14804. }
  14805. if (/^[^:]+:\/\/\/?[^\/]+\//.test(baseUrl)) {
  14806. baseUrl = baseUrl.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '')
  14807. if (!/[\/\\]$/.test(baseUrl)) {
  14808. baseUrl += '/'
  14809. }
  14810. }
  14811. return baseUrl
  14812. }
  14813. URI.prototype.setPath = function (path) {
  14814. var pathMatch = /^(.*?)\/?(\w+)?$/.exec(path)
  14815. this.path = pathMatch[0]
  14816. this.directory = pathMatch[1]
  14817. this.file = pathMatch[2]
  14818. this.source = ''
  14819. this.getURI()
  14820. }
  14821. URI.prototype.toRelative = function (uri) {
  14822. var output
  14823. if (uri === './') {
  14824. return uri
  14825. }
  14826. var relativeUri = new URI(uri, { base_uri: this })
  14827. if (
  14828. (relativeUri.host !== 'mce_host' &&
  14829. this.host !== relativeUri.host &&
  14830. relativeUri.host) ||
  14831. this.port !== relativeUri.port ||
  14832. (this.protocol !== relativeUri.protocol && relativeUri.protocol !== '')
  14833. ) {
  14834. return relativeUri.getURI()
  14835. }
  14836. var tu = this.getURI(),
  14837. uu = relativeUri.getURI()
  14838. if (
  14839. tu === uu ||
  14840. (tu.charAt(tu.length - 1) === '/' && tu.substr(0, tu.length - 1) === uu)
  14841. ) {
  14842. return tu
  14843. }
  14844. output = this.toRelPath(this.path, relativeUri.path)
  14845. if (relativeUri.query) {
  14846. output += '?' + relativeUri.query
  14847. }
  14848. if (relativeUri.anchor) {
  14849. output += '#' + relativeUri.anchor
  14850. }
  14851. return output
  14852. }
  14853. URI.prototype.toAbsolute = function (uri, noHost) {
  14854. var absoluteUri = new URI(uri, { base_uri: this })
  14855. return absoluteUri.getURI(noHost && this.isSameOrigin(absoluteUri))
  14856. }
  14857. URI.prototype.isSameOrigin = function (uri) {
  14858. if (this.host == uri.host && this.protocol == uri.protocol) {
  14859. if (this.port == uri.port) {
  14860. return true
  14861. }
  14862. var defaultPort = DEFAULT_PORTS[this.protocol]
  14863. if (
  14864. defaultPort &&
  14865. (this.port || defaultPort) == (uri.port || defaultPort)
  14866. ) {
  14867. return true
  14868. }
  14869. }
  14870. return false
  14871. }
  14872. URI.prototype.toRelPath = function (base, path) {
  14873. var breakPoint = 0,
  14874. out = '',
  14875. i,
  14876. l
  14877. var normalizedBase = base.substring(0, base.lastIndexOf('/')).split('/')
  14878. var items = path.split('/')
  14879. if (normalizedBase.length >= items.length) {
  14880. for (i = 0, l = normalizedBase.length; i < l; i++) {
  14881. if (i >= items.length || normalizedBase[i] !== items[i]) {
  14882. breakPoint = i + 1
  14883. break
  14884. }
  14885. }
  14886. }
  14887. if (normalizedBase.length < items.length) {
  14888. for (i = 0, l = items.length; i < l; i++) {
  14889. if (i >= normalizedBase.length || normalizedBase[i] !== items[i]) {
  14890. breakPoint = i + 1
  14891. break
  14892. }
  14893. }
  14894. }
  14895. if (breakPoint === 1) {
  14896. return path
  14897. }
  14898. for (i = 0, l = normalizedBase.length - (breakPoint - 1); i < l; i++) {
  14899. out += '../'
  14900. }
  14901. for (i = breakPoint - 1, l = items.length; i < l; i++) {
  14902. if (i !== breakPoint - 1) {
  14903. out += '/' + items[i]
  14904. } else {
  14905. out += items[i]
  14906. }
  14907. }
  14908. return out
  14909. }
  14910. URI.prototype.toAbsPath = function (base, path) {
  14911. var i,
  14912. nb = 0,
  14913. o = [],
  14914. outPath
  14915. var tr = /\/$/.test(path) ? '/' : ''
  14916. var normalizedBase = base.split('/')
  14917. var normalizedPath = path.split('/')
  14918. each$d(normalizedBase, function (k) {
  14919. if (k) {
  14920. o.push(k)
  14921. }
  14922. })
  14923. normalizedBase = o
  14924. for (i = normalizedPath.length - 1, o = []; i >= 0; i--) {
  14925. if (normalizedPath[i].length === 0 || normalizedPath[i] === '.') {
  14926. continue
  14927. }
  14928. if (normalizedPath[i] === '..') {
  14929. nb++
  14930. continue
  14931. }
  14932. if (nb > 0) {
  14933. nb--
  14934. continue
  14935. }
  14936. o.push(normalizedPath[i])
  14937. }
  14938. i = normalizedBase.length - nb
  14939. if (i <= 0) {
  14940. outPath = reverse(o).join('/')
  14941. } else {
  14942. outPath =
  14943. normalizedBase.slice(0, i).join('/') + '/' + reverse(o).join('/')
  14944. }
  14945. if (outPath.indexOf('/') !== 0) {
  14946. outPath = '/' + outPath
  14947. }
  14948. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) {
  14949. outPath += tr
  14950. }
  14951. return outPath
  14952. }
  14953. URI.prototype.getURI = function (noProtoHost) {
  14954. if (noProtoHost === void 0) {
  14955. noProtoHost = false
  14956. }
  14957. var s
  14958. if (!this.source || noProtoHost) {
  14959. s = ''
  14960. if (!noProtoHost) {
  14961. if (this.protocol) {
  14962. s += this.protocol + '://'
  14963. } else {
  14964. s += '//'
  14965. }
  14966. if (this.userInfo) {
  14967. s += this.userInfo + '@'
  14968. }
  14969. if (this.host) {
  14970. s += this.host
  14971. }
  14972. if (this.port) {
  14973. s += ':' + this.port
  14974. }
  14975. }
  14976. if (this.path) {
  14977. s += this.path
  14978. }
  14979. if (this.query) {
  14980. s += '?' + this.query
  14981. }
  14982. if (this.anchor) {
  14983. s += '#' + this.anchor
  14984. }
  14985. this.source = s
  14986. }
  14987. return this.source
  14988. }
  14989. return URI
  14990. })()
  14991. var filteredClobberElements = Tools.makeMap(
  14992. 'button,fieldset,form,iframe,img,image,input,object,output,select,textarea'
  14993. )
  14994. var isValidPrefixAttrName = function (name) {
  14995. return name.indexOf('data-') === 0 || name.indexOf('aria-') === 0
  14996. }
  14997. var findMatchingEndTagIndex = function (schema, html, startIndex) {
  14998. var startTagRegExp = /<([!?\/])?([A-Za-z0-9\-_:.]+)/g
  14999. var endTagRegExp =
  15000. /(?:\s(?:[^'">]+(?:"[^"]*"|'[^']*'))*[^"'>]*(?:"[^">]*|'[^'>]*)?|\s*|\/)>/g
  15001. var shortEndedElements = schema.getShortEndedElements()
  15002. var count = 1,
  15003. index = startIndex
  15004. while (count !== 0) {
  15005. startTagRegExp.lastIndex = index
  15006. while (true) {
  15007. var startMatch = startTagRegExp.exec(html)
  15008. if (startMatch === null) {
  15009. return index
  15010. } else if (startMatch[1] === '!') {
  15011. if (startsWith(startMatch[2], '--')) {
  15012. index = findCommentEndIndex(
  15013. html,
  15014. false,
  15015. startMatch.index + '!--'.length
  15016. )
  15017. } else {
  15018. index = findCommentEndIndex(html, true, startMatch.index + 1)
  15019. }
  15020. break
  15021. } else {
  15022. endTagRegExp.lastIndex = startTagRegExp.lastIndex
  15023. var endMatch = endTagRegExp.exec(html)
  15024. if (isNull(endMatch) || endMatch.index !== startTagRegExp.lastIndex) {
  15025. continue
  15026. }
  15027. if (startMatch[1] === '/') {
  15028. count -= 1
  15029. } else if (!has$2(shortEndedElements, startMatch[2])) {
  15030. count += 1
  15031. }
  15032. index = startTagRegExp.lastIndex + endMatch[0].length
  15033. break
  15034. }
  15035. }
  15036. }
  15037. return index
  15038. }
  15039. var isConditionalComment = function (html, startIndex) {
  15040. return /^\s*\[if [\w\W]+\]>.*<!\[endif\](--!?)?>/.test(
  15041. html.substr(startIndex)
  15042. )
  15043. }
  15044. var findCommentEndIndex = function (html, isBogus, startIndex) {
  15045. if (startIndex === void 0) {
  15046. startIndex = 0
  15047. }
  15048. var lcHtml = html.toLowerCase()
  15049. if (
  15050. lcHtml.indexOf('[if ', startIndex) !== -1 &&
  15051. isConditionalComment(lcHtml, startIndex)
  15052. ) {
  15053. var endIfIndex = lcHtml.indexOf('[endif]', startIndex)
  15054. return lcHtml.indexOf('>', endIfIndex)
  15055. } else {
  15056. if (isBogus) {
  15057. var endIndex = lcHtml.indexOf('>', startIndex)
  15058. return endIndex !== -1 ? endIndex : lcHtml.length
  15059. } else {
  15060. var endCommentRegexp = /--!?>/g
  15061. endCommentRegexp.lastIndex = startIndex
  15062. var match = endCommentRegexp.exec(html)
  15063. return match ? match.index + match[0].length : lcHtml.length
  15064. }
  15065. }
  15066. }
  15067. var checkBogusAttribute = function (regExp, attrString) {
  15068. var matches = regExp.exec(attrString)
  15069. if (matches) {
  15070. var name_1 = matches[1]
  15071. var value = matches[2]
  15072. return typeof name_1 === 'string' &&
  15073. name_1.toLowerCase() === 'data-mce-bogus'
  15074. ? value
  15075. : null
  15076. } else {
  15077. return null
  15078. }
  15079. }
  15080. var SaxParser = function (settings, schema) {
  15081. var _a
  15082. if (schema === void 0) {
  15083. schema = Schema()
  15084. }
  15085. settings = settings || {}
  15086. var doc = (_a = settings.document) !== null && _a !== void 0 ? _a : document
  15087. var form = doc.createElement('form')
  15088. if (settings.fix_self_closing !== false) {
  15089. settings.fix_self_closing = true
  15090. }
  15091. var comment = settings.comment ? settings.comment : noop
  15092. var cdata = settings.cdata ? settings.cdata : noop
  15093. var text = settings.text ? settings.text : noop
  15094. var start = settings.start ? settings.start : noop
  15095. var end = settings.end ? settings.end : noop
  15096. var pi = settings.pi ? settings.pi : noop
  15097. var doctype = settings.doctype ? settings.doctype : noop
  15098. var parseInternal = function (base64Extract, format) {
  15099. if (format === void 0) {
  15100. format = 'html'
  15101. }
  15102. var html = base64Extract.html
  15103. var matches,
  15104. index = 0,
  15105. value,
  15106. endRegExp
  15107. var stack = []
  15108. var attrList, i, textData, name
  15109. var isInternalElement, isShortEnded
  15110. var elementRule,
  15111. isValidElement,
  15112. attr,
  15113. attribsValue,
  15114. validAttributesMap,
  15115. validAttributePatterns
  15116. var attributesRequired, attributesDefault, attributesForced
  15117. var anyAttributesRequired,
  15118. attrValue,
  15119. idCount = 0
  15120. var decode = Entities.decode
  15121. var filteredUrlAttrs = Tools.makeMap(
  15122. 'src,href,data,background,action,formaction,poster,xlink:href'
  15123. )
  15124. var parsingMode = format === 'html' ? 0 : 1
  15125. var processEndTag = function (name) {
  15126. var pos, i
  15127. pos = stack.length
  15128. while (pos--) {
  15129. if (stack[pos].name === name) {
  15130. break
  15131. }
  15132. }
  15133. if (pos >= 0) {
  15134. for (i = stack.length - 1; i >= pos; i--) {
  15135. name = stack[i]
  15136. if (name.valid) {
  15137. end(name.name)
  15138. }
  15139. }
  15140. stack.length = pos
  15141. }
  15142. }
  15143. var processText = function (value, raw) {
  15144. return text(restoreDataUris(value, base64Extract), raw)
  15145. }
  15146. var processComment = function (value) {
  15147. if (value === '') {
  15148. return
  15149. }
  15150. if (value.charAt(0) === '>') {
  15151. value = ' ' + value
  15152. }
  15153. if (
  15154. !settings.allow_conditional_comments &&
  15155. value.substr(0, 3).toLowerCase() === '[if'
  15156. ) {
  15157. value = ' ' + value
  15158. }
  15159. comment(restoreDataUris(value, base64Extract))
  15160. }
  15161. var processAttr = function (value) {
  15162. return restoreDataUris(value, base64Extract)
  15163. }
  15164. var processMalformedComment = function (value, startIndex) {
  15165. var startTag = value || ''
  15166. var isBogus = !startsWith(startTag, '--')
  15167. var endIndex = findCommentEndIndex(html, isBogus, startIndex)
  15168. value = html.substr(startIndex, endIndex - startIndex)
  15169. processComment(isBogus ? startTag + value : value)
  15170. return endIndex + 1
  15171. }
  15172. var parseAttribute = function (tagName, name, value, val2, val3) {
  15173. name = name.toLowerCase()
  15174. value = processAttr(
  15175. name in fillAttrsMap ? name : decode(value || val2 || val3 || '')
  15176. )
  15177. if (
  15178. validate &&
  15179. !isInternalElement &&
  15180. isValidPrefixAttrName(name) === false
  15181. ) {
  15182. var attrRule = validAttributesMap[name]
  15183. if (!attrRule && validAttributePatterns) {
  15184. var i_1 = validAttributePatterns.length
  15185. while (i_1--) {
  15186. attrRule = validAttributePatterns[i_1]
  15187. if (attrRule.pattern.test(name)) {
  15188. break
  15189. }
  15190. }
  15191. if (i_1 === -1) {
  15192. attrRule = null
  15193. }
  15194. }
  15195. if (!attrRule) {
  15196. return
  15197. }
  15198. if (attrRule.validValues && !(value in attrRule.validValues)) {
  15199. return
  15200. }
  15201. }
  15202. var isNameOrId = name === 'name' || name === 'id'
  15203. if (
  15204. isNameOrId &&
  15205. tagName in filteredClobberElements &&
  15206. (value in doc || value in form)
  15207. ) {
  15208. return
  15209. }
  15210. if (
  15211. filteredUrlAttrs[name] &&
  15212. !URI.isDomSafe(value, tagName, settings)
  15213. ) {
  15214. return
  15215. }
  15216. if (
  15217. isInternalElement &&
  15218. (name in filteredUrlAttrs || name.indexOf('on') === 0)
  15219. ) {
  15220. return
  15221. }
  15222. attrList.map[name] = value
  15223. attrList.push({
  15224. name: name,
  15225. value: value,
  15226. })
  15227. }
  15228. var tokenRegExp = new RegExp(
  15229. '<(?:' +
  15230. '(?:!--([\\w\\W]*?)--!?>)|' +
  15231. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' +
  15232. '(?:![Dd][Oo][Cc][Tt][Yy][Pp][Ee]([\\w\\W]*?)>)|' +
  15233. '(?:!(--)?)|' +
  15234. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' +
  15235. '(?:\\/([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)>)|' +
  15236. '(?:([A-Za-z][A-Za-z0-9\\-_:.]*)(\\s(?:[^\'">]+(?:"[^"]*"|\'[^\']*\'))*[^"\'>]*(?:"[^">]*|\'[^\'>]*)?|\\s*|\\/)>)' +
  15237. ')',
  15238. 'g'
  15239. )
  15240. var attrRegExp =
  15241. /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g
  15242. var shortEndedElements = schema.getShortEndedElements()
  15243. var selfClosing =
  15244. settings.self_closing_elements || schema.getSelfClosingElements()
  15245. var fillAttrsMap = schema.getBoolAttrs()
  15246. var validate = settings.validate
  15247. var removeInternalElements = settings.remove_internals
  15248. var fixSelfClosing = settings.fix_self_closing
  15249. var specialElements = schema.getSpecialElements()
  15250. var processHtml = html + '>'
  15251. while ((matches = tokenRegExp.exec(processHtml))) {
  15252. var matchText = matches[0]
  15253. if (index < matches.index) {
  15254. processText(decode(html.substr(index, matches.index - index)))
  15255. }
  15256. if ((value = matches[7])) {
  15257. value = value.toLowerCase()
  15258. if (value.charAt(0) === ':') {
  15259. value = value.substr(1)
  15260. }
  15261. processEndTag(value)
  15262. } else if ((value = matches[8])) {
  15263. if (matches.index + matchText.length > html.length) {
  15264. processText(decode(html.substr(matches.index)))
  15265. index = matches.index + matchText.length
  15266. continue
  15267. }
  15268. value = value.toLowerCase()
  15269. if (value.charAt(0) === ':') {
  15270. value = value.substr(1)
  15271. }
  15272. isShortEnded = value in shortEndedElements
  15273. if (
  15274. fixSelfClosing &&
  15275. selfClosing[value] &&
  15276. stack.length > 0 &&
  15277. stack[stack.length - 1].name === value
  15278. ) {
  15279. processEndTag(value)
  15280. }
  15281. var bogusValue = checkBogusAttribute(attrRegExp, matches[9])
  15282. if (bogusValue !== null) {
  15283. if (bogusValue === 'all') {
  15284. index = findMatchingEndTagIndex(
  15285. schema,
  15286. html,
  15287. tokenRegExp.lastIndex
  15288. )
  15289. tokenRegExp.lastIndex = index
  15290. continue
  15291. }
  15292. isValidElement = false
  15293. }
  15294. if (!validate || (elementRule = schema.getElementRule(value))) {
  15295. isValidElement = true
  15296. if (validate) {
  15297. validAttributesMap = elementRule.attributes
  15298. validAttributePatterns = elementRule.attributePatterns
  15299. }
  15300. if ((attribsValue = matches[9])) {
  15301. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1
  15302. if (isInternalElement && removeInternalElements) {
  15303. isValidElement = false
  15304. }
  15305. attrList = []
  15306. attrList.map = {}
  15307. attribsValue.replace(
  15308. attrRegExp,
  15309. function (match, name, val, val2, val3) {
  15310. parseAttribute(value, name, val, val2, val3)
  15311. return ''
  15312. }
  15313. )
  15314. } else {
  15315. attrList = []
  15316. attrList.map = {}
  15317. }
  15318. if (validate && !isInternalElement) {
  15319. attributesRequired = elementRule.attributesRequired
  15320. attributesDefault = elementRule.attributesDefault
  15321. attributesForced = elementRule.attributesForced
  15322. anyAttributesRequired = elementRule.removeEmptyAttrs
  15323. if (anyAttributesRequired && !attrList.length) {
  15324. isValidElement = false
  15325. }
  15326. if (attributesForced) {
  15327. i = attributesForced.length
  15328. while (i--) {
  15329. attr = attributesForced[i]
  15330. name = attr.name
  15331. attrValue = attr.value
  15332. if (attrValue === '{$uid}') {
  15333. attrValue = 'mce_' + idCount++
  15334. }
  15335. attrList.map[name] = attrValue
  15336. attrList.push({
  15337. name: name,
  15338. value: attrValue,
  15339. })
  15340. }
  15341. }
  15342. if (attributesDefault) {
  15343. i = attributesDefault.length
  15344. while (i--) {
  15345. attr = attributesDefault[i]
  15346. name = attr.name
  15347. if (!(name in attrList.map)) {
  15348. attrValue = attr.value
  15349. if (attrValue === '{$uid}') {
  15350. attrValue = 'mce_' + idCount++
  15351. }
  15352. attrList.map[name] = attrValue
  15353. attrList.push({
  15354. name: name,
  15355. value: attrValue,
  15356. })
  15357. }
  15358. }
  15359. }
  15360. if (attributesRequired) {
  15361. i = attributesRequired.length
  15362. while (i--) {
  15363. if (attributesRequired[i] in attrList.map) {
  15364. break
  15365. }
  15366. }
  15367. if (i === -1) {
  15368. isValidElement = false
  15369. }
  15370. }
  15371. if ((attr = attrList.map['data-mce-bogus'])) {
  15372. if (attr === 'all') {
  15373. index = findMatchingEndTagIndex(
  15374. schema,
  15375. html,
  15376. tokenRegExp.lastIndex
  15377. )
  15378. tokenRegExp.lastIndex = index
  15379. continue
  15380. }
  15381. isValidElement = false
  15382. }
  15383. }
  15384. if (isValidElement) {
  15385. start(value, attrList, isShortEnded)
  15386. }
  15387. } else {
  15388. isValidElement = false
  15389. }
  15390. if ((endRegExp = specialElements[value])) {
  15391. endRegExp.lastIndex = index = matches.index + matchText.length
  15392. if ((matches = endRegExp.exec(html))) {
  15393. if (isValidElement) {
  15394. textData = html.substr(index, matches.index - index)
  15395. }
  15396. index = matches.index + matches[0].length
  15397. } else {
  15398. textData = html.substr(index)
  15399. index = html.length
  15400. }
  15401. if (isValidElement) {
  15402. if (textData.length > 0) {
  15403. processText(textData, true)
  15404. }
  15405. end(value)
  15406. }
  15407. tokenRegExp.lastIndex = index
  15408. continue
  15409. }
  15410. if (!isShortEnded) {
  15411. if (
  15412. !attribsValue ||
  15413. attribsValue.indexOf('/') !== attribsValue.length - 1
  15414. ) {
  15415. stack.push({
  15416. name: value,
  15417. valid: isValidElement,
  15418. })
  15419. } else if (isValidElement) {
  15420. end(value)
  15421. }
  15422. }
  15423. } else if ((value = matches[1])) {
  15424. processComment(value)
  15425. } else if ((value = matches[2])) {
  15426. var isValidCdataSection =
  15427. parsingMode === 1 ||
  15428. settings.preserve_cdata ||
  15429. (stack.length > 0 &&
  15430. schema.isValidChild(stack[stack.length - 1].name, '#cdata'))
  15431. if (isValidCdataSection) {
  15432. cdata(value)
  15433. } else {
  15434. index = processMalformedComment('', matches.index + 2)
  15435. tokenRegExp.lastIndex = index
  15436. continue
  15437. }
  15438. } else if ((value = matches[3])) {
  15439. doctype(value)
  15440. } else if ((value = matches[4]) || matchText === '<!') {
  15441. index = processMalformedComment(
  15442. value,
  15443. matches.index + matchText.length
  15444. )
  15445. tokenRegExp.lastIndex = index
  15446. continue
  15447. } else if ((value = matches[5])) {
  15448. if (parsingMode === 1) {
  15449. pi(value, matches[6])
  15450. } else {
  15451. index = processMalformedComment('?', matches.index + 2)
  15452. tokenRegExp.lastIndex = index
  15453. continue
  15454. }
  15455. }
  15456. index = matches.index + matchText.length
  15457. }
  15458. if (index < html.length) {
  15459. processText(decode(html.substr(index)))
  15460. }
  15461. for (i = stack.length - 1; i >= 0; i--) {
  15462. value = stack[i]
  15463. if (value.valid) {
  15464. end(value.name)
  15465. }
  15466. }
  15467. }
  15468. var parse = function (html, format) {
  15469. if (format === void 0) {
  15470. format = 'html'
  15471. }
  15472. parseInternal(extractBase64DataUris(html), format)
  15473. }
  15474. return { parse: parse }
  15475. }
  15476. SaxParser.findEndTag = findMatchingEndTagIndex
  15477. var trimHtml = function (tempAttrs, html) {
  15478. var trimContentRegExp = new RegExp(
  15479. ['\\s?(' + tempAttrs.join('|') + ')="[^"]+"'].join('|'),
  15480. 'gi'
  15481. )
  15482. return html.replace(trimContentRegExp, '')
  15483. }
  15484. var trimInternal = function (serializer, html) {
  15485. var bogusAllRegExp = /<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g
  15486. var schema = serializer.schema
  15487. var content = trimHtml(serializer.getTempAttrs(), html)
  15488. var shortEndedElements = schema.getShortEndedElements()
  15489. var matches
  15490. while ((matches = bogusAllRegExp.exec(content))) {
  15491. var index = bogusAllRegExp.lastIndex
  15492. var matchLength = matches[0].length
  15493. var endTagIndex = void 0
  15494. if (shortEndedElements[matches[1]]) {
  15495. endTagIndex = index
  15496. } else {
  15497. endTagIndex = SaxParser.findEndTag(schema, content, index)
  15498. }
  15499. content =
  15500. content.substring(0, index - matchLength) +
  15501. content.substring(endTagIndex)
  15502. bogusAllRegExp.lastIndex = index - matchLength
  15503. }
  15504. return trim$2(content)
  15505. }
  15506. var trimExternal = trimInternal
  15507. var trimEmptyContents = function (editor, html) {
  15508. var blockName = getForcedRootBlock(editor)
  15509. var emptyRegExp = new RegExp(
  15510. '^(<' +
  15511. blockName +
  15512. '[^>]*>(&nbsp;|&#160;|\\s|\xA0|<br \\/>|)<\\/' +
  15513. blockName +
  15514. '>[\r\n]*|<br \\/>[\r\n]*)$'
  15515. )
  15516. return html.replace(emptyRegExp, '')
  15517. }
  15518. var setupArgs$3 = function (args, format) {
  15519. return __assign(__assign({}, args), {
  15520. format: format,
  15521. get: true,
  15522. getInner: true,
  15523. })
  15524. }
  15525. var getContentFromBody = function (editor, args, format, body) {
  15526. var defaultedArgs = setupArgs$3(args, format)
  15527. var updatedArgs = args.no_events
  15528. ? defaultedArgs
  15529. : editor.fire('BeforeGetContent', defaultedArgs)
  15530. var content
  15531. if (updatedArgs.format === 'raw') {
  15532. content = Tools.trim(trimExternal(editor.serializer, body.innerHTML))
  15533. } else if (updatedArgs.format === 'text') {
  15534. content = editor.dom.isEmpty(body)
  15535. ? ''
  15536. : trim$2(body.innerText || body.textContent)
  15537. } else if (updatedArgs.format === 'tree') {
  15538. content = editor.serializer.serialize(body, updatedArgs)
  15539. } else {
  15540. content = trimEmptyContents(
  15541. editor,
  15542. editor.serializer.serialize(body, updatedArgs)
  15543. )
  15544. }
  15545. if (
  15546. !contains$3(['text', 'tree'], updatedArgs.format) &&
  15547. !isWsPreserveElement(SugarElement.fromDom(body))
  15548. ) {
  15549. updatedArgs.content = Tools.trim(content)
  15550. } else {
  15551. updatedArgs.content = content
  15552. }
  15553. if (updatedArgs.no_events) {
  15554. return updatedArgs.content
  15555. } else {
  15556. return editor.fire('GetContent', updatedArgs).content
  15557. }
  15558. }
  15559. var getContentInternal = function (editor, args, format) {
  15560. return Optional.from(editor.getBody()).fold(
  15561. constant(args.format === 'tree' ? new AstNode('body', 11) : ''),
  15562. function (body) {
  15563. return getContentFromBody(editor, args, format, body)
  15564. }
  15565. )
  15566. }
  15567. var each$c = Tools.each
  15568. var ElementUtils = function (dom) {
  15569. var compare = function (node1, node2) {
  15570. if (node1.nodeName !== node2.nodeName) {
  15571. return false
  15572. }
  15573. var getAttribs = function (node) {
  15574. var attribs = {}
  15575. each$c(dom.getAttribs(node), function (attr) {
  15576. var name = attr.nodeName.toLowerCase()
  15577. if (
  15578. name.indexOf('_') !== 0 &&
  15579. name !== 'style' &&
  15580. name.indexOf('data-') !== 0
  15581. ) {
  15582. attribs[name] = dom.getAttrib(node, name)
  15583. }
  15584. })
  15585. return attribs
  15586. }
  15587. var compareObjects = function (obj1, obj2) {
  15588. var value, name
  15589. for (name in obj1) {
  15590. if (has$2(obj1, name)) {
  15591. value = obj2[name]
  15592. if (typeof value === 'undefined') {
  15593. return false
  15594. }
  15595. if (obj1[name] !== value) {
  15596. return false
  15597. }
  15598. delete obj2[name]
  15599. }
  15600. }
  15601. for (name in obj2) {
  15602. if (has$2(obj2, name)) {
  15603. return false
  15604. }
  15605. }
  15606. return true
  15607. }
  15608. if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
  15609. return false
  15610. }
  15611. if (
  15612. !compareObjects(
  15613. dom.parseStyle(dom.getAttrib(node1, 'style')),
  15614. dom.parseStyle(dom.getAttrib(node2, 'style'))
  15615. )
  15616. ) {
  15617. return false
  15618. }
  15619. return !isBookmarkNode$1(node1) && !isBookmarkNode$1(node2)
  15620. }
  15621. return { compare: compare }
  15622. }
  15623. var makeMap$1 = Tools.makeMap
  15624. var Writer = function (settings) {
  15625. var html = []
  15626. settings = settings || {}
  15627. var indent = settings.indent
  15628. var indentBefore = makeMap$1(settings.indent_before || '')
  15629. var indentAfter = makeMap$1(settings.indent_after || '')
  15630. var encode = Entities.getEncodeFunc(
  15631. settings.entity_encoding || 'raw',
  15632. settings.entities
  15633. )
  15634. var htmlOutput = settings.element_format === 'html'
  15635. return {
  15636. start: function (name, attrs, empty) {
  15637. var i, l, attr, value
  15638. if (indent && indentBefore[name] && html.length > 0) {
  15639. value = html[html.length - 1]
  15640. if (value.length > 0 && value !== '\n') {
  15641. html.push('\n')
  15642. }
  15643. }
  15644. html.push('<', name)
  15645. if (attrs) {
  15646. for (i = 0, l = attrs.length; i < l; i++) {
  15647. attr = attrs[i]
  15648. html.push(' ', attr.name, '="', encode(attr.value, true), '"')
  15649. }
  15650. }
  15651. if (!empty || htmlOutput) {
  15652. html[html.length] = '>'
  15653. } else {
  15654. html[html.length] = ' />'
  15655. }
  15656. if (empty && indent && indentAfter[name] && html.length > 0) {
  15657. value = html[html.length - 1]
  15658. if (value.length > 0 && value !== '\n') {
  15659. html.push('\n')
  15660. }
  15661. }
  15662. },
  15663. end: function (name) {
  15664. var value
  15665. html.push('</', name, '>')
  15666. if (indent && indentAfter[name] && html.length > 0) {
  15667. value = html[html.length - 1]
  15668. if (value.length > 0 && value !== '\n') {
  15669. html.push('\n')
  15670. }
  15671. }
  15672. },
  15673. text: function (text, raw) {
  15674. if (text.length > 0) {
  15675. html[html.length] = raw ? text : encode(text)
  15676. }
  15677. },
  15678. cdata: function (text) {
  15679. html.push('<![CDATA[', text, ']]>')
  15680. },
  15681. comment: function (text) {
  15682. html.push('<!--', text, '-->')
  15683. },
  15684. pi: function (name, text) {
  15685. if (text) {
  15686. html.push('<?', name, ' ', encode(text), '?>')
  15687. } else {
  15688. html.push('<?', name, '?>')
  15689. }
  15690. if (indent) {
  15691. html.push('\n')
  15692. }
  15693. },
  15694. doctype: function (text) {
  15695. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '')
  15696. },
  15697. reset: function () {
  15698. html.length = 0
  15699. },
  15700. getContent: function () {
  15701. return html.join('').replace(/\n$/, '')
  15702. },
  15703. }
  15704. }
  15705. var HtmlSerializer = function (settings, schema) {
  15706. if (schema === void 0) {
  15707. schema = Schema()
  15708. }
  15709. var writer = Writer(settings)
  15710. settings = settings || {}
  15711. settings.validate = 'validate' in settings ? settings.validate : true
  15712. var serialize = function (node) {
  15713. var validate = settings.validate
  15714. var handlers = {
  15715. 3: function (node) {
  15716. writer.text(node.value, node.raw)
  15717. },
  15718. 8: function (node) {
  15719. writer.comment(node.value)
  15720. },
  15721. 7: function (node) {
  15722. writer.pi(node.name, node.value)
  15723. },
  15724. 10: function (node) {
  15725. writer.doctype(node.value)
  15726. },
  15727. 4: function (node) {
  15728. writer.cdata(node.value)
  15729. },
  15730. 11: function (node) {
  15731. if ((node = node.firstChild)) {
  15732. do {
  15733. walk(node)
  15734. } while ((node = node.next))
  15735. }
  15736. },
  15737. }
  15738. writer.reset()
  15739. var walk = function (node) {
  15740. var handler = handlers[node.type]
  15741. if (!handler) {
  15742. var name_1 = node.name
  15743. var isEmpty = node.shortEnded
  15744. var attrs = node.attributes
  15745. if (validate && attrs && attrs.length > 1) {
  15746. var sortedAttrs = []
  15747. sortedAttrs.map = {}
  15748. var elementRule = schema.getElementRule(node.name)
  15749. if (elementRule) {
  15750. for (
  15751. var i = 0, l = elementRule.attributesOrder.length;
  15752. i < l;
  15753. i++
  15754. ) {
  15755. var attrName = elementRule.attributesOrder[i]
  15756. if (attrName in attrs.map) {
  15757. var attrValue = attrs.map[attrName]
  15758. sortedAttrs.map[attrName] = attrValue
  15759. sortedAttrs.push({
  15760. name: attrName,
  15761. value: attrValue,
  15762. })
  15763. }
  15764. }
  15765. for (var i = 0, l = attrs.length; i < l; i++) {
  15766. var attrName = attrs[i].name
  15767. if (!(attrName in sortedAttrs.map)) {
  15768. var attrValue = attrs.map[attrName]
  15769. sortedAttrs.map[attrName] = attrValue
  15770. sortedAttrs.push({
  15771. name: attrName,
  15772. value: attrValue,
  15773. })
  15774. }
  15775. }
  15776. attrs = sortedAttrs
  15777. }
  15778. }
  15779. writer.start(node.name, attrs, isEmpty)
  15780. if (!isEmpty) {
  15781. if ((node = node.firstChild)) {
  15782. do {
  15783. walk(node)
  15784. } while ((node = node.next))
  15785. }
  15786. writer.end(name_1)
  15787. }
  15788. } else {
  15789. handler(node)
  15790. }
  15791. }
  15792. if (node.type === 1 && !settings.inner) {
  15793. walk(node)
  15794. } else {
  15795. handlers[11](node)
  15796. }
  15797. return writer.getContent()
  15798. }
  15799. return { serialize: serialize }
  15800. }
  15801. var nonInheritableStyles = new Set()
  15802. ;(function () {
  15803. var nonInheritableStylesArr = [
  15804. 'margin',
  15805. 'margin-left',
  15806. 'margin-right',
  15807. 'margin-top',
  15808. 'margin-bottom',
  15809. 'padding',
  15810. 'padding-left',
  15811. 'padding-right',
  15812. 'padding-top',
  15813. 'padding-bottom',
  15814. 'border',
  15815. 'border-width',
  15816. 'border-style',
  15817. 'border-color',
  15818. 'background',
  15819. 'background-attachment',
  15820. 'background-clip',
  15821. 'background-color',
  15822. 'background-image',
  15823. 'background-origin',
  15824. 'background-position',
  15825. 'background-repeat',
  15826. 'background-size',
  15827. 'float',
  15828. 'position',
  15829. 'left',
  15830. 'right',
  15831. 'top',
  15832. 'bottom',
  15833. 'z-index',
  15834. 'display',
  15835. 'transform',
  15836. 'width',
  15837. 'max-width',
  15838. 'min-width',
  15839. 'height',
  15840. 'max-height',
  15841. 'min-height',
  15842. 'overflow',
  15843. 'overflow-x',
  15844. 'overflow-y',
  15845. 'text-overflow',
  15846. 'vertical-align',
  15847. 'transition',
  15848. 'transition-delay',
  15849. 'transition-duration',
  15850. 'transition-property',
  15851. 'transition-timing-function',
  15852. ]
  15853. each$k(nonInheritableStylesArr, function (style) {
  15854. nonInheritableStyles.add(style)
  15855. })
  15856. })()
  15857. var shorthandStyleProps = ['font', 'text-decoration', 'text-emphasis']
  15858. var getStyleProps = function (dom, node) {
  15859. return keys(dom.parseStyle(dom.getAttrib(node, 'style')))
  15860. }
  15861. var isNonInheritableStyle = function (style) {
  15862. return nonInheritableStyles.has(style)
  15863. }
  15864. var hasInheritableStyles = function (dom, node) {
  15865. return forall(getStyleProps(dom, node), function (style) {
  15866. return !isNonInheritableStyle(style)
  15867. })
  15868. }
  15869. var getLonghandStyleProps = function (styles) {
  15870. return filter$4(styles, function (style) {
  15871. return exists(shorthandStyleProps, function (prop) {
  15872. return startsWith(style, prop)
  15873. })
  15874. })
  15875. }
  15876. var hasStyleConflict = function (dom, node, parentNode) {
  15877. var nodeStyleProps = getStyleProps(dom, node)
  15878. var parentNodeStyleProps = getStyleProps(dom, parentNode)
  15879. var valueMismatch = function (prop) {
  15880. var nodeValue = dom.getStyle(node, prop)
  15881. var parentValue = dom.getStyle(parentNode, prop)
  15882. return (
  15883. isNotEmpty(nodeValue) &&
  15884. isNotEmpty(parentValue) &&
  15885. nodeValue !== parentValue
  15886. )
  15887. }
  15888. return exists(nodeStyleProps, function (nodeStyleProp) {
  15889. var propExists = function (props) {
  15890. return exists(props, function (prop) {
  15891. return prop === nodeStyleProp
  15892. })
  15893. }
  15894. if (
  15895. !propExists(parentNodeStyleProps) &&
  15896. propExists(shorthandStyleProps)
  15897. ) {
  15898. var longhandProps = getLonghandStyleProps(parentNodeStyleProps)
  15899. return exists(longhandProps, valueMismatch)
  15900. } else {
  15901. return valueMismatch(nodeStyleProp)
  15902. }
  15903. })
  15904. }
  15905. var isChar = function (forward, predicate, pos) {
  15906. return Optional.from(pos.container())
  15907. .filter(isText$7)
  15908. .exists(function (text) {
  15909. var delta = forward ? 0 : -1
  15910. return predicate(text.data.charAt(pos.offset() + delta))
  15911. })
  15912. }
  15913. var isBeforeSpace = curry(isChar, true, isWhiteSpace)
  15914. var isAfterSpace = curry(isChar, false, isWhiteSpace)
  15915. var isEmptyText = function (pos) {
  15916. var container = pos.container()
  15917. return (
  15918. isText$7(container) &&
  15919. (container.data.length === 0 ||
  15920. (isZwsp(container.data) &&
  15921. BookmarkManager.isBookmarkNode(container.parentNode)))
  15922. )
  15923. }
  15924. var matchesElementPosition = function (before, predicate) {
  15925. return function (pos) {
  15926. return Optional.from(getChildNodeAtRelativeOffset(before ? 0 : -1, pos))
  15927. .filter(predicate)
  15928. .isSome()
  15929. }
  15930. }
  15931. var isImageBlock = function (node) {
  15932. return (
  15933. isImg(node) && get$5(SugarElement.fromDom(node), 'display') === 'block'
  15934. )
  15935. }
  15936. var isCefNode = function (node) {
  15937. return isContentEditableFalse$b(node) && !isBogusAll$1(node)
  15938. }
  15939. var isBeforeImageBlock = matchesElementPosition(true, isImageBlock)
  15940. var isAfterImageBlock = matchesElementPosition(false, isImageBlock)
  15941. var isBeforeMedia = matchesElementPosition(true, isMedia$2)
  15942. var isAfterMedia = matchesElementPosition(false, isMedia$2)
  15943. var isBeforeTable = matchesElementPosition(true, isTable$3)
  15944. var isAfterTable = matchesElementPosition(false, isTable$3)
  15945. var isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode)
  15946. var isAfterContentEditableFalse = matchesElementPosition(false, isCefNode)
  15947. var getLastChildren = function (elm) {
  15948. var children = []
  15949. var rawNode = elm.dom
  15950. while (rawNode) {
  15951. children.push(SugarElement.fromDom(rawNode))
  15952. rawNode = rawNode.lastChild
  15953. }
  15954. return children
  15955. }
  15956. var removeTrailingBr = function (elm) {
  15957. var allBrs = descendants(elm, 'br')
  15958. var brs = filter$4(getLastChildren(elm).slice(-1), isBr$4)
  15959. if (allBrs.length === brs.length) {
  15960. each$k(brs, remove$7)
  15961. }
  15962. }
  15963. var fillWithPaddingBr = function (elm) {
  15964. empty(elm)
  15965. append$1(elm, SugarElement.fromHtml('<br data-mce-bogus="1">'))
  15966. }
  15967. var trimBlockTrailingBr = function (elm) {
  15968. lastChild(elm).each(function (lastChild) {
  15969. prevSibling(lastChild).each(function (lastChildPrevSibling) {
  15970. if (
  15971. isBlock$2(elm) &&
  15972. isBr$4(lastChild) &&
  15973. isBlock$2(lastChildPrevSibling)
  15974. ) {
  15975. remove$7(lastChild)
  15976. }
  15977. })
  15978. })
  15979. }
  15980. var dropLast = function (xs) {
  15981. return xs.slice(0, -1)
  15982. }
  15983. var parentsUntil = function (start, root, predicate) {
  15984. if (contains$1(root, start)) {
  15985. return dropLast(
  15986. parents$1(start, function (elm) {
  15987. return predicate(elm) || eq(elm, root)
  15988. })
  15989. )
  15990. } else {
  15991. return []
  15992. }
  15993. }
  15994. var parents = function (start, root) {
  15995. return parentsUntil(start, root, never)
  15996. }
  15997. var parentsAndSelf = function (start, root) {
  15998. return [start].concat(parents(start, root))
  15999. }
  16000. var navigateIgnoreEmptyTextNodes = function (forward, root, from) {
  16001. return navigateIgnore(forward, root, from, isEmptyText)
  16002. }
  16003. var getClosestBlock$1 = function (root, pos) {
  16004. return find$3(
  16005. parentsAndSelf(SugarElement.fromDom(pos.container()), root),
  16006. isBlock$2
  16007. )
  16008. }
  16009. var isAtBeforeAfterBlockBoundary = function (forward, root, pos) {
  16010. return navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(
  16011. function (newPos) {
  16012. return getClosestBlock$1(root, pos).fold(
  16013. function () {
  16014. return isInSameBlock(newPos, pos, root.dom) === false
  16015. },
  16016. function (fromBlock) {
  16017. return (
  16018. isInSameBlock(newPos, pos, root.dom) === false &&
  16019. contains$1(fromBlock, SugarElement.fromDom(newPos.container()))
  16020. )
  16021. }
  16022. )
  16023. }
  16024. )
  16025. }
  16026. var isAtBlockBoundary = function (forward, root, pos) {
  16027. return getClosestBlock$1(root, pos).fold(
  16028. function () {
  16029. return navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(
  16030. function (newPos) {
  16031. return isInSameBlock(newPos, pos, root.dom) === false
  16032. }
  16033. )
  16034. },
  16035. function (parent) {
  16036. return navigateIgnoreEmptyTextNodes(forward, parent.dom, pos).isNone()
  16037. }
  16038. )
  16039. }
  16040. var isAtStartOfBlock = curry(isAtBlockBoundary, false)
  16041. var isAtEndOfBlock = curry(isAtBlockBoundary, true)
  16042. var isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false)
  16043. var isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true)
  16044. var isBr = function (pos) {
  16045. return getElementFromPosition(pos).exists(isBr$4)
  16046. }
  16047. var findBr = function (forward, root, pos) {
  16048. var parentBlocks = filter$4(
  16049. parentsAndSelf(SugarElement.fromDom(pos.container()), root),
  16050. isBlock$2
  16051. )
  16052. var scope = head(parentBlocks).getOr(root)
  16053. return fromPosition(forward, scope.dom, pos).filter(isBr)
  16054. }
  16055. var isBeforeBr$1 = function (root, pos) {
  16056. return (
  16057. getElementFromPosition(pos).exists(isBr$4) ||
  16058. findBr(true, root, pos).isSome()
  16059. )
  16060. }
  16061. var isAfterBr = function (root, pos) {
  16062. return (
  16063. getElementFromPrevPosition(pos).exists(isBr$4) ||
  16064. findBr(false, root, pos).isSome()
  16065. )
  16066. }
  16067. var findPreviousBr = curry(findBr, false)
  16068. var findNextBr = curry(findBr, true)
  16069. var isInMiddleOfText = function (pos) {
  16070. return (
  16071. CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd()
  16072. )
  16073. }
  16074. var getClosestBlock = function (root, pos) {
  16075. var parentBlocks = filter$4(
  16076. parentsAndSelf(SugarElement.fromDom(pos.container()), root),
  16077. isBlock$2
  16078. )
  16079. return head(parentBlocks).getOr(root)
  16080. }
  16081. var hasSpaceBefore = function (root, pos) {
  16082. if (isInMiddleOfText(pos)) {
  16083. return isAfterSpace(pos)
  16084. } else {
  16085. return (
  16086. isAfterSpace(pos) ||
  16087. prevPosition(getClosestBlock(root, pos).dom, pos).exists(isAfterSpace)
  16088. )
  16089. }
  16090. }
  16091. var hasSpaceAfter = function (root, pos) {
  16092. if (isInMiddleOfText(pos)) {
  16093. return isBeforeSpace(pos)
  16094. } else {
  16095. return (
  16096. isBeforeSpace(pos) ||
  16097. nextPosition(getClosestBlock(root, pos).dom, pos).exists(isBeforeSpace)
  16098. )
  16099. }
  16100. }
  16101. var isPreValue = function (value) {
  16102. return contains$3(['pre', 'pre-wrap'], value)
  16103. }
  16104. var isInPre = function (pos) {
  16105. return getElementFromPosition(pos)
  16106. .bind(function (elm) {
  16107. return closest$3(elm, isElement$6)
  16108. })
  16109. .exists(function (elm) {
  16110. return isPreValue(get$5(elm, 'white-space'))
  16111. })
  16112. }
  16113. var isAtBeginningOfBody = function (root, pos) {
  16114. return prevPosition(root.dom, pos).isNone()
  16115. }
  16116. var isAtEndOfBody = function (root, pos) {
  16117. return nextPosition(root.dom, pos).isNone()
  16118. }
  16119. var isAtLineBoundary = function (root, pos) {
  16120. return (
  16121. isAtBeginningOfBody(root, pos) ||
  16122. isAtEndOfBody(root, pos) ||
  16123. isAtStartOfBlock(root, pos) ||
  16124. isAtEndOfBlock(root, pos) ||
  16125. isAfterBr(root, pos) ||
  16126. isBeforeBr$1(root, pos)
  16127. )
  16128. }
  16129. var needsToHaveNbsp = function (root, pos) {
  16130. if (isInPre(pos)) {
  16131. return false
  16132. } else {
  16133. return (
  16134. isAtLineBoundary(root, pos) ||
  16135. hasSpaceBefore(root, pos) ||
  16136. hasSpaceAfter(root, pos)
  16137. )
  16138. }
  16139. }
  16140. var needsToBeNbspLeft = function (root, pos) {
  16141. if (isInPre(pos)) {
  16142. return false
  16143. } else {
  16144. return (
  16145. isAtStartOfBlock(root, pos) ||
  16146. isBeforeBlock(root, pos) ||
  16147. isAfterBr(root, pos) ||
  16148. hasSpaceBefore(root, pos)
  16149. )
  16150. }
  16151. }
  16152. var leanRight = function (pos) {
  16153. var container = pos.container()
  16154. var offset = pos.offset()
  16155. if (isText$7(container) && offset < container.data.length) {
  16156. return CaretPosition(container, offset + 1)
  16157. } else {
  16158. return pos
  16159. }
  16160. }
  16161. var needsToBeNbspRight = function (root, pos) {
  16162. if (isInPre(pos)) {
  16163. return false
  16164. } else {
  16165. return (
  16166. isAtEndOfBlock(root, pos) ||
  16167. isAfterBlock(root, pos) ||
  16168. isBeforeBr$1(root, pos) ||
  16169. hasSpaceAfter(root, pos)
  16170. )
  16171. }
  16172. }
  16173. var needsToBeNbsp = function (root, pos) {
  16174. return (
  16175. needsToBeNbspLeft(root, pos) || needsToBeNbspRight(root, leanRight(pos))
  16176. )
  16177. }
  16178. var isNbspAt = function (text, offset) {
  16179. return isNbsp(text.charAt(offset))
  16180. }
  16181. var hasNbsp = function (pos) {
  16182. var container = pos.container()
  16183. return isText$7(container) && contains$2(container.data, nbsp)
  16184. }
  16185. var normalizeNbspMiddle = function (text) {
  16186. var chars = text.split('')
  16187. return map$3(chars, function (chr, i) {
  16188. if (
  16189. isNbsp(chr) &&
  16190. i > 0 &&
  16191. i < chars.length - 1 &&
  16192. isContent(chars[i - 1]) &&
  16193. isContent(chars[i + 1])
  16194. ) {
  16195. return ' '
  16196. } else {
  16197. return chr
  16198. }
  16199. }).join('')
  16200. }
  16201. var normalizeNbspAtStart = function (root, node) {
  16202. var text = node.data
  16203. var firstPos = CaretPosition(node, 0)
  16204. if (isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos)) {
  16205. node.data = ' ' + text.slice(1)
  16206. return true
  16207. } else {
  16208. return false
  16209. }
  16210. }
  16211. var normalizeNbspInMiddleOfTextNode = function (node) {
  16212. var text = node.data
  16213. var newText = normalizeNbspMiddle(text)
  16214. if (newText !== text) {
  16215. node.data = newText
  16216. return true
  16217. } else {
  16218. return false
  16219. }
  16220. }
  16221. var normalizeNbspAtEnd = function (root, node) {
  16222. var text = node.data
  16223. var lastPos = CaretPosition(node, text.length - 1)
  16224. if (isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos)) {
  16225. node.data = text.slice(0, -1) + ' '
  16226. return true
  16227. } else {
  16228. return false
  16229. }
  16230. }
  16231. var normalizeNbsps = function (root, pos) {
  16232. return Optional.some(pos)
  16233. .filter(hasNbsp)
  16234. .bind(function (pos) {
  16235. var container = pos.container()
  16236. var normalized =
  16237. normalizeNbspAtStart(root, container) ||
  16238. normalizeNbspInMiddleOfTextNode(container) ||
  16239. normalizeNbspAtEnd(root, container)
  16240. return normalized ? Optional.some(pos) : Optional.none()
  16241. })
  16242. }
  16243. var normalizeNbspsInEditor = function (editor) {
  16244. var root = SugarElement.fromDom(editor.getBody())
  16245. if (editor.selection.isCollapsed()) {
  16246. normalizeNbsps(
  16247. root,
  16248. CaretPosition.fromRangeStart(editor.selection.getRng())
  16249. ).each(function (pos) {
  16250. editor.selection.setRng(pos.toRange())
  16251. })
  16252. }
  16253. }
  16254. var normalizeContent = function (content, isStartOfContent, isEndOfContent) {
  16255. var result = foldl(
  16256. content,
  16257. function (acc, c) {
  16258. if (isWhiteSpace(c) || isNbsp(c)) {
  16259. if (
  16260. acc.previousCharIsSpace ||
  16261. (acc.str === '' && isStartOfContent) ||
  16262. (acc.str.length === content.length - 1 && isEndOfContent)
  16263. ) {
  16264. return {
  16265. previousCharIsSpace: false,
  16266. str: acc.str + nbsp,
  16267. }
  16268. } else {
  16269. return {
  16270. previousCharIsSpace: true,
  16271. str: acc.str + ' ',
  16272. }
  16273. }
  16274. } else {
  16275. return {
  16276. previousCharIsSpace: false,
  16277. str: acc.str + c,
  16278. }
  16279. }
  16280. },
  16281. {
  16282. previousCharIsSpace: false,
  16283. str: '',
  16284. }
  16285. )
  16286. return result.str
  16287. }
  16288. var normalize$1 = function (node, offset, count) {
  16289. if (count === 0) {
  16290. return
  16291. }
  16292. var elm = SugarElement.fromDom(node)
  16293. var root = ancestor$3(elm, isBlock$2).getOr(elm)
  16294. var whitespace = node.data.slice(offset, offset + count)
  16295. var isEndOfContent =
  16296. offset + count >= node.data.length &&
  16297. needsToBeNbspRight(root, CaretPosition(node, node.data.length))
  16298. var isStartOfContent =
  16299. offset === 0 && needsToBeNbspLeft(root, CaretPosition(node, 0))
  16300. node.replaceData(
  16301. offset,
  16302. count,
  16303. normalizeContent(whitespace, isStartOfContent, isEndOfContent)
  16304. )
  16305. }
  16306. var normalizeWhitespaceAfter = function (node, offset) {
  16307. var content = node.data.slice(offset)
  16308. var whitespaceCount = content.length - lTrim(content).length
  16309. normalize$1(node, offset, whitespaceCount)
  16310. }
  16311. var normalizeWhitespaceBefore = function (node, offset) {
  16312. var content = node.data.slice(0, offset)
  16313. var whitespaceCount = content.length - rTrim(content).length
  16314. normalize$1(node, offset - whitespaceCount, whitespaceCount)
  16315. }
  16316. var mergeTextNodes = function (
  16317. prevNode,
  16318. nextNode,
  16319. normalizeWhitespace,
  16320. mergeToPrev
  16321. ) {
  16322. if (mergeToPrev === void 0) {
  16323. mergeToPrev = true
  16324. }
  16325. var whitespaceOffset = rTrim(prevNode.data).length
  16326. var newNode = mergeToPrev ? prevNode : nextNode
  16327. var removeNode = mergeToPrev ? nextNode : prevNode
  16328. if (mergeToPrev) {
  16329. newNode.appendData(removeNode.data)
  16330. } else {
  16331. newNode.insertData(0, removeNode.data)
  16332. }
  16333. remove$7(SugarElement.fromDom(removeNode))
  16334. if (normalizeWhitespace) {
  16335. normalizeWhitespaceAfter(newNode, whitespaceOffset)
  16336. }
  16337. return newNode
  16338. }
  16339. var needsReposition = function (pos, elm) {
  16340. var container = pos.container()
  16341. var offset = pos.offset()
  16342. return (
  16343. CaretPosition.isTextPosition(pos) === false &&
  16344. container === elm.parentNode &&
  16345. offset > CaretPosition.before(elm).offset()
  16346. )
  16347. }
  16348. var reposition = function (elm, pos) {
  16349. return needsReposition(pos, elm)
  16350. ? CaretPosition(pos.container(), pos.offset() - 1)
  16351. : pos
  16352. }
  16353. var beforeOrStartOf = function (node) {
  16354. return isText$7(node) ? CaretPosition(node, 0) : CaretPosition.before(node)
  16355. }
  16356. var afterOrEndOf = function (node) {
  16357. return isText$7(node)
  16358. ? CaretPosition(node, node.data.length)
  16359. : CaretPosition.after(node)
  16360. }
  16361. var getPreviousSiblingCaretPosition = function (elm) {
  16362. if (isCaretCandidate$3(elm.previousSibling)) {
  16363. return Optional.some(afterOrEndOf(elm.previousSibling))
  16364. } else {
  16365. return elm.previousSibling
  16366. ? lastPositionIn(elm.previousSibling)
  16367. : Optional.none()
  16368. }
  16369. }
  16370. var getNextSiblingCaretPosition = function (elm) {
  16371. if (isCaretCandidate$3(elm.nextSibling)) {
  16372. return Optional.some(beforeOrStartOf(elm.nextSibling))
  16373. } else {
  16374. return elm.nextSibling
  16375. ? firstPositionIn(elm.nextSibling)
  16376. : Optional.none()
  16377. }
  16378. }
  16379. var findCaretPositionBackwardsFromElm = function (rootElement, elm) {
  16380. var startPosition = CaretPosition.before(
  16381. elm.previousSibling ? elm.previousSibling : elm.parentNode
  16382. )
  16383. return prevPosition(rootElement, startPosition).fold(function () {
  16384. return nextPosition(rootElement, CaretPosition.after(elm))
  16385. }, Optional.some)
  16386. }
  16387. var findCaretPositionForwardsFromElm = function (rootElement, elm) {
  16388. return nextPosition(rootElement, CaretPosition.after(elm)).fold(
  16389. function () {
  16390. return prevPosition(rootElement, CaretPosition.before(elm))
  16391. },
  16392. Optional.some
  16393. )
  16394. }
  16395. var findCaretPositionBackwards = function (rootElement, elm) {
  16396. return getPreviousSiblingCaretPosition(elm)
  16397. .orThunk(function () {
  16398. return getNextSiblingCaretPosition(elm)
  16399. })
  16400. .orThunk(function () {
  16401. return findCaretPositionBackwardsFromElm(rootElement, elm)
  16402. })
  16403. }
  16404. var findCaretPositionForward = function (rootElement, elm) {
  16405. return getNextSiblingCaretPosition(elm)
  16406. .orThunk(function () {
  16407. return getPreviousSiblingCaretPosition(elm)
  16408. })
  16409. .orThunk(function () {
  16410. return findCaretPositionForwardsFromElm(rootElement, elm)
  16411. })
  16412. }
  16413. var findCaretPosition = function (forward, rootElement, elm) {
  16414. return forward
  16415. ? findCaretPositionForward(rootElement, elm)
  16416. : findCaretPositionBackwards(rootElement, elm)
  16417. }
  16418. var findCaretPosOutsideElmAfterDelete = function (forward, rootElement, elm) {
  16419. return findCaretPosition(forward, rootElement, elm).map(
  16420. curry(reposition, elm)
  16421. )
  16422. }
  16423. var setSelection$1 = function (editor, forward, pos) {
  16424. pos.fold(
  16425. function () {
  16426. editor.focus()
  16427. },
  16428. function (pos) {
  16429. editor.selection.setRng(pos.toRange(), forward)
  16430. }
  16431. )
  16432. }
  16433. var eqRawNode = function (rawNode) {
  16434. return function (elm) {
  16435. return elm.dom === rawNode
  16436. }
  16437. }
  16438. var isBlock = function (editor, elm) {
  16439. return elm && has$2(editor.schema.getBlockElements(), name(elm))
  16440. }
  16441. var paddEmptyBlock = function (elm) {
  16442. if (isEmpty$2(elm)) {
  16443. var br = SugarElement.fromHtml('<br data-mce-bogus="1">')
  16444. empty(elm)
  16445. append$1(elm, br)
  16446. return Optional.some(CaretPosition.before(br.dom))
  16447. } else {
  16448. return Optional.none()
  16449. }
  16450. }
  16451. var deleteNormalized = function (
  16452. elm,
  16453. afterDeletePosOpt,
  16454. normalizeWhitespace
  16455. ) {
  16456. var prevTextOpt = prevSibling(elm).filter(isText$8)
  16457. var nextTextOpt = nextSibling(elm).filter(isText$8)
  16458. remove$7(elm)
  16459. return lift3(
  16460. prevTextOpt,
  16461. nextTextOpt,
  16462. afterDeletePosOpt,
  16463. function (prev, next, pos) {
  16464. var prevNode = prev.dom,
  16465. nextNode = next.dom
  16466. var offset = prevNode.data.length
  16467. mergeTextNodes(prevNode, nextNode, normalizeWhitespace)
  16468. return pos.container() === nextNode
  16469. ? CaretPosition(prevNode, offset)
  16470. : pos
  16471. }
  16472. ).orThunk(function () {
  16473. if (normalizeWhitespace) {
  16474. prevTextOpt.each(function (elm) {
  16475. return normalizeWhitespaceBefore(elm.dom, elm.dom.length)
  16476. })
  16477. nextTextOpt.each(function (elm) {
  16478. return normalizeWhitespaceAfter(elm.dom, 0)
  16479. })
  16480. }
  16481. return afterDeletePosOpt
  16482. })
  16483. }
  16484. var isInlineElement = function (editor, element) {
  16485. return has$2(editor.schema.getTextInlineElements(), name(element))
  16486. }
  16487. var deleteElement$2 = function (editor, forward, elm, moveCaret) {
  16488. if (moveCaret === void 0) {
  16489. moveCaret = true
  16490. }
  16491. var afterDeletePos = findCaretPosOutsideElmAfterDelete(
  16492. forward,
  16493. editor.getBody(),
  16494. elm.dom
  16495. )
  16496. var parentBlock = ancestor$3(
  16497. elm,
  16498. curry(isBlock, editor),
  16499. eqRawNode(editor.getBody())
  16500. )
  16501. var normalizedAfterDeletePos = deleteNormalized(
  16502. elm,
  16503. afterDeletePos,
  16504. isInlineElement(editor, elm)
  16505. )
  16506. if (editor.dom.isEmpty(editor.getBody())) {
  16507. editor.setContent('')
  16508. editor.selection.setCursorLocation()
  16509. } else {
  16510. parentBlock.bind(paddEmptyBlock).fold(
  16511. function () {
  16512. if (moveCaret) {
  16513. setSelection$1(editor, forward, normalizedAfterDeletePos)
  16514. }
  16515. },
  16516. function (paddPos) {
  16517. if (moveCaret) {
  16518. setSelection$1(editor, forward, Optional.some(paddPos))
  16519. }
  16520. }
  16521. )
  16522. }
  16523. }
  16524. var isRootFromElement = function (root) {
  16525. return function (cur) {
  16526. return eq(root, cur)
  16527. }
  16528. }
  16529. var getTableCells = function (table) {
  16530. return descendants(table, 'td,th')
  16531. }
  16532. var getTableDetailsFromRange = function (rng, isRoot) {
  16533. var getTable = function (node) {
  16534. return getClosestTable(SugarElement.fromDom(node), isRoot)
  16535. }
  16536. var startTable = getTable(rng.startContainer)
  16537. var endTable = getTable(rng.endContainer)
  16538. var isStartInTable = startTable.isSome()
  16539. var isEndInTable = endTable.isSome()
  16540. var isSameTable = lift2(startTable, endTable, eq).getOr(false)
  16541. var isMultiTable = !isSameTable && isStartInTable && isEndInTable
  16542. return {
  16543. startTable: startTable,
  16544. endTable: endTable,
  16545. isStartInTable: isStartInTable,
  16546. isEndInTable: isEndInTable,
  16547. isSameTable: isSameTable,
  16548. isMultiTable: isMultiTable,
  16549. }
  16550. }
  16551. var tableCellRng = function (start, end) {
  16552. return {
  16553. start: start,
  16554. end: end,
  16555. }
  16556. }
  16557. var tableSelection = function (rng, table, cells) {
  16558. return {
  16559. rng: rng,
  16560. table: table,
  16561. cells: cells,
  16562. }
  16563. }
  16564. var deleteAction = Adt.generate([
  16565. {
  16566. singleCellTable: ['rng', 'cell'],
  16567. },
  16568. { fullTable: ['table'] },
  16569. {
  16570. partialTable: ['cells', 'outsideDetails'],
  16571. },
  16572. {
  16573. multiTable: ['startTableCells', 'endTableCells', 'betweenRng'],
  16574. },
  16575. ])
  16576. var getClosestCell$1 = function (container, isRoot) {
  16577. return closest$2(SugarElement.fromDom(container), 'td,th', isRoot)
  16578. }
  16579. var isExpandedCellRng = function (cellRng) {
  16580. return !eq(cellRng.start, cellRng.end)
  16581. }
  16582. var getTableFromCellRng = function (cellRng, isRoot) {
  16583. return getClosestTable(cellRng.start, isRoot).bind(function (
  16584. startParentTable
  16585. ) {
  16586. return getClosestTable(cellRng.end, isRoot).bind(function (
  16587. endParentTable
  16588. ) {
  16589. return someIf(eq(startParentTable, endParentTable), startParentTable)
  16590. })
  16591. })
  16592. }
  16593. var isSingleCellTable = function (cellRng, isRoot) {
  16594. return (
  16595. !isExpandedCellRng(cellRng) &&
  16596. getTableFromCellRng(cellRng, isRoot).exists(function (table) {
  16597. var rows = table.dom.rows
  16598. return rows.length === 1 && rows[0].cells.length === 1
  16599. })
  16600. )
  16601. }
  16602. var getCellRng = function (rng, isRoot) {
  16603. var startCell = getClosestCell$1(rng.startContainer, isRoot)
  16604. var endCell = getClosestCell$1(rng.endContainer, isRoot)
  16605. return lift2(startCell, endCell, tableCellRng)
  16606. }
  16607. var getCellRangeFromStartTable = function (isRoot) {
  16608. return function (startCell) {
  16609. return getClosestTable(startCell, isRoot).bind(function (table) {
  16610. return last$2(getTableCells(table)).map(function (endCell) {
  16611. return tableCellRng(startCell, endCell)
  16612. })
  16613. })
  16614. }
  16615. }
  16616. var getCellRangeFromEndTable = function (isRoot) {
  16617. return function (endCell) {
  16618. return getClosestTable(endCell, isRoot).bind(function (table) {
  16619. return head(getTableCells(table)).map(function (startCell) {
  16620. return tableCellRng(startCell, endCell)
  16621. })
  16622. })
  16623. }
  16624. }
  16625. var getTableSelectionFromCellRng = function (isRoot) {
  16626. return function (cellRng) {
  16627. return getTableFromCellRng(cellRng, isRoot).map(function (table) {
  16628. return tableSelection(cellRng, table, getTableCells(table))
  16629. })
  16630. }
  16631. }
  16632. var getTableSelections = function (cellRng, selectionDetails, rng, isRoot) {
  16633. if (rng.collapsed || !cellRng.forall(isExpandedCellRng)) {
  16634. return Optional.none()
  16635. } else if (selectionDetails.isSameTable) {
  16636. var sameTableSelection = cellRng.bind(
  16637. getTableSelectionFromCellRng(isRoot)
  16638. )
  16639. return Optional.some({
  16640. start: sameTableSelection,
  16641. end: sameTableSelection,
  16642. })
  16643. } else {
  16644. var startCell = getClosestCell$1(rng.startContainer, isRoot)
  16645. var endCell = getClosestCell$1(rng.endContainer, isRoot)
  16646. var startTableSelection = startCell
  16647. .bind(getCellRangeFromStartTable(isRoot))
  16648. .bind(getTableSelectionFromCellRng(isRoot))
  16649. var endTableSelection = endCell
  16650. .bind(getCellRangeFromEndTable(isRoot))
  16651. .bind(getTableSelectionFromCellRng(isRoot))
  16652. return Optional.some({
  16653. start: startTableSelection,
  16654. end: endTableSelection,
  16655. })
  16656. }
  16657. }
  16658. var getCellIndex = function (cells, cell) {
  16659. return findIndex$2(cells, function (x) {
  16660. return eq(x, cell)
  16661. })
  16662. }
  16663. var getSelectedCells = function (tableSelection) {
  16664. return lift2(
  16665. getCellIndex(tableSelection.cells, tableSelection.rng.start),
  16666. getCellIndex(tableSelection.cells, tableSelection.rng.end),
  16667. function (startIndex, endIndex) {
  16668. return tableSelection.cells.slice(startIndex, endIndex + 1)
  16669. }
  16670. )
  16671. }
  16672. var isSingleCellTableContentSelected = function (optCellRng, rng, isRoot) {
  16673. return optCellRng.exists(function (cellRng) {
  16674. return (
  16675. isSingleCellTable(cellRng, isRoot) &&
  16676. hasAllContentsSelected(cellRng.start, rng)
  16677. )
  16678. })
  16679. }
  16680. var unselectCells = function (rng, selectionDetails) {
  16681. var startTable = selectionDetails.startTable,
  16682. endTable = selectionDetails.endTable
  16683. var otherContentRng = rng.cloneRange()
  16684. startTable.each(function (table) {
  16685. return otherContentRng.setStartAfter(table.dom)
  16686. })
  16687. endTable.each(function (table) {
  16688. return otherContentRng.setEndBefore(table.dom)
  16689. })
  16690. return otherContentRng
  16691. }
  16692. var handleSingleTable = function (cellRng, selectionDetails, rng, isRoot) {
  16693. return getTableSelections(cellRng, selectionDetails, rng, isRoot)
  16694. .bind(function (_a) {
  16695. var start = _a.start,
  16696. end = _a.end
  16697. return start.or(end)
  16698. })
  16699. .bind(function (tableSelection) {
  16700. var isSameTable = selectionDetails.isSameTable
  16701. var selectedCells = getSelectedCells(tableSelection).getOr([])
  16702. if (
  16703. isSameTable &&
  16704. tableSelection.cells.length === selectedCells.length
  16705. ) {
  16706. return Optional.some(deleteAction.fullTable(tableSelection.table))
  16707. } else if (selectedCells.length > 0) {
  16708. if (isSameTable) {
  16709. return Optional.some(
  16710. deleteAction.partialTable(selectedCells, Optional.none())
  16711. )
  16712. } else {
  16713. var otherContentRng = unselectCells(rng, selectionDetails)
  16714. return Optional.some(
  16715. deleteAction.partialTable(
  16716. selectedCells,
  16717. Optional.some(
  16718. __assign(__assign({}, selectionDetails), {
  16719. rng: otherContentRng,
  16720. })
  16721. )
  16722. )
  16723. )
  16724. }
  16725. } else {
  16726. return Optional.none()
  16727. }
  16728. })
  16729. }
  16730. var handleMultiTable = function (cellRng, selectionDetails, rng, isRoot) {
  16731. return getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(
  16732. function (_a) {
  16733. var start = _a.start,
  16734. end = _a.end
  16735. var startTableSelectedCells = start.bind(getSelectedCells).getOr([])
  16736. var endTableSelectedCells = end.bind(getSelectedCells).getOr([])
  16737. if (
  16738. startTableSelectedCells.length > 0 &&
  16739. endTableSelectedCells.length > 0
  16740. ) {
  16741. var otherContentRng = unselectCells(rng, selectionDetails)
  16742. return Optional.some(
  16743. deleteAction.multiTable(
  16744. startTableSelectedCells,
  16745. endTableSelectedCells,
  16746. otherContentRng
  16747. )
  16748. )
  16749. } else {
  16750. return Optional.none()
  16751. }
  16752. }
  16753. )
  16754. }
  16755. var getActionFromRange = function (root, rng) {
  16756. var isRoot = isRootFromElement(root)
  16757. var optCellRng = getCellRng(rng, isRoot)
  16758. var selectionDetails = getTableDetailsFromRange(rng, isRoot)
  16759. if (isSingleCellTableContentSelected(optCellRng, rng, isRoot)) {
  16760. return optCellRng.map(function (cellRng) {
  16761. return deleteAction.singleCellTable(rng, cellRng.start)
  16762. })
  16763. } else if (selectionDetails.isMultiTable) {
  16764. return handleMultiTable(optCellRng, selectionDetails, rng, isRoot)
  16765. } else {
  16766. return handleSingleTable(optCellRng, selectionDetails, rng, isRoot)
  16767. }
  16768. }
  16769. var freefallRtl = function (root) {
  16770. var child = isComment$1(root) ? prevSibling(root) : lastChild(root)
  16771. return child.bind(freefallRtl).orThunk(function () {
  16772. return Optional.some(root)
  16773. })
  16774. }
  16775. var cleanCells = function (cells) {
  16776. return each$k(cells, function (cell) {
  16777. remove$6(cell, 'contenteditable')
  16778. fillWithPaddingBr(cell)
  16779. })
  16780. }
  16781. var getOutsideBlock = function (editor, container) {
  16782. return Optional.from(
  16783. editor.dom.getParent(container, editor.dom.isBlock)
  16784. ).map(SugarElement.fromDom)
  16785. }
  16786. var handleEmptyBlock = function (editor, startInTable, emptyBlock) {
  16787. emptyBlock.each(function (block) {
  16788. if (startInTable) {
  16789. remove$7(block)
  16790. } else {
  16791. fillWithPaddingBr(block)
  16792. editor.selection.setCursorLocation(block.dom, 0)
  16793. }
  16794. })
  16795. }
  16796. var deleteContentInsideCell = function (
  16797. editor,
  16798. cell,
  16799. rng,
  16800. isFirstCellInSelection
  16801. ) {
  16802. var insideTableRng = rng.cloneRange()
  16803. if (isFirstCellInSelection) {
  16804. insideTableRng.setStart(rng.startContainer, rng.startOffset)
  16805. insideTableRng.setEndAfter(cell.dom.lastChild)
  16806. } else {
  16807. insideTableRng.setStartBefore(cell.dom.firstChild)
  16808. insideTableRng.setEnd(rng.endContainer, rng.endOffset)
  16809. }
  16810. deleteCellContents(editor, insideTableRng, cell, false)
  16811. }
  16812. var collapseAndRestoreCellSelection = function (editor) {
  16813. var selectedCells = getCellsFromEditor(editor)
  16814. var selectedNode = SugarElement.fromDom(editor.selection.getNode())
  16815. if (isTableCell$5(selectedNode.dom) && isEmpty$2(selectedNode)) {
  16816. editor.selection.setCursorLocation(selectedNode.dom, 0)
  16817. } else {
  16818. editor.selection.collapse(true)
  16819. }
  16820. if (
  16821. selectedCells.length > 1 &&
  16822. exists(selectedCells, function (cell) {
  16823. return eq(cell, selectedNode)
  16824. })
  16825. ) {
  16826. set$1(selectedNode, 'data-mce-selected', '1')
  16827. }
  16828. }
  16829. var emptySingleTableCells = function (editor, cells, outsideDetails) {
  16830. var editorRng = editor.selection.getRng()
  16831. var cellsToClean = outsideDetails
  16832. .bind(function (_a) {
  16833. var rng = _a.rng,
  16834. isStartInTable = _a.isStartInTable
  16835. var outsideBlock = getOutsideBlock(
  16836. editor,
  16837. isStartInTable ? rng.endContainer : rng.startContainer
  16838. )
  16839. rng.deleteContents()
  16840. handleEmptyBlock(editor, isStartInTable, outsideBlock.filter(isEmpty$2))
  16841. var endPointCell = isStartInTable ? cells[0] : cells[cells.length - 1]
  16842. deleteContentInsideCell(editor, endPointCell, editorRng, isStartInTable)
  16843. if (!isEmpty$2(endPointCell)) {
  16844. return Optional.some(
  16845. isStartInTable ? cells.slice(1) : cells.slice(0, -1)
  16846. )
  16847. } else {
  16848. return Optional.none()
  16849. }
  16850. })
  16851. .getOr(cells)
  16852. cleanCells(cellsToClean)
  16853. collapseAndRestoreCellSelection(editor)
  16854. return true
  16855. }
  16856. var emptyMultiTableCells = function (
  16857. editor,
  16858. startTableCells,
  16859. endTableCells,
  16860. betweenRng
  16861. ) {
  16862. var rng = editor.selection.getRng()
  16863. var startCell = startTableCells[0]
  16864. var endCell = endTableCells[endTableCells.length - 1]
  16865. deleteContentInsideCell(editor, startCell, rng, true)
  16866. deleteContentInsideCell(editor, endCell, rng, false)
  16867. var startTableCellsToClean = isEmpty$2(startCell)
  16868. ? startTableCells
  16869. : startTableCells.slice(1)
  16870. var endTableCellsToClean = isEmpty$2(endCell)
  16871. ? endTableCells
  16872. : endTableCells.slice(0, -1)
  16873. cleanCells(startTableCellsToClean.concat(endTableCellsToClean))
  16874. betweenRng.deleteContents()
  16875. collapseAndRestoreCellSelection(editor)
  16876. return true
  16877. }
  16878. var deleteCellContents = function (editor, rng, cell, moveSelection) {
  16879. if (moveSelection === void 0) {
  16880. moveSelection = true
  16881. }
  16882. rng.deleteContents()
  16883. var lastNode = freefallRtl(cell).getOr(cell)
  16884. var lastBlock = SugarElement.fromDom(
  16885. editor.dom.getParent(lastNode.dom, editor.dom.isBlock)
  16886. )
  16887. if (isEmpty$2(lastBlock)) {
  16888. fillWithPaddingBr(lastBlock)
  16889. if (moveSelection) {
  16890. editor.selection.setCursorLocation(lastBlock.dom, 0)
  16891. }
  16892. }
  16893. if (!eq(cell, lastBlock)) {
  16894. var additionalCleanupNodes = is$1(parent(lastBlock), cell)
  16895. ? []
  16896. : siblings(lastBlock)
  16897. each$k(additionalCleanupNodes.concat(children(cell)), function (node) {
  16898. if (
  16899. !eq(node, lastBlock) &&
  16900. !contains$1(node, lastBlock) &&
  16901. isEmpty$2(node)
  16902. ) {
  16903. remove$7(node)
  16904. }
  16905. })
  16906. }
  16907. return true
  16908. }
  16909. var deleteTableElement = function (editor, table) {
  16910. deleteElement$2(editor, false, table)
  16911. return true
  16912. }
  16913. var deleteCellRange = function (editor, rootElm, rng) {
  16914. return getActionFromRange(rootElm, rng).map(function (action) {
  16915. return action.fold(
  16916. curry(deleteCellContents, editor),
  16917. curry(deleteTableElement, editor),
  16918. curry(emptySingleTableCells, editor),
  16919. curry(emptyMultiTableCells, editor)
  16920. )
  16921. })
  16922. }
  16923. var deleteCaptionRange = function (editor, caption) {
  16924. return emptyElement(editor, caption)
  16925. }
  16926. var deleteTableRange = function (editor, rootElm, rng, startElm) {
  16927. return getParentCaption(rootElm, startElm)
  16928. .fold(
  16929. function () {
  16930. return deleteCellRange(editor, rootElm, rng)
  16931. },
  16932. function (caption) {
  16933. return deleteCaptionRange(editor, caption)
  16934. }
  16935. )
  16936. .getOr(false)
  16937. }
  16938. var deleteRange$2 = function (editor, startElm, selectedCells) {
  16939. var rootNode = SugarElement.fromDom(editor.getBody())
  16940. var rng = editor.selection.getRng()
  16941. return selectedCells.length !== 0
  16942. ? emptySingleTableCells(editor, selectedCells, Optional.none())
  16943. : deleteTableRange(editor, rootNode, rng, startElm)
  16944. }
  16945. var getParentCell = function (rootElm, elm) {
  16946. return find$3(parentsAndSelf(elm, rootElm), isTableCell$4)
  16947. }
  16948. var getParentCaption = function (rootElm, elm) {
  16949. return find$3(parentsAndSelf(elm, rootElm), isTag('caption'))
  16950. }
  16951. var deleteBetweenCells = function (editor, rootElm, forward, fromCell, from) {
  16952. return navigate(forward, editor.getBody(), from).bind(function (to) {
  16953. return getParentCell(rootElm, SugarElement.fromDom(to.getNode())).map(
  16954. function (toCell) {
  16955. return eq(toCell, fromCell) === false
  16956. }
  16957. )
  16958. })
  16959. }
  16960. var emptyElement = function (editor, elm) {
  16961. fillWithPaddingBr(elm)
  16962. editor.selection.setCursorLocation(elm.dom, 0)
  16963. return Optional.some(true)
  16964. }
  16965. var isDeleteOfLastCharPos = function (fromCaption, forward, from, to) {
  16966. return firstPositionIn(fromCaption.dom)
  16967. .bind(function (first) {
  16968. return lastPositionIn(fromCaption.dom).map(function (last) {
  16969. return forward
  16970. ? from.isEqual(first) && to.isEqual(last)
  16971. : from.isEqual(last) && to.isEqual(first)
  16972. })
  16973. })
  16974. .getOr(true)
  16975. }
  16976. var emptyCaretCaption = function (editor, elm) {
  16977. return emptyElement(editor, elm)
  16978. }
  16979. var validateCaretCaption = function (rootElm, fromCaption, to) {
  16980. return getParentCaption(rootElm, SugarElement.fromDom(to.getNode())).map(
  16981. function (toCaption) {
  16982. return eq(toCaption, fromCaption) === false
  16983. }
  16984. )
  16985. }
  16986. var deleteCaretInsideCaption = function (
  16987. editor,
  16988. rootElm,
  16989. forward,
  16990. fromCaption,
  16991. from
  16992. ) {
  16993. return navigate(forward, editor.getBody(), from)
  16994. .bind(function (to) {
  16995. return isDeleteOfLastCharPos(fromCaption, forward, from, to)
  16996. ? emptyCaretCaption(editor, fromCaption)
  16997. : validateCaretCaption(rootElm, fromCaption, to)
  16998. })
  16999. .or(Optional.some(true))
  17000. }
  17001. var deleteCaretCells = function (editor, forward, rootElm, startElm) {
  17002. var from = CaretPosition.fromRangeStart(editor.selection.getRng())
  17003. return getParentCell(rootElm, startElm)
  17004. .bind(function (fromCell) {
  17005. return isEmpty$2(fromCell)
  17006. ? emptyElement(editor, fromCell)
  17007. : deleteBetweenCells(editor, rootElm, forward, fromCell, from)
  17008. })
  17009. .getOr(false)
  17010. }
  17011. var deleteCaretCaption = function (editor, forward, rootElm, fromCaption) {
  17012. var from = CaretPosition.fromRangeStart(editor.selection.getRng())
  17013. return isEmpty$2(fromCaption)
  17014. ? emptyElement(editor, fromCaption)
  17015. : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from)
  17016. }
  17017. var isNearTable = function (forward, pos) {
  17018. return forward ? isBeforeTable(pos) : isAfterTable(pos)
  17019. }
  17020. var isBeforeOrAfterTable = function (editor, forward) {
  17021. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng())
  17022. return (
  17023. isNearTable(forward, fromPos) ||
  17024. fromPosition(forward, editor.getBody(), fromPos).exists(function (pos) {
  17025. return isNearTable(forward, pos)
  17026. })
  17027. )
  17028. }
  17029. var deleteCaret$3 = function (editor, forward, startElm) {
  17030. var rootElm = SugarElement.fromDom(editor.getBody())
  17031. return getParentCaption(rootElm, startElm).fold(
  17032. function () {
  17033. return (
  17034. deleteCaretCells(editor, forward, rootElm, startElm) ||
  17035. isBeforeOrAfterTable(editor, forward)
  17036. )
  17037. },
  17038. function (fromCaption) {
  17039. return deleteCaretCaption(editor, forward, rootElm, fromCaption).getOr(
  17040. false
  17041. )
  17042. }
  17043. )
  17044. }
  17045. var backspaceDelete$9 = function (editor, forward) {
  17046. var startElm = SugarElement.fromDom(editor.selection.getStart(true))
  17047. var cells = getCellsFromEditor(editor)
  17048. return editor.selection.isCollapsed() && cells.length === 0
  17049. ? deleteCaret$3(editor, forward, startElm)
  17050. : deleteRange$2(editor, startElm, cells)
  17051. }
  17052. var createRange = function (sc, so, ec, eo) {
  17053. var rng = document.createRange()
  17054. rng.setStart(sc, so)
  17055. rng.setEnd(ec, eo)
  17056. return rng
  17057. }
  17058. var normalizeBlockSelectionRange = function (rng) {
  17059. var startPos = CaretPosition.fromRangeStart(rng)
  17060. var endPos = CaretPosition.fromRangeEnd(rng)
  17061. var rootNode = rng.commonAncestorContainer
  17062. return fromPosition(false, rootNode, endPos)
  17063. .map(function (newEndPos) {
  17064. if (
  17065. !isInSameBlock(startPos, endPos, rootNode) &&
  17066. isInSameBlock(startPos, newEndPos, rootNode)
  17067. ) {
  17068. return createRange(
  17069. startPos.container(),
  17070. startPos.offset(),
  17071. newEndPos.container(),
  17072. newEndPos.offset()
  17073. )
  17074. } else {
  17075. return rng
  17076. }
  17077. })
  17078. .getOr(rng)
  17079. }
  17080. var normalize = function (rng) {
  17081. return rng.collapsed ? rng : normalizeBlockSelectionRange(rng)
  17082. }
  17083. var hasOnlyOneChild$1 = function (node) {
  17084. return node.firstChild && node.firstChild === node.lastChild
  17085. }
  17086. var isPaddingNode = function (node) {
  17087. return node.name === 'br' || node.value === nbsp
  17088. }
  17089. var isPaddedEmptyBlock = function (schema, node) {
  17090. var blockElements = schema.getBlockElements()
  17091. return (
  17092. blockElements[node.name] &&
  17093. hasOnlyOneChild$1(node) &&
  17094. isPaddingNode(node.firstChild)
  17095. )
  17096. }
  17097. var isEmptyFragmentElement = function (schema, node) {
  17098. var nonEmptyElements = schema.getNonEmptyElements()
  17099. return (
  17100. node &&
  17101. (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node))
  17102. )
  17103. }
  17104. var isListFragment = function (schema, fragment) {
  17105. var firstChild = fragment.firstChild
  17106. var lastChild = fragment.lastChild
  17107. if (firstChild && firstChild.name === 'meta') {
  17108. firstChild = firstChild.next
  17109. }
  17110. if (lastChild && lastChild.attr('id') === 'mce_marker') {
  17111. lastChild = lastChild.prev
  17112. }
  17113. if (isEmptyFragmentElement(schema, lastChild)) {
  17114. lastChild = lastChild.prev
  17115. }
  17116. if (!firstChild || firstChild !== lastChild) {
  17117. return false
  17118. }
  17119. return firstChild.name === 'ul' || firstChild.name === 'ol'
  17120. }
  17121. var cleanupDomFragment = function (domFragment) {
  17122. var firstChild = domFragment.firstChild
  17123. var lastChild = domFragment.lastChild
  17124. if (firstChild && firstChild.nodeName === 'META') {
  17125. firstChild.parentNode.removeChild(firstChild)
  17126. }
  17127. if (lastChild && lastChild.id === 'mce_marker') {
  17128. lastChild.parentNode.removeChild(lastChild)
  17129. }
  17130. return domFragment
  17131. }
  17132. var toDomFragment = function (dom, serializer, fragment) {
  17133. var html = serializer.serialize(fragment)
  17134. var domFragment = dom.createFragment(html)
  17135. return cleanupDomFragment(domFragment)
  17136. }
  17137. var listItems = function (elm) {
  17138. return filter$4(elm.childNodes, function (child) {
  17139. return child.nodeName === 'LI'
  17140. })
  17141. }
  17142. var isPadding = function (node) {
  17143. return node.data === nbsp || isBr$5(node)
  17144. }
  17145. var isListItemPadded = function (node) {
  17146. return (
  17147. node &&
  17148. node.firstChild &&
  17149. node.firstChild === node.lastChild &&
  17150. isPadding(node.firstChild)
  17151. )
  17152. }
  17153. var isEmptyOrPadded = function (elm) {
  17154. return !elm.firstChild || isListItemPadded(elm)
  17155. }
  17156. var trimListItems = function (elms) {
  17157. return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1])
  17158. ? elms.slice(0, -1)
  17159. : elms
  17160. }
  17161. var getParentLi = function (dom, node) {
  17162. var parentBlock = dom.getParent(node, dom.isBlock)
  17163. return parentBlock && parentBlock.nodeName === 'LI' ? parentBlock : null
  17164. }
  17165. var isParentBlockLi = function (dom, node) {
  17166. return !!getParentLi(dom, node)
  17167. }
  17168. var getSplit = function (parentNode, rng) {
  17169. var beforeRng = rng.cloneRange()
  17170. var afterRng = rng.cloneRange()
  17171. beforeRng.setStartBefore(parentNode)
  17172. afterRng.setEndAfter(parentNode)
  17173. return [beforeRng.cloneContents(), afterRng.cloneContents()]
  17174. }
  17175. var findFirstIn = function (node, rootNode) {
  17176. var caretPos = CaretPosition.before(node)
  17177. var caretWalker = CaretWalker(rootNode)
  17178. var newCaretPos = caretWalker.next(caretPos)
  17179. return newCaretPos ? newCaretPos.toRange() : null
  17180. }
  17181. var findLastOf = function (node, rootNode) {
  17182. var caretPos = CaretPosition.after(node)
  17183. var caretWalker = CaretWalker(rootNode)
  17184. var newCaretPos = caretWalker.prev(caretPos)
  17185. return newCaretPos ? newCaretPos.toRange() : null
  17186. }
  17187. var insertMiddle = function (target, elms, rootNode, rng) {
  17188. var parts = getSplit(target, rng)
  17189. var parentElm = target.parentNode
  17190. parentElm.insertBefore(parts[0], target)
  17191. Tools.each(elms, function (li) {
  17192. parentElm.insertBefore(li, target)
  17193. })
  17194. parentElm.insertBefore(parts[1], target)
  17195. parentElm.removeChild(target)
  17196. return findLastOf(elms[elms.length - 1], rootNode)
  17197. }
  17198. var insertBefore$1 = function (target, elms, rootNode) {
  17199. var parentElm = target.parentNode
  17200. Tools.each(elms, function (elm) {
  17201. parentElm.insertBefore(elm, target)
  17202. })
  17203. return findFirstIn(target, rootNode)
  17204. }
  17205. var insertAfter$1 = function (target, elms, rootNode, dom) {
  17206. dom.insertAfter(elms.reverse(), target)
  17207. return findLastOf(elms[0], rootNode)
  17208. }
  17209. var insertAtCaret$1 = function (serializer, dom, rng, fragment) {
  17210. var domFragment = toDomFragment(dom, serializer, fragment)
  17211. var liTarget = getParentLi(dom, rng.startContainer)
  17212. var liElms = trimListItems(listItems(domFragment.firstChild))
  17213. var BEGINNING = 1,
  17214. END = 2
  17215. var rootNode = dom.getRoot()
  17216. var isAt = function (location) {
  17217. var caretPos = CaretPosition.fromRangeStart(rng)
  17218. var caretWalker = CaretWalker(dom.getRoot())
  17219. var newPos =
  17220. location === BEGINNING
  17221. ? caretWalker.prev(caretPos)
  17222. : caretWalker.next(caretPos)
  17223. return newPos ? getParentLi(dom, newPos.getNode()) !== liTarget : true
  17224. }
  17225. if (isAt(BEGINNING)) {
  17226. return insertBefore$1(liTarget, liElms, rootNode)
  17227. } else if (isAt(END)) {
  17228. return insertAfter$1(liTarget, liElms, rootNode, dom)
  17229. }
  17230. return insertMiddle(liTarget, liElms, rootNode, rng)
  17231. }
  17232. var trimOrPadLeftRight = function (dom, rng, html) {
  17233. var root = SugarElement.fromDom(dom.getRoot())
  17234. if (needsToBeNbspLeft(root, CaretPosition.fromRangeStart(rng))) {
  17235. html = html.replace(/^ /, '&nbsp;')
  17236. } else {
  17237. html = html.replace(/^&nbsp;/, ' ')
  17238. }
  17239. if (needsToBeNbspRight(root, CaretPosition.fromRangeEnd(rng))) {
  17240. html = html.replace(/(&nbsp;| )(<br( \/)>)?$/, '&nbsp;')
  17241. } else {
  17242. html = html.replace(/&nbsp;(<br( \/)?>)?$/, ' ')
  17243. }
  17244. return html
  17245. }
  17246. var isTableCell$1 = isTableCell$5
  17247. var isTableCellContentSelected = function (dom, rng, cell) {
  17248. if (cell !== null) {
  17249. var endCell = dom.getParent(rng.endContainer, isTableCell$1)
  17250. return (
  17251. cell === endCell &&
  17252. hasAllContentsSelected(SugarElement.fromDom(cell), rng)
  17253. )
  17254. } else {
  17255. return false
  17256. }
  17257. }
  17258. var validInsertion = function (editor, value, parentNode) {
  17259. if (parentNode.getAttribute('data-mce-bogus') === 'all') {
  17260. parentNode.parentNode.insertBefore(
  17261. editor.dom.createFragment(value),
  17262. parentNode
  17263. )
  17264. } else {
  17265. var node = parentNode.firstChild
  17266. var node2 = parentNode.lastChild
  17267. if (!node || (node === node2 && node.nodeName === 'BR')) {
  17268. editor.dom.setHTML(parentNode, value)
  17269. } else {
  17270. editor.selection.setContent(value)
  17271. }
  17272. }
  17273. }
  17274. var trimBrsFromTableCell = function (dom, elm) {
  17275. Optional.from(dom.getParent(elm, 'td,th'))
  17276. .map(SugarElement.fromDom)
  17277. .each(trimBlockTrailingBr)
  17278. }
  17279. var reduceInlineTextElements = function (editor, merge) {
  17280. var textInlineElements = editor.schema.getTextInlineElements()
  17281. var dom = editor.dom
  17282. if (merge) {
  17283. var root_1 = editor.getBody()
  17284. var elementUtils_1 = ElementUtils(dom)
  17285. Tools.each(dom.select('*[data-mce-fragment]'), function (node) {
  17286. var isInline = isNonNullable(
  17287. textInlineElements[node.nodeName.toLowerCase()]
  17288. )
  17289. if (isInline && hasInheritableStyles(dom, node)) {
  17290. for (
  17291. var parentNode = node.parentNode;
  17292. isNonNullable(parentNode) && parentNode !== root_1;
  17293. parentNode = parentNode.parentNode
  17294. ) {
  17295. var styleConflict = hasStyleConflict(dom, node, parentNode)
  17296. if (styleConflict) {
  17297. break
  17298. }
  17299. if (elementUtils_1.compare(parentNode, node)) {
  17300. dom.remove(node, true)
  17301. break
  17302. }
  17303. }
  17304. }
  17305. })
  17306. }
  17307. }
  17308. var markFragmentElements = function (fragment) {
  17309. var node = fragment
  17310. while ((node = node.walk())) {
  17311. if (node.type === 1) {
  17312. node.attr('data-mce-fragment', '1')
  17313. }
  17314. }
  17315. }
  17316. var unmarkFragmentElements = function (elm) {
  17317. Tools.each(elm.getElementsByTagName('*'), function (elm) {
  17318. elm.removeAttribute('data-mce-fragment')
  17319. })
  17320. }
  17321. var isPartOfFragment = function (node) {
  17322. return !!node.getAttribute('data-mce-fragment')
  17323. }
  17324. var canHaveChildren = function (editor, node) {
  17325. return node && !editor.schema.getShortEndedElements()[node.nodeName]
  17326. }
  17327. var moveSelectionToMarker = function (editor, marker) {
  17328. var nextRng
  17329. var dom = editor.dom
  17330. var selection = editor.selection
  17331. if (!marker) {
  17332. return
  17333. }
  17334. selection.scrollIntoView(marker)
  17335. var parentEditableElm = getContentEditableRoot$1(editor.getBody(), marker)
  17336. if (dom.getContentEditable(parentEditableElm) === 'false') {
  17337. dom.remove(marker)
  17338. selection.select(parentEditableElm)
  17339. return
  17340. }
  17341. var rng = dom.createRng()
  17342. var node = marker.previousSibling
  17343. if (isText$7(node)) {
  17344. rng.setStart(node, node.nodeValue.length)
  17345. if (!Env.ie) {
  17346. var node2 = marker.nextSibling
  17347. if (isText$7(node2)) {
  17348. node.appendData(node2.data)
  17349. node2.parentNode.removeChild(node2)
  17350. }
  17351. }
  17352. } else {
  17353. rng.setStartBefore(marker)
  17354. rng.setEndBefore(marker)
  17355. }
  17356. var findNextCaretRng = function (rng) {
  17357. var caretPos = CaretPosition.fromRangeStart(rng)
  17358. var caretWalker = CaretWalker(editor.getBody())
  17359. caretPos = caretWalker.next(caretPos)
  17360. if (caretPos) {
  17361. return caretPos.toRange()
  17362. }
  17363. }
  17364. var parentBlock = dom.getParent(marker, dom.isBlock)
  17365. dom.remove(marker)
  17366. if (parentBlock && dom.isEmpty(parentBlock)) {
  17367. editor.$(parentBlock).empty()
  17368. rng.setStart(parentBlock, 0)
  17369. rng.setEnd(parentBlock, 0)
  17370. if (
  17371. !isTableCell$1(parentBlock) &&
  17372. !isPartOfFragment(parentBlock) &&
  17373. (nextRng = findNextCaretRng(rng))
  17374. ) {
  17375. rng = nextRng
  17376. dom.remove(parentBlock)
  17377. } else {
  17378. dom.add(parentBlock, dom.create('br', { 'data-mce-bogus': '1' }))
  17379. }
  17380. }
  17381. selection.setRng(rng)
  17382. }
  17383. var deleteSelectedContent = function (editor) {
  17384. var dom = editor.dom
  17385. var rng = normalize(editor.selection.getRng())
  17386. editor.selection.setRng(rng)
  17387. var startCell = dom.getParent(rng.startContainer, isTableCell$1)
  17388. if (isTableCellContentSelected(dom, rng, startCell)) {
  17389. deleteCellContents(editor, rng, SugarElement.fromDom(startCell))
  17390. } else {
  17391. editor.getDoc().execCommand('Delete', false, null)
  17392. }
  17393. }
  17394. var insertHtmlAtCaret = function (editor, value, details) {
  17395. var parentNode
  17396. var rng, node
  17397. var selection = editor.selection
  17398. var dom = editor.dom
  17399. if (/^ | $/.test(value)) {
  17400. value = trimOrPadLeftRight(dom, selection.getRng(), value)
  17401. }
  17402. var parser = editor.parser
  17403. var merge = details.merge
  17404. var serializer = HtmlSerializer(
  17405. { validate: shouldValidate(editor) },
  17406. editor.schema
  17407. )
  17408. var bookmarkHtml =
  17409. '<span id="mce_marker" data-mce-type="bookmark">&#xFEFF;</span>'
  17410. var args = editor.fire('BeforeSetContent', {
  17411. content: value,
  17412. format: 'html',
  17413. selection: true,
  17414. paste: details.paste,
  17415. })
  17416. if (args.isDefaultPrevented()) {
  17417. editor.fire('SetContent', {
  17418. content: args.content,
  17419. format: 'html',
  17420. selection: true,
  17421. paste: details.paste,
  17422. })
  17423. return
  17424. }
  17425. value = args.content
  17426. if (value.indexOf('{$caret}') === -1) {
  17427. value += '{$caret}'
  17428. }
  17429. value = value.replace(/\{\$caret\}/, bookmarkHtml)
  17430. rng = selection.getRng()
  17431. var caretElement =
  17432. rng.startContainer || (rng.parentElement ? rng.parentElement() : null)
  17433. var body = editor.getBody()
  17434. if (caretElement === body && selection.isCollapsed()) {
  17435. if (
  17436. dom.isBlock(body.firstChild) &&
  17437. canHaveChildren(editor, body.firstChild) &&
  17438. dom.isEmpty(body.firstChild)
  17439. ) {
  17440. rng = dom.createRng()
  17441. rng.setStart(body.firstChild, 0)
  17442. rng.setEnd(body.firstChild, 0)
  17443. selection.setRng(rng)
  17444. }
  17445. }
  17446. if (!selection.isCollapsed()) {
  17447. deleteSelectedContent(editor)
  17448. }
  17449. parentNode = selection.getNode()
  17450. var parserArgs = {
  17451. context: parentNode.nodeName.toLowerCase(),
  17452. data: details.data,
  17453. insert: true,
  17454. }
  17455. var fragment = parser.parse(value, parserArgs)
  17456. if (
  17457. details.paste === true &&
  17458. isListFragment(editor.schema, fragment) &&
  17459. isParentBlockLi(dom, parentNode)
  17460. ) {
  17461. rng = insertAtCaret$1(serializer, dom, selection.getRng(), fragment)
  17462. selection.setRng(rng)
  17463. editor.fire('SetContent', args)
  17464. return
  17465. }
  17466. markFragmentElements(fragment)
  17467. node = fragment.lastChild
  17468. if (node.attr('id') === 'mce_marker') {
  17469. var marker = node
  17470. for (node = node.prev; node; node = node.walk(true)) {
  17471. if (node.type === 3 || !dom.isBlock(node.name)) {
  17472. if (editor.schema.isValidChild(node.parent.name, 'span')) {
  17473. node.parent.insert(marker, node, node.name === 'br')
  17474. }
  17475. break
  17476. }
  17477. }
  17478. }
  17479. editor._selectionOverrides.showBlockCaretContainer(parentNode)
  17480. if (!parserArgs.invalid) {
  17481. value = serializer.serialize(fragment)
  17482. validInsertion(editor, value, parentNode)
  17483. } else {
  17484. editor.selection.setContent(bookmarkHtml)
  17485. parentNode = selection.getNode()
  17486. var rootNode = editor.getBody()
  17487. if (parentNode.nodeType === 9) {
  17488. parentNode = node = rootNode
  17489. } else {
  17490. node = parentNode
  17491. }
  17492. while (node !== rootNode) {
  17493. parentNode = node
  17494. node = node.parentNode
  17495. }
  17496. value =
  17497. parentNode === rootNode
  17498. ? rootNode.innerHTML
  17499. : dom.getOuterHTML(parentNode)
  17500. value = serializer.serialize(
  17501. parser.parse(
  17502. value.replace(
  17503. /<span (id="mce_marker"|id=mce_marker).+?<\/span>/i,
  17504. function () {
  17505. return serializer.serialize(fragment)
  17506. }
  17507. )
  17508. )
  17509. )
  17510. if (parentNode === rootNode) {
  17511. dom.setHTML(rootNode, value)
  17512. } else {
  17513. dom.setOuterHTML(parentNode, value)
  17514. }
  17515. }
  17516. reduceInlineTextElements(editor, merge)
  17517. moveSelectionToMarker(editor, dom.get('mce_marker'))
  17518. unmarkFragmentElements(editor.getBody())
  17519. trimBrsFromTableCell(dom, selection.getStart())
  17520. editor.fire('SetContent', args)
  17521. editor.addVisual()
  17522. }
  17523. var traverse = function (node, fn) {
  17524. fn(node)
  17525. if (node.firstChild) {
  17526. traverse(node.firstChild, fn)
  17527. }
  17528. if (node.next) {
  17529. traverse(node.next, fn)
  17530. }
  17531. }
  17532. var findMatchingNodes = function (nodeFilters, attributeFilters, node) {
  17533. var nodeMatches = {}
  17534. var attrMatches = {}
  17535. var matches = []
  17536. if (node.firstChild) {
  17537. traverse(node.firstChild, function (node) {
  17538. each$k(nodeFilters, function (filter) {
  17539. if (filter.name === node.name) {
  17540. if (nodeMatches[filter.name]) {
  17541. nodeMatches[filter.name].nodes.push(node)
  17542. } else {
  17543. nodeMatches[filter.name] = {
  17544. filter: filter,
  17545. nodes: [node],
  17546. }
  17547. }
  17548. }
  17549. })
  17550. each$k(attributeFilters, function (filter) {
  17551. if (typeof node.attr(filter.name) === 'string') {
  17552. if (attrMatches[filter.name]) {
  17553. attrMatches[filter.name].nodes.push(node)
  17554. } else {
  17555. attrMatches[filter.name] = {
  17556. filter: filter,
  17557. nodes: [node],
  17558. }
  17559. }
  17560. }
  17561. })
  17562. })
  17563. }
  17564. for (var name_1 in nodeMatches) {
  17565. if (has$2(nodeMatches, name_1)) {
  17566. matches.push(nodeMatches[name_1])
  17567. }
  17568. }
  17569. for (var name_2 in attrMatches) {
  17570. if (has$2(attrMatches, name_2)) {
  17571. matches.push(attrMatches[name_2])
  17572. }
  17573. }
  17574. return matches
  17575. }
  17576. var filter$1 = function (nodeFilters, attributeFilters, node) {
  17577. var matches = findMatchingNodes(nodeFilters, attributeFilters, node)
  17578. each$k(matches, function (match) {
  17579. each$k(match.filter.callbacks, function (callback) {
  17580. callback(match.nodes, match.filter.name, {})
  17581. })
  17582. })
  17583. }
  17584. var defaultFormat$1 = 'html'
  17585. var isTreeNode = function (content) {
  17586. return content instanceof AstNode
  17587. }
  17588. var moveSelection = function (editor) {
  17589. if (hasFocus(editor)) {
  17590. firstPositionIn(editor.getBody()).each(function (pos) {
  17591. var node = pos.getNode()
  17592. var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos
  17593. editor.selection.setRng(caretPos.toRange())
  17594. })
  17595. }
  17596. }
  17597. var setEditorHtml = function (editor, html, noSelection) {
  17598. editor.dom.setHTML(editor.getBody(), html)
  17599. if (noSelection !== true) {
  17600. moveSelection(editor)
  17601. }
  17602. }
  17603. var setContentString = function (editor, body, content, args) {
  17604. if (content.length === 0 || /^\s+$/.test(content)) {
  17605. var padd = '<br data-mce-bogus="1">'
  17606. if (body.nodeName === 'TABLE') {
  17607. content = '<tr><td>' + padd + '</td></tr>'
  17608. } else if (/^(UL|OL)$/.test(body.nodeName)) {
  17609. content = '<li>' + padd + '</li>'
  17610. }
  17611. var forcedRootBlockName = getForcedRootBlock(editor)
  17612. if (
  17613. forcedRootBlockName &&
  17614. editor.schema.isValidChild(
  17615. body.nodeName.toLowerCase(),
  17616. forcedRootBlockName.toLowerCase()
  17617. )
  17618. ) {
  17619. content = padd
  17620. content = editor.dom.createHTML(
  17621. forcedRootBlockName,
  17622. getForcedRootBlockAttrs(editor),
  17623. content
  17624. )
  17625. } else if (!content) {
  17626. content = '<br data-mce-bogus="1">'
  17627. }
  17628. setEditorHtml(editor, content, args.no_selection)
  17629. editor.fire('SetContent', args)
  17630. } else {
  17631. if (args.format !== 'raw') {
  17632. content = HtmlSerializer(
  17633. { validate: editor.validate },
  17634. editor.schema
  17635. ).serialize(
  17636. editor.parser.parse(content, {
  17637. isRootContent: true,
  17638. insert: true,
  17639. })
  17640. )
  17641. }
  17642. args.content = isWsPreserveElement(SugarElement.fromDom(body))
  17643. ? content
  17644. : Tools.trim(content)
  17645. setEditorHtml(editor, args.content, args.no_selection)
  17646. if (!args.no_events) {
  17647. editor.fire('SetContent', args)
  17648. }
  17649. }
  17650. return args.content
  17651. }
  17652. var setContentTree = function (editor, body, content, args) {
  17653. filter$1(
  17654. editor.parser.getNodeFilters(),
  17655. editor.parser.getAttributeFilters(),
  17656. content
  17657. )
  17658. var html = HtmlSerializer(
  17659. { validate: editor.validate },
  17660. editor.schema
  17661. ).serialize(content)
  17662. args.content = isWsPreserveElement(SugarElement.fromDom(body))
  17663. ? html
  17664. : Tools.trim(html)
  17665. setEditorHtml(editor, args.content, args.no_selection)
  17666. if (!args.no_events) {
  17667. editor.fire('SetContent', args)
  17668. }
  17669. return content
  17670. }
  17671. var setupArgs$2 = function (args, content) {
  17672. return __assign(__assign({ format: defaultFormat$1 }, args), {
  17673. set: true,
  17674. content: isTreeNode(content) ? '' : content,
  17675. })
  17676. }
  17677. var setContentInternal = function (editor, content, args) {
  17678. var defaultedArgs = setupArgs$2(args, content)
  17679. var updatedArgs = args.no_events
  17680. ? defaultedArgs
  17681. : editor.fire('BeforeSetContent', defaultedArgs)
  17682. if (!isTreeNode(content)) {
  17683. content = updatedArgs.content
  17684. }
  17685. return Optional.from(editor.getBody()).fold(
  17686. constant(content),
  17687. function (body) {
  17688. return isTreeNode(content)
  17689. ? setContentTree(editor, body, content, updatedArgs)
  17690. : setContentString(editor, body, content, updatedArgs)
  17691. }
  17692. )
  17693. }
  17694. var sibling = function (scope, predicate) {
  17695. return sibling$2(scope, predicate).isSome()
  17696. }
  17697. var ensureIsRoot = function (isRoot) {
  17698. return isFunction(isRoot) ? isRoot : never
  17699. }
  17700. var ancestor = function (scope, transform, isRoot) {
  17701. var element = scope.dom
  17702. var stop = ensureIsRoot(isRoot)
  17703. while (element.parentNode) {
  17704. element = element.parentNode
  17705. var el = SugarElement.fromDom(element)
  17706. var transformed = transform(el)
  17707. if (transformed.isSome()) {
  17708. return transformed
  17709. } else if (stop(el)) {
  17710. break
  17711. }
  17712. }
  17713. return Optional.none()
  17714. }
  17715. var closest$1 = function (scope, transform, isRoot) {
  17716. var current = transform(scope)
  17717. var stop = ensureIsRoot(isRoot)
  17718. return current.orThunk(function () {
  17719. return stop(scope) ? Optional.none() : ancestor(scope, transform, stop)
  17720. })
  17721. }
  17722. var isEq$3 = isEq$5
  17723. var matchesUnInheritedFormatSelector = function (ed, node, name) {
  17724. var formatList = ed.formatter.get(name)
  17725. if (formatList) {
  17726. for (var i = 0; i < formatList.length; i++) {
  17727. var format = formatList[i]
  17728. if (
  17729. isSelectorFormat(format) &&
  17730. format.inherit === false &&
  17731. ed.dom.is(node, format.selector)
  17732. ) {
  17733. return true
  17734. }
  17735. }
  17736. }
  17737. return false
  17738. }
  17739. var matchParents = function (editor, node, name, vars, similar) {
  17740. var root = editor.dom.getRoot()
  17741. if (node === root) {
  17742. return false
  17743. }
  17744. node = editor.dom.getParent(node, function (node) {
  17745. if (matchesUnInheritedFormatSelector(editor, node, name)) {
  17746. return true
  17747. }
  17748. return (
  17749. node.parentNode === root || !!matchNode(editor, node, name, vars, true)
  17750. )
  17751. })
  17752. return !!matchNode(editor, node, name, vars, similar)
  17753. }
  17754. var matchName$1 = function (dom, node, format) {
  17755. if (isEq$3(node, format.inline)) {
  17756. return true
  17757. }
  17758. if (isEq$3(node, format.block)) {
  17759. return true
  17760. }
  17761. if (format.selector) {
  17762. return node.nodeType === 1 && dom.is(node, format.selector)
  17763. }
  17764. }
  17765. var matchItems = function (dom, node, format, itemName, similar, vars) {
  17766. var items = format[itemName]
  17767. if (isFunction(format.onmatch)) {
  17768. return format.onmatch(node, format, itemName)
  17769. }
  17770. if (items) {
  17771. if (isUndefined(items.length)) {
  17772. for (var key in items) {
  17773. if (has$2(items, key)) {
  17774. var value =
  17775. itemName === 'attributes'
  17776. ? dom.getAttrib(node, key)
  17777. : getStyle(dom, node, key)
  17778. var expectedValue = replaceVars(items[key], vars)
  17779. var isEmptyValue = isNullable(value) || isEmpty$3(value)
  17780. if (isEmptyValue && isNullable(expectedValue)) {
  17781. continue
  17782. }
  17783. if (similar && isEmptyValue && !format.exact) {
  17784. return false
  17785. }
  17786. if (
  17787. (!similar || format.exact) &&
  17788. !isEq$3(value, normalizeStyleValue(dom, expectedValue, key))
  17789. ) {
  17790. return false
  17791. }
  17792. }
  17793. }
  17794. } else {
  17795. for (var i = 0; i < items.length; i++) {
  17796. if (
  17797. itemName === 'attributes'
  17798. ? dom.getAttrib(node, items[i])
  17799. : getStyle(dom, node, items[i])
  17800. ) {
  17801. return true
  17802. }
  17803. }
  17804. }
  17805. }
  17806. return true
  17807. }
  17808. var matchNode = function (ed, node, name, vars, similar) {
  17809. var formatList = ed.formatter.get(name)
  17810. var dom = ed.dom
  17811. if (formatList && node) {
  17812. for (var i = 0; i < formatList.length; i++) {
  17813. var format = formatList[i]
  17814. if (
  17815. matchName$1(ed.dom, node, format) &&
  17816. matchItems(dom, node, format, 'attributes', similar, vars) &&
  17817. matchItems(dom, node, format, 'styles', similar, vars)
  17818. ) {
  17819. var classes = format.classes
  17820. if (classes) {
  17821. for (var x = 0; x < classes.length; x++) {
  17822. if (!ed.dom.hasClass(node, replaceVars(classes[x], vars))) {
  17823. return
  17824. }
  17825. }
  17826. }
  17827. return format
  17828. }
  17829. }
  17830. }
  17831. }
  17832. var match$2 = function (editor, name, vars, node, similar) {
  17833. if (node) {
  17834. return matchParents(editor, node, name, vars, similar)
  17835. }
  17836. node = editor.selection.getNode()
  17837. if (matchParents(editor, node, name, vars, similar)) {
  17838. return true
  17839. }
  17840. var startNode = editor.selection.getStart()
  17841. if (startNode !== node) {
  17842. if (matchParents(editor, startNode, name, vars, similar)) {
  17843. return true
  17844. }
  17845. }
  17846. return false
  17847. }
  17848. var matchAll = function (editor, names, vars) {
  17849. var matchedFormatNames = []
  17850. var checkedMap = {}
  17851. var startElement = editor.selection.getStart()
  17852. editor.dom.getParent(
  17853. startElement,
  17854. function (node) {
  17855. for (var i = 0; i < names.length; i++) {
  17856. var name_1 = names[i]
  17857. if (!checkedMap[name_1] && matchNode(editor, node, name_1, vars)) {
  17858. checkedMap[name_1] = true
  17859. matchedFormatNames.push(name_1)
  17860. }
  17861. }
  17862. },
  17863. editor.dom.getRoot()
  17864. )
  17865. return matchedFormatNames
  17866. }
  17867. var closest = function (editor, names) {
  17868. var isRoot = function (elm) {
  17869. return eq(elm, SugarElement.fromDom(editor.getBody()))
  17870. }
  17871. var match = function (elm, name) {
  17872. return matchNode(editor, elm.dom, name)
  17873. ? Optional.some(name)
  17874. : Optional.none()
  17875. }
  17876. return Optional.from(editor.selection.getStart(true))
  17877. .bind(function (rawElm) {
  17878. return closest$1(
  17879. SugarElement.fromDom(rawElm),
  17880. function (elm) {
  17881. return findMap(names, function (name) {
  17882. return match(elm, name)
  17883. })
  17884. },
  17885. isRoot
  17886. )
  17887. })
  17888. .getOrNull()
  17889. }
  17890. var canApply = function (editor, name) {
  17891. var formatList = editor.formatter.get(name)
  17892. var dom = editor.dom
  17893. if (formatList) {
  17894. var startNode = editor.selection.getStart()
  17895. var parents = getParents$2(dom, startNode)
  17896. for (var x = formatList.length - 1; x >= 0; x--) {
  17897. var format = formatList[x]
  17898. if (!isSelectorFormat(format) || isNonNullable(format.defaultBlock)) {
  17899. return true
  17900. }
  17901. for (var i = parents.length - 1; i >= 0; i--) {
  17902. if (dom.is(parents[i], format.selector)) {
  17903. return true
  17904. }
  17905. }
  17906. }
  17907. }
  17908. return false
  17909. }
  17910. var matchAllOnNode = function (editor, node, formatNames) {
  17911. return foldl(
  17912. formatNames,
  17913. function (acc, name) {
  17914. var matchSimilar = isVariableFormatName(editor, name)
  17915. if (editor.formatter.matchNode(node, name, {}, matchSimilar)) {
  17916. return acc.concat([name])
  17917. } else {
  17918. return acc
  17919. }
  17920. },
  17921. []
  17922. )
  17923. }
  17924. var ZWSP = ZWSP$1,
  17925. CARET_ID = '_mce_caret'
  17926. var importNode = function (ownerDocument, node) {
  17927. return ownerDocument.importNode(node, true)
  17928. }
  17929. var getEmptyCaretContainers = function (node) {
  17930. var nodes = []
  17931. while (node) {
  17932. if (
  17933. (node.nodeType === 3 && node.nodeValue !== ZWSP) ||
  17934. node.childNodes.length > 1
  17935. ) {
  17936. return []
  17937. }
  17938. if (node.nodeType === 1) {
  17939. nodes.push(node)
  17940. }
  17941. node = node.firstChild
  17942. }
  17943. return nodes
  17944. }
  17945. var isCaretContainerEmpty = function (node) {
  17946. return getEmptyCaretContainers(node).length > 0
  17947. }
  17948. var findFirstTextNode = function (node) {
  17949. if (node) {
  17950. var walker = new DomTreeWalker(node, node)
  17951. for (node = walker.current(); node; node = walker.next()) {
  17952. if (isText$7(node)) {
  17953. return node
  17954. }
  17955. }
  17956. }
  17957. return null
  17958. }
  17959. var createCaretContainer = function (fill) {
  17960. var caretContainer = SugarElement.fromTag('span')
  17961. setAll$1(caretContainer, {
  17962. id: CARET_ID,
  17963. 'data-mce-bogus': '1',
  17964. 'data-mce-type': 'format-caret',
  17965. })
  17966. if (fill) {
  17967. append$1(caretContainer, SugarElement.fromText(ZWSP))
  17968. }
  17969. return caretContainer
  17970. }
  17971. var trimZwspFromCaretContainer = function (caretContainerNode) {
  17972. var textNode = findFirstTextNode(caretContainerNode)
  17973. if (textNode && textNode.nodeValue.charAt(0) === ZWSP) {
  17974. textNode.deleteData(0, 1)
  17975. }
  17976. return textNode
  17977. }
  17978. var removeCaretContainerNode = function (editor, node, moveCaret) {
  17979. if (moveCaret === void 0) {
  17980. moveCaret = true
  17981. }
  17982. var dom = editor.dom,
  17983. selection = editor.selection
  17984. if (isCaretContainerEmpty(node)) {
  17985. deleteElement$2(editor, false, SugarElement.fromDom(node), moveCaret)
  17986. } else {
  17987. var rng = selection.getRng()
  17988. var block = dom.getParent(node, dom.isBlock)
  17989. var startContainer = rng.startContainer
  17990. var startOffset = rng.startOffset
  17991. var endContainer = rng.endContainer
  17992. var endOffset = rng.endOffset
  17993. var textNode = trimZwspFromCaretContainer(node)
  17994. dom.remove(node, true)
  17995. if (startContainer === textNode && startOffset > 0) {
  17996. rng.setStart(textNode, startOffset - 1)
  17997. }
  17998. if (endContainer === textNode && endOffset > 0) {
  17999. rng.setEnd(textNode, endOffset - 1)
  18000. }
  18001. if (block && dom.isEmpty(block)) {
  18002. fillWithPaddingBr(SugarElement.fromDom(block))
  18003. }
  18004. selection.setRng(rng)
  18005. }
  18006. }
  18007. var removeCaretContainer = function (editor, node, moveCaret) {
  18008. if (moveCaret === void 0) {
  18009. moveCaret = true
  18010. }
  18011. var dom = editor.dom,
  18012. selection = editor.selection
  18013. if (!node) {
  18014. node = getParentCaretContainer(editor.getBody(), selection.getStart())
  18015. if (!node) {
  18016. while ((node = dom.get(CARET_ID))) {
  18017. removeCaretContainerNode(editor, node, false)
  18018. }
  18019. }
  18020. } else {
  18021. removeCaretContainerNode(editor, node, moveCaret)
  18022. }
  18023. }
  18024. var insertCaretContainerNode = function (editor, caretContainer, formatNode) {
  18025. var dom = editor.dom,
  18026. block = dom.getParent(formatNode, curry(isTextBlock$1, editor))
  18027. if (block && dom.isEmpty(block)) {
  18028. formatNode.parentNode.replaceChild(caretContainer, formatNode)
  18029. } else {
  18030. removeTrailingBr(SugarElement.fromDom(formatNode))
  18031. if (dom.isEmpty(formatNode)) {
  18032. formatNode.parentNode.replaceChild(caretContainer, formatNode)
  18033. } else {
  18034. dom.insertAfter(caretContainer, formatNode)
  18035. }
  18036. }
  18037. }
  18038. var appendNode = function (parentNode, node) {
  18039. parentNode.appendChild(node)
  18040. return node
  18041. }
  18042. var insertFormatNodesIntoCaretContainer = function (
  18043. formatNodes,
  18044. caretContainer
  18045. ) {
  18046. var innerMostFormatNode = foldr(
  18047. formatNodes,
  18048. function (parentNode, formatNode) {
  18049. return appendNode(parentNode, formatNode.cloneNode(false))
  18050. },
  18051. caretContainer
  18052. )
  18053. return appendNode(
  18054. innerMostFormatNode,
  18055. innerMostFormatNode.ownerDocument.createTextNode(ZWSP)
  18056. )
  18057. }
  18058. var cleanFormatNode = function (
  18059. editor,
  18060. caretContainer,
  18061. formatNode,
  18062. name,
  18063. vars,
  18064. similar
  18065. ) {
  18066. var formatter = editor.formatter
  18067. var dom = editor.dom
  18068. var validFormats = filter$4(keys(formatter.get()), function (formatName) {
  18069. return formatName !== name && !contains$2(formatName, 'removeformat')
  18070. })
  18071. var matchedFormats = matchAllOnNode(editor, formatNode, validFormats)
  18072. var uniqueFormats = filter$4(matchedFormats, function (fmtName) {
  18073. return !areSimilarFormats(editor, fmtName, name)
  18074. })
  18075. if (uniqueFormats.length > 0) {
  18076. var clonedFormatNode = formatNode.cloneNode(false)
  18077. dom.add(caretContainer, clonedFormatNode)
  18078. formatter.remove(name, vars, clonedFormatNode, similar)
  18079. dom.remove(clonedFormatNode)
  18080. return Optional.some(clonedFormatNode)
  18081. } else {
  18082. return Optional.none()
  18083. }
  18084. }
  18085. var applyCaretFormat = function (editor, name, vars) {
  18086. var caretContainer, textNode
  18087. var selection = editor.selection
  18088. var selectionRng = selection.getRng()
  18089. var offset = selectionRng.startOffset
  18090. var container = selectionRng.startContainer
  18091. var text = container.nodeValue
  18092. caretContainer = getParentCaretContainer(
  18093. editor.getBody(),
  18094. selection.getStart()
  18095. )
  18096. if (caretContainer) {
  18097. textNode = findFirstTextNode(caretContainer)
  18098. }
  18099. var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/
  18100. if (
  18101. text &&
  18102. offset > 0 &&
  18103. offset < text.length &&
  18104. wordcharRegex.test(text.charAt(offset)) &&
  18105. wordcharRegex.test(text.charAt(offset - 1))
  18106. ) {
  18107. var bookmark = selection.getBookmark()
  18108. selectionRng.collapse(true)
  18109. var rng = expandRng(editor, selectionRng, editor.formatter.get(name))
  18110. rng = split(rng)
  18111. editor.formatter.apply(name, vars, rng)
  18112. selection.moveToBookmark(bookmark)
  18113. } else {
  18114. if (!caretContainer || textNode.nodeValue !== ZWSP) {
  18115. caretContainer = importNode(
  18116. editor.getDoc(),
  18117. createCaretContainer(true).dom
  18118. )
  18119. textNode = caretContainer.firstChild
  18120. selectionRng.insertNode(caretContainer)
  18121. offset = 1
  18122. editor.formatter.apply(name, vars, caretContainer)
  18123. } else {
  18124. editor.formatter.apply(name, vars, caretContainer)
  18125. }
  18126. selection.setCursorLocation(textNode, offset)
  18127. }
  18128. }
  18129. var removeCaretFormat = function (editor, name, vars, similar) {
  18130. var dom = editor.dom
  18131. var selection = editor.selection
  18132. var hasContentAfter, node, formatNode
  18133. var parents = []
  18134. var rng = selection.getRng()
  18135. var container = rng.startContainer
  18136. var offset = rng.startOffset
  18137. node = container
  18138. if (container.nodeType === 3) {
  18139. if (offset !== container.nodeValue.length) {
  18140. hasContentAfter = true
  18141. }
  18142. node = node.parentNode
  18143. }
  18144. while (node) {
  18145. if (matchNode(editor, node, name, vars, similar)) {
  18146. formatNode = node
  18147. break
  18148. }
  18149. if (node.nextSibling) {
  18150. hasContentAfter = true
  18151. }
  18152. parents.push(node)
  18153. node = node.parentNode
  18154. }
  18155. if (!formatNode) {
  18156. return
  18157. }
  18158. if (hasContentAfter) {
  18159. var bookmark = selection.getBookmark()
  18160. rng.collapse(true)
  18161. var expandedRng = expandRng(editor, rng, editor.formatter.get(name), true)
  18162. expandedRng = split(expandedRng)
  18163. editor.formatter.remove(name, vars, expandedRng, similar)
  18164. selection.moveToBookmark(bookmark)
  18165. } else {
  18166. var caretContainer = getParentCaretContainer(editor.getBody(), formatNode)
  18167. var newCaretContainer = createCaretContainer(false).dom
  18168. insertCaretContainerNode(
  18169. editor,
  18170. newCaretContainer,
  18171. caretContainer !== null ? caretContainer : formatNode
  18172. )
  18173. var cleanedFormatNode = cleanFormatNode(
  18174. editor,
  18175. newCaretContainer,
  18176. formatNode,
  18177. name,
  18178. vars,
  18179. similar
  18180. )
  18181. var caretTextNode = insertFormatNodesIntoCaretContainer(
  18182. parents.concat(cleanedFormatNode.toArray()),
  18183. newCaretContainer
  18184. )
  18185. removeCaretContainerNode(editor, caretContainer, false)
  18186. selection.setCursorLocation(caretTextNode, 1)
  18187. if (dom.isEmpty(formatNode)) {
  18188. dom.remove(formatNode)
  18189. }
  18190. }
  18191. }
  18192. var disableCaretContainer = function (editor, keyCode) {
  18193. var selection = editor.selection,
  18194. body = editor.getBody()
  18195. removeCaretContainer(editor, null, false)
  18196. if (
  18197. (keyCode === 8 || keyCode === 46) &&
  18198. selection.isCollapsed() &&
  18199. selection.getStart().innerHTML === ZWSP
  18200. ) {
  18201. removeCaretContainer(
  18202. editor,
  18203. getParentCaretContainer(body, selection.getStart())
  18204. )
  18205. }
  18206. if (keyCode === 37 || keyCode === 39) {
  18207. removeCaretContainer(
  18208. editor,
  18209. getParentCaretContainer(body, selection.getStart())
  18210. )
  18211. }
  18212. }
  18213. var setup$k = function (editor) {
  18214. editor.on('mouseup keydown', function (e) {
  18215. disableCaretContainer(editor, e.keyCode)
  18216. })
  18217. }
  18218. var replaceWithCaretFormat = function (targetNode, formatNodes) {
  18219. var caretContainer = createCaretContainer(false)
  18220. var innerMost = insertFormatNodesIntoCaretContainer(
  18221. formatNodes,
  18222. caretContainer.dom
  18223. )
  18224. before$4(SugarElement.fromDom(targetNode), caretContainer)
  18225. remove$7(SugarElement.fromDom(targetNode))
  18226. return CaretPosition(innerMost, 0)
  18227. }
  18228. var isFormatElement = function (editor, element) {
  18229. var inlineElements = editor.schema.getTextInlineElements()
  18230. return (
  18231. has$2(inlineElements, name(element)) &&
  18232. !isCaretNode(element.dom) &&
  18233. !isBogus$2(element.dom)
  18234. )
  18235. }
  18236. var isEmptyCaretFormatElement = function (element) {
  18237. return isCaretNode(element.dom) && isCaretContainerEmpty(element.dom)
  18238. }
  18239. var postProcessHooks = {}
  18240. var filter = filter$2
  18241. var each$b = each$i
  18242. var addPostProcessHook = function (name, hook) {
  18243. var hooks = postProcessHooks[name]
  18244. if (!hooks) {
  18245. postProcessHooks[name] = []
  18246. }
  18247. postProcessHooks[name].push(hook)
  18248. }
  18249. var postProcess$1 = function (name, editor) {
  18250. each$b(postProcessHooks[name], function (hook) {
  18251. hook(editor)
  18252. })
  18253. }
  18254. addPostProcessHook('pre', function (editor) {
  18255. var rng = editor.selection.getRng()
  18256. var blocks
  18257. var hasPreSibling = function (pre) {
  18258. return (
  18259. isPre(pre.previousSibling) &&
  18260. indexOf$1(blocks, pre.previousSibling) !== -1
  18261. )
  18262. }
  18263. var joinPre = function (pre1, pre2) {
  18264. DomQuery(pre2).remove()
  18265. DomQuery(pre1).append('<br><br>').append(pre2.childNodes)
  18266. }
  18267. var isPre = matchNodeNames(['pre'])
  18268. if (!rng.collapsed) {
  18269. blocks = editor.selection.getSelectedBlocks()
  18270. each$b(filter(filter(blocks, isPre), hasPreSibling), function (pre) {
  18271. joinPre(pre.previousSibling, pre)
  18272. })
  18273. }
  18274. })
  18275. var each$a = Tools.each
  18276. var isElementNode$1 = function (node) {
  18277. return (
  18278. isElement$5(node) &&
  18279. !isBookmarkNode$1(node) &&
  18280. !isCaretNode(node) &&
  18281. !isBogus$2(node)
  18282. )
  18283. }
  18284. var findElementSibling = function (node, siblingName) {
  18285. for (var sibling = node; sibling; sibling = sibling[siblingName]) {
  18286. if (isText$7(sibling) && isNotEmpty(sibling.data)) {
  18287. return node
  18288. }
  18289. if (isElement$5(sibling) && !isBookmarkNode$1(sibling)) {
  18290. return sibling
  18291. }
  18292. }
  18293. return node
  18294. }
  18295. var mergeSiblingsNodes = function (dom, prev, next) {
  18296. var elementUtils = ElementUtils(dom)
  18297. if (prev && next) {
  18298. prev = findElementSibling(prev, 'previousSibling')
  18299. next = findElementSibling(next, 'nextSibling')
  18300. if (elementUtils.compare(prev, next)) {
  18301. for (var sibling = prev.nextSibling; sibling && sibling !== next; ) {
  18302. var tmpSibling = sibling
  18303. sibling = sibling.nextSibling
  18304. prev.appendChild(tmpSibling)
  18305. }
  18306. dom.remove(next)
  18307. Tools.each(Tools.grep(next.childNodes), function (node) {
  18308. prev.appendChild(node)
  18309. })
  18310. return prev
  18311. }
  18312. }
  18313. return next
  18314. }
  18315. var mergeSiblings = function (dom, format, vars, node) {
  18316. if (node && format.merge_siblings !== false) {
  18317. var newNode = mergeSiblingsNodes(dom, getNonWhiteSpaceSibling(node), node)
  18318. mergeSiblingsNodes(dom, newNode, getNonWhiteSpaceSibling(newNode, true))
  18319. }
  18320. }
  18321. var clearChildStyles = function (dom, format, node) {
  18322. if (format.clear_child_styles) {
  18323. var selector = format.links ? '*:not(a)' : '*'
  18324. each$a(dom.select(selector, node), function (node) {
  18325. if (isElementNode$1(node)) {
  18326. each$a(format.styles, function (value, name) {
  18327. dom.setStyle(node, name, '')
  18328. })
  18329. }
  18330. })
  18331. }
  18332. }
  18333. var processChildElements = function (node, filter, process) {
  18334. each$a(node.childNodes, function (node) {
  18335. if (isElementNode$1(node)) {
  18336. if (filter(node)) {
  18337. process(node)
  18338. }
  18339. if (node.hasChildNodes()) {
  18340. processChildElements(node, filter, process)
  18341. }
  18342. }
  18343. })
  18344. }
  18345. var unwrapEmptySpan = function (dom, node) {
  18346. if (node.nodeName === 'SPAN' && dom.getAttribs(node).length === 0) {
  18347. dom.remove(node, true)
  18348. }
  18349. }
  18350. var hasStyle = function (dom, name) {
  18351. return function (node) {
  18352. return !!(node && getStyle(dom, node, name))
  18353. }
  18354. }
  18355. var applyStyle = function (dom, name, value) {
  18356. return function (node) {
  18357. dom.setStyle(node, name, value)
  18358. if (node.getAttribute('style') === '') {
  18359. node.removeAttribute('style')
  18360. }
  18361. unwrapEmptySpan(dom, node)
  18362. }
  18363. }
  18364. var removeResult = Adt.generate([
  18365. { keep: [] },
  18366. { rename: ['name'] },
  18367. { removed: [] },
  18368. ])
  18369. var MCE_ATTR_RE = /^(src|href|style)$/
  18370. var each$9 = Tools.each
  18371. var isEq$2 = isEq$5
  18372. var isTableCellOrRow = function (node) {
  18373. return /^(TR|TH|TD)$/.test(node.nodeName)
  18374. }
  18375. var isChildOfInlineParent = function (dom, node, parent) {
  18376. return (
  18377. dom.isChildOf(node, parent) && node !== parent && !dom.isBlock(parent)
  18378. )
  18379. }
  18380. var getContainer = function (ed, rng, start) {
  18381. var container = rng[start ? 'startContainer' : 'endContainer']
  18382. var offset = rng[start ? 'startOffset' : 'endOffset']
  18383. if (isElement$5(container)) {
  18384. var lastIdx = container.childNodes.length - 1
  18385. if (!start && offset) {
  18386. offset--
  18387. }
  18388. container = container.childNodes[offset > lastIdx ? lastIdx : offset]
  18389. }
  18390. if (isText$7(container) && start && offset >= container.nodeValue.length) {
  18391. container = new DomTreeWalker(container, ed.getBody()).next() || container
  18392. }
  18393. if (isText$7(container) && !start && offset === 0) {
  18394. container = new DomTreeWalker(container, ed.getBody()).prev() || container
  18395. }
  18396. return container
  18397. }
  18398. var normalizeTableSelection = function (node, start) {
  18399. var prop = start ? 'firstChild' : 'lastChild'
  18400. if (isTableCellOrRow(node) && node[prop]) {
  18401. var childNode = node[prop]
  18402. if (node.nodeName === 'TR') {
  18403. return childNode[prop] || childNode
  18404. } else {
  18405. return childNode
  18406. }
  18407. }
  18408. return node
  18409. }
  18410. var wrap$1 = function (dom, node, name, attrs) {
  18411. var wrapper = dom.create(name, attrs)
  18412. node.parentNode.insertBefore(wrapper, node)
  18413. wrapper.appendChild(node)
  18414. return wrapper
  18415. }
  18416. var wrapWithSiblings = function (dom, node, next, name, attrs) {
  18417. var start = SugarElement.fromDom(node)
  18418. var wrapper = SugarElement.fromDom(dom.create(name, attrs))
  18419. var siblings = next ? nextSiblings(start) : prevSiblings(start)
  18420. append(wrapper, siblings)
  18421. if (next) {
  18422. before$4(start, wrapper)
  18423. prepend(wrapper, start)
  18424. } else {
  18425. after$3(start, wrapper)
  18426. append$1(wrapper, start)
  18427. }
  18428. return wrapper.dom
  18429. }
  18430. var matchName = function (dom, node, format) {
  18431. if (isInlineFormat(format) && isEq$2(node, format.inline)) {
  18432. return true
  18433. }
  18434. if (isBlockFormat(format) && isEq$2(node, format.block)) {
  18435. return true
  18436. }
  18437. if (isSelectorFormat(format)) {
  18438. return isElement$5(node) && dom.is(node, format.selector)
  18439. }
  18440. }
  18441. var isColorFormatAndAnchor = function (node, format) {
  18442. return format.links && node.nodeName === 'A'
  18443. }
  18444. var find = function (dom, node, next, inc) {
  18445. var sibling = getNonWhiteSpaceSibling(node, next, inc)
  18446. return (
  18447. isNullable(sibling) || sibling.nodeName === 'BR' || dom.isBlock(sibling)
  18448. )
  18449. }
  18450. var removeNode = function (ed, node, format) {
  18451. var parentNode = node.parentNode
  18452. var rootBlockElm
  18453. var dom = ed.dom,
  18454. forcedRootBlock = getForcedRootBlock(ed)
  18455. if (isBlockFormat(format)) {
  18456. if (!forcedRootBlock) {
  18457. if (dom.isBlock(node) && !dom.isBlock(parentNode)) {
  18458. if (
  18459. !find(dom, node, false) &&
  18460. !find(dom, node.firstChild, true, true)
  18461. ) {
  18462. node.insertBefore(dom.create('br'), node.firstChild)
  18463. }
  18464. if (
  18465. !find(dom, node, true) &&
  18466. !find(dom, node.lastChild, false, true)
  18467. ) {
  18468. node.appendChild(dom.create('br'))
  18469. }
  18470. }
  18471. } else {
  18472. if (parentNode === dom.getRoot()) {
  18473. if (!format.list_block || !isEq$2(node, format.list_block)) {
  18474. each$k(from(node.childNodes), function (node) {
  18475. if (isValid(ed, forcedRootBlock, node.nodeName.toLowerCase())) {
  18476. if (!rootBlockElm) {
  18477. rootBlockElm = wrap$1(dom, node, forcedRootBlock)
  18478. dom.setAttribs(
  18479. rootBlockElm,
  18480. ed.settings.forced_root_block_attrs
  18481. )
  18482. } else {
  18483. rootBlockElm.appendChild(node)
  18484. }
  18485. } else {
  18486. rootBlockElm = null
  18487. }
  18488. })
  18489. }
  18490. }
  18491. }
  18492. }
  18493. if (isMixedFormat(format) && !isEq$2(format.inline, node)) {
  18494. return
  18495. }
  18496. dom.remove(node, true)
  18497. }
  18498. var removeFormatInternal = function (ed, format, vars, node, compareNode) {
  18499. var stylesModified
  18500. var dom = ed.dom
  18501. if (
  18502. !matchName(dom, node, format) &&
  18503. !isColorFormatAndAnchor(node, format)
  18504. ) {
  18505. return removeResult.keep()
  18506. }
  18507. var elm = node
  18508. if (
  18509. isInlineFormat(format) &&
  18510. format.remove === 'all' &&
  18511. isArray$1(format.preserve_attributes)
  18512. ) {
  18513. var attrsToPreserve = filter$4(dom.getAttribs(elm), function (attr) {
  18514. return contains$3(format.preserve_attributes, attr.name.toLowerCase())
  18515. })
  18516. dom.removeAllAttribs(elm)
  18517. each$k(attrsToPreserve, function (attr) {
  18518. return dom.setAttrib(elm, attr.name, attr.value)
  18519. })
  18520. if (attrsToPreserve.length > 0) {
  18521. return removeResult.rename('span')
  18522. }
  18523. }
  18524. if (format.remove !== 'all') {
  18525. each$9(format.styles, function (value, name) {
  18526. value = normalizeStyleValue(dom, replaceVars(value, vars), name + '')
  18527. if (isNumber(name)) {
  18528. name = value
  18529. compareNode = null
  18530. }
  18531. if (
  18532. format.remove_similar ||
  18533. !compareNode ||
  18534. isEq$2(getStyle(dom, compareNode, name), value)
  18535. ) {
  18536. dom.setStyle(elm, name, '')
  18537. }
  18538. stylesModified = true
  18539. })
  18540. if (stylesModified && dom.getAttrib(elm, 'style') === '') {
  18541. elm.removeAttribute('style')
  18542. elm.removeAttribute('data-mce-style')
  18543. }
  18544. each$9(format.attributes, function (value, name) {
  18545. var valueOut
  18546. value = replaceVars(value, vars)
  18547. if (isNumber(name)) {
  18548. name = value
  18549. compareNode = null
  18550. }
  18551. if (
  18552. format.remove_similar ||
  18553. !compareNode ||
  18554. isEq$2(dom.getAttrib(compareNode, name), value)
  18555. ) {
  18556. if (name === 'class') {
  18557. value = dom.getAttrib(elm, name)
  18558. if (value) {
  18559. valueOut = ''
  18560. each$k(value.split(/\s+/), function (cls) {
  18561. if (/mce\-\w+/.test(cls)) {
  18562. valueOut += (valueOut ? ' ' : '') + cls
  18563. }
  18564. })
  18565. if (valueOut) {
  18566. dom.setAttrib(elm, name, valueOut)
  18567. return
  18568. }
  18569. }
  18570. }
  18571. if (MCE_ATTR_RE.test(name)) {
  18572. elm.removeAttribute('data-mce-' + name)
  18573. }
  18574. if (
  18575. name === 'style' &&
  18576. matchNodeNames(['li'])(elm) &&
  18577. dom.getStyle(elm, 'list-style-type') === 'none'
  18578. ) {
  18579. elm.removeAttribute(name)
  18580. dom.setStyle(elm, 'list-style-type', 'none')
  18581. return
  18582. }
  18583. if (name === 'class') {
  18584. elm.removeAttribute('className')
  18585. }
  18586. elm.removeAttribute(name)
  18587. }
  18588. })
  18589. each$9(format.classes, function (value) {
  18590. value = replaceVars(value, vars)
  18591. if (!compareNode || dom.hasClass(compareNode, value)) {
  18592. dom.removeClass(elm, value)
  18593. }
  18594. })
  18595. var attrs = dom.getAttribs(elm)
  18596. for (var i = 0; i < attrs.length; i++) {
  18597. var attrName = attrs[i].nodeName
  18598. if (attrName.indexOf('_') !== 0 && attrName.indexOf('data-') !== 0) {
  18599. return removeResult.keep()
  18600. }
  18601. }
  18602. }
  18603. if (format.remove !== 'none') {
  18604. removeNode(ed, elm, format)
  18605. return removeResult.removed()
  18606. }
  18607. return removeResult.keep()
  18608. }
  18609. var removeFormat$1 = function (ed, format, vars, node, compareNode) {
  18610. return removeFormatInternal(ed, format, vars, node, compareNode).fold(
  18611. never,
  18612. function (newName) {
  18613. ed.dom.rename(node, newName)
  18614. return true
  18615. },
  18616. always
  18617. )
  18618. }
  18619. var findFormatRoot = function (editor, container, name, vars, similar) {
  18620. var formatRoot
  18621. each$k(
  18622. getParents$2(editor.dom, container.parentNode).reverse(),
  18623. function (parent) {
  18624. if (!formatRoot && parent.id !== '_start' && parent.id !== '_end') {
  18625. var format = matchNode(editor, parent, name, vars, similar)
  18626. if (format && format.split !== false) {
  18627. formatRoot = parent
  18628. }
  18629. }
  18630. }
  18631. )
  18632. return formatRoot
  18633. }
  18634. var removeFormatFromClone = function (editor, format, vars, clone) {
  18635. return removeFormatInternal(editor, format, vars, clone, clone).fold(
  18636. constant(clone),
  18637. function (newName) {
  18638. var fragment = editor.dom.createFragment()
  18639. fragment.appendChild(clone)
  18640. return editor.dom.rename(clone, newName)
  18641. },
  18642. constant(null)
  18643. )
  18644. }
  18645. var wrapAndSplit = function (
  18646. editor,
  18647. formatList,
  18648. formatRoot,
  18649. container,
  18650. target,
  18651. split,
  18652. format,
  18653. vars
  18654. ) {
  18655. var clone, lastClone, firstClone
  18656. var dom = editor.dom
  18657. if (formatRoot) {
  18658. var formatRootParent = formatRoot.parentNode
  18659. for (
  18660. var parent_1 = container.parentNode;
  18661. parent_1 && parent_1 !== formatRootParent;
  18662. parent_1 = parent_1.parentNode
  18663. ) {
  18664. clone = dom.clone(parent_1, false)
  18665. for (var i = 0; i < formatList.length; i++) {
  18666. clone = removeFormatFromClone(editor, formatList[i], vars, clone)
  18667. if (clone === null) {
  18668. break
  18669. }
  18670. }
  18671. if (clone) {
  18672. if (lastClone) {
  18673. clone.appendChild(lastClone)
  18674. }
  18675. if (!firstClone) {
  18676. firstClone = clone
  18677. }
  18678. lastClone = clone
  18679. }
  18680. }
  18681. if (split && (!format.mixed || !dom.isBlock(formatRoot))) {
  18682. container = dom.split(formatRoot, container)
  18683. }
  18684. if (lastClone) {
  18685. target.parentNode.insertBefore(lastClone, target)
  18686. firstClone.appendChild(target)
  18687. if (isInlineFormat(format)) {
  18688. mergeSiblings(dom, format, vars, lastClone)
  18689. }
  18690. }
  18691. }
  18692. return container
  18693. }
  18694. var remove$1 = function (ed, name, vars, node, similar) {
  18695. var formatList = ed.formatter.get(name)
  18696. var format = formatList[0]
  18697. var contentEditable = true
  18698. var dom = ed.dom
  18699. var selection = ed.selection
  18700. var splitToFormatRoot = function (container) {
  18701. var formatRoot = findFormatRoot(ed, container, name, vars, similar)
  18702. return wrapAndSplit(
  18703. ed,
  18704. formatList,
  18705. formatRoot,
  18706. container,
  18707. container,
  18708. true,
  18709. format,
  18710. vars
  18711. )
  18712. }
  18713. var isRemoveBookmarkNode = function (node) {
  18714. return (
  18715. isBookmarkNode$1(node) &&
  18716. isElement$5(node) &&
  18717. (node.id === '_start' || node.id === '_end')
  18718. )
  18719. }
  18720. var removeNodeFormat = function (node) {
  18721. return exists(formatList, function (fmt) {
  18722. return removeFormat$1(ed, fmt, vars, node, node)
  18723. })
  18724. }
  18725. var process = function (node) {
  18726. var lastContentEditable = true
  18727. var hasContentEditableState = false
  18728. if (isElement$5(node) && dom.getContentEditable(node)) {
  18729. lastContentEditable = contentEditable
  18730. contentEditable = dom.getContentEditable(node) === 'true'
  18731. hasContentEditableState = true
  18732. }
  18733. var children = from(node.childNodes)
  18734. if (contentEditable && !hasContentEditableState) {
  18735. var removed = removeNodeFormat(node)
  18736. var parentNode = node.parentNode
  18737. if (
  18738. !removed &&
  18739. isNonNullable(parentNode) &&
  18740. shouldExpandToSelector(format)
  18741. ) {
  18742. removeNodeFormat(parentNode)
  18743. }
  18744. }
  18745. if (format.deep) {
  18746. if (children.length) {
  18747. for (var i = 0; i < children.length; i++) {
  18748. process(children[i])
  18749. }
  18750. if (hasContentEditableState) {
  18751. contentEditable = lastContentEditable
  18752. }
  18753. }
  18754. }
  18755. var textDecorations = ['underline', 'line-through', 'overline']
  18756. each$k(textDecorations, function (decoration) {
  18757. if (
  18758. isElement$5(node) &&
  18759. ed.dom.getStyle(node, 'text-decoration') === decoration &&
  18760. node.parentNode &&
  18761. getTextDecoration(dom, node.parentNode) === decoration
  18762. ) {
  18763. removeFormat$1(
  18764. ed,
  18765. {
  18766. deep: false,
  18767. exact: true,
  18768. inline: 'span',
  18769. styles: { textDecoration: decoration },
  18770. },
  18771. null,
  18772. node
  18773. )
  18774. }
  18775. })
  18776. }
  18777. var unwrap = function (start) {
  18778. var node = dom.get(start ? '_start' : '_end')
  18779. var out = node[start ? 'firstChild' : 'lastChild']
  18780. if (isRemoveBookmarkNode(out)) {
  18781. out = out[start ? 'firstChild' : 'lastChild']
  18782. }
  18783. if (isText$7(out) && out.data.length === 0) {
  18784. out = start
  18785. ? node.previousSibling || node.nextSibling
  18786. : node.nextSibling || node.previousSibling
  18787. }
  18788. dom.remove(node, true)
  18789. return out
  18790. }
  18791. var removeRngStyle = function (rng) {
  18792. var startContainer, endContainer
  18793. var expandedRng = expandRng(ed, rng, formatList, rng.collapsed)
  18794. if (format.split) {
  18795. expandedRng = split(expandedRng)
  18796. startContainer = getContainer(ed, expandedRng, true)
  18797. endContainer = getContainer(ed, expandedRng)
  18798. if (startContainer !== endContainer) {
  18799. startContainer = normalizeTableSelection(startContainer, true)
  18800. endContainer = normalizeTableSelection(endContainer, false)
  18801. if (isChildOfInlineParent(dom, startContainer, endContainer)) {
  18802. var marker = Optional.from(startContainer.firstChild).getOr(
  18803. startContainer
  18804. )
  18805. splitToFormatRoot(
  18806. wrapWithSiblings(dom, marker, true, 'span', {
  18807. id: '_start',
  18808. 'data-mce-type': 'bookmark',
  18809. })
  18810. )
  18811. unwrap(true)
  18812. return
  18813. }
  18814. if (isChildOfInlineParent(dom, endContainer, startContainer)) {
  18815. var marker = Optional.from(endContainer.lastChild).getOr(
  18816. endContainer
  18817. )
  18818. splitToFormatRoot(
  18819. wrapWithSiblings(dom, marker, false, 'span', {
  18820. id: '_end',
  18821. 'data-mce-type': 'bookmark',
  18822. })
  18823. )
  18824. unwrap(false)
  18825. return
  18826. }
  18827. startContainer = wrap$1(dom, startContainer, 'span', {
  18828. id: '_start',
  18829. 'data-mce-type': 'bookmark',
  18830. })
  18831. endContainer = wrap$1(dom, endContainer, 'span', {
  18832. id: '_end',
  18833. 'data-mce-type': 'bookmark',
  18834. })
  18835. var newRng = dom.createRng()
  18836. newRng.setStartAfter(startContainer)
  18837. newRng.setEndBefore(endContainer)
  18838. walk$2(dom, newRng, function (nodes) {
  18839. each$k(nodes, function (n) {
  18840. if (!isBookmarkNode$1(n) && !isBookmarkNode$1(n.parentNode)) {
  18841. splitToFormatRoot(n)
  18842. }
  18843. })
  18844. })
  18845. splitToFormatRoot(startContainer)
  18846. splitToFormatRoot(endContainer)
  18847. startContainer = unwrap(true)
  18848. endContainer = unwrap()
  18849. } else {
  18850. startContainer = endContainer = splitToFormatRoot(startContainer)
  18851. }
  18852. expandedRng.startContainer = startContainer.parentNode
  18853. ? startContainer.parentNode
  18854. : startContainer
  18855. expandedRng.startOffset = dom.nodeIndex(startContainer)
  18856. expandedRng.endContainer = endContainer.parentNode
  18857. ? endContainer.parentNode
  18858. : endContainer
  18859. expandedRng.endOffset = dom.nodeIndex(endContainer) + 1
  18860. }
  18861. walk$2(dom, expandedRng, function (nodes) {
  18862. each$k(nodes, process)
  18863. })
  18864. }
  18865. if (node) {
  18866. if (isNode(node)) {
  18867. var rng = dom.createRng()
  18868. rng.setStartBefore(node)
  18869. rng.setEndAfter(node)
  18870. removeRngStyle(rng)
  18871. } else {
  18872. removeRngStyle(node)
  18873. }
  18874. fireFormatRemove(ed, name, node, vars)
  18875. return
  18876. }
  18877. if (dom.getContentEditable(selection.getNode()) === 'false') {
  18878. node = selection.getNode()
  18879. for (var i = 0; i < formatList.length; i++) {
  18880. if (formatList[i].ceFalseOverride) {
  18881. if (removeFormat$1(ed, formatList[i], vars, node, node)) {
  18882. break
  18883. }
  18884. }
  18885. }
  18886. fireFormatRemove(ed, name, node, vars)
  18887. return
  18888. }
  18889. if (
  18890. !selection.isCollapsed() ||
  18891. !isInlineFormat(format) ||
  18892. getCellsFromEditor(ed).length
  18893. ) {
  18894. preserve(selection, true, function () {
  18895. runOnRanges(ed, removeRngStyle)
  18896. })
  18897. if (
  18898. isInlineFormat(format) &&
  18899. match$2(ed, name, vars, selection.getStart())
  18900. ) {
  18901. moveStart(dom, selection, selection.getRng())
  18902. }
  18903. ed.nodeChanged()
  18904. } else {
  18905. removeCaretFormat(ed, name, vars, similar)
  18906. }
  18907. fireFormatRemove(ed, name, node, vars)
  18908. }
  18909. var each$8 = Tools.each
  18910. var mergeTextDecorationsAndColor = function (dom, format, vars, node) {
  18911. var processTextDecorationsAndColor = function (n) {
  18912. if (n.nodeType === 1 && n.parentNode && n.parentNode.nodeType === 1) {
  18913. var textDecoration = getTextDecoration(dom, n.parentNode)
  18914. if (dom.getStyle(n, 'color') && textDecoration) {
  18915. dom.setStyle(n, 'text-decoration', textDecoration)
  18916. } else if (dom.getStyle(n, 'text-decoration') === textDecoration) {
  18917. dom.setStyle(n, 'text-decoration', null)
  18918. }
  18919. }
  18920. }
  18921. if (
  18922. format.styles &&
  18923. (format.styles.color || format.styles.textDecoration)
  18924. ) {
  18925. Tools.walk(node, processTextDecorationsAndColor, 'childNodes')
  18926. processTextDecorationsAndColor(node)
  18927. }
  18928. }
  18929. var mergeBackgroundColorAndFontSize = function (dom, format, vars, node) {
  18930. if (format.styles && format.styles.backgroundColor) {
  18931. processChildElements(
  18932. node,
  18933. hasStyle(dom, 'fontSize'),
  18934. applyStyle(
  18935. dom,
  18936. 'backgroundColor',
  18937. replaceVars(format.styles.backgroundColor, vars)
  18938. )
  18939. )
  18940. }
  18941. }
  18942. var mergeSubSup = function (dom, format, vars, node) {
  18943. if (
  18944. isInlineFormat(format) &&
  18945. (format.inline === 'sub' || format.inline === 'sup')
  18946. ) {
  18947. processChildElements(
  18948. node,
  18949. hasStyle(dom, 'fontSize'),
  18950. applyStyle(dom, 'fontSize', '')
  18951. )
  18952. dom.remove(
  18953. dom.select(format.inline === 'sup' ? 'sub' : 'sup', node),
  18954. true
  18955. )
  18956. }
  18957. }
  18958. var mergeWithChildren = function (editor, formatList, vars, node) {
  18959. each$8(formatList, function (format) {
  18960. if (isInlineFormat(format)) {
  18961. each$8(editor.dom.select(format.inline, node), function (child) {
  18962. if (!isElementNode$1(child)) {
  18963. return
  18964. }
  18965. removeFormat$1(
  18966. editor,
  18967. format,
  18968. vars,
  18969. child,
  18970. format.exact ? child : null
  18971. )
  18972. })
  18973. }
  18974. clearChildStyles(editor.dom, format, node)
  18975. })
  18976. }
  18977. var mergeWithParents = function (editor, format, name, vars, node) {
  18978. if (matchNode(editor, node.parentNode, name, vars)) {
  18979. if (removeFormat$1(editor, format, vars, node)) {
  18980. return
  18981. }
  18982. }
  18983. if (format.merge_with_parents) {
  18984. editor.dom.getParent(node.parentNode, function (parent) {
  18985. if (matchNode(editor, parent, name, vars)) {
  18986. removeFormat$1(editor, format, vars, node)
  18987. return true
  18988. }
  18989. })
  18990. }
  18991. }
  18992. var each$7 = Tools.each
  18993. var isElementNode = function (node) {
  18994. return (
  18995. isElement$5(node) &&
  18996. !isBookmarkNode$1(node) &&
  18997. !isCaretNode(node) &&
  18998. !isBogus$2(node)
  18999. )
  19000. }
  19001. var canFormatBR = function (editor, format, node, parentName) {
  19002. if (canFormatEmptyLines(editor) && isInlineFormat(format)) {
  19003. var validBRParentElements = __assign(
  19004. __assign({}, editor.schema.getTextBlockElements()),
  19005. {
  19006. td: {},
  19007. th: {},
  19008. li: {},
  19009. dt: {},
  19010. dd: {},
  19011. figcaption: {},
  19012. caption: {},
  19013. details: {},
  19014. summary: {},
  19015. }
  19016. )
  19017. var hasCaretNodeSibling = sibling(
  19018. SugarElement.fromDom(node),
  19019. function (sibling) {
  19020. return isCaretNode(sibling.dom)
  19021. }
  19022. )
  19023. return (
  19024. hasNonNullableKey(validBRParentElements, parentName) &&
  19025. isEmpty$2(SugarElement.fromDom(node.parentNode), false) &&
  19026. !hasCaretNodeSibling
  19027. )
  19028. } else {
  19029. return false
  19030. }
  19031. }
  19032. var applyFormat$1 = function (ed, name, vars, node) {
  19033. var formatList = ed.formatter.get(name)
  19034. var format = formatList[0]
  19035. var isCollapsed = !node && ed.selection.isCollapsed()
  19036. var dom = ed.dom
  19037. var selection = ed.selection
  19038. var setElementFormat = function (elm, fmt) {
  19039. if (fmt === void 0) {
  19040. fmt = format
  19041. }
  19042. if (isFunction(fmt.onformat)) {
  19043. fmt.onformat(elm, fmt, vars, node)
  19044. }
  19045. each$7(fmt.styles, function (value, name) {
  19046. dom.setStyle(elm, name, replaceVars(value, vars))
  19047. })
  19048. if (fmt.styles) {
  19049. var styleVal = dom.getAttrib(elm, 'style')
  19050. if (styleVal) {
  19051. dom.setAttrib(elm, 'data-mce-style', styleVal)
  19052. }
  19053. }
  19054. each$7(fmt.attributes, function (value, name) {
  19055. dom.setAttrib(elm, name, replaceVars(value, vars))
  19056. })
  19057. each$7(fmt.classes, function (value) {
  19058. value = replaceVars(value, vars)
  19059. if (!dom.hasClass(elm, value)) {
  19060. dom.addClass(elm, value)
  19061. }
  19062. })
  19063. }
  19064. var applyNodeStyle = function (formatList, node) {
  19065. var found = false
  19066. each$7(formatList, function (format) {
  19067. if (!isSelectorFormat(format)) {
  19068. return false
  19069. }
  19070. if (
  19071. isNonNullable(format.collapsed) &&
  19072. format.collapsed !== isCollapsed
  19073. ) {
  19074. return
  19075. }
  19076. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  19077. setElementFormat(node, format)
  19078. found = true
  19079. return false
  19080. }
  19081. })
  19082. return found
  19083. }
  19084. var createWrapElement = function (wrapName) {
  19085. if (isString$1(wrapName)) {
  19086. var wrapElm = dom.create(wrapName)
  19087. setElementFormat(wrapElm)
  19088. return wrapElm
  19089. } else {
  19090. return null
  19091. }
  19092. }
  19093. var applyRngStyle = function (dom, rng, nodeSpecific) {
  19094. var newWrappers = []
  19095. var contentEditable = true
  19096. var wrapName = format.inline || format.block
  19097. var wrapElm = createWrapElement(wrapName)
  19098. walk$2(dom, rng, function (nodes) {
  19099. var currentWrapElm
  19100. var process = function (node) {
  19101. var hasContentEditableState = false
  19102. var lastContentEditable = contentEditable
  19103. var nodeName = node.nodeName.toLowerCase()
  19104. var parentNode = node.parentNode
  19105. var parentName = parentNode.nodeName.toLowerCase()
  19106. if (isElement$5(node) && dom.getContentEditable(node)) {
  19107. lastContentEditable = contentEditable
  19108. contentEditable = dom.getContentEditable(node) === 'true'
  19109. hasContentEditableState = true
  19110. }
  19111. if (isBr$5(node) && !canFormatBR(ed, format, node, parentName)) {
  19112. currentWrapElm = null
  19113. if (isBlockFormat(format)) {
  19114. dom.remove(node)
  19115. }
  19116. return
  19117. }
  19118. if (
  19119. isBlockFormat(format) &&
  19120. format.wrapper &&
  19121. matchNode(ed, node, name, vars)
  19122. ) {
  19123. currentWrapElm = null
  19124. return
  19125. }
  19126. if (
  19127. contentEditable &&
  19128. !hasContentEditableState &&
  19129. isBlockFormat(format) &&
  19130. !format.wrapper &&
  19131. isTextBlock$1(ed, nodeName) &&
  19132. isValid(ed, parentName, wrapName)
  19133. ) {
  19134. var elm = dom.rename(node, wrapName)
  19135. setElementFormat(elm)
  19136. newWrappers.push(elm)
  19137. currentWrapElm = null
  19138. return
  19139. }
  19140. if (isSelectorFormat(format)) {
  19141. var found = applyNodeStyle(formatList, node)
  19142. if (
  19143. !found &&
  19144. isNonNullable(parentNode) &&
  19145. shouldExpandToSelector(format)
  19146. ) {
  19147. found = applyNodeStyle(formatList, parentNode)
  19148. }
  19149. if (!isInlineFormat(format) || found) {
  19150. currentWrapElm = null
  19151. return
  19152. }
  19153. }
  19154. if (
  19155. contentEditable &&
  19156. !hasContentEditableState &&
  19157. isValid(ed, wrapName, nodeName) &&
  19158. isValid(ed, parentName, wrapName) &&
  19159. !(!nodeSpecific && isText$7(node) && isZwsp(node.data)) &&
  19160. !isCaretNode(node) &&
  19161. (!isInlineFormat(format) || !dom.isBlock(node))
  19162. ) {
  19163. if (!currentWrapElm) {
  19164. currentWrapElm = dom.clone(wrapElm, false)
  19165. node.parentNode.insertBefore(currentWrapElm, node)
  19166. newWrappers.push(currentWrapElm)
  19167. }
  19168. currentWrapElm.appendChild(node)
  19169. } else {
  19170. currentWrapElm = null
  19171. each$k(from(node.childNodes), process)
  19172. if (hasContentEditableState) {
  19173. contentEditable = lastContentEditable
  19174. }
  19175. currentWrapElm = null
  19176. }
  19177. }
  19178. each$k(nodes, process)
  19179. })
  19180. if (format.links === true) {
  19181. each$k(newWrappers, function (node) {
  19182. var process = function (node) {
  19183. if (node.nodeName === 'A') {
  19184. setElementFormat(node, format)
  19185. }
  19186. each$k(from(node.childNodes), process)
  19187. }
  19188. process(node)
  19189. })
  19190. }
  19191. each$k(newWrappers, function (node) {
  19192. var getChildCount = function (node) {
  19193. var count = 0
  19194. each$k(node.childNodes, function (node) {
  19195. if (!isEmptyTextNode$1(node) && !isBookmarkNode$1(node)) {
  19196. count++
  19197. }
  19198. })
  19199. return count
  19200. }
  19201. var mergeStyles = function (node) {
  19202. var childElement = find$3(node.childNodes, isElementNode).filter(
  19203. function (child) {
  19204. return matchName$1(dom, child, format)
  19205. }
  19206. )
  19207. return childElement
  19208. .map(function (child) {
  19209. var clone = dom.clone(child, false)
  19210. setElementFormat(clone)
  19211. dom.replace(clone, node, true)
  19212. dom.remove(child, true)
  19213. return clone
  19214. })
  19215. .getOr(node)
  19216. }
  19217. var childCount = getChildCount(node)
  19218. if (
  19219. (newWrappers.length > 1 || !dom.isBlock(node)) &&
  19220. childCount === 0
  19221. ) {
  19222. dom.remove(node, true)
  19223. return
  19224. }
  19225. if (
  19226. isInlineFormat(format) ||
  19227. (isBlockFormat(format) && format.wrapper)
  19228. ) {
  19229. if (!format.exact && childCount === 1) {
  19230. node = mergeStyles(node)
  19231. }
  19232. mergeWithChildren(ed, formatList, vars, node)
  19233. mergeWithParents(ed, format, name, vars, node)
  19234. mergeBackgroundColorAndFontSize(dom, format, vars, node)
  19235. mergeTextDecorationsAndColor(dom, format, vars, node)
  19236. mergeSubSup(dom, format, vars, node)
  19237. mergeSiblings(dom, format, vars, node)
  19238. }
  19239. })
  19240. }
  19241. if (dom.getContentEditable(selection.getNode()) === 'false') {
  19242. node = selection.getNode()
  19243. for (var i = 0, l = formatList.length; i < l; i++) {
  19244. var formatItem = formatList[i]
  19245. if (
  19246. formatItem.ceFalseOverride &&
  19247. isSelectorFormat(formatItem) &&
  19248. dom.is(node, formatItem.selector)
  19249. ) {
  19250. setElementFormat(node, formatItem)
  19251. break
  19252. }
  19253. }
  19254. fireFormatApply(ed, name, node, vars)
  19255. return
  19256. }
  19257. if (format) {
  19258. if (node) {
  19259. if (isNode(node)) {
  19260. if (!applyNodeStyle(formatList, node)) {
  19261. var rng = dom.createRng()
  19262. rng.setStartBefore(node)
  19263. rng.setEndAfter(node)
  19264. applyRngStyle(dom, expandRng(ed, rng, formatList), true)
  19265. }
  19266. } else {
  19267. applyRngStyle(dom, node, true)
  19268. }
  19269. } else {
  19270. if (
  19271. !isCollapsed ||
  19272. !isInlineFormat(format) ||
  19273. getCellsFromEditor(ed).length
  19274. ) {
  19275. var curSelNode = selection.getNode()
  19276. var firstFormat = formatList[0]
  19277. if (
  19278. !ed.settings.forced_root_block &&
  19279. firstFormat.defaultBlock &&
  19280. !dom.getParent(curSelNode, dom.isBlock)
  19281. ) {
  19282. applyFormat$1(ed, firstFormat.defaultBlock)
  19283. }
  19284. selection.setRng(normalize(selection.getRng()))
  19285. preserve(selection, true, function () {
  19286. runOnRanges(ed, function (selectionRng, fake) {
  19287. var expandedRng = fake
  19288. ? selectionRng
  19289. : expandRng(ed, selectionRng, formatList)
  19290. applyRngStyle(dom, expandedRng, false)
  19291. })
  19292. })
  19293. moveStart(dom, selection, selection.getRng())
  19294. ed.nodeChanged()
  19295. } else {
  19296. applyCaretFormat(ed, name, vars)
  19297. }
  19298. }
  19299. postProcess$1(name, ed)
  19300. }
  19301. fireFormatApply(ed, name, node, vars)
  19302. }
  19303. var hasVars = function (value) {
  19304. return has$2(value, 'vars')
  19305. }
  19306. var setup$j = function (registeredFormatListeners, editor) {
  19307. registeredFormatListeners.set({})
  19308. editor.on('NodeChange', function (e) {
  19309. updateAndFireChangeCallbacks(
  19310. editor,
  19311. e.element,
  19312. registeredFormatListeners.get()
  19313. )
  19314. })
  19315. editor.on('FormatApply FormatRemove', function (e) {
  19316. var element = Optional.from(e.node)
  19317. .map(function (nodeOrRange) {
  19318. return isNode(nodeOrRange) ? nodeOrRange : nodeOrRange.startContainer
  19319. })
  19320. .bind(function (node) {
  19321. return isElement$5(node)
  19322. ? Optional.some(node)
  19323. : Optional.from(node.parentElement)
  19324. })
  19325. .getOrThunk(function () {
  19326. return fallbackElement(editor)
  19327. })
  19328. updateAndFireChangeCallbacks(
  19329. editor,
  19330. element,
  19331. registeredFormatListeners.get()
  19332. )
  19333. })
  19334. }
  19335. var fallbackElement = function (editor) {
  19336. return editor.selection.getStart()
  19337. }
  19338. var matchingNode = function (editor, parents, format, similar, vars) {
  19339. var isMatchingNode = function (node) {
  19340. var matchingFormat = editor.formatter.matchNode(
  19341. node,
  19342. format,
  19343. vars !== null && vars !== void 0 ? vars : {},
  19344. similar
  19345. )
  19346. return !isUndefined(matchingFormat)
  19347. }
  19348. var isUnableToMatch = function (node) {
  19349. if (matchesUnInheritedFormatSelector(editor, node, format)) {
  19350. return true
  19351. } else {
  19352. if (!similar) {
  19353. return isNonNullable(
  19354. editor.formatter.matchNode(node, format, vars, true)
  19355. )
  19356. } else {
  19357. return false
  19358. }
  19359. }
  19360. }
  19361. return findUntil$1(parents, isMatchingNode, isUnableToMatch)
  19362. }
  19363. var getParents = function (editor, elm) {
  19364. var element = elm !== null && elm !== void 0 ? elm : fallbackElement(editor)
  19365. return filter$4(getParents$2(editor.dom, element), function (node) {
  19366. return isElement$5(node) && !isBogus$2(node)
  19367. })
  19368. }
  19369. var updateAndFireChangeCallbacks = function (
  19370. editor,
  19371. elm,
  19372. registeredCallbacks
  19373. ) {
  19374. var parents = getParents(editor, elm)
  19375. each$j(registeredCallbacks, function (data, format) {
  19376. var runIfChanged = function (spec) {
  19377. var match = matchingNode(
  19378. editor,
  19379. parents,
  19380. format,
  19381. spec.similar,
  19382. hasVars(spec) ? spec.vars : undefined
  19383. )
  19384. var isSet = match.isSome()
  19385. if (spec.state.get() !== isSet) {
  19386. spec.state.set(isSet)
  19387. var node_1 = match.getOr(elm)
  19388. if (hasVars(spec)) {
  19389. spec.callback(isSet, {
  19390. node: node_1,
  19391. format: format,
  19392. parents: parents,
  19393. })
  19394. } else {
  19395. each$k(spec.callbacks, function (callback) {
  19396. return callback(isSet, {
  19397. node: node_1,
  19398. format: format,
  19399. parents: parents,
  19400. })
  19401. })
  19402. }
  19403. }
  19404. }
  19405. each$k([data.withSimilar, data.withoutSimilar], runIfChanged)
  19406. each$k(data.withVars, runIfChanged)
  19407. })
  19408. }
  19409. var addListeners = function (
  19410. editor,
  19411. registeredFormatListeners,
  19412. formats,
  19413. callback,
  19414. similar,
  19415. vars
  19416. ) {
  19417. var formatChangeItems = registeredFormatListeners.get()
  19418. each$k(formats.split(','), function (format) {
  19419. var group = get$9(formatChangeItems, format).getOrThunk(function () {
  19420. var base = {
  19421. withSimilar: {
  19422. state: Cell(false),
  19423. similar: true,
  19424. callbacks: [],
  19425. },
  19426. withoutSimilar: {
  19427. state: Cell(false),
  19428. similar: false,
  19429. callbacks: [],
  19430. },
  19431. withVars: [],
  19432. }
  19433. formatChangeItems[format] = base
  19434. return base
  19435. })
  19436. var getCurrent = function () {
  19437. var parents = getParents(editor)
  19438. return matchingNode(editor, parents, format, similar, vars).isSome()
  19439. }
  19440. if (isUndefined(vars)) {
  19441. var toAppendTo = similar ? group.withSimilar : group.withoutSimilar
  19442. toAppendTo.callbacks.push(callback)
  19443. if (toAppendTo.callbacks.length === 1) {
  19444. toAppendTo.state.set(getCurrent())
  19445. }
  19446. } else {
  19447. group.withVars.push({
  19448. state: Cell(getCurrent()),
  19449. similar: similar,
  19450. vars: vars,
  19451. callback: callback,
  19452. })
  19453. }
  19454. })
  19455. registeredFormatListeners.set(formatChangeItems)
  19456. }
  19457. var removeListeners = function (
  19458. registeredFormatListeners,
  19459. formats,
  19460. callback
  19461. ) {
  19462. var formatChangeItems = registeredFormatListeners.get()
  19463. each$k(formats.split(','), function (format) {
  19464. return get$9(formatChangeItems, format).each(function (group) {
  19465. formatChangeItems[format] = {
  19466. withSimilar: __assign(__assign({}, group.withSimilar), {
  19467. callbacks: filter$4(group.withSimilar.callbacks, function (cb) {
  19468. return cb !== callback
  19469. }),
  19470. }),
  19471. withoutSimilar: __assign(__assign({}, group.withoutSimilar), {
  19472. callbacks: filter$4(group.withoutSimilar.callbacks, function (cb) {
  19473. return cb !== callback
  19474. }),
  19475. }),
  19476. withVars: filter$4(group.withVars, function (item) {
  19477. return item.callback !== callback
  19478. }),
  19479. }
  19480. })
  19481. })
  19482. registeredFormatListeners.set(formatChangeItems)
  19483. }
  19484. var formatChangedInternal = function (
  19485. editor,
  19486. registeredFormatListeners,
  19487. formats,
  19488. callback,
  19489. similar,
  19490. vars
  19491. ) {
  19492. if (registeredFormatListeners.get() === null) {
  19493. setup$j(registeredFormatListeners, editor)
  19494. }
  19495. addListeners(
  19496. editor,
  19497. registeredFormatListeners,
  19498. formats,
  19499. callback,
  19500. similar,
  19501. vars
  19502. )
  19503. return {
  19504. unbind: function () {
  19505. return removeListeners(registeredFormatListeners, formats, callback)
  19506. },
  19507. }
  19508. }
  19509. var toggle = function (editor, name, vars, node) {
  19510. var fmt = editor.formatter.get(name)
  19511. if (
  19512. match$2(editor, name, vars, node) &&
  19513. (!('toggle' in fmt[0]) || fmt[0].toggle)
  19514. ) {
  19515. remove$1(editor, name, vars, node)
  19516. } else {
  19517. applyFormat$1(editor, name, vars, node)
  19518. }
  19519. }
  19520. var fromElements = function (elements, scope) {
  19521. var doc = scope || document
  19522. var fragment = doc.createDocumentFragment()
  19523. each$k(elements, function (element) {
  19524. fragment.appendChild(element.dom)
  19525. })
  19526. return SugarElement.fromDom(fragment)
  19527. }
  19528. var tableModel = function (element, width, rows) {
  19529. return {
  19530. element: element,
  19531. width: width,
  19532. rows: rows,
  19533. }
  19534. }
  19535. var tableRow = function (element, cells) {
  19536. return {
  19537. element: element,
  19538. cells: cells,
  19539. }
  19540. }
  19541. var cellPosition = function (x, y) {
  19542. return {
  19543. x: x,
  19544. y: y,
  19545. }
  19546. }
  19547. var getSpan = function (td, key) {
  19548. var value = parseInt(get$6(td, key), 10)
  19549. return isNaN(value) ? 1 : value
  19550. }
  19551. var fillout = function (table, x, y, tr, td) {
  19552. var rowspan = getSpan(td, 'rowspan')
  19553. var colspan = getSpan(td, 'colspan')
  19554. var rows = table.rows
  19555. for (var y2 = y; y2 < y + rowspan; y2++) {
  19556. if (!rows[y2]) {
  19557. rows[y2] = tableRow(deep$1(tr), [])
  19558. }
  19559. for (var x2 = x; x2 < x + colspan; x2++) {
  19560. var cells = rows[y2].cells
  19561. cells[x2] = y2 === y && x2 === x ? td : shallow(td)
  19562. }
  19563. }
  19564. }
  19565. var cellExists = function (table, x, y) {
  19566. var rows = table.rows
  19567. var cells = rows[y] ? rows[y].cells : []
  19568. return !!cells[x]
  19569. }
  19570. var skipCellsX = function (table, x, y) {
  19571. while (cellExists(table, x, y)) {
  19572. x++
  19573. }
  19574. return x
  19575. }
  19576. var getWidth = function (rows) {
  19577. return foldl(
  19578. rows,
  19579. function (acc, row) {
  19580. return row.cells.length > acc ? row.cells.length : acc
  19581. },
  19582. 0
  19583. )
  19584. }
  19585. var findElementPos = function (table, element) {
  19586. var rows = table.rows
  19587. for (var y = 0; y < rows.length; y++) {
  19588. var cells = rows[y].cells
  19589. for (var x = 0; x < cells.length; x++) {
  19590. if (eq(cells[x], element)) {
  19591. return Optional.some(cellPosition(x, y))
  19592. }
  19593. }
  19594. }
  19595. return Optional.none()
  19596. }
  19597. var extractRows = function (table, sx, sy, ex, ey) {
  19598. var newRows = []
  19599. var rows = table.rows
  19600. for (var y = sy; y <= ey; y++) {
  19601. var cells = rows[y].cells
  19602. var slice = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1)
  19603. newRows.push(tableRow(rows[y].element, slice))
  19604. }
  19605. return newRows
  19606. }
  19607. var subTable = function (table, startPos, endPos) {
  19608. var sx = startPos.x,
  19609. sy = startPos.y
  19610. var ex = endPos.x,
  19611. ey = endPos.y
  19612. var newRows =
  19613. sy < ey
  19614. ? extractRows(table, sx, sy, ex, ey)
  19615. : extractRows(table, sx, ey, ex, sy)
  19616. return tableModel(table.element, getWidth(newRows), newRows)
  19617. }
  19618. var createDomTable = function (table, rows) {
  19619. var tableElement = shallow(table.element)
  19620. var tableBody = SugarElement.fromTag('tbody')
  19621. append(tableBody, rows)
  19622. append$1(tableElement, tableBody)
  19623. return tableElement
  19624. }
  19625. var modelRowsToDomRows = function (table) {
  19626. return map$3(table.rows, function (row) {
  19627. var cells = map$3(row.cells, function (cell) {
  19628. var td = deep$1(cell)
  19629. remove$6(td, 'colspan')
  19630. remove$6(td, 'rowspan')
  19631. return td
  19632. })
  19633. var tr = shallow(row.element)
  19634. append(tr, cells)
  19635. return tr
  19636. })
  19637. }
  19638. var fromDom = function (tableElm) {
  19639. var table = tableModel(shallow(tableElm), 0, [])
  19640. each$k(descendants(tableElm, 'tr'), function (tr, y) {
  19641. each$k(descendants(tr, 'td,th'), function (td, x) {
  19642. fillout(table, skipCellsX(table, x, y), y, tr, td)
  19643. })
  19644. })
  19645. return tableModel(table.element, getWidth(table.rows), table.rows)
  19646. }
  19647. var toDom = function (table) {
  19648. return createDomTable(table, modelRowsToDomRows(table))
  19649. }
  19650. var subsection = function (table, startElement, endElement) {
  19651. return findElementPos(table, startElement).bind(function (startPos) {
  19652. return findElementPos(table, endElement).map(function (endPos) {
  19653. return subTable(table, startPos, endPos)
  19654. })
  19655. })
  19656. }
  19657. var findParentListContainer = function (parents) {
  19658. return find$3(parents, function (elm) {
  19659. return name(elm) === 'ul' || name(elm) === 'ol'
  19660. })
  19661. }
  19662. var getFullySelectedListWrappers = function (parents, rng) {
  19663. return find$3(parents, function (elm) {
  19664. return name(elm) === 'li' && hasAllContentsSelected(elm, rng)
  19665. }).fold(constant([]), function (_li) {
  19666. return findParentListContainer(parents)
  19667. .map(function (listCont) {
  19668. var listElm = SugarElement.fromTag(name(listCont))
  19669. var listStyles = filter$3(
  19670. getAllRaw(listCont),
  19671. function (_style, name) {
  19672. return startsWith(name, 'list-style')
  19673. }
  19674. )
  19675. setAll(listElm, listStyles)
  19676. return [SugarElement.fromTag('li'), listElm]
  19677. })
  19678. .getOr([])
  19679. })
  19680. }
  19681. var wrap = function (innerElm, elms) {
  19682. var wrapped = foldl(
  19683. elms,
  19684. function (acc, elm) {
  19685. append$1(elm, acc)
  19686. return elm
  19687. },
  19688. innerElm
  19689. )
  19690. return elms.length > 0 ? fromElements([wrapped]) : wrapped
  19691. }
  19692. var directListWrappers = function (commonAnchorContainer) {
  19693. if (isListItem(commonAnchorContainer)) {
  19694. return parent(commonAnchorContainer)
  19695. .filter(isList)
  19696. .fold(constant([]), function (listElm) {
  19697. return [commonAnchorContainer, listElm]
  19698. })
  19699. } else {
  19700. return isList(commonAnchorContainer) ? [commonAnchorContainer] : []
  19701. }
  19702. }
  19703. var getWrapElements = function (rootNode, rng) {
  19704. var commonAnchorContainer = SugarElement.fromDom(
  19705. rng.commonAncestorContainer
  19706. )
  19707. var parents = parentsAndSelf(commonAnchorContainer, rootNode)
  19708. var wrapElements = filter$4(parents, function (elm) {
  19709. return isInline$1(elm) || isHeading(elm)
  19710. })
  19711. var listWrappers = getFullySelectedListWrappers(parents, rng)
  19712. var allWrappers = wrapElements.concat(
  19713. listWrappers.length
  19714. ? listWrappers
  19715. : directListWrappers(commonAnchorContainer)
  19716. )
  19717. return map$3(allWrappers, shallow)
  19718. }
  19719. var emptyFragment = function () {
  19720. return fromElements([])
  19721. }
  19722. var getFragmentFromRange = function (rootNode, rng) {
  19723. return wrap(
  19724. SugarElement.fromDom(rng.cloneContents()),
  19725. getWrapElements(rootNode, rng)
  19726. )
  19727. }
  19728. var getParentTable = function (rootElm, cell) {
  19729. return ancestor$2(cell, 'table', curry(eq, rootElm))
  19730. }
  19731. var getTableFragment = function (rootNode, selectedTableCells) {
  19732. return getParentTable(rootNode, selectedTableCells[0])
  19733. .bind(function (tableElm) {
  19734. var firstCell = selectedTableCells[0]
  19735. var lastCell = selectedTableCells[selectedTableCells.length - 1]
  19736. var fullTableModel = fromDom(tableElm)
  19737. return subsection(fullTableModel, firstCell, lastCell).map(function (
  19738. sectionedTableModel
  19739. ) {
  19740. return fromElements([toDom(sectionedTableModel)])
  19741. })
  19742. })
  19743. .getOrThunk(emptyFragment)
  19744. }
  19745. var getSelectionFragment = function (rootNode, ranges) {
  19746. return ranges.length > 0 && ranges[0].collapsed
  19747. ? emptyFragment()
  19748. : getFragmentFromRange(rootNode, ranges[0])
  19749. }
  19750. var read$3 = function (rootNode, ranges) {
  19751. var selectedCells = getCellsFromElementOrRanges(ranges, rootNode)
  19752. return selectedCells.length > 0
  19753. ? getTableFragment(rootNode, selectedCells)
  19754. : getSelectionFragment(rootNode, ranges)
  19755. }
  19756. var trimLeadingCollapsibleText = function (text) {
  19757. return text.replace(/^[ \f\n\r\t\v]+/, '')
  19758. }
  19759. var isCollapsibleWhitespace = function (text, index) {
  19760. return index >= 0 && index < text.length && isWhiteSpace(text.charAt(index))
  19761. }
  19762. var getInnerText = function (bin, shouldTrim) {
  19763. var text = trim$2(bin.innerText)
  19764. return shouldTrim ? trimLeadingCollapsibleText(text) : text
  19765. }
  19766. var getContextNodeName = function (parentBlockOpt) {
  19767. return parentBlockOpt
  19768. .map(function (block) {
  19769. return block.nodeName
  19770. })
  19771. .getOr('div')
  19772. .toLowerCase()
  19773. }
  19774. var getTextContent = function (editor) {
  19775. return Optional.from(editor.selection.getRng())
  19776. .map(function (rng) {
  19777. var parentBlockOpt = Optional.from(
  19778. editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock)
  19779. )
  19780. var body = editor.getBody()
  19781. var contextNodeName = getContextNodeName(parentBlockOpt)
  19782. var shouldTrimSpaces = Env.browser.isIE() && contextNodeName !== 'pre'
  19783. var bin = editor.dom.add(
  19784. body,
  19785. contextNodeName,
  19786. {
  19787. 'data-mce-bogus': 'all',
  19788. style: 'overflow: hidden; opacity: 0;',
  19789. },
  19790. rng.cloneContents()
  19791. )
  19792. var text = getInnerText(bin, shouldTrimSpaces)
  19793. var nonRenderedText = trim$2(bin.textContent)
  19794. editor.dom.remove(bin)
  19795. if (
  19796. isCollapsibleWhitespace(nonRenderedText, 0) ||
  19797. isCollapsibleWhitespace(nonRenderedText, nonRenderedText.length - 1)
  19798. ) {
  19799. var parentBlock = parentBlockOpt.getOr(body)
  19800. var parentBlockText = getInnerText(parentBlock, shouldTrimSpaces)
  19801. var textIndex = parentBlockText.indexOf(text)
  19802. if (textIndex === -1) {
  19803. return text
  19804. } else {
  19805. var hasProceedingSpace = isCollapsibleWhitespace(
  19806. parentBlockText,
  19807. textIndex - 1
  19808. )
  19809. var hasTrailingSpace = isCollapsibleWhitespace(
  19810. parentBlockText,
  19811. textIndex + text.length
  19812. )
  19813. return (
  19814. (hasProceedingSpace ? ' ' : '') +
  19815. text +
  19816. (hasTrailingSpace ? ' ' : '')
  19817. )
  19818. }
  19819. } else {
  19820. return text
  19821. }
  19822. })
  19823. .getOr('')
  19824. }
  19825. var getSerializedContent = function (editor, args) {
  19826. var rng = editor.selection.getRng(),
  19827. tmpElm = editor.dom.create('body')
  19828. var sel = editor.selection.getSel()
  19829. var ranges = processRanges(editor, getRanges(sel))
  19830. var fragment = args.contextual
  19831. ? read$3(SugarElement.fromDom(editor.getBody()), ranges).dom
  19832. : rng.cloneContents()
  19833. if (fragment) {
  19834. tmpElm.appendChild(fragment)
  19835. }
  19836. return editor.selection.serializer.serialize(tmpElm, args)
  19837. }
  19838. var setupArgs$1 = function (args, format) {
  19839. return __assign(__assign({}, args), {
  19840. format: format,
  19841. get: true,
  19842. selection: true,
  19843. })
  19844. }
  19845. var getSelectedContentInternal = function (editor, format, args) {
  19846. if (args === void 0) {
  19847. args = {}
  19848. }
  19849. var defaultedArgs = setupArgs$1(args, format)
  19850. var updatedArgs = editor.fire('BeforeGetContent', defaultedArgs)
  19851. if (updatedArgs.isDefaultPrevented()) {
  19852. editor.fire('GetContent', updatedArgs)
  19853. return updatedArgs.content
  19854. }
  19855. if (updatedArgs.format === 'text') {
  19856. return getTextContent(editor)
  19857. } else {
  19858. updatedArgs.getInner = true
  19859. var content = getSerializedContent(editor, updatedArgs)
  19860. if (updatedArgs.format === 'tree') {
  19861. return content
  19862. } else {
  19863. updatedArgs.content = editor.selection.isCollapsed() ? '' : content
  19864. editor.fire('GetContent', updatedArgs)
  19865. return updatedArgs.content
  19866. }
  19867. }
  19868. }
  19869. var KEEP = 0,
  19870. INSERT = 1,
  19871. DELETE = 2
  19872. var diff = function (left, right) {
  19873. var size = left.length + right.length + 2
  19874. var vDown = new Array(size)
  19875. var vUp = new Array(size)
  19876. var snake = function (start, end, diag) {
  19877. return {
  19878. start: start,
  19879. end: end,
  19880. diag: diag,
  19881. }
  19882. }
  19883. var buildScript = function (start1, end1, start2, end2, script) {
  19884. var middle = getMiddleSnake(start1, end1, start2, end2)
  19885. if (
  19886. middle === null ||
  19887. (middle.start === end1 && middle.diag === end1 - end2) ||
  19888. (middle.end === start1 && middle.diag === start1 - start2)
  19889. ) {
  19890. var i = start1
  19891. var j = start2
  19892. while (i < end1 || j < end2) {
  19893. if (i < end1 && j < end2 && left[i] === right[j]) {
  19894. script.push([KEEP, left[i]])
  19895. ++i
  19896. ++j
  19897. } else {
  19898. if (end1 - start1 > end2 - start2) {
  19899. script.push([DELETE, left[i]])
  19900. ++i
  19901. } else {
  19902. script.push([INSERT, right[j]])
  19903. ++j
  19904. }
  19905. }
  19906. }
  19907. } else {
  19908. buildScript(
  19909. start1,
  19910. middle.start,
  19911. start2,
  19912. middle.start - middle.diag,
  19913. script
  19914. )
  19915. for (var i2 = middle.start; i2 < middle.end; ++i2) {
  19916. script.push([KEEP, left[i2]])
  19917. }
  19918. buildScript(middle.end, end1, middle.end - middle.diag, end2, script)
  19919. }
  19920. }
  19921. var buildSnake = function (start, diag, end1, end2) {
  19922. var end = start
  19923. while (
  19924. end - diag < end2 &&
  19925. end < end1 &&
  19926. left[end] === right[end - diag]
  19927. ) {
  19928. ++end
  19929. }
  19930. return snake(start, end, diag)
  19931. }
  19932. var getMiddleSnake = function (start1, end1, start2, end2) {
  19933. var m = end1 - start1
  19934. var n = end2 - start2
  19935. if (m === 0 || n === 0) {
  19936. return null
  19937. }
  19938. var delta = m - n
  19939. var sum = n + m
  19940. var offset = (sum % 2 === 0 ? sum : sum + 1) / 2
  19941. vDown[1 + offset] = start1
  19942. vUp[1 + offset] = end1 + 1
  19943. var d, k, i, x, y
  19944. for (d = 0; d <= offset; ++d) {
  19945. for (k = -d; k <= d; k += 2) {
  19946. i = k + offset
  19947. if (k === -d || (k !== d && vDown[i - 1] < vDown[i + 1])) {
  19948. vDown[i] = vDown[i + 1]
  19949. } else {
  19950. vDown[i] = vDown[i - 1] + 1
  19951. }
  19952. x = vDown[i]
  19953. y = x - start1 + start2 - k
  19954. while (x < end1 && y < end2 && left[x] === right[y]) {
  19955. vDown[i] = ++x
  19956. ++y
  19957. }
  19958. if (delta % 2 !== 0 && delta - d <= k && k <= delta + d) {
  19959. if (vUp[i - delta] <= vDown[i]) {
  19960. return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2)
  19961. }
  19962. }
  19963. }
  19964. for (k = delta - d; k <= delta + d; k += 2) {
  19965. i = k + offset - delta
  19966. if (
  19967. k === delta - d ||
  19968. (k !== delta + d && vUp[i + 1] <= vUp[i - 1])
  19969. ) {
  19970. vUp[i] = vUp[i + 1] - 1
  19971. } else {
  19972. vUp[i] = vUp[i - 1]
  19973. }
  19974. x = vUp[i] - 1
  19975. y = x - start1 + start2 - k
  19976. while (x >= start1 && y >= start2 && left[x] === right[y]) {
  19977. vUp[i] = x--
  19978. y--
  19979. }
  19980. if (delta % 2 === 0 && -d <= k && k <= d) {
  19981. if (vUp[i] <= vDown[i + delta]) {
  19982. return buildSnake(vUp[i], k + start1 - start2, end1, end2)
  19983. }
  19984. }
  19985. }
  19986. }
  19987. }
  19988. var script = []
  19989. buildScript(0, left.length, 0, right.length, script)
  19990. return script
  19991. }
  19992. var getOuterHtml = function (elm) {
  19993. if (isElement$5(elm)) {
  19994. return elm.outerHTML
  19995. } else if (isText$7(elm)) {
  19996. return Entities.encodeRaw(elm.data, false)
  19997. } else if (isComment(elm)) {
  19998. return '<!--' + elm.data + '-->'
  19999. }
  20000. return ''
  20001. }
  20002. var createFragment = function (html) {
  20003. var node
  20004. var container = document.createElement('div')
  20005. var frag = document.createDocumentFragment()
  20006. if (html) {
  20007. container.innerHTML = html
  20008. }
  20009. while ((node = container.firstChild)) {
  20010. frag.appendChild(node)
  20011. }
  20012. return frag
  20013. }
  20014. var insertAt = function (elm, html, index) {
  20015. var fragment = createFragment(html)
  20016. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  20017. var target = elm.childNodes[index]
  20018. target.parentNode.insertBefore(fragment, target)
  20019. } else {
  20020. elm.appendChild(fragment)
  20021. }
  20022. }
  20023. var removeAt = function (elm, index) {
  20024. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  20025. var target = elm.childNodes[index]
  20026. target.parentNode.removeChild(target)
  20027. }
  20028. }
  20029. var applyDiff = function (diff, elm) {
  20030. var index = 0
  20031. each$k(diff, function (action) {
  20032. if (action[0] === KEEP) {
  20033. index++
  20034. } else if (action[0] === INSERT) {
  20035. insertAt(elm, action[1], index)
  20036. index++
  20037. } else if (action[0] === DELETE) {
  20038. removeAt(elm, index)
  20039. }
  20040. })
  20041. }
  20042. var read$2 = function (elm) {
  20043. return filter$4(map$3(from(elm.childNodes), getOuterHtml), function (item) {
  20044. return item.length > 0
  20045. })
  20046. }
  20047. var write = function (fragments, elm) {
  20048. var currentFragments = map$3(from(elm.childNodes), getOuterHtml)
  20049. applyDiff(diff(currentFragments, fragments), elm)
  20050. return elm
  20051. }
  20052. var lazyTempDocument = cached(function () {
  20053. return document.implementation.createHTMLDocument('undo')
  20054. })
  20055. var hasIframes = function (html) {
  20056. return html.indexOf('</iframe>') !== -1
  20057. }
  20058. var createFragmentedLevel = function (fragments) {
  20059. return {
  20060. type: 'fragmented',
  20061. fragments: fragments,
  20062. content: '',
  20063. bookmark: null,
  20064. beforeBookmark: null,
  20065. }
  20066. }
  20067. var createCompleteLevel = function (content) {
  20068. return {
  20069. type: 'complete',
  20070. fragments: null,
  20071. content: content,
  20072. bookmark: null,
  20073. beforeBookmark: null,
  20074. }
  20075. }
  20076. var createFromEditor = function (editor) {
  20077. var fragments = read$2(editor.getBody())
  20078. var trimmedFragments = bind(fragments, function (html) {
  20079. var trimmed = trimInternal(editor.serializer, html)
  20080. return trimmed.length > 0 ? [trimmed] : []
  20081. })
  20082. var content = trimmedFragments.join('')
  20083. return hasIframes(content)
  20084. ? createFragmentedLevel(trimmedFragments)
  20085. : createCompleteLevel(content)
  20086. }
  20087. var applyToEditor = function (editor, level, before) {
  20088. var bookmark = before ? level.beforeBookmark : level.bookmark
  20089. if (level.type === 'fragmented') {
  20090. write(level.fragments, editor.getBody())
  20091. } else {
  20092. editor.setContent(level.content, {
  20093. format: 'raw',
  20094. no_selection:
  20095. isNonNullable(bookmark) && isPathBookmark(bookmark)
  20096. ? !bookmark.isFakeCaret
  20097. : true,
  20098. })
  20099. }
  20100. editor.selection.moveToBookmark(bookmark)
  20101. }
  20102. var getLevelContent = function (level) {
  20103. return level.type === 'fragmented'
  20104. ? level.fragments.join('')
  20105. : level.content
  20106. }
  20107. var getCleanLevelContent = function (level) {
  20108. var elm = SugarElement.fromTag('body', lazyTempDocument())
  20109. set(elm, getLevelContent(level))
  20110. each$k(descendants(elm, '*[data-mce-bogus]'), unwrap)
  20111. return get$3(elm)
  20112. }
  20113. var hasEqualContent = function (level1, level2) {
  20114. return getLevelContent(level1) === getLevelContent(level2)
  20115. }
  20116. var hasEqualCleanedContent = function (level1, level2) {
  20117. return getCleanLevelContent(level1) === getCleanLevelContent(level2)
  20118. }
  20119. var isEq$1 = function (level1, level2) {
  20120. if (!level1 || !level2) {
  20121. return false
  20122. } else if (hasEqualContent(level1, level2)) {
  20123. return true
  20124. } else {
  20125. return hasEqualCleanedContent(level1, level2)
  20126. }
  20127. }
  20128. var isUnlocked = function (locks) {
  20129. return locks.get() === 0
  20130. }
  20131. var setTyping = function (undoManager, typing, locks) {
  20132. if (isUnlocked(locks)) {
  20133. undoManager.typing = typing
  20134. }
  20135. }
  20136. var endTyping = function (undoManager, locks) {
  20137. if (undoManager.typing) {
  20138. setTyping(undoManager, false, locks)
  20139. undoManager.add()
  20140. }
  20141. }
  20142. var endTypingLevelIgnoreLocks = function (undoManager) {
  20143. if (undoManager.typing) {
  20144. undoManager.typing = false
  20145. undoManager.add()
  20146. }
  20147. }
  20148. var beforeChange$1 = function (editor, locks, beforeBookmark) {
  20149. if (isUnlocked(locks)) {
  20150. beforeBookmark.set(getUndoBookmark(editor.selection))
  20151. }
  20152. }
  20153. var addUndoLevel$1 = function (
  20154. editor,
  20155. undoManager,
  20156. index,
  20157. locks,
  20158. beforeBookmark,
  20159. level,
  20160. event
  20161. ) {
  20162. var currentLevel = createFromEditor(editor)
  20163. level = level || {}
  20164. level = Tools.extend(level, currentLevel)
  20165. if (isUnlocked(locks) === false || editor.removed) {
  20166. return null
  20167. }
  20168. var lastLevel = undoManager.data[index.get()]
  20169. if (
  20170. editor
  20171. .fire('BeforeAddUndo', {
  20172. level: level,
  20173. lastLevel: lastLevel,
  20174. originalEvent: event,
  20175. })
  20176. .isDefaultPrevented()
  20177. ) {
  20178. return null
  20179. }
  20180. if (lastLevel && isEq$1(lastLevel, level)) {
  20181. return null
  20182. }
  20183. if (undoManager.data[index.get()]) {
  20184. beforeBookmark.get().each(function (bm) {
  20185. undoManager.data[index.get()].beforeBookmark = bm
  20186. })
  20187. }
  20188. var customUndoRedoLevels = getCustomUndoRedoLevels(editor)
  20189. if (customUndoRedoLevels) {
  20190. if (undoManager.data.length > customUndoRedoLevels) {
  20191. for (var i = 0; i < undoManager.data.length - 1; i++) {
  20192. undoManager.data[i] = undoManager.data[i + 1]
  20193. }
  20194. undoManager.data.length--
  20195. index.set(undoManager.data.length)
  20196. }
  20197. }
  20198. level.bookmark = getUndoBookmark(editor.selection)
  20199. if (index.get() < undoManager.data.length - 1) {
  20200. undoManager.data.length = index.get() + 1
  20201. }
  20202. undoManager.data.push(level)
  20203. index.set(undoManager.data.length - 1)
  20204. var args = {
  20205. level: level,
  20206. lastLevel: lastLevel,
  20207. originalEvent: event,
  20208. }
  20209. if (index.get() > 0) {
  20210. editor.setDirty(true)
  20211. editor.fire('AddUndo', args)
  20212. editor.fire('change', args)
  20213. } else {
  20214. editor.fire('AddUndo', args)
  20215. }
  20216. return level
  20217. }
  20218. var clear$1 = function (editor, undoManager, index) {
  20219. undoManager.data = []
  20220. index.set(0)
  20221. undoManager.typing = false
  20222. editor.fire('ClearUndos')
  20223. }
  20224. var extra$1 = function (editor, undoManager, index, callback1, callback2) {
  20225. if (undoManager.transact(callback1)) {
  20226. var bookmark = undoManager.data[index.get()].bookmark
  20227. var lastLevel = undoManager.data[index.get() - 1]
  20228. applyToEditor(editor, lastLevel, true)
  20229. if (undoManager.transact(callback2)) {
  20230. undoManager.data[index.get() - 1].beforeBookmark = bookmark
  20231. }
  20232. }
  20233. }
  20234. var redo$1 = function (editor, index, data) {
  20235. var level
  20236. if (index.get() < data.length - 1) {
  20237. index.set(index.get() + 1)
  20238. level = data[index.get()]
  20239. applyToEditor(editor, level, false)
  20240. editor.setDirty(true)
  20241. editor.fire('Redo', { level: level })
  20242. }
  20243. return level
  20244. }
  20245. var undo$1 = function (editor, undoManager, locks, index) {
  20246. var level
  20247. if (undoManager.typing) {
  20248. undoManager.add()
  20249. undoManager.typing = false
  20250. setTyping(undoManager, false, locks)
  20251. }
  20252. if (index.get() > 0) {
  20253. index.set(index.get() - 1)
  20254. level = undoManager.data[index.get()]
  20255. applyToEditor(editor, level, true)
  20256. editor.setDirty(true)
  20257. editor.fire('Undo', { level: level })
  20258. }
  20259. return level
  20260. }
  20261. var reset$1 = function (undoManager) {
  20262. undoManager.clear()
  20263. undoManager.add()
  20264. }
  20265. var hasUndo$1 = function (editor, undoManager, index) {
  20266. return (
  20267. index.get() > 0 ||
  20268. (undoManager.typing &&
  20269. undoManager.data[0] &&
  20270. !isEq$1(createFromEditor(editor), undoManager.data[0]))
  20271. )
  20272. }
  20273. var hasRedo$1 = function (undoManager, index) {
  20274. return index.get() < undoManager.data.length - 1 && !undoManager.typing
  20275. }
  20276. var transact$1 = function (undoManager, locks, callback) {
  20277. endTyping(undoManager, locks)
  20278. undoManager.beforeChange()
  20279. undoManager.ignore(callback)
  20280. return undoManager.add()
  20281. }
  20282. var ignore$1 = function (locks, callback) {
  20283. try {
  20284. locks.set(locks.get() + 1)
  20285. callback()
  20286. } finally {
  20287. locks.set(locks.get() - 1)
  20288. }
  20289. }
  20290. var addVisualInternal = function (editor, elm) {
  20291. var dom = editor.dom
  20292. var scope = isNonNullable(elm) ? elm : editor.getBody()
  20293. if (isUndefined(editor.hasVisual)) {
  20294. editor.hasVisual = isVisualAidsEnabled(editor)
  20295. }
  20296. each$k(dom.select('table,a', scope), function (matchedElm) {
  20297. switch (matchedElm.nodeName) {
  20298. case 'TABLE':
  20299. var cls = getVisualAidsTableClass(editor)
  20300. var value = dom.getAttrib(matchedElm, 'border')
  20301. if ((!value || value === '0') && editor.hasVisual) {
  20302. dom.addClass(matchedElm, cls)
  20303. } else {
  20304. dom.removeClass(matchedElm, cls)
  20305. }
  20306. break
  20307. case 'A':
  20308. if (!dom.getAttrib(matchedElm, 'href')) {
  20309. var value_1 = dom.getAttrib(matchedElm, 'name') || matchedElm.id
  20310. var cls_1 = getVisualAidsAnchorClass(editor)
  20311. if (value_1 && editor.hasVisual) {
  20312. dom.addClass(matchedElm, cls_1)
  20313. } else {
  20314. dom.removeClass(matchedElm, cls_1)
  20315. }
  20316. }
  20317. break
  20318. }
  20319. })
  20320. editor.fire('VisualAid', {
  20321. element: elm,
  20322. hasVisual: editor.hasVisual,
  20323. })
  20324. }
  20325. var makePlainAdaptor = function (editor) {
  20326. return {
  20327. undoManager: {
  20328. beforeChange: function (locks, beforeBookmark) {
  20329. return beforeChange$1(editor, locks, beforeBookmark)
  20330. },
  20331. add: function (
  20332. undoManager,
  20333. index,
  20334. locks,
  20335. beforeBookmark,
  20336. level,
  20337. event
  20338. ) {
  20339. return addUndoLevel$1(
  20340. editor,
  20341. undoManager,
  20342. index,
  20343. locks,
  20344. beforeBookmark,
  20345. level,
  20346. event
  20347. )
  20348. },
  20349. undo: function (undoManager, locks, index) {
  20350. return undo$1(editor, undoManager, locks, index)
  20351. },
  20352. redo: function (index, data) {
  20353. return redo$1(editor, index, data)
  20354. },
  20355. clear: function (undoManager, index) {
  20356. return clear$1(editor, undoManager, index)
  20357. },
  20358. reset: function (undoManager) {
  20359. return reset$1(undoManager)
  20360. },
  20361. hasUndo: function (undoManager, index) {
  20362. return hasUndo$1(editor, undoManager, index)
  20363. },
  20364. hasRedo: function (undoManager, index) {
  20365. return hasRedo$1(undoManager, index)
  20366. },
  20367. transact: function (undoManager, locks, callback) {
  20368. return transact$1(undoManager, locks, callback)
  20369. },
  20370. ignore: function (locks, callback) {
  20371. return ignore$1(locks, callback)
  20372. },
  20373. extra: function (undoManager, index, callback1, callback2) {
  20374. return extra$1(editor, undoManager, index, callback1, callback2)
  20375. },
  20376. },
  20377. formatter: {
  20378. match: function (name, vars, node, similar) {
  20379. return match$2(editor, name, vars, node, similar)
  20380. },
  20381. matchAll: function (names, vars) {
  20382. return matchAll(editor, names, vars)
  20383. },
  20384. matchNode: function (node, name, vars, similar) {
  20385. return matchNode(editor, node, name, vars, similar)
  20386. },
  20387. canApply: function (name) {
  20388. return canApply(editor, name)
  20389. },
  20390. closest: function (names) {
  20391. return closest(editor, names)
  20392. },
  20393. apply: function (name, vars, node) {
  20394. return applyFormat$1(editor, name, vars, node)
  20395. },
  20396. remove: function (name, vars, node, similar) {
  20397. return remove$1(editor, name, vars, node, similar)
  20398. },
  20399. toggle: function (name, vars, node) {
  20400. return toggle(editor, name, vars, node)
  20401. },
  20402. formatChanged: function (
  20403. registeredFormatListeners,
  20404. formats,
  20405. callback,
  20406. similar,
  20407. vars
  20408. ) {
  20409. return formatChangedInternal(
  20410. editor,
  20411. registeredFormatListeners,
  20412. formats,
  20413. callback,
  20414. similar,
  20415. vars
  20416. )
  20417. },
  20418. },
  20419. editor: {
  20420. getContent: function (args, format) {
  20421. return getContentInternal(editor, args, format)
  20422. },
  20423. setContent: function (content, args) {
  20424. return setContentInternal(editor, content, args)
  20425. },
  20426. insertContent: function (value, details) {
  20427. return insertHtmlAtCaret(editor, value, details)
  20428. },
  20429. addVisual: function (elm) {
  20430. return addVisualInternal(editor, elm)
  20431. },
  20432. },
  20433. selection: {
  20434. getContent: function (format, args) {
  20435. return getSelectedContentInternal(editor, format, args)
  20436. },
  20437. },
  20438. raw: {
  20439. getModel: function () {
  20440. return Optional.none()
  20441. },
  20442. },
  20443. }
  20444. }
  20445. var makeRtcAdaptor = function (rtcEditor) {
  20446. var defaultVars = function (vars) {
  20447. return isObject(vars) ? vars : {}
  20448. }
  20449. var undoManager = rtcEditor.undoManager,
  20450. formatter = rtcEditor.formatter,
  20451. editor = rtcEditor.editor,
  20452. selection = rtcEditor.selection,
  20453. raw = rtcEditor.raw
  20454. return {
  20455. undoManager: {
  20456. beforeChange: undoManager.beforeChange,
  20457. add: undoManager.add,
  20458. undo: undoManager.undo,
  20459. redo: undoManager.redo,
  20460. clear: undoManager.clear,
  20461. reset: undoManager.reset,
  20462. hasUndo: undoManager.hasUndo,
  20463. hasRedo: undoManager.hasRedo,
  20464. transact: function (_undoManager, _locks, fn) {
  20465. return undoManager.transact(fn)
  20466. },
  20467. ignore: function (_locks, callback) {
  20468. return undoManager.ignore(callback)
  20469. },
  20470. extra: function (_undoManager, _index, callback1, callback2) {
  20471. return undoManager.extra(callback1, callback2)
  20472. },
  20473. },
  20474. formatter: {
  20475. match: function (name, vars, _node, similar) {
  20476. return formatter.match(name, defaultVars(vars), similar)
  20477. },
  20478. matchAll: formatter.matchAll,
  20479. matchNode: formatter.matchNode,
  20480. canApply: function (name) {
  20481. return formatter.canApply(name)
  20482. },
  20483. closest: function (names) {
  20484. return formatter.closest(names)
  20485. },
  20486. apply: function (name, vars, _node) {
  20487. return formatter.apply(name, defaultVars(vars))
  20488. },
  20489. remove: function (name, vars, _node, _similar) {
  20490. return formatter.remove(name, defaultVars(vars))
  20491. },
  20492. toggle: function (name, vars, _node) {
  20493. return formatter.toggle(name, defaultVars(vars))
  20494. },
  20495. formatChanged: function (_rfl, formats, callback, similar, vars) {
  20496. return formatter.formatChanged(formats, callback, similar, vars)
  20497. },
  20498. },
  20499. editor: {
  20500. getContent: function (args, _format) {
  20501. return editor.getContent(args)
  20502. },
  20503. setContent: function (content, args) {
  20504. return editor.setContent(content, args)
  20505. },
  20506. insertContent: function (content, _details) {
  20507. return editor.insertContent(content)
  20508. },
  20509. addVisual: editor.addVisual,
  20510. },
  20511. selection: {
  20512. getContent: function (_format, args) {
  20513. return selection.getContent(args)
  20514. },
  20515. },
  20516. raw: {
  20517. getModel: function () {
  20518. return Optional.some(raw.getRawModel())
  20519. },
  20520. },
  20521. }
  20522. }
  20523. var makeNoopAdaptor = function () {
  20524. var nul = constant(null)
  20525. var empty = constant('')
  20526. return {
  20527. undoManager: {
  20528. beforeChange: noop,
  20529. add: nul,
  20530. undo: nul,
  20531. redo: nul,
  20532. clear: noop,
  20533. reset: noop,
  20534. hasUndo: never,
  20535. hasRedo: never,
  20536. transact: nul,
  20537. ignore: noop,
  20538. extra: noop,
  20539. },
  20540. formatter: {
  20541. match: never,
  20542. matchAll: constant([]),
  20543. matchNode: constant(undefined),
  20544. canApply: never,
  20545. closest: empty,
  20546. apply: noop,
  20547. remove: noop,
  20548. toggle: noop,
  20549. formatChanged: constant({ unbind: noop }),
  20550. },
  20551. editor: {
  20552. getContent: empty,
  20553. setContent: empty,
  20554. insertContent: noop,
  20555. addVisual: noop,
  20556. },
  20557. selection: { getContent: empty },
  20558. raw: { getModel: constant(Optional.none()) },
  20559. }
  20560. }
  20561. var isRtc = function (editor) {
  20562. return has$2(editor.plugins, 'rtc')
  20563. }
  20564. var getRtcSetup = function (editor) {
  20565. return get$9(editor.plugins, 'rtc').bind(function (rtcPlugin) {
  20566. return Optional.from(rtcPlugin.setup)
  20567. })
  20568. }
  20569. var setup$i = function (editor) {
  20570. var editorCast = editor
  20571. return getRtcSetup(editor).fold(
  20572. function () {
  20573. editorCast.rtcInstance = makePlainAdaptor(editor)
  20574. return Optional.none()
  20575. },
  20576. function (setup) {
  20577. editorCast.rtcInstance = makeNoopAdaptor()
  20578. return Optional.some(function () {
  20579. return setup().then(function (rtcEditor) {
  20580. editorCast.rtcInstance = makeRtcAdaptor(rtcEditor)
  20581. return rtcEditor.rtc.isRemote
  20582. })
  20583. })
  20584. }
  20585. )
  20586. }
  20587. var getRtcInstanceWithFallback = function (editor) {
  20588. return editor.rtcInstance ? editor.rtcInstance : makePlainAdaptor(editor)
  20589. }
  20590. var getRtcInstanceWithError = function (editor) {
  20591. var rtcInstance = editor.rtcInstance
  20592. if (!rtcInstance) {
  20593. throw new Error('Failed to get RTC instance not yet initialized.')
  20594. } else {
  20595. return rtcInstance
  20596. }
  20597. }
  20598. var beforeChange = function (editor, locks, beforeBookmark) {
  20599. getRtcInstanceWithError(editor).undoManager.beforeChange(
  20600. locks,
  20601. beforeBookmark
  20602. )
  20603. }
  20604. var addUndoLevel = function (
  20605. editor,
  20606. undoManager,
  20607. index,
  20608. locks,
  20609. beforeBookmark,
  20610. level,
  20611. event
  20612. ) {
  20613. return getRtcInstanceWithError(editor).undoManager.add(
  20614. undoManager,
  20615. index,
  20616. locks,
  20617. beforeBookmark,
  20618. level,
  20619. event
  20620. )
  20621. }
  20622. var undo = function (editor, undoManager, locks, index) {
  20623. return getRtcInstanceWithError(editor).undoManager.undo(
  20624. undoManager,
  20625. locks,
  20626. index
  20627. )
  20628. }
  20629. var redo = function (editor, index, data) {
  20630. return getRtcInstanceWithError(editor).undoManager.redo(index, data)
  20631. }
  20632. var clear = function (editor, undoManager, index) {
  20633. getRtcInstanceWithError(editor).undoManager.clear(undoManager, index)
  20634. }
  20635. var reset = function (editor, undoManager) {
  20636. getRtcInstanceWithError(editor).undoManager.reset(undoManager)
  20637. }
  20638. var hasUndo = function (editor, undoManager, index) {
  20639. return getRtcInstanceWithError(editor).undoManager.hasUndo(
  20640. undoManager,
  20641. index
  20642. )
  20643. }
  20644. var hasRedo = function (editor, undoManager, index) {
  20645. return getRtcInstanceWithError(editor).undoManager.hasRedo(
  20646. undoManager,
  20647. index
  20648. )
  20649. }
  20650. var transact = function (editor, undoManager, locks, callback) {
  20651. return getRtcInstanceWithError(editor).undoManager.transact(
  20652. undoManager,
  20653. locks,
  20654. callback
  20655. )
  20656. }
  20657. var ignore = function (editor, locks, callback) {
  20658. getRtcInstanceWithError(editor).undoManager.ignore(locks, callback)
  20659. }
  20660. var extra = function (editor, undoManager, index, callback1, callback2) {
  20661. getRtcInstanceWithError(editor).undoManager.extra(
  20662. undoManager,
  20663. index,
  20664. callback1,
  20665. callback2
  20666. )
  20667. }
  20668. var matchFormat = function (editor, name, vars, node, similar) {
  20669. return getRtcInstanceWithError(editor).formatter.match(
  20670. name,
  20671. vars,
  20672. node,
  20673. similar
  20674. )
  20675. }
  20676. var matchAllFormats = function (editor, names, vars) {
  20677. return getRtcInstanceWithError(editor).formatter.matchAll(names, vars)
  20678. }
  20679. var matchNodeFormat = function (editor, node, name, vars, similar) {
  20680. return getRtcInstanceWithError(editor).formatter.matchNode(
  20681. node,
  20682. name,
  20683. vars,
  20684. similar
  20685. )
  20686. }
  20687. var canApplyFormat = function (editor, name) {
  20688. return getRtcInstanceWithError(editor).formatter.canApply(name)
  20689. }
  20690. var closestFormat = function (editor, names) {
  20691. return getRtcInstanceWithError(editor).formatter.closest(names)
  20692. }
  20693. var applyFormat = function (editor, name, vars, node) {
  20694. getRtcInstanceWithError(editor).formatter.apply(name, vars, node)
  20695. }
  20696. var removeFormat = function (editor, name, vars, node, similar) {
  20697. getRtcInstanceWithError(editor).formatter.remove(name, vars, node, similar)
  20698. }
  20699. var toggleFormat = function (editor, name, vars, node) {
  20700. getRtcInstanceWithError(editor).formatter.toggle(name, vars, node)
  20701. }
  20702. var formatChanged = function (
  20703. editor,
  20704. registeredFormatListeners,
  20705. formats,
  20706. callback,
  20707. similar,
  20708. vars
  20709. ) {
  20710. return getRtcInstanceWithError(editor).formatter.formatChanged(
  20711. registeredFormatListeners,
  20712. formats,
  20713. callback,
  20714. similar,
  20715. vars
  20716. )
  20717. }
  20718. var getContent$2 = function (editor, args, format) {
  20719. return getRtcInstanceWithFallback(editor).editor.getContent(args, format)
  20720. }
  20721. var setContent$2 = function (editor, content, args) {
  20722. return getRtcInstanceWithFallback(editor).editor.setContent(content, args)
  20723. }
  20724. var insertContent = function (editor, value, details) {
  20725. return getRtcInstanceWithFallback(editor).editor.insertContent(
  20726. value,
  20727. details
  20728. )
  20729. }
  20730. var getSelectedContent = function (editor, format, args) {
  20731. return getRtcInstanceWithError(editor).selection.getContent(format, args)
  20732. }
  20733. var addVisual$1 = function (editor, elm) {
  20734. return getRtcInstanceWithError(editor).editor.addVisual(elm)
  20735. }
  20736. var getContent$1 = function (editor, args) {
  20737. if (args === void 0) {
  20738. args = {}
  20739. }
  20740. var format = args.format ? args.format : 'html'
  20741. return getSelectedContent(editor, format, args)
  20742. }
  20743. var removeEmpty = function (text) {
  20744. if (text.dom.length === 0) {
  20745. remove$7(text)
  20746. return Optional.none()
  20747. } else {
  20748. return Optional.some(text)
  20749. }
  20750. }
  20751. var walkPastBookmark = function (node, start) {
  20752. return node
  20753. .filter(function (elm) {
  20754. return BookmarkManager.isBookmarkNode(elm.dom)
  20755. })
  20756. .bind(start ? nextSibling : prevSibling)
  20757. }
  20758. var merge = function (outer, inner, rng, start) {
  20759. var outerElm = outer.dom
  20760. var innerElm = inner.dom
  20761. var oldLength = start ? outerElm.length : innerElm.length
  20762. if (start) {
  20763. mergeTextNodes(outerElm, innerElm, false, !start)
  20764. rng.setStart(innerElm, oldLength)
  20765. } else {
  20766. mergeTextNodes(innerElm, outerElm, false, !start)
  20767. rng.setEnd(innerElm, oldLength)
  20768. }
  20769. }
  20770. var normalizeTextIfRequired = function (inner, start) {
  20771. parent(inner).each(function (root) {
  20772. var text = inner.dom
  20773. if (start && needsToBeNbspLeft(root, CaretPosition(text, 0))) {
  20774. normalizeWhitespaceAfter(text, 0)
  20775. } else if (
  20776. !start &&
  20777. needsToBeNbspRight(root, CaretPosition(text, text.length))
  20778. ) {
  20779. normalizeWhitespaceBefore(text, text.length)
  20780. }
  20781. })
  20782. }
  20783. var mergeAndNormalizeText = function (outerNode, innerNode, rng, start) {
  20784. outerNode
  20785. .bind(function (outer) {
  20786. var normalizer = start
  20787. ? normalizeWhitespaceBefore
  20788. : normalizeWhitespaceAfter
  20789. normalizer(outer.dom, start ? outer.dom.length : 0)
  20790. return innerNode.filter(isText$8).map(function (inner) {
  20791. return merge(outer, inner, rng, start)
  20792. })
  20793. })
  20794. .orThunk(function () {
  20795. var innerTextNode = walkPastBookmark(innerNode, start)
  20796. .or(innerNode)
  20797. .filter(isText$8)
  20798. return innerTextNode.map(function (inner) {
  20799. return normalizeTextIfRequired(inner, start)
  20800. })
  20801. })
  20802. }
  20803. var rngSetContent = function (rng, fragment) {
  20804. var firstChild = Optional.from(fragment.firstChild).map(
  20805. SugarElement.fromDom
  20806. )
  20807. var lastChild = Optional.from(fragment.lastChild).map(SugarElement.fromDom)
  20808. rng.deleteContents()
  20809. rng.insertNode(fragment)
  20810. var prevText = firstChild
  20811. .bind(prevSibling)
  20812. .filter(isText$8)
  20813. .bind(removeEmpty)
  20814. var nextText = lastChild
  20815. .bind(nextSibling)
  20816. .filter(isText$8)
  20817. .bind(removeEmpty)
  20818. mergeAndNormalizeText(prevText, firstChild, rng, true)
  20819. mergeAndNormalizeText(nextText, lastChild, rng, false)
  20820. rng.collapse(false)
  20821. }
  20822. var setupArgs = function (args, content) {
  20823. return __assign(__assign({ format: 'html' }, args), {
  20824. set: true,
  20825. selection: true,
  20826. content: content,
  20827. })
  20828. }
  20829. var cleanContent = function (editor, args) {
  20830. if (args.format !== 'raw') {
  20831. var rng = editor.selection.getRng()
  20832. var contextBlock = editor.dom.getParent(
  20833. rng.commonAncestorContainer,
  20834. editor.dom.isBlock
  20835. )
  20836. var contextArgs = contextBlock
  20837. ? { context: contextBlock.nodeName.toLowerCase() }
  20838. : {}
  20839. var node = editor.parser.parse(
  20840. args.content,
  20841. __assign(
  20842. __assign(
  20843. {
  20844. isRootContent: true,
  20845. forced_root_block: false,
  20846. },
  20847. contextArgs
  20848. ),
  20849. args
  20850. )
  20851. )
  20852. return HtmlSerializer(
  20853. { validate: editor.validate },
  20854. editor.schema
  20855. ).serialize(node)
  20856. } else {
  20857. return args.content
  20858. }
  20859. }
  20860. var setContent$1 = function (editor, content, args) {
  20861. if (args === void 0) {
  20862. args = {}
  20863. }
  20864. var defaultedArgs = setupArgs(args, content)
  20865. var updatedArgs = defaultedArgs
  20866. if (!defaultedArgs.no_events) {
  20867. var eventArgs = editor.fire('BeforeSetContent', defaultedArgs)
  20868. if (eventArgs.isDefaultPrevented()) {
  20869. editor.fire('SetContent', eventArgs)
  20870. return
  20871. } else {
  20872. updatedArgs = eventArgs
  20873. }
  20874. }
  20875. updatedArgs.content = cleanContent(editor, updatedArgs)
  20876. var rng = editor.selection.getRng()
  20877. rngSetContent(rng, rng.createContextualFragment(updatedArgs.content))
  20878. editor.selection.setRng(rng)
  20879. scrollRangeIntoView(editor, rng)
  20880. if (!updatedArgs.no_events) {
  20881. editor.fire('SetContent', updatedArgs)
  20882. }
  20883. }
  20884. var deleteFromCallbackMap = function (callbackMap, selector, callback) {
  20885. if (callbackMap && has$2(callbackMap, selector)) {
  20886. var newCallbacks = filter$4(callbackMap[selector], function (cb) {
  20887. return cb !== callback
  20888. })
  20889. if (newCallbacks.length === 0) {
  20890. delete callbackMap[selector]
  20891. } else {
  20892. callbackMap[selector] = newCallbacks
  20893. }
  20894. }
  20895. }
  20896. function SelectorChanged(dom, editor) {
  20897. var selectorChangedData
  20898. var currentSelectors
  20899. var findMatchingNode = function (selector, nodes) {
  20900. return find$3(nodes, function (node) {
  20901. return dom.is(node, selector)
  20902. })
  20903. }
  20904. var getParents = function (elem) {
  20905. return dom.getParents(elem, null, dom.getRoot())
  20906. }
  20907. return {
  20908. selectorChangedWithUnbind: function (selector, callback) {
  20909. if (!selectorChangedData) {
  20910. selectorChangedData = {}
  20911. currentSelectors = {}
  20912. editor.on('NodeChange', function (e) {
  20913. var node = e.element
  20914. var parents = getParents(node)
  20915. var matchedSelectors = {}
  20916. Tools.each(selectorChangedData, function (callbacks, selector) {
  20917. findMatchingNode(selector, parents).each(function (node) {
  20918. if (!currentSelectors[selector]) {
  20919. each$k(callbacks, function (callback) {
  20920. callback(true, {
  20921. node: node,
  20922. selector: selector,
  20923. parents: parents,
  20924. })
  20925. })
  20926. currentSelectors[selector] = callbacks
  20927. }
  20928. matchedSelectors[selector] = callbacks
  20929. })
  20930. })
  20931. Tools.each(currentSelectors, function (callbacks, selector) {
  20932. if (!matchedSelectors[selector]) {
  20933. delete currentSelectors[selector]
  20934. Tools.each(callbacks, function (callback) {
  20935. callback(false, {
  20936. node: node,
  20937. selector: selector,
  20938. parents: parents,
  20939. })
  20940. })
  20941. }
  20942. })
  20943. })
  20944. }
  20945. if (!selectorChangedData[selector]) {
  20946. selectorChangedData[selector] = []
  20947. }
  20948. selectorChangedData[selector].push(callback)
  20949. findMatchingNode(
  20950. selector,
  20951. getParents(editor.selection.getStart())
  20952. ).each(function () {
  20953. currentSelectors[selector] = selectorChangedData[selector]
  20954. })
  20955. return {
  20956. unbind: function () {
  20957. deleteFromCallbackMap(selectorChangedData, selector, callback)
  20958. deleteFromCallbackMap(currentSelectors, selector, callback)
  20959. },
  20960. }
  20961. },
  20962. }
  20963. }
  20964. var isNativeIeSelection = function (rng) {
  20965. return !!rng.select
  20966. }
  20967. var isAttachedToDom = function (node) {
  20968. return (
  20969. !!(node && node.ownerDocument) &&
  20970. contains$1(
  20971. SugarElement.fromDom(node.ownerDocument),
  20972. SugarElement.fromDom(node)
  20973. )
  20974. )
  20975. }
  20976. var isValidRange = function (rng) {
  20977. if (!rng) {
  20978. return false
  20979. } else if (isNativeIeSelection(rng)) {
  20980. return true
  20981. } else {
  20982. return (
  20983. isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer)
  20984. )
  20985. }
  20986. }
  20987. var EditorSelection = function (dom, win, serializer, editor) {
  20988. var selectedRange
  20989. var explicitRange
  20990. var selectorChangedWithUnbind = SelectorChanged(
  20991. dom,
  20992. editor
  20993. ).selectorChangedWithUnbind
  20994. var setCursorLocation = function (node, offset) {
  20995. var rng = dom.createRng()
  20996. if (isNonNullable(node) && isNonNullable(offset)) {
  20997. rng.setStart(node, offset)
  20998. rng.setEnd(node, offset)
  20999. setRng(rng)
  21000. collapse(false)
  21001. } else {
  21002. moveEndPoint(dom, rng, editor.getBody(), true)
  21003. setRng(rng)
  21004. }
  21005. }
  21006. var getContent = function (args) {
  21007. return getContent$1(editor, args)
  21008. }
  21009. var setContent = function (content, args) {
  21010. return setContent$1(editor, content, args)
  21011. }
  21012. var getStart$1 = function (real) {
  21013. return getStart(editor.getBody(), getRng$1(), real)
  21014. }
  21015. var getEnd$1 = function (real) {
  21016. return getEnd(editor.getBody(), getRng$1(), real)
  21017. }
  21018. var getBookmark = function (type, normalized) {
  21019. return bookmarkManager.getBookmark(type, normalized)
  21020. }
  21021. var moveToBookmark = function (bookmark) {
  21022. return bookmarkManager.moveToBookmark(bookmark)
  21023. }
  21024. var select$1 = function (node, content) {
  21025. select(dom, node, content).each(setRng)
  21026. return node
  21027. }
  21028. var isCollapsed = function () {
  21029. var rng = getRng$1(),
  21030. sel = getSel()
  21031. if (!rng || rng.item) {
  21032. return false
  21033. }
  21034. if (rng.compareEndPoints) {
  21035. return rng.compareEndPoints('StartToEnd', rng) === 0
  21036. }
  21037. return !sel || rng.collapsed
  21038. }
  21039. var collapse = function (toStart) {
  21040. var rng = getRng$1()
  21041. rng.collapse(!!toStart)
  21042. setRng(rng)
  21043. }
  21044. var getSel = function () {
  21045. return win.getSelection ? win.getSelection() : win.document.selection
  21046. }
  21047. var getRng$1 = function () {
  21048. var selection, rng, elm
  21049. var tryCompareBoundaryPoints = function (
  21050. how,
  21051. sourceRange,
  21052. destinationRange
  21053. ) {
  21054. try {
  21055. return sourceRange.compareBoundaryPoints(how, destinationRange)
  21056. } catch (ex) {
  21057. return -1
  21058. }
  21059. }
  21060. var doc = win.document
  21061. if (editor.bookmark !== undefined && hasFocus(editor) === false) {
  21062. var bookmark = getRng(editor)
  21063. if (bookmark.isSome()) {
  21064. return bookmark
  21065. .map(function (r) {
  21066. return processRanges(editor, [r])[0]
  21067. })
  21068. .getOr(doc.createRange())
  21069. }
  21070. }
  21071. try {
  21072. if ((selection = getSel()) && !isRestrictedNode(selection.anchorNode)) {
  21073. if (selection.rangeCount > 0) {
  21074. rng = selection.getRangeAt(0)
  21075. } else {
  21076. rng = selection.createRange
  21077. ? selection.createRange()
  21078. : doc.createRange()
  21079. }
  21080. rng = processRanges(editor, [rng])[0]
  21081. }
  21082. } catch (ex) {}
  21083. if (!rng) {
  21084. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange()
  21085. }
  21086. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  21087. elm = dom.getRoot()
  21088. rng.setStart(elm, 0)
  21089. rng.setEnd(elm, 0)
  21090. }
  21091. if (selectedRange && explicitRange) {
  21092. if (
  21093. tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) ===
  21094. 0 &&
  21095. tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0
  21096. ) {
  21097. rng = explicitRange
  21098. } else {
  21099. selectedRange = null
  21100. explicitRange = null
  21101. }
  21102. }
  21103. return rng
  21104. }
  21105. var setRng = function (rng, forward) {
  21106. var node
  21107. if (!isValidRange(rng)) {
  21108. return
  21109. }
  21110. var ieRange = isNativeIeSelection(rng) ? rng : null
  21111. if (ieRange) {
  21112. explicitRange = null
  21113. try {
  21114. ieRange.select()
  21115. } catch (ex) {}
  21116. return
  21117. }
  21118. var sel = getSel()
  21119. var evt = editor.fire('SetSelectionRange', {
  21120. range: rng,
  21121. forward: forward,
  21122. })
  21123. rng = evt.range
  21124. if (sel) {
  21125. explicitRange = rng
  21126. try {
  21127. sel.removeAllRanges()
  21128. sel.addRange(rng)
  21129. } catch (ex) {}
  21130. if (forward === false && sel.extend) {
  21131. sel.collapse(rng.endContainer, rng.endOffset)
  21132. sel.extend(rng.startContainer, rng.startOffset)
  21133. }
  21134. selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null
  21135. }
  21136. if (
  21137. !rng.collapsed &&
  21138. rng.startContainer === rng.endContainer &&
  21139. sel.setBaseAndExtent &&
  21140. !Env.ie
  21141. ) {
  21142. if (rng.endOffset - rng.startOffset < 2) {
  21143. if (rng.startContainer.hasChildNodes()) {
  21144. node = rng.startContainer.childNodes[rng.startOffset]
  21145. if (node && node.tagName === 'IMG') {
  21146. sel.setBaseAndExtent(
  21147. rng.startContainer,
  21148. rng.startOffset,
  21149. rng.endContainer,
  21150. rng.endOffset
  21151. )
  21152. if (
  21153. sel.anchorNode !== rng.startContainer ||
  21154. sel.focusNode !== rng.endContainer
  21155. ) {
  21156. sel.setBaseAndExtent(node, 0, node, 1)
  21157. }
  21158. }
  21159. }
  21160. }
  21161. }
  21162. editor.fire('AfterSetSelectionRange', {
  21163. range: rng,
  21164. forward: forward,
  21165. })
  21166. }
  21167. var setNode = function (elm) {
  21168. setContent(dom.getOuterHTML(elm))
  21169. return elm
  21170. }
  21171. var getNode$1 = function () {
  21172. return getNode(editor.getBody(), getRng$1())
  21173. }
  21174. var getSelectedBlocks$1 = function (startElm, endElm) {
  21175. return getSelectedBlocks(dom, getRng$1(), startElm, endElm)
  21176. }
  21177. var isForward = function () {
  21178. var sel = getSel()
  21179. var anchorNode = sel === null || sel === void 0 ? void 0 : sel.anchorNode
  21180. var focusNode = sel === null || sel === void 0 ? void 0 : sel.focusNode
  21181. if (
  21182. !sel ||
  21183. !anchorNode ||
  21184. !focusNode ||
  21185. isRestrictedNode(anchorNode) ||
  21186. isRestrictedNode(focusNode)
  21187. ) {
  21188. return true
  21189. }
  21190. var anchorRange = dom.createRng()
  21191. anchorRange.setStart(anchorNode, sel.anchorOffset)
  21192. anchorRange.collapse(true)
  21193. var focusRange = dom.createRng()
  21194. focusRange.setStart(focusNode, sel.focusOffset)
  21195. focusRange.collapse(true)
  21196. return (
  21197. anchorRange.compareBoundaryPoints(
  21198. anchorRange.START_TO_START,
  21199. focusRange
  21200. ) <= 0
  21201. )
  21202. }
  21203. var normalize = function () {
  21204. var rng = getRng$1()
  21205. var sel = getSel()
  21206. if (!hasMultipleRanges(sel) && hasAnyRanges(editor)) {
  21207. var normRng = normalize$2(dom, rng)
  21208. normRng.each(function (normRng) {
  21209. setRng(normRng, isForward())
  21210. })
  21211. return normRng.getOr(rng)
  21212. }
  21213. return rng
  21214. }
  21215. var selectorChanged = function (selector, callback) {
  21216. selectorChangedWithUnbind(selector, callback)
  21217. return exports
  21218. }
  21219. var getScrollContainer = function () {
  21220. var scrollContainer
  21221. var node = dom.getRoot()
  21222. while (node && node.nodeName !== 'BODY') {
  21223. if (node.scrollHeight > node.clientHeight) {
  21224. scrollContainer = node
  21225. break
  21226. }
  21227. node = node.parentNode
  21228. }
  21229. return scrollContainer
  21230. }
  21231. var scrollIntoView = function (elm, alignToTop) {
  21232. if (isNonNullable(elm)) {
  21233. scrollElementIntoView(editor, elm, alignToTop)
  21234. } else {
  21235. scrollRangeIntoView(editor, getRng$1(), alignToTop)
  21236. }
  21237. }
  21238. var placeCaretAt = function (clientX, clientY) {
  21239. return setRng(fromPoint(clientX, clientY, editor.getDoc()))
  21240. }
  21241. var getBoundingClientRect = function () {
  21242. var rng = getRng$1()
  21243. return rng.collapsed
  21244. ? CaretPosition.fromRangeStart(rng).getClientRects()[0]
  21245. : rng.getBoundingClientRect()
  21246. }
  21247. var destroy = function () {
  21248. win = selectedRange = explicitRange = null
  21249. controlSelection.destroy()
  21250. }
  21251. var exports = {
  21252. bookmarkManager: null,
  21253. controlSelection: null,
  21254. dom: dom,
  21255. win: win,
  21256. serializer: serializer,
  21257. editor: editor,
  21258. collapse: collapse,
  21259. setCursorLocation: setCursorLocation,
  21260. getContent: getContent,
  21261. setContent: setContent,
  21262. getBookmark: getBookmark,
  21263. moveToBookmark: moveToBookmark,
  21264. select: select$1,
  21265. isCollapsed: isCollapsed,
  21266. isForward: isForward,
  21267. setNode: setNode,
  21268. getNode: getNode$1,
  21269. getSel: getSel,
  21270. setRng: setRng,
  21271. getRng: getRng$1,
  21272. getStart: getStart$1,
  21273. getEnd: getEnd$1,
  21274. getSelectedBlocks: getSelectedBlocks$1,
  21275. normalize: normalize,
  21276. selectorChanged: selectorChanged,
  21277. selectorChangedWithUnbind: selectorChangedWithUnbind,
  21278. getScrollContainer: getScrollContainer,
  21279. scrollIntoView: scrollIntoView,
  21280. placeCaretAt: placeCaretAt,
  21281. getBoundingClientRect: getBoundingClientRect,
  21282. destroy: destroy,
  21283. }
  21284. var bookmarkManager = BookmarkManager(exports)
  21285. var controlSelection = ControlSelection(exports, editor)
  21286. exports.bookmarkManager = bookmarkManager
  21287. exports.controlSelection = controlSelection
  21288. return exports
  21289. }
  21290. var removeAttrs = function (node, names) {
  21291. each$k(names, function (name) {
  21292. node.attr(name, null)
  21293. })
  21294. }
  21295. var addFontToSpansFilter = function (domParser, styles, fontSizes) {
  21296. domParser.addNodeFilter('font', function (nodes) {
  21297. each$k(nodes, function (node) {
  21298. var props = styles.parse(node.attr('style'))
  21299. var color = node.attr('color')
  21300. var face = node.attr('face')
  21301. var size = node.attr('size')
  21302. if (color) {
  21303. props.color = color
  21304. }
  21305. if (face) {
  21306. props['font-family'] = face
  21307. }
  21308. if (size) {
  21309. props['font-size'] = fontSizes[parseInt(node.attr('size'), 10) - 1]
  21310. }
  21311. node.name = 'span'
  21312. node.attr('style', styles.serialize(props))
  21313. removeAttrs(node, ['color', 'face', 'size'])
  21314. })
  21315. })
  21316. }
  21317. var addStrikeToSpanFilter = function (domParser, styles) {
  21318. domParser.addNodeFilter('strike', function (nodes) {
  21319. each$k(nodes, function (node) {
  21320. var props = styles.parse(node.attr('style'))
  21321. props['text-decoration'] = 'line-through'
  21322. node.name = 'span'
  21323. node.attr('style', styles.serialize(props))
  21324. })
  21325. })
  21326. }
  21327. var addFilters = function (domParser, settings) {
  21328. var styles = Styles()
  21329. if (settings.convert_fonts_to_spans) {
  21330. addFontToSpansFilter(
  21331. domParser,
  21332. styles,
  21333. Tools.explode(settings.font_size_legacy_values)
  21334. )
  21335. }
  21336. addStrikeToSpanFilter(domParser, styles)
  21337. }
  21338. var register$2 = function (domParser, settings) {
  21339. if (settings.inline_styles) {
  21340. addFilters(domParser, settings)
  21341. }
  21342. }
  21343. var blobUriToBlob = function (url) {
  21344. return new promiseObj(function (resolve, reject) {
  21345. var rejectWithError = function () {
  21346. reject(
  21347. 'Cannot convert ' +
  21348. url +
  21349. ' to Blob. Resource might not exist or is inaccessible.'
  21350. )
  21351. }
  21352. try {
  21353. var xhr_1 = new XMLHttpRequest()
  21354. xhr_1.open('GET', url, true)
  21355. xhr_1.responseType = 'blob'
  21356. xhr_1.onload = function () {
  21357. if (xhr_1.status === 200) {
  21358. resolve(xhr_1.response)
  21359. } else {
  21360. rejectWithError()
  21361. }
  21362. }
  21363. xhr_1.onerror = rejectWithError
  21364. xhr_1.send()
  21365. } catch (ex) {
  21366. rejectWithError()
  21367. }
  21368. })
  21369. }
  21370. var parseDataUri = function (uri) {
  21371. var type
  21372. var uriParts = decodeURIComponent(uri).split(',')
  21373. var matches = /data:([^;]+)/.exec(uriParts[0])
  21374. if (matches) {
  21375. type = matches[1]
  21376. }
  21377. return {
  21378. type: type,
  21379. data: uriParts[1],
  21380. }
  21381. }
  21382. var buildBlob = function (type, data) {
  21383. var str
  21384. try {
  21385. str = atob(data)
  21386. } catch (e) {
  21387. return Optional.none()
  21388. }
  21389. var arr = new Uint8Array(str.length)
  21390. for (var i = 0; i < arr.length; i++) {
  21391. arr[i] = str.charCodeAt(i)
  21392. }
  21393. return Optional.some(new Blob([arr], { type: type }))
  21394. }
  21395. var dataUriToBlob = function (uri) {
  21396. return new promiseObj(function (resolve) {
  21397. var _a = parseDataUri(uri),
  21398. type = _a.type,
  21399. data = _a.data
  21400. buildBlob(type, data).fold(function () {
  21401. return resolve(new Blob([]))
  21402. }, resolve)
  21403. })
  21404. }
  21405. var uriToBlob = function (url) {
  21406. if (url.indexOf('blob:') === 0) {
  21407. return blobUriToBlob(url)
  21408. }
  21409. if (url.indexOf('data:') === 0) {
  21410. return dataUriToBlob(url)
  21411. }
  21412. return null
  21413. }
  21414. var blobToDataUri = function (blob) {
  21415. return new promiseObj(function (resolve) {
  21416. var reader = new FileReader()
  21417. reader.onloadend = function () {
  21418. resolve(reader.result)
  21419. }
  21420. reader.readAsDataURL(blob)
  21421. })
  21422. }
  21423. var count$1 = 0
  21424. var uniqueId = function (prefix) {
  21425. return (prefix || 'blobid') + count$1++
  21426. }
  21427. var imageToBlobInfo = function (blobCache, img, resolve, reject) {
  21428. var base64, blobInfo
  21429. if (img.src.indexOf('blob:') === 0) {
  21430. blobInfo = blobCache.getByUri(img.src)
  21431. if (blobInfo) {
  21432. resolve({
  21433. image: img,
  21434. blobInfo: blobInfo,
  21435. })
  21436. } else {
  21437. uriToBlob(img.src).then(
  21438. function (blob) {
  21439. blobToDataUri(blob).then(function (dataUri) {
  21440. base64 = parseDataUri(dataUri).data
  21441. blobInfo = blobCache.create(uniqueId(), blob, base64)
  21442. blobCache.add(blobInfo)
  21443. resolve({
  21444. image: img,
  21445. blobInfo: blobInfo,
  21446. })
  21447. })
  21448. },
  21449. function (err) {
  21450. reject(err)
  21451. }
  21452. )
  21453. }
  21454. return
  21455. }
  21456. var _a = parseDataUri(img.src),
  21457. data = _a.data,
  21458. type = _a.type
  21459. base64 = data
  21460. blobInfo = blobCache.getByData(base64, type)
  21461. if (blobInfo) {
  21462. resolve({
  21463. image: img,
  21464. blobInfo: blobInfo,
  21465. })
  21466. } else {
  21467. uriToBlob(img.src).then(
  21468. function (blob) {
  21469. blobInfo = blobCache.create(uniqueId(), blob, base64)
  21470. blobCache.add(blobInfo)
  21471. resolve({
  21472. image: img,
  21473. blobInfo: blobInfo,
  21474. })
  21475. },
  21476. function (err) {
  21477. reject(err)
  21478. }
  21479. )
  21480. }
  21481. }
  21482. var getAllImages = function (elm) {
  21483. return elm ? from(elm.getElementsByTagName('img')) : []
  21484. }
  21485. var ImageScanner = function (uploadStatus, blobCache) {
  21486. var cachedPromises = {}
  21487. var findAll = function (elm, predicate) {
  21488. if (!predicate) {
  21489. predicate = always
  21490. }
  21491. var images = filter$4(getAllImages(elm), function (img) {
  21492. var src = img.src
  21493. if (!Env.fileApi) {
  21494. return false
  21495. }
  21496. if (img.hasAttribute('data-mce-bogus')) {
  21497. return false
  21498. }
  21499. if (img.hasAttribute('data-mce-placeholder')) {
  21500. return false
  21501. }
  21502. if (!src || src === Env.transparentSrc) {
  21503. return false
  21504. }
  21505. if (src.indexOf('blob:') === 0) {
  21506. return !uploadStatus.isUploaded(src) && predicate(img)
  21507. }
  21508. if (src.indexOf('data:') === 0) {
  21509. return predicate(img)
  21510. }
  21511. return false
  21512. })
  21513. var promises = map$3(images, function (img) {
  21514. if (cachedPromises[img.src] !== undefined) {
  21515. return new promiseObj(function (resolve) {
  21516. cachedPromises[img.src].then(function (imageInfo) {
  21517. if (typeof imageInfo === 'string') {
  21518. return imageInfo
  21519. }
  21520. resolve({
  21521. image: img,
  21522. blobInfo: imageInfo.blobInfo,
  21523. })
  21524. })
  21525. })
  21526. }
  21527. var newPromise = new promiseObj(function (resolve, reject) {
  21528. imageToBlobInfo(blobCache, img, resolve, reject)
  21529. })
  21530. .then(function (result) {
  21531. delete cachedPromises[result.image.src]
  21532. return result
  21533. })
  21534. .catch(function (error) {
  21535. delete cachedPromises[img.src]
  21536. return error
  21537. })
  21538. cachedPromises[img.src] = newPromise
  21539. return newPromise
  21540. })
  21541. return promiseObj.all(promises)
  21542. }
  21543. return { findAll: findAll }
  21544. }
  21545. var paddEmptyNode = function (settings, args, blockElements, node) {
  21546. var brPreferred = settings.padd_empty_with_br || args.insert
  21547. if (brPreferred && blockElements[node.name]) {
  21548. node.empty().append(new AstNode('br', 1)).shortEnded = true
  21549. } else {
  21550. node.empty().append(new AstNode('#text', 3)).value = nbsp
  21551. }
  21552. }
  21553. var isPaddedWithNbsp = function (node) {
  21554. return hasOnlyChild(node, '#text') && node.firstChild.value === nbsp
  21555. }
  21556. var hasOnlyChild = function (node, name) {
  21557. return (
  21558. node &&
  21559. node.firstChild &&
  21560. node.firstChild === node.lastChild &&
  21561. node.firstChild.name === name
  21562. )
  21563. }
  21564. var isPadded = function (schema, node) {
  21565. var rule = schema.getElementRule(node.name)
  21566. return rule && rule.paddEmpty
  21567. }
  21568. var isEmpty = function (schema, nonEmptyElements, whitespaceElements, node) {
  21569. return node.isEmpty(nonEmptyElements, whitespaceElements, function (node) {
  21570. return isPadded(schema, node)
  21571. })
  21572. }
  21573. var isLineBreakNode = function (node, blockElements) {
  21574. return node && (has$2(blockElements, node.name) || node.name === 'br')
  21575. }
  21576. var isBogusImage = function (img) {
  21577. return isNonNullable(img.attr('data-mce-bogus'))
  21578. }
  21579. var isInternalImageSource = function (img) {
  21580. return (
  21581. img.attr('src') === Env.transparentSrc ||
  21582. isNonNullable(img.attr('data-mce-placeholder'))
  21583. )
  21584. }
  21585. var isValidDataImg = function (img, settings) {
  21586. if (settings.images_dataimg_filter) {
  21587. var imgElem_1 = new Image()
  21588. imgElem_1.src = img.attr('src')
  21589. each$j(img.attributes.map, function (value, key) {
  21590. imgElem_1.setAttribute(key, value)
  21591. })
  21592. return settings.images_dataimg_filter(imgElem_1)
  21593. } else {
  21594. return true
  21595. }
  21596. }
  21597. var registerBase64ImageFilter = function (parser, settings) {
  21598. var blobCache = settings.blob_cache
  21599. var processImage = function (img) {
  21600. var inputSrc = img.attr('src')
  21601. if (isInternalImageSource(img) || isBogusImage(img)) {
  21602. return
  21603. }
  21604. parseDataUri$1(inputSrc)
  21605. .filter(function () {
  21606. return isValidDataImg(img, settings)
  21607. })
  21608. .bind(function (_a) {
  21609. var type = _a.type,
  21610. data = _a.data
  21611. return Optional.from(blobCache.getByData(data, type)).orThunk(
  21612. function () {
  21613. return buildBlob(type, data).map(function (blob) {
  21614. var blobInfo = blobCache.create(uniqueId(), blob, data)
  21615. blobCache.add(blobInfo)
  21616. return blobInfo
  21617. })
  21618. }
  21619. )
  21620. })
  21621. .each(function (blobInfo) {
  21622. img.attr('src', blobInfo.blobUri())
  21623. })
  21624. }
  21625. if (blobCache) {
  21626. parser.addAttributeFilter('src', function (nodes) {
  21627. return each$k(nodes, processImage)
  21628. })
  21629. }
  21630. }
  21631. var register$1 = function (parser, settings) {
  21632. var schema = parser.schema
  21633. if (settings.remove_trailing_brs) {
  21634. parser.addNodeFilter('br', function (nodes, _, args) {
  21635. var i
  21636. var l = nodes.length
  21637. var node
  21638. var blockElements = Tools.extend({}, schema.getBlockElements())
  21639. var nonEmptyElements = schema.getNonEmptyElements()
  21640. var parent, lastParent, prev, prevName
  21641. var whiteSpaceElements = schema.getWhiteSpaceElements()
  21642. var elementRule, textNode
  21643. blockElements.body = 1
  21644. for (i = 0; i < l; i++) {
  21645. node = nodes[i]
  21646. parent = node.parent
  21647. if (blockElements[node.parent.name] && node === parent.lastChild) {
  21648. prev = node.prev
  21649. while (prev) {
  21650. prevName = prev.name
  21651. if (
  21652. prevName !== 'span' ||
  21653. prev.attr('data-mce-type') !== 'bookmark'
  21654. ) {
  21655. if (prevName === 'br') {
  21656. node = null
  21657. }
  21658. break
  21659. }
  21660. prev = prev.prev
  21661. }
  21662. if (node) {
  21663. node.remove()
  21664. if (
  21665. isEmpty(schema, nonEmptyElements, whiteSpaceElements, parent)
  21666. ) {
  21667. elementRule = schema.getElementRule(parent.name)
  21668. if (elementRule) {
  21669. if (elementRule.removeEmpty) {
  21670. parent.remove()
  21671. } else if (elementRule.paddEmpty) {
  21672. paddEmptyNode(settings, args, blockElements, parent)
  21673. }
  21674. }
  21675. }
  21676. }
  21677. } else {
  21678. lastParent = node
  21679. while (
  21680. parent &&
  21681. parent.firstChild === lastParent &&
  21682. parent.lastChild === lastParent
  21683. ) {
  21684. lastParent = parent
  21685. if (blockElements[parent.name]) {
  21686. break
  21687. }
  21688. parent = parent.parent
  21689. }
  21690. if (lastParent === parent && settings.padd_empty_with_br !== true) {
  21691. textNode = new AstNode('#text', 3)
  21692. textNode.value = nbsp
  21693. node.replace(textNode)
  21694. }
  21695. }
  21696. }
  21697. })
  21698. }
  21699. parser.addAttributeFilter('href', function (nodes) {
  21700. var i = nodes.length
  21701. var appendRel = function (rel) {
  21702. var parts = rel.split(' ').filter(function (p) {
  21703. return p.length > 0
  21704. })
  21705. return parts.concat(['noopener']).sort().join(' ')
  21706. }
  21707. var addNoOpener = function (rel) {
  21708. var newRel = rel ? Tools.trim(rel) : ''
  21709. if (!/\b(noopener)\b/g.test(newRel)) {
  21710. return appendRel(newRel)
  21711. } else {
  21712. return newRel
  21713. }
  21714. }
  21715. if (!settings.allow_unsafe_link_target) {
  21716. while (i--) {
  21717. var node = nodes[i]
  21718. if (node.name === 'a' && node.attr('target') === '_blank') {
  21719. node.attr('rel', addNoOpener(node.attr('rel')))
  21720. }
  21721. }
  21722. }
  21723. })
  21724. if (!settings.allow_html_in_named_anchor) {
  21725. parser.addAttributeFilter('id,name', function (nodes) {
  21726. var i = nodes.length,
  21727. sibling,
  21728. prevSibling,
  21729. parent,
  21730. node
  21731. while (i--) {
  21732. node = nodes[i]
  21733. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  21734. parent = node.parent
  21735. sibling = node.lastChild
  21736. do {
  21737. prevSibling = sibling.prev
  21738. parent.insert(sibling, node)
  21739. sibling = prevSibling
  21740. } while (sibling)
  21741. }
  21742. }
  21743. })
  21744. }
  21745. if (settings.fix_list_elements) {
  21746. parser.addNodeFilter('ul,ol', function (nodes) {
  21747. var i = nodes.length,
  21748. node,
  21749. parentNode
  21750. while (i--) {
  21751. node = nodes[i]
  21752. parentNode = node.parent
  21753. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  21754. if (node.prev && node.prev.name === 'li') {
  21755. node.prev.append(node)
  21756. } else {
  21757. var li = new AstNode('li', 1)
  21758. li.attr('style', 'list-style-type: none')
  21759. node.wrap(li)
  21760. }
  21761. }
  21762. }
  21763. })
  21764. }
  21765. if (settings.validate && schema.getValidClasses()) {
  21766. parser.addAttributeFilter('class', function (nodes) {
  21767. var validClasses = schema.getValidClasses()
  21768. var i = nodes.length
  21769. while (i--) {
  21770. var node = nodes[i]
  21771. var classList = node.attr('class').split(' ')
  21772. var classValue = ''
  21773. for (var ci = 0; ci < classList.length; ci++) {
  21774. var className = classList[ci]
  21775. var valid = false
  21776. var validClassesMap = validClasses['*']
  21777. if (validClassesMap && validClassesMap[className]) {
  21778. valid = true
  21779. }
  21780. validClassesMap = validClasses[node.name]
  21781. if (!valid && validClassesMap && validClassesMap[className]) {
  21782. valid = true
  21783. }
  21784. if (valid) {
  21785. if (classValue) {
  21786. classValue += ' '
  21787. }
  21788. classValue += className
  21789. }
  21790. }
  21791. if (!classValue.length) {
  21792. classValue = null
  21793. }
  21794. node.attr('class', classValue)
  21795. }
  21796. })
  21797. }
  21798. registerBase64ImageFilter(parser, settings)
  21799. }
  21800. var makeMap = Tools.makeMap,
  21801. each$6 = Tools.each,
  21802. explode$2 = Tools.explode,
  21803. extend$4 = Tools.extend
  21804. var DomParser = function (settings, schema) {
  21805. if (schema === void 0) {
  21806. schema = Schema()
  21807. }
  21808. var nodeFilters = {}
  21809. var attributeFilters = []
  21810. var matchedNodes = {}
  21811. var matchedAttributes = {}
  21812. settings = settings || {}
  21813. settings.validate = 'validate' in settings ? settings.validate : true
  21814. settings.root_name = settings.root_name || 'body'
  21815. var fixInvalidChildren = function (nodes) {
  21816. var nonSplitableElements = makeMap('tr,td,th,tbody,thead,tfoot,table')
  21817. var nonEmptyElements = schema.getNonEmptyElements()
  21818. var whitespaceElements = schema.getWhiteSpaceElements()
  21819. var textBlockElements = schema.getTextBlockElements()
  21820. var specialElements = schema.getSpecialElements()
  21821. var removeOrUnwrapInvalidNode = function (node, originalNodeParent) {
  21822. if (originalNodeParent === void 0) {
  21823. originalNodeParent = node.parent
  21824. }
  21825. if (specialElements[node.name]) {
  21826. node.empty().remove()
  21827. } else {
  21828. var children = node.children()
  21829. for (
  21830. var _i = 0, children_1 = children;
  21831. _i < children_1.length;
  21832. _i++
  21833. ) {
  21834. var childNode = children_1[_i]
  21835. if (!schema.isValidChild(originalNodeParent.name, childNode.name)) {
  21836. removeOrUnwrapInvalidNode(childNode, originalNodeParent)
  21837. }
  21838. }
  21839. node.unwrap()
  21840. }
  21841. }
  21842. for (var ni = 0; ni < nodes.length; ni++) {
  21843. var node = nodes[ni]
  21844. var parent_1 = void 0,
  21845. newParent = void 0,
  21846. tempNode = void 0
  21847. if (!node.parent || node.fixed) {
  21848. continue
  21849. }
  21850. if (textBlockElements[node.name] && node.parent.name === 'li') {
  21851. var sibling = node.next
  21852. while (sibling) {
  21853. if (textBlockElements[sibling.name]) {
  21854. sibling.name = 'li'
  21855. sibling.fixed = true
  21856. node.parent.insert(sibling, node.parent)
  21857. } else {
  21858. break
  21859. }
  21860. sibling = sibling.next
  21861. }
  21862. node.unwrap()
  21863. continue
  21864. }
  21865. var parents = [node]
  21866. for (
  21867. parent_1 = node.parent;
  21868. parent_1 &&
  21869. !schema.isValidChild(parent_1.name, node.name) &&
  21870. !nonSplitableElements[parent_1.name];
  21871. parent_1 = parent_1.parent
  21872. ) {
  21873. parents.push(parent_1)
  21874. }
  21875. if (parent_1 && parents.length > 1) {
  21876. if (schema.isValidChild(parent_1.name, node.name)) {
  21877. parents.reverse()
  21878. newParent = filterNode(parents[0].clone())
  21879. var currentNode = newParent
  21880. for (var i = 0; i < parents.length - 1; i++) {
  21881. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  21882. tempNode = filterNode(parents[i].clone())
  21883. currentNode.append(tempNode)
  21884. } else {
  21885. tempNode = currentNode
  21886. }
  21887. for (
  21888. var childNode = parents[i].firstChild;
  21889. childNode && childNode !== parents[i + 1];
  21890. ) {
  21891. var nextNode = childNode.next
  21892. tempNode.append(childNode)
  21893. childNode = nextNode
  21894. }
  21895. currentNode = tempNode
  21896. }
  21897. if (
  21898. !isEmpty(schema, nonEmptyElements, whitespaceElements, newParent)
  21899. ) {
  21900. parent_1.insert(newParent, parents[0], true)
  21901. parent_1.insert(node, newParent)
  21902. } else {
  21903. parent_1.insert(node, parents[0], true)
  21904. }
  21905. parent_1 = parents[0]
  21906. if (
  21907. isEmpty(schema, nonEmptyElements, whitespaceElements, parent_1) ||
  21908. hasOnlyChild(parent_1, 'br')
  21909. ) {
  21910. parent_1.empty().remove()
  21911. }
  21912. } else {
  21913. removeOrUnwrapInvalidNode(node)
  21914. }
  21915. } else if (node.parent) {
  21916. if (node.name === 'li') {
  21917. var sibling = node.prev
  21918. if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {
  21919. sibling.append(node)
  21920. continue
  21921. }
  21922. sibling = node.next
  21923. if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {
  21924. sibling.insert(node, sibling.firstChild, true)
  21925. continue
  21926. }
  21927. node.wrap(filterNode(new AstNode('ul', 1)))
  21928. continue
  21929. }
  21930. if (
  21931. schema.isValidChild(node.parent.name, 'div') &&
  21932. schema.isValidChild('div', node.name)
  21933. ) {
  21934. node.wrap(filterNode(new AstNode('div', 1)))
  21935. } else {
  21936. removeOrUnwrapInvalidNode(node)
  21937. }
  21938. }
  21939. }
  21940. }
  21941. var filterNode = function (node) {
  21942. var name = node.name
  21943. if (name in nodeFilters) {
  21944. var list = matchedNodes[name]
  21945. if (list) {
  21946. list.push(node)
  21947. } else {
  21948. matchedNodes[name] = [node]
  21949. }
  21950. }
  21951. var i = attributeFilters.length
  21952. while (i--) {
  21953. var attrName = attributeFilters[i].name
  21954. if (attrName in node.attributes.map) {
  21955. var list = matchedAttributes[attrName]
  21956. if (list) {
  21957. list.push(node)
  21958. } else {
  21959. matchedAttributes[attrName] = [node]
  21960. }
  21961. }
  21962. }
  21963. return node
  21964. }
  21965. var addNodeFilter = function (name, callback) {
  21966. each$6(explode$2(name), function (name) {
  21967. var list = nodeFilters[name]
  21968. if (!list) {
  21969. nodeFilters[name] = list = []
  21970. }
  21971. list.push(callback)
  21972. })
  21973. }
  21974. var getNodeFilters = function () {
  21975. var out = []
  21976. for (var name_1 in nodeFilters) {
  21977. if (has$2(nodeFilters, name_1)) {
  21978. out.push({
  21979. name: name_1,
  21980. callbacks: nodeFilters[name_1],
  21981. })
  21982. }
  21983. }
  21984. return out
  21985. }
  21986. var addAttributeFilter = function (name, callback) {
  21987. each$6(explode$2(name), function (name) {
  21988. var i
  21989. for (i = 0; i < attributeFilters.length; i++) {
  21990. if (attributeFilters[i].name === name) {
  21991. attributeFilters[i].callbacks.push(callback)
  21992. return
  21993. }
  21994. }
  21995. attributeFilters.push({
  21996. name: name,
  21997. callbacks: [callback],
  21998. })
  21999. })
  22000. }
  22001. var getAttributeFilters = function () {
  22002. return [].concat(attributeFilters)
  22003. }
  22004. var parse = function (html, args) {
  22005. var nodes, i, l, fi, fl, list, name
  22006. var invalidChildren = []
  22007. var node
  22008. var getRootBlockName = function (name) {
  22009. if (name === false) {
  22010. return ''
  22011. } else if (name === true) {
  22012. return 'p'
  22013. } else {
  22014. return name
  22015. }
  22016. }
  22017. args = args || {}
  22018. matchedNodes = {}
  22019. matchedAttributes = {}
  22020. var blockElements = extend$4(
  22021. makeMap('script,style,head,html,body,title,meta,param'),
  22022. schema.getBlockElements()
  22023. )
  22024. var nonEmptyElements = schema.getNonEmptyElements()
  22025. var children = schema.children
  22026. var validate = settings.validate
  22027. var forcedRootBlockName =
  22028. 'forced_root_block' in args
  22029. ? args.forced_root_block
  22030. : settings.forced_root_block
  22031. var rootBlockName = getRootBlockName(forcedRootBlockName)
  22032. var whiteSpaceElements = schema.getWhiteSpaceElements()
  22033. var startWhiteSpaceRegExp = /^[ \t\r\n]+/
  22034. var endWhiteSpaceRegExp = /[ \t\r\n]+$/
  22035. var allWhiteSpaceRegExp = /[ \t\r\n]+/g
  22036. var isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/
  22037. var isInWhiteSpacePreservedElement =
  22038. has$2(whiteSpaceElements, args.context) ||
  22039. has$2(whiteSpaceElements, settings.root_name)
  22040. var addRootBlocks = function () {
  22041. var node = rootNode.firstChild,
  22042. rootBlockNode = null
  22043. var trim = function (rootBlock) {
  22044. if (rootBlock) {
  22045. node = rootBlock.firstChild
  22046. if (node && node.type === 3) {
  22047. node.value = node.value.replace(startWhiteSpaceRegExp, '')
  22048. }
  22049. node = rootBlock.lastChild
  22050. if (node && node.type === 3) {
  22051. node.value = node.value.replace(endWhiteSpaceRegExp, '')
  22052. }
  22053. }
  22054. }
  22055. if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
  22056. return
  22057. }
  22058. while (node) {
  22059. var next = node.next
  22060. if (
  22061. node.type === 3 ||
  22062. (node.type === 1 &&
  22063. node.name !== 'p' &&
  22064. !blockElements[node.name] &&
  22065. !node.attr('data-mce-type'))
  22066. ) {
  22067. if (!rootBlockNode) {
  22068. rootBlockNode = createNode(rootBlockName, 1)
  22069. rootBlockNode.attr(settings.forced_root_block_attrs)
  22070. rootNode.insert(rootBlockNode, node)
  22071. rootBlockNode.append(node)
  22072. } else {
  22073. rootBlockNode.append(node)
  22074. }
  22075. } else {
  22076. trim(rootBlockNode)
  22077. rootBlockNode = null
  22078. }
  22079. node = next
  22080. }
  22081. trim(rootBlockNode)
  22082. }
  22083. var createNode = function (name, type) {
  22084. var node = new AstNode(name, type)
  22085. var list
  22086. if (name in nodeFilters) {
  22087. list = matchedNodes[name]
  22088. if (list) {
  22089. list.push(node)
  22090. } else {
  22091. matchedNodes[name] = [node]
  22092. }
  22093. }
  22094. return node
  22095. }
  22096. var removeWhitespaceBefore = function (node) {
  22097. var blockElements = schema.getBlockElements()
  22098. for (var textNode = node.prev; textNode && textNode.type === 3; ) {
  22099. var textVal = textNode.value.replace(endWhiteSpaceRegExp, '')
  22100. if (textVal.length > 0) {
  22101. textNode.value = textVal
  22102. return
  22103. }
  22104. var textNodeNext = textNode.next
  22105. if (textNodeNext) {
  22106. if (textNodeNext.type === 3 && textNodeNext.value.length) {
  22107. textNode = textNode.prev
  22108. continue
  22109. }
  22110. if (
  22111. !blockElements[textNodeNext.name] &&
  22112. textNodeNext.name !== 'script' &&
  22113. textNodeNext.name !== 'style'
  22114. ) {
  22115. textNode = textNode.prev
  22116. continue
  22117. }
  22118. }
  22119. var sibling = textNode.prev
  22120. textNode.remove()
  22121. textNode = sibling
  22122. }
  22123. }
  22124. var cloneAndExcludeBlocks = function (input) {
  22125. var output = {}
  22126. for (var name_2 in input) {
  22127. if (name_2 !== 'li' && name_2 !== 'p') {
  22128. output[name_2] = input[name_2]
  22129. }
  22130. }
  22131. return output
  22132. }
  22133. var parser = SaxParser(
  22134. {
  22135. validate: validate,
  22136. document: settings.document,
  22137. allow_html_data_urls: settings.allow_html_data_urls,
  22138. allow_svg_data_urls: settings.allow_svg_data_urls,
  22139. allow_script_urls: settings.allow_script_urls,
  22140. allow_conditional_comments: settings.allow_conditional_comments,
  22141. preserve_cdata: settings.preserve_cdata,
  22142. self_closing_elements: cloneAndExcludeBlocks(
  22143. schema.getSelfClosingElements()
  22144. ),
  22145. cdata: function (text) {
  22146. node.append(createNode('#cdata', 4)).value = text
  22147. },
  22148. text: function (text, raw) {
  22149. var textNode
  22150. if (!isInWhiteSpacePreservedElement) {
  22151. text = text.replace(allWhiteSpaceRegExp, ' ')
  22152. if (isLineBreakNode(node.lastChild, blockElements)) {
  22153. text = text.replace(startWhiteSpaceRegExp, '')
  22154. }
  22155. }
  22156. if (text.length !== 0) {
  22157. textNode = createNode('#text', 3)
  22158. textNode.raw = !!raw
  22159. node.append(textNode).value = text
  22160. }
  22161. },
  22162. comment: function (text) {
  22163. node.append(createNode('#comment', 8)).value = text
  22164. },
  22165. pi: function (name, text) {
  22166. node.append(createNode(name, 7)).value = text
  22167. removeWhitespaceBefore(node)
  22168. },
  22169. doctype: function (text) {
  22170. var newNode = node.append(createNode('#doctype', 10))
  22171. newNode.value = text
  22172. removeWhitespaceBefore(node)
  22173. },
  22174. start: function (name, attrs, empty) {
  22175. var elementRule = validate ? schema.getElementRule(name) : {}
  22176. if (elementRule) {
  22177. var newNode = createNode(elementRule.outputName || name, 1)
  22178. newNode.attributes = attrs
  22179. newNode.shortEnded = empty
  22180. node.append(newNode)
  22181. var parent_2 = children[node.name]
  22182. if (
  22183. parent_2 &&
  22184. children[newNode.name] &&
  22185. !parent_2[newNode.name]
  22186. ) {
  22187. invalidChildren.push(newNode)
  22188. }
  22189. var attrFiltersLen = attributeFilters.length
  22190. while (attrFiltersLen--) {
  22191. var attrName = attributeFilters[attrFiltersLen].name
  22192. if (attrName in attrs.map) {
  22193. list = matchedAttributes[attrName]
  22194. if (list) {
  22195. list.push(newNode)
  22196. } else {
  22197. matchedAttributes[attrName] = [newNode]
  22198. }
  22199. }
  22200. }
  22201. if (blockElements[name]) {
  22202. removeWhitespaceBefore(newNode)
  22203. }
  22204. if (!empty) {
  22205. node = newNode
  22206. }
  22207. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  22208. isInWhiteSpacePreservedElement = true
  22209. }
  22210. }
  22211. },
  22212. end: function (name) {
  22213. var textNode, text, sibling, tempNode
  22214. var elementRule = validate ? schema.getElementRule(name) : {}
  22215. if (elementRule) {
  22216. if (blockElements[name]) {
  22217. if (!isInWhiteSpacePreservedElement) {
  22218. textNode = node.firstChild
  22219. if (textNode && textNode.type === 3) {
  22220. text = textNode.value.replace(startWhiteSpaceRegExp, '')
  22221. if (text.length > 0) {
  22222. textNode.value = text
  22223. textNode = textNode.next
  22224. } else {
  22225. sibling = textNode.next
  22226. textNode.remove()
  22227. textNode = sibling
  22228. while (textNode && textNode.type === 3) {
  22229. text = textNode.value
  22230. sibling = textNode.next
  22231. if (
  22232. text.length === 0 ||
  22233. isAllWhiteSpaceRegExp.test(text)
  22234. ) {
  22235. textNode.remove()
  22236. textNode = sibling
  22237. }
  22238. textNode = sibling
  22239. }
  22240. }
  22241. }
  22242. textNode = node.lastChild
  22243. if (textNode && textNode.type === 3) {
  22244. text = textNode.value.replace(endWhiteSpaceRegExp, '')
  22245. if (text.length > 0) {
  22246. textNode.value = text
  22247. textNode = textNode.prev
  22248. } else {
  22249. sibling = textNode.prev
  22250. textNode.remove()
  22251. textNode = sibling
  22252. while (textNode && textNode.type === 3) {
  22253. text = textNode.value
  22254. sibling = textNode.prev
  22255. if (
  22256. text.length === 0 ||
  22257. isAllWhiteSpaceRegExp.test(text)
  22258. ) {
  22259. textNode.remove()
  22260. textNode = sibling
  22261. }
  22262. textNode = sibling
  22263. }
  22264. }
  22265. }
  22266. }
  22267. }
  22268. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  22269. isInWhiteSpacePreservedElement = false
  22270. }
  22271. if (
  22272. elementRule.removeEmpty &&
  22273. isEmpty(schema, nonEmptyElements, whiteSpaceElements, node)
  22274. ) {
  22275. tempNode = node.parent
  22276. if (blockElements[node.name]) {
  22277. node.empty().remove()
  22278. } else {
  22279. node.unwrap()
  22280. }
  22281. node = tempNode
  22282. return
  22283. }
  22284. if (
  22285. elementRule.paddEmpty &&
  22286. (isPaddedWithNbsp(node) ||
  22287. isEmpty(schema, nonEmptyElements, whiteSpaceElements, node))
  22288. ) {
  22289. paddEmptyNode(settings, args, blockElements, node)
  22290. }
  22291. node = node.parent
  22292. }
  22293. },
  22294. },
  22295. schema
  22296. )
  22297. var rootNode = (node = new AstNode(
  22298. args.context || settings.root_name,
  22299. 11
  22300. ))
  22301. parser.parse(html, args.format)
  22302. if (validate && invalidChildren.length) {
  22303. if (!args.context) {
  22304. fixInvalidChildren(invalidChildren)
  22305. } else {
  22306. args.invalid = true
  22307. }
  22308. }
  22309. if (rootBlockName && (rootNode.name === 'body' || args.isRootContent)) {
  22310. addRootBlocks()
  22311. }
  22312. if (!args.invalid) {
  22313. for (name in matchedNodes) {
  22314. if (!has$2(matchedNodes, name)) {
  22315. continue
  22316. }
  22317. list = nodeFilters[name]
  22318. nodes = matchedNodes[name]
  22319. fi = nodes.length
  22320. while (fi--) {
  22321. if (!nodes[fi].parent) {
  22322. nodes.splice(fi, 1)
  22323. }
  22324. }
  22325. for (i = 0, l = list.length; i < l; i++) {
  22326. list[i](nodes, name, args)
  22327. }
  22328. }
  22329. for (i = 0, l = attributeFilters.length; i < l; i++) {
  22330. list = attributeFilters[i]
  22331. if (list.name in matchedAttributes) {
  22332. nodes = matchedAttributes[list.name]
  22333. fi = nodes.length
  22334. while (fi--) {
  22335. if (!nodes[fi].parent) {
  22336. nodes.splice(fi, 1)
  22337. }
  22338. }
  22339. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) {
  22340. list.callbacks[fi](nodes, list.name, args)
  22341. }
  22342. }
  22343. }
  22344. }
  22345. return rootNode
  22346. }
  22347. var exports = {
  22348. schema: schema,
  22349. addAttributeFilter: addAttributeFilter,
  22350. getAttributeFilters: getAttributeFilters,
  22351. addNodeFilter: addNodeFilter,
  22352. getNodeFilters: getNodeFilters,
  22353. filterNode: filterNode,
  22354. parse: parse,
  22355. }
  22356. register$1(exports, settings)
  22357. register$2(exports, settings)
  22358. return exports
  22359. }
  22360. var register = function (htmlParser, settings, dom) {
  22361. htmlParser.addAttributeFilter('data-mce-tabindex', function (nodes, name) {
  22362. var i = nodes.length
  22363. while (i--) {
  22364. var node = nodes[i]
  22365. node.attr('tabindex', node.attr('data-mce-tabindex'))
  22366. node.attr(name, null)
  22367. }
  22368. })
  22369. htmlParser.addAttributeFilter('src,href,style', function (nodes, name) {
  22370. var internalName = 'data-mce-' + name
  22371. var urlConverter = settings.url_converter
  22372. var urlConverterScope = settings.url_converter_scope
  22373. var i = nodes.length
  22374. while (i--) {
  22375. var node = nodes[i]
  22376. var value = node.attr(internalName)
  22377. if (value !== undefined) {
  22378. node.attr(name, value.length > 0 ? value : null)
  22379. node.attr(internalName, null)
  22380. } else {
  22381. value = node.attr(name)
  22382. if (name === 'style') {
  22383. value = dom.serializeStyle(dom.parseStyle(value), node.name)
  22384. } else if (urlConverter) {
  22385. value = urlConverter.call(urlConverterScope, value, name, node.name)
  22386. }
  22387. node.attr(name, value.length > 0 ? value : null)
  22388. }
  22389. }
  22390. })
  22391. htmlParser.addAttributeFilter('class', function (nodes) {
  22392. var i = nodes.length
  22393. while (i--) {
  22394. var node = nodes[i]
  22395. var value = node.attr('class')
  22396. if (value) {
  22397. value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, '')
  22398. node.attr('class', value.length > 0 ? value : null)
  22399. }
  22400. }
  22401. })
  22402. htmlParser.addAttributeFilter(
  22403. 'data-mce-type',
  22404. function (nodes, name, args) {
  22405. var i = nodes.length
  22406. while (i--) {
  22407. var node = nodes[i]
  22408. if (node.attr('data-mce-type') === 'bookmark' && !args.cleanup) {
  22409. var hasChildren = Optional.from(node.firstChild).exists(function (
  22410. firstChild
  22411. ) {
  22412. return !isZwsp(firstChild.value)
  22413. })
  22414. if (hasChildren) {
  22415. node.unwrap()
  22416. } else {
  22417. node.remove()
  22418. }
  22419. }
  22420. }
  22421. }
  22422. )
  22423. htmlParser.addNodeFilter('noscript', function (nodes) {
  22424. var i = nodes.length
  22425. while (i--) {
  22426. var node = nodes[i].firstChild
  22427. if (node) {
  22428. node.value = Entities.decode(node.value)
  22429. }
  22430. }
  22431. })
  22432. htmlParser.addNodeFilter('script,style', function (nodes, name) {
  22433. var trim = function (value) {
  22434. return value
  22435. .replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  22436. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  22437. .replace(
  22438. /^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi,
  22439. ''
  22440. )
  22441. .replace(
  22442. /\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g,
  22443. ''
  22444. )
  22445. }
  22446. var i = nodes.length
  22447. while (i--) {
  22448. var node = nodes[i]
  22449. var value = node.firstChild ? node.firstChild.value : ''
  22450. if (name === 'script') {
  22451. var type = node.attr('type')
  22452. if (type) {
  22453. node.attr(
  22454. 'type',
  22455. type === 'mce-no/type' ? null : type.replace(/^mce\-/, '')
  22456. )
  22457. }
  22458. if (settings.element_format === 'xhtml' && value.length > 0) {
  22459. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>'
  22460. }
  22461. } else {
  22462. if (settings.element_format === 'xhtml' && value.length > 0) {
  22463. node.firstChild.value = '<!--\n' + trim(value) + '\n-->'
  22464. }
  22465. }
  22466. }
  22467. })
  22468. htmlParser.addNodeFilter('#comment', function (nodes) {
  22469. var i = nodes.length
  22470. while (i--) {
  22471. var node = nodes[i]
  22472. if (settings.preserve_cdata && node.value.indexOf('[CDATA[') === 0) {
  22473. node.name = '#cdata'
  22474. node.type = 4
  22475. node.value = dom.decode(node.value.replace(/^\[CDATA\[|\]\]$/g, ''))
  22476. } else if (node.value.indexOf('mce:protected ') === 0) {
  22477. node.name = '#text'
  22478. node.type = 3
  22479. node.raw = true
  22480. node.value = unescape(node.value).substr(14)
  22481. }
  22482. }
  22483. })
  22484. htmlParser.addNodeFilter('xml:namespace,input', function (nodes, name) {
  22485. var i = nodes.length
  22486. while (i--) {
  22487. var node = nodes[i]
  22488. if (node.type === 7) {
  22489. node.remove()
  22490. } else if (node.type === 1) {
  22491. if (name === 'input' && !node.attr('type')) {
  22492. node.attr('type', 'text')
  22493. }
  22494. }
  22495. }
  22496. })
  22497. htmlParser.addAttributeFilter('data-mce-type', function (nodes) {
  22498. each$k(nodes, function (node) {
  22499. if (node.attr('data-mce-type') === 'format-caret') {
  22500. if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) {
  22501. node.remove()
  22502. } else {
  22503. node.unwrap()
  22504. }
  22505. }
  22506. })
  22507. })
  22508. htmlParser.addAttributeFilter(
  22509. 'data-mce-src,data-mce-href,data-mce-style,' +
  22510. 'data-mce-selected,data-mce-expando,' +
  22511. 'data-mce-type,data-mce-resize,data-mce-placeholder',
  22512. function (nodes, name) {
  22513. var i = nodes.length
  22514. while (i--) {
  22515. nodes[i].attr(name, null)
  22516. }
  22517. }
  22518. )
  22519. }
  22520. var trimTrailingBr = function (rootNode) {
  22521. var isBr = function (node) {
  22522. return node && node.name === 'br'
  22523. }
  22524. var brNode1 = rootNode.lastChild
  22525. if (isBr(brNode1)) {
  22526. var brNode2 = brNode1.prev
  22527. if (isBr(brNode2)) {
  22528. brNode1.remove()
  22529. brNode2.remove()
  22530. }
  22531. }
  22532. }
  22533. var preProcess = function (editor, node, args) {
  22534. var oldDoc
  22535. var dom = editor.dom
  22536. var clonedNode = node.cloneNode(true)
  22537. var impl = document.implementation
  22538. if (impl.createHTMLDocument) {
  22539. var doc_1 = impl.createHTMLDocument('')
  22540. Tools.each(
  22541. clonedNode.nodeName === 'BODY' ? clonedNode.childNodes : [clonedNode],
  22542. function (node) {
  22543. doc_1.body.appendChild(doc_1.importNode(node, true))
  22544. }
  22545. )
  22546. if (clonedNode.nodeName !== 'BODY') {
  22547. clonedNode = doc_1.body.firstChild
  22548. } else {
  22549. clonedNode = doc_1.body
  22550. }
  22551. oldDoc = dom.doc
  22552. dom.doc = doc_1
  22553. }
  22554. firePreProcess(editor, __assign(__assign({}, args), { node: clonedNode }))
  22555. if (oldDoc) {
  22556. dom.doc = oldDoc
  22557. }
  22558. return clonedNode
  22559. }
  22560. var shouldFireEvent = function (editor, args) {
  22561. return editor && editor.hasEventListeners('PreProcess') && !args.no_events
  22562. }
  22563. var process = function (editor, node, args) {
  22564. return shouldFireEvent(editor, args) ? preProcess(editor, node, args) : node
  22565. }
  22566. var addTempAttr = function (htmlParser, tempAttrs, name) {
  22567. if (Tools.inArray(tempAttrs, name) === -1) {
  22568. htmlParser.addAttributeFilter(name, function (nodes, name) {
  22569. var i = nodes.length
  22570. while (i--) {
  22571. nodes[i].attr(name, null)
  22572. }
  22573. })
  22574. tempAttrs.push(name)
  22575. }
  22576. }
  22577. var postProcess = function (editor, args, content) {
  22578. if (!args.no_events && editor) {
  22579. var outArgs = firePostProcess(
  22580. editor,
  22581. __assign(__assign({}, args), { content: content })
  22582. )
  22583. return outArgs.content
  22584. } else {
  22585. return content
  22586. }
  22587. }
  22588. var getHtmlFromNode = function (dom, node, args) {
  22589. var html = trim$2(args.getInner ? node.innerHTML : dom.getOuterHTML(node))
  22590. return args.selection || isWsPreserveElement(SugarElement.fromDom(node))
  22591. ? html
  22592. : Tools.trim(html)
  22593. }
  22594. var parseHtml = function (htmlParser, html, args) {
  22595. var parserArgs = args.selection
  22596. ? __assign({ forced_root_block: false }, args)
  22597. : args
  22598. var rootNode = htmlParser.parse(html, parserArgs)
  22599. trimTrailingBr(rootNode)
  22600. return rootNode
  22601. }
  22602. var serializeNode = function (settings, schema, node) {
  22603. var htmlSerializer = HtmlSerializer(settings, schema)
  22604. return htmlSerializer.serialize(node)
  22605. }
  22606. var toHtml = function (editor, settings, schema, rootNode, args) {
  22607. var content = serializeNode(settings, schema, rootNode)
  22608. return postProcess(editor, args, content)
  22609. }
  22610. var DomSerializerImpl = function (settings, editor) {
  22611. var tempAttrs = ['data-mce-selected']
  22612. var dom = editor && editor.dom ? editor.dom : DOMUtils.DOM
  22613. var schema = editor && editor.schema ? editor.schema : Schema(settings)
  22614. settings.entity_encoding = settings.entity_encoding || 'named'
  22615. settings.remove_trailing_brs =
  22616. 'remove_trailing_brs' in settings ? settings.remove_trailing_brs : true
  22617. var htmlParser = DomParser(settings, schema)
  22618. register(htmlParser, settings, dom)
  22619. var serialize = function (node, parserArgs) {
  22620. if (parserArgs === void 0) {
  22621. parserArgs = {}
  22622. }
  22623. var args = __assign({ format: 'html' }, parserArgs)
  22624. var targetNode = process(editor, node, args)
  22625. var html = getHtmlFromNode(dom, targetNode, args)
  22626. var rootNode = parseHtml(htmlParser, html, args)
  22627. return args.format === 'tree'
  22628. ? rootNode
  22629. : toHtml(editor, settings, schema, rootNode, args)
  22630. }
  22631. return {
  22632. schema: schema,
  22633. addNodeFilter: htmlParser.addNodeFilter,
  22634. addAttributeFilter: htmlParser.addAttributeFilter,
  22635. serialize: serialize,
  22636. addRules: schema.addValidElements,
  22637. setRules: schema.setValidElements,
  22638. addTempAttr: curry(addTempAttr, htmlParser, tempAttrs),
  22639. getTempAttrs: constant(tempAttrs),
  22640. getNodeFilters: htmlParser.getNodeFilters,
  22641. getAttributeFilters: htmlParser.getAttributeFilters,
  22642. }
  22643. }
  22644. var DomSerializer = function (settings, editor) {
  22645. var domSerializer = DomSerializerImpl(settings, editor)
  22646. return {
  22647. schema: domSerializer.schema,
  22648. addNodeFilter: domSerializer.addNodeFilter,
  22649. addAttributeFilter: domSerializer.addAttributeFilter,
  22650. serialize: domSerializer.serialize,
  22651. addRules: domSerializer.addRules,
  22652. setRules: domSerializer.setRules,
  22653. addTempAttr: domSerializer.addTempAttr,
  22654. getTempAttrs: domSerializer.getTempAttrs,
  22655. getNodeFilters: domSerializer.getNodeFilters,
  22656. getAttributeFilters: domSerializer.getAttributeFilters,
  22657. }
  22658. }
  22659. var defaultFormat = 'html'
  22660. var getContent = function (editor, args) {
  22661. if (args === void 0) {
  22662. args = {}
  22663. }
  22664. var format = args.format ? args.format : defaultFormat
  22665. return getContent$2(editor, args, format)
  22666. }
  22667. var setContent = function (editor, content, args) {
  22668. if (args === void 0) {
  22669. args = {}
  22670. }
  22671. return setContent$2(editor, content, args)
  22672. }
  22673. var DOM$7 = DOMUtils.DOM
  22674. var restoreOriginalStyles = function (editor) {
  22675. DOM$7.setStyle(editor.id, 'display', editor.orgDisplay)
  22676. }
  22677. var safeDestroy = function (x) {
  22678. return Optional.from(x).each(function (x) {
  22679. return x.destroy()
  22680. })
  22681. }
  22682. var clearDomReferences = function (editor) {
  22683. editor.contentAreaContainer =
  22684. editor.formElement =
  22685. editor.container =
  22686. editor.editorContainer =
  22687. null
  22688. editor.bodyElement = editor.contentDocument = editor.contentWindow = null
  22689. editor.iframeElement = editor.targetElm = null
  22690. if (editor.selection) {
  22691. editor.selection =
  22692. editor.selection.win =
  22693. editor.selection.dom =
  22694. editor.selection.dom.doc =
  22695. null
  22696. }
  22697. }
  22698. var restoreForm = function (editor) {
  22699. var form = editor.formElement
  22700. if (form) {
  22701. if (form._mceOldSubmit) {
  22702. form.submit = form._mceOldSubmit
  22703. form._mceOldSubmit = null
  22704. }
  22705. DOM$7.unbind(form, 'submit reset', editor.formEventDelegate)
  22706. }
  22707. }
  22708. var remove = function (editor) {
  22709. if (!editor.removed) {
  22710. var _selectionOverrides = editor._selectionOverrides,
  22711. editorUpload = editor.editorUpload
  22712. var body = editor.getBody()
  22713. var element = editor.getElement()
  22714. if (body) {
  22715. editor.save({ is_removing: true })
  22716. }
  22717. editor.removed = true
  22718. editor.unbindAllNativeEvents()
  22719. if (editor.hasHiddenInput && element) {
  22720. DOM$7.remove(element.nextSibling)
  22721. }
  22722. fireRemove(editor)
  22723. editor.editorManager.remove(editor)
  22724. if (!editor.inline && body) {
  22725. restoreOriginalStyles(editor)
  22726. }
  22727. fireDetach(editor)
  22728. DOM$7.remove(editor.getContainer())
  22729. safeDestroy(_selectionOverrides)
  22730. safeDestroy(editorUpload)
  22731. editor.destroy()
  22732. }
  22733. }
  22734. var destroy = function (editor, automatic) {
  22735. var selection = editor.selection,
  22736. dom = editor.dom
  22737. if (editor.destroyed) {
  22738. return
  22739. }
  22740. if (!automatic && !editor.removed) {
  22741. editor.remove()
  22742. return
  22743. }
  22744. if (!automatic) {
  22745. editor.editorManager.off('beforeunload', editor._beforeUnload)
  22746. if (editor.theme && editor.theme.destroy) {
  22747. editor.theme.destroy()
  22748. }
  22749. safeDestroy(selection)
  22750. safeDestroy(dom)
  22751. }
  22752. restoreForm(editor)
  22753. clearDomReferences(editor)
  22754. editor.destroyed = true
  22755. }
  22756. var deep = function (old, nu) {
  22757. var bothObjects = isObject(old) && isObject(nu)
  22758. return bothObjects ? deepMerge(old, nu) : nu
  22759. }
  22760. var baseMerge = function (merger) {
  22761. return function () {
  22762. var objects = []
  22763. for (var _i = 0; _i < arguments.length; _i++) {
  22764. objects[_i] = arguments[_i]
  22765. }
  22766. if (objects.length === 0) {
  22767. throw new Error("Can't merge zero objects")
  22768. }
  22769. var ret = {}
  22770. for (var j = 0; j < objects.length; j++) {
  22771. var curObject = objects[j]
  22772. for (var key in curObject) {
  22773. if (has$2(curObject, key)) {
  22774. ret[key] = merger(ret[key], curObject[key])
  22775. }
  22776. }
  22777. }
  22778. return ret
  22779. }
  22780. }
  22781. var deepMerge = baseMerge(deep)
  22782. var deprecatedSettings = (
  22783. 'autoresize_on_init,content_editable_state,convert_fonts_to_spans,inline_styles,padd_empty_with_br,block_elements,' +
  22784. 'boolean_attributes,editor_deselector,editor_selector,elements,file_browser_callback_types,filepicker_validator_handler,' +
  22785. 'force_hex_style_colors,force_p_newlines,gecko_spellcheck,images_dataimg_filter,media_scripts,mode,move_caret_before_on_enter_elements,' +
  22786. 'non_empty_elements,self_closing_elements,short_ended_elements,special,spellchecker_select_languages,spellchecker_whitelist,' +
  22787. 'tab_focus,table_responsive_width,text_block_elements,text_inline_elements,toolbar_drawer,types,validate,whitespace_elements,' +
  22788. 'paste_word_valid_elements,paste_retain_style_properties,paste_convert_word_fake_lists'
  22789. ).split(',')
  22790. var deprecatedPlugins =
  22791. 'bbcode,colorpicker,contextmenu,fullpage,legacyoutput,spellchecker,textcolor'.split(
  22792. ','
  22793. )
  22794. var movedToPremiumPlugins = 'imagetools,toc'.split(',')
  22795. var getDeprecatedSettings = function (settings) {
  22796. var settingNames = filter$4(deprecatedSettings, function (setting) {
  22797. return has$2(settings, setting)
  22798. })
  22799. var forcedRootBlock = settings.forced_root_block
  22800. if (forcedRootBlock === false || forcedRootBlock === '') {
  22801. settingNames.push('forced_root_block (false only)')
  22802. }
  22803. return sort(settingNames)
  22804. }
  22805. var getDeprecatedPlugins = function (settings) {
  22806. var plugins = Tools.makeMap(settings.plugins, ' ')
  22807. var hasPlugin = function (plugin) {
  22808. return has$2(plugins, plugin)
  22809. }
  22810. var pluginNames = __spreadArray(
  22811. __spreadArray([], filter$4(deprecatedPlugins, hasPlugin), true),
  22812. bind(movedToPremiumPlugins, function (plugin) {
  22813. return hasPlugin(plugin) ? [plugin + ' (moving to premium)'] : []
  22814. }),
  22815. true
  22816. )
  22817. return sort(pluginNames)
  22818. }
  22819. var logDeprecationsWarning = function (rawSettings, finalSettings) {
  22820. var deprecatedSettings = getDeprecatedSettings(rawSettings)
  22821. var deprecatedPlugins = getDeprecatedPlugins(finalSettings)
  22822. var hasDeprecatedPlugins = deprecatedPlugins.length > 0
  22823. var hasDeprecatedSettings = deprecatedSettings.length > 0
  22824. var isLegacyMobileTheme = finalSettings.theme === 'mobile'
  22825. if (hasDeprecatedPlugins || hasDeprecatedSettings || isLegacyMobileTheme) {
  22826. var listJoiner = '\n- '
  22827. var themesMessage = isLegacyMobileTheme
  22828. ? '\n\nThemes:' + listJoiner + 'mobile'
  22829. : ''
  22830. var pluginsMessage = hasDeprecatedPlugins
  22831. ? '\n\nPlugins:' + listJoiner + deprecatedPlugins.join(listJoiner)
  22832. : ''
  22833. var settingsMessage = hasDeprecatedSettings
  22834. ? '\n\nSettings:' + listJoiner + deprecatedSettings.join(listJoiner)
  22835. : ''
  22836. console.warn(
  22837. 'The following deprecated features are currently enabled, these will be removed in TinyMCE 6.0. ' +
  22838. 'See https://www.tiny.cloud/docs/release-notes/6.0-upcoming-changes/ for more information.' +
  22839. themesMessage +
  22840. pluginsMessage +
  22841. settingsMessage
  22842. )
  22843. }
  22844. }
  22845. var sectionResult = function (sections, settings) {
  22846. return {
  22847. sections: constant(sections),
  22848. settings: constant(settings),
  22849. }
  22850. }
  22851. var deviceDetection = detect().deviceType
  22852. var isTouch = deviceDetection.isTouch()
  22853. var isPhone = deviceDetection.isPhone()
  22854. var isTablet = deviceDetection.isTablet()
  22855. var legacyMobilePlugins = ['lists', 'autolink', 'autosave']
  22856. var defaultTouchSettings = {
  22857. table_grid: false,
  22858. object_resizing: false,
  22859. resize: false,
  22860. }
  22861. var normalizePlugins = function (plugins) {
  22862. var pluginNames = isArray$1(plugins) ? plugins.join(' ') : plugins
  22863. var trimmedPlugins = map$3(
  22864. isString$1(pluginNames) ? pluginNames.split(' ') : [],
  22865. trim$4
  22866. )
  22867. return filter$4(trimmedPlugins, function (item) {
  22868. return item.length > 0
  22869. })
  22870. }
  22871. var filterLegacyMobilePlugins = function (plugins) {
  22872. return filter$4(plugins, curry(contains$3, legacyMobilePlugins))
  22873. }
  22874. var extractSections = function (keys, settings) {
  22875. var result = bifilter(settings, function (value, key) {
  22876. return contains$3(keys, key)
  22877. })
  22878. return sectionResult(result.t, result.f)
  22879. }
  22880. var getSection = function (sectionResult, name, defaults) {
  22881. if (defaults === void 0) {
  22882. defaults = {}
  22883. }
  22884. var sections = sectionResult.sections()
  22885. var sectionSettings = get$9(sections, name).getOr({})
  22886. return Tools.extend({}, defaults, sectionSettings)
  22887. }
  22888. var hasSection = function (sectionResult, name) {
  22889. return has$2(sectionResult.sections(), name)
  22890. }
  22891. var isSectionTheme = function (sectionResult, name, theme) {
  22892. var section = sectionResult.sections()
  22893. return hasSection(sectionResult, name) && section[name].theme === theme
  22894. }
  22895. var getSectionConfig = function (sectionResult, name) {
  22896. return hasSection(sectionResult, name) ? sectionResult.sections()[name] : {}
  22897. }
  22898. var getToolbarMode = function (settings, defaultVal) {
  22899. return get$9(settings, 'toolbar_mode')
  22900. .orThunk(function () {
  22901. return get$9(settings, 'toolbar_drawer').map(function (val) {
  22902. return val === false ? 'wrap' : val
  22903. })
  22904. })
  22905. .getOr(defaultVal)
  22906. }
  22907. var getDefaultSettings = function (
  22908. settings,
  22909. id,
  22910. documentBaseUrl,
  22911. isTouch,
  22912. editor
  22913. ) {
  22914. var baseDefaults = {
  22915. id: id,
  22916. theme: 'silver',
  22917. toolbar_mode: getToolbarMode(settings, 'floating'),
  22918. plugins: '',
  22919. document_base_url: documentBaseUrl,
  22920. add_form_submit_trigger: true,
  22921. submit_patch: true,
  22922. add_unload_trigger: true,
  22923. convert_urls: true,
  22924. relative_urls: true,
  22925. remove_script_host: true,
  22926. object_resizing: true,
  22927. doctype: '<!DOCTYPE html>',
  22928. visual: true,
  22929. font_size_legacy_values:
  22930. 'xx-small,small,medium,large,x-large,xx-large,300%',
  22931. forced_root_block: 'p',
  22932. hidden_input: true,
  22933. inline_styles: true,
  22934. convert_fonts_to_spans: true,
  22935. indent: true,
  22936. indent_before:
  22937. 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' +
  22938. 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist',
  22939. indent_after:
  22940. 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' +
  22941. 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist',
  22942. entity_encoding: 'named',
  22943. url_converter: editor.convertURL,
  22944. url_converter_scope: editor,
  22945. }
  22946. return __assign(
  22947. __assign({}, baseDefaults),
  22948. isTouch ? defaultTouchSettings : {}
  22949. )
  22950. }
  22951. var getDefaultMobileSettings = function (mobileSettings, isPhone) {
  22952. var defaultMobileSettings = {
  22953. resize: false,
  22954. toolbar_mode: getToolbarMode(mobileSettings, 'scrolling'),
  22955. toolbar_sticky: false,
  22956. }
  22957. var defaultPhoneSettings = { menubar: false }
  22958. return __assign(
  22959. __assign(__assign({}, defaultTouchSettings), defaultMobileSettings),
  22960. isPhone ? defaultPhoneSettings : {}
  22961. )
  22962. }
  22963. var getExternalPlugins = function (overrideSettings, settings) {
  22964. var userDefinedExternalPlugins = settings.external_plugins
  22965. ? settings.external_plugins
  22966. : {}
  22967. if (overrideSettings && overrideSettings.external_plugins) {
  22968. return Tools.extend(
  22969. {},
  22970. overrideSettings.external_plugins,
  22971. userDefinedExternalPlugins
  22972. )
  22973. } else {
  22974. return userDefinedExternalPlugins
  22975. }
  22976. }
  22977. var combinePlugins = function (forcedPlugins, plugins) {
  22978. return []
  22979. .concat(normalizePlugins(forcedPlugins))
  22980. .concat(normalizePlugins(plugins))
  22981. }
  22982. var getPlatformPlugins = function (
  22983. isMobileDevice,
  22984. sectionResult,
  22985. desktopPlugins,
  22986. mobilePlugins
  22987. ) {
  22988. if (isMobileDevice && isSectionTheme(sectionResult, 'mobile', 'mobile')) {
  22989. return filterLegacyMobilePlugins(mobilePlugins)
  22990. } else if (isMobileDevice && hasSection(sectionResult, 'mobile')) {
  22991. return mobilePlugins
  22992. } else {
  22993. return desktopPlugins
  22994. }
  22995. }
  22996. var processPlugins = function (
  22997. isMobileDevice,
  22998. sectionResult,
  22999. defaultOverrideSettings,
  23000. settings
  23001. ) {
  23002. var forcedPlugins = normalizePlugins(defaultOverrideSettings.forced_plugins)
  23003. var desktopPlugins = normalizePlugins(settings.plugins)
  23004. var mobileConfig = getSectionConfig(sectionResult, 'mobile')
  23005. var mobilePlugins = mobileConfig.plugins
  23006. ? normalizePlugins(mobileConfig.plugins)
  23007. : desktopPlugins
  23008. var platformPlugins = getPlatformPlugins(
  23009. isMobileDevice,
  23010. sectionResult,
  23011. desktopPlugins,
  23012. mobilePlugins
  23013. )
  23014. var combinedPlugins = combinePlugins(forcedPlugins, platformPlugins)
  23015. if (Env.browser.isIE() && contains$3(combinedPlugins, 'rtc')) {
  23016. throw new Error('RTC plugin is not supported on IE 11.')
  23017. }
  23018. return Tools.extend(settings, { plugins: combinedPlugins.join(' ') })
  23019. }
  23020. var isOnMobile = function (isMobileDevice, sectionResult) {
  23021. return isMobileDevice && hasSection(sectionResult, 'mobile')
  23022. }
  23023. var combineSettings = function (
  23024. isMobileDevice,
  23025. isPhone,
  23026. defaultSettings,
  23027. defaultOverrideSettings,
  23028. settings
  23029. ) {
  23030. var defaultDeviceSettings = isMobileDevice
  23031. ? { mobile: getDefaultMobileSettings(settings.mobile || {}, isPhone) }
  23032. : {}
  23033. var sectionResult = extractSections(
  23034. ['mobile'],
  23035. deepMerge(defaultDeviceSettings, settings)
  23036. )
  23037. var extendedSettings = Tools.extend(
  23038. defaultSettings,
  23039. defaultOverrideSettings,
  23040. sectionResult.settings(),
  23041. isOnMobile(isMobileDevice, sectionResult)
  23042. ? getSection(sectionResult, 'mobile')
  23043. : {},
  23044. {
  23045. validate: true,
  23046. external_plugins: getExternalPlugins(
  23047. defaultOverrideSettings,
  23048. sectionResult.settings()
  23049. ),
  23050. }
  23051. )
  23052. return processPlugins(
  23053. isMobileDevice,
  23054. sectionResult,
  23055. defaultOverrideSettings,
  23056. extendedSettings
  23057. )
  23058. }
  23059. var getEditorSettings = function (
  23060. editor,
  23061. id,
  23062. documentBaseUrl,
  23063. defaultOverrideSettings,
  23064. settings
  23065. ) {
  23066. var defaultSettings = getDefaultSettings(
  23067. settings,
  23068. id,
  23069. documentBaseUrl,
  23070. isTouch,
  23071. editor
  23072. )
  23073. var finalSettings = combineSettings(
  23074. isPhone || isTablet,
  23075. isPhone,
  23076. defaultSettings,
  23077. defaultOverrideSettings,
  23078. settings
  23079. )
  23080. if (finalSettings.deprecation_warnings !== false) {
  23081. logDeprecationsWarning(settings, finalSettings)
  23082. }
  23083. return finalSettings
  23084. }
  23085. var getFiltered = function (predicate, editor, name) {
  23086. return Optional.from(editor.settings[name]).filter(predicate)
  23087. }
  23088. var getParamObject = function (value) {
  23089. var output = {}
  23090. if (typeof value === 'string') {
  23091. each$k(
  23092. value.indexOf('=') > 0
  23093. ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/)
  23094. : value.split(','),
  23095. function (val) {
  23096. var arr = val.split('=')
  23097. if (arr.length > 1) {
  23098. output[Tools.trim(arr[0])] = Tools.trim(arr[1])
  23099. } else {
  23100. output[Tools.trim(arr[0])] = Tools.trim(arr[0])
  23101. }
  23102. }
  23103. )
  23104. } else {
  23105. output = value
  23106. }
  23107. return output
  23108. }
  23109. var isArrayOf = function (p) {
  23110. return function (a) {
  23111. return isArray$1(a) && forall(a, p)
  23112. }
  23113. }
  23114. var getParam = function (editor, name, defaultVal, type) {
  23115. var value = name in editor.settings ? editor.settings[name] : defaultVal
  23116. if (type === 'hash') {
  23117. return getParamObject(value)
  23118. } else if (type === 'string') {
  23119. return getFiltered(isString$1, editor, name).getOr(defaultVal)
  23120. } else if (type === 'number') {
  23121. return getFiltered(isNumber, editor, name).getOr(defaultVal)
  23122. } else if (type === 'boolean') {
  23123. return getFiltered(isBoolean, editor, name).getOr(defaultVal)
  23124. } else if (type === 'object') {
  23125. return getFiltered(isObject, editor, name).getOr(defaultVal)
  23126. } else if (type === 'array') {
  23127. return getFiltered(isArray$1, editor, name).getOr(defaultVal)
  23128. } else if (type === 'string[]') {
  23129. return getFiltered(isArrayOf(isString$1), editor, name).getOr(defaultVal)
  23130. } else if (type === 'function') {
  23131. return getFiltered(isFunction, editor, name).getOr(defaultVal)
  23132. } else {
  23133. return value
  23134. }
  23135. }
  23136. var CreateIconManager = function () {
  23137. var lookup = {}
  23138. var add = function (id, iconPack) {
  23139. lookup[id] = iconPack
  23140. }
  23141. var get = function (id) {
  23142. if (lookup[id]) {
  23143. return lookup[id]
  23144. }
  23145. return { icons: {} }
  23146. }
  23147. var has = function (id) {
  23148. return has$2(lookup, id)
  23149. }
  23150. return {
  23151. add: add,
  23152. get: get,
  23153. has: has,
  23154. }
  23155. }
  23156. var IconManager = CreateIconManager()
  23157. var getProp = function (propName, elm) {
  23158. var rawElm = elm.dom
  23159. return rawElm[propName]
  23160. }
  23161. var getComputedSizeProp = function (propName, elm) {
  23162. return parseInt(get$5(elm, propName), 10)
  23163. }
  23164. var getClientWidth = curry(getProp, 'clientWidth')
  23165. var getClientHeight = curry(getProp, 'clientHeight')
  23166. var getMarginTop = curry(getComputedSizeProp, 'margin-top')
  23167. var getMarginLeft = curry(getComputedSizeProp, 'margin-left')
  23168. var getBoundingClientRect = function (elm) {
  23169. return elm.dom.getBoundingClientRect()
  23170. }
  23171. var isInsideElementContentArea = function (bodyElm, clientX, clientY) {
  23172. var clientWidth = getClientWidth(bodyElm)
  23173. var clientHeight = getClientHeight(bodyElm)
  23174. return (
  23175. clientX >= 0 &&
  23176. clientY >= 0 &&
  23177. clientX <= clientWidth &&
  23178. clientY <= clientHeight
  23179. )
  23180. }
  23181. var transpose = function (inline, elm, clientX, clientY) {
  23182. var clientRect = getBoundingClientRect(elm)
  23183. var deltaX = inline
  23184. ? clientRect.left + elm.dom.clientLeft + getMarginLeft(elm)
  23185. : 0
  23186. var deltaY = inline
  23187. ? clientRect.top + elm.dom.clientTop + getMarginTop(elm)
  23188. : 0
  23189. var x = clientX - deltaX
  23190. var y = clientY - deltaY
  23191. return {
  23192. x: x,
  23193. y: y,
  23194. }
  23195. }
  23196. var isXYInContentArea = function (editor, clientX, clientY) {
  23197. var bodyElm = SugarElement.fromDom(editor.getBody())
  23198. var targetElm = editor.inline ? bodyElm : documentElement(bodyElm)
  23199. var transposedPoint = transpose(editor.inline, targetElm, clientX, clientY)
  23200. return isInsideElementContentArea(
  23201. targetElm,
  23202. transposedPoint.x,
  23203. transposedPoint.y
  23204. )
  23205. }
  23206. var fromDomSafe = function (node) {
  23207. return Optional.from(node).map(SugarElement.fromDom)
  23208. }
  23209. var isEditorAttachedToDom = function (editor) {
  23210. var rawContainer = editor.inline
  23211. ? editor.getBody()
  23212. : editor.getContentAreaContainer()
  23213. return fromDomSafe(rawContainer).map(inBody).getOr(false)
  23214. }
  23215. var NotificationManagerImpl = function () {
  23216. var unimplemented = function () {
  23217. throw new Error(
  23218. 'Theme did not provide a NotificationManager implementation.'
  23219. )
  23220. }
  23221. return {
  23222. open: unimplemented,
  23223. close: unimplemented,
  23224. reposition: unimplemented,
  23225. getArgs: unimplemented,
  23226. }
  23227. }
  23228. var NotificationManager = function (editor) {
  23229. var notifications = []
  23230. var getImplementation = function () {
  23231. var theme = editor.theme
  23232. return theme && theme.getNotificationManagerImpl
  23233. ? theme.getNotificationManagerImpl()
  23234. : NotificationManagerImpl()
  23235. }
  23236. var getTopNotification = function () {
  23237. return Optional.from(notifications[0])
  23238. }
  23239. var isEqual = function (a, b) {
  23240. return (
  23241. a.type === b.type &&
  23242. a.text === b.text &&
  23243. !a.progressBar &&
  23244. !a.timeout &&
  23245. !b.progressBar &&
  23246. !b.timeout
  23247. )
  23248. }
  23249. var reposition = function () {
  23250. if (notifications.length > 0) {
  23251. getImplementation().reposition(notifications)
  23252. }
  23253. }
  23254. var addNotification = function (notification) {
  23255. notifications.push(notification)
  23256. }
  23257. var closeNotification = function (notification) {
  23258. findIndex$2(notifications, function (otherNotification) {
  23259. return otherNotification === notification
  23260. }).each(function (index) {
  23261. notifications.splice(index, 1)
  23262. })
  23263. }
  23264. var open = function (spec, fireEvent) {
  23265. if (fireEvent === void 0) {
  23266. fireEvent = true
  23267. }
  23268. if (editor.removed || !isEditorAttachedToDom(editor)) {
  23269. return
  23270. }
  23271. if (fireEvent) {
  23272. editor.fire('BeforeOpenNotification', { notification: spec })
  23273. }
  23274. return find$3(notifications, function (notification) {
  23275. return isEqual(getImplementation().getArgs(notification), spec)
  23276. }).getOrThunk(function () {
  23277. editor.editorManager.setActive(editor)
  23278. var notification = getImplementation().open(spec, function () {
  23279. closeNotification(notification)
  23280. reposition()
  23281. getTopNotification().fold(
  23282. function () {
  23283. return editor.focus()
  23284. },
  23285. function (top) {
  23286. return focus$1(SugarElement.fromDom(top.getEl()))
  23287. }
  23288. )
  23289. })
  23290. addNotification(notification)
  23291. reposition()
  23292. editor.fire('OpenNotification', {
  23293. notification: __assign({}, notification),
  23294. })
  23295. return notification
  23296. })
  23297. }
  23298. var close = function () {
  23299. getTopNotification().each(function (notification) {
  23300. getImplementation().close(notification)
  23301. closeNotification(notification)
  23302. reposition()
  23303. })
  23304. }
  23305. var getNotifications = constant(notifications)
  23306. var registerEvents = function (editor) {
  23307. editor.on('SkinLoaded', function () {
  23308. var serviceMessage = getServiceMessage(editor)
  23309. if (serviceMessage) {
  23310. open(
  23311. {
  23312. text: serviceMessage,
  23313. type: 'warning',
  23314. timeout: 0,
  23315. },
  23316. false
  23317. )
  23318. }
  23319. reposition()
  23320. })
  23321. editor.on('show ResizeEditor ResizeWindow NodeChange', function () {
  23322. Delay.requestAnimationFrame(reposition)
  23323. })
  23324. editor.on('remove', function () {
  23325. each$k(notifications.slice(), function (notification) {
  23326. getImplementation().close(notification)
  23327. })
  23328. })
  23329. }
  23330. registerEvents(editor)
  23331. return {
  23332. open: open,
  23333. close: close,
  23334. getNotifications: getNotifications,
  23335. }
  23336. }
  23337. var PluginManager = AddOnManager.PluginManager
  23338. var ThemeManager = AddOnManager.ThemeManager
  23339. function WindowManagerImpl() {
  23340. var unimplemented = function () {
  23341. throw new Error('Theme did not provide a WindowManager implementation.')
  23342. }
  23343. return {
  23344. open: unimplemented,
  23345. openUrl: unimplemented,
  23346. alert: unimplemented,
  23347. confirm: unimplemented,
  23348. close: unimplemented,
  23349. getParams: unimplemented,
  23350. setParams: unimplemented,
  23351. }
  23352. }
  23353. var WindowManager = function (editor) {
  23354. var dialogs = []
  23355. var getImplementation = function () {
  23356. var theme = editor.theme
  23357. return theme && theme.getWindowManagerImpl
  23358. ? theme.getWindowManagerImpl()
  23359. : WindowManagerImpl()
  23360. }
  23361. var funcBind = function (scope, f) {
  23362. return function () {
  23363. var args = []
  23364. for (var _i = 0; _i < arguments.length; _i++) {
  23365. args[_i] = arguments[_i]
  23366. }
  23367. return f ? f.apply(scope, args) : undefined
  23368. }
  23369. }
  23370. var fireOpenEvent = function (dialog) {
  23371. editor.fire('OpenWindow', { dialog: dialog })
  23372. }
  23373. var fireCloseEvent = function (dialog) {
  23374. editor.fire('CloseWindow', { dialog: dialog })
  23375. }
  23376. var addDialog = function (dialog) {
  23377. dialogs.push(dialog)
  23378. fireOpenEvent(dialog)
  23379. }
  23380. var closeDialog = function (dialog) {
  23381. fireCloseEvent(dialog)
  23382. dialogs = filter$4(dialogs, function (otherDialog) {
  23383. return otherDialog !== dialog
  23384. })
  23385. if (dialogs.length === 0) {
  23386. editor.focus()
  23387. }
  23388. }
  23389. var getTopDialog = function () {
  23390. return Optional.from(dialogs[dialogs.length - 1])
  23391. }
  23392. var storeSelectionAndOpenDialog = function (openDialog) {
  23393. editor.editorManager.setActive(editor)
  23394. store(editor)
  23395. var dialog = openDialog()
  23396. addDialog(dialog)
  23397. return dialog
  23398. }
  23399. var open = function (args, params) {
  23400. return storeSelectionAndOpenDialog(function () {
  23401. return getImplementation().open(args, params, closeDialog)
  23402. })
  23403. }
  23404. var openUrl = function (args) {
  23405. return storeSelectionAndOpenDialog(function () {
  23406. return getImplementation().openUrl(args, closeDialog)
  23407. })
  23408. }
  23409. var alert = function (message, callback, scope) {
  23410. var windowManagerImpl = getImplementation()
  23411. windowManagerImpl.alert(
  23412. message,
  23413. funcBind(scope ? scope : windowManagerImpl, callback)
  23414. )
  23415. }
  23416. var confirm = function (message, callback, scope) {
  23417. var windowManagerImpl = getImplementation()
  23418. windowManagerImpl.confirm(
  23419. message,
  23420. funcBind(scope ? scope : windowManagerImpl, callback)
  23421. )
  23422. }
  23423. var close = function () {
  23424. getTopDialog().each(function (dialog) {
  23425. getImplementation().close(dialog)
  23426. closeDialog(dialog)
  23427. })
  23428. }
  23429. editor.on('remove', function () {
  23430. each$k(dialogs, function (dialog) {
  23431. getImplementation().close(dialog)
  23432. })
  23433. })
  23434. return {
  23435. open: open,
  23436. openUrl: openUrl,
  23437. alert: alert,
  23438. confirm: confirm,
  23439. close: close,
  23440. }
  23441. }
  23442. var displayNotification = function (editor, message) {
  23443. editor.notificationManager.open({
  23444. type: 'error',
  23445. text: message,
  23446. })
  23447. }
  23448. var displayError = function (editor, message) {
  23449. if (editor._skinLoaded) {
  23450. displayNotification(editor, message)
  23451. } else {
  23452. editor.on('SkinLoaded', function () {
  23453. displayNotification(editor, message)
  23454. })
  23455. }
  23456. }
  23457. var uploadError = function (editor, message) {
  23458. displayError(
  23459. editor,
  23460. I18n.translate(['Failed to upload image: {0}', message])
  23461. )
  23462. }
  23463. var logError = function (editor, errorType, msg) {
  23464. fireError(editor, errorType, { message: msg })
  23465. console.error(msg)
  23466. }
  23467. var createLoadError = function (type, url, name) {
  23468. return name
  23469. ? 'Failed to load ' + type + ': ' + name + ' from url ' + url
  23470. : 'Failed to load ' + type + ' url: ' + url
  23471. }
  23472. var pluginLoadError = function (editor, url, name) {
  23473. logError(editor, 'PluginLoadError', createLoadError('plugin', url, name))
  23474. }
  23475. var iconsLoadError = function (editor, url, name) {
  23476. logError(editor, 'IconsLoadError', createLoadError('icons', url, name))
  23477. }
  23478. var languageLoadError = function (editor, url, name) {
  23479. logError(
  23480. editor,
  23481. 'LanguageLoadError',
  23482. createLoadError('language', url, name)
  23483. )
  23484. }
  23485. var pluginInitError = function (editor, name, err) {
  23486. var message = I18n.translate(['Failed to initialize plugin: {0}', name])
  23487. fireError(editor, 'PluginLoadError', { message: message })
  23488. initError(message, err)
  23489. displayError(editor, message)
  23490. }
  23491. var initError = function (message) {
  23492. var x = []
  23493. for (var _i = 1; _i < arguments.length; _i++) {
  23494. x[_i - 1] = arguments[_i]
  23495. }
  23496. var console = window.console
  23497. if (console) {
  23498. if (console.error) {
  23499. console.error.apply(console, __spreadArray([message], x, false))
  23500. } else {
  23501. console.log.apply(console, __spreadArray([message], x, false))
  23502. }
  23503. }
  23504. }
  23505. var isContentCssSkinName = function (url) {
  23506. return /^[a-z0-9\-]+$/i.test(url)
  23507. }
  23508. var getContentCssUrls = function (editor) {
  23509. return transformToUrls(editor, getContentCss(editor))
  23510. }
  23511. var getFontCssUrls = function (editor) {
  23512. return transformToUrls(editor, getFontCss(editor))
  23513. }
  23514. var transformToUrls = function (editor, cssLinks) {
  23515. var skinUrl = editor.editorManager.baseURL + '/skins/content'
  23516. var suffix = editor.editorManager.suffix
  23517. var contentCssFile = 'content' + suffix + '.css'
  23518. var inline = editor.inline === true
  23519. return map$3(cssLinks, function (url) {
  23520. if (isContentCssSkinName(url) && !inline) {
  23521. return skinUrl + '/' + url + '/' + contentCssFile
  23522. } else {
  23523. return editor.documentBaseURI.toAbsolute(url)
  23524. }
  23525. })
  23526. }
  23527. var appendContentCssFromSettings = function (editor) {
  23528. editor.contentCSS = editor.contentCSS.concat(
  23529. getContentCssUrls(editor),
  23530. getFontCssUrls(editor)
  23531. )
  23532. }
  23533. var UploadStatus = function () {
  23534. var PENDING = 1,
  23535. UPLOADED = 2
  23536. var blobUriStatuses = {}
  23537. var createStatus = function (status, resultUri) {
  23538. return {
  23539. status: status,
  23540. resultUri: resultUri,
  23541. }
  23542. }
  23543. var hasBlobUri = function (blobUri) {
  23544. return blobUri in blobUriStatuses
  23545. }
  23546. var getResultUri = function (blobUri) {
  23547. var result = blobUriStatuses[blobUri]
  23548. return result ? result.resultUri : null
  23549. }
  23550. var isPending = function (blobUri) {
  23551. return hasBlobUri(blobUri)
  23552. ? blobUriStatuses[blobUri].status === PENDING
  23553. : false
  23554. }
  23555. var isUploaded = function (blobUri) {
  23556. return hasBlobUri(blobUri)
  23557. ? blobUriStatuses[blobUri].status === UPLOADED
  23558. : false
  23559. }
  23560. var markPending = function (blobUri) {
  23561. blobUriStatuses[blobUri] = createStatus(PENDING, null)
  23562. }
  23563. var markUploaded = function (blobUri, resultUri) {
  23564. blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri)
  23565. }
  23566. var removeFailed = function (blobUri) {
  23567. delete blobUriStatuses[blobUri]
  23568. }
  23569. var destroy = function () {
  23570. blobUriStatuses = {}
  23571. }
  23572. return {
  23573. hasBlobUri: hasBlobUri,
  23574. getResultUri: getResultUri,
  23575. isPending: isPending,
  23576. isUploaded: isUploaded,
  23577. markPending: markPending,
  23578. markUploaded: markUploaded,
  23579. removeFailed: removeFailed,
  23580. destroy: destroy,
  23581. }
  23582. }
  23583. var count = 0
  23584. var seed = function () {
  23585. var rnd = function () {
  23586. return Math.round(Math.random() * 4294967295).toString(36)
  23587. }
  23588. var now = new Date().getTime()
  23589. return 's' + now.toString(36) + rnd() + rnd() + rnd()
  23590. }
  23591. var uuid = function (prefix) {
  23592. return prefix + count++ + seed()
  23593. }
  23594. var BlobCache = function () {
  23595. var cache = []
  23596. var mimeToExt = function (mime) {
  23597. var mimes = {
  23598. 'image/jpeg': 'jpg',
  23599. 'image/jpg': 'jpg',
  23600. 'image/gif': 'gif',
  23601. 'image/png': 'png',
  23602. 'image/apng': 'apng',
  23603. 'image/avif': 'avif',
  23604. 'image/svg+xml': 'svg',
  23605. 'image/webp': 'webp',
  23606. 'image/bmp': 'bmp',
  23607. 'image/tiff': 'tiff',
  23608. }
  23609. return mimes[mime.toLowerCase()] || 'dat'
  23610. }
  23611. var create = function (o, blob, base64, name, filename) {
  23612. if (isString$1(o)) {
  23613. var id = o
  23614. return toBlobInfo({
  23615. id: id,
  23616. name: name,
  23617. filename: filename,
  23618. blob: blob,
  23619. base64: base64,
  23620. })
  23621. } else if (isObject(o)) {
  23622. return toBlobInfo(o)
  23623. } else {
  23624. throw new Error('Unknown input type')
  23625. }
  23626. }
  23627. var toBlobInfo = function (o) {
  23628. if (!o.blob || !o.base64) {
  23629. throw new Error(
  23630. 'blob and base64 representations of the image are required for BlobInfo to be created'
  23631. )
  23632. }
  23633. var id = o.id || uuid('blobid')
  23634. var name = o.name || id
  23635. var blob = o.blob
  23636. return {
  23637. id: constant(id),
  23638. name: constant(name),
  23639. filename: constant(o.filename || name + '.' + mimeToExt(blob.type)),
  23640. blob: constant(blob),
  23641. base64: constant(o.base64),
  23642. blobUri: constant(o.blobUri || URL.createObjectURL(blob)),
  23643. uri: constant(o.uri),
  23644. }
  23645. }
  23646. var add = function (blobInfo) {
  23647. if (!get(blobInfo.id())) {
  23648. cache.push(blobInfo)
  23649. }
  23650. }
  23651. var findFirst = function (predicate) {
  23652. return find$3(cache, predicate).getOrUndefined()
  23653. }
  23654. var get = function (id) {
  23655. return findFirst(function (cachedBlobInfo) {
  23656. return cachedBlobInfo.id() === id
  23657. })
  23658. }
  23659. var getByUri = function (blobUri) {
  23660. return findFirst(function (blobInfo) {
  23661. return blobInfo.blobUri() === blobUri
  23662. })
  23663. }
  23664. var getByData = function (base64, type) {
  23665. return findFirst(function (blobInfo) {
  23666. return blobInfo.base64() === base64 && blobInfo.blob().type === type
  23667. })
  23668. }
  23669. var removeByUri = function (blobUri) {
  23670. cache = filter$4(cache, function (blobInfo) {
  23671. if (blobInfo.blobUri() === blobUri) {
  23672. URL.revokeObjectURL(blobInfo.blobUri())
  23673. return false
  23674. }
  23675. return true
  23676. })
  23677. }
  23678. var destroy = function () {
  23679. each$k(cache, function (cachedBlobInfo) {
  23680. URL.revokeObjectURL(cachedBlobInfo.blobUri())
  23681. })
  23682. cache = []
  23683. }
  23684. return {
  23685. create: create,
  23686. add: add,
  23687. get: get,
  23688. getByUri: getByUri,
  23689. getByData: getByData,
  23690. findFirst: findFirst,
  23691. removeByUri: removeByUri,
  23692. destroy: destroy,
  23693. }
  23694. }
  23695. var Uploader = function (uploadStatus, settings) {
  23696. var pendingPromises = {}
  23697. var pathJoin = function (path1, path2) {
  23698. if (path1) {
  23699. return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '')
  23700. }
  23701. return path2
  23702. }
  23703. var defaultHandler = function (blobInfo, success, failure, progress) {
  23704. var xhr = new XMLHttpRequest()
  23705. xhr.open('POST', settings.url)
  23706. xhr.withCredentials = settings.credentials
  23707. xhr.upload.onprogress = function (e) {
  23708. progress((e.loaded / e.total) * 100)
  23709. }
  23710. xhr.onerror = function () {
  23711. failure(
  23712. 'Image upload failed due to a XHR Transport error. Code: ' +
  23713. xhr.status
  23714. )
  23715. }
  23716. xhr.onload = function () {
  23717. if (xhr.status < 200 || xhr.status >= 300) {
  23718. failure('HTTP Error: ' + xhr.status)
  23719. return
  23720. }
  23721. var json = JSON.parse(xhr.responseText)
  23722. if (!json || typeof json.location !== 'string') {
  23723. failure('Invalid JSON: ' + xhr.responseText)
  23724. return
  23725. }
  23726. success(pathJoin(settings.basePath, json.location))
  23727. }
  23728. var formData = new FormData()
  23729. formData.append('file', blobInfo.blob(), blobInfo.filename())
  23730. xhr.send(formData)
  23731. }
  23732. var noUpload = function () {
  23733. return new promiseObj(function (resolve) {
  23734. resolve([])
  23735. })
  23736. }
  23737. var handlerSuccess = function (blobInfo, url) {
  23738. return {
  23739. url: url,
  23740. blobInfo: blobInfo,
  23741. status: true,
  23742. }
  23743. }
  23744. var handlerFailure = function (blobInfo, message, options) {
  23745. return {
  23746. url: '',
  23747. blobInfo: blobInfo,
  23748. status: false,
  23749. error: {
  23750. message: message,
  23751. options: options,
  23752. },
  23753. }
  23754. }
  23755. var resolvePending = function (blobUri, result) {
  23756. Tools.each(pendingPromises[blobUri], function (resolve) {
  23757. resolve(result)
  23758. })
  23759. delete pendingPromises[blobUri]
  23760. }
  23761. var uploadBlobInfo = function (blobInfo, handler, openNotification) {
  23762. uploadStatus.markPending(blobInfo.blobUri())
  23763. return new promiseObj(function (resolve) {
  23764. var notification, progress
  23765. try {
  23766. var closeNotification_1 = function () {
  23767. if (notification) {
  23768. notification.close()
  23769. progress = noop
  23770. }
  23771. }
  23772. var success = function (url) {
  23773. closeNotification_1()
  23774. uploadStatus.markUploaded(blobInfo.blobUri(), url)
  23775. resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url))
  23776. resolve(handlerSuccess(blobInfo, url))
  23777. }
  23778. var failure = function (error, options) {
  23779. var failureOptions = options ? options : {}
  23780. closeNotification_1()
  23781. uploadStatus.removeFailed(blobInfo.blobUri())
  23782. resolvePending(
  23783. blobInfo.blobUri(),
  23784. handlerFailure(blobInfo, error, failureOptions)
  23785. )
  23786. resolve(handlerFailure(blobInfo, error, failureOptions))
  23787. }
  23788. progress = function (percent) {
  23789. if (percent < 0 || percent > 100) {
  23790. return
  23791. }
  23792. Optional.from(notification)
  23793. .orThunk(function () {
  23794. return Optional.from(openNotification).map(apply)
  23795. })
  23796. .each(function (n) {
  23797. notification = n
  23798. n.progressBar.value(percent)
  23799. })
  23800. }
  23801. handler(blobInfo, success, failure, progress)
  23802. } catch (ex) {
  23803. resolve(handlerFailure(blobInfo, ex.message, {}))
  23804. }
  23805. })
  23806. }
  23807. var isDefaultHandler = function (handler) {
  23808. return handler === defaultHandler
  23809. }
  23810. var pendingUploadBlobInfo = function (blobInfo) {
  23811. var blobUri = blobInfo.blobUri()
  23812. return new promiseObj(function (resolve) {
  23813. pendingPromises[blobUri] = pendingPromises[blobUri] || []
  23814. pendingPromises[blobUri].push(resolve)
  23815. })
  23816. }
  23817. var uploadBlobs = function (blobInfos, openNotification) {
  23818. blobInfos = Tools.grep(blobInfos, function (blobInfo) {
  23819. return !uploadStatus.isUploaded(blobInfo.blobUri())
  23820. })
  23821. return promiseObj.all(
  23822. Tools.map(blobInfos, function (blobInfo) {
  23823. return uploadStatus.isPending(blobInfo.blobUri())
  23824. ? pendingUploadBlobInfo(blobInfo)
  23825. : uploadBlobInfo(blobInfo, settings.handler, openNotification)
  23826. })
  23827. )
  23828. }
  23829. var upload = function (blobInfos, openNotification) {
  23830. return !settings.url && isDefaultHandler(settings.handler)
  23831. ? noUpload()
  23832. : uploadBlobs(blobInfos, openNotification)
  23833. }
  23834. if (isFunction(settings.handler) === false) {
  23835. settings.handler = defaultHandler
  23836. }
  23837. return { upload: upload }
  23838. }
  23839. var openNotification = function (editor) {
  23840. return function () {
  23841. return editor.notificationManager.open({
  23842. text: editor.translate('Image uploading...'),
  23843. type: 'info',
  23844. timeout: -1,
  23845. progressBar: true,
  23846. })
  23847. }
  23848. }
  23849. var createUploader = function (editor, uploadStatus) {
  23850. return Uploader(uploadStatus, {
  23851. url: getImageUploadUrl(editor),
  23852. basePath: getImageUploadBasePath(editor),
  23853. credentials: getImagesUploadCredentials(editor),
  23854. handler: getImagesUploadHandler(editor),
  23855. })
  23856. }
  23857. var ImageUploader = function (editor) {
  23858. var uploadStatus = UploadStatus()
  23859. var uploader = createUploader(editor, uploadStatus)
  23860. return {
  23861. upload: function (blobInfos, showNotification) {
  23862. if (showNotification === void 0) {
  23863. showNotification = true
  23864. }
  23865. return uploader.upload(
  23866. blobInfos,
  23867. showNotification ? openNotification(editor) : undefined
  23868. )
  23869. },
  23870. }
  23871. }
  23872. var UploadChangeHandler = function (editor) {
  23873. var lastChangedLevel = Cell(null)
  23874. editor.on('change AddUndo', function (e) {
  23875. lastChangedLevel.set(__assign({}, e.level))
  23876. })
  23877. var fireIfChanged = function () {
  23878. var data = editor.undoManager.data
  23879. last$2(data)
  23880. .filter(function (level) {
  23881. return !isEq$1(lastChangedLevel.get(), level)
  23882. })
  23883. .each(function (level) {
  23884. editor.setDirty(true)
  23885. editor.fire('change', {
  23886. level: level,
  23887. lastLevel: get$a(data, data.length - 2).getOrNull(),
  23888. })
  23889. })
  23890. }
  23891. return { fireIfChanged: fireIfChanged }
  23892. }
  23893. var EditorUpload = function (editor) {
  23894. var blobCache = BlobCache()
  23895. var uploader, imageScanner
  23896. var uploadStatus = UploadStatus()
  23897. var urlFilters = []
  23898. var changeHandler = UploadChangeHandler(editor)
  23899. var aliveGuard = function (callback) {
  23900. return function (result) {
  23901. if (editor.selection) {
  23902. return callback(result)
  23903. }
  23904. return []
  23905. }
  23906. }
  23907. var cacheInvalidator = function (url) {
  23908. return url + (url.indexOf('?') === -1 ? '?' : '&') + new Date().getTime()
  23909. }
  23910. var replaceString = function (content, search, replace) {
  23911. var index = 0
  23912. do {
  23913. index = content.indexOf(search, index)
  23914. if (index !== -1) {
  23915. content =
  23916. content.substring(0, index) +
  23917. replace +
  23918. content.substr(index + search.length)
  23919. index += replace.length - search.length + 1
  23920. }
  23921. } while (index !== -1)
  23922. return content
  23923. }
  23924. var replaceImageUrl = function (content, targetUrl, replacementUrl) {
  23925. var replacementString =
  23926. 'src="' +
  23927. replacementUrl +
  23928. '"' +
  23929. (replacementUrl === Env.transparentSrc
  23930. ? ' data-mce-placeholder="1"'
  23931. : '')
  23932. content = replaceString(
  23933. content,
  23934. 'src="' + targetUrl + '"',
  23935. replacementString
  23936. )
  23937. content = replaceString(
  23938. content,
  23939. 'data-mce-src="' + targetUrl + '"',
  23940. 'data-mce-src="' + replacementUrl + '"'
  23941. )
  23942. return content
  23943. }
  23944. var replaceUrlInUndoStack = function (targetUrl, replacementUrl) {
  23945. each$k(editor.undoManager.data, function (level) {
  23946. if (level.type === 'fragmented') {
  23947. level.fragments = map$3(level.fragments, function (fragment) {
  23948. return replaceImageUrl(fragment, targetUrl, replacementUrl)
  23949. })
  23950. } else {
  23951. level.content = replaceImageUrl(
  23952. level.content,
  23953. targetUrl,
  23954. replacementUrl
  23955. )
  23956. }
  23957. })
  23958. }
  23959. var replaceImageUriInView = function (image, resultUri) {
  23960. var src = editor.convertURL(resultUri, 'src')
  23961. replaceUrlInUndoStack(image.src, resultUri)
  23962. editor.$(image).attr({
  23963. src: shouldReuseFileName(editor)
  23964. ? cacheInvalidator(resultUri)
  23965. : resultUri,
  23966. 'data-mce-src': src,
  23967. })
  23968. }
  23969. var uploadImages = function (callback) {
  23970. if (!uploader) {
  23971. uploader = createUploader(editor, uploadStatus)
  23972. }
  23973. return scanForImages().then(
  23974. aliveGuard(function (imageInfos) {
  23975. var blobInfos = map$3(imageInfos, function (imageInfo) {
  23976. return imageInfo.blobInfo
  23977. })
  23978. return uploader.upload(blobInfos, openNotification(editor)).then(
  23979. aliveGuard(function (result) {
  23980. var imagesToRemove = []
  23981. var filteredResult = map$3(result, function (uploadInfo, index) {
  23982. var blobInfo = imageInfos[index].blobInfo
  23983. var image = imageInfos[index].image
  23984. if (uploadInfo.status && shouldReplaceBlobUris(editor)) {
  23985. blobCache.removeByUri(image.src)
  23986. if (isRtc(editor));
  23987. else {
  23988. replaceImageUriInView(image, uploadInfo.url)
  23989. }
  23990. } else if (uploadInfo.error) {
  23991. if (uploadInfo.error.options.remove) {
  23992. replaceUrlInUndoStack(
  23993. image.getAttribute('src'),
  23994. Env.transparentSrc
  23995. )
  23996. imagesToRemove.push(image)
  23997. }
  23998. uploadError(editor, uploadInfo.error.message)
  23999. }
  24000. return {
  24001. element: image,
  24002. status: uploadInfo.status,
  24003. uploadUri: uploadInfo.url,
  24004. blobInfo: blobInfo,
  24005. }
  24006. })
  24007. if (filteredResult.length > 0) {
  24008. changeHandler.fireIfChanged()
  24009. }
  24010. if (imagesToRemove.length > 0) {
  24011. if (isRtc(editor)) {
  24012. console.error(
  24013. 'Removing images on failed uploads is currently unsupported for RTC'
  24014. )
  24015. } else {
  24016. editor.undoManager.transact(function () {
  24017. each$k(imagesToRemove, function (element) {
  24018. editor.dom.remove(element)
  24019. blobCache.removeByUri(element.src)
  24020. })
  24021. })
  24022. }
  24023. }
  24024. if (callback) {
  24025. callback(filteredResult)
  24026. }
  24027. return filteredResult
  24028. })
  24029. )
  24030. })
  24031. )
  24032. }
  24033. var uploadImagesAuto = function (callback) {
  24034. if (isAutomaticUploadsEnabled(editor)) {
  24035. return uploadImages(callback)
  24036. }
  24037. }
  24038. var isValidDataUriImage = function (imgElm) {
  24039. if (
  24040. forall(urlFilters, function (filter) {
  24041. return filter(imgElm)
  24042. }) === false
  24043. ) {
  24044. return false
  24045. }
  24046. if (imgElm.getAttribute('src').indexOf('data:') === 0) {
  24047. var dataImgFilter = getImagesDataImgFilter(editor)
  24048. return dataImgFilter(imgElm)
  24049. }
  24050. return true
  24051. }
  24052. var addFilter = function (filter) {
  24053. urlFilters.push(filter)
  24054. }
  24055. var scanForImages = function () {
  24056. if (!imageScanner) {
  24057. imageScanner = ImageScanner(uploadStatus, blobCache)
  24058. }
  24059. return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(
  24060. aliveGuard(function (result) {
  24061. result = filter$4(result, function (resultItem) {
  24062. if (typeof resultItem === 'string') {
  24063. displayError(editor, resultItem)
  24064. return false
  24065. }
  24066. return true
  24067. })
  24068. if (isRtc(editor));
  24069. else {
  24070. each$k(result, function (resultItem) {
  24071. replaceUrlInUndoStack(
  24072. resultItem.image.src,
  24073. resultItem.blobInfo.blobUri()
  24074. )
  24075. resultItem.image.src = resultItem.blobInfo.blobUri()
  24076. resultItem.image.removeAttribute('data-mce-src')
  24077. })
  24078. }
  24079. return result
  24080. })
  24081. )
  24082. }
  24083. var destroy = function () {
  24084. blobCache.destroy()
  24085. uploadStatus.destroy()
  24086. imageScanner = uploader = null
  24087. }
  24088. var replaceBlobUris = function (content) {
  24089. return content.replace(/src="(blob:[^"]+)"/g, function (match, blobUri) {
  24090. var resultUri = uploadStatus.getResultUri(blobUri)
  24091. if (resultUri) {
  24092. return 'src="' + resultUri + '"'
  24093. }
  24094. var blobInfo = blobCache.getByUri(blobUri)
  24095. if (!blobInfo) {
  24096. blobInfo = foldl(
  24097. editor.editorManager.get(),
  24098. function (result, editor) {
  24099. return (
  24100. result ||
  24101. (editor.editorUpload &&
  24102. editor.editorUpload.blobCache.getByUri(blobUri))
  24103. )
  24104. },
  24105. null
  24106. )
  24107. }
  24108. if (blobInfo) {
  24109. var blob = blobInfo.blob()
  24110. return 'src="data:' + blob.type + ';base64,' + blobInfo.base64() + '"'
  24111. }
  24112. return match
  24113. })
  24114. }
  24115. editor.on('SetContent', function () {
  24116. if (isAutomaticUploadsEnabled(editor)) {
  24117. uploadImagesAuto()
  24118. } else {
  24119. scanForImages()
  24120. }
  24121. })
  24122. editor.on('RawSaveContent', function (e) {
  24123. e.content = replaceBlobUris(e.content)
  24124. })
  24125. editor.on('GetContent', function (e) {
  24126. if (e.source_view || e.format === 'raw' || e.format === 'tree') {
  24127. return
  24128. }
  24129. e.content = replaceBlobUris(e.content)
  24130. })
  24131. editor.on('PostRender', function () {
  24132. editor.parser.addNodeFilter('img', function (images) {
  24133. each$k(images, function (img) {
  24134. var src = img.attr('src')
  24135. if (blobCache.getByUri(src)) {
  24136. return
  24137. }
  24138. var resultUri = uploadStatus.getResultUri(src)
  24139. if (resultUri) {
  24140. img.attr('src', resultUri)
  24141. }
  24142. })
  24143. })
  24144. })
  24145. return {
  24146. blobCache: blobCache,
  24147. addFilter: addFilter,
  24148. uploadImages: uploadImages,
  24149. uploadImagesAuto: uploadImagesAuto,
  24150. scanForImages: scanForImages,
  24151. destroy: destroy,
  24152. }
  24153. }
  24154. var get = function (dom) {
  24155. var formats = {
  24156. valigntop: [
  24157. {
  24158. selector: 'td,th',
  24159. styles: { verticalAlign: 'top' },
  24160. },
  24161. ],
  24162. valignmiddle: [
  24163. {
  24164. selector: 'td,th',
  24165. styles: { verticalAlign: 'middle' },
  24166. },
  24167. ],
  24168. valignbottom: [
  24169. {
  24170. selector: 'td,th',
  24171. styles: { verticalAlign: 'bottom' },
  24172. },
  24173. ],
  24174. alignleft: [
  24175. {
  24176. selector: 'figure.image',
  24177. collapsed: false,
  24178. classes: 'align-left',
  24179. ceFalseOverride: true,
  24180. preview: 'font-family font-size',
  24181. },
  24182. {
  24183. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24184. styles: { textAlign: 'left' },
  24185. inherit: false,
  24186. preview: false,
  24187. defaultBlock: 'div',
  24188. },
  24189. {
  24190. selector: 'img,table,audio,video',
  24191. collapsed: false,
  24192. styles: { float: 'left' },
  24193. preview: 'font-family font-size',
  24194. },
  24195. ],
  24196. aligncenter: [
  24197. {
  24198. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24199. styles: { textAlign: 'center' },
  24200. inherit: false,
  24201. preview: 'font-family font-size',
  24202. defaultBlock: 'div',
  24203. },
  24204. {
  24205. selector: 'figure.image',
  24206. collapsed: false,
  24207. classes: 'align-center',
  24208. ceFalseOverride: true,
  24209. preview: 'font-family font-size',
  24210. },
  24211. {
  24212. selector: 'img,audio,video',
  24213. collapsed: false,
  24214. styles: {
  24215. display: 'block',
  24216. marginLeft: 'auto',
  24217. marginRight: 'auto',
  24218. },
  24219. preview: false,
  24220. },
  24221. {
  24222. selector: 'table',
  24223. collapsed: false,
  24224. styles: {
  24225. marginLeft: 'auto',
  24226. marginRight: 'auto',
  24227. },
  24228. preview: 'font-family font-size',
  24229. },
  24230. ],
  24231. alignright: [
  24232. {
  24233. selector: 'figure.image',
  24234. collapsed: false,
  24235. classes: 'align-right',
  24236. ceFalseOverride: true,
  24237. preview: 'font-family font-size',
  24238. },
  24239. {
  24240. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24241. styles: { textAlign: 'right' },
  24242. inherit: false,
  24243. preview: 'font-family font-size',
  24244. defaultBlock: 'div',
  24245. },
  24246. {
  24247. selector: 'img,table,audio,video',
  24248. collapsed: false,
  24249. styles: { float: 'right' },
  24250. preview: 'font-family font-size',
  24251. },
  24252. ],
  24253. alignjustify: [
  24254. {
  24255. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24256. styles: { textAlign: 'justify' },
  24257. inherit: false,
  24258. defaultBlock: 'div',
  24259. preview: 'font-family font-size',
  24260. },
  24261. ],
  24262. bold: [
  24263. {
  24264. inline: 'strong',
  24265. remove: 'all',
  24266. preserve_attributes: ['class', 'style'],
  24267. },
  24268. {
  24269. inline: 'span',
  24270. styles: { fontWeight: 'bold' },
  24271. },
  24272. {
  24273. inline: 'b',
  24274. remove: 'all',
  24275. preserve_attributes: ['class', 'style'],
  24276. },
  24277. ],
  24278. italic: [
  24279. {
  24280. inline: 'em',
  24281. remove: 'all',
  24282. preserve_attributes: ['class', 'style'],
  24283. },
  24284. {
  24285. inline: 'span',
  24286. styles: { fontStyle: 'italic' },
  24287. },
  24288. {
  24289. inline: 'i',
  24290. remove: 'all',
  24291. preserve_attributes: ['class', 'style'],
  24292. },
  24293. ],
  24294. underline: [
  24295. {
  24296. inline: 'span',
  24297. styles: { textDecoration: 'underline' },
  24298. exact: true,
  24299. },
  24300. {
  24301. inline: 'u',
  24302. remove: 'all',
  24303. preserve_attributes: ['class', 'style'],
  24304. },
  24305. ],
  24306. strikethrough: [
  24307. {
  24308. inline: 'span',
  24309. styles: { textDecoration: 'line-through' },
  24310. exact: true,
  24311. },
  24312. {
  24313. inline: 'strike',
  24314. remove: 'all',
  24315. preserve_attributes: ['class', 'style'],
  24316. },
  24317. {
  24318. inline: 's',
  24319. remove: 'all',
  24320. preserve_attributes: ['class', 'style'],
  24321. },
  24322. ],
  24323. forecolor: {
  24324. inline: 'span',
  24325. styles: { color: '%value' },
  24326. links: true,
  24327. remove_similar: true,
  24328. clear_child_styles: true,
  24329. },
  24330. hilitecolor: {
  24331. inline: 'span',
  24332. styles: { backgroundColor: '%value' },
  24333. links: true,
  24334. remove_similar: true,
  24335. clear_child_styles: true,
  24336. },
  24337. fontname: {
  24338. inline: 'span',
  24339. toggle: false,
  24340. styles: { fontFamily: '%value' },
  24341. clear_child_styles: true,
  24342. },
  24343. fontsize: {
  24344. inline: 'span',
  24345. toggle: false,
  24346. styles: { fontSize: '%value' },
  24347. clear_child_styles: true,
  24348. },
  24349. lineheight: {
  24350. selector: 'h1,h2,h3,h4,h5,h6,p,li,td,th,div',
  24351. defaultBlock: 'p',
  24352. styles: { lineHeight: '%value' },
  24353. },
  24354. fontsize_class: {
  24355. inline: 'span',
  24356. attributes: { class: '%value' },
  24357. },
  24358. blockquote: {
  24359. block: 'blockquote',
  24360. wrapper: true,
  24361. remove: 'all',
  24362. },
  24363. subscript: { inline: 'sub' },
  24364. superscript: { inline: 'sup' },
  24365. code: { inline: 'code' },
  24366. link: {
  24367. inline: 'a',
  24368. selector: 'a',
  24369. remove: 'all',
  24370. split: true,
  24371. deep: true,
  24372. onmatch: function (node, _fmt, _itemName) {
  24373. return isElement$5(node) && node.hasAttribute('href')
  24374. },
  24375. onformat: function (elm, _fmt, vars) {
  24376. Tools.each(vars, function (value, key) {
  24377. dom.setAttrib(elm, key, value)
  24378. })
  24379. },
  24380. },
  24381. lang: {
  24382. inline: 'span',
  24383. clear_child_styles: true,
  24384. remove_similar: true,
  24385. attributes: {
  24386. lang: '%value',
  24387. 'data-mce-lang': function (vars) {
  24388. var _a
  24389. return (_a =
  24390. vars === null || vars === void 0 ? void 0 : vars.customValue) !==
  24391. null && _a !== void 0
  24392. ? _a
  24393. : null
  24394. },
  24395. },
  24396. },
  24397. removeformat: [
  24398. {
  24399. selector:
  24400. 'b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,small',
  24401. remove: 'all',
  24402. split: true,
  24403. expand: false,
  24404. block_expand: true,
  24405. deep: true,
  24406. },
  24407. {
  24408. selector: 'span',
  24409. attributes: ['style', 'class'],
  24410. remove: 'empty',
  24411. split: true,
  24412. expand: false,
  24413. deep: true,
  24414. },
  24415. {
  24416. selector: '*',
  24417. attributes: ['style', 'class'],
  24418. split: false,
  24419. expand: false,
  24420. deep: true,
  24421. },
  24422. ],
  24423. }
  24424. Tools.each(
  24425. 'p h1 h2 h3 h4 h5 h6 div address pre dt dd samp'.split(/\s/),
  24426. function (name) {
  24427. formats[name] = {
  24428. block: name,
  24429. remove: 'all',
  24430. }
  24431. }
  24432. )
  24433. return formats
  24434. }
  24435. var FormatRegistry = function (editor) {
  24436. var formats = {}
  24437. var get$1 = function (name) {
  24438. return isNonNullable(name) ? formats[name] : formats
  24439. }
  24440. var has = function (name) {
  24441. return has$2(formats, name)
  24442. }
  24443. var register = function (name, format) {
  24444. if (name) {
  24445. if (!isString$1(name)) {
  24446. each$j(name, function (format, name) {
  24447. register(name, format)
  24448. })
  24449. } else {
  24450. if (!isArray$1(format)) {
  24451. format = [format]
  24452. }
  24453. each$k(format, function (format) {
  24454. if (isUndefined(format.deep)) {
  24455. format.deep = !isSelectorFormat(format)
  24456. }
  24457. if (isUndefined(format.split)) {
  24458. format.split = !isSelectorFormat(format) || isInlineFormat(format)
  24459. }
  24460. if (
  24461. isUndefined(format.remove) &&
  24462. isSelectorFormat(format) &&
  24463. !isInlineFormat(format)
  24464. ) {
  24465. format.remove = 'none'
  24466. }
  24467. if (isSelectorFormat(format) && isInlineFormat(format)) {
  24468. format.mixed = true
  24469. format.block_expand = true
  24470. }
  24471. if (isString$1(format.classes)) {
  24472. format.classes = format.classes.split(/\s+/)
  24473. }
  24474. })
  24475. formats[name] = format
  24476. }
  24477. }
  24478. }
  24479. var unregister = function (name) {
  24480. if (name && formats[name]) {
  24481. delete formats[name]
  24482. }
  24483. return formats
  24484. }
  24485. register(get(editor.dom))
  24486. register(getFormats(editor))
  24487. return {
  24488. get: get$1,
  24489. has: has,
  24490. register: register,
  24491. unregister: unregister,
  24492. }
  24493. }
  24494. var each$5 = Tools.each
  24495. var dom = DOMUtils.DOM
  24496. var parsedSelectorToHtml = function (ancestry, editor) {
  24497. var elm, item, fragment
  24498. var schema = (editor && editor.schema) || Schema({})
  24499. var decorate = function (elm, item) {
  24500. if (item.classes.length) {
  24501. dom.addClass(elm, item.classes.join(' '))
  24502. }
  24503. dom.setAttribs(elm, item.attrs)
  24504. }
  24505. var createElement = function (sItem) {
  24506. item =
  24507. typeof sItem === 'string'
  24508. ? {
  24509. name: sItem,
  24510. classes: [],
  24511. attrs: {},
  24512. }
  24513. : sItem
  24514. var elm = dom.create(item.name)
  24515. decorate(elm, item)
  24516. return elm
  24517. }
  24518. var getRequiredParent = function (elm, candidate) {
  24519. var name = typeof elm !== 'string' ? elm.nodeName.toLowerCase() : elm
  24520. var elmRule = schema.getElementRule(name)
  24521. var parentsRequired = elmRule && elmRule.parentsRequired
  24522. if (parentsRequired && parentsRequired.length) {
  24523. return candidate && Tools.inArray(parentsRequired, candidate) !== -1
  24524. ? candidate
  24525. : parentsRequired[0]
  24526. } else {
  24527. return false
  24528. }
  24529. }
  24530. var wrapInHtml = function (elm, ancestry, siblings) {
  24531. var parent, parentCandidate
  24532. var ancestor = ancestry.length > 0 && ancestry[0]
  24533. var ancestorName = ancestor && ancestor.name
  24534. var parentRequired = getRequiredParent(elm, ancestorName)
  24535. if (parentRequired) {
  24536. if (ancestorName === parentRequired) {
  24537. parentCandidate = ancestry[0]
  24538. ancestry = ancestry.slice(1)
  24539. } else {
  24540. parentCandidate = parentRequired
  24541. }
  24542. } else if (ancestor) {
  24543. parentCandidate = ancestry[0]
  24544. ancestry = ancestry.slice(1)
  24545. } else if (!siblings) {
  24546. return elm
  24547. }
  24548. if (parentCandidate) {
  24549. parent = createElement(parentCandidate)
  24550. parent.appendChild(elm)
  24551. }
  24552. if (siblings) {
  24553. if (!parent) {
  24554. parent = dom.create('div')
  24555. parent.appendChild(elm)
  24556. }
  24557. Tools.each(siblings, function (sibling) {
  24558. var siblingElm = createElement(sibling)
  24559. parent.insertBefore(siblingElm, elm)
  24560. })
  24561. }
  24562. return wrapInHtml(
  24563. parent,
  24564. ancestry,
  24565. parentCandidate && parentCandidate.siblings
  24566. )
  24567. }
  24568. if (ancestry && ancestry.length) {
  24569. item = ancestry[0]
  24570. elm = createElement(item)
  24571. fragment = dom.create('div')
  24572. fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings))
  24573. return fragment
  24574. } else {
  24575. return ''
  24576. }
  24577. }
  24578. var parseSelectorItem = function (item) {
  24579. var tagName
  24580. var obj = {
  24581. classes: [],
  24582. attrs: {},
  24583. }
  24584. item = obj.selector = Tools.trim(item)
  24585. if (item !== '*') {
  24586. tagName = item.replace(
  24587. /(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g,
  24588. function ($0, $1, $2, $3, $4) {
  24589. switch ($1) {
  24590. case '#':
  24591. obj.attrs.id = $2
  24592. break
  24593. case '.':
  24594. obj.classes.push($2)
  24595. break
  24596. case ':':
  24597. if (
  24598. Tools.inArray(
  24599. 'checked disabled enabled read-only required'.split(' '),
  24600. $2
  24601. ) !== -1
  24602. ) {
  24603. obj.attrs[$2] = $2
  24604. }
  24605. break
  24606. }
  24607. if ($3 === '[') {
  24608. var m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/)
  24609. if (m) {
  24610. obj.attrs[m[1]] = m[2]
  24611. }
  24612. }
  24613. return ''
  24614. }
  24615. )
  24616. }
  24617. obj.name = tagName || 'div'
  24618. return obj
  24619. }
  24620. var parseSelector = function (selector) {
  24621. if (!selector || typeof selector !== 'string') {
  24622. return []
  24623. }
  24624. selector = selector.split(/\s*,\s*/)[0]
  24625. selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, '$1')
  24626. return Tools.map(
  24627. selector.split(/(?:>|\s+(?![^\[\]]+\]))/),
  24628. function (item) {
  24629. var siblings = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem)
  24630. var obj = siblings.pop()
  24631. if (siblings.length) {
  24632. obj.siblings = siblings
  24633. }
  24634. return obj
  24635. }
  24636. ).reverse()
  24637. }
  24638. var getCssText = function (editor, format) {
  24639. var name, previewFrag
  24640. var previewCss = '',
  24641. parentFontSize
  24642. var previewStyles = getPreviewStyles(editor)
  24643. if (previewStyles === '') {
  24644. return ''
  24645. }
  24646. var removeVars = function (val) {
  24647. return val.replace(/%(\w+)/g, '')
  24648. }
  24649. if (typeof format === 'string') {
  24650. format = editor.formatter.get(format)
  24651. if (!format) {
  24652. return
  24653. }
  24654. format = format[0]
  24655. }
  24656. if ('preview' in format) {
  24657. var previewOpt = get$9(format, 'preview')
  24658. if (is$1(previewOpt, false)) {
  24659. return ''
  24660. } else {
  24661. previewStyles = previewOpt.getOr(previewStyles)
  24662. }
  24663. }
  24664. name = format.block || format.inline || 'span'
  24665. var items = parseSelector(format.selector)
  24666. if (items.length) {
  24667. if (!items[0].name) {
  24668. items[0].name = name
  24669. }
  24670. name = format.selector
  24671. previewFrag = parsedSelectorToHtml(items, editor)
  24672. } else {
  24673. previewFrag = parsedSelectorToHtml([name], editor)
  24674. }
  24675. var previewElm = dom.select(name, previewFrag)[0] || previewFrag.firstChild
  24676. each$5(format.styles, function (value, name) {
  24677. var newValue = removeVars(value)
  24678. if (newValue) {
  24679. dom.setStyle(previewElm, name, newValue)
  24680. }
  24681. })
  24682. each$5(format.attributes, function (value, name) {
  24683. var newValue = removeVars(value)
  24684. if (newValue) {
  24685. dom.setAttrib(previewElm, name, newValue)
  24686. }
  24687. })
  24688. each$5(format.classes, function (value) {
  24689. var newValue = removeVars(value)
  24690. if (!dom.hasClass(previewElm, newValue)) {
  24691. dom.addClass(previewElm, newValue)
  24692. }
  24693. })
  24694. editor.fire('PreviewFormats')
  24695. dom.setStyles(previewFrag, {
  24696. position: 'absolute',
  24697. left: -65535,
  24698. })
  24699. editor.getBody().appendChild(previewFrag)
  24700. parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true)
  24701. parentFontSize = /px$/.test(parentFontSize)
  24702. ? parseInt(parentFontSize, 10)
  24703. : 0
  24704. each$5(previewStyles.split(' '), function (name) {
  24705. var value = dom.getStyle(previewElm, name, true)
  24706. if (
  24707. name === 'background-color' &&
  24708. /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)
  24709. ) {
  24710. value = dom.getStyle(editor.getBody(), name, true)
  24711. if (dom.toHex(value).toLowerCase() === '#ffffff') {
  24712. return
  24713. }
  24714. }
  24715. if (name === 'color') {
  24716. if (dom.toHex(value).toLowerCase() === '#000000') {
  24717. return
  24718. }
  24719. }
  24720. if (name === 'font-size') {
  24721. if (/em|%$/.test(value)) {
  24722. if (parentFontSize === 0) {
  24723. return
  24724. }
  24725. var numValue = parseFloat(value) / (/%$/.test(value) ? 100 : 1)
  24726. value = numValue * parentFontSize + 'px'
  24727. }
  24728. }
  24729. if (name === 'border' && value) {
  24730. previewCss += 'padding:0 2px;'
  24731. }
  24732. previewCss += name + ':' + value + ';'
  24733. })
  24734. editor.fire('AfterPreviewFormats')
  24735. dom.remove(previewFrag)
  24736. return previewCss
  24737. }
  24738. var setup$h = function (editor) {
  24739. editor.addShortcut('meta+b', '', 'Bold')
  24740. editor.addShortcut('meta+i', '', 'Italic')
  24741. editor.addShortcut('meta+u', '', 'Underline')
  24742. for (var i = 1; i <= 6; i++) {
  24743. editor.addShortcut('access+' + i, '', ['FormatBlock', false, 'h' + i])
  24744. }
  24745. editor.addShortcut('access+7', '', ['FormatBlock', false, 'p'])
  24746. editor.addShortcut('access+8', '', ['FormatBlock', false, 'div'])
  24747. editor.addShortcut('access+9', '', ['FormatBlock', false, 'address'])
  24748. }
  24749. var Formatter = function (editor) {
  24750. var formats = FormatRegistry(editor)
  24751. var formatChangeState = Cell(null)
  24752. setup$h(editor)
  24753. setup$k(editor)
  24754. return {
  24755. get: formats.get,
  24756. has: formats.has,
  24757. register: formats.register,
  24758. unregister: formats.unregister,
  24759. apply: function (name, vars, node) {
  24760. applyFormat(editor, name, vars, node)
  24761. },
  24762. remove: function (name, vars, node, similar) {
  24763. removeFormat(editor, name, vars, node, similar)
  24764. },
  24765. toggle: function (name, vars, node) {
  24766. toggleFormat(editor, name, vars, node)
  24767. },
  24768. match: function (name, vars, node, similar) {
  24769. return matchFormat(editor, name, vars, node, similar)
  24770. },
  24771. closest: function (names) {
  24772. return closestFormat(editor, names)
  24773. },
  24774. matchAll: function (names, vars) {
  24775. return matchAllFormats(editor, names, vars)
  24776. },
  24777. matchNode: function (node, name, vars, similar) {
  24778. return matchNodeFormat(editor, node, name, vars, similar)
  24779. },
  24780. canApply: function (name) {
  24781. return canApplyFormat(editor, name)
  24782. },
  24783. formatChanged: function (formats, callback, similar, vars) {
  24784. return formatChanged(
  24785. editor,
  24786. formatChangeState,
  24787. formats,
  24788. callback,
  24789. similar,
  24790. vars
  24791. )
  24792. },
  24793. getCssText: curry(getCssText, editor),
  24794. }
  24795. }
  24796. var shouldIgnoreCommand = function (cmd) {
  24797. switch (cmd.toLowerCase()) {
  24798. case 'undo':
  24799. case 'redo':
  24800. case 'mcerepaint':
  24801. case 'mcefocus':
  24802. return true
  24803. default:
  24804. return false
  24805. }
  24806. }
  24807. var registerEvents = function (editor, undoManager, locks) {
  24808. var isFirstTypedCharacter = Cell(false)
  24809. var addNonTypingUndoLevel = function (e) {
  24810. setTyping(undoManager, false, locks)
  24811. undoManager.add({}, e)
  24812. }
  24813. editor.on('init', function () {
  24814. undoManager.add()
  24815. })
  24816. editor.on('BeforeExecCommand', function (e) {
  24817. var cmd = e.command
  24818. if (!shouldIgnoreCommand(cmd)) {
  24819. endTyping(undoManager, locks)
  24820. undoManager.beforeChange()
  24821. }
  24822. })
  24823. editor.on('ExecCommand', function (e) {
  24824. var cmd = e.command
  24825. if (!shouldIgnoreCommand(cmd)) {
  24826. addNonTypingUndoLevel(e)
  24827. }
  24828. })
  24829. editor.on('ObjectResizeStart cut', function () {
  24830. undoManager.beforeChange()
  24831. })
  24832. editor.on('SaveContent ObjectResized blur', addNonTypingUndoLevel)
  24833. editor.on('dragend', addNonTypingUndoLevel)
  24834. editor.on('keyup', function (e) {
  24835. var keyCode = e.keyCode
  24836. if (e.isDefaultPrevented()) {
  24837. return
  24838. }
  24839. if (
  24840. (keyCode >= 33 && keyCode <= 36) ||
  24841. (keyCode >= 37 && keyCode <= 40) ||
  24842. keyCode === 45 ||
  24843. e.ctrlKey
  24844. ) {
  24845. addNonTypingUndoLevel()
  24846. editor.nodeChanged()
  24847. }
  24848. if (keyCode === 46 || keyCode === 8) {
  24849. editor.nodeChanged()
  24850. }
  24851. if (
  24852. isFirstTypedCharacter.get() &&
  24853. undoManager.typing &&
  24854. isEq$1(createFromEditor(editor), undoManager.data[0]) === false
  24855. ) {
  24856. if (editor.isDirty() === false) {
  24857. editor.setDirty(true)
  24858. editor.fire('change', {
  24859. level: undoManager.data[0],
  24860. lastLevel: null,
  24861. })
  24862. }
  24863. editor.fire('TypingUndo')
  24864. isFirstTypedCharacter.set(false)
  24865. editor.nodeChanged()
  24866. }
  24867. })
  24868. editor.on('keydown', function (e) {
  24869. var keyCode = e.keyCode
  24870. if (e.isDefaultPrevented()) {
  24871. return
  24872. }
  24873. if (
  24874. (keyCode >= 33 && keyCode <= 36) ||
  24875. (keyCode >= 37 && keyCode <= 40) ||
  24876. keyCode === 45
  24877. ) {
  24878. if (undoManager.typing) {
  24879. addNonTypingUndoLevel(e)
  24880. }
  24881. return
  24882. }
  24883. var modKey = (e.ctrlKey && !e.altKey) || e.metaKey
  24884. if (
  24885. (keyCode < 16 || keyCode > 20) &&
  24886. keyCode !== 224 &&
  24887. keyCode !== 91 &&
  24888. !undoManager.typing &&
  24889. !modKey
  24890. ) {
  24891. undoManager.beforeChange()
  24892. setTyping(undoManager, true, locks)
  24893. undoManager.add({}, e)
  24894. isFirstTypedCharacter.set(true)
  24895. }
  24896. })
  24897. editor.on('mousedown', function (e) {
  24898. if (undoManager.typing) {
  24899. addNonTypingUndoLevel(e)
  24900. }
  24901. })
  24902. var isInsertReplacementText = function (event) {
  24903. return event.inputType === 'insertReplacementText'
  24904. }
  24905. var isInsertTextDataNull = function (event) {
  24906. return event.inputType === 'insertText' && event.data === null
  24907. }
  24908. var isInsertFromPasteOrDrop = function (event) {
  24909. return (
  24910. event.inputType === 'insertFromPaste' ||
  24911. event.inputType === 'insertFromDrop'
  24912. )
  24913. }
  24914. editor.on('input', function (e) {
  24915. if (
  24916. e.inputType &&
  24917. (isInsertReplacementText(e) ||
  24918. isInsertTextDataNull(e) ||
  24919. isInsertFromPasteOrDrop(e))
  24920. ) {
  24921. addNonTypingUndoLevel(e)
  24922. }
  24923. })
  24924. editor.on('AddUndo Undo Redo ClearUndos', function (e) {
  24925. if (!e.isDefaultPrevented()) {
  24926. editor.nodeChanged()
  24927. }
  24928. })
  24929. }
  24930. var addKeyboardShortcuts = function (editor) {
  24931. editor.addShortcut('meta+z', '', 'Undo')
  24932. editor.addShortcut('meta+y,meta+shift+z', '', 'Redo')
  24933. }
  24934. var UndoManager = function (editor) {
  24935. var beforeBookmark = value()
  24936. var locks = Cell(0)
  24937. var index = Cell(0)
  24938. var undoManager = {
  24939. data: [],
  24940. typing: false,
  24941. beforeChange: function () {
  24942. beforeChange(editor, locks, beforeBookmark)
  24943. },
  24944. add: function (level, event) {
  24945. return addUndoLevel(
  24946. editor,
  24947. undoManager,
  24948. index,
  24949. locks,
  24950. beforeBookmark,
  24951. level,
  24952. event
  24953. )
  24954. },
  24955. undo: function () {
  24956. return undo(editor, undoManager, locks, index)
  24957. },
  24958. redo: function () {
  24959. return redo(editor, index, undoManager.data)
  24960. },
  24961. clear: function () {
  24962. clear(editor, undoManager, index)
  24963. },
  24964. reset: function () {
  24965. reset(editor, undoManager)
  24966. },
  24967. hasUndo: function () {
  24968. return hasUndo(editor, undoManager, index)
  24969. },
  24970. hasRedo: function () {
  24971. return hasRedo(editor, undoManager, index)
  24972. },
  24973. transact: function (callback) {
  24974. return transact(editor, undoManager, locks, callback)
  24975. },
  24976. ignore: function (callback) {
  24977. ignore(editor, locks, callback)
  24978. },
  24979. extra: function (callback1, callback2) {
  24980. extra(editor, undoManager, index, callback1, callback2)
  24981. },
  24982. }
  24983. if (!isRtc(editor)) {
  24984. registerEvents(editor, undoManager, locks)
  24985. }
  24986. addKeyboardShortcuts(editor)
  24987. return undoManager
  24988. }
  24989. var nonTypingKeycodes = [
  24990. 9,
  24991. 27,
  24992. VK.HOME,
  24993. VK.END,
  24994. 19,
  24995. 20,
  24996. 44,
  24997. 144,
  24998. 145,
  24999. 33,
  25000. 34,
  25001. 45,
  25002. 16,
  25003. 17,
  25004. 18,
  25005. 91,
  25006. 92,
  25007. 93,
  25008. VK.DOWN,
  25009. VK.UP,
  25010. VK.LEFT,
  25011. VK.RIGHT,
  25012. ].concat(Env.browser.isFirefox() ? [224] : [])
  25013. var placeholderAttr = 'data-mce-placeholder'
  25014. var isKeyboardEvent = function (e) {
  25015. return e.type === 'keydown' || e.type === 'keyup'
  25016. }
  25017. var isDeleteEvent = function (e) {
  25018. var keyCode = e.keyCode
  25019. return keyCode === VK.BACKSPACE || keyCode === VK.DELETE
  25020. }
  25021. var isNonTypingKeyboardEvent = function (e) {
  25022. if (isKeyboardEvent(e)) {
  25023. var keyCode = e.keyCode
  25024. return (
  25025. !isDeleteEvent(e) &&
  25026. (VK.metaKeyPressed(e) ||
  25027. e.altKey ||
  25028. (keyCode >= 112 && keyCode <= 123) ||
  25029. contains$3(nonTypingKeycodes, keyCode))
  25030. )
  25031. } else {
  25032. return false
  25033. }
  25034. }
  25035. var isTypingKeyboardEvent = function (e) {
  25036. return (
  25037. isKeyboardEvent(e) &&
  25038. !(isDeleteEvent(e) || (e.type === 'keyup' && e.keyCode === 229))
  25039. )
  25040. }
  25041. var isVisuallyEmpty = function (dom, rootElm, forcedRootBlock) {
  25042. if (isEmpty$2(SugarElement.fromDom(rootElm), false)) {
  25043. var isForcedRootBlockFalse = forcedRootBlock === ''
  25044. var firstElement = rootElm.firstElementChild
  25045. if (!firstElement) {
  25046. return true
  25047. } else if (
  25048. dom.getStyle(rootElm.firstElementChild, 'padding-left') ||
  25049. dom.getStyle(rootElm.firstElementChild, 'padding-right')
  25050. ) {
  25051. return false
  25052. } else {
  25053. return isForcedRootBlockFalse
  25054. ? !dom.isBlock(firstElement)
  25055. : forcedRootBlock === firstElement.nodeName.toLowerCase()
  25056. }
  25057. } else {
  25058. return false
  25059. }
  25060. }
  25061. var setup$g = function (editor) {
  25062. var dom = editor.dom
  25063. var rootBlock = getForcedRootBlock(editor)
  25064. var placeholder = getPlaceholder(editor)
  25065. var updatePlaceholder = function (e, initial) {
  25066. if (isNonTypingKeyboardEvent(e)) {
  25067. return
  25068. }
  25069. var body = editor.getBody()
  25070. var showPlaceholder = isTypingKeyboardEvent(e)
  25071. ? false
  25072. : isVisuallyEmpty(dom, body, rootBlock)
  25073. var isPlaceholderShown = dom.getAttrib(body, placeholderAttr) !== ''
  25074. if (isPlaceholderShown !== showPlaceholder || initial) {
  25075. dom.setAttrib(
  25076. body,
  25077. placeholderAttr,
  25078. showPlaceholder ? placeholder : null
  25079. )
  25080. dom.setAttrib(
  25081. body,
  25082. 'aria-placeholder',
  25083. showPlaceholder ? placeholder : null
  25084. )
  25085. firePlaceholderToggle(editor, showPlaceholder)
  25086. editor.on(showPlaceholder ? 'keydown' : 'keyup', updatePlaceholder)
  25087. editor.off(showPlaceholder ? 'keyup' : 'keydown', updatePlaceholder)
  25088. }
  25089. }
  25090. if (placeholder) {
  25091. editor.on('init', function (e) {
  25092. updatePlaceholder(e, true)
  25093. editor.on('change SetContent ExecCommand', updatePlaceholder)
  25094. editor.on('paste', function (e) {
  25095. return Delay.setEditorTimeout(editor, function () {
  25096. return updatePlaceholder(e)
  25097. })
  25098. })
  25099. })
  25100. }
  25101. }
  25102. var strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/
  25103. var hasStrongRtl = function (text) {
  25104. return strongRtl.test(text)
  25105. }
  25106. var isInlineTarget = function (editor, elm) {
  25107. return is$2(SugarElement.fromDom(elm), getInlineBoundarySelector(editor))
  25108. }
  25109. var isRtl = function (element) {
  25110. return (
  25111. DOMUtils.DOM.getStyle(element, 'direction', true) === 'rtl' ||
  25112. hasStrongRtl(element.textContent)
  25113. )
  25114. }
  25115. var findInlineParents = function (isInlineTarget, rootNode, pos) {
  25116. return filter$4(
  25117. DOMUtils.DOM.getParents(pos.container(), '*', rootNode),
  25118. isInlineTarget
  25119. )
  25120. }
  25121. var findRootInline = function (isInlineTarget, rootNode, pos) {
  25122. var parents = findInlineParents(isInlineTarget, rootNode, pos)
  25123. return Optional.from(parents[parents.length - 1])
  25124. }
  25125. var hasSameParentBlock = function (rootNode, node1, node2) {
  25126. var block1 = getParentBlock$2(node1, rootNode)
  25127. var block2 = getParentBlock$2(node2, rootNode)
  25128. return block1 && block1 === block2
  25129. }
  25130. var isAtZwsp = function (pos) {
  25131. return isBeforeInline(pos) || isAfterInline(pos)
  25132. }
  25133. var normalizePosition = function (forward, pos) {
  25134. if (!pos) {
  25135. return pos
  25136. }
  25137. var container = pos.container(),
  25138. offset = pos.offset()
  25139. if (forward) {
  25140. if (isCaretContainerInline(container)) {
  25141. if (isText$7(container.nextSibling)) {
  25142. return CaretPosition(container.nextSibling, 0)
  25143. } else {
  25144. return CaretPosition.after(container)
  25145. }
  25146. } else {
  25147. return isBeforeInline(pos) ? CaretPosition(container, offset + 1) : pos
  25148. }
  25149. } else {
  25150. if (isCaretContainerInline(container)) {
  25151. if (isText$7(container.previousSibling)) {
  25152. return CaretPosition(
  25153. container.previousSibling,
  25154. container.previousSibling.data.length
  25155. )
  25156. } else {
  25157. return CaretPosition.before(container)
  25158. }
  25159. } else {
  25160. return isAfterInline(pos) ? CaretPosition(container, offset - 1) : pos
  25161. }
  25162. }
  25163. }
  25164. var normalizeForwards = curry(normalizePosition, true)
  25165. var normalizeBackwards = curry(normalizePosition, false)
  25166. var isBeforeRoot = function (rootNode) {
  25167. return function (elm) {
  25168. return eq(rootNode, SugarElement.fromDom(elm.dom.parentNode))
  25169. }
  25170. }
  25171. var isTextBlockOrListItem = function (element) {
  25172. return isTextBlock$2(element) || isListItem(element)
  25173. }
  25174. var getParentBlock$1 = function (rootNode, elm) {
  25175. if (contains$1(rootNode, elm)) {
  25176. return closest$3(elm, isTextBlockOrListItem, isBeforeRoot(rootNode))
  25177. } else {
  25178. return Optional.none()
  25179. }
  25180. }
  25181. var placeCaretInEmptyBody = function (editor) {
  25182. var body = editor.getBody()
  25183. var node =
  25184. body.firstChild && editor.dom.isBlock(body.firstChild)
  25185. ? body.firstChild
  25186. : body
  25187. editor.selection.setCursorLocation(node, 0)
  25188. }
  25189. var paddEmptyBody = function (editor) {
  25190. if (editor.dom.isEmpty(editor.getBody())) {
  25191. editor.setContent('')
  25192. placeCaretInEmptyBody(editor)
  25193. }
  25194. }
  25195. var willDeleteLastPositionInElement = function (forward, fromPos, elm) {
  25196. return lift2(
  25197. firstPositionIn(elm),
  25198. lastPositionIn(elm),
  25199. function (firstPos, lastPos) {
  25200. var normalizedFirstPos = normalizePosition(true, firstPos)
  25201. var normalizedLastPos = normalizePosition(false, lastPos)
  25202. var normalizedFromPos = normalizePosition(false, fromPos)
  25203. if (forward) {
  25204. return nextPosition(elm, normalizedFromPos).exists(function (
  25205. nextPos
  25206. ) {
  25207. return (
  25208. nextPos.isEqual(normalizedLastPos) &&
  25209. fromPos.isEqual(normalizedFirstPos)
  25210. )
  25211. })
  25212. } else {
  25213. return prevPosition(elm, normalizedFromPos).exists(function (
  25214. prevPos
  25215. ) {
  25216. return (
  25217. prevPos.isEqual(normalizedFirstPos) &&
  25218. fromPos.isEqual(normalizedLastPos)
  25219. )
  25220. })
  25221. }
  25222. }
  25223. ).getOr(true)
  25224. }
  25225. var blockPosition = function (block, position) {
  25226. return {
  25227. block: block,
  25228. position: position,
  25229. }
  25230. }
  25231. var blockBoundary = function (from, to) {
  25232. return {
  25233. from: from,
  25234. to: to,
  25235. }
  25236. }
  25237. var getBlockPosition = function (rootNode, pos) {
  25238. var rootElm = SugarElement.fromDom(rootNode)
  25239. var containerElm = SugarElement.fromDom(pos.container())
  25240. return getParentBlock$1(rootElm, containerElm).map(function (block) {
  25241. return blockPosition(block, pos)
  25242. })
  25243. }
  25244. var isDifferentBlocks = function (blockBoundary) {
  25245. return eq(blockBoundary.from.block, blockBoundary.to.block) === false
  25246. }
  25247. var hasSameParent = function (blockBoundary) {
  25248. return parent(blockBoundary.from.block)
  25249. .bind(function (parent1) {
  25250. return parent(blockBoundary.to.block).filter(function (parent2) {
  25251. return eq(parent1, parent2)
  25252. })
  25253. })
  25254. .isSome()
  25255. }
  25256. var isEditable$1 = function (blockBoundary) {
  25257. return (
  25258. isContentEditableFalse$b(blockBoundary.from.block.dom) === false &&
  25259. isContentEditableFalse$b(blockBoundary.to.block.dom) === false
  25260. )
  25261. }
  25262. var skipLastBr = function (rootNode, forward, blockPosition) {
  25263. if (
  25264. isBr$5(blockPosition.position.getNode()) &&
  25265. isEmpty$2(blockPosition.block) === false
  25266. ) {
  25267. return positionIn(false, blockPosition.block.dom)
  25268. .bind(function (lastPositionInBlock) {
  25269. if (lastPositionInBlock.isEqual(blockPosition.position)) {
  25270. return fromPosition(forward, rootNode, lastPositionInBlock).bind(
  25271. function (to) {
  25272. return getBlockPosition(rootNode, to)
  25273. }
  25274. )
  25275. } else {
  25276. return Optional.some(blockPosition)
  25277. }
  25278. })
  25279. .getOr(blockPosition)
  25280. } else {
  25281. return blockPosition
  25282. }
  25283. }
  25284. var readFromRange = function (rootNode, forward, rng) {
  25285. var fromBlockPos = getBlockPosition(
  25286. rootNode,
  25287. CaretPosition.fromRangeStart(rng)
  25288. )
  25289. var toBlockPos = fromBlockPos.bind(function (blockPos) {
  25290. return fromPosition(forward, rootNode, blockPos.position).bind(function (
  25291. to
  25292. ) {
  25293. return getBlockPosition(rootNode, to).map(function (blockPos) {
  25294. return skipLastBr(rootNode, forward, blockPos)
  25295. })
  25296. })
  25297. })
  25298. return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(function (
  25299. blockBoundary
  25300. ) {
  25301. return (
  25302. isDifferentBlocks(blockBoundary) &&
  25303. hasSameParent(blockBoundary) &&
  25304. isEditable$1(blockBoundary)
  25305. )
  25306. })
  25307. }
  25308. var read$1 = function (rootNode, forward, rng) {
  25309. return rng.collapsed
  25310. ? readFromRange(rootNode, forward, rng)
  25311. : Optional.none()
  25312. }
  25313. var getChildrenUntilBlockBoundary = function (block) {
  25314. var children$1 = children(block)
  25315. return findIndex$2(children$1, isBlock$2).fold(
  25316. constant(children$1),
  25317. function (index) {
  25318. return children$1.slice(0, index)
  25319. }
  25320. )
  25321. }
  25322. var extractChildren = function (block) {
  25323. var children = getChildrenUntilBlockBoundary(block)
  25324. each$k(children, remove$7)
  25325. return children
  25326. }
  25327. var removeEmptyRoot = function (rootNode, block) {
  25328. var parents = parentsAndSelf(block, rootNode)
  25329. return find$3(parents.reverse(), function (element) {
  25330. return isEmpty$2(element)
  25331. }).each(remove$7)
  25332. }
  25333. var isEmptyBefore = function (el) {
  25334. return (
  25335. filter$4(prevSiblings(el), function (el) {
  25336. return !isEmpty$2(el)
  25337. }).length === 0
  25338. )
  25339. }
  25340. var nestedBlockMerge = function (
  25341. rootNode,
  25342. fromBlock,
  25343. toBlock,
  25344. insertionPoint
  25345. ) {
  25346. if (isEmpty$2(toBlock)) {
  25347. fillWithPaddingBr(toBlock)
  25348. return firstPositionIn(toBlock.dom)
  25349. }
  25350. if (isEmptyBefore(insertionPoint) && isEmpty$2(fromBlock)) {
  25351. before$4(insertionPoint, SugarElement.fromTag('br'))
  25352. }
  25353. var position = prevPosition(
  25354. toBlock.dom,
  25355. CaretPosition.before(insertionPoint.dom)
  25356. )
  25357. each$k(extractChildren(fromBlock), function (child) {
  25358. before$4(insertionPoint, child)
  25359. })
  25360. removeEmptyRoot(rootNode, fromBlock)
  25361. return position
  25362. }
  25363. var sidelongBlockMerge = function (rootNode, fromBlock, toBlock) {
  25364. if (isEmpty$2(toBlock)) {
  25365. remove$7(toBlock)
  25366. if (isEmpty$2(fromBlock)) {
  25367. fillWithPaddingBr(fromBlock)
  25368. }
  25369. return firstPositionIn(fromBlock.dom)
  25370. }
  25371. var position = lastPositionIn(toBlock.dom)
  25372. each$k(extractChildren(fromBlock), function (child) {
  25373. append$1(toBlock, child)
  25374. })
  25375. removeEmptyRoot(rootNode, fromBlock)
  25376. return position
  25377. }
  25378. var findInsertionPoint = function (toBlock, block) {
  25379. var parentsAndSelf$1 = parentsAndSelf(block, toBlock)
  25380. return Optional.from(parentsAndSelf$1[parentsAndSelf$1.length - 1])
  25381. }
  25382. var getInsertionPoint = function (fromBlock, toBlock) {
  25383. return contains$1(toBlock, fromBlock)
  25384. ? findInsertionPoint(toBlock, fromBlock)
  25385. : Optional.none()
  25386. }
  25387. var trimBr = function (first, block) {
  25388. positionIn(first, block.dom)
  25389. .map(function (position) {
  25390. return position.getNode()
  25391. })
  25392. .map(SugarElement.fromDom)
  25393. .filter(isBr$4)
  25394. .each(remove$7)
  25395. }
  25396. var mergeBlockInto = function (rootNode, fromBlock, toBlock) {
  25397. trimBr(true, fromBlock)
  25398. trimBr(false, toBlock)
  25399. return getInsertionPoint(fromBlock, toBlock).fold(
  25400. curry(sidelongBlockMerge, rootNode, fromBlock, toBlock),
  25401. curry(nestedBlockMerge, rootNode, fromBlock, toBlock)
  25402. )
  25403. }
  25404. var mergeBlocks = function (rootNode, forward, block1, block2) {
  25405. return forward
  25406. ? mergeBlockInto(rootNode, block2, block1)
  25407. : mergeBlockInto(rootNode, block1, block2)
  25408. }
  25409. var backspaceDelete$8 = function (editor, forward) {
  25410. var rootNode = SugarElement.fromDom(editor.getBody())
  25411. var position = read$1(
  25412. rootNode.dom,
  25413. forward,
  25414. editor.selection.getRng()
  25415. ).bind(function (blockBoundary) {
  25416. return mergeBlocks(
  25417. rootNode,
  25418. forward,
  25419. blockBoundary.from.block,
  25420. blockBoundary.to.block
  25421. )
  25422. })
  25423. position.each(function (pos) {
  25424. editor.selection.setRng(pos.toRange())
  25425. })
  25426. return position.isSome()
  25427. }
  25428. var deleteRangeMergeBlocks = function (rootNode, selection) {
  25429. var rng = selection.getRng()
  25430. return lift2(
  25431. getParentBlock$1(rootNode, SugarElement.fromDom(rng.startContainer)),
  25432. getParentBlock$1(rootNode, SugarElement.fromDom(rng.endContainer)),
  25433. function (block1, block2) {
  25434. if (eq(block1, block2) === false) {
  25435. rng.deleteContents()
  25436. mergeBlocks(rootNode, true, block1, block2).each(function (pos) {
  25437. selection.setRng(pos.toRange())
  25438. })
  25439. return true
  25440. } else {
  25441. return false
  25442. }
  25443. }
  25444. ).getOr(false)
  25445. }
  25446. var isRawNodeInTable = function (root, rawNode) {
  25447. var node = SugarElement.fromDom(rawNode)
  25448. var isRoot = curry(eq, root)
  25449. return ancestor$3(node, isTableCell$4, isRoot).isSome()
  25450. }
  25451. var isSelectionInTable = function (root, rng) {
  25452. return (
  25453. isRawNodeInTable(root, rng.startContainer) ||
  25454. isRawNodeInTable(root, rng.endContainer)
  25455. )
  25456. }
  25457. var isEverythingSelected = function (root, rng) {
  25458. var noPrevious = prevPosition(
  25459. root.dom,
  25460. CaretPosition.fromRangeStart(rng)
  25461. ).isNone()
  25462. var noNext = nextPosition(
  25463. root.dom,
  25464. CaretPosition.fromRangeEnd(rng)
  25465. ).isNone()
  25466. return !isSelectionInTable(root, rng) && noPrevious && noNext
  25467. }
  25468. var emptyEditor = function (editor) {
  25469. editor.setContent('')
  25470. editor.selection.setCursorLocation()
  25471. return true
  25472. }
  25473. var deleteRange$1 = function (editor) {
  25474. var rootNode = SugarElement.fromDom(editor.getBody())
  25475. var rng = editor.selection.getRng()
  25476. return isEverythingSelected(rootNode, rng)
  25477. ? emptyEditor(editor)
  25478. : deleteRangeMergeBlocks(rootNode, editor.selection)
  25479. }
  25480. var backspaceDelete$7 = function (editor, _forward) {
  25481. return editor.selection.isCollapsed() ? false : deleteRange$1(editor)
  25482. }
  25483. var isContentEditableTrue$2 = isContentEditableTrue$4
  25484. var isContentEditableFalse$4 = isContentEditableFalse$b
  25485. var showCaret = function (direction, editor, node, before, scrollIntoView) {
  25486. return Optional.from(
  25487. editor._selectionOverrides.showCaret(
  25488. direction,
  25489. node,
  25490. before,
  25491. scrollIntoView
  25492. )
  25493. )
  25494. }
  25495. var getNodeRange = function (node) {
  25496. var rng = node.ownerDocument.createRange()
  25497. rng.selectNode(node)
  25498. return rng
  25499. }
  25500. var selectNode = function (editor, node) {
  25501. var e = editor.fire('BeforeObjectSelected', { target: node })
  25502. if (e.isDefaultPrevented()) {
  25503. return Optional.none()
  25504. }
  25505. return Optional.some(getNodeRange(node))
  25506. }
  25507. var renderCaretAtRange = function (editor, range, scrollIntoView) {
  25508. var normalizedRange = normalizeRange(1, editor.getBody(), range)
  25509. var caretPosition = CaretPosition.fromRangeStart(normalizedRange)
  25510. var caretPositionNode = caretPosition.getNode()
  25511. if (isInlineFakeCaretTarget(caretPositionNode)) {
  25512. return showCaret(
  25513. 1,
  25514. editor,
  25515. caretPositionNode,
  25516. !caretPosition.isAtEnd(),
  25517. false
  25518. )
  25519. }
  25520. var caretPositionBeforeNode = caretPosition.getNode(true)
  25521. if (isInlineFakeCaretTarget(caretPositionBeforeNode)) {
  25522. return showCaret(1, editor, caretPositionBeforeNode, false, false)
  25523. }
  25524. var ceRoot = editor.dom.getParent(caretPosition.getNode(), function (node) {
  25525. return isContentEditableFalse$4(node) || isContentEditableTrue$2(node)
  25526. })
  25527. if (isInlineFakeCaretTarget(ceRoot)) {
  25528. return showCaret(1, editor, ceRoot, false, scrollIntoView)
  25529. }
  25530. return Optional.none()
  25531. }
  25532. var renderRangeCaret = function (editor, range, scrollIntoView) {
  25533. return range.collapsed
  25534. ? renderCaretAtRange(editor, range, scrollIntoView).getOr(range)
  25535. : range
  25536. }
  25537. var isBeforeBoundary = function (pos) {
  25538. return isBeforeContentEditableFalse(pos) || isBeforeMedia(pos)
  25539. }
  25540. var isAfterBoundary = function (pos) {
  25541. return isAfterContentEditableFalse(pos) || isAfterMedia(pos)
  25542. }
  25543. var trimEmptyTextNode = function (dom, node) {
  25544. if (isText$7(node) && node.data.length === 0) {
  25545. dom.remove(node)
  25546. }
  25547. }
  25548. var deleteContentAndShowCaret = function (
  25549. editor,
  25550. range,
  25551. node,
  25552. direction,
  25553. forward,
  25554. peekCaretPosition
  25555. ) {
  25556. showCaret(
  25557. direction,
  25558. editor,
  25559. peekCaretPosition.getNode(!forward),
  25560. forward,
  25561. true
  25562. ).each(function (caretRange) {
  25563. if (range.collapsed) {
  25564. var deleteRange = range.cloneRange()
  25565. if (forward) {
  25566. deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset)
  25567. } else {
  25568. deleteRange.setStart(caretRange.endContainer, caretRange.endOffset)
  25569. }
  25570. deleteRange.deleteContents()
  25571. } else {
  25572. range.deleteContents()
  25573. }
  25574. editor.selection.setRng(caretRange)
  25575. })
  25576. trimEmptyTextNode(editor.dom, node)
  25577. return true
  25578. }
  25579. var deleteBoundaryText = function (editor, forward) {
  25580. var range = editor.selection.getRng()
  25581. if (!isText$7(range.commonAncestorContainer)) {
  25582. return false
  25583. }
  25584. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  25585. var caretWalker = CaretWalker(editor.getBody())
  25586. var getNextPosFn = curry(
  25587. getVisualCaretPosition,
  25588. forward ? caretWalker.next : caretWalker.prev
  25589. )
  25590. var isBeforeFn = forward ? isBeforeBoundary : isAfterBoundary
  25591. var caretPosition = getNormalizedRangeEndPoint(
  25592. direction,
  25593. editor.getBody(),
  25594. range
  25595. )
  25596. var nextCaretPosition = normalizePosition(
  25597. forward,
  25598. getNextPosFn(caretPosition)
  25599. )
  25600. if (
  25601. !nextCaretPosition ||
  25602. !isMoveInsideSameBlock(caretPosition, nextCaretPosition)
  25603. ) {
  25604. return false
  25605. } else if (isBeforeFn(nextCaretPosition)) {
  25606. return deleteContentAndShowCaret(
  25607. editor,
  25608. range,
  25609. caretPosition.getNode(),
  25610. direction,
  25611. forward,
  25612. nextCaretPosition
  25613. )
  25614. }
  25615. var peekCaretPosition = getNextPosFn(nextCaretPosition)
  25616. if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
  25617. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  25618. return deleteContentAndShowCaret(
  25619. editor,
  25620. range,
  25621. caretPosition.getNode(),
  25622. direction,
  25623. forward,
  25624. peekCaretPosition
  25625. )
  25626. }
  25627. }
  25628. return false
  25629. }
  25630. var backspaceDelete$6 = function (editor, forward) {
  25631. return deleteBoundaryText(editor, forward)
  25632. }
  25633. var isCompoundElement = function (node) {
  25634. return (
  25635. isTableCell$4(SugarElement.fromDom(node)) ||
  25636. isListItem(SugarElement.fromDom(node))
  25637. )
  25638. }
  25639. var DeleteAction = Adt.generate([
  25640. { remove: ['element'] },
  25641. { moveToElement: ['element'] },
  25642. { moveToPosition: ['position'] },
  25643. ])
  25644. var isAtContentEditableBlockCaret = function (forward, from) {
  25645. var elm = from.getNode(forward === false)
  25646. var caretLocation = forward ? 'after' : 'before'
  25647. return (
  25648. isElement$5(elm) && elm.getAttribute('data-mce-caret') === caretLocation
  25649. )
  25650. }
  25651. var isDeleteFromCefDifferentBlocks = function (root, forward, from, to) {
  25652. var inSameBlock = function (elm) {
  25653. return (
  25654. isInline$1(SugarElement.fromDom(elm)) && !isInSameBlock(from, to, root)
  25655. )
  25656. }
  25657. return getRelativeCefElm(!forward, from).fold(function () {
  25658. return getRelativeCefElm(forward, to).fold(never, inSameBlock)
  25659. }, inSameBlock)
  25660. }
  25661. var deleteEmptyBlockOrMoveToCef = function (root, forward, from, to) {
  25662. var toCefElm = to.getNode(forward === false)
  25663. return getParentBlock$1(
  25664. SugarElement.fromDom(root),
  25665. SugarElement.fromDom(from.getNode())
  25666. )
  25667. .map(function (blockElm) {
  25668. return isEmpty$2(blockElm)
  25669. ? DeleteAction.remove(blockElm.dom)
  25670. : DeleteAction.moveToElement(toCefElm)
  25671. })
  25672. .orThunk(function () {
  25673. return Optional.some(DeleteAction.moveToElement(toCefElm))
  25674. })
  25675. }
  25676. var findCefPosition = function (root, forward, from) {
  25677. return fromPosition(forward, root, from).bind(function (to) {
  25678. if (isCompoundElement(to.getNode())) {
  25679. return Optional.none()
  25680. } else if (isDeleteFromCefDifferentBlocks(root, forward, from, to)) {
  25681. return Optional.none()
  25682. } else if (forward && isContentEditableFalse$b(to.getNode())) {
  25683. return deleteEmptyBlockOrMoveToCef(root, forward, from, to)
  25684. } else if (
  25685. forward === false &&
  25686. isContentEditableFalse$b(to.getNode(true))
  25687. ) {
  25688. return deleteEmptyBlockOrMoveToCef(root, forward, from, to)
  25689. } else if (forward && isAfterContentEditableFalse(from)) {
  25690. return Optional.some(DeleteAction.moveToPosition(to))
  25691. } else if (forward === false && isBeforeContentEditableFalse(from)) {
  25692. return Optional.some(DeleteAction.moveToPosition(to))
  25693. } else {
  25694. return Optional.none()
  25695. }
  25696. })
  25697. }
  25698. var getContentEditableBlockAction = function (forward, elm) {
  25699. if (forward && isContentEditableFalse$b(elm.nextSibling)) {
  25700. return Optional.some(DeleteAction.moveToElement(elm.nextSibling))
  25701. } else if (
  25702. forward === false &&
  25703. isContentEditableFalse$b(elm.previousSibling)
  25704. ) {
  25705. return Optional.some(DeleteAction.moveToElement(elm.previousSibling))
  25706. } else {
  25707. return Optional.none()
  25708. }
  25709. }
  25710. var skipMoveToActionFromInlineCefToContent = function (
  25711. root,
  25712. from,
  25713. deleteAction
  25714. ) {
  25715. return deleteAction.fold(
  25716. function (elm) {
  25717. return Optional.some(DeleteAction.remove(elm))
  25718. },
  25719. function (elm) {
  25720. return Optional.some(DeleteAction.moveToElement(elm))
  25721. },
  25722. function (to) {
  25723. if (isInSameBlock(from, to, root)) {
  25724. return Optional.none()
  25725. } else {
  25726. return Optional.some(DeleteAction.moveToPosition(to))
  25727. }
  25728. }
  25729. )
  25730. }
  25731. var getContentEditableAction = function (root, forward, from) {
  25732. if (isAtContentEditableBlockCaret(forward, from)) {
  25733. return getContentEditableBlockAction(
  25734. forward,
  25735. from.getNode(forward === false)
  25736. ).fold(function () {
  25737. return findCefPosition(root, forward, from)
  25738. }, Optional.some)
  25739. } else {
  25740. return findCefPosition(root, forward, from).bind(function (deleteAction) {
  25741. return skipMoveToActionFromInlineCefToContent(root, from, deleteAction)
  25742. })
  25743. }
  25744. }
  25745. var read = function (root, forward, rng) {
  25746. var normalizedRange = normalizeRange(forward ? 1 : -1, root, rng)
  25747. var from = CaretPosition.fromRangeStart(normalizedRange)
  25748. var rootElement = SugarElement.fromDom(root)
  25749. if (forward === false && isAfterContentEditableFalse(from)) {
  25750. return Optional.some(DeleteAction.remove(from.getNode(true)))
  25751. } else if (forward && isBeforeContentEditableFalse(from)) {
  25752. return Optional.some(DeleteAction.remove(from.getNode()))
  25753. } else if (
  25754. forward === false &&
  25755. isBeforeContentEditableFalse(from) &&
  25756. isAfterBr(rootElement, from)
  25757. ) {
  25758. return findPreviousBr(rootElement, from).map(function (br) {
  25759. return DeleteAction.remove(br.getNode())
  25760. })
  25761. } else if (
  25762. forward &&
  25763. isAfterContentEditableFalse(from) &&
  25764. isBeforeBr$1(rootElement, from)
  25765. ) {
  25766. return findNextBr(rootElement, from).map(function (br) {
  25767. return DeleteAction.remove(br.getNode())
  25768. })
  25769. } else {
  25770. return getContentEditableAction(root, forward, from)
  25771. }
  25772. }
  25773. var deleteElement$1 = function (editor, forward) {
  25774. return function (element) {
  25775. editor._selectionOverrides.hideFakeCaret()
  25776. deleteElement$2(editor, forward, SugarElement.fromDom(element))
  25777. return true
  25778. }
  25779. }
  25780. var moveToElement = function (editor, forward) {
  25781. return function (element) {
  25782. var pos = forward
  25783. ? CaretPosition.before(element)
  25784. : CaretPosition.after(element)
  25785. editor.selection.setRng(pos.toRange())
  25786. return true
  25787. }
  25788. }
  25789. var moveToPosition = function (editor) {
  25790. return function (pos) {
  25791. editor.selection.setRng(pos.toRange())
  25792. return true
  25793. }
  25794. }
  25795. var getAncestorCe = function (editor, node) {
  25796. return Optional.from(getContentEditableRoot$1(editor.getBody(), node))
  25797. }
  25798. var backspaceDeleteCaret = function (editor, forward) {
  25799. var selectedNode = editor.selection.getNode()
  25800. return getAncestorCe(editor, selectedNode)
  25801. .filter(isContentEditableFalse$b)
  25802. .fold(function () {
  25803. return read(
  25804. editor.getBody(),
  25805. forward,
  25806. editor.selection.getRng()
  25807. ).exists(function (deleteAction) {
  25808. return deleteAction.fold(
  25809. deleteElement$1(editor, forward),
  25810. moveToElement(editor, forward),
  25811. moveToPosition(editor)
  25812. )
  25813. })
  25814. }, always)
  25815. }
  25816. var deleteOffscreenSelection = function (rootElement) {
  25817. each$k(descendants(rootElement, '.mce-offscreen-selection'), remove$7)
  25818. }
  25819. var backspaceDeleteRange = function (editor, forward) {
  25820. var selectedNode = editor.selection.getNode()
  25821. if (
  25822. isContentEditableFalse$b(selectedNode) &&
  25823. !isTableCell$5(selectedNode)
  25824. ) {
  25825. var hasCefAncestor = getAncestorCe(
  25826. editor,
  25827. selectedNode.parentNode
  25828. ).filter(isContentEditableFalse$b)
  25829. return hasCefAncestor.fold(function () {
  25830. deleteOffscreenSelection(SugarElement.fromDom(editor.getBody()))
  25831. deleteElement$2(
  25832. editor,
  25833. forward,
  25834. SugarElement.fromDom(editor.selection.getNode())
  25835. )
  25836. paddEmptyBody(editor)
  25837. return true
  25838. }, always)
  25839. }
  25840. return false
  25841. }
  25842. var paddEmptyElement = function (editor) {
  25843. var dom = editor.dom,
  25844. selection = editor.selection
  25845. var ceRoot = getContentEditableRoot$1(editor.getBody(), selection.getNode())
  25846. if (
  25847. isContentEditableTrue$4(ceRoot) &&
  25848. dom.isBlock(ceRoot) &&
  25849. dom.isEmpty(ceRoot)
  25850. ) {
  25851. var br = dom.create('br', { 'data-mce-bogus': '1' })
  25852. dom.setHTML(ceRoot, '')
  25853. ceRoot.appendChild(br)
  25854. selection.setRng(CaretPosition.before(br).toRange())
  25855. }
  25856. return true
  25857. }
  25858. var backspaceDelete$5 = function (editor, forward) {
  25859. if (editor.selection.isCollapsed()) {
  25860. return backspaceDeleteCaret(editor, forward)
  25861. } else {
  25862. return backspaceDeleteRange(editor, forward)
  25863. }
  25864. }
  25865. var deleteCaret$2 = function (editor, forward) {
  25866. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng())
  25867. return fromPosition(forward, editor.getBody(), fromPos)
  25868. .filter(function (pos) {
  25869. return forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos)
  25870. })
  25871. .bind(function (pos) {
  25872. return Optional.from(
  25873. getChildNodeAtRelativeOffset(forward ? 0 : -1, pos)
  25874. )
  25875. })
  25876. .exists(function (elm) {
  25877. editor.selection.select(elm)
  25878. return true
  25879. })
  25880. }
  25881. var backspaceDelete$4 = function (editor, forward) {
  25882. return editor.selection.isCollapsed()
  25883. ? deleteCaret$2(editor, forward)
  25884. : false
  25885. }
  25886. var isText = isText$7
  25887. var startsWithCaretContainer = function (node) {
  25888. return isText(node) && node.data[0] === ZWSP$1
  25889. }
  25890. var endsWithCaretContainer = function (node) {
  25891. return isText(node) && node.data[node.data.length - 1] === ZWSP$1
  25892. }
  25893. var createZwsp = function (node) {
  25894. return node.ownerDocument.createTextNode(ZWSP$1)
  25895. }
  25896. var insertBefore = function (node) {
  25897. if (isText(node.previousSibling)) {
  25898. if (endsWithCaretContainer(node.previousSibling)) {
  25899. return node.previousSibling
  25900. } else {
  25901. node.previousSibling.appendData(ZWSP$1)
  25902. return node.previousSibling
  25903. }
  25904. } else if (isText(node)) {
  25905. if (startsWithCaretContainer(node)) {
  25906. return node
  25907. } else {
  25908. node.insertData(0, ZWSP$1)
  25909. return node
  25910. }
  25911. } else {
  25912. var newNode = createZwsp(node)
  25913. node.parentNode.insertBefore(newNode, node)
  25914. return newNode
  25915. }
  25916. }
  25917. var insertAfter = function (node) {
  25918. if (isText(node.nextSibling)) {
  25919. if (startsWithCaretContainer(node.nextSibling)) {
  25920. return node.nextSibling
  25921. } else {
  25922. node.nextSibling.insertData(0, ZWSP$1)
  25923. return node.nextSibling
  25924. }
  25925. } else if (isText(node)) {
  25926. if (endsWithCaretContainer(node)) {
  25927. return node
  25928. } else {
  25929. node.appendData(ZWSP$1)
  25930. return node
  25931. }
  25932. } else {
  25933. var newNode = createZwsp(node)
  25934. if (node.nextSibling) {
  25935. node.parentNode.insertBefore(newNode, node.nextSibling)
  25936. } else {
  25937. node.parentNode.appendChild(newNode)
  25938. }
  25939. return newNode
  25940. }
  25941. }
  25942. var insertInline = function (before, node) {
  25943. return before ? insertBefore(node) : insertAfter(node)
  25944. }
  25945. var insertInlineBefore = curry(insertInline, true)
  25946. var insertInlineAfter = curry(insertInline, false)
  25947. var insertInlinePos = function (pos, before) {
  25948. if (isText$7(pos.container())) {
  25949. return insertInline(before, pos.container())
  25950. } else {
  25951. return insertInline(before, pos.getNode())
  25952. }
  25953. }
  25954. var isPosCaretContainer = function (pos, caret) {
  25955. var caretNode = caret.get()
  25956. return (
  25957. caretNode &&
  25958. pos.container() === caretNode &&
  25959. isCaretContainerInline(caretNode)
  25960. )
  25961. }
  25962. var renderCaret = function (caret, location) {
  25963. return location.fold(
  25964. function (element) {
  25965. remove$2(caret.get())
  25966. var text = insertInlineBefore(element)
  25967. caret.set(text)
  25968. return Optional.some(CaretPosition(text, text.length - 1))
  25969. },
  25970. function (element) {
  25971. return firstPositionIn(element).map(function (pos) {
  25972. if (!isPosCaretContainer(pos, caret)) {
  25973. remove$2(caret.get())
  25974. var text = insertInlinePos(pos, true)
  25975. caret.set(text)
  25976. return CaretPosition(text, 1)
  25977. } else {
  25978. return CaretPosition(caret.get(), 1)
  25979. }
  25980. })
  25981. },
  25982. function (element) {
  25983. return lastPositionIn(element).map(function (pos) {
  25984. if (!isPosCaretContainer(pos, caret)) {
  25985. remove$2(caret.get())
  25986. var text = insertInlinePos(pos, false)
  25987. caret.set(text)
  25988. return CaretPosition(text, text.length - 1)
  25989. } else {
  25990. return CaretPosition(caret.get(), caret.get().length - 1)
  25991. }
  25992. })
  25993. },
  25994. function (element) {
  25995. remove$2(caret.get())
  25996. var text = insertInlineAfter(element)
  25997. caret.set(text)
  25998. return Optional.some(CaretPosition(text, 1))
  25999. }
  26000. )
  26001. }
  26002. var evaluateUntil = function (fns, args) {
  26003. for (var i = 0; i < fns.length; i++) {
  26004. var result = fns[i].apply(null, args)
  26005. if (result.isSome()) {
  26006. return result
  26007. }
  26008. }
  26009. return Optional.none()
  26010. }
  26011. var Location = Adt.generate([
  26012. { before: ['element'] },
  26013. { start: ['element'] },
  26014. { end: ['element'] },
  26015. { after: ['element'] },
  26016. ])
  26017. var rescope$1 = function (rootNode, node) {
  26018. var parentBlock = getParentBlock$2(node, rootNode)
  26019. return parentBlock ? parentBlock : rootNode
  26020. }
  26021. var before = function (isInlineTarget, rootNode, pos) {
  26022. var nPos = normalizeForwards(pos)
  26023. var scope = rescope$1(rootNode, nPos.container())
  26024. return findRootInline(isInlineTarget, scope, nPos).fold(function () {
  26025. return nextPosition(scope, nPos)
  26026. .bind(curry(findRootInline, isInlineTarget, scope))
  26027. .map(function (inline) {
  26028. return Location.before(inline)
  26029. })
  26030. }, Optional.none)
  26031. }
  26032. var isNotInsideFormatCaretContainer = function (rootNode, elm) {
  26033. return getParentCaretContainer(rootNode, elm) === null
  26034. }
  26035. var findInsideRootInline = function (isInlineTarget, rootNode, pos) {
  26036. return findRootInline(isInlineTarget, rootNode, pos).filter(
  26037. curry(isNotInsideFormatCaretContainer, rootNode)
  26038. )
  26039. }
  26040. var start$1 = function (isInlineTarget, rootNode, pos) {
  26041. var nPos = normalizeBackwards(pos)
  26042. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (
  26043. inline
  26044. ) {
  26045. var prevPos = prevPosition(inline, nPos)
  26046. return prevPos.isNone()
  26047. ? Optional.some(Location.start(inline))
  26048. : Optional.none()
  26049. })
  26050. }
  26051. var end = function (isInlineTarget, rootNode, pos) {
  26052. var nPos = normalizeForwards(pos)
  26053. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (
  26054. inline
  26055. ) {
  26056. var nextPos = nextPosition(inline, nPos)
  26057. return nextPos.isNone()
  26058. ? Optional.some(Location.end(inline))
  26059. : Optional.none()
  26060. })
  26061. }
  26062. var after = function (isInlineTarget, rootNode, pos) {
  26063. var nPos = normalizeBackwards(pos)
  26064. var scope = rescope$1(rootNode, nPos.container())
  26065. return findRootInline(isInlineTarget, scope, nPos).fold(function () {
  26066. return prevPosition(scope, nPos)
  26067. .bind(curry(findRootInline, isInlineTarget, scope))
  26068. .map(function (inline) {
  26069. return Location.after(inline)
  26070. })
  26071. }, Optional.none)
  26072. }
  26073. var isValidLocation = function (location) {
  26074. return isRtl(getElement(location)) === false
  26075. }
  26076. var readLocation = function (isInlineTarget, rootNode, pos) {
  26077. var location = evaluateUntil(
  26078. [before, start$1, end, after],
  26079. [isInlineTarget, rootNode, pos]
  26080. )
  26081. return location.filter(isValidLocation)
  26082. }
  26083. var getElement = function (location) {
  26084. return location.fold(identity, identity, identity, identity)
  26085. }
  26086. var getName = function (location) {
  26087. return location.fold(
  26088. constant('before'),
  26089. constant('start'),
  26090. constant('end'),
  26091. constant('after')
  26092. )
  26093. }
  26094. var outside = function (location) {
  26095. return location.fold(
  26096. Location.before,
  26097. Location.before,
  26098. Location.after,
  26099. Location.after
  26100. )
  26101. }
  26102. var inside = function (location) {
  26103. return location.fold(
  26104. Location.start,
  26105. Location.start,
  26106. Location.end,
  26107. Location.end
  26108. )
  26109. }
  26110. var isEq = function (location1, location2) {
  26111. return (
  26112. getName(location1) === getName(location2) &&
  26113. getElement(location1) === getElement(location2)
  26114. )
  26115. }
  26116. var betweenInlines = function (
  26117. forward,
  26118. isInlineTarget,
  26119. rootNode,
  26120. from,
  26121. to,
  26122. location
  26123. ) {
  26124. return lift2(
  26125. findRootInline(isInlineTarget, rootNode, from),
  26126. findRootInline(isInlineTarget, rootNode, to),
  26127. function (fromInline, toInline) {
  26128. if (
  26129. fromInline !== toInline &&
  26130. hasSameParentBlock(rootNode, fromInline, toInline)
  26131. ) {
  26132. return Location.after(forward ? fromInline : toInline)
  26133. } else {
  26134. return location
  26135. }
  26136. }
  26137. ).getOr(location)
  26138. }
  26139. var skipNoMovement = function (fromLocation, toLocation) {
  26140. return fromLocation.fold(always, function (fromLocation) {
  26141. return !isEq(fromLocation, toLocation)
  26142. })
  26143. }
  26144. var findLocationTraverse = function (
  26145. forward,
  26146. isInlineTarget,
  26147. rootNode,
  26148. fromLocation,
  26149. pos
  26150. ) {
  26151. var from = normalizePosition(forward, pos)
  26152. var to = fromPosition(forward, rootNode, from).map(
  26153. curry(normalizePosition, forward)
  26154. )
  26155. var location = to.fold(
  26156. function () {
  26157. return fromLocation.map(outside)
  26158. },
  26159. function (to) {
  26160. return readLocation(isInlineTarget, rootNode, to)
  26161. .map(
  26162. curry(betweenInlines, forward, isInlineTarget, rootNode, from, to)
  26163. )
  26164. .filter(curry(skipNoMovement, fromLocation))
  26165. }
  26166. )
  26167. return location.filter(isValidLocation)
  26168. }
  26169. var findLocationSimple = function (forward, location) {
  26170. if (forward) {
  26171. return location.fold(
  26172. compose(Optional.some, Location.start),
  26173. Optional.none,
  26174. compose(Optional.some, Location.after),
  26175. Optional.none
  26176. )
  26177. } else {
  26178. return location.fold(
  26179. Optional.none,
  26180. compose(Optional.some, Location.before),
  26181. Optional.none,
  26182. compose(Optional.some, Location.end)
  26183. )
  26184. }
  26185. }
  26186. var findLocation$1 = function (forward, isInlineTarget, rootNode, pos) {
  26187. var from = normalizePosition(forward, pos)
  26188. var fromLocation = readLocation(isInlineTarget, rootNode, from)
  26189. return readLocation(isInlineTarget, rootNode, from)
  26190. .bind(curry(findLocationSimple, forward))
  26191. .orThunk(function () {
  26192. return findLocationTraverse(
  26193. forward,
  26194. isInlineTarget,
  26195. rootNode,
  26196. fromLocation,
  26197. pos
  26198. )
  26199. })
  26200. }
  26201. curry(findLocation$1, false)
  26202. curry(findLocation$1, true)
  26203. var hasSelectionModifyApi = function (editor) {
  26204. return isFunction(editor.selection.getSel().modify)
  26205. }
  26206. var moveRel = function (forward, selection, pos) {
  26207. var delta = forward ? 1 : -1
  26208. selection.setRng(
  26209. CaretPosition(pos.container(), pos.offset() + delta).toRange()
  26210. )
  26211. selection.getSel().modify('move', forward ? 'forward' : 'backward', 'word')
  26212. return true
  26213. }
  26214. var moveByWord = function (forward, editor) {
  26215. var rng = editor.selection.getRng()
  26216. var pos = forward
  26217. ? CaretPosition.fromRangeEnd(rng)
  26218. : CaretPosition.fromRangeStart(rng)
  26219. if (!hasSelectionModifyApi(editor)) {
  26220. return false
  26221. } else if (forward && isBeforeInline(pos)) {
  26222. return moveRel(true, editor.selection, pos)
  26223. } else if (!forward && isAfterInline(pos)) {
  26224. return moveRel(false, editor.selection, pos)
  26225. } else {
  26226. return false
  26227. }
  26228. }
  26229. var BreakType
  26230. ;(function (BreakType) {
  26231. BreakType[(BreakType['Br'] = 0)] = 'Br'
  26232. BreakType[(BreakType['Block'] = 1)] = 'Block'
  26233. BreakType[(BreakType['Wrap'] = 2)] = 'Wrap'
  26234. BreakType[(BreakType['Eol'] = 3)] = 'Eol'
  26235. })(BreakType || (BreakType = {}))
  26236. var flip = function (direction, positions) {
  26237. return direction === HDirection.Backwards ? reverse(positions) : positions
  26238. }
  26239. var walk = function (direction, caretWalker, pos) {
  26240. return direction === HDirection.Forwards
  26241. ? caretWalker.next(pos)
  26242. : caretWalker.prev(pos)
  26243. }
  26244. var getBreakType = function (scope, direction, currentPos, nextPos) {
  26245. if (isBr$5(nextPos.getNode(direction === HDirection.Forwards))) {
  26246. return BreakType.Br
  26247. } else if (isInSameBlock(currentPos, nextPos) === false) {
  26248. return BreakType.Block
  26249. } else {
  26250. return BreakType.Wrap
  26251. }
  26252. }
  26253. var getPositionsUntil = function (predicate, direction, scope, start) {
  26254. var caretWalker = CaretWalker(scope)
  26255. var currentPos = start
  26256. var positions = []
  26257. while (currentPos) {
  26258. var nextPos = walk(direction, caretWalker, currentPos)
  26259. if (!nextPos) {
  26260. break
  26261. }
  26262. if (isBr$5(nextPos.getNode(false))) {
  26263. if (direction === HDirection.Forwards) {
  26264. return {
  26265. positions: flip(direction, positions).concat([nextPos]),
  26266. breakType: BreakType.Br,
  26267. breakAt: Optional.some(nextPos),
  26268. }
  26269. } else {
  26270. return {
  26271. positions: flip(direction, positions),
  26272. breakType: BreakType.Br,
  26273. breakAt: Optional.some(nextPos),
  26274. }
  26275. }
  26276. }
  26277. if (!nextPos.isVisible()) {
  26278. currentPos = nextPos
  26279. continue
  26280. }
  26281. if (predicate(currentPos, nextPos)) {
  26282. var breakType = getBreakType(scope, direction, currentPos, nextPos)
  26283. return {
  26284. positions: flip(direction, positions),
  26285. breakType: breakType,
  26286. breakAt: Optional.some(nextPos),
  26287. }
  26288. }
  26289. positions.push(nextPos)
  26290. currentPos = nextPos
  26291. }
  26292. return {
  26293. positions: flip(direction, positions),
  26294. breakType: BreakType.Eol,
  26295. breakAt: Optional.none(),
  26296. }
  26297. }
  26298. var getAdjacentLinePositions = function (
  26299. direction,
  26300. getPositionsUntilBreak,
  26301. scope,
  26302. start
  26303. ) {
  26304. return getPositionsUntilBreak(scope, start)
  26305. .breakAt.map(function (pos) {
  26306. var positions = getPositionsUntilBreak(scope, pos).positions
  26307. return direction === HDirection.Backwards
  26308. ? positions.concat(pos)
  26309. : [pos].concat(positions)
  26310. })
  26311. .getOr([])
  26312. }
  26313. var findClosestHorizontalPositionFromPoint = function (positions, x) {
  26314. return foldl(
  26315. positions,
  26316. function (acc, newPos) {
  26317. return acc.fold(
  26318. function () {
  26319. return Optional.some(newPos)
  26320. },
  26321. function (lastPos) {
  26322. return lift2(
  26323. head(lastPos.getClientRects()),
  26324. head(newPos.getClientRects()),
  26325. function (lastRect, newRect) {
  26326. var lastDist = Math.abs(x - lastRect.left)
  26327. var newDist = Math.abs(x - newRect.left)
  26328. return newDist <= lastDist ? newPos : lastPos
  26329. }
  26330. ).or(acc)
  26331. }
  26332. )
  26333. },
  26334. Optional.none()
  26335. )
  26336. }
  26337. var findClosestHorizontalPosition = function (positions, pos) {
  26338. return head(pos.getClientRects()).bind(function (targetRect) {
  26339. return findClosestHorizontalPositionFromPoint(positions, targetRect.left)
  26340. })
  26341. }
  26342. var getPositionsUntilPreviousLine = curry(
  26343. getPositionsUntil,
  26344. CaretPosition.isAbove,
  26345. -1
  26346. )
  26347. var getPositionsUntilNextLine = curry(
  26348. getPositionsUntil,
  26349. CaretPosition.isBelow,
  26350. 1
  26351. )
  26352. var getPositionsAbove = curry(
  26353. getAdjacentLinePositions,
  26354. -1,
  26355. getPositionsUntilPreviousLine
  26356. )
  26357. var getPositionsBelow = curry(
  26358. getAdjacentLinePositions,
  26359. 1,
  26360. getPositionsUntilNextLine
  26361. )
  26362. var isAtFirstLine = function (scope, pos) {
  26363. return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone()
  26364. }
  26365. var isAtLastLine = function (scope, pos) {
  26366. return getPositionsUntilNextLine(scope, pos).breakAt.isNone()
  26367. }
  26368. var getFirstLinePositions = function (scope) {
  26369. return firstPositionIn(scope)
  26370. .map(function (pos) {
  26371. return [pos].concat(getPositionsUntilNextLine(scope, pos).positions)
  26372. })
  26373. .getOr([])
  26374. }
  26375. var getLastLinePositions = function (scope) {
  26376. return lastPositionIn(scope)
  26377. .map(function (pos) {
  26378. return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos)
  26379. })
  26380. .getOr([])
  26381. }
  26382. var getNodeClientRects = function (node) {
  26383. var toArrayWithNode = function (clientRects) {
  26384. return map$3(clientRects, function (rect) {
  26385. var clientRect = clone(rect)
  26386. clientRect.node = node
  26387. return clientRect
  26388. })
  26389. }
  26390. if (isElement$5(node)) {
  26391. return toArrayWithNode(node.getClientRects())
  26392. }
  26393. if (isText$7(node)) {
  26394. var rng = node.ownerDocument.createRange()
  26395. rng.setStart(node, 0)
  26396. rng.setEnd(node, node.data.length)
  26397. return toArrayWithNode(rng.getClientRects())
  26398. }
  26399. }
  26400. var getClientRects = function (nodes) {
  26401. return bind(nodes, getNodeClientRects)
  26402. }
  26403. var VDirection
  26404. ;(function (VDirection) {
  26405. VDirection[(VDirection['Up'] = -1)] = 'Up'
  26406. VDirection[(VDirection['Down'] = 1)] = 'Down'
  26407. })(VDirection || (VDirection = {}))
  26408. var findUntil = function (direction, root, predicateFn, node) {
  26409. while (
  26410. (node = findNode$1(node, direction, isEditableCaretCandidate$1, root))
  26411. ) {
  26412. if (predicateFn(node)) {
  26413. return
  26414. }
  26415. }
  26416. }
  26417. var walkUntil$1 = function (
  26418. direction,
  26419. isAboveFn,
  26420. isBeflowFn,
  26421. root,
  26422. predicateFn,
  26423. caretPosition
  26424. ) {
  26425. var line = 0
  26426. var result = []
  26427. var add = function (node) {
  26428. var clientRects = getClientRects([node])
  26429. if (direction === -1) {
  26430. clientRects = clientRects.reverse()
  26431. }
  26432. for (var i = 0; i < clientRects.length; i++) {
  26433. var clientRect = clientRects[i]
  26434. if (isBeflowFn(clientRect, targetClientRect)) {
  26435. continue
  26436. }
  26437. if (result.length > 0 && isAboveFn(clientRect, last$1(result))) {
  26438. line++
  26439. }
  26440. clientRect.line = line
  26441. if (predicateFn(clientRect)) {
  26442. return true
  26443. }
  26444. result.push(clientRect)
  26445. }
  26446. }
  26447. var targetClientRect = last$1(caretPosition.getClientRects())
  26448. if (!targetClientRect) {
  26449. return result
  26450. }
  26451. var node = caretPosition.getNode()
  26452. add(node)
  26453. findUntil(direction, root, add, node)
  26454. return result
  26455. }
  26456. var aboveLineNumber = function (lineNumber, clientRect) {
  26457. return clientRect.line > lineNumber
  26458. }
  26459. var isLineNumber = function (lineNumber, clientRect) {
  26460. return clientRect.line === lineNumber
  26461. }
  26462. var upUntil = curry(walkUntil$1, VDirection.Up, isAbove$1, isBelow$1)
  26463. var downUntil = curry(walkUntil$1, VDirection.Down, isBelow$1, isAbove$1)
  26464. var positionsUntil = function (direction, root, predicateFn, node) {
  26465. var caretWalker = CaretWalker(root)
  26466. var walkFn
  26467. var isBelowFn
  26468. var isAboveFn
  26469. var caretPosition
  26470. var result = []
  26471. var line = 0
  26472. var getClientRect = function (caretPosition) {
  26473. if (direction === 1) {
  26474. return last$1(caretPosition.getClientRects())
  26475. }
  26476. return last$1(caretPosition.getClientRects())
  26477. }
  26478. if (direction === 1) {
  26479. walkFn = caretWalker.next
  26480. isBelowFn = isBelow$1
  26481. isAboveFn = isAbove$1
  26482. caretPosition = CaretPosition.after(node)
  26483. } else {
  26484. walkFn = caretWalker.prev
  26485. isBelowFn = isAbove$1
  26486. isAboveFn = isBelow$1
  26487. caretPosition = CaretPosition.before(node)
  26488. }
  26489. var targetClientRect = getClientRect(caretPosition)
  26490. do {
  26491. if (!caretPosition.isVisible()) {
  26492. continue
  26493. }
  26494. var rect = getClientRect(caretPosition)
  26495. if (isAboveFn(rect, targetClientRect)) {
  26496. continue
  26497. }
  26498. if (result.length > 0 && isBelowFn(rect, last$1(result))) {
  26499. line++
  26500. }
  26501. var clientRect = clone(rect)
  26502. clientRect.position = caretPosition
  26503. clientRect.line = line
  26504. if (predicateFn(clientRect)) {
  26505. return result
  26506. }
  26507. result.push(clientRect)
  26508. } while ((caretPosition = walkFn(caretPosition)))
  26509. return result
  26510. }
  26511. var isAboveLine = function (lineNumber) {
  26512. return function (clientRect) {
  26513. return aboveLineNumber(lineNumber, clientRect)
  26514. }
  26515. }
  26516. var isLine = function (lineNumber) {
  26517. return function (clientRect) {
  26518. return isLineNumber(lineNumber, clientRect)
  26519. }
  26520. }
  26521. var isContentEditableFalse$3 = isContentEditableFalse$b
  26522. var findNode = findNode$1
  26523. var distanceToRectLeft = function (clientRect, clientX) {
  26524. return Math.abs(clientRect.left - clientX)
  26525. }
  26526. var distanceToRectRight = function (clientRect, clientX) {
  26527. return Math.abs(clientRect.right - clientX)
  26528. }
  26529. var isInsideX = function (clientX, clientRect) {
  26530. return clientX >= clientRect.left && clientX <= clientRect.right
  26531. }
  26532. var isInsideY = function (clientY, clientRect) {
  26533. return clientY >= clientRect.top && clientY <= clientRect.bottom
  26534. }
  26535. var isNodeClientRect = function (rect) {
  26536. return hasNonNullableKey(rect, 'node')
  26537. }
  26538. var findClosestClientRect = function (clientRects, clientX, allowInside) {
  26539. if (allowInside === void 0) {
  26540. allowInside = always
  26541. }
  26542. return reduce(clientRects, function (oldClientRect, clientRect) {
  26543. if (isInsideX(clientX, clientRect)) {
  26544. return allowInside(clientRect) ? clientRect : oldClientRect
  26545. }
  26546. if (isInsideX(clientX, oldClientRect)) {
  26547. return allowInside(oldClientRect) ? oldClientRect : clientRect
  26548. }
  26549. var oldDistance = Math.min(
  26550. distanceToRectLeft(oldClientRect, clientX),
  26551. distanceToRectRight(oldClientRect, clientX)
  26552. )
  26553. var newDistance = Math.min(
  26554. distanceToRectLeft(clientRect, clientX),
  26555. distanceToRectRight(clientRect, clientX)
  26556. )
  26557. if (
  26558. newDistance === oldDistance &&
  26559. isNodeClientRect(clientRect) &&
  26560. isContentEditableFalse$3(clientRect.node)
  26561. ) {
  26562. return clientRect
  26563. }
  26564. if (newDistance < oldDistance) {
  26565. return clientRect
  26566. }
  26567. return oldClientRect
  26568. })
  26569. }
  26570. var walkUntil = function (
  26571. direction,
  26572. root,
  26573. predicateFn,
  26574. startNode,
  26575. includeChildren
  26576. ) {
  26577. var node = findNode(
  26578. startNode,
  26579. direction,
  26580. isEditableCaretCandidate$1,
  26581. root,
  26582. !includeChildren
  26583. )
  26584. do {
  26585. if (!node || predicateFn(node)) {
  26586. return
  26587. }
  26588. } while (
  26589. (node = findNode(node, direction, isEditableCaretCandidate$1, root))
  26590. )
  26591. }
  26592. var findLineNodeRects = function (root, targetNodeRect, includeChildren) {
  26593. if (includeChildren === void 0) {
  26594. includeChildren = true
  26595. }
  26596. var clientRects = []
  26597. var collect = function (checkPosFn, node) {
  26598. var lineRects = filter$4(getClientRects([node]), function (clientRect) {
  26599. return !checkPosFn(clientRect, targetNodeRect)
  26600. })
  26601. clientRects = clientRects.concat(lineRects)
  26602. return lineRects.length === 0
  26603. }
  26604. clientRects.push(targetNodeRect)
  26605. walkUntil(
  26606. VDirection.Up,
  26607. root,
  26608. curry(collect, isAbove$1),
  26609. targetNodeRect.node,
  26610. includeChildren
  26611. )
  26612. walkUntil(
  26613. VDirection.Down,
  26614. root,
  26615. curry(collect, isBelow$1),
  26616. targetNodeRect.node,
  26617. includeChildren
  26618. )
  26619. return clientRects
  26620. }
  26621. var getFakeCaretTargets = function (root) {
  26622. return filter$4(from(root.getElementsByTagName('*')), isFakeCaretTarget)
  26623. }
  26624. var caretInfo = function (clientRect, clientX) {
  26625. return {
  26626. node: clientRect.node,
  26627. before:
  26628. distanceToRectLeft(clientRect, clientX) <
  26629. distanceToRectRight(clientRect, clientX),
  26630. }
  26631. }
  26632. var closestFakeCaret = function (root, clientX, clientY) {
  26633. var fakeTargetNodeRects = getClientRects(getFakeCaretTargets(root))
  26634. var targetNodeRects = filter$4(
  26635. fakeTargetNodeRects,
  26636. curry(isInsideY, clientY)
  26637. )
  26638. var checkInside = function (clientRect) {
  26639. return !isTable$3(clientRect.node) && !isMedia$2(clientRect.node)
  26640. }
  26641. var closestNodeRect = findClosestClientRect(
  26642. targetNodeRects,
  26643. clientX,
  26644. checkInside
  26645. )
  26646. if (closestNodeRect) {
  26647. var includeChildren = checkInside(closestNodeRect)
  26648. closestNodeRect = findClosestClientRect(
  26649. findLineNodeRects(root, closestNodeRect, includeChildren),
  26650. clientX,
  26651. checkInside
  26652. )
  26653. if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
  26654. return caretInfo(closestNodeRect, clientX)
  26655. }
  26656. }
  26657. return null
  26658. }
  26659. var moveToRange = function (editor, rng) {
  26660. editor.selection.setRng(rng)
  26661. scrollRangeIntoView(editor, editor.selection.getRng())
  26662. }
  26663. var renderRangeCaretOpt = function (editor, range, scrollIntoView) {
  26664. return Optional.some(renderRangeCaret(editor, range, scrollIntoView))
  26665. }
  26666. var moveHorizontally = function (
  26667. editor,
  26668. direction,
  26669. range,
  26670. isBefore,
  26671. isAfter,
  26672. isElement
  26673. ) {
  26674. var forwards = direction === HDirection.Forwards
  26675. var caretWalker = CaretWalker(editor.getBody())
  26676. var getNextPosFn = curry(
  26677. getVisualCaretPosition,
  26678. forwards ? caretWalker.next : caretWalker.prev
  26679. )
  26680. var isBeforeFn = forwards ? isBefore : isAfter
  26681. if (!range.collapsed) {
  26682. var node = getSelectedNode(range)
  26683. if (isElement(node)) {
  26684. return showCaret(
  26685. direction,
  26686. editor,
  26687. node,
  26688. direction === HDirection.Backwards,
  26689. false
  26690. )
  26691. }
  26692. }
  26693. var caretPosition = getNormalizedRangeEndPoint(
  26694. direction,
  26695. editor.getBody(),
  26696. range
  26697. )
  26698. if (isBeforeFn(caretPosition)) {
  26699. return selectNode(editor, caretPosition.getNode(!forwards))
  26700. }
  26701. var nextCaretPosition = normalizePosition(
  26702. forwards,
  26703. getNextPosFn(caretPosition)
  26704. )
  26705. var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range)
  26706. if (!nextCaretPosition) {
  26707. return rangeIsInContainerBlock ? Optional.some(range) : Optional.none()
  26708. }
  26709. if (isBeforeFn(nextCaretPosition)) {
  26710. return showCaret(
  26711. direction,
  26712. editor,
  26713. nextCaretPosition.getNode(!forwards),
  26714. forwards,
  26715. false
  26716. )
  26717. }
  26718. var peekCaretPosition = getNextPosFn(nextCaretPosition)
  26719. if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
  26720. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  26721. return showCaret(
  26722. direction,
  26723. editor,
  26724. peekCaretPosition.getNode(!forwards),
  26725. forwards,
  26726. false
  26727. )
  26728. }
  26729. }
  26730. if (rangeIsInContainerBlock) {
  26731. return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false)
  26732. }
  26733. return Optional.none()
  26734. }
  26735. var moveVertically = function (
  26736. editor,
  26737. direction,
  26738. range,
  26739. isBefore,
  26740. isAfter,
  26741. isElement
  26742. ) {
  26743. var caretPosition = getNormalizedRangeEndPoint(
  26744. direction,
  26745. editor.getBody(),
  26746. range
  26747. )
  26748. var caretClientRect = last$1(caretPosition.getClientRects())
  26749. var forwards = direction === VDirection.Down
  26750. if (!caretClientRect) {
  26751. return Optional.none()
  26752. }
  26753. var walkerFn = forwards ? downUntil : upUntil
  26754. var linePositions = walkerFn(
  26755. editor.getBody(),
  26756. isAboveLine(1),
  26757. caretPosition
  26758. )
  26759. var nextLinePositions = filter$4(linePositions, isLine(1))
  26760. var clientX = caretClientRect.left
  26761. var nextLineRect = findClosestClientRect(nextLinePositions, clientX)
  26762. if (nextLineRect && isElement(nextLineRect.node)) {
  26763. var dist1 = Math.abs(clientX - nextLineRect.left)
  26764. var dist2 = Math.abs(clientX - nextLineRect.right)
  26765. return showCaret(
  26766. direction,
  26767. editor,
  26768. nextLineRect.node,
  26769. dist1 < dist2,
  26770. false
  26771. )
  26772. }
  26773. var currentNode
  26774. if (isBefore(caretPosition)) {
  26775. currentNode = caretPosition.getNode()
  26776. } else if (isAfter(caretPosition)) {
  26777. currentNode = caretPosition.getNode(true)
  26778. } else {
  26779. currentNode = getSelectedNode(range)
  26780. }
  26781. if (currentNode) {
  26782. var caretPositions = positionsUntil(
  26783. direction,
  26784. editor.getBody(),
  26785. isAboveLine(1),
  26786. currentNode
  26787. )
  26788. var closestNextLineRect = findClosestClientRect(
  26789. filter$4(caretPositions, isLine(1)),
  26790. clientX
  26791. )
  26792. if (closestNextLineRect) {
  26793. return renderRangeCaretOpt(
  26794. editor,
  26795. closestNextLineRect.position.toRange(),
  26796. false
  26797. )
  26798. }
  26799. closestNextLineRect = last$1(filter$4(caretPositions, isLine(0)))
  26800. if (closestNextLineRect) {
  26801. return renderRangeCaretOpt(
  26802. editor,
  26803. closestNextLineRect.position.toRange(),
  26804. false
  26805. )
  26806. }
  26807. }
  26808. if (nextLinePositions.length === 0) {
  26809. return getLineEndPoint(editor, forwards)
  26810. .filter(forwards ? isAfter : isBefore)
  26811. .map(function (pos) {
  26812. return renderRangeCaret(editor, pos.toRange(), false)
  26813. })
  26814. }
  26815. return Optional.none()
  26816. }
  26817. var getLineEndPoint = function (editor, forward) {
  26818. var rng = editor.selection.getRng()
  26819. var body = editor.getBody()
  26820. if (forward) {
  26821. var from = CaretPosition.fromRangeEnd(rng)
  26822. var result = getPositionsUntilNextLine(body, from)
  26823. return last$2(result.positions)
  26824. } else {
  26825. var from = CaretPosition.fromRangeStart(rng)
  26826. var result = getPositionsUntilPreviousLine(body, from)
  26827. return head(result.positions)
  26828. }
  26829. }
  26830. var moveToLineEndPoint$3 = function (editor, forward, isElementPosition) {
  26831. return getLineEndPoint(editor, forward)
  26832. .filter(isElementPosition)
  26833. .exists(function (pos) {
  26834. editor.selection.setRng(pos.toRange())
  26835. return true
  26836. })
  26837. }
  26838. var setCaretPosition = function (editor, pos) {
  26839. var rng = editor.dom.createRng()
  26840. rng.setStart(pos.container(), pos.offset())
  26841. rng.setEnd(pos.container(), pos.offset())
  26842. editor.selection.setRng(rng)
  26843. }
  26844. var setSelected = function (state, elm) {
  26845. if (state) {
  26846. elm.setAttribute('data-mce-selected', 'inline-boundary')
  26847. } else {
  26848. elm.removeAttribute('data-mce-selected')
  26849. }
  26850. }
  26851. var renderCaretLocation = function (editor, caret, location) {
  26852. return renderCaret(caret, location).map(function (pos) {
  26853. setCaretPosition(editor, pos)
  26854. return location
  26855. })
  26856. }
  26857. var findLocation = function (editor, caret, forward) {
  26858. var rootNode = editor.getBody()
  26859. var from = CaretPosition.fromRangeStart(editor.selection.getRng())
  26860. var isInlineTarget$1 = curry(isInlineTarget, editor)
  26861. var location = findLocation$1(forward, isInlineTarget$1, rootNode, from)
  26862. return location.bind(function (location) {
  26863. return renderCaretLocation(editor, caret, location)
  26864. })
  26865. }
  26866. var toggleInlines = function (isInlineTarget, dom, elms) {
  26867. var inlineBoundaries = map$3(
  26868. descendants(
  26869. SugarElement.fromDom(dom.getRoot()),
  26870. '*[data-mce-selected="inline-boundary"]'
  26871. ),
  26872. function (e) {
  26873. return e.dom
  26874. }
  26875. )
  26876. var selectedInlines = filter$4(inlineBoundaries, isInlineTarget)
  26877. var targetInlines = filter$4(elms, isInlineTarget)
  26878. each$k(
  26879. difference(selectedInlines, targetInlines),
  26880. curry(setSelected, false)
  26881. )
  26882. each$k(difference(targetInlines, selectedInlines), curry(setSelected, true))
  26883. }
  26884. var safeRemoveCaretContainer = function (editor, caret) {
  26885. if (
  26886. editor.selection.isCollapsed() &&
  26887. editor.composing !== true &&
  26888. caret.get()
  26889. ) {
  26890. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  26891. if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) {
  26892. setCaretPosition(editor, removeAndReposition(caret.get(), pos))
  26893. caret.set(null)
  26894. }
  26895. }
  26896. }
  26897. var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) {
  26898. if (editor.selection.isCollapsed()) {
  26899. var inlines = filter$4(elms, isInlineTarget)
  26900. each$k(inlines, function (_inline) {
  26901. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  26902. readLocation(isInlineTarget, editor.getBody(), pos).bind(function (
  26903. location
  26904. ) {
  26905. return renderCaretLocation(editor, caret, location)
  26906. })
  26907. })
  26908. }
  26909. }
  26910. var move$2 = function (editor, caret, forward) {
  26911. return isInlineBoundariesEnabled(editor)
  26912. ? findLocation(editor, caret, forward).isSome()
  26913. : false
  26914. }
  26915. var moveWord = function (forward, editor, _caret) {
  26916. return isInlineBoundariesEnabled(editor)
  26917. ? moveByWord(forward, editor)
  26918. : false
  26919. }
  26920. var setupSelectedState = function (editor) {
  26921. var caret = Cell(null)
  26922. var isInlineTarget$1 = curry(isInlineTarget, editor)
  26923. editor.on('NodeChange', function (e) {
  26924. if (
  26925. isInlineBoundariesEnabled(editor) &&
  26926. !(Env.browser.isIE() && e.initial)
  26927. ) {
  26928. toggleInlines(isInlineTarget$1, editor.dom, e.parents)
  26929. safeRemoveCaretContainer(editor, caret)
  26930. renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents)
  26931. }
  26932. })
  26933. return caret
  26934. }
  26935. var moveNextWord = curry(moveWord, true)
  26936. var movePrevWord = curry(moveWord, false)
  26937. var moveToLineEndPoint$2 = function (editor, forward, caret) {
  26938. if (isInlineBoundariesEnabled(editor)) {
  26939. var linePoint = getLineEndPoint(editor, forward).getOrThunk(function () {
  26940. var rng = editor.selection.getRng()
  26941. return forward
  26942. ? CaretPosition.fromRangeEnd(rng)
  26943. : CaretPosition.fromRangeStart(rng)
  26944. })
  26945. return readLocation(
  26946. curry(isInlineTarget, editor),
  26947. editor.getBody(),
  26948. linePoint
  26949. ).exists(function (loc) {
  26950. var outsideLoc = outside(loc)
  26951. return renderCaret(caret, outsideLoc).exists(function (pos) {
  26952. setCaretPosition(editor, pos)
  26953. return true
  26954. })
  26955. })
  26956. } else {
  26957. return false
  26958. }
  26959. }
  26960. var rangeFromPositions = function (from, to) {
  26961. var range = document.createRange()
  26962. range.setStart(from.container(), from.offset())
  26963. range.setEnd(to.container(), to.offset())
  26964. return range
  26965. }
  26966. var hasOnlyTwoOrLessPositionsLeft = function (elm) {
  26967. return lift2(
  26968. firstPositionIn(elm),
  26969. lastPositionIn(elm),
  26970. function (firstPos, lastPos) {
  26971. var normalizedFirstPos = normalizePosition(true, firstPos)
  26972. var normalizedLastPos = normalizePosition(false, lastPos)
  26973. return nextPosition(elm, normalizedFirstPos).forall(function (pos) {
  26974. return pos.isEqual(normalizedLastPos)
  26975. })
  26976. }
  26977. ).getOr(true)
  26978. }
  26979. var setCaretLocation = function (editor, caret) {
  26980. return function (location) {
  26981. return renderCaret(caret, location).exists(function (pos) {
  26982. setCaretPosition(editor, pos)
  26983. return true
  26984. })
  26985. }
  26986. }
  26987. var deleteFromTo = function (editor, caret, from, to) {
  26988. var rootNode = editor.getBody()
  26989. var isInlineTarget$1 = curry(isInlineTarget, editor)
  26990. editor.undoManager.ignore(function () {
  26991. editor.selection.setRng(rangeFromPositions(from, to))
  26992. editor.execCommand('Delete')
  26993. readLocation(
  26994. isInlineTarget$1,
  26995. rootNode,
  26996. CaretPosition.fromRangeStart(editor.selection.getRng())
  26997. )
  26998. .map(inside)
  26999. .map(setCaretLocation(editor, caret))
  27000. })
  27001. editor.nodeChanged()
  27002. }
  27003. var rescope = function (rootNode, node) {
  27004. var parentBlock = getParentBlock$2(node, rootNode)
  27005. return parentBlock ? parentBlock : rootNode
  27006. }
  27007. var backspaceDeleteCollapsed = function (editor, caret, forward, from) {
  27008. var rootNode = rescope(editor.getBody(), from.container())
  27009. var isInlineTarget$1 = curry(isInlineTarget, editor)
  27010. var fromLocation = readLocation(isInlineTarget$1, rootNode, from)
  27011. return fromLocation
  27012. .bind(function (location) {
  27013. if (forward) {
  27014. return location.fold(
  27015. constant(Optional.some(inside(location))),
  27016. Optional.none,
  27017. constant(Optional.some(outside(location))),
  27018. Optional.none
  27019. )
  27020. } else {
  27021. return location.fold(
  27022. Optional.none,
  27023. constant(Optional.some(outside(location))),
  27024. Optional.none,
  27025. constant(Optional.some(inside(location)))
  27026. )
  27027. }
  27028. })
  27029. .map(setCaretLocation(editor, caret))
  27030. .getOrThunk(function () {
  27031. var toPosition = navigate(forward, rootNode, from)
  27032. var toLocation = toPosition.bind(function (pos) {
  27033. return readLocation(isInlineTarget$1, rootNode, pos)
  27034. })
  27035. return lift2(fromLocation, toLocation, function () {
  27036. return findRootInline(isInlineTarget$1, rootNode, from).exists(
  27037. function (elm) {
  27038. if (hasOnlyTwoOrLessPositionsLeft(elm)) {
  27039. deleteElement$2(editor, forward, SugarElement.fromDom(elm))
  27040. return true
  27041. } else {
  27042. return false
  27043. }
  27044. }
  27045. )
  27046. })
  27047. .orThunk(function () {
  27048. return toLocation.bind(function (_) {
  27049. return toPosition.map(function (to) {
  27050. if (forward) {
  27051. deleteFromTo(editor, caret, from, to)
  27052. } else {
  27053. deleteFromTo(editor, caret, to, from)
  27054. }
  27055. return true
  27056. })
  27057. })
  27058. })
  27059. .getOr(false)
  27060. })
  27061. }
  27062. var backspaceDelete$3 = function (editor, caret, forward) {
  27063. if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) {
  27064. var from = CaretPosition.fromRangeStart(editor.selection.getRng())
  27065. return backspaceDeleteCollapsed(editor, caret, forward, from)
  27066. }
  27067. return false
  27068. }
  27069. var getParentInlines = function (rootElm, startElm) {
  27070. var parents = parentsAndSelf(startElm, rootElm)
  27071. return findIndex$2(parents, isBlock$2).fold(
  27072. constant(parents),
  27073. function (index) {
  27074. return parents.slice(0, index)
  27075. }
  27076. )
  27077. }
  27078. var hasOnlyOneChild = function (elm) {
  27079. return childNodesCount(elm) === 1
  27080. }
  27081. var deleteLastPosition = function (forward, editor, target, parentInlines) {
  27082. var isFormatElement$1 = curry(isFormatElement, editor)
  27083. var formatNodes = map$3(
  27084. filter$4(parentInlines, isFormatElement$1),
  27085. function (elm) {
  27086. return elm.dom
  27087. }
  27088. )
  27089. if (formatNodes.length === 0) {
  27090. deleteElement$2(editor, forward, target)
  27091. } else {
  27092. var pos = replaceWithCaretFormat(target.dom, formatNodes)
  27093. editor.selection.setRng(pos.toRange())
  27094. }
  27095. }
  27096. var deleteCaret$1 = function (editor, forward) {
  27097. var rootElm = SugarElement.fromDom(editor.getBody())
  27098. var startElm = SugarElement.fromDom(editor.selection.getStart())
  27099. var parentInlines = filter$4(
  27100. getParentInlines(rootElm, startElm),
  27101. hasOnlyOneChild
  27102. )
  27103. return last$2(parentInlines).exists(function (target) {
  27104. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng())
  27105. if (
  27106. willDeleteLastPositionInElement(forward, fromPos, target.dom) &&
  27107. !isEmptyCaretFormatElement(target)
  27108. ) {
  27109. deleteLastPosition(forward, editor, target, parentInlines)
  27110. return true
  27111. } else {
  27112. return false
  27113. }
  27114. })
  27115. }
  27116. var backspaceDelete$2 = function (editor, forward) {
  27117. return editor.selection.isCollapsed()
  27118. ? deleteCaret$1(editor, forward)
  27119. : false
  27120. }
  27121. var deleteElement = function (editor, forward, element) {
  27122. editor._selectionOverrides.hideFakeCaret()
  27123. deleteElement$2(editor, forward, SugarElement.fromDom(element))
  27124. return true
  27125. }
  27126. var deleteCaret = function (editor, forward) {
  27127. var isNearMedia = forward ? isBeforeMedia : isAfterMedia
  27128. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  27129. var fromPos = getNormalizedRangeEndPoint(
  27130. direction,
  27131. editor.getBody(),
  27132. editor.selection.getRng()
  27133. )
  27134. if (isNearMedia(fromPos)) {
  27135. return deleteElement(editor, forward, fromPos.getNode(!forward))
  27136. } else {
  27137. return Optional.from(normalizePosition(forward, fromPos))
  27138. .filter(function (pos) {
  27139. return isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos)
  27140. })
  27141. .exists(function (pos) {
  27142. return deleteElement(editor, forward, pos.getNode(!forward))
  27143. })
  27144. }
  27145. }
  27146. var deleteRange = function (editor, forward) {
  27147. var selectedNode = editor.selection.getNode()
  27148. return isMedia$2(selectedNode)
  27149. ? deleteElement(editor, forward, selectedNode)
  27150. : false
  27151. }
  27152. var backspaceDelete$1 = function (editor, forward) {
  27153. return editor.selection.isCollapsed()
  27154. ? deleteCaret(editor, forward)
  27155. : deleteRange(editor, forward)
  27156. }
  27157. var isEditable = function (target) {
  27158. return closest$3(target, function (elm) {
  27159. return (
  27160. isContentEditableTrue$4(elm.dom) || isContentEditableFalse$b(elm.dom)
  27161. )
  27162. }).exists(function (elm) {
  27163. return isContentEditableTrue$4(elm.dom)
  27164. })
  27165. }
  27166. var parseIndentValue = function (value) {
  27167. var number = parseInt(value, 10)
  27168. return isNaN(number) ? 0 : number
  27169. }
  27170. var getIndentStyleName = function (useMargin, element) {
  27171. var indentStyleName = useMargin || isTable$2(element) ? 'margin' : 'padding'
  27172. var suffix = get$5(element, 'direction') === 'rtl' ? '-right' : '-left'
  27173. return indentStyleName + suffix
  27174. }
  27175. var indentElement = function (dom, command, useMargin, value, unit, element) {
  27176. var indentStyleName = getIndentStyleName(
  27177. useMargin,
  27178. SugarElement.fromDom(element)
  27179. )
  27180. if (command === 'outdent') {
  27181. var styleValue = Math.max(
  27182. 0,
  27183. parseIndentValue(element.style[indentStyleName]) - value
  27184. )
  27185. dom.setStyle(
  27186. element,
  27187. indentStyleName,
  27188. styleValue ? styleValue + unit : ''
  27189. )
  27190. } else {
  27191. var styleValue =
  27192. parseIndentValue(element.style[indentStyleName]) + value + unit
  27193. dom.setStyle(element, indentStyleName, styleValue)
  27194. }
  27195. }
  27196. var validateBlocks = function (editor, blocks) {
  27197. return forall(blocks, function (block) {
  27198. var indentStyleName = getIndentStyleName(
  27199. shouldIndentUseMargin(editor),
  27200. block
  27201. )
  27202. var intentValue = getRaw(block, indentStyleName)
  27203. .map(parseIndentValue)
  27204. .getOr(0)
  27205. var contentEditable = editor.dom.getContentEditable(block.dom)
  27206. return contentEditable !== 'false' && intentValue > 0
  27207. })
  27208. }
  27209. var canOutdent = function (editor) {
  27210. var blocks = getBlocksToIndent(editor)
  27211. return (
  27212. !editor.mode.isReadOnly() &&
  27213. (blocks.length > 1 || validateBlocks(editor, blocks))
  27214. )
  27215. }
  27216. var isListComponent = function (el) {
  27217. return isList(el) || isListItem(el)
  27218. }
  27219. var parentIsListComponent = function (el) {
  27220. return parent(el).exists(isListComponent)
  27221. }
  27222. var getBlocksToIndent = function (editor) {
  27223. return filter$4(
  27224. fromDom$1(editor.selection.getSelectedBlocks()),
  27225. function (el) {
  27226. return (
  27227. !isListComponent(el) && !parentIsListComponent(el) && isEditable(el)
  27228. )
  27229. }
  27230. )
  27231. }
  27232. var handle = function (editor, command) {
  27233. var dom = editor.dom,
  27234. selection = editor.selection,
  27235. formatter = editor.formatter
  27236. var indentation = getIndentation(editor)
  27237. var indentUnit = /[a-z%]+$/i.exec(indentation)[0]
  27238. var indentValue = parseInt(indentation, 10)
  27239. var useMargin = shouldIndentUseMargin(editor)
  27240. var forcedRootBlock = getForcedRootBlock(editor)
  27241. if (
  27242. !editor.queryCommandState('InsertUnorderedList') &&
  27243. !editor.queryCommandState('InsertOrderedList')
  27244. ) {
  27245. if (
  27246. forcedRootBlock === '' &&
  27247. !dom.getParent(selection.getNode(), dom.isBlock)
  27248. ) {
  27249. formatter.apply('div')
  27250. }
  27251. }
  27252. each$k(getBlocksToIndent(editor), function (block) {
  27253. indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom)
  27254. })
  27255. }
  27256. var backspaceDelete = function (editor, _forward) {
  27257. if (editor.selection.isCollapsed() && canOutdent(editor)) {
  27258. var dom = editor.dom
  27259. var rng = editor.selection.getRng()
  27260. var pos = CaretPosition.fromRangeStart(rng)
  27261. var block = dom.getParent(rng.startContainer, dom.isBlock)
  27262. if (
  27263. block !== null &&
  27264. isAtStartOfBlock(SugarElement.fromDom(block), pos)
  27265. ) {
  27266. handle(editor, 'outdent')
  27267. return true
  27268. }
  27269. }
  27270. return false
  27271. }
  27272. var nativeCommand = function (editor, command) {
  27273. editor.getDoc().execCommand(command, false, null)
  27274. }
  27275. var deleteCommand = function (editor, caret) {
  27276. if (backspaceDelete(editor)) {
  27277. return
  27278. } else if (backspaceDelete$5(editor, false)) {
  27279. return
  27280. } else if (backspaceDelete$6(editor, false)) {
  27281. return
  27282. } else if (backspaceDelete$3(editor, caret, false)) {
  27283. return
  27284. } else if (backspaceDelete$8(editor, false)) {
  27285. return
  27286. } else if (backspaceDelete$9(editor)) {
  27287. return
  27288. } else if (backspaceDelete$4(editor, false)) {
  27289. return
  27290. } else if (backspaceDelete$1(editor, false)) {
  27291. return
  27292. } else if (backspaceDelete$7(editor)) {
  27293. return
  27294. } else if (backspaceDelete$2(editor, false)) {
  27295. return
  27296. } else {
  27297. nativeCommand(editor, 'Delete')
  27298. paddEmptyBody(editor)
  27299. }
  27300. }
  27301. var forwardDeleteCommand = function (editor, caret) {
  27302. if (backspaceDelete$5(editor, true)) {
  27303. return
  27304. } else if (backspaceDelete$6(editor, true)) {
  27305. return
  27306. } else if (backspaceDelete$3(editor, caret, true)) {
  27307. return
  27308. } else if (backspaceDelete$8(editor, true)) {
  27309. return
  27310. } else if (backspaceDelete$9(editor)) {
  27311. return
  27312. } else if (backspaceDelete$4(editor, true)) {
  27313. return
  27314. } else if (backspaceDelete$1(editor, true)) {
  27315. return
  27316. } else if (backspaceDelete$7(editor)) {
  27317. return
  27318. } else if (backspaceDelete$2(editor, true)) {
  27319. return
  27320. } else {
  27321. nativeCommand(editor, 'ForwardDelete')
  27322. }
  27323. }
  27324. var setup$f = function (editor, caret) {
  27325. editor.addCommand('delete', function () {
  27326. deleteCommand(editor, caret)
  27327. })
  27328. editor.addCommand('forwardDelete', function () {
  27329. forwardDeleteCommand(editor, caret)
  27330. })
  27331. }
  27332. var SIGNIFICANT_MOVE = 5
  27333. var LONGPRESS_DELAY = 400
  27334. var getTouch = function (event) {
  27335. if (event.touches === undefined || event.touches.length !== 1) {
  27336. return Optional.none()
  27337. }
  27338. return Optional.some(event.touches[0])
  27339. }
  27340. var isFarEnough = function (touch, data) {
  27341. var distX = Math.abs(touch.clientX - data.x)
  27342. var distY = Math.abs(touch.clientY - data.y)
  27343. return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE
  27344. }
  27345. var setup$e = function (editor) {
  27346. var startData = value()
  27347. var longpressFired = Cell(false)
  27348. var debounceLongpress = last(function (e) {
  27349. editor.fire('longpress', __assign(__assign({}, e), { type: 'longpress' }))
  27350. longpressFired.set(true)
  27351. }, LONGPRESS_DELAY)
  27352. editor.on(
  27353. 'touchstart',
  27354. function (e) {
  27355. getTouch(e).each(function (touch) {
  27356. debounceLongpress.cancel()
  27357. var data = {
  27358. x: touch.clientX,
  27359. y: touch.clientY,
  27360. target: e.target,
  27361. }
  27362. debounceLongpress.throttle(e)
  27363. longpressFired.set(false)
  27364. startData.set(data)
  27365. })
  27366. },
  27367. true
  27368. )
  27369. editor.on(
  27370. 'touchmove',
  27371. function (e) {
  27372. debounceLongpress.cancel()
  27373. getTouch(e).each(function (touch) {
  27374. startData.on(function (data) {
  27375. if (isFarEnough(touch, data)) {
  27376. startData.clear()
  27377. longpressFired.set(false)
  27378. editor.fire('longpresscancel')
  27379. }
  27380. })
  27381. })
  27382. },
  27383. true
  27384. )
  27385. editor.on(
  27386. 'touchend touchcancel',
  27387. function (e) {
  27388. debounceLongpress.cancel()
  27389. if (e.type === 'touchcancel') {
  27390. return
  27391. }
  27392. startData
  27393. .get()
  27394. .filter(function (data) {
  27395. return data.target.isEqualNode(e.target)
  27396. })
  27397. .each(function () {
  27398. if (longpressFired.get()) {
  27399. e.preventDefault()
  27400. } else {
  27401. editor.fire('tap', __assign(__assign({}, e), { type: 'tap' }))
  27402. }
  27403. })
  27404. },
  27405. true
  27406. )
  27407. }
  27408. var isBlockElement = function (blockElements, node) {
  27409. return has$2(blockElements, node.nodeName)
  27410. }
  27411. var isValidTarget = function (blockElements, node) {
  27412. if (isText$7(node)) {
  27413. return true
  27414. } else if (isElement$5(node)) {
  27415. return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node)
  27416. } else {
  27417. return false
  27418. }
  27419. }
  27420. var hasBlockParent = function (blockElements, root, node) {
  27421. return exists(
  27422. parents(SugarElement.fromDom(node), SugarElement.fromDom(root)),
  27423. function (elm) {
  27424. return isBlockElement(blockElements, elm.dom)
  27425. }
  27426. )
  27427. }
  27428. var shouldRemoveTextNode = function (blockElements, node) {
  27429. if (isText$7(node)) {
  27430. if (node.nodeValue.length === 0) {
  27431. return true
  27432. } else if (
  27433. /^\s+$/.test(node.nodeValue) &&
  27434. (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))
  27435. ) {
  27436. return true
  27437. }
  27438. }
  27439. return false
  27440. }
  27441. var addRootBlocks = function (editor) {
  27442. var dom = editor.dom,
  27443. selection = editor.selection
  27444. var schema = editor.schema,
  27445. blockElements = schema.getBlockElements()
  27446. var node = selection.getStart()
  27447. var rootNode = editor.getBody()
  27448. var rootBlockNode, tempNode, wrapped
  27449. var forcedRootBlock = getForcedRootBlock(editor)
  27450. if (!node || !isElement$5(node) || !forcedRootBlock) {
  27451. return
  27452. }
  27453. var rootNodeName = rootNode.nodeName.toLowerCase()
  27454. if (
  27455. !schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) ||
  27456. hasBlockParent(blockElements, rootNode, node)
  27457. ) {
  27458. return
  27459. }
  27460. var rng = selection.getRng()
  27461. var startContainer = rng.startContainer
  27462. var startOffset = rng.startOffset
  27463. var endContainer = rng.endContainer
  27464. var endOffset = rng.endOffset
  27465. var restoreSelection = hasFocus(editor)
  27466. node = rootNode.firstChild
  27467. while (node) {
  27468. if (isValidTarget(blockElements, node)) {
  27469. if (shouldRemoveTextNode(blockElements, node)) {
  27470. tempNode = node
  27471. node = node.nextSibling
  27472. dom.remove(tempNode)
  27473. continue
  27474. }
  27475. if (!rootBlockNode) {
  27476. rootBlockNode = dom.create(
  27477. forcedRootBlock,
  27478. getForcedRootBlockAttrs(editor)
  27479. )
  27480. node.parentNode.insertBefore(rootBlockNode, node)
  27481. wrapped = true
  27482. }
  27483. tempNode = node
  27484. node = node.nextSibling
  27485. rootBlockNode.appendChild(tempNode)
  27486. } else {
  27487. rootBlockNode = null
  27488. node = node.nextSibling
  27489. }
  27490. }
  27491. if (wrapped && restoreSelection) {
  27492. rng.setStart(startContainer, startOffset)
  27493. rng.setEnd(endContainer, endOffset)
  27494. selection.setRng(rng)
  27495. editor.nodeChanged()
  27496. }
  27497. }
  27498. var setup$d = function (editor) {
  27499. if (getForcedRootBlock(editor)) {
  27500. editor.on('NodeChange', curry(addRootBlocks, editor))
  27501. }
  27502. }
  27503. var findBlockCaretContainer = function (editor) {
  27504. return descendant(
  27505. SugarElement.fromDom(editor.getBody()),
  27506. '*[data-mce-caret]'
  27507. )
  27508. .map(function (elm) {
  27509. return elm.dom
  27510. })
  27511. .getOrNull()
  27512. }
  27513. var removeIeControlRect = function (editor) {
  27514. editor.selection.setRng(editor.selection.getRng())
  27515. }
  27516. var showBlockCaretContainer = function (editor, blockCaretContainer) {
  27517. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  27518. showCaretContainerBlock(blockCaretContainer)
  27519. removeIeControlRect(editor)
  27520. editor.selection.scrollIntoView(blockCaretContainer)
  27521. }
  27522. }
  27523. var handleBlockContainer = function (editor, e) {
  27524. var blockCaretContainer = findBlockCaretContainer(editor)
  27525. if (!blockCaretContainer) {
  27526. return
  27527. }
  27528. if (e.type === 'compositionstart') {
  27529. e.preventDefault()
  27530. e.stopPropagation()
  27531. showBlockCaretContainer(editor, blockCaretContainer)
  27532. return
  27533. }
  27534. if (hasContent(blockCaretContainer)) {
  27535. showBlockCaretContainer(editor, blockCaretContainer)
  27536. editor.undoManager.add()
  27537. }
  27538. }
  27539. var setup$c = function (editor) {
  27540. editor.on('keyup compositionstart', curry(handleBlockContainer, editor))
  27541. }
  27542. var isContentEditableFalse$2 = isContentEditableFalse$b
  27543. var moveToCeFalseHorizontally = function (direction, editor, range) {
  27544. return moveHorizontally(
  27545. editor,
  27546. direction,
  27547. range,
  27548. isBeforeContentEditableFalse,
  27549. isAfterContentEditableFalse,
  27550. isContentEditableFalse$2
  27551. )
  27552. }
  27553. var moveToCeFalseVertically = function (direction, editor, range) {
  27554. var isBefore = function (caretPosition) {
  27555. return (
  27556. isBeforeContentEditableFalse(caretPosition) ||
  27557. isBeforeTable(caretPosition)
  27558. )
  27559. }
  27560. var isAfter = function (caretPosition) {
  27561. return (
  27562. isAfterContentEditableFalse(caretPosition) ||
  27563. isAfterTable(caretPosition)
  27564. )
  27565. }
  27566. return moveVertically(
  27567. editor,
  27568. direction,
  27569. range,
  27570. isBefore,
  27571. isAfter,
  27572. isContentEditableFalse$2
  27573. )
  27574. }
  27575. var createTextBlock = function (editor) {
  27576. var textBlock = editor.dom.create(getForcedRootBlock(editor))
  27577. if (!Env.ie || Env.ie >= 11) {
  27578. textBlock.innerHTML = '<br data-mce-bogus="1">'
  27579. }
  27580. return textBlock
  27581. }
  27582. var exitPreBlock = function (editor, direction, range) {
  27583. var caretWalker = CaretWalker(editor.getBody())
  27584. var getVisualCaretPosition$1 = curry(
  27585. getVisualCaretPosition,
  27586. direction === 1 ? caretWalker.next : caretWalker.prev
  27587. )
  27588. if (range.collapsed && hasForcedRootBlock(editor)) {
  27589. var pre = editor.dom.getParent(range.startContainer, 'PRE')
  27590. if (!pre) {
  27591. return
  27592. }
  27593. var caretPos = getVisualCaretPosition$1(
  27594. CaretPosition.fromRangeStart(range)
  27595. )
  27596. if (!caretPos) {
  27597. var newBlock = createTextBlock(editor)
  27598. if (direction === 1) {
  27599. editor.$(pre).after(newBlock)
  27600. } else {
  27601. editor.$(pre).before(newBlock)
  27602. }
  27603. editor.selection.select(newBlock, true)
  27604. editor.selection.collapse()
  27605. }
  27606. }
  27607. }
  27608. var getHorizontalRange = function (editor, forward) {
  27609. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  27610. var range = editor.selection.getRng()
  27611. return moveToCeFalseHorizontally(direction, editor, range).orThunk(
  27612. function () {
  27613. exitPreBlock(editor, direction, range)
  27614. return Optional.none()
  27615. }
  27616. )
  27617. }
  27618. var getVerticalRange = function (editor, down) {
  27619. var direction = down ? 1 : -1
  27620. var range = editor.selection.getRng()
  27621. return moveToCeFalseVertically(direction, editor, range).orThunk(
  27622. function () {
  27623. exitPreBlock(editor, direction, range)
  27624. return Optional.none()
  27625. }
  27626. )
  27627. }
  27628. var moveH$2 = function (editor, forward) {
  27629. return getHorizontalRange(editor, forward).exists(function (newRange) {
  27630. moveToRange(editor, newRange)
  27631. return true
  27632. })
  27633. }
  27634. var moveV$3 = function (editor, down) {
  27635. return getVerticalRange(editor, down).exists(function (newRange) {
  27636. moveToRange(editor, newRange)
  27637. return true
  27638. })
  27639. }
  27640. var moveToLineEndPoint$1 = function (editor, forward) {
  27641. var isCefPosition = forward
  27642. ? isAfterContentEditableFalse
  27643. : isBeforeContentEditableFalse
  27644. return moveToLineEndPoint$3(editor, forward, isCefPosition)
  27645. }
  27646. var isTarget = function (node) {
  27647. return contains$3(['figcaption'], name(node))
  27648. }
  27649. var rangeBefore = function (target) {
  27650. var rng = document.createRange()
  27651. rng.setStartBefore(target.dom)
  27652. rng.setEndBefore(target.dom)
  27653. return rng
  27654. }
  27655. var insertElement = function (root, elm, forward) {
  27656. if (forward) {
  27657. append$1(root, elm)
  27658. } else {
  27659. prepend(root, elm)
  27660. }
  27661. }
  27662. var insertBr = function (root, forward) {
  27663. var br = SugarElement.fromTag('br')
  27664. insertElement(root, br, forward)
  27665. return rangeBefore(br)
  27666. }
  27667. var insertBlock = function (root, forward, blockName, attrs) {
  27668. var block = SugarElement.fromTag(blockName)
  27669. var br = SugarElement.fromTag('br')
  27670. setAll$1(block, attrs)
  27671. append$1(block, br)
  27672. insertElement(root, block, forward)
  27673. return rangeBefore(br)
  27674. }
  27675. var insertEmptyLine = function (root, rootBlockName, attrs, forward) {
  27676. if (rootBlockName === '') {
  27677. return insertBr(root, forward)
  27678. } else {
  27679. return insertBlock(root, forward, rootBlockName, attrs)
  27680. }
  27681. }
  27682. var getClosestTargetBlock = function (pos, root) {
  27683. var isRoot = curry(eq, root)
  27684. return closest$3(
  27685. SugarElement.fromDom(pos.container()),
  27686. isBlock$2,
  27687. isRoot
  27688. ).filter(isTarget)
  27689. }
  27690. var isAtFirstOrLastLine = function (root, forward, pos) {
  27691. return forward ? isAtLastLine(root.dom, pos) : isAtFirstLine(root.dom, pos)
  27692. }
  27693. var moveCaretToNewEmptyLine = function (editor, forward) {
  27694. var root = SugarElement.fromDom(editor.getBody())
  27695. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  27696. var rootBlock = getForcedRootBlock(editor)
  27697. var rootBlockAttrs = getForcedRootBlockAttrs(editor)
  27698. return getClosestTargetBlock(pos, root).exists(function () {
  27699. if (isAtFirstOrLastLine(root, forward, pos)) {
  27700. var rng = insertEmptyLine(root, rootBlock, rootBlockAttrs, forward)
  27701. editor.selection.setRng(rng)
  27702. return true
  27703. } else {
  27704. return false
  27705. }
  27706. })
  27707. }
  27708. var moveV$2 = function (editor, forward) {
  27709. if (editor.selection.isCollapsed()) {
  27710. return moveCaretToNewEmptyLine(editor, forward)
  27711. } else {
  27712. return false
  27713. }
  27714. }
  27715. var defaultPatterns = function (patterns) {
  27716. return map$3(patterns, function (pattern) {
  27717. return __assign(
  27718. {
  27719. shiftKey: false,
  27720. altKey: false,
  27721. ctrlKey: false,
  27722. metaKey: false,
  27723. keyCode: 0,
  27724. action: noop,
  27725. },
  27726. pattern
  27727. )
  27728. })
  27729. }
  27730. var matchesEvent = function (pattern, evt) {
  27731. return (
  27732. evt.keyCode === pattern.keyCode &&
  27733. evt.shiftKey === pattern.shiftKey &&
  27734. evt.altKey === pattern.altKey &&
  27735. evt.ctrlKey === pattern.ctrlKey &&
  27736. evt.metaKey === pattern.metaKey
  27737. )
  27738. }
  27739. var match$1 = function (patterns, evt) {
  27740. return bind(defaultPatterns(patterns), function (pattern) {
  27741. return matchesEvent(pattern, evt) ? [pattern] : []
  27742. })
  27743. }
  27744. var action = function (f) {
  27745. var x = []
  27746. for (var _i = 1; _i < arguments.length; _i++) {
  27747. x[_i - 1] = arguments[_i]
  27748. }
  27749. return function () {
  27750. return f.apply(null, x)
  27751. }
  27752. }
  27753. var execute = function (patterns, evt) {
  27754. return find$3(match$1(patterns, evt), function (pattern) {
  27755. return pattern.action()
  27756. })
  27757. }
  27758. var moveH$1 = function (editor, forward) {
  27759. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  27760. var range = editor.selection.getRng()
  27761. return moveHorizontally(
  27762. editor,
  27763. direction,
  27764. range,
  27765. isBeforeMedia,
  27766. isAfterMedia,
  27767. isMedia$2
  27768. ).exists(function (newRange) {
  27769. moveToRange(editor, newRange)
  27770. return true
  27771. })
  27772. }
  27773. var moveV$1 = function (editor, down) {
  27774. var direction = down ? 1 : -1
  27775. var range = editor.selection.getRng()
  27776. return moveVertically(
  27777. editor,
  27778. direction,
  27779. range,
  27780. isBeforeMedia,
  27781. isAfterMedia,
  27782. isMedia$2
  27783. ).exists(function (newRange) {
  27784. moveToRange(editor, newRange)
  27785. return true
  27786. })
  27787. }
  27788. var moveToLineEndPoint = function (editor, forward) {
  27789. var isNearMedia = forward ? isAfterMedia : isBeforeMedia
  27790. return moveToLineEndPoint$3(editor, forward, isNearMedia)
  27791. }
  27792. var deflate = function (rect, delta) {
  27793. return {
  27794. left: rect.left - delta,
  27795. top: rect.top - delta,
  27796. right: rect.right + delta * 2,
  27797. bottom: rect.bottom + delta * 2,
  27798. width: rect.width + delta,
  27799. height: rect.height + delta,
  27800. }
  27801. }
  27802. var getCorners = function (getYAxisValue, tds) {
  27803. return bind(tds, function (td) {
  27804. var rect = deflate(clone(td.getBoundingClientRect()), -1)
  27805. return [
  27806. {
  27807. x: rect.left,
  27808. y: getYAxisValue(rect),
  27809. cell: td,
  27810. },
  27811. {
  27812. x: rect.right,
  27813. y: getYAxisValue(rect),
  27814. cell: td,
  27815. },
  27816. ]
  27817. })
  27818. }
  27819. var findClosestCorner = function (corners, x, y) {
  27820. return foldl(
  27821. corners,
  27822. function (acc, newCorner) {
  27823. return acc.fold(
  27824. function () {
  27825. return Optional.some(newCorner)
  27826. },
  27827. function (oldCorner) {
  27828. var oldDist = Math.sqrt(
  27829. Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y)
  27830. )
  27831. var newDist = Math.sqrt(
  27832. Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y)
  27833. )
  27834. return Optional.some(newDist < oldDist ? newCorner : oldCorner)
  27835. }
  27836. )
  27837. },
  27838. Optional.none()
  27839. )
  27840. }
  27841. var getClosestCell = function (getYAxisValue, isTargetCorner, table, x, y) {
  27842. var cells = descendants(SugarElement.fromDom(table), 'td,th,caption').map(
  27843. function (e) {
  27844. return e.dom
  27845. }
  27846. )
  27847. var corners = filter$4(getCorners(getYAxisValue, cells), function (corner) {
  27848. return isTargetCorner(corner, y)
  27849. })
  27850. return findClosestCorner(corners, x, y).map(function (corner) {
  27851. return corner.cell
  27852. })
  27853. }
  27854. var getBottomValue = function (rect) {
  27855. return rect.bottom
  27856. }
  27857. var getTopValue = function (rect) {
  27858. return rect.top
  27859. }
  27860. var isAbove = function (corner, y) {
  27861. return corner.y < y
  27862. }
  27863. var isBelow = function (corner, y) {
  27864. return corner.y > y
  27865. }
  27866. var getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove)
  27867. var getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow)
  27868. var findClosestPositionInAboveCell = function (table, pos) {
  27869. return head(pos.getClientRects())
  27870. .bind(function (rect) {
  27871. return getClosestCellAbove(table, rect.left, rect.top)
  27872. })
  27873. .bind(function (cell) {
  27874. return findClosestHorizontalPosition(getLastLinePositions(cell), pos)
  27875. })
  27876. }
  27877. var findClosestPositionInBelowCell = function (table, pos) {
  27878. return last$2(pos.getClientRects())
  27879. .bind(function (rect) {
  27880. return getClosestCellBelow(table, rect.left, rect.top)
  27881. })
  27882. .bind(function (cell) {
  27883. return findClosestHorizontalPosition(getFirstLinePositions(cell), pos)
  27884. })
  27885. }
  27886. var hasNextBreak = function (getPositionsUntil, scope, lineInfo) {
  27887. return lineInfo.breakAt.exists(function (breakPos) {
  27888. return getPositionsUntil(scope, breakPos).breakAt.isSome()
  27889. })
  27890. }
  27891. var startsWithWrapBreak = function (lineInfo) {
  27892. return (
  27893. lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0
  27894. )
  27895. }
  27896. var startsWithBrBreak = function (lineInfo) {
  27897. return (
  27898. lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1
  27899. )
  27900. }
  27901. var isAtTableCellLine = function (getPositionsUntil, scope, pos) {
  27902. var lineInfo = getPositionsUntil(scope, pos)
  27903. if (
  27904. startsWithWrapBreak(lineInfo) ||
  27905. (!isBr$5(pos.getNode()) && startsWithBrBreak(lineInfo))
  27906. ) {
  27907. return !hasNextBreak(getPositionsUntil, scope, lineInfo)
  27908. } else {
  27909. return lineInfo.breakAt.isNone()
  27910. }
  27911. }
  27912. var isAtFirstTableCellLine = curry(
  27913. isAtTableCellLine,
  27914. getPositionsUntilPreviousLine
  27915. )
  27916. var isAtLastTableCellLine = curry(
  27917. isAtTableCellLine,
  27918. getPositionsUntilNextLine
  27919. )
  27920. var isCaretAtStartOrEndOfTable = function (forward, rng, table) {
  27921. var caretPos = CaretPosition.fromRangeStart(rng)
  27922. return positionIn(!forward, table).exists(function (pos) {
  27923. return pos.isEqual(caretPos)
  27924. })
  27925. }
  27926. var navigateHorizontally = function (editor, forward, table, _td) {
  27927. var rng = editor.selection.getRng()
  27928. var direction = forward ? 1 : -1
  27929. if (
  27930. isFakeCaretTableBrowser() &&
  27931. isCaretAtStartOrEndOfTable(forward, rng, table)
  27932. ) {
  27933. showCaret(direction, editor, table, !forward, false).each(function (
  27934. newRng
  27935. ) {
  27936. moveToRange(editor, newRng)
  27937. })
  27938. return true
  27939. }
  27940. return false
  27941. }
  27942. var getClosestAbovePosition = function (root, table, start) {
  27943. return findClosestPositionInAboveCell(table, start)
  27944. .orThunk(function () {
  27945. return head(start.getClientRects()).bind(function (rect) {
  27946. return findClosestHorizontalPositionFromPoint(
  27947. getPositionsAbove(root, CaretPosition.before(table)),
  27948. rect.left
  27949. )
  27950. })
  27951. })
  27952. .getOr(CaretPosition.before(table))
  27953. }
  27954. var getClosestBelowPosition = function (root, table, start) {
  27955. return findClosestPositionInBelowCell(table, start)
  27956. .orThunk(function () {
  27957. return head(start.getClientRects()).bind(function (rect) {
  27958. return findClosestHorizontalPositionFromPoint(
  27959. getPositionsBelow(root, CaretPosition.after(table)),
  27960. rect.left
  27961. )
  27962. })
  27963. })
  27964. .getOr(CaretPosition.after(table))
  27965. }
  27966. var getTable = function (previous, pos) {
  27967. var node = pos.getNode(previous)
  27968. return isElement$5(node) && node.nodeName === 'TABLE'
  27969. ? Optional.some(node)
  27970. : Optional.none()
  27971. }
  27972. var renderBlock = function (down, editor, table, pos) {
  27973. var forcedRootBlock = getForcedRootBlock(editor)
  27974. if (forcedRootBlock) {
  27975. editor.undoManager.transact(function () {
  27976. var element = SugarElement.fromTag(forcedRootBlock)
  27977. setAll$1(element, getForcedRootBlockAttrs(editor))
  27978. append$1(element, SugarElement.fromTag('br'))
  27979. if (down) {
  27980. after$3(SugarElement.fromDom(table), element)
  27981. } else {
  27982. before$4(SugarElement.fromDom(table), element)
  27983. }
  27984. var rng = editor.dom.createRng()
  27985. rng.setStart(element.dom, 0)
  27986. rng.setEnd(element.dom, 0)
  27987. moveToRange(editor, rng)
  27988. })
  27989. } else {
  27990. moveToRange(editor, pos.toRange())
  27991. }
  27992. }
  27993. var moveCaret = function (editor, down, pos) {
  27994. var table = down ? getTable(true, pos) : getTable(false, pos)
  27995. var last = down === false
  27996. table.fold(
  27997. function () {
  27998. return moveToRange(editor, pos.toRange())
  27999. },
  28000. function (table) {
  28001. return positionIn(last, editor.getBody())
  28002. .filter(function (lastPos) {
  28003. return lastPos.isEqual(pos)
  28004. })
  28005. .fold(
  28006. function () {
  28007. return moveToRange(editor, pos.toRange())
  28008. },
  28009. function (_) {
  28010. return renderBlock(down, editor, table, pos)
  28011. }
  28012. )
  28013. }
  28014. )
  28015. }
  28016. var navigateVertically = function (editor, down, table, td) {
  28017. var rng = editor.selection.getRng()
  28018. var pos = CaretPosition.fromRangeStart(rng)
  28019. var root = editor.getBody()
  28020. if (!down && isAtFirstTableCellLine(td, pos)) {
  28021. var newPos = getClosestAbovePosition(root, table, pos)
  28022. moveCaret(editor, down, newPos)
  28023. return true
  28024. } else if (down && isAtLastTableCellLine(td, pos)) {
  28025. var newPos = getClosestBelowPosition(root, table, pos)
  28026. moveCaret(editor, down, newPos)
  28027. return true
  28028. } else {
  28029. return false
  28030. }
  28031. }
  28032. var move$1 = function (editor, forward, mover) {
  28033. return Optional.from(
  28034. editor.dom.getParent(editor.selection.getNode(), 'td,th')
  28035. )
  28036. .bind(function (td) {
  28037. return Optional.from(editor.dom.getParent(td, 'table')).map(function (
  28038. table
  28039. ) {
  28040. return mover(editor, forward, table, td)
  28041. })
  28042. })
  28043. .getOr(false)
  28044. }
  28045. var moveH = function (editor, forward) {
  28046. return move$1(editor, forward, navigateHorizontally)
  28047. }
  28048. var moveV = function (editor, forward) {
  28049. return move$1(editor, forward, navigateVertically)
  28050. }
  28051. var executeKeydownOverride$3 = function (editor, caret, evt) {
  28052. var os = detect().os
  28053. execute(
  28054. [
  28055. {
  28056. keyCode: VK.RIGHT,
  28057. action: action(moveH$2, editor, true),
  28058. },
  28059. {
  28060. keyCode: VK.LEFT,
  28061. action: action(moveH$2, editor, false),
  28062. },
  28063. {
  28064. keyCode: VK.UP,
  28065. action: action(moveV$3, editor, false),
  28066. },
  28067. {
  28068. keyCode: VK.DOWN,
  28069. action: action(moveV$3, editor, true),
  28070. },
  28071. {
  28072. keyCode: VK.RIGHT,
  28073. action: action(moveH, editor, true),
  28074. },
  28075. {
  28076. keyCode: VK.LEFT,
  28077. action: action(moveH, editor, false),
  28078. },
  28079. {
  28080. keyCode: VK.UP,
  28081. action: action(moveV, editor, false),
  28082. },
  28083. {
  28084. keyCode: VK.DOWN,
  28085. action: action(moveV, editor, true),
  28086. },
  28087. {
  28088. keyCode: VK.RIGHT,
  28089. action: action(moveH$1, editor, true),
  28090. },
  28091. {
  28092. keyCode: VK.LEFT,
  28093. action: action(moveH$1, editor, false),
  28094. },
  28095. {
  28096. keyCode: VK.UP,
  28097. action: action(moveV$1, editor, false),
  28098. },
  28099. {
  28100. keyCode: VK.DOWN,
  28101. action: action(moveV$1, editor, true),
  28102. },
  28103. {
  28104. keyCode: VK.RIGHT,
  28105. action: action(move$2, editor, caret, true),
  28106. },
  28107. {
  28108. keyCode: VK.LEFT,
  28109. action: action(move$2, editor, caret, false),
  28110. },
  28111. {
  28112. keyCode: VK.RIGHT,
  28113. ctrlKey: !os.isOSX(),
  28114. altKey: os.isOSX(),
  28115. action: action(moveNextWord, editor, caret),
  28116. },
  28117. {
  28118. keyCode: VK.LEFT,
  28119. ctrlKey: !os.isOSX(),
  28120. altKey: os.isOSX(),
  28121. action: action(movePrevWord, editor, caret),
  28122. },
  28123. {
  28124. keyCode: VK.UP,
  28125. action: action(moveV$2, editor, false),
  28126. },
  28127. {
  28128. keyCode: VK.DOWN,
  28129. action: action(moveV$2, editor, true),
  28130. },
  28131. ],
  28132. evt
  28133. ).each(function (_) {
  28134. evt.preventDefault()
  28135. })
  28136. }
  28137. var setup$b = function (editor, caret) {
  28138. editor.on('keydown', function (evt) {
  28139. if (evt.isDefaultPrevented() === false) {
  28140. executeKeydownOverride$3(editor, caret, evt)
  28141. }
  28142. })
  28143. }
  28144. var executeKeydownOverride$2 = function (editor, caret, evt) {
  28145. execute(
  28146. [
  28147. {
  28148. keyCode: VK.BACKSPACE,
  28149. action: action(backspaceDelete, editor, false),
  28150. },
  28151. {
  28152. keyCode: VK.BACKSPACE,
  28153. action: action(backspaceDelete$5, editor, false),
  28154. },
  28155. {
  28156. keyCode: VK.DELETE,
  28157. action: action(backspaceDelete$5, editor, true),
  28158. },
  28159. {
  28160. keyCode: VK.BACKSPACE,
  28161. action: action(backspaceDelete$6, editor, false),
  28162. },
  28163. {
  28164. keyCode: VK.DELETE,
  28165. action: action(backspaceDelete$6, editor, true),
  28166. },
  28167. {
  28168. keyCode: VK.BACKSPACE,
  28169. action: action(backspaceDelete$3, editor, caret, false),
  28170. },
  28171. {
  28172. keyCode: VK.DELETE,
  28173. action: action(backspaceDelete$3, editor, caret, true),
  28174. },
  28175. {
  28176. keyCode: VK.BACKSPACE,
  28177. action: action(backspaceDelete$9, editor, false),
  28178. },
  28179. {
  28180. keyCode: VK.DELETE,
  28181. action: action(backspaceDelete$9, editor, true),
  28182. },
  28183. {
  28184. keyCode: VK.BACKSPACE,
  28185. action: action(backspaceDelete$4, editor, false),
  28186. },
  28187. {
  28188. keyCode: VK.DELETE,
  28189. action: action(backspaceDelete$4, editor, true),
  28190. },
  28191. {
  28192. keyCode: VK.BACKSPACE,
  28193. action: action(backspaceDelete$1, editor, false),
  28194. },
  28195. {
  28196. keyCode: VK.DELETE,
  28197. action: action(backspaceDelete$1, editor, true),
  28198. },
  28199. {
  28200. keyCode: VK.BACKSPACE,
  28201. action: action(backspaceDelete$7, editor, false),
  28202. },
  28203. {
  28204. keyCode: VK.DELETE,
  28205. action: action(backspaceDelete$7, editor, true),
  28206. },
  28207. {
  28208. keyCode: VK.BACKSPACE,
  28209. action: action(backspaceDelete$8, editor, false),
  28210. },
  28211. {
  28212. keyCode: VK.DELETE,
  28213. action: action(backspaceDelete$8, editor, true),
  28214. },
  28215. {
  28216. keyCode: VK.BACKSPACE,
  28217. action: action(backspaceDelete$2, editor, false),
  28218. },
  28219. {
  28220. keyCode: VK.DELETE,
  28221. action: action(backspaceDelete$2, editor, true),
  28222. },
  28223. ],
  28224. evt
  28225. ).each(function (_) {
  28226. evt.preventDefault()
  28227. })
  28228. }
  28229. var executeKeyupOverride = function (editor, evt) {
  28230. execute(
  28231. [
  28232. {
  28233. keyCode: VK.BACKSPACE,
  28234. action: action(paddEmptyElement, editor),
  28235. },
  28236. {
  28237. keyCode: VK.DELETE,
  28238. action: action(paddEmptyElement, editor),
  28239. },
  28240. ],
  28241. evt
  28242. )
  28243. }
  28244. var setup$a = function (editor, caret) {
  28245. editor.on('keydown', function (evt) {
  28246. if (evt.isDefaultPrevented() === false) {
  28247. executeKeydownOverride$2(editor, caret, evt)
  28248. }
  28249. })
  28250. editor.on('keyup', function (evt) {
  28251. if (evt.isDefaultPrevented() === false) {
  28252. executeKeyupOverride(editor, evt)
  28253. }
  28254. })
  28255. }
  28256. var firstNonWhiteSpaceNodeSibling = function (node) {
  28257. while (node) {
  28258. if (
  28259. node.nodeType === 1 ||
  28260. (node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data))
  28261. ) {
  28262. return node
  28263. }
  28264. node = node.nextSibling
  28265. }
  28266. }
  28267. var moveToCaretPosition = function (editor, root) {
  28268. var node,
  28269. lastNode = root
  28270. var dom = editor.dom
  28271. var moveCaretBeforeOnEnterElementsMap =
  28272. editor.schema.getMoveCaretBeforeOnEnterElements()
  28273. if (!root) {
  28274. return
  28275. }
  28276. if (/^(LI|DT|DD)$/.test(root.nodeName)) {
  28277. var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild)
  28278. if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
  28279. root.insertBefore(dom.doc.createTextNode(nbsp), root.firstChild)
  28280. }
  28281. }
  28282. var rng = dom.createRng()
  28283. root.normalize()
  28284. if (root.hasChildNodes()) {
  28285. var walker = new DomTreeWalker(root, root)
  28286. while ((node = walker.current())) {
  28287. if (isText$7(node)) {
  28288. rng.setStart(node, 0)
  28289. rng.setEnd(node, 0)
  28290. break
  28291. }
  28292. if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
  28293. rng.setStartBefore(node)
  28294. rng.setEndBefore(node)
  28295. break
  28296. }
  28297. lastNode = node
  28298. node = walker.next()
  28299. }
  28300. if (!node) {
  28301. rng.setStart(lastNode, 0)
  28302. rng.setEnd(lastNode, 0)
  28303. }
  28304. } else {
  28305. if (isBr$5(root)) {
  28306. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  28307. rng.setStartBefore(root)
  28308. rng.setEndBefore(root)
  28309. } else {
  28310. rng.setStartAfter(root)
  28311. rng.setEndAfter(root)
  28312. }
  28313. } else {
  28314. rng.setStart(root, 0)
  28315. rng.setEnd(root, 0)
  28316. }
  28317. }
  28318. editor.selection.setRng(rng)
  28319. scrollRangeIntoView(editor, rng)
  28320. }
  28321. var getEditableRoot$1 = function (dom, node) {
  28322. var root = dom.getRoot()
  28323. var parent, editableRoot
  28324. parent = node
  28325. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  28326. if (dom.getContentEditable(parent) === 'true') {
  28327. editableRoot = parent
  28328. }
  28329. parent = parent.parentNode
  28330. }
  28331. return parent !== root ? editableRoot : root
  28332. }
  28333. var getParentBlock = function (editor) {
  28334. return Optional.from(
  28335. editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock)
  28336. )
  28337. }
  28338. var getParentBlockName = function (editor) {
  28339. return getParentBlock(editor).fold(constant(''), function (parentBlock) {
  28340. return parentBlock.nodeName.toUpperCase()
  28341. })
  28342. }
  28343. var isListItemParentBlock = function (editor) {
  28344. return getParentBlock(editor)
  28345. .filter(function (elm) {
  28346. return isListItem(SugarElement.fromDom(elm))
  28347. })
  28348. .isSome()
  28349. }
  28350. var hasFirstChild = function (elm, name) {
  28351. return elm.firstChild && elm.firstChild.nodeName === name
  28352. }
  28353. var isFirstChild = function (elm) {
  28354. var _a
  28355. return (
  28356. ((_a = elm.parentNode) === null || _a === void 0
  28357. ? void 0
  28358. : _a.firstChild) === elm
  28359. )
  28360. }
  28361. var hasParent = function (elm, parentName) {
  28362. return elm && elm.parentNode && elm.parentNode.nodeName === parentName
  28363. }
  28364. var isListBlock = function (elm) {
  28365. return elm && /^(OL|UL|LI)$/.test(elm.nodeName)
  28366. }
  28367. var isNestedList = function (elm) {
  28368. return isListBlock(elm) && isListBlock(elm.parentNode)
  28369. }
  28370. var getContainerBlock = function (containerBlock) {
  28371. var containerBlockParent = containerBlock.parentNode
  28372. if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) {
  28373. return containerBlockParent
  28374. }
  28375. return containerBlock
  28376. }
  28377. var isFirstOrLastLi = function (containerBlock, parentBlock, first) {
  28378. var node = containerBlock[first ? 'firstChild' : 'lastChild']
  28379. while (node) {
  28380. if (isElement$5(node)) {
  28381. break
  28382. }
  28383. node = node[first ? 'nextSibling' : 'previousSibling']
  28384. }
  28385. return node === parentBlock
  28386. }
  28387. var insert$3 = function (
  28388. editor,
  28389. createNewBlock,
  28390. containerBlock,
  28391. parentBlock,
  28392. newBlockName
  28393. ) {
  28394. var dom = editor.dom
  28395. var rng = editor.selection.getRng()
  28396. if (containerBlock === editor.getBody()) {
  28397. return
  28398. }
  28399. if (isNestedList(containerBlock)) {
  28400. newBlockName = 'LI'
  28401. }
  28402. var newBlock = newBlockName
  28403. ? createNewBlock(newBlockName)
  28404. : dom.create('BR')
  28405. if (
  28406. isFirstOrLastLi(containerBlock, parentBlock, true) &&
  28407. isFirstOrLastLi(containerBlock, parentBlock, false)
  28408. ) {
  28409. if (hasParent(containerBlock, 'LI')) {
  28410. var containerBlockParent = getContainerBlock(containerBlock)
  28411. dom.insertAfter(newBlock, containerBlockParent)
  28412. if (isFirstChild(containerBlock)) {
  28413. dom.remove(containerBlockParent)
  28414. } else {
  28415. dom.remove(containerBlock)
  28416. }
  28417. } else {
  28418. dom.replace(newBlock, containerBlock)
  28419. }
  28420. } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) {
  28421. if (hasParent(containerBlock, 'LI')) {
  28422. dom.insertAfter(newBlock, getContainerBlock(containerBlock))
  28423. newBlock.appendChild(dom.doc.createTextNode(' '))
  28424. newBlock.appendChild(containerBlock)
  28425. } else {
  28426. containerBlock.parentNode.insertBefore(newBlock, containerBlock)
  28427. }
  28428. dom.remove(parentBlock)
  28429. } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) {
  28430. dom.insertAfter(newBlock, getContainerBlock(containerBlock))
  28431. dom.remove(parentBlock)
  28432. } else {
  28433. containerBlock = getContainerBlock(containerBlock)
  28434. var tmpRng = rng.cloneRange()
  28435. tmpRng.setStartAfter(parentBlock)
  28436. tmpRng.setEndAfter(containerBlock)
  28437. var fragment = tmpRng.extractContents()
  28438. if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) {
  28439. newBlock = fragment.firstChild
  28440. dom.insertAfter(fragment, containerBlock)
  28441. } else {
  28442. dom.insertAfter(fragment, containerBlock)
  28443. dom.insertAfter(newBlock, containerBlock)
  28444. }
  28445. dom.remove(parentBlock)
  28446. }
  28447. moveToCaretPosition(editor, newBlock)
  28448. }
  28449. var trimZwsp = function (fragment) {
  28450. each$k(
  28451. descendants$1(SugarElement.fromDom(fragment), isText$8),
  28452. function (text) {
  28453. var rawNode = text.dom
  28454. rawNode.nodeValue = trim$2(rawNode.nodeValue)
  28455. }
  28456. )
  28457. }
  28458. var isEmptyAnchor = function (dom, elm) {
  28459. return elm && elm.nodeName === 'A' && dom.isEmpty(elm)
  28460. }
  28461. var isTableCell = function (node) {
  28462. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName)
  28463. }
  28464. var emptyBlock = function (elm) {
  28465. elm.innerHTML = '<br data-mce-bogus="1">'
  28466. }
  28467. var containerAndSiblingName = function (container, nodeName) {
  28468. return (
  28469. container.nodeName === nodeName ||
  28470. (container.previousSibling &&
  28471. container.previousSibling.nodeName === nodeName)
  28472. )
  28473. }
  28474. var canSplitBlock = function (dom, node) {
  28475. return (
  28476. node &&
  28477. dom.isBlock(node) &&
  28478. !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
  28479. !/^(fixed|absolute)/i.test(node.style.position) &&
  28480. dom.getContentEditable(node) !== 'true'
  28481. )
  28482. }
  28483. var trimInlineElementsOnLeftSideOfBlock = function (
  28484. dom,
  28485. nonEmptyElementsMap,
  28486. block
  28487. ) {
  28488. var node = block
  28489. var firstChilds = []
  28490. var i
  28491. if (!node) {
  28492. return
  28493. }
  28494. while ((node = node.firstChild)) {
  28495. if (dom.isBlock(node)) {
  28496. return
  28497. }
  28498. if (
  28499. isElement$5(node) &&
  28500. !nonEmptyElementsMap[node.nodeName.toLowerCase()]
  28501. ) {
  28502. firstChilds.push(node)
  28503. }
  28504. }
  28505. i = firstChilds.length
  28506. while (i--) {
  28507. node = firstChilds[i]
  28508. if (
  28509. !node.hasChildNodes() ||
  28510. (node.firstChild === node.lastChild && node.firstChild.nodeValue === '')
  28511. ) {
  28512. dom.remove(node)
  28513. } else {
  28514. if (isEmptyAnchor(dom, node)) {
  28515. dom.remove(node)
  28516. }
  28517. }
  28518. }
  28519. }
  28520. var normalizeZwspOffset = function (start, container, offset) {
  28521. if (isText$7(container) === false) {
  28522. return offset
  28523. } else if (start) {
  28524. return offset === 1 && container.data.charAt(offset - 1) === ZWSP$1
  28525. ? 0
  28526. : offset
  28527. } else {
  28528. return offset === container.data.length - 1 &&
  28529. container.data.charAt(offset) === ZWSP$1
  28530. ? container.data.length
  28531. : offset
  28532. }
  28533. }
  28534. var includeZwspInRange = function (rng) {
  28535. var newRng = rng.cloneRange()
  28536. newRng.setStart(
  28537. rng.startContainer,
  28538. normalizeZwspOffset(true, rng.startContainer, rng.startOffset)
  28539. )
  28540. newRng.setEnd(
  28541. rng.endContainer,
  28542. normalizeZwspOffset(false, rng.endContainer, rng.endOffset)
  28543. )
  28544. return newRng
  28545. }
  28546. var trimLeadingLineBreaks = function (node) {
  28547. do {
  28548. if (isText$7(node)) {
  28549. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '')
  28550. }
  28551. node = node.firstChild
  28552. } while (node)
  28553. }
  28554. var getEditableRoot = function (dom, node) {
  28555. var root = dom.getRoot()
  28556. var parent, editableRoot
  28557. parent = node
  28558. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  28559. if (dom.getContentEditable(parent) === 'true') {
  28560. editableRoot = parent
  28561. }
  28562. parent = parent.parentNode
  28563. }
  28564. return parent !== root ? editableRoot : root
  28565. }
  28566. var applyAttributes = function (editor, node, forcedRootBlockAttrs) {
  28567. var dom = editor.dom
  28568. Optional.from(forcedRootBlockAttrs.style)
  28569. .map(dom.parseStyle)
  28570. .each(function (attrStyles) {
  28571. var currentStyles = getAllRaw(SugarElement.fromDom(node))
  28572. var newStyles = __assign(__assign({}, currentStyles), attrStyles)
  28573. dom.setStyles(node, newStyles)
  28574. })
  28575. var attrClassesOpt = Optional.from(forcedRootBlockAttrs.class).map(
  28576. function (attrClasses) {
  28577. return attrClasses.split(/\s+/)
  28578. }
  28579. )
  28580. var currentClassesOpt = Optional.from(node.className).map(function (
  28581. currentClasses
  28582. ) {
  28583. return filter$4(currentClasses.split(/\s+/), function (clazz) {
  28584. return clazz !== ''
  28585. })
  28586. })
  28587. lift2(
  28588. attrClassesOpt,
  28589. currentClassesOpt,
  28590. function (attrClasses, currentClasses) {
  28591. var filteredClasses = filter$4(currentClasses, function (clazz) {
  28592. return !contains$3(attrClasses, clazz)
  28593. })
  28594. var newClasses = __spreadArray(
  28595. __spreadArray([], attrClasses, true),
  28596. filteredClasses,
  28597. true
  28598. )
  28599. dom.setAttrib(node, 'class', newClasses.join(' '))
  28600. }
  28601. )
  28602. var appliedAttrs = ['style', 'class']
  28603. var remainingAttrs = filter$3(forcedRootBlockAttrs, function (_, attrs) {
  28604. return !contains$3(appliedAttrs, attrs)
  28605. })
  28606. dom.setAttribs(node, remainingAttrs)
  28607. }
  28608. var setForcedBlockAttrs = function (editor, node) {
  28609. var forcedRootBlockName = getForcedRootBlock(editor)
  28610. if (
  28611. forcedRootBlockName &&
  28612. forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()
  28613. ) {
  28614. var forcedRootBlockAttrs = getForcedRootBlockAttrs(editor)
  28615. applyAttributes(editor, node, forcedRootBlockAttrs)
  28616. }
  28617. }
  28618. var wrapSelfAndSiblingsInDefaultBlock = function (
  28619. editor,
  28620. newBlockName,
  28621. rng,
  28622. container,
  28623. offset
  28624. ) {
  28625. var newBlock, parentBlock, startNode, node, next, rootBlockName
  28626. var blockName = newBlockName || 'P'
  28627. var dom = editor.dom,
  28628. editableRoot = getEditableRoot(dom, container)
  28629. parentBlock = dom.getParent(container, dom.isBlock)
  28630. if (!parentBlock || !canSplitBlock(dom, parentBlock)) {
  28631. parentBlock = parentBlock || editableRoot
  28632. if (parentBlock === editor.getBody() || isTableCell(parentBlock)) {
  28633. rootBlockName = parentBlock.nodeName.toLowerCase()
  28634. } else {
  28635. rootBlockName = parentBlock.parentNode.nodeName.toLowerCase()
  28636. }
  28637. if (!parentBlock.hasChildNodes()) {
  28638. newBlock = dom.create(blockName)
  28639. setForcedBlockAttrs(editor, newBlock)
  28640. parentBlock.appendChild(newBlock)
  28641. rng.setStart(newBlock, 0)
  28642. rng.setEnd(newBlock, 0)
  28643. return newBlock
  28644. }
  28645. node = container
  28646. while (node.parentNode !== parentBlock) {
  28647. node = node.parentNode
  28648. }
  28649. while (node && !dom.isBlock(node)) {
  28650. startNode = node
  28651. node = node.previousSibling
  28652. }
  28653. if (
  28654. startNode &&
  28655. editor.schema.isValidChild(rootBlockName, blockName.toLowerCase())
  28656. ) {
  28657. newBlock = dom.create(blockName)
  28658. setForcedBlockAttrs(editor, newBlock)
  28659. startNode.parentNode.insertBefore(newBlock, startNode)
  28660. node = startNode
  28661. while (node && !dom.isBlock(node)) {
  28662. next = node.nextSibling
  28663. newBlock.appendChild(node)
  28664. node = next
  28665. }
  28666. rng.setStart(container, offset)
  28667. rng.setEnd(container, offset)
  28668. }
  28669. }
  28670. return container
  28671. }
  28672. var addBrToBlockIfNeeded = function (dom, block) {
  28673. block.normalize()
  28674. var lastChild = block.lastChild
  28675. if (
  28676. !lastChild ||
  28677. /^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true))
  28678. ) {
  28679. dom.add(block, 'br')
  28680. }
  28681. }
  28682. var insert$2 = function (editor, evt) {
  28683. var tmpRng, container, offset, parentBlock
  28684. var newBlock,
  28685. fragment,
  28686. containerBlock,
  28687. parentBlockName,
  28688. newBlockName,
  28689. isAfterLastNodeInContainer
  28690. var dom = editor.dom
  28691. var schema = editor.schema,
  28692. nonEmptyElementsMap = schema.getNonEmptyElements()
  28693. var rng = editor.selection.getRng()
  28694. var createNewBlock = function (name) {
  28695. var node = container,
  28696. block,
  28697. clonedNode,
  28698. caretNode
  28699. var textInlineElements = schema.getTextInlineElements()
  28700. if (name || parentBlockName === 'TABLE' || parentBlockName === 'HR') {
  28701. block = dom.create(name || newBlockName)
  28702. } else {
  28703. block = parentBlock.cloneNode(false)
  28704. }
  28705. caretNode = block
  28706. if (shouldKeepStyles(editor) === false) {
  28707. dom.setAttrib(block, 'style', null)
  28708. dom.setAttrib(block, 'class', null)
  28709. } else {
  28710. do {
  28711. if (textInlineElements[node.nodeName]) {
  28712. if (isCaretNode(node) || isBookmarkNode$1(node)) {
  28713. continue
  28714. }
  28715. clonedNode = node.cloneNode(false)
  28716. dom.setAttrib(clonedNode, 'id', '')
  28717. if (block.hasChildNodes()) {
  28718. clonedNode.appendChild(block.firstChild)
  28719. block.appendChild(clonedNode)
  28720. } else {
  28721. caretNode = clonedNode
  28722. block.appendChild(clonedNode)
  28723. }
  28724. }
  28725. } while ((node = node.parentNode) && node !== editableRoot)
  28726. }
  28727. setForcedBlockAttrs(editor, block)
  28728. emptyBlock(caretNode)
  28729. return block
  28730. }
  28731. var isCaretAtStartOrEndOfBlock = function (start) {
  28732. var node, name
  28733. var normalizedOffset = normalizeZwspOffset(start, container, offset)
  28734. if (
  28735. isText$7(container) &&
  28736. (start
  28737. ? normalizedOffset > 0
  28738. : normalizedOffset < container.nodeValue.length)
  28739. ) {
  28740. return false
  28741. }
  28742. if (
  28743. container.parentNode === parentBlock &&
  28744. isAfterLastNodeInContainer &&
  28745. !start
  28746. ) {
  28747. return true
  28748. }
  28749. if (
  28750. start &&
  28751. isElement$5(container) &&
  28752. container === parentBlock.firstChild
  28753. ) {
  28754. return true
  28755. }
  28756. if (
  28757. containerAndSiblingName(container, 'TABLE') ||
  28758. containerAndSiblingName(container, 'HR')
  28759. ) {
  28760. return (
  28761. (isAfterLastNodeInContainer && !start) ||
  28762. (!isAfterLastNodeInContainer && start)
  28763. )
  28764. }
  28765. var walker = new DomTreeWalker(container, parentBlock)
  28766. if (isText$7(container)) {
  28767. if (start && normalizedOffset === 0) {
  28768. walker.prev()
  28769. } else if (!start && normalizedOffset === container.nodeValue.length) {
  28770. walker.next()
  28771. }
  28772. }
  28773. while ((node = walker.current())) {
  28774. if (isElement$5(node)) {
  28775. if (!node.getAttribute('data-mce-bogus')) {
  28776. name = node.nodeName.toLowerCase()
  28777. if (nonEmptyElementsMap[name] && name !== 'br') {
  28778. return false
  28779. }
  28780. }
  28781. } else if (isText$7(node) && !isWhitespaceText(node.nodeValue)) {
  28782. return false
  28783. }
  28784. if (start) {
  28785. walker.prev()
  28786. } else {
  28787. walker.next()
  28788. }
  28789. }
  28790. return true
  28791. }
  28792. var insertNewBlockAfter = function () {
  28793. if (
  28794. /^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) &&
  28795. containerBlockName !== 'HGROUP'
  28796. ) {
  28797. newBlock = createNewBlock(newBlockName)
  28798. } else {
  28799. newBlock = createNewBlock()
  28800. }
  28801. if (
  28802. shouldEndContainerOnEmptyBlock(editor) &&
  28803. canSplitBlock(dom, containerBlock) &&
  28804. dom.isEmpty(parentBlock)
  28805. ) {
  28806. newBlock = dom.split(containerBlock, parentBlock)
  28807. } else {
  28808. dom.insertAfter(newBlock, parentBlock)
  28809. }
  28810. moveToCaretPosition(editor, newBlock)
  28811. }
  28812. normalize$2(dom, rng).each(function (normRng) {
  28813. rng.setStart(normRng.startContainer, normRng.startOffset)
  28814. rng.setEnd(normRng.endContainer, normRng.endOffset)
  28815. })
  28816. container = rng.startContainer
  28817. offset = rng.startOffset
  28818. newBlockName = getForcedRootBlock(editor)
  28819. var shiftKey = !!(evt && evt.shiftKey)
  28820. var ctrlKey = !!(evt && evt.ctrlKey)
  28821. if (isElement$5(container) && container.hasChildNodes()) {
  28822. isAfterLastNodeInContainer = offset > container.childNodes.length - 1
  28823. container =
  28824. container.childNodes[
  28825. Math.min(offset, container.childNodes.length - 1)
  28826. ] || container
  28827. if (isAfterLastNodeInContainer && isText$7(container)) {
  28828. offset = container.nodeValue.length
  28829. } else {
  28830. offset = 0
  28831. }
  28832. }
  28833. var editableRoot = getEditableRoot(dom, container)
  28834. if (!editableRoot) {
  28835. return
  28836. }
  28837. if ((newBlockName && !shiftKey) || (!newBlockName && shiftKey)) {
  28838. container = wrapSelfAndSiblingsInDefaultBlock(
  28839. editor,
  28840. newBlockName,
  28841. rng,
  28842. container,
  28843. offset
  28844. )
  28845. }
  28846. parentBlock = dom.getParent(container, dom.isBlock)
  28847. containerBlock = parentBlock
  28848. ? dom.getParent(parentBlock.parentNode, dom.isBlock)
  28849. : null
  28850. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''
  28851. var containerBlockName = containerBlock
  28852. ? containerBlock.nodeName.toUpperCase()
  28853. : ''
  28854. if (containerBlockName === 'LI' && !ctrlKey) {
  28855. parentBlock = containerBlock
  28856. containerBlock = containerBlock.parentNode
  28857. parentBlockName = containerBlockName
  28858. }
  28859. if (/^(LI|DT|DD)$/.test(parentBlockName)) {
  28860. if (dom.isEmpty(parentBlock)) {
  28861. insert$3(
  28862. editor,
  28863. createNewBlock,
  28864. containerBlock,
  28865. parentBlock,
  28866. newBlockName
  28867. )
  28868. return
  28869. }
  28870. }
  28871. if (newBlockName && parentBlock === editor.getBody()) {
  28872. return
  28873. }
  28874. newBlockName = newBlockName || 'P'
  28875. if (isCaretContainerBlock$1(parentBlock)) {
  28876. newBlock = showCaretContainerBlock(parentBlock)
  28877. if (dom.isEmpty(parentBlock)) {
  28878. emptyBlock(parentBlock)
  28879. }
  28880. setForcedBlockAttrs(editor, newBlock)
  28881. moveToCaretPosition(editor, newBlock)
  28882. } else if (isCaretAtStartOrEndOfBlock()) {
  28883. insertNewBlockAfter()
  28884. } else if (isCaretAtStartOrEndOfBlock(true)) {
  28885. newBlock = parentBlock.parentNode.insertBefore(
  28886. createNewBlock(),
  28887. parentBlock
  28888. )
  28889. moveToCaretPosition(
  28890. editor,
  28891. containerAndSiblingName(parentBlock, 'HR') ? newBlock : parentBlock
  28892. )
  28893. } else {
  28894. tmpRng = includeZwspInRange(rng).cloneRange()
  28895. tmpRng.setEndAfter(parentBlock)
  28896. fragment = tmpRng.extractContents()
  28897. trimZwsp(fragment)
  28898. trimLeadingLineBreaks(fragment)
  28899. newBlock = fragment.firstChild
  28900. dom.insertAfter(fragment, parentBlock)
  28901. trimInlineElementsOnLeftSideOfBlock(dom, nonEmptyElementsMap, newBlock)
  28902. addBrToBlockIfNeeded(dom, parentBlock)
  28903. if (dom.isEmpty(parentBlock)) {
  28904. emptyBlock(parentBlock)
  28905. }
  28906. newBlock.normalize()
  28907. if (dom.isEmpty(newBlock)) {
  28908. dom.remove(newBlock)
  28909. insertNewBlockAfter()
  28910. } else {
  28911. setForcedBlockAttrs(editor, newBlock)
  28912. moveToCaretPosition(editor, newBlock)
  28913. }
  28914. }
  28915. dom.setAttrib(newBlock, 'id', '')
  28916. editor.fire('NewBlock', { newBlock: newBlock })
  28917. }
  28918. var hasRightSideContent = function (schema, container, parentBlock) {
  28919. var walker = new DomTreeWalker(container, parentBlock)
  28920. var node
  28921. var nonEmptyElementsMap = schema.getNonEmptyElements()
  28922. while ((node = walker.next())) {
  28923. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
  28924. return true
  28925. }
  28926. }
  28927. }
  28928. var moveSelectionToBr = function (editor, brElm, extraBr) {
  28929. var rng = editor.dom.createRng()
  28930. if (!extraBr) {
  28931. rng.setStartAfter(brElm)
  28932. rng.setEndAfter(brElm)
  28933. } else {
  28934. rng.setStartBefore(brElm)
  28935. rng.setEndBefore(brElm)
  28936. }
  28937. editor.selection.setRng(rng)
  28938. scrollRangeIntoView(editor, rng)
  28939. }
  28940. var insertBrAtCaret = function (editor, evt) {
  28941. var selection = editor.selection
  28942. var dom = editor.dom
  28943. var rng = selection.getRng()
  28944. var brElm
  28945. var extraBr
  28946. normalize$2(dom, rng).each(function (normRng) {
  28947. rng.setStart(normRng.startContainer, normRng.startOffset)
  28948. rng.setEnd(normRng.endContainer, normRng.endOffset)
  28949. })
  28950. var offset = rng.startOffset
  28951. var container = rng.startContainer
  28952. if (container.nodeType === 1 && container.hasChildNodes()) {
  28953. var isAfterLastNodeInContainer = offset > container.childNodes.length - 1
  28954. container =
  28955. container.childNodes[
  28956. Math.min(offset, container.childNodes.length - 1)
  28957. ] || container
  28958. if (isAfterLastNodeInContainer && container.nodeType === 3) {
  28959. offset = container.nodeValue.length
  28960. } else {
  28961. offset = 0
  28962. }
  28963. }
  28964. var parentBlock = dom.getParent(container, dom.isBlock)
  28965. var containerBlock = parentBlock
  28966. ? dom.getParent(parentBlock.parentNode, dom.isBlock)
  28967. : null
  28968. var containerBlockName = containerBlock
  28969. ? containerBlock.nodeName.toUpperCase()
  28970. : ''
  28971. var isControlKey = !!(evt && evt.ctrlKey)
  28972. if (containerBlockName === 'LI' && !isControlKey) {
  28973. parentBlock = containerBlock
  28974. }
  28975. if (
  28976. container &&
  28977. container.nodeType === 3 &&
  28978. offset >= container.nodeValue.length
  28979. ) {
  28980. if (!hasRightSideContent(editor.schema, container, parentBlock)) {
  28981. brElm = dom.create('br')
  28982. rng.insertNode(brElm)
  28983. rng.setStartAfter(brElm)
  28984. rng.setEndAfter(brElm)
  28985. extraBr = true
  28986. }
  28987. }
  28988. brElm = dom.create('br')
  28989. rangeInsertNode(dom, rng, brElm)
  28990. moveSelectionToBr(editor, brElm, extraBr)
  28991. editor.undoManager.add()
  28992. }
  28993. var insertBrBefore = function (editor, inline) {
  28994. var br = SugarElement.fromTag('br')
  28995. before$4(SugarElement.fromDom(inline), br)
  28996. editor.undoManager.add()
  28997. }
  28998. var insertBrAfter = function (editor, inline) {
  28999. if (!hasBrAfter(editor.getBody(), inline)) {
  29000. after$3(SugarElement.fromDom(inline), SugarElement.fromTag('br'))
  29001. }
  29002. var br = SugarElement.fromTag('br')
  29003. after$3(SugarElement.fromDom(inline), br)
  29004. moveSelectionToBr(editor, br.dom, false)
  29005. editor.undoManager.add()
  29006. }
  29007. var isBeforeBr = function (pos) {
  29008. return isBr$5(pos.getNode())
  29009. }
  29010. var hasBrAfter = function (rootNode, startNode) {
  29011. if (isBeforeBr(CaretPosition.after(startNode))) {
  29012. return true
  29013. } else {
  29014. return nextPosition(rootNode, CaretPosition.after(startNode))
  29015. .map(function (pos) {
  29016. return isBr$5(pos.getNode())
  29017. })
  29018. .getOr(false)
  29019. }
  29020. }
  29021. var isAnchorLink = function (elm) {
  29022. return elm && elm.nodeName === 'A' && 'href' in elm
  29023. }
  29024. var isInsideAnchor = function (location) {
  29025. return location.fold(never, isAnchorLink, isAnchorLink, never)
  29026. }
  29027. var readInlineAnchorLocation = function (editor) {
  29028. var isInlineTarget$1 = curry(isInlineTarget, editor)
  29029. var position = CaretPosition.fromRangeStart(editor.selection.getRng())
  29030. return readLocation(isInlineTarget$1, editor.getBody(), position).filter(
  29031. isInsideAnchor
  29032. )
  29033. }
  29034. var insertBrOutsideAnchor = function (editor, location) {
  29035. location.fold(
  29036. noop,
  29037. curry(insertBrBefore, editor),
  29038. curry(insertBrAfter, editor),
  29039. noop
  29040. )
  29041. }
  29042. var insert$1 = function (editor, evt) {
  29043. var anchorLocation = readInlineAnchorLocation(editor)
  29044. if (anchorLocation.isSome()) {
  29045. anchorLocation.each(curry(insertBrOutsideAnchor, editor))
  29046. } else {
  29047. insertBrAtCaret(editor, evt)
  29048. }
  29049. }
  29050. var matchesSelector = function (editor, selector) {
  29051. return getParentBlock(editor)
  29052. .filter(function (parentBlock) {
  29053. return (
  29054. selector.length > 0 &&
  29055. is$2(SugarElement.fromDom(parentBlock), selector)
  29056. )
  29057. })
  29058. .isSome()
  29059. }
  29060. var shouldInsertBr = function (editor) {
  29061. return matchesSelector(editor, getBrNewLineSelector(editor))
  29062. }
  29063. var shouldBlockNewLine$1 = function (editor) {
  29064. return matchesSelector(editor, getNoNewLineSelector(editor))
  29065. }
  29066. var newLineAction = Adt.generate([{ br: [] }, { block: [] }, { none: [] }])
  29067. var shouldBlockNewLine = function (editor, _shiftKey) {
  29068. return shouldBlockNewLine$1(editor)
  29069. }
  29070. var isBrMode = function (requiredState) {
  29071. return function (editor, _shiftKey) {
  29072. var brMode = getForcedRootBlock(editor) === ''
  29073. return brMode === requiredState
  29074. }
  29075. }
  29076. var inListBlock = function (requiredState) {
  29077. return function (editor, _shiftKey) {
  29078. return isListItemParentBlock(editor) === requiredState
  29079. }
  29080. }
  29081. var inBlock = function (blockName, requiredState) {
  29082. return function (editor, _shiftKey) {
  29083. var state = getParentBlockName(editor) === blockName.toUpperCase()
  29084. return state === requiredState
  29085. }
  29086. }
  29087. var inPreBlock = function (requiredState) {
  29088. return inBlock('pre', requiredState)
  29089. }
  29090. var inSummaryBlock = function () {
  29091. return inBlock('summary', true)
  29092. }
  29093. var shouldPutBrInPre = function (requiredState) {
  29094. return function (editor, _shiftKey) {
  29095. return shouldPutBrInPre$1(editor) === requiredState
  29096. }
  29097. }
  29098. var inBrContext = function (editor, _shiftKey) {
  29099. return shouldInsertBr(editor)
  29100. }
  29101. var hasShiftKey = function (_editor, shiftKey) {
  29102. return shiftKey
  29103. }
  29104. var canInsertIntoEditableRoot = function (editor) {
  29105. var forcedRootBlock = getForcedRootBlock(editor)
  29106. var rootEditable = getEditableRoot$1(
  29107. editor.dom,
  29108. editor.selection.getStart()
  29109. )
  29110. return (
  29111. rootEditable &&
  29112. editor.schema.isValidChild(
  29113. rootEditable.nodeName,
  29114. forcedRootBlock ? forcedRootBlock : 'P'
  29115. )
  29116. )
  29117. }
  29118. var match = function (predicates, action) {
  29119. return function (editor, shiftKey) {
  29120. var isMatch = foldl(
  29121. predicates,
  29122. function (res, p) {
  29123. return res && p(editor, shiftKey)
  29124. },
  29125. true
  29126. )
  29127. return isMatch ? Optional.some(action) : Optional.none()
  29128. }
  29129. }
  29130. var getAction = function (editor, evt) {
  29131. return evaluateUntil(
  29132. [
  29133. match([shouldBlockNewLine], newLineAction.none()),
  29134. match([inSummaryBlock()], newLineAction.br()),
  29135. match(
  29136. [inPreBlock(true), shouldPutBrInPre(false), hasShiftKey],
  29137. newLineAction.br()
  29138. ),
  29139. match(
  29140. [inPreBlock(true), shouldPutBrInPre(false)],
  29141. newLineAction.block()
  29142. ),
  29143. match(
  29144. [inPreBlock(true), shouldPutBrInPre(true), hasShiftKey],
  29145. newLineAction.block()
  29146. ),
  29147. match([inPreBlock(true), shouldPutBrInPre(true)], newLineAction.br()),
  29148. match([inListBlock(true), hasShiftKey], newLineAction.br()),
  29149. match([inListBlock(true)], newLineAction.block()),
  29150. match(
  29151. [isBrMode(true), hasShiftKey, canInsertIntoEditableRoot],
  29152. newLineAction.block()
  29153. ),
  29154. match([isBrMode(true)], newLineAction.br()),
  29155. match([inBrContext], newLineAction.br()),
  29156. match([isBrMode(false), hasShiftKey], newLineAction.br()),
  29157. match([canInsertIntoEditableRoot], newLineAction.block()),
  29158. ],
  29159. [editor, !!(evt && evt.shiftKey)]
  29160. ).getOr(newLineAction.none())
  29161. }
  29162. var insert = function (editor, evt) {
  29163. getAction(editor, evt).fold(
  29164. function () {
  29165. insert$1(editor, evt)
  29166. },
  29167. function () {
  29168. insert$2(editor, evt)
  29169. },
  29170. noop
  29171. )
  29172. }
  29173. var handleEnterKeyEvent = function (editor, event) {
  29174. if (event.isDefaultPrevented()) {
  29175. return
  29176. }
  29177. event.preventDefault()
  29178. endTypingLevelIgnoreLocks(editor.undoManager)
  29179. editor.undoManager.transact(function () {
  29180. if (editor.selection.isCollapsed() === false) {
  29181. editor.execCommand('Delete')
  29182. }
  29183. insert(editor, event)
  29184. })
  29185. }
  29186. var setup$9 = function (editor) {
  29187. editor.on('keydown', function (event) {
  29188. if (event.keyCode === VK.ENTER) {
  29189. handleEnterKeyEvent(editor, event)
  29190. }
  29191. })
  29192. }
  29193. var executeKeydownOverride$1 = function (editor, caret, evt) {
  29194. execute(
  29195. [
  29196. {
  29197. keyCode: VK.END,
  29198. action: action(moveToLineEndPoint$1, editor, true),
  29199. },
  29200. {
  29201. keyCode: VK.HOME,
  29202. action: action(moveToLineEndPoint$1, editor, false),
  29203. },
  29204. {
  29205. keyCode: VK.END,
  29206. action: action(moveToLineEndPoint, editor, true),
  29207. },
  29208. {
  29209. keyCode: VK.HOME,
  29210. action: action(moveToLineEndPoint, editor, false),
  29211. },
  29212. {
  29213. keyCode: VK.END,
  29214. action: action(moveToLineEndPoint$2, editor, true, caret),
  29215. },
  29216. {
  29217. keyCode: VK.HOME,
  29218. action: action(moveToLineEndPoint$2, editor, false, caret),
  29219. },
  29220. ],
  29221. evt
  29222. ).each(function (_) {
  29223. evt.preventDefault()
  29224. })
  29225. }
  29226. var setup$8 = function (editor, caret) {
  29227. editor.on('keydown', function (evt) {
  29228. if (evt.isDefaultPrevented() === false) {
  29229. executeKeydownOverride$1(editor, caret, evt)
  29230. }
  29231. })
  29232. }
  29233. var browser = detect().browser
  29234. var setupIeInput = function (editor) {
  29235. var keypressThrotter = first(function () {
  29236. if (!editor.composing) {
  29237. normalizeNbspsInEditor(editor)
  29238. }
  29239. }, 0)
  29240. if (browser.isIE()) {
  29241. editor.on('keypress', function (_e) {
  29242. keypressThrotter.throttle()
  29243. })
  29244. editor.on('remove', function (_e) {
  29245. keypressThrotter.cancel()
  29246. })
  29247. }
  29248. }
  29249. var setup$7 = function (editor) {
  29250. setupIeInput(editor)
  29251. editor.on('input', function (e) {
  29252. if (e.isComposing === false) {
  29253. normalizeNbspsInEditor(editor)
  29254. }
  29255. })
  29256. }
  29257. var platform = detect()
  29258. var executeKeyupAction = function (editor, caret, evt) {
  29259. execute(
  29260. [
  29261. {
  29262. keyCode: VK.PAGE_UP,
  29263. action: action(moveToLineEndPoint$2, editor, false, caret),
  29264. },
  29265. {
  29266. keyCode: VK.PAGE_DOWN,
  29267. action: action(moveToLineEndPoint$2, editor, true, caret),
  29268. },
  29269. ],
  29270. evt
  29271. )
  29272. }
  29273. var stopImmediatePropagation = function (e) {
  29274. return e.stopImmediatePropagation()
  29275. }
  29276. var isPageUpDown = function (evt) {
  29277. return evt.keyCode === VK.PAGE_UP || evt.keyCode === VK.PAGE_DOWN
  29278. }
  29279. var setNodeChangeBlocker = function (blocked, editor, block) {
  29280. if (block && !blocked.get()) {
  29281. editor.on('NodeChange', stopImmediatePropagation, true)
  29282. } else if (!block && blocked.get()) {
  29283. editor.off('NodeChange', stopImmediatePropagation)
  29284. }
  29285. blocked.set(block)
  29286. }
  29287. var setup$6 = function (editor, caret) {
  29288. if (platform.os.isOSX()) {
  29289. return
  29290. }
  29291. var blocked = Cell(false)
  29292. editor.on('keydown', function (evt) {
  29293. if (isPageUpDown(evt)) {
  29294. setNodeChangeBlocker(blocked, editor, true)
  29295. }
  29296. })
  29297. editor.on('keyup', function (evt) {
  29298. if (evt.isDefaultPrevented() === false) {
  29299. executeKeyupAction(editor, caret, evt)
  29300. }
  29301. if (isPageUpDown(evt) && blocked.get()) {
  29302. setNodeChangeBlocker(blocked, editor, false)
  29303. editor.nodeChanged()
  29304. }
  29305. })
  29306. }
  29307. var insertTextAtPosition = function (text, pos) {
  29308. var container = pos.container()
  29309. var offset = pos.offset()
  29310. if (isText$7(container)) {
  29311. container.insertData(offset, text)
  29312. return Optional.some(CaretPosition(container, offset + text.length))
  29313. } else {
  29314. return getElementFromPosition(pos).map(function (elm) {
  29315. var textNode = SugarElement.fromText(text)
  29316. if (pos.isAtEnd()) {
  29317. after$3(elm, textNode)
  29318. } else {
  29319. before$4(elm, textNode)
  29320. }
  29321. return CaretPosition(textNode.dom, text.length)
  29322. })
  29323. }
  29324. }
  29325. var insertNbspAtPosition = curry(insertTextAtPosition, nbsp)
  29326. var insertSpaceAtPosition = curry(insertTextAtPosition, ' ')
  29327. var locationToCaretPosition = function (root) {
  29328. return function (location) {
  29329. return location.fold(
  29330. function (element) {
  29331. return prevPosition(root.dom, CaretPosition.before(element))
  29332. },
  29333. function (element) {
  29334. return firstPositionIn(element)
  29335. },
  29336. function (element) {
  29337. return lastPositionIn(element)
  29338. },
  29339. function (element) {
  29340. return nextPosition(root.dom, CaretPosition.after(element))
  29341. }
  29342. )
  29343. }
  29344. }
  29345. var insertInlineBoundarySpaceOrNbsp = function (root, pos) {
  29346. return function (checkPos) {
  29347. return needsToHaveNbsp(root, checkPos)
  29348. ? insertNbspAtPosition(pos)
  29349. : insertSpaceAtPosition(pos)
  29350. }
  29351. }
  29352. var setSelection = function (editor) {
  29353. return function (pos) {
  29354. editor.selection.setRng(pos.toRange())
  29355. editor.nodeChanged()
  29356. return true
  29357. }
  29358. }
  29359. var insertSpaceOrNbspAtSelection = function (editor) {
  29360. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  29361. var root = SugarElement.fromDom(editor.getBody())
  29362. if (editor.selection.isCollapsed()) {
  29363. var isInlineTarget$1 = curry(isInlineTarget, editor)
  29364. var caretPosition = CaretPosition.fromRangeStart(
  29365. editor.selection.getRng()
  29366. )
  29367. return readLocation(isInlineTarget$1, editor.getBody(), caretPosition)
  29368. .bind(locationToCaretPosition(root))
  29369. .bind(insertInlineBoundarySpaceOrNbsp(root, pos))
  29370. .exists(setSelection(editor))
  29371. } else {
  29372. return false
  29373. }
  29374. }
  29375. var executeKeydownOverride = function (editor, evt) {
  29376. execute(
  29377. [
  29378. {
  29379. keyCode: VK.SPACEBAR,
  29380. action: action(insertSpaceOrNbspAtSelection, editor),
  29381. },
  29382. ],
  29383. evt
  29384. ).each(function (_) {
  29385. evt.preventDefault()
  29386. })
  29387. }
  29388. var setup$5 = function (editor) {
  29389. editor.on('keydown', function (evt) {
  29390. if (evt.isDefaultPrevented() === false) {
  29391. executeKeydownOverride(editor, evt)
  29392. }
  29393. })
  29394. }
  29395. var registerKeyboardOverrides = function (editor) {
  29396. var caret = setupSelectedState(editor)
  29397. setup$c(editor)
  29398. setup$b(editor, caret)
  29399. setup$a(editor, caret)
  29400. setup$9(editor)
  29401. setup$5(editor)
  29402. setup$7(editor)
  29403. setup$8(editor, caret)
  29404. setup$6(editor, caret)
  29405. return caret
  29406. }
  29407. var setup$4 = function (editor) {
  29408. if (!isRtc(editor)) {
  29409. return registerKeyboardOverrides(editor)
  29410. } else {
  29411. return Cell(null)
  29412. }
  29413. }
  29414. var NodeChange = (function () {
  29415. function NodeChange(editor) {
  29416. this.lastPath = []
  29417. this.editor = editor
  29418. var lastRng
  29419. var self = this
  29420. if (!('onselectionchange' in editor.getDoc())) {
  29421. editor.on('NodeChange click mouseup keyup focus', function (e) {
  29422. var nativeRng = editor.selection.getRng()
  29423. var fakeRng = {
  29424. startContainer: nativeRng.startContainer,
  29425. startOffset: nativeRng.startOffset,
  29426. endContainer: nativeRng.endContainer,
  29427. endOffset: nativeRng.endOffset,
  29428. }
  29429. if (e.type === 'nodechange' || !isEq$4(fakeRng, lastRng)) {
  29430. editor.fire('SelectionChange')
  29431. }
  29432. lastRng = fakeRng
  29433. })
  29434. }
  29435. editor.on('contextmenu', function () {
  29436. editor.fire('SelectionChange')
  29437. })
  29438. editor.on('SelectionChange', function () {
  29439. var startElm = editor.selection.getStart(true)
  29440. if (!startElm || (!Env.range && editor.selection.isCollapsed())) {
  29441. return
  29442. }
  29443. if (
  29444. hasAnyRanges(editor) &&
  29445. !self.isSameElementPath(startElm) &&
  29446. editor.dom.isChildOf(startElm, editor.getBody())
  29447. ) {
  29448. editor.nodeChanged({ selectionChange: true })
  29449. }
  29450. })
  29451. editor.on('mouseup', function (e) {
  29452. if (!e.isDefaultPrevented() && hasAnyRanges(editor)) {
  29453. if (editor.selection.getNode().nodeName === 'IMG') {
  29454. Delay.setEditorTimeout(editor, function () {
  29455. editor.nodeChanged()
  29456. })
  29457. } else {
  29458. editor.nodeChanged()
  29459. }
  29460. }
  29461. })
  29462. }
  29463. NodeChange.prototype.nodeChanged = function (args) {
  29464. var selection = this.editor.selection
  29465. var node, parents, root
  29466. if (
  29467. this.editor.initialized &&
  29468. selection &&
  29469. !shouldDisableNodeChange(this.editor) &&
  29470. !this.editor.mode.isReadOnly()
  29471. ) {
  29472. root = this.editor.getBody()
  29473. node = selection.getStart(true) || root
  29474. if (
  29475. node.ownerDocument !== this.editor.getDoc() ||
  29476. !this.editor.dom.isChildOf(node, root)
  29477. ) {
  29478. node = root
  29479. }
  29480. parents = []
  29481. this.editor.dom.getParent(node, function (node) {
  29482. if (node === root) {
  29483. return true
  29484. }
  29485. parents.push(node)
  29486. })
  29487. args = args || {}
  29488. args.element = node
  29489. args.parents = parents
  29490. this.editor.fire('NodeChange', args)
  29491. }
  29492. }
  29493. NodeChange.prototype.isSameElementPath = function (startElm) {
  29494. var i
  29495. var currentPath = this.editor
  29496. .$(startElm)
  29497. .parentsUntil(this.editor.getBody())
  29498. .add(startElm)
  29499. if (currentPath.length === this.lastPath.length) {
  29500. for (i = currentPath.length; i >= 0; i--) {
  29501. if (currentPath[i] !== this.lastPath[i]) {
  29502. break
  29503. }
  29504. }
  29505. if (i === -1) {
  29506. this.lastPath = currentPath
  29507. return true
  29508. }
  29509. }
  29510. this.lastPath = currentPath
  29511. return false
  29512. }
  29513. return NodeChange
  29514. })()
  29515. var preventSummaryToggle = function (editor) {
  29516. editor.on('click', function (e) {
  29517. if (editor.dom.getParent(e.target, 'details')) {
  29518. e.preventDefault()
  29519. }
  29520. })
  29521. }
  29522. var filterDetails = function (editor) {
  29523. editor.parser.addNodeFilter('details', function (elms) {
  29524. each$k(elms, function (details) {
  29525. details.attr('data-mce-open', details.attr('open'))
  29526. details.attr('open', 'open')
  29527. })
  29528. })
  29529. editor.serializer.addNodeFilter('details', function (elms) {
  29530. each$k(elms, function (details) {
  29531. var open = details.attr('data-mce-open')
  29532. details.attr('open', isString$1(open) ? open : null)
  29533. details.attr('data-mce-open', null)
  29534. })
  29535. })
  29536. }
  29537. var setup$3 = function (editor) {
  29538. preventSummaryToggle(editor)
  29539. filterDetails(editor)
  29540. }
  29541. var isTextBlockNode = function (node) {
  29542. return isElement$5(node) && isTextBlock$2(SugarElement.fromDom(node))
  29543. }
  29544. var normalizeSelection = function (editor) {
  29545. var rng = editor.selection.getRng()
  29546. var startPos = CaretPosition.fromRangeStart(rng)
  29547. var endPos = CaretPosition.fromRangeEnd(rng)
  29548. if (CaretPosition.isElementPosition(startPos)) {
  29549. var container = startPos.container()
  29550. if (isTextBlockNode(container)) {
  29551. firstPositionIn(container).each(function (pos) {
  29552. return rng.setStart(pos.container(), pos.offset())
  29553. })
  29554. }
  29555. }
  29556. if (CaretPosition.isElementPosition(endPos)) {
  29557. var container = startPos.container()
  29558. if (isTextBlockNode(container)) {
  29559. lastPositionIn(container).each(function (pos) {
  29560. return rng.setEnd(pos.container(), pos.offset())
  29561. })
  29562. }
  29563. }
  29564. editor.selection.setRng(normalize(rng))
  29565. }
  29566. var setup$2 = function (editor) {
  29567. editor.on('click', function (e) {
  29568. if (e.detail >= 3) {
  29569. normalizeSelection(editor)
  29570. }
  29571. })
  29572. }
  29573. var getAbsolutePosition = function (elm) {
  29574. var clientRect = elm.getBoundingClientRect()
  29575. var doc = elm.ownerDocument
  29576. var docElem = doc.documentElement
  29577. var win = doc.defaultView
  29578. return {
  29579. top: clientRect.top + win.pageYOffset - docElem.clientTop,
  29580. left: clientRect.left + win.pageXOffset - docElem.clientLeft,
  29581. }
  29582. }
  29583. var getBodyPosition = function (editor) {
  29584. return editor.inline
  29585. ? getAbsolutePosition(editor.getBody())
  29586. : {
  29587. left: 0,
  29588. top: 0,
  29589. }
  29590. }
  29591. var getScrollPosition = function (editor) {
  29592. var body = editor.getBody()
  29593. return editor.inline
  29594. ? {
  29595. left: body.scrollLeft,
  29596. top: body.scrollTop,
  29597. }
  29598. : {
  29599. left: 0,
  29600. top: 0,
  29601. }
  29602. }
  29603. var getBodyScroll = function (editor) {
  29604. var body = editor.getBody(),
  29605. docElm = editor.getDoc().documentElement
  29606. var inlineScroll = {
  29607. left: body.scrollLeft,
  29608. top: body.scrollTop,
  29609. }
  29610. var iframeScroll = {
  29611. left: body.scrollLeft || docElm.scrollLeft,
  29612. top: body.scrollTop || docElm.scrollTop,
  29613. }
  29614. return editor.inline ? inlineScroll : iframeScroll
  29615. }
  29616. var getMousePosition = function (editor, event) {
  29617. if (event.target.ownerDocument !== editor.getDoc()) {
  29618. var iframePosition = getAbsolutePosition(editor.getContentAreaContainer())
  29619. var scrollPosition = getBodyScroll(editor)
  29620. return {
  29621. left: event.pageX - iframePosition.left + scrollPosition.left,
  29622. top: event.pageY - iframePosition.top + scrollPosition.top,
  29623. }
  29624. }
  29625. return {
  29626. left: event.pageX,
  29627. top: event.pageY,
  29628. }
  29629. }
  29630. var calculatePosition = function (
  29631. bodyPosition,
  29632. scrollPosition,
  29633. mousePosition
  29634. ) {
  29635. return {
  29636. pageX: mousePosition.left - bodyPosition.left + scrollPosition.left,
  29637. pageY: mousePosition.top - bodyPosition.top + scrollPosition.top,
  29638. }
  29639. }
  29640. var calc = function (editor, event) {
  29641. return calculatePosition(
  29642. getBodyPosition(editor),
  29643. getScrollPosition(editor),
  29644. getMousePosition(editor, event)
  29645. )
  29646. }
  29647. var isContentEditableFalse$1 = isContentEditableFalse$b,
  29648. isContentEditableTrue$1 = isContentEditableTrue$4
  29649. var isDraggable = function (rootElm, elm) {
  29650. return isContentEditableFalse$1(elm) && elm !== rootElm
  29651. }
  29652. var isValidDropTarget = function (editor, targetElement, dragElement) {
  29653. if (
  29654. targetElement === dragElement ||
  29655. editor.dom.isChildOf(targetElement, dragElement)
  29656. ) {
  29657. return false
  29658. }
  29659. return !isContentEditableFalse$1(targetElement)
  29660. }
  29661. var cloneElement = function (elm) {
  29662. var cloneElm = elm.cloneNode(true)
  29663. cloneElm.removeAttribute('data-mce-selected')
  29664. return cloneElm
  29665. }
  29666. var createGhost = function (editor, elm, width, height) {
  29667. var dom = editor.dom
  29668. var clonedElm = elm.cloneNode(true)
  29669. dom.setStyles(clonedElm, {
  29670. width: width,
  29671. height: height,
  29672. })
  29673. dom.setAttrib(clonedElm, 'data-mce-selected', null)
  29674. var ghostElm = dom.create('div', {
  29675. class: 'mce-drag-container',
  29676. 'data-mce-bogus': 'all',
  29677. unselectable: 'on',
  29678. contenteditable: 'false',
  29679. })
  29680. dom.setStyles(ghostElm, {
  29681. position: 'absolute',
  29682. opacity: 0.5,
  29683. overflow: 'hidden',
  29684. border: 0,
  29685. padding: 0,
  29686. margin: 0,
  29687. width: width,
  29688. height: height,
  29689. })
  29690. dom.setStyles(clonedElm, {
  29691. margin: 0,
  29692. boxSizing: 'border-box',
  29693. })
  29694. ghostElm.appendChild(clonedElm)
  29695. return ghostElm
  29696. }
  29697. var appendGhostToBody = function (ghostElm, bodyElm) {
  29698. if (ghostElm.parentNode !== bodyElm) {
  29699. bodyElm.appendChild(ghostElm)
  29700. }
  29701. }
  29702. var moveGhost = function (ghostElm, position, width, height, maxX, maxY) {
  29703. var overflowX = 0,
  29704. overflowY = 0
  29705. ghostElm.style.left = position.pageX + 'px'
  29706. ghostElm.style.top = position.pageY + 'px'
  29707. if (position.pageX + width > maxX) {
  29708. overflowX = position.pageX + width - maxX
  29709. }
  29710. if (position.pageY + height > maxY) {
  29711. overflowY = position.pageY + height - maxY
  29712. }
  29713. ghostElm.style.width = width - overflowX + 'px'
  29714. ghostElm.style.height = height - overflowY + 'px'
  29715. }
  29716. var removeElement = function (elm) {
  29717. if (elm && elm.parentNode) {
  29718. elm.parentNode.removeChild(elm)
  29719. }
  29720. }
  29721. var isLeftMouseButtonPressed = function (e) {
  29722. return e.button === 0
  29723. }
  29724. var applyRelPos = function (state, position) {
  29725. return {
  29726. pageX: position.pageX - state.relX,
  29727. pageY: position.pageY + 5,
  29728. }
  29729. }
  29730. var start = function (state, editor) {
  29731. return function (e) {
  29732. if (isLeftMouseButtonPressed(e)) {
  29733. var ceElm = find$3(
  29734. editor.dom.getParents(e.target),
  29735. or(isContentEditableFalse$1, isContentEditableTrue$1)
  29736. ).getOr(null)
  29737. if (isDraggable(editor.getBody(), ceElm)) {
  29738. var elmPos = editor.dom.getPos(ceElm)
  29739. var bodyElm = editor.getBody()
  29740. var docElm = editor.getDoc().documentElement
  29741. state.set({
  29742. element: ceElm,
  29743. dragging: false,
  29744. screenX: e.screenX,
  29745. screenY: e.screenY,
  29746. maxX:
  29747. (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2,
  29748. maxY:
  29749. (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2,
  29750. relX: e.pageX - elmPos.x,
  29751. relY: e.pageY - elmPos.y,
  29752. width: ceElm.offsetWidth,
  29753. height: ceElm.offsetHeight,
  29754. ghost: createGhost(
  29755. editor,
  29756. ceElm,
  29757. ceElm.offsetWidth,
  29758. ceElm.offsetHeight
  29759. ),
  29760. })
  29761. }
  29762. }
  29763. }
  29764. }
  29765. var move = function (state, editor) {
  29766. var throttledPlaceCaretAt = Delay.throttle(function (clientX, clientY) {
  29767. editor._selectionOverrides.hideFakeCaret()
  29768. editor.selection.placeCaretAt(clientX, clientY)
  29769. }, 0)
  29770. editor.on('remove', throttledPlaceCaretAt.stop)
  29771. return function (e) {
  29772. return state.on(function (state) {
  29773. var movement = Math.max(
  29774. Math.abs(e.screenX - state.screenX),
  29775. Math.abs(e.screenY - state.screenY)
  29776. )
  29777. if (!state.dragging && movement > 10) {
  29778. var args = editor.fire('dragstart', { target: state.element })
  29779. if (args.isDefaultPrevented()) {
  29780. return
  29781. }
  29782. state.dragging = true
  29783. editor.focus()
  29784. }
  29785. if (state.dragging) {
  29786. var targetPos = applyRelPos(state, calc(editor, e))
  29787. appendGhostToBody(state.ghost, editor.getBody())
  29788. moveGhost(
  29789. state.ghost,
  29790. targetPos,
  29791. state.width,
  29792. state.height,
  29793. state.maxX,
  29794. state.maxY
  29795. )
  29796. throttledPlaceCaretAt(e.clientX, e.clientY)
  29797. }
  29798. })
  29799. }
  29800. }
  29801. var getRawTarget = function (selection) {
  29802. var rng = selection.getSel().getRangeAt(0)
  29803. var startContainer = rng.startContainer
  29804. return startContainer.nodeType === 3
  29805. ? startContainer.parentNode
  29806. : startContainer
  29807. }
  29808. var drop = function (state, editor) {
  29809. return function (e) {
  29810. state.on(function (state) {
  29811. if (state.dragging) {
  29812. if (
  29813. isValidDropTarget(
  29814. editor,
  29815. getRawTarget(editor.selection),
  29816. state.element
  29817. )
  29818. ) {
  29819. var targetClone_1 = cloneElement(state.element)
  29820. var args = editor.fire('drop', {
  29821. clientX: e.clientX,
  29822. clientY: e.clientY,
  29823. })
  29824. if (!args.isDefaultPrevented()) {
  29825. editor.undoManager.transact(function () {
  29826. removeElement(state.element)
  29827. editor.insertContent(editor.dom.getOuterHTML(targetClone_1))
  29828. editor._selectionOverrides.hideFakeCaret()
  29829. })
  29830. }
  29831. }
  29832. editor.fire('dragend')
  29833. }
  29834. })
  29835. removeDragState(state)
  29836. }
  29837. }
  29838. var stop = function (state, editor) {
  29839. return function () {
  29840. state.on(function (state) {
  29841. if (state.dragging) {
  29842. editor.fire('dragend')
  29843. }
  29844. })
  29845. removeDragState(state)
  29846. }
  29847. }
  29848. var removeDragState = function (state) {
  29849. state.on(function (state) {
  29850. removeElement(state.ghost)
  29851. })
  29852. state.clear()
  29853. }
  29854. var bindFakeDragEvents = function (editor) {
  29855. var state = value()
  29856. var pageDom = DOMUtils.DOM
  29857. var rootDocument = document
  29858. var dragStartHandler = start(state, editor)
  29859. var dragHandler = move(state, editor)
  29860. var dropHandler = drop(state, editor)
  29861. var dragEndHandler = stop(state, editor)
  29862. editor.on('mousedown', dragStartHandler)
  29863. editor.on('mousemove', dragHandler)
  29864. editor.on('mouseup', dropHandler)
  29865. pageDom.bind(rootDocument, 'mousemove', dragHandler)
  29866. pageDom.bind(rootDocument, 'mouseup', dragEndHandler)
  29867. editor.on('remove', function () {
  29868. pageDom.unbind(rootDocument, 'mousemove', dragHandler)
  29869. pageDom.unbind(rootDocument, 'mouseup', dragEndHandler)
  29870. })
  29871. editor.on('keydown', function (e) {
  29872. if (e.keyCode === VK.ESC) {
  29873. dragEndHandler()
  29874. }
  29875. })
  29876. }
  29877. var blockIeDrop = function (editor) {
  29878. editor.on('drop', function (e) {
  29879. var realTarget =
  29880. typeof e.clientX !== 'undefined'
  29881. ? editor.getDoc().elementFromPoint(e.clientX, e.clientY)
  29882. : null
  29883. if (
  29884. isContentEditableFalse$1(realTarget) ||
  29885. editor.dom.getContentEditableParent(realTarget) === 'false'
  29886. ) {
  29887. e.preventDefault()
  29888. }
  29889. })
  29890. }
  29891. var blockUnsupportedFileDrop = function (editor) {
  29892. var preventFileDrop = function (e) {
  29893. if (!e.isDefaultPrevented()) {
  29894. var dataTransfer = e.dataTransfer
  29895. if (
  29896. dataTransfer &&
  29897. (contains$3(dataTransfer.types, 'Files') ||
  29898. dataTransfer.files.length > 0)
  29899. ) {
  29900. e.preventDefault()
  29901. if (e.type === 'drop') {
  29902. displayError(editor, 'Dropped file type is not supported')
  29903. }
  29904. }
  29905. }
  29906. }
  29907. var preventFileDropIfUIElement = function (e) {
  29908. if (isUIElement(editor, e.target)) {
  29909. preventFileDrop(e)
  29910. }
  29911. }
  29912. var setup = function () {
  29913. var pageDom = DOMUtils.DOM
  29914. var dom = editor.dom
  29915. var doc = document
  29916. var editorRoot = editor.inline ? editor.getBody() : editor.getDoc()
  29917. var eventNames = ['drop', 'dragover']
  29918. each$k(eventNames, function (name) {
  29919. pageDom.bind(doc, name, preventFileDropIfUIElement)
  29920. dom.bind(editorRoot, name, preventFileDrop)
  29921. })
  29922. editor.on('remove', function () {
  29923. each$k(eventNames, function (name) {
  29924. pageDom.unbind(doc, name, preventFileDropIfUIElement)
  29925. dom.unbind(editorRoot, name, preventFileDrop)
  29926. })
  29927. })
  29928. }
  29929. editor.on('init', function () {
  29930. Delay.setEditorTimeout(editor, setup, 0)
  29931. })
  29932. }
  29933. var init$2 = function (editor) {
  29934. bindFakeDragEvents(editor)
  29935. blockIeDrop(editor)
  29936. if (shouldBlockUnsupportedDrop(editor)) {
  29937. blockUnsupportedFileDrop(editor)
  29938. }
  29939. }
  29940. var setup$1 = function (editor) {
  29941. var renderFocusCaret = first(function () {
  29942. if (
  29943. !editor.removed &&
  29944. editor.getBody().contains(document.activeElement)
  29945. ) {
  29946. var rng = editor.selection.getRng()
  29947. if (rng.collapsed) {
  29948. var caretRange = renderRangeCaret(editor, rng, false)
  29949. editor.selection.setRng(caretRange)
  29950. }
  29951. }
  29952. }, 0)
  29953. editor.on('focus', function () {
  29954. renderFocusCaret.throttle()
  29955. })
  29956. editor.on('blur', function () {
  29957. renderFocusCaret.cancel()
  29958. })
  29959. }
  29960. var setup = function (editor) {
  29961. editor.on('init', function () {
  29962. editor.on('focusin', function (e) {
  29963. var target = e.target
  29964. if (isMedia$2(target)) {
  29965. var ceRoot = getContentEditableRoot$1(editor.getBody(), target)
  29966. var node = isContentEditableFalse$b(ceRoot) ? ceRoot : target
  29967. if (editor.selection.getNode() !== node) {
  29968. selectNode(editor, node).each(function (rng) {
  29969. return editor.selection.setRng(rng)
  29970. })
  29971. }
  29972. }
  29973. })
  29974. })
  29975. }
  29976. var isContentEditableTrue = isContentEditableTrue$4
  29977. var isContentEditableFalse = isContentEditableFalse$b
  29978. var getContentEditableRoot = function (editor, node) {
  29979. return getContentEditableRoot$1(editor.getBody(), node)
  29980. }
  29981. var SelectionOverrides = function (editor) {
  29982. var selection = editor.selection,
  29983. dom = editor.dom
  29984. var isBlock = dom.isBlock
  29985. var rootNode = editor.getBody()
  29986. var fakeCaret = FakeCaret(editor, rootNode, isBlock, function () {
  29987. return hasFocus(editor)
  29988. })
  29989. var realSelectionId = 'sel-' + dom.uniqueId()
  29990. var elementSelectionAttr = 'data-mce-selected'
  29991. var selectedElement
  29992. var isFakeSelectionElement = function (node) {
  29993. return dom.hasClass(node, 'mce-offscreen-selection')
  29994. }
  29995. var isFakeSelectionTargetElement = function (node) {
  29996. return (
  29997. node !== rootNode &&
  29998. (isContentEditableFalse(node) || isMedia$2(node)) &&
  29999. dom.isChildOf(node, rootNode)
  30000. )
  30001. }
  30002. var isNearFakeSelectionElement = function (pos) {
  30003. return (
  30004. isBeforeContentEditableFalse(pos) ||
  30005. isAfterContentEditableFalse(pos) ||
  30006. isBeforeMedia(pos) ||
  30007. isAfterMedia(pos)
  30008. )
  30009. }
  30010. var getRealSelectionElement = function () {
  30011. var container = dom.get(realSelectionId)
  30012. return container ? container.getElementsByTagName('*')[0] : container
  30013. }
  30014. var setRange = function (range) {
  30015. if (range) {
  30016. selection.setRng(range)
  30017. }
  30018. }
  30019. var getRange = selection.getRng
  30020. var showCaret = function (direction, node, before, scrollIntoView) {
  30021. if (scrollIntoView === void 0) {
  30022. scrollIntoView = true
  30023. }
  30024. var e = editor.fire('ShowCaret', {
  30025. target: node,
  30026. direction: direction,
  30027. before: before,
  30028. })
  30029. if (e.isDefaultPrevented()) {
  30030. return null
  30031. }
  30032. if (scrollIntoView) {
  30033. selection.scrollIntoView(node, direction === -1)
  30034. }
  30035. return fakeCaret.show(before, node)
  30036. }
  30037. var showBlockCaretContainer = function (blockCaretContainer) {
  30038. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  30039. showCaretContainerBlock(blockCaretContainer)
  30040. setRange(getRange())
  30041. selection.scrollIntoView(blockCaretContainer)
  30042. }
  30043. }
  30044. var registerEvents = function () {
  30045. editor.on('mouseup', function (e) {
  30046. var range = getRange()
  30047. if (
  30048. range.collapsed &&
  30049. isXYInContentArea(editor, e.clientX, e.clientY)
  30050. ) {
  30051. renderCaretAtRange(editor, range, false).each(setRange)
  30052. }
  30053. })
  30054. editor.on('click', function (e) {
  30055. var contentEditableRoot = getContentEditableRoot(editor, e.target)
  30056. if (contentEditableRoot) {
  30057. if (isContentEditableFalse(contentEditableRoot)) {
  30058. e.preventDefault()
  30059. editor.focus()
  30060. }
  30061. if (isContentEditableTrue(contentEditableRoot)) {
  30062. if (dom.isChildOf(contentEditableRoot, selection.getNode())) {
  30063. removeElementSelection()
  30064. }
  30065. }
  30066. }
  30067. })
  30068. editor.on('blur NewBlock', removeElementSelection)
  30069. editor.on('ResizeWindow FullscreenStateChanged', fakeCaret.reposition)
  30070. var hasNormalCaretPosition = function (elm) {
  30071. var start = elm.firstChild
  30072. if (isNullable(start)) {
  30073. return false
  30074. }
  30075. var startPos = CaretPosition.before(start)
  30076. if (isBr$5(startPos.getNode()) && elm.childNodes.length === 1) {
  30077. return !isNearFakeSelectionElement(startPos)
  30078. } else {
  30079. var caretWalker = CaretWalker(elm)
  30080. var newPos = caretWalker.next(startPos)
  30081. return newPos && !isNearFakeSelectionElement(newPos)
  30082. }
  30083. }
  30084. var isInSameBlock = function (node1, node2) {
  30085. var block1 = dom.getParent(node1, isBlock)
  30086. var block2 = dom.getParent(node2, isBlock)
  30087. return block1 === block2
  30088. }
  30089. var hasBetterMouseTarget = function (targetNode, caretNode) {
  30090. var targetBlock = dom.getParent(targetNode, isBlock)
  30091. var caretBlock = dom.getParent(caretNode, isBlock)
  30092. if (isNullable(targetBlock)) {
  30093. return false
  30094. }
  30095. if (
  30096. targetNode !== caretBlock &&
  30097. dom.isChildOf(targetBlock, caretBlock) &&
  30098. isContentEditableFalse(
  30099. getContentEditableRoot(editor, targetBlock)
  30100. ) === false
  30101. ) {
  30102. return true
  30103. }
  30104. return (
  30105. !dom.isChildOf(caretBlock, targetBlock) &&
  30106. !isInSameBlock(targetBlock, caretBlock) &&
  30107. hasNormalCaretPosition(targetBlock)
  30108. )
  30109. }
  30110. editor.on(
  30111. 'tap',
  30112. function (e) {
  30113. var targetElm = e.target
  30114. var contentEditableRoot = getContentEditableRoot(editor, targetElm)
  30115. if (isContentEditableFalse(contentEditableRoot)) {
  30116. e.preventDefault()
  30117. selectNode(editor, contentEditableRoot).each(setElementSelection)
  30118. } else if (isFakeSelectionTargetElement(targetElm)) {
  30119. selectNode(editor, targetElm).each(setElementSelection)
  30120. }
  30121. },
  30122. true
  30123. )
  30124. editor.on('mousedown', function (e) {
  30125. var targetElm = e.target
  30126. if (
  30127. targetElm !== rootNode &&
  30128. targetElm.nodeName !== 'HTML' &&
  30129. !dom.isChildOf(targetElm, rootNode)
  30130. ) {
  30131. return
  30132. }
  30133. if (isXYInContentArea(editor, e.clientX, e.clientY) === false) {
  30134. return
  30135. }
  30136. var contentEditableRoot = getContentEditableRoot(editor, targetElm)
  30137. if (contentEditableRoot) {
  30138. if (isContentEditableFalse(contentEditableRoot)) {
  30139. e.preventDefault()
  30140. selectNode(editor, contentEditableRoot).each(setElementSelection)
  30141. } else {
  30142. removeElementSelection()
  30143. if (
  30144. !(isContentEditableTrue(contentEditableRoot) && e.shiftKey) &&
  30145. !isXYWithinRange(e.clientX, e.clientY, selection.getRng())
  30146. ) {
  30147. hideFakeCaret()
  30148. selection.placeCaretAt(e.clientX, e.clientY)
  30149. }
  30150. }
  30151. } else if (isFakeSelectionTargetElement(targetElm)) {
  30152. selectNode(editor, targetElm).each(setElementSelection)
  30153. } else if (isFakeCaretTarget(targetElm) === false) {
  30154. removeElementSelection()
  30155. hideFakeCaret()
  30156. var fakeCaretInfo = closestFakeCaret(rootNode, e.clientX, e.clientY)
  30157. if (fakeCaretInfo) {
  30158. if (!hasBetterMouseTarget(targetElm, fakeCaretInfo.node)) {
  30159. e.preventDefault()
  30160. var range = showCaret(
  30161. 1,
  30162. fakeCaretInfo.node,
  30163. fakeCaretInfo.before,
  30164. false
  30165. )
  30166. setRange(range)
  30167. editor.getBody().focus()
  30168. }
  30169. }
  30170. }
  30171. })
  30172. editor.on('keypress', function (e) {
  30173. if (VK.modifierPressed(e)) {
  30174. return
  30175. }
  30176. if (isContentEditableFalse(selection.getNode())) {
  30177. e.preventDefault()
  30178. }
  30179. })
  30180. editor.on('GetSelectionRange', function (e) {
  30181. var rng = e.range
  30182. if (selectedElement) {
  30183. if (!selectedElement.parentNode) {
  30184. selectedElement = null
  30185. return
  30186. }
  30187. rng = rng.cloneRange()
  30188. rng.selectNode(selectedElement)
  30189. e.range = rng
  30190. }
  30191. })
  30192. editor.on('SetSelectionRange', function (e) {
  30193. e.range = normalizeShortEndedElementSelection(e.range)
  30194. var rng = setElementSelection(e.range, e.forward)
  30195. if (rng) {
  30196. e.range = rng
  30197. }
  30198. })
  30199. var isPasteBin = function (node) {
  30200. return node.id === 'mcepastebin'
  30201. }
  30202. editor.on('AfterSetSelectionRange', function (e) {
  30203. var rng = e.range
  30204. var parentNode = rng.startContainer.parentNode
  30205. if (!isRangeInCaretContainer(rng) && !isPasteBin(parentNode)) {
  30206. hideFakeCaret()
  30207. }
  30208. if (!isFakeSelectionElement(parentNode)) {
  30209. removeElementSelection()
  30210. }
  30211. })
  30212. editor.on('copy', function (e) {
  30213. var clipboardData = e.clipboardData
  30214. if (!e.isDefaultPrevented() && e.clipboardData && !Env.ie) {
  30215. var realSelectionElement = getRealSelectionElement()
  30216. if (realSelectionElement) {
  30217. e.preventDefault()
  30218. clipboardData.clearData()
  30219. clipboardData.setData('text/html', realSelectionElement.outerHTML)
  30220. clipboardData.setData(
  30221. 'text/plain',
  30222. realSelectionElement.outerText || realSelectionElement.innerText
  30223. )
  30224. }
  30225. }
  30226. })
  30227. init$2(editor)
  30228. setup$1(editor)
  30229. setup(editor)
  30230. }
  30231. var isWithinCaretContainer = function (node) {
  30232. return (
  30233. isCaretContainer$2(node) ||
  30234. startsWithCaretContainer$1(node) ||
  30235. endsWithCaretContainer$1(node)
  30236. )
  30237. }
  30238. var isRangeInCaretContainer = function (rng) {
  30239. return (
  30240. isWithinCaretContainer(rng.startContainer) ||
  30241. isWithinCaretContainer(rng.endContainer)
  30242. )
  30243. }
  30244. var normalizeShortEndedElementSelection = function (rng) {
  30245. var shortEndedElements = editor.schema.getShortEndedElements()
  30246. var newRng = dom.createRng()
  30247. var startContainer = rng.startContainer
  30248. var startOffset = rng.startOffset
  30249. var endContainer = rng.endContainer
  30250. var endOffset = rng.endOffset
  30251. if (has$2(shortEndedElements, startContainer.nodeName.toLowerCase())) {
  30252. if (startOffset === 0) {
  30253. newRng.setStartBefore(startContainer)
  30254. } else {
  30255. newRng.setStartAfter(startContainer)
  30256. }
  30257. } else {
  30258. newRng.setStart(startContainer, startOffset)
  30259. }
  30260. if (has$2(shortEndedElements, endContainer.nodeName.toLowerCase())) {
  30261. if (endOffset === 0) {
  30262. newRng.setEndBefore(endContainer)
  30263. } else {
  30264. newRng.setEndAfter(endContainer)
  30265. }
  30266. } else {
  30267. newRng.setEnd(endContainer, endOffset)
  30268. }
  30269. return newRng
  30270. }
  30271. var setupOffscreenSelection = function (
  30272. node,
  30273. targetClone,
  30274. origTargetClone
  30275. ) {
  30276. var $ = editor.$
  30277. var $realSelectionContainer = descendant(
  30278. SugarElement.fromDom(editor.getBody()),
  30279. '#' + realSelectionId
  30280. ).fold(
  30281. function () {
  30282. return $([])
  30283. },
  30284. function (elm) {
  30285. return $([elm.dom])
  30286. }
  30287. )
  30288. if ($realSelectionContainer.length === 0) {
  30289. $realSelectionContainer = $(
  30290. '<div data-mce-bogus="all" class="mce-offscreen-selection"></div>'
  30291. ).attr('id', realSelectionId)
  30292. $realSelectionContainer.appendTo(editor.getBody())
  30293. }
  30294. var newRange = dom.createRng()
  30295. if (targetClone === origTargetClone && Env.ie) {
  30296. $realSelectionContainer
  30297. .empty()
  30298. .append('<p style="font-size: 0" data-mce-bogus="all">\xA0</p>')
  30299. .append(targetClone)
  30300. newRange.setStartAfter($realSelectionContainer[0].firstChild.firstChild)
  30301. newRange.setEndAfter(targetClone)
  30302. } else {
  30303. $realSelectionContainer
  30304. .empty()
  30305. .append(nbsp)
  30306. .append(targetClone)
  30307. .append(nbsp)
  30308. newRange.setStart($realSelectionContainer[0].firstChild, 1)
  30309. newRange.setEnd($realSelectionContainer[0].lastChild, 0)
  30310. }
  30311. $realSelectionContainer.css({ top: dom.getPos(node, editor.getBody()).y })
  30312. $realSelectionContainer[0].focus()
  30313. var sel = selection.getSel()
  30314. sel.removeAllRanges()
  30315. sel.addRange(newRange)
  30316. return newRange
  30317. }
  30318. var selectElement = function (elm) {
  30319. var targetClone = elm.cloneNode(true)
  30320. var e = editor.fire('ObjectSelected', {
  30321. target: elm,
  30322. targetClone: targetClone,
  30323. })
  30324. if (e.isDefaultPrevented()) {
  30325. return null
  30326. }
  30327. var range = setupOffscreenSelection(elm, e.targetClone, targetClone)
  30328. var nodeElm = SugarElement.fromDom(elm)
  30329. each$k(
  30330. descendants(
  30331. SugarElement.fromDom(editor.getBody()),
  30332. '*[data-mce-selected]'
  30333. ),
  30334. function (elm) {
  30335. if (!eq(nodeElm, elm)) {
  30336. remove$6(elm, elementSelectionAttr)
  30337. }
  30338. }
  30339. )
  30340. if (!dom.getAttrib(elm, elementSelectionAttr)) {
  30341. elm.setAttribute(elementSelectionAttr, '1')
  30342. }
  30343. selectedElement = elm
  30344. hideFakeCaret()
  30345. return range
  30346. }
  30347. var setElementSelection = function (range, forward) {
  30348. if (!range) {
  30349. return null
  30350. }
  30351. if (range.collapsed) {
  30352. if (!isRangeInCaretContainer(range)) {
  30353. var dir = forward ? 1 : -1
  30354. var caretPosition = getNormalizedRangeEndPoint(dir, rootNode, range)
  30355. var beforeNode = caretPosition.getNode(!forward)
  30356. if (isFakeCaretTarget(beforeNode)) {
  30357. return showCaret(
  30358. dir,
  30359. beforeNode,
  30360. forward ? !caretPosition.isAtEnd() : false,
  30361. false
  30362. )
  30363. }
  30364. var afterNode = caretPosition.getNode(forward)
  30365. if (isFakeCaretTarget(afterNode)) {
  30366. return showCaret(
  30367. dir,
  30368. afterNode,
  30369. forward ? false : !caretPosition.isAtEnd(),
  30370. false
  30371. )
  30372. }
  30373. }
  30374. return null
  30375. }
  30376. var startContainer = range.startContainer
  30377. var startOffset = range.startOffset
  30378. var endOffset = range.endOffset
  30379. if (
  30380. startContainer.nodeType === 3 &&
  30381. startOffset === 0 &&
  30382. isContentEditableFalse(startContainer.parentNode)
  30383. ) {
  30384. startContainer = startContainer.parentNode
  30385. startOffset = dom.nodeIndex(startContainer)
  30386. startContainer = startContainer.parentNode
  30387. }
  30388. if (startContainer.nodeType !== 1) {
  30389. return null
  30390. }
  30391. if (
  30392. endOffset === startOffset + 1 &&
  30393. startContainer === range.endContainer
  30394. ) {
  30395. var node = startContainer.childNodes[startOffset]
  30396. if (isFakeSelectionTargetElement(node)) {
  30397. return selectElement(node)
  30398. }
  30399. }
  30400. return null
  30401. }
  30402. var removeElementSelection = function () {
  30403. if (selectedElement) {
  30404. selectedElement.removeAttribute(elementSelectionAttr)
  30405. }
  30406. descendant(
  30407. SugarElement.fromDom(editor.getBody()),
  30408. '#' + realSelectionId
  30409. ).each(remove$7)
  30410. selectedElement = null
  30411. }
  30412. var destroy = function () {
  30413. fakeCaret.destroy()
  30414. selectedElement = null
  30415. }
  30416. var hideFakeCaret = function () {
  30417. fakeCaret.hide()
  30418. }
  30419. if (Env.ceFalse && !isRtc(editor)) {
  30420. registerEvents()
  30421. }
  30422. return {
  30423. showCaret: showCaret,
  30424. showBlockCaretContainer: showBlockCaretContainer,
  30425. hideFakeCaret: hideFakeCaret,
  30426. destroy: destroy,
  30427. }
  30428. }
  30429. var Quirks = function (editor) {
  30430. var each = Tools.each
  30431. var BACKSPACE = VK.BACKSPACE,
  30432. DELETE = VK.DELETE,
  30433. dom = editor.dom,
  30434. selection = editor.selection,
  30435. parser = editor.parser
  30436. var isGecko = Env.gecko,
  30437. isIE = Env.ie,
  30438. isWebKit = Env.webkit
  30439. var mceInternalUrlPrefix = 'data:text/mce-internal,'
  30440. var mceInternalDataType = isIE ? 'Text' : 'URL'
  30441. var setEditorCommandState = function (cmd, state) {
  30442. try {
  30443. editor.getDoc().execCommand(cmd, false, state)
  30444. } catch (ex) {}
  30445. }
  30446. var isDefaultPrevented = function (e) {
  30447. return e.isDefaultPrevented()
  30448. }
  30449. var setMceInternalContent = function (e) {
  30450. var selectionHtml, internalContent
  30451. if (e.dataTransfer) {
  30452. if (editor.selection.isCollapsed() && e.target.tagName === 'IMG') {
  30453. selection.select(e.target)
  30454. }
  30455. selectionHtml = editor.selection.getContent()
  30456. if (selectionHtml.length > 0) {
  30457. internalContent =
  30458. mceInternalUrlPrefix +
  30459. escape(editor.id) +
  30460. ',' +
  30461. escape(selectionHtml)
  30462. e.dataTransfer.setData(mceInternalDataType, internalContent)
  30463. }
  30464. }
  30465. }
  30466. var getMceInternalContent = function (e) {
  30467. var internalContent
  30468. if (e.dataTransfer) {
  30469. internalContent = e.dataTransfer.getData(mceInternalDataType)
  30470. if (
  30471. internalContent &&
  30472. internalContent.indexOf(mceInternalUrlPrefix) >= 0
  30473. ) {
  30474. internalContent = internalContent
  30475. .substr(mceInternalUrlPrefix.length)
  30476. .split(',')
  30477. return {
  30478. id: unescape(internalContent[0]),
  30479. html: unescape(internalContent[1]),
  30480. }
  30481. }
  30482. }
  30483. return null
  30484. }
  30485. var insertClipboardContents = function (content, internal) {
  30486. if (editor.queryCommandSupported('mceInsertClipboardContent')) {
  30487. editor.execCommand('mceInsertClipboardContent', false, {
  30488. content: content,
  30489. internal: internal,
  30490. })
  30491. } else {
  30492. editor.execCommand('mceInsertContent', false, content)
  30493. }
  30494. }
  30495. var emptyEditorWhenDeleting = function () {
  30496. var serializeRng = function (rng) {
  30497. var body = dom.create('body')
  30498. var contents = rng.cloneContents()
  30499. body.appendChild(contents)
  30500. return selection.serializer.serialize(body, { format: 'html' })
  30501. }
  30502. var allContentsSelected = function (rng) {
  30503. var selection = serializeRng(rng)
  30504. var allRng = dom.createRng()
  30505. allRng.selectNode(editor.getBody())
  30506. var allSelection = serializeRng(allRng)
  30507. return selection === allSelection
  30508. }
  30509. editor.on('keydown', function (e) {
  30510. var keyCode = e.keyCode
  30511. var isCollapsed, body
  30512. if (
  30513. !isDefaultPrevented(e) &&
  30514. (keyCode === DELETE || keyCode === BACKSPACE)
  30515. ) {
  30516. isCollapsed = editor.selection.isCollapsed()
  30517. body = editor.getBody()
  30518. if (isCollapsed && !dom.isEmpty(body)) {
  30519. return
  30520. }
  30521. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  30522. return
  30523. }
  30524. e.preventDefault()
  30525. editor.setContent('')
  30526. if (body.firstChild && dom.isBlock(body.firstChild)) {
  30527. editor.selection.setCursorLocation(body.firstChild, 0)
  30528. } else {
  30529. editor.selection.setCursorLocation(body, 0)
  30530. }
  30531. editor.nodeChanged()
  30532. }
  30533. })
  30534. }
  30535. var selectAll = function () {
  30536. editor.shortcuts.add('meta+a', null, 'SelectAll')
  30537. }
  30538. var documentElementEditingFocus = function () {
  30539. if (!editor.inline) {
  30540. dom.bind(editor.getDoc(), 'mousedown mouseup', function (e) {
  30541. var rng
  30542. if (e.target === editor.getDoc().documentElement) {
  30543. rng = selection.getRng()
  30544. editor.getBody().focus()
  30545. if (e.type === 'mousedown') {
  30546. if (isCaretContainer$2(rng.startContainer)) {
  30547. return
  30548. }
  30549. selection.placeCaretAt(e.clientX, e.clientY)
  30550. } else {
  30551. selection.setRng(rng)
  30552. }
  30553. }
  30554. })
  30555. }
  30556. }
  30557. var removeHrOnBackspace = function () {
  30558. editor.on('keydown', function (e) {
  30559. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  30560. if (!editor.getBody().getElementsByTagName('hr').length) {
  30561. return
  30562. }
  30563. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  30564. var node = selection.getNode()
  30565. var previousSibling = node.previousSibling
  30566. if (node.nodeName === 'HR') {
  30567. dom.remove(node)
  30568. e.preventDefault()
  30569. return
  30570. }
  30571. if (
  30572. previousSibling &&
  30573. previousSibling.nodeName &&
  30574. previousSibling.nodeName.toLowerCase() === 'hr'
  30575. ) {
  30576. dom.remove(previousSibling)
  30577. e.preventDefault()
  30578. }
  30579. }
  30580. }
  30581. })
  30582. }
  30583. var focusBody = function () {
  30584. if (!Range.prototype.getClientRects) {
  30585. editor.on('mousedown', function (e) {
  30586. if (!isDefaultPrevented(e) && e.target.nodeName === 'HTML') {
  30587. var body_1 = editor.getBody()
  30588. body_1.blur()
  30589. Delay.setEditorTimeout(editor, function () {
  30590. body_1.focus()
  30591. })
  30592. }
  30593. })
  30594. }
  30595. }
  30596. var selectControlElements = function () {
  30597. editor.on('click', function (e) {
  30598. var target = e.target
  30599. if (
  30600. /^(IMG|HR)$/.test(target.nodeName) &&
  30601. dom.getContentEditableParent(target) !== 'false'
  30602. ) {
  30603. e.preventDefault()
  30604. editor.selection.select(target)
  30605. editor.nodeChanged()
  30606. }
  30607. if (
  30608. target.nodeName === 'A' &&
  30609. dom.hasClass(target, 'mce-item-anchor')
  30610. ) {
  30611. e.preventDefault()
  30612. selection.select(target)
  30613. }
  30614. })
  30615. }
  30616. var removeStylesWhenDeletingAcrossBlockElements = function () {
  30617. var getAttributeApplyFunction = function () {
  30618. var template = dom.getAttribs(selection.getStart().cloneNode(false))
  30619. return function () {
  30620. var target = selection.getStart()
  30621. if (target !== editor.getBody()) {
  30622. dom.setAttrib(target, 'style', null)
  30623. each(template, function (attr) {
  30624. target.setAttributeNode(attr.cloneNode(true))
  30625. })
  30626. }
  30627. }
  30628. }
  30629. var isSelectionAcrossElements = function () {
  30630. return (
  30631. !selection.isCollapsed() &&
  30632. dom.getParent(selection.getStart(), dom.isBlock) !==
  30633. dom.getParent(selection.getEnd(), dom.isBlock)
  30634. )
  30635. }
  30636. editor.on('keypress', function (e) {
  30637. var applyAttributes
  30638. if (
  30639. !isDefaultPrevented(e) &&
  30640. (e.keyCode === 8 || e.keyCode === 46) &&
  30641. isSelectionAcrossElements()
  30642. ) {
  30643. applyAttributes = getAttributeApplyFunction()
  30644. editor.getDoc().execCommand('delete', false, null)
  30645. applyAttributes()
  30646. e.preventDefault()
  30647. return false
  30648. }
  30649. })
  30650. dom.bind(editor.getDoc(), 'cut', function (e) {
  30651. var applyAttributes
  30652. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  30653. applyAttributes = getAttributeApplyFunction()
  30654. Delay.setEditorTimeout(editor, function () {
  30655. applyAttributes()
  30656. })
  30657. }
  30658. })
  30659. }
  30660. var disableBackspaceIntoATable = function () {
  30661. editor.on('keydown', function (e) {
  30662. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  30663. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  30664. var previousSibling = selection.getNode().previousSibling
  30665. if (
  30666. previousSibling &&
  30667. previousSibling.nodeName &&
  30668. previousSibling.nodeName.toLowerCase() === 'table'
  30669. ) {
  30670. e.preventDefault()
  30671. return false
  30672. }
  30673. }
  30674. }
  30675. })
  30676. }
  30677. var removeBlockQuoteOnBackSpace = function () {
  30678. editor.on('keydown', function (e) {
  30679. var rng, parent
  30680. if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) {
  30681. return
  30682. }
  30683. rng = selection.getRng()
  30684. var container = rng.startContainer
  30685. var offset = rng.startOffset
  30686. var root = dom.getRoot()
  30687. parent = container
  30688. if (!rng.collapsed || offset !== 0) {
  30689. return
  30690. }
  30691. while (
  30692. parent &&
  30693. parent.parentNode &&
  30694. parent.parentNode.firstChild === parent &&
  30695. parent.parentNode !== root
  30696. ) {
  30697. parent = parent.parentNode
  30698. }
  30699. if (parent.tagName === 'BLOCKQUOTE') {
  30700. editor.formatter.toggle('blockquote', null, parent)
  30701. rng = dom.createRng()
  30702. rng.setStart(container, 0)
  30703. rng.setEnd(container, 0)
  30704. selection.setRng(rng)
  30705. }
  30706. })
  30707. }
  30708. var setGeckoEditingOptions = function () {
  30709. var setOpts = function () {
  30710. setEditorCommandState('StyleWithCSS', false)
  30711. setEditorCommandState('enableInlineTableEditing', false)
  30712. if (!getObjectResizing(editor)) {
  30713. setEditorCommandState('enableObjectResizing', false)
  30714. }
  30715. }
  30716. if (!isReadOnly$1(editor)) {
  30717. editor.on('BeforeExecCommand mousedown', setOpts)
  30718. }
  30719. }
  30720. var addBrAfterLastLinks = function () {
  30721. var fixLinks = function () {
  30722. each(dom.select('a'), function (node) {
  30723. var parentNode = node.parentNode
  30724. var root = dom.getRoot()
  30725. if (parentNode.lastChild === node) {
  30726. while (parentNode && !dom.isBlock(parentNode)) {
  30727. if (
  30728. parentNode.parentNode.lastChild !== parentNode ||
  30729. parentNode === root
  30730. ) {
  30731. return
  30732. }
  30733. parentNode = parentNode.parentNode
  30734. }
  30735. dom.add(parentNode, 'br', { 'data-mce-bogus': 1 })
  30736. }
  30737. })
  30738. }
  30739. editor.on('SetContent ExecCommand', function (e) {
  30740. if (e.type === 'setcontent' || e.command === 'mceInsertLink') {
  30741. fixLinks()
  30742. }
  30743. })
  30744. }
  30745. var setDefaultBlockType = function () {
  30746. if (getForcedRootBlock(editor)) {
  30747. editor.on('init', function () {
  30748. setEditorCommandState(
  30749. 'DefaultParagraphSeparator',
  30750. getForcedRootBlock(editor)
  30751. )
  30752. })
  30753. }
  30754. }
  30755. var normalizeSelection = function () {
  30756. editor.on(
  30757. 'keyup focusin mouseup',
  30758. function (e) {
  30759. if (!VK.modifierPressed(e)) {
  30760. selection.normalize()
  30761. }
  30762. },
  30763. true
  30764. )
  30765. }
  30766. var showBrokenImageIcon = function () {
  30767. editor.contentStyles.push(
  30768. 'img:-moz-broken {' +
  30769. '-moz-force-broken-image-icon:1;' +
  30770. 'min-width:24px;' +
  30771. 'min-height:24px' +
  30772. '}'
  30773. )
  30774. }
  30775. var restoreFocusOnKeyDown = function () {
  30776. if (!editor.inline) {
  30777. editor.on('keydown', function () {
  30778. if (document.activeElement === document.body) {
  30779. editor.getWin().focus()
  30780. }
  30781. })
  30782. }
  30783. }
  30784. var bodyHeight = function () {
  30785. if (!editor.inline) {
  30786. editor.contentStyles.push('body {min-height: 150px}')
  30787. editor.on('click', function (e) {
  30788. var rng
  30789. if (e.target.nodeName === 'HTML') {
  30790. if (Env.ie > 11) {
  30791. editor.getBody().focus()
  30792. return
  30793. }
  30794. rng = editor.selection.getRng()
  30795. editor.getBody().focus()
  30796. editor.selection.setRng(rng)
  30797. editor.selection.normalize()
  30798. editor.nodeChanged()
  30799. }
  30800. })
  30801. }
  30802. }
  30803. var blockCmdArrowNavigation = function () {
  30804. if (Env.mac) {
  30805. editor.on('keydown', function (e) {
  30806. if (
  30807. VK.metaKeyPressed(e) &&
  30808. !e.shiftKey &&
  30809. (e.keyCode === 37 || e.keyCode === 39)
  30810. ) {
  30811. e.preventDefault()
  30812. var selection_1 = editor.selection.getSel()
  30813. selection_1.modify(
  30814. 'move',
  30815. e.keyCode === 37 ? 'backward' : 'forward',
  30816. 'lineboundary'
  30817. )
  30818. }
  30819. })
  30820. }
  30821. }
  30822. var disableAutoUrlDetect = function () {
  30823. setEditorCommandState('AutoUrlDetect', false)
  30824. }
  30825. var tapLinksAndImages = function () {
  30826. editor.on('click', function (e) {
  30827. var elm = e.target
  30828. do {
  30829. if (elm.tagName === 'A') {
  30830. e.preventDefault()
  30831. return
  30832. }
  30833. } while ((elm = elm.parentNode))
  30834. })
  30835. editor.contentStyles.push(
  30836. '.mce-content-body {-webkit-touch-callout: none}'
  30837. )
  30838. }
  30839. var blockFormSubmitInsideEditor = function () {
  30840. editor.on('init', function () {
  30841. editor.dom.bind(editor.getBody(), 'submit', function (e) {
  30842. e.preventDefault()
  30843. })
  30844. })
  30845. }
  30846. var removeAppleInterchangeBrs = function () {
  30847. parser.addNodeFilter('br', function (nodes) {
  30848. var i = nodes.length
  30849. while (i--) {
  30850. if (nodes[i].attr('class') === 'Apple-interchange-newline') {
  30851. nodes[i].remove()
  30852. }
  30853. }
  30854. })
  30855. }
  30856. var ieInternalDragAndDrop = function () {
  30857. editor.on('dragstart', function (e) {
  30858. setMceInternalContent(e)
  30859. })
  30860. editor.on('drop', function (e) {
  30861. if (!isDefaultPrevented(e)) {
  30862. var internalContent = getMceInternalContent(e)
  30863. if (internalContent && internalContent.id !== editor.id) {
  30864. e.preventDefault()
  30865. var rng = fromPoint(e.x, e.y, editor.getDoc())
  30866. selection.setRng(rng)
  30867. insertClipboardContents(internalContent.html, true)
  30868. }
  30869. }
  30870. })
  30871. }
  30872. var refreshContentEditable = noop
  30873. var isHidden = function () {
  30874. if (!isGecko || editor.removed) {
  30875. return false
  30876. }
  30877. var sel = editor.selection.getSel()
  30878. return !sel || !sel.rangeCount || sel.rangeCount === 0
  30879. }
  30880. var setupRtc = function () {
  30881. if (isWebKit) {
  30882. documentElementEditingFocus()
  30883. selectControlElements()
  30884. blockFormSubmitInsideEditor()
  30885. selectAll()
  30886. if (Env.iOS) {
  30887. restoreFocusOnKeyDown()
  30888. bodyHeight()
  30889. tapLinksAndImages()
  30890. }
  30891. }
  30892. if (isGecko) {
  30893. focusBody()
  30894. setGeckoEditingOptions()
  30895. showBrokenImageIcon()
  30896. blockCmdArrowNavigation()
  30897. }
  30898. }
  30899. var setup = function () {
  30900. removeBlockQuoteOnBackSpace()
  30901. emptyEditorWhenDeleting()
  30902. if (!Env.windowsPhone) {
  30903. normalizeSelection()
  30904. }
  30905. if (isWebKit) {
  30906. documentElementEditingFocus()
  30907. selectControlElements()
  30908. setDefaultBlockType()
  30909. blockFormSubmitInsideEditor()
  30910. disableBackspaceIntoATable()
  30911. removeAppleInterchangeBrs()
  30912. if (Env.iOS) {
  30913. restoreFocusOnKeyDown()
  30914. bodyHeight()
  30915. tapLinksAndImages()
  30916. } else {
  30917. selectAll()
  30918. }
  30919. }
  30920. if (Env.ie >= 11) {
  30921. bodyHeight()
  30922. disableBackspaceIntoATable()
  30923. }
  30924. if (Env.ie) {
  30925. selectAll()
  30926. disableAutoUrlDetect()
  30927. ieInternalDragAndDrop()
  30928. }
  30929. if (isGecko) {
  30930. removeHrOnBackspace()
  30931. focusBody()
  30932. removeStylesWhenDeletingAcrossBlockElements()
  30933. setGeckoEditingOptions()
  30934. addBrAfterLastLinks()
  30935. showBrokenImageIcon()
  30936. blockCmdArrowNavigation()
  30937. disableBackspaceIntoATable()
  30938. }
  30939. }
  30940. if (isRtc(editor)) {
  30941. setupRtc()
  30942. } else {
  30943. setup()
  30944. }
  30945. return {
  30946. refreshContentEditable: refreshContentEditable,
  30947. isHidden: isHidden,
  30948. }
  30949. }
  30950. var DOM$6 = DOMUtils.DOM
  30951. var appendStyle = function (editor, text) {
  30952. var body = SugarElement.fromDom(editor.getBody())
  30953. var container = getStyleContainer(getRootNode(body))
  30954. var style = SugarElement.fromTag('style')
  30955. set$1(style, 'type', 'text/css')
  30956. append$1(style, SugarElement.fromText(text))
  30957. append$1(container, style)
  30958. editor.on('remove', function () {
  30959. remove$7(style)
  30960. })
  30961. }
  30962. var getRootName = function (editor) {
  30963. return editor.inline
  30964. ? editor.getElement().nodeName.toLowerCase()
  30965. : undefined
  30966. }
  30967. var removeUndefined = function (obj) {
  30968. return filter$3(obj, function (v) {
  30969. return isUndefined(v) === false
  30970. })
  30971. }
  30972. var mkParserSettings = function (editor) {
  30973. var settings = editor.settings
  30974. var blobCache = editor.editorUpload.blobCache
  30975. return removeUndefined({
  30976. allow_conditional_comments: settings.allow_conditional_comments,
  30977. allow_html_data_urls: settings.allow_html_data_urls,
  30978. allow_svg_data_urls: settings.allow_svg_data_urls,
  30979. allow_html_in_named_anchor: settings.allow_html_in_named_anchor,
  30980. allow_script_urls: settings.allow_script_urls,
  30981. allow_unsafe_link_target: settings.allow_unsafe_link_target,
  30982. convert_fonts_to_spans: settings.convert_fonts_to_spans,
  30983. fix_list_elements: settings.fix_list_elements,
  30984. font_size_legacy_values: settings.font_size_legacy_values,
  30985. forced_root_block: settings.forced_root_block,
  30986. forced_root_block_attrs: settings.forced_root_block_attrs,
  30987. padd_empty_with_br: settings.padd_empty_with_br,
  30988. preserve_cdata: settings.preserve_cdata,
  30989. remove_trailing_brs: settings.remove_trailing_brs,
  30990. inline_styles: settings.inline_styles,
  30991. root_name: getRootName(editor),
  30992. validate: true,
  30993. blob_cache: blobCache,
  30994. document: editor.getDoc(),
  30995. images_dataimg_filter: settings.images_dataimg_filter,
  30996. })
  30997. }
  30998. var mkSerializerSettings = function (editor) {
  30999. var settings = editor.settings
  31000. return __assign(
  31001. __assign({}, mkParserSettings(editor)),
  31002. removeUndefined({
  31003. url_converter: settings.url_converter,
  31004. url_converter_scope: settings.url_converter_scope,
  31005. element_format: settings.element_format,
  31006. entities: settings.entities,
  31007. entity_encoding: settings.entity_encoding,
  31008. indent: settings.indent,
  31009. indent_after: settings.indent_after,
  31010. indent_before: settings.indent_before,
  31011. block_elements: settings.block_elements,
  31012. boolean_attributes: settings.boolean_attributes,
  31013. custom_elements: settings.custom_elements,
  31014. extended_valid_elements: settings.extended_valid_elements,
  31015. invalid_elements: settings.invalid_elements,
  31016. invalid_styles: settings.invalid_styles,
  31017. move_caret_before_on_enter_elements:
  31018. settings.move_caret_before_on_enter_elements,
  31019. non_empty_elements: settings.non_empty_elements,
  31020. schema: settings.schema,
  31021. self_closing_elements: settings.self_closing_elements,
  31022. short_ended_elements: settings.short_ended_elements,
  31023. special: settings.special,
  31024. text_block_elements: settings.text_block_elements,
  31025. text_inline_elements: settings.text_inline_elements,
  31026. valid_children: settings.valid_children,
  31027. valid_classes: settings.valid_classes,
  31028. valid_elements: settings.valid_elements,
  31029. valid_styles: settings.valid_styles,
  31030. verify_html: settings.verify_html,
  31031. whitespace_elements: settings.whitespace_elements,
  31032. })
  31033. )
  31034. }
  31035. var createParser = function (editor) {
  31036. var parser = DomParser(mkParserSettings(editor), editor.schema)
  31037. parser.addAttributeFilter(
  31038. 'src,href,style,tabindex',
  31039. function (nodes, name) {
  31040. var i = nodes.length,
  31041. node,
  31042. value
  31043. var dom = editor.dom
  31044. var internalName = 'data-mce-' + name
  31045. while (i--) {
  31046. node = nodes[i]
  31047. value = node.attr(name)
  31048. if (value && !node.attr(internalName)) {
  31049. if (value.indexOf('data:') === 0 || value.indexOf('blob:') === 0) {
  31050. continue
  31051. }
  31052. if (name === 'style') {
  31053. value = dom.serializeStyle(dom.parseStyle(value), node.name)
  31054. if (!value.length) {
  31055. value = null
  31056. }
  31057. node.attr(internalName, value)
  31058. node.attr(name, value)
  31059. } else if (name === 'tabindex') {
  31060. node.attr(internalName, value)
  31061. node.attr(name, null)
  31062. } else {
  31063. node.attr(internalName, editor.convertURL(value, name, node.name))
  31064. }
  31065. }
  31066. }
  31067. }
  31068. )
  31069. parser.addNodeFilter('script', function (nodes) {
  31070. var i = nodes.length
  31071. while (i--) {
  31072. var node = nodes[i]
  31073. var type = node.attr('type') || 'no/type'
  31074. if (type.indexOf('mce-') !== 0) {
  31075. node.attr('type', 'mce-' + type)
  31076. }
  31077. }
  31078. })
  31079. if (editor.settings.preserve_cdata) {
  31080. parser.addNodeFilter('#cdata', function (nodes) {
  31081. var i = nodes.length
  31082. while (i--) {
  31083. var node = nodes[i]
  31084. node.type = 8
  31085. node.name = '#comment'
  31086. node.value = '[CDATA[' + editor.dom.encode(node.value) + ']]'
  31087. }
  31088. })
  31089. }
  31090. parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function (nodes) {
  31091. var i = nodes.length
  31092. var nonEmptyElements = editor.schema.getNonEmptyElements()
  31093. while (i--) {
  31094. var node = nodes[i]
  31095. if (node.isEmpty(nonEmptyElements) && node.getAll('br').length === 0) {
  31096. node.append(new AstNode('br', 1)).shortEnded = true
  31097. }
  31098. }
  31099. })
  31100. return parser
  31101. }
  31102. var autoFocus = function (editor) {
  31103. if (editor.settings.auto_focus) {
  31104. Delay.setEditorTimeout(
  31105. editor,
  31106. function () {
  31107. var focusEditor
  31108. if (editor.settings.auto_focus === true) {
  31109. focusEditor = editor
  31110. } else {
  31111. focusEditor = editor.editorManager.get(editor.settings.auto_focus)
  31112. }
  31113. if (!focusEditor.destroyed) {
  31114. focusEditor.focus()
  31115. }
  31116. },
  31117. 100
  31118. )
  31119. }
  31120. }
  31121. var moveSelectionToFirstCaretPosition = function (editor) {
  31122. var root = editor.dom.getRoot()
  31123. if (
  31124. !editor.inline &&
  31125. (!hasAnyRanges(editor) || editor.selection.getStart(true) === root)
  31126. ) {
  31127. firstPositionIn(root).each(function (pos) {
  31128. var node = pos.getNode()
  31129. var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos
  31130. if (Env.browser.isIE()) {
  31131. storeNative(editor, caretPos.toRange())
  31132. } else {
  31133. editor.selection.setRng(caretPos.toRange())
  31134. }
  31135. })
  31136. }
  31137. }
  31138. var initEditor = function (editor) {
  31139. editor.bindPendingEventDelegates()
  31140. editor.initialized = true
  31141. fireInit(editor)
  31142. editor.focus(true)
  31143. moveSelectionToFirstCaretPosition(editor)
  31144. editor.nodeChanged({ initial: true })
  31145. editor.execCallback('init_instance_callback', editor)
  31146. autoFocus(editor)
  31147. }
  31148. var getStyleSheetLoader$1 = function (editor) {
  31149. return editor.inline
  31150. ? editor.ui.styleSheetLoader
  31151. : editor.dom.styleSheetLoader
  31152. }
  31153. var makeStylesheetLoadingPromises = function (editor, css, framedFonts) {
  31154. var promises = [
  31155. new promiseObj(function (resolve, reject) {
  31156. return getStyleSheetLoader$1(editor).loadAll(css, resolve, reject)
  31157. }),
  31158. ]
  31159. if (editor.inline) {
  31160. return promises
  31161. } else {
  31162. return promises.concat([
  31163. new promiseObj(function (resolve, reject) {
  31164. return editor.ui.styleSheetLoader.loadAll(
  31165. framedFonts,
  31166. resolve,
  31167. reject
  31168. )
  31169. }),
  31170. ])
  31171. }
  31172. }
  31173. var loadContentCss = function (editor) {
  31174. var styleSheetLoader = getStyleSheetLoader$1(editor)
  31175. var fontCss = getFontCss(editor)
  31176. var css = editor.contentCSS
  31177. var removeCss = function () {
  31178. styleSheetLoader.unloadAll(css)
  31179. if (!editor.inline) {
  31180. editor.ui.styleSheetLoader.unloadAll(fontCss)
  31181. }
  31182. }
  31183. var loaded = function () {
  31184. if (editor.removed) {
  31185. removeCss()
  31186. } else {
  31187. editor.on('remove', removeCss)
  31188. }
  31189. }
  31190. if (editor.contentStyles.length > 0) {
  31191. var contentCssText_1 = ''
  31192. Tools.each(editor.contentStyles, function (style) {
  31193. contentCssText_1 += style + '\r\n'
  31194. })
  31195. editor.dom.addStyle(contentCssText_1)
  31196. }
  31197. var allStylesheets = promiseObj
  31198. .all(makeStylesheetLoadingPromises(editor, css, fontCss))
  31199. .then(loaded)
  31200. .catch(loaded)
  31201. if (editor.settings.content_style) {
  31202. appendStyle(editor, editor.settings.content_style)
  31203. }
  31204. return allStylesheets
  31205. }
  31206. var preInit = function (editor) {
  31207. var settings = editor.settings,
  31208. doc = editor.getDoc(),
  31209. body = editor.getBody()
  31210. firePreInit(editor)
  31211. if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
  31212. doc.body.spellcheck = false
  31213. DOM$6.setAttrib(body, 'spellcheck', 'false')
  31214. }
  31215. editor.quirks = Quirks(editor)
  31216. firePostRender(editor)
  31217. var directionality = getDirectionality(editor)
  31218. if (directionality !== undefined) {
  31219. body.dir = directionality
  31220. }
  31221. if (settings.protect) {
  31222. editor.on('BeforeSetContent', function (e) {
  31223. Tools.each(settings.protect, function (pattern) {
  31224. e.content = e.content.replace(pattern, function (str) {
  31225. return '<!--mce:protected ' + escape(str) + '-->'
  31226. })
  31227. })
  31228. })
  31229. }
  31230. editor.on('SetContent', function () {
  31231. editor.addVisual(editor.getBody())
  31232. })
  31233. editor.on('compositionstart compositionend', function (e) {
  31234. editor.composing = e.type === 'compositionstart'
  31235. })
  31236. }
  31237. var loadInitialContent = function (editor) {
  31238. if (!isRtc(editor)) {
  31239. editor.load({
  31240. initial: true,
  31241. format: 'html',
  31242. })
  31243. }
  31244. editor.startContent = editor.getContent({ format: 'raw' })
  31245. }
  31246. var initEditorWithInitialContent = function (editor) {
  31247. if (editor.removed !== true) {
  31248. loadInitialContent(editor)
  31249. initEditor(editor)
  31250. }
  31251. }
  31252. var initContentBody = function (editor, skipWrite) {
  31253. var settings = editor.settings
  31254. var targetElm = editor.getElement()
  31255. var doc = editor.getDoc()
  31256. if (!settings.inline) {
  31257. editor.getElement().style.visibility = editor.orgVisibility
  31258. }
  31259. if (!skipWrite && !editor.inline) {
  31260. doc.open()
  31261. doc.write(editor.iframeHTML)
  31262. doc.close()
  31263. }
  31264. if (editor.inline) {
  31265. DOM$6.addClass(targetElm, 'mce-content-body')
  31266. editor.contentDocument = doc = document
  31267. editor.contentWindow = window
  31268. editor.bodyElement = targetElm
  31269. editor.contentAreaContainer = targetElm
  31270. }
  31271. var body = editor.getBody()
  31272. body.disabled = true
  31273. editor.readonly = !!settings.readonly
  31274. if (!editor.readonly) {
  31275. if (
  31276. editor.inline &&
  31277. DOM$6.getStyle(body, 'position', true) === 'static'
  31278. ) {
  31279. body.style.position = 'relative'
  31280. }
  31281. body.contentEditable = editor.getParam('content_editable_state', true)
  31282. }
  31283. body.disabled = false
  31284. editor.editorUpload = EditorUpload(editor)
  31285. editor.schema = Schema(settings)
  31286. editor.dom = DOMUtils(doc, {
  31287. keep_values: true,
  31288. url_converter: editor.convertURL,
  31289. url_converter_scope: editor,
  31290. hex_colors: settings.force_hex_style_colors,
  31291. update_styles: true,
  31292. root_element: editor.inline ? editor.getBody() : null,
  31293. collect: function () {
  31294. return editor.inline
  31295. },
  31296. schema: editor.schema,
  31297. contentCssCors: shouldUseContentCssCors(editor),
  31298. referrerPolicy: getReferrerPolicy(editor),
  31299. onSetAttrib: function (e) {
  31300. editor.fire('SetAttrib', e)
  31301. },
  31302. })
  31303. editor.parser = createParser(editor)
  31304. editor.serializer = DomSerializer(mkSerializerSettings(editor), editor)
  31305. editor.selection = EditorSelection(
  31306. editor.dom,
  31307. editor.getWin(),
  31308. editor.serializer,
  31309. editor
  31310. )
  31311. editor.annotator = Annotator(editor)
  31312. editor.formatter = Formatter(editor)
  31313. editor.undoManager = UndoManager(editor)
  31314. editor._nodeChangeDispatcher = new NodeChange(editor)
  31315. editor._selectionOverrides = SelectionOverrides(editor)
  31316. setup$e(editor)
  31317. setup$3(editor)
  31318. if (!isRtc(editor)) {
  31319. setup$2(editor)
  31320. }
  31321. var caret = setup$4(editor)
  31322. setup$f(editor, caret)
  31323. setup$d(editor)
  31324. setup$g(editor)
  31325. var setupRtcThunk = setup$i(editor)
  31326. preInit(editor)
  31327. setupRtcThunk.fold(
  31328. function () {
  31329. loadContentCss(editor).then(function () {
  31330. return initEditorWithInitialContent(editor)
  31331. })
  31332. },
  31333. function (setupRtc) {
  31334. editor.setProgressState(true)
  31335. loadContentCss(editor).then(function () {
  31336. setupRtc().then(
  31337. function (_rtcMode) {
  31338. editor.setProgressState(false)
  31339. initEditorWithInitialContent(editor)
  31340. },
  31341. function (err) {
  31342. editor.notificationManager.open({
  31343. type: 'error',
  31344. text: String(err),
  31345. })
  31346. initEditorWithInitialContent(editor)
  31347. }
  31348. )
  31349. })
  31350. }
  31351. )
  31352. }
  31353. var DOM$5 = DOMUtils.DOM
  31354. var relaxDomain = function (editor, ifr) {
  31355. if (document.domain !== window.location.hostname && Env.browser.isIE()) {
  31356. var bodyUuid = uuid('mce')
  31357. editor[bodyUuid] = function () {
  31358. initContentBody(editor)
  31359. }
  31360. var domainRelaxUrl =
  31361. 'javascript:(function(){' +
  31362. 'document.open();document.domain="' +
  31363. document.domain +
  31364. '";' +
  31365. 'var ed = window.parent.tinymce.get("' +
  31366. editor.id +
  31367. '");document.write(ed.iframeHTML);' +
  31368. 'document.close();ed.' +
  31369. bodyUuid +
  31370. '(true);})()'
  31371. DOM$5.setAttrib(ifr, 'src', domainRelaxUrl)
  31372. return true
  31373. }
  31374. return false
  31375. }
  31376. var createIframeElement = function (id, title, height, customAttrs) {
  31377. var iframe = SugarElement.fromTag('iframe')
  31378. setAll$1(iframe, customAttrs)
  31379. setAll$1(iframe, {
  31380. id: id + '_ifr',
  31381. frameBorder: '0',
  31382. allowTransparency: 'true',
  31383. title: title,
  31384. })
  31385. add$1(iframe, 'tox-edit-area__iframe')
  31386. return iframe
  31387. }
  31388. var getIframeHtml = function (editor) {
  31389. var iframeHTML = getDocType(editor) + '<html><head>'
  31390. if (getDocumentBaseUrl(editor) !== editor.documentBaseUrl) {
  31391. iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />'
  31392. }
  31393. iframeHTML +=
  31394. '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
  31395. var bodyId = getBodyId(editor)
  31396. var bodyClass = getBodyClass(editor)
  31397. var translatedAriaText = editor.translate(getIframeAriaText(editor))
  31398. if (getContentSecurityPolicy(editor)) {
  31399. iframeHTML +=
  31400. '<meta http-equiv="Content-Security-Policy" content="' +
  31401. getContentSecurityPolicy(editor) +
  31402. '" />'
  31403. }
  31404. iframeHTML +=
  31405. '</head>' +
  31406. ('<body id="' +
  31407. bodyId +
  31408. '" class="mce-content-body ' +
  31409. bodyClass +
  31410. '" data-id="' +
  31411. editor.id +
  31412. '" aria-label="' +
  31413. translatedAriaText +
  31414. '">') +
  31415. '<br>' +
  31416. '</body></html>'
  31417. return iframeHTML
  31418. }
  31419. var createIframe = function (editor, o) {
  31420. var iframeTitle = editor.translate('Rich Text Area')
  31421. var ifr = createIframeElement(
  31422. editor.id,
  31423. iframeTitle,
  31424. o.height,
  31425. getIframeAttrs(editor)
  31426. ).dom
  31427. ifr.onload = function () {
  31428. ifr.onload = null
  31429. editor.fire('load')
  31430. }
  31431. var isDomainRelaxed = relaxDomain(editor, ifr)
  31432. editor.contentAreaContainer = o.iframeContainer
  31433. editor.iframeElement = ifr
  31434. editor.iframeHTML = getIframeHtml(editor)
  31435. DOM$5.add(o.iframeContainer, ifr)
  31436. return isDomainRelaxed
  31437. }
  31438. var init$1 = function (editor, boxInfo) {
  31439. var isDomainRelaxed = createIframe(editor, boxInfo)
  31440. if (boxInfo.editorContainer) {
  31441. DOM$5.get(boxInfo.editorContainer).style.display = editor.orgDisplay
  31442. editor.hidden = DOM$5.isHidden(boxInfo.editorContainer)
  31443. }
  31444. editor.getElement().style.display = 'none'
  31445. DOM$5.setAttrib(editor.id, 'aria-hidden', 'true')
  31446. if (!isDomainRelaxed) {
  31447. initContentBody(editor)
  31448. }
  31449. }
  31450. var DOM$4 = DOMUtils.DOM
  31451. var initPlugin = function (editor, initializedPlugins, plugin) {
  31452. var Plugin = PluginManager.get(plugin)
  31453. var pluginUrl =
  31454. PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, '')
  31455. plugin = Tools.trim(plugin)
  31456. if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) {
  31457. Tools.each(PluginManager.dependencies(plugin), function (dep) {
  31458. initPlugin(editor, initializedPlugins, dep)
  31459. })
  31460. if (editor.plugins[plugin]) {
  31461. return
  31462. }
  31463. try {
  31464. var pluginInstance = new Plugin(editor, pluginUrl, editor.$)
  31465. editor.plugins[plugin] = pluginInstance
  31466. if (pluginInstance.init) {
  31467. pluginInstance.init(editor, pluginUrl)
  31468. initializedPlugins.push(plugin)
  31469. }
  31470. } catch (e) {
  31471. pluginInitError(editor, plugin, e)
  31472. }
  31473. }
  31474. }
  31475. var trimLegacyPrefix = function (name) {
  31476. return name.replace(/^\-/, '')
  31477. }
  31478. var initPlugins = function (editor) {
  31479. var initializedPlugins = []
  31480. Tools.each(getPlugins(editor).split(/[ ,]/), function (name) {
  31481. initPlugin(editor, initializedPlugins, trimLegacyPrefix(name))
  31482. })
  31483. }
  31484. var initIcons = function (editor) {
  31485. var iconPackName = Tools.trim(getIconPackName(editor))
  31486. var currentIcons = editor.ui.registry.getAll().icons
  31487. var loadIcons = __assign(
  31488. __assign({}, IconManager.get('default').icons),
  31489. IconManager.get(iconPackName).icons
  31490. )
  31491. each$j(loadIcons, function (svgData, icon) {
  31492. if (!has$2(currentIcons, icon)) {
  31493. editor.ui.registry.addIcon(icon, svgData)
  31494. }
  31495. })
  31496. }
  31497. var initTheme = function (editor) {
  31498. var theme = getTheme(editor)
  31499. if (isString$1(theme)) {
  31500. editor.settings.theme = trimLegacyPrefix(theme)
  31501. var Theme = ThemeManager.get(theme)
  31502. editor.theme = new Theme(editor, ThemeManager.urls[theme])
  31503. if (editor.theme.init) {
  31504. editor.theme.init(
  31505. editor,
  31506. ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ''),
  31507. editor.$
  31508. )
  31509. }
  31510. } else {
  31511. editor.theme = {}
  31512. }
  31513. }
  31514. var renderFromLoadedTheme = function (editor) {
  31515. return editor.theme.renderUI()
  31516. }
  31517. var renderFromThemeFunc = function (editor) {
  31518. var elm = editor.getElement()
  31519. var theme = getTheme(editor)
  31520. var info = theme(editor, elm)
  31521. if (info.editorContainer.nodeType) {
  31522. info.editorContainer.id = info.editorContainer.id || editor.id + '_parent'
  31523. }
  31524. if (info.iframeContainer && info.iframeContainer.nodeType) {
  31525. info.iframeContainer.id =
  31526. info.iframeContainer.id || editor.id + '_iframecontainer'
  31527. }
  31528. info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight
  31529. return info
  31530. }
  31531. var createThemeFalseResult = function (element) {
  31532. return {
  31533. editorContainer: element,
  31534. iframeContainer: element,
  31535. api: {},
  31536. }
  31537. }
  31538. var renderThemeFalseIframe = function (targetElement) {
  31539. var iframeContainer = DOM$4.create('div')
  31540. DOM$4.insertAfter(iframeContainer, targetElement)
  31541. return createThemeFalseResult(iframeContainer)
  31542. }
  31543. var renderThemeFalse = function (editor) {
  31544. var targetElement = editor.getElement()
  31545. return editor.inline
  31546. ? createThemeFalseResult(null)
  31547. : renderThemeFalseIframe(targetElement)
  31548. }
  31549. var renderThemeUi = function (editor) {
  31550. var elm = editor.getElement()
  31551. editor.orgDisplay = elm.style.display
  31552. if (isString$1(getTheme(editor))) {
  31553. return renderFromLoadedTheme(editor)
  31554. } else if (isFunction(getTheme(editor))) {
  31555. return renderFromThemeFunc(editor)
  31556. } else {
  31557. return renderThemeFalse(editor)
  31558. }
  31559. }
  31560. var augmentEditorUiApi = function (editor, api) {
  31561. var uiApiFacade = {
  31562. show: Optional.from(api.show).getOr(noop),
  31563. hide: Optional.from(api.hide).getOr(noop),
  31564. disable: Optional.from(api.disable).getOr(noop),
  31565. isDisabled: Optional.from(api.isDisabled).getOr(never),
  31566. enable: function () {
  31567. if (!editor.mode.isReadOnly()) {
  31568. Optional.from(api.enable).map(call)
  31569. }
  31570. },
  31571. }
  31572. editor.ui = __assign(__assign({}, editor.ui), uiApiFacade)
  31573. }
  31574. var init = function (editor) {
  31575. editor.fire('ScriptsLoaded')
  31576. initIcons(editor)
  31577. initTheme(editor)
  31578. initPlugins(editor)
  31579. var renderInfo = renderThemeUi(editor)
  31580. augmentEditorUiApi(editor, Optional.from(renderInfo.api).getOr({}))
  31581. var boxInfo = {
  31582. editorContainer: renderInfo.editorContainer,
  31583. iframeContainer: renderInfo.iframeContainer,
  31584. }
  31585. editor.editorContainer = boxInfo.editorContainer
  31586. ? boxInfo.editorContainer
  31587. : null
  31588. appendContentCssFromSettings(editor)
  31589. if (editor.inline) {
  31590. return initContentBody(editor)
  31591. } else {
  31592. return init$1(editor, boxInfo)
  31593. }
  31594. }
  31595. var DOM$3 = DOMUtils.DOM
  31596. var hasSkipLoadPrefix = function (name) {
  31597. return name.charAt(0) === '-'
  31598. }
  31599. var loadLanguage = function (scriptLoader, editor) {
  31600. var languageCode = getLanguageCode(editor)
  31601. var languageUrl = getLanguageUrl(editor)
  31602. if (I18n.hasCode(languageCode) === false && languageCode !== 'en') {
  31603. var url_1 =
  31604. languageUrl !== ''
  31605. ? languageUrl
  31606. : editor.editorManager.baseURL + '/langs/' + languageCode + '.js'
  31607. scriptLoader.add(url_1, noop, undefined, function () {
  31608. languageLoadError(editor, url_1, languageCode)
  31609. })
  31610. }
  31611. }
  31612. var loadTheme = function (scriptLoader, editor, suffix, callback) {
  31613. var theme = getTheme(editor)
  31614. if (isString$1(theme)) {
  31615. if (!hasSkipLoadPrefix(theme) && !has$2(ThemeManager.urls, theme)) {
  31616. var themeUrl = getThemeUrl(editor)
  31617. if (themeUrl) {
  31618. ThemeManager.load(theme, editor.documentBaseURI.toAbsolute(themeUrl))
  31619. } else {
  31620. ThemeManager.load(
  31621. theme,
  31622. 'themes/' + theme + '/theme' + suffix + '.js'
  31623. )
  31624. }
  31625. }
  31626. scriptLoader.loadQueue(function () {
  31627. ThemeManager.waitFor(theme, callback)
  31628. })
  31629. } else {
  31630. callback()
  31631. }
  31632. }
  31633. var getIconsUrlMetaFromUrl = function (editor) {
  31634. return Optional.from(getIconsUrl(editor))
  31635. .filter(function (url) {
  31636. return url.length > 0
  31637. })
  31638. .map(function (url) {
  31639. return {
  31640. url: url,
  31641. name: Optional.none(),
  31642. }
  31643. })
  31644. }
  31645. var getIconsUrlMetaFromName = function (editor, name, suffix) {
  31646. return Optional.from(name)
  31647. .filter(function (name) {
  31648. return name.length > 0 && !IconManager.has(name)
  31649. })
  31650. .map(function (name) {
  31651. return {
  31652. url:
  31653. editor.editorManager.baseURL +
  31654. '/icons/' +
  31655. name +
  31656. '/icons' +
  31657. suffix +
  31658. '.js',
  31659. name: Optional.some(name),
  31660. }
  31661. })
  31662. }
  31663. var loadIcons = function (scriptLoader, editor, suffix) {
  31664. var defaultIconsUrl = getIconsUrlMetaFromName(editor, 'default', suffix)
  31665. var customIconsUrl = getIconsUrlMetaFromUrl(editor).orThunk(function () {
  31666. return getIconsUrlMetaFromName(editor, getIconPackName(editor), '')
  31667. })
  31668. each$k(cat([defaultIconsUrl, customIconsUrl]), function (urlMeta) {
  31669. scriptLoader.add(urlMeta.url, noop, undefined, function () {
  31670. iconsLoadError(editor, urlMeta.url, urlMeta.name.getOrUndefined())
  31671. })
  31672. })
  31673. }
  31674. var loadPlugins = function (editor, suffix) {
  31675. Tools.each(getExternalPlugins$1(editor), function (url, name) {
  31676. PluginManager.load(name, url, noop, undefined, function () {
  31677. pluginLoadError(editor, url, name)
  31678. })
  31679. editor.settings.plugins += ' ' + name
  31680. })
  31681. Tools.each(getPlugins(editor).split(/[ ,]/), function (plugin) {
  31682. plugin = Tools.trim(plugin)
  31683. if (plugin && !PluginManager.urls[plugin]) {
  31684. if (hasSkipLoadPrefix(plugin)) {
  31685. plugin = plugin.substr(1, plugin.length)
  31686. var dependencies = PluginManager.dependencies(plugin)
  31687. Tools.each(dependencies, function (depPlugin) {
  31688. var defaultSettings = {
  31689. prefix: 'plugins/',
  31690. resource: depPlugin,
  31691. suffix: '/plugin' + suffix + '.js',
  31692. }
  31693. var dep = PluginManager.createUrl(defaultSettings, depPlugin)
  31694. PluginManager.load(dep.resource, dep, noop, undefined, function () {
  31695. pluginLoadError(
  31696. editor,
  31697. dep.prefix + dep.resource + dep.suffix,
  31698. dep.resource
  31699. )
  31700. })
  31701. })
  31702. } else {
  31703. var url_2 = {
  31704. prefix: 'plugins/',
  31705. resource: plugin,
  31706. suffix: '/plugin' + suffix + '.js',
  31707. }
  31708. PluginManager.load(plugin, url_2, noop, undefined, function () {
  31709. pluginLoadError(
  31710. editor,
  31711. url_2.prefix + url_2.resource + url_2.suffix,
  31712. plugin
  31713. )
  31714. })
  31715. }
  31716. }
  31717. })
  31718. }
  31719. var loadScripts = function (editor, suffix) {
  31720. var scriptLoader = ScriptLoader.ScriptLoader
  31721. loadTheme(scriptLoader, editor, suffix, function () {
  31722. loadLanguage(scriptLoader, editor)
  31723. loadIcons(scriptLoader, editor, suffix)
  31724. loadPlugins(editor, suffix)
  31725. scriptLoader.loadQueue(
  31726. function () {
  31727. if (!editor.removed) {
  31728. init(editor)
  31729. }
  31730. },
  31731. editor,
  31732. function () {
  31733. if (!editor.removed) {
  31734. init(editor)
  31735. }
  31736. }
  31737. )
  31738. })
  31739. }
  31740. var getStyleSheetLoader = function (element, editor) {
  31741. return instance.forElement(element, {
  31742. contentCssCors: hasContentCssCors(editor),
  31743. referrerPolicy: getReferrerPolicy(editor),
  31744. })
  31745. }
  31746. var render = function (editor) {
  31747. var id = editor.id
  31748. I18n.setCode(getLanguageCode(editor))
  31749. var readyHandler = function () {
  31750. DOM$3.unbind(window, 'ready', readyHandler)
  31751. editor.render()
  31752. }
  31753. if (!EventUtils.Event.domLoaded) {
  31754. DOM$3.bind(window, 'ready', readyHandler)
  31755. return
  31756. }
  31757. if (!editor.getElement()) {
  31758. return
  31759. }
  31760. if (!Env.contentEditable) {
  31761. return
  31762. }
  31763. var element = SugarElement.fromDom(editor.getElement())
  31764. var snapshot = clone$3(element)
  31765. editor.on('remove', function () {
  31766. eachr(element.dom.attributes, function (attr) {
  31767. return remove$6(element, attr.name)
  31768. })
  31769. setAll$1(element, snapshot)
  31770. })
  31771. editor.ui.styleSheetLoader = getStyleSheetLoader(element, editor)
  31772. if (!isInline(editor)) {
  31773. editor.orgVisibility = editor.getElement().style.visibility
  31774. editor.getElement().style.visibility = 'hidden'
  31775. } else {
  31776. editor.inline = true
  31777. }
  31778. var form = editor.getElement().form || DOM$3.getParent(id, 'form')
  31779. if (form) {
  31780. editor.formElement = form
  31781. if (hasHiddenInput(editor) && !isTextareaOrInput(editor.getElement())) {
  31782. DOM$3.insertAfter(
  31783. DOM$3.create('input', {
  31784. type: 'hidden',
  31785. name: id,
  31786. }),
  31787. id
  31788. )
  31789. editor.hasHiddenInput = true
  31790. }
  31791. editor.formEventDelegate = function (e) {
  31792. editor.fire(e.type, e)
  31793. }
  31794. DOM$3.bind(form, 'submit reset', editor.formEventDelegate)
  31795. editor.on('reset', function () {
  31796. editor.resetContent()
  31797. })
  31798. if (
  31799. shouldPatchSubmit(editor) &&
  31800. !form.submit.nodeType &&
  31801. !form.submit.length &&
  31802. !form._mceOldSubmit
  31803. ) {
  31804. form._mceOldSubmit = form.submit
  31805. form.submit = function () {
  31806. editor.editorManager.triggerSave()
  31807. editor.setDirty(false)
  31808. return form._mceOldSubmit(form)
  31809. }
  31810. }
  31811. }
  31812. editor.windowManager = WindowManager(editor)
  31813. editor.notificationManager = NotificationManager(editor)
  31814. if (isEncodingXml(editor)) {
  31815. editor.on('GetContent', function (e) {
  31816. if (e.save) {
  31817. e.content = DOM$3.encode(e.content)
  31818. }
  31819. })
  31820. }
  31821. if (shouldAddFormSubmitTrigger(editor)) {
  31822. editor.on('submit', function () {
  31823. if (editor.initialized) {
  31824. editor.save()
  31825. }
  31826. })
  31827. }
  31828. if (shouldAddUnloadTrigger(editor)) {
  31829. editor._beforeUnload = function () {
  31830. if (editor.initialized && !editor.destroyed && !editor.isHidden()) {
  31831. editor.save({
  31832. format: 'raw',
  31833. no_events: true,
  31834. set_dirty: false,
  31835. })
  31836. }
  31837. }
  31838. editor.editorManager.on('BeforeUnload', editor._beforeUnload)
  31839. }
  31840. editor.editorManager.add(editor)
  31841. loadScripts(editor, editor.suffix)
  31842. }
  31843. var addVisual = function (editor, elm) {
  31844. return addVisual$1(editor, elm)
  31845. }
  31846. var legacyPropNames = {
  31847. 'font-size': 'size',
  31848. 'font-family': 'face',
  31849. }
  31850. var getSpecifiedFontProp = function (propName, rootElm, elm) {
  31851. var getProperty = function (elm) {
  31852. return getRaw(elm, propName).orThunk(function () {
  31853. if (name(elm) === 'font') {
  31854. return get$9(legacyPropNames, propName).bind(function (
  31855. legacyPropName
  31856. ) {
  31857. return getOpt(elm, legacyPropName)
  31858. })
  31859. } else {
  31860. return Optional.none()
  31861. }
  31862. })
  31863. }
  31864. var isRoot = function (elm) {
  31865. return eq(SugarElement.fromDom(rootElm), elm)
  31866. }
  31867. return closest$1(
  31868. SugarElement.fromDom(elm),
  31869. function (elm) {
  31870. return getProperty(elm)
  31871. },
  31872. isRoot
  31873. )
  31874. }
  31875. var normalizeFontFamily = function (fontFamily) {
  31876. return fontFamily.replace(/[\'\"\\]/g, '').replace(/,\s+/g, ',')
  31877. }
  31878. var getComputedFontProp = function (propName, elm) {
  31879. return Optional.from(DOMUtils.DOM.getStyle(elm, propName, true))
  31880. }
  31881. var getFontProp = function (propName) {
  31882. return function (rootElm, elm) {
  31883. return Optional.from(elm)
  31884. .map(SugarElement.fromDom)
  31885. .filter(isElement$6)
  31886. .bind(function (element) {
  31887. return getSpecifiedFontProp(propName, rootElm, element.dom).or(
  31888. getComputedFontProp(propName, element.dom)
  31889. )
  31890. })
  31891. .getOr('')
  31892. }
  31893. }
  31894. var getFontSize = getFontProp('font-size')
  31895. var getFontFamily = compose(normalizeFontFamily, getFontProp('font-family'))
  31896. var findFirstCaretElement = function (editor) {
  31897. return firstPositionIn(editor.getBody()).map(function (caret) {
  31898. var container = caret.container()
  31899. return isText$7(container) ? container.parentNode : container
  31900. })
  31901. }
  31902. var getCaretElement = function (editor) {
  31903. return Optional.from(editor.selection.getRng()).bind(function (rng) {
  31904. var root = editor.getBody()
  31905. var atStartOfNode = rng.startContainer === root && rng.startOffset === 0
  31906. return atStartOfNode
  31907. ? Optional.none()
  31908. : Optional.from(editor.selection.getStart(true))
  31909. })
  31910. }
  31911. var bindRange = function (editor, binder) {
  31912. return getCaretElement(editor)
  31913. .orThunk(curry(findFirstCaretElement, editor))
  31914. .map(SugarElement.fromDom)
  31915. .filter(isElement$6)
  31916. .bind(binder)
  31917. }
  31918. var mapRange = function (editor, mapper) {
  31919. return bindRange(editor, compose1(Optional.some, mapper))
  31920. }
  31921. var fromFontSizeNumber = function (editor, value) {
  31922. if (/^[0-9.]+$/.test(value)) {
  31923. var fontSizeNumber = parseInt(value, 10)
  31924. if (fontSizeNumber >= 1 && fontSizeNumber <= 7) {
  31925. var fontSizes = getFontStyleValues(editor)
  31926. var fontClasses = getFontSizeClasses(editor)
  31927. if (fontClasses) {
  31928. return fontClasses[fontSizeNumber - 1] || value
  31929. } else {
  31930. return fontSizes[fontSizeNumber - 1] || value
  31931. }
  31932. } else {
  31933. return value
  31934. }
  31935. } else {
  31936. return value
  31937. }
  31938. }
  31939. var normalizeFontNames = function (font) {
  31940. var fonts = font.split(/\s*,\s*/)
  31941. return map$3(fonts, function (font) {
  31942. if (
  31943. font.indexOf(' ') !== -1 &&
  31944. !(startsWith(font, '"') || startsWith(font, "'"))
  31945. ) {
  31946. return "'" + font + "'"
  31947. } else {
  31948. return font
  31949. }
  31950. }).join(',')
  31951. }
  31952. var fontNameAction = function (editor, value) {
  31953. var font = fromFontSizeNumber(editor, value)
  31954. editor.formatter.toggle('fontname', { value: normalizeFontNames(font) })
  31955. editor.nodeChanged()
  31956. }
  31957. var fontNameQuery = function (editor) {
  31958. return mapRange(editor, function (elm) {
  31959. return getFontFamily(editor.getBody(), elm.dom)
  31960. }).getOr('')
  31961. }
  31962. var fontSizeAction = function (editor, value) {
  31963. editor.formatter.toggle('fontsize', {
  31964. value: fromFontSizeNumber(editor, value),
  31965. })
  31966. editor.nodeChanged()
  31967. }
  31968. var fontSizeQuery = function (editor) {
  31969. return mapRange(editor, function (elm) {
  31970. return getFontSize(editor.getBody(), elm.dom)
  31971. }).getOr('')
  31972. }
  31973. var lineHeightQuery = function (editor) {
  31974. return mapRange(editor, function (elm) {
  31975. var root = SugarElement.fromDom(editor.getBody())
  31976. var specifiedStyle = closest$1(
  31977. elm,
  31978. function (elm) {
  31979. return getRaw(elm, 'line-height')
  31980. },
  31981. curry(eq, root)
  31982. )
  31983. var computedStyle = function () {
  31984. var lineHeight = parseFloat(get$5(elm, 'line-height'))
  31985. var fontSize = parseFloat(get$5(elm, 'font-size'))
  31986. return String(lineHeight / fontSize)
  31987. }
  31988. return specifiedStyle.getOrThunk(computedStyle)
  31989. }).getOr('')
  31990. }
  31991. var lineHeightAction = function (editor, lineHeight) {
  31992. editor.formatter.toggle('lineheight', { value: String(lineHeight) })
  31993. editor.nodeChanged()
  31994. }
  31995. var processValue = function (value) {
  31996. if (typeof value !== 'string') {
  31997. var details = Tools.extend(
  31998. {
  31999. paste: value.paste,
  32000. data: { paste: value.paste },
  32001. },
  32002. value
  32003. )
  32004. return {
  32005. content: value.content,
  32006. details: details,
  32007. }
  32008. }
  32009. return {
  32010. content: value,
  32011. details: {},
  32012. }
  32013. }
  32014. var insertAtCaret = function (editor, value) {
  32015. var result = processValue(value)
  32016. insertContent(editor, result.content, result.details)
  32017. }
  32018. var each$4 = Tools.each
  32019. var map = Tools.map,
  32020. inArray = Tools.inArray
  32021. var EditorCommands = (function () {
  32022. function EditorCommands(editor) {
  32023. this.commands = {
  32024. state: {},
  32025. exec: {},
  32026. value: {},
  32027. }
  32028. this.editor = editor
  32029. this.setupCommands(editor)
  32030. }
  32031. EditorCommands.prototype.execCommand = function (command, ui, value, args) {
  32032. var func,
  32033. state = false
  32034. var self = this
  32035. if (self.editor.removed) {
  32036. return
  32037. }
  32038. if (command.toLowerCase() !== 'mcefocus') {
  32039. if (
  32040. !/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(
  32041. command
  32042. ) &&
  32043. (!args || !args.skip_focus)
  32044. ) {
  32045. self.editor.focus()
  32046. } else {
  32047. restore(self.editor)
  32048. }
  32049. }
  32050. args = self.editor.fire('BeforeExecCommand', {
  32051. command: command,
  32052. ui: ui,
  32053. value: value,
  32054. })
  32055. if (args.isDefaultPrevented()) {
  32056. return false
  32057. }
  32058. var customCommand = command.toLowerCase()
  32059. if ((func = self.commands.exec[customCommand])) {
  32060. func(customCommand, ui, value)
  32061. self.editor.fire('ExecCommand', {
  32062. command: command,
  32063. ui: ui,
  32064. value: value,
  32065. })
  32066. return true
  32067. }
  32068. each$4(this.editor.plugins, function (p) {
  32069. if (p.execCommand && p.execCommand(command, ui, value)) {
  32070. self.editor.fire('ExecCommand', {
  32071. command: command,
  32072. ui: ui,
  32073. value: value,
  32074. })
  32075. state = true
  32076. return false
  32077. }
  32078. })
  32079. if (state) {
  32080. return state
  32081. }
  32082. if (
  32083. self.editor.theme &&
  32084. self.editor.theme.execCommand &&
  32085. self.editor.theme.execCommand(command, ui, value)
  32086. ) {
  32087. self.editor.fire('ExecCommand', {
  32088. command: command,
  32089. ui: ui,
  32090. value: value,
  32091. })
  32092. return true
  32093. }
  32094. try {
  32095. state = self.editor.getDoc().execCommand(command, ui, value)
  32096. } catch (ex) {}
  32097. if (state) {
  32098. self.editor.fire('ExecCommand', {
  32099. command: command,
  32100. ui: ui,
  32101. value: value,
  32102. })
  32103. return true
  32104. }
  32105. return false
  32106. }
  32107. EditorCommands.prototype.queryCommandState = function (command) {
  32108. var func
  32109. if (this.editor.quirks.isHidden() || this.editor.removed) {
  32110. return
  32111. }
  32112. command = command.toLowerCase()
  32113. if ((func = this.commands.state[command])) {
  32114. return func(command)
  32115. }
  32116. try {
  32117. return this.editor.getDoc().queryCommandState(command)
  32118. } catch (ex) {}
  32119. return false
  32120. }
  32121. EditorCommands.prototype.queryCommandValue = function (command) {
  32122. var func
  32123. if (this.editor.quirks.isHidden() || this.editor.removed) {
  32124. return
  32125. }
  32126. command = command.toLowerCase()
  32127. if ((func = this.commands.value[command])) {
  32128. return func(command)
  32129. }
  32130. try {
  32131. return this.editor.getDoc().queryCommandValue(command)
  32132. } catch (ex) {}
  32133. }
  32134. EditorCommands.prototype.addCommands = function (commandList, type) {
  32135. if (type === void 0) {
  32136. type = 'exec'
  32137. }
  32138. var self = this
  32139. each$4(commandList, function (callback, command) {
  32140. each$4(command.toLowerCase().split(','), function (command) {
  32141. self.commands[type][command] = callback
  32142. })
  32143. })
  32144. }
  32145. EditorCommands.prototype.addCommand = function (command, callback, scope) {
  32146. var _this = this
  32147. command = command.toLowerCase()
  32148. this.commands.exec[command] = function (command, ui, value, args) {
  32149. return callback.call(scope || _this.editor, ui, value, args)
  32150. }
  32151. }
  32152. EditorCommands.prototype.queryCommandSupported = function (command) {
  32153. command = command.toLowerCase()
  32154. if (this.commands.exec[command]) {
  32155. return true
  32156. }
  32157. try {
  32158. return this.editor.getDoc().queryCommandSupported(command)
  32159. } catch (ex) {}
  32160. return false
  32161. }
  32162. EditorCommands.prototype.addQueryStateHandler = function (
  32163. command,
  32164. callback,
  32165. scope
  32166. ) {
  32167. var _this = this
  32168. command = command.toLowerCase()
  32169. this.commands.state[command] = function () {
  32170. return callback.call(scope || _this.editor)
  32171. }
  32172. }
  32173. EditorCommands.prototype.addQueryValueHandler = function (
  32174. command,
  32175. callback,
  32176. scope
  32177. ) {
  32178. var _this = this
  32179. command = command.toLowerCase()
  32180. this.commands.value[command] = function () {
  32181. return callback.call(scope || _this.editor)
  32182. }
  32183. }
  32184. EditorCommands.prototype.hasCustomCommand = function (command) {
  32185. command = command.toLowerCase()
  32186. return !!this.commands.exec[command]
  32187. }
  32188. EditorCommands.prototype.execNativeCommand = function (command, ui, value) {
  32189. if (ui === undefined) {
  32190. ui = false
  32191. }
  32192. if (value === undefined) {
  32193. value = null
  32194. }
  32195. return this.editor.getDoc().execCommand(command, ui, value)
  32196. }
  32197. EditorCommands.prototype.isFormatMatch = function (name) {
  32198. return this.editor.formatter.match(name)
  32199. }
  32200. EditorCommands.prototype.toggleFormat = function (name, value) {
  32201. this.editor.formatter.toggle(name, value)
  32202. this.editor.nodeChanged()
  32203. }
  32204. EditorCommands.prototype.storeSelection = function (type) {
  32205. this.selectionBookmark = this.editor.selection.getBookmark(type)
  32206. }
  32207. EditorCommands.prototype.restoreSelection = function () {
  32208. this.editor.selection.moveToBookmark(this.selectionBookmark)
  32209. }
  32210. EditorCommands.prototype.setupCommands = function (editor) {
  32211. var self = this
  32212. this.addCommands({
  32213. 'mceResetDesignMode,mceBeginUndoLevel': noop,
  32214. 'mceEndUndoLevel,mceAddUndoLevel': function () {
  32215. editor.undoManager.add()
  32216. },
  32217. mceFocus: function (_command, _ui, value) {
  32218. focus(editor, value)
  32219. },
  32220. 'Cut,Copy,Paste': function (command) {
  32221. var doc = editor.getDoc()
  32222. var failed
  32223. try {
  32224. self.execNativeCommand(command)
  32225. } catch (ex) {
  32226. failed = true
  32227. }
  32228. if (command === 'paste' && !doc.queryCommandEnabled(command)) {
  32229. failed = true
  32230. }
  32231. if (failed || !doc.queryCommandSupported(command)) {
  32232. var msg = editor.translate(
  32233. "Your browser doesn't support direct access to the clipboard. " +
  32234. 'Please use the Ctrl+X/C/V keyboard shortcuts instead.'
  32235. )
  32236. if (Env.mac) {
  32237. msg = msg.replace(/Ctrl\+/g, '\u2318+')
  32238. }
  32239. editor.notificationManager.open({
  32240. text: msg,
  32241. type: 'error',
  32242. })
  32243. }
  32244. },
  32245. unlink: function () {
  32246. if (editor.selection.isCollapsed()) {
  32247. var elm = editor.dom.getParent(editor.selection.getStart(), 'a')
  32248. if (elm) {
  32249. editor.dom.remove(elm, true)
  32250. }
  32251. return
  32252. }
  32253. editor.formatter.remove('link')
  32254. },
  32255. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone':
  32256. function (command) {
  32257. var align = command.substring(7)
  32258. if (align === 'full') {
  32259. align = 'justify'
  32260. }
  32261. each$4('left,center,right,justify'.split(','), function (name) {
  32262. if (align !== name) {
  32263. editor.formatter.remove('align' + name)
  32264. }
  32265. })
  32266. if (align !== 'none') {
  32267. self.toggleFormat('align' + align)
  32268. }
  32269. },
  32270. 'InsertUnorderedList,InsertOrderedList': function (command) {
  32271. var listParent
  32272. self.execNativeCommand(command)
  32273. var listElm = editor.dom.getParent(
  32274. editor.selection.getNode(),
  32275. 'ol,ul'
  32276. )
  32277. if (listElm) {
  32278. listParent = listElm.parentNode
  32279. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  32280. self.storeSelection()
  32281. editor.dom.split(listParent, listElm)
  32282. self.restoreSelection()
  32283. }
  32284. }
  32285. },
  32286. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (
  32287. command
  32288. ) {
  32289. self.toggleFormat(command)
  32290. },
  32291. 'ForeColor,HiliteColor': function (command, ui, value) {
  32292. self.toggleFormat(command, { value: value })
  32293. },
  32294. FontName: function (command, ui, value) {
  32295. fontNameAction(editor, value)
  32296. },
  32297. FontSize: function (command, ui, value) {
  32298. fontSizeAction(editor, value)
  32299. },
  32300. LineHeight: function (command, ui, value) {
  32301. lineHeightAction(editor, value)
  32302. },
  32303. Lang: function (command, ui, lang) {
  32304. self.toggleFormat(command, {
  32305. value: lang.code,
  32306. customValue: lang.customCode,
  32307. })
  32308. },
  32309. RemoveFormat: function (command) {
  32310. editor.formatter.remove(command)
  32311. },
  32312. mceBlockQuote: function () {
  32313. self.toggleFormat('blockquote')
  32314. },
  32315. FormatBlock: function (command, ui, value) {
  32316. return self.toggleFormat(value || 'p')
  32317. },
  32318. mceCleanup: function () {
  32319. var bookmark = editor.selection.getBookmark()
  32320. editor.setContent(editor.getContent())
  32321. editor.selection.moveToBookmark(bookmark)
  32322. },
  32323. mceRemoveNode: function (command, ui, value) {
  32324. var node = value || editor.selection.getNode()
  32325. if (node !== editor.getBody()) {
  32326. self.storeSelection()
  32327. editor.dom.remove(node, true)
  32328. self.restoreSelection()
  32329. }
  32330. },
  32331. mceSelectNodeDepth: function (command, ui, value) {
  32332. var counter = 0
  32333. editor.dom.getParent(
  32334. editor.selection.getNode(),
  32335. function (node) {
  32336. if (node.nodeType === 1 && counter++ === value) {
  32337. editor.selection.select(node)
  32338. return false
  32339. }
  32340. },
  32341. editor.getBody()
  32342. )
  32343. },
  32344. mceSelectNode: function (command, ui, value) {
  32345. editor.selection.select(value)
  32346. },
  32347. mceInsertContent: function (command, ui, value) {
  32348. insertAtCaret(editor, value)
  32349. },
  32350. mceInsertRawHTML: function (command, ui, value) {
  32351. editor.selection.setContent('tiny_mce_marker')
  32352. var content = editor.getContent()
  32353. editor.setContent(
  32354. content.replace(/tiny_mce_marker/g, function () {
  32355. return value
  32356. })
  32357. )
  32358. },
  32359. mceInsertNewLine: function (command, ui, value) {
  32360. insert(editor, value)
  32361. },
  32362. mceToggleFormat: function (command, ui, value) {
  32363. self.toggleFormat(value)
  32364. },
  32365. mceSetContent: function (command, ui, value) {
  32366. editor.setContent(value)
  32367. },
  32368. 'Indent,Outdent': function (command) {
  32369. handle(editor, command)
  32370. },
  32371. mceRepaint: noop,
  32372. InsertHorizontalRule: function () {
  32373. editor.execCommand('mceInsertContent', false, '<hr />')
  32374. },
  32375. mceToggleVisualAid: function () {
  32376. editor.hasVisual = !editor.hasVisual
  32377. editor.addVisual()
  32378. },
  32379. mceReplaceContent: function (command, ui, value) {
  32380. editor.execCommand(
  32381. 'mceInsertContent',
  32382. false,
  32383. value.replace(
  32384. /\{\$selection\}/g,
  32385. editor.selection.getContent({ format: 'text' })
  32386. )
  32387. )
  32388. },
  32389. mceInsertLink: function (command, ui, value) {
  32390. if (typeof value === 'string') {
  32391. value = { href: value }
  32392. }
  32393. var anchor = editor.dom.getParent(editor.selection.getNode(), 'a')
  32394. value.href = value.href.replace(/ /g, '%20')
  32395. if (!anchor || !value.href) {
  32396. editor.formatter.remove('link')
  32397. }
  32398. if (value.href) {
  32399. editor.formatter.apply('link', value, anchor)
  32400. }
  32401. },
  32402. selectAll: function () {
  32403. var editingHost = editor.dom.getParent(
  32404. editor.selection.getStart(),
  32405. isContentEditableTrue$4
  32406. )
  32407. if (editingHost) {
  32408. var rng = editor.dom.createRng()
  32409. rng.selectNodeContents(editingHost)
  32410. editor.selection.setRng(rng)
  32411. }
  32412. },
  32413. mceNewDocument: function () {
  32414. editor.setContent('')
  32415. },
  32416. InsertLineBreak: function (command, ui, value) {
  32417. insert$1(editor, value)
  32418. return true
  32419. },
  32420. })
  32421. var alignStates = function (name) {
  32422. return function () {
  32423. var selection = editor.selection
  32424. var nodes = selection.isCollapsed()
  32425. ? [editor.dom.getParent(selection.getNode(), editor.dom.isBlock)]
  32426. : selection.getSelectedBlocks()
  32427. var matches = map(nodes, function (node) {
  32428. return !!editor.formatter.matchNode(node, name)
  32429. })
  32430. return inArray(matches, true) !== -1
  32431. }
  32432. }
  32433. self.addCommands(
  32434. {
  32435. JustifyLeft: alignStates('alignleft'),
  32436. JustifyCenter: alignStates('aligncenter'),
  32437. JustifyRight: alignStates('alignright'),
  32438. JustifyFull: alignStates('alignjustify'),
  32439. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript':
  32440. function (command) {
  32441. return self.isFormatMatch(command)
  32442. },
  32443. mceBlockQuote: function () {
  32444. return self.isFormatMatch('blockquote')
  32445. },
  32446. Outdent: function () {
  32447. return canOutdent(editor)
  32448. },
  32449. 'InsertUnorderedList,InsertOrderedList': function (command) {
  32450. var list = editor.dom.getParent(editor.selection.getNode(), 'ul,ol')
  32451. return (
  32452. list &&
  32453. ((command === 'insertunorderedlist' && list.tagName === 'UL') ||
  32454. (command === 'insertorderedlist' && list.tagName === 'OL'))
  32455. )
  32456. },
  32457. },
  32458. 'state'
  32459. )
  32460. self.addCommands({
  32461. Undo: function () {
  32462. editor.undoManager.undo()
  32463. },
  32464. Redo: function () {
  32465. editor.undoManager.redo()
  32466. },
  32467. })
  32468. self.addQueryValueHandler(
  32469. 'FontName',
  32470. function () {
  32471. return fontNameQuery(editor)
  32472. },
  32473. this
  32474. )
  32475. self.addQueryValueHandler(
  32476. 'FontSize',
  32477. function () {
  32478. return fontSizeQuery(editor)
  32479. },
  32480. this
  32481. )
  32482. self.addQueryValueHandler(
  32483. 'LineHeight',
  32484. function () {
  32485. return lineHeightQuery(editor)
  32486. },
  32487. this
  32488. )
  32489. }
  32490. return EditorCommands
  32491. })()
  32492. var internalContentEditableAttr = 'data-mce-contenteditable'
  32493. var toggleClass = function (elm, cls, state) {
  32494. if (has(elm, cls) && state === false) {
  32495. remove$3(elm, cls)
  32496. } else if (state) {
  32497. add$1(elm, cls)
  32498. }
  32499. }
  32500. var setEditorCommandState = function (editor, cmd, state) {
  32501. try {
  32502. editor.getDoc().execCommand(cmd, false, String(state))
  32503. } catch (ex) {}
  32504. }
  32505. var setContentEditable = function (elm, state) {
  32506. elm.dom.contentEditable = state ? 'true' : 'false'
  32507. }
  32508. var switchOffContentEditableTrue = function (elm) {
  32509. each$k(descendants(elm, '*[contenteditable="true"]'), function (elm) {
  32510. set$1(elm, internalContentEditableAttr, 'true')
  32511. setContentEditable(elm, false)
  32512. })
  32513. }
  32514. var switchOnContentEditableTrue = function (elm) {
  32515. each$k(
  32516. descendants(elm, '*[' + internalContentEditableAttr + '="true"]'),
  32517. function (elm) {
  32518. remove$6(elm, internalContentEditableAttr)
  32519. setContentEditable(elm, true)
  32520. }
  32521. )
  32522. }
  32523. var removeFakeSelection = function (editor) {
  32524. Optional.from(editor.selection.getNode()).each(function (elm) {
  32525. elm.removeAttribute('data-mce-selected')
  32526. })
  32527. }
  32528. var restoreFakeSelection = function (editor) {
  32529. editor.selection.setRng(editor.selection.getRng())
  32530. }
  32531. var toggleReadOnly = function (editor, state) {
  32532. var body = SugarElement.fromDom(editor.getBody())
  32533. toggleClass(body, 'mce-content-readonly', state)
  32534. if (state) {
  32535. editor.selection.controlSelection.hideResizeRect()
  32536. editor._selectionOverrides.hideFakeCaret()
  32537. removeFakeSelection(editor)
  32538. editor.readonly = true
  32539. setContentEditable(body, false)
  32540. switchOffContentEditableTrue(body)
  32541. } else {
  32542. editor.readonly = false
  32543. setContentEditable(body, true)
  32544. switchOnContentEditableTrue(body)
  32545. setEditorCommandState(editor, 'StyleWithCSS', false)
  32546. setEditorCommandState(editor, 'enableInlineTableEditing', false)
  32547. setEditorCommandState(editor, 'enableObjectResizing', false)
  32548. if (hasEditorOrUiFocus(editor)) {
  32549. editor.focus()
  32550. }
  32551. restoreFakeSelection(editor)
  32552. editor.nodeChanged()
  32553. }
  32554. }
  32555. var isReadOnly = function (editor) {
  32556. return editor.readonly
  32557. }
  32558. var registerFilters = function (editor) {
  32559. editor.parser.addAttributeFilter('contenteditable', function (nodes) {
  32560. if (isReadOnly(editor)) {
  32561. each$k(nodes, function (node) {
  32562. node.attr(internalContentEditableAttr, node.attr('contenteditable'))
  32563. node.attr('contenteditable', 'false')
  32564. })
  32565. }
  32566. })
  32567. editor.serializer.addAttributeFilter(
  32568. internalContentEditableAttr,
  32569. function (nodes) {
  32570. if (isReadOnly(editor)) {
  32571. each$k(nodes, function (node) {
  32572. node.attr('contenteditable', node.attr(internalContentEditableAttr))
  32573. })
  32574. }
  32575. }
  32576. )
  32577. editor.serializer.addTempAttr(internalContentEditableAttr)
  32578. }
  32579. var registerReadOnlyContentFilters = function (editor) {
  32580. if (editor.serializer) {
  32581. registerFilters(editor)
  32582. } else {
  32583. editor.on('PreInit', function () {
  32584. registerFilters(editor)
  32585. })
  32586. }
  32587. }
  32588. var isClickEvent = function (e) {
  32589. return e.type === 'click'
  32590. }
  32591. var getAnchorHrefOpt = function (editor, elm) {
  32592. var isRoot = function (elm) {
  32593. return eq(elm, SugarElement.fromDom(editor.getBody()))
  32594. }
  32595. return closest$2(elm, 'a', isRoot).bind(function (a) {
  32596. return getOpt(a, 'href')
  32597. })
  32598. }
  32599. var processReadonlyEvents = function (editor, e) {
  32600. if (isClickEvent(e) && !VK.metaKeyPressed(e)) {
  32601. var elm = SugarElement.fromDom(e.target)
  32602. getAnchorHrefOpt(editor, elm).each(function (href) {
  32603. e.preventDefault()
  32604. if (/^#/.test(href)) {
  32605. var targetEl = editor.dom.select(
  32606. href + ',[name="' + removeLeading(href, '#') + '"]'
  32607. )
  32608. if (targetEl.length) {
  32609. editor.selection.scrollIntoView(targetEl[0], true)
  32610. }
  32611. } else {
  32612. window.open(
  32613. href,
  32614. '_blank',
  32615. 'rel=noopener noreferrer,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes'
  32616. )
  32617. }
  32618. })
  32619. }
  32620. }
  32621. var registerReadOnlySelectionBlockers = function (editor) {
  32622. editor.on('ShowCaret', function (e) {
  32623. if (isReadOnly(editor)) {
  32624. e.preventDefault()
  32625. }
  32626. })
  32627. editor.on('ObjectSelected', function (e) {
  32628. if (isReadOnly(editor)) {
  32629. e.preventDefault()
  32630. }
  32631. })
  32632. }
  32633. var nativeEvents = Tools.makeMap(
  32634. 'focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange ' +
  32635. 'mouseout mouseenter mouseleave wheel keydown keypress keyup input beforeinput contextmenu dragstart dragend dragover ' +
  32636. 'draggesture dragdrop drop drag submit ' +
  32637. 'compositionstart compositionend compositionupdate touchstart touchmove touchend touchcancel',
  32638. ' '
  32639. )
  32640. var EventDispatcher = (function () {
  32641. function EventDispatcher(settings) {
  32642. this.bindings = {}
  32643. this.settings = settings || {}
  32644. this.scope = this.settings.scope || this
  32645. this.toggleEvent = this.settings.toggleEvent || never
  32646. }
  32647. EventDispatcher.isNative = function (name) {
  32648. return !!nativeEvents[name.toLowerCase()]
  32649. }
  32650. EventDispatcher.prototype.fire = function (name, args) {
  32651. var lcName = name.toLowerCase()
  32652. var event = normalize$3(lcName, args || {}, this.scope)
  32653. if (this.settings.beforeFire) {
  32654. this.settings.beforeFire(event)
  32655. }
  32656. var handlers = this.bindings[lcName]
  32657. if (handlers) {
  32658. for (var i = 0, l = handlers.length; i < l; i++) {
  32659. var callback = handlers[i]
  32660. if (callback.removed) {
  32661. continue
  32662. }
  32663. if (callback.once) {
  32664. this.off(lcName, callback.func)
  32665. }
  32666. if (event.isImmediatePropagationStopped()) {
  32667. return event
  32668. }
  32669. if (callback.func.call(this.scope, event) === false) {
  32670. event.preventDefault()
  32671. return event
  32672. }
  32673. }
  32674. }
  32675. return event
  32676. }
  32677. EventDispatcher.prototype.on = function (name, callback, prepend, extra) {
  32678. if (callback === false) {
  32679. callback = never
  32680. }
  32681. if (callback) {
  32682. var wrappedCallback = {
  32683. func: callback,
  32684. removed: false,
  32685. }
  32686. if (extra) {
  32687. Tools.extend(wrappedCallback, extra)
  32688. }
  32689. var names = name.toLowerCase().split(' ')
  32690. var i = names.length
  32691. while (i--) {
  32692. var currentName = names[i]
  32693. var handlers = this.bindings[currentName]
  32694. if (!handlers) {
  32695. handlers = []
  32696. this.toggleEvent(currentName, true)
  32697. }
  32698. if (prepend) {
  32699. handlers = __spreadArray([wrappedCallback], handlers, true)
  32700. } else {
  32701. handlers = __spreadArray(
  32702. __spreadArray([], handlers, true),
  32703. [wrappedCallback],
  32704. false
  32705. )
  32706. }
  32707. this.bindings[currentName] = handlers
  32708. }
  32709. }
  32710. return this
  32711. }
  32712. EventDispatcher.prototype.off = function (name, callback) {
  32713. var _this = this
  32714. if (name) {
  32715. var names = name.toLowerCase().split(' ')
  32716. var i = names.length
  32717. while (i--) {
  32718. var currentName = names[i]
  32719. var handlers = this.bindings[currentName]
  32720. if (!currentName) {
  32721. each$j(this.bindings, function (_value, bindingName) {
  32722. _this.toggleEvent(bindingName, false)
  32723. delete _this.bindings[bindingName]
  32724. })
  32725. return this
  32726. }
  32727. if (handlers) {
  32728. if (!callback) {
  32729. handlers.length = 0
  32730. } else {
  32731. var filteredHandlers = partition(handlers, function (handler) {
  32732. return handler.func === callback
  32733. })
  32734. handlers = filteredHandlers.fail
  32735. this.bindings[currentName] = handlers
  32736. each$k(filteredHandlers.pass, function (handler) {
  32737. handler.removed = true
  32738. })
  32739. }
  32740. if (!handlers.length) {
  32741. this.toggleEvent(name, false)
  32742. delete this.bindings[currentName]
  32743. }
  32744. }
  32745. }
  32746. } else {
  32747. each$j(this.bindings, function (_value, name) {
  32748. _this.toggleEvent(name, false)
  32749. })
  32750. this.bindings = {}
  32751. }
  32752. return this
  32753. }
  32754. EventDispatcher.prototype.once = function (name, callback, prepend) {
  32755. return this.on(name, callback, prepend, { once: true })
  32756. }
  32757. EventDispatcher.prototype.has = function (name) {
  32758. name = name.toLowerCase()
  32759. return !(!this.bindings[name] || this.bindings[name].length === 0)
  32760. }
  32761. return EventDispatcher
  32762. })()
  32763. var getEventDispatcher = function (obj) {
  32764. if (!obj._eventDispatcher) {
  32765. obj._eventDispatcher = new EventDispatcher({
  32766. scope: obj,
  32767. toggleEvent: function (name, state) {
  32768. if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) {
  32769. obj.toggleNativeEvent(name, state)
  32770. }
  32771. },
  32772. })
  32773. }
  32774. return obj._eventDispatcher
  32775. }
  32776. var Observable = {
  32777. fire: function (name, args, bubble) {
  32778. var self = this
  32779. if (self.removed && name !== 'remove' && name !== 'detach') {
  32780. return args
  32781. }
  32782. var dispatcherArgs = getEventDispatcher(self).fire(name, args)
  32783. if (bubble !== false && self.parent) {
  32784. var parent_1 = self.parent()
  32785. while (parent_1 && !dispatcherArgs.isPropagationStopped()) {
  32786. parent_1.fire(name, dispatcherArgs, false)
  32787. parent_1 = parent_1.parent()
  32788. }
  32789. }
  32790. return dispatcherArgs
  32791. },
  32792. on: function (name, callback, prepend) {
  32793. return getEventDispatcher(this).on(name, callback, prepend)
  32794. },
  32795. off: function (name, callback) {
  32796. return getEventDispatcher(this).off(name, callback)
  32797. },
  32798. once: function (name, callback) {
  32799. return getEventDispatcher(this).once(name, callback)
  32800. },
  32801. hasEventListeners: function (name) {
  32802. return getEventDispatcher(this).has(name)
  32803. },
  32804. }
  32805. var DOM$2 = DOMUtils.DOM
  32806. var customEventRootDelegates
  32807. var getEventTarget = function (editor, eventName) {
  32808. if (eventName === 'selectionchange') {
  32809. return editor.getDoc()
  32810. }
  32811. if (
  32812. !editor.inline &&
  32813. /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)
  32814. ) {
  32815. return editor.getDoc().documentElement
  32816. }
  32817. var eventRoot = getEventRoot(editor)
  32818. if (eventRoot) {
  32819. if (!editor.eventRoot) {
  32820. editor.eventRoot = DOM$2.select(eventRoot)[0]
  32821. }
  32822. return editor.eventRoot
  32823. }
  32824. return editor.getBody()
  32825. }
  32826. var isListening = function (editor) {
  32827. return !editor.hidden && !isReadOnly(editor)
  32828. }
  32829. var fireEvent = function (editor, eventName, e) {
  32830. if (isListening(editor)) {
  32831. editor.fire(eventName, e)
  32832. } else if (isReadOnly(editor)) {
  32833. processReadonlyEvents(editor, e)
  32834. }
  32835. }
  32836. var bindEventDelegate = function (editor, eventName) {
  32837. var delegate
  32838. if (!editor.delegates) {
  32839. editor.delegates = {}
  32840. }
  32841. if (editor.delegates[eventName] || editor.removed) {
  32842. return
  32843. }
  32844. var eventRootElm = getEventTarget(editor, eventName)
  32845. if (getEventRoot(editor)) {
  32846. if (!customEventRootDelegates) {
  32847. customEventRootDelegates = {}
  32848. editor.editorManager.on('removeEditor', function () {
  32849. if (!editor.editorManager.activeEditor) {
  32850. if (customEventRootDelegates) {
  32851. each$j(customEventRootDelegates, function (_value, name) {
  32852. editor.dom.unbind(getEventTarget(editor, name))
  32853. })
  32854. customEventRootDelegates = null
  32855. }
  32856. }
  32857. })
  32858. }
  32859. if (customEventRootDelegates[eventName]) {
  32860. return
  32861. }
  32862. delegate = function (e) {
  32863. var target = e.target
  32864. var editors = editor.editorManager.get()
  32865. var i = editors.length
  32866. while (i--) {
  32867. var body = editors[i].getBody()
  32868. if (body === target || DOM$2.isChildOf(target, body)) {
  32869. fireEvent(editors[i], eventName, e)
  32870. }
  32871. }
  32872. }
  32873. customEventRootDelegates[eventName] = delegate
  32874. DOM$2.bind(eventRootElm, eventName, delegate)
  32875. } else {
  32876. delegate = function (e) {
  32877. fireEvent(editor, eventName, e)
  32878. }
  32879. DOM$2.bind(eventRootElm, eventName, delegate)
  32880. editor.delegates[eventName] = delegate
  32881. }
  32882. }
  32883. var EditorObservable = __assign(__assign({}, Observable), {
  32884. bindPendingEventDelegates: function () {
  32885. var self = this
  32886. Tools.each(self._pendingNativeEvents, function (name) {
  32887. bindEventDelegate(self, name)
  32888. })
  32889. },
  32890. toggleNativeEvent: function (name, state) {
  32891. var self = this
  32892. if (name === 'focus' || name === 'blur') {
  32893. return
  32894. }
  32895. if (self.removed) {
  32896. return
  32897. }
  32898. if (state) {
  32899. if (self.initialized) {
  32900. bindEventDelegate(self, name)
  32901. } else {
  32902. if (!self._pendingNativeEvents) {
  32903. self._pendingNativeEvents = [name]
  32904. } else {
  32905. self._pendingNativeEvents.push(name)
  32906. }
  32907. }
  32908. } else if (self.initialized) {
  32909. self.dom.unbind(getEventTarget(self, name), name, self.delegates[name])
  32910. delete self.delegates[name]
  32911. }
  32912. },
  32913. unbindAllNativeEvents: function () {
  32914. var self = this
  32915. var body = self.getBody()
  32916. var dom = self.dom
  32917. if (self.delegates) {
  32918. each$j(self.delegates, function (value, name) {
  32919. self.dom.unbind(getEventTarget(self, name), name, value)
  32920. })
  32921. delete self.delegates
  32922. }
  32923. if (!self.inline && body && dom) {
  32924. body.onload = null
  32925. dom.unbind(self.getWin())
  32926. dom.unbind(self.getDoc())
  32927. }
  32928. if (dom) {
  32929. dom.unbind(body)
  32930. dom.unbind(self.getContainer())
  32931. }
  32932. },
  32933. })
  32934. var defaultModes = ['design', 'readonly']
  32935. var switchToMode = function (editor, activeMode, availableModes, mode) {
  32936. var oldMode = availableModes[activeMode.get()]
  32937. var newMode = availableModes[mode]
  32938. try {
  32939. newMode.activate()
  32940. } catch (e) {
  32941. console.error('problem while activating editor mode ' + mode + ':', e)
  32942. return
  32943. }
  32944. oldMode.deactivate()
  32945. if (oldMode.editorReadOnly !== newMode.editorReadOnly) {
  32946. toggleReadOnly(editor, newMode.editorReadOnly)
  32947. }
  32948. activeMode.set(mode)
  32949. fireSwitchMode(editor, mode)
  32950. }
  32951. var setMode = function (editor, availableModes, activeMode, mode) {
  32952. if (mode === activeMode.get()) {
  32953. return
  32954. } else if (!has$2(availableModes, mode)) {
  32955. throw new Error("Editor mode '" + mode + "' is invalid")
  32956. }
  32957. if (editor.initialized) {
  32958. switchToMode(editor, activeMode, availableModes, mode)
  32959. } else {
  32960. editor.on('init', function () {
  32961. return switchToMode(editor, activeMode, availableModes, mode)
  32962. })
  32963. }
  32964. }
  32965. var registerMode = function (availableModes, mode, api) {
  32966. var _a
  32967. if (contains$3(defaultModes, mode)) {
  32968. throw new Error('Cannot override default mode ' + mode)
  32969. }
  32970. return __assign(
  32971. __assign({}, availableModes),
  32972. ((_a = {}),
  32973. (_a[mode] = __assign(__assign({}, api), {
  32974. deactivate: function () {
  32975. try {
  32976. api.deactivate()
  32977. } catch (e) {
  32978. console.error(
  32979. 'problem while deactivating editor mode ' + mode + ':',
  32980. e
  32981. )
  32982. }
  32983. },
  32984. })),
  32985. _a)
  32986. )
  32987. }
  32988. var create$4 = function (editor) {
  32989. var activeMode = Cell('design')
  32990. var availableModes = Cell({
  32991. design: {
  32992. activate: noop,
  32993. deactivate: noop,
  32994. editorReadOnly: false,
  32995. },
  32996. readonly: {
  32997. activate: noop,
  32998. deactivate: noop,
  32999. editorReadOnly: true,
  33000. },
  33001. })
  33002. registerReadOnlyContentFilters(editor)
  33003. registerReadOnlySelectionBlockers(editor)
  33004. return {
  33005. isReadOnly: function () {
  33006. return isReadOnly(editor)
  33007. },
  33008. set: function (mode) {
  33009. return setMode(editor, availableModes.get(), activeMode, mode)
  33010. },
  33011. get: function () {
  33012. return activeMode.get()
  33013. },
  33014. register: function (mode, api) {
  33015. availableModes.set(registerMode(availableModes.get(), mode, api))
  33016. },
  33017. }
  33018. }
  33019. var each$3 = Tools.each,
  33020. explode$1 = Tools.explode
  33021. var keyCodeLookup = {
  33022. f1: 112,
  33023. f2: 113,
  33024. f3: 114,
  33025. f4: 115,
  33026. f5: 116,
  33027. f6: 117,
  33028. f7: 118,
  33029. f8: 119,
  33030. f9: 120,
  33031. f10: 121,
  33032. f11: 122,
  33033. f12: 123,
  33034. }
  33035. var modifierNames = Tools.makeMap('alt,ctrl,shift,meta,access')
  33036. var parseShortcut = function (pattern) {
  33037. var key
  33038. var shortcut = {}
  33039. each$3(explode$1(pattern.toLowerCase(), '+'), function (value) {
  33040. if (value in modifierNames) {
  33041. shortcut[value] = true
  33042. } else {
  33043. if (/^[0-9]{2,}$/.test(value)) {
  33044. shortcut.keyCode = parseInt(value, 10)
  33045. } else {
  33046. shortcut.charCode = value.charCodeAt(0)
  33047. shortcut.keyCode =
  33048. keyCodeLookup[value] || value.toUpperCase().charCodeAt(0)
  33049. }
  33050. }
  33051. })
  33052. var id = [shortcut.keyCode]
  33053. for (key in modifierNames) {
  33054. if (shortcut[key]) {
  33055. id.push(key)
  33056. } else {
  33057. shortcut[key] = false
  33058. }
  33059. }
  33060. shortcut.id = id.join(',')
  33061. if (shortcut.access) {
  33062. shortcut.alt = true
  33063. if (Env.mac) {
  33064. shortcut.ctrl = true
  33065. } else {
  33066. shortcut.shift = true
  33067. }
  33068. }
  33069. if (shortcut.meta) {
  33070. if (Env.mac) {
  33071. shortcut.meta = true
  33072. } else {
  33073. shortcut.ctrl = true
  33074. shortcut.meta = false
  33075. }
  33076. }
  33077. return shortcut
  33078. }
  33079. var Shortcuts = (function () {
  33080. function Shortcuts(editor) {
  33081. this.shortcuts = {}
  33082. this.pendingPatterns = []
  33083. this.editor = editor
  33084. var self = this
  33085. editor.on('keyup keypress keydown', function (e) {
  33086. if (
  33087. (self.hasModifier(e) || self.isFunctionKey(e)) &&
  33088. !e.isDefaultPrevented()
  33089. ) {
  33090. each$3(self.shortcuts, function (shortcut) {
  33091. if (self.matchShortcut(e, shortcut)) {
  33092. self.pendingPatterns = shortcut.subpatterns.slice(0)
  33093. if (e.type === 'keydown') {
  33094. self.executeShortcutAction(shortcut)
  33095. }
  33096. return true
  33097. }
  33098. })
  33099. if (self.matchShortcut(e, self.pendingPatterns[0])) {
  33100. if (self.pendingPatterns.length === 1) {
  33101. if (e.type === 'keydown') {
  33102. self.executeShortcutAction(self.pendingPatterns[0])
  33103. }
  33104. }
  33105. self.pendingPatterns.shift()
  33106. }
  33107. }
  33108. })
  33109. }
  33110. Shortcuts.prototype.add = function (pattern, desc, cmdFunc, scope) {
  33111. var self = this
  33112. var func = self.normalizeCommandFunc(cmdFunc)
  33113. each$3(explode$1(Tools.trim(pattern)), function (pattern) {
  33114. var shortcut = self.createShortcut(pattern, desc, func, scope)
  33115. self.shortcuts[shortcut.id] = shortcut
  33116. })
  33117. return true
  33118. }
  33119. Shortcuts.prototype.remove = function (pattern) {
  33120. var shortcut = this.createShortcut(pattern)
  33121. if (this.shortcuts[shortcut.id]) {
  33122. delete this.shortcuts[shortcut.id]
  33123. return true
  33124. }
  33125. return false
  33126. }
  33127. Shortcuts.prototype.normalizeCommandFunc = function (cmdFunc) {
  33128. var self = this
  33129. var cmd = cmdFunc
  33130. if (typeof cmd === 'string') {
  33131. return function () {
  33132. self.editor.execCommand(cmd, false, null)
  33133. }
  33134. } else if (Tools.isArray(cmd)) {
  33135. return function () {
  33136. self.editor.execCommand(cmd[0], cmd[1], cmd[2])
  33137. }
  33138. } else {
  33139. return cmd
  33140. }
  33141. }
  33142. Shortcuts.prototype.createShortcut = function (
  33143. pattern,
  33144. desc,
  33145. cmdFunc,
  33146. scope
  33147. ) {
  33148. var shortcuts = Tools.map(explode$1(pattern, '>'), parseShortcut)
  33149. shortcuts[shortcuts.length - 1] = Tools.extend(
  33150. shortcuts[shortcuts.length - 1],
  33151. {
  33152. func: cmdFunc,
  33153. scope: scope || this.editor,
  33154. }
  33155. )
  33156. return Tools.extend(shortcuts[0], {
  33157. desc: this.editor.translate(desc),
  33158. subpatterns: shortcuts.slice(1),
  33159. })
  33160. }
  33161. Shortcuts.prototype.hasModifier = function (e) {
  33162. return e.altKey || e.ctrlKey || e.metaKey
  33163. }
  33164. Shortcuts.prototype.isFunctionKey = function (e) {
  33165. return e.type === 'keydown' && e.keyCode >= 112 && e.keyCode <= 123
  33166. }
  33167. Shortcuts.prototype.matchShortcut = function (e, shortcut) {
  33168. if (!shortcut) {
  33169. return false
  33170. }
  33171. if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) {
  33172. return false
  33173. }
  33174. if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) {
  33175. return false
  33176. }
  33177. if (
  33178. e.keyCode === shortcut.keyCode ||
  33179. (e.charCode && e.charCode === shortcut.charCode)
  33180. ) {
  33181. e.preventDefault()
  33182. return true
  33183. }
  33184. return false
  33185. }
  33186. Shortcuts.prototype.executeShortcutAction = function (shortcut) {
  33187. return shortcut.func ? shortcut.func.call(shortcut.scope) : null
  33188. }
  33189. return Shortcuts
  33190. })()
  33191. var create$3 = function () {
  33192. var buttons = {}
  33193. var menuItems = {}
  33194. var popups = {}
  33195. var icons = {}
  33196. var contextMenus = {}
  33197. var contextToolbars = {}
  33198. var sidebars = {}
  33199. var add = function (collection, type) {
  33200. return function (name, spec) {
  33201. return (collection[name.toLowerCase()] = __assign(__assign({}, spec), {
  33202. type: type,
  33203. }))
  33204. }
  33205. }
  33206. var addIcon = function (name, svgData) {
  33207. return (icons[name.toLowerCase()] = svgData)
  33208. }
  33209. return {
  33210. addButton: add(buttons, 'button'),
  33211. addGroupToolbarButton: add(buttons, 'grouptoolbarbutton'),
  33212. addToggleButton: add(buttons, 'togglebutton'),
  33213. addMenuButton: add(buttons, 'menubutton'),
  33214. addSplitButton: add(buttons, 'splitbutton'),
  33215. addMenuItem: add(menuItems, 'menuitem'),
  33216. addNestedMenuItem: add(menuItems, 'nestedmenuitem'),
  33217. addToggleMenuItem: add(menuItems, 'togglemenuitem'),
  33218. addAutocompleter: add(popups, 'autocompleter'),
  33219. addContextMenu: add(contextMenus, 'contextmenu'),
  33220. addContextToolbar: add(contextToolbars, 'contexttoolbar'),
  33221. addContextForm: add(contextToolbars, 'contextform'),
  33222. addSidebar: add(sidebars, 'sidebar'),
  33223. addIcon: addIcon,
  33224. getAll: function () {
  33225. return {
  33226. buttons: buttons,
  33227. menuItems: menuItems,
  33228. icons: icons,
  33229. popups: popups,
  33230. contextMenus: contextMenus,
  33231. contextToolbars: contextToolbars,
  33232. sidebars: sidebars,
  33233. }
  33234. },
  33235. }
  33236. }
  33237. var registry = function () {
  33238. var bridge = create$3()
  33239. return {
  33240. addAutocompleter: bridge.addAutocompleter,
  33241. addButton: bridge.addButton,
  33242. addContextForm: bridge.addContextForm,
  33243. addContextMenu: bridge.addContextMenu,
  33244. addContextToolbar: bridge.addContextToolbar,
  33245. addIcon: bridge.addIcon,
  33246. addMenuButton: bridge.addMenuButton,
  33247. addMenuItem: bridge.addMenuItem,
  33248. addNestedMenuItem: bridge.addNestedMenuItem,
  33249. addSidebar: bridge.addSidebar,
  33250. addSplitButton: bridge.addSplitButton,
  33251. addToggleButton: bridge.addToggleButton,
  33252. addGroupToolbarButton: bridge.addGroupToolbarButton,
  33253. addToggleMenuItem: bridge.addToggleMenuItem,
  33254. getAll: bridge.getAll,
  33255. }
  33256. }
  33257. var DOM$1 = DOMUtils.DOM
  33258. var extend$3 = Tools.extend,
  33259. each$2 = Tools.each
  33260. var resolve = Tools.resolve
  33261. var ie = Env.ie
  33262. var Editor = (function () {
  33263. function Editor(id, settings, editorManager) {
  33264. var _this = this
  33265. this.plugins = {}
  33266. this.contentCSS = []
  33267. this.contentStyles = []
  33268. this.loadedCSS = {}
  33269. this.isNotDirty = false
  33270. this.editorManager = editorManager
  33271. this.documentBaseUrl = editorManager.documentBaseURL
  33272. extend$3(this, EditorObservable)
  33273. this.settings = getEditorSettings(
  33274. this,
  33275. id,
  33276. this.documentBaseUrl,
  33277. editorManager.defaultSettings,
  33278. settings
  33279. )
  33280. if (this.settings.suffix) {
  33281. editorManager.suffix = this.settings.suffix
  33282. }
  33283. this.suffix = editorManager.suffix
  33284. if (this.settings.base_url) {
  33285. editorManager._setBaseUrl(this.settings.base_url)
  33286. }
  33287. this.baseUri = editorManager.baseURI
  33288. if (this.settings.referrer_policy) {
  33289. ScriptLoader.ScriptLoader._setReferrerPolicy(
  33290. this.settings.referrer_policy
  33291. )
  33292. DOMUtils.DOM.styleSheetLoader._setReferrerPolicy(
  33293. this.settings.referrer_policy
  33294. )
  33295. }
  33296. AddOnManager.languageLoad = this.settings.language_load
  33297. AddOnManager.baseURL = editorManager.baseURL
  33298. this.id = id
  33299. this.setDirty(false)
  33300. this.documentBaseURI = new URI(this.settings.document_base_url, {
  33301. base_uri: this.baseUri,
  33302. })
  33303. this.baseURI = this.baseUri
  33304. this.inline = !!this.settings.inline
  33305. this.shortcuts = new Shortcuts(this)
  33306. this.editorCommands = new EditorCommands(this)
  33307. if (this.settings.cache_suffix) {
  33308. Env.cacheSuffix = this.settings.cache_suffix.replace(/^[\?\&]+/, '')
  33309. }
  33310. this.ui = {
  33311. registry: registry(),
  33312. styleSheetLoader: undefined,
  33313. show: noop,
  33314. hide: noop,
  33315. enable: noop,
  33316. disable: noop,
  33317. isDisabled: never,
  33318. }
  33319. var self = this
  33320. var modeInstance = create$4(self)
  33321. this.mode = modeInstance
  33322. this.setMode = modeInstance.set
  33323. editorManager.fire('SetupEditor', { editor: this })
  33324. this.execCallback('setup', this)
  33325. this.$ = DomQuery.overrideDefaults(function () {
  33326. return {
  33327. context: _this.inline ? _this.getBody() : _this.getDoc(),
  33328. element: _this.getBody(),
  33329. }
  33330. })
  33331. }
  33332. Editor.prototype.render = function () {
  33333. render(this)
  33334. }
  33335. Editor.prototype.focus = function (skipFocus) {
  33336. this.execCommand('mceFocus', false, skipFocus)
  33337. }
  33338. Editor.prototype.hasFocus = function () {
  33339. return hasFocus(this)
  33340. }
  33341. Editor.prototype.execCallback = function (name) {
  33342. var x = []
  33343. for (var _i = 1; _i < arguments.length; _i++) {
  33344. x[_i - 1] = arguments[_i]
  33345. }
  33346. var self = this
  33347. var callback = self.settings[name],
  33348. scope
  33349. if (!callback) {
  33350. return
  33351. }
  33352. if (self.callbackLookup && (scope = self.callbackLookup[name])) {
  33353. callback = scope.func
  33354. scope = scope.scope
  33355. }
  33356. if (typeof callback === 'string') {
  33357. scope = callback.replace(/\.\w+$/, '')
  33358. scope = scope ? resolve(scope) : 0
  33359. callback = resolve(callback)
  33360. self.callbackLookup = self.callbackLookup || {}
  33361. self.callbackLookup[name] = {
  33362. func: callback,
  33363. scope: scope,
  33364. }
  33365. }
  33366. return callback.apply(scope || self, x)
  33367. }
  33368. Editor.prototype.translate = function (text) {
  33369. return I18n.translate(text)
  33370. }
  33371. Editor.prototype.getParam = function (name, defaultVal, type) {
  33372. return getParam(this, name, defaultVal, type)
  33373. }
  33374. Editor.prototype.hasPlugin = function (name, loaded) {
  33375. var hasPlugin = contains$3(getPlugins(this).split(/[ ,]/), name)
  33376. if (hasPlugin) {
  33377. return loaded ? PluginManager.get(name) !== undefined : true
  33378. } else {
  33379. return false
  33380. }
  33381. }
  33382. Editor.prototype.nodeChanged = function (args) {
  33383. this._nodeChangeDispatcher.nodeChanged(args)
  33384. }
  33385. Editor.prototype.addCommand = function (name, callback, scope) {
  33386. this.editorCommands.addCommand(name, callback, scope)
  33387. }
  33388. Editor.prototype.addQueryStateHandler = function (name, callback, scope) {
  33389. this.editorCommands.addQueryStateHandler(name, callback, scope)
  33390. }
  33391. Editor.prototype.addQueryValueHandler = function (name, callback, scope) {
  33392. this.editorCommands.addQueryValueHandler(name, callback, scope)
  33393. }
  33394. Editor.prototype.addShortcut = function (pattern, desc, cmdFunc, scope) {
  33395. this.shortcuts.add(pattern, desc, cmdFunc, scope)
  33396. }
  33397. Editor.prototype.execCommand = function (cmd, ui, value, args) {
  33398. return this.editorCommands.execCommand(cmd, ui, value, args)
  33399. }
  33400. Editor.prototype.queryCommandState = function (cmd) {
  33401. return this.editorCommands.queryCommandState(cmd)
  33402. }
  33403. Editor.prototype.queryCommandValue = function (cmd) {
  33404. return this.editorCommands.queryCommandValue(cmd)
  33405. }
  33406. Editor.prototype.queryCommandSupported = function (cmd) {
  33407. return this.editorCommands.queryCommandSupported(cmd)
  33408. }
  33409. Editor.prototype.show = function () {
  33410. var self = this
  33411. if (self.hidden) {
  33412. self.hidden = false
  33413. if (self.inline) {
  33414. self.getBody().contentEditable = 'true'
  33415. } else {
  33416. DOM$1.show(self.getContainer())
  33417. DOM$1.hide(self.id)
  33418. }
  33419. self.load()
  33420. self.fire('show')
  33421. }
  33422. }
  33423. Editor.prototype.hide = function () {
  33424. var self = this,
  33425. doc = self.getDoc()
  33426. if (!self.hidden) {
  33427. if (ie && doc && !self.inline) {
  33428. doc.execCommand('SelectAll')
  33429. }
  33430. self.save()
  33431. if (self.inline) {
  33432. self.getBody().contentEditable = 'false'
  33433. if (self === self.editorManager.focusedEditor) {
  33434. self.editorManager.focusedEditor = null
  33435. }
  33436. } else {
  33437. DOM$1.hide(self.getContainer())
  33438. DOM$1.setStyle(self.id, 'display', self.orgDisplay)
  33439. }
  33440. self.hidden = true
  33441. self.fire('hide')
  33442. }
  33443. }
  33444. Editor.prototype.isHidden = function () {
  33445. return !!this.hidden
  33446. }
  33447. Editor.prototype.setProgressState = function (state, time) {
  33448. this.fire('ProgressState', {
  33449. state: state,
  33450. time: time,
  33451. })
  33452. }
  33453. Editor.prototype.load = function (args) {
  33454. var self = this
  33455. var elm = self.getElement(),
  33456. html
  33457. if (self.removed) {
  33458. return ''
  33459. }
  33460. if (elm) {
  33461. args = args || {}
  33462. args.load = true
  33463. var value = isTextareaOrInput(elm) ? elm.value : elm.innerHTML
  33464. html = self.setContent(value, args)
  33465. args.element = elm
  33466. if (!args.no_events) {
  33467. self.fire('LoadContent', args)
  33468. }
  33469. args.element = elm = null
  33470. return html
  33471. }
  33472. }
  33473. Editor.prototype.save = function (args) {
  33474. var self = this
  33475. var elm = self.getElement(),
  33476. html,
  33477. form
  33478. if (!elm || !self.initialized || self.removed) {
  33479. return
  33480. }
  33481. args = args || {}
  33482. args.save = true
  33483. args.element = elm
  33484. html = args.content = self.getContent(args)
  33485. if (!args.no_events) {
  33486. self.fire('SaveContent', args)
  33487. }
  33488. if (args.format === 'raw') {
  33489. self.fire('RawSaveContent', args)
  33490. }
  33491. html = args.content
  33492. if (!isTextareaOrInput(elm)) {
  33493. if (args.is_removing || !self.inline) {
  33494. elm.innerHTML = html
  33495. }
  33496. if ((form = DOM$1.getParent(self.id, 'form'))) {
  33497. each$2(form.elements, function (elm) {
  33498. if (elm.name === self.id) {
  33499. elm.value = html
  33500. return false
  33501. }
  33502. })
  33503. }
  33504. } else {
  33505. elm.value = html
  33506. }
  33507. args.element = elm = null
  33508. if (args.set_dirty !== false) {
  33509. self.setDirty(false)
  33510. }
  33511. return html
  33512. }
  33513. Editor.prototype.setContent = function (content, args) {
  33514. return setContent(this, content, args)
  33515. }
  33516. Editor.prototype.getContent = function (args) {
  33517. return getContent(this, args)
  33518. }
  33519. Editor.prototype.insertContent = function (content, args) {
  33520. if (args) {
  33521. content = extend$3({ content: content }, args)
  33522. }
  33523. this.execCommand('mceInsertContent', false, content)
  33524. }
  33525. Editor.prototype.resetContent = function (initialContent) {
  33526. if (initialContent === undefined) {
  33527. setContent(this, this.startContent, { format: 'raw' })
  33528. } else {
  33529. setContent(this, initialContent)
  33530. }
  33531. this.undoManager.reset()
  33532. this.setDirty(false)
  33533. this.nodeChanged()
  33534. }
  33535. Editor.prototype.isDirty = function () {
  33536. return !this.isNotDirty
  33537. }
  33538. Editor.prototype.setDirty = function (state) {
  33539. var oldState = !this.isNotDirty
  33540. this.isNotDirty = !state
  33541. if (state && state !== oldState) {
  33542. this.fire('dirty')
  33543. }
  33544. }
  33545. Editor.prototype.getContainer = function () {
  33546. var self = this
  33547. if (!self.container) {
  33548. self.container = DOM$1.get(self.editorContainer || self.id + '_parent')
  33549. }
  33550. return self.container
  33551. }
  33552. Editor.prototype.getContentAreaContainer = function () {
  33553. return this.contentAreaContainer
  33554. }
  33555. Editor.prototype.getElement = function () {
  33556. if (!this.targetElm) {
  33557. this.targetElm = DOM$1.get(this.id)
  33558. }
  33559. return this.targetElm
  33560. }
  33561. Editor.prototype.getWin = function () {
  33562. var self = this
  33563. var elm
  33564. if (!self.contentWindow) {
  33565. elm = self.iframeElement
  33566. if (elm) {
  33567. self.contentWindow = elm.contentWindow
  33568. }
  33569. }
  33570. return self.contentWindow
  33571. }
  33572. Editor.prototype.getDoc = function () {
  33573. var self = this
  33574. var win
  33575. if (!self.contentDocument) {
  33576. win = self.getWin()
  33577. if (win) {
  33578. self.contentDocument = win.document
  33579. }
  33580. }
  33581. return self.contentDocument
  33582. }
  33583. Editor.prototype.getBody = function () {
  33584. var doc = this.getDoc()
  33585. return this.bodyElement || (doc ? doc.body : null)
  33586. }
  33587. Editor.prototype.convertURL = function (url, name, elm) {
  33588. var self = this,
  33589. settings = self.settings
  33590. if (settings.urlconverter_callback) {
  33591. return self.execCallback('urlconverter_callback', url, elm, true, name)
  33592. }
  33593. if (
  33594. !settings.convert_urls ||
  33595. (elm && elm.nodeName === 'LINK') ||
  33596. url.indexOf('file:') === 0 ||
  33597. url.length === 0
  33598. ) {
  33599. return url
  33600. }
  33601. if (settings.relative_urls) {
  33602. return self.documentBaseURI.toRelative(url)
  33603. }
  33604. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host)
  33605. return url
  33606. }
  33607. Editor.prototype.addVisual = function (elm) {
  33608. addVisual(this, elm)
  33609. }
  33610. Editor.prototype.remove = function () {
  33611. remove(this)
  33612. }
  33613. Editor.prototype.destroy = function (automatic) {
  33614. destroy(this, automatic)
  33615. }
  33616. Editor.prototype.uploadImages = function (callback) {
  33617. return this.editorUpload.uploadImages(callback)
  33618. }
  33619. Editor.prototype._scanForImages = function () {
  33620. return this.editorUpload.scanForImages()
  33621. }
  33622. Editor.prototype.addButton = function () {
  33623. throw new Error(
  33624. 'editor.addButton has been removed in tinymce 5x, use editor.ui.registry.addButton or editor.ui.registry.addToggleButton or editor.ui.registry.addSplitButton instead'
  33625. )
  33626. }
  33627. Editor.prototype.addSidebar = function () {
  33628. throw new Error(
  33629. 'editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead'
  33630. )
  33631. }
  33632. Editor.prototype.addMenuItem = function () {
  33633. throw new Error(
  33634. 'editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead'
  33635. )
  33636. }
  33637. Editor.prototype.addContextToolbar = function () {
  33638. throw new Error(
  33639. 'editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead'
  33640. )
  33641. }
  33642. return Editor
  33643. })()
  33644. var DOM = DOMUtils.DOM
  33645. var explode = Tools.explode,
  33646. each$1 = Tools.each,
  33647. extend$2 = Tools.extend
  33648. var instanceCounter = 0,
  33649. boundGlobalEvents = false
  33650. var beforeUnloadDelegate
  33651. var legacyEditors = []
  33652. var editors = []
  33653. var isValidLegacyKey = function (id) {
  33654. return id !== 'length'
  33655. }
  33656. var globalEventDelegate = function (e) {
  33657. var type = e.type
  33658. each$1(EditorManager.get(), function (editor) {
  33659. switch (type) {
  33660. case 'scroll':
  33661. editor.fire('ScrollWindow', e)
  33662. break
  33663. case 'resize':
  33664. editor.fire('ResizeWindow', e)
  33665. break
  33666. }
  33667. })
  33668. }
  33669. var toggleGlobalEvents = function (state) {
  33670. if (state !== boundGlobalEvents) {
  33671. if (state) {
  33672. DomQuery(window).on('resize scroll', globalEventDelegate)
  33673. } else {
  33674. DomQuery(window).off('resize scroll', globalEventDelegate)
  33675. }
  33676. boundGlobalEvents = state
  33677. }
  33678. }
  33679. var removeEditorFromList = function (targetEditor) {
  33680. var oldEditors = editors
  33681. delete legacyEditors[targetEditor.id]
  33682. for (var i = 0; i < legacyEditors.length; i++) {
  33683. if (legacyEditors[i] === targetEditor) {
  33684. legacyEditors.splice(i, 1)
  33685. break
  33686. }
  33687. }
  33688. editors = filter$4(editors, function (editor) {
  33689. return targetEditor !== editor
  33690. })
  33691. if (EditorManager.activeEditor === targetEditor) {
  33692. EditorManager.activeEditor = editors.length > 0 ? editors[0] : null
  33693. }
  33694. if (EditorManager.focusedEditor === targetEditor) {
  33695. EditorManager.focusedEditor = null
  33696. }
  33697. return oldEditors.length !== editors.length
  33698. }
  33699. var purgeDestroyedEditor = function (editor) {
  33700. if (
  33701. editor &&
  33702. editor.initialized &&
  33703. !(editor.getContainer() || editor.getBody()).parentNode
  33704. ) {
  33705. removeEditorFromList(editor)
  33706. editor.unbindAllNativeEvents()
  33707. editor.destroy(true)
  33708. editor.removed = true
  33709. editor = null
  33710. }
  33711. return editor
  33712. }
  33713. var isQuirksMode = document.compatMode !== 'CSS1Compat'
  33714. var EditorManager = __assign(__assign({}, Observable), {
  33715. baseURI: null,
  33716. baseURL: null,
  33717. defaultSettings: {},
  33718. documentBaseURL: null,
  33719. suffix: null,
  33720. $: DomQuery,
  33721. majorVersion: '5',
  33722. minorVersion: '10.2',
  33723. releaseDate: '2021-11-17',
  33724. editors: legacyEditors,
  33725. i18n: I18n,
  33726. activeEditor: null,
  33727. focusedEditor: null,
  33728. settings: {},
  33729. setup: function () {
  33730. var self = this
  33731. var baseURL,
  33732. documentBaseURL,
  33733. suffix = ''
  33734. documentBaseURL = URI.getDocumentBaseUrl(document.location)
  33735. if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) {
  33736. documentBaseURL = documentBaseURL
  33737. .replace(/[\?#].*$/, '')
  33738. .replace(/[\/\\][^\/]+$/, '')
  33739. if (!/[\/\\]$/.test(documentBaseURL)) {
  33740. documentBaseURL += '/'
  33741. }
  33742. }
  33743. var preInit = window.tinymce || window.tinyMCEPreInit
  33744. if (preInit) {
  33745. baseURL = preInit.base || preInit.baseURL
  33746. suffix = preInit.suffix
  33747. } else {
  33748. var scripts = document.getElementsByTagName('script')
  33749. for (var i = 0; i < scripts.length; i++) {
  33750. var src = scripts[i].src || ''
  33751. if (src === '') {
  33752. continue
  33753. }
  33754. var srcScript = src.substring(src.lastIndexOf('/'))
  33755. if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
  33756. if (srcScript.indexOf('.min') !== -1) {
  33757. suffix = '.min'
  33758. }
  33759. baseURL = src.substring(0, src.lastIndexOf('/'))
  33760. break
  33761. }
  33762. }
  33763. if (!baseURL && document.currentScript) {
  33764. var src = document.currentScript.src
  33765. if (src.indexOf('.min') !== -1) {
  33766. suffix = '.min'
  33767. }
  33768. baseURL = src.substring(0, src.lastIndexOf('/'))
  33769. }
  33770. }
  33771. self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL)
  33772. self.documentBaseURL = documentBaseURL
  33773. self.baseURI = new URI(self.baseURL)
  33774. self.suffix = suffix
  33775. setup$l(self)
  33776. },
  33777. overrideDefaults: function (defaultSettings) {
  33778. var baseUrl = defaultSettings.base_url
  33779. if (baseUrl) {
  33780. this._setBaseUrl(baseUrl)
  33781. }
  33782. var suffix = defaultSettings.suffix
  33783. if (defaultSettings.suffix) {
  33784. this.suffix = suffix
  33785. }
  33786. this.defaultSettings = defaultSettings
  33787. var pluginBaseUrls = defaultSettings.plugin_base_urls
  33788. if (pluginBaseUrls !== undefined) {
  33789. each$j(pluginBaseUrls, function (pluginBaseUrl, pluginName) {
  33790. AddOnManager.PluginManager.urls[pluginName] = pluginBaseUrl
  33791. })
  33792. }
  33793. },
  33794. init: function (settings) {
  33795. var self = this
  33796. var result
  33797. var invalidInlineTargets = Tools.makeMap(
  33798. 'area base basefont br col frame hr img input isindex link meta param embed source wbr track ' +
  33799. 'colgroup option table tbody tfoot thead tr th td script noscript style textarea video audio iframe object menu',
  33800. ' '
  33801. )
  33802. var isInvalidInlineTarget = function (settings, elm) {
  33803. return (
  33804. settings.inline && elm.tagName.toLowerCase() in invalidInlineTargets
  33805. )
  33806. }
  33807. var createId = function (elm) {
  33808. var id = elm.id
  33809. if (!id) {
  33810. id = get$9(elm, 'name')
  33811. .filter(function (name) {
  33812. return !DOM.get(name)
  33813. })
  33814. .getOrThunk(DOM.uniqueId)
  33815. elm.setAttribute('id', id)
  33816. }
  33817. return id
  33818. }
  33819. var execCallback = function (name) {
  33820. var callback = settings[name]
  33821. if (!callback) {
  33822. return
  33823. }
  33824. return callback.apply(self, [])
  33825. }
  33826. var hasClass = function (elm, className) {
  33827. return className.constructor === RegExp
  33828. ? className.test(elm.className)
  33829. : DOM.hasClass(elm, className)
  33830. }
  33831. var findTargets = function (settings) {
  33832. var targets = []
  33833. if (Env.browser.isIE() && Env.browser.version.major < 11) {
  33834. initError(
  33835. 'TinyMCE does not support the browser you are using. For a list of supported' +
  33836. ' browsers please see: https://www.tinymce.com/docs/get-started/system-requirements/'
  33837. )
  33838. return []
  33839. } else if (isQuirksMode) {
  33840. initError(
  33841. 'Failed to initialize the editor as the document is not in standards mode. ' +
  33842. 'TinyMCE requires standards mode.'
  33843. )
  33844. return []
  33845. }
  33846. if (settings.types) {
  33847. each$1(settings.types, function (type) {
  33848. targets = targets.concat(DOM.select(type.selector))
  33849. })
  33850. return targets
  33851. } else if (settings.selector) {
  33852. return DOM.select(settings.selector)
  33853. } else if (settings.target) {
  33854. return [settings.target]
  33855. }
  33856. switch (settings.mode) {
  33857. case 'exact':
  33858. var l = settings.elements || ''
  33859. if (l.length > 0) {
  33860. each$1(explode(l), function (id) {
  33861. var elm = DOM.get(id)
  33862. if (elm) {
  33863. targets.push(elm)
  33864. } else {
  33865. each$1(document.forms, function (f) {
  33866. each$1(f.elements, function (e) {
  33867. if (e.name === id) {
  33868. id = 'mce_editor_' + instanceCounter++
  33869. DOM.setAttrib(e, 'id', id)
  33870. targets.push(e)
  33871. }
  33872. })
  33873. })
  33874. }
  33875. })
  33876. }
  33877. break
  33878. case 'textareas':
  33879. case 'specific_textareas':
  33880. each$1(DOM.select('textarea'), function (elm) {
  33881. if (
  33882. settings.editor_deselector &&
  33883. hasClass(elm, settings.editor_deselector)
  33884. ) {
  33885. return
  33886. }
  33887. if (
  33888. !settings.editor_selector ||
  33889. hasClass(elm, settings.editor_selector)
  33890. ) {
  33891. targets.push(elm)
  33892. }
  33893. })
  33894. break
  33895. }
  33896. return targets
  33897. }
  33898. var provideResults = function (editors) {
  33899. result = editors
  33900. }
  33901. var initEditors = function () {
  33902. var initCount = 0
  33903. var editors = []
  33904. var targets
  33905. var createEditor = function (id, settings, targetElm) {
  33906. var editor = new Editor(id, settings, self)
  33907. editors.push(editor)
  33908. editor.on('init', function () {
  33909. if (++initCount === targets.length) {
  33910. provideResults(editors)
  33911. }
  33912. })
  33913. editor.targetElm = editor.targetElm || targetElm
  33914. editor.render()
  33915. }
  33916. DOM.unbind(window, 'ready', initEditors)
  33917. execCallback('onpageload')
  33918. targets = DomQuery.unique(findTargets(settings))
  33919. if (settings.types) {
  33920. each$1(settings.types, function (type) {
  33921. Tools.each(targets, function (elm) {
  33922. if (DOM.is(elm, type.selector)) {
  33923. createEditor(createId(elm), extend$2({}, settings, type), elm)
  33924. return false
  33925. }
  33926. return true
  33927. })
  33928. })
  33929. return
  33930. }
  33931. Tools.each(targets, function (elm) {
  33932. purgeDestroyedEditor(self.get(elm.id))
  33933. })
  33934. targets = Tools.grep(targets, function (elm) {
  33935. return !self.get(elm.id)
  33936. })
  33937. if (targets.length === 0) {
  33938. provideResults([])
  33939. } else {
  33940. each$1(targets, function (elm) {
  33941. if (isInvalidInlineTarget(settings, elm)) {
  33942. initError(
  33943. 'Could not initialize inline editor on invalid inline target element',
  33944. elm
  33945. )
  33946. } else {
  33947. createEditor(createId(elm), settings, elm)
  33948. }
  33949. })
  33950. }
  33951. }
  33952. self.settings = settings
  33953. DOM.bind(window, 'ready', initEditors)
  33954. return new promiseObj(function (resolve) {
  33955. if (result) {
  33956. resolve(result)
  33957. } else {
  33958. provideResults = function (editors) {
  33959. resolve(editors)
  33960. }
  33961. }
  33962. })
  33963. },
  33964. get: function (id) {
  33965. if (arguments.length === 0) {
  33966. return editors.slice(0)
  33967. } else if (isString$1(id)) {
  33968. return find$3(editors, function (editor) {
  33969. return editor.id === id
  33970. }).getOr(null)
  33971. } else if (isNumber(id)) {
  33972. return editors[id] ? editors[id] : null
  33973. } else {
  33974. return null
  33975. }
  33976. },
  33977. add: function (editor) {
  33978. var self = this
  33979. var existingEditor = legacyEditors[editor.id]
  33980. if (existingEditor === editor) {
  33981. return editor
  33982. }
  33983. if (self.get(editor.id) === null) {
  33984. if (isValidLegacyKey(editor.id)) {
  33985. legacyEditors[editor.id] = editor
  33986. }
  33987. legacyEditors.push(editor)
  33988. editors.push(editor)
  33989. }
  33990. toggleGlobalEvents(true)
  33991. self.activeEditor = editor
  33992. self.fire('AddEditor', { editor: editor })
  33993. if (!beforeUnloadDelegate) {
  33994. beforeUnloadDelegate = function (e) {
  33995. var event = self.fire('BeforeUnload')
  33996. if (event.returnValue) {
  33997. e.preventDefault()
  33998. e.returnValue = event.returnValue
  33999. return event.returnValue
  34000. }
  34001. }
  34002. window.addEventListener('beforeunload', beforeUnloadDelegate)
  34003. }
  34004. return editor
  34005. },
  34006. createEditor: function (id, settings) {
  34007. return this.add(new Editor(id, settings, this))
  34008. },
  34009. remove: function (selector) {
  34010. var self = this
  34011. var i, editor
  34012. if (!selector) {
  34013. for (i = editors.length - 1; i >= 0; i--) {
  34014. self.remove(editors[i])
  34015. }
  34016. return
  34017. }
  34018. if (isString$1(selector)) {
  34019. each$1(DOM.select(selector), function (elm) {
  34020. editor = self.get(elm.id)
  34021. if (editor) {
  34022. self.remove(editor)
  34023. }
  34024. })
  34025. return
  34026. }
  34027. editor = selector
  34028. if (isNull(self.get(editor.id))) {
  34029. return null
  34030. }
  34031. if (removeEditorFromList(editor)) {
  34032. self.fire('RemoveEditor', { editor: editor })
  34033. }
  34034. if (editors.length === 0) {
  34035. window.removeEventListener('beforeunload', beforeUnloadDelegate)
  34036. }
  34037. editor.remove()
  34038. toggleGlobalEvents(editors.length > 0)
  34039. return editor
  34040. },
  34041. execCommand: function (cmd, ui, value) {
  34042. var self = this,
  34043. editor = self.get(value)
  34044. switch (cmd) {
  34045. case 'mceAddEditor':
  34046. if (!self.get(value)) {
  34047. new Editor(value, self.settings, self).render()
  34048. }
  34049. return true
  34050. case 'mceRemoveEditor':
  34051. if (editor) {
  34052. editor.remove()
  34053. }
  34054. return true
  34055. case 'mceToggleEditor':
  34056. if (!editor) {
  34057. self.execCommand('mceAddEditor', false, value)
  34058. return true
  34059. }
  34060. if (editor.isHidden()) {
  34061. editor.show()
  34062. } else {
  34063. editor.hide()
  34064. }
  34065. return true
  34066. }
  34067. if (self.activeEditor) {
  34068. return self.activeEditor.execCommand(cmd, ui, value)
  34069. }
  34070. return false
  34071. },
  34072. triggerSave: function () {
  34073. each$1(editors, function (editor) {
  34074. editor.save()
  34075. })
  34076. },
  34077. addI18n: function (code, items) {
  34078. I18n.add(code, items)
  34079. },
  34080. translate: function (text) {
  34081. return I18n.translate(text)
  34082. },
  34083. setActive: function (editor) {
  34084. var activeEditor = this.activeEditor
  34085. if (this.activeEditor !== editor) {
  34086. if (activeEditor) {
  34087. activeEditor.fire('deactivate', { relatedTarget: editor })
  34088. }
  34089. editor.fire('activate', { relatedTarget: activeEditor })
  34090. }
  34091. this.activeEditor = editor
  34092. },
  34093. _setBaseUrl: function (baseUrl) {
  34094. this.baseURL = new URI(this.documentBaseURL).toAbsolute(
  34095. baseUrl.replace(/\/+$/, '')
  34096. )
  34097. this.baseURI = new URI(this.baseURL)
  34098. },
  34099. })
  34100. EditorManager.setup()
  34101. var min$1 = Math.min,
  34102. max$1 = Math.max,
  34103. round$1 = Math.round
  34104. var relativePosition = function (rect, targetRect, rel) {
  34105. var x = targetRect.x
  34106. var y = targetRect.y
  34107. var w = rect.w
  34108. var h = rect.h
  34109. var targetW = targetRect.w
  34110. var targetH = targetRect.h
  34111. var relChars = (rel || '').split('')
  34112. if (relChars[0] === 'b') {
  34113. y += targetH
  34114. }
  34115. if (relChars[1] === 'r') {
  34116. x += targetW
  34117. }
  34118. if (relChars[0] === 'c') {
  34119. y += round$1(targetH / 2)
  34120. }
  34121. if (relChars[1] === 'c') {
  34122. x += round$1(targetW / 2)
  34123. }
  34124. if (relChars[3] === 'b') {
  34125. y -= h
  34126. }
  34127. if (relChars[4] === 'r') {
  34128. x -= w
  34129. }
  34130. if (relChars[3] === 'c') {
  34131. y -= round$1(h / 2)
  34132. }
  34133. if (relChars[4] === 'c') {
  34134. x -= round$1(w / 2)
  34135. }
  34136. return create$2(x, y, w, h)
  34137. }
  34138. var findBestRelativePosition = function (
  34139. rect,
  34140. targetRect,
  34141. constrainRect,
  34142. rels
  34143. ) {
  34144. var pos, i
  34145. for (i = 0; i < rels.length; i++) {
  34146. pos = relativePosition(rect, targetRect, rels[i])
  34147. if (
  34148. pos.x >= constrainRect.x &&
  34149. pos.x + pos.w <= constrainRect.w + constrainRect.x &&
  34150. pos.y >= constrainRect.y &&
  34151. pos.y + pos.h <= constrainRect.h + constrainRect.y
  34152. ) {
  34153. return rels[i]
  34154. }
  34155. }
  34156. return null
  34157. }
  34158. var inflate = function (rect, w, h) {
  34159. return create$2(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2)
  34160. }
  34161. var intersect = function (rect, cropRect) {
  34162. var x1 = max$1(rect.x, cropRect.x)
  34163. var y1 = max$1(rect.y, cropRect.y)
  34164. var x2 = min$1(rect.x + rect.w, cropRect.x + cropRect.w)
  34165. var y2 = min$1(rect.y + rect.h, cropRect.y + cropRect.h)
  34166. if (x2 - x1 < 0 || y2 - y1 < 0) {
  34167. return null
  34168. }
  34169. return create$2(x1, y1, x2 - x1, y2 - y1)
  34170. }
  34171. var clamp = function (rect, clampRect, fixedSize) {
  34172. var x1 = rect.x
  34173. var y1 = rect.y
  34174. var x2 = rect.x + rect.w
  34175. var y2 = rect.y + rect.h
  34176. var cx2 = clampRect.x + clampRect.w
  34177. var cy2 = clampRect.y + clampRect.h
  34178. var underflowX1 = max$1(0, clampRect.x - x1)
  34179. var underflowY1 = max$1(0, clampRect.y - y1)
  34180. var overflowX2 = max$1(0, x2 - cx2)
  34181. var overflowY2 = max$1(0, y2 - cy2)
  34182. x1 += underflowX1
  34183. y1 += underflowY1
  34184. if (fixedSize) {
  34185. x2 += underflowX1
  34186. y2 += underflowY1
  34187. x1 -= overflowX2
  34188. y1 -= overflowY2
  34189. }
  34190. x2 -= overflowX2
  34191. y2 -= overflowY2
  34192. return create$2(x1, y1, x2 - x1, y2 - y1)
  34193. }
  34194. var create$2 = function (x, y, w, h) {
  34195. return {
  34196. x: x,
  34197. y: y,
  34198. w: w,
  34199. h: h,
  34200. }
  34201. }
  34202. var fromClientRect = function (clientRect) {
  34203. return create$2(
  34204. clientRect.left,
  34205. clientRect.top,
  34206. clientRect.width,
  34207. clientRect.height
  34208. )
  34209. }
  34210. var Rect = {
  34211. inflate: inflate,
  34212. relativePosition: relativePosition,
  34213. findBestRelativePosition: findBestRelativePosition,
  34214. intersect: intersect,
  34215. clamp: clamp,
  34216. create: create$2,
  34217. fromClientRect: fromClientRect,
  34218. }
  34219. var awaiter = function (resolveCb, rejectCb, timeout) {
  34220. if (timeout === void 0) {
  34221. timeout = 1000
  34222. }
  34223. var done = false
  34224. var timer = null
  34225. var complete = function (completer) {
  34226. return function () {
  34227. var args = []
  34228. for (var _i = 0; _i < arguments.length; _i++) {
  34229. args[_i] = arguments[_i]
  34230. }
  34231. if (!done) {
  34232. done = true
  34233. if (timer !== null) {
  34234. clearTimeout(timer)
  34235. timer = null
  34236. }
  34237. completer.apply(null, args)
  34238. }
  34239. }
  34240. }
  34241. var resolve = complete(resolveCb)
  34242. var reject = complete(rejectCb)
  34243. var start = function () {
  34244. var args = []
  34245. for (var _i = 0; _i < arguments.length; _i++) {
  34246. args[_i] = arguments[_i]
  34247. }
  34248. if (!done && timer === null) {
  34249. timer = setTimeout(function () {
  34250. return reject.apply(null, args)
  34251. }, timeout)
  34252. }
  34253. }
  34254. return {
  34255. start: start,
  34256. resolve: resolve,
  34257. reject: reject,
  34258. }
  34259. }
  34260. var create$1 = function () {
  34261. var tasks = {}
  34262. var resultFns = {}
  34263. var load = function (id, url) {
  34264. var loadErrMsg = 'Script at URL "' + url + '" failed to load'
  34265. var runErrMsg =
  34266. 'Script at URL "' +
  34267. url +
  34268. '" did not call `tinymce.Resource.add(\'' +
  34269. id +
  34270. "', data)` within 1 second"
  34271. if (tasks[id] !== undefined) {
  34272. return tasks[id]
  34273. } else {
  34274. var task = new promiseObj(function (resolve, reject) {
  34275. var waiter = awaiter(resolve, reject)
  34276. resultFns[id] = waiter.resolve
  34277. ScriptLoader.ScriptLoader.loadScript(
  34278. url,
  34279. function () {
  34280. return waiter.start(runErrMsg)
  34281. },
  34282. function () {
  34283. return waiter.reject(loadErrMsg)
  34284. }
  34285. )
  34286. })
  34287. tasks[id] = task
  34288. return task
  34289. }
  34290. }
  34291. var add = function (id, data) {
  34292. if (resultFns[id] !== undefined) {
  34293. resultFns[id](data)
  34294. delete resultFns[id]
  34295. }
  34296. tasks[id] = promiseObj.resolve(data)
  34297. }
  34298. return {
  34299. load: load,
  34300. add: add,
  34301. }
  34302. }
  34303. var Resource = create$1()
  34304. var each = Tools.each,
  34305. extend$1 = Tools.extend
  34306. var extendClass, initializing
  34307. var Class = function () {}
  34308. Class.extend = extendClass = function (props) {
  34309. var self = this
  34310. var _super = self.prototype
  34311. var Class = function () {
  34312. var i, mixins, mixin
  34313. var self = this
  34314. if (!initializing) {
  34315. if (self.init) {
  34316. self.init.apply(self, arguments)
  34317. }
  34318. mixins = self.Mixins
  34319. if (mixins) {
  34320. i = mixins.length
  34321. while (i--) {
  34322. mixin = mixins[i]
  34323. if (mixin.init) {
  34324. mixin.init.apply(self, arguments)
  34325. }
  34326. }
  34327. }
  34328. }
  34329. }
  34330. var dummy = function () {
  34331. return this
  34332. }
  34333. var createMethod = function (name, fn) {
  34334. return function () {
  34335. var self = this
  34336. var tmp = self._super
  34337. self._super = _super[name]
  34338. var ret = fn.apply(self, arguments)
  34339. self._super = tmp
  34340. return ret
  34341. }
  34342. }
  34343. initializing = true
  34344. var prototype = new self()
  34345. initializing = false
  34346. if (props.Mixins) {
  34347. each(props.Mixins, function (mixin) {
  34348. for (var name_1 in mixin) {
  34349. if (name_1 !== 'init') {
  34350. props[name_1] = mixin[name_1]
  34351. }
  34352. }
  34353. })
  34354. if (_super.Mixins) {
  34355. props.Mixins = _super.Mixins.concat(props.Mixins)
  34356. }
  34357. }
  34358. if (props.Methods) {
  34359. each(props.Methods.split(','), function (name) {
  34360. props[name] = dummy
  34361. })
  34362. }
  34363. if (props.Properties) {
  34364. each(props.Properties.split(','), function (name) {
  34365. var fieldName = '_' + name
  34366. props[name] = function (value) {
  34367. var self = this
  34368. if (value !== undefined) {
  34369. self[fieldName] = value
  34370. return self
  34371. }
  34372. return self[fieldName]
  34373. }
  34374. })
  34375. }
  34376. if (props.Statics) {
  34377. each(props.Statics, function (func, name) {
  34378. Class[name] = func
  34379. })
  34380. }
  34381. if (props.Defaults && _super.Defaults) {
  34382. props.Defaults = extend$1({}, _super.Defaults, props.Defaults)
  34383. }
  34384. each$j(props, function (member, name) {
  34385. if (typeof member === 'function' && _super[name]) {
  34386. prototype[name] = createMethod(name, member)
  34387. } else {
  34388. prototype[name] = member
  34389. }
  34390. })
  34391. Class.prototype = prototype
  34392. Class.constructor = Class
  34393. Class.extend = extendClass
  34394. return Class
  34395. }
  34396. var min = Math.min,
  34397. max = Math.max,
  34398. round = Math.round
  34399. var Color = function (value) {
  34400. var self = {}
  34401. var r = 0,
  34402. g = 0,
  34403. b = 0
  34404. var rgb2hsv = function (r, g, b) {
  34405. var h, s, v
  34406. h = 0
  34407. s = 0
  34408. v = 0
  34409. r = r / 255
  34410. g = g / 255
  34411. b = b / 255
  34412. var minRGB = min(r, min(g, b))
  34413. var maxRGB = max(r, max(g, b))
  34414. if (minRGB === maxRGB) {
  34415. v = minRGB
  34416. return {
  34417. h: 0,
  34418. s: 0,
  34419. v: v * 100,
  34420. }
  34421. }
  34422. var d = r === minRGB ? g - b : b === minRGB ? r - g : b - r
  34423. h = r === minRGB ? 3 : b === minRGB ? 1 : 5
  34424. h = 60 * (h - d / (maxRGB - minRGB))
  34425. s = (maxRGB - minRGB) / maxRGB
  34426. v = maxRGB
  34427. return {
  34428. h: round(h),
  34429. s: round(s * 100),
  34430. v: round(v * 100),
  34431. }
  34432. }
  34433. var hsvToRgb = function (hue, saturation, brightness) {
  34434. hue = (parseInt(hue, 10) || 0) % 360
  34435. saturation = parseInt(saturation, 10) / 100
  34436. brightness = parseInt(brightness, 10) / 100
  34437. saturation = max(0, min(saturation, 1))
  34438. brightness = max(0, min(brightness, 1))
  34439. if (saturation === 0) {
  34440. r = g = b = round(255 * brightness)
  34441. return
  34442. }
  34443. var side = hue / 60
  34444. var chroma = brightness * saturation
  34445. var x = chroma * (1 - Math.abs((side % 2) - 1))
  34446. var match = brightness - chroma
  34447. switch (Math.floor(side)) {
  34448. case 0:
  34449. r = chroma
  34450. g = x
  34451. b = 0
  34452. break
  34453. case 1:
  34454. r = x
  34455. g = chroma
  34456. b = 0
  34457. break
  34458. case 2:
  34459. r = 0
  34460. g = chroma
  34461. b = x
  34462. break
  34463. case 3:
  34464. r = 0
  34465. g = x
  34466. b = chroma
  34467. break
  34468. case 4:
  34469. r = x
  34470. g = 0
  34471. b = chroma
  34472. break
  34473. case 5:
  34474. r = chroma
  34475. g = 0
  34476. b = x
  34477. break
  34478. default:
  34479. r = g = b = 0
  34480. }
  34481. r = round(255 * (r + match))
  34482. g = round(255 * (g + match))
  34483. b = round(255 * (b + match))
  34484. }
  34485. var toHex = function () {
  34486. var hex = function (val) {
  34487. val = parseInt(val, 10).toString(16)
  34488. return val.length > 1 ? val : '0' + val
  34489. }
  34490. return '#' + hex(r) + hex(g) + hex(b)
  34491. }
  34492. var toRgb = function () {
  34493. return {
  34494. r: r,
  34495. g: g,
  34496. b: b,
  34497. }
  34498. }
  34499. var toHsv = function () {
  34500. return rgb2hsv(r, g, b)
  34501. }
  34502. var parse = function (value) {
  34503. var matches
  34504. if (typeof value === 'object') {
  34505. if ('r' in value) {
  34506. r = value.r
  34507. g = value.g
  34508. b = value.b
  34509. } else if ('v' in value) {
  34510. hsvToRgb(value.h, value.s, value.v)
  34511. }
  34512. } else {
  34513. if (
  34514. (matches =
  34515. /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(
  34516. value
  34517. ))
  34518. ) {
  34519. r = parseInt(matches[1], 10)
  34520. g = parseInt(matches[2], 10)
  34521. b = parseInt(matches[3], 10)
  34522. } else if (
  34523. (matches = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value))
  34524. ) {
  34525. r = parseInt(matches[1], 16)
  34526. g = parseInt(matches[2], 16)
  34527. b = parseInt(matches[3], 16)
  34528. } else if ((matches = /#([0-F])([0-F])([0-F])/gi.exec(value))) {
  34529. r = parseInt(matches[1] + matches[1], 16)
  34530. g = parseInt(matches[2] + matches[2], 16)
  34531. b = parseInt(matches[3] + matches[3], 16)
  34532. }
  34533. }
  34534. r = r < 0 ? 0 : r > 255 ? 255 : r
  34535. g = g < 0 ? 0 : g > 255 ? 255 : g
  34536. b = b < 0 ? 0 : b > 255 ? 255 : b
  34537. return self
  34538. }
  34539. if (value) {
  34540. parse(value)
  34541. }
  34542. self.toRgb = toRgb
  34543. self.toHsv = toHsv
  34544. self.toHex = toHex
  34545. self.parse = parse
  34546. return self
  34547. }
  34548. var serialize = function (obj) {
  34549. var data = JSON.stringify(obj)
  34550. if (!isString$1(data)) {
  34551. return data
  34552. }
  34553. return data.replace(/[\u0080-\uFFFF]/g, function (match) {
  34554. var hexCode = match.charCodeAt(0).toString(16)
  34555. return '\\u' + '0000'.substring(hexCode.length) + hexCode
  34556. })
  34557. }
  34558. var JSONUtils = {
  34559. serialize: serialize,
  34560. parse: function (text) {
  34561. try {
  34562. return JSON.parse(text)
  34563. } catch (ex) {}
  34564. },
  34565. }
  34566. var JSONP = {
  34567. callbacks: {},
  34568. count: 0,
  34569. send: function (settings) {
  34570. var self = this,
  34571. dom = DOMUtils.DOM,
  34572. count = settings.count !== undefined ? settings.count : self.count
  34573. var id = 'tinymce_jsonp_' + count
  34574. self.callbacks[count] = function (json) {
  34575. dom.remove(id)
  34576. delete self.callbacks[count]
  34577. settings.callback(json)
  34578. }
  34579. dom.add(dom.doc.body, 'script', {
  34580. id: id,
  34581. src: settings.url,
  34582. type: 'text/javascript',
  34583. })
  34584. self.count++
  34585. },
  34586. }
  34587. var XHR = __assign(__assign({}, Observable), {
  34588. send: function (settings) {
  34589. var xhr,
  34590. count = 0
  34591. var ready = function () {
  34592. if (!settings.async || xhr.readyState === 4 || count++ > 10000) {
  34593. if (settings.success && count < 10000 && xhr.status === 200) {
  34594. settings.success.call(
  34595. settings.success_scope,
  34596. '' + xhr.responseText,
  34597. xhr,
  34598. settings
  34599. )
  34600. } else if (settings.error) {
  34601. settings.error.call(
  34602. settings.error_scope,
  34603. count > 10000 ? 'TIMED_OUT' : 'GENERAL',
  34604. xhr,
  34605. settings
  34606. )
  34607. }
  34608. xhr = null
  34609. } else {
  34610. Delay.setTimeout(ready, 10)
  34611. }
  34612. }
  34613. settings.scope = settings.scope || this
  34614. settings.success_scope = settings.success_scope || settings.scope
  34615. settings.error_scope = settings.error_scope || settings.scope
  34616. settings.async = settings.async !== false
  34617. settings.data = settings.data || ''
  34618. XHR.fire('beforeInitialize', { settings: settings })
  34619. xhr = new XMLHttpRequest()
  34620. if (xhr.overrideMimeType) {
  34621. xhr.overrideMimeType(settings.content_type)
  34622. }
  34623. xhr.open(
  34624. settings.type || (settings.data ? 'POST' : 'GET'),
  34625. settings.url,
  34626. settings.async
  34627. )
  34628. if (settings.crossDomain) {
  34629. xhr.withCredentials = true
  34630. }
  34631. if (settings.content_type) {
  34632. xhr.setRequestHeader('Content-Type', settings.content_type)
  34633. }
  34634. if (settings.requestheaders) {
  34635. Tools.each(settings.requestheaders, function (header) {
  34636. xhr.setRequestHeader(header.key, header.value)
  34637. })
  34638. }
  34639. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
  34640. xhr = XHR.fire('beforeSend', {
  34641. xhr: xhr,
  34642. settings: settings,
  34643. }).xhr
  34644. xhr.send(settings.data)
  34645. if (!settings.async) {
  34646. return ready()
  34647. }
  34648. Delay.setTimeout(ready, 10)
  34649. },
  34650. })
  34651. var extend = Tools.extend
  34652. var JSONRequest = (function () {
  34653. function JSONRequest(settings) {
  34654. this.settings = extend({}, settings)
  34655. this.count = 0
  34656. }
  34657. JSONRequest.sendRPC = function (o) {
  34658. return new JSONRequest().send(o)
  34659. }
  34660. JSONRequest.prototype.send = function (args) {
  34661. var ecb = args.error,
  34662. scb = args.success
  34663. var xhrArgs = extend(this.settings, args)
  34664. xhrArgs.success = function (c, x) {
  34665. c = JSONUtils.parse(c)
  34666. if (typeof c === 'undefined') {
  34667. c = { error: 'JSON Parse error.' }
  34668. }
  34669. if (c.error) {
  34670. ecb.call(xhrArgs.error_scope || xhrArgs.scope, c.error, x)
  34671. } else {
  34672. scb.call(xhrArgs.success_scope || xhrArgs.scope, c.result)
  34673. }
  34674. }
  34675. xhrArgs.error = function (ty, x) {
  34676. if (ecb) {
  34677. ecb.call(xhrArgs.error_scope || xhrArgs.scope, ty, x)
  34678. }
  34679. }
  34680. xhrArgs.data = JSONUtils.serialize({
  34681. id: args.id || 'c' + this.count++,
  34682. method: args.method,
  34683. params: args.params,
  34684. })
  34685. xhrArgs.content_type = 'application/json'
  34686. XHR.send(xhrArgs)
  34687. }
  34688. return JSONRequest
  34689. })()
  34690. var create = function () {
  34691. return (function () {
  34692. var data = {}
  34693. var keys = []
  34694. var storage = {
  34695. getItem: function (key) {
  34696. var item = data[key]
  34697. return item ? item : null
  34698. },
  34699. setItem: function (key, value) {
  34700. keys.push(key)
  34701. data[key] = String(value)
  34702. },
  34703. key: function (index) {
  34704. return keys[index]
  34705. },
  34706. removeItem: function (key) {
  34707. keys = keys.filter(function (k) {
  34708. return k === key
  34709. })
  34710. delete data[key]
  34711. },
  34712. clear: function () {
  34713. keys = []
  34714. data = {}
  34715. },
  34716. length: 0,
  34717. }
  34718. Object.defineProperty(storage, 'length', {
  34719. get: function () {
  34720. return keys.length
  34721. },
  34722. configurable: false,
  34723. enumerable: false,
  34724. })
  34725. return storage
  34726. })()
  34727. }
  34728. var localStorage
  34729. try {
  34730. var test = '__storage_test__'
  34731. localStorage = window.localStorage
  34732. localStorage.setItem(test, test)
  34733. localStorage.removeItem(test)
  34734. } catch (e) {
  34735. localStorage = create()
  34736. }
  34737. var LocalStorage = localStorage
  34738. var publicApi = {
  34739. geom: { Rect: Rect },
  34740. util: {
  34741. Promise: promiseObj,
  34742. Delay: Delay,
  34743. Tools: Tools,
  34744. VK: VK,
  34745. URI: URI,
  34746. Class: Class,
  34747. EventDispatcher: EventDispatcher,
  34748. Observable: Observable,
  34749. I18n: I18n,
  34750. XHR: XHR,
  34751. JSON: JSONUtils,
  34752. JSONRequest: JSONRequest,
  34753. JSONP: JSONP,
  34754. LocalStorage: LocalStorage,
  34755. Color: Color,
  34756. ImageUploader: ImageUploader,
  34757. },
  34758. dom: {
  34759. EventUtils: EventUtils,
  34760. Sizzle: Sizzle,
  34761. DomQuery: DomQuery,
  34762. TreeWalker: DomTreeWalker,
  34763. TextSeeker: TextSeeker,
  34764. DOMUtils: DOMUtils,
  34765. ScriptLoader: ScriptLoader,
  34766. RangeUtils: RangeUtils,
  34767. Serializer: DomSerializer,
  34768. StyleSheetLoader: StyleSheetLoader,
  34769. ControlSelection: ControlSelection,
  34770. BookmarkManager: BookmarkManager,
  34771. Selection: EditorSelection,
  34772. Event: EventUtils.Event,
  34773. },
  34774. html: {
  34775. Styles: Styles,
  34776. Entities: Entities,
  34777. Node: AstNode,
  34778. Schema: Schema,
  34779. SaxParser: SaxParser,
  34780. DomParser: DomParser,
  34781. Writer: Writer,
  34782. Serializer: HtmlSerializer,
  34783. },
  34784. Env: Env,
  34785. AddOnManager: AddOnManager,
  34786. Annotator: Annotator,
  34787. Formatter: Formatter,
  34788. UndoManager: UndoManager,
  34789. EditorCommands: EditorCommands,
  34790. WindowManager: WindowManager,
  34791. NotificationManager: NotificationManager,
  34792. EditorObservable: EditorObservable,
  34793. Shortcuts: Shortcuts,
  34794. Editor: Editor,
  34795. FocusManager: FocusManager,
  34796. EditorManager: EditorManager,
  34797. DOM: DOMUtils.DOM,
  34798. ScriptLoader: ScriptLoader.ScriptLoader,
  34799. PluginManager: PluginManager,
  34800. ThemeManager: ThemeManager,
  34801. IconManager: IconManager,
  34802. Resource: Resource,
  34803. trim: Tools.trim,
  34804. isArray: Tools.isArray,
  34805. is: Tools.is,
  34806. toArray: Tools.toArray,
  34807. makeMap: Tools.makeMap,
  34808. each: Tools.each,
  34809. map: Tools.map,
  34810. grep: Tools.grep,
  34811. inArray: Tools.inArray,
  34812. extend: Tools.extend,
  34813. create: Tools.create,
  34814. walk: Tools.walk,
  34815. createNS: Tools.createNS,
  34816. resolve: Tools.resolve,
  34817. explode: Tools.explode,
  34818. _addCacheSuffix: Tools._addCacheSuffix,
  34819. isOpera: Env.opera,
  34820. isWebKit: Env.webkit,
  34821. isIE: Env.ie,
  34822. isGecko: Env.gecko,
  34823. isMac: Env.mac,
  34824. }
  34825. var tinymce = Tools.extend(EditorManager, publicApi)
  34826. var exportToModuleLoaders = function (tinymce) {
  34827. if (typeof module === 'object') {
  34828. try {
  34829. module.exports = tinymce
  34830. } catch (_) {}
  34831. }
  34832. }
  34833. var exportToWindowGlobal = function (tinymce) {
  34834. window.tinymce = tinymce
  34835. window.tinyMCE = tinymce
  34836. }
  34837. exportToWindowGlobal(tinymce)
  34838. exportToModuleLoaders(tinymce)
  34839. })()