tinymce.js 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250
  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.1.0 (2019-10-17)
  8. */
  9. (function (domGlobals) {
  10. 'use strict';
  11. var noop = function () {
  12. };
  13. var compose = function (fa, fb) {
  14. return function () {
  15. var args = [];
  16. for (var _i = 0; _i < arguments.length; _i++) {
  17. args[_i] = arguments[_i];
  18. }
  19. return fa(fb.apply(null, args));
  20. };
  21. };
  22. var constant = function (value) {
  23. return function () {
  24. return value;
  25. };
  26. };
  27. var identity = function (x) {
  28. return x;
  29. };
  30. function curry(fn) {
  31. var initialArgs = [];
  32. for (var _i = 1; _i < arguments.length; _i++) {
  33. initialArgs[_i - 1] = arguments[_i];
  34. }
  35. return function () {
  36. var restArgs = [];
  37. for (var _i = 0; _i < arguments.length; _i++) {
  38. restArgs[_i] = arguments[_i];
  39. }
  40. var all = initialArgs.concat(restArgs);
  41. return fn.apply(null, all);
  42. };
  43. }
  44. var not = function (f) {
  45. return function () {
  46. var args = [];
  47. for (var _i = 0; _i < arguments.length; _i++) {
  48. args[_i] = arguments[_i];
  49. }
  50. return !f.apply(null, args);
  51. };
  52. };
  53. var die = function (msg) {
  54. return function () {
  55. throw new Error(msg);
  56. };
  57. };
  58. var never = constant(false);
  59. var always = constant(true);
  60. var none = function () {
  61. return NONE;
  62. };
  63. var NONE = function () {
  64. var eq = function (o) {
  65. return o.isNone();
  66. };
  67. var call = function (thunk) {
  68. return thunk();
  69. };
  70. var id = function (n) {
  71. return n;
  72. };
  73. var me = {
  74. fold: function (n, s) {
  75. return n();
  76. },
  77. is: never,
  78. isSome: never,
  79. isNone: always,
  80. getOr: id,
  81. getOrThunk: call,
  82. getOrDie: function (msg) {
  83. throw new Error(msg || 'error: getOrDie called on none.');
  84. },
  85. getOrNull: constant(null),
  86. getOrUndefined: constant(undefined),
  87. or: id,
  88. orThunk: call,
  89. map: none,
  90. each: noop,
  91. bind: none,
  92. exists: never,
  93. forall: always,
  94. filter: none,
  95. equals: eq,
  96. equals_: eq,
  97. toArray: function () {
  98. return [];
  99. },
  100. toString: constant('none()')
  101. };
  102. if (Object.freeze) {
  103. Object.freeze(me);
  104. }
  105. return me;
  106. }();
  107. var some = function (a) {
  108. var constant_a = constant(a);
  109. var self = function () {
  110. return me;
  111. };
  112. var bind = function (f) {
  113. return f(a);
  114. };
  115. var me = {
  116. fold: function (n, s) {
  117. return s(a);
  118. },
  119. is: function (v) {
  120. return a === v;
  121. },
  122. isSome: always,
  123. isNone: never,
  124. getOr: constant_a,
  125. getOrThunk: constant_a,
  126. getOrDie: constant_a,
  127. getOrNull: constant_a,
  128. getOrUndefined: constant_a,
  129. or: self,
  130. orThunk: self,
  131. map: function (f) {
  132. return some(f(a));
  133. },
  134. each: function (f) {
  135. f(a);
  136. },
  137. bind: bind,
  138. exists: bind,
  139. forall: bind,
  140. filter: function (f) {
  141. return f(a) ? me : NONE;
  142. },
  143. toArray: function () {
  144. return [a];
  145. },
  146. toString: function () {
  147. return 'some(' + a + ')';
  148. },
  149. equals: function (o) {
  150. return o.is(a);
  151. },
  152. equals_: function (o, elementEq) {
  153. return o.fold(never, function (b) {
  154. return elementEq(a, b);
  155. });
  156. }
  157. };
  158. return me;
  159. };
  160. var from = function (value) {
  161. return value === null || value === undefined ? NONE : some(value);
  162. };
  163. var Option = {
  164. some: some,
  165. none: none,
  166. from: from
  167. };
  168. var typeOf = function (x) {
  169. if (x === null) {
  170. return 'null';
  171. }
  172. var t = typeof x;
  173. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  174. return 'array';
  175. }
  176. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  177. return 'string';
  178. }
  179. return t;
  180. };
  181. var isType = function (type) {
  182. return function (value) {
  183. return typeOf(value) === type;
  184. };
  185. };
  186. var isString = isType('string');
  187. var isObject = isType('object');
  188. var isArray = isType('array');
  189. var isNull = isType('null');
  190. var isBoolean = isType('boolean');
  191. var isFunction = isType('function');
  192. var isNumber = isType('number');
  193. var nativeSlice = Array.prototype.slice;
  194. var nativeIndexOf = Array.prototype.indexOf;
  195. var nativePush = Array.prototype.push;
  196. var rawIndexOf = function (ts, t) {
  197. return nativeIndexOf.call(ts, t);
  198. };
  199. var indexOf = function (xs, x) {
  200. var r = rawIndexOf(xs, x);
  201. return r === -1 ? Option.none() : Option.some(r);
  202. };
  203. var contains = function (xs, x) {
  204. return rawIndexOf(xs, x) > -1;
  205. };
  206. var exists = function (xs, pred) {
  207. for (var i = 0, len = xs.length; i < len; i++) {
  208. var x = xs[i];
  209. if (pred(x, i)) {
  210. return true;
  211. }
  212. }
  213. return false;
  214. };
  215. var map = function (xs, f) {
  216. var len = xs.length;
  217. var r = new Array(len);
  218. for (var i = 0; i < len; i++) {
  219. var x = xs[i];
  220. r[i] = f(x, i);
  221. }
  222. return r;
  223. };
  224. var each = function (xs, f) {
  225. for (var i = 0, len = xs.length; i < len; i++) {
  226. var x = xs[i];
  227. f(x, i);
  228. }
  229. };
  230. var eachr = function (xs, f) {
  231. for (var i = xs.length - 1; i >= 0; i--) {
  232. var x = xs[i];
  233. f(x, i);
  234. }
  235. };
  236. var partition = function (xs, pred) {
  237. var pass = [];
  238. var fail = [];
  239. for (var i = 0, len = xs.length; i < len; i++) {
  240. var x = xs[i];
  241. var arr = pred(x, i) ? pass : fail;
  242. arr.push(x);
  243. }
  244. return {
  245. pass: pass,
  246. fail: fail
  247. };
  248. };
  249. var filter = function (xs, pred) {
  250. var r = [];
  251. for (var i = 0, len = xs.length; i < len; i++) {
  252. var x = xs[i];
  253. if (pred(x, i)) {
  254. r.push(x);
  255. }
  256. }
  257. return r;
  258. };
  259. var foldr = function (xs, f, acc) {
  260. eachr(xs, function (x) {
  261. acc = f(acc, x);
  262. });
  263. return acc;
  264. };
  265. var foldl = function (xs, f, acc) {
  266. each(xs, function (x) {
  267. acc = f(acc, x);
  268. });
  269. return acc;
  270. };
  271. var find = function (xs, pred) {
  272. for (var i = 0, len = xs.length; i < len; i++) {
  273. var x = xs[i];
  274. if (pred(x, i)) {
  275. return Option.some(x);
  276. }
  277. }
  278. return Option.none();
  279. };
  280. var findIndex = function (xs, pred) {
  281. for (var i = 0, len = xs.length; i < len; i++) {
  282. var x = xs[i];
  283. if (pred(x, i)) {
  284. return Option.some(i);
  285. }
  286. }
  287. return Option.none();
  288. };
  289. var flatten = function (xs) {
  290. var r = [];
  291. for (var i = 0, len = xs.length; i < len; ++i) {
  292. if (!isArray(xs[i])) {
  293. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  294. }
  295. nativePush.apply(r, xs[i]);
  296. }
  297. return r;
  298. };
  299. var bind = function (xs, f) {
  300. var output = map(xs, f);
  301. return flatten(output);
  302. };
  303. var forall = function (xs, pred) {
  304. for (var i = 0, len = xs.length; i < len; ++i) {
  305. var x = xs[i];
  306. if (pred(x, i) !== true) {
  307. return false;
  308. }
  309. }
  310. return true;
  311. };
  312. var reverse = function (xs) {
  313. var r = nativeSlice.call(xs, 0);
  314. r.reverse();
  315. return r;
  316. };
  317. var difference = function (a1, a2) {
  318. return filter(a1, function (x) {
  319. return !contains(a2, x);
  320. });
  321. };
  322. var mapToObject = function (xs, f) {
  323. var r = {};
  324. for (var i = 0, len = xs.length; i < len; i++) {
  325. var x = xs[i];
  326. r[String(x)] = f(x, i);
  327. }
  328. return r;
  329. };
  330. var sort = function (xs, comparator) {
  331. var copy = nativeSlice.call(xs, 0);
  332. copy.sort(comparator);
  333. return copy;
  334. };
  335. var head = function (xs) {
  336. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  337. };
  338. var last = function (xs) {
  339. return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
  340. };
  341. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  342. return nativeSlice.call(x);
  343. };
  344. var __assign = function () {
  345. __assign = Object.assign || function __assign(t) {
  346. for (var s, i = 1, n = arguments.length; i < n; i++) {
  347. s = arguments[i];
  348. for (var p in s)
  349. if (Object.prototype.hasOwnProperty.call(s, p))
  350. t[p] = s[p];
  351. }
  352. return t;
  353. };
  354. return __assign.apply(this, arguments);
  355. };
  356. function __rest(s, e) {
  357. var t = {};
  358. for (var p in s)
  359. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  360. t[p] = s[p];
  361. if (s != null && typeof Object.getOwnPropertySymbols === 'function')
  362. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  363. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  364. t[p[i]] = s[p[i]];
  365. }
  366. return t;
  367. }
  368. var isNodeType = function (type) {
  369. return function (node) {
  370. return !!node && node.nodeType === type;
  371. };
  372. };
  373. var isRestrictedNode = function (node) {
  374. return !!node && !Object.getPrototypeOf(node);
  375. };
  376. var isElement = isNodeType(1);
  377. var matchNodeNames = function (names) {
  378. var lowercasedNames = names.map(function (s) {
  379. return s.toLowerCase();
  380. });
  381. return function (node) {
  382. if (node && node.nodeName) {
  383. var nodeName = node.nodeName.toLowerCase();
  384. return contains(lowercasedNames, nodeName);
  385. }
  386. return false;
  387. };
  388. };
  389. var matchStyleValues = function (name, values) {
  390. var items = values.toLowerCase().split(' ');
  391. return function (node) {
  392. var i, cssValue;
  393. if (isElement(node)) {
  394. for (i = 0; i < items.length; i++) {
  395. var computed = node.ownerDocument.defaultView.getComputedStyle(node, null);
  396. cssValue = computed ? computed.getPropertyValue(name) : null;
  397. if (cssValue === items[i]) {
  398. return true;
  399. }
  400. }
  401. }
  402. return false;
  403. };
  404. };
  405. var hasPropValue = function (propName, propValue) {
  406. return function (node) {
  407. return isElement(node) && node[propName] === propValue;
  408. };
  409. };
  410. var hasAttribute = function (attrName, attrValue) {
  411. return function (node) {
  412. return isElement(node) && node.hasAttribute(attrName);
  413. };
  414. };
  415. var hasAttributeValue = function (attrName, attrValue) {
  416. return function (node) {
  417. return isElement(node) && node.getAttribute(attrName) === attrValue;
  418. };
  419. };
  420. var isBogus = function (node) {
  421. return isElement(node) && node.hasAttribute('data-mce-bogus');
  422. };
  423. var isBogusAll = function (node) {
  424. return isElement(node) && node.getAttribute('data-mce-bogus') === 'all';
  425. };
  426. var isTable = function (node) {
  427. return isElement(node) && node.tagName === 'TABLE';
  428. };
  429. var hasContentEditableState = function (value) {
  430. return function (node) {
  431. if (isElement(node)) {
  432. if (node.contentEditable === value) {
  433. return true;
  434. }
  435. if (node.getAttribute('data-mce-contenteditable') === value) {
  436. return true;
  437. }
  438. }
  439. return false;
  440. };
  441. };
  442. var isTextareaOrInput = matchNodeNames([
  443. 'textarea',
  444. 'input'
  445. ]);
  446. var isText = isNodeType(3);
  447. var isComment = isNodeType(8);
  448. var isDocument = isNodeType(9);
  449. var isDocumentFragment = isNodeType(11);
  450. var isBr = matchNodeNames(['br']);
  451. var isContentEditableTrue = hasContentEditableState('true');
  452. var isContentEditableFalse = hasContentEditableState('false');
  453. var NodeType = {
  454. isText: isText,
  455. isElement: isElement,
  456. isComment: isComment,
  457. isDocument: isDocument,
  458. isDocumentFragment: isDocumentFragment,
  459. isBr: isBr,
  460. isContentEditableTrue: isContentEditableTrue,
  461. isContentEditableFalse: isContentEditableFalse,
  462. isRestrictedNode: isRestrictedNode,
  463. matchNodeNames: matchNodeNames,
  464. hasPropValue: hasPropValue,
  465. hasAttribute: hasAttribute,
  466. hasAttributeValue: hasAttributeValue,
  467. matchStyleValues: matchStyleValues,
  468. isBogus: isBogus,
  469. isBogusAll: isBogusAll,
  470. isTable: isTable,
  471. isTextareaOrInput: isTextareaOrInput
  472. };
  473. var Cell = function (initial) {
  474. var value = initial;
  475. var get = function () {
  476. return value;
  477. };
  478. var set = function (v) {
  479. value = v;
  480. };
  481. var clone = function () {
  482. return Cell(get());
  483. };
  484. return {
  485. get: get,
  486. set: set,
  487. clone: clone
  488. };
  489. };
  490. var firstMatch = function (regexes, s) {
  491. for (var i = 0; i < regexes.length; i++) {
  492. var x = regexes[i];
  493. if (x.test(s)) {
  494. return x;
  495. }
  496. }
  497. return undefined;
  498. };
  499. var find$1 = function (regexes, agent) {
  500. var r = firstMatch(regexes, agent);
  501. if (!r) {
  502. return {
  503. major: 0,
  504. minor: 0
  505. };
  506. }
  507. var group = function (i) {
  508. return Number(agent.replace(r, '$' + i));
  509. };
  510. return nu(group(1), group(2));
  511. };
  512. var detect = function (versionRegexes, agent) {
  513. var cleanedAgent = String(agent).toLowerCase();
  514. if (versionRegexes.length === 0) {
  515. return unknown();
  516. }
  517. return find$1(versionRegexes, cleanedAgent);
  518. };
  519. var unknown = function () {
  520. return nu(0, 0);
  521. };
  522. var nu = function (major, minor) {
  523. return {
  524. major: major,
  525. minor: minor
  526. };
  527. };
  528. var Version = {
  529. nu: nu,
  530. detect: detect,
  531. unknown: unknown
  532. };
  533. var edge = 'Edge';
  534. var chrome = 'Chrome';
  535. var ie = 'IE';
  536. var opera = 'Opera';
  537. var firefox = 'Firefox';
  538. var safari = 'Safari';
  539. var isBrowser = function (name, current) {
  540. return function () {
  541. return current === name;
  542. };
  543. };
  544. var unknown$1 = function () {
  545. return nu$1({
  546. current: undefined,
  547. version: Version.unknown()
  548. });
  549. };
  550. var nu$1 = function (info) {
  551. var current = info.current;
  552. var version = info.version;
  553. return {
  554. current: current,
  555. version: version,
  556. isEdge: isBrowser(edge, current),
  557. isChrome: isBrowser(chrome, current),
  558. isIE: isBrowser(ie, current),
  559. isOpera: isBrowser(opera, current),
  560. isFirefox: isBrowser(firefox, current),
  561. isSafari: isBrowser(safari, current)
  562. };
  563. };
  564. var Browser = {
  565. unknown: unknown$1,
  566. nu: nu$1,
  567. edge: constant(edge),
  568. chrome: constant(chrome),
  569. ie: constant(ie),
  570. opera: constant(opera),
  571. firefox: constant(firefox),
  572. safari: constant(safari)
  573. };
  574. var windows = 'Windows';
  575. var ios = 'iOS';
  576. var android = 'Android';
  577. var linux = 'Linux';
  578. var osx = 'OSX';
  579. var solaris = 'Solaris';
  580. var freebsd = 'FreeBSD';
  581. var isOS = function (name, current) {
  582. return function () {
  583. return current === name;
  584. };
  585. };
  586. var unknown$2 = function () {
  587. return nu$2({
  588. current: undefined,
  589. version: Version.unknown()
  590. });
  591. };
  592. var nu$2 = function (info) {
  593. var current = info.current;
  594. var version = info.version;
  595. return {
  596. current: current,
  597. version: version,
  598. isWindows: isOS(windows, current),
  599. isiOS: isOS(ios, current),
  600. isAndroid: isOS(android, current),
  601. isOSX: isOS(osx, current),
  602. isLinux: isOS(linux, current),
  603. isSolaris: isOS(solaris, current),
  604. isFreeBSD: isOS(freebsd, current)
  605. };
  606. };
  607. var OperatingSystem = {
  608. unknown: unknown$2,
  609. nu: nu$2,
  610. windows: constant(windows),
  611. ios: constant(ios),
  612. android: constant(android),
  613. linux: constant(linux),
  614. osx: constant(osx),
  615. solaris: constant(solaris),
  616. freebsd: constant(freebsd)
  617. };
  618. var DeviceType = function (os, browser, userAgent, mediaMatch) {
  619. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  620. var isiPhone = os.isiOS() && !isiPad;
  621. var isMobile = os.isiOS() || os.isAndroid();
  622. var isTouch = isMobile || mediaMatch('(pointer:coarse)');
  623. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
  624. var isPhone = isiPhone || isMobile && !isTablet;
  625. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  626. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  627. return {
  628. isiPad: constant(isiPad),
  629. isiPhone: constant(isiPhone),
  630. isTablet: constant(isTablet),
  631. isPhone: constant(isPhone),
  632. isTouch: constant(isTouch),
  633. isAndroid: os.isAndroid,
  634. isiOS: os.isiOS,
  635. isWebView: constant(iOSwebview),
  636. isDesktop: constant(isDesktop)
  637. };
  638. };
  639. var detect$1 = function (candidates, userAgent) {
  640. var agent = String(userAgent).toLowerCase();
  641. return find(candidates, function (candidate) {
  642. return candidate.search(agent);
  643. });
  644. };
  645. var detectBrowser = function (browsers, userAgent) {
  646. return detect$1(browsers, userAgent).map(function (browser) {
  647. var version = Version.detect(browser.versionRegexes, userAgent);
  648. return {
  649. current: browser.name,
  650. version: version
  651. };
  652. });
  653. };
  654. var detectOs = function (oses, userAgent) {
  655. return detect$1(oses, userAgent).map(function (os) {
  656. var version = Version.detect(os.versionRegexes, userAgent);
  657. return {
  658. current: os.name,
  659. version: version
  660. };
  661. });
  662. };
  663. var UaString = {
  664. detectBrowser: detectBrowser,
  665. detectOs: detectOs
  666. };
  667. var checkRange = function (str, substr, start) {
  668. if (substr === '') {
  669. return true;
  670. }
  671. if (str.length < substr.length) {
  672. return false;
  673. }
  674. var x = str.substr(start, start + substr.length);
  675. return x === substr;
  676. };
  677. var contains$1 = function (str, substr) {
  678. return str.indexOf(substr) !== -1;
  679. };
  680. var startsWith = function (str, prefix) {
  681. return checkRange(str, prefix, 0);
  682. };
  683. var trim = function (str) {
  684. return str.replace(/^\s+|\s+$/g, '');
  685. };
  686. var lTrim = function (str) {
  687. return str.replace(/^\s+/g, '');
  688. };
  689. var rTrim = function (str) {
  690. return str.replace(/\s+$/g, '');
  691. };
  692. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  693. var checkContains = function (target) {
  694. return function (uastring) {
  695. return contains$1(uastring, target);
  696. };
  697. };
  698. var browsers = [
  699. {
  700. name: 'Edge',
  701. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  702. search: function (uastring) {
  703. return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
  704. }
  705. },
  706. {
  707. name: 'Chrome',
  708. versionRegexes: [
  709. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  710. normalVersionRegex
  711. ],
  712. search: function (uastring) {
  713. return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
  714. }
  715. },
  716. {
  717. name: 'IE',
  718. versionRegexes: [
  719. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  720. /.*?rv:([0-9]+)\.([0-9]+).*/
  721. ],
  722. search: function (uastring) {
  723. return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
  724. }
  725. },
  726. {
  727. name: 'Opera',
  728. versionRegexes: [
  729. normalVersionRegex,
  730. /.*?opera\/([0-9]+)\.([0-9]+).*/
  731. ],
  732. search: checkContains('opera')
  733. },
  734. {
  735. name: 'Firefox',
  736. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  737. search: checkContains('firefox')
  738. },
  739. {
  740. name: 'Safari',
  741. versionRegexes: [
  742. normalVersionRegex,
  743. /.*?cpu os ([0-9]+)_([0-9]+).*/
  744. ],
  745. search: function (uastring) {
  746. return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
  747. }
  748. }
  749. ];
  750. var oses = [
  751. {
  752. name: 'Windows',
  753. search: checkContains('win'),
  754. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  755. },
  756. {
  757. name: 'iOS',
  758. search: function (uastring) {
  759. return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
  760. },
  761. versionRegexes: [
  762. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  763. /.*cpu os ([0-9]+)_([0-9]+).*/,
  764. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  765. ]
  766. },
  767. {
  768. name: 'Android',
  769. search: checkContains('android'),
  770. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  771. },
  772. {
  773. name: 'OSX',
  774. search: checkContains('os x'),
  775. versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
  776. },
  777. {
  778. name: 'Linux',
  779. search: checkContains('linux'),
  780. versionRegexes: []
  781. },
  782. {
  783. name: 'Solaris',
  784. search: checkContains('sunos'),
  785. versionRegexes: []
  786. },
  787. {
  788. name: 'FreeBSD',
  789. search: checkContains('freebsd'),
  790. versionRegexes: []
  791. }
  792. ];
  793. var PlatformInfo = {
  794. browsers: constant(browsers),
  795. oses: constant(oses)
  796. };
  797. var detect$2 = function (userAgent, mediaMatch) {
  798. var browsers = PlatformInfo.browsers();
  799. var oses = PlatformInfo.oses();
  800. var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
  801. var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  802. var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
  803. return {
  804. browser: browser,
  805. os: os,
  806. deviceType: deviceType
  807. };
  808. };
  809. var PlatformDetection = { detect: detect$2 };
  810. var mediaMatch = function (query) {
  811. return domGlobals.window.matchMedia(query).matches;
  812. };
  813. var platform = Cell(PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch));
  814. var detect$3 = function () {
  815. return platform.get();
  816. };
  817. var fromHtml = function (html, scope) {
  818. var doc = scope || domGlobals.document;
  819. var div = doc.createElement('div');
  820. div.innerHTML = html;
  821. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  822. domGlobals.console.error('HTML does not have a single root node', html);
  823. throw new Error('HTML must have a single root node');
  824. }
  825. return fromDom(div.childNodes[0]);
  826. };
  827. var fromTag = function (tag, scope) {
  828. var doc = scope || domGlobals.document;
  829. var node = doc.createElement(tag);
  830. return fromDom(node);
  831. };
  832. var fromText = function (text, scope) {
  833. var doc = scope || domGlobals.document;
  834. var node = doc.createTextNode(text);
  835. return fromDom(node);
  836. };
  837. var fromDom = function (node) {
  838. if (node === null || node === undefined) {
  839. throw new Error('Node cannot be null or undefined');
  840. }
  841. return { dom: constant(node) };
  842. };
  843. var fromPoint = function (docElm, x, y) {
  844. var doc = docElm.dom();
  845. return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
  846. };
  847. var Element = {
  848. fromHtml: fromHtml,
  849. fromTag: fromTag,
  850. fromText: fromText,
  851. fromDom: fromDom,
  852. fromPoint: fromPoint
  853. };
  854. var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
  855. var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
  856. var COMMENT = domGlobals.Node.COMMENT_NODE;
  857. var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
  858. var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
  859. var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
  860. var ELEMENT = domGlobals.Node.ELEMENT_NODE;
  861. var TEXT = domGlobals.Node.TEXT_NODE;
  862. var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
  863. var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
  864. var ENTITY = domGlobals.Node.ENTITY_NODE;
  865. var NOTATION = domGlobals.Node.NOTATION_NODE;
  866. var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
  867. var name = function (element) {
  868. var r = element.dom().nodeName;
  869. return r.toLowerCase();
  870. };
  871. var type = function (element) {
  872. return element.dom().nodeType;
  873. };
  874. var isType$1 = function (t) {
  875. return function (element) {
  876. return type(element) === t;
  877. };
  878. };
  879. var isElement$1 = isType$1(ELEMENT);
  880. var isText$1 = isType$1(TEXT);
  881. var keys = Object.keys;
  882. var hasOwnProperty = Object.hasOwnProperty;
  883. var each$1 = function (obj, f) {
  884. var props = keys(obj);
  885. for (var k = 0, len = props.length; k < len; k++) {
  886. var i = props[k];
  887. var x = obj[i];
  888. f(x, i);
  889. }
  890. };
  891. var map$1 = function (obj, f) {
  892. return tupleMap(obj, function (x, i) {
  893. return {
  894. k: i,
  895. v: f(x, i)
  896. };
  897. });
  898. };
  899. var tupleMap = function (obj, f) {
  900. var r = {};
  901. each$1(obj, function (x, i) {
  902. var tuple = f(x, i);
  903. r[tuple.k] = tuple.v;
  904. });
  905. return r;
  906. };
  907. var bifilter = function (obj, pred) {
  908. var t = {};
  909. var f = {};
  910. each$1(obj, function (x, i) {
  911. var branch = pred(x, i) ? t : f;
  912. branch[i] = x;
  913. });
  914. return {
  915. t: t,
  916. f: f
  917. };
  918. };
  919. var get = function (obj, key) {
  920. return has(obj, key) ? Option.from(obj[key]) : Option.none();
  921. };
  922. var has = function (obj, key) {
  923. return hasOwnProperty.call(obj, key);
  924. };
  925. var isSupported = function (dom) {
  926. return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
  927. };
  928. var inBody = function (element) {
  929. var dom = isText$1(element) ? element.dom().parentNode : element.dom();
  930. return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
  931. };
  932. var rawSet = function (dom, key, value) {
  933. if (isString(value) || isBoolean(value) || isNumber(value)) {
  934. dom.setAttribute(key, value + '');
  935. } else {
  936. domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  937. throw new Error('Attribute value was not simple');
  938. }
  939. };
  940. var set = function (element, key, value) {
  941. rawSet(element.dom(), key, value);
  942. };
  943. var setAll = function (element, attrs) {
  944. var dom = element.dom();
  945. each$1(attrs, function (v, k) {
  946. rawSet(dom, k, v);
  947. });
  948. };
  949. var get$1 = function (element, key) {
  950. var v = element.dom().getAttribute(key);
  951. return v === null ? undefined : v;
  952. };
  953. var has$1 = function (element, key) {
  954. var dom = element.dom();
  955. return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
  956. };
  957. var remove = function (element, key) {
  958. element.dom().removeAttribute(key);
  959. };
  960. var get$2 = function (element, property) {
  961. var dom = element.dom();
  962. var styles = domGlobals.window.getComputedStyle(dom);
  963. var r = styles.getPropertyValue(property);
  964. var v = r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
  965. return v === null ? undefined : v;
  966. };
  967. var getUnsafeProperty = function (dom, property) {
  968. return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
  969. };
  970. var getRaw = function (element, property) {
  971. var dom = element.dom();
  972. var raw = getUnsafeProperty(dom, property);
  973. return Option.from(raw).filter(function (r) {
  974. return r.length > 0;
  975. });
  976. };
  977. var reflow = function (e) {
  978. return e.dom().offsetWidth;
  979. };
  980. var Immutable = function () {
  981. var fields = [];
  982. for (var _i = 0; _i < arguments.length; _i++) {
  983. fields[_i] = arguments[_i];
  984. }
  985. return function () {
  986. var values = [];
  987. for (var _i = 0; _i < arguments.length; _i++) {
  988. values[_i] = arguments[_i];
  989. }
  990. if (fields.length !== values.length) {
  991. throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
  992. }
  993. var struct = {};
  994. each(fields, function (name, i) {
  995. struct[name] = constant(values[i]);
  996. });
  997. return struct;
  998. };
  999. };
  1000. var toArray = function (target, f) {
  1001. var r = [];
  1002. var recurse = function (e) {
  1003. r.push(e);
  1004. return f(e);
  1005. };
  1006. var cur = f(target);
  1007. do {
  1008. cur = cur.bind(recurse);
  1009. } while (cur.isSome());
  1010. return r;
  1011. };
  1012. var Recurse = { toArray: toArray };
  1013. var compareDocumentPosition = function (a, b, match) {
  1014. return (a.compareDocumentPosition(b) & match) !== 0;
  1015. };
  1016. var documentPositionPreceding = function (a, b) {
  1017. return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_PRECEDING);
  1018. };
  1019. var documentPositionContainedBy = function (a, b) {
  1020. return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
  1021. };
  1022. var Node = {
  1023. documentPositionPreceding: documentPositionPreceding,
  1024. documentPositionContainedBy: documentPositionContainedBy
  1025. };
  1026. var ELEMENT$1 = ELEMENT;
  1027. var DOCUMENT$1 = DOCUMENT;
  1028. var is = function (element, selector) {
  1029. var dom = element.dom();
  1030. if (dom.nodeType !== ELEMENT$1) {
  1031. return false;
  1032. } else {
  1033. var elem = dom;
  1034. if (elem.matches !== undefined) {
  1035. return elem.matches(selector);
  1036. } else if (elem.msMatchesSelector !== undefined) {
  1037. return elem.msMatchesSelector(selector);
  1038. } else if (elem.webkitMatchesSelector !== undefined) {
  1039. return elem.webkitMatchesSelector(selector);
  1040. } else if (elem.mozMatchesSelector !== undefined) {
  1041. return elem.mozMatchesSelector(selector);
  1042. } else {
  1043. throw new Error('Browser lacks native selectors');
  1044. }
  1045. }
  1046. };
  1047. var bypassSelector = function (dom) {
  1048. return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
  1049. };
  1050. var all = function (selector, scope) {
  1051. var base = scope === undefined ? domGlobals.document : scope.dom();
  1052. return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
  1053. };
  1054. var one = function (selector, scope) {
  1055. var base = scope === undefined ? domGlobals.document : scope.dom();
  1056. return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
  1057. };
  1058. var eq = function (e1, e2) {
  1059. return e1.dom() === e2.dom();
  1060. };
  1061. var regularContains = function (e1, e2) {
  1062. var d1 = e1.dom();
  1063. var d2 = e2.dom();
  1064. return d1 === d2 ? false : d1.contains(d2);
  1065. };
  1066. var ieContains = function (e1, e2) {
  1067. return Node.documentPositionContainedBy(e1.dom(), e2.dom());
  1068. };
  1069. var browser = detect$3().browser;
  1070. var contains$2 = browser.isIE() ? ieContains : regularContains;
  1071. var owner = function (element) {
  1072. return Element.fromDom(element.dom().ownerDocument);
  1073. };
  1074. var documentElement = function (element) {
  1075. return Element.fromDom(element.dom().ownerDocument.documentElement);
  1076. };
  1077. var defaultView = function (element) {
  1078. return Element.fromDom(element.dom().ownerDocument.defaultView);
  1079. };
  1080. var parent = function (element) {
  1081. return Option.from(element.dom().parentNode).map(Element.fromDom);
  1082. };
  1083. var parents = function (element, isRoot) {
  1084. var stop = isFunction(isRoot) ? isRoot : never;
  1085. var dom = element.dom();
  1086. var ret = [];
  1087. while (dom.parentNode !== null && dom.parentNode !== undefined) {
  1088. var rawParent = dom.parentNode;
  1089. var p = Element.fromDom(rawParent);
  1090. ret.push(p);
  1091. if (stop(p) === true) {
  1092. break;
  1093. } else {
  1094. dom = rawParent;
  1095. }
  1096. }
  1097. return ret;
  1098. };
  1099. var prevSibling = function (element) {
  1100. return Option.from(element.dom().previousSibling).map(Element.fromDom);
  1101. };
  1102. var nextSibling = function (element) {
  1103. return Option.from(element.dom().nextSibling).map(Element.fromDom);
  1104. };
  1105. var prevSiblings = function (element) {
  1106. return reverse(Recurse.toArray(element, prevSibling));
  1107. };
  1108. var nextSiblings = function (element) {
  1109. return Recurse.toArray(element, nextSibling);
  1110. };
  1111. var children = function (element) {
  1112. return map(element.dom().childNodes, Element.fromDom);
  1113. };
  1114. var child = function (element, index) {
  1115. var cs = element.dom().childNodes;
  1116. return Option.from(cs[index]).map(Element.fromDom);
  1117. };
  1118. var firstChild = function (element) {
  1119. return child(element, 0);
  1120. };
  1121. var lastChild = function (element) {
  1122. return child(element, element.dom().childNodes.length - 1);
  1123. };
  1124. var childNodesCount = function (element) {
  1125. return element.dom().childNodes.length;
  1126. };
  1127. var spot = Immutable('element', 'offset');
  1128. var browser$1 = detect$3().browser;
  1129. var firstElement = function (nodes) {
  1130. return find(nodes, isElement$1);
  1131. };
  1132. var getTableCaptionDeltaY = function (elm) {
  1133. if (browser$1.isFirefox() && name(elm) === 'table') {
  1134. return firstElement(children(elm)).filter(function (elm) {
  1135. return name(elm) === 'caption';
  1136. }).bind(function (caption) {
  1137. return firstElement(nextSiblings(caption)).map(function (body) {
  1138. var bodyTop = body.dom().offsetTop;
  1139. var captionTop = caption.dom().offsetTop;
  1140. var captionHeight = caption.dom().offsetHeight;
  1141. return bodyTop <= captionTop ? -captionHeight : 0;
  1142. });
  1143. }).getOr(0);
  1144. } else {
  1145. return 0;
  1146. }
  1147. };
  1148. var hasChild = function (elm, child) {
  1149. return elm.children && contains(elm.children, child);
  1150. };
  1151. var getPos = function (body, elm, rootElm) {
  1152. var x = 0, y = 0, offsetParent;
  1153. var doc = body.ownerDocument;
  1154. var pos;
  1155. rootElm = rootElm ? rootElm : body;
  1156. if (elm) {
  1157. if (rootElm === body && elm.getBoundingClientRect && get$2(Element.fromDom(body), 'position') === 'static') {
  1158. pos = elm.getBoundingClientRect();
  1159. x = pos.left + (doc.documentElement.scrollLeft || body.scrollLeft) - doc.documentElement.clientLeft;
  1160. y = pos.top + (doc.documentElement.scrollTop || body.scrollTop) - doc.documentElement.clientTop;
  1161. return {
  1162. x: x,
  1163. y: y
  1164. };
  1165. }
  1166. offsetParent = elm;
  1167. while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
  1168. x += offsetParent.offsetLeft || 0;
  1169. y += offsetParent.offsetTop || 0;
  1170. offsetParent = offsetParent.offsetParent;
  1171. }
  1172. offsetParent = elm.parentNode;
  1173. while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
  1174. x -= offsetParent.scrollLeft || 0;
  1175. y -= offsetParent.scrollTop || 0;
  1176. offsetParent = offsetParent.parentNode;
  1177. }
  1178. y += getTableCaptionDeltaY(Element.fromDom(elm));
  1179. }
  1180. return {
  1181. x: x,
  1182. y: y
  1183. };
  1184. };
  1185. var Position = { getPos: getPos };
  1186. var exports$1 = {}, module$1 = { exports: exports$1 };
  1187. (function (define, exports, module, require) {
  1188. (function (f) {
  1189. if (typeof exports === 'object' && typeof module !== 'undefined') {
  1190. module.exports = f();
  1191. } else if (typeof define === 'function' && define.amd) {
  1192. define([], f);
  1193. } else {
  1194. var g;
  1195. if (typeof window !== 'undefined') {
  1196. g = window;
  1197. } else if (typeof global !== 'undefined') {
  1198. g = global;
  1199. } else if (typeof self !== 'undefined') {
  1200. g = self;
  1201. } else {
  1202. g = this;
  1203. }
  1204. g.EphoxContactWrapper = f();
  1205. }
  1206. }(function () {
  1207. return function () {
  1208. function r(e, n, t) {
  1209. function o(i, f) {
  1210. if (!n[i]) {
  1211. if (!e[i]) {
  1212. var c = 'function' == typeof require && require;
  1213. if (!f && c)
  1214. return c(i, !0);
  1215. if (u)
  1216. return u(i, !0);
  1217. var a = new Error('Cannot find module \'' + i + '\'');
  1218. throw a.code = 'MODULE_NOT_FOUND', a;
  1219. }
  1220. var p = n[i] = { exports: {} };
  1221. e[i][0].call(p.exports, function (r) {
  1222. var n = e[i][1][r];
  1223. return o(n || r);
  1224. }, p, p.exports, r, e, n, t);
  1225. }
  1226. return n[i].exports;
  1227. }
  1228. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  1229. o(t[i]);
  1230. return o;
  1231. }
  1232. return r;
  1233. }()({
  1234. 1: [
  1235. function (require, module, exports) {
  1236. var process = module.exports = {};
  1237. var cachedSetTimeout;
  1238. var cachedClearTimeout;
  1239. function defaultSetTimout() {
  1240. throw new Error('setTimeout has not been defined');
  1241. }
  1242. function defaultClearTimeout() {
  1243. throw new Error('clearTimeout has not been defined');
  1244. }
  1245. (function () {
  1246. try {
  1247. if (typeof setTimeout === 'function') {
  1248. cachedSetTimeout = setTimeout;
  1249. } else {
  1250. cachedSetTimeout = defaultSetTimout;
  1251. }
  1252. } catch (e) {
  1253. cachedSetTimeout = defaultSetTimout;
  1254. }
  1255. try {
  1256. if (typeof clearTimeout === 'function') {
  1257. cachedClearTimeout = clearTimeout;
  1258. } else {
  1259. cachedClearTimeout = defaultClearTimeout;
  1260. }
  1261. } catch (e) {
  1262. cachedClearTimeout = defaultClearTimeout;
  1263. }
  1264. }());
  1265. function runTimeout(fun) {
  1266. if (cachedSetTimeout === setTimeout) {
  1267. return setTimeout(fun, 0);
  1268. }
  1269. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1270. cachedSetTimeout = setTimeout;
  1271. return setTimeout(fun, 0);
  1272. }
  1273. try {
  1274. return cachedSetTimeout(fun, 0);
  1275. } catch (e) {
  1276. try {
  1277. return cachedSetTimeout.call(null, fun, 0);
  1278. } catch (e) {
  1279. return cachedSetTimeout.call(this, fun, 0);
  1280. }
  1281. }
  1282. }
  1283. function runClearTimeout(marker) {
  1284. if (cachedClearTimeout === clearTimeout) {
  1285. return clearTimeout(marker);
  1286. }
  1287. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1288. cachedClearTimeout = clearTimeout;
  1289. return clearTimeout(marker);
  1290. }
  1291. try {
  1292. return cachedClearTimeout(marker);
  1293. } catch (e) {
  1294. try {
  1295. return cachedClearTimeout.call(null, marker);
  1296. } catch (e) {
  1297. return cachedClearTimeout.call(this, marker);
  1298. }
  1299. }
  1300. }
  1301. var queue = [];
  1302. var draining = false;
  1303. var currentQueue;
  1304. var queueIndex = -1;
  1305. function cleanUpNextTick() {
  1306. if (!draining || !currentQueue) {
  1307. return;
  1308. }
  1309. draining = false;
  1310. if (currentQueue.length) {
  1311. queue = currentQueue.concat(queue);
  1312. } else {
  1313. queueIndex = -1;
  1314. }
  1315. if (queue.length) {
  1316. drainQueue();
  1317. }
  1318. }
  1319. function drainQueue() {
  1320. if (draining) {
  1321. return;
  1322. }
  1323. var timeout = runTimeout(cleanUpNextTick);
  1324. draining = true;
  1325. var len = queue.length;
  1326. while (len) {
  1327. currentQueue = queue;
  1328. queue = [];
  1329. while (++queueIndex < len) {
  1330. if (currentQueue) {
  1331. currentQueue[queueIndex].run();
  1332. }
  1333. }
  1334. queueIndex = -1;
  1335. len = queue.length;
  1336. }
  1337. currentQueue = null;
  1338. draining = false;
  1339. runClearTimeout(timeout);
  1340. }
  1341. process.nextTick = function (fun) {
  1342. var args = new Array(arguments.length - 1);
  1343. if (arguments.length > 1) {
  1344. for (var i = 1; i < arguments.length; i++) {
  1345. args[i - 1] = arguments[i];
  1346. }
  1347. }
  1348. queue.push(new Item(fun, args));
  1349. if (queue.length === 1 && !draining) {
  1350. runTimeout(drainQueue);
  1351. }
  1352. };
  1353. function Item(fun, array) {
  1354. this.fun = fun;
  1355. this.array = array;
  1356. }
  1357. Item.prototype.run = function () {
  1358. this.fun.apply(null, this.array);
  1359. };
  1360. process.title = 'browser';
  1361. process.browser = true;
  1362. process.env = {};
  1363. process.argv = [];
  1364. process.version = '';
  1365. process.versions = {};
  1366. function noop() {
  1367. }
  1368. process.on = noop;
  1369. process.addListener = noop;
  1370. process.once = noop;
  1371. process.off = noop;
  1372. process.removeListener = noop;
  1373. process.removeAllListeners = noop;
  1374. process.emit = noop;
  1375. process.prependListener = noop;
  1376. process.prependOnceListener = noop;
  1377. process.listeners = function (name) {
  1378. return [];
  1379. };
  1380. process.binding = function (name) {
  1381. throw new Error('process.binding is not supported');
  1382. };
  1383. process.cwd = function () {
  1384. return '/';
  1385. };
  1386. process.chdir = function (dir) {
  1387. throw new Error('process.chdir is not supported');
  1388. };
  1389. process.umask = function () {
  1390. return 0;
  1391. };
  1392. },
  1393. {}
  1394. ],
  1395. 2: [
  1396. function (require, module, exports) {
  1397. (function (setImmediate) {
  1398. (function (root) {
  1399. var setTimeoutFunc = setTimeout;
  1400. function noop() {
  1401. }
  1402. function bind(fn, thisArg) {
  1403. return function () {
  1404. fn.apply(thisArg, arguments);
  1405. };
  1406. }
  1407. function Promise(fn) {
  1408. if (typeof this !== 'object')
  1409. throw new TypeError('Promises must be constructed via new');
  1410. if (typeof fn !== 'function')
  1411. throw new TypeError('not a function');
  1412. this._state = 0;
  1413. this._handled = false;
  1414. this._value = undefined;
  1415. this._deferreds = [];
  1416. doResolve(fn, this);
  1417. }
  1418. function handle(self, deferred) {
  1419. while (self._state === 3) {
  1420. self = self._value;
  1421. }
  1422. if (self._state === 0) {
  1423. self._deferreds.push(deferred);
  1424. return;
  1425. }
  1426. self._handled = true;
  1427. Promise._immediateFn(function () {
  1428. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  1429. if (cb === null) {
  1430. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  1431. return;
  1432. }
  1433. var ret;
  1434. try {
  1435. ret = cb(self._value);
  1436. } catch (e) {
  1437. reject(deferred.promise, e);
  1438. return;
  1439. }
  1440. resolve(deferred.promise, ret);
  1441. });
  1442. }
  1443. function resolve(self, newValue) {
  1444. try {
  1445. if (newValue === self)
  1446. throw new TypeError('A promise cannot be resolved with itself.');
  1447. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  1448. var then = newValue.then;
  1449. if (newValue instanceof Promise) {
  1450. self._state = 3;
  1451. self._value = newValue;
  1452. finale(self);
  1453. return;
  1454. } else if (typeof then === 'function') {
  1455. doResolve(bind(then, newValue), self);
  1456. return;
  1457. }
  1458. }
  1459. self._state = 1;
  1460. self._value = newValue;
  1461. finale(self);
  1462. } catch (e) {
  1463. reject(self, e);
  1464. }
  1465. }
  1466. function reject(self, newValue) {
  1467. self._state = 2;
  1468. self._value = newValue;
  1469. finale(self);
  1470. }
  1471. function finale(self) {
  1472. if (self._state === 2 && self._deferreds.length === 0) {
  1473. Promise._immediateFn(function () {
  1474. if (!self._handled) {
  1475. Promise._unhandledRejectionFn(self._value);
  1476. }
  1477. });
  1478. }
  1479. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  1480. handle(self, self._deferreds[i]);
  1481. }
  1482. self._deferreds = null;
  1483. }
  1484. function Handler(onFulfilled, onRejected, promise) {
  1485. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  1486. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  1487. this.promise = promise;
  1488. }
  1489. function doResolve(fn, self) {
  1490. var done = false;
  1491. try {
  1492. fn(function (value) {
  1493. if (done)
  1494. return;
  1495. done = true;
  1496. resolve(self, value);
  1497. }, function (reason) {
  1498. if (done)
  1499. return;
  1500. done = true;
  1501. reject(self, reason);
  1502. });
  1503. } catch (ex) {
  1504. if (done)
  1505. return;
  1506. done = true;
  1507. reject(self, ex);
  1508. }
  1509. }
  1510. Promise.prototype['catch'] = function (onRejected) {
  1511. return this.then(null, onRejected);
  1512. };
  1513. Promise.prototype.then = function (onFulfilled, onRejected) {
  1514. var prom = new this.constructor(noop);
  1515. handle(this, new Handler(onFulfilled, onRejected, prom));
  1516. return prom;
  1517. };
  1518. Promise.all = function (arr) {
  1519. var args = Array.prototype.slice.call(arr);
  1520. return new Promise(function (resolve, reject) {
  1521. if (args.length === 0)
  1522. return resolve([]);
  1523. var remaining = args.length;
  1524. function res(i, val) {
  1525. try {
  1526. if (val && (typeof val === 'object' || typeof val === 'function')) {
  1527. var then = val.then;
  1528. if (typeof then === 'function') {
  1529. then.call(val, function (val) {
  1530. res(i, val);
  1531. }, reject);
  1532. return;
  1533. }
  1534. }
  1535. args[i] = val;
  1536. if (--remaining === 0) {
  1537. resolve(args);
  1538. }
  1539. } catch (ex) {
  1540. reject(ex);
  1541. }
  1542. }
  1543. for (var i = 0; i < args.length; i++) {
  1544. res(i, args[i]);
  1545. }
  1546. });
  1547. };
  1548. Promise.resolve = function (value) {
  1549. if (value && typeof value === 'object' && value.constructor === Promise) {
  1550. return value;
  1551. }
  1552. return new Promise(function (resolve) {
  1553. resolve(value);
  1554. });
  1555. };
  1556. Promise.reject = function (value) {
  1557. return new Promise(function (resolve, reject) {
  1558. reject(value);
  1559. });
  1560. };
  1561. Promise.race = function (values) {
  1562. return new Promise(function (resolve, reject) {
  1563. for (var i = 0, len = values.length; i < len; i++) {
  1564. values[i].then(resolve, reject);
  1565. }
  1566. });
  1567. };
  1568. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  1569. setImmediate(fn);
  1570. } : function (fn) {
  1571. setTimeoutFunc(fn, 0);
  1572. };
  1573. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  1574. if (typeof console !== 'undefined' && console) {
  1575. console.warn('Possible Unhandled Promise Rejection:', err);
  1576. }
  1577. };
  1578. Promise._setImmediateFn = function _setImmediateFn(fn) {
  1579. Promise._immediateFn = fn;
  1580. };
  1581. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  1582. Promise._unhandledRejectionFn = fn;
  1583. };
  1584. if (typeof module !== 'undefined' && module.exports) {
  1585. module.exports = Promise;
  1586. } else if (!root.Promise) {
  1587. root.Promise = Promise;
  1588. }
  1589. }(this));
  1590. }.call(this, require('timers').setImmediate));
  1591. },
  1592. { 'timers': 3 }
  1593. ],
  1594. 3: [
  1595. function (require, module, exports) {
  1596. (function (setImmediate, clearImmediate) {
  1597. var nextTick = require('process/browser.js').nextTick;
  1598. var apply = Function.prototype.apply;
  1599. var slice = Array.prototype.slice;
  1600. var immediateIds = {};
  1601. var nextImmediateId = 0;
  1602. exports.setTimeout = function () {
  1603. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  1604. };
  1605. exports.setInterval = function () {
  1606. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  1607. };
  1608. exports.clearTimeout = exports.clearInterval = function (timeout) {
  1609. timeout.close();
  1610. };
  1611. function Timeout(id, clearFn) {
  1612. this._id = id;
  1613. this._clearFn = clearFn;
  1614. }
  1615. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  1616. };
  1617. Timeout.prototype.close = function () {
  1618. this._clearFn.call(window, this._id);
  1619. };
  1620. exports.enroll = function (item, msecs) {
  1621. clearTimeout(item._idleTimeoutId);
  1622. item._idleTimeout = msecs;
  1623. };
  1624. exports.unenroll = function (item) {
  1625. clearTimeout(item._idleTimeoutId);
  1626. item._idleTimeout = -1;
  1627. };
  1628. exports._unrefActive = exports.active = function (item) {
  1629. clearTimeout(item._idleTimeoutId);
  1630. var msecs = item._idleTimeout;
  1631. if (msecs >= 0) {
  1632. item._idleTimeoutId = setTimeout(function onTimeout() {
  1633. if (item._onTimeout)
  1634. item._onTimeout();
  1635. }, msecs);
  1636. }
  1637. };
  1638. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  1639. var id = nextImmediateId++;
  1640. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  1641. immediateIds[id] = true;
  1642. nextTick(function onNextTick() {
  1643. if (immediateIds[id]) {
  1644. if (args) {
  1645. fn.apply(null, args);
  1646. } else {
  1647. fn.call(null);
  1648. }
  1649. exports.clearImmediate(id);
  1650. }
  1651. });
  1652. return id;
  1653. };
  1654. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  1655. delete immediateIds[id];
  1656. };
  1657. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  1658. },
  1659. {
  1660. 'process/browser.js': 1,
  1661. 'timers': 3
  1662. }
  1663. ],
  1664. 4: [
  1665. function (require, module, exports) {
  1666. var promisePolyfill = require('promise-polyfill');
  1667. var Global = function () {
  1668. if (typeof window !== 'undefined') {
  1669. return window;
  1670. } else {
  1671. return Function('return this;')();
  1672. }
  1673. }();
  1674. module.exports = { boltExport: Global.Promise || promisePolyfill };
  1675. },
  1676. { 'promise-polyfill': 2 }
  1677. ]
  1678. }, {}, [4])(4);
  1679. }));
  1680. }(undefined, exports$1, module$1, undefined));
  1681. var Promise = module$1.exports.boltExport;
  1682. var nu$3 = function (baseFn) {
  1683. var data = Option.none();
  1684. var callbacks = [];
  1685. var map = function (f) {
  1686. return nu$3(function (nCallback) {
  1687. get(function (data) {
  1688. nCallback(f(data));
  1689. });
  1690. });
  1691. };
  1692. var get = function (nCallback) {
  1693. if (isReady()) {
  1694. call(nCallback);
  1695. } else {
  1696. callbacks.push(nCallback);
  1697. }
  1698. };
  1699. var set = function (x) {
  1700. data = Option.some(x);
  1701. run(callbacks);
  1702. callbacks = [];
  1703. };
  1704. var isReady = function () {
  1705. return data.isSome();
  1706. };
  1707. var run = function (cbs) {
  1708. each(cbs, call);
  1709. };
  1710. var call = function (cb) {
  1711. data.each(function (x) {
  1712. domGlobals.setTimeout(function () {
  1713. cb(x);
  1714. }, 0);
  1715. });
  1716. };
  1717. baseFn(set);
  1718. return {
  1719. get: get,
  1720. map: map,
  1721. isReady: isReady
  1722. };
  1723. };
  1724. var pure = function (a) {
  1725. return nu$3(function (callback) {
  1726. callback(a);
  1727. });
  1728. };
  1729. var LazyValue = {
  1730. nu: nu$3,
  1731. pure: pure
  1732. };
  1733. var errorReporter = function (err) {
  1734. domGlobals.setTimeout(function () {
  1735. throw err;
  1736. }, 0);
  1737. };
  1738. var make = function (run) {
  1739. var get = function (callback) {
  1740. run().then(callback, errorReporter);
  1741. };
  1742. var map = function (fab) {
  1743. return make(function () {
  1744. return run().then(fab);
  1745. });
  1746. };
  1747. var bind = function (aFutureB) {
  1748. return make(function () {
  1749. return run().then(function (v) {
  1750. return aFutureB(v).toPromise();
  1751. });
  1752. });
  1753. };
  1754. var anonBind = function (futureB) {
  1755. return make(function () {
  1756. return run().then(function () {
  1757. return futureB.toPromise();
  1758. });
  1759. });
  1760. };
  1761. var toLazy = function () {
  1762. return LazyValue.nu(get);
  1763. };
  1764. var toCached = function () {
  1765. var cache = null;
  1766. return make(function () {
  1767. if (cache === null) {
  1768. cache = run();
  1769. }
  1770. return cache;
  1771. });
  1772. };
  1773. var toPromise = run;
  1774. return {
  1775. map: map,
  1776. bind: bind,
  1777. anonBind: anonBind,
  1778. toLazy: toLazy,
  1779. toCached: toCached,
  1780. toPromise: toPromise,
  1781. get: get
  1782. };
  1783. };
  1784. var nu$4 = function (baseFn) {
  1785. return make(function () {
  1786. return new Promise(baseFn);
  1787. });
  1788. };
  1789. var pure$1 = function (a) {
  1790. return make(function () {
  1791. return Promise.resolve(a);
  1792. });
  1793. };
  1794. var Future = {
  1795. nu: nu$4,
  1796. pure: pure$1
  1797. };
  1798. var par = function (asyncValues, nu) {
  1799. return nu(function (callback) {
  1800. var r = [];
  1801. var count = 0;
  1802. var cb = function (i) {
  1803. return function (value) {
  1804. r[i] = value;
  1805. count++;
  1806. if (count >= asyncValues.length) {
  1807. callback(r);
  1808. }
  1809. };
  1810. };
  1811. if (asyncValues.length === 0) {
  1812. callback([]);
  1813. } else {
  1814. each(asyncValues, function (asyncValue, i) {
  1815. asyncValue.get(cb(i));
  1816. });
  1817. }
  1818. });
  1819. };
  1820. var par$1 = function (futures) {
  1821. return par(futures, Future.nu);
  1822. };
  1823. var value = function (o) {
  1824. var is = function (v) {
  1825. return o === v;
  1826. };
  1827. var or = function (opt) {
  1828. return value(o);
  1829. };
  1830. var orThunk = function (f) {
  1831. return value(o);
  1832. };
  1833. var map = function (f) {
  1834. return value(f(o));
  1835. };
  1836. var mapError = function (f) {
  1837. return value(o);
  1838. };
  1839. var each = function (f) {
  1840. f(o);
  1841. };
  1842. var bind = function (f) {
  1843. return f(o);
  1844. };
  1845. var fold = function (_, onValue) {
  1846. return onValue(o);
  1847. };
  1848. var exists = function (f) {
  1849. return f(o);
  1850. };
  1851. var forall = function (f) {
  1852. return f(o);
  1853. };
  1854. var toOption = function () {
  1855. return Option.some(o);
  1856. };
  1857. return {
  1858. is: is,
  1859. isValue: always,
  1860. isError: never,
  1861. getOr: constant(o),
  1862. getOrThunk: constant(o),
  1863. getOrDie: constant(o),
  1864. or: or,
  1865. orThunk: orThunk,
  1866. fold: fold,
  1867. map: map,
  1868. mapError: mapError,
  1869. each: each,
  1870. bind: bind,
  1871. exists: exists,
  1872. forall: forall,
  1873. toOption: toOption
  1874. };
  1875. };
  1876. var error = function (message) {
  1877. var getOrThunk = function (f) {
  1878. return f();
  1879. };
  1880. var getOrDie = function () {
  1881. return die(String(message))();
  1882. };
  1883. var or = function (opt) {
  1884. return opt;
  1885. };
  1886. var orThunk = function (f) {
  1887. return f();
  1888. };
  1889. var map = function (f) {
  1890. return error(message);
  1891. };
  1892. var mapError = function (f) {
  1893. return error(f(message));
  1894. };
  1895. var bind = function (f) {
  1896. return error(message);
  1897. };
  1898. var fold = function (onError, _) {
  1899. return onError(message);
  1900. };
  1901. return {
  1902. is: never,
  1903. isValue: never,
  1904. isError: always,
  1905. getOr: identity,
  1906. getOrThunk: getOrThunk,
  1907. getOrDie: getOrDie,
  1908. or: or,
  1909. orThunk: orThunk,
  1910. fold: fold,
  1911. map: map,
  1912. mapError: mapError,
  1913. each: noop,
  1914. bind: bind,
  1915. exists: never,
  1916. forall: always,
  1917. toOption: Option.none
  1918. };
  1919. };
  1920. var fromOption = function (opt, err) {
  1921. return opt.fold(function () {
  1922. return error(err);
  1923. }, value);
  1924. };
  1925. var Result = {
  1926. value: value,
  1927. error: error,
  1928. fromOption: fromOption
  1929. };
  1930. var promise = function () {
  1931. function bind(fn, thisArg) {
  1932. return function () {
  1933. fn.apply(thisArg, arguments);
  1934. };
  1935. }
  1936. var isArray = Array.isArray || function (value) {
  1937. return Object.prototype.toString.call(value) === '[object Array]';
  1938. };
  1939. var Promise = function (fn) {
  1940. if (typeof this !== 'object') {
  1941. throw new TypeError('Promises must be constructed via new');
  1942. }
  1943. if (typeof fn !== 'function') {
  1944. throw new TypeError('not a function');
  1945. }
  1946. this._state = null;
  1947. this._value = null;
  1948. this._deferreds = [];
  1949. doResolve(fn, bind(resolve, this), bind(reject, this));
  1950. };
  1951. var asap = Promise.immediateFn || typeof domGlobals.setImmediate === 'function' && domGlobals.setImmediate || function (fn) {
  1952. domGlobals.setTimeout(fn, 1);
  1953. };
  1954. function handle(deferred) {
  1955. var me = this;
  1956. if (this._state === null) {
  1957. this._deferreds.push(deferred);
  1958. return;
  1959. }
  1960. asap(function () {
  1961. var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
  1962. if (cb === null) {
  1963. (me._state ? deferred.resolve : deferred.reject)(me._value);
  1964. return;
  1965. }
  1966. var ret;
  1967. try {
  1968. ret = cb(me._value);
  1969. } catch (e) {
  1970. deferred.reject(e);
  1971. return;
  1972. }
  1973. deferred.resolve(ret);
  1974. });
  1975. }
  1976. function resolve(newValue) {
  1977. try {
  1978. if (newValue === this) {
  1979. throw new TypeError('A promise cannot be resolved with itself.');
  1980. }
  1981. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  1982. var then = newValue.then;
  1983. if (typeof then === 'function') {
  1984. doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
  1985. return;
  1986. }
  1987. }
  1988. this._state = true;
  1989. this._value = newValue;
  1990. finale.call(this);
  1991. } catch (e) {
  1992. reject.call(this, e);
  1993. }
  1994. }
  1995. function reject(newValue) {
  1996. this._state = false;
  1997. this._value = newValue;
  1998. finale.call(this);
  1999. }
  2000. function finale() {
  2001. for (var i = 0, len = this._deferreds.length; i < len; i++) {
  2002. handle.call(this, this._deferreds[i]);
  2003. }
  2004. this._deferreds = null;
  2005. }
  2006. function Handler(onFulfilled, onRejected, resolve, reject) {
  2007. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  2008. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  2009. this.resolve = resolve;
  2010. this.reject = reject;
  2011. }
  2012. function doResolve(fn, onFulfilled, onRejected) {
  2013. var done = false;
  2014. try {
  2015. fn(function (value) {
  2016. if (done) {
  2017. return;
  2018. }
  2019. done = true;
  2020. onFulfilled(value);
  2021. }, function (reason) {
  2022. if (done) {
  2023. return;
  2024. }
  2025. done = true;
  2026. onRejected(reason);
  2027. });
  2028. } catch (ex) {
  2029. if (done) {
  2030. return;
  2031. }
  2032. done = true;
  2033. onRejected(ex);
  2034. }
  2035. }
  2036. Promise.prototype.catch = function (onRejected) {
  2037. return this.then(null, onRejected);
  2038. };
  2039. Promise.prototype.then = function (onFulfilled, onRejected) {
  2040. var me = this;
  2041. return new Promise(function (resolve, reject) {
  2042. handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
  2043. });
  2044. };
  2045. Promise.all = function () {
  2046. var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
  2047. return new Promise(function (resolve, reject) {
  2048. if (args.length === 0) {
  2049. return resolve([]);
  2050. }
  2051. var remaining = args.length;
  2052. function res(i, val) {
  2053. try {
  2054. if (val && (typeof val === 'object' || typeof val === 'function')) {
  2055. var then = val.then;
  2056. if (typeof then === 'function') {
  2057. then.call(val, function (val) {
  2058. res(i, val);
  2059. }, reject);
  2060. return;
  2061. }
  2062. }
  2063. args[i] = val;
  2064. if (--remaining === 0) {
  2065. resolve(args);
  2066. }
  2067. } catch (ex) {
  2068. reject(ex);
  2069. }
  2070. }
  2071. for (var i = 0; i < args.length; i++) {
  2072. res(i, args[i]);
  2073. }
  2074. });
  2075. };
  2076. Promise.resolve = function (value) {
  2077. if (value && typeof value === 'object' && value.constructor === Promise) {
  2078. return value;
  2079. }
  2080. return new Promise(function (resolve) {
  2081. resolve(value);
  2082. });
  2083. };
  2084. Promise.reject = function (value) {
  2085. return new Promise(function (resolve, reject) {
  2086. reject(value);
  2087. });
  2088. };
  2089. Promise.race = function (values) {
  2090. return new Promise(function (resolve, reject) {
  2091. for (var i = 0, len = values.length; i < len; i++) {
  2092. values[i].then(resolve, reject);
  2093. }
  2094. });
  2095. };
  2096. return Promise;
  2097. };
  2098. var promiseObj = window.Promise ? window.Promise : promise();
  2099. var requestAnimationFramePromise;
  2100. var requestAnimationFrame = function (callback, element) {
  2101. var i, requestAnimationFrameFunc = domGlobals.window.requestAnimationFrame;
  2102. var vendors = [
  2103. 'ms',
  2104. 'moz',
  2105. 'webkit'
  2106. ];
  2107. var featurefill = function (callback) {
  2108. domGlobals.window.setTimeout(callback, 0);
  2109. };
  2110. for (i = 0; i < vendors.length && !requestAnimationFrameFunc; i++) {
  2111. requestAnimationFrameFunc = domGlobals.window[vendors[i] + 'RequestAnimationFrame'];
  2112. }
  2113. if (!requestAnimationFrameFunc) {
  2114. requestAnimationFrameFunc = featurefill;
  2115. }
  2116. requestAnimationFrameFunc(callback, element);
  2117. };
  2118. var wrappedSetTimeout = function (callback, time) {
  2119. if (typeof time !== 'number') {
  2120. time = 0;
  2121. }
  2122. return domGlobals.setTimeout(callback, time);
  2123. };
  2124. var wrappedSetInterval = function (callback, time) {
  2125. if (typeof time !== 'number') {
  2126. time = 1;
  2127. }
  2128. return domGlobals.setInterval(callback, time);
  2129. };
  2130. var wrappedClearTimeout = function (id) {
  2131. return domGlobals.clearTimeout(id);
  2132. };
  2133. var wrappedClearInterval = function (id) {
  2134. return domGlobals.clearInterval(id);
  2135. };
  2136. var debounce = function (callback, time) {
  2137. var timer, func;
  2138. func = function () {
  2139. var args = [];
  2140. for (var _i = 0; _i < arguments.length; _i++) {
  2141. args[_i] = arguments[_i];
  2142. }
  2143. domGlobals.clearTimeout(timer);
  2144. timer = wrappedSetTimeout(function () {
  2145. callback.apply(this, args);
  2146. }, time);
  2147. };
  2148. func.stop = function () {
  2149. domGlobals.clearTimeout(timer);
  2150. };
  2151. return func;
  2152. };
  2153. var Delay = {
  2154. requestAnimationFrame: function (callback, element) {
  2155. if (requestAnimationFramePromise) {
  2156. requestAnimationFramePromise.then(callback);
  2157. return;
  2158. }
  2159. requestAnimationFramePromise = new promiseObj(function (resolve) {
  2160. if (!element) {
  2161. element = domGlobals.document.body;
  2162. }
  2163. requestAnimationFrame(resolve, element);
  2164. }).then(callback);
  2165. },
  2166. setTimeout: wrappedSetTimeout,
  2167. setInterval: wrappedSetInterval,
  2168. setEditorTimeout: function (editor, callback, time) {
  2169. return wrappedSetTimeout(function () {
  2170. if (!editor.removed) {
  2171. callback();
  2172. }
  2173. }, time);
  2174. },
  2175. setEditorInterval: function (editor, callback, time) {
  2176. var timer;
  2177. timer = wrappedSetInterval(function () {
  2178. if (!editor.removed) {
  2179. callback();
  2180. } else {
  2181. domGlobals.clearInterval(timer);
  2182. }
  2183. }, time);
  2184. return timer;
  2185. },
  2186. debounce: debounce,
  2187. throttle: debounce,
  2188. clearInterval: wrappedClearInterval,
  2189. clearTimeout: wrappedClearTimeout
  2190. };
  2191. var userAgent = domGlobals.navigator.userAgent;
  2192. var platform$1 = detect$3();
  2193. var browser$2 = platform$1.browser;
  2194. var os = platform$1.os;
  2195. var deviceType = platform$1.deviceType;
  2196. var webkit = /WebKit/.test(userAgent) && !browser$2.isEdge();
  2197. var fileApi = 'FormData' in domGlobals.window && 'FileReader' in domGlobals.window && 'URL' in domGlobals.window && !!domGlobals.URL.createObjectURL;
  2198. var windowsPhone = userAgent.indexOf('Windows Phone') !== -1;
  2199. var Env = {
  2200. opera: browser$2.isOpera(),
  2201. webkit: webkit,
  2202. ie: browser$2.isIE() || browser$2.isEdge() ? browser$2.version.major : false,
  2203. gecko: browser$2.isFirefox(),
  2204. mac: os.isOSX() || os.isiOS(),
  2205. iOS: deviceType.isiPad() || deviceType.isiPhone(),
  2206. android: os.isAndroid(),
  2207. contentEditable: true,
  2208. transparentSrc: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  2209. caretAfter: true,
  2210. range: domGlobals.window.getSelection && 'Range' in domGlobals.window,
  2211. documentMode: browser$2.isIE() ? domGlobals.document.documentMode || 7 : 10,
  2212. fileApi: fileApi,
  2213. ceFalse: true,
  2214. cacheSuffix: null,
  2215. container: null,
  2216. experimentalShadowDom: false,
  2217. canHaveCSP: !browser$2.isIE(),
  2218. desktop: deviceType.isDesktop(),
  2219. windowsPhone: windowsPhone,
  2220. browser: {
  2221. current: browser$2.current,
  2222. version: browser$2.version,
  2223. isChrome: browser$2.isChrome,
  2224. isEdge: browser$2.isEdge,
  2225. isFirefox: browser$2.isFirefox,
  2226. isIE: browser$2.isIE,
  2227. isOpera: browser$2.isOpera,
  2228. isSafari: browser$2.isSafari
  2229. },
  2230. os: {
  2231. current: os.current,
  2232. version: os.version,
  2233. isAndroid: os.isAndroid,
  2234. isFreeBSD: os.isFreeBSD,
  2235. isiOS: os.isiOS,
  2236. isLinux: os.isLinux,
  2237. isOSX: os.isOSX,
  2238. isSolaris: os.isSolaris,
  2239. isWindows: os.isWindows
  2240. },
  2241. deviceType: {
  2242. isDesktop: deviceType.isDesktop,
  2243. isiPad: deviceType.isiPad,
  2244. isiPhone: deviceType.isiPhone,
  2245. isPhone: deviceType.isPhone,
  2246. isTablet: deviceType.isTablet,
  2247. isTouch: deviceType.isTouch,
  2248. isWebView: deviceType.isWebView
  2249. }
  2250. };
  2251. var isArray$1 = Array.isArray;
  2252. var toArray$1 = function (obj) {
  2253. var array = obj, i, l;
  2254. if (!isArray$1(obj)) {
  2255. array = [];
  2256. for (i = 0, l = obj.length; i < l; i++) {
  2257. array[i] = obj[i];
  2258. }
  2259. }
  2260. return array;
  2261. };
  2262. var each$2 = function (o, cb, s) {
  2263. var n, l;
  2264. if (!o) {
  2265. return 0;
  2266. }
  2267. s = s || o;
  2268. if (o.length !== undefined) {
  2269. for (n = 0, l = o.length; n < l; n++) {
  2270. if (cb.call(s, o[n], n, o) === false) {
  2271. return 0;
  2272. }
  2273. }
  2274. } else {
  2275. for (n in o) {
  2276. if (o.hasOwnProperty(n)) {
  2277. if (cb.call(s, o[n], n, o) === false) {
  2278. return 0;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. return 1;
  2284. };
  2285. var map$2 = function (array, callback) {
  2286. var out = [];
  2287. each$2(array, function (item, index) {
  2288. out.push(callback(item, index, array));
  2289. });
  2290. return out;
  2291. };
  2292. var filter$1 = function (a, f) {
  2293. var o = [];
  2294. each$2(a, function (v, index) {
  2295. if (!f || f(v, index, a)) {
  2296. o.push(v);
  2297. }
  2298. });
  2299. return o;
  2300. };
  2301. var indexOf$1 = function (a, v) {
  2302. var i, l;
  2303. if (a) {
  2304. for (i = 0, l = a.length; i < l; i++) {
  2305. if (a[i] === v) {
  2306. return i;
  2307. }
  2308. }
  2309. }
  2310. return -1;
  2311. };
  2312. var reduce = function (collection, iteratee, accumulator, thisArg) {
  2313. var i = 0;
  2314. if (arguments.length < 3) {
  2315. accumulator = collection[0];
  2316. }
  2317. for (; i < collection.length; i++) {
  2318. accumulator = iteratee.call(thisArg, accumulator, collection[i], i);
  2319. }
  2320. return accumulator;
  2321. };
  2322. var findIndex$1 = function (array, predicate, thisArg) {
  2323. var i, l;
  2324. for (i = 0, l = array.length; i < l; i++) {
  2325. if (predicate.call(thisArg, array[i], i, array)) {
  2326. return i;
  2327. }
  2328. }
  2329. return -1;
  2330. };
  2331. var find$2 = function (array, predicate, thisArg) {
  2332. var idx = findIndex$1(array, predicate, thisArg);
  2333. if (idx !== -1) {
  2334. return array[idx];
  2335. }
  2336. return undefined;
  2337. };
  2338. var last$1 = function (collection) {
  2339. return collection[collection.length - 1];
  2340. };
  2341. var ArrUtils = {
  2342. isArray: isArray$1,
  2343. toArray: toArray$1,
  2344. each: each$2,
  2345. map: map$2,
  2346. filter: filter$1,
  2347. indexOf: indexOf$1,
  2348. reduce: reduce,
  2349. findIndex: findIndex$1,
  2350. find: find$2,
  2351. last: last$1
  2352. };
  2353. var whiteSpaceRegExp = /^\s*|\s*$/g;
  2354. var trim$1 = function (str) {
  2355. return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp, '');
  2356. };
  2357. var is$1 = function (obj, type) {
  2358. if (!type) {
  2359. return obj !== undefined;
  2360. }
  2361. if (type === 'array' && ArrUtils.isArray(obj)) {
  2362. return true;
  2363. }
  2364. return typeof obj === type;
  2365. };
  2366. var makeMap = function (items, delim, map) {
  2367. var i;
  2368. items = items || [];
  2369. delim = delim || ',';
  2370. if (typeof items === 'string') {
  2371. items = items.split(delim);
  2372. }
  2373. map = map || {};
  2374. i = items.length;
  2375. while (i--) {
  2376. map[items[i]] = {};
  2377. }
  2378. return map;
  2379. };
  2380. var hasOwnProperty$1 = function (obj, prop) {
  2381. return Object.prototype.hasOwnProperty.call(obj, prop);
  2382. };
  2383. var create = function (s, p, root) {
  2384. var self = this;
  2385. var sp, ns, cn, scn, c, de = 0;
  2386. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  2387. cn = s[3].match(/(^|\.)(\w+)$/i)[2];
  2388. ns = self.createNS(s[3].replace(/\.\w+$/, ''), root);
  2389. if (ns[cn]) {
  2390. return;
  2391. }
  2392. if (s[2] === 'static') {
  2393. ns[cn] = p;
  2394. if (this.onCreate) {
  2395. this.onCreate(s[2], s[3], ns[cn]);
  2396. }
  2397. return;
  2398. }
  2399. if (!p[cn]) {
  2400. p[cn] = function () {
  2401. };
  2402. de = 1;
  2403. }
  2404. ns[cn] = p[cn];
  2405. self.extend(ns[cn].prototype, p);
  2406. if (s[5]) {
  2407. sp = self.resolve(s[5]).prototype;
  2408. scn = s[5].match(/\.(\w+)$/i)[1];
  2409. c = ns[cn];
  2410. if (de) {
  2411. ns[cn] = function () {
  2412. return sp[scn].apply(this, arguments);
  2413. };
  2414. } else {
  2415. ns[cn] = function () {
  2416. this.parent = sp[scn];
  2417. return c.apply(this, arguments);
  2418. };
  2419. }
  2420. ns[cn].prototype[cn] = ns[cn];
  2421. self.each(sp, function (f, n) {
  2422. ns[cn].prototype[n] = sp[n];
  2423. });
  2424. self.each(p, function (f, n) {
  2425. if (sp[n]) {
  2426. ns[cn].prototype[n] = function () {
  2427. this.parent = sp[n];
  2428. return f.apply(this, arguments);
  2429. };
  2430. } else {
  2431. if (n !== cn) {
  2432. ns[cn].prototype[n] = f;
  2433. }
  2434. }
  2435. });
  2436. }
  2437. self.each(p.static, function (f, n) {
  2438. ns[cn][n] = f;
  2439. });
  2440. };
  2441. var extend = function (obj, ext) {
  2442. var x = [];
  2443. for (var _i = 2; _i < arguments.length; _i++) {
  2444. x[_i - 2] = arguments[_i];
  2445. }
  2446. var i, l, name;
  2447. var args = arguments;
  2448. var value;
  2449. for (i = 1, l = args.length; i < l; i++) {
  2450. ext = args[i];
  2451. for (name in ext) {
  2452. if (ext.hasOwnProperty(name)) {
  2453. value = ext[name];
  2454. if (value !== undefined) {
  2455. obj[name] = value;
  2456. }
  2457. }
  2458. }
  2459. }
  2460. return obj;
  2461. };
  2462. var walk = function (o, f, n, s) {
  2463. s = s || this;
  2464. if (o) {
  2465. if (n) {
  2466. o = o[n];
  2467. }
  2468. ArrUtils.each(o, function (o, i) {
  2469. if (f.call(s, o, i, n) === false) {
  2470. return false;
  2471. }
  2472. walk(o, f, n, s);
  2473. });
  2474. }
  2475. };
  2476. var createNS = function (n, o) {
  2477. var i, v;
  2478. o = o || domGlobals.window;
  2479. n = n.split('.');
  2480. for (i = 0; i < n.length; i++) {
  2481. v = n[i];
  2482. if (!o[v]) {
  2483. o[v] = {};
  2484. }
  2485. o = o[v];
  2486. }
  2487. return o;
  2488. };
  2489. var resolve = function (n, o) {
  2490. var i, l;
  2491. o = o || domGlobals.window;
  2492. n = n.split('.');
  2493. for (i = 0, l = n.length; i < l; i++) {
  2494. o = o[n[i]];
  2495. if (!o) {
  2496. break;
  2497. }
  2498. }
  2499. return o;
  2500. };
  2501. var explode = function (s, d) {
  2502. if (!s || is$1(s, 'array')) {
  2503. return s;
  2504. }
  2505. return ArrUtils.map(s.split(d || ','), trim$1);
  2506. };
  2507. var _addCacheSuffix = function (url) {
  2508. var cacheSuffix = Env.cacheSuffix;
  2509. if (cacheSuffix) {
  2510. url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix;
  2511. }
  2512. return url;
  2513. };
  2514. var Tools = {
  2515. trim: trim$1,
  2516. isArray: ArrUtils.isArray,
  2517. is: is$1,
  2518. toArray: ArrUtils.toArray,
  2519. makeMap: makeMap,
  2520. each: ArrUtils.each,
  2521. map: ArrUtils.map,
  2522. grep: ArrUtils.filter,
  2523. inArray: ArrUtils.indexOf,
  2524. hasOwn: hasOwnProperty$1,
  2525. extend: extend,
  2526. create: create,
  2527. walk: walk,
  2528. createNS: createNS,
  2529. resolve: resolve,
  2530. explode: explode,
  2531. _addCacheSuffix: _addCacheSuffix
  2532. };
  2533. function StyleSheetLoader(document, settings) {
  2534. if (settings === void 0) {
  2535. settings = {};
  2536. }
  2537. var idCount = 0;
  2538. var loadedStates = {};
  2539. var maxLoadTime;
  2540. maxLoadTime = settings.maxLoadTime || 5000;
  2541. var _setReferrerPolicy = function (referrerPolicy) {
  2542. settings.referrerPolicy = referrerPolicy;
  2543. };
  2544. var appendToHead = function (node) {
  2545. document.getElementsByTagName('head')[0].appendChild(node);
  2546. };
  2547. var load = function (url, loadedCallback, errorCallback) {
  2548. var link, style, startTime, state;
  2549. var resolve = function (status) {
  2550. state.status = status;
  2551. state.passed = [];
  2552. state.failed = [];
  2553. if (link) {
  2554. link.onload = null;
  2555. link.onerror = null;
  2556. link = null;
  2557. }
  2558. };
  2559. var passed = function () {
  2560. var callbacks = state.passed;
  2561. var i = callbacks.length;
  2562. while (i--) {
  2563. callbacks[i]();
  2564. }
  2565. resolve(2);
  2566. };
  2567. var failed = function () {
  2568. var callbacks = state.failed;
  2569. var i = callbacks.length;
  2570. while (i--) {
  2571. callbacks[i]();
  2572. }
  2573. resolve(3);
  2574. };
  2575. var isOldWebKit = function () {
  2576. var webKitChunks = domGlobals.navigator.userAgent.match(/WebKit\/(\d*)/);
  2577. return !!(webKitChunks && parseInt(webKitChunks[1], 10) < 536);
  2578. };
  2579. var wait = function (testCallback, waitCallback) {
  2580. if (!testCallback()) {
  2581. if (new Date().getTime() - startTime < maxLoadTime) {
  2582. Delay.setTimeout(waitCallback);
  2583. } else {
  2584. failed();
  2585. }
  2586. }
  2587. };
  2588. var waitForWebKitLinkLoaded = function () {
  2589. wait(function () {
  2590. var styleSheets = document.styleSheets;
  2591. var styleSheet, i = styleSheets.length, owner;
  2592. while (i--) {
  2593. styleSheet = styleSheets[i];
  2594. owner = styleSheet.ownerNode ? styleSheet.ownerNode : styleSheet.owningElement;
  2595. if (owner && owner.id === link.id) {
  2596. passed();
  2597. return true;
  2598. }
  2599. }
  2600. }, waitForWebKitLinkLoaded);
  2601. };
  2602. var waitForGeckoLinkLoaded = function () {
  2603. wait(function () {
  2604. try {
  2605. var cssRules = style.sheet.cssRules;
  2606. passed();
  2607. return !!cssRules;
  2608. } catch (ex) {
  2609. }
  2610. }, waitForGeckoLinkLoaded);
  2611. };
  2612. url = Tools._addCacheSuffix(url);
  2613. if (!loadedStates[url]) {
  2614. state = {
  2615. passed: [],
  2616. failed: []
  2617. };
  2618. loadedStates[url] = state;
  2619. } else {
  2620. state = loadedStates[url];
  2621. }
  2622. if (loadedCallback) {
  2623. state.passed.push(loadedCallback);
  2624. }
  2625. if (errorCallback) {
  2626. state.failed.push(errorCallback);
  2627. }
  2628. if (state.status === 1) {
  2629. return;
  2630. }
  2631. if (state.status === 2) {
  2632. passed();
  2633. return;
  2634. }
  2635. if (state.status === 3) {
  2636. failed();
  2637. return;
  2638. }
  2639. state.status = 1;
  2640. link = document.createElement('link');
  2641. link.rel = 'stylesheet';
  2642. link.type = 'text/css';
  2643. link.id = 'u' + idCount++;
  2644. link.async = false;
  2645. link.defer = false;
  2646. startTime = new Date().getTime();
  2647. if (settings.contentCssCors) {
  2648. link.crossOrigin = 'anonymous';
  2649. }
  2650. if (settings.referrerPolicy) {
  2651. set(Element.fromDom(link), 'referrerpolicy', settings.referrerPolicy);
  2652. }
  2653. if ('onload' in link && !isOldWebKit()) {
  2654. link.onload = waitForWebKitLinkLoaded;
  2655. link.onerror = failed;
  2656. } else {
  2657. if (domGlobals.navigator.userAgent.indexOf('Firefox') > 0) {
  2658. style = document.createElement('style');
  2659. style.textContent = '@import "' + url + '"';
  2660. waitForGeckoLinkLoaded();
  2661. appendToHead(style);
  2662. return;
  2663. }
  2664. waitForWebKitLinkLoaded();
  2665. }
  2666. appendToHead(link);
  2667. link.href = url;
  2668. };
  2669. var loadF = function (url) {
  2670. return Future.nu(function (resolve) {
  2671. load(url, compose(resolve, constant(Result.value(url))), compose(resolve, constant(Result.error(url))));
  2672. });
  2673. };
  2674. var unbox = function (result) {
  2675. return result.fold(identity, identity);
  2676. };
  2677. var loadAll = function (urls, success, failure) {
  2678. par$1(map(urls, loadF)).get(function (result) {
  2679. var parts = partition(result, function (r) {
  2680. return r.isValue();
  2681. });
  2682. if (parts.fail.length > 0) {
  2683. failure(parts.fail.map(unbox));
  2684. } else {
  2685. success(parts.pass.map(unbox));
  2686. }
  2687. });
  2688. };
  2689. return {
  2690. load: load,
  2691. loadAll: loadAll,
  2692. _setReferrerPolicy: _setReferrerPolicy
  2693. };
  2694. }
  2695. var blocks = [
  2696. 'article',
  2697. 'aside',
  2698. 'details',
  2699. 'div',
  2700. 'dt',
  2701. 'figcaption',
  2702. 'footer',
  2703. 'form',
  2704. 'fieldset',
  2705. 'header',
  2706. 'hgroup',
  2707. 'html',
  2708. 'main',
  2709. 'nav',
  2710. 'section',
  2711. 'summary',
  2712. 'body',
  2713. 'p',
  2714. 'dl',
  2715. 'multicol',
  2716. 'dd',
  2717. 'figure',
  2718. 'address',
  2719. 'center',
  2720. 'blockquote',
  2721. 'h1',
  2722. 'h2',
  2723. 'h3',
  2724. 'h4',
  2725. 'h5',
  2726. 'h6',
  2727. 'listing',
  2728. 'xmp',
  2729. 'pre',
  2730. 'plaintext',
  2731. 'menu',
  2732. 'dir',
  2733. 'ul',
  2734. 'ol',
  2735. 'li',
  2736. 'hr',
  2737. 'table',
  2738. 'tbody',
  2739. 'thead',
  2740. 'tfoot',
  2741. 'th',
  2742. 'tr',
  2743. 'td',
  2744. 'caption'
  2745. ];
  2746. var voids = [
  2747. 'area',
  2748. 'base',
  2749. 'basefont',
  2750. 'br',
  2751. 'col',
  2752. 'frame',
  2753. 'hr',
  2754. 'img',
  2755. 'input',
  2756. 'isindex',
  2757. 'link',
  2758. 'meta',
  2759. 'param',
  2760. 'embed',
  2761. 'source',
  2762. 'wbr',
  2763. 'track'
  2764. ];
  2765. var tableCells = [
  2766. 'td',
  2767. 'th'
  2768. ];
  2769. var tableSections = [
  2770. 'thead',
  2771. 'tbody',
  2772. 'tfoot'
  2773. ];
  2774. var textBlocks = [
  2775. 'h1',
  2776. 'h2',
  2777. 'h3',
  2778. 'h4',
  2779. 'h5',
  2780. 'h6',
  2781. 'p',
  2782. 'div',
  2783. 'address',
  2784. 'pre',
  2785. 'form',
  2786. 'blockquote',
  2787. 'center',
  2788. 'dir',
  2789. 'fieldset',
  2790. 'header',
  2791. 'footer',
  2792. 'article',
  2793. 'section',
  2794. 'hgroup',
  2795. 'aside',
  2796. 'nav',
  2797. 'figure'
  2798. ];
  2799. var headings = [
  2800. 'h1',
  2801. 'h2',
  2802. 'h3',
  2803. 'h4',
  2804. 'h5',
  2805. 'h6'
  2806. ];
  2807. var listItems = [
  2808. 'li',
  2809. 'dd',
  2810. 'dt'
  2811. ];
  2812. var lists = [
  2813. 'ul',
  2814. 'ol',
  2815. 'dl'
  2816. ];
  2817. var wsElements = [
  2818. 'pre',
  2819. 'script',
  2820. 'textarea',
  2821. 'style'
  2822. ];
  2823. var lazyLookup = function (items) {
  2824. var lookup;
  2825. return function (node) {
  2826. lookup = lookup ? lookup : mapToObject(items, constant(true));
  2827. return lookup.hasOwnProperty(name(node));
  2828. };
  2829. };
  2830. var isHeading = lazyLookup(headings);
  2831. var isBlock = lazyLookup(blocks);
  2832. var isTable$1 = function (node) {
  2833. return name(node) === 'table';
  2834. };
  2835. var isInline = function (node) {
  2836. return isElement$1(node) && !isBlock(node);
  2837. };
  2838. var isBr$1 = function (node) {
  2839. return isElement$1(node) && name(node) === 'br';
  2840. };
  2841. var isTextBlock = lazyLookup(textBlocks);
  2842. var isList = lazyLookup(lists);
  2843. var isListItem = lazyLookup(listItems);
  2844. var isVoid = lazyLookup(voids);
  2845. var isTableSection = lazyLookup(tableSections);
  2846. var isTableCell = lazyLookup(tableCells);
  2847. var isWsPreserveElement = lazyLookup(wsElements);
  2848. var surroundedBySpans = function (node) {
  2849. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName === 'SPAN';
  2850. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName === 'SPAN';
  2851. return previousIsSpan && nextIsSpan;
  2852. };
  2853. var isBookmarkNode = function (node) {
  2854. return node && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark';
  2855. };
  2856. var trimNode = function (dom, node) {
  2857. var i, children = node.childNodes;
  2858. if (NodeType.isElement(node) && isBookmarkNode(node)) {
  2859. return;
  2860. }
  2861. for (i = children.length - 1; i >= 0; i--) {
  2862. trimNode(dom, children[i]);
  2863. }
  2864. if (NodeType.isDocument(node) === false) {
  2865. if (NodeType.isText(node) && node.nodeValue.length > 0) {
  2866. var trimmedLength = Tools.trim(node.nodeValue).length;
  2867. if (dom.isBlock(node.parentNode) || trimmedLength > 0) {
  2868. return;
  2869. }
  2870. if (trimmedLength === 0 && surroundedBySpans(node)) {
  2871. return;
  2872. }
  2873. } else if (NodeType.isElement(node)) {
  2874. children = node.childNodes;
  2875. if (children.length === 1 && isBookmarkNode(children[0])) {
  2876. node.parentNode.insertBefore(children[0], node);
  2877. }
  2878. if (children.length || isVoid(Element.fromDom(node))) {
  2879. return;
  2880. }
  2881. }
  2882. dom.remove(node);
  2883. }
  2884. return node;
  2885. };
  2886. var TrimNode = { trimNode: trimNode };
  2887. var makeMap$1 = Tools.makeMap;
  2888. var namedEntities, baseEntities, reverseEntities;
  2889. var attrsCharsRegExp = /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  2890. var textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  2891. var rawCharsRegExp = /[<>&\"\']/g;
  2892. var entityRegExp = /&#([a-z0-9]+);?|&([a-z0-9]+);/gi;
  2893. var asciiMap = {
  2894. 128: '\u20AC',
  2895. 130: '\u201A',
  2896. 131: '\u0192',
  2897. 132: '\u201E',
  2898. 133: '\u2026',
  2899. 134: '\u2020',
  2900. 135: '\u2021',
  2901. 136: '\u02c6',
  2902. 137: '\u2030',
  2903. 138: '\u0160',
  2904. 139: '\u2039',
  2905. 140: '\u0152',
  2906. 142: '\u017d',
  2907. 145: '\u2018',
  2908. 146: '\u2019',
  2909. 147: '\u201C',
  2910. 148: '\u201D',
  2911. 149: '\u2022',
  2912. 150: '\u2013',
  2913. 151: '\u2014',
  2914. 152: '\u02DC',
  2915. 153: '\u2122',
  2916. 154: '\u0161',
  2917. 155: '\u203A',
  2918. 156: '\u0153',
  2919. 158: '\u017e',
  2920. 159: '\u0178'
  2921. };
  2922. baseEntities = {
  2923. '"': '&quot;',
  2924. '\'': '&#39;',
  2925. '<': '&lt;',
  2926. '>': '&gt;',
  2927. '&': '&amp;',
  2928. '`': '&#96;'
  2929. };
  2930. reverseEntities = {
  2931. '&lt;': '<',
  2932. '&gt;': '>',
  2933. '&amp;': '&',
  2934. '&quot;': '"',
  2935. '&apos;': '\''
  2936. };
  2937. var nativeDecode = function (text) {
  2938. var elm;
  2939. elm = Element.fromTag('div').dom();
  2940. elm.innerHTML = text;
  2941. return elm.textContent || elm.innerText || text;
  2942. };
  2943. var buildEntitiesLookup = function (items, radix) {
  2944. var i, chr, entity;
  2945. var lookup = {};
  2946. if (items) {
  2947. items = items.split(',');
  2948. radix = radix || 10;
  2949. for (i = 0; i < items.length; i += 2) {
  2950. chr = String.fromCharCode(parseInt(items[i], radix));
  2951. if (!baseEntities[chr]) {
  2952. entity = '&' + items[i + 1] + ';';
  2953. lookup[chr] = entity;
  2954. lookup[entity] = chr;
  2955. }
  2956. }
  2957. return lookup;
  2958. }
  2959. };
  2960. namedEntities = buildEntitiesLookup('50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' + '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' + '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' + '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' + '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' + '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' + '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' + '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' + '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' + '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' + 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' + 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' + 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' + 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' + 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' + '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' + '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' + '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' + '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' + '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' + 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' + 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' + 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' + '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' + '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
  2961. var encodeRaw = function (text, attr) {
  2962. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2963. return baseEntities[chr] || chr;
  2964. });
  2965. };
  2966. var encodeAllRaw = function (text) {
  2967. return ('' + text).replace(rawCharsRegExp, function (chr) {
  2968. return baseEntities[chr] || chr;
  2969. });
  2970. };
  2971. var encodeNumeric = function (text, attr) {
  2972. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2973. if (chr.length > 1) {
  2974. return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';
  2975. }
  2976. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  2977. });
  2978. };
  2979. var encodeNamed = function (text, attr, entities) {
  2980. entities = entities || namedEntities;
  2981. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2982. return baseEntities[chr] || entities[chr] || chr;
  2983. });
  2984. };
  2985. var getEncodeFunc = function (name, entities) {
  2986. var entitiesMap = buildEntitiesLookup(entities) || namedEntities;
  2987. var encodeNamedAndNumeric = function (text, attr) {
  2988. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2989. if (baseEntities[chr] !== undefined) {
  2990. return baseEntities[chr];
  2991. }
  2992. if (entitiesMap[chr] !== undefined) {
  2993. return entitiesMap[chr];
  2994. }
  2995. if (chr.length > 1) {
  2996. return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';
  2997. }
  2998. return '&#' + chr.charCodeAt(0) + ';';
  2999. });
  3000. };
  3001. var encodeCustomNamed = function (text, attr) {
  3002. return encodeNamed(text, attr, entitiesMap);
  3003. };
  3004. var nameMap = makeMap$1(name.replace(/\+/g, ','));
  3005. if (nameMap.named && nameMap.numeric) {
  3006. return encodeNamedAndNumeric;
  3007. }
  3008. if (nameMap.named) {
  3009. if (entities) {
  3010. return encodeCustomNamed;
  3011. }
  3012. return encodeNamed;
  3013. }
  3014. if (nameMap.numeric) {
  3015. return encodeNumeric;
  3016. }
  3017. return encodeRaw;
  3018. };
  3019. var decode = function (text) {
  3020. return text.replace(entityRegExp, function (all, numeric) {
  3021. if (numeric) {
  3022. if (numeric.charAt(0).toLowerCase() === 'x') {
  3023. numeric = parseInt(numeric.substr(1), 16);
  3024. } else {
  3025. numeric = parseInt(numeric, 10);
  3026. }
  3027. if (numeric > 65535) {
  3028. numeric -= 65536;
  3029. return String.fromCharCode(55296 + (numeric >> 10), 56320 + (numeric & 1023));
  3030. }
  3031. return asciiMap[numeric] || String.fromCharCode(numeric);
  3032. }
  3033. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  3034. });
  3035. };
  3036. var Entities = {
  3037. encodeRaw: encodeRaw,
  3038. encodeAllRaw: encodeAllRaw,
  3039. encodeNumeric: encodeNumeric,
  3040. encodeNamed: encodeNamed,
  3041. getEncodeFunc: getEncodeFunc,
  3042. decode: decode
  3043. };
  3044. var mapCache = {}, dummyObj = {};
  3045. var makeMap$2 = Tools.makeMap, each$3 = Tools.each, extend$1 = Tools.extend, explode$1 = Tools.explode, inArray = Tools.inArray;
  3046. var split = function (items, delim) {
  3047. items = Tools.trim(items);
  3048. return items ? items.split(delim || ' ') : [];
  3049. };
  3050. var compileSchema = function (type) {
  3051. var schema = {};
  3052. var globalAttributes, blockContent;
  3053. var phrasingContent, flowContent, html4BlockContent, html4PhrasingContent;
  3054. var add = function (name, attributes, children) {
  3055. var ni, attributesOrder, element;
  3056. var arrayToMap = function (array, obj) {
  3057. var map = {};
  3058. var i, l;
  3059. for (i = 0, l = array.length; i < l; i++) {
  3060. map[array[i]] = obj || {};
  3061. }
  3062. return map;
  3063. };
  3064. children = children || [];
  3065. attributes = attributes || '';
  3066. if (typeof children === 'string') {
  3067. children = split(children);
  3068. }
  3069. name = split(name);
  3070. ni = name.length;
  3071. while (ni--) {
  3072. attributesOrder = split([
  3073. globalAttributes,
  3074. attributes
  3075. ].join(' '));
  3076. element = {
  3077. attributes: arrayToMap(attributesOrder),
  3078. attributesOrder: attributesOrder,
  3079. children: arrayToMap(children, dummyObj)
  3080. };
  3081. schema[name[ni]] = element;
  3082. }
  3083. };
  3084. var addAttrs = function (name, attributes) {
  3085. var ni, schemaItem, i, l;
  3086. name = split(name);
  3087. ni = name.length;
  3088. attributes = split(attributes);
  3089. while (ni--) {
  3090. schemaItem = schema[name[ni]];
  3091. for (i = 0, l = attributes.length; i < l; i++) {
  3092. schemaItem.attributes[attributes[i]] = {};
  3093. schemaItem.attributesOrder.push(attributes[i]);
  3094. }
  3095. }
  3096. };
  3097. if (mapCache[type]) {
  3098. return mapCache[type];
  3099. }
  3100. globalAttributes = 'id accesskey class dir lang style tabindex title role';
  3101. blockContent = 'address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul';
  3102. phrasingContent = 'a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd ' + 'label map noscript object q s samp script select small span strong sub sup ' + 'textarea u var #text #comment';
  3103. if (type !== 'html4') {
  3104. globalAttributes += ' contenteditable contextmenu draggable dropzone ' + 'hidden spellcheck translate';
  3105. blockContent += ' article aside details dialog figure main header footer hgroup section nav';
  3106. phrasingContent += ' audio canvas command datalist mark meter output picture ' + 'progress time wbr video ruby bdi keygen';
  3107. }
  3108. if (type !== 'html5-strict') {
  3109. globalAttributes += ' xml:lang';
  3110. html4PhrasingContent = 'acronym applet basefont big font strike tt';
  3111. phrasingContent = [
  3112. phrasingContent,
  3113. html4PhrasingContent
  3114. ].join(' ');
  3115. each$3(split(html4PhrasingContent), function (name) {
  3116. add(name, '', phrasingContent);
  3117. });
  3118. html4BlockContent = 'center dir isindex noframes';
  3119. blockContent = [
  3120. blockContent,
  3121. html4BlockContent
  3122. ].join(' ');
  3123. flowContent = [
  3124. blockContent,
  3125. phrasingContent
  3126. ].join(' ');
  3127. each$3(split(html4BlockContent), function (name) {
  3128. add(name, '', flowContent);
  3129. });
  3130. }
  3131. flowContent = flowContent || [
  3132. blockContent,
  3133. phrasingContent
  3134. ].join(' ');
  3135. add('html', 'manifest', 'head body');
  3136. add('head', '', 'base command link meta noscript script style title');
  3137. add('title hr noscript br');
  3138. add('base', 'href target');
  3139. add('link', 'href rel media hreflang type sizes hreflang');
  3140. add('meta', 'name http-equiv content charset');
  3141. add('style', 'media type scoped');
  3142. add('script', 'src async defer type charset');
  3143. add('body', 'onafterprint onbeforeprint onbeforeunload onblur onerror onfocus ' + 'onhashchange onload onmessage onoffline ononline onpagehide onpageshow ' + 'onpopstate onresize onscroll onstorage onunload', flowContent);
  3144. add('address dt dd div caption', '', flowContent);
  3145. add('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', '', phrasingContent);
  3146. add('blockquote', 'cite', flowContent);
  3147. add('ol', 'reversed start type', 'li');
  3148. add('ul', '', 'li');
  3149. add('li', 'value', flowContent);
  3150. add('dl', '', 'dt dd');
  3151. add('a', 'href target rel media hreflang type', phrasingContent);
  3152. add('q', 'cite', phrasingContent);
  3153. add('ins del', 'cite datetime', flowContent);
  3154. add('img', 'src sizes srcset alt usemap ismap width height');
  3155. add('iframe', 'src name width height', flowContent);
  3156. add('embed', 'src type width height');
  3157. add('object', 'data type typemustmatch name usemap form width height', [
  3158. flowContent,
  3159. 'param'
  3160. ].join(' '));
  3161. add('param', 'name value');
  3162. add('map', 'name', [
  3163. flowContent,
  3164. 'area'
  3165. ].join(' '));
  3166. add('area', 'alt coords shape href target rel media hreflang type');
  3167. add('table', 'border', 'caption colgroup thead tfoot tbody tr' + (type === 'html4' ? ' col' : ''));
  3168. add('colgroup', 'span', 'col');
  3169. add('col', 'span');
  3170. add('tbody thead tfoot', '', 'tr');
  3171. add('tr', '', 'td th');
  3172. add('td', 'colspan rowspan headers', flowContent);
  3173. add('th', 'colspan rowspan headers scope abbr', flowContent);
  3174. add('form', 'accept-charset action autocomplete enctype method name novalidate target', flowContent);
  3175. add('fieldset', 'disabled form name', [
  3176. flowContent,
  3177. 'legend'
  3178. ].join(' '));
  3179. add('label', 'form for', phrasingContent);
  3180. add('input', 'accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate ' + 'formtarget height list max maxlength min multiple name pattern readonly required size src step type value width');
  3181. add('button', 'disabled form formaction formenctype formmethod formnovalidate formtarget name type value', type === 'html4' ? flowContent : phrasingContent);
  3182. add('select', 'disabled form multiple name required size', 'option optgroup');
  3183. add('optgroup', 'disabled label', 'option');
  3184. add('option', 'disabled label selected value');
  3185. add('textarea', 'cols dirname disabled form maxlength name readonly required rows wrap');
  3186. add('menu', 'type label', [
  3187. flowContent,
  3188. 'li'
  3189. ].join(' '));
  3190. add('noscript', '', flowContent);
  3191. if (type !== 'html4') {
  3192. add('wbr');
  3193. add('ruby', '', [
  3194. phrasingContent,
  3195. 'rt rp'
  3196. ].join(' '));
  3197. add('figcaption', '', flowContent);
  3198. add('mark rt rp summary bdi', '', phrasingContent);
  3199. add('canvas', 'width height', flowContent);
  3200. add('video', 'src crossorigin poster preload autoplay mediagroup loop ' + 'muted controls width height buffered', [
  3201. flowContent,
  3202. 'track source'
  3203. ].join(' '));
  3204. add('audio', 'src crossorigin preload autoplay mediagroup loop muted controls ' + 'buffered volume', [
  3205. flowContent,
  3206. 'track source'
  3207. ].join(' '));
  3208. add('picture', '', 'img source');
  3209. add('source', 'src srcset type media sizes');
  3210. add('track', 'kind src srclang label default');
  3211. add('datalist', '', [
  3212. phrasingContent,
  3213. 'option'
  3214. ].join(' '));
  3215. add('article section nav aside main header footer', '', flowContent);
  3216. add('hgroup', '', 'h1 h2 h3 h4 h5 h6');
  3217. add('figure', '', [
  3218. flowContent,
  3219. 'figcaption'
  3220. ].join(' '));
  3221. add('time', 'datetime', phrasingContent);
  3222. add('dialog', 'open', flowContent);
  3223. add('command', 'type label icon disabled checked radiogroup command');
  3224. add('output', 'for form name', phrasingContent);
  3225. add('progress', 'value max', phrasingContent);
  3226. add('meter', 'value min max low high optimum', phrasingContent);
  3227. add('details', 'open', [
  3228. flowContent,
  3229. 'summary'
  3230. ].join(' '));
  3231. add('keygen', 'autofocus challenge disabled form keytype name');
  3232. }
  3233. if (type !== 'html5-strict') {
  3234. addAttrs('script', 'language xml:space');
  3235. addAttrs('style', 'xml:space');
  3236. addAttrs('object', 'declare classid code codebase codetype archive standby align border hspace vspace');
  3237. addAttrs('embed', 'align name hspace vspace');
  3238. addAttrs('param', 'valuetype type');
  3239. addAttrs('a', 'charset name rev shape coords');
  3240. addAttrs('br', 'clear');
  3241. addAttrs('applet', 'codebase archive code object alt name width height align hspace vspace');
  3242. addAttrs('img', 'name longdesc align border hspace vspace');
  3243. addAttrs('iframe', 'longdesc frameborder marginwidth marginheight scrolling align');
  3244. addAttrs('font basefont', 'size color face');
  3245. addAttrs('input', 'usemap align');
  3246. addAttrs('select', 'onchange');
  3247. addAttrs('textarea');
  3248. addAttrs('h1 h2 h3 h4 h5 h6 div p legend caption', 'align');
  3249. addAttrs('ul', 'type compact');
  3250. addAttrs('li', 'type');
  3251. addAttrs('ol dl menu dir', 'compact');
  3252. addAttrs('pre', 'width xml:space');
  3253. addAttrs('hr', 'align noshade size width');
  3254. addAttrs('isindex', 'prompt');
  3255. addAttrs('table', 'summary width frame rules cellspacing cellpadding align bgcolor');
  3256. addAttrs('col', 'width align char charoff valign');
  3257. addAttrs('colgroup', 'width align char charoff valign');
  3258. addAttrs('thead', 'align char charoff valign');
  3259. addAttrs('tr', 'align char charoff valign bgcolor');
  3260. addAttrs('th', 'axis align char charoff valign nowrap bgcolor width height');
  3261. addAttrs('form', 'accept');
  3262. addAttrs('td', 'abbr axis scope align char charoff valign nowrap bgcolor width height');
  3263. addAttrs('tfoot', 'align char charoff valign');
  3264. addAttrs('tbody', 'align char charoff valign');
  3265. addAttrs('area', 'nohref');
  3266. addAttrs('body', 'background bgcolor text link vlink alink');
  3267. }
  3268. if (type !== 'html4') {
  3269. addAttrs('input button select textarea', 'autofocus');
  3270. addAttrs('input textarea', 'placeholder');
  3271. addAttrs('a', 'download');
  3272. addAttrs('link script img', 'crossorigin');
  3273. addAttrs('iframe', 'sandbox seamless allowfullscreen');
  3274. }
  3275. each$3(split('a form meter progress dfn'), function (name) {
  3276. if (schema[name]) {
  3277. delete schema[name].children[name];
  3278. }
  3279. });
  3280. delete schema.caption.children.table;
  3281. delete schema.script;
  3282. mapCache[type] = schema;
  3283. return schema;
  3284. };
  3285. var compileElementMap = function (value, mode) {
  3286. var styles;
  3287. if (value) {
  3288. styles = {};
  3289. if (typeof value === 'string') {
  3290. value = { '*': value };
  3291. }
  3292. each$3(value, function (value, key) {
  3293. styles[key] = styles[key.toUpperCase()] = mode === 'map' ? makeMap$2(value, /[, ]/) : explode$1(value, /[, ]/);
  3294. });
  3295. }
  3296. return styles;
  3297. };
  3298. function Schema(settings) {
  3299. var elements = {};
  3300. var children = {};
  3301. var patternElements = [];
  3302. var validStyles;
  3303. var invalidStyles;
  3304. var schemaItems;
  3305. var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, validClasses;
  3306. var blockElementsMap, nonEmptyElementsMap, moveCaretBeforeOnEnterElementsMap, textBlockElementsMap, textInlineElementsMap;
  3307. var customElementsMap = {}, specialElements = {};
  3308. var createLookupTable = function (option, defaultValue, extendWith) {
  3309. var value = settings[option];
  3310. if (!value) {
  3311. value = mapCache[option];
  3312. if (!value) {
  3313. value = makeMap$2(defaultValue, ' ', makeMap$2(defaultValue.toUpperCase(), ' '));
  3314. value = extend$1(value, extendWith);
  3315. mapCache[option] = value;
  3316. }
  3317. } else {
  3318. value = makeMap$2(value, /[, ]/, makeMap$2(value.toUpperCase(), /[, ]/));
  3319. }
  3320. return value;
  3321. };
  3322. settings = settings || {};
  3323. schemaItems = compileSchema(settings.schema);
  3324. if (settings.verify_html === false) {
  3325. settings.valid_elements = '*[*]';
  3326. }
  3327. validStyles = compileElementMap(settings.valid_styles);
  3328. invalidStyles = compileElementMap(settings.invalid_styles, 'map');
  3329. validClasses = compileElementMap(settings.valid_classes, 'map');
  3330. whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea video audio iframe object code');
  3331. selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
  3332. shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link ' + 'meta param embed source wbr track');
  3333. boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize ' + 'noshade nowrap readonly selected autoplay loop controls');
  3334. nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object ' + 'script pre code', shortEndedElementsMap);
  3335. moveCaretBeforeOnEnterElementsMap = createLookupTable('move_caret_before_on_enter_elements', 'table', nonEmptyElementsMap);
  3336. textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' + 'blockquote center dir fieldset header footer article section hgroup aside main nav figure');
  3337. blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + 'th tr td li ol ul caption dl dt dd noscript menu isindex option ' + 'datalist select optgroup figcaption details summary', textBlockElementsMap);
  3338. textInlineElementsMap = createLookupTable('text_inline_elements', 'span strong b em i font strike u var cite ' + 'dfn code mark q sup sub samp');
  3339. each$3((settings.special || 'script noscript noframes noembed title style textarea xmp').split(' '), function (name) {
  3340. specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi');
  3341. });
  3342. var patternToRegExp = function (str) {
  3343. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  3344. };
  3345. var addValidElements = function (validElements) {
  3346. var ei, el, ai, al, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, prefix, outputName, globalAttributes, globalAttributesOrder, key, value;
  3347. var elementRuleRegExp = /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)\])?$/, attrRuleRegExp = /^([!\-])?(\w+[\\:]:\w+|[^=:<]+)?(?:([=:<])(.*))?$/, hasPatternsRegExp = /[*?+]/;
  3348. if (validElements) {
  3349. validElements = split(validElements, ',');
  3350. if (elements['@']) {
  3351. globalAttributes = elements['@'].attributes;
  3352. globalAttributesOrder = elements['@'].attributesOrder;
  3353. }
  3354. for (ei = 0, el = validElements.length; ei < el; ei++) {
  3355. matches = elementRuleRegExp.exec(validElements[ei]);
  3356. if (matches) {
  3357. prefix = matches[1];
  3358. elementName = matches[2];
  3359. outputName = matches[3];
  3360. attrData = matches[5];
  3361. attributes = {};
  3362. attributesOrder = [];
  3363. element = {
  3364. attributes: attributes,
  3365. attributesOrder: attributesOrder
  3366. };
  3367. if (prefix === '#') {
  3368. element.paddEmpty = true;
  3369. }
  3370. if (prefix === '-') {
  3371. element.removeEmpty = true;
  3372. }
  3373. if (matches[4] === '!') {
  3374. element.removeEmptyAttrs = true;
  3375. }
  3376. if (globalAttributes) {
  3377. for (key in globalAttributes) {
  3378. attributes[key] = globalAttributes[key];
  3379. }
  3380. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  3381. }
  3382. if (attrData) {
  3383. attrData = split(attrData, '|');
  3384. for (ai = 0, al = attrData.length; ai < al; ai++) {
  3385. matches = attrRuleRegExp.exec(attrData[ai]);
  3386. if (matches) {
  3387. attr = {};
  3388. attrType = matches[1];
  3389. attrName = matches[2].replace(/[\\:]:/g, ':');
  3390. prefix = matches[3];
  3391. value = matches[4];
  3392. if (attrType === '!') {
  3393. element.attributesRequired = element.attributesRequired || [];
  3394. element.attributesRequired.push(attrName);
  3395. attr.required = true;
  3396. }
  3397. if (attrType === '-') {
  3398. delete attributes[attrName];
  3399. attributesOrder.splice(inArray(attributesOrder, attrName), 1);
  3400. continue;
  3401. }
  3402. if (prefix) {
  3403. if (prefix === '=') {
  3404. element.attributesDefault = element.attributesDefault || [];
  3405. element.attributesDefault.push({
  3406. name: attrName,
  3407. value: value
  3408. });
  3409. attr.defaultValue = value;
  3410. }
  3411. if (prefix === ':') {
  3412. element.attributesForced = element.attributesForced || [];
  3413. element.attributesForced.push({
  3414. name: attrName,
  3415. value: value
  3416. });
  3417. attr.forcedValue = value;
  3418. }
  3419. if (prefix === '<') {
  3420. attr.validValues = makeMap$2(value, '?');
  3421. }
  3422. }
  3423. if (hasPatternsRegExp.test(attrName)) {
  3424. element.attributePatterns = element.attributePatterns || [];
  3425. attr.pattern = patternToRegExp(attrName);
  3426. element.attributePatterns.push(attr);
  3427. } else {
  3428. if (!attributes[attrName]) {
  3429. attributesOrder.push(attrName);
  3430. }
  3431. attributes[attrName] = attr;
  3432. }
  3433. }
  3434. }
  3435. }
  3436. if (!globalAttributes && elementName === '@') {
  3437. globalAttributes = attributes;
  3438. globalAttributesOrder = attributesOrder;
  3439. }
  3440. if (outputName) {
  3441. element.outputName = elementName;
  3442. elements[outputName] = element;
  3443. }
  3444. if (hasPatternsRegExp.test(elementName)) {
  3445. element.pattern = patternToRegExp(elementName);
  3446. patternElements.push(element);
  3447. } else {
  3448. elements[elementName] = element;
  3449. }
  3450. }
  3451. }
  3452. }
  3453. };
  3454. var setValidElements = function (validElements) {
  3455. elements = {};
  3456. patternElements = [];
  3457. addValidElements(validElements);
  3458. each$3(schemaItems, function (element, name) {
  3459. children[name] = element.children;
  3460. });
  3461. };
  3462. var addCustomElements = function (customElements) {
  3463. var customElementRegExp = /^(~)?(.+)$/;
  3464. if (customElements) {
  3465. mapCache.text_block_elements = mapCache.block_elements = null;
  3466. each$3(split(customElements, ','), function (rule) {
  3467. var matches = customElementRegExp.exec(rule), inline = matches[1] === '~', cloneName = inline ? 'span' : 'div', name = matches[2];
  3468. children[name] = children[cloneName];
  3469. customElementsMap[name] = cloneName;
  3470. if (!inline) {
  3471. blockElementsMap[name.toUpperCase()] = {};
  3472. blockElementsMap[name] = {};
  3473. }
  3474. if (!elements[name]) {
  3475. var customRule = elements[cloneName];
  3476. customRule = extend$1({}, customRule);
  3477. delete customRule.removeEmptyAttrs;
  3478. delete customRule.removeEmpty;
  3479. elements[name] = customRule;
  3480. }
  3481. each$3(children, function (element, elmName) {
  3482. if (element[cloneName]) {
  3483. children[elmName] = element = extend$1({}, children[elmName]);
  3484. element[name] = element[cloneName];
  3485. }
  3486. });
  3487. });
  3488. }
  3489. };
  3490. var addValidChildren = function (validChildren) {
  3491. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  3492. mapCache[settings.schema] = null;
  3493. if (validChildren) {
  3494. each$3(split(validChildren, ','), function (rule) {
  3495. var matches = childRuleRegExp.exec(rule);
  3496. var parent, prefix;
  3497. if (matches) {
  3498. prefix = matches[1];
  3499. if (prefix) {
  3500. parent = children[matches[2]];
  3501. } else {
  3502. parent = children[matches[2]] = { '#comment': {} };
  3503. }
  3504. parent = children[matches[2]];
  3505. each$3(split(matches[3], '|'), function (child) {
  3506. if (prefix === '-') {
  3507. delete parent[child];
  3508. } else {
  3509. parent[child] = {};
  3510. }
  3511. });
  3512. }
  3513. });
  3514. }
  3515. };
  3516. var getElementRule = function (name) {
  3517. var element = elements[name], i;
  3518. if (element) {
  3519. return element;
  3520. }
  3521. i = patternElements.length;
  3522. while (i--) {
  3523. element = patternElements[i];
  3524. if (element.pattern.test(name)) {
  3525. return element;
  3526. }
  3527. }
  3528. };
  3529. if (!settings.valid_elements) {
  3530. each$3(schemaItems, function (element, name) {
  3531. elements[name] = {
  3532. attributes: element.attributes,
  3533. attributesOrder: element.attributesOrder
  3534. };
  3535. children[name] = element.children;
  3536. });
  3537. if (settings.schema !== 'html5') {
  3538. each$3(split('strong/b em/i'), function (item) {
  3539. item = split(item, '/');
  3540. elements[item[1]].outputName = item[0];
  3541. });
  3542. }
  3543. each$3(split('ol ul sub sup blockquote span font a table tbody tr strong em b i'), function (name) {
  3544. if (elements[name]) {
  3545. elements[name].removeEmpty = true;
  3546. }
  3547. });
  3548. each$3(split('p h1 h2 h3 h4 h5 h6 th td pre div address caption li'), function (name) {
  3549. elements[name].paddEmpty = true;
  3550. });
  3551. each$3(split('span'), function (name) {
  3552. elements[name].removeEmptyAttrs = true;
  3553. });
  3554. } else {
  3555. setValidElements(settings.valid_elements);
  3556. }
  3557. addCustomElements(settings.custom_elements);
  3558. addValidChildren(settings.valid_children);
  3559. addValidElements(settings.extended_valid_elements);
  3560. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  3561. each$3({
  3562. dd: 'dl',
  3563. dt: 'dl',
  3564. li: 'ul ol',
  3565. td: 'tr',
  3566. th: 'tr',
  3567. tr: 'tbody thead tfoot',
  3568. tbody: 'table',
  3569. thead: 'table',
  3570. tfoot: 'table',
  3571. legend: 'fieldset',
  3572. area: 'map',
  3573. param: 'video audio object'
  3574. }, function (parents, item) {
  3575. if (elements[item]) {
  3576. elements[item].parentsRequired = split(parents);
  3577. }
  3578. });
  3579. if (settings.invalid_elements) {
  3580. each$3(explode$1(settings.invalid_elements), function (item) {
  3581. if (elements[item]) {
  3582. delete elements[item];
  3583. }
  3584. });
  3585. }
  3586. if (!getElementRule('span')) {
  3587. addValidElements('span[!data-mce-type|*]');
  3588. }
  3589. var getValidStyles = function () {
  3590. return validStyles;
  3591. };
  3592. var getInvalidStyles = function () {
  3593. return invalidStyles;
  3594. };
  3595. var getValidClasses = function () {
  3596. return validClasses;
  3597. };
  3598. var getBoolAttrs = function () {
  3599. return boolAttrMap;
  3600. };
  3601. var getBlockElements = function () {
  3602. return blockElementsMap;
  3603. };
  3604. var getTextBlockElements = function () {
  3605. return textBlockElementsMap;
  3606. };
  3607. var getTextInlineElements = function () {
  3608. return textInlineElementsMap;
  3609. };
  3610. var getShortEndedElements = function () {
  3611. return shortEndedElementsMap;
  3612. };
  3613. var getSelfClosingElements = function () {
  3614. return selfClosingElementsMap;
  3615. };
  3616. var getNonEmptyElements = function () {
  3617. return nonEmptyElementsMap;
  3618. };
  3619. var getMoveCaretBeforeOnEnterElements = function () {
  3620. return moveCaretBeforeOnEnterElementsMap;
  3621. };
  3622. var getWhiteSpaceElements = function () {
  3623. return whiteSpaceElementsMap;
  3624. };
  3625. var getSpecialElements = function () {
  3626. return specialElements;
  3627. };
  3628. var isValidChild = function (name, child) {
  3629. var parent = children[name.toLowerCase()];
  3630. return !!(parent && parent[child.toLowerCase()]);
  3631. };
  3632. var isValid = function (name, attr) {
  3633. var attrPatterns, i;
  3634. var rule = getElementRule(name);
  3635. if (rule) {
  3636. if (attr) {
  3637. if (rule.attributes[attr]) {
  3638. return true;
  3639. }
  3640. attrPatterns = rule.attributePatterns;
  3641. if (attrPatterns) {
  3642. i = attrPatterns.length;
  3643. while (i--) {
  3644. if (attrPatterns[i].pattern.test(name)) {
  3645. return true;
  3646. }
  3647. }
  3648. }
  3649. } else {
  3650. return true;
  3651. }
  3652. }
  3653. return false;
  3654. };
  3655. var getCustomElements = function () {
  3656. return customElementsMap;
  3657. };
  3658. return {
  3659. children: children,
  3660. elements: elements,
  3661. getValidStyles: getValidStyles,
  3662. getValidClasses: getValidClasses,
  3663. getBlockElements: getBlockElements,
  3664. getInvalidStyles: getInvalidStyles,
  3665. getShortEndedElements: getShortEndedElements,
  3666. getTextBlockElements: getTextBlockElements,
  3667. getTextInlineElements: getTextInlineElements,
  3668. getBoolAttrs: getBoolAttrs,
  3669. getElementRule: getElementRule,
  3670. getSelfClosingElements: getSelfClosingElements,
  3671. getNonEmptyElements: getNonEmptyElements,
  3672. getMoveCaretBeforeOnEnterElements: getMoveCaretBeforeOnEnterElements,
  3673. getWhiteSpaceElements: getWhiteSpaceElements,
  3674. getSpecialElements: getSpecialElements,
  3675. isValidChild: isValidChild,
  3676. isValid: isValid,
  3677. getCustomElements: getCustomElements,
  3678. addValidElements: addValidElements,
  3679. setValidElements: setValidElements,
  3680. addCustomElements: addCustomElements,
  3681. addValidChildren: addValidChildren
  3682. };
  3683. }
  3684. var toHex = function (match, r, g, b) {
  3685. var hex = function (val) {
  3686. val = parseInt(val, 10).toString(16);
  3687. return val.length > 1 ? val : '0' + val;
  3688. };
  3689. return '#' + hex(r) + hex(g) + hex(b);
  3690. };
  3691. var Styles = function (settings, schema) {
  3692. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi;
  3693. var urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi;
  3694. var styleRegExp = /\s*([^:]+):\s*([^;]+);?/g;
  3695. var trimRightRegExp = /\s+$/;
  3696. var i;
  3697. var encodingLookup = {};
  3698. var encodingItems;
  3699. var validStyles;
  3700. var invalidStyles;
  3701. var invisibleChar = '\uFEFF';
  3702. settings = settings || {};
  3703. if (schema) {
  3704. validStyles = schema.getValidStyles();
  3705. invalidStyles = schema.getInvalidStyles();
  3706. }
  3707. encodingItems = ('\\" \\\' \\; \\: ; : ' + invisibleChar).split(' ');
  3708. for (i = 0; i < encodingItems.length; i++) {
  3709. encodingLookup[encodingItems[i]] = invisibleChar + i;
  3710. encodingLookup[invisibleChar + i] = encodingItems[i];
  3711. }
  3712. return {
  3713. toHex: function (color) {
  3714. return color.replace(rgbRegExp, toHex);
  3715. },
  3716. parse: function (css) {
  3717. var styles = {};
  3718. var matches, name, value, isEncoded;
  3719. var urlConverter = settings.url_converter;
  3720. var urlConverterScope = settings.url_converter_scope || this;
  3721. var compress = function (prefix, suffix, noJoin) {
  3722. var top, right, bottom, left;
  3723. top = styles[prefix + '-top' + suffix];
  3724. if (!top) {
  3725. return;
  3726. }
  3727. right = styles[prefix + '-right' + suffix];
  3728. if (!right) {
  3729. return;
  3730. }
  3731. bottom = styles[prefix + '-bottom' + suffix];
  3732. if (!bottom) {
  3733. return;
  3734. }
  3735. left = styles[prefix + '-left' + suffix];
  3736. if (!left) {
  3737. return;
  3738. }
  3739. var box = [
  3740. top,
  3741. right,
  3742. bottom,
  3743. left
  3744. ];
  3745. i = box.length - 1;
  3746. while (i--) {
  3747. if (box[i] !== box[i + 1]) {
  3748. break;
  3749. }
  3750. }
  3751. if (i > -1 && noJoin) {
  3752. return;
  3753. }
  3754. styles[prefix + suffix] = i === -1 ? box[0] : box.join(' ');
  3755. delete styles[prefix + '-top' + suffix];
  3756. delete styles[prefix + '-right' + suffix];
  3757. delete styles[prefix + '-bottom' + suffix];
  3758. delete styles[prefix + '-left' + suffix];
  3759. };
  3760. var canCompress = function (key) {
  3761. var value = styles[key], i;
  3762. if (!value) {
  3763. return;
  3764. }
  3765. value = value.split(' ');
  3766. i = value.length;
  3767. while (i--) {
  3768. if (value[i] !== value[0]) {
  3769. return false;
  3770. }
  3771. }
  3772. styles[key] = value[0];
  3773. return true;
  3774. };
  3775. var compress2 = function (target, a, b, c) {
  3776. if (!canCompress(a)) {
  3777. return;
  3778. }
  3779. if (!canCompress(b)) {
  3780. return;
  3781. }
  3782. if (!canCompress(c)) {
  3783. return;
  3784. }
  3785. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  3786. delete styles[a];
  3787. delete styles[b];
  3788. delete styles[c];
  3789. };
  3790. var encode = function (str) {
  3791. isEncoded = true;
  3792. return encodingLookup[str];
  3793. };
  3794. var decode = function (str, keepSlashes) {
  3795. if (isEncoded) {
  3796. str = str.replace(/\uFEFF[0-9]/g, function (str) {
  3797. return encodingLookup[str];
  3798. });
  3799. }
  3800. if (!keepSlashes) {
  3801. str = str.replace(/\\([\'\";:])/g, '$1');
  3802. }
  3803. return str;
  3804. };
  3805. var decodeSingleHexSequence = function (escSeq) {
  3806. return String.fromCharCode(parseInt(escSeq.slice(1), 16));
  3807. };
  3808. var decodeHexSequences = function (value) {
  3809. return value.replace(/\\[0-9a-f]+/gi, decodeSingleHexSequence);
  3810. };
  3811. var processUrl = function (match, url, url2, url3, str, str2) {
  3812. str = str || str2;
  3813. if (str) {
  3814. str = decode(str);
  3815. return '\'' + str.replace(/\'/g, '\\\'') + '\'';
  3816. }
  3817. url = decode(url || url2 || url3);
  3818. if (!settings.allow_script_urls) {
  3819. var scriptUrl = url.replace(/[\s\r\n]+/g, '');
  3820. if (/(java|vb)script:/i.test(scriptUrl)) {
  3821. return '';
  3822. }
  3823. if (!settings.allow_svg_data_urls && /^data:image\/svg/i.test(scriptUrl)) {
  3824. return '';
  3825. }
  3826. }
  3827. if (urlConverter) {
  3828. url = urlConverter.call(urlConverterScope, url, 'style');
  3829. }
  3830. return 'url(\'' + url.replace(/\'/g, '\\\'') + '\')';
  3831. };
  3832. if (css) {
  3833. css = css.replace(/[\u0000-\u001F]/g, '');
  3834. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function (str) {
  3835. return str.replace(/[;:]/g, encode);
  3836. });
  3837. while (matches = styleRegExp.exec(css)) {
  3838. styleRegExp.lastIndex = matches.index + matches[0].length;
  3839. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  3840. value = matches[2].replace(trimRightRegExp, '');
  3841. if (name && value) {
  3842. name = decodeHexSequences(name);
  3843. value = decodeHexSequences(value);
  3844. if (name.indexOf(invisibleChar) !== -1 || name.indexOf('"') !== -1) {
  3845. continue;
  3846. }
  3847. if (!settings.allow_script_urls && (name === 'behavior' || /expression\s*\(|\/\*|\*\//.test(value))) {
  3848. continue;
  3849. }
  3850. if (name === 'font-weight' && value === '700') {
  3851. value = 'bold';
  3852. } else if (name === 'color' || name === 'background-color') {
  3853. value = value.toLowerCase();
  3854. }
  3855. value = value.replace(rgbRegExp, toHex);
  3856. value = value.replace(urlOrStrRegExp, processUrl);
  3857. styles[name] = isEncoded ? decode(value, true) : value;
  3858. }
  3859. }
  3860. compress('border', '', true);
  3861. compress('border', '-width');
  3862. compress('border', '-color');
  3863. compress('border', '-style');
  3864. compress('padding', '');
  3865. compress('margin', '');
  3866. compress2('border', 'border-width', 'border-style', 'border-color');
  3867. if (styles.border === 'medium none') {
  3868. delete styles.border;
  3869. }
  3870. if (styles['border-image'] === 'none') {
  3871. delete styles['border-image'];
  3872. }
  3873. }
  3874. return styles;
  3875. },
  3876. serialize: function (styles, elementName) {
  3877. var css = '', name, value;
  3878. var serializeStyles = function (name) {
  3879. var styleList, i, l, value;
  3880. styleList = validStyles[name];
  3881. if (styleList) {
  3882. for (i = 0, l = styleList.length; i < l; i++) {
  3883. name = styleList[i];
  3884. value = styles[name];
  3885. if (value) {
  3886. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  3887. }
  3888. }
  3889. }
  3890. };
  3891. var isValid = function (name, elementName) {
  3892. var styleMap;
  3893. styleMap = invalidStyles['*'];
  3894. if (styleMap && styleMap[name]) {
  3895. return false;
  3896. }
  3897. styleMap = invalidStyles[elementName];
  3898. if (styleMap && styleMap[name]) {
  3899. return false;
  3900. }
  3901. return true;
  3902. };
  3903. if (elementName && validStyles) {
  3904. serializeStyles('*');
  3905. serializeStyles(elementName);
  3906. } else {
  3907. for (name in styles) {
  3908. value = styles[name];
  3909. if (value && (!invalidStyles || isValid(name, elementName))) {
  3910. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  3911. }
  3912. }
  3913. }
  3914. return css;
  3915. }
  3916. };
  3917. };
  3918. var eventExpandoPrefix = 'mce-data-';
  3919. var mouseEventRe = /^(?:mouse|contextmenu)|click/;
  3920. var deprecated = {
  3921. keyLocation: 1,
  3922. layerX: 1,
  3923. layerY: 1,
  3924. returnValue: 1,
  3925. webkitMovementX: 1,
  3926. webkitMovementY: 1,
  3927. keyIdentifier: 1,
  3928. mozPressure: 1
  3929. };
  3930. var hasIsDefaultPrevented = function (event) {
  3931. return event.isDefaultPrevented === returnTrue || event.isDefaultPrevented === returnFalse;
  3932. };
  3933. var returnFalse = function () {
  3934. return false;
  3935. };
  3936. var returnTrue = function () {
  3937. return true;
  3938. };
  3939. var addEvent = function (target, name, callback, capture) {
  3940. if (target.addEventListener) {
  3941. target.addEventListener(name, callback, capture || false);
  3942. } else if (target.attachEvent) {
  3943. target.attachEvent('on' + name, callback);
  3944. }
  3945. };
  3946. var removeEvent = function (target, name, callback, capture) {
  3947. if (target.removeEventListener) {
  3948. target.removeEventListener(name, callback, capture || false);
  3949. } else if (target.detachEvent) {
  3950. target.detachEvent('on' + name, callback);
  3951. }
  3952. };
  3953. var getTargetFromShadowDom = function (event, defaultTarget) {
  3954. if (event.composedPath) {
  3955. var composedPath = event.composedPath();
  3956. if (composedPath && composedPath.length > 0) {
  3957. return composedPath[0];
  3958. }
  3959. }
  3960. return defaultTarget;
  3961. };
  3962. var fix = function (originalEvent, data) {
  3963. var name;
  3964. var event = data || {};
  3965. for (name in originalEvent) {
  3966. if (!deprecated[name]) {
  3967. event[name] = originalEvent[name];
  3968. }
  3969. }
  3970. if (!event.target) {
  3971. event.target = event.srcElement || domGlobals.document;
  3972. }
  3973. if (Env.experimentalShadowDom) {
  3974. event.target = getTargetFromShadowDom(originalEvent, event.target);
  3975. }
  3976. if (originalEvent && mouseEventRe.test(originalEvent.type) && originalEvent.pageX === undefined && originalEvent.clientX !== undefined) {
  3977. var eventDoc = event.target.ownerDocument || domGlobals.document;
  3978. var doc = eventDoc.documentElement;
  3979. var body = eventDoc.body;
  3980. event.pageX = originalEvent.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  3981. event.pageY = originalEvent.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  3982. }
  3983. event.preventDefault = function () {
  3984. event.isDefaultPrevented = returnTrue;
  3985. if (originalEvent) {
  3986. if (originalEvent.preventDefault) {
  3987. originalEvent.preventDefault();
  3988. } else {
  3989. originalEvent.returnValue = false;
  3990. }
  3991. }
  3992. };
  3993. event.stopPropagation = function () {
  3994. event.isPropagationStopped = returnTrue;
  3995. if (originalEvent) {
  3996. if (originalEvent.stopPropagation) {
  3997. originalEvent.stopPropagation();
  3998. } else {
  3999. originalEvent.cancelBubble = true;
  4000. }
  4001. }
  4002. };
  4003. event.stopImmediatePropagation = function () {
  4004. event.isImmediatePropagationStopped = returnTrue;
  4005. event.stopPropagation();
  4006. };
  4007. if (hasIsDefaultPrevented(event) === false) {
  4008. event.isDefaultPrevented = returnFalse;
  4009. event.isPropagationStopped = returnFalse;
  4010. event.isImmediatePropagationStopped = returnFalse;
  4011. }
  4012. if (typeof event.metaKey === 'undefined') {
  4013. event.metaKey = false;
  4014. }
  4015. return event;
  4016. };
  4017. var bindOnReady = function (win, callback, eventUtils) {
  4018. var doc = win.document, event = { type: 'ready' };
  4019. if (eventUtils.domLoaded) {
  4020. callback(event);
  4021. return;
  4022. }
  4023. var isDocReady = function () {
  4024. return doc.readyState === 'complete' || doc.readyState === 'interactive' && doc.body;
  4025. };
  4026. var readyHandler = function () {
  4027. removeEvent(win, 'DOMContentLoaded', readyHandler);
  4028. removeEvent(win, 'load', readyHandler);
  4029. if (!eventUtils.domLoaded) {
  4030. eventUtils.domLoaded = true;
  4031. callback(event);
  4032. }
  4033. };
  4034. if (isDocReady()) {
  4035. readyHandler();
  4036. } else {
  4037. addEvent(win, 'DOMContentLoaded', readyHandler);
  4038. }
  4039. addEvent(win, 'load', readyHandler);
  4040. };
  4041. var EventUtils = function () {
  4042. function EventUtils() {
  4043. this.domLoaded = false;
  4044. this.events = {};
  4045. this.count = 1;
  4046. this.expando = eventExpandoPrefix + (+new Date()).toString(32);
  4047. this.hasMouseEnterLeave = 'onmouseenter' in domGlobals.document.documentElement;
  4048. this.hasFocusIn = 'onfocusin' in domGlobals.document.documentElement;
  4049. this.count = 1;
  4050. }
  4051. EventUtils.prototype.bind = function (target, names, callback, scope) {
  4052. var self = this;
  4053. var id, callbackList, i, name, fakeName, nativeHandler, capture;
  4054. var win = domGlobals.window;
  4055. var defaultNativeHandler = function (evt) {
  4056. self.executeHandlers(fix(evt || win.event), id);
  4057. };
  4058. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4059. return;
  4060. }
  4061. if (!target[self.expando]) {
  4062. id = self.count++;
  4063. target[self.expando] = id;
  4064. self.events[id] = {};
  4065. } else {
  4066. id = target[self.expando];
  4067. }
  4068. scope = scope || target;
  4069. var namesList = names.split(' ');
  4070. i = namesList.length;
  4071. while (i--) {
  4072. name = namesList[i];
  4073. nativeHandler = defaultNativeHandler;
  4074. fakeName = capture = false;
  4075. if (name === 'DOMContentLoaded') {
  4076. name = 'ready';
  4077. }
  4078. if (self.domLoaded && name === 'ready' && target.readyState === 'complete') {
  4079. callback.call(scope, fix({ type: name }));
  4080. continue;
  4081. }
  4082. if (!self.hasMouseEnterLeave) {
  4083. fakeName = self.mouseEnterLeave[name];
  4084. if (fakeName) {
  4085. nativeHandler = function (evt) {
  4086. var current, related;
  4087. current = evt.currentTarget;
  4088. related = evt.relatedTarget;
  4089. if (related && current.contains) {
  4090. related = current.contains(related);
  4091. } else {
  4092. while (related && related !== current) {
  4093. related = related.parentNode;
  4094. }
  4095. }
  4096. if (!related) {
  4097. evt = fix(evt || win.event);
  4098. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
  4099. evt.target = current;
  4100. self.executeHandlers(evt, id);
  4101. }
  4102. };
  4103. }
  4104. }
  4105. if (!self.hasFocusIn && (name === 'focusin' || name === 'focusout')) {
  4106. capture = true;
  4107. fakeName = name === 'focusin' ? 'focus' : 'blur';
  4108. nativeHandler = function (evt) {
  4109. evt = fix(evt || win.event);
  4110. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
  4111. self.executeHandlers(evt, id);
  4112. };
  4113. }
  4114. callbackList = self.events[id][name];
  4115. if (!callbackList) {
  4116. self.events[id][name] = callbackList = [{
  4117. func: callback,
  4118. scope: scope
  4119. }];
  4120. callbackList.fakeName = fakeName;
  4121. callbackList.capture = capture;
  4122. callbackList.nativeHandler = nativeHandler;
  4123. if (name === 'ready') {
  4124. bindOnReady(target, nativeHandler, self);
  4125. } else {
  4126. addEvent(target, fakeName || name, nativeHandler, capture);
  4127. }
  4128. } else {
  4129. if (name === 'ready' && self.domLoaded) {
  4130. callback(fix({ type: name }));
  4131. } else {
  4132. callbackList.push({
  4133. func: callback,
  4134. scope: scope
  4135. });
  4136. }
  4137. }
  4138. }
  4139. target = callbackList = 0;
  4140. return callback;
  4141. };
  4142. EventUtils.prototype.unbind = function (target, names, callback) {
  4143. var id, callbackList, i, ci, name, eventMap;
  4144. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4145. return this;
  4146. }
  4147. id = target[this.expando];
  4148. if (id) {
  4149. eventMap = this.events[id];
  4150. if (names) {
  4151. var namesList = names.split(' ');
  4152. i = namesList.length;
  4153. while (i--) {
  4154. name = namesList[i];
  4155. callbackList = eventMap[name];
  4156. if (callbackList) {
  4157. if (callback) {
  4158. ci = callbackList.length;
  4159. while (ci--) {
  4160. if (callbackList[ci].func === callback) {
  4161. var nativeHandler = callbackList.nativeHandler;
  4162. var fakeName = callbackList.fakeName, capture = callbackList.capture;
  4163. callbackList = callbackList.slice(0, ci).concat(callbackList.slice(ci + 1));
  4164. callbackList.nativeHandler = nativeHandler;
  4165. callbackList.fakeName = fakeName;
  4166. callbackList.capture = capture;
  4167. eventMap[name] = callbackList;
  4168. }
  4169. }
  4170. }
  4171. if (!callback || callbackList.length === 0) {
  4172. delete eventMap[name];
  4173. removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
  4174. }
  4175. }
  4176. }
  4177. } else {
  4178. for (name in eventMap) {
  4179. callbackList = eventMap[name];
  4180. removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
  4181. }
  4182. eventMap = {};
  4183. }
  4184. for (name in eventMap) {
  4185. return this;
  4186. }
  4187. delete this.events[id];
  4188. try {
  4189. delete target[this.expando];
  4190. } catch (ex) {
  4191. target[this.expando] = null;
  4192. }
  4193. }
  4194. return this;
  4195. };
  4196. EventUtils.prototype.fire = function (target, name, args) {
  4197. var id;
  4198. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4199. return this;
  4200. }
  4201. var event = fix(null, args);
  4202. event.type = name;
  4203. event.target = target;
  4204. do {
  4205. id = target[this.expando];
  4206. if (id) {
  4207. this.executeHandlers(event, id);
  4208. }
  4209. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  4210. } while (target && !event.isPropagationStopped());
  4211. return this;
  4212. };
  4213. EventUtils.prototype.clean = function (target) {
  4214. var i, children;
  4215. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4216. return this;
  4217. }
  4218. if (target[this.expando]) {
  4219. this.unbind(target);
  4220. }
  4221. if (!target.getElementsByTagName) {
  4222. target = target.document;
  4223. }
  4224. if (target && target.getElementsByTagName) {
  4225. this.unbind(target);
  4226. children = target.getElementsByTagName('*');
  4227. i = children.length;
  4228. while (i--) {
  4229. target = children[i];
  4230. if (target[this.expando]) {
  4231. this.unbind(target);
  4232. }
  4233. }
  4234. }
  4235. return this;
  4236. };
  4237. EventUtils.prototype.destroy = function () {
  4238. this.events = {};
  4239. };
  4240. EventUtils.prototype.cancel = function (e) {
  4241. if (e) {
  4242. e.preventDefault();
  4243. e.stopImmediatePropagation();
  4244. }
  4245. return false;
  4246. };
  4247. EventUtils.prototype.executeHandlers = function (evt, id) {
  4248. var callbackList, i, l, callback;
  4249. var container = this.events[id];
  4250. callbackList = container && container[evt.type];
  4251. if (callbackList) {
  4252. for (i = 0, l = callbackList.length; i < l; i++) {
  4253. callback = callbackList[i];
  4254. if (callback && callback.func.call(callback.scope, evt) === false) {
  4255. evt.preventDefault();
  4256. }
  4257. if (evt.isImmediatePropagationStopped()) {
  4258. return;
  4259. }
  4260. }
  4261. }
  4262. };
  4263. EventUtils.Event = new EventUtils();
  4264. return EventUtils;
  4265. }();
  4266. var i, support, Expr, getText, isXML, tokenize, compile, select, outermostContext, sortInput, hasDuplicate, setDocument, document, docElem, documentIsHTML, rbuggyQSA, rbuggyMatches, matches, contains$3, expando = 'sizzle' + -new Date(), preferredDoc = domGlobals.window.document, dirruns = 0, done = 0, classCache = createCache(), tokenCache = createCache(), compilerCache = createCache(), sortOrder = function (a, b) {
  4267. if (a === b) {
  4268. hasDuplicate = true;
  4269. }
  4270. return 0;
  4271. }, strundefined = typeof undefined, MAX_NEGATIVE = 1 << 31, hasOwn = {}.hasOwnProperty, arr = [], pop = arr.pop, push_native = arr.push, push = arr.push, slice = arr.slice, indexOf$2 = arr.indexOf || function (elem) {
  4272. var i = 0, len = this.length;
  4273. for (; i < len; i++) {
  4274. if (this[i] === elem) {
  4275. return i;
  4276. }
  4277. }
  4278. return -1;
  4279. }, booleans = 'checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped', whitespace = '[\\x20\\t\\r\\n\\f]', identifier = '(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+', attributes = '\\[' + whitespace + '*(' + identifier + ')(?:' + whitespace + '*([*^$|!~]?=)' + whitespace + '*(?:\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)"|(' + identifier + '))|)' + whitespace + '*\\]', pseudos = ':(' + identifier + ')(?:\\((' + '(\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)")|' + '((?:\\\\.|[^\\\\()[\\]]|' + attributes + ')*)|' + '.*' + ')\\)|)', rtrim = new RegExp('^' + whitespace + '+|((?:^|[^\\\\])(?:\\\\.)*)' + whitespace + '+$', 'g'), rcomma = new RegExp('^' + whitespace + '*,' + whitespace + '*'), rcombinators = new RegExp('^' + whitespace + '*([>+~]|' + whitespace + ')' + whitespace + '*'), rattributeQuotes = new RegExp('=' + whitespace + '*([^\\]\'"]*?)' + whitespace + '*\\]', 'g'), rpseudo = new RegExp(pseudos), ridentifier = new RegExp('^' + identifier + '$'), matchExpr = {
  4280. ID: new RegExp('^#(' + identifier + ')'),
  4281. CLASS: new RegExp('^\\.(' + identifier + ')'),
  4282. TAG: new RegExp('^(' + identifier + '|[*])'),
  4283. ATTR: new RegExp('^' + attributes),
  4284. PSEUDO: new RegExp('^' + pseudos),
  4285. CHILD: new RegExp('^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(' + whitespace + '*(even|odd|(([+-]|)(\\d*)n|)' + whitespace + '*(?:([+-]|)' + whitespace + '*(\\d+)|))' + whitespace + '*\\)|)', 'i'),
  4286. bool: new RegExp('^(?:' + booleans + ')$', 'i'),
  4287. needsContext: new RegExp('^' + whitespace + '*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(' + whitespace + '*((?:-\\d)?\\d*)' + whitespace + '*\\)|)(?=[^-]|$)', 'i')
  4288. }, rinputs = /^(?:input|select|textarea|button)$/i, rheader = /^h\d$/i, rnative = /^[^{]+\{\s*\[native \w/, rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, rsibling = /[+~]/, rescape = /'|\\/g, runescape = new RegExp('\\\\([\\da-f]{1,6}' + whitespace + '?|(' + whitespace + ')|.)', 'ig'), funescape = function (_, escaped, escapedWhitespace) {
  4289. var high = '0x' + escaped - 65536;
  4290. return high !== high || escapedWhitespace ? escaped : high < 0 ? String.fromCharCode(high + 65536) : String.fromCharCode(high >> 10 | 55296, high & 1023 | 56320);
  4291. };
  4292. try {
  4293. push.apply(arr = slice.call(preferredDoc.childNodes), preferredDoc.childNodes);
  4294. arr[preferredDoc.childNodes.length].nodeType;
  4295. } catch (e) {
  4296. push = {
  4297. apply: arr.length ? function (target, els) {
  4298. push_native.apply(target, slice.call(els));
  4299. } : function (target, els) {
  4300. var j = target.length, i = 0;
  4301. while (target[j++] = els[i++]) {
  4302. }
  4303. target.length = j - 1;
  4304. }
  4305. };
  4306. }
  4307. var Sizzle = function (selector, context, results, seed) {
  4308. var match, elem, m, nodeType, i, groups, old, nid, newContext, newSelector;
  4309. if ((context ? context.ownerDocument || context : preferredDoc) !== document) {
  4310. setDocument(context);
  4311. }
  4312. context = context || document;
  4313. results = results || [];
  4314. if (!selector || typeof selector !== 'string') {
  4315. return results;
  4316. }
  4317. if ((nodeType = context.nodeType) !== 1 && nodeType !== 9) {
  4318. return [];
  4319. }
  4320. if (documentIsHTML && !seed) {
  4321. if (match = rquickExpr.exec(selector)) {
  4322. if (m = match[1]) {
  4323. if (nodeType === 9) {
  4324. elem = context.getElementById(m);
  4325. if (elem && elem.parentNode) {
  4326. if (elem.id === m) {
  4327. results.push(elem);
  4328. return results;
  4329. }
  4330. } else {
  4331. return results;
  4332. }
  4333. } else {
  4334. if (context.ownerDocument && (elem = context.ownerDocument.getElementById(m)) && contains$3(context, elem) && elem.id === m) {
  4335. results.push(elem);
  4336. return results;
  4337. }
  4338. }
  4339. } else if (match[2]) {
  4340. push.apply(results, context.getElementsByTagName(selector));
  4341. return results;
  4342. } else if ((m = match[3]) && support.getElementsByClassName) {
  4343. push.apply(results, context.getElementsByClassName(m));
  4344. return results;
  4345. }
  4346. }
  4347. if (support.qsa && (!rbuggyQSA || !rbuggyQSA.test(selector))) {
  4348. nid = old = expando;
  4349. newContext = context;
  4350. newSelector = nodeType === 9 && selector;
  4351. if (nodeType === 1 && context.nodeName.toLowerCase() !== 'object') {
  4352. groups = tokenize(selector);
  4353. if (old = context.getAttribute('id')) {
  4354. nid = old.replace(rescape, '\\$&');
  4355. } else {
  4356. context.setAttribute('id', nid);
  4357. }
  4358. nid = '[id=\'' + nid + '\'] ';
  4359. i = groups.length;
  4360. while (i--) {
  4361. groups[i] = nid + toSelector(groups[i]);
  4362. }
  4363. newContext = rsibling.test(selector) && testContext(context.parentNode) || context;
  4364. newSelector = groups.join(',');
  4365. }
  4366. if (newSelector) {
  4367. try {
  4368. push.apply(results, newContext.querySelectorAll(newSelector));
  4369. return results;
  4370. } catch (qsaError) {
  4371. } finally {
  4372. if (!old) {
  4373. context.removeAttribute('id');
  4374. }
  4375. }
  4376. }
  4377. }
  4378. }
  4379. return select(selector.replace(rtrim, '$1'), context, results, seed);
  4380. };
  4381. function createCache() {
  4382. var keys = [];
  4383. function cache(key, value) {
  4384. if (keys.push(key + ' ') > Expr.cacheLength) {
  4385. delete cache[keys.shift()];
  4386. }
  4387. return cache[key + ' '] = value;
  4388. }
  4389. return cache;
  4390. }
  4391. function markFunction(fn) {
  4392. fn[expando] = true;
  4393. return fn;
  4394. }
  4395. function siblingCheck(a, b) {
  4396. var cur = b && a, diff = cur && a.nodeType === 1 && b.nodeType === 1 && (~b.sourceIndex || MAX_NEGATIVE) - (~a.sourceIndex || MAX_NEGATIVE);
  4397. if (diff) {
  4398. return diff;
  4399. }
  4400. if (cur) {
  4401. while (cur = cur.nextSibling) {
  4402. if (cur === b) {
  4403. return -1;
  4404. }
  4405. }
  4406. }
  4407. return a ? 1 : -1;
  4408. }
  4409. function createInputPseudo(type) {
  4410. return function (elem) {
  4411. var name = elem.nodeName.toLowerCase();
  4412. return name === 'input' && elem.type === type;
  4413. };
  4414. }
  4415. function createButtonPseudo(type) {
  4416. return function (elem) {
  4417. var name = elem.nodeName.toLowerCase();
  4418. return (name === 'input' || name === 'button') && elem.type === type;
  4419. };
  4420. }
  4421. function createPositionalPseudo(fn) {
  4422. return markFunction(function (argument) {
  4423. argument = +argument;
  4424. return markFunction(function (seed, matches) {
  4425. var j, matchIndexes = fn([], seed.length, argument), i = matchIndexes.length;
  4426. while (i--) {
  4427. if (seed[j = matchIndexes[i]]) {
  4428. seed[j] = !(matches[j] = seed[j]);
  4429. }
  4430. }
  4431. });
  4432. });
  4433. }
  4434. function testContext(context) {
  4435. return context && typeof context.getElementsByTagName !== strundefined && context;
  4436. }
  4437. support = Sizzle.support = {};
  4438. isXML = Sizzle.isXML = function (elem) {
  4439. var documentElement = elem && (elem.ownerDocument || elem).documentElement;
  4440. return documentElement ? documentElement.nodeName !== 'HTML' : false;
  4441. };
  4442. setDocument = Sizzle.setDocument = function (node) {
  4443. var hasCompare, doc = node ? node.ownerDocument || node : preferredDoc, parent = doc.defaultView;
  4444. function getTop(win) {
  4445. try {
  4446. return win.top;
  4447. } catch (ex) {
  4448. }
  4449. return null;
  4450. }
  4451. if (doc === document || doc.nodeType !== 9 || !doc.documentElement) {
  4452. return document;
  4453. }
  4454. document = doc;
  4455. docElem = doc.documentElement;
  4456. documentIsHTML = !isXML(doc);
  4457. if (parent && parent !== getTop(parent)) {
  4458. if (parent.addEventListener) {
  4459. parent.addEventListener('unload', function () {
  4460. setDocument();
  4461. }, false);
  4462. } else if (parent.attachEvent) {
  4463. parent.attachEvent('onunload', function () {
  4464. setDocument();
  4465. });
  4466. }
  4467. }
  4468. support.attributes = true;
  4469. support.getElementsByTagName = true;
  4470. support.getElementsByClassName = rnative.test(doc.getElementsByClassName);
  4471. support.getById = true;
  4472. Expr.find.ID = function (id, context) {
  4473. if (typeof context.getElementById !== strundefined && documentIsHTML) {
  4474. var m = context.getElementById(id);
  4475. return m && m.parentNode ? [m] : [];
  4476. }
  4477. };
  4478. Expr.filter.ID = function (id) {
  4479. var attrId = id.replace(runescape, funescape);
  4480. return function (elem) {
  4481. return elem.getAttribute('id') === attrId;
  4482. };
  4483. };
  4484. Expr.find.TAG = support.getElementsByTagName ? function (tag, context) {
  4485. if (typeof context.getElementsByTagName !== strundefined) {
  4486. return context.getElementsByTagName(tag);
  4487. }
  4488. } : function (tag, context) {
  4489. var elem, tmp = [], i = 0, results = context.getElementsByTagName(tag);
  4490. if (tag === '*') {
  4491. while (elem = results[i++]) {
  4492. if (elem.nodeType === 1) {
  4493. tmp.push(elem);
  4494. }
  4495. }
  4496. return tmp;
  4497. }
  4498. return results;
  4499. };
  4500. Expr.find.CLASS = support.getElementsByClassName && function (className, context) {
  4501. if (documentIsHTML) {
  4502. return context.getElementsByClassName(className);
  4503. }
  4504. };
  4505. rbuggyMatches = [];
  4506. rbuggyQSA = [];
  4507. support.disconnectedMatch = true;
  4508. rbuggyQSA = rbuggyQSA.length && new RegExp(rbuggyQSA.join('|'));
  4509. rbuggyMatches = rbuggyMatches.length && new RegExp(rbuggyMatches.join('|'));
  4510. hasCompare = rnative.test(docElem.compareDocumentPosition);
  4511. contains$3 = hasCompare || rnative.test(docElem.contains) ? function (a, b) {
  4512. var adown = a.nodeType === 9 ? a.documentElement : a, bup = b && b.parentNode;
  4513. return a === bup || !!(bup && bup.nodeType === 1 && (adown.contains ? adown.contains(bup) : a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16));
  4514. } : function (a, b) {
  4515. if (b) {
  4516. while (b = b.parentNode) {
  4517. if (b === a) {
  4518. return true;
  4519. }
  4520. }
  4521. }
  4522. return false;
  4523. };
  4524. sortOrder = hasCompare ? function (a, b) {
  4525. if (a === b) {
  4526. hasDuplicate = true;
  4527. return 0;
  4528. }
  4529. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  4530. if (compare) {
  4531. return compare;
  4532. }
  4533. compare = (a.ownerDocument || a) === (b.ownerDocument || b) ? a.compareDocumentPosition(b) : 1;
  4534. if (compare & 1 || !support.sortDetached && b.compareDocumentPosition(a) === compare) {
  4535. if (a === doc || a.ownerDocument === preferredDoc && contains$3(preferredDoc, a)) {
  4536. return -1;
  4537. }
  4538. if (b === doc || b.ownerDocument === preferredDoc && contains$3(preferredDoc, b)) {
  4539. return 1;
  4540. }
  4541. return sortInput ? indexOf$2.call(sortInput, a) - indexOf$2.call(sortInput, b) : 0;
  4542. }
  4543. return compare & 4 ? -1 : 1;
  4544. } : function (a, b) {
  4545. if (a === b) {
  4546. hasDuplicate = true;
  4547. return 0;
  4548. }
  4549. var cur, i = 0, aup = a.parentNode, bup = b.parentNode, ap = [a], bp = [b];
  4550. if (!aup || !bup) {
  4551. return a === doc ? -1 : b === doc ? 1 : aup ? -1 : bup ? 1 : sortInput ? indexOf$2.call(sortInput, a) - indexOf$2.call(sortInput, b) : 0;
  4552. } else if (aup === bup) {
  4553. return siblingCheck(a, b);
  4554. }
  4555. cur = a;
  4556. while (cur = cur.parentNode) {
  4557. ap.unshift(cur);
  4558. }
  4559. cur = b;
  4560. while (cur = cur.parentNode) {
  4561. bp.unshift(cur);
  4562. }
  4563. while (ap[i] === bp[i]) {
  4564. i++;
  4565. }
  4566. return i ? siblingCheck(ap[i], bp[i]) : ap[i] === preferredDoc ? -1 : bp[i] === preferredDoc ? 1 : 0;
  4567. };
  4568. return doc;
  4569. };
  4570. Sizzle.matches = function (expr, elements) {
  4571. return Sizzle(expr, null, null, elements);
  4572. };
  4573. Sizzle.matchesSelector = function (elem, expr) {
  4574. if ((elem.ownerDocument || elem) !== document) {
  4575. setDocument(elem);
  4576. }
  4577. expr = expr.replace(rattributeQuotes, '=\'$1\']');
  4578. if (support.matchesSelector && documentIsHTML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && (!rbuggyQSA || !rbuggyQSA.test(expr))) {
  4579. try {
  4580. var ret = matches.call(elem, expr);
  4581. if (ret || support.disconnectedMatch || elem.document && elem.document.nodeType !== 11) {
  4582. return ret;
  4583. }
  4584. } catch (e) {
  4585. }
  4586. }
  4587. return Sizzle(expr, document, null, [elem]).length > 0;
  4588. };
  4589. Sizzle.contains = function (context, elem) {
  4590. if ((context.ownerDocument || context) !== document) {
  4591. setDocument(context);
  4592. }
  4593. return contains$3(context, elem);
  4594. };
  4595. Sizzle.attr = function (elem, name) {
  4596. if ((elem.ownerDocument || elem) !== document) {
  4597. setDocument(elem);
  4598. }
  4599. var fn = Expr.attrHandle[name.toLowerCase()], val = fn && hasOwn.call(Expr.attrHandle, name.toLowerCase()) ? fn(elem, name, !documentIsHTML) : undefined;
  4600. return val !== undefined ? val : support.attributes || !documentIsHTML ? elem.getAttribute(name) : (val = elem.getAttributeNode(name)) && val.specified ? val.value : null;
  4601. };
  4602. Sizzle.error = function (msg) {
  4603. throw new Error('Syntax error, unrecognized expression: ' + msg);
  4604. };
  4605. Sizzle.uniqueSort = function (results) {
  4606. var elem, duplicates = [], j = 0, i = 0;
  4607. hasDuplicate = !support.detectDuplicates;
  4608. sortInput = !support.sortStable && results.slice(0);
  4609. results.sort(sortOrder);
  4610. if (hasDuplicate) {
  4611. while (elem = results[i++]) {
  4612. if (elem === results[i]) {
  4613. j = duplicates.push(i);
  4614. }
  4615. }
  4616. while (j--) {
  4617. results.splice(duplicates[j], 1);
  4618. }
  4619. }
  4620. sortInput = null;
  4621. return results;
  4622. };
  4623. getText = Sizzle.getText = function (elem) {
  4624. var node, ret = '', i = 0, nodeType = elem.nodeType;
  4625. if (!nodeType) {
  4626. while (node = elem[i++]) {
  4627. ret += getText(node);
  4628. }
  4629. } else if (nodeType === 1 || nodeType === 9 || nodeType === 11) {
  4630. if (typeof elem.textContent === 'string') {
  4631. return elem.textContent;
  4632. } else {
  4633. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  4634. ret += getText(elem);
  4635. }
  4636. }
  4637. } else if (nodeType === 3 || nodeType === 4) {
  4638. return elem.nodeValue;
  4639. }
  4640. return ret;
  4641. };
  4642. Expr = Sizzle.selectors = {
  4643. cacheLength: 50,
  4644. createPseudo: markFunction,
  4645. match: matchExpr,
  4646. attrHandle: {},
  4647. find: {},
  4648. relative: {
  4649. '>': {
  4650. dir: 'parentNode',
  4651. first: true
  4652. },
  4653. ' ': { dir: 'parentNode' },
  4654. '+': {
  4655. dir: 'previousSibling',
  4656. first: true
  4657. },
  4658. '~': { dir: 'previousSibling' }
  4659. },
  4660. preFilter: {
  4661. ATTR: function (match) {
  4662. match[1] = match[1].replace(runescape, funescape);
  4663. match[3] = (match[3] || match[4] || match[5] || '').replace(runescape, funescape);
  4664. if (match[2] === '~=') {
  4665. match[3] = ' ' + match[3] + ' ';
  4666. }
  4667. return match.slice(0, 4);
  4668. },
  4669. CHILD: function (match) {
  4670. match[1] = match[1].toLowerCase();
  4671. if (match[1].slice(0, 3) === 'nth') {
  4672. if (!match[3]) {
  4673. Sizzle.error(match[0]);
  4674. }
  4675. match[4] = +(match[4] ? match[5] + (match[6] || 1) : 2 * (match[3] === 'even' || match[3] === 'odd'));
  4676. match[5] = +(match[7] + match[8] || match[3] === 'odd');
  4677. } else if (match[3]) {
  4678. Sizzle.error(match[0]);
  4679. }
  4680. return match;
  4681. },
  4682. PSEUDO: function (match) {
  4683. var excess, unquoted = !match[6] && match[2];
  4684. if (matchExpr.CHILD.test(match[0])) {
  4685. return null;
  4686. }
  4687. if (match[3]) {
  4688. match[2] = match[4] || match[5] || '';
  4689. } else if (unquoted && rpseudo.test(unquoted) && (excess = tokenize(unquoted, true)) && (excess = unquoted.indexOf(')', unquoted.length - excess) - unquoted.length)) {
  4690. match[0] = match[0].slice(0, excess);
  4691. match[2] = unquoted.slice(0, excess);
  4692. }
  4693. return match.slice(0, 3);
  4694. }
  4695. },
  4696. filter: {
  4697. TAG: function (nodeNameSelector) {
  4698. var nodeName = nodeNameSelector.replace(runescape, funescape).toLowerCase();
  4699. return nodeNameSelector === '*' ? function () {
  4700. return true;
  4701. } : function (elem) {
  4702. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  4703. };
  4704. },
  4705. CLASS: function (className) {
  4706. var pattern = classCache[className + ' '];
  4707. return pattern || (pattern = new RegExp('(^|' + whitespace + ')' + className + '(' + whitespace + '|$)')) && classCache(className, function (elem) {
  4708. return pattern.test(typeof elem.className === 'string' && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute('class') || '');
  4709. });
  4710. },
  4711. ATTR: function (name, operator, check) {
  4712. return function (elem) {
  4713. var result = Sizzle.attr(elem, name);
  4714. if (result == null) {
  4715. return operator === '!=';
  4716. }
  4717. if (!operator) {
  4718. return true;
  4719. }
  4720. result += '';
  4721. return operator === '=' ? result === check : operator === '!=' ? result !== check : operator === '^=' ? check && result.indexOf(check) === 0 : operator === '*=' ? check && result.indexOf(check) > -1 : operator === '$=' ? check && result.slice(-check.length) === check : operator === '~=' ? (' ' + result + ' ').indexOf(check) > -1 : operator === '|=' ? result === check || result.slice(0, check.length + 1) === check + '-' : false;
  4722. };
  4723. },
  4724. CHILD: function (type, what, argument, first, last) {
  4725. var simple = type.slice(0, 3) !== 'nth', forward = type.slice(-4) !== 'last', ofType = what === 'of-type';
  4726. return first === 1 && last === 0 ? function (elem) {
  4727. return !!elem.parentNode;
  4728. } : function (elem, context, xml) {
  4729. var cache, outerCache, node, diff, nodeIndex, start, dir = simple !== forward ? 'nextSibling' : 'previousSibling', parent = elem.parentNode, name = ofType && elem.nodeName.toLowerCase(), useCache = !xml && !ofType;
  4730. if (parent) {
  4731. if (simple) {
  4732. while (dir) {
  4733. node = elem;
  4734. while (node = node[dir]) {
  4735. if (ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) {
  4736. return false;
  4737. }
  4738. }
  4739. start = dir = type === 'only' && !start && 'nextSibling';
  4740. }
  4741. return true;
  4742. }
  4743. start = [forward ? parent.firstChild : parent.lastChild];
  4744. if (forward && useCache) {
  4745. outerCache = parent[expando] || (parent[expando] = {});
  4746. cache = outerCache[type] || [];
  4747. nodeIndex = cache[0] === dirruns && cache[1];
  4748. diff = cache[0] === dirruns && cache[2];
  4749. node = nodeIndex && parent.childNodes[nodeIndex];
  4750. while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) {
  4751. if (node.nodeType === 1 && ++diff && node === elem) {
  4752. outerCache[type] = [
  4753. dirruns,
  4754. nodeIndex,
  4755. diff
  4756. ];
  4757. break;
  4758. }
  4759. }
  4760. } else if (useCache && (cache = (elem[expando] || (elem[expando] = {}))[type]) && cache[0] === dirruns) {
  4761. diff = cache[1];
  4762. } else {
  4763. while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) {
  4764. if ((ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) && ++diff) {
  4765. if (useCache) {
  4766. (node[expando] || (node[expando] = {}))[type] = [
  4767. dirruns,
  4768. diff
  4769. ];
  4770. }
  4771. if (node === elem) {
  4772. break;
  4773. }
  4774. }
  4775. }
  4776. }
  4777. diff -= last;
  4778. return diff === first || diff % first === 0 && diff / first >= 0;
  4779. }
  4780. };
  4781. },
  4782. PSEUDO: function (pseudo, argument) {
  4783. var args, fn = Expr.pseudos[pseudo] || Expr.setFilters[pseudo.toLowerCase()] || Sizzle.error('unsupported pseudo: ' + pseudo);
  4784. if (fn[expando]) {
  4785. return fn(argument);
  4786. }
  4787. if (fn.length > 1) {
  4788. args = [
  4789. pseudo,
  4790. pseudo,
  4791. '',
  4792. argument
  4793. ];
  4794. return Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function (seed, matches) {
  4795. var idx, matched = fn(seed, argument), i = matched.length;
  4796. while (i--) {
  4797. idx = indexOf$2.call(seed, matched[i]);
  4798. seed[idx] = !(matches[idx] = matched[i]);
  4799. }
  4800. }) : function (elem) {
  4801. return fn(elem, 0, args);
  4802. };
  4803. }
  4804. return fn;
  4805. }
  4806. },
  4807. pseudos: {
  4808. not: markFunction(function (selector) {
  4809. var input = [], results = [], matcher = compile(selector.replace(rtrim, '$1'));
  4810. return matcher[expando] ? markFunction(function (seed, matches, context, xml) {
  4811. var elem, unmatched = matcher(seed, null, xml, []), i = seed.length;
  4812. while (i--) {
  4813. if (elem = unmatched[i]) {
  4814. seed[i] = !(matches[i] = elem);
  4815. }
  4816. }
  4817. }) : function (elem, context, xml) {
  4818. input[0] = elem;
  4819. matcher(input, null, xml, results);
  4820. return !results.pop();
  4821. };
  4822. }),
  4823. has: markFunction(function (selector) {
  4824. return function (elem) {
  4825. return Sizzle(selector, elem).length > 0;
  4826. };
  4827. }),
  4828. contains: markFunction(function (text) {
  4829. text = text.replace(runescape, funescape);
  4830. return function (elem) {
  4831. return (elem.textContent || elem.innerText || getText(elem)).indexOf(text) > -1;
  4832. };
  4833. }),
  4834. lang: markFunction(function (lang) {
  4835. if (!ridentifier.test(lang || '')) {
  4836. Sizzle.error('unsupported lang: ' + lang);
  4837. }
  4838. lang = lang.replace(runescape, funescape).toLowerCase();
  4839. return function (elem) {
  4840. var elemLang;
  4841. do {
  4842. if (elemLang = documentIsHTML ? elem.lang : elem.getAttribute('xml:lang') || elem.getAttribute('lang')) {
  4843. elemLang = elemLang.toLowerCase();
  4844. return elemLang === lang || elemLang.indexOf(lang + '-') === 0;
  4845. }
  4846. } while ((elem = elem.parentNode) && elem.nodeType === 1);
  4847. return false;
  4848. };
  4849. }),
  4850. target: function (elem) {
  4851. var hash = domGlobals.window.location && domGlobals.window.location.hash;
  4852. return hash && hash.slice(1) === elem.id;
  4853. },
  4854. root: function (elem) {
  4855. return elem === docElem;
  4856. },
  4857. focus: function (elem) {
  4858. return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  4859. },
  4860. enabled: function (elem) {
  4861. return elem.disabled === false;
  4862. },
  4863. disabled: function (elem) {
  4864. return elem.disabled === true;
  4865. },
  4866. checked: function (elem) {
  4867. var nodeName = elem.nodeName.toLowerCase();
  4868. return nodeName === 'input' && !!elem.checked || nodeName === 'option' && !!elem.selected;
  4869. },
  4870. selected: function (elem) {
  4871. if (elem.parentNode) {
  4872. elem.parentNode.selectedIndex;
  4873. }
  4874. return elem.selected === true;
  4875. },
  4876. empty: function (elem) {
  4877. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  4878. if (elem.nodeType < 6) {
  4879. return false;
  4880. }
  4881. }
  4882. return true;
  4883. },
  4884. parent: function (elem) {
  4885. return !Expr.pseudos.empty(elem);
  4886. },
  4887. header: function (elem) {
  4888. return rheader.test(elem.nodeName);
  4889. },
  4890. input: function (elem) {
  4891. return rinputs.test(elem.nodeName);
  4892. },
  4893. button: function (elem) {
  4894. var name = elem.nodeName.toLowerCase();
  4895. return name === 'input' && elem.type === 'button' || name === 'button';
  4896. },
  4897. text: function (elem) {
  4898. var attr;
  4899. return elem.nodeName.toLowerCase() === 'input' && elem.type === 'text' && ((attr = elem.getAttribute('type')) == null || attr.toLowerCase() === 'text');
  4900. },
  4901. first: createPositionalPseudo(function () {
  4902. return [0];
  4903. }),
  4904. last: createPositionalPseudo(function (matchIndexes, length) {
  4905. return [length - 1];
  4906. }),
  4907. eq: createPositionalPseudo(function (matchIndexes, length, argument) {
  4908. return [argument < 0 ? argument + length : argument];
  4909. }),
  4910. even: createPositionalPseudo(function (matchIndexes, length) {
  4911. var i = 0;
  4912. for (; i < length; i += 2) {
  4913. matchIndexes.push(i);
  4914. }
  4915. return matchIndexes;
  4916. }),
  4917. odd: createPositionalPseudo(function (matchIndexes, length) {
  4918. var i = 1;
  4919. for (; i < length; i += 2) {
  4920. matchIndexes.push(i);
  4921. }
  4922. return matchIndexes;
  4923. }),
  4924. lt: createPositionalPseudo(function (matchIndexes, length, argument) {
  4925. var i = argument < 0 ? argument + length : argument;
  4926. for (; --i >= 0;) {
  4927. matchIndexes.push(i);
  4928. }
  4929. return matchIndexes;
  4930. }),
  4931. gt: createPositionalPseudo(function (matchIndexes, length, argument) {
  4932. var i = argument < 0 ? argument + length : argument;
  4933. for (; ++i < length;) {
  4934. matchIndexes.push(i);
  4935. }
  4936. return matchIndexes;
  4937. })
  4938. }
  4939. };
  4940. Expr.pseudos.nth = Expr.pseudos.eq;
  4941. for (i in {
  4942. radio: true,
  4943. checkbox: true,
  4944. file: true,
  4945. password: true,
  4946. image: true
  4947. }) {
  4948. Expr.pseudos[i] = createInputPseudo(i);
  4949. }
  4950. for (i in {
  4951. submit: true,
  4952. reset: true
  4953. }) {
  4954. Expr.pseudos[i] = createButtonPseudo(i);
  4955. }
  4956. function setFilters() {
  4957. }
  4958. setFilters.prototype = Expr.filters = Expr.pseudos;
  4959. Expr.setFilters = new setFilters();
  4960. tokenize = Sizzle.tokenize = function (selector, parseOnly) {
  4961. var matched, match, tokens, type, soFar, groups, preFilters, cached = tokenCache[selector + ' '];
  4962. if (cached) {
  4963. return parseOnly ? 0 : cached.slice(0);
  4964. }
  4965. soFar = selector;
  4966. groups = [];
  4967. preFilters = Expr.preFilter;
  4968. while (soFar) {
  4969. if (!matched || (match = rcomma.exec(soFar))) {
  4970. if (match) {
  4971. soFar = soFar.slice(match[0].length) || soFar;
  4972. }
  4973. groups.push(tokens = []);
  4974. }
  4975. matched = false;
  4976. if (match = rcombinators.exec(soFar)) {
  4977. matched = match.shift();
  4978. tokens.push({
  4979. value: matched,
  4980. type: match[0].replace(rtrim, ' ')
  4981. });
  4982. soFar = soFar.slice(matched.length);
  4983. }
  4984. for (type in Expr.filter) {
  4985. if (!Expr.filter.hasOwnProperty(type))
  4986. continue;
  4987. if ((match = matchExpr[type].exec(soFar)) && (!preFilters[type] || (match = preFilters[type](match)))) {
  4988. matched = match.shift();
  4989. tokens.push({
  4990. value: matched,
  4991. type: type,
  4992. matches: match
  4993. });
  4994. soFar = soFar.slice(matched.length);
  4995. }
  4996. }
  4997. if (!matched) {
  4998. break;
  4999. }
  5000. }
  5001. return parseOnly ? soFar.length : soFar ? Sizzle.error(selector) : tokenCache(selector, groups).slice(0);
  5002. };
  5003. function toSelector(tokens) {
  5004. var i = 0, len = tokens.length, selector = '';
  5005. for (; i < len; i++) {
  5006. selector += tokens[i].value;
  5007. }
  5008. return selector;
  5009. }
  5010. function addCombinator(matcher, combinator, base) {
  5011. var dir = combinator.dir, checkNonElements = base && dir === 'parentNode', doneName = done++;
  5012. return combinator.first ? function (elem, context, xml) {
  5013. while (elem = elem[dir]) {
  5014. if (elem.nodeType === 1 || checkNonElements) {
  5015. return matcher(elem, context, xml);
  5016. }
  5017. }
  5018. } : function (elem, context, xml) {
  5019. var oldCache, outerCache, newCache = [
  5020. dirruns,
  5021. doneName
  5022. ];
  5023. if (xml) {
  5024. while (elem = elem[dir]) {
  5025. if (elem.nodeType === 1 || checkNonElements) {
  5026. if (matcher(elem, context, xml)) {
  5027. return true;
  5028. }
  5029. }
  5030. }
  5031. } else {
  5032. while (elem = elem[dir]) {
  5033. if (elem.nodeType === 1 || checkNonElements) {
  5034. outerCache = elem[expando] || (elem[expando] = {});
  5035. if ((oldCache = outerCache[dir]) && oldCache[0] === dirruns && oldCache[1] === doneName) {
  5036. return newCache[2] = oldCache[2];
  5037. } else {
  5038. outerCache[dir] = newCache;
  5039. if (newCache[2] = matcher(elem, context, xml)) {
  5040. return true;
  5041. }
  5042. }
  5043. }
  5044. }
  5045. }
  5046. };
  5047. }
  5048. function elementMatcher(matchers) {
  5049. return matchers.length > 1 ? function (elem, context, xml) {
  5050. var i = matchers.length;
  5051. while (i--) {
  5052. if (!matchers[i](elem, context, xml)) {
  5053. return false;
  5054. }
  5055. }
  5056. return true;
  5057. } : matchers[0];
  5058. }
  5059. function multipleContexts(selector, contexts, results) {
  5060. var i = 0, len = contexts.length;
  5061. for (; i < len; i++) {
  5062. Sizzle(selector, contexts[i], results);
  5063. }
  5064. return results;
  5065. }
  5066. function condense(unmatched, map, filter, context, xml) {
  5067. var elem, newUnmatched = [], i = 0, len = unmatched.length, mapped = map != null;
  5068. for (; i < len; i++) {
  5069. if (elem = unmatched[i]) {
  5070. if (!filter || filter(elem, context, xml)) {
  5071. newUnmatched.push(elem);
  5072. if (mapped) {
  5073. map.push(i);
  5074. }
  5075. }
  5076. }
  5077. }
  5078. return newUnmatched;
  5079. }
  5080. function setMatcher(preFilter, selector, matcher, postFilter, postFinder, postSelector) {
  5081. if (postFilter && !postFilter[expando]) {
  5082. postFilter = setMatcher(postFilter);
  5083. }
  5084. if (postFinder && !postFinder[expando]) {
  5085. postFinder = setMatcher(postFinder, postSelector);
  5086. }
  5087. return markFunction(function (seed, results, context, xml) {
  5088. var temp, i, elem, preMap = [], postMap = [], preexisting = results.length, elems = seed || multipleContexts(selector || '*', context.nodeType ? [context] : context, []), matcherIn = preFilter && (seed || !selector) ? condense(elems, preMap, preFilter, context, xml) : elems, matcherOut = matcher ? postFinder || (seed ? preFilter : preexisting || postFilter) ? [] : results : matcherIn;
  5089. if (matcher) {
  5090. matcher(matcherIn, matcherOut, context, xml);
  5091. }
  5092. if (postFilter) {
  5093. temp = condense(matcherOut, postMap);
  5094. postFilter(temp, [], context, xml);
  5095. i = temp.length;
  5096. while (i--) {
  5097. if (elem = temp[i]) {
  5098. matcherOut[postMap[i]] = !(matcherIn[postMap[i]] = elem);
  5099. }
  5100. }
  5101. }
  5102. if (seed) {
  5103. if (postFinder || preFilter) {
  5104. if (postFinder) {
  5105. temp = [];
  5106. i = matcherOut.length;
  5107. while (i--) {
  5108. if (elem = matcherOut[i]) {
  5109. temp.push(matcherIn[i] = elem);
  5110. }
  5111. }
  5112. postFinder(null, matcherOut = [], temp, xml);
  5113. }
  5114. i = matcherOut.length;
  5115. while (i--) {
  5116. if ((elem = matcherOut[i]) && (temp = postFinder ? indexOf$2.call(seed, elem) : preMap[i]) > -1) {
  5117. seed[temp] = !(results[temp] = elem);
  5118. }
  5119. }
  5120. }
  5121. } else {
  5122. matcherOut = condense(matcherOut === results ? matcherOut.splice(preexisting, matcherOut.length) : matcherOut);
  5123. if (postFinder) {
  5124. postFinder(null, results, matcherOut, xml);
  5125. } else {
  5126. push.apply(results, matcherOut);
  5127. }
  5128. }
  5129. });
  5130. }
  5131. function matcherFromTokens(tokens) {
  5132. var checkContext, matcher, j, len = tokens.length, leadingRelative = Expr.relative[tokens[0].type], implicitRelative = leadingRelative || Expr.relative[' '], i = leadingRelative ? 1 : 0, matchContext = addCombinator(function (elem) {
  5133. return elem === checkContext;
  5134. }, implicitRelative, true), matchAnyContext = addCombinator(function (elem) {
  5135. return indexOf$2.call(checkContext, elem) > -1;
  5136. }, implicitRelative, true), matchers = [function (elem, context, xml) {
  5137. return !leadingRelative && (xml || context !== outermostContext) || ((checkContext = context).nodeType ? matchContext(elem, context, xml) : matchAnyContext(elem, context, xml));
  5138. }];
  5139. for (; i < len; i++) {
  5140. if (matcher = Expr.relative[tokens[i].type]) {
  5141. matchers = [addCombinator(elementMatcher(matchers), matcher)];
  5142. } else {
  5143. matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches);
  5144. if (matcher[expando]) {
  5145. j = ++i;
  5146. for (; j < len; j++) {
  5147. if (Expr.relative[tokens[j].type]) {
  5148. break;
  5149. }
  5150. }
  5151. return setMatcher(i > 1 && elementMatcher(matchers), i > 1 && toSelector(tokens.slice(0, i - 1).concat({ value: tokens[i - 2].type === ' ' ? '*' : '' })).replace(rtrim, '$1'), matcher, i < j && matcherFromTokens(tokens.slice(i, j)), j < len && matcherFromTokens(tokens = tokens.slice(j)), j < len && toSelector(tokens));
  5152. }
  5153. matchers.push(matcher);
  5154. }
  5155. }
  5156. return elementMatcher(matchers);
  5157. }
  5158. function matcherFromGroupMatchers(elementMatchers, setMatchers) {
  5159. var bySet = setMatchers.length > 0, byElement = elementMatchers.length > 0, superMatcher = function (seed, context, xml, results, outermost) {
  5160. var elem, j, matcher, matchedCount = 0, i = '0', unmatched = seed && [], setMatched = [], contextBackup = outermostContext, elems = seed || byElement && Expr.find.TAG('*', outermost), dirrunsUnique = dirruns += contextBackup == null ? 1 : Math.random() || 0.1, len = elems.length;
  5161. if (outermost) {
  5162. outermostContext = context !== document && context;
  5163. }
  5164. for (; i !== len && (elem = elems[i]) != null; i++) {
  5165. if (byElement && elem) {
  5166. j = 0;
  5167. while (matcher = elementMatchers[j++]) {
  5168. if (matcher(elem, context, xml)) {
  5169. results.push(elem);
  5170. break;
  5171. }
  5172. }
  5173. if (outermost) {
  5174. dirruns = dirrunsUnique;
  5175. }
  5176. }
  5177. if (bySet) {
  5178. if (elem = !matcher && elem) {
  5179. matchedCount--;
  5180. }
  5181. if (seed) {
  5182. unmatched.push(elem);
  5183. }
  5184. }
  5185. }
  5186. matchedCount += i;
  5187. if (bySet && i !== matchedCount) {
  5188. j = 0;
  5189. while (matcher = setMatchers[j++]) {
  5190. matcher(unmatched, setMatched, context, xml);
  5191. }
  5192. if (seed) {
  5193. if (matchedCount > 0) {
  5194. while (i--) {
  5195. if (!(unmatched[i] || setMatched[i])) {
  5196. setMatched[i] = pop.call(results);
  5197. }
  5198. }
  5199. }
  5200. setMatched = condense(setMatched);
  5201. }
  5202. push.apply(results, setMatched);
  5203. if (outermost && !seed && setMatched.length > 0 && matchedCount + setMatchers.length > 1) {
  5204. Sizzle.uniqueSort(results);
  5205. }
  5206. }
  5207. if (outermost) {
  5208. dirruns = dirrunsUnique;
  5209. outermostContext = contextBackup;
  5210. }
  5211. return unmatched;
  5212. };
  5213. return bySet ? markFunction(superMatcher) : superMatcher;
  5214. }
  5215. compile = Sizzle.compile = function (selector, match) {
  5216. var i, setMatchers = [], elementMatchers = [], cached = compilerCache[selector + ' '];
  5217. if (!cached) {
  5218. if (!match) {
  5219. match = tokenize(selector);
  5220. }
  5221. i = match.length;
  5222. while (i--) {
  5223. cached = matcherFromTokens(match[i]);
  5224. if (cached[expando]) {
  5225. setMatchers.push(cached);
  5226. } else {
  5227. elementMatchers.push(cached);
  5228. }
  5229. }
  5230. cached = compilerCache(selector, matcherFromGroupMatchers(elementMatchers, setMatchers));
  5231. cached.selector = selector;
  5232. }
  5233. return cached;
  5234. };
  5235. select = Sizzle.select = function (selector, context, results, seed) {
  5236. var i, tokens, token, type, find, compiled = typeof selector === 'function' && selector, match = !seed && tokenize(selector = compiled.selector || selector);
  5237. results = results || [];
  5238. if (match.length === 1) {
  5239. tokens = match[0] = match[0].slice(0);
  5240. if (tokens.length > 2 && (token = tokens[0]).type === 'ID' && support.getById && context.nodeType === 9 && documentIsHTML && Expr.relative[tokens[1].type]) {
  5241. context = (Expr.find.ID(token.matches[0].replace(runescape, funescape), context) || [])[0];
  5242. if (!context) {
  5243. return results;
  5244. } else if (compiled) {
  5245. context = context.parentNode;
  5246. }
  5247. selector = selector.slice(tokens.shift().value.length);
  5248. }
  5249. i = matchExpr.needsContext.test(selector) ? 0 : tokens.length;
  5250. while (i--) {
  5251. token = tokens[i];
  5252. if (Expr.relative[type = token.type]) {
  5253. break;
  5254. }
  5255. if (find = Expr.find[type]) {
  5256. if (seed = find(token.matches[0].replace(runescape, funescape), rsibling.test(tokens[0].type) && testContext(context.parentNode) || context)) {
  5257. tokens.splice(i, 1);
  5258. selector = seed.length && toSelector(tokens);
  5259. if (!selector) {
  5260. push.apply(results, seed);
  5261. return results;
  5262. }
  5263. break;
  5264. }
  5265. }
  5266. }
  5267. }
  5268. (compiled || compile(selector, match))(seed, context, !documentIsHTML, results, rsibling.test(selector) && testContext(context.parentNode) || context);
  5269. return results;
  5270. };
  5271. support.sortStable = expando.split('').sort(sortOrder).join('') === expando;
  5272. support.detectDuplicates = !!hasDuplicate;
  5273. setDocument();
  5274. support.sortDetached = true;
  5275. var doc = domGlobals.document, push$1 = Array.prototype.push, slice$1 = Array.prototype.slice;
  5276. var rquickExpr$1 = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/;
  5277. var Event = EventUtils.Event;
  5278. var skipUniques = Tools.makeMap('children,contents,next,prev');
  5279. var isDefined = function (obj) {
  5280. return typeof obj !== 'undefined';
  5281. };
  5282. var isString$1 = function (obj) {
  5283. return typeof obj === 'string';
  5284. };
  5285. var isWindow = function (obj) {
  5286. return obj && obj === obj.window;
  5287. };
  5288. var createFragment = function (html, fragDoc) {
  5289. var frag, node, container;
  5290. fragDoc = fragDoc || doc;
  5291. container = fragDoc.createElement('div');
  5292. frag = fragDoc.createDocumentFragment();
  5293. container.innerHTML = html;
  5294. while (node = container.firstChild) {
  5295. frag.appendChild(node);
  5296. }
  5297. return frag;
  5298. };
  5299. var domManipulate = function (targetNodes, sourceItem, callback, reverse) {
  5300. var i;
  5301. if (isString$1(sourceItem)) {
  5302. sourceItem = createFragment(sourceItem, getElementDocument(targetNodes[0]));
  5303. } else if (sourceItem.length && !sourceItem.nodeType) {
  5304. sourceItem = DomQuery.makeArray(sourceItem);
  5305. if (reverse) {
  5306. for (i = sourceItem.length - 1; i >= 0; i--) {
  5307. domManipulate(targetNodes, sourceItem[i], callback, reverse);
  5308. }
  5309. } else {
  5310. for (i = 0; i < sourceItem.length; i++) {
  5311. domManipulate(targetNodes, sourceItem[i], callback, reverse);
  5312. }
  5313. }
  5314. return targetNodes;
  5315. }
  5316. if (sourceItem.nodeType) {
  5317. i = targetNodes.length;
  5318. while (i--) {
  5319. callback.call(targetNodes[i], sourceItem);
  5320. }
  5321. }
  5322. return targetNodes;
  5323. };
  5324. var hasClass = function (node, className) {
  5325. return node && className && (' ' + node.className + ' ').indexOf(' ' + className + ' ') !== -1;
  5326. };
  5327. var wrap = function (elements, wrapper, all) {
  5328. var lastParent, newWrapper;
  5329. wrapper = DomQuery(wrapper)[0];
  5330. elements.each(function () {
  5331. var self = this;
  5332. if (!all || lastParent !== self.parentNode) {
  5333. lastParent = self.parentNode;
  5334. newWrapper = wrapper.cloneNode(false);
  5335. self.parentNode.insertBefore(newWrapper, self);
  5336. newWrapper.appendChild(self);
  5337. } else {
  5338. newWrapper.appendChild(self);
  5339. }
  5340. });
  5341. return elements;
  5342. };
  5343. var numericCssMap = Tools.makeMap('fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom', ' ');
  5344. var booleanMap = Tools.makeMap('checked compact declare defer disabled ismap multiple nohref noshade nowrap readonly selected', ' ');
  5345. var propFix = {
  5346. for: 'htmlFor',
  5347. class: 'className',
  5348. readonly: 'readOnly'
  5349. };
  5350. var cssFix = { float: 'cssFloat' };
  5351. var attrHooks = {}, cssHooks = {};
  5352. var DomQueryConstructor = function (selector, context) {
  5353. return new DomQuery.fn.init(selector, context);
  5354. };
  5355. var inArray$1 = function (item, array) {
  5356. var i;
  5357. if (array.indexOf) {
  5358. return array.indexOf(item);
  5359. }
  5360. i = array.length;
  5361. while (i--) {
  5362. if (array[i] === item) {
  5363. return i;
  5364. }
  5365. }
  5366. return -1;
  5367. };
  5368. var whiteSpaceRegExp$1 = /^\s*|\s*$/g;
  5369. var trim$2 = function (str) {
  5370. return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp$1, '');
  5371. };
  5372. var each$4 = function (obj, callback) {
  5373. var length, key, i, value;
  5374. if (obj) {
  5375. length = obj.length;
  5376. if (length === undefined) {
  5377. for (key in obj) {
  5378. if (obj.hasOwnProperty(key)) {
  5379. value = obj[key];
  5380. if (callback.call(value, key, value) === false) {
  5381. break;
  5382. }
  5383. }
  5384. }
  5385. } else {
  5386. for (i = 0; i < length; i++) {
  5387. value = obj[i];
  5388. if (callback.call(value, i, value) === false) {
  5389. break;
  5390. }
  5391. }
  5392. }
  5393. }
  5394. return obj;
  5395. };
  5396. var grep = function (array, callback) {
  5397. var out = [];
  5398. each$4(array, function (i, item) {
  5399. if (callback(item, i)) {
  5400. out.push(item);
  5401. }
  5402. });
  5403. return out;
  5404. };
  5405. var getElementDocument = function (element) {
  5406. if (!element) {
  5407. return doc;
  5408. }
  5409. if (element.nodeType === 9) {
  5410. return element;
  5411. }
  5412. return element.ownerDocument;
  5413. };
  5414. DomQueryConstructor.fn = DomQueryConstructor.prototype = {
  5415. constructor: DomQueryConstructor,
  5416. selector: '',
  5417. context: null,
  5418. length: 0,
  5419. init: function (selector, context) {
  5420. var self = this;
  5421. var match, node;
  5422. if (!selector) {
  5423. return self;
  5424. }
  5425. if (selector.nodeType) {
  5426. self.context = self[0] = selector;
  5427. self.length = 1;
  5428. return self;
  5429. }
  5430. if (context && context.nodeType) {
  5431. self.context = context;
  5432. } else {
  5433. if (context) {
  5434. return DomQuery(selector).attr(context);
  5435. }
  5436. self.context = context = domGlobals.document;
  5437. }
  5438. if (isString$1(selector)) {
  5439. self.selector = selector;
  5440. if (selector.charAt(0) === '<' && selector.charAt(selector.length - 1) === '>' && selector.length >= 3) {
  5441. match = [
  5442. null,
  5443. selector,
  5444. null
  5445. ];
  5446. } else {
  5447. match = rquickExpr$1.exec(selector);
  5448. }
  5449. if (match) {
  5450. if (match[1]) {
  5451. node = createFragment(selector, getElementDocument(context)).firstChild;
  5452. while (node) {
  5453. push$1.call(self, node);
  5454. node = node.nextSibling;
  5455. }
  5456. } else {
  5457. node = getElementDocument(context).getElementById(match[2]);
  5458. if (!node) {
  5459. return self;
  5460. }
  5461. if (node.id !== match[2]) {
  5462. return self.find(selector);
  5463. }
  5464. self.length = 1;
  5465. self[0] = node;
  5466. }
  5467. } else {
  5468. return DomQuery(context).find(selector);
  5469. }
  5470. } else {
  5471. this.add(selector, false);
  5472. }
  5473. return self;
  5474. },
  5475. toArray: function () {
  5476. return Tools.toArray(this);
  5477. },
  5478. add: function (items, sort) {
  5479. var self = this;
  5480. var nodes, i;
  5481. if (isString$1(items)) {
  5482. return self.add(DomQuery(items));
  5483. }
  5484. if (sort !== false) {
  5485. nodes = DomQuery.unique(self.toArray().concat(DomQuery.makeArray(items)));
  5486. self.length = nodes.length;
  5487. for (i = 0; i < nodes.length; i++) {
  5488. self[i] = nodes[i];
  5489. }
  5490. } else {
  5491. push$1.apply(self, DomQuery.makeArray(items));
  5492. }
  5493. return self;
  5494. },
  5495. attr: function (name, value) {
  5496. var self = this;
  5497. var hook;
  5498. if (typeof name === 'object') {
  5499. each$4(name, function (name, value) {
  5500. self.attr(name, value);
  5501. });
  5502. } else if (isDefined(value)) {
  5503. this.each(function () {
  5504. var hook;
  5505. if (this.nodeType === 1) {
  5506. hook = attrHooks[name];
  5507. if (hook && hook.set) {
  5508. hook.set(this, value);
  5509. return;
  5510. }
  5511. if (value === null) {
  5512. this.removeAttribute(name, 2);
  5513. } else {
  5514. this.setAttribute(name, value, 2);
  5515. }
  5516. }
  5517. });
  5518. } else {
  5519. if (self[0] && self[0].nodeType === 1) {
  5520. hook = attrHooks[name];
  5521. if (hook && hook.get) {
  5522. return hook.get(self[0], name);
  5523. }
  5524. if (booleanMap[name]) {
  5525. return self.prop(name) ? name : undefined;
  5526. }
  5527. value = self[0].getAttribute(name, 2);
  5528. if (value === null) {
  5529. value = undefined;
  5530. }
  5531. }
  5532. return value;
  5533. }
  5534. return self;
  5535. },
  5536. removeAttr: function (name) {
  5537. return this.attr(name, null);
  5538. },
  5539. prop: function (name, value) {
  5540. var self = this;
  5541. name = propFix[name] || name;
  5542. if (typeof name === 'object') {
  5543. each$4(name, function (name, value) {
  5544. self.prop(name, value);
  5545. });
  5546. } else if (isDefined(value)) {
  5547. this.each(function () {
  5548. if (this.nodeType === 1) {
  5549. this[name] = value;
  5550. }
  5551. });
  5552. } else {
  5553. if (self[0] && self[0].nodeType && name in self[0]) {
  5554. return self[0][name];
  5555. }
  5556. return value;
  5557. }
  5558. return self;
  5559. },
  5560. css: function (name, value) {
  5561. var self = this;
  5562. var elm, hook;
  5563. var camel = function (name) {
  5564. return name.replace(/-(\D)/g, function (a, b) {
  5565. return b.toUpperCase();
  5566. });
  5567. };
  5568. var dashed = function (name) {
  5569. return name.replace(/[A-Z]/g, function (a) {
  5570. return '-' + a;
  5571. });
  5572. };
  5573. if (typeof name === 'object') {
  5574. each$4(name, function (name, value) {
  5575. self.css(name, value);
  5576. });
  5577. } else {
  5578. if (isDefined(value)) {
  5579. name = camel(name);
  5580. if (typeof value === 'number' && !numericCssMap[name]) {
  5581. value = value.toString() + 'px';
  5582. }
  5583. self.each(function () {
  5584. var style = this.style;
  5585. hook = cssHooks[name];
  5586. if (hook && hook.set) {
  5587. hook.set(this, value);
  5588. return;
  5589. }
  5590. try {
  5591. this.style[cssFix[name] || name] = value;
  5592. } catch (ex) {
  5593. }
  5594. if (value === null || value === '') {
  5595. if (style.removeProperty) {
  5596. style.removeProperty(dashed(name));
  5597. } else {
  5598. style.removeAttribute(name);
  5599. }
  5600. }
  5601. });
  5602. } else {
  5603. elm = self[0];
  5604. hook = cssHooks[name];
  5605. if (hook && hook.get) {
  5606. return hook.get(elm);
  5607. }
  5608. if (elm.ownerDocument.defaultView) {
  5609. try {
  5610. return elm.ownerDocument.defaultView.getComputedStyle(elm, null).getPropertyValue(dashed(name));
  5611. } catch (ex) {
  5612. return undefined;
  5613. }
  5614. } else if (elm.currentStyle) {
  5615. return elm.currentStyle[camel(name)];
  5616. } else {
  5617. return '';
  5618. }
  5619. }
  5620. }
  5621. return self;
  5622. },
  5623. remove: function () {
  5624. var self = this;
  5625. var node, i = this.length;
  5626. while (i--) {
  5627. node = self[i];
  5628. Event.clean(node);
  5629. if (node.parentNode) {
  5630. node.parentNode.removeChild(node);
  5631. }
  5632. }
  5633. return this;
  5634. },
  5635. empty: function () {
  5636. var self = this;
  5637. var node, i = this.length;
  5638. while (i--) {
  5639. node = self[i];
  5640. while (node.firstChild) {
  5641. node.removeChild(node.firstChild);
  5642. }
  5643. }
  5644. return this;
  5645. },
  5646. html: function (value) {
  5647. var self = this;
  5648. var i;
  5649. if (isDefined(value)) {
  5650. i = self.length;
  5651. try {
  5652. while (i--) {
  5653. self[i].innerHTML = value;
  5654. }
  5655. } catch (ex) {
  5656. DomQuery(self[i]).empty().append(value);
  5657. }
  5658. return self;
  5659. }
  5660. return self[0] ? self[0].innerHTML : '';
  5661. },
  5662. text: function (value) {
  5663. var self = this;
  5664. var i;
  5665. if (isDefined(value)) {
  5666. i = self.length;
  5667. while (i--) {
  5668. if ('innerText' in self[i]) {
  5669. self[i].innerText = value;
  5670. } else {
  5671. self[0].textContent = value;
  5672. }
  5673. }
  5674. return self;
  5675. }
  5676. return self[0] ? self[0].innerText || self[0].textContent : '';
  5677. },
  5678. append: function () {
  5679. return domManipulate(this, arguments, function (node) {
  5680. if (this.nodeType === 1 || this.host && this.host.nodeType === 1) {
  5681. this.appendChild(node);
  5682. }
  5683. });
  5684. },
  5685. prepend: function () {
  5686. return domManipulate(this, arguments, function (node) {
  5687. if (this.nodeType === 1 || this.host && this.host.nodeType === 1) {
  5688. this.insertBefore(node, this.firstChild);
  5689. }
  5690. }, true);
  5691. },
  5692. before: function () {
  5693. var self = this;
  5694. if (self[0] && self[0].parentNode) {
  5695. return domManipulate(self, arguments, function (node) {
  5696. this.parentNode.insertBefore(node, this);
  5697. });
  5698. }
  5699. return self;
  5700. },
  5701. after: function () {
  5702. var self = this;
  5703. if (self[0] && self[0].parentNode) {
  5704. return domManipulate(self, arguments, function (node) {
  5705. this.parentNode.insertBefore(node, this.nextSibling);
  5706. }, true);
  5707. }
  5708. return self;
  5709. },
  5710. appendTo: function (val) {
  5711. DomQuery(val).append(this);
  5712. return this;
  5713. },
  5714. prependTo: function (val) {
  5715. DomQuery(val).prepend(this);
  5716. return this;
  5717. },
  5718. replaceWith: function (content) {
  5719. return this.before(content).remove();
  5720. },
  5721. wrap: function (content) {
  5722. return wrap(this, content);
  5723. },
  5724. wrapAll: function (content) {
  5725. return wrap(this, content, true);
  5726. },
  5727. wrapInner: function (content) {
  5728. this.each(function () {
  5729. DomQuery(this).contents().wrapAll(content);
  5730. });
  5731. return this;
  5732. },
  5733. unwrap: function () {
  5734. return this.parent().each(function () {
  5735. DomQuery(this).replaceWith(this.childNodes);
  5736. });
  5737. },
  5738. clone: function () {
  5739. var result = [];
  5740. this.each(function () {
  5741. result.push(this.cloneNode(true));
  5742. });
  5743. return DomQuery(result);
  5744. },
  5745. addClass: function (className) {
  5746. return this.toggleClass(className, true);
  5747. },
  5748. removeClass: function (className) {
  5749. return this.toggleClass(className, false);
  5750. },
  5751. toggleClass: function (className, state) {
  5752. var self = this;
  5753. if (typeof className !== 'string') {
  5754. return self;
  5755. }
  5756. if (className.indexOf(' ') !== -1) {
  5757. each$4(className.split(' '), function () {
  5758. self.toggleClass(this, state);
  5759. });
  5760. } else {
  5761. self.each(function (index, node) {
  5762. var existingClassName, classState;
  5763. classState = hasClass(node, className);
  5764. if (classState !== state) {
  5765. existingClassName = node.className;
  5766. if (classState) {
  5767. node.className = trim$2((' ' + existingClassName + ' ').replace(' ' + className + ' ', ' '));
  5768. } else {
  5769. node.className += existingClassName ? ' ' + className : className;
  5770. }
  5771. }
  5772. });
  5773. }
  5774. return self;
  5775. },
  5776. hasClass: function (className) {
  5777. return hasClass(this[0], className);
  5778. },
  5779. each: function (callback) {
  5780. return each$4(this, callback);
  5781. },
  5782. on: function (name, callback) {
  5783. return this.each(function () {
  5784. Event.bind(this, name, callback);
  5785. });
  5786. },
  5787. off: function (name, callback) {
  5788. return this.each(function () {
  5789. Event.unbind(this, name, callback);
  5790. });
  5791. },
  5792. trigger: function (name) {
  5793. return this.each(function () {
  5794. if (typeof name === 'object') {
  5795. Event.fire(this, name.type, name);
  5796. } else {
  5797. Event.fire(this, name);
  5798. }
  5799. });
  5800. },
  5801. show: function () {
  5802. return this.css('display', '');
  5803. },
  5804. hide: function () {
  5805. return this.css('display', 'none');
  5806. },
  5807. slice: function () {
  5808. return new DomQuery(slice$1.apply(this, arguments));
  5809. },
  5810. eq: function (index) {
  5811. return index === -1 ? this.slice(index) : this.slice(index, +index + 1);
  5812. },
  5813. first: function () {
  5814. return this.eq(0);
  5815. },
  5816. last: function () {
  5817. return this.eq(-1);
  5818. },
  5819. find: function (selector) {
  5820. var i, l;
  5821. var ret = [];
  5822. for (i = 0, l = this.length; i < l; i++) {
  5823. DomQuery.find(selector, this[i], ret);
  5824. }
  5825. return DomQuery(ret);
  5826. },
  5827. filter: function (selector) {
  5828. if (typeof selector === 'function') {
  5829. return DomQuery(grep(this.toArray(), function (item, i) {
  5830. return selector(i, item);
  5831. }));
  5832. }
  5833. return DomQuery(DomQuery.filter(selector, this.toArray()));
  5834. },
  5835. closest: function (selector) {
  5836. var result = [];
  5837. if (selector instanceof DomQuery) {
  5838. selector = selector[0];
  5839. }
  5840. this.each(function (i, node) {
  5841. while (node) {
  5842. if (typeof selector === 'string' && DomQuery(node).is(selector)) {
  5843. result.push(node);
  5844. break;
  5845. } else if (node === selector) {
  5846. result.push(node);
  5847. break;
  5848. }
  5849. node = node.parentNode;
  5850. }
  5851. });
  5852. return DomQuery(result);
  5853. },
  5854. offset: function (offset) {
  5855. var elm, doc, docElm;
  5856. var x = 0, y = 0, pos;
  5857. if (!offset) {
  5858. elm = this[0];
  5859. if (elm) {
  5860. doc = elm.ownerDocument;
  5861. docElm = doc.documentElement;
  5862. if (elm.getBoundingClientRect) {
  5863. pos = elm.getBoundingClientRect();
  5864. x = pos.left + (docElm.scrollLeft || doc.body.scrollLeft) - docElm.clientLeft;
  5865. y = pos.top + (docElm.scrollTop || doc.body.scrollTop) - docElm.clientTop;
  5866. }
  5867. }
  5868. return {
  5869. left: x,
  5870. top: y
  5871. };
  5872. }
  5873. return this.css(offset);
  5874. },
  5875. push: push$1,
  5876. sort: Array.prototype.sort,
  5877. splice: Array.prototype.splice
  5878. };
  5879. Tools.extend(DomQueryConstructor, {
  5880. extend: Tools.extend,
  5881. makeArray: function (object) {
  5882. if (isWindow(object) || object.nodeType) {
  5883. return [object];
  5884. }
  5885. return Tools.toArray(object);
  5886. },
  5887. inArray: inArray$1,
  5888. isArray: Tools.isArray,
  5889. each: each$4,
  5890. trim: trim$2,
  5891. grep: grep,
  5892. find: Sizzle,
  5893. expr: Sizzle.selectors,
  5894. unique: Sizzle.uniqueSort,
  5895. text: Sizzle.getText,
  5896. contains: Sizzle.contains,
  5897. filter: function (expr, elems, not) {
  5898. var i = elems.length;
  5899. if (not) {
  5900. expr = ':not(' + expr + ')';
  5901. }
  5902. while (i--) {
  5903. if (elems[i].nodeType !== 1) {
  5904. elems.splice(i, 1);
  5905. }
  5906. }
  5907. if (elems.length === 1) {
  5908. elems = DomQuery.find.matchesSelector(elems[0], expr) ? [elems[0]] : [];
  5909. } else {
  5910. elems = DomQuery.find.matches(expr, elems);
  5911. }
  5912. return elems;
  5913. }
  5914. });
  5915. var dir = function (el, prop, until) {
  5916. var matched = [];
  5917. var cur = el[prop];
  5918. if (typeof until !== 'string' && until instanceof DomQuery) {
  5919. until = until[0];
  5920. }
  5921. while (cur && cur.nodeType !== 9) {
  5922. if (until !== undefined) {
  5923. if (cur === until) {
  5924. break;
  5925. }
  5926. if (typeof until === 'string' && DomQuery(cur).is(until)) {
  5927. break;
  5928. }
  5929. }
  5930. if (cur.nodeType === 1) {
  5931. matched.push(cur);
  5932. }
  5933. cur = cur[prop];
  5934. }
  5935. return matched;
  5936. };
  5937. var sibling = function (node, siblingName, nodeType, until) {
  5938. var result = [];
  5939. if (until instanceof DomQuery) {
  5940. until = until[0];
  5941. }
  5942. for (; node; node = node[siblingName]) {
  5943. if (nodeType && node.nodeType !== nodeType) {
  5944. continue;
  5945. }
  5946. if (until !== undefined) {
  5947. if (node === until) {
  5948. break;
  5949. }
  5950. if (typeof until === 'string' && DomQuery(node).is(until)) {
  5951. break;
  5952. }
  5953. }
  5954. result.push(node);
  5955. }
  5956. return result;
  5957. };
  5958. var firstSibling = function (node, siblingName, nodeType) {
  5959. for (node = node[siblingName]; node; node = node[siblingName]) {
  5960. if (node.nodeType === nodeType) {
  5961. return node;
  5962. }
  5963. }
  5964. return null;
  5965. };
  5966. each$4({
  5967. parent: function (node) {
  5968. var parent = node.parentNode;
  5969. return parent && parent.nodeType !== 11 ? parent : null;
  5970. },
  5971. parents: function (node) {
  5972. return dir(node, 'parentNode');
  5973. },
  5974. next: function (node) {
  5975. return firstSibling(node, 'nextSibling', 1);
  5976. },
  5977. prev: function (node) {
  5978. return firstSibling(node, 'previousSibling', 1);
  5979. },
  5980. children: function (node) {
  5981. return sibling(node.firstChild, 'nextSibling', 1);
  5982. },
  5983. contents: function (node) {
  5984. return Tools.toArray((node.nodeName === 'iframe' ? node.contentDocument || node.contentWindow.document : node).childNodes);
  5985. }
  5986. }, function (name, fn) {
  5987. DomQueryConstructor.fn[name] = function (selector) {
  5988. var self = this;
  5989. var result = [];
  5990. self.each(function () {
  5991. var nodes = fn.call(result, this, selector, result);
  5992. if (nodes) {
  5993. if (DomQuery.isArray(nodes)) {
  5994. result.push.apply(result, nodes);
  5995. } else {
  5996. result.push(nodes);
  5997. }
  5998. }
  5999. });
  6000. if (this.length > 1) {
  6001. if (!skipUniques[name]) {
  6002. result = DomQuery.unique(result);
  6003. }
  6004. if (name.indexOf('parents') === 0) {
  6005. result = result.reverse();
  6006. }
  6007. }
  6008. var wrappedResult = DomQuery(result);
  6009. if (selector) {
  6010. return wrappedResult.filter(selector);
  6011. }
  6012. return wrappedResult;
  6013. };
  6014. });
  6015. each$4({
  6016. parentsUntil: function (node, until) {
  6017. return dir(node, 'parentNode', until);
  6018. },
  6019. nextUntil: function (node, until) {
  6020. return sibling(node, 'nextSibling', 1, until).slice(1);
  6021. },
  6022. prevUntil: function (node, until) {
  6023. return sibling(node, 'previousSibling', 1, until).slice(1);
  6024. }
  6025. }, function (name, fn) {
  6026. DomQueryConstructor.fn[name] = function (selector, filter) {
  6027. var self = this;
  6028. var result = [];
  6029. self.each(function () {
  6030. var nodes = fn.call(result, this, selector, result);
  6031. if (nodes) {
  6032. if (DomQuery.isArray(nodes)) {
  6033. result.push.apply(result, nodes);
  6034. } else {
  6035. result.push(nodes);
  6036. }
  6037. }
  6038. });
  6039. if (this.length > 1) {
  6040. result = DomQuery.unique(result);
  6041. if (name.indexOf('parents') === 0 || name === 'prevUntil') {
  6042. result = result.reverse();
  6043. }
  6044. }
  6045. var wrappedResult = DomQuery(result);
  6046. if (filter) {
  6047. return wrappedResult.filter(filter);
  6048. }
  6049. return wrappedResult;
  6050. };
  6051. });
  6052. DomQueryConstructor.fn.is = function (selector) {
  6053. return !!selector && this.filter(selector).length > 0;
  6054. };
  6055. DomQueryConstructor.fn.init.prototype = DomQueryConstructor.fn;
  6056. DomQueryConstructor.overrideDefaults = function (callback) {
  6057. var defaults;
  6058. var sub = function (selector, context) {
  6059. defaults = defaults || callback();
  6060. if (arguments.length === 0) {
  6061. selector = defaults.element;
  6062. }
  6063. if (!context) {
  6064. context = defaults.context;
  6065. }
  6066. return new sub.fn.init(selector, context);
  6067. };
  6068. DomQuery.extend(sub, this);
  6069. return sub;
  6070. };
  6071. DomQueryConstructor.attrHooks = attrHooks;
  6072. DomQueryConstructor.cssHooks = cssHooks;
  6073. var DomQuery = DomQueryConstructor;
  6074. var TreeWalker = function () {
  6075. function TreeWalker(startNode, rootNode) {
  6076. this.node = startNode;
  6077. this.rootNode = rootNode;
  6078. this.current = this.current.bind(this);
  6079. this.next = this.next.bind(this);
  6080. this.prev = this.prev.bind(this);
  6081. this.prev2 = this.prev2.bind(this);
  6082. }
  6083. TreeWalker.prototype.current = function () {
  6084. return this.node;
  6085. };
  6086. TreeWalker.prototype.next = function (shallow) {
  6087. this.node = this.findSibling(this.node, 'firstChild', 'nextSibling', shallow);
  6088. return this.node;
  6089. };
  6090. TreeWalker.prototype.prev = function (shallow) {
  6091. this.node = this.findSibling(this.node, 'lastChild', 'previousSibling', shallow);
  6092. return this.node;
  6093. };
  6094. TreeWalker.prototype.prev2 = function (shallow) {
  6095. this.node = this.findPreviousNode(this.node, 'lastChild', 'previousSibling', shallow);
  6096. return this.node;
  6097. };
  6098. TreeWalker.prototype.findSibling = function (node, startName, siblingName, shallow) {
  6099. var sibling, parent;
  6100. if (node) {
  6101. if (!shallow && node[startName]) {
  6102. return node[startName];
  6103. }
  6104. if (node !== this.rootNode) {
  6105. sibling = node[siblingName];
  6106. if (sibling) {
  6107. return sibling;
  6108. }
  6109. for (parent = node.parentNode; parent && parent !== this.rootNode; parent = parent.parentNode) {
  6110. sibling = parent[siblingName];
  6111. if (sibling) {
  6112. return sibling;
  6113. }
  6114. }
  6115. }
  6116. }
  6117. };
  6118. TreeWalker.prototype.findPreviousNode = function (node, startName, siblingName, shallow) {
  6119. var sibling, parent, child;
  6120. if (node) {
  6121. sibling = node[siblingName];
  6122. if (this.rootNode && sibling === this.rootNode) {
  6123. return;
  6124. }
  6125. if (sibling) {
  6126. if (!shallow) {
  6127. for (child = sibling[startName]; child; child = child[startName]) {
  6128. if (!child[startName]) {
  6129. return child;
  6130. }
  6131. }
  6132. }
  6133. return sibling;
  6134. }
  6135. parent = node.parentNode;
  6136. if (parent && parent !== this.rootNode) {
  6137. return parent;
  6138. }
  6139. }
  6140. };
  6141. return TreeWalker;
  6142. }();
  6143. var before = function (marker, element) {
  6144. var parent$1 = parent(marker);
  6145. parent$1.each(function (v) {
  6146. v.dom().insertBefore(element.dom(), marker.dom());
  6147. });
  6148. };
  6149. var after = function (marker, element) {
  6150. var sibling = nextSibling(marker);
  6151. sibling.fold(function () {
  6152. var parent$1 = parent(marker);
  6153. parent$1.each(function (v) {
  6154. append(v, element);
  6155. });
  6156. }, function (v) {
  6157. before(v, element);
  6158. });
  6159. };
  6160. var prepend = function (parent, element) {
  6161. var firstChild$1 = firstChild(parent);
  6162. firstChild$1.fold(function () {
  6163. append(parent, element);
  6164. }, function (v) {
  6165. parent.dom().insertBefore(element.dom(), v.dom());
  6166. });
  6167. };
  6168. var append = function (parent, element) {
  6169. parent.dom().appendChild(element.dom());
  6170. };
  6171. var wrap$1 = function (element, wrapper) {
  6172. before(element, wrapper);
  6173. append(wrapper, element);
  6174. };
  6175. var before$1 = function (marker, elements) {
  6176. each(elements, function (x) {
  6177. before(marker, x);
  6178. });
  6179. };
  6180. var append$1 = function (parent, elements) {
  6181. each(elements, function (x) {
  6182. append(parent, x);
  6183. });
  6184. };
  6185. var empty = function (element) {
  6186. element.dom().textContent = '';
  6187. each(children(element), function (rogue) {
  6188. remove$1(rogue);
  6189. });
  6190. };
  6191. var remove$1 = function (element) {
  6192. var dom = element.dom();
  6193. if (dom.parentNode !== null) {
  6194. dom.parentNode.removeChild(dom);
  6195. }
  6196. };
  6197. var unwrap = function (wrapper) {
  6198. var children$1 = children(wrapper);
  6199. if (children$1.length > 0) {
  6200. before$1(wrapper, children$1);
  6201. }
  6202. remove$1(wrapper);
  6203. };
  6204. var r = function (left, top) {
  6205. var translate = function (x, y) {
  6206. return r(left + x, top + y);
  6207. };
  6208. return {
  6209. left: constant(left),
  6210. top: constant(top),
  6211. translate: translate
  6212. };
  6213. };
  6214. var Position$1 = r;
  6215. var boxPosition = function (dom) {
  6216. var box = dom.getBoundingClientRect();
  6217. return Position$1(box.left, box.top);
  6218. };
  6219. var firstDefinedOrZero = function (a, b) {
  6220. return a !== undefined ? a : b !== undefined ? b : 0;
  6221. };
  6222. var absolute = function (element) {
  6223. var doc = element.dom().ownerDocument;
  6224. var body = doc.body;
  6225. var win = doc.defaultView;
  6226. var html = doc.documentElement;
  6227. if (body === element.dom()) {
  6228. return Position$1(body.offsetLeft, body.offsetTop);
  6229. }
  6230. var scrollTop = firstDefinedOrZero(win.pageYOffset, html.scrollTop);
  6231. var scrollLeft = firstDefinedOrZero(win.pageXOffset, html.scrollLeft);
  6232. var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
  6233. var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
  6234. return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  6235. };
  6236. var viewport = function (element) {
  6237. var dom = element.dom();
  6238. var doc = dom.ownerDocument;
  6239. var body = doc.body;
  6240. if (body === dom) {
  6241. return Position$1(body.offsetLeft, body.offsetTop);
  6242. }
  6243. if (!inBody(element)) {
  6244. return Position$1(0, 0);
  6245. }
  6246. return boxPosition(dom);
  6247. };
  6248. var isSafari = detect$3().browser.isSafari();
  6249. var get$3 = function (_DOC) {
  6250. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  6251. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  6252. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  6253. return Position$1(x, y);
  6254. };
  6255. var to = function (x, y, _DOC) {
  6256. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  6257. var win = doc.defaultView;
  6258. win.scrollTo(x, y);
  6259. };
  6260. var intoView = function (element, alignToTop) {
  6261. if (isSafari && isFunction(element.dom().scrollIntoViewIfNeeded)) {
  6262. element.dom().scrollIntoViewIfNeeded(false);
  6263. } else {
  6264. element.dom().scrollIntoView(alignToTop);
  6265. }
  6266. };
  6267. var bounds = function (x, y, width, height) {
  6268. return {
  6269. x: constant(x),
  6270. y: constant(y),
  6271. width: constant(width),
  6272. height: constant(height),
  6273. right: constant(x + width),
  6274. bottom: constant(y + height)
  6275. };
  6276. };
  6277. var getBounds = function (_win) {
  6278. var win = _win === undefined ? domGlobals.window : _win;
  6279. var visualViewport = win['visualViewport'];
  6280. if (visualViewport !== undefined) {
  6281. return bounds(visualViewport.pageLeft, visualViewport.pageTop, visualViewport.width, visualViewport.height);
  6282. } else {
  6283. var doc = Element.fromDom(win.document);
  6284. var html = win.document.documentElement;
  6285. var scroll = get$3(doc);
  6286. var width = html.clientWidth;
  6287. var height = html.clientHeight;
  6288. return bounds(scroll.left(), scroll.top(), width, height);
  6289. }
  6290. };
  6291. var each$5 = Tools.each;
  6292. var grep$1 = Tools.grep;
  6293. var isIE = Env.ie;
  6294. var simpleSelectorRe = /^([a-z0-9],?)+$/i;
  6295. var whiteSpaceRegExp$2 = /^[ \t\r\n]*$/;
  6296. var setupAttrHooks = function (styles, settings, getContext) {
  6297. var keepValues = settings.keep_values;
  6298. var keepUrlHook = {
  6299. set: function ($elm, value, name) {
  6300. if (settings.url_converter) {
  6301. value = settings.url_converter.call(settings.url_converter_scope || getContext(), value, name, $elm[0]);
  6302. }
  6303. $elm.attr('data-mce-' + name, value).attr(name, value);
  6304. },
  6305. get: function ($elm, name) {
  6306. return $elm.attr('data-mce-' + name) || $elm.attr(name);
  6307. }
  6308. };
  6309. var attrHooks = {
  6310. style: {
  6311. set: function ($elm, value) {
  6312. if (value !== null && typeof value === 'object') {
  6313. $elm.css(value);
  6314. return;
  6315. }
  6316. if (keepValues) {
  6317. $elm.attr('data-mce-style', value);
  6318. }
  6319. $elm.attr('style', value);
  6320. },
  6321. get: function ($elm) {
  6322. var value = $elm.attr('data-mce-style') || $elm.attr('style');
  6323. value = styles.serialize(styles.parse(value), $elm[0].nodeName);
  6324. return value;
  6325. }
  6326. }
  6327. };
  6328. if (keepValues) {
  6329. attrHooks.href = attrHooks.src = keepUrlHook;
  6330. }
  6331. return attrHooks;
  6332. };
  6333. var updateInternalStyleAttr = function (styles, $elm) {
  6334. var rawValue = $elm.attr('style');
  6335. var value = styles.serialize(styles.parse(rawValue), $elm[0].nodeName);
  6336. if (!value) {
  6337. value = null;
  6338. }
  6339. $elm.attr('data-mce-style', value);
  6340. };
  6341. var findNodeIndex = function (node, normalized) {
  6342. var idx = 0, lastNodeType, nodeType;
  6343. if (node) {
  6344. for (lastNodeType = node.nodeType, node = node.previousSibling; node; node = node.previousSibling) {
  6345. nodeType = node.nodeType;
  6346. if (normalized && nodeType === 3) {
  6347. if (nodeType === lastNodeType || !node.nodeValue.length) {
  6348. continue;
  6349. }
  6350. }
  6351. idx++;
  6352. lastNodeType = nodeType;
  6353. }
  6354. }
  6355. return idx;
  6356. };
  6357. function DOMUtils(doc, settings) {
  6358. var _this = this;
  6359. if (settings === void 0) {
  6360. settings = {};
  6361. }
  6362. var attrHooks;
  6363. var addedStyles = {};
  6364. var win = domGlobals.window;
  6365. var files = {};
  6366. var counter = 0;
  6367. var stdMode = true;
  6368. var boxModel = true;
  6369. var styleSheetLoader = StyleSheetLoader(doc, {
  6370. contentCssCors: settings.contentCssCors,
  6371. referrerPolicy: settings.referrerPolicy
  6372. });
  6373. var boundEvents = [];
  6374. var schema = settings.schema ? settings.schema : Schema({});
  6375. var styles = Styles({
  6376. url_converter: settings.url_converter,
  6377. url_converter_scope: settings.url_converter_scope
  6378. }, settings.schema);
  6379. var events = settings.ownEvents ? new EventUtils() : EventUtils.Event;
  6380. var blockElementsMap = schema.getBlockElements();
  6381. var $ = DomQuery.overrideDefaults(function () {
  6382. return {
  6383. context: doc,
  6384. element: self.getRoot()
  6385. };
  6386. });
  6387. var isBlock = function (node) {
  6388. if (typeof node === 'string') {
  6389. return !!blockElementsMap[node];
  6390. } else if (node) {
  6391. var type = node.nodeType;
  6392. if (type) {
  6393. return !!(type === 1 && blockElementsMap[node.nodeName]);
  6394. }
  6395. }
  6396. return false;
  6397. };
  6398. var get = function (elm) {
  6399. if (elm && doc && typeof elm === 'string') {
  6400. var node = doc.getElementById(elm);
  6401. if (node && node.id !== elm) {
  6402. return doc.getElementsByName(elm)[1];
  6403. } else {
  6404. return node;
  6405. }
  6406. }
  6407. return elm;
  6408. };
  6409. var $$ = function (elm) {
  6410. if (typeof elm === 'string') {
  6411. elm = get(elm);
  6412. }
  6413. return $(elm);
  6414. };
  6415. var getAttrib = function (elm, name, defaultVal) {
  6416. var hook, value;
  6417. var $elm = $$(elm);
  6418. if ($elm.length) {
  6419. hook = attrHooks[name];
  6420. if (hook && hook.get) {
  6421. value = hook.get($elm, name);
  6422. } else {
  6423. value = $elm.attr(name);
  6424. }
  6425. }
  6426. if (typeof value === 'undefined') {
  6427. value = defaultVal || '';
  6428. }
  6429. return value;
  6430. };
  6431. var getAttribs = function (elm) {
  6432. var node = get(elm);
  6433. if (!node) {
  6434. return [];
  6435. }
  6436. return node.attributes;
  6437. };
  6438. var setAttrib = function (elm, name, value) {
  6439. var originalValue, hook;
  6440. if (value === '') {
  6441. value = null;
  6442. }
  6443. var $elm = $$(elm);
  6444. originalValue = $elm.attr(name);
  6445. if (!$elm.length) {
  6446. return;
  6447. }
  6448. hook = attrHooks[name];
  6449. if (hook && hook.set) {
  6450. hook.set($elm, value, name);
  6451. } else {
  6452. $elm.attr(name, value);
  6453. }
  6454. if (originalValue !== value && settings.onSetAttrib) {
  6455. settings.onSetAttrib({
  6456. attrElm: $elm,
  6457. attrName: name,
  6458. attrValue: value
  6459. });
  6460. }
  6461. };
  6462. var clone = function (node, deep) {
  6463. if (!isIE || node.nodeType !== 1 || deep) {
  6464. return node.cloneNode(deep);
  6465. }
  6466. if (!deep) {
  6467. var clone_1 = doc.createElement(node.nodeName);
  6468. each$5(getAttribs(node), function (attr) {
  6469. setAttrib(clone_1, attr.nodeName, getAttrib(node, attr.nodeName));
  6470. });
  6471. return clone_1;
  6472. }
  6473. return null;
  6474. };
  6475. var getRoot = function () {
  6476. return settings.root_element || doc.body;
  6477. };
  6478. var getViewPort = function (argWin) {
  6479. var vp = getBounds(argWin);
  6480. return {
  6481. x: vp.x(),
  6482. y: vp.y(),
  6483. w: vp.width(),
  6484. h: vp.height()
  6485. };
  6486. };
  6487. var getPos = function (elm, rootElm) {
  6488. return Position.getPos(doc.body, get(elm), rootElm);
  6489. };
  6490. var setStyle = function (elm, name, value) {
  6491. var $elm = isString(name) ? $$(elm).css(name, value) : $$(elm).css(name);
  6492. if (settings.update_styles) {
  6493. updateInternalStyleAttr(styles, $elm);
  6494. }
  6495. };
  6496. var setStyles = function (elm, stylesArg) {
  6497. var $elm = $$(elm).css(stylesArg);
  6498. if (settings.update_styles) {
  6499. updateInternalStyleAttr(styles, $elm);
  6500. }
  6501. };
  6502. var getStyle = function (elm, name, computed) {
  6503. var $elm = $$(elm);
  6504. if (computed) {
  6505. return $elm.css(name);
  6506. }
  6507. name = name.replace(/-(\D)/g, function (a, b) {
  6508. return b.toUpperCase();
  6509. });
  6510. if (name === 'float') {
  6511. name = Env.browser.isIE() ? 'styleFloat' : 'cssFloat';
  6512. }
  6513. return $elm[0] && $elm[0].style ? $elm[0].style[name] : undefined;
  6514. };
  6515. var getSize = function (elm) {
  6516. var w, h;
  6517. elm = get(elm);
  6518. w = getStyle(elm, 'width');
  6519. h = getStyle(elm, 'height');
  6520. if (w.indexOf('px') === -1) {
  6521. w = 0;
  6522. }
  6523. if (h.indexOf('px') === -1) {
  6524. h = 0;
  6525. }
  6526. return {
  6527. w: parseInt(w, 10) || elm.offsetWidth || elm.clientWidth,
  6528. h: parseInt(h, 10) || elm.offsetHeight || elm.clientHeight
  6529. };
  6530. };
  6531. var getRect = function (elm) {
  6532. var pos, size;
  6533. elm = get(elm);
  6534. pos = getPos(elm);
  6535. size = getSize(elm);
  6536. return {
  6537. x: pos.x,
  6538. y: pos.y,
  6539. w: size.w,
  6540. h: size.h
  6541. };
  6542. };
  6543. var is = function (elm, selector) {
  6544. var i;
  6545. if (!elm) {
  6546. return false;
  6547. }
  6548. if (!Array.isArray(elm)) {
  6549. if (selector === '*') {
  6550. return elm.nodeType === 1;
  6551. }
  6552. if (simpleSelectorRe.test(selector)) {
  6553. var selectors = selector.toLowerCase().split(/,/);
  6554. var elmName = elm.nodeName.toLowerCase();
  6555. for (i = selectors.length - 1; i >= 0; i--) {
  6556. if (selectors[i] === elmName) {
  6557. return true;
  6558. }
  6559. }
  6560. return false;
  6561. }
  6562. if (elm.nodeType && elm.nodeType !== 1) {
  6563. return false;
  6564. }
  6565. }
  6566. var elms = !Array.isArray(elm) ? [elm] : elm;
  6567. return Sizzle(selector, elms[0].ownerDocument || elms[0], null, elms).length > 0;
  6568. };
  6569. var getParents = function (elm, selector, root, collect) {
  6570. var result = [];
  6571. var selectorVal;
  6572. var node = get(elm);
  6573. collect = collect === undefined;
  6574. root = root || (getRoot().nodeName !== 'BODY' ? getRoot().parentNode : null);
  6575. if (Tools.is(selector, 'string')) {
  6576. selectorVal = selector;
  6577. if (selector === '*') {
  6578. selector = function (node) {
  6579. return node.nodeType === 1;
  6580. };
  6581. } else {
  6582. selector = function (node) {
  6583. return is(node, selectorVal);
  6584. };
  6585. }
  6586. }
  6587. while (node) {
  6588. if (node === root || !node.nodeType || node.nodeType === 9) {
  6589. break;
  6590. }
  6591. if (!selector || typeof selector === 'function' && selector(node)) {
  6592. if (collect) {
  6593. result.push(node);
  6594. } else {
  6595. return [node];
  6596. }
  6597. }
  6598. node = node.parentNode;
  6599. }
  6600. return collect ? result : null;
  6601. };
  6602. var getParent = function (node, selector, root) {
  6603. var parents = getParents(node, selector, root, false);
  6604. return parents && parents.length > 0 ? parents[0] : null;
  6605. };
  6606. var _findSib = function (node, selector, name) {
  6607. var func = selector;
  6608. if (node) {
  6609. if (typeof selector === 'string') {
  6610. func = function (node) {
  6611. return is(node, selector);
  6612. };
  6613. }
  6614. for (node = node[name]; node; node = node[name]) {
  6615. if (typeof func === 'function' && func(node)) {
  6616. return node;
  6617. }
  6618. }
  6619. }
  6620. return null;
  6621. };
  6622. var getNext = function (node, selector) {
  6623. return _findSib(node, selector, 'nextSibling');
  6624. };
  6625. var getPrev = function (node, selector) {
  6626. return _findSib(node, selector, 'previousSibling');
  6627. };
  6628. var select = function (selector, scope) {
  6629. return Sizzle(selector, get(scope) || settings.root_element || doc, []);
  6630. };
  6631. var run = function (elm, func, scope) {
  6632. var result;
  6633. var node = typeof elm === 'string' ? get(elm) : elm;
  6634. if (!node) {
  6635. return false;
  6636. }
  6637. if (Tools.isArray(node) && (node.length || node.length === 0)) {
  6638. result = [];
  6639. each$5(node, function (elm, i) {
  6640. if (elm) {
  6641. if (typeof elm === 'string') {
  6642. elm = get(elm);
  6643. }
  6644. result.push(func.call(scope, elm, i));
  6645. }
  6646. });
  6647. return result;
  6648. }
  6649. var context = scope ? scope : _this;
  6650. return func.call(context, node);
  6651. };
  6652. var setAttribs = function (elm, attrs) {
  6653. $$(elm).each(function (i, node) {
  6654. each$5(attrs, function (value, name) {
  6655. setAttrib(node, name, value);
  6656. });
  6657. });
  6658. };
  6659. var setHTML = function (elm, html) {
  6660. var $elm = $$(elm);
  6661. if (isIE) {
  6662. $elm.each(function (i, target) {
  6663. if (target.canHaveHTML === false) {
  6664. return;
  6665. }
  6666. while (target.firstChild) {
  6667. target.removeChild(target.firstChild);
  6668. }
  6669. try {
  6670. target.innerHTML = '<br>' + html;
  6671. target.removeChild(target.firstChild);
  6672. } catch (ex) {
  6673. DomQuery('<div></div>').html('<br>' + html).contents().slice(1).appendTo(target);
  6674. }
  6675. return html;
  6676. });
  6677. } else {
  6678. $elm.html(html);
  6679. }
  6680. };
  6681. var add = function (parentElm, name, attrs, html, create) {
  6682. return run(parentElm, function (parentElm) {
  6683. var newElm = typeof name === 'string' ? doc.createElement(name) : name;
  6684. setAttribs(newElm, attrs);
  6685. if (html) {
  6686. if (typeof html !== 'string' && html.nodeType) {
  6687. newElm.appendChild(html);
  6688. } else if (typeof html === 'string') {
  6689. setHTML(newElm, html);
  6690. }
  6691. }
  6692. return !create ? parentElm.appendChild(newElm) : newElm;
  6693. });
  6694. };
  6695. var create = function (name, attrs, html) {
  6696. return add(doc.createElement(name), name, attrs, html, true);
  6697. };
  6698. var decode = Entities.decode;
  6699. var encode = Entities.encodeAllRaw;
  6700. var createHTML = function (name, attrs, html) {
  6701. var outHtml = '', key;
  6702. outHtml += '<' + name;
  6703. for (key in attrs) {
  6704. if (attrs.hasOwnProperty(key) && attrs[key] !== null && typeof attrs[key] !== 'undefined') {
  6705. outHtml += ' ' + key + '="' + encode(attrs[key]) + '"';
  6706. }
  6707. }
  6708. if (typeof html !== 'undefined') {
  6709. return outHtml + '>' + html + '</' + name + '>';
  6710. }
  6711. return outHtml + ' />';
  6712. };
  6713. var createFragment = function (html) {
  6714. var node;
  6715. var container = doc.createElement('div');
  6716. var frag = doc.createDocumentFragment();
  6717. if (html) {
  6718. container.innerHTML = html;
  6719. }
  6720. while (node = container.firstChild) {
  6721. frag.appendChild(node);
  6722. }
  6723. return frag;
  6724. };
  6725. var remove = function (node, keepChildren) {
  6726. var $node = $$(node);
  6727. if (keepChildren) {
  6728. $node.each(function () {
  6729. var child;
  6730. while (child = this.firstChild) {
  6731. if (child.nodeType === 3 && child.data.length === 0) {
  6732. this.removeChild(child);
  6733. } else {
  6734. this.parentNode.insertBefore(child, this);
  6735. }
  6736. }
  6737. }).remove();
  6738. } else {
  6739. $node.remove();
  6740. }
  6741. return $node.length > 1 ? $node.toArray() : $node[0];
  6742. };
  6743. var removeAllAttribs = function (e) {
  6744. return run(e, function (e) {
  6745. var i;
  6746. var attrs = e.attributes;
  6747. for (i = attrs.length - 1; i >= 0; i--) {
  6748. e.removeAttributeNode(attrs.item(i));
  6749. }
  6750. });
  6751. };
  6752. var parseStyle = function (cssText) {
  6753. return styles.parse(cssText);
  6754. };
  6755. var serializeStyle = function (stylesArg, name) {
  6756. return styles.serialize(stylesArg, name);
  6757. };
  6758. var addStyle = function (cssText) {
  6759. var head, styleElm;
  6760. if (self !== DOMUtils.DOM && doc === domGlobals.document) {
  6761. if (addedStyles[cssText]) {
  6762. return;
  6763. }
  6764. addedStyles[cssText] = true;
  6765. }
  6766. styleElm = doc.getElementById('mceDefaultStyles');
  6767. if (!styleElm) {
  6768. styleElm = doc.createElement('style');
  6769. styleElm.id = 'mceDefaultStyles';
  6770. styleElm.type = 'text/css';
  6771. head = doc.getElementsByTagName('head')[0];
  6772. if (head.firstChild) {
  6773. head.insertBefore(styleElm, head.firstChild);
  6774. } else {
  6775. head.appendChild(styleElm);
  6776. }
  6777. }
  6778. if (styleElm.styleSheet) {
  6779. styleElm.styleSheet.cssText += cssText;
  6780. } else {
  6781. styleElm.appendChild(doc.createTextNode(cssText));
  6782. }
  6783. };
  6784. var loadCSS = function (url) {
  6785. var head;
  6786. if (self !== DOMUtils.DOM && doc === domGlobals.document) {
  6787. DOMUtils.DOM.loadCSS(url);
  6788. return;
  6789. }
  6790. if (!url) {
  6791. url = '';
  6792. }
  6793. head = doc.getElementsByTagName('head')[0];
  6794. each$5(url.split(','), function (url) {
  6795. var link;
  6796. url = Tools._addCacheSuffix(url);
  6797. if (files[url]) {
  6798. return;
  6799. }
  6800. files[url] = true;
  6801. link = create('link', __assign(__assign({
  6802. rel: 'stylesheet',
  6803. type: 'text/css',
  6804. href: url
  6805. }, settings.contentCssCors ? { crossOrigin: 'anonymous' } : {}), settings.referrerPolicy ? { referrerPolicy: settings.referrerPolicy } : {}));
  6806. head.appendChild(link);
  6807. });
  6808. };
  6809. var toggleClass = function (elm, cls, state) {
  6810. $$(elm).toggleClass(cls, state).each(function () {
  6811. if (this.className === '') {
  6812. DomQuery(this).attr('class', null);
  6813. }
  6814. });
  6815. };
  6816. var addClass = function (elm, cls) {
  6817. $$(elm).addClass(cls);
  6818. };
  6819. var removeClass = function (elm, cls) {
  6820. toggleClass(elm, cls, false);
  6821. };
  6822. var hasClass = function (elm, cls) {
  6823. return $$(elm).hasClass(cls);
  6824. };
  6825. var show = function (elm) {
  6826. $$(elm).show();
  6827. };
  6828. var hide = function (elm) {
  6829. $$(elm).hide();
  6830. };
  6831. var isHidden = function (elm) {
  6832. return $$(elm).css('display') === 'none';
  6833. };
  6834. var uniqueId = function (prefix) {
  6835. return (!prefix ? 'mce_' : prefix) + counter++;
  6836. };
  6837. var getOuterHTML = function (elm) {
  6838. var node = typeof elm === 'string' ? get(elm) : elm;
  6839. return NodeType.isElement(node) ? node.outerHTML : DomQuery('<div></div>').append(DomQuery(node).clone()).html();
  6840. };
  6841. var setOuterHTML = function (elm, html) {
  6842. $$(elm).each(function () {
  6843. try {
  6844. if ('outerHTML' in this) {
  6845. this.outerHTML = html;
  6846. return;
  6847. }
  6848. } catch (ex) {
  6849. }
  6850. remove(DomQuery(this).html(html), true);
  6851. });
  6852. };
  6853. var insertAfter = function (node, reference) {
  6854. var referenceNode = get(reference);
  6855. return run(node, function (node) {
  6856. var parent, nextSibling;
  6857. parent = referenceNode.parentNode;
  6858. nextSibling = referenceNode.nextSibling;
  6859. if (nextSibling) {
  6860. parent.insertBefore(node, nextSibling);
  6861. } else {
  6862. parent.appendChild(node);
  6863. }
  6864. return node;
  6865. });
  6866. };
  6867. var replace = function (newElm, oldElm, keepChildren) {
  6868. return run(oldElm, function (oldElm) {
  6869. if (Tools.is(oldElm, 'array')) {
  6870. newElm = newElm.cloneNode(true);
  6871. }
  6872. if (keepChildren) {
  6873. each$5(grep$1(oldElm.childNodes), function (node) {
  6874. newElm.appendChild(node);
  6875. });
  6876. }
  6877. return oldElm.parentNode.replaceChild(newElm, oldElm);
  6878. });
  6879. };
  6880. var rename = function (elm, name) {
  6881. var newElm;
  6882. if (elm.nodeName !== name.toUpperCase()) {
  6883. newElm = create(name);
  6884. each$5(getAttribs(elm), function (attrNode) {
  6885. setAttrib(newElm, attrNode.nodeName, getAttrib(elm, attrNode.nodeName));
  6886. });
  6887. replace(newElm, elm, true);
  6888. }
  6889. return newElm || elm;
  6890. };
  6891. var findCommonAncestor = function (a, b) {
  6892. var ps = a, pe;
  6893. while (ps) {
  6894. pe = b;
  6895. while (pe && ps !== pe) {
  6896. pe = pe.parentNode;
  6897. }
  6898. if (ps === pe) {
  6899. break;
  6900. }
  6901. ps = ps.parentNode;
  6902. }
  6903. if (!ps && a.ownerDocument) {
  6904. return a.ownerDocument.documentElement;
  6905. }
  6906. return ps;
  6907. };
  6908. var toHex = function (rgbVal) {
  6909. return styles.toHex(Tools.trim(rgbVal));
  6910. };
  6911. var isEmpty = function (node, elements) {
  6912. var i, attributes, type, name, brCount = 0;
  6913. node = node.firstChild;
  6914. if (node) {
  6915. var walker = new TreeWalker(node, node.parentNode);
  6916. var whitespace = schema ? schema.getWhiteSpaceElements() : {};
  6917. elements = elements || (schema ? schema.getNonEmptyElements() : null);
  6918. do {
  6919. type = node.nodeType;
  6920. if (NodeType.isElement(node)) {
  6921. var bogusVal = node.getAttribute('data-mce-bogus');
  6922. if (bogusVal) {
  6923. node = walker.next(bogusVal === 'all');
  6924. continue;
  6925. }
  6926. name = node.nodeName.toLowerCase();
  6927. if (elements && elements[name]) {
  6928. if (name === 'br') {
  6929. brCount++;
  6930. node = walker.next();
  6931. continue;
  6932. }
  6933. return false;
  6934. }
  6935. attributes = getAttribs(node);
  6936. i = attributes.length;
  6937. while (i--) {
  6938. name = attributes[i].nodeName;
  6939. if (name === 'name' || name === 'data-mce-bookmark') {
  6940. return false;
  6941. }
  6942. }
  6943. }
  6944. if (type === 8) {
  6945. return false;
  6946. }
  6947. if (type === 3 && !whiteSpaceRegExp$2.test(node.nodeValue)) {
  6948. return false;
  6949. }
  6950. if (type === 3 && node.parentNode && whitespace[node.parentNode.nodeName] && whiteSpaceRegExp$2.test(node.nodeValue)) {
  6951. return false;
  6952. }
  6953. node = walker.next();
  6954. } while (node);
  6955. }
  6956. return brCount <= 1;
  6957. };
  6958. var createRng = function () {
  6959. return doc.createRange();
  6960. };
  6961. var split = function (parentElm, splitElm, replacementElm) {
  6962. var r = createRng(), bef, aft, pa;
  6963. if (parentElm && splitElm) {
  6964. r.setStart(parentElm.parentNode, findNodeIndex(parentElm));
  6965. r.setEnd(splitElm.parentNode, findNodeIndex(splitElm));
  6966. bef = r.extractContents();
  6967. r = createRng();
  6968. r.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1);
  6969. r.setEnd(parentElm.parentNode, findNodeIndex(parentElm) + 1);
  6970. aft = r.extractContents();
  6971. pa = parentElm.parentNode;
  6972. pa.insertBefore(TrimNode.trimNode(self, bef), parentElm);
  6973. if (replacementElm) {
  6974. pa.insertBefore(replacementElm, parentElm);
  6975. } else {
  6976. pa.insertBefore(splitElm, parentElm);
  6977. }
  6978. pa.insertBefore(TrimNode.trimNode(self, aft), parentElm);
  6979. remove(parentElm);
  6980. return replacementElm || splitElm;
  6981. }
  6982. };
  6983. var bind = function (target, name, func, scope) {
  6984. if (Tools.isArray(target)) {
  6985. var i = target.length;
  6986. var rv = [];
  6987. while (i--) {
  6988. rv[i] = bind(target[i], name, func, scope);
  6989. }
  6990. return rv;
  6991. }
  6992. if (settings.collect && (target === doc || target === win)) {
  6993. boundEvents.push([
  6994. target,
  6995. name,
  6996. func,
  6997. scope
  6998. ]);
  6999. }
  7000. return events.bind(target, name, func, scope || self);
  7001. };
  7002. var unbind = function (target, name, func) {
  7003. var i;
  7004. if (Tools.isArray(target)) {
  7005. i = target.length;
  7006. var rv = [];
  7007. while (i--) {
  7008. rv[i] = unbind(target[i], name, func);
  7009. }
  7010. return rv;
  7011. }
  7012. if (boundEvents && (target === doc || target === win)) {
  7013. i = boundEvents.length;
  7014. while (i--) {
  7015. var item = boundEvents[i];
  7016. if (target === item[0] && (!name || name === item[1]) && (!func || func === item[2])) {
  7017. events.unbind(item[0], item[1], item[2]);
  7018. }
  7019. }
  7020. }
  7021. return events.unbind(target, name, func);
  7022. };
  7023. var fire = function (target, name, evt) {
  7024. return events.fire(target, name, evt);
  7025. };
  7026. var getContentEditable = function (node) {
  7027. if (node && NodeType.isElement(node)) {
  7028. var contentEditable = node.getAttribute('data-mce-contenteditable');
  7029. if (contentEditable && contentEditable !== 'inherit') {
  7030. return contentEditable;
  7031. }
  7032. return node.contentEditable !== 'inherit' ? node.contentEditable : null;
  7033. } else {
  7034. return null;
  7035. }
  7036. };
  7037. var getContentEditableParent = function (node) {
  7038. var root = getRoot();
  7039. var state = null;
  7040. for (; node && node !== root; node = node.parentNode) {
  7041. state = getContentEditable(node);
  7042. if (state !== null) {
  7043. break;
  7044. }
  7045. }
  7046. return state;
  7047. };
  7048. var destroy = function () {
  7049. if (boundEvents) {
  7050. var i = boundEvents.length;
  7051. while (i--) {
  7052. var item = boundEvents[i];
  7053. events.unbind(item[0], item[1], item[2]);
  7054. }
  7055. }
  7056. if (Sizzle.setDocument) {
  7057. Sizzle.setDocument();
  7058. }
  7059. };
  7060. var isChildOf = function (node, parent) {
  7061. while (node) {
  7062. if (parent === node) {
  7063. return true;
  7064. }
  7065. node = node.parentNode;
  7066. }
  7067. return false;
  7068. };
  7069. var dumpRng = function (r) {
  7070. return 'startContainer: ' + r.startContainer.nodeName + ', startOffset: ' + r.startOffset + ', endContainer: ' + r.endContainer.nodeName + ', endOffset: ' + r.endOffset;
  7071. };
  7072. var self = {
  7073. doc: doc,
  7074. settings: settings,
  7075. win: win,
  7076. files: files,
  7077. stdMode: stdMode,
  7078. boxModel: boxModel,
  7079. styleSheetLoader: styleSheetLoader,
  7080. boundEvents: boundEvents,
  7081. styles: styles,
  7082. schema: schema,
  7083. events: events,
  7084. isBlock: isBlock,
  7085. $: $,
  7086. $$: $$,
  7087. root: null,
  7088. clone: clone,
  7089. getRoot: getRoot,
  7090. getViewPort: getViewPort,
  7091. getRect: getRect,
  7092. getSize: getSize,
  7093. getParent: getParent,
  7094. getParents: getParents,
  7095. get: get,
  7096. getNext: getNext,
  7097. getPrev: getPrev,
  7098. select: select,
  7099. is: is,
  7100. add: add,
  7101. create: create,
  7102. createHTML: createHTML,
  7103. createFragment: createFragment,
  7104. remove: remove,
  7105. setStyle: setStyle,
  7106. getStyle: getStyle,
  7107. setStyles: setStyles,
  7108. removeAllAttribs: removeAllAttribs,
  7109. setAttrib: setAttrib,
  7110. setAttribs: setAttribs,
  7111. getAttrib: getAttrib,
  7112. getPos: getPos,
  7113. parseStyle: parseStyle,
  7114. serializeStyle: serializeStyle,
  7115. addStyle: addStyle,
  7116. loadCSS: loadCSS,
  7117. addClass: addClass,
  7118. removeClass: removeClass,
  7119. hasClass: hasClass,
  7120. toggleClass: toggleClass,
  7121. show: show,
  7122. hide: hide,
  7123. isHidden: isHidden,
  7124. uniqueId: uniqueId,
  7125. setHTML: setHTML,
  7126. getOuterHTML: getOuterHTML,
  7127. setOuterHTML: setOuterHTML,
  7128. decode: decode,
  7129. encode: encode,
  7130. insertAfter: insertAfter,
  7131. replace: replace,
  7132. rename: rename,
  7133. findCommonAncestor: findCommonAncestor,
  7134. toHex: toHex,
  7135. run: run,
  7136. getAttribs: getAttribs,
  7137. isEmpty: isEmpty,
  7138. createRng: createRng,
  7139. nodeIndex: findNodeIndex,
  7140. split: split,
  7141. bind: bind,
  7142. unbind: unbind,
  7143. fire: fire,
  7144. getContentEditable: getContentEditable,
  7145. getContentEditableParent: getContentEditableParent,
  7146. destroy: destroy,
  7147. isChildOf: isChildOf,
  7148. dumpRng: dumpRng
  7149. };
  7150. attrHooks = setupAttrHooks(styles, settings, function () {
  7151. return self;
  7152. });
  7153. return self;
  7154. }
  7155. (function (DOMUtils) {
  7156. DOMUtils.DOM = DOMUtils(domGlobals.document);
  7157. DOMUtils.nodeIndex = findNodeIndex;
  7158. }(DOMUtils || (DOMUtils = {})));
  7159. var DOMUtils$1 = DOMUtils;
  7160. var DOM = DOMUtils$1.DOM;
  7161. var each$6 = Tools.each, grep$2 = Tools.grep;
  7162. var QUEUED = 0;
  7163. var LOADING = 1;
  7164. var LOADED = 2;
  7165. var FAILED = 3;
  7166. var ScriptLoader = function () {
  7167. function ScriptLoader(settings) {
  7168. if (settings === void 0) {
  7169. settings = {};
  7170. }
  7171. this.states = {};
  7172. this.queue = [];
  7173. this.scriptLoadedCallbacks = {};
  7174. this.queueLoadedCallbacks = [];
  7175. this.loading = 0;
  7176. this.settings = settings;
  7177. }
  7178. ScriptLoader.prototype._setReferrerPolicy = function (referrerPolicy) {
  7179. this.settings.referrerPolicy = referrerPolicy;
  7180. };
  7181. ScriptLoader.prototype.loadScript = function (url, success, failure) {
  7182. var dom = DOM;
  7183. var elm, id;
  7184. var done = function () {
  7185. dom.remove(id);
  7186. if (elm) {
  7187. elm.onreadystatechange = elm.onload = elm = null;
  7188. }
  7189. success();
  7190. };
  7191. var error = function () {
  7192. if (isFunction(failure)) {
  7193. failure();
  7194. } else {
  7195. if (typeof domGlobals.console !== 'undefined' && domGlobals.console.log) {
  7196. domGlobals.console.log('Failed to load script: ' + url);
  7197. }
  7198. }
  7199. };
  7200. id = dom.uniqueId();
  7201. elm = domGlobals.document.createElement('script');
  7202. elm.id = id;
  7203. elm.type = 'text/javascript';
  7204. elm.src = Tools._addCacheSuffix(url);
  7205. if (this.settings.referrerPolicy) {
  7206. dom.setAttrib(elm, 'referrerpolicy', this.settings.referrerPolicy);
  7207. }
  7208. elm.onload = done;
  7209. elm.onerror = error;
  7210. (domGlobals.document.getElementsByTagName('head')[0] || domGlobals.document.body).appendChild(elm);
  7211. };
  7212. ScriptLoader.prototype.isDone = function (url) {
  7213. return this.states[url] === LOADED;
  7214. };
  7215. ScriptLoader.prototype.markDone = function (url) {
  7216. this.states[url] = LOADED;
  7217. };
  7218. ScriptLoader.prototype.add = function (url, success, scope, failure) {
  7219. var state = this.states[url];
  7220. if (state === undefined) {
  7221. this.queue.push(url);
  7222. this.states[url] = QUEUED;
  7223. }
  7224. if (success) {
  7225. if (!this.scriptLoadedCallbacks[url]) {
  7226. this.scriptLoadedCallbacks[url] = [];
  7227. }
  7228. this.scriptLoadedCallbacks[url].push({
  7229. success: success,
  7230. failure: failure,
  7231. scope: scope || this
  7232. });
  7233. }
  7234. };
  7235. ScriptLoader.prototype.load = function (url, success, scope, failure) {
  7236. return this.add(url, success, scope, failure);
  7237. };
  7238. ScriptLoader.prototype.remove = function (url) {
  7239. delete this.states[url];
  7240. delete this.scriptLoadedCallbacks[url];
  7241. };
  7242. ScriptLoader.prototype.loadQueue = function (success, scope, failure) {
  7243. this.loadScripts(this.queue, success, scope, failure);
  7244. };
  7245. ScriptLoader.prototype.loadScripts = function (scripts, success, scope, failure) {
  7246. var self = this;
  7247. var loadScripts;
  7248. var failures = [];
  7249. var execCallbacks = function (name, url) {
  7250. each$6(self.scriptLoadedCallbacks[url], function (callback) {
  7251. if (isFunction(callback[name])) {
  7252. callback[name].call(callback.scope);
  7253. }
  7254. });
  7255. self.scriptLoadedCallbacks[url] = undefined;
  7256. };
  7257. self.queueLoadedCallbacks.push({
  7258. success: success,
  7259. failure: failure,
  7260. scope: scope || this
  7261. });
  7262. loadScripts = function () {
  7263. var loadingScripts = grep$2(scripts);
  7264. scripts.length = 0;
  7265. each$6(loadingScripts, function (url) {
  7266. if (self.states[url] === LOADED) {
  7267. execCallbacks('success', url);
  7268. return;
  7269. }
  7270. if (self.states[url] === FAILED) {
  7271. execCallbacks('failure', url);
  7272. return;
  7273. }
  7274. if (self.states[url] !== LOADING) {
  7275. self.states[url] = LOADING;
  7276. self.loading++;
  7277. self.loadScript(url, function () {
  7278. self.states[url] = LOADED;
  7279. self.loading--;
  7280. execCallbacks('success', url);
  7281. loadScripts();
  7282. }, function () {
  7283. self.states[url] = FAILED;
  7284. self.loading--;
  7285. failures.push(url);
  7286. execCallbacks('failure', url);
  7287. loadScripts();
  7288. });
  7289. }
  7290. });
  7291. if (!self.loading) {
  7292. var notifyCallbacks = self.queueLoadedCallbacks.slice(0);
  7293. self.queueLoadedCallbacks.length = 0;
  7294. each$6(notifyCallbacks, function (callback) {
  7295. if (failures.length === 0) {
  7296. if (isFunction(callback.success)) {
  7297. callback.success.call(callback.scope);
  7298. }
  7299. } else {
  7300. if (isFunction(callback.failure)) {
  7301. callback.failure.call(callback.scope, failures);
  7302. }
  7303. }
  7304. });
  7305. }
  7306. };
  7307. loadScripts();
  7308. };
  7309. ScriptLoader.ScriptLoader = new ScriptLoader();
  7310. return ScriptLoader;
  7311. }();
  7312. var isRaw = function (str) {
  7313. return isObject(str) && has(str, 'raw');
  7314. };
  7315. var isTokenised = function (str) {
  7316. return isArray(str) && str.length > 1;
  7317. };
  7318. var data = {};
  7319. var currentCode = Cell('en');
  7320. var getData = function () {
  7321. return map$1(data, function (value) {
  7322. return __assign({}, value);
  7323. });
  7324. };
  7325. var setCode = function (newCode) {
  7326. if (newCode) {
  7327. currentCode.set(newCode);
  7328. }
  7329. };
  7330. var getCode = function () {
  7331. return currentCode.get();
  7332. };
  7333. var add = function (code, items) {
  7334. var langData = data[code];
  7335. if (!langData) {
  7336. data[code] = langData = {};
  7337. }
  7338. for (var name in items) {
  7339. langData[name.toLowerCase()] = items[name];
  7340. }
  7341. };
  7342. var translate = function (text) {
  7343. var langData = data[currentCode.get()] || {};
  7344. var toString = function (obj) {
  7345. if (isFunction(obj)) {
  7346. return Object.prototype.toString.call(obj);
  7347. }
  7348. return !isEmpty(obj) ? '' + obj : '';
  7349. };
  7350. var isEmpty = function (text) {
  7351. return text === '' || text === null || text === undefined;
  7352. };
  7353. var getLangData = function (text) {
  7354. var textstr = toString(text);
  7355. var lowercaseTextstr = textstr.toLowerCase();
  7356. return has(langData, lowercaseTextstr) ? toString(langData[lowercaseTextstr]) : textstr;
  7357. };
  7358. var removeContext = function (str) {
  7359. return str.replace(/{context:\w+}$/, '');
  7360. };
  7361. var translated = function (text) {
  7362. return text;
  7363. };
  7364. if (isEmpty(text)) {
  7365. return translated('');
  7366. }
  7367. if (isRaw(text)) {
  7368. return translated(toString(text.raw));
  7369. }
  7370. if (isTokenised(text)) {
  7371. var values_1 = text.slice(1);
  7372. var substitued = getLangData(text[0]).replace(/\{([0-9]+)\}/g, function ($1, $2) {
  7373. return has(values_1, $2) ? toString(values_1[$2]) : $1;
  7374. });
  7375. return translated(removeContext(substitued));
  7376. }
  7377. return translated(removeContext(getLangData(text)));
  7378. };
  7379. var isRtl = function () {
  7380. return get(data, currentCode.get()).bind(function (items) {
  7381. return get(items, '_dir');
  7382. }).exists(function (dir) {
  7383. return dir === 'rtl';
  7384. });
  7385. };
  7386. var hasCode = function (code) {
  7387. return has(data, code);
  7388. };
  7389. var I18n = {
  7390. getData: getData,
  7391. setCode: setCode,
  7392. getCode: getCode,
  7393. add: add,
  7394. translate: translate,
  7395. isRtl: isRtl,
  7396. hasCode: hasCode
  7397. };
  7398. var each$7 = Tools.each;
  7399. function AddOnManager() {
  7400. var _this = this;
  7401. var items = [];
  7402. var urls = {};
  7403. var lookup = {};
  7404. var _listeners = [];
  7405. var get = function (name) {
  7406. if (lookup[name]) {
  7407. return lookup[name].instance;
  7408. }
  7409. return undefined;
  7410. };
  7411. var dependencies = function (name) {
  7412. var result;
  7413. if (lookup[name]) {
  7414. result = lookup[name].dependencies;
  7415. }
  7416. return result || [];
  7417. };
  7418. var requireLangPack = function (name, languages) {
  7419. var language = I18n.getCode();
  7420. if (language && AddOnManager.languageLoad !== false) {
  7421. if (languages) {
  7422. languages = ',' + languages + ',';
  7423. if (languages.indexOf(',' + language.substr(0, 2) + ',') !== -1) {
  7424. language = language.substr(0, 2);
  7425. } else if (languages.indexOf(',' + language + ',') === -1) {
  7426. return;
  7427. }
  7428. }
  7429. ScriptLoader.ScriptLoader.add(urls[name] + '/langs/' + language + '.js');
  7430. }
  7431. };
  7432. var add = function (id, addOn, dependencies) {
  7433. items.push(addOn);
  7434. lookup[id] = {
  7435. instance: addOn,
  7436. dependencies: dependencies
  7437. };
  7438. var result = partition(_listeners, function (listener) {
  7439. return listener.name === id;
  7440. });
  7441. _listeners = result.fail;
  7442. each$7(result.pass, function (listener) {
  7443. listener.callback();
  7444. });
  7445. return addOn;
  7446. };
  7447. var remove = function (name) {
  7448. delete urls[name];
  7449. delete lookup[name];
  7450. };
  7451. var createUrl = function (baseUrl, dep) {
  7452. if (typeof dep === 'object') {
  7453. return dep;
  7454. }
  7455. return typeof baseUrl === 'string' ? {
  7456. prefix: '',
  7457. resource: dep,
  7458. suffix: ''
  7459. } : {
  7460. prefix: baseUrl.prefix,
  7461. resource: dep,
  7462. suffix: baseUrl.suffix
  7463. };
  7464. };
  7465. var addComponents = function (pluginName, scripts) {
  7466. var pluginUrl = _this.urls[pluginName];
  7467. each$7(scripts, function (script) {
  7468. ScriptLoader.ScriptLoader.add(pluginUrl + '/' + script);
  7469. });
  7470. };
  7471. var loadDependencies = function (name, addOnUrl, success, scope) {
  7472. var deps = dependencies(name);
  7473. each$7(deps, function (dep) {
  7474. var newUrl = createUrl(addOnUrl, dep);
  7475. load(newUrl.resource, newUrl, undefined, undefined);
  7476. });
  7477. if (success) {
  7478. if (scope) {
  7479. success.call(scope);
  7480. } else {
  7481. success.call(ScriptLoader);
  7482. }
  7483. }
  7484. };
  7485. var load = function (name, addOnUrl, success, scope, failure) {
  7486. if (urls[name]) {
  7487. return;
  7488. }
  7489. var urlString = typeof addOnUrl === 'string' ? addOnUrl : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix;
  7490. if (urlString.indexOf('/') !== 0 && urlString.indexOf('://') === -1) {
  7491. urlString = AddOnManager.baseURL + '/' + urlString;
  7492. }
  7493. urls[name] = urlString.substring(0, urlString.lastIndexOf('/'));
  7494. if (lookup[name]) {
  7495. loadDependencies(name, addOnUrl, success, scope);
  7496. } else {
  7497. ScriptLoader.ScriptLoader.add(urlString, function () {
  7498. return loadDependencies(name, addOnUrl, success, scope);
  7499. }, scope, failure);
  7500. }
  7501. };
  7502. var waitFor = function (name, callback) {
  7503. if (lookup.hasOwnProperty(name)) {
  7504. callback();
  7505. } else {
  7506. _listeners.push({
  7507. name: name,
  7508. callback: callback
  7509. });
  7510. }
  7511. };
  7512. return {
  7513. items: items,
  7514. urls: urls,
  7515. lookup: lookup,
  7516. _listeners: _listeners,
  7517. get: get,
  7518. dependencies: dependencies,
  7519. requireLangPack: requireLangPack,
  7520. add: add,
  7521. remove: remove,
  7522. createUrl: createUrl,
  7523. addComponents: addComponents,
  7524. load: load,
  7525. waitFor: waitFor
  7526. };
  7527. }
  7528. (function (AddOnManager) {
  7529. AddOnManager.PluginManager = AddOnManager();
  7530. AddOnManager.ThemeManager = AddOnManager();
  7531. }(AddOnManager || (AddOnManager = {})));
  7532. var AddOnManager$1 = AddOnManager;
  7533. var first = function (fn, rate) {
  7534. var timer = null;
  7535. var cancel = function () {
  7536. if (timer !== null) {
  7537. domGlobals.clearTimeout(timer);
  7538. timer = null;
  7539. }
  7540. };
  7541. var throttle = function () {
  7542. var args = [];
  7543. for (var _i = 0; _i < arguments.length; _i++) {
  7544. args[_i] = arguments[_i];
  7545. }
  7546. if (timer === null) {
  7547. timer = domGlobals.setTimeout(function () {
  7548. fn.apply(null, args);
  7549. timer = null;
  7550. }, rate);
  7551. }
  7552. };
  7553. return {
  7554. cancel: cancel,
  7555. throttle: throttle
  7556. };
  7557. };
  7558. var last$2 = function (fn, rate) {
  7559. var timer = null;
  7560. var cancel = function () {
  7561. if (timer !== null) {
  7562. domGlobals.clearTimeout(timer);
  7563. timer = null;
  7564. }
  7565. };
  7566. var throttle = function () {
  7567. var args = [];
  7568. for (var _i = 0; _i < arguments.length; _i++) {
  7569. args[_i] = arguments[_i];
  7570. }
  7571. if (timer !== null) {
  7572. domGlobals.clearTimeout(timer);
  7573. }
  7574. timer = domGlobals.setTimeout(function () {
  7575. fn.apply(null, args);
  7576. timer = null;
  7577. }, rate);
  7578. };
  7579. return {
  7580. cancel: cancel,
  7581. throttle: throttle
  7582. };
  7583. };
  7584. var read = function (element, attr) {
  7585. var value = get$1(element, attr);
  7586. return value === undefined || value === '' ? [] : value.split(' ');
  7587. };
  7588. var add$1 = function (element, attr, id) {
  7589. var old = read(element, attr);
  7590. var nu = old.concat([id]);
  7591. set(element, attr, nu.join(' '));
  7592. return true;
  7593. };
  7594. var remove$2 = function (element, attr, id) {
  7595. var nu = filter(read(element, attr), function (v) {
  7596. return v !== id;
  7597. });
  7598. if (nu.length > 0) {
  7599. set(element, attr, nu.join(' '));
  7600. } else {
  7601. remove(element, attr);
  7602. }
  7603. return false;
  7604. };
  7605. var supports = function (element) {
  7606. return element.dom().classList !== undefined;
  7607. };
  7608. var get$4 = function (element) {
  7609. return read(element, 'class');
  7610. };
  7611. var add$2 = function (element, clazz) {
  7612. return add$1(element, 'class', clazz);
  7613. };
  7614. var remove$3 = function (element, clazz) {
  7615. return remove$2(element, 'class', clazz);
  7616. };
  7617. var add$3 = function (element, clazz) {
  7618. if (supports(element)) {
  7619. element.dom().classList.add(clazz);
  7620. } else {
  7621. add$2(element, clazz);
  7622. }
  7623. };
  7624. var cleanClass = function (element) {
  7625. var classList = supports(element) ? element.dom().classList : get$4(element);
  7626. if (classList.length === 0) {
  7627. remove(element, 'class');
  7628. }
  7629. };
  7630. var remove$4 = function (element, clazz) {
  7631. if (supports(element)) {
  7632. var classList = element.dom().classList;
  7633. classList.remove(clazz);
  7634. } else {
  7635. remove$3(element, clazz);
  7636. }
  7637. cleanClass(element);
  7638. };
  7639. var has$2 = function (element, clazz) {
  7640. return supports(element) && element.dom().classList.contains(clazz);
  7641. };
  7642. var descendants = function (scope, predicate) {
  7643. var result = [];
  7644. each(children(scope), function (x) {
  7645. if (predicate(x)) {
  7646. result = result.concat([x]);
  7647. }
  7648. result = result.concat(descendants(x, predicate));
  7649. });
  7650. return result;
  7651. };
  7652. var descendants$1 = function (scope, selector) {
  7653. return all(selector, scope);
  7654. };
  7655. function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
  7656. return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
  7657. }
  7658. var ancestor = function (scope, predicate, isRoot) {
  7659. var element = scope.dom();
  7660. var stop = isFunction(isRoot) ? isRoot : constant(false);
  7661. while (element.parentNode) {
  7662. element = element.parentNode;
  7663. var el = Element.fromDom(element);
  7664. if (predicate(el)) {
  7665. return Option.some(el);
  7666. } else if (stop(el)) {
  7667. break;
  7668. }
  7669. }
  7670. return Option.none();
  7671. };
  7672. var closest = function (scope, predicate, isRoot) {
  7673. var is = function (s, test) {
  7674. return test(s);
  7675. };
  7676. return ClosestOrAncestor(is, ancestor, scope, predicate, isRoot);
  7677. };
  7678. var ancestor$1 = function (scope, selector, isRoot) {
  7679. return ancestor(scope, function (e) {
  7680. return is(e, selector);
  7681. }, isRoot);
  7682. };
  7683. var descendant = function (scope, selector) {
  7684. return one(selector, scope);
  7685. };
  7686. var closest$1 = function (scope, selector, isRoot) {
  7687. return ClosestOrAncestor(is, ancestor$1, scope, selector, isRoot);
  7688. };
  7689. var annotation = constant('mce-annotation');
  7690. var dataAnnotation = constant('data-mce-annotation');
  7691. var dataAnnotationId = constant('data-mce-annotation-uid');
  7692. var identify = function (editor, annotationName) {
  7693. var rng = editor.selection.getRng();
  7694. var start = Element.fromDom(rng.startContainer);
  7695. var root = Element.fromDom(editor.getBody());
  7696. var selector = annotationName.fold(function () {
  7697. return '.' + annotation();
  7698. }, function (an) {
  7699. return '[' + dataAnnotation() + '="' + an + '"]';
  7700. });
  7701. var newStart = child(start, rng.startOffset).getOr(start);
  7702. var closest = closest$1(newStart, selector, function (n) {
  7703. return eq(n, root);
  7704. });
  7705. var getAttr = function (c, property) {
  7706. if (has$1(c, property)) {
  7707. return Option.some(get$1(c, property));
  7708. } else {
  7709. return Option.none();
  7710. }
  7711. };
  7712. return closest.bind(function (c) {
  7713. return getAttr(c, '' + dataAnnotationId()).bind(function (uid) {
  7714. return getAttr(c, '' + dataAnnotation()).map(function (name) {
  7715. var elements = findMarkers(editor, uid);
  7716. return {
  7717. uid: uid,
  7718. name: name,
  7719. elements: elements
  7720. };
  7721. });
  7722. });
  7723. });
  7724. };
  7725. var isAnnotation = function (elem) {
  7726. return isElement$1(elem) && has$2(elem, annotation());
  7727. };
  7728. var findMarkers = function (editor, uid) {
  7729. var body = Element.fromDom(editor.getBody());
  7730. return descendants$1(body, '[' + dataAnnotationId() + '="' + uid + '"]');
  7731. };
  7732. var findAll = function (editor, name) {
  7733. var body = Element.fromDom(editor.getBody());
  7734. var markers = descendants$1(body, '[' + dataAnnotation() + '="' + name + '"]');
  7735. var directory = {};
  7736. each(markers, function (m) {
  7737. var uid = get$1(m, dataAnnotationId());
  7738. var nodesAlready = directory.hasOwnProperty(uid) ? directory[uid] : [];
  7739. directory[uid] = nodesAlready.concat([m]);
  7740. });
  7741. return directory;
  7742. };
  7743. var setup = function (editor, registry) {
  7744. var changeCallbacks = Cell({});
  7745. var initData = function () {
  7746. return {
  7747. listeners: [],
  7748. previous: Cell(Option.none())
  7749. };
  7750. };
  7751. var withCallbacks = function (name, f) {
  7752. updateCallbacks(name, function (data) {
  7753. f(data);
  7754. return data;
  7755. });
  7756. };
  7757. var updateCallbacks = function (name, f) {
  7758. var callbackMap = changeCallbacks.get();
  7759. var data = callbackMap.hasOwnProperty(name) ? callbackMap[name] : initData();
  7760. var outputData = f(data);
  7761. callbackMap[name] = outputData;
  7762. changeCallbacks.set(callbackMap);
  7763. };
  7764. var fireCallbacks = function (name, uid, elements) {
  7765. withCallbacks(name, function (data) {
  7766. each(data.listeners, function (f) {
  7767. return f(true, name, {
  7768. uid: uid,
  7769. nodes: map(elements, function (elem) {
  7770. return elem.dom();
  7771. })
  7772. });
  7773. });
  7774. });
  7775. };
  7776. var fireNoAnnotation = function (name) {
  7777. withCallbacks(name, function (data) {
  7778. each(data.listeners, function (f) {
  7779. return f(false, name);
  7780. });
  7781. });
  7782. };
  7783. var onNodeChange = last$2(function () {
  7784. var callbackMap = changeCallbacks.get();
  7785. var annotations = sort(keys(callbackMap));
  7786. each(annotations, function (name) {
  7787. updateCallbacks(name, function (data) {
  7788. var prev = data.previous.get();
  7789. identify(editor, Option.some(name)).fold(function () {
  7790. if (prev.isSome()) {
  7791. fireNoAnnotation(name);
  7792. data.previous.set(Option.none());
  7793. }
  7794. }, function (_a) {
  7795. var uid = _a.uid, name = _a.name, elements = _a.elements;
  7796. if (!prev.is(uid)) {
  7797. fireCallbacks(name, uid, elements);
  7798. data.previous.set(Option.some(uid));
  7799. }
  7800. });
  7801. return {
  7802. previous: data.previous,
  7803. listeners: data.listeners
  7804. };
  7805. });
  7806. });
  7807. }, 30);
  7808. editor.on('remove', function () {
  7809. onNodeChange.cancel();
  7810. });
  7811. editor.on('NodeChange', function () {
  7812. onNodeChange.throttle();
  7813. });
  7814. var addListener = function (name, f) {
  7815. updateCallbacks(name, function (data) {
  7816. return {
  7817. previous: data.previous,
  7818. listeners: data.listeners.concat([f])
  7819. };
  7820. });
  7821. };
  7822. return { addListener: addListener };
  7823. };
  7824. var setup$1 = function (editor, registry) {
  7825. var identifyParserNode = function (span) {
  7826. return Option.from(span.attr(dataAnnotation())).bind(registry.lookup);
  7827. };
  7828. editor.on('init', function () {
  7829. editor.serializer.addNodeFilter('span', function (spans) {
  7830. each(spans, function (span) {
  7831. identifyParserNode(span).each(function (settings) {
  7832. if (settings.persistent === false) {
  7833. span.unwrap();
  7834. }
  7835. });
  7836. });
  7837. });
  7838. });
  7839. };
  7840. var create$1 = function () {
  7841. var annotations = {};
  7842. var register = function (name, settings) {
  7843. annotations[name] = {
  7844. name: name,
  7845. settings: settings
  7846. };
  7847. };
  7848. var lookup = function (name) {
  7849. return annotations.hasOwnProperty(name) ? Option.from(annotations[name]).map(function (a) {
  7850. return a.settings;
  7851. }) : Option.none();
  7852. };
  7853. return {
  7854. register: register,
  7855. lookup: lookup
  7856. };
  7857. };
  7858. var unique = 0;
  7859. var generate = function (prefix) {
  7860. var date = new Date();
  7861. var time = date.getTime();
  7862. var random = Math.floor(Math.random() * 1000000000);
  7863. unique++;
  7864. return prefix + '_' + random + unique + String(time);
  7865. };
  7866. var add$4 = function (element, classes) {
  7867. each(classes, function (x) {
  7868. add$3(element, x);
  7869. });
  7870. };
  7871. var clone = function (original, isDeep) {
  7872. return Element.fromDom(original.dom().cloneNode(isDeep));
  7873. };
  7874. var shallow = function (original) {
  7875. return clone(original, false);
  7876. };
  7877. var deep = function (original) {
  7878. return clone(original, true);
  7879. };
  7880. var fromHtml$1 = function (html, scope) {
  7881. var doc = scope || domGlobals.document;
  7882. var div = doc.createElement('div');
  7883. div.innerHTML = html;
  7884. return children(Element.fromDom(div));
  7885. };
  7886. var get$5 = function (element) {
  7887. return element.dom().innerHTML;
  7888. };
  7889. var set$1 = function (element, content) {
  7890. var owner$1 = owner(element);
  7891. var docDom = owner$1.dom();
  7892. var fragment = Element.fromDom(docDom.createDocumentFragment());
  7893. var contentElements = fromHtml$1(content, docDom);
  7894. append$1(fragment, contentElements);
  7895. empty(element);
  7896. append(element, fragment);
  7897. };
  7898. var ZWSP = '\uFEFF';
  7899. var isZwsp = function (chr) {
  7900. return chr === ZWSP;
  7901. };
  7902. var trim$3 = function (text) {
  7903. return text.replace(new RegExp(ZWSP, 'g'), '');
  7904. };
  7905. var Zwsp = {
  7906. isZwsp: isZwsp,
  7907. ZWSP: ZWSP,
  7908. trim: trim$3
  7909. };
  7910. var isElement$2 = NodeType.isElement;
  7911. var isText$2 = NodeType.isText;
  7912. var isCaretContainerBlock = function (node) {
  7913. if (isText$2(node)) {
  7914. node = node.parentNode;
  7915. }
  7916. return isElement$2(node) && node.hasAttribute('data-mce-caret');
  7917. };
  7918. var isCaretContainerInline = function (node) {
  7919. return isText$2(node) && Zwsp.isZwsp(node.data);
  7920. };
  7921. var isCaretContainer = function (node) {
  7922. return isCaretContainerBlock(node) || isCaretContainerInline(node);
  7923. };
  7924. var hasContent = function (node) {
  7925. return node.firstChild !== node.lastChild || !NodeType.isBr(node.firstChild);
  7926. };
  7927. var insertInline = function (node, before) {
  7928. var doc, sibling, textNode, parentNode;
  7929. doc = node.ownerDocument;
  7930. textNode = doc.createTextNode(Zwsp.ZWSP);
  7931. parentNode = node.parentNode;
  7932. if (!before) {
  7933. sibling = node.nextSibling;
  7934. if (isText$2(sibling)) {
  7935. if (isCaretContainer(sibling)) {
  7936. return sibling;
  7937. }
  7938. if (startsWithCaretContainer(sibling)) {
  7939. sibling.splitText(1);
  7940. return sibling;
  7941. }
  7942. }
  7943. if (node.nextSibling) {
  7944. parentNode.insertBefore(textNode, node.nextSibling);
  7945. } else {
  7946. parentNode.appendChild(textNode);
  7947. }
  7948. } else {
  7949. sibling = node.previousSibling;
  7950. if (isText$2(sibling)) {
  7951. if (isCaretContainer(sibling)) {
  7952. return sibling;
  7953. }
  7954. if (endsWithCaretContainer(sibling)) {
  7955. return sibling.splitText(sibling.data.length - 1);
  7956. }
  7957. }
  7958. parentNode.insertBefore(textNode, node);
  7959. }
  7960. return textNode;
  7961. };
  7962. var isBeforeInline = function (pos) {
  7963. var container = pos.container();
  7964. if (!pos || !NodeType.isText(container)) {
  7965. return false;
  7966. }
  7967. return container.data.charAt(pos.offset()) === Zwsp.ZWSP || pos.isAtStart() && isCaretContainerInline(container.previousSibling);
  7968. };
  7969. var isAfterInline = function (pos) {
  7970. var container = pos.container();
  7971. if (!pos || !NodeType.isText(container)) {
  7972. return false;
  7973. }
  7974. return container.data.charAt(pos.offset() - 1) === Zwsp.ZWSP || pos.isAtEnd() && isCaretContainerInline(container.nextSibling);
  7975. };
  7976. var createBogusBr = function () {
  7977. var br = domGlobals.document.createElement('br');
  7978. br.setAttribute('data-mce-bogus', '1');
  7979. return br;
  7980. };
  7981. var insertBlock = function (blockName, node, before) {
  7982. var doc, blockNode, parentNode;
  7983. doc = node.ownerDocument;
  7984. blockNode = doc.createElement(blockName);
  7985. blockNode.setAttribute('data-mce-caret', before ? 'before' : 'after');
  7986. blockNode.setAttribute('data-mce-bogus', 'all');
  7987. blockNode.appendChild(createBogusBr());
  7988. parentNode = node.parentNode;
  7989. if (!before) {
  7990. if (node.nextSibling) {
  7991. parentNode.insertBefore(blockNode, node.nextSibling);
  7992. } else {
  7993. parentNode.appendChild(blockNode);
  7994. }
  7995. } else {
  7996. parentNode.insertBefore(blockNode, node);
  7997. }
  7998. return blockNode;
  7999. };
  8000. var startsWithCaretContainer = function (node) {
  8001. return isText$2(node) && node.data[0] === Zwsp.ZWSP;
  8002. };
  8003. var endsWithCaretContainer = function (node) {
  8004. return isText$2(node) && node.data[node.data.length - 1] === Zwsp.ZWSP;
  8005. };
  8006. var trimBogusBr = function (elm) {
  8007. var brs = elm.getElementsByTagName('br');
  8008. var lastBr = brs[brs.length - 1];
  8009. if (NodeType.isBogus(lastBr)) {
  8010. lastBr.parentNode.removeChild(lastBr);
  8011. }
  8012. };
  8013. var showCaretContainerBlock = function (caretContainer) {
  8014. if (caretContainer && caretContainer.hasAttribute('data-mce-caret')) {
  8015. trimBogusBr(caretContainer);
  8016. caretContainer.removeAttribute('data-mce-caret');
  8017. caretContainer.removeAttribute('data-mce-bogus');
  8018. caretContainer.removeAttribute('style');
  8019. caretContainer.removeAttribute('_moz_abspos');
  8020. return caretContainer;
  8021. }
  8022. return null;
  8023. };
  8024. var isRangeInCaretContainerBlock = function (range) {
  8025. return isCaretContainerBlock(range.startContainer);
  8026. };
  8027. var isContentEditableTrue$1 = NodeType.isContentEditableTrue;
  8028. var isContentEditableFalse$1 = NodeType.isContentEditableFalse;
  8029. var isBr$2 = NodeType.isBr;
  8030. var isText$3 = NodeType.isText;
  8031. var isInvalidTextElement = NodeType.matchNodeNames([
  8032. 'script',
  8033. 'style',
  8034. 'textarea'
  8035. ]);
  8036. var isAtomicInline = NodeType.matchNodeNames([
  8037. 'img',
  8038. 'input',
  8039. 'textarea',
  8040. 'hr',
  8041. 'iframe',
  8042. 'video',
  8043. 'audio',
  8044. 'object'
  8045. ]);
  8046. var isTable$2 = NodeType.matchNodeNames(['table']);
  8047. var isCaretContainer$1 = isCaretContainer;
  8048. var isCaretCandidate = function (node) {
  8049. if (isCaretContainer$1(node)) {
  8050. return false;
  8051. }
  8052. if (isText$3(node)) {
  8053. if (isInvalidTextElement(node.parentNode)) {
  8054. return false;
  8055. }
  8056. return true;
  8057. }
  8058. return isAtomicInline(node) || isBr$2(node) || isTable$2(node) || isNonUiContentEditableFalse(node);
  8059. };
  8060. var isUnselectable = function (node) {
  8061. return NodeType.isElement(node) && node.getAttribute('unselectable') === 'true';
  8062. };
  8063. var isNonUiContentEditableFalse = function (node) {
  8064. return isUnselectable(node) === false && isContentEditableFalse$1(node);
  8065. };
  8066. var isInEditable = function (node, root) {
  8067. for (node = node.parentNode; node && node !== root; node = node.parentNode) {
  8068. if (isNonUiContentEditableFalse(node)) {
  8069. return false;
  8070. }
  8071. if (isContentEditableTrue$1(node)) {
  8072. return true;
  8073. }
  8074. }
  8075. return true;
  8076. };
  8077. var isAtomicContentEditableFalse = function (node) {
  8078. if (!isNonUiContentEditableFalse(node)) {
  8079. return false;
  8080. }
  8081. return foldl(from$1(node.getElementsByTagName('*')), function (result, elm) {
  8082. return result || isContentEditableTrue$1(elm);
  8083. }, false) !== true;
  8084. };
  8085. var isAtomic = function (node) {
  8086. return isAtomicInline(node) || isAtomicContentEditableFalse(node);
  8087. };
  8088. var isEditableCaretCandidate = function (node, root) {
  8089. return isCaretCandidate(node) && isInEditable(node, root);
  8090. };
  8091. var round = Math.round;
  8092. var clone$1 = function (rect) {
  8093. if (!rect) {
  8094. return {
  8095. left: 0,
  8096. top: 0,
  8097. bottom: 0,
  8098. right: 0,
  8099. width: 0,
  8100. height: 0
  8101. };
  8102. }
  8103. return {
  8104. left: round(rect.left),
  8105. top: round(rect.top),
  8106. bottom: round(rect.bottom),
  8107. right: round(rect.right),
  8108. width: round(rect.width),
  8109. height: round(rect.height)
  8110. };
  8111. };
  8112. var collapse = function (rect, toStart) {
  8113. rect = clone$1(rect);
  8114. if (toStart) {
  8115. rect.right = rect.left;
  8116. } else {
  8117. rect.left = rect.left + rect.width;
  8118. rect.right = rect.left;
  8119. }
  8120. rect.width = 0;
  8121. return rect;
  8122. };
  8123. var isEqual = function (rect1, rect2) {
  8124. return rect1.left === rect2.left && rect1.top === rect2.top && rect1.bottom === rect2.bottom && rect1.right === rect2.right;
  8125. };
  8126. var isValidOverflow = function (overflowY, rect1, rect2) {
  8127. return overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2;
  8128. };
  8129. var isAbove = function (rect1, rect2) {
  8130. if (rect1.bottom - rect1.height / 2 < rect2.top) {
  8131. return true;
  8132. }
  8133. if (rect1.top > rect2.bottom) {
  8134. return false;
  8135. }
  8136. return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2);
  8137. };
  8138. var isBelow = function (rect1, rect2) {
  8139. if (rect1.top > rect2.bottom) {
  8140. return true;
  8141. }
  8142. if (rect1.bottom < rect2.top) {
  8143. return false;
  8144. }
  8145. return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2);
  8146. };
  8147. var containsXY = function (rect, clientX, clientY) {
  8148. return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
  8149. };
  8150. var getSelectedNode = function (range) {
  8151. var startContainer = range.startContainer, startOffset = range.startOffset;
  8152. if (startContainer.hasChildNodes() && range.endOffset === startOffset + 1) {
  8153. return startContainer.childNodes[startOffset];
  8154. }
  8155. return null;
  8156. };
  8157. var getNode = function (container, offset) {
  8158. if (container.nodeType === 1 && container.hasChildNodes()) {
  8159. if (offset >= container.childNodes.length) {
  8160. offset = container.childNodes.length - 1;
  8161. }
  8162. container = container.childNodes[offset];
  8163. }
  8164. return container;
  8165. };
  8166. var extendingChars = new RegExp('[\u0300-\u036f\u0483-\u0487\u0488-\u0489\u0591-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u061a' + '\u064b-\u065f\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0' + '\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0902\u093a\u093c' + '\u0941-\u0948\u094d\u0951-\u0957\u0962-\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2-\u09e3' + '\u0a01-\u0a02\u0a3c\u0a41-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a51\u0a70-\u0a71\u0a75\u0a81-\u0a82\u0abc' + '\u0ac1-\u0ac5\u0ac7-\u0ac8\u0acd\u0ae2-\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57' + '\u0b62-\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c00\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56' + '\u0c62-\u0c63\u0c81\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc-\u0ccd\u0cd5-\u0cd6\u0ce2-\u0ce3\u0d01\u0d3e\u0d41-\u0d44' + '\u0d4d\u0d57\u0d62-\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9' + '\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86-\u0f87\u0f8d-\u0f97' + '\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039-\u103a\u103d-\u103e\u1058-\u1059\u105e-\u1060\u1071-\u1074' + '\u1082\u1085-\u1086\u108d\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b4-\u17b5' + '\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193b\u1a17-\u1a18' + '\u1a1b\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1ab0-\u1abd\u1ABE\u1b00-\u1b03\u1b34' + '\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80-\u1b81\u1ba2-\u1ba5\u1ba8-\u1ba9\u1bab-\u1bad\u1be6\u1be8-\u1be9' + '\u1bed\u1bef-\u1bf1\u1c2c-\u1c33\u1c36-\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1cf4\u1cf8-\u1cf9' + '\u1dc0-\u1df5\u1dfc-\u1dff\u200c-\u200d\u20d0-\u20dc\u20DD-\u20E0\u20e1\u20E2-\u20E4\u20e5-\u20f0\u2cef-\u2cf1' + '\u2d7f\u2de0-\u2dff\u302a-\u302d\u302e-\u302f\u3099-\u309a\ua66f\uA670-\uA672\ua674-\ua67d\ua69e-\ua69f\ua6f0-\ua6f1' + '\ua802\ua806\ua80b\ua825-\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc' + '\ua9e5\uaa29-\uaa2e\uaa31-\uaa32\uaa35-\uaa36\uaa43\uaa4c\uaa7c\uaab0\uaab2-\uaab4\uaab7-\uaab8\uaabe-\uaabf\uaac1' + '\uaaec-\uaaed\uaaf6\uabe5\uabe8\uabed\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\uff9e-\uff9f]');
  8167. var isExtendingChar = function (ch) {
  8168. return typeof ch === 'string' && ch.charCodeAt(0) >= 768 && extendingChars.test(ch);
  8169. };
  8170. var lift2 = function (oa, ob, f) {
  8171. return oa.isSome() && ob.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie())) : Option.none();
  8172. };
  8173. var lift3 = function (oa, ob, oc, f) {
  8174. return oa.isSome() && ob.isSome() && oc.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Option.none();
  8175. };
  8176. var someIf = function (b, a) {
  8177. return b ? Option.some(a) : Option.none();
  8178. };
  8179. var slice$2 = [].slice;
  8180. var or = function () {
  8181. var x = [];
  8182. for (var _i = 0; _i < arguments.length; _i++) {
  8183. x[_i] = arguments[_i];
  8184. }
  8185. var args = slice$2.call(arguments);
  8186. return function (x) {
  8187. for (var i = 0; i < args.length; i++) {
  8188. if (args[i](x)) {
  8189. return true;
  8190. }
  8191. }
  8192. return false;
  8193. };
  8194. };
  8195. var and = function () {
  8196. var x = [];
  8197. for (var _i = 0; _i < arguments.length; _i++) {
  8198. x[_i] = arguments[_i];
  8199. }
  8200. var args = slice$2.call(arguments);
  8201. return function (x) {
  8202. for (var i = 0; i < args.length; i++) {
  8203. if (!args[i](x)) {
  8204. return false;
  8205. }
  8206. }
  8207. return true;
  8208. };
  8209. };
  8210. var Predicate = {
  8211. and: and,
  8212. or: or
  8213. };
  8214. var isElement$3 = NodeType.isElement;
  8215. var isCaretCandidate$1 = isCaretCandidate;
  8216. var isBlock$1 = NodeType.matchStyleValues('display', 'block table');
  8217. var isFloated = NodeType.matchStyleValues('float', 'left right');
  8218. var isValidElementCaretCandidate = Predicate.and(isElement$3, isCaretCandidate$1, not(isFloated));
  8219. var isNotPre = not(NodeType.matchStyleValues('white-space', 'pre pre-line pre-wrap'));
  8220. var isText$4 = NodeType.isText;
  8221. var isBr$3 = NodeType.isBr;
  8222. var nodeIndex = DOMUtils$1.nodeIndex;
  8223. var resolveIndex = getNode;
  8224. var createRange = function (doc) {
  8225. return 'createRange' in doc ? doc.createRange() : DOMUtils$1.DOM.createRng();
  8226. };
  8227. var isWhiteSpace = function (chr) {
  8228. return chr && /[\r\n\t ]/.test(chr);
  8229. };
  8230. var isRange = function (rng) {
  8231. return !!rng.setStart && !!rng.setEnd;
  8232. };
  8233. var isHiddenWhiteSpaceRange = function (range) {
  8234. var container = range.startContainer;
  8235. var offset = range.startOffset;
  8236. var text;
  8237. if (isWhiteSpace(range.toString()) && isNotPre(container.parentNode) && NodeType.isText(container)) {
  8238. text = container.data;
  8239. if (isWhiteSpace(text[offset - 1]) || isWhiteSpace(text[offset + 1])) {
  8240. return true;
  8241. }
  8242. }
  8243. return false;
  8244. };
  8245. var getBrClientRect = function (brNode) {
  8246. var doc = brNode.ownerDocument;
  8247. var rng = createRange(doc);
  8248. var nbsp = doc.createTextNode('\xA0');
  8249. var parentNode = brNode.parentNode;
  8250. var clientRect;
  8251. parentNode.insertBefore(nbsp, brNode);
  8252. rng.setStart(nbsp, 0);
  8253. rng.setEnd(nbsp, 1);
  8254. clientRect = clone$1(rng.getBoundingClientRect());
  8255. parentNode.removeChild(nbsp);
  8256. return clientRect;
  8257. };
  8258. var getBoundingClientRectWebKitText = function (rng) {
  8259. var sc = rng.startContainer;
  8260. var ec = rng.endContainer;
  8261. var so = rng.startOffset;
  8262. var eo = rng.endOffset;
  8263. if (sc === ec && NodeType.isText(ec) && so === 0 && eo === 1) {
  8264. var newRng = rng.cloneRange();
  8265. newRng.setEndAfter(ec);
  8266. return getBoundingClientRect(newRng);
  8267. } else {
  8268. return null;
  8269. }
  8270. };
  8271. var isZeroRect = function (r) {
  8272. return r.left === 0 && r.right === 0 && r.top === 0 && r.bottom === 0;
  8273. };
  8274. var getBoundingClientRect = function (item) {
  8275. var clientRect, clientRects;
  8276. clientRects = item.getClientRects();
  8277. if (clientRects.length > 0) {
  8278. clientRect = clone$1(clientRects[0]);
  8279. } else {
  8280. clientRect = clone$1(item.getBoundingClientRect());
  8281. }
  8282. if (!isRange(item) && isBr$3(item) && isZeroRect(clientRect)) {
  8283. return getBrClientRect(item);
  8284. }
  8285. if (isZeroRect(clientRect) && isRange(item)) {
  8286. return getBoundingClientRectWebKitText(item);
  8287. }
  8288. return clientRect;
  8289. };
  8290. var collapseAndInflateWidth = function (clientRect, toStart) {
  8291. var newClientRect = collapse(clientRect, toStart);
  8292. newClientRect.width = 1;
  8293. newClientRect.right = newClientRect.left + 1;
  8294. return newClientRect;
  8295. };
  8296. var getCaretPositionClientRects = function (caretPosition) {
  8297. var clientRects = [];
  8298. var beforeNode, node;
  8299. var addUniqueAndValidRect = function (clientRect) {
  8300. if (clientRect.height === 0) {
  8301. return;
  8302. }
  8303. if (clientRects.length > 0) {
  8304. if (isEqual(clientRect, clientRects[clientRects.length - 1])) {
  8305. return;
  8306. }
  8307. }
  8308. clientRects.push(clientRect);
  8309. };
  8310. var addCharacterOffset = function (container, offset) {
  8311. var range = createRange(container.ownerDocument);
  8312. if (offset < container.data.length) {
  8313. if (isExtendingChar(container.data[offset])) {
  8314. return clientRects;
  8315. }
  8316. if (isExtendingChar(container.data[offset - 1])) {
  8317. range.setStart(container, offset);
  8318. range.setEnd(container, offset + 1);
  8319. if (!isHiddenWhiteSpaceRange(range)) {
  8320. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(range), false));
  8321. return clientRects;
  8322. }
  8323. }
  8324. }
  8325. if (offset > 0) {
  8326. range.setStart(container, offset - 1);
  8327. range.setEnd(container, offset);
  8328. if (!isHiddenWhiteSpaceRange(range)) {
  8329. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(range), false));
  8330. }
  8331. }
  8332. if (offset < container.data.length) {
  8333. range.setStart(container, offset);
  8334. range.setEnd(container, offset + 1);
  8335. if (!isHiddenWhiteSpaceRange(range)) {
  8336. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(range), true));
  8337. }
  8338. }
  8339. };
  8340. if (isText$4(caretPosition.container())) {
  8341. addCharacterOffset(caretPosition.container(), caretPosition.offset());
  8342. return clientRects;
  8343. }
  8344. if (isElement$3(caretPosition.container())) {
  8345. if (caretPosition.isAtEnd()) {
  8346. node = resolveIndex(caretPosition.container(), caretPosition.offset());
  8347. if (isText$4(node)) {
  8348. addCharacterOffset(node, node.data.length);
  8349. }
  8350. if (isValidElementCaretCandidate(node) && !isBr$3(node)) {
  8351. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(node), false));
  8352. }
  8353. } else {
  8354. node = resolveIndex(caretPosition.container(), caretPosition.offset());
  8355. if (isText$4(node)) {
  8356. addCharacterOffset(node, 0);
  8357. }
  8358. if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) {
  8359. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(node), false));
  8360. return clientRects;
  8361. }
  8362. beforeNode = resolveIndex(caretPosition.container(), caretPosition.offset() - 1);
  8363. if (isValidElementCaretCandidate(beforeNode) && !isBr$3(beforeNode)) {
  8364. if (isBlock$1(beforeNode) || isBlock$1(node) || !isValidElementCaretCandidate(node)) {
  8365. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(beforeNode), false));
  8366. }
  8367. }
  8368. if (isValidElementCaretCandidate(node)) {
  8369. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(node), true));
  8370. }
  8371. }
  8372. }
  8373. return clientRects;
  8374. };
  8375. function CaretPosition(container, offset, clientRects) {
  8376. var isAtStart = function () {
  8377. if (isText$4(container)) {
  8378. return offset === 0;
  8379. }
  8380. return offset === 0;
  8381. };
  8382. var isAtEnd = function () {
  8383. if (isText$4(container)) {
  8384. return offset >= container.data.length;
  8385. }
  8386. return offset >= container.childNodes.length;
  8387. };
  8388. var toRange = function () {
  8389. var range;
  8390. range = createRange(container.ownerDocument);
  8391. range.setStart(container, offset);
  8392. range.setEnd(container, offset);
  8393. return range;
  8394. };
  8395. var getClientRects = function () {
  8396. if (!clientRects) {
  8397. clientRects = getCaretPositionClientRects(CaretPosition(container, offset));
  8398. }
  8399. return clientRects;
  8400. };
  8401. var isVisible = function () {
  8402. return getClientRects().length > 0;
  8403. };
  8404. var isEqual = function (caretPosition) {
  8405. return caretPosition && container === caretPosition.container() && offset === caretPosition.offset();
  8406. };
  8407. var getNode = function (before) {
  8408. return resolveIndex(container, before ? offset - 1 : offset);
  8409. };
  8410. return {
  8411. container: constant(container),
  8412. offset: constant(offset),
  8413. toRange: toRange,
  8414. getClientRects: getClientRects,
  8415. isVisible: isVisible,
  8416. isAtStart: isAtStart,
  8417. isAtEnd: isAtEnd,
  8418. isEqual: isEqual,
  8419. getNode: getNode
  8420. };
  8421. }
  8422. (function (CaretPosition) {
  8423. CaretPosition.fromRangeStart = function (range) {
  8424. return CaretPosition(range.startContainer, range.startOffset);
  8425. };
  8426. CaretPosition.fromRangeEnd = function (range) {
  8427. return CaretPosition(range.endContainer, range.endOffset);
  8428. };
  8429. CaretPosition.after = function (node) {
  8430. return CaretPosition(node.parentNode, nodeIndex(node) + 1);
  8431. };
  8432. CaretPosition.before = function (node) {
  8433. return CaretPosition(node.parentNode, nodeIndex(node));
  8434. };
  8435. CaretPosition.isAbove = function (pos1, pos2) {
  8436. return lift2(head(pos2.getClientRects()), last(pos1.getClientRects()), isAbove).getOr(false);
  8437. };
  8438. CaretPosition.isBelow = function (pos1, pos2) {
  8439. return lift2(last(pos2.getClientRects()), head(pos1.getClientRects()), isBelow).getOr(false);
  8440. };
  8441. CaretPosition.isAtStart = function (pos) {
  8442. return pos ? pos.isAtStart() : false;
  8443. };
  8444. CaretPosition.isAtEnd = function (pos) {
  8445. return pos ? pos.isAtEnd() : false;
  8446. };
  8447. CaretPosition.isTextPosition = function (pos) {
  8448. return pos ? NodeType.isText(pos.container()) : false;
  8449. };
  8450. CaretPosition.isElementPosition = function (pos) {
  8451. return CaretPosition.isTextPosition(pos) === false;
  8452. };
  8453. }(CaretPosition || (CaretPosition = {})));
  8454. var CaretPosition$1 = CaretPosition;
  8455. var isText$5 = NodeType.isText;
  8456. var isBogus$1 = NodeType.isBogus;
  8457. var nodeIndex$1 = DOMUtils$1.nodeIndex;
  8458. var normalizedParent = function (node) {
  8459. var parentNode = node.parentNode;
  8460. if (isBogus$1(parentNode)) {
  8461. return normalizedParent(parentNode);
  8462. }
  8463. return parentNode;
  8464. };
  8465. var getChildNodes = function (node) {
  8466. if (!node) {
  8467. return [];
  8468. }
  8469. return ArrUtils.reduce(node.childNodes, function (result, node) {
  8470. if (isBogus$1(node) && node.nodeName !== 'BR') {
  8471. result = result.concat(getChildNodes(node));
  8472. } else {
  8473. result.push(node);
  8474. }
  8475. return result;
  8476. }, []);
  8477. };
  8478. var normalizedTextOffset = function (node, offset) {
  8479. while (node = node.previousSibling) {
  8480. if (!isText$5(node)) {
  8481. break;
  8482. }
  8483. offset += node.data.length;
  8484. }
  8485. return offset;
  8486. };
  8487. var equal = function (a) {
  8488. return function (b) {
  8489. return a === b;
  8490. };
  8491. };
  8492. var normalizedNodeIndex = function (node) {
  8493. var nodes, index, numTextFragments;
  8494. nodes = getChildNodes(normalizedParent(node));
  8495. index = ArrUtils.findIndex(nodes, equal(node), node);
  8496. nodes = nodes.slice(0, index + 1);
  8497. numTextFragments = ArrUtils.reduce(nodes, function (result, node, i) {
  8498. if (isText$5(node) && isText$5(nodes[i - 1])) {
  8499. result++;
  8500. }
  8501. return result;
  8502. }, 0);
  8503. nodes = ArrUtils.filter(nodes, NodeType.matchNodeNames([node.nodeName]));
  8504. index = ArrUtils.findIndex(nodes, equal(node), node);
  8505. return index - numTextFragments;
  8506. };
  8507. var createPathItem = function (node) {
  8508. var name;
  8509. if (isText$5(node)) {
  8510. name = 'text()';
  8511. } else {
  8512. name = node.nodeName.toLowerCase();
  8513. }
  8514. return name + '[' + normalizedNodeIndex(node) + ']';
  8515. };
  8516. var parentsUntil = function (root, node, predicate) {
  8517. var parents = [];
  8518. for (node = node.parentNode; node !== root; node = node.parentNode) {
  8519. if (predicate && predicate(node)) {
  8520. break;
  8521. }
  8522. parents.push(node);
  8523. }
  8524. return parents;
  8525. };
  8526. var create$2 = function (root, caretPosition) {
  8527. var container, offset, path = [], outputOffset, childNodes, parents;
  8528. container = caretPosition.container();
  8529. offset = caretPosition.offset();
  8530. if (isText$5(container)) {
  8531. outputOffset = normalizedTextOffset(container, offset);
  8532. } else {
  8533. childNodes = container.childNodes;
  8534. if (offset >= childNodes.length) {
  8535. outputOffset = 'after';
  8536. offset = childNodes.length - 1;
  8537. } else {
  8538. outputOffset = 'before';
  8539. }
  8540. container = childNodes[offset];
  8541. }
  8542. path.push(createPathItem(container));
  8543. parents = parentsUntil(root, container);
  8544. parents = ArrUtils.filter(parents, not(NodeType.isBogus));
  8545. path = path.concat(ArrUtils.map(parents, function (node) {
  8546. return createPathItem(node);
  8547. }));
  8548. return path.reverse().join('/') + ',' + outputOffset;
  8549. };
  8550. var resolvePathItem = function (node, name, index) {
  8551. var nodes = getChildNodes(node);
  8552. nodes = ArrUtils.filter(nodes, function (node, index) {
  8553. return !isText$5(node) || !isText$5(nodes[index - 1]);
  8554. });
  8555. nodes = ArrUtils.filter(nodes, NodeType.matchNodeNames([name]));
  8556. return nodes[index];
  8557. };
  8558. var findTextPosition = function (container, offset) {
  8559. var node = container, targetOffset = 0, dataLen;
  8560. while (isText$5(node)) {
  8561. dataLen = node.data.length;
  8562. if (offset >= targetOffset && offset <= targetOffset + dataLen) {
  8563. container = node;
  8564. offset = offset - targetOffset;
  8565. break;
  8566. }
  8567. if (!isText$5(node.nextSibling)) {
  8568. container = node;
  8569. offset = dataLen;
  8570. break;
  8571. }
  8572. targetOffset += dataLen;
  8573. node = node.nextSibling;
  8574. }
  8575. if (isText$5(container) && offset > container.data.length) {
  8576. offset = container.data.length;
  8577. }
  8578. return CaretPosition$1(container, offset);
  8579. };
  8580. var resolve$1 = function (root, path) {
  8581. var parts, container, offset;
  8582. if (!path) {
  8583. return null;
  8584. }
  8585. parts = path.split(',');
  8586. path = parts[0].split('/');
  8587. offset = parts.length > 1 ? parts[1] : 'before';
  8588. container = ArrUtils.reduce(path, function (result, value) {
  8589. value = /([\w\-\(\)]+)\[([0-9]+)\]/.exec(value);
  8590. if (!value) {
  8591. return null;
  8592. }
  8593. if (value[1] === 'text()') {
  8594. value[1] = '#text';
  8595. }
  8596. return resolvePathItem(result, value[1], parseInt(value[2], 10));
  8597. }, root);
  8598. if (!container) {
  8599. return null;
  8600. }
  8601. if (!isText$5(container)) {
  8602. if (offset === 'after') {
  8603. offset = nodeIndex$1(container) + 1;
  8604. } else {
  8605. offset = nodeIndex$1(container);
  8606. }
  8607. return CaretPosition$1(container.parentNode, offset);
  8608. }
  8609. return findTextPosition(container, parseInt(offset, 10));
  8610. };
  8611. var trimEmptyTextNode = function (dom, node) {
  8612. if (NodeType.isText(node) && node.data.length === 0) {
  8613. dom.remove(node);
  8614. }
  8615. };
  8616. var insertNode = function (dom, rng, node) {
  8617. rng.insertNode(node);
  8618. trimEmptyTextNode(dom, node.previousSibling);
  8619. trimEmptyTextNode(dom, node.nextSibling);
  8620. };
  8621. var insertFragment = function (dom, rng, frag) {
  8622. var firstChild = Option.from(frag.firstChild);
  8623. var lastChild = Option.from(frag.lastChild);
  8624. rng.insertNode(frag);
  8625. firstChild.each(function (child) {
  8626. return trimEmptyTextNode(dom, child.previousSibling);
  8627. });
  8628. lastChild.each(function (child) {
  8629. return trimEmptyTextNode(dom, child.nextSibling);
  8630. });
  8631. };
  8632. var rangeInsertNode = function (dom, rng, node) {
  8633. if (NodeType.isDocumentFragment(node)) {
  8634. insertFragment(dom, rng, node);
  8635. } else {
  8636. insertNode(dom, rng, node);
  8637. }
  8638. };
  8639. var isContentEditableFalse$2 = NodeType.isContentEditableFalse;
  8640. var getNormalizedTextOffset = function (trim, container, offset) {
  8641. var node, trimmedOffset;
  8642. trimmedOffset = trim(container.data.slice(0, offset)).length;
  8643. for (node = container.previousSibling; node && NodeType.isText(node); node = node.previousSibling) {
  8644. trimmedOffset += trim(node.data).length;
  8645. }
  8646. return trimmedOffset;
  8647. };
  8648. var getPoint = function (dom, trim, normalized, rng, start) {
  8649. var container = rng[start ? 'startContainer' : 'endContainer'];
  8650. var offset = rng[start ? 'startOffset' : 'endOffset'];
  8651. var point = [];
  8652. var childNodes, after = 0;
  8653. var root = dom.getRoot();
  8654. if (NodeType.isText(container)) {
  8655. point.push(normalized ? getNormalizedTextOffset(trim, container, offset) : offset);
  8656. } else {
  8657. childNodes = container.childNodes;
  8658. if (offset >= childNodes.length && childNodes.length) {
  8659. after = 1;
  8660. offset = Math.max(0, childNodes.length - 1);
  8661. }
  8662. point.push(dom.nodeIndex(childNodes[offset], normalized) + after);
  8663. }
  8664. for (; container && container !== root; container = container.parentNode) {
  8665. point.push(dom.nodeIndex(container, normalized));
  8666. }
  8667. return point;
  8668. };
  8669. var getLocation = function (trim, selection, normalized, rng) {
  8670. var dom = selection.dom, bookmark = {};
  8671. bookmark.start = getPoint(dom, trim, normalized, rng, true);
  8672. if (!selection.isCollapsed()) {
  8673. bookmark.end = getPoint(dom, trim, normalized, rng, false);
  8674. }
  8675. return bookmark;
  8676. };
  8677. var findIndex$2 = function (dom, name, element) {
  8678. var count = 0;
  8679. Tools.each(dom.select(name), function (node) {
  8680. if (node.getAttribute('data-mce-bogus') === 'all') {
  8681. return;
  8682. }
  8683. if (node === element) {
  8684. return false;
  8685. }
  8686. count++;
  8687. });
  8688. return count;
  8689. };
  8690. var moveEndPoint = function (rng, start) {
  8691. var container, offset, childNodes;
  8692. var prefix = start ? 'start' : 'end';
  8693. container = rng[prefix + 'Container'];
  8694. offset = rng[prefix + 'Offset'];
  8695. if (NodeType.isElement(container) && container.nodeName === 'TR') {
  8696. childNodes = container.childNodes;
  8697. container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
  8698. if (container) {
  8699. offset = start ? 0 : container.childNodes.length;
  8700. rng['set' + (start ? 'Start' : 'End')](container, offset);
  8701. }
  8702. }
  8703. };
  8704. var normalizeTableCellSelection = function (rng) {
  8705. moveEndPoint(rng, true);
  8706. moveEndPoint(rng, false);
  8707. return rng;
  8708. };
  8709. var findSibling = function (node, offset) {
  8710. var sibling;
  8711. if (NodeType.isElement(node)) {
  8712. node = getNode(node, offset);
  8713. if (isContentEditableFalse$2(node)) {
  8714. return node;
  8715. }
  8716. }
  8717. if (isCaretContainer(node)) {
  8718. if (NodeType.isText(node) && isCaretContainerBlock(node)) {
  8719. node = node.parentNode;
  8720. }
  8721. sibling = node.previousSibling;
  8722. if (isContentEditableFalse$2(sibling)) {
  8723. return sibling;
  8724. }
  8725. sibling = node.nextSibling;
  8726. if (isContentEditableFalse$2(sibling)) {
  8727. return sibling;
  8728. }
  8729. }
  8730. };
  8731. var findAdjacentContentEditableFalseElm = function (rng) {
  8732. return findSibling(rng.startContainer, rng.startOffset) || findSibling(rng.endContainer, rng.endOffset);
  8733. };
  8734. var getOffsetBookmark = function (trim, normalized, selection) {
  8735. var element = selection.getNode();
  8736. var name = element ? element.nodeName : null;
  8737. var rng = selection.getRng();
  8738. if (isContentEditableFalse$2(element) || name === 'IMG') {
  8739. return {
  8740. name: name,
  8741. index: findIndex$2(selection.dom, name, element)
  8742. };
  8743. }
  8744. var sibling = findAdjacentContentEditableFalseElm(rng);
  8745. if (sibling) {
  8746. name = sibling.tagName;
  8747. return {
  8748. name: name,
  8749. index: findIndex$2(selection.dom, name, sibling)
  8750. };
  8751. }
  8752. return getLocation(trim, selection, normalized, rng);
  8753. };
  8754. var getCaretBookmark = function (selection) {
  8755. var rng = selection.getRng();
  8756. return {
  8757. start: create$2(selection.dom.getRoot(), CaretPosition$1.fromRangeStart(rng)),
  8758. end: create$2(selection.dom.getRoot(), CaretPosition$1.fromRangeEnd(rng))
  8759. };
  8760. };
  8761. var getRangeBookmark = function (selection) {
  8762. return { rng: selection.getRng() };
  8763. };
  8764. var createBookmarkSpan = function (dom, id, filled) {
  8765. var args = {
  8766. 'data-mce-type': 'bookmark',
  8767. 'id': id,
  8768. 'style': 'overflow:hidden;line-height:0px'
  8769. };
  8770. return filled ? dom.create('span', args, '&#xFEFF;') : dom.create('span', args);
  8771. };
  8772. var getPersistentBookmark = function (selection, filled) {
  8773. var dom = selection.dom;
  8774. var rng = selection.getRng();
  8775. var id = dom.uniqueId();
  8776. var collapsed = selection.isCollapsed();
  8777. var element = selection.getNode();
  8778. var name = element.nodeName;
  8779. if (name === 'IMG') {
  8780. return {
  8781. name: name,
  8782. index: findIndex$2(dom, name, element)
  8783. };
  8784. }
  8785. var rng2 = normalizeTableCellSelection(rng.cloneRange());
  8786. if (!collapsed) {
  8787. rng2.collapse(false);
  8788. var endBookmarkNode = createBookmarkSpan(dom, id + '_end', filled);
  8789. rangeInsertNode(dom, rng2, endBookmarkNode);
  8790. }
  8791. rng = normalizeTableCellSelection(rng);
  8792. rng.collapse(true);
  8793. var startBookmarkNode = createBookmarkSpan(dom, id + '_start', filled);
  8794. rangeInsertNode(dom, rng, startBookmarkNode);
  8795. selection.moveToBookmark({
  8796. id: id,
  8797. keep: 1
  8798. });
  8799. return { id: id };
  8800. };
  8801. var getBookmark = function (selection, type, normalized) {
  8802. if (type === 2) {
  8803. return getOffsetBookmark(Zwsp.trim, normalized, selection);
  8804. } else if (type === 3) {
  8805. return getCaretBookmark(selection);
  8806. } else if (type) {
  8807. return getRangeBookmark(selection);
  8808. } else {
  8809. return getPersistentBookmark(selection, false);
  8810. }
  8811. };
  8812. var GetBookmark = {
  8813. getBookmark: getBookmark,
  8814. getUndoBookmark: curry(getOffsetBookmark, identity, true),
  8815. getPersistentBookmark: getPersistentBookmark
  8816. };
  8817. var CARET_ID = '_mce_caret';
  8818. var isCaretNode = function (node) {
  8819. return NodeType.isElement(node) && node.id === CARET_ID;
  8820. };
  8821. var getParentCaretContainer = function (body, node) {
  8822. while (node && node !== body) {
  8823. if (node.id === CARET_ID) {
  8824. return node;
  8825. }
  8826. node = node.parentNode;
  8827. }
  8828. return null;
  8829. };
  8830. var isElement$4 = NodeType.isElement;
  8831. var isText$6 = NodeType.isText;
  8832. var removeNode = function (node) {
  8833. var parentNode = node.parentNode;
  8834. if (parentNode) {
  8835. parentNode.removeChild(node);
  8836. }
  8837. };
  8838. var getNodeValue = function (node) {
  8839. try {
  8840. return node.nodeValue;
  8841. } catch (ex) {
  8842. return '';
  8843. }
  8844. };
  8845. var setNodeValue = function (node, text) {
  8846. if (text.length === 0) {
  8847. removeNode(node);
  8848. } else {
  8849. node.nodeValue = text;
  8850. }
  8851. };
  8852. var trimCount = function (text) {
  8853. var trimmedText = Zwsp.trim(text);
  8854. return {
  8855. count: text.length - trimmedText.length,
  8856. text: trimmedText
  8857. };
  8858. };
  8859. var removeUnchanged = function (caretContainer, pos) {
  8860. remove$5(caretContainer);
  8861. return pos;
  8862. };
  8863. var removeTextAndReposition = function (caretContainer, pos) {
  8864. var before = trimCount(caretContainer.data.substr(0, pos.offset()));
  8865. var after = trimCount(caretContainer.data.substr(pos.offset()));
  8866. var text = before.text + after.text;
  8867. if (text.length > 0) {
  8868. setNodeValue(caretContainer, text);
  8869. return CaretPosition$1(caretContainer, pos.offset() - before.count);
  8870. } else {
  8871. return pos;
  8872. }
  8873. };
  8874. var removeElementAndReposition = function (caretContainer, pos) {
  8875. var parentNode = pos.container();
  8876. var newPosition = indexOf(from$1(parentNode.childNodes), caretContainer).map(function (index) {
  8877. return index < pos.offset() ? CaretPosition$1(parentNode, pos.offset() - 1) : pos;
  8878. }).getOr(pos);
  8879. remove$5(caretContainer);
  8880. return newPosition;
  8881. };
  8882. var removeTextCaretContainer = function (caretContainer, pos) {
  8883. return isText$6(caretContainer) && pos.container() === caretContainer ? removeTextAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
  8884. };
  8885. var removeElementCaretContainer = function (caretContainer, pos) {
  8886. return pos.container() === caretContainer.parentNode ? removeElementAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
  8887. };
  8888. var removeAndReposition = function (container, pos) {
  8889. return CaretPosition$1.isTextPosition(pos) ? removeTextCaretContainer(container, pos) : removeElementCaretContainer(container, pos);
  8890. };
  8891. var remove$5 = function (caretContainerNode) {
  8892. if (isElement$4(caretContainerNode) && isCaretContainer(caretContainerNode)) {
  8893. if (hasContent(caretContainerNode)) {
  8894. caretContainerNode.removeAttribute('data-mce-caret');
  8895. } else {
  8896. removeNode(caretContainerNode);
  8897. }
  8898. }
  8899. if (isText$6(caretContainerNode)) {
  8900. var text = Zwsp.trim(getNodeValue(caretContainerNode));
  8901. setNodeValue(caretContainerNode, text);
  8902. }
  8903. };
  8904. var CaretContainerRemove = {
  8905. removeAndReposition: removeAndReposition,
  8906. remove: remove$5
  8907. };
  8908. var browser$3 = detect$3().browser;
  8909. var isContentEditableFalse$3 = NodeType.isContentEditableFalse;
  8910. var isTableCell$1 = function (node) {
  8911. return NodeType.isElement(node) && /^(TD|TH)$/i.test(node.tagName);
  8912. };
  8913. var getAbsoluteClientRect = function (root, element, before) {
  8914. var clientRect = collapse(element.getBoundingClientRect(), before);
  8915. var docElm, scrollX, scrollY, margin, rootRect;
  8916. if (root.tagName === 'BODY') {
  8917. docElm = root.ownerDocument.documentElement;
  8918. scrollX = root.scrollLeft || docElm.scrollLeft;
  8919. scrollY = root.scrollTop || docElm.scrollTop;
  8920. } else {
  8921. rootRect = root.getBoundingClientRect();
  8922. scrollX = root.scrollLeft - rootRect.left;
  8923. scrollY = root.scrollTop - rootRect.top;
  8924. }
  8925. clientRect.left += scrollX;
  8926. clientRect.right += scrollX;
  8927. clientRect.top += scrollY;
  8928. clientRect.bottom += scrollY;
  8929. clientRect.width = 1;
  8930. margin = element.offsetWidth - element.clientWidth;
  8931. if (margin > 0) {
  8932. if (before) {
  8933. margin *= -1;
  8934. }
  8935. clientRect.left += margin;
  8936. clientRect.right += margin;
  8937. }
  8938. return clientRect;
  8939. };
  8940. var trimInlineCaretContainers = function (root) {
  8941. var contentEditableFalseNodes, node, sibling, i, data;
  8942. contentEditableFalseNodes = DomQuery('*[contentEditable=false]', root);
  8943. for (i = 0; i < contentEditableFalseNodes.length; i++) {
  8944. node = contentEditableFalseNodes[i];
  8945. sibling = node.previousSibling;
  8946. if (endsWithCaretContainer(sibling)) {
  8947. data = sibling.data;
  8948. if (data.length === 1) {
  8949. sibling.parentNode.removeChild(sibling);
  8950. } else {
  8951. sibling.deleteData(data.length - 1, 1);
  8952. }
  8953. }
  8954. sibling = node.nextSibling;
  8955. if (startsWithCaretContainer(sibling)) {
  8956. data = sibling.data;
  8957. if (data.length === 1) {
  8958. sibling.parentNode.removeChild(sibling);
  8959. } else {
  8960. sibling.deleteData(0, 1);
  8961. }
  8962. }
  8963. }
  8964. };
  8965. var FakeCaret = function (root, isBlock, hasFocus) {
  8966. var lastVisualCaret = Cell(Option.none());
  8967. var cursorInterval, caretContainerNode;
  8968. var show = function (before, element) {
  8969. var clientRect, rng;
  8970. hide();
  8971. if (isTableCell$1(element)) {
  8972. return null;
  8973. }
  8974. if (isBlock(element)) {
  8975. caretContainerNode = insertBlock('p', element, before);
  8976. clientRect = getAbsoluteClientRect(root, element, before);
  8977. DomQuery(caretContainerNode).css('top', clientRect.top);
  8978. var caret = DomQuery('<div class="mce-visual-caret" data-mce-bogus="all"></div>').css(clientRect).appendTo(root)[0];
  8979. lastVisualCaret.set(Option.some({
  8980. caret: caret,
  8981. element: element,
  8982. before: before
  8983. }));
  8984. lastVisualCaret.get().each(function (caretState) {
  8985. if (before) {
  8986. DomQuery(caretState.caret).addClass('mce-visual-caret-before');
  8987. }
  8988. });
  8989. startBlink();
  8990. rng = element.ownerDocument.createRange();
  8991. rng.setStart(caretContainerNode, 0);
  8992. rng.setEnd(caretContainerNode, 0);
  8993. } else {
  8994. caretContainerNode = insertInline(element, before);
  8995. rng = element.ownerDocument.createRange();
  8996. if (isContentEditableFalse$3(caretContainerNode.nextSibling)) {
  8997. rng.setStart(caretContainerNode, 0);
  8998. rng.setEnd(caretContainerNode, 0);
  8999. } else {
  9000. rng.setStart(caretContainerNode, 1);
  9001. rng.setEnd(caretContainerNode, 1);
  9002. }
  9003. return rng;
  9004. }
  9005. return rng;
  9006. };
  9007. var hide = function () {
  9008. trimInlineCaretContainers(root);
  9009. if (caretContainerNode) {
  9010. CaretContainerRemove.remove(caretContainerNode);
  9011. caretContainerNode = null;
  9012. }
  9013. lastVisualCaret.get().each(function (caretState) {
  9014. DomQuery(caretState.caret).remove();
  9015. lastVisualCaret.set(Option.none());
  9016. });
  9017. Delay.clearInterval(cursorInterval);
  9018. };
  9019. var startBlink = function () {
  9020. cursorInterval = Delay.setInterval(function () {
  9021. if (hasFocus()) {
  9022. DomQuery('div.mce-visual-caret', root).toggleClass('mce-visual-caret-hidden');
  9023. } else {
  9024. DomQuery('div.mce-visual-caret', root).addClass('mce-visual-caret-hidden');
  9025. }
  9026. }, 500);
  9027. };
  9028. var reposition = function () {
  9029. lastVisualCaret.get().each(function (caretState) {
  9030. var clientRect = getAbsoluteClientRect(root, caretState.element, caretState.before);
  9031. DomQuery(caretState.caret).css(__assign({}, clientRect));
  9032. });
  9033. };
  9034. var destroy = function () {
  9035. return Delay.clearInterval(cursorInterval);
  9036. };
  9037. var getCss = function () {
  9038. return '.mce-visual-caret {' + 'position: absolute;' + 'background-color: black;' + 'background-color: currentcolor;' + '}' + '.mce-visual-caret-hidden {' + 'display: none;' + '}' + '*[data-mce-caret] {' + 'position: absolute;' + 'left: -1000px;' + 'right: auto;' + 'top: 0;' + 'margin: 0;' + 'padding: 0;' + '}';
  9039. };
  9040. return {
  9041. show: show,
  9042. hide: hide,
  9043. getCss: getCss,
  9044. reposition: reposition,
  9045. destroy: destroy
  9046. };
  9047. };
  9048. var isFakeCaretTableBrowser = function () {
  9049. return browser$3.isIE() || browser$3.isEdge() || browser$3.isFirefox();
  9050. };
  9051. var isFakeCaretTarget = function (node) {
  9052. return isContentEditableFalse$3(node) || NodeType.isTable(node) && isFakeCaretTableBrowser();
  9053. };
  9054. var isContentEditableFalse$4 = NodeType.isContentEditableFalse;
  9055. var isBlockLike = NodeType.matchStyleValues('display', 'block table table-cell table-caption list-item');
  9056. var isCaretContainer$2 = isCaretContainer;
  9057. var isCaretContainerBlock$1 = isCaretContainerBlock;
  9058. var isElement$5 = NodeType.isElement;
  9059. var isCaretCandidate$2 = isCaretCandidate;
  9060. var isForwards = function (direction) {
  9061. return direction > 0;
  9062. };
  9063. var isBackwards = function (direction) {
  9064. return direction < 0;
  9065. };
  9066. var skipCaretContainers = function (walk, shallow) {
  9067. var node;
  9068. while (node = walk(shallow)) {
  9069. if (!isCaretContainerBlock$1(node)) {
  9070. return node;
  9071. }
  9072. }
  9073. return null;
  9074. };
  9075. var findNode = function (node, direction, predicateFn, rootNode, shallow) {
  9076. var walker = new TreeWalker(node, rootNode);
  9077. if (isBackwards(direction)) {
  9078. if (isContentEditableFalse$4(node) || isCaretContainerBlock$1(node)) {
  9079. node = skipCaretContainers(walker.prev, true);
  9080. if (predicateFn(node)) {
  9081. return node;
  9082. }
  9083. }
  9084. while (node = skipCaretContainers(walker.prev, shallow)) {
  9085. if (predicateFn(node)) {
  9086. return node;
  9087. }
  9088. }
  9089. }
  9090. if (isForwards(direction)) {
  9091. if (isContentEditableFalse$4(node) || isCaretContainerBlock$1(node)) {
  9092. node = skipCaretContainers(walker.next, true);
  9093. if (predicateFn(node)) {
  9094. return node;
  9095. }
  9096. }
  9097. while (node = skipCaretContainers(walker.next, shallow)) {
  9098. if (predicateFn(node)) {
  9099. return node;
  9100. }
  9101. }
  9102. }
  9103. return null;
  9104. };
  9105. var getParentBlock = function (node, rootNode) {
  9106. while (node && node !== rootNode) {
  9107. if (isBlockLike(node)) {
  9108. return node;
  9109. }
  9110. node = node.parentNode;
  9111. }
  9112. return null;
  9113. };
  9114. var isInSameBlock = function (caretPosition1, caretPosition2, rootNode) {
  9115. return getParentBlock(caretPosition1.container(), rootNode) === getParentBlock(caretPosition2.container(), rootNode);
  9116. };
  9117. var getChildNodeAtRelativeOffset = function (relativeOffset, caretPosition) {
  9118. var container, offset;
  9119. if (!caretPosition) {
  9120. return null;
  9121. }
  9122. container = caretPosition.container();
  9123. offset = caretPosition.offset();
  9124. if (!isElement$5(container)) {
  9125. return null;
  9126. }
  9127. return container.childNodes[offset + relativeOffset];
  9128. };
  9129. var beforeAfter = function (before, node) {
  9130. var range = node.ownerDocument.createRange();
  9131. if (before) {
  9132. range.setStartBefore(node);
  9133. range.setEndBefore(node);
  9134. } else {
  9135. range.setStartAfter(node);
  9136. range.setEndAfter(node);
  9137. }
  9138. return range;
  9139. };
  9140. var isNodesInSameBlock = function (root, node1, node2) {
  9141. return getParentBlock(node1, root) === getParentBlock(node2, root);
  9142. };
  9143. var lean = function (left, root, node) {
  9144. var sibling, siblingName;
  9145. if (left) {
  9146. siblingName = 'previousSibling';
  9147. } else {
  9148. siblingName = 'nextSibling';
  9149. }
  9150. while (node && node !== root) {
  9151. sibling = node[siblingName];
  9152. if (isCaretContainer$2(sibling)) {
  9153. sibling = sibling[siblingName];
  9154. }
  9155. if (isContentEditableFalse$4(sibling)) {
  9156. if (isNodesInSameBlock(root, sibling, node)) {
  9157. return sibling;
  9158. }
  9159. break;
  9160. }
  9161. if (isCaretCandidate$2(sibling)) {
  9162. break;
  9163. }
  9164. node = node.parentNode;
  9165. }
  9166. return null;
  9167. };
  9168. var before$2 = curry(beforeAfter, true);
  9169. var after$1 = curry(beforeAfter, false);
  9170. var normalizeRange = function (direction, root, range) {
  9171. var node, container, offset, location;
  9172. var leanLeft = curry(lean, true, root);
  9173. var leanRight = curry(lean, false, root);
  9174. container = range.startContainer;
  9175. offset = range.startOffset;
  9176. if (isCaretContainerBlock(container)) {
  9177. if (!isElement$5(container)) {
  9178. container = container.parentNode;
  9179. }
  9180. location = container.getAttribute('data-mce-caret');
  9181. if (location === 'before') {
  9182. node = container.nextSibling;
  9183. if (isFakeCaretTarget(node)) {
  9184. return before$2(node);
  9185. }
  9186. }
  9187. if (location === 'after') {
  9188. node = container.previousSibling;
  9189. if (isFakeCaretTarget(node)) {
  9190. return after$1(node);
  9191. }
  9192. }
  9193. }
  9194. if (!range.collapsed) {
  9195. return range;
  9196. }
  9197. if (NodeType.isText(container)) {
  9198. if (isCaretContainer$2(container)) {
  9199. if (direction === 1) {
  9200. node = leanRight(container);
  9201. if (node) {
  9202. return before$2(node);
  9203. }
  9204. node = leanLeft(container);
  9205. if (node) {
  9206. return after$1(node);
  9207. }
  9208. }
  9209. if (direction === -1) {
  9210. node = leanLeft(container);
  9211. if (node) {
  9212. return after$1(node);
  9213. }
  9214. node = leanRight(container);
  9215. if (node) {
  9216. return before$2(node);
  9217. }
  9218. }
  9219. return range;
  9220. }
  9221. if (endsWithCaretContainer(container) && offset >= container.data.length - 1) {
  9222. if (direction === 1) {
  9223. node = leanRight(container);
  9224. if (node) {
  9225. return before$2(node);
  9226. }
  9227. }
  9228. return range;
  9229. }
  9230. if (startsWithCaretContainer(container) && offset <= 1) {
  9231. if (direction === -1) {
  9232. node = leanLeft(container);
  9233. if (node) {
  9234. return after$1(node);
  9235. }
  9236. }
  9237. return range;
  9238. }
  9239. if (offset === container.data.length) {
  9240. node = leanRight(container);
  9241. if (node) {
  9242. return before$2(node);
  9243. }
  9244. return range;
  9245. }
  9246. if (offset === 0) {
  9247. node = leanLeft(container);
  9248. if (node) {
  9249. return after$1(node);
  9250. }
  9251. return range;
  9252. }
  9253. }
  9254. return range;
  9255. };
  9256. var getRelativeCefElm = function (forward, caretPosition) {
  9257. return Option.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition)).filter(isContentEditableFalse$4);
  9258. };
  9259. var getNormalizedRangeEndPoint = function (direction, root, range) {
  9260. var normalizedRange = normalizeRange(direction, root, range);
  9261. if (direction === -1) {
  9262. return CaretPosition.fromRangeStart(normalizedRange);
  9263. }
  9264. return CaretPosition.fromRangeEnd(normalizedRange);
  9265. };
  9266. var getElementFromPosition = function (pos) {
  9267. return Option.from(pos.getNode()).map(Element.fromDom);
  9268. };
  9269. var getElementFromPrevPosition = function (pos) {
  9270. return Option.from(pos.getNode(true)).map(Element.fromDom);
  9271. };
  9272. var getVisualCaretPosition = function (walkFn, caretPosition) {
  9273. while (caretPosition = walkFn(caretPosition)) {
  9274. if (caretPosition.isVisible()) {
  9275. return caretPosition;
  9276. }
  9277. }
  9278. return caretPosition;
  9279. };
  9280. var isMoveInsideSameBlock = function (from, to) {
  9281. var inSameBlock = isInSameBlock(from, to);
  9282. if (!inSameBlock && NodeType.isBr(from.getNode())) {
  9283. return true;
  9284. }
  9285. return inSameBlock;
  9286. };
  9287. var HDirection;
  9288. (function (HDirection) {
  9289. HDirection[HDirection['Backwards'] = -1] = 'Backwards';
  9290. HDirection[HDirection['Forwards'] = 1] = 'Forwards';
  9291. }(HDirection || (HDirection = {})));
  9292. var isContentEditableFalse$5 = NodeType.isContentEditableFalse;
  9293. var isText$7 = NodeType.isText;
  9294. var isElement$6 = NodeType.isElement;
  9295. var isBr$4 = NodeType.isBr;
  9296. var isCaretCandidate$3 = isCaretCandidate;
  9297. var isAtomic$1 = isAtomic;
  9298. var isEditableCaretCandidate$1 = isEditableCaretCandidate;
  9299. var getParents = function (node, root) {
  9300. var parents = [];
  9301. while (node && node !== root) {
  9302. parents.push(node);
  9303. node = node.parentNode;
  9304. }
  9305. return parents;
  9306. };
  9307. var nodeAtIndex = function (container, offset) {
  9308. if (container.hasChildNodes() && offset < container.childNodes.length) {
  9309. return container.childNodes[offset];
  9310. }
  9311. return null;
  9312. };
  9313. var getCaretCandidatePosition = function (direction, node) {
  9314. if (isForwards(direction)) {
  9315. if (isCaretCandidate$3(node.previousSibling) && !isText$7(node.previousSibling)) {
  9316. return CaretPosition$1.before(node);
  9317. }
  9318. if (isText$7(node)) {
  9319. return CaretPosition$1(node, 0);
  9320. }
  9321. }
  9322. if (isBackwards(direction)) {
  9323. if (isCaretCandidate$3(node.nextSibling) && !isText$7(node.nextSibling)) {
  9324. return CaretPosition$1.after(node);
  9325. }
  9326. if (isText$7(node)) {
  9327. return CaretPosition$1(node, node.data.length);
  9328. }
  9329. }
  9330. if (isBackwards(direction)) {
  9331. if (isBr$4(node)) {
  9332. return CaretPosition$1.before(node);
  9333. }
  9334. return CaretPosition$1.after(node);
  9335. }
  9336. return CaretPosition$1.before(node);
  9337. };
  9338. var moveForwardFromBr = function (root, nextNode) {
  9339. var nextSibling = nextNode.nextSibling;
  9340. if (nextSibling && isCaretCandidate$3(nextSibling)) {
  9341. if (isText$7(nextSibling)) {
  9342. return CaretPosition$1(nextSibling, 0);
  9343. } else {
  9344. return CaretPosition$1.before(nextSibling);
  9345. }
  9346. } else {
  9347. return findCaretPosition(HDirection.Forwards, CaretPosition$1.after(nextNode), root);
  9348. }
  9349. };
  9350. var findCaretPosition = function (direction, startPos, root) {
  9351. var node, nextNode, innerNode;
  9352. var rootContentEditableFalseElm, caretPosition;
  9353. if (!isElement$6(root) || !startPos) {
  9354. return null;
  9355. }
  9356. if (startPos.isEqual(CaretPosition$1.after(root)) && root.lastChild) {
  9357. caretPosition = CaretPosition$1.after(root.lastChild);
  9358. if (isBackwards(direction) && isCaretCandidate$3(root.lastChild) && isElement$6(root.lastChild)) {
  9359. return isBr$4(root.lastChild) ? CaretPosition$1.before(root.lastChild) : caretPosition;
  9360. }
  9361. } else {
  9362. caretPosition = startPos;
  9363. }
  9364. var container = caretPosition.container();
  9365. var offset = caretPosition.offset();
  9366. if (isText$7(container)) {
  9367. if (isBackwards(direction) && offset > 0) {
  9368. return CaretPosition$1(container, --offset);
  9369. }
  9370. if (isForwards(direction) && offset < container.length) {
  9371. return CaretPosition$1(container, ++offset);
  9372. }
  9373. node = container;
  9374. } else {
  9375. if (isBackwards(direction) && offset > 0) {
  9376. nextNode = nodeAtIndex(container, offset - 1);
  9377. if (isCaretCandidate$3(nextNode)) {
  9378. if (!isAtomic$1(nextNode)) {
  9379. innerNode = findNode(nextNode, direction, isEditableCaretCandidate$1, nextNode);
  9380. if (innerNode) {
  9381. if (isText$7(innerNode)) {
  9382. return CaretPosition$1(innerNode, innerNode.data.length);
  9383. }
  9384. return CaretPosition$1.after(innerNode);
  9385. }
  9386. }
  9387. if (isText$7(nextNode)) {
  9388. return CaretPosition$1(nextNode, nextNode.data.length);
  9389. }
  9390. return CaretPosition$1.before(nextNode);
  9391. }
  9392. }
  9393. if (isForwards(direction) && offset < container.childNodes.length) {
  9394. nextNode = nodeAtIndex(container, offset);
  9395. if (isCaretCandidate$3(nextNode)) {
  9396. if (isBr$4(nextNode)) {
  9397. return moveForwardFromBr(root, nextNode);
  9398. }
  9399. if (!isAtomic$1(nextNode)) {
  9400. innerNode = findNode(nextNode, direction, isEditableCaretCandidate$1, nextNode);
  9401. if (innerNode) {
  9402. if (isText$7(innerNode)) {
  9403. return CaretPosition$1(innerNode, 0);
  9404. }
  9405. return CaretPosition$1.before(innerNode);
  9406. }
  9407. }
  9408. if (isText$7(nextNode)) {
  9409. return CaretPosition$1(nextNode, 0);
  9410. }
  9411. return CaretPosition$1.after(nextNode);
  9412. }
  9413. }
  9414. node = nextNode ? nextNode : caretPosition.getNode();
  9415. }
  9416. if (isForwards(direction) && caretPosition.isAtEnd() || isBackwards(direction) && caretPosition.isAtStart()) {
  9417. node = findNode(node, direction, constant(true), root, true);
  9418. if (isEditableCaretCandidate$1(node, root)) {
  9419. return getCaretCandidatePosition(direction, node);
  9420. }
  9421. }
  9422. nextNode = findNode(node, direction, isEditableCaretCandidate$1, root);
  9423. rootContentEditableFalseElm = ArrUtils.last(filter(getParents(container, root), isContentEditableFalse$5));
  9424. if (rootContentEditableFalseElm && (!nextNode || !rootContentEditableFalseElm.contains(nextNode))) {
  9425. if (isForwards(direction)) {
  9426. caretPosition = CaretPosition$1.after(rootContentEditableFalseElm);
  9427. } else {
  9428. caretPosition = CaretPosition$1.before(rootContentEditableFalseElm);
  9429. }
  9430. return caretPosition;
  9431. }
  9432. if (nextNode) {
  9433. return getCaretCandidatePosition(direction, nextNode);
  9434. }
  9435. return null;
  9436. };
  9437. var CaretWalker = function (root) {
  9438. return {
  9439. next: function (caretPosition) {
  9440. return findCaretPosition(HDirection.Forwards, caretPosition, root);
  9441. },
  9442. prev: function (caretPosition) {
  9443. return findCaretPosition(HDirection.Backwards, caretPosition, root);
  9444. }
  9445. };
  9446. };
  9447. var walkToPositionIn = function (forward, root, start) {
  9448. var position = forward ? CaretPosition$1.before(start) : CaretPosition$1.after(start);
  9449. return fromPosition(forward, root, position);
  9450. };
  9451. var afterElement = function (node) {
  9452. return NodeType.isBr(node) ? CaretPosition$1.before(node) : CaretPosition$1.after(node);
  9453. };
  9454. var isBeforeOrStart = function (position) {
  9455. if (CaretPosition$1.isTextPosition(position)) {
  9456. return position.offset() === 0;
  9457. } else {
  9458. return isCaretCandidate(position.getNode());
  9459. }
  9460. };
  9461. var isAfterOrEnd = function (position) {
  9462. if (CaretPosition$1.isTextPosition(position)) {
  9463. var container = position.container();
  9464. return position.offset() === container.data.length;
  9465. } else {
  9466. return isCaretCandidate(position.getNode(true));
  9467. }
  9468. };
  9469. var isBeforeAfterSameElement = function (from, to) {
  9470. return !CaretPosition$1.isTextPosition(from) && !CaretPosition$1.isTextPosition(to) && from.getNode() === to.getNode(true);
  9471. };
  9472. var isAtBr = function (position) {
  9473. return !CaretPosition$1.isTextPosition(position) && NodeType.isBr(position.getNode());
  9474. };
  9475. var shouldSkipPosition = function (forward, from, to) {
  9476. if (forward) {
  9477. return !isBeforeAfterSameElement(from, to) && !isAtBr(from) && isAfterOrEnd(from) && isBeforeOrStart(to);
  9478. } else {
  9479. return !isBeforeAfterSameElement(to, from) && isBeforeOrStart(from) && isAfterOrEnd(to);
  9480. }
  9481. };
  9482. var fromPosition = function (forward, root, pos) {
  9483. var walker = CaretWalker(root);
  9484. return Option.from(forward ? walker.next(pos) : walker.prev(pos));
  9485. };
  9486. var navigate = function (forward, root, from) {
  9487. return fromPosition(forward, root, from).bind(function (to) {
  9488. if (isInSameBlock(from, to, root) && shouldSkipPosition(forward, from, to)) {
  9489. return fromPosition(forward, root, to);
  9490. } else {
  9491. return Option.some(to);
  9492. }
  9493. });
  9494. };
  9495. var navigateIgnore = function (forward, root, from, ignoreFilter) {
  9496. return navigate(forward, root, from).bind(function (pos) {
  9497. return ignoreFilter(pos) ? navigateIgnore(forward, root, pos, ignoreFilter) : Option.some(pos);
  9498. });
  9499. };
  9500. var positionIn = function (forward, element) {
  9501. var startNode = forward ? element.firstChild : element.lastChild;
  9502. if (NodeType.isText(startNode)) {
  9503. return Option.some(CaretPosition$1(startNode, forward ? 0 : startNode.data.length));
  9504. } else if (startNode) {
  9505. if (isCaretCandidate(startNode)) {
  9506. return Option.some(forward ? CaretPosition$1.before(startNode) : afterElement(startNode));
  9507. } else {
  9508. return walkToPositionIn(forward, element, startNode);
  9509. }
  9510. } else {
  9511. return Option.none();
  9512. }
  9513. };
  9514. var nextPosition = curry(fromPosition, true);
  9515. var prevPosition = curry(fromPosition, false);
  9516. var CaretFinder = {
  9517. fromPosition: fromPosition,
  9518. nextPosition: nextPosition,
  9519. prevPosition: prevPosition,
  9520. navigate: navigate,
  9521. navigateIgnore: navigateIgnore,
  9522. positionIn: positionIn,
  9523. firstPositionIn: curry(positionIn, true),
  9524. lastPositionIn: curry(positionIn, false)
  9525. };
  9526. var isStringPathBookmark = function (bookmark) {
  9527. return typeof bookmark.start === 'string';
  9528. };
  9529. var isRangeBookmark = function (bookmark) {
  9530. return bookmark.hasOwnProperty('rng');
  9531. };
  9532. var isIdBookmark = function (bookmark) {
  9533. return bookmark.hasOwnProperty('id');
  9534. };
  9535. var isIndexBookmark = function (bookmark) {
  9536. return bookmark.hasOwnProperty('name');
  9537. };
  9538. var isPathBookmark = function (bookmark) {
  9539. return Tools.isArray(bookmark.start);
  9540. };
  9541. var addBogus = function (dom, node) {
  9542. if (NodeType.isElement(node) && dom.isBlock(node) && !node.innerHTML && !Env.ie) {
  9543. node.innerHTML = '<br data-mce-bogus="1" />';
  9544. }
  9545. return node;
  9546. };
  9547. var resolveCaretPositionBookmark = function (dom, bookmark) {
  9548. var rng, pos;
  9549. rng = dom.createRng();
  9550. pos = resolve$1(dom.getRoot(), bookmark.start);
  9551. rng.setStart(pos.container(), pos.offset());
  9552. pos = resolve$1(dom.getRoot(), bookmark.end);
  9553. rng.setEnd(pos.container(), pos.offset());
  9554. return rng;
  9555. };
  9556. var insertZwsp = function (node, rng) {
  9557. var textNode = node.ownerDocument.createTextNode(Zwsp.ZWSP);
  9558. node.appendChild(textNode);
  9559. rng.setStart(textNode, 0);
  9560. rng.setEnd(textNode, 0);
  9561. };
  9562. var isEmpty = function (node) {
  9563. return node.hasChildNodes() === false;
  9564. };
  9565. var tryFindRangePosition = function (node, rng) {
  9566. return CaretFinder.lastPositionIn(node).fold(function () {
  9567. return false;
  9568. }, function (pos) {
  9569. rng.setStart(pos.container(), pos.offset());
  9570. rng.setEnd(pos.container(), pos.offset());
  9571. return true;
  9572. });
  9573. };
  9574. var padEmptyCaretContainer = function (root, node, rng) {
  9575. if (isEmpty(node) && getParentCaretContainer(root, node)) {
  9576. insertZwsp(node, rng);
  9577. return true;
  9578. } else {
  9579. return false;
  9580. }
  9581. };
  9582. var setEndPoint = function (dom, start, bookmark, rng) {
  9583. var point = bookmark[start ? 'start' : 'end'];
  9584. var i, node, offset, children;
  9585. var root = dom.getRoot();
  9586. if (point) {
  9587. offset = point[0];
  9588. for (node = root, i = point.length - 1; i >= 1; i--) {
  9589. children = node.childNodes;
  9590. if (padEmptyCaretContainer(root, node, rng)) {
  9591. return true;
  9592. }
  9593. if (point[i] > children.length - 1) {
  9594. if (padEmptyCaretContainer(root, node, rng)) {
  9595. return true;
  9596. }
  9597. return tryFindRangePosition(node, rng);
  9598. }
  9599. node = children[point[i]];
  9600. }
  9601. if (node.nodeType === 3) {
  9602. offset = Math.min(point[0], node.nodeValue.length);
  9603. }
  9604. if (node.nodeType === 1) {
  9605. offset = Math.min(point[0], node.childNodes.length);
  9606. }
  9607. if (start) {
  9608. rng.setStart(node, offset);
  9609. } else {
  9610. rng.setEnd(node, offset);
  9611. }
  9612. }
  9613. return true;
  9614. };
  9615. var isValidTextNode = function (node) {
  9616. return NodeType.isText(node) && node.data.length > 0;
  9617. };
  9618. var restoreEndPoint = function (dom, suffix, bookmark) {
  9619. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev;
  9620. var keep = bookmark.keep;
  9621. var container, offset;
  9622. if (marker) {
  9623. node = marker.parentNode;
  9624. if (suffix === 'start') {
  9625. if (!keep) {
  9626. idx = dom.nodeIndex(marker);
  9627. } else {
  9628. if (marker.hasChildNodes()) {
  9629. node = marker.firstChild;
  9630. idx = 1;
  9631. } else if (isValidTextNode(marker.nextSibling)) {
  9632. node = marker.nextSibling;
  9633. idx = 0;
  9634. } else if (isValidTextNode(marker.previousSibling)) {
  9635. node = marker.previousSibling;
  9636. idx = marker.previousSibling.data.length;
  9637. } else {
  9638. node = marker.parentNode;
  9639. idx = dom.nodeIndex(marker) + 1;
  9640. }
  9641. }
  9642. container = node;
  9643. offset = idx;
  9644. } else {
  9645. if (!keep) {
  9646. idx = dom.nodeIndex(marker);
  9647. } else {
  9648. if (marker.hasChildNodes()) {
  9649. node = marker.firstChild;
  9650. idx = 1;
  9651. } else if (isValidTextNode(marker.previousSibling)) {
  9652. node = marker.previousSibling;
  9653. idx = marker.previousSibling.data.length;
  9654. } else {
  9655. node = marker.parentNode;
  9656. idx = dom.nodeIndex(marker);
  9657. }
  9658. }
  9659. container = node;
  9660. offset = idx;
  9661. }
  9662. if (!keep) {
  9663. prev = marker.previousSibling;
  9664. next = marker.nextSibling;
  9665. Tools.each(Tools.grep(marker.childNodes), function (node) {
  9666. if (NodeType.isText(node)) {
  9667. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  9668. }
  9669. });
  9670. while (marker = dom.get(bookmark.id + '_' + suffix)) {
  9671. dom.remove(marker, true);
  9672. }
  9673. if (prev && next && prev.nodeType === next.nodeType && NodeType.isText(prev) && !Env.opera) {
  9674. idx = prev.nodeValue.length;
  9675. prev.appendData(next.nodeValue);
  9676. dom.remove(next);
  9677. if (suffix === 'start') {
  9678. container = prev;
  9679. offset = idx;
  9680. } else {
  9681. container = prev;
  9682. offset = idx;
  9683. }
  9684. }
  9685. }
  9686. return Option.some(CaretPosition$1(container, offset));
  9687. } else {
  9688. return Option.none();
  9689. }
  9690. };
  9691. var resolvePaths = function (dom, bookmark) {
  9692. var rng = dom.createRng();
  9693. if (setEndPoint(dom, true, bookmark, rng) && setEndPoint(dom, false, bookmark, rng)) {
  9694. return Option.some(rng);
  9695. } else {
  9696. return Option.none();
  9697. }
  9698. };
  9699. var resolveId = function (dom, bookmark) {
  9700. var startPos = restoreEndPoint(dom, 'start', bookmark);
  9701. var endPos = restoreEndPoint(dom, 'end', bookmark);
  9702. return lift2(startPos, endPos.or(startPos), function (spos, epos) {
  9703. var rng = dom.createRng();
  9704. rng.setStart(addBogus(dom, spos.container()), spos.offset());
  9705. rng.setEnd(addBogus(dom, epos.container()), epos.offset());
  9706. return rng;
  9707. });
  9708. };
  9709. var resolveIndex$1 = function (dom, bookmark) {
  9710. return Option.from(dom.select(bookmark.name)[bookmark.index]).map(function (elm) {
  9711. var rng = dom.createRng();
  9712. rng.selectNode(elm);
  9713. return rng;
  9714. });
  9715. };
  9716. var resolve$2 = function (selection, bookmark) {
  9717. var dom = selection.dom;
  9718. if (bookmark) {
  9719. if (isPathBookmark(bookmark)) {
  9720. return resolvePaths(dom, bookmark);
  9721. } else if (isStringPathBookmark(bookmark)) {
  9722. return Option.some(resolveCaretPositionBookmark(dom, bookmark));
  9723. } else if (isIdBookmark(bookmark)) {
  9724. return resolveId(dom, bookmark);
  9725. } else if (isIndexBookmark(bookmark)) {
  9726. return resolveIndex$1(dom, bookmark);
  9727. } else if (isRangeBookmark(bookmark)) {
  9728. return Option.some(bookmark.rng);
  9729. }
  9730. }
  9731. return Option.none();
  9732. };
  9733. var ResolveBookmark = { resolve: resolve$2 };
  9734. var getBookmark$1 = function (selection, type, normalized) {
  9735. return GetBookmark.getBookmark(selection, type, normalized);
  9736. };
  9737. var moveToBookmark = function (selection, bookmark) {
  9738. ResolveBookmark.resolve(selection, bookmark).each(function (rng) {
  9739. selection.setRng(rng);
  9740. });
  9741. };
  9742. var isBookmarkNode$1 = function (node) {
  9743. return NodeType.isElement(node) && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark';
  9744. };
  9745. var Bookmarks = {
  9746. getBookmark: getBookmark$1,
  9747. moveToBookmark: moveToBookmark,
  9748. isBookmarkNode: isBookmarkNode$1
  9749. };
  9750. var isInlineBlock = function (node) {
  9751. return node && /^(IMG)$/.test(node.nodeName);
  9752. };
  9753. var moveStart = function (dom, selection, rng) {
  9754. var offset = rng.startOffset;
  9755. var container = rng.startContainer, walker, node, nodes;
  9756. if (rng.startContainer === rng.endContainer) {
  9757. if (isInlineBlock(rng.startContainer.childNodes[rng.startOffset])) {
  9758. return;
  9759. }
  9760. }
  9761. if (container.nodeType === 1) {
  9762. nodes = container.childNodes;
  9763. if (offset < nodes.length) {
  9764. container = nodes[offset];
  9765. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  9766. } else {
  9767. container = nodes[nodes.length - 1];
  9768. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  9769. walker.next(true);
  9770. }
  9771. for (node = walker.current(); node; node = walker.next()) {
  9772. if (node.nodeType === 3 && !isWhiteSpaceNode(node)) {
  9773. rng.setStart(node, 0);
  9774. selection.setRng(rng);
  9775. return;
  9776. }
  9777. }
  9778. }
  9779. };
  9780. var getNonWhiteSpaceSibling = function (node, next, inc) {
  9781. if (node) {
  9782. next = next ? 'nextSibling' : 'previousSibling';
  9783. for (node = inc ? node : node[next]; node; node = node[next]) {
  9784. if (node.nodeType === 1 || !isWhiteSpaceNode(node)) {
  9785. return node;
  9786. }
  9787. }
  9788. }
  9789. };
  9790. var isTextBlock$1 = function (editor, name) {
  9791. if (name.nodeType) {
  9792. name = name.nodeName;
  9793. }
  9794. return !!editor.schema.getTextBlockElements()[name.toLowerCase()];
  9795. };
  9796. var isValid = function (ed, parent, child) {
  9797. return ed.schema.isValidChild(parent, child);
  9798. };
  9799. var isWhiteSpaceNode = function (node) {
  9800. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  9801. };
  9802. var replaceVars = function (value, vars) {
  9803. if (typeof value !== 'string') {
  9804. value = value(vars);
  9805. } else if (vars) {
  9806. value = value.replace(/%(\w+)/g, function (str, name) {
  9807. return vars[name] || str;
  9808. });
  9809. }
  9810. return value;
  9811. };
  9812. var isEq = function (str1, str2) {
  9813. str1 = str1 || '';
  9814. str2 = str2 || '';
  9815. str1 = '' + (str1.nodeName || str1);
  9816. str2 = '' + (str2.nodeName || str2);
  9817. return str1.toLowerCase() === str2.toLowerCase();
  9818. };
  9819. var normalizeStyleValue = function (dom, value, name) {
  9820. if (name === 'color' || name === 'backgroundColor') {
  9821. value = dom.toHex(value);
  9822. }
  9823. if (name === 'fontWeight' && value === 700) {
  9824. value = 'bold';
  9825. }
  9826. if (name === 'fontFamily') {
  9827. value = value.replace(/[\'\"]/g, '').replace(/,\s+/g, ',');
  9828. }
  9829. return '' + value;
  9830. };
  9831. var getStyle = function (dom, node, name) {
  9832. return normalizeStyleValue(dom, dom.getStyle(node, name), name);
  9833. };
  9834. var getTextDecoration = function (dom, node) {
  9835. var decoration;
  9836. dom.getParent(node, function (n) {
  9837. decoration = dom.getStyle(n, 'text-decoration');
  9838. return decoration && decoration !== 'none';
  9839. });
  9840. return decoration;
  9841. };
  9842. var getParents$1 = function (dom, node, selector) {
  9843. return dom.getParents(node, selector, dom.getRoot());
  9844. };
  9845. var FormatUtils = {
  9846. isInlineBlock: isInlineBlock,
  9847. moveStart: moveStart,
  9848. getNonWhiteSpaceSibling: getNonWhiteSpaceSibling,
  9849. isTextBlock: isTextBlock$1,
  9850. isValid: isValid,
  9851. isWhiteSpaceNode: isWhiteSpaceNode,
  9852. replaceVars: replaceVars,
  9853. isEq: isEq,
  9854. normalizeStyleValue: normalizeStyleValue,
  9855. getStyle: getStyle,
  9856. getTextDecoration: getTextDecoration,
  9857. getParents: getParents$1
  9858. };
  9859. var isBookmarkNode$2 = Bookmarks.isBookmarkNode;
  9860. var getParents$2 = FormatUtils.getParents, isWhiteSpaceNode$1 = FormatUtils.isWhiteSpaceNode, isTextBlock$2 = FormatUtils.isTextBlock;
  9861. var findLeaf = function (node, offset) {
  9862. if (typeof offset === 'undefined') {
  9863. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  9864. }
  9865. while (node && node.hasChildNodes()) {
  9866. node = node.childNodes[offset];
  9867. if (node) {
  9868. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  9869. }
  9870. }
  9871. return {
  9872. node: node,
  9873. offset: offset
  9874. };
  9875. };
  9876. var excludeTrailingWhitespace = function (endContainer, endOffset) {
  9877. var leaf = findLeaf(endContainer, endOffset);
  9878. if (leaf.node) {
  9879. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling) {
  9880. leaf = findLeaf(leaf.node.previousSibling);
  9881. }
  9882. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 && leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  9883. if (leaf.offset > 1) {
  9884. endContainer = leaf.node;
  9885. endContainer.splitText(leaf.offset - 1);
  9886. }
  9887. }
  9888. }
  9889. return endContainer;
  9890. };
  9891. var isBogusBr = function (node) {
  9892. return node.nodeName === 'BR' && node.getAttribute('data-mce-bogus') && !node.nextSibling;
  9893. };
  9894. var findParentContentEditable = function (dom, node) {
  9895. var parent = node;
  9896. while (parent) {
  9897. if (parent.nodeType === 1 && dom.getContentEditable(parent)) {
  9898. return dom.getContentEditable(parent) === 'false' ? parent : node;
  9899. }
  9900. parent = parent.parentNode;
  9901. }
  9902. return node;
  9903. };
  9904. var findSpace = function (start, remove, node, offset) {
  9905. var pos, pos2;
  9906. var str = node.nodeValue;
  9907. if (typeof offset === 'undefined') {
  9908. offset = start ? str.length : 0;
  9909. }
  9910. if (start) {
  9911. pos = str.lastIndexOf(' ', offset);
  9912. pos2 = str.lastIndexOf('\xA0', offset);
  9913. pos = pos > pos2 ? pos : pos2;
  9914. if (pos !== -1 && !remove && (pos < offset || !start) && pos <= str.length) {
  9915. pos++;
  9916. }
  9917. } else {
  9918. pos = str.indexOf(' ', offset);
  9919. pos2 = str.indexOf('\xA0', offset);
  9920. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  9921. }
  9922. return pos;
  9923. };
  9924. var findWordEndPoint = function (dom, body, container, offset, start, remove) {
  9925. var node, pos, lastTextNode;
  9926. if (container.nodeType === 3) {
  9927. pos = findSpace(start, remove, container, offset);
  9928. if (pos !== -1) {
  9929. return {
  9930. container: container,
  9931. offset: pos
  9932. };
  9933. }
  9934. lastTextNode = container;
  9935. }
  9936. var walker = new TreeWalker(container, dom.getParent(container, dom.isBlock) || body);
  9937. while (node = walker[start ? 'prev' : 'next']()) {
  9938. if (node.nodeType === 3 && !isBookmarkNode$2(node.parentNode)) {
  9939. lastTextNode = node;
  9940. pos = findSpace(start, remove, node);
  9941. if (pos !== -1) {
  9942. return {
  9943. container: node,
  9944. offset: pos
  9945. };
  9946. }
  9947. } else if (dom.isBlock(node) || FormatUtils.isEq(node, 'BR')) {
  9948. break;
  9949. }
  9950. }
  9951. if (lastTextNode) {
  9952. if (start) {
  9953. offset = 0;
  9954. } else {
  9955. offset = lastTextNode.length;
  9956. }
  9957. return {
  9958. container: lastTextNode,
  9959. offset: offset
  9960. };
  9961. }
  9962. };
  9963. var findSelectorEndPoint = function (dom, format, rng, container, siblingName) {
  9964. var parents, i, y, curFormat;
  9965. if (container.nodeType === 3 && container.nodeValue.length === 0 && container[siblingName]) {
  9966. container = container[siblingName];
  9967. }
  9968. parents = getParents$2(dom, container);
  9969. for (i = 0; i < parents.length; i++) {
  9970. for (y = 0; y < format.length; y++) {
  9971. curFormat = format[y];
  9972. if ('collapsed' in curFormat && curFormat.collapsed !== rng.collapsed) {
  9973. continue;
  9974. }
  9975. if (dom.is(parents[i], curFormat.selector)) {
  9976. return parents[i];
  9977. }
  9978. }
  9979. }
  9980. return container;
  9981. };
  9982. var findBlockEndPoint = function (editor, format, container, siblingName) {
  9983. var node;
  9984. var dom = editor.dom;
  9985. var root = dom.getRoot();
  9986. if (!format[0].wrapper) {
  9987. node = dom.getParent(container, format[0].block, root);
  9988. }
  9989. if (!node) {
  9990. var scopeRoot = dom.getParent(container, 'LI,TD,TH');
  9991. node = dom.getParent(container.nodeType === 3 ? container.parentNode : container, function (node) {
  9992. return node !== root && isTextBlock$2(editor, node);
  9993. }, scopeRoot);
  9994. }
  9995. if (node && format[0].wrapper) {
  9996. node = getParents$2(dom, node, 'ul,ol').reverse()[0] || node;
  9997. }
  9998. if (!node) {
  9999. node = container;
  10000. while (node[siblingName] && !dom.isBlock(node[siblingName])) {
  10001. node = node[siblingName];
  10002. if (FormatUtils.isEq(node, 'br')) {
  10003. break;
  10004. }
  10005. }
  10006. }
  10007. return node || container;
  10008. };
  10009. var findParentContainer = function (dom, format, startContainer, startOffset, endContainer, endOffset, start) {
  10010. var container, parent, sibling, siblingName, root;
  10011. container = parent = start ? startContainer : endContainer;
  10012. siblingName = start ? 'previousSibling' : 'nextSibling';
  10013. root = dom.getRoot();
  10014. if (container.nodeType === 3 && !isWhiteSpaceNode$1(container)) {
  10015. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  10016. return container;
  10017. }
  10018. }
  10019. while (true) {
  10020. if (!format[0].block_expand && dom.isBlock(parent)) {
  10021. return parent;
  10022. }
  10023. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  10024. if (!isBookmarkNode$2(sibling) && !isWhiteSpaceNode$1(sibling) && !isBogusBr(sibling)) {
  10025. return parent;
  10026. }
  10027. }
  10028. if (parent === root || parent.parentNode === root) {
  10029. container = parent;
  10030. break;
  10031. }
  10032. parent = parent.parentNode;
  10033. }
  10034. return container;
  10035. };
  10036. var expandRng = function (editor, rng, format, remove) {
  10037. var endPoint, startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
  10038. var dom = editor.dom;
  10039. if (startContainer.nodeType === 1 && startContainer.hasChildNodes()) {
  10040. startContainer = getNode(startContainer, startOffset);
  10041. if (startContainer.nodeType === 3) {
  10042. startOffset = 0;
  10043. }
  10044. }
  10045. if (endContainer.nodeType === 1 && endContainer.hasChildNodes()) {
  10046. endContainer = getNode(endContainer, rng.collapsed ? endOffset : endOffset - 1);
  10047. if (endContainer.nodeType === 3) {
  10048. endOffset = endContainer.nodeValue.length;
  10049. }
  10050. }
  10051. startContainer = findParentContentEditable(dom, startContainer);
  10052. endContainer = findParentContentEditable(dom, endContainer);
  10053. if (isBookmarkNode$2(startContainer.parentNode) || isBookmarkNode$2(startContainer)) {
  10054. startContainer = isBookmarkNode$2(startContainer) ? startContainer : startContainer.parentNode;
  10055. if (rng.collapsed) {
  10056. startContainer = startContainer.previousSibling || startContainer;
  10057. } else {
  10058. startContainer = startContainer.nextSibling || startContainer;
  10059. }
  10060. if (startContainer.nodeType === 3) {
  10061. startOffset = rng.collapsed ? startContainer.length : 0;
  10062. }
  10063. }
  10064. if (isBookmarkNode$2(endContainer.parentNode) || isBookmarkNode$2(endContainer)) {
  10065. endContainer = isBookmarkNode$2(endContainer) ? endContainer : endContainer.parentNode;
  10066. if (rng.collapsed) {
  10067. endContainer = endContainer.nextSibling || endContainer;
  10068. } else {
  10069. endContainer = endContainer.previousSibling || endContainer;
  10070. }
  10071. if (endContainer.nodeType === 3) {
  10072. endOffset = rng.collapsed ? 0 : endContainer.length;
  10073. }
  10074. }
  10075. if (rng.collapsed) {
  10076. endPoint = findWordEndPoint(dom, editor.getBody(), startContainer, startOffset, true, remove);
  10077. if (endPoint) {
  10078. startContainer = endPoint.container;
  10079. startOffset = endPoint.offset;
  10080. }
  10081. endPoint = findWordEndPoint(dom, editor.getBody(), endContainer, endOffset, false, remove);
  10082. if (endPoint) {
  10083. endContainer = endPoint.container;
  10084. endOffset = endPoint.offset;
  10085. }
  10086. }
  10087. if (format[0].inline) {
  10088. endContainer = remove ? endContainer : excludeTrailingWhitespace(endContainer, endOffset);
  10089. }
  10090. if (format[0].inline || format[0].block_expand) {
  10091. if (!format[0].inline || (startContainer.nodeType !== 3 || startOffset === 0)) {
  10092. startContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, true);
  10093. }
  10094. if (!format[0].inline || (endContainer.nodeType !== 3 || endOffset === endContainer.nodeValue.length)) {
  10095. endContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, false);
  10096. }
  10097. }
  10098. if (format[0].selector && format[0].expand !== false && !format[0].inline) {
  10099. startContainer = findSelectorEndPoint(dom, format, rng, startContainer, 'previousSibling');
  10100. endContainer = findSelectorEndPoint(dom, format, rng, endContainer, 'nextSibling');
  10101. }
  10102. if (format[0].block || format[0].selector) {
  10103. startContainer = findBlockEndPoint(editor, format, startContainer, 'previousSibling');
  10104. endContainer = findBlockEndPoint(editor, format, endContainer, 'nextSibling');
  10105. if (format[0].block) {
  10106. if (!dom.isBlock(startContainer)) {
  10107. startContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, true);
  10108. }
  10109. if (!dom.isBlock(endContainer)) {
  10110. endContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, false);
  10111. }
  10112. }
  10113. }
  10114. if (startContainer.nodeType === 1) {
  10115. startOffset = dom.nodeIndex(startContainer);
  10116. startContainer = startContainer.parentNode;
  10117. }
  10118. if (endContainer.nodeType === 1) {
  10119. endOffset = dom.nodeIndex(endContainer) + 1;
  10120. endContainer = endContainer.parentNode;
  10121. }
  10122. return {
  10123. startContainer: startContainer,
  10124. startOffset: startOffset,
  10125. endContainer: endContainer,
  10126. endOffset: endOffset
  10127. };
  10128. };
  10129. var ExpandRange = { expandRng: expandRng };
  10130. var each$8 = Tools.each;
  10131. var getEndChild = function (container, index) {
  10132. var childNodes = container.childNodes;
  10133. index--;
  10134. if (index > childNodes.length - 1) {
  10135. index = childNodes.length - 1;
  10136. } else if (index < 0) {
  10137. index = 0;
  10138. }
  10139. return childNodes[index] || container;
  10140. };
  10141. var walk$1 = function (dom, rng, callback) {
  10142. var startContainer = rng.startContainer;
  10143. var startOffset = rng.startOffset;
  10144. var endContainer = rng.endContainer;
  10145. var endOffset = rng.endOffset;
  10146. var ancestor;
  10147. var startPoint;
  10148. var endPoint;
  10149. var node;
  10150. var parent;
  10151. var siblings;
  10152. var nodes;
  10153. nodes = dom.select('td[data-mce-selected],th[data-mce-selected]');
  10154. if (nodes.length > 0) {
  10155. each$8(nodes, function (node) {
  10156. callback([node]);
  10157. });
  10158. return;
  10159. }
  10160. var exclude = function (nodes) {
  10161. var node;
  10162. node = nodes[0];
  10163. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  10164. nodes.splice(0, 1);
  10165. }
  10166. node = nodes[nodes.length - 1];
  10167. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  10168. nodes.splice(nodes.length - 1, 1);
  10169. }
  10170. return nodes;
  10171. };
  10172. var collectSiblings = function (node, name, endNode) {
  10173. var siblings = [];
  10174. for (; node && node !== endNode; node = node[name]) {
  10175. siblings.push(node);
  10176. }
  10177. return siblings;
  10178. };
  10179. var findEndPoint = function (node, root) {
  10180. do {
  10181. if (node.parentNode === root) {
  10182. return node;
  10183. }
  10184. node = node.parentNode;
  10185. } while (node);
  10186. };
  10187. var walkBoundary = function (startNode, endNode, next) {
  10188. var siblingName = next ? 'nextSibling' : 'previousSibling';
  10189. for (node = startNode, parent = node.parentNode; node && node !== endNode; node = parent) {
  10190. parent = node.parentNode;
  10191. siblings = collectSiblings(node === startNode ? node : node[siblingName], siblingName);
  10192. if (siblings.length) {
  10193. if (!next) {
  10194. siblings.reverse();
  10195. }
  10196. callback(exclude(siblings));
  10197. }
  10198. }
  10199. };
  10200. if (startContainer.nodeType === 1 && startContainer.hasChildNodes()) {
  10201. startContainer = startContainer.childNodes[startOffset];
  10202. }
  10203. if (endContainer.nodeType === 1 && endContainer.hasChildNodes()) {
  10204. endContainer = getEndChild(endContainer, endOffset);
  10205. }
  10206. if (startContainer === endContainer) {
  10207. return callback(exclude([startContainer]));
  10208. }
  10209. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  10210. for (node = startContainer; node; node = node.parentNode) {
  10211. if (node === endContainer) {
  10212. return walkBoundary(startContainer, ancestor, true);
  10213. }
  10214. if (node === ancestor) {
  10215. break;
  10216. }
  10217. }
  10218. for (node = endContainer; node; node = node.parentNode) {
  10219. if (node === startContainer) {
  10220. return walkBoundary(endContainer, ancestor);
  10221. }
  10222. if (node === ancestor) {
  10223. break;
  10224. }
  10225. }
  10226. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  10227. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  10228. walkBoundary(startContainer, startPoint, true);
  10229. siblings = collectSiblings(startPoint === startContainer ? startPoint : startPoint.nextSibling, 'nextSibling', endPoint === endContainer ? endPoint.nextSibling : endPoint);
  10230. if (siblings.length) {
  10231. callback(exclude(siblings));
  10232. }
  10233. walkBoundary(endContainer, endPoint);
  10234. };
  10235. var RangeWalk = { walk: walk$1 };
  10236. var zeroWidth = function () {
  10237. return '\uFEFF';
  10238. };
  10239. function NodeValue (is, name) {
  10240. var get = function (element) {
  10241. if (!is(element)) {
  10242. throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
  10243. }
  10244. return getOption(element).getOr('');
  10245. };
  10246. var getOption = function (element) {
  10247. return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
  10248. };
  10249. var set = function (element, value) {
  10250. if (!is(element)) {
  10251. throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
  10252. }
  10253. element.dom().nodeValue = value;
  10254. };
  10255. return {
  10256. get: get,
  10257. getOption: getOption,
  10258. set: set
  10259. };
  10260. }
  10261. var api = NodeValue(isText$1, 'text');
  10262. var get$6 = function (element) {
  10263. return api.get(element);
  10264. };
  10265. var isZeroWidth = function (elem) {
  10266. return isText$1(elem) && get$6(elem) === zeroWidth();
  10267. };
  10268. var context = function (editor, elem, wrapName, nodeName) {
  10269. return parent(elem).fold(function () {
  10270. return 'skipping';
  10271. }, function (parent) {
  10272. if (nodeName === 'br' || isZeroWidth(elem)) {
  10273. return 'valid';
  10274. } else if (isAnnotation(elem)) {
  10275. return 'existing';
  10276. } else if (isCaretNode(elem)) {
  10277. return 'caret';
  10278. } else if (!FormatUtils.isValid(editor, wrapName, nodeName) || !FormatUtils.isValid(editor, name(parent), wrapName)) {
  10279. return 'invalid-child';
  10280. } else {
  10281. return 'valid';
  10282. }
  10283. });
  10284. };
  10285. var shouldApplyToTrailingSpaces = function (rng) {
  10286. return rng.startContainer.nodeType === 3 && rng.startContainer.nodeValue.length >= rng.startOffset && rng.startContainer.nodeValue[rng.startOffset] === '\xA0';
  10287. };
  10288. var applyWordGrab = function (editor, rng) {
  10289. var r = ExpandRange.expandRng(editor, rng, [{ inline: true }], shouldApplyToTrailingSpaces(rng));
  10290. rng.setStart(r.startContainer, r.startOffset);
  10291. rng.setEnd(r.endContainer, r.endOffset);
  10292. editor.selection.setRng(rng);
  10293. };
  10294. var makeAnnotation = function (eDoc, _a, annotationName, decorate) {
  10295. var _b = _a.uid, uid = _b === void 0 ? generate('mce-annotation') : _b, data = __rest(_a, ['uid']);
  10296. var master = Element.fromTag('span', eDoc);
  10297. add$3(master, annotation());
  10298. set(master, '' + dataAnnotationId(), uid);
  10299. set(master, '' + dataAnnotation(), annotationName);
  10300. var _c = decorate(uid, data), _d = _c.attributes, attributes = _d === void 0 ? {} : _d, _e = _c.classes, classes = _e === void 0 ? [] : _e;
  10301. setAll(master, attributes);
  10302. add$4(master, classes);
  10303. return master;
  10304. };
  10305. var annotate = function (editor, rng, annotationName, decorate, data) {
  10306. var newWrappers = [];
  10307. var master = makeAnnotation(editor.getDoc(), data, annotationName, decorate);
  10308. var wrapper = Cell(Option.none());
  10309. var finishWrapper = function () {
  10310. wrapper.set(Option.none());
  10311. };
  10312. var getOrOpenWrapper = function () {
  10313. return wrapper.get().getOrThunk(function () {
  10314. var nu = shallow(master);
  10315. newWrappers.push(nu);
  10316. wrapper.set(Option.some(nu));
  10317. return nu;
  10318. });
  10319. };
  10320. var processElements = function (elems) {
  10321. each(elems, processElement);
  10322. };
  10323. var processElement = function (elem) {
  10324. var ctx = context(editor, elem, 'span', name(elem));
  10325. switch (ctx) {
  10326. case 'invalid-child': {
  10327. finishWrapper();
  10328. var children$1 = children(elem);
  10329. processElements(children$1);
  10330. finishWrapper();
  10331. break;
  10332. }
  10333. case 'valid': {
  10334. var w = getOrOpenWrapper();
  10335. wrap$1(elem, w);
  10336. break;
  10337. }
  10338. case 'skipping':
  10339. case 'existing':
  10340. case 'caret':
  10341. }
  10342. };
  10343. var processNodes = function (nodes) {
  10344. var elems = map(nodes, Element.fromDom);
  10345. processElements(elems);
  10346. };
  10347. RangeWalk.walk(editor.dom, rng, function (nodes) {
  10348. finishWrapper();
  10349. processNodes(nodes);
  10350. });
  10351. return newWrappers;
  10352. };
  10353. var annotateWithBookmark = function (editor, name, settings, data) {
  10354. editor.undoManager.transact(function () {
  10355. var initialRng = editor.selection.getRng();
  10356. if (initialRng.collapsed) {
  10357. applyWordGrab(editor, initialRng);
  10358. }
  10359. if (editor.selection.getRng().collapsed) {
  10360. var wrapper = makeAnnotation(editor.getDoc(), data, name, settings.decorate);
  10361. set$1(wrapper, '\xA0');
  10362. editor.selection.getRng().insertNode(wrapper.dom());
  10363. editor.selection.select(wrapper.dom());
  10364. } else {
  10365. var bookmark = GetBookmark.getPersistentBookmark(editor.selection, false);
  10366. var rng = editor.selection.getRng();
  10367. annotate(editor, rng, name, settings.decorate, data);
  10368. editor.selection.moveToBookmark(bookmark);
  10369. }
  10370. });
  10371. };
  10372. var Annotator = function (editor) {
  10373. var registry = create$1();
  10374. setup$1(editor, registry);
  10375. var changes = setup(editor);
  10376. return {
  10377. register: function (name, settings) {
  10378. registry.register(name, settings);
  10379. },
  10380. annotate: function (name, data) {
  10381. registry.lookup(name).each(function (settings) {
  10382. annotateWithBookmark(editor, name, settings, data);
  10383. });
  10384. },
  10385. annotationChanged: function (name, callback) {
  10386. changes.addListener(name, callback);
  10387. },
  10388. remove: function (name) {
  10389. identify(editor, Option.some(name)).each(function (_a) {
  10390. var elements = _a.elements;
  10391. each(elements, unwrap);
  10392. });
  10393. },
  10394. getAll: function (name) {
  10395. var directory = findAll(editor, name);
  10396. return map$1(directory, function (elems) {
  10397. return map(elems, function (elem) {
  10398. return elem.dom();
  10399. });
  10400. });
  10401. }
  10402. };
  10403. };
  10404. var whiteSpaceRegExp$3 = /^[ \t\r\n]*$/;
  10405. var typeLookup = {
  10406. '#text': 3,
  10407. '#comment': 8,
  10408. '#cdata': 4,
  10409. '#pi': 7,
  10410. '#doctype': 10,
  10411. '#document-fragment': 11
  10412. };
  10413. var walk$2 = function (node, root, prev) {
  10414. var startName = prev ? 'lastChild' : 'firstChild';
  10415. var siblingName = prev ? 'prev' : 'next';
  10416. if (node[startName]) {
  10417. return node[startName];
  10418. }
  10419. if (node !== root) {
  10420. var sibling = node[siblingName];
  10421. if (sibling) {
  10422. return sibling;
  10423. }
  10424. for (var parent = node.parent; parent && parent !== root; parent = parent.parent) {
  10425. sibling = parent[siblingName];
  10426. if (sibling) {
  10427. return sibling;
  10428. }
  10429. }
  10430. }
  10431. };
  10432. var Node$1 = function () {
  10433. function Node(name, type) {
  10434. this.name = name;
  10435. this.type = type;
  10436. if (type === 1) {
  10437. this.attributes = [];
  10438. this.attributes.map = {};
  10439. }
  10440. }
  10441. Node.create = function (name, attrs) {
  10442. var node = new Node(name, typeLookup[name] || 1);
  10443. if (attrs) {
  10444. for (var attrName in attrs) {
  10445. node.attr(attrName, attrs[attrName]);
  10446. }
  10447. }
  10448. return node;
  10449. };
  10450. Node.prototype.replace = function (node) {
  10451. var self = this;
  10452. if (node.parent) {
  10453. node.remove();
  10454. }
  10455. self.insert(node, self);
  10456. self.remove();
  10457. return self;
  10458. };
  10459. Node.prototype.attr = function (name, value) {
  10460. var self = this;
  10461. var attrs;
  10462. if (typeof name !== 'string') {
  10463. for (var key in name) {
  10464. self.attr(key, name[key]);
  10465. }
  10466. return self;
  10467. }
  10468. if (attrs = self.attributes) {
  10469. if (value !== undefined) {
  10470. if (value === null) {
  10471. if (name in attrs.map) {
  10472. delete attrs.map[name];
  10473. var i = attrs.length;
  10474. while (i--) {
  10475. if (attrs[i].name === name) {
  10476. attrs.splice(i, 1);
  10477. return self;
  10478. }
  10479. }
  10480. }
  10481. return self;
  10482. }
  10483. if (name in attrs.map) {
  10484. var i = attrs.length;
  10485. while (i--) {
  10486. if (attrs[i].name === name) {
  10487. attrs[i].value = value;
  10488. break;
  10489. }
  10490. }
  10491. } else {
  10492. attrs.push({
  10493. name: name,
  10494. value: value
  10495. });
  10496. }
  10497. attrs.map[name] = value;
  10498. return self;
  10499. }
  10500. return attrs.map[name];
  10501. }
  10502. };
  10503. Node.prototype.clone = function () {
  10504. var self = this;
  10505. var clone = new Node(self.name, self.type);
  10506. var selfAttrs;
  10507. if (selfAttrs = self.attributes) {
  10508. var cloneAttrs = [];
  10509. cloneAttrs.map = {};
  10510. for (var i = 0, l = selfAttrs.length; i < l; i++) {
  10511. var selfAttr = selfAttrs[i];
  10512. if (selfAttr.name !== 'id') {
  10513. cloneAttrs[cloneAttrs.length] = {
  10514. name: selfAttr.name,
  10515. value: selfAttr.value
  10516. };
  10517. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  10518. }
  10519. }
  10520. clone.attributes = cloneAttrs;
  10521. }
  10522. clone.value = self.value;
  10523. clone.shortEnded = self.shortEnded;
  10524. return clone;
  10525. };
  10526. Node.prototype.wrap = function (wrapper) {
  10527. var self = this;
  10528. self.parent.insert(wrapper, self);
  10529. wrapper.append(self);
  10530. return self;
  10531. };
  10532. Node.prototype.unwrap = function () {
  10533. var self = this;
  10534. for (var node = self.firstChild; node;) {
  10535. var next = node.next;
  10536. self.insert(node, self, true);
  10537. node = next;
  10538. }
  10539. self.remove();
  10540. };
  10541. Node.prototype.remove = function () {
  10542. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  10543. if (parent) {
  10544. if (parent.firstChild === self) {
  10545. parent.firstChild = next;
  10546. if (next) {
  10547. next.prev = null;
  10548. }
  10549. } else {
  10550. prev.next = next;
  10551. }
  10552. if (parent.lastChild === self) {
  10553. parent.lastChild = prev;
  10554. if (prev) {
  10555. prev.next = null;
  10556. }
  10557. } else {
  10558. next.prev = prev;
  10559. }
  10560. self.parent = self.next = self.prev = null;
  10561. }
  10562. return self;
  10563. };
  10564. Node.prototype.append = function (node) {
  10565. var self = this;
  10566. if (node.parent) {
  10567. node.remove();
  10568. }
  10569. var last = self.lastChild;
  10570. if (last) {
  10571. last.next = node;
  10572. node.prev = last;
  10573. self.lastChild = node;
  10574. } else {
  10575. self.lastChild = self.firstChild = node;
  10576. }
  10577. node.parent = self;
  10578. return node;
  10579. };
  10580. Node.prototype.insert = function (node, refNode, before) {
  10581. if (node.parent) {
  10582. node.remove();
  10583. }
  10584. var parent = refNode.parent || this;
  10585. if (before) {
  10586. if (refNode === parent.firstChild) {
  10587. parent.firstChild = node;
  10588. } else {
  10589. refNode.prev.next = node;
  10590. }
  10591. node.prev = refNode.prev;
  10592. node.next = refNode;
  10593. refNode.prev = node;
  10594. } else {
  10595. if (refNode === parent.lastChild) {
  10596. parent.lastChild = node;
  10597. } else {
  10598. refNode.next.prev = node;
  10599. }
  10600. node.next = refNode.next;
  10601. node.prev = refNode;
  10602. refNode.next = node;
  10603. }
  10604. node.parent = parent;
  10605. return node;
  10606. };
  10607. Node.prototype.getAll = function (name) {
  10608. var self = this;
  10609. var collection = [];
  10610. for (var node = self.firstChild; node; node = walk$2(node, self)) {
  10611. if (node.name === name) {
  10612. collection.push(node);
  10613. }
  10614. }
  10615. return collection;
  10616. };
  10617. Node.prototype.empty = function () {
  10618. var self = this;
  10619. if (self.firstChild) {
  10620. var nodes = [];
  10621. for (var node = self.firstChild; node; node = walk$2(node, self)) {
  10622. nodes.push(node);
  10623. }
  10624. var i = nodes.length;
  10625. while (i--) {
  10626. var node = nodes[i];
  10627. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  10628. }
  10629. }
  10630. self.firstChild = self.lastChild = null;
  10631. return self;
  10632. };
  10633. Node.prototype.isEmpty = function (elements, whitespace, predicate) {
  10634. if (whitespace === void 0) {
  10635. whitespace = {};
  10636. }
  10637. var self = this;
  10638. var node = self.firstChild;
  10639. if (node) {
  10640. do {
  10641. if (node.type === 1) {
  10642. if (node.attr('data-mce-bogus')) {
  10643. continue;
  10644. }
  10645. if (elements[node.name]) {
  10646. return false;
  10647. }
  10648. var i = node.attributes.length;
  10649. while (i--) {
  10650. var name = node.attributes[i].name;
  10651. if (name === 'name' || name.indexOf('data-mce-bookmark') === 0) {
  10652. return false;
  10653. }
  10654. }
  10655. }
  10656. if (node.type === 8) {
  10657. return false;
  10658. }
  10659. if (node.type === 3 && !whiteSpaceRegExp$3.test(node.value)) {
  10660. return false;
  10661. }
  10662. if (node.type === 3 && node.parent && whitespace[node.parent.name] && whiteSpaceRegExp$3.test(node.value)) {
  10663. return false;
  10664. }
  10665. if (predicate && predicate(node)) {
  10666. return false;
  10667. }
  10668. } while (node = walk$2(node, self));
  10669. }
  10670. return true;
  10671. };
  10672. Node.prototype.walk = function (prev) {
  10673. return walk$2(this, null, prev);
  10674. };
  10675. return Node;
  10676. }();
  10677. var isValidPrefixAttrName = function (name) {
  10678. return name.indexOf('data-') === 0 || name.indexOf('aria-') === 0;
  10679. };
  10680. var trimComments = function (text) {
  10681. return text.replace(/<!--|-->/g, '');
  10682. };
  10683. var isInvalidUri = function (settings, uri) {
  10684. if (settings.allow_html_data_urls) {
  10685. return false;
  10686. } else if (/^data:image\//i.test(uri)) {
  10687. return settings.allow_svg_data_urls === false && /^data:image\/svg\+xml/i.test(uri);
  10688. } else {
  10689. return /^data:/i.test(uri);
  10690. }
  10691. };
  10692. var findEndTagIndex = function (schema, html, startIndex) {
  10693. var count = 1, index, matches, tokenRegExp, shortEndedElements;
  10694. shortEndedElements = schema.getShortEndedElements();
  10695. tokenRegExp = /<([!?\/])?([A-Za-z0-9\-_\:\.]+)((?:\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\/|\s+)>/g;
  10696. tokenRegExp.lastIndex = index = startIndex;
  10697. while (matches = tokenRegExp.exec(html)) {
  10698. index = tokenRegExp.lastIndex;
  10699. if (matches[1] === '/') {
  10700. count--;
  10701. } else if (!matches[1]) {
  10702. if (matches[2] in shortEndedElements) {
  10703. continue;
  10704. }
  10705. count++;
  10706. }
  10707. if (count === 0) {
  10708. break;
  10709. }
  10710. }
  10711. return index;
  10712. };
  10713. var checkBogusAttribute = function (regExp, attrString) {
  10714. var matches = regExp.exec(attrString);
  10715. if (matches) {
  10716. var name = matches[1];
  10717. var value = matches[2];
  10718. return typeof name === 'string' && name.toLowerCase() === 'data-mce-bogus' ? value : null;
  10719. } else {
  10720. return null;
  10721. }
  10722. };
  10723. function SaxParser(settings, schema) {
  10724. if (schema === void 0) {
  10725. schema = Schema();
  10726. }
  10727. var noop = function () {
  10728. };
  10729. settings = settings || {};
  10730. if (settings.fix_self_closing !== false) {
  10731. settings.fix_self_closing = true;
  10732. }
  10733. var comment = settings.comment ? settings.comment : noop;
  10734. var cdata = settings.cdata ? settings.cdata : noop;
  10735. var text = settings.text ? settings.text : noop;
  10736. var start = settings.start ? settings.start : noop;
  10737. var end = settings.end ? settings.end : noop;
  10738. var pi = settings.pi ? settings.pi : noop;
  10739. var doctype = settings.doctype ? settings.doctype : noop;
  10740. var parse = function (html) {
  10741. var matches, index = 0, value, endRegExp;
  10742. var stack = [];
  10743. var attrList, i, textData, name;
  10744. var isInternalElement, removeInternalElements, shortEndedElements, fillAttrsMap, isShortEnded;
  10745. var validate, elementRule, isValidElement, attr, attribsValue, validAttributesMap, validAttributePatterns;
  10746. var attributesRequired, attributesDefault, attributesForced, processHtml;
  10747. var anyAttributesRequired, selfClosing, tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0;
  10748. var decode = Entities.decode;
  10749. var fixSelfClosing;
  10750. var filteredUrlAttrs = Tools.makeMap('src,href,data,background,formaction,poster,xlink:href');
  10751. var scriptUriRegExp = /((java|vb)script|mhtml):/i;
  10752. var processEndTag = function (name) {
  10753. var pos, i;
  10754. pos = stack.length;
  10755. while (pos--) {
  10756. if (stack[pos].name === name) {
  10757. break;
  10758. }
  10759. }
  10760. if (pos >= 0) {
  10761. for (i = stack.length - 1; i >= pos; i--) {
  10762. name = stack[i];
  10763. if (name.valid) {
  10764. end(name.name);
  10765. }
  10766. }
  10767. stack.length = pos;
  10768. }
  10769. };
  10770. var parseAttribute = function (match, name, value, val2, val3) {
  10771. var attrRule, i;
  10772. var trimRegExp = /[\s\u0000-\u001F]+/g;
  10773. name = name.toLowerCase();
  10774. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || '');
  10775. if (validate && !isInternalElement && isValidPrefixAttrName(name) === false) {
  10776. attrRule = validAttributesMap[name];
  10777. if (!attrRule && validAttributePatterns) {
  10778. i = validAttributePatterns.length;
  10779. while (i--) {
  10780. attrRule = validAttributePatterns[i];
  10781. if (attrRule.pattern.test(name)) {
  10782. break;
  10783. }
  10784. }
  10785. if (i === -1) {
  10786. attrRule = null;
  10787. }
  10788. }
  10789. if (!attrRule) {
  10790. return;
  10791. }
  10792. if (attrRule.validValues && !(value in attrRule.validValues)) {
  10793. return;
  10794. }
  10795. }
  10796. if (filteredUrlAttrs[name] && !settings.allow_script_urls) {
  10797. var uri = value.replace(trimRegExp, '');
  10798. try {
  10799. uri = decodeURIComponent(uri);
  10800. } catch (ex) {
  10801. uri = unescape(uri);
  10802. }
  10803. if (scriptUriRegExp.test(uri)) {
  10804. return;
  10805. }
  10806. if (isInvalidUri(settings, uri)) {
  10807. return;
  10808. }
  10809. }
  10810. if (isInternalElement && (name in filteredUrlAttrs || name.indexOf('on') === 0)) {
  10811. return;
  10812. }
  10813. attrList.map[name] = value;
  10814. attrList.push({
  10815. name: name,
  10816. value: value
  10817. });
  10818. };
  10819. tokenRegExp = new RegExp('<(?:' + '(?:!--([\\w\\W]*?)-->)|' + '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + '(?:!DOCTYPE([\\w\\W]*?)>)|' + '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + '(?:\\/([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)>)|' + '(?:([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + ')', 'g');
  10820. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
  10821. shortEndedElements = schema.getShortEndedElements();
  10822. selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  10823. fillAttrsMap = schema.getBoolAttrs();
  10824. validate = settings.validate;
  10825. removeInternalElements = settings.remove_internals;
  10826. fixSelfClosing = settings.fix_self_closing;
  10827. specialElements = schema.getSpecialElements();
  10828. processHtml = html + '>';
  10829. while (matches = tokenRegExp.exec(processHtml)) {
  10830. if (index < matches.index) {
  10831. text(decode(html.substr(index, matches.index - index)));
  10832. }
  10833. if (value = matches[6]) {
  10834. value = value.toLowerCase();
  10835. if (value.charAt(0) === ':') {
  10836. value = value.substr(1);
  10837. }
  10838. processEndTag(value);
  10839. } else if (value = matches[7]) {
  10840. if (matches.index + matches[0].length > html.length) {
  10841. text(decode(html.substr(matches.index)));
  10842. index = matches.index + matches[0].length;
  10843. continue;
  10844. }
  10845. value = value.toLowerCase();
  10846. if (value.charAt(0) === ':') {
  10847. value = value.substr(1);
  10848. }
  10849. isShortEnded = value in shortEndedElements;
  10850. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value) {
  10851. processEndTag(value);
  10852. }
  10853. var bogusValue = checkBogusAttribute(attrRegExp, matches[8]);
  10854. if (bogusValue !== null) {
  10855. if (bogusValue === 'all') {
  10856. index = findEndTagIndex(schema, html, tokenRegExp.lastIndex);
  10857. tokenRegExp.lastIndex = index;
  10858. continue;
  10859. }
  10860. isValidElement = false;
  10861. }
  10862. if (!validate || (elementRule = schema.getElementRule(value))) {
  10863. isValidElement = true;
  10864. if (validate) {
  10865. validAttributesMap = elementRule.attributes;
  10866. validAttributePatterns = elementRule.attributePatterns;
  10867. }
  10868. if (attribsValue = matches[8]) {
  10869. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1;
  10870. if (isInternalElement && removeInternalElements) {
  10871. isValidElement = false;
  10872. }
  10873. attrList = [];
  10874. attrList.map = {};
  10875. attribsValue.replace(attrRegExp, parseAttribute);
  10876. } else {
  10877. attrList = [];
  10878. attrList.map = {};
  10879. }
  10880. if (validate && !isInternalElement) {
  10881. attributesRequired = elementRule.attributesRequired;
  10882. attributesDefault = elementRule.attributesDefault;
  10883. attributesForced = elementRule.attributesForced;
  10884. anyAttributesRequired = elementRule.removeEmptyAttrs;
  10885. if (anyAttributesRequired && !attrList.length) {
  10886. isValidElement = false;
  10887. }
  10888. if (attributesForced) {
  10889. i = attributesForced.length;
  10890. while (i--) {
  10891. attr = attributesForced[i];
  10892. name = attr.name;
  10893. attrValue = attr.value;
  10894. if (attrValue === '{$uid}') {
  10895. attrValue = 'mce_' + idCount++;
  10896. }
  10897. attrList.map[name] = attrValue;
  10898. attrList.push({
  10899. name: name,
  10900. value: attrValue
  10901. });
  10902. }
  10903. }
  10904. if (attributesDefault) {
  10905. i = attributesDefault.length;
  10906. while (i--) {
  10907. attr = attributesDefault[i];
  10908. name = attr.name;
  10909. if (!(name in attrList.map)) {
  10910. attrValue = attr.value;
  10911. if (attrValue === '{$uid}') {
  10912. attrValue = 'mce_' + idCount++;
  10913. }
  10914. attrList.map[name] = attrValue;
  10915. attrList.push({
  10916. name: name,
  10917. value: attrValue
  10918. });
  10919. }
  10920. }
  10921. }
  10922. if (attributesRequired) {
  10923. i = attributesRequired.length;
  10924. while (i--) {
  10925. if (attributesRequired[i] in attrList.map) {
  10926. break;
  10927. }
  10928. }
  10929. if (i === -1) {
  10930. isValidElement = false;
  10931. }
  10932. }
  10933. if (attr = attrList.map['data-mce-bogus']) {
  10934. if (attr === 'all') {
  10935. index = findEndTagIndex(schema, html, tokenRegExp.lastIndex);
  10936. tokenRegExp.lastIndex = index;
  10937. continue;
  10938. }
  10939. isValidElement = false;
  10940. }
  10941. }
  10942. if (isValidElement) {
  10943. start(value, attrList, isShortEnded);
  10944. }
  10945. } else {
  10946. isValidElement = false;
  10947. }
  10948. if (endRegExp = specialElements[value]) {
  10949. endRegExp.lastIndex = index = matches.index + matches[0].length;
  10950. if (matches = endRegExp.exec(html)) {
  10951. if (isValidElement) {
  10952. textData = html.substr(index, matches.index - index);
  10953. }
  10954. index = matches.index + matches[0].length;
  10955. } else {
  10956. textData = html.substr(index);
  10957. index = html.length;
  10958. }
  10959. if (isValidElement) {
  10960. if (textData.length > 0) {
  10961. text(textData, true);
  10962. }
  10963. end(value);
  10964. }
  10965. tokenRegExp.lastIndex = index;
  10966. continue;
  10967. }
  10968. if (!isShortEnded) {
  10969. if (!attribsValue || attribsValue.indexOf('/') !== attribsValue.length - 1) {
  10970. stack.push({
  10971. name: value,
  10972. valid: isValidElement
  10973. });
  10974. } else if (isValidElement) {
  10975. end(value);
  10976. }
  10977. }
  10978. } else if (value = matches[1]) {
  10979. if (value.charAt(0) === '>') {
  10980. value = ' ' + value;
  10981. }
  10982. if (!settings.allow_conditional_comments && value.substr(0, 3).toLowerCase() === '[if') {
  10983. value = ' ' + value;
  10984. }
  10985. comment(value);
  10986. } else if (value = matches[2]) {
  10987. cdata(trimComments(value));
  10988. } else if (value = matches[3]) {
  10989. doctype(value);
  10990. } else if (value = matches[4]) {
  10991. pi(value, matches[5]);
  10992. }
  10993. index = matches.index + matches[0].length;
  10994. }
  10995. if (index < html.length) {
  10996. text(decode(html.substr(index)));
  10997. }
  10998. for (i = stack.length - 1; i >= 0; i--) {
  10999. value = stack[i];
  11000. if (value.valid) {
  11001. end(value.name);
  11002. }
  11003. }
  11004. };
  11005. return { parse: parse };
  11006. }
  11007. (function (SaxParser) {
  11008. SaxParser.findEndTag = findEndTagIndex;
  11009. }(SaxParser || (SaxParser = {})));
  11010. var SaxParser$1 = SaxParser;
  11011. var trimHtml = function (tempAttrs, html) {
  11012. var trimContentRegExp = new RegExp(['\\s?(' + tempAttrs.join('|') + ')="[^"]+"'].join('|'), 'gi');
  11013. return html.replace(trimContentRegExp, '');
  11014. };
  11015. var trimInternal = function (serializer, html) {
  11016. var content = html;
  11017. var bogusAllRegExp = /<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g;
  11018. var endTagIndex, index, matchLength, matches, shortEndedElements;
  11019. var schema = serializer.schema;
  11020. content = trimHtml(serializer.getTempAttrs(), content);
  11021. shortEndedElements = schema.getShortEndedElements();
  11022. while (matches = bogusAllRegExp.exec(content)) {
  11023. index = bogusAllRegExp.lastIndex;
  11024. matchLength = matches[0].length;
  11025. if (shortEndedElements[matches[1]]) {
  11026. endTagIndex = index;
  11027. } else {
  11028. endTagIndex = SaxParser$1.findEndTag(schema, content, index);
  11029. }
  11030. content = content.substring(0, index - matchLength) + content.substring(endTagIndex);
  11031. bogusAllRegExp.lastIndex = index - matchLength;
  11032. }
  11033. return Zwsp.trim(content);
  11034. };
  11035. var trimExternal = trimInternal;
  11036. var TrimHtml = {
  11037. trimExternal: trimExternal,
  11038. trimInternal: trimInternal
  11039. };
  11040. var getBodySetting = function (editor, name, defaultValue) {
  11041. var value = editor.getParam(name, defaultValue);
  11042. if (value.indexOf('=') !== -1) {
  11043. var bodyObj = editor.getParam(name, '', 'hash');
  11044. return bodyObj.hasOwnProperty(editor.id) ? bodyObj[editor.id] : defaultValue;
  11045. } else {
  11046. return value;
  11047. }
  11048. };
  11049. var getIframeAttrs = function (editor) {
  11050. return editor.getParam('iframe_attrs', {});
  11051. };
  11052. var getDocType = function (editor) {
  11053. return editor.getParam('doctype', '<!DOCTYPE html>');
  11054. };
  11055. var getDocumentBaseUrl = function (editor) {
  11056. return editor.getParam('document_base_url', '');
  11057. };
  11058. var getBodyId = function (editor) {
  11059. return getBodySetting(editor, 'body_id', 'tinymce');
  11060. };
  11061. var getBodyClass = function (editor) {
  11062. return getBodySetting(editor, 'body_class', '');
  11063. };
  11064. var getContentSecurityPolicy = function (editor) {
  11065. return editor.getParam('content_security_policy', '');
  11066. };
  11067. var shouldPutBrInPre = function (editor) {
  11068. return editor.getParam('br_in_pre', true);
  11069. };
  11070. var getForcedRootBlock = function (editor) {
  11071. if (editor.getParam('force_p_newlines', false)) {
  11072. return 'p';
  11073. }
  11074. var block = editor.getParam('forced_root_block', 'p');
  11075. if (block === false) {
  11076. return '';
  11077. } else if (block === true) {
  11078. return 'p';
  11079. } else {
  11080. return block;
  11081. }
  11082. };
  11083. var getForcedRootBlockAttrs = function (editor) {
  11084. return editor.getParam('forced_root_block_attrs', {});
  11085. };
  11086. var getBrNewLineSelector = function (editor) {
  11087. return editor.getParam('br_newline_selector', '.mce-toc h2,figcaption,caption');
  11088. };
  11089. var getNoNewLineSelector = function (editor) {
  11090. return editor.getParam('no_newline_selector', '');
  11091. };
  11092. var shouldKeepStyles = function (editor) {
  11093. return editor.getParam('keep_styles', true);
  11094. };
  11095. var shouldEndContainerOnEmptyBlock = function (editor) {
  11096. return editor.getParam('end_container_on_empty_block', false);
  11097. };
  11098. var getFontStyleValues = function (editor) {
  11099. return Tools.explode(editor.getParam('font_size_style_values', 'xx-small,x-small,small,medium,large,x-large,xx-large'));
  11100. };
  11101. var getFontSizeClasses = function (editor) {
  11102. return Tools.explode(editor.getParam('font_size_classes', ''));
  11103. };
  11104. var getImagesDataImgFilter = function (editor) {
  11105. return editor.getParam('images_dataimg_filter', constant(true), 'function');
  11106. };
  11107. var isAutomaticUploadsEnabled = function (editor) {
  11108. return editor.getParam('automatic_uploads', true, 'boolean');
  11109. };
  11110. var shouldReuseFileName = function (editor) {
  11111. return editor.getParam('images_reuse_filename', false, 'boolean');
  11112. };
  11113. var shouldReplaceBlobUris = function (editor) {
  11114. return editor.getParam('images_replace_blob_uris', true, 'boolean');
  11115. };
  11116. var getIconPackName = function (editor) {
  11117. return editor.getParam('icons', '', 'string');
  11118. };
  11119. var getIconsUrl = function (editor) {
  11120. return editor.getParam('icons_url', '', 'string');
  11121. };
  11122. var getImageUploadUrl = function (editor) {
  11123. return editor.getParam('images_upload_url', '', 'string');
  11124. };
  11125. var getImageUploadBasePath = function (editor) {
  11126. return editor.getParam('images_upload_base_path', '', 'string');
  11127. };
  11128. var getImagesUploadCredentials = function (editor) {
  11129. return editor.getParam('images_upload_credentials', false, 'boolean');
  11130. };
  11131. var getImagesUploadHandler = function (editor) {
  11132. return editor.getParam('images_upload_handler', null, 'function');
  11133. };
  11134. var shouldUseContentCssCors = function (editor) {
  11135. return editor.getParam('content_css_cors', false, 'boolean');
  11136. };
  11137. var getReferrerPolicy = function (editor) {
  11138. return editor.getParam('referrer_policy', '', 'string');
  11139. };
  11140. var getLanguageCode = function (editor) {
  11141. return editor.getParam('language', 'en', 'string');
  11142. };
  11143. var getLanguageUrl = function (editor) {
  11144. return editor.getParam('language_url', '', 'string');
  11145. };
  11146. var shouldIndentUseMargin = function (editor) {
  11147. return editor.getParam('indent_use_margin', false);
  11148. };
  11149. var getIndentation = function (editor) {
  11150. return editor.getParam('indentation', '40px', 'string');
  11151. };
  11152. var getContentCss = function (editor) {
  11153. var contentCss = editor.settings.content_css;
  11154. if (isString(contentCss)) {
  11155. return map(contentCss.split(','), trim);
  11156. } else if (isArray(contentCss)) {
  11157. return contentCss;
  11158. } else if (contentCss === false || editor.inline) {
  11159. return [];
  11160. } else {
  11161. return ['default'];
  11162. }
  11163. };
  11164. var getDirectionality = function (editor) {
  11165. return editor.getParam('directionality', I18n.isRtl() ? 'rtl' : undefined);
  11166. };
  11167. var getInlineBoundarySelector = function (editor) {
  11168. return editor.getParam('inline_boundaries_selector', 'a[href],code,.mce-annotation', 'string');
  11169. };
  11170. var Settings = {
  11171. getIframeAttrs: getIframeAttrs,
  11172. getDocType: getDocType,
  11173. getDocumentBaseUrl: getDocumentBaseUrl,
  11174. getBodyId: getBodyId,
  11175. getBodyClass: getBodyClass,
  11176. getContentSecurityPolicy: getContentSecurityPolicy,
  11177. shouldPutBrInPre: shouldPutBrInPre,
  11178. getForcedRootBlock: getForcedRootBlock,
  11179. getForcedRootBlockAttrs: getForcedRootBlockAttrs,
  11180. getBrNewLineSelector: getBrNewLineSelector,
  11181. getNoNewLineSelector: getNoNewLineSelector,
  11182. shouldKeepStyles: shouldKeepStyles,
  11183. shouldEndContainerOnEmptyBlock: shouldEndContainerOnEmptyBlock,
  11184. getFontStyleValues: getFontStyleValues,
  11185. getFontSizeClasses: getFontSizeClasses,
  11186. getIconPackName: getIconPackName,
  11187. getIconsUrl: getIconsUrl,
  11188. getImagesDataImgFilter: getImagesDataImgFilter,
  11189. isAutomaticUploadsEnabled: isAutomaticUploadsEnabled,
  11190. shouldReuseFileName: shouldReuseFileName,
  11191. shouldReplaceBlobUris: shouldReplaceBlobUris,
  11192. getImageUploadUrl: getImageUploadUrl,
  11193. getImageUploadBasePath: getImageUploadBasePath,
  11194. getImagesUploadCredentials: getImagesUploadCredentials,
  11195. getImagesUploadHandler: getImagesUploadHandler,
  11196. shouldUseContentCssCors: shouldUseContentCssCors,
  11197. getReferrerPolicy: getReferrerPolicy,
  11198. getLanguageCode: getLanguageCode,
  11199. getLanguageUrl: getLanguageUrl,
  11200. shouldIndentUseMargin: shouldIndentUseMargin,
  11201. getIndentation: getIndentation,
  11202. getContentCss: getContentCss,
  11203. getDirectionality: getDirectionality,
  11204. getInlineBoundarySelector: getInlineBoundarySelector
  11205. };
  11206. var defaultFormat = 'html';
  11207. var trimEmptyContents = function (editor, html) {
  11208. var blockName = Settings.getForcedRootBlock(editor);
  11209. var emptyRegExp = new RegExp('^(<' + blockName + '[^>]*>(&nbsp;|&#160;|\\s|\xA0|<br \\/>|)<\\/' + blockName + '>[\r\n]*|<br \\/>[\r\n]*)$');
  11210. return html.replace(emptyRegExp, '');
  11211. };
  11212. var getContentFromBody = function (editor, args, body) {
  11213. var content;
  11214. args.format = args.format ? args.format : defaultFormat;
  11215. args.get = true;
  11216. args.getInner = true;
  11217. if (!args.no_events) {
  11218. editor.fire('BeforeGetContent', args);
  11219. }
  11220. if (args.format === 'raw') {
  11221. content = Tools.trim(TrimHtml.trimExternal(editor.serializer, body.innerHTML));
  11222. } else if (args.format === 'text') {
  11223. content = Zwsp.trim(body.innerText || body.textContent);
  11224. } else if (args.format === 'tree') {
  11225. return editor.serializer.serialize(body, args);
  11226. } else {
  11227. content = trimEmptyContents(editor, editor.serializer.serialize(body, args));
  11228. }
  11229. if (args.format !== 'text' && !isWsPreserveElement(Element.fromDom(body))) {
  11230. args.content = Tools.trim(content);
  11231. } else {
  11232. args.content = content;
  11233. }
  11234. if (!args.no_events) {
  11235. editor.fire('GetContent', args);
  11236. }
  11237. return args.content;
  11238. };
  11239. var getContent = function (editor, args) {
  11240. if (args === void 0) {
  11241. args = {};
  11242. }
  11243. return Option.from(editor.getBody()).fold(constant(args.format === 'tree' ? new Node$1('body', 11) : ''), function (body) {
  11244. return getContentFromBody(editor, args, body);
  11245. });
  11246. };
  11247. var makeMap$3 = Tools.makeMap;
  11248. var Writer = function (settings) {
  11249. var html = [];
  11250. var indent, indentBefore, indentAfter, encode, htmlOutput;
  11251. settings = settings || {};
  11252. indent = settings.indent;
  11253. indentBefore = makeMap$3(settings.indent_before || '');
  11254. indentAfter = makeMap$3(settings.indent_after || '');
  11255. encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  11256. htmlOutput = settings.element_format === 'html';
  11257. return {
  11258. start: function (name, attrs, empty) {
  11259. var i, l, attr, value;
  11260. if (indent && indentBefore[name] && html.length > 0) {
  11261. value = html[html.length - 1];
  11262. if (value.length > 0 && value !== '\n') {
  11263. html.push('\n');
  11264. }
  11265. }
  11266. html.push('<', name);
  11267. if (attrs) {
  11268. for (i = 0, l = attrs.length; i < l; i++) {
  11269. attr = attrs[i];
  11270. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  11271. }
  11272. }
  11273. if (!empty || htmlOutput) {
  11274. html[html.length] = '>';
  11275. } else {
  11276. html[html.length] = ' />';
  11277. }
  11278. if (empty && indent && indentAfter[name] && html.length > 0) {
  11279. value = html[html.length - 1];
  11280. if (value.length > 0 && value !== '\n') {
  11281. html.push('\n');
  11282. }
  11283. }
  11284. },
  11285. end: function (name) {
  11286. var value;
  11287. html.push('</', name, '>');
  11288. if (indent && indentAfter[name] && html.length > 0) {
  11289. value = html[html.length - 1];
  11290. if (value.length > 0 && value !== '\n') {
  11291. html.push('\n');
  11292. }
  11293. }
  11294. },
  11295. text: function (text, raw) {
  11296. if (text.length > 0) {
  11297. html[html.length] = raw ? text : encode(text);
  11298. }
  11299. },
  11300. cdata: function (text) {
  11301. html.push('<![CDATA[', text, ']]>');
  11302. },
  11303. comment: function (text) {
  11304. html.push('<!--', text, '-->');
  11305. },
  11306. pi: function (name, text) {
  11307. if (text) {
  11308. html.push('<?', name, ' ', encode(text), '?>');
  11309. } else {
  11310. html.push('<?', name, '?>');
  11311. }
  11312. if (indent) {
  11313. html.push('\n');
  11314. }
  11315. },
  11316. doctype: function (text) {
  11317. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  11318. },
  11319. reset: function () {
  11320. html.length = 0;
  11321. },
  11322. getContent: function () {
  11323. return html.join('').replace(/\n$/, '');
  11324. }
  11325. };
  11326. };
  11327. var Serializer = function (settings, schema) {
  11328. if (schema === void 0) {
  11329. schema = Schema();
  11330. }
  11331. var writer = Writer(settings);
  11332. settings = settings || {};
  11333. settings.validate = 'validate' in settings ? settings.validate : true;
  11334. var serialize = function (node) {
  11335. var handlers, validate;
  11336. validate = settings.validate;
  11337. handlers = {
  11338. 3: function (node) {
  11339. writer.text(node.value, node.raw);
  11340. },
  11341. 8: function (node) {
  11342. writer.comment(node.value);
  11343. },
  11344. 7: function (node) {
  11345. writer.pi(node.name, node.value);
  11346. },
  11347. 10: function (node) {
  11348. writer.doctype(node.value);
  11349. },
  11350. 4: function (node) {
  11351. writer.cdata(node.value);
  11352. },
  11353. 11: function (node) {
  11354. if (node = node.firstChild) {
  11355. do {
  11356. walk(node);
  11357. } while (node = node.next);
  11358. }
  11359. }
  11360. };
  11361. writer.reset();
  11362. var walk = function (node) {
  11363. var handler = handlers[node.type];
  11364. var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  11365. if (!handler) {
  11366. name = node.name;
  11367. isEmpty = node.shortEnded;
  11368. attrs = node.attributes;
  11369. if (validate && attrs && attrs.length > 1) {
  11370. sortedAttrs = [];
  11371. sortedAttrs.map = {};
  11372. elementRule = schema.getElementRule(node.name);
  11373. if (elementRule) {
  11374. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  11375. attrName = elementRule.attributesOrder[i];
  11376. if (attrName in attrs.map) {
  11377. attrValue = attrs.map[attrName];
  11378. sortedAttrs.map[attrName] = attrValue;
  11379. sortedAttrs.push({
  11380. name: attrName,
  11381. value: attrValue
  11382. });
  11383. }
  11384. }
  11385. for (i = 0, l = attrs.length; i < l; i++) {
  11386. attrName = attrs[i].name;
  11387. if (!(attrName in sortedAttrs.map)) {
  11388. attrValue = attrs.map[attrName];
  11389. sortedAttrs.map[attrName] = attrValue;
  11390. sortedAttrs.push({
  11391. name: attrName,
  11392. value: attrValue
  11393. });
  11394. }
  11395. }
  11396. attrs = sortedAttrs;
  11397. }
  11398. }
  11399. writer.start(node.name, attrs, isEmpty);
  11400. if (!isEmpty) {
  11401. if (node = node.firstChild) {
  11402. do {
  11403. walk(node);
  11404. } while (node = node.next);
  11405. }
  11406. writer.end(name);
  11407. }
  11408. } else {
  11409. handler(node);
  11410. }
  11411. };
  11412. if (node.type === 1 && !settings.inner) {
  11413. walk(node);
  11414. } else {
  11415. handlers[11](node);
  11416. }
  11417. return writer.getContent();
  11418. };
  11419. return { serialize: serialize };
  11420. };
  11421. var traverse = function (node, fn) {
  11422. fn(node);
  11423. if (node.firstChild) {
  11424. traverse(node.firstChild, fn);
  11425. }
  11426. if (node.next) {
  11427. traverse(node.next, fn);
  11428. }
  11429. };
  11430. var findMatchingNodes = function (nodeFilters, attributeFilters, node) {
  11431. var nodeMatches = {};
  11432. var attrMatches = {};
  11433. var matches = [];
  11434. if (node.firstChild) {
  11435. traverse(node.firstChild, function (node) {
  11436. each(nodeFilters, function (filter) {
  11437. if (filter.name === node.name) {
  11438. if (nodeMatches[filter.name]) {
  11439. nodeMatches[filter.name].nodes.push(node);
  11440. } else {
  11441. nodeMatches[filter.name] = {
  11442. filter: filter,
  11443. nodes: [node]
  11444. };
  11445. }
  11446. }
  11447. });
  11448. each(attributeFilters, function (filter) {
  11449. if (typeof node.attr(filter.name) === 'string') {
  11450. if (attrMatches[filter.name]) {
  11451. attrMatches[filter.name].nodes.push(node);
  11452. } else {
  11453. attrMatches[filter.name] = {
  11454. filter: filter,
  11455. nodes: [node]
  11456. };
  11457. }
  11458. }
  11459. });
  11460. });
  11461. }
  11462. for (var name in nodeMatches) {
  11463. if (nodeMatches.hasOwnProperty(name)) {
  11464. matches.push(nodeMatches[name]);
  11465. }
  11466. }
  11467. for (var name in attrMatches) {
  11468. if (attrMatches.hasOwnProperty(name)) {
  11469. matches.push(attrMatches[name]);
  11470. }
  11471. }
  11472. return matches;
  11473. };
  11474. var filter$2 = function (nodeFilters, attributeFilters, node) {
  11475. var matches = findMatchingNodes(nodeFilters, attributeFilters, node);
  11476. each(matches, function (match) {
  11477. each(match.filter.callbacks, function (callback) {
  11478. callback(match.nodes, match.filter.name, {});
  11479. });
  11480. });
  11481. };
  11482. var hasFocus = function (element) {
  11483. var doc = owner(element).dom();
  11484. return element.dom() === doc.activeElement;
  11485. };
  11486. var active = function (_doc) {
  11487. var doc = _doc !== undefined ? _doc.dom() : domGlobals.document;
  11488. return Option.from(doc.activeElement).map(Element.fromDom);
  11489. };
  11490. var search = function (element) {
  11491. return active(owner(element)).filter(function (e) {
  11492. return element.dom().contains(e.dom());
  11493. });
  11494. };
  11495. var generate$1 = function (cases) {
  11496. if (!isArray(cases)) {
  11497. throw new Error('cases must be an array');
  11498. }
  11499. if (cases.length === 0) {
  11500. throw new Error('there must be at least one case');
  11501. }
  11502. var constructors = [];
  11503. var adt = {};
  11504. each(cases, function (acase, count) {
  11505. var keys$1 = keys(acase);
  11506. if (keys$1.length !== 1) {
  11507. throw new Error('one and only one name per case');
  11508. }
  11509. var key = keys$1[0];
  11510. var value = acase[key];
  11511. if (adt[key] !== undefined) {
  11512. throw new Error('duplicate key detected:' + key);
  11513. } else if (key === 'cata') {
  11514. throw new Error('cannot have a case named cata (sorry)');
  11515. } else if (!isArray(value)) {
  11516. throw new Error('case arguments must be an array');
  11517. }
  11518. constructors.push(key);
  11519. adt[key] = function () {
  11520. var argLength = arguments.length;
  11521. if (argLength !== value.length) {
  11522. throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
  11523. }
  11524. var args = new Array(argLength);
  11525. for (var i = 0; i < args.length; i++) {
  11526. args[i] = arguments[i];
  11527. }
  11528. var match = function (branches) {
  11529. var branchKeys = keys(branches);
  11530. if (constructors.length !== branchKeys.length) {
  11531. throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
  11532. }
  11533. var allReqd = forall(constructors, function (reqKey) {
  11534. return contains(branchKeys, reqKey);
  11535. });
  11536. if (!allReqd) {
  11537. throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
  11538. }
  11539. return branches[key].apply(null, args);
  11540. };
  11541. return {
  11542. fold: function () {
  11543. if (arguments.length !== cases.length) {
  11544. throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
  11545. }
  11546. var target = arguments[count];
  11547. return target.apply(null, args);
  11548. },
  11549. match: match,
  11550. log: function (label) {
  11551. domGlobals.console.log(label, {
  11552. constructors: constructors,
  11553. constructor: key,
  11554. params: args
  11555. });
  11556. }
  11557. };
  11558. };
  11559. });
  11560. return adt;
  11561. };
  11562. var Adt = { generate: generate$1 };
  11563. var create$3 = Immutable('start', 'soffset', 'finish', 'foffset');
  11564. var SimRange = { create: create$3 };
  11565. var adt = Adt.generate([
  11566. { before: ['element'] },
  11567. {
  11568. on: [
  11569. 'element',
  11570. 'offset'
  11571. ]
  11572. },
  11573. { after: ['element'] }
  11574. ]);
  11575. var cata = function (subject, onBefore, onOn, onAfter) {
  11576. return subject.fold(onBefore, onOn, onAfter);
  11577. };
  11578. var getStart = function (situ) {
  11579. return situ.fold(identity, identity, identity);
  11580. };
  11581. var before$3 = adt.before;
  11582. var on = adt.on;
  11583. var after$2 = adt.after;
  11584. var Situ = {
  11585. before: before$3,
  11586. on: on,
  11587. after: after$2,
  11588. cata: cata,
  11589. getStart: getStart
  11590. };
  11591. var adt$1 = Adt.generate([
  11592. { domRange: ['rng'] },
  11593. {
  11594. relative: [
  11595. 'startSitu',
  11596. 'finishSitu'
  11597. ]
  11598. },
  11599. {
  11600. exact: [
  11601. 'start',
  11602. 'soffset',
  11603. 'finish',
  11604. 'foffset'
  11605. ]
  11606. }
  11607. ]);
  11608. var exactFromRange = function (simRange) {
  11609. return adt$1.exact(simRange.start(), simRange.soffset(), simRange.finish(), simRange.foffset());
  11610. };
  11611. var getStart$1 = function (selection) {
  11612. return selection.match({
  11613. domRange: function (rng) {
  11614. return Element.fromDom(rng.startContainer);
  11615. },
  11616. relative: function (startSitu, finishSitu) {
  11617. return Situ.getStart(startSitu);
  11618. },
  11619. exact: function (start, soffset, finish, foffset) {
  11620. return start;
  11621. }
  11622. });
  11623. };
  11624. var domRange = adt$1.domRange;
  11625. var relative = adt$1.relative;
  11626. var exact = adt$1.exact;
  11627. var getWin = function (selection) {
  11628. var start = getStart$1(selection);
  11629. return defaultView(start);
  11630. };
  11631. var range = SimRange.create;
  11632. var Selection = {
  11633. domRange: domRange,
  11634. relative: relative,
  11635. exact: exact,
  11636. exactFromRange: exactFromRange,
  11637. getWin: getWin,
  11638. range: range
  11639. };
  11640. var browser$4 = detect$3().browser;
  11641. var clamp = function (offset, element) {
  11642. var max = isText$1(element) ? get$6(element).length : children(element).length + 1;
  11643. if (offset > max) {
  11644. return max;
  11645. } else if (offset < 0) {
  11646. return 0;
  11647. }
  11648. return offset;
  11649. };
  11650. var normalizeRng = function (rng) {
  11651. return Selection.range(rng.start(), clamp(rng.soffset(), rng.start()), rng.finish(), clamp(rng.foffset(), rng.finish()));
  11652. };
  11653. var isOrContains = function (root, elm) {
  11654. return !NodeType.isRestrictedNode(elm.dom()) && (contains$2(root, elm) || eq(root, elm));
  11655. };
  11656. var isRngInRoot = function (root) {
  11657. return function (rng) {
  11658. return isOrContains(root, rng.start()) && isOrContains(root, rng.finish());
  11659. };
  11660. };
  11661. var shouldStore = function (editor) {
  11662. return editor.inline === true || browser$4.isIE();
  11663. };
  11664. var nativeRangeToSelectionRange = function (r) {
  11665. return Selection.range(Element.fromDom(r.startContainer), r.startOffset, Element.fromDom(r.endContainer), r.endOffset);
  11666. };
  11667. var readRange = function (win) {
  11668. var selection = win.getSelection();
  11669. var rng = !selection || selection.rangeCount === 0 ? Option.none() : Option.from(selection.getRangeAt(0));
  11670. return rng.map(nativeRangeToSelectionRange);
  11671. };
  11672. var getBookmark$2 = function (root) {
  11673. var win = defaultView(root);
  11674. return readRange(win.dom()).filter(isRngInRoot(root));
  11675. };
  11676. var validate = function (root, bookmark) {
  11677. return Option.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng);
  11678. };
  11679. var bookmarkToNativeRng = function (bookmark) {
  11680. var rng = domGlobals.document.createRange();
  11681. try {
  11682. rng.setStart(bookmark.start().dom(), bookmark.soffset());
  11683. rng.setEnd(bookmark.finish().dom(), bookmark.foffset());
  11684. return Option.some(rng);
  11685. } catch (_) {
  11686. return Option.none();
  11687. }
  11688. };
  11689. var store = function (editor) {
  11690. var newBookmark = shouldStore(editor) ? getBookmark$2(Element.fromDom(editor.getBody())) : Option.none();
  11691. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
  11692. };
  11693. var storeNative = function (editor, rng) {
  11694. var root = Element.fromDom(editor.getBody());
  11695. var range = shouldStore(editor) ? Option.from(rng) : Option.none();
  11696. var newBookmark = range.map(nativeRangeToSelectionRange).filter(isRngInRoot(root));
  11697. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
  11698. };
  11699. var getRng = function (editor) {
  11700. var bookmark = editor.bookmark ? editor.bookmark : Option.none();
  11701. return bookmark.bind(function (x) {
  11702. return validate(Element.fromDom(editor.getBody()), x);
  11703. }).bind(bookmarkToNativeRng);
  11704. };
  11705. var restore = function (editor) {
  11706. getRng(editor).each(function (rng) {
  11707. editor.selection.setRng(rng);
  11708. });
  11709. };
  11710. var SelectionBookmark = {
  11711. store: store,
  11712. storeNative: storeNative,
  11713. readRange: readRange,
  11714. restore: restore,
  11715. getRng: getRng,
  11716. getBookmark: getBookmark$2,
  11717. validate: validate
  11718. };
  11719. var isEditorUIElement = function (elm) {
  11720. var className = elm.className.toString();
  11721. return className.indexOf('tox-') !== -1 || className.indexOf('mce-') !== -1;
  11722. };
  11723. var FocusManager = { isEditorUIElement: isEditorUIElement };
  11724. var isManualNodeChange = function (e) {
  11725. return e.type === 'nodechange' && e.selectionChange;
  11726. };
  11727. var registerPageMouseUp = function (editor, throttledStore) {
  11728. var mouseUpPage = function () {
  11729. throttledStore.throttle();
  11730. };
  11731. DOMUtils$1.DOM.bind(domGlobals.document, 'mouseup', mouseUpPage);
  11732. editor.on('remove', function () {
  11733. DOMUtils$1.DOM.unbind(domGlobals.document, 'mouseup', mouseUpPage);
  11734. });
  11735. };
  11736. var registerFocusOut = function (editor) {
  11737. editor.on('focusout', function () {
  11738. SelectionBookmark.store(editor);
  11739. });
  11740. };
  11741. var registerMouseUp = function (editor, throttledStore) {
  11742. editor.on('mouseup touchend', function (e) {
  11743. throttledStore.throttle();
  11744. });
  11745. };
  11746. var registerEditorEvents = function (editor, throttledStore) {
  11747. var browser = detect$3().browser;
  11748. if (browser.isIE()) {
  11749. registerFocusOut(editor);
  11750. } else {
  11751. registerMouseUp(editor, throttledStore);
  11752. }
  11753. editor.on('keyup NodeChange', function (e) {
  11754. if (!isManualNodeChange(e)) {
  11755. SelectionBookmark.store(editor);
  11756. }
  11757. });
  11758. };
  11759. var register = function (editor) {
  11760. var throttledStore = first(function () {
  11761. SelectionBookmark.store(editor);
  11762. }, 0);
  11763. editor.on('init', function () {
  11764. if (editor.inline) {
  11765. registerPageMouseUp(editor, throttledStore);
  11766. }
  11767. registerEditorEvents(editor, throttledStore);
  11768. });
  11769. editor.on('remove', function () {
  11770. throttledStore.cancel();
  11771. });
  11772. };
  11773. var SelectionRestore = { register: register };
  11774. var documentFocusInHandler;
  11775. var DOM$1 = DOMUtils$1.DOM;
  11776. var isEditorUIElement$1 = function (elm) {
  11777. return FocusManager.isEditorUIElement(elm);
  11778. };
  11779. var isEditorContentAreaElement = function (elm) {
  11780. var classList = elm.classList;
  11781. if (classList !== undefined) {
  11782. return classList.contains('tox-edit-area') || classList.contains('tox-edit-area__iframe') || classList.contains('mce-content-body');
  11783. } else {
  11784. return false;
  11785. }
  11786. };
  11787. var isUIElement = function (editor, elm) {
  11788. var customSelector = editor ? editor.settings.custom_ui_selector : '';
  11789. var parent = DOM$1.getParent(elm, function (elm) {
  11790. return isEditorUIElement$1(elm) || (customSelector ? editor.dom.is(elm, customSelector) : false);
  11791. });
  11792. return parent !== null;
  11793. };
  11794. var getActiveElement = function () {
  11795. try {
  11796. return domGlobals.document.activeElement;
  11797. } catch (ex) {
  11798. return domGlobals.document.body;
  11799. }
  11800. };
  11801. var registerEvents = function (editorManager, e) {
  11802. var editor = e.editor;
  11803. SelectionRestore.register(editor);
  11804. editor.on('focusin', function () {
  11805. var self = this;
  11806. var focusedEditor = editorManager.focusedEditor;
  11807. if (focusedEditor !== self) {
  11808. if (focusedEditor) {
  11809. focusedEditor.fire('blur', { focusedEditor: self });
  11810. }
  11811. editorManager.setActive(self);
  11812. editorManager.focusedEditor = self;
  11813. self.fire('focus', { blurredEditor: focusedEditor });
  11814. self.focus(true);
  11815. }
  11816. });
  11817. editor.on('focusout', function () {
  11818. var self = this;
  11819. Delay.setEditorTimeout(self, function () {
  11820. var focusedEditor = editorManager.focusedEditor;
  11821. if (!isUIElement(self, getActiveElement()) && focusedEditor === self) {
  11822. self.fire('blur', { focusedEditor: null });
  11823. editorManager.focusedEditor = null;
  11824. }
  11825. });
  11826. });
  11827. if (!documentFocusInHandler) {
  11828. documentFocusInHandler = function (e) {
  11829. var activeEditor = editorManager.activeEditor;
  11830. var target;
  11831. target = e.target;
  11832. if (activeEditor && target.ownerDocument === domGlobals.document) {
  11833. if (target !== domGlobals.document.body && !isUIElement(activeEditor, target) && editorManager.focusedEditor === activeEditor) {
  11834. activeEditor.fire('blur', { focusedEditor: null });
  11835. editorManager.focusedEditor = null;
  11836. }
  11837. }
  11838. };
  11839. DOM$1.bind(domGlobals.document, 'focusin', documentFocusInHandler);
  11840. }
  11841. };
  11842. var unregisterDocumentEvents = function (editorManager, e) {
  11843. if (editorManager.focusedEditor === e.editor) {
  11844. editorManager.focusedEditor = null;
  11845. }
  11846. if (!editorManager.activeEditor) {
  11847. DOM$1.unbind(domGlobals.document, 'focusin', documentFocusInHandler);
  11848. documentFocusInHandler = null;
  11849. }
  11850. };
  11851. var setup$2 = function (editorManager) {
  11852. editorManager.on('AddEditor', curry(registerEvents, editorManager));
  11853. editorManager.on('RemoveEditor', curry(unregisterDocumentEvents, editorManager));
  11854. };
  11855. var FocusController = {
  11856. setup: setup$2,
  11857. isEditorUIElement: isEditorUIElement$1,
  11858. isEditorContentAreaElement: isEditorContentAreaElement,
  11859. isUIElement: isUIElement
  11860. };
  11861. var getContentEditableHost = function (editor, node) {
  11862. return editor.dom.getParent(node, function (node) {
  11863. return editor.dom.getContentEditable(node) === 'true';
  11864. });
  11865. };
  11866. var getCollapsedNode = function (rng) {
  11867. return rng.collapsed ? Option.from(getNode(rng.startContainer, rng.startOffset)).map(Element.fromDom) : Option.none();
  11868. };
  11869. var getFocusInElement = function (root, rng) {
  11870. return getCollapsedNode(rng).bind(function (node) {
  11871. if (isTableSection(node)) {
  11872. return Option.some(node);
  11873. } else if (contains$2(root, node) === false) {
  11874. return Option.some(root);
  11875. } else {
  11876. return Option.none();
  11877. }
  11878. });
  11879. };
  11880. var normalizeSelection = function (editor, rng) {
  11881. getFocusInElement(Element.fromDom(editor.getBody()), rng).bind(function (elm) {
  11882. return CaretFinder.firstPositionIn(elm.dom());
  11883. }).fold(function () {
  11884. editor.selection.normalize();
  11885. return;
  11886. }, function (caretPos) {
  11887. return editor.selection.setRng(caretPos.toRange());
  11888. });
  11889. };
  11890. var focusBody = function (body) {
  11891. if (body.setActive) {
  11892. try {
  11893. body.setActive();
  11894. } catch (ex) {
  11895. body.focus();
  11896. }
  11897. } else {
  11898. body.focus();
  11899. }
  11900. };
  11901. var hasElementFocus = function (elm) {
  11902. return hasFocus(elm) || search(elm).isSome();
  11903. };
  11904. var hasIframeFocus = function (editor) {
  11905. return editor.iframeElement && hasFocus(Element.fromDom(editor.iframeElement));
  11906. };
  11907. var hasInlineFocus = function (editor) {
  11908. var rawBody = editor.getBody();
  11909. return rawBody && hasElementFocus(Element.fromDom(rawBody));
  11910. };
  11911. var hasUiFocus = function (editor) {
  11912. return active().filter(function (elem) {
  11913. return !FocusController.isEditorContentAreaElement(elem.dom()) && FocusController.isUIElement(editor, elem.dom());
  11914. }).isSome();
  11915. };
  11916. var hasFocus$1 = function (editor) {
  11917. return editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor);
  11918. };
  11919. var hasEditorOrUiFocus = function (editor) {
  11920. return hasFocus$1(editor) || hasUiFocus(editor);
  11921. };
  11922. var focusEditor = function (editor) {
  11923. var selection = editor.selection;
  11924. var body = editor.getBody();
  11925. var rng = selection.getRng();
  11926. editor.quirks.refreshContentEditable();
  11927. if (editor.bookmark !== undefined && hasFocus$1(editor) === false) {
  11928. SelectionBookmark.getRng(editor).each(function (bookmarkRng) {
  11929. editor.selection.setRng(bookmarkRng);
  11930. rng = bookmarkRng;
  11931. });
  11932. }
  11933. var contentEditableHost = getContentEditableHost(editor, selection.getNode());
  11934. if (editor.$.contains(body, contentEditableHost)) {
  11935. focusBody(contentEditableHost);
  11936. normalizeSelection(editor, rng);
  11937. activateEditor(editor);
  11938. return;
  11939. }
  11940. if (!editor.inline) {
  11941. if (!Env.opera) {
  11942. focusBody(body);
  11943. }
  11944. editor.getWin().focus();
  11945. }
  11946. if (Env.gecko || editor.inline) {
  11947. focusBody(body);
  11948. normalizeSelection(editor, rng);
  11949. }
  11950. activateEditor(editor);
  11951. };
  11952. var activateEditor = function (editor) {
  11953. return editor.editorManager.setActive(editor);
  11954. };
  11955. var focus = function (editor, skipFocus) {
  11956. if (editor.removed) {
  11957. return;
  11958. }
  11959. skipFocus ? activateEditor(editor) : focusEditor(editor);
  11960. };
  11961. var EditorFocus = {
  11962. focus: focus,
  11963. hasFocus: hasFocus$1,
  11964. hasEditorOrUiFocus: hasEditorOrUiFocus
  11965. };
  11966. var defaultFormat$1 = 'html';
  11967. var isTreeNode = function (content) {
  11968. return content instanceof Node$1;
  11969. };
  11970. var moveSelection = function (editor) {
  11971. if (EditorFocus.hasFocus(editor)) {
  11972. CaretFinder.firstPositionIn(editor.getBody()).each(function (pos) {
  11973. var node = pos.getNode();
  11974. var caretPos = NodeType.isTable(node) ? CaretFinder.firstPositionIn(node).getOr(pos) : pos;
  11975. editor.selection.setRng(caretPos.toRange());
  11976. });
  11977. }
  11978. };
  11979. var setEditorHtml = function (editor, html) {
  11980. editor.dom.setHTML(editor.getBody(), html);
  11981. moveSelection(editor);
  11982. };
  11983. var setContentString = function (editor, body, content, args) {
  11984. var forcedRootBlockName, padd;
  11985. if (content.length === 0 || /^\s+$/.test(content)) {
  11986. padd = '<br data-mce-bogus="1">';
  11987. if (body.nodeName === 'TABLE') {
  11988. content = '<tr><td>' + padd + '</td></tr>';
  11989. } else if (/^(UL|OL)$/.test(body.nodeName)) {
  11990. content = '<li>' + padd + '</li>';
  11991. }
  11992. forcedRootBlockName = Settings.getForcedRootBlock(editor);
  11993. if (forcedRootBlockName && editor.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) {
  11994. content = padd;
  11995. content = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs, content);
  11996. } else if (!content) {
  11997. content = '<br data-mce-bogus="1">';
  11998. }
  11999. setEditorHtml(editor, content);
  12000. editor.fire('SetContent', args);
  12001. } else {
  12002. if (args.format !== 'raw') {
  12003. content = Serializer({ validate: editor.validate }, editor.schema).serialize(editor.parser.parse(content, {
  12004. isRootContent: true,
  12005. insert: true
  12006. }));
  12007. }
  12008. args.content = isWsPreserveElement(Element.fromDom(body)) ? content : Tools.trim(content);
  12009. setEditorHtml(editor, args.content);
  12010. if (!args.no_events) {
  12011. editor.fire('SetContent', args);
  12012. }
  12013. }
  12014. return args.content;
  12015. };
  12016. var setContentTree = function (editor, body, content, args) {
  12017. filter$2(editor.parser.getNodeFilters(), editor.parser.getAttributeFilters(), content);
  12018. var html = Serializer({ validate: editor.validate }, editor.schema).serialize(content);
  12019. args.content = isWsPreserveElement(Element.fromDom(body)) ? html : Tools.trim(html);
  12020. setEditorHtml(editor, args.content);
  12021. if (!args.no_events) {
  12022. editor.fire('SetContent', args);
  12023. }
  12024. return content;
  12025. };
  12026. var setContent = function (editor, content, args) {
  12027. if (args === void 0) {
  12028. args = {};
  12029. }
  12030. args.format = args.format ? args.format : defaultFormat$1;
  12031. args.set = true;
  12032. args.content = isTreeNode(content) ? '' : content;
  12033. if (!isTreeNode(content) && !args.no_events) {
  12034. editor.fire('BeforeSetContent', args);
  12035. content = args.content;
  12036. }
  12037. return Option.from(editor.getBody()).fold(constant(content), function (body) {
  12038. return isTreeNode(content) ? setContentTree(editor, body, content, args) : setContentString(editor, body, content, args);
  12039. });
  12040. };
  12041. var firePreProcess = function (editor, args) {
  12042. return editor.fire('PreProcess', args);
  12043. };
  12044. var firePostProcess = function (editor, args) {
  12045. return editor.fire('PostProcess', args);
  12046. };
  12047. var fireRemove = function (editor) {
  12048. return editor.fire('remove');
  12049. };
  12050. var fireDetach = function (editor) {
  12051. return editor.fire('detach');
  12052. };
  12053. var fireSwitchMode = function (editor, mode) {
  12054. return editor.fire('SwitchMode', { mode: mode });
  12055. };
  12056. var fireObjectResizeStart = function (editor, target, width, height) {
  12057. editor.fire('ObjectResizeStart', {
  12058. target: target,
  12059. width: width,
  12060. height: height
  12061. });
  12062. };
  12063. var fireObjectResized = function (editor, target, width, height) {
  12064. editor.fire('ObjectResized', {
  12065. target: target,
  12066. width: width,
  12067. height: height
  12068. });
  12069. };
  12070. var Events = {
  12071. firePreProcess: firePreProcess,
  12072. firePostProcess: firePostProcess,
  12073. fireRemove: fireRemove,
  12074. fireDetach: fireDetach,
  12075. fireSwitchMode: fireSwitchMode,
  12076. fireObjectResizeStart: fireObjectResizeStart,
  12077. fireObjectResized: fireObjectResized
  12078. };
  12079. var DOM$2 = DOMUtils$1.DOM;
  12080. var restoreOriginalStyles = function (editor) {
  12081. DOM$2.setStyle(editor.id, 'display', editor.orgDisplay);
  12082. };
  12083. var safeDestroy = function (x) {
  12084. return Option.from(x).each(function (x) {
  12085. return x.destroy();
  12086. });
  12087. };
  12088. var clearDomReferences = function (editor) {
  12089. editor.contentAreaContainer = editor.formElement = editor.container = editor.editorContainer = null;
  12090. editor.bodyElement = editor.contentDocument = editor.contentWindow = null;
  12091. editor.iframeElement = editor.targetElm = null;
  12092. if (editor.selection) {
  12093. editor.selection = editor.selection.win = editor.selection.dom = editor.selection.dom.doc = null;
  12094. }
  12095. };
  12096. var restoreForm = function (editor) {
  12097. var form = editor.formElement;
  12098. if (form) {
  12099. if (form._mceOldSubmit) {
  12100. form.submit = form._mceOldSubmit;
  12101. form._mceOldSubmit = null;
  12102. }
  12103. DOM$2.unbind(form, 'submit reset', editor.formEventDelegate);
  12104. }
  12105. };
  12106. var remove$6 = function (editor) {
  12107. if (!editor.removed) {
  12108. var _selectionOverrides = editor._selectionOverrides, editorUpload = editor.editorUpload;
  12109. var body = editor.getBody();
  12110. var element = editor.getElement();
  12111. if (body) {
  12112. editor.save({ is_removing: true });
  12113. }
  12114. editor.removed = true;
  12115. editor.unbindAllNativeEvents();
  12116. if (editor.hasHiddenInput && element) {
  12117. DOM$2.remove(element.nextSibling);
  12118. }
  12119. Events.fireRemove(editor);
  12120. editor.editorManager.remove(editor);
  12121. if (!editor.inline && body) {
  12122. restoreOriginalStyles(editor);
  12123. }
  12124. Events.fireDetach(editor);
  12125. DOM$2.remove(editor.getContainer());
  12126. safeDestroy(_selectionOverrides);
  12127. safeDestroy(editorUpload);
  12128. editor.destroy();
  12129. }
  12130. };
  12131. var destroy = function (editor, automatic) {
  12132. var selection = editor.selection, dom = editor.dom;
  12133. if (editor.destroyed) {
  12134. return;
  12135. }
  12136. if (!automatic && !editor.removed) {
  12137. editor.remove();
  12138. return;
  12139. }
  12140. if (!automatic) {
  12141. editor.editorManager.off('beforeunload', editor._beforeUnload);
  12142. if (editor.theme && editor.theme.destroy) {
  12143. editor.theme.destroy();
  12144. }
  12145. safeDestroy(selection);
  12146. safeDestroy(dom);
  12147. }
  12148. restoreForm(editor);
  12149. clearDomReferences(editor);
  12150. editor.destroyed = true;
  12151. };
  12152. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  12153. var shallow$1 = function (old, nu) {
  12154. return nu;
  12155. };
  12156. var deep$1 = function (old, nu) {
  12157. var bothObjects = isObject(old) && isObject(nu);
  12158. return bothObjects ? deepMerge(old, nu) : nu;
  12159. };
  12160. var baseMerge = function (merger) {
  12161. return function () {
  12162. var objects = new Array(arguments.length);
  12163. for (var i = 0; i < objects.length; i++) {
  12164. objects[i] = arguments[i];
  12165. }
  12166. if (objects.length === 0) {
  12167. throw new Error('Can\'t merge zero objects');
  12168. }
  12169. var ret = {};
  12170. for (var j = 0; j < objects.length; j++) {
  12171. var curObject = objects[j];
  12172. for (var key in curObject) {
  12173. if (hasOwnProperty$2.call(curObject, key)) {
  12174. ret[key] = merger(ret[key], curObject[key]);
  12175. }
  12176. }
  12177. }
  12178. return ret;
  12179. };
  12180. };
  12181. var deepMerge = baseMerge(deep$1);
  12182. var merge = baseMerge(shallow$1);
  12183. var sectionResult = Immutable('sections', 'settings');
  12184. var deviceDetection = detect$3().deviceType;
  12185. var isTouch = deviceDetection.isTouch();
  12186. var isPhone = deviceDetection.isPhone();
  12187. var legacyMobilePlugins = [
  12188. 'lists',
  12189. 'autolink',
  12190. 'autosave'
  12191. ];
  12192. var defaultTouchSettings = {
  12193. table_grid: false,
  12194. object_resizing: false,
  12195. resize: false
  12196. };
  12197. var normalizePlugins = function (plugins) {
  12198. var pluginNames = isArray(plugins) ? plugins.join(' ') : plugins;
  12199. var trimmedPlugins = map(isString(pluginNames) ? pluginNames.split(' ') : [], trim);
  12200. return filter(trimmedPlugins, function (item) {
  12201. return item.length > 0;
  12202. });
  12203. };
  12204. var filterLegacyMobilePlugins = function (plugins) {
  12205. return filter(plugins, curry(contains, legacyMobilePlugins));
  12206. };
  12207. var extractSections = function (keys, settings) {
  12208. var result = bifilter(settings, function (value, key) {
  12209. return contains(keys, key);
  12210. });
  12211. return sectionResult(result.t, result.f);
  12212. };
  12213. var getSection = function (sectionResult, name, defaults) {
  12214. if (defaults === void 0) {
  12215. defaults = {};
  12216. }
  12217. var sections = sectionResult.sections();
  12218. var sectionSettings = sections.hasOwnProperty(name) ? sections[name] : {};
  12219. return Tools.extend({}, defaults, sectionSettings);
  12220. };
  12221. var hasSection = function (sectionResult, name) {
  12222. return sectionResult.sections().hasOwnProperty(name);
  12223. };
  12224. var isSectionTheme = function (sectionResult, name, theme) {
  12225. var section = sectionResult.sections();
  12226. return hasSection(sectionResult, name) && section[name].theme === theme;
  12227. };
  12228. var getSectionConfig = function (sectionResult, name) {
  12229. return hasSection(sectionResult, name) ? sectionResult.sections()[name] : {};
  12230. };
  12231. var getDefaultSettings = function (id, documentBaseUrl, isTouch, editor) {
  12232. var baseDefaults = {
  12233. id: id,
  12234. theme: 'silver',
  12235. toolbar_drawer: 'floating',
  12236. plugins: '',
  12237. document_base_url: documentBaseUrl,
  12238. add_form_submit_trigger: true,
  12239. submit_patch: true,
  12240. add_unload_trigger: true,
  12241. convert_urls: true,
  12242. relative_urls: true,
  12243. remove_script_host: true,
  12244. object_resizing: true,
  12245. doctype: '<!DOCTYPE html>',
  12246. visual: true,
  12247. font_size_legacy_values: 'xx-small,small,medium,large,x-large,xx-large,300%',
  12248. forced_root_block: 'p',
  12249. hidden_input: true,
  12250. inline_styles: true,
  12251. convert_fonts_to_spans: true,
  12252. indent: true,
  12253. indent_before: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist',
  12254. indent_after: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist',
  12255. entity_encoding: 'named',
  12256. url_converter: editor.convertURL,
  12257. url_converter_scope: editor
  12258. };
  12259. return __assign(__assign({}, baseDefaults), isTouch ? defaultTouchSettings : {});
  12260. };
  12261. var getDefaultMobileSettings = function (isPhone) {
  12262. var defaultMobileSettings = {
  12263. resize: false,
  12264. toolbar_drawer: false,
  12265. toolbar_sticky: false
  12266. };
  12267. var defaultPhoneSettings = { menubar: false };
  12268. return __assign(__assign(__assign({}, defaultTouchSettings), defaultMobileSettings), isPhone ? defaultPhoneSettings : {});
  12269. };
  12270. var getExternalPlugins = function (overrideSettings, settings) {
  12271. var userDefinedExternalPlugins = settings.external_plugins ? settings.external_plugins : {};
  12272. if (overrideSettings && overrideSettings.external_plugins) {
  12273. return Tools.extend({}, overrideSettings.external_plugins, userDefinedExternalPlugins);
  12274. } else {
  12275. return userDefinedExternalPlugins;
  12276. }
  12277. };
  12278. var combinePlugins = function (forcedPlugins, plugins) {
  12279. return [].concat(normalizePlugins(forcedPlugins)).concat(normalizePlugins(plugins));
  12280. };
  12281. var processPlugins = function (isTouchDevice, sectionResult, defaultOverrideSettings, settings) {
  12282. var forcedPlugins = normalizePlugins(defaultOverrideSettings.forced_plugins);
  12283. var desktopPlugins = normalizePlugins(settings.plugins);
  12284. var mobileConfig = getSectionConfig(sectionResult, 'mobile');
  12285. var mobilePlugins = mobileConfig.plugins ? normalizePlugins(mobileConfig.plugins) : desktopPlugins;
  12286. var platformPlugins = isTouchDevice && isSectionTheme(sectionResult, 'mobile', 'mobile') ? filterLegacyMobilePlugins(mobilePlugins) : isTouchDevice && hasSection(sectionResult, 'mobile') ? mobilePlugins : desktopPlugins;
  12287. var combinedPlugins = combinePlugins(forcedPlugins, platformPlugins);
  12288. return Tools.extend(settings, { plugins: combinedPlugins.join(' ') });
  12289. };
  12290. var isOnMobile = function (isTouchDevice, sectionResult) {
  12291. return isTouchDevice && hasSection(sectionResult, 'mobile');
  12292. };
  12293. var combineSettings = function (isTouchDevice, isPhone, defaultSettings, defaultOverrideSettings, settings) {
  12294. var defaultDeviceSettings = isTouchDevice ? { mobile: getDefaultMobileSettings(isPhone) } : {};
  12295. var sectionResult = extractSections(['mobile'], deepMerge(defaultDeviceSettings, settings));
  12296. var extendedSettings = Tools.extend(defaultSettings, defaultOverrideSettings, sectionResult.settings(), isOnMobile(isTouchDevice, sectionResult) ? getSection(sectionResult, 'mobile') : {}, {
  12297. validate: true,
  12298. external_plugins: getExternalPlugins(defaultOverrideSettings, sectionResult.settings())
  12299. });
  12300. return processPlugins(isTouchDevice, sectionResult, defaultOverrideSettings, extendedSettings);
  12301. };
  12302. var getEditorSettings = function (editor, id, documentBaseUrl, defaultOverrideSettings, settings) {
  12303. var defaultSettings = getDefaultSettings(id, documentBaseUrl, isTouch, editor);
  12304. return combineSettings(isTouch, isPhone, defaultSettings, defaultOverrideSettings, settings);
  12305. };
  12306. var getFiltered = function (predicate, editor, name) {
  12307. return Option.from(editor.settings[name]).filter(predicate);
  12308. };
  12309. var getParamObject = function (value) {
  12310. var output = {};
  12311. if (typeof value === 'string') {
  12312. each(value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(','), function (val) {
  12313. var arr = val.split('=');
  12314. if (arr.length > 1) {
  12315. output[Tools.trim(arr[0])] = Tools.trim(arr[1]);
  12316. } else {
  12317. output[Tools.trim(arr[0])] = Tools.trim(arr[0]);
  12318. }
  12319. });
  12320. } else {
  12321. output = value;
  12322. }
  12323. return output;
  12324. };
  12325. var isArrayOf = function (p) {
  12326. return function (a) {
  12327. return isArray(a) && forall(a, p);
  12328. };
  12329. };
  12330. var getParam = function (editor, name, defaultVal, type) {
  12331. var value = name in editor.settings ? editor.settings[name] : defaultVal;
  12332. if (type === 'hash') {
  12333. return getParamObject(value);
  12334. } else if (type === 'string') {
  12335. return getFiltered(isString, editor, name).getOr(defaultVal);
  12336. } else if (type === 'number') {
  12337. return getFiltered(isNumber, editor, name).getOr(defaultVal);
  12338. } else if (type === 'boolean') {
  12339. return getFiltered(isBoolean, editor, name).getOr(defaultVal);
  12340. } else if (type === 'object') {
  12341. return getFiltered(isObject, editor, name).getOr(defaultVal);
  12342. } else if (type === 'array') {
  12343. return getFiltered(isArray, editor, name).getOr(defaultVal);
  12344. } else if (type === 'string[]') {
  12345. return getFiltered(isArrayOf(isString), editor, name).getOr(defaultVal);
  12346. } else if (type === 'function') {
  12347. return getFiltered(isFunction, editor, name).getOr(defaultVal);
  12348. } else {
  12349. return value;
  12350. }
  12351. };
  12352. var getProp = function (propName, elm) {
  12353. var rawElm = elm.dom();
  12354. return rawElm[propName];
  12355. };
  12356. var getComputedSizeProp = function (propName, elm) {
  12357. return parseInt(get$2(elm, propName), 10);
  12358. };
  12359. var getClientWidth = curry(getProp, 'clientWidth');
  12360. var getClientHeight = curry(getProp, 'clientHeight');
  12361. var getMarginTop = curry(getComputedSizeProp, 'margin-top');
  12362. var getMarginLeft = curry(getComputedSizeProp, 'margin-left');
  12363. var getBoundingClientRect$1 = function (elm) {
  12364. return elm.dom().getBoundingClientRect();
  12365. };
  12366. var isInsideElementContentArea = function (bodyElm, clientX, clientY) {
  12367. var clientWidth = getClientWidth(bodyElm);
  12368. var clientHeight = getClientHeight(bodyElm);
  12369. return clientX >= 0 && clientY >= 0 && clientX <= clientWidth && clientY <= clientHeight;
  12370. };
  12371. var transpose = function (inline, elm, clientX, clientY) {
  12372. var clientRect = getBoundingClientRect$1(elm);
  12373. var deltaX = inline ? clientRect.left + elm.dom().clientLeft + getMarginLeft(elm) : 0;
  12374. var deltaY = inline ? clientRect.top + elm.dom().clientTop + getMarginTop(elm) : 0;
  12375. var x = clientX - deltaX;
  12376. var y = clientY - deltaY;
  12377. return {
  12378. x: x,
  12379. y: y
  12380. };
  12381. };
  12382. var isXYInContentArea = function (editor, clientX, clientY) {
  12383. var bodyElm = Element.fromDom(editor.getBody());
  12384. var targetElm = editor.inline ? bodyElm : documentElement(bodyElm);
  12385. var transposedPoint = transpose(editor.inline, targetElm, clientX, clientY);
  12386. return isInsideElementContentArea(targetElm, transposedPoint.x, transposedPoint.y);
  12387. };
  12388. var fromDomSafe = function (node) {
  12389. return Option.from(node).map(Element.fromDom);
  12390. };
  12391. var isEditorAttachedToDom = function (editor) {
  12392. var rawContainer = editor.inline ? editor.getBody() : editor.getContentAreaContainer();
  12393. return fromDomSafe(rawContainer).map(function (container) {
  12394. return contains$2(owner(container), container);
  12395. }).getOr(false);
  12396. };
  12397. var EditorView = {
  12398. isXYInContentArea: isXYInContentArea,
  12399. isEditorAttachedToDom: isEditorAttachedToDom
  12400. };
  12401. function NotificationManagerImpl() {
  12402. var unimplemented = function () {
  12403. throw new Error('Theme did not provide a NotificationManager implementation.');
  12404. };
  12405. return {
  12406. open: unimplemented,
  12407. close: unimplemented,
  12408. reposition: unimplemented,
  12409. getArgs: unimplemented
  12410. };
  12411. }
  12412. function NotificationManager(editor) {
  12413. var notifications = [];
  12414. var getImplementation = function () {
  12415. var theme = editor.theme;
  12416. return theme && theme.getNotificationManagerImpl ? theme.getNotificationManagerImpl() : NotificationManagerImpl();
  12417. };
  12418. var getTopNotification = function () {
  12419. return Option.from(notifications[0]);
  12420. };
  12421. var isEqual = function (a, b) {
  12422. return a.type === b.type && a.text === b.text && !a.progressBar && !a.timeout && !b.progressBar && !b.timeout;
  12423. };
  12424. var reposition = function () {
  12425. if (notifications.length > 0) {
  12426. getImplementation().reposition(notifications);
  12427. }
  12428. };
  12429. var addNotification = function (notification) {
  12430. notifications.push(notification);
  12431. };
  12432. var closeNotification = function (notification) {
  12433. findIndex(notifications, function (otherNotification) {
  12434. return otherNotification === notification;
  12435. }).each(function (index) {
  12436. notifications.splice(index, 1);
  12437. });
  12438. };
  12439. var open = function (spec) {
  12440. if (editor.removed || !EditorView.isEditorAttachedToDom(editor)) {
  12441. return;
  12442. }
  12443. return find(notifications, function (notification) {
  12444. return isEqual(getImplementation().getArgs(notification), spec);
  12445. }).getOrThunk(function () {
  12446. editor.editorManager.setActive(editor);
  12447. var notification = getImplementation().open(spec, function () {
  12448. closeNotification(notification);
  12449. reposition();
  12450. });
  12451. addNotification(notification);
  12452. reposition();
  12453. return notification;
  12454. });
  12455. };
  12456. var close = function () {
  12457. getTopNotification().each(function (notification) {
  12458. getImplementation().close(notification);
  12459. closeNotification(notification);
  12460. reposition();
  12461. });
  12462. };
  12463. var getNotifications = function () {
  12464. return notifications;
  12465. };
  12466. var registerEvents = function (editor) {
  12467. editor.on('SkinLoaded', function () {
  12468. var serviceMessage = editor.settings.service_message;
  12469. if (serviceMessage) {
  12470. open({
  12471. text: serviceMessage,
  12472. type: 'warning',
  12473. timeout: 0
  12474. });
  12475. }
  12476. });
  12477. editor.on('ResizeEditor ResizeWindow NodeChange', function () {
  12478. Delay.requestAnimationFrame(reposition);
  12479. });
  12480. editor.on('remove', function () {
  12481. each(notifications.slice(), function (notification) {
  12482. getImplementation().close(notification);
  12483. });
  12484. });
  12485. };
  12486. registerEvents(editor);
  12487. return {
  12488. open: open,
  12489. close: close,
  12490. getNotifications: getNotifications
  12491. };
  12492. }
  12493. function WindowManagerImpl () {
  12494. var unimplemented = function () {
  12495. throw new Error('Theme did not provide a WindowManager implementation.');
  12496. };
  12497. return {
  12498. open: unimplemented,
  12499. openUrl: unimplemented,
  12500. alert: unimplemented,
  12501. confirm: unimplemented,
  12502. close: unimplemented,
  12503. getParams: unimplemented,
  12504. setParams: unimplemented
  12505. };
  12506. }
  12507. var WindowManager = function (editor) {
  12508. var dialogs = [];
  12509. var getImplementation = function () {
  12510. var theme = editor.theme;
  12511. return theme && theme.getWindowManagerImpl ? theme.getWindowManagerImpl() : WindowManagerImpl();
  12512. };
  12513. var funcBind = function (scope, f) {
  12514. return function () {
  12515. return f ? f.apply(scope, arguments) : undefined;
  12516. };
  12517. };
  12518. var fireOpenEvent = function (dialog) {
  12519. editor.fire('OpenWindow', { dialog: dialog });
  12520. };
  12521. var fireCloseEvent = function (dialog) {
  12522. editor.fire('CloseWindow', { dialog: dialog });
  12523. };
  12524. var addDialog = function (dialog) {
  12525. dialogs.push(dialog);
  12526. fireOpenEvent(dialog);
  12527. };
  12528. var closeDialog = function (dialog) {
  12529. fireCloseEvent(dialog);
  12530. dialogs = filter(dialogs, function (otherDialog) {
  12531. return otherDialog !== dialog;
  12532. });
  12533. if (dialogs.length === 0) {
  12534. editor.focus();
  12535. }
  12536. };
  12537. var getTopDialog = function () {
  12538. return Option.from(dialogs[dialogs.length - 1]);
  12539. };
  12540. var storeSelectionAndOpenDialog = function (openDialog) {
  12541. editor.editorManager.setActive(editor);
  12542. SelectionBookmark.store(editor);
  12543. var dialog = openDialog();
  12544. addDialog(dialog);
  12545. return dialog;
  12546. };
  12547. var open = function (args, params) {
  12548. return storeSelectionAndOpenDialog(function () {
  12549. return getImplementation().open(args, params, closeDialog);
  12550. });
  12551. };
  12552. var openUrl = function (args) {
  12553. return storeSelectionAndOpenDialog(function () {
  12554. return getImplementation().openUrl(args, closeDialog);
  12555. });
  12556. };
  12557. var alert = function (message, callback, scope) {
  12558. getImplementation().alert(message, funcBind(scope ? scope : this, callback));
  12559. };
  12560. var confirm = function (message, callback, scope) {
  12561. getImplementation().confirm(message, funcBind(scope ? scope : this, callback));
  12562. };
  12563. var close = function () {
  12564. getTopDialog().each(function (dialog) {
  12565. getImplementation().close(dialog);
  12566. closeDialog(dialog);
  12567. });
  12568. };
  12569. editor.on('remove', function () {
  12570. each(dialogs, function (dialog) {
  12571. getImplementation().close(dialog);
  12572. });
  12573. });
  12574. return {
  12575. open: open,
  12576. openUrl: openUrl,
  12577. alert: alert,
  12578. confirm: confirm,
  12579. close: close
  12580. };
  12581. };
  12582. var displayNotification = function (editor, message) {
  12583. editor.notificationManager.open({
  12584. type: 'error',
  12585. text: message
  12586. });
  12587. };
  12588. var displayError = function (editor, message) {
  12589. if (editor._skinLoaded) {
  12590. displayNotification(editor, message);
  12591. } else {
  12592. editor.on('SkinLoaded', function () {
  12593. displayNotification(editor, message);
  12594. });
  12595. }
  12596. };
  12597. var uploadError = function (editor, message) {
  12598. displayError(editor, I18n.translate([
  12599. 'Failed to upload image: {0}',
  12600. message
  12601. ]));
  12602. };
  12603. var logError = function (msg) {
  12604. domGlobals.console.error(msg);
  12605. };
  12606. var createLoadError = function (type, url, name) {
  12607. return name ? 'Failed to load ' + type + ': ' + name + ' from url ' + url : 'Failed to load ' + type + ' url: ' + url;
  12608. };
  12609. var pluginLoadError = function (url, name) {
  12610. logError(createLoadError('plugin', url, name));
  12611. };
  12612. var iconsLoadError = function (url, name) {
  12613. logError(createLoadError('icons', url, name));
  12614. };
  12615. var languageLoadError = function (url, name) {
  12616. logError(createLoadError('language', url, name));
  12617. };
  12618. var pluginInitError = function (editor, name, err) {
  12619. var message = I18n.translate([
  12620. 'Failed to initialize plugin: {0}',
  12621. name
  12622. ]);
  12623. initError(message, err);
  12624. displayError(editor, message);
  12625. };
  12626. var initError = function (message) {
  12627. var x = [];
  12628. for (var _i = 1; _i < arguments.length; _i++) {
  12629. x[_i - 1] = arguments[_i];
  12630. }
  12631. var console = domGlobals.window.console;
  12632. if (console) {
  12633. if (console.error) {
  12634. console.error.apply(console, arguments);
  12635. } else {
  12636. console.log.apply(console, arguments);
  12637. }
  12638. }
  12639. };
  12640. var ErrorReporter = {
  12641. pluginLoadError: pluginLoadError,
  12642. iconsLoadError: iconsLoadError,
  12643. languageLoadError: languageLoadError,
  12644. pluginInitError: pluginInitError,
  12645. uploadError: uploadError,
  12646. displayError: displayError,
  12647. initError: initError
  12648. };
  12649. var getAll = function () {
  12650. return {
  12651. 'accessibility-check': '<svg width="24" height="24"><path d="M12 2a2 2 0 0 1 2 2 2 2 0 0 1-2 2 2 2 0 0 1-2-2c0-1.1.9-2 2-2zm8 7h-5v12c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-5c0-.6-.4-1-1-1a1 1 0 0 0-1 1v5c0 .6-.4 1-1 1a1 1 0 0 1-1-1V9H4a1 1 0 1 1 0-2h16c.6 0 1 .4 1 1s-.4 1-1 1z" fill-rule="nonzero"/></svg>',
  12652. 'action-next': '<svg width="24" height="24"><path fill-rule="nonzero" d="M5.7 7.3a1 1 0 0 0-1.4 1.4l7.7 7.7 7.7-7.7a1 1 0 1 0-1.4-1.4L12 13.6 5.7 7.3z"/></svg>',
  12653. 'action-prev': '<svg width="24" height="24"><path fill-rule="nonzero" d="M18.3 15.7a1 1 0 0 0 1.4-1.4L12 6.6l-7.7 7.7a1 1 0 0 0 1.4 1.4L12 9.4l6.3 6.3z"/></svg>',
  12654. 'align-center': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm3 4h8c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 1 1 0-2zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2zm-3-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12655. 'align-justify': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0 4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12656. 'align-left': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 4h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12657. 'align-none': '<svg width="24" height="24"><path d="M14.2 5L13 7H5a1 1 0 1 1 0-2h9.2zm4 0h.8a1 1 0 0 1 0 2h-2l1.2-2zm-6.4 4l-1.2 2H5a1 1 0 0 1 0-2h6.8zm4 0H19a1 1 0 0 1 0 2h-4.4l1.2-2zm-6.4 4l-1.2 2H5a1 1 0 0 1 0-2h4.4zm4 0H19a1 1 0 0 1 0 2h-6.8l1.2-2zM7 17l-1.2 2H5a1 1 0 0 1 0-2h2zm4 0h8a1 1 0 0 1 0 2H9.8l1.2-2zm5.2-13.5l1.3.7-9.7 16.3-1.3-.7 9.7-16.3z" fill-rule="evenodd"/></svg>',
  12658. 'align-right': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm6 4h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm-6-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12659. 'arrow-left': '<svg width="24" height="24"><path d="M5.6 13l12 6a1 1 0 0 0 1.4-1V6a1 1 0 0 0-1.4-.9l-12 6a1 1 0 0 0 0 1.8z" fill-rule="evenodd"/></svg>',
  12660. 'arrow-right': '<svg width="24" height="24"><path d="M18.5 13l-12 6A1 1 0 0 1 5 18V6a1 1 0 0 1 1.4-.9l12 6a1 1 0 0 1 0 1.8z" fill-rule="evenodd"/></svg>',
  12661. 'bold': '<svg width="24" height="24"><path d="M7.8 19c-.3 0-.5 0-.6-.2l-.2-.5V5.7c0-.2 0-.4.2-.5l.6-.2h5c1.5 0 2.7.3 3.5 1 .7.6 1.1 1.4 1.1 2.5a3 3 0 0 1-.6 1.9c-.4.6-1 1-1.6 1.2.4.1.9.3 1.3.6s.8.7 1 1.2c.4.4.5 1 .5 1.6 0 1.3-.4 2.3-1.3 3-.8.7-2.1 1-3.8 1H7.8zm5-8.3c.6 0 1.2-.1 1.6-.5.4-.3.6-.7.6-1.3 0-1.1-.8-1.7-2.3-1.7H9.3v3.5h3.4zm.5 6c.7 0 1.3-.1 1.7-.4.4-.4.6-.9.6-1.5s-.2-1-.7-1.4c-.4-.3-1-.4-2-.4H9.4v3.8h4z" fill-rule="evenodd"/></svg>',
  12662. 'bookmark': '<svg width="24" height="24"><path d="M6 4v17l6-4 6 4V4c0-.6-.4-1-1-1H7a1 1 0 0 0-1 1z" fill-rule="nonzero"/></svg>',
  12663. 'border-width': '<svg width="24" height="24"><path d="M5 14.8h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2zm-.5 3.7h15c.3 0 .5.2.5.5s-.2.5-.5.5h-15a.5.5 0 1 1 0-1zm.5-8.3h14c.6 0 1 .4 1 1v1c0 .5-.4 1-1 1H5a1 1 0 0 1-1-1v-1c0-.6.4-1 1-1zm0-5.7h14c.6 0 1 .4 1 1v2c0 .6-.4 1-1 1H5a1 1 0 0 1-1-1v-2c0-.6.4-1 1-1z" fill-rule="evenodd"/></svg>',
  12664. 'brightness': '<svg width="24" height="24"><path d="M12 17c.3 0 .5.1.7.3.2.2.3.4.3.7v1c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3 1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7v-1c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3zm0-10a1 1 0 0 1-.7-.3A1 1 0 0 1 11 6V5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3.3 0 .5.1.7.3.2.2.3.4.3.7v1c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3zm7 4c.3 0 .5.1.7.3.2.2.3.4.3.7 0 .3-.1.5-.3.7a1 1 0 0 1-.7.3h-1a1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h1zM7 12c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3H5a1 1 0 0 1-.7-.3A1 1 0 0 1 4 12c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h1c.3 0 .5.1.7.3.2.2.3.4.3.7zm10 3.5l.7.8c.2.1.3.4.3.6 0 .3-.1.6-.3.8a1 1 0 0 1-.8.3 1 1 0 0 1-.6-.3l-.8-.7a1 1 0 0 1-.3-.8c0-.2.1-.5.3-.7a1 1 0 0 1 1.4 0zm-10-7l-.7-.8a1 1 0 0 1-.3-.6c0-.3.1-.6.3-.8.2-.2.5-.3.8-.3.2 0 .5.1.7.3l.7.7c.2.2.3.5.3.8 0 .2-.1.5-.3.7a1 1 0 0 1-.7.3 1 1 0 0 1-.8-.3zm10 0a1 1 0 0 1-.8.3 1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7c0-.3.1-.6.3-.8l.8-.7c.1-.2.4-.3.6-.3.3 0 .6.1.8.3.2.2.3.5.3.8 0 .2-.1.5-.3.7l-.7.7zm-10 7c.2-.2.5-.3.8-.3.2 0 .5.1.7.3a1 1 0 0 1 0 1.4l-.8.8a1 1 0 0 1-.6.3 1 1 0 0 1-.8-.3 1 1 0 0 1-.3-.8c0-.2.1-.5.3-.6l.7-.8zM12 8a4 4 0 0 1 3.7 2.4 4 4 0 0 1 0 3.2A4 4 0 0 1 12 16a4 4 0 0 1-3.7-2.4 4 4 0 0 1 0-3.2A4 4 0 0 1 12 8zm0 6.5c.7 0 1.3-.2 1.8-.7.5-.5.7-1.1.7-1.8s-.2-1.3-.7-1.8c-.5-.5-1.1-.7-1.8-.7s-1.3.2-1.8.7c-.5.5-.7 1.1-.7 1.8s.2 1.3.7 1.8c.5.5 1.1.7 1.8.7z" fill-rule="evenodd"/></svg>',
  12665. 'browse': '<svg width="24" height="24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-4v-2h4V8H5v10h4v2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm-8 9.4l-2.3 2.3a1 1 0 1 1-1.4-1.4l4-4a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1-1.4 1.4L13 13.4V20a1 1 0 0 1-2 0v-6.6z" fill-rule="nonzero"/></svg>',
  12666. 'cancel': '<svg width="24" height="24"><path d="M12 4.6a7.4 7.4 0 1 1 0 14.8 7.4 7.4 0 0 1 0-14.8zM12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zm0 8L14.8 8l1 1.1-2.7 2.8 2.7 2.7-1.1 1.1-2.7-2.7-2.7 2.7-1-1.1 2.6-2.7-2.7-2.7 1-1.1 2.8 2.7z" fill-rule="nonzero"/></svg>',
  12667. 'change-case': '<svg width="24" height="24"><path d="M18.4 18.2v-.6c-.5.8-1.3 1.2-2.4 1.2-2.2 0-3.3-1.6-3.3-4.8 0-3.1 1-4.7 3.3-4.7 1.1 0 1.8.3 2.4 1.1v-.6c0-.5.4-.8.8-.8s.8.3.8.8v8.4c0 .5-.4.8-.8.8a.8.8 0 0 1-.8-.8zm-2-7.4c-1.3 0-1.8.9-1.8 3.2 0 2.4.5 3.3 1.7 3.3 1.3 0 1.8-.9 1.8-3.2 0-2.4-.5-3.3-1.7-3.3zM10 15.7H5.5l-.8 2.6a1 1 0 0 1-1 .7h-.2a.7.7 0 0 1-.7-1l4-12a1 1 0 1 1 2 0l4 12a.7.7 0 0 1-.8 1h-.2a1 1 0 0 1-1-.7l-.8-2.6zm-.3-1.5l-2-6.5-1.9 6.5h3.9z" fill-rule="evenodd"/></svg>',
  12668. 'character-count': '<svg width="24" height="24"><path d="M4 11.5h16v1H4v-1zm4.8-6.8V10H7.7V5.8h-1v-1h2zM11 8.3V9h2v1h-3V7.7l2-1v-.9h-2v-1h3v2.4l-2 1zm6.3-3.4V10h-3.1V9h2.1V8h-2.1V6.8h2.1v-1h-2.1v-1h3.1zM5.8 16.4c0-.5.2-.8.5-1 .2-.2.6-.3 1.2-.3l.8.1c.2 0 .4.2.5.3l.4.4v2.8l.2.3H8.2v-.1-.2l-.6.3H7c-.4 0-.7 0-1-.2a1 1 0 0 1-.3-.9c0-.3 0-.6.3-.8.3-.2.7-.4 1.2-.4l.6-.2h.3v-.2l-.1-.2a.8.8 0 0 0-.5-.1 1 1 0 0 0-.4 0l-.3.4h-1zm2.3.8h-.2l-.2.1-.4.1a1 1 0 0 0-.4.2l-.2.2.1.3.5.1h.4l.4-.4v-.6zm2-3.4h1.2v1.7l.5-.3h.5c.5 0 .9.1 1.2.5.3.4.5.8.5 1.4 0 .6-.2 1.1-.5 1.5-.3.4-.7.6-1.3.6l-.6-.1-.4-.4v.4h-1.1v-5.4zm1.1 3.3c0 .3 0 .6.2.8a.7.7 0 0 0 1.2 0l.2-.8c0-.4 0-.6-.2-.8a.7.7 0 0 0-.6-.3l-.6.3-.2.8zm6.1-.5c0-.2 0-.3-.2-.4a.8.8 0 0 0-.5-.2c-.3 0-.5.1-.6.3l-.2.9c0 .3 0 .6.2.8.1.2.3.3.6.3.2 0 .4 0 .5-.2l.2-.4h1.1c0 .5-.3.8-.6 1.1a2 2 0 0 1-1.3.4c-.5 0-1-.2-1.3-.6a2 2 0 0 1-.5-1.4c0-.6.1-1.1.5-1.5.3-.4.8-.5 1.4-.5.5 0 1 0 1.2.3.4.3.5.7.5 1.2h-1v-.1z" fill-rule="evenodd"/></svg>',
  12669. 'checklist-rtl': '<svg width="24" height="24"><path d="M5 17h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm14.2 11c.2-.4.6-.5.9-.3.3.2.4.6.2 1L18 20c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L18 14c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L18 8c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8z" fill-rule="evenodd"/></svg>',
  12670. 'checklist': '<svg width="24" height="24"><path d="M11 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8a1 1 0 0 1 0 2h-8a1 1 0 0 1 0-2zM7.2 16c.2-.4.6-.5.9-.3.3.2.4.6.2 1L6 20c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L6 14c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L6 8c-.2.3-.7.4-1 0L3.8 6.9a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8z" fill-rule="evenodd"/></svg>',
  12671. 'checkmark': '<svg width="24" height="24"><path d="M18.2 5.4a1 1 0 0 1 1.6 1.2l-8 12a1 1 0 0 1-1.5.1l-5-5a1 1 0 1 1 1.4-1.4l4.1 4.1 7.4-11z" fill-rule="nonzero"/></svg>',
  12672. 'chevron-down': '<svg width="10" height="10"><path d="M8.7 2.2c.3-.3.8-.3 1 0 .4.4.4.9 0 1.2L5.7 7.8c-.3.3-.9.3-1.2 0L.2 3.4a.8.8 0 0 1 0-1.2c.3-.3.8-.3 1.1 0L5 6l3.7-3.8z" fill-rule="nonzero"/></svg>',
  12673. 'chevron-left': '<svg width="10" height="10"><path d="M7.8 1.3L4 5l3.8 3.7c.3.3.3.8 0 1-.4.4-.9.4-1.2 0L2.2 5.7a.8.8 0 0 1 0-1.2L6.6.2C7 0 7.4 0 7.8.2c.3.3.3.8 0 1.1z" fill-rule="nonzero"/></svg>',
  12674. 'chevron-right': '<svg width="10" height="10"><path d="M2.2 1.3a.8.8 0 0 1 0-1c.4-.4.9-.4 1.2 0l4.4 4.1c.3.4.3.9 0 1.2L3.4 9.8c-.3.3-.8.3-1.2 0a.8.8 0 0 1 0-1.1L6 5 2.2 1.3z" fill-rule="nonzero"/></svg>',
  12675. 'chevron-up': '<svg width="10" height="10"><path d="M8.7 7.8L5 4 1.3 7.8c-.3.3-.8.3-1 0a.8.8 0 0 1 0-1.2l4.1-4.4c.3-.3.9-.3 1.2 0l4.2 4.4c.3.3.3.9 0 1.2-.3.3-.8.3-1.1 0z" fill-rule="nonzero"/></svg>',
  12676. 'close': '<svg width="24" height="24"><path d="M17.3 8.2L13.4 12l3.9 3.8a1 1 0 0 1-1.5 1.5L12 13.4l-3.8 3.9a1 1 0 0 1-1.5-1.5l3.9-3.8-3.9-3.8a1 1 0 0 1 1.5-1.5l3.8 3.9 3.8-3.9a1 1 0 0 1 1.5 1.5z" fill-rule="evenodd"/></svg>',
  12677. 'code-sample': '<svg width="24" height="26"><path d="M7.1 11a2.8 2.8 0 0 1-.8 2 2.8 2.8 0 0 1 .8 2v1.7c0 .3.1.6.4.8.2.3.5.4.8.4.3 0 .4.2.4.4v.8c0 .2-.1.4-.4.4-.7 0-1.4-.3-2-.8-.5-.6-.8-1.3-.8-2V15c0-.3-.1-.6-.4-.8-.2-.3-.5-.4-.8-.4a.4.4 0 0 1-.4-.4v-.8c0-.2.2-.4.4-.4.3 0 .6-.1.8-.4.3-.2.4-.5.4-.8V9.3c0-.7.3-1.4.8-2 .6-.5 1.3-.8 2-.8.3 0 .4.2.4.4v.8c0 .2-.1.4-.4.4-.3 0-.6.1-.8.4-.3.2-.4.5-.4.8V11zm9.8 0V9.3c0-.3-.1-.6-.4-.8-.2-.3-.5-.4-.8-.4a.4.4 0 0 1-.4-.4V7c0-.2.1-.4.4-.4.7 0 1.4.3 2 .8.5.6.8 1.3.8 2V11c0 .3.1.6.4.8.2.3.5.4.8.4.2 0 .4.2.4.4v.8c0 .2-.2.4-.4.4-.3 0-.6.1-.8.4-.3.2-.4.5-.4.8v1.7c0 .7-.3 1.4-.8 2-.6.5-1.3.8-2 .8a.4.4 0 0 1-.4-.4v-.8c0-.2.1-.4.4-.4.3 0 .6-.1.8-.4.3-.2.4-.5.4-.8V15a2.8 2.8 0 0 1 .8-2 2.8 2.8 0 0 1-.8-2zm-3.3-.4c0 .4-.1.8-.5 1.1-.3.3-.7.5-1.1.5-.4 0-.8-.2-1.1-.5-.4-.3-.5-.7-.5-1.1 0-.5.1-.9.5-1.2.3-.3.7-.4 1.1-.4.4 0 .8.1 1.1.4.4.3.5.7.5 1.2zM12 13c.4 0 .8.1 1.1.5.4.3.5.7.5 1.1 0 1-.1 1.6-.5 2a3 3 0 0 1-1.1 1c-.4.3-.8.4-1.1.4a.5.5 0 0 1-.5-.5V17a3 3 0 0 0 1-.2l.6-.6c-.6 0-1-.2-1.3-.5-.2-.3-.3-.7-.3-1 0-.5.1-1 .5-1.2.3-.4.7-.5 1.1-.5z" fill-rule="evenodd"/></svg>',
  12678. 'color-levels': '<svg width="24" height="24"><path d="M17.5 11.4A9 9 0 0 1 18 14c0 .5 0 1-.2 1.4 0 .4-.3.9-.5 1.3a6.2 6.2 0 0 1-3.7 3 5.7 5.7 0 0 1-3.2 0A5.9 5.9 0 0 1 7.6 18a6.2 6.2 0 0 1-1.4-2.6 6.7 6.7 0 0 1 0-2.8c0-.4.1-.9.3-1.3a13.6 13.6 0 0 1 2.3-4A20 20 0 0 1 12 4a26.4 26.4 0 0 1 3.2 3.4 18.2 18.2 0 0 1 2.3 4zm-2 4.5c.4-.7.5-1.4.5-2a7.3 7.3 0 0 0-1-3.2c.2.6.2 1.2.2 1.9a4.5 4.5 0 0 1-1.3 3 5.3 5.3 0 0 1-2.3 1.5 4.9 4.9 0 0 1-2 .1 4.3 4.3 0 0 0 2.4.8 4 4 0 0 0 2-.6 4 4 0 0 0 1.5-1.5z" fill-rule="evenodd"/></svg>',
  12679. 'color-picker': '<svg width="24" height="24"><path d="M12 3a9 9 0 0 0 0 18 1.5 1.5 0 0 0 1.1-2.5c-.2-.3-.4-.6-.4-1 0-.8.7-1.5 1.5-1.5H16a5 5 0 0 0 5-5c0-4.4-4-8-9-8zm-5.5 9a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm3-4a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm5 0a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm3 4a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3z" fill-rule="nonzero"/></svg>',
  12680. 'color-swatch-remove-color': '<svg width="24" height="24"><path stroke="#000" stroke-width="2" d="M21 3L3 21" fill-rule="evenodd"/></svg>',
  12681. 'color-swatch': '<svg width="24" height="24"><rect x="3" y="3" width="18" height="18" rx="1" fill-rule="evenodd"/></svg>',
  12682. 'comment-add': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M9 19l3-2h7c.6 0 1-.4 1-1V6c0-.6-.4-1-1-1H5a1 1 0 0 0-1 1v10c0 .6.4 1 1 1h4v2zm-2 4v-4H5a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h14a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-6.4L7 23z"/><path d="M13 10h2a1 1 0 0 1 0 2h-2v2a1 1 0 0 1-2 0v-2H9a1 1 0 0 1 0-2h2V8a1 1 0 0 1 2 0v2z"/></g></svg>',
  12683. 'comment': '<svg width="24" height="24"><path fill-rule="nonzero" d="M9 19l3-2h7c.6 0 1-.4 1-1V6c0-.6-.4-1-1-1H5a1 1 0 0 0-1 1v10c0 .6.4 1 1 1h4v2zm-2 4v-4H5a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h14a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-6.4L7 23z"/></svg>',
  12684. 'contrast': '<svg width="24" height="24"><path d="M12 4a7.8 7.8 0 0 1 5.7 2.3A8 8 0 1 1 12 4zm-6 8a6 6 0 0 0 6 6V6a6 6 0 0 0-6 6z" fill-rule="evenodd"/></svg>',
  12685. 'copy': '<svg width="24" height="24"><path d="M16 3H6a2 2 0 0 0-2 2v11h2V5h10V3zm1 4a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V9c0-1.2.9-2 2-2h7zm0 12V9h-7v10h7z" fill-rule="nonzero"/></svg>',
  12686. 'crop': '<svg width="24" height="24"><path d="M17 8v7h2c.6 0 1 .4 1 1s-.4 1-1 1h-2v2c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-2H7V9H5a1 1 0 1 1 0-2h2V5c0-.6.4-1 1-1s1 .4 1 1v2h7l3-3 1 1-3 3zM9 9v5l5-5H9zm1 6h5v-5l-5 5z" fill-rule="evenodd"/></svg>',
  12687. 'cut': '<svg width="24" height="24"><path d="M18 15c.6.7 1 1.4 1 2.3 0 .8-.2 1.5-.7 2l-.8.5-1 .2c-.4 0-.8 0-1.2-.3a3.9 3.9 0 0 1-2.1-2.2c-.2-.5-.3-1-.2-1.5l-1-1-1 1c0 .5 0 1-.2 1.5-.1.5-.4 1-.9 1.4-.3.4-.7.6-1.2.8l-1.2.3c-.4 0-.7 0-1-.2-.3 0-.6-.3-.8-.5-.5-.5-.8-1.2-.7-2 0-.9.4-1.6 1-2.2A3.7 3.7 0 0 1 8.6 14H9l1-1-4-4-.5-1a3.3 3.3 0 0 1 0-2c0-.4.3-.7.5-1l6 6 6-6 .5 1a3.3 3.3 0 0 1 0 2c0 .4-.3.7-.5 1l-4 4 1 1h.5c.4 0 .8 0 1.2.3.5.2.9.4 1.2.8zm-8.5 2.2l.1-.4v-.3-.4a1 1 0 0 0-.2-.5 1 1 0 0 0-.4-.2 1.6 1.6 0 0 0-.8 0 2.6 2.6 0 0 0-.8.3 2.5 2.5 0 0 0-.9 1.1l-.1.4v.7l.2.5.5.2h.7a2.5 2.5 0 0 0 .8-.3 2.8 2.8 0 0 0 1-1zm2.5-2.8c.4 0 .7-.1 1-.4.3-.3.4-.6.4-1s-.1-.7-.4-1c-.3-.3-.6-.4-1-.4s-.7.1-1 .4c-.3.3-.4.6-.4 1s.1.7.4 1c.3.3.6.4 1 .4zm5.4 4l.2-.5v-.4-.3a2.6 2.6 0 0 0-.3-.8 2.4 2.4 0 0 0-.7-.7 2.5 2.5 0 0 0-.8-.3 1.5 1.5 0 0 0-.8 0 1 1 0 0 0-.4.2 1 1 0 0 0-.2.5 1.5 1.5 0 0 0 0 .7v.4l.3.4.3.4a2.8 2.8 0 0 0 .8.5l.4.1h.7l.5-.2z" fill-rule="evenodd"/></svg>',
  12688. 'document-properties': '<svg width="24" height="24"><path d="M14.4 3H7a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h10a2 2 0 0 0 2-2V7.6L14.4 3zM17 19H7V5h6v4h4v10z" fill-rule="nonzero"/></svg>',
  12689. 'drag': '<svg width="24" height="24"><path d="M13 5h2v2h-2V5zm0 4h2v2h-2V9zM9 9h2v2H9V9zm4 4h2v2h-2v-2zm-4 0h2v2H9v-2zm0 4h2v2H9v-2zm4 0h2v2h-2v-2zM9 5h2v2H9V5z" fill-rule="evenodd"/></svg>',
  12690. 'duplicate': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M16 3v2H6v11H4V5c0-1.1.9-2 2-2h10zm3 8h-2V9h-7v10h9a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V9c0-1.2.9-2 2-2h7a2 2 0 0 1 2 2v2z"/><path d="M17 14h1a1 1 0 0 1 0 2h-1v1a1 1 0 0 1-2 0v-1h-1a1 1 0 0 1 0-2h1v-1a1 1 0 0 1 2 0v1z"/></g></svg>',
  12691. 'edit-block': '<svg width="24" height="24"><path fill-rule="nonzero" d="M19.8 8.8l-9.4 9.4c-.2.2-.5.4-.9.4l-5.4 1.2 1.2-5.4.5-.8 9.4-9.4c.7-.7 1.8-.7 2.5 0l2.1 2.1c.7.7.7 1.8 0 2.5zm-2-.2l1-.9v-.3l-2.2-2.2a.3.3 0 0 0-.3 0l-1 1L18 8.5zm-1 1l-2.5-2.4-6 6 2.5 2.5 6-6zm-7 7.1l-2.6-2.4-.3.3-.1.2-.7 3 3.1-.6h.1l.4-.5z"/></svg>',
  12692. 'edit-image': '<svg width="24" height="24"><path d="M18 16h2V7a2 2 0 0 0-2-2H7v2h11v9zM6 17h15a1 1 0 0 1 0 2h-1v1a1 1 0 0 1-2 0v-1H6a2 2 0 0 1-2-2V7H3a1 1 0 1 1 0-2h1V4a1 1 0 1 1 2 0v13zm3-5.3l1.3 2 3-4.7 3.7 6H7l2-3.3z" fill-rule="nonzero"/></svg>',
  12693. 'embed-page': '<svg width="24" height="24"><path d="M19 6V5H5v14h2A13 13 0 0 1 19 6zm0 1.4c-.8.8-1.6 2.4-2.2 4.6H19V7.4zm0 5.6h-2.4c-.4 1.8-.6 3.8-.6 6h3v-6zm-4 6c0-2.2.2-4.2.6-6H13c-.7 1.8-1.1 3.8-1.1 6h3zm-4 0c0-2.2.4-4.2 1-6H9.6A12 12 0 0 0 8 19h3zM4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm11.8 9c.4-1.9 1-3.4 1.8-4.5a9.2 9.2 0 0 0-4 4.5h2.2zm-3.4 0a12 12 0 0 1 2.8-4 12 12 0 0 0-5 4h2.2z" fill-rule="nonzero"/></svg>',
  12694. 'embed': '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm1 2v14h14V5H5zm4.8 2.6l5.6 4a.5.5 0 0 1 0 .8l-5.6 4A.5.5 0 0 1 9 16V8a.5.5 0 0 1 .8-.4z" fill-rule="nonzero"/></svg>',
  12695. 'emoji': '<svg width="24" height="24"><path d="M9 11c.6 0 1-.4 1-1s-.4-1-1-1a1 1 0 0 0-1 1c0 .6.4 1 1 1zm6 0c.6 0 1-.4 1-1s-.4-1-1-1a1 1 0 0 0-1 1c0 .6.4 1 1 1zm-3 5.5c2.1 0 4-1.5 4.4-3.5H7.6c.5 2 2.3 3.5 4.4 3.5zM12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zm0 14.5a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13z" fill-rule="nonzero"/></svg>',
  12696. 'fill': '<svg width="24" height="26"><path d="M16.6 12l-9-9-1.4 1.4 2.4 2.4-5.2 5.1c-.5.6-.5 1.6 0 2.2L9 19.6a1.5 1.5 0 0 0 2.2 0l5.5-5.5c.5-.6.5-1.6 0-2.2zM5.2 13L10 8.2l4.8 4.8H5.2zM19 14.5s-2 2.2-2 3.5c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.3-2-3.5-2-3.5z" fill-rule="nonzero"/></svg>',
  12697. 'flip-horizontally': '<svg width="24" height="24"><path d="M14 19h2v-2h-2v2zm4-8h2V9h-2v2zM4 7v10c0 1.1.9 2 2 2h3v-2H6V7h3V5H6a2 2 0 0 0-2 2zm14-2v2h2a2 2 0 0 0-2-2zm-7 16h2V3h-2v18zm7-6h2v-2h-2v2zm-4-8h2V5h-2v2zm4 12a2 2 0 0 0 2-2h-2v2z" fill-rule="nonzero"/></svg>',
  12698. 'flip-vertically': '<svg width="24" height="24"><path d="M5 14v2h2v-2H5zm8 4v2h2v-2h-2zm4-14H7a2 2 0 0 0-2 2v3h2V6h10v3h2V6a2 2 0 0 0-2-2zm2 14h-2v2a2 2 0 0 0 2-2zM3 11v2h18v-2H3zm6 7v2h2v-2H9zm8-4v2h2v-2h-2zM5 18c0 1.1.9 2 2 2v-2H5z" fill-rule="nonzero"/></svg>',
  12699. 'format-painter': '<svg width="24" height="24"><path d="M18 5V4c0-.5-.4-1-1-1H5a1 1 0 0 0-1 1v4c0 .6.5 1 1 1h12c.6 0 1-.4 1-1V7h1v4H9v9c0 .6.4 1 1 1h2c.6 0 1-.4 1-1v-7h8V5h-3z" fill-rule="nonzero"/></svg>',
  12700. 'fullscreen': '<svg width="24" height="24"><path d="M15.3 10l-1.2-1.3 2.9-3h-2.3a.9.9 0 1 1 0-1.7H19c.5 0 .9.4.9.9v4.4a.9.9 0 1 1-1.8 0V7l-2.9 3zm0 4l3 3v-2.3a.9.9 0 1 1 1.7 0V19c0 .5-.4.9-.9.9h-4.4a.9.9 0 1 1 0-1.8H17l-3-2.9 1.3-1.2zM10 15.4l-2.9 3h2.3a.9.9 0 1 1 0 1.7H5a.9.9 0 0 1-.9-.9v-4.4a.9.9 0 1 1 1.8 0V17l2.9-3 1.2 1.3zM8.7 10L5.7 7v2.3a.9.9 0 0 1-1.7 0V5c0-.5.4-.9.9-.9h4.4a.9.9 0 0 1 0 1.8H7l3 2.9-1.3 1.2z" fill-rule="nonzero"/></svg>',
  12701. 'gallery': '<svg width="24" height="24"><path fill-rule="nonzero" d="M5 15.7l2.3-2.2c.3-.3.7-.3 1 0L11 16l5.1-5c.3-.4.8-.4 1 0l2 1.9V8H5v7.7zM5 18V19h3l1.8-1.9-2-2L5 17.9zm14-3l-2.5-2.4-6.4 6.5H19v-4zM4 6h16c.6 0 1 .4 1 1v13c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V7c0-.6.4-1 1-1zm6 7a2 2 0 1 1 0-4 2 2 0 0 1 0 4zM4.5 4h15a.5.5 0 1 1 0 1h-15a.5.5 0 0 1 0-1zm2-2h11a.5.5 0 1 1 0 1h-11a.5.5 0 0 1 0-1z"/></svg>',
  12702. 'gamma': '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm1 2v14h14V5H5zm6.5 11.8V14L9.2 8.7a5.1 5.1 0 0 0-.4-.8l-.1-.2H8 8v-1l.3-.1.3-.1h.7a1 1 0 0 1 .6.5l.1.3a8.5 8.5 0 0 1 .3.6l1.9 4.6 2-5.2a1 1 0 0 1 1-.6.5.5 0 0 1 .5.6L13 14v2.8a.7.7 0 0 1-1.4 0z" fill-rule="nonzero"/></svg>',
  12703. 'help': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M12 5.5a6.5 6.5 0 0 0-6 9 6.3 6.3 0 0 0 1.4 2l1 1a6.3 6.3 0 0 0 3.6 1 6.5 6.5 0 0 0 6-9 6.3 6.3 0 0 0-1.4-2l-1-1a6.3 6.3 0 0 0-3.6-1zM12 4a7.8 7.8 0 0 1 5.7 2.3A8 8 0 1 1 12 4z"/><path d="M9.6 9.7a.7.7 0 0 1-.7-.8c0-1.1 1.5-1.8 3.2-1.8 1.8 0 3.2.8 3.2 2.4 0 1.4-.4 2.1-1.5 2.8-.2 0-.3.1-.3.2a2 2 0 0 0-.8.8.8.8 0 0 1-1.4-.6c.3-.7.8-1 1.3-1.5l.4-.2c.7-.4.8-.6.8-1.5 0-.5-.6-.9-1.7-.9-.5 0-1 .1-1.4.3-.2 0-.3.1-.3.2v-.2c0 .4-.4.8-.8.8z" fill-rule="nonzero"/><circle cx="12" cy="16" r="1"/></g></svg>',
  12704. 'highlight-bg-color': '<svg width="24" height="24"><g fill-rule="evenodd"><path id="tox-icon-highlight-bg-color__color" d="M3 18h18v3H3z"/><path fill-rule="nonzero" d="M7.7 16.7H3l3.3-3.3-.7-.8L10.2 8l4 4.1-4 4.2c-.2.2-.6.2-.8 0l-.6-.7-1.1 1.1zm5-7.5L11 7.4l3-2.9a2 2 0 0 1 2.6 0L18 6c.7.7.7 2 0 2.7l-2.9 2.9-1.8-1.8-.5-.6"/></g></svg>',
  12705. 'home': '<svg width="24" height="24"><path fill-rule="nonzero" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>',
  12706. 'horizontal-rule': '<svg width="24" height="24"><path d="M4 11h16v2H4z" fill-rule="evenodd"/></svg>',
  12707. 'image-options': '<svg width="24" height="24"><path d="M6 10a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm12 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm-6 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2z" fill-rule="nonzero"/></svg>',
  12708. 'image': '<svg width="24" height="24"><path d="M5 15.7l3.3-3.2c.3-.3.7-.3 1 0L12 15l4.1-4c.3-.4.8-.4 1 0l2 1.9V5H5v10.7zM5 18V19h3l2.8-2.9-2-2L5 17.9zm14-3l-2.5-2.4-6.4 6.5H19v-4zM4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm6 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4z" fill-rule="nonzero"/></svg>',
  12709. 'indent': '<svg width="24" height="24"><path d="M7 5h12c.6 0 1 .4 1 1s-.4 1-1 1H7a1 1 0 1 1 0-2zm5 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm0 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm-5 4h12a1 1 0 0 1 0 2H7a1 1 0 0 1 0-2zm-2.6-3.8L6.2 12l-1.8-1.2a1 1 0 0 1 1.2-1.6l3 2a1 1 0 0 1 0 1.6l-3 2a1 1 0 1 1-1.2-1.6z" fill-rule="evenodd"/></svg>',
  12710. 'info': '<svg width="24" height="24"><path d="M12 4a7.8 7.8 0 0 1 5.7 2.3A8 8 0 1 1 12 4zm-1 3v2h2V7h-2zm3 10v-1h-1v-5h-3v1h1v4h-1v1h4z" fill-rule="evenodd"/></svg>',
  12711. 'insert-character': '<svg width="24" height="24"><path d="M15 18h4l1-2v4h-6v-3.3l1.4-1a6 6 0 0 0 1.8-2.9 6.3 6.3 0 0 0-.1-4.1 5.8 5.8 0 0 0-3-3.2c-.6-.3-1.3-.5-2.1-.5a5.1 5.1 0 0 0-3.9 1.8 6.3 6.3 0 0 0-1.3 6 6.2 6.2 0 0 0 1.8 3l1.4.9V20H4v-4l1 2h4v-.5l-2-1L5.4 15A6.5 6.5 0 0 1 4 11c0-1 .2-1.9.6-2.7A7 7 0 0 1 6.3 6C7.1 5.4 8 5 9 4.5c1-.3 2-.5 3.1-.5a8.8 8.8 0 0 1 5.7 2 7 7 0 0 1 1.7 2.3 6 6 0 0 1 .2 4.8c-.2.7-.6 1.3-1 1.9a7.6 7.6 0 0 1-3.6 2.5v.5z" fill-rule="evenodd"/></svg>',
  12712. 'insert-time': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M12 19a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm0 2a9 9 0 1 1 0-18 9 9 0 0 1 0 18z"/><path d="M16 12h-3V7c0-.6-.4-1-1-1a1 1 0 0 0-1 1v7h5c.6 0 1-.4 1-1s-.4-1-1-1z"/></g></svg>',
  12713. 'invert': '<svg width="24" height="24"><path d="M18 19.3L16.5 18a5.8 5.8 0 0 1-3.1 1.9 6.1 6.1 0 0 1-5.5-1.6A5.8 5.8 0 0 1 6 14v-.3l.1-1.2A13.9 13.9 0 0 1 7.7 9l-3-3 .7-.8 2.8 2.9 9 8.9 1.5 1.6-.7.6zm0-5.5v.3l-.1 1.1-.4 1-1.2-1.2a4.3 4.3 0 0 0 .2-1v-.2c0-.4 0-.8-.2-1.3l-.5-1.4a14.8 14.8 0 0 0-3-4.2L12 6a26.1 26.1 0 0 0-2.2 2.5l-1-1a20.9 20.9 0 0 1 2.9-3.3L12 4l1 .8a22.2 22.2 0 0 1 4 5.4c.6 1.2 1 2.4 1 3.6z" fill-rule="evenodd"/></svg>',
  12714. 'italic': '<svg width="24" height="24"><path d="M16.7 4.7l-.1.9h-.3c-.6 0-1 0-1.4.3-.3.3-.4.6-.5 1.1l-2.1 9.8v.6c0 .5.4.8 1.4.8h.2l-.2.8H8l.2-.8h.2c1.1 0 1.8-.5 2-1.5l2-9.8.1-.5c0-.6-.4-.8-1.4-.8h-.3l.2-.9h5.8z" fill-rule="evenodd"/></svg>',
  12715. 'line': '<svg width="24" height="24"><path d="M15 9l-8 8H4v-3l8-8 3 3zm1-1l-3-3 1-1h1c-.2 0 0 0 0 0l2 2s0 .2 0 0v1l-1 1zM4 18h16v2H4v-2z" fill-rule="evenodd"/></svg>',
  12716. 'link': '<svg width="24" height="24"><path d="M6.2 12.3a1 1 0 0 1 1.4 1.4l-2.1 2a2 2 0 1 0 2.7 2.8l4.8-4.8a1 1 0 0 0 0-1.4 1 1 0 1 1 1.4-1.3 2.9 2.9 0 0 1 0 4L9.6 20a3.9 3.9 0 0 1-5.5-5.5l2-2zm11.6-.6a1 1 0 0 1-1.4-1.4l2-2a2 2 0 1 0-2.6-2.8L11 10.3a1 1 0 0 0 0 1.4A1 1 0 1 1 9.6 13a2.9 2.9 0 0 1 0-4L14.4 4a3.9 3.9 0 0 1 5.5 5.5l-2 2z" fill-rule="nonzero"/></svg>',
  12717. 'list-bull-circle': '<svg width="48" height="48"><g fill-rule="evenodd"><path d="M11 16a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0 1a3 3 0 1 1 0-6 3 3 0 0 1 0 6zM11 26a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0 1a3 3 0 1 1 0-6 3 3 0 0 1 0 6zM11 36a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0 1a3 3 0 1 1 0-6 3 3 0 0 1 0 6z" fill-rule="nonzero"/><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/></g></svg>',
  12718. 'list-bull-default': '<svg width="48" height="48"><g fill-rule="evenodd"><circle cx="11" cy="14" r="3"/><circle cx="11" cy="24" r="3"/><circle cx="11" cy="34" r="3"/><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/></g></svg>',
  12719. 'list-bull-square': '<svg width="48" height="48"><g fill-rule="evenodd"><path d="M8 11h6v6H8zM8 21h6v6H8zM8 31h6v6H8z"/><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/></g></svg>',
  12720. 'list-num-default-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M37.4 17v-4.8l-1.6 1v-1.1l1.6-1h1.2V17zM33.3 17.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm1.7 5.7c0-1.2 1-2 2.2-2 1.3 0 2.1.8 2.1 1.8 0 .7-.3 1.2-1.3 2.2l-1.2 1v.2h2.6v1h-4.3v-.9l2-1.9c.8-.8 1-1.1 1-1.5 0-.5-.4-.8-1-.8-.5 0-.9.3-.9.9H35zm-1.7 4.3c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm3.2 7.3v-1h.7c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7s-1 .3-1 .8H35c0-1.1 1-1.8 2.2-1.8 1.2 0 2.1.6 2.1 1.6 0 .7-.4 1.2-1 1.3v.1c.7.1 1.3.7 1.3 1.4 0 1-1 1.9-2.4 1.9-1.3 0-2.2-.8-2.3-2h1.2c0 .6.5 1 1.1 1 .6 0 1-.4 1-1 0-.5-.3-.8-1-.8h-.7zm-3.3 2.7c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7z"/></g></svg>',
  12721. 'list-num-default': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M10 17v-4.8l-1.5 1v-1.1l1.6-1h1.2V17h-1.2zm3.6.1c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zm-5 5.7c0-1.2.8-2 2.1-2s2.1.8 2.1 1.8c0 .7-.3 1.2-1.4 2.2l-1.1 1v.2h2.6v1H8.6v-.9l2-1.9c.8-.8 1-1.1 1-1.5 0-.5-.4-.8-1-.8-.5 0-.9.3-.9.9H8.5zm6.3 4.3c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zM10 34.4v-1h.7c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7s-1 .3-1 .8H8.6c0-1.1 1-1.8 2.2-1.8 1.3 0 2.1.6 2.1 1.6 0 .7-.4 1.2-1 1.3v.1c.8.1 1.3.7 1.3 1.4 0 1-1 1.9-2.4 1.9-1.3 0-2.2-.8-2.3-2h1.2c0 .6.5 1 1.1 1 .7 0 1-.4 1-1 0-.5-.3-.8-1-.8h-.7zm4.7 2.7c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7z"/></g></svg>',
  12722. 'list-num-lower-alpha-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M36.5 16c-.9 0-1.5-.5-1.5-1.3s.6-1.3 1.8-1.4h1v-.4c0-.4-.2-.6-.7-.6-.4 0-.7.1-.8.4h-1.1c0-.8.8-1.4 2-1.4S39 12 39 13V16h-1.2v-.6c-.3.4-.8.7-1.4.7zm.4-.8c.6 0 1-.4 1-.9V14h-1c-.5.1-.7.3-.7.6 0 .4.3.6.7.6zM33.1 16.1c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7zM37.7 26c-.7 0-1.2-.2-1.5-.7v.7H35v-6.3h1.2v2.5c.3-.5.8-.9 1.5-.9 1.1 0 1.8 1 1.8 2.4 0 1.5-.7 2.4-1.8 2.4zm-.5-3.6c-.6 0-1 .5-1 1.3s.4 1.4 1 1.4c.7 0 1-.6 1-1.4 0-.8-.3-1.3-1-1.3zM33.2 26.1c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7zm6 7h-1c-.1-.5-.4-.8-1-.8s-1 .5-1 1.4c0 1 .4 1.4 1 1.4.5 0 .9-.2 1-.7h1c0 1-.8 1.7-2 1.7-1.4 0-2.2-.9-2.2-2.4s.8-2.4 2.2-2.4c1.2 0 2 .7 2 1.7zm-6.1 3c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12723. 'list-num-lower-alpha': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M10.3 15.2c.5 0 1-.4 1-.9V14h-1c-.5.1-.8.3-.8.6 0 .4.3.6.8.6zm-.4.9c-1 0-1.5-.6-1.5-1.4 0-.8.6-1.3 1.7-1.4h1.1v-.4c0-.4-.2-.6-.7-.6-.5 0-.8.1-.9.4h-1c0-.8.8-1.4 2-1.4 1.1 0 1.8.6 1.8 1.6V16h-1.1v-.6h-.1c-.2.4-.7.7-1.3.7zm4.6 0c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm-3.2 10c-.6 0-1.2-.3-1.4-.8v.7H8.5v-6.3H10v2.5c.3-.5.8-.9 1.4-.9 1.2 0 1.9 1 1.9 2.4 0 1.5-.7 2.4-1.9 2.4zm-.4-3.7c-.7 0-1 .5-1 1.3s.3 1.4 1 1.4c.6 0 1-.6 1-1.4 0-.8-.4-1.3-1-1.3zm4 3.7c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm-2.2 7h-1.2c0-.5-.4-.8-.9-.8-.6 0-1 .5-1 1.4 0 1 .4 1.4 1 1.4.5 0 .8-.2 1-.7h1c0 1-.8 1.7-2 1.7-1.4 0-2.2-.9-2.2-2.4s.8-2.4 2.2-2.4c1.2 0 2 .7 2 1.7zm1.8 3c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12724. 'list-num-lower-greek-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M37.4 16c-1.2 0-2-.8-2-2.3 0-1.5.8-2.4 2-2.4.6 0 1 .4 1.3 1v-.9H40v3.2c0 .4.1.5.4.5h.2v.9h-.6c-.6 0-1-.2-1-.7h-.2c-.2.4-.7.8-1.3.8zm.3-1c.6 0 1-.5 1-1.3s-.4-1.3-1-1.3-1 .5-1 1.3.4 1.4 1 1.4zM33.3 16.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zM36 21.9c0-1.5.8-2.3 2.1-2.3 1.2 0 2 .6 2 1.6 0 .6-.3 1-.9 1.3.9.3 1.3.8 1.3 1.7 0 1.2-.7 1.9-1.8 1.9-.6 0-1.1-.3-1.4-.8v2.2H36V22zm1.8 1.2v-1h.3c.5 0 .9-.2.9-.7 0-.5-.3-.8-.9-.8-.5 0-.8.3-.8 1v2.2c0 .8.4 1.3 1 1.3s1-.4 1-1-.4-1-1.2-1h-.3zM33.3 26.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zM37.1 34.6L34.8 30h1.4l1.7 3.5 1.7-3.5h1.1l-2.2 4.6v.1c.5.8.7 1.4.7 1.8 0 .4-.2.8-.4 1-.2.2-.6.3-1 .3-.9 0-1.3-.4-1.3-1.2 0-.5.2-1 .5-1.7l.1-.2zm.7 1a2 2 0 0 0-.4.9c0 .3.1.4.4.4.3 0 .4-.1.4-.4 0-.2-.1-.6-.4-1zM33.3 36.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12725. 'list-num-lower-greek': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M10.5 15c.7 0 1-.5 1-1.3s-.3-1.3-1-1.3c-.5 0-.9.5-.9 1.3s.4 1.4 1 1.4zm-.3 1c-1.1 0-1.8-.8-1.8-2.3 0-1.5.7-2.4 1.8-2.4.7 0 1.1.4 1.3 1h.1v-.9h1.2v3.2c0 .4.1.5.4.5h.2v.9h-.6c-.6 0-1-.2-1.1-.7h-.1c-.2.4-.7.8-1.4.8zm5 .1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7zm-4.9 7v-1h.3c.6 0 1-.2 1-.7 0-.5-.4-.8-1-.8-.5 0-.8.3-.8 1v2.2c0 .8.4 1.3 1.1 1.3.6 0 1-.4 1-1s-.5-1-1.3-1h-.3zM8.6 22c0-1.5.7-2.3 2-2.3 1.2 0 2 .6 2 1.6 0 .6-.3 1-.8 1.3.8.3 1.3.8 1.3 1.7 0 1.2-.8 1.9-1.9 1.9-.6 0-1.1-.3-1.3-.8v2.2H8.5V22zm6.2 4.2c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zm-4.5 8.5L8 30h1.4l1.7 3.5 1.7-3.5h1.1l-2.2 4.6v.1c.5.8.7 1.4.7 1.8 0 .4-.1.8-.4 1-.2.2-.6.3-1 .3-.9 0-1.3-.4-1.3-1.2 0-.5.2-1 .5-1.7l.1-.2zm.7 1a2 2 0 0 0-.4.9c0 .3.1.4.4.4.3 0 .4-.1.4-.4 0-.2-.1-.6-.4-1zm4.5.5c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12726. 'list-num-lower-roman-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M32.9 16v-1.2h-1.3V16H33zm0 10v-1.2h-1.3V26H33zm0 10v-1.2h-1.3V36H33z"/><path fill-rule="nonzero" d="M36 21h-1.5v5H36zM36 31h-1.5v5H36zM39 21h-1.5v5H39zM39 31h-1.5v5H39zM42 31h-1.5v5H42zM36 11h-1.5v5H36zM36 19h-1.5v1H36zM36 29h-1.5v1H36zM39 19h-1.5v1H39zM39 29h-1.5v1H39zM42 29h-1.5v1H42zM36 9h-1.5v1H36z"/></g></svg>',
  12727. 'list-num-lower-roman': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M15.1 16v-1.2h1.3V16H15zm0 10v-1.2h1.3V26H15zm0 10v-1.2h1.3V36H15z"/><path fill-rule="nonzero" d="M12 21h1.5v5H12zM12 31h1.5v5H12zM9 21h1.5v5H9zM9 31h1.5v5H9zM6 31h1.5v5H6zM12 11h1.5v5H12zM12 19h1.5v1H12zM12 29h1.5v1H12zM9 19h1.5v1H9zM9 29h1.5v1H9zM6 29h1.5v1H6zM12 9h1.5v1H12z"/></g></svg>',
  12728. 'list-num-upper-alpha-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M39.3 17l-.5-1.4h-2l-.5 1.4H35l2-6h1.6l2 6h-1.3zm-1.6-4.7l-.7 2.3h1.6l-.8-2.3zM33.4 17c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zm4.7 9.9h-2.7v-6H38c1.2 0 1.9.6 1.9 1.5 0 .6-.5 1.2-1 1.3.7.1 1.3.7 1.3 1.5 0 1-.8 1.7-2 1.7zm-1.4-5v1.5h1c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7h-1zm0 4h1.1c.7 0 1.1-.3 1.1-.8 0-.6-.4-.9-1.1-.9h-1.1V26zM33 27.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm4.9 10c-1.8 0-2.8-1.1-2.8-3.1s1-3.1 2.8-3.1c1.4 0 2.5.9 2.6 2.2h-1.3c0-.7-.6-1.1-1.3-1.1-1 0-1.6.7-1.6 2s.6 2 1.6 2c.7 0 1.2-.4 1.4-1h1.2c-.1 1.3-1.2 2.2-2.6 2.2zm-4.5 0c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12729. 'list-num-upper-alpha': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M12.6 17l-.5-1.4h-2L9.5 17H8.3l2-6H12l2 6h-1.3zM11 12.3l-.7 2.3h1.6l-.8-2.3zm4.7 4.8c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zM11.4 27H8.7v-6h2.6c1.2 0 1.9.6 1.9 1.5 0 .6-.5 1.2-1 1.3.7.1 1.3.7 1.3 1.5 0 1-.8 1.7-2 1.7zM10 22v1.5h1c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7h-1zm0 4H11c.7 0 1.1-.3 1.1-.8 0-.6-.4-.9-1.1-.9H10V26zm5.4 1.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm-4.1 10c-1.8 0-2.8-1.1-2.8-3.1s1-3.1 2.8-3.1c1.4 0 2.5.9 2.6 2.2h-1.3c0-.7-.6-1.1-1.3-1.1-1 0-1.6.7-1.6 2s.6 2 1.6 2c.7 0 1.2-.4 1.4-1h1.2c-.1 1.3-1.2 2.2-2.6 2.2zm4.5 0c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12730. 'list-num-upper-roman-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M31.6 17v-1.2H33V17h-1.3zm0 10v-1.2H33V27h-1.3zm0 10v-1.2H33V37h-1.3z"/><path fill-rule="nonzero" d="M34.5 20H36v7h-1.5zM34.5 30H36v7h-1.5zM37.5 20H39v7h-1.5zM37.5 30H39v7h-1.5zM40.5 30H42v7h-1.5zM34.5 10H36v7h-1.5z"/></g></svg>',
  12731. 'list-num-upper-roman': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M15.1 17v-1.2h1.3V17H15zm0 10v-1.2h1.3V27H15zm0 10v-1.2h1.3V37H15z"/><path fill-rule="nonzero" d="M12 20h1.5v7H12zM12 30h1.5v7H12zM9 20h1.5v7H9zM9 30h1.5v7H9zM6 30h1.5v7H6zM12 10h1.5v7H12z"/></g></svg>',
  12732. 'lock': '<svg width="24" height="24"><path d="M16.3 11c.2 0 .3 0 .5.2l.2.6v7.4c0 .3 0 .4-.2.6l-.6.2H7.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6v-7.4c0-.3 0-.4.2-.6l.5-.2H8V8c0-.8.3-1.5.9-2.1.6-.6 1.3-.9 2.1-.9h2c.8 0 1.5.3 2.1.9.6.6.9 1.3.9 2.1v3h.3zM10 8v3h4V8a1 1 0 0 0-.3-.7A1 1 0 0 0 13 7h-2a1 1 0 0 0-.7.3 1 1 0 0 0-.3.7z" fill-rule="evenodd"/></svg>',
  12733. 'ltr': '<svg width="24" height="24"><path d="M11 5h7a1 1 0 0 1 0 2h-1v11a1 1 0 0 1-2 0V7h-2v11a1 1 0 0 1-2 0v-6c-.5 0-1 0-1.4-.3A3.4 3.4 0 0 1 7.8 10a3.3 3.3 0 0 1 0-2.8 3.4 3.4 0 0 1 1.8-1.8L11 5zM4.4 16.2L6.2 15l-1.8-1.2a1 1 0 0 1 1.2-1.6l3 2a1 1 0 0 1 0 1.6l-3 2a1 1 0 1 1-1.2-1.6z" fill-rule="evenodd"/></svg>',
  12734. 'more-drawer': '<svg width="24" height="24"><path d="M6 10a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm12 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm-6 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2z" fill-rule="nonzero"/></svg>',
  12735. 'new-document': '<svg width="24" height="24"><path d="M14.4 3H7a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h10a2 2 0 0 0 2-2V7.6L14.4 3zM17 19H7V5h6v4h4v10z" fill-rule="nonzero"/></svg>',
  12736. 'new-tab': '<svg width="24" height="24"><path d="M15 13l2-2v8H5V7h8l-2 2H7v8h8v-4zm4-8v5.5l-2-2-5.6 5.5H10v-1.4L15.5 7l-2-2H19z" fill-rule="evenodd"/></svg>',
  12737. 'non-breaking': '<svg width="24" height="24"><path d="M11 11H8a1 1 0 1 1 0-2h3V6c0-.6.4-1 1-1s1 .4 1 1v3h3c.6 0 1 .4 1 1s-.4 1-1 1h-3v3c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-3zm10 4v5H3v-5c0-.6.4-1 1-1s1 .4 1 1v3h14v-3c0-.6.4-1 1-1s1 .4 1 1z" fill-rule="evenodd"/></svg>',
  12738. 'notice': '<svg width="24" height="24"><path d="M17.8 9.8L15.4 4 20 8.5v7L15.5 20h-7L4 15.5v-7L8.5 4h7l2.3 5.8zm0 0l2.2 5.7-2.3-5.8zM13 17v-2h-2v2h2zm0-4V7h-2v6h2z" fill-rule="evenodd"/></svg>',
  12739. 'ordered-list-rtl': '<svg width="24" height="24"><path d="M6 17h8a1 1 0 0 1 0 2H6a1 1 0 0 1 0-2zm0-6h8a1 1 0 0 1 0 2H6a1 1 0 0 1 0-2zm0-6h8a1 1 0 0 1 0 2H6a1 1 0 1 1 0-2zm13-1v3.5a.5.5 0 1 1-1 0V5h-.5a.5.5 0 1 1 0-1H19zm-1 8.8l.2.2h1.3a.5.5 0 1 1 0 1h-1.6a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0-.2-.2h-1.3a.5.5 0 0 1-.5-.5c0-.3.2-.5.5-.5h1.6c.5 0 .9.4.9 1v.1c0 .4-.3.8-.6 1l-1.2.4-.2.3zm2 4.2v2c0 .6-.4 1-1 1h-1.5a.5.5 0 0 1 0-1h1.2a.3.3 0 1 0 0-.6h-1.3a.4.4 0 1 1 0-.8h1.3a.3.3 0 0 0 0-.6h-1.2a.5.5 0 1 1 0-1H19c.6 0 1 .4 1 1z" fill-rule="evenodd"/></svg>',
  12740. 'ordered-list': '<svg width="24" height="24"><path d="M10 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 1 1 0-2zM6 4v3.5c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.5V5h-.5a.5.5 0 0 1 0-1H6zm-1 8.8l.2.2h1.3c.3 0 .5.2.5.5s-.2.5-.5.5H4.9a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0-.2-.2H4.5a.5.5 0 0 1-.5-.5c0-.3.2-.5.5-.5h1.6c.5 0 .9.4.9 1v.1c0 .4-.3.8-.6 1l-1.2.4-.2.3zM7 17v2c0 .6-.4 1-1 1H4.5a.5.5 0 0 1 0-1h1.2c.2 0 .3-.1.3-.3 0-.2-.1-.3-.3-.3H4.4a.4.4 0 1 1 0-.8h1.3c.2 0 .3-.1.3-.3 0-.2-.1-.3-.3-.3H4.5a.5.5 0 1 1 0-1H6c.6 0 1 .4 1 1z" fill-rule="evenodd"/></svg>',
  12741. 'orientation': '<svg width="24" height="24"><path d="M7.3 6.4L1 13l6.4 6.5 6.5-6.5-6.5-6.5zM3.7 13l3.6-3.7L11 13l-3.7 3.7-3.6-3.7zM12 6l2.8 2.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0L9.2 5.7a.8.8 0 0 1 0-1.2L13.6.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L12 4h1a9 9 0 1 1-4.3 16.9l1.5-1.5A7 7 0 1 0 13 6h-1z" fill-rule="nonzero"/></svg>',
  12742. 'outdent': '<svg width="24" height="24"><path d="M7 5h12c.6 0 1 .4 1 1s-.4 1-1 1H7a1 1 0 1 1 0-2zm5 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm0 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm-5 4h12a1 1 0 0 1 0 2H7a1 1 0 0 1 0-2zm1.6-3.8a1 1 0 0 1-1.2 1.6l-3-2a1 1 0 0 1 0-1.6l3-2a1 1 0 0 1 1.2 1.6L6.8 12l1.8 1.2z" fill-rule="evenodd"/></svg>',
  12743. 'page-break': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M5 11c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h1c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2zm4 0c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h1c.6 0 1 .4 1 1s-.4 1-1 1h-1a1 1 0 0 1 0-2zm4 0c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zM7 3v5h10V3c0-.6.4-1 1-1s1 .4 1 1v7H5V3c0-.6.4-1 1-1s1 .4 1 1zM6 22a1 1 0 0 1-1-1v-7h14v7c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-5H7v5c0 .6-.4 1-1 1z"/></g></svg>',
  12744. 'paste-text': '<svg width="24" height="24"><path d="M18 9V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h3V9h9zM9 20H6a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2h3.2A3 3 0 0 1 12 1a3 3 0 0 1 2.8 2H18a2 2 0 0 1 2 2v4h1v12H9v-1zm1.5-9.5v9h9v-9h-9zM12 3a1 1 0 0 0-1 1c0 .5.4 1 1 1s1-.5 1-1-.4-1-1-1zm0 9h6v2h-.5l-.5-1h-1v4h.8v1h-3.6v-1h.8v-4h-1l-.5 1H12v-2z" fill-rule="nonzero"/></svg>',
  12745. 'paste': '<svg width="24" height="24"><path d="M18 9V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h3V9h9zM9 20H6a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2h3.2A3 3 0 0 1 12 1a3 3 0 0 1 2.8 2H18a2 2 0 0 1 2 2v4h1v12H9v-1zm1.5-9.5v9h9v-9h-9zM12 3a1 1 0 0 0-1 1c0 .5.4 1 1 1s1-.5 1-1-.4-1-1-1z" fill-rule="nonzero"/></svg>',
  12746. 'permanent-pen': '<svg width="24" height="24"><path d="M10.5 17.5L8 20H3v-3l3.5-3.5a2 2 0 0 1 0-3L14 3l1 1-7.3 7.3a1 1 0 0 0 0 1.4l3.6 3.6c.4.4 1 .4 1.4 0L20 9l1 1-7.6 7.6a2 2 0 0 1-2.8 0l-.1-.1z" fill-rule="nonzero"/></svg>',
  12747. 'plus': '<svg width="24" height="24"><g fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke="#000" stroke-width="2"><path d="M12 5v14M5 12h14"/></g></svg>',
  12748. 'preferences': '<svg width="24" height="24"><path d="M20.1 13.5l-1.9.2a5.8 5.8 0 0 1-.6 1.5l1.2 1.5c.4.4.3 1 0 1.4l-.7.7a1 1 0 0 1-1.4 0l-1.5-1.2a6.2 6.2 0 0 1-1.5.6l-.2 1.9c0 .5-.5.9-1 .9h-1a1 1 0 0 1-1-.9l-.2-1.9a5.8 5.8 0 0 1-1.5-.6l-1.5 1.2a1 1 0 0 1-1.4 0l-.7-.7a1 1 0 0 1 0-1.4l1.2-1.5a6.2 6.2 0 0 1-.6-1.5l-1.9-.2a1 1 0 0 1-.9-1v-1c0-.5.4-1 .9-1l1.9-.2a5.8 5.8 0 0 1 .6-1.5L5.2 7.3a1 1 0 0 1 0-1.4l.7-.7a1 1 0 0 1 1.4 0l1.5 1.2a6.2 6.2 0 0 1 1.5-.6l.2-1.9c0-.5.5-.9 1-.9h1c.5 0 1 .4 1 .9l.2 1.9a5.8 5.8 0 0 1 1.5.6l1.5-1.2a1 1 0 0 1 1.4 0l.7.7c.3.4.4 1 0 1.4l-1.2 1.5a6.2 6.2 0 0 1 .6 1.5l1.9.2c.5 0 .9.5.9 1v1c0 .5-.4 1-.9 1zM12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z" fill-rule="evenodd"/></svg>',
  12749. 'preview': '<svg width="24" height="24"><path d="M3.5 12.5c.5.8 1.1 1.6 1.8 2.3 2 2 4.2 3.2 6.7 3.2s4.7-1.2 6.7-3.2a16.2 16.2 0 0 0 2.1-2.8 15.7 15.7 0 0 0-2.1-2.8c-2-2-4.2-3.2-6.7-3.2a9.3 9.3 0 0 0-6.7 3.2A16.2 16.2 0 0 0 3.2 12c0 .2.2.3.3.5zm-2.4-1l.7-1.2L4 7.8C6.2 5.4 8.9 4 12 4c3 0 5.8 1.4 8.1 3.8a18.2 18.2 0 0 1 2.8 3.7v1l-.7 1.2-2.1 2.5c-2.3 2.4-5 3.8-8.1 3.8-3 0-5.8-1.4-8.1-3.8a18.2 18.2 0 0 1-2.8-3.7 1 1 0 0 1 0-1zm12-3.3a2 2 0 1 0 2.7 2.6 4 4 0 1 1-2.6-2.6z" fill-rule="nonzero"/></svg>',
  12750. 'print': '<svg width="24" height="24"><path d="M18 8H6a3 3 0 0 0-3 3v6h2v3h14v-3h2v-6a3 3 0 0 0-3-3zm-1 10H7v-4h10v4zm.5-5c-.8 0-1.5-.7-1.5-1.5s.7-1.5 1.5-1.5 1.5.7 1.5 1.5-.7 1.5-1.5 1.5zm.5-8H6v2h12V5z" fill-rule="nonzero"/></svg>',
  12751. 'quote': '<svg width="24" height="24"><path d="M7.5 17h.9c.4 0 .7-.2.9-.6L11 13V8c0-.6-.4-1-1-1H6a1 1 0 0 0-1 1v4c0 .6.4 1 1 1h2l-1.3 2.7a1 1 0 0 0 .8 1.3zm8 0h.9c.4 0 .7-.2.9-.6L19 13V8c0-.6-.4-1-1-1h-4a1 1 0 0 0-1 1v4c0 .6.4 1 1 1h2l-1.3 2.7a1 1 0 0 0 .8 1.3z" fill-rule="nonzero"/></svg>',
  12752. 'redo': '<svg width="24" height="24"><path d="M17.6 10H12c-2.8 0-4.4 1.4-4.9 3.5-.4 2 .3 4 1.4 4.6a1 1 0 1 1-1 1.8c-2-1.2-2.9-4.1-2.3-6.8.6-3 3-5.1 6.8-5.1h5.6l-3.3-3.3a1 1 0 1 1 1.4-1.4l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4l3.3-3.3z" fill-rule="nonzero"/></svg>',
  12753. 'reload': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M5 22.1l-1.2-4.7v-.2a1 1 0 0 1 1-1l5 .4a1 1 0 1 1-.2 2l-2.2-.2a7.8 7.8 0 0 0 8.4.2 7.5 7.5 0 0 0 3.5-6.4 1 1 0 1 1 2 0 9.5 9.5 0 0 1-4.5 8 9.9 9.9 0 0 1-10.2 0l.4 1.4a1 1 0 1 1-2 .5zM13.6 7.4c0-.5.5-1 1-.9l2.8.2a8 8 0 0 0-9.5-1 7.5 7.5 0 0 0-3.6 7 1 1 0 0 1-2 0 9.5 9.5 0 0 1 4.5-8.6 10 10 0 0 1 10.9.3l-.3-1a1 1 0 0 1 2-.5l1.1 4.8a1 1 0 0 1-1 1.2l-5-.4a1 1 0 0 1-.9-1z"/></g></svg>',
  12754. 'remove-formatting': '<svg width="24" height="24"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8zM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1z" fill-rule="evenodd"/></svg>',
  12755. 'remove': '<svg width="24" height="24"><path d="M16 7h3a1 1 0 0 1 0 2h-1v9a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3V9H5a1 1 0 1 1 0-2h3V6a3 3 0 0 1 3-3h2a3 3 0 0 1 3 3v1zm-2 0V6c0-.6-.4-1-1-1h-2a1 1 0 0 0-1 1v1h4zm2 2H8v9c0 .6.4 1 1 1h6c.6 0 1-.4 1-1V9zm-7 3a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4zm4 0a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4z" fill-rule="nonzero"/></svg>',
  12756. 'resize-handle': '<svg width="10" height="10"><g fill-rule="nonzero"><path d="M8.1 1.1A.5.5 0 1 1 9 2l-7 7A.5.5 0 1 1 1 8l7-7zM8.1 5.1A.5.5 0 1 1 9 6l-3 3A.5.5 0 1 1 5 8l3-3z"/></g></svg>',
  12757. 'resize': '<svg width="24" height="24"><path d="M4 5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h6c.3 0 .5.1.7.3.2.2.3.4.3.7 0 .3-.1.5-.3.7a1 1 0 0 1-.7.3H7.4L18 16.6V13c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3.3 0 .5.1.7.3.2.2.3.4.3.7v6c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3h-6a1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h3.6L6 7.4V11c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3 1 1 0 0 1-.7-.3A1 1 0 0 1 4 11V5z" fill-rule="evenodd"/></svg>',
  12758. 'restore-draft': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M17 13c0 .6-.4 1-1 1h-4V8c0-.6.4-1 1-1s1 .4 1 1v4h2c.6 0 1 .4 1 1z"/><path d="M4.7 10H9a1 1 0 0 1 0 2H3a1 1 0 0 1-1-1V5a1 1 0 1 1 2 0v3l2.5-2.4a9.2 9.2 0 0 1 10.8-1.5A9 9 0 0 1 13.4 21c-2.4.1-4.7-.7-6.5-2.2a1 1 0 1 1 1.3-1.5 7.2 7.2 0 0 0 11.6-3.7 7 7 0 0 0-3.5-7.7A7.2 7.2 0 0 0 8 7L4.7 10z" fill-rule="nonzero"/></g></svg>',
  12759. 'rotate-left': '<svg width="24" height="24"><path d="M4.7 10H9a1 1 0 0 1 0 2H3a1 1 0 0 1-1-1V5a1 1 0 1 1 2 0v3l2.5-2.4a9.2 9.2 0 0 1 10.8-1.5A9 9 0 0 1 13.4 21c-2.4.1-4.7-.7-6.5-2.2a1 1 0 1 1 1.3-1.5 7.2 7.2 0 0 0 11.6-3.7 7 7 0 0 0-3.5-7.7A7.2 7.2 0 0 0 8 7L4.7 10z" fill-rule="nonzero"/></svg>',
  12760. 'rotate-right': '<svg width="24" height="24"><path d="M20 8V5a1 1 0 0 1 2 0v6c0 .6-.4 1-1 1h-6a1 1 0 0 1 0-2h4.3L16 7A7.2 7.2 0 0 0 7.7 6a7 7 0 0 0 3 13.1c1.9.1 3.7-.5 5-1.7a1 1 0 0 1 1.4 1.5A9.2 9.2 0 0 1 2.2 14c-.9-3.9 1-8 4.5-9.9 3.5-1.9 8-1.3 10.8 1.5L20 8z" fill-rule="nonzero"/></svg>',
  12761. 'rtl': '<svg width="24" height="24"><path d="M8 5h8v2h-2v12h-2V7h-2v12H8v-7c-.5 0-1 0-1.4-.3A3.4 3.4 0 0 1 4.8 10a3.3 3.3 0 0 1 0-2.8 3.4 3.4 0 0 1 1.8-1.8L8 5zm12 11.2a1 1 0 1 1-1 1.6l-3-2a1 1 0 0 1 0-1.6l3-2a1 1 0 1 1 1 1.6L18.4 15l1.8 1.2z" fill-rule="evenodd"/></svg>',
  12762. 'save': '<svg width="24" height="24"><path d="M5 16h14a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2zm0 2v2h14v-2H5zm10 0h2v2h-2v-2zm-4-6.4L8.7 9.3a1 1 0 1 0-1.4 1.4l4 4c.4.4 1 .4 1.4 0l4-4a1 1 0 1 0-1.4-1.4L13 11.6V4a1 1 0 0 0-2 0v7.6z" fill-rule="nonzero"/></svg>',
  12763. 'search': '<svg width="24" height="24"><path d="M16 17.3a8 8 0 1 1 1.4-1.4l4.3 4.4a1 1 0 0 1-1.4 1.4l-4.4-4.3zm-5-.3a6 6 0 1 0 0-12 6 6 0 0 0 0 12z" fill-rule="nonzero"/></svg>',
  12764. 'select-all': '<svg width="24" height="24"><path d="M3 5h2V3a2 2 0 0 0-2 2zm0 8h2v-2H3v2zm4 8h2v-2H7v2zM3 9h2V7H3v2zm10-6h-2v2h2V3zm6 0v2h2a2 2 0 0 0-2-2zM5 21v-2H3c0 1.1.9 2 2 2zm-2-4h2v-2H3v2zM9 3H7v2h2V3zm2 18h2v-2h-2v2zm8-8h2v-2h-2v2zm0 8a2 2 0 0 0 2-2h-2v2zm0-12h2V7h-2v2zm0 8h2v-2h-2v2zm-4 4h2v-2h-2v2zm0-16h2V3h-2v2zM7 17h10V7H7v10zm2-8h6v6H9V9z" fill-rule="nonzero"/></svg>',
  12765. 'selected': '<svg width="24" height="24"><path fill-rule="nonzero" d="M6 4h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2zm3.6 10.9L7 12.3a.7.7 0 0 0-1 1L9.6 17 18 8.6a.7.7 0 0 0 0-1 .7.7 0 0 0-1 0l-7.4 7.3z"/></svg>',
  12766. 'settings': '<svg width="24" height="24"><path d="M11 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8v.3c0 .2 0 .3-.2.5l-.6.2H7.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6V8H5a1 1 0 1 1 0-2h2v-.3c0-.2 0-.3.2-.5l.5-.2h2.5c.3 0 .4 0 .6.2l.2.5V6zM8 8h2V6H8v2zm9 2.8v.2h2c.6 0 1 .4 1 1s-.4 1-1 1h-2v.3c0 .2 0 .3-.2.5l-.6.2h-2.4c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6V13H5a1 1 0 0 1 0-2h8v-.3c0-.2 0-.3.2-.5l.6-.2h2.4c.3 0 .4 0 .6.2l.2.6zM14 13h2v-2h-2v2zm-3 2.8v.2h8c.6 0 1 .4 1 1s-.4 1-1 1h-8v.3c0 .2 0 .3-.2.5l-.6.2H7.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6V18H5a1 1 0 0 1 0-2h2v-.3c0-.2 0-.3.2-.5l.5-.2h2.5c.3 0 .4 0 .6.2l.2.6zM8 18h2v-2H8v2z" fill-rule="evenodd"/></svg>',
  12767. 'sharpen': '<svg width="24" height="24"><path d="M16 6l4 4-8 9-8-9 4-4h8zm-4 10.2l5.5-6.2-.1-.1H12v-.3h5.1l-.2-.2H12V9h4.6l-.2-.2H12v-.3h4.1l-.2-.2H12V8h3.6l-.2-.2H8.7L6.5 10l.1.1H12v.3H6.9l.2.2H12v.3H7.3l.2.2H12v.3H7.7l.3.2h4v.3H8.2l.2.2H12v.3H8.6l.3.2H12v.3H9l.3.2H12v.3H9.5l.2.2H12v.3h-2l.2.2H12v.3h-1.6l.2.2H12v.3h-1.1l.2.2h.9v.3h-.7l.2.2h.5v.3h-.3l.3.2z" fill-rule="evenodd"/></svg>',
  12768. 'sourcecode': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7zM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7z"/></g></svg>',
  12769. 'spell-check': '<svg width="24" height="24"><path d="M6 8v3H5V5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h2c.3 0 .5.1.7.3.2.2.3.4.3.7v6H8V8H6zm0-3v2h2V5H6zm13 0h-3v5h3v1h-3a1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7V5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h3v1zm-5 1.5l-.1.7c-.1.2-.3.3-.6.3.3 0 .5.1.6.3l.1.7V10c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3h-3V4h3c.3 0 .5.1.7.3.2.2.3.4.3.7v1.5zM13 10V8h-2v2h2zm0-3V5h-2v2h2zm3 5l1 1-6.5 7L7 15.5l1.3-1 2.2 2.2L16 12z" fill-rule="evenodd"/></svg>',
  12770. 'strike-through': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M15.6 8.5c-.5-.7-1-1.1-1.3-1.3-.6-.4-1.3-.6-2-.6-2.7 0-2.8 1.7-2.8 2.1 0 1.6 1.8 2 3.2 2.3 4.4.9 4.6 2.8 4.6 3.9 0 1.4-.7 4.1-5 4.1A6.2 6.2 0 0 1 7 16.4l1.5-1.1c.4.6 1.6 2 3.7 2 1.6 0 2.5-.4 3-1.2.4-.8.3-2-.8-2.6-.7-.4-1.6-.7-2.9-1-1-.2-3.9-.8-3.9-3.6C7.6 6 10.3 5 12.4 5c2.9 0 4.2 1.6 4.7 2.4l-1.5 1.1z"/><path d="M5 11h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2z" fill-rule="nonzero"/></g></svg>',
  12771. 'subscript': '<svg width="24" height="24"><path d="M10.4 10l4.6 4.6-1.4 1.4L9 11.4 4.4 16 3 14.6 7.6 10 3 5.4 4.4 4 9 8.6 13.6 4 15 5.4 10.4 10zM21 19h-5v-1l1-.8 1.7-1.6c.3-.4.5-.8.5-1.2 0-.3 0-.6-.2-.7-.2-.2-.5-.3-.9-.3a2 2 0 0 0-.8.2l-.7.3-.4-1.1 1-.6 1.2-.2c.8 0 1.4.3 1.8.7.4.4.6.9.6 1.5s-.2 1.1-.5 1.6a8 8 0 0 1-1.3 1.3l-.6.6h2.6V19z" fill-rule="nonzero"/></svg>',
  12772. 'superscript': '<svg width="24" height="24"><path d="M15 9.4L10.4 14l4.6 4.6-1.4 1.4L9 15.4 4.4 20 3 18.6 7.6 14 3 9.4 4.4 8 9 12.6 13.6 8 15 9.4zm5.9 1.6h-5v-1l1-.8 1.7-1.6c.3-.5.5-.9.5-1.3 0-.3 0-.5-.2-.7-.2-.2-.5-.3-.9-.3l-.8.2-.7.4-.4-1.2c.2-.2.5-.4 1-.5.3-.2.8-.2 1.2-.2.8 0 1.4.2 1.8.6.4.4.6 1 .6 1.6 0 .5-.2 1-.5 1.5l-1.3 1.4-.6.5h2.6V11z" fill-rule="nonzero"/></svg>',
  12773. 'table-cell-properties': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm10 10h-4v3h4v-3zm0-8h-4v3h4V7zM9 7H5v3h4V7zm-4 4v3h4v-3H5zm10 0v3h4v-3h-4zm0-1h4V7h-4v3zM5 15v3h4v-3H5zm10 3h4v-3h-4v3z" fill-rule="evenodd"/></svg>',
  12774. 'table-cell-select-all': '<svg width="24" height="24"><path d="M12.5 5.5v6h6v-6h-6zm-1 0h-6v6h6v-6zm1 13h6v-6h-6v6zm-1 0v-6h-6v6h6zm-7-14h15v15h-15v-15z" fill-rule="nonzero"/></svg>',
  12775. 'table-cell-select-inner': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M5.5 5.5v13h13v-13h-13zm-1-1h15v15h-15v-15z" opacity=".2"/><path d="M11.5 11.5v-7h1v7h7v1h-7v7h-1v-7h-7v-1h7z"/></g></svg>',
  12776. 'table-delete-column': '<svg width="24" height="24"><path d="M9 11.2l1 1v.2l-1 1v-2.2zm5 1l1-1v2.2l-1-1v-.2zM20 5v14H4V5h16zm-1 2h-4v.8l-.2-.2-.8.8V7h-4v1.4l-.8-.8-.2.2V7H5v11h4v-1.8l.5.5.5-.4V18h4v-1.8l.8.8.2-.3V18h4V7zm-3.9 3.4l-1.8 1.9 1.8 1.9c.4.3.4.9 0 1.2-.3.3-.8.3-1.2 0L12 13.5l-1.8 1.9a.8.8 0 0 1-1.2 0 .9.9 0 0 1 0-1.2l1.8-1.9-1.9-2a.9.9 0 0 1 1.2-1.2l2 2 1.8-1.8c.3-.4.9-.4 1.2 0a.8.8 0 0 1 0 1.1z" fill-rule="evenodd"/></svg>',
  12777. 'table-delete-row': '<svg width="24" height="24"><path d="M16.7 8.8l1.1 1.2-2.4 2.5L18 15l-1.2 1.2-2.5-2.5-2.4 2.5-1.3-1.2 2.5-2.5-2.5-2.5 1.2-1.3 2.6 2.6 2.4-2.5zM4 5h16v14H4V5zm15 5V7H5v3h4.8l1 1H5v3h5.8l-1 1H5v3h14v-3h-.4l-1-1H19v-3h-1.3l1-1h.3z" fill-rule="evenodd"/></svg>',
  12778. 'table-delete-table': '<svg width="24" height="26"><path d="M4 6h16v14H4V6zm1 2v11h14V8H5zm11.7 8.7l-1.5 1.5L12 15l-3.3 3.2-1.4-1.5 3.2-3.2-3.3-3.2 1.5-1.5L12 12l3.2-3.2 1.5 1.5-3.2 3.2 3.2 3.2z" fill-rule="evenodd"/></svg>',
  12779. 'table-insert-column-after': '<svg width="24" height="24"><path d="M14.3 9c.4 0 .7.3.7.6v2.2h2.1c.4 0 .7.3.7.7 0 .4-.3.7-.7.7H15v2.2c0 .3-.3.6-.7.6a.7.7 0 0 1-.6-.6v-2.2h-2.2a.7.7 0 0 1 0-1.4h2.2V9.6c0-.3.3-.6.6-.6zM4 5h16v14H4V5zm5 13v-3H5v3h4zm0-4v-3H5v3h4zm0-4V7H5v3h4zm10 8V7h-9v11h9z" fill-rule="evenodd"/></svg>',
  12780. 'table-insert-column-before': '<svg width="24" height="24"><path d="M9.7 16a.7.7 0 0 1-.7-.6v-2.2H6.9a.7.7 0 0 1 0-1.4H9V9.6c0-.3.3-.6.7-.6.3 0 .6.3.6.6v2.2h2.2c.4 0 .8.3.8.7 0 .4-.4.7-.8.7h-2.2v2.2c0 .3-.3.6-.6.6zM4 5h16v14H4V5zm10 13V7H5v11h9zm5 0v-3h-4v3h4zm0-4v-3h-4v3h4zm0-4V7h-4v3h4z" fill-rule="evenodd"/></svg>',
  12781. 'table-insert-row-above': '<svg width="24" height="24"><path d="M14.8 10.5c0 .3-.2.5-.5.5h-1.8v1.8c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.6V11H9.7a.5.5 0 0 1 0-1h1.8V8.3c0-.3.2-.6.5-.6s.5.3.5.6V10h1.8c.3 0 .5.2.5.5zM4 5h16v14H4V5zm5 13v-3H5v3h4zm5 0v-3h-4v3h4zm5 0v-3h-4v3h4zm0-4V7H5v7h14z" fill-rule="evenodd"/></svg>',
  12782. 'table-insert-row-after': '<svg width="24" height="24"><path d="M9.2 14.5c0-.3.2-.5.5-.5h1.8v-1.8c0-.3.2-.5.5-.5s.5.2.5.6V14h1.8c.3 0 .5.2.5.5s-.2.5-.5.5h-1.8v1.7c0 .3-.2.6-.5.6a.5.5 0 0 1-.5-.6V15H9.7a.5.5 0 0 1-.5-.5zM4 5h16v14H4V5zm6 2v3h4V7h-4zM5 7v3h4V7H5zm14 11v-7H5v7h14zm0-8V7h-4v3h4z" fill-rule="evenodd"/></svg>',
  12783. 'table-left-header': '<svg width="24" height="24"><path d="M4 5h16v13H4V5zm10 12v-3h-4v3h4zm0-4v-3h-4v3h4zm0-4V6h-4v3h4zm5 8v-3h-4v3h4zm0-4v-3h-4v3h4zm0-4V6h-4v3h4z" fill-rule="evenodd"/></svg>',
  12784. 'table-merge-cells': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm6 13h9v-7h-9v7zm4-11h-4v3h4V7zM9 7H5v3h4V7zm-4 4v3h4v-3H5zm10-1h4V7h-4v3zM5 15v3h4v-3H5z" fill-rule="evenodd"/></svg>',
  12785. 'table-row-properties': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm10 10h-4v3h4v-3zm0-8h-4v3h4V7zM9 7H5v3h4V7zm6 3h4V7h-4v3zM5 15v3h4v-3H5zm10 3h4v-3h-4v3z" fill-rule="evenodd"/></svg>',
  12786. 'table-split-cells': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm6 2v3h4V7h-4zM9 18v-3H5v3h4zm0-4v-3H5v3h4zm0-4V7H5v3h4zm10 8v-7h-9v7h9zm0-8V7h-4v3h4zm-3.5 4.5l1.5 1.6c.3.2.3.7 0 1-.2.2-.7.2-1 0l-1.5-1.6-1.6 1.5c-.2.3-.7.3-1 0a.7.7 0 0 1 0-1l1.6-1.5-1.5-1.6a.7.7 0 0 1 1-1l1.5 1.6 1.6-1.5c.2-.3.7-.3 1 0 .2.2.2.7 0 1l-1.6 1.5z" fill-rule="evenodd"/></svg>',
  12787. 'table-top-header': '<svg width="24" height="24"><path d="M4 5h16v13H4V5zm5 12v-3H5v3h4zm0-4v-3H5v3h4zm5 4v-3h-4v3h4zm0-4v-3h-4v3h4zm5 4v-3h-4v3h4zm0-4v-3h-4v3h4z" fill-rule="evenodd"/></svg>',
  12788. 'table': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm6 9h4v-3h-4v3zm4 1h-4v3h4v-3zm0-8h-4v3h4V7zM9 7H5v3h4V7zm-4 4v3h4v-3H5zm10 0v3h4v-3h-4zm0-1h4V7h-4v3zM5 15v3h4v-3H5zm10 3h4v-3h-4v3z" fill-rule="evenodd"/></svg>',
  12789. 'template': '<svg width="24" height="24"><path d="M19 19v-1H5v1h14zM9 16v-4a5 5 0 1 1 6 0v4h4a2 2 0 0 1 2 2v3H3v-3c0-1.1.9-2 2-2h4zm4 0v-5l.8-.6a3 3 0 1 0-3.6 0l.8.6v5h2z" fill-rule="nonzero"/></svg>',
  12790. 'temporary-placeholder': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M9 7.6V6h2.5V4.5a.5.5 0 1 1 1 0V6H15v1.6a8 8 0 1 1-6 0zm-2.6 5.3a.5.5 0 0 0 .3.6c.3 0 .6 0 .6-.3l.1-.2a5 5 0 0 1 3.3-2.8c.3-.1.4-.4.4-.6-.1-.3-.4-.5-.6-.4a6 6 0 0 0-4.1 3.7z"/><circle cx="14" cy="4" r="1"/><circle cx="12" cy="2" r="1"/><circle cx="10" cy="4" r="1"/></g></svg>',
  12791. 'text-color': '<svg width="24" height="24"><g fill-rule="evenodd"><path id="tox-icon-text-color__color" d="M3 18h18v3H3z"/><path d="M8.7 16h-.8a.5.5 0 0 1-.5-.6l2.7-9c.1-.3.3-.4.5-.4h2.8c.2 0 .4.1.5.4l2.7 9a.5.5 0 0 1-.5.6h-.8a.5.5 0 0 1-.4-.4l-.7-2.2c0-.3-.3-.4-.5-.4h-3.4c-.2 0-.4.1-.5.4l-.7 2.2c0 .3-.2.4-.4.4zm2.6-7.6l-.6 2a.5.5 0 0 0 .5.6h1.6a.5.5 0 0 0 .5-.6l-.6-2c0-.3-.3-.4-.5-.4h-.4c-.2 0-.4.1-.5.4z"/></g></svg>',
  12792. 'toc': '<svg width="24" height="24"><path d="M5 5c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 1 1 0-2zm3 0h11c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 1 1 0-2zm-3 8c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h11c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2zm0-4c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 1 1 0-2zm3 0h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm-3 8c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12793. 'translate': '<svg width="24" height="24"><path d="M12.7 14.3l-.3.7-.4.7-2.2-2.2-3.1 3c-.3.4-.8.4-1 0a.7.7 0 0 1 0-1l3.1-3A12.4 12.4 0 0 1 6.7 9H8a10.1 10.1 0 0 0 1.7 2.4c.5-.5 1-1.1 1.4-1.8l.9-2H4.7a.7.7 0 1 1 0-1.5h4.4v-.7c0-.4.3-.8.7-.8.4 0 .7.4.7.8v.7H15c.4 0 .8.3.8.7 0 .4-.4.8-.8.8h-1.4a12.3 12.3 0 0 1-1 2.4 13.5 13.5 0 0 1-1.7 2.3l1.9 1.8zm4.3-3l2.7 7.3a.5.5 0 0 1-.4.7 1 1 0 0 1-1-.7l-.6-1.5h-3.4l-.6 1.5a1 1 0 0 1-1 .7.5.5 0 0 1-.4-.7l2.7-7.4a1 1 0 1 1 2 0zm-2.2 4.4h2.4L16 12.5l-1.2 3.2z" fill-rule="evenodd"/></svg>',
  12794. 'underline': '<svg width="24" height="24"><path d="M16 5c.6 0 1 .4 1 1v5.5a4 4 0 0 1-.4 1.8l-1 1.4a5.3 5.3 0 0 1-5.5 1 5 5 0 0 1-1.6-1c-.5-.4-.8-.9-1.1-1.4a4 4 0 0 1-.4-1.8V6c0-.6.4-1 1-1s1 .4 1 1v5.5c0 .3 0 .6.2 1l.6.7a3.3 3.3 0 0 0 2.2.8 3.4 3.4 0 0 0 2.2-.8c.3-.2.4-.5.6-.8l.2-.9V6c0-.6.4-1 1-1zM8 17h8c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12795. 'undo': '<svg width="24" height="24"><path d="M6.4 8H12c3.7 0 6.2 2 6.8 5.1.6 2.7-.4 5.6-2.3 6.8a1 1 0 0 1-1-1.8c1.1-.6 1.8-2.7 1.4-4.6-.5-2.1-2.1-3.5-4.9-3.5H6.4l3.3 3.3a1 1 0 1 1-1.4 1.4l-5-5a1 1 0 0 1 0-1.4l5-5a1 1 0 0 1 1.4 1.4L6.4 8z" fill-rule="nonzero"/></svg>',
  12796. 'unlink': '<svg width="24" height="24"><path d="M6.2 12.3a1 1 0 0 1 1.4 1.4l-2 2a2 2 0 1 0 2.6 2.8l4.8-4.8a1 1 0 0 0 0-1.4 1 1 0 1 1 1.4-1.3 2.9 2.9 0 0 1 0 4L9.6 20a3.9 3.9 0 0 1-5.5-5.5l2-2zm11.6-.6a1 1 0 0 1-1.4-1.4l2.1-2a2 2 0 1 0-2.7-2.8L11 10.3a1 1 0 0 0 0 1.4A1 1 0 1 1 9.6 13a2.9 2.9 0 0 1 0-4L14.4 4a3.9 3.9 0 0 1 5.5 5.5l-2 2zM7.6 6.3a.8.8 0 0 1-1 1.1L3.3 4.2a.7.7 0 1 1 1-1l3.2 3.1zM5.1 8.6a.8.8 0 0 1 0 1.5H3a.8.8 0 0 1 0-1.5H5zm5-3.5a.8.8 0 0 1-1.5 0V3a.8.8 0 0 1 1.5 0V5zm6 11.8a.8.8 0 0 1 1-1l3.2 3.2a.8.8 0 0 1-1 1L16 17zm-2.2 2a.8.8 0 0 1 1.5 0V21a.8.8 0 0 1-1.5 0V19zm5-3.5a.7.7 0 1 1 0-1.5H21a.8.8 0 0 1 0 1.5H19z" fill-rule="nonzero"/></svg>',
  12797. 'unlock': '<svg width="24" height="24"><path d="M16 5c.8 0 1.5.3 2.1.9.6.6.9 1.3.9 2.1v3h-2V8a1 1 0 0 0-.3-.7A1 1 0 0 0 16 7h-2a1 1 0 0 0-.7.3 1 1 0 0 0-.3.7v3h.3c.2 0 .3 0 .5.2l.2.6v7.4c0 .3 0 .4-.2.6l-.6.2H4.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6v-7.4c0-.3 0-.4.2-.6l.5-.2H11V8c0-.8.3-1.5.9-2.1.6-.6 1.3-.9 2.1-.9h2z" fill-rule="evenodd"/></svg>',
  12798. 'unordered-list': '<svg width="24" height="24"><path d="M11 5h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zM4.5 6c0-.4.1-.8.4-1 .3-.4.7-.5 1.1-.5.4 0 .8.1 1 .4.4.3.5.7.5 1.1 0 .4-.1.8-.4 1-.3.4-.7.5-1.1.5-.4 0-.8-.1-1-.4-.4-.3-.5-.7-.5-1.1zm0 6c0-.4.1-.8.4-1 .3-.4.7-.5 1.1-.5.4 0 .8.1 1 .4.4.3.5.7.5 1.1 0 .4-.1.8-.4 1-.3.4-.7.5-1.1.5-.4 0-.8-.1-1-.4-.4-.3-.5-.7-.5-1.1zm0 6c0-.4.1-.8.4-1 .3-.4.7-.5 1.1-.5.4 0 .8.1 1 .4.4.3.5.7.5 1.1 0 .4-.1.8-.4 1-.3.4-.7.5-1.1.5-.4 0-.8-.1-1-.4-.4-.3-.5-.7-.5-1.1z" fill-rule="evenodd"/></svg>',
  12799. 'unselected': '<svg width="24" height="24"><path fill-rule="nonzero" d="M6 4h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2zm0 1a1 1 0 0 0-1 1v12c0 .6.4 1 1 1h12c.6 0 1-.4 1-1V6c0-.6-.4-1-1-1H6z"/></svg>',
  12800. 'upload': '<svg width="24" height="24"><path d="M18 19v-2a1 1 0 0 1 2 0v3c0 .6-.4 1-1 1H5a1 1 0 0 1-1-1v-3a1 1 0 0 1 2 0v2h12zM11 6.4L8.7 8.7a1 1 0 0 1-1.4-1.4l4-4a1 1 0 0 1 1.4 0l4 4a1 1 0 1 1-1.4 1.4L13 6.4V16a1 1 0 0 1-2 0V6.4z" fill-rule="nonzero"/></svg>',
  12801. 'user': '<svg width="24" height="24"><path d="M12 24a12 12 0 1 1 0-24 12 12 0 0 1 0 24zm-8.7-5.3a11 11 0 0 0 17.4 0C19.4 16.3 14.6 15 12 15c-2.6 0-7.4 1.3-8.7 3.7zM12 13c2.2 0 4-2 4-4.5S14.2 4 12 4 8 6 8 8.5 9.8 13 12 13z" fill-rule="nonzero"/></svg>',
  12802. 'visualblocks': '<svg width="24" height="24"><path d="M9 19v2H7v-2h2zm-4 0v2a2 2 0 0 1-2-2h2zm8 0v2h-2v-2h2zm8 0a2 2 0 0 1-2 2v-2h2zm-4 0v2h-2v-2h2zM15 7a1 1 0 0 1 0 2v7a1 1 0 0 1-2 0V9h-1v7a1 1 0 0 1-2 0v-4a2.5 2.5 0 0 1-.2-5H15zM5 15v2H3v-2h2zm16 0v2h-2v-2h2zM5 11v2H3v-2h2zm16 0v2h-2v-2h2zM5 7v2H3V7h2zm16 0v2h-2V7h2zM5 3v2H3c0-1.1.9-2 2-2zm8 0v2h-2V3h2zm6 0a2 2 0 0 1 2 2h-2V3zM9 3v2H7V3h2zm8 0v2h-2V3h2z" fill-rule="evenodd"/></svg>',
  12803. 'visualchars': '<svg width="24" height="24"><path d="M10 5h7a1 1 0 0 1 0 2h-1v11a1 1 0 0 1-2 0V7h-2v11a1 1 0 0 1-2 0v-6c-.5 0-1 0-1.4-.3A3.4 3.4 0 0 1 6.8 10a3.3 3.3 0 0 1 0-2.8 3.4 3.4 0 0 1 1.8-1.8L10 5z" fill-rule="evenodd"/></svg>',
  12804. 'warning': '<svg width="24" height="24"><path d="M19.8 18.3c.2.5.3.9 0 1.2-.1.3-.5.5-1 .5H5.2c-.5 0-.9-.2-1-.5-.3-.3-.2-.7 0-1.2L11 4.7l.5-.5.5-.2c.2 0 .3 0 .5.2.2 0 .3.3.5.5l6.8 13.6zM12 18c.3 0 .5-.1.7-.3.2-.2.3-.4.3-.7a1 1 0 0 0-.3-.7 1 1 0 0 0-.7-.3 1 1 0 0 0-.7.3 1 1 0 0 0-.3.7c0 .3.1.5.3.7.2.2.4.3.7.3zm.7-3l.3-4a1 1 0 0 0-.3-.7 1 1 0 0 0-.7-.3 1 1 0 0 0-.7.3 1 1 0 0 0-.3.7l.3 4h1.4z" fill-rule="evenodd"/></svg>',
  12805. 'zoom-in': '<svg width="24" height="24"><path d="M16 17.3a8 8 0 1 1 1.4-1.4l4.3 4.4a1 1 0 0 1-1.4 1.4l-4.4-4.3zm-5-.3a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm-1-9a1 1 0 0 1 2 0v6a1 1 0 0 1-2 0V8zm-2 4a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2H8z" fill-rule="nonzero"/></svg>',
  12806. 'zoom-out': '<svg width="24" height="24"><path d="M16 17.3a8 8 0 1 1 1.4-1.4l4.3 4.4a1 1 0 0 1-1.4 1.4l-4.4-4.3zm-5-.3a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm-3-5a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2H8z" fill-rule="nonzero"/></svg>'
  12807. };
  12808. };
  12809. var CreateIconManager = function () {
  12810. var lookup = {};
  12811. var add = function (id, iconPack) {
  12812. lookup[id] = iconPack;
  12813. };
  12814. var get = function (id) {
  12815. if (lookup[id]) {
  12816. return lookup[id];
  12817. }
  12818. return { icons: {} };
  12819. };
  12820. var has$1 = function (id) {
  12821. return has(lookup, id);
  12822. };
  12823. return {
  12824. add: add,
  12825. get: get,
  12826. has: has$1
  12827. };
  12828. };
  12829. var IconManager = CreateIconManager();
  12830. var PluginManager = AddOnManager$1.PluginManager;
  12831. var ThemeManager = AddOnManager$1.ThemeManager;
  12832. function Uploader(uploadStatus, settings) {
  12833. var pendingPromises = {};
  12834. var pathJoin = function (path1, path2) {
  12835. if (path1) {
  12836. return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
  12837. }
  12838. return path2;
  12839. };
  12840. var defaultHandler = function (blobInfo, success, failure, progress) {
  12841. var xhr, formData;
  12842. xhr = new domGlobals.XMLHttpRequest();
  12843. xhr.open('POST', settings.url);
  12844. xhr.withCredentials = settings.credentials;
  12845. xhr.upload.onprogress = function (e) {
  12846. progress(e.loaded / e.total * 100);
  12847. };
  12848. xhr.onerror = function () {
  12849. failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
  12850. };
  12851. xhr.onload = function () {
  12852. var json;
  12853. if (xhr.status < 200 || xhr.status >= 300) {
  12854. failure('HTTP Error: ' + xhr.status);
  12855. return;
  12856. }
  12857. json = JSON.parse(xhr.responseText);
  12858. if (!json || typeof json.location !== 'string') {
  12859. failure('Invalid JSON: ' + xhr.responseText);
  12860. return;
  12861. }
  12862. success(pathJoin(settings.basePath, json.location));
  12863. };
  12864. formData = new domGlobals.FormData();
  12865. formData.append('file', blobInfo.blob(), blobInfo.filename());
  12866. xhr.send(formData);
  12867. };
  12868. var noUpload = function () {
  12869. return new promiseObj(function (resolve) {
  12870. resolve([]);
  12871. });
  12872. };
  12873. var handlerSuccess = function (blobInfo, url) {
  12874. return {
  12875. url: url,
  12876. blobInfo: blobInfo,
  12877. status: true
  12878. };
  12879. };
  12880. var handlerFailure = function (blobInfo, error) {
  12881. return {
  12882. url: '',
  12883. blobInfo: blobInfo,
  12884. status: false,
  12885. error: error
  12886. };
  12887. };
  12888. var resolvePending = function (blobUri, result) {
  12889. Tools.each(pendingPromises[blobUri], function (resolve) {
  12890. resolve(result);
  12891. });
  12892. delete pendingPromises[blobUri];
  12893. };
  12894. var uploadBlobInfo = function (blobInfo, handler, openNotification) {
  12895. uploadStatus.markPending(blobInfo.blobUri());
  12896. return new promiseObj(function (resolve) {
  12897. var notification, progress;
  12898. var noop = function () {
  12899. };
  12900. try {
  12901. var closeNotification_1 = function () {
  12902. if (notification) {
  12903. notification.close();
  12904. progress = noop;
  12905. }
  12906. };
  12907. var success = function (url) {
  12908. closeNotification_1();
  12909. uploadStatus.markUploaded(blobInfo.blobUri(), url);
  12910. resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url));
  12911. resolve(handlerSuccess(blobInfo, url));
  12912. };
  12913. var failure = function (error) {
  12914. closeNotification_1();
  12915. uploadStatus.removeFailed(blobInfo.blobUri());
  12916. resolvePending(blobInfo.blobUri(), handlerFailure(blobInfo, error));
  12917. resolve(handlerFailure(blobInfo, error));
  12918. };
  12919. progress = function (percent) {
  12920. if (percent < 0 || percent > 100) {
  12921. return;
  12922. }
  12923. if (!notification) {
  12924. notification = openNotification();
  12925. }
  12926. notification.progressBar.value(percent);
  12927. };
  12928. handler(blobInfo, success, failure, progress);
  12929. } catch (ex) {
  12930. resolve(handlerFailure(blobInfo, ex.message));
  12931. }
  12932. });
  12933. };
  12934. var isDefaultHandler = function (handler) {
  12935. return handler === defaultHandler;
  12936. };
  12937. var pendingUploadBlobInfo = function (blobInfo) {
  12938. var blobUri = blobInfo.blobUri();
  12939. return new promiseObj(function (resolve) {
  12940. pendingPromises[blobUri] = pendingPromises[blobUri] || [];
  12941. pendingPromises[blobUri].push(resolve);
  12942. });
  12943. };
  12944. var uploadBlobs = function (blobInfos, openNotification) {
  12945. blobInfos = Tools.grep(blobInfos, function (blobInfo) {
  12946. return !uploadStatus.isUploaded(blobInfo.blobUri());
  12947. });
  12948. return promiseObj.all(Tools.map(blobInfos, function (blobInfo) {
  12949. return uploadStatus.isPending(blobInfo.blobUri()) ? pendingUploadBlobInfo(blobInfo) : uploadBlobInfo(blobInfo, settings.handler, openNotification);
  12950. }));
  12951. };
  12952. var upload = function (blobInfos, openNotification) {
  12953. return !settings.url && isDefaultHandler(settings.handler) ? noUpload() : uploadBlobs(blobInfos, openNotification);
  12954. };
  12955. if (isFunction(settings.handler) === false) {
  12956. settings.handler = defaultHandler;
  12957. }
  12958. return { upload: upload };
  12959. }
  12960. var blobUriToBlob = function (url) {
  12961. return new promiseObj(function (resolve, reject) {
  12962. var rejectWithError = function () {
  12963. reject('Cannot convert ' + url + ' to Blob. Resource might not exist or is inaccessible.');
  12964. };
  12965. try {
  12966. var xhr = new domGlobals.XMLHttpRequest();
  12967. xhr.open('GET', url, true);
  12968. xhr.responseType = 'blob';
  12969. xhr.onload = function () {
  12970. if (this.status === 200) {
  12971. resolve(this.response);
  12972. } else {
  12973. rejectWithError();
  12974. }
  12975. };
  12976. xhr.onerror = rejectWithError;
  12977. xhr.send();
  12978. } catch (ex) {
  12979. rejectWithError();
  12980. }
  12981. });
  12982. };
  12983. var parseDataUri = function (uri) {
  12984. var type, matches;
  12985. var uriParts = decodeURIComponent(uri).split(',');
  12986. matches = /data:([^;]+)/.exec(uriParts[0]);
  12987. if (matches) {
  12988. type = matches[1];
  12989. }
  12990. return {
  12991. type: type,
  12992. data: uriParts[1]
  12993. };
  12994. };
  12995. var dataUriToBlob = function (uri) {
  12996. return new promiseObj(function (resolve) {
  12997. var str, arr, i;
  12998. var uriParts = parseDataUri(uri);
  12999. try {
  13000. str = domGlobals.atob(uriParts.data);
  13001. } catch (e) {
  13002. resolve(new domGlobals.Blob([]));
  13003. return;
  13004. }
  13005. arr = new Uint8Array(str.length);
  13006. for (i = 0; i < arr.length; i++) {
  13007. arr[i] = str.charCodeAt(i);
  13008. }
  13009. resolve(new domGlobals.Blob([arr], { type: uriParts.type }));
  13010. });
  13011. };
  13012. var uriToBlob = function (url) {
  13013. if (url.indexOf('blob:') === 0) {
  13014. return blobUriToBlob(url);
  13015. }
  13016. if (url.indexOf('data:') === 0) {
  13017. return dataUriToBlob(url);
  13018. }
  13019. return null;
  13020. };
  13021. var blobToDataUri = function (blob) {
  13022. return new promiseObj(function (resolve) {
  13023. var reader = new domGlobals.FileReader();
  13024. reader.onloadend = function () {
  13025. resolve(reader.result);
  13026. };
  13027. reader.readAsDataURL(blob);
  13028. });
  13029. };
  13030. var Conversions = {
  13031. uriToBlob: uriToBlob,
  13032. blobToDataUri: blobToDataUri,
  13033. parseDataUri: parseDataUri
  13034. };
  13035. var count = 0;
  13036. var uniqueId = function (prefix) {
  13037. return (prefix || 'blobid') + count++;
  13038. };
  13039. var imageToBlobInfo = function (blobCache, img, resolve, reject) {
  13040. var base64, blobInfo;
  13041. if (img.src.indexOf('blob:') === 0) {
  13042. blobInfo = blobCache.getByUri(img.src);
  13043. if (blobInfo) {
  13044. resolve({
  13045. image: img,
  13046. blobInfo: blobInfo
  13047. });
  13048. } else {
  13049. Conversions.uriToBlob(img.src).then(function (blob) {
  13050. Conversions.blobToDataUri(blob).then(function (dataUri) {
  13051. base64 = Conversions.parseDataUri(dataUri).data;
  13052. blobInfo = blobCache.create(uniqueId(), blob, base64);
  13053. blobCache.add(blobInfo);
  13054. resolve({
  13055. image: img,
  13056. blobInfo: blobInfo
  13057. });
  13058. });
  13059. }, function (err) {
  13060. reject(err);
  13061. });
  13062. }
  13063. return;
  13064. }
  13065. base64 = Conversions.parseDataUri(img.src).data;
  13066. blobInfo = blobCache.findFirst(function (cachedBlobInfo) {
  13067. return cachedBlobInfo.base64() === base64;
  13068. });
  13069. if (blobInfo) {
  13070. resolve({
  13071. image: img,
  13072. blobInfo: blobInfo
  13073. });
  13074. } else {
  13075. Conversions.uriToBlob(img.src).then(function (blob) {
  13076. blobInfo = blobCache.create(uniqueId(), blob, base64);
  13077. blobCache.add(blobInfo);
  13078. resolve({
  13079. image: img,
  13080. blobInfo: blobInfo
  13081. });
  13082. }, function (err) {
  13083. reject(err);
  13084. });
  13085. }
  13086. };
  13087. var getAllImages = function (elm) {
  13088. return elm ? from$1(elm.getElementsByTagName('img')) : [];
  13089. };
  13090. function ImageScanner(uploadStatus, blobCache) {
  13091. var cachedPromises = {};
  13092. var findAll = function (elm, predicate) {
  13093. var images;
  13094. if (!predicate) {
  13095. predicate = constant(true);
  13096. }
  13097. images = filter(getAllImages(elm), function (img) {
  13098. var src = img.src;
  13099. if (!Env.fileApi) {
  13100. return false;
  13101. }
  13102. if (img.hasAttribute('data-mce-bogus')) {
  13103. return false;
  13104. }
  13105. if (img.hasAttribute('data-mce-placeholder')) {
  13106. return false;
  13107. }
  13108. if (!src || src === Env.transparentSrc) {
  13109. return false;
  13110. }
  13111. if (src.indexOf('blob:') === 0) {
  13112. return !uploadStatus.isUploaded(src) && predicate(img);
  13113. }
  13114. if (src.indexOf('data:') === 0) {
  13115. return predicate(img);
  13116. }
  13117. return false;
  13118. });
  13119. var promises = map(images, function (img) {
  13120. if (cachedPromises[img.src]) {
  13121. return new promiseObj(function (resolve) {
  13122. cachedPromises[img.src].then(function (imageInfo) {
  13123. if (typeof imageInfo === 'string') {
  13124. return imageInfo;
  13125. }
  13126. resolve({
  13127. image: img,
  13128. blobInfo: imageInfo.blobInfo
  13129. });
  13130. });
  13131. });
  13132. }
  13133. var newPromise = new promiseObj(function (resolve, reject) {
  13134. imageToBlobInfo(blobCache, img, resolve, reject);
  13135. }).then(function (result) {
  13136. delete cachedPromises[result.image.src];
  13137. return result;
  13138. }).catch(function (error) {
  13139. delete cachedPromises[img.src];
  13140. return error;
  13141. });
  13142. cachedPromises[img.src] = newPromise;
  13143. return newPromise;
  13144. });
  13145. return promiseObj.all(promises);
  13146. };
  13147. return { findAll: findAll };
  13148. }
  13149. var count$1 = 0;
  13150. var seed = function () {
  13151. var rnd = function () {
  13152. return Math.round(Math.random() * 4294967295).toString(36);
  13153. };
  13154. var now = new Date().getTime();
  13155. return 's' + now.toString(36) + rnd() + rnd() + rnd();
  13156. };
  13157. var uuid = function (prefix) {
  13158. return prefix + count$1++ + seed();
  13159. };
  13160. var Uuid = { uuid: uuid };
  13161. var BlobCache = function () {
  13162. var cache = [];
  13163. var mimeToExt = function (mime) {
  13164. var mimes = {
  13165. 'image/jpeg': 'jpg',
  13166. 'image/jpg': 'jpg',
  13167. 'image/gif': 'gif',
  13168. 'image/png': 'png'
  13169. };
  13170. return mimes[mime.toLowerCase()] || 'dat';
  13171. };
  13172. var create = function (o, blob, base64, filename) {
  13173. if (isString(o)) {
  13174. var id = o;
  13175. return toBlobInfo({
  13176. id: id,
  13177. name: filename,
  13178. blob: blob,
  13179. base64: base64
  13180. });
  13181. } else if (isObject(o)) {
  13182. return toBlobInfo(o);
  13183. } else {
  13184. throw new Error('Unknown input type');
  13185. }
  13186. };
  13187. var toBlobInfo = function (o) {
  13188. var id, name;
  13189. if (!o.blob || !o.base64) {
  13190. throw new Error('blob and base64 representations of the image are required for BlobInfo to be created');
  13191. }
  13192. id = o.id || Uuid.uuid('blobid');
  13193. name = o.name || id;
  13194. return {
  13195. id: constant(id),
  13196. name: constant(name),
  13197. filename: constant(name + '.' + mimeToExt(o.blob.type)),
  13198. blob: constant(o.blob),
  13199. base64: constant(o.base64),
  13200. blobUri: constant(o.blobUri || domGlobals.URL.createObjectURL(o.blob)),
  13201. uri: constant(o.uri)
  13202. };
  13203. };
  13204. var add = function (blobInfo) {
  13205. if (!get(blobInfo.id())) {
  13206. cache.push(blobInfo);
  13207. }
  13208. };
  13209. var get = function (id) {
  13210. return findFirst(function (cachedBlobInfo) {
  13211. return cachedBlobInfo.id() === id;
  13212. });
  13213. };
  13214. var findFirst = function (predicate) {
  13215. return filter(cache, predicate)[0];
  13216. };
  13217. var getByUri = function (blobUri) {
  13218. return findFirst(function (blobInfo) {
  13219. return blobInfo.blobUri() === blobUri;
  13220. });
  13221. };
  13222. var removeByUri = function (blobUri) {
  13223. cache = filter(cache, function (blobInfo) {
  13224. if (blobInfo.blobUri() === blobUri) {
  13225. domGlobals.URL.revokeObjectURL(blobInfo.blobUri());
  13226. return false;
  13227. }
  13228. return true;
  13229. });
  13230. };
  13231. var destroy = function () {
  13232. each(cache, function (cachedBlobInfo) {
  13233. domGlobals.URL.revokeObjectURL(cachedBlobInfo.blobUri());
  13234. });
  13235. cache = [];
  13236. };
  13237. return {
  13238. create: create,
  13239. add: add,
  13240. get: get,
  13241. getByUri: getByUri,
  13242. findFirst: findFirst,
  13243. removeByUri: removeByUri,
  13244. destroy: destroy
  13245. };
  13246. };
  13247. function UploadStatus () {
  13248. var PENDING = 1, UPLOADED = 2;
  13249. var blobUriStatuses = {};
  13250. var createStatus = function (status, resultUri) {
  13251. return {
  13252. status: status,
  13253. resultUri: resultUri
  13254. };
  13255. };
  13256. var hasBlobUri = function (blobUri) {
  13257. return blobUri in blobUriStatuses;
  13258. };
  13259. var getResultUri = function (blobUri) {
  13260. var result = blobUriStatuses[blobUri];
  13261. return result ? result.resultUri : null;
  13262. };
  13263. var isPending = function (blobUri) {
  13264. return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === PENDING : false;
  13265. };
  13266. var isUploaded = function (blobUri) {
  13267. return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === UPLOADED : false;
  13268. };
  13269. var markPending = function (blobUri) {
  13270. blobUriStatuses[blobUri] = createStatus(PENDING, null);
  13271. };
  13272. var markUploaded = function (blobUri, resultUri) {
  13273. blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri);
  13274. };
  13275. var removeFailed = function (blobUri) {
  13276. delete blobUriStatuses[blobUri];
  13277. };
  13278. var destroy = function () {
  13279. blobUriStatuses = {};
  13280. };
  13281. return {
  13282. hasBlobUri: hasBlobUri,
  13283. getResultUri: getResultUri,
  13284. isPending: isPending,
  13285. isUploaded: isUploaded,
  13286. markPending: markPending,
  13287. markUploaded: markUploaded,
  13288. removeFailed: removeFailed,
  13289. destroy: destroy
  13290. };
  13291. }
  13292. var EditorUpload = function (editor) {
  13293. var blobCache = BlobCache();
  13294. var uploader, imageScanner;
  13295. var uploadStatus = UploadStatus();
  13296. var urlFilters = [];
  13297. var aliveGuard = function (callback) {
  13298. return function (result) {
  13299. if (editor.selection) {
  13300. return callback(result);
  13301. }
  13302. return [];
  13303. };
  13304. };
  13305. var cacheInvalidator = function () {
  13306. return '?' + new Date().getTime();
  13307. };
  13308. var replaceString = function (content, search, replace) {
  13309. var index = 0;
  13310. do {
  13311. index = content.indexOf(search, index);
  13312. if (index !== -1) {
  13313. content = content.substring(0, index) + replace + content.substr(index + search.length);
  13314. index += replace.length - search.length + 1;
  13315. }
  13316. } while (index !== -1);
  13317. return content;
  13318. };
  13319. var replaceImageUrl = function (content, targetUrl, replacementUrl) {
  13320. content = replaceString(content, 'src="' + targetUrl + '"', 'src="' + replacementUrl + '"');
  13321. content = replaceString(content, 'data-mce-src="' + targetUrl + '"', 'data-mce-src="' + replacementUrl + '"');
  13322. return content;
  13323. };
  13324. var replaceUrlInUndoStack = function (targetUrl, replacementUrl) {
  13325. each(editor.undoManager.data, function (level) {
  13326. if (level.type === 'fragmented') {
  13327. level.fragments = map(level.fragments, function (fragment) {
  13328. return replaceImageUrl(fragment, targetUrl, replacementUrl);
  13329. });
  13330. } else {
  13331. level.content = replaceImageUrl(level.content, targetUrl, replacementUrl);
  13332. }
  13333. });
  13334. };
  13335. var openNotification = function () {
  13336. return editor.notificationManager.open({
  13337. text: editor.translate('Image uploading...'),
  13338. type: 'info',
  13339. timeout: -1,
  13340. progressBar: true
  13341. });
  13342. };
  13343. var replaceImageUri = function (image, resultUri) {
  13344. blobCache.removeByUri(image.src);
  13345. replaceUrlInUndoStack(image.src, resultUri);
  13346. editor.$(image).attr({
  13347. 'src': Settings.shouldReuseFileName(editor) ? resultUri + cacheInvalidator() : resultUri,
  13348. 'data-mce-src': editor.convertURL(resultUri, 'src')
  13349. });
  13350. };
  13351. var uploadImages = function (callback) {
  13352. if (!uploader) {
  13353. uploader = Uploader(uploadStatus, {
  13354. url: Settings.getImageUploadUrl(editor),
  13355. basePath: Settings.getImageUploadBasePath(editor),
  13356. credentials: Settings.getImagesUploadCredentials(editor),
  13357. handler: Settings.getImagesUploadHandler(editor)
  13358. });
  13359. }
  13360. return scanForImages().then(aliveGuard(function (imageInfos) {
  13361. var blobInfos;
  13362. blobInfos = map(imageInfos, function (imageInfo) {
  13363. return imageInfo.blobInfo;
  13364. });
  13365. return uploader.upload(blobInfos, openNotification).then(aliveGuard(function (result) {
  13366. var filteredResult = map(result, function (uploadInfo, index) {
  13367. var image = imageInfos[index].image;
  13368. if (uploadInfo.status && Settings.shouldReplaceBlobUris(editor)) {
  13369. replaceImageUri(image, uploadInfo.url);
  13370. } else if (uploadInfo.error) {
  13371. ErrorReporter.uploadError(editor, uploadInfo.error);
  13372. }
  13373. return {
  13374. element: image,
  13375. status: uploadInfo.status
  13376. };
  13377. });
  13378. if (callback) {
  13379. callback(filteredResult);
  13380. }
  13381. return filteredResult;
  13382. }));
  13383. }));
  13384. };
  13385. var uploadImagesAuto = function (callback) {
  13386. if (Settings.isAutomaticUploadsEnabled(editor)) {
  13387. return uploadImages(callback);
  13388. }
  13389. };
  13390. var isValidDataUriImage = function (imgElm) {
  13391. if (forall(urlFilters, function (filter) {
  13392. return filter(imgElm);
  13393. }) === false) {
  13394. return false;
  13395. }
  13396. if (imgElm.getAttribute('src').indexOf('data:') === 0) {
  13397. var dataImgFilter = Settings.getImagesDataImgFilter(editor);
  13398. return dataImgFilter(imgElm);
  13399. }
  13400. return true;
  13401. };
  13402. var addFilter = function (filter) {
  13403. urlFilters.push(filter);
  13404. };
  13405. var scanForImages = function () {
  13406. if (!imageScanner) {
  13407. imageScanner = ImageScanner(uploadStatus, blobCache);
  13408. }
  13409. return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(aliveGuard(function (result) {
  13410. result = filter(result, function (resultItem) {
  13411. if (typeof resultItem === 'string') {
  13412. ErrorReporter.displayError(editor, resultItem);
  13413. return false;
  13414. }
  13415. return true;
  13416. });
  13417. each(result, function (resultItem) {
  13418. replaceUrlInUndoStack(resultItem.image.src, resultItem.blobInfo.blobUri());
  13419. resultItem.image.src = resultItem.blobInfo.blobUri();
  13420. resultItem.image.removeAttribute('data-mce-src');
  13421. });
  13422. return result;
  13423. }));
  13424. };
  13425. var destroy = function () {
  13426. blobCache.destroy();
  13427. uploadStatus.destroy();
  13428. imageScanner = uploader = null;
  13429. };
  13430. var replaceBlobUris = function (content) {
  13431. return content.replace(/src="(blob:[^"]+)"/g, function (match, blobUri) {
  13432. var resultUri = uploadStatus.getResultUri(blobUri);
  13433. if (resultUri) {
  13434. return 'src="' + resultUri + '"';
  13435. }
  13436. var blobInfo = blobCache.getByUri(blobUri);
  13437. if (!blobInfo) {
  13438. blobInfo = foldl(editor.editorManager.get(), function (result, editor) {
  13439. return result || editor.editorUpload && editor.editorUpload.blobCache.getByUri(blobUri);
  13440. }, null);
  13441. }
  13442. if (blobInfo) {
  13443. var blob = blobInfo.blob();
  13444. return 'src="data:' + blob.type + ';base64,' + blobInfo.base64() + '"';
  13445. }
  13446. return match;
  13447. });
  13448. };
  13449. editor.on('SetContent', function () {
  13450. if (Settings.isAutomaticUploadsEnabled(editor)) {
  13451. uploadImagesAuto();
  13452. } else {
  13453. scanForImages();
  13454. }
  13455. });
  13456. editor.on('RawSaveContent', function (e) {
  13457. e.content = replaceBlobUris(e.content);
  13458. });
  13459. editor.on('GetContent', function (e) {
  13460. if (e.source_view || e.format === 'raw') {
  13461. return;
  13462. }
  13463. e.content = replaceBlobUris(e.content);
  13464. });
  13465. editor.on('PostRender', function () {
  13466. editor.parser.addNodeFilter('img', function (images) {
  13467. each(images, function (img) {
  13468. var src = img.attr('src');
  13469. if (blobCache.getByUri(src)) {
  13470. return;
  13471. }
  13472. var resultUri = uploadStatus.getResultUri(src);
  13473. if (resultUri) {
  13474. img.attr('src', resultUri);
  13475. }
  13476. });
  13477. });
  13478. });
  13479. return {
  13480. blobCache: blobCache,
  13481. addFilter: addFilter,
  13482. uploadImages: uploadImages,
  13483. uploadImagesAuto: uploadImagesAuto,
  13484. scanForImages: scanForImages,
  13485. destroy: destroy
  13486. };
  13487. };
  13488. var dropLast = function (xs) {
  13489. return xs.slice(0, -1);
  13490. };
  13491. var parentsUntil$1 = function (start, root, predicate) {
  13492. if (contains$2(root, start)) {
  13493. return dropLast(parents(start, function (elm) {
  13494. return predicate(elm) || eq(elm, root);
  13495. }));
  13496. } else {
  13497. return [];
  13498. }
  13499. };
  13500. var parents$1 = function (start, root) {
  13501. return parentsUntil$1(start, root, constant(false));
  13502. };
  13503. var parentsAndSelf = function (start, root) {
  13504. return [start].concat(parents$1(start, root));
  13505. };
  13506. var Parents = {
  13507. parentsUntil: parentsUntil$1,
  13508. parents: parents$1,
  13509. parentsAndSelf: parentsAndSelf
  13510. };
  13511. var isBlockElement = function (blockElements, node) {
  13512. return blockElements.hasOwnProperty(node.nodeName);
  13513. };
  13514. var isValidTarget = function (blockElements, node) {
  13515. if (NodeType.isText(node)) {
  13516. return true;
  13517. } else if (NodeType.isElement(node)) {
  13518. return !isBlockElement(blockElements, node) && !Bookmarks.isBookmarkNode(node);
  13519. } else {
  13520. return false;
  13521. }
  13522. };
  13523. var hasBlockParent = function (blockElements, root, node) {
  13524. return exists(Parents.parents(Element.fromDom(node), Element.fromDom(root)), function (elm) {
  13525. return isBlockElement(blockElements, elm.dom());
  13526. });
  13527. };
  13528. var shouldRemoveTextNode = function (blockElements, node) {
  13529. if (NodeType.isText(node)) {
  13530. if (node.nodeValue.length === 0) {
  13531. return true;
  13532. } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) {
  13533. return true;
  13534. }
  13535. }
  13536. return false;
  13537. };
  13538. var addRootBlocks = function (editor) {
  13539. var dom = editor.dom, selection = editor.selection;
  13540. var schema = editor.schema, blockElements = schema.getBlockElements();
  13541. var node = selection.getStart();
  13542. var rootNode = editor.getBody();
  13543. var rng;
  13544. var startContainer, startOffset, endContainer, endOffset, rootBlockNode;
  13545. var tempNode, wrapped, restoreSelection;
  13546. var rootNodeName;
  13547. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  13548. if (!node || !NodeType.isElement(node) || !forcedRootBlock) {
  13549. return;
  13550. }
  13551. rootNodeName = rootNode.nodeName.toLowerCase();
  13552. if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) {
  13553. return;
  13554. }
  13555. rng = selection.getRng();
  13556. startContainer = rng.startContainer;
  13557. startOffset = rng.startOffset;
  13558. endContainer = rng.endContainer;
  13559. endOffset = rng.endOffset;
  13560. restoreSelection = EditorFocus.hasFocus(editor);
  13561. node = rootNode.firstChild;
  13562. while (node) {
  13563. if (isValidTarget(blockElements, node)) {
  13564. if (shouldRemoveTextNode(blockElements, node)) {
  13565. tempNode = node;
  13566. node = node.nextSibling;
  13567. dom.remove(tempNode);
  13568. continue;
  13569. }
  13570. if (!rootBlockNode) {
  13571. rootBlockNode = dom.create(forcedRootBlock, Settings.getForcedRootBlockAttrs(editor));
  13572. node.parentNode.insertBefore(rootBlockNode, node);
  13573. wrapped = true;
  13574. }
  13575. tempNode = node;
  13576. node = node.nextSibling;
  13577. rootBlockNode.appendChild(tempNode);
  13578. } else {
  13579. rootBlockNode = null;
  13580. node = node.nextSibling;
  13581. }
  13582. }
  13583. if (wrapped && restoreSelection) {
  13584. rng.setStart(startContainer, startOffset);
  13585. rng.setEnd(endContainer, endOffset);
  13586. selection.setRng(rng);
  13587. editor.nodeChanged();
  13588. }
  13589. };
  13590. var setup$3 = function (editor) {
  13591. if (Settings.getForcedRootBlock(editor)) {
  13592. editor.on('NodeChange', curry(addRootBlocks, editor));
  13593. }
  13594. };
  13595. var ForceBlocks = { setup: setup$3 };
  13596. var isEq$1 = function (rng1, rng2) {
  13597. return rng1 && rng2 && (rng1.startContainer === rng2.startContainer && rng1.startOffset === rng2.startOffset) && (rng1.endContainer === rng2.endContainer && rng1.endOffset === rng2.endOffset);
  13598. };
  13599. var RangeCompare = { isEq: isEq$1 };
  13600. var getStartNode = function (rng) {
  13601. var sc = rng.startContainer, so = rng.startOffset;
  13602. if (NodeType.isText(sc)) {
  13603. return so === 0 ? Option.some(Element.fromDom(sc)) : Option.none();
  13604. } else {
  13605. return Option.from(sc.childNodes[so]).map(Element.fromDom);
  13606. }
  13607. };
  13608. var getEndNode = function (rng) {
  13609. var ec = rng.endContainer, eo = rng.endOffset;
  13610. if (NodeType.isText(ec)) {
  13611. return eo === ec.data.length ? Option.some(Element.fromDom(ec)) : Option.none();
  13612. } else {
  13613. return Option.from(ec.childNodes[eo - 1]).map(Element.fromDom);
  13614. }
  13615. };
  13616. var getFirstChildren = function (node) {
  13617. return firstChild(node).fold(constant([node]), function (child) {
  13618. return [node].concat(getFirstChildren(child));
  13619. });
  13620. };
  13621. var getLastChildren = function (node) {
  13622. return lastChild(node).fold(constant([node]), function (child) {
  13623. if (name(child) === 'br') {
  13624. return prevSibling(child).map(function (sibling) {
  13625. return [node].concat(getLastChildren(sibling));
  13626. }).getOr([]);
  13627. } else {
  13628. return [node].concat(getLastChildren(child));
  13629. }
  13630. });
  13631. };
  13632. var hasAllContentsSelected = function (elm, rng) {
  13633. return lift2(getStartNode(rng), getEndNode(rng), function (startNode, endNode) {
  13634. var start = find(getFirstChildren(elm), curry(eq, startNode));
  13635. var end = find(getLastChildren(elm), curry(eq, endNode));
  13636. return start.isSome() && end.isSome();
  13637. }).getOr(false);
  13638. };
  13639. var moveEndPoint$1 = function (dom, rng, node, start) {
  13640. var root = node, walker = new TreeWalker(node, root);
  13641. var nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  13642. do {
  13643. if (node.nodeType === 3 && Tools.trim(node.nodeValue).length !== 0) {
  13644. if (start) {
  13645. rng.setStart(node, 0);
  13646. } else {
  13647. rng.setEnd(node, node.nodeValue.length);
  13648. }
  13649. return;
  13650. }
  13651. if (nonEmptyElementsMap[node.nodeName] && !/^(TD|TH)$/.test(node.nodeName)) {
  13652. if (start) {
  13653. rng.setStartBefore(node);
  13654. } else {
  13655. if (node.nodeName === 'BR') {
  13656. rng.setEndBefore(node);
  13657. } else {
  13658. rng.setEndAfter(node);
  13659. }
  13660. }
  13661. return;
  13662. }
  13663. } while (node = start ? walker.next() : walker.prev());
  13664. if (root.nodeName === 'BODY') {
  13665. if (start) {
  13666. rng.setStart(root, 0);
  13667. } else {
  13668. rng.setEnd(root, root.childNodes.length);
  13669. }
  13670. }
  13671. };
  13672. var hasAnyRanges = function (editor) {
  13673. var sel = editor.selection.getSel();
  13674. return sel && sel.rangeCount > 0;
  13675. };
  13676. var NodeChange = function () {
  13677. function NodeChange(editor) {
  13678. this.lastPath = [];
  13679. this.editor = editor;
  13680. var lastRng;
  13681. var self = this;
  13682. if (!('onselectionchange' in editor.getDoc())) {
  13683. editor.on('NodeChange click mouseup keyup focus', function (e) {
  13684. var nativeRng, fakeRng;
  13685. nativeRng = editor.selection.getRng();
  13686. fakeRng = {
  13687. startContainer: nativeRng.startContainer,
  13688. startOffset: nativeRng.startOffset,
  13689. endContainer: nativeRng.endContainer,
  13690. endOffset: nativeRng.endOffset
  13691. };
  13692. if (e.type === 'nodechange' || !RangeCompare.isEq(fakeRng, lastRng)) {
  13693. editor.fire('SelectionChange');
  13694. }
  13695. lastRng = fakeRng;
  13696. });
  13697. }
  13698. editor.on('contextmenu', function () {
  13699. editor.fire('SelectionChange');
  13700. });
  13701. editor.on('SelectionChange', function () {
  13702. var startElm = editor.selection.getStart(true);
  13703. if (!startElm || !Env.range && editor.selection.isCollapsed()) {
  13704. return;
  13705. }
  13706. if (hasAnyRanges(editor) && !self.isSameElementPath(startElm) && editor.dom.isChildOf(startElm, editor.getBody())) {
  13707. editor.nodeChanged({ selectionChange: true });
  13708. }
  13709. });
  13710. editor.on('mouseup', function (e) {
  13711. if (!e.isDefaultPrevented() && hasAnyRanges(editor)) {
  13712. if (editor.selection.getNode().nodeName === 'IMG') {
  13713. Delay.setEditorTimeout(editor, function () {
  13714. editor.nodeChanged();
  13715. });
  13716. } else {
  13717. editor.nodeChanged();
  13718. }
  13719. }
  13720. });
  13721. }
  13722. NodeChange.prototype.nodeChanged = function (args) {
  13723. var selection = this.editor.selection;
  13724. var node, parents, root;
  13725. if (this.editor.initialized && selection && !this.editor.settings.disable_nodechange && !this.editor.readonly) {
  13726. root = this.editor.getBody();
  13727. node = selection.getStart(true) || root;
  13728. if (node.ownerDocument !== this.editor.getDoc() || !this.editor.dom.isChildOf(node, root)) {
  13729. node = root;
  13730. }
  13731. parents = [];
  13732. this.editor.dom.getParent(node, function (node) {
  13733. if (node === root) {
  13734. return true;
  13735. }
  13736. parents.push(node);
  13737. });
  13738. args = args || {};
  13739. args.element = node;
  13740. args.parents = parents;
  13741. this.editor.fire('NodeChange', args);
  13742. }
  13743. };
  13744. NodeChange.prototype.isSameElementPath = function (startElm) {
  13745. var i, currentPath;
  13746. currentPath = this.editor.$(startElm).parentsUntil(this.editor.getBody()).add(startElm);
  13747. if (currentPath.length === this.lastPath.length) {
  13748. for (i = currentPath.length; i >= 0; i--) {
  13749. if (currentPath[i] !== this.lastPath[i]) {
  13750. break;
  13751. }
  13752. }
  13753. if (i === -1) {
  13754. this.lastPath = currentPath;
  13755. return true;
  13756. }
  13757. }
  13758. this.lastPath = currentPath;
  13759. return false;
  13760. };
  13761. return NodeChange;
  13762. }();
  13763. var VK = {
  13764. BACKSPACE: 8,
  13765. DELETE: 46,
  13766. DOWN: 40,
  13767. ENTER: 13,
  13768. LEFT: 37,
  13769. RIGHT: 39,
  13770. SPACEBAR: 32,
  13771. TAB: 9,
  13772. UP: 38,
  13773. END: 35,
  13774. HOME: 36,
  13775. modifierPressed: function (e) {
  13776. return e.shiftKey || e.ctrlKey || e.altKey || this.metaKeyPressed(e);
  13777. },
  13778. metaKeyPressed: function (e) {
  13779. return Env.mac ? e.metaKey : e.ctrlKey && !e.altKey;
  13780. }
  13781. };
  13782. var is$2 = function (expected) {
  13783. return function (actual) {
  13784. return expected === actual;
  13785. };
  13786. };
  13787. var isNbsp = is$2('\xA0');
  13788. var isWhiteSpace$1 = function (chr) {
  13789. return /^[\r\n\t ]$/.test(chr);
  13790. };
  13791. var isContent = function (chr) {
  13792. return !isWhiteSpace$1(chr) && !isNbsp(chr);
  13793. };
  13794. var isChar = function (forward, predicate, pos) {
  13795. return Option.from(pos.container()).filter(NodeType.isText).exists(function (text) {
  13796. var delta = forward ? 0 : -1;
  13797. return predicate(text.data.charAt(pos.offset() + delta));
  13798. });
  13799. };
  13800. var isBeforeSpace = curry(isChar, true, isWhiteSpace$1);
  13801. var isAfterSpace = curry(isChar, false, isWhiteSpace$1);
  13802. var isEmptyText = function (pos) {
  13803. var container = pos.container();
  13804. return NodeType.isText(container) && container.data.length === 0;
  13805. };
  13806. var matchesElementPosition = function (before, predicate) {
  13807. return function (pos) {
  13808. return Option.from(getChildNodeAtRelativeOffset(before ? 0 : -1, pos)).filter(predicate).isSome();
  13809. };
  13810. };
  13811. var isImageBlock = function (node) {
  13812. return node.nodeName === 'IMG' && get$2(Element.fromDom(node), 'display') === 'block';
  13813. };
  13814. var isCefNode = function (node) {
  13815. return NodeType.isContentEditableFalse(node) && !NodeType.isBogusAll(node);
  13816. };
  13817. var isBeforeImageBlock = matchesElementPosition(true, isImageBlock);
  13818. var isAfterImageBlock = matchesElementPosition(false, isImageBlock);
  13819. var isBeforeTable = matchesElementPosition(true, NodeType.isTable);
  13820. var isAfterTable = matchesElementPosition(false, NodeType.isTable);
  13821. var isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode);
  13822. var isAfterContentEditableFalse = matchesElementPosition(false, isCefNode);
  13823. var getNodeClientRects = function (node) {
  13824. var toArrayWithNode = function (clientRects) {
  13825. return map(clientRects, function (clientRect) {
  13826. clientRect = clone$1(clientRect);
  13827. clientRect.node = node;
  13828. return clientRect;
  13829. });
  13830. };
  13831. if (NodeType.isElement(node)) {
  13832. return toArrayWithNode(node.getClientRects());
  13833. }
  13834. if (NodeType.isText(node)) {
  13835. var rng = node.ownerDocument.createRange();
  13836. rng.setStart(node, 0);
  13837. rng.setEnd(node, node.data.length);
  13838. return toArrayWithNode(rng.getClientRects());
  13839. }
  13840. };
  13841. var getClientRects = function (node) {
  13842. return foldl(node, function (result, node) {
  13843. return result.concat(getNodeClientRects(node));
  13844. }, []);
  13845. };
  13846. var VDirection;
  13847. (function (VDirection) {
  13848. VDirection[VDirection['Up'] = -1] = 'Up';
  13849. VDirection[VDirection['Down'] = 1] = 'Down';
  13850. }(VDirection || (VDirection = {})));
  13851. var findUntil = function (direction, root, predicateFn, node) {
  13852. while (node = findNode(node, direction, isEditableCaretCandidate, root)) {
  13853. if (predicateFn(node)) {
  13854. return;
  13855. }
  13856. }
  13857. };
  13858. var walkUntil = function (direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) {
  13859. var line = 0, node;
  13860. var result = [];
  13861. var targetClientRect;
  13862. var add = function (node) {
  13863. var i, clientRect, clientRects;
  13864. clientRects = getClientRects([node]);
  13865. if (direction === -1) {
  13866. clientRects = clientRects.reverse();
  13867. }
  13868. for (i = 0; i < clientRects.length; i++) {
  13869. clientRect = clientRects[i];
  13870. if (isBeflowFn(clientRect, targetClientRect)) {
  13871. continue;
  13872. }
  13873. if (result.length > 0 && isAboveFn(clientRect, ArrUtils.last(result))) {
  13874. line++;
  13875. }
  13876. clientRect.line = line;
  13877. if (predicateFn(clientRect)) {
  13878. return true;
  13879. }
  13880. result.push(clientRect);
  13881. }
  13882. };
  13883. targetClientRect = ArrUtils.last(caretPosition.getClientRects());
  13884. if (!targetClientRect) {
  13885. return result;
  13886. }
  13887. node = caretPosition.getNode();
  13888. add(node);
  13889. findUntil(direction, root, add, node);
  13890. return result;
  13891. };
  13892. var aboveLineNumber = function (lineNumber, clientRect) {
  13893. return clientRect.line > lineNumber;
  13894. };
  13895. var isLineNumber = function (lineNumber, clientRect) {
  13896. return clientRect.line === lineNumber;
  13897. };
  13898. var upUntil = curry(walkUntil, VDirection.Up, isAbove, isBelow);
  13899. var downUntil = curry(walkUntil, VDirection.Down, isBelow, isAbove);
  13900. var positionsUntil = function (direction, root, predicateFn, node) {
  13901. var caretWalker = CaretWalker(root);
  13902. var walkFn, isBelowFn, isAboveFn, caretPosition;
  13903. var result = [];
  13904. var line = 0, clientRect, targetClientRect;
  13905. var getClientRect = function (caretPosition) {
  13906. if (direction === 1) {
  13907. return ArrUtils.last(caretPosition.getClientRects());
  13908. }
  13909. return ArrUtils.last(caretPosition.getClientRects());
  13910. };
  13911. if (direction === 1) {
  13912. walkFn = caretWalker.next;
  13913. isBelowFn = isBelow;
  13914. isAboveFn = isAbove;
  13915. caretPosition = CaretPosition$1.after(node);
  13916. } else {
  13917. walkFn = caretWalker.prev;
  13918. isBelowFn = isAbove;
  13919. isAboveFn = isBelow;
  13920. caretPosition = CaretPosition$1.before(node);
  13921. }
  13922. targetClientRect = getClientRect(caretPosition);
  13923. do {
  13924. if (!caretPosition.isVisible()) {
  13925. continue;
  13926. }
  13927. clientRect = getClientRect(caretPosition);
  13928. if (isAboveFn(clientRect, targetClientRect)) {
  13929. continue;
  13930. }
  13931. if (result.length > 0 && isBelowFn(clientRect, ArrUtils.last(result))) {
  13932. line++;
  13933. }
  13934. clientRect = clone$1(clientRect);
  13935. clientRect.position = caretPosition;
  13936. clientRect.line = line;
  13937. if (predicateFn(clientRect)) {
  13938. return result;
  13939. }
  13940. result.push(clientRect);
  13941. } while (caretPosition = walkFn(caretPosition));
  13942. return result;
  13943. };
  13944. var isAboveLine = function (lineNumber) {
  13945. return function (clientRect) {
  13946. return aboveLineNumber(lineNumber, clientRect);
  13947. };
  13948. };
  13949. var isLine = function (lineNumber) {
  13950. return function (clientRect) {
  13951. return isLineNumber(lineNumber, clientRect);
  13952. };
  13953. };
  13954. var isContentEditableFalse$6 = NodeType.isContentEditableFalse;
  13955. var findNode$1 = findNode;
  13956. var distanceToRectLeft = function (clientRect, clientX) {
  13957. return Math.abs(clientRect.left - clientX);
  13958. };
  13959. var distanceToRectRight = function (clientRect, clientX) {
  13960. return Math.abs(clientRect.right - clientX);
  13961. };
  13962. var isInside = function (clientX, clientRect) {
  13963. return clientX >= clientRect.left && clientX <= clientRect.right;
  13964. };
  13965. var findClosestClientRect = function (clientRects, clientX) {
  13966. return ArrUtils.reduce(clientRects, function (oldClientRect, clientRect) {
  13967. var oldDistance, newDistance;
  13968. oldDistance = Math.min(distanceToRectLeft(oldClientRect, clientX), distanceToRectRight(oldClientRect, clientX));
  13969. newDistance = Math.min(distanceToRectLeft(clientRect, clientX), distanceToRectRight(clientRect, clientX));
  13970. if (isInside(clientX, clientRect)) {
  13971. return clientRect;
  13972. }
  13973. if (isInside(clientX, oldClientRect)) {
  13974. return oldClientRect;
  13975. }
  13976. if (newDistance === oldDistance && isContentEditableFalse$6(clientRect.node)) {
  13977. return clientRect;
  13978. }
  13979. if (newDistance < oldDistance) {
  13980. return clientRect;
  13981. }
  13982. return oldClientRect;
  13983. });
  13984. };
  13985. var walkUntil$1 = function (direction, root, predicateFn, node) {
  13986. while (node = findNode$1(node, direction, isEditableCaretCandidate, root)) {
  13987. if (predicateFn(node)) {
  13988. return;
  13989. }
  13990. }
  13991. };
  13992. var findLineNodeRects = function (root, targetNodeRect) {
  13993. var clientRects = [];
  13994. var collect = function (checkPosFn, node) {
  13995. var lineRects;
  13996. lineRects = filter(getClientRects([node]), function (clientRect) {
  13997. return !checkPosFn(clientRect, targetNodeRect);
  13998. });
  13999. clientRects = clientRects.concat(lineRects);
  14000. return lineRects.length === 0;
  14001. };
  14002. clientRects.push(targetNodeRect);
  14003. walkUntil$1(VDirection.Up, root, curry(collect, isAbove), targetNodeRect.node);
  14004. walkUntil$1(VDirection.Down, root, curry(collect, isBelow), targetNodeRect.node);
  14005. return clientRects;
  14006. };
  14007. var getFakeCaretTargets = function (root) {
  14008. return filter(from$1(root.getElementsByTagName('*')), isFakeCaretTarget);
  14009. };
  14010. var caretInfo = function (clientRect, clientX) {
  14011. return {
  14012. node: clientRect.node,
  14013. before: distanceToRectLeft(clientRect, clientX) < distanceToRectRight(clientRect, clientX)
  14014. };
  14015. };
  14016. var closestCaret = function (root, clientX, clientY) {
  14017. var closestNodeRect;
  14018. var contentEditableFalseNodeRects = getClientRects(getFakeCaretTargets(root));
  14019. var targetNodeRects = filter(contentEditableFalseNodeRects, function (rect) {
  14020. return clientY >= rect.top && clientY <= rect.bottom;
  14021. });
  14022. closestNodeRect = findClosestClientRect(targetNodeRects, clientX);
  14023. if (closestNodeRect) {
  14024. closestNodeRect = findClosestClientRect(findLineNodeRects(root, closestNodeRect), clientX);
  14025. if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
  14026. return caretInfo(closestNodeRect, clientX);
  14027. }
  14028. }
  14029. return null;
  14030. };
  14031. var isXYWithinRange = function (clientX, clientY, range) {
  14032. if (range.collapsed) {
  14033. return false;
  14034. }
  14035. if (Env.browser.isIE() && range.startOffset === range.endOffset - 1 && range.startContainer === range.endContainer) {
  14036. var elm = range.startContainer.childNodes[range.startOffset];
  14037. if (NodeType.isElement(elm)) {
  14038. return exists(elm.getClientRects(), function (rect) {
  14039. return containsXY(rect, clientX, clientY);
  14040. });
  14041. }
  14042. }
  14043. return exists(range.getClientRects(), function (rect) {
  14044. return containsXY(rect, clientX, clientY);
  14045. });
  14046. };
  14047. var RangePoint = { isXYWithinRange: isXYWithinRange };
  14048. var getAbsolutePosition = function (elm) {
  14049. var doc, docElem, win, clientRect;
  14050. clientRect = elm.getBoundingClientRect();
  14051. doc = elm.ownerDocument;
  14052. docElem = doc.documentElement;
  14053. win = doc.defaultView;
  14054. return {
  14055. top: clientRect.top + win.pageYOffset - docElem.clientTop,
  14056. left: clientRect.left + win.pageXOffset - docElem.clientLeft
  14057. };
  14058. };
  14059. var getBodyPosition = function (editor) {
  14060. return editor.inline ? getAbsolutePosition(editor.getBody()) : {
  14061. left: 0,
  14062. top: 0
  14063. };
  14064. };
  14065. var getScrollPosition = function (editor) {
  14066. var body = editor.getBody();
  14067. return editor.inline ? {
  14068. left: body.scrollLeft,
  14069. top: body.scrollTop
  14070. } : {
  14071. left: 0,
  14072. top: 0
  14073. };
  14074. };
  14075. var getBodyScroll = function (editor) {
  14076. var body = editor.getBody(), docElm = editor.getDoc().documentElement;
  14077. var inlineScroll = {
  14078. left: body.scrollLeft,
  14079. top: body.scrollTop
  14080. };
  14081. var iframeScroll = {
  14082. left: body.scrollLeft || docElm.scrollLeft,
  14083. top: body.scrollTop || docElm.scrollTop
  14084. };
  14085. return editor.inline ? inlineScroll : iframeScroll;
  14086. };
  14087. var getMousePosition = function (editor, event) {
  14088. if (event.target.ownerDocument !== editor.getDoc()) {
  14089. var iframePosition = getAbsolutePosition(editor.getContentAreaContainer());
  14090. var scrollPosition = getBodyScroll(editor);
  14091. return {
  14092. left: event.pageX - iframePosition.left + scrollPosition.left,
  14093. top: event.pageY - iframePosition.top + scrollPosition.top
  14094. };
  14095. }
  14096. return {
  14097. left: event.pageX,
  14098. top: event.pageY
  14099. };
  14100. };
  14101. var calculatePosition = function (bodyPosition, scrollPosition, mousePosition) {
  14102. return {
  14103. pageX: mousePosition.left - bodyPosition.left + scrollPosition.left,
  14104. pageY: mousePosition.top - bodyPosition.top + scrollPosition.top
  14105. };
  14106. };
  14107. var calc = function (editor, event) {
  14108. return calculatePosition(getBodyPosition(editor), getScrollPosition(editor), getMousePosition(editor, event));
  14109. };
  14110. var MousePosition = { calc: calc };
  14111. var isContentEditableFalse$7 = NodeType.isContentEditableFalse, isContentEditableTrue$2 = NodeType.isContentEditableTrue;
  14112. var isDraggable = function (rootElm, elm) {
  14113. return isContentEditableFalse$7(elm) && elm !== rootElm;
  14114. };
  14115. var isValidDropTarget = function (editor, targetElement, dragElement) {
  14116. if (targetElement === dragElement || editor.dom.isChildOf(targetElement, dragElement)) {
  14117. return false;
  14118. }
  14119. return !isContentEditableFalse$7(targetElement);
  14120. };
  14121. var cloneElement = function (elm) {
  14122. var cloneElm = elm.cloneNode(true);
  14123. cloneElm.removeAttribute('data-mce-selected');
  14124. return cloneElm;
  14125. };
  14126. var createGhost = function (editor, elm, width, height) {
  14127. var clonedElm = elm.cloneNode(true);
  14128. editor.dom.setStyles(clonedElm, {
  14129. width: width,
  14130. height: height
  14131. });
  14132. editor.dom.setAttrib(clonedElm, 'data-mce-selected', null);
  14133. var ghostElm = editor.dom.create('div', {
  14134. 'class': 'mce-drag-container',
  14135. 'data-mce-bogus': 'all',
  14136. 'unselectable': 'on',
  14137. 'contenteditable': 'false'
  14138. });
  14139. editor.dom.setStyles(ghostElm, {
  14140. position: 'absolute',
  14141. opacity: 0.5,
  14142. overflow: 'hidden',
  14143. border: 0,
  14144. padding: 0,
  14145. margin: 0,
  14146. width: width,
  14147. height: height
  14148. });
  14149. editor.dom.setStyles(clonedElm, {
  14150. margin: 0,
  14151. boxSizing: 'border-box'
  14152. });
  14153. ghostElm.appendChild(clonedElm);
  14154. return ghostElm;
  14155. };
  14156. var appendGhostToBody = function (ghostElm, bodyElm) {
  14157. if (ghostElm.parentNode !== bodyElm) {
  14158. bodyElm.appendChild(ghostElm);
  14159. }
  14160. };
  14161. var moveGhost = function (ghostElm, position, width, height, maxX, maxY) {
  14162. var overflowX = 0, overflowY = 0;
  14163. ghostElm.style.left = position.pageX + 'px';
  14164. ghostElm.style.top = position.pageY + 'px';
  14165. if (position.pageX + width > maxX) {
  14166. overflowX = position.pageX + width - maxX;
  14167. }
  14168. if (position.pageY + height > maxY) {
  14169. overflowY = position.pageY + height - maxY;
  14170. }
  14171. ghostElm.style.width = width - overflowX + 'px';
  14172. ghostElm.style.height = height - overflowY + 'px';
  14173. };
  14174. var removeElement = function (elm) {
  14175. if (elm && elm.parentNode) {
  14176. elm.parentNode.removeChild(elm);
  14177. }
  14178. };
  14179. var isLeftMouseButtonPressed = function (e) {
  14180. return e.button === 0;
  14181. };
  14182. var hasDraggableElement = function (state) {
  14183. return state.element;
  14184. };
  14185. var applyRelPos = function (state, position) {
  14186. return {
  14187. pageX: position.pageX - state.relX,
  14188. pageY: position.pageY + 5
  14189. };
  14190. };
  14191. var start = function (state, editor) {
  14192. return function (e) {
  14193. if (isLeftMouseButtonPressed(e)) {
  14194. var ceElm = find(editor.dom.getParents(e.target), Predicate.or(isContentEditableFalse$7, isContentEditableTrue$2)).getOr(null);
  14195. if (isDraggable(editor.getBody(), ceElm)) {
  14196. var elmPos = editor.dom.getPos(ceElm);
  14197. var bodyElm = editor.getBody();
  14198. var docElm = editor.getDoc().documentElement;
  14199. state.element = ceElm;
  14200. state.screenX = e.screenX;
  14201. state.screenY = e.screenY;
  14202. state.maxX = (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2;
  14203. state.maxY = (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2;
  14204. state.relX = e.pageX - elmPos.x;
  14205. state.relY = e.pageY - elmPos.y;
  14206. state.width = ceElm.offsetWidth;
  14207. state.height = ceElm.offsetHeight;
  14208. state.ghost = createGhost(editor, ceElm, state.width, state.height);
  14209. }
  14210. }
  14211. };
  14212. };
  14213. var move = function (state, editor) {
  14214. var throttledPlaceCaretAt = Delay.throttle(function (clientX, clientY) {
  14215. editor._selectionOverrides.hideFakeCaret();
  14216. editor.selection.placeCaretAt(clientX, clientY);
  14217. }, 0);
  14218. return function (e) {
  14219. var movement = Math.max(Math.abs(e.screenX - state.screenX), Math.abs(e.screenY - state.screenY));
  14220. if (hasDraggableElement(state) && !state.dragging && movement > 10) {
  14221. var args = editor.fire('dragstart', { target: state.element });
  14222. if (args.isDefaultPrevented()) {
  14223. return;
  14224. }
  14225. state.dragging = true;
  14226. editor.focus();
  14227. }
  14228. if (state.dragging) {
  14229. var targetPos = applyRelPos(state, MousePosition.calc(editor, e));
  14230. appendGhostToBody(state.ghost, editor.getBody());
  14231. moveGhost(state.ghost, targetPos, state.width, state.height, state.maxX, state.maxY);
  14232. throttledPlaceCaretAt(e.clientX, e.clientY);
  14233. }
  14234. };
  14235. };
  14236. var getRawTarget = function (selection) {
  14237. var rng = selection.getSel().getRangeAt(0);
  14238. var startContainer = rng.startContainer;
  14239. return startContainer.nodeType === 3 ? startContainer.parentNode : startContainer;
  14240. };
  14241. var drop = function (state, editor) {
  14242. return function (e) {
  14243. if (state.dragging) {
  14244. if (isValidDropTarget(editor, getRawTarget(editor.selection), state.element)) {
  14245. var targetClone_1 = cloneElement(state.element);
  14246. var args = editor.fire('drop', {
  14247. targetClone: targetClone_1,
  14248. clientX: e.clientX,
  14249. clientY: e.clientY
  14250. });
  14251. if (!args.isDefaultPrevented()) {
  14252. targetClone_1 = args.targetClone;
  14253. editor.undoManager.transact(function () {
  14254. removeElement(state.element);
  14255. editor.insertContent(editor.dom.getOuterHTML(targetClone_1));
  14256. editor._selectionOverrides.hideFakeCaret();
  14257. });
  14258. }
  14259. }
  14260. }
  14261. removeDragState(state);
  14262. };
  14263. };
  14264. var stop = function (state, editor) {
  14265. return function () {
  14266. if (state.dragging) {
  14267. editor.fire('dragend');
  14268. }
  14269. removeDragState(state);
  14270. };
  14271. };
  14272. var removeDragState = function (state) {
  14273. state.dragging = false;
  14274. state.element = null;
  14275. removeElement(state.ghost);
  14276. };
  14277. var bindFakeDragEvents = function (editor) {
  14278. var state = {};
  14279. var pageDom, dragStartHandler, dragHandler, dropHandler, dragEndHandler, rootDocument;
  14280. pageDom = DOMUtils$1.DOM;
  14281. rootDocument = domGlobals.document;
  14282. dragStartHandler = start(state, editor);
  14283. dragHandler = move(state, editor);
  14284. dropHandler = drop(state, editor);
  14285. dragEndHandler = stop(state, editor);
  14286. editor.on('mousedown', dragStartHandler);
  14287. editor.on('mousemove', dragHandler);
  14288. editor.on('mouseup', dropHandler);
  14289. pageDom.bind(rootDocument, 'mousemove', dragHandler);
  14290. pageDom.bind(rootDocument, 'mouseup', dragEndHandler);
  14291. editor.on('remove', function () {
  14292. pageDom.unbind(rootDocument, 'mousemove', dragHandler);
  14293. pageDom.unbind(rootDocument, 'mouseup', dragEndHandler);
  14294. });
  14295. };
  14296. var blockIeDrop = function (editor) {
  14297. editor.on('drop', function (e) {
  14298. var realTarget = typeof e.clientX !== 'undefined' ? editor.getDoc().elementFromPoint(e.clientX, e.clientY) : null;
  14299. if (isContentEditableFalse$7(realTarget) || isContentEditableFalse$7(editor.dom.getContentEditableParent(realTarget))) {
  14300. e.preventDefault();
  14301. }
  14302. });
  14303. };
  14304. var init = function (editor) {
  14305. bindFakeDragEvents(editor);
  14306. blockIeDrop(editor);
  14307. };
  14308. var DragDropOverrides = { init: init };
  14309. var isContentEditableTrue$3 = NodeType.isContentEditableTrue;
  14310. var isContentEditableFalse$8 = NodeType.isContentEditableFalse;
  14311. var showCaret = function (direction, editor, node, before, scrollIntoView) {
  14312. return editor._selectionOverrides.showCaret(direction, node, before, scrollIntoView);
  14313. };
  14314. var getNodeRange = function (node) {
  14315. var rng = node.ownerDocument.createRange();
  14316. rng.selectNode(node);
  14317. return rng;
  14318. };
  14319. var selectNode = function (editor, node) {
  14320. var e = editor.fire('BeforeObjectSelected', { target: node });
  14321. if (e.isDefaultPrevented()) {
  14322. return null;
  14323. }
  14324. return getNodeRange(node);
  14325. };
  14326. var renderCaretAtRange = function (editor, range, scrollIntoView) {
  14327. var normalizedRange = normalizeRange(1, editor.getBody(), range);
  14328. var caretPosition = CaretPosition$1.fromRangeStart(normalizedRange);
  14329. var caretPositionNode = caretPosition.getNode();
  14330. if (isContentEditableFalse$8(caretPositionNode)) {
  14331. return showCaret(1, editor, caretPositionNode, !caretPosition.isAtEnd(), false);
  14332. }
  14333. var caretPositionBeforeNode = caretPosition.getNode(true);
  14334. if (isContentEditableFalse$8(caretPositionBeforeNode)) {
  14335. return showCaret(1, editor, caretPositionBeforeNode, false, false);
  14336. }
  14337. var ceRoot = editor.dom.getParent(caretPosition.getNode(), function (node) {
  14338. return isContentEditableFalse$8(node) || isContentEditableTrue$3(node);
  14339. });
  14340. if (isContentEditableFalse$8(ceRoot)) {
  14341. return showCaret(1, editor, ceRoot, false, scrollIntoView);
  14342. }
  14343. return null;
  14344. };
  14345. var renderRangeCaret = function (editor, range, scrollIntoView) {
  14346. if (!range || !range.collapsed) {
  14347. return range;
  14348. }
  14349. var caretRange = renderCaretAtRange(editor, range, scrollIntoView);
  14350. if (caretRange) {
  14351. return caretRange;
  14352. }
  14353. return range;
  14354. };
  14355. var setup$4 = function (editor) {
  14356. var renderFocusCaret = first(function () {
  14357. if (!editor.removed && editor.getBody().contains(domGlobals.document.activeElement)) {
  14358. var rng = editor.selection.getRng();
  14359. if (rng.collapsed) {
  14360. var caretRange = renderRangeCaret(editor, editor.selection.getRng(), false);
  14361. editor.selection.setRng(caretRange);
  14362. }
  14363. }
  14364. }, 0);
  14365. editor.on('focus', function () {
  14366. renderFocusCaret.throttle();
  14367. });
  14368. editor.on('blur', function () {
  14369. renderFocusCaret.cancel();
  14370. });
  14371. };
  14372. var CefFocus = { setup: setup$4 };
  14373. var isContentEditableTrue$4 = NodeType.isContentEditableTrue;
  14374. var isContentEditableFalse$9 = NodeType.isContentEditableFalse;
  14375. var getContentEditableRoot = function (editor, node) {
  14376. var root = editor.getBody();
  14377. while (node && node !== root) {
  14378. if (isContentEditableTrue$4(node) || isContentEditableFalse$9(node)) {
  14379. return node;
  14380. }
  14381. node = node.parentNode;
  14382. }
  14383. return null;
  14384. };
  14385. var SelectionOverrides = function (editor) {
  14386. var isBlock = function (node) {
  14387. return editor.dom.isBlock(node);
  14388. };
  14389. var rootNode = editor.getBody();
  14390. var fakeCaret = FakeCaret(editor.getBody(), isBlock, function () {
  14391. return EditorFocus.hasFocus(editor);
  14392. });
  14393. var realSelectionId = 'sel-' + editor.dom.uniqueId();
  14394. var selectedContentEditableNode;
  14395. var isFakeSelectionElement = function (elm) {
  14396. return editor.dom.hasClass(elm, 'mce-offscreen-selection');
  14397. };
  14398. var getRealSelectionElement = function () {
  14399. var container = editor.dom.get(realSelectionId);
  14400. return container ? container.getElementsByTagName('*')[0] : container;
  14401. };
  14402. var setRange = function (range) {
  14403. if (range) {
  14404. editor.selection.setRng(range);
  14405. }
  14406. };
  14407. var getRange = function () {
  14408. return editor.selection.getRng();
  14409. };
  14410. var showCaret = function (direction, node, before, scrollIntoView) {
  14411. if (scrollIntoView === void 0) {
  14412. scrollIntoView = true;
  14413. }
  14414. var e;
  14415. e = editor.fire('ShowCaret', {
  14416. target: node,
  14417. direction: direction,
  14418. before: before
  14419. });
  14420. if (e.isDefaultPrevented()) {
  14421. return null;
  14422. }
  14423. if (scrollIntoView) {
  14424. editor.selection.scrollIntoView(node, direction === -1);
  14425. }
  14426. return fakeCaret.show(before, node);
  14427. };
  14428. var showBlockCaretContainer = function (blockCaretContainer) {
  14429. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  14430. showCaretContainerBlock(blockCaretContainer);
  14431. setRange(getRange());
  14432. editor.selection.scrollIntoView(blockCaretContainer[0]);
  14433. }
  14434. };
  14435. var registerEvents = function () {
  14436. editor.on('mouseup', function (e) {
  14437. var range = getRange();
  14438. if (range.collapsed && EditorView.isXYInContentArea(editor, e.clientX, e.clientY)) {
  14439. setRange(renderCaretAtRange(editor, range, false));
  14440. }
  14441. });
  14442. editor.on('click', function (e) {
  14443. var contentEditableRoot;
  14444. contentEditableRoot = getContentEditableRoot(editor, e.target);
  14445. if (contentEditableRoot) {
  14446. if (isContentEditableFalse$9(contentEditableRoot)) {
  14447. e.preventDefault();
  14448. editor.focus();
  14449. }
  14450. if (isContentEditableTrue$4(contentEditableRoot)) {
  14451. if (editor.dom.isChildOf(contentEditableRoot, editor.selection.getNode())) {
  14452. removeContentEditableSelection();
  14453. }
  14454. }
  14455. }
  14456. });
  14457. editor.on('blur NewBlock', function () {
  14458. removeContentEditableSelection();
  14459. });
  14460. editor.on('ResizeWindow FullscreenStateChanged', function () {
  14461. return fakeCaret.reposition();
  14462. });
  14463. var handleTouchSelect = function (editor) {
  14464. var moved = false;
  14465. editor.on('touchstart', function () {
  14466. moved = false;
  14467. });
  14468. editor.on('touchmove', function () {
  14469. moved = true;
  14470. });
  14471. editor.on('touchend', function (e) {
  14472. if (!moved) {
  14473. var contentEditableRoot = getContentEditableRoot(editor, e.target);
  14474. if (isContentEditableFalse$9(contentEditableRoot)) {
  14475. e.preventDefault();
  14476. setContentEditableSelection(selectNode(editor, contentEditableRoot));
  14477. }
  14478. }
  14479. }, true);
  14480. };
  14481. var hasNormalCaretPosition = function (elm) {
  14482. var caretWalker = CaretWalker(elm);
  14483. if (!elm.firstChild) {
  14484. return false;
  14485. }
  14486. var startPos = CaretPosition$1.before(elm.firstChild);
  14487. var newPos = caretWalker.next(startPos);
  14488. return newPos && !isBeforeContentEditableFalse(newPos) && !isAfterContentEditableFalse(newPos);
  14489. };
  14490. var isInSameBlock = function (node1, node2) {
  14491. var block1 = editor.dom.getParent(node1, editor.dom.isBlock);
  14492. var block2 = editor.dom.getParent(node2, editor.dom.isBlock);
  14493. return block1 === block2;
  14494. };
  14495. var hasBetterMouseTarget = function (targetNode, caretNode) {
  14496. var targetBlock = editor.dom.getParent(targetNode, editor.dom.isBlock);
  14497. var caretBlock = editor.dom.getParent(caretNode, editor.dom.isBlock);
  14498. if (targetBlock && editor.dom.isChildOf(targetBlock, caretBlock) && isContentEditableFalse$9(getContentEditableRoot(editor, targetBlock)) === false) {
  14499. return true;
  14500. }
  14501. return targetBlock && !isInSameBlock(targetBlock, caretBlock) && hasNormalCaretPosition(targetBlock);
  14502. };
  14503. handleTouchSelect(editor);
  14504. editor.on('mousedown', function (e) {
  14505. var contentEditableRoot;
  14506. var targetElm = e.target;
  14507. if (targetElm !== rootNode && targetElm.nodeName !== 'HTML' && !editor.dom.isChildOf(targetElm, rootNode)) {
  14508. return;
  14509. }
  14510. if (EditorView.isXYInContentArea(editor, e.clientX, e.clientY) === false) {
  14511. return;
  14512. }
  14513. contentEditableRoot = getContentEditableRoot(editor, targetElm);
  14514. if (contentEditableRoot) {
  14515. if (isContentEditableFalse$9(contentEditableRoot)) {
  14516. e.preventDefault();
  14517. setContentEditableSelection(selectNode(editor, contentEditableRoot));
  14518. } else {
  14519. removeContentEditableSelection();
  14520. if (!(isContentEditableTrue$4(contentEditableRoot) && e.shiftKey) && !RangePoint.isXYWithinRange(e.clientX, e.clientY, editor.selection.getRng())) {
  14521. hideFakeCaret();
  14522. editor.selection.placeCaretAt(e.clientX, e.clientY);
  14523. }
  14524. }
  14525. } else if (isFakeCaretTarget(targetElm) === false) {
  14526. removeContentEditableSelection();
  14527. hideFakeCaret();
  14528. var caretInfo = closestCaret(rootNode, e.clientX, e.clientY);
  14529. if (caretInfo) {
  14530. if (!hasBetterMouseTarget(e.target, caretInfo.node)) {
  14531. e.preventDefault();
  14532. var range = showCaret(1, caretInfo.node, caretInfo.before, false);
  14533. editor.getBody().focus();
  14534. setRange(range);
  14535. }
  14536. }
  14537. }
  14538. });
  14539. editor.on('keypress', function (e) {
  14540. if (VK.modifierPressed(e)) {
  14541. return;
  14542. }
  14543. switch (e.keyCode) {
  14544. default:
  14545. if (isContentEditableFalse$9(editor.selection.getNode())) {
  14546. e.preventDefault();
  14547. }
  14548. break;
  14549. }
  14550. });
  14551. editor.on('GetSelectionRange', function (e) {
  14552. var rng = e.range;
  14553. if (selectedContentEditableNode) {
  14554. if (!selectedContentEditableNode.parentNode) {
  14555. selectedContentEditableNode = null;
  14556. return;
  14557. }
  14558. rng = rng.cloneRange();
  14559. rng.selectNode(selectedContentEditableNode);
  14560. e.range = rng;
  14561. }
  14562. });
  14563. editor.on('SetSelectionRange', function (e) {
  14564. e.range = normalizeShortEndedElementSelection(e.range);
  14565. var rng = setContentEditableSelection(e.range, e.forward);
  14566. if (rng) {
  14567. e.range = rng;
  14568. }
  14569. });
  14570. var isPasteBin = function (node) {
  14571. return node.id === 'mcepastebin';
  14572. };
  14573. editor.on('AfterSetSelectionRange', function (e) {
  14574. var rng = e.range;
  14575. if (!isRangeInCaretContainer(rng) && !isPasteBin(rng.startContainer.parentNode)) {
  14576. hideFakeCaret();
  14577. }
  14578. if (!isFakeSelectionElement(rng.startContainer.parentNode)) {
  14579. removeContentEditableSelection();
  14580. }
  14581. });
  14582. editor.on('copy', function (e) {
  14583. var clipboardData = e.clipboardData;
  14584. if (!e.isDefaultPrevented() && e.clipboardData && !Env.ie) {
  14585. var realSelectionElement = getRealSelectionElement();
  14586. if (realSelectionElement) {
  14587. e.preventDefault();
  14588. clipboardData.clearData();
  14589. clipboardData.setData('text/html', realSelectionElement.outerHTML);
  14590. clipboardData.setData('text/plain', realSelectionElement.outerText);
  14591. }
  14592. }
  14593. });
  14594. DragDropOverrides.init(editor);
  14595. CefFocus.setup(editor);
  14596. };
  14597. var isWithinCaretContainer = function (node) {
  14598. return isCaretContainer(node) || startsWithCaretContainer(node) || endsWithCaretContainer(node);
  14599. };
  14600. var isRangeInCaretContainer = function (rng) {
  14601. return isWithinCaretContainer(rng.startContainer) || isWithinCaretContainer(rng.endContainer);
  14602. };
  14603. var normalizeShortEndedElementSelection = function (rng) {
  14604. var shortEndedElements = editor.schema.getShortEndedElements();
  14605. var newRng = editor.dom.createRng();
  14606. var startContainer = rng.startContainer;
  14607. var startOffset = rng.startOffset;
  14608. var endContainer = rng.endContainer;
  14609. var endOffset = rng.endOffset;
  14610. if (has(shortEndedElements, startContainer.nodeName.toLowerCase())) {
  14611. if (startOffset === 0) {
  14612. newRng.setStartBefore(startContainer);
  14613. } else {
  14614. newRng.setStartAfter(startContainer);
  14615. }
  14616. } else {
  14617. newRng.setStart(startContainer, startOffset);
  14618. }
  14619. if (has(shortEndedElements, endContainer.nodeName.toLowerCase())) {
  14620. if (endOffset === 0) {
  14621. newRng.setEndBefore(endContainer);
  14622. } else {
  14623. newRng.setEndAfter(endContainer);
  14624. }
  14625. } else {
  14626. newRng.setEnd(endContainer, endOffset);
  14627. }
  14628. return newRng;
  14629. };
  14630. var setContentEditableSelection = function (range, forward) {
  14631. var node;
  14632. var $ = editor.$;
  14633. var dom = editor.dom;
  14634. var $realSelectionContainer, sel, startContainer, startOffset, endOffset, e, caretPosition, targetClone, origTargetClone;
  14635. if (!range) {
  14636. return null;
  14637. }
  14638. if (range.collapsed) {
  14639. if (!isRangeInCaretContainer(range)) {
  14640. if (forward === false) {
  14641. caretPosition = getNormalizedRangeEndPoint(-1, rootNode, range);
  14642. if (isFakeCaretTarget(caretPosition.getNode(true))) {
  14643. return showCaret(-1, caretPosition.getNode(true), false, false);
  14644. }
  14645. if (isFakeCaretTarget(caretPosition.getNode())) {
  14646. return showCaret(-1, caretPosition.getNode(), !caretPosition.isAtEnd(), false);
  14647. }
  14648. } else {
  14649. caretPosition = getNormalizedRangeEndPoint(1, rootNode, range);
  14650. if (isFakeCaretTarget(caretPosition.getNode())) {
  14651. return showCaret(1, caretPosition.getNode(), !caretPosition.isAtEnd(), false);
  14652. }
  14653. if (isFakeCaretTarget(caretPosition.getNode(true))) {
  14654. return showCaret(1, caretPosition.getNode(true), false, false);
  14655. }
  14656. }
  14657. }
  14658. return null;
  14659. }
  14660. startContainer = range.startContainer;
  14661. startOffset = range.startOffset;
  14662. endOffset = range.endOffset;
  14663. if (startContainer.nodeType === 3 && startOffset === 0 && isContentEditableFalse$9(startContainer.parentNode)) {
  14664. startContainer = startContainer.parentNode;
  14665. startOffset = dom.nodeIndex(startContainer);
  14666. startContainer = startContainer.parentNode;
  14667. }
  14668. if (startContainer.nodeType !== 1) {
  14669. return null;
  14670. }
  14671. if (endOffset === startOffset + 1 && startContainer === range.endContainer) {
  14672. node = startContainer.childNodes[startOffset];
  14673. }
  14674. if (!isContentEditableFalse$9(node)) {
  14675. return null;
  14676. }
  14677. targetClone = origTargetClone = node.cloneNode(true);
  14678. e = editor.fire('ObjectSelected', {
  14679. target: node,
  14680. targetClone: targetClone
  14681. });
  14682. if (e.isDefaultPrevented()) {
  14683. return null;
  14684. }
  14685. $realSelectionContainer = descendant(Element.fromDom(editor.getBody()), '#' + realSelectionId).fold(function () {
  14686. return $([]);
  14687. }, function (elm) {
  14688. return $([elm.dom()]);
  14689. });
  14690. targetClone = e.targetClone;
  14691. if ($realSelectionContainer.length === 0) {
  14692. $realSelectionContainer = $('<div data-mce-bogus="all" class="mce-offscreen-selection"></div>').attr('id', realSelectionId);
  14693. $realSelectionContainer.appendTo(editor.getBody());
  14694. }
  14695. range = editor.dom.createRng();
  14696. if (targetClone === origTargetClone && Env.ie) {
  14697. $realSelectionContainer.empty().append('<p style="font-size: 0" data-mce-bogus="all">\xA0</p>').append(targetClone);
  14698. range.setStartAfter($realSelectionContainer[0].firstChild.firstChild);
  14699. range.setEndAfter(targetClone);
  14700. } else {
  14701. $realSelectionContainer.empty().append('\xA0').append(targetClone).append('\xA0');
  14702. range.setStart($realSelectionContainer[0].firstChild, 1);
  14703. range.setEnd($realSelectionContainer[0].lastChild, 0);
  14704. }
  14705. $realSelectionContainer.css({ top: dom.getPos(node, editor.getBody()).y });
  14706. $realSelectionContainer[0].focus();
  14707. sel = editor.selection.getSel();
  14708. sel.removeAllRanges();
  14709. sel.addRange(range);
  14710. var nodeElm = Element.fromDom(node);
  14711. each(descendants$1(Element.fromDom(editor.getBody()), '*[data-mce-selected]'), function (elm) {
  14712. if (!eq(nodeElm, elm)) {
  14713. remove(elm, 'data-mce-selected');
  14714. }
  14715. });
  14716. if (!editor.dom.getAttrib(node, 'data-mce-selected')) {
  14717. node.setAttribute('data-mce-selected', '1');
  14718. }
  14719. selectedContentEditableNode = node;
  14720. hideFakeCaret();
  14721. return range;
  14722. };
  14723. var removeContentEditableSelection = function () {
  14724. if (selectedContentEditableNode) {
  14725. selectedContentEditableNode.removeAttribute('data-mce-selected');
  14726. descendant(Element.fromDom(editor.getBody()), '#' + realSelectionId).each(remove$1);
  14727. selectedContentEditableNode = null;
  14728. }
  14729. descendant(Element.fromDom(editor.getBody()), '#' + realSelectionId).each(remove$1);
  14730. selectedContentEditableNode = null;
  14731. };
  14732. var destroy = function () {
  14733. fakeCaret.destroy();
  14734. selectedContentEditableNode = null;
  14735. };
  14736. var hideFakeCaret = function () {
  14737. fakeCaret.hide();
  14738. };
  14739. if (Env.ceFalse) {
  14740. registerEvents();
  14741. }
  14742. return {
  14743. showCaret: showCaret,
  14744. showBlockCaretContainer: showBlockCaretContainer,
  14745. hideFakeCaret: hideFakeCaret,
  14746. destroy: destroy
  14747. };
  14748. };
  14749. var KEEP = 0, INSERT = 1, DELETE = 2;
  14750. var diff = function (left, right) {
  14751. var size = left.length + right.length + 2;
  14752. var vDown = new Array(size);
  14753. var vUp = new Array(size);
  14754. var snake = function (start, end, diag) {
  14755. return {
  14756. start: start,
  14757. end: end,
  14758. diag: diag
  14759. };
  14760. };
  14761. var buildScript = function (start1, end1, start2, end2, script) {
  14762. var middle = getMiddleSnake(start1, end1, start2, end2);
  14763. if (middle === null || middle.start === end1 && middle.diag === end1 - end2 || middle.end === start1 && middle.diag === start1 - start2) {
  14764. var i = start1;
  14765. var j = start2;
  14766. while (i < end1 || j < end2) {
  14767. if (i < end1 && j < end2 && left[i] === right[j]) {
  14768. script.push([
  14769. KEEP,
  14770. left[i]
  14771. ]);
  14772. ++i;
  14773. ++j;
  14774. } else {
  14775. if (end1 - start1 > end2 - start2) {
  14776. script.push([
  14777. DELETE,
  14778. left[i]
  14779. ]);
  14780. ++i;
  14781. } else {
  14782. script.push([
  14783. INSERT,
  14784. right[j]
  14785. ]);
  14786. ++j;
  14787. }
  14788. }
  14789. }
  14790. } else {
  14791. buildScript(start1, middle.start, start2, middle.start - middle.diag, script);
  14792. for (var i2 = middle.start; i2 < middle.end; ++i2) {
  14793. script.push([
  14794. KEEP,
  14795. left[i2]
  14796. ]);
  14797. }
  14798. buildScript(middle.end, end1, middle.end - middle.diag, end2, script);
  14799. }
  14800. };
  14801. var buildSnake = function (start, diag, end1, end2) {
  14802. var end = start;
  14803. while (end - diag < end2 && end < end1 && left[end] === right[end - diag]) {
  14804. ++end;
  14805. }
  14806. return snake(start, end, diag);
  14807. };
  14808. var getMiddleSnake = function (start1, end1, start2, end2) {
  14809. var m = end1 - start1;
  14810. var n = end2 - start2;
  14811. if (m === 0 || n === 0) {
  14812. return null;
  14813. }
  14814. var delta = m - n;
  14815. var sum = n + m;
  14816. var offset = (sum % 2 === 0 ? sum : sum + 1) / 2;
  14817. vDown[1 + offset] = start1;
  14818. vUp[1 + offset] = end1 + 1;
  14819. var d, k, i, x, y;
  14820. for (d = 0; d <= offset; ++d) {
  14821. for (k = -d; k <= d; k += 2) {
  14822. i = k + offset;
  14823. if (k === -d || k !== d && vDown[i - 1] < vDown[i + 1]) {
  14824. vDown[i] = vDown[i + 1];
  14825. } else {
  14826. vDown[i] = vDown[i - 1] + 1;
  14827. }
  14828. x = vDown[i];
  14829. y = x - start1 + start2 - k;
  14830. while (x < end1 && y < end2 && left[x] === right[y]) {
  14831. vDown[i] = ++x;
  14832. ++y;
  14833. }
  14834. if (delta % 2 !== 0 && delta - d <= k && k <= delta + d) {
  14835. if (vUp[i - delta] <= vDown[i]) {
  14836. return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2);
  14837. }
  14838. }
  14839. }
  14840. for (k = delta - d; k <= delta + d; k += 2) {
  14841. i = k + offset - delta;
  14842. if (k === delta - d || k !== delta + d && vUp[i + 1] <= vUp[i - 1]) {
  14843. vUp[i] = vUp[i + 1] - 1;
  14844. } else {
  14845. vUp[i] = vUp[i - 1];
  14846. }
  14847. x = vUp[i] - 1;
  14848. y = x - start1 + start2 - k;
  14849. while (x >= start1 && y >= start2 && left[x] === right[y]) {
  14850. vUp[i] = x--;
  14851. y--;
  14852. }
  14853. if (delta % 2 === 0 && -d <= k && k <= d) {
  14854. if (vUp[i] <= vDown[i + delta]) {
  14855. return buildSnake(vUp[i], k + start1 - start2, end1, end2);
  14856. }
  14857. }
  14858. }
  14859. }
  14860. };
  14861. var script = [];
  14862. buildScript(0, left.length, 0, right.length, script);
  14863. return script;
  14864. };
  14865. var Diff = {
  14866. KEEP: KEEP,
  14867. DELETE: DELETE,
  14868. INSERT: INSERT,
  14869. diff: diff
  14870. };
  14871. var getOuterHtml = function (elm) {
  14872. if (NodeType.isElement(elm)) {
  14873. return elm.outerHTML;
  14874. } else if (NodeType.isText(elm)) {
  14875. return Entities.encodeRaw(elm.data, false);
  14876. } else if (NodeType.isComment(elm)) {
  14877. return '<!--' + elm.data + '-->';
  14878. }
  14879. return '';
  14880. };
  14881. var createFragment$1 = function (html) {
  14882. var frag, node, container;
  14883. container = domGlobals.document.createElement('div');
  14884. frag = domGlobals.document.createDocumentFragment();
  14885. if (html) {
  14886. container.innerHTML = html;
  14887. }
  14888. while (node = container.firstChild) {
  14889. frag.appendChild(node);
  14890. }
  14891. return frag;
  14892. };
  14893. var insertAt = function (elm, html, index) {
  14894. var fragment = createFragment$1(html);
  14895. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  14896. var target = elm.childNodes[index];
  14897. target.parentNode.insertBefore(fragment, target);
  14898. } else {
  14899. elm.appendChild(fragment);
  14900. }
  14901. };
  14902. var removeAt = function (elm, index) {
  14903. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  14904. var target = elm.childNodes[index];
  14905. target.parentNode.removeChild(target);
  14906. }
  14907. };
  14908. var applyDiff = function (diff, elm) {
  14909. var index = 0;
  14910. each(diff, function (action) {
  14911. if (action[0] === Diff.KEEP) {
  14912. index++;
  14913. } else if (action[0] === Diff.INSERT) {
  14914. insertAt(elm, action[1], index);
  14915. index++;
  14916. } else if (action[0] === Diff.DELETE) {
  14917. removeAt(elm, index);
  14918. }
  14919. });
  14920. };
  14921. var read$1 = function (elm) {
  14922. return filter(map(from$1(elm.childNodes), getOuterHtml), function (item) {
  14923. return item.length > 0;
  14924. });
  14925. };
  14926. var write = function (fragments, elm) {
  14927. var currentFragments = map(from$1(elm.childNodes), getOuterHtml);
  14928. applyDiff(Diff.diff(currentFragments, fragments), elm);
  14929. return elm;
  14930. };
  14931. var Fragments = {
  14932. read: read$1,
  14933. write: write
  14934. };
  14935. var undoLevelDocument = Cell(Option.none());
  14936. var lazyTempDocument = function () {
  14937. return undoLevelDocument.get().getOrThunk(function () {
  14938. var doc = domGlobals.document.implementation.createHTMLDocument('undo');
  14939. undoLevelDocument.set(Option.some(doc));
  14940. return doc;
  14941. });
  14942. };
  14943. var hasIframes = function (html) {
  14944. return html.indexOf('</iframe>') !== -1;
  14945. };
  14946. var createFragmentedLevel = function (fragments) {
  14947. return {
  14948. type: 'fragmented',
  14949. fragments: fragments,
  14950. content: '',
  14951. bookmark: null,
  14952. beforeBookmark: null
  14953. };
  14954. };
  14955. var createCompleteLevel = function (content) {
  14956. return {
  14957. type: 'complete',
  14958. fragments: null,
  14959. content: content,
  14960. bookmark: null,
  14961. beforeBookmark: null
  14962. };
  14963. };
  14964. var createFromEditor = function (editor) {
  14965. var fragments, content, trimmedFragments;
  14966. fragments = Fragments.read(editor.getBody());
  14967. trimmedFragments = bind(fragments, function (html) {
  14968. var trimmed = TrimHtml.trimInternal(editor.serializer, html);
  14969. return trimmed.length > 0 ? [trimmed] : [];
  14970. });
  14971. content = trimmedFragments.join('');
  14972. return hasIframes(content) ? createFragmentedLevel(trimmedFragments) : createCompleteLevel(content);
  14973. };
  14974. var applyToEditor = function (editor, level, before) {
  14975. if (level.type === 'fragmented') {
  14976. Fragments.write(level.fragments, editor.getBody());
  14977. } else {
  14978. editor.setContent(level.content, { format: 'raw' });
  14979. }
  14980. editor.selection.moveToBookmark(before ? level.beforeBookmark : level.bookmark);
  14981. };
  14982. var getLevelContent = function (level) {
  14983. return level.type === 'fragmented' ? level.fragments.join('') : level.content;
  14984. };
  14985. var getCleanLevelContent = function (level) {
  14986. var elm = Element.fromTag('body', lazyTempDocument());
  14987. set$1(elm, getLevelContent(level));
  14988. each(descendants$1(elm, '*[data-mce-bogus]'), unwrap);
  14989. return get$5(elm);
  14990. };
  14991. var hasEqualContent = function (level1, level2) {
  14992. return getLevelContent(level1) === getLevelContent(level2);
  14993. };
  14994. var hasEqualCleanedContent = function (level1, level2) {
  14995. return getCleanLevelContent(level1) === getCleanLevelContent(level2);
  14996. };
  14997. var isEq$2 = function (level1, level2) {
  14998. if (!level1 || !level2) {
  14999. return false;
  15000. } else if (hasEqualContent(level1, level2)) {
  15001. return true;
  15002. } else {
  15003. return hasEqualCleanedContent(level1, level2);
  15004. }
  15005. };
  15006. var Levels = {
  15007. createFragmentedLevel: createFragmentedLevel,
  15008. createCompleteLevel: createCompleteLevel,
  15009. createFromEditor: createFromEditor,
  15010. applyToEditor: applyToEditor,
  15011. isEq: isEq$2
  15012. };
  15013. var isUnlocked = function (locks) {
  15014. return locks.get() === 0;
  15015. };
  15016. var setTyping = function (undoManager, typing, locks) {
  15017. if (isUnlocked(locks)) {
  15018. undoManager.typing = typing;
  15019. }
  15020. };
  15021. var endTyping = function (undoManager, locks) {
  15022. if (undoManager.typing) {
  15023. setTyping(undoManager, false, locks);
  15024. undoManager.add();
  15025. }
  15026. };
  15027. var endTypingLevelIgnoreLocks = function (undoManager) {
  15028. if (undoManager.typing) {
  15029. undoManager.typing = false;
  15030. undoManager.add();
  15031. }
  15032. };
  15033. var beforeChange = function (editor, locks, beforeBookmark) {
  15034. if (isUnlocked(locks)) {
  15035. beforeBookmark.set(Option.some(GetBookmark.getUndoBookmark(editor.selection)));
  15036. }
  15037. };
  15038. var addUndoLevel = function (editor, undoManager, index, locks, beforeBookmark, level, event) {
  15039. var settings = editor.settings;
  15040. var currentLevel = Levels.createFromEditor(editor);
  15041. level = level || {};
  15042. level = Tools.extend(level, currentLevel);
  15043. if (isUnlocked(locks) === false || editor.removed) {
  15044. return null;
  15045. }
  15046. var lastLevel = undoManager.data[index.get()];
  15047. if (editor.fire('BeforeAddUndo', {
  15048. level: level,
  15049. lastLevel: lastLevel,
  15050. originalEvent: event
  15051. }).isDefaultPrevented()) {
  15052. return null;
  15053. }
  15054. if (lastLevel && Levels.isEq(lastLevel, level)) {
  15055. return null;
  15056. }
  15057. if (undoManager.data[index.get()]) {
  15058. beforeBookmark.get().each(function (bm) {
  15059. undoManager.data[index.get()].beforeBookmark = bm;
  15060. });
  15061. }
  15062. if (settings.custom_undo_redo_levels) {
  15063. if (undoManager.data.length > settings.custom_undo_redo_levels) {
  15064. for (var i = 0; i < undoManager.data.length - 1; i++) {
  15065. undoManager.data[i] = undoManager.data[i + 1];
  15066. }
  15067. undoManager.data.length--;
  15068. index.set(undoManager.data.length);
  15069. }
  15070. }
  15071. level.bookmark = GetBookmark.getUndoBookmark(editor.selection);
  15072. if (index.get() < undoManager.data.length - 1) {
  15073. undoManager.data.length = index.get() + 1;
  15074. }
  15075. undoManager.data.push(level);
  15076. index.set(undoManager.data.length - 1);
  15077. var args = {
  15078. level: level,
  15079. lastLevel: lastLevel,
  15080. originalEvent: event
  15081. };
  15082. editor.fire('AddUndo', args);
  15083. if (index.get() > 0) {
  15084. editor.setDirty(true);
  15085. editor.fire('change', args);
  15086. }
  15087. return level;
  15088. };
  15089. var clear = function (editor, undoManager, index) {
  15090. undoManager.data = [];
  15091. index.set(0);
  15092. undoManager.typing = false;
  15093. editor.fire('ClearUndos');
  15094. };
  15095. var extra = function (editor, undoManager, index, callback1, callback2) {
  15096. if (undoManager.transact(callback1)) {
  15097. var bookmark = undoManager.data[index.get()].bookmark;
  15098. var lastLevel = undoManager.data[index.get() - 1];
  15099. Levels.applyToEditor(editor, lastLevel, true);
  15100. if (undoManager.transact(callback2)) {
  15101. undoManager.data[index.get() - 1].beforeBookmark = bookmark;
  15102. }
  15103. }
  15104. };
  15105. var redo = function (editor, index, data) {
  15106. var level;
  15107. if (index.get() < data.length - 1) {
  15108. index.set(index.get() + 1);
  15109. level = data[index.get()];
  15110. Levels.applyToEditor(editor, level, false);
  15111. editor.setDirty(true);
  15112. editor.fire('Redo', { level: level });
  15113. }
  15114. return level;
  15115. };
  15116. var undo = function (editor, undoManager, locks, index) {
  15117. var level;
  15118. if (undoManager.typing) {
  15119. undoManager.add();
  15120. undoManager.typing = false;
  15121. setTyping(undoManager, false, locks);
  15122. }
  15123. if (index.get() > 0) {
  15124. index.set(index.get() - 1);
  15125. level = undoManager.data[index.get()];
  15126. Levels.applyToEditor(editor, level, true);
  15127. editor.setDirty(true);
  15128. editor.fire('Undo', { level: level });
  15129. }
  15130. return level;
  15131. };
  15132. var reset = function (undoManager) {
  15133. undoManager.clear();
  15134. undoManager.add();
  15135. };
  15136. var hasUndo = function (editor, undoManager, index) {
  15137. return index.get() > 0 || undoManager.typing && undoManager.data[0] && !Levels.isEq(Levels.createFromEditor(editor), undoManager.data[0]);
  15138. };
  15139. var hasRedo = function (undoManager, index) {
  15140. return index.get() < undoManager.data.length - 1 && !undoManager.typing;
  15141. };
  15142. var transact = function (undoManager, locks, callback) {
  15143. endTyping(undoManager, locks);
  15144. undoManager.beforeChange();
  15145. undoManager.ignore(callback);
  15146. return undoManager.add();
  15147. };
  15148. var ignore = function (locks, callback) {
  15149. try {
  15150. locks.set(locks.get() + 1);
  15151. callback();
  15152. } finally {
  15153. locks.set(locks.get() - 1);
  15154. }
  15155. };
  15156. var registerEvents$1 = function (editor, undoManager, locks) {
  15157. var isFirstTypedCharacter = Cell(false);
  15158. var addNonTypingUndoLevel = function (e) {
  15159. setTyping(undoManager, false, locks);
  15160. undoManager.add({}, e);
  15161. };
  15162. editor.on('init', function () {
  15163. undoManager.add();
  15164. });
  15165. editor.on('BeforeExecCommand', function (e) {
  15166. var cmd = e.command;
  15167. if (cmd !== 'Undo' && cmd !== 'Redo' && cmd !== 'mceRepaint') {
  15168. endTyping(undoManager, locks);
  15169. undoManager.beforeChange();
  15170. }
  15171. });
  15172. editor.on('ExecCommand', function (e) {
  15173. var cmd = e.command;
  15174. if (cmd !== 'Undo' && cmd !== 'Redo' && cmd !== 'mceRepaint') {
  15175. addNonTypingUndoLevel(e);
  15176. }
  15177. });
  15178. editor.on('ObjectResizeStart cut', function () {
  15179. undoManager.beforeChange();
  15180. });
  15181. editor.on('SaveContent ObjectResized blur', addNonTypingUndoLevel);
  15182. editor.on('dragend', addNonTypingUndoLevel);
  15183. editor.on('keyup', function (e) {
  15184. var keyCode = e.keyCode;
  15185. if (e.isDefaultPrevented()) {
  15186. return;
  15187. }
  15188. if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45 || e.ctrlKey) {
  15189. addNonTypingUndoLevel();
  15190. editor.nodeChanged();
  15191. }
  15192. if (keyCode === 46 || keyCode === 8) {
  15193. editor.nodeChanged();
  15194. }
  15195. if (isFirstTypedCharacter.get() && undoManager.typing && Levels.isEq(Levels.createFromEditor(editor), undoManager.data[0]) === false) {
  15196. if (editor.isDirty() === false) {
  15197. editor.setDirty(true);
  15198. editor.fire('change', {
  15199. level: undoManager.data[0],
  15200. lastLevel: null
  15201. });
  15202. }
  15203. editor.fire('TypingUndo');
  15204. isFirstTypedCharacter.set(false);
  15205. editor.nodeChanged();
  15206. }
  15207. });
  15208. editor.on('keydown', function (e) {
  15209. var keyCode = e.keyCode;
  15210. if (e.isDefaultPrevented()) {
  15211. return;
  15212. }
  15213. if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45) {
  15214. if (undoManager.typing) {
  15215. addNonTypingUndoLevel(e);
  15216. }
  15217. return;
  15218. }
  15219. var modKey = e.ctrlKey && !e.altKey || e.metaKey;
  15220. if ((keyCode < 16 || keyCode > 20) && keyCode !== 224 && keyCode !== 91 && !undoManager.typing && !modKey) {
  15221. undoManager.beforeChange();
  15222. setTyping(undoManager, true, locks);
  15223. undoManager.add({}, e);
  15224. isFirstTypedCharacter.set(true);
  15225. }
  15226. });
  15227. editor.on('mousedown', function (e) {
  15228. if (undoManager.typing) {
  15229. addNonTypingUndoLevel(e);
  15230. }
  15231. });
  15232. var isInsertReplacementText = function (event) {
  15233. return event.inputType === 'insertReplacementText';
  15234. };
  15235. var isInsertTextDataNull = function (event) {
  15236. return event.inputType === 'insertText' && event.data === null;
  15237. };
  15238. editor.on('input', function (e) {
  15239. if (e.inputType && (isInsertReplacementText(e) || isInsertTextDataNull(e))) {
  15240. addNonTypingUndoLevel(e);
  15241. }
  15242. });
  15243. editor.on('AddUndo Undo Redo ClearUndos', function (e) {
  15244. if (!e.isDefaultPrevented()) {
  15245. editor.nodeChanged();
  15246. }
  15247. });
  15248. };
  15249. var addKeyboardShortcuts = function (editor) {
  15250. editor.addShortcut('meta+z', '', 'Undo');
  15251. editor.addShortcut('meta+y,meta+shift+z', '', 'Redo');
  15252. };
  15253. var UndoManager = function (editor) {
  15254. var beforeBookmark = Cell(Option.none());
  15255. var locks = Cell(0);
  15256. var index = Cell(0);
  15257. var undoManager = {
  15258. data: [],
  15259. typing: false,
  15260. beforeChange: function () {
  15261. beforeChange(editor, locks, beforeBookmark);
  15262. },
  15263. add: function (level, event) {
  15264. return addUndoLevel(editor, undoManager, index, locks, beforeBookmark, level, event);
  15265. },
  15266. undo: function () {
  15267. return undo(editor, undoManager, locks, index);
  15268. },
  15269. redo: function () {
  15270. return redo(editor, index, undoManager.data);
  15271. },
  15272. clear: function () {
  15273. clear(editor, undoManager, index);
  15274. },
  15275. reset: function () {
  15276. reset(undoManager);
  15277. },
  15278. hasUndo: function () {
  15279. return hasUndo(editor, undoManager, index);
  15280. },
  15281. hasRedo: function () {
  15282. return hasRedo(undoManager, index);
  15283. },
  15284. transact: function (callback) {
  15285. return transact(undoManager, locks, callback);
  15286. },
  15287. ignore: function (callback) {
  15288. ignore(locks, callback);
  15289. },
  15290. extra: function (callback1, callback2) {
  15291. extra(editor, undoManager, index, callback1, callback2);
  15292. }
  15293. };
  15294. registerEvents$1(editor, undoManager, locks);
  15295. addKeyboardShortcuts(editor);
  15296. return undoManager;
  15297. };
  15298. var getLastChildren$1 = function (elm) {
  15299. var children = [];
  15300. var rawNode = elm.dom();
  15301. while (rawNode) {
  15302. children.push(Element.fromDom(rawNode));
  15303. rawNode = rawNode.lastChild;
  15304. }
  15305. return children;
  15306. };
  15307. var removeTrailingBr = function (elm) {
  15308. var allBrs = descendants$1(elm, 'br');
  15309. var brs = filter(getLastChildren$1(elm).slice(-1), isBr$1);
  15310. if (allBrs.length === brs.length) {
  15311. each(brs, remove$1);
  15312. }
  15313. };
  15314. var fillWithPaddingBr = function (elm) {
  15315. empty(elm);
  15316. append(elm, Element.fromHtml('<br data-mce-bogus="1">'));
  15317. };
  15318. var isPaddingContents = function (elm) {
  15319. return isText$1(elm) ? get$6(elm) === '\xA0' : isBr$1(elm);
  15320. };
  15321. var isPaddedElement = function (elm) {
  15322. return filter(children(elm), isPaddingContents).length === 1;
  15323. };
  15324. var trimBlockTrailingBr = function (elm) {
  15325. lastChild(elm).each(function (lastChild) {
  15326. prevSibling(lastChild).each(function (lastChildPrevSibling) {
  15327. if (isBlock(elm) && isBr$1(lastChild) && isBlock(lastChildPrevSibling)) {
  15328. remove$1(lastChild);
  15329. }
  15330. });
  15331. });
  15332. };
  15333. var PaddingBr = {
  15334. removeTrailingBr: removeTrailingBr,
  15335. fillWithPaddingBr: fillWithPaddingBr,
  15336. isPaddedElement: isPaddedElement,
  15337. trimBlockTrailingBr: trimBlockTrailingBr
  15338. };
  15339. var isEq$3 = FormatUtils.isEq;
  15340. var matchesUnInheritedFormatSelector = function (ed, node, name) {
  15341. var formatList = ed.formatter.get(name);
  15342. if (formatList) {
  15343. for (var i = 0; i < formatList.length; i++) {
  15344. if (formatList[i].inherit === false && ed.dom.is(node, formatList[i].selector)) {
  15345. return true;
  15346. }
  15347. }
  15348. }
  15349. return false;
  15350. };
  15351. var matchParents = function (editor, node, name, vars) {
  15352. var root = editor.dom.getRoot();
  15353. if (node === root) {
  15354. return false;
  15355. }
  15356. node = editor.dom.getParent(node, function (node) {
  15357. if (matchesUnInheritedFormatSelector(editor, node, name)) {
  15358. return true;
  15359. }
  15360. return node.parentNode === root || !!matchNode(editor, node, name, vars, true);
  15361. });
  15362. return matchNode(editor, node, name, vars);
  15363. };
  15364. var matchName = function (dom, node, format) {
  15365. if (isEq$3(node, format.inline)) {
  15366. return true;
  15367. }
  15368. if (isEq$3(node, format.block)) {
  15369. return true;
  15370. }
  15371. if (format.selector) {
  15372. return node.nodeType === 1 && dom.is(node, format.selector);
  15373. }
  15374. };
  15375. var matchItems = function (dom, node, format, itemName, similar, vars) {
  15376. var key, value;
  15377. var items = format[itemName];
  15378. var i;
  15379. if (format.onmatch) {
  15380. return format.onmatch(node, format, itemName);
  15381. }
  15382. if (items) {
  15383. if (typeof items.length === 'undefined') {
  15384. for (key in items) {
  15385. if (items.hasOwnProperty(key)) {
  15386. if (itemName === 'attributes') {
  15387. value = dom.getAttrib(node, key);
  15388. } else {
  15389. value = FormatUtils.getStyle(dom, node, key);
  15390. }
  15391. if (similar && !value && !format.exact) {
  15392. return;
  15393. }
  15394. if ((!similar || format.exact) && !isEq$3(value, FormatUtils.normalizeStyleValue(dom, FormatUtils.replaceVars(items[key], vars), key))) {
  15395. return;
  15396. }
  15397. }
  15398. }
  15399. } else {
  15400. for (i = 0; i < items.length; i++) {
  15401. if (itemName === 'attributes' ? dom.getAttrib(node, items[i]) : FormatUtils.getStyle(dom, node, items[i])) {
  15402. return format;
  15403. }
  15404. }
  15405. }
  15406. }
  15407. return format;
  15408. };
  15409. var matchNode = function (ed, node, name, vars, similar) {
  15410. var formatList = ed.formatter.get(name);
  15411. var format, i, x, classes;
  15412. var dom = ed.dom;
  15413. if (formatList && node) {
  15414. for (i = 0; i < formatList.length; i++) {
  15415. format = formatList[i];
  15416. if (matchName(ed.dom, node, format) && matchItems(dom, node, format, 'attributes', similar, vars) && matchItems(dom, node, format, 'styles', similar, vars)) {
  15417. if (classes = format.classes) {
  15418. for (x = 0; x < classes.length; x++) {
  15419. if (!ed.dom.hasClass(node, classes[x])) {
  15420. return;
  15421. }
  15422. }
  15423. }
  15424. return format;
  15425. }
  15426. }
  15427. }
  15428. };
  15429. var match = function (editor, name, vars, node) {
  15430. var startNode;
  15431. if (node) {
  15432. return matchParents(editor, node, name, vars);
  15433. }
  15434. node = editor.selection.getNode();
  15435. if (matchParents(editor, node, name, vars)) {
  15436. return true;
  15437. }
  15438. startNode = editor.selection.getStart();
  15439. if (startNode !== node) {
  15440. if (matchParents(editor, startNode, name, vars)) {
  15441. return true;
  15442. }
  15443. }
  15444. return false;
  15445. };
  15446. var matchAll = function (editor, names, vars) {
  15447. var startElement;
  15448. var matchedFormatNames = [];
  15449. var checkedMap = {};
  15450. startElement = editor.selection.getStart();
  15451. editor.dom.getParent(startElement, function (node) {
  15452. var i, name;
  15453. for (i = 0; i < names.length; i++) {
  15454. name = names[i];
  15455. if (!checkedMap[name] && matchNode(editor, node, name, vars)) {
  15456. checkedMap[name] = true;
  15457. matchedFormatNames.push(name);
  15458. }
  15459. }
  15460. }, editor.dom.getRoot());
  15461. return matchedFormatNames;
  15462. };
  15463. var canApply = function (editor, name) {
  15464. var formatList = editor.formatter.get(name);
  15465. var startNode, parents, i, x, selector;
  15466. var dom = editor.dom;
  15467. if (formatList) {
  15468. startNode = editor.selection.getStart();
  15469. parents = FormatUtils.getParents(dom, startNode);
  15470. for (x = formatList.length - 1; x >= 0; x--) {
  15471. selector = formatList[x].selector;
  15472. if (!selector || formatList[x].defaultBlock) {
  15473. return true;
  15474. }
  15475. for (i = parents.length - 1; i >= 0; i--) {
  15476. if (dom.is(parents[i], selector)) {
  15477. return true;
  15478. }
  15479. }
  15480. }
  15481. }
  15482. return false;
  15483. };
  15484. var MatchFormat = {
  15485. matchNode: matchNode,
  15486. matchName: matchName,
  15487. match: match,
  15488. matchAll: matchAll,
  15489. canApply: canApply,
  15490. matchesUnInheritedFormatSelector: matchesUnInheritedFormatSelector
  15491. };
  15492. var splitText = function (node, offset) {
  15493. return node.splitText(offset);
  15494. };
  15495. var split$1 = function (rng) {
  15496. var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
  15497. if (startContainer === endContainer && NodeType.isText(startContainer)) {
  15498. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  15499. endContainer = splitText(startContainer, startOffset);
  15500. startContainer = endContainer.previousSibling;
  15501. if (endOffset > startOffset) {
  15502. endOffset = endOffset - startOffset;
  15503. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  15504. endOffset = endContainer.nodeValue.length;
  15505. startOffset = 0;
  15506. } else {
  15507. endOffset = 0;
  15508. }
  15509. }
  15510. } else {
  15511. if (NodeType.isText(startContainer) && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  15512. startContainer = splitText(startContainer, startOffset);
  15513. startOffset = 0;
  15514. }
  15515. if (NodeType.isText(endContainer) && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  15516. endContainer = splitText(endContainer, endOffset).previousSibling;
  15517. endOffset = endContainer.nodeValue.length;
  15518. }
  15519. }
  15520. return {
  15521. startContainer: startContainer,
  15522. startOffset: startOffset,
  15523. endContainer: endContainer,
  15524. endOffset: endOffset
  15525. };
  15526. };
  15527. var isCollapsibleWhitespace = function (c) {
  15528. return ' \f\n\r\t\x0B'.indexOf(c) !== -1;
  15529. };
  15530. var normalizeContent = function (content, isStartOfContent, isEndOfContent) {
  15531. var result = foldl(content, function (acc, c) {
  15532. if (isCollapsibleWhitespace(c) || c === '\xA0') {
  15533. if (acc.previousCharIsSpace || acc.str === '' && isStartOfContent || acc.str.length === content.length - 1 && isEndOfContent) {
  15534. return {
  15535. previousCharIsSpace: false,
  15536. str: acc.str + '\xA0'
  15537. };
  15538. } else {
  15539. return {
  15540. previousCharIsSpace: true,
  15541. str: acc.str + ' '
  15542. };
  15543. }
  15544. } else {
  15545. return {
  15546. previousCharIsSpace: false,
  15547. str: acc.str + c
  15548. };
  15549. }
  15550. }, {
  15551. previousCharIsSpace: false,
  15552. str: ''
  15553. });
  15554. return result.str;
  15555. };
  15556. var normalize = function (node, offset, count) {
  15557. if (count === 0) {
  15558. return;
  15559. }
  15560. var whitespace = node.data.slice(offset, offset + count);
  15561. var isEndOfContent = offset + count >= node.data.length;
  15562. var isStartOfContent = offset === 0;
  15563. node.replaceData(offset, count, normalizeContent(whitespace, isStartOfContent, isEndOfContent));
  15564. };
  15565. var normalizeWhitespaceAfter = function (node, offset) {
  15566. var content = node.data.slice(offset);
  15567. var whitespaceCount = content.length - lTrim(content).length;
  15568. return normalize(node, offset, whitespaceCount);
  15569. };
  15570. var normalizeWhitespaceBefore = function (node, offset) {
  15571. var content = node.data.slice(0, offset);
  15572. var whitespaceCount = content.length - rTrim(content).length;
  15573. return normalize(node, offset - whitespaceCount, whitespaceCount);
  15574. };
  15575. var mergeTextNodes = function (prevNode, nextNode, normalizeWhitespace) {
  15576. var whitespaceOffset = rTrim(prevNode.data).length;
  15577. prevNode.appendData(nextNode.data);
  15578. remove$1(Element.fromDom(nextNode));
  15579. if (normalizeWhitespace) {
  15580. normalizeWhitespaceAfter(prevNode, whitespaceOffset);
  15581. }
  15582. return prevNode;
  15583. };
  15584. var ancestor$2 = function (scope, selector, isRoot) {
  15585. return ancestor$1(scope, selector, isRoot).isSome();
  15586. };
  15587. var hasWhitespacePreserveParent = function (rootNode, node) {
  15588. var rootElement = Element.fromDom(rootNode);
  15589. var startNode = Element.fromDom(node);
  15590. return ancestor$2(startNode, 'pre,code', curry(eq, rootElement));
  15591. };
  15592. var isWhitespace = function (rootNode, node) {
  15593. return NodeType.isText(node) && /^[ \t\r\n]*$/.test(node.data) && hasWhitespacePreserveParent(rootNode, node) === false;
  15594. };
  15595. var isNamedAnchor = function (node) {
  15596. return NodeType.isElement(node) && node.nodeName === 'A' && node.hasAttribute('name');
  15597. };
  15598. var isContent$1 = function (rootNode, node) {
  15599. return isCaretCandidate(node) && isWhitespace(rootNode, node) === false || isNamedAnchor(node) || isBookmark(node);
  15600. };
  15601. var isBookmark = NodeType.hasAttribute('data-mce-bookmark');
  15602. var isBogus$2 = NodeType.hasAttribute('data-mce-bogus');
  15603. var isBogusAll$1 = NodeType.hasAttributeValue('data-mce-bogus', 'all');
  15604. var isEmptyNode = function (targetNode) {
  15605. var node, brCount = 0;
  15606. if (isContent$1(targetNode, targetNode)) {
  15607. return false;
  15608. } else {
  15609. node = targetNode.firstChild;
  15610. if (!node) {
  15611. return true;
  15612. }
  15613. var walker = new TreeWalker(node, targetNode);
  15614. do {
  15615. if (isBogusAll$1(node)) {
  15616. node = walker.next(true);
  15617. continue;
  15618. }
  15619. if (isBogus$2(node)) {
  15620. node = walker.next();
  15621. continue;
  15622. }
  15623. if (NodeType.isBr(node)) {
  15624. brCount++;
  15625. node = walker.next();
  15626. continue;
  15627. }
  15628. if (isContent$1(targetNode, node)) {
  15629. return false;
  15630. }
  15631. node = walker.next();
  15632. } while (node);
  15633. return brCount <= 1;
  15634. }
  15635. };
  15636. var isEmpty$1 = function (elm) {
  15637. return isEmptyNode(elm.dom());
  15638. };
  15639. var Empty = { isEmpty: isEmpty$1 };
  15640. var needsReposition = function (pos, elm) {
  15641. var container = pos.container();
  15642. var offset = pos.offset();
  15643. return CaretPosition$1.isTextPosition(pos) === false && container === elm.parentNode && offset > CaretPosition$1.before(elm).offset();
  15644. };
  15645. var reposition = function (elm, pos) {
  15646. return needsReposition(pos, elm) ? CaretPosition$1(pos.container(), pos.offset() - 1) : pos;
  15647. };
  15648. var beforeOrStartOf = function (node) {
  15649. return NodeType.isText(node) ? CaretPosition$1(node, 0) : CaretPosition$1.before(node);
  15650. };
  15651. var afterOrEndOf = function (node) {
  15652. return NodeType.isText(node) ? CaretPosition$1(node, node.data.length) : CaretPosition$1.after(node);
  15653. };
  15654. var getPreviousSiblingCaretPosition = function (elm) {
  15655. if (isCaretCandidate(elm.previousSibling)) {
  15656. return Option.some(afterOrEndOf(elm.previousSibling));
  15657. } else {
  15658. return elm.previousSibling ? CaretFinder.lastPositionIn(elm.previousSibling) : Option.none();
  15659. }
  15660. };
  15661. var getNextSiblingCaretPosition = function (elm) {
  15662. if (isCaretCandidate(elm.nextSibling)) {
  15663. return Option.some(beforeOrStartOf(elm.nextSibling));
  15664. } else {
  15665. return elm.nextSibling ? CaretFinder.firstPositionIn(elm.nextSibling) : Option.none();
  15666. }
  15667. };
  15668. var findCaretPositionBackwardsFromElm = function (rootElement, elm) {
  15669. var startPosition = CaretPosition$1.before(elm.previousSibling ? elm.previousSibling : elm.parentNode);
  15670. return CaretFinder.prevPosition(rootElement, startPosition).fold(function () {
  15671. return CaretFinder.nextPosition(rootElement, CaretPosition$1.after(elm));
  15672. }, Option.some);
  15673. };
  15674. var findCaretPositionForwardsFromElm = function (rootElement, elm) {
  15675. return CaretFinder.nextPosition(rootElement, CaretPosition$1.after(elm)).fold(function () {
  15676. return CaretFinder.prevPosition(rootElement, CaretPosition$1.before(elm));
  15677. }, Option.some);
  15678. };
  15679. var findCaretPositionBackwards = function (rootElement, elm) {
  15680. return getPreviousSiblingCaretPosition(elm).orThunk(function () {
  15681. return getNextSiblingCaretPosition(elm);
  15682. }).orThunk(function () {
  15683. return findCaretPositionBackwardsFromElm(rootElement, elm);
  15684. });
  15685. };
  15686. var findCaretPositionForward = function (rootElement, elm) {
  15687. return getNextSiblingCaretPosition(elm).orThunk(function () {
  15688. return getPreviousSiblingCaretPosition(elm);
  15689. }).orThunk(function () {
  15690. return findCaretPositionForwardsFromElm(rootElement, elm);
  15691. });
  15692. };
  15693. var findCaretPosition$1 = function (forward, rootElement, elm) {
  15694. return forward ? findCaretPositionForward(rootElement, elm) : findCaretPositionBackwards(rootElement, elm);
  15695. };
  15696. var findCaretPosOutsideElmAfterDelete = function (forward, rootElement, elm) {
  15697. return findCaretPosition$1(forward, rootElement, elm).map(curry(reposition, elm));
  15698. };
  15699. var setSelection = function (editor, forward, pos) {
  15700. pos.fold(function () {
  15701. editor.focus();
  15702. }, function (pos) {
  15703. editor.selection.setRng(pos.toRange(), forward);
  15704. });
  15705. };
  15706. var eqRawNode = function (rawNode) {
  15707. return function (elm) {
  15708. return elm.dom() === rawNode;
  15709. };
  15710. };
  15711. var isBlock$2 = function (editor, elm) {
  15712. return elm && editor.schema.getBlockElements().hasOwnProperty(name(elm));
  15713. };
  15714. var paddEmptyBlock = function (elm) {
  15715. if (Empty.isEmpty(elm)) {
  15716. var br = Element.fromHtml('<br data-mce-bogus="1">');
  15717. empty(elm);
  15718. append(elm, br);
  15719. return Option.some(CaretPosition$1.before(br.dom()));
  15720. } else {
  15721. return Option.none();
  15722. }
  15723. };
  15724. var deleteNormalized = function (elm, afterDeletePosOpt, normalizeWhitespace) {
  15725. var prevTextOpt = prevSibling(elm).filter(isText$1);
  15726. var nextTextOpt = nextSibling(elm).filter(isText$1);
  15727. remove$1(elm);
  15728. return lift3(prevTextOpt, nextTextOpt, afterDeletePosOpt, function (prev, next, pos) {
  15729. var prevNode = prev.dom(), nextNode = next.dom();
  15730. var offset = prevNode.data.length;
  15731. mergeTextNodes(prevNode, nextNode, normalizeWhitespace);
  15732. return pos.container() === nextNode ? CaretPosition$1(prevNode, offset) : pos;
  15733. }).orThunk(function () {
  15734. if (normalizeWhitespace) {
  15735. prevTextOpt.each(function (elm) {
  15736. return normalizeWhitespaceBefore(elm.dom(), elm.dom().length);
  15737. });
  15738. nextTextOpt.each(function (elm) {
  15739. return normalizeWhitespaceAfter(elm.dom(), 0);
  15740. });
  15741. }
  15742. return afterDeletePosOpt;
  15743. });
  15744. };
  15745. var isInlineElement = function (editor, element) {
  15746. return has(editor.schema.getTextInlineElements(), name(element));
  15747. };
  15748. var deleteElement = function (editor, forward, elm, moveCaret) {
  15749. if (moveCaret === void 0) {
  15750. moveCaret = true;
  15751. }
  15752. var afterDeletePos = findCaretPosOutsideElmAfterDelete(forward, editor.getBody(), elm.dom());
  15753. var parentBlock = ancestor(elm, curry(isBlock$2, editor), eqRawNode(editor.getBody()));
  15754. var normalizedAfterDeletePos = deleteNormalized(elm, afterDeletePos, isInlineElement(editor, elm));
  15755. if (editor.dom.isEmpty(editor.getBody())) {
  15756. editor.setContent('');
  15757. editor.selection.setCursorLocation();
  15758. } else {
  15759. parentBlock.bind(paddEmptyBlock).fold(function () {
  15760. if (moveCaret) {
  15761. setSelection(editor, forward, normalizedAfterDeletePos);
  15762. }
  15763. }, function (paddPos) {
  15764. if (moveCaret) {
  15765. setSelection(editor, forward, Option.some(paddPos));
  15766. }
  15767. });
  15768. }
  15769. };
  15770. var DeleteElement = { deleteElement: deleteElement };
  15771. var ZWSP$1 = Zwsp.ZWSP, CARET_ID$1 = '_mce_caret';
  15772. var importNode = function (ownerDocument, node) {
  15773. return ownerDocument.importNode(node, true);
  15774. };
  15775. var getEmptyCaretContainers = function (node) {
  15776. var nodes = [];
  15777. while (node) {
  15778. if (node.nodeType === 3 && node.nodeValue !== ZWSP$1 || node.childNodes.length > 1) {
  15779. return [];
  15780. }
  15781. if (node.nodeType === 1) {
  15782. nodes.push(node);
  15783. }
  15784. node = node.firstChild;
  15785. }
  15786. return nodes;
  15787. };
  15788. var isCaretContainerEmpty = function (node) {
  15789. return getEmptyCaretContainers(node).length > 0;
  15790. };
  15791. var findFirstTextNode = function (node) {
  15792. if (node) {
  15793. var walker = new TreeWalker(node, node);
  15794. for (node = walker.current(); node; node = walker.next()) {
  15795. if (node.nodeType === 3) {
  15796. return node;
  15797. }
  15798. }
  15799. }
  15800. return null;
  15801. };
  15802. var createCaretContainer = function (fill) {
  15803. var caretContainer = Element.fromTag('span');
  15804. setAll(caretContainer, {
  15805. 'id': CARET_ID$1,
  15806. 'data-mce-bogus': '1',
  15807. 'data-mce-type': 'format-caret'
  15808. });
  15809. if (fill) {
  15810. append(caretContainer, Element.fromText(ZWSP$1));
  15811. }
  15812. return caretContainer;
  15813. };
  15814. var trimZwspFromCaretContainer = function (caretContainerNode) {
  15815. var textNode = findFirstTextNode(caretContainerNode);
  15816. if (textNode && textNode.nodeValue.charAt(0) === ZWSP$1) {
  15817. textNode.deleteData(0, 1);
  15818. }
  15819. return textNode;
  15820. };
  15821. var removeCaretContainerNode = function (editor, node, moveCaret) {
  15822. if (moveCaret === void 0) {
  15823. moveCaret = true;
  15824. }
  15825. var dom = editor.dom, selection = editor.selection;
  15826. if (isCaretContainerEmpty(node)) {
  15827. DeleteElement.deleteElement(editor, false, Element.fromDom(node), moveCaret);
  15828. } else {
  15829. var rng = selection.getRng();
  15830. var block = dom.getParent(node, dom.isBlock);
  15831. var textNode = trimZwspFromCaretContainer(node);
  15832. if (rng.startContainer === textNode && rng.startOffset > 0) {
  15833. rng.setStart(textNode, rng.startOffset - 1);
  15834. }
  15835. if (rng.endContainer === textNode && rng.endOffset > 0) {
  15836. rng.setEnd(textNode, rng.endOffset - 1);
  15837. }
  15838. dom.remove(node, true);
  15839. if (block && dom.isEmpty(block)) {
  15840. PaddingBr.fillWithPaddingBr(Element.fromDom(block));
  15841. }
  15842. selection.setRng(rng);
  15843. }
  15844. };
  15845. var removeCaretContainer = function (editor, node, moveCaret) {
  15846. if (moveCaret === void 0) {
  15847. moveCaret = true;
  15848. }
  15849. var dom = editor.dom, selection = editor.selection;
  15850. if (!node) {
  15851. node = getParentCaretContainer(editor.getBody(), selection.getStart());
  15852. if (!node) {
  15853. while (node = dom.get(CARET_ID$1)) {
  15854. removeCaretContainerNode(editor, node, false);
  15855. }
  15856. }
  15857. } else {
  15858. removeCaretContainerNode(editor, node, moveCaret);
  15859. }
  15860. };
  15861. var insertCaretContainerNode = function (editor, caretContainer, formatNode) {
  15862. var dom = editor.dom, block = dom.getParent(formatNode, curry(FormatUtils.isTextBlock, editor));
  15863. if (block && dom.isEmpty(block)) {
  15864. formatNode.parentNode.replaceChild(caretContainer, formatNode);
  15865. } else {
  15866. PaddingBr.removeTrailingBr(Element.fromDom(formatNode));
  15867. if (dom.isEmpty(formatNode)) {
  15868. formatNode.parentNode.replaceChild(caretContainer, formatNode);
  15869. } else {
  15870. dom.insertAfter(caretContainer, formatNode);
  15871. }
  15872. }
  15873. };
  15874. var appendNode = function (parentNode, node) {
  15875. parentNode.appendChild(node);
  15876. return node;
  15877. };
  15878. var insertFormatNodesIntoCaretContainer = function (formatNodes, caretContainer) {
  15879. var innerMostFormatNode = foldr(formatNodes, function (parentNode, formatNode) {
  15880. return appendNode(parentNode, formatNode.cloneNode(false));
  15881. }, caretContainer);
  15882. return appendNode(innerMostFormatNode, innerMostFormatNode.ownerDocument.createTextNode(ZWSP$1));
  15883. };
  15884. var applyCaretFormat = function (editor, name, vars) {
  15885. var rng, caretContainer, textNode, offset, bookmark, container, text;
  15886. var selection = editor.selection;
  15887. rng = selection.getRng();
  15888. offset = rng.startOffset;
  15889. container = rng.startContainer;
  15890. text = container.nodeValue;
  15891. caretContainer = getParentCaretContainer(editor.getBody(), selection.getStart());
  15892. if (caretContainer) {
  15893. textNode = findFirstTextNode(caretContainer);
  15894. }
  15895. var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/;
  15896. if (text && offset > 0 && offset < text.length && wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) {
  15897. bookmark = selection.getBookmark();
  15898. rng.collapse(true);
  15899. rng = ExpandRange.expandRng(editor, rng, editor.formatter.get(name));
  15900. rng = split$1(rng);
  15901. editor.formatter.apply(name, vars, rng);
  15902. selection.moveToBookmark(bookmark);
  15903. } else {
  15904. if (!caretContainer || textNode.nodeValue !== ZWSP$1) {
  15905. caretContainer = importNode(editor.getDoc(), createCaretContainer(true).dom());
  15906. textNode = caretContainer.firstChild;
  15907. rng.insertNode(caretContainer);
  15908. offset = 1;
  15909. editor.formatter.apply(name, vars, caretContainer);
  15910. } else {
  15911. editor.formatter.apply(name, vars, caretContainer);
  15912. }
  15913. selection.setCursorLocation(textNode, offset);
  15914. }
  15915. };
  15916. var removeCaretFormat = function (editor, name, vars, similar) {
  15917. var dom = editor.dom, selection = editor.selection;
  15918. var container, offset, bookmark;
  15919. var hasContentAfter, node, formatNode;
  15920. var parents = [], rng = selection.getRng();
  15921. var caretContainer;
  15922. container = rng.startContainer;
  15923. offset = rng.startOffset;
  15924. node = container;
  15925. if (container.nodeType === 3) {
  15926. if (offset !== container.nodeValue.length) {
  15927. hasContentAfter = true;
  15928. }
  15929. node = node.parentNode;
  15930. }
  15931. while (node) {
  15932. if (MatchFormat.matchNode(editor, node, name, vars, similar)) {
  15933. formatNode = node;
  15934. break;
  15935. }
  15936. if (node.nextSibling) {
  15937. hasContentAfter = true;
  15938. }
  15939. parents.push(node);
  15940. node = node.parentNode;
  15941. }
  15942. if (!formatNode) {
  15943. return;
  15944. }
  15945. if (hasContentAfter) {
  15946. bookmark = selection.getBookmark();
  15947. rng.collapse(true);
  15948. var expandedRng = ExpandRange.expandRng(editor, rng, editor.formatter.get(name), true);
  15949. expandedRng = split$1(expandedRng);
  15950. editor.formatter.remove(name, vars, expandedRng);
  15951. selection.moveToBookmark(bookmark);
  15952. } else {
  15953. caretContainer = getParentCaretContainer(editor.getBody(), formatNode);
  15954. var newCaretContainer = createCaretContainer(false).dom();
  15955. var caretNode = insertFormatNodesIntoCaretContainer(parents, newCaretContainer);
  15956. if (caretContainer) {
  15957. insertCaretContainerNode(editor, newCaretContainer, caretContainer);
  15958. } else {
  15959. insertCaretContainerNode(editor, newCaretContainer, formatNode);
  15960. }
  15961. removeCaretContainerNode(editor, caretContainer, false);
  15962. selection.setCursorLocation(caretNode, 1);
  15963. if (dom.isEmpty(formatNode)) {
  15964. dom.remove(formatNode);
  15965. }
  15966. }
  15967. };
  15968. var disableCaretContainer = function (editor, keyCode) {
  15969. var selection = editor.selection, body = editor.getBody();
  15970. removeCaretContainer(editor, null, false);
  15971. if ((keyCode === 8 || keyCode === 46) && selection.isCollapsed() && selection.getStart().innerHTML === ZWSP$1) {
  15972. removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
  15973. }
  15974. if (keyCode === 37 || keyCode === 39) {
  15975. removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
  15976. }
  15977. };
  15978. var setup$5 = function (editor) {
  15979. editor.on('mouseup keydown', function (e) {
  15980. disableCaretContainer(editor, e.keyCode);
  15981. });
  15982. };
  15983. var replaceWithCaretFormat = function (targetNode, formatNodes) {
  15984. var caretContainer = createCaretContainer(false);
  15985. var innerMost = insertFormatNodesIntoCaretContainer(formatNodes, caretContainer.dom());
  15986. before(Element.fromDom(targetNode), caretContainer);
  15987. remove$1(Element.fromDom(targetNode));
  15988. return CaretPosition$1(innerMost, 0);
  15989. };
  15990. var isFormatElement = function (editor, element) {
  15991. var inlineElements = editor.schema.getTextInlineElements();
  15992. return inlineElements.hasOwnProperty(name(element)) && !isCaretNode(element.dom()) && !NodeType.isBogus(element.dom());
  15993. };
  15994. var isEmptyCaretFormatElement = function (element) {
  15995. return isCaretNode(element.dom()) && isCaretContainerEmpty(element.dom());
  15996. };
  15997. var postProcessHooks = {}, filter$3 = ArrUtils.filter, each$9 = ArrUtils.each;
  15998. var addPostProcessHook = function (name, hook) {
  15999. var hooks = postProcessHooks[name];
  16000. if (!hooks) {
  16001. postProcessHooks[name] = hooks = [];
  16002. }
  16003. postProcessHooks[name].push(hook);
  16004. };
  16005. var postProcess = function (name, editor) {
  16006. each$9(postProcessHooks[name], function (hook) {
  16007. hook(editor);
  16008. });
  16009. };
  16010. addPostProcessHook('pre', function (editor) {
  16011. var rng = editor.selection.getRng();
  16012. var isPre, blocks;
  16013. var hasPreSibling = function (pre) {
  16014. return isPre(pre.previousSibling) && ArrUtils.indexOf(blocks, pre.previousSibling) !== -1;
  16015. };
  16016. var joinPre = function (pre1, pre2) {
  16017. DomQuery(pre2).remove();
  16018. DomQuery(pre1).append('<br><br>').append(pre2.childNodes);
  16019. };
  16020. isPre = NodeType.matchNodeNames(['pre']);
  16021. if (!rng.collapsed) {
  16022. blocks = editor.selection.getSelectedBlocks();
  16023. each$9(filter$3(filter$3(blocks, isPre), hasPreSibling), function (pre) {
  16024. joinPre(pre.previousSibling, pre);
  16025. });
  16026. }
  16027. });
  16028. var Hooks = { postProcess: postProcess };
  16029. var each$a = Tools.each;
  16030. var ElementUtils = function (dom) {
  16031. this.compare = function (node1, node2) {
  16032. if (node1.nodeName !== node2.nodeName) {
  16033. return false;
  16034. }
  16035. var getAttribs = function (node) {
  16036. var attribs = {};
  16037. each$a(dom.getAttribs(node), function (attr) {
  16038. var name = attr.nodeName.toLowerCase();
  16039. if (name.indexOf('_') !== 0 && name !== 'style' && name.indexOf('data-') !== 0) {
  16040. attribs[name] = dom.getAttrib(node, name);
  16041. }
  16042. });
  16043. return attribs;
  16044. };
  16045. var compareObjects = function (obj1, obj2) {
  16046. var value, name;
  16047. for (name in obj1) {
  16048. if (obj1.hasOwnProperty(name)) {
  16049. value = obj2[name];
  16050. if (typeof value === 'undefined') {
  16051. return false;
  16052. }
  16053. if (obj1[name] !== value) {
  16054. return false;
  16055. }
  16056. delete obj2[name];
  16057. }
  16058. }
  16059. for (name in obj2) {
  16060. if (obj2.hasOwnProperty(name)) {
  16061. return false;
  16062. }
  16063. }
  16064. return true;
  16065. };
  16066. if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
  16067. return false;
  16068. }
  16069. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) {
  16070. return false;
  16071. }
  16072. return !Bookmarks.isBookmarkNode(node1) && !Bookmarks.isBookmarkNode(node2);
  16073. };
  16074. };
  16075. var MCE_ATTR_RE = /^(src|href|style)$/;
  16076. var each$b = Tools.each;
  16077. var isEq$4 = FormatUtils.isEq;
  16078. var isTableCell$2 = function (node) {
  16079. return /^(TH|TD)$/.test(node.nodeName);
  16080. };
  16081. var isChildOfInlineParent = function (dom, node, parent) {
  16082. return dom.isChildOf(node, parent) && node !== parent && !dom.isBlock(parent);
  16083. };
  16084. var getContainer = function (ed, rng, start) {
  16085. var container, offset, lastIdx;
  16086. container = rng[start ? 'startContainer' : 'endContainer'];
  16087. offset = rng[start ? 'startOffset' : 'endOffset'];
  16088. if (NodeType.isElement(container)) {
  16089. lastIdx = container.childNodes.length - 1;
  16090. if (!start && offset) {
  16091. offset--;
  16092. }
  16093. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  16094. }
  16095. if (NodeType.isText(container) && start && offset >= container.nodeValue.length) {
  16096. container = new TreeWalker(container, ed.getBody()).next() || container;
  16097. }
  16098. if (NodeType.isText(container) && !start && offset === 0) {
  16099. container = new TreeWalker(container, ed.getBody()).prev() || container;
  16100. }
  16101. return container;
  16102. };
  16103. var wrap$2 = function (dom, node, name, attrs) {
  16104. var wrapper = dom.create(name, attrs);
  16105. node.parentNode.insertBefore(wrapper, node);
  16106. wrapper.appendChild(node);
  16107. return wrapper;
  16108. };
  16109. var wrapWithSiblings = function (dom, node, next, name, attrs) {
  16110. var start = Element.fromDom(node);
  16111. var wrapper = Element.fromDom(dom.create(name, attrs));
  16112. var siblings = next ? nextSiblings(start) : prevSiblings(start);
  16113. append$1(wrapper, siblings);
  16114. if (next) {
  16115. before(start, wrapper);
  16116. prepend(wrapper, start);
  16117. } else {
  16118. after(start, wrapper);
  16119. append(wrapper, start);
  16120. }
  16121. return wrapper.dom();
  16122. };
  16123. var matchName$1 = function (dom, node, format) {
  16124. if (isEq$4(node, format.inline)) {
  16125. return true;
  16126. }
  16127. if (isEq$4(node, format.block)) {
  16128. return true;
  16129. }
  16130. if (format.selector) {
  16131. return NodeType.isElement(node) && dom.is(node, format.selector);
  16132. }
  16133. };
  16134. var isColorFormatAndAnchor = function (node, format) {
  16135. return format.links && node.tagName === 'A';
  16136. };
  16137. var find$3 = function (dom, node, next, inc) {
  16138. node = FormatUtils.getNonWhiteSpaceSibling(node, next, inc);
  16139. return !node || (node.nodeName === 'BR' || dom.isBlock(node));
  16140. };
  16141. var removeNode$1 = function (ed, node, format) {
  16142. var parentNode = node.parentNode;
  16143. var rootBlockElm;
  16144. var dom = ed.dom, forcedRootBlock = Settings.getForcedRootBlock(ed);
  16145. if (format.block) {
  16146. if (!forcedRootBlock) {
  16147. if (dom.isBlock(node) && !dom.isBlock(parentNode)) {
  16148. if (!find$3(dom, node, false) && !find$3(dom, node.firstChild, true, 1)) {
  16149. node.insertBefore(dom.create('br'), node.firstChild);
  16150. }
  16151. if (!find$3(dom, node, true) && !find$3(dom, node.lastChild, false, 1)) {
  16152. node.appendChild(dom.create('br'));
  16153. }
  16154. }
  16155. } else {
  16156. if (parentNode === dom.getRoot()) {
  16157. if (!format.list_block || !isEq$4(node, format.list_block)) {
  16158. each$b(Tools.grep(node.childNodes), function (node) {
  16159. if (FormatUtils.isValid(ed, forcedRootBlock, node.nodeName.toLowerCase())) {
  16160. if (!rootBlockElm) {
  16161. rootBlockElm = wrap$2(dom, node, forcedRootBlock);
  16162. dom.setAttribs(rootBlockElm, ed.settings.forced_root_block_attrs);
  16163. } else {
  16164. rootBlockElm.appendChild(node);
  16165. }
  16166. } else {
  16167. rootBlockElm = 0;
  16168. }
  16169. });
  16170. }
  16171. }
  16172. }
  16173. }
  16174. if (format.selector && format.inline && !isEq$4(format.inline, node)) {
  16175. return;
  16176. }
  16177. dom.remove(node, 1);
  16178. };
  16179. var removeFormat = function (ed, format, vars, node, compareNode) {
  16180. var i, attrs, stylesModified;
  16181. var dom = ed.dom;
  16182. if (!matchName$1(dom, node, format) && !isColorFormatAndAnchor(node, format)) {
  16183. return false;
  16184. }
  16185. if (format.remove !== 'all') {
  16186. each$b(format.styles, function (value, name) {
  16187. value = FormatUtils.normalizeStyleValue(dom, FormatUtils.replaceVars(value, vars), name);
  16188. if (typeof name === 'number') {
  16189. name = value;
  16190. compareNode = 0;
  16191. }
  16192. if (format.remove_similar || (!compareNode || isEq$4(FormatUtils.getStyle(dom, compareNode, name), value))) {
  16193. dom.setStyle(node, name, '');
  16194. }
  16195. stylesModified = 1;
  16196. });
  16197. if (stylesModified && dom.getAttrib(node, 'style') === '') {
  16198. node.removeAttribute('style');
  16199. node.removeAttribute('data-mce-style');
  16200. }
  16201. each$b(format.attributes, function (value, name) {
  16202. var valueOut;
  16203. value = FormatUtils.replaceVars(value, vars);
  16204. if (typeof name === 'number') {
  16205. name = value;
  16206. compareNode = 0;
  16207. }
  16208. if (format.remove_similar || (!compareNode || isEq$4(dom.getAttrib(compareNode, name), value))) {
  16209. if (name === 'class') {
  16210. value = dom.getAttrib(node, name);
  16211. if (value) {
  16212. valueOut = '';
  16213. each$b(value.split(/\s+/), function (cls) {
  16214. if (/mce\-\w+/.test(cls)) {
  16215. valueOut += (valueOut ? ' ' : '') + cls;
  16216. }
  16217. });
  16218. if (valueOut) {
  16219. dom.setAttrib(node, name, valueOut);
  16220. return;
  16221. }
  16222. }
  16223. }
  16224. if (name === 'class') {
  16225. node.removeAttribute('className');
  16226. }
  16227. if (MCE_ATTR_RE.test(name)) {
  16228. node.removeAttribute('data-mce-' + name);
  16229. }
  16230. node.removeAttribute(name);
  16231. }
  16232. });
  16233. each$b(format.classes, function (value) {
  16234. value = FormatUtils.replaceVars(value, vars);
  16235. if (!compareNode || dom.hasClass(compareNode, value)) {
  16236. dom.removeClass(node, value);
  16237. }
  16238. });
  16239. attrs = dom.getAttribs(node);
  16240. for (i = 0; i < attrs.length; i++) {
  16241. var attrName = attrs[i].nodeName;
  16242. if (attrName.indexOf('_') !== 0 && attrName.indexOf('data-') !== 0) {
  16243. return false;
  16244. }
  16245. }
  16246. }
  16247. if (format.remove !== 'none') {
  16248. removeNode$1(ed, node, format);
  16249. return true;
  16250. }
  16251. };
  16252. var findFormatRoot = function (editor, container, name, vars, similar) {
  16253. var formatRoot;
  16254. each$b(FormatUtils.getParents(editor.dom, container.parentNode).reverse(), function (parent) {
  16255. var format;
  16256. if (!formatRoot && parent.id !== '_start' && parent.id !== '_end') {
  16257. format = MatchFormat.matchNode(editor, parent, name, vars, similar);
  16258. if (format && format.split !== false) {
  16259. formatRoot = parent;
  16260. }
  16261. }
  16262. });
  16263. return formatRoot;
  16264. };
  16265. var wrapAndSplit = function (editor, formatList, formatRoot, container, target, split, format, vars) {
  16266. var parent, clone, lastClone, firstClone, i, formatRootParent;
  16267. var dom = editor.dom;
  16268. if (formatRoot) {
  16269. formatRootParent = formatRoot.parentNode;
  16270. for (parent = container.parentNode; parent && parent !== formatRootParent; parent = parent.parentNode) {
  16271. clone = dom.clone(parent, false);
  16272. for (i = 0; i < formatList.length; i++) {
  16273. if (removeFormat(editor, formatList[i], vars, clone, clone)) {
  16274. clone = 0;
  16275. break;
  16276. }
  16277. }
  16278. if (clone) {
  16279. if (lastClone) {
  16280. clone.appendChild(lastClone);
  16281. }
  16282. if (!firstClone) {
  16283. firstClone = clone;
  16284. }
  16285. lastClone = clone;
  16286. }
  16287. }
  16288. if (split && (!format.mixed || !dom.isBlock(formatRoot))) {
  16289. container = dom.split(formatRoot, container);
  16290. }
  16291. if (lastClone) {
  16292. target.parentNode.insertBefore(lastClone, target);
  16293. firstClone.appendChild(target);
  16294. }
  16295. }
  16296. return container;
  16297. };
  16298. var remove$7 = function (ed, name, vars, node, similar) {
  16299. var formatList = ed.formatter.get(name), format = formatList[0];
  16300. var bookmark, rng, contentEditable = true;
  16301. var dom = ed.dom;
  16302. var selection = ed.selection;
  16303. var splitToFormatRoot = function (container) {
  16304. var formatRoot = findFormatRoot(ed, container, name, vars, similar);
  16305. return wrapAndSplit(ed, formatList, formatRoot, container, container, true, format, vars);
  16306. };
  16307. var isRemoveBookmarkNode = function (node) {
  16308. return Bookmarks.isBookmarkNode(node) && NodeType.isElement(node) && (node.id === '_start' || node.id === '_end');
  16309. };
  16310. var process = function (node) {
  16311. var children, i, l, lastContentEditable, hasContentEditableState;
  16312. if (NodeType.isElement(node) && dom.getContentEditable(node)) {
  16313. lastContentEditable = contentEditable;
  16314. contentEditable = dom.getContentEditable(node) === 'true';
  16315. hasContentEditableState = true;
  16316. }
  16317. children = Tools.grep(node.childNodes);
  16318. if (contentEditable && !hasContentEditableState) {
  16319. for (i = 0, l = formatList.length; i < l; i++) {
  16320. if (removeFormat(ed, formatList[i], vars, node, node)) {
  16321. break;
  16322. }
  16323. }
  16324. }
  16325. if (format.deep) {
  16326. if (children.length) {
  16327. for (i = 0, l = children.length; i < l; i++) {
  16328. process(children[i]);
  16329. }
  16330. if (hasContentEditableState) {
  16331. contentEditable = lastContentEditable;
  16332. }
  16333. }
  16334. }
  16335. };
  16336. var unwrap = function (start) {
  16337. var node = dom.get(start ? '_start' : '_end');
  16338. var out = node[start ? 'firstChild' : 'lastChild'];
  16339. if (isRemoveBookmarkNode(out)) {
  16340. out = out[start ? 'firstChild' : 'lastChild'];
  16341. }
  16342. if (NodeType.isText(out) && out.data.length === 0) {
  16343. out = start ? node.previousSibling || node.nextSibling : node.nextSibling || node.previousSibling;
  16344. }
  16345. dom.remove(node, true);
  16346. return out;
  16347. };
  16348. var removeRngStyle = function (rng) {
  16349. var startContainer, endContainer;
  16350. var commonAncestorContainer = rng.commonAncestorContainer;
  16351. rng = ExpandRange.expandRng(ed, rng, formatList, true);
  16352. if (format.split) {
  16353. rng = split$1(rng);
  16354. startContainer = getContainer(ed, rng, true);
  16355. endContainer = getContainer(ed, rng);
  16356. if (startContainer !== endContainer) {
  16357. if (/^(TR|TH|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
  16358. if (startContainer.nodeName === 'TR') {
  16359. startContainer = startContainer.firstChild.firstChild || startContainer;
  16360. } else {
  16361. startContainer = startContainer.firstChild || startContainer;
  16362. }
  16363. }
  16364. if (commonAncestorContainer && /^T(HEAD|BODY|FOOT|R)$/.test(commonAncestorContainer.nodeName) && isTableCell$2(endContainer) && endContainer.firstChild) {
  16365. endContainer = endContainer.firstChild || endContainer;
  16366. }
  16367. if (isChildOfInlineParent(dom, startContainer, endContainer)) {
  16368. var marker = Option.from(startContainer.firstChild).getOr(startContainer);
  16369. splitToFormatRoot(wrapWithSiblings(dom, marker, true, 'span', {
  16370. 'id': '_start',
  16371. 'data-mce-type': 'bookmark'
  16372. }));
  16373. unwrap(true);
  16374. return;
  16375. }
  16376. if (isChildOfInlineParent(dom, endContainer, startContainer)) {
  16377. var marker = Option.from(endContainer.lastChild).getOr(endContainer);
  16378. splitToFormatRoot(wrapWithSiblings(dom, marker, false, 'span', {
  16379. 'id': '_end',
  16380. 'data-mce-type': 'bookmark'
  16381. }));
  16382. unwrap(false);
  16383. return;
  16384. }
  16385. startContainer = wrap$2(dom, startContainer, 'span', {
  16386. 'id': '_start',
  16387. 'data-mce-type': 'bookmark'
  16388. });
  16389. endContainer = wrap$2(dom, endContainer, 'span', {
  16390. 'id': '_end',
  16391. 'data-mce-type': 'bookmark'
  16392. });
  16393. splitToFormatRoot(startContainer);
  16394. splitToFormatRoot(endContainer);
  16395. startContainer = unwrap(true);
  16396. endContainer = unwrap();
  16397. } else {
  16398. startContainer = endContainer = splitToFormatRoot(startContainer);
  16399. }
  16400. rng.startContainer = startContainer.parentNode ? startContainer.parentNode : startContainer;
  16401. rng.startOffset = dom.nodeIndex(startContainer);
  16402. rng.endContainer = endContainer.parentNode ? endContainer.parentNode : endContainer;
  16403. rng.endOffset = dom.nodeIndex(endContainer) + 1;
  16404. }
  16405. RangeWalk.walk(dom, rng, function (nodes) {
  16406. each$b(nodes, function (node) {
  16407. process(node);
  16408. if (NodeType.isElement(node) && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && FormatUtils.getTextDecoration(dom, node.parentNode) === 'underline') {
  16409. removeFormat(ed, {
  16410. deep: false,
  16411. exact: true,
  16412. inline: 'span',
  16413. styles: { textDecoration: 'underline' }
  16414. }, null, node);
  16415. }
  16416. });
  16417. });
  16418. };
  16419. if (node) {
  16420. if (node.nodeType) {
  16421. rng = dom.createRng();
  16422. rng.setStartBefore(node);
  16423. rng.setEndAfter(node);
  16424. removeRngStyle(rng);
  16425. } else {
  16426. removeRngStyle(node);
  16427. }
  16428. return;
  16429. }
  16430. if (dom.getContentEditable(selection.getNode()) === 'false') {
  16431. node = selection.getNode();
  16432. for (var i = 0, l = formatList.length; i < l; i++) {
  16433. if (formatList[i].ceFalseOverride) {
  16434. if (removeFormat(ed, formatList[i], vars, node, node)) {
  16435. break;
  16436. }
  16437. }
  16438. }
  16439. return;
  16440. }
  16441. if (!selection.isCollapsed() || !format.inline || dom.select('td[data-mce-selected],th[data-mce-selected]').length) {
  16442. bookmark = GetBookmark.getPersistentBookmark(ed.selection, true);
  16443. removeRngStyle(selection.getRng());
  16444. selection.moveToBookmark(bookmark);
  16445. if (format.inline && MatchFormat.match(ed, name, vars, selection.getStart())) {
  16446. FormatUtils.moveStart(dom, selection, selection.getRng());
  16447. }
  16448. ed.nodeChanged();
  16449. } else {
  16450. removeCaretFormat(ed, name, vars, similar);
  16451. }
  16452. };
  16453. var RemoveFormat = {
  16454. removeFormat: removeFormat,
  16455. remove: remove$7
  16456. };
  16457. var each$c = Tools.each;
  16458. var isElementNode = function (node) {
  16459. return node && node.nodeType === 1 && !Bookmarks.isBookmarkNode(node) && !isCaretNode(node) && !NodeType.isBogus(node);
  16460. };
  16461. var findElementSibling = function (node, siblingName) {
  16462. var sibling;
  16463. for (sibling = node; sibling; sibling = sibling[siblingName]) {
  16464. if (sibling.nodeType === 3 && sibling.nodeValue.length !== 0) {
  16465. return node;
  16466. }
  16467. if (sibling.nodeType === 1 && !Bookmarks.isBookmarkNode(sibling)) {
  16468. return sibling;
  16469. }
  16470. }
  16471. return node;
  16472. };
  16473. var mergeSiblingsNodes = function (dom, prev, next) {
  16474. var sibling, tmpSibling;
  16475. var elementUtils = new ElementUtils(dom);
  16476. if (prev && next) {
  16477. prev = findElementSibling(prev, 'previousSibling');
  16478. next = findElementSibling(next, 'nextSibling');
  16479. if (elementUtils.compare(prev, next)) {
  16480. for (sibling = prev.nextSibling; sibling && sibling !== next;) {
  16481. tmpSibling = sibling;
  16482. sibling = sibling.nextSibling;
  16483. prev.appendChild(tmpSibling);
  16484. }
  16485. dom.remove(next);
  16486. Tools.each(Tools.grep(next.childNodes), function (node) {
  16487. prev.appendChild(node);
  16488. });
  16489. return prev;
  16490. }
  16491. }
  16492. return next;
  16493. };
  16494. var processChildElements = function (node, filter, process) {
  16495. each$c(node.childNodes, function (node) {
  16496. if (isElementNode(node)) {
  16497. if (filter(node)) {
  16498. process(node);
  16499. }
  16500. if (node.hasChildNodes()) {
  16501. processChildElements(node, filter, process);
  16502. }
  16503. }
  16504. });
  16505. };
  16506. var hasStyle = function (dom, name) {
  16507. return curry(function (name, node) {
  16508. return !!(node && FormatUtils.getStyle(dom, node, name));
  16509. }, name);
  16510. };
  16511. var applyStyle = function (dom, name, value) {
  16512. return curry(function (name, value, node) {
  16513. dom.setStyle(node, name, value);
  16514. if (node.getAttribute('style') === '') {
  16515. node.removeAttribute('style');
  16516. }
  16517. unwrapEmptySpan(dom, node);
  16518. }, name, value);
  16519. };
  16520. var unwrapEmptySpan = function (dom, node) {
  16521. if (node.nodeName === 'SPAN' && dom.getAttribs(node).length === 0) {
  16522. dom.remove(node, true);
  16523. }
  16524. };
  16525. var processUnderlineAndColor = function (dom, node) {
  16526. var textDecoration;
  16527. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  16528. textDecoration = FormatUtils.getTextDecoration(dom, node.parentNode);
  16529. if (dom.getStyle(node, 'color') && textDecoration) {
  16530. dom.setStyle(node, 'text-decoration', textDecoration);
  16531. } else if (dom.getStyle(node, 'text-decoration') === textDecoration) {
  16532. dom.setStyle(node, 'text-decoration', null);
  16533. }
  16534. }
  16535. };
  16536. var mergeUnderlineAndColor = function (dom, format, vars, node) {
  16537. if (format.styles.color || format.styles.textDecoration) {
  16538. Tools.walk(node, curry(processUnderlineAndColor, dom), 'childNodes');
  16539. processUnderlineAndColor(dom, node);
  16540. }
  16541. };
  16542. var mergeBackgroundColorAndFontSize = function (dom, format, vars, node) {
  16543. if (format.styles && format.styles.backgroundColor) {
  16544. processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'backgroundColor', FormatUtils.replaceVars(format.styles.backgroundColor, vars)));
  16545. }
  16546. };
  16547. var mergeSubSup = function (dom, format, vars, node) {
  16548. if (format.inline === 'sub' || format.inline === 'sup') {
  16549. processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'fontSize', ''));
  16550. dom.remove(dom.select(format.inline === 'sup' ? 'sub' : 'sup', node), true);
  16551. }
  16552. };
  16553. var mergeSiblings = function (dom, format, vars, node) {
  16554. if (node && format.merge_siblings !== false) {
  16555. node = mergeSiblingsNodes(dom, FormatUtils.getNonWhiteSpaceSibling(node), node);
  16556. node = mergeSiblingsNodes(dom, node, FormatUtils.getNonWhiteSpaceSibling(node, true));
  16557. }
  16558. };
  16559. var clearChildStyles = function (dom, format, node) {
  16560. if (format.clear_child_styles) {
  16561. var selector = format.links ? '*:not(a)' : '*';
  16562. each$c(dom.select(selector, node), function (node) {
  16563. if (isElementNode(node)) {
  16564. each$c(format.styles, function (value, name) {
  16565. dom.setStyle(node, name, '');
  16566. });
  16567. }
  16568. });
  16569. }
  16570. };
  16571. var mergeWithChildren = function (editor, formatList, vars, node) {
  16572. each$c(formatList, function (format) {
  16573. each$c(editor.dom.select(format.inline, node), function (child) {
  16574. if (!isElementNode(child)) {
  16575. return;
  16576. }
  16577. RemoveFormat.removeFormat(editor, format, vars, child, format.exact ? child : null);
  16578. });
  16579. clearChildStyles(editor.dom, format, node);
  16580. });
  16581. };
  16582. var mergeWithParents = function (editor, format, name, vars, node) {
  16583. if (MatchFormat.matchNode(editor, node.parentNode, name, vars)) {
  16584. if (RemoveFormat.removeFormat(editor, format, vars, node)) {
  16585. return;
  16586. }
  16587. }
  16588. if (format.merge_with_parents) {
  16589. editor.dom.getParent(node.parentNode, function (parent) {
  16590. if (MatchFormat.matchNode(editor, parent, name, vars)) {
  16591. RemoveFormat.removeFormat(editor, format, vars, node);
  16592. return true;
  16593. }
  16594. });
  16595. }
  16596. };
  16597. var MergeFormats = {
  16598. mergeWithChildren: mergeWithChildren,
  16599. mergeUnderlineAndColor: mergeUnderlineAndColor,
  16600. mergeBackgroundColorAndFontSize: mergeBackgroundColorAndFontSize,
  16601. mergeSubSup: mergeSubSup,
  16602. mergeSiblings: mergeSiblings,
  16603. mergeWithParents: mergeWithParents
  16604. };
  16605. var createRange$1 = function (sc, so, ec, eo) {
  16606. var rng = domGlobals.document.createRange();
  16607. rng.setStart(sc, so);
  16608. rng.setEnd(ec, eo);
  16609. return rng;
  16610. };
  16611. var normalizeBlockSelectionRange = function (rng) {
  16612. var startPos = CaretPosition$1.fromRangeStart(rng);
  16613. var endPos = CaretPosition$1.fromRangeEnd(rng);
  16614. var rootNode = rng.commonAncestorContainer;
  16615. return CaretFinder.fromPosition(false, rootNode, endPos).map(function (newEndPos) {
  16616. if (!isInSameBlock(startPos, endPos, rootNode) && isInSameBlock(startPos, newEndPos, rootNode)) {
  16617. return createRange$1(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset());
  16618. } else {
  16619. return rng;
  16620. }
  16621. }).getOr(rng);
  16622. };
  16623. var normalize$1 = function (rng) {
  16624. return rng.collapsed ? rng : normalizeBlockSelectionRange(rng);
  16625. };
  16626. var RangeNormalizer = { normalize: normalize$1 };
  16627. var each$d = Tools.each;
  16628. var isElementNode$1 = function (node) {
  16629. return node && node.nodeType === 1 && !Bookmarks.isBookmarkNode(node) && !isCaretNode(node) && !NodeType.isBogus(node);
  16630. };
  16631. var applyFormat = function (ed, name, vars, node) {
  16632. var formatList = ed.formatter.get(name);
  16633. var format = formatList[0];
  16634. var bookmark, rng;
  16635. var isCollapsed = !node && ed.selection.isCollapsed();
  16636. var dom = ed.dom, selection = ed.selection;
  16637. var setElementFormat = function (elm, fmt) {
  16638. fmt = fmt || format;
  16639. if (elm) {
  16640. if (fmt.onformat) {
  16641. fmt.onformat(elm, fmt, vars, node);
  16642. }
  16643. each$d(fmt.styles, function (value, name) {
  16644. dom.setStyle(elm, name, FormatUtils.replaceVars(value, vars));
  16645. });
  16646. if (fmt.styles) {
  16647. var styleVal = dom.getAttrib(elm, 'style');
  16648. if (styleVal) {
  16649. elm.setAttribute('data-mce-style', styleVal);
  16650. }
  16651. }
  16652. each$d(fmt.attributes, function (value, name) {
  16653. dom.setAttrib(elm, name, FormatUtils.replaceVars(value, vars));
  16654. });
  16655. each$d(fmt.classes, function (value) {
  16656. value = FormatUtils.replaceVars(value, vars);
  16657. if (!dom.hasClass(elm, value)) {
  16658. dom.addClass(elm, value);
  16659. }
  16660. });
  16661. }
  16662. };
  16663. var applyNodeStyle = function (formatList, node) {
  16664. var found = false;
  16665. if (!format.selector) {
  16666. return false;
  16667. }
  16668. each$d(formatList, function (format) {
  16669. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  16670. return;
  16671. }
  16672. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  16673. setElementFormat(node, format);
  16674. found = true;
  16675. return false;
  16676. }
  16677. });
  16678. return found;
  16679. };
  16680. var applyRngStyle = function (dom, rng, bookmark, nodeSpecific) {
  16681. var newWrappers = [];
  16682. var wrapName, wrapElm, contentEditable = true;
  16683. wrapName = format.inline || format.block;
  16684. wrapElm = dom.create(wrapName);
  16685. setElementFormat(wrapElm);
  16686. RangeWalk.walk(dom, rng, function (nodes) {
  16687. var currentWrapElm;
  16688. var process = function (node) {
  16689. var nodeName, parentName, hasContentEditableState, lastContentEditable;
  16690. lastContentEditable = contentEditable;
  16691. nodeName = node.nodeName.toLowerCase();
  16692. parentName = node.parentNode.nodeName.toLowerCase();
  16693. if (node.nodeType === 1 && dom.getContentEditable(node)) {
  16694. lastContentEditable = contentEditable;
  16695. contentEditable = dom.getContentEditable(node) === 'true';
  16696. hasContentEditableState = true;
  16697. }
  16698. if (FormatUtils.isEq(nodeName, 'br')) {
  16699. currentWrapElm = 0;
  16700. if (format.block) {
  16701. dom.remove(node);
  16702. }
  16703. return;
  16704. }
  16705. if (format.wrapper && MatchFormat.matchNode(ed, node, name, vars)) {
  16706. currentWrapElm = 0;
  16707. return;
  16708. }
  16709. if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && FormatUtils.isTextBlock(ed, nodeName) && FormatUtils.isValid(ed, parentName, wrapName)) {
  16710. node = dom.rename(node, wrapName);
  16711. setElementFormat(node);
  16712. newWrappers.push(node);
  16713. currentWrapElm = 0;
  16714. return;
  16715. }
  16716. if (format.selector) {
  16717. var found = applyNodeStyle(formatList, node);
  16718. if (!format.inline || found) {
  16719. currentWrapElm = 0;
  16720. return;
  16721. }
  16722. }
  16723. if (contentEditable && !hasContentEditableState && FormatUtils.isValid(ed, wrapName, nodeName) && FormatUtils.isValid(ed, parentName, wrapName) && !(!nodeSpecific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node) && (!format.inline || !dom.isBlock(node))) {
  16724. if (!currentWrapElm) {
  16725. currentWrapElm = dom.clone(wrapElm, false);
  16726. node.parentNode.insertBefore(currentWrapElm, node);
  16727. newWrappers.push(currentWrapElm);
  16728. }
  16729. currentWrapElm.appendChild(node);
  16730. } else {
  16731. currentWrapElm = 0;
  16732. each$d(Tools.grep(node.childNodes), process);
  16733. if (hasContentEditableState) {
  16734. contentEditable = lastContentEditable;
  16735. }
  16736. currentWrapElm = 0;
  16737. }
  16738. };
  16739. each$d(nodes, process);
  16740. });
  16741. if (format.links === true) {
  16742. each$d(newWrappers, function (node) {
  16743. var process = function (node) {
  16744. if (node.nodeName === 'A') {
  16745. setElementFormat(node, format);
  16746. }
  16747. each$d(Tools.grep(node.childNodes), process);
  16748. };
  16749. process(node);
  16750. });
  16751. }
  16752. each$d(newWrappers, function (node) {
  16753. var childCount;
  16754. var getChildCount = function (node) {
  16755. var count = 0;
  16756. each$d(node.childNodes, function (node) {
  16757. if (!FormatUtils.isWhiteSpaceNode(node) && !Bookmarks.isBookmarkNode(node)) {
  16758. count++;
  16759. }
  16760. });
  16761. return count;
  16762. };
  16763. var getChildElementNode = function (root) {
  16764. var child = false;
  16765. each$d(root.childNodes, function (node) {
  16766. if (isElementNode$1(node)) {
  16767. child = node;
  16768. return false;
  16769. }
  16770. });
  16771. return child;
  16772. };
  16773. var mergeStyles = function (node) {
  16774. var child, clone;
  16775. child = getChildElementNode(node);
  16776. if (child && !Bookmarks.isBookmarkNode(child) && MatchFormat.matchName(dom, child, format)) {
  16777. clone = dom.clone(child, false);
  16778. setElementFormat(clone);
  16779. dom.replace(clone, node, true);
  16780. dom.remove(child, 1);
  16781. }
  16782. return clone || node;
  16783. };
  16784. childCount = getChildCount(node);
  16785. if ((newWrappers.length > 1 || !dom.isBlock(node)) && childCount === 0) {
  16786. dom.remove(node, 1);
  16787. return;
  16788. }
  16789. if (format.inline || format.wrapper) {
  16790. if (!format.exact && childCount === 1) {
  16791. node = mergeStyles(node);
  16792. }
  16793. MergeFormats.mergeWithChildren(ed, formatList, vars, node);
  16794. MergeFormats.mergeWithParents(ed, format, name, vars, node);
  16795. MergeFormats.mergeBackgroundColorAndFontSize(dom, format, vars, node);
  16796. MergeFormats.mergeSubSup(dom, format, vars, node);
  16797. MergeFormats.mergeSiblings(dom, format, vars, node);
  16798. }
  16799. });
  16800. };
  16801. if (dom.getContentEditable(selection.getNode()) === 'false') {
  16802. node = selection.getNode();
  16803. for (var i = 0, l = formatList.length; i < l; i++) {
  16804. if (formatList[i].ceFalseOverride && dom.is(node, formatList[i].selector)) {
  16805. setElementFormat(node, formatList[i]);
  16806. return;
  16807. }
  16808. }
  16809. return;
  16810. }
  16811. if (format) {
  16812. if (node) {
  16813. if (node.nodeType) {
  16814. if (!applyNodeStyle(formatList, node)) {
  16815. rng = dom.createRng();
  16816. rng.setStartBefore(node);
  16817. rng.setEndAfter(node);
  16818. applyRngStyle(dom, ExpandRange.expandRng(ed, rng, formatList), null, true);
  16819. }
  16820. } else {
  16821. applyRngStyle(dom, node, null, true);
  16822. }
  16823. } else {
  16824. if (!isCollapsed || !format.inline || dom.select('td[data-mce-selected],th[data-mce-selected]').length) {
  16825. var curSelNode = ed.selection.getNode();
  16826. if (!ed.settings.forced_root_block && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
  16827. applyFormat(ed, formatList[0].defaultBlock);
  16828. }
  16829. ed.selection.setRng(RangeNormalizer.normalize(ed.selection.getRng()));
  16830. bookmark = GetBookmark.getPersistentBookmark(ed.selection, true);
  16831. applyRngStyle(dom, ExpandRange.expandRng(ed, selection.getRng(), formatList));
  16832. if (format.styles) {
  16833. MergeFormats.mergeUnderlineAndColor(dom, format, vars, curSelNode);
  16834. }
  16835. selection.moveToBookmark(bookmark);
  16836. FormatUtils.moveStart(dom, selection, selection.getRng());
  16837. ed.nodeChanged();
  16838. } else {
  16839. applyCaretFormat(ed, name, vars);
  16840. }
  16841. }
  16842. Hooks.postProcess(name, ed);
  16843. }
  16844. };
  16845. var ApplyFormat = { applyFormat: applyFormat };
  16846. var setup$6 = function (registeredFormatListeners, editor) {
  16847. var currentFormats = Cell({});
  16848. registeredFormatListeners.set({});
  16849. editor.on('NodeChange', function (e) {
  16850. updateAndFireChangeCallbacks(editor, e.element, currentFormats, registeredFormatListeners.get());
  16851. });
  16852. };
  16853. var updateAndFireChangeCallbacks = function (editor, elm, currentFormats, formatChangeData) {
  16854. var formatsList = keys(currentFormats.get());
  16855. var newFormats = {};
  16856. var matchedFormats = {};
  16857. var parents = filter(FormatUtils.getParents(editor.dom, elm), function (node) {
  16858. return node.nodeType === 1 && !node.getAttribute('data-mce-bogus');
  16859. });
  16860. each$1(formatChangeData, function (data, format) {
  16861. Tools.each(parents, function (node) {
  16862. if (editor.formatter.matchNode(node, format, {}, data.similar)) {
  16863. if (formatsList.indexOf(format) === -1) {
  16864. each(data.callbacks, function (callback) {
  16865. callback(true, {
  16866. node: node,
  16867. format: format,
  16868. parents: parents
  16869. });
  16870. });
  16871. newFormats[format] = data.callbacks;
  16872. }
  16873. matchedFormats[format] = data.callbacks;
  16874. return false;
  16875. }
  16876. if (MatchFormat.matchesUnInheritedFormatSelector(editor, node, format)) {
  16877. return false;
  16878. }
  16879. });
  16880. });
  16881. var remainingFormats = filterRemainingFormats(currentFormats.get(), matchedFormats, elm, parents);
  16882. currentFormats.set(__assign(__assign({}, newFormats), remainingFormats));
  16883. };
  16884. var filterRemainingFormats = function (currentFormats, matchedFormats, elm, parents) {
  16885. return bifilter(currentFormats, function (callbacks, format) {
  16886. if (!has(matchedFormats, format)) {
  16887. each(callbacks, function (callback) {
  16888. callback(false, {
  16889. node: elm,
  16890. format: format,
  16891. parents: parents
  16892. });
  16893. });
  16894. return false;
  16895. } else {
  16896. return true;
  16897. }
  16898. }).t;
  16899. };
  16900. var addListeners = function (registeredFormatListeners, formats, callback, similar) {
  16901. var formatChangeItems = registeredFormatListeners.get();
  16902. each(formats.split(','), function (format) {
  16903. if (!formatChangeItems[format]) {
  16904. formatChangeItems[format] = {
  16905. similar: similar,
  16906. callbacks: []
  16907. };
  16908. }
  16909. formatChangeItems[format].callbacks.push(callback);
  16910. });
  16911. registeredFormatListeners.set(formatChangeItems);
  16912. };
  16913. var removeListeners = function (registeredFormatListeners, formats, callback) {
  16914. var formatChangeItems = registeredFormatListeners.get();
  16915. each(formats.split(','), function (format) {
  16916. formatChangeItems[format].callbacks = filter(formatChangeItems[format].callbacks, function (c) {
  16917. return c !== callback;
  16918. });
  16919. if (formatChangeItems[format].callbacks.length === 0) {
  16920. delete formatChangeItems[format];
  16921. }
  16922. });
  16923. registeredFormatListeners.set(formatChangeItems);
  16924. };
  16925. var formatChanged = function (editor, registeredFormatListeners, formats, callback, similar) {
  16926. if (registeredFormatListeners.get() === null) {
  16927. setup$6(registeredFormatListeners, editor);
  16928. }
  16929. addListeners(registeredFormatListeners, formats, callback, similar);
  16930. return {
  16931. unbind: function () {
  16932. return removeListeners(registeredFormatListeners, formats, callback);
  16933. }
  16934. };
  16935. };
  16936. var get$7 = function (dom) {
  16937. var formats = {
  16938. valigntop: [{
  16939. selector: 'td,th',
  16940. styles: { verticalAlign: 'top' }
  16941. }],
  16942. valignmiddle: [{
  16943. selector: 'td,th',
  16944. styles: { verticalAlign: 'middle' }
  16945. }],
  16946. valignbottom: [{
  16947. selector: 'td,th',
  16948. styles: { verticalAlign: 'bottom' }
  16949. }],
  16950. alignleft: [
  16951. {
  16952. selector: 'figure.image',
  16953. collapsed: false,
  16954. classes: 'align-left',
  16955. ceFalseOverride: true,
  16956. preview: 'font-family font-size'
  16957. },
  16958. {
  16959. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  16960. styles: { textAlign: 'left' },
  16961. inherit: false,
  16962. preview: false,
  16963. defaultBlock: 'div'
  16964. },
  16965. {
  16966. selector: 'img,table',
  16967. collapsed: false,
  16968. styles: { float: 'left' },
  16969. preview: 'font-family font-size'
  16970. }
  16971. ],
  16972. aligncenter: [
  16973. {
  16974. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  16975. styles: { textAlign: 'center' },
  16976. inherit: false,
  16977. preview: 'font-family font-size',
  16978. defaultBlock: 'div'
  16979. },
  16980. {
  16981. selector: 'figure.image',
  16982. collapsed: false,
  16983. classes: 'align-center',
  16984. ceFalseOverride: true,
  16985. preview: 'font-family font-size'
  16986. },
  16987. {
  16988. selector: 'img',
  16989. collapsed: false,
  16990. styles: {
  16991. display: 'block',
  16992. marginLeft: 'auto',
  16993. marginRight: 'auto'
  16994. },
  16995. preview: false
  16996. },
  16997. {
  16998. selector: 'table',
  16999. collapsed: false,
  17000. styles: {
  17001. marginLeft: 'auto',
  17002. marginRight: 'auto'
  17003. },
  17004. preview: 'font-family font-size'
  17005. }
  17006. ],
  17007. alignright: [
  17008. {
  17009. selector: 'figure.image',
  17010. collapsed: false,
  17011. classes: 'align-right',
  17012. ceFalseOverride: true,
  17013. preview: 'font-family font-size'
  17014. },
  17015. {
  17016. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  17017. styles: { textAlign: 'right' },
  17018. inherit: false,
  17019. preview: 'font-family font-size',
  17020. defaultBlock: 'div'
  17021. },
  17022. {
  17023. selector: 'img,table',
  17024. collapsed: false,
  17025. styles: { float: 'right' },
  17026. preview: 'font-family font-size'
  17027. }
  17028. ],
  17029. alignjustify: [{
  17030. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  17031. styles: { textAlign: 'justify' },
  17032. inherit: false,
  17033. defaultBlock: 'div',
  17034. preview: 'font-family font-size'
  17035. }],
  17036. bold: [
  17037. {
  17038. inline: 'strong',
  17039. remove: 'all'
  17040. },
  17041. {
  17042. inline: 'span',
  17043. styles: { fontWeight: 'bold' }
  17044. },
  17045. {
  17046. inline: 'b',
  17047. remove: 'all'
  17048. }
  17049. ],
  17050. italic: [
  17051. {
  17052. inline: 'em',
  17053. remove: 'all'
  17054. },
  17055. {
  17056. inline: 'span',
  17057. styles: { fontStyle: 'italic' }
  17058. },
  17059. {
  17060. inline: 'i',
  17061. remove: 'all'
  17062. }
  17063. ],
  17064. underline: [
  17065. {
  17066. inline: 'span',
  17067. styles: { textDecoration: 'underline' },
  17068. exact: true
  17069. },
  17070. {
  17071. inline: 'u',
  17072. remove: 'all'
  17073. }
  17074. ],
  17075. strikethrough: [
  17076. {
  17077. inline: 'span',
  17078. styles: { textDecoration: 'line-through' },
  17079. exact: true
  17080. },
  17081. {
  17082. inline: 'strike',
  17083. remove: 'all'
  17084. }
  17085. ],
  17086. forecolor: {
  17087. inline: 'span',
  17088. styles: { color: '%value' },
  17089. links: true,
  17090. remove_similar: true,
  17091. clear_child_styles: true
  17092. },
  17093. hilitecolor: {
  17094. inline: 'span',
  17095. styles: { backgroundColor: '%value' },
  17096. links: true,
  17097. remove_similar: true,
  17098. clear_child_styles: true
  17099. },
  17100. fontname: {
  17101. inline: 'span',
  17102. toggle: false,
  17103. styles: { fontFamily: '%value' },
  17104. clear_child_styles: true
  17105. },
  17106. fontsize: {
  17107. inline: 'span',
  17108. toggle: false,
  17109. styles: { fontSize: '%value' },
  17110. clear_child_styles: true
  17111. },
  17112. fontsize_class: {
  17113. inline: 'span',
  17114. attributes: { class: '%value' }
  17115. },
  17116. blockquote: {
  17117. block: 'blockquote',
  17118. wrapper: true,
  17119. remove: 'all'
  17120. },
  17121. subscript: { inline: 'sub' },
  17122. superscript: { inline: 'sup' },
  17123. code: { inline: 'code' },
  17124. link: {
  17125. inline: 'a',
  17126. selector: 'a',
  17127. remove: 'all',
  17128. split: true,
  17129. deep: true,
  17130. onmatch: function () {
  17131. return true;
  17132. },
  17133. onformat: function (elm, fmt, vars) {
  17134. Tools.each(vars, function (value, key) {
  17135. dom.setAttrib(elm, key, value);
  17136. });
  17137. }
  17138. },
  17139. removeformat: [
  17140. {
  17141. selector: 'b,strong,em,i,font,u,strike,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins',
  17142. remove: 'all',
  17143. split: true,
  17144. expand: false,
  17145. block_expand: true,
  17146. deep: true
  17147. },
  17148. {
  17149. selector: 'span',
  17150. attributes: [
  17151. 'style',
  17152. 'class'
  17153. ],
  17154. remove: 'empty',
  17155. split: true,
  17156. expand: false,
  17157. deep: true
  17158. },
  17159. {
  17160. selector: '*',
  17161. attributes: [
  17162. 'style',
  17163. 'class'
  17164. ],
  17165. split: false,
  17166. expand: false,
  17167. deep: true
  17168. }
  17169. ]
  17170. };
  17171. Tools.each('p h1 h2 h3 h4 h5 h6 div address pre div dt dd samp'.split(/\s/), function (name) {
  17172. formats[name] = {
  17173. block: name,
  17174. remove: 'all'
  17175. };
  17176. });
  17177. return formats;
  17178. };
  17179. var DefaultFormats = { get: get$7 };
  17180. function FormatRegistry(editor) {
  17181. var formats = {};
  17182. var get = function (name) {
  17183. return name ? formats[name] : formats;
  17184. };
  17185. var has$1 = function (name) {
  17186. return has(formats, name);
  17187. };
  17188. var register = function (name, format) {
  17189. if (name) {
  17190. if (typeof name !== 'string') {
  17191. Tools.each(name, function (format, name) {
  17192. register(name, format);
  17193. });
  17194. } else {
  17195. if (!isArray(format)) {
  17196. format = [format];
  17197. }
  17198. Tools.each(format, function (format) {
  17199. if (typeof format.deep === 'undefined') {
  17200. format.deep = !format.selector;
  17201. }
  17202. if (typeof format.split === 'undefined') {
  17203. format.split = !format.selector || format.inline;
  17204. }
  17205. if (typeof format.remove === 'undefined' && format.selector && !format.inline) {
  17206. format.remove = 'none';
  17207. }
  17208. if (format.selector && format.inline) {
  17209. format.mixed = true;
  17210. format.block_expand = true;
  17211. }
  17212. if (typeof format.classes === 'string') {
  17213. format.classes = format.classes.split(/\s+/);
  17214. }
  17215. });
  17216. formats[name] = format;
  17217. }
  17218. }
  17219. };
  17220. var unregister = function (name) {
  17221. if (name && formats[name]) {
  17222. delete formats[name];
  17223. }
  17224. return formats;
  17225. };
  17226. register(DefaultFormats.get(editor.dom));
  17227. register(editor.settings.formats);
  17228. return {
  17229. get: get,
  17230. has: has$1,
  17231. register: register,
  17232. unregister: unregister
  17233. };
  17234. }
  17235. var each$e = Tools.each;
  17236. var dom = DOMUtils$1.DOM;
  17237. var parsedSelectorToHtml = function (ancestry, editor) {
  17238. var elm, item, fragment;
  17239. var schema = editor && editor.schema || Schema({});
  17240. var decorate = function (elm, item) {
  17241. if (item.classes.length) {
  17242. dom.addClass(elm, item.classes.join(' '));
  17243. }
  17244. dom.setAttribs(elm, item.attrs);
  17245. };
  17246. var createElement = function (sItem) {
  17247. var elm;
  17248. item = typeof sItem === 'string' ? {
  17249. name: sItem,
  17250. classes: [],
  17251. attrs: {}
  17252. } : sItem;
  17253. elm = dom.create(item.name);
  17254. decorate(elm, item);
  17255. return elm;
  17256. };
  17257. var getRequiredParent = function (elm, candidate) {
  17258. var name = typeof elm !== 'string' ? elm.nodeName.toLowerCase() : elm;
  17259. var elmRule = schema.getElementRule(name);
  17260. var parentsRequired = elmRule && elmRule.parentsRequired;
  17261. if (parentsRequired && parentsRequired.length) {
  17262. return candidate && Tools.inArray(parentsRequired, candidate) !== -1 ? candidate : parentsRequired[0];
  17263. } else {
  17264. return false;
  17265. }
  17266. };
  17267. var wrapInHtml = function (elm, ancestry, siblings) {
  17268. var parent, parentCandidate, parentRequired;
  17269. var ancestor = ancestry.length > 0 && ancestry[0];
  17270. var ancestorName = ancestor && ancestor.name;
  17271. parentRequired = getRequiredParent(elm, ancestorName);
  17272. if (parentRequired) {
  17273. if (ancestorName === parentRequired) {
  17274. parentCandidate = ancestry[0];
  17275. ancestry = ancestry.slice(1);
  17276. } else {
  17277. parentCandidate = parentRequired;
  17278. }
  17279. } else if (ancestor) {
  17280. parentCandidate = ancestry[0];
  17281. ancestry = ancestry.slice(1);
  17282. } else if (!siblings) {
  17283. return elm;
  17284. }
  17285. if (parentCandidate) {
  17286. parent = createElement(parentCandidate);
  17287. parent.appendChild(elm);
  17288. }
  17289. if (siblings) {
  17290. if (!parent) {
  17291. parent = dom.create('div');
  17292. parent.appendChild(elm);
  17293. }
  17294. Tools.each(siblings, function (sibling) {
  17295. var siblingElm = createElement(sibling);
  17296. parent.insertBefore(siblingElm, elm);
  17297. });
  17298. }
  17299. return wrapInHtml(parent, ancestry, parentCandidate && parentCandidate.siblings);
  17300. };
  17301. if (ancestry && ancestry.length) {
  17302. item = ancestry[0];
  17303. elm = createElement(item);
  17304. fragment = dom.create('div');
  17305. fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings));
  17306. return fragment;
  17307. } else {
  17308. return '';
  17309. }
  17310. };
  17311. var selectorToHtml = function (selector, editor) {
  17312. return parsedSelectorToHtml(parseSelector(selector), editor);
  17313. };
  17314. var parseSelectorItem = function (item) {
  17315. var tagName;
  17316. var obj = {
  17317. classes: [],
  17318. attrs: {}
  17319. };
  17320. item = obj.selector = Tools.trim(item);
  17321. if (item !== '*') {
  17322. tagName = item.replace(/(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g, function ($0, $1, $2, $3, $4) {
  17323. switch ($1) {
  17324. case '#':
  17325. obj.attrs.id = $2;
  17326. break;
  17327. case '.':
  17328. obj.classes.push($2);
  17329. break;
  17330. case ':':
  17331. if (Tools.inArray('checked disabled enabled read-only required'.split(' '), $2) !== -1) {
  17332. obj.attrs[$2] = $2;
  17333. }
  17334. break;
  17335. }
  17336. if ($3 === '[') {
  17337. var m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/);
  17338. if (m) {
  17339. obj.attrs[m[1]] = m[2];
  17340. }
  17341. }
  17342. return '';
  17343. });
  17344. }
  17345. obj.name = tagName || 'div';
  17346. return obj;
  17347. };
  17348. var parseSelector = function (selector) {
  17349. if (!selector || typeof selector !== 'string') {
  17350. return [];
  17351. }
  17352. selector = selector.split(/\s*,\s*/)[0];
  17353. selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, '$1');
  17354. return Tools.map(selector.split(/(?:>|\s+(?![^\[\]]+\]))/), function (item) {
  17355. var siblings = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem);
  17356. var obj = siblings.pop();
  17357. if (siblings.length) {
  17358. obj.siblings = siblings;
  17359. }
  17360. return obj;
  17361. }).reverse();
  17362. };
  17363. var getCssText = function (editor, format) {
  17364. var name, previewFrag, previewElm, items;
  17365. var previewCss = '', parentFontSize, previewStyles;
  17366. previewStyles = editor.settings.preview_styles;
  17367. if (previewStyles === false) {
  17368. return '';
  17369. }
  17370. if (typeof previewStyles !== 'string') {
  17371. previewStyles = 'font-family font-size font-weight font-style text-decoration ' + 'text-transform color background-color border border-radius outline text-shadow';
  17372. }
  17373. var removeVars = function (val) {
  17374. return val.replace(/%(\w+)/g, '');
  17375. };
  17376. if (typeof format === 'string') {
  17377. format = editor.formatter.get(format);
  17378. if (!format) {
  17379. return;
  17380. }
  17381. format = format[0];
  17382. }
  17383. if ('preview' in format) {
  17384. previewStyles = format.preview;
  17385. if (previewStyles === false) {
  17386. return '';
  17387. }
  17388. }
  17389. name = format.block || format.inline || 'span';
  17390. items = parseSelector(format.selector);
  17391. if (items.length) {
  17392. if (!items[0].name) {
  17393. items[0].name = name;
  17394. }
  17395. name = format.selector;
  17396. previewFrag = parsedSelectorToHtml(items, editor);
  17397. } else {
  17398. previewFrag = parsedSelectorToHtml([name], editor);
  17399. }
  17400. previewElm = dom.select(name, previewFrag)[0] || previewFrag.firstChild;
  17401. each$e(format.styles, function (value, name) {
  17402. value = removeVars(value);
  17403. if (value) {
  17404. dom.setStyle(previewElm, name, value);
  17405. }
  17406. });
  17407. each$e(format.attributes, function (value, name) {
  17408. value = removeVars(value);
  17409. if (value) {
  17410. dom.setAttrib(previewElm, name, value);
  17411. }
  17412. });
  17413. each$e(format.classes, function (value) {
  17414. value = removeVars(value);
  17415. if (!dom.hasClass(previewElm, value)) {
  17416. dom.addClass(previewElm, value);
  17417. }
  17418. });
  17419. editor.fire('PreviewFormats');
  17420. dom.setStyles(previewFrag, {
  17421. position: 'absolute',
  17422. left: -65535
  17423. });
  17424. editor.getBody().appendChild(previewFrag);
  17425. parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true);
  17426. parentFontSize = /px$/.test(parentFontSize) ? parseInt(parentFontSize, 10) : 0;
  17427. each$e(previewStyles.split(' '), function (name) {
  17428. var value = dom.getStyle(previewElm, name, true);
  17429. if (name === 'background-color' && /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)) {
  17430. value = dom.getStyle(editor.getBody(), name, true);
  17431. if (dom.toHex(value).toLowerCase() === '#ffffff') {
  17432. return;
  17433. }
  17434. }
  17435. if (name === 'color') {
  17436. if (dom.toHex(value).toLowerCase() === '#000000') {
  17437. return;
  17438. }
  17439. }
  17440. if (name === 'font-size') {
  17441. if (/em|%$/.test(value)) {
  17442. if (parentFontSize === 0) {
  17443. return;
  17444. }
  17445. var numValue = parseFloat(value) / (/%$/.test(value) ? 100 : 1);
  17446. value = numValue * parentFontSize + 'px';
  17447. }
  17448. }
  17449. if (name === 'border' && value) {
  17450. previewCss += 'padding:0 2px;';
  17451. }
  17452. previewCss += name + ':' + value + ';';
  17453. });
  17454. editor.fire('AfterPreviewFormats');
  17455. dom.remove(previewFrag);
  17456. return previewCss;
  17457. };
  17458. var Preview = {
  17459. getCssText: getCssText,
  17460. parseSelector: parseSelector,
  17461. selectorToHtml: selectorToHtml
  17462. };
  17463. var toggle = function (editor, formats, name, vars, node) {
  17464. var fmt = formats.get(name);
  17465. if (MatchFormat.match(editor, name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle)) {
  17466. RemoveFormat.remove(editor, name, vars, node);
  17467. } else {
  17468. ApplyFormat.applyFormat(editor, name, vars, node);
  17469. }
  17470. };
  17471. var ToggleFormat = { toggle: toggle };
  17472. var setup$7 = function (editor) {
  17473. editor.addShortcut('meta+b', '', 'Bold');
  17474. editor.addShortcut('meta+i', '', 'Italic');
  17475. editor.addShortcut('meta+u', '', 'Underline');
  17476. for (var i = 1; i <= 6; i++) {
  17477. editor.addShortcut('access+' + i, '', [
  17478. 'FormatBlock',
  17479. false,
  17480. 'h' + i
  17481. ]);
  17482. }
  17483. editor.addShortcut('access+7', '', [
  17484. 'FormatBlock',
  17485. false,
  17486. 'p'
  17487. ]);
  17488. editor.addShortcut('access+8', '', [
  17489. 'FormatBlock',
  17490. false,
  17491. 'div'
  17492. ]);
  17493. editor.addShortcut('access+9', '', [
  17494. 'FormatBlock',
  17495. false,
  17496. 'address'
  17497. ]);
  17498. };
  17499. var FormatShortcuts = { setup: setup$7 };
  17500. var Formatter = function (editor) {
  17501. var formats = FormatRegistry(editor);
  17502. var formatChangeState = Cell(null);
  17503. FormatShortcuts.setup(editor);
  17504. setup$5(editor);
  17505. return {
  17506. get: formats.get,
  17507. has: formats.has,
  17508. register: formats.register,
  17509. unregister: formats.unregister,
  17510. apply: curry(ApplyFormat.applyFormat, editor),
  17511. remove: curry(RemoveFormat.remove, editor),
  17512. toggle: curry(ToggleFormat.toggle, editor, formats),
  17513. match: curry(MatchFormat.match, editor),
  17514. matchAll: curry(MatchFormat.matchAll, editor),
  17515. matchNode: curry(MatchFormat.matchNode, editor),
  17516. canApply: curry(MatchFormat.canApply, editor),
  17517. formatChanged: curry(formatChanged, editor, formatChangeState),
  17518. getCssText: curry(Preview.getCssText, editor)
  17519. };
  17520. };
  17521. var register$1 = function (htmlParser, settings, dom) {
  17522. htmlParser.addAttributeFilter('data-mce-tabindex', function (nodes, name) {
  17523. var i = nodes.length, node;
  17524. while (i--) {
  17525. node = nodes[i];
  17526. node.attr('tabindex', node.attr('data-mce-tabindex'));
  17527. node.attr(name, null);
  17528. }
  17529. });
  17530. htmlParser.addAttributeFilter('src,href,style', function (nodes, name) {
  17531. var i = nodes.length, node, value;
  17532. var internalName = 'data-mce-' + name;
  17533. var urlConverter = settings.url_converter;
  17534. var urlConverterScope = settings.url_converter_scope;
  17535. while (i--) {
  17536. node = nodes[i];
  17537. value = node.attr(internalName);
  17538. if (value !== undefined) {
  17539. node.attr(name, value.length > 0 ? value : null);
  17540. node.attr(internalName, null);
  17541. } else {
  17542. value = node.attr(name);
  17543. if (name === 'style') {
  17544. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  17545. } else if (urlConverter) {
  17546. value = urlConverter.call(urlConverterScope, value, name, node.name);
  17547. }
  17548. node.attr(name, value.length > 0 ? value : null);
  17549. }
  17550. }
  17551. });
  17552. htmlParser.addAttributeFilter('class', function (nodes) {
  17553. var i = nodes.length, node, value;
  17554. while (i--) {
  17555. node = nodes[i];
  17556. value = node.attr('class');
  17557. if (value) {
  17558. value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, '');
  17559. node.attr('class', value.length > 0 ? value : null);
  17560. }
  17561. }
  17562. });
  17563. htmlParser.addAttributeFilter('data-mce-type', function (nodes, name, args) {
  17564. var i = nodes.length, node;
  17565. while (i--) {
  17566. node = nodes[i];
  17567. if (node.attr('data-mce-type') === 'bookmark' && !args.cleanup) {
  17568. var hasChildren = Option.from(node.firstChild).exists(function (firstChild) {
  17569. return !Zwsp.isZwsp(firstChild.value);
  17570. });
  17571. if (hasChildren) {
  17572. node.unwrap();
  17573. } else {
  17574. node.remove();
  17575. }
  17576. }
  17577. }
  17578. });
  17579. htmlParser.addNodeFilter('noscript', function (nodes) {
  17580. var i = nodes.length, node;
  17581. while (i--) {
  17582. node = nodes[i].firstChild;
  17583. if (node) {
  17584. node.value = Entities.decode(node.value);
  17585. }
  17586. }
  17587. });
  17588. htmlParser.addNodeFilter('script,style', function (nodes, name) {
  17589. var i = nodes.length, node, value, type;
  17590. var trim = function (value) {
  17591. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n').replace(/^[\r\n]*|[\r\n]*$/g, '').replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '').replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  17592. };
  17593. while (i--) {
  17594. node = nodes[i];
  17595. value = node.firstChild ? node.firstChild.value : '';
  17596. if (name === 'script') {
  17597. type = node.attr('type');
  17598. if (type) {
  17599. node.attr('type', type === 'mce-no/type' ? null : type.replace(/^mce\-/, ''));
  17600. }
  17601. if (settings.element_format === 'xhtml' && value.length > 0) {
  17602. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  17603. }
  17604. } else {
  17605. if (settings.element_format === 'xhtml' && value.length > 0) {
  17606. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  17607. }
  17608. }
  17609. }
  17610. });
  17611. htmlParser.addNodeFilter('#comment', function (nodes) {
  17612. var i = nodes.length, node;
  17613. while (i--) {
  17614. node = nodes[i];
  17615. if (node.value.indexOf('[CDATA[') === 0) {
  17616. node.name = '#cdata';
  17617. node.type = 4;
  17618. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  17619. } else if (node.value.indexOf('mce:protected ') === 0) {
  17620. node.name = '#text';
  17621. node.type = 3;
  17622. node.raw = true;
  17623. node.value = unescape(node.value).substr(14);
  17624. }
  17625. }
  17626. });
  17627. htmlParser.addNodeFilter('xml:namespace,input', function (nodes, name) {
  17628. var i = nodes.length, node;
  17629. while (i--) {
  17630. node = nodes[i];
  17631. if (node.type === 7) {
  17632. node.remove();
  17633. } else if (node.type === 1) {
  17634. if (name === 'input' && !node.attr('type')) {
  17635. node.attr('type', 'text');
  17636. }
  17637. }
  17638. }
  17639. });
  17640. htmlParser.addAttributeFilter('data-mce-type', function (nodes) {
  17641. each(nodes, function (node) {
  17642. if (node.attr('data-mce-type') === 'format-caret') {
  17643. if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) {
  17644. node.remove();
  17645. } else {
  17646. node.unwrap();
  17647. }
  17648. }
  17649. });
  17650. });
  17651. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style,' + 'data-mce-selected,data-mce-expando,' + 'data-mce-type,data-mce-resize', function (nodes, name) {
  17652. var i = nodes.length;
  17653. while (i--) {
  17654. nodes[i].attr(name, null);
  17655. }
  17656. });
  17657. };
  17658. var trimTrailingBr = function (rootNode) {
  17659. var brNode1, brNode2;
  17660. var isBr = function (node) {
  17661. return node && node.name === 'br';
  17662. };
  17663. brNode1 = rootNode.lastChild;
  17664. if (isBr(brNode1)) {
  17665. brNode2 = brNode1.prev;
  17666. if (isBr(brNode2)) {
  17667. brNode1.remove();
  17668. brNode2.remove();
  17669. }
  17670. }
  17671. };
  17672. var DomSerializerFilters = {
  17673. register: register$1,
  17674. trimTrailingBr: trimTrailingBr
  17675. };
  17676. var preProcess = function (editor, node, args) {
  17677. var impl, doc, oldDoc;
  17678. var dom = editor.dom;
  17679. node = node.cloneNode(true);
  17680. impl = domGlobals.document.implementation;
  17681. if (impl.createHTMLDocument) {
  17682. doc = impl.createHTMLDocument('');
  17683. Tools.each(node.nodeName === 'BODY' ? node.childNodes : [node], function (node) {
  17684. doc.body.appendChild(doc.importNode(node, true));
  17685. });
  17686. if (node.nodeName !== 'BODY') {
  17687. node = doc.body.firstChild;
  17688. } else {
  17689. node = doc.body;
  17690. }
  17691. oldDoc = dom.doc;
  17692. dom.doc = doc;
  17693. }
  17694. Events.firePreProcess(editor, merge(args, { node: node }));
  17695. if (oldDoc) {
  17696. dom.doc = oldDoc;
  17697. }
  17698. return node;
  17699. };
  17700. var shouldFireEvent = function (editor, args) {
  17701. return editor && editor.hasEventListeners('PreProcess') && !args.no_events;
  17702. };
  17703. var process = function (editor, node, args) {
  17704. return shouldFireEvent(editor, args) ? preProcess(editor, node, args) : node;
  17705. };
  17706. var DomSerializerPreProcess = { process: process };
  17707. var removeAttrs = function (node, names) {
  17708. each(names, function (name) {
  17709. node.attr(name, null);
  17710. });
  17711. };
  17712. var addFontToSpansFilter = function (domParser, styles, fontSizes) {
  17713. domParser.addNodeFilter('font', function (nodes) {
  17714. each(nodes, function (node) {
  17715. var props = styles.parse(node.attr('style'));
  17716. var color = node.attr('color');
  17717. var face = node.attr('face');
  17718. var size = node.attr('size');
  17719. if (color) {
  17720. props.color = color;
  17721. }
  17722. if (face) {
  17723. props['font-family'] = face;
  17724. }
  17725. if (size) {
  17726. props['font-size'] = fontSizes[parseInt(node.attr('size'), 10) - 1];
  17727. }
  17728. node.name = 'span';
  17729. node.attr('style', styles.serialize(props));
  17730. removeAttrs(node, [
  17731. 'color',
  17732. 'face',
  17733. 'size'
  17734. ]);
  17735. });
  17736. });
  17737. };
  17738. var addStrikeToSpanFilter = function (domParser, styles) {
  17739. domParser.addNodeFilter('strike', function (nodes) {
  17740. each(nodes, function (node) {
  17741. var props = styles.parse(node.attr('style'));
  17742. props['text-decoration'] = 'line-through';
  17743. node.name = 'span';
  17744. node.attr('style', styles.serialize(props));
  17745. });
  17746. });
  17747. };
  17748. var addFilters = function (domParser, settings) {
  17749. var styles = Styles();
  17750. if (settings.convert_fonts_to_spans) {
  17751. addFontToSpansFilter(domParser, styles, Tools.explode(settings.font_size_legacy_values));
  17752. }
  17753. addStrikeToSpanFilter(domParser, styles);
  17754. };
  17755. var register$2 = function (domParser, settings) {
  17756. if (settings.inline_styles) {
  17757. addFilters(domParser, settings);
  17758. }
  17759. };
  17760. var LegacyFilter = { register: register$2 };
  17761. var paddEmptyNode = function (settings, args, blockElements, node) {
  17762. var brPreferred = settings.padd_empty_with_br || args.insert;
  17763. if (brPreferred && blockElements[node.name]) {
  17764. node.empty().append(new Node$1('br', 1)).shortEnded = true;
  17765. } else {
  17766. node.empty().append(new Node$1('#text', 3)).value = '\xA0';
  17767. }
  17768. };
  17769. var isPaddedWithNbsp = function (node) {
  17770. return hasOnlyChild(node, '#text') && node.firstChild.value === '\xA0';
  17771. };
  17772. var hasOnlyChild = function (node, name) {
  17773. return node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name;
  17774. };
  17775. var isPadded = function (schema, node) {
  17776. var rule = schema.getElementRule(node.name);
  17777. return rule && rule.paddEmpty;
  17778. };
  17779. var isEmpty$2 = function (schema, nonEmptyElements, whitespaceElements, node) {
  17780. return node.isEmpty(nonEmptyElements, whitespaceElements, function (node) {
  17781. return isPadded(schema, node);
  17782. });
  17783. };
  17784. var isLineBreakNode = function (node, blockElements) {
  17785. return node && (blockElements[node.name] || node.name === 'br');
  17786. };
  17787. var register$3 = function (parser, settings) {
  17788. var schema = parser.schema;
  17789. if (settings.remove_trailing_brs) {
  17790. parser.addNodeFilter('br', function (nodes, _, args) {
  17791. var i;
  17792. var l = nodes.length;
  17793. var node;
  17794. var blockElements = Tools.extend({}, schema.getBlockElements());
  17795. var nonEmptyElements = schema.getNonEmptyElements();
  17796. var parent, lastParent, prev, prevName;
  17797. var whiteSpaceElements = schema.getNonEmptyElements();
  17798. var elementRule, textNode;
  17799. blockElements.body = 1;
  17800. for (i = 0; i < l; i++) {
  17801. node = nodes[i];
  17802. parent = node.parent;
  17803. if (blockElements[node.parent.name] && node === parent.lastChild) {
  17804. prev = node.prev;
  17805. while (prev) {
  17806. prevName = prev.name;
  17807. if (prevName !== 'span' || prev.attr('data-mce-type') !== 'bookmark') {
  17808. if (prevName !== 'br') {
  17809. break;
  17810. }
  17811. if (prevName === 'br') {
  17812. node = null;
  17813. break;
  17814. }
  17815. }
  17816. prev = prev.prev;
  17817. }
  17818. if (node) {
  17819. node.remove();
  17820. if (isEmpty$2(schema, nonEmptyElements, whiteSpaceElements, parent)) {
  17821. elementRule = schema.getElementRule(parent.name);
  17822. if (elementRule) {
  17823. if (elementRule.removeEmpty) {
  17824. parent.remove();
  17825. } else if (elementRule.paddEmpty) {
  17826. paddEmptyNode(settings, args, blockElements, parent);
  17827. }
  17828. }
  17829. }
  17830. }
  17831. } else {
  17832. lastParent = node;
  17833. while (parent && parent.firstChild === lastParent && parent.lastChild === lastParent) {
  17834. lastParent = parent;
  17835. if (blockElements[parent.name]) {
  17836. break;
  17837. }
  17838. parent = parent.parent;
  17839. }
  17840. if (lastParent === parent && settings.padd_empty_with_br !== true) {
  17841. textNode = new Node$1('#text', 3);
  17842. textNode.value = '\xA0';
  17843. node.replace(textNode);
  17844. }
  17845. }
  17846. }
  17847. });
  17848. }
  17849. parser.addAttributeFilter('href', function (nodes) {
  17850. var i = nodes.length, node;
  17851. var appendRel = function (rel) {
  17852. var parts = rel.split(' ').filter(function (p) {
  17853. return p.length > 0;
  17854. });
  17855. return parts.concat(['noopener']).sort().join(' ');
  17856. };
  17857. var addNoOpener = function (rel) {
  17858. var newRel = rel ? Tools.trim(rel) : '';
  17859. if (!/\b(noopener)\b/g.test(newRel)) {
  17860. return appendRel(newRel);
  17861. } else {
  17862. return newRel;
  17863. }
  17864. };
  17865. if (!settings.allow_unsafe_link_target) {
  17866. while (i--) {
  17867. node = nodes[i];
  17868. if (node.name === 'a' && node.attr('target') === '_blank') {
  17869. node.attr('rel', addNoOpener(node.attr('rel')));
  17870. }
  17871. }
  17872. }
  17873. });
  17874. if (!settings.allow_html_in_named_anchor) {
  17875. parser.addAttributeFilter('id,name', function (nodes) {
  17876. var i = nodes.length, sibling, prevSibling, parent, node;
  17877. while (i--) {
  17878. node = nodes[i];
  17879. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  17880. parent = node.parent;
  17881. sibling = node.lastChild;
  17882. do {
  17883. prevSibling = sibling.prev;
  17884. parent.insert(sibling, node);
  17885. sibling = prevSibling;
  17886. } while (sibling);
  17887. }
  17888. }
  17889. });
  17890. }
  17891. if (settings.fix_list_elements) {
  17892. parser.addNodeFilter('ul,ol', function (nodes) {
  17893. var i = nodes.length, node, parentNode;
  17894. while (i--) {
  17895. node = nodes[i];
  17896. parentNode = node.parent;
  17897. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  17898. if (node.prev && node.prev.name === 'li') {
  17899. node.prev.append(node);
  17900. } else {
  17901. var li = new Node$1('li', 1);
  17902. li.attr('style', 'list-style-type: none');
  17903. node.wrap(li);
  17904. }
  17905. }
  17906. }
  17907. });
  17908. }
  17909. if (settings.validate && schema.getValidClasses()) {
  17910. parser.addAttributeFilter('class', function (nodes) {
  17911. var i = nodes.length, node, classList, ci, className, classValue;
  17912. var validClasses = schema.getValidClasses();
  17913. var validClassesMap, valid;
  17914. while (i--) {
  17915. node = nodes[i];
  17916. classList = node.attr('class').split(' ');
  17917. classValue = '';
  17918. for (ci = 0; ci < classList.length; ci++) {
  17919. className = classList[ci];
  17920. valid = false;
  17921. validClassesMap = validClasses['*'];
  17922. if (validClassesMap && validClassesMap[className]) {
  17923. valid = true;
  17924. }
  17925. validClassesMap = validClasses[node.name];
  17926. if (!valid && validClassesMap && validClassesMap[className]) {
  17927. valid = true;
  17928. }
  17929. if (valid) {
  17930. if (classValue) {
  17931. classValue += ' ';
  17932. }
  17933. classValue += className;
  17934. }
  17935. }
  17936. if (!classValue.length) {
  17937. classValue = null;
  17938. }
  17939. node.attr('class', classValue);
  17940. }
  17941. });
  17942. }
  17943. };
  17944. var makeMap$4 = Tools.makeMap, each$f = Tools.each, explode$2 = Tools.explode, extend$2 = Tools.extend;
  17945. var DomParser = function (settings, schema) {
  17946. if (schema === void 0) {
  17947. schema = Schema();
  17948. }
  17949. var nodeFilters = {};
  17950. var attributeFilters = [];
  17951. var matchedNodes = {};
  17952. var matchedAttributes = {};
  17953. settings = settings || {};
  17954. settings.validate = 'validate' in settings ? settings.validate : true;
  17955. settings.root_name = settings.root_name || 'body';
  17956. var fixInvalidChildren = function (nodes) {
  17957. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i;
  17958. var nonEmptyElements, whitespaceElements, nonSplitableElements, textBlockElements, specialElements, sibling, nextNode;
  17959. nonSplitableElements = makeMap$4('tr,td,th,tbody,thead,tfoot,table');
  17960. nonEmptyElements = schema.getNonEmptyElements();
  17961. whitespaceElements = schema.getWhiteSpaceElements();
  17962. textBlockElements = schema.getTextBlockElements();
  17963. specialElements = schema.getSpecialElements();
  17964. for (ni = 0; ni < nodes.length; ni++) {
  17965. node = nodes[ni];
  17966. if (!node.parent || node.fixed) {
  17967. continue;
  17968. }
  17969. if (textBlockElements[node.name] && node.parent.name === 'li') {
  17970. sibling = node.next;
  17971. while (sibling) {
  17972. if (textBlockElements[sibling.name]) {
  17973. sibling.name = 'li';
  17974. sibling.fixed = true;
  17975. node.parent.insert(sibling, node.parent);
  17976. } else {
  17977. break;
  17978. }
  17979. sibling = sibling.next;
  17980. }
  17981. node.unwrap(node);
  17982. continue;
  17983. }
  17984. parents = [node];
  17985. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent) {
  17986. parents.push(parent);
  17987. }
  17988. if (parent && parents.length > 1) {
  17989. parents.reverse();
  17990. newParent = currentNode = filterNode(parents[0].clone());
  17991. for (i = 0; i < parents.length - 1; i++) {
  17992. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  17993. tempNode = filterNode(parents[i].clone());
  17994. currentNode.append(tempNode);
  17995. } else {
  17996. tempNode = currentNode;
  17997. }
  17998. for (childNode = parents[i].firstChild; childNode && childNode !== parents[i + 1];) {
  17999. nextNode = childNode.next;
  18000. tempNode.append(childNode);
  18001. childNode = nextNode;
  18002. }
  18003. currentNode = tempNode;
  18004. }
  18005. if (!isEmpty$2(schema, nonEmptyElements, whitespaceElements, newParent)) {
  18006. parent.insert(newParent, parents[0], true);
  18007. parent.insert(node, newParent);
  18008. } else {
  18009. parent.insert(node, parents[0], true);
  18010. }
  18011. parent = parents[0];
  18012. if (isEmpty$2(schema, nonEmptyElements, whitespaceElements, parent) || hasOnlyChild(parent, 'br')) {
  18013. parent.empty().remove();
  18014. }
  18015. } else if (node.parent) {
  18016. if (node.name === 'li') {
  18017. sibling = node.prev;
  18018. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  18019. sibling.append(node);
  18020. continue;
  18021. }
  18022. sibling = node.next;
  18023. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  18024. sibling.insert(node, sibling.firstChild, true);
  18025. continue;
  18026. }
  18027. node.wrap(filterNode(new Node$1('ul', 1)));
  18028. continue;
  18029. }
  18030. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  18031. node.wrap(filterNode(new Node$1('div', 1)));
  18032. } else {
  18033. if (specialElements[node.name]) {
  18034. node.empty().remove();
  18035. } else {
  18036. node.unwrap();
  18037. }
  18038. }
  18039. }
  18040. }
  18041. };
  18042. var filterNode = function (node) {
  18043. var i, name, list;
  18044. name = node.name;
  18045. if (name in nodeFilters) {
  18046. list = matchedNodes[name];
  18047. if (list) {
  18048. list.push(node);
  18049. } else {
  18050. matchedNodes[name] = [node];
  18051. }
  18052. }
  18053. i = attributeFilters.length;
  18054. while (i--) {
  18055. name = attributeFilters[i].name;
  18056. if (name in node.attributes.map) {
  18057. list = matchedAttributes[name];
  18058. if (list) {
  18059. list.push(node);
  18060. } else {
  18061. matchedAttributes[name] = [node];
  18062. }
  18063. }
  18064. }
  18065. return node;
  18066. };
  18067. var addNodeFilter = function (name, callback) {
  18068. each$f(explode$2(name), function (name) {
  18069. var list = nodeFilters[name];
  18070. if (!list) {
  18071. nodeFilters[name] = list = [];
  18072. }
  18073. list.push(callback);
  18074. });
  18075. };
  18076. var getNodeFilters = function () {
  18077. var out = [];
  18078. for (var name in nodeFilters) {
  18079. if (nodeFilters.hasOwnProperty(name)) {
  18080. out.push({
  18081. name: name,
  18082. callbacks: nodeFilters[name]
  18083. });
  18084. }
  18085. }
  18086. return out;
  18087. };
  18088. var addAttributeFilter = function (name, callback) {
  18089. each$f(explode$2(name), function (name) {
  18090. var i;
  18091. for (i = 0; i < attributeFilters.length; i++) {
  18092. if (attributeFilters[i].name === name) {
  18093. attributeFilters[i].callbacks.push(callback);
  18094. return;
  18095. }
  18096. }
  18097. attributeFilters.push({
  18098. name: name,
  18099. callbacks: [callback]
  18100. });
  18101. });
  18102. };
  18103. var getAttributeFilters = function () {
  18104. return [].concat(attributeFilters);
  18105. };
  18106. var parse = function (html, args) {
  18107. var parser, nodes, i, l, fi, fl, list, name;
  18108. var blockElements;
  18109. var invalidChildren = [];
  18110. var isInWhiteSpacePreservedElement;
  18111. var node;
  18112. var getRootBlockName = function (name) {
  18113. if (name === false) {
  18114. return '';
  18115. } else if (name === true) {
  18116. return 'p';
  18117. } else {
  18118. return name;
  18119. }
  18120. };
  18121. args = args || {};
  18122. matchedNodes = {};
  18123. matchedAttributes = {};
  18124. blockElements = extend$2(makeMap$4('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  18125. var nonEmptyElements = schema.getNonEmptyElements();
  18126. var children = schema.children;
  18127. var validate = settings.validate;
  18128. var forcedRootBlockName = 'forced_root_block' in args ? args.forced_root_block : settings.forced_root_block;
  18129. var rootBlockName = getRootBlockName(forcedRootBlockName);
  18130. var whiteSpaceElements = schema.getWhiteSpaceElements();
  18131. var startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  18132. var endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  18133. var allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  18134. var isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  18135. isInWhiteSpacePreservedElement = whiteSpaceElements.hasOwnProperty(args.context) || whiteSpaceElements.hasOwnProperty(settings.root_name);
  18136. var addRootBlocks = function () {
  18137. var node = rootNode.firstChild, next, rootBlockNode;
  18138. var trim = function (rootBlockNode) {
  18139. if (rootBlockNode) {
  18140. node = rootBlockNode.firstChild;
  18141. if (node && node.type === 3) {
  18142. node.value = node.value.replace(startWhiteSpaceRegExp, '');
  18143. }
  18144. node = rootBlockNode.lastChild;
  18145. if (node && node.type === 3) {
  18146. node.value = node.value.replace(endWhiteSpaceRegExp, '');
  18147. }
  18148. }
  18149. };
  18150. if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
  18151. return;
  18152. }
  18153. while (node) {
  18154. next = node.next;
  18155. if (node.type === 3 || node.type === 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type')) {
  18156. if (!rootBlockNode) {
  18157. rootBlockNode = createNode(rootBlockName, 1);
  18158. rootBlockNode.attr(settings.forced_root_block_attrs);
  18159. rootNode.insert(rootBlockNode, node);
  18160. rootBlockNode.append(node);
  18161. } else {
  18162. rootBlockNode.append(node);
  18163. }
  18164. } else {
  18165. trim(rootBlockNode);
  18166. rootBlockNode = null;
  18167. }
  18168. node = next;
  18169. }
  18170. trim(rootBlockNode);
  18171. };
  18172. var createNode = function (name, type) {
  18173. var node = new Node$1(name, type);
  18174. var list;
  18175. if (name in nodeFilters) {
  18176. list = matchedNodes[name];
  18177. if (list) {
  18178. list.push(node);
  18179. } else {
  18180. matchedNodes[name] = [node];
  18181. }
  18182. }
  18183. return node;
  18184. };
  18185. var removeWhitespaceBefore = function (node) {
  18186. var textNode, textNodeNext, textVal, sibling;
  18187. var blockElements = schema.getBlockElements();
  18188. for (textNode = node.prev; textNode && textNode.type === 3;) {
  18189. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  18190. if (textVal.length > 0) {
  18191. textNode.value = textVal;
  18192. return;
  18193. }
  18194. textNodeNext = textNode.next;
  18195. if (textNodeNext) {
  18196. if (textNodeNext.type === 3 && textNodeNext.value.length) {
  18197. textNode = textNode.prev;
  18198. continue;
  18199. }
  18200. if (!blockElements[textNodeNext.name] && textNodeNext.name !== 'script' && textNodeNext.name !== 'style') {
  18201. textNode = textNode.prev;
  18202. continue;
  18203. }
  18204. }
  18205. sibling = textNode.prev;
  18206. textNode.remove();
  18207. textNode = sibling;
  18208. }
  18209. };
  18210. var cloneAndExcludeBlocks = function (input) {
  18211. var name;
  18212. var output = {};
  18213. for (name in input) {
  18214. if (name !== 'li' && name !== 'p') {
  18215. output[name] = input[name];
  18216. }
  18217. }
  18218. return output;
  18219. };
  18220. parser = SaxParser$1({
  18221. validate: validate,
  18222. allow_script_urls: settings.allow_script_urls,
  18223. allow_conditional_comments: settings.allow_conditional_comments,
  18224. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  18225. cdata: function (text) {
  18226. node.append(createNode('#cdata', 4)).value = text;
  18227. },
  18228. text: function (text, raw) {
  18229. var textNode;
  18230. if (!isInWhiteSpacePreservedElement) {
  18231. text = text.replace(allWhiteSpaceRegExp, ' ');
  18232. if (isLineBreakNode(node.lastChild, blockElements)) {
  18233. text = text.replace(startWhiteSpaceRegExp, '');
  18234. }
  18235. }
  18236. if (text.length !== 0) {
  18237. textNode = createNode('#text', 3);
  18238. textNode.raw = !!raw;
  18239. node.append(textNode).value = text;
  18240. }
  18241. },
  18242. comment: function (text) {
  18243. node.append(createNode('#comment', 8)).value = text;
  18244. },
  18245. pi: function (name, text) {
  18246. node.append(createNode(name, 7)).value = text;
  18247. removeWhitespaceBefore(node);
  18248. },
  18249. doctype: function (text) {
  18250. var newNode;
  18251. newNode = node.append(createNode('#doctype', 10));
  18252. newNode.value = text;
  18253. removeWhitespaceBefore(node);
  18254. },
  18255. start: function (name, attrs, empty) {
  18256. var newNode, attrFiltersLen, elementRule, attrName, parent;
  18257. elementRule = validate ? schema.getElementRule(name) : {};
  18258. if (elementRule) {
  18259. newNode = createNode(elementRule.outputName || name, 1);
  18260. newNode.attributes = attrs;
  18261. newNode.shortEnded = empty;
  18262. node.append(newNode);
  18263. parent = children[node.name];
  18264. if (parent && children[newNode.name] && !parent[newNode.name]) {
  18265. invalidChildren.push(newNode);
  18266. }
  18267. attrFiltersLen = attributeFilters.length;
  18268. while (attrFiltersLen--) {
  18269. attrName = attributeFilters[attrFiltersLen].name;
  18270. if (attrName in attrs.map) {
  18271. list = matchedAttributes[attrName];
  18272. if (list) {
  18273. list.push(newNode);
  18274. } else {
  18275. matchedAttributes[attrName] = [newNode];
  18276. }
  18277. }
  18278. }
  18279. if (blockElements[name]) {
  18280. removeWhitespaceBefore(newNode);
  18281. }
  18282. if (!empty) {
  18283. node = newNode;
  18284. }
  18285. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  18286. isInWhiteSpacePreservedElement = true;
  18287. }
  18288. }
  18289. },
  18290. end: function (name) {
  18291. var textNode, elementRule, text, sibling, tempNode;
  18292. elementRule = validate ? schema.getElementRule(name) : {};
  18293. if (elementRule) {
  18294. if (blockElements[name]) {
  18295. if (!isInWhiteSpacePreservedElement) {
  18296. textNode = node.firstChild;
  18297. if (textNode && textNode.type === 3) {
  18298. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  18299. if (text.length > 0) {
  18300. textNode.value = text;
  18301. textNode = textNode.next;
  18302. } else {
  18303. sibling = textNode.next;
  18304. textNode.remove();
  18305. textNode = sibling;
  18306. while (textNode && textNode.type === 3) {
  18307. text = textNode.value;
  18308. sibling = textNode.next;
  18309. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  18310. textNode.remove();
  18311. textNode = sibling;
  18312. }
  18313. textNode = sibling;
  18314. }
  18315. }
  18316. }
  18317. textNode = node.lastChild;
  18318. if (textNode && textNode.type === 3) {
  18319. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  18320. if (text.length > 0) {
  18321. textNode.value = text;
  18322. textNode = textNode.prev;
  18323. } else {
  18324. sibling = textNode.prev;
  18325. textNode.remove();
  18326. textNode = sibling;
  18327. while (textNode && textNode.type === 3) {
  18328. text = textNode.value;
  18329. sibling = textNode.prev;
  18330. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  18331. textNode.remove();
  18332. textNode = sibling;
  18333. }
  18334. textNode = sibling;
  18335. }
  18336. }
  18337. }
  18338. }
  18339. }
  18340. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  18341. isInWhiteSpacePreservedElement = false;
  18342. }
  18343. if (elementRule.removeEmpty && isEmpty$2(schema, nonEmptyElements, whiteSpaceElements, node)) {
  18344. if (!node.attr('name') && !node.attr('id')) {
  18345. tempNode = node.parent;
  18346. if (blockElements[node.name]) {
  18347. node.empty().remove();
  18348. } else {
  18349. node.unwrap();
  18350. }
  18351. node = tempNode;
  18352. return;
  18353. }
  18354. }
  18355. if (elementRule.paddEmpty && (isPaddedWithNbsp(node) || isEmpty$2(schema, nonEmptyElements, whiteSpaceElements, node))) {
  18356. paddEmptyNode(settings, args, blockElements, node);
  18357. }
  18358. node = node.parent;
  18359. }
  18360. }
  18361. }, schema);
  18362. var rootNode = node = new Node$1(args.context || settings.root_name, 11);
  18363. parser.parse(html);
  18364. if (validate && invalidChildren.length) {
  18365. if (!args.context) {
  18366. fixInvalidChildren(invalidChildren);
  18367. } else {
  18368. args.invalid = true;
  18369. }
  18370. }
  18371. if (rootBlockName && (rootNode.name === 'body' || args.isRootContent)) {
  18372. addRootBlocks();
  18373. }
  18374. if (!args.invalid) {
  18375. for (name in matchedNodes) {
  18376. if (!matchedNodes.hasOwnProperty(name)) {
  18377. continue;
  18378. }
  18379. list = nodeFilters[name];
  18380. nodes = matchedNodes[name];
  18381. fi = nodes.length;
  18382. while (fi--) {
  18383. if (!nodes[fi].parent) {
  18384. nodes.splice(fi, 1);
  18385. }
  18386. }
  18387. for (i = 0, l = list.length; i < l; i++) {
  18388. list[i](nodes, name, args);
  18389. }
  18390. }
  18391. for (i = 0, l = attributeFilters.length; i < l; i++) {
  18392. list = attributeFilters[i];
  18393. if (list.name in matchedAttributes) {
  18394. nodes = matchedAttributes[list.name];
  18395. fi = nodes.length;
  18396. while (fi--) {
  18397. if (!nodes[fi].parent) {
  18398. nodes.splice(fi, 1);
  18399. }
  18400. }
  18401. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) {
  18402. list.callbacks[fi](nodes, list.name, args);
  18403. }
  18404. }
  18405. }
  18406. }
  18407. return rootNode;
  18408. };
  18409. var exports = {
  18410. schema: schema,
  18411. addAttributeFilter: addAttributeFilter,
  18412. getAttributeFilters: getAttributeFilters,
  18413. addNodeFilter: addNodeFilter,
  18414. getNodeFilters: getNodeFilters,
  18415. filterNode: filterNode,
  18416. parse: parse
  18417. };
  18418. register$3(exports, settings);
  18419. LegacyFilter.register(exports, settings);
  18420. return exports;
  18421. };
  18422. var addTempAttr = function (htmlParser, tempAttrs, name) {
  18423. if (Tools.inArray(tempAttrs, name) === -1) {
  18424. htmlParser.addAttributeFilter(name, function (nodes, name) {
  18425. var i = nodes.length;
  18426. while (i--) {
  18427. nodes[i].attr(name, null);
  18428. }
  18429. });
  18430. tempAttrs.push(name);
  18431. }
  18432. };
  18433. var postProcess$1 = function (editor, args, content) {
  18434. if (!args.no_events && editor) {
  18435. var outArgs = Events.firePostProcess(editor, merge(args, { content: content }));
  18436. return outArgs.content;
  18437. } else {
  18438. return content;
  18439. }
  18440. };
  18441. var getHtmlFromNode = function (dom, node, args) {
  18442. var html = Zwsp.trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node));
  18443. return args.selection || isWsPreserveElement(Element.fromDom(node)) ? html : Tools.trim(html);
  18444. };
  18445. var parseHtml = function (htmlParser, html, args) {
  18446. var parserArgs = args.selection ? merge({ forced_root_block: false }, args) : args;
  18447. var rootNode = htmlParser.parse(html, parserArgs);
  18448. DomSerializerFilters.trimTrailingBr(rootNode);
  18449. return rootNode;
  18450. };
  18451. var serializeNode = function (settings, schema, node) {
  18452. var htmlSerializer = Serializer(settings, schema);
  18453. return htmlSerializer.serialize(node);
  18454. };
  18455. var toHtml = function (editor, settings, schema, rootNode, args) {
  18456. var content = serializeNode(settings, schema, rootNode);
  18457. return postProcess$1(editor, args, content);
  18458. };
  18459. var DomSerializer = function (settings, editor) {
  18460. var dom, schema, htmlParser;
  18461. var tempAttrs = ['data-mce-selected'];
  18462. dom = editor && editor.dom ? editor.dom : DOMUtils$1.DOM;
  18463. schema = editor && editor.schema ? editor.schema : Schema(settings);
  18464. settings.entity_encoding = settings.entity_encoding || 'named';
  18465. settings.remove_trailing_brs = 'remove_trailing_brs' in settings ? settings.remove_trailing_brs : true;
  18466. htmlParser = DomParser(settings, schema);
  18467. DomSerializerFilters.register(htmlParser, settings, dom);
  18468. var serialize = function (node, parserArgs) {
  18469. var args = merge({ format: 'html' }, parserArgs ? parserArgs : {});
  18470. var targetNode = DomSerializerPreProcess.process(editor, node, args);
  18471. var html = getHtmlFromNode(dom, targetNode, args);
  18472. var rootNode = parseHtml(htmlParser, html, args);
  18473. return args.format === 'tree' ? rootNode : toHtml(editor, settings, schema, rootNode, args);
  18474. };
  18475. return {
  18476. schema: schema,
  18477. addNodeFilter: htmlParser.addNodeFilter,
  18478. addAttributeFilter: htmlParser.addAttributeFilter,
  18479. serialize: serialize,
  18480. addRules: function (rules) {
  18481. schema.addValidElements(rules);
  18482. },
  18483. setRules: function (rules) {
  18484. schema.setValidElements(rules);
  18485. },
  18486. addTempAttr: curry(addTempAttr, htmlParser, tempAttrs),
  18487. getTempAttrs: function () {
  18488. return tempAttrs;
  18489. }
  18490. };
  18491. };
  18492. var Serializer$1 = function (settings, editor) {
  18493. var domSerializer = DomSerializer(settings, editor);
  18494. return {
  18495. schema: domSerializer.schema,
  18496. addNodeFilter: domSerializer.addNodeFilter,
  18497. addAttributeFilter: domSerializer.addAttributeFilter,
  18498. serialize: domSerializer.serialize,
  18499. addRules: domSerializer.addRules,
  18500. setRules: domSerializer.setRules,
  18501. addTempAttr: domSerializer.addTempAttr,
  18502. getTempAttrs: domSerializer.getTempAttrs
  18503. };
  18504. };
  18505. function BookmarkManager(selection) {
  18506. return {
  18507. getBookmark: curry(Bookmarks.getBookmark, selection),
  18508. moveToBookmark: curry(Bookmarks.moveToBookmark, selection)
  18509. };
  18510. }
  18511. (function (BookmarkManager) {
  18512. BookmarkManager.isBookmarkNode = Bookmarks.isBookmarkNode;
  18513. }(BookmarkManager || (BookmarkManager = {})));
  18514. var BookmarkManager$1 = BookmarkManager;
  18515. var isContentEditableFalse$a = NodeType.isContentEditableFalse;
  18516. var isContentEditableTrue$5 = NodeType.isContentEditableTrue;
  18517. var getContentEditableRoot$1 = function (root, node) {
  18518. while (node && node !== root) {
  18519. if (isContentEditableTrue$5(node) || isContentEditableFalse$a(node)) {
  18520. return node;
  18521. }
  18522. node = node.parentNode;
  18523. }
  18524. return null;
  18525. };
  18526. var ControlSelection = function (selection, editor) {
  18527. var dom = editor.dom, each = Tools.each;
  18528. var selectedElm, selectedElmGhost, resizeHelper, resizeHandles, selectedHandle;
  18529. var startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted;
  18530. var width, height;
  18531. var editableDoc = editor.getDoc(), rootDocument = domGlobals.document;
  18532. var abs = Math.abs, round = Math.round, rootElement = editor.getBody();
  18533. var startScrollWidth, startScrollHeight;
  18534. resizeHandles = {
  18535. nw: [
  18536. 0,
  18537. 0,
  18538. -1,
  18539. -1
  18540. ],
  18541. ne: [
  18542. 1,
  18543. 0,
  18544. 1,
  18545. -1
  18546. ],
  18547. se: [
  18548. 1,
  18549. 1,
  18550. 1,
  18551. 1
  18552. ],
  18553. sw: [
  18554. 0,
  18555. 1,
  18556. -1,
  18557. 1
  18558. ]
  18559. };
  18560. var isImage = function (elm) {
  18561. return elm && (elm.nodeName === 'IMG' || editor.dom.is(elm, 'figure.image'));
  18562. };
  18563. var isEventOnImageOutsideRange = function (evt, range) {
  18564. if (evt.type === 'longpress' || evt.type.indexOf('touch') === 0) {
  18565. var touch = evt.touches[0];
  18566. return isImage(evt.target) && !RangePoint.isXYWithinRange(touch.clientX, touch.clientY, range);
  18567. } else {
  18568. return isImage(evt.target) && !RangePoint.isXYWithinRange(evt.clientX, evt.clientY, range);
  18569. }
  18570. };
  18571. var contextMenuSelectImage = function (evt) {
  18572. var target = evt.target;
  18573. if (isEventOnImageOutsideRange(evt, editor.selection.getRng()) && !evt.isDefaultPrevented()) {
  18574. editor.selection.select(target);
  18575. }
  18576. };
  18577. var getResizeTarget = function (elm) {
  18578. return editor.dom.is(elm, 'figure.image') ? elm.querySelector('img') : elm;
  18579. };
  18580. var isResizable = function (elm) {
  18581. var selector = editor.settings.object_resizing;
  18582. if (selector === false || Env.iOS) {
  18583. return false;
  18584. }
  18585. if (typeof selector !== 'string') {
  18586. selector = 'table,img,figure.image,div';
  18587. }
  18588. if (elm.getAttribute('data-mce-resize') === 'false') {
  18589. return false;
  18590. }
  18591. if (elm === editor.getBody()) {
  18592. return false;
  18593. }
  18594. return is(Element.fromDom(elm), selector);
  18595. };
  18596. var resizeGhostElement = function (e) {
  18597. var deltaX, deltaY, proportional;
  18598. var resizeHelperX, resizeHelperY;
  18599. deltaX = e.screenX - startX;
  18600. deltaY = e.screenY - startY;
  18601. width = deltaX * selectedHandle[2] + startW;
  18602. height = deltaY * selectedHandle[3] + startH;
  18603. width = width < 5 ? 5 : width;
  18604. height = height < 5 ? 5 : height;
  18605. if (isImage(selectedElm) && editor.settings.resize_img_proportional !== false) {
  18606. proportional = !VK.modifierPressed(e);
  18607. } else {
  18608. proportional = VK.modifierPressed(e) || isImage(selectedElm) && selectedHandle[2] * selectedHandle[3] !== 0;
  18609. }
  18610. if (proportional) {
  18611. if (abs(deltaX) > abs(deltaY)) {
  18612. height = round(width * ratio);
  18613. width = round(height / ratio);
  18614. } else {
  18615. width = round(height / ratio);
  18616. height = round(width * ratio);
  18617. }
  18618. }
  18619. dom.setStyles(getResizeTarget(selectedElmGhost), {
  18620. width: width,
  18621. height: height
  18622. });
  18623. resizeHelperX = selectedHandle.startPos.x + deltaX;
  18624. resizeHelperY = selectedHandle.startPos.y + deltaY;
  18625. resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0;
  18626. resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0;
  18627. dom.setStyles(resizeHelper, {
  18628. left: resizeHelperX,
  18629. top: resizeHelperY,
  18630. display: 'block'
  18631. });
  18632. resizeHelper.innerHTML = width + ' &times; ' + height;
  18633. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  18634. dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
  18635. }
  18636. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  18637. dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
  18638. }
  18639. deltaX = rootElement.scrollWidth - startScrollWidth;
  18640. deltaY = rootElement.scrollHeight - startScrollHeight;
  18641. if (deltaX + deltaY !== 0) {
  18642. dom.setStyles(resizeHelper, {
  18643. left: resizeHelperX - deltaX,
  18644. top: resizeHelperY - deltaY
  18645. });
  18646. }
  18647. if (!resizeStarted) {
  18648. Events.fireObjectResizeStart(editor, selectedElm, startW, startH);
  18649. resizeStarted = true;
  18650. }
  18651. };
  18652. var endGhostResize = function () {
  18653. resizeStarted = false;
  18654. var setSizeProp = function (name, value) {
  18655. if (value) {
  18656. if (selectedElm.style[name] || !editor.schema.isValid(selectedElm.nodeName.toLowerCase(), name)) {
  18657. dom.setStyle(getResizeTarget(selectedElm), name, value);
  18658. } else {
  18659. dom.setAttrib(getResizeTarget(selectedElm), name, value);
  18660. }
  18661. }
  18662. };
  18663. setSizeProp('width', width);
  18664. setSizeProp('height', height);
  18665. dom.unbind(editableDoc, 'mousemove', resizeGhostElement);
  18666. dom.unbind(editableDoc, 'mouseup', endGhostResize);
  18667. if (rootDocument !== editableDoc) {
  18668. dom.unbind(rootDocument, 'mousemove', resizeGhostElement);
  18669. dom.unbind(rootDocument, 'mouseup', endGhostResize);
  18670. }
  18671. dom.remove(selectedElmGhost);
  18672. dom.remove(resizeHelper);
  18673. showResizeRect(selectedElm);
  18674. Events.fireObjectResized(editor, selectedElm, width, height);
  18675. dom.setAttrib(selectedElm, 'style', dom.getAttrib(selectedElm, 'style'));
  18676. editor.nodeChanged();
  18677. };
  18678. var showResizeRect = function (targetElm) {
  18679. var position, targetWidth, targetHeight, e, rect;
  18680. hideResizeRect();
  18681. unbindResizeHandleEvents();
  18682. position = dom.getPos(targetElm, rootElement);
  18683. selectedElmX = position.x;
  18684. selectedElmY = position.y;
  18685. rect = targetElm.getBoundingClientRect();
  18686. targetWidth = rect.width || rect.right - rect.left;
  18687. targetHeight = rect.height || rect.bottom - rect.top;
  18688. if (selectedElm !== targetElm) {
  18689. selectedElm = targetElm;
  18690. width = height = 0;
  18691. }
  18692. e = editor.fire('ObjectSelected', { target: targetElm });
  18693. if (isResizable(targetElm) && !e.isDefaultPrevented()) {
  18694. each(resizeHandles, function (handle, name) {
  18695. var handleElm;
  18696. var startDrag = function (e) {
  18697. startX = e.screenX;
  18698. startY = e.screenY;
  18699. startW = getResizeTarget(selectedElm).clientWidth;
  18700. startH = getResizeTarget(selectedElm).clientHeight;
  18701. ratio = startH / startW;
  18702. selectedHandle = handle;
  18703. handle.startPos = {
  18704. x: targetWidth * handle[0] + selectedElmX,
  18705. y: targetHeight * handle[1] + selectedElmY
  18706. };
  18707. startScrollWidth = rootElement.scrollWidth;
  18708. startScrollHeight = rootElement.scrollHeight;
  18709. selectedElmGhost = selectedElm.cloneNode(true);
  18710. dom.addClass(selectedElmGhost, 'mce-clonedresizable');
  18711. dom.setAttrib(selectedElmGhost, 'data-mce-bogus', 'all');
  18712. selectedElmGhost.contentEditable = false;
  18713. selectedElmGhost.unSelectabe = true;
  18714. dom.setStyles(selectedElmGhost, {
  18715. left: selectedElmX,
  18716. top: selectedElmY,
  18717. margin: 0
  18718. });
  18719. selectedElmGhost.removeAttribute('data-mce-selected');
  18720. rootElement.appendChild(selectedElmGhost);
  18721. dom.bind(editableDoc, 'mousemove', resizeGhostElement);
  18722. dom.bind(editableDoc, 'mouseup', endGhostResize);
  18723. if (rootDocument !== editableDoc) {
  18724. dom.bind(rootDocument, 'mousemove', resizeGhostElement);
  18725. dom.bind(rootDocument, 'mouseup', endGhostResize);
  18726. }
  18727. resizeHelper = dom.add(rootElement, 'div', {
  18728. 'class': 'mce-resize-helper',
  18729. 'data-mce-bogus': 'all'
  18730. }, startW + ' &times; ' + startH);
  18731. };
  18732. handleElm = dom.get('mceResizeHandle' + name);
  18733. if (handleElm) {
  18734. dom.remove(handleElm);
  18735. }
  18736. handleElm = dom.add(rootElement, 'div', {
  18737. 'id': 'mceResizeHandle' + name,
  18738. 'data-mce-bogus': 'all',
  18739. 'class': 'mce-resizehandle',
  18740. 'unselectable': true,
  18741. 'style': 'cursor:' + name + '-resize; margin:0; padding:0'
  18742. });
  18743. if (Env.ie === 11) {
  18744. handleElm.contentEditable = false;
  18745. }
  18746. dom.bind(handleElm, 'mousedown', function (e) {
  18747. e.stopImmediatePropagation();
  18748. e.preventDefault();
  18749. startDrag(e);
  18750. });
  18751. handle.elm = handleElm;
  18752. dom.setStyles(handleElm, {
  18753. left: targetWidth * handle[0] + selectedElmX - handleElm.offsetWidth / 2,
  18754. top: targetHeight * handle[1] + selectedElmY - handleElm.offsetHeight / 2
  18755. });
  18756. });
  18757. } else {
  18758. hideResizeRect();
  18759. }
  18760. selectedElm.setAttribute('data-mce-selected', '1');
  18761. };
  18762. var hideResizeRect = function () {
  18763. var name, handleElm;
  18764. unbindResizeHandleEvents();
  18765. if (selectedElm) {
  18766. selectedElm.removeAttribute('data-mce-selected');
  18767. }
  18768. for (name in resizeHandles) {
  18769. handleElm = dom.get('mceResizeHandle' + name);
  18770. if (handleElm) {
  18771. dom.unbind(handleElm);
  18772. dom.remove(handleElm);
  18773. }
  18774. }
  18775. };
  18776. var updateResizeRect = function (e) {
  18777. var startElm, controlElm;
  18778. var isChildOrEqual = function (node, parent) {
  18779. if (node) {
  18780. do {
  18781. if (node === parent) {
  18782. return true;
  18783. }
  18784. } while (node = node.parentNode);
  18785. }
  18786. };
  18787. if (resizeStarted || editor.removed) {
  18788. return;
  18789. }
  18790. each(dom.select('img[data-mce-selected],hr[data-mce-selected]'), function (img) {
  18791. img.removeAttribute('data-mce-selected');
  18792. });
  18793. controlElm = e.type === 'mousedown' ? e.target : selection.getNode();
  18794. controlElm = dom.$(controlElm).closest('table,img,figure.image,hr')[0];
  18795. if (isChildOrEqual(controlElm, rootElement)) {
  18796. disableGeckoResize();
  18797. startElm = selection.getStart(true);
  18798. if (isChildOrEqual(startElm, controlElm) && isChildOrEqual(selection.getEnd(true), controlElm)) {
  18799. showResizeRect(controlElm);
  18800. return;
  18801. }
  18802. }
  18803. hideResizeRect();
  18804. };
  18805. var isWithinContentEditableFalse = function (elm) {
  18806. return isContentEditableFalse$a(getContentEditableRoot$1(editor.getBody(), elm));
  18807. };
  18808. var unbindResizeHandleEvents = function () {
  18809. for (var name in resizeHandles) {
  18810. var handle = resizeHandles[name];
  18811. if (handle.elm) {
  18812. dom.unbind(handle.elm);
  18813. delete handle.elm;
  18814. }
  18815. }
  18816. };
  18817. var disableGeckoResize = function () {
  18818. try {
  18819. editor.getDoc().execCommand('enableObjectResizing', false, false);
  18820. } catch (ex) {
  18821. }
  18822. };
  18823. editor.on('init', function () {
  18824. disableGeckoResize();
  18825. if (Env.browser.isIE() || Env.browser.isEdge()) {
  18826. editor.on('mousedown click', function (e) {
  18827. var target = e.target, nodeName = target.nodeName;
  18828. if (!resizeStarted && /^(TABLE|IMG|HR)$/.test(nodeName) && !isWithinContentEditableFalse(target)) {
  18829. if (e.button !== 2) {
  18830. editor.selection.select(target, nodeName === 'TABLE');
  18831. }
  18832. if (e.type === 'mousedown') {
  18833. editor.nodeChanged();
  18834. }
  18835. }
  18836. });
  18837. editor.dom.bind(rootElement, 'mscontrolselect', function (e) {
  18838. var delayedSelect = function (node) {
  18839. Delay.setEditorTimeout(editor, function () {
  18840. editor.selection.select(node);
  18841. });
  18842. };
  18843. if (isWithinContentEditableFalse(e.target)) {
  18844. e.preventDefault();
  18845. delayedSelect(e.target);
  18846. return;
  18847. }
  18848. if (/^(TABLE|IMG|HR)$/.test(e.target.nodeName)) {
  18849. e.preventDefault();
  18850. if (e.target.tagName === 'IMG') {
  18851. delayedSelect(e.target);
  18852. }
  18853. }
  18854. });
  18855. }
  18856. var throttledUpdateResizeRect = Delay.throttle(function (e) {
  18857. if (!editor.composing) {
  18858. updateResizeRect(e);
  18859. }
  18860. });
  18861. editor.on('nodechange ResizeEditor ResizeWindow drop FullscreenStateChanged', throttledUpdateResizeRect);
  18862. editor.on('keyup compositionend', function (e) {
  18863. if (selectedElm && selectedElm.nodeName === 'TABLE') {
  18864. throttledUpdateResizeRect(e);
  18865. }
  18866. });
  18867. editor.on('hide blur', hideResizeRect);
  18868. editor.on('contextmenu longpress', contextMenuSelectImage, true);
  18869. });
  18870. editor.on('remove', unbindResizeHandleEvents);
  18871. var destroy = function () {
  18872. selectedElm = selectedElmGhost = null;
  18873. };
  18874. return {
  18875. isResizable: isResizable,
  18876. showResizeRect: showResizeRect,
  18877. hideResizeRect: hideResizeRect,
  18878. updateResizeRect: updateResizeRect,
  18879. destroy: destroy
  18880. };
  18881. };
  18882. function Dimension (name, getOffset) {
  18883. var set = function (element, h) {
  18884. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  18885. throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
  18886. }
  18887. var dom = element.dom();
  18888. if (isSupported(dom)) {
  18889. dom.style[name] = h + 'px';
  18890. }
  18891. };
  18892. var get = function (element) {
  18893. var r = getOffset(element);
  18894. if (r <= 0 || r === null) {
  18895. var css = get$2(element, name);
  18896. return parseFloat(css) || 0;
  18897. }
  18898. return r;
  18899. };
  18900. var getOuter = get;
  18901. var aggregate = function (element, properties) {
  18902. return foldl(properties, function (acc, property) {
  18903. var val = get$2(element, property);
  18904. var value = val === undefined ? 0 : parseInt(val, 10);
  18905. return isNaN(value) ? acc : acc + value;
  18906. }, 0);
  18907. };
  18908. var max = function (element, value, properties) {
  18909. var cumulativeInclusions = aggregate(element, properties);
  18910. var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
  18911. return absoluteMax;
  18912. };
  18913. return {
  18914. set: set,
  18915. get: get,
  18916. getOuter: getOuter,
  18917. aggregate: aggregate,
  18918. max: max
  18919. };
  18920. }
  18921. var api$1 = Dimension('height', function (element) {
  18922. var dom = element.dom();
  18923. return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
  18924. });
  18925. var get$8 = function (element) {
  18926. return api$1.get(element);
  18927. };
  18928. var walkUp = function (navigation, doc) {
  18929. var frame = navigation.view(doc);
  18930. return frame.fold(constant([]), function (f) {
  18931. var parent = navigation.owner(f);
  18932. var rest = walkUp(navigation, parent);
  18933. return [f].concat(rest);
  18934. });
  18935. };
  18936. var pathTo = function (element, navigation) {
  18937. var d = navigation.owner(element);
  18938. return walkUp(navigation, d);
  18939. };
  18940. var view = function (doc) {
  18941. var element = doc.dom() === domGlobals.document ? Option.none() : Option.from(doc.dom().defaultView.frameElement);
  18942. return element.map(Element.fromDom);
  18943. };
  18944. var owner$1 = function (element) {
  18945. return owner(element);
  18946. };
  18947. var Navigation = /*#__PURE__*/Object.freeze({
  18948. view: view,
  18949. owner: owner$1
  18950. });
  18951. var find$4 = function (element) {
  18952. var doc = Element.fromDom(domGlobals.document);
  18953. var scroll = get$3(doc);
  18954. var frames = pathTo(element, Navigation);
  18955. var offset = viewport(element);
  18956. var r = foldr(frames, function (b, a) {
  18957. var loc = viewport(a);
  18958. return {
  18959. left: b.left + loc.left(),
  18960. top: b.top + loc.top()
  18961. };
  18962. }, {
  18963. left: 0,
  18964. top: 0
  18965. });
  18966. return Position$1(r.left + offset.left() + scroll.left(), r.top + offset.top() + scroll.top());
  18967. };
  18968. var excludeFromDescend = function (element) {
  18969. return name(element) === 'textarea';
  18970. };
  18971. var descend = function (element, offset) {
  18972. var children$1 = children(element);
  18973. if (children$1.length === 0 || excludeFromDescend(element)) {
  18974. return {
  18975. element: element,
  18976. offset: offset
  18977. };
  18978. } else if (offset < children$1.length && !excludeFromDescend(children$1[offset])) {
  18979. return {
  18980. element: children$1[offset],
  18981. offset: 0
  18982. };
  18983. } else {
  18984. var last = children$1[children$1.length - 1];
  18985. if (excludeFromDescend(last)) {
  18986. return {
  18987. element: element,
  18988. offset: offset
  18989. };
  18990. } else {
  18991. if (name(last) === 'img') {
  18992. return {
  18993. element: last,
  18994. offset: 1
  18995. };
  18996. } else if (isText$1(last)) {
  18997. return {
  18998. element: last,
  18999. offset: get$6(last).length
  19000. };
  19001. } else {
  19002. return {
  19003. element: last,
  19004. offset: children(last).length
  19005. };
  19006. }
  19007. }
  19008. }
  19009. };
  19010. var markerInfo = function (element, cleanupFun) {
  19011. var pos = absolute(element);
  19012. var height = get$8(element);
  19013. return {
  19014. element: element,
  19015. bottom: pos.top() + height,
  19016. pos: pos,
  19017. cleanup: cleanupFun
  19018. };
  19019. };
  19020. var createMarker = function (element, offset) {
  19021. var startPoint = descend(element, offset);
  19022. var span = Element.fromHtml('<span data-mce-bogus="all">' + Zwsp.ZWSP + '</span>');
  19023. before(startPoint.element, span);
  19024. return markerInfo(span, function () {
  19025. return remove$1(span);
  19026. });
  19027. };
  19028. var elementMarker = function (element) {
  19029. return markerInfo(Element.fromDom(element), noop);
  19030. };
  19031. var withMarker = function (editor, f, rng, alignToTop) {
  19032. preserveWith(editor, function (_s, _e) {
  19033. return applyWithMarker(editor, f, rng, alignToTop);
  19034. }, rng);
  19035. };
  19036. var applyWithMarker = function (editor, f, rng, alignToTop) {
  19037. var body = Element.fromDom(editor.getBody());
  19038. var doc = Element.fromDom(editor.getDoc());
  19039. reflow(body);
  19040. var scrollTop = get$3(doc).top();
  19041. var marker = createMarker(Element.fromDom(rng.startContainer), rng.startOffset);
  19042. f(doc, scrollTop, marker, alignToTop);
  19043. marker.cleanup();
  19044. };
  19045. var withElement = function (editor, element, f, alignToTop) {
  19046. var doc = Element.fromDom(editor.getDoc());
  19047. var scrollTop = get$3(doc).top();
  19048. f(doc, scrollTop, element, alignToTop);
  19049. };
  19050. var preserveWith = function (editor, f, rng) {
  19051. var startElement = rng.startContainer;
  19052. var startOffset = rng.startOffset;
  19053. var endElement = rng.endContainer;
  19054. var endOffset = rng.endOffset;
  19055. f(Element.fromDom(startElement), Element.fromDom(endElement));
  19056. var newRng = editor.dom.createRng();
  19057. newRng.setStart(startElement, startOffset);
  19058. newRng.setEnd(endElement, endOffset);
  19059. editor.selection.setRng(rng);
  19060. };
  19061. var fireScrollIntoViewEvent = function (editor, elm, alignToTop) {
  19062. var scrollEvent = editor.fire('ScrollIntoView', {
  19063. elm: elm,
  19064. alignToTop: alignToTop
  19065. });
  19066. return scrollEvent.isDefaultPrevented();
  19067. };
  19068. var scrollTo = function (marker, viewHeight, alignToTop, doc) {
  19069. var pos = marker.pos;
  19070. if (alignToTop) {
  19071. to(pos.left(), pos.top(), doc);
  19072. } else {
  19073. var y = pos.top() - viewHeight + (marker.bottom - pos.top());
  19074. to(pos.left(), y, doc);
  19075. }
  19076. };
  19077. var intoWindowIfNeeded = function (doc, scrollTop, viewHeight, marker, alignToTop) {
  19078. if (marker.pos.top() < scrollTop) {
  19079. scrollTo(marker, viewHeight, alignToTop !== false, doc);
  19080. } else if (marker.bottom > viewHeight + scrollTop) {
  19081. scrollTo(marker, viewHeight, alignToTop === true, doc);
  19082. }
  19083. };
  19084. var intoWindow = function (doc, scrollTop, marker, alignToTop) {
  19085. var viewHeight = doc.dom().defaultView.innerHeight;
  19086. intoWindowIfNeeded(doc, scrollTop, viewHeight, marker, alignToTop);
  19087. };
  19088. var intoFrame = function (editor, doc, scrollTop, marker, alignToTop) {
  19089. var frameViewHeight = doc.dom().defaultView.innerHeight;
  19090. intoWindowIfNeeded(doc, scrollTop, frameViewHeight, marker, alignToTop);
  19091. var op = find$4(marker.element);
  19092. var viewportBounds = getBounds(domGlobals.window);
  19093. if (op.top() < viewportBounds.y()) {
  19094. intoView(marker.element, alignToTop !== false);
  19095. } else if (op.top() > viewportBounds.bottom()) {
  19096. intoView(marker.element, alignToTop === true);
  19097. }
  19098. };
  19099. var rangeIntoWindow = function (editor, rng, alignToTop) {
  19100. return withMarker(editor, curry(intoWindow), rng, alignToTop);
  19101. };
  19102. var elementIntoWindow = function (editor, element, alignToTop) {
  19103. return withElement(editor, elementMarker(element), curry(intoWindow), alignToTop);
  19104. };
  19105. var rangeIntoFrame = function (editor, rng, alignToTop) {
  19106. return withMarker(editor, curry(intoFrame, editor), rng, alignToTop);
  19107. };
  19108. var elementIntoFrame = function (editor, element, alignToTop) {
  19109. return withElement(editor, elementMarker(element), curry(intoFrame, editor), alignToTop);
  19110. };
  19111. var elementIntoView = function (editor, element, alignToTop) {
  19112. if (fireScrollIntoViewEvent(editor, element, alignToTop)) {
  19113. return;
  19114. }
  19115. var scroller = editor.inline ? elementIntoWindow : elementIntoFrame;
  19116. scroller(editor, element, alignToTop);
  19117. };
  19118. var rangeIntoView = function (editor, rng, alignToTop) {
  19119. var scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame;
  19120. scroller(editor, rng, alignToTop);
  19121. };
  19122. var ScrollIntoView = {
  19123. scrollElementIntoView: elementIntoView,
  19124. scrollRangeIntoView: rangeIntoView
  19125. };
  19126. var hasCeProperty = function (node) {
  19127. return NodeType.isContentEditableTrue(node) || NodeType.isContentEditableFalse(node);
  19128. };
  19129. var findParent = function (node, rootNode, predicate) {
  19130. while (node && node !== rootNode) {
  19131. if (predicate(node)) {
  19132. return node;
  19133. }
  19134. node = node.parentNode;
  19135. }
  19136. return null;
  19137. };
  19138. var findClosestIeRange = function (clientX, clientY, doc) {
  19139. var element, rng, rects;
  19140. element = doc.elementFromPoint(clientX, clientY);
  19141. rng = doc.body.createTextRange();
  19142. if (!element || element.tagName === 'HTML') {
  19143. element = doc.body;
  19144. }
  19145. rng.moveToElementText(element);
  19146. rects = Tools.toArray(rng.getClientRects());
  19147. rects = rects.sort(function (a, b) {
  19148. a = Math.abs(Math.max(a.top - clientY, a.bottom - clientY));
  19149. b = Math.abs(Math.max(b.top - clientY, b.bottom - clientY));
  19150. return a - b;
  19151. });
  19152. if (rects.length > 0) {
  19153. clientY = (rects[0].bottom + rects[0].top) / 2;
  19154. try {
  19155. rng.moveToPoint(clientX, clientY);
  19156. rng.collapse(true);
  19157. return rng;
  19158. } catch (ex) {
  19159. }
  19160. }
  19161. return null;
  19162. };
  19163. var moveOutOfContentEditableFalse = function (rng, rootNode) {
  19164. var parentElement = rng && rng.parentElement ? rng.parentElement() : null;
  19165. return NodeType.isContentEditableFalse(findParent(parentElement, rootNode, hasCeProperty)) ? null : rng;
  19166. };
  19167. var fromPoint$1 = function (clientX, clientY, doc) {
  19168. var rng, point;
  19169. var pointDoc = doc;
  19170. if (pointDoc.caretPositionFromPoint) {
  19171. point = pointDoc.caretPositionFromPoint(clientX, clientY);
  19172. if (point) {
  19173. rng = doc.createRange();
  19174. rng.setStart(point.offsetNode, point.offset);
  19175. rng.collapse(true);
  19176. }
  19177. } else if (doc.caretRangeFromPoint) {
  19178. rng = doc.caretRangeFromPoint(clientX, clientY);
  19179. } else if (pointDoc.body.createTextRange) {
  19180. rng = pointDoc.body.createTextRange();
  19181. try {
  19182. rng.moveToPoint(clientX, clientY);
  19183. rng.collapse(true);
  19184. } catch (ex) {
  19185. rng = findClosestIeRange(clientX, clientY, doc);
  19186. }
  19187. return moveOutOfContentEditableFalse(rng, doc.body);
  19188. }
  19189. return rng;
  19190. };
  19191. var CaretRangeFromPoint = { fromPoint: fromPoint$1 };
  19192. var processRanges = function (editor, ranges) {
  19193. return map(ranges, function (range) {
  19194. var evt = editor.fire('GetSelectionRange', { range: range });
  19195. return evt.range !== range ? evt.range : range;
  19196. });
  19197. };
  19198. var EventProcessRanges = { processRanges: processRanges };
  19199. var fromElements = function (elements, scope) {
  19200. var doc = scope || domGlobals.document;
  19201. var fragment = doc.createDocumentFragment();
  19202. each(elements, function (element) {
  19203. fragment.appendChild(element.dom());
  19204. });
  19205. return Element.fromDom(fragment);
  19206. };
  19207. var tableModel = Immutable('element', 'width', 'rows');
  19208. var tableRow = Immutable('element', 'cells');
  19209. var cellPosition = Immutable('x', 'y');
  19210. var getSpan = function (td, key) {
  19211. var value = parseInt(get$1(td, key), 10);
  19212. return isNaN(value) ? 1 : value;
  19213. };
  19214. var fillout = function (table, x, y, tr, td) {
  19215. var rowspan = getSpan(td, 'rowspan');
  19216. var colspan = getSpan(td, 'colspan');
  19217. var rows = table.rows();
  19218. for (var y2 = y; y2 < y + rowspan; y2++) {
  19219. if (!rows[y2]) {
  19220. rows[y2] = tableRow(deep(tr), []);
  19221. }
  19222. for (var x2 = x; x2 < x + colspan; x2++) {
  19223. var cells = rows[y2].cells();
  19224. cells[x2] = y2 === y && x2 === x ? td : shallow(td);
  19225. }
  19226. }
  19227. };
  19228. var cellExists = function (table, x, y) {
  19229. var rows = table.rows();
  19230. var cells = rows[y] ? rows[y].cells() : [];
  19231. return !!cells[x];
  19232. };
  19233. var skipCellsX = function (table, x, y) {
  19234. while (cellExists(table, x, y)) {
  19235. x++;
  19236. }
  19237. return x;
  19238. };
  19239. var getWidth = function (rows) {
  19240. return foldl(rows, function (acc, row) {
  19241. return row.cells().length > acc ? row.cells().length : acc;
  19242. }, 0);
  19243. };
  19244. var findElementPos = function (table, element) {
  19245. var rows = table.rows();
  19246. for (var y = 0; y < rows.length; y++) {
  19247. var cells = rows[y].cells();
  19248. for (var x = 0; x < cells.length; x++) {
  19249. if (eq(cells[x], element)) {
  19250. return Option.some(cellPosition(x, y));
  19251. }
  19252. }
  19253. }
  19254. return Option.none();
  19255. };
  19256. var extractRows = function (table, sx, sy, ex, ey) {
  19257. var newRows = [];
  19258. var rows = table.rows();
  19259. for (var y = sy; y <= ey; y++) {
  19260. var cells = rows[y].cells();
  19261. var slice = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1);
  19262. newRows.push(tableRow(rows[y].element(), slice));
  19263. }
  19264. return newRows;
  19265. };
  19266. var subTable = function (table, startPos, endPos) {
  19267. var sx = startPos.x(), sy = startPos.y();
  19268. var ex = endPos.x(), ey = endPos.y();
  19269. var newRows = sy < ey ? extractRows(table, sx, sy, ex, ey) : extractRows(table, sx, ey, ex, sy);
  19270. return tableModel(table.element(), getWidth(newRows), newRows);
  19271. };
  19272. var createDomTable = function (table, rows) {
  19273. var tableElement = shallow(table.element());
  19274. var tableBody = Element.fromTag('tbody');
  19275. append$1(tableBody, rows);
  19276. append(tableElement, tableBody);
  19277. return tableElement;
  19278. };
  19279. var modelRowsToDomRows = function (table) {
  19280. return map(table.rows(), function (row) {
  19281. var cells = map(row.cells(), function (cell) {
  19282. var td = deep(cell);
  19283. remove(td, 'colspan');
  19284. remove(td, 'rowspan');
  19285. return td;
  19286. });
  19287. var tr = shallow(row.element());
  19288. append$1(tr, cells);
  19289. return tr;
  19290. });
  19291. };
  19292. var fromDom$1 = function (tableElm) {
  19293. var table = tableModel(shallow(tableElm), 0, []);
  19294. each(descendants$1(tableElm, 'tr'), function (tr, y) {
  19295. each(descendants$1(tr, 'td,th'), function (td, x) {
  19296. fillout(table, skipCellsX(table, x, y), y, tr, td);
  19297. });
  19298. });
  19299. return tableModel(table.element(), getWidth(table.rows()), table.rows());
  19300. };
  19301. var toDom = function (table) {
  19302. return createDomTable(table, modelRowsToDomRows(table));
  19303. };
  19304. var subsection = function (table, startElement, endElement) {
  19305. return findElementPos(table, startElement).bind(function (startPos) {
  19306. return findElementPos(table, endElement).map(function (endPos) {
  19307. return subTable(table, startPos, endPos);
  19308. });
  19309. });
  19310. };
  19311. var SimpleTableModel = {
  19312. fromDom: fromDom$1,
  19313. toDom: toDom,
  19314. subsection: subsection
  19315. };
  19316. var getRanges = function (selection) {
  19317. var ranges = [];
  19318. if (selection) {
  19319. for (var i = 0; i < selection.rangeCount; i++) {
  19320. ranges.push(selection.getRangeAt(i));
  19321. }
  19322. }
  19323. return ranges;
  19324. };
  19325. var getSelectedNodes = function (ranges) {
  19326. return bind(ranges, function (range) {
  19327. var node = getSelectedNode(range);
  19328. return node ? [Element.fromDom(node)] : [];
  19329. });
  19330. };
  19331. var hasMultipleRanges = function (selection) {
  19332. return getRanges(selection).length > 1;
  19333. };
  19334. var MultiRange = {
  19335. getRanges: getRanges,
  19336. getSelectedNodes: getSelectedNodes,
  19337. hasMultipleRanges: hasMultipleRanges
  19338. };
  19339. var getCellsFromRanges = function (ranges) {
  19340. return filter(MultiRange.getSelectedNodes(ranges), isTableCell);
  19341. };
  19342. var getCellsFromElement = function (elm) {
  19343. return descendants$1(elm, 'td[data-mce-selected],th[data-mce-selected]');
  19344. };
  19345. var getCellsFromElementOrRanges = function (ranges, element) {
  19346. var selectedCells = getCellsFromElement(element);
  19347. var rangeCells = getCellsFromRanges(ranges);
  19348. return selectedCells.length > 0 ? selectedCells : rangeCells;
  19349. };
  19350. var getCellsFromEditor = function (editor) {
  19351. return getCellsFromElementOrRanges(MultiRange.getRanges(editor.selection.getSel()), Element.fromDom(editor.getBody()));
  19352. };
  19353. var TableCellSelection = {
  19354. getCellsFromRanges: getCellsFromRanges,
  19355. getCellsFromElement: getCellsFromElement,
  19356. getCellsFromElementOrRanges: getCellsFromElementOrRanges,
  19357. getCellsFromEditor: getCellsFromEditor
  19358. };
  19359. var findParentListContainer = function (parents) {
  19360. return find(parents, function (elm) {
  19361. return name(elm) === 'ul' || name(elm) === 'ol';
  19362. });
  19363. };
  19364. var getFullySelectedListWrappers = function (parents, rng) {
  19365. return find(parents, function (elm) {
  19366. return name(elm) === 'li' && hasAllContentsSelected(elm, rng);
  19367. }).fold(constant([]), function (li) {
  19368. return findParentListContainer(parents).map(function (listCont) {
  19369. return [
  19370. Element.fromTag('li'),
  19371. Element.fromTag(name(listCont))
  19372. ];
  19373. }).getOr([]);
  19374. });
  19375. };
  19376. var wrap$3 = function (innerElm, elms) {
  19377. var wrapped = foldl(elms, function (acc, elm) {
  19378. append(elm, acc);
  19379. return elm;
  19380. }, innerElm);
  19381. return elms.length > 0 ? fromElements([wrapped]) : wrapped;
  19382. };
  19383. var directListWrappers = function (commonAnchorContainer) {
  19384. if (isListItem(commonAnchorContainer)) {
  19385. return parent(commonAnchorContainer).filter(isList).fold(constant([]), function (listElm) {
  19386. return [
  19387. commonAnchorContainer,
  19388. listElm
  19389. ];
  19390. });
  19391. } else {
  19392. return isList(commonAnchorContainer) ? [commonAnchorContainer] : [];
  19393. }
  19394. };
  19395. var getWrapElements = function (rootNode, rng) {
  19396. var commonAnchorContainer = Element.fromDom(rng.commonAncestorContainer);
  19397. var parents = Parents.parentsAndSelf(commonAnchorContainer, rootNode);
  19398. var wrapElements = filter(parents, function (elm) {
  19399. return isInline(elm) || isHeading(elm);
  19400. });
  19401. var listWrappers = getFullySelectedListWrappers(parents, rng);
  19402. var allWrappers = wrapElements.concat(listWrappers.length ? listWrappers : directListWrappers(commonAnchorContainer));
  19403. return map(allWrappers, shallow);
  19404. };
  19405. var emptyFragment = function () {
  19406. return fromElements([]);
  19407. };
  19408. var getFragmentFromRange = function (rootNode, rng) {
  19409. return wrap$3(Element.fromDom(rng.cloneContents()), getWrapElements(rootNode, rng));
  19410. };
  19411. var getParentTable = function (rootElm, cell) {
  19412. return ancestor$1(cell, 'table', curry(eq, rootElm));
  19413. };
  19414. var getTableFragment = function (rootNode, selectedTableCells) {
  19415. return getParentTable(rootNode, selectedTableCells[0]).bind(function (tableElm) {
  19416. var firstCell = selectedTableCells[0];
  19417. var lastCell = selectedTableCells[selectedTableCells.length - 1];
  19418. var fullTableModel = SimpleTableModel.fromDom(tableElm);
  19419. return SimpleTableModel.subsection(fullTableModel, firstCell, lastCell).map(function (sectionedTableModel) {
  19420. return fromElements([SimpleTableModel.toDom(sectionedTableModel)]);
  19421. });
  19422. }).getOrThunk(emptyFragment);
  19423. };
  19424. var getSelectionFragment = function (rootNode, ranges) {
  19425. return ranges.length > 0 && ranges[0].collapsed ? emptyFragment() : getFragmentFromRange(rootNode, ranges[0]);
  19426. };
  19427. var read$2 = function (rootNode, ranges) {
  19428. var selectedCells = TableCellSelection.getCellsFromElementOrRanges(ranges, rootNode);
  19429. return selectedCells.length > 0 ? getTableFragment(rootNode, selectedCells) : getSelectionFragment(rootNode, ranges);
  19430. };
  19431. var FragmentReader = { read: read$2 };
  19432. var getTextContent = function (editor) {
  19433. return Option.from(editor.selection.getRng()).map(function (rng) {
  19434. var bin = editor.dom.add(editor.getBody(), 'div', {
  19435. 'data-mce-bogus': 'all',
  19436. 'style': 'overflow: hidden; opacity: 0;'
  19437. }, rng.cloneContents());
  19438. var text = Zwsp.trim(bin.innerText);
  19439. editor.dom.remove(bin);
  19440. return text;
  19441. }).getOr('');
  19442. };
  19443. var getHtmlContent = function (editor, args) {
  19444. var rng = editor.selection.getRng(), tmpElm = editor.dom.create('body');
  19445. var sel = editor.selection.getSel();
  19446. var fragment;
  19447. var ranges = EventProcessRanges.processRanges(editor, MultiRange.getRanges(sel));
  19448. fragment = args.contextual ? FragmentReader.read(Element.fromDom(editor.getBody()), ranges).dom() : rng.cloneContents();
  19449. if (fragment) {
  19450. tmpElm.appendChild(fragment);
  19451. }
  19452. return editor.selection.serializer.serialize(tmpElm, args);
  19453. };
  19454. var getContent$1 = function (editor, args) {
  19455. if (args === void 0) {
  19456. args = {};
  19457. }
  19458. args.get = true;
  19459. args.format = args.format || 'html';
  19460. args.selection = true;
  19461. args = editor.fire('BeforeGetContent', args);
  19462. if (args.isDefaultPrevented()) {
  19463. editor.fire('GetContent', args);
  19464. return args.content;
  19465. }
  19466. if (args.format === 'text') {
  19467. return getTextContent(editor);
  19468. } else {
  19469. args.getInner = true;
  19470. var content = getHtmlContent(editor, args);
  19471. if (args.format === 'tree') {
  19472. return content;
  19473. } else {
  19474. args.content = editor.selection.isCollapsed() ? '' : content;
  19475. editor.fire('GetContent', args);
  19476. return args.content;
  19477. }
  19478. }
  19479. };
  19480. var GetSelectionContent = { getContent: getContent$1 };
  19481. var findParent$1 = function (node, rootNode, predicate) {
  19482. while (node && node !== rootNode) {
  19483. if (predicate(node)) {
  19484. return node;
  19485. }
  19486. node = node.parentNode;
  19487. }
  19488. return null;
  19489. };
  19490. var hasParent = function (node, rootNode, predicate) {
  19491. return findParent$1(node, rootNode, predicate) !== null;
  19492. };
  19493. var hasParentWithName = function (node, rootNode, name) {
  19494. return hasParent(node, rootNode, function (node) {
  19495. return node.nodeName === name;
  19496. });
  19497. };
  19498. var isTable$3 = function (node) {
  19499. return node && node.nodeName === 'TABLE';
  19500. };
  19501. var isTableCell$3 = function (node) {
  19502. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
  19503. };
  19504. var isCeFalseCaretContainer = function (node, rootNode) {
  19505. return isCaretContainer(node) && hasParent(node, rootNode, isCaretNode) === false;
  19506. };
  19507. var hasBrBeforeAfter = function (dom, node, left) {
  19508. var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || dom.getRoot());
  19509. while (node = walker[left ? 'prev' : 'next']()) {
  19510. if (NodeType.isBr(node)) {
  19511. return true;
  19512. }
  19513. }
  19514. };
  19515. var isPrevNode = function (node, name) {
  19516. return node.previousSibling && node.previousSibling.nodeName === name;
  19517. };
  19518. var hasContentEditableFalseParent = function (body, node) {
  19519. while (node && node !== body) {
  19520. if (NodeType.isContentEditableFalse(node)) {
  19521. return true;
  19522. }
  19523. node = node.parentNode;
  19524. }
  19525. return false;
  19526. };
  19527. var findTextNodeRelative = function (dom, isAfterNode, collapsed, left, startNode) {
  19528. var lastInlineElement;
  19529. var body = dom.getRoot();
  19530. var node;
  19531. var nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  19532. var parentBlockContainer = dom.getParent(startNode.parentNode, dom.isBlock) || body;
  19533. if (left && NodeType.isBr(startNode) && isAfterNode && dom.isEmpty(parentBlockContainer)) {
  19534. return Option.some(CaretPosition(startNode.parentNode, dom.nodeIndex(startNode)));
  19535. }
  19536. var walker = new TreeWalker(startNode, parentBlockContainer);
  19537. while (node = walker[left ? 'prev' : 'next']()) {
  19538. if (dom.getContentEditableParent(node) === 'false' || isCeFalseCaretContainer(node, body)) {
  19539. return Option.none();
  19540. }
  19541. if (NodeType.isText(node) && node.nodeValue.length > 0) {
  19542. if (hasParentWithName(node, body, 'A') === false) {
  19543. return Option.some(CaretPosition(node, left ? node.nodeValue.length : 0));
  19544. }
  19545. return Option.none();
  19546. }
  19547. if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  19548. return Option.none();
  19549. }
  19550. lastInlineElement = node;
  19551. }
  19552. if (collapsed && lastInlineElement) {
  19553. return Option.some(CaretPosition(lastInlineElement, 0));
  19554. }
  19555. return Option.none();
  19556. };
  19557. var normalizeEndPoint = function (dom, collapsed, start, rng) {
  19558. var container, offset;
  19559. var body = dom.getRoot();
  19560. var node, nonEmptyElementsMap;
  19561. var directionLeft, isAfterNode, normalized = false;
  19562. container = rng[(start ? 'start' : 'end') + 'Container'];
  19563. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  19564. isAfterNode = NodeType.isElement(container) && offset === container.childNodes.length;
  19565. nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  19566. directionLeft = start;
  19567. if (isCaretContainer(container)) {
  19568. return Option.none();
  19569. }
  19570. if (NodeType.isElement(container) && offset > container.childNodes.length - 1) {
  19571. directionLeft = false;
  19572. }
  19573. if (NodeType.isDocument(container)) {
  19574. container = body;
  19575. offset = 0;
  19576. }
  19577. if (container === body) {
  19578. if (directionLeft) {
  19579. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  19580. if (node) {
  19581. if (isCaretContainer(node)) {
  19582. return Option.none();
  19583. }
  19584. if (nonEmptyElementsMap[node.nodeName] || isTable$3(node)) {
  19585. return Option.none();
  19586. }
  19587. }
  19588. }
  19589. if (container.hasChildNodes()) {
  19590. offset = Math.min(!directionLeft && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1);
  19591. container = container.childNodes[offset];
  19592. offset = NodeType.isText(container) && isAfterNode ? container.data.length : 0;
  19593. if (!collapsed && container === body.lastChild && isTable$3(container)) {
  19594. return Option.none();
  19595. }
  19596. if (hasContentEditableFalseParent(body, container) || isCaretContainer(container)) {
  19597. return Option.none();
  19598. }
  19599. if (container.hasChildNodes() && isTable$3(container) === false) {
  19600. node = container;
  19601. var walker = new TreeWalker(container, body);
  19602. do {
  19603. if (NodeType.isContentEditableFalse(node) || isCaretContainer(node)) {
  19604. normalized = false;
  19605. break;
  19606. }
  19607. if (NodeType.isText(node) && node.nodeValue.length > 0) {
  19608. offset = directionLeft ? 0 : node.nodeValue.length;
  19609. container = node;
  19610. normalized = true;
  19611. break;
  19612. }
  19613. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] && !isTableCell$3(node)) {
  19614. offset = dom.nodeIndex(node);
  19615. container = node.parentNode;
  19616. if (!directionLeft) {
  19617. offset++;
  19618. }
  19619. normalized = true;
  19620. break;
  19621. }
  19622. } while (node = directionLeft ? walker.next() : walker.prev());
  19623. }
  19624. }
  19625. }
  19626. if (collapsed) {
  19627. if (NodeType.isText(container) && offset === 0) {
  19628. findTextNodeRelative(dom, isAfterNode, collapsed, true, container).each(function (pos) {
  19629. container = pos.container();
  19630. offset = pos.offset();
  19631. normalized = true;
  19632. });
  19633. }
  19634. if (NodeType.isElement(container)) {
  19635. node = container.childNodes[offset];
  19636. if (!node) {
  19637. node = container.childNodes[offset - 1];
  19638. }
  19639. if (node && NodeType.isBr(node) && !isPrevNode(node, 'A') && !hasBrBeforeAfter(dom, node, false) && !hasBrBeforeAfter(dom, node, true)) {
  19640. findTextNodeRelative(dom, isAfterNode, collapsed, true, node).each(function (pos) {
  19641. container = pos.container();
  19642. offset = pos.offset();
  19643. normalized = true;
  19644. });
  19645. }
  19646. }
  19647. }
  19648. if (directionLeft && !collapsed && NodeType.isText(container) && offset === container.nodeValue.length) {
  19649. findTextNodeRelative(dom, isAfterNode, collapsed, false, container).each(function (pos) {
  19650. container = pos.container();
  19651. offset = pos.offset();
  19652. normalized = true;
  19653. });
  19654. }
  19655. return normalized ? Option.some(CaretPosition(container, offset)) : Option.none();
  19656. };
  19657. var normalize$2 = function (dom, rng) {
  19658. var collapsed = rng.collapsed, normRng = rng.cloneRange();
  19659. var startPos = CaretPosition.fromRangeStart(rng);
  19660. normalizeEndPoint(dom, collapsed, true, normRng).each(function (pos) {
  19661. if (!collapsed || !CaretPosition.isAbove(startPos, pos)) {
  19662. normRng.setStart(pos.container(), pos.offset());
  19663. }
  19664. });
  19665. if (!collapsed) {
  19666. normalizeEndPoint(dom, collapsed, false, normRng).each(function (pos) {
  19667. normRng.setEnd(pos.container(), pos.offset());
  19668. });
  19669. }
  19670. if (collapsed) {
  19671. normRng.collapse(true);
  19672. }
  19673. return RangeCompare.isEq(rng, normRng) ? Option.none() : Option.some(normRng);
  19674. };
  19675. var NormalizeRange = { normalize: normalize$2 };
  19676. var prependData = function (target, data) {
  19677. target.insertData(0, data);
  19678. };
  19679. var removeEmpty = function (text) {
  19680. if (text.dom().length === 0) {
  19681. remove$1(text);
  19682. return Option.none();
  19683. }
  19684. return Option.some(text);
  19685. };
  19686. var rngSetContent = function (rng, fragment) {
  19687. var firstChild = Option.from(fragment.firstChild).map(Element.fromDom);
  19688. var lastChild = Option.from(fragment.lastChild).map(Element.fromDom);
  19689. rng.deleteContents();
  19690. rng.insertNode(fragment);
  19691. var prevText = firstChild.bind(prevSibling).filter(isText$1).bind(removeEmpty);
  19692. var nextText = lastChild.bind(nextSibling).filter(isText$1).bind(removeEmpty);
  19693. lift2(prevText, firstChild.filter(isText$1), function (prev, start) {
  19694. prependData(start.dom(), prev.dom().data);
  19695. remove$1(prev);
  19696. });
  19697. lift2(nextText, lastChild.filter(isText$1), function (next, end) {
  19698. var oldLength = end.dom().length;
  19699. end.dom().appendData(next.dom().data);
  19700. rng.setEnd(end.dom(), oldLength);
  19701. remove$1(next);
  19702. });
  19703. rng.collapse(false);
  19704. };
  19705. var setupArgs = function (args, content) {
  19706. args = args || { format: 'html' };
  19707. args.set = true;
  19708. args.selection = true;
  19709. args.content = content;
  19710. return args;
  19711. };
  19712. var setContent$1 = function (editor, content, args) {
  19713. args = setupArgs(args, content);
  19714. if (!args.no_events) {
  19715. args = editor.fire('BeforeSetContent', args);
  19716. if (args.isDefaultPrevented()) {
  19717. editor.fire('SetContent', args);
  19718. return;
  19719. }
  19720. }
  19721. var rng = editor.selection.getRng();
  19722. rngSetContent(rng, rng.createContextualFragment(args.content));
  19723. editor.selection.setRng(rng);
  19724. ScrollIntoView.scrollRangeIntoView(editor, rng);
  19725. if (!args.no_events) {
  19726. editor.fire('SetContent', args);
  19727. }
  19728. };
  19729. var SetSelectionContent = { setContent: setContent$1 };
  19730. var getEndpointElement = function (root, rng, start, real, resolve) {
  19731. var container = start ? rng.startContainer : rng.endContainer;
  19732. var offset = start ? rng.startOffset : rng.endOffset;
  19733. return Option.from(container).map(Element.fromDom).map(function (elm) {
  19734. return !real || !rng.collapsed ? child(elm, resolve(elm, offset)).getOr(elm) : elm;
  19735. }).bind(function (elm) {
  19736. return isElement$1(elm) ? Option.some(elm) : parent(elm);
  19737. }).map(function (elm) {
  19738. return elm.dom();
  19739. }).getOr(root);
  19740. };
  19741. var getStart$2 = function (root, rng, real) {
  19742. return getEndpointElement(root, rng, true, real, function (elm, offset) {
  19743. return Math.min(childNodesCount(elm), offset);
  19744. });
  19745. };
  19746. var getEnd = function (root, rng, real) {
  19747. return getEndpointElement(root, rng, false, real, function (elm, offset) {
  19748. return offset > 0 ? offset - 1 : offset;
  19749. });
  19750. };
  19751. var skipEmptyTextNodes = function (node, forwards) {
  19752. var orig = node;
  19753. while (node && NodeType.isText(node) && node.length === 0) {
  19754. node = forwards ? node.nextSibling : node.previousSibling;
  19755. }
  19756. return node || orig;
  19757. };
  19758. var getNode$1 = function (root, rng) {
  19759. var elm, startContainer, endContainer, startOffset, endOffset;
  19760. if (!rng) {
  19761. return root;
  19762. }
  19763. startContainer = rng.startContainer;
  19764. endContainer = rng.endContainer;
  19765. startOffset = rng.startOffset;
  19766. endOffset = rng.endOffset;
  19767. elm = rng.commonAncestorContainer;
  19768. if (!rng.collapsed) {
  19769. if (startContainer === endContainer) {
  19770. if (endOffset - startOffset < 2) {
  19771. if (startContainer.hasChildNodes()) {
  19772. elm = startContainer.childNodes[startOffset];
  19773. }
  19774. }
  19775. }
  19776. if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
  19777. if (startContainer.length === startOffset) {
  19778. startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);
  19779. } else {
  19780. startContainer = startContainer.parentNode;
  19781. }
  19782. if (endOffset === 0) {
  19783. endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);
  19784. } else {
  19785. endContainer = endContainer.parentNode;
  19786. }
  19787. if (startContainer && startContainer === endContainer) {
  19788. return startContainer;
  19789. }
  19790. }
  19791. }
  19792. if (elm && elm.nodeType === 3) {
  19793. return elm.parentNode;
  19794. }
  19795. return elm;
  19796. };
  19797. var getSelectedBlocks = function (dom, rng, startElm, endElm) {
  19798. var node, root;
  19799. var selectedBlocks = [];
  19800. root = dom.getRoot();
  19801. startElm = dom.getParent(startElm || getStart$2(root, rng, rng.collapsed), dom.isBlock);
  19802. endElm = dom.getParent(endElm || getEnd(root, rng, rng.collapsed), dom.isBlock);
  19803. if (startElm && startElm !== root) {
  19804. selectedBlocks.push(startElm);
  19805. }
  19806. if (startElm && endElm && startElm !== endElm) {
  19807. node = startElm;
  19808. var walker = new TreeWalker(startElm, root);
  19809. while ((node = walker.next()) && node !== endElm) {
  19810. if (dom.isBlock(node)) {
  19811. selectedBlocks.push(node);
  19812. }
  19813. }
  19814. }
  19815. if (endElm && startElm !== endElm && endElm !== root) {
  19816. selectedBlocks.push(endElm);
  19817. }
  19818. return selectedBlocks;
  19819. };
  19820. var select$1 = function (dom, node, content) {
  19821. return Option.from(node).map(function (node) {
  19822. var idx = dom.nodeIndex(node);
  19823. var rng = dom.createRng();
  19824. rng.setStart(node.parentNode, idx);
  19825. rng.setEnd(node.parentNode, idx + 1);
  19826. if (content) {
  19827. moveEndPoint$1(dom, rng, node, true);
  19828. moveEndPoint$1(dom, rng, node, false);
  19829. }
  19830. return rng;
  19831. });
  19832. };
  19833. var deleteFromCallbackMap = function (callbackMap, selector, callback) {
  19834. if (callbackMap && callbackMap.hasOwnProperty(selector)) {
  19835. var newCallbacks = filter(callbackMap[selector], function (cb) {
  19836. return cb !== callback;
  19837. });
  19838. if (newCallbacks.length === 0) {
  19839. delete callbackMap[selector];
  19840. } else {
  19841. callbackMap[selector] = newCallbacks;
  19842. }
  19843. }
  19844. };
  19845. function SelectorChanged (dom, editor) {
  19846. var selectorChangedData;
  19847. var currentSelectors;
  19848. return {
  19849. selectorChangedWithUnbind: function (selector, callback) {
  19850. if (!selectorChangedData) {
  19851. selectorChangedData = {};
  19852. currentSelectors = {};
  19853. editor.on('NodeChange', function (e) {
  19854. var node = e.element, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
  19855. Tools.each(selectorChangedData, function (callbacks, selector) {
  19856. Tools.each(parents, function (node) {
  19857. if (dom.is(node, selector)) {
  19858. if (!currentSelectors[selector]) {
  19859. Tools.each(callbacks, function (callback) {
  19860. callback(true, {
  19861. node: node,
  19862. selector: selector,
  19863. parents: parents
  19864. });
  19865. });
  19866. currentSelectors[selector] = callbacks;
  19867. }
  19868. matchedSelectors[selector] = callbacks;
  19869. return false;
  19870. }
  19871. });
  19872. });
  19873. Tools.each(currentSelectors, function (callbacks, selector) {
  19874. if (!matchedSelectors[selector]) {
  19875. delete currentSelectors[selector];
  19876. Tools.each(callbacks, function (callback) {
  19877. callback(false, {
  19878. node: node,
  19879. selector: selector,
  19880. parents: parents
  19881. });
  19882. });
  19883. }
  19884. });
  19885. });
  19886. }
  19887. if (!selectorChangedData[selector]) {
  19888. selectorChangedData[selector] = [];
  19889. }
  19890. selectorChangedData[selector].push(callback);
  19891. return {
  19892. unbind: function () {
  19893. deleteFromCallbackMap(selectorChangedData, selector, callback);
  19894. deleteFromCallbackMap(currentSelectors, selector, callback);
  19895. }
  19896. };
  19897. }
  19898. };
  19899. }
  19900. var isNativeIeSelection = function (rng) {
  19901. return !!rng.select;
  19902. };
  19903. var isAttachedToDom = function (node) {
  19904. return !!(node && node.ownerDocument) && contains$2(Element.fromDom(node.ownerDocument), Element.fromDom(node));
  19905. };
  19906. var isValidRange = function (rng) {
  19907. if (!rng) {
  19908. return false;
  19909. } else if (isNativeIeSelection(rng)) {
  19910. return true;
  19911. } else {
  19912. return isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer);
  19913. }
  19914. };
  19915. var Selection$1 = function (dom, win, serializer, editor) {
  19916. var bookmarkManager;
  19917. var controlSelection;
  19918. var selectedRange;
  19919. var explicitRange;
  19920. var selectorChangedWithUnbind = SelectorChanged(dom, editor).selectorChangedWithUnbind;
  19921. var setCursorLocation = function (node, offset) {
  19922. var rng = dom.createRng();
  19923. if (!node) {
  19924. moveEndPoint$1(dom, rng, editor.getBody(), true);
  19925. setRng(rng);
  19926. } else {
  19927. rng.setStart(node, offset);
  19928. rng.setEnd(node, offset);
  19929. setRng(rng);
  19930. collapse(false);
  19931. }
  19932. };
  19933. var getContent = function (args) {
  19934. return GetSelectionContent.getContent(editor, args);
  19935. };
  19936. var setContent = function (content, args) {
  19937. return SetSelectionContent.setContent(editor, content, args);
  19938. };
  19939. var getStart = function (real) {
  19940. return getStart$2(editor.getBody(), getRng(), real);
  19941. };
  19942. var getEnd$1 = function (real) {
  19943. return getEnd(editor.getBody(), getRng(), real);
  19944. };
  19945. var getBookmark = function (type, normalized) {
  19946. return bookmarkManager.getBookmark(type, normalized);
  19947. };
  19948. var moveToBookmark = function (bookmark) {
  19949. return bookmarkManager.moveToBookmark(bookmark);
  19950. };
  19951. var select = function (node, content) {
  19952. select$1(dom, node, content).each(setRng);
  19953. return node;
  19954. };
  19955. var isCollapsed = function () {
  19956. var rng = getRng(), sel = getSel();
  19957. if (!rng || rng.item) {
  19958. return false;
  19959. }
  19960. if (rng.compareEndPoints) {
  19961. return rng.compareEndPoints('StartToEnd', rng) === 0;
  19962. }
  19963. return !sel || rng.collapsed;
  19964. };
  19965. var collapse = function (toStart) {
  19966. var rng = getRng();
  19967. rng.collapse(!!toStart);
  19968. setRng(rng);
  19969. };
  19970. var getSel = function () {
  19971. return win.getSelection ? win.getSelection() : win.document.selection;
  19972. };
  19973. var getRng = function () {
  19974. var selection, rng, elm, doc;
  19975. var tryCompareBoundaryPoints = function (how, sourceRange, destinationRange) {
  19976. try {
  19977. return sourceRange.compareBoundaryPoints(how, destinationRange);
  19978. } catch (ex) {
  19979. return -1;
  19980. }
  19981. };
  19982. if (!win) {
  19983. return null;
  19984. }
  19985. doc = win.document;
  19986. if (typeof doc === 'undefined' || doc === null) {
  19987. return null;
  19988. }
  19989. if (editor.bookmark !== undefined && EditorFocus.hasFocus(editor) === false) {
  19990. var bookmark = SelectionBookmark.getRng(editor);
  19991. if (bookmark.isSome()) {
  19992. return bookmark.map(function (r) {
  19993. return EventProcessRanges.processRanges(editor, [r])[0];
  19994. }).getOr(doc.createRange());
  19995. }
  19996. }
  19997. try {
  19998. if ((selection = getSel()) && !NodeType.isRestrictedNode(selection.anchorNode)) {
  19999. if (selection.rangeCount > 0) {
  20000. rng = selection.getRangeAt(0);
  20001. } else {
  20002. rng = selection.createRange ? selection.createRange() : doc.createRange();
  20003. }
  20004. }
  20005. } catch (ex) {
  20006. }
  20007. rng = EventProcessRanges.processRanges(editor, [rng])[0];
  20008. if (!rng) {
  20009. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  20010. }
  20011. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  20012. elm = dom.getRoot();
  20013. rng.setStart(elm, 0);
  20014. rng.setEnd(elm, 0);
  20015. }
  20016. if (selectedRange && explicitRange) {
  20017. if (tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) === 0 && tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0) {
  20018. rng = explicitRange;
  20019. } else {
  20020. selectedRange = null;
  20021. explicitRange = null;
  20022. }
  20023. }
  20024. return rng;
  20025. };
  20026. var setRng = function (rng, forward) {
  20027. var sel, node, evt;
  20028. if (!isValidRange(rng)) {
  20029. return;
  20030. }
  20031. var ieRange = isNativeIeSelection(rng) ? rng : null;
  20032. if (ieRange) {
  20033. explicitRange = null;
  20034. try {
  20035. ieRange.select();
  20036. } catch (ex) {
  20037. }
  20038. return;
  20039. }
  20040. sel = getSel();
  20041. evt = editor.fire('SetSelectionRange', {
  20042. range: rng,
  20043. forward: forward
  20044. });
  20045. rng = evt.range;
  20046. if (sel) {
  20047. explicitRange = rng;
  20048. try {
  20049. sel.removeAllRanges();
  20050. sel.addRange(rng);
  20051. } catch (ex) {
  20052. }
  20053. if (forward === false && sel.extend) {
  20054. sel.collapse(rng.endContainer, rng.endOffset);
  20055. sel.extend(rng.startContainer, rng.startOffset);
  20056. }
  20057. selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
  20058. }
  20059. if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent && !Env.ie) {
  20060. if (rng.endOffset - rng.startOffset < 2) {
  20061. if (rng.startContainer.hasChildNodes()) {
  20062. node = rng.startContainer.childNodes[rng.startOffset];
  20063. if (node && node.tagName === 'IMG') {
  20064. sel.setBaseAndExtent(rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset);
  20065. if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) {
  20066. sel.setBaseAndExtent(node, 0, node, 1);
  20067. }
  20068. }
  20069. }
  20070. }
  20071. }
  20072. editor.fire('AfterSetSelectionRange', {
  20073. range: rng,
  20074. forward: forward
  20075. });
  20076. };
  20077. var setNode = function (elm) {
  20078. setContent(dom.getOuterHTML(elm));
  20079. return elm;
  20080. };
  20081. var getNode = function () {
  20082. return getNode$1(editor.getBody(), getRng());
  20083. };
  20084. var getSelectedBlocks$1 = function (startElm, endElm) {
  20085. return getSelectedBlocks(dom, getRng(), startElm, endElm);
  20086. };
  20087. var isForward = function () {
  20088. var sel = getSel();
  20089. var anchorRange, focusRange;
  20090. if (!sel || !sel.anchorNode || !sel.focusNode) {
  20091. return true;
  20092. }
  20093. anchorRange = dom.createRng();
  20094. anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
  20095. anchorRange.collapse(true);
  20096. focusRange = dom.createRng();
  20097. focusRange.setStart(sel.focusNode, sel.focusOffset);
  20098. focusRange.collapse(true);
  20099. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  20100. };
  20101. var normalize = function () {
  20102. var rng = getRng();
  20103. var sel = getSel();
  20104. if (!MultiRange.hasMultipleRanges(sel) && hasAnyRanges(editor)) {
  20105. var normRng = NormalizeRange.normalize(dom, rng);
  20106. normRng.each(function (normRng) {
  20107. setRng(normRng, isForward());
  20108. });
  20109. return normRng.getOr(rng);
  20110. }
  20111. return rng;
  20112. };
  20113. var selectorChanged = function (selector, callback) {
  20114. selectorChangedWithUnbind(selector, callback);
  20115. return exports;
  20116. };
  20117. var getScrollContainer = function () {
  20118. var scrollContainer;
  20119. var node = dom.getRoot();
  20120. while (node && node.nodeName !== 'BODY') {
  20121. if (node.scrollHeight > node.clientHeight) {
  20122. scrollContainer = node;
  20123. break;
  20124. }
  20125. node = node.parentNode;
  20126. }
  20127. return scrollContainer;
  20128. };
  20129. var scrollIntoView = function (elm, alignToTop) {
  20130. return ScrollIntoView.scrollElementIntoView(editor, elm, alignToTop);
  20131. };
  20132. var placeCaretAt = function (clientX, clientY) {
  20133. return setRng(CaretRangeFromPoint.fromPoint(clientX, clientY, editor.getDoc()));
  20134. };
  20135. var getBoundingClientRect = function () {
  20136. var rng = getRng();
  20137. return rng.collapsed ? CaretPosition$1.fromRangeStart(rng).getClientRects()[0] : rng.getBoundingClientRect();
  20138. };
  20139. var destroy = function () {
  20140. win = selectedRange = explicitRange = null;
  20141. controlSelection.destroy();
  20142. };
  20143. var exports = {
  20144. bookmarkManager: null,
  20145. controlSelection: null,
  20146. dom: dom,
  20147. win: win,
  20148. serializer: serializer,
  20149. editor: editor,
  20150. collapse: collapse,
  20151. setCursorLocation: setCursorLocation,
  20152. getContent: getContent,
  20153. setContent: setContent,
  20154. getBookmark: getBookmark,
  20155. moveToBookmark: moveToBookmark,
  20156. select: select,
  20157. isCollapsed: isCollapsed,
  20158. isForward: isForward,
  20159. setNode: setNode,
  20160. getNode: getNode,
  20161. getSel: getSel,
  20162. setRng: setRng,
  20163. getRng: getRng,
  20164. getStart: getStart,
  20165. getEnd: getEnd$1,
  20166. getSelectedBlocks: getSelectedBlocks$1,
  20167. normalize: normalize,
  20168. selectorChanged: selectorChanged,
  20169. selectorChangedWithUnbind: selectorChangedWithUnbind,
  20170. getScrollContainer: getScrollContainer,
  20171. scrollIntoView: scrollIntoView,
  20172. placeCaretAt: placeCaretAt,
  20173. getBoundingClientRect: getBoundingClientRect,
  20174. destroy: destroy
  20175. };
  20176. bookmarkManager = BookmarkManager$1(exports);
  20177. controlSelection = ControlSelection(exports, editor);
  20178. exports.bookmarkManager = bookmarkManager;
  20179. exports.controlSelection = controlSelection;
  20180. return exports;
  20181. };
  20182. var isText$8 = NodeType.isText;
  20183. var startsWithCaretContainer$1 = function (node) {
  20184. return isText$8(node) && node.data[0] === Zwsp.ZWSP;
  20185. };
  20186. var endsWithCaretContainer$1 = function (node) {
  20187. return isText$8(node) && node.data[node.data.length - 1] === Zwsp.ZWSP;
  20188. };
  20189. var createZwsp = function (node) {
  20190. return node.ownerDocument.createTextNode(Zwsp.ZWSP);
  20191. };
  20192. var insertBefore = function (node) {
  20193. if (isText$8(node.previousSibling)) {
  20194. if (endsWithCaretContainer$1(node.previousSibling)) {
  20195. return node.previousSibling;
  20196. } else {
  20197. node.previousSibling.appendData(Zwsp.ZWSP);
  20198. return node.previousSibling;
  20199. }
  20200. } else if (isText$8(node)) {
  20201. if (startsWithCaretContainer$1(node)) {
  20202. return node;
  20203. } else {
  20204. node.insertData(0, Zwsp.ZWSP);
  20205. return node;
  20206. }
  20207. } else {
  20208. var newNode = createZwsp(node);
  20209. node.parentNode.insertBefore(newNode, node);
  20210. return newNode;
  20211. }
  20212. };
  20213. var insertAfter = function (node) {
  20214. if (isText$8(node.nextSibling)) {
  20215. if (startsWithCaretContainer$1(node.nextSibling)) {
  20216. return node.nextSibling;
  20217. } else {
  20218. node.nextSibling.insertData(0, Zwsp.ZWSP);
  20219. return node.nextSibling;
  20220. }
  20221. } else if (isText$8(node)) {
  20222. if (endsWithCaretContainer$1(node)) {
  20223. return node;
  20224. } else {
  20225. node.appendData(Zwsp.ZWSP);
  20226. return node;
  20227. }
  20228. } else {
  20229. var newNode = createZwsp(node);
  20230. if (node.nextSibling) {
  20231. node.parentNode.insertBefore(newNode, node.nextSibling);
  20232. } else {
  20233. node.parentNode.appendChild(newNode);
  20234. }
  20235. return newNode;
  20236. }
  20237. };
  20238. var insertInline$1 = function (before, node) {
  20239. return before ? insertBefore(node) : insertAfter(node);
  20240. };
  20241. var insertInlineBefore = curry(insertInline$1, true);
  20242. var insertInlineAfter = curry(insertInline$1, false);
  20243. var insertInlinePos = function (pos, before) {
  20244. if (NodeType.isText(pos.container())) {
  20245. return insertInline$1(before, pos.container());
  20246. } else {
  20247. return insertInline$1(before, pos.getNode());
  20248. }
  20249. };
  20250. var isPosCaretContainer = function (pos, caret) {
  20251. var caretNode = caret.get();
  20252. return caretNode && pos.container() === caretNode && isCaretContainerInline(caretNode);
  20253. };
  20254. var renderCaret = function (caret, location) {
  20255. return location.fold(function (element) {
  20256. CaretContainerRemove.remove(caret.get());
  20257. var text = insertInlineBefore(element);
  20258. caret.set(text);
  20259. return Option.some(CaretPosition$1(text, text.length - 1));
  20260. }, function (element) {
  20261. return CaretFinder.firstPositionIn(element).map(function (pos) {
  20262. if (!isPosCaretContainer(pos, caret)) {
  20263. CaretContainerRemove.remove(caret.get());
  20264. var text = insertInlinePos(pos, true);
  20265. caret.set(text);
  20266. return CaretPosition$1(text, 1);
  20267. } else {
  20268. return CaretPosition$1(caret.get(), 1);
  20269. }
  20270. });
  20271. }, function (element) {
  20272. return CaretFinder.lastPositionIn(element).map(function (pos) {
  20273. if (!isPosCaretContainer(pos, caret)) {
  20274. CaretContainerRemove.remove(caret.get());
  20275. var text = insertInlinePos(pos, false);
  20276. caret.set(text);
  20277. return CaretPosition$1(text, text.length - 1);
  20278. } else {
  20279. return CaretPosition$1(caret.get(), caret.get().length - 1);
  20280. }
  20281. });
  20282. }, function (element) {
  20283. CaretContainerRemove.remove(caret.get());
  20284. var text = insertInlineAfter(element);
  20285. caret.set(text);
  20286. return Option.some(CaretPosition$1(text, 1));
  20287. });
  20288. };
  20289. var BoundaryCaret = { renderCaret: renderCaret };
  20290. var strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/;
  20291. var hasStrongRtl = function (text) {
  20292. return strongRtl.test(text);
  20293. };
  20294. var isInlineTarget = function (editor, elm) {
  20295. return is(Element.fromDom(elm), Settings.getInlineBoundarySelector(editor));
  20296. };
  20297. var isRtl$1 = function (element) {
  20298. return DOMUtils$1.DOM.getStyle(element, 'direction', true) === 'rtl' || hasStrongRtl(element.textContent);
  20299. };
  20300. var findInlineParents = function (isInlineTarget, rootNode, pos) {
  20301. return filter(DOMUtils$1.DOM.getParents(pos.container(), '*', rootNode), isInlineTarget);
  20302. };
  20303. var findRootInline = function (isInlineTarget, rootNode, pos) {
  20304. var parents = findInlineParents(isInlineTarget, rootNode, pos);
  20305. return Option.from(parents[parents.length - 1]);
  20306. };
  20307. var hasSameParentBlock = function (rootNode, node1, node2) {
  20308. var block1 = getParentBlock(node1, rootNode);
  20309. var block2 = getParentBlock(node2, rootNode);
  20310. return block1 && block1 === block2;
  20311. };
  20312. var isAtZwsp = function (pos) {
  20313. return isBeforeInline(pos) || isAfterInline(pos);
  20314. };
  20315. var normalizePosition = function (forward, pos) {
  20316. if (!pos) {
  20317. return pos;
  20318. }
  20319. var container = pos.container(), offset = pos.offset();
  20320. if (forward) {
  20321. if (isCaretContainerInline(container)) {
  20322. if (NodeType.isText(container.nextSibling)) {
  20323. return CaretPosition$1(container.nextSibling, 0);
  20324. } else {
  20325. return CaretPosition$1.after(container);
  20326. }
  20327. } else {
  20328. return isBeforeInline(pos) ? CaretPosition$1(container, offset + 1) : pos;
  20329. }
  20330. } else {
  20331. if (isCaretContainerInline(container)) {
  20332. if (NodeType.isText(container.previousSibling)) {
  20333. return CaretPosition$1(container.previousSibling, container.previousSibling.data.length);
  20334. } else {
  20335. return CaretPosition$1.before(container);
  20336. }
  20337. } else {
  20338. return isAfterInline(pos) ? CaretPosition$1(container, offset - 1) : pos;
  20339. }
  20340. }
  20341. };
  20342. var normalizeForwards = curry(normalizePosition, true);
  20343. var normalizeBackwards = curry(normalizePosition, false);
  20344. var InlineUtils = {
  20345. isInlineTarget: isInlineTarget,
  20346. findRootInline: findRootInline,
  20347. isRtl: isRtl$1,
  20348. isAtZwsp: isAtZwsp,
  20349. normalizePosition: normalizePosition,
  20350. normalizeForwards: normalizeForwards,
  20351. normalizeBackwards: normalizeBackwards,
  20352. hasSameParentBlock: hasSameParentBlock
  20353. };
  20354. var evaluateUntil = function (fns, args) {
  20355. for (var i = 0; i < fns.length; i++) {
  20356. var result = fns[i].apply(null, args);
  20357. if (result.isSome()) {
  20358. return result;
  20359. }
  20360. }
  20361. return Option.none();
  20362. };
  20363. var LazyEvaluator = { evaluateUntil: evaluateUntil };
  20364. var Location = Adt.generate([
  20365. { before: ['element'] },
  20366. { start: ['element'] },
  20367. { end: ['element'] },
  20368. { after: ['element'] }
  20369. ]);
  20370. var rescope = function (rootNode, node) {
  20371. var parentBlock = getParentBlock(node, rootNode);
  20372. return parentBlock ? parentBlock : rootNode;
  20373. };
  20374. var before$4 = function (isInlineTarget, rootNode, pos) {
  20375. var nPos = InlineUtils.normalizeForwards(pos);
  20376. var scope = rescope(rootNode, nPos.container());
  20377. return InlineUtils.findRootInline(isInlineTarget, scope, nPos).fold(function () {
  20378. return CaretFinder.nextPosition(scope, nPos).bind(curry(InlineUtils.findRootInline, isInlineTarget, scope)).map(function (inline) {
  20379. return Location.before(inline);
  20380. });
  20381. }, Option.none);
  20382. };
  20383. var isNotInsideFormatCaretContainer = function (rootNode, elm) {
  20384. return getParentCaretContainer(rootNode, elm) === null;
  20385. };
  20386. var findInsideRootInline = function (isInlineTarget, rootNode, pos) {
  20387. return InlineUtils.findRootInline(isInlineTarget, rootNode, pos).filter(curry(isNotInsideFormatCaretContainer, rootNode));
  20388. };
  20389. var start$1 = function (isInlineTarget, rootNode, pos) {
  20390. var nPos = InlineUtils.normalizeBackwards(pos);
  20391. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (inline) {
  20392. var prevPos = CaretFinder.prevPosition(inline, nPos);
  20393. return prevPos.isNone() ? Option.some(Location.start(inline)) : Option.none();
  20394. });
  20395. };
  20396. var end = function (isInlineTarget, rootNode, pos) {
  20397. var nPos = InlineUtils.normalizeForwards(pos);
  20398. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (inline) {
  20399. var nextPos = CaretFinder.nextPosition(inline, nPos);
  20400. return nextPos.isNone() ? Option.some(Location.end(inline)) : Option.none();
  20401. });
  20402. };
  20403. var after$3 = function (isInlineTarget, rootNode, pos) {
  20404. var nPos = InlineUtils.normalizeBackwards(pos);
  20405. var scope = rescope(rootNode, nPos.container());
  20406. return InlineUtils.findRootInline(isInlineTarget, scope, nPos).fold(function () {
  20407. return CaretFinder.prevPosition(scope, nPos).bind(curry(InlineUtils.findRootInline, isInlineTarget, scope)).map(function (inline) {
  20408. return Location.after(inline);
  20409. });
  20410. }, Option.none);
  20411. };
  20412. var isValidLocation = function (location) {
  20413. return InlineUtils.isRtl(getElement(location)) === false;
  20414. };
  20415. var readLocation = function (isInlineTarget, rootNode, pos) {
  20416. var location = LazyEvaluator.evaluateUntil([
  20417. before$4,
  20418. start$1,
  20419. end,
  20420. after$3
  20421. ], [
  20422. isInlineTarget,
  20423. rootNode,
  20424. pos
  20425. ]);
  20426. return location.filter(isValidLocation);
  20427. };
  20428. var getElement = function (location) {
  20429. return location.fold(identity, identity, identity, identity);
  20430. };
  20431. var getName = function (location) {
  20432. return location.fold(constant('before'), constant('start'), constant('end'), constant('after'));
  20433. };
  20434. var outside = function (location) {
  20435. return location.fold(Location.before, Location.before, Location.after, Location.after);
  20436. };
  20437. var inside = function (location) {
  20438. return location.fold(Location.start, Location.start, Location.end, Location.end);
  20439. };
  20440. var isEq$5 = function (location1, location2) {
  20441. return getName(location1) === getName(location2) && getElement(location1) === getElement(location2);
  20442. };
  20443. var betweenInlines = function (forward, isInlineTarget, rootNode, from, to, location) {
  20444. return lift2(InlineUtils.findRootInline(isInlineTarget, rootNode, from), InlineUtils.findRootInline(isInlineTarget, rootNode, to), function (fromInline, toInline) {
  20445. if (fromInline !== toInline && InlineUtils.hasSameParentBlock(rootNode, fromInline, toInline)) {
  20446. return Location.after(forward ? fromInline : toInline);
  20447. } else {
  20448. return location;
  20449. }
  20450. }).getOr(location);
  20451. };
  20452. var skipNoMovement = function (fromLocation, toLocation) {
  20453. return fromLocation.fold(constant(true), function (fromLocation) {
  20454. return !isEq$5(fromLocation, toLocation);
  20455. });
  20456. };
  20457. var findLocationTraverse = function (forward, isInlineTarget, rootNode, fromLocation, pos) {
  20458. var from = InlineUtils.normalizePosition(forward, pos);
  20459. var to = CaretFinder.fromPosition(forward, rootNode, from).map(curry(InlineUtils.normalizePosition, forward));
  20460. var location = to.fold(function () {
  20461. return fromLocation.map(outside);
  20462. }, function (to) {
  20463. return readLocation(isInlineTarget, rootNode, to).map(curry(betweenInlines, forward, isInlineTarget, rootNode, from, to)).filter(curry(skipNoMovement, fromLocation));
  20464. });
  20465. return location.filter(isValidLocation);
  20466. };
  20467. var findLocationSimple = function (forward, location) {
  20468. if (forward) {
  20469. return location.fold(compose(Option.some, Location.start), Option.none, compose(Option.some, Location.after), Option.none);
  20470. } else {
  20471. return location.fold(Option.none, compose(Option.some, Location.before), Option.none, compose(Option.some, Location.end));
  20472. }
  20473. };
  20474. var findLocation = function (forward, isInlineTarget, rootNode, pos) {
  20475. var from = InlineUtils.normalizePosition(forward, pos);
  20476. var fromLocation = readLocation(isInlineTarget, rootNode, from);
  20477. return readLocation(isInlineTarget, rootNode, from).bind(curry(findLocationSimple, forward)).orThunk(function () {
  20478. return findLocationTraverse(forward, isInlineTarget, rootNode, fromLocation, pos);
  20479. });
  20480. };
  20481. var BoundaryLocation = {
  20482. readLocation: readLocation,
  20483. findLocation: findLocation,
  20484. prevLocation: curry(findLocation, false),
  20485. nextLocation: curry(findLocation, true),
  20486. getElement: getElement,
  20487. outside: outside,
  20488. inside: inside
  20489. };
  20490. var hasSelectionModifyApi = function (editor) {
  20491. return isFunction(editor.selection.getSel().modify);
  20492. };
  20493. var moveRel = function (forward, selection, pos) {
  20494. var delta = forward ? 1 : -1;
  20495. selection.setRng(CaretPosition$1(pos.container(), pos.offset() + delta).toRange());
  20496. selection.getSel().modify('move', forward ? 'forward' : 'backward', 'word');
  20497. return true;
  20498. };
  20499. var moveByWord = function (forward, editor) {
  20500. var rng = editor.selection.getRng();
  20501. var pos = forward ? CaretPosition$1.fromRangeEnd(rng) : CaretPosition$1.fromRangeStart(rng);
  20502. if (!hasSelectionModifyApi(editor)) {
  20503. return false;
  20504. } else if (forward && isBeforeInline(pos)) {
  20505. return moveRel(true, editor.selection, pos);
  20506. } else if (!forward && isAfterInline(pos)) {
  20507. return moveRel(false, editor.selection, pos);
  20508. } else {
  20509. return false;
  20510. }
  20511. };
  20512. var WordSelection = {
  20513. hasSelectionModifyApi: hasSelectionModifyApi,
  20514. moveByWord: moveByWord
  20515. };
  20516. var setCaretPosition = function (editor, pos) {
  20517. var rng = editor.dom.createRng();
  20518. rng.setStart(pos.container(), pos.offset());
  20519. rng.setEnd(pos.container(), pos.offset());
  20520. editor.selection.setRng(rng);
  20521. };
  20522. var isFeatureEnabled = function (editor) {
  20523. return editor.settings.inline_boundaries !== false;
  20524. };
  20525. var setSelected = function (state, elm) {
  20526. if (state) {
  20527. elm.setAttribute('data-mce-selected', 'inline-boundary');
  20528. } else {
  20529. elm.removeAttribute('data-mce-selected');
  20530. }
  20531. };
  20532. var renderCaretLocation = function (editor, caret, location) {
  20533. return BoundaryCaret.renderCaret(caret, location).map(function (pos) {
  20534. setCaretPosition(editor, pos);
  20535. return location;
  20536. });
  20537. };
  20538. var findLocation$1 = function (editor, caret, forward) {
  20539. var rootNode = editor.getBody();
  20540. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20541. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  20542. var location = BoundaryLocation.findLocation(forward, isInlineTarget, rootNode, from);
  20543. return location.bind(function (location) {
  20544. return renderCaretLocation(editor, caret, location);
  20545. });
  20546. };
  20547. var toggleInlines = function (isInlineTarget, dom, elms) {
  20548. var selectedInlines = filter(dom.select('*[data-mce-selected="inline-boundary"]'), isInlineTarget);
  20549. var targetInlines = filter(elms, isInlineTarget);
  20550. each(difference(selectedInlines, targetInlines), curry(setSelected, false));
  20551. each(difference(targetInlines, selectedInlines), curry(setSelected, true));
  20552. };
  20553. var safeRemoveCaretContainer = function (editor, caret) {
  20554. if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) {
  20555. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20556. if (CaretPosition$1.isTextPosition(pos) && InlineUtils.isAtZwsp(pos) === false) {
  20557. setCaretPosition(editor, CaretContainerRemove.removeAndReposition(caret.get(), pos));
  20558. caret.set(null);
  20559. }
  20560. }
  20561. };
  20562. var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) {
  20563. if (editor.selection.isCollapsed()) {
  20564. var inlines = filter(elms, isInlineTarget);
  20565. each(inlines, function (inline) {
  20566. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20567. BoundaryLocation.readLocation(isInlineTarget, editor.getBody(), pos).bind(function (location) {
  20568. return renderCaretLocation(editor, caret, location);
  20569. });
  20570. });
  20571. }
  20572. };
  20573. var move$1 = function (editor, caret, forward) {
  20574. return function () {
  20575. return isFeatureEnabled(editor) ? findLocation$1(editor, caret, forward).isSome() : false;
  20576. };
  20577. };
  20578. var moveWord = function (forward, editor, caret) {
  20579. return function () {
  20580. return isFeatureEnabled(editor) ? WordSelection.moveByWord(forward, editor) : false;
  20581. };
  20582. };
  20583. var setupSelectedState = function (editor) {
  20584. var caret = Cell(null);
  20585. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  20586. editor.on('NodeChange', function (e) {
  20587. if (isFeatureEnabled(editor)) {
  20588. toggleInlines(isInlineTarget, editor.dom, e.parents);
  20589. safeRemoveCaretContainer(editor, caret);
  20590. renderInsideInlineCaret(isInlineTarget, editor, caret, e.parents);
  20591. }
  20592. });
  20593. return caret;
  20594. };
  20595. var moveNextWord = curry(moveWord, true);
  20596. var movePrevWord = curry(moveWord, false);
  20597. var BoundarySelection = {
  20598. move: move$1,
  20599. moveNextWord: moveNextWord,
  20600. movePrevWord: movePrevWord,
  20601. setupSelectedState: setupSelectedState,
  20602. setCaretPosition: setCaretPosition
  20603. };
  20604. var BreakType;
  20605. (function (BreakType) {
  20606. BreakType[BreakType['Br'] = 0] = 'Br';
  20607. BreakType[BreakType['Block'] = 1] = 'Block';
  20608. BreakType[BreakType['Wrap'] = 2] = 'Wrap';
  20609. BreakType[BreakType['Eol'] = 3] = 'Eol';
  20610. }(BreakType || (BreakType = {})));
  20611. var flip = function (direction, positions) {
  20612. return direction === HDirection.Backwards ? positions.reverse() : positions;
  20613. };
  20614. var walk$3 = function (direction, caretWalker, pos) {
  20615. return direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos);
  20616. };
  20617. var getBreakType = function (scope, direction, currentPos, nextPos) {
  20618. if (NodeType.isBr(nextPos.getNode(direction === HDirection.Forwards))) {
  20619. return BreakType.Br;
  20620. } else if (isInSameBlock(currentPos, nextPos) === false) {
  20621. return BreakType.Block;
  20622. } else {
  20623. return BreakType.Wrap;
  20624. }
  20625. };
  20626. var getPositionsUntil = function (predicate, direction, scope, start) {
  20627. var caretWalker = CaretWalker(scope);
  20628. var currentPos = start, nextPos;
  20629. var positions = [];
  20630. while (currentPos) {
  20631. nextPos = walk$3(direction, caretWalker, currentPos);
  20632. if (!nextPos) {
  20633. break;
  20634. }
  20635. if (NodeType.isBr(nextPos.getNode(false))) {
  20636. if (direction === HDirection.Forwards) {
  20637. return {
  20638. positions: flip(direction, positions).concat([nextPos]),
  20639. breakType: BreakType.Br,
  20640. breakAt: Option.some(nextPos)
  20641. };
  20642. } else {
  20643. return {
  20644. positions: flip(direction, positions),
  20645. breakType: BreakType.Br,
  20646. breakAt: Option.some(nextPos)
  20647. };
  20648. }
  20649. }
  20650. if (!nextPos.isVisible()) {
  20651. currentPos = nextPos;
  20652. continue;
  20653. }
  20654. if (predicate(currentPos, nextPos)) {
  20655. var breakType = getBreakType(scope, direction, currentPos, nextPos);
  20656. return {
  20657. positions: flip(direction, positions),
  20658. breakType: breakType,
  20659. breakAt: Option.some(nextPos)
  20660. };
  20661. }
  20662. positions.push(nextPos);
  20663. currentPos = nextPos;
  20664. }
  20665. return {
  20666. positions: flip(direction, positions),
  20667. breakType: BreakType.Eol,
  20668. breakAt: Option.none()
  20669. };
  20670. };
  20671. var getAdjacentLinePositions = function (direction, getPositionsUntilBreak, scope, start) {
  20672. return getPositionsUntilBreak(scope, start).breakAt.map(function (pos) {
  20673. var positions = getPositionsUntilBreak(scope, pos).positions;
  20674. return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions);
  20675. }).getOr([]);
  20676. };
  20677. var findClosestHorizontalPositionFromPoint = function (positions, x) {
  20678. return foldl(positions, function (acc, newPos) {
  20679. return acc.fold(function () {
  20680. return Option.some(newPos);
  20681. }, function (lastPos) {
  20682. return lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), function (lastRect, newRect) {
  20683. var lastDist = Math.abs(x - lastRect.left);
  20684. var newDist = Math.abs(x - newRect.left);
  20685. return newDist <= lastDist ? newPos : lastPos;
  20686. }).or(acc);
  20687. });
  20688. }, Option.none());
  20689. };
  20690. var findClosestHorizontalPosition = function (positions, pos) {
  20691. return head(pos.getClientRects()).bind(function (targetRect) {
  20692. return findClosestHorizontalPositionFromPoint(positions, targetRect.left);
  20693. });
  20694. };
  20695. var getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1);
  20696. var getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1);
  20697. var isAtFirstLine = function (scope, pos) {
  20698. return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone();
  20699. };
  20700. var isAtLastLine = function (scope, pos) {
  20701. return getPositionsUntilNextLine(scope, pos).breakAt.isNone();
  20702. };
  20703. var getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine);
  20704. var getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine);
  20705. var getFirstLinePositions = function (scope) {
  20706. return CaretFinder.firstPositionIn(scope).map(function (pos) {
  20707. return [pos].concat(getPositionsUntilNextLine(scope, pos).positions);
  20708. }).getOr([]);
  20709. };
  20710. var getLastLinePositions = function (scope) {
  20711. return CaretFinder.lastPositionIn(scope).map(function (pos) {
  20712. return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos);
  20713. }).getOr([]);
  20714. };
  20715. var isContentEditableFalse$b = NodeType.isContentEditableFalse;
  20716. var getSelectedNode$1 = getSelectedNode;
  20717. var moveToCeFalseHorizontally = function (direction, editor, getNextPosFn, range) {
  20718. var forwards = direction === HDirection.Forwards;
  20719. var isBeforeContentEditableFalseFn = forwards ? isBeforeContentEditableFalse : isAfterContentEditableFalse;
  20720. if (!range.collapsed) {
  20721. var node = getSelectedNode$1(range);
  20722. if (isContentEditableFalse$b(node)) {
  20723. return showCaret(direction, editor, node, direction === HDirection.Backwards, true);
  20724. }
  20725. }
  20726. var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range);
  20727. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  20728. if (isBeforeContentEditableFalseFn(caretPosition)) {
  20729. return selectNode(editor, caretPosition.getNode(!forwards));
  20730. }
  20731. var nextCaretPosition = InlineUtils.normalizePosition(forwards, getNextPosFn(caretPosition));
  20732. if (!nextCaretPosition) {
  20733. if (rangeIsInContainerBlock) {
  20734. return range;
  20735. }
  20736. return null;
  20737. }
  20738. if (isBeforeContentEditableFalseFn(nextCaretPosition)) {
  20739. return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, true);
  20740. }
  20741. var peekCaretPosition = getNextPosFn(nextCaretPosition);
  20742. if (peekCaretPosition && isBeforeContentEditableFalseFn(peekCaretPosition)) {
  20743. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  20744. return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, true);
  20745. }
  20746. }
  20747. if (rangeIsInContainerBlock) {
  20748. return renderRangeCaret(editor, nextCaretPosition.toRange(), true);
  20749. }
  20750. return null;
  20751. };
  20752. var moveToCeFalseVertically = function (direction, editor, walkerFn, range) {
  20753. var caretPosition, linePositions, nextLinePositions;
  20754. var closestNextLineRect, caretClientRect, clientX;
  20755. var dist1, dist2, contentEditableFalseNode;
  20756. contentEditableFalseNode = getSelectedNode$1(range);
  20757. caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  20758. linePositions = walkerFn(editor.getBody(), isAboveLine(1), caretPosition);
  20759. nextLinePositions = filter(linePositions, isLine(1));
  20760. caretClientRect = ArrUtils.last(caretPosition.getClientRects());
  20761. if (isBeforeContentEditableFalse(caretPosition) || isBeforeTable(caretPosition)) {
  20762. contentEditableFalseNode = caretPosition.getNode();
  20763. }
  20764. if (isAfterContentEditableFalse(caretPosition) || isAfterTable(caretPosition)) {
  20765. contentEditableFalseNode = caretPosition.getNode(true);
  20766. }
  20767. if (!caretClientRect) {
  20768. return null;
  20769. }
  20770. clientX = caretClientRect.left;
  20771. closestNextLineRect = findClosestClientRect(nextLinePositions, clientX);
  20772. if (closestNextLineRect) {
  20773. if (isContentEditableFalse$b(closestNextLineRect.node)) {
  20774. dist1 = Math.abs(clientX - closestNextLineRect.left);
  20775. dist2 = Math.abs(clientX - closestNextLineRect.right);
  20776. return showCaret(direction, editor, closestNextLineRect.node, dist1 < dist2, true);
  20777. }
  20778. }
  20779. if (contentEditableFalseNode) {
  20780. var caretPositions = positionsUntil(direction, editor.getBody(), isAboveLine(1), contentEditableFalseNode);
  20781. closestNextLineRect = findClosestClientRect(filter(caretPositions, isLine(1)), clientX);
  20782. if (closestNextLineRect) {
  20783. return renderRangeCaret(editor, closestNextLineRect.position.toRange(), true);
  20784. }
  20785. closestNextLineRect = ArrUtils.last(filter(caretPositions, isLine(0)));
  20786. if (closestNextLineRect) {
  20787. return renderRangeCaret(editor, closestNextLineRect.position.toRange(), true);
  20788. }
  20789. }
  20790. };
  20791. var createTextBlock = function (editor) {
  20792. var textBlock = editor.dom.create(Settings.getForcedRootBlock(editor));
  20793. if (!Env.ie || Env.ie >= 11) {
  20794. textBlock.innerHTML = '<br data-mce-bogus="1">';
  20795. }
  20796. return textBlock;
  20797. };
  20798. var exitPreBlock = function (editor, direction, range) {
  20799. var pre, caretPos, newBlock;
  20800. var caretWalker = CaretWalker(editor.getBody());
  20801. var getNextVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.next);
  20802. var getPrevVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.prev);
  20803. if (range.collapsed && editor.settings.forced_root_block) {
  20804. pre = editor.dom.getParent(range.startContainer, 'PRE');
  20805. if (!pre) {
  20806. return;
  20807. }
  20808. if (direction === 1) {
  20809. caretPos = getNextVisualCaretPosition(CaretPosition$1.fromRangeStart(range));
  20810. } else {
  20811. caretPos = getPrevVisualCaretPosition(CaretPosition$1.fromRangeStart(range));
  20812. }
  20813. if (!caretPos) {
  20814. newBlock = createTextBlock(editor);
  20815. if (direction === 1) {
  20816. editor.$(pre).after(newBlock);
  20817. } else {
  20818. editor.$(pre).before(newBlock);
  20819. }
  20820. editor.selection.select(newBlock, true);
  20821. editor.selection.collapse();
  20822. }
  20823. }
  20824. };
  20825. var getHorizontalRange = function (editor, forward) {
  20826. var caretWalker = CaretWalker(editor.getBody());
  20827. var getNextVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.next);
  20828. var getPrevVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.prev);
  20829. var newRange;
  20830. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  20831. var getNextPosFn = forward ? getNextVisualCaretPosition : getPrevVisualCaretPosition;
  20832. var range = editor.selection.getRng();
  20833. newRange = moveToCeFalseHorizontally(direction, editor, getNextPosFn, range);
  20834. if (newRange) {
  20835. return newRange;
  20836. }
  20837. newRange = exitPreBlock(editor, direction, range);
  20838. if (newRange) {
  20839. return newRange;
  20840. }
  20841. return null;
  20842. };
  20843. var getVerticalRange = function (editor, down) {
  20844. var newRange;
  20845. var direction = down ? 1 : -1;
  20846. var walkerFn = down ? downUntil : upUntil;
  20847. var range = editor.selection.getRng();
  20848. newRange = moveToCeFalseVertically(direction, editor, walkerFn, range);
  20849. if (newRange) {
  20850. return newRange;
  20851. }
  20852. newRange = exitPreBlock(editor, direction, range);
  20853. if (newRange) {
  20854. return newRange;
  20855. }
  20856. return null;
  20857. };
  20858. var moveH = function (editor, forward) {
  20859. return function () {
  20860. var newRng = getHorizontalRange(editor, forward);
  20861. if (newRng) {
  20862. editor.selection.setRng(newRng);
  20863. return true;
  20864. } else {
  20865. return false;
  20866. }
  20867. };
  20868. };
  20869. var moveV = function (editor, down) {
  20870. return function () {
  20871. var newRng = getVerticalRange(editor, down);
  20872. if (newRng) {
  20873. editor.selection.setRng(newRng);
  20874. return true;
  20875. } else {
  20876. return false;
  20877. }
  20878. };
  20879. };
  20880. var isCefPosition = function (forward) {
  20881. return function (pos) {
  20882. return forward ? isAfterContentEditableFalse(pos) : isBeforeContentEditableFalse(pos);
  20883. };
  20884. };
  20885. var moveToLineEndPoint = function (editor, forward) {
  20886. return function () {
  20887. var from = forward ? CaretPosition$1.fromRangeEnd(editor.selection.getRng()) : CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20888. var result = forward ? getPositionsUntilNextLine(editor.getBody(), from) : getPositionsUntilPreviousLine(editor.getBody(), from);
  20889. var to = forward ? last(result.positions) : head(result.positions);
  20890. return to.filter(isCefPosition(forward)).fold(constant(false), function (pos) {
  20891. editor.selection.setRng(pos.toRange());
  20892. return true;
  20893. });
  20894. };
  20895. };
  20896. var deflate = function (rect, delta) {
  20897. return {
  20898. left: rect.left - delta,
  20899. top: rect.top - delta,
  20900. right: rect.right + delta * 2,
  20901. bottom: rect.bottom + delta * 2,
  20902. width: rect.width + delta,
  20903. height: rect.height + delta
  20904. };
  20905. };
  20906. var getCorners = function (getYAxisValue, tds) {
  20907. return bind(tds, function (td) {
  20908. var rect = deflate(clone$1(td.getBoundingClientRect()), -1);
  20909. return [
  20910. {
  20911. x: rect.left,
  20912. y: getYAxisValue(rect),
  20913. cell: td
  20914. },
  20915. {
  20916. x: rect.right,
  20917. y: getYAxisValue(rect),
  20918. cell: td
  20919. }
  20920. ];
  20921. });
  20922. };
  20923. var findClosestCorner = function (corners, x, y) {
  20924. return foldl(corners, function (acc, newCorner) {
  20925. return acc.fold(function () {
  20926. return Option.some(newCorner);
  20927. }, function (oldCorner) {
  20928. var oldDist = Math.sqrt(Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y));
  20929. var newDist = Math.sqrt(Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y));
  20930. return Option.some(newDist < oldDist ? newCorner : oldCorner);
  20931. });
  20932. }, Option.none());
  20933. };
  20934. var getClosestCell = function (getYAxisValue, isTargetCorner, table, x, y) {
  20935. var cells = descendants$1(Element.fromDom(table), 'td,th,caption').map(function (e) {
  20936. return e.dom();
  20937. });
  20938. var corners = filter(getCorners(getYAxisValue, cells), function (corner) {
  20939. return isTargetCorner(corner, y);
  20940. });
  20941. return findClosestCorner(corners, x, y).map(function (corner) {
  20942. return corner.cell;
  20943. });
  20944. };
  20945. var getBottomValue = function (rect) {
  20946. return rect.bottom;
  20947. };
  20948. var getTopValue = function (rect) {
  20949. return rect.top;
  20950. };
  20951. var isAbove$1 = function (corner, y) {
  20952. return corner.y < y;
  20953. };
  20954. var isBelow$1 = function (corner, y) {
  20955. return corner.y > y;
  20956. };
  20957. var getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove$1);
  20958. var getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow$1);
  20959. var findClosestPositionInAboveCell = function (table, pos) {
  20960. return head(pos.getClientRects()).bind(function (rect) {
  20961. return getClosestCellAbove(table, rect.left, rect.top);
  20962. }).bind(function (cell) {
  20963. return findClosestHorizontalPosition(getLastLinePositions(cell), pos);
  20964. });
  20965. };
  20966. var findClosestPositionInBelowCell = function (table, pos) {
  20967. return last(pos.getClientRects()).bind(function (rect) {
  20968. return getClosestCellBelow(table, rect.left, rect.top);
  20969. }).bind(function (cell) {
  20970. return findClosestHorizontalPosition(getFirstLinePositions(cell), pos);
  20971. });
  20972. };
  20973. var moveToRange = function (editor, rng) {
  20974. editor.selection.setRng(rng);
  20975. ScrollIntoView.scrollRangeIntoView(editor, rng);
  20976. };
  20977. var hasNextBreak = function (getPositionsUntil, scope, lineInfo) {
  20978. return lineInfo.breakAt.map(function (breakPos) {
  20979. return getPositionsUntil(scope, breakPos).breakAt.isSome();
  20980. }).getOr(false);
  20981. };
  20982. var startsWithWrapBreak = function (lineInfo) {
  20983. return lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0;
  20984. };
  20985. var startsWithBrBreak = function (lineInfo) {
  20986. return lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1;
  20987. };
  20988. var isAtTableCellLine = function (getPositionsUntil, scope, pos) {
  20989. var lineInfo = getPositionsUntil(scope, pos);
  20990. if (startsWithWrapBreak(lineInfo) || !NodeType.isBr(pos.getNode()) && startsWithBrBreak(lineInfo)) {
  20991. return !hasNextBreak(getPositionsUntil, scope, lineInfo);
  20992. } else {
  20993. return lineInfo.breakAt.isNone();
  20994. }
  20995. };
  20996. var isAtFirstTableCellLine = curry(isAtTableCellLine, getPositionsUntilPreviousLine);
  20997. var isAtLastTableCellLine = curry(isAtTableCellLine, getPositionsUntilNextLine);
  20998. var isCaretAtStartOrEndOfTable = function (forward, rng, table) {
  20999. var caretPos = CaretPosition$1.fromRangeStart(rng);
  21000. return CaretFinder.positionIn(!forward, table).map(function (pos) {
  21001. return pos.isEqual(caretPos);
  21002. }).getOr(false);
  21003. };
  21004. var navigateHorizontally = function (editor, forward, table, td) {
  21005. var rng = editor.selection.getRng();
  21006. var direction = forward ? 1 : -1;
  21007. if (isFakeCaretTableBrowser() && isCaretAtStartOrEndOfTable(forward, rng, table)) {
  21008. var newRng = showCaret(direction, editor, table, !forward, true);
  21009. moveToRange(editor, newRng);
  21010. return true;
  21011. }
  21012. return false;
  21013. };
  21014. var getClosestAbovePosition = function (root, table, start) {
  21015. return findClosestPositionInAboveCell(table, start).orThunk(function () {
  21016. return head(start.getClientRects()).bind(function (rect) {
  21017. return findClosestHorizontalPositionFromPoint(getPositionsAbove(root, CaretPosition$1.before(table)), rect.left);
  21018. });
  21019. }).getOr(CaretPosition$1.before(table));
  21020. };
  21021. var getClosestBelowPosition = function (root, table, start) {
  21022. return findClosestPositionInBelowCell(table, start).orThunk(function () {
  21023. return head(start.getClientRects()).bind(function (rect) {
  21024. return findClosestHorizontalPositionFromPoint(getPositionsBelow(root, CaretPosition$1.after(table)), rect.left);
  21025. });
  21026. }).getOr(CaretPosition$1.after(table));
  21027. };
  21028. var getTable = function (previous, pos) {
  21029. var node = pos.getNode(previous);
  21030. return NodeType.isElement(node) && node.nodeName === 'TABLE' ? Option.some(node) : Option.none();
  21031. };
  21032. var renderBlock = function (down, editor, table, pos) {
  21033. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  21034. if (forcedRootBlock) {
  21035. editor.undoManager.transact(function () {
  21036. var element = Element.fromTag(forcedRootBlock);
  21037. setAll(element, Settings.getForcedRootBlockAttrs(editor));
  21038. append(element, Element.fromTag('br'));
  21039. if (down) {
  21040. after(Element.fromDom(table), element);
  21041. } else {
  21042. before(Element.fromDom(table), element);
  21043. }
  21044. var rng = editor.dom.createRng();
  21045. rng.setStart(element.dom(), 0);
  21046. rng.setEnd(element.dom(), 0);
  21047. moveToRange(editor, rng);
  21048. });
  21049. } else {
  21050. moveToRange(editor, pos.toRange());
  21051. }
  21052. };
  21053. var moveCaret = function (editor, down, pos) {
  21054. var table = down ? getTable(true, pos) : getTable(false, pos);
  21055. var last = down === false;
  21056. table.fold(function () {
  21057. return moveToRange(editor, pos.toRange());
  21058. }, function (table) {
  21059. return CaretFinder.positionIn(last, editor.getBody()).filter(function (lastPos) {
  21060. return lastPos.isEqual(pos);
  21061. }).fold(function () {
  21062. return moveToRange(editor, pos.toRange());
  21063. }, function (_) {
  21064. return renderBlock(down, editor, table, pos);
  21065. });
  21066. });
  21067. };
  21068. var navigateVertically = function (editor, down, table, td) {
  21069. var rng = editor.selection.getRng();
  21070. var pos = CaretPosition$1.fromRangeStart(rng);
  21071. var root = editor.getBody();
  21072. if (!down && isAtFirstTableCellLine(td, pos)) {
  21073. var newPos = getClosestAbovePosition(root, table, pos);
  21074. moveCaret(editor, down, newPos);
  21075. return true;
  21076. } else if (down && isAtLastTableCellLine(td, pos)) {
  21077. var newPos = getClosestBelowPosition(root, table, pos);
  21078. moveCaret(editor, down, newPos);
  21079. return true;
  21080. } else {
  21081. return false;
  21082. }
  21083. };
  21084. var moveH$1 = function (editor, forward) {
  21085. return function () {
  21086. return Option.from(editor.dom.getParent(editor.selection.getNode(), 'td,th')).bind(function (td) {
  21087. return Option.from(editor.dom.getParent(td, 'table')).map(function (table) {
  21088. return navigateHorizontally(editor, forward, table);
  21089. });
  21090. }).getOr(false);
  21091. };
  21092. };
  21093. var moveV$1 = function (editor, forward) {
  21094. return function () {
  21095. return Option.from(editor.dom.getParent(editor.selection.getNode(), 'td,th')).bind(function (td) {
  21096. return Option.from(editor.dom.getParent(td, 'table')).map(function (table) {
  21097. return navigateVertically(editor, forward, table, td);
  21098. });
  21099. }).getOr(false);
  21100. };
  21101. };
  21102. var isTarget = function (node) {
  21103. return contains(['figcaption'], name(node));
  21104. };
  21105. var rangeBefore = function (target) {
  21106. var rng = domGlobals.document.createRange();
  21107. rng.setStartBefore(target.dom());
  21108. rng.setEndBefore(target.dom());
  21109. return rng;
  21110. };
  21111. var insertElement = function (root, elm, forward) {
  21112. if (forward) {
  21113. append(root, elm);
  21114. } else {
  21115. prepend(root, elm);
  21116. }
  21117. };
  21118. var insertBr = function (root, forward) {
  21119. var br = Element.fromTag('br');
  21120. insertElement(root, br, forward);
  21121. return rangeBefore(br);
  21122. };
  21123. var insertBlock$1 = function (root, forward, blockName, attrs) {
  21124. var block = Element.fromTag(blockName);
  21125. var br = Element.fromTag('br');
  21126. setAll(block, attrs);
  21127. append(block, br);
  21128. insertElement(root, block, forward);
  21129. return rangeBefore(br);
  21130. };
  21131. var insertEmptyLine = function (root, rootBlockName, attrs, forward) {
  21132. if (rootBlockName === '') {
  21133. return insertBr(root, forward);
  21134. } else {
  21135. return insertBlock$1(root, forward, rootBlockName, attrs);
  21136. }
  21137. };
  21138. var getClosestTargetBlock = function (pos, root) {
  21139. var isRoot = curry(eq, root);
  21140. return closest(Element.fromDom(pos.container()), isBlock, isRoot).filter(isTarget);
  21141. };
  21142. var isAtFirstOrLastLine = function (root, forward, pos) {
  21143. return forward ? isAtLastLine(root.dom(), pos) : isAtFirstLine(root.dom(), pos);
  21144. };
  21145. var moveCaretToNewEmptyLine = function (editor, forward) {
  21146. var root = Element.fromDom(editor.getBody());
  21147. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  21148. var rootBlock = Settings.getForcedRootBlock(editor);
  21149. var rootBlockAttrs = Settings.getForcedRootBlockAttrs(editor);
  21150. return getClosestTargetBlock(pos, root).exists(function () {
  21151. if (isAtFirstOrLastLine(root, forward, pos)) {
  21152. var rng = insertEmptyLine(root, rootBlock, rootBlockAttrs, forward);
  21153. editor.selection.setRng(rng);
  21154. return true;
  21155. } else {
  21156. return false;
  21157. }
  21158. });
  21159. };
  21160. var moveV$2 = function (editor, forward) {
  21161. return function () {
  21162. if (editor.selection.isCollapsed()) {
  21163. return moveCaretToNewEmptyLine(editor, forward);
  21164. } else {
  21165. return false;
  21166. }
  21167. };
  21168. };
  21169. var defaultPatterns = function (patterns) {
  21170. return map(patterns, function (pattern) {
  21171. return merge({
  21172. shiftKey: false,
  21173. altKey: false,
  21174. ctrlKey: false,
  21175. metaKey: false,
  21176. keyCode: 0,
  21177. action: noop
  21178. }, pattern);
  21179. });
  21180. };
  21181. var matchesEvent = function (pattern, evt) {
  21182. return evt.keyCode === pattern.keyCode && evt.shiftKey === pattern.shiftKey && evt.altKey === pattern.altKey && evt.ctrlKey === pattern.ctrlKey && evt.metaKey === pattern.metaKey;
  21183. };
  21184. var match$1 = function (patterns, evt) {
  21185. return bind(defaultPatterns(patterns), function (pattern) {
  21186. return matchesEvent(pattern, evt) ? [pattern] : [];
  21187. });
  21188. };
  21189. var action = function (f) {
  21190. var x = [];
  21191. for (var _i = 1; _i < arguments.length; _i++) {
  21192. x[_i - 1] = arguments[_i];
  21193. }
  21194. var args = Array.prototype.slice.call(arguments, 1);
  21195. return function () {
  21196. return f.apply(null, args);
  21197. };
  21198. };
  21199. var execute = function (patterns, evt) {
  21200. return find(match$1(patterns, evt), function (pattern) {
  21201. return pattern.action();
  21202. });
  21203. };
  21204. var MatchKeys = {
  21205. match: match$1,
  21206. action: action,
  21207. execute: execute
  21208. };
  21209. var executeKeydownOverride = function (editor, caret, evt) {
  21210. var os = detect$3().os;
  21211. MatchKeys.execute([
  21212. {
  21213. keyCode: VK.RIGHT,
  21214. action: moveH(editor, true)
  21215. },
  21216. {
  21217. keyCode: VK.LEFT,
  21218. action: moveH(editor, false)
  21219. },
  21220. {
  21221. keyCode: VK.UP,
  21222. action: moveV(editor, false)
  21223. },
  21224. {
  21225. keyCode: VK.DOWN,
  21226. action: moveV(editor, true)
  21227. },
  21228. {
  21229. keyCode: VK.RIGHT,
  21230. action: moveH$1(editor, true)
  21231. },
  21232. {
  21233. keyCode: VK.LEFT,
  21234. action: moveH$1(editor, false)
  21235. },
  21236. {
  21237. keyCode: VK.UP,
  21238. action: moveV$1(editor, false)
  21239. },
  21240. {
  21241. keyCode: VK.DOWN,
  21242. action: moveV$1(editor, true)
  21243. },
  21244. {
  21245. keyCode: VK.RIGHT,
  21246. action: BoundarySelection.move(editor, caret, true)
  21247. },
  21248. {
  21249. keyCode: VK.LEFT,
  21250. action: BoundarySelection.move(editor, caret, false)
  21251. },
  21252. {
  21253. keyCode: VK.RIGHT,
  21254. ctrlKey: !os.isOSX(),
  21255. altKey: os.isOSX(),
  21256. action: BoundarySelection.moveNextWord(editor, caret)
  21257. },
  21258. {
  21259. keyCode: VK.LEFT,
  21260. ctrlKey: !os.isOSX(),
  21261. altKey: os.isOSX(),
  21262. action: BoundarySelection.movePrevWord(editor, caret)
  21263. },
  21264. {
  21265. keyCode: VK.UP,
  21266. action: moveV$2(editor, false)
  21267. },
  21268. {
  21269. keyCode: VK.DOWN,
  21270. action: moveV$2(editor, true)
  21271. }
  21272. ], evt).each(function (_) {
  21273. evt.preventDefault();
  21274. });
  21275. };
  21276. var setup$8 = function (editor, caret) {
  21277. editor.on('keydown', function (evt) {
  21278. if (evt.isDefaultPrevented() === false) {
  21279. executeKeydownOverride(editor, caret, evt);
  21280. }
  21281. });
  21282. };
  21283. var ArrowKeys = { setup: setup$8 };
  21284. var isBeforeRoot = function (rootNode) {
  21285. return function (elm) {
  21286. return eq(rootNode, Element.fromDom(elm.dom().parentNode));
  21287. };
  21288. };
  21289. var getParentBlock$1 = function (rootNode, elm) {
  21290. return contains$2(rootNode, elm) ? closest(elm, function (element) {
  21291. return isTextBlock(element) || isListItem(element);
  21292. }, isBeforeRoot(rootNode)) : Option.none();
  21293. };
  21294. var placeCaretInEmptyBody = function (editor) {
  21295. var body = editor.getBody();
  21296. var node = body.firstChild && editor.dom.isBlock(body.firstChild) ? body.firstChild : body;
  21297. editor.selection.setCursorLocation(node, 0);
  21298. };
  21299. var paddEmptyBody = function (editor) {
  21300. if (editor.dom.isEmpty(editor.getBody())) {
  21301. editor.setContent('');
  21302. placeCaretInEmptyBody(editor);
  21303. }
  21304. };
  21305. var willDeleteLastPositionInElement = function (forward, fromPos, elm) {
  21306. return lift2(CaretFinder.firstPositionIn(elm), CaretFinder.lastPositionIn(elm), function (firstPos, lastPos) {
  21307. var normalizedFirstPos = InlineUtils.normalizePosition(true, firstPos);
  21308. var normalizedLastPos = InlineUtils.normalizePosition(false, lastPos);
  21309. var normalizedFromPos = InlineUtils.normalizePosition(false, fromPos);
  21310. if (forward) {
  21311. return CaretFinder.nextPosition(elm, normalizedFromPos).map(function (nextPos) {
  21312. return nextPos.isEqual(normalizedLastPos) && fromPos.isEqual(normalizedFirstPos);
  21313. }).getOr(false);
  21314. } else {
  21315. return CaretFinder.prevPosition(elm, normalizedFromPos).map(function (prevPos) {
  21316. return prevPos.isEqual(normalizedFirstPos) && fromPos.isEqual(normalizedLastPos);
  21317. }).getOr(false);
  21318. }
  21319. }).getOr(true);
  21320. };
  21321. var DeleteUtils = {
  21322. getParentBlock: getParentBlock$1,
  21323. paddEmptyBody: paddEmptyBody,
  21324. willDeleteLastPositionInElement: willDeleteLastPositionInElement
  21325. };
  21326. var blockPosition = function (block, position) {
  21327. return {
  21328. block: constant(block),
  21329. position: constant(position)
  21330. };
  21331. };
  21332. var blockBoundary = function (from, to) {
  21333. return {
  21334. from: constant(from),
  21335. to: constant(to)
  21336. };
  21337. };
  21338. var getBlockPosition = function (rootNode, pos) {
  21339. var rootElm = Element.fromDom(rootNode);
  21340. var containerElm = Element.fromDom(pos.container());
  21341. return DeleteUtils.getParentBlock(rootElm, containerElm).map(function (block) {
  21342. return blockPosition(block, pos);
  21343. });
  21344. };
  21345. var isDifferentBlocks = function (blockBoundary) {
  21346. return eq(blockBoundary.from().block(), blockBoundary.to().block()) === false;
  21347. };
  21348. var hasSameParent = function (blockBoundary) {
  21349. return parent(blockBoundary.from().block()).bind(function (parent1) {
  21350. return parent(blockBoundary.to().block()).filter(function (parent2) {
  21351. return eq(parent1, parent2);
  21352. });
  21353. }).isSome();
  21354. };
  21355. var isEditable = function (blockBoundary) {
  21356. return NodeType.isContentEditableFalse(blockBoundary.from().block().dom()) === false && NodeType.isContentEditableFalse(blockBoundary.to().block().dom()) === false;
  21357. };
  21358. var skipLastBr = function (rootNode, forward, blockPosition) {
  21359. if (NodeType.isBr(blockPosition.position().getNode()) && Empty.isEmpty(blockPosition.block()) === false) {
  21360. return CaretFinder.positionIn(false, blockPosition.block().dom()).bind(function (lastPositionInBlock) {
  21361. if (lastPositionInBlock.isEqual(blockPosition.position())) {
  21362. return CaretFinder.fromPosition(forward, rootNode, lastPositionInBlock).bind(function (to) {
  21363. return getBlockPosition(rootNode, to);
  21364. });
  21365. } else {
  21366. return Option.some(blockPosition);
  21367. }
  21368. }).getOr(blockPosition);
  21369. } else {
  21370. return blockPosition;
  21371. }
  21372. };
  21373. var readFromRange = function (rootNode, forward, rng) {
  21374. var fromBlockPos = getBlockPosition(rootNode, CaretPosition$1.fromRangeStart(rng));
  21375. var toBlockPos = fromBlockPos.bind(function (blockPos) {
  21376. return CaretFinder.fromPosition(forward, rootNode, blockPos.position()).bind(function (to) {
  21377. return getBlockPosition(rootNode, to).map(function (blockPos) {
  21378. return skipLastBr(rootNode, forward, blockPos);
  21379. });
  21380. });
  21381. });
  21382. return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(function (blockBoundary) {
  21383. return isDifferentBlocks(blockBoundary) && hasSameParent(blockBoundary) && isEditable(blockBoundary);
  21384. });
  21385. };
  21386. var read$3 = function (rootNode, forward, rng) {
  21387. return rng.collapsed ? readFromRange(rootNode, forward, rng) : Option.none();
  21388. };
  21389. var BlockMergeBoundary = { read: read$3 };
  21390. var getChildrenUntilBlockBoundary = function (block) {
  21391. var children$1 = children(block);
  21392. return findIndex(children$1, isBlock).fold(function () {
  21393. return children$1;
  21394. }, function (index) {
  21395. return children$1.slice(0, index);
  21396. });
  21397. };
  21398. var extractChildren = function (block) {
  21399. var children = getChildrenUntilBlockBoundary(block);
  21400. each(children, remove$1);
  21401. return children;
  21402. };
  21403. var removeEmptyRoot = function (rootNode, block) {
  21404. var parents = Parents.parentsAndSelf(block, rootNode);
  21405. return find(parents.reverse(), Empty.isEmpty).each(remove$1);
  21406. };
  21407. var isEmptyBefore = function (el) {
  21408. return filter(prevSiblings(el), function (el) {
  21409. return !Empty.isEmpty(el);
  21410. }).length === 0;
  21411. };
  21412. var nestedBlockMerge = function (rootNode, fromBlock, toBlock, insertionPoint) {
  21413. if (Empty.isEmpty(toBlock)) {
  21414. PaddingBr.fillWithPaddingBr(toBlock);
  21415. return CaretFinder.firstPositionIn(toBlock.dom());
  21416. }
  21417. if (isEmptyBefore(insertionPoint) && Empty.isEmpty(fromBlock)) {
  21418. before(insertionPoint, Element.fromTag('br'));
  21419. }
  21420. var position = CaretFinder.prevPosition(toBlock.dom(), CaretPosition$1.before(insertionPoint.dom()));
  21421. each(extractChildren(fromBlock), function (child) {
  21422. before(insertionPoint, child);
  21423. });
  21424. removeEmptyRoot(rootNode, fromBlock);
  21425. return position;
  21426. };
  21427. var sidelongBlockMerge = function (rootNode, fromBlock, toBlock) {
  21428. if (Empty.isEmpty(toBlock)) {
  21429. remove$1(toBlock);
  21430. if (Empty.isEmpty(fromBlock)) {
  21431. PaddingBr.fillWithPaddingBr(fromBlock);
  21432. }
  21433. return CaretFinder.firstPositionIn(fromBlock.dom());
  21434. }
  21435. var position = CaretFinder.lastPositionIn(toBlock.dom());
  21436. each(extractChildren(fromBlock), function (child) {
  21437. append(toBlock, child);
  21438. });
  21439. removeEmptyRoot(rootNode, fromBlock);
  21440. return position;
  21441. };
  21442. var findInsertionPoint = function (toBlock, block) {
  21443. var parentsAndSelf = Parents.parentsAndSelf(block, toBlock);
  21444. return Option.from(parentsAndSelf[parentsAndSelf.length - 1]);
  21445. };
  21446. var getInsertionPoint = function (fromBlock, toBlock) {
  21447. return contains$2(toBlock, fromBlock) ? findInsertionPoint(toBlock, fromBlock) : Option.none();
  21448. };
  21449. var trimBr = function (first, block) {
  21450. CaretFinder.positionIn(first, block.dom()).map(function (position) {
  21451. return position.getNode();
  21452. }).map(Element.fromDom).filter(isBr$1).each(remove$1);
  21453. };
  21454. var mergeBlockInto = function (rootNode, fromBlock, toBlock) {
  21455. trimBr(true, fromBlock);
  21456. trimBr(false, toBlock);
  21457. return getInsertionPoint(fromBlock, toBlock).fold(curry(sidelongBlockMerge, rootNode, fromBlock, toBlock), curry(nestedBlockMerge, rootNode, fromBlock, toBlock));
  21458. };
  21459. var mergeBlocks = function (rootNode, forward, block1, block2) {
  21460. return forward ? mergeBlockInto(rootNode, block2, block1) : mergeBlockInto(rootNode, block1, block2);
  21461. };
  21462. var MergeBlocks = { mergeBlocks: mergeBlocks };
  21463. var backspaceDelete = function (editor, forward) {
  21464. var rootNode = Element.fromDom(editor.getBody());
  21465. var position = BlockMergeBoundary.read(rootNode.dom(), forward, editor.selection.getRng()).bind(function (blockBoundary) {
  21466. return MergeBlocks.mergeBlocks(rootNode, forward, blockBoundary.from().block(), blockBoundary.to().block());
  21467. });
  21468. position.each(function (pos) {
  21469. editor.selection.setRng(pos.toRange());
  21470. });
  21471. return position.isSome();
  21472. };
  21473. var BlockBoundaryDelete = { backspaceDelete: backspaceDelete };
  21474. var deleteRangeMergeBlocks = function (rootNode, selection) {
  21475. var rng = selection.getRng();
  21476. return lift2(DeleteUtils.getParentBlock(rootNode, Element.fromDom(rng.startContainer)), DeleteUtils.getParentBlock(rootNode, Element.fromDom(rng.endContainer)), function (block1, block2) {
  21477. if (eq(block1, block2) === false) {
  21478. rng.deleteContents();
  21479. MergeBlocks.mergeBlocks(rootNode, true, block1, block2).each(function (pos) {
  21480. selection.setRng(pos.toRange());
  21481. });
  21482. return true;
  21483. } else {
  21484. return false;
  21485. }
  21486. }).getOr(false);
  21487. };
  21488. var isRawNodeInTable = function (root, rawNode) {
  21489. var node = Element.fromDom(rawNode);
  21490. var isRoot = curry(eq, root);
  21491. return ancestor(node, isTableCell, isRoot).isSome();
  21492. };
  21493. var isSelectionInTable = function (root, rng) {
  21494. return isRawNodeInTable(root, rng.startContainer) || isRawNodeInTable(root, rng.endContainer);
  21495. };
  21496. var isEverythingSelected = function (root, rng) {
  21497. var noPrevious = CaretFinder.prevPosition(root.dom(), CaretPosition$1.fromRangeStart(rng)).isNone();
  21498. var noNext = CaretFinder.nextPosition(root.dom(), CaretPosition$1.fromRangeEnd(rng)).isNone();
  21499. return !isSelectionInTable(root, rng) && noPrevious && noNext;
  21500. };
  21501. var emptyEditor = function (editor) {
  21502. editor.setContent('');
  21503. editor.selection.setCursorLocation();
  21504. return true;
  21505. };
  21506. var deleteRange = function (editor) {
  21507. var rootNode = Element.fromDom(editor.getBody());
  21508. var rng = editor.selection.getRng();
  21509. return isEverythingSelected(rootNode, rng) ? emptyEditor(editor) : deleteRangeMergeBlocks(rootNode, editor.selection);
  21510. };
  21511. var backspaceDelete$1 = function (editor, forward) {
  21512. return editor.selection.isCollapsed() ? false : deleteRange(editor);
  21513. };
  21514. var BlockRangeDelete = { backspaceDelete: backspaceDelete$1 };
  21515. var isBr$5 = function (pos) {
  21516. return getElementFromPosition(pos).exists(isBr$1);
  21517. };
  21518. var findBr = function (forward, root, pos) {
  21519. var parentBlocks = filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), isBlock);
  21520. var scope = head(parentBlocks).getOr(root);
  21521. return CaretFinder.fromPosition(forward, scope.dom(), pos).filter(isBr$5);
  21522. };
  21523. var isBeforeBr = function (root, pos) {
  21524. return getElementFromPosition(pos).exists(isBr$1) || findBr(true, root, pos).isSome();
  21525. };
  21526. var isAfterBr = function (root, pos) {
  21527. return getElementFromPrevPosition(pos).exists(isBr$1) || findBr(false, root, pos).isSome();
  21528. };
  21529. var findPreviousBr = curry(findBr, false);
  21530. var findNextBr = curry(findBr, true);
  21531. var isCompoundElement = function (node) {
  21532. return isTableCell(Element.fromDom(node)) || isListItem(Element.fromDom(node));
  21533. };
  21534. var DeleteAction = Adt.generate([
  21535. { remove: ['element'] },
  21536. { moveToElement: ['element'] },
  21537. { moveToPosition: ['position'] }
  21538. ]);
  21539. var isAtContentEditableBlockCaret = function (forward, from) {
  21540. var elm = from.getNode(forward === false);
  21541. var caretLocation = forward ? 'after' : 'before';
  21542. return NodeType.isElement(elm) && elm.getAttribute('data-mce-caret') === caretLocation;
  21543. };
  21544. var isDeleteFromCefDifferentBlocks = function (root, forward, from, to) {
  21545. var inSameBlock = function (elm) {
  21546. return isInline(Element.fromDom(elm)) && !isInSameBlock(from, to, root);
  21547. };
  21548. return getRelativeCefElm(!forward, from).fold(function () {
  21549. return getRelativeCefElm(forward, to).fold(constant(false), inSameBlock);
  21550. }, inSameBlock);
  21551. };
  21552. var deleteEmptyBlockOrMoveToCef = function (root, forward, from, to) {
  21553. var toCefElm = to.getNode(forward === false);
  21554. return DeleteUtils.getParentBlock(Element.fromDom(root), Element.fromDom(from.getNode())).map(function (blockElm) {
  21555. return Empty.isEmpty(blockElm) ? DeleteAction.remove(blockElm.dom()) : DeleteAction.moveToElement(toCefElm);
  21556. }).orThunk(function () {
  21557. return Option.some(DeleteAction.moveToElement(toCefElm));
  21558. });
  21559. };
  21560. var findCefPosition = function (root, forward, from) {
  21561. return CaretFinder.fromPosition(forward, root, from).bind(function (to) {
  21562. if (isCompoundElement(to.getNode())) {
  21563. return Option.none();
  21564. } else if (isDeleteFromCefDifferentBlocks(root, forward, from, to)) {
  21565. return Option.none();
  21566. } else if (forward && NodeType.isContentEditableFalse(to.getNode())) {
  21567. return deleteEmptyBlockOrMoveToCef(root, forward, from, to);
  21568. } else if (forward === false && NodeType.isContentEditableFalse(to.getNode(true))) {
  21569. return deleteEmptyBlockOrMoveToCef(root, forward, from, to);
  21570. } else if (forward && isAfterContentEditableFalse(from)) {
  21571. return Option.some(DeleteAction.moveToPosition(to));
  21572. } else if (forward === false && isBeforeContentEditableFalse(from)) {
  21573. return Option.some(DeleteAction.moveToPosition(to));
  21574. } else {
  21575. return Option.none();
  21576. }
  21577. });
  21578. };
  21579. var getContentEditableBlockAction = function (forward, elm) {
  21580. if (forward && NodeType.isContentEditableFalse(elm.nextSibling)) {
  21581. return Option.some(DeleteAction.moveToElement(elm.nextSibling));
  21582. } else if (forward === false && NodeType.isContentEditableFalse(elm.previousSibling)) {
  21583. return Option.some(DeleteAction.moveToElement(elm.previousSibling));
  21584. } else {
  21585. return Option.none();
  21586. }
  21587. };
  21588. var skipMoveToActionFromInlineCefToContent = function (root, from, deleteAction) {
  21589. return deleteAction.fold(function (elm) {
  21590. return Option.some(DeleteAction.remove(elm));
  21591. }, function (elm) {
  21592. return Option.some(DeleteAction.moveToElement(elm));
  21593. }, function (to) {
  21594. if (isInSameBlock(from, to, root)) {
  21595. return Option.none();
  21596. } else {
  21597. return Option.some(DeleteAction.moveToPosition(to));
  21598. }
  21599. });
  21600. };
  21601. var getContentEditableAction = function (root, forward, from) {
  21602. if (isAtContentEditableBlockCaret(forward, from)) {
  21603. return getContentEditableBlockAction(forward, from.getNode(forward === false)).fold(function () {
  21604. return findCefPosition(root, forward, from);
  21605. }, Option.some);
  21606. } else {
  21607. return findCefPosition(root, forward, from).bind(function (deleteAction) {
  21608. return skipMoveToActionFromInlineCefToContent(root, from, deleteAction);
  21609. });
  21610. }
  21611. };
  21612. var read$4 = function (root, forward, rng) {
  21613. var normalizedRange = normalizeRange(forward ? 1 : -1, root, rng);
  21614. var from = CaretPosition$1.fromRangeStart(normalizedRange);
  21615. var rootElement = Element.fromDom(root);
  21616. if (forward === false && isAfterContentEditableFalse(from)) {
  21617. return Option.some(DeleteAction.remove(from.getNode(true)));
  21618. } else if (forward && isBeforeContentEditableFalse(from)) {
  21619. return Option.some(DeleteAction.remove(from.getNode()));
  21620. } else if (forward === false && isBeforeContentEditableFalse(from) && isAfterBr(rootElement, from)) {
  21621. return findPreviousBr(rootElement, from).map(function (br) {
  21622. return DeleteAction.remove(br.getNode());
  21623. });
  21624. } else if (forward && isAfterContentEditableFalse(from) && isBeforeBr(rootElement, from)) {
  21625. return findNextBr(rootElement, from).map(function (br) {
  21626. return DeleteAction.remove(br.getNode());
  21627. });
  21628. } else {
  21629. return getContentEditableAction(root, forward, from);
  21630. }
  21631. };
  21632. var deleteElement$1 = function (editor, forward) {
  21633. return function (element) {
  21634. editor._selectionOverrides.hideFakeCaret();
  21635. DeleteElement.deleteElement(editor, forward, Element.fromDom(element));
  21636. return true;
  21637. };
  21638. };
  21639. var moveToElement = function (editor, forward) {
  21640. return function (element) {
  21641. var pos = forward ? CaretPosition$1.before(element) : CaretPosition$1.after(element);
  21642. editor.selection.setRng(pos.toRange());
  21643. return true;
  21644. };
  21645. };
  21646. var moveToPosition = function (editor) {
  21647. return function (pos) {
  21648. editor.selection.setRng(pos.toRange());
  21649. return true;
  21650. };
  21651. };
  21652. var getAncestorCe = function (editor, node) {
  21653. return Option.from(getContentEditableRoot$2(editor.getBody(), node));
  21654. };
  21655. var backspaceDeleteCaret = function (editor, forward) {
  21656. var selectedNode = editor.selection.getNode();
  21657. return getAncestorCe(editor, selectedNode).filter(NodeType.isContentEditableFalse).fold(function () {
  21658. var result = read$4(editor.getBody(), forward, editor.selection.getRng()).map(function (deleteAction) {
  21659. return deleteAction.fold(deleteElement$1(editor, forward), moveToElement(editor, forward), moveToPosition(editor));
  21660. });
  21661. return result.getOr(false);
  21662. }, function () {
  21663. return true;
  21664. });
  21665. };
  21666. var deleteOffscreenSelection = function (rootElement) {
  21667. each(descendants$1(rootElement, '.mce-offscreen-selection'), remove$1);
  21668. };
  21669. var backspaceDeleteRange = function (editor, forward) {
  21670. var selectedNode = editor.selection.getNode();
  21671. if (NodeType.isContentEditableFalse(selectedNode)) {
  21672. var hasCefAncestor = getAncestorCe(editor, selectedNode.parentNode).filter(NodeType.isContentEditableFalse);
  21673. return hasCefAncestor.fold(function () {
  21674. deleteOffscreenSelection(Element.fromDom(editor.getBody()));
  21675. DeleteElement.deleteElement(editor, forward, Element.fromDom(editor.selection.getNode()));
  21676. DeleteUtils.paddEmptyBody(editor);
  21677. return true;
  21678. }, function () {
  21679. return true;
  21680. });
  21681. }
  21682. return false;
  21683. };
  21684. var getContentEditableRoot$2 = function (root, node) {
  21685. while (node && node !== root) {
  21686. if (NodeType.isContentEditableTrue(node) || NodeType.isContentEditableFalse(node)) {
  21687. return node;
  21688. }
  21689. node = node.parentNode;
  21690. }
  21691. return null;
  21692. };
  21693. var paddEmptyElement = function (editor) {
  21694. var br;
  21695. var ceRoot = getContentEditableRoot$2(editor.getBody(), editor.selection.getNode());
  21696. if (NodeType.isContentEditableTrue(ceRoot) && editor.dom.isBlock(ceRoot) && editor.dom.isEmpty(ceRoot)) {
  21697. br = editor.dom.create('br', { 'data-mce-bogus': '1' });
  21698. editor.dom.setHTML(ceRoot, '');
  21699. ceRoot.appendChild(br);
  21700. editor.selection.setRng(CaretPosition$1.before(br).toRange());
  21701. }
  21702. return true;
  21703. };
  21704. var backspaceDelete$2 = function (editor, forward) {
  21705. if (editor.selection.isCollapsed()) {
  21706. return backspaceDeleteCaret(editor, forward);
  21707. } else {
  21708. return backspaceDeleteRange(editor, forward);
  21709. }
  21710. };
  21711. var CefDelete = {
  21712. backspaceDelete: backspaceDelete$2,
  21713. paddEmptyElement: paddEmptyElement
  21714. };
  21715. var trimEmptyTextNode$1 = function (dom, node) {
  21716. if (NodeType.isText(node) && node.data.length === 0) {
  21717. dom.remove(node);
  21718. }
  21719. };
  21720. var deleteContentAndShowCaret = function (editor, range, node, direction, forward, peekCaretPosition) {
  21721. var caretRange = showCaret(direction, editor, peekCaretPosition.getNode(!forward), forward, true);
  21722. if (range.collapsed) {
  21723. var deleteRange = range.cloneRange();
  21724. if (forward) {
  21725. deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset);
  21726. } else {
  21727. deleteRange.setStart(caretRange.endContainer, caretRange.endOffset);
  21728. }
  21729. deleteRange.deleteContents();
  21730. } else {
  21731. range.deleteContents();
  21732. }
  21733. editor.selection.setRng(caretRange);
  21734. trimEmptyTextNode$1(editor.dom, node);
  21735. return true;
  21736. };
  21737. var deleteCefBoundaryText = function (editor, forward) {
  21738. var range = editor.selection.getRng();
  21739. if (!NodeType.isText(range.commonAncestorContainer)) {
  21740. return false;
  21741. }
  21742. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  21743. var caretWalker = CaretWalker(editor.getBody());
  21744. var getNextVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.next);
  21745. var getPrevVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.prev);
  21746. var getNextPosFn = forward ? getNextVisualCaretPosition : getPrevVisualCaretPosition;
  21747. var isBeforeContentEditableFalseFn = forward ? isBeforeContentEditableFalse : isAfterContentEditableFalse;
  21748. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  21749. var nextCaretPosition = InlineUtils.normalizePosition(forward, getNextPosFn(caretPosition));
  21750. if (!nextCaretPosition) {
  21751. return false;
  21752. } else if (isBeforeContentEditableFalseFn(nextCaretPosition)) {
  21753. return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, nextCaretPosition);
  21754. }
  21755. var peekCaretPosition = getNextPosFn(nextCaretPosition);
  21756. if (peekCaretPosition && isBeforeContentEditableFalseFn(peekCaretPosition)) {
  21757. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  21758. return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, peekCaretPosition);
  21759. }
  21760. }
  21761. return false;
  21762. };
  21763. var backspaceDelete$3 = function (editor, forward) {
  21764. return deleteCefBoundaryText(editor, forward);
  21765. };
  21766. var CefBoundaryDelete = { backspaceDelete: backspaceDelete$3 };
  21767. var isFeatureEnabled$1 = function (editor) {
  21768. return editor.settings.inline_boundaries !== false;
  21769. };
  21770. var rangeFromPositions = function (from, to) {
  21771. var range = domGlobals.document.createRange();
  21772. range.setStart(from.container(), from.offset());
  21773. range.setEnd(to.container(), to.offset());
  21774. return range;
  21775. };
  21776. var hasOnlyTwoOrLessPositionsLeft = function (elm) {
  21777. return lift2(CaretFinder.firstPositionIn(elm), CaretFinder.lastPositionIn(elm), function (firstPos, lastPos) {
  21778. var normalizedFirstPos = InlineUtils.normalizePosition(true, firstPos);
  21779. var normalizedLastPos = InlineUtils.normalizePosition(false, lastPos);
  21780. return CaretFinder.nextPosition(elm, normalizedFirstPos).map(function (pos) {
  21781. return pos.isEqual(normalizedLastPos);
  21782. }).getOr(true);
  21783. }).getOr(true);
  21784. };
  21785. var setCaretLocation = function (editor, caret) {
  21786. return function (location) {
  21787. return BoundaryCaret.renderCaret(caret, location).map(function (pos) {
  21788. BoundarySelection.setCaretPosition(editor, pos);
  21789. return true;
  21790. }).getOr(false);
  21791. };
  21792. };
  21793. var deleteFromTo = function (editor, caret, from, to) {
  21794. var rootNode = editor.getBody();
  21795. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  21796. editor.undoManager.ignore(function () {
  21797. editor.selection.setRng(rangeFromPositions(from, to));
  21798. editor.execCommand('Delete');
  21799. BoundaryLocation.readLocation(isInlineTarget, rootNode, CaretPosition$1.fromRangeStart(editor.selection.getRng())).map(BoundaryLocation.inside).map(setCaretLocation(editor, caret));
  21800. });
  21801. editor.nodeChanged();
  21802. };
  21803. var rescope$1 = function (rootNode, node) {
  21804. var parentBlock = getParentBlock(node, rootNode);
  21805. return parentBlock ? parentBlock : rootNode;
  21806. };
  21807. var backspaceDeleteCollapsed = function (editor, caret, forward, from) {
  21808. var rootNode = rescope$1(editor.getBody(), from.container());
  21809. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  21810. var fromLocation = BoundaryLocation.readLocation(isInlineTarget, rootNode, from);
  21811. return fromLocation.bind(function (location) {
  21812. if (forward) {
  21813. return location.fold(constant(Option.some(BoundaryLocation.inside(location))), Option.none, constant(Option.some(BoundaryLocation.outside(location))), Option.none);
  21814. } else {
  21815. return location.fold(Option.none, constant(Option.some(BoundaryLocation.outside(location))), Option.none, constant(Option.some(BoundaryLocation.inside(location))));
  21816. }
  21817. }).map(setCaretLocation(editor, caret)).getOrThunk(function () {
  21818. var toPosition = CaretFinder.navigate(forward, rootNode, from);
  21819. var toLocation = toPosition.bind(function (pos) {
  21820. return BoundaryLocation.readLocation(isInlineTarget, rootNode, pos);
  21821. });
  21822. if (fromLocation.isSome() && toLocation.isSome()) {
  21823. return InlineUtils.findRootInline(isInlineTarget, rootNode, from).map(function (elm) {
  21824. if (hasOnlyTwoOrLessPositionsLeft(elm)) {
  21825. DeleteElement.deleteElement(editor, forward, Element.fromDom(elm));
  21826. return true;
  21827. } else {
  21828. return false;
  21829. }
  21830. }).getOr(false);
  21831. } else {
  21832. return toLocation.bind(function (_) {
  21833. return toPosition.map(function (to) {
  21834. if (forward) {
  21835. deleteFromTo(editor, caret, from, to);
  21836. } else {
  21837. deleteFromTo(editor, caret, to, from);
  21838. }
  21839. return true;
  21840. });
  21841. }).getOr(false);
  21842. }
  21843. });
  21844. };
  21845. var backspaceDelete$4 = function (editor, caret, forward) {
  21846. if (editor.selection.isCollapsed() && isFeatureEnabled$1(editor)) {
  21847. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  21848. return backspaceDeleteCollapsed(editor, caret, forward, from);
  21849. }
  21850. return false;
  21851. };
  21852. var BoundaryDelete = { backspaceDelete: backspaceDelete$4 };
  21853. var getParentInlines = function (rootElm, startElm) {
  21854. var parents = Parents.parentsAndSelf(startElm, rootElm);
  21855. return findIndex(parents, isBlock).fold(constant(parents), function (index) {
  21856. return parents.slice(0, index);
  21857. });
  21858. };
  21859. var hasOnlyOneChild = function (elm) {
  21860. return children(elm).length === 1;
  21861. };
  21862. var deleteLastPosition = function (forward, editor, target, parentInlines) {
  21863. var isFormatElement$1 = curry(isFormatElement, editor);
  21864. var formatNodes = map(filter(parentInlines, isFormatElement$1), function (elm) {
  21865. return elm.dom();
  21866. });
  21867. if (formatNodes.length === 0) {
  21868. DeleteElement.deleteElement(editor, forward, target);
  21869. } else {
  21870. var pos = replaceWithCaretFormat(target.dom(), formatNodes);
  21871. editor.selection.setRng(pos.toRange());
  21872. }
  21873. };
  21874. var deleteCaret = function (editor, forward) {
  21875. var rootElm = Element.fromDom(editor.getBody());
  21876. var startElm = Element.fromDom(editor.selection.getStart());
  21877. var parentInlines = filter(getParentInlines(rootElm, startElm), hasOnlyOneChild);
  21878. return last(parentInlines).map(function (target) {
  21879. var fromPos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  21880. if (DeleteUtils.willDeleteLastPositionInElement(forward, fromPos, target.dom()) && !isEmptyCaretFormatElement(target)) {
  21881. deleteLastPosition(forward, editor, target, parentInlines);
  21882. return true;
  21883. } else {
  21884. return false;
  21885. }
  21886. }).getOr(false);
  21887. };
  21888. var backspaceDelete$5 = function (editor, forward) {
  21889. return editor.selection.isCollapsed() ? deleteCaret(editor, forward) : false;
  21890. };
  21891. var InlineFormatDelete = { backspaceDelete: backspaceDelete$5 };
  21892. var tableCellRng = function (start, end) {
  21893. return {
  21894. start: constant(start),
  21895. end: constant(end)
  21896. };
  21897. };
  21898. var tableSelection = function (rng, table, cells) {
  21899. return {
  21900. rng: constant(rng),
  21901. table: constant(table),
  21902. cells: constant(cells)
  21903. };
  21904. };
  21905. var deleteAction = Adt.generate([
  21906. { removeTable: ['element'] },
  21907. { emptyCells: ['cells'] }
  21908. ]);
  21909. var isRootFromElement = function (root) {
  21910. return function (cur) {
  21911. return eq(root, cur);
  21912. };
  21913. };
  21914. var getClosestCell$1 = function (container, isRoot) {
  21915. return closest$1(Element.fromDom(container), 'td,th', isRoot);
  21916. };
  21917. var getClosestTable = function (cell, isRoot) {
  21918. return ancestor$1(cell, 'table', isRoot);
  21919. };
  21920. var isExpandedCellRng = function (cellRng) {
  21921. return eq(cellRng.start(), cellRng.end()) === false;
  21922. };
  21923. var getTableFromCellRng = function (cellRng, isRoot) {
  21924. return getClosestTable(cellRng.start(), isRoot).bind(function (startParentTable) {
  21925. return getClosestTable(cellRng.end(), isRoot).bind(function (endParentTable) {
  21926. return someIf(eq(startParentTable, endParentTable), startParentTable);
  21927. });
  21928. });
  21929. };
  21930. var getTableCells = function (table) {
  21931. return descendants$1(table, 'td,th');
  21932. };
  21933. var getCellRangeFromStartTable = function (cellRng, isRoot) {
  21934. return getClosestTable(cellRng.start(), isRoot).bind(function (table) {
  21935. return last(getTableCells(table)).map(function (endCell) {
  21936. return tableCellRng(cellRng.start(), endCell);
  21937. });
  21938. });
  21939. };
  21940. var partialSelection = function (isRoot, rng) {
  21941. var startCell = getClosestCell$1(rng.startContainer, isRoot);
  21942. var endCell = getClosestCell$1(rng.endContainer, isRoot);
  21943. return rng.collapsed ? Option.none() : lift2(startCell, endCell, tableCellRng).fold(function () {
  21944. return startCell.fold(function () {
  21945. return endCell.bind(function (endCell) {
  21946. return getClosestTable(endCell, isRoot).bind(function (table) {
  21947. return head(getTableCells(table)).map(function (startCell) {
  21948. return tableCellRng(startCell, endCell);
  21949. });
  21950. });
  21951. });
  21952. }, function (startCell) {
  21953. return getClosestTable(startCell, isRoot).bind(function (table) {
  21954. return last(getTableCells(table)).map(function (endCell) {
  21955. return tableCellRng(startCell, endCell);
  21956. });
  21957. });
  21958. });
  21959. }, function (cellRng) {
  21960. return isWithinSameTable(isRoot, cellRng) ? Option.none() : getCellRangeFromStartTable(cellRng, isRoot);
  21961. });
  21962. };
  21963. var isWithinSameTable = function (isRoot, cellRng) {
  21964. return getTableFromCellRng(cellRng, isRoot).isSome();
  21965. };
  21966. var getCellRng = function (rng, isRoot) {
  21967. var startCell = getClosestCell$1(rng.startContainer, isRoot);
  21968. var endCell = getClosestCell$1(rng.endContainer, isRoot);
  21969. return lift2(startCell, endCell, tableCellRng).filter(isExpandedCellRng).filter(function (cellRng) {
  21970. return isWithinSameTable(isRoot, cellRng);
  21971. }).orThunk(function () {
  21972. return partialSelection(isRoot, rng);
  21973. });
  21974. };
  21975. var getTableSelectionFromCellRng = function (cellRng, isRoot) {
  21976. return getTableFromCellRng(cellRng, isRoot).map(function (table) {
  21977. return tableSelection(cellRng, table, getTableCells(table));
  21978. });
  21979. };
  21980. var getTableSelectionFromRng = function (root, rng) {
  21981. var isRoot = isRootFromElement(root);
  21982. return getCellRng(rng, isRoot).bind(function (cellRng) {
  21983. return getTableSelectionFromCellRng(cellRng, isRoot);
  21984. });
  21985. };
  21986. var getCellIndex = function (cells, cell) {
  21987. return findIndex(cells, function (x) {
  21988. return eq(x, cell);
  21989. });
  21990. };
  21991. var getSelectedCells = function (tableSelection) {
  21992. return lift2(getCellIndex(tableSelection.cells(), tableSelection.rng().start()), getCellIndex(tableSelection.cells(), tableSelection.rng().end()), function (startIndex, endIndex) {
  21993. return tableSelection.cells().slice(startIndex, endIndex + 1);
  21994. });
  21995. };
  21996. var getAction = function (tableSelection) {
  21997. return getSelectedCells(tableSelection).map(function (selected) {
  21998. var cells = tableSelection.cells();
  21999. return selected.length === cells.length ? deleteAction.removeTable(tableSelection.table()) : deleteAction.emptyCells(selected);
  22000. });
  22001. };
  22002. var getActionFromRange = function (root, rng) {
  22003. return getTableSelectionFromRng(root, rng).bind(getAction);
  22004. };
  22005. var emptyCells = function (editor, cells) {
  22006. each(cells, PaddingBr.fillWithPaddingBr);
  22007. editor.selection.setCursorLocation(cells[0].dom(), 0);
  22008. return true;
  22009. };
  22010. var deleteTableElement = function (editor, table) {
  22011. DeleteElement.deleteElement(editor, false, table);
  22012. return true;
  22013. };
  22014. var deleteCellRange = function (editor, rootElm, rng) {
  22015. return getActionFromRange(rootElm, rng).map(function (action) {
  22016. return action.fold(curry(deleteTableElement, editor), curry(emptyCells, editor));
  22017. });
  22018. };
  22019. var deleteCaptionRange = function (editor, caption) {
  22020. return emptyElement(editor, caption);
  22021. };
  22022. var deleteTableRange = function (editor, rootElm, rng, startElm) {
  22023. return getParentCaption(rootElm, startElm).fold(function () {
  22024. return deleteCellRange(editor, rootElm, rng);
  22025. }, function (caption) {
  22026. return deleteCaptionRange(editor, caption);
  22027. }).getOr(false);
  22028. };
  22029. var deleteRange$1 = function (editor, startElm) {
  22030. var rootNode = Element.fromDom(editor.getBody());
  22031. var rng = editor.selection.getRng();
  22032. var selectedCells = TableCellSelection.getCellsFromEditor(editor);
  22033. return selectedCells.length !== 0 ? emptyCells(editor, selectedCells) : deleteTableRange(editor, rootNode, rng, startElm);
  22034. };
  22035. var getParentCell = function (rootElm, elm) {
  22036. return find(Parents.parentsAndSelf(elm, rootElm), isTableCell);
  22037. };
  22038. var getParentCaption = function (rootElm, elm) {
  22039. return find(Parents.parentsAndSelf(elm, rootElm), function (elm) {
  22040. return name(elm) === 'caption';
  22041. });
  22042. };
  22043. var deleteBetweenCells = function (editor, rootElm, forward, fromCell, from) {
  22044. return CaretFinder.navigate(forward, editor.getBody(), from).bind(function (to) {
  22045. return getParentCell(rootElm, Element.fromDom(to.getNode())).map(function (toCell) {
  22046. return eq(toCell, fromCell) === false;
  22047. });
  22048. });
  22049. };
  22050. var emptyElement = function (editor, elm) {
  22051. PaddingBr.fillWithPaddingBr(elm);
  22052. editor.selection.setCursorLocation(elm.dom(), 0);
  22053. return Option.some(true);
  22054. };
  22055. var isDeleteOfLastCharPos = function (fromCaption, forward, from, to) {
  22056. return CaretFinder.firstPositionIn(fromCaption.dom()).bind(function (first) {
  22057. return CaretFinder.lastPositionIn(fromCaption.dom()).map(function (last) {
  22058. return forward ? from.isEqual(first) && to.isEqual(last) : from.isEqual(last) && to.isEqual(first);
  22059. });
  22060. }).getOr(true);
  22061. };
  22062. var emptyCaretCaption = function (editor, elm) {
  22063. return emptyElement(editor, elm);
  22064. };
  22065. var validateCaretCaption = function (rootElm, fromCaption, to) {
  22066. return getParentCaption(rootElm, Element.fromDom(to.getNode())).map(function (toCaption) {
  22067. return eq(toCaption, fromCaption) === false;
  22068. });
  22069. };
  22070. var deleteCaretInsideCaption = function (editor, rootElm, forward, fromCaption, from) {
  22071. return CaretFinder.navigate(forward, editor.getBody(), from).bind(function (to) {
  22072. return isDeleteOfLastCharPos(fromCaption, forward, from, to) ? emptyCaretCaption(editor, fromCaption) : validateCaretCaption(rootElm, fromCaption, to);
  22073. }).or(Option.some(true));
  22074. };
  22075. var deleteCaretCells = function (editor, forward, rootElm, startElm) {
  22076. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22077. return getParentCell(rootElm, startElm).bind(function (fromCell) {
  22078. return Empty.isEmpty(fromCell) ? emptyElement(editor, fromCell) : deleteBetweenCells(editor, rootElm, forward, fromCell, from);
  22079. }).getOr(false);
  22080. };
  22081. var deleteCaretCaption = function (editor, forward, rootElm, fromCaption) {
  22082. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22083. return Empty.isEmpty(fromCaption) ? emptyElement(editor, fromCaption) : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from);
  22084. };
  22085. var isNearTable = function (forward, pos) {
  22086. return forward ? isBeforeTable(pos) : isAfterTable(pos);
  22087. };
  22088. var isBeforeOrAfterTable = function (editor, forward) {
  22089. var fromPos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22090. return isNearTable(forward, fromPos) || CaretFinder.fromPosition(forward, editor.getBody(), fromPos).map(function (pos) {
  22091. return isNearTable(forward, pos);
  22092. }).getOr(false);
  22093. };
  22094. var deleteCaret$1 = function (editor, forward, startElm) {
  22095. var rootElm = Element.fromDom(editor.getBody());
  22096. return getParentCaption(rootElm, startElm).fold(function () {
  22097. return deleteCaretCells(editor, forward, rootElm, startElm) || isBeforeOrAfterTable(editor, forward);
  22098. }, function (fromCaption) {
  22099. return deleteCaretCaption(editor, forward, rootElm, fromCaption).getOr(false);
  22100. });
  22101. };
  22102. var backspaceDelete$6 = function (editor, forward) {
  22103. var startElm = Element.fromDom(editor.selection.getStart(true));
  22104. var cells = TableCellSelection.getCellsFromEditor(editor);
  22105. return editor.selection.isCollapsed() && cells.length === 0 ? deleteCaret$1(editor, forward, startElm) : deleteRange$1(editor, startElm);
  22106. };
  22107. var TableDelete = { backspaceDelete: backspaceDelete$6 };
  22108. var deleteCaret$2 = function (editor, forward) {
  22109. var fromPos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22110. return CaretFinder.fromPosition(forward, editor.getBody(), fromPos).filter(function (pos) {
  22111. return forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos);
  22112. }).bind(function (pos) {
  22113. return Option.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, pos));
  22114. }).map(function (elm) {
  22115. editor.selection.select(elm);
  22116. return true;
  22117. }).getOr(false);
  22118. };
  22119. var backspaceDelete$7 = function (editor, forward) {
  22120. return editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : false;
  22121. };
  22122. var PageBreakDelete = { backspaceDelete: backspaceDelete$7 };
  22123. var isEditable$1 = function (target) {
  22124. return closest(target, function (elm) {
  22125. return NodeType.isContentEditableTrue(elm.dom()) || NodeType.isContentEditableFalse(elm.dom());
  22126. }).exists(function (elm) {
  22127. return NodeType.isContentEditableTrue(elm.dom());
  22128. });
  22129. };
  22130. var parseIndentValue = function (value) {
  22131. var number = parseInt(value, 10);
  22132. return isNaN(number) ? 0 : number;
  22133. };
  22134. var getIndentStyleName = function (useMargin, element) {
  22135. var indentStyleName = useMargin || isTable$1(element) ? 'margin' : 'padding';
  22136. var suffix = get$2(element, 'direction') === 'rtl' ? '-right' : '-left';
  22137. return indentStyleName + suffix;
  22138. };
  22139. var indentElement = function (dom, command, useMargin, value, unit, element) {
  22140. var indentStyleName = getIndentStyleName(useMargin, Element.fromDom(element));
  22141. if (command === 'outdent') {
  22142. var styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value);
  22143. dom.setStyle(element, indentStyleName, styleValue ? styleValue + unit : '');
  22144. } else {
  22145. var styleValue = parseIndentValue(element.style[indentStyleName]) + value + unit;
  22146. dom.setStyle(element, indentStyleName, styleValue);
  22147. }
  22148. };
  22149. var validateBlocks = function (editor, blocks) {
  22150. return forall(blocks, function (block) {
  22151. var indentStyleName = getIndentStyleName(Settings.shouldIndentUseMargin(editor), block);
  22152. var intentValue = getRaw(block, indentStyleName).map(parseIndentValue).getOr(0);
  22153. var contentEditable = editor.dom.getContentEditable(block.dom());
  22154. return contentEditable !== 'false' && intentValue > 0;
  22155. });
  22156. };
  22157. var canOutdent = function (editor) {
  22158. var blocks = getBlocksToIndent(editor);
  22159. return editor.readonly !== true && (blocks.length > 1 || validateBlocks(editor, blocks));
  22160. };
  22161. var isListComponent = function (el) {
  22162. return isList(el) || isListItem(el);
  22163. };
  22164. var parentIsListComponent = function (el) {
  22165. return parent(el).map(isListComponent).getOr(false);
  22166. };
  22167. var getBlocksToIndent = function (editor) {
  22168. return filter(map(editor.selection.getSelectedBlocks(), Element.fromDom), function (el) {
  22169. return !isListComponent(el) && !parentIsListComponent(el) && isEditable$1(el);
  22170. });
  22171. };
  22172. var handle = function (editor, command) {
  22173. var dom = editor.dom, selection = editor.selection, formatter = editor.formatter;
  22174. var indentation = Settings.getIndentation(editor);
  22175. var indentUnit = /[a-z%]+$/i.exec(indentation)[0];
  22176. var indentValue = parseInt(indentation, 10);
  22177. var useMargin = Settings.shouldIndentUseMargin(editor);
  22178. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  22179. if (!editor.queryCommandState('InsertUnorderedList') && !editor.queryCommandState('InsertOrderedList')) {
  22180. if (forcedRootBlock === '' && !dom.getParent(selection.getNode(), dom.isBlock)) {
  22181. formatter.apply('div');
  22182. }
  22183. }
  22184. each(getBlocksToIndent(editor), function (block) {
  22185. indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom());
  22186. });
  22187. };
  22188. var navigateIgnoreEmptyTextNodes = function (forward, root, from) {
  22189. return CaretFinder.navigateIgnore(forward, root, from, isEmptyText);
  22190. };
  22191. var getClosestBlock = function (root, pos) {
  22192. return find(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), isBlock);
  22193. };
  22194. var isAtBeforeAfterBlockBoundary = function (forward, root, pos) {
  22195. return navigateIgnoreEmptyTextNodes(forward, root.dom(), pos).forall(function (newPos) {
  22196. return getClosestBlock(root, pos).fold(function () {
  22197. return isInSameBlock(newPos, pos, root.dom()) === false;
  22198. }, function (fromBlock) {
  22199. return isInSameBlock(newPos, pos, root.dom()) === false && contains$2(fromBlock, Element.fromDom(newPos.container()));
  22200. });
  22201. });
  22202. };
  22203. var isAtBlockBoundary = function (forward, root, pos) {
  22204. return getClosestBlock(root, pos).fold(function () {
  22205. return navigateIgnoreEmptyTextNodes(forward, root.dom(), pos).forall(function (newPos) {
  22206. return isInSameBlock(newPos, pos, root.dom()) === false;
  22207. });
  22208. }, function (parent) {
  22209. return navigateIgnoreEmptyTextNodes(forward, parent.dom(), pos).isNone();
  22210. });
  22211. };
  22212. var isAtStartOfBlock = curry(isAtBlockBoundary, false);
  22213. var isAtEndOfBlock = curry(isAtBlockBoundary, true);
  22214. var isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false);
  22215. var isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true);
  22216. var backspaceDelete$8 = function (editor, _caret, _forward) {
  22217. if (editor.selection.isCollapsed() && canOutdent(editor)) {
  22218. var dom = editor.dom;
  22219. var rng = editor.selection.getRng();
  22220. var pos = CaretPosition$1.fromRangeStart(rng);
  22221. var block = dom.getParent(rng.startContainer, dom.isBlock);
  22222. if (block !== null && isAtStartOfBlock(Element.fromDom(block), pos)) {
  22223. handle(editor, 'outdent');
  22224. return true;
  22225. }
  22226. }
  22227. return false;
  22228. };
  22229. var Outdent = { backspaceDelete: backspaceDelete$8 };
  22230. var executeKeydownOverride$1 = function (editor, caret, evt) {
  22231. MatchKeys.execute([
  22232. {
  22233. keyCode: VK.BACKSPACE,
  22234. action: MatchKeys.action(Outdent.backspaceDelete, editor, false)
  22235. },
  22236. {
  22237. keyCode: VK.BACKSPACE,
  22238. action: MatchKeys.action(CefDelete.backspaceDelete, editor, false)
  22239. },
  22240. {
  22241. keyCode: VK.DELETE,
  22242. action: MatchKeys.action(CefDelete.backspaceDelete, editor, true)
  22243. },
  22244. {
  22245. keyCode: VK.BACKSPACE,
  22246. action: MatchKeys.action(CefBoundaryDelete.backspaceDelete, editor, false)
  22247. },
  22248. {
  22249. keyCode: VK.DELETE,
  22250. action: MatchKeys.action(CefBoundaryDelete.backspaceDelete, editor, true)
  22251. },
  22252. {
  22253. keyCode: VK.BACKSPACE,
  22254. action: MatchKeys.action(BoundaryDelete.backspaceDelete, editor, caret, false)
  22255. },
  22256. {
  22257. keyCode: VK.DELETE,
  22258. action: MatchKeys.action(BoundaryDelete.backspaceDelete, editor, caret, true)
  22259. },
  22260. {
  22261. keyCode: VK.BACKSPACE,
  22262. action: MatchKeys.action(TableDelete.backspaceDelete, editor, false)
  22263. },
  22264. {
  22265. keyCode: VK.DELETE,
  22266. action: MatchKeys.action(TableDelete.backspaceDelete, editor, true)
  22267. },
  22268. {
  22269. keyCode: VK.BACKSPACE,
  22270. action: MatchKeys.action(PageBreakDelete.backspaceDelete, editor, false)
  22271. },
  22272. {
  22273. keyCode: VK.DELETE,
  22274. action: MatchKeys.action(PageBreakDelete.backspaceDelete, editor, true)
  22275. },
  22276. {
  22277. keyCode: VK.BACKSPACE,
  22278. action: MatchKeys.action(BlockRangeDelete.backspaceDelete, editor, false)
  22279. },
  22280. {
  22281. keyCode: VK.DELETE,
  22282. action: MatchKeys.action(BlockRangeDelete.backspaceDelete, editor, true)
  22283. },
  22284. {
  22285. keyCode: VK.BACKSPACE,
  22286. action: MatchKeys.action(BlockBoundaryDelete.backspaceDelete, editor, false)
  22287. },
  22288. {
  22289. keyCode: VK.DELETE,
  22290. action: MatchKeys.action(BlockBoundaryDelete.backspaceDelete, editor, true)
  22291. },
  22292. {
  22293. keyCode: VK.BACKSPACE,
  22294. action: MatchKeys.action(InlineFormatDelete.backspaceDelete, editor, false)
  22295. },
  22296. {
  22297. keyCode: VK.DELETE,
  22298. action: MatchKeys.action(InlineFormatDelete.backspaceDelete, editor, true)
  22299. }
  22300. ], evt).each(function (_) {
  22301. evt.preventDefault();
  22302. });
  22303. };
  22304. var executeKeyupOverride = function (editor, evt) {
  22305. MatchKeys.execute([
  22306. {
  22307. keyCode: VK.BACKSPACE,
  22308. action: MatchKeys.action(CefDelete.paddEmptyElement, editor)
  22309. },
  22310. {
  22311. keyCode: VK.DELETE,
  22312. action: MatchKeys.action(CefDelete.paddEmptyElement, editor)
  22313. }
  22314. ], evt);
  22315. };
  22316. var setup$9 = function (editor, caret) {
  22317. editor.on('keydown', function (evt) {
  22318. if (evt.isDefaultPrevented() === false) {
  22319. executeKeydownOverride$1(editor, caret, evt);
  22320. }
  22321. });
  22322. editor.on('keyup', function (evt) {
  22323. if (evt.isDefaultPrevented() === false) {
  22324. executeKeyupOverride(editor, evt);
  22325. }
  22326. });
  22327. };
  22328. var DeleteBackspaceKeys = { setup: setup$9 };
  22329. var firstNonWhiteSpaceNodeSibling = function (node) {
  22330. while (node) {
  22331. if (node.nodeType === 1 || node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data)) {
  22332. return node;
  22333. }
  22334. node = node.nextSibling;
  22335. }
  22336. };
  22337. var moveToCaretPosition = function (editor, root) {
  22338. var node, rng, lastNode = root;
  22339. var dom = editor.dom;
  22340. var moveCaretBeforeOnEnterElementsMap = editor.schema.getMoveCaretBeforeOnEnterElements();
  22341. if (!root) {
  22342. return;
  22343. }
  22344. if (/^(LI|DT|DD)$/.test(root.nodeName)) {
  22345. var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild);
  22346. if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
  22347. root.insertBefore(dom.doc.createTextNode('\xA0'), root.firstChild);
  22348. }
  22349. }
  22350. rng = dom.createRng();
  22351. root.normalize();
  22352. if (root.hasChildNodes()) {
  22353. var walker = new TreeWalker(root, root);
  22354. while (node = walker.current()) {
  22355. if (NodeType.isText(node)) {
  22356. rng.setStart(node, 0);
  22357. rng.setEnd(node, 0);
  22358. break;
  22359. }
  22360. if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
  22361. rng.setStartBefore(node);
  22362. rng.setEndBefore(node);
  22363. break;
  22364. }
  22365. lastNode = node;
  22366. node = walker.next();
  22367. }
  22368. if (!node) {
  22369. rng.setStart(lastNode, 0);
  22370. rng.setEnd(lastNode, 0);
  22371. }
  22372. } else {
  22373. if (NodeType.isBr(root)) {
  22374. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  22375. rng.setStartBefore(root);
  22376. rng.setEndBefore(root);
  22377. } else {
  22378. rng.setStartAfter(root);
  22379. rng.setEndAfter(root);
  22380. }
  22381. } else {
  22382. rng.setStart(root, 0);
  22383. rng.setEnd(root, 0);
  22384. }
  22385. }
  22386. editor.selection.setRng(rng);
  22387. editor.selection.scrollIntoView(root);
  22388. };
  22389. var getEditableRoot = function (dom, node) {
  22390. var root = dom.getRoot();
  22391. var parent, editableRoot;
  22392. parent = node;
  22393. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  22394. if (dom.getContentEditable(parent) === 'true') {
  22395. editableRoot = parent;
  22396. }
  22397. parent = parent.parentNode;
  22398. }
  22399. return parent !== root ? editableRoot : root;
  22400. };
  22401. var getParentBlock$2 = function (editor) {
  22402. return Option.from(editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock));
  22403. };
  22404. var getParentBlockName = function (editor) {
  22405. return getParentBlock$2(editor).fold(constant(''), function (parentBlock) {
  22406. return parentBlock.nodeName.toUpperCase();
  22407. });
  22408. };
  22409. var isListItemParentBlock = function (editor) {
  22410. return getParentBlock$2(editor).filter(function (elm) {
  22411. return isListItem(Element.fromDom(elm));
  22412. }).isSome();
  22413. };
  22414. var NewLineUtils = {
  22415. moveToCaretPosition: moveToCaretPosition,
  22416. getEditableRoot: getEditableRoot,
  22417. getParentBlock: getParentBlock$2,
  22418. getParentBlockName: getParentBlockName,
  22419. isListItemParentBlock: isListItemParentBlock
  22420. };
  22421. var hasFirstChild = function (elm, name) {
  22422. return elm.firstChild && elm.firstChild.nodeName === name;
  22423. };
  22424. var hasParent$1 = function (elm, parentName) {
  22425. return elm && elm.parentNode && elm.parentNode.nodeName === parentName;
  22426. };
  22427. var isListBlock = function (elm) {
  22428. return elm && /^(OL|UL|LI)$/.test(elm.nodeName);
  22429. };
  22430. var isNestedList = function (elm) {
  22431. return isListBlock(elm) && isListBlock(elm.parentNode);
  22432. };
  22433. var getContainerBlock = function (containerBlock) {
  22434. var containerBlockParent = containerBlock.parentNode;
  22435. if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) {
  22436. return containerBlockParent;
  22437. }
  22438. return containerBlock;
  22439. };
  22440. var isFirstOrLastLi = function (containerBlock, parentBlock, first) {
  22441. var node = containerBlock[first ? 'firstChild' : 'lastChild'];
  22442. while (node) {
  22443. if (NodeType.isElement(node)) {
  22444. break;
  22445. }
  22446. node = node[first ? 'nextSibling' : 'previousSibling'];
  22447. }
  22448. return node === parentBlock;
  22449. };
  22450. var insert = function (editor, createNewBlock, containerBlock, parentBlock, newBlockName) {
  22451. var dom = editor.dom;
  22452. var rng = editor.selection.getRng();
  22453. if (containerBlock === editor.getBody()) {
  22454. return;
  22455. }
  22456. if (isNestedList(containerBlock)) {
  22457. newBlockName = 'LI';
  22458. }
  22459. var newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
  22460. if (isFirstOrLastLi(containerBlock, parentBlock, true) && isFirstOrLastLi(containerBlock, parentBlock, false)) {
  22461. if (hasParent$1(containerBlock, 'LI')) {
  22462. dom.insertAfter(newBlock, getContainerBlock(containerBlock));
  22463. } else {
  22464. dom.replace(newBlock, containerBlock);
  22465. }
  22466. } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) {
  22467. if (hasParent$1(containerBlock, 'LI')) {
  22468. dom.insertAfter(newBlock, getContainerBlock(containerBlock));
  22469. newBlock.appendChild(dom.doc.createTextNode(' '));
  22470. newBlock.appendChild(containerBlock);
  22471. } else {
  22472. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  22473. }
  22474. } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) {
  22475. dom.insertAfter(newBlock, getContainerBlock(containerBlock));
  22476. } else {
  22477. containerBlock = getContainerBlock(containerBlock);
  22478. var tmpRng = rng.cloneRange();
  22479. tmpRng.setStartAfter(parentBlock);
  22480. tmpRng.setEndAfter(containerBlock);
  22481. var fragment = tmpRng.extractContents();
  22482. if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) {
  22483. newBlock = fragment.firstChild;
  22484. dom.insertAfter(fragment, containerBlock);
  22485. } else {
  22486. dom.insertAfter(fragment, containerBlock);
  22487. dom.insertAfter(newBlock, containerBlock);
  22488. }
  22489. }
  22490. dom.remove(parentBlock);
  22491. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22492. };
  22493. var InsertLi = { insert: insert };
  22494. var trimZwsp = function (fragment) {
  22495. each(descendants(Element.fromDom(fragment), isText$1), function (text) {
  22496. var rawNode = text.dom();
  22497. rawNode.nodeValue = Zwsp.trim(rawNode.nodeValue);
  22498. });
  22499. };
  22500. var isEmptyAnchor = function (dom, elm) {
  22501. return elm && elm.nodeName === 'A' && dom.isEmpty(elm);
  22502. };
  22503. var isTableCell$4 = function (node) {
  22504. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
  22505. };
  22506. var emptyBlock = function (elm) {
  22507. elm.innerHTML = '<br data-mce-bogus="1">';
  22508. };
  22509. var containerAndSiblingName = function (container, nodeName) {
  22510. return container.nodeName === nodeName || container.previousSibling && container.previousSibling.nodeName === nodeName;
  22511. };
  22512. var canSplitBlock = function (dom, node) {
  22513. return node && dom.isBlock(node) && !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) && !/^(fixed|absolute)/i.test(node.style.position) && dom.getContentEditable(node) !== 'true';
  22514. };
  22515. var trimInlineElementsOnLeftSideOfBlock = function (dom, nonEmptyElementsMap, block) {
  22516. var node = block;
  22517. var firstChilds = [];
  22518. var i;
  22519. if (!node) {
  22520. return;
  22521. }
  22522. while (node = node.firstChild) {
  22523. if (dom.isBlock(node)) {
  22524. return;
  22525. }
  22526. if (NodeType.isElement(node) && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  22527. firstChilds.push(node);
  22528. }
  22529. }
  22530. i = firstChilds.length;
  22531. while (i--) {
  22532. node = firstChilds[i];
  22533. if (!node.hasChildNodes() || node.firstChild === node.lastChild && node.firstChild.nodeValue === '') {
  22534. dom.remove(node);
  22535. } else {
  22536. if (isEmptyAnchor(dom, node)) {
  22537. dom.remove(node);
  22538. }
  22539. }
  22540. }
  22541. };
  22542. var normalizeZwspOffset = function (start, container, offset) {
  22543. if (NodeType.isText(container) === false) {
  22544. return offset;
  22545. } else if (start) {
  22546. return offset === 1 && container.data.charAt(offset - 1) === Zwsp.ZWSP ? 0 : offset;
  22547. } else {
  22548. return offset === container.data.length - 1 && container.data.charAt(offset) === Zwsp.ZWSP ? container.data.length : offset;
  22549. }
  22550. };
  22551. var includeZwspInRange = function (rng) {
  22552. var newRng = rng.cloneRange();
  22553. newRng.setStart(rng.startContainer, normalizeZwspOffset(true, rng.startContainer, rng.startOffset));
  22554. newRng.setEnd(rng.endContainer, normalizeZwspOffset(false, rng.endContainer, rng.endOffset));
  22555. return newRng;
  22556. };
  22557. var trimLeadingLineBreaks = function (node) {
  22558. do {
  22559. if (NodeType.isText(node)) {
  22560. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
  22561. }
  22562. node = node.firstChild;
  22563. } while (node);
  22564. };
  22565. var getEditableRoot$1 = function (dom, node) {
  22566. var root = dom.getRoot();
  22567. var parent, editableRoot;
  22568. parent = node;
  22569. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  22570. if (dom.getContentEditable(parent) === 'true') {
  22571. editableRoot = parent;
  22572. }
  22573. parent = parent.parentNode;
  22574. }
  22575. return parent !== root ? editableRoot : root;
  22576. };
  22577. var setForcedBlockAttrs = function (editor, node) {
  22578. var forcedRootBlockName = Settings.getForcedRootBlock(editor);
  22579. if (forcedRootBlockName && forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()) {
  22580. editor.dom.setAttribs(node, Settings.getForcedRootBlockAttrs(editor));
  22581. }
  22582. };
  22583. var wrapSelfAndSiblingsInDefaultBlock = function (editor, newBlockName, rng, container, offset) {
  22584. var newBlock, parentBlock, startNode, node, next, rootBlockName;
  22585. var blockName = newBlockName || 'P';
  22586. var dom = editor.dom, editableRoot = getEditableRoot$1(dom, container);
  22587. parentBlock = dom.getParent(container, dom.isBlock);
  22588. if (!parentBlock || !canSplitBlock(dom, parentBlock)) {
  22589. parentBlock = parentBlock || editableRoot;
  22590. if (parentBlock === editor.getBody() || isTableCell$4(parentBlock)) {
  22591. rootBlockName = parentBlock.nodeName.toLowerCase();
  22592. } else {
  22593. rootBlockName = parentBlock.parentNode.nodeName.toLowerCase();
  22594. }
  22595. if (!parentBlock.hasChildNodes()) {
  22596. newBlock = dom.create(blockName);
  22597. setForcedBlockAttrs(editor, newBlock);
  22598. parentBlock.appendChild(newBlock);
  22599. rng.setStart(newBlock, 0);
  22600. rng.setEnd(newBlock, 0);
  22601. return newBlock;
  22602. }
  22603. node = container;
  22604. while (node.parentNode !== parentBlock) {
  22605. node = node.parentNode;
  22606. }
  22607. while (node && !dom.isBlock(node)) {
  22608. startNode = node;
  22609. node = node.previousSibling;
  22610. }
  22611. if (startNode && editor.schema.isValidChild(rootBlockName, blockName.toLowerCase())) {
  22612. newBlock = dom.create(blockName);
  22613. setForcedBlockAttrs(editor, newBlock);
  22614. startNode.parentNode.insertBefore(newBlock, startNode);
  22615. node = startNode;
  22616. while (node && !dom.isBlock(node)) {
  22617. next = node.nextSibling;
  22618. newBlock.appendChild(node);
  22619. node = next;
  22620. }
  22621. rng.setStart(container, offset);
  22622. rng.setEnd(container, offset);
  22623. }
  22624. }
  22625. return container;
  22626. };
  22627. var addBrToBlockIfNeeded = function (dom, block) {
  22628. var lastChild;
  22629. block.normalize();
  22630. lastChild = block.lastChild;
  22631. if (!lastChild || /^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true))) {
  22632. dom.add(block, 'br');
  22633. }
  22634. };
  22635. var insert$1 = function (editor, evt) {
  22636. var tmpRng, editableRoot, container, offset, parentBlock, shiftKey;
  22637. var newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
  22638. var dom = editor.dom;
  22639. var schema = editor.schema, nonEmptyElementsMap = schema.getNonEmptyElements();
  22640. var rng = editor.selection.getRng();
  22641. var createNewBlock = function (name) {
  22642. var node = container, block, clonedNode, caretNode;
  22643. var textInlineElements = schema.getTextInlineElements();
  22644. if (name || parentBlockName === 'TABLE' || parentBlockName === 'HR') {
  22645. block = dom.create(name || newBlockName);
  22646. setForcedBlockAttrs(editor, block);
  22647. } else {
  22648. block = parentBlock.cloneNode(false);
  22649. }
  22650. caretNode = block;
  22651. if (Settings.shouldKeepStyles(editor) === false) {
  22652. dom.setAttrib(block, 'style', null);
  22653. dom.setAttrib(block, 'class', null);
  22654. } else {
  22655. do {
  22656. if (textInlineElements[node.nodeName]) {
  22657. if (isCaretNode(node) || Bookmarks.isBookmarkNode(node)) {
  22658. continue;
  22659. }
  22660. clonedNode = node.cloneNode(false);
  22661. dom.setAttrib(clonedNode, 'id', '');
  22662. if (block.hasChildNodes()) {
  22663. clonedNode.appendChild(block.firstChild);
  22664. block.appendChild(clonedNode);
  22665. } else {
  22666. caretNode = clonedNode;
  22667. block.appendChild(clonedNode);
  22668. }
  22669. }
  22670. } while ((node = node.parentNode) && node !== editableRoot);
  22671. }
  22672. emptyBlock(caretNode);
  22673. return block;
  22674. };
  22675. var isCaretAtStartOrEndOfBlock = function (start) {
  22676. var node, name;
  22677. var normalizedOffset = normalizeZwspOffset(start, container, offset);
  22678. if (NodeType.isText(container) && (start ? normalizedOffset > 0 : normalizedOffset < container.nodeValue.length)) {
  22679. return false;
  22680. }
  22681. if (container.parentNode === parentBlock && isAfterLastNodeInContainer && !start) {
  22682. return true;
  22683. }
  22684. if (start && NodeType.isElement(container) && container === parentBlock.firstChild) {
  22685. return true;
  22686. }
  22687. if (containerAndSiblingName(container, 'TABLE') || containerAndSiblingName(container, 'HR')) {
  22688. return isAfterLastNodeInContainer && !start || !isAfterLastNodeInContainer && start;
  22689. }
  22690. var walker = new TreeWalker(container, parentBlock);
  22691. if (NodeType.isText(container)) {
  22692. if (start && normalizedOffset === 0) {
  22693. walker.prev();
  22694. } else if (!start && normalizedOffset === container.nodeValue.length) {
  22695. walker.next();
  22696. }
  22697. }
  22698. while (node = walker.current()) {
  22699. if (NodeType.isElement(node)) {
  22700. if (!node.getAttribute('data-mce-bogus')) {
  22701. name = node.nodeName.toLowerCase();
  22702. if (nonEmptyElementsMap[name] && name !== 'br') {
  22703. return false;
  22704. }
  22705. }
  22706. } else if (NodeType.isText(node) && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
  22707. return false;
  22708. }
  22709. if (start) {
  22710. walker.prev();
  22711. } else {
  22712. walker.next();
  22713. }
  22714. }
  22715. return true;
  22716. };
  22717. var insertNewBlockAfter = function () {
  22718. if (/^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) && containerBlockName !== 'HGROUP') {
  22719. newBlock = createNewBlock(newBlockName);
  22720. } else {
  22721. newBlock = createNewBlock();
  22722. }
  22723. if (Settings.shouldEndContainerOnEmptyBlock(editor) && canSplitBlock(dom, containerBlock) && dom.isEmpty(parentBlock)) {
  22724. newBlock = dom.split(containerBlock, parentBlock);
  22725. } else {
  22726. dom.insertAfter(newBlock, parentBlock);
  22727. }
  22728. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22729. };
  22730. NormalizeRange.normalize(dom, rng).each(function (normRng) {
  22731. rng.setStart(normRng.startContainer, normRng.startOffset);
  22732. rng.setEnd(normRng.endContainer, normRng.endOffset);
  22733. });
  22734. container = rng.startContainer;
  22735. offset = rng.startOffset;
  22736. newBlockName = Settings.getForcedRootBlock(editor);
  22737. shiftKey = !!(evt && evt.shiftKey);
  22738. var ctrlKey = !!(evt && evt.ctrlKey);
  22739. if (NodeType.isElement(container) && container.hasChildNodes()) {
  22740. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  22741. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  22742. if (isAfterLastNodeInContainer && NodeType.isText(container)) {
  22743. offset = container.nodeValue.length;
  22744. } else {
  22745. offset = 0;
  22746. }
  22747. }
  22748. editableRoot = getEditableRoot$1(dom, container);
  22749. if (!editableRoot) {
  22750. return;
  22751. }
  22752. if (newBlockName && !shiftKey || !newBlockName && shiftKey) {
  22753. container = wrapSelfAndSiblingsInDefaultBlock(editor, newBlockName, rng, container, offset);
  22754. }
  22755. parentBlock = dom.getParent(container, dom.isBlock);
  22756. containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  22757. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : '';
  22758. containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : '';
  22759. if (containerBlockName === 'LI' && !ctrlKey) {
  22760. parentBlock = containerBlock;
  22761. containerBlock = containerBlock.parentNode;
  22762. parentBlockName = containerBlockName;
  22763. }
  22764. if (/^(LI|DT|DD)$/.test(parentBlockName)) {
  22765. if (dom.isEmpty(parentBlock)) {
  22766. InsertLi.insert(editor, createNewBlock, containerBlock, parentBlock, newBlockName);
  22767. return;
  22768. }
  22769. }
  22770. if (newBlockName && parentBlock === editor.getBody()) {
  22771. return;
  22772. }
  22773. newBlockName = newBlockName || 'P';
  22774. if (isCaretContainerBlock(parentBlock)) {
  22775. newBlock = showCaretContainerBlock(parentBlock);
  22776. if (dom.isEmpty(parentBlock)) {
  22777. emptyBlock(parentBlock);
  22778. }
  22779. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22780. } else if (isCaretAtStartOrEndOfBlock()) {
  22781. insertNewBlockAfter();
  22782. } else if (isCaretAtStartOrEndOfBlock(true)) {
  22783. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  22784. NewLineUtils.moveToCaretPosition(editor, containerAndSiblingName(parentBlock, 'HR') ? newBlock : parentBlock);
  22785. } else {
  22786. tmpRng = includeZwspInRange(rng).cloneRange();
  22787. tmpRng.setEndAfter(parentBlock);
  22788. fragment = tmpRng.extractContents();
  22789. trimZwsp(fragment);
  22790. trimLeadingLineBreaks(fragment);
  22791. newBlock = fragment.firstChild;
  22792. dom.insertAfter(fragment, parentBlock);
  22793. trimInlineElementsOnLeftSideOfBlock(dom, nonEmptyElementsMap, newBlock);
  22794. addBrToBlockIfNeeded(dom, parentBlock);
  22795. if (dom.isEmpty(parentBlock)) {
  22796. emptyBlock(parentBlock);
  22797. }
  22798. newBlock.normalize();
  22799. if (dom.isEmpty(newBlock)) {
  22800. dom.remove(newBlock);
  22801. insertNewBlockAfter();
  22802. } else {
  22803. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22804. }
  22805. }
  22806. dom.setAttrib(newBlock, 'id', '');
  22807. editor.fire('NewBlock', { newBlock: newBlock });
  22808. };
  22809. var InsertBlock = { insert: insert$1 };
  22810. var hasRightSideContent = function (schema, container, parentBlock) {
  22811. var walker = new TreeWalker(container, parentBlock);
  22812. var node;
  22813. var nonEmptyElementsMap = schema.getNonEmptyElements();
  22814. while (node = walker.next()) {
  22815. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
  22816. return true;
  22817. }
  22818. }
  22819. };
  22820. var scrollToBr = function (dom, selection, brElm) {
  22821. var marker = dom.create('span', {}, '&nbsp;');
  22822. brElm.parentNode.insertBefore(marker, brElm);
  22823. selection.scrollIntoView(marker);
  22824. dom.remove(marker);
  22825. };
  22826. var moveSelectionToBr = function (dom, selection, brElm, extraBr) {
  22827. var rng = dom.createRng();
  22828. if (!extraBr) {
  22829. rng.setStartAfter(brElm);
  22830. rng.setEndAfter(brElm);
  22831. } else {
  22832. rng.setStartBefore(brElm);
  22833. rng.setEndBefore(brElm);
  22834. }
  22835. selection.setRng(rng);
  22836. };
  22837. var insertBrAtCaret = function (editor, evt) {
  22838. var selection = editor.selection;
  22839. var dom = editor.dom;
  22840. var rng = selection.getRng();
  22841. var brElm;
  22842. var extraBr;
  22843. NormalizeRange.normalize(dom, rng).each(function (normRng) {
  22844. rng.setStart(normRng.startContainer, normRng.startOffset);
  22845. rng.setEnd(normRng.endContainer, normRng.endOffset);
  22846. });
  22847. var offset = rng.startOffset;
  22848. var container = rng.startContainer;
  22849. if (container.nodeType === 1 && container.hasChildNodes()) {
  22850. var isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  22851. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  22852. if (isAfterLastNodeInContainer && container.nodeType === 3) {
  22853. offset = container.nodeValue.length;
  22854. } else {
  22855. offset = 0;
  22856. }
  22857. }
  22858. var parentBlock = dom.getParent(container, dom.isBlock);
  22859. var containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  22860. var containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : '';
  22861. var isControlKey = !!(evt && evt.ctrlKey);
  22862. if (containerBlockName === 'LI' && !isControlKey) {
  22863. parentBlock = containerBlock;
  22864. }
  22865. if (container && container.nodeType === 3 && offset >= container.nodeValue.length) {
  22866. if (!hasRightSideContent(editor.schema, container, parentBlock)) {
  22867. brElm = dom.create('br');
  22868. rng.insertNode(brElm);
  22869. rng.setStartAfter(brElm);
  22870. rng.setEndAfter(brElm);
  22871. extraBr = true;
  22872. }
  22873. }
  22874. brElm = dom.create('br');
  22875. rangeInsertNode(dom, rng, brElm);
  22876. scrollToBr(dom, selection, brElm);
  22877. moveSelectionToBr(dom, selection, brElm, extraBr);
  22878. editor.undoManager.add();
  22879. };
  22880. var insertBrBefore = function (editor, inline) {
  22881. var br = Element.fromTag('br');
  22882. before(Element.fromDom(inline), br);
  22883. editor.undoManager.add();
  22884. };
  22885. var insertBrAfter = function (editor, inline) {
  22886. if (!hasBrAfter(editor.getBody(), inline)) {
  22887. after(Element.fromDom(inline), Element.fromTag('br'));
  22888. }
  22889. var br = Element.fromTag('br');
  22890. after(Element.fromDom(inline), br);
  22891. scrollToBr(editor.dom, editor.selection, br.dom());
  22892. moveSelectionToBr(editor.dom, editor.selection, br.dom(), false);
  22893. editor.undoManager.add();
  22894. };
  22895. var isBeforeBr$1 = function (pos) {
  22896. return NodeType.isBr(pos.getNode());
  22897. };
  22898. var hasBrAfter = function (rootNode, startNode) {
  22899. if (isBeforeBr$1(CaretPosition$1.after(startNode))) {
  22900. return true;
  22901. } else {
  22902. return CaretFinder.nextPosition(rootNode, CaretPosition$1.after(startNode)).map(function (pos) {
  22903. return NodeType.isBr(pos.getNode());
  22904. }).getOr(false);
  22905. }
  22906. };
  22907. var isAnchorLink = function (elm) {
  22908. return elm && elm.nodeName === 'A' && 'href' in elm;
  22909. };
  22910. var isInsideAnchor = function (location) {
  22911. return location.fold(constant(false), isAnchorLink, isAnchorLink, constant(false));
  22912. };
  22913. var readInlineAnchorLocation = function (editor) {
  22914. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  22915. var position = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22916. return BoundaryLocation.readLocation(isInlineTarget, editor.getBody(), position).filter(isInsideAnchor);
  22917. };
  22918. var insertBrOutsideAnchor = function (editor, location) {
  22919. location.fold(noop, curry(insertBrBefore, editor), curry(insertBrAfter, editor), noop);
  22920. };
  22921. var insert$2 = function (editor, evt) {
  22922. var anchorLocation = readInlineAnchorLocation(editor);
  22923. if (anchorLocation.isSome()) {
  22924. anchorLocation.each(curry(insertBrOutsideAnchor, editor));
  22925. } else {
  22926. insertBrAtCaret(editor, evt);
  22927. }
  22928. };
  22929. var InsertBr = { insert: insert$2 };
  22930. var matchesSelector = function (editor, selector) {
  22931. return NewLineUtils.getParentBlock(editor).filter(function (parentBlock) {
  22932. return selector.length > 0 && is(Element.fromDom(parentBlock), selector);
  22933. }).isSome();
  22934. };
  22935. var shouldInsertBr = function (editor) {
  22936. return matchesSelector(editor, Settings.getBrNewLineSelector(editor));
  22937. };
  22938. var shouldBlockNewLine = function (editor) {
  22939. return matchesSelector(editor, Settings.getNoNewLineSelector(editor));
  22940. };
  22941. var ContextSelectors = {
  22942. shouldInsertBr: shouldInsertBr,
  22943. shouldBlockNewLine: shouldBlockNewLine
  22944. };
  22945. var newLineAction = Adt.generate([
  22946. { br: [] },
  22947. { block: [] },
  22948. { none: [] }
  22949. ]);
  22950. var shouldBlockNewLine$1 = function (editor, shiftKey) {
  22951. return ContextSelectors.shouldBlockNewLine(editor);
  22952. };
  22953. var isBrMode = function (requiredState) {
  22954. return function (editor, shiftKey) {
  22955. var brMode = Settings.getForcedRootBlock(editor) === '';
  22956. return brMode === requiredState;
  22957. };
  22958. };
  22959. var inListBlock = function (requiredState) {
  22960. return function (editor, shiftKey) {
  22961. return NewLineUtils.isListItemParentBlock(editor) === requiredState;
  22962. };
  22963. };
  22964. var inBlock = function (blockName, requiredState) {
  22965. return function (editor, shiftKey) {
  22966. var state = NewLineUtils.getParentBlockName(editor) === blockName.toUpperCase();
  22967. return state === requiredState;
  22968. };
  22969. };
  22970. var inPreBlock = function (requiredState) {
  22971. return inBlock('pre', requiredState);
  22972. };
  22973. var inSummaryBlock = function () {
  22974. return inBlock('summary', true);
  22975. };
  22976. var shouldPutBrInPre$1 = function (requiredState) {
  22977. return function (editor, shiftKey) {
  22978. return Settings.shouldPutBrInPre(editor) === requiredState;
  22979. };
  22980. };
  22981. var inBrContext = function (editor, shiftKey) {
  22982. return ContextSelectors.shouldInsertBr(editor);
  22983. };
  22984. var hasShiftKey = function (editor, shiftKey) {
  22985. return shiftKey;
  22986. };
  22987. var canInsertIntoEditableRoot = function (editor) {
  22988. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  22989. var rootEditable = NewLineUtils.getEditableRoot(editor.dom, editor.selection.getStart());
  22990. return rootEditable && editor.schema.isValidChild(rootEditable.nodeName, forcedRootBlock ? forcedRootBlock : 'P');
  22991. };
  22992. var match$2 = function (predicates, action) {
  22993. return function (editor, shiftKey) {
  22994. var isMatch = foldl(predicates, function (res, p) {
  22995. return res && p(editor, shiftKey);
  22996. }, true);
  22997. return isMatch ? Option.some(action) : Option.none();
  22998. };
  22999. };
  23000. var getAction$1 = function (editor, evt) {
  23001. return LazyEvaluator.evaluateUntil([
  23002. match$2([shouldBlockNewLine$1], newLineAction.none()),
  23003. match$2([inSummaryBlock()], newLineAction.br()),
  23004. match$2([
  23005. inPreBlock(true),
  23006. shouldPutBrInPre$1(false),
  23007. hasShiftKey
  23008. ], newLineAction.br()),
  23009. match$2([
  23010. inPreBlock(true),
  23011. shouldPutBrInPre$1(false)
  23012. ], newLineAction.block()),
  23013. match$2([
  23014. inPreBlock(true),
  23015. shouldPutBrInPre$1(true),
  23016. hasShiftKey
  23017. ], newLineAction.block()),
  23018. match$2([
  23019. inPreBlock(true),
  23020. shouldPutBrInPre$1(true)
  23021. ], newLineAction.br()),
  23022. match$2([
  23023. inListBlock(true),
  23024. hasShiftKey
  23025. ], newLineAction.br()),
  23026. match$2([inListBlock(true)], newLineAction.block()),
  23027. match$2([
  23028. isBrMode(true),
  23029. hasShiftKey,
  23030. canInsertIntoEditableRoot
  23031. ], newLineAction.block()),
  23032. match$2([isBrMode(true)], newLineAction.br()),
  23033. match$2([inBrContext], newLineAction.br()),
  23034. match$2([
  23035. isBrMode(false),
  23036. hasShiftKey
  23037. ], newLineAction.br()),
  23038. match$2([canInsertIntoEditableRoot], newLineAction.block())
  23039. ], [
  23040. editor,
  23041. !!(evt && evt.shiftKey)
  23042. ]).getOr(newLineAction.none());
  23043. };
  23044. var NewLineAction = { getAction: getAction$1 };
  23045. var insert$3 = function (editor, evt) {
  23046. NewLineAction.getAction(editor, evt).fold(function () {
  23047. InsertBr.insert(editor, evt);
  23048. }, function () {
  23049. InsertBlock.insert(editor, evt);
  23050. }, noop);
  23051. };
  23052. var InsertNewLine = { insert: insert$3 };
  23053. var handleEnterKeyEvent = function (editor, event) {
  23054. if (event.isDefaultPrevented()) {
  23055. return;
  23056. }
  23057. event.preventDefault();
  23058. endTypingLevelIgnoreLocks(editor.undoManager);
  23059. editor.undoManager.transact(function () {
  23060. if (editor.selection.isCollapsed() === false) {
  23061. editor.execCommand('Delete');
  23062. }
  23063. InsertNewLine.insert(editor, event);
  23064. });
  23065. };
  23066. var setup$a = function (editor) {
  23067. editor.on('keydown', function (event) {
  23068. if (event.keyCode === VK.ENTER) {
  23069. handleEnterKeyEvent(editor, event);
  23070. }
  23071. });
  23072. };
  23073. var EnterKey = { setup: setup$a };
  23074. var insertTextAtPosition = function (text, pos) {
  23075. var container = pos.container();
  23076. var offset = pos.offset();
  23077. if (NodeType.isText(container)) {
  23078. container.insertData(offset, text);
  23079. return Option.some(CaretPosition(container, offset + text.length));
  23080. } else {
  23081. return getElementFromPosition(pos).map(function (elm) {
  23082. var textNode = Element.fromText(text);
  23083. if (pos.isAtEnd()) {
  23084. after(elm, textNode);
  23085. } else {
  23086. before(elm, textNode);
  23087. }
  23088. return CaretPosition(textNode.dom(), text.length);
  23089. });
  23090. }
  23091. };
  23092. var insertNbspAtPosition = curry(insertTextAtPosition, '\xA0');
  23093. var insertSpaceAtPosition = curry(insertTextAtPosition, ' ');
  23094. var nbsp = '\xA0';
  23095. var isInMiddleOfText = function (pos) {
  23096. return CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd();
  23097. };
  23098. var getClosestBlock$1 = function (root, pos) {
  23099. var parentBlocks = filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), isBlock);
  23100. return head(parentBlocks).getOr(root);
  23101. };
  23102. var hasSpaceBefore = function (root, pos) {
  23103. if (isInMiddleOfText(pos)) {
  23104. return isAfterSpace(pos);
  23105. } else {
  23106. return isAfterSpace(pos) || CaretFinder.prevPosition(getClosestBlock$1(root, pos).dom(), pos).exists(isAfterSpace);
  23107. }
  23108. };
  23109. var hasSpaceAfter = function (root, pos) {
  23110. if (isInMiddleOfText(pos)) {
  23111. return isBeforeSpace(pos);
  23112. } else {
  23113. return isBeforeSpace(pos) || CaretFinder.nextPosition(getClosestBlock$1(root, pos).dom(), pos).exists(isBeforeSpace);
  23114. }
  23115. };
  23116. var isPreValue = function (value) {
  23117. return contains([
  23118. 'pre',
  23119. 'pre-wrap'
  23120. ], value);
  23121. };
  23122. var isInPre = function (pos) {
  23123. return getElementFromPosition(pos).bind(function (elm) {
  23124. return closest(elm, isElement$1);
  23125. }).exists(function (elm) {
  23126. return isPreValue(get$2(elm, 'white-space'));
  23127. });
  23128. };
  23129. var isAtBeginningOfBody = function (root, pos) {
  23130. return CaretFinder.prevPosition(root.dom(), pos).isNone();
  23131. };
  23132. var isAtEndOfBody = function (root, pos) {
  23133. return CaretFinder.nextPosition(root.dom(), pos).isNone();
  23134. };
  23135. var isAtLineBoundary = function (root, pos) {
  23136. return isAtBeginningOfBody(root, pos) || isAtEndOfBody(root, pos) || isAtStartOfBlock(root, pos) || isAtEndOfBlock(root, pos) || isAfterBr(root, pos) || isBeforeBr(root, pos);
  23137. };
  23138. var needsToHaveNbsp = function (root, pos) {
  23139. if (isInPre(pos)) {
  23140. return false;
  23141. } else {
  23142. return isAtLineBoundary(root, pos) || hasSpaceBefore(root, pos) || hasSpaceAfter(root, pos);
  23143. }
  23144. };
  23145. var needsToBeNbspLeft = function (root, pos) {
  23146. if (isInPre(pos)) {
  23147. return false;
  23148. } else {
  23149. return isAtStartOfBlock(root, pos) || isBeforeBlock(root, pos) || isAfterBr(root, pos) || hasSpaceBefore(root, pos);
  23150. }
  23151. };
  23152. var leanRight = function (pos) {
  23153. var container = pos.container();
  23154. var offset = pos.offset();
  23155. if (NodeType.isText(container) && offset < container.data.length) {
  23156. return CaretPosition(container, offset + 1);
  23157. } else {
  23158. return pos;
  23159. }
  23160. };
  23161. var needsToBeNbspRight = function (root, pos) {
  23162. var afterPos = leanRight(pos);
  23163. if (isInPre(afterPos)) {
  23164. return false;
  23165. } else {
  23166. return isAtEndOfBlock(root, afterPos) || isAfterBlock(root, afterPos) || isBeforeBr(root, afterPos) || hasSpaceAfter(root, afterPos);
  23167. }
  23168. };
  23169. var needsToBeNbsp = function (root, pos) {
  23170. return needsToBeNbspLeft(root, pos) || needsToBeNbspRight(root, pos);
  23171. };
  23172. var isNbspAt = function (text, offset) {
  23173. return isNbsp(text.charAt(offset));
  23174. };
  23175. var hasNbsp = function (pos) {
  23176. var container = pos.container();
  23177. return NodeType.isText(container) && contains$1(container.data, nbsp);
  23178. };
  23179. var normalizeNbspMiddle = function (text) {
  23180. var chars = text.split('');
  23181. return map(chars, function (chr, i) {
  23182. if (isNbsp(chr) && i > 0 && i < chars.length - 1 && isContent(chars[i - 1]) && isContent(chars[i + 1])) {
  23183. return ' ';
  23184. } else {
  23185. return chr;
  23186. }
  23187. }).join('');
  23188. };
  23189. var normalizeNbspAtStart = function (root, node) {
  23190. var text = node.data;
  23191. var firstPos = CaretPosition(node, 0);
  23192. if (isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos)) {
  23193. node.data = ' ' + text.slice(1);
  23194. return true;
  23195. } else {
  23196. return false;
  23197. }
  23198. };
  23199. var normalizeNbspInMiddleOfTextNode = function (node) {
  23200. var text = node.data;
  23201. var newText = normalizeNbspMiddle(text);
  23202. if (newText !== text) {
  23203. node.data = newText;
  23204. return true;
  23205. } else {
  23206. return false;
  23207. }
  23208. };
  23209. var normalizeNbspAtEnd = function (root, node) {
  23210. var text = node.data;
  23211. var lastPos = CaretPosition(node, text.length - 1);
  23212. if (isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos)) {
  23213. node.data = text.slice(0, -1) + ' ';
  23214. return true;
  23215. } else {
  23216. return false;
  23217. }
  23218. };
  23219. var normalizeNbsps = function (root, pos) {
  23220. return Option.some(pos).filter(hasNbsp).bind(function (pos) {
  23221. var container = pos.container();
  23222. var normalized = normalizeNbspAtStart(root, container) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container);
  23223. return normalized ? Option.some(pos) : Option.none();
  23224. });
  23225. };
  23226. var normalizeNbspsInEditor = function (editor) {
  23227. var root = Element.fromDom(editor.getBody());
  23228. if (editor.selection.isCollapsed()) {
  23229. normalizeNbsps(root, CaretPosition.fromRangeStart(editor.selection.getRng())).each(function (pos) {
  23230. editor.selection.setRng(pos.toRange());
  23231. });
  23232. }
  23233. };
  23234. var locationToCaretPosition = function (root) {
  23235. return function (location) {
  23236. return location.fold(function (element) {
  23237. return CaretFinder.prevPosition(root.dom(), CaretPosition$1.before(element));
  23238. }, function (element) {
  23239. return CaretFinder.firstPositionIn(element);
  23240. }, function (element) {
  23241. return CaretFinder.lastPositionIn(element);
  23242. }, function (element) {
  23243. return CaretFinder.nextPosition(root.dom(), CaretPosition$1.after(element));
  23244. });
  23245. };
  23246. };
  23247. var insertInlineBoundarySpaceOrNbsp = function (root, pos) {
  23248. return function (checkPos) {
  23249. return needsToHaveNbsp(root, checkPos) ? insertNbspAtPosition(pos) : insertSpaceAtPosition(pos);
  23250. };
  23251. };
  23252. var setSelection$1 = function (editor) {
  23253. return function (pos) {
  23254. editor.selection.setRng(pos.toRange());
  23255. editor.nodeChanged();
  23256. return true;
  23257. };
  23258. };
  23259. var insertSpaceOrNbspAtSelection = function (editor) {
  23260. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  23261. var root = Element.fromDom(editor.getBody());
  23262. if (editor.selection.isCollapsed()) {
  23263. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  23264. var caretPosition = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  23265. return BoundaryLocation.readLocation(isInlineTarget, editor.getBody(), caretPosition).bind(locationToCaretPosition(root)).bind(insertInlineBoundarySpaceOrNbsp(root, pos)).exists(setSelection$1(editor));
  23266. } else {
  23267. return false;
  23268. }
  23269. };
  23270. var executeKeydownOverride$2 = function (editor, evt) {
  23271. MatchKeys.execute([{
  23272. keyCode: VK.SPACEBAR,
  23273. action: MatchKeys.action(insertSpaceOrNbspAtSelection, editor)
  23274. }], evt).each(function (_) {
  23275. evt.preventDefault();
  23276. });
  23277. };
  23278. var setup$b = function (editor) {
  23279. editor.on('keydown', function (evt) {
  23280. if (evt.isDefaultPrevented() === false) {
  23281. executeKeydownOverride$2(editor, evt);
  23282. }
  23283. });
  23284. };
  23285. var SpaceKey = { setup: setup$b };
  23286. var findBlockCaretContainer = function (editor) {
  23287. return descendant(Element.fromDom(editor.getBody()), '*[data-mce-caret]').fold(constant(null), function (elm) {
  23288. return elm.dom();
  23289. });
  23290. };
  23291. var removeIeControlRect = function (editor) {
  23292. editor.selection.setRng(editor.selection.getRng());
  23293. };
  23294. var showBlockCaretContainer = function (editor, blockCaretContainer) {
  23295. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  23296. showCaretContainerBlock(blockCaretContainer);
  23297. removeIeControlRect(editor);
  23298. editor.selection.scrollIntoView(blockCaretContainer);
  23299. }
  23300. };
  23301. var handleBlockContainer = function (editor, e) {
  23302. var blockCaretContainer = findBlockCaretContainer(editor);
  23303. if (!blockCaretContainer) {
  23304. return;
  23305. }
  23306. if (e.type === 'compositionstart') {
  23307. e.preventDefault();
  23308. e.stopPropagation();
  23309. showBlockCaretContainer(editor, blockCaretContainer);
  23310. return;
  23311. }
  23312. if (hasContent(blockCaretContainer)) {
  23313. showBlockCaretContainer(editor, blockCaretContainer);
  23314. editor.undoManager.add();
  23315. }
  23316. };
  23317. var setup$c = function (editor) {
  23318. editor.on('keyup compositionstart', curry(handleBlockContainer, editor));
  23319. };
  23320. var CaretContainerInput = { setup: setup$c };
  23321. var browser$5 = detect$3().browser;
  23322. var setupIeInput = function (editor) {
  23323. var keypressThrotter = first(function () {
  23324. if (!editor.composing) {
  23325. normalizeNbspsInEditor(editor);
  23326. }
  23327. }, 0);
  23328. if (browser$5.isIE()) {
  23329. editor.on('keypress', function (e) {
  23330. keypressThrotter.throttle();
  23331. });
  23332. editor.on('remove', function (e) {
  23333. keypressThrotter.cancel();
  23334. });
  23335. }
  23336. };
  23337. var setup$d = function (editor) {
  23338. setupIeInput(editor);
  23339. editor.on('input', function (e) {
  23340. if (e.isComposing === false) {
  23341. normalizeNbspsInEditor(editor);
  23342. }
  23343. });
  23344. };
  23345. var executeKeydownOverride$3 = function (editor, evt) {
  23346. MatchKeys.execute([
  23347. {
  23348. keyCode: VK.END,
  23349. action: moveToLineEndPoint(editor, true)
  23350. },
  23351. {
  23352. keyCode: VK.HOME,
  23353. action: moveToLineEndPoint(editor, false)
  23354. }
  23355. ], evt).each(function (_) {
  23356. evt.preventDefault();
  23357. });
  23358. };
  23359. var setup$e = function (editor) {
  23360. editor.on('keydown', function (evt) {
  23361. if (evt.isDefaultPrevented() === false) {
  23362. executeKeydownOverride$3(editor, evt);
  23363. }
  23364. });
  23365. };
  23366. var HomeEndKeys = { setup: setup$e };
  23367. var setup$f = function (editor) {
  23368. var caret = BoundarySelection.setupSelectedState(editor);
  23369. CaretContainerInput.setup(editor);
  23370. ArrowKeys.setup(editor, caret);
  23371. DeleteBackspaceKeys.setup(editor, caret);
  23372. EnterKey.setup(editor);
  23373. SpaceKey.setup(editor);
  23374. setup$d(editor);
  23375. HomeEndKeys.setup(editor);
  23376. };
  23377. var KeyboardOverrides = { setup: setup$f };
  23378. var Quirks = function (editor) {
  23379. var each = Tools.each;
  23380. var BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection, settings = editor.settings, parser = editor.parser;
  23381. var isGecko = Env.gecko, isIE = Env.ie, isWebKit = Env.webkit;
  23382. var mceInternalUrlPrefix = 'data:text/mce-internal,';
  23383. var mceInternalDataType = isIE ? 'Text' : 'URL';
  23384. var setEditorCommandState = function (cmd, state) {
  23385. try {
  23386. editor.getDoc().execCommand(cmd, false, state);
  23387. } catch (ex) {
  23388. }
  23389. };
  23390. var isDefaultPrevented = function (e) {
  23391. return e.isDefaultPrevented();
  23392. };
  23393. var setMceInternalContent = function (e) {
  23394. var selectionHtml, internalContent;
  23395. if (e.dataTransfer) {
  23396. if (editor.selection.isCollapsed() && e.target.tagName === 'IMG') {
  23397. selection.select(e.target);
  23398. }
  23399. selectionHtml = editor.selection.getContent();
  23400. if (selectionHtml.length > 0) {
  23401. internalContent = mceInternalUrlPrefix + escape(editor.id) + ',' + escape(selectionHtml);
  23402. e.dataTransfer.setData(mceInternalDataType, internalContent);
  23403. }
  23404. }
  23405. };
  23406. var getMceInternalContent = function (e) {
  23407. var internalContent;
  23408. if (e.dataTransfer) {
  23409. internalContent = e.dataTransfer.getData(mceInternalDataType);
  23410. if (internalContent && internalContent.indexOf(mceInternalUrlPrefix) >= 0) {
  23411. internalContent = internalContent.substr(mceInternalUrlPrefix.length).split(',');
  23412. return {
  23413. id: unescape(internalContent[0]),
  23414. html: unescape(internalContent[1])
  23415. };
  23416. }
  23417. }
  23418. return null;
  23419. };
  23420. var insertClipboardContents = function (content, internal) {
  23421. if (editor.queryCommandSupported('mceInsertClipboardContent')) {
  23422. editor.execCommand('mceInsertClipboardContent', false, {
  23423. content: content,
  23424. internal: internal
  23425. });
  23426. } else {
  23427. editor.execCommand('mceInsertContent', false, content);
  23428. }
  23429. };
  23430. var emptyEditorWhenDeleting = function () {
  23431. var serializeRng = function (rng) {
  23432. var body = dom.create('body');
  23433. var contents = rng.cloneContents();
  23434. body.appendChild(contents);
  23435. return selection.serializer.serialize(body, { format: 'html' });
  23436. };
  23437. var allContentsSelected = function (rng) {
  23438. var selection = serializeRng(rng);
  23439. var allRng = dom.createRng();
  23440. allRng.selectNode(editor.getBody());
  23441. var allSelection = serializeRng(allRng);
  23442. return selection === allSelection;
  23443. };
  23444. editor.on('keydown', function (e) {
  23445. var keyCode = e.keyCode;
  23446. var isCollapsed, body;
  23447. if (!isDefaultPrevented(e) && (keyCode === DELETE || keyCode === BACKSPACE)) {
  23448. isCollapsed = editor.selection.isCollapsed();
  23449. body = editor.getBody();
  23450. if (isCollapsed && !dom.isEmpty(body)) {
  23451. return;
  23452. }
  23453. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  23454. return;
  23455. }
  23456. e.preventDefault();
  23457. editor.setContent('');
  23458. if (body.firstChild && dom.isBlock(body.firstChild)) {
  23459. editor.selection.setCursorLocation(body.firstChild, 0);
  23460. } else {
  23461. editor.selection.setCursorLocation(body, 0);
  23462. }
  23463. editor.nodeChanged();
  23464. }
  23465. });
  23466. };
  23467. var selectAll = function () {
  23468. editor.shortcuts.add('meta+a', null, 'SelectAll');
  23469. };
  23470. var inputMethodFocus = function () {
  23471. if (!editor.inline) {
  23472. dom.bind(editor.getDoc(), 'mousedown mouseup', function (e) {
  23473. var rng;
  23474. if (e.target === editor.getDoc().documentElement) {
  23475. rng = selection.getRng();
  23476. editor.getBody().focus();
  23477. if (e.type === 'mousedown') {
  23478. if (isCaretContainer(rng.startContainer)) {
  23479. return;
  23480. }
  23481. selection.placeCaretAt(e.clientX, e.clientY);
  23482. } else {
  23483. selection.setRng(rng);
  23484. }
  23485. }
  23486. });
  23487. }
  23488. };
  23489. var removeHrOnBackspace = function () {
  23490. editor.on('keydown', function (e) {
  23491. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  23492. if (!editor.getBody().getElementsByTagName('hr').length) {
  23493. return;
  23494. }
  23495. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  23496. var node = selection.getNode();
  23497. var previousSibling = node.previousSibling;
  23498. if (node.nodeName === 'HR') {
  23499. dom.remove(node);
  23500. e.preventDefault();
  23501. return;
  23502. }
  23503. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'hr') {
  23504. dom.remove(previousSibling);
  23505. e.preventDefault();
  23506. }
  23507. }
  23508. }
  23509. });
  23510. };
  23511. var focusBody = function () {
  23512. if (!domGlobals.Range.prototype.getClientRects) {
  23513. editor.on('mousedown', function (e) {
  23514. if (!isDefaultPrevented(e) && e.target.nodeName === 'HTML') {
  23515. var body_1 = editor.getBody();
  23516. body_1.blur();
  23517. Delay.setEditorTimeout(editor, function () {
  23518. body_1.focus();
  23519. });
  23520. }
  23521. });
  23522. }
  23523. };
  23524. var selectControlElements = function () {
  23525. editor.on('click', function (e) {
  23526. var target = e.target;
  23527. if (/^(IMG|HR)$/.test(target.nodeName) && dom.getContentEditableParent(target) !== 'false') {
  23528. e.preventDefault();
  23529. editor.selection.select(target);
  23530. editor.nodeChanged();
  23531. }
  23532. if (target.nodeName === 'A' && dom.hasClass(target, 'mce-item-anchor')) {
  23533. e.preventDefault();
  23534. selection.select(target);
  23535. }
  23536. });
  23537. };
  23538. var removeStylesWhenDeletingAcrossBlockElements = function () {
  23539. var getAttributeApplyFunction = function () {
  23540. var template = dom.getAttribs(selection.getStart().cloneNode(false));
  23541. return function () {
  23542. var target = selection.getStart();
  23543. if (target !== editor.getBody()) {
  23544. dom.setAttrib(target, 'style', null);
  23545. each(template, function (attr) {
  23546. target.setAttributeNode(attr.cloneNode(true));
  23547. });
  23548. }
  23549. };
  23550. };
  23551. var isSelectionAcrossElements = function () {
  23552. return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) !== dom.getParent(selection.getEnd(), dom.isBlock);
  23553. };
  23554. editor.on('keypress', function (e) {
  23555. var applyAttributes;
  23556. if (!isDefaultPrevented(e) && (e.keyCode === 8 || e.keyCode === 46) && isSelectionAcrossElements()) {
  23557. applyAttributes = getAttributeApplyFunction();
  23558. editor.getDoc().execCommand('delete', false, null);
  23559. applyAttributes();
  23560. e.preventDefault();
  23561. return false;
  23562. }
  23563. });
  23564. dom.bind(editor.getDoc(), 'cut', function (e) {
  23565. var applyAttributes;
  23566. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  23567. applyAttributes = getAttributeApplyFunction();
  23568. Delay.setEditorTimeout(editor, function () {
  23569. applyAttributes();
  23570. });
  23571. }
  23572. });
  23573. };
  23574. var disableBackspaceIntoATable = function () {
  23575. editor.on('keydown', function (e) {
  23576. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  23577. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  23578. var previousSibling = selection.getNode().previousSibling;
  23579. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'table') {
  23580. e.preventDefault();
  23581. return false;
  23582. }
  23583. }
  23584. }
  23585. });
  23586. };
  23587. var removeBlockQuoteOnBackSpace = function () {
  23588. editor.on('keydown', function (e) {
  23589. var rng, container, offset, root, parent;
  23590. if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) {
  23591. return;
  23592. }
  23593. rng = selection.getRng();
  23594. container = rng.startContainer;
  23595. offset = rng.startOffset;
  23596. root = dom.getRoot();
  23597. parent = container;
  23598. if (!rng.collapsed || offset !== 0) {
  23599. return;
  23600. }
  23601. while (parent && parent.parentNode && parent.parentNode.firstChild === parent && parent.parentNode !== root) {
  23602. parent = parent.parentNode;
  23603. }
  23604. if (parent.tagName === 'BLOCKQUOTE') {
  23605. editor.formatter.toggle('blockquote', null, parent);
  23606. rng = dom.createRng();
  23607. rng.setStart(container, 0);
  23608. rng.setEnd(container, 0);
  23609. selection.setRng(rng);
  23610. }
  23611. });
  23612. };
  23613. var setGeckoEditingOptions = function () {
  23614. var setOpts = function () {
  23615. setEditorCommandState('StyleWithCSS', false);
  23616. setEditorCommandState('enableInlineTableEditing', false);
  23617. if (!settings.object_resizing) {
  23618. setEditorCommandState('enableObjectResizing', false);
  23619. }
  23620. };
  23621. if (!settings.readonly) {
  23622. editor.on('BeforeExecCommand mousedown', setOpts);
  23623. }
  23624. };
  23625. var addBrAfterLastLinks = function () {
  23626. var fixLinks = function () {
  23627. each(dom.select('a'), function (node) {
  23628. var parentNode = node.parentNode;
  23629. var root = dom.getRoot();
  23630. if (parentNode.lastChild === node) {
  23631. while (parentNode && !dom.isBlock(parentNode)) {
  23632. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  23633. return;
  23634. }
  23635. parentNode = parentNode.parentNode;
  23636. }
  23637. dom.add(parentNode, 'br', { 'data-mce-bogus': 1 });
  23638. }
  23639. });
  23640. };
  23641. editor.on('SetContent ExecCommand', function (e) {
  23642. if (e.type === 'setcontent' || e.command === 'mceInsertLink') {
  23643. fixLinks();
  23644. }
  23645. });
  23646. };
  23647. var setDefaultBlockType = function () {
  23648. if (settings.forced_root_block) {
  23649. editor.on('init', function () {
  23650. setEditorCommandState('DefaultParagraphSeparator', Settings.getForcedRootBlock(editor));
  23651. });
  23652. }
  23653. };
  23654. var normalizeSelection = function () {
  23655. editor.on('keyup focusin mouseup', function (e) {
  23656. if (!VK.modifierPressed(e)) {
  23657. selection.normalize();
  23658. }
  23659. }, true);
  23660. };
  23661. var showBrokenImageIcon = function () {
  23662. editor.contentStyles.push('img:-moz-broken {' + '-moz-force-broken-image-icon:1;' + 'min-width:24px;' + 'min-height:24px' + '}');
  23663. };
  23664. var restoreFocusOnKeyDown = function () {
  23665. if (!editor.inline) {
  23666. editor.on('keydown', function () {
  23667. if (domGlobals.document.activeElement === domGlobals.document.body) {
  23668. editor.getWin().focus();
  23669. }
  23670. });
  23671. }
  23672. };
  23673. var bodyHeight = function () {
  23674. if (!editor.inline) {
  23675. editor.contentStyles.push('body {min-height: 150px}');
  23676. editor.on('click', function (e) {
  23677. var rng;
  23678. if (e.target.nodeName === 'HTML') {
  23679. if (Env.ie > 11) {
  23680. editor.getBody().focus();
  23681. return;
  23682. }
  23683. rng = editor.selection.getRng();
  23684. editor.getBody().focus();
  23685. editor.selection.setRng(rng);
  23686. editor.selection.normalize();
  23687. editor.nodeChanged();
  23688. }
  23689. });
  23690. }
  23691. };
  23692. var blockCmdArrowNavigation = function () {
  23693. if (Env.mac) {
  23694. editor.on('keydown', function (e) {
  23695. if (VK.metaKeyPressed(e) && !e.shiftKey && (e.keyCode === 37 || e.keyCode === 39)) {
  23696. e.preventDefault();
  23697. var selection_1 = editor.selection.getSel();
  23698. selection_1.modify('move', e.keyCode === 37 ? 'backward' : 'forward', 'lineboundary');
  23699. }
  23700. });
  23701. }
  23702. };
  23703. var disableAutoUrlDetect = function () {
  23704. setEditorCommandState('AutoUrlDetect', false);
  23705. };
  23706. var tapLinksAndImages = function () {
  23707. editor.on('click', function (e) {
  23708. var elm = e.target;
  23709. do {
  23710. if (elm.tagName === 'A') {
  23711. e.preventDefault();
  23712. return;
  23713. }
  23714. } while (elm = elm.parentNode);
  23715. });
  23716. editor.contentStyles.push('.mce-content-body {-webkit-touch-callout: none}');
  23717. };
  23718. var blockFormSubmitInsideEditor = function () {
  23719. editor.on('init', function () {
  23720. editor.dom.bind(editor.getBody(), 'submit', function (e) {
  23721. e.preventDefault();
  23722. });
  23723. });
  23724. };
  23725. var removeAppleInterchangeBrs = function () {
  23726. parser.addNodeFilter('br', function (nodes) {
  23727. var i = nodes.length;
  23728. while (i--) {
  23729. if (nodes[i].attr('class') === 'Apple-interchange-newline') {
  23730. nodes[i].remove();
  23731. }
  23732. }
  23733. });
  23734. };
  23735. var ieInternalDragAndDrop = function () {
  23736. editor.on('dragstart', function (e) {
  23737. setMceInternalContent(e);
  23738. });
  23739. editor.on('drop', function (e) {
  23740. if (!isDefaultPrevented(e)) {
  23741. var internalContent = getMceInternalContent(e);
  23742. if (internalContent && internalContent.id !== editor.id) {
  23743. e.preventDefault();
  23744. var rng = CaretRangeFromPoint.fromPoint(e.x, e.y, editor.getDoc());
  23745. selection.setRng(rng);
  23746. insertClipboardContents(internalContent.html, true);
  23747. }
  23748. }
  23749. });
  23750. };
  23751. var refreshContentEditable = function () {
  23752. };
  23753. var isHidden = function () {
  23754. var sel;
  23755. if (!isGecko || editor.removed) {
  23756. return false;
  23757. }
  23758. sel = editor.selection.getSel();
  23759. return !sel || !sel.rangeCount || sel.rangeCount === 0;
  23760. };
  23761. removeBlockQuoteOnBackSpace();
  23762. emptyEditorWhenDeleting();
  23763. if (!Env.windowsPhone) {
  23764. normalizeSelection();
  23765. }
  23766. if (isWebKit) {
  23767. inputMethodFocus();
  23768. selectControlElements();
  23769. setDefaultBlockType();
  23770. blockFormSubmitInsideEditor();
  23771. disableBackspaceIntoATable();
  23772. removeAppleInterchangeBrs();
  23773. if (Env.iOS) {
  23774. restoreFocusOnKeyDown();
  23775. bodyHeight();
  23776. tapLinksAndImages();
  23777. } else {
  23778. selectAll();
  23779. }
  23780. }
  23781. if (Env.ie >= 11) {
  23782. bodyHeight();
  23783. disableBackspaceIntoATable();
  23784. }
  23785. if (Env.ie) {
  23786. selectAll();
  23787. disableAutoUrlDetect();
  23788. ieInternalDragAndDrop();
  23789. }
  23790. if (isGecko) {
  23791. removeHrOnBackspace();
  23792. focusBody();
  23793. removeStylesWhenDeletingAcrossBlockElements();
  23794. setGeckoEditingOptions();
  23795. addBrAfterLastLinks();
  23796. showBrokenImageIcon();
  23797. blockCmdArrowNavigation();
  23798. disableBackspaceIntoATable();
  23799. }
  23800. return {
  23801. refreshContentEditable: refreshContentEditable,
  23802. isHidden: isHidden
  23803. };
  23804. };
  23805. var isTextBlockNode = function (node) {
  23806. return NodeType.isElement(node) && isTextBlock(Element.fromDom(node));
  23807. };
  23808. var normalizeSelection$1 = function (editor) {
  23809. var rng = editor.selection.getRng();
  23810. var startPos = CaretPosition.fromRangeStart(rng);
  23811. var endPos = CaretPosition.fromRangeEnd(rng);
  23812. if (CaretPosition.isElementPosition(startPos)) {
  23813. var container = startPos.container();
  23814. if (isTextBlockNode(container)) {
  23815. CaretFinder.firstPositionIn(container).each(function (pos) {
  23816. return rng.setStart(pos.container(), pos.offset());
  23817. });
  23818. }
  23819. }
  23820. if (CaretPosition.isElementPosition(endPos)) {
  23821. var container = startPos.container();
  23822. if (isTextBlockNode(container)) {
  23823. CaretFinder.lastPositionIn(container).each(function (pos) {
  23824. return rng.setEnd(pos.container(), pos.offset());
  23825. });
  23826. }
  23827. }
  23828. editor.selection.setRng(RangeNormalizer.normalize(rng));
  23829. };
  23830. var setup$g = function (editor) {
  23831. editor.on('click', function (e) {
  23832. if (e.detail >= 3) {
  23833. normalizeSelection$1(editor);
  23834. }
  23835. });
  23836. };
  23837. var preventSummaryToggle = function (editor) {
  23838. editor.on('click', function (e) {
  23839. if (editor.dom.getParent(e.target, 'details')) {
  23840. e.preventDefault();
  23841. }
  23842. });
  23843. };
  23844. var filterDetails = function (editor) {
  23845. editor.parser.addNodeFilter('details', function (elms) {
  23846. each(elms, function (details) {
  23847. details.attr('data-mce-open', details.attr('open'));
  23848. details.attr('open', 'open');
  23849. });
  23850. });
  23851. editor.serializer.addNodeFilter('details', function (elms) {
  23852. each(elms, function (details) {
  23853. var open = details.attr('data-mce-open');
  23854. details.attr('open', isString(open) ? open : null);
  23855. details.attr('data-mce-open', null);
  23856. });
  23857. });
  23858. };
  23859. var setup$h = function (editor) {
  23860. preventSummaryToggle(editor);
  23861. filterDetails(editor);
  23862. };
  23863. var DOM$3 = DOMUtils$1.DOM;
  23864. var appendStyle = function (editor, text) {
  23865. var head = Element.fromDom(editor.getDoc().head);
  23866. var tag = Element.fromTag('style');
  23867. set(tag, 'type', 'text/css');
  23868. append(tag, Element.fromText(text));
  23869. append(head, tag);
  23870. };
  23871. var createParser = function (editor) {
  23872. var parser = DomParser(editor.settings, editor.schema);
  23873. parser.addAttributeFilter('src,href,style,tabindex', function (nodes, name) {
  23874. var i = nodes.length, node;
  23875. var dom = editor.dom;
  23876. var value, internalName;
  23877. while (i--) {
  23878. node = nodes[i];
  23879. value = node.attr(name);
  23880. internalName = 'data-mce-' + name;
  23881. if (!node.attr(internalName)) {
  23882. if (value.indexOf('data:') === 0 || value.indexOf('blob:') === 0) {
  23883. continue;
  23884. }
  23885. if (name === 'style') {
  23886. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  23887. if (!value.length) {
  23888. value = null;
  23889. }
  23890. node.attr(internalName, value);
  23891. node.attr(name, value);
  23892. } else if (name === 'tabindex') {
  23893. node.attr(internalName, value);
  23894. node.attr(name, null);
  23895. } else {
  23896. node.attr(internalName, editor.convertURL(value, name, node.name));
  23897. }
  23898. }
  23899. }
  23900. });
  23901. parser.addNodeFilter('script', function (nodes) {
  23902. var i = nodes.length, node, type;
  23903. while (i--) {
  23904. node = nodes[i];
  23905. type = node.attr('type') || 'no/type';
  23906. if (type.indexOf('mce-') !== 0) {
  23907. node.attr('type', 'mce-' + type);
  23908. }
  23909. }
  23910. });
  23911. parser.addNodeFilter('#cdata', function (nodes) {
  23912. var i = nodes.length, node;
  23913. while (i--) {
  23914. node = nodes[i];
  23915. node.type = 8;
  23916. node.name = '#comment';
  23917. node.value = '[CDATA[' + node.value + ']]';
  23918. }
  23919. });
  23920. parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function (nodes) {
  23921. var i = nodes.length, node;
  23922. var nonEmptyElements = editor.schema.getNonEmptyElements();
  23923. while (i--) {
  23924. node = nodes[i];
  23925. if (node.isEmpty(nonEmptyElements) && node.getAll('br').length === 0) {
  23926. node.append(new Node$1('br', 1)).shortEnded = true;
  23927. }
  23928. }
  23929. });
  23930. return parser;
  23931. };
  23932. var autoFocus = function (editor) {
  23933. if (editor.settings.auto_focus) {
  23934. Delay.setEditorTimeout(editor, function () {
  23935. var focusEditor;
  23936. if (editor.settings.auto_focus === true) {
  23937. focusEditor = editor;
  23938. } else {
  23939. focusEditor = editor.editorManager.get(editor.settings.auto_focus);
  23940. }
  23941. if (!focusEditor.destroyed) {
  23942. focusEditor.focus();
  23943. }
  23944. }, 100);
  23945. }
  23946. };
  23947. var initEditor = function (editor) {
  23948. editor.bindPendingEventDelegates();
  23949. editor.initialized = true;
  23950. editor.fire('init');
  23951. editor.focus(true);
  23952. editor.nodeChanged({ initial: true });
  23953. editor.execCallback('init_instance_callback', editor);
  23954. autoFocus(editor);
  23955. };
  23956. var getStyleSheetLoader = function (editor) {
  23957. return editor.inline ? DOM$3.styleSheetLoader : editor.dom.styleSheetLoader;
  23958. };
  23959. var initContentBody = function (editor, skipWrite) {
  23960. var settings = editor.settings;
  23961. var targetElm = editor.getElement();
  23962. var doc = editor.getDoc(), body, contentCssText;
  23963. if (!settings.inline) {
  23964. editor.getElement().style.visibility = editor.orgVisibility;
  23965. }
  23966. if (!skipWrite && !editor.inline) {
  23967. doc.open();
  23968. doc.write(editor.iframeHTML);
  23969. doc.close();
  23970. }
  23971. if (editor.inline) {
  23972. editor.on('remove', function () {
  23973. var bodyEl = this.getBody();
  23974. DOM$3.removeClass(bodyEl, 'mce-content-body');
  23975. DOM$3.removeClass(bodyEl, 'mce-edit-focus');
  23976. DOM$3.setAttrib(bodyEl, 'contentEditable', null);
  23977. });
  23978. DOM$3.addClass(targetElm, 'mce-content-body');
  23979. editor.contentDocument = doc = domGlobals.document;
  23980. editor.contentWindow = domGlobals.window;
  23981. editor.bodyElement = targetElm;
  23982. editor.contentAreaContainer = targetElm;
  23983. settings.root_name = targetElm.nodeName.toLowerCase();
  23984. }
  23985. body = editor.getBody();
  23986. body.disabled = true;
  23987. editor.readonly = settings.readonly;
  23988. if (!editor.readonly) {
  23989. if (editor.inline && DOM$3.getStyle(body, 'position', true) === 'static') {
  23990. body.style.position = 'relative';
  23991. }
  23992. body.contentEditable = editor.getParam('content_editable_state', true);
  23993. }
  23994. body.disabled = false;
  23995. editor.editorUpload = EditorUpload(editor);
  23996. editor.schema = Schema(settings);
  23997. editor.dom = DOMUtils$1(doc, {
  23998. keep_values: true,
  23999. url_converter: editor.convertURL,
  24000. url_converter_scope: editor,
  24001. hex_colors: settings.force_hex_style_colors,
  24002. update_styles: true,
  24003. root_element: editor.inline ? editor.getBody() : null,
  24004. collect: function () {
  24005. return editor.inline;
  24006. },
  24007. schema: editor.schema,
  24008. contentCssCors: Settings.shouldUseContentCssCors(editor),
  24009. referrerPolicy: Settings.getReferrerPolicy(editor),
  24010. onSetAttrib: function (e) {
  24011. editor.fire('SetAttrib', e);
  24012. }
  24013. });
  24014. editor.parser = createParser(editor);
  24015. editor.serializer = Serializer$1(settings, editor);
  24016. editor.selection = Selection$1(editor.dom, editor.getWin(), editor.serializer, editor);
  24017. editor.annotator = Annotator(editor);
  24018. editor.formatter = Formatter(editor);
  24019. editor.undoManager = UndoManager(editor);
  24020. editor._nodeChangeDispatcher = new NodeChange(editor);
  24021. editor._selectionOverrides = SelectionOverrides(editor);
  24022. setup$h(editor);
  24023. setup$g(editor);
  24024. KeyboardOverrides.setup(editor);
  24025. ForceBlocks.setup(editor);
  24026. editor.fire('PreInit');
  24027. if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
  24028. doc.body.spellcheck = false;
  24029. DOM$3.setAttrib(body, 'spellcheck', 'false');
  24030. }
  24031. editor.quirks = Quirks(editor);
  24032. editor.fire('PostRender');
  24033. var directionality = Settings.getDirectionality(editor);
  24034. if (directionality !== undefined) {
  24035. body.dir = directionality;
  24036. }
  24037. if (settings.protect) {
  24038. editor.on('BeforeSetContent', function (e) {
  24039. Tools.each(settings.protect, function (pattern) {
  24040. e.content = e.content.replace(pattern, function (str) {
  24041. return '<!--mce:protected ' + escape(str) + '-->';
  24042. });
  24043. });
  24044. });
  24045. }
  24046. editor.on('SetContent', function () {
  24047. editor.addVisual(editor.getBody());
  24048. });
  24049. editor.load({
  24050. initial: true,
  24051. format: 'html'
  24052. });
  24053. editor.startContent = editor.getContent({ format: 'raw' });
  24054. editor.on('compositionstart compositionend', function (e) {
  24055. editor.composing = e.type === 'compositionstart';
  24056. });
  24057. if (editor.contentStyles.length > 0) {
  24058. contentCssText = '';
  24059. Tools.each(editor.contentStyles, function (style) {
  24060. contentCssText += style + '\r\n';
  24061. });
  24062. editor.dom.addStyle(contentCssText);
  24063. }
  24064. getStyleSheetLoader(editor).loadAll(editor.contentCSS, function (_) {
  24065. initEditor(editor);
  24066. }, function (urls) {
  24067. initEditor(editor);
  24068. });
  24069. if (settings.content_style) {
  24070. appendStyle(editor, settings.content_style);
  24071. }
  24072. };
  24073. var InitContentBody = { initContentBody: initContentBody };
  24074. var DOM$4 = DOMUtils$1.DOM;
  24075. var relaxDomain = function (editor, ifr) {
  24076. if (domGlobals.document.domain !== domGlobals.window.location.hostname && Env.browser.isIE()) {
  24077. var bodyUuid = Uuid.uuid('mce');
  24078. editor[bodyUuid] = function () {
  24079. InitContentBody.initContentBody(editor);
  24080. };
  24081. var domainRelaxUrl = 'javascript:(function(){' + 'document.open();document.domain="' + domGlobals.document.domain + '";' + 'var ed = window.parent.tinymce.get("' + editor.id + '");document.write(ed.iframeHTML);' + 'document.close();ed.' + bodyUuid + '(true);})()';
  24082. DOM$4.setAttrib(ifr, 'src', domainRelaxUrl);
  24083. return true;
  24084. }
  24085. return false;
  24086. };
  24087. var createIframeElement = function (id, title, height, customAttrs) {
  24088. var iframe = Element.fromTag('iframe');
  24089. setAll(iframe, customAttrs);
  24090. setAll(iframe, {
  24091. id: id + '_ifr',
  24092. frameBorder: '0',
  24093. allowTransparency: 'true',
  24094. title: title
  24095. });
  24096. add$3(iframe, 'tox-edit-area__iframe');
  24097. return iframe;
  24098. };
  24099. var getIframeHtml = function (editor) {
  24100. var bodyId, bodyClass, iframeHTML;
  24101. iframeHTML = Settings.getDocType(editor) + '<html><head>';
  24102. if (Settings.getDocumentBaseUrl(editor) !== editor.documentBaseUrl) {
  24103. iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />';
  24104. }
  24105. iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  24106. bodyId = Settings.getBodyId(editor);
  24107. bodyClass = Settings.getBodyClass(editor);
  24108. if (Settings.getContentSecurityPolicy(editor)) {
  24109. iframeHTML += '<meta http-equiv="Content-Security-Policy" content="' + Settings.getContentSecurityPolicy(editor) + '" />';
  24110. }
  24111. iframeHTML += '</head><body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '" data-id="' + editor.id + '"><br></body></html>';
  24112. return iframeHTML;
  24113. };
  24114. var createIframe = function (editor, o) {
  24115. var title = editor.editorManager.translate('Rich Text Area. Press ALT-0 for help.');
  24116. var ifr = createIframeElement(editor.id, title, o.height, Settings.getIframeAttrs(editor)).dom();
  24117. ifr.onload = function () {
  24118. ifr.onload = null;
  24119. editor.fire('load');
  24120. };
  24121. var isDomainRelaxed = relaxDomain(editor, ifr);
  24122. editor.contentAreaContainer = o.iframeContainer;
  24123. editor.iframeElement = ifr;
  24124. editor.iframeHTML = getIframeHtml(editor);
  24125. DOM$4.add(o.iframeContainer, ifr);
  24126. return isDomainRelaxed;
  24127. };
  24128. var init$1 = function (editor, boxInfo) {
  24129. var isDomainRelaxed = createIframe(editor, boxInfo);
  24130. if (boxInfo.editorContainer) {
  24131. DOM$4.get(boxInfo.editorContainer).style.display = editor.orgDisplay;
  24132. editor.hidden = DOM$4.isHidden(boxInfo.editorContainer);
  24133. }
  24134. editor.getElement().style.display = 'none';
  24135. DOM$4.setAttrib(editor.id, 'aria-hidden', 'true');
  24136. if (!isDomainRelaxed) {
  24137. InitContentBody.initContentBody(editor);
  24138. }
  24139. };
  24140. var InitIframe = { init: init$1 };
  24141. var isContentCssSkinName = function (url) {
  24142. return /^[a-z0-9\-]+$/i.test(url);
  24143. };
  24144. var getContentCssUrls = function (editor) {
  24145. var contentCss = Settings.getContentCss(editor);
  24146. var skinUrl = editor.editorManager.baseURL + '/skins/content';
  24147. var suffix = editor.editorManager.suffix;
  24148. var contentCssFile = 'content' + suffix + '.css';
  24149. var inline = editor.inline === true;
  24150. return map(contentCss, function (url) {
  24151. if (isContentCssSkinName(url) && !inline) {
  24152. return skinUrl + '/' + url + '/' + contentCssFile;
  24153. } else {
  24154. return editor.documentBaseURI.toAbsolute(url);
  24155. }
  24156. });
  24157. };
  24158. var appendContentCssFromSettings = function (editor) {
  24159. editor.contentCSS = editor.contentCSS.concat(getContentCssUrls(editor));
  24160. };
  24161. var DOM$5 = DOMUtils$1.DOM;
  24162. var initPlugin = function (editor, initializedPlugins, plugin) {
  24163. var Plugin = PluginManager.get(plugin);
  24164. var pluginUrl = PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, '');
  24165. plugin = Tools.trim(plugin);
  24166. if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) {
  24167. Tools.each(PluginManager.dependencies(plugin), function (dep) {
  24168. initPlugin(editor, initializedPlugins, dep);
  24169. });
  24170. if (editor.plugins[plugin]) {
  24171. return;
  24172. }
  24173. try {
  24174. var pluginInstance = new Plugin(editor, pluginUrl, editor.$);
  24175. editor.plugins[plugin] = pluginInstance;
  24176. if (pluginInstance.init) {
  24177. pluginInstance.init(editor, pluginUrl);
  24178. initializedPlugins.push(plugin);
  24179. }
  24180. } catch (e) {
  24181. ErrorReporter.pluginInitError(editor, plugin, e);
  24182. }
  24183. }
  24184. };
  24185. var trimLegacyPrefix = function (name) {
  24186. return name.replace(/^\-/, '');
  24187. };
  24188. var initPlugins = function (editor) {
  24189. var initializedPlugins = [];
  24190. Tools.each(editor.settings.plugins.split(/[ ,]/), function (name) {
  24191. initPlugin(editor, initializedPlugins, trimLegacyPrefix(name));
  24192. });
  24193. };
  24194. var initIcons = function (editor) {
  24195. var iconPackName = Tools.trim(editor.settings.icons);
  24196. var currentIcons = editor.ui.registry.getAll().icons;
  24197. var defaultIcons = getAll();
  24198. var loadIcons = __assign(__assign({}, defaultIcons), IconManager.get(iconPackName).icons);
  24199. each$1(loadIcons, function (svgData, icon) {
  24200. if (!has(currentIcons, icon)) {
  24201. editor.ui.registry.addIcon(icon, svgData);
  24202. }
  24203. });
  24204. };
  24205. var initTheme = function (editor) {
  24206. var theme = editor.settings.theme;
  24207. if (isString(theme)) {
  24208. editor.settings.theme = trimLegacyPrefix(theme);
  24209. var Theme = ThemeManager.get(theme);
  24210. editor.theme = new Theme(editor, ThemeManager.urls[theme]);
  24211. if (editor.theme.init) {
  24212. editor.theme.init(editor, ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ''), editor.$);
  24213. }
  24214. } else {
  24215. editor.theme = {};
  24216. }
  24217. };
  24218. var renderFromLoadedTheme = function (editor) {
  24219. return editor.theme.renderUI();
  24220. };
  24221. var renderFromThemeFunc = function (editor) {
  24222. var elm = editor.getElement();
  24223. var theme = editor.settings.theme;
  24224. var info = theme(editor, elm);
  24225. if (info.editorContainer.nodeType) {
  24226. info.editorContainer.id = info.editorContainer.id || editor.id + '_parent';
  24227. }
  24228. if (info.iframeContainer && info.iframeContainer.nodeType) {
  24229. info.iframeContainer.id = info.iframeContainer.id || editor.id + '_iframecontainer';
  24230. }
  24231. info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight;
  24232. return info;
  24233. };
  24234. var createThemeFalseResult = function (element) {
  24235. return {
  24236. editorContainer: element,
  24237. iframeContainer: element
  24238. };
  24239. };
  24240. var renderThemeFalseIframe = function (targetElement) {
  24241. var iframeContainer = DOM$5.create('div');
  24242. DOM$5.insertAfter(iframeContainer, targetElement);
  24243. return createThemeFalseResult(iframeContainer);
  24244. };
  24245. var renderThemeFalse = function (editor) {
  24246. var targetElement = editor.getElement();
  24247. return editor.inline ? createThemeFalseResult(null) : renderThemeFalseIframe(targetElement);
  24248. };
  24249. var renderThemeUi = function (editor) {
  24250. var elm = editor.getElement();
  24251. editor.orgDisplay = elm.style.display;
  24252. if (isString(editor.settings.theme)) {
  24253. return renderFromLoadedTheme(editor);
  24254. } else if (isFunction(editor.settings.theme)) {
  24255. return renderFromThemeFunc(editor);
  24256. } else {
  24257. return renderThemeFalse(editor);
  24258. }
  24259. };
  24260. var init$2 = function (editor) {
  24261. editor.fire('ScriptsLoaded');
  24262. initIcons(editor);
  24263. initTheme(editor);
  24264. initPlugins(editor);
  24265. var boxInfo = renderThemeUi(editor);
  24266. editor.editorContainer = boxInfo.editorContainer ? boxInfo.editorContainer : null;
  24267. appendContentCssFromSettings(editor);
  24268. if (editor.inline) {
  24269. return InitContentBody.initContentBody(editor);
  24270. } else {
  24271. return InitIframe.init(editor, boxInfo);
  24272. }
  24273. };
  24274. var Init = { init: init$2 };
  24275. var DOM$6 = DOMUtils$1.DOM;
  24276. var hasSkipLoadPrefix = function (name) {
  24277. return name.charAt(0) === '-';
  24278. };
  24279. var loadLanguage = function (scriptLoader, editor) {
  24280. var languageCode = Settings.getLanguageCode(editor);
  24281. var languageUrl = Settings.getLanguageUrl(editor);
  24282. if (I18n.hasCode(languageCode) === false && languageCode !== 'en') {
  24283. var url_1 = languageUrl !== '' ? languageUrl : editor.editorManager.baseURL + '/langs/' + languageCode + '.js';
  24284. scriptLoader.add(url_1, noop, undefined, function () {
  24285. ErrorReporter.languageLoadError(url_1, languageCode);
  24286. });
  24287. }
  24288. };
  24289. var loadTheme = function (scriptLoader, editor, suffix, callback) {
  24290. var settings = editor.settings, theme = settings.theme;
  24291. if (isString(theme)) {
  24292. if (!hasSkipLoadPrefix(theme) && !ThemeManager.urls.hasOwnProperty(theme)) {
  24293. var themeUrl = settings.theme_url;
  24294. if (themeUrl) {
  24295. ThemeManager.load(theme, editor.documentBaseURI.toAbsolute(themeUrl));
  24296. } else {
  24297. ThemeManager.load(theme, 'themes/' + theme + '/theme' + suffix + '.js');
  24298. }
  24299. }
  24300. scriptLoader.loadQueue(function () {
  24301. ThemeManager.waitFor(theme, callback);
  24302. });
  24303. } else {
  24304. callback();
  24305. }
  24306. };
  24307. var getIconsUrlMetaFromUrl = function (editor) {
  24308. return Option.from(Settings.getIconsUrl(editor)).filter(function (url) {
  24309. return url.length > 0;
  24310. }).map(function (url) {
  24311. return {
  24312. url: url,
  24313. name: Option.none()
  24314. };
  24315. });
  24316. };
  24317. var getIconsUrlMetaFromName = function (editor) {
  24318. return Option.from(Settings.getIconPackName(editor)).filter(function (name) {
  24319. return name.length > 0 && !IconManager.has(name);
  24320. }).map(function (name) {
  24321. return {
  24322. url: editor.editorManager.baseURL + '/icons/' + name + '/icons.js',
  24323. name: Option.some(name)
  24324. };
  24325. });
  24326. };
  24327. var loadIcons = function (scriptLoader, editor) {
  24328. getIconsUrlMetaFromUrl(editor).orThunk(function () {
  24329. return getIconsUrlMetaFromName(editor);
  24330. }).each(function (urlMeta) {
  24331. scriptLoader.add(urlMeta.url, noop, undefined, function () {
  24332. ErrorReporter.iconsLoadError(urlMeta.url, urlMeta.name.getOrUndefined());
  24333. });
  24334. });
  24335. };
  24336. var loadPlugins = function (settings, suffix) {
  24337. if (isArray(settings.plugins)) {
  24338. settings.plugins = settings.plugins.join(' ');
  24339. }
  24340. Tools.each(settings.external_plugins, function (url, name) {
  24341. PluginManager.load(name, url, noop, undefined, function () {
  24342. ErrorReporter.pluginLoadError(name, url);
  24343. });
  24344. settings.plugins += ' ' + name;
  24345. });
  24346. Tools.each(settings.plugins.split(/[ ,]/), function (plugin) {
  24347. plugin = Tools.trim(plugin);
  24348. if (plugin && !PluginManager.urls[plugin]) {
  24349. if (hasSkipLoadPrefix(plugin)) {
  24350. plugin = plugin.substr(1, plugin.length);
  24351. var dependencies = PluginManager.dependencies(plugin);
  24352. Tools.each(dependencies, function (dep) {
  24353. var defaultSettings = {
  24354. prefix: 'plugins/',
  24355. resource: dep,
  24356. suffix: '/plugin' + suffix + '.js'
  24357. };
  24358. dep = PluginManager.createUrl(defaultSettings, dep);
  24359. PluginManager.load(dep.resource, dep, noop, undefined, function () {
  24360. ErrorReporter.pluginLoadError(dep.prefix + dep.resource + dep.suffix, dep.resource);
  24361. });
  24362. });
  24363. } else {
  24364. var url_2 = {
  24365. prefix: 'plugins/',
  24366. resource: plugin,
  24367. suffix: '/plugin' + suffix + '.js'
  24368. };
  24369. PluginManager.load(plugin, url_2, noop, undefined, function () {
  24370. ErrorReporter.pluginLoadError(url_2.prefix + url_2.resource + url_2.suffix, plugin);
  24371. });
  24372. }
  24373. }
  24374. });
  24375. };
  24376. var loadScripts = function (editor, suffix) {
  24377. var scriptLoader = ScriptLoader.ScriptLoader;
  24378. loadTheme(scriptLoader, editor, suffix, function () {
  24379. loadLanguage(scriptLoader, editor);
  24380. loadIcons(scriptLoader, editor);
  24381. loadPlugins(editor.settings, suffix);
  24382. scriptLoader.loadQueue(function () {
  24383. if (!editor.removed) {
  24384. Init.init(editor);
  24385. }
  24386. }, editor, function () {
  24387. if (!editor.removed) {
  24388. Init.init(editor);
  24389. }
  24390. });
  24391. });
  24392. };
  24393. var render = function (editor) {
  24394. var settings = editor.settings, id = editor.id;
  24395. I18n.setCode(Settings.getLanguageCode(editor));
  24396. var readyHandler = function () {
  24397. DOM$6.unbind(domGlobals.window, 'ready', readyHandler);
  24398. editor.render();
  24399. };
  24400. if (!EventUtils.Event.domLoaded) {
  24401. DOM$6.bind(domGlobals.window, 'ready', readyHandler);
  24402. return;
  24403. }
  24404. if (!editor.getElement()) {
  24405. return;
  24406. }
  24407. if (!Env.contentEditable) {
  24408. return;
  24409. }
  24410. if (!settings.inline) {
  24411. editor.orgVisibility = editor.getElement().style.visibility;
  24412. editor.getElement().style.visibility = 'hidden';
  24413. } else {
  24414. editor.inline = true;
  24415. }
  24416. var form = editor.getElement().form || DOM$6.getParent(id, 'form');
  24417. if (form) {
  24418. editor.formElement = form;
  24419. if (settings.hidden_input && !NodeType.isTextareaOrInput(editor.getElement())) {
  24420. DOM$6.insertAfter(DOM$6.create('input', {
  24421. type: 'hidden',
  24422. name: id
  24423. }), id);
  24424. editor.hasHiddenInput = true;
  24425. }
  24426. editor.formEventDelegate = function (e) {
  24427. editor.fire(e.type, e);
  24428. };
  24429. DOM$6.bind(form, 'submit reset', editor.formEventDelegate);
  24430. editor.on('reset', function () {
  24431. editor.resetContent();
  24432. });
  24433. if (settings.submit_patch && !form.submit.nodeType && !form.submit.length && !form._mceOldSubmit) {
  24434. form._mceOldSubmit = form.submit;
  24435. form.submit = function () {
  24436. editor.editorManager.triggerSave();
  24437. editor.setDirty(false);
  24438. return form._mceOldSubmit(form);
  24439. };
  24440. }
  24441. }
  24442. editor.windowManager = WindowManager(editor);
  24443. editor.notificationManager = NotificationManager(editor);
  24444. if (settings.encoding === 'xml') {
  24445. editor.on('GetContent', function (e) {
  24446. if (e.save) {
  24447. e.content = DOM$6.encode(e.content);
  24448. }
  24449. });
  24450. }
  24451. if (settings.add_form_submit_trigger) {
  24452. editor.on('submit', function () {
  24453. if (editor.initialized) {
  24454. editor.save();
  24455. }
  24456. });
  24457. }
  24458. if (settings.add_unload_trigger) {
  24459. editor._beforeUnload = function () {
  24460. if (editor.initialized && !editor.destroyed && !editor.isHidden()) {
  24461. editor.save({
  24462. format: 'raw',
  24463. no_events: true,
  24464. set_dirty: false
  24465. });
  24466. }
  24467. };
  24468. editor.editorManager.on('BeforeUnload', editor._beforeUnload);
  24469. }
  24470. editor.editorManager.add(editor);
  24471. loadScripts(editor, editor.suffix);
  24472. };
  24473. var Render = { render: render };
  24474. var internalContentEditableAttr = 'data-mce-contenteditable';
  24475. var toggleClass = function (elm, cls, state) {
  24476. if (has$2(elm, cls) && state === false) {
  24477. remove$4(elm, cls);
  24478. } else if (state) {
  24479. add$3(elm, cls);
  24480. }
  24481. };
  24482. var setEditorCommandState = function (editor, cmd, state) {
  24483. try {
  24484. editor.getDoc().execCommand(cmd, false, state);
  24485. } catch (ex) {
  24486. }
  24487. };
  24488. var setContentEditable = function (elm, state) {
  24489. elm.dom().contentEditable = state ? 'true' : 'false';
  24490. };
  24491. var switchOffContentEditableTrue = function (elm) {
  24492. each(descendants$1(elm, '*[contenteditable="true"]'), function (elm) {
  24493. set(elm, internalContentEditableAttr, 'true');
  24494. setContentEditable(elm, false);
  24495. });
  24496. };
  24497. var switchOnContentEditableTrue = function (elm) {
  24498. each(descendants$1(elm, '*[' + internalContentEditableAttr + '="true"]'), function (elm) {
  24499. remove(elm, internalContentEditableAttr);
  24500. setContentEditable(elm, true);
  24501. });
  24502. };
  24503. var removeFakeSelection = function (editor) {
  24504. Option.from(editor.selection.getNode()).each(function (elm) {
  24505. elm.removeAttribute('data-mce-selected');
  24506. });
  24507. };
  24508. var restoreFakeSelection = function (editor) {
  24509. editor.selection.setRng(editor.selection.getRng());
  24510. };
  24511. var toggleReadOnly = function (editor, state) {
  24512. var body = Element.fromDom(editor.getBody());
  24513. toggleClass(body, 'mce-content-readonly', state);
  24514. if (state) {
  24515. editor.selection.controlSelection.hideResizeRect();
  24516. editor._selectionOverrides.hideFakeCaret();
  24517. removeFakeSelection(editor);
  24518. editor.readonly = true;
  24519. setContentEditable(body, false);
  24520. switchOffContentEditableTrue(body);
  24521. } else {
  24522. editor.readonly = false;
  24523. setContentEditable(body, true);
  24524. switchOnContentEditableTrue(body);
  24525. setEditorCommandState(editor, 'StyleWithCSS', false);
  24526. setEditorCommandState(editor, 'enableInlineTableEditing', false);
  24527. setEditorCommandState(editor, 'enableObjectResizing', false);
  24528. if (EditorFocus.hasEditorOrUiFocus(editor)) {
  24529. editor.focus();
  24530. }
  24531. restoreFakeSelection(editor);
  24532. editor.nodeChanged();
  24533. }
  24534. };
  24535. var isReadOnly = function (editor) {
  24536. return editor.readonly === true;
  24537. };
  24538. var registerFilters = function (editor) {
  24539. editor.parser.addAttributeFilter('contenteditable', function (nodes) {
  24540. if (isReadOnly(editor)) {
  24541. each(nodes, function (node) {
  24542. node.attr(internalContentEditableAttr, node.attr('contenteditable'));
  24543. node.attr('contenteditable', 'false');
  24544. });
  24545. }
  24546. });
  24547. editor.serializer.addAttributeFilter(internalContentEditableAttr, function (nodes) {
  24548. if (isReadOnly(editor)) {
  24549. each(nodes, function (node) {
  24550. node.attr('contenteditable', node.attr(internalContentEditableAttr));
  24551. });
  24552. }
  24553. });
  24554. editor.serializer.addTempAttr(internalContentEditableAttr);
  24555. };
  24556. var registerReadOnlyContentFilters = function (editor) {
  24557. if (editor.serializer) {
  24558. registerFilters(editor);
  24559. } else {
  24560. editor.on('PreInit', function () {
  24561. registerFilters(editor);
  24562. });
  24563. }
  24564. };
  24565. var isClickEvent = function (e) {
  24566. return e.type === 'click';
  24567. };
  24568. var preventReadOnlyEvents = function (e) {
  24569. var target = e.target;
  24570. if (isClickEvent(e) && target.tagName === 'A' && !VK.metaKeyPressed(e)) {
  24571. e.preventDefault();
  24572. }
  24573. };
  24574. var registerReadOnlySelectionBlockers = function (editor) {
  24575. editor.on('ShowCaret', function (e) {
  24576. if (isReadOnly(editor)) {
  24577. e.preventDefault();
  24578. }
  24579. });
  24580. editor.on('ObjectSelected', function (e) {
  24581. if (isReadOnly(editor)) {
  24582. e.preventDefault();
  24583. }
  24584. });
  24585. };
  24586. var defaultModes = [
  24587. 'design',
  24588. 'readonly'
  24589. ];
  24590. var switchToMode = function (editor, activeMode, availableModes, mode) {
  24591. var oldMode = availableModes[activeMode.get()];
  24592. var newMode = availableModes[mode];
  24593. try {
  24594. newMode.activate();
  24595. } catch (e) {
  24596. domGlobals.console.error('problem while activating editor mode ' + mode + ':', e);
  24597. return;
  24598. }
  24599. oldMode.deactivate();
  24600. if (oldMode.editorReadOnly !== newMode.editorReadOnly) {
  24601. toggleReadOnly(editor, newMode.editorReadOnly);
  24602. }
  24603. activeMode.set(mode);
  24604. Events.fireSwitchMode(editor, mode);
  24605. };
  24606. var setMode = function (editor, availableModes, activeMode, mode) {
  24607. if (mode === activeMode.get()) {
  24608. return;
  24609. } else if (!has(availableModes, mode)) {
  24610. throw new Error('Editor mode \'' + mode + '\' is invalid');
  24611. }
  24612. if (editor.initialized) {
  24613. switchToMode(editor, activeMode, availableModes, mode);
  24614. } else {
  24615. editor.on('init', function () {
  24616. return switchToMode(editor, activeMode, availableModes, mode);
  24617. });
  24618. }
  24619. };
  24620. var registerMode = function (availableModes, mode, api) {
  24621. var _a;
  24622. if (contains(defaultModes, mode)) {
  24623. throw new Error('Cannot override default mode ' + mode);
  24624. }
  24625. return __assign(__assign({}, availableModes), (_a = {}, _a[mode] = __assign(__assign({}, api), {
  24626. deactivate: function () {
  24627. try {
  24628. api.deactivate();
  24629. } catch (e) {
  24630. domGlobals.console.error('problem while deactivating editor mode ' + mode + ':', e);
  24631. }
  24632. }
  24633. }), _a));
  24634. };
  24635. var create$4 = function (editor) {
  24636. var activeMode = Cell('design');
  24637. var availableModes = Cell({
  24638. design: {
  24639. activate: noop,
  24640. deactivate: noop,
  24641. editorReadOnly: false
  24642. },
  24643. readonly: {
  24644. activate: noop,
  24645. deactivate: noop,
  24646. editorReadOnly: true
  24647. }
  24648. });
  24649. registerReadOnlyContentFilters(editor);
  24650. registerReadOnlySelectionBlockers(editor);
  24651. return {
  24652. isReadOnly: function () {
  24653. return isReadOnly(editor);
  24654. },
  24655. set: function (mode) {
  24656. return setMode(editor, availableModes.get(), activeMode, mode);
  24657. },
  24658. get: function () {
  24659. return activeMode.get();
  24660. },
  24661. register: function (mode, api) {
  24662. availableModes.set(registerMode(availableModes.get(), mode, api));
  24663. }
  24664. };
  24665. };
  24666. var hasOnlyOneChild$1 = function (node) {
  24667. return node.firstChild && node.firstChild === node.lastChild;
  24668. };
  24669. var isPaddingNode = function (node) {
  24670. return node.name === 'br' || node.value === '\xA0';
  24671. };
  24672. var isPaddedEmptyBlock = function (schema, node) {
  24673. var blockElements = schema.getBlockElements();
  24674. return blockElements[node.name] && hasOnlyOneChild$1(node) && isPaddingNode(node.firstChild);
  24675. };
  24676. var isEmptyFragmentElement = function (schema, node) {
  24677. var nonEmptyElements = schema.getNonEmptyElements();
  24678. return node && (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node));
  24679. };
  24680. var isListFragment = function (schema, fragment) {
  24681. var firstChild = fragment.firstChild;
  24682. var lastChild = fragment.lastChild;
  24683. if (firstChild && firstChild.name === 'meta') {
  24684. firstChild = firstChild.next;
  24685. }
  24686. if (lastChild && lastChild.attr('id') === 'mce_marker') {
  24687. lastChild = lastChild.prev;
  24688. }
  24689. if (isEmptyFragmentElement(schema, lastChild)) {
  24690. lastChild = lastChild.prev;
  24691. }
  24692. if (!firstChild || firstChild !== lastChild) {
  24693. return false;
  24694. }
  24695. return firstChild.name === 'ul' || firstChild.name === 'ol';
  24696. };
  24697. var cleanupDomFragment = function (domFragment) {
  24698. var firstChild = domFragment.firstChild;
  24699. var lastChild = domFragment.lastChild;
  24700. if (firstChild && firstChild.nodeName === 'META') {
  24701. firstChild.parentNode.removeChild(firstChild);
  24702. }
  24703. if (lastChild && lastChild.id === 'mce_marker') {
  24704. lastChild.parentNode.removeChild(lastChild);
  24705. }
  24706. return domFragment;
  24707. };
  24708. var toDomFragment = function (dom, serializer, fragment) {
  24709. var html = serializer.serialize(fragment);
  24710. var domFragment = dom.createFragment(html);
  24711. return cleanupDomFragment(domFragment);
  24712. };
  24713. var listItems$1 = function (elm) {
  24714. return Tools.grep(elm.childNodes, function (child) {
  24715. return child.nodeName === 'LI';
  24716. });
  24717. };
  24718. var isPadding = function (node) {
  24719. return node.data === '\xA0' || NodeType.isBr(node);
  24720. };
  24721. var isListItemPadded = function (node) {
  24722. return node && node.firstChild && node.firstChild === node.lastChild && isPadding(node.firstChild);
  24723. };
  24724. var isEmptyOrPadded = function (elm) {
  24725. return !elm.firstChild || isListItemPadded(elm);
  24726. };
  24727. var trimListItems = function (elms) {
  24728. return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1]) ? elms.slice(0, -1) : elms;
  24729. };
  24730. var getParentLi = function (dom, node) {
  24731. var parentBlock = dom.getParent(node, dom.isBlock);
  24732. return parentBlock && parentBlock.nodeName === 'LI' ? parentBlock : null;
  24733. };
  24734. var isParentBlockLi = function (dom, node) {
  24735. return !!getParentLi(dom, node);
  24736. };
  24737. var getSplit = function (parentNode, rng) {
  24738. var beforeRng = rng.cloneRange();
  24739. var afterRng = rng.cloneRange();
  24740. beforeRng.setStartBefore(parentNode);
  24741. afterRng.setEndAfter(parentNode);
  24742. return [
  24743. beforeRng.cloneContents(),
  24744. afterRng.cloneContents()
  24745. ];
  24746. };
  24747. var findFirstIn = function (node, rootNode) {
  24748. var caretPos = CaretPosition$1.before(node);
  24749. var caretWalker = CaretWalker(rootNode);
  24750. var newCaretPos = caretWalker.next(caretPos);
  24751. return newCaretPos ? newCaretPos.toRange() : null;
  24752. };
  24753. var findLastOf = function (node, rootNode) {
  24754. var caretPos = CaretPosition$1.after(node);
  24755. var caretWalker = CaretWalker(rootNode);
  24756. var newCaretPos = caretWalker.prev(caretPos);
  24757. return newCaretPos ? newCaretPos.toRange() : null;
  24758. };
  24759. var insertMiddle = function (target, elms, rootNode, rng) {
  24760. var parts = getSplit(target, rng);
  24761. var parentElm = target.parentNode;
  24762. parentElm.insertBefore(parts[0], target);
  24763. Tools.each(elms, function (li) {
  24764. parentElm.insertBefore(li, target);
  24765. });
  24766. parentElm.insertBefore(parts[1], target);
  24767. parentElm.removeChild(target);
  24768. return findLastOf(elms[elms.length - 1], rootNode);
  24769. };
  24770. var insertBefore$1 = function (target, elms, rootNode) {
  24771. var parentElm = target.parentNode;
  24772. Tools.each(elms, function (elm) {
  24773. parentElm.insertBefore(elm, target);
  24774. });
  24775. return findFirstIn(target, rootNode);
  24776. };
  24777. var insertAfter$1 = function (target, elms, rootNode, dom) {
  24778. dom.insertAfter(elms.reverse(), target);
  24779. return findLastOf(elms[0], rootNode);
  24780. };
  24781. var insertAtCaret = function (serializer, dom, rng, fragment) {
  24782. var domFragment = toDomFragment(dom, serializer, fragment);
  24783. var liTarget = getParentLi(dom, rng.startContainer);
  24784. var liElms = trimListItems(listItems$1(domFragment.firstChild));
  24785. var BEGINNING = 1, END = 2;
  24786. var rootNode = dom.getRoot();
  24787. var isAt = function (location) {
  24788. var caretPos = CaretPosition$1.fromRangeStart(rng);
  24789. var caretWalker = CaretWalker(dom.getRoot());
  24790. var newPos = location === BEGINNING ? caretWalker.prev(caretPos) : caretWalker.next(caretPos);
  24791. return newPos ? getParentLi(dom, newPos.getNode()) !== liTarget : true;
  24792. };
  24793. if (isAt(BEGINNING)) {
  24794. return insertBefore$1(liTarget, liElms, rootNode);
  24795. } else if (isAt(END)) {
  24796. return insertAfter$1(liTarget, liElms, rootNode, dom);
  24797. }
  24798. return insertMiddle(liTarget, liElms, rootNode, rng);
  24799. };
  24800. var InsertList = {
  24801. isListFragment: isListFragment,
  24802. insertAtCaret: insertAtCaret,
  24803. isParentBlockLi: isParentBlockLi,
  24804. trimListItems: trimListItems,
  24805. listItems: listItems$1
  24806. };
  24807. var isAfterNbsp = function (container, offset) {
  24808. return NodeType.isText(container) && container.nodeValue[offset - 1] === '\xA0';
  24809. };
  24810. var trimOrPadLeftRight = function (rng, html) {
  24811. var container, offset;
  24812. container = rng.startContainer;
  24813. offset = rng.startOffset;
  24814. var hasSiblingText = function (siblingName) {
  24815. return container[siblingName] && container[siblingName].nodeType === 3;
  24816. };
  24817. if (container.nodeType === 3) {
  24818. if (offset > 0) {
  24819. html = html.replace(/^&nbsp;/, ' ');
  24820. } else if (!hasSiblingText('previousSibling')) {
  24821. html = html.replace(/^ /, '&nbsp;');
  24822. }
  24823. if (offset < container.length) {
  24824. html = html.replace(/&nbsp;(<br>|)$/, ' ');
  24825. } else if (!hasSiblingText('nextSibling')) {
  24826. html = html.replace(/(&nbsp;| )(<br>|)$/, '&nbsp;');
  24827. }
  24828. }
  24829. return html;
  24830. };
  24831. var trimNbspAfterDeleteAndPadValue = function (rng, value) {
  24832. var container, offset;
  24833. container = rng.startContainer;
  24834. offset = rng.startOffset;
  24835. if (container.nodeType === 3 && rng.collapsed) {
  24836. if (container.data[offset] === '\xA0') {
  24837. container.deleteData(offset, 1);
  24838. if (!/[\u00a0| ]$/.test(value)) {
  24839. value += ' ';
  24840. }
  24841. } else if (container.data[offset - 1] === '\xA0') {
  24842. container.deleteData(offset - 1, 1);
  24843. if (!/[\u00a0| ]$/.test(value)) {
  24844. value = ' ' + value;
  24845. }
  24846. }
  24847. }
  24848. return value;
  24849. };
  24850. var isTableCell$5 = NodeType.matchNodeNames([
  24851. 'td',
  24852. 'th'
  24853. ]);
  24854. var selectionSetContent = function (editor, content) {
  24855. var rng = editor.selection.getRng();
  24856. var container = rng.startContainer;
  24857. var offset = rng.startOffset;
  24858. if (rng.collapsed && isAfterNbsp(container, offset) && NodeType.isText(container)) {
  24859. container.insertData(offset - 1, ' ');
  24860. container.deleteData(offset, 1);
  24861. rng.setStart(container, offset);
  24862. rng.setEnd(container, offset);
  24863. editor.selection.setRng(rng);
  24864. }
  24865. editor.selection.setContent(content);
  24866. };
  24867. var validInsertion = function (editor, value, parentNode) {
  24868. if (parentNode.getAttribute('data-mce-bogus') === 'all') {
  24869. parentNode.parentNode.insertBefore(editor.dom.createFragment(value), parentNode);
  24870. } else {
  24871. var node = parentNode.firstChild;
  24872. var node2 = parentNode.lastChild;
  24873. if (!node || node === node2 && node.nodeName === 'BR') {
  24874. editor.dom.setHTML(parentNode, value);
  24875. } else {
  24876. selectionSetContent(editor, value);
  24877. }
  24878. }
  24879. };
  24880. var trimBrsFromTableCell = function (dom, elm) {
  24881. Option.from(dom.getParent(elm, 'td,th')).map(Element.fromDom).each(PaddingBr.trimBlockTrailingBr);
  24882. };
  24883. var reduceInlineTextElements = function (editor, merge) {
  24884. var textInlineElements = editor.schema.getTextInlineElements();
  24885. var dom = editor.dom;
  24886. if (merge) {
  24887. var root_1 = editor.getBody(), elementUtils_1 = new ElementUtils(dom);
  24888. Tools.each(dom.select('*[data-mce-fragment]'), function (node) {
  24889. for (var testNode = node.parentNode; testNode && testNode !== root_1; testNode = testNode.parentNode) {
  24890. if (textInlineElements[node.nodeName.toLowerCase()] && elementUtils_1.compare(testNode, node)) {
  24891. dom.remove(node, true);
  24892. }
  24893. }
  24894. });
  24895. }
  24896. };
  24897. var markFragmentElements = function (fragment) {
  24898. var node = fragment;
  24899. while (node = node.walk()) {
  24900. if (node.type === 1) {
  24901. node.attr('data-mce-fragment', '1');
  24902. }
  24903. }
  24904. };
  24905. var umarkFragmentElements = function (elm) {
  24906. Tools.each(elm.getElementsByTagName('*'), function (elm) {
  24907. elm.removeAttribute('data-mce-fragment');
  24908. });
  24909. };
  24910. var isPartOfFragment = function (node) {
  24911. return !!node.getAttribute('data-mce-fragment');
  24912. };
  24913. var canHaveChildren = function (editor, node) {
  24914. return node && !editor.schema.getShortEndedElements()[node.nodeName];
  24915. };
  24916. var moveSelectionToMarker = function (editor, marker) {
  24917. var parentEditableFalseElm, parentBlock, nextRng;
  24918. var dom = editor.dom, selection = editor.selection;
  24919. var node, node2;
  24920. var getContentEditableFalseParent = function (node) {
  24921. var root = editor.getBody();
  24922. for (; node && node !== root; node = node.parentNode) {
  24923. if (editor.dom.getContentEditable(node) === 'false') {
  24924. return node;
  24925. }
  24926. }
  24927. return null;
  24928. };
  24929. if (!marker) {
  24930. return;
  24931. }
  24932. editor.selection.scrollIntoView(marker);
  24933. parentEditableFalseElm = getContentEditableFalseParent(marker);
  24934. if (parentEditableFalseElm) {
  24935. dom.remove(marker);
  24936. selection.select(parentEditableFalseElm);
  24937. return;
  24938. }
  24939. var rng = dom.createRng();
  24940. node = marker.previousSibling;
  24941. if (node && node.nodeType === 3) {
  24942. rng.setStart(node, node.nodeValue.length);
  24943. if (!Env.ie) {
  24944. node2 = marker.nextSibling;
  24945. if (node2 && node2.nodeType === 3) {
  24946. node.appendData(node2.data);
  24947. node2.parentNode.removeChild(node2);
  24948. }
  24949. }
  24950. } else {
  24951. rng.setStartBefore(marker);
  24952. rng.setEndBefore(marker);
  24953. }
  24954. var findNextCaretRng = function (rng) {
  24955. var caretPos = CaretPosition$1.fromRangeStart(rng);
  24956. var caretWalker = CaretWalker(editor.getBody());
  24957. caretPos = caretWalker.next(caretPos);
  24958. if (caretPos) {
  24959. return caretPos.toRange();
  24960. }
  24961. };
  24962. parentBlock = dom.getParent(marker, dom.isBlock);
  24963. dom.remove(marker);
  24964. if (parentBlock && dom.isEmpty(parentBlock)) {
  24965. editor.$(parentBlock).empty();
  24966. rng.setStart(parentBlock, 0);
  24967. rng.setEnd(parentBlock, 0);
  24968. if (!isTableCell$5(parentBlock) && !isPartOfFragment(parentBlock) && (nextRng = findNextCaretRng(rng))) {
  24969. rng = nextRng;
  24970. dom.remove(parentBlock);
  24971. } else {
  24972. dom.add(parentBlock, dom.create('br', { 'data-mce-bogus': '1' }));
  24973. }
  24974. }
  24975. selection.setRng(rng);
  24976. };
  24977. var insertHtmlAtCaret = function (editor, value, details) {
  24978. var parser, serializer, parentNode, rootNode, fragment, args;
  24979. var marker, rng, node, bookmarkHtml, merge;
  24980. var selection = editor.selection, dom = editor.dom;
  24981. if (/^ | $/.test(value)) {
  24982. value = trimOrPadLeftRight(selection.getRng(), value);
  24983. }
  24984. parser = editor.parser;
  24985. merge = details.merge;
  24986. serializer = Serializer({ validate: editor.settings.validate }, editor.schema);
  24987. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">&#xFEFF;&#x200B;</span>';
  24988. args = {
  24989. content: value,
  24990. format: 'html',
  24991. selection: true,
  24992. paste: details.paste
  24993. };
  24994. args = editor.fire('BeforeSetContent', args);
  24995. if (args.isDefaultPrevented()) {
  24996. editor.fire('SetContent', {
  24997. content: args.content,
  24998. format: 'html',
  24999. selection: true,
  25000. paste: details.paste
  25001. });
  25002. return;
  25003. }
  25004. value = args.content;
  25005. if (value.indexOf('{$caret}') === -1) {
  25006. value += '{$caret}';
  25007. }
  25008. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  25009. rng = selection.getRng();
  25010. var caretElement = rng.startContainer || (rng.parentElement ? rng.parentElement() : null);
  25011. var body = editor.getBody();
  25012. if (caretElement === body && selection.isCollapsed()) {
  25013. if (dom.isBlock(body.firstChild) && canHaveChildren(editor, body.firstChild) && dom.isEmpty(body.firstChild)) {
  25014. rng = dom.createRng();
  25015. rng.setStart(body.firstChild, 0);
  25016. rng.setEnd(body.firstChild, 0);
  25017. selection.setRng(rng);
  25018. }
  25019. }
  25020. if (!selection.isCollapsed()) {
  25021. editor.selection.setRng(RangeNormalizer.normalize(editor.selection.getRng()));
  25022. editor.getDoc().execCommand('Delete', false, null);
  25023. value = trimNbspAfterDeleteAndPadValue(editor.selection.getRng(), value);
  25024. }
  25025. parentNode = selection.getNode();
  25026. var parserArgs = {
  25027. context: parentNode.nodeName.toLowerCase(),
  25028. data: details.data,
  25029. insert: true
  25030. };
  25031. fragment = parser.parse(value, parserArgs);
  25032. if (details.paste === true && InsertList.isListFragment(editor.schema, fragment) && InsertList.isParentBlockLi(dom, parentNode)) {
  25033. rng = InsertList.insertAtCaret(serializer, dom, editor.selection.getRng(), fragment);
  25034. editor.selection.setRng(rng);
  25035. editor.fire('SetContent', args);
  25036. return;
  25037. }
  25038. markFragmentElements(fragment);
  25039. node = fragment.lastChild;
  25040. if (node.attr('id') === 'mce_marker') {
  25041. marker = node;
  25042. for (node = node.prev; node; node = node.walk(true)) {
  25043. if (node.type === 3 || !dom.isBlock(node.name)) {
  25044. if (editor.schema.isValidChild(node.parent.name, 'span')) {
  25045. node.parent.insert(marker, node, node.name === 'br');
  25046. }
  25047. break;
  25048. }
  25049. }
  25050. }
  25051. editor._selectionOverrides.showBlockCaretContainer(parentNode);
  25052. if (!parserArgs.invalid) {
  25053. value = serializer.serialize(fragment);
  25054. validInsertion(editor, value, parentNode);
  25055. } else {
  25056. selectionSetContent(editor, bookmarkHtml);
  25057. parentNode = selection.getNode();
  25058. rootNode = editor.getBody();
  25059. if (parentNode.nodeType === 9) {
  25060. parentNode = node = rootNode;
  25061. } else {
  25062. node = parentNode;
  25063. }
  25064. while (node !== rootNode) {
  25065. parentNode = node;
  25066. node = node.parentNode;
  25067. }
  25068. value = parentNode === rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  25069. value = serializer.serialize(parser.parse(value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function () {
  25070. return serializer.serialize(fragment);
  25071. })));
  25072. if (parentNode === rootNode) {
  25073. dom.setHTML(rootNode, value);
  25074. } else {
  25075. dom.setOuterHTML(parentNode, value);
  25076. }
  25077. }
  25078. reduceInlineTextElements(editor, merge);
  25079. moveSelectionToMarker(editor, dom.get('mce_marker'));
  25080. umarkFragmentElements(editor.getBody());
  25081. trimBrsFromTableCell(editor.dom, editor.selection.getStart());
  25082. editor.fire('SetContent', args);
  25083. editor.addVisual();
  25084. };
  25085. var processValue = function (value) {
  25086. var details;
  25087. if (typeof value !== 'string') {
  25088. details = Tools.extend({
  25089. paste: value.paste,
  25090. data: { paste: value.paste }
  25091. }, value);
  25092. return {
  25093. content: value.content,
  25094. details: details
  25095. };
  25096. }
  25097. return {
  25098. content: value,
  25099. details: {}
  25100. };
  25101. };
  25102. var insertAtCaret$1 = function (editor, value) {
  25103. var result = processValue(value);
  25104. insertHtmlAtCaret(editor, result.content, result.details);
  25105. };
  25106. var InsertContent = { insertAtCaret: insertAtCaret$1 };
  25107. var nativeCommand = function (editor, command) {
  25108. editor.getDoc().execCommand(command, false, null);
  25109. };
  25110. var deleteCommand = function (editor) {
  25111. if (Outdent.backspaceDelete(editor, false)) {
  25112. return;
  25113. } else if (CefDelete.backspaceDelete(editor, false)) {
  25114. return;
  25115. } else if (CefBoundaryDelete.backspaceDelete(editor, false)) {
  25116. return;
  25117. } else if (BoundaryDelete.backspaceDelete(editor, false)) {
  25118. return;
  25119. } else if (BlockBoundaryDelete.backspaceDelete(editor, false)) {
  25120. return;
  25121. } else if (TableDelete.backspaceDelete(editor)) {
  25122. return;
  25123. } else if (BlockRangeDelete.backspaceDelete(editor, false)) {
  25124. return;
  25125. } else if (InlineFormatDelete.backspaceDelete(editor, false)) {
  25126. return;
  25127. } else {
  25128. nativeCommand(editor, 'Delete');
  25129. DeleteUtils.paddEmptyBody(editor);
  25130. }
  25131. };
  25132. var forwardDeleteCommand = function (editor) {
  25133. if (CefDelete.backspaceDelete(editor, true)) {
  25134. return;
  25135. } else if (CefBoundaryDelete.backspaceDelete(editor, true)) {
  25136. return;
  25137. } else if (BoundaryDelete.backspaceDelete(editor, true)) {
  25138. return;
  25139. } else if (BlockBoundaryDelete.backspaceDelete(editor, true)) {
  25140. return;
  25141. } else if (TableDelete.backspaceDelete(editor)) {
  25142. return;
  25143. } else if (BlockRangeDelete.backspaceDelete(editor, true)) {
  25144. return;
  25145. } else if (InlineFormatDelete.backspaceDelete(editor, true)) {
  25146. return;
  25147. } else {
  25148. nativeCommand(editor, 'ForwardDelete');
  25149. }
  25150. };
  25151. var DeleteCommands = {
  25152. deleteCommand: deleteCommand,
  25153. forwardDeleteCommand: forwardDeleteCommand
  25154. };
  25155. var getSpecifiedFontProp = function (propName, rootElm, elm) {
  25156. var getProperty = function (elm) {
  25157. return getRaw(elm, propName);
  25158. };
  25159. var isRoot = function (elm) {
  25160. return eq(Element.fromDom(rootElm), elm);
  25161. };
  25162. return closest(Element.fromDom(elm), function (elm) {
  25163. return getProperty(elm).isSome();
  25164. }, isRoot).bind(getProperty);
  25165. };
  25166. var round$1 = function (number, precision) {
  25167. var factor = Math.pow(10, precision);
  25168. return Math.round(number * factor) / factor;
  25169. };
  25170. var toPt = function (fontSize, precision) {
  25171. if (/[0-9.]+px$/.test(fontSize)) {
  25172. return round$1(parseInt(fontSize, 10) * 72 / 96, precision || 0) + 'pt';
  25173. }
  25174. return fontSize;
  25175. };
  25176. var normalizeFontFamily = function (fontFamily) {
  25177. return fontFamily.replace(/[\'\"\\]/g, '').replace(/,\s+/g, ',');
  25178. };
  25179. var getComputedFontProp = function (propName, elm) {
  25180. return Option.from(DOMUtils$1.DOM.getStyle(elm, propName, true));
  25181. };
  25182. var getFontProp = function (propName) {
  25183. return function (rootElm, elm) {
  25184. return Option.from(elm).map(Element.fromDom).filter(isElement$1).bind(function (element) {
  25185. return getSpecifiedFontProp(propName, rootElm, element.dom()).or(getComputedFontProp(propName, element.dom()));
  25186. }).getOr('');
  25187. };
  25188. };
  25189. var FontInfo = {
  25190. getFontSize: getFontProp('font-size'),
  25191. getFontFamily: compose(normalizeFontFamily, getFontProp('font-family')),
  25192. toPt: toPt
  25193. };
  25194. var findFirstCaretElement = function (editor) {
  25195. return CaretFinder.firstPositionIn(editor.getBody()).map(function (caret) {
  25196. var container = caret.container();
  25197. return NodeType.isText(container) ? container.parentNode : container;
  25198. });
  25199. };
  25200. var isRangeAtStartOfNode = function (rng, root) {
  25201. return rng.startContainer === root && rng.startOffset === 0;
  25202. };
  25203. var getCaretElement = function (editor) {
  25204. return Option.from(editor.selection.getRng()).bind(function (rng) {
  25205. var root = editor.getBody();
  25206. return isRangeAtStartOfNode(rng, root) ? Option.none() : Option.from(editor.selection.getStart(true));
  25207. });
  25208. };
  25209. var fromFontSizeNumber = function (editor, value) {
  25210. if (/^[0-9\.]+$/.test(value)) {
  25211. var fontSizeNumber = parseInt(value, 10);
  25212. if (fontSizeNumber >= 1 && fontSizeNumber <= 7) {
  25213. var fontSizes = Settings.getFontStyleValues(editor);
  25214. var fontClasses = Settings.getFontSizeClasses(editor);
  25215. if (fontClasses) {
  25216. return fontClasses[fontSizeNumber - 1] || value;
  25217. } else {
  25218. return fontSizes[fontSizeNumber - 1] || value;
  25219. }
  25220. } else {
  25221. return value;
  25222. }
  25223. } else {
  25224. return value;
  25225. }
  25226. };
  25227. var normalizeFontNames = function (font) {
  25228. var fonts = font.split(/\s*,\s*/);
  25229. return map(fonts, function (font) {
  25230. if (font.indexOf(' ') !== -1 && !(startsWith(font, '"') || startsWith(font, '\''))) {
  25231. return '"' + font + '"';
  25232. } else {
  25233. return font;
  25234. }
  25235. }).join(',');
  25236. };
  25237. var fontNameAction = function (editor, value) {
  25238. var font = fromFontSizeNumber(editor, value);
  25239. editor.formatter.toggle('fontname', { value: normalizeFontNames(font) });
  25240. editor.nodeChanged();
  25241. };
  25242. var fontNameQuery = function (editor) {
  25243. return getCaretElement(editor).fold(function () {
  25244. return findFirstCaretElement(editor).map(function (caretElement) {
  25245. return FontInfo.getFontFamily(editor.getBody(), caretElement);
  25246. }).getOr('');
  25247. }, function (caretElement) {
  25248. return FontInfo.getFontFamily(editor.getBody(), caretElement);
  25249. });
  25250. };
  25251. var fontSizeAction = function (editor, value) {
  25252. editor.formatter.toggle('fontsize', { value: fromFontSizeNumber(editor, value) });
  25253. editor.nodeChanged();
  25254. };
  25255. var fontSizeQuery = function (editor) {
  25256. return getCaretElement(editor).fold(function () {
  25257. return findFirstCaretElement(editor).map(function (caretElement) {
  25258. return FontInfo.getFontSize(editor.getBody(), caretElement);
  25259. }).getOr('');
  25260. }, function (caretElement) {
  25261. return FontInfo.getFontSize(editor.getBody(), caretElement);
  25262. });
  25263. };
  25264. var each$g = Tools.each;
  25265. var map$3 = Tools.map, inArray$2 = Tools.inArray;
  25266. var EditorCommands = function () {
  25267. function EditorCommands(editor) {
  25268. this.commands = {
  25269. state: {},
  25270. exec: {},
  25271. value: {}
  25272. };
  25273. this.editor = editor;
  25274. this.setupCommands(editor);
  25275. }
  25276. EditorCommands.prototype.execCommand = function (command, ui, value, args) {
  25277. var func, customCommand, state = false;
  25278. var self = this;
  25279. if (self.editor.removed) {
  25280. return;
  25281. }
  25282. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(command) && (!args || !args.skip_focus)) {
  25283. self.editor.focus();
  25284. } else {
  25285. SelectionBookmark.restore(self.editor);
  25286. }
  25287. args = self.editor.fire('BeforeExecCommand', {
  25288. command: command,
  25289. ui: ui,
  25290. value: value
  25291. });
  25292. if (args.isDefaultPrevented()) {
  25293. return false;
  25294. }
  25295. customCommand = command.toLowerCase();
  25296. if (func = self.commands.exec[customCommand]) {
  25297. func(customCommand, ui, value);
  25298. self.editor.fire('ExecCommand', {
  25299. command: command,
  25300. ui: ui,
  25301. value: value
  25302. });
  25303. return true;
  25304. }
  25305. each$g(this.editor.plugins, function (p) {
  25306. if (p.execCommand && p.execCommand(command, ui, value)) {
  25307. self.editor.fire('ExecCommand', {
  25308. command: command,
  25309. ui: ui,
  25310. value: value
  25311. });
  25312. state = true;
  25313. return false;
  25314. }
  25315. });
  25316. if (state) {
  25317. return state;
  25318. }
  25319. if (self.editor.theme && self.editor.theme.execCommand && self.editor.theme.execCommand(command, ui, value)) {
  25320. self.editor.fire('ExecCommand', {
  25321. command: command,
  25322. ui: ui,
  25323. value: value
  25324. });
  25325. return true;
  25326. }
  25327. try {
  25328. state = self.editor.getDoc().execCommand(command, ui, value);
  25329. } catch (ex) {
  25330. }
  25331. if (state) {
  25332. self.editor.fire('ExecCommand', {
  25333. command: command,
  25334. ui: ui,
  25335. value: value
  25336. });
  25337. return true;
  25338. }
  25339. return false;
  25340. };
  25341. EditorCommands.prototype.queryCommandState = function (command) {
  25342. var func;
  25343. if (this.editor.quirks.isHidden() || this.editor.removed) {
  25344. return;
  25345. }
  25346. command = command.toLowerCase();
  25347. if (func = this.commands.state[command]) {
  25348. return func(command);
  25349. }
  25350. try {
  25351. return this.editor.getDoc().queryCommandState(command);
  25352. } catch (ex) {
  25353. }
  25354. return false;
  25355. };
  25356. EditorCommands.prototype.queryCommandValue = function (command) {
  25357. var func;
  25358. if (this.editor.quirks.isHidden() || this.editor.removed) {
  25359. return;
  25360. }
  25361. command = command.toLowerCase();
  25362. if (func = this.commands.value[command]) {
  25363. return func(command);
  25364. }
  25365. try {
  25366. return this.editor.getDoc().queryCommandValue(command);
  25367. } catch (ex) {
  25368. }
  25369. };
  25370. EditorCommands.prototype.addCommands = function (commandList, type) {
  25371. var self = this;
  25372. type = type || 'exec';
  25373. each$g(commandList, function (callback, command) {
  25374. each$g(command.toLowerCase().split(','), function (command) {
  25375. self.commands[type][command] = callback;
  25376. });
  25377. });
  25378. };
  25379. EditorCommands.prototype.addCommand = function (command, callback, scope) {
  25380. var _this = this;
  25381. command = command.toLowerCase();
  25382. this.commands.exec[command] = function (command, ui, value, args) {
  25383. return callback.call(scope || _this.editor, ui, value, args);
  25384. };
  25385. };
  25386. EditorCommands.prototype.queryCommandSupported = function (command) {
  25387. command = command.toLowerCase();
  25388. if (this.commands.exec[command]) {
  25389. return true;
  25390. }
  25391. try {
  25392. return this.editor.getDoc().queryCommandSupported(command);
  25393. } catch (ex) {
  25394. }
  25395. return false;
  25396. };
  25397. EditorCommands.prototype.addQueryStateHandler = function (command, callback, scope) {
  25398. var _this = this;
  25399. command = command.toLowerCase();
  25400. this.commands.state[command] = function () {
  25401. return callback.call(scope || _this.editor);
  25402. };
  25403. };
  25404. EditorCommands.prototype.addQueryValueHandler = function (command, callback, scope) {
  25405. var _this = this;
  25406. command = command.toLowerCase();
  25407. this.commands.value[command] = function () {
  25408. return callback.call(scope || _this.editor);
  25409. };
  25410. };
  25411. EditorCommands.prototype.hasCustomCommand = function (command) {
  25412. command = command.toLowerCase();
  25413. return !!this.commands.exec[command];
  25414. };
  25415. EditorCommands.prototype.execNativeCommand = function (command, ui, value) {
  25416. if (ui === undefined) {
  25417. ui = false;
  25418. }
  25419. if (value === undefined) {
  25420. value = null;
  25421. }
  25422. return this.editor.getDoc().execCommand(command, ui, value);
  25423. };
  25424. EditorCommands.prototype.isFormatMatch = function (name) {
  25425. return this.editor.formatter.match(name);
  25426. };
  25427. EditorCommands.prototype.toggleFormat = function (name, value) {
  25428. this.editor.formatter.toggle(name, value ? { value: value } : undefined);
  25429. this.editor.nodeChanged();
  25430. };
  25431. EditorCommands.prototype.storeSelection = function (type) {
  25432. this.selectionBookmark = this.editor.selection.getBookmark(type);
  25433. };
  25434. EditorCommands.prototype.restoreSelection = function () {
  25435. this.editor.selection.moveToBookmark(this.selectionBookmark);
  25436. };
  25437. EditorCommands.prototype.setupCommands = function (editor) {
  25438. var self = this;
  25439. this.addCommands({
  25440. 'mceResetDesignMode,mceBeginUndoLevel': function () {
  25441. },
  25442. 'mceEndUndoLevel,mceAddUndoLevel': function () {
  25443. editor.undoManager.add();
  25444. },
  25445. 'Cut,Copy,Paste': function (command) {
  25446. var doc = editor.getDoc();
  25447. var failed;
  25448. try {
  25449. self.execNativeCommand(command);
  25450. } catch (ex) {
  25451. failed = true;
  25452. }
  25453. if (command === 'paste' && !doc.queryCommandEnabled(command)) {
  25454. failed = true;
  25455. }
  25456. if (failed || !doc.queryCommandSupported(command)) {
  25457. var msg = editor.translate('Your browser doesn\'t support direct access to the clipboard. ' + 'Please use the Ctrl+X/C/V keyboard shortcuts instead.');
  25458. if (Env.mac) {
  25459. msg = msg.replace(/Ctrl\+/g, '\u2318+');
  25460. }
  25461. editor.notificationManager.open({
  25462. text: msg,
  25463. type: 'error'
  25464. });
  25465. }
  25466. },
  25467. 'unlink': function () {
  25468. if (editor.selection.isCollapsed()) {
  25469. var elm = editor.dom.getParent(editor.selection.getStart(), 'a');
  25470. if (elm) {
  25471. editor.dom.remove(elm, true);
  25472. }
  25473. return;
  25474. }
  25475. editor.formatter.remove('link');
  25476. },
  25477. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone': function (command) {
  25478. var align = command.substring(7);
  25479. if (align === 'full') {
  25480. align = 'justify';
  25481. }
  25482. each$g('left,center,right,justify'.split(','), function (name) {
  25483. if (align !== name) {
  25484. editor.formatter.remove('align' + name);
  25485. }
  25486. });
  25487. if (align !== 'none') {
  25488. self.toggleFormat('align' + align);
  25489. }
  25490. },
  25491. 'InsertUnorderedList,InsertOrderedList': function (command) {
  25492. var listElm, listParent;
  25493. self.execNativeCommand(command);
  25494. listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
  25495. if (listElm) {
  25496. listParent = listElm.parentNode;
  25497. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  25498. self.storeSelection();
  25499. editor.dom.split(listParent, listElm);
  25500. self.restoreSelection();
  25501. }
  25502. }
  25503. },
  25504. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (command) {
  25505. self.toggleFormat(command);
  25506. },
  25507. 'ForeColor,HiliteColor': function (command, ui, value) {
  25508. self.toggleFormat(command, value);
  25509. },
  25510. 'FontName': function (command, ui, value) {
  25511. fontNameAction(editor, value);
  25512. },
  25513. 'FontSize': function (command, ui, value) {
  25514. fontSizeAction(editor, value);
  25515. },
  25516. 'RemoveFormat': function (command) {
  25517. editor.formatter.remove(command);
  25518. },
  25519. 'mceBlockQuote': function () {
  25520. self.toggleFormat('blockquote');
  25521. },
  25522. 'FormatBlock': function (command, ui, value) {
  25523. return self.toggleFormat(value || 'p');
  25524. },
  25525. 'mceCleanup': function () {
  25526. var bookmark = editor.selection.getBookmark();
  25527. editor.setContent(editor.getContent());
  25528. editor.selection.moveToBookmark(bookmark);
  25529. },
  25530. 'mceRemoveNode': function (command, ui, value) {
  25531. var node = value || editor.selection.getNode();
  25532. if (node !== editor.getBody()) {
  25533. self.storeSelection();
  25534. editor.dom.remove(node, true);
  25535. self.restoreSelection();
  25536. }
  25537. },
  25538. 'mceSelectNodeDepth': function (command, ui, value) {
  25539. var counter = 0;
  25540. editor.dom.getParent(editor.selection.getNode(), function (node) {
  25541. if (node.nodeType === 1 && counter++ === value) {
  25542. editor.selection.select(node);
  25543. return false;
  25544. }
  25545. }, editor.getBody());
  25546. },
  25547. 'mceSelectNode': function (command, ui, value) {
  25548. editor.selection.select(value);
  25549. },
  25550. 'mceInsertContent': function (command, ui, value) {
  25551. InsertContent.insertAtCaret(editor, value);
  25552. },
  25553. 'mceInsertRawHTML': function (command, ui, value) {
  25554. editor.selection.setContent('tiny_mce_marker');
  25555. var content = editor.getContent();
  25556. editor.setContent(content.replace(/tiny_mce_marker/g, function () {
  25557. return value;
  25558. }));
  25559. },
  25560. 'mceInsertNewLine': function (command, ui, value) {
  25561. InsertNewLine.insert(editor, value);
  25562. },
  25563. 'mceToggleFormat': function (command, ui, value) {
  25564. self.toggleFormat(value);
  25565. },
  25566. 'mceSetContent': function (command, ui, value) {
  25567. editor.setContent(value);
  25568. },
  25569. 'Indent,Outdent': function (command) {
  25570. handle(editor, command);
  25571. },
  25572. 'mceRepaint': function () {
  25573. },
  25574. 'InsertHorizontalRule': function () {
  25575. editor.execCommand('mceInsertContent', false, '<hr />');
  25576. },
  25577. 'mceToggleVisualAid': function () {
  25578. editor.hasVisual = !editor.hasVisual;
  25579. editor.addVisual();
  25580. },
  25581. 'mceReplaceContent': function (command, ui, value) {
  25582. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, editor.selection.getContent({ format: 'text' })));
  25583. },
  25584. 'mceInsertLink': function (command, ui, value) {
  25585. var anchor;
  25586. if (typeof value === 'string') {
  25587. value = { href: value };
  25588. }
  25589. anchor = editor.dom.getParent(editor.selection.getNode(), 'a');
  25590. value.href = value.href.replace(/ /g, '%20');
  25591. if (!anchor || !value.href) {
  25592. editor.formatter.remove('link');
  25593. }
  25594. if (value.href) {
  25595. editor.formatter.apply('link', value, anchor);
  25596. }
  25597. },
  25598. 'selectAll': function () {
  25599. var editingHost = editor.dom.getParent(editor.selection.getStart(), NodeType.isContentEditableTrue);
  25600. if (editingHost) {
  25601. var rng = editor.dom.createRng();
  25602. rng.selectNodeContents(editingHost);
  25603. editor.selection.setRng(rng);
  25604. }
  25605. },
  25606. 'delete': function () {
  25607. DeleteCommands.deleteCommand(editor);
  25608. },
  25609. 'forwardDelete': function () {
  25610. DeleteCommands.forwardDeleteCommand(editor);
  25611. },
  25612. 'mceNewDocument': function () {
  25613. editor.setContent('');
  25614. },
  25615. 'InsertLineBreak': function (command, ui, value) {
  25616. InsertBr.insert(editor, value);
  25617. return true;
  25618. }
  25619. });
  25620. var alignStates = function (name) {
  25621. return function () {
  25622. var nodes = editor.selection.isCollapsed() ? [editor.dom.getParent(editor.selection.getNode(), editor.dom.isBlock)] : editor.selection.getSelectedBlocks();
  25623. var matches = map$3(nodes, function (node) {
  25624. return !!editor.formatter.matchNode(node, name);
  25625. });
  25626. return inArray$2(matches, true) !== -1;
  25627. };
  25628. };
  25629. self.addCommands({
  25630. 'JustifyLeft': alignStates('alignleft'),
  25631. 'JustifyCenter': alignStates('aligncenter'),
  25632. 'JustifyRight': alignStates('alignright'),
  25633. 'JustifyFull': alignStates('alignjustify'),
  25634. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (command) {
  25635. return self.isFormatMatch(command);
  25636. },
  25637. 'mceBlockQuote': function () {
  25638. return self.isFormatMatch('blockquote');
  25639. },
  25640. 'Outdent': function () {
  25641. return canOutdent(editor);
  25642. },
  25643. 'InsertUnorderedList,InsertOrderedList': function (command) {
  25644. var list = editor.dom.getParent(editor.selection.getNode(), 'ul,ol');
  25645. return list && (command === 'insertunorderedlist' && list.tagName === 'UL' || command === 'insertorderedlist' && list.tagName === 'OL');
  25646. }
  25647. }, 'state');
  25648. self.addCommands({
  25649. Undo: function () {
  25650. editor.undoManager.undo();
  25651. },
  25652. Redo: function () {
  25653. editor.undoManager.redo();
  25654. }
  25655. });
  25656. self.addQueryValueHandler('FontName', function () {
  25657. return fontNameQuery(editor);
  25658. }, this);
  25659. self.addQueryValueHandler('FontSize', function () {
  25660. return fontSizeQuery(editor);
  25661. }, this);
  25662. };
  25663. return EditorCommands;
  25664. }();
  25665. var nativeEvents = Tools.makeMap('focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange ' + 'mouseout mouseenter mouseleave wheel keydown keypress keyup input beforeinput contextmenu dragstart dragend dragover ' + 'draggesture dragdrop drop drag submit ' + 'compositionstart compositionend compositionupdate touchstart touchmove touchend touchcancel', ' ');
  25666. var EventDispatcher = function () {
  25667. function EventDispatcher(settings) {
  25668. this.bindings = {};
  25669. this.settings = settings || {};
  25670. this.scope = this.settings.scope || this;
  25671. this.toggleEvent = this.settings.toggleEvent || never;
  25672. }
  25673. EventDispatcher.isNative = function (name) {
  25674. return !!nativeEvents[name.toLowerCase()];
  25675. };
  25676. EventDispatcher.prototype.fire = function (name, args) {
  25677. var handlers, i, l, callback;
  25678. name = name.toLowerCase();
  25679. args = args || {};
  25680. args.type = name;
  25681. if (!args.target) {
  25682. args.target = this.scope;
  25683. }
  25684. if (!args.preventDefault) {
  25685. args.preventDefault = function () {
  25686. args.isDefaultPrevented = always;
  25687. };
  25688. args.stopPropagation = function () {
  25689. args.isPropagationStopped = always;
  25690. };
  25691. args.stopImmediatePropagation = function () {
  25692. args.isImmediatePropagationStopped = always;
  25693. };
  25694. args.isDefaultPrevented = never;
  25695. args.isPropagationStopped = never;
  25696. args.isImmediatePropagationStopped = never;
  25697. }
  25698. if (this.settings.beforeFire) {
  25699. this.settings.beforeFire(args);
  25700. }
  25701. handlers = this.bindings[name];
  25702. if (handlers) {
  25703. for (i = 0, l = handlers.length; i < l; i++) {
  25704. callback = handlers[i];
  25705. if (callback.once) {
  25706. this.off(name, callback.func);
  25707. }
  25708. if (args.isImmediatePropagationStopped()) {
  25709. args.stopPropagation();
  25710. return args;
  25711. }
  25712. if (callback.func.call(this.scope, args) === false) {
  25713. args.preventDefault();
  25714. return args;
  25715. }
  25716. }
  25717. }
  25718. return args;
  25719. };
  25720. EventDispatcher.prototype.on = function (name, callback, prepend, extra) {
  25721. var handlers, names, i;
  25722. if (callback === false) {
  25723. callback = never;
  25724. }
  25725. if (callback) {
  25726. var wrappedCallback = { func: callback };
  25727. if (extra) {
  25728. Tools.extend(wrappedCallback, extra);
  25729. }
  25730. names = name.toLowerCase().split(' ');
  25731. i = names.length;
  25732. while (i--) {
  25733. name = names[i];
  25734. handlers = this.bindings[name];
  25735. if (!handlers) {
  25736. handlers = this.bindings[name] = [];
  25737. this.toggleEvent(name, true);
  25738. }
  25739. if (prepend) {
  25740. handlers.unshift(wrappedCallback);
  25741. } else {
  25742. handlers.push(wrappedCallback);
  25743. }
  25744. }
  25745. }
  25746. return this;
  25747. };
  25748. EventDispatcher.prototype.off = function (name, callback) {
  25749. var i, handlers, bindingName, names, hi;
  25750. if (name) {
  25751. names = name.toLowerCase().split(' ');
  25752. i = names.length;
  25753. while (i--) {
  25754. name = names[i];
  25755. handlers = this.bindings[name];
  25756. if (!name) {
  25757. for (bindingName in this.bindings) {
  25758. this.toggleEvent(bindingName, false);
  25759. delete this.bindings[bindingName];
  25760. }
  25761. return this;
  25762. }
  25763. if (handlers) {
  25764. if (!callback) {
  25765. handlers.length = 0;
  25766. } else {
  25767. hi = handlers.length;
  25768. while (hi--) {
  25769. if (handlers[hi].func === callback) {
  25770. handlers = handlers.slice(0, hi).concat(handlers.slice(hi + 1));
  25771. this.bindings[name] = handlers;
  25772. }
  25773. }
  25774. }
  25775. if (!handlers.length) {
  25776. this.toggleEvent(name, false);
  25777. delete this.bindings[name];
  25778. }
  25779. }
  25780. }
  25781. } else {
  25782. for (name in this.bindings) {
  25783. this.toggleEvent(name, false);
  25784. }
  25785. this.bindings = {};
  25786. }
  25787. return this;
  25788. };
  25789. EventDispatcher.prototype.once = function (name, callback, prepend) {
  25790. return this.on(name, callback, prepend, { once: true });
  25791. };
  25792. EventDispatcher.prototype.has = function (name) {
  25793. name = name.toLowerCase();
  25794. return !(!this.bindings[name] || this.bindings[name].length === 0);
  25795. };
  25796. return EventDispatcher;
  25797. }();
  25798. var getEventDispatcher = function (obj) {
  25799. if (!obj._eventDispatcher) {
  25800. obj._eventDispatcher = new EventDispatcher({
  25801. scope: obj,
  25802. toggleEvent: function (name, state) {
  25803. if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) {
  25804. obj.toggleNativeEvent(name, state);
  25805. }
  25806. }
  25807. });
  25808. }
  25809. return obj._eventDispatcher;
  25810. };
  25811. var Observable = {
  25812. fire: function (name, args, bubble) {
  25813. var self = this;
  25814. if (self.removed && name !== 'remove' && name !== 'detach') {
  25815. return args;
  25816. }
  25817. var dispatcherArgs = getEventDispatcher(self).fire(name, args);
  25818. if (bubble !== false && self.parent) {
  25819. var parent = self.parent();
  25820. while (parent && !dispatcherArgs.isPropagationStopped()) {
  25821. parent.fire(name, dispatcherArgs, false);
  25822. parent = parent.parent();
  25823. }
  25824. }
  25825. return dispatcherArgs;
  25826. },
  25827. on: function (name, callback, prepend) {
  25828. return getEventDispatcher(this).on(name, callback, prepend);
  25829. },
  25830. off: function (name, callback) {
  25831. return getEventDispatcher(this).off(name, callback);
  25832. },
  25833. once: function (name, callback) {
  25834. return getEventDispatcher(this).once(name, callback);
  25835. },
  25836. hasEventListeners: function (name) {
  25837. return getEventDispatcher(this).has(name);
  25838. }
  25839. };
  25840. var DOM$7 = DOMUtils$1.DOM;
  25841. var customEventRootDelegates;
  25842. var getEventTarget = function (editor, eventName) {
  25843. if (eventName === 'selectionchange') {
  25844. return editor.getDoc();
  25845. }
  25846. if (!editor.inline && /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)) {
  25847. return editor.getDoc().documentElement;
  25848. }
  25849. if (editor.settings.event_root) {
  25850. if (!editor.eventRoot) {
  25851. editor.eventRoot = DOM$7.select(editor.settings.event_root)[0];
  25852. }
  25853. return editor.eventRoot;
  25854. }
  25855. return editor.getBody();
  25856. };
  25857. var isListening = function (editor) {
  25858. return !editor.hidden && !isReadOnly(editor);
  25859. };
  25860. var fireEvent = function (editor, eventName, e) {
  25861. if (isListening(editor)) {
  25862. editor.fire(eventName, e);
  25863. } else if (isReadOnly(editor)) {
  25864. preventReadOnlyEvents(e);
  25865. }
  25866. };
  25867. var bindEventDelegate = function (editor, eventName) {
  25868. var eventRootElm, delegate;
  25869. if (!editor.delegates) {
  25870. editor.delegates = {};
  25871. }
  25872. if (editor.delegates[eventName] || editor.removed) {
  25873. return;
  25874. }
  25875. eventRootElm = getEventTarget(editor, eventName);
  25876. if (editor.settings.event_root) {
  25877. if (!customEventRootDelegates) {
  25878. customEventRootDelegates = {};
  25879. editor.editorManager.on('removeEditor', function () {
  25880. var name;
  25881. if (!editor.editorManager.activeEditor) {
  25882. if (customEventRootDelegates) {
  25883. for (name in customEventRootDelegates) {
  25884. editor.dom.unbind(getEventTarget(editor, name));
  25885. }
  25886. customEventRootDelegates = null;
  25887. }
  25888. }
  25889. });
  25890. }
  25891. if (customEventRootDelegates[eventName]) {
  25892. return;
  25893. }
  25894. delegate = function (e) {
  25895. var target = e.target;
  25896. var editors = editor.editorManager.get();
  25897. var i = editors.length;
  25898. while (i--) {
  25899. var body = editors[i].getBody();
  25900. if (body === target || DOM$7.isChildOf(target, body)) {
  25901. fireEvent(editors[i], eventName, e);
  25902. }
  25903. }
  25904. };
  25905. customEventRootDelegates[eventName] = delegate;
  25906. DOM$7.bind(eventRootElm, eventName, delegate);
  25907. } else {
  25908. delegate = function (e) {
  25909. fireEvent(editor, eventName, e);
  25910. };
  25911. DOM$7.bind(eventRootElm, eventName, delegate);
  25912. editor.delegates[eventName] = delegate;
  25913. }
  25914. };
  25915. var EditorObservable = __assign(__assign({}, Observable), {
  25916. bindPendingEventDelegates: function () {
  25917. var self = this;
  25918. Tools.each(self._pendingNativeEvents, function (name) {
  25919. bindEventDelegate(self, name);
  25920. });
  25921. },
  25922. toggleNativeEvent: function (name, state) {
  25923. var self = this;
  25924. if (name === 'focus' || name === 'blur') {
  25925. return;
  25926. }
  25927. if (state) {
  25928. if (self.initialized) {
  25929. bindEventDelegate(self, name);
  25930. } else {
  25931. if (!self._pendingNativeEvents) {
  25932. self._pendingNativeEvents = [name];
  25933. } else {
  25934. self._pendingNativeEvents.push(name);
  25935. }
  25936. }
  25937. } else if (self.initialized) {
  25938. self.dom.unbind(getEventTarget(self, name), name, self.delegates[name]);
  25939. delete self.delegates[name];
  25940. }
  25941. },
  25942. unbindAllNativeEvents: function () {
  25943. var self = this;
  25944. var body = self.getBody();
  25945. var dom = self.dom;
  25946. var name;
  25947. if (self.delegates) {
  25948. for (name in self.delegates) {
  25949. self.dom.unbind(getEventTarget(self, name), name, self.delegates[name]);
  25950. }
  25951. delete self.delegates;
  25952. }
  25953. if (!self.inline && body && dom) {
  25954. body.onload = null;
  25955. dom.unbind(self.getWin());
  25956. dom.unbind(self.getDoc());
  25957. }
  25958. if (dom) {
  25959. dom.unbind(body);
  25960. dom.unbind(self.getContainer());
  25961. }
  25962. }
  25963. });
  25964. var each$h = Tools.each, explode$3 = Tools.explode;
  25965. var keyCodeLookup = {
  25966. f1: 112,
  25967. f2: 113,
  25968. f3: 114,
  25969. f4: 115,
  25970. f5: 116,
  25971. f6: 117,
  25972. f7: 118,
  25973. f8: 119,
  25974. f9: 120,
  25975. f10: 121,
  25976. f11: 122,
  25977. f12: 123
  25978. };
  25979. var modifierNames = Tools.makeMap('alt,ctrl,shift,meta,access');
  25980. var Shortcuts = function () {
  25981. function Shortcuts(editor) {
  25982. this.shortcuts = {};
  25983. this.pendingPatterns = [];
  25984. this.editor = editor;
  25985. var self = this;
  25986. editor.on('keyup keypress keydown', function (e) {
  25987. if ((self.hasModifier(e) || self.isFunctionKey(e)) && !e.isDefaultPrevented()) {
  25988. each$h(self.shortcuts, function (shortcut) {
  25989. if (self.matchShortcut(e, shortcut)) {
  25990. self.pendingPatterns = shortcut.subpatterns.slice(0);
  25991. if (e.type === 'keydown') {
  25992. self.executeShortcutAction(shortcut);
  25993. }
  25994. return true;
  25995. }
  25996. });
  25997. if (self.matchShortcut(e, self.pendingPatterns[0])) {
  25998. if (self.pendingPatterns.length === 1) {
  25999. if (e.type === 'keydown') {
  26000. self.executeShortcutAction(self.pendingPatterns[0]);
  26001. }
  26002. }
  26003. self.pendingPatterns.shift();
  26004. }
  26005. }
  26006. });
  26007. }
  26008. Shortcuts.prototype.add = function (pattern, desc, cmdFunc, scope) {
  26009. var self = this;
  26010. var cmd;
  26011. cmd = cmdFunc;
  26012. if (typeof cmdFunc === 'string') {
  26013. cmdFunc = function () {
  26014. self.editor.execCommand(cmd, false, null);
  26015. };
  26016. } else if (Tools.isArray(cmd)) {
  26017. cmdFunc = function () {
  26018. self.editor.execCommand(cmd[0], cmd[1], cmd[2]);
  26019. };
  26020. }
  26021. each$h(explode$3(Tools.trim(pattern)), function (pattern) {
  26022. var shortcut = self.createShortcut(pattern, desc, cmdFunc, scope);
  26023. self.shortcuts[shortcut.id] = shortcut;
  26024. });
  26025. return true;
  26026. };
  26027. Shortcuts.prototype.remove = function (pattern) {
  26028. var shortcut = this.createShortcut(pattern);
  26029. if (this.shortcuts[shortcut.id]) {
  26030. delete this.shortcuts[shortcut.id];
  26031. return true;
  26032. }
  26033. return false;
  26034. };
  26035. Shortcuts.prototype.parseShortcut = function (pattern) {
  26036. var id, key;
  26037. var shortcut = {};
  26038. each$h(explode$3(pattern.toLowerCase(), '+'), function (value) {
  26039. if (value in modifierNames) {
  26040. shortcut[value] = true;
  26041. } else {
  26042. if (/^[0-9]{2,}$/.test(value)) {
  26043. shortcut.keyCode = parseInt(value, 10);
  26044. } else {
  26045. shortcut.charCode = value.charCodeAt(0);
  26046. shortcut.keyCode = keyCodeLookup[value] || value.toUpperCase().charCodeAt(0);
  26047. }
  26048. }
  26049. });
  26050. id = [shortcut.keyCode];
  26051. for (key in modifierNames) {
  26052. if (shortcut[key]) {
  26053. id.push(key);
  26054. } else {
  26055. shortcut[key] = false;
  26056. }
  26057. }
  26058. shortcut.id = id.join(',');
  26059. if (shortcut.access) {
  26060. shortcut.alt = true;
  26061. if (Env.mac) {
  26062. shortcut.ctrl = true;
  26063. } else {
  26064. shortcut.shift = true;
  26065. }
  26066. }
  26067. if (shortcut.meta) {
  26068. if (Env.mac) {
  26069. shortcut.meta = true;
  26070. } else {
  26071. shortcut.ctrl = true;
  26072. shortcut.meta = false;
  26073. }
  26074. }
  26075. return shortcut;
  26076. };
  26077. Shortcuts.prototype.createShortcut = function (pattern, desc, cmdFunc, scope) {
  26078. var shortcuts;
  26079. shortcuts = Tools.map(explode$3(pattern, '>'), this.parseShortcut);
  26080. shortcuts[shortcuts.length - 1] = Tools.extend(shortcuts[shortcuts.length - 1], {
  26081. func: cmdFunc,
  26082. scope: scope || this.editor
  26083. });
  26084. return Tools.extend(shortcuts[0], {
  26085. desc: this.editor.translate(desc),
  26086. subpatterns: shortcuts.slice(1)
  26087. });
  26088. };
  26089. Shortcuts.prototype.hasModifier = function (e) {
  26090. return e.altKey || e.ctrlKey || e.metaKey;
  26091. };
  26092. Shortcuts.prototype.isFunctionKey = function (e) {
  26093. return e.type === 'keydown' && e.keyCode >= 112 && e.keyCode <= 123;
  26094. };
  26095. Shortcuts.prototype.matchShortcut = function (e, shortcut) {
  26096. if (!shortcut) {
  26097. return false;
  26098. }
  26099. if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) {
  26100. return false;
  26101. }
  26102. if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) {
  26103. return false;
  26104. }
  26105. if (e.keyCode === shortcut.keyCode || e.charCode && e.charCode === shortcut.charCode) {
  26106. e.preventDefault();
  26107. return true;
  26108. }
  26109. return false;
  26110. };
  26111. Shortcuts.prototype.executeShortcutAction = function (shortcut) {
  26112. return shortcut.func ? shortcut.func.call(shortcut.scope) : null;
  26113. };
  26114. return Shortcuts;
  26115. }();
  26116. var each$i = Tools.each, trim$4 = Tools.trim;
  26117. var queryParts = 'source protocol authority userInfo user password host port relative path directory file query anchor'.split(' ');
  26118. var DEFAULT_PORTS = {
  26119. ftp: 21,
  26120. http: 80,
  26121. https: 443,
  26122. mailto: 25
  26123. };
  26124. var URI = function () {
  26125. function URI(url, settings) {
  26126. url = trim$4(url);
  26127. this.settings = settings || {};
  26128. var baseUri = this.settings.base_uri;
  26129. var self = this;
  26130. if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
  26131. self.source = url;
  26132. return;
  26133. }
  26134. var isProtocolRelative = url.indexOf('//') === 0;
  26135. if (url.indexOf('/') === 0 && !isProtocolRelative) {
  26136. url = (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url;
  26137. }
  26138. if (!/^[\w\-]*:?\/\//.test(url)) {
  26139. var baseUrl = this.settings.base_uri ? this.settings.base_uri.path : new URI(domGlobals.document.location.href).directory;
  26140. if (this.settings.base_uri && this.settings.base_uri.protocol == '') {
  26141. url = '//mce_host' + self.toAbsPath(baseUrl, url);
  26142. } else {
  26143. var match = /([^#?]*)([#?]?.*)/.exec(url);
  26144. url = (baseUri && baseUri.protocol || 'http') + '://mce_host' + self.toAbsPath(baseUrl, match[1]) + match[2];
  26145. }
  26146. }
  26147. url = url.replace(/@@/g, '(mce_at)');
  26148. var urlMatch = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
  26149. each$i(queryParts, function (v, i) {
  26150. var part = urlMatch[i];
  26151. if (part) {
  26152. part = part.replace(/\(mce_at\)/g, '@@');
  26153. }
  26154. self[v] = part;
  26155. });
  26156. if (baseUri) {
  26157. if (!self.protocol) {
  26158. self.protocol = baseUri.protocol;
  26159. }
  26160. if (!self.userInfo) {
  26161. self.userInfo = baseUri.userInfo;
  26162. }
  26163. if (!self.port && self.host === 'mce_host') {
  26164. self.port = baseUri.port;
  26165. }
  26166. if (!self.host || self.host === 'mce_host') {
  26167. self.host = baseUri.host;
  26168. }
  26169. self.source = '';
  26170. }
  26171. if (isProtocolRelative) {
  26172. self.protocol = '';
  26173. }
  26174. }
  26175. URI.parseDataUri = function (uri) {
  26176. var type;
  26177. var uriComponents = decodeURIComponent(uri).split(',');
  26178. var matches = /data:([^;]+)/.exec(uriComponents[0]);
  26179. if (matches) {
  26180. type = matches[1];
  26181. }
  26182. return {
  26183. type: type,
  26184. data: uriComponents[1]
  26185. };
  26186. };
  26187. URI.getDocumentBaseUrl = function (loc) {
  26188. var baseUrl;
  26189. if (loc.protocol.indexOf('http') !== 0 && loc.protocol !== 'file:') {
  26190. baseUrl = loc.href;
  26191. } else {
  26192. baseUrl = loc.protocol + '//' + loc.host + loc.pathname;
  26193. }
  26194. if (/^[^:]+:\/\/\/?[^\/]+\//.test(baseUrl)) {
  26195. baseUrl = baseUrl.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  26196. if (!/[\/\\]$/.test(baseUrl)) {
  26197. baseUrl += '/';
  26198. }
  26199. }
  26200. return baseUrl;
  26201. };
  26202. URI.prototype.setPath = function (path) {
  26203. var pathMatch = /^(.*?)\/?(\w+)?$/.exec(path);
  26204. this.path = pathMatch[0];
  26205. this.directory = pathMatch[1];
  26206. this.file = pathMatch[2];
  26207. this.source = '';
  26208. this.getURI();
  26209. };
  26210. URI.prototype.toRelative = function (uri) {
  26211. var output;
  26212. if (uri === './') {
  26213. return uri;
  26214. }
  26215. var relativeUri = new URI(uri, { base_uri: this });
  26216. if (relativeUri.host !== 'mce_host' && this.host !== relativeUri.host && relativeUri.host || this.port !== relativeUri.port || this.protocol !== relativeUri.protocol && relativeUri.protocol !== '') {
  26217. return relativeUri.getURI();
  26218. }
  26219. var tu = this.getURI(), uu = relativeUri.getURI();
  26220. if (tu === uu || tu.charAt(tu.length - 1) === '/' && tu.substr(0, tu.length - 1) === uu) {
  26221. return tu;
  26222. }
  26223. output = this.toRelPath(this.path, relativeUri.path);
  26224. if (relativeUri.query) {
  26225. output += '?' + relativeUri.query;
  26226. }
  26227. if (relativeUri.anchor) {
  26228. output += '#' + relativeUri.anchor;
  26229. }
  26230. return output;
  26231. };
  26232. URI.prototype.toAbsolute = function (uri, noHost) {
  26233. var absoluteUri = new URI(uri, { base_uri: this });
  26234. return absoluteUri.getURI(noHost && this.isSameOrigin(absoluteUri));
  26235. };
  26236. URI.prototype.isSameOrigin = function (uri) {
  26237. if (this.host == uri.host && this.protocol == uri.protocol) {
  26238. if (this.port == uri.port) {
  26239. return true;
  26240. }
  26241. var defaultPort = DEFAULT_PORTS[this.protocol];
  26242. if (defaultPort && (this.port || defaultPort) == (uri.port || defaultPort)) {
  26243. return true;
  26244. }
  26245. }
  26246. return false;
  26247. };
  26248. URI.prototype.toRelPath = function (base, path) {
  26249. var items, breakPoint = 0, out = '', i, l;
  26250. var normalizedBase = base.substring(0, base.lastIndexOf('/')).split('/');
  26251. items = path.split('/');
  26252. if (normalizedBase.length >= items.length) {
  26253. for (i = 0, l = normalizedBase.length; i < l; i++) {
  26254. if (i >= items.length || normalizedBase[i] !== items[i]) {
  26255. breakPoint = i + 1;
  26256. break;
  26257. }
  26258. }
  26259. }
  26260. if (normalizedBase.length < items.length) {
  26261. for (i = 0, l = items.length; i < l; i++) {
  26262. if (i >= normalizedBase.length || normalizedBase[i] !== items[i]) {
  26263. breakPoint = i + 1;
  26264. break;
  26265. }
  26266. }
  26267. }
  26268. if (breakPoint === 1) {
  26269. return path;
  26270. }
  26271. for (i = 0, l = normalizedBase.length - (breakPoint - 1); i < l; i++) {
  26272. out += '../';
  26273. }
  26274. for (i = breakPoint - 1, l = items.length; i < l; i++) {
  26275. if (i !== breakPoint - 1) {
  26276. out += '/' + items[i];
  26277. } else {
  26278. out += items[i];
  26279. }
  26280. }
  26281. return out;
  26282. };
  26283. URI.prototype.toAbsPath = function (base, path) {
  26284. var i, nb = 0, o = [], tr, outPath;
  26285. tr = /\/$/.test(path) ? '/' : '';
  26286. var normalizedBase = base.split('/');
  26287. var normalizedPath = path.split('/');
  26288. each$i(normalizedBase, function (k) {
  26289. if (k) {
  26290. o.push(k);
  26291. }
  26292. });
  26293. normalizedBase = o;
  26294. for (i = normalizedPath.length - 1, o = []; i >= 0; i--) {
  26295. if (normalizedPath[i].length === 0 || normalizedPath[i] === '.') {
  26296. continue;
  26297. }
  26298. if (normalizedPath[i] === '..') {
  26299. nb++;
  26300. continue;
  26301. }
  26302. if (nb > 0) {
  26303. nb--;
  26304. continue;
  26305. }
  26306. o.push(normalizedPath[i]);
  26307. }
  26308. i = normalizedBase.length - nb;
  26309. if (i <= 0) {
  26310. outPath = o.reverse().join('/');
  26311. } else {
  26312. outPath = normalizedBase.slice(0, i).join('/') + '/' + o.reverse().join('/');
  26313. }
  26314. if (outPath.indexOf('/') !== 0) {
  26315. outPath = '/' + outPath;
  26316. }
  26317. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) {
  26318. outPath += tr;
  26319. }
  26320. return outPath;
  26321. };
  26322. URI.prototype.getURI = function (noProtoHost) {
  26323. if (noProtoHost === void 0) {
  26324. noProtoHost = false;
  26325. }
  26326. var s;
  26327. if (!this.source || noProtoHost) {
  26328. s = '';
  26329. if (!noProtoHost) {
  26330. if (this.protocol) {
  26331. s += this.protocol + '://';
  26332. } else {
  26333. s += '//';
  26334. }
  26335. if (this.userInfo) {
  26336. s += this.userInfo + '@';
  26337. }
  26338. if (this.host) {
  26339. s += this.host;
  26340. }
  26341. if (this.port) {
  26342. s += ':' + this.port;
  26343. }
  26344. }
  26345. if (this.path) {
  26346. s += this.path;
  26347. }
  26348. if (this.query) {
  26349. s += '?' + this.query;
  26350. }
  26351. if (this.anchor) {
  26352. s += '#' + this.anchor;
  26353. }
  26354. this.source = s;
  26355. }
  26356. return this.source;
  26357. };
  26358. return URI;
  26359. }();
  26360. var create$5 = function () {
  26361. var buttons = {};
  26362. var menuItems = {};
  26363. var popups = {};
  26364. var icons = {};
  26365. var contextMenus = {};
  26366. var contextToolbars = {};
  26367. var sidebars = {};
  26368. var add = function (collection, type) {
  26369. return function (name, spec) {
  26370. return collection[name.toLowerCase()] = __assign(__assign({}, spec), { type: type });
  26371. };
  26372. };
  26373. var addIcon = function (name, svgData) {
  26374. return icons[name.toLowerCase()] = svgData;
  26375. };
  26376. return {
  26377. addButton: add(buttons, 'button'),
  26378. addToggleButton: add(buttons, 'togglebutton'),
  26379. addMenuButton: add(buttons, 'menubutton'),
  26380. addSplitButton: add(buttons, 'splitbutton'),
  26381. addMenuItem: add(menuItems, 'menuitem'),
  26382. addNestedMenuItem: add(menuItems, 'nestedmenuitem'),
  26383. addToggleMenuItem: add(menuItems, 'togglemenuitem'),
  26384. addAutocompleter: add(popups, 'autocompleter'),
  26385. addContextMenu: add(contextMenus, 'contextmenu'),
  26386. addContextToolbar: add(contextToolbars, 'contexttoolbar'),
  26387. addContextForm: add(contextToolbars, 'contextform'),
  26388. addSidebar: add(sidebars, 'sidebar'),
  26389. addIcon: addIcon,
  26390. getAll: function () {
  26391. return {
  26392. buttons: buttons,
  26393. menuItems: menuItems,
  26394. icons: icons,
  26395. popups: popups,
  26396. contextMenus: contextMenus,
  26397. contextToolbars: contextToolbars,
  26398. sidebars: sidebars
  26399. };
  26400. }
  26401. };
  26402. };
  26403. var registry = function () {
  26404. var bridge = create$5();
  26405. return {
  26406. addAutocompleter: bridge.addAutocompleter,
  26407. addButton: bridge.addButton,
  26408. addContextForm: bridge.addContextForm,
  26409. addContextMenu: bridge.addContextMenu,
  26410. addContextToolbar: bridge.addContextToolbar,
  26411. addIcon: bridge.addIcon,
  26412. addMenuButton: bridge.addMenuButton,
  26413. addMenuItem: bridge.addMenuItem,
  26414. addNestedMenuItem: bridge.addNestedMenuItem,
  26415. addSidebar: bridge.addSidebar,
  26416. addSplitButton: bridge.addSplitButton,
  26417. addToggleButton: bridge.addToggleButton,
  26418. addToggleMenuItem: bridge.addToggleMenuItem,
  26419. getAll: bridge.getAll
  26420. };
  26421. };
  26422. var DOM$8 = DOMUtils$1.DOM;
  26423. var extend$3 = Tools.extend, each$j = Tools.each;
  26424. var resolve$3 = Tools.resolve;
  26425. var ie$1 = Env.ie;
  26426. var Editor = function () {
  26427. function Editor(id, settings, editorManager) {
  26428. var _this = this;
  26429. this.plugins = {};
  26430. this.contentCSS = [];
  26431. this.contentStyles = [];
  26432. this.loadedCSS = {};
  26433. this.isNotDirty = false;
  26434. this.editorManager = editorManager;
  26435. this.documentBaseUrl = editorManager.documentBaseURL;
  26436. extend$3(this, EditorObservable);
  26437. this.settings = getEditorSettings(this, id, this.documentBaseUrl, editorManager.defaultSettings, settings);
  26438. if (this.settings.suffix) {
  26439. editorManager.suffix = this.settings.suffix;
  26440. }
  26441. this.suffix = editorManager.suffix;
  26442. if (this.settings.base_url) {
  26443. editorManager._setBaseUrl(this.settings.base_url);
  26444. }
  26445. this.baseUri = editorManager.baseURI;
  26446. if (this.settings.referrer_policy) {
  26447. ScriptLoader.ScriptLoader._setReferrerPolicy(this.settings.referrer_policy);
  26448. DOMUtils$1.DOM.styleSheetLoader._setReferrerPolicy(this.settings.referrer_policy);
  26449. }
  26450. AddOnManager$1.languageLoad = this.settings.language_load;
  26451. AddOnManager$1.baseURL = editorManager.baseURL;
  26452. this.id = id;
  26453. this.setDirty(false);
  26454. this.documentBaseURI = new URI(this.settings.document_base_url, { base_uri: this.baseUri });
  26455. this.baseURI = this.baseUri;
  26456. this.inline = !!this.settings.inline;
  26457. this.shortcuts = new Shortcuts(this);
  26458. this.editorCommands = new EditorCommands(this);
  26459. if (this.settings.cache_suffix) {
  26460. Env.cacheSuffix = this.settings.cache_suffix.replace(/^[\?\&]+/, '');
  26461. }
  26462. this.ui = { registry: registry() };
  26463. var self = this;
  26464. var modeInstance = create$4(self);
  26465. this.mode = modeInstance;
  26466. this.setMode = modeInstance.set;
  26467. editorManager.fire('SetupEditor', { editor: this });
  26468. this.execCallback('setup', this);
  26469. this.$ = DomQuery.overrideDefaults(function () {
  26470. return {
  26471. context: _this.inline ? _this.getBody() : _this.getDoc(),
  26472. element: _this.getBody()
  26473. };
  26474. });
  26475. }
  26476. Editor.prototype.render = function () {
  26477. Render.render(this);
  26478. };
  26479. Editor.prototype.focus = function (skipFocus) {
  26480. EditorFocus.focus(this, skipFocus);
  26481. };
  26482. Editor.prototype.hasFocus = function () {
  26483. return EditorFocus.hasFocus(this);
  26484. };
  26485. Editor.prototype.execCallback = function (name) {
  26486. var x = [];
  26487. for (var _i = 1; _i < arguments.length; _i++) {
  26488. x[_i - 1] = arguments[_i];
  26489. }
  26490. var self = this;
  26491. var callback = self.settings[name], scope;
  26492. if (!callback) {
  26493. return;
  26494. }
  26495. if (self.callbackLookup && (scope = self.callbackLookup[name])) {
  26496. callback = scope.func;
  26497. scope = scope.scope;
  26498. }
  26499. if (typeof callback === 'string') {
  26500. scope = callback.replace(/\.\w+$/, '');
  26501. scope = scope ? resolve$3(scope) : 0;
  26502. callback = resolve$3(callback);
  26503. self.callbackLookup = self.callbackLookup || {};
  26504. self.callbackLookup[name] = {
  26505. func: callback,
  26506. scope: scope
  26507. };
  26508. }
  26509. return callback.apply(scope || self, Array.prototype.slice.call(arguments, 1));
  26510. };
  26511. Editor.prototype.translate = function (text) {
  26512. return I18n.translate(text);
  26513. };
  26514. Editor.prototype.getParam = function (name, defaultVal, type) {
  26515. return getParam(this, name, defaultVal, type);
  26516. };
  26517. Editor.prototype.nodeChanged = function (args) {
  26518. this._nodeChangeDispatcher.nodeChanged(args);
  26519. };
  26520. Editor.prototype.addCommand = function (name, callback, scope) {
  26521. this.editorCommands.addCommand(name, callback, scope);
  26522. };
  26523. Editor.prototype.addQueryStateHandler = function (name, callback, scope) {
  26524. this.editorCommands.addQueryStateHandler(name, callback, scope);
  26525. };
  26526. Editor.prototype.addQueryValueHandler = function (name, callback, scope) {
  26527. this.editorCommands.addQueryValueHandler(name, callback, scope);
  26528. };
  26529. Editor.prototype.addShortcut = function (pattern, desc, cmdFunc, scope) {
  26530. this.shortcuts.add(pattern, desc, cmdFunc, scope);
  26531. };
  26532. Editor.prototype.execCommand = function (cmd, ui, value, args) {
  26533. return this.editorCommands.execCommand(cmd, ui, value, args);
  26534. };
  26535. Editor.prototype.queryCommandState = function (cmd) {
  26536. return this.editorCommands.queryCommandState(cmd);
  26537. };
  26538. Editor.prototype.queryCommandValue = function (cmd) {
  26539. return this.editorCommands.queryCommandValue(cmd);
  26540. };
  26541. Editor.prototype.queryCommandSupported = function (cmd) {
  26542. return this.editorCommands.queryCommandSupported(cmd);
  26543. };
  26544. Editor.prototype.show = function () {
  26545. var self = this;
  26546. if (self.hidden) {
  26547. self.hidden = false;
  26548. if (self.inline) {
  26549. self.getBody().contentEditable = 'true';
  26550. } else {
  26551. DOM$8.show(self.getContainer());
  26552. DOM$8.hide(self.id);
  26553. }
  26554. self.load();
  26555. self.fire('show');
  26556. }
  26557. };
  26558. Editor.prototype.hide = function () {
  26559. var self = this, doc = self.getDoc();
  26560. if (!self.hidden) {
  26561. if (ie$1 && doc && !self.inline) {
  26562. doc.execCommand('SelectAll');
  26563. }
  26564. self.save();
  26565. if (self.inline) {
  26566. self.getBody().contentEditable = 'false';
  26567. if (self === self.editorManager.focusedEditor) {
  26568. self.editorManager.focusedEditor = null;
  26569. }
  26570. } else {
  26571. DOM$8.hide(self.getContainer());
  26572. DOM$8.setStyle(self.id, 'display', self.orgDisplay);
  26573. }
  26574. self.hidden = true;
  26575. self.fire('hide');
  26576. }
  26577. };
  26578. Editor.prototype.isHidden = function () {
  26579. return !!this.hidden;
  26580. };
  26581. Editor.prototype.setProgressState = function (state, time) {
  26582. this.fire('ProgressState', {
  26583. state: state,
  26584. time: time
  26585. });
  26586. };
  26587. Editor.prototype.load = function (args) {
  26588. var self = this;
  26589. var elm = self.getElement(), html;
  26590. if (self.removed) {
  26591. return '';
  26592. }
  26593. if (elm) {
  26594. args = args || {};
  26595. args.load = true;
  26596. var value = NodeType.isTextareaOrInput(elm) ? elm.value : elm.innerHTML;
  26597. html = self.setContent(value, args);
  26598. args.element = elm;
  26599. if (!args.no_events) {
  26600. self.fire('LoadContent', args);
  26601. }
  26602. args.element = elm = null;
  26603. return html;
  26604. }
  26605. };
  26606. Editor.prototype.save = function (args) {
  26607. var self = this;
  26608. var elm = self.getElement(), html, form;
  26609. if (!elm || !self.initialized || self.removed) {
  26610. return;
  26611. }
  26612. args = args || {};
  26613. args.save = true;
  26614. args.element = elm;
  26615. html = args.content = self.getContent(args);
  26616. if (!args.no_events) {
  26617. self.fire('SaveContent', args);
  26618. }
  26619. if (args.format === 'raw') {
  26620. self.fire('RawSaveContent', args);
  26621. }
  26622. html = args.content;
  26623. if (!NodeType.isTextareaOrInput(elm)) {
  26624. if (args.is_removing || !self.inline) {
  26625. elm.innerHTML = html;
  26626. }
  26627. if (form = DOM$8.getParent(self.id, 'form')) {
  26628. each$j(form.elements, function (elm) {
  26629. if (elm.name === self.id) {
  26630. elm.value = html;
  26631. return false;
  26632. }
  26633. });
  26634. }
  26635. } else {
  26636. elm.value = html;
  26637. }
  26638. args.element = elm = null;
  26639. if (args.set_dirty !== false) {
  26640. self.setDirty(false);
  26641. }
  26642. return html;
  26643. };
  26644. Editor.prototype.setContent = function (content, args) {
  26645. return setContent(this, content, args);
  26646. };
  26647. Editor.prototype.getContent = function (args) {
  26648. return getContent(this, args);
  26649. };
  26650. Editor.prototype.insertContent = function (content, args) {
  26651. if (args) {
  26652. content = extend$3({ content: content }, args);
  26653. }
  26654. this.execCommand('mceInsertContent', false, content);
  26655. };
  26656. Editor.prototype.resetContent = function (initialContent) {
  26657. if (initialContent === undefined) {
  26658. setContent(this, this.startContent, { format: 'raw' });
  26659. } else {
  26660. setContent(this, initialContent);
  26661. }
  26662. this.undoManager.reset();
  26663. this.setDirty(false);
  26664. this.nodeChanged();
  26665. };
  26666. Editor.prototype.isDirty = function () {
  26667. return !this.isNotDirty;
  26668. };
  26669. Editor.prototype.setDirty = function (state) {
  26670. var oldState = !this.isNotDirty;
  26671. this.isNotDirty = !state;
  26672. if (state && state !== oldState) {
  26673. this.fire('dirty');
  26674. }
  26675. };
  26676. Editor.prototype.getContainer = function () {
  26677. var self = this;
  26678. if (!self.container) {
  26679. self.container = DOM$8.get(self.editorContainer || self.id + '_parent');
  26680. }
  26681. return self.container;
  26682. };
  26683. Editor.prototype.getContentAreaContainer = function () {
  26684. return this.contentAreaContainer;
  26685. };
  26686. Editor.prototype.getElement = function () {
  26687. if (!this.targetElm) {
  26688. this.targetElm = DOM$8.get(this.id);
  26689. }
  26690. return this.targetElm;
  26691. };
  26692. Editor.prototype.getWin = function () {
  26693. var self = this;
  26694. var elm;
  26695. if (!self.contentWindow) {
  26696. elm = self.iframeElement;
  26697. if (elm) {
  26698. self.contentWindow = elm.contentWindow;
  26699. }
  26700. }
  26701. return self.contentWindow;
  26702. };
  26703. Editor.prototype.getDoc = function () {
  26704. var self = this;
  26705. var win;
  26706. if (!self.contentDocument) {
  26707. win = self.getWin();
  26708. if (win) {
  26709. self.contentDocument = win.document;
  26710. }
  26711. }
  26712. return self.contentDocument;
  26713. };
  26714. Editor.prototype.getBody = function () {
  26715. var doc = this.getDoc();
  26716. return this.bodyElement || (doc ? doc.body : null);
  26717. };
  26718. Editor.prototype.convertURL = function (url, name, elm) {
  26719. var self = this, settings = self.settings;
  26720. if (settings.urlconverter_callback) {
  26721. return self.execCallback('urlconverter_callback', url, elm, true, name);
  26722. }
  26723. if (!settings.convert_urls || elm && elm.nodeName === 'LINK' || url.indexOf('file:') === 0 || url.length === 0) {
  26724. return url;
  26725. }
  26726. if (settings.relative_urls) {
  26727. return self.documentBaseURI.toRelative(url);
  26728. }
  26729. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  26730. return url;
  26731. };
  26732. Editor.prototype.addVisual = function (elm) {
  26733. var self = this;
  26734. var settings = self.settings;
  26735. var dom = self.dom;
  26736. var cls;
  26737. elm = elm || self.getBody();
  26738. if (self.hasVisual === undefined) {
  26739. self.hasVisual = settings.visual;
  26740. }
  26741. each$j(dom.select('table,a', elm), function (elm) {
  26742. var value;
  26743. switch (elm.nodeName) {
  26744. case 'TABLE':
  26745. cls = settings.visual_table_class || 'mce-item-table';
  26746. value = dom.getAttrib(elm, 'border');
  26747. if ((!value || value === '0') && self.hasVisual) {
  26748. dom.addClass(elm, cls);
  26749. } else {
  26750. dom.removeClass(elm, cls);
  26751. }
  26752. return;
  26753. case 'A':
  26754. if (!dom.getAttrib(elm, 'href')) {
  26755. value = dom.getAttrib(elm, 'name') || elm.id;
  26756. cls = settings.visual_anchor_class || 'mce-item-anchor';
  26757. if (value && self.hasVisual) {
  26758. dom.addClass(elm, cls);
  26759. } else {
  26760. dom.removeClass(elm, cls);
  26761. }
  26762. }
  26763. return;
  26764. }
  26765. });
  26766. self.fire('VisualAid', {
  26767. element: elm,
  26768. hasVisual: self.hasVisual
  26769. });
  26770. };
  26771. Editor.prototype.remove = function () {
  26772. remove$6(this);
  26773. };
  26774. Editor.prototype.destroy = function (automatic) {
  26775. destroy(this, automatic);
  26776. };
  26777. Editor.prototype.uploadImages = function (callback) {
  26778. return this.editorUpload.uploadImages(callback);
  26779. };
  26780. Editor.prototype._scanForImages = function () {
  26781. return this.editorUpload.scanForImages();
  26782. };
  26783. Editor.prototype.addButton = function () {
  26784. throw new Error('editor.addButton has been removed in tinymce 5x, use editor.ui.registry.addButton or editor.ui.registry.addToggleButton or editor.ui.registry.addSplitButton instead');
  26785. };
  26786. Editor.prototype.addSidebar = function () {
  26787. throw new Error('editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead');
  26788. };
  26789. Editor.prototype.addMenuItem = function () {
  26790. throw new Error('editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead');
  26791. };
  26792. Editor.prototype.addContextToolbar = function () {
  26793. throw new Error('editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead');
  26794. };
  26795. return Editor;
  26796. }();
  26797. var DOM$9 = DOMUtils$1.DOM;
  26798. var explode$4 = Tools.explode, each$k = Tools.each, extend$4 = Tools.extend;
  26799. var instanceCounter = 0, boundGlobalEvents = false;
  26800. var beforeUnloadDelegate;
  26801. var legacyEditors = [];
  26802. var editors = [];
  26803. var isValidLegacyKey = function (id) {
  26804. return id !== 'length';
  26805. };
  26806. var globalEventDelegate = function (e) {
  26807. var type = e.type;
  26808. each$k(EditorManager.get(), function (editor) {
  26809. switch (type) {
  26810. case 'scroll':
  26811. editor.fire('ScrollWindow', e);
  26812. break;
  26813. case 'resize':
  26814. editor.fire('ResizeWindow', e);
  26815. break;
  26816. }
  26817. });
  26818. };
  26819. var toggleGlobalEvents = function (state) {
  26820. if (state !== boundGlobalEvents) {
  26821. if (state) {
  26822. DomQuery(window).on('resize scroll', globalEventDelegate);
  26823. } else {
  26824. DomQuery(window).off('resize scroll', globalEventDelegate);
  26825. }
  26826. boundGlobalEvents = state;
  26827. }
  26828. };
  26829. var removeEditorFromList = function (targetEditor) {
  26830. var oldEditors = editors;
  26831. delete legacyEditors[targetEditor.id];
  26832. for (var i = 0; i < legacyEditors.length; i++) {
  26833. if (legacyEditors[i] === targetEditor) {
  26834. legacyEditors.splice(i, 1);
  26835. break;
  26836. }
  26837. }
  26838. editors = filter(editors, function (editor) {
  26839. return targetEditor !== editor;
  26840. });
  26841. if (EditorManager.activeEditor === targetEditor) {
  26842. EditorManager.activeEditor = editors.length > 0 ? editors[0] : null;
  26843. }
  26844. if (EditorManager.focusedEditor === targetEditor) {
  26845. EditorManager.focusedEditor = null;
  26846. }
  26847. return oldEditors.length !== editors.length;
  26848. };
  26849. var purgeDestroyedEditor = function (editor) {
  26850. if (editor && editor.initialized && !(editor.getContainer() || editor.getBody()).parentNode) {
  26851. removeEditorFromList(editor);
  26852. editor.unbindAllNativeEvents();
  26853. editor.destroy(true);
  26854. editor.removed = true;
  26855. editor = null;
  26856. }
  26857. return editor;
  26858. };
  26859. var isQuirksMode = domGlobals.document.compatMode !== 'CSS1Compat';
  26860. var EditorManager = __assign(__assign({}, Observable), {
  26861. baseURI: null,
  26862. baseURL: null,
  26863. defaultSettings: {},
  26864. documentBaseURL: null,
  26865. suffix: null,
  26866. $: DomQuery,
  26867. majorVersion: '5',
  26868. minorVersion: '1.0',
  26869. releaseDate: '2019-10-17',
  26870. editors: legacyEditors,
  26871. i18n: I18n,
  26872. activeEditor: null,
  26873. focusedEditor: null,
  26874. settings: {},
  26875. setup: function () {
  26876. var self = this;
  26877. var baseURL, documentBaseURL, suffix = '';
  26878. documentBaseURL = URI.getDocumentBaseUrl(domGlobals.document.location);
  26879. if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) {
  26880. documentBaseURL = documentBaseURL.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  26881. if (!/[\/\\]$/.test(documentBaseURL)) {
  26882. documentBaseURL += '/';
  26883. }
  26884. }
  26885. var preInit = window.tinymce || window.tinyMCEPreInit;
  26886. if (preInit) {
  26887. baseURL = preInit.base || preInit.baseURL;
  26888. suffix = preInit.suffix;
  26889. } else {
  26890. var scripts = domGlobals.document.getElementsByTagName('script');
  26891. for (var i = 0; i < scripts.length; i++) {
  26892. var src = scripts[i].src || '';
  26893. if (src === '') {
  26894. continue;
  26895. }
  26896. var srcScript = src.substring(src.lastIndexOf('/'));
  26897. if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
  26898. if (srcScript.indexOf('.min') !== -1) {
  26899. suffix = '.min';
  26900. }
  26901. baseURL = src.substring(0, src.lastIndexOf('/'));
  26902. break;
  26903. }
  26904. }
  26905. if (!baseURL && domGlobals.document.currentScript) {
  26906. var src = domGlobals.document.currentScript.src;
  26907. if (src.indexOf('.min') !== -1) {
  26908. suffix = '.min';
  26909. }
  26910. baseURL = src.substring(0, src.lastIndexOf('/'));
  26911. }
  26912. }
  26913. self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL);
  26914. self.documentBaseURL = documentBaseURL;
  26915. self.baseURI = new URI(self.baseURL);
  26916. self.suffix = suffix;
  26917. FocusController.setup(self);
  26918. },
  26919. overrideDefaults: function (defaultSettings) {
  26920. var baseUrl, suffix;
  26921. baseUrl = defaultSettings.base_url;
  26922. if (baseUrl) {
  26923. this._setBaseUrl(baseUrl);
  26924. }
  26925. suffix = defaultSettings.suffix;
  26926. if (defaultSettings.suffix) {
  26927. this.suffix = suffix;
  26928. }
  26929. this.defaultSettings = defaultSettings;
  26930. var pluginBaseUrls = defaultSettings.plugin_base_urls;
  26931. for (var name in pluginBaseUrls) {
  26932. AddOnManager$1.PluginManager.urls[name] = pluginBaseUrls[name];
  26933. }
  26934. },
  26935. init: function (settings) {
  26936. var self = this;
  26937. var result, invalidInlineTargets;
  26938. invalidInlineTargets = Tools.makeMap('area base basefont br col frame hr img input isindex link meta param embed source wbr track ' + 'colgroup option table tbody tfoot thead tr th td script noscript style textarea video audio iframe object menu', ' ');
  26939. var isInvalidInlineTarget = function (settings, elm) {
  26940. return settings.inline && elm.tagName.toLowerCase() in invalidInlineTargets;
  26941. };
  26942. var createId = function (elm) {
  26943. var id = elm.id;
  26944. if (!id) {
  26945. id = elm.name;
  26946. if (id && !DOM$9.get(id)) {
  26947. id = elm.name;
  26948. } else {
  26949. id = DOM$9.uniqueId();
  26950. }
  26951. elm.setAttribute('id', id);
  26952. }
  26953. return id;
  26954. };
  26955. var execCallback = function (name) {
  26956. var callback = settings[name];
  26957. if (!callback) {
  26958. return;
  26959. }
  26960. return callback.apply(self, Array.prototype.slice.call(arguments, 2));
  26961. };
  26962. var hasClass = function (elm, className) {
  26963. return className.constructor === RegExp ? className.test(elm.className) : DOM$9.hasClass(elm, className);
  26964. };
  26965. var findTargets = function (settings) {
  26966. var l, targets = [];
  26967. if (Env.browser.isIE() && Env.browser.version.major < 11) {
  26968. ErrorReporter.initError('TinyMCE does not support the browser you are using. For a list of supported' + ' browsers please see: https://www.tinymce.com/docs/get-started/system-requirements/');
  26969. return [];
  26970. } else if (isQuirksMode) {
  26971. ErrorReporter.initError('Failed to initialize the editor as the document is not in standards mode. ' + 'TinyMCE requires standards mode.');
  26972. return [];
  26973. }
  26974. if (settings.types) {
  26975. each$k(settings.types, function (type) {
  26976. targets = targets.concat(DOM$9.select(type.selector));
  26977. });
  26978. return targets;
  26979. } else if (settings.selector) {
  26980. return DOM$9.select(settings.selector);
  26981. } else if (settings.target) {
  26982. return [settings.target];
  26983. }
  26984. switch (settings.mode) {
  26985. case 'exact':
  26986. l = settings.elements || '';
  26987. if (l.length > 0) {
  26988. each$k(explode$4(l), function (id) {
  26989. var elm;
  26990. if (elm = DOM$9.get(id)) {
  26991. targets.push(elm);
  26992. } else {
  26993. each$k(domGlobals.document.forms, function (f) {
  26994. each$k(f.elements, function (e) {
  26995. if (e.name === id) {
  26996. id = 'mce_editor_' + instanceCounter++;
  26997. DOM$9.setAttrib(e, 'id', id);
  26998. targets.push(e);
  26999. }
  27000. });
  27001. });
  27002. }
  27003. });
  27004. }
  27005. break;
  27006. case 'textareas':
  27007. case 'specific_textareas':
  27008. each$k(DOM$9.select('textarea'), function (elm) {
  27009. if (settings.editor_deselector && hasClass(elm, settings.editor_deselector)) {
  27010. return;
  27011. }
  27012. if (!settings.editor_selector || hasClass(elm, settings.editor_selector)) {
  27013. targets.push(elm);
  27014. }
  27015. });
  27016. break;
  27017. }
  27018. return targets;
  27019. };
  27020. var provideResults = function (editors) {
  27021. result = editors;
  27022. };
  27023. var initEditors = function () {
  27024. var initCount = 0;
  27025. var editors = [];
  27026. var targets;
  27027. var createEditor = function (id, settings, targetElm) {
  27028. var editor = new Editor(id, settings, self);
  27029. editors.push(editor);
  27030. editor.on('init', function () {
  27031. if (++initCount === targets.length) {
  27032. provideResults(editors);
  27033. }
  27034. });
  27035. editor.targetElm = editor.targetElm || targetElm;
  27036. editor.render();
  27037. };
  27038. DOM$9.unbind(window, 'ready', initEditors);
  27039. execCallback('onpageload');
  27040. targets = DomQuery.unique(findTargets(settings));
  27041. if (settings.types) {
  27042. each$k(settings.types, function (type) {
  27043. Tools.each(targets, function (elm) {
  27044. if (DOM$9.is(elm, type.selector)) {
  27045. createEditor(createId(elm), extend$4({}, settings, type), elm);
  27046. return false;
  27047. }
  27048. return true;
  27049. });
  27050. });
  27051. return;
  27052. }
  27053. Tools.each(targets, function (elm) {
  27054. purgeDestroyedEditor(self.get(elm.id));
  27055. });
  27056. targets = Tools.grep(targets, function (elm) {
  27057. return !self.get(elm.id);
  27058. });
  27059. if (targets.length === 0) {
  27060. provideResults([]);
  27061. } else {
  27062. each$k(targets, function (elm) {
  27063. if (isInvalidInlineTarget(settings, elm)) {
  27064. ErrorReporter.initError('Could not initialize inline editor on invalid inline target element', elm);
  27065. } else {
  27066. createEditor(createId(elm), settings, elm);
  27067. }
  27068. });
  27069. }
  27070. };
  27071. self.settings = settings;
  27072. DOM$9.bind(window, 'ready', initEditors);
  27073. return new promiseObj(function (resolve) {
  27074. if (result) {
  27075. resolve(result);
  27076. } else {
  27077. provideResults = function (editors) {
  27078. resolve(editors);
  27079. };
  27080. }
  27081. });
  27082. },
  27083. get: function (id) {
  27084. if (arguments.length === 0) {
  27085. return editors.slice(0);
  27086. } else if (isString(id)) {
  27087. return find(editors, function (editor) {
  27088. return editor.id === id;
  27089. }).getOr(null);
  27090. } else if (isNumber(id)) {
  27091. return editors[id] ? editors[id] : null;
  27092. } else {
  27093. return null;
  27094. }
  27095. },
  27096. add: function (editor) {
  27097. var self = this;
  27098. var existingEditor;
  27099. existingEditor = legacyEditors[editor.id];
  27100. if (existingEditor === editor) {
  27101. return editor;
  27102. }
  27103. if (self.get(editor.id) === null) {
  27104. if (isValidLegacyKey(editor.id)) {
  27105. legacyEditors[editor.id] = editor;
  27106. }
  27107. legacyEditors.push(editor);
  27108. editors.push(editor);
  27109. }
  27110. toggleGlobalEvents(true);
  27111. self.activeEditor = editor;
  27112. self.fire('AddEditor', { editor: editor });
  27113. if (!beforeUnloadDelegate) {
  27114. beforeUnloadDelegate = function (e) {
  27115. var event = self.fire('BeforeUnload');
  27116. if (event.returnValue) {
  27117. e.preventDefault();
  27118. e.returnValue = event.returnValue;
  27119. return event.returnValue;
  27120. }
  27121. };
  27122. window.addEventListener('beforeunload', beforeUnloadDelegate);
  27123. }
  27124. return editor;
  27125. },
  27126. createEditor: function (id, settings) {
  27127. return this.add(new Editor(id, settings, this));
  27128. },
  27129. remove: function (selector) {
  27130. var self = this;
  27131. var i, editor;
  27132. if (!selector) {
  27133. for (i = editors.length - 1; i >= 0; i--) {
  27134. self.remove(editors[i]);
  27135. }
  27136. return;
  27137. }
  27138. if (isString(selector)) {
  27139. each$k(DOM$9.select(selector), function (elm) {
  27140. editor = self.get(elm.id);
  27141. if (editor) {
  27142. self.remove(editor);
  27143. }
  27144. });
  27145. return;
  27146. }
  27147. editor = selector;
  27148. if (isNull(self.get(editor.id))) {
  27149. return null;
  27150. }
  27151. if (removeEditorFromList(editor)) {
  27152. self.fire('RemoveEditor', { editor: editor });
  27153. }
  27154. if (editors.length === 0) {
  27155. window.removeEventListener('beforeunload', beforeUnloadDelegate);
  27156. }
  27157. editor.remove();
  27158. toggleGlobalEvents(editors.length > 0);
  27159. return editor;
  27160. },
  27161. execCommand: function (cmd, ui, value) {
  27162. var self = this, editor = self.get(value);
  27163. switch (cmd) {
  27164. case 'mceAddEditor':
  27165. if (!self.get(value)) {
  27166. new Editor(value, self.settings, self).render();
  27167. }
  27168. return true;
  27169. case 'mceRemoveEditor':
  27170. if (editor) {
  27171. editor.remove();
  27172. }
  27173. return true;
  27174. case 'mceToggleEditor':
  27175. if (!editor) {
  27176. self.execCommand('mceAddEditor', 0, value);
  27177. return true;
  27178. }
  27179. if (editor.isHidden()) {
  27180. editor.show();
  27181. } else {
  27182. editor.hide();
  27183. }
  27184. return true;
  27185. }
  27186. if (self.activeEditor) {
  27187. return self.activeEditor.execCommand(cmd, ui, value);
  27188. }
  27189. return false;
  27190. },
  27191. triggerSave: function () {
  27192. each$k(editors, function (editor) {
  27193. editor.save();
  27194. });
  27195. },
  27196. addI18n: function (code, items) {
  27197. I18n.add(code, items);
  27198. },
  27199. translate: function (text) {
  27200. return I18n.translate(text);
  27201. },
  27202. setActive: function (editor) {
  27203. var activeEditor = this.activeEditor;
  27204. if (this.activeEditor !== editor) {
  27205. if (activeEditor) {
  27206. activeEditor.fire('deactivate', { relatedTarget: editor });
  27207. }
  27208. editor.fire('activate', { relatedTarget: activeEditor });
  27209. }
  27210. this.activeEditor = editor;
  27211. },
  27212. _setBaseUrl: function (baseUrl) {
  27213. this.baseURL = new URI(this.documentBaseURL).toAbsolute(baseUrl.replace(/\/+$/, ''));
  27214. this.baseURI = new URI(this.baseURL);
  27215. }
  27216. });
  27217. EditorManager.setup();
  27218. function RangeUtils(dom) {
  27219. var walk = function (rng, callback) {
  27220. return RangeWalk.walk(dom, rng, callback);
  27221. };
  27222. var split = split$1;
  27223. var normalize = function (rng) {
  27224. return NormalizeRange.normalize(dom, rng).fold(constant(false), function (normalizedRng) {
  27225. rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);
  27226. rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);
  27227. return true;
  27228. });
  27229. };
  27230. return {
  27231. walk: walk,
  27232. split: split,
  27233. normalize: normalize
  27234. };
  27235. }
  27236. (function (RangeUtils) {
  27237. RangeUtils.compareRanges = RangeCompare.isEq;
  27238. RangeUtils.getCaretRangeFromPoint = CaretRangeFromPoint.fromPoint;
  27239. RangeUtils.getSelectedNode = getSelectedNode;
  27240. RangeUtils.getNode = getNode;
  27241. }(RangeUtils || (RangeUtils = {})));
  27242. var RangeUtils$1 = RangeUtils;
  27243. var awaiter = function (resolveCb, rejectCb, timeout) {
  27244. if (timeout === void 0) {
  27245. timeout = 1000;
  27246. }
  27247. var done = false;
  27248. var timer = null;
  27249. var complete = function (completer) {
  27250. return function () {
  27251. var args = [];
  27252. for (var _i = 0; _i < arguments.length; _i++) {
  27253. args[_i] = arguments[_i];
  27254. }
  27255. if (!done) {
  27256. done = true;
  27257. if (timer !== null) {
  27258. domGlobals.clearTimeout(timer);
  27259. timer = null;
  27260. }
  27261. completer.apply(null, args);
  27262. }
  27263. };
  27264. };
  27265. var resolve = complete(resolveCb);
  27266. var reject = complete(rejectCb);
  27267. var start = function () {
  27268. var args = [];
  27269. for (var _i = 0; _i < arguments.length; _i++) {
  27270. args[_i] = arguments[_i];
  27271. }
  27272. if (!done && timer === null) {
  27273. timer = domGlobals.setTimeout(function () {
  27274. return reject.apply(null, args);
  27275. }, timeout);
  27276. }
  27277. };
  27278. return {
  27279. start: start,
  27280. resolve: resolve,
  27281. reject: reject
  27282. };
  27283. };
  27284. var create$6 = function () {
  27285. var tasks = {};
  27286. var resultFns = {};
  27287. var load = function (id, url) {
  27288. var loadErrMsg = 'Script at URL "' + url + '" failed to load';
  27289. var runErrMsg = 'Script at URL "' + url + '" did not call `tinymce.Resource.add(\'' + id + '\', data)` within 1 second';
  27290. if (tasks[id] !== undefined) {
  27291. return tasks[id];
  27292. } else {
  27293. var task = new promiseObj(function (resolve, reject) {
  27294. var waiter = awaiter(resolve, reject);
  27295. resultFns[id] = waiter.resolve;
  27296. ScriptLoader.ScriptLoader.loadScript(url, function () {
  27297. return waiter.start(runErrMsg);
  27298. }, function () {
  27299. return waiter.reject(loadErrMsg);
  27300. });
  27301. });
  27302. tasks[id] = task;
  27303. return task;
  27304. }
  27305. };
  27306. var add = function (id, data) {
  27307. if (resultFns[id] !== undefined) {
  27308. resultFns[id](data);
  27309. delete resultFns[id];
  27310. }
  27311. tasks[id] = promiseObj.resolve(data);
  27312. };
  27313. return {
  27314. load: load,
  27315. add: add
  27316. };
  27317. };
  27318. var Resource = create$6();
  27319. var min = Math.min, max = Math.max, round$2 = Math.round;
  27320. var relativePosition = function (rect, targetRect, rel) {
  27321. var x, y, w, h, targetW, targetH;
  27322. x = targetRect.x;
  27323. y = targetRect.y;
  27324. w = rect.w;
  27325. h = rect.h;
  27326. targetW = targetRect.w;
  27327. targetH = targetRect.h;
  27328. rel = (rel || '').split('');
  27329. if (rel[0] === 'b') {
  27330. y += targetH;
  27331. }
  27332. if (rel[1] === 'r') {
  27333. x += targetW;
  27334. }
  27335. if (rel[0] === 'c') {
  27336. y += round$2(targetH / 2);
  27337. }
  27338. if (rel[1] === 'c') {
  27339. x += round$2(targetW / 2);
  27340. }
  27341. if (rel[3] === 'b') {
  27342. y -= h;
  27343. }
  27344. if (rel[4] === 'r') {
  27345. x -= w;
  27346. }
  27347. if (rel[3] === 'c') {
  27348. y -= round$2(h / 2);
  27349. }
  27350. if (rel[4] === 'c') {
  27351. x -= round$2(w / 2);
  27352. }
  27353. return create$7(x, y, w, h);
  27354. };
  27355. var findBestRelativePosition = function (rect, targetRect, constrainRect, rels) {
  27356. var pos, i;
  27357. for (i = 0; i < rels.length; i++) {
  27358. pos = relativePosition(rect, targetRect, rels[i]);
  27359. if (pos.x >= constrainRect.x && pos.x + pos.w <= constrainRect.w + constrainRect.x && pos.y >= constrainRect.y && pos.y + pos.h <= constrainRect.h + constrainRect.y) {
  27360. return rels[i];
  27361. }
  27362. }
  27363. return null;
  27364. };
  27365. var inflate = function (rect, w, h) {
  27366. return create$7(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2);
  27367. };
  27368. var intersect = function (rect, cropRect) {
  27369. var x1, y1, x2, y2;
  27370. x1 = max(rect.x, cropRect.x);
  27371. y1 = max(rect.y, cropRect.y);
  27372. x2 = min(rect.x + rect.w, cropRect.x + cropRect.w);
  27373. y2 = min(rect.y + rect.h, cropRect.y + cropRect.h);
  27374. if (x2 - x1 < 0 || y2 - y1 < 0) {
  27375. return null;
  27376. }
  27377. return create$7(x1, y1, x2 - x1, y2 - y1);
  27378. };
  27379. var clamp$1 = function (rect, clampRect, fixedSize) {
  27380. var underflowX1, underflowY1, overflowX2, overflowY2, x1, y1, x2, y2, cx2, cy2;
  27381. x1 = rect.x;
  27382. y1 = rect.y;
  27383. x2 = rect.x + rect.w;
  27384. y2 = rect.y + rect.h;
  27385. cx2 = clampRect.x + clampRect.w;
  27386. cy2 = clampRect.y + clampRect.h;
  27387. underflowX1 = max(0, clampRect.x - x1);
  27388. underflowY1 = max(0, clampRect.y - y1);
  27389. overflowX2 = max(0, x2 - cx2);
  27390. overflowY2 = max(0, y2 - cy2);
  27391. x1 += underflowX1;
  27392. y1 += underflowY1;
  27393. if (fixedSize) {
  27394. x2 += underflowX1;
  27395. y2 += underflowY1;
  27396. x1 -= overflowX2;
  27397. y1 -= overflowY2;
  27398. }
  27399. x2 -= overflowX2;
  27400. y2 -= overflowY2;
  27401. return create$7(x1, y1, x2 - x1, y2 - y1);
  27402. };
  27403. var create$7 = function (x, y, w, h) {
  27404. return {
  27405. x: x,
  27406. y: y,
  27407. w: w,
  27408. h: h
  27409. };
  27410. };
  27411. var fromClientRect = function (clientRect) {
  27412. return create$7(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
  27413. };
  27414. var Rect = {
  27415. inflate: inflate,
  27416. relativePosition: relativePosition,
  27417. findBestRelativePosition: findBestRelativePosition,
  27418. intersect: intersect,
  27419. clamp: clamp$1,
  27420. create: create$7,
  27421. fromClientRect: fromClientRect
  27422. };
  27423. var each$l = Tools.each, extend$5 = Tools.extend;
  27424. var extendClass, initializing;
  27425. var Class = function () {
  27426. };
  27427. Class.extend = extendClass = function (prop) {
  27428. var self = this;
  27429. var _super = self.prototype;
  27430. var prototype, name, member;
  27431. var Class = function () {
  27432. var i, mixins, mixin;
  27433. var self = this;
  27434. if (!initializing) {
  27435. if (self.init) {
  27436. self.init.apply(self, arguments);
  27437. }
  27438. mixins = self.Mixins;
  27439. if (mixins) {
  27440. i = mixins.length;
  27441. while (i--) {
  27442. mixin = mixins[i];
  27443. if (mixin.init) {
  27444. mixin.init.apply(self, arguments);
  27445. }
  27446. }
  27447. }
  27448. }
  27449. };
  27450. var dummy = function () {
  27451. return this;
  27452. };
  27453. var createMethod = function (name, fn) {
  27454. return function () {
  27455. var self = this;
  27456. var tmp = self._super;
  27457. var ret;
  27458. self._super = _super[name];
  27459. ret = fn.apply(self, arguments);
  27460. self._super = tmp;
  27461. return ret;
  27462. };
  27463. };
  27464. initializing = true;
  27465. prototype = new self();
  27466. initializing = false;
  27467. if (prop.Mixins) {
  27468. each$l(prop.Mixins, function (mixin) {
  27469. for (var name_1 in mixin) {
  27470. if (name_1 !== 'init') {
  27471. prop[name_1] = mixin[name_1];
  27472. }
  27473. }
  27474. });
  27475. if (_super.Mixins) {
  27476. prop.Mixins = _super.Mixins.concat(prop.Mixins);
  27477. }
  27478. }
  27479. if (prop.Methods) {
  27480. each$l(prop.Methods.split(','), function (name) {
  27481. prop[name] = dummy;
  27482. });
  27483. }
  27484. if (prop.Properties) {
  27485. each$l(prop.Properties.split(','), function (name) {
  27486. var fieldName = '_' + name;
  27487. prop[name] = function (value) {
  27488. var self = this;
  27489. if (value !== undefined) {
  27490. self[fieldName] = value;
  27491. return self;
  27492. }
  27493. return self[fieldName];
  27494. };
  27495. });
  27496. }
  27497. if (prop.Statics) {
  27498. each$l(prop.Statics, function (func, name) {
  27499. Class[name] = func;
  27500. });
  27501. }
  27502. if (prop.Defaults && _super.Defaults) {
  27503. prop.Defaults = extend$5({}, _super.Defaults, prop.Defaults);
  27504. }
  27505. for (name in prop) {
  27506. member = prop[name];
  27507. if (typeof member === 'function' && _super[name]) {
  27508. prototype[name] = createMethod(name, member);
  27509. } else {
  27510. prototype[name] = member;
  27511. }
  27512. }
  27513. Class.prototype = prototype;
  27514. Class.constructor = Class;
  27515. Class.extend = extendClass;
  27516. return Class;
  27517. };
  27518. var min$1 = Math.min, max$1 = Math.max, round$3 = Math.round;
  27519. var Color = function (value) {
  27520. var self = {};
  27521. var r = 0, g = 0, b = 0;
  27522. var rgb2hsv = function (r, g, b) {
  27523. var h, s, v, d, minRGB, maxRGB;
  27524. h = 0;
  27525. s = 0;
  27526. v = 0;
  27527. r = r / 255;
  27528. g = g / 255;
  27529. b = b / 255;
  27530. minRGB = min$1(r, min$1(g, b));
  27531. maxRGB = max$1(r, max$1(g, b));
  27532. if (minRGB === maxRGB) {
  27533. v = minRGB;
  27534. return {
  27535. h: 0,
  27536. s: 0,
  27537. v: v * 100
  27538. };
  27539. }
  27540. d = r === minRGB ? g - b : b === minRGB ? r - g : b - r;
  27541. h = r === minRGB ? 3 : b === minRGB ? 1 : 5;
  27542. h = 60 * (h - d / (maxRGB - minRGB));
  27543. s = (maxRGB - minRGB) / maxRGB;
  27544. v = maxRGB;
  27545. return {
  27546. h: round$3(h),
  27547. s: round$3(s * 100),
  27548. v: round$3(v * 100)
  27549. };
  27550. };
  27551. var hsvToRgb = function (hue, saturation, brightness) {
  27552. var side, chroma, x, match;
  27553. hue = (parseInt(hue, 10) || 0) % 360;
  27554. saturation = parseInt(saturation, 10) / 100;
  27555. brightness = parseInt(brightness, 10) / 100;
  27556. saturation = max$1(0, min$1(saturation, 1));
  27557. brightness = max$1(0, min$1(brightness, 1));
  27558. if (saturation === 0) {
  27559. r = g = b = round$3(255 * brightness);
  27560. return;
  27561. }
  27562. side = hue / 60;
  27563. chroma = brightness * saturation;
  27564. x = chroma * (1 - Math.abs(side % 2 - 1));
  27565. match = brightness - chroma;
  27566. switch (Math.floor(side)) {
  27567. case 0:
  27568. r = chroma;
  27569. g = x;
  27570. b = 0;
  27571. break;
  27572. case 1:
  27573. r = x;
  27574. g = chroma;
  27575. b = 0;
  27576. break;
  27577. case 2:
  27578. r = 0;
  27579. g = chroma;
  27580. b = x;
  27581. break;
  27582. case 3:
  27583. r = 0;
  27584. g = x;
  27585. b = chroma;
  27586. break;
  27587. case 4:
  27588. r = x;
  27589. g = 0;
  27590. b = chroma;
  27591. break;
  27592. case 5:
  27593. r = chroma;
  27594. g = 0;
  27595. b = x;
  27596. break;
  27597. default:
  27598. r = g = b = 0;
  27599. }
  27600. r = round$3(255 * (r + match));
  27601. g = round$3(255 * (g + match));
  27602. b = round$3(255 * (b + match));
  27603. };
  27604. var toHex = function () {
  27605. var hex = function (val) {
  27606. val = parseInt(val, 10).toString(16);
  27607. return val.length > 1 ? val : '0' + val;
  27608. };
  27609. return '#' + hex(r) + hex(g) + hex(b);
  27610. };
  27611. var toRgb = function () {
  27612. return {
  27613. r: r,
  27614. g: g,
  27615. b: b
  27616. };
  27617. };
  27618. var toHsv = function () {
  27619. return rgb2hsv(r, g, b);
  27620. };
  27621. var parse = function (value) {
  27622. var matches;
  27623. if (typeof value === 'object') {
  27624. if ('r' in value) {
  27625. r = value.r;
  27626. g = value.g;
  27627. b = value.b;
  27628. } else if ('v' in value) {
  27629. hsvToRgb(value.h, value.s, value.v);
  27630. }
  27631. } else {
  27632. if (matches = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(value)) {
  27633. r = parseInt(matches[1], 10);
  27634. g = parseInt(matches[2], 10);
  27635. b = parseInt(matches[3], 10);
  27636. } else if (matches = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value)) {
  27637. r = parseInt(matches[1], 16);
  27638. g = parseInt(matches[2], 16);
  27639. b = parseInt(matches[3], 16);
  27640. } else if (matches = /#([0-F])([0-F])([0-F])/gi.exec(value)) {
  27641. r = parseInt(matches[1] + matches[1], 16);
  27642. g = parseInt(matches[2] + matches[2], 16);
  27643. b = parseInt(matches[3] + matches[3], 16);
  27644. }
  27645. }
  27646. r = r < 0 ? 0 : r > 255 ? 255 : r;
  27647. g = g < 0 ? 0 : g > 255 ? 255 : g;
  27648. b = b < 0 ? 0 : b > 255 ? 255 : b;
  27649. return self;
  27650. };
  27651. if (value) {
  27652. parse(value);
  27653. }
  27654. self.toRgb = toRgb;
  27655. self.toHsv = toHsv;
  27656. self.toHex = toHex;
  27657. self.parse = parse;
  27658. return self;
  27659. };
  27660. var serialize = function (obj) {
  27661. var data = JSON.stringify(obj);
  27662. if (!isString(data)) {
  27663. return data;
  27664. }
  27665. return data.replace(/[\u0080-\uFFFF]/g, function (match) {
  27666. var hexCode = match.charCodeAt(0).toString(16);
  27667. return '\\u' + '0000'.substring(hexCode.length) + hexCode;
  27668. });
  27669. };
  27670. var JSONUtils = {
  27671. serialize: serialize,
  27672. parse: function (text) {
  27673. try {
  27674. return JSON.parse(text);
  27675. } catch (ex) {
  27676. }
  27677. }
  27678. };
  27679. var JSONP = {
  27680. callbacks: {},
  27681. count: 0,
  27682. send: function (settings) {
  27683. var self = this, dom = DOMUtils$1.DOM, count = settings.count !== undefined ? settings.count : self.count;
  27684. var id = 'tinymce_jsonp_' + count;
  27685. self.callbacks[count] = function (json) {
  27686. dom.remove(id);
  27687. delete self.callbacks[count];
  27688. settings.callback(json);
  27689. };
  27690. dom.add(dom.doc.body, 'script', {
  27691. id: id,
  27692. src: settings.url,
  27693. type: 'text/javascript'
  27694. });
  27695. self.count++;
  27696. }
  27697. };
  27698. var XHR = __assign(__assign({}, Observable), {
  27699. send: function (settings) {
  27700. var xhr, count = 0;
  27701. var ready = function () {
  27702. if (!settings.async || xhr.readyState === 4 || count++ > 10000) {
  27703. if (settings.success && count < 10000 && xhr.status === 200) {
  27704. settings.success.call(settings.success_scope, '' + xhr.responseText, xhr, settings);
  27705. } else if (settings.error) {
  27706. settings.error.call(settings.error_scope, count > 10000 ? 'TIMED_OUT' : 'GENERAL', xhr, settings);
  27707. }
  27708. xhr = null;
  27709. } else {
  27710. Delay.setTimeout(ready, 10);
  27711. }
  27712. };
  27713. settings.scope = settings.scope || this;
  27714. settings.success_scope = settings.success_scope || settings.scope;
  27715. settings.error_scope = settings.error_scope || settings.scope;
  27716. settings.async = settings.async !== false;
  27717. settings.data = settings.data || '';
  27718. XHR.fire('beforeInitialize', { settings: settings });
  27719. xhr = new domGlobals.XMLHttpRequest();
  27720. if (xhr) {
  27721. if (xhr.overrideMimeType) {
  27722. xhr.overrideMimeType(settings.content_type);
  27723. }
  27724. xhr.open(settings.type || (settings.data ? 'POST' : 'GET'), settings.url, settings.async);
  27725. if (settings.crossDomain) {
  27726. xhr.withCredentials = true;
  27727. }
  27728. if (settings.content_type) {
  27729. xhr.setRequestHeader('Content-Type', settings.content_type);
  27730. }
  27731. if (settings.requestheaders) {
  27732. Tools.each(settings.requestheaders, function (header) {
  27733. xhr.setRequestHeader(header.key, header.value);
  27734. });
  27735. }
  27736. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  27737. xhr = XHR.fire('beforeSend', {
  27738. xhr: xhr,
  27739. settings: settings
  27740. }).xhr;
  27741. xhr.send(settings.data);
  27742. if (!settings.async) {
  27743. return ready();
  27744. }
  27745. Delay.setTimeout(ready, 10);
  27746. }
  27747. }
  27748. });
  27749. var extend$6 = Tools.extend;
  27750. var JSONRequest = function () {
  27751. function JSONRequest(settings) {
  27752. this.settings = extend$6({}, settings);
  27753. this.count = 0;
  27754. }
  27755. JSONRequest.sendRPC = function (o) {
  27756. return new JSONRequest().send(o);
  27757. };
  27758. JSONRequest.prototype.send = function (args) {
  27759. var ecb = args.error, scb = args.success;
  27760. var xhrArgs = extend$6(this.settings, args);
  27761. xhrArgs.success = function (c, x) {
  27762. c = JSONUtils.parse(c);
  27763. if (typeof c === 'undefined') {
  27764. c = { error: 'JSON Parse error.' };
  27765. }
  27766. if (c.error) {
  27767. ecb.call(xhrArgs.error_scope || xhrArgs.scope, c.error, x);
  27768. } else {
  27769. scb.call(xhrArgs.success_scope || xhrArgs.scope, c.result);
  27770. }
  27771. };
  27772. xhrArgs.error = function (ty, x) {
  27773. if (ecb) {
  27774. ecb.call(xhrArgs.error_scope || xhrArgs.scope, ty, x);
  27775. }
  27776. };
  27777. xhrArgs.data = JSONUtils.serialize({
  27778. id: args.id || 'c' + this.count++,
  27779. method: args.method,
  27780. params: args.params
  27781. });
  27782. xhrArgs.content_type = 'application/json';
  27783. XHR.send(xhrArgs);
  27784. };
  27785. return JSONRequest;
  27786. }();
  27787. var create$8 = function () {
  27788. return function () {
  27789. var data = {};
  27790. var keys = [];
  27791. var storage = {
  27792. getItem: function (key) {
  27793. var item = data[key];
  27794. return item ? item : null;
  27795. },
  27796. setItem: function (key, value) {
  27797. keys.push(key);
  27798. data[key] = String(value);
  27799. },
  27800. key: function (index) {
  27801. return keys[index];
  27802. },
  27803. removeItem: function (key) {
  27804. keys = keys.filter(function (k) {
  27805. return k === key;
  27806. });
  27807. delete data[key];
  27808. },
  27809. clear: function () {
  27810. keys = [];
  27811. data = {};
  27812. },
  27813. length: 0
  27814. };
  27815. Object.defineProperty(storage, 'length', {
  27816. get: function () {
  27817. return keys.length;
  27818. },
  27819. configurable: false,
  27820. enumerable: false
  27821. });
  27822. return storage;
  27823. }();
  27824. };
  27825. var localStorage;
  27826. try {
  27827. localStorage = domGlobals.window.localStorage;
  27828. } catch (e) {
  27829. localStorage = create$8();
  27830. }
  27831. var LocalStorage = localStorage;
  27832. var publicApi = {
  27833. geom: { Rect: Rect },
  27834. util: {
  27835. Promise: promiseObj,
  27836. Delay: Delay,
  27837. Tools: Tools,
  27838. VK: VK,
  27839. URI: URI,
  27840. Class: Class,
  27841. EventDispatcher: EventDispatcher,
  27842. Observable: Observable,
  27843. I18n: I18n,
  27844. XHR: XHR,
  27845. JSON: JSONUtils,
  27846. JSONRequest: JSONRequest,
  27847. JSONP: JSONP,
  27848. LocalStorage: LocalStorage,
  27849. Color: Color
  27850. },
  27851. dom: {
  27852. EventUtils: EventUtils,
  27853. Sizzle: Sizzle,
  27854. DomQuery: DomQuery,
  27855. TreeWalker: TreeWalker,
  27856. DOMUtils: DOMUtils$1,
  27857. ScriptLoader: ScriptLoader,
  27858. RangeUtils: RangeUtils$1,
  27859. Serializer: Serializer$1,
  27860. ControlSelection: ControlSelection,
  27861. BookmarkManager: BookmarkManager$1,
  27862. Selection: Selection$1,
  27863. Event: EventUtils.Event
  27864. },
  27865. html: {
  27866. Styles: Styles,
  27867. Entities: Entities,
  27868. Node: Node$1,
  27869. Schema: Schema,
  27870. SaxParser: SaxParser$1,
  27871. DomParser: DomParser,
  27872. Writer: Writer,
  27873. Serializer: Serializer
  27874. },
  27875. Env: Env,
  27876. AddOnManager: AddOnManager$1,
  27877. Annotator: Annotator,
  27878. Formatter: Formatter,
  27879. UndoManager: UndoManager,
  27880. EditorCommands: EditorCommands,
  27881. WindowManager: WindowManager,
  27882. NotificationManager: NotificationManager,
  27883. EditorObservable: EditorObservable,
  27884. Shortcuts: Shortcuts,
  27885. Editor: Editor,
  27886. FocusManager: FocusManager,
  27887. EditorManager: EditorManager,
  27888. DOM: DOMUtils$1.DOM,
  27889. ScriptLoader: ScriptLoader.ScriptLoader,
  27890. PluginManager: AddOnManager$1.PluginManager,
  27891. ThemeManager: AddOnManager$1.ThemeManager,
  27892. IconManager: IconManager,
  27893. Resource: Resource,
  27894. trim: Tools.trim,
  27895. isArray: Tools.isArray,
  27896. is: Tools.is,
  27897. toArray: Tools.toArray,
  27898. makeMap: Tools.makeMap,
  27899. each: Tools.each,
  27900. map: Tools.map,
  27901. grep: Tools.grep,
  27902. inArray: Tools.inArray,
  27903. extend: Tools.extend,
  27904. create: Tools.create,
  27905. walk: Tools.walk,
  27906. createNS: Tools.createNS,
  27907. resolve: Tools.resolve,
  27908. explode: Tools.explode,
  27909. _addCacheSuffix: Tools._addCacheSuffix,
  27910. isOpera: Env.opera,
  27911. isWebKit: Env.webkit,
  27912. isIE: Env.ie,
  27913. isGecko: Env.gecko,
  27914. isMac: Env.mac
  27915. };
  27916. var tinymce = Tools.extend(EditorManager, publicApi);
  27917. var exportToModuleLoaders = function (tinymce) {
  27918. if (typeof module === 'object') {
  27919. try {
  27920. module.exports = tinymce;
  27921. } catch (_) {
  27922. }
  27923. }
  27924. };
  27925. var exportToWindowGlobal = function (tinymce) {
  27926. window.tinymce = tinymce;
  27927. window.tinyMCE = tinymce;
  27928. };
  27929. exportToWindowGlobal(tinymce);
  27930. exportToModuleLoaders(tinymce);
  27931. }(window));