tinymce.js 1.0 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200
  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. console.log(content, 'contentcontentcontentcontentcontent-----')
  20505. return editor.setContent(content, args)
  20506. },
  20507. insertContent: function (content, _details) {
  20508. return editor.insertContent(content)
  20509. },
  20510. addVisual: editor.addVisual,
  20511. },
  20512. selection: {
  20513. getContent: function (_format, args) {
  20514. return selection.getContent(args)
  20515. },
  20516. },
  20517. raw: {
  20518. getModel: function () {
  20519. return Optional.some(raw.getRawModel())
  20520. },
  20521. },
  20522. }
  20523. }
  20524. var makeNoopAdaptor = function () {
  20525. var nul = constant(null)
  20526. var empty = constant('')
  20527. return {
  20528. undoManager: {
  20529. beforeChange: noop,
  20530. add: nul,
  20531. undo: nul,
  20532. redo: nul,
  20533. clear: noop,
  20534. reset: noop,
  20535. hasUndo: never,
  20536. hasRedo: never,
  20537. transact: nul,
  20538. ignore: noop,
  20539. extra: noop,
  20540. },
  20541. formatter: {
  20542. match: never,
  20543. matchAll: constant([]),
  20544. matchNode: constant(undefined),
  20545. canApply: never,
  20546. closest: empty,
  20547. apply: noop,
  20548. remove: noop,
  20549. toggle: noop,
  20550. formatChanged: constant({ unbind: noop }),
  20551. },
  20552. editor: {
  20553. getContent: empty,
  20554. setContent: empty,
  20555. insertContent: noop,
  20556. addVisual: noop,
  20557. },
  20558. selection: { getContent: empty },
  20559. raw: { getModel: constant(Optional.none()) },
  20560. }
  20561. }
  20562. var isRtc = function (editor) {
  20563. return has$2(editor.plugins, 'rtc')
  20564. }
  20565. var getRtcSetup = function (editor) {
  20566. return get$9(editor.plugins, 'rtc').bind(function (rtcPlugin) {
  20567. return Optional.from(rtcPlugin.setup)
  20568. })
  20569. }
  20570. var setup$i = function (editor) {
  20571. var editorCast = editor
  20572. return getRtcSetup(editor).fold(
  20573. function () {
  20574. editorCast.rtcInstance = makePlainAdaptor(editor)
  20575. return Optional.none()
  20576. },
  20577. function (setup) {
  20578. editorCast.rtcInstance = makeNoopAdaptor()
  20579. return Optional.some(function () {
  20580. return setup().then(function (rtcEditor) {
  20581. editorCast.rtcInstance = makeRtcAdaptor(rtcEditor)
  20582. return rtcEditor.rtc.isRemote
  20583. })
  20584. })
  20585. }
  20586. )
  20587. }
  20588. var getRtcInstanceWithFallback = function (editor) {
  20589. return editor.rtcInstance ? editor.rtcInstance : makePlainAdaptor(editor)
  20590. }
  20591. var getRtcInstanceWithError = function (editor) {
  20592. var rtcInstance = editor.rtcInstance
  20593. if (!rtcInstance) {
  20594. throw new Error('Failed to get RTC instance not yet initialized.')
  20595. } else {
  20596. return rtcInstance
  20597. }
  20598. }
  20599. var beforeChange = function (editor, locks, beforeBookmark) {
  20600. getRtcInstanceWithError(editor).undoManager.beforeChange(
  20601. locks,
  20602. beforeBookmark
  20603. )
  20604. }
  20605. var addUndoLevel = function (
  20606. editor,
  20607. undoManager,
  20608. index,
  20609. locks,
  20610. beforeBookmark,
  20611. level,
  20612. event
  20613. ) {
  20614. return getRtcInstanceWithError(editor).undoManager.add(
  20615. undoManager,
  20616. index,
  20617. locks,
  20618. beforeBookmark,
  20619. level,
  20620. event
  20621. )
  20622. }
  20623. var undo = function (editor, undoManager, locks, index) {
  20624. return getRtcInstanceWithError(editor).undoManager.undo(
  20625. undoManager,
  20626. locks,
  20627. index
  20628. )
  20629. }
  20630. var redo = function (editor, index, data) {
  20631. return getRtcInstanceWithError(editor).undoManager.redo(index, data)
  20632. }
  20633. var clear = function (editor, undoManager, index) {
  20634. getRtcInstanceWithError(editor).undoManager.clear(undoManager, index)
  20635. }
  20636. var reset = function (editor, undoManager) {
  20637. getRtcInstanceWithError(editor).undoManager.reset(undoManager)
  20638. }
  20639. var hasUndo = function (editor, undoManager, index) {
  20640. return getRtcInstanceWithError(editor).undoManager.hasUndo(
  20641. undoManager,
  20642. index
  20643. )
  20644. }
  20645. var hasRedo = function (editor, undoManager, index) {
  20646. return getRtcInstanceWithError(editor).undoManager.hasRedo(
  20647. undoManager,
  20648. index
  20649. )
  20650. }
  20651. var transact = function (editor, undoManager, locks, callback) {
  20652. return getRtcInstanceWithError(editor).undoManager.transact(
  20653. undoManager,
  20654. locks,
  20655. callback
  20656. )
  20657. }
  20658. var ignore = function (editor, locks, callback) {
  20659. getRtcInstanceWithError(editor).undoManager.ignore(locks, callback)
  20660. }
  20661. var extra = function (editor, undoManager, index, callback1, callback2) {
  20662. getRtcInstanceWithError(editor).undoManager.extra(
  20663. undoManager,
  20664. index,
  20665. callback1,
  20666. callback2
  20667. )
  20668. }
  20669. var matchFormat = function (editor, name, vars, node, similar) {
  20670. return getRtcInstanceWithError(editor).formatter.match(
  20671. name,
  20672. vars,
  20673. node,
  20674. similar
  20675. )
  20676. }
  20677. var matchAllFormats = function (editor, names, vars) {
  20678. return getRtcInstanceWithError(editor).formatter.matchAll(names, vars)
  20679. }
  20680. var matchNodeFormat = function (editor, node, name, vars, similar) {
  20681. return getRtcInstanceWithError(editor).formatter.matchNode(
  20682. node,
  20683. name,
  20684. vars,
  20685. similar
  20686. )
  20687. }
  20688. var canApplyFormat = function (editor, name) {
  20689. return getRtcInstanceWithError(editor).formatter.canApply(name)
  20690. }
  20691. var closestFormat = function (editor, names) {
  20692. return getRtcInstanceWithError(editor).formatter.closest(names)
  20693. }
  20694. var applyFormat = function (editor, name, vars, node) {
  20695. getRtcInstanceWithError(editor).formatter.apply(name, vars, node)
  20696. }
  20697. var removeFormat = function (editor, name, vars, node, similar) {
  20698. getRtcInstanceWithError(editor).formatter.remove(name, vars, node, similar)
  20699. }
  20700. var toggleFormat = function (editor, name, vars, node) {
  20701. getRtcInstanceWithError(editor).formatter.toggle(name, vars, node)
  20702. }
  20703. var formatChanged = function (
  20704. editor,
  20705. registeredFormatListeners,
  20706. formats,
  20707. callback,
  20708. similar,
  20709. vars
  20710. ) {
  20711. return getRtcInstanceWithError(editor).formatter.formatChanged(
  20712. registeredFormatListeners,
  20713. formats,
  20714. callback,
  20715. similar,
  20716. vars
  20717. )
  20718. }
  20719. var getContent$2 = function (editor, args, format) {
  20720. return getRtcInstanceWithFallback(editor).editor.getContent(args, format)
  20721. }
  20722. var setContent$2 = function (editor, content, args) {
  20723. return getRtcInstanceWithFallback(editor).editor.setContent(content, args)
  20724. }
  20725. var insertContent = function (editor, value, details) {
  20726. return getRtcInstanceWithFallback(editor).editor.insertContent(
  20727. value,
  20728. details
  20729. )
  20730. }
  20731. var getSelectedContent = function (editor, format, args) {
  20732. return getRtcInstanceWithError(editor).selection.getContent(format, args)
  20733. }
  20734. var addVisual$1 = function (editor, elm) {
  20735. return getRtcInstanceWithError(editor).editor.addVisual(elm)
  20736. }
  20737. var getContent$1 = function (editor, args) {
  20738. if (args === void 0) {
  20739. args = {}
  20740. }
  20741. var format = args.format ? args.format : 'html'
  20742. return getSelectedContent(editor, format, args)
  20743. }
  20744. var removeEmpty = function (text) {
  20745. if (text.dom.length === 0) {
  20746. remove$7(text)
  20747. return Optional.none()
  20748. } else {
  20749. return Optional.some(text)
  20750. }
  20751. }
  20752. var walkPastBookmark = function (node, start) {
  20753. return node
  20754. .filter(function (elm) {
  20755. return BookmarkManager.isBookmarkNode(elm.dom)
  20756. })
  20757. .bind(start ? nextSibling : prevSibling)
  20758. }
  20759. var merge = function (outer, inner, rng, start) {
  20760. var outerElm = outer.dom
  20761. var innerElm = inner.dom
  20762. var oldLength = start ? outerElm.length : innerElm.length
  20763. if (start) {
  20764. mergeTextNodes(outerElm, innerElm, false, !start)
  20765. rng.setStart(innerElm, oldLength)
  20766. } else {
  20767. mergeTextNodes(innerElm, outerElm, false, !start)
  20768. rng.setEnd(innerElm, oldLength)
  20769. }
  20770. }
  20771. var normalizeTextIfRequired = function (inner, start) {
  20772. parent(inner).each(function (root) {
  20773. var text = inner.dom
  20774. if (start && needsToBeNbspLeft(root, CaretPosition(text, 0))) {
  20775. normalizeWhitespaceAfter(text, 0)
  20776. } else if (
  20777. !start &&
  20778. needsToBeNbspRight(root, CaretPosition(text, text.length))
  20779. ) {
  20780. normalizeWhitespaceBefore(text, text.length)
  20781. }
  20782. })
  20783. }
  20784. var mergeAndNormalizeText = function (outerNode, innerNode, rng, start) {
  20785. outerNode
  20786. .bind(function (outer) {
  20787. var normalizer = start
  20788. ? normalizeWhitespaceBefore
  20789. : normalizeWhitespaceAfter
  20790. normalizer(outer.dom, start ? outer.dom.length : 0)
  20791. return innerNode.filter(isText$8).map(function (inner) {
  20792. return merge(outer, inner, rng, start)
  20793. })
  20794. })
  20795. .orThunk(function () {
  20796. var innerTextNode = walkPastBookmark(innerNode, start)
  20797. .or(innerNode)
  20798. .filter(isText$8)
  20799. return innerTextNode.map(function (inner) {
  20800. return normalizeTextIfRequired(inner, start)
  20801. })
  20802. })
  20803. }
  20804. var rngSetContent = function (rng, fragment) {
  20805. var firstChild = Optional.from(fragment.firstChild).map(
  20806. SugarElement.fromDom
  20807. )
  20808. var lastChild = Optional.from(fragment.lastChild).map(SugarElement.fromDom)
  20809. rng.deleteContents()
  20810. rng.insertNode(fragment)
  20811. var prevText = firstChild
  20812. .bind(prevSibling)
  20813. .filter(isText$8)
  20814. .bind(removeEmpty)
  20815. var nextText = lastChild
  20816. .bind(nextSibling)
  20817. .filter(isText$8)
  20818. .bind(removeEmpty)
  20819. mergeAndNormalizeText(prevText, firstChild, rng, true)
  20820. mergeAndNormalizeText(nextText, lastChild, rng, false)
  20821. rng.collapse(false)
  20822. }
  20823. var setupArgs = function (args, content) {
  20824. return __assign(__assign({ format: 'html' }, args), {
  20825. set: true,
  20826. selection: true,
  20827. content: content,
  20828. })
  20829. }
  20830. var cleanContent = function (editor, args) {
  20831. if (args.format !== 'raw') {
  20832. var rng = editor.selection.getRng()
  20833. var contextBlock = editor.dom.getParent(
  20834. rng.commonAncestorContainer,
  20835. editor.dom.isBlock
  20836. )
  20837. var contextArgs = contextBlock
  20838. ? { context: contextBlock.nodeName.toLowerCase() }
  20839. : {}
  20840. var node = editor.parser.parse(
  20841. args.content,
  20842. __assign(
  20843. __assign(
  20844. {
  20845. isRootContent: true,
  20846. forced_root_block: false,
  20847. },
  20848. contextArgs
  20849. ),
  20850. args
  20851. )
  20852. )
  20853. return HtmlSerializer(
  20854. { validate: editor.validate },
  20855. editor.schema
  20856. ).serialize(node)
  20857. } else {
  20858. return args.content
  20859. }
  20860. }
  20861. var setContent$1 = function (editor, content, args) {
  20862. if (args === void 0) {
  20863. args = {}
  20864. }
  20865. var defaultedArgs = setupArgs(args, content)
  20866. var updatedArgs = defaultedArgs
  20867. if (!defaultedArgs.no_events) {
  20868. var eventArgs = editor.fire('BeforeSetContent', defaultedArgs)
  20869. if (eventArgs.isDefaultPrevented()) {
  20870. editor.fire('SetContent', eventArgs)
  20871. return
  20872. } else {
  20873. updatedArgs = eventArgs
  20874. }
  20875. }
  20876. updatedArgs.content = cleanContent(editor, updatedArgs)
  20877. var rng = editor.selection.getRng()
  20878. rngSetContent(rng, rng.createContextualFragment(updatedArgs.content))
  20879. editor.selection.setRng(rng)
  20880. scrollRangeIntoView(editor, rng)
  20881. if (!updatedArgs.no_events) {
  20882. editor.fire('SetContent', updatedArgs)
  20883. }
  20884. }
  20885. var deleteFromCallbackMap = function (callbackMap, selector, callback) {
  20886. if (callbackMap && has$2(callbackMap, selector)) {
  20887. var newCallbacks = filter$4(callbackMap[selector], function (cb) {
  20888. return cb !== callback
  20889. })
  20890. if (newCallbacks.length === 0) {
  20891. delete callbackMap[selector]
  20892. } else {
  20893. callbackMap[selector] = newCallbacks
  20894. }
  20895. }
  20896. }
  20897. function SelectorChanged(dom, editor) {
  20898. var selectorChangedData
  20899. var currentSelectors
  20900. var findMatchingNode = function (selector, nodes) {
  20901. return find$3(nodes, function (node) {
  20902. return dom.is(node, selector)
  20903. })
  20904. }
  20905. var getParents = function (elem) {
  20906. return dom.getParents(elem, null, dom.getRoot())
  20907. }
  20908. return {
  20909. selectorChangedWithUnbind: function (selector, callback) {
  20910. if (!selectorChangedData) {
  20911. selectorChangedData = {}
  20912. currentSelectors = {}
  20913. editor.on('NodeChange', function (e) {
  20914. var node = e.element
  20915. var parents = getParents(node)
  20916. var matchedSelectors = {}
  20917. Tools.each(selectorChangedData, function (callbacks, selector) {
  20918. findMatchingNode(selector, parents).each(function (node) {
  20919. if (!currentSelectors[selector]) {
  20920. each$k(callbacks, function (callback) {
  20921. callback(true, {
  20922. node: node,
  20923. selector: selector,
  20924. parents: parents,
  20925. })
  20926. })
  20927. currentSelectors[selector] = callbacks
  20928. }
  20929. matchedSelectors[selector] = callbacks
  20930. })
  20931. })
  20932. Tools.each(currentSelectors, function (callbacks, selector) {
  20933. if (!matchedSelectors[selector]) {
  20934. delete currentSelectors[selector]
  20935. Tools.each(callbacks, function (callback) {
  20936. callback(false, {
  20937. node: node,
  20938. selector: selector,
  20939. parents: parents,
  20940. })
  20941. })
  20942. }
  20943. })
  20944. })
  20945. }
  20946. if (!selectorChangedData[selector]) {
  20947. selectorChangedData[selector] = []
  20948. }
  20949. selectorChangedData[selector].push(callback)
  20950. findMatchingNode(
  20951. selector,
  20952. getParents(editor.selection.getStart())
  20953. ).each(function () {
  20954. currentSelectors[selector] = selectorChangedData[selector]
  20955. })
  20956. return {
  20957. unbind: function () {
  20958. deleteFromCallbackMap(selectorChangedData, selector, callback)
  20959. deleteFromCallbackMap(currentSelectors, selector, callback)
  20960. },
  20961. }
  20962. },
  20963. }
  20964. }
  20965. var isNativeIeSelection = function (rng) {
  20966. return !!rng.select
  20967. }
  20968. var isAttachedToDom = function (node) {
  20969. return (
  20970. !!(node && node.ownerDocument) &&
  20971. contains$1(
  20972. SugarElement.fromDom(node.ownerDocument),
  20973. SugarElement.fromDom(node)
  20974. )
  20975. )
  20976. }
  20977. var isValidRange = function (rng) {
  20978. if (!rng) {
  20979. return false
  20980. } else if (isNativeIeSelection(rng)) {
  20981. return true
  20982. } else {
  20983. return (
  20984. isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer)
  20985. )
  20986. }
  20987. }
  20988. var EditorSelection = function (dom, win, serializer, editor) {
  20989. var selectedRange
  20990. var explicitRange
  20991. var selectorChangedWithUnbind = SelectorChanged(
  20992. dom,
  20993. editor
  20994. ).selectorChangedWithUnbind
  20995. var setCursorLocation = function (node, offset) {
  20996. var rng = dom.createRng()
  20997. if (isNonNullable(node) && isNonNullable(offset)) {
  20998. rng.setStart(node, offset)
  20999. rng.setEnd(node, offset)
  21000. setRng(rng)
  21001. collapse(false)
  21002. } else {
  21003. moveEndPoint(dom, rng, editor.getBody(), true)
  21004. setRng(rng)
  21005. }
  21006. }
  21007. var getContent = function (args) {
  21008. return getContent$1(editor, args)
  21009. }
  21010. var setContent = function (content, args) {
  21011. return setContent$1(editor, content, args)
  21012. }
  21013. var getStart$1 = function (real) {
  21014. return getStart(editor.getBody(), getRng$1(), real)
  21015. }
  21016. var getEnd$1 = function (real) {
  21017. return getEnd(editor.getBody(), getRng$1(), real)
  21018. }
  21019. var getBookmark = function (type, normalized) {
  21020. return bookmarkManager.getBookmark(type, normalized)
  21021. }
  21022. var moveToBookmark = function (bookmark) {
  21023. return bookmarkManager.moveToBookmark(bookmark)
  21024. }
  21025. var select$1 = function (node, content) {
  21026. select(dom, node, content).each(setRng)
  21027. return node
  21028. }
  21029. var isCollapsed = function () {
  21030. var rng = getRng$1(),
  21031. sel = getSel()
  21032. if (!rng || rng.item) {
  21033. return false
  21034. }
  21035. if (rng.compareEndPoints) {
  21036. return rng.compareEndPoints('StartToEnd', rng) === 0
  21037. }
  21038. return !sel || rng.collapsed
  21039. }
  21040. var collapse = function (toStart) {
  21041. var rng = getRng$1()
  21042. rng.collapse(!!toStart)
  21043. setRng(rng)
  21044. }
  21045. var getSel = function () {
  21046. return win.getSelection ? win.getSelection() : win.document.selection
  21047. }
  21048. var getRng$1 = function () {
  21049. var selection, rng, elm
  21050. var tryCompareBoundaryPoints = function (
  21051. how,
  21052. sourceRange,
  21053. destinationRange
  21054. ) {
  21055. try {
  21056. return sourceRange.compareBoundaryPoints(how, destinationRange)
  21057. } catch (ex) {
  21058. return -1
  21059. }
  21060. }
  21061. var doc = win.document
  21062. if (editor.bookmark !== undefined && hasFocus(editor) === false) {
  21063. var bookmark = getRng(editor)
  21064. if (bookmark.isSome()) {
  21065. return bookmark
  21066. .map(function (r) {
  21067. return processRanges(editor, [r])[0]
  21068. })
  21069. .getOr(doc.createRange())
  21070. }
  21071. }
  21072. try {
  21073. if ((selection = getSel()) && !isRestrictedNode(selection.anchorNode)) {
  21074. if (selection.rangeCount > 0) {
  21075. rng = selection.getRangeAt(0)
  21076. } else {
  21077. rng = selection.createRange
  21078. ? selection.createRange()
  21079. : doc.createRange()
  21080. }
  21081. rng = processRanges(editor, [rng])[0]
  21082. }
  21083. } catch (ex) {}
  21084. if (!rng) {
  21085. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange()
  21086. }
  21087. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  21088. elm = dom.getRoot()
  21089. rng.setStart(elm, 0)
  21090. rng.setEnd(elm, 0)
  21091. }
  21092. if (selectedRange && explicitRange) {
  21093. if (
  21094. tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) ===
  21095. 0 &&
  21096. tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0
  21097. ) {
  21098. rng = explicitRange
  21099. } else {
  21100. selectedRange = null
  21101. explicitRange = null
  21102. }
  21103. }
  21104. return rng
  21105. }
  21106. var setRng = function (rng, forward) {
  21107. var node
  21108. if (!isValidRange(rng)) {
  21109. return
  21110. }
  21111. var ieRange = isNativeIeSelection(rng) ? rng : null
  21112. if (ieRange) {
  21113. explicitRange = null
  21114. try {
  21115. ieRange.select()
  21116. } catch (ex) {}
  21117. return
  21118. }
  21119. var sel = getSel()
  21120. var evt = editor.fire('SetSelectionRange', {
  21121. range: rng,
  21122. forward: forward,
  21123. })
  21124. rng = evt.range
  21125. if (sel) {
  21126. explicitRange = rng
  21127. try {
  21128. sel.removeAllRanges()
  21129. sel.addRange(rng)
  21130. } catch (ex) {}
  21131. if (forward === false && sel.extend) {
  21132. sel.collapse(rng.endContainer, rng.endOffset)
  21133. sel.extend(rng.startContainer, rng.startOffset)
  21134. }
  21135. selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null
  21136. }
  21137. if (
  21138. !rng.collapsed &&
  21139. rng.startContainer === rng.endContainer &&
  21140. sel.setBaseAndExtent &&
  21141. !Env.ie
  21142. ) {
  21143. if (rng.endOffset - rng.startOffset < 2) {
  21144. if (rng.startContainer.hasChildNodes()) {
  21145. node = rng.startContainer.childNodes[rng.startOffset]
  21146. if (node && node.tagName === 'IMG') {
  21147. sel.setBaseAndExtent(
  21148. rng.startContainer,
  21149. rng.startOffset,
  21150. rng.endContainer,
  21151. rng.endOffset
  21152. )
  21153. if (
  21154. sel.anchorNode !== rng.startContainer ||
  21155. sel.focusNode !== rng.endContainer
  21156. ) {
  21157. sel.setBaseAndExtent(node, 0, node, 1)
  21158. }
  21159. }
  21160. }
  21161. }
  21162. }
  21163. editor.fire('AfterSetSelectionRange', {
  21164. range: rng,
  21165. forward: forward,
  21166. })
  21167. }
  21168. var setNode = function (elm) {
  21169. setContent(dom.getOuterHTML(elm))
  21170. return elm
  21171. }
  21172. var getNode$1 = function () {
  21173. return getNode(editor.getBody(), getRng$1())
  21174. }
  21175. var getSelectedBlocks$1 = function (startElm, endElm) {
  21176. return getSelectedBlocks(dom, getRng$1(), startElm, endElm)
  21177. }
  21178. var isForward = function () {
  21179. var sel = getSel()
  21180. var anchorNode = sel === null || sel === void 0 ? void 0 : sel.anchorNode
  21181. var focusNode = sel === null || sel === void 0 ? void 0 : sel.focusNode
  21182. if (
  21183. !sel ||
  21184. !anchorNode ||
  21185. !focusNode ||
  21186. isRestrictedNode(anchorNode) ||
  21187. isRestrictedNode(focusNode)
  21188. ) {
  21189. return true
  21190. }
  21191. var anchorRange = dom.createRng()
  21192. anchorRange.setStart(anchorNode, sel.anchorOffset)
  21193. anchorRange.collapse(true)
  21194. var focusRange = dom.createRng()
  21195. focusRange.setStart(focusNode, sel.focusOffset)
  21196. focusRange.collapse(true)
  21197. return (
  21198. anchorRange.compareBoundaryPoints(
  21199. anchorRange.START_TO_START,
  21200. focusRange
  21201. ) <= 0
  21202. )
  21203. }
  21204. var normalize = function () {
  21205. var rng = getRng$1()
  21206. var sel = getSel()
  21207. if (!hasMultipleRanges(sel) && hasAnyRanges(editor)) {
  21208. var normRng = normalize$2(dom, rng)
  21209. normRng.each(function (normRng) {
  21210. setRng(normRng, isForward())
  21211. })
  21212. return normRng.getOr(rng)
  21213. }
  21214. return rng
  21215. }
  21216. var selectorChanged = function (selector, callback) {
  21217. selectorChangedWithUnbind(selector, callback)
  21218. return exports
  21219. }
  21220. var getScrollContainer = function () {
  21221. var scrollContainer
  21222. var node = dom.getRoot()
  21223. while (node && node.nodeName !== 'BODY') {
  21224. if (node.scrollHeight > node.clientHeight) {
  21225. scrollContainer = node
  21226. break
  21227. }
  21228. node = node.parentNode
  21229. }
  21230. return scrollContainer
  21231. }
  21232. var scrollIntoView = function (elm, alignToTop) {
  21233. if (isNonNullable(elm)) {
  21234. scrollElementIntoView(editor, elm, alignToTop)
  21235. } else {
  21236. scrollRangeIntoView(editor, getRng$1(), alignToTop)
  21237. }
  21238. }
  21239. var placeCaretAt = function (clientX, clientY) {
  21240. return setRng(fromPoint(clientX, clientY, editor.getDoc()))
  21241. }
  21242. var getBoundingClientRect = function () {
  21243. var rng = getRng$1()
  21244. return rng.collapsed
  21245. ? CaretPosition.fromRangeStart(rng).getClientRects()[0]
  21246. : rng.getBoundingClientRect()
  21247. }
  21248. var destroy = function () {
  21249. win = selectedRange = explicitRange = null
  21250. controlSelection.destroy()
  21251. }
  21252. var exports = {
  21253. bookmarkManager: null,
  21254. controlSelection: null,
  21255. dom: dom,
  21256. win: win,
  21257. serializer: serializer,
  21258. editor: editor,
  21259. collapse: collapse,
  21260. setCursorLocation: setCursorLocation,
  21261. getContent: getContent,
  21262. setContent: setContent,
  21263. getBookmark: getBookmark,
  21264. moveToBookmark: moveToBookmark,
  21265. select: select$1,
  21266. isCollapsed: isCollapsed,
  21267. isForward: isForward,
  21268. setNode: setNode,
  21269. getNode: getNode$1,
  21270. getSel: getSel,
  21271. setRng: setRng,
  21272. getRng: getRng$1,
  21273. getStart: getStart$1,
  21274. getEnd: getEnd$1,
  21275. getSelectedBlocks: getSelectedBlocks$1,
  21276. normalize: normalize,
  21277. selectorChanged: selectorChanged,
  21278. selectorChangedWithUnbind: selectorChangedWithUnbind,
  21279. getScrollContainer: getScrollContainer,
  21280. scrollIntoView: scrollIntoView,
  21281. placeCaretAt: placeCaretAt,
  21282. getBoundingClientRect: getBoundingClientRect,
  21283. destroy: destroy,
  21284. }
  21285. var bookmarkManager = BookmarkManager(exports)
  21286. var controlSelection = ControlSelection(exports, editor)
  21287. exports.bookmarkManager = bookmarkManager
  21288. exports.controlSelection = controlSelection
  21289. return exports
  21290. }
  21291. var removeAttrs = function (node, names) {
  21292. each$k(names, function (name) {
  21293. node.attr(name, null)
  21294. })
  21295. }
  21296. var addFontToSpansFilter = function (domParser, styles, fontSizes) {
  21297. domParser.addNodeFilter('font', function (nodes) {
  21298. each$k(nodes, function (node) {
  21299. var props = styles.parse(node.attr('style'))
  21300. var color = node.attr('color')
  21301. var face = node.attr('face')
  21302. var size = node.attr('size')
  21303. if (color) {
  21304. props.color = color
  21305. }
  21306. if (face) {
  21307. props['font-family'] = face
  21308. }
  21309. if (size) {
  21310. props['font-size'] = fontSizes[parseInt(node.attr('size'), 10) - 1]
  21311. }
  21312. node.name = 'span'
  21313. node.attr('style', styles.serialize(props))
  21314. removeAttrs(node, ['color', 'face', 'size'])
  21315. })
  21316. })
  21317. }
  21318. var addStrikeToSpanFilter = function (domParser, styles) {
  21319. domParser.addNodeFilter('strike', function (nodes) {
  21320. each$k(nodes, function (node) {
  21321. var props = styles.parse(node.attr('style'))
  21322. props['text-decoration'] = 'line-through'
  21323. node.name = 'span'
  21324. node.attr('style', styles.serialize(props))
  21325. })
  21326. })
  21327. }
  21328. var addFilters = function (domParser, settings) {
  21329. var styles = Styles()
  21330. if (settings.convert_fonts_to_spans) {
  21331. addFontToSpansFilter(
  21332. domParser,
  21333. styles,
  21334. Tools.explode(settings.font_size_legacy_values)
  21335. )
  21336. }
  21337. addStrikeToSpanFilter(domParser, styles)
  21338. }
  21339. var register$2 = function (domParser, settings) {
  21340. if (settings.inline_styles) {
  21341. addFilters(domParser, settings)
  21342. }
  21343. }
  21344. var blobUriToBlob = function (url) {
  21345. return new promiseObj(function (resolve, reject) {
  21346. var rejectWithError = function () {
  21347. reject(
  21348. 'Cannot convert ' +
  21349. url +
  21350. ' to Blob. Resource might not exist or is inaccessible.'
  21351. )
  21352. }
  21353. try {
  21354. var xhr_1 = new XMLHttpRequest()
  21355. xhr_1.open('GET', url, true)
  21356. xhr_1.responseType = 'blob'
  21357. xhr_1.onload = function () {
  21358. if (xhr_1.status === 200) {
  21359. resolve(xhr_1.response)
  21360. } else {
  21361. rejectWithError()
  21362. }
  21363. }
  21364. xhr_1.onerror = rejectWithError
  21365. xhr_1.send()
  21366. } catch (ex) {
  21367. rejectWithError()
  21368. }
  21369. })
  21370. }
  21371. var parseDataUri = function (uri) {
  21372. var type
  21373. var uriParts = decodeURIComponent(uri).split(',')
  21374. var matches = /data:([^;]+)/.exec(uriParts[0])
  21375. if (matches) {
  21376. type = matches[1]
  21377. }
  21378. return {
  21379. type: type,
  21380. data: uriParts[1],
  21381. }
  21382. }
  21383. var buildBlob = function (type, data) {
  21384. var str
  21385. try {
  21386. str = atob(data)
  21387. } catch (e) {
  21388. return Optional.none()
  21389. }
  21390. var arr = new Uint8Array(str.length)
  21391. for (var i = 0; i < arr.length; i++) {
  21392. arr[i] = str.charCodeAt(i)
  21393. }
  21394. return Optional.some(new Blob([arr], { type: type }))
  21395. }
  21396. var dataUriToBlob = function (uri) {
  21397. return new promiseObj(function (resolve) {
  21398. var _a = parseDataUri(uri),
  21399. type = _a.type,
  21400. data = _a.data
  21401. buildBlob(type, data).fold(function () {
  21402. return resolve(new Blob([]))
  21403. }, resolve)
  21404. })
  21405. }
  21406. var uriToBlob = function (url) {
  21407. if (url.indexOf('blob:') === 0) {
  21408. return blobUriToBlob(url)
  21409. }
  21410. if (url.indexOf('data:') === 0) {
  21411. return dataUriToBlob(url)
  21412. }
  21413. return null
  21414. }
  21415. var blobToDataUri = function (blob) {
  21416. return new promiseObj(function (resolve) {
  21417. var reader = new FileReader()
  21418. reader.onloadend = function () {
  21419. resolve(reader.result)
  21420. }
  21421. reader.readAsDataURL(blob)
  21422. })
  21423. }
  21424. var count$1 = 0
  21425. var uniqueId = function (prefix) {
  21426. return (prefix || 'blobid') + count$1++
  21427. }
  21428. var imageToBlobInfo = function (blobCache, img, resolve, reject) {
  21429. var base64, blobInfo
  21430. if (img.src.indexOf('blob:') === 0) {
  21431. blobInfo = blobCache.getByUri(img.src)
  21432. if (blobInfo) {
  21433. resolve({
  21434. image: img,
  21435. blobInfo: blobInfo,
  21436. })
  21437. } else {
  21438. uriToBlob(img.src).then(
  21439. function (blob) {
  21440. blobToDataUri(blob).then(function (dataUri) {
  21441. base64 = parseDataUri(dataUri).data
  21442. blobInfo = blobCache.create(uniqueId(), blob, base64)
  21443. blobCache.add(blobInfo)
  21444. resolve({
  21445. image: img,
  21446. blobInfo: blobInfo,
  21447. })
  21448. })
  21449. },
  21450. function (err) {
  21451. reject(err)
  21452. }
  21453. )
  21454. }
  21455. return
  21456. }
  21457. var _a = parseDataUri(img.src),
  21458. data = _a.data,
  21459. type = _a.type
  21460. base64 = data
  21461. blobInfo = blobCache.getByData(base64, type)
  21462. if (blobInfo) {
  21463. resolve({
  21464. image: img,
  21465. blobInfo: blobInfo,
  21466. })
  21467. } else {
  21468. uriToBlob(img.src).then(
  21469. function (blob) {
  21470. blobInfo = blobCache.create(uniqueId(), blob, base64)
  21471. blobCache.add(blobInfo)
  21472. resolve({
  21473. image: img,
  21474. blobInfo: blobInfo,
  21475. })
  21476. },
  21477. function (err) {
  21478. reject(err)
  21479. }
  21480. )
  21481. }
  21482. }
  21483. var getAllImages = function (elm) {
  21484. return elm ? from(elm.getElementsByTagName('img')) : []
  21485. }
  21486. var ImageScanner = function (uploadStatus, blobCache) {
  21487. var cachedPromises = {}
  21488. var findAll = function (elm, predicate) {
  21489. if (!predicate) {
  21490. predicate = always
  21491. }
  21492. var images = filter$4(getAllImages(elm), function (img) {
  21493. var src = img.src
  21494. if (!Env.fileApi) {
  21495. return false
  21496. }
  21497. if (img.hasAttribute('data-mce-bogus')) {
  21498. return false
  21499. }
  21500. if (img.hasAttribute('data-mce-placeholder')) {
  21501. return false
  21502. }
  21503. if (!src || src === Env.transparentSrc) {
  21504. return false
  21505. }
  21506. if (src.indexOf('blob:') === 0) {
  21507. return !uploadStatus.isUploaded(src) && predicate(img)
  21508. }
  21509. if (src.indexOf('data:') === 0) {
  21510. return predicate(img)
  21511. }
  21512. return false
  21513. })
  21514. var promises = map$3(images, function (img) {
  21515. if (cachedPromises[img.src] !== undefined) {
  21516. return new promiseObj(function (resolve) {
  21517. cachedPromises[img.src].then(function (imageInfo) {
  21518. if (typeof imageInfo === 'string') {
  21519. return imageInfo
  21520. }
  21521. resolve({
  21522. image: img,
  21523. blobInfo: imageInfo.blobInfo,
  21524. })
  21525. })
  21526. })
  21527. }
  21528. var newPromise = new promiseObj(function (resolve, reject) {
  21529. imageToBlobInfo(blobCache, img, resolve, reject)
  21530. })
  21531. .then(function (result) {
  21532. delete cachedPromises[result.image.src]
  21533. return result
  21534. })
  21535. .catch(function (error) {
  21536. delete cachedPromises[img.src]
  21537. return error
  21538. })
  21539. cachedPromises[img.src] = newPromise
  21540. return newPromise
  21541. })
  21542. return promiseObj.all(promises)
  21543. }
  21544. return { findAll: findAll }
  21545. }
  21546. var paddEmptyNode = function (settings, args, blockElements, node) {
  21547. var brPreferred = settings.padd_empty_with_br || args.insert
  21548. if (brPreferred && blockElements[node.name]) {
  21549. node.empty().append(new AstNode('br', 1)).shortEnded = true
  21550. } else {
  21551. node.empty().append(new AstNode('#text', 3)).value = nbsp
  21552. }
  21553. }
  21554. var isPaddedWithNbsp = function (node) {
  21555. return hasOnlyChild(node, '#text') && node.firstChild.value === nbsp
  21556. }
  21557. var hasOnlyChild = function (node, name) {
  21558. return (
  21559. node &&
  21560. node.firstChild &&
  21561. node.firstChild === node.lastChild &&
  21562. node.firstChild.name === name
  21563. )
  21564. }
  21565. var isPadded = function (schema, node) {
  21566. var rule = schema.getElementRule(node.name)
  21567. return rule && rule.paddEmpty
  21568. }
  21569. var isEmpty = function (schema, nonEmptyElements, whitespaceElements, node) {
  21570. return node.isEmpty(nonEmptyElements, whitespaceElements, function (node) {
  21571. return isPadded(schema, node)
  21572. })
  21573. }
  21574. var isLineBreakNode = function (node, blockElements) {
  21575. return node && (has$2(blockElements, node.name) || node.name === 'br')
  21576. }
  21577. var isBogusImage = function (img) {
  21578. return isNonNullable(img.attr('data-mce-bogus'))
  21579. }
  21580. var isInternalImageSource = function (img) {
  21581. return (
  21582. img.attr('src') === Env.transparentSrc ||
  21583. isNonNullable(img.attr('data-mce-placeholder'))
  21584. )
  21585. }
  21586. var isValidDataImg = function (img, settings) {
  21587. if (settings.images_dataimg_filter) {
  21588. var imgElem_1 = new Image()
  21589. imgElem_1.src = img.attr('src')
  21590. each$j(img.attributes.map, function (value, key) {
  21591. imgElem_1.setAttribute(key, value)
  21592. })
  21593. return settings.images_dataimg_filter(imgElem_1)
  21594. } else {
  21595. return true
  21596. }
  21597. }
  21598. var registerBase64ImageFilter = function (parser, settings) {
  21599. var blobCache = settings.blob_cache
  21600. var processImage = function (img) {
  21601. var inputSrc = img.attr('src')
  21602. if (isInternalImageSource(img) || isBogusImage(img)) {
  21603. return
  21604. }
  21605. parseDataUri$1(inputSrc)
  21606. .filter(function () {
  21607. return isValidDataImg(img, settings)
  21608. })
  21609. .bind(function (_a) {
  21610. var type = _a.type,
  21611. data = _a.data
  21612. return Optional.from(blobCache.getByData(data, type)).orThunk(
  21613. function () {
  21614. return buildBlob(type, data).map(function (blob) {
  21615. var blobInfo = blobCache.create(uniqueId(), blob, data)
  21616. blobCache.add(blobInfo)
  21617. return blobInfo
  21618. })
  21619. }
  21620. )
  21621. })
  21622. .each(function (blobInfo) {
  21623. img.attr('src', blobInfo.blobUri())
  21624. })
  21625. }
  21626. if (blobCache) {
  21627. parser.addAttributeFilter('src', function (nodes) {
  21628. return each$k(nodes, processImage)
  21629. })
  21630. }
  21631. }
  21632. var register$1 = function (parser, settings) {
  21633. var schema = parser.schema
  21634. if (settings.remove_trailing_brs) {
  21635. parser.addNodeFilter('br', function (nodes, _, args) {
  21636. var i
  21637. var l = nodes.length
  21638. var node
  21639. var blockElements = Tools.extend({}, schema.getBlockElements())
  21640. var nonEmptyElements = schema.getNonEmptyElements()
  21641. var parent, lastParent, prev, prevName
  21642. var whiteSpaceElements = schema.getWhiteSpaceElements()
  21643. var elementRule, textNode
  21644. blockElements.body = 1
  21645. for (i = 0; i < l; i++) {
  21646. node = nodes[i]
  21647. parent = node.parent
  21648. if (blockElements[node.parent.name] && node === parent.lastChild) {
  21649. prev = node.prev
  21650. while (prev) {
  21651. prevName = prev.name
  21652. if (
  21653. prevName !== 'span' ||
  21654. prev.attr('data-mce-type') !== 'bookmark'
  21655. ) {
  21656. if (prevName === 'br') {
  21657. node = null
  21658. }
  21659. break
  21660. }
  21661. prev = prev.prev
  21662. }
  21663. if (node) {
  21664. node.remove()
  21665. if (
  21666. isEmpty(schema, nonEmptyElements, whiteSpaceElements, parent)
  21667. ) {
  21668. elementRule = schema.getElementRule(parent.name)
  21669. if (elementRule) {
  21670. if (elementRule.removeEmpty) {
  21671. parent.remove()
  21672. } else if (elementRule.paddEmpty) {
  21673. paddEmptyNode(settings, args, blockElements, parent)
  21674. }
  21675. }
  21676. }
  21677. }
  21678. } else {
  21679. lastParent = node
  21680. while (
  21681. parent &&
  21682. parent.firstChild === lastParent &&
  21683. parent.lastChild === lastParent
  21684. ) {
  21685. lastParent = parent
  21686. if (blockElements[parent.name]) {
  21687. break
  21688. }
  21689. parent = parent.parent
  21690. }
  21691. if (lastParent === parent && settings.padd_empty_with_br !== true) {
  21692. textNode = new AstNode('#text', 3)
  21693. textNode.value = nbsp
  21694. node.replace(textNode)
  21695. }
  21696. }
  21697. }
  21698. })
  21699. }
  21700. parser.addAttributeFilter('href', function (nodes) {
  21701. var i = nodes.length
  21702. var appendRel = function (rel) {
  21703. var parts = rel.split(' ').filter(function (p) {
  21704. return p.length > 0
  21705. })
  21706. return parts.concat(['noopener']).sort().join(' ')
  21707. }
  21708. var addNoOpener = function (rel) {
  21709. var newRel = rel ? Tools.trim(rel) : ''
  21710. if (!/\b(noopener)\b/g.test(newRel)) {
  21711. return appendRel(newRel)
  21712. } else {
  21713. return newRel
  21714. }
  21715. }
  21716. if (!settings.allow_unsafe_link_target) {
  21717. while (i--) {
  21718. var node = nodes[i]
  21719. if (node.name === 'a' && node.attr('target') === '_blank') {
  21720. node.attr('rel', addNoOpener(node.attr('rel')))
  21721. }
  21722. }
  21723. }
  21724. })
  21725. if (!settings.allow_html_in_named_anchor) {
  21726. parser.addAttributeFilter('id,name', function (nodes) {
  21727. var i = nodes.length,
  21728. sibling,
  21729. prevSibling,
  21730. parent,
  21731. node
  21732. while (i--) {
  21733. node = nodes[i]
  21734. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  21735. parent = node.parent
  21736. sibling = node.lastChild
  21737. do {
  21738. prevSibling = sibling.prev
  21739. parent.insert(sibling, node)
  21740. sibling = prevSibling
  21741. } while (sibling)
  21742. }
  21743. }
  21744. })
  21745. }
  21746. if (settings.fix_list_elements) {
  21747. parser.addNodeFilter('ul,ol', function (nodes) {
  21748. var i = nodes.length,
  21749. node,
  21750. parentNode
  21751. while (i--) {
  21752. node = nodes[i]
  21753. parentNode = node.parent
  21754. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  21755. if (node.prev && node.prev.name === 'li') {
  21756. node.prev.append(node)
  21757. } else {
  21758. var li = new AstNode('li', 1)
  21759. li.attr('style', 'list-style-type: none')
  21760. node.wrap(li)
  21761. }
  21762. }
  21763. }
  21764. })
  21765. }
  21766. if (settings.validate && schema.getValidClasses()) {
  21767. parser.addAttributeFilter('class', function (nodes) {
  21768. var validClasses = schema.getValidClasses()
  21769. var i = nodes.length
  21770. while (i--) {
  21771. var node = nodes[i]
  21772. var classList = node.attr('class').split(' ')
  21773. var classValue = ''
  21774. for (var ci = 0; ci < classList.length; ci++) {
  21775. var className = classList[ci]
  21776. var valid = false
  21777. var validClassesMap = validClasses['*']
  21778. if (validClassesMap && validClassesMap[className]) {
  21779. valid = true
  21780. }
  21781. validClassesMap = validClasses[node.name]
  21782. if (!valid && validClassesMap && validClassesMap[className]) {
  21783. valid = true
  21784. }
  21785. if (valid) {
  21786. if (classValue) {
  21787. classValue += ' '
  21788. }
  21789. classValue += className
  21790. }
  21791. }
  21792. if (!classValue.length) {
  21793. classValue = null
  21794. }
  21795. node.attr('class', classValue)
  21796. }
  21797. })
  21798. }
  21799. registerBase64ImageFilter(parser, settings)
  21800. }
  21801. var makeMap = Tools.makeMap,
  21802. each$6 = Tools.each,
  21803. explode$2 = Tools.explode,
  21804. extend$4 = Tools.extend
  21805. var DomParser = function (settings, schema) {
  21806. if (schema === void 0) {
  21807. schema = Schema()
  21808. }
  21809. var nodeFilters = {}
  21810. var attributeFilters = []
  21811. var matchedNodes = {}
  21812. var matchedAttributes = {}
  21813. settings = settings || {}
  21814. settings.validate = 'validate' in settings ? settings.validate : true
  21815. settings.root_name = settings.root_name || 'body'
  21816. var fixInvalidChildren = function (nodes) {
  21817. var nonSplitableElements = makeMap('tr,td,th,tbody,thead,tfoot,table')
  21818. var nonEmptyElements = schema.getNonEmptyElements()
  21819. var whitespaceElements = schema.getWhiteSpaceElements()
  21820. var textBlockElements = schema.getTextBlockElements()
  21821. var specialElements = schema.getSpecialElements()
  21822. var removeOrUnwrapInvalidNode = function (node, originalNodeParent) {
  21823. if (originalNodeParent === void 0) {
  21824. originalNodeParent = node.parent
  21825. }
  21826. if (specialElements[node.name]) {
  21827. node.empty().remove()
  21828. } else {
  21829. var children = node.children()
  21830. for (
  21831. var _i = 0, children_1 = children;
  21832. _i < children_1.length;
  21833. _i++
  21834. ) {
  21835. var childNode = children_1[_i]
  21836. if (!schema.isValidChild(originalNodeParent.name, childNode.name)) {
  21837. removeOrUnwrapInvalidNode(childNode, originalNodeParent)
  21838. }
  21839. }
  21840. node.unwrap()
  21841. }
  21842. }
  21843. for (var ni = 0; ni < nodes.length; ni++) {
  21844. var node = nodes[ni]
  21845. var parent_1 = void 0,
  21846. newParent = void 0,
  21847. tempNode = void 0
  21848. if (!node.parent || node.fixed) {
  21849. continue
  21850. }
  21851. if (textBlockElements[node.name] && node.parent.name === 'li') {
  21852. var sibling = node.next
  21853. while (sibling) {
  21854. if (textBlockElements[sibling.name]) {
  21855. sibling.name = 'li'
  21856. sibling.fixed = true
  21857. node.parent.insert(sibling, node.parent)
  21858. } else {
  21859. break
  21860. }
  21861. sibling = sibling.next
  21862. }
  21863. node.unwrap()
  21864. continue
  21865. }
  21866. var parents = [node]
  21867. for (
  21868. parent_1 = node.parent;
  21869. parent_1 &&
  21870. !schema.isValidChild(parent_1.name, node.name) &&
  21871. !nonSplitableElements[parent_1.name];
  21872. parent_1 = parent_1.parent
  21873. ) {
  21874. parents.push(parent_1)
  21875. }
  21876. if (parent_1 && parents.length > 1) {
  21877. if (schema.isValidChild(parent_1.name, node.name)) {
  21878. parents.reverse()
  21879. newParent = filterNode(parents[0].clone())
  21880. var currentNode = newParent
  21881. for (var i = 0; i < parents.length - 1; i++) {
  21882. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  21883. tempNode = filterNode(parents[i].clone())
  21884. currentNode.append(tempNode)
  21885. } else {
  21886. tempNode = currentNode
  21887. }
  21888. for (
  21889. var childNode = parents[i].firstChild;
  21890. childNode && childNode !== parents[i + 1];
  21891. ) {
  21892. var nextNode = childNode.next
  21893. tempNode.append(childNode)
  21894. childNode = nextNode
  21895. }
  21896. currentNode = tempNode
  21897. }
  21898. if (
  21899. !isEmpty(schema, nonEmptyElements, whitespaceElements, newParent)
  21900. ) {
  21901. parent_1.insert(newParent, parents[0], true)
  21902. parent_1.insert(node, newParent)
  21903. } else {
  21904. parent_1.insert(node, parents[0], true)
  21905. }
  21906. parent_1 = parents[0]
  21907. if (
  21908. isEmpty(schema, nonEmptyElements, whitespaceElements, parent_1) ||
  21909. hasOnlyChild(parent_1, 'br')
  21910. ) {
  21911. parent_1.empty().remove()
  21912. }
  21913. } else {
  21914. removeOrUnwrapInvalidNode(node)
  21915. }
  21916. } else if (node.parent) {
  21917. if (node.name === 'li') {
  21918. var sibling = node.prev
  21919. if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {
  21920. sibling.append(node)
  21921. continue
  21922. }
  21923. sibling = node.next
  21924. if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {
  21925. sibling.insert(node, sibling.firstChild, true)
  21926. continue
  21927. }
  21928. node.wrap(filterNode(new AstNode('ul', 1)))
  21929. continue
  21930. }
  21931. if (
  21932. schema.isValidChild(node.parent.name, 'div') &&
  21933. schema.isValidChild('div', node.name)
  21934. ) {
  21935. node.wrap(filterNode(new AstNode('div', 1)))
  21936. } else {
  21937. removeOrUnwrapInvalidNode(node)
  21938. }
  21939. }
  21940. }
  21941. }
  21942. var filterNode = function (node) {
  21943. var name = node.name
  21944. if (name in nodeFilters) {
  21945. var list = matchedNodes[name]
  21946. if (list) {
  21947. list.push(node)
  21948. } else {
  21949. matchedNodes[name] = [node]
  21950. }
  21951. }
  21952. var i = attributeFilters.length
  21953. while (i--) {
  21954. var attrName = attributeFilters[i].name
  21955. if (attrName in node.attributes.map) {
  21956. var list = matchedAttributes[attrName]
  21957. if (list) {
  21958. list.push(node)
  21959. } else {
  21960. matchedAttributes[attrName] = [node]
  21961. }
  21962. }
  21963. }
  21964. return node
  21965. }
  21966. var addNodeFilter = function (name, callback) {
  21967. each$6(explode$2(name), function (name) {
  21968. var list = nodeFilters[name]
  21969. if (!list) {
  21970. nodeFilters[name] = list = []
  21971. }
  21972. list.push(callback)
  21973. })
  21974. }
  21975. var getNodeFilters = function () {
  21976. var out = []
  21977. for (var name_1 in nodeFilters) {
  21978. if (has$2(nodeFilters, name_1)) {
  21979. out.push({
  21980. name: name_1,
  21981. callbacks: nodeFilters[name_1],
  21982. })
  21983. }
  21984. }
  21985. return out
  21986. }
  21987. var addAttributeFilter = function (name, callback) {
  21988. each$6(explode$2(name), function (name) {
  21989. var i
  21990. for (i = 0; i < attributeFilters.length; i++) {
  21991. if (attributeFilters[i].name === name) {
  21992. attributeFilters[i].callbacks.push(callback)
  21993. return
  21994. }
  21995. }
  21996. attributeFilters.push({
  21997. name: name,
  21998. callbacks: [callback],
  21999. })
  22000. })
  22001. }
  22002. var getAttributeFilters = function () {
  22003. return [].concat(attributeFilters)
  22004. }
  22005. var parse = function (html, args) {
  22006. var nodes, i, l, fi, fl, list, name
  22007. var invalidChildren = []
  22008. var node
  22009. var getRootBlockName = function (name) {
  22010. if (name === false) {
  22011. return ''
  22012. } else if (name === true) {
  22013. return 'p'
  22014. } else {
  22015. return name
  22016. }
  22017. }
  22018. args = args || {}
  22019. matchedNodes = {}
  22020. matchedAttributes = {}
  22021. var blockElements = extend$4(
  22022. makeMap('script,style,head,html,body,title,meta,param'),
  22023. schema.getBlockElements()
  22024. )
  22025. var nonEmptyElements = schema.getNonEmptyElements()
  22026. var children = schema.children
  22027. var validate = settings.validate
  22028. var forcedRootBlockName =
  22029. 'forced_root_block' in args
  22030. ? args.forced_root_block
  22031. : settings.forced_root_block
  22032. var rootBlockName = getRootBlockName(forcedRootBlockName)
  22033. var whiteSpaceElements = schema.getWhiteSpaceElements()
  22034. var startWhiteSpaceRegExp = /^[ \t\r\n]+/
  22035. var endWhiteSpaceRegExp = /[ \t\r\n]+$/
  22036. var allWhiteSpaceRegExp = /[ \t\r\n]+/g
  22037. var isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/
  22038. var isInWhiteSpacePreservedElement =
  22039. has$2(whiteSpaceElements, args.context) ||
  22040. has$2(whiteSpaceElements, settings.root_name)
  22041. var addRootBlocks = function () {
  22042. var node = rootNode.firstChild,
  22043. rootBlockNode = null
  22044. var trim = function (rootBlock) {
  22045. if (rootBlock) {
  22046. node = rootBlock.firstChild
  22047. if (node && node.type === 3) {
  22048. node.value = node.value.replace(startWhiteSpaceRegExp, '')
  22049. }
  22050. node = rootBlock.lastChild
  22051. if (node && node.type === 3) {
  22052. node.value = node.value.replace(endWhiteSpaceRegExp, '')
  22053. }
  22054. }
  22055. }
  22056. if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
  22057. return
  22058. }
  22059. while (node) {
  22060. var next = node.next
  22061. if (
  22062. node.type === 3 ||
  22063. (node.type === 1 &&
  22064. node.name !== 'p' &&
  22065. !blockElements[node.name] &&
  22066. !node.attr('data-mce-type'))
  22067. ) {
  22068. if (!rootBlockNode) {
  22069. rootBlockNode = createNode(rootBlockName, 1)
  22070. rootBlockNode.attr(settings.forced_root_block_attrs)
  22071. rootNode.insert(rootBlockNode, node)
  22072. rootBlockNode.append(node)
  22073. } else {
  22074. rootBlockNode.append(node)
  22075. }
  22076. } else {
  22077. trim(rootBlockNode)
  22078. rootBlockNode = null
  22079. }
  22080. node = next
  22081. }
  22082. trim(rootBlockNode)
  22083. }
  22084. var createNode = function (name, type) {
  22085. var node = new AstNode(name, type)
  22086. var list
  22087. if (name in nodeFilters) {
  22088. list = matchedNodes[name]
  22089. if (list) {
  22090. list.push(node)
  22091. } else {
  22092. matchedNodes[name] = [node]
  22093. }
  22094. }
  22095. return node
  22096. }
  22097. var removeWhitespaceBefore = function (node) {
  22098. var blockElements = schema.getBlockElements()
  22099. for (var textNode = node.prev; textNode && textNode.type === 3; ) {
  22100. var textVal = textNode.value.replace(endWhiteSpaceRegExp, '')
  22101. if (textVal.length > 0) {
  22102. textNode.value = textVal
  22103. return
  22104. }
  22105. var textNodeNext = textNode.next
  22106. if (textNodeNext) {
  22107. if (textNodeNext.type === 3 && textNodeNext.value.length) {
  22108. textNode = textNode.prev
  22109. continue
  22110. }
  22111. if (
  22112. !blockElements[textNodeNext.name] &&
  22113. textNodeNext.name !== 'script' &&
  22114. textNodeNext.name !== 'style'
  22115. ) {
  22116. textNode = textNode.prev
  22117. continue
  22118. }
  22119. }
  22120. var sibling = textNode.prev
  22121. textNode.remove()
  22122. textNode = sibling
  22123. }
  22124. }
  22125. var cloneAndExcludeBlocks = function (input) {
  22126. var output = {}
  22127. for (var name_2 in input) {
  22128. if (name_2 !== 'li' && name_2 !== 'p') {
  22129. output[name_2] = input[name_2]
  22130. }
  22131. }
  22132. return output
  22133. }
  22134. var parser = SaxParser(
  22135. {
  22136. validate: validate,
  22137. document: settings.document,
  22138. allow_html_data_urls: settings.allow_html_data_urls,
  22139. allow_svg_data_urls: settings.allow_svg_data_urls,
  22140. allow_script_urls: settings.allow_script_urls,
  22141. allow_conditional_comments: settings.allow_conditional_comments,
  22142. preserve_cdata: settings.preserve_cdata,
  22143. self_closing_elements: cloneAndExcludeBlocks(
  22144. schema.getSelfClosingElements()
  22145. ),
  22146. cdata: function (text) {
  22147. node.append(createNode('#cdata', 4)).value = text
  22148. },
  22149. text: function (text, raw) {
  22150. var textNode
  22151. if (!isInWhiteSpacePreservedElement) {
  22152. text = text.replace(allWhiteSpaceRegExp, ' ')
  22153. if (isLineBreakNode(node.lastChild, blockElements)) {
  22154. text = text.replace(startWhiteSpaceRegExp, '')
  22155. }
  22156. }
  22157. if (text.length !== 0) {
  22158. textNode = createNode('#text', 3)
  22159. textNode.raw = !!raw
  22160. node.append(textNode).value = text
  22161. }
  22162. },
  22163. comment: function (text) {
  22164. node.append(createNode('#comment', 8)).value = text
  22165. },
  22166. pi: function (name, text) {
  22167. node.append(createNode(name, 7)).value = text
  22168. removeWhitespaceBefore(node)
  22169. },
  22170. doctype: function (text) {
  22171. var newNode = node.append(createNode('#doctype', 10))
  22172. newNode.value = text
  22173. removeWhitespaceBefore(node)
  22174. },
  22175. start: function (name, attrs, empty) {
  22176. var elementRule = validate ? schema.getElementRule(name) : {}
  22177. if (elementRule) {
  22178. var newNode = createNode(elementRule.outputName || name, 1)
  22179. newNode.attributes = attrs
  22180. newNode.shortEnded = empty
  22181. node.append(newNode)
  22182. var parent_2 = children[node.name]
  22183. if (
  22184. parent_2 &&
  22185. children[newNode.name] &&
  22186. !parent_2[newNode.name]
  22187. ) {
  22188. invalidChildren.push(newNode)
  22189. }
  22190. var attrFiltersLen = attributeFilters.length
  22191. while (attrFiltersLen--) {
  22192. var attrName = attributeFilters[attrFiltersLen].name
  22193. if (attrName in attrs.map) {
  22194. list = matchedAttributes[attrName]
  22195. if (list) {
  22196. list.push(newNode)
  22197. } else {
  22198. matchedAttributes[attrName] = [newNode]
  22199. }
  22200. }
  22201. }
  22202. if (blockElements[name]) {
  22203. removeWhitespaceBefore(newNode)
  22204. }
  22205. if (!empty) {
  22206. node = newNode
  22207. }
  22208. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  22209. isInWhiteSpacePreservedElement = true
  22210. }
  22211. }
  22212. },
  22213. end: function (name) {
  22214. var textNode, text, sibling, tempNode
  22215. var elementRule = validate ? schema.getElementRule(name) : {}
  22216. if (elementRule) {
  22217. if (blockElements[name]) {
  22218. if (!isInWhiteSpacePreservedElement) {
  22219. textNode = node.firstChild
  22220. if (textNode && textNode.type === 3) {
  22221. text = textNode.value.replace(startWhiteSpaceRegExp, '')
  22222. if (text.length > 0) {
  22223. textNode.value = text
  22224. textNode = textNode.next
  22225. } else {
  22226. sibling = textNode.next
  22227. textNode.remove()
  22228. textNode = sibling
  22229. while (textNode && textNode.type === 3) {
  22230. text = textNode.value
  22231. sibling = textNode.next
  22232. if (
  22233. text.length === 0 ||
  22234. isAllWhiteSpaceRegExp.test(text)
  22235. ) {
  22236. textNode.remove()
  22237. textNode = sibling
  22238. }
  22239. textNode = sibling
  22240. }
  22241. }
  22242. }
  22243. textNode = node.lastChild
  22244. if (textNode && textNode.type === 3) {
  22245. text = textNode.value.replace(endWhiteSpaceRegExp, '')
  22246. if (text.length > 0) {
  22247. textNode.value = text
  22248. textNode = textNode.prev
  22249. } else {
  22250. sibling = textNode.prev
  22251. textNode.remove()
  22252. textNode = sibling
  22253. while (textNode && textNode.type === 3) {
  22254. text = textNode.value
  22255. sibling = textNode.prev
  22256. if (
  22257. text.length === 0 ||
  22258. isAllWhiteSpaceRegExp.test(text)
  22259. ) {
  22260. textNode.remove()
  22261. textNode = sibling
  22262. }
  22263. textNode = sibling
  22264. }
  22265. }
  22266. }
  22267. }
  22268. }
  22269. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  22270. isInWhiteSpacePreservedElement = false
  22271. }
  22272. if (
  22273. elementRule.removeEmpty &&
  22274. isEmpty(schema, nonEmptyElements, whiteSpaceElements, node)
  22275. ) {
  22276. tempNode = node.parent
  22277. if (blockElements[node.name]) {
  22278. node.empty().remove()
  22279. } else {
  22280. node.unwrap()
  22281. }
  22282. node = tempNode
  22283. return
  22284. }
  22285. if (
  22286. elementRule.paddEmpty &&
  22287. (isPaddedWithNbsp(node) ||
  22288. isEmpty(schema, nonEmptyElements, whiteSpaceElements, node))
  22289. ) {
  22290. paddEmptyNode(settings, args, blockElements, node)
  22291. }
  22292. node = node.parent
  22293. }
  22294. },
  22295. },
  22296. schema
  22297. )
  22298. var rootNode = (node = new AstNode(
  22299. args.context || settings.root_name,
  22300. 11
  22301. ))
  22302. parser.parse(html, args.format)
  22303. if (validate && invalidChildren.length) {
  22304. if (!args.context) {
  22305. fixInvalidChildren(invalidChildren)
  22306. } else {
  22307. args.invalid = true
  22308. }
  22309. }
  22310. if (rootBlockName && (rootNode.name === 'body' || args.isRootContent)) {
  22311. addRootBlocks()
  22312. }
  22313. if (!args.invalid) {
  22314. for (name in matchedNodes) {
  22315. if (!has$2(matchedNodes, name)) {
  22316. continue
  22317. }
  22318. list = nodeFilters[name]
  22319. nodes = matchedNodes[name]
  22320. fi = nodes.length
  22321. while (fi--) {
  22322. if (!nodes[fi].parent) {
  22323. nodes.splice(fi, 1)
  22324. }
  22325. }
  22326. for (i = 0, l = list.length; i < l; i++) {
  22327. list[i](nodes, name, args)
  22328. }
  22329. }
  22330. for (i = 0, l = attributeFilters.length; i < l; i++) {
  22331. list = attributeFilters[i]
  22332. if (list.name in matchedAttributes) {
  22333. nodes = matchedAttributes[list.name]
  22334. fi = nodes.length
  22335. while (fi--) {
  22336. if (!nodes[fi].parent) {
  22337. nodes.splice(fi, 1)
  22338. }
  22339. }
  22340. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) {
  22341. list.callbacks[fi](nodes, list.name, args)
  22342. }
  22343. }
  22344. }
  22345. }
  22346. return rootNode
  22347. }
  22348. var exports = {
  22349. schema: schema,
  22350. addAttributeFilter: addAttributeFilter,
  22351. getAttributeFilters: getAttributeFilters,
  22352. addNodeFilter: addNodeFilter,
  22353. getNodeFilters: getNodeFilters,
  22354. filterNode: filterNode,
  22355. parse: parse,
  22356. }
  22357. register$1(exports, settings)
  22358. register$2(exports, settings)
  22359. return exports
  22360. }
  22361. var register = function (htmlParser, settings, dom) {
  22362. htmlParser.addAttributeFilter('data-mce-tabindex', function (nodes, name) {
  22363. var i = nodes.length
  22364. while (i--) {
  22365. var node = nodes[i]
  22366. node.attr('tabindex', node.attr('data-mce-tabindex'))
  22367. node.attr(name, null)
  22368. }
  22369. })
  22370. htmlParser.addAttributeFilter('src,href,style', function (nodes, name) {
  22371. var internalName = 'data-mce-' + name
  22372. var urlConverter = settings.url_converter
  22373. var urlConverterScope = settings.url_converter_scope
  22374. var i = nodes.length
  22375. while (i--) {
  22376. var node = nodes[i]
  22377. var value = node.attr(internalName)
  22378. if (value !== undefined) {
  22379. node.attr(name, value.length > 0 ? value : null)
  22380. node.attr(internalName, null)
  22381. } else {
  22382. value = node.attr(name)
  22383. if (name === 'style') {
  22384. value = dom.serializeStyle(dom.parseStyle(value), node.name)
  22385. } else if (urlConverter) {
  22386. value = urlConverter.call(urlConverterScope, value, name, node.name)
  22387. }
  22388. node.attr(name, value.length > 0 ? value : null)
  22389. }
  22390. }
  22391. })
  22392. htmlParser.addAttributeFilter('class', function (nodes) {
  22393. var i = nodes.length
  22394. while (i--) {
  22395. var node = nodes[i]
  22396. var value = node.attr('class')
  22397. if (value) {
  22398. value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, '')
  22399. node.attr('class', value.length > 0 ? value : null)
  22400. }
  22401. }
  22402. })
  22403. htmlParser.addAttributeFilter(
  22404. 'data-mce-type',
  22405. function (nodes, name, args) {
  22406. var i = nodes.length
  22407. while (i--) {
  22408. var node = nodes[i]
  22409. if (node.attr('data-mce-type') === 'bookmark' && !args.cleanup) {
  22410. var hasChildren = Optional.from(node.firstChild).exists(function (
  22411. firstChild
  22412. ) {
  22413. return !isZwsp(firstChild.value)
  22414. })
  22415. if (hasChildren) {
  22416. node.unwrap()
  22417. } else {
  22418. node.remove()
  22419. }
  22420. }
  22421. }
  22422. }
  22423. )
  22424. htmlParser.addNodeFilter('noscript', function (nodes) {
  22425. var i = nodes.length
  22426. while (i--) {
  22427. var node = nodes[i].firstChild
  22428. if (node) {
  22429. node.value = Entities.decode(node.value)
  22430. }
  22431. }
  22432. })
  22433. htmlParser.addNodeFilter('script,style', function (nodes, name) {
  22434. var trim = function (value) {
  22435. return value
  22436. .replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  22437. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  22438. .replace(
  22439. /^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi,
  22440. ''
  22441. )
  22442. .replace(
  22443. /\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g,
  22444. ''
  22445. )
  22446. }
  22447. var i = nodes.length
  22448. while (i--) {
  22449. var node = nodes[i]
  22450. var value = node.firstChild ? node.firstChild.value : ''
  22451. if (name === 'script') {
  22452. var type = node.attr('type')
  22453. if (type) {
  22454. node.attr(
  22455. 'type',
  22456. type === 'mce-no/type' ? null : type.replace(/^mce\-/, '')
  22457. )
  22458. }
  22459. if (settings.element_format === 'xhtml' && value.length > 0) {
  22460. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>'
  22461. }
  22462. } else {
  22463. if (settings.element_format === 'xhtml' && value.length > 0) {
  22464. node.firstChild.value = '<!--\n' + trim(value) + '\n-->'
  22465. }
  22466. }
  22467. }
  22468. })
  22469. htmlParser.addNodeFilter('#comment', function (nodes) {
  22470. var i = nodes.length
  22471. while (i--) {
  22472. var node = nodes[i]
  22473. if (settings.preserve_cdata && node.value.indexOf('[CDATA[') === 0) {
  22474. node.name = '#cdata'
  22475. node.type = 4
  22476. node.value = dom.decode(node.value.replace(/^\[CDATA\[|\]\]$/g, ''))
  22477. } else if (node.value.indexOf('mce:protected ') === 0) {
  22478. node.name = '#text'
  22479. node.type = 3
  22480. node.raw = true
  22481. node.value = unescape(node.value).substr(14)
  22482. }
  22483. }
  22484. })
  22485. htmlParser.addNodeFilter('xml:namespace,input', function (nodes, name) {
  22486. var i = nodes.length
  22487. while (i--) {
  22488. var node = nodes[i]
  22489. if (node.type === 7) {
  22490. node.remove()
  22491. } else if (node.type === 1) {
  22492. if (name === 'input' && !node.attr('type')) {
  22493. node.attr('type', 'text')
  22494. }
  22495. }
  22496. }
  22497. })
  22498. htmlParser.addAttributeFilter('data-mce-type', function (nodes) {
  22499. each$k(nodes, function (node) {
  22500. if (node.attr('data-mce-type') === 'format-caret') {
  22501. if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) {
  22502. node.remove()
  22503. } else {
  22504. node.unwrap()
  22505. }
  22506. }
  22507. })
  22508. })
  22509. htmlParser.addAttributeFilter(
  22510. 'data-mce-src,data-mce-href,data-mce-style,' +
  22511. 'data-mce-selected,data-mce-expando,' +
  22512. 'data-mce-type,data-mce-resize,data-mce-placeholder',
  22513. function (nodes, name) {
  22514. var i = nodes.length
  22515. while (i--) {
  22516. nodes[i].attr(name, null)
  22517. }
  22518. }
  22519. )
  22520. }
  22521. var trimTrailingBr = function (rootNode) {
  22522. var isBr = function (node) {
  22523. return node && node.name === 'br'
  22524. }
  22525. var brNode1 = rootNode.lastChild
  22526. if (isBr(brNode1)) {
  22527. var brNode2 = brNode1.prev
  22528. if (isBr(brNode2)) {
  22529. brNode1.remove()
  22530. brNode2.remove()
  22531. }
  22532. }
  22533. }
  22534. var preProcess = function (editor, node, args) {
  22535. var oldDoc
  22536. var dom = editor.dom
  22537. var clonedNode = node.cloneNode(true)
  22538. var impl = document.implementation
  22539. if (impl.createHTMLDocument) {
  22540. var doc_1 = impl.createHTMLDocument('')
  22541. Tools.each(
  22542. clonedNode.nodeName === 'BODY' ? clonedNode.childNodes : [clonedNode],
  22543. function (node) {
  22544. doc_1.body.appendChild(doc_1.importNode(node, true))
  22545. }
  22546. )
  22547. if (clonedNode.nodeName !== 'BODY') {
  22548. clonedNode = doc_1.body.firstChild
  22549. } else {
  22550. clonedNode = doc_1.body
  22551. }
  22552. oldDoc = dom.doc
  22553. dom.doc = doc_1
  22554. }
  22555. firePreProcess(editor, __assign(__assign({}, args), { node: clonedNode }))
  22556. if (oldDoc) {
  22557. dom.doc = oldDoc
  22558. }
  22559. return clonedNode
  22560. }
  22561. var shouldFireEvent = function (editor, args) {
  22562. return editor && editor.hasEventListeners('PreProcess') && !args.no_events
  22563. }
  22564. var process = function (editor, node, args) {
  22565. return shouldFireEvent(editor, args) ? preProcess(editor, node, args) : node
  22566. }
  22567. var addTempAttr = function (htmlParser, tempAttrs, name) {
  22568. if (Tools.inArray(tempAttrs, name) === -1) {
  22569. htmlParser.addAttributeFilter(name, function (nodes, name) {
  22570. var i = nodes.length
  22571. while (i--) {
  22572. nodes[i].attr(name, null)
  22573. }
  22574. })
  22575. tempAttrs.push(name)
  22576. }
  22577. }
  22578. var postProcess = function (editor, args, content) {
  22579. if (!args.no_events && editor) {
  22580. var outArgs = firePostProcess(
  22581. editor,
  22582. __assign(__assign({}, args), { content: content })
  22583. )
  22584. return outArgs.content
  22585. } else {
  22586. return content
  22587. }
  22588. }
  22589. var getHtmlFromNode = function (dom, node, args) {
  22590. var html = trim$2(args.getInner ? node.innerHTML : dom.getOuterHTML(node))
  22591. return args.selection || isWsPreserveElement(SugarElement.fromDom(node))
  22592. ? html
  22593. : Tools.trim(html)
  22594. }
  22595. var parseHtml = function (htmlParser, html, args) {
  22596. var parserArgs = args.selection
  22597. ? __assign({ forced_root_block: false }, args)
  22598. : args
  22599. var rootNode = htmlParser.parse(html, parserArgs)
  22600. trimTrailingBr(rootNode)
  22601. return rootNode
  22602. }
  22603. var serializeNode = function (settings, schema, node) {
  22604. var htmlSerializer = HtmlSerializer(settings, schema)
  22605. return htmlSerializer.serialize(node)
  22606. }
  22607. var toHtml = function (editor, settings, schema, rootNode, args) {
  22608. var content = serializeNode(settings, schema, rootNode)
  22609. return postProcess(editor, args, content)
  22610. }
  22611. var DomSerializerImpl = function (settings, editor) {
  22612. var tempAttrs = ['data-mce-selected']
  22613. var dom = editor && editor.dom ? editor.dom : DOMUtils.DOM
  22614. var schema = editor && editor.schema ? editor.schema : Schema(settings)
  22615. settings.entity_encoding = settings.entity_encoding || 'named'
  22616. settings.remove_trailing_brs =
  22617. 'remove_trailing_brs' in settings ? settings.remove_trailing_brs : true
  22618. var htmlParser = DomParser(settings, schema)
  22619. register(htmlParser, settings, dom)
  22620. var serialize = function (node, parserArgs) {
  22621. if (parserArgs === void 0) {
  22622. parserArgs = {}
  22623. }
  22624. var args = __assign({ format: 'html' }, parserArgs)
  22625. var targetNode = process(editor, node, args)
  22626. var html = getHtmlFromNode(dom, targetNode, args)
  22627. var rootNode = parseHtml(htmlParser, html, args)
  22628. return args.format === 'tree'
  22629. ? rootNode
  22630. : toHtml(editor, settings, schema, rootNode, args)
  22631. }
  22632. return {
  22633. schema: schema,
  22634. addNodeFilter: htmlParser.addNodeFilter,
  22635. addAttributeFilter: htmlParser.addAttributeFilter,
  22636. serialize: serialize,
  22637. addRules: schema.addValidElements,
  22638. setRules: schema.setValidElements,
  22639. addTempAttr: curry(addTempAttr, htmlParser, tempAttrs),
  22640. getTempAttrs: constant(tempAttrs),
  22641. getNodeFilters: htmlParser.getNodeFilters,
  22642. getAttributeFilters: htmlParser.getAttributeFilters,
  22643. }
  22644. }
  22645. var DomSerializer = function (settings, editor) {
  22646. var domSerializer = DomSerializerImpl(settings, editor)
  22647. return {
  22648. schema: domSerializer.schema,
  22649. addNodeFilter: domSerializer.addNodeFilter,
  22650. addAttributeFilter: domSerializer.addAttributeFilter,
  22651. serialize: domSerializer.serialize,
  22652. addRules: domSerializer.addRules,
  22653. setRules: domSerializer.setRules,
  22654. addTempAttr: domSerializer.addTempAttr,
  22655. getTempAttrs: domSerializer.getTempAttrs,
  22656. getNodeFilters: domSerializer.getNodeFilters,
  22657. getAttributeFilters: domSerializer.getAttributeFilters,
  22658. }
  22659. }
  22660. var defaultFormat = 'html'
  22661. var getContent = function (editor, args) {
  22662. if (args === void 0) {
  22663. args = {}
  22664. }
  22665. var format = args.format ? args.format : defaultFormat
  22666. return getContent$2(editor, args, format)
  22667. }
  22668. var setContent = function (editor, content, args) {
  22669. if (args === void 0) {
  22670. args = {}
  22671. }
  22672. return setContent$2(editor, content, args)
  22673. }
  22674. var DOM$7 = DOMUtils.DOM
  22675. var restoreOriginalStyles = function (editor) {
  22676. DOM$7.setStyle(editor.id, 'display', editor.orgDisplay)
  22677. }
  22678. var safeDestroy = function (x) {
  22679. return Optional.from(x).each(function (x) {
  22680. return x.destroy()
  22681. })
  22682. }
  22683. var clearDomReferences = function (editor) {
  22684. editor.contentAreaContainer =
  22685. editor.formElement =
  22686. editor.container =
  22687. editor.editorContainer =
  22688. null
  22689. editor.bodyElement = editor.contentDocument = editor.contentWindow = null
  22690. editor.iframeElement = editor.targetElm = null
  22691. if (editor.selection) {
  22692. editor.selection =
  22693. editor.selection.win =
  22694. editor.selection.dom =
  22695. editor.selection.dom.doc =
  22696. null
  22697. }
  22698. }
  22699. var restoreForm = function (editor) {
  22700. var form = editor.formElement
  22701. if (form) {
  22702. if (form._mceOldSubmit) {
  22703. form.submit = form._mceOldSubmit
  22704. form._mceOldSubmit = null
  22705. }
  22706. DOM$7.unbind(form, 'submit reset', editor.formEventDelegate)
  22707. }
  22708. }
  22709. var remove = function (editor) {
  22710. if (!editor.removed) {
  22711. var _selectionOverrides = editor._selectionOverrides,
  22712. editorUpload = editor.editorUpload
  22713. var body = editor.getBody()
  22714. var element = editor.getElement()
  22715. if (body) {
  22716. editor.save({ is_removing: true })
  22717. }
  22718. editor.removed = true
  22719. editor.unbindAllNativeEvents()
  22720. if (editor.hasHiddenInput && element) {
  22721. DOM$7.remove(element.nextSibling)
  22722. }
  22723. fireRemove(editor)
  22724. editor.editorManager.remove(editor)
  22725. if (!editor.inline && body) {
  22726. restoreOriginalStyles(editor)
  22727. }
  22728. fireDetach(editor)
  22729. DOM$7.remove(editor.getContainer())
  22730. safeDestroy(_selectionOverrides)
  22731. safeDestroy(editorUpload)
  22732. editor.destroy()
  22733. }
  22734. }
  22735. var destroy = function (editor, automatic) {
  22736. var selection = editor.selection,
  22737. dom = editor.dom
  22738. if (editor.destroyed) {
  22739. return
  22740. }
  22741. if (!automatic && !editor.removed) {
  22742. editor.remove()
  22743. return
  22744. }
  22745. if (!automatic) {
  22746. editor.editorManager.off('beforeunload', editor._beforeUnload)
  22747. if (editor.theme && editor.theme.destroy) {
  22748. editor.theme.destroy()
  22749. }
  22750. safeDestroy(selection)
  22751. safeDestroy(dom)
  22752. }
  22753. restoreForm(editor)
  22754. clearDomReferences(editor)
  22755. editor.destroyed = true
  22756. }
  22757. var deep = function (old, nu) {
  22758. var bothObjects = isObject(old) && isObject(nu)
  22759. return bothObjects ? deepMerge(old, nu) : nu
  22760. }
  22761. var baseMerge = function (merger) {
  22762. return function () {
  22763. var objects = []
  22764. for (var _i = 0; _i < arguments.length; _i++) {
  22765. objects[_i] = arguments[_i]
  22766. }
  22767. if (objects.length === 0) {
  22768. throw new Error("Can't merge zero objects")
  22769. }
  22770. var ret = {}
  22771. for (var j = 0; j < objects.length; j++) {
  22772. var curObject = objects[j]
  22773. for (var key in curObject) {
  22774. if (has$2(curObject, key)) {
  22775. ret[key] = merger(ret[key], curObject[key])
  22776. }
  22777. }
  22778. }
  22779. return ret
  22780. }
  22781. }
  22782. var deepMerge = baseMerge(deep)
  22783. var deprecatedSettings = (
  22784. 'autoresize_on_init,content_editable_state,convert_fonts_to_spans,inline_styles,padd_empty_with_br,block_elements,' +
  22785. 'boolean_attributes,editor_deselector,editor_selector,elements,file_browser_callback_types,filepicker_validator_handler,' +
  22786. 'force_hex_style_colors,force_p_newlines,gecko_spellcheck,images_dataimg_filter,media_scripts,mode,move_caret_before_on_enter_elements,' +
  22787. 'non_empty_elements,self_closing_elements,short_ended_elements,special,spellchecker_select_languages,spellchecker_whitelist,' +
  22788. 'tab_focus,table_responsive_width,text_block_elements,text_inline_elements,toolbar_drawer,types,validate,whitespace_elements,' +
  22789. 'paste_word_valid_elements,paste_retain_style_properties,paste_convert_word_fake_lists'
  22790. ).split(',')
  22791. var deprecatedPlugins =
  22792. 'bbcode,colorpicker,contextmenu,fullpage,legacyoutput,spellchecker,textcolor'.split(
  22793. ','
  22794. )
  22795. var movedToPremiumPlugins = 'imagetools,toc'.split(',')
  22796. var getDeprecatedSettings = function (settings) {
  22797. var settingNames = filter$4(deprecatedSettings, function (setting) {
  22798. return has$2(settings, setting)
  22799. })
  22800. var forcedRootBlock = settings.forced_root_block
  22801. if (forcedRootBlock === false || forcedRootBlock === '') {
  22802. settingNames.push('forced_root_block (false only)')
  22803. }
  22804. return sort(settingNames)
  22805. }
  22806. var getDeprecatedPlugins = function (settings) {
  22807. var plugins = Tools.makeMap(settings.plugins, ' ')
  22808. var hasPlugin = function (plugin) {
  22809. return has$2(plugins, plugin)
  22810. }
  22811. var pluginNames = __spreadArray(
  22812. __spreadArray([], filter$4(deprecatedPlugins, hasPlugin), true),
  22813. bind(movedToPremiumPlugins, function (plugin) {
  22814. return hasPlugin(plugin) ? [plugin + ' (moving to premium)'] : []
  22815. }),
  22816. true
  22817. )
  22818. return sort(pluginNames)
  22819. }
  22820. var logDeprecationsWarning = function (rawSettings, finalSettings) {
  22821. var deprecatedSettings = getDeprecatedSettings(rawSettings)
  22822. var deprecatedPlugins = getDeprecatedPlugins(finalSettings)
  22823. var hasDeprecatedPlugins = deprecatedPlugins.length > 0
  22824. var hasDeprecatedSettings = deprecatedSettings.length > 0
  22825. var isLegacyMobileTheme = finalSettings.theme === 'mobile'
  22826. if (hasDeprecatedPlugins || hasDeprecatedSettings || isLegacyMobileTheme) {
  22827. var listJoiner = '\n- '
  22828. var themesMessage = isLegacyMobileTheme
  22829. ? '\n\nThemes:' + listJoiner + 'mobile'
  22830. : ''
  22831. var pluginsMessage = hasDeprecatedPlugins
  22832. ? '\n\nPlugins:' + listJoiner + deprecatedPlugins.join(listJoiner)
  22833. : ''
  22834. var settingsMessage = hasDeprecatedSettings
  22835. ? '\n\nSettings:' + listJoiner + deprecatedSettings.join(listJoiner)
  22836. : ''
  22837. console.warn(
  22838. 'The following deprecated features are currently enabled, these will be removed in TinyMCE 6.0. ' +
  22839. 'See https://www.tiny.cloud/docs/release-notes/6.0-upcoming-changes/ for more information.' +
  22840. themesMessage +
  22841. pluginsMessage +
  22842. settingsMessage
  22843. )
  22844. }
  22845. }
  22846. var sectionResult = function (sections, settings) {
  22847. return {
  22848. sections: constant(sections),
  22849. settings: constant(settings),
  22850. }
  22851. }
  22852. var deviceDetection = detect().deviceType
  22853. var isTouch = deviceDetection.isTouch()
  22854. var isPhone = deviceDetection.isPhone()
  22855. var isTablet = deviceDetection.isTablet()
  22856. var legacyMobilePlugins = ['lists', 'autolink', 'autosave']
  22857. var defaultTouchSettings = {
  22858. table_grid: false,
  22859. object_resizing: false,
  22860. resize: false,
  22861. }
  22862. var normalizePlugins = function (plugins) {
  22863. var pluginNames = isArray$1(plugins) ? plugins.join(' ') : plugins
  22864. var trimmedPlugins = map$3(
  22865. isString$1(pluginNames) ? pluginNames.split(' ') : [],
  22866. trim$4
  22867. )
  22868. return filter$4(trimmedPlugins, function (item) {
  22869. return item.length > 0
  22870. })
  22871. }
  22872. var filterLegacyMobilePlugins = function (plugins) {
  22873. return filter$4(plugins, curry(contains$3, legacyMobilePlugins))
  22874. }
  22875. var extractSections = function (keys, settings) {
  22876. var result = bifilter(settings, function (value, key) {
  22877. return contains$3(keys, key)
  22878. })
  22879. return sectionResult(result.t, result.f)
  22880. }
  22881. var getSection = function (sectionResult, name, defaults) {
  22882. if (defaults === void 0) {
  22883. defaults = {}
  22884. }
  22885. var sections = sectionResult.sections()
  22886. var sectionSettings = get$9(sections, name).getOr({})
  22887. return Tools.extend({}, defaults, sectionSettings)
  22888. }
  22889. var hasSection = function (sectionResult, name) {
  22890. return has$2(sectionResult.sections(), name)
  22891. }
  22892. var isSectionTheme = function (sectionResult, name, theme) {
  22893. var section = sectionResult.sections()
  22894. return hasSection(sectionResult, name) && section[name].theme === theme
  22895. }
  22896. var getSectionConfig = function (sectionResult, name) {
  22897. return hasSection(sectionResult, name) ? sectionResult.sections()[name] : {}
  22898. }
  22899. var getToolbarMode = function (settings, defaultVal) {
  22900. return get$9(settings, 'toolbar_mode')
  22901. .orThunk(function () {
  22902. return get$9(settings, 'toolbar_drawer').map(function (val) {
  22903. return val === false ? 'wrap' : val
  22904. })
  22905. })
  22906. .getOr(defaultVal)
  22907. }
  22908. var getDefaultSettings = function (
  22909. settings,
  22910. id,
  22911. documentBaseUrl,
  22912. isTouch,
  22913. editor
  22914. ) {
  22915. var baseDefaults = {
  22916. id: id,
  22917. theme: 'silver',
  22918. toolbar_mode: getToolbarMode(settings, 'floating'),
  22919. plugins: '',
  22920. document_base_url: documentBaseUrl,
  22921. add_form_submit_trigger: true,
  22922. submit_patch: true,
  22923. add_unload_trigger: true,
  22924. convert_urls: true,
  22925. relative_urls: true,
  22926. remove_script_host: true,
  22927. object_resizing: true,
  22928. doctype: '<!DOCTYPE html>',
  22929. visual: true,
  22930. font_size_legacy_values:
  22931. 'xx-small,small,medium,large,x-large,xx-large,300%',
  22932. forced_root_block: 'p',
  22933. hidden_input: true,
  22934. inline_styles: true,
  22935. convert_fonts_to_spans: true,
  22936. indent: true,
  22937. indent_before:
  22938. 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' +
  22939. 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist',
  22940. indent_after:
  22941. 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' +
  22942. 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist',
  22943. entity_encoding: 'named',
  22944. url_converter: editor.convertURL,
  22945. url_converter_scope: editor,
  22946. }
  22947. return __assign(
  22948. __assign({}, baseDefaults),
  22949. isTouch ? defaultTouchSettings : {}
  22950. )
  22951. }
  22952. var getDefaultMobileSettings = function (mobileSettings, isPhone) {
  22953. var defaultMobileSettings = {
  22954. resize: false,
  22955. toolbar_mode: getToolbarMode(mobileSettings, 'scrolling'),
  22956. toolbar_sticky: false,
  22957. }
  22958. var defaultPhoneSettings = { menubar: false }
  22959. return __assign(
  22960. __assign(__assign({}, defaultTouchSettings), defaultMobileSettings),
  22961. isPhone ? defaultPhoneSettings : {}
  22962. )
  22963. }
  22964. var getExternalPlugins = function (overrideSettings, settings) {
  22965. var userDefinedExternalPlugins = settings.external_plugins
  22966. ? settings.external_plugins
  22967. : {}
  22968. if (overrideSettings && overrideSettings.external_plugins) {
  22969. return Tools.extend(
  22970. {},
  22971. overrideSettings.external_plugins,
  22972. userDefinedExternalPlugins
  22973. )
  22974. } else {
  22975. return userDefinedExternalPlugins
  22976. }
  22977. }
  22978. var combinePlugins = function (forcedPlugins, plugins) {
  22979. return []
  22980. .concat(normalizePlugins(forcedPlugins))
  22981. .concat(normalizePlugins(plugins))
  22982. }
  22983. var getPlatformPlugins = function (
  22984. isMobileDevice,
  22985. sectionResult,
  22986. desktopPlugins,
  22987. mobilePlugins
  22988. ) {
  22989. if (isMobileDevice && isSectionTheme(sectionResult, 'mobile', 'mobile')) {
  22990. return filterLegacyMobilePlugins(mobilePlugins)
  22991. } else if (isMobileDevice && hasSection(sectionResult, 'mobile')) {
  22992. return mobilePlugins
  22993. } else {
  22994. return desktopPlugins
  22995. }
  22996. }
  22997. var processPlugins = function (
  22998. isMobileDevice,
  22999. sectionResult,
  23000. defaultOverrideSettings,
  23001. settings
  23002. ) {
  23003. var forcedPlugins = normalizePlugins(defaultOverrideSettings.forced_plugins)
  23004. var desktopPlugins = normalizePlugins(settings.plugins)
  23005. var mobileConfig = getSectionConfig(sectionResult, 'mobile')
  23006. var mobilePlugins = mobileConfig.plugins
  23007. ? normalizePlugins(mobileConfig.plugins)
  23008. : desktopPlugins
  23009. var platformPlugins = getPlatformPlugins(
  23010. isMobileDevice,
  23011. sectionResult,
  23012. desktopPlugins,
  23013. mobilePlugins
  23014. )
  23015. var combinedPlugins = combinePlugins(forcedPlugins, platformPlugins)
  23016. if (Env.browser.isIE() && contains$3(combinedPlugins, 'rtc')) {
  23017. throw new Error('RTC plugin is not supported on IE 11.')
  23018. }
  23019. return Tools.extend(settings, { plugins: combinedPlugins.join(' ') })
  23020. }
  23021. var isOnMobile = function (isMobileDevice, sectionResult) {
  23022. return isMobileDevice && hasSection(sectionResult, 'mobile')
  23023. }
  23024. var combineSettings = function (
  23025. isMobileDevice,
  23026. isPhone,
  23027. defaultSettings,
  23028. defaultOverrideSettings,
  23029. settings
  23030. ) {
  23031. var defaultDeviceSettings = isMobileDevice
  23032. ? { mobile: getDefaultMobileSettings(settings.mobile || {}, isPhone) }
  23033. : {}
  23034. var sectionResult = extractSections(
  23035. ['mobile'],
  23036. deepMerge(defaultDeviceSettings, settings)
  23037. )
  23038. var extendedSettings = Tools.extend(
  23039. defaultSettings,
  23040. defaultOverrideSettings,
  23041. sectionResult.settings(),
  23042. isOnMobile(isMobileDevice, sectionResult)
  23043. ? getSection(sectionResult, 'mobile')
  23044. : {},
  23045. {
  23046. validate: true,
  23047. external_plugins: getExternalPlugins(
  23048. defaultOverrideSettings,
  23049. sectionResult.settings()
  23050. ),
  23051. }
  23052. )
  23053. return processPlugins(
  23054. isMobileDevice,
  23055. sectionResult,
  23056. defaultOverrideSettings,
  23057. extendedSettings
  23058. )
  23059. }
  23060. var getEditorSettings = function (
  23061. editor,
  23062. id,
  23063. documentBaseUrl,
  23064. defaultOverrideSettings,
  23065. settings
  23066. ) {
  23067. var defaultSettings = getDefaultSettings(
  23068. settings,
  23069. id,
  23070. documentBaseUrl,
  23071. isTouch,
  23072. editor
  23073. )
  23074. var finalSettings = combineSettings(
  23075. isPhone || isTablet,
  23076. isPhone,
  23077. defaultSettings,
  23078. defaultOverrideSettings,
  23079. settings
  23080. )
  23081. if (finalSettings.deprecation_warnings !== false) {
  23082. logDeprecationsWarning(settings, finalSettings)
  23083. }
  23084. return finalSettings
  23085. }
  23086. var getFiltered = function (predicate, editor, name) {
  23087. return Optional.from(editor.settings[name]).filter(predicate)
  23088. }
  23089. var getParamObject = function (value) {
  23090. var output = {}
  23091. if (typeof value === 'string') {
  23092. each$k(
  23093. value.indexOf('=') > 0
  23094. ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/)
  23095. : value.split(','),
  23096. function (val) {
  23097. var arr = val.split('=')
  23098. if (arr.length > 1) {
  23099. output[Tools.trim(arr[0])] = Tools.trim(arr[1])
  23100. } else {
  23101. output[Tools.trim(arr[0])] = Tools.trim(arr[0])
  23102. }
  23103. }
  23104. )
  23105. } else {
  23106. output = value
  23107. }
  23108. return output
  23109. }
  23110. var isArrayOf = function (p) {
  23111. return function (a) {
  23112. return isArray$1(a) && forall(a, p)
  23113. }
  23114. }
  23115. var getParam = function (editor, name, defaultVal, type) {
  23116. var value = name in editor.settings ? editor.settings[name] : defaultVal
  23117. if (type === 'hash') {
  23118. return getParamObject(value)
  23119. } else if (type === 'string') {
  23120. return getFiltered(isString$1, editor, name).getOr(defaultVal)
  23121. } else if (type === 'number') {
  23122. return getFiltered(isNumber, editor, name).getOr(defaultVal)
  23123. } else if (type === 'boolean') {
  23124. return getFiltered(isBoolean, editor, name).getOr(defaultVal)
  23125. } else if (type === 'object') {
  23126. return getFiltered(isObject, editor, name).getOr(defaultVal)
  23127. } else if (type === 'array') {
  23128. return getFiltered(isArray$1, editor, name).getOr(defaultVal)
  23129. } else if (type === 'string[]') {
  23130. return getFiltered(isArrayOf(isString$1), editor, name).getOr(defaultVal)
  23131. } else if (type === 'function') {
  23132. return getFiltered(isFunction, editor, name).getOr(defaultVal)
  23133. } else {
  23134. return value
  23135. }
  23136. }
  23137. var CreateIconManager = function () {
  23138. var lookup = {}
  23139. var add = function (id, iconPack) {
  23140. lookup[id] = iconPack
  23141. }
  23142. var get = function (id) {
  23143. if (lookup[id]) {
  23144. return lookup[id]
  23145. }
  23146. return { icons: {} }
  23147. }
  23148. var has = function (id) {
  23149. return has$2(lookup, id)
  23150. }
  23151. return {
  23152. add: add,
  23153. get: get,
  23154. has: has,
  23155. }
  23156. }
  23157. var IconManager = CreateIconManager()
  23158. var getProp = function (propName, elm) {
  23159. var rawElm = elm.dom
  23160. return rawElm[propName]
  23161. }
  23162. var getComputedSizeProp = function (propName, elm) {
  23163. return parseInt(get$5(elm, propName), 10)
  23164. }
  23165. var getClientWidth = curry(getProp, 'clientWidth')
  23166. var getClientHeight = curry(getProp, 'clientHeight')
  23167. var getMarginTop = curry(getComputedSizeProp, 'margin-top')
  23168. var getMarginLeft = curry(getComputedSizeProp, 'margin-left')
  23169. var getBoundingClientRect = function (elm) {
  23170. return elm.dom.getBoundingClientRect()
  23171. }
  23172. var isInsideElementContentArea = function (bodyElm, clientX, clientY) {
  23173. var clientWidth = getClientWidth(bodyElm)
  23174. var clientHeight = getClientHeight(bodyElm)
  23175. return (
  23176. clientX >= 0 &&
  23177. clientY >= 0 &&
  23178. clientX <= clientWidth &&
  23179. clientY <= clientHeight
  23180. )
  23181. }
  23182. var transpose = function (inline, elm, clientX, clientY) {
  23183. var clientRect = getBoundingClientRect(elm)
  23184. var deltaX = inline
  23185. ? clientRect.left + elm.dom.clientLeft + getMarginLeft(elm)
  23186. : 0
  23187. var deltaY = inline
  23188. ? clientRect.top + elm.dom.clientTop + getMarginTop(elm)
  23189. : 0
  23190. var x = clientX - deltaX
  23191. var y = clientY - deltaY
  23192. return {
  23193. x: x,
  23194. y: y,
  23195. }
  23196. }
  23197. var isXYInContentArea = function (editor, clientX, clientY) {
  23198. var bodyElm = SugarElement.fromDom(editor.getBody())
  23199. var targetElm = editor.inline ? bodyElm : documentElement(bodyElm)
  23200. var transposedPoint = transpose(editor.inline, targetElm, clientX, clientY)
  23201. return isInsideElementContentArea(
  23202. targetElm,
  23203. transposedPoint.x,
  23204. transposedPoint.y
  23205. )
  23206. }
  23207. var fromDomSafe = function (node) {
  23208. return Optional.from(node).map(SugarElement.fromDom)
  23209. }
  23210. var isEditorAttachedToDom = function (editor) {
  23211. var rawContainer = editor.inline
  23212. ? editor.getBody()
  23213. : editor.getContentAreaContainer()
  23214. return fromDomSafe(rawContainer).map(inBody).getOr(false)
  23215. }
  23216. var NotificationManagerImpl = function () {
  23217. var unimplemented = function () {
  23218. throw new Error(
  23219. 'Theme did not provide a NotificationManager implementation.'
  23220. )
  23221. }
  23222. return {
  23223. open: unimplemented,
  23224. close: unimplemented,
  23225. reposition: unimplemented,
  23226. getArgs: unimplemented,
  23227. }
  23228. }
  23229. var NotificationManager = function (editor) {
  23230. var notifications = []
  23231. var getImplementation = function () {
  23232. var theme = editor.theme
  23233. return theme && theme.getNotificationManagerImpl
  23234. ? theme.getNotificationManagerImpl()
  23235. : NotificationManagerImpl()
  23236. }
  23237. var getTopNotification = function () {
  23238. return Optional.from(notifications[0])
  23239. }
  23240. var isEqual = function (a, b) {
  23241. return (
  23242. a.type === b.type &&
  23243. a.text === b.text &&
  23244. !a.progressBar &&
  23245. !a.timeout &&
  23246. !b.progressBar &&
  23247. !b.timeout
  23248. )
  23249. }
  23250. var reposition = function () {
  23251. if (notifications.length > 0) {
  23252. getImplementation().reposition(notifications)
  23253. }
  23254. }
  23255. var addNotification = function (notification) {
  23256. notifications.push(notification)
  23257. }
  23258. var closeNotification = function (notification) {
  23259. findIndex$2(notifications, function (otherNotification) {
  23260. return otherNotification === notification
  23261. }).each(function (index) {
  23262. notifications.splice(index, 1)
  23263. })
  23264. }
  23265. var open = function (spec, fireEvent) {
  23266. if (fireEvent === void 0) {
  23267. fireEvent = true
  23268. }
  23269. if (editor.removed || !isEditorAttachedToDom(editor)) {
  23270. return
  23271. }
  23272. if (fireEvent) {
  23273. editor.fire('BeforeOpenNotification', { notification: spec })
  23274. }
  23275. return find$3(notifications, function (notification) {
  23276. return isEqual(getImplementation().getArgs(notification), spec)
  23277. }).getOrThunk(function () {
  23278. editor.editorManager.setActive(editor)
  23279. var notification = getImplementation().open(spec, function () {
  23280. closeNotification(notification)
  23281. reposition()
  23282. getTopNotification().fold(
  23283. function () {
  23284. return editor.focus()
  23285. },
  23286. function (top) {
  23287. return focus$1(SugarElement.fromDom(top.getEl()))
  23288. }
  23289. )
  23290. })
  23291. addNotification(notification)
  23292. reposition()
  23293. editor.fire('OpenNotification', {
  23294. notification: __assign({}, notification),
  23295. })
  23296. return notification
  23297. })
  23298. }
  23299. var close = function () {
  23300. getTopNotification().each(function (notification) {
  23301. getImplementation().close(notification)
  23302. closeNotification(notification)
  23303. reposition()
  23304. })
  23305. }
  23306. var getNotifications = constant(notifications)
  23307. var registerEvents = function (editor) {
  23308. editor.on('SkinLoaded', function () {
  23309. var serviceMessage = getServiceMessage(editor)
  23310. if (serviceMessage) {
  23311. open(
  23312. {
  23313. text: serviceMessage,
  23314. type: 'warning',
  23315. timeout: 0,
  23316. },
  23317. false
  23318. )
  23319. }
  23320. reposition()
  23321. })
  23322. editor.on('show ResizeEditor ResizeWindow NodeChange', function () {
  23323. Delay.requestAnimationFrame(reposition)
  23324. })
  23325. editor.on('remove', function () {
  23326. each$k(notifications.slice(), function (notification) {
  23327. getImplementation().close(notification)
  23328. })
  23329. })
  23330. }
  23331. registerEvents(editor)
  23332. return {
  23333. open: open,
  23334. close: close,
  23335. getNotifications: getNotifications,
  23336. }
  23337. }
  23338. var PluginManager = AddOnManager.PluginManager
  23339. var ThemeManager = AddOnManager.ThemeManager
  23340. function WindowManagerImpl() {
  23341. var unimplemented = function () {
  23342. throw new Error('Theme did not provide a WindowManager implementation.')
  23343. }
  23344. return {
  23345. open: unimplemented,
  23346. openUrl: unimplemented,
  23347. alert: unimplemented,
  23348. confirm: unimplemented,
  23349. close: unimplemented,
  23350. getParams: unimplemented,
  23351. setParams: unimplemented,
  23352. }
  23353. }
  23354. var WindowManager = function (editor) {
  23355. var dialogs = []
  23356. var getImplementation = function () {
  23357. var theme = editor.theme
  23358. return theme && theme.getWindowManagerImpl
  23359. ? theme.getWindowManagerImpl()
  23360. : WindowManagerImpl()
  23361. }
  23362. var funcBind = function (scope, f) {
  23363. return function () {
  23364. var args = []
  23365. for (var _i = 0; _i < arguments.length; _i++) {
  23366. args[_i] = arguments[_i]
  23367. }
  23368. return f ? f.apply(scope, args) : undefined
  23369. }
  23370. }
  23371. var fireOpenEvent = function (dialog) {
  23372. editor.fire('OpenWindow', { dialog: dialog })
  23373. }
  23374. var fireCloseEvent = function (dialog) {
  23375. editor.fire('CloseWindow', { dialog: dialog })
  23376. }
  23377. var addDialog = function (dialog) {
  23378. dialogs.push(dialog)
  23379. fireOpenEvent(dialog)
  23380. }
  23381. var closeDialog = function (dialog) {
  23382. fireCloseEvent(dialog)
  23383. dialogs = filter$4(dialogs, function (otherDialog) {
  23384. return otherDialog !== dialog
  23385. })
  23386. if (dialogs.length === 0) {
  23387. editor.focus()
  23388. }
  23389. }
  23390. var getTopDialog = function () {
  23391. return Optional.from(dialogs[dialogs.length - 1])
  23392. }
  23393. var storeSelectionAndOpenDialog = function (openDialog) {
  23394. editor.editorManager.setActive(editor)
  23395. store(editor)
  23396. var dialog = openDialog()
  23397. addDialog(dialog)
  23398. return dialog
  23399. }
  23400. var open = function (args, params) {
  23401. return storeSelectionAndOpenDialog(function () {
  23402. return getImplementation().open(args, params, closeDialog)
  23403. })
  23404. }
  23405. var openUrl = function (args) {
  23406. return storeSelectionAndOpenDialog(function () {
  23407. return getImplementation().openUrl(args, closeDialog)
  23408. })
  23409. }
  23410. var alert = function (message, callback, scope) {
  23411. var windowManagerImpl = getImplementation()
  23412. windowManagerImpl.alert(
  23413. message,
  23414. funcBind(scope ? scope : windowManagerImpl, callback)
  23415. )
  23416. }
  23417. var confirm = function (message, callback, scope) {
  23418. var windowManagerImpl = getImplementation()
  23419. windowManagerImpl.confirm(
  23420. message,
  23421. funcBind(scope ? scope : windowManagerImpl, callback)
  23422. )
  23423. }
  23424. var close = function () {
  23425. getTopDialog().each(function (dialog) {
  23426. getImplementation().close(dialog)
  23427. closeDialog(dialog)
  23428. })
  23429. }
  23430. editor.on('remove', function () {
  23431. each$k(dialogs, function (dialog) {
  23432. getImplementation().close(dialog)
  23433. })
  23434. })
  23435. return {
  23436. open: open,
  23437. openUrl: openUrl,
  23438. alert: alert,
  23439. confirm: confirm,
  23440. close: close,
  23441. }
  23442. }
  23443. var displayNotification = function (editor, message) {
  23444. editor.notificationManager.open({
  23445. type: 'error',
  23446. text: message,
  23447. })
  23448. }
  23449. var displayError = function (editor, message) {
  23450. if (editor._skinLoaded) {
  23451. displayNotification(editor, message)
  23452. } else {
  23453. editor.on('SkinLoaded', function () {
  23454. displayNotification(editor, message)
  23455. })
  23456. }
  23457. }
  23458. var uploadError = function (editor, message) {
  23459. displayError(
  23460. editor,
  23461. I18n.translate(['Failed to upload image: {0}', message])
  23462. )
  23463. }
  23464. var logError = function (editor, errorType, msg) {
  23465. fireError(editor, errorType, { message: msg })
  23466. console.error(msg)
  23467. }
  23468. var createLoadError = function (type, url, name) {
  23469. return name
  23470. ? 'Failed to load ' + type + ': ' + name + ' from url ' + url
  23471. : 'Failed to load ' + type + ' url: ' + url
  23472. }
  23473. var pluginLoadError = function (editor, url, name) {
  23474. logError(editor, 'PluginLoadError', createLoadError('plugin', url, name))
  23475. }
  23476. var iconsLoadError = function (editor, url, name) {
  23477. logError(editor, 'IconsLoadError', createLoadError('icons', url, name))
  23478. }
  23479. var languageLoadError = function (editor, url, name) {
  23480. logError(
  23481. editor,
  23482. 'LanguageLoadError',
  23483. createLoadError('language', url, name)
  23484. )
  23485. }
  23486. var pluginInitError = function (editor, name, err) {
  23487. var message = I18n.translate(['Failed to initialize plugin: {0}', name])
  23488. fireError(editor, 'PluginLoadError', { message: message })
  23489. initError(message, err)
  23490. displayError(editor, message)
  23491. }
  23492. var initError = function (message) {
  23493. var x = []
  23494. for (var _i = 1; _i < arguments.length; _i++) {
  23495. x[_i - 1] = arguments[_i]
  23496. }
  23497. var console = window.console
  23498. if (console) {
  23499. if (console.error) {
  23500. console.error.apply(console, __spreadArray([message], x, false))
  23501. } else {
  23502. console.log.apply(console, __spreadArray([message], x, false))
  23503. }
  23504. }
  23505. }
  23506. var isContentCssSkinName = function (url) {
  23507. return /^[a-z0-9\-]+$/i.test(url)
  23508. }
  23509. var getContentCssUrls = function (editor) {
  23510. return transformToUrls(editor, getContentCss(editor))
  23511. }
  23512. var getFontCssUrls = function (editor) {
  23513. return transformToUrls(editor, getFontCss(editor))
  23514. }
  23515. var transformToUrls = function (editor, cssLinks) {
  23516. var skinUrl = editor.editorManager.baseURL + '/skins/content'
  23517. var suffix = editor.editorManager.suffix
  23518. var contentCssFile = 'content' + suffix + '.css'
  23519. var inline = editor.inline === true
  23520. return map$3(cssLinks, function (url) {
  23521. if (isContentCssSkinName(url) && !inline) {
  23522. return skinUrl + '/' + url + '/' + contentCssFile
  23523. } else {
  23524. return editor.documentBaseURI.toAbsolute(url)
  23525. }
  23526. })
  23527. }
  23528. var appendContentCssFromSettings = function (editor) {
  23529. editor.contentCSS = editor.contentCSS.concat(
  23530. getContentCssUrls(editor),
  23531. getFontCssUrls(editor)
  23532. )
  23533. }
  23534. var UploadStatus = function () {
  23535. var PENDING = 1,
  23536. UPLOADED = 2
  23537. var blobUriStatuses = {}
  23538. var createStatus = function (status, resultUri) {
  23539. return {
  23540. status: status,
  23541. resultUri: resultUri,
  23542. }
  23543. }
  23544. var hasBlobUri = function (blobUri) {
  23545. return blobUri in blobUriStatuses
  23546. }
  23547. var getResultUri = function (blobUri) {
  23548. var result = blobUriStatuses[blobUri]
  23549. return result ? result.resultUri : null
  23550. }
  23551. var isPending = function (blobUri) {
  23552. return hasBlobUri(blobUri)
  23553. ? blobUriStatuses[blobUri].status === PENDING
  23554. : false
  23555. }
  23556. var isUploaded = function (blobUri) {
  23557. return hasBlobUri(blobUri)
  23558. ? blobUriStatuses[blobUri].status === UPLOADED
  23559. : false
  23560. }
  23561. var markPending = function (blobUri) {
  23562. blobUriStatuses[blobUri] = createStatus(PENDING, null)
  23563. }
  23564. var markUploaded = function (blobUri, resultUri) {
  23565. blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri)
  23566. }
  23567. var removeFailed = function (blobUri) {
  23568. delete blobUriStatuses[blobUri]
  23569. }
  23570. var destroy = function () {
  23571. blobUriStatuses = {}
  23572. }
  23573. return {
  23574. hasBlobUri: hasBlobUri,
  23575. getResultUri: getResultUri,
  23576. isPending: isPending,
  23577. isUploaded: isUploaded,
  23578. markPending: markPending,
  23579. markUploaded: markUploaded,
  23580. removeFailed: removeFailed,
  23581. destroy: destroy,
  23582. }
  23583. }
  23584. var count = 0
  23585. var seed = function () {
  23586. var rnd = function () {
  23587. return Math.round(Math.random() * 4294967295).toString(36)
  23588. }
  23589. var now = new Date().getTime()
  23590. return 's' + now.toString(36) + rnd() + rnd() + rnd()
  23591. }
  23592. var uuid = function (prefix) {
  23593. return prefix + count++ + seed()
  23594. }
  23595. var BlobCache = function () {
  23596. var cache = []
  23597. var mimeToExt = function (mime) {
  23598. var mimes = {
  23599. 'image/jpeg': 'jpg',
  23600. 'image/jpg': 'jpg',
  23601. 'image/gif': 'gif',
  23602. 'image/png': 'png',
  23603. 'image/apng': 'apng',
  23604. 'image/avif': 'avif',
  23605. 'image/svg+xml': 'svg',
  23606. 'image/webp': 'webp',
  23607. 'image/bmp': 'bmp',
  23608. 'image/tiff': 'tiff',
  23609. }
  23610. return mimes[mime.toLowerCase()] || 'dat'
  23611. }
  23612. var create = function (o, blob, base64, name, filename) {
  23613. if (isString$1(o)) {
  23614. var id = o
  23615. return toBlobInfo({
  23616. id: id,
  23617. name: name,
  23618. filename: filename,
  23619. blob: blob,
  23620. base64: base64,
  23621. })
  23622. } else if (isObject(o)) {
  23623. return toBlobInfo(o)
  23624. } else {
  23625. throw new Error('Unknown input type')
  23626. }
  23627. }
  23628. var toBlobInfo = function (o) {
  23629. if (!o.blob || !o.base64) {
  23630. throw new Error(
  23631. 'blob and base64 representations of the image are required for BlobInfo to be created'
  23632. )
  23633. }
  23634. var id = o.id || uuid('blobid')
  23635. var name = o.name || id
  23636. var blob = o.blob
  23637. return {
  23638. id: constant(id),
  23639. name: constant(name),
  23640. filename: constant(o.filename || name + '.' + mimeToExt(blob.type)),
  23641. blob: constant(blob),
  23642. base64: constant(o.base64),
  23643. blobUri: constant(o.blobUri || URL.createObjectURL(blob)),
  23644. uri: constant(o.uri),
  23645. }
  23646. }
  23647. var add = function (blobInfo) {
  23648. if (!get(blobInfo.id())) {
  23649. cache.push(blobInfo)
  23650. }
  23651. }
  23652. var findFirst = function (predicate) {
  23653. return find$3(cache, predicate).getOrUndefined()
  23654. }
  23655. var get = function (id) {
  23656. return findFirst(function (cachedBlobInfo) {
  23657. return cachedBlobInfo.id() === id
  23658. })
  23659. }
  23660. var getByUri = function (blobUri) {
  23661. return findFirst(function (blobInfo) {
  23662. return blobInfo.blobUri() === blobUri
  23663. })
  23664. }
  23665. var getByData = function (base64, type) {
  23666. return findFirst(function (blobInfo) {
  23667. return blobInfo.base64() === base64 && blobInfo.blob().type === type
  23668. })
  23669. }
  23670. var removeByUri = function (blobUri) {
  23671. cache = filter$4(cache, function (blobInfo) {
  23672. if (blobInfo.blobUri() === blobUri) {
  23673. URL.revokeObjectURL(blobInfo.blobUri())
  23674. return false
  23675. }
  23676. return true
  23677. })
  23678. }
  23679. var destroy = function () {
  23680. each$k(cache, function (cachedBlobInfo) {
  23681. URL.revokeObjectURL(cachedBlobInfo.blobUri())
  23682. })
  23683. cache = []
  23684. }
  23685. return {
  23686. create: create,
  23687. add: add,
  23688. get: get,
  23689. getByUri: getByUri,
  23690. getByData: getByData,
  23691. findFirst: findFirst,
  23692. removeByUri: removeByUri,
  23693. destroy: destroy,
  23694. }
  23695. }
  23696. var Uploader = function (uploadStatus, settings) {
  23697. var pendingPromises = {}
  23698. var pathJoin = function (path1, path2) {
  23699. if (path1) {
  23700. return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '')
  23701. }
  23702. return path2
  23703. }
  23704. var defaultHandler = function (blobInfo, success, failure, progress) {
  23705. var xhr = new XMLHttpRequest()
  23706. xhr.open('POST', settings.url)
  23707. xhr.withCredentials = settings.credentials
  23708. xhr.upload.onprogress = function (e) {
  23709. progress((e.loaded / e.total) * 100)
  23710. }
  23711. xhr.onerror = function () {
  23712. failure(
  23713. 'Image upload failed due to a XHR Transport error. Code: ' +
  23714. xhr.status
  23715. )
  23716. }
  23717. xhr.onload = function () {
  23718. if (xhr.status < 200 || xhr.status >= 300) {
  23719. failure('HTTP Error: ' + xhr.status)
  23720. return
  23721. }
  23722. var json = JSON.parse(xhr.responseText)
  23723. if (!json || typeof json.location !== 'string') {
  23724. failure('Invalid JSON: ' + xhr.responseText)
  23725. return
  23726. }
  23727. success(pathJoin(settings.basePath, json.location))
  23728. }
  23729. var formData = new FormData()
  23730. formData.append('file', blobInfo.blob(), blobInfo.filename())
  23731. xhr.send(formData)
  23732. }
  23733. var noUpload = function () {
  23734. return new promiseObj(function (resolve) {
  23735. resolve([])
  23736. })
  23737. }
  23738. var handlerSuccess = function (blobInfo, url) {
  23739. return {
  23740. url: url,
  23741. blobInfo: blobInfo,
  23742. status: true,
  23743. }
  23744. }
  23745. var handlerFailure = function (blobInfo, message, options) {
  23746. return {
  23747. url: '',
  23748. blobInfo: blobInfo,
  23749. status: false,
  23750. error: {
  23751. message: message,
  23752. options: options,
  23753. },
  23754. }
  23755. }
  23756. var resolvePending = function (blobUri, result) {
  23757. Tools.each(pendingPromises[blobUri], function (resolve) {
  23758. resolve(result)
  23759. })
  23760. delete pendingPromises[blobUri]
  23761. }
  23762. var uploadBlobInfo = function (blobInfo, handler, openNotification) {
  23763. uploadStatus.markPending(blobInfo.blobUri())
  23764. return new promiseObj(function (resolve) {
  23765. var notification, progress
  23766. try {
  23767. var closeNotification_1 = function () {
  23768. if (notification) {
  23769. notification.close()
  23770. progress = noop
  23771. }
  23772. }
  23773. var success = function (url) {
  23774. closeNotification_1()
  23775. uploadStatus.markUploaded(blobInfo.blobUri(), url)
  23776. resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url))
  23777. resolve(handlerSuccess(blobInfo, url))
  23778. }
  23779. var failure = function (error, options) {
  23780. var failureOptions = options ? options : {}
  23781. closeNotification_1()
  23782. uploadStatus.removeFailed(blobInfo.blobUri())
  23783. resolvePending(
  23784. blobInfo.blobUri(),
  23785. handlerFailure(blobInfo, error, failureOptions)
  23786. )
  23787. resolve(handlerFailure(blobInfo, error, failureOptions))
  23788. }
  23789. progress = function (percent) {
  23790. if (percent < 0 || percent > 100) {
  23791. return
  23792. }
  23793. Optional.from(notification)
  23794. .orThunk(function () {
  23795. return Optional.from(openNotification).map(apply)
  23796. })
  23797. .each(function (n) {
  23798. notification = n
  23799. n.progressBar.value(percent)
  23800. })
  23801. }
  23802. handler(blobInfo, success, failure, progress)
  23803. } catch (ex) {
  23804. resolve(handlerFailure(blobInfo, ex.message, {}))
  23805. }
  23806. })
  23807. }
  23808. var isDefaultHandler = function (handler) {
  23809. return handler === defaultHandler
  23810. }
  23811. var pendingUploadBlobInfo = function (blobInfo) {
  23812. var blobUri = blobInfo.blobUri()
  23813. return new promiseObj(function (resolve) {
  23814. pendingPromises[blobUri] = pendingPromises[blobUri] || []
  23815. pendingPromises[blobUri].push(resolve)
  23816. })
  23817. }
  23818. var uploadBlobs = function (blobInfos, openNotification) {
  23819. blobInfos = Tools.grep(blobInfos, function (blobInfo) {
  23820. return !uploadStatus.isUploaded(blobInfo.blobUri())
  23821. })
  23822. return promiseObj.all(
  23823. Tools.map(blobInfos, function (blobInfo) {
  23824. return uploadStatus.isPending(blobInfo.blobUri())
  23825. ? pendingUploadBlobInfo(blobInfo)
  23826. : uploadBlobInfo(blobInfo, settings.handler, openNotification)
  23827. })
  23828. )
  23829. }
  23830. var upload = function (blobInfos, openNotification) {
  23831. return !settings.url && isDefaultHandler(settings.handler)
  23832. ? noUpload()
  23833. : uploadBlobs(blobInfos, openNotification)
  23834. }
  23835. if (isFunction(settings.handler) === false) {
  23836. settings.handler = defaultHandler
  23837. }
  23838. return { upload: upload }
  23839. }
  23840. var openNotification = function (editor) {
  23841. return function () {
  23842. return editor.notificationManager.open({
  23843. text: editor.translate('Image uploading...'),
  23844. type: 'info',
  23845. timeout: -1,
  23846. progressBar: true,
  23847. })
  23848. }
  23849. }
  23850. var createUploader = function (editor, uploadStatus) {
  23851. return Uploader(uploadStatus, {
  23852. url: getImageUploadUrl(editor),
  23853. basePath: getImageUploadBasePath(editor),
  23854. credentials: getImagesUploadCredentials(editor),
  23855. handler: getImagesUploadHandler(editor),
  23856. })
  23857. }
  23858. var ImageUploader = function (editor) {
  23859. var uploadStatus = UploadStatus()
  23860. var uploader = createUploader(editor, uploadStatus)
  23861. return {
  23862. upload: function (blobInfos, showNotification) {
  23863. if (showNotification === void 0) {
  23864. showNotification = true
  23865. }
  23866. return uploader.upload(
  23867. blobInfos,
  23868. showNotification ? openNotification(editor) : undefined
  23869. )
  23870. },
  23871. }
  23872. }
  23873. var UploadChangeHandler = function (editor) {
  23874. var lastChangedLevel = Cell(null)
  23875. editor.on('change AddUndo', function (e) {
  23876. lastChangedLevel.set(__assign({}, e.level))
  23877. })
  23878. var fireIfChanged = function () {
  23879. var data = editor.undoManager.data
  23880. last$2(data)
  23881. .filter(function (level) {
  23882. return !isEq$1(lastChangedLevel.get(), level)
  23883. })
  23884. .each(function (level) {
  23885. editor.setDirty(true)
  23886. editor.fire('change', {
  23887. level: level,
  23888. lastLevel: get$a(data, data.length - 2).getOrNull(),
  23889. })
  23890. })
  23891. }
  23892. return { fireIfChanged: fireIfChanged }
  23893. }
  23894. var EditorUpload = function (editor) {
  23895. var blobCache = BlobCache()
  23896. var uploader, imageScanner
  23897. var uploadStatus = UploadStatus()
  23898. var urlFilters = []
  23899. var changeHandler = UploadChangeHandler(editor)
  23900. var aliveGuard = function (callback) {
  23901. return function (result) {
  23902. if (editor.selection) {
  23903. return callback(result)
  23904. }
  23905. return []
  23906. }
  23907. }
  23908. var cacheInvalidator = function (url) {
  23909. return url + (url.indexOf('?') === -1 ? '?' : '&') + new Date().getTime()
  23910. }
  23911. var replaceString = function (content, search, replace) {
  23912. var index = 0
  23913. do {
  23914. index = content.indexOf(search, index)
  23915. if (index !== -1) {
  23916. content =
  23917. content.substring(0, index) +
  23918. replace +
  23919. content.substr(index + search.length)
  23920. index += replace.length - search.length + 1
  23921. }
  23922. } while (index !== -1)
  23923. return content
  23924. }
  23925. var replaceImageUrl = function (content, targetUrl, replacementUrl) {
  23926. var replacementString =
  23927. 'src="' +
  23928. replacementUrl +
  23929. '"' +
  23930. (replacementUrl === Env.transparentSrc
  23931. ? ' data-mce-placeholder="1"'
  23932. : '')
  23933. content = replaceString(
  23934. content,
  23935. 'src="' + targetUrl + '"',
  23936. replacementString
  23937. )
  23938. content = replaceString(
  23939. content,
  23940. 'data-mce-src="' + targetUrl + '"',
  23941. 'data-mce-src="' + replacementUrl + '"'
  23942. )
  23943. return content
  23944. }
  23945. var replaceUrlInUndoStack = function (targetUrl, replacementUrl) {
  23946. each$k(editor.undoManager.data, function (level) {
  23947. if (level.type === 'fragmented') {
  23948. level.fragments = map$3(level.fragments, function (fragment) {
  23949. return replaceImageUrl(fragment, targetUrl, replacementUrl)
  23950. })
  23951. } else {
  23952. level.content = replaceImageUrl(
  23953. level.content,
  23954. targetUrl,
  23955. replacementUrl
  23956. )
  23957. }
  23958. })
  23959. }
  23960. var replaceImageUriInView = function (image, resultUri) {
  23961. var src = editor.convertURL(resultUri, 'src')
  23962. replaceUrlInUndoStack(image.src, resultUri)
  23963. editor.$(image).attr({
  23964. src: shouldReuseFileName(editor)
  23965. ? cacheInvalidator(resultUri)
  23966. : resultUri,
  23967. 'data-mce-src': src,
  23968. })
  23969. }
  23970. var uploadImages = function (callback) {
  23971. if (!uploader) {
  23972. uploader = createUploader(editor, uploadStatus)
  23973. }
  23974. return scanForImages().then(
  23975. aliveGuard(function (imageInfos) {
  23976. var blobInfos = map$3(imageInfos, function (imageInfo) {
  23977. return imageInfo.blobInfo
  23978. })
  23979. return uploader.upload(blobInfos, openNotification(editor)).then(
  23980. aliveGuard(function (result) {
  23981. var imagesToRemove = []
  23982. var filteredResult = map$3(result, function (uploadInfo, index) {
  23983. var blobInfo = imageInfos[index].blobInfo
  23984. var image = imageInfos[index].image
  23985. if (uploadInfo.status && shouldReplaceBlobUris(editor)) {
  23986. blobCache.removeByUri(image.src)
  23987. if (isRtc(editor));
  23988. else {
  23989. replaceImageUriInView(image, uploadInfo.url)
  23990. }
  23991. } else if (uploadInfo.error) {
  23992. if (uploadInfo.error.options.remove) {
  23993. replaceUrlInUndoStack(
  23994. image.getAttribute('src'),
  23995. Env.transparentSrc
  23996. )
  23997. imagesToRemove.push(image)
  23998. }
  23999. uploadError(editor, uploadInfo.error.message)
  24000. }
  24001. return {
  24002. element: image,
  24003. status: uploadInfo.status,
  24004. uploadUri: uploadInfo.url,
  24005. blobInfo: blobInfo,
  24006. }
  24007. })
  24008. if (filteredResult.length > 0) {
  24009. changeHandler.fireIfChanged()
  24010. }
  24011. if (imagesToRemove.length > 0) {
  24012. if (isRtc(editor)) {
  24013. console.error(
  24014. 'Removing images on failed uploads is currently unsupported for RTC'
  24015. )
  24016. } else {
  24017. editor.undoManager.transact(function () {
  24018. each$k(imagesToRemove, function (element) {
  24019. editor.dom.remove(element)
  24020. blobCache.removeByUri(element.src)
  24021. })
  24022. })
  24023. }
  24024. }
  24025. if (callback) {
  24026. callback(filteredResult)
  24027. }
  24028. return filteredResult
  24029. })
  24030. )
  24031. })
  24032. )
  24033. }
  24034. var uploadImagesAuto = function (callback) {
  24035. if (isAutomaticUploadsEnabled(editor)) {
  24036. return uploadImages(callback)
  24037. }
  24038. }
  24039. var isValidDataUriImage = function (imgElm) {
  24040. if (
  24041. forall(urlFilters, function (filter) {
  24042. return filter(imgElm)
  24043. }) === false
  24044. ) {
  24045. return false
  24046. }
  24047. if (imgElm.getAttribute('src').indexOf('data:') === 0) {
  24048. var dataImgFilter = getImagesDataImgFilter(editor)
  24049. return dataImgFilter(imgElm)
  24050. }
  24051. return true
  24052. }
  24053. var addFilter = function (filter) {
  24054. urlFilters.push(filter)
  24055. }
  24056. var scanForImages = function () {
  24057. if (!imageScanner) {
  24058. imageScanner = ImageScanner(uploadStatus, blobCache)
  24059. }
  24060. return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(
  24061. aliveGuard(function (result) {
  24062. result = filter$4(result, function (resultItem) {
  24063. if (typeof resultItem === 'string') {
  24064. displayError(editor, resultItem)
  24065. return false
  24066. }
  24067. return true
  24068. })
  24069. if (isRtc(editor));
  24070. else {
  24071. each$k(result, function (resultItem) {
  24072. replaceUrlInUndoStack(
  24073. resultItem.image.src,
  24074. resultItem.blobInfo.blobUri()
  24075. )
  24076. resultItem.image.src = resultItem.blobInfo.blobUri()
  24077. resultItem.image.removeAttribute('data-mce-src')
  24078. })
  24079. }
  24080. return result
  24081. })
  24082. )
  24083. }
  24084. var destroy = function () {
  24085. blobCache.destroy()
  24086. uploadStatus.destroy()
  24087. imageScanner = uploader = null
  24088. }
  24089. var replaceBlobUris = function (content) {
  24090. return content.replace(/src="(blob:[^"]+)"/g, function (match, blobUri) {
  24091. var resultUri = uploadStatus.getResultUri(blobUri)
  24092. if (resultUri) {
  24093. return 'src="' + resultUri + '"'
  24094. }
  24095. var blobInfo = blobCache.getByUri(blobUri)
  24096. if (!blobInfo) {
  24097. blobInfo = foldl(
  24098. editor.editorManager.get(),
  24099. function (result, editor) {
  24100. return (
  24101. result ||
  24102. (editor.editorUpload &&
  24103. editor.editorUpload.blobCache.getByUri(blobUri))
  24104. )
  24105. },
  24106. null
  24107. )
  24108. }
  24109. if (blobInfo) {
  24110. var blob = blobInfo.blob()
  24111. return 'src="data:' + blob.type + ';base64,' + blobInfo.base64() + '"'
  24112. }
  24113. return match
  24114. })
  24115. }
  24116. editor.on('SetContent', function () {
  24117. if (isAutomaticUploadsEnabled(editor)) {
  24118. uploadImagesAuto()
  24119. } else {
  24120. scanForImages()
  24121. }
  24122. })
  24123. editor.on('RawSaveContent', function (e) {
  24124. e.content = replaceBlobUris(e.content)
  24125. })
  24126. editor.on('GetContent', function (e) {
  24127. if (e.source_view || e.format === 'raw' || e.format === 'tree') {
  24128. return
  24129. }
  24130. e.content = replaceBlobUris(e.content)
  24131. })
  24132. editor.on('PostRender', function () {
  24133. editor.parser.addNodeFilter('img', function (images) {
  24134. each$k(images, function (img) {
  24135. var src = img.attr('src')
  24136. if (blobCache.getByUri(src)) {
  24137. return
  24138. }
  24139. var resultUri = uploadStatus.getResultUri(src)
  24140. if (resultUri) {
  24141. img.attr('src', resultUri)
  24142. }
  24143. })
  24144. })
  24145. })
  24146. return {
  24147. blobCache: blobCache,
  24148. addFilter: addFilter,
  24149. uploadImages: uploadImages,
  24150. uploadImagesAuto: uploadImagesAuto,
  24151. scanForImages: scanForImages,
  24152. destroy: destroy,
  24153. }
  24154. }
  24155. var get = function (dom) {
  24156. var formats = {
  24157. valigntop: [
  24158. {
  24159. selector: 'td,th',
  24160. styles: { verticalAlign: 'top' },
  24161. },
  24162. ],
  24163. valignmiddle: [
  24164. {
  24165. selector: 'td,th',
  24166. styles: { verticalAlign: 'middle' },
  24167. },
  24168. ],
  24169. valignbottom: [
  24170. {
  24171. selector: 'td,th',
  24172. styles: { verticalAlign: 'bottom' },
  24173. },
  24174. ],
  24175. alignleft: [
  24176. {
  24177. selector: 'figure.image',
  24178. collapsed: false,
  24179. classes: 'align-left',
  24180. ceFalseOverride: true,
  24181. preview: 'font-family font-size',
  24182. },
  24183. {
  24184. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24185. styles: { textAlign: 'left' },
  24186. inherit: false,
  24187. preview: false,
  24188. defaultBlock: 'div',
  24189. },
  24190. {
  24191. selector: 'img,table,audio,video',
  24192. collapsed: false,
  24193. styles: { float: 'left' },
  24194. preview: 'font-family font-size',
  24195. },
  24196. ],
  24197. aligncenter: [
  24198. {
  24199. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24200. styles: { textAlign: 'center' },
  24201. inherit: false,
  24202. preview: 'font-family font-size',
  24203. defaultBlock: 'div',
  24204. },
  24205. {
  24206. selector: 'figure.image',
  24207. collapsed: false,
  24208. classes: 'align-center',
  24209. ceFalseOverride: true,
  24210. preview: 'font-family font-size',
  24211. },
  24212. {
  24213. selector: 'img,audio,video',
  24214. collapsed: false,
  24215. styles: {
  24216. display: 'block',
  24217. marginLeft: 'auto',
  24218. marginRight: 'auto',
  24219. },
  24220. preview: false,
  24221. },
  24222. {
  24223. selector: 'table',
  24224. collapsed: false,
  24225. styles: {
  24226. marginLeft: 'auto',
  24227. marginRight: 'auto',
  24228. },
  24229. preview: 'font-family font-size',
  24230. },
  24231. ],
  24232. alignright: [
  24233. {
  24234. selector: 'figure.image',
  24235. collapsed: false,
  24236. classes: 'align-right',
  24237. ceFalseOverride: true,
  24238. preview: 'font-family font-size',
  24239. },
  24240. {
  24241. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24242. styles: { textAlign: 'right' },
  24243. inherit: false,
  24244. preview: 'font-family font-size',
  24245. defaultBlock: 'div',
  24246. },
  24247. {
  24248. selector: 'img,table,audio,video',
  24249. collapsed: false,
  24250. styles: { float: 'right' },
  24251. preview: 'font-family font-size',
  24252. },
  24253. ],
  24254. alignjustify: [
  24255. {
  24256. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  24257. styles: { textAlign: 'justify' },
  24258. inherit: false,
  24259. defaultBlock: 'div',
  24260. preview: 'font-family font-size',
  24261. },
  24262. ],
  24263. bold: [
  24264. {
  24265. inline: 'strong',
  24266. remove: 'all',
  24267. preserve_attributes: ['class', 'style'],
  24268. },
  24269. {
  24270. inline: 'span',
  24271. styles: { fontWeight: 'bold' },
  24272. },
  24273. {
  24274. inline: 'b',
  24275. remove: 'all',
  24276. preserve_attributes: ['class', 'style'],
  24277. },
  24278. ],
  24279. italic: [
  24280. {
  24281. inline: 'em',
  24282. remove: 'all',
  24283. preserve_attributes: ['class', 'style'],
  24284. },
  24285. {
  24286. inline: 'span',
  24287. styles: { fontStyle: 'italic' },
  24288. },
  24289. {
  24290. inline: 'i',
  24291. remove: 'all',
  24292. preserve_attributes: ['class', 'style'],
  24293. },
  24294. ],
  24295. underline: [
  24296. {
  24297. inline: 'span',
  24298. styles: { textDecoration: 'underline' },
  24299. exact: true,
  24300. },
  24301. {
  24302. inline: 'u',
  24303. remove: 'all',
  24304. preserve_attributes: ['class', 'style'],
  24305. },
  24306. ],
  24307. strikethrough: [
  24308. {
  24309. inline: 'span',
  24310. styles: { textDecoration: 'line-through' },
  24311. exact: true,
  24312. },
  24313. {
  24314. inline: 'strike',
  24315. remove: 'all',
  24316. preserve_attributes: ['class', 'style'],
  24317. },
  24318. {
  24319. inline: 's',
  24320. remove: 'all',
  24321. preserve_attributes: ['class', 'style'],
  24322. },
  24323. ],
  24324. forecolor: {
  24325. inline: 'span',
  24326. styles: { color: '%value' },
  24327. links: true,
  24328. remove_similar: true,
  24329. clear_child_styles: true,
  24330. },
  24331. hilitecolor: {
  24332. inline: 'span',
  24333. styles: { backgroundColor: '%value' },
  24334. links: true,
  24335. remove_similar: true,
  24336. clear_child_styles: true,
  24337. },
  24338. fontname: {
  24339. inline: 'span',
  24340. toggle: false,
  24341. styles: { fontFamily: '%value' },
  24342. clear_child_styles: true,
  24343. },
  24344. fontsize: {
  24345. inline: 'span',
  24346. toggle: false,
  24347. styles: { fontSize: '%value' },
  24348. clear_child_styles: true,
  24349. },
  24350. lineheight: {
  24351. selector: 'h1,h2,h3,h4,h5,h6,p,li,td,th,div',
  24352. defaultBlock: 'p',
  24353. styles: { lineHeight: '%value' },
  24354. },
  24355. fontsize_class: {
  24356. inline: 'span',
  24357. attributes: { class: '%value' },
  24358. },
  24359. blockquote: {
  24360. block: 'blockquote',
  24361. wrapper: true,
  24362. remove: 'all',
  24363. },
  24364. subscript: { inline: 'sub' },
  24365. superscript: { inline: 'sup' },
  24366. code: { inline: 'code' },
  24367. link: {
  24368. inline: 'a',
  24369. selector: 'a',
  24370. remove: 'all',
  24371. split: true,
  24372. deep: true,
  24373. onmatch: function (node, _fmt, _itemName) {
  24374. return isElement$5(node) && node.hasAttribute('href')
  24375. },
  24376. onformat: function (elm, _fmt, vars) {
  24377. Tools.each(vars, function (value, key) {
  24378. dom.setAttrib(elm, key, value)
  24379. })
  24380. },
  24381. },
  24382. lang: {
  24383. inline: 'span',
  24384. clear_child_styles: true,
  24385. remove_similar: true,
  24386. attributes: {
  24387. lang: '%value',
  24388. 'data-mce-lang': function (vars) {
  24389. var _a
  24390. return (_a =
  24391. vars === null || vars === void 0 ? void 0 : vars.customValue) !==
  24392. null && _a !== void 0
  24393. ? _a
  24394. : null
  24395. },
  24396. },
  24397. },
  24398. removeformat: [
  24399. {
  24400. selector:
  24401. 'b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,small',
  24402. remove: 'all',
  24403. split: true,
  24404. expand: false,
  24405. block_expand: true,
  24406. deep: true,
  24407. },
  24408. {
  24409. selector: 'span',
  24410. attributes: ['style', 'class'],
  24411. remove: 'empty',
  24412. split: true,
  24413. expand: false,
  24414. deep: true,
  24415. },
  24416. {
  24417. selector: '*',
  24418. attributes: ['style', 'class'],
  24419. split: false,
  24420. expand: false,
  24421. deep: true,
  24422. },
  24423. ],
  24424. }
  24425. Tools.each(
  24426. 'p h1 h2 h3 h4 h5 h6 div address pre dt dd samp'.split(/\s/),
  24427. function (name) {
  24428. formats[name] = {
  24429. block: name,
  24430. remove: 'all',
  24431. }
  24432. }
  24433. )
  24434. return formats
  24435. }
  24436. var FormatRegistry = function (editor) {
  24437. var formats = {}
  24438. var get$1 = function (name) {
  24439. return isNonNullable(name) ? formats[name] : formats
  24440. }
  24441. var has = function (name) {
  24442. return has$2(formats, name)
  24443. }
  24444. var register = function (name, format) {
  24445. if (name) {
  24446. if (!isString$1(name)) {
  24447. each$j(name, function (format, name) {
  24448. register(name, format)
  24449. })
  24450. } else {
  24451. if (!isArray$1(format)) {
  24452. format = [format]
  24453. }
  24454. each$k(format, function (format) {
  24455. if (isUndefined(format.deep)) {
  24456. format.deep = !isSelectorFormat(format)
  24457. }
  24458. if (isUndefined(format.split)) {
  24459. format.split = !isSelectorFormat(format) || isInlineFormat(format)
  24460. }
  24461. if (
  24462. isUndefined(format.remove) &&
  24463. isSelectorFormat(format) &&
  24464. !isInlineFormat(format)
  24465. ) {
  24466. format.remove = 'none'
  24467. }
  24468. if (isSelectorFormat(format) && isInlineFormat(format)) {
  24469. format.mixed = true
  24470. format.block_expand = true
  24471. }
  24472. if (isString$1(format.classes)) {
  24473. format.classes = format.classes.split(/\s+/)
  24474. }
  24475. })
  24476. formats[name] = format
  24477. }
  24478. }
  24479. }
  24480. var unregister = function (name) {
  24481. if (name && formats[name]) {
  24482. delete formats[name]
  24483. }
  24484. return formats
  24485. }
  24486. register(get(editor.dom))
  24487. register(getFormats(editor))
  24488. return {
  24489. get: get$1,
  24490. has: has,
  24491. register: register,
  24492. unregister: unregister,
  24493. }
  24494. }
  24495. var each$5 = Tools.each
  24496. var dom = DOMUtils.DOM
  24497. var parsedSelectorToHtml = function (ancestry, editor) {
  24498. var elm, item, fragment
  24499. var schema = (editor && editor.schema) || Schema({})
  24500. var decorate = function (elm, item) {
  24501. if (item.classes.length) {
  24502. dom.addClass(elm, item.classes.join(' '))
  24503. }
  24504. dom.setAttribs(elm, item.attrs)
  24505. }
  24506. var createElement = function (sItem) {
  24507. item =
  24508. typeof sItem === 'string'
  24509. ? {
  24510. name: sItem,
  24511. classes: [],
  24512. attrs: {},
  24513. }
  24514. : sItem
  24515. var elm = dom.create(item.name)
  24516. decorate(elm, item)
  24517. return elm
  24518. }
  24519. var getRequiredParent = function (elm, candidate) {
  24520. var name = typeof elm !== 'string' ? elm.nodeName.toLowerCase() : elm
  24521. var elmRule = schema.getElementRule(name)
  24522. var parentsRequired = elmRule && elmRule.parentsRequired
  24523. if (parentsRequired && parentsRequired.length) {
  24524. return candidate && Tools.inArray(parentsRequired, candidate) !== -1
  24525. ? candidate
  24526. : parentsRequired[0]
  24527. } else {
  24528. return false
  24529. }
  24530. }
  24531. var wrapInHtml = function (elm, ancestry, siblings) {
  24532. var parent, parentCandidate
  24533. var ancestor = ancestry.length > 0 && ancestry[0]
  24534. var ancestorName = ancestor && ancestor.name
  24535. var parentRequired = getRequiredParent(elm, ancestorName)
  24536. if (parentRequired) {
  24537. if (ancestorName === parentRequired) {
  24538. parentCandidate = ancestry[0]
  24539. ancestry = ancestry.slice(1)
  24540. } else {
  24541. parentCandidate = parentRequired
  24542. }
  24543. } else if (ancestor) {
  24544. parentCandidate = ancestry[0]
  24545. ancestry = ancestry.slice(1)
  24546. } else if (!siblings) {
  24547. return elm
  24548. }
  24549. if (parentCandidate) {
  24550. parent = createElement(parentCandidate)
  24551. parent.appendChild(elm)
  24552. }
  24553. if (siblings) {
  24554. if (!parent) {
  24555. parent = dom.create('div')
  24556. parent.appendChild(elm)
  24557. }
  24558. Tools.each(siblings, function (sibling) {
  24559. var siblingElm = createElement(sibling)
  24560. parent.insertBefore(siblingElm, elm)
  24561. })
  24562. }
  24563. return wrapInHtml(
  24564. parent,
  24565. ancestry,
  24566. parentCandidate && parentCandidate.siblings
  24567. )
  24568. }
  24569. if (ancestry && ancestry.length) {
  24570. item = ancestry[0]
  24571. elm = createElement(item)
  24572. fragment = dom.create('div')
  24573. fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings))
  24574. return fragment
  24575. } else {
  24576. return ''
  24577. }
  24578. }
  24579. var parseSelectorItem = function (item) {
  24580. var tagName
  24581. var obj = {
  24582. classes: [],
  24583. attrs: {},
  24584. }
  24585. item = obj.selector = Tools.trim(item)
  24586. if (item !== '*') {
  24587. tagName = item.replace(
  24588. /(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g,
  24589. function ($0, $1, $2, $3, $4) {
  24590. switch ($1) {
  24591. case '#':
  24592. obj.attrs.id = $2
  24593. break
  24594. case '.':
  24595. obj.classes.push($2)
  24596. break
  24597. case ':':
  24598. if (
  24599. Tools.inArray(
  24600. 'checked disabled enabled read-only required'.split(' '),
  24601. $2
  24602. ) !== -1
  24603. ) {
  24604. obj.attrs[$2] = $2
  24605. }
  24606. break
  24607. }
  24608. if ($3 === '[') {
  24609. var m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/)
  24610. if (m) {
  24611. obj.attrs[m[1]] = m[2]
  24612. }
  24613. }
  24614. return ''
  24615. }
  24616. )
  24617. }
  24618. obj.name = tagName || 'div'
  24619. return obj
  24620. }
  24621. var parseSelector = function (selector) {
  24622. if (!selector || typeof selector !== 'string') {
  24623. return []
  24624. }
  24625. selector = selector.split(/\s*,\s*/)[0]
  24626. selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, '$1')
  24627. return Tools.map(
  24628. selector.split(/(?:>|\s+(?![^\[\]]+\]))/),
  24629. function (item) {
  24630. var siblings = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem)
  24631. var obj = siblings.pop()
  24632. if (siblings.length) {
  24633. obj.siblings = siblings
  24634. }
  24635. return obj
  24636. }
  24637. ).reverse()
  24638. }
  24639. var getCssText = function (editor, format) {
  24640. var name, previewFrag
  24641. var previewCss = '',
  24642. parentFontSize
  24643. var previewStyles = getPreviewStyles(editor)
  24644. if (previewStyles === '') {
  24645. return ''
  24646. }
  24647. var removeVars = function (val) {
  24648. return val.replace(/%(\w+)/g, '')
  24649. }
  24650. if (typeof format === 'string') {
  24651. format = editor.formatter.get(format)
  24652. if (!format) {
  24653. return
  24654. }
  24655. format = format[0]
  24656. }
  24657. if ('preview' in format) {
  24658. var previewOpt = get$9(format, 'preview')
  24659. if (is$1(previewOpt, false)) {
  24660. return ''
  24661. } else {
  24662. previewStyles = previewOpt.getOr(previewStyles)
  24663. }
  24664. }
  24665. name = format.block || format.inline || 'span'
  24666. var items = parseSelector(format.selector)
  24667. if (items.length) {
  24668. if (!items[0].name) {
  24669. items[0].name = name
  24670. }
  24671. name = format.selector
  24672. previewFrag = parsedSelectorToHtml(items, editor)
  24673. } else {
  24674. previewFrag = parsedSelectorToHtml([name], editor)
  24675. }
  24676. var previewElm = dom.select(name, previewFrag)[0] || previewFrag.firstChild
  24677. each$5(format.styles, function (value, name) {
  24678. var newValue = removeVars(value)
  24679. if (newValue) {
  24680. dom.setStyle(previewElm, name, newValue)
  24681. }
  24682. })
  24683. each$5(format.attributes, function (value, name) {
  24684. var newValue = removeVars(value)
  24685. if (newValue) {
  24686. dom.setAttrib(previewElm, name, newValue)
  24687. }
  24688. })
  24689. each$5(format.classes, function (value) {
  24690. var newValue = removeVars(value)
  24691. if (!dom.hasClass(previewElm, newValue)) {
  24692. dom.addClass(previewElm, newValue)
  24693. }
  24694. })
  24695. editor.fire('PreviewFormats')
  24696. dom.setStyles(previewFrag, {
  24697. position: 'absolute',
  24698. left: -65535,
  24699. })
  24700. editor.getBody().appendChild(previewFrag)
  24701. parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true)
  24702. parentFontSize = /px$/.test(parentFontSize)
  24703. ? parseInt(parentFontSize, 10)
  24704. : 0
  24705. each$5(previewStyles.split(' '), function (name) {
  24706. var value = dom.getStyle(previewElm, name, true)
  24707. if (
  24708. name === 'background-color' &&
  24709. /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)
  24710. ) {
  24711. value = dom.getStyle(editor.getBody(), name, true)
  24712. if (dom.toHex(value).toLowerCase() === '#ffffff') {
  24713. return
  24714. }
  24715. }
  24716. if (name === 'color') {
  24717. if (dom.toHex(value).toLowerCase() === '#000000') {
  24718. return
  24719. }
  24720. }
  24721. if (name === 'font-size') {
  24722. if (/em|%$/.test(value)) {
  24723. if (parentFontSize === 0) {
  24724. return
  24725. }
  24726. var numValue = parseFloat(value) / (/%$/.test(value) ? 100 : 1)
  24727. value = numValue * parentFontSize + 'px'
  24728. }
  24729. }
  24730. if (name === 'border' && value) {
  24731. previewCss += 'padding:0 2px;'
  24732. }
  24733. previewCss += name + ':' + value + ';'
  24734. })
  24735. editor.fire('AfterPreviewFormats')
  24736. dom.remove(previewFrag)
  24737. return previewCss
  24738. }
  24739. var setup$h = function (editor) {
  24740. editor.addShortcut('meta+b', '', 'Bold')
  24741. editor.addShortcut('meta+i', '', 'Italic')
  24742. editor.addShortcut('meta+u', '', 'Underline')
  24743. for (var i = 1; i <= 6; i++) {
  24744. editor.addShortcut('access+' + i, '', ['FormatBlock', false, 'h' + i])
  24745. }
  24746. editor.addShortcut('access+7', '', ['FormatBlock', false, 'p'])
  24747. editor.addShortcut('access+8', '', ['FormatBlock', false, 'div'])
  24748. editor.addShortcut('access+9', '', ['FormatBlock', false, 'address'])
  24749. }
  24750. var Formatter = function (editor) {
  24751. var formats = FormatRegistry(editor)
  24752. var formatChangeState = Cell(null)
  24753. setup$h(editor)
  24754. setup$k(editor)
  24755. return {
  24756. get: formats.get,
  24757. has: formats.has,
  24758. register: formats.register,
  24759. unregister: formats.unregister,
  24760. apply: function (name, vars, node) {
  24761. applyFormat(editor, name, vars, node)
  24762. },
  24763. remove: function (name, vars, node, similar) {
  24764. removeFormat(editor, name, vars, node, similar)
  24765. },
  24766. toggle: function (name, vars, node) {
  24767. toggleFormat(editor, name, vars, node)
  24768. },
  24769. match: function (name, vars, node, similar) {
  24770. return matchFormat(editor, name, vars, node, similar)
  24771. },
  24772. closest: function (names) {
  24773. return closestFormat(editor, names)
  24774. },
  24775. matchAll: function (names, vars) {
  24776. return matchAllFormats(editor, names, vars)
  24777. },
  24778. matchNode: function (node, name, vars, similar) {
  24779. return matchNodeFormat(editor, node, name, vars, similar)
  24780. },
  24781. canApply: function (name) {
  24782. return canApplyFormat(editor, name)
  24783. },
  24784. formatChanged: function (formats, callback, similar, vars) {
  24785. return formatChanged(
  24786. editor,
  24787. formatChangeState,
  24788. formats,
  24789. callback,
  24790. similar,
  24791. vars
  24792. )
  24793. },
  24794. getCssText: curry(getCssText, editor),
  24795. }
  24796. }
  24797. var shouldIgnoreCommand = function (cmd) {
  24798. switch (cmd.toLowerCase()) {
  24799. case 'undo':
  24800. case 'redo':
  24801. case 'mcerepaint':
  24802. case 'mcefocus':
  24803. return true
  24804. default:
  24805. return false
  24806. }
  24807. }
  24808. var registerEvents = function (editor, undoManager, locks) {
  24809. var isFirstTypedCharacter = Cell(false)
  24810. var addNonTypingUndoLevel = function (e) {
  24811. setTyping(undoManager, false, locks)
  24812. undoManager.add({}, e)
  24813. }
  24814. editor.on('init', function () {
  24815. undoManager.add()
  24816. })
  24817. editor.on('BeforeExecCommand', function (e) {
  24818. var cmd = e.command
  24819. if (!shouldIgnoreCommand(cmd)) {
  24820. endTyping(undoManager, locks)
  24821. undoManager.beforeChange()
  24822. }
  24823. })
  24824. editor.on('ExecCommand', function (e) {
  24825. var cmd = e.command
  24826. if (!shouldIgnoreCommand(cmd)) {
  24827. addNonTypingUndoLevel(e)
  24828. }
  24829. })
  24830. editor.on('ObjectResizeStart cut', function () {
  24831. undoManager.beforeChange()
  24832. })
  24833. editor.on('SaveContent ObjectResized blur', addNonTypingUndoLevel)
  24834. editor.on('dragend', addNonTypingUndoLevel)
  24835. editor.on('keyup', function (e) {
  24836. var keyCode = e.keyCode
  24837. if (e.isDefaultPrevented()) {
  24838. return
  24839. }
  24840. if (
  24841. (keyCode >= 33 && keyCode <= 36) ||
  24842. (keyCode >= 37 && keyCode <= 40) ||
  24843. keyCode === 45 ||
  24844. e.ctrlKey
  24845. ) {
  24846. addNonTypingUndoLevel()
  24847. editor.nodeChanged()
  24848. }
  24849. if (keyCode === 46 || keyCode === 8) {
  24850. editor.nodeChanged()
  24851. }
  24852. if (
  24853. isFirstTypedCharacter.get() &&
  24854. undoManager.typing &&
  24855. isEq$1(createFromEditor(editor), undoManager.data[0]) === false
  24856. ) {
  24857. if (editor.isDirty() === false) {
  24858. editor.setDirty(true)
  24859. editor.fire('change', {
  24860. level: undoManager.data[0],
  24861. lastLevel: null,
  24862. })
  24863. }
  24864. editor.fire('TypingUndo')
  24865. isFirstTypedCharacter.set(false)
  24866. editor.nodeChanged()
  24867. }
  24868. })
  24869. editor.on('keydown', function (e) {
  24870. var keyCode = e.keyCode
  24871. if (e.isDefaultPrevented()) {
  24872. return
  24873. }
  24874. if (
  24875. (keyCode >= 33 && keyCode <= 36) ||
  24876. (keyCode >= 37 && keyCode <= 40) ||
  24877. keyCode === 45
  24878. ) {
  24879. if (undoManager.typing) {
  24880. addNonTypingUndoLevel(e)
  24881. }
  24882. return
  24883. }
  24884. var modKey = (e.ctrlKey && !e.altKey) || e.metaKey
  24885. if (
  24886. (keyCode < 16 || keyCode > 20) &&
  24887. keyCode !== 224 &&
  24888. keyCode !== 91 &&
  24889. !undoManager.typing &&
  24890. !modKey
  24891. ) {
  24892. undoManager.beforeChange()
  24893. setTyping(undoManager, true, locks)
  24894. undoManager.add({}, e)
  24895. isFirstTypedCharacter.set(true)
  24896. }
  24897. })
  24898. editor.on('mousedown', function (e) {
  24899. if (undoManager.typing) {
  24900. addNonTypingUndoLevel(e)
  24901. }
  24902. })
  24903. var isInsertReplacementText = function (event) {
  24904. return event.inputType === 'insertReplacementText'
  24905. }
  24906. var isInsertTextDataNull = function (event) {
  24907. return event.inputType === 'insertText' && event.data === null
  24908. }
  24909. var isInsertFromPasteOrDrop = function (event) {
  24910. return (
  24911. event.inputType === 'insertFromPaste' ||
  24912. event.inputType === 'insertFromDrop'
  24913. )
  24914. }
  24915. editor.on('input', function (e) {
  24916. if (
  24917. e.inputType &&
  24918. (isInsertReplacementText(e) ||
  24919. isInsertTextDataNull(e) ||
  24920. isInsertFromPasteOrDrop(e))
  24921. ) {
  24922. addNonTypingUndoLevel(e)
  24923. }
  24924. })
  24925. editor.on('AddUndo Undo Redo ClearUndos', function (e) {
  24926. if (!e.isDefaultPrevented()) {
  24927. editor.nodeChanged()
  24928. }
  24929. })
  24930. }
  24931. var addKeyboardShortcuts = function (editor) {
  24932. editor.addShortcut('meta+z', '', 'Undo')
  24933. editor.addShortcut('meta+y,meta+shift+z', '', 'Redo')
  24934. }
  24935. var UndoManager = function (editor) {
  24936. var beforeBookmark = value()
  24937. var locks = Cell(0)
  24938. var index = Cell(0)
  24939. var undoManager = {
  24940. data: [],
  24941. typing: false,
  24942. beforeChange: function () {
  24943. beforeChange(editor, locks, beforeBookmark)
  24944. },
  24945. add: function (level, event) {
  24946. return addUndoLevel(
  24947. editor,
  24948. undoManager,
  24949. index,
  24950. locks,
  24951. beforeBookmark,
  24952. level,
  24953. event
  24954. )
  24955. },
  24956. undo: function () {
  24957. return undo(editor, undoManager, locks, index)
  24958. },
  24959. redo: function () {
  24960. return redo(editor, index, undoManager.data)
  24961. },
  24962. clear: function () {
  24963. clear(editor, undoManager, index)
  24964. },
  24965. reset: function () {
  24966. reset(editor, undoManager)
  24967. },
  24968. hasUndo: function () {
  24969. return hasUndo(editor, undoManager, index)
  24970. },
  24971. hasRedo: function () {
  24972. return hasRedo(editor, undoManager, index)
  24973. },
  24974. transact: function (callback) {
  24975. return transact(editor, undoManager, locks, callback)
  24976. },
  24977. ignore: function (callback) {
  24978. ignore(editor, locks, callback)
  24979. },
  24980. extra: function (callback1, callback2) {
  24981. extra(editor, undoManager, index, callback1, callback2)
  24982. },
  24983. }
  24984. if (!isRtc(editor)) {
  24985. registerEvents(editor, undoManager, locks)
  24986. }
  24987. addKeyboardShortcuts(editor)
  24988. return undoManager
  24989. }
  24990. var nonTypingKeycodes = [
  24991. 9,
  24992. 27,
  24993. VK.HOME,
  24994. VK.END,
  24995. 19,
  24996. 20,
  24997. 44,
  24998. 144,
  24999. 145,
  25000. 33,
  25001. 34,
  25002. 45,
  25003. 16,
  25004. 17,
  25005. 18,
  25006. 91,
  25007. 92,
  25008. 93,
  25009. VK.DOWN,
  25010. VK.UP,
  25011. VK.LEFT,
  25012. VK.RIGHT,
  25013. ].concat(Env.browser.isFirefox() ? [224] : [])
  25014. var placeholderAttr = 'data-mce-placeholder'
  25015. var isKeyboardEvent = function (e) {
  25016. return e.type === 'keydown' || e.type === 'keyup'
  25017. }
  25018. var isDeleteEvent = function (e) {
  25019. var keyCode = e.keyCode
  25020. return keyCode === VK.BACKSPACE || keyCode === VK.DELETE
  25021. }
  25022. var isNonTypingKeyboardEvent = function (e) {
  25023. if (isKeyboardEvent(e)) {
  25024. var keyCode = e.keyCode
  25025. return (
  25026. !isDeleteEvent(e) &&
  25027. (VK.metaKeyPressed(e) ||
  25028. e.altKey ||
  25029. (keyCode >= 112 && keyCode <= 123) ||
  25030. contains$3(nonTypingKeycodes, keyCode))
  25031. )
  25032. } else {
  25033. return false
  25034. }
  25035. }
  25036. var isTypingKeyboardEvent = function (e) {
  25037. return (
  25038. isKeyboardEvent(e) &&
  25039. !(isDeleteEvent(e) || (e.type === 'keyup' && e.keyCode === 229))
  25040. )
  25041. }
  25042. var isVisuallyEmpty = function (dom, rootElm, forcedRootBlock) {
  25043. if (isEmpty$2(SugarElement.fromDom(rootElm), false)) {
  25044. var isForcedRootBlockFalse = forcedRootBlock === ''
  25045. var firstElement = rootElm.firstElementChild
  25046. if (!firstElement) {
  25047. return true
  25048. } else if (
  25049. dom.getStyle(rootElm.firstElementChild, 'padding-left') ||
  25050. dom.getStyle(rootElm.firstElementChild, 'padding-right')
  25051. ) {
  25052. return false
  25053. } else {
  25054. return isForcedRootBlockFalse
  25055. ? !dom.isBlock(firstElement)
  25056. : forcedRootBlock === firstElement.nodeName.toLowerCase()
  25057. }
  25058. } else {
  25059. return false
  25060. }
  25061. }
  25062. var setup$g = function (editor) {
  25063. var dom = editor.dom
  25064. var rootBlock = getForcedRootBlock(editor)
  25065. var placeholder = getPlaceholder(editor)
  25066. var updatePlaceholder = function (e, initial) {
  25067. if (isNonTypingKeyboardEvent(e)) {
  25068. return
  25069. }
  25070. var body = editor.getBody()
  25071. var showPlaceholder = isTypingKeyboardEvent(e)
  25072. ? false
  25073. : isVisuallyEmpty(dom, body, rootBlock)
  25074. var isPlaceholderShown = dom.getAttrib(body, placeholderAttr) !== ''
  25075. if (isPlaceholderShown !== showPlaceholder || initial) {
  25076. dom.setAttrib(
  25077. body,
  25078. placeholderAttr,
  25079. showPlaceholder ? placeholder : null
  25080. )
  25081. dom.setAttrib(
  25082. body,
  25083. 'aria-placeholder',
  25084. showPlaceholder ? placeholder : null
  25085. )
  25086. firePlaceholderToggle(editor, showPlaceholder)
  25087. editor.on(showPlaceholder ? 'keydown' : 'keyup', updatePlaceholder)
  25088. editor.off(showPlaceholder ? 'keyup' : 'keydown', updatePlaceholder)
  25089. }
  25090. }
  25091. if (placeholder) {
  25092. editor.on('init', function (e) {
  25093. updatePlaceholder(e, true)
  25094. editor.on('change SetContent ExecCommand', updatePlaceholder)
  25095. editor.on('paste', function (e) {
  25096. return Delay.setEditorTimeout(editor, function () {
  25097. return updatePlaceholder(e)
  25098. })
  25099. })
  25100. })
  25101. }
  25102. }
  25103. var strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/
  25104. var hasStrongRtl = function (text) {
  25105. return strongRtl.test(text)
  25106. }
  25107. var isInlineTarget = function (editor, elm) {
  25108. return is$2(SugarElement.fromDom(elm), getInlineBoundarySelector(editor))
  25109. }
  25110. var isRtl = function (element) {
  25111. return (
  25112. DOMUtils.DOM.getStyle(element, 'direction', true) === 'rtl' ||
  25113. hasStrongRtl(element.textContent)
  25114. )
  25115. }
  25116. var findInlineParents = function (isInlineTarget, rootNode, pos) {
  25117. return filter$4(
  25118. DOMUtils.DOM.getParents(pos.container(), '*', rootNode),
  25119. isInlineTarget
  25120. )
  25121. }
  25122. var findRootInline = function (isInlineTarget, rootNode, pos) {
  25123. var parents = findInlineParents(isInlineTarget, rootNode, pos)
  25124. return Optional.from(parents[parents.length - 1])
  25125. }
  25126. var hasSameParentBlock = function (rootNode, node1, node2) {
  25127. var block1 = getParentBlock$2(node1, rootNode)
  25128. var block2 = getParentBlock$2(node2, rootNode)
  25129. return block1 && block1 === block2
  25130. }
  25131. var isAtZwsp = function (pos) {
  25132. return isBeforeInline(pos) || isAfterInline(pos)
  25133. }
  25134. var normalizePosition = function (forward, pos) {
  25135. if (!pos) {
  25136. return pos
  25137. }
  25138. var container = pos.container(),
  25139. offset = pos.offset()
  25140. if (forward) {
  25141. if (isCaretContainerInline(container)) {
  25142. if (isText$7(container.nextSibling)) {
  25143. return CaretPosition(container.nextSibling, 0)
  25144. } else {
  25145. return CaretPosition.after(container)
  25146. }
  25147. } else {
  25148. return isBeforeInline(pos) ? CaretPosition(container, offset + 1) : pos
  25149. }
  25150. } else {
  25151. if (isCaretContainerInline(container)) {
  25152. if (isText$7(container.previousSibling)) {
  25153. return CaretPosition(
  25154. container.previousSibling,
  25155. container.previousSibling.data.length
  25156. )
  25157. } else {
  25158. return CaretPosition.before(container)
  25159. }
  25160. } else {
  25161. return isAfterInline(pos) ? CaretPosition(container, offset - 1) : pos
  25162. }
  25163. }
  25164. }
  25165. var normalizeForwards = curry(normalizePosition, true)
  25166. var normalizeBackwards = curry(normalizePosition, false)
  25167. var isBeforeRoot = function (rootNode) {
  25168. return function (elm) {
  25169. return eq(rootNode, SugarElement.fromDom(elm.dom.parentNode))
  25170. }
  25171. }
  25172. var isTextBlockOrListItem = function (element) {
  25173. return isTextBlock$2(element) || isListItem(element)
  25174. }
  25175. var getParentBlock$1 = function (rootNode, elm) {
  25176. if (contains$1(rootNode, elm)) {
  25177. return closest$3(elm, isTextBlockOrListItem, isBeforeRoot(rootNode))
  25178. } else {
  25179. return Optional.none()
  25180. }
  25181. }
  25182. var placeCaretInEmptyBody = function (editor) {
  25183. var body = editor.getBody()
  25184. var node =
  25185. body.firstChild && editor.dom.isBlock(body.firstChild)
  25186. ? body.firstChild
  25187. : body
  25188. editor.selection.setCursorLocation(node, 0)
  25189. }
  25190. var paddEmptyBody = function (editor) {
  25191. if (editor.dom.isEmpty(editor.getBody())) {
  25192. editor.setContent('')
  25193. placeCaretInEmptyBody(editor)
  25194. }
  25195. }
  25196. var willDeleteLastPositionInElement = function (forward, fromPos, elm) {
  25197. return lift2(
  25198. firstPositionIn(elm),
  25199. lastPositionIn(elm),
  25200. function (firstPos, lastPos) {
  25201. var normalizedFirstPos = normalizePosition(true, firstPos)
  25202. var normalizedLastPos = normalizePosition(false, lastPos)
  25203. var normalizedFromPos = normalizePosition(false, fromPos)
  25204. if (forward) {
  25205. return nextPosition(elm, normalizedFromPos).exists(function (
  25206. nextPos
  25207. ) {
  25208. return (
  25209. nextPos.isEqual(normalizedLastPos) &&
  25210. fromPos.isEqual(normalizedFirstPos)
  25211. )
  25212. })
  25213. } else {
  25214. return prevPosition(elm, normalizedFromPos).exists(function (
  25215. prevPos
  25216. ) {
  25217. return (
  25218. prevPos.isEqual(normalizedFirstPos) &&
  25219. fromPos.isEqual(normalizedLastPos)
  25220. )
  25221. })
  25222. }
  25223. }
  25224. ).getOr(true)
  25225. }
  25226. var blockPosition = function (block, position) {
  25227. return {
  25228. block: block,
  25229. position: position,
  25230. }
  25231. }
  25232. var blockBoundary = function (from, to) {
  25233. return {
  25234. from: from,
  25235. to: to,
  25236. }
  25237. }
  25238. var getBlockPosition = function (rootNode, pos) {
  25239. var rootElm = SugarElement.fromDom(rootNode)
  25240. var containerElm = SugarElement.fromDom(pos.container())
  25241. return getParentBlock$1(rootElm, containerElm).map(function (block) {
  25242. return blockPosition(block, pos)
  25243. })
  25244. }
  25245. var isDifferentBlocks = function (blockBoundary) {
  25246. return eq(blockBoundary.from.block, blockBoundary.to.block) === false
  25247. }
  25248. var hasSameParent = function (blockBoundary) {
  25249. return parent(blockBoundary.from.block)
  25250. .bind(function (parent1) {
  25251. return parent(blockBoundary.to.block).filter(function (parent2) {
  25252. return eq(parent1, parent2)
  25253. })
  25254. })
  25255. .isSome()
  25256. }
  25257. var isEditable$1 = function (blockBoundary) {
  25258. return (
  25259. isContentEditableFalse$b(blockBoundary.from.block.dom) === false &&
  25260. isContentEditableFalse$b(blockBoundary.to.block.dom) === false
  25261. )
  25262. }
  25263. var skipLastBr = function (rootNode, forward, blockPosition) {
  25264. if (
  25265. isBr$5(blockPosition.position.getNode()) &&
  25266. isEmpty$2(blockPosition.block) === false
  25267. ) {
  25268. return positionIn(false, blockPosition.block.dom)
  25269. .bind(function (lastPositionInBlock) {
  25270. if (lastPositionInBlock.isEqual(blockPosition.position)) {
  25271. return fromPosition(forward, rootNode, lastPositionInBlock).bind(
  25272. function (to) {
  25273. return getBlockPosition(rootNode, to)
  25274. }
  25275. )
  25276. } else {
  25277. return Optional.some(blockPosition)
  25278. }
  25279. })
  25280. .getOr(blockPosition)
  25281. } else {
  25282. return blockPosition
  25283. }
  25284. }
  25285. var readFromRange = function (rootNode, forward, rng) {
  25286. var fromBlockPos = getBlockPosition(
  25287. rootNode,
  25288. CaretPosition.fromRangeStart(rng)
  25289. )
  25290. var toBlockPos = fromBlockPos.bind(function (blockPos) {
  25291. return fromPosition(forward, rootNode, blockPos.position).bind(function (
  25292. to
  25293. ) {
  25294. return getBlockPosition(rootNode, to).map(function (blockPos) {
  25295. return skipLastBr(rootNode, forward, blockPos)
  25296. })
  25297. })
  25298. })
  25299. return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(function (
  25300. blockBoundary
  25301. ) {
  25302. return (
  25303. isDifferentBlocks(blockBoundary) &&
  25304. hasSameParent(blockBoundary) &&
  25305. isEditable$1(blockBoundary)
  25306. )
  25307. })
  25308. }
  25309. var read$1 = function (rootNode, forward, rng) {
  25310. return rng.collapsed
  25311. ? readFromRange(rootNode, forward, rng)
  25312. : Optional.none()
  25313. }
  25314. var getChildrenUntilBlockBoundary = function (block) {
  25315. var children$1 = children(block)
  25316. return findIndex$2(children$1, isBlock$2).fold(
  25317. constant(children$1),
  25318. function (index) {
  25319. return children$1.slice(0, index)
  25320. }
  25321. )
  25322. }
  25323. var extractChildren = function (block) {
  25324. var children = getChildrenUntilBlockBoundary(block)
  25325. each$k(children, remove$7)
  25326. return children
  25327. }
  25328. var removeEmptyRoot = function (rootNode, block) {
  25329. var parents = parentsAndSelf(block, rootNode)
  25330. return find$3(parents.reverse(), function (element) {
  25331. return isEmpty$2(element)
  25332. }).each(remove$7)
  25333. }
  25334. var isEmptyBefore = function (el) {
  25335. return (
  25336. filter$4(prevSiblings(el), function (el) {
  25337. return !isEmpty$2(el)
  25338. }).length === 0
  25339. )
  25340. }
  25341. var nestedBlockMerge = function (
  25342. rootNode,
  25343. fromBlock,
  25344. toBlock,
  25345. insertionPoint
  25346. ) {
  25347. if (isEmpty$2(toBlock)) {
  25348. fillWithPaddingBr(toBlock)
  25349. return firstPositionIn(toBlock.dom)
  25350. }
  25351. if (isEmptyBefore(insertionPoint) && isEmpty$2(fromBlock)) {
  25352. before$4(insertionPoint, SugarElement.fromTag('br'))
  25353. }
  25354. var position = prevPosition(
  25355. toBlock.dom,
  25356. CaretPosition.before(insertionPoint.dom)
  25357. )
  25358. each$k(extractChildren(fromBlock), function (child) {
  25359. before$4(insertionPoint, child)
  25360. })
  25361. removeEmptyRoot(rootNode, fromBlock)
  25362. return position
  25363. }
  25364. var sidelongBlockMerge = function (rootNode, fromBlock, toBlock) {
  25365. if (isEmpty$2(toBlock)) {
  25366. remove$7(toBlock)
  25367. if (isEmpty$2(fromBlock)) {
  25368. fillWithPaddingBr(fromBlock)
  25369. }
  25370. return firstPositionIn(fromBlock.dom)
  25371. }
  25372. var position = lastPositionIn(toBlock.dom)
  25373. each$k(extractChildren(fromBlock), function (child) {
  25374. append$1(toBlock, child)
  25375. })
  25376. removeEmptyRoot(rootNode, fromBlock)
  25377. return position
  25378. }
  25379. var findInsertionPoint = function (toBlock, block) {
  25380. var parentsAndSelf$1 = parentsAndSelf(block, toBlock)
  25381. return Optional.from(parentsAndSelf$1[parentsAndSelf$1.length - 1])
  25382. }
  25383. var getInsertionPoint = function (fromBlock, toBlock) {
  25384. return contains$1(toBlock, fromBlock)
  25385. ? findInsertionPoint(toBlock, fromBlock)
  25386. : Optional.none()
  25387. }
  25388. var trimBr = function (first, block) {
  25389. positionIn(first, block.dom)
  25390. .map(function (position) {
  25391. return position.getNode()
  25392. })
  25393. .map(SugarElement.fromDom)
  25394. .filter(isBr$4)
  25395. .each(remove$7)
  25396. }
  25397. var mergeBlockInto = function (rootNode, fromBlock, toBlock) {
  25398. trimBr(true, fromBlock)
  25399. trimBr(false, toBlock)
  25400. return getInsertionPoint(fromBlock, toBlock).fold(
  25401. curry(sidelongBlockMerge, rootNode, fromBlock, toBlock),
  25402. curry(nestedBlockMerge, rootNode, fromBlock, toBlock)
  25403. )
  25404. }
  25405. var mergeBlocks = function (rootNode, forward, block1, block2) {
  25406. return forward
  25407. ? mergeBlockInto(rootNode, block2, block1)
  25408. : mergeBlockInto(rootNode, block1, block2)
  25409. }
  25410. var backspaceDelete$8 = function (editor, forward) {
  25411. var rootNode = SugarElement.fromDom(editor.getBody())
  25412. var position = read$1(
  25413. rootNode.dom,
  25414. forward,
  25415. editor.selection.getRng()
  25416. ).bind(function (blockBoundary) {
  25417. return mergeBlocks(
  25418. rootNode,
  25419. forward,
  25420. blockBoundary.from.block,
  25421. blockBoundary.to.block
  25422. )
  25423. })
  25424. position.each(function (pos) {
  25425. editor.selection.setRng(pos.toRange())
  25426. })
  25427. return position.isSome()
  25428. }
  25429. var deleteRangeMergeBlocks = function (rootNode, selection) {
  25430. var rng = selection.getRng()
  25431. return lift2(
  25432. getParentBlock$1(rootNode, SugarElement.fromDom(rng.startContainer)),
  25433. getParentBlock$1(rootNode, SugarElement.fromDom(rng.endContainer)),
  25434. function (block1, block2) {
  25435. if (eq(block1, block2) === false) {
  25436. rng.deleteContents()
  25437. mergeBlocks(rootNode, true, block1, block2).each(function (pos) {
  25438. selection.setRng(pos.toRange())
  25439. })
  25440. return true
  25441. } else {
  25442. return false
  25443. }
  25444. }
  25445. ).getOr(false)
  25446. }
  25447. var isRawNodeInTable = function (root, rawNode) {
  25448. var node = SugarElement.fromDom(rawNode)
  25449. var isRoot = curry(eq, root)
  25450. return ancestor$3(node, isTableCell$4, isRoot).isSome()
  25451. }
  25452. var isSelectionInTable = function (root, rng) {
  25453. return (
  25454. isRawNodeInTable(root, rng.startContainer) ||
  25455. isRawNodeInTable(root, rng.endContainer)
  25456. )
  25457. }
  25458. var isEverythingSelected = function (root, rng) {
  25459. var noPrevious = prevPosition(
  25460. root.dom,
  25461. CaretPosition.fromRangeStart(rng)
  25462. ).isNone()
  25463. var noNext = nextPosition(
  25464. root.dom,
  25465. CaretPosition.fromRangeEnd(rng)
  25466. ).isNone()
  25467. return !isSelectionInTable(root, rng) && noPrevious && noNext
  25468. }
  25469. var emptyEditor = function (editor) {
  25470. editor.setContent('')
  25471. editor.selection.setCursorLocation()
  25472. return true
  25473. }
  25474. var deleteRange$1 = function (editor) {
  25475. var rootNode = SugarElement.fromDom(editor.getBody())
  25476. var rng = editor.selection.getRng()
  25477. return isEverythingSelected(rootNode, rng)
  25478. ? emptyEditor(editor)
  25479. : deleteRangeMergeBlocks(rootNode, editor.selection)
  25480. }
  25481. var backspaceDelete$7 = function (editor, _forward) {
  25482. return editor.selection.isCollapsed() ? false : deleteRange$1(editor)
  25483. }
  25484. var isContentEditableTrue$2 = isContentEditableTrue$4
  25485. var isContentEditableFalse$4 = isContentEditableFalse$b
  25486. var showCaret = function (direction, editor, node, before, scrollIntoView) {
  25487. return Optional.from(
  25488. editor._selectionOverrides.showCaret(
  25489. direction,
  25490. node,
  25491. before,
  25492. scrollIntoView
  25493. )
  25494. )
  25495. }
  25496. var getNodeRange = function (node) {
  25497. var rng = node.ownerDocument.createRange()
  25498. rng.selectNode(node)
  25499. return rng
  25500. }
  25501. var selectNode = function (editor, node) {
  25502. var e = editor.fire('BeforeObjectSelected', { target: node })
  25503. if (e.isDefaultPrevented()) {
  25504. return Optional.none()
  25505. }
  25506. return Optional.some(getNodeRange(node))
  25507. }
  25508. var renderCaretAtRange = function (editor, range, scrollIntoView) {
  25509. var normalizedRange = normalizeRange(1, editor.getBody(), range)
  25510. var caretPosition = CaretPosition.fromRangeStart(normalizedRange)
  25511. var caretPositionNode = caretPosition.getNode()
  25512. if (isInlineFakeCaretTarget(caretPositionNode)) {
  25513. return showCaret(
  25514. 1,
  25515. editor,
  25516. caretPositionNode,
  25517. !caretPosition.isAtEnd(),
  25518. false
  25519. )
  25520. }
  25521. var caretPositionBeforeNode = caretPosition.getNode(true)
  25522. if (isInlineFakeCaretTarget(caretPositionBeforeNode)) {
  25523. return showCaret(1, editor, caretPositionBeforeNode, false, false)
  25524. }
  25525. var ceRoot = editor.dom.getParent(caretPosition.getNode(), function (node) {
  25526. return isContentEditableFalse$4(node) || isContentEditableTrue$2(node)
  25527. })
  25528. if (isInlineFakeCaretTarget(ceRoot)) {
  25529. return showCaret(1, editor, ceRoot, false, scrollIntoView)
  25530. }
  25531. return Optional.none()
  25532. }
  25533. var renderRangeCaret = function (editor, range, scrollIntoView) {
  25534. return range.collapsed
  25535. ? renderCaretAtRange(editor, range, scrollIntoView).getOr(range)
  25536. : range
  25537. }
  25538. var isBeforeBoundary = function (pos) {
  25539. return isBeforeContentEditableFalse(pos) || isBeforeMedia(pos)
  25540. }
  25541. var isAfterBoundary = function (pos) {
  25542. return isAfterContentEditableFalse(pos) || isAfterMedia(pos)
  25543. }
  25544. var trimEmptyTextNode = function (dom, node) {
  25545. if (isText$7(node) && node.data.length === 0) {
  25546. dom.remove(node)
  25547. }
  25548. }
  25549. var deleteContentAndShowCaret = function (
  25550. editor,
  25551. range,
  25552. node,
  25553. direction,
  25554. forward,
  25555. peekCaretPosition
  25556. ) {
  25557. showCaret(
  25558. direction,
  25559. editor,
  25560. peekCaretPosition.getNode(!forward),
  25561. forward,
  25562. true
  25563. ).each(function (caretRange) {
  25564. if (range.collapsed) {
  25565. var deleteRange = range.cloneRange()
  25566. if (forward) {
  25567. deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset)
  25568. } else {
  25569. deleteRange.setStart(caretRange.endContainer, caretRange.endOffset)
  25570. }
  25571. deleteRange.deleteContents()
  25572. } else {
  25573. range.deleteContents()
  25574. }
  25575. editor.selection.setRng(caretRange)
  25576. })
  25577. trimEmptyTextNode(editor.dom, node)
  25578. return true
  25579. }
  25580. var deleteBoundaryText = function (editor, forward) {
  25581. var range = editor.selection.getRng()
  25582. if (!isText$7(range.commonAncestorContainer)) {
  25583. return false
  25584. }
  25585. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  25586. var caretWalker = CaretWalker(editor.getBody())
  25587. var getNextPosFn = curry(
  25588. getVisualCaretPosition,
  25589. forward ? caretWalker.next : caretWalker.prev
  25590. )
  25591. var isBeforeFn = forward ? isBeforeBoundary : isAfterBoundary
  25592. var caretPosition = getNormalizedRangeEndPoint(
  25593. direction,
  25594. editor.getBody(),
  25595. range
  25596. )
  25597. var nextCaretPosition = normalizePosition(
  25598. forward,
  25599. getNextPosFn(caretPosition)
  25600. )
  25601. if (
  25602. !nextCaretPosition ||
  25603. !isMoveInsideSameBlock(caretPosition, nextCaretPosition)
  25604. ) {
  25605. return false
  25606. } else if (isBeforeFn(nextCaretPosition)) {
  25607. return deleteContentAndShowCaret(
  25608. editor,
  25609. range,
  25610. caretPosition.getNode(),
  25611. direction,
  25612. forward,
  25613. nextCaretPosition
  25614. )
  25615. }
  25616. var peekCaretPosition = getNextPosFn(nextCaretPosition)
  25617. if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
  25618. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  25619. return deleteContentAndShowCaret(
  25620. editor,
  25621. range,
  25622. caretPosition.getNode(),
  25623. direction,
  25624. forward,
  25625. peekCaretPosition
  25626. )
  25627. }
  25628. }
  25629. return false
  25630. }
  25631. var backspaceDelete$6 = function (editor, forward) {
  25632. return deleteBoundaryText(editor, forward)
  25633. }
  25634. var isCompoundElement = function (node) {
  25635. return (
  25636. isTableCell$4(SugarElement.fromDom(node)) ||
  25637. isListItem(SugarElement.fromDom(node))
  25638. )
  25639. }
  25640. var DeleteAction = Adt.generate([
  25641. { remove: ['element'] },
  25642. { moveToElement: ['element'] },
  25643. { moveToPosition: ['position'] },
  25644. ])
  25645. var isAtContentEditableBlockCaret = function (forward, from) {
  25646. var elm = from.getNode(forward === false)
  25647. var caretLocation = forward ? 'after' : 'before'
  25648. return (
  25649. isElement$5(elm) && elm.getAttribute('data-mce-caret') === caretLocation
  25650. )
  25651. }
  25652. var isDeleteFromCefDifferentBlocks = function (root, forward, from, to) {
  25653. var inSameBlock = function (elm) {
  25654. return (
  25655. isInline$1(SugarElement.fromDom(elm)) && !isInSameBlock(from, to, root)
  25656. )
  25657. }
  25658. return getRelativeCefElm(!forward, from).fold(function () {
  25659. return getRelativeCefElm(forward, to).fold(never, inSameBlock)
  25660. }, inSameBlock)
  25661. }
  25662. var deleteEmptyBlockOrMoveToCef = function (root, forward, from, to) {
  25663. var toCefElm = to.getNode(forward === false)
  25664. return getParentBlock$1(
  25665. SugarElement.fromDom(root),
  25666. SugarElement.fromDom(from.getNode())
  25667. )
  25668. .map(function (blockElm) {
  25669. return isEmpty$2(blockElm)
  25670. ? DeleteAction.remove(blockElm.dom)
  25671. : DeleteAction.moveToElement(toCefElm)
  25672. })
  25673. .orThunk(function () {
  25674. return Optional.some(DeleteAction.moveToElement(toCefElm))
  25675. })
  25676. }
  25677. var findCefPosition = function (root, forward, from) {
  25678. return fromPosition(forward, root, from).bind(function (to) {
  25679. if (isCompoundElement(to.getNode())) {
  25680. return Optional.none()
  25681. } else if (isDeleteFromCefDifferentBlocks(root, forward, from, to)) {
  25682. return Optional.none()
  25683. } else if (forward && isContentEditableFalse$b(to.getNode())) {
  25684. return deleteEmptyBlockOrMoveToCef(root, forward, from, to)
  25685. } else if (
  25686. forward === false &&
  25687. isContentEditableFalse$b(to.getNode(true))
  25688. ) {
  25689. return deleteEmptyBlockOrMoveToCef(root, forward, from, to)
  25690. } else if (forward && isAfterContentEditableFalse(from)) {
  25691. return Optional.some(DeleteAction.moveToPosition(to))
  25692. } else if (forward === false && isBeforeContentEditableFalse(from)) {
  25693. return Optional.some(DeleteAction.moveToPosition(to))
  25694. } else {
  25695. return Optional.none()
  25696. }
  25697. })
  25698. }
  25699. var getContentEditableBlockAction = function (forward, elm) {
  25700. if (forward && isContentEditableFalse$b(elm.nextSibling)) {
  25701. return Optional.some(DeleteAction.moveToElement(elm.nextSibling))
  25702. } else if (
  25703. forward === false &&
  25704. isContentEditableFalse$b(elm.previousSibling)
  25705. ) {
  25706. return Optional.some(DeleteAction.moveToElement(elm.previousSibling))
  25707. } else {
  25708. return Optional.none()
  25709. }
  25710. }
  25711. var skipMoveToActionFromInlineCefToContent = function (
  25712. root,
  25713. from,
  25714. deleteAction
  25715. ) {
  25716. return deleteAction.fold(
  25717. function (elm) {
  25718. return Optional.some(DeleteAction.remove(elm))
  25719. },
  25720. function (elm) {
  25721. return Optional.some(DeleteAction.moveToElement(elm))
  25722. },
  25723. function (to) {
  25724. if (isInSameBlock(from, to, root)) {
  25725. return Optional.none()
  25726. } else {
  25727. return Optional.some(DeleteAction.moveToPosition(to))
  25728. }
  25729. }
  25730. )
  25731. }
  25732. var getContentEditableAction = function (root, forward, from) {
  25733. if (isAtContentEditableBlockCaret(forward, from)) {
  25734. return getContentEditableBlockAction(
  25735. forward,
  25736. from.getNode(forward === false)
  25737. ).fold(function () {
  25738. return findCefPosition(root, forward, from)
  25739. }, Optional.some)
  25740. } else {
  25741. return findCefPosition(root, forward, from).bind(function (deleteAction) {
  25742. return skipMoveToActionFromInlineCefToContent(root, from, deleteAction)
  25743. })
  25744. }
  25745. }
  25746. var read = function (root, forward, rng) {
  25747. var normalizedRange = normalizeRange(forward ? 1 : -1, root, rng)
  25748. var from = CaretPosition.fromRangeStart(normalizedRange)
  25749. var rootElement = SugarElement.fromDom(root)
  25750. if (forward === false && isAfterContentEditableFalse(from)) {
  25751. return Optional.some(DeleteAction.remove(from.getNode(true)))
  25752. } else if (forward && isBeforeContentEditableFalse(from)) {
  25753. return Optional.some(DeleteAction.remove(from.getNode()))
  25754. } else if (
  25755. forward === false &&
  25756. isBeforeContentEditableFalse(from) &&
  25757. isAfterBr(rootElement, from)
  25758. ) {
  25759. return findPreviousBr(rootElement, from).map(function (br) {
  25760. return DeleteAction.remove(br.getNode())
  25761. })
  25762. } else if (
  25763. forward &&
  25764. isAfterContentEditableFalse(from) &&
  25765. isBeforeBr$1(rootElement, from)
  25766. ) {
  25767. return findNextBr(rootElement, from).map(function (br) {
  25768. return DeleteAction.remove(br.getNode())
  25769. })
  25770. } else {
  25771. return getContentEditableAction(root, forward, from)
  25772. }
  25773. }
  25774. var deleteElement$1 = function (editor, forward) {
  25775. return function (element) {
  25776. editor._selectionOverrides.hideFakeCaret()
  25777. deleteElement$2(editor, forward, SugarElement.fromDom(element))
  25778. return true
  25779. }
  25780. }
  25781. var moveToElement = function (editor, forward) {
  25782. return function (element) {
  25783. var pos = forward
  25784. ? CaretPosition.before(element)
  25785. : CaretPosition.after(element)
  25786. editor.selection.setRng(pos.toRange())
  25787. return true
  25788. }
  25789. }
  25790. var moveToPosition = function (editor) {
  25791. return function (pos) {
  25792. editor.selection.setRng(pos.toRange())
  25793. return true
  25794. }
  25795. }
  25796. var getAncestorCe = function (editor, node) {
  25797. return Optional.from(getContentEditableRoot$1(editor.getBody(), node))
  25798. }
  25799. var backspaceDeleteCaret = function (editor, forward) {
  25800. var selectedNode = editor.selection.getNode()
  25801. return getAncestorCe(editor, selectedNode)
  25802. .filter(isContentEditableFalse$b)
  25803. .fold(function () {
  25804. return read(
  25805. editor.getBody(),
  25806. forward,
  25807. editor.selection.getRng()
  25808. ).exists(function (deleteAction) {
  25809. return deleteAction.fold(
  25810. deleteElement$1(editor, forward),
  25811. moveToElement(editor, forward),
  25812. moveToPosition(editor)
  25813. )
  25814. })
  25815. }, always)
  25816. }
  25817. var deleteOffscreenSelection = function (rootElement) {
  25818. each$k(descendants(rootElement, '.mce-offscreen-selection'), remove$7)
  25819. }
  25820. var backspaceDeleteRange = function (editor, forward) {
  25821. var selectedNode = editor.selection.getNode()
  25822. if (
  25823. isContentEditableFalse$b(selectedNode) &&
  25824. !isTableCell$5(selectedNode)
  25825. ) {
  25826. var hasCefAncestor = getAncestorCe(
  25827. editor,
  25828. selectedNode.parentNode
  25829. ).filter(isContentEditableFalse$b)
  25830. return hasCefAncestor.fold(function () {
  25831. deleteOffscreenSelection(SugarElement.fromDom(editor.getBody()))
  25832. deleteElement$2(
  25833. editor,
  25834. forward,
  25835. SugarElement.fromDom(editor.selection.getNode())
  25836. )
  25837. paddEmptyBody(editor)
  25838. return true
  25839. }, always)
  25840. }
  25841. return false
  25842. }
  25843. var paddEmptyElement = function (editor) {
  25844. var dom = editor.dom,
  25845. selection = editor.selection
  25846. var ceRoot = getContentEditableRoot$1(editor.getBody(), selection.getNode())
  25847. if (
  25848. isContentEditableTrue$4(ceRoot) &&
  25849. dom.isBlock(ceRoot) &&
  25850. dom.isEmpty(ceRoot)
  25851. ) {
  25852. var br = dom.create('br', { 'data-mce-bogus': '1' })
  25853. dom.setHTML(ceRoot, '')
  25854. ceRoot.appendChild(br)
  25855. selection.setRng(CaretPosition.before(br).toRange())
  25856. }
  25857. return true
  25858. }
  25859. var backspaceDelete$5 = function (editor, forward) {
  25860. if (editor.selection.isCollapsed()) {
  25861. return backspaceDeleteCaret(editor, forward)
  25862. } else {
  25863. return backspaceDeleteRange(editor, forward)
  25864. }
  25865. }
  25866. var deleteCaret$2 = function (editor, forward) {
  25867. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng())
  25868. return fromPosition(forward, editor.getBody(), fromPos)
  25869. .filter(function (pos) {
  25870. return forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos)
  25871. })
  25872. .bind(function (pos) {
  25873. return Optional.from(
  25874. getChildNodeAtRelativeOffset(forward ? 0 : -1, pos)
  25875. )
  25876. })
  25877. .exists(function (elm) {
  25878. editor.selection.select(elm)
  25879. return true
  25880. })
  25881. }
  25882. var backspaceDelete$4 = function (editor, forward) {
  25883. return editor.selection.isCollapsed()
  25884. ? deleteCaret$2(editor, forward)
  25885. : false
  25886. }
  25887. var isText = isText$7
  25888. var startsWithCaretContainer = function (node) {
  25889. return isText(node) && node.data[0] === ZWSP$1
  25890. }
  25891. var endsWithCaretContainer = function (node) {
  25892. return isText(node) && node.data[node.data.length - 1] === ZWSP$1
  25893. }
  25894. var createZwsp = function (node) {
  25895. return node.ownerDocument.createTextNode(ZWSP$1)
  25896. }
  25897. var insertBefore = function (node) {
  25898. if (isText(node.previousSibling)) {
  25899. if (endsWithCaretContainer(node.previousSibling)) {
  25900. return node.previousSibling
  25901. } else {
  25902. node.previousSibling.appendData(ZWSP$1)
  25903. return node.previousSibling
  25904. }
  25905. } else if (isText(node)) {
  25906. if (startsWithCaretContainer(node)) {
  25907. return node
  25908. } else {
  25909. node.insertData(0, ZWSP$1)
  25910. return node
  25911. }
  25912. } else {
  25913. var newNode = createZwsp(node)
  25914. node.parentNode.insertBefore(newNode, node)
  25915. return newNode
  25916. }
  25917. }
  25918. var insertAfter = function (node) {
  25919. if (isText(node.nextSibling)) {
  25920. if (startsWithCaretContainer(node.nextSibling)) {
  25921. return node.nextSibling
  25922. } else {
  25923. node.nextSibling.insertData(0, ZWSP$1)
  25924. return node.nextSibling
  25925. }
  25926. } else if (isText(node)) {
  25927. if (endsWithCaretContainer(node)) {
  25928. return node
  25929. } else {
  25930. node.appendData(ZWSP$1)
  25931. return node
  25932. }
  25933. } else {
  25934. var newNode = createZwsp(node)
  25935. if (node.nextSibling) {
  25936. node.parentNode.insertBefore(newNode, node.nextSibling)
  25937. } else {
  25938. node.parentNode.appendChild(newNode)
  25939. }
  25940. return newNode
  25941. }
  25942. }
  25943. var insertInline = function (before, node) {
  25944. return before ? insertBefore(node) : insertAfter(node)
  25945. }
  25946. var insertInlineBefore = curry(insertInline, true)
  25947. var insertInlineAfter = curry(insertInline, false)
  25948. var insertInlinePos = function (pos, before) {
  25949. if (isText$7(pos.container())) {
  25950. return insertInline(before, pos.container())
  25951. } else {
  25952. return insertInline(before, pos.getNode())
  25953. }
  25954. }
  25955. var isPosCaretContainer = function (pos, caret) {
  25956. var caretNode = caret.get()
  25957. return (
  25958. caretNode &&
  25959. pos.container() === caretNode &&
  25960. isCaretContainerInline(caretNode)
  25961. )
  25962. }
  25963. var renderCaret = function (caret, location) {
  25964. return location.fold(
  25965. function (element) {
  25966. remove$2(caret.get())
  25967. var text = insertInlineBefore(element)
  25968. caret.set(text)
  25969. return Optional.some(CaretPosition(text, text.length - 1))
  25970. },
  25971. function (element) {
  25972. return firstPositionIn(element).map(function (pos) {
  25973. if (!isPosCaretContainer(pos, caret)) {
  25974. remove$2(caret.get())
  25975. var text = insertInlinePos(pos, true)
  25976. caret.set(text)
  25977. return CaretPosition(text, 1)
  25978. } else {
  25979. return CaretPosition(caret.get(), 1)
  25980. }
  25981. })
  25982. },
  25983. function (element) {
  25984. return lastPositionIn(element).map(function (pos) {
  25985. if (!isPosCaretContainer(pos, caret)) {
  25986. remove$2(caret.get())
  25987. var text = insertInlinePos(pos, false)
  25988. caret.set(text)
  25989. return CaretPosition(text, text.length - 1)
  25990. } else {
  25991. return CaretPosition(caret.get(), caret.get().length - 1)
  25992. }
  25993. })
  25994. },
  25995. function (element) {
  25996. remove$2(caret.get())
  25997. var text = insertInlineAfter(element)
  25998. caret.set(text)
  25999. return Optional.some(CaretPosition(text, 1))
  26000. }
  26001. )
  26002. }
  26003. var evaluateUntil = function (fns, args) {
  26004. for (var i = 0; i < fns.length; i++) {
  26005. var result = fns[i].apply(null, args)
  26006. if (result.isSome()) {
  26007. return result
  26008. }
  26009. }
  26010. return Optional.none()
  26011. }
  26012. var Location = Adt.generate([
  26013. { before: ['element'] },
  26014. { start: ['element'] },
  26015. { end: ['element'] },
  26016. { after: ['element'] },
  26017. ])
  26018. var rescope$1 = function (rootNode, node) {
  26019. var parentBlock = getParentBlock$2(node, rootNode)
  26020. return parentBlock ? parentBlock : rootNode
  26021. }
  26022. var before = function (isInlineTarget, rootNode, pos) {
  26023. var nPos = normalizeForwards(pos)
  26024. var scope = rescope$1(rootNode, nPos.container())
  26025. return findRootInline(isInlineTarget, scope, nPos).fold(function () {
  26026. return nextPosition(scope, nPos)
  26027. .bind(curry(findRootInline, isInlineTarget, scope))
  26028. .map(function (inline) {
  26029. return Location.before(inline)
  26030. })
  26031. }, Optional.none)
  26032. }
  26033. var isNotInsideFormatCaretContainer = function (rootNode, elm) {
  26034. return getParentCaretContainer(rootNode, elm) === null
  26035. }
  26036. var findInsideRootInline = function (isInlineTarget, rootNode, pos) {
  26037. return findRootInline(isInlineTarget, rootNode, pos).filter(
  26038. curry(isNotInsideFormatCaretContainer, rootNode)
  26039. )
  26040. }
  26041. var start$1 = function (isInlineTarget, rootNode, pos) {
  26042. var nPos = normalizeBackwards(pos)
  26043. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (
  26044. inline
  26045. ) {
  26046. var prevPos = prevPosition(inline, nPos)
  26047. return prevPos.isNone()
  26048. ? Optional.some(Location.start(inline))
  26049. : Optional.none()
  26050. })
  26051. }
  26052. var end = function (isInlineTarget, rootNode, pos) {
  26053. var nPos = normalizeForwards(pos)
  26054. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (
  26055. inline
  26056. ) {
  26057. var nextPos = nextPosition(inline, nPos)
  26058. return nextPos.isNone()
  26059. ? Optional.some(Location.end(inline))
  26060. : Optional.none()
  26061. })
  26062. }
  26063. var after = function (isInlineTarget, rootNode, pos) {
  26064. var nPos = normalizeBackwards(pos)
  26065. var scope = rescope$1(rootNode, nPos.container())
  26066. return findRootInline(isInlineTarget, scope, nPos).fold(function () {
  26067. return prevPosition(scope, nPos)
  26068. .bind(curry(findRootInline, isInlineTarget, scope))
  26069. .map(function (inline) {
  26070. return Location.after(inline)
  26071. })
  26072. }, Optional.none)
  26073. }
  26074. var isValidLocation = function (location) {
  26075. return isRtl(getElement(location)) === false
  26076. }
  26077. var readLocation = function (isInlineTarget, rootNode, pos) {
  26078. var location = evaluateUntil(
  26079. [before, start$1, end, after],
  26080. [isInlineTarget, rootNode, pos]
  26081. )
  26082. return location.filter(isValidLocation)
  26083. }
  26084. var getElement = function (location) {
  26085. return location.fold(identity, identity, identity, identity)
  26086. }
  26087. var getName = function (location) {
  26088. return location.fold(
  26089. constant('before'),
  26090. constant('start'),
  26091. constant('end'),
  26092. constant('after')
  26093. )
  26094. }
  26095. var outside = function (location) {
  26096. return location.fold(
  26097. Location.before,
  26098. Location.before,
  26099. Location.after,
  26100. Location.after
  26101. )
  26102. }
  26103. var inside = function (location) {
  26104. return location.fold(
  26105. Location.start,
  26106. Location.start,
  26107. Location.end,
  26108. Location.end
  26109. )
  26110. }
  26111. var isEq = function (location1, location2) {
  26112. return (
  26113. getName(location1) === getName(location2) &&
  26114. getElement(location1) === getElement(location2)
  26115. )
  26116. }
  26117. var betweenInlines = function (
  26118. forward,
  26119. isInlineTarget,
  26120. rootNode,
  26121. from,
  26122. to,
  26123. location
  26124. ) {
  26125. return lift2(
  26126. findRootInline(isInlineTarget, rootNode, from),
  26127. findRootInline(isInlineTarget, rootNode, to),
  26128. function (fromInline, toInline) {
  26129. if (
  26130. fromInline !== toInline &&
  26131. hasSameParentBlock(rootNode, fromInline, toInline)
  26132. ) {
  26133. return Location.after(forward ? fromInline : toInline)
  26134. } else {
  26135. return location
  26136. }
  26137. }
  26138. ).getOr(location)
  26139. }
  26140. var skipNoMovement = function (fromLocation, toLocation) {
  26141. return fromLocation.fold(always, function (fromLocation) {
  26142. return !isEq(fromLocation, toLocation)
  26143. })
  26144. }
  26145. var findLocationTraverse = function (
  26146. forward,
  26147. isInlineTarget,
  26148. rootNode,
  26149. fromLocation,
  26150. pos
  26151. ) {
  26152. var from = normalizePosition(forward, pos)
  26153. var to = fromPosition(forward, rootNode, from).map(
  26154. curry(normalizePosition, forward)
  26155. )
  26156. var location = to.fold(
  26157. function () {
  26158. return fromLocation.map(outside)
  26159. },
  26160. function (to) {
  26161. return readLocation(isInlineTarget, rootNode, to)
  26162. .map(
  26163. curry(betweenInlines, forward, isInlineTarget, rootNode, from, to)
  26164. )
  26165. .filter(curry(skipNoMovement, fromLocation))
  26166. }
  26167. )
  26168. return location.filter(isValidLocation)
  26169. }
  26170. var findLocationSimple = function (forward, location) {
  26171. if (forward) {
  26172. return location.fold(
  26173. compose(Optional.some, Location.start),
  26174. Optional.none,
  26175. compose(Optional.some, Location.after),
  26176. Optional.none
  26177. )
  26178. } else {
  26179. return location.fold(
  26180. Optional.none,
  26181. compose(Optional.some, Location.before),
  26182. Optional.none,
  26183. compose(Optional.some, Location.end)
  26184. )
  26185. }
  26186. }
  26187. var findLocation$1 = function (forward, isInlineTarget, rootNode, pos) {
  26188. var from = normalizePosition(forward, pos)
  26189. var fromLocation = readLocation(isInlineTarget, rootNode, from)
  26190. return readLocation(isInlineTarget, rootNode, from)
  26191. .bind(curry(findLocationSimple, forward))
  26192. .orThunk(function () {
  26193. return findLocationTraverse(
  26194. forward,
  26195. isInlineTarget,
  26196. rootNode,
  26197. fromLocation,
  26198. pos
  26199. )
  26200. })
  26201. }
  26202. curry(findLocation$1, false)
  26203. curry(findLocation$1, true)
  26204. var hasSelectionModifyApi = function (editor) {
  26205. return isFunction(editor.selection.getSel().modify)
  26206. }
  26207. var moveRel = function (forward, selection, pos) {
  26208. var delta = forward ? 1 : -1
  26209. selection.setRng(
  26210. CaretPosition(pos.container(), pos.offset() + delta).toRange()
  26211. )
  26212. selection.getSel().modify('move', forward ? 'forward' : 'backward', 'word')
  26213. return true
  26214. }
  26215. var moveByWord = function (forward, editor) {
  26216. var rng = editor.selection.getRng()
  26217. var pos = forward
  26218. ? CaretPosition.fromRangeEnd(rng)
  26219. : CaretPosition.fromRangeStart(rng)
  26220. if (!hasSelectionModifyApi(editor)) {
  26221. return false
  26222. } else if (forward && isBeforeInline(pos)) {
  26223. return moveRel(true, editor.selection, pos)
  26224. } else if (!forward && isAfterInline(pos)) {
  26225. return moveRel(false, editor.selection, pos)
  26226. } else {
  26227. return false
  26228. }
  26229. }
  26230. var BreakType
  26231. ;(function (BreakType) {
  26232. BreakType[(BreakType['Br'] = 0)] = 'Br'
  26233. BreakType[(BreakType['Block'] = 1)] = 'Block'
  26234. BreakType[(BreakType['Wrap'] = 2)] = 'Wrap'
  26235. BreakType[(BreakType['Eol'] = 3)] = 'Eol'
  26236. })(BreakType || (BreakType = {}))
  26237. var flip = function (direction, positions) {
  26238. return direction === HDirection.Backwards ? reverse(positions) : positions
  26239. }
  26240. var walk = function (direction, caretWalker, pos) {
  26241. return direction === HDirection.Forwards
  26242. ? caretWalker.next(pos)
  26243. : caretWalker.prev(pos)
  26244. }
  26245. var getBreakType = function (scope, direction, currentPos, nextPos) {
  26246. if (isBr$5(nextPos.getNode(direction === HDirection.Forwards))) {
  26247. return BreakType.Br
  26248. } else if (isInSameBlock(currentPos, nextPos) === false) {
  26249. return BreakType.Block
  26250. } else {
  26251. return BreakType.Wrap
  26252. }
  26253. }
  26254. var getPositionsUntil = function (predicate, direction, scope, start) {
  26255. var caretWalker = CaretWalker(scope)
  26256. var currentPos = start
  26257. var positions = []
  26258. while (currentPos) {
  26259. var nextPos = walk(direction, caretWalker, currentPos)
  26260. if (!nextPos) {
  26261. break
  26262. }
  26263. if (isBr$5(nextPos.getNode(false))) {
  26264. if (direction === HDirection.Forwards) {
  26265. return {
  26266. positions: flip(direction, positions).concat([nextPos]),
  26267. breakType: BreakType.Br,
  26268. breakAt: Optional.some(nextPos),
  26269. }
  26270. } else {
  26271. return {
  26272. positions: flip(direction, positions),
  26273. breakType: BreakType.Br,
  26274. breakAt: Optional.some(nextPos),
  26275. }
  26276. }
  26277. }
  26278. if (!nextPos.isVisible()) {
  26279. currentPos = nextPos
  26280. continue
  26281. }
  26282. if (predicate(currentPos, nextPos)) {
  26283. var breakType = getBreakType(scope, direction, currentPos, nextPos)
  26284. return {
  26285. positions: flip(direction, positions),
  26286. breakType: breakType,
  26287. breakAt: Optional.some(nextPos),
  26288. }
  26289. }
  26290. positions.push(nextPos)
  26291. currentPos = nextPos
  26292. }
  26293. return {
  26294. positions: flip(direction, positions),
  26295. breakType: BreakType.Eol,
  26296. breakAt: Optional.none(),
  26297. }
  26298. }
  26299. var getAdjacentLinePositions = function (
  26300. direction,
  26301. getPositionsUntilBreak,
  26302. scope,
  26303. start
  26304. ) {
  26305. return getPositionsUntilBreak(scope, start)
  26306. .breakAt.map(function (pos) {
  26307. var positions = getPositionsUntilBreak(scope, pos).positions
  26308. return direction === HDirection.Backwards
  26309. ? positions.concat(pos)
  26310. : [pos].concat(positions)
  26311. })
  26312. .getOr([])
  26313. }
  26314. var findClosestHorizontalPositionFromPoint = function (positions, x) {
  26315. return foldl(
  26316. positions,
  26317. function (acc, newPos) {
  26318. return acc.fold(
  26319. function () {
  26320. return Optional.some(newPos)
  26321. },
  26322. function (lastPos) {
  26323. return lift2(
  26324. head(lastPos.getClientRects()),
  26325. head(newPos.getClientRects()),
  26326. function (lastRect, newRect) {
  26327. var lastDist = Math.abs(x - lastRect.left)
  26328. var newDist = Math.abs(x - newRect.left)
  26329. return newDist <= lastDist ? newPos : lastPos
  26330. }
  26331. ).or(acc)
  26332. }
  26333. )
  26334. },
  26335. Optional.none()
  26336. )
  26337. }
  26338. var findClosestHorizontalPosition = function (positions, pos) {
  26339. return head(pos.getClientRects()).bind(function (targetRect) {
  26340. return findClosestHorizontalPositionFromPoint(positions, targetRect.left)
  26341. })
  26342. }
  26343. var getPositionsUntilPreviousLine = curry(
  26344. getPositionsUntil,
  26345. CaretPosition.isAbove,
  26346. -1
  26347. )
  26348. var getPositionsUntilNextLine = curry(
  26349. getPositionsUntil,
  26350. CaretPosition.isBelow,
  26351. 1
  26352. )
  26353. var getPositionsAbove = curry(
  26354. getAdjacentLinePositions,
  26355. -1,
  26356. getPositionsUntilPreviousLine
  26357. )
  26358. var getPositionsBelow = curry(
  26359. getAdjacentLinePositions,
  26360. 1,
  26361. getPositionsUntilNextLine
  26362. )
  26363. var isAtFirstLine = function (scope, pos) {
  26364. return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone()
  26365. }
  26366. var isAtLastLine = function (scope, pos) {
  26367. return getPositionsUntilNextLine(scope, pos).breakAt.isNone()
  26368. }
  26369. var getFirstLinePositions = function (scope) {
  26370. return firstPositionIn(scope)
  26371. .map(function (pos) {
  26372. return [pos].concat(getPositionsUntilNextLine(scope, pos).positions)
  26373. })
  26374. .getOr([])
  26375. }
  26376. var getLastLinePositions = function (scope) {
  26377. return lastPositionIn(scope)
  26378. .map(function (pos) {
  26379. return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos)
  26380. })
  26381. .getOr([])
  26382. }
  26383. var getNodeClientRects = function (node) {
  26384. var toArrayWithNode = function (clientRects) {
  26385. return map$3(clientRects, function (rect) {
  26386. var clientRect = clone(rect)
  26387. clientRect.node = node
  26388. return clientRect
  26389. })
  26390. }
  26391. if (isElement$5(node)) {
  26392. return toArrayWithNode(node.getClientRects())
  26393. }
  26394. if (isText$7(node)) {
  26395. var rng = node.ownerDocument.createRange()
  26396. rng.setStart(node, 0)
  26397. rng.setEnd(node, node.data.length)
  26398. return toArrayWithNode(rng.getClientRects())
  26399. }
  26400. }
  26401. var getClientRects = function (nodes) {
  26402. return bind(nodes, getNodeClientRects)
  26403. }
  26404. var VDirection
  26405. ;(function (VDirection) {
  26406. VDirection[(VDirection['Up'] = -1)] = 'Up'
  26407. VDirection[(VDirection['Down'] = 1)] = 'Down'
  26408. })(VDirection || (VDirection = {}))
  26409. var findUntil = function (direction, root, predicateFn, node) {
  26410. while (
  26411. (node = findNode$1(node, direction, isEditableCaretCandidate$1, root))
  26412. ) {
  26413. if (predicateFn(node)) {
  26414. return
  26415. }
  26416. }
  26417. }
  26418. var walkUntil$1 = function (
  26419. direction,
  26420. isAboveFn,
  26421. isBeflowFn,
  26422. root,
  26423. predicateFn,
  26424. caretPosition
  26425. ) {
  26426. var line = 0
  26427. var result = []
  26428. var add = function (node) {
  26429. var clientRects = getClientRects([node])
  26430. if (direction === -1) {
  26431. clientRects = clientRects.reverse()
  26432. }
  26433. for (var i = 0; i < clientRects.length; i++) {
  26434. var clientRect = clientRects[i]
  26435. if (isBeflowFn(clientRect, targetClientRect)) {
  26436. continue
  26437. }
  26438. if (result.length > 0 && isAboveFn(clientRect, last$1(result))) {
  26439. line++
  26440. }
  26441. clientRect.line = line
  26442. if (predicateFn(clientRect)) {
  26443. return true
  26444. }
  26445. result.push(clientRect)
  26446. }
  26447. }
  26448. var targetClientRect = last$1(caretPosition.getClientRects())
  26449. if (!targetClientRect) {
  26450. return result
  26451. }
  26452. var node = caretPosition.getNode()
  26453. add(node)
  26454. findUntil(direction, root, add, node)
  26455. return result
  26456. }
  26457. var aboveLineNumber = function (lineNumber, clientRect) {
  26458. return clientRect.line > lineNumber
  26459. }
  26460. var isLineNumber = function (lineNumber, clientRect) {
  26461. return clientRect.line === lineNumber
  26462. }
  26463. var upUntil = curry(walkUntil$1, VDirection.Up, isAbove$1, isBelow$1)
  26464. var downUntil = curry(walkUntil$1, VDirection.Down, isBelow$1, isAbove$1)
  26465. var positionsUntil = function (direction, root, predicateFn, node) {
  26466. var caretWalker = CaretWalker(root)
  26467. var walkFn
  26468. var isBelowFn
  26469. var isAboveFn
  26470. var caretPosition
  26471. var result = []
  26472. var line = 0
  26473. var getClientRect = function (caretPosition) {
  26474. if (direction === 1) {
  26475. return last$1(caretPosition.getClientRects())
  26476. }
  26477. return last$1(caretPosition.getClientRects())
  26478. }
  26479. if (direction === 1) {
  26480. walkFn = caretWalker.next
  26481. isBelowFn = isBelow$1
  26482. isAboveFn = isAbove$1
  26483. caretPosition = CaretPosition.after(node)
  26484. } else {
  26485. walkFn = caretWalker.prev
  26486. isBelowFn = isAbove$1
  26487. isAboveFn = isBelow$1
  26488. caretPosition = CaretPosition.before(node)
  26489. }
  26490. var targetClientRect = getClientRect(caretPosition)
  26491. do {
  26492. if (!caretPosition.isVisible()) {
  26493. continue
  26494. }
  26495. var rect = getClientRect(caretPosition)
  26496. if (isAboveFn(rect, targetClientRect)) {
  26497. continue
  26498. }
  26499. if (result.length > 0 && isBelowFn(rect, last$1(result))) {
  26500. line++
  26501. }
  26502. var clientRect = clone(rect)
  26503. clientRect.position = caretPosition
  26504. clientRect.line = line
  26505. if (predicateFn(clientRect)) {
  26506. return result
  26507. }
  26508. result.push(clientRect)
  26509. } while ((caretPosition = walkFn(caretPosition)))
  26510. return result
  26511. }
  26512. var isAboveLine = function (lineNumber) {
  26513. return function (clientRect) {
  26514. return aboveLineNumber(lineNumber, clientRect)
  26515. }
  26516. }
  26517. var isLine = function (lineNumber) {
  26518. return function (clientRect) {
  26519. return isLineNumber(lineNumber, clientRect)
  26520. }
  26521. }
  26522. var isContentEditableFalse$3 = isContentEditableFalse$b
  26523. var findNode = findNode$1
  26524. var distanceToRectLeft = function (clientRect, clientX) {
  26525. return Math.abs(clientRect.left - clientX)
  26526. }
  26527. var distanceToRectRight = function (clientRect, clientX) {
  26528. return Math.abs(clientRect.right - clientX)
  26529. }
  26530. var isInsideX = function (clientX, clientRect) {
  26531. return clientX >= clientRect.left && clientX <= clientRect.right
  26532. }
  26533. var isInsideY = function (clientY, clientRect) {
  26534. return clientY >= clientRect.top && clientY <= clientRect.bottom
  26535. }
  26536. var isNodeClientRect = function (rect) {
  26537. return hasNonNullableKey(rect, 'node')
  26538. }
  26539. var findClosestClientRect = function (clientRects, clientX, allowInside) {
  26540. if (allowInside === void 0) {
  26541. allowInside = always
  26542. }
  26543. return reduce(clientRects, function (oldClientRect, clientRect) {
  26544. if (isInsideX(clientX, clientRect)) {
  26545. return allowInside(clientRect) ? clientRect : oldClientRect
  26546. }
  26547. if (isInsideX(clientX, oldClientRect)) {
  26548. return allowInside(oldClientRect) ? oldClientRect : clientRect
  26549. }
  26550. var oldDistance = Math.min(
  26551. distanceToRectLeft(oldClientRect, clientX),
  26552. distanceToRectRight(oldClientRect, clientX)
  26553. )
  26554. var newDistance = Math.min(
  26555. distanceToRectLeft(clientRect, clientX),
  26556. distanceToRectRight(clientRect, clientX)
  26557. )
  26558. if (
  26559. newDistance === oldDistance &&
  26560. isNodeClientRect(clientRect) &&
  26561. isContentEditableFalse$3(clientRect.node)
  26562. ) {
  26563. return clientRect
  26564. }
  26565. if (newDistance < oldDistance) {
  26566. return clientRect
  26567. }
  26568. return oldClientRect
  26569. })
  26570. }
  26571. var walkUntil = function (
  26572. direction,
  26573. root,
  26574. predicateFn,
  26575. startNode,
  26576. includeChildren
  26577. ) {
  26578. var node = findNode(
  26579. startNode,
  26580. direction,
  26581. isEditableCaretCandidate$1,
  26582. root,
  26583. !includeChildren
  26584. )
  26585. do {
  26586. if (!node || predicateFn(node)) {
  26587. return
  26588. }
  26589. } while (
  26590. (node = findNode(node, direction, isEditableCaretCandidate$1, root))
  26591. )
  26592. }
  26593. var findLineNodeRects = function (root, targetNodeRect, includeChildren) {
  26594. if (includeChildren === void 0) {
  26595. includeChildren = true
  26596. }
  26597. var clientRects = []
  26598. var collect = function (checkPosFn, node) {
  26599. var lineRects = filter$4(getClientRects([node]), function (clientRect) {
  26600. return !checkPosFn(clientRect, targetNodeRect)
  26601. })
  26602. clientRects = clientRects.concat(lineRects)
  26603. return lineRects.length === 0
  26604. }
  26605. clientRects.push(targetNodeRect)
  26606. walkUntil(
  26607. VDirection.Up,
  26608. root,
  26609. curry(collect, isAbove$1),
  26610. targetNodeRect.node,
  26611. includeChildren
  26612. )
  26613. walkUntil(
  26614. VDirection.Down,
  26615. root,
  26616. curry(collect, isBelow$1),
  26617. targetNodeRect.node,
  26618. includeChildren
  26619. )
  26620. return clientRects
  26621. }
  26622. var getFakeCaretTargets = function (root) {
  26623. return filter$4(from(root.getElementsByTagName('*')), isFakeCaretTarget)
  26624. }
  26625. var caretInfo = function (clientRect, clientX) {
  26626. return {
  26627. node: clientRect.node,
  26628. before:
  26629. distanceToRectLeft(clientRect, clientX) <
  26630. distanceToRectRight(clientRect, clientX),
  26631. }
  26632. }
  26633. var closestFakeCaret = function (root, clientX, clientY) {
  26634. var fakeTargetNodeRects = getClientRects(getFakeCaretTargets(root))
  26635. var targetNodeRects = filter$4(
  26636. fakeTargetNodeRects,
  26637. curry(isInsideY, clientY)
  26638. )
  26639. var checkInside = function (clientRect) {
  26640. return !isTable$3(clientRect.node) && !isMedia$2(clientRect.node)
  26641. }
  26642. var closestNodeRect = findClosestClientRect(
  26643. targetNodeRects,
  26644. clientX,
  26645. checkInside
  26646. )
  26647. if (closestNodeRect) {
  26648. var includeChildren = checkInside(closestNodeRect)
  26649. closestNodeRect = findClosestClientRect(
  26650. findLineNodeRects(root, closestNodeRect, includeChildren),
  26651. clientX,
  26652. checkInside
  26653. )
  26654. if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
  26655. return caretInfo(closestNodeRect, clientX)
  26656. }
  26657. }
  26658. return null
  26659. }
  26660. var moveToRange = function (editor, rng) {
  26661. editor.selection.setRng(rng)
  26662. scrollRangeIntoView(editor, editor.selection.getRng())
  26663. }
  26664. var renderRangeCaretOpt = function (editor, range, scrollIntoView) {
  26665. return Optional.some(renderRangeCaret(editor, range, scrollIntoView))
  26666. }
  26667. var moveHorizontally = function (
  26668. editor,
  26669. direction,
  26670. range,
  26671. isBefore,
  26672. isAfter,
  26673. isElement
  26674. ) {
  26675. var forwards = direction === HDirection.Forwards
  26676. var caretWalker = CaretWalker(editor.getBody())
  26677. var getNextPosFn = curry(
  26678. getVisualCaretPosition,
  26679. forwards ? caretWalker.next : caretWalker.prev
  26680. )
  26681. var isBeforeFn = forwards ? isBefore : isAfter
  26682. if (!range.collapsed) {
  26683. var node = getSelectedNode(range)
  26684. if (isElement(node)) {
  26685. return showCaret(
  26686. direction,
  26687. editor,
  26688. node,
  26689. direction === HDirection.Backwards,
  26690. false
  26691. )
  26692. }
  26693. }
  26694. var caretPosition = getNormalizedRangeEndPoint(
  26695. direction,
  26696. editor.getBody(),
  26697. range
  26698. )
  26699. if (isBeforeFn(caretPosition)) {
  26700. return selectNode(editor, caretPosition.getNode(!forwards))
  26701. }
  26702. var nextCaretPosition = normalizePosition(
  26703. forwards,
  26704. getNextPosFn(caretPosition)
  26705. )
  26706. var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range)
  26707. if (!nextCaretPosition) {
  26708. return rangeIsInContainerBlock ? Optional.some(range) : Optional.none()
  26709. }
  26710. if (isBeforeFn(nextCaretPosition)) {
  26711. return showCaret(
  26712. direction,
  26713. editor,
  26714. nextCaretPosition.getNode(!forwards),
  26715. forwards,
  26716. false
  26717. )
  26718. }
  26719. var peekCaretPosition = getNextPosFn(nextCaretPosition)
  26720. if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
  26721. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  26722. return showCaret(
  26723. direction,
  26724. editor,
  26725. peekCaretPosition.getNode(!forwards),
  26726. forwards,
  26727. false
  26728. )
  26729. }
  26730. }
  26731. if (rangeIsInContainerBlock) {
  26732. return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false)
  26733. }
  26734. return Optional.none()
  26735. }
  26736. var moveVertically = function (
  26737. editor,
  26738. direction,
  26739. range,
  26740. isBefore,
  26741. isAfter,
  26742. isElement
  26743. ) {
  26744. var caretPosition = getNormalizedRangeEndPoint(
  26745. direction,
  26746. editor.getBody(),
  26747. range
  26748. )
  26749. var caretClientRect = last$1(caretPosition.getClientRects())
  26750. var forwards = direction === VDirection.Down
  26751. if (!caretClientRect) {
  26752. return Optional.none()
  26753. }
  26754. var walkerFn = forwards ? downUntil : upUntil
  26755. var linePositions = walkerFn(
  26756. editor.getBody(),
  26757. isAboveLine(1),
  26758. caretPosition
  26759. )
  26760. var nextLinePositions = filter$4(linePositions, isLine(1))
  26761. var clientX = caretClientRect.left
  26762. var nextLineRect = findClosestClientRect(nextLinePositions, clientX)
  26763. if (nextLineRect && isElement(nextLineRect.node)) {
  26764. var dist1 = Math.abs(clientX - nextLineRect.left)
  26765. var dist2 = Math.abs(clientX - nextLineRect.right)
  26766. return showCaret(
  26767. direction,
  26768. editor,
  26769. nextLineRect.node,
  26770. dist1 < dist2,
  26771. false
  26772. )
  26773. }
  26774. var currentNode
  26775. if (isBefore(caretPosition)) {
  26776. currentNode = caretPosition.getNode()
  26777. } else if (isAfter(caretPosition)) {
  26778. currentNode = caretPosition.getNode(true)
  26779. } else {
  26780. currentNode = getSelectedNode(range)
  26781. }
  26782. if (currentNode) {
  26783. var caretPositions = positionsUntil(
  26784. direction,
  26785. editor.getBody(),
  26786. isAboveLine(1),
  26787. currentNode
  26788. )
  26789. var closestNextLineRect = findClosestClientRect(
  26790. filter$4(caretPositions, isLine(1)),
  26791. clientX
  26792. )
  26793. if (closestNextLineRect) {
  26794. return renderRangeCaretOpt(
  26795. editor,
  26796. closestNextLineRect.position.toRange(),
  26797. false
  26798. )
  26799. }
  26800. closestNextLineRect = last$1(filter$4(caretPositions, isLine(0)))
  26801. if (closestNextLineRect) {
  26802. return renderRangeCaretOpt(
  26803. editor,
  26804. closestNextLineRect.position.toRange(),
  26805. false
  26806. )
  26807. }
  26808. }
  26809. if (nextLinePositions.length === 0) {
  26810. return getLineEndPoint(editor, forwards)
  26811. .filter(forwards ? isAfter : isBefore)
  26812. .map(function (pos) {
  26813. return renderRangeCaret(editor, pos.toRange(), false)
  26814. })
  26815. }
  26816. return Optional.none()
  26817. }
  26818. var getLineEndPoint = function (editor, forward) {
  26819. var rng = editor.selection.getRng()
  26820. var body = editor.getBody()
  26821. if (forward) {
  26822. var from = CaretPosition.fromRangeEnd(rng)
  26823. var result = getPositionsUntilNextLine(body, from)
  26824. return last$2(result.positions)
  26825. } else {
  26826. var from = CaretPosition.fromRangeStart(rng)
  26827. var result = getPositionsUntilPreviousLine(body, from)
  26828. return head(result.positions)
  26829. }
  26830. }
  26831. var moveToLineEndPoint$3 = function (editor, forward, isElementPosition) {
  26832. return getLineEndPoint(editor, forward)
  26833. .filter(isElementPosition)
  26834. .exists(function (pos) {
  26835. editor.selection.setRng(pos.toRange())
  26836. return true
  26837. })
  26838. }
  26839. var setCaretPosition = function (editor, pos) {
  26840. var rng = editor.dom.createRng()
  26841. rng.setStart(pos.container(), pos.offset())
  26842. rng.setEnd(pos.container(), pos.offset())
  26843. editor.selection.setRng(rng)
  26844. }
  26845. var setSelected = function (state, elm) {
  26846. if (state) {
  26847. elm.setAttribute('data-mce-selected', 'inline-boundary')
  26848. } else {
  26849. elm.removeAttribute('data-mce-selected')
  26850. }
  26851. }
  26852. var renderCaretLocation = function (editor, caret, location) {
  26853. return renderCaret(caret, location).map(function (pos) {
  26854. setCaretPosition(editor, pos)
  26855. return location
  26856. })
  26857. }
  26858. var findLocation = function (editor, caret, forward) {
  26859. var rootNode = editor.getBody()
  26860. var from = CaretPosition.fromRangeStart(editor.selection.getRng())
  26861. var isInlineTarget$1 = curry(isInlineTarget, editor)
  26862. var location = findLocation$1(forward, isInlineTarget$1, rootNode, from)
  26863. return location.bind(function (location) {
  26864. return renderCaretLocation(editor, caret, location)
  26865. })
  26866. }
  26867. var toggleInlines = function (isInlineTarget, dom, elms) {
  26868. var inlineBoundaries = map$3(
  26869. descendants(
  26870. SugarElement.fromDom(dom.getRoot()),
  26871. '*[data-mce-selected="inline-boundary"]'
  26872. ),
  26873. function (e) {
  26874. return e.dom
  26875. }
  26876. )
  26877. var selectedInlines = filter$4(inlineBoundaries, isInlineTarget)
  26878. var targetInlines = filter$4(elms, isInlineTarget)
  26879. each$k(
  26880. difference(selectedInlines, targetInlines),
  26881. curry(setSelected, false)
  26882. )
  26883. each$k(difference(targetInlines, selectedInlines), curry(setSelected, true))
  26884. }
  26885. var safeRemoveCaretContainer = function (editor, caret) {
  26886. if (
  26887. editor.selection.isCollapsed() &&
  26888. editor.composing !== true &&
  26889. caret.get()
  26890. ) {
  26891. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  26892. if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) {
  26893. setCaretPosition(editor, removeAndReposition(caret.get(), pos))
  26894. caret.set(null)
  26895. }
  26896. }
  26897. }
  26898. var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) {
  26899. if (editor.selection.isCollapsed()) {
  26900. var inlines = filter$4(elms, isInlineTarget)
  26901. each$k(inlines, function (_inline) {
  26902. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  26903. readLocation(isInlineTarget, editor.getBody(), pos).bind(function (
  26904. location
  26905. ) {
  26906. return renderCaretLocation(editor, caret, location)
  26907. })
  26908. })
  26909. }
  26910. }
  26911. var move$2 = function (editor, caret, forward) {
  26912. return isInlineBoundariesEnabled(editor)
  26913. ? findLocation(editor, caret, forward).isSome()
  26914. : false
  26915. }
  26916. var moveWord = function (forward, editor, _caret) {
  26917. return isInlineBoundariesEnabled(editor)
  26918. ? moveByWord(forward, editor)
  26919. : false
  26920. }
  26921. var setupSelectedState = function (editor) {
  26922. var caret = Cell(null)
  26923. var isInlineTarget$1 = curry(isInlineTarget, editor)
  26924. editor.on('NodeChange', function (e) {
  26925. if (
  26926. isInlineBoundariesEnabled(editor) &&
  26927. !(Env.browser.isIE() && e.initial)
  26928. ) {
  26929. toggleInlines(isInlineTarget$1, editor.dom, e.parents)
  26930. safeRemoveCaretContainer(editor, caret)
  26931. renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents)
  26932. }
  26933. })
  26934. return caret
  26935. }
  26936. var moveNextWord = curry(moveWord, true)
  26937. var movePrevWord = curry(moveWord, false)
  26938. var moveToLineEndPoint$2 = function (editor, forward, caret) {
  26939. if (isInlineBoundariesEnabled(editor)) {
  26940. var linePoint = getLineEndPoint(editor, forward).getOrThunk(function () {
  26941. var rng = editor.selection.getRng()
  26942. return forward
  26943. ? CaretPosition.fromRangeEnd(rng)
  26944. : CaretPosition.fromRangeStart(rng)
  26945. })
  26946. return readLocation(
  26947. curry(isInlineTarget, editor),
  26948. editor.getBody(),
  26949. linePoint
  26950. ).exists(function (loc) {
  26951. var outsideLoc = outside(loc)
  26952. return renderCaret(caret, outsideLoc).exists(function (pos) {
  26953. setCaretPosition(editor, pos)
  26954. return true
  26955. })
  26956. })
  26957. } else {
  26958. return false
  26959. }
  26960. }
  26961. var rangeFromPositions = function (from, to) {
  26962. var range = document.createRange()
  26963. range.setStart(from.container(), from.offset())
  26964. range.setEnd(to.container(), to.offset())
  26965. return range
  26966. }
  26967. var hasOnlyTwoOrLessPositionsLeft = function (elm) {
  26968. return lift2(
  26969. firstPositionIn(elm),
  26970. lastPositionIn(elm),
  26971. function (firstPos, lastPos) {
  26972. var normalizedFirstPos = normalizePosition(true, firstPos)
  26973. var normalizedLastPos = normalizePosition(false, lastPos)
  26974. return nextPosition(elm, normalizedFirstPos).forall(function (pos) {
  26975. return pos.isEqual(normalizedLastPos)
  26976. })
  26977. }
  26978. ).getOr(true)
  26979. }
  26980. var setCaretLocation = function (editor, caret) {
  26981. return function (location) {
  26982. return renderCaret(caret, location).exists(function (pos) {
  26983. setCaretPosition(editor, pos)
  26984. return true
  26985. })
  26986. }
  26987. }
  26988. var deleteFromTo = function (editor, caret, from, to) {
  26989. var rootNode = editor.getBody()
  26990. var isInlineTarget$1 = curry(isInlineTarget, editor)
  26991. editor.undoManager.ignore(function () {
  26992. editor.selection.setRng(rangeFromPositions(from, to))
  26993. editor.execCommand('Delete')
  26994. readLocation(
  26995. isInlineTarget$1,
  26996. rootNode,
  26997. CaretPosition.fromRangeStart(editor.selection.getRng())
  26998. )
  26999. .map(inside)
  27000. .map(setCaretLocation(editor, caret))
  27001. })
  27002. editor.nodeChanged()
  27003. }
  27004. var rescope = function (rootNode, node) {
  27005. var parentBlock = getParentBlock$2(node, rootNode)
  27006. return parentBlock ? parentBlock : rootNode
  27007. }
  27008. var backspaceDeleteCollapsed = function (editor, caret, forward, from) {
  27009. var rootNode = rescope(editor.getBody(), from.container())
  27010. var isInlineTarget$1 = curry(isInlineTarget, editor)
  27011. var fromLocation = readLocation(isInlineTarget$1, rootNode, from)
  27012. return fromLocation
  27013. .bind(function (location) {
  27014. if (forward) {
  27015. return location.fold(
  27016. constant(Optional.some(inside(location))),
  27017. Optional.none,
  27018. constant(Optional.some(outside(location))),
  27019. Optional.none
  27020. )
  27021. } else {
  27022. return location.fold(
  27023. Optional.none,
  27024. constant(Optional.some(outside(location))),
  27025. Optional.none,
  27026. constant(Optional.some(inside(location)))
  27027. )
  27028. }
  27029. })
  27030. .map(setCaretLocation(editor, caret))
  27031. .getOrThunk(function () {
  27032. var toPosition = navigate(forward, rootNode, from)
  27033. var toLocation = toPosition.bind(function (pos) {
  27034. return readLocation(isInlineTarget$1, rootNode, pos)
  27035. })
  27036. return lift2(fromLocation, toLocation, function () {
  27037. return findRootInline(isInlineTarget$1, rootNode, from).exists(
  27038. function (elm) {
  27039. if (hasOnlyTwoOrLessPositionsLeft(elm)) {
  27040. deleteElement$2(editor, forward, SugarElement.fromDom(elm))
  27041. return true
  27042. } else {
  27043. return false
  27044. }
  27045. }
  27046. )
  27047. })
  27048. .orThunk(function () {
  27049. return toLocation.bind(function (_) {
  27050. return toPosition.map(function (to) {
  27051. if (forward) {
  27052. deleteFromTo(editor, caret, from, to)
  27053. } else {
  27054. deleteFromTo(editor, caret, to, from)
  27055. }
  27056. return true
  27057. })
  27058. })
  27059. })
  27060. .getOr(false)
  27061. })
  27062. }
  27063. var backspaceDelete$3 = function (editor, caret, forward) {
  27064. if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) {
  27065. var from = CaretPosition.fromRangeStart(editor.selection.getRng())
  27066. return backspaceDeleteCollapsed(editor, caret, forward, from)
  27067. }
  27068. return false
  27069. }
  27070. var getParentInlines = function (rootElm, startElm) {
  27071. var parents = parentsAndSelf(startElm, rootElm)
  27072. return findIndex$2(parents, isBlock$2).fold(
  27073. constant(parents),
  27074. function (index) {
  27075. return parents.slice(0, index)
  27076. }
  27077. )
  27078. }
  27079. var hasOnlyOneChild = function (elm) {
  27080. return childNodesCount(elm) === 1
  27081. }
  27082. var deleteLastPosition = function (forward, editor, target, parentInlines) {
  27083. var isFormatElement$1 = curry(isFormatElement, editor)
  27084. var formatNodes = map$3(
  27085. filter$4(parentInlines, isFormatElement$1),
  27086. function (elm) {
  27087. return elm.dom
  27088. }
  27089. )
  27090. if (formatNodes.length === 0) {
  27091. deleteElement$2(editor, forward, target)
  27092. } else {
  27093. var pos = replaceWithCaretFormat(target.dom, formatNodes)
  27094. editor.selection.setRng(pos.toRange())
  27095. }
  27096. }
  27097. var deleteCaret$1 = function (editor, forward) {
  27098. var rootElm = SugarElement.fromDom(editor.getBody())
  27099. var startElm = SugarElement.fromDom(editor.selection.getStart())
  27100. var parentInlines = filter$4(
  27101. getParentInlines(rootElm, startElm),
  27102. hasOnlyOneChild
  27103. )
  27104. return last$2(parentInlines).exists(function (target) {
  27105. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng())
  27106. if (
  27107. willDeleteLastPositionInElement(forward, fromPos, target.dom) &&
  27108. !isEmptyCaretFormatElement(target)
  27109. ) {
  27110. deleteLastPosition(forward, editor, target, parentInlines)
  27111. return true
  27112. } else {
  27113. return false
  27114. }
  27115. })
  27116. }
  27117. var backspaceDelete$2 = function (editor, forward) {
  27118. return editor.selection.isCollapsed()
  27119. ? deleteCaret$1(editor, forward)
  27120. : false
  27121. }
  27122. var deleteElement = function (editor, forward, element) {
  27123. editor._selectionOverrides.hideFakeCaret()
  27124. deleteElement$2(editor, forward, SugarElement.fromDom(element))
  27125. return true
  27126. }
  27127. var deleteCaret = function (editor, forward) {
  27128. var isNearMedia = forward ? isBeforeMedia : isAfterMedia
  27129. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  27130. var fromPos = getNormalizedRangeEndPoint(
  27131. direction,
  27132. editor.getBody(),
  27133. editor.selection.getRng()
  27134. )
  27135. if (isNearMedia(fromPos)) {
  27136. return deleteElement(editor, forward, fromPos.getNode(!forward))
  27137. } else {
  27138. return Optional.from(normalizePosition(forward, fromPos))
  27139. .filter(function (pos) {
  27140. return isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos)
  27141. })
  27142. .exists(function (pos) {
  27143. return deleteElement(editor, forward, pos.getNode(!forward))
  27144. })
  27145. }
  27146. }
  27147. var deleteRange = function (editor, forward) {
  27148. var selectedNode = editor.selection.getNode()
  27149. return isMedia$2(selectedNode)
  27150. ? deleteElement(editor, forward, selectedNode)
  27151. : false
  27152. }
  27153. var backspaceDelete$1 = function (editor, forward) {
  27154. return editor.selection.isCollapsed()
  27155. ? deleteCaret(editor, forward)
  27156. : deleteRange(editor, forward)
  27157. }
  27158. var isEditable = function (target) {
  27159. return closest$3(target, function (elm) {
  27160. return (
  27161. isContentEditableTrue$4(elm.dom) || isContentEditableFalse$b(elm.dom)
  27162. )
  27163. }).exists(function (elm) {
  27164. return isContentEditableTrue$4(elm.dom)
  27165. })
  27166. }
  27167. var parseIndentValue = function (value) {
  27168. var number = parseInt(value, 10)
  27169. return isNaN(number) ? 0 : number
  27170. }
  27171. var getIndentStyleName = function (useMargin, element) {
  27172. var indentStyleName = useMargin || isTable$2(element) ? 'margin' : 'padding'
  27173. var suffix = get$5(element, 'direction') === 'rtl' ? '-right' : '-left'
  27174. return indentStyleName + suffix
  27175. }
  27176. var indentElement = function (dom, command, useMargin, value, unit, element) {
  27177. var indentStyleName = getIndentStyleName(
  27178. useMargin,
  27179. SugarElement.fromDom(element)
  27180. )
  27181. if (command === 'outdent') {
  27182. var styleValue = Math.max(
  27183. 0,
  27184. parseIndentValue(element.style[indentStyleName]) - value
  27185. )
  27186. dom.setStyle(
  27187. element,
  27188. indentStyleName,
  27189. styleValue ? styleValue + unit : ''
  27190. )
  27191. } else {
  27192. var styleValue =
  27193. parseIndentValue(element.style[indentStyleName]) + value + unit
  27194. dom.setStyle(element, indentStyleName, styleValue)
  27195. }
  27196. }
  27197. var validateBlocks = function (editor, blocks) {
  27198. return forall(blocks, function (block) {
  27199. var indentStyleName = getIndentStyleName(
  27200. shouldIndentUseMargin(editor),
  27201. block
  27202. )
  27203. var intentValue = getRaw(block, indentStyleName)
  27204. .map(parseIndentValue)
  27205. .getOr(0)
  27206. var contentEditable = editor.dom.getContentEditable(block.dom)
  27207. return contentEditable !== 'false' && intentValue > 0
  27208. })
  27209. }
  27210. var canOutdent = function (editor) {
  27211. var blocks = getBlocksToIndent(editor)
  27212. return (
  27213. !editor.mode.isReadOnly() &&
  27214. (blocks.length > 1 || validateBlocks(editor, blocks))
  27215. )
  27216. }
  27217. var isListComponent = function (el) {
  27218. return isList(el) || isListItem(el)
  27219. }
  27220. var parentIsListComponent = function (el) {
  27221. return parent(el).exists(isListComponent)
  27222. }
  27223. var getBlocksToIndent = function (editor) {
  27224. return filter$4(
  27225. fromDom$1(editor.selection.getSelectedBlocks()),
  27226. function (el) {
  27227. return (
  27228. !isListComponent(el) && !parentIsListComponent(el) && isEditable(el)
  27229. )
  27230. }
  27231. )
  27232. }
  27233. var handle = function (editor, command) {
  27234. var dom = editor.dom,
  27235. selection = editor.selection,
  27236. formatter = editor.formatter
  27237. var indentation = getIndentation(editor)
  27238. var indentUnit = /[a-z%]+$/i.exec(indentation)[0]
  27239. var indentValue = parseInt(indentation, 10)
  27240. var useMargin = shouldIndentUseMargin(editor)
  27241. var forcedRootBlock = getForcedRootBlock(editor)
  27242. if (
  27243. !editor.queryCommandState('InsertUnorderedList') &&
  27244. !editor.queryCommandState('InsertOrderedList')
  27245. ) {
  27246. if (
  27247. forcedRootBlock === '' &&
  27248. !dom.getParent(selection.getNode(), dom.isBlock)
  27249. ) {
  27250. formatter.apply('div')
  27251. }
  27252. }
  27253. each$k(getBlocksToIndent(editor), function (block) {
  27254. indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom)
  27255. })
  27256. }
  27257. var backspaceDelete = function (editor, _forward) {
  27258. if (editor.selection.isCollapsed() && canOutdent(editor)) {
  27259. var dom = editor.dom
  27260. var rng = editor.selection.getRng()
  27261. var pos = CaretPosition.fromRangeStart(rng)
  27262. var block = dom.getParent(rng.startContainer, dom.isBlock)
  27263. if (
  27264. block !== null &&
  27265. isAtStartOfBlock(SugarElement.fromDom(block), pos)
  27266. ) {
  27267. handle(editor, 'outdent')
  27268. return true
  27269. }
  27270. }
  27271. return false
  27272. }
  27273. var nativeCommand = function (editor, command) {
  27274. editor.getDoc().execCommand(command, false, null)
  27275. }
  27276. var deleteCommand = function (editor, caret) {
  27277. if (backspaceDelete(editor)) {
  27278. return
  27279. } else if (backspaceDelete$5(editor, false)) {
  27280. return
  27281. } else if (backspaceDelete$6(editor, false)) {
  27282. return
  27283. } else if (backspaceDelete$3(editor, caret, false)) {
  27284. return
  27285. } else if (backspaceDelete$8(editor, false)) {
  27286. return
  27287. } else if (backspaceDelete$9(editor)) {
  27288. return
  27289. } else if (backspaceDelete$4(editor, false)) {
  27290. return
  27291. } else if (backspaceDelete$1(editor, false)) {
  27292. return
  27293. } else if (backspaceDelete$7(editor)) {
  27294. return
  27295. } else if (backspaceDelete$2(editor, false)) {
  27296. return
  27297. } else {
  27298. nativeCommand(editor, 'Delete')
  27299. paddEmptyBody(editor)
  27300. }
  27301. }
  27302. var forwardDeleteCommand = function (editor, caret) {
  27303. if (backspaceDelete$5(editor, true)) {
  27304. return
  27305. } else if (backspaceDelete$6(editor, true)) {
  27306. return
  27307. } else if (backspaceDelete$3(editor, caret, true)) {
  27308. return
  27309. } else if (backspaceDelete$8(editor, true)) {
  27310. return
  27311. } else if (backspaceDelete$9(editor)) {
  27312. return
  27313. } else if (backspaceDelete$4(editor, true)) {
  27314. return
  27315. } else if (backspaceDelete$1(editor, true)) {
  27316. return
  27317. } else if (backspaceDelete$7(editor)) {
  27318. return
  27319. } else if (backspaceDelete$2(editor, true)) {
  27320. return
  27321. } else {
  27322. nativeCommand(editor, 'ForwardDelete')
  27323. }
  27324. }
  27325. var setup$f = function (editor, caret) {
  27326. editor.addCommand('delete', function () {
  27327. deleteCommand(editor, caret)
  27328. })
  27329. editor.addCommand('forwardDelete', function () {
  27330. forwardDeleteCommand(editor, caret)
  27331. })
  27332. }
  27333. var SIGNIFICANT_MOVE = 5
  27334. var LONGPRESS_DELAY = 400
  27335. var getTouch = function (event) {
  27336. if (event.touches === undefined || event.touches.length !== 1) {
  27337. return Optional.none()
  27338. }
  27339. return Optional.some(event.touches[0])
  27340. }
  27341. var isFarEnough = function (touch, data) {
  27342. var distX = Math.abs(touch.clientX - data.x)
  27343. var distY = Math.abs(touch.clientY - data.y)
  27344. return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE
  27345. }
  27346. var setup$e = function (editor) {
  27347. var startData = value()
  27348. var longpressFired = Cell(false)
  27349. var debounceLongpress = last(function (e) {
  27350. editor.fire('longpress', __assign(__assign({}, e), { type: 'longpress' }))
  27351. longpressFired.set(true)
  27352. }, LONGPRESS_DELAY)
  27353. editor.on(
  27354. 'touchstart',
  27355. function (e) {
  27356. getTouch(e).each(function (touch) {
  27357. debounceLongpress.cancel()
  27358. var data = {
  27359. x: touch.clientX,
  27360. y: touch.clientY,
  27361. target: e.target,
  27362. }
  27363. debounceLongpress.throttle(e)
  27364. longpressFired.set(false)
  27365. startData.set(data)
  27366. })
  27367. },
  27368. true
  27369. )
  27370. editor.on(
  27371. 'touchmove',
  27372. function (e) {
  27373. debounceLongpress.cancel()
  27374. getTouch(e).each(function (touch) {
  27375. startData.on(function (data) {
  27376. if (isFarEnough(touch, data)) {
  27377. startData.clear()
  27378. longpressFired.set(false)
  27379. editor.fire('longpresscancel')
  27380. }
  27381. })
  27382. })
  27383. },
  27384. true
  27385. )
  27386. editor.on(
  27387. 'touchend touchcancel',
  27388. function (e) {
  27389. debounceLongpress.cancel()
  27390. if (e.type === 'touchcancel') {
  27391. return
  27392. }
  27393. startData
  27394. .get()
  27395. .filter(function (data) {
  27396. return data.target.isEqualNode(e.target)
  27397. })
  27398. .each(function () {
  27399. if (longpressFired.get()) {
  27400. e.preventDefault()
  27401. } else {
  27402. editor.fire('tap', __assign(__assign({}, e), { type: 'tap' }))
  27403. }
  27404. })
  27405. },
  27406. true
  27407. )
  27408. }
  27409. var isBlockElement = function (blockElements, node) {
  27410. return has$2(blockElements, node.nodeName)
  27411. }
  27412. var isValidTarget = function (blockElements, node) {
  27413. if (isText$7(node)) {
  27414. return true
  27415. } else if (isElement$5(node)) {
  27416. return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node)
  27417. } else {
  27418. return false
  27419. }
  27420. }
  27421. var hasBlockParent = function (blockElements, root, node) {
  27422. return exists(
  27423. parents(SugarElement.fromDom(node), SugarElement.fromDom(root)),
  27424. function (elm) {
  27425. return isBlockElement(blockElements, elm.dom)
  27426. }
  27427. )
  27428. }
  27429. var shouldRemoveTextNode = function (blockElements, node) {
  27430. if (isText$7(node)) {
  27431. if (node.nodeValue.length === 0) {
  27432. return true
  27433. } else if (
  27434. /^\s+$/.test(node.nodeValue) &&
  27435. (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))
  27436. ) {
  27437. return true
  27438. }
  27439. }
  27440. return false
  27441. }
  27442. var addRootBlocks = function (editor) {
  27443. var dom = editor.dom,
  27444. selection = editor.selection
  27445. var schema = editor.schema,
  27446. blockElements = schema.getBlockElements()
  27447. var node = selection.getStart()
  27448. var rootNode = editor.getBody()
  27449. var rootBlockNode, tempNode, wrapped
  27450. var forcedRootBlock = getForcedRootBlock(editor)
  27451. if (!node || !isElement$5(node) || !forcedRootBlock) {
  27452. return
  27453. }
  27454. var rootNodeName = rootNode.nodeName.toLowerCase()
  27455. if (
  27456. !schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) ||
  27457. hasBlockParent(blockElements, rootNode, node)
  27458. ) {
  27459. return
  27460. }
  27461. var rng = selection.getRng()
  27462. var startContainer = rng.startContainer
  27463. var startOffset = rng.startOffset
  27464. var endContainer = rng.endContainer
  27465. var endOffset = rng.endOffset
  27466. var restoreSelection = hasFocus(editor)
  27467. node = rootNode.firstChild
  27468. while (node) {
  27469. if (isValidTarget(blockElements, node)) {
  27470. if (shouldRemoveTextNode(blockElements, node)) {
  27471. tempNode = node
  27472. node = node.nextSibling
  27473. dom.remove(tempNode)
  27474. continue
  27475. }
  27476. if (!rootBlockNode) {
  27477. rootBlockNode = dom.create(
  27478. forcedRootBlock,
  27479. getForcedRootBlockAttrs(editor)
  27480. )
  27481. node.parentNode.insertBefore(rootBlockNode, node)
  27482. wrapped = true
  27483. }
  27484. tempNode = node
  27485. node = node.nextSibling
  27486. rootBlockNode.appendChild(tempNode)
  27487. } else {
  27488. rootBlockNode = null
  27489. node = node.nextSibling
  27490. }
  27491. }
  27492. if (wrapped && restoreSelection) {
  27493. rng.setStart(startContainer, startOffset)
  27494. rng.setEnd(endContainer, endOffset)
  27495. selection.setRng(rng)
  27496. editor.nodeChanged()
  27497. }
  27498. }
  27499. var setup$d = function (editor) {
  27500. if (getForcedRootBlock(editor)) {
  27501. editor.on('NodeChange', curry(addRootBlocks, editor))
  27502. }
  27503. }
  27504. var findBlockCaretContainer = function (editor) {
  27505. return descendant(
  27506. SugarElement.fromDom(editor.getBody()),
  27507. '*[data-mce-caret]'
  27508. )
  27509. .map(function (elm) {
  27510. return elm.dom
  27511. })
  27512. .getOrNull()
  27513. }
  27514. var removeIeControlRect = function (editor) {
  27515. editor.selection.setRng(editor.selection.getRng())
  27516. }
  27517. var showBlockCaretContainer = function (editor, blockCaretContainer) {
  27518. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  27519. showCaretContainerBlock(blockCaretContainer)
  27520. removeIeControlRect(editor)
  27521. editor.selection.scrollIntoView(blockCaretContainer)
  27522. }
  27523. }
  27524. var handleBlockContainer = function (editor, e) {
  27525. var blockCaretContainer = findBlockCaretContainer(editor)
  27526. if (!blockCaretContainer) {
  27527. return
  27528. }
  27529. if (e.type === 'compositionstart') {
  27530. e.preventDefault()
  27531. e.stopPropagation()
  27532. showBlockCaretContainer(editor, blockCaretContainer)
  27533. return
  27534. }
  27535. if (hasContent(blockCaretContainer)) {
  27536. showBlockCaretContainer(editor, blockCaretContainer)
  27537. editor.undoManager.add()
  27538. }
  27539. }
  27540. var setup$c = function (editor) {
  27541. editor.on('keyup compositionstart', curry(handleBlockContainer, editor))
  27542. }
  27543. var isContentEditableFalse$2 = isContentEditableFalse$b
  27544. var moveToCeFalseHorizontally = function (direction, editor, range) {
  27545. return moveHorizontally(
  27546. editor,
  27547. direction,
  27548. range,
  27549. isBeforeContentEditableFalse,
  27550. isAfterContentEditableFalse,
  27551. isContentEditableFalse$2
  27552. )
  27553. }
  27554. var moveToCeFalseVertically = function (direction, editor, range) {
  27555. var isBefore = function (caretPosition) {
  27556. return (
  27557. isBeforeContentEditableFalse(caretPosition) ||
  27558. isBeforeTable(caretPosition)
  27559. )
  27560. }
  27561. var isAfter = function (caretPosition) {
  27562. return (
  27563. isAfterContentEditableFalse(caretPosition) ||
  27564. isAfterTable(caretPosition)
  27565. )
  27566. }
  27567. return moveVertically(
  27568. editor,
  27569. direction,
  27570. range,
  27571. isBefore,
  27572. isAfter,
  27573. isContentEditableFalse$2
  27574. )
  27575. }
  27576. var createTextBlock = function (editor) {
  27577. var textBlock = editor.dom.create(getForcedRootBlock(editor))
  27578. if (!Env.ie || Env.ie >= 11) {
  27579. textBlock.innerHTML = '<br data-mce-bogus="1">'
  27580. }
  27581. return textBlock
  27582. }
  27583. var exitPreBlock = function (editor, direction, range) {
  27584. var caretWalker = CaretWalker(editor.getBody())
  27585. var getVisualCaretPosition$1 = curry(
  27586. getVisualCaretPosition,
  27587. direction === 1 ? caretWalker.next : caretWalker.prev
  27588. )
  27589. if (range.collapsed && hasForcedRootBlock(editor)) {
  27590. var pre = editor.dom.getParent(range.startContainer, 'PRE')
  27591. if (!pre) {
  27592. return
  27593. }
  27594. var caretPos = getVisualCaretPosition$1(
  27595. CaretPosition.fromRangeStart(range)
  27596. )
  27597. if (!caretPos) {
  27598. var newBlock = createTextBlock(editor)
  27599. if (direction === 1) {
  27600. editor.$(pre).after(newBlock)
  27601. } else {
  27602. editor.$(pre).before(newBlock)
  27603. }
  27604. editor.selection.select(newBlock, true)
  27605. editor.selection.collapse()
  27606. }
  27607. }
  27608. }
  27609. var getHorizontalRange = function (editor, forward) {
  27610. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  27611. var range = editor.selection.getRng()
  27612. return moveToCeFalseHorizontally(direction, editor, range).orThunk(
  27613. function () {
  27614. exitPreBlock(editor, direction, range)
  27615. return Optional.none()
  27616. }
  27617. )
  27618. }
  27619. var getVerticalRange = function (editor, down) {
  27620. var direction = down ? 1 : -1
  27621. var range = editor.selection.getRng()
  27622. return moveToCeFalseVertically(direction, editor, range).orThunk(
  27623. function () {
  27624. exitPreBlock(editor, direction, range)
  27625. return Optional.none()
  27626. }
  27627. )
  27628. }
  27629. var moveH$2 = function (editor, forward) {
  27630. return getHorizontalRange(editor, forward).exists(function (newRange) {
  27631. moveToRange(editor, newRange)
  27632. return true
  27633. })
  27634. }
  27635. var moveV$3 = function (editor, down) {
  27636. return getVerticalRange(editor, down).exists(function (newRange) {
  27637. moveToRange(editor, newRange)
  27638. return true
  27639. })
  27640. }
  27641. var moveToLineEndPoint$1 = function (editor, forward) {
  27642. var isCefPosition = forward
  27643. ? isAfterContentEditableFalse
  27644. : isBeforeContentEditableFalse
  27645. return moveToLineEndPoint$3(editor, forward, isCefPosition)
  27646. }
  27647. var isTarget = function (node) {
  27648. return contains$3(['figcaption'], name(node))
  27649. }
  27650. var rangeBefore = function (target) {
  27651. var rng = document.createRange()
  27652. rng.setStartBefore(target.dom)
  27653. rng.setEndBefore(target.dom)
  27654. return rng
  27655. }
  27656. var insertElement = function (root, elm, forward) {
  27657. if (forward) {
  27658. append$1(root, elm)
  27659. } else {
  27660. prepend(root, elm)
  27661. }
  27662. }
  27663. var insertBr = function (root, forward) {
  27664. var br = SugarElement.fromTag('br')
  27665. insertElement(root, br, forward)
  27666. return rangeBefore(br)
  27667. }
  27668. var insertBlock = function (root, forward, blockName, attrs) {
  27669. var block = SugarElement.fromTag(blockName)
  27670. var br = SugarElement.fromTag('br')
  27671. setAll$1(block, attrs)
  27672. append$1(block, br)
  27673. insertElement(root, block, forward)
  27674. return rangeBefore(br)
  27675. }
  27676. var insertEmptyLine = function (root, rootBlockName, attrs, forward) {
  27677. if (rootBlockName === '') {
  27678. return insertBr(root, forward)
  27679. } else {
  27680. return insertBlock(root, forward, rootBlockName, attrs)
  27681. }
  27682. }
  27683. var getClosestTargetBlock = function (pos, root) {
  27684. var isRoot = curry(eq, root)
  27685. return closest$3(
  27686. SugarElement.fromDom(pos.container()),
  27687. isBlock$2,
  27688. isRoot
  27689. ).filter(isTarget)
  27690. }
  27691. var isAtFirstOrLastLine = function (root, forward, pos) {
  27692. return forward ? isAtLastLine(root.dom, pos) : isAtFirstLine(root.dom, pos)
  27693. }
  27694. var moveCaretToNewEmptyLine = function (editor, forward) {
  27695. var root = SugarElement.fromDom(editor.getBody())
  27696. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  27697. var rootBlock = getForcedRootBlock(editor)
  27698. var rootBlockAttrs = getForcedRootBlockAttrs(editor)
  27699. return getClosestTargetBlock(pos, root).exists(function () {
  27700. if (isAtFirstOrLastLine(root, forward, pos)) {
  27701. var rng = insertEmptyLine(root, rootBlock, rootBlockAttrs, forward)
  27702. editor.selection.setRng(rng)
  27703. return true
  27704. } else {
  27705. return false
  27706. }
  27707. })
  27708. }
  27709. var moveV$2 = function (editor, forward) {
  27710. if (editor.selection.isCollapsed()) {
  27711. return moveCaretToNewEmptyLine(editor, forward)
  27712. } else {
  27713. return false
  27714. }
  27715. }
  27716. var defaultPatterns = function (patterns) {
  27717. return map$3(patterns, function (pattern) {
  27718. return __assign(
  27719. {
  27720. shiftKey: false,
  27721. altKey: false,
  27722. ctrlKey: false,
  27723. metaKey: false,
  27724. keyCode: 0,
  27725. action: noop,
  27726. },
  27727. pattern
  27728. )
  27729. })
  27730. }
  27731. var matchesEvent = function (pattern, evt) {
  27732. return (
  27733. evt.keyCode === pattern.keyCode &&
  27734. evt.shiftKey === pattern.shiftKey &&
  27735. evt.altKey === pattern.altKey &&
  27736. evt.ctrlKey === pattern.ctrlKey &&
  27737. evt.metaKey === pattern.metaKey
  27738. )
  27739. }
  27740. var match$1 = function (patterns, evt) {
  27741. return bind(defaultPatterns(patterns), function (pattern) {
  27742. return matchesEvent(pattern, evt) ? [pattern] : []
  27743. })
  27744. }
  27745. var action = function (f) {
  27746. var x = []
  27747. for (var _i = 1; _i < arguments.length; _i++) {
  27748. x[_i - 1] = arguments[_i]
  27749. }
  27750. return function () {
  27751. return f.apply(null, x)
  27752. }
  27753. }
  27754. var execute = function (patterns, evt) {
  27755. return find$3(match$1(patterns, evt), function (pattern) {
  27756. return pattern.action()
  27757. })
  27758. }
  27759. var moveH$1 = function (editor, forward) {
  27760. var direction = forward ? HDirection.Forwards : HDirection.Backwards
  27761. var range = editor.selection.getRng()
  27762. return moveHorizontally(
  27763. editor,
  27764. direction,
  27765. range,
  27766. isBeforeMedia,
  27767. isAfterMedia,
  27768. isMedia$2
  27769. ).exists(function (newRange) {
  27770. moveToRange(editor, newRange)
  27771. return true
  27772. })
  27773. }
  27774. var moveV$1 = function (editor, down) {
  27775. var direction = down ? 1 : -1
  27776. var range = editor.selection.getRng()
  27777. return moveVertically(
  27778. editor,
  27779. direction,
  27780. range,
  27781. isBeforeMedia,
  27782. isAfterMedia,
  27783. isMedia$2
  27784. ).exists(function (newRange) {
  27785. moveToRange(editor, newRange)
  27786. return true
  27787. })
  27788. }
  27789. var moveToLineEndPoint = function (editor, forward) {
  27790. var isNearMedia = forward ? isAfterMedia : isBeforeMedia
  27791. return moveToLineEndPoint$3(editor, forward, isNearMedia)
  27792. }
  27793. var deflate = function (rect, delta) {
  27794. return {
  27795. left: rect.left - delta,
  27796. top: rect.top - delta,
  27797. right: rect.right + delta * 2,
  27798. bottom: rect.bottom + delta * 2,
  27799. width: rect.width + delta,
  27800. height: rect.height + delta,
  27801. }
  27802. }
  27803. var getCorners = function (getYAxisValue, tds) {
  27804. return bind(tds, function (td) {
  27805. var rect = deflate(clone(td.getBoundingClientRect()), -1)
  27806. return [
  27807. {
  27808. x: rect.left,
  27809. y: getYAxisValue(rect),
  27810. cell: td,
  27811. },
  27812. {
  27813. x: rect.right,
  27814. y: getYAxisValue(rect),
  27815. cell: td,
  27816. },
  27817. ]
  27818. })
  27819. }
  27820. var findClosestCorner = function (corners, x, y) {
  27821. return foldl(
  27822. corners,
  27823. function (acc, newCorner) {
  27824. return acc.fold(
  27825. function () {
  27826. return Optional.some(newCorner)
  27827. },
  27828. function (oldCorner) {
  27829. var oldDist = Math.sqrt(
  27830. Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y)
  27831. )
  27832. var newDist = Math.sqrt(
  27833. Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y)
  27834. )
  27835. return Optional.some(newDist < oldDist ? newCorner : oldCorner)
  27836. }
  27837. )
  27838. },
  27839. Optional.none()
  27840. )
  27841. }
  27842. var getClosestCell = function (getYAxisValue, isTargetCorner, table, x, y) {
  27843. var cells = descendants(SugarElement.fromDom(table), 'td,th,caption').map(
  27844. function (e) {
  27845. return e.dom
  27846. }
  27847. )
  27848. var corners = filter$4(getCorners(getYAxisValue, cells), function (corner) {
  27849. return isTargetCorner(corner, y)
  27850. })
  27851. return findClosestCorner(corners, x, y).map(function (corner) {
  27852. return corner.cell
  27853. })
  27854. }
  27855. var getBottomValue = function (rect) {
  27856. return rect.bottom
  27857. }
  27858. var getTopValue = function (rect) {
  27859. return rect.top
  27860. }
  27861. var isAbove = function (corner, y) {
  27862. return corner.y < y
  27863. }
  27864. var isBelow = function (corner, y) {
  27865. return corner.y > y
  27866. }
  27867. var getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove)
  27868. var getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow)
  27869. var findClosestPositionInAboveCell = function (table, pos) {
  27870. return head(pos.getClientRects())
  27871. .bind(function (rect) {
  27872. return getClosestCellAbove(table, rect.left, rect.top)
  27873. })
  27874. .bind(function (cell) {
  27875. return findClosestHorizontalPosition(getLastLinePositions(cell), pos)
  27876. })
  27877. }
  27878. var findClosestPositionInBelowCell = function (table, pos) {
  27879. return last$2(pos.getClientRects())
  27880. .bind(function (rect) {
  27881. return getClosestCellBelow(table, rect.left, rect.top)
  27882. })
  27883. .bind(function (cell) {
  27884. return findClosestHorizontalPosition(getFirstLinePositions(cell), pos)
  27885. })
  27886. }
  27887. var hasNextBreak = function (getPositionsUntil, scope, lineInfo) {
  27888. return lineInfo.breakAt.exists(function (breakPos) {
  27889. return getPositionsUntil(scope, breakPos).breakAt.isSome()
  27890. })
  27891. }
  27892. var startsWithWrapBreak = function (lineInfo) {
  27893. return (
  27894. lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0
  27895. )
  27896. }
  27897. var startsWithBrBreak = function (lineInfo) {
  27898. return (
  27899. lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1
  27900. )
  27901. }
  27902. var isAtTableCellLine = function (getPositionsUntil, scope, pos) {
  27903. var lineInfo = getPositionsUntil(scope, pos)
  27904. if (
  27905. startsWithWrapBreak(lineInfo) ||
  27906. (!isBr$5(pos.getNode()) && startsWithBrBreak(lineInfo))
  27907. ) {
  27908. return !hasNextBreak(getPositionsUntil, scope, lineInfo)
  27909. } else {
  27910. return lineInfo.breakAt.isNone()
  27911. }
  27912. }
  27913. var isAtFirstTableCellLine = curry(
  27914. isAtTableCellLine,
  27915. getPositionsUntilPreviousLine
  27916. )
  27917. var isAtLastTableCellLine = curry(
  27918. isAtTableCellLine,
  27919. getPositionsUntilNextLine
  27920. )
  27921. var isCaretAtStartOrEndOfTable = function (forward, rng, table) {
  27922. var caretPos = CaretPosition.fromRangeStart(rng)
  27923. return positionIn(!forward, table).exists(function (pos) {
  27924. return pos.isEqual(caretPos)
  27925. })
  27926. }
  27927. var navigateHorizontally = function (editor, forward, table, _td) {
  27928. var rng = editor.selection.getRng()
  27929. var direction = forward ? 1 : -1
  27930. if (
  27931. isFakeCaretTableBrowser() &&
  27932. isCaretAtStartOrEndOfTable(forward, rng, table)
  27933. ) {
  27934. showCaret(direction, editor, table, !forward, false).each(function (
  27935. newRng
  27936. ) {
  27937. moveToRange(editor, newRng)
  27938. })
  27939. return true
  27940. }
  27941. return false
  27942. }
  27943. var getClosestAbovePosition = function (root, table, start) {
  27944. return findClosestPositionInAboveCell(table, start)
  27945. .orThunk(function () {
  27946. return head(start.getClientRects()).bind(function (rect) {
  27947. return findClosestHorizontalPositionFromPoint(
  27948. getPositionsAbove(root, CaretPosition.before(table)),
  27949. rect.left
  27950. )
  27951. })
  27952. })
  27953. .getOr(CaretPosition.before(table))
  27954. }
  27955. var getClosestBelowPosition = function (root, table, start) {
  27956. return findClosestPositionInBelowCell(table, start)
  27957. .orThunk(function () {
  27958. return head(start.getClientRects()).bind(function (rect) {
  27959. return findClosestHorizontalPositionFromPoint(
  27960. getPositionsBelow(root, CaretPosition.after(table)),
  27961. rect.left
  27962. )
  27963. })
  27964. })
  27965. .getOr(CaretPosition.after(table))
  27966. }
  27967. var getTable = function (previous, pos) {
  27968. var node = pos.getNode(previous)
  27969. return isElement$5(node) && node.nodeName === 'TABLE'
  27970. ? Optional.some(node)
  27971. : Optional.none()
  27972. }
  27973. var renderBlock = function (down, editor, table, pos) {
  27974. var forcedRootBlock = getForcedRootBlock(editor)
  27975. if (forcedRootBlock) {
  27976. editor.undoManager.transact(function () {
  27977. var element = SugarElement.fromTag(forcedRootBlock)
  27978. setAll$1(element, getForcedRootBlockAttrs(editor))
  27979. append$1(element, SugarElement.fromTag('br'))
  27980. if (down) {
  27981. after$3(SugarElement.fromDom(table), element)
  27982. } else {
  27983. before$4(SugarElement.fromDom(table), element)
  27984. }
  27985. var rng = editor.dom.createRng()
  27986. rng.setStart(element.dom, 0)
  27987. rng.setEnd(element.dom, 0)
  27988. moveToRange(editor, rng)
  27989. })
  27990. } else {
  27991. moveToRange(editor, pos.toRange())
  27992. }
  27993. }
  27994. var moveCaret = function (editor, down, pos) {
  27995. var table = down ? getTable(true, pos) : getTable(false, pos)
  27996. var last = down === false
  27997. table.fold(
  27998. function () {
  27999. return moveToRange(editor, pos.toRange())
  28000. },
  28001. function (table) {
  28002. return positionIn(last, editor.getBody())
  28003. .filter(function (lastPos) {
  28004. return lastPos.isEqual(pos)
  28005. })
  28006. .fold(
  28007. function () {
  28008. return moveToRange(editor, pos.toRange())
  28009. },
  28010. function (_) {
  28011. return renderBlock(down, editor, table, pos)
  28012. }
  28013. )
  28014. }
  28015. )
  28016. }
  28017. var navigateVertically = function (editor, down, table, td) {
  28018. var rng = editor.selection.getRng()
  28019. var pos = CaretPosition.fromRangeStart(rng)
  28020. var root = editor.getBody()
  28021. if (!down && isAtFirstTableCellLine(td, pos)) {
  28022. var newPos = getClosestAbovePosition(root, table, pos)
  28023. moveCaret(editor, down, newPos)
  28024. return true
  28025. } else if (down && isAtLastTableCellLine(td, pos)) {
  28026. var newPos = getClosestBelowPosition(root, table, pos)
  28027. moveCaret(editor, down, newPos)
  28028. return true
  28029. } else {
  28030. return false
  28031. }
  28032. }
  28033. var move$1 = function (editor, forward, mover) {
  28034. return Optional.from(
  28035. editor.dom.getParent(editor.selection.getNode(), 'td,th')
  28036. )
  28037. .bind(function (td) {
  28038. return Optional.from(editor.dom.getParent(td, 'table')).map(function (
  28039. table
  28040. ) {
  28041. return mover(editor, forward, table, td)
  28042. })
  28043. })
  28044. .getOr(false)
  28045. }
  28046. var moveH = function (editor, forward) {
  28047. return move$1(editor, forward, navigateHorizontally)
  28048. }
  28049. var moveV = function (editor, forward) {
  28050. return move$1(editor, forward, navigateVertically)
  28051. }
  28052. var executeKeydownOverride$3 = function (editor, caret, evt) {
  28053. var os = detect().os
  28054. execute(
  28055. [
  28056. {
  28057. keyCode: VK.RIGHT,
  28058. action: action(moveH$2, editor, true),
  28059. },
  28060. {
  28061. keyCode: VK.LEFT,
  28062. action: action(moveH$2, editor, false),
  28063. },
  28064. {
  28065. keyCode: VK.UP,
  28066. action: action(moveV$3, editor, false),
  28067. },
  28068. {
  28069. keyCode: VK.DOWN,
  28070. action: action(moveV$3, editor, true),
  28071. },
  28072. {
  28073. keyCode: VK.RIGHT,
  28074. action: action(moveH, editor, true),
  28075. },
  28076. {
  28077. keyCode: VK.LEFT,
  28078. action: action(moveH, editor, false),
  28079. },
  28080. {
  28081. keyCode: VK.UP,
  28082. action: action(moveV, editor, false),
  28083. },
  28084. {
  28085. keyCode: VK.DOWN,
  28086. action: action(moveV, editor, true),
  28087. },
  28088. {
  28089. keyCode: VK.RIGHT,
  28090. action: action(moveH$1, editor, true),
  28091. },
  28092. {
  28093. keyCode: VK.LEFT,
  28094. action: action(moveH$1, editor, false),
  28095. },
  28096. {
  28097. keyCode: VK.UP,
  28098. action: action(moveV$1, editor, false),
  28099. },
  28100. {
  28101. keyCode: VK.DOWN,
  28102. action: action(moveV$1, editor, true),
  28103. },
  28104. {
  28105. keyCode: VK.RIGHT,
  28106. action: action(move$2, editor, caret, true),
  28107. },
  28108. {
  28109. keyCode: VK.LEFT,
  28110. action: action(move$2, editor, caret, false),
  28111. },
  28112. {
  28113. keyCode: VK.RIGHT,
  28114. ctrlKey: !os.isOSX(),
  28115. altKey: os.isOSX(),
  28116. action: action(moveNextWord, editor, caret),
  28117. },
  28118. {
  28119. keyCode: VK.LEFT,
  28120. ctrlKey: !os.isOSX(),
  28121. altKey: os.isOSX(),
  28122. action: action(movePrevWord, editor, caret),
  28123. },
  28124. {
  28125. keyCode: VK.UP,
  28126. action: action(moveV$2, editor, false),
  28127. },
  28128. {
  28129. keyCode: VK.DOWN,
  28130. action: action(moveV$2, editor, true),
  28131. },
  28132. ],
  28133. evt
  28134. ).each(function (_) {
  28135. evt.preventDefault()
  28136. })
  28137. }
  28138. var setup$b = function (editor, caret) {
  28139. editor.on('keydown', function (evt) {
  28140. if (evt.isDefaultPrevented() === false) {
  28141. executeKeydownOverride$3(editor, caret, evt)
  28142. }
  28143. })
  28144. }
  28145. var executeKeydownOverride$2 = function (editor, caret, evt) {
  28146. execute(
  28147. [
  28148. {
  28149. keyCode: VK.BACKSPACE,
  28150. action: action(backspaceDelete, editor, false),
  28151. },
  28152. {
  28153. keyCode: VK.BACKSPACE,
  28154. action: action(backspaceDelete$5, editor, false),
  28155. },
  28156. {
  28157. keyCode: VK.DELETE,
  28158. action: action(backspaceDelete$5, editor, true),
  28159. },
  28160. {
  28161. keyCode: VK.BACKSPACE,
  28162. action: action(backspaceDelete$6, editor, false),
  28163. },
  28164. {
  28165. keyCode: VK.DELETE,
  28166. action: action(backspaceDelete$6, editor, true),
  28167. },
  28168. {
  28169. keyCode: VK.BACKSPACE,
  28170. action: action(backspaceDelete$3, editor, caret, false),
  28171. },
  28172. {
  28173. keyCode: VK.DELETE,
  28174. action: action(backspaceDelete$3, editor, caret, true),
  28175. },
  28176. {
  28177. keyCode: VK.BACKSPACE,
  28178. action: action(backspaceDelete$9, editor, false),
  28179. },
  28180. {
  28181. keyCode: VK.DELETE,
  28182. action: action(backspaceDelete$9, editor, true),
  28183. },
  28184. {
  28185. keyCode: VK.BACKSPACE,
  28186. action: action(backspaceDelete$4, editor, false),
  28187. },
  28188. {
  28189. keyCode: VK.DELETE,
  28190. action: action(backspaceDelete$4, editor, true),
  28191. },
  28192. {
  28193. keyCode: VK.BACKSPACE,
  28194. action: action(backspaceDelete$1, editor, false),
  28195. },
  28196. {
  28197. keyCode: VK.DELETE,
  28198. action: action(backspaceDelete$1, editor, true),
  28199. },
  28200. {
  28201. keyCode: VK.BACKSPACE,
  28202. action: action(backspaceDelete$7, editor, false),
  28203. },
  28204. {
  28205. keyCode: VK.DELETE,
  28206. action: action(backspaceDelete$7, editor, true),
  28207. },
  28208. {
  28209. keyCode: VK.BACKSPACE,
  28210. action: action(backspaceDelete$8, editor, false),
  28211. },
  28212. {
  28213. keyCode: VK.DELETE,
  28214. action: action(backspaceDelete$8, editor, true),
  28215. },
  28216. {
  28217. keyCode: VK.BACKSPACE,
  28218. action: action(backspaceDelete$2, editor, false),
  28219. },
  28220. {
  28221. keyCode: VK.DELETE,
  28222. action: action(backspaceDelete$2, editor, true),
  28223. },
  28224. ],
  28225. evt
  28226. ).each(function (_) {
  28227. evt.preventDefault()
  28228. })
  28229. }
  28230. var executeKeyupOverride = function (editor, evt) {
  28231. execute(
  28232. [
  28233. {
  28234. keyCode: VK.BACKSPACE,
  28235. action: action(paddEmptyElement, editor),
  28236. },
  28237. {
  28238. keyCode: VK.DELETE,
  28239. action: action(paddEmptyElement, editor),
  28240. },
  28241. ],
  28242. evt
  28243. )
  28244. }
  28245. var setup$a = function (editor, caret) {
  28246. editor.on('keydown', function (evt) {
  28247. if (evt.isDefaultPrevented() === false) {
  28248. executeKeydownOverride$2(editor, caret, evt)
  28249. }
  28250. })
  28251. editor.on('keyup', function (evt) {
  28252. if (evt.isDefaultPrevented() === false) {
  28253. executeKeyupOverride(editor, evt)
  28254. }
  28255. })
  28256. }
  28257. var firstNonWhiteSpaceNodeSibling = function (node) {
  28258. while (node) {
  28259. if (
  28260. node.nodeType === 1 ||
  28261. (node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data))
  28262. ) {
  28263. return node
  28264. }
  28265. node = node.nextSibling
  28266. }
  28267. }
  28268. var moveToCaretPosition = function (editor, root) {
  28269. var node,
  28270. lastNode = root
  28271. var dom = editor.dom
  28272. var moveCaretBeforeOnEnterElementsMap =
  28273. editor.schema.getMoveCaretBeforeOnEnterElements()
  28274. if (!root) {
  28275. return
  28276. }
  28277. if (/^(LI|DT|DD)$/.test(root.nodeName)) {
  28278. var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild)
  28279. if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
  28280. root.insertBefore(dom.doc.createTextNode(nbsp), root.firstChild)
  28281. }
  28282. }
  28283. var rng = dom.createRng()
  28284. root.normalize()
  28285. if (root.hasChildNodes()) {
  28286. var walker = new DomTreeWalker(root, root)
  28287. while ((node = walker.current())) {
  28288. if (isText$7(node)) {
  28289. rng.setStart(node, 0)
  28290. rng.setEnd(node, 0)
  28291. break
  28292. }
  28293. if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
  28294. rng.setStartBefore(node)
  28295. rng.setEndBefore(node)
  28296. break
  28297. }
  28298. lastNode = node
  28299. node = walker.next()
  28300. }
  28301. if (!node) {
  28302. rng.setStart(lastNode, 0)
  28303. rng.setEnd(lastNode, 0)
  28304. }
  28305. } else {
  28306. if (isBr$5(root)) {
  28307. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  28308. rng.setStartBefore(root)
  28309. rng.setEndBefore(root)
  28310. } else {
  28311. rng.setStartAfter(root)
  28312. rng.setEndAfter(root)
  28313. }
  28314. } else {
  28315. rng.setStart(root, 0)
  28316. rng.setEnd(root, 0)
  28317. }
  28318. }
  28319. editor.selection.setRng(rng)
  28320. scrollRangeIntoView(editor, rng)
  28321. }
  28322. var getEditableRoot$1 = function (dom, node) {
  28323. var root = dom.getRoot()
  28324. var parent, editableRoot
  28325. parent = node
  28326. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  28327. if (dom.getContentEditable(parent) === 'true') {
  28328. editableRoot = parent
  28329. }
  28330. parent = parent.parentNode
  28331. }
  28332. return parent !== root ? editableRoot : root
  28333. }
  28334. var getParentBlock = function (editor) {
  28335. return Optional.from(
  28336. editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock)
  28337. )
  28338. }
  28339. var getParentBlockName = function (editor) {
  28340. return getParentBlock(editor).fold(constant(''), function (parentBlock) {
  28341. return parentBlock.nodeName.toUpperCase()
  28342. })
  28343. }
  28344. var isListItemParentBlock = function (editor) {
  28345. return getParentBlock(editor)
  28346. .filter(function (elm) {
  28347. return isListItem(SugarElement.fromDom(elm))
  28348. })
  28349. .isSome()
  28350. }
  28351. var hasFirstChild = function (elm, name) {
  28352. return elm.firstChild && elm.firstChild.nodeName === name
  28353. }
  28354. var isFirstChild = function (elm) {
  28355. var _a
  28356. return (
  28357. ((_a = elm.parentNode) === null || _a === void 0
  28358. ? void 0
  28359. : _a.firstChild) === elm
  28360. )
  28361. }
  28362. var hasParent = function (elm, parentName) {
  28363. return elm && elm.parentNode && elm.parentNode.nodeName === parentName
  28364. }
  28365. var isListBlock = function (elm) {
  28366. return elm && /^(OL|UL|LI)$/.test(elm.nodeName)
  28367. }
  28368. var isNestedList = function (elm) {
  28369. return isListBlock(elm) && isListBlock(elm.parentNode)
  28370. }
  28371. var getContainerBlock = function (containerBlock) {
  28372. var containerBlockParent = containerBlock.parentNode
  28373. if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) {
  28374. return containerBlockParent
  28375. }
  28376. return containerBlock
  28377. }
  28378. var isFirstOrLastLi = function (containerBlock, parentBlock, first) {
  28379. var node = containerBlock[first ? 'firstChild' : 'lastChild']
  28380. while (node) {
  28381. if (isElement$5(node)) {
  28382. break
  28383. }
  28384. node = node[first ? 'nextSibling' : 'previousSibling']
  28385. }
  28386. return node === parentBlock
  28387. }
  28388. var insert$3 = function (
  28389. editor,
  28390. createNewBlock,
  28391. containerBlock,
  28392. parentBlock,
  28393. newBlockName
  28394. ) {
  28395. var dom = editor.dom
  28396. var rng = editor.selection.getRng()
  28397. if (containerBlock === editor.getBody()) {
  28398. return
  28399. }
  28400. if (isNestedList(containerBlock)) {
  28401. newBlockName = 'LI'
  28402. }
  28403. var newBlock = newBlockName
  28404. ? createNewBlock(newBlockName)
  28405. : dom.create('BR')
  28406. if (
  28407. isFirstOrLastLi(containerBlock, parentBlock, true) &&
  28408. isFirstOrLastLi(containerBlock, parentBlock, false)
  28409. ) {
  28410. if (hasParent(containerBlock, 'LI')) {
  28411. var containerBlockParent = getContainerBlock(containerBlock)
  28412. dom.insertAfter(newBlock, containerBlockParent)
  28413. if (isFirstChild(containerBlock)) {
  28414. dom.remove(containerBlockParent)
  28415. } else {
  28416. dom.remove(containerBlock)
  28417. }
  28418. } else {
  28419. dom.replace(newBlock, containerBlock)
  28420. }
  28421. } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) {
  28422. if (hasParent(containerBlock, 'LI')) {
  28423. dom.insertAfter(newBlock, getContainerBlock(containerBlock))
  28424. newBlock.appendChild(dom.doc.createTextNode(' '))
  28425. newBlock.appendChild(containerBlock)
  28426. } else {
  28427. containerBlock.parentNode.insertBefore(newBlock, containerBlock)
  28428. }
  28429. dom.remove(parentBlock)
  28430. } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) {
  28431. dom.insertAfter(newBlock, getContainerBlock(containerBlock))
  28432. dom.remove(parentBlock)
  28433. } else {
  28434. containerBlock = getContainerBlock(containerBlock)
  28435. var tmpRng = rng.cloneRange()
  28436. tmpRng.setStartAfter(parentBlock)
  28437. tmpRng.setEndAfter(containerBlock)
  28438. var fragment = tmpRng.extractContents()
  28439. if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) {
  28440. newBlock = fragment.firstChild
  28441. dom.insertAfter(fragment, containerBlock)
  28442. } else {
  28443. dom.insertAfter(fragment, containerBlock)
  28444. dom.insertAfter(newBlock, containerBlock)
  28445. }
  28446. dom.remove(parentBlock)
  28447. }
  28448. moveToCaretPosition(editor, newBlock)
  28449. }
  28450. var trimZwsp = function (fragment) {
  28451. each$k(
  28452. descendants$1(SugarElement.fromDom(fragment), isText$8),
  28453. function (text) {
  28454. var rawNode = text.dom
  28455. rawNode.nodeValue = trim$2(rawNode.nodeValue)
  28456. }
  28457. )
  28458. }
  28459. var isEmptyAnchor = function (dom, elm) {
  28460. return elm && elm.nodeName === 'A' && dom.isEmpty(elm)
  28461. }
  28462. var isTableCell = function (node) {
  28463. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName)
  28464. }
  28465. var emptyBlock = function (elm) {
  28466. elm.innerHTML = '<br data-mce-bogus="1">'
  28467. }
  28468. var containerAndSiblingName = function (container, nodeName) {
  28469. return (
  28470. container.nodeName === nodeName ||
  28471. (container.previousSibling &&
  28472. container.previousSibling.nodeName === nodeName)
  28473. )
  28474. }
  28475. var canSplitBlock = function (dom, node) {
  28476. return (
  28477. node &&
  28478. dom.isBlock(node) &&
  28479. !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
  28480. !/^(fixed|absolute)/i.test(node.style.position) &&
  28481. dom.getContentEditable(node) !== 'true'
  28482. )
  28483. }
  28484. var trimInlineElementsOnLeftSideOfBlock = function (
  28485. dom,
  28486. nonEmptyElementsMap,
  28487. block
  28488. ) {
  28489. var node = block
  28490. var firstChilds = []
  28491. var i
  28492. if (!node) {
  28493. return
  28494. }
  28495. while ((node = node.firstChild)) {
  28496. if (dom.isBlock(node)) {
  28497. return
  28498. }
  28499. if (
  28500. isElement$5(node) &&
  28501. !nonEmptyElementsMap[node.nodeName.toLowerCase()]
  28502. ) {
  28503. firstChilds.push(node)
  28504. }
  28505. }
  28506. i = firstChilds.length
  28507. while (i--) {
  28508. node = firstChilds[i]
  28509. if (
  28510. !node.hasChildNodes() ||
  28511. (node.firstChild === node.lastChild && node.firstChild.nodeValue === '')
  28512. ) {
  28513. dom.remove(node)
  28514. } else {
  28515. if (isEmptyAnchor(dom, node)) {
  28516. dom.remove(node)
  28517. }
  28518. }
  28519. }
  28520. }
  28521. var normalizeZwspOffset = function (start, container, offset) {
  28522. if (isText$7(container) === false) {
  28523. return offset
  28524. } else if (start) {
  28525. return offset === 1 && container.data.charAt(offset - 1) === ZWSP$1
  28526. ? 0
  28527. : offset
  28528. } else {
  28529. return offset === container.data.length - 1 &&
  28530. container.data.charAt(offset) === ZWSP$1
  28531. ? container.data.length
  28532. : offset
  28533. }
  28534. }
  28535. var includeZwspInRange = function (rng) {
  28536. var newRng = rng.cloneRange()
  28537. newRng.setStart(
  28538. rng.startContainer,
  28539. normalizeZwspOffset(true, rng.startContainer, rng.startOffset)
  28540. )
  28541. newRng.setEnd(
  28542. rng.endContainer,
  28543. normalizeZwspOffset(false, rng.endContainer, rng.endOffset)
  28544. )
  28545. return newRng
  28546. }
  28547. var trimLeadingLineBreaks = function (node) {
  28548. do {
  28549. if (isText$7(node)) {
  28550. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '')
  28551. }
  28552. node = node.firstChild
  28553. } while (node)
  28554. }
  28555. var getEditableRoot = function (dom, node) {
  28556. var root = dom.getRoot()
  28557. var parent, editableRoot
  28558. parent = node
  28559. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  28560. if (dom.getContentEditable(parent) === 'true') {
  28561. editableRoot = parent
  28562. }
  28563. parent = parent.parentNode
  28564. }
  28565. return parent !== root ? editableRoot : root
  28566. }
  28567. var applyAttributes = function (editor, node, forcedRootBlockAttrs) {
  28568. var dom = editor.dom
  28569. Optional.from(forcedRootBlockAttrs.style)
  28570. .map(dom.parseStyle)
  28571. .each(function (attrStyles) {
  28572. var currentStyles = getAllRaw(SugarElement.fromDom(node))
  28573. var newStyles = __assign(__assign({}, currentStyles), attrStyles)
  28574. dom.setStyles(node, newStyles)
  28575. })
  28576. var attrClassesOpt = Optional.from(forcedRootBlockAttrs.class).map(
  28577. function (attrClasses) {
  28578. return attrClasses.split(/\s+/)
  28579. }
  28580. )
  28581. var currentClassesOpt = Optional.from(node.className).map(function (
  28582. currentClasses
  28583. ) {
  28584. return filter$4(currentClasses.split(/\s+/), function (clazz) {
  28585. return clazz !== ''
  28586. })
  28587. })
  28588. lift2(
  28589. attrClassesOpt,
  28590. currentClassesOpt,
  28591. function (attrClasses, currentClasses) {
  28592. var filteredClasses = filter$4(currentClasses, function (clazz) {
  28593. return !contains$3(attrClasses, clazz)
  28594. })
  28595. var newClasses = __spreadArray(
  28596. __spreadArray([], attrClasses, true),
  28597. filteredClasses,
  28598. true
  28599. )
  28600. dom.setAttrib(node, 'class', newClasses.join(' '))
  28601. }
  28602. )
  28603. var appliedAttrs = ['style', 'class']
  28604. var remainingAttrs = filter$3(forcedRootBlockAttrs, function (_, attrs) {
  28605. return !contains$3(appliedAttrs, attrs)
  28606. })
  28607. dom.setAttribs(node, remainingAttrs)
  28608. }
  28609. var setForcedBlockAttrs = function (editor, node) {
  28610. var forcedRootBlockName = getForcedRootBlock(editor)
  28611. if (
  28612. forcedRootBlockName &&
  28613. forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()
  28614. ) {
  28615. var forcedRootBlockAttrs = getForcedRootBlockAttrs(editor)
  28616. applyAttributes(editor, node, forcedRootBlockAttrs)
  28617. }
  28618. }
  28619. var wrapSelfAndSiblingsInDefaultBlock = function (
  28620. editor,
  28621. newBlockName,
  28622. rng,
  28623. container,
  28624. offset
  28625. ) {
  28626. var newBlock, parentBlock, startNode, node, next, rootBlockName
  28627. var blockName = newBlockName || 'P'
  28628. var dom = editor.dom,
  28629. editableRoot = getEditableRoot(dom, container)
  28630. parentBlock = dom.getParent(container, dom.isBlock)
  28631. if (!parentBlock || !canSplitBlock(dom, parentBlock)) {
  28632. parentBlock = parentBlock || editableRoot
  28633. if (parentBlock === editor.getBody() || isTableCell(parentBlock)) {
  28634. rootBlockName = parentBlock.nodeName.toLowerCase()
  28635. } else {
  28636. rootBlockName = parentBlock.parentNode.nodeName.toLowerCase()
  28637. }
  28638. if (!parentBlock.hasChildNodes()) {
  28639. newBlock = dom.create(blockName)
  28640. setForcedBlockAttrs(editor, newBlock)
  28641. parentBlock.appendChild(newBlock)
  28642. rng.setStart(newBlock, 0)
  28643. rng.setEnd(newBlock, 0)
  28644. return newBlock
  28645. }
  28646. node = container
  28647. while (node.parentNode !== parentBlock) {
  28648. node = node.parentNode
  28649. }
  28650. while (node && !dom.isBlock(node)) {
  28651. startNode = node
  28652. node = node.previousSibling
  28653. }
  28654. if (
  28655. startNode &&
  28656. editor.schema.isValidChild(rootBlockName, blockName.toLowerCase())
  28657. ) {
  28658. newBlock = dom.create(blockName)
  28659. setForcedBlockAttrs(editor, newBlock)
  28660. startNode.parentNode.insertBefore(newBlock, startNode)
  28661. node = startNode
  28662. while (node && !dom.isBlock(node)) {
  28663. next = node.nextSibling
  28664. newBlock.appendChild(node)
  28665. node = next
  28666. }
  28667. rng.setStart(container, offset)
  28668. rng.setEnd(container, offset)
  28669. }
  28670. }
  28671. return container
  28672. }
  28673. var addBrToBlockIfNeeded = function (dom, block) {
  28674. block.normalize()
  28675. var lastChild = block.lastChild
  28676. if (
  28677. !lastChild ||
  28678. /^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true))
  28679. ) {
  28680. dom.add(block, 'br')
  28681. }
  28682. }
  28683. var insert$2 = function (editor, evt) {
  28684. var tmpRng, container, offset, parentBlock
  28685. var newBlock,
  28686. fragment,
  28687. containerBlock,
  28688. parentBlockName,
  28689. newBlockName,
  28690. isAfterLastNodeInContainer
  28691. var dom = editor.dom
  28692. var schema = editor.schema,
  28693. nonEmptyElementsMap = schema.getNonEmptyElements()
  28694. var rng = editor.selection.getRng()
  28695. var createNewBlock = function (name) {
  28696. var node = container,
  28697. block,
  28698. clonedNode,
  28699. caretNode
  28700. var textInlineElements = schema.getTextInlineElements()
  28701. if (name || parentBlockName === 'TABLE' || parentBlockName === 'HR') {
  28702. block = dom.create(name || newBlockName)
  28703. } else {
  28704. block = parentBlock.cloneNode(false)
  28705. }
  28706. caretNode = block
  28707. if (shouldKeepStyles(editor) === false) {
  28708. dom.setAttrib(block, 'style', null)
  28709. dom.setAttrib(block, 'class', null)
  28710. } else {
  28711. do {
  28712. if (textInlineElements[node.nodeName]) {
  28713. if (isCaretNode(node) || isBookmarkNode$1(node)) {
  28714. continue
  28715. }
  28716. clonedNode = node.cloneNode(false)
  28717. dom.setAttrib(clonedNode, 'id', '')
  28718. if (block.hasChildNodes()) {
  28719. clonedNode.appendChild(block.firstChild)
  28720. block.appendChild(clonedNode)
  28721. } else {
  28722. caretNode = clonedNode
  28723. block.appendChild(clonedNode)
  28724. }
  28725. }
  28726. } while ((node = node.parentNode) && node !== editableRoot)
  28727. }
  28728. setForcedBlockAttrs(editor, block)
  28729. emptyBlock(caretNode)
  28730. return block
  28731. }
  28732. var isCaretAtStartOrEndOfBlock = function (start) {
  28733. var node, name
  28734. var normalizedOffset = normalizeZwspOffset(start, container, offset)
  28735. if (
  28736. isText$7(container) &&
  28737. (start
  28738. ? normalizedOffset > 0
  28739. : normalizedOffset < container.nodeValue.length)
  28740. ) {
  28741. return false
  28742. }
  28743. if (
  28744. container.parentNode === parentBlock &&
  28745. isAfterLastNodeInContainer &&
  28746. !start
  28747. ) {
  28748. return true
  28749. }
  28750. if (
  28751. start &&
  28752. isElement$5(container) &&
  28753. container === parentBlock.firstChild
  28754. ) {
  28755. return true
  28756. }
  28757. if (
  28758. containerAndSiblingName(container, 'TABLE') ||
  28759. containerAndSiblingName(container, 'HR')
  28760. ) {
  28761. return (
  28762. (isAfterLastNodeInContainer && !start) ||
  28763. (!isAfterLastNodeInContainer && start)
  28764. )
  28765. }
  28766. var walker = new DomTreeWalker(container, parentBlock)
  28767. if (isText$7(container)) {
  28768. if (start && normalizedOffset === 0) {
  28769. walker.prev()
  28770. } else if (!start && normalizedOffset === container.nodeValue.length) {
  28771. walker.next()
  28772. }
  28773. }
  28774. while ((node = walker.current())) {
  28775. if (isElement$5(node)) {
  28776. if (!node.getAttribute('data-mce-bogus')) {
  28777. name = node.nodeName.toLowerCase()
  28778. if (nonEmptyElementsMap[name] && name !== 'br') {
  28779. return false
  28780. }
  28781. }
  28782. } else if (isText$7(node) && !isWhitespaceText(node.nodeValue)) {
  28783. return false
  28784. }
  28785. if (start) {
  28786. walker.prev()
  28787. } else {
  28788. walker.next()
  28789. }
  28790. }
  28791. return true
  28792. }
  28793. var insertNewBlockAfter = function () {
  28794. if (
  28795. /^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) &&
  28796. containerBlockName !== 'HGROUP'
  28797. ) {
  28798. newBlock = createNewBlock(newBlockName)
  28799. } else {
  28800. newBlock = createNewBlock()
  28801. }
  28802. if (
  28803. shouldEndContainerOnEmptyBlock(editor) &&
  28804. canSplitBlock(dom, containerBlock) &&
  28805. dom.isEmpty(parentBlock)
  28806. ) {
  28807. newBlock = dom.split(containerBlock, parentBlock)
  28808. } else {
  28809. dom.insertAfter(newBlock, parentBlock)
  28810. }
  28811. moveToCaretPosition(editor, newBlock)
  28812. }
  28813. normalize$2(dom, rng).each(function (normRng) {
  28814. rng.setStart(normRng.startContainer, normRng.startOffset)
  28815. rng.setEnd(normRng.endContainer, normRng.endOffset)
  28816. })
  28817. container = rng.startContainer
  28818. offset = rng.startOffset
  28819. newBlockName = getForcedRootBlock(editor)
  28820. var shiftKey = !!(evt && evt.shiftKey)
  28821. var ctrlKey = !!(evt && evt.ctrlKey)
  28822. if (isElement$5(container) && container.hasChildNodes()) {
  28823. isAfterLastNodeInContainer = offset > container.childNodes.length - 1
  28824. container =
  28825. container.childNodes[
  28826. Math.min(offset, container.childNodes.length - 1)
  28827. ] || container
  28828. if (isAfterLastNodeInContainer && isText$7(container)) {
  28829. offset = container.nodeValue.length
  28830. } else {
  28831. offset = 0
  28832. }
  28833. }
  28834. var editableRoot = getEditableRoot(dom, container)
  28835. if (!editableRoot) {
  28836. return
  28837. }
  28838. if ((newBlockName && !shiftKey) || (!newBlockName && shiftKey)) {
  28839. container = wrapSelfAndSiblingsInDefaultBlock(
  28840. editor,
  28841. newBlockName,
  28842. rng,
  28843. container,
  28844. offset
  28845. )
  28846. }
  28847. parentBlock = dom.getParent(container, dom.isBlock)
  28848. containerBlock = parentBlock
  28849. ? dom.getParent(parentBlock.parentNode, dom.isBlock)
  28850. : null
  28851. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''
  28852. var containerBlockName = containerBlock
  28853. ? containerBlock.nodeName.toUpperCase()
  28854. : ''
  28855. if (containerBlockName === 'LI' && !ctrlKey) {
  28856. parentBlock = containerBlock
  28857. containerBlock = containerBlock.parentNode
  28858. parentBlockName = containerBlockName
  28859. }
  28860. if (/^(LI|DT|DD)$/.test(parentBlockName)) {
  28861. if (dom.isEmpty(parentBlock)) {
  28862. insert$3(
  28863. editor,
  28864. createNewBlock,
  28865. containerBlock,
  28866. parentBlock,
  28867. newBlockName
  28868. )
  28869. return
  28870. }
  28871. }
  28872. if (newBlockName && parentBlock === editor.getBody()) {
  28873. return
  28874. }
  28875. newBlockName = newBlockName || 'P'
  28876. if (isCaretContainerBlock$1(parentBlock)) {
  28877. newBlock = showCaretContainerBlock(parentBlock)
  28878. if (dom.isEmpty(parentBlock)) {
  28879. emptyBlock(parentBlock)
  28880. }
  28881. setForcedBlockAttrs(editor, newBlock)
  28882. moveToCaretPosition(editor, newBlock)
  28883. } else if (isCaretAtStartOrEndOfBlock()) {
  28884. insertNewBlockAfter()
  28885. } else if (isCaretAtStartOrEndOfBlock(true)) {
  28886. newBlock = parentBlock.parentNode.insertBefore(
  28887. createNewBlock(),
  28888. parentBlock
  28889. )
  28890. moveToCaretPosition(
  28891. editor,
  28892. containerAndSiblingName(parentBlock, 'HR') ? newBlock : parentBlock
  28893. )
  28894. } else {
  28895. tmpRng = includeZwspInRange(rng).cloneRange()
  28896. tmpRng.setEndAfter(parentBlock)
  28897. fragment = tmpRng.extractContents()
  28898. trimZwsp(fragment)
  28899. trimLeadingLineBreaks(fragment)
  28900. newBlock = fragment.firstChild
  28901. dom.insertAfter(fragment, parentBlock)
  28902. trimInlineElementsOnLeftSideOfBlock(dom, nonEmptyElementsMap, newBlock)
  28903. addBrToBlockIfNeeded(dom, parentBlock)
  28904. if (dom.isEmpty(parentBlock)) {
  28905. emptyBlock(parentBlock)
  28906. }
  28907. newBlock.normalize()
  28908. if (dom.isEmpty(newBlock)) {
  28909. dom.remove(newBlock)
  28910. insertNewBlockAfter()
  28911. } else {
  28912. setForcedBlockAttrs(editor, newBlock)
  28913. moveToCaretPosition(editor, newBlock)
  28914. }
  28915. }
  28916. dom.setAttrib(newBlock, 'id', '')
  28917. editor.fire('NewBlock', { newBlock: newBlock })
  28918. }
  28919. var hasRightSideContent = function (schema, container, parentBlock) {
  28920. var walker = new DomTreeWalker(container, parentBlock)
  28921. var node
  28922. var nonEmptyElementsMap = schema.getNonEmptyElements()
  28923. while ((node = walker.next())) {
  28924. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
  28925. return true
  28926. }
  28927. }
  28928. }
  28929. var moveSelectionToBr = function (editor, brElm, extraBr) {
  28930. var rng = editor.dom.createRng()
  28931. if (!extraBr) {
  28932. rng.setStartAfter(brElm)
  28933. rng.setEndAfter(brElm)
  28934. } else {
  28935. rng.setStartBefore(brElm)
  28936. rng.setEndBefore(brElm)
  28937. }
  28938. editor.selection.setRng(rng)
  28939. scrollRangeIntoView(editor, rng)
  28940. }
  28941. var insertBrAtCaret = function (editor, evt) {
  28942. var selection = editor.selection
  28943. var dom = editor.dom
  28944. var rng = selection.getRng()
  28945. var brElm
  28946. var extraBr
  28947. normalize$2(dom, rng).each(function (normRng) {
  28948. rng.setStart(normRng.startContainer, normRng.startOffset)
  28949. rng.setEnd(normRng.endContainer, normRng.endOffset)
  28950. })
  28951. var offset = rng.startOffset
  28952. var container = rng.startContainer
  28953. if (container.nodeType === 1 && container.hasChildNodes()) {
  28954. var isAfterLastNodeInContainer = offset > container.childNodes.length - 1
  28955. container =
  28956. container.childNodes[
  28957. Math.min(offset, container.childNodes.length - 1)
  28958. ] || container
  28959. if (isAfterLastNodeInContainer && container.nodeType === 3) {
  28960. offset = container.nodeValue.length
  28961. } else {
  28962. offset = 0
  28963. }
  28964. }
  28965. var parentBlock = dom.getParent(container, dom.isBlock)
  28966. var containerBlock = parentBlock
  28967. ? dom.getParent(parentBlock.parentNode, dom.isBlock)
  28968. : null
  28969. var containerBlockName = containerBlock
  28970. ? containerBlock.nodeName.toUpperCase()
  28971. : ''
  28972. var isControlKey = !!(evt && evt.ctrlKey)
  28973. if (containerBlockName === 'LI' && !isControlKey) {
  28974. parentBlock = containerBlock
  28975. }
  28976. if (
  28977. container &&
  28978. container.nodeType === 3 &&
  28979. offset >= container.nodeValue.length
  28980. ) {
  28981. if (!hasRightSideContent(editor.schema, container, parentBlock)) {
  28982. brElm = dom.create('br')
  28983. rng.insertNode(brElm)
  28984. rng.setStartAfter(brElm)
  28985. rng.setEndAfter(brElm)
  28986. extraBr = true
  28987. }
  28988. }
  28989. brElm = dom.create('br')
  28990. rangeInsertNode(dom, rng, brElm)
  28991. moveSelectionToBr(editor, brElm, extraBr)
  28992. editor.undoManager.add()
  28993. }
  28994. var insertBrBefore = function (editor, inline) {
  28995. var br = SugarElement.fromTag('br')
  28996. before$4(SugarElement.fromDom(inline), br)
  28997. editor.undoManager.add()
  28998. }
  28999. var insertBrAfter = function (editor, inline) {
  29000. if (!hasBrAfter(editor.getBody(), inline)) {
  29001. after$3(SugarElement.fromDom(inline), SugarElement.fromTag('br'))
  29002. }
  29003. var br = SugarElement.fromTag('br')
  29004. after$3(SugarElement.fromDom(inline), br)
  29005. moveSelectionToBr(editor, br.dom, false)
  29006. editor.undoManager.add()
  29007. }
  29008. var isBeforeBr = function (pos) {
  29009. return isBr$5(pos.getNode())
  29010. }
  29011. var hasBrAfter = function (rootNode, startNode) {
  29012. if (isBeforeBr(CaretPosition.after(startNode))) {
  29013. return true
  29014. } else {
  29015. return nextPosition(rootNode, CaretPosition.after(startNode))
  29016. .map(function (pos) {
  29017. return isBr$5(pos.getNode())
  29018. })
  29019. .getOr(false)
  29020. }
  29021. }
  29022. var isAnchorLink = function (elm) {
  29023. return elm && elm.nodeName === 'A' && 'href' in elm
  29024. }
  29025. var isInsideAnchor = function (location) {
  29026. return location.fold(never, isAnchorLink, isAnchorLink, never)
  29027. }
  29028. var readInlineAnchorLocation = function (editor) {
  29029. var isInlineTarget$1 = curry(isInlineTarget, editor)
  29030. var position = CaretPosition.fromRangeStart(editor.selection.getRng())
  29031. return readLocation(isInlineTarget$1, editor.getBody(), position).filter(
  29032. isInsideAnchor
  29033. )
  29034. }
  29035. var insertBrOutsideAnchor = function (editor, location) {
  29036. location.fold(
  29037. noop,
  29038. curry(insertBrBefore, editor),
  29039. curry(insertBrAfter, editor),
  29040. noop
  29041. )
  29042. }
  29043. var insert$1 = function (editor, evt) {
  29044. var anchorLocation = readInlineAnchorLocation(editor)
  29045. if (anchorLocation.isSome()) {
  29046. anchorLocation.each(curry(insertBrOutsideAnchor, editor))
  29047. } else {
  29048. insertBrAtCaret(editor, evt)
  29049. }
  29050. }
  29051. var matchesSelector = function (editor, selector) {
  29052. return getParentBlock(editor)
  29053. .filter(function (parentBlock) {
  29054. return (
  29055. selector.length > 0 &&
  29056. is$2(SugarElement.fromDom(parentBlock), selector)
  29057. )
  29058. })
  29059. .isSome()
  29060. }
  29061. var shouldInsertBr = function (editor) {
  29062. return matchesSelector(editor, getBrNewLineSelector(editor))
  29063. }
  29064. var shouldBlockNewLine$1 = function (editor) {
  29065. return matchesSelector(editor, getNoNewLineSelector(editor))
  29066. }
  29067. var newLineAction = Adt.generate([{ br: [] }, { block: [] }, { none: [] }])
  29068. var shouldBlockNewLine = function (editor, _shiftKey) {
  29069. return shouldBlockNewLine$1(editor)
  29070. }
  29071. var isBrMode = function (requiredState) {
  29072. return function (editor, _shiftKey) {
  29073. var brMode = getForcedRootBlock(editor) === ''
  29074. return brMode === requiredState
  29075. }
  29076. }
  29077. var inListBlock = function (requiredState) {
  29078. return function (editor, _shiftKey) {
  29079. return isListItemParentBlock(editor) === requiredState
  29080. }
  29081. }
  29082. var inBlock = function (blockName, requiredState) {
  29083. return function (editor, _shiftKey) {
  29084. var state = getParentBlockName(editor) === blockName.toUpperCase()
  29085. return state === requiredState
  29086. }
  29087. }
  29088. var inPreBlock = function (requiredState) {
  29089. return inBlock('pre', requiredState)
  29090. }
  29091. var inSummaryBlock = function () {
  29092. return inBlock('summary', true)
  29093. }
  29094. var shouldPutBrInPre = function (requiredState) {
  29095. return function (editor, _shiftKey) {
  29096. return shouldPutBrInPre$1(editor) === requiredState
  29097. }
  29098. }
  29099. var inBrContext = function (editor, _shiftKey) {
  29100. return shouldInsertBr(editor)
  29101. }
  29102. var hasShiftKey = function (_editor, shiftKey) {
  29103. return shiftKey
  29104. }
  29105. var canInsertIntoEditableRoot = function (editor) {
  29106. var forcedRootBlock = getForcedRootBlock(editor)
  29107. var rootEditable = getEditableRoot$1(
  29108. editor.dom,
  29109. editor.selection.getStart()
  29110. )
  29111. return (
  29112. rootEditable &&
  29113. editor.schema.isValidChild(
  29114. rootEditable.nodeName,
  29115. forcedRootBlock ? forcedRootBlock : 'P'
  29116. )
  29117. )
  29118. }
  29119. var match = function (predicates, action) {
  29120. return function (editor, shiftKey) {
  29121. var isMatch = foldl(
  29122. predicates,
  29123. function (res, p) {
  29124. return res && p(editor, shiftKey)
  29125. },
  29126. true
  29127. )
  29128. return isMatch ? Optional.some(action) : Optional.none()
  29129. }
  29130. }
  29131. var getAction = function (editor, evt) {
  29132. return evaluateUntil(
  29133. [
  29134. match([shouldBlockNewLine], newLineAction.none()),
  29135. match([inSummaryBlock()], newLineAction.br()),
  29136. match(
  29137. [inPreBlock(true), shouldPutBrInPre(false), hasShiftKey],
  29138. newLineAction.br()
  29139. ),
  29140. match(
  29141. [inPreBlock(true), shouldPutBrInPre(false)],
  29142. newLineAction.block()
  29143. ),
  29144. match(
  29145. [inPreBlock(true), shouldPutBrInPre(true), hasShiftKey],
  29146. newLineAction.block()
  29147. ),
  29148. match([inPreBlock(true), shouldPutBrInPre(true)], newLineAction.br()),
  29149. match([inListBlock(true), hasShiftKey], newLineAction.br()),
  29150. match([inListBlock(true)], newLineAction.block()),
  29151. match(
  29152. [isBrMode(true), hasShiftKey, canInsertIntoEditableRoot],
  29153. newLineAction.block()
  29154. ),
  29155. match([isBrMode(true)], newLineAction.br()),
  29156. match([inBrContext], newLineAction.br()),
  29157. match([isBrMode(false), hasShiftKey], newLineAction.br()),
  29158. match([canInsertIntoEditableRoot], newLineAction.block()),
  29159. ],
  29160. [editor, !!(evt && evt.shiftKey)]
  29161. ).getOr(newLineAction.none())
  29162. }
  29163. var insert = function (editor, evt) {
  29164. getAction(editor, evt).fold(
  29165. function () {
  29166. insert$1(editor, evt)
  29167. },
  29168. function () {
  29169. insert$2(editor, evt)
  29170. },
  29171. noop
  29172. )
  29173. }
  29174. var handleEnterKeyEvent = function (editor, event) {
  29175. if (event.isDefaultPrevented()) {
  29176. return
  29177. }
  29178. event.preventDefault()
  29179. endTypingLevelIgnoreLocks(editor.undoManager)
  29180. editor.undoManager.transact(function () {
  29181. if (editor.selection.isCollapsed() === false) {
  29182. editor.execCommand('Delete')
  29183. }
  29184. insert(editor, event)
  29185. })
  29186. }
  29187. var setup$9 = function (editor) {
  29188. editor.on('keydown', function (event) {
  29189. if (event.keyCode === VK.ENTER) {
  29190. handleEnterKeyEvent(editor, event)
  29191. }
  29192. })
  29193. }
  29194. var executeKeydownOverride$1 = function (editor, caret, evt) {
  29195. execute(
  29196. [
  29197. {
  29198. keyCode: VK.END,
  29199. action: action(moveToLineEndPoint$1, editor, true),
  29200. },
  29201. {
  29202. keyCode: VK.HOME,
  29203. action: action(moveToLineEndPoint$1, editor, false),
  29204. },
  29205. {
  29206. keyCode: VK.END,
  29207. action: action(moveToLineEndPoint, editor, true),
  29208. },
  29209. {
  29210. keyCode: VK.HOME,
  29211. action: action(moveToLineEndPoint, editor, false),
  29212. },
  29213. {
  29214. keyCode: VK.END,
  29215. action: action(moveToLineEndPoint$2, editor, true, caret),
  29216. },
  29217. {
  29218. keyCode: VK.HOME,
  29219. action: action(moveToLineEndPoint$2, editor, false, caret),
  29220. },
  29221. ],
  29222. evt
  29223. ).each(function (_) {
  29224. evt.preventDefault()
  29225. })
  29226. }
  29227. var setup$8 = function (editor, caret) {
  29228. editor.on('keydown', function (evt) {
  29229. if (evt.isDefaultPrevented() === false) {
  29230. executeKeydownOverride$1(editor, caret, evt)
  29231. }
  29232. })
  29233. }
  29234. var browser = detect().browser
  29235. var setupIeInput = function (editor) {
  29236. var keypressThrotter = first(function () {
  29237. if (!editor.composing) {
  29238. normalizeNbspsInEditor(editor)
  29239. }
  29240. }, 0)
  29241. if (browser.isIE()) {
  29242. editor.on('keypress', function (_e) {
  29243. keypressThrotter.throttle()
  29244. })
  29245. editor.on('remove', function (_e) {
  29246. keypressThrotter.cancel()
  29247. })
  29248. }
  29249. }
  29250. var setup$7 = function (editor) {
  29251. setupIeInput(editor)
  29252. editor.on('input', function (e) {
  29253. if (e.isComposing === false) {
  29254. normalizeNbspsInEditor(editor)
  29255. }
  29256. })
  29257. }
  29258. var platform = detect()
  29259. var executeKeyupAction = function (editor, caret, evt) {
  29260. execute(
  29261. [
  29262. {
  29263. keyCode: VK.PAGE_UP,
  29264. action: action(moveToLineEndPoint$2, editor, false, caret),
  29265. },
  29266. {
  29267. keyCode: VK.PAGE_DOWN,
  29268. action: action(moveToLineEndPoint$2, editor, true, caret),
  29269. },
  29270. ],
  29271. evt
  29272. )
  29273. }
  29274. var stopImmediatePropagation = function (e) {
  29275. return e.stopImmediatePropagation()
  29276. }
  29277. var isPageUpDown = function (evt) {
  29278. return evt.keyCode === VK.PAGE_UP || evt.keyCode === VK.PAGE_DOWN
  29279. }
  29280. var setNodeChangeBlocker = function (blocked, editor, block) {
  29281. if (block && !blocked.get()) {
  29282. editor.on('NodeChange', stopImmediatePropagation, true)
  29283. } else if (!block && blocked.get()) {
  29284. editor.off('NodeChange', stopImmediatePropagation)
  29285. }
  29286. blocked.set(block)
  29287. }
  29288. var setup$6 = function (editor, caret) {
  29289. if (platform.os.isOSX()) {
  29290. return
  29291. }
  29292. var blocked = Cell(false)
  29293. editor.on('keydown', function (evt) {
  29294. if (isPageUpDown(evt)) {
  29295. setNodeChangeBlocker(blocked, editor, true)
  29296. }
  29297. })
  29298. editor.on('keyup', function (evt) {
  29299. if (evt.isDefaultPrevented() === false) {
  29300. executeKeyupAction(editor, caret, evt)
  29301. }
  29302. if (isPageUpDown(evt) && blocked.get()) {
  29303. setNodeChangeBlocker(blocked, editor, false)
  29304. editor.nodeChanged()
  29305. }
  29306. })
  29307. }
  29308. var insertTextAtPosition = function (text, pos) {
  29309. var container = pos.container()
  29310. var offset = pos.offset()
  29311. if (isText$7(container)) {
  29312. container.insertData(offset, text)
  29313. return Optional.some(CaretPosition(container, offset + text.length))
  29314. } else {
  29315. return getElementFromPosition(pos).map(function (elm) {
  29316. var textNode = SugarElement.fromText(text)
  29317. if (pos.isAtEnd()) {
  29318. after$3(elm, textNode)
  29319. } else {
  29320. before$4(elm, textNode)
  29321. }
  29322. return CaretPosition(textNode.dom, text.length)
  29323. })
  29324. }
  29325. }
  29326. var insertNbspAtPosition = curry(insertTextAtPosition, nbsp)
  29327. var insertSpaceAtPosition = curry(insertTextAtPosition, ' ')
  29328. var locationToCaretPosition = function (root) {
  29329. return function (location) {
  29330. return location.fold(
  29331. function (element) {
  29332. return prevPosition(root.dom, CaretPosition.before(element))
  29333. },
  29334. function (element) {
  29335. return firstPositionIn(element)
  29336. },
  29337. function (element) {
  29338. return lastPositionIn(element)
  29339. },
  29340. function (element) {
  29341. return nextPosition(root.dom, CaretPosition.after(element))
  29342. }
  29343. )
  29344. }
  29345. }
  29346. var insertInlineBoundarySpaceOrNbsp = function (root, pos) {
  29347. return function (checkPos) {
  29348. return needsToHaveNbsp(root, checkPos)
  29349. ? insertNbspAtPosition(pos)
  29350. : insertSpaceAtPosition(pos)
  29351. }
  29352. }
  29353. var setSelection = function (editor) {
  29354. return function (pos) {
  29355. editor.selection.setRng(pos.toRange())
  29356. editor.nodeChanged()
  29357. return true
  29358. }
  29359. }
  29360. var insertSpaceOrNbspAtSelection = function (editor) {
  29361. var pos = CaretPosition.fromRangeStart(editor.selection.getRng())
  29362. var root = SugarElement.fromDom(editor.getBody())
  29363. if (editor.selection.isCollapsed()) {
  29364. var isInlineTarget$1 = curry(isInlineTarget, editor)
  29365. var caretPosition = CaretPosition.fromRangeStart(
  29366. editor.selection.getRng()
  29367. )
  29368. return readLocation(isInlineTarget$1, editor.getBody(), caretPosition)
  29369. .bind(locationToCaretPosition(root))
  29370. .bind(insertInlineBoundarySpaceOrNbsp(root, pos))
  29371. .exists(setSelection(editor))
  29372. } else {
  29373. return false
  29374. }
  29375. }
  29376. var executeKeydownOverride = function (editor, evt) {
  29377. execute(
  29378. [
  29379. {
  29380. keyCode: VK.SPACEBAR,
  29381. action: action(insertSpaceOrNbspAtSelection, editor),
  29382. },
  29383. ],
  29384. evt
  29385. ).each(function (_) {
  29386. evt.preventDefault()
  29387. })
  29388. }
  29389. var setup$5 = function (editor) {
  29390. editor.on('keydown', function (evt) {
  29391. if (evt.isDefaultPrevented() === false) {
  29392. executeKeydownOverride(editor, evt)
  29393. }
  29394. })
  29395. }
  29396. var registerKeyboardOverrides = function (editor) {
  29397. var caret = setupSelectedState(editor)
  29398. setup$c(editor)
  29399. setup$b(editor, caret)
  29400. setup$a(editor, caret)
  29401. setup$9(editor)
  29402. setup$5(editor)
  29403. setup$7(editor)
  29404. setup$8(editor, caret)
  29405. setup$6(editor, caret)
  29406. return caret
  29407. }
  29408. var setup$4 = function (editor) {
  29409. if (!isRtc(editor)) {
  29410. return registerKeyboardOverrides(editor)
  29411. } else {
  29412. return Cell(null)
  29413. }
  29414. }
  29415. var NodeChange = (function () {
  29416. function NodeChange(editor) {
  29417. this.lastPath = []
  29418. this.editor = editor
  29419. var lastRng
  29420. var self = this
  29421. if (!('onselectionchange' in editor.getDoc())) {
  29422. editor.on('NodeChange click mouseup keyup focus', function (e) {
  29423. var nativeRng = editor.selection.getRng()
  29424. var fakeRng = {
  29425. startContainer: nativeRng.startContainer,
  29426. startOffset: nativeRng.startOffset,
  29427. endContainer: nativeRng.endContainer,
  29428. endOffset: nativeRng.endOffset,
  29429. }
  29430. if (e.type === 'nodechange' || !isEq$4(fakeRng, lastRng)) {
  29431. editor.fire('SelectionChange')
  29432. }
  29433. lastRng = fakeRng
  29434. })
  29435. }
  29436. editor.on('contextmenu', function () {
  29437. editor.fire('SelectionChange')
  29438. })
  29439. editor.on('SelectionChange', function () {
  29440. var startElm = editor.selection.getStart(true)
  29441. if (!startElm || (!Env.range && editor.selection.isCollapsed())) {
  29442. return
  29443. }
  29444. if (
  29445. hasAnyRanges(editor) &&
  29446. !self.isSameElementPath(startElm) &&
  29447. editor.dom.isChildOf(startElm, editor.getBody())
  29448. ) {
  29449. editor.nodeChanged({ selectionChange: true })
  29450. }
  29451. })
  29452. editor.on('mouseup', function (e) {
  29453. if (!e.isDefaultPrevented() && hasAnyRanges(editor)) {
  29454. if (editor.selection.getNode().nodeName === 'IMG') {
  29455. Delay.setEditorTimeout(editor, function () {
  29456. editor.nodeChanged()
  29457. })
  29458. } else {
  29459. editor.nodeChanged()
  29460. }
  29461. }
  29462. })
  29463. }
  29464. NodeChange.prototype.nodeChanged = function (args) {
  29465. var selection = this.editor.selection
  29466. var node, parents, root
  29467. if (
  29468. this.editor.initialized &&
  29469. selection &&
  29470. !shouldDisableNodeChange(this.editor) &&
  29471. !this.editor.mode.isReadOnly()
  29472. ) {
  29473. root = this.editor.getBody()
  29474. node = selection.getStart(true) || root
  29475. if (
  29476. node.ownerDocument !== this.editor.getDoc() ||
  29477. !this.editor.dom.isChildOf(node, root)
  29478. ) {
  29479. node = root
  29480. }
  29481. parents = []
  29482. this.editor.dom.getParent(node, function (node) {
  29483. if (node === root) {
  29484. return true
  29485. }
  29486. parents.push(node)
  29487. })
  29488. args = args || {}
  29489. args.element = node
  29490. args.parents = parents
  29491. this.editor.fire('NodeChange', args)
  29492. }
  29493. }
  29494. NodeChange.prototype.isSameElementPath = function (startElm) {
  29495. var i
  29496. var currentPath = this.editor
  29497. .$(startElm)
  29498. .parentsUntil(this.editor.getBody())
  29499. .add(startElm)
  29500. if (currentPath.length === this.lastPath.length) {
  29501. for (i = currentPath.length; i >= 0; i--) {
  29502. if (currentPath[i] !== this.lastPath[i]) {
  29503. break
  29504. }
  29505. }
  29506. if (i === -1) {
  29507. this.lastPath = currentPath
  29508. return true
  29509. }
  29510. }
  29511. this.lastPath = currentPath
  29512. return false
  29513. }
  29514. return NodeChange
  29515. })()
  29516. var preventSummaryToggle = function (editor) {
  29517. editor.on('click', function (e) {
  29518. if (editor.dom.getParent(e.target, 'details')) {
  29519. e.preventDefault()
  29520. }
  29521. })
  29522. }
  29523. var filterDetails = function (editor) {
  29524. editor.parser.addNodeFilter('details', function (elms) {
  29525. each$k(elms, function (details) {
  29526. details.attr('data-mce-open', details.attr('open'))
  29527. details.attr('open', 'open')
  29528. })
  29529. })
  29530. editor.serializer.addNodeFilter('details', function (elms) {
  29531. each$k(elms, function (details) {
  29532. var open = details.attr('data-mce-open')
  29533. details.attr('open', isString$1(open) ? open : null)
  29534. details.attr('data-mce-open', null)
  29535. })
  29536. })
  29537. }
  29538. var setup$3 = function (editor) {
  29539. preventSummaryToggle(editor)
  29540. filterDetails(editor)
  29541. }
  29542. var isTextBlockNode = function (node) {
  29543. return isElement$5(node) && isTextBlock$2(SugarElement.fromDom(node))
  29544. }
  29545. var normalizeSelection = function (editor) {
  29546. var rng = editor.selection.getRng()
  29547. var startPos = CaretPosition.fromRangeStart(rng)
  29548. var endPos = CaretPosition.fromRangeEnd(rng)
  29549. if (CaretPosition.isElementPosition(startPos)) {
  29550. var container = startPos.container()
  29551. if (isTextBlockNode(container)) {
  29552. firstPositionIn(container).each(function (pos) {
  29553. return rng.setStart(pos.container(), pos.offset())
  29554. })
  29555. }
  29556. }
  29557. if (CaretPosition.isElementPosition(endPos)) {
  29558. var container = startPos.container()
  29559. if (isTextBlockNode(container)) {
  29560. lastPositionIn(container).each(function (pos) {
  29561. return rng.setEnd(pos.container(), pos.offset())
  29562. })
  29563. }
  29564. }
  29565. editor.selection.setRng(normalize(rng))
  29566. }
  29567. var setup$2 = function (editor) {
  29568. editor.on('click', function (e) {
  29569. if (e.detail >= 3) {
  29570. normalizeSelection(editor)
  29571. }
  29572. })
  29573. }
  29574. var getAbsolutePosition = function (elm) {
  29575. var clientRect = elm.getBoundingClientRect()
  29576. var doc = elm.ownerDocument
  29577. var docElem = doc.documentElement
  29578. var win = doc.defaultView
  29579. return {
  29580. top: clientRect.top + win.pageYOffset - docElem.clientTop,
  29581. left: clientRect.left + win.pageXOffset - docElem.clientLeft,
  29582. }
  29583. }
  29584. var getBodyPosition = function (editor) {
  29585. return editor.inline
  29586. ? getAbsolutePosition(editor.getBody())
  29587. : {
  29588. left: 0,
  29589. top: 0,
  29590. }
  29591. }
  29592. var getScrollPosition = function (editor) {
  29593. var body = editor.getBody()
  29594. return editor.inline
  29595. ? {
  29596. left: body.scrollLeft,
  29597. top: body.scrollTop,
  29598. }
  29599. : {
  29600. left: 0,
  29601. top: 0,
  29602. }
  29603. }
  29604. var getBodyScroll = function (editor) {
  29605. var body = editor.getBody(),
  29606. docElm = editor.getDoc().documentElement
  29607. var inlineScroll = {
  29608. left: body.scrollLeft,
  29609. top: body.scrollTop,
  29610. }
  29611. var iframeScroll = {
  29612. left: body.scrollLeft || docElm.scrollLeft,
  29613. top: body.scrollTop || docElm.scrollTop,
  29614. }
  29615. return editor.inline ? inlineScroll : iframeScroll
  29616. }
  29617. var getMousePosition = function (editor, event) {
  29618. if (event.target.ownerDocument !== editor.getDoc()) {
  29619. var iframePosition = getAbsolutePosition(editor.getContentAreaContainer())
  29620. var scrollPosition = getBodyScroll(editor)
  29621. return {
  29622. left: event.pageX - iframePosition.left + scrollPosition.left,
  29623. top: event.pageY - iframePosition.top + scrollPosition.top,
  29624. }
  29625. }
  29626. return {
  29627. left: event.pageX,
  29628. top: event.pageY,
  29629. }
  29630. }
  29631. var calculatePosition = function (
  29632. bodyPosition,
  29633. scrollPosition,
  29634. mousePosition
  29635. ) {
  29636. return {
  29637. pageX: mousePosition.left - bodyPosition.left + scrollPosition.left,
  29638. pageY: mousePosition.top - bodyPosition.top + scrollPosition.top,
  29639. }
  29640. }
  29641. var calc = function (editor, event) {
  29642. return calculatePosition(
  29643. getBodyPosition(editor),
  29644. getScrollPosition(editor),
  29645. getMousePosition(editor, event)
  29646. )
  29647. }
  29648. var isContentEditableFalse$1 = isContentEditableFalse$b,
  29649. isContentEditableTrue$1 = isContentEditableTrue$4
  29650. var isDraggable = function (rootElm, elm) {
  29651. return isContentEditableFalse$1(elm) && elm !== rootElm
  29652. }
  29653. var isValidDropTarget = function (editor, targetElement, dragElement) {
  29654. if (
  29655. targetElement === dragElement ||
  29656. editor.dom.isChildOf(targetElement, dragElement)
  29657. ) {
  29658. return false
  29659. }
  29660. return !isContentEditableFalse$1(targetElement)
  29661. }
  29662. var cloneElement = function (elm) {
  29663. var cloneElm = elm.cloneNode(true)
  29664. cloneElm.removeAttribute('data-mce-selected')
  29665. return cloneElm
  29666. }
  29667. var createGhost = function (editor, elm, width, height) {
  29668. var dom = editor.dom
  29669. var clonedElm = elm.cloneNode(true)
  29670. dom.setStyles(clonedElm, {
  29671. width: width,
  29672. height: height,
  29673. })
  29674. dom.setAttrib(clonedElm, 'data-mce-selected', null)
  29675. var ghostElm = dom.create('div', {
  29676. class: 'mce-drag-container',
  29677. 'data-mce-bogus': 'all',
  29678. unselectable: 'on',
  29679. contenteditable: 'false',
  29680. })
  29681. dom.setStyles(ghostElm, {
  29682. position: 'absolute',
  29683. opacity: 0.5,
  29684. overflow: 'hidden',
  29685. border: 0,
  29686. padding: 0,
  29687. margin: 0,
  29688. width: width,
  29689. height: height,
  29690. })
  29691. dom.setStyles(clonedElm, {
  29692. margin: 0,
  29693. boxSizing: 'border-box',
  29694. })
  29695. ghostElm.appendChild(clonedElm)
  29696. return ghostElm
  29697. }
  29698. var appendGhostToBody = function (ghostElm, bodyElm) {
  29699. if (ghostElm.parentNode !== bodyElm) {
  29700. bodyElm.appendChild(ghostElm)
  29701. }
  29702. }
  29703. var moveGhost = function (ghostElm, position, width, height, maxX, maxY) {
  29704. var overflowX = 0,
  29705. overflowY = 0
  29706. ghostElm.style.left = position.pageX + 'px'
  29707. ghostElm.style.top = position.pageY + 'px'
  29708. if (position.pageX + width > maxX) {
  29709. overflowX = position.pageX + width - maxX
  29710. }
  29711. if (position.pageY + height > maxY) {
  29712. overflowY = position.pageY + height - maxY
  29713. }
  29714. ghostElm.style.width = width - overflowX + 'px'
  29715. ghostElm.style.height = height - overflowY + 'px'
  29716. }
  29717. var removeElement = function (elm) {
  29718. if (elm && elm.parentNode) {
  29719. elm.parentNode.removeChild(elm)
  29720. }
  29721. }
  29722. var isLeftMouseButtonPressed = function (e) {
  29723. return e.button === 0
  29724. }
  29725. var applyRelPos = function (state, position) {
  29726. return {
  29727. pageX: position.pageX - state.relX,
  29728. pageY: position.pageY + 5,
  29729. }
  29730. }
  29731. var start = function (state, editor) {
  29732. return function (e) {
  29733. if (isLeftMouseButtonPressed(e)) {
  29734. var ceElm = find$3(
  29735. editor.dom.getParents(e.target),
  29736. or(isContentEditableFalse$1, isContentEditableTrue$1)
  29737. ).getOr(null)
  29738. if (isDraggable(editor.getBody(), ceElm)) {
  29739. var elmPos = editor.dom.getPos(ceElm)
  29740. var bodyElm = editor.getBody()
  29741. var docElm = editor.getDoc().documentElement
  29742. state.set({
  29743. element: ceElm,
  29744. dragging: false,
  29745. screenX: e.screenX,
  29746. screenY: e.screenY,
  29747. maxX:
  29748. (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2,
  29749. maxY:
  29750. (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2,
  29751. relX: e.pageX - elmPos.x,
  29752. relY: e.pageY - elmPos.y,
  29753. width: ceElm.offsetWidth,
  29754. height: ceElm.offsetHeight,
  29755. ghost: createGhost(
  29756. editor,
  29757. ceElm,
  29758. ceElm.offsetWidth,
  29759. ceElm.offsetHeight
  29760. ),
  29761. })
  29762. }
  29763. }
  29764. }
  29765. }
  29766. var move = function (state, editor) {
  29767. var throttledPlaceCaretAt = Delay.throttle(function (clientX, clientY) {
  29768. editor._selectionOverrides.hideFakeCaret()
  29769. editor.selection.placeCaretAt(clientX, clientY)
  29770. }, 0)
  29771. editor.on('remove', throttledPlaceCaretAt.stop)
  29772. return function (e) {
  29773. return state.on(function (state) {
  29774. var movement = Math.max(
  29775. Math.abs(e.screenX - state.screenX),
  29776. Math.abs(e.screenY - state.screenY)
  29777. )
  29778. if (!state.dragging && movement > 10) {
  29779. var args = editor.fire('dragstart', { target: state.element })
  29780. if (args.isDefaultPrevented()) {
  29781. return
  29782. }
  29783. state.dragging = true
  29784. editor.focus()
  29785. }
  29786. if (state.dragging) {
  29787. var targetPos = applyRelPos(state, calc(editor, e))
  29788. appendGhostToBody(state.ghost, editor.getBody())
  29789. moveGhost(
  29790. state.ghost,
  29791. targetPos,
  29792. state.width,
  29793. state.height,
  29794. state.maxX,
  29795. state.maxY
  29796. )
  29797. throttledPlaceCaretAt(e.clientX, e.clientY)
  29798. }
  29799. })
  29800. }
  29801. }
  29802. var getRawTarget = function (selection) {
  29803. var rng = selection.getSel().getRangeAt(0)
  29804. var startContainer = rng.startContainer
  29805. return startContainer.nodeType === 3
  29806. ? startContainer.parentNode
  29807. : startContainer
  29808. }
  29809. var drop = function (state, editor) {
  29810. return function (e) {
  29811. state.on(function (state) {
  29812. if (state.dragging) {
  29813. if (
  29814. isValidDropTarget(
  29815. editor,
  29816. getRawTarget(editor.selection),
  29817. state.element
  29818. )
  29819. ) {
  29820. var targetClone_1 = cloneElement(state.element)
  29821. var args = editor.fire('drop', {
  29822. clientX: e.clientX,
  29823. clientY: e.clientY,
  29824. })
  29825. if (!args.isDefaultPrevented()) {
  29826. editor.undoManager.transact(function () {
  29827. removeElement(state.element)
  29828. editor.insertContent(editor.dom.getOuterHTML(targetClone_1))
  29829. editor._selectionOverrides.hideFakeCaret()
  29830. })
  29831. }
  29832. }
  29833. editor.fire('dragend')
  29834. }
  29835. })
  29836. removeDragState(state)
  29837. }
  29838. }
  29839. var stop = function (state, editor) {
  29840. return function () {
  29841. state.on(function (state) {
  29842. if (state.dragging) {
  29843. editor.fire('dragend')
  29844. }
  29845. })
  29846. removeDragState(state)
  29847. }
  29848. }
  29849. var removeDragState = function (state) {
  29850. state.on(function (state) {
  29851. removeElement(state.ghost)
  29852. })
  29853. state.clear()
  29854. }
  29855. var bindFakeDragEvents = function (editor) {
  29856. var state = value()
  29857. var pageDom = DOMUtils.DOM
  29858. var rootDocument = document
  29859. var dragStartHandler = start(state, editor)
  29860. var dragHandler = move(state, editor)
  29861. var dropHandler = drop(state, editor)
  29862. var dragEndHandler = stop(state, editor)
  29863. editor.on('mousedown', dragStartHandler)
  29864. editor.on('mousemove', dragHandler)
  29865. editor.on('mouseup', dropHandler)
  29866. pageDom.bind(rootDocument, 'mousemove', dragHandler)
  29867. pageDom.bind(rootDocument, 'mouseup', dragEndHandler)
  29868. editor.on('remove', function () {
  29869. pageDom.unbind(rootDocument, 'mousemove', dragHandler)
  29870. pageDom.unbind(rootDocument, 'mouseup', dragEndHandler)
  29871. })
  29872. editor.on('keydown', function (e) {
  29873. if (e.keyCode === VK.ESC) {
  29874. dragEndHandler()
  29875. }
  29876. })
  29877. }
  29878. var blockIeDrop = function (editor) {
  29879. editor.on('drop', function (e) {
  29880. var realTarget =
  29881. typeof e.clientX !== 'undefined'
  29882. ? editor.getDoc().elementFromPoint(e.clientX, e.clientY)
  29883. : null
  29884. if (
  29885. isContentEditableFalse$1(realTarget) ||
  29886. editor.dom.getContentEditableParent(realTarget) === 'false'
  29887. ) {
  29888. e.preventDefault()
  29889. }
  29890. })
  29891. }
  29892. var blockUnsupportedFileDrop = function (editor) {
  29893. var preventFileDrop = function (e) {
  29894. if (!e.isDefaultPrevented()) {
  29895. var dataTransfer = e.dataTransfer
  29896. if (
  29897. dataTransfer &&
  29898. (contains$3(dataTransfer.types, 'Files') ||
  29899. dataTransfer.files.length > 0)
  29900. ) {
  29901. e.preventDefault()
  29902. if (e.type === 'drop') {
  29903. displayError(editor, 'Dropped file type is not supported')
  29904. }
  29905. }
  29906. }
  29907. }
  29908. var preventFileDropIfUIElement = function (e) {
  29909. if (isUIElement(editor, e.target)) {
  29910. preventFileDrop(e)
  29911. }
  29912. }
  29913. var setup = function () {
  29914. var pageDom = DOMUtils.DOM
  29915. var dom = editor.dom
  29916. var doc = document
  29917. var editorRoot = editor.inline ? editor.getBody() : editor.getDoc()
  29918. var eventNames = ['drop', 'dragover']
  29919. each$k(eventNames, function (name) {
  29920. pageDom.bind(doc, name, preventFileDropIfUIElement)
  29921. dom.bind(editorRoot, name, preventFileDrop)
  29922. })
  29923. editor.on('remove', function () {
  29924. each$k(eventNames, function (name) {
  29925. pageDom.unbind(doc, name, preventFileDropIfUIElement)
  29926. dom.unbind(editorRoot, name, preventFileDrop)
  29927. })
  29928. })
  29929. }
  29930. editor.on('init', function () {
  29931. Delay.setEditorTimeout(editor, setup, 0)
  29932. })
  29933. }
  29934. var init$2 = function (editor) {
  29935. bindFakeDragEvents(editor)
  29936. blockIeDrop(editor)
  29937. if (shouldBlockUnsupportedDrop(editor)) {
  29938. blockUnsupportedFileDrop(editor)
  29939. }
  29940. }
  29941. var setup$1 = function (editor) {
  29942. var renderFocusCaret = first(function () {
  29943. if (
  29944. !editor.removed &&
  29945. editor.getBody().contains(document.activeElement)
  29946. ) {
  29947. var rng = editor.selection.getRng()
  29948. if (rng.collapsed) {
  29949. var caretRange = renderRangeCaret(editor, rng, false)
  29950. editor.selection.setRng(caretRange)
  29951. }
  29952. }
  29953. }, 0)
  29954. editor.on('focus', function () {
  29955. renderFocusCaret.throttle()
  29956. })
  29957. editor.on('blur', function () {
  29958. renderFocusCaret.cancel()
  29959. })
  29960. }
  29961. var setup = function (editor) {
  29962. editor.on('init', function () {
  29963. editor.on('focusin', function (e) {
  29964. var target = e.target
  29965. if (isMedia$2(target)) {
  29966. var ceRoot = getContentEditableRoot$1(editor.getBody(), target)
  29967. var node = isContentEditableFalse$b(ceRoot) ? ceRoot : target
  29968. if (editor.selection.getNode() !== node) {
  29969. selectNode(editor, node).each(function (rng) {
  29970. return editor.selection.setRng(rng)
  29971. })
  29972. }
  29973. }
  29974. })
  29975. })
  29976. }
  29977. var isContentEditableTrue = isContentEditableTrue$4
  29978. var isContentEditableFalse = isContentEditableFalse$b
  29979. var getContentEditableRoot = function (editor, node) {
  29980. return getContentEditableRoot$1(editor.getBody(), node)
  29981. }
  29982. var SelectionOverrides = function (editor) {
  29983. var selection = editor.selection,
  29984. dom = editor.dom
  29985. var isBlock = dom.isBlock
  29986. var rootNode = editor.getBody()
  29987. var fakeCaret = FakeCaret(editor, rootNode, isBlock, function () {
  29988. return hasFocus(editor)
  29989. })
  29990. var realSelectionId = 'sel-' + dom.uniqueId()
  29991. var elementSelectionAttr = 'data-mce-selected'
  29992. var selectedElement
  29993. var isFakeSelectionElement = function (node) {
  29994. return dom.hasClass(node, 'mce-offscreen-selection')
  29995. }
  29996. var isFakeSelectionTargetElement = function (node) {
  29997. return (
  29998. node !== rootNode &&
  29999. (isContentEditableFalse(node) || isMedia$2(node)) &&
  30000. dom.isChildOf(node, rootNode)
  30001. )
  30002. }
  30003. var isNearFakeSelectionElement = function (pos) {
  30004. return (
  30005. isBeforeContentEditableFalse(pos) ||
  30006. isAfterContentEditableFalse(pos) ||
  30007. isBeforeMedia(pos) ||
  30008. isAfterMedia(pos)
  30009. )
  30010. }
  30011. var getRealSelectionElement = function () {
  30012. var container = dom.get(realSelectionId)
  30013. return container ? container.getElementsByTagName('*')[0] : container
  30014. }
  30015. var setRange = function (range) {
  30016. if (range) {
  30017. selection.setRng(range)
  30018. }
  30019. }
  30020. var getRange = selection.getRng
  30021. var showCaret = function (direction, node, before, scrollIntoView) {
  30022. if (scrollIntoView === void 0) {
  30023. scrollIntoView = true
  30024. }
  30025. var e = editor.fire('ShowCaret', {
  30026. target: node,
  30027. direction: direction,
  30028. before: before,
  30029. })
  30030. if (e.isDefaultPrevented()) {
  30031. return null
  30032. }
  30033. if (scrollIntoView) {
  30034. selection.scrollIntoView(node, direction === -1)
  30035. }
  30036. return fakeCaret.show(before, node)
  30037. }
  30038. var showBlockCaretContainer = function (blockCaretContainer) {
  30039. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  30040. showCaretContainerBlock(blockCaretContainer)
  30041. setRange(getRange())
  30042. selection.scrollIntoView(blockCaretContainer)
  30043. }
  30044. }
  30045. var registerEvents = function () {
  30046. editor.on('mouseup', function (e) {
  30047. var range = getRange()
  30048. if (
  30049. range.collapsed &&
  30050. isXYInContentArea(editor, e.clientX, e.clientY)
  30051. ) {
  30052. renderCaretAtRange(editor, range, false).each(setRange)
  30053. }
  30054. })
  30055. editor.on('click', function (e) {
  30056. var contentEditableRoot = getContentEditableRoot(editor, e.target)
  30057. if (contentEditableRoot) {
  30058. if (isContentEditableFalse(contentEditableRoot)) {
  30059. e.preventDefault()
  30060. editor.focus()
  30061. }
  30062. if (isContentEditableTrue(contentEditableRoot)) {
  30063. if (dom.isChildOf(contentEditableRoot, selection.getNode())) {
  30064. removeElementSelection()
  30065. }
  30066. }
  30067. }
  30068. })
  30069. editor.on('blur NewBlock', removeElementSelection)
  30070. editor.on('ResizeWindow FullscreenStateChanged', fakeCaret.reposition)
  30071. var hasNormalCaretPosition = function (elm) {
  30072. var start = elm.firstChild
  30073. if (isNullable(start)) {
  30074. return false
  30075. }
  30076. var startPos = CaretPosition.before(start)
  30077. if (isBr$5(startPos.getNode()) && elm.childNodes.length === 1) {
  30078. return !isNearFakeSelectionElement(startPos)
  30079. } else {
  30080. var caretWalker = CaretWalker(elm)
  30081. var newPos = caretWalker.next(startPos)
  30082. return newPos && !isNearFakeSelectionElement(newPos)
  30083. }
  30084. }
  30085. var isInSameBlock = function (node1, node2) {
  30086. var block1 = dom.getParent(node1, isBlock)
  30087. var block2 = dom.getParent(node2, isBlock)
  30088. return block1 === block2
  30089. }
  30090. var hasBetterMouseTarget = function (targetNode, caretNode) {
  30091. var targetBlock = dom.getParent(targetNode, isBlock)
  30092. var caretBlock = dom.getParent(caretNode, isBlock)
  30093. if (isNullable(targetBlock)) {
  30094. return false
  30095. }
  30096. if (
  30097. targetNode !== caretBlock &&
  30098. dom.isChildOf(targetBlock, caretBlock) &&
  30099. isContentEditableFalse(
  30100. getContentEditableRoot(editor, targetBlock)
  30101. ) === false
  30102. ) {
  30103. return true
  30104. }
  30105. return (
  30106. !dom.isChildOf(caretBlock, targetBlock) &&
  30107. !isInSameBlock(targetBlock, caretBlock) &&
  30108. hasNormalCaretPosition(targetBlock)
  30109. )
  30110. }
  30111. editor.on(
  30112. 'tap',
  30113. function (e) {
  30114. var targetElm = e.target
  30115. var contentEditableRoot = getContentEditableRoot(editor, targetElm)
  30116. if (isContentEditableFalse(contentEditableRoot)) {
  30117. e.preventDefault()
  30118. selectNode(editor, contentEditableRoot).each(setElementSelection)
  30119. } else if (isFakeSelectionTargetElement(targetElm)) {
  30120. selectNode(editor, targetElm).each(setElementSelection)
  30121. }
  30122. },
  30123. true
  30124. )
  30125. editor.on('mousedown', function (e) {
  30126. var targetElm = e.target
  30127. if (
  30128. targetElm !== rootNode &&
  30129. targetElm.nodeName !== 'HTML' &&
  30130. !dom.isChildOf(targetElm, rootNode)
  30131. ) {
  30132. return
  30133. }
  30134. if (isXYInContentArea(editor, e.clientX, e.clientY) === false) {
  30135. return
  30136. }
  30137. var contentEditableRoot = getContentEditableRoot(editor, targetElm)
  30138. if (contentEditableRoot) {
  30139. if (isContentEditableFalse(contentEditableRoot)) {
  30140. e.preventDefault()
  30141. selectNode(editor, contentEditableRoot).each(setElementSelection)
  30142. } else {
  30143. removeElementSelection()
  30144. if (
  30145. !(isContentEditableTrue(contentEditableRoot) && e.shiftKey) &&
  30146. !isXYWithinRange(e.clientX, e.clientY, selection.getRng())
  30147. ) {
  30148. hideFakeCaret()
  30149. selection.placeCaretAt(e.clientX, e.clientY)
  30150. }
  30151. }
  30152. } else if (isFakeSelectionTargetElement(targetElm)) {
  30153. selectNode(editor, targetElm).each(setElementSelection)
  30154. } else if (isFakeCaretTarget(targetElm) === false) {
  30155. removeElementSelection()
  30156. hideFakeCaret()
  30157. var fakeCaretInfo = closestFakeCaret(rootNode, e.clientX, e.clientY)
  30158. if (fakeCaretInfo) {
  30159. if (!hasBetterMouseTarget(targetElm, fakeCaretInfo.node)) {
  30160. e.preventDefault()
  30161. var range = showCaret(
  30162. 1,
  30163. fakeCaretInfo.node,
  30164. fakeCaretInfo.before,
  30165. false
  30166. )
  30167. setRange(range)
  30168. editor.getBody().focus()
  30169. }
  30170. }
  30171. }
  30172. })
  30173. editor.on('keypress', function (e) {
  30174. if (VK.modifierPressed(e)) {
  30175. return
  30176. }
  30177. if (isContentEditableFalse(selection.getNode())) {
  30178. e.preventDefault()
  30179. }
  30180. })
  30181. editor.on('GetSelectionRange', function (e) {
  30182. var rng = e.range
  30183. if (selectedElement) {
  30184. if (!selectedElement.parentNode) {
  30185. selectedElement = null
  30186. return
  30187. }
  30188. rng = rng.cloneRange()
  30189. rng.selectNode(selectedElement)
  30190. e.range = rng
  30191. }
  30192. })
  30193. editor.on('SetSelectionRange', function (e) {
  30194. e.range = normalizeShortEndedElementSelection(e.range)
  30195. var rng = setElementSelection(e.range, e.forward)
  30196. if (rng) {
  30197. e.range = rng
  30198. }
  30199. })
  30200. var isPasteBin = function (node) {
  30201. return node.id === 'mcepastebin'
  30202. }
  30203. editor.on('AfterSetSelectionRange', function (e) {
  30204. var rng = e.range
  30205. var parentNode = rng.startContainer.parentNode
  30206. if (!isRangeInCaretContainer(rng) && !isPasteBin(parentNode)) {
  30207. hideFakeCaret()
  30208. }
  30209. if (!isFakeSelectionElement(parentNode)) {
  30210. removeElementSelection()
  30211. }
  30212. })
  30213. editor.on('copy', function (e) {
  30214. var clipboardData = e.clipboardData
  30215. if (!e.isDefaultPrevented() && e.clipboardData && !Env.ie) {
  30216. var realSelectionElement = getRealSelectionElement()
  30217. if (realSelectionElement) {
  30218. e.preventDefault()
  30219. clipboardData.clearData()
  30220. clipboardData.setData('text/html', realSelectionElement.outerHTML)
  30221. clipboardData.setData(
  30222. 'text/plain',
  30223. realSelectionElement.outerText || realSelectionElement.innerText
  30224. )
  30225. }
  30226. }
  30227. })
  30228. init$2(editor)
  30229. setup$1(editor)
  30230. setup(editor)
  30231. }
  30232. var isWithinCaretContainer = function (node) {
  30233. return (
  30234. isCaretContainer$2(node) ||
  30235. startsWithCaretContainer$1(node) ||
  30236. endsWithCaretContainer$1(node)
  30237. )
  30238. }
  30239. var isRangeInCaretContainer = function (rng) {
  30240. return (
  30241. isWithinCaretContainer(rng.startContainer) ||
  30242. isWithinCaretContainer(rng.endContainer)
  30243. )
  30244. }
  30245. var normalizeShortEndedElementSelection = function (rng) {
  30246. var shortEndedElements = editor.schema.getShortEndedElements()
  30247. var newRng = dom.createRng()
  30248. var startContainer = rng.startContainer
  30249. var startOffset = rng.startOffset
  30250. var endContainer = rng.endContainer
  30251. var endOffset = rng.endOffset
  30252. if (has$2(shortEndedElements, startContainer.nodeName.toLowerCase())) {
  30253. if (startOffset === 0) {
  30254. newRng.setStartBefore(startContainer)
  30255. } else {
  30256. newRng.setStartAfter(startContainer)
  30257. }
  30258. } else {
  30259. newRng.setStart(startContainer, startOffset)
  30260. }
  30261. if (has$2(shortEndedElements, endContainer.nodeName.toLowerCase())) {
  30262. if (endOffset === 0) {
  30263. newRng.setEndBefore(endContainer)
  30264. } else {
  30265. newRng.setEndAfter(endContainer)
  30266. }
  30267. } else {
  30268. newRng.setEnd(endContainer, endOffset)
  30269. }
  30270. return newRng
  30271. }
  30272. var setupOffscreenSelection = function (
  30273. node,
  30274. targetClone,
  30275. origTargetClone
  30276. ) {
  30277. var $ = editor.$
  30278. var $realSelectionContainer = descendant(
  30279. SugarElement.fromDom(editor.getBody()),
  30280. '#' + realSelectionId
  30281. ).fold(
  30282. function () {
  30283. return $([])
  30284. },
  30285. function (elm) {
  30286. return $([elm.dom])
  30287. }
  30288. )
  30289. if ($realSelectionContainer.length === 0) {
  30290. $realSelectionContainer = $(
  30291. '<div data-mce-bogus="all" class="mce-offscreen-selection"></div>'
  30292. ).attr('id', realSelectionId)
  30293. $realSelectionContainer.appendTo(editor.getBody())
  30294. }
  30295. var newRange = dom.createRng()
  30296. if (targetClone === origTargetClone && Env.ie) {
  30297. $realSelectionContainer
  30298. .empty()
  30299. .append('<p style="font-size: 0" data-mce-bogus="all">\xA0</p>')
  30300. .append(targetClone)
  30301. newRange.setStartAfter($realSelectionContainer[0].firstChild.firstChild)
  30302. newRange.setEndAfter(targetClone)
  30303. } else {
  30304. $realSelectionContainer
  30305. .empty()
  30306. .append(nbsp)
  30307. .append(targetClone)
  30308. .append(nbsp)
  30309. newRange.setStart($realSelectionContainer[0].firstChild, 1)
  30310. newRange.setEnd($realSelectionContainer[0].lastChild, 0)
  30311. }
  30312. $realSelectionContainer.css({ top: dom.getPos(node, editor.getBody()).y })
  30313. $realSelectionContainer[0].focus()
  30314. var sel = selection.getSel()
  30315. sel.removeAllRanges()
  30316. sel.addRange(newRange)
  30317. return newRange
  30318. }
  30319. var selectElement = function (elm) {
  30320. var targetClone = elm.cloneNode(true)
  30321. var e = editor.fire('ObjectSelected', {
  30322. target: elm,
  30323. targetClone: targetClone,
  30324. })
  30325. if (e.isDefaultPrevented()) {
  30326. return null
  30327. }
  30328. var range = setupOffscreenSelection(elm, e.targetClone, targetClone)
  30329. var nodeElm = SugarElement.fromDom(elm)
  30330. each$k(
  30331. descendants(
  30332. SugarElement.fromDom(editor.getBody()),
  30333. '*[data-mce-selected]'
  30334. ),
  30335. function (elm) {
  30336. if (!eq(nodeElm, elm)) {
  30337. remove$6(elm, elementSelectionAttr)
  30338. }
  30339. }
  30340. )
  30341. if (!dom.getAttrib(elm, elementSelectionAttr)) {
  30342. elm.setAttribute(elementSelectionAttr, '1')
  30343. }
  30344. selectedElement = elm
  30345. hideFakeCaret()
  30346. return range
  30347. }
  30348. var setElementSelection = function (range, forward) {
  30349. if (!range) {
  30350. return null
  30351. }
  30352. if (range.collapsed) {
  30353. if (!isRangeInCaretContainer(range)) {
  30354. var dir = forward ? 1 : -1
  30355. var caretPosition = getNormalizedRangeEndPoint(dir, rootNode, range)
  30356. var beforeNode = caretPosition.getNode(!forward)
  30357. if (isFakeCaretTarget(beforeNode)) {
  30358. return showCaret(
  30359. dir,
  30360. beforeNode,
  30361. forward ? !caretPosition.isAtEnd() : false,
  30362. false
  30363. )
  30364. }
  30365. var afterNode = caretPosition.getNode(forward)
  30366. if (isFakeCaretTarget(afterNode)) {
  30367. return showCaret(
  30368. dir,
  30369. afterNode,
  30370. forward ? false : !caretPosition.isAtEnd(),
  30371. false
  30372. )
  30373. }
  30374. }
  30375. return null
  30376. }
  30377. var startContainer = range.startContainer
  30378. var startOffset = range.startOffset
  30379. var endOffset = range.endOffset
  30380. if (
  30381. startContainer.nodeType === 3 &&
  30382. startOffset === 0 &&
  30383. isContentEditableFalse(startContainer.parentNode)
  30384. ) {
  30385. startContainer = startContainer.parentNode
  30386. startOffset = dom.nodeIndex(startContainer)
  30387. startContainer = startContainer.parentNode
  30388. }
  30389. if (startContainer.nodeType !== 1) {
  30390. return null
  30391. }
  30392. if (
  30393. endOffset === startOffset + 1 &&
  30394. startContainer === range.endContainer
  30395. ) {
  30396. var node = startContainer.childNodes[startOffset]
  30397. if (isFakeSelectionTargetElement(node)) {
  30398. return selectElement(node)
  30399. }
  30400. }
  30401. return null
  30402. }
  30403. var removeElementSelection = function () {
  30404. if (selectedElement) {
  30405. selectedElement.removeAttribute(elementSelectionAttr)
  30406. }
  30407. descendant(
  30408. SugarElement.fromDom(editor.getBody()),
  30409. '#' + realSelectionId
  30410. ).each(remove$7)
  30411. selectedElement = null
  30412. }
  30413. var destroy = function () {
  30414. fakeCaret.destroy()
  30415. selectedElement = null
  30416. }
  30417. var hideFakeCaret = function () {
  30418. fakeCaret.hide()
  30419. }
  30420. if (Env.ceFalse && !isRtc(editor)) {
  30421. registerEvents()
  30422. }
  30423. return {
  30424. showCaret: showCaret,
  30425. showBlockCaretContainer: showBlockCaretContainer,
  30426. hideFakeCaret: hideFakeCaret,
  30427. destroy: destroy,
  30428. }
  30429. }
  30430. var Quirks = function (editor) {
  30431. var each = Tools.each
  30432. var BACKSPACE = VK.BACKSPACE,
  30433. DELETE = VK.DELETE,
  30434. dom = editor.dom,
  30435. selection = editor.selection,
  30436. parser = editor.parser
  30437. var isGecko = Env.gecko,
  30438. isIE = Env.ie,
  30439. isWebKit = Env.webkit
  30440. var mceInternalUrlPrefix = 'data:text/mce-internal,'
  30441. var mceInternalDataType = isIE ? 'Text' : 'URL'
  30442. var setEditorCommandState = function (cmd, state) {
  30443. try {
  30444. editor.getDoc().execCommand(cmd, false, state)
  30445. } catch (ex) {}
  30446. }
  30447. var isDefaultPrevented = function (e) {
  30448. return e.isDefaultPrevented()
  30449. }
  30450. var setMceInternalContent = function (e) {
  30451. var selectionHtml, internalContent
  30452. if (e.dataTransfer) {
  30453. if (editor.selection.isCollapsed() && e.target.tagName === 'IMG') {
  30454. selection.select(e.target)
  30455. }
  30456. selectionHtml = editor.selection.getContent()
  30457. if (selectionHtml.length > 0) {
  30458. internalContent =
  30459. mceInternalUrlPrefix +
  30460. escape(editor.id) +
  30461. ',' +
  30462. escape(selectionHtml)
  30463. e.dataTransfer.setData(mceInternalDataType, internalContent)
  30464. }
  30465. }
  30466. }
  30467. var getMceInternalContent = function (e) {
  30468. var internalContent
  30469. if (e.dataTransfer) {
  30470. internalContent = e.dataTransfer.getData(mceInternalDataType)
  30471. if (
  30472. internalContent &&
  30473. internalContent.indexOf(mceInternalUrlPrefix) >= 0
  30474. ) {
  30475. internalContent = internalContent
  30476. .substr(mceInternalUrlPrefix.length)
  30477. .split(',')
  30478. return {
  30479. id: unescape(internalContent[0]),
  30480. html: unescape(internalContent[1]),
  30481. }
  30482. }
  30483. }
  30484. return null
  30485. }
  30486. var insertClipboardContents = function (content, internal) {
  30487. if (editor.queryCommandSupported('mceInsertClipboardContent')) {
  30488. editor.execCommand('mceInsertClipboardContent', false, {
  30489. content: content,
  30490. internal: internal,
  30491. })
  30492. } else {
  30493. editor.execCommand('mceInsertContent', false, content)
  30494. }
  30495. }
  30496. var emptyEditorWhenDeleting = function () {
  30497. var serializeRng = function (rng) {
  30498. var body = dom.create('body')
  30499. var contents = rng.cloneContents()
  30500. body.appendChild(contents)
  30501. return selection.serializer.serialize(body, { format: 'html' })
  30502. }
  30503. var allContentsSelected = function (rng) {
  30504. var selection = serializeRng(rng)
  30505. var allRng = dom.createRng()
  30506. allRng.selectNode(editor.getBody())
  30507. var allSelection = serializeRng(allRng)
  30508. return selection === allSelection
  30509. }
  30510. editor.on('keydown', function (e) {
  30511. var keyCode = e.keyCode
  30512. var isCollapsed, body
  30513. if (
  30514. !isDefaultPrevented(e) &&
  30515. (keyCode === DELETE || keyCode === BACKSPACE)
  30516. ) {
  30517. isCollapsed = editor.selection.isCollapsed()
  30518. body = editor.getBody()
  30519. if (isCollapsed && !dom.isEmpty(body)) {
  30520. return
  30521. }
  30522. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  30523. return
  30524. }
  30525. e.preventDefault()
  30526. editor.setContent('')
  30527. if (body.firstChild && dom.isBlock(body.firstChild)) {
  30528. editor.selection.setCursorLocation(body.firstChild, 0)
  30529. } else {
  30530. editor.selection.setCursorLocation(body, 0)
  30531. }
  30532. editor.nodeChanged()
  30533. }
  30534. })
  30535. }
  30536. var selectAll = function () {
  30537. editor.shortcuts.add('meta+a', null, 'SelectAll')
  30538. }
  30539. var documentElementEditingFocus = function () {
  30540. if (!editor.inline) {
  30541. dom.bind(editor.getDoc(), 'mousedown mouseup', function (e) {
  30542. var rng
  30543. if (e.target === editor.getDoc().documentElement) {
  30544. rng = selection.getRng()
  30545. editor.getBody().focus()
  30546. if (e.type === 'mousedown') {
  30547. if (isCaretContainer$2(rng.startContainer)) {
  30548. return
  30549. }
  30550. selection.placeCaretAt(e.clientX, e.clientY)
  30551. } else {
  30552. selection.setRng(rng)
  30553. }
  30554. }
  30555. })
  30556. }
  30557. }
  30558. var removeHrOnBackspace = function () {
  30559. editor.on('keydown', function (e) {
  30560. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  30561. if (!editor.getBody().getElementsByTagName('hr').length) {
  30562. return
  30563. }
  30564. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  30565. var node = selection.getNode()
  30566. var previousSibling = node.previousSibling
  30567. if (node.nodeName === 'HR') {
  30568. dom.remove(node)
  30569. e.preventDefault()
  30570. return
  30571. }
  30572. if (
  30573. previousSibling &&
  30574. previousSibling.nodeName &&
  30575. previousSibling.nodeName.toLowerCase() === 'hr'
  30576. ) {
  30577. dom.remove(previousSibling)
  30578. e.preventDefault()
  30579. }
  30580. }
  30581. }
  30582. })
  30583. }
  30584. var focusBody = function () {
  30585. if (!Range.prototype.getClientRects) {
  30586. editor.on('mousedown', function (e) {
  30587. if (!isDefaultPrevented(e) && e.target.nodeName === 'HTML') {
  30588. var body_1 = editor.getBody()
  30589. body_1.blur()
  30590. Delay.setEditorTimeout(editor, function () {
  30591. body_1.focus()
  30592. })
  30593. }
  30594. })
  30595. }
  30596. }
  30597. var selectControlElements = function () {
  30598. editor.on('click', function (e) {
  30599. var target = e.target
  30600. if (
  30601. /^(IMG|HR)$/.test(target.nodeName) &&
  30602. dom.getContentEditableParent(target) !== 'false'
  30603. ) {
  30604. e.preventDefault()
  30605. editor.selection.select(target)
  30606. editor.nodeChanged()
  30607. }
  30608. if (
  30609. target.nodeName === 'A' &&
  30610. dom.hasClass(target, 'mce-item-anchor')
  30611. ) {
  30612. e.preventDefault()
  30613. selection.select(target)
  30614. }
  30615. })
  30616. }
  30617. var removeStylesWhenDeletingAcrossBlockElements = function () {
  30618. var getAttributeApplyFunction = function () {
  30619. var template = dom.getAttribs(selection.getStart().cloneNode(false))
  30620. return function () {
  30621. var target = selection.getStart()
  30622. if (target !== editor.getBody()) {
  30623. dom.setAttrib(target, 'style', null)
  30624. each(template, function (attr) {
  30625. target.setAttributeNode(attr.cloneNode(true))
  30626. })
  30627. }
  30628. }
  30629. }
  30630. var isSelectionAcrossElements = function () {
  30631. return (
  30632. !selection.isCollapsed() &&
  30633. dom.getParent(selection.getStart(), dom.isBlock) !==
  30634. dom.getParent(selection.getEnd(), dom.isBlock)
  30635. )
  30636. }
  30637. editor.on('keypress', function (e) {
  30638. var applyAttributes
  30639. if (
  30640. !isDefaultPrevented(e) &&
  30641. (e.keyCode === 8 || e.keyCode === 46) &&
  30642. isSelectionAcrossElements()
  30643. ) {
  30644. applyAttributes = getAttributeApplyFunction()
  30645. editor.getDoc().execCommand('delete', false, null)
  30646. applyAttributes()
  30647. e.preventDefault()
  30648. return false
  30649. }
  30650. })
  30651. dom.bind(editor.getDoc(), 'cut', function (e) {
  30652. var applyAttributes
  30653. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  30654. applyAttributes = getAttributeApplyFunction()
  30655. Delay.setEditorTimeout(editor, function () {
  30656. applyAttributes()
  30657. })
  30658. }
  30659. })
  30660. }
  30661. var disableBackspaceIntoATable = function () {
  30662. editor.on('keydown', function (e) {
  30663. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  30664. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  30665. var previousSibling = selection.getNode().previousSibling
  30666. if (
  30667. previousSibling &&
  30668. previousSibling.nodeName &&
  30669. previousSibling.nodeName.toLowerCase() === 'table'
  30670. ) {
  30671. e.preventDefault()
  30672. return false
  30673. }
  30674. }
  30675. }
  30676. })
  30677. }
  30678. var removeBlockQuoteOnBackSpace = function () {
  30679. editor.on('keydown', function (e) {
  30680. var rng, parent
  30681. if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) {
  30682. return
  30683. }
  30684. rng = selection.getRng()
  30685. var container = rng.startContainer
  30686. var offset = rng.startOffset
  30687. var root = dom.getRoot()
  30688. parent = container
  30689. if (!rng.collapsed || offset !== 0) {
  30690. return
  30691. }
  30692. while (
  30693. parent &&
  30694. parent.parentNode &&
  30695. parent.parentNode.firstChild === parent &&
  30696. parent.parentNode !== root
  30697. ) {
  30698. parent = parent.parentNode
  30699. }
  30700. if (parent.tagName === 'BLOCKQUOTE') {
  30701. editor.formatter.toggle('blockquote', null, parent)
  30702. rng = dom.createRng()
  30703. rng.setStart(container, 0)
  30704. rng.setEnd(container, 0)
  30705. selection.setRng(rng)
  30706. }
  30707. })
  30708. }
  30709. var setGeckoEditingOptions = function () {
  30710. var setOpts = function () {
  30711. setEditorCommandState('StyleWithCSS', false)
  30712. setEditorCommandState('enableInlineTableEditing', false)
  30713. if (!getObjectResizing(editor)) {
  30714. setEditorCommandState('enableObjectResizing', false)
  30715. }
  30716. }
  30717. if (!isReadOnly$1(editor)) {
  30718. editor.on('BeforeExecCommand mousedown', setOpts)
  30719. }
  30720. }
  30721. var addBrAfterLastLinks = function () {
  30722. var fixLinks = function () {
  30723. each(dom.select('a'), function (node) {
  30724. var parentNode = node.parentNode
  30725. var root = dom.getRoot()
  30726. if (parentNode.lastChild === node) {
  30727. while (parentNode && !dom.isBlock(parentNode)) {
  30728. if (
  30729. parentNode.parentNode.lastChild !== parentNode ||
  30730. parentNode === root
  30731. ) {
  30732. return
  30733. }
  30734. parentNode = parentNode.parentNode
  30735. }
  30736. dom.add(parentNode, 'br', { 'data-mce-bogus': 1 })
  30737. }
  30738. })
  30739. }
  30740. editor.on('SetContent ExecCommand', function (e) {
  30741. if (e.type === 'setcontent' || e.command === 'mceInsertLink') {
  30742. fixLinks()
  30743. }
  30744. })
  30745. }
  30746. var setDefaultBlockType = function () {
  30747. if (getForcedRootBlock(editor)) {
  30748. editor.on('init', function () {
  30749. setEditorCommandState(
  30750. 'DefaultParagraphSeparator',
  30751. getForcedRootBlock(editor)
  30752. )
  30753. })
  30754. }
  30755. }
  30756. var normalizeSelection = function () {
  30757. editor.on(
  30758. 'keyup focusin mouseup',
  30759. function (e) {
  30760. if (!VK.modifierPressed(e)) {
  30761. selection.normalize()
  30762. }
  30763. },
  30764. true
  30765. )
  30766. }
  30767. var showBrokenImageIcon = function () {
  30768. editor.contentStyles.push(
  30769. 'img:-moz-broken {' +
  30770. '-moz-force-broken-image-icon:1;' +
  30771. 'min-width:24px;' +
  30772. 'min-height:24px' +
  30773. '}'
  30774. )
  30775. }
  30776. var restoreFocusOnKeyDown = function () {
  30777. if (!editor.inline) {
  30778. editor.on('keydown', function () {
  30779. if (document.activeElement === document.body) {
  30780. editor.getWin().focus()
  30781. }
  30782. })
  30783. }
  30784. }
  30785. var bodyHeight = function () {
  30786. if (!editor.inline) {
  30787. editor.contentStyles.push('body {min-height: 150px}')
  30788. editor.on('click', function (e) {
  30789. var rng
  30790. if (e.target.nodeName === 'HTML') {
  30791. if (Env.ie > 11) {
  30792. editor.getBody().focus()
  30793. return
  30794. }
  30795. rng = editor.selection.getRng()
  30796. editor.getBody().focus()
  30797. editor.selection.setRng(rng)
  30798. editor.selection.normalize()
  30799. editor.nodeChanged()
  30800. }
  30801. })
  30802. }
  30803. }
  30804. var blockCmdArrowNavigation = function () {
  30805. if (Env.mac) {
  30806. editor.on('keydown', function (e) {
  30807. if (
  30808. VK.metaKeyPressed(e) &&
  30809. !e.shiftKey &&
  30810. (e.keyCode === 37 || e.keyCode === 39)
  30811. ) {
  30812. e.preventDefault()
  30813. var selection_1 = editor.selection.getSel()
  30814. selection_1.modify(
  30815. 'move',
  30816. e.keyCode === 37 ? 'backward' : 'forward',
  30817. 'lineboundary'
  30818. )
  30819. }
  30820. })
  30821. }
  30822. }
  30823. var disableAutoUrlDetect = function () {
  30824. setEditorCommandState('AutoUrlDetect', false)
  30825. }
  30826. var tapLinksAndImages = function () {
  30827. editor.on('click', function (e) {
  30828. var elm = e.target
  30829. do {
  30830. if (elm.tagName === 'A') {
  30831. e.preventDefault()
  30832. return
  30833. }
  30834. } while ((elm = elm.parentNode))
  30835. })
  30836. editor.contentStyles.push(
  30837. '.mce-content-body {-webkit-touch-callout: none}'
  30838. )
  30839. }
  30840. var blockFormSubmitInsideEditor = function () {
  30841. editor.on('init', function () {
  30842. editor.dom.bind(editor.getBody(), 'submit', function (e) {
  30843. e.preventDefault()
  30844. })
  30845. })
  30846. }
  30847. var removeAppleInterchangeBrs = function () {
  30848. parser.addNodeFilter('br', function (nodes) {
  30849. var i = nodes.length
  30850. while (i--) {
  30851. if (nodes[i].attr('class') === 'Apple-interchange-newline') {
  30852. nodes[i].remove()
  30853. }
  30854. }
  30855. })
  30856. }
  30857. var ieInternalDragAndDrop = function () {
  30858. editor.on('dragstart', function (e) {
  30859. setMceInternalContent(e)
  30860. })
  30861. editor.on('drop', function (e) {
  30862. if (!isDefaultPrevented(e)) {
  30863. var internalContent = getMceInternalContent(e)
  30864. if (internalContent && internalContent.id !== editor.id) {
  30865. e.preventDefault()
  30866. var rng = fromPoint(e.x, e.y, editor.getDoc())
  30867. selection.setRng(rng)
  30868. insertClipboardContents(internalContent.html, true)
  30869. }
  30870. }
  30871. })
  30872. }
  30873. var refreshContentEditable = noop
  30874. var isHidden = function () {
  30875. if (!isGecko || editor.removed) {
  30876. return false
  30877. }
  30878. var sel = editor.selection.getSel()
  30879. return !sel || !sel.rangeCount || sel.rangeCount === 0
  30880. }
  30881. var setupRtc = function () {
  30882. if (isWebKit) {
  30883. documentElementEditingFocus()
  30884. selectControlElements()
  30885. blockFormSubmitInsideEditor()
  30886. selectAll()
  30887. if (Env.iOS) {
  30888. restoreFocusOnKeyDown()
  30889. bodyHeight()
  30890. tapLinksAndImages()
  30891. }
  30892. }
  30893. if (isGecko) {
  30894. focusBody()
  30895. setGeckoEditingOptions()
  30896. showBrokenImageIcon()
  30897. blockCmdArrowNavigation()
  30898. }
  30899. }
  30900. var setup = function () {
  30901. removeBlockQuoteOnBackSpace()
  30902. emptyEditorWhenDeleting()
  30903. if (!Env.windowsPhone) {
  30904. normalizeSelection()
  30905. }
  30906. if (isWebKit) {
  30907. documentElementEditingFocus()
  30908. selectControlElements()
  30909. setDefaultBlockType()
  30910. blockFormSubmitInsideEditor()
  30911. disableBackspaceIntoATable()
  30912. removeAppleInterchangeBrs()
  30913. if (Env.iOS) {
  30914. restoreFocusOnKeyDown()
  30915. bodyHeight()
  30916. tapLinksAndImages()
  30917. } else {
  30918. selectAll()
  30919. }
  30920. }
  30921. if (Env.ie >= 11) {
  30922. bodyHeight()
  30923. disableBackspaceIntoATable()
  30924. }
  30925. if (Env.ie) {
  30926. selectAll()
  30927. disableAutoUrlDetect()
  30928. ieInternalDragAndDrop()
  30929. }
  30930. if (isGecko) {
  30931. removeHrOnBackspace()
  30932. focusBody()
  30933. removeStylesWhenDeletingAcrossBlockElements()
  30934. setGeckoEditingOptions()
  30935. addBrAfterLastLinks()
  30936. showBrokenImageIcon()
  30937. blockCmdArrowNavigation()
  30938. disableBackspaceIntoATable()
  30939. }
  30940. }
  30941. if (isRtc(editor)) {
  30942. setupRtc()
  30943. } else {
  30944. setup()
  30945. }
  30946. return {
  30947. refreshContentEditable: refreshContentEditable,
  30948. isHidden: isHidden,
  30949. }
  30950. }
  30951. var DOM$6 = DOMUtils.DOM
  30952. var appendStyle = function (editor, text) {
  30953. var body = SugarElement.fromDom(editor.getBody())
  30954. var container = getStyleContainer(getRootNode(body))
  30955. var style = SugarElement.fromTag('style')
  30956. set$1(style, 'type', 'text/css')
  30957. append$1(style, SugarElement.fromText(text))
  30958. append$1(container, style)
  30959. editor.on('remove', function () {
  30960. remove$7(style)
  30961. })
  30962. }
  30963. var getRootName = function (editor) {
  30964. return editor.inline
  30965. ? editor.getElement().nodeName.toLowerCase()
  30966. : undefined
  30967. }
  30968. var removeUndefined = function (obj) {
  30969. return filter$3(obj, function (v) {
  30970. return isUndefined(v) === false
  30971. })
  30972. }
  30973. var mkParserSettings = function (editor) {
  30974. var settings = editor.settings
  30975. var blobCache = editor.editorUpload.blobCache
  30976. return removeUndefined({
  30977. allow_conditional_comments: settings.allow_conditional_comments,
  30978. allow_html_data_urls: settings.allow_html_data_urls,
  30979. allow_svg_data_urls: settings.allow_svg_data_urls,
  30980. allow_html_in_named_anchor: settings.allow_html_in_named_anchor,
  30981. allow_script_urls: settings.allow_script_urls,
  30982. allow_unsafe_link_target: settings.allow_unsafe_link_target,
  30983. convert_fonts_to_spans: settings.convert_fonts_to_spans,
  30984. fix_list_elements: settings.fix_list_elements,
  30985. font_size_legacy_values: settings.font_size_legacy_values,
  30986. forced_root_block: settings.forced_root_block,
  30987. forced_root_block_attrs: settings.forced_root_block_attrs,
  30988. padd_empty_with_br: settings.padd_empty_with_br,
  30989. preserve_cdata: settings.preserve_cdata,
  30990. remove_trailing_brs: settings.remove_trailing_brs,
  30991. inline_styles: settings.inline_styles,
  30992. root_name: getRootName(editor),
  30993. validate: true,
  30994. blob_cache: blobCache,
  30995. document: editor.getDoc(),
  30996. images_dataimg_filter: settings.images_dataimg_filter,
  30997. })
  30998. }
  30999. var mkSerializerSettings = function (editor) {
  31000. var settings = editor.settings
  31001. return __assign(
  31002. __assign({}, mkParserSettings(editor)),
  31003. removeUndefined({
  31004. url_converter: settings.url_converter,
  31005. url_converter_scope: settings.url_converter_scope,
  31006. element_format: settings.element_format,
  31007. entities: settings.entities,
  31008. entity_encoding: settings.entity_encoding,
  31009. indent: settings.indent,
  31010. indent_after: settings.indent_after,
  31011. indent_before: settings.indent_before,
  31012. block_elements: settings.block_elements,
  31013. boolean_attributes: settings.boolean_attributes,
  31014. custom_elements: settings.custom_elements,
  31015. extended_valid_elements: settings.extended_valid_elements,
  31016. invalid_elements: settings.invalid_elements,
  31017. invalid_styles: settings.invalid_styles,
  31018. move_caret_before_on_enter_elements:
  31019. settings.move_caret_before_on_enter_elements,
  31020. non_empty_elements: settings.non_empty_elements,
  31021. schema: settings.schema,
  31022. self_closing_elements: settings.self_closing_elements,
  31023. short_ended_elements: settings.short_ended_elements,
  31024. special: settings.special,
  31025. text_block_elements: settings.text_block_elements,
  31026. text_inline_elements: settings.text_inline_elements,
  31027. valid_children: settings.valid_children,
  31028. valid_classes: settings.valid_classes,
  31029. valid_elements: settings.valid_elements,
  31030. valid_styles: settings.valid_styles,
  31031. verify_html: settings.verify_html,
  31032. whitespace_elements: settings.whitespace_elements,
  31033. })
  31034. )
  31035. }
  31036. var createParser = function (editor) {
  31037. var parser = DomParser(mkParserSettings(editor), editor.schema)
  31038. parser.addAttributeFilter(
  31039. 'src,href,style,tabindex',
  31040. function (nodes, name) {
  31041. var i = nodes.length,
  31042. node,
  31043. value
  31044. var dom = editor.dom
  31045. var internalName = 'data-mce-' + name
  31046. while (i--) {
  31047. node = nodes[i]
  31048. value = node.attr(name)
  31049. if (value && !node.attr(internalName)) {
  31050. if (value.indexOf('data:') === 0 || value.indexOf('blob:') === 0) {
  31051. continue
  31052. }
  31053. if (name === 'style') {
  31054. value = dom.serializeStyle(dom.parseStyle(value), node.name)
  31055. if (!value.length) {
  31056. value = null
  31057. }
  31058. node.attr(internalName, value)
  31059. node.attr(name, value)
  31060. } else if (name === 'tabindex') {
  31061. node.attr(internalName, value)
  31062. node.attr(name, null)
  31063. } else {
  31064. node.attr(internalName, editor.convertURL(value, name, node.name))
  31065. }
  31066. }
  31067. }
  31068. }
  31069. )
  31070. parser.addNodeFilter('script', function (nodes) {
  31071. var i = nodes.length
  31072. while (i--) {
  31073. var node = nodes[i]
  31074. var type = node.attr('type') || 'no/type'
  31075. if (type.indexOf('mce-') !== 0) {
  31076. node.attr('type', 'mce-' + type)
  31077. }
  31078. }
  31079. })
  31080. if (editor.settings.preserve_cdata) {
  31081. parser.addNodeFilter('#cdata', function (nodes) {
  31082. var i = nodes.length
  31083. while (i--) {
  31084. var node = nodes[i]
  31085. node.type = 8
  31086. node.name = '#comment'
  31087. node.value = '[CDATA[' + editor.dom.encode(node.value) + ']]'
  31088. }
  31089. })
  31090. }
  31091. parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function (nodes) {
  31092. var i = nodes.length
  31093. var nonEmptyElements = editor.schema.getNonEmptyElements()
  31094. while (i--) {
  31095. var node = nodes[i]
  31096. if (node.isEmpty(nonEmptyElements) && node.getAll('br').length === 0) {
  31097. node.append(new AstNode('br', 1)).shortEnded = true
  31098. }
  31099. }
  31100. })
  31101. return parser
  31102. }
  31103. var autoFocus = function (editor) {
  31104. if (editor.settings.auto_focus) {
  31105. Delay.setEditorTimeout(
  31106. editor,
  31107. function () {
  31108. var focusEditor
  31109. if (editor.settings.auto_focus === true) {
  31110. focusEditor = editor
  31111. } else {
  31112. focusEditor = editor.editorManager.get(editor.settings.auto_focus)
  31113. }
  31114. if (!focusEditor.destroyed) {
  31115. focusEditor.focus()
  31116. }
  31117. },
  31118. 100
  31119. )
  31120. }
  31121. }
  31122. var moveSelectionToFirstCaretPosition = function (editor) {
  31123. var root = editor.dom.getRoot()
  31124. if (
  31125. !editor.inline &&
  31126. (!hasAnyRanges(editor) || editor.selection.getStart(true) === root)
  31127. ) {
  31128. firstPositionIn(root).each(function (pos) {
  31129. var node = pos.getNode()
  31130. var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos
  31131. if (Env.browser.isIE()) {
  31132. storeNative(editor, caretPos.toRange())
  31133. } else {
  31134. editor.selection.setRng(caretPos.toRange())
  31135. }
  31136. })
  31137. }
  31138. }
  31139. var initEditor = function (editor) {
  31140. editor.bindPendingEventDelegates()
  31141. editor.initialized = true
  31142. fireInit(editor)
  31143. editor.focus(true)
  31144. moveSelectionToFirstCaretPosition(editor)
  31145. editor.nodeChanged({ initial: true })
  31146. editor.execCallback('init_instance_callback', editor)
  31147. autoFocus(editor)
  31148. }
  31149. var getStyleSheetLoader$1 = function (editor) {
  31150. return editor.inline
  31151. ? editor.ui.styleSheetLoader
  31152. : editor.dom.styleSheetLoader
  31153. }
  31154. var makeStylesheetLoadingPromises = function (editor, css, framedFonts) {
  31155. var promises = [
  31156. new promiseObj(function (resolve, reject) {
  31157. return getStyleSheetLoader$1(editor).loadAll(css, resolve, reject)
  31158. }),
  31159. ]
  31160. if (editor.inline) {
  31161. return promises
  31162. } else {
  31163. return promises.concat([
  31164. new promiseObj(function (resolve, reject) {
  31165. return editor.ui.styleSheetLoader.loadAll(
  31166. framedFonts,
  31167. resolve,
  31168. reject
  31169. )
  31170. }),
  31171. ])
  31172. }
  31173. }
  31174. var loadContentCss = function (editor) {
  31175. var styleSheetLoader = getStyleSheetLoader$1(editor)
  31176. var fontCss = getFontCss(editor)
  31177. var css = editor.contentCSS
  31178. var removeCss = function () {
  31179. styleSheetLoader.unloadAll(css)
  31180. if (!editor.inline) {
  31181. editor.ui.styleSheetLoader.unloadAll(fontCss)
  31182. }
  31183. }
  31184. var loaded = function () {
  31185. if (editor.removed) {
  31186. removeCss()
  31187. } else {
  31188. editor.on('remove', removeCss)
  31189. }
  31190. }
  31191. if (editor.contentStyles.length > 0) {
  31192. var contentCssText_1 = ''
  31193. Tools.each(editor.contentStyles, function (style) {
  31194. contentCssText_1 += style + '\r\n'
  31195. })
  31196. editor.dom.addStyle(contentCssText_1)
  31197. }
  31198. var allStylesheets = promiseObj
  31199. .all(makeStylesheetLoadingPromises(editor, css, fontCss))
  31200. .then(loaded)
  31201. .catch(loaded)
  31202. if (editor.settings.content_style) {
  31203. appendStyle(editor, editor.settings.content_style)
  31204. }
  31205. return allStylesheets
  31206. }
  31207. var preInit = function (editor) {
  31208. var settings = editor.settings,
  31209. doc = editor.getDoc(),
  31210. body = editor.getBody()
  31211. firePreInit(editor)
  31212. if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
  31213. doc.body.spellcheck = false
  31214. DOM$6.setAttrib(body, 'spellcheck', 'false')
  31215. }
  31216. editor.quirks = Quirks(editor)
  31217. firePostRender(editor)
  31218. var directionality = getDirectionality(editor)
  31219. if (directionality !== undefined) {
  31220. body.dir = directionality
  31221. }
  31222. if (settings.protect) {
  31223. editor.on('BeforeSetContent', function (e) {
  31224. Tools.each(settings.protect, function (pattern) {
  31225. e.content = e.content.replace(pattern, function (str) {
  31226. return '<!--mce:protected ' + escape(str) + '-->'
  31227. })
  31228. })
  31229. })
  31230. }
  31231. editor.on('SetContent', function () {
  31232. editor.addVisual(editor.getBody())
  31233. })
  31234. editor.on('compositionstart compositionend', function (e) {
  31235. editor.composing = e.type === 'compositionstart'
  31236. })
  31237. }
  31238. var loadInitialContent = function (editor) {
  31239. if (!isRtc(editor)) {
  31240. editor.load({
  31241. initial: true,
  31242. format: 'html',
  31243. })
  31244. }
  31245. editor.startContent = editor.getContent({ format: 'raw' })
  31246. }
  31247. var initEditorWithInitialContent = function (editor) {
  31248. if (editor.removed !== true) {
  31249. loadInitialContent(editor)
  31250. initEditor(editor)
  31251. }
  31252. }
  31253. var initContentBody = function (editor, skipWrite) {
  31254. var settings = editor.settings
  31255. var targetElm = editor.getElement()
  31256. var doc = editor.getDoc()
  31257. if (!settings.inline) {
  31258. editor.getElement().style.visibility = editor.orgVisibility
  31259. }
  31260. if (!skipWrite && !editor.inline) {
  31261. doc.open()
  31262. doc.write(editor.iframeHTML)
  31263. doc.close()
  31264. }
  31265. if (editor.inline) {
  31266. DOM$6.addClass(targetElm, 'mce-content-body')
  31267. editor.contentDocument = doc = document
  31268. editor.contentWindow = window
  31269. editor.bodyElement = targetElm
  31270. editor.contentAreaContainer = targetElm
  31271. }
  31272. var body = editor.getBody()
  31273. body.disabled = true
  31274. editor.readonly = !!settings.readonly
  31275. if (!editor.readonly) {
  31276. if (
  31277. editor.inline &&
  31278. DOM$6.getStyle(body, 'position', true) === 'static'
  31279. ) {
  31280. body.style.position = 'relative'
  31281. }
  31282. body.contentEditable = editor.getParam('content_editable_state', true)
  31283. }
  31284. body.disabled = false
  31285. editor.editorUpload = EditorUpload(editor)
  31286. editor.schema = Schema(settings)
  31287. editor.dom = DOMUtils(doc, {
  31288. keep_values: true,
  31289. url_converter: editor.convertURL,
  31290. url_converter_scope: editor,
  31291. hex_colors: settings.force_hex_style_colors,
  31292. update_styles: true,
  31293. root_element: editor.inline ? editor.getBody() : null,
  31294. collect: function () {
  31295. return editor.inline
  31296. },
  31297. schema: editor.schema,
  31298. contentCssCors: shouldUseContentCssCors(editor),
  31299. referrerPolicy: getReferrerPolicy(editor),
  31300. onSetAttrib: function (e) {
  31301. editor.fire('SetAttrib', e)
  31302. },
  31303. })
  31304. editor.parser = createParser(editor)
  31305. editor.serializer = DomSerializer(mkSerializerSettings(editor), editor)
  31306. editor.selection = EditorSelection(
  31307. editor.dom,
  31308. editor.getWin(),
  31309. editor.serializer,
  31310. editor
  31311. )
  31312. editor.annotator = Annotator(editor)
  31313. editor.formatter = Formatter(editor)
  31314. editor.undoManager = UndoManager(editor)
  31315. editor._nodeChangeDispatcher = new NodeChange(editor)
  31316. editor._selectionOverrides = SelectionOverrides(editor)
  31317. setup$e(editor)
  31318. setup$3(editor)
  31319. if (!isRtc(editor)) {
  31320. setup$2(editor)
  31321. }
  31322. var caret = setup$4(editor)
  31323. setup$f(editor, caret)
  31324. setup$d(editor)
  31325. setup$g(editor)
  31326. var setupRtcThunk = setup$i(editor)
  31327. preInit(editor)
  31328. setupRtcThunk.fold(
  31329. function () {
  31330. loadContentCss(editor).then(function () {
  31331. return initEditorWithInitialContent(editor)
  31332. })
  31333. },
  31334. function (setupRtc) {
  31335. editor.setProgressState(true)
  31336. loadContentCss(editor).then(function () {
  31337. setupRtc().then(
  31338. function (_rtcMode) {
  31339. editor.setProgressState(false)
  31340. initEditorWithInitialContent(editor)
  31341. },
  31342. function (err) {
  31343. editor.notificationManager.open({
  31344. type: 'error',
  31345. text: String(err),
  31346. })
  31347. initEditorWithInitialContent(editor)
  31348. }
  31349. )
  31350. })
  31351. }
  31352. )
  31353. }
  31354. var DOM$5 = DOMUtils.DOM
  31355. var relaxDomain = function (editor, ifr) {
  31356. if (document.domain !== window.location.hostname && Env.browser.isIE()) {
  31357. var bodyUuid = uuid('mce')
  31358. editor[bodyUuid] = function () {
  31359. initContentBody(editor)
  31360. }
  31361. var domainRelaxUrl =
  31362. 'javascript:(function(){' +
  31363. 'document.open();document.domain="' +
  31364. document.domain +
  31365. '";' +
  31366. 'var ed = window.parent.tinymce.get("' +
  31367. editor.id +
  31368. '");document.write(ed.iframeHTML);' +
  31369. 'document.close();ed.' +
  31370. bodyUuid +
  31371. '(true);})()'
  31372. DOM$5.setAttrib(ifr, 'src', domainRelaxUrl)
  31373. return true
  31374. }
  31375. return false
  31376. }
  31377. var createIframeElement = function (id, title, height, customAttrs) {
  31378. var iframe = SugarElement.fromTag('iframe')
  31379. setAll$1(iframe, customAttrs)
  31380. setAll$1(iframe, {
  31381. id: id + '_ifr',
  31382. frameBorder: '0',
  31383. allowTransparency: 'true',
  31384. title: title,
  31385. })
  31386. add$1(iframe, 'tox-edit-area__iframe')
  31387. return iframe
  31388. }
  31389. var getIframeHtml = function (editor) {
  31390. var iframeHTML = getDocType(editor) + '<html><head>'
  31391. if (getDocumentBaseUrl(editor) !== editor.documentBaseUrl) {
  31392. iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />'
  31393. }
  31394. iframeHTML +=
  31395. '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
  31396. var bodyId = getBodyId(editor)
  31397. var bodyClass = getBodyClass(editor)
  31398. var translatedAriaText = editor.translate(getIframeAriaText(editor))
  31399. if (getContentSecurityPolicy(editor)) {
  31400. iframeHTML +=
  31401. '<meta http-equiv="Content-Security-Policy" content="' +
  31402. getContentSecurityPolicy(editor) +
  31403. '" />'
  31404. }
  31405. iframeHTML +=
  31406. '</head>' +
  31407. ('<body id="' +
  31408. bodyId +
  31409. '" class="mce-content-body ' +
  31410. bodyClass +
  31411. '" data-id="' +
  31412. editor.id +
  31413. '" aria-label="' +
  31414. translatedAriaText +
  31415. '">') +
  31416. '<br>' +
  31417. '</body></html>'
  31418. return iframeHTML
  31419. }
  31420. var createIframe = function (editor, o) {
  31421. var iframeTitle = editor.translate('Rich Text Area')
  31422. var ifr = createIframeElement(
  31423. editor.id,
  31424. iframeTitle,
  31425. o.height,
  31426. getIframeAttrs(editor)
  31427. ).dom
  31428. ifr.onload = function () {
  31429. ifr.onload = null
  31430. editor.fire('load')
  31431. }
  31432. var isDomainRelaxed = relaxDomain(editor, ifr)
  31433. editor.contentAreaContainer = o.iframeContainer
  31434. editor.iframeElement = ifr
  31435. editor.iframeHTML = getIframeHtml(editor)
  31436. DOM$5.add(o.iframeContainer, ifr)
  31437. return isDomainRelaxed
  31438. }
  31439. var init$1 = function (editor, boxInfo) {
  31440. var isDomainRelaxed = createIframe(editor, boxInfo)
  31441. if (boxInfo.editorContainer) {
  31442. DOM$5.get(boxInfo.editorContainer).style.display = editor.orgDisplay
  31443. editor.hidden = DOM$5.isHidden(boxInfo.editorContainer)
  31444. }
  31445. editor.getElement().style.display = 'none'
  31446. DOM$5.setAttrib(editor.id, 'aria-hidden', 'true')
  31447. if (!isDomainRelaxed) {
  31448. initContentBody(editor)
  31449. }
  31450. }
  31451. var DOM$4 = DOMUtils.DOM
  31452. var initPlugin = function (editor, initializedPlugins, plugin) {
  31453. var Plugin = PluginManager.get(plugin)
  31454. var pluginUrl =
  31455. PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, '')
  31456. plugin = Tools.trim(plugin)
  31457. if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) {
  31458. Tools.each(PluginManager.dependencies(plugin), function (dep) {
  31459. initPlugin(editor, initializedPlugins, dep)
  31460. })
  31461. if (editor.plugins[plugin]) {
  31462. return
  31463. }
  31464. try {
  31465. var pluginInstance = new Plugin(editor, pluginUrl, editor.$)
  31466. editor.plugins[plugin] = pluginInstance
  31467. if (pluginInstance.init) {
  31468. pluginInstance.init(editor, pluginUrl)
  31469. initializedPlugins.push(plugin)
  31470. }
  31471. } catch (e) {
  31472. pluginInitError(editor, plugin, e)
  31473. }
  31474. }
  31475. }
  31476. var trimLegacyPrefix = function (name) {
  31477. return name.replace(/^\-/, '')
  31478. }
  31479. var initPlugins = function (editor) {
  31480. var initializedPlugins = []
  31481. Tools.each(getPlugins(editor).split(/[ ,]/), function (name) {
  31482. initPlugin(editor, initializedPlugins, trimLegacyPrefix(name))
  31483. })
  31484. }
  31485. var initIcons = function (editor) {
  31486. var iconPackName = Tools.trim(getIconPackName(editor))
  31487. var currentIcons = editor.ui.registry.getAll().icons
  31488. var loadIcons = __assign(
  31489. __assign({}, IconManager.get('default').icons),
  31490. IconManager.get(iconPackName).icons
  31491. )
  31492. each$j(loadIcons, function (svgData, icon) {
  31493. if (!has$2(currentIcons, icon)) {
  31494. editor.ui.registry.addIcon(icon, svgData)
  31495. }
  31496. })
  31497. }
  31498. var initTheme = function (editor) {
  31499. var theme = getTheme(editor)
  31500. if (isString$1(theme)) {
  31501. editor.settings.theme = trimLegacyPrefix(theme)
  31502. var Theme = ThemeManager.get(theme)
  31503. editor.theme = new Theme(editor, ThemeManager.urls[theme])
  31504. if (editor.theme.init) {
  31505. editor.theme.init(
  31506. editor,
  31507. ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ''),
  31508. editor.$
  31509. )
  31510. }
  31511. } else {
  31512. editor.theme = {}
  31513. }
  31514. }
  31515. var renderFromLoadedTheme = function (editor) {
  31516. return editor.theme.renderUI()
  31517. }
  31518. var renderFromThemeFunc = function (editor) {
  31519. var elm = editor.getElement()
  31520. var theme = getTheme(editor)
  31521. var info = theme(editor, elm)
  31522. if (info.editorContainer.nodeType) {
  31523. info.editorContainer.id = info.editorContainer.id || editor.id + '_parent'
  31524. }
  31525. if (info.iframeContainer && info.iframeContainer.nodeType) {
  31526. info.iframeContainer.id =
  31527. info.iframeContainer.id || editor.id + '_iframecontainer'
  31528. }
  31529. info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight
  31530. return info
  31531. }
  31532. var createThemeFalseResult = function (element) {
  31533. return {
  31534. editorContainer: element,
  31535. iframeContainer: element,
  31536. api: {},
  31537. }
  31538. }
  31539. var renderThemeFalseIframe = function (targetElement) {
  31540. var iframeContainer = DOM$4.create('div')
  31541. DOM$4.insertAfter(iframeContainer, targetElement)
  31542. return createThemeFalseResult(iframeContainer)
  31543. }
  31544. var renderThemeFalse = function (editor) {
  31545. var targetElement = editor.getElement()
  31546. return editor.inline
  31547. ? createThemeFalseResult(null)
  31548. : renderThemeFalseIframe(targetElement)
  31549. }
  31550. var renderThemeUi = function (editor) {
  31551. var elm = editor.getElement()
  31552. editor.orgDisplay = elm.style.display
  31553. if (isString$1(getTheme(editor))) {
  31554. return renderFromLoadedTheme(editor)
  31555. } else if (isFunction(getTheme(editor))) {
  31556. return renderFromThemeFunc(editor)
  31557. } else {
  31558. return renderThemeFalse(editor)
  31559. }
  31560. }
  31561. var augmentEditorUiApi = function (editor, api) {
  31562. var uiApiFacade = {
  31563. show: Optional.from(api.show).getOr(noop),
  31564. hide: Optional.from(api.hide).getOr(noop),
  31565. disable: Optional.from(api.disable).getOr(noop),
  31566. isDisabled: Optional.from(api.isDisabled).getOr(never),
  31567. enable: function () {
  31568. if (!editor.mode.isReadOnly()) {
  31569. Optional.from(api.enable).map(call)
  31570. }
  31571. },
  31572. }
  31573. editor.ui = __assign(__assign({}, editor.ui), uiApiFacade)
  31574. }
  31575. var init = function (editor) {
  31576. editor.fire('ScriptsLoaded')
  31577. initIcons(editor)
  31578. initTheme(editor)
  31579. initPlugins(editor)
  31580. var renderInfo = renderThemeUi(editor)
  31581. augmentEditorUiApi(editor, Optional.from(renderInfo.api).getOr({}))
  31582. var boxInfo = {
  31583. editorContainer: renderInfo.editorContainer,
  31584. iframeContainer: renderInfo.iframeContainer,
  31585. }
  31586. editor.editorContainer = boxInfo.editorContainer
  31587. ? boxInfo.editorContainer
  31588. : null
  31589. appendContentCssFromSettings(editor)
  31590. if (editor.inline) {
  31591. return initContentBody(editor)
  31592. } else {
  31593. return init$1(editor, boxInfo)
  31594. }
  31595. }
  31596. var DOM$3 = DOMUtils.DOM
  31597. var hasSkipLoadPrefix = function (name) {
  31598. return name.charAt(0) === '-'
  31599. }
  31600. var loadLanguage = function (scriptLoader, editor) {
  31601. var languageCode = getLanguageCode(editor)
  31602. var languageUrl = getLanguageUrl(editor)
  31603. if (I18n.hasCode(languageCode) === false && languageCode !== 'en') {
  31604. var url_1 =
  31605. languageUrl !== ''
  31606. ? languageUrl
  31607. : editor.editorManager.baseURL + '/langs/' + languageCode + '.js'
  31608. scriptLoader.add(url_1, noop, undefined, function () {
  31609. languageLoadError(editor, url_1, languageCode)
  31610. })
  31611. }
  31612. }
  31613. var loadTheme = function (scriptLoader, editor, suffix, callback) {
  31614. var theme = getTheme(editor)
  31615. if (isString$1(theme)) {
  31616. if (!hasSkipLoadPrefix(theme) && !has$2(ThemeManager.urls, theme)) {
  31617. var themeUrl = getThemeUrl(editor)
  31618. if (themeUrl) {
  31619. ThemeManager.load(theme, editor.documentBaseURI.toAbsolute(themeUrl))
  31620. } else {
  31621. ThemeManager.load(
  31622. theme,
  31623. 'themes/' + theme + '/theme' + suffix + '.js'
  31624. )
  31625. }
  31626. }
  31627. scriptLoader.loadQueue(function () {
  31628. ThemeManager.waitFor(theme, callback)
  31629. })
  31630. } else {
  31631. callback()
  31632. }
  31633. }
  31634. var getIconsUrlMetaFromUrl = function (editor) {
  31635. return Optional.from(getIconsUrl(editor))
  31636. .filter(function (url) {
  31637. return url.length > 0
  31638. })
  31639. .map(function (url) {
  31640. return {
  31641. url: url,
  31642. name: Optional.none(),
  31643. }
  31644. })
  31645. }
  31646. var getIconsUrlMetaFromName = function (editor, name, suffix) {
  31647. return Optional.from(name)
  31648. .filter(function (name) {
  31649. return name.length > 0 && !IconManager.has(name)
  31650. })
  31651. .map(function (name) {
  31652. return {
  31653. url:
  31654. editor.editorManager.baseURL +
  31655. '/icons/' +
  31656. name +
  31657. '/icons' +
  31658. suffix +
  31659. '.js',
  31660. name: Optional.some(name),
  31661. }
  31662. })
  31663. }
  31664. var loadIcons = function (scriptLoader, editor, suffix) {
  31665. var defaultIconsUrl = getIconsUrlMetaFromName(editor, 'default', suffix)
  31666. var customIconsUrl = getIconsUrlMetaFromUrl(editor).orThunk(function () {
  31667. return getIconsUrlMetaFromName(editor, getIconPackName(editor), '')
  31668. })
  31669. each$k(cat([defaultIconsUrl, customIconsUrl]), function (urlMeta) {
  31670. scriptLoader.add(urlMeta.url, noop, undefined, function () {
  31671. iconsLoadError(editor, urlMeta.url, urlMeta.name.getOrUndefined())
  31672. })
  31673. })
  31674. }
  31675. var loadPlugins = function (editor, suffix) {
  31676. Tools.each(getExternalPlugins$1(editor), function (url, name) {
  31677. PluginManager.load(name, url, noop, undefined, function () {
  31678. pluginLoadError(editor, url, name)
  31679. })
  31680. editor.settings.plugins += ' ' + name
  31681. })
  31682. Tools.each(getPlugins(editor).split(/[ ,]/), function (plugin) {
  31683. plugin = Tools.trim(plugin)
  31684. if (plugin && !PluginManager.urls[plugin]) {
  31685. if (hasSkipLoadPrefix(plugin)) {
  31686. plugin = plugin.substr(1, plugin.length)
  31687. var dependencies = PluginManager.dependencies(plugin)
  31688. Tools.each(dependencies, function (depPlugin) {
  31689. var defaultSettings = {
  31690. prefix: 'plugins/',
  31691. resource: depPlugin,
  31692. suffix: '/plugin' + suffix + '.js',
  31693. }
  31694. var dep = PluginManager.createUrl(defaultSettings, depPlugin)
  31695. PluginManager.load(dep.resource, dep, noop, undefined, function () {
  31696. pluginLoadError(
  31697. editor,
  31698. dep.prefix + dep.resource + dep.suffix,
  31699. dep.resource
  31700. )
  31701. })
  31702. })
  31703. } else {
  31704. var url_2 = {
  31705. prefix: 'plugins/',
  31706. resource: plugin,
  31707. suffix: '/plugin' + suffix + '.js',
  31708. }
  31709. PluginManager.load(plugin, url_2, noop, undefined, function () {
  31710. pluginLoadError(
  31711. editor,
  31712. url_2.prefix + url_2.resource + url_2.suffix,
  31713. plugin
  31714. )
  31715. })
  31716. }
  31717. }
  31718. })
  31719. }
  31720. var loadScripts = function (editor, suffix) {
  31721. var scriptLoader = ScriptLoader.ScriptLoader
  31722. loadTheme(scriptLoader, editor, suffix, function () {
  31723. loadLanguage(scriptLoader, editor)
  31724. loadIcons(scriptLoader, editor, suffix)
  31725. loadPlugins(editor, suffix)
  31726. scriptLoader.loadQueue(
  31727. function () {
  31728. if (!editor.removed) {
  31729. init(editor)
  31730. }
  31731. },
  31732. editor,
  31733. function () {
  31734. if (!editor.removed) {
  31735. init(editor)
  31736. }
  31737. }
  31738. )
  31739. })
  31740. }
  31741. var getStyleSheetLoader = function (element, editor) {
  31742. return instance.forElement(element, {
  31743. contentCssCors: hasContentCssCors(editor),
  31744. referrerPolicy: getReferrerPolicy(editor),
  31745. })
  31746. }
  31747. var render = function (editor) {
  31748. var id = editor.id
  31749. I18n.setCode(getLanguageCode(editor))
  31750. var readyHandler = function () {
  31751. DOM$3.unbind(window, 'ready', readyHandler)
  31752. editor.render()
  31753. }
  31754. if (!EventUtils.Event.domLoaded) {
  31755. DOM$3.bind(window, 'ready', readyHandler)
  31756. return
  31757. }
  31758. if (!editor.getElement()) {
  31759. return
  31760. }
  31761. if (!Env.contentEditable) {
  31762. return
  31763. }
  31764. var element = SugarElement.fromDom(editor.getElement())
  31765. var snapshot = clone$3(element)
  31766. editor.on('remove', function () {
  31767. eachr(element.dom.attributes, function (attr) {
  31768. return remove$6(element, attr.name)
  31769. })
  31770. setAll$1(element, snapshot)
  31771. })
  31772. editor.ui.styleSheetLoader = getStyleSheetLoader(element, editor)
  31773. if (!isInline(editor)) {
  31774. editor.orgVisibility = editor.getElement().style.visibility
  31775. editor.getElement().style.visibility = 'hidden'
  31776. } else {
  31777. editor.inline = true
  31778. }
  31779. var form = editor.getElement().form || DOM$3.getParent(id, 'form')
  31780. if (form) {
  31781. editor.formElement = form
  31782. if (hasHiddenInput(editor) && !isTextareaOrInput(editor.getElement())) {
  31783. DOM$3.insertAfter(
  31784. DOM$3.create('input', {
  31785. type: 'hidden',
  31786. name: id,
  31787. }),
  31788. id
  31789. )
  31790. editor.hasHiddenInput = true
  31791. }
  31792. editor.formEventDelegate = function (e) {
  31793. editor.fire(e.type, e)
  31794. }
  31795. DOM$3.bind(form, 'submit reset', editor.formEventDelegate)
  31796. editor.on('reset', function () {
  31797. editor.resetContent()
  31798. })
  31799. if (
  31800. shouldPatchSubmit(editor) &&
  31801. !form.submit.nodeType &&
  31802. !form.submit.length &&
  31803. !form._mceOldSubmit
  31804. ) {
  31805. form._mceOldSubmit = form.submit
  31806. form.submit = function () {
  31807. editor.editorManager.triggerSave()
  31808. editor.setDirty(false)
  31809. return form._mceOldSubmit(form)
  31810. }
  31811. }
  31812. }
  31813. editor.windowManager = WindowManager(editor)
  31814. editor.notificationManager = NotificationManager(editor)
  31815. if (isEncodingXml(editor)) {
  31816. editor.on('GetContent', function (e) {
  31817. if (e.save) {
  31818. e.content = DOM$3.encode(e.content)
  31819. }
  31820. })
  31821. }
  31822. if (shouldAddFormSubmitTrigger(editor)) {
  31823. editor.on('submit', function () {
  31824. if (editor.initialized) {
  31825. editor.save()
  31826. }
  31827. })
  31828. }
  31829. if (shouldAddUnloadTrigger(editor)) {
  31830. editor._beforeUnload = function () {
  31831. if (editor.initialized && !editor.destroyed && !editor.isHidden()) {
  31832. editor.save({
  31833. format: 'raw',
  31834. no_events: true,
  31835. set_dirty: false,
  31836. })
  31837. }
  31838. }
  31839. editor.editorManager.on('BeforeUnload', editor._beforeUnload)
  31840. }
  31841. editor.editorManager.add(editor)
  31842. loadScripts(editor, editor.suffix)
  31843. }
  31844. var addVisual = function (editor, elm) {
  31845. return addVisual$1(editor, elm)
  31846. }
  31847. var legacyPropNames = {
  31848. 'font-size': 'size',
  31849. 'font-family': 'face',
  31850. }
  31851. var getSpecifiedFontProp = function (propName, rootElm, elm) {
  31852. var getProperty = function (elm) {
  31853. return getRaw(elm, propName).orThunk(function () {
  31854. if (name(elm) === 'font') {
  31855. return get$9(legacyPropNames, propName).bind(function (
  31856. legacyPropName
  31857. ) {
  31858. return getOpt(elm, legacyPropName)
  31859. })
  31860. } else {
  31861. return Optional.none()
  31862. }
  31863. })
  31864. }
  31865. var isRoot = function (elm) {
  31866. return eq(SugarElement.fromDom(rootElm), elm)
  31867. }
  31868. return closest$1(
  31869. SugarElement.fromDom(elm),
  31870. function (elm) {
  31871. return getProperty(elm)
  31872. },
  31873. isRoot
  31874. )
  31875. }
  31876. var normalizeFontFamily = function (fontFamily) {
  31877. return fontFamily.replace(/[\'\"\\]/g, '').replace(/,\s+/g, ',')
  31878. }
  31879. var getComputedFontProp = function (propName, elm) {
  31880. return Optional.from(DOMUtils.DOM.getStyle(elm, propName, true))
  31881. }
  31882. var getFontProp = function (propName) {
  31883. return function (rootElm, elm) {
  31884. return Optional.from(elm)
  31885. .map(SugarElement.fromDom)
  31886. .filter(isElement$6)
  31887. .bind(function (element) {
  31888. return getSpecifiedFontProp(propName, rootElm, element.dom).or(
  31889. getComputedFontProp(propName, element.dom)
  31890. )
  31891. })
  31892. .getOr('')
  31893. }
  31894. }
  31895. var getFontSize = getFontProp('font-size')
  31896. var getFontFamily = compose(normalizeFontFamily, getFontProp('font-family'))
  31897. var findFirstCaretElement = function (editor) {
  31898. return firstPositionIn(editor.getBody()).map(function (caret) {
  31899. var container = caret.container()
  31900. return isText$7(container) ? container.parentNode : container
  31901. })
  31902. }
  31903. var getCaretElement = function (editor) {
  31904. return Optional.from(editor.selection.getRng()).bind(function (rng) {
  31905. var root = editor.getBody()
  31906. var atStartOfNode = rng.startContainer === root && rng.startOffset === 0
  31907. return atStartOfNode
  31908. ? Optional.none()
  31909. : Optional.from(editor.selection.getStart(true))
  31910. })
  31911. }
  31912. var bindRange = function (editor, binder) {
  31913. return getCaretElement(editor)
  31914. .orThunk(curry(findFirstCaretElement, editor))
  31915. .map(SugarElement.fromDom)
  31916. .filter(isElement$6)
  31917. .bind(binder)
  31918. }
  31919. var mapRange = function (editor, mapper) {
  31920. return bindRange(editor, compose1(Optional.some, mapper))
  31921. }
  31922. var fromFontSizeNumber = function (editor, value) {
  31923. if (/^[0-9.]+$/.test(value)) {
  31924. var fontSizeNumber = parseInt(value, 10)
  31925. if (fontSizeNumber >= 1 && fontSizeNumber <= 7) {
  31926. var fontSizes = getFontStyleValues(editor)
  31927. var fontClasses = getFontSizeClasses(editor)
  31928. if (fontClasses) {
  31929. return fontClasses[fontSizeNumber - 1] || value
  31930. } else {
  31931. return fontSizes[fontSizeNumber - 1] || value
  31932. }
  31933. } else {
  31934. return value
  31935. }
  31936. } else {
  31937. return value
  31938. }
  31939. }
  31940. var normalizeFontNames = function (font) {
  31941. var fonts = font.split(/\s*,\s*/)
  31942. return map$3(fonts, function (font) {
  31943. if (
  31944. font.indexOf(' ') !== -1 &&
  31945. !(startsWith(font, '"') || startsWith(font, "'"))
  31946. ) {
  31947. return "'" + font + "'"
  31948. } else {
  31949. return font
  31950. }
  31951. }).join(',')
  31952. }
  31953. var fontNameAction = function (editor, value) {
  31954. var font = fromFontSizeNumber(editor, value)
  31955. editor.formatter.toggle('fontname', { value: normalizeFontNames(font) })
  31956. editor.nodeChanged()
  31957. }
  31958. var fontNameQuery = function (editor) {
  31959. return mapRange(editor, function (elm) {
  31960. return getFontFamily(editor.getBody(), elm.dom)
  31961. }).getOr('')
  31962. }
  31963. var fontSizeAction = function (editor, value) {
  31964. editor.formatter.toggle('fontsize', {
  31965. value: fromFontSizeNumber(editor, value),
  31966. })
  31967. editor.nodeChanged()
  31968. }
  31969. var fontSizeQuery = function (editor) {
  31970. return mapRange(editor, function (elm) {
  31971. return getFontSize(editor.getBody(), elm.dom)
  31972. }).getOr('')
  31973. }
  31974. var lineHeightQuery = function (editor) {
  31975. return mapRange(editor, function (elm) {
  31976. var root = SugarElement.fromDom(editor.getBody())
  31977. var specifiedStyle = closest$1(
  31978. elm,
  31979. function (elm) {
  31980. return getRaw(elm, 'line-height')
  31981. },
  31982. curry(eq, root)
  31983. )
  31984. var computedStyle = function () {
  31985. var lineHeight = parseFloat(get$5(elm, 'line-height'))
  31986. var fontSize = parseFloat(get$5(elm, 'font-size'))
  31987. return String(lineHeight / fontSize)
  31988. }
  31989. return specifiedStyle.getOrThunk(computedStyle)
  31990. }).getOr('')
  31991. }
  31992. var lineHeightAction = function (editor, lineHeight) {
  31993. editor.formatter.toggle('lineheight', { value: String(lineHeight) })
  31994. editor.nodeChanged()
  31995. }
  31996. var processValue = function (value) {
  31997. if (typeof value !== 'string') {
  31998. var details = Tools.extend(
  31999. {
  32000. paste: value.paste,
  32001. data: { paste: value.paste },
  32002. },
  32003. value
  32004. )
  32005. return {
  32006. content: value.content,
  32007. details: details,
  32008. }
  32009. }
  32010. return {
  32011. content: value,
  32012. details: {},
  32013. }
  32014. }
  32015. var insertAtCaret = function (editor, value) {
  32016. var result = processValue(value)
  32017. insertContent(editor, result.content, result.details)
  32018. }
  32019. var each$4 = Tools.each
  32020. var map = Tools.map,
  32021. inArray = Tools.inArray
  32022. var EditorCommands = (function () {
  32023. function EditorCommands(editor) {
  32024. this.commands = {
  32025. state: {},
  32026. exec: {},
  32027. value: {},
  32028. }
  32029. this.editor = editor
  32030. this.setupCommands(editor)
  32031. }
  32032. EditorCommands.prototype.execCommand = function (command, ui, value, args) {
  32033. var func,
  32034. state = false
  32035. var self = this
  32036. if (self.editor.removed) {
  32037. return
  32038. }
  32039. if (command.toLowerCase() !== 'mcefocus') {
  32040. if (
  32041. !/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(
  32042. command
  32043. ) &&
  32044. (!args || !args.skip_focus)
  32045. ) {
  32046. self.editor.focus()
  32047. } else {
  32048. restore(self.editor)
  32049. }
  32050. }
  32051. args = self.editor.fire('BeforeExecCommand', {
  32052. command: command,
  32053. ui: ui,
  32054. value: value,
  32055. })
  32056. if (args.isDefaultPrevented()) {
  32057. return false
  32058. }
  32059. var customCommand = command.toLowerCase()
  32060. if ((func = self.commands.exec[customCommand])) {
  32061. func(customCommand, ui, value)
  32062. self.editor.fire('ExecCommand', {
  32063. command: command,
  32064. ui: ui,
  32065. value: value,
  32066. })
  32067. return true
  32068. }
  32069. each$4(this.editor.plugins, function (p) {
  32070. if (p.execCommand && p.execCommand(command, ui, value)) {
  32071. self.editor.fire('ExecCommand', {
  32072. command: command,
  32073. ui: ui,
  32074. value: value,
  32075. })
  32076. state = true
  32077. return false
  32078. }
  32079. })
  32080. if (state) {
  32081. return state
  32082. }
  32083. if (
  32084. self.editor.theme &&
  32085. self.editor.theme.execCommand &&
  32086. self.editor.theme.execCommand(command, ui, value)
  32087. ) {
  32088. self.editor.fire('ExecCommand', {
  32089. command: command,
  32090. ui: ui,
  32091. value: value,
  32092. })
  32093. return true
  32094. }
  32095. try {
  32096. state = self.editor.getDoc().execCommand(command, ui, value)
  32097. } catch (ex) {}
  32098. if (state) {
  32099. self.editor.fire('ExecCommand', {
  32100. command: command,
  32101. ui: ui,
  32102. value: value,
  32103. })
  32104. return true
  32105. }
  32106. return false
  32107. }
  32108. EditorCommands.prototype.queryCommandState = function (command) {
  32109. var func
  32110. if (this.editor.quirks.isHidden() || this.editor.removed) {
  32111. return
  32112. }
  32113. command = command.toLowerCase()
  32114. if ((func = this.commands.state[command])) {
  32115. return func(command)
  32116. }
  32117. try {
  32118. return this.editor.getDoc().queryCommandState(command)
  32119. } catch (ex) {}
  32120. return false
  32121. }
  32122. EditorCommands.prototype.queryCommandValue = function (command) {
  32123. var func
  32124. if (this.editor.quirks.isHidden() || this.editor.removed) {
  32125. return
  32126. }
  32127. command = command.toLowerCase()
  32128. if ((func = this.commands.value[command])) {
  32129. return func(command)
  32130. }
  32131. try {
  32132. return this.editor.getDoc().queryCommandValue(command)
  32133. } catch (ex) {}
  32134. }
  32135. EditorCommands.prototype.addCommands = function (commandList, type) {
  32136. if (type === void 0) {
  32137. type = 'exec'
  32138. }
  32139. var self = this
  32140. each$4(commandList, function (callback, command) {
  32141. each$4(command.toLowerCase().split(','), function (command) {
  32142. self.commands[type][command] = callback
  32143. })
  32144. })
  32145. }
  32146. EditorCommands.prototype.addCommand = function (command, callback, scope) {
  32147. var _this = this
  32148. command = command.toLowerCase()
  32149. this.commands.exec[command] = function (command, ui, value, args) {
  32150. return callback.call(scope || _this.editor, ui, value, args)
  32151. }
  32152. }
  32153. EditorCommands.prototype.queryCommandSupported = function (command) {
  32154. command = command.toLowerCase()
  32155. if (this.commands.exec[command]) {
  32156. return true
  32157. }
  32158. try {
  32159. return this.editor.getDoc().queryCommandSupported(command)
  32160. } catch (ex) {}
  32161. return false
  32162. }
  32163. EditorCommands.prototype.addQueryStateHandler = function (
  32164. command,
  32165. callback,
  32166. scope
  32167. ) {
  32168. var _this = this
  32169. command = command.toLowerCase()
  32170. this.commands.state[command] = function () {
  32171. return callback.call(scope || _this.editor)
  32172. }
  32173. }
  32174. EditorCommands.prototype.addQueryValueHandler = function (
  32175. command,
  32176. callback,
  32177. scope
  32178. ) {
  32179. var _this = this
  32180. command = command.toLowerCase()
  32181. this.commands.value[command] = function () {
  32182. return callback.call(scope || _this.editor)
  32183. }
  32184. }
  32185. EditorCommands.prototype.hasCustomCommand = function (command) {
  32186. command = command.toLowerCase()
  32187. return !!this.commands.exec[command]
  32188. }
  32189. EditorCommands.prototype.execNativeCommand = function (command, ui, value) {
  32190. if (ui === undefined) {
  32191. ui = false
  32192. }
  32193. if (value === undefined) {
  32194. value = null
  32195. }
  32196. return this.editor.getDoc().execCommand(command, ui, value)
  32197. }
  32198. EditorCommands.prototype.isFormatMatch = function (name) {
  32199. return this.editor.formatter.match(name)
  32200. }
  32201. EditorCommands.prototype.toggleFormat = function (name, value) {
  32202. this.editor.formatter.toggle(name, value)
  32203. this.editor.nodeChanged()
  32204. }
  32205. EditorCommands.prototype.storeSelection = function (type) {
  32206. this.selectionBookmark = this.editor.selection.getBookmark(type)
  32207. }
  32208. EditorCommands.prototype.restoreSelection = function () {
  32209. this.editor.selection.moveToBookmark(this.selectionBookmark)
  32210. }
  32211. EditorCommands.prototype.setupCommands = function (editor) {
  32212. var self = this
  32213. this.addCommands({
  32214. 'mceResetDesignMode,mceBeginUndoLevel': noop,
  32215. 'mceEndUndoLevel,mceAddUndoLevel': function () {
  32216. editor.undoManager.add()
  32217. },
  32218. mceFocus: function (_command, _ui, value) {
  32219. focus(editor, value)
  32220. },
  32221. 'Cut,Copy,Paste': function (command) {
  32222. var doc = editor.getDoc()
  32223. var failed
  32224. try {
  32225. self.execNativeCommand(command)
  32226. } catch (ex) {
  32227. failed = true
  32228. }
  32229. if (command === 'paste' && !doc.queryCommandEnabled(command)) {
  32230. failed = true
  32231. }
  32232. if (failed || !doc.queryCommandSupported(command)) {
  32233. var msg = editor.translate(
  32234. "Your browser doesn't support direct access to the clipboard. " +
  32235. 'Please use the Ctrl+X/C/V keyboard shortcuts instead.'
  32236. )
  32237. if (Env.mac) {
  32238. msg = msg.replace(/Ctrl\+/g, '\u2318+')
  32239. }
  32240. editor.notificationManager.open({
  32241. text: msg,
  32242. type: 'error',
  32243. })
  32244. }
  32245. },
  32246. unlink: function () {
  32247. if (editor.selection.isCollapsed()) {
  32248. var elm = editor.dom.getParent(editor.selection.getStart(), 'a')
  32249. if (elm) {
  32250. editor.dom.remove(elm, true)
  32251. }
  32252. return
  32253. }
  32254. editor.formatter.remove('link')
  32255. },
  32256. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone':
  32257. function (command) {
  32258. var align = command.substring(7)
  32259. if (align === 'full') {
  32260. align = 'justify'
  32261. }
  32262. each$4('left,center,right,justify'.split(','), function (name) {
  32263. if (align !== name) {
  32264. editor.formatter.remove('align' + name)
  32265. }
  32266. })
  32267. if (align !== 'none') {
  32268. self.toggleFormat('align' + align)
  32269. }
  32270. },
  32271. 'InsertUnorderedList,InsertOrderedList': function (command) {
  32272. var listParent
  32273. self.execNativeCommand(command)
  32274. var listElm = editor.dom.getParent(
  32275. editor.selection.getNode(),
  32276. 'ol,ul'
  32277. )
  32278. if (listElm) {
  32279. listParent = listElm.parentNode
  32280. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  32281. self.storeSelection()
  32282. editor.dom.split(listParent, listElm)
  32283. self.restoreSelection()
  32284. }
  32285. }
  32286. },
  32287. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (
  32288. command
  32289. ) {
  32290. self.toggleFormat(command)
  32291. },
  32292. 'ForeColor,HiliteColor': function (command, ui, value) {
  32293. self.toggleFormat(command, { value: value })
  32294. },
  32295. FontName: function (command, ui, value) {
  32296. fontNameAction(editor, value)
  32297. },
  32298. FontSize: function (command, ui, value) {
  32299. fontSizeAction(editor, value)
  32300. },
  32301. LineHeight: function (command, ui, value) {
  32302. lineHeightAction(editor, value)
  32303. },
  32304. Lang: function (command, ui, lang) {
  32305. self.toggleFormat(command, {
  32306. value: lang.code,
  32307. customValue: lang.customCode,
  32308. })
  32309. },
  32310. RemoveFormat: function (command) {
  32311. editor.formatter.remove(command)
  32312. },
  32313. mceBlockQuote: function () {
  32314. self.toggleFormat('blockquote')
  32315. },
  32316. FormatBlock: function (command, ui, value) {
  32317. return self.toggleFormat(value || 'p')
  32318. },
  32319. mceCleanup: function () {
  32320. var bookmark = editor.selection.getBookmark()
  32321. editor.setContent(editor.getContent())
  32322. editor.selection.moveToBookmark(bookmark)
  32323. },
  32324. mceRemoveNode: function (command, ui, value) {
  32325. var node = value || editor.selection.getNode()
  32326. if (node !== editor.getBody()) {
  32327. self.storeSelection()
  32328. editor.dom.remove(node, true)
  32329. self.restoreSelection()
  32330. }
  32331. },
  32332. mceSelectNodeDepth: function (command, ui, value) {
  32333. var counter = 0
  32334. editor.dom.getParent(
  32335. editor.selection.getNode(),
  32336. function (node) {
  32337. if (node.nodeType === 1 && counter++ === value) {
  32338. editor.selection.select(node)
  32339. return false
  32340. }
  32341. },
  32342. editor.getBody()
  32343. )
  32344. },
  32345. mceSelectNode: function (command, ui, value) {
  32346. editor.selection.select(value)
  32347. },
  32348. mceInsertContent: function (command, ui, value) {
  32349. insertAtCaret(editor, value)
  32350. },
  32351. mceInsertRawHTML: function (command, ui, value) {
  32352. editor.selection.setContent('tiny_mce_marker')
  32353. var content = editor.getContent()
  32354. editor.setContent(
  32355. content.replace(/tiny_mce_marker/g, function () {
  32356. return value
  32357. })
  32358. )
  32359. },
  32360. mceInsertNewLine: function (command, ui, value) {
  32361. insert(editor, value)
  32362. },
  32363. mceToggleFormat: function (command, ui, value) {
  32364. self.toggleFormat(value)
  32365. },
  32366. mceSetContent: function (command, ui, value) {
  32367. editor.setContent(value)
  32368. },
  32369. 'Indent,Outdent': function (command) {
  32370. handle(editor, command)
  32371. },
  32372. mceRepaint: noop,
  32373. InsertHorizontalRule: function () {
  32374. editor.execCommand('mceInsertContent', false, '<hr />')
  32375. },
  32376. mceToggleVisualAid: function () {
  32377. editor.hasVisual = !editor.hasVisual
  32378. editor.addVisual()
  32379. },
  32380. mceReplaceContent: function (command, ui, value) {
  32381. editor.execCommand(
  32382. 'mceInsertContent',
  32383. false,
  32384. value.replace(
  32385. /\{\$selection\}/g,
  32386. editor.selection.getContent({ format: 'text' })
  32387. )
  32388. )
  32389. },
  32390. mceInsertLink: function (command, ui, value) {
  32391. if (typeof value === 'string') {
  32392. value = { href: value }
  32393. }
  32394. var anchor = editor.dom.getParent(editor.selection.getNode(), 'a')
  32395. value.href = value.href.replace(/ /g, '%20')
  32396. if (!anchor || !value.href) {
  32397. editor.formatter.remove('link')
  32398. }
  32399. if (value.href) {
  32400. editor.formatter.apply('link', value, anchor)
  32401. }
  32402. },
  32403. selectAll: function () {
  32404. var editingHost = editor.dom.getParent(
  32405. editor.selection.getStart(),
  32406. isContentEditableTrue$4
  32407. )
  32408. if (editingHost) {
  32409. var rng = editor.dom.createRng()
  32410. rng.selectNodeContents(editingHost)
  32411. editor.selection.setRng(rng)
  32412. }
  32413. },
  32414. mceNewDocument: function () {
  32415. editor.setContent('')
  32416. },
  32417. InsertLineBreak: function (command, ui, value) {
  32418. insert$1(editor, value)
  32419. return true
  32420. },
  32421. })
  32422. var alignStates = function (name) {
  32423. return function () {
  32424. var selection = editor.selection
  32425. var nodes = selection.isCollapsed()
  32426. ? [editor.dom.getParent(selection.getNode(), editor.dom.isBlock)]
  32427. : selection.getSelectedBlocks()
  32428. var matches = map(nodes, function (node) {
  32429. return !!editor.formatter.matchNode(node, name)
  32430. })
  32431. return inArray(matches, true) !== -1
  32432. }
  32433. }
  32434. self.addCommands(
  32435. {
  32436. JustifyLeft: alignStates('alignleft'),
  32437. JustifyCenter: alignStates('aligncenter'),
  32438. JustifyRight: alignStates('alignright'),
  32439. JustifyFull: alignStates('alignjustify'),
  32440. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript':
  32441. function (command) {
  32442. return self.isFormatMatch(command)
  32443. },
  32444. mceBlockQuote: function () {
  32445. return self.isFormatMatch('blockquote')
  32446. },
  32447. Outdent: function () {
  32448. return canOutdent(editor)
  32449. },
  32450. 'InsertUnorderedList,InsertOrderedList': function (command) {
  32451. var list = editor.dom.getParent(editor.selection.getNode(), 'ul,ol')
  32452. return (
  32453. list &&
  32454. ((command === 'insertunorderedlist' && list.tagName === 'UL') ||
  32455. (command === 'insertorderedlist' && list.tagName === 'OL'))
  32456. )
  32457. },
  32458. },
  32459. 'state'
  32460. )
  32461. self.addCommands({
  32462. Undo: function () {
  32463. editor.undoManager.undo()
  32464. },
  32465. Redo: function () {
  32466. editor.undoManager.redo()
  32467. },
  32468. })
  32469. self.addQueryValueHandler(
  32470. 'FontName',
  32471. function () {
  32472. return fontNameQuery(editor)
  32473. },
  32474. this
  32475. )
  32476. self.addQueryValueHandler(
  32477. 'FontSize',
  32478. function () {
  32479. return fontSizeQuery(editor)
  32480. },
  32481. this
  32482. )
  32483. self.addQueryValueHandler(
  32484. 'LineHeight',
  32485. function () {
  32486. return lineHeightQuery(editor)
  32487. },
  32488. this
  32489. )
  32490. }
  32491. return EditorCommands
  32492. })()
  32493. var internalContentEditableAttr = 'data-mce-contenteditable'
  32494. var toggleClass = function (elm, cls, state) {
  32495. if (has(elm, cls) && state === false) {
  32496. remove$3(elm, cls)
  32497. } else if (state) {
  32498. add$1(elm, cls)
  32499. }
  32500. }
  32501. var setEditorCommandState = function (editor, cmd, state) {
  32502. try {
  32503. editor.getDoc().execCommand(cmd, false, String(state))
  32504. } catch (ex) {}
  32505. }
  32506. var setContentEditable = function (elm, state) {
  32507. elm.dom.contentEditable = state ? 'true' : 'false'
  32508. }
  32509. var switchOffContentEditableTrue = function (elm) {
  32510. each$k(descendants(elm, '*[contenteditable="true"]'), function (elm) {
  32511. set$1(elm, internalContentEditableAttr, 'true')
  32512. setContentEditable(elm, false)
  32513. })
  32514. }
  32515. var switchOnContentEditableTrue = function (elm) {
  32516. each$k(
  32517. descendants(elm, '*[' + internalContentEditableAttr + '="true"]'),
  32518. function (elm) {
  32519. remove$6(elm, internalContentEditableAttr)
  32520. setContentEditable(elm, true)
  32521. }
  32522. )
  32523. }
  32524. var removeFakeSelection = function (editor) {
  32525. Optional.from(editor.selection.getNode()).each(function (elm) {
  32526. elm.removeAttribute('data-mce-selected')
  32527. })
  32528. }
  32529. var restoreFakeSelection = function (editor) {
  32530. editor.selection.setRng(editor.selection.getRng())
  32531. }
  32532. var toggleReadOnly = function (editor, state) {
  32533. var body = SugarElement.fromDom(editor.getBody())
  32534. toggleClass(body, 'mce-content-readonly', state)
  32535. if (state) {
  32536. editor.selection.controlSelection.hideResizeRect()
  32537. editor._selectionOverrides.hideFakeCaret()
  32538. removeFakeSelection(editor)
  32539. editor.readonly = true
  32540. setContentEditable(body, false)
  32541. switchOffContentEditableTrue(body)
  32542. } else {
  32543. editor.readonly = false
  32544. setContentEditable(body, true)
  32545. switchOnContentEditableTrue(body)
  32546. setEditorCommandState(editor, 'StyleWithCSS', false)
  32547. setEditorCommandState(editor, 'enableInlineTableEditing', false)
  32548. setEditorCommandState(editor, 'enableObjectResizing', false)
  32549. if (hasEditorOrUiFocus(editor)) {
  32550. editor.focus()
  32551. }
  32552. restoreFakeSelection(editor)
  32553. editor.nodeChanged()
  32554. }
  32555. }
  32556. var isReadOnly = function (editor) {
  32557. return editor.readonly
  32558. }
  32559. var registerFilters = function (editor) {
  32560. editor.parser.addAttributeFilter('contenteditable', function (nodes) {
  32561. if (isReadOnly(editor)) {
  32562. each$k(nodes, function (node) {
  32563. node.attr(internalContentEditableAttr, node.attr('contenteditable'))
  32564. node.attr('contenteditable', 'false')
  32565. })
  32566. }
  32567. })
  32568. editor.serializer.addAttributeFilter(
  32569. internalContentEditableAttr,
  32570. function (nodes) {
  32571. if (isReadOnly(editor)) {
  32572. each$k(nodes, function (node) {
  32573. node.attr('contenteditable', node.attr(internalContentEditableAttr))
  32574. })
  32575. }
  32576. }
  32577. )
  32578. editor.serializer.addTempAttr(internalContentEditableAttr)
  32579. }
  32580. var registerReadOnlyContentFilters = function (editor) {
  32581. if (editor.serializer) {
  32582. registerFilters(editor)
  32583. } else {
  32584. editor.on('PreInit', function () {
  32585. registerFilters(editor)
  32586. })
  32587. }
  32588. }
  32589. var isClickEvent = function (e) {
  32590. return e.type === 'click'
  32591. }
  32592. var getAnchorHrefOpt = function (editor, elm) {
  32593. var isRoot = function (elm) {
  32594. return eq(elm, SugarElement.fromDom(editor.getBody()))
  32595. }
  32596. return closest$2(elm, 'a', isRoot).bind(function (a) {
  32597. return getOpt(a, 'href')
  32598. })
  32599. }
  32600. var processReadonlyEvents = function (editor, e) {
  32601. if (isClickEvent(e) && !VK.metaKeyPressed(e)) {
  32602. var elm = SugarElement.fromDom(e.target)
  32603. getAnchorHrefOpt(editor, elm).each(function (href) {
  32604. e.preventDefault()
  32605. if (/^#/.test(href)) {
  32606. var targetEl = editor.dom.select(
  32607. href + ',[name="' + removeLeading(href, '#') + '"]'
  32608. )
  32609. if (targetEl.length) {
  32610. editor.selection.scrollIntoView(targetEl[0], true)
  32611. }
  32612. } else {
  32613. window.open(
  32614. href,
  32615. '_blank',
  32616. 'rel=noopener noreferrer,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes'
  32617. )
  32618. }
  32619. })
  32620. }
  32621. }
  32622. var registerReadOnlySelectionBlockers = function (editor) {
  32623. editor.on('ShowCaret', function (e) {
  32624. if (isReadOnly(editor)) {
  32625. e.preventDefault()
  32626. }
  32627. })
  32628. editor.on('ObjectSelected', function (e) {
  32629. if (isReadOnly(editor)) {
  32630. e.preventDefault()
  32631. }
  32632. })
  32633. }
  32634. var nativeEvents = Tools.makeMap(
  32635. 'focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange ' +
  32636. 'mouseout mouseenter mouseleave wheel keydown keypress keyup input beforeinput contextmenu dragstart dragend dragover ' +
  32637. 'draggesture dragdrop drop drag submit ' +
  32638. 'compositionstart compositionend compositionupdate touchstart touchmove touchend touchcancel',
  32639. ' '
  32640. )
  32641. var EventDispatcher = (function () {
  32642. function EventDispatcher(settings) {
  32643. this.bindings = {}
  32644. this.settings = settings || {}
  32645. this.scope = this.settings.scope || this
  32646. this.toggleEvent = this.settings.toggleEvent || never
  32647. }
  32648. EventDispatcher.isNative = function (name) {
  32649. return !!nativeEvents[name.toLowerCase()]
  32650. }
  32651. EventDispatcher.prototype.fire = function (name, args) {
  32652. var lcName = name.toLowerCase()
  32653. var event = normalize$3(lcName, args || {}, this.scope)
  32654. if (this.settings.beforeFire) {
  32655. this.settings.beforeFire(event)
  32656. }
  32657. var handlers = this.bindings[lcName]
  32658. if (handlers) {
  32659. for (var i = 0, l = handlers.length; i < l; i++) {
  32660. var callback = handlers[i]
  32661. if (callback.removed) {
  32662. continue
  32663. }
  32664. if (callback.once) {
  32665. this.off(lcName, callback.func)
  32666. }
  32667. if (event.isImmediatePropagationStopped()) {
  32668. return event
  32669. }
  32670. if (callback.func.call(this.scope, event) === false) {
  32671. event.preventDefault()
  32672. return event
  32673. }
  32674. }
  32675. }
  32676. return event
  32677. }
  32678. EventDispatcher.prototype.on = function (name, callback, prepend, extra) {
  32679. if (callback === false) {
  32680. callback = never
  32681. }
  32682. if (callback) {
  32683. var wrappedCallback = {
  32684. func: callback,
  32685. removed: false,
  32686. }
  32687. if (extra) {
  32688. Tools.extend(wrappedCallback, extra)
  32689. }
  32690. var names = name.toLowerCase().split(' ')
  32691. var i = names.length
  32692. while (i--) {
  32693. var currentName = names[i]
  32694. var handlers = this.bindings[currentName]
  32695. if (!handlers) {
  32696. handlers = []
  32697. this.toggleEvent(currentName, true)
  32698. }
  32699. if (prepend) {
  32700. handlers = __spreadArray([wrappedCallback], handlers, true)
  32701. } else {
  32702. handlers = __spreadArray(
  32703. __spreadArray([], handlers, true),
  32704. [wrappedCallback],
  32705. false
  32706. )
  32707. }
  32708. this.bindings[currentName] = handlers
  32709. }
  32710. }
  32711. return this
  32712. }
  32713. EventDispatcher.prototype.off = function (name, callback) {
  32714. var _this = this
  32715. if (name) {
  32716. var names = name.toLowerCase().split(' ')
  32717. var i = names.length
  32718. while (i--) {
  32719. var currentName = names[i]
  32720. var handlers = this.bindings[currentName]
  32721. if (!currentName) {
  32722. each$j(this.bindings, function (_value, bindingName) {
  32723. _this.toggleEvent(bindingName, false)
  32724. delete _this.bindings[bindingName]
  32725. })
  32726. return this
  32727. }
  32728. if (handlers) {
  32729. if (!callback) {
  32730. handlers.length = 0
  32731. } else {
  32732. var filteredHandlers = partition(handlers, function (handler) {
  32733. return handler.func === callback
  32734. })
  32735. handlers = filteredHandlers.fail
  32736. this.bindings[currentName] = handlers
  32737. each$k(filteredHandlers.pass, function (handler) {
  32738. handler.removed = true
  32739. })
  32740. }
  32741. if (!handlers.length) {
  32742. this.toggleEvent(name, false)
  32743. delete this.bindings[currentName]
  32744. }
  32745. }
  32746. }
  32747. } else {
  32748. each$j(this.bindings, function (_value, name) {
  32749. _this.toggleEvent(name, false)
  32750. })
  32751. this.bindings = {}
  32752. }
  32753. return this
  32754. }
  32755. EventDispatcher.prototype.once = function (name, callback, prepend) {
  32756. return this.on(name, callback, prepend, { once: true })
  32757. }
  32758. EventDispatcher.prototype.has = function (name) {
  32759. name = name.toLowerCase()
  32760. return !(!this.bindings[name] || this.bindings[name].length === 0)
  32761. }
  32762. return EventDispatcher
  32763. })()
  32764. var getEventDispatcher = function (obj) {
  32765. if (!obj._eventDispatcher) {
  32766. obj._eventDispatcher = new EventDispatcher({
  32767. scope: obj,
  32768. toggleEvent: function (name, state) {
  32769. if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) {
  32770. obj.toggleNativeEvent(name, state)
  32771. }
  32772. },
  32773. })
  32774. }
  32775. return obj._eventDispatcher
  32776. }
  32777. var Observable = {
  32778. fire: function (name, args, bubble) {
  32779. var self = this
  32780. if (self.removed && name !== 'remove' && name !== 'detach') {
  32781. return args
  32782. }
  32783. var dispatcherArgs = getEventDispatcher(self).fire(name, args)
  32784. if (bubble !== false && self.parent) {
  32785. var parent_1 = self.parent()
  32786. while (parent_1 && !dispatcherArgs.isPropagationStopped()) {
  32787. parent_1.fire(name, dispatcherArgs, false)
  32788. parent_1 = parent_1.parent()
  32789. }
  32790. }
  32791. return dispatcherArgs
  32792. },
  32793. on: function (name, callback, prepend) {
  32794. return getEventDispatcher(this).on(name, callback, prepend)
  32795. },
  32796. off: function (name, callback) {
  32797. return getEventDispatcher(this).off(name, callback)
  32798. },
  32799. once: function (name, callback) {
  32800. return getEventDispatcher(this).once(name, callback)
  32801. },
  32802. hasEventListeners: function (name) {
  32803. return getEventDispatcher(this).has(name)
  32804. },
  32805. }
  32806. var DOM$2 = DOMUtils.DOM
  32807. var customEventRootDelegates
  32808. var getEventTarget = function (editor, eventName) {
  32809. if (eventName === 'selectionchange') {
  32810. return editor.getDoc()
  32811. }
  32812. if (
  32813. !editor.inline &&
  32814. /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)
  32815. ) {
  32816. return editor.getDoc().documentElement
  32817. }
  32818. var eventRoot = getEventRoot(editor)
  32819. if (eventRoot) {
  32820. if (!editor.eventRoot) {
  32821. editor.eventRoot = DOM$2.select(eventRoot)[0]
  32822. }
  32823. return editor.eventRoot
  32824. }
  32825. return editor.getBody()
  32826. }
  32827. var isListening = function (editor) {
  32828. return !editor.hidden && !isReadOnly(editor)
  32829. }
  32830. var fireEvent = function (editor, eventName, e) {
  32831. if (isListening(editor)) {
  32832. editor.fire(eventName, e)
  32833. } else if (isReadOnly(editor)) {
  32834. processReadonlyEvents(editor, e)
  32835. }
  32836. }
  32837. var bindEventDelegate = function (editor, eventName) {
  32838. var delegate
  32839. if (!editor.delegates) {
  32840. editor.delegates = {}
  32841. }
  32842. if (editor.delegates[eventName] || editor.removed) {
  32843. return
  32844. }
  32845. var eventRootElm = getEventTarget(editor, eventName)
  32846. if (getEventRoot(editor)) {
  32847. if (!customEventRootDelegates) {
  32848. customEventRootDelegates = {}
  32849. editor.editorManager.on('removeEditor', function () {
  32850. if (!editor.editorManager.activeEditor) {
  32851. if (customEventRootDelegates) {
  32852. each$j(customEventRootDelegates, function (_value, name) {
  32853. editor.dom.unbind(getEventTarget(editor, name))
  32854. })
  32855. customEventRootDelegates = null
  32856. }
  32857. }
  32858. })
  32859. }
  32860. if (customEventRootDelegates[eventName]) {
  32861. return
  32862. }
  32863. delegate = function (e) {
  32864. var target = e.target
  32865. var editors = editor.editorManager.get()
  32866. var i = editors.length
  32867. while (i--) {
  32868. var body = editors[i].getBody()
  32869. if (body === target || DOM$2.isChildOf(target, body)) {
  32870. fireEvent(editors[i], eventName, e)
  32871. }
  32872. }
  32873. }
  32874. customEventRootDelegates[eventName] = delegate
  32875. DOM$2.bind(eventRootElm, eventName, delegate)
  32876. } else {
  32877. delegate = function (e) {
  32878. fireEvent(editor, eventName, e)
  32879. }
  32880. DOM$2.bind(eventRootElm, eventName, delegate)
  32881. editor.delegates[eventName] = delegate
  32882. }
  32883. }
  32884. var EditorObservable = __assign(__assign({}, Observable), {
  32885. bindPendingEventDelegates: function () {
  32886. var self = this
  32887. Tools.each(self._pendingNativeEvents, function (name) {
  32888. bindEventDelegate(self, name)
  32889. })
  32890. },
  32891. toggleNativeEvent: function (name, state) {
  32892. var self = this
  32893. if (name === 'focus' || name === 'blur') {
  32894. return
  32895. }
  32896. if (self.removed) {
  32897. return
  32898. }
  32899. if (state) {
  32900. if (self.initialized) {
  32901. bindEventDelegate(self, name)
  32902. } else {
  32903. if (!self._pendingNativeEvents) {
  32904. self._pendingNativeEvents = [name]
  32905. } else {
  32906. self._pendingNativeEvents.push(name)
  32907. }
  32908. }
  32909. } else if (self.initialized) {
  32910. self.dom.unbind(getEventTarget(self, name), name, self.delegates[name])
  32911. delete self.delegates[name]
  32912. }
  32913. },
  32914. unbindAllNativeEvents: function () {
  32915. var self = this
  32916. var body = self.getBody()
  32917. var dom = self.dom
  32918. if (self.delegates) {
  32919. each$j(self.delegates, function (value, name) {
  32920. self.dom.unbind(getEventTarget(self, name), name, value)
  32921. })
  32922. delete self.delegates
  32923. }
  32924. if (!self.inline && body && dom) {
  32925. body.onload = null
  32926. dom.unbind(self.getWin())
  32927. dom.unbind(self.getDoc())
  32928. }
  32929. if (dom) {
  32930. dom.unbind(body)
  32931. dom.unbind(self.getContainer())
  32932. }
  32933. },
  32934. })
  32935. var defaultModes = ['design', 'readonly']
  32936. var switchToMode = function (editor, activeMode, availableModes, mode) {
  32937. var oldMode = availableModes[activeMode.get()]
  32938. var newMode = availableModes[mode]
  32939. try {
  32940. newMode.activate()
  32941. } catch (e) {
  32942. console.error('problem while activating editor mode ' + mode + ':', e)
  32943. return
  32944. }
  32945. oldMode.deactivate()
  32946. if (oldMode.editorReadOnly !== newMode.editorReadOnly) {
  32947. toggleReadOnly(editor, newMode.editorReadOnly)
  32948. }
  32949. activeMode.set(mode)
  32950. fireSwitchMode(editor, mode)
  32951. }
  32952. var setMode = function (editor, availableModes, activeMode, mode) {
  32953. if (mode === activeMode.get()) {
  32954. return
  32955. } else if (!has$2(availableModes, mode)) {
  32956. throw new Error("Editor mode '" + mode + "' is invalid")
  32957. }
  32958. if (editor.initialized) {
  32959. switchToMode(editor, activeMode, availableModes, mode)
  32960. } else {
  32961. editor.on('init', function () {
  32962. return switchToMode(editor, activeMode, availableModes, mode)
  32963. })
  32964. }
  32965. }
  32966. var registerMode = function (availableModes, mode, api) {
  32967. var _a
  32968. if (contains$3(defaultModes, mode)) {
  32969. throw new Error('Cannot override default mode ' + mode)
  32970. }
  32971. return __assign(
  32972. __assign({}, availableModes),
  32973. ((_a = {}),
  32974. (_a[mode] = __assign(__assign({}, api), {
  32975. deactivate: function () {
  32976. try {
  32977. api.deactivate()
  32978. } catch (e) {
  32979. console.error(
  32980. 'problem while deactivating editor mode ' + mode + ':',
  32981. e
  32982. )
  32983. }
  32984. },
  32985. })),
  32986. _a)
  32987. )
  32988. }
  32989. var create$4 = function (editor) {
  32990. var activeMode = Cell('design')
  32991. var availableModes = Cell({
  32992. design: {
  32993. activate: noop,
  32994. deactivate: noop,
  32995. editorReadOnly: false,
  32996. },
  32997. readonly: {
  32998. activate: noop,
  32999. deactivate: noop,
  33000. editorReadOnly: true,
  33001. },
  33002. })
  33003. registerReadOnlyContentFilters(editor)
  33004. registerReadOnlySelectionBlockers(editor)
  33005. return {
  33006. isReadOnly: function () {
  33007. return isReadOnly(editor)
  33008. },
  33009. set: function (mode) {
  33010. return setMode(editor, availableModes.get(), activeMode, mode)
  33011. },
  33012. get: function () {
  33013. return activeMode.get()
  33014. },
  33015. register: function (mode, api) {
  33016. availableModes.set(registerMode(availableModes.get(), mode, api))
  33017. },
  33018. }
  33019. }
  33020. var each$3 = Tools.each,
  33021. explode$1 = Tools.explode
  33022. var keyCodeLookup = {
  33023. f1: 112,
  33024. f2: 113,
  33025. f3: 114,
  33026. f4: 115,
  33027. f5: 116,
  33028. f6: 117,
  33029. f7: 118,
  33030. f8: 119,
  33031. f9: 120,
  33032. f10: 121,
  33033. f11: 122,
  33034. f12: 123,
  33035. }
  33036. var modifierNames = Tools.makeMap('alt,ctrl,shift,meta,access')
  33037. var parseShortcut = function (pattern) {
  33038. var key
  33039. var shortcut = {}
  33040. each$3(explode$1(pattern.toLowerCase(), '+'), function (value) {
  33041. if (value in modifierNames) {
  33042. shortcut[value] = true
  33043. } else {
  33044. if (/^[0-9]{2,}$/.test(value)) {
  33045. shortcut.keyCode = parseInt(value, 10)
  33046. } else {
  33047. shortcut.charCode = value.charCodeAt(0)
  33048. shortcut.keyCode =
  33049. keyCodeLookup[value] || value.toUpperCase().charCodeAt(0)
  33050. }
  33051. }
  33052. })
  33053. var id = [shortcut.keyCode]
  33054. for (key in modifierNames) {
  33055. if (shortcut[key]) {
  33056. id.push(key)
  33057. } else {
  33058. shortcut[key] = false
  33059. }
  33060. }
  33061. shortcut.id = id.join(',')
  33062. if (shortcut.access) {
  33063. shortcut.alt = true
  33064. if (Env.mac) {
  33065. shortcut.ctrl = true
  33066. } else {
  33067. shortcut.shift = true
  33068. }
  33069. }
  33070. if (shortcut.meta) {
  33071. if (Env.mac) {
  33072. shortcut.meta = true
  33073. } else {
  33074. shortcut.ctrl = true
  33075. shortcut.meta = false
  33076. }
  33077. }
  33078. return shortcut
  33079. }
  33080. var Shortcuts = (function () {
  33081. function Shortcuts(editor) {
  33082. this.shortcuts = {}
  33083. this.pendingPatterns = []
  33084. this.editor = editor
  33085. var self = this
  33086. editor.on('keyup keypress keydown', function (e) {
  33087. if (
  33088. (self.hasModifier(e) || self.isFunctionKey(e)) &&
  33089. !e.isDefaultPrevented()
  33090. ) {
  33091. each$3(self.shortcuts, function (shortcut) {
  33092. if (self.matchShortcut(e, shortcut)) {
  33093. self.pendingPatterns = shortcut.subpatterns.slice(0)
  33094. if (e.type === 'keydown') {
  33095. self.executeShortcutAction(shortcut)
  33096. }
  33097. return true
  33098. }
  33099. })
  33100. if (self.matchShortcut(e, self.pendingPatterns[0])) {
  33101. if (self.pendingPatterns.length === 1) {
  33102. if (e.type === 'keydown') {
  33103. self.executeShortcutAction(self.pendingPatterns[0])
  33104. }
  33105. }
  33106. self.pendingPatterns.shift()
  33107. }
  33108. }
  33109. })
  33110. }
  33111. Shortcuts.prototype.add = function (pattern, desc, cmdFunc, scope) {
  33112. var self = this
  33113. var func = self.normalizeCommandFunc(cmdFunc)
  33114. each$3(explode$1(Tools.trim(pattern)), function (pattern) {
  33115. var shortcut = self.createShortcut(pattern, desc, func, scope)
  33116. self.shortcuts[shortcut.id] = shortcut
  33117. })
  33118. return true
  33119. }
  33120. Shortcuts.prototype.remove = function (pattern) {
  33121. var shortcut = this.createShortcut(pattern)
  33122. if (this.shortcuts[shortcut.id]) {
  33123. delete this.shortcuts[shortcut.id]
  33124. return true
  33125. }
  33126. return false
  33127. }
  33128. Shortcuts.prototype.normalizeCommandFunc = function (cmdFunc) {
  33129. var self = this
  33130. var cmd = cmdFunc
  33131. if (typeof cmd === 'string') {
  33132. return function () {
  33133. self.editor.execCommand(cmd, false, null)
  33134. }
  33135. } else if (Tools.isArray(cmd)) {
  33136. return function () {
  33137. self.editor.execCommand(cmd[0], cmd[1], cmd[2])
  33138. }
  33139. } else {
  33140. return cmd
  33141. }
  33142. }
  33143. Shortcuts.prototype.createShortcut = function (
  33144. pattern,
  33145. desc,
  33146. cmdFunc,
  33147. scope
  33148. ) {
  33149. var shortcuts = Tools.map(explode$1(pattern, '>'), parseShortcut)
  33150. shortcuts[shortcuts.length - 1] = Tools.extend(
  33151. shortcuts[shortcuts.length - 1],
  33152. {
  33153. func: cmdFunc,
  33154. scope: scope || this.editor,
  33155. }
  33156. )
  33157. return Tools.extend(shortcuts[0], {
  33158. desc: this.editor.translate(desc),
  33159. subpatterns: shortcuts.slice(1),
  33160. })
  33161. }
  33162. Shortcuts.prototype.hasModifier = function (e) {
  33163. return e.altKey || e.ctrlKey || e.metaKey
  33164. }
  33165. Shortcuts.prototype.isFunctionKey = function (e) {
  33166. return e.type === 'keydown' && e.keyCode >= 112 && e.keyCode <= 123
  33167. }
  33168. Shortcuts.prototype.matchShortcut = function (e, shortcut) {
  33169. if (!shortcut) {
  33170. return false
  33171. }
  33172. if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) {
  33173. return false
  33174. }
  33175. if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) {
  33176. return false
  33177. }
  33178. if (
  33179. e.keyCode === shortcut.keyCode ||
  33180. (e.charCode && e.charCode === shortcut.charCode)
  33181. ) {
  33182. e.preventDefault()
  33183. return true
  33184. }
  33185. return false
  33186. }
  33187. Shortcuts.prototype.executeShortcutAction = function (shortcut) {
  33188. return shortcut.func ? shortcut.func.call(shortcut.scope) : null
  33189. }
  33190. return Shortcuts
  33191. })()
  33192. var create$3 = function () {
  33193. var buttons = {}
  33194. var menuItems = {}
  33195. var popups = {}
  33196. var icons = {}
  33197. var contextMenus = {}
  33198. var contextToolbars = {}
  33199. var sidebars = {}
  33200. var add = function (collection, type) {
  33201. return function (name, spec) {
  33202. return (collection[name.toLowerCase()] = __assign(__assign({}, spec), {
  33203. type: type,
  33204. }))
  33205. }
  33206. }
  33207. var addIcon = function (name, svgData) {
  33208. return (icons[name.toLowerCase()] = svgData)
  33209. }
  33210. return {
  33211. addButton: add(buttons, 'button'),
  33212. addGroupToolbarButton: add(buttons, 'grouptoolbarbutton'),
  33213. addToggleButton: add(buttons, 'togglebutton'),
  33214. addMenuButton: add(buttons, 'menubutton'),
  33215. addSplitButton: add(buttons, 'splitbutton'),
  33216. addMenuItem: add(menuItems, 'menuitem'),
  33217. addNestedMenuItem: add(menuItems, 'nestedmenuitem'),
  33218. addToggleMenuItem: add(menuItems, 'togglemenuitem'),
  33219. addAutocompleter: add(popups, 'autocompleter'),
  33220. addContextMenu: add(contextMenus, 'contextmenu'),
  33221. addContextToolbar: add(contextToolbars, 'contexttoolbar'),
  33222. addContextForm: add(contextToolbars, 'contextform'),
  33223. addSidebar: add(sidebars, 'sidebar'),
  33224. addIcon: addIcon,
  33225. getAll: function () {
  33226. return {
  33227. buttons: buttons,
  33228. menuItems: menuItems,
  33229. icons: icons,
  33230. popups: popups,
  33231. contextMenus: contextMenus,
  33232. contextToolbars: contextToolbars,
  33233. sidebars: sidebars,
  33234. }
  33235. },
  33236. }
  33237. }
  33238. var registry = function () {
  33239. var bridge = create$3()
  33240. return {
  33241. addAutocompleter: bridge.addAutocompleter,
  33242. addButton: bridge.addButton,
  33243. addContextForm: bridge.addContextForm,
  33244. addContextMenu: bridge.addContextMenu,
  33245. addContextToolbar: bridge.addContextToolbar,
  33246. addIcon: bridge.addIcon,
  33247. addMenuButton: bridge.addMenuButton,
  33248. addMenuItem: bridge.addMenuItem,
  33249. addNestedMenuItem: bridge.addNestedMenuItem,
  33250. addSidebar: bridge.addSidebar,
  33251. addSplitButton: bridge.addSplitButton,
  33252. addToggleButton: bridge.addToggleButton,
  33253. addGroupToolbarButton: bridge.addGroupToolbarButton,
  33254. addToggleMenuItem: bridge.addToggleMenuItem,
  33255. getAll: bridge.getAll,
  33256. }
  33257. }
  33258. var DOM$1 = DOMUtils.DOM
  33259. var extend$3 = Tools.extend,
  33260. each$2 = Tools.each
  33261. var resolve = Tools.resolve
  33262. var ie = Env.ie
  33263. var Editor = (function () {
  33264. function Editor(id, settings, editorManager) {
  33265. var _this = this
  33266. this.plugins = {}
  33267. this.contentCSS = []
  33268. this.contentStyles = []
  33269. this.loadedCSS = {}
  33270. this.isNotDirty = false
  33271. this.editorManager = editorManager
  33272. this.documentBaseUrl = editorManager.documentBaseURL
  33273. extend$3(this, EditorObservable)
  33274. this.settings = getEditorSettings(
  33275. this,
  33276. id,
  33277. this.documentBaseUrl,
  33278. editorManager.defaultSettings,
  33279. settings
  33280. )
  33281. if (this.settings.suffix) {
  33282. editorManager.suffix = this.settings.suffix
  33283. }
  33284. this.suffix = editorManager.suffix
  33285. if (this.settings.base_url) {
  33286. editorManager._setBaseUrl(this.settings.base_url)
  33287. }
  33288. this.baseUri = editorManager.baseURI
  33289. if (this.settings.referrer_policy) {
  33290. ScriptLoader.ScriptLoader._setReferrerPolicy(
  33291. this.settings.referrer_policy
  33292. )
  33293. DOMUtils.DOM.styleSheetLoader._setReferrerPolicy(
  33294. this.settings.referrer_policy
  33295. )
  33296. }
  33297. AddOnManager.languageLoad = this.settings.language_load
  33298. AddOnManager.baseURL = editorManager.baseURL
  33299. this.id = id
  33300. this.setDirty(false)
  33301. this.documentBaseURI = new URI(this.settings.document_base_url, {
  33302. base_uri: this.baseUri,
  33303. })
  33304. this.baseURI = this.baseUri
  33305. this.inline = !!this.settings.inline
  33306. this.shortcuts = new Shortcuts(this)
  33307. this.editorCommands = new EditorCommands(this)
  33308. if (this.settings.cache_suffix) {
  33309. Env.cacheSuffix = this.settings.cache_suffix.replace(/^[\?\&]+/, '')
  33310. }
  33311. this.ui = {
  33312. registry: registry(),
  33313. styleSheetLoader: undefined,
  33314. show: noop,
  33315. hide: noop,
  33316. enable: noop,
  33317. disable: noop,
  33318. isDisabled: never,
  33319. }
  33320. var self = this
  33321. var modeInstance = create$4(self)
  33322. this.mode = modeInstance
  33323. this.setMode = modeInstance.set
  33324. editorManager.fire('SetupEditor', { editor: this })
  33325. this.execCallback('setup', this)
  33326. this.$ = DomQuery.overrideDefaults(function () {
  33327. return {
  33328. context: _this.inline ? _this.getBody() : _this.getDoc(),
  33329. element: _this.getBody(),
  33330. }
  33331. })
  33332. }
  33333. Editor.prototype.render = function () {
  33334. render(this)
  33335. }
  33336. Editor.prototype.focus = function (skipFocus) {
  33337. this.execCommand('mceFocus', false, skipFocus)
  33338. }
  33339. Editor.prototype.hasFocus = function () {
  33340. return hasFocus(this)
  33341. }
  33342. Editor.prototype.execCallback = function (name) {
  33343. var x = []
  33344. for (var _i = 1; _i < arguments.length; _i++) {
  33345. x[_i - 1] = arguments[_i]
  33346. }
  33347. var self = this
  33348. var callback = self.settings[name],
  33349. scope
  33350. if (!callback) {
  33351. return
  33352. }
  33353. if (self.callbackLookup && (scope = self.callbackLookup[name])) {
  33354. callback = scope.func
  33355. scope = scope.scope
  33356. }
  33357. if (typeof callback === 'string') {
  33358. scope = callback.replace(/\.\w+$/, '')
  33359. scope = scope ? resolve(scope) : 0
  33360. callback = resolve(callback)
  33361. self.callbackLookup = self.callbackLookup || {}
  33362. self.callbackLookup[name] = {
  33363. func: callback,
  33364. scope: scope,
  33365. }
  33366. }
  33367. return callback.apply(scope || self, x)
  33368. }
  33369. Editor.prototype.translate = function (text) {
  33370. return I18n.translate(text)
  33371. }
  33372. Editor.prototype.getParam = function (name, defaultVal, type) {
  33373. return getParam(this, name, defaultVal, type)
  33374. }
  33375. Editor.prototype.hasPlugin = function (name, loaded) {
  33376. var hasPlugin = contains$3(getPlugins(this).split(/[ ,]/), name)
  33377. if (hasPlugin) {
  33378. return loaded ? PluginManager.get(name) !== undefined : true
  33379. } else {
  33380. return false
  33381. }
  33382. }
  33383. Editor.prototype.nodeChanged = function (args) {
  33384. this._nodeChangeDispatcher.nodeChanged(args)
  33385. }
  33386. Editor.prototype.addCommand = function (name, callback, scope) {
  33387. this.editorCommands.addCommand(name, callback, scope)
  33388. }
  33389. Editor.prototype.addQueryStateHandler = function (name, callback, scope) {
  33390. this.editorCommands.addQueryStateHandler(name, callback, scope)
  33391. }
  33392. Editor.prototype.addQueryValueHandler = function (name, callback, scope) {
  33393. this.editorCommands.addQueryValueHandler(name, callback, scope)
  33394. }
  33395. Editor.prototype.addShortcut = function (pattern, desc, cmdFunc, scope) {
  33396. this.shortcuts.add(pattern, desc, cmdFunc, scope)
  33397. }
  33398. Editor.prototype.execCommand = function (cmd, ui, value, args) {
  33399. return this.editorCommands.execCommand(cmd, ui, value, args)
  33400. }
  33401. Editor.prototype.queryCommandState = function (cmd) {
  33402. return this.editorCommands.queryCommandState(cmd)
  33403. }
  33404. Editor.prototype.queryCommandValue = function (cmd) {
  33405. return this.editorCommands.queryCommandValue(cmd)
  33406. }
  33407. Editor.prototype.queryCommandSupported = function (cmd) {
  33408. return this.editorCommands.queryCommandSupported(cmd)
  33409. }
  33410. Editor.prototype.show = function () {
  33411. var self = this
  33412. if (self.hidden) {
  33413. self.hidden = false
  33414. if (self.inline) {
  33415. self.getBody().contentEditable = 'true'
  33416. } else {
  33417. DOM$1.show(self.getContainer())
  33418. DOM$1.hide(self.id)
  33419. }
  33420. self.load()
  33421. self.fire('show')
  33422. }
  33423. }
  33424. Editor.prototype.hide = function () {
  33425. var self = this,
  33426. doc = self.getDoc()
  33427. if (!self.hidden) {
  33428. if (ie && doc && !self.inline) {
  33429. doc.execCommand('SelectAll')
  33430. }
  33431. self.save()
  33432. if (self.inline) {
  33433. self.getBody().contentEditable = 'false'
  33434. if (self === self.editorManager.focusedEditor) {
  33435. self.editorManager.focusedEditor = null
  33436. }
  33437. } else {
  33438. DOM$1.hide(self.getContainer())
  33439. DOM$1.setStyle(self.id, 'display', self.orgDisplay)
  33440. }
  33441. self.hidden = true
  33442. self.fire('hide')
  33443. }
  33444. }
  33445. Editor.prototype.isHidden = function () {
  33446. return !!this.hidden
  33447. }
  33448. Editor.prototype.setProgressState = function (state, time) {
  33449. this.fire('ProgressState', {
  33450. state: state,
  33451. time: time,
  33452. })
  33453. }
  33454. Editor.prototype.load = function (args) {
  33455. var self = this
  33456. var elm = self.getElement(),
  33457. html
  33458. if (self.removed) {
  33459. return ''
  33460. }
  33461. if (elm) {
  33462. args = args || {}
  33463. args.load = true
  33464. var value = isTextareaOrInput(elm) ? elm.value : elm.innerHTML
  33465. html = self.setContent(value, args)
  33466. args.element = elm
  33467. if (!args.no_events) {
  33468. self.fire('LoadContent', args)
  33469. }
  33470. args.element = elm = null
  33471. return html
  33472. }
  33473. }
  33474. Editor.prototype.save = function (args) {
  33475. var self = this
  33476. var elm = self.getElement(),
  33477. html,
  33478. form
  33479. if (!elm || !self.initialized || self.removed) {
  33480. return
  33481. }
  33482. args = args || {}
  33483. args.save = true
  33484. args.element = elm
  33485. html = args.content = self.getContent(args)
  33486. if (!args.no_events) {
  33487. self.fire('SaveContent', args)
  33488. }
  33489. if (args.format === 'raw') {
  33490. self.fire('RawSaveContent', args)
  33491. }
  33492. html = args.content
  33493. if (!isTextareaOrInput(elm)) {
  33494. if (args.is_removing || !self.inline) {
  33495. elm.innerHTML = html
  33496. }
  33497. if ((form = DOM$1.getParent(self.id, 'form'))) {
  33498. each$2(form.elements, function (elm) {
  33499. if (elm.name === self.id) {
  33500. elm.value = html
  33501. return false
  33502. }
  33503. })
  33504. }
  33505. } else {
  33506. elm.value = html
  33507. }
  33508. args.element = elm = null
  33509. if (args.set_dirty !== false) {
  33510. self.setDirty(false)
  33511. }
  33512. return html
  33513. }
  33514. Editor.prototype.setContent = function (content, args) {
  33515. return setContent(this, content, args)
  33516. }
  33517. Editor.prototype.getContent = function (args) {
  33518. return getContent(this, args)
  33519. }
  33520. Editor.prototype.insertContent = function (content, args) {
  33521. if (args) {
  33522. content = extend$3({ content: content }, args)
  33523. }
  33524. this.execCommand('mceInsertContent', false, content)
  33525. }
  33526. Editor.prototype.resetContent = function (initialContent) {
  33527. if (initialContent === undefined) {
  33528. setContent(this, this.startContent, { format: 'raw' })
  33529. } else {
  33530. setContent(this, initialContent)
  33531. }
  33532. this.undoManager.reset()
  33533. this.setDirty(false)
  33534. this.nodeChanged()
  33535. }
  33536. Editor.prototype.isDirty = function () {
  33537. return !this.isNotDirty
  33538. }
  33539. Editor.prototype.setDirty = function (state) {
  33540. var oldState = !this.isNotDirty
  33541. this.isNotDirty = !state
  33542. if (state && state !== oldState) {
  33543. this.fire('dirty')
  33544. }
  33545. }
  33546. Editor.prototype.getContainer = function () {
  33547. var self = this
  33548. if (!self.container) {
  33549. self.container = DOM$1.get(self.editorContainer || self.id + '_parent')
  33550. }
  33551. return self.container
  33552. }
  33553. Editor.prototype.getContentAreaContainer = function () {
  33554. return this.contentAreaContainer
  33555. }
  33556. Editor.prototype.getElement = function () {
  33557. if (!this.targetElm) {
  33558. this.targetElm = DOM$1.get(this.id)
  33559. }
  33560. return this.targetElm
  33561. }
  33562. Editor.prototype.getWin = function () {
  33563. var self = this
  33564. var elm
  33565. if (!self.contentWindow) {
  33566. elm = self.iframeElement
  33567. if (elm) {
  33568. self.contentWindow = elm.contentWindow
  33569. }
  33570. }
  33571. return self.contentWindow
  33572. }
  33573. Editor.prototype.getDoc = function () {
  33574. var self = this
  33575. var win
  33576. if (!self.contentDocument) {
  33577. win = self.getWin()
  33578. if (win) {
  33579. self.contentDocument = win.document
  33580. }
  33581. }
  33582. return self.contentDocument
  33583. }
  33584. Editor.prototype.getBody = function () {
  33585. var doc = this.getDoc()
  33586. return this.bodyElement || (doc ? doc.body : null)
  33587. }
  33588. Editor.prototype.convertURL = function (url, name, elm) {
  33589. var self = this,
  33590. settings = self.settings
  33591. if (settings.urlconverter_callback) {
  33592. return self.execCallback('urlconverter_callback', url, elm, true, name)
  33593. }
  33594. if (
  33595. !settings.convert_urls ||
  33596. (elm && elm.nodeName === 'LINK') ||
  33597. url.indexOf('file:') === 0 ||
  33598. url.length === 0
  33599. ) {
  33600. return url
  33601. }
  33602. if (settings.relative_urls) {
  33603. return self.documentBaseURI.toRelative(url)
  33604. }
  33605. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host)
  33606. return url
  33607. }
  33608. Editor.prototype.addVisual = function (elm) {
  33609. addVisual(this, elm)
  33610. }
  33611. Editor.prototype.remove = function () {
  33612. remove(this)
  33613. }
  33614. Editor.prototype.destroy = function (automatic) {
  33615. destroy(this, automatic)
  33616. }
  33617. Editor.prototype.uploadImages = function (callback) {
  33618. return this.editorUpload.uploadImages(callback)
  33619. }
  33620. Editor.prototype._scanForImages = function () {
  33621. return this.editorUpload.scanForImages()
  33622. }
  33623. Editor.prototype.addButton = function () {
  33624. throw new Error(
  33625. 'editor.addButton has been removed in tinymce 5x, use editor.ui.registry.addButton or editor.ui.registry.addToggleButton or editor.ui.registry.addSplitButton instead'
  33626. )
  33627. }
  33628. Editor.prototype.addSidebar = function () {
  33629. throw new Error(
  33630. 'editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead'
  33631. )
  33632. }
  33633. Editor.prototype.addMenuItem = function () {
  33634. throw new Error(
  33635. 'editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead'
  33636. )
  33637. }
  33638. Editor.prototype.addContextToolbar = function () {
  33639. throw new Error(
  33640. 'editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead'
  33641. )
  33642. }
  33643. return Editor
  33644. })()
  33645. var DOM = DOMUtils.DOM
  33646. var explode = Tools.explode,
  33647. each$1 = Tools.each,
  33648. extend$2 = Tools.extend
  33649. var instanceCounter = 0,
  33650. boundGlobalEvents = false
  33651. var beforeUnloadDelegate
  33652. var legacyEditors = []
  33653. var editors = []
  33654. var isValidLegacyKey = function (id) {
  33655. return id !== 'length'
  33656. }
  33657. var globalEventDelegate = function (e) {
  33658. var type = e.type
  33659. each$1(EditorManager.get(), function (editor) {
  33660. switch (type) {
  33661. case 'scroll':
  33662. editor.fire('ScrollWindow', e)
  33663. break
  33664. case 'resize':
  33665. editor.fire('ResizeWindow', e)
  33666. break
  33667. }
  33668. })
  33669. }
  33670. var toggleGlobalEvents = function (state) {
  33671. if (state !== boundGlobalEvents) {
  33672. if (state) {
  33673. DomQuery(window).on('resize scroll', globalEventDelegate)
  33674. } else {
  33675. DomQuery(window).off('resize scroll', globalEventDelegate)
  33676. }
  33677. boundGlobalEvents = state
  33678. }
  33679. }
  33680. var removeEditorFromList = function (targetEditor) {
  33681. var oldEditors = editors
  33682. delete legacyEditors[targetEditor.id]
  33683. for (var i = 0; i < legacyEditors.length; i++) {
  33684. if (legacyEditors[i] === targetEditor) {
  33685. legacyEditors.splice(i, 1)
  33686. break
  33687. }
  33688. }
  33689. editors = filter$4(editors, function (editor) {
  33690. return targetEditor !== editor
  33691. })
  33692. if (EditorManager.activeEditor === targetEditor) {
  33693. EditorManager.activeEditor = editors.length > 0 ? editors[0] : null
  33694. }
  33695. if (EditorManager.focusedEditor === targetEditor) {
  33696. EditorManager.focusedEditor = null
  33697. }
  33698. return oldEditors.length !== editors.length
  33699. }
  33700. var purgeDestroyedEditor = function (editor) {
  33701. if (
  33702. editor &&
  33703. editor.initialized &&
  33704. !(editor.getContainer() || editor.getBody()).parentNode
  33705. ) {
  33706. removeEditorFromList(editor)
  33707. editor.unbindAllNativeEvents()
  33708. editor.destroy(true)
  33709. editor.removed = true
  33710. editor = null
  33711. }
  33712. return editor
  33713. }
  33714. var isQuirksMode = document.compatMode !== 'CSS1Compat'
  33715. var EditorManager = __assign(__assign({}, Observable), {
  33716. baseURI: null,
  33717. baseURL: null,
  33718. defaultSettings: {},
  33719. documentBaseURL: null,
  33720. suffix: null,
  33721. $: DomQuery,
  33722. majorVersion: '5',
  33723. minorVersion: '10.2',
  33724. releaseDate: '2021-11-17',
  33725. editors: legacyEditors,
  33726. i18n: I18n,
  33727. activeEditor: null,
  33728. focusedEditor: null,
  33729. settings: {},
  33730. setup: function () {
  33731. var self = this
  33732. var baseURL,
  33733. documentBaseURL,
  33734. suffix = ''
  33735. documentBaseURL = URI.getDocumentBaseUrl(document.location)
  33736. if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) {
  33737. documentBaseURL = documentBaseURL
  33738. .replace(/[\?#].*$/, '')
  33739. .replace(/[\/\\][^\/]+$/, '')
  33740. if (!/[\/\\]$/.test(documentBaseURL)) {
  33741. documentBaseURL += '/'
  33742. }
  33743. }
  33744. var preInit = window.tinymce || window.tinyMCEPreInit
  33745. if (preInit) {
  33746. baseURL = preInit.base || preInit.baseURL
  33747. suffix = preInit.suffix
  33748. } else {
  33749. var scripts = document.getElementsByTagName('script')
  33750. for (var i = 0; i < scripts.length; i++) {
  33751. var src = scripts[i].src || ''
  33752. if (src === '') {
  33753. continue
  33754. }
  33755. var srcScript = src.substring(src.lastIndexOf('/'))
  33756. if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
  33757. if (srcScript.indexOf('.min') !== -1) {
  33758. suffix = '.min'
  33759. }
  33760. baseURL = src.substring(0, src.lastIndexOf('/'))
  33761. break
  33762. }
  33763. }
  33764. if (!baseURL && document.currentScript) {
  33765. var src = document.currentScript.src
  33766. if (src.indexOf('.min') !== -1) {
  33767. suffix = '.min'
  33768. }
  33769. baseURL = src.substring(0, src.lastIndexOf('/'))
  33770. }
  33771. }
  33772. self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL)
  33773. self.documentBaseURL = documentBaseURL
  33774. self.baseURI = new URI(self.baseURL)
  33775. self.suffix = suffix
  33776. setup$l(self)
  33777. },
  33778. overrideDefaults: function (defaultSettings) {
  33779. var baseUrl = defaultSettings.base_url
  33780. if (baseUrl) {
  33781. this._setBaseUrl(baseUrl)
  33782. }
  33783. var suffix = defaultSettings.suffix
  33784. if (defaultSettings.suffix) {
  33785. this.suffix = suffix
  33786. }
  33787. this.defaultSettings = defaultSettings
  33788. var pluginBaseUrls = defaultSettings.plugin_base_urls
  33789. if (pluginBaseUrls !== undefined) {
  33790. each$j(pluginBaseUrls, function (pluginBaseUrl, pluginName) {
  33791. AddOnManager.PluginManager.urls[pluginName] = pluginBaseUrl
  33792. })
  33793. }
  33794. },
  33795. init: function (settings) {
  33796. var self = this
  33797. var result
  33798. var invalidInlineTargets = Tools.makeMap(
  33799. 'area base basefont br col frame hr img input isindex link meta param embed source wbr track ' +
  33800. 'colgroup option table tbody tfoot thead tr th td script noscript style textarea video audio iframe object menu',
  33801. ' '
  33802. )
  33803. var isInvalidInlineTarget = function (settings, elm) {
  33804. return (
  33805. settings.inline && elm.tagName.toLowerCase() in invalidInlineTargets
  33806. )
  33807. }
  33808. var createId = function (elm) {
  33809. var id = elm.id
  33810. if (!id) {
  33811. id = get$9(elm, 'name')
  33812. .filter(function (name) {
  33813. return !DOM.get(name)
  33814. })
  33815. .getOrThunk(DOM.uniqueId)
  33816. elm.setAttribute('id', id)
  33817. }
  33818. return id
  33819. }
  33820. var execCallback = function (name) {
  33821. var callback = settings[name]
  33822. if (!callback) {
  33823. return
  33824. }
  33825. return callback.apply(self, [])
  33826. }
  33827. var hasClass = function (elm, className) {
  33828. return className.constructor === RegExp
  33829. ? className.test(elm.className)
  33830. : DOM.hasClass(elm, className)
  33831. }
  33832. var findTargets = function (settings) {
  33833. var targets = []
  33834. if (Env.browser.isIE() && Env.browser.version.major < 11) {
  33835. initError(
  33836. 'TinyMCE does not support the browser you are using. For a list of supported' +
  33837. ' browsers please see: https://www.tinymce.com/docs/get-started/system-requirements/'
  33838. )
  33839. return []
  33840. } else if (isQuirksMode) {
  33841. initError(
  33842. 'Failed to initialize the editor as the document is not in standards mode. ' +
  33843. 'TinyMCE requires standards mode.'
  33844. )
  33845. return []
  33846. }
  33847. if (settings.types) {
  33848. each$1(settings.types, function (type) {
  33849. targets = targets.concat(DOM.select(type.selector))
  33850. })
  33851. return targets
  33852. } else if (settings.selector) {
  33853. return DOM.select(settings.selector)
  33854. } else if (settings.target) {
  33855. return [settings.target]
  33856. }
  33857. switch (settings.mode) {
  33858. case 'exact':
  33859. var l = settings.elements || ''
  33860. if (l.length > 0) {
  33861. each$1(explode(l), function (id) {
  33862. var elm = DOM.get(id)
  33863. if (elm) {
  33864. targets.push(elm)
  33865. } else {
  33866. each$1(document.forms, function (f) {
  33867. each$1(f.elements, function (e) {
  33868. if (e.name === id) {
  33869. id = 'mce_editor_' + instanceCounter++
  33870. DOM.setAttrib(e, 'id', id)
  33871. targets.push(e)
  33872. }
  33873. })
  33874. })
  33875. }
  33876. })
  33877. }
  33878. break
  33879. case 'textareas':
  33880. case 'specific_textareas':
  33881. each$1(DOM.select('textarea'), function (elm) {
  33882. if (
  33883. settings.editor_deselector &&
  33884. hasClass(elm, settings.editor_deselector)
  33885. ) {
  33886. return
  33887. }
  33888. if (
  33889. !settings.editor_selector ||
  33890. hasClass(elm, settings.editor_selector)
  33891. ) {
  33892. targets.push(elm)
  33893. }
  33894. })
  33895. break
  33896. }
  33897. return targets
  33898. }
  33899. var provideResults = function (editors) {
  33900. result = editors
  33901. }
  33902. var initEditors = function () {
  33903. var initCount = 0
  33904. var editors = []
  33905. var targets
  33906. var createEditor = function (id, settings, targetElm) {
  33907. var editor = new Editor(id, settings, self)
  33908. editors.push(editor)
  33909. editor.on('init', function () {
  33910. if (++initCount === targets.length) {
  33911. provideResults(editors)
  33912. }
  33913. })
  33914. editor.targetElm = editor.targetElm || targetElm
  33915. editor.render()
  33916. }
  33917. DOM.unbind(window, 'ready', initEditors)
  33918. execCallback('onpageload')
  33919. targets = DomQuery.unique(findTargets(settings))
  33920. if (settings.types) {
  33921. each$1(settings.types, function (type) {
  33922. Tools.each(targets, function (elm) {
  33923. if (DOM.is(elm, type.selector)) {
  33924. createEditor(createId(elm), extend$2({}, settings, type), elm)
  33925. return false
  33926. }
  33927. return true
  33928. })
  33929. })
  33930. return
  33931. }
  33932. Tools.each(targets, function (elm) {
  33933. purgeDestroyedEditor(self.get(elm.id))
  33934. })
  33935. targets = Tools.grep(targets, function (elm) {
  33936. return !self.get(elm.id)
  33937. })
  33938. if (targets.length === 0) {
  33939. provideResults([])
  33940. } else {
  33941. each$1(targets, function (elm) {
  33942. if (isInvalidInlineTarget(settings, elm)) {
  33943. initError(
  33944. 'Could not initialize inline editor on invalid inline target element',
  33945. elm
  33946. )
  33947. } else {
  33948. createEditor(createId(elm), settings, elm)
  33949. }
  33950. })
  33951. }
  33952. }
  33953. self.settings = settings
  33954. DOM.bind(window, 'ready', initEditors)
  33955. return new promiseObj(function (resolve) {
  33956. if (result) {
  33957. resolve(result)
  33958. } else {
  33959. provideResults = function (editors) {
  33960. resolve(editors)
  33961. }
  33962. }
  33963. })
  33964. },
  33965. get: function (id) {
  33966. if (arguments.length === 0) {
  33967. return editors.slice(0)
  33968. } else if (isString$1(id)) {
  33969. return find$3(editors, function (editor) {
  33970. return editor.id === id
  33971. }).getOr(null)
  33972. } else if (isNumber(id)) {
  33973. return editors[id] ? editors[id] : null
  33974. } else {
  33975. return null
  33976. }
  33977. },
  33978. add: function (editor) {
  33979. var self = this
  33980. var existingEditor = legacyEditors[editor.id]
  33981. if (existingEditor === editor) {
  33982. return editor
  33983. }
  33984. if (self.get(editor.id) === null) {
  33985. if (isValidLegacyKey(editor.id)) {
  33986. legacyEditors[editor.id] = editor
  33987. }
  33988. legacyEditors.push(editor)
  33989. editors.push(editor)
  33990. }
  33991. toggleGlobalEvents(true)
  33992. self.activeEditor = editor
  33993. self.fire('AddEditor', { editor: editor })
  33994. if (!beforeUnloadDelegate) {
  33995. beforeUnloadDelegate = function (e) {
  33996. var event = self.fire('BeforeUnload')
  33997. if (event.returnValue) {
  33998. e.preventDefault()
  33999. e.returnValue = event.returnValue
  34000. return event.returnValue
  34001. }
  34002. }
  34003. window.addEventListener('beforeunload', beforeUnloadDelegate)
  34004. }
  34005. return editor
  34006. },
  34007. createEditor: function (id, settings) {
  34008. return this.add(new Editor(id, settings, this))
  34009. },
  34010. remove: function (selector) {
  34011. var self = this
  34012. var i, editor
  34013. if (!selector) {
  34014. for (i = editors.length - 1; i >= 0; i--) {
  34015. self.remove(editors[i])
  34016. }
  34017. return
  34018. }
  34019. if (isString$1(selector)) {
  34020. each$1(DOM.select(selector), function (elm) {
  34021. editor = self.get(elm.id)
  34022. if (editor) {
  34023. self.remove(editor)
  34024. }
  34025. })
  34026. return
  34027. }
  34028. editor = selector
  34029. if (isNull(self.get(editor.id))) {
  34030. return null
  34031. }
  34032. if (removeEditorFromList(editor)) {
  34033. self.fire('RemoveEditor', { editor: editor })
  34034. }
  34035. if (editors.length === 0) {
  34036. window.removeEventListener('beforeunload', beforeUnloadDelegate)
  34037. }
  34038. editor.remove()
  34039. toggleGlobalEvents(editors.length > 0)
  34040. return editor
  34041. },
  34042. execCommand: function (cmd, ui, value) {
  34043. var self = this,
  34044. editor = self.get(value)
  34045. switch (cmd) {
  34046. case 'mceAddEditor':
  34047. if (!self.get(value)) {
  34048. new Editor(value, self.settings, self).render()
  34049. }
  34050. return true
  34051. case 'mceRemoveEditor':
  34052. if (editor) {
  34053. editor.remove()
  34054. }
  34055. return true
  34056. case 'mceToggleEditor':
  34057. if (!editor) {
  34058. self.execCommand('mceAddEditor', false, value)
  34059. return true
  34060. }
  34061. if (editor.isHidden()) {
  34062. editor.show()
  34063. } else {
  34064. editor.hide()
  34065. }
  34066. return true
  34067. }
  34068. if (self.activeEditor) {
  34069. return self.activeEditor.execCommand(cmd, ui, value)
  34070. }
  34071. return false
  34072. },
  34073. triggerSave: function () {
  34074. each$1(editors, function (editor) {
  34075. editor.save()
  34076. })
  34077. },
  34078. addI18n: function (code, items) {
  34079. I18n.add(code, items)
  34080. },
  34081. translate: function (text) {
  34082. return I18n.translate(text)
  34083. },
  34084. setActive: function (editor) {
  34085. var activeEditor = this.activeEditor
  34086. if (this.activeEditor !== editor) {
  34087. if (activeEditor) {
  34088. activeEditor.fire('deactivate', { relatedTarget: editor })
  34089. }
  34090. editor.fire('activate', { relatedTarget: activeEditor })
  34091. }
  34092. this.activeEditor = editor
  34093. },
  34094. _setBaseUrl: function (baseUrl) {
  34095. this.baseURL = new URI(this.documentBaseURL).toAbsolute(
  34096. baseUrl.replace(/\/+$/, '')
  34097. )
  34098. this.baseURI = new URI(this.baseURL)
  34099. },
  34100. })
  34101. EditorManager.setup()
  34102. var min$1 = Math.min,
  34103. max$1 = Math.max,
  34104. round$1 = Math.round
  34105. var relativePosition = function (rect, targetRect, rel) {
  34106. var x = targetRect.x
  34107. var y = targetRect.y
  34108. var w = rect.w
  34109. var h = rect.h
  34110. var targetW = targetRect.w
  34111. var targetH = targetRect.h
  34112. var relChars = (rel || '').split('')
  34113. if (relChars[0] === 'b') {
  34114. y += targetH
  34115. }
  34116. if (relChars[1] === 'r') {
  34117. x += targetW
  34118. }
  34119. if (relChars[0] === 'c') {
  34120. y += round$1(targetH / 2)
  34121. }
  34122. if (relChars[1] === 'c') {
  34123. x += round$1(targetW / 2)
  34124. }
  34125. if (relChars[3] === 'b') {
  34126. y -= h
  34127. }
  34128. if (relChars[4] === 'r') {
  34129. x -= w
  34130. }
  34131. if (relChars[3] === 'c') {
  34132. y -= round$1(h / 2)
  34133. }
  34134. if (relChars[4] === 'c') {
  34135. x -= round$1(w / 2)
  34136. }
  34137. return create$2(x, y, w, h)
  34138. }
  34139. var findBestRelativePosition = function (
  34140. rect,
  34141. targetRect,
  34142. constrainRect,
  34143. rels
  34144. ) {
  34145. var pos, i
  34146. for (i = 0; i < rels.length; i++) {
  34147. pos = relativePosition(rect, targetRect, rels[i])
  34148. if (
  34149. pos.x >= constrainRect.x &&
  34150. pos.x + pos.w <= constrainRect.w + constrainRect.x &&
  34151. pos.y >= constrainRect.y &&
  34152. pos.y + pos.h <= constrainRect.h + constrainRect.y
  34153. ) {
  34154. return rels[i]
  34155. }
  34156. }
  34157. return null
  34158. }
  34159. var inflate = function (rect, w, h) {
  34160. return create$2(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2)
  34161. }
  34162. var intersect = function (rect, cropRect) {
  34163. var x1 = max$1(rect.x, cropRect.x)
  34164. var y1 = max$1(rect.y, cropRect.y)
  34165. var x2 = min$1(rect.x + rect.w, cropRect.x + cropRect.w)
  34166. var y2 = min$1(rect.y + rect.h, cropRect.y + cropRect.h)
  34167. if (x2 - x1 < 0 || y2 - y1 < 0) {
  34168. return null
  34169. }
  34170. return create$2(x1, y1, x2 - x1, y2 - y1)
  34171. }
  34172. var clamp = function (rect, clampRect, fixedSize) {
  34173. var x1 = rect.x
  34174. var y1 = rect.y
  34175. var x2 = rect.x + rect.w
  34176. var y2 = rect.y + rect.h
  34177. var cx2 = clampRect.x + clampRect.w
  34178. var cy2 = clampRect.y + clampRect.h
  34179. var underflowX1 = max$1(0, clampRect.x - x1)
  34180. var underflowY1 = max$1(0, clampRect.y - y1)
  34181. var overflowX2 = max$1(0, x2 - cx2)
  34182. var overflowY2 = max$1(0, y2 - cy2)
  34183. x1 += underflowX1
  34184. y1 += underflowY1
  34185. if (fixedSize) {
  34186. x2 += underflowX1
  34187. y2 += underflowY1
  34188. x1 -= overflowX2
  34189. y1 -= overflowY2
  34190. }
  34191. x2 -= overflowX2
  34192. y2 -= overflowY2
  34193. return create$2(x1, y1, x2 - x1, y2 - y1)
  34194. }
  34195. var create$2 = function (x, y, w, h) {
  34196. return {
  34197. x: x,
  34198. y: y,
  34199. w: w,
  34200. h: h,
  34201. }
  34202. }
  34203. var fromClientRect = function (clientRect) {
  34204. return create$2(
  34205. clientRect.left,
  34206. clientRect.top,
  34207. clientRect.width,
  34208. clientRect.height
  34209. )
  34210. }
  34211. var Rect = {
  34212. inflate: inflate,
  34213. relativePosition: relativePosition,
  34214. findBestRelativePosition: findBestRelativePosition,
  34215. intersect: intersect,
  34216. clamp: clamp,
  34217. create: create$2,
  34218. fromClientRect: fromClientRect,
  34219. }
  34220. var awaiter = function (resolveCb, rejectCb, timeout) {
  34221. if (timeout === void 0) {
  34222. timeout = 1000
  34223. }
  34224. var done = false
  34225. var timer = null
  34226. var complete = function (completer) {
  34227. return function () {
  34228. var args = []
  34229. for (var _i = 0; _i < arguments.length; _i++) {
  34230. args[_i] = arguments[_i]
  34231. }
  34232. if (!done) {
  34233. done = true
  34234. if (timer !== null) {
  34235. clearTimeout(timer)
  34236. timer = null
  34237. }
  34238. completer.apply(null, args)
  34239. }
  34240. }
  34241. }
  34242. var resolve = complete(resolveCb)
  34243. var reject = complete(rejectCb)
  34244. var start = function () {
  34245. var args = []
  34246. for (var _i = 0; _i < arguments.length; _i++) {
  34247. args[_i] = arguments[_i]
  34248. }
  34249. if (!done && timer === null) {
  34250. timer = setTimeout(function () {
  34251. return reject.apply(null, args)
  34252. }, timeout)
  34253. }
  34254. }
  34255. return {
  34256. start: start,
  34257. resolve: resolve,
  34258. reject: reject,
  34259. }
  34260. }
  34261. var create$1 = function () {
  34262. var tasks = {}
  34263. var resultFns = {}
  34264. var load = function (id, url) {
  34265. var loadErrMsg = 'Script at URL "' + url + '" failed to load'
  34266. var runErrMsg =
  34267. 'Script at URL "' +
  34268. url +
  34269. '" did not call `tinymce.Resource.add(\'' +
  34270. id +
  34271. "', data)` within 1 second"
  34272. if (tasks[id] !== undefined) {
  34273. return tasks[id]
  34274. } else {
  34275. var task = new promiseObj(function (resolve, reject) {
  34276. var waiter = awaiter(resolve, reject)
  34277. resultFns[id] = waiter.resolve
  34278. ScriptLoader.ScriptLoader.loadScript(
  34279. url,
  34280. function () {
  34281. return waiter.start(runErrMsg)
  34282. },
  34283. function () {
  34284. return waiter.reject(loadErrMsg)
  34285. }
  34286. )
  34287. })
  34288. tasks[id] = task
  34289. return task
  34290. }
  34291. }
  34292. var add = function (id, data) {
  34293. if (resultFns[id] !== undefined) {
  34294. resultFns[id](data)
  34295. delete resultFns[id]
  34296. }
  34297. tasks[id] = promiseObj.resolve(data)
  34298. }
  34299. return {
  34300. load: load,
  34301. add: add,
  34302. }
  34303. }
  34304. var Resource = create$1()
  34305. var each = Tools.each,
  34306. extend$1 = Tools.extend
  34307. var extendClass, initializing
  34308. var Class = function () {}
  34309. Class.extend = extendClass = function (props) {
  34310. var self = this
  34311. var _super = self.prototype
  34312. var Class = function () {
  34313. var i, mixins, mixin
  34314. var self = this
  34315. if (!initializing) {
  34316. if (self.init) {
  34317. self.init.apply(self, arguments)
  34318. }
  34319. mixins = self.Mixins
  34320. if (mixins) {
  34321. i = mixins.length
  34322. while (i--) {
  34323. mixin = mixins[i]
  34324. if (mixin.init) {
  34325. mixin.init.apply(self, arguments)
  34326. }
  34327. }
  34328. }
  34329. }
  34330. }
  34331. var dummy = function () {
  34332. return this
  34333. }
  34334. var createMethod = function (name, fn) {
  34335. return function () {
  34336. var self = this
  34337. var tmp = self._super
  34338. self._super = _super[name]
  34339. var ret = fn.apply(self, arguments)
  34340. self._super = tmp
  34341. return ret
  34342. }
  34343. }
  34344. initializing = true
  34345. var prototype = new self()
  34346. initializing = false
  34347. if (props.Mixins) {
  34348. each(props.Mixins, function (mixin) {
  34349. for (var name_1 in mixin) {
  34350. if (name_1 !== 'init') {
  34351. props[name_1] = mixin[name_1]
  34352. }
  34353. }
  34354. })
  34355. if (_super.Mixins) {
  34356. props.Mixins = _super.Mixins.concat(props.Mixins)
  34357. }
  34358. }
  34359. if (props.Methods) {
  34360. each(props.Methods.split(','), function (name) {
  34361. props[name] = dummy
  34362. })
  34363. }
  34364. if (props.Properties) {
  34365. each(props.Properties.split(','), function (name) {
  34366. var fieldName = '_' + name
  34367. props[name] = function (value) {
  34368. var self = this
  34369. if (value !== undefined) {
  34370. self[fieldName] = value
  34371. return self
  34372. }
  34373. return self[fieldName]
  34374. }
  34375. })
  34376. }
  34377. if (props.Statics) {
  34378. each(props.Statics, function (func, name) {
  34379. Class[name] = func
  34380. })
  34381. }
  34382. if (props.Defaults && _super.Defaults) {
  34383. props.Defaults = extend$1({}, _super.Defaults, props.Defaults)
  34384. }
  34385. each$j(props, function (member, name) {
  34386. if (typeof member === 'function' && _super[name]) {
  34387. prototype[name] = createMethod(name, member)
  34388. } else {
  34389. prototype[name] = member
  34390. }
  34391. })
  34392. Class.prototype = prototype
  34393. Class.constructor = Class
  34394. Class.extend = extendClass
  34395. return Class
  34396. }
  34397. var min = Math.min,
  34398. max = Math.max,
  34399. round = Math.round
  34400. var Color = function (value) {
  34401. var self = {}
  34402. var r = 0,
  34403. g = 0,
  34404. b = 0
  34405. var rgb2hsv = function (r, g, b) {
  34406. var h, s, v
  34407. h = 0
  34408. s = 0
  34409. v = 0
  34410. r = r / 255
  34411. g = g / 255
  34412. b = b / 255
  34413. var minRGB = min(r, min(g, b))
  34414. var maxRGB = max(r, max(g, b))
  34415. if (minRGB === maxRGB) {
  34416. v = minRGB
  34417. return {
  34418. h: 0,
  34419. s: 0,
  34420. v: v * 100,
  34421. }
  34422. }
  34423. var d = r === minRGB ? g - b : b === minRGB ? r - g : b - r
  34424. h = r === minRGB ? 3 : b === minRGB ? 1 : 5
  34425. h = 60 * (h - d / (maxRGB - minRGB))
  34426. s = (maxRGB - minRGB) / maxRGB
  34427. v = maxRGB
  34428. return {
  34429. h: round(h),
  34430. s: round(s * 100),
  34431. v: round(v * 100),
  34432. }
  34433. }
  34434. var hsvToRgb = function (hue, saturation, brightness) {
  34435. hue = (parseInt(hue, 10) || 0) % 360
  34436. saturation = parseInt(saturation, 10) / 100
  34437. brightness = parseInt(brightness, 10) / 100
  34438. saturation = max(0, min(saturation, 1))
  34439. brightness = max(0, min(brightness, 1))
  34440. if (saturation === 0) {
  34441. r = g = b = round(255 * brightness)
  34442. return
  34443. }
  34444. var side = hue / 60
  34445. var chroma = brightness * saturation
  34446. var x = chroma * (1 - Math.abs((side % 2) - 1))
  34447. var match = brightness - chroma
  34448. switch (Math.floor(side)) {
  34449. case 0:
  34450. r = chroma
  34451. g = x
  34452. b = 0
  34453. break
  34454. case 1:
  34455. r = x
  34456. g = chroma
  34457. b = 0
  34458. break
  34459. case 2:
  34460. r = 0
  34461. g = chroma
  34462. b = x
  34463. break
  34464. case 3:
  34465. r = 0
  34466. g = x
  34467. b = chroma
  34468. break
  34469. case 4:
  34470. r = x
  34471. g = 0
  34472. b = chroma
  34473. break
  34474. case 5:
  34475. r = chroma
  34476. g = 0
  34477. b = x
  34478. break
  34479. default:
  34480. r = g = b = 0
  34481. }
  34482. r = round(255 * (r + match))
  34483. g = round(255 * (g + match))
  34484. b = round(255 * (b + match))
  34485. }
  34486. var toHex = function () {
  34487. var hex = function (val) {
  34488. val = parseInt(val, 10).toString(16)
  34489. return val.length > 1 ? val : '0' + val
  34490. }
  34491. return '#' + hex(r) + hex(g) + hex(b)
  34492. }
  34493. var toRgb = function () {
  34494. return {
  34495. r: r,
  34496. g: g,
  34497. b: b,
  34498. }
  34499. }
  34500. var toHsv = function () {
  34501. return rgb2hsv(r, g, b)
  34502. }
  34503. var parse = function (value) {
  34504. var matches
  34505. if (typeof value === 'object') {
  34506. if ('r' in value) {
  34507. r = value.r
  34508. g = value.g
  34509. b = value.b
  34510. } else if ('v' in value) {
  34511. hsvToRgb(value.h, value.s, value.v)
  34512. }
  34513. } else {
  34514. if (
  34515. (matches =
  34516. /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(
  34517. value
  34518. ))
  34519. ) {
  34520. r = parseInt(matches[1], 10)
  34521. g = parseInt(matches[2], 10)
  34522. b = parseInt(matches[3], 10)
  34523. } else if (
  34524. (matches = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value))
  34525. ) {
  34526. r = parseInt(matches[1], 16)
  34527. g = parseInt(matches[2], 16)
  34528. b = parseInt(matches[3], 16)
  34529. } else if ((matches = /#([0-F])([0-F])([0-F])/gi.exec(value))) {
  34530. r = parseInt(matches[1] + matches[1], 16)
  34531. g = parseInt(matches[2] + matches[2], 16)
  34532. b = parseInt(matches[3] + matches[3], 16)
  34533. }
  34534. }
  34535. r = r < 0 ? 0 : r > 255 ? 255 : r
  34536. g = g < 0 ? 0 : g > 255 ? 255 : g
  34537. b = b < 0 ? 0 : b > 255 ? 255 : b
  34538. return self
  34539. }
  34540. if (value) {
  34541. parse(value)
  34542. }
  34543. self.toRgb = toRgb
  34544. self.toHsv = toHsv
  34545. self.toHex = toHex
  34546. self.parse = parse
  34547. return self
  34548. }
  34549. var serialize = function (obj) {
  34550. var data = JSON.stringify(obj)
  34551. if (!isString$1(data)) {
  34552. return data
  34553. }
  34554. return data.replace(/[\u0080-\uFFFF]/g, function (match) {
  34555. var hexCode = match.charCodeAt(0).toString(16)
  34556. return '\\u' + '0000'.substring(hexCode.length) + hexCode
  34557. })
  34558. }
  34559. var JSONUtils = {
  34560. serialize: serialize,
  34561. parse: function (text) {
  34562. try {
  34563. return JSON.parse(text)
  34564. } catch (ex) {}
  34565. },
  34566. }
  34567. var JSONP = {
  34568. callbacks: {},
  34569. count: 0,
  34570. send: function (settings) {
  34571. var self = this,
  34572. dom = DOMUtils.DOM,
  34573. count = settings.count !== undefined ? settings.count : self.count
  34574. var id = 'tinymce_jsonp_' + count
  34575. self.callbacks[count] = function (json) {
  34576. dom.remove(id)
  34577. delete self.callbacks[count]
  34578. settings.callback(json)
  34579. }
  34580. dom.add(dom.doc.body, 'script', {
  34581. id: id,
  34582. src: settings.url,
  34583. type: 'text/javascript',
  34584. })
  34585. self.count++
  34586. },
  34587. }
  34588. var XHR = __assign(__assign({}, Observable), {
  34589. send: function (settings) {
  34590. var xhr,
  34591. count = 0
  34592. var ready = function () {
  34593. if (!settings.async || xhr.readyState === 4 || count++ > 10000) {
  34594. if (settings.success && count < 10000 && xhr.status === 200) {
  34595. settings.success.call(
  34596. settings.success_scope,
  34597. '' + xhr.responseText,
  34598. xhr,
  34599. settings
  34600. )
  34601. } else if (settings.error) {
  34602. settings.error.call(
  34603. settings.error_scope,
  34604. count > 10000 ? 'TIMED_OUT' : 'GENERAL',
  34605. xhr,
  34606. settings
  34607. )
  34608. }
  34609. xhr = null
  34610. } else {
  34611. Delay.setTimeout(ready, 10)
  34612. }
  34613. }
  34614. settings.scope = settings.scope || this
  34615. settings.success_scope = settings.success_scope || settings.scope
  34616. settings.error_scope = settings.error_scope || settings.scope
  34617. settings.async = settings.async !== false
  34618. settings.data = settings.data || ''
  34619. XHR.fire('beforeInitialize', { settings: settings })
  34620. xhr = new XMLHttpRequest()
  34621. if (xhr.overrideMimeType) {
  34622. xhr.overrideMimeType(settings.content_type)
  34623. }
  34624. xhr.open(
  34625. settings.type || (settings.data ? 'POST' : 'GET'),
  34626. settings.url,
  34627. settings.async
  34628. )
  34629. if (settings.crossDomain) {
  34630. xhr.withCredentials = true
  34631. }
  34632. if (settings.content_type) {
  34633. xhr.setRequestHeader('Content-Type', settings.content_type)
  34634. }
  34635. if (settings.requestheaders) {
  34636. Tools.each(settings.requestheaders, function (header) {
  34637. xhr.setRequestHeader(header.key, header.value)
  34638. })
  34639. }
  34640. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
  34641. xhr = XHR.fire('beforeSend', {
  34642. xhr: xhr,
  34643. settings: settings,
  34644. }).xhr
  34645. xhr.send(settings.data)
  34646. if (!settings.async) {
  34647. return ready()
  34648. }
  34649. Delay.setTimeout(ready, 10)
  34650. },
  34651. })
  34652. var extend = Tools.extend
  34653. var JSONRequest = (function () {
  34654. function JSONRequest(settings) {
  34655. this.settings = extend({}, settings)
  34656. this.count = 0
  34657. }
  34658. JSONRequest.sendRPC = function (o) {
  34659. return new JSONRequest().send(o)
  34660. }
  34661. JSONRequest.prototype.send = function (args) {
  34662. var ecb = args.error,
  34663. scb = args.success
  34664. var xhrArgs = extend(this.settings, args)
  34665. xhrArgs.success = function (c, x) {
  34666. c = JSONUtils.parse(c)
  34667. if (typeof c === 'undefined') {
  34668. c = { error: 'JSON Parse error.' }
  34669. }
  34670. if (c.error) {
  34671. ecb.call(xhrArgs.error_scope || xhrArgs.scope, c.error, x)
  34672. } else {
  34673. scb.call(xhrArgs.success_scope || xhrArgs.scope, c.result)
  34674. }
  34675. }
  34676. xhrArgs.error = function (ty, x) {
  34677. if (ecb) {
  34678. ecb.call(xhrArgs.error_scope || xhrArgs.scope, ty, x)
  34679. }
  34680. }
  34681. xhrArgs.data = JSONUtils.serialize({
  34682. id: args.id || 'c' + this.count++,
  34683. method: args.method,
  34684. params: args.params,
  34685. })
  34686. xhrArgs.content_type = 'application/json'
  34687. XHR.send(xhrArgs)
  34688. }
  34689. return JSONRequest
  34690. })()
  34691. var create = function () {
  34692. return (function () {
  34693. var data = {}
  34694. var keys = []
  34695. var storage = {
  34696. getItem: function (key) {
  34697. var item = data[key]
  34698. return item ? item : null
  34699. },
  34700. setItem: function (key, value) {
  34701. keys.push(key)
  34702. data[key] = String(value)
  34703. },
  34704. key: function (index) {
  34705. return keys[index]
  34706. },
  34707. removeItem: function (key) {
  34708. keys = keys.filter(function (k) {
  34709. return k === key
  34710. })
  34711. delete data[key]
  34712. },
  34713. clear: function () {
  34714. keys = []
  34715. data = {}
  34716. },
  34717. length: 0,
  34718. }
  34719. Object.defineProperty(storage, 'length', {
  34720. get: function () {
  34721. return keys.length
  34722. },
  34723. configurable: false,
  34724. enumerable: false,
  34725. })
  34726. return storage
  34727. })()
  34728. }
  34729. var localStorage
  34730. try {
  34731. var test = '__storage_test__'
  34732. localStorage = window.localStorage
  34733. localStorage.setItem(test, test)
  34734. localStorage.removeItem(test)
  34735. } catch (e) {
  34736. localStorage = create()
  34737. }
  34738. var LocalStorage = localStorage
  34739. var publicApi = {
  34740. geom: { Rect: Rect },
  34741. util: {
  34742. Promise: promiseObj,
  34743. Delay: Delay,
  34744. Tools: Tools,
  34745. VK: VK,
  34746. URI: URI,
  34747. Class: Class,
  34748. EventDispatcher: EventDispatcher,
  34749. Observable: Observable,
  34750. I18n: I18n,
  34751. XHR: XHR,
  34752. JSON: JSONUtils,
  34753. JSONRequest: JSONRequest,
  34754. JSONP: JSONP,
  34755. LocalStorage: LocalStorage,
  34756. Color: Color,
  34757. ImageUploader: ImageUploader,
  34758. },
  34759. dom: {
  34760. EventUtils: EventUtils,
  34761. Sizzle: Sizzle,
  34762. DomQuery: DomQuery,
  34763. TreeWalker: DomTreeWalker,
  34764. TextSeeker: TextSeeker,
  34765. DOMUtils: DOMUtils,
  34766. ScriptLoader: ScriptLoader,
  34767. RangeUtils: RangeUtils,
  34768. Serializer: DomSerializer,
  34769. StyleSheetLoader: StyleSheetLoader,
  34770. ControlSelection: ControlSelection,
  34771. BookmarkManager: BookmarkManager,
  34772. Selection: EditorSelection,
  34773. Event: EventUtils.Event,
  34774. },
  34775. html: {
  34776. Styles: Styles,
  34777. Entities: Entities,
  34778. Node: AstNode,
  34779. Schema: Schema,
  34780. SaxParser: SaxParser,
  34781. DomParser: DomParser,
  34782. Writer: Writer,
  34783. Serializer: HtmlSerializer,
  34784. },
  34785. Env: Env,
  34786. AddOnManager: AddOnManager,
  34787. Annotator: Annotator,
  34788. Formatter: Formatter,
  34789. UndoManager: UndoManager,
  34790. EditorCommands: EditorCommands,
  34791. WindowManager: WindowManager,
  34792. NotificationManager: NotificationManager,
  34793. EditorObservable: EditorObservable,
  34794. Shortcuts: Shortcuts,
  34795. Editor: Editor,
  34796. FocusManager: FocusManager,
  34797. EditorManager: EditorManager,
  34798. DOM: DOMUtils.DOM,
  34799. ScriptLoader: ScriptLoader.ScriptLoader,
  34800. PluginManager: PluginManager,
  34801. ThemeManager: ThemeManager,
  34802. IconManager: IconManager,
  34803. Resource: Resource,
  34804. trim: Tools.trim,
  34805. isArray: Tools.isArray,
  34806. is: Tools.is,
  34807. toArray: Tools.toArray,
  34808. makeMap: Tools.makeMap,
  34809. each: Tools.each,
  34810. map: Tools.map,
  34811. grep: Tools.grep,
  34812. inArray: Tools.inArray,
  34813. extend: Tools.extend,
  34814. create: Tools.create,
  34815. walk: Tools.walk,
  34816. createNS: Tools.createNS,
  34817. resolve: Tools.resolve,
  34818. explode: Tools.explode,
  34819. _addCacheSuffix: Tools._addCacheSuffix,
  34820. isOpera: Env.opera,
  34821. isWebKit: Env.webkit,
  34822. isIE: Env.ie,
  34823. isGecko: Env.gecko,
  34824. isMac: Env.mac,
  34825. }
  34826. var tinymce = Tools.extend(EditorManager, publicApi)
  34827. var exportToModuleLoaders = function (tinymce) {
  34828. if (typeof module === 'object') {
  34829. try {
  34830. module.exports = tinymce
  34831. } catch (_) {}
  34832. }
  34833. }
  34834. var exportToWindowGlobal = function (tinymce) {
  34835. window.tinymce = tinymce
  34836. window.tinyMCE = tinymce
  34837. }
  34838. exportToWindowGlobal(tinymce)
  34839. exportToModuleLoaders(tinymce)
  34840. })()