tinymce_tinymce.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730
  1. import {
  2. __commonJS,
  3. init_define_APP_INFO
  4. } from "./chunk-XY75H3MP.js";
  5. // node_modules/tinymce/tinymce.js
  6. var require_tinymce = __commonJS({
  7. "node_modules/tinymce/tinymce.js"(exports, module) {
  8. init_define_APP_INFO();
  9. (function() {
  10. "use strict";
  11. var typeOf$1 = function(x) {
  12. if (x === null) {
  13. return "null";
  14. }
  15. if (x === void 0) {
  16. return "undefined";
  17. }
  18. var t = typeof x;
  19. if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  20. return "array";
  21. }
  22. if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  23. return "string";
  24. }
  25. return t;
  26. };
  27. var isEquatableType = function(x) {
  28. return [
  29. "undefined",
  30. "boolean",
  31. "number",
  32. "string",
  33. "function",
  34. "xml",
  35. "null"
  36. ].indexOf(x) !== -1;
  37. };
  38. var sort$1 = function(xs, compareFn) {
  39. var clone2 = Array.prototype.slice.call(xs);
  40. return clone2.sort(compareFn);
  41. };
  42. var contramap = function(eqa, f) {
  43. return eq$2(function(x, y) {
  44. return eqa.eq(f(x), f(y));
  45. });
  46. };
  47. var eq$2 = function(f) {
  48. return { eq: f };
  49. };
  50. var tripleEq = eq$2(function(x, y) {
  51. return x === y;
  52. });
  53. var eqString = tripleEq;
  54. var eqArray = function(eqa) {
  55. return eq$2(function(x, y) {
  56. if (x.length !== y.length) {
  57. return false;
  58. }
  59. var len = x.length;
  60. for (var i = 0; i < len; i++) {
  61. if (!eqa.eq(x[i], y[i])) {
  62. return false;
  63. }
  64. }
  65. return true;
  66. });
  67. };
  68. var eqSortedArray = function(eqa, compareFn) {
  69. return contramap(eqArray(eqa), function(xs) {
  70. return sort$1(xs, compareFn);
  71. });
  72. };
  73. var eqRecord = function(eqa) {
  74. return eq$2(function(x, y) {
  75. var kx = Object.keys(x);
  76. var ky = Object.keys(y);
  77. if (!eqSortedArray(eqString).eq(kx, ky)) {
  78. return false;
  79. }
  80. var len = kx.length;
  81. for (var i = 0; i < len; i++) {
  82. var q = kx[i];
  83. if (!eqa.eq(x[q], y[q])) {
  84. return false;
  85. }
  86. }
  87. return true;
  88. });
  89. };
  90. var eqAny = eq$2(function(x, y) {
  91. if (x === y) {
  92. return true;
  93. }
  94. var tx = typeOf$1(x);
  95. var ty = typeOf$1(y);
  96. if (tx !== ty) {
  97. return false;
  98. }
  99. if (isEquatableType(tx)) {
  100. return x === y;
  101. } else if (tx === "array") {
  102. return eqArray(eqAny).eq(x, y);
  103. } else if (tx === "object") {
  104. return eqRecord(eqAny).eq(x, y);
  105. }
  106. return false;
  107. });
  108. var typeOf = function(x) {
  109. var t = typeof x;
  110. if (x === null) {
  111. return "null";
  112. } else if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  113. return "array";
  114. } else if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  115. return "string";
  116. } else {
  117. return t;
  118. }
  119. };
  120. var isType$1 = function(type2) {
  121. return function(value2) {
  122. return typeOf(value2) === type2;
  123. };
  124. };
  125. var isSimpleType = function(type2) {
  126. return function(value2) {
  127. return typeof value2 === type2;
  128. };
  129. };
  130. var eq$1 = function(t) {
  131. return function(a) {
  132. return t === a;
  133. };
  134. };
  135. var isString$1 = isType$1("string");
  136. var isObject = isType$1("object");
  137. var isArray$1 = isType$1("array");
  138. var isNull = eq$1(null);
  139. var isBoolean = isSimpleType("boolean");
  140. var isUndefined = eq$1(void 0);
  141. var isNullable = function(a) {
  142. return a === null || a === void 0;
  143. };
  144. var isNonNullable = function(a) {
  145. return !isNullable(a);
  146. };
  147. var isFunction = isSimpleType("function");
  148. var isNumber = isSimpleType("number");
  149. var noop = function() {
  150. };
  151. var compose = function(fa, fb) {
  152. return function() {
  153. var args = [];
  154. for (var _i = 0; _i < arguments.length; _i++) {
  155. args[_i] = arguments[_i];
  156. }
  157. return fa(fb.apply(null, args));
  158. };
  159. };
  160. var compose1 = function(fbc, fab) {
  161. return function(a) {
  162. return fbc(fab(a));
  163. };
  164. };
  165. var constant = function(value2) {
  166. return function() {
  167. return value2;
  168. };
  169. };
  170. var identity = function(x) {
  171. return x;
  172. };
  173. var tripleEquals = function(a, b) {
  174. return a === b;
  175. };
  176. function curry(fn) {
  177. var initialArgs = [];
  178. for (var _i = 1; _i < arguments.length; _i++) {
  179. initialArgs[_i - 1] = arguments[_i];
  180. }
  181. return function() {
  182. var restArgs = [];
  183. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  184. restArgs[_i2] = arguments[_i2];
  185. }
  186. var all2 = initialArgs.concat(restArgs);
  187. return fn.apply(null, all2);
  188. };
  189. }
  190. var not = function(f) {
  191. return function(t) {
  192. return !f(t);
  193. };
  194. };
  195. var die = function(msg) {
  196. return function() {
  197. throw new Error(msg);
  198. };
  199. };
  200. var apply = function(f) {
  201. return f();
  202. };
  203. var call = function(f) {
  204. f();
  205. };
  206. var never = constant(false);
  207. var always = constant(true);
  208. var none = function() {
  209. return NONE;
  210. };
  211. var NONE = function() {
  212. var call2 = function(thunk) {
  213. return thunk();
  214. };
  215. var id = identity;
  216. var me = {
  217. fold: function(n, _s) {
  218. return n();
  219. },
  220. isSome: never,
  221. isNone: always,
  222. getOr: id,
  223. getOrThunk: call2,
  224. getOrDie: function(msg) {
  225. throw new Error(msg || "error: getOrDie called on none.");
  226. },
  227. getOrNull: constant(null),
  228. getOrUndefined: constant(void 0),
  229. or: id,
  230. orThunk: call2,
  231. map: none,
  232. each: noop,
  233. bind: none,
  234. exists: never,
  235. forall: always,
  236. filter: function() {
  237. return none();
  238. },
  239. toArray: function() {
  240. return [];
  241. },
  242. toString: constant("none()")
  243. };
  244. return me;
  245. }();
  246. var some = function(a) {
  247. var constant_a = constant(a);
  248. var self2 = function() {
  249. return me;
  250. };
  251. var bind2 = function(f) {
  252. return f(a);
  253. };
  254. var me = {
  255. fold: function(n, s) {
  256. return s(a);
  257. },
  258. isSome: always,
  259. isNone: never,
  260. getOr: constant_a,
  261. getOrThunk: constant_a,
  262. getOrDie: constant_a,
  263. getOrNull: constant_a,
  264. getOrUndefined: constant_a,
  265. or: self2,
  266. orThunk: self2,
  267. map: function(f) {
  268. return some(f(a));
  269. },
  270. each: function(f) {
  271. f(a);
  272. },
  273. bind: bind2,
  274. exists: bind2,
  275. forall: bind2,
  276. filter: function(f) {
  277. return f(a) ? me : NONE;
  278. },
  279. toArray: function() {
  280. return [a];
  281. },
  282. toString: function() {
  283. return "some(" + a + ")";
  284. }
  285. };
  286. return me;
  287. };
  288. var from$1 = function(value2) {
  289. return value2 === null || value2 === void 0 ? NONE : some(value2);
  290. };
  291. var Optional = {
  292. some,
  293. none,
  294. from: from$1
  295. };
  296. var nativeSlice = Array.prototype.slice;
  297. var nativeIndexOf = Array.prototype.indexOf;
  298. var nativePush = Array.prototype.push;
  299. var rawIndexOf = function(ts, t) {
  300. return nativeIndexOf.call(ts, t);
  301. };
  302. var indexOf$2 = function(xs, x) {
  303. var r2 = rawIndexOf(xs, x);
  304. return r2 === -1 ? Optional.none() : Optional.some(r2);
  305. };
  306. var contains$3 = function(xs, x) {
  307. return rawIndexOf(xs, x) > -1;
  308. };
  309. var exists = function(xs, pred) {
  310. for (var i = 0, len = xs.length; i < len; i++) {
  311. var x = xs[i];
  312. if (pred(x, i)) {
  313. return true;
  314. }
  315. }
  316. return false;
  317. };
  318. var map$3 = function(xs, f) {
  319. var len = xs.length;
  320. var r2 = new Array(len);
  321. for (var i = 0; i < len; i++) {
  322. var x = xs[i];
  323. r2[i] = f(x, i);
  324. }
  325. return r2;
  326. };
  327. var each$k = function(xs, f) {
  328. for (var i = 0, len = xs.length; i < len; i++) {
  329. var x = xs[i];
  330. f(x, i);
  331. }
  332. };
  333. var eachr = function(xs, f) {
  334. for (var i = xs.length - 1; i >= 0; i--) {
  335. var x = xs[i];
  336. f(x, i);
  337. }
  338. };
  339. var partition = function(xs, pred) {
  340. var pass = [];
  341. var fail = [];
  342. for (var i = 0, len = xs.length; i < len; i++) {
  343. var x = xs[i];
  344. var arr2 = pred(x, i) ? pass : fail;
  345. arr2.push(x);
  346. }
  347. return {
  348. pass,
  349. fail
  350. };
  351. };
  352. var filter$4 = function(xs, pred) {
  353. var r2 = [];
  354. for (var i = 0, len = xs.length; i < len; i++) {
  355. var x = xs[i];
  356. if (pred(x, i)) {
  357. r2.push(x);
  358. }
  359. }
  360. return r2;
  361. };
  362. var foldr = function(xs, f, acc) {
  363. eachr(xs, function(x, i) {
  364. acc = f(acc, x, i);
  365. });
  366. return acc;
  367. };
  368. var foldl = function(xs, f, acc) {
  369. each$k(xs, function(x, i) {
  370. acc = f(acc, x, i);
  371. });
  372. return acc;
  373. };
  374. var findUntil$1 = function(xs, pred, until) {
  375. for (var i = 0, len = xs.length; i < len; i++) {
  376. var x = xs[i];
  377. if (pred(x, i)) {
  378. return Optional.some(x);
  379. } else if (until(x, i)) {
  380. break;
  381. }
  382. }
  383. return Optional.none();
  384. };
  385. var find$3 = function(xs, pred) {
  386. return findUntil$1(xs, pred, never);
  387. };
  388. var findIndex$2 = function(xs, pred) {
  389. for (var i = 0, len = xs.length; i < len; i++) {
  390. var x = xs[i];
  391. if (pred(x, i)) {
  392. return Optional.some(i);
  393. }
  394. }
  395. return Optional.none();
  396. };
  397. var flatten = function(xs) {
  398. var r2 = [];
  399. for (var i = 0, len = xs.length; i < len; ++i) {
  400. if (!isArray$1(xs[i])) {
  401. throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
  402. }
  403. nativePush.apply(r2, xs[i]);
  404. }
  405. return r2;
  406. };
  407. var bind = function(xs, f) {
  408. return flatten(map$3(xs, f));
  409. };
  410. var forall = function(xs, pred) {
  411. for (var i = 0, len = xs.length; i < len; ++i) {
  412. var x = xs[i];
  413. if (pred(x, i) !== true) {
  414. return false;
  415. }
  416. }
  417. return true;
  418. };
  419. var reverse = function(xs) {
  420. var r2 = nativeSlice.call(xs, 0);
  421. r2.reverse();
  422. return r2;
  423. };
  424. var difference = function(a1, a2) {
  425. return filter$4(a1, function(x) {
  426. return !contains$3(a2, x);
  427. });
  428. };
  429. var mapToObject = function(xs, f) {
  430. var r2 = {};
  431. for (var i = 0, len = xs.length; i < len; i++) {
  432. var x = xs[i];
  433. r2[String(x)] = f(x, i);
  434. }
  435. return r2;
  436. };
  437. var sort = function(xs, comparator) {
  438. var copy = nativeSlice.call(xs, 0);
  439. copy.sort(comparator);
  440. return copy;
  441. };
  442. var get$a = function(xs, i) {
  443. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  444. };
  445. var head = function(xs) {
  446. return get$a(xs, 0);
  447. };
  448. var last$2 = function(xs) {
  449. return get$a(xs, xs.length - 1);
  450. };
  451. var from = isFunction(Array.from) ? Array.from : function(x) {
  452. return nativeSlice.call(x);
  453. };
  454. var findMap = function(arr2, f) {
  455. for (var i = 0; i < arr2.length; i++) {
  456. var r2 = f(arr2[i], i);
  457. if (r2.isSome()) {
  458. return r2;
  459. }
  460. }
  461. return Optional.none();
  462. };
  463. var keys = Object.keys;
  464. var hasOwnProperty$1 = Object.hasOwnProperty;
  465. var each$j = function(obj, f) {
  466. var props = keys(obj);
  467. for (var k = 0, len = props.length; k < len; k++) {
  468. var i = props[k];
  469. var x = obj[i];
  470. f(x, i);
  471. }
  472. };
  473. var map$2 = function(obj, f) {
  474. return tupleMap(obj, function(x, i) {
  475. return {
  476. k: i,
  477. v: f(x, i)
  478. };
  479. });
  480. };
  481. var tupleMap = function(obj, f) {
  482. var r2 = {};
  483. each$j(obj, function(x, i) {
  484. var tuple = f(x, i);
  485. r2[tuple.k] = tuple.v;
  486. });
  487. return r2;
  488. };
  489. var objAcc = function(r2) {
  490. return function(x, i) {
  491. r2[i] = x;
  492. };
  493. };
  494. var internalFilter = function(obj, pred, onTrue, onFalse) {
  495. var r2 = {};
  496. each$j(obj, function(x, i) {
  497. (pred(x, i) ? onTrue : onFalse)(x, i);
  498. });
  499. return r2;
  500. };
  501. var bifilter = function(obj, pred) {
  502. var t = {};
  503. var f = {};
  504. internalFilter(obj, pred, objAcc(t), objAcc(f));
  505. return {
  506. t,
  507. f
  508. };
  509. };
  510. var filter$3 = function(obj, pred) {
  511. var t = {};
  512. internalFilter(obj, pred, objAcc(t), noop);
  513. return t;
  514. };
  515. var mapToArray = function(obj, f) {
  516. var r2 = [];
  517. each$j(obj, function(value2, name2) {
  518. r2.push(f(value2, name2));
  519. });
  520. return r2;
  521. };
  522. var values = function(obj) {
  523. return mapToArray(obj, identity);
  524. };
  525. var get$9 = function(obj, key) {
  526. return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none();
  527. };
  528. var has$2 = function(obj, key) {
  529. return hasOwnProperty$1.call(obj, key);
  530. };
  531. var hasNonNullableKey = function(obj, key) {
  532. return has$2(obj, key) && obj[key] !== void 0 && obj[key] !== null;
  533. };
  534. var equal$1 = function(a1, a2, eq2) {
  535. if (eq2 === void 0) {
  536. eq2 = eqAny;
  537. }
  538. return eqRecord(eq2).eq(a1, a2);
  539. };
  540. var isArray = Array.isArray;
  541. var toArray$1 = function(obj) {
  542. if (!isArray(obj)) {
  543. var array = [];
  544. for (var i = 0, l = obj.length; i < l; i++) {
  545. array[i] = obj[i];
  546. }
  547. return array;
  548. } else {
  549. return obj;
  550. }
  551. };
  552. var each$i = function(o, cb, s) {
  553. var n, l;
  554. if (!o) {
  555. return false;
  556. }
  557. s = s || o;
  558. if (o.length !== void 0) {
  559. for (n = 0, l = o.length; n < l; n++) {
  560. if (cb.call(s, o[n], n, o) === false) {
  561. return false;
  562. }
  563. }
  564. } else {
  565. for (n in o) {
  566. if (has$2(o, n)) {
  567. if (cb.call(s, o[n], n, o) === false) {
  568. return false;
  569. }
  570. }
  571. }
  572. }
  573. return true;
  574. };
  575. var map$1 = function(array, callback) {
  576. var out = [];
  577. each$i(array, function(item, index) {
  578. out.push(callback(item, index, array));
  579. });
  580. return out;
  581. };
  582. var filter$2 = function(a, f) {
  583. var o = [];
  584. each$i(a, function(v, index) {
  585. if (!f || f(v, index, a)) {
  586. o.push(v);
  587. }
  588. });
  589. return o;
  590. };
  591. var indexOf$1 = function(a, v) {
  592. if (a) {
  593. for (var i = 0, l = a.length; i < l; i++) {
  594. if (a[i] === v) {
  595. return i;
  596. }
  597. }
  598. }
  599. return -1;
  600. };
  601. var reduce = function(collection, iteratee, accumulator, thisArg) {
  602. var acc = isUndefined(accumulator) ? collection[0] : accumulator;
  603. for (var i = 0; i < collection.length; i++) {
  604. acc = iteratee.call(thisArg, acc, collection[i], i);
  605. }
  606. return acc;
  607. };
  608. var findIndex$1 = function(array, predicate, thisArg) {
  609. var i, l;
  610. for (i = 0, l = array.length; i < l; i++) {
  611. if (predicate.call(thisArg, array[i], i, array)) {
  612. return i;
  613. }
  614. }
  615. return -1;
  616. };
  617. var last$1 = function(collection) {
  618. return collection[collection.length - 1];
  619. };
  620. var __assign = function() {
  621. __assign = Object.assign || function __assign2(t) {
  622. for (var s, i = 1, n = arguments.length; i < n; i++) {
  623. s = arguments[i];
  624. for (var p in s)
  625. if (Object.prototype.hasOwnProperty.call(s, p))
  626. t[p] = s[p];
  627. }
  628. return t;
  629. };
  630. return __assign.apply(this, arguments);
  631. };
  632. function __rest(s, e) {
  633. var t = {};
  634. for (var p in s)
  635. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  636. t[p] = s[p];
  637. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  638. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  639. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  640. t[p[i]] = s[p[i]];
  641. }
  642. return t;
  643. }
  644. function __spreadArray(to2, from2, pack) {
  645. if (pack || arguments.length === 2)
  646. for (var i = 0, l = from2.length, ar; i < l; i++) {
  647. if (ar || !(i in from2)) {
  648. if (!ar)
  649. ar = Array.prototype.slice.call(from2, 0, i);
  650. ar[i] = from2[i];
  651. }
  652. }
  653. return to2.concat(ar || Array.prototype.slice.call(from2));
  654. }
  655. var cached = function(f) {
  656. var called = false;
  657. var r2;
  658. return function() {
  659. var args = [];
  660. for (var _i = 0; _i < arguments.length; _i++) {
  661. args[_i] = arguments[_i];
  662. }
  663. if (!called) {
  664. called = true;
  665. r2 = f.apply(null, args);
  666. }
  667. return r2;
  668. };
  669. };
  670. var DeviceType = function(os2, browser2, userAgent2, mediaMatch2) {
  671. var isiPad = os2.isiOS() && /ipad/i.test(userAgent2) === true;
  672. var isiPhone = os2.isiOS() && !isiPad;
  673. var isMobile = os2.isiOS() || os2.isAndroid();
  674. var isTouch2 = isMobile || mediaMatch2("(pointer:coarse)");
  675. var isTablet2 = isiPad || !isiPhone && isMobile && mediaMatch2("(min-device-width:768px)");
  676. var isPhone2 = isiPhone || isMobile && !isTablet2;
  677. var iOSwebview = browser2.isSafari() && os2.isiOS() && /safari/i.test(userAgent2) === false;
  678. var isDesktop = !isPhone2 && !isTablet2 && !iOSwebview;
  679. return {
  680. isiPad: constant(isiPad),
  681. isiPhone: constant(isiPhone),
  682. isTablet: constant(isTablet2),
  683. isPhone: constant(isPhone2),
  684. isTouch: constant(isTouch2),
  685. isAndroid: os2.isAndroid,
  686. isiOS: os2.isiOS,
  687. isWebView: constant(iOSwebview),
  688. isDesktop: constant(isDesktop)
  689. };
  690. };
  691. var firstMatch = function(regexes, s) {
  692. for (var i = 0; i < regexes.length; i++) {
  693. var x = regexes[i];
  694. if (x.test(s)) {
  695. return x;
  696. }
  697. }
  698. return void 0;
  699. };
  700. var find$2 = function(regexes, agent) {
  701. var r2 = firstMatch(regexes, agent);
  702. if (!r2) {
  703. return {
  704. major: 0,
  705. minor: 0
  706. };
  707. }
  708. var group = function(i) {
  709. return Number(agent.replace(r2, "$" + i));
  710. };
  711. return nu$4(group(1), group(2));
  712. };
  713. var detect$3 = function(versionRegexes, agent) {
  714. var cleanedAgent = String(agent).toLowerCase();
  715. if (versionRegexes.length === 0) {
  716. return unknown$2();
  717. }
  718. return find$2(versionRegexes, cleanedAgent);
  719. };
  720. var unknown$2 = function() {
  721. return nu$4(0, 0);
  722. };
  723. var nu$4 = function(major, minor) {
  724. return {
  725. major,
  726. minor
  727. };
  728. };
  729. var Version = {
  730. nu: nu$4,
  731. detect: detect$3,
  732. unknown: unknown$2
  733. };
  734. var detectBrowser$1 = function(browsers2, userAgentData) {
  735. return findMap(userAgentData.brands, function(uaBrand) {
  736. var lcBrand = uaBrand.brand.toLowerCase();
  737. return find$3(browsers2, function(browser2) {
  738. var _a;
  739. return lcBrand === ((_a = browser2.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase());
  740. }).map(function(info) {
  741. return {
  742. current: info.name,
  743. version: Version.nu(parseInt(uaBrand.version, 10), 0)
  744. };
  745. });
  746. });
  747. };
  748. var detect$2 = function(candidates, userAgent2) {
  749. var agent = String(userAgent2).toLowerCase();
  750. return find$3(candidates, function(candidate) {
  751. return candidate.search(agent);
  752. });
  753. };
  754. var detectBrowser = function(browsers2, userAgent2) {
  755. return detect$2(browsers2, userAgent2).map(function(browser2) {
  756. var version = Version.detect(browser2.versionRegexes, userAgent2);
  757. return {
  758. current: browser2.name,
  759. version
  760. };
  761. });
  762. };
  763. var detectOs = function(oses2, userAgent2) {
  764. return detect$2(oses2, userAgent2).map(function(os2) {
  765. var version = Version.detect(os2.versionRegexes, userAgent2);
  766. return {
  767. current: os2.name,
  768. version
  769. };
  770. });
  771. };
  772. var removeFromStart = function(str, numChars) {
  773. return str.substring(numChars);
  774. };
  775. var checkRange = function(str, substr, start2) {
  776. return substr === "" || str.length >= substr.length && str.substr(start2, start2 + substr.length) === substr;
  777. };
  778. var removeLeading = function(str, prefix) {
  779. return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;
  780. };
  781. var contains$2 = function(str, substr) {
  782. return str.indexOf(substr) !== -1;
  783. };
  784. var startsWith = function(str, prefix) {
  785. return checkRange(str, prefix, 0);
  786. };
  787. var blank = function(r2) {
  788. return function(s) {
  789. return s.replace(r2, "");
  790. };
  791. };
  792. var trim$4 = blank(/^\s+|\s+$/g);
  793. var lTrim = blank(/^\s+/g);
  794. var rTrim = blank(/\s+$/g);
  795. var isNotEmpty = function(s) {
  796. return s.length > 0;
  797. };
  798. var isEmpty$3 = function(s) {
  799. return !isNotEmpty(s);
  800. };
  801. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  802. var checkContains = function(target) {
  803. return function(uastring) {
  804. return contains$2(uastring, target);
  805. };
  806. };
  807. var browsers = [
  808. {
  809. name: "Edge",
  810. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  811. search: function(uastring) {
  812. return contains$2(uastring, "edge/") && contains$2(uastring, "chrome") && contains$2(uastring, "safari") && contains$2(uastring, "applewebkit");
  813. }
  814. },
  815. {
  816. name: "Chrome",
  817. brand: "Chromium",
  818. versionRegexes: [
  819. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  820. normalVersionRegex
  821. ],
  822. search: function(uastring) {
  823. return contains$2(uastring, "chrome") && !contains$2(uastring, "chromeframe");
  824. }
  825. },
  826. {
  827. name: "IE",
  828. versionRegexes: [
  829. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  830. /.*?rv:([0-9]+)\.([0-9]+).*/
  831. ],
  832. search: function(uastring) {
  833. return contains$2(uastring, "msie") || contains$2(uastring, "trident");
  834. }
  835. },
  836. {
  837. name: "Opera",
  838. versionRegexes: [
  839. normalVersionRegex,
  840. /.*?opera\/([0-9]+)\.([0-9]+).*/
  841. ],
  842. search: checkContains("opera")
  843. },
  844. {
  845. name: "Firefox",
  846. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  847. search: checkContains("firefox")
  848. },
  849. {
  850. name: "Safari",
  851. versionRegexes: [
  852. normalVersionRegex,
  853. /.*?cpu os ([0-9]+)_([0-9]+).*/
  854. ],
  855. search: function(uastring) {
  856. return (contains$2(uastring, "safari") || contains$2(uastring, "mobile/")) && contains$2(uastring, "applewebkit");
  857. }
  858. }
  859. ];
  860. var oses = [
  861. {
  862. name: "Windows",
  863. search: checkContains("win"),
  864. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  865. },
  866. {
  867. name: "iOS",
  868. search: function(uastring) {
  869. return contains$2(uastring, "iphone") || contains$2(uastring, "ipad");
  870. },
  871. versionRegexes: [
  872. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  873. /.*cpu os ([0-9]+)_([0-9]+).*/,
  874. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  875. ]
  876. },
  877. {
  878. name: "Android",
  879. search: checkContains("android"),
  880. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  881. },
  882. {
  883. name: "OSX",
  884. search: checkContains("mac os x"),
  885. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  886. },
  887. {
  888. name: "Linux",
  889. search: checkContains("linux"),
  890. versionRegexes: []
  891. },
  892. {
  893. name: "Solaris",
  894. search: checkContains("sunos"),
  895. versionRegexes: []
  896. },
  897. {
  898. name: "FreeBSD",
  899. search: checkContains("freebsd"),
  900. versionRegexes: []
  901. },
  902. {
  903. name: "ChromeOS",
  904. search: checkContains("cros"),
  905. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  906. }
  907. ];
  908. var PlatformInfo = {
  909. browsers: constant(browsers),
  910. oses: constant(oses)
  911. };
  912. var edge = "Edge";
  913. var chrome = "Chrome";
  914. var ie$1 = "IE";
  915. var opera = "Opera";
  916. var firefox = "Firefox";
  917. var safari = "Safari";
  918. var unknown$1 = function() {
  919. return nu$3({
  920. current: void 0,
  921. version: Version.unknown()
  922. });
  923. };
  924. var nu$3 = function(info) {
  925. var current = info.current;
  926. var version = info.version;
  927. var isBrowser = function(name2) {
  928. return function() {
  929. return current === name2;
  930. };
  931. };
  932. return {
  933. current,
  934. version,
  935. isEdge: isBrowser(edge),
  936. isChrome: isBrowser(chrome),
  937. isIE: isBrowser(ie$1),
  938. isOpera: isBrowser(opera),
  939. isFirefox: isBrowser(firefox),
  940. isSafari: isBrowser(safari)
  941. };
  942. };
  943. var Browser = {
  944. unknown: unknown$1,
  945. nu: nu$3,
  946. edge: constant(edge),
  947. chrome: constant(chrome),
  948. ie: constant(ie$1),
  949. opera: constant(opera),
  950. firefox: constant(firefox),
  951. safari: constant(safari)
  952. };
  953. var windows = "Windows";
  954. var ios = "iOS";
  955. var android = "Android";
  956. var linux = "Linux";
  957. var osx = "OSX";
  958. var solaris = "Solaris";
  959. var freebsd = "FreeBSD";
  960. var chromeos = "ChromeOS";
  961. var unknown = function() {
  962. return nu$2({
  963. current: void 0,
  964. version: Version.unknown()
  965. });
  966. };
  967. var nu$2 = function(info) {
  968. var current = info.current;
  969. var version = info.version;
  970. var isOS = function(name2) {
  971. return function() {
  972. return current === name2;
  973. };
  974. };
  975. return {
  976. current,
  977. version,
  978. isWindows: isOS(windows),
  979. isiOS: isOS(ios),
  980. isAndroid: isOS(android),
  981. isOSX: isOS(osx),
  982. isLinux: isOS(linux),
  983. isSolaris: isOS(solaris),
  984. isFreeBSD: isOS(freebsd),
  985. isChromeOS: isOS(chromeos)
  986. };
  987. };
  988. var OperatingSystem = {
  989. unknown,
  990. nu: nu$2,
  991. windows: constant(windows),
  992. ios: constant(ios),
  993. android: constant(android),
  994. linux: constant(linux),
  995. osx: constant(osx),
  996. solaris: constant(solaris),
  997. freebsd: constant(freebsd),
  998. chromeos: constant(chromeos)
  999. };
  1000. var detect$1 = function(userAgent2, userAgentDataOpt, mediaMatch2) {
  1001. var browsers2 = PlatformInfo.browsers();
  1002. var oses2 = PlatformInfo.oses();
  1003. var browser2 = userAgentDataOpt.bind(function(userAgentData) {
  1004. return detectBrowser$1(browsers2, userAgentData);
  1005. }).orThunk(function() {
  1006. return detectBrowser(browsers2, userAgent2);
  1007. }).fold(Browser.unknown, Browser.nu);
  1008. var os2 = detectOs(oses2, userAgent2).fold(OperatingSystem.unknown, OperatingSystem.nu);
  1009. var deviceType2 = DeviceType(os2, browser2, userAgent2, mediaMatch2);
  1010. return {
  1011. browser: browser2,
  1012. os: os2,
  1013. deviceType: deviceType2
  1014. };
  1015. };
  1016. var PlatformDetection = { detect: detect$1 };
  1017. var mediaMatch = function(query) {
  1018. return window.matchMedia(query).matches;
  1019. };
  1020. var platform$2 = cached(function() {
  1021. return PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch);
  1022. });
  1023. var detect = function() {
  1024. return platform$2();
  1025. };
  1026. var userAgent = navigator.userAgent;
  1027. var platform$1 = detect();
  1028. var browser$4 = platform$1.browser;
  1029. var os = platform$1.os;
  1030. var deviceType = platform$1.deviceType;
  1031. var webkit = /WebKit/.test(userAgent) && !browser$4.isEdge();
  1032. var fileApi = "FormData" in window && "FileReader" in window && "URL" in window && !!URL.createObjectURL;
  1033. var windowsPhone = userAgent.indexOf("Windows Phone") !== -1;
  1034. var Env = {
  1035. opera: browser$4.isOpera(),
  1036. webkit,
  1037. ie: browser$4.isIE() || browser$4.isEdge() ? browser$4.version.major : false,
  1038. gecko: browser$4.isFirefox(),
  1039. mac: os.isOSX() || os.isiOS(),
  1040. iOS: deviceType.isiPad() || deviceType.isiPhone(),
  1041. android: os.isAndroid(),
  1042. contentEditable: true,
  1043. transparentSrc: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
  1044. caretAfter: true,
  1045. range: window.getSelection && "Range" in window,
  1046. documentMode: browser$4.isIE() ? document.documentMode || 7 : 10,
  1047. fileApi,
  1048. ceFalse: true,
  1049. cacheSuffix: null,
  1050. container: null,
  1051. experimentalShadowDom: false,
  1052. canHaveCSP: !browser$4.isIE(),
  1053. desktop: deviceType.isDesktop(),
  1054. windowsPhone,
  1055. browser: {
  1056. current: browser$4.current,
  1057. version: browser$4.version,
  1058. isChrome: browser$4.isChrome,
  1059. isEdge: browser$4.isEdge,
  1060. isFirefox: browser$4.isFirefox,
  1061. isIE: browser$4.isIE,
  1062. isOpera: browser$4.isOpera,
  1063. isSafari: browser$4.isSafari
  1064. },
  1065. os: {
  1066. current: os.current,
  1067. version: os.version,
  1068. isAndroid: os.isAndroid,
  1069. isChromeOS: os.isChromeOS,
  1070. isFreeBSD: os.isFreeBSD,
  1071. isiOS: os.isiOS,
  1072. isLinux: os.isLinux,
  1073. isOSX: os.isOSX,
  1074. isSolaris: os.isSolaris,
  1075. isWindows: os.isWindows
  1076. },
  1077. deviceType: {
  1078. isDesktop: deviceType.isDesktop,
  1079. isiPad: deviceType.isiPad,
  1080. isiPhone: deviceType.isiPhone,
  1081. isPhone: deviceType.isPhone,
  1082. isTablet: deviceType.isTablet,
  1083. isTouch: deviceType.isTouch,
  1084. isWebView: deviceType.isWebView
  1085. }
  1086. };
  1087. var whiteSpaceRegExp$2 = /^\s*|\s*$/g;
  1088. var trim$3 = function(str) {
  1089. return str === null || str === void 0 ? "" : ("" + str).replace(whiteSpaceRegExp$2, "");
  1090. };
  1091. var is$3 = function(obj, type2) {
  1092. if (!type2) {
  1093. return obj !== void 0;
  1094. }
  1095. if (type2 === "array" && isArray(obj)) {
  1096. return true;
  1097. }
  1098. return typeof obj === type2;
  1099. };
  1100. var makeMap$4 = function(items, delim, map2) {
  1101. var i;
  1102. items = items || [];
  1103. delim = delim || ",";
  1104. if (typeof items === "string") {
  1105. items = items.split(delim);
  1106. }
  1107. map2 = map2 || {};
  1108. i = items.length;
  1109. while (i--) {
  1110. map2[items[i]] = {};
  1111. }
  1112. return map2;
  1113. };
  1114. var hasOwnProperty = has$2;
  1115. var create$9 = function(s, p, root) {
  1116. var self2 = this;
  1117. var sp, scn, c, de = 0;
  1118. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  1119. var cn = s[3].match(/(^|\.)(\w+)$/i)[2];
  1120. var ns = self2.createNS(s[3].replace(/\.\w+$/, ""), root);
  1121. if (ns[cn]) {
  1122. return;
  1123. }
  1124. if (s[2] === "static") {
  1125. ns[cn] = p;
  1126. if (this.onCreate) {
  1127. this.onCreate(s[2], s[3], ns[cn]);
  1128. }
  1129. return;
  1130. }
  1131. if (!p[cn]) {
  1132. p[cn] = function() {
  1133. };
  1134. de = 1;
  1135. }
  1136. ns[cn] = p[cn];
  1137. self2.extend(ns[cn].prototype, p);
  1138. if (s[5]) {
  1139. sp = self2.resolve(s[5]).prototype;
  1140. scn = s[5].match(/\.(\w+)$/i)[1];
  1141. c = ns[cn];
  1142. if (de) {
  1143. ns[cn] = function() {
  1144. return sp[scn].apply(this, arguments);
  1145. };
  1146. } else {
  1147. ns[cn] = function() {
  1148. this.parent = sp[scn];
  1149. return c.apply(this, arguments);
  1150. };
  1151. }
  1152. ns[cn].prototype[cn] = ns[cn];
  1153. self2.each(sp, function(f, n) {
  1154. ns[cn].prototype[n] = sp[n];
  1155. });
  1156. self2.each(p, function(f, n) {
  1157. if (sp[n]) {
  1158. ns[cn].prototype[n] = function() {
  1159. this.parent = sp[n];
  1160. return f.apply(this, arguments);
  1161. };
  1162. } else {
  1163. if (n !== cn) {
  1164. ns[cn].prototype[n] = f;
  1165. }
  1166. }
  1167. });
  1168. }
  1169. self2.each(p.static, function(f, n) {
  1170. ns[cn][n] = f;
  1171. });
  1172. };
  1173. var extend$6 = function(obj) {
  1174. var exts = [];
  1175. for (var _i = 1; _i < arguments.length; _i++) {
  1176. exts[_i - 1] = arguments[_i];
  1177. }
  1178. for (var i = 0; i < exts.length; i++) {
  1179. var ext = exts[i];
  1180. for (var name_1 in ext) {
  1181. if (has$2(ext, name_1)) {
  1182. var value2 = ext[name_1];
  1183. if (value2 !== void 0) {
  1184. obj[name_1] = value2;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. return obj;
  1190. };
  1191. var walk$3 = function(o, f, n, s) {
  1192. s = s || this;
  1193. if (o) {
  1194. if (n) {
  1195. o = o[n];
  1196. }
  1197. each$i(o, function(o2, i) {
  1198. if (f.call(s, o2, i, n) === false) {
  1199. return false;
  1200. }
  1201. walk$3(o2, f, n, s);
  1202. });
  1203. }
  1204. };
  1205. var createNS = function(n, o) {
  1206. var i, v;
  1207. o = o || window;
  1208. n = n.split(".");
  1209. for (i = 0; i < n.length; i++) {
  1210. v = n[i];
  1211. if (!o[v]) {
  1212. o[v] = {};
  1213. }
  1214. o = o[v];
  1215. }
  1216. return o;
  1217. };
  1218. var resolve$3 = function(n, o) {
  1219. var i, l;
  1220. o = o || window;
  1221. n = n.split(".");
  1222. for (i = 0, l = n.length; i < l; i++) {
  1223. o = o[n[i]];
  1224. if (!o) {
  1225. break;
  1226. }
  1227. }
  1228. return o;
  1229. };
  1230. var explode$4 = function(s, d) {
  1231. if (!s || is$3(s, "array")) {
  1232. return s;
  1233. }
  1234. return map$1(s.split(d || ","), trim$3);
  1235. };
  1236. var _addCacheSuffix = function(url) {
  1237. var cacheSuffix = Env.cacheSuffix;
  1238. if (cacheSuffix) {
  1239. url += (url.indexOf("?") === -1 ? "?" : "&") + cacheSuffix;
  1240. }
  1241. return url;
  1242. };
  1243. var Tools = {
  1244. trim: trim$3,
  1245. isArray,
  1246. is: is$3,
  1247. toArray: toArray$1,
  1248. makeMap: makeMap$4,
  1249. each: each$i,
  1250. map: map$1,
  1251. grep: filter$2,
  1252. inArray: indexOf$1,
  1253. hasOwn: hasOwnProperty,
  1254. extend: extend$6,
  1255. create: create$9,
  1256. walk: walk$3,
  1257. createNS,
  1258. resolve: resolve$3,
  1259. explode: explode$4,
  1260. _addCacheSuffix
  1261. };
  1262. var fromHtml$1 = function(html, scope) {
  1263. var doc2 = scope || document;
  1264. var div = doc2.createElement("div");
  1265. div.innerHTML = html;
  1266. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  1267. console.error("HTML does not have a single root node", html);
  1268. throw new Error("HTML must have a single root node");
  1269. }
  1270. return fromDom$2(div.childNodes[0]);
  1271. };
  1272. var fromTag = function(tag, scope) {
  1273. var doc2 = scope || document;
  1274. var node = doc2.createElement(tag);
  1275. return fromDom$2(node);
  1276. };
  1277. var fromText = function(text, scope) {
  1278. var doc2 = scope || document;
  1279. var node = doc2.createTextNode(text);
  1280. return fromDom$2(node);
  1281. };
  1282. var fromDom$2 = function(node) {
  1283. if (node === null || node === void 0) {
  1284. throw new Error("Node cannot be null or undefined");
  1285. }
  1286. return { dom: node };
  1287. };
  1288. var fromPoint$1 = function(docElm, x, y) {
  1289. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$2);
  1290. };
  1291. var SugarElement = {
  1292. fromHtml: fromHtml$1,
  1293. fromTag,
  1294. fromText,
  1295. fromDom: fromDom$2,
  1296. fromPoint: fromPoint$1
  1297. };
  1298. var toArray = function(target, f) {
  1299. var r2 = [];
  1300. var recurse = function(e) {
  1301. r2.push(e);
  1302. return f(e);
  1303. };
  1304. var cur = f(target);
  1305. do {
  1306. cur = cur.bind(recurse);
  1307. } while (cur.isSome());
  1308. return r2;
  1309. };
  1310. var compareDocumentPosition = function(a, b, match2) {
  1311. return (a.compareDocumentPosition(b) & match2) !== 0;
  1312. };
  1313. var documentPositionContainedBy = function(a, b) {
  1314. return compareDocumentPosition(a, b, Node.DOCUMENT_POSITION_CONTAINED_BY);
  1315. };
  1316. var COMMENT = 8;
  1317. var DOCUMENT = 9;
  1318. var DOCUMENT_FRAGMENT = 11;
  1319. var ELEMENT = 1;
  1320. var TEXT = 3;
  1321. var is$2 = function(element, selector) {
  1322. var dom2 = element.dom;
  1323. if (dom2.nodeType !== ELEMENT) {
  1324. return false;
  1325. } else {
  1326. var elem = dom2;
  1327. if (elem.matches !== void 0) {
  1328. return elem.matches(selector);
  1329. } else if (elem.msMatchesSelector !== void 0) {
  1330. return elem.msMatchesSelector(selector);
  1331. } else if (elem.webkitMatchesSelector !== void 0) {
  1332. return elem.webkitMatchesSelector(selector);
  1333. } else if (elem.mozMatchesSelector !== void 0) {
  1334. return elem.mozMatchesSelector(selector);
  1335. } else {
  1336. throw new Error("Browser lacks native selectors");
  1337. }
  1338. }
  1339. };
  1340. var bypassSelector = function(dom2) {
  1341. return dom2.nodeType !== ELEMENT && dom2.nodeType !== DOCUMENT && dom2.nodeType !== DOCUMENT_FRAGMENT || dom2.childElementCount === 0;
  1342. };
  1343. var all = function(selector, scope) {
  1344. var base = scope === void 0 ? document : scope.dom;
  1345. return bypassSelector(base) ? [] : map$3(base.querySelectorAll(selector), SugarElement.fromDom);
  1346. };
  1347. var one = function(selector, scope) {
  1348. var base = scope === void 0 ? document : scope.dom;
  1349. return bypassSelector(base) ? Optional.none() : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom);
  1350. };
  1351. var eq = function(e1, e2) {
  1352. return e1.dom === e2.dom;
  1353. };
  1354. var regularContains = function(e1, e2) {
  1355. var d1 = e1.dom;
  1356. var d2 = e2.dom;
  1357. return d1 === d2 ? false : d1.contains(d2);
  1358. };
  1359. var ieContains = function(e1, e2) {
  1360. return documentPositionContainedBy(e1.dom, e2.dom);
  1361. };
  1362. var contains$1 = function(e1, e2) {
  1363. return detect().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
  1364. };
  1365. typeof window !== "undefined" ? window : Function("return this;")();
  1366. var name = function(element) {
  1367. var r2 = element.dom.nodeName;
  1368. return r2.toLowerCase();
  1369. };
  1370. var type = function(element) {
  1371. return element.dom.nodeType;
  1372. };
  1373. var isType = function(t) {
  1374. return function(element) {
  1375. return type(element) === t;
  1376. };
  1377. };
  1378. var isComment$1 = function(element) {
  1379. return type(element) === COMMENT || name(element) === "#comment";
  1380. };
  1381. var isElement$6 = isType(ELEMENT);
  1382. var isText$8 = isType(TEXT);
  1383. var isDocument$2 = isType(DOCUMENT);
  1384. var isDocumentFragment$1 = isType(DOCUMENT_FRAGMENT);
  1385. var isTag = function(tag) {
  1386. return function(e) {
  1387. return isElement$6(e) && name(e) === tag;
  1388. };
  1389. };
  1390. var owner$1 = function(element) {
  1391. return SugarElement.fromDom(element.dom.ownerDocument);
  1392. };
  1393. var documentOrOwner = function(dos) {
  1394. return isDocument$2(dos) ? dos : owner$1(dos);
  1395. };
  1396. var documentElement = function(element) {
  1397. return SugarElement.fromDom(documentOrOwner(element).dom.documentElement);
  1398. };
  1399. var defaultView = function(element) {
  1400. return SugarElement.fromDom(documentOrOwner(element).dom.defaultView);
  1401. };
  1402. var parent = function(element) {
  1403. return Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
  1404. };
  1405. var parents$1 = function(element, isRoot) {
  1406. var stop2 = isFunction(isRoot) ? isRoot : never;
  1407. var dom2 = element.dom;
  1408. var ret = [];
  1409. while (dom2.parentNode !== null && dom2.parentNode !== void 0) {
  1410. var rawParent = dom2.parentNode;
  1411. var p = SugarElement.fromDom(rawParent);
  1412. ret.push(p);
  1413. if (stop2(p) === true) {
  1414. break;
  1415. } else {
  1416. dom2 = rawParent;
  1417. }
  1418. }
  1419. return ret;
  1420. };
  1421. var siblings = function(element) {
  1422. var filterSelf = function(elements) {
  1423. return filter$4(elements, function(x) {
  1424. return !eq(element, x);
  1425. });
  1426. };
  1427. return parent(element).map(children).map(filterSelf).getOr([]);
  1428. };
  1429. var prevSibling = function(element) {
  1430. return Optional.from(element.dom.previousSibling).map(SugarElement.fromDom);
  1431. };
  1432. var nextSibling = function(element) {
  1433. return Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
  1434. };
  1435. var prevSiblings = function(element) {
  1436. return reverse(toArray(element, prevSibling));
  1437. };
  1438. var nextSiblings = function(element) {
  1439. return toArray(element, nextSibling);
  1440. };
  1441. var children = function(element) {
  1442. return map$3(element.dom.childNodes, SugarElement.fromDom);
  1443. };
  1444. var child$1 = function(element, index) {
  1445. var cs = element.dom.childNodes;
  1446. return Optional.from(cs[index]).map(SugarElement.fromDom);
  1447. };
  1448. var firstChild = function(element) {
  1449. return child$1(element, 0);
  1450. };
  1451. var lastChild = function(element) {
  1452. return child$1(element, element.dom.childNodes.length - 1);
  1453. };
  1454. var childNodesCount = function(element) {
  1455. return element.dom.childNodes.length;
  1456. };
  1457. var getHead = function(doc2) {
  1458. var b = doc2.dom.head;
  1459. if (b === null || b === void 0) {
  1460. throw new Error("Head is not available yet");
  1461. }
  1462. return SugarElement.fromDom(b);
  1463. };
  1464. var isShadowRoot = function(dos) {
  1465. return isDocumentFragment$1(dos) && isNonNullable(dos.dom.host);
  1466. };
  1467. var supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
  1468. var isSupported$1 = constant(supported);
  1469. var getRootNode = supported ? function(e) {
  1470. return SugarElement.fromDom(e.dom.getRootNode());
  1471. } : documentOrOwner;
  1472. var getStyleContainer = function(dos) {
  1473. return isShadowRoot(dos) ? dos : getHead(documentOrOwner(dos));
  1474. };
  1475. var getShadowRoot = function(e) {
  1476. var r2 = getRootNode(e);
  1477. return isShadowRoot(r2) ? Optional.some(r2) : Optional.none();
  1478. };
  1479. var getShadowHost = function(e) {
  1480. return SugarElement.fromDom(e.dom.host);
  1481. };
  1482. var getOriginalEventTarget = function(event) {
  1483. if (isSupported$1() && isNonNullable(event.target)) {
  1484. var el = SugarElement.fromDom(event.target);
  1485. if (isElement$6(el) && isOpenShadowHost(el)) {
  1486. if (event.composed && event.composedPath) {
  1487. var composedPath = event.composedPath();
  1488. if (composedPath) {
  1489. return head(composedPath);
  1490. }
  1491. }
  1492. }
  1493. }
  1494. return Optional.from(event.target);
  1495. };
  1496. var isOpenShadowHost = function(element) {
  1497. return isNonNullable(element.dom.shadowRoot);
  1498. };
  1499. var before$4 = function(marker, element) {
  1500. var parent$1 = parent(marker);
  1501. parent$1.each(function(v) {
  1502. v.dom.insertBefore(element.dom, marker.dom);
  1503. });
  1504. };
  1505. var after$3 = function(marker, element) {
  1506. var sibling2 = nextSibling(marker);
  1507. sibling2.fold(function() {
  1508. var parent$1 = parent(marker);
  1509. parent$1.each(function(v) {
  1510. append$1(v, element);
  1511. });
  1512. }, function(v) {
  1513. before$4(v, element);
  1514. });
  1515. };
  1516. var prepend = function(parent2, element) {
  1517. var firstChild$1 = firstChild(parent2);
  1518. firstChild$1.fold(function() {
  1519. append$1(parent2, element);
  1520. }, function(v) {
  1521. parent2.dom.insertBefore(element.dom, v.dom);
  1522. });
  1523. };
  1524. var append$1 = function(parent2, element) {
  1525. parent2.dom.appendChild(element.dom);
  1526. };
  1527. var wrap$3 = function(element, wrapper) {
  1528. before$4(element, wrapper);
  1529. append$1(wrapper, element);
  1530. };
  1531. var before$3 = function(marker, elements) {
  1532. each$k(elements, function(x) {
  1533. before$4(marker, x);
  1534. });
  1535. };
  1536. var append = function(parent2, elements) {
  1537. each$k(elements, function(x) {
  1538. append$1(parent2, x);
  1539. });
  1540. };
  1541. var empty = function(element) {
  1542. element.dom.textContent = "";
  1543. each$k(children(element), function(rogue) {
  1544. remove$7(rogue);
  1545. });
  1546. };
  1547. var remove$7 = function(element) {
  1548. var dom2 = element.dom;
  1549. if (dom2.parentNode !== null) {
  1550. dom2.parentNode.removeChild(dom2);
  1551. }
  1552. };
  1553. var unwrap = function(wrapper) {
  1554. var children$1 = children(wrapper);
  1555. if (children$1.length > 0) {
  1556. before$3(wrapper, children$1);
  1557. }
  1558. remove$7(wrapper);
  1559. };
  1560. var inBody = function(element) {
  1561. var dom2 = isText$8(element) ? element.dom.parentNode : element.dom;
  1562. if (dom2 === void 0 || dom2 === null || dom2.ownerDocument === null) {
  1563. return false;
  1564. }
  1565. var doc2 = dom2.ownerDocument;
  1566. return getShadowRoot(SugarElement.fromDom(dom2)).fold(function() {
  1567. return doc2.body.contains(dom2);
  1568. }, compose1(inBody, getShadowHost));
  1569. };
  1570. var r = function(left, top) {
  1571. var translate2 = function(x, y) {
  1572. return r(left + x, top + y);
  1573. };
  1574. return {
  1575. left,
  1576. top,
  1577. translate: translate2
  1578. };
  1579. };
  1580. var SugarPosition = r;
  1581. var boxPosition = function(dom2) {
  1582. var box = dom2.getBoundingClientRect();
  1583. return SugarPosition(box.left, box.top);
  1584. };
  1585. var firstDefinedOrZero = function(a, b) {
  1586. if (a !== void 0) {
  1587. return a;
  1588. } else {
  1589. return b !== void 0 ? b : 0;
  1590. }
  1591. };
  1592. var absolute = function(element) {
  1593. var doc2 = element.dom.ownerDocument;
  1594. var body = doc2.body;
  1595. var win = doc2.defaultView;
  1596. var html = doc2.documentElement;
  1597. if (body === element.dom) {
  1598. return SugarPosition(body.offsetLeft, body.offsetTop);
  1599. }
  1600. var scrollTop = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageYOffset, html.scrollTop);
  1601. var scrollLeft = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageXOffset, html.scrollLeft);
  1602. var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
  1603. var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
  1604. return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  1605. };
  1606. var viewport = function(element) {
  1607. var dom2 = element.dom;
  1608. var doc2 = dom2.ownerDocument;
  1609. var body = doc2.body;
  1610. if (body === dom2) {
  1611. return SugarPosition(body.offsetLeft, body.offsetTop);
  1612. }
  1613. if (!inBody(element)) {
  1614. return SugarPosition(0, 0);
  1615. }
  1616. return boxPosition(dom2);
  1617. };
  1618. var get$8 = function(_DOC) {
  1619. var doc2 = _DOC !== void 0 ? _DOC.dom : document;
  1620. var x = doc2.body.scrollLeft || doc2.documentElement.scrollLeft;
  1621. var y = doc2.body.scrollTop || doc2.documentElement.scrollTop;
  1622. return SugarPosition(x, y);
  1623. };
  1624. var to = function(x, y, _DOC) {
  1625. var doc2 = _DOC !== void 0 ? _DOC.dom : document;
  1626. var win = doc2.defaultView;
  1627. if (win) {
  1628. win.scrollTo(x, y);
  1629. }
  1630. };
  1631. var intoView = function(element, alignToTop) {
  1632. var isSafari = detect().browser.isSafari();
  1633. if (isSafari && isFunction(element.dom.scrollIntoViewIfNeeded)) {
  1634. element.dom.scrollIntoViewIfNeeded(false);
  1635. } else {
  1636. element.dom.scrollIntoView(alignToTop);
  1637. }
  1638. };
  1639. var get$7 = function(_win) {
  1640. var win = _win === void 0 ? window : _win;
  1641. if (detect().browser.isFirefox()) {
  1642. return Optional.none();
  1643. } else {
  1644. return Optional.from(win["visualViewport"]);
  1645. }
  1646. };
  1647. var bounds = function(x, y, width, height) {
  1648. return {
  1649. x,
  1650. y,
  1651. width,
  1652. height,
  1653. right: x + width,
  1654. bottom: y + height
  1655. };
  1656. };
  1657. var getBounds = function(_win) {
  1658. var win = _win === void 0 ? window : _win;
  1659. var doc2 = win.document;
  1660. var scroll = get$8(SugarElement.fromDom(doc2));
  1661. return get$7(win).fold(function() {
  1662. var html = win.document.documentElement;
  1663. var width = html.clientWidth;
  1664. var height = html.clientHeight;
  1665. return bounds(scroll.left, scroll.top, width, height);
  1666. }, function(visualViewport) {
  1667. return bounds(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height);
  1668. });
  1669. };
  1670. var isNodeType = function(type2) {
  1671. return function(node) {
  1672. return !!node && node.nodeType === type2;
  1673. };
  1674. };
  1675. var isRestrictedNode = function(node) {
  1676. return !!node && !Object.getPrototypeOf(node);
  1677. };
  1678. var isElement$5 = isNodeType(1);
  1679. var matchNodeNames = function(names) {
  1680. var lowercasedNames = names.map(function(s) {
  1681. return s.toLowerCase();
  1682. });
  1683. return function(node) {
  1684. if (node && node.nodeName) {
  1685. var nodeName = node.nodeName.toLowerCase();
  1686. return contains$3(lowercasedNames, nodeName);
  1687. }
  1688. return false;
  1689. };
  1690. };
  1691. var matchStyleValues = function(name2, values2) {
  1692. var items = values2.toLowerCase().split(" ");
  1693. return function(node) {
  1694. if (isElement$5(node)) {
  1695. for (var i = 0; i < items.length; i++) {
  1696. var computed = node.ownerDocument.defaultView.getComputedStyle(node, null);
  1697. var cssValue = computed ? computed.getPropertyValue(name2) : null;
  1698. if (cssValue === items[i]) {
  1699. return true;
  1700. }
  1701. }
  1702. }
  1703. return false;
  1704. };
  1705. };
  1706. var hasAttribute = function(attrName) {
  1707. return function(node) {
  1708. return isElement$5(node) && node.hasAttribute(attrName);
  1709. };
  1710. };
  1711. var hasAttributeValue = function(attrName, attrValue) {
  1712. return function(node) {
  1713. return isElement$5(node) && node.getAttribute(attrName) === attrValue;
  1714. };
  1715. };
  1716. var isBogus$2 = function(node) {
  1717. return isElement$5(node) && node.hasAttribute("data-mce-bogus");
  1718. };
  1719. var isBogusAll$1 = function(node) {
  1720. return isElement$5(node) && node.getAttribute("data-mce-bogus") === "all";
  1721. };
  1722. var isTable$3 = function(node) {
  1723. return isElement$5(node) && node.tagName === "TABLE";
  1724. };
  1725. var hasContentEditableState = function(value2) {
  1726. return function(node) {
  1727. if (isElement$5(node)) {
  1728. if (node.contentEditable === value2) {
  1729. return true;
  1730. }
  1731. if (node.getAttribute("data-mce-contenteditable") === value2) {
  1732. return true;
  1733. }
  1734. }
  1735. return false;
  1736. };
  1737. };
  1738. var isTextareaOrInput = matchNodeNames([
  1739. "textarea",
  1740. "input"
  1741. ]);
  1742. var isText$7 = isNodeType(3);
  1743. var isComment = isNodeType(8);
  1744. var isDocument$1 = isNodeType(9);
  1745. var isDocumentFragment = isNodeType(11);
  1746. var isBr$5 = matchNodeNames(["br"]);
  1747. var isImg = matchNodeNames(["img"]);
  1748. var isContentEditableTrue$4 = hasContentEditableState("true");
  1749. var isContentEditableFalse$b = hasContentEditableState("false");
  1750. var isTableCell$5 = matchNodeNames([
  1751. "td",
  1752. "th"
  1753. ]);
  1754. var isMedia$2 = matchNodeNames([
  1755. "video",
  1756. "audio",
  1757. "object",
  1758. "embed"
  1759. ]);
  1760. var is$1 = function(lhs, rhs, comparator) {
  1761. if (comparator === void 0) {
  1762. comparator = tripleEquals;
  1763. }
  1764. return lhs.exists(function(left) {
  1765. return comparator(left, rhs);
  1766. });
  1767. };
  1768. var cat = function(arr2) {
  1769. var r2 = [];
  1770. var push2 = function(x) {
  1771. r2.push(x);
  1772. };
  1773. for (var i = 0; i < arr2.length; i++) {
  1774. arr2[i].each(push2);
  1775. }
  1776. return r2;
  1777. };
  1778. var lift2 = function(oa, ob, f) {
  1779. return oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
  1780. };
  1781. var lift3 = function(oa, ob, oc, f) {
  1782. return oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none();
  1783. };
  1784. var someIf = function(b, a) {
  1785. return b ? Optional.some(a) : Optional.none();
  1786. };
  1787. var isSupported = function(dom2) {
  1788. return dom2.style !== void 0 && isFunction(dom2.style.getPropertyValue);
  1789. };
  1790. var rawSet = function(dom2, key, value2) {
  1791. if (isString$1(value2) || isBoolean(value2) || isNumber(value2)) {
  1792. dom2.setAttribute(key, value2 + "");
  1793. } else {
  1794. console.error("Invalid call to Attribute.set. Key ", key, ":: Value ", value2, ":: Element ", dom2);
  1795. throw new Error("Attribute value was not simple");
  1796. }
  1797. };
  1798. var set$1 = function(element, key, value2) {
  1799. rawSet(element.dom, key, value2);
  1800. };
  1801. var setAll$1 = function(element, attrs) {
  1802. var dom2 = element.dom;
  1803. each$j(attrs, function(v, k) {
  1804. rawSet(dom2, k, v);
  1805. });
  1806. };
  1807. var get$6 = function(element, key) {
  1808. var v = element.dom.getAttribute(key);
  1809. return v === null ? void 0 : v;
  1810. };
  1811. var getOpt = function(element, key) {
  1812. return Optional.from(get$6(element, key));
  1813. };
  1814. var has$1 = function(element, key) {
  1815. var dom2 = element.dom;
  1816. return dom2 && dom2.hasAttribute ? dom2.hasAttribute(key) : false;
  1817. };
  1818. var remove$6 = function(element, key) {
  1819. element.dom.removeAttribute(key);
  1820. };
  1821. var clone$3 = function(element) {
  1822. return foldl(element.dom.attributes, function(acc, attr) {
  1823. acc[attr.name] = attr.value;
  1824. return acc;
  1825. }, {});
  1826. };
  1827. var internalSet = function(dom2, property, value2) {
  1828. if (!isString$1(value2)) {
  1829. console.error("Invalid call to CSS.set. Property ", property, ":: Value ", value2, ":: Element ", dom2);
  1830. throw new Error("CSS value must be a string: " + value2);
  1831. }
  1832. if (isSupported(dom2)) {
  1833. dom2.style.setProperty(property, value2);
  1834. }
  1835. };
  1836. var setAll = function(element, css) {
  1837. var dom2 = element.dom;
  1838. each$j(css, function(v, k) {
  1839. internalSet(dom2, k, v);
  1840. });
  1841. };
  1842. var get$5 = function(element, property) {
  1843. var dom2 = element.dom;
  1844. var styles = window.getComputedStyle(dom2);
  1845. var r2 = styles.getPropertyValue(property);
  1846. return r2 === "" && !inBody(element) ? getUnsafeProperty(dom2, property) : r2;
  1847. };
  1848. var getUnsafeProperty = function(dom2, property) {
  1849. return isSupported(dom2) ? dom2.style.getPropertyValue(property) : "";
  1850. };
  1851. var getRaw = function(element, property) {
  1852. var dom2 = element.dom;
  1853. var raw = getUnsafeProperty(dom2, property);
  1854. return Optional.from(raw).filter(function(r2) {
  1855. return r2.length > 0;
  1856. });
  1857. };
  1858. var getAllRaw = function(element) {
  1859. var css = {};
  1860. var dom2 = element.dom;
  1861. if (isSupported(dom2)) {
  1862. for (var i = 0; i < dom2.style.length; i++) {
  1863. var ruleName = dom2.style.item(i);
  1864. css[ruleName] = dom2.style[ruleName];
  1865. }
  1866. }
  1867. return css;
  1868. };
  1869. var reflow = function(e) {
  1870. return e.dom.offsetWidth;
  1871. };
  1872. var browser$3 = detect().browser;
  1873. var firstElement = function(nodes) {
  1874. return find$3(nodes, isElement$6);
  1875. };
  1876. var getTableCaptionDeltaY = function(elm) {
  1877. if (browser$3.isFirefox() && name(elm) === "table") {
  1878. return firstElement(children(elm)).filter(function(elm2) {
  1879. return name(elm2) === "caption";
  1880. }).bind(function(caption) {
  1881. return firstElement(nextSiblings(caption)).map(function(body) {
  1882. var bodyTop = body.dom.offsetTop;
  1883. var captionTop = caption.dom.offsetTop;
  1884. var captionHeight = caption.dom.offsetHeight;
  1885. return bodyTop <= captionTop ? -captionHeight : 0;
  1886. });
  1887. }).getOr(0);
  1888. } else {
  1889. return 0;
  1890. }
  1891. };
  1892. var hasChild = function(elm, child2) {
  1893. return elm.children && contains$3(elm.children, child2);
  1894. };
  1895. var getPos = function(body, elm, rootElm) {
  1896. var x = 0, y = 0;
  1897. var doc2 = body.ownerDocument;
  1898. rootElm = rootElm ? rootElm : body;
  1899. if (elm) {
  1900. if (rootElm === body && elm.getBoundingClientRect && get$5(SugarElement.fromDom(body), "position") === "static") {
  1901. var pos = elm.getBoundingClientRect();
  1902. x = pos.left + (doc2.documentElement.scrollLeft || body.scrollLeft) - doc2.documentElement.clientLeft;
  1903. y = pos.top + (doc2.documentElement.scrollTop || body.scrollTop) - doc2.documentElement.clientTop;
  1904. return {
  1905. x,
  1906. y
  1907. };
  1908. }
  1909. var offsetParent = elm;
  1910. while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
  1911. var castOffsetParent = offsetParent;
  1912. x += castOffsetParent.offsetLeft || 0;
  1913. y += castOffsetParent.offsetTop || 0;
  1914. offsetParent = castOffsetParent.offsetParent;
  1915. }
  1916. offsetParent = elm.parentNode;
  1917. while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
  1918. x -= offsetParent.scrollLeft || 0;
  1919. y -= offsetParent.scrollTop || 0;
  1920. offsetParent = offsetParent.parentNode;
  1921. }
  1922. y += getTableCaptionDeltaY(SugarElement.fromDom(elm));
  1923. }
  1924. return {
  1925. x,
  1926. y
  1927. };
  1928. };
  1929. var exports$1 = {}, module$1 = { exports: exports$1 };
  1930. (function(define, exports2, module2, require2) {
  1931. (function(global2, factory) {
  1932. typeof exports2 === "object" && typeof module2 !== "undefined" ? module2.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, global2.EphoxContactWrapper = factory());
  1933. })(this, function() {
  1934. var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  1935. var promise = { exports: {} };
  1936. (function(module3) {
  1937. (function(root) {
  1938. var setTimeoutFunc = setTimeout;
  1939. function noop2() {
  1940. }
  1941. function bind2(fn, thisArg) {
  1942. return function() {
  1943. fn.apply(thisArg, arguments);
  1944. };
  1945. }
  1946. function Promise2(fn) {
  1947. if (typeof this !== "object")
  1948. throw new TypeError("Promises must be constructed via new");
  1949. if (typeof fn !== "function")
  1950. throw new TypeError("not a function");
  1951. this._state = 0;
  1952. this._handled = false;
  1953. this._value = void 0;
  1954. this._deferreds = [];
  1955. doResolve(fn, this);
  1956. }
  1957. function handle2(self2, deferred) {
  1958. while (self2._state === 3) {
  1959. self2 = self2._value;
  1960. }
  1961. if (self2._state === 0) {
  1962. self2._deferreds.push(deferred);
  1963. return;
  1964. }
  1965. self2._handled = true;
  1966. Promise2._immediateFn(function() {
  1967. var cb = self2._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  1968. if (cb === null) {
  1969. (self2._state === 1 ? resolve2 : reject)(deferred.promise, self2._value);
  1970. return;
  1971. }
  1972. var ret;
  1973. try {
  1974. ret = cb(self2._value);
  1975. } catch (e) {
  1976. reject(deferred.promise, e);
  1977. return;
  1978. }
  1979. resolve2(deferred.promise, ret);
  1980. });
  1981. }
  1982. function resolve2(self2, newValue) {
  1983. try {
  1984. if (newValue === self2)
  1985. throw new TypeError("A promise cannot be resolved with itself.");
  1986. if (newValue && (typeof newValue === "object" || typeof newValue === "function")) {
  1987. var then = newValue.then;
  1988. if (newValue instanceof Promise2) {
  1989. self2._state = 3;
  1990. self2._value = newValue;
  1991. finale(self2);
  1992. return;
  1993. } else if (typeof then === "function") {
  1994. doResolve(bind2(then, newValue), self2);
  1995. return;
  1996. }
  1997. }
  1998. self2._state = 1;
  1999. self2._value = newValue;
  2000. finale(self2);
  2001. } catch (e) {
  2002. reject(self2, e);
  2003. }
  2004. }
  2005. function reject(self2, newValue) {
  2006. self2._state = 2;
  2007. self2._value = newValue;
  2008. finale(self2);
  2009. }
  2010. function finale(self2) {
  2011. if (self2._state === 2 && self2._deferreds.length === 0) {
  2012. Promise2._immediateFn(function() {
  2013. if (!self2._handled) {
  2014. Promise2._unhandledRejectionFn(self2._value);
  2015. }
  2016. });
  2017. }
  2018. for (var i = 0, len = self2._deferreds.length; i < len; i++) {
  2019. handle2(self2, self2._deferreds[i]);
  2020. }
  2021. self2._deferreds = null;
  2022. }
  2023. function Handler(onFulfilled, onRejected, promise2) {
  2024. this.onFulfilled = typeof onFulfilled === "function" ? onFulfilled : null;
  2025. this.onRejected = typeof onRejected === "function" ? onRejected : null;
  2026. this.promise = promise2;
  2027. }
  2028. function doResolve(fn, self2) {
  2029. var done2 = false;
  2030. try {
  2031. fn(function(value2) {
  2032. if (done2)
  2033. return;
  2034. done2 = true;
  2035. resolve2(self2, value2);
  2036. }, function(reason) {
  2037. if (done2)
  2038. return;
  2039. done2 = true;
  2040. reject(self2, reason);
  2041. });
  2042. } catch (ex) {
  2043. if (done2)
  2044. return;
  2045. done2 = true;
  2046. reject(self2, ex);
  2047. }
  2048. }
  2049. Promise2.prototype["catch"] = function(onRejected) {
  2050. return this.then(null, onRejected);
  2051. };
  2052. Promise2.prototype.then = function(onFulfilled, onRejected) {
  2053. var prom = new this.constructor(noop2);
  2054. handle2(this, new Handler(onFulfilled, onRejected, prom));
  2055. return prom;
  2056. };
  2057. Promise2.all = function(arr2) {
  2058. var args = Array.prototype.slice.call(arr2);
  2059. return new Promise2(function(resolve3, reject2) {
  2060. if (args.length === 0)
  2061. return resolve3([]);
  2062. var remaining = args.length;
  2063. function res(i2, val) {
  2064. try {
  2065. if (val && (typeof val === "object" || typeof val === "function")) {
  2066. var then = val.then;
  2067. if (typeof then === "function") {
  2068. then.call(val, function(val2) {
  2069. res(i2, val2);
  2070. }, reject2);
  2071. return;
  2072. }
  2073. }
  2074. args[i2] = val;
  2075. if (--remaining === 0) {
  2076. resolve3(args);
  2077. }
  2078. } catch (ex) {
  2079. reject2(ex);
  2080. }
  2081. }
  2082. for (var i = 0; i < args.length; i++) {
  2083. res(i, args[i]);
  2084. }
  2085. });
  2086. };
  2087. Promise2.resolve = function(value2) {
  2088. if (value2 && typeof value2 === "object" && value2.constructor === Promise2) {
  2089. return value2;
  2090. }
  2091. return new Promise2(function(resolve3) {
  2092. resolve3(value2);
  2093. });
  2094. };
  2095. Promise2.reject = function(value2) {
  2096. return new Promise2(function(resolve3, reject2) {
  2097. reject2(value2);
  2098. });
  2099. };
  2100. Promise2.race = function(values2) {
  2101. return new Promise2(function(resolve3, reject2) {
  2102. for (var i = 0, len = values2.length; i < len; i++) {
  2103. values2[i].then(resolve3, reject2);
  2104. }
  2105. });
  2106. };
  2107. Promise2._immediateFn = typeof setImmediate === "function" ? function(fn) {
  2108. setImmediate(fn);
  2109. } : function(fn) {
  2110. setTimeoutFunc(fn, 0);
  2111. };
  2112. Promise2._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  2113. if (typeof console !== "undefined" && console) {
  2114. console.warn("Possible Unhandled Promise Rejection:", err);
  2115. }
  2116. };
  2117. Promise2._setImmediateFn = function _setImmediateFn(fn) {
  2118. Promise2._immediateFn = fn;
  2119. };
  2120. Promise2._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  2121. Promise2._unhandledRejectionFn = fn;
  2122. };
  2123. if (module3.exports) {
  2124. module3.exports = Promise2;
  2125. } else if (!root.Promise) {
  2126. root.Promise = Promise2;
  2127. }
  2128. })(commonjsGlobal);
  2129. })(promise);
  2130. var promisePolyfill = promise.exports;
  2131. var Global = function() {
  2132. if (typeof window !== "undefined") {
  2133. return window;
  2134. } else {
  2135. return Function("return this;")();
  2136. }
  2137. }();
  2138. var promisePolyfill_1 = { boltExport: Global.Promise || promisePolyfill };
  2139. return promisePolyfill_1;
  2140. });
  2141. })(void 0, exports$1, module$1);
  2142. var Promise$1 = module$1.exports.boltExport;
  2143. var nu$1 = function(baseFn) {
  2144. var data2 = Optional.none();
  2145. var callbacks = [];
  2146. var map2 = function(f) {
  2147. return nu$1(function(nCallback) {
  2148. get2(function(data3) {
  2149. nCallback(f(data3));
  2150. });
  2151. });
  2152. };
  2153. var get2 = function(nCallback) {
  2154. if (isReady()) {
  2155. call2(nCallback);
  2156. } else {
  2157. callbacks.push(nCallback);
  2158. }
  2159. };
  2160. var set2 = function(x) {
  2161. if (!isReady()) {
  2162. data2 = Optional.some(x);
  2163. run(callbacks);
  2164. callbacks = [];
  2165. }
  2166. };
  2167. var isReady = function() {
  2168. return data2.isSome();
  2169. };
  2170. var run = function(cbs) {
  2171. each$k(cbs, call2);
  2172. };
  2173. var call2 = function(cb) {
  2174. data2.each(function(x) {
  2175. setTimeout(function() {
  2176. cb(x);
  2177. }, 0);
  2178. });
  2179. };
  2180. baseFn(set2);
  2181. return {
  2182. get: get2,
  2183. map: map2,
  2184. isReady
  2185. };
  2186. };
  2187. var pure$1 = function(a) {
  2188. return nu$1(function(callback) {
  2189. callback(a);
  2190. });
  2191. };
  2192. var LazyValue = {
  2193. nu: nu$1,
  2194. pure: pure$1
  2195. };
  2196. var errorReporter = function(err) {
  2197. setTimeout(function() {
  2198. throw err;
  2199. }, 0);
  2200. };
  2201. var make = function(run) {
  2202. var get2 = function(callback) {
  2203. run().then(callback, errorReporter);
  2204. };
  2205. var map2 = function(fab) {
  2206. return make(function() {
  2207. return run().then(fab);
  2208. });
  2209. };
  2210. var bind2 = function(aFutureB) {
  2211. return make(function() {
  2212. return run().then(function(v) {
  2213. return aFutureB(v).toPromise();
  2214. });
  2215. });
  2216. };
  2217. var anonBind = function(futureB) {
  2218. return make(function() {
  2219. return run().then(function() {
  2220. return futureB.toPromise();
  2221. });
  2222. });
  2223. };
  2224. var toLazy = function() {
  2225. return LazyValue.nu(get2);
  2226. };
  2227. var toCached = function() {
  2228. var cache = null;
  2229. return make(function() {
  2230. if (cache === null) {
  2231. cache = run();
  2232. }
  2233. return cache;
  2234. });
  2235. };
  2236. var toPromise = run;
  2237. return {
  2238. map: map2,
  2239. bind: bind2,
  2240. anonBind,
  2241. toLazy,
  2242. toCached,
  2243. toPromise,
  2244. get: get2
  2245. };
  2246. };
  2247. var nu = function(baseFn) {
  2248. return make(function() {
  2249. return new Promise$1(baseFn);
  2250. });
  2251. };
  2252. var pure = function(a) {
  2253. return make(function() {
  2254. return Promise$1.resolve(a);
  2255. });
  2256. };
  2257. var Future = {
  2258. nu,
  2259. pure
  2260. };
  2261. var par$1 = function(asyncValues, nu2) {
  2262. return nu2(function(callback) {
  2263. var r2 = [];
  2264. var count2 = 0;
  2265. var cb = function(i) {
  2266. return function(value2) {
  2267. r2[i] = value2;
  2268. count2++;
  2269. if (count2 >= asyncValues.length) {
  2270. callback(r2);
  2271. }
  2272. };
  2273. };
  2274. if (asyncValues.length === 0) {
  2275. callback([]);
  2276. } else {
  2277. each$k(asyncValues, function(asyncValue, i) {
  2278. asyncValue.get(cb(i));
  2279. });
  2280. }
  2281. });
  2282. };
  2283. var par = function(futures) {
  2284. return par$1(futures, Future.nu);
  2285. };
  2286. var value$1 = function(o) {
  2287. var or2 = function(_opt) {
  2288. return value$1(o);
  2289. };
  2290. var orThunk = function(_f) {
  2291. return value$1(o);
  2292. };
  2293. var map2 = function(f) {
  2294. return value$1(f(o));
  2295. };
  2296. var mapError = function(_f) {
  2297. return value$1(o);
  2298. };
  2299. var each2 = function(f) {
  2300. f(o);
  2301. };
  2302. var bind2 = function(f) {
  2303. return f(o);
  2304. };
  2305. var fold = function(_, onValue) {
  2306. return onValue(o);
  2307. };
  2308. var exists2 = function(f) {
  2309. return f(o);
  2310. };
  2311. var forall2 = function(f) {
  2312. return f(o);
  2313. };
  2314. var toOptional = function() {
  2315. return Optional.some(o);
  2316. };
  2317. return {
  2318. isValue: always,
  2319. isError: never,
  2320. getOr: constant(o),
  2321. getOrThunk: constant(o),
  2322. getOrDie: constant(o),
  2323. or: or2,
  2324. orThunk,
  2325. fold,
  2326. map: map2,
  2327. mapError,
  2328. each: each2,
  2329. bind: bind2,
  2330. exists: exists2,
  2331. forall: forall2,
  2332. toOptional
  2333. };
  2334. };
  2335. var error = function(message) {
  2336. var getOrThunk = function(f) {
  2337. return f();
  2338. };
  2339. var getOrDie = function() {
  2340. return die(String(message))();
  2341. };
  2342. var or2 = identity;
  2343. var orThunk = function(f) {
  2344. return f();
  2345. };
  2346. var map2 = function(_f) {
  2347. return error(message);
  2348. };
  2349. var mapError = function(f) {
  2350. return error(f(message));
  2351. };
  2352. var bind2 = function(_f) {
  2353. return error(message);
  2354. };
  2355. var fold = function(onError, _) {
  2356. return onError(message);
  2357. };
  2358. return {
  2359. isValue: never,
  2360. isError: always,
  2361. getOr: identity,
  2362. getOrThunk,
  2363. getOrDie,
  2364. or: or2,
  2365. orThunk,
  2366. fold,
  2367. map: map2,
  2368. mapError,
  2369. each: noop,
  2370. bind: bind2,
  2371. exists: never,
  2372. forall: always,
  2373. toOptional: Optional.none
  2374. };
  2375. };
  2376. var fromOption = function(opt, err) {
  2377. return opt.fold(function() {
  2378. return error(err);
  2379. }, value$1);
  2380. };
  2381. var Result = {
  2382. value: value$1,
  2383. error,
  2384. fromOption
  2385. };
  2386. var generate$1 = function(cases) {
  2387. if (!isArray$1(cases)) {
  2388. throw new Error("cases must be an array");
  2389. }
  2390. if (cases.length === 0) {
  2391. throw new Error("there must be at least one case");
  2392. }
  2393. var constructors = [];
  2394. var adt2 = {};
  2395. each$k(cases, function(acase, count2) {
  2396. var keys$1 = keys(acase);
  2397. if (keys$1.length !== 1) {
  2398. throw new Error("one and only one name per case");
  2399. }
  2400. var key = keys$1[0];
  2401. var value2 = acase[key];
  2402. if (adt2[key] !== void 0) {
  2403. throw new Error("duplicate key detected:" + key);
  2404. } else if (key === "cata") {
  2405. throw new Error("cannot have a case named cata (sorry)");
  2406. } else if (!isArray$1(value2)) {
  2407. throw new Error("case arguments must be an array");
  2408. }
  2409. constructors.push(key);
  2410. adt2[key] = function() {
  2411. var args = [];
  2412. for (var _i = 0; _i < arguments.length; _i++) {
  2413. args[_i] = arguments[_i];
  2414. }
  2415. var argLength = args.length;
  2416. if (argLength !== value2.length) {
  2417. throw new Error("Wrong number of arguments to case " + key + ". Expected " + value2.length + " (" + value2 + "), got " + argLength);
  2418. }
  2419. var match2 = function(branches) {
  2420. var branchKeys = keys(branches);
  2421. if (constructors.length !== branchKeys.length) {
  2422. throw new Error("Wrong number of arguments to match. Expected: " + constructors.join(",") + "\nActual: " + branchKeys.join(","));
  2423. }
  2424. var allReqd = forall(constructors, function(reqKey) {
  2425. return contains$3(branchKeys, reqKey);
  2426. });
  2427. if (!allReqd) {
  2428. throw new Error("Not all branches were specified when using match. Specified: " + branchKeys.join(", ") + "\nRequired: " + constructors.join(", "));
  2429. }
  2430. return branches[key].apply(null, args);
  2431. };
  2432. return {
  2433. fold: function() {
  2434. var foldArgs = [];
  2435. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  2436. foldArgs[_i2] = arguments[_i2];
  2437. }
  2438. if (foldArgs.length !== cases.length) {
  2439. throw new Error("Wrong number of arguments to fold. Expected " + cases.length + ", got " + foldArgs.length);
  2440. }
  2441. var target = foldArgs[count2];
  2442. return target.apply(null, args);
  2443. },
  2444. match: match2,
  2445. log: function(label) {
  2446. console.log(label, {
  2447. constructors,
  2448. constructor: key,
  2449. params: args
  2450. });
  2451. }
  2452. };
  2453. };
  2454. });
  2455. return adt2;
  2456. };
  2457. var Adt = { generate: generate$1 };
  2458. Adt.generate([
  2459. {
  2460. bothErrors: [
  2461. "error1",
  2462. "error2"
  2463. ]
  2464. },
  2465. {
  2466. firstError: [
  2467. "error1",
  2468. "value2"
  2469. ]
  2470. },
  2471. {
  2472. secondError: [
  2473. "value1",
  2474. "error2"
  2475. ]
  2476. },
  2477. {
  2478. bothValues: [
  2479. "value1",
  2480. "value2"
  2481. ]
  2482. }
  2483. ]);
  2484. var unite = function(result) {
  2485. return result.fold(identity, identity);
  2486. };
  2487. function ClosestOrAncestor(is2, ancestor2, scope, a, isRoot) {
  2488. if (is2(scope, a)) {
  2489. return Optional.some(scope);
  2490. } else if (isFunction(isRoot) && isRoot(scope)) {
  2491. return Optional.none();
  2492. } else {
  2493. return ancestor2(scope, a, isRoot);
  2494. }
  2495. }
  2496. var ancestor$3 = function(scope, predicate, isRoot) {
  2497. var element = scope.dom;
  2498. var stop2 = isFunction(isRoot) ? isRoot : never;
  2499. while (element.parentNode) {
  2500. element = element.parentNode;
  2501. var el = SugarElement.fromDom(element);
  2502. if (predicate(el)) {
  2503. return Optional.some(el);
  2504. } else if (stop2(el)) {
  2505. break;
  2506. }
  2507. }
  2508. return Optional.none();
  2509. };
  2510. var closest$3 = function(scope, predicate, isRoot) {
  2511. var is2 = function(s, test2) {
  2512. return test2(s);
  2513. };
  2514. return ClosestOrAncestor(is2, ancestor$3, scope, predicate, isRoot);
  2515. };
  2516. var sibling$2 = function(scope, predicate) {
  2517. var element = scope.dom;
  2518. if (!element.parentNode) {
  2519. return Optional.none();
  2520. }
  2521. return child(SugarElement.fromDom(element.parentNode), function(x) {
  2522. return !eq(scope, x) && predicate(x);
  2523. });
  2524. };
  2525. var child = function(scope, predicate) {
  2526. var pred = function(node) {
  2527. return predicate(SugarElement.fromDom(node));
  2528. };
  2529. var result = find$3(scope.dom.childNodes, pred);
  2530. return result.map(SugarElement.fromDom);
  2531. };
  2532. var ancestor$2 = function(scope, selector, isRoot) {
  2533. return ancestor$3(scope, function(e) {
  2534. return is$2(e, selector);
  2535. }, isRoot);
  2536. };
  2537. var descendant = function(scope, selector) {
  2538. return one(selector, scope);
  2539. };
  2540. var closest$2 = function(scope, selector, isRoot) {
  2541. var is2 = function(element, selector2) {
  2542. return is$2(element, selector2);
  2543. };
  2544. return ClosestOrAncestor(is2, ancestor$2, scope, selector, isRoot);
  2545. };
  2546. var promiseObj = window.Promise ? window.Promise : Promise$1;
  2547. var requestAnimationFramePromise;
  2548. var requestAnimationFrame = function(callback, element) {
  2549. var requestAnimationFrameFunc = window.requestAnimationFrame;
  2550. var vendors = [
  2551. "ms",
  2552. "moz",
  2553. "webkit"
  2554. ];
  2555. var featurefill = function(cb) {
  2556. window.setTimeout(cb, 0);
  2557. };
  2558. for (var i = 0; i < vendors.length && !requestAnimationFrameFunc; i++) {
  2559. requestAnimationFrameFunc = window[vendors[i] + "RequestAnimationFrame"];
  2560. }
  2561. if (!requestAnimationFrameFunc) {
  2562. requestAnimationFrameFunc = featurefill;
  2563. }
  2564. requestAnimationFrameFunc(callback, element);
  2565. };
  2566. var wrappedSetTimeout = function(callback, time) {
  2567. if (typeof time !== "number") {
  2568. time = 0;
  2569. }
  2570. return setTimeout(callback, time);
  2571. };
  2572. var wrappedSetInterval = function(callback, time) {
  2573. if (typeof time !== "number") {
  2574. time = 1;
  2575. }
  2576. return setInterval(callback, time);
  2577. };
  2578. var wrappedClearTimeout = function(id) {
  2579. return clearTimeout(id);
  2580. };
  2581. var wrappedClearInterval = function(id) {
  2582. return clearInterval(id);
  2583. };
  2584. var debounce = function(callback, time) {
  2585. var timer;
  2586. var func = function() {
  2587. var args = [];
  2588. for (var _i = 0; _i < arguments.length; _i++) {
  2589. args[_i] = arguments[_i];
  2590. }
  2591. clearTimeout(timer);
  2592. timer = wrappedSetTimeout(function() {
  2593. callback.apply(this, args);
  2594. }, time);
  2595. };
  2596. func.stop = function() {
  2597. clearTimeout(timer);
  2598. };
  2599. return func;
  2600. };
  2601. var Delay = {
  2602. requestAnimationFrame: function(callback, element) {
  2603. if (requestAnimationFramePromise) {
  2604. requestAnimationFramePromise.then(callback);
  2605. return;
  2606. }
  2607. requestAnimationFramePromise = new promiseObj(function(resolve2) {
  2608. if (!element) {
  2609. element = document.body;
  2610. }
  2611. requestAnimationFrame(resolve2, element);
  2612. }).then(callback);
  2613. },
  2614. setTimeout: wrappedSetTimeout,
  2615. setInterval: wrappedSetInterval,
  2616. setEditorTimeout: function(editor, callback, time) {
  2617. return wrappedSetTimeout(function() {
  2618. if (!editor.removed) {
  2619. callback();
  2620. }
  2621. }, time);
  2622. },
  2623. setEditorInterval: function(editor, callback, time) {
  2624. var timer = wrappedSetInterval(function() {
  2625. if (!editor.removed) {
  2626. callback();
  2627. } else {
  2628. clearInterval(timer);
  2629. }
  2630. }, time);
  2631. return timer;
  2632. },
  2633. debounce,
  2634. throttle: debounce,
  2635. clearInterval: wrappedClearInterval,
  2636. clearTimeout: wrappedClearTimeout
  2637. };
  2638. var StyleSheetLoader = function(documentOrShadowRoot, settings) {
  2639. if (settings === void 0) {
  2640. settings = {};
  2641. }
  2642. var idCount = 0;
  2643. var loadedStates = {};
  2644. var edos = SugarElement.fromDom(documentOrShadowRoot);
  2645. var doc2 = documentOrOwner(edos);
  2646. var maxLoadTime = settings.maxLoadTime || 5e3;
  2647. var _setReferrerPolicy = function(referrerPolicy) {
  2648. settings.referrerPolicy = referrerPolicy;
  2649. };
  2650. var addStyle = function(element) {
  2651. append$1(getStyleContainer(edos), element);
  2652. };
  2653. var removeStyle = function(id) {
  2654. var styleContainer = getStyleContainer(edos);
  2655. descendant(styleContainer, "#" + id).each(remove$7);
  2656. };
  2657. var getOrCreateState = function(url) {
  2658. return get$9(loadedStates, url).getOrThunk(function() {
  2659. return {
  2660. id: "mce-u" + idCount++,
  2661. passed: [],
  2662. failed: [],
  2663. count: 0
  2664. };
  2665. });
  2666. };
  2667. var load = function(url, success, failure) {
  2668. var link;
  2669. var urlWithSuffix = Tools._addCacheSuffix(url);
  2670. var state = getOrCreateState(urlWithSuffix);
  2671. loadedStates[urlWithSuffix] = state;
  2672. state.count++;
  2673. var resolve2 = function(callbacks, status) {
  2674. var i = callbacks.length;
  2675. while (i--) {
  2676. callbacks[i]();
  2677. }
  2678. state.status = status;
  2679. state.passed = [];
  2680. state.failed = [];
  2681. if (link) {
  2682. link.onload = null;
  2683. link.onerror = null;
  2684. link = null;
  2685. }
  2686. };
  2687. var passed = function() {
  2688. return resolve2(state.passed, 2);
  2689. };
  2690. var failed = function() {
  2691. return resolve2(state.failed, 3);
  2692. };
  2693. var wait = function(testCallback, waitCallback) {
  2694. if (!testCallback()) {
  2695. if (Date.now() - startTime < maxLoadTime) {
  2696. Delay.setTimeout(waitCallback);
  2697. } else {
  2698. failed();
  2699. }
  2700. }
  2701. };
  2702. var waitForWebKitLinkLoaded = function() {
  2703. wait(function() {
  2704. var styleSheets = documentOrShadowRoot.styleSheets;
  2705. var i = styleSheets.length;
  2706. while (i--) {
  2707. var styleSheet = styleSheets[i];
  2708. var owner2 = styleSheet.ownerNode;
  2709. if (owner2 && owner2.id === link.id) {
  2710. passed();
  2711. return true;
  2712. }
  2713. }
  2714. return false;
  2715. }, waitForWebKitLinkLoaded);
  2716. };
  2717. if (success) {
  2718. state.passed.push(success);
  2719. }
  2720. if (failure) {
  2721. state.failed.push(failure);
  2722. }
  2723. if (state.status === 1) {
  2724. return;
  2725. }
  2726. if (state.status === 2) {
  2727. passed();
  2728. return;
  2729. }
  2730. if (state.status === 3) {
  2731. failed();
  2732. return;
  2733. }
  2734. state.status = 1;
  2735. var linkElem = SugarElement.fromTag("link", doc2.dom);
  2736. setAll$1(linkElem, {
  2737. rel: "stylesheet",
  2738. type: "text/css",
  2739. id: state.id
  2740. });
  2741. var startTime = Date.now();
  2742. if (settings.contentCssCors) {
  2743. set$1(linkElem, "crossOrigin", "anonymous");
  2744. }
  2745. if (settings.referrerPolicy) {
  2746. set$1(linkElem, "referrerpolicy", settings.referrerPolicy);
  2747. }
  2748. link = linkElem.dom;
  2749. link.onload = waitForWebKitLinkLoaded;
  2750. link.onerror = failed;
  2751. addStyle(linkElem);
  2752. set$1(linkElem, "href", urlWithSuffix);
  2753. };
  2754. var loadF = function(url) {
  2755. return Future.nu(function(resolve2) {
  2756. load(url, compose(resolve2, constant(Result.value(url))), compose(resolve2, constant(Result.error(url))));
  2757. });
  2758. };
  2759. var loadAll = function(urls, success, failure) {
  2760. par(map$3(urls, loadF)).get(function(result) {
  2761. var parts = partition(result, function(r2) {
  2762. return r2.isValue();
  2763. });
  2764. if (parts.fail.length > 0) {
  2765. failure(parts.fail.map(unite));
  2766. } else {
  2767. success(parts.pass.map(unite));
  2768. }
  2769. });
  2770. };
  2771. var unload = function(url) {
  2772. var urlWithSuffix = Tools._addCacheSuffix(url);
  2773. get$9(loadedStates, urlWithSuffix).each(function(state) {
  2774. var count2 = --state.count;
  2775. if (count2 === 0) {
  2776. delete loadedStates[urlWithSuffix];
  2777. removeStyle(state.id);
  2778. }
  2779. });
  2780. };
  2781. var unloadAll = function(urls) {
  2782. each$k(urls, function(url) {
  2783. unload(url);
  2784. });
  2785. };
  2786. return {
  2787. load,
  2788. loadAll,
  2789. unload,
  2790. unloadAll,
  2791. _setReferrerPolicy
  2792. };
  2793. };
  2794. var create$8 = function() {
  2795. var map2 = /* @__PURE__ */ new WeakMap();
  2796. var forElement = function(referenceElement, settings) {
  2797. var root = getRootNode(referenceElement);
  2798. var rootDom = root.dom;
  2799. return Optional.from(map2.get(rootDom)).getOrThunk(function() {
  2800. var sl = StyleSheetLoader(rootDom, settings);
  2801. map2.set(rootDom, sl);
  2802. return sl;
  2803. });
  2804. };
  2805. return { forElement };
  2806. };
  2807. var instance = create$8();
  2808. var DomTreeWalker = function() {
  2809. function DomTreeWalker2(startNode, rootNode) {
  2810. this.node = startNode;
  2811. this.rootNode = rootNode;
  2812. this.current = this.current.bind(this);
  2813. this.next = this.next.bind(this);
  2814. this.prev = this.prev.bind(this);
  2815. this.prev2 = this.prev2.bind(this);
  2816. }
  2817. DomTreeWalker2.prototype.current = function() {
  2818. return this.node;
  2819. };
  2820. DomTreeWalker2.prototype.next = function(shallow2) {
  2821. this.node = this.findSibling(this.node, "firstChild", "nextSibling", shallow2);
  2822. return this.node;
  2823. };
  2824. DomTreeWalker2.prototype.prev = function(shallow2) {
  2825. this.node = this.findSibling(this.node, "lastChild", "previousSibling", shallow2);
  2826. return this.node;
  2827. };
  2828. DomTreeWalker2.prototype.prev2 = function(shallow2) {
  2829. this.node = this.findPreviousNode(this.node, "lastChild", "previousSibling", shallow2);
  2830. return this.node;
  2831. };
  2832. DomTreeWalker2.prototype.findSibling = function(node, startName, siblingName, shallow2) {
  2833. var sibling2, parent2;
  2834. if (node) {
  2835. if (!shallow2 && node[startName]) {
  2836. return node[startName];
  2837. }
  2838. if (node !== this.rootNode) {
  2839. sibling2 = node[siblingName];
  2840. if (sibling2) {
  2841. return sibling2;
  2842. }
  2843. for (parent2 = node.parentNode; parent2 && parent2 !== this.rootNode; parent2 = parent2.parentNode) {
  2844. sibling2 = parent2[siblingName];
  2845. if (sibling2) {
  2846. return sibling2;
  2847. }
  2848. }
  2849. }
  2850. }
  2851. };
  2852. DomTreeWalker2.prototype.findPreviousNode = function(node, startName, siblingName, shallow2) {
  2853. var sibling2, parent2, child2;
  2854. if (node) {
  2855. sibling2 = node[siblingName];
  2856. if (this.rootNode && sibling2 === this.rootNode) {
  2857. return;
  2858. }
  2859. if (sibling2) {
  2860. if (!shallow2) {
  2861. for (child2 = sibling2[startName]; child2; child2 = child2[startName]) {
  2862. if (!child2[startName]) {
  2863. return child2;
  2864. }
  2865. }
  2866. }
  2867. return sibling2;
  2868. }
  2869. parent2 = node.parentNode;
  2870. if (parent2 && parent2 !== this.rootNode) {
  2871. return parent2;
  2872. }
  2873. }
  2874. };
  2875. return DomTreeWalker2;
  2876. }();
  2877. var blocks = [
  2878. "article",
  2879. "aside",
  2880. "details",
  2881. "div",
  2882. "dt",
  2883. "figcaption",
  2884. "footer",
  2885. "form",
  2886. "fieldset",
  2887. "header",
  2888. "hgroup",
  2889. "html",
  2890. "main",
  2891. "nav",
  2892. "section",
  2893. "summary",
  2894. "body",
  2895. "p",
  2896. "dl",
  2897. "multicol",
  2898. "dd",
  2899. "figure",
  2900. "address",
  2901. "center",
  2902. "blockquote",
  2903. "h1",
  2904. "h2",
  2905. "h3",
  2906. "h4",
  2907. "h5",
  2908. "h6",
  2909. "listing",
  2910. "xmp",
  2911. "pre",
  2912. "plaintext",
  2913. "menu",
  2914. "dir",
  2915. "ul",
  2916. "ol",
  2917. "li",
  2918. "hr",
  2919. "table",
  2920. "tbody",
  2921. "thead",
  2922. "tfoot",
  2923. "th",
  2924. "tr",
  2925. "td",
  2926. "caption"
  2927. ];
  2928. var tableCells = [
  2929. "td",
  2930. "th"
  2931. ];
  2932. var tableSections = [
  2933. "thead",
  2934. "tbody",
  2935. "tfoot"
  2936. ];
  2937. var textBlocks = [
  2938. "h1",
  2939. "h2",
  2940. "h3",
  2941. "h4",
  2942. "h5",
  2943. "h6",
  2944. "p",
  2945. "div",
  2946. "address",
  2947. "pre",
  2948. "form",
  2949. "blockquote",
  2950. "center",
  2951. "dir",
  2952. "fieldset",
  2953. "header",
  2954. "footer",
  2955. "article",
  2956. "section",
  2957. "hgroup",
  2958. "aside",
  2959. "nav",
  2960. "figure"
  2961. ];
  2962. var headings = [
  2963. "h1",
  2964. "h2",
  2965. "h3",
  2966. "h4",
  2967. "h5",
  2968. "h6"
  2969. ];
  2970. var listItems$1 = [
  2971. "li",
  2972. "dd",
  2973. "dt"
  2974. ];
  2975. var lists = [
  2976. "ul",
  2977. "ol",
  2978. "dl"
  2979. ];
  2980. var wsElements = [
  2981. "pre",
  2982. "script",
  2983. "textarea",
  2984. "style"
  2985. ];
  2986. var lazyLookup = function(items) {
  2987. var lookup;
  2988. return function(node) {
  2989. lookup = lookup ? lookup : mapToObject(items, always);
  2990. return has$2(lookup, name(node));
  2991. };
  2992. };
  2993. var isHeading = lazyLookup(headings);
  2994. var isBlock$2 = lazyLookup(blocks);
  2995. var isTable$2 = function(node) {
  2996. return name(node) === "table";
  2997. };
  2998. var isInline$1 = function(node) {
  2999. return isElement$6(node) && !isBlock$2(node);
  3000. };
  3001. var isBr$4 = function(node) {
  3002. return isElement$6(node) && name(node) === "br";
  3003. };
  3004. var isTextBlock$2 = lazyLookup(textBlocks);
  3005. var isList = lazyLookup(lists);
  3006. var isListItem = lazyLookup(listItems$1);
  3007. var isTableSection = lazyLookup(tableSections);
  3008. var isTableCell$4 = lazyLookup(tableCells);
  3009. var isWsPreserveElement = lazyLookup(wsElements);
  3010. var ancestor$1 = function(scope, selector, isRoot) {
  3011. return ancestor$2(scope, selector, isRoot).isSome();
  3012. };
  3013. var zeroWidth = "\uFEFF";
  3014. var nbsp = "\xA0";
  3015. var isZwsp$1 = function(char) {
  3016. return char === zeroWidth;
  3017. };
  3018. var removeZwsp = function(s) {
  3019. return s.replace(/\uFEFF/g, "");
  3020. };
  3021. var ZWSP$1 = zeroWidth;
  3022. var isZwsp = isZwsp$1;
  3023. var trim$2 = removeZwsp;
  3024. var isElement$4 = isElement$5;
  3025. var isText$6 = isText$7;
  3026. var isCaretContainerBlock$1 = function(node) {
  3027. if (isText$6(node)) {
  3028. node = node.parentNode;
  3029. }
  3030. return isElement$4(node) && node.hasAttribute("data-mce-caret");
  3031. };
  3032. var isCaretContainerInline = function(node) {
  3033. return isText$6(node) && isZwsp(node.data);
  3034. };
  3035. var isCaretContainer$2 = function(node) {
  3036. return isCaretContainerBlock$1(node) || isCaretContainerInline(node);
  3037. };
  3038. var hasContent = function(node) {
  3039. return node.firstChild !== node.lastChild || !isBr$5(node.firstChild);
  3040. };
  3041. var insertInline$1 = function(node, before2) {
  3042. var doc2 = node.ownerDocument;
  3043. var textNode = doc2.createTextNode(ZWSP$1);
  3044. var parentNode = node.parentNode;
  3045. if (!before2) {
  3046. var sibling2 = node.nextSibling;
  3047. if (isText$6(sibling2)) {
  3048. if (isCaretContainer$2(sibling2)) {
  3049. return sibling2;
  3050. }
  3051. if (startsWithCaretContainer$1(sibling2)) {
  3052. sibling2.splitText(1);
  3053. return sibling2;
  3054. }
  3055. }
  3056. if (node.nextSibling) {
  3057. parentNode.insertBefore(textNode, node.nextSibling);
  3058. } else {
  3059. parentNode.appendChild(textNode);
  3060. }
  3061. } else {
  3062. var sibling2 = node.previousSibling;
  3063. if (isText$6(sibling2)) {
  3064. if (isCaretContainer$2(sibling2)) {
  3065. return sibling2;
  3066. }
  3067. if (endsWithCaretContainer$1(sibling2)) {
  3068. return sibling2.splitText(sibling2.data.length - 1);
  3069. }
  3070. }
  3071. parentNode.insertBefore(textNode, node);
  3072. }
  3073. return textNode;
  3074. };
  3075. var isBeforeInline = function(pos) {
  3076. var container = pos.container();
  3077. if (!isText$7(container)) {
  3078. return false;
  3079. }
  3080. return container.data.charAt(pos.offset()) === ZWSP$1 || pos.isAtStart() && isCaretContainerInline(container.previousSibling);
  3081. };
  3082. var isAfterInline = function(pos) {
  3083. var container = pos.container();
  3084. if (!isText$7(container)) {
  3085. return false;
  3086. }
  3087. return container.data.charAt(pos.offset() - 1) === ZWSP$1 || pos.isAtEnd() && isCaretContainerInline(container.nextSibling);
  3088. };
  3089. var createBogusBr = function() {
  3090. var br = document.createElement("br");
  3091. br.setAttribute("data-mce-bogus", "1");
  3092. return br;
  3093. };
  3094. var insertBlock$1 = function(blockName, node, before2) {
  3095. var doc2 = node.ownerDocument;
  3096. var blockNode = doc2.createElement(blockName);
  3097. blockNode.setAttribute("data-mce-caret", before2 ? "before" : "after");
  3098. blockNode.setAttribute("data-mce-bogus", "all");
  3099. blockNode.appendChild(createBogusBr());
  3100. var parentNode = node.parentNode;
  3101. if (!before2) {
  3102. if (node.nextSibling) {
  3103. parentNode.insertBefore(blockNode, node.nextSibling);
  3104. } else {
  3105. parentNode.appendChild(blockNode);
  3106. }
  3107. } else {
  3108. parentNode.insertBefore(blockNode, node);
  3109. }
  3110. return blockNode;
  3111. };
  3112. var startsWithCaretContainer$1 = function(node) {
  3113. return isText$6(node) && node.data[0] === ZWSP$1;
  3114. };
  3115. var endsWithCaretContainer$1 = function(node) {
  3116. return isText$6(node) && node.data[node.data.length - 1] === ZWSP$1;
  3117. };
  3118. var trimBogusBr = function(elm) {
  3119. var brs = elm.getElementsByTagName("br");
  3120. var lastBr = brs[brs.length - 1];
  3121. if (isBogus$2(lastBr)) {
  3122. lastBr.parentNode.removeChild(lastBr);
  3123. }
  3124. };
  3125. var showCaretContainerBlock = function(caretContainer) {
  3126. if (caretContainer && caretContainer.hasAttribute("data-mce-caret")) {
  3127. trimBogusBr(caretContainer);
  3128. caretContainer.removeAttribute("data-mce-caret");
  3129. caretContainer.removeAttribute("data-mce-bogus");
  3130. caretContainer.removeAttribute("style");
  3131. caretContainer.removeAttribute("_moz_abspos");
  3132. return caretContainer;
  3133. }
  3134. return null;
  3135. };
  3136. var isRangeInCaretContainerBlock = function(range2) {
  3137. return isCaretContainerBlock$1(range2.startContainer);
  3138. };
  3139. var isContentEditableTrue$3 = isContentEditableTrue$4;
  3140. var isContentEditableFalse$a = isContentEditableFalse$b;
  3141. var isBr$3 = isBr$5;
  3142. var isText$5 = isText$7;
  3143. var isInvalidTextElement = matchNodeNames([
  3144. "script",
  3145. "style",
  3146. "textarea"
  3147. ]);
  3148. var isAtomicInline = matchNodeNames([
  3149. "img",
  3150. "input",
  3151. "textarea",
  3152. "hr",
  3153. "iframe",
  3154. "video",
  3155. "audio",
  3156. "object",
  3157. "embed"
  3158. ]);
  3159. var isTable$1 = matchNodeNames(["table"]);
  3160. var isCaretContainer$1 = isCaretContainer$2;
  3161. var isCaretCandidate$3 = function(node) {
  3162. if (isCaretContainer$1(node)) {
  3163. return false;
  3164. }
  3165. if (isText$5(node)) {
  3166. return !isInvalidTextElement(node.parentNode);
  3167. }
  3168. return isAtomicInline(node) || isBr$3(node) || isTable$1(node) || isNonUiContentEditableFalse(node);
  3169. };
  3170. var isUnselectable = function(node) {
  3171. return isElement$5(node) && node.getAttribute("unselectable") === "true";
  3172. };
  3173. var isNonUiContentEditableFalse = function(node) {
  3174. return isUnselectable(node) === false && isContentEditableFalse$a(node);
  3175. };
  3176. var isInEditable = function(node, root) {
  3177. for (node = node.parentNode; node && node !== root; node = node.parentNode) {
  3178. if (isNonUiContentEditableFalse(node)) {
  3179. return false;
  3180. }
  3181. if (isContentEditableTrue$3(node)) {
  3182. return true;
  3183. }
  3184. }
  3185. return true;
  3186. };
  3187. var isAtomicContentEditableFalse = function(node) {
  3188. if (!isNonUiContentEditableFalse(node)) {
  3189. return false;
  3190. }
  3191. return foldl(from(node.getElementsByTagName("*")), function(result, elm) {
  3192. return result || isContentEditableTrue$3(elm);
  3193. }, false) !== true;
  3194. };
  3195. var isAtomic$1 = function(node) {
  3196. return isAtomicInline(node) || isAtomicContentEditableFalse(node);
  3197. };
  3198. var isEditableCaretCandidate$1 = function(node, root) {
  3199. return isCaretCandidate$3(node) && isInEditable(node, root);
  3200. };
  3201. var whiteSpaceRegExp$1 = /^[ \t\r\n]*$/;
  3202. var isWhitespaceText = function(text) {
  3203. return whiteSpaceRegExp$1.test(text);
  3204. };
  3205. var hasWhitespacePreserveParent = function(node, rootNode) {
  3206. var rootElement = SugarElement.fromDom(rootNode);
  3207. var startNode = SugarElement.fromDom(node);
  3208. return ancestor$1(startNode, "pre,code", curry(eq, rootElement));
  3209. };
  3210. var isWhitespace = function(node, rootNode) {
  3211. return isText$7(node) && isWhitespaceText(node.data) && hasWhitespacePreserveParent(node, rootNode) === false;
  3212. };
  3213. var isNamedAnchor = function(node) {
  3214. return isElement$5(node) && node.nodeName === "A" && !node.hasAttribute("href") && (node.hasAttribute("name") || node.hasAttribute("id"));
  3215. };
  3216. var isContent$1 = function(node, rootNode) {
  3217. return isCaretCandidate$3(node) && isWhitespace(node, rootNode) === false || isNamedAnchor(node) || isBookmark(node);
  3218. };
  3219. var isBookmark = hasAttribute("data-mce-bookmark");
  3220. var isBogus$1 = hasAttribute("data-mce-bogus");
  3221. var isBogusAll = hasAttributeValue("data-mce-bogus", "all");
  3222. var isEmptyNode = function(targetNode, skipBogus) {
  3223. var brCount = 0;
  3224. if (isContent$1(targetNode, targetNode)) {
  3225. return false;
  3226. } else {
  3227. var node = targetNode.firstChild;
  3228. if (!node) {
  3229. return true;
  3230. }
  3231. var walker = new DomTreeWalker(node, targetNode);
  3232. do {
  3233. if (skipBogus) {
  3234. if (isBogusAll(node)) {
  3235. node = walker.next(true);
  3236. continue;
  3237. }
  3238. if (isBogus$1(node)) {
  3239. node = walker.next();
  3240. continue;
  3241. }
  3242. }
  3243. if (isBr$5(node)) {
  3244. brCount++;
  3245. node = walker.next();
  3246. continue;
  3247. }
  3248. if (isContent$1(node, targetNode)) {
  3249. return false;
  3250. }
  3251. node = walker.next();
  3252. } while (node);
  3253. return brCount <= 1;
  3254. }
  3255. };
  3256. var isEmpty$2 = function(elm, skipBogus) {
  3257. if (skipBogus === void 0) {
  3258. skipBogus = true;
  3259. }
  3260. return isEmptyNode(elm.dom, skipBogus);
  3261. };
  3262. var isSpan = function(node) {
  3263. return node.nodeName.toLowerCase() === "span";
  3264. };
  3265. var isInlineContent = function(node, root) {
  3266. return isNonNullable(node) && (isContent$1(node, root) || isInline$1(SugarElement.fromDom(node)));
  3267. };
  3268. var surroundedByInlineContent = function(node, root) {
  3269. var prev = new DomTreeWalker(node, root).prev(false);
  3270. var next = new DomTreeWalker(node, root).next(false);
  3271. var prevIsInline = isUndefined(prev) || isInlineContent(prev, root);
  3272. var nextIsInline = isUndefined(next) || isInlineContent(next, root);
  3273. return prevIsInline && nextIsInline;
  3274. };
  3275. var isBookmarkNode$2 = function(node) {
  3276. return isSpan(node) && node.getAttribute("data-mce-type") === "bookmark";
  3277. };
  3278. var isKeepTextNode = function(node, root) {
  3279. return isText$7(node) && node.data.length > 0 && surroundedByInlineContent(node, root);
  3280. };
  3281. var isKeepElement = function(node) {
  3282. return isElement$5(node) ? node.childNodes.length > 0 : false;
  3283. };
  3284. var isDocument = function(node) {
  3285. return isDocumentFragment(node) || isDocument$1(node);
  3286. };
  3287. var trimNode = function(dom2, node, root) {
  3288. var rootNode = root || node;
  3289. if (isElement$5(node) && isBookmarkNode$2(node)) {
  3290. return node;
  3291. }
  3292. var children2 = node.childNodes;
  3293. for (var i = children2.length - 1; i >= 0; i--) {
  3294. trimNode(dom2, children2[i], rootNode);
  3295. }
  3296. if (isElement$5(node)) {
  3297. var currentChildren = node.childNodes;
  3298. if (currentChildren.length === 1 && isBookmarkNode$2(currentChildren[0])) {
  3299. node.parentNode.insertBefore(currentChildren[0], node);
  3300. }
  3301. }
  3302. if (!isDocument(node) && !isContent$1(node, rootNode) && !isKeepElement(node) && !isKeepTextNode(node, rootNode)) {
  3303. dom2.remove(node);
  3304. }
  3305. return node;
  3306. };
  3307. var makeMap$3 = Tools.makeMap;
  3308. var attrsCharsRegExp = /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  3309. var textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  3310. var rawCharsRegExp = /[<>&\"\']/g;
  3311. var entityRegExp = /&#([a-z0-9]+);?|&([a-z0-9]+);/gi;
  3312. var asciiMap = {
  3313. 128: "\u20AC",
  3314. 130: "\u201A",
  3315. 131: "\u0192",
  3316. 132: "\u201E",
  3317. 133: "\u2026",
  3318. 134: "\u2020",
  3319. 135: "\u2021",
  3320. 136: "\u02C6",
  3321. 137: "\u2030",
  3322. 138: "\u0160",
  3323. 139: "\u2039",
  3324. 140: "\u0152",
  3325. 142: "\u017D",
  3326. 145: "\u2018",
  3327. 146: "\u2019",
  3328. 147: "\u201C",
  3329. 148: "\u201D",
  3330. 149: "\u2022",
  3331. 150: "\u2013",
  3332. 151: "\u2014",
  3333. 152: "\u02DC",
  3334. 153: "\u2122",
  3335. 154: "\u0161",
  3336. 155: "\u203A",
  3337. 156: "\u0153",
  3338. 158: "\u017E",
  3339. 159: "\u0178"
  3340. };
  3341. var baseEntities = {
  3342. '"': "&quot;",
  3343. "'": "&#39;",
  3344. "<": "&lt;",
  3345. ">": "&gt;",
  3346. "&": "&amp;",
  3347. "`": "&#96;"
  3348. };
  3349. var reverseEntities = {
  3350. "&lt;": "<",
  3351. "&gt;": ">",
  3352. "&amp;": "&",
  3353. "&quot;": '"',
  3354. "&apos;": "'"
  3355. };
  3356. var nativeDecode = function(text) {
  3357. var elm = SugarElement.fromTag("div").dom;
  3358. elm.innerHTML = text;
  3359. return elm.textContent || elm.innerText || text;
  3360. };
  3361. var buildEntitiesLookup = function(items, radix) {
  3362. var i, chr, entity;
  3363. var lookup = {};
  3364. if (items) {
  3365. items = items.split(",");
  3366. radix = radix || 10;
  3367. for (i = 0; i < items.length; i += 2) {
  3368. chr = String.fromCharCode(parseInt(items[i], radix));
  3369. if (!baseEntities[chr]) {
  3370. entity = "&" + items[i + 1] + ";";
  3371. lookup[chr] = entity;
  3372. lookup[entity] = chr;
  3373. }
  3374. }
  3375. return lookup;
  3376. }
  3377. };
  3378. var 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);
  3379. var encodeRaw = function(text, attr) {
  3380. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  3381. return baseEntities[chr] || chr;
  3382. });
  3383. };
  3384. var encodeAllRaw = function(text) {
  3385. return ("" + text).replace(rawCharsRegExp, function(chr) {
  3386. return baseEntities[chr] || chr;
  3387. });
  3388. };
  3389. var encodeNumeric = function(text, attr) {
  3390. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  3391. if (chr.length > 1) {
  3392. return "&#" + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ";";
  3393. }
  3394. return baseEntities[chr] || "&#" + chr.charCodeAt(0) + ";";
  3395. });
  3396. };
  3397. var encodeNamed = function(text, attr, entities) {
  3398. entities = entities || namedEntities;
  3399. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  3400. return baseEntities[chr] || entities[chr] || chr;
  3401. });
  3402. };
  3403. var getEncodeFunc = function(name2, entities) {
  3404. var entitiesMap = buildEntitiesLookup(entities) || namedEntities;
  3405. var encodeNamedAndNumeric = function(text, attr) {
  3406. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  3407. if (baseEntities[chr] !== void 0) {
  3408. return baseEntities[chr];
  3409. }
  3410. if (entitiesMap[chr] !== void 0) {
  3411. return entitiesMap[chr];
  3412. }
  3413. if (chr.length > 1) {
  3414. return "&#" + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ";";
  3415. }
  3416. return "&#" + chr.charCodeAt(0) + ";";
  3417. });
  3418. };
  3419. var encodeCustomNamed = function(text, attr) {
  3420. return encodeNamed(text, attr, entitiesMap);
  3421. };
  3422. var nameMap = makeMap$3(name2.replace(/\+/g, ","));
  3423. if (nameMap.named && nameMap.numeric) {
  3424. return encodeNamedAndNumeric;
  3425. }
  3426. if (nameMap.named) {
  3427. if (entities) {
  3428. return encodeCustomNamed;
  3429. }
  3430. return encodeNamed;
  3431. }
  3432. if (nameMap.numeric) {
  3433. return encodeNumeric;
  3434. }
  3435. return encodeRaw;
  3436. };
  3437. var decode = function(text) {
  3438. return text.replace(entityRegExp, function(all2, numeric) {
  3439. if (numeric) {
  3440. if (numeric.charAt(0).toLowerCase() === "x") {
  3441. numeric = parseInt(numeric.substr(1), 16);
  3442. } else {
  3443. numeric = parseInt(numeric, 10);
  3444. }
  3445. if (numeric > 65535) {
  3446. numeric -= 65536;
  3447. return String.fromCharCode(55296 + (numeric >> 10), 56320 + (numeric & 1023));
  3448. }
  3449. return asciiMap[numeric] || String.fromCharCode(numeric);
  3450. }
  3451. return reverseEntities[all2] || namedEntities[all2] || nativeDecode(all2);
  3452. });
  3453. };
  3454. var Entities = {
  3455. encodeRaw,
  3456. encodeAllRaw,
  3457. encodeNumeric,
  3458. encodeNamed,
  3459. getEncodeFunc,
  3460. decode
  3461. };
  3462. var mapCache = {}, dummyObj = {};
  3463. var makeMap$2 = Tools.makeMap, each$h = Tools.each, extend$5 = Tools.extend, explode$3 = Tools.explode, inArray$2 = Tools.inArray;
  3464. var split$1 = function(items, delim) {
  3465. items = Tools.trim(items);
  3466. return items ? items.split(delim || " ") : [];
  3467. };
  3468. var createMap = function(defaultValue, extendWith) {
  3469. var value2 = makeMap$2(defaultValue, " ", makeMap$2(defaultValue.toUpperCase(), " "));
  3470. return extend$5(value2, extendWith);
  3471. };
  3472. var getTextRootBlockElements = function(schema) {
  3473. return createMap("td th li dt dd figcaption caption details summary", schema.getTextBlockElements());
  3474. };
  3475. var compileSchema = function(type2) {
  3476. var schema = {};
  3477. var globalAttributes, blockContent;
  3478. var phrasingContent, flowContent, html4BlockContent, html4PhrasingContent;
  3479. var add2 = function(name2, attributes2, children2) {
  3480. var ni, attributesOrder, element;
  3481. var arrayToMap = function(array, obj) {
  3482. var map2 = {};
  3483. var i, l;
  3484. for (i = 0, l = array.length; i < l; i++) {
  3485. map2[array[i]] = obj || {};
  3486. }
  3487. return map2;
  3488. };
  3489. children2 = children2 || [];
  3490. attributes2 = attributes2 || "";
  3491. if (typeof children2 === "string") {
  3492. children2 = split$1(children2);
  3493. }
  3494. var names = split$1(name2);
  3495. ni = names.length;
  3496. while (ni--) {
  3497. attributesOrder = split$1([
  3498. globalAttributes,
  3499. attributes2
  3500. ].join(" "));
  3501. element = {
  3502. attributes: arrayToMap(attributesOrder),
  3503. attributesOrder,
  3504. children: arrayToMap(children2, dummyObj)
  3505. };
  3506. schema[names[ni]] = element;
  3507. }
  3508. };
  3509. var addAttrs = function(name2, attributes2) {
  3510. var ni, schemaItem, i, l;
  3511. var names = split$1(name2);
  3512. ni = names.length;
  3513. var attrs = split$1(attributes2);
  3514. while (ni--) {
  3515. schemaItem = schema[names[ni]];
  3516. for (i = 0, l = attrs.length; i < l; i++) {
  3517. schemaItem.attributes[attrs[i]] = {};
  3518. schemaItem.attributesOrder.push(attrs[i]);
  3519. }
  3520. }
  3521. };
  3522. if (mapCache[type2]) {
  3523. return mapCache[type2];
  3524. }
  3525. globalAttributes = "id accesskey class dir lang style tabindex title role";
  3526. blockContent = "address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul";
  3527. 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";
  3528. if (type2 !== "html4") {
  3529. globalAttributes += " contenteditable contextmenu draggable dropzone hidden spellcheck translate";
  3530. blockContent += " article aside details dialog figure main header footer hgroup section nav";
  3531. phrasingContent += " audio canvas command datalist mark meter output picture progress time wbr video ruby bdi keygen";
  3532. }
  3533. if (type2 !== "html5-strict") {
  3534. globalAttributes += " xml:lang";
  3535. html4PhrasingContent = "acronym applet basefont big font strike tt";
  3536. phrasingContent = [
  3537. phrasingContent,
  3538. html4PhrasingContent
  3539. ].join(" ");
  3540. each$h(split$1(html4PhrasingContent), function(name2) {
  3541. add2(name2, "", phrasingContent);
  3542. });
  3543. html4BlockContent = "center dir isindex noframes";
  3544. blockContent = [
  3545. blockContent,
  3546. html4BlockContent
  3547. ].join(" ");
  3548. flowContent = [
  3549. blockContent,
  3550. phrasingContent
  3551. ].join(" ");
  3552. each$h(split$1(html4BlockContent), function(name2) {
  3553. add2(name2, "", flowContent);
  3554. });
  3555. }
  3556. flowContent = flowContent || [
  3557. blockContent,
  3558. phrasingContent
  3559. ].join(" ");
  3560. add2("html", "manifest", "head body");
  3561. add2("head", "", "base command link meta noscript script style title");
  3562. add2("title hr noscript br");
  3563. add2("base", "href target");
  3564. add2("link", "href rel media hreflang type sizes hreflang");
  3565. add2("meta", "name http-equiv content charset");
  3566. add2("style", "media type scoped");
  3567. add2("script", "src async defer type charset");
  3568. add2("body", "onafterprint onbeforeprint onbeforeunload onblur onerror onfocus onhashchange onload onmessage onoffline ononline onpagehide onpageshow onpopstate onresize onscroll onstorage onunload", flowContent);
  3569. add2("address dt dd div caption", "", flowContent);
  3570. add2("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);
  3571. add2("blockquote", "cite", flowContent);
  3572. add2("ol", "reversed start type", "li");
  3573. add2("ul", "", "li");
  3574. add2("li", "value", flowContent);
  3575. add2("dl", "", "dt dd");
  3576. add2("a", "href target rel media hreflang type", phrasingContent);
  3577. add2("q", "cite", phrasingContent);
  3578. add2("ins del", "cite datetime", flowContent);
  3579. add2("img", "src sizes srcset alt usemap ismap width height");
  3580. add2("iframe", "src name width height", flowContent);
  3581. add2("embed", "src type width height");
  3582. add2("object", "data type typemustmatch name usemap form width height", [
  3583. flowContent,
  3584. "param"
  3585. ].join(" "));
  3586. add2("param", "name value");
  3587. add2("map", "name", [
  3588. flowContent,
  3589. "area"
  3590. ].join(" "));
  3591. add2("area", "alt coords shape href target rel media hreflang type");
  3592. add2("table", "border", "caption colgroup thead tfoot tbody tr" + (type2 === "html4" ? " col" : ""));
  3593. add2("colgroup", "span", "col");
  3594. add2("col", "span");
  3595. add2("tbody thead tfoot", "", "tr");
  3596. add2("tr", "", "td th");
  3597. add2("td", "colspan rowspan headers", flowContent);
  3598. add2("th", "colspan rowspan headers scope abbr", flowContent);
  3599. add2("form", "accept-charset action autocomplete enctype method name novalidate target", flowContent);
  3600. add2("fieldset", "disabled form name", [
  3601. flowContent,
  3602. "legend"
  3603. ].join(" "));
  3604. add2("label", "form for", phrasingContent);
  3605. add2("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");
  3606. add2("button", "disabled form formaction formenctype formmethod formnovalidate formtarget name type value", type2 === "html4" ? flowContent : phrasingContent);
  3607. add2("select", "disabled form multiple name required size", "option optgroup");
  3608. add2("optgroup", "disabled label", "option");
  3609. add2("option", "disabled label selected value");
  3610. add2("textarea", "cols dirname disabled form maxlength name readonly required rows wrap");
  3611. add2("menu", "type label", [
  3612. flowContent,
  3613. "li"
  3614. ].join(" "));
  3615. add2("noscript", "", flowContent);
  3616. if (type2 !== "html4") {
  3617. add2("wbr");
  3618. add2("ruby", "", [
  3619. phrasingContent,
  3620. "rt rp"
  3621. ].join(" "));
  3622. add2("figcaption", "", flowContent);
  3623. add2("mark rt rp summary bdi", "", phrasingContent);
  3624. add2("canvas", "width height", flowContent);
  3625. add2("video", "src crossorigin poster preload autoplay mediagroup loop muted controls width height buffered", [
  3626. flowContent,
  3627. "track source"
  3628. ].join(" "));
  3629. add2("audio", "src crossorigin preload autoplay mediagroup loop muted controls buffered volume", [
  3630. flowContent,
  3631. "track source"
  3632. ].join(" "));
  3633. add2("picture", "", "img source");
  3634. add2("source", "src srcset type media sizes");
  3635. add2("track", "kind src srclang label default");
  3636. add2("datalist", "", [
  3637. phrasingContent,
  3638. "option"
  3639. ].join(" "));
  3640. add2("article section nav aside main header footer", "", flowContent);
  3641. add2("hgroup", "", "h1 h2 h3 h4 h5 h6");
  3642. add2("figure", "", [
  3643. flowContent,
  3644. "figcaption"
  3645. ].join(" "));
  3646. add2("time", "datetime", phrasingContent);
  3647. add2("dialog", "open", flowContent);
  3648. add2("command", "type label icon disabled checked radiogroup command");
  3649. add2("output", "for form name", phrasingContent);
  3650. add2("progress", "value max", phrasingContent);
  3651. add2("meter", "value min max low high optimum", phrasingContent);
  3652. add2("details", "open", [
  3653. flowContent,
  3654. "summary"
  3655. ].join(" "));
  3656. add2("keygen", "autofocus challenge disabled form keytype name");
  3657. }
  3658. if (type2 !== "html5-strict") {
  3659. addAttrs("script", "language xml:space");
  3660. addAttrs("style", "xml:space");
  3661. addAttrs("object", "declare classid code codebase codetype archive standby align border hspace vspace");
  3662. addAttrs("embed", "align name hspace vspace");
  3663. addAttrs("param", "valuetype type");
  3664. addAttrs("a", "charset name rev shape coords");
  3665. addAttrs("br", "clear");
  3666. addAttrs("applet", "codebase archive code object alt name width height align hspace vspace");
  3667. addAttrs("img", "name longdesc align border hspace vspace");
  3668. addAttrs("iframe", "longdesc frameborder marginwidth marginheight scrolling align");
  3669. addAttrs("font basefont", "size color face");
  3670. addAttrs("input", "usemap align");
  3671. addAttrs("select");
  3672. addAttrs("textarea");
  3673. addAttrs("h1 h2 h3 h4 h5 h6 div p legend caption", "align");
  3674. addAttrs("ul", "type compact");
  3675. addAttrs("li", "type");
  3676. addAttrs("ol dl menu dir", "compact");
  3677. addAttrs("pre", "width xml:space");
  3678. addAttrs("hr", "align noshade size width");
  3679. addAttrs("isindex", "prompt");
  3680. addAttrs("table", "summary width frame rules cellspacing cellpadding align bgcolor");
  3681. addAttrs("col", "width align char charoff valign");
  3682. addAttrs("colgroup", "width align char charoff valign");
  3683. addAttrs("thead", "align char charoff valign");
  3684. addAttrs("tr", "align char charoff valign bgcolor");
  3685. addAttrs("th", "axis align char charoff valign nowrap bgcolor width height");
  3686. addAttrs("form", "accept");
  3687. addAttrs("td", "abbr axis scope align char charoff valign nowrap bgcolor width height");
  3688. addAttrs("tfoot", "align char charoff valign");
  3689. addAttrs("tbody", "align char charoff valign");
  3690. addAttrs("area", "nohref");
  3691. addAttrs("body", "background bgcolor text link vlink alink");
  3692. }
  3693. if (type2 !== "html4") {
  3694. addAttrs("input button select textarea", "autofocus");
  3695. addAttrs("input textarea", "placeholder");
  3696. addAttrs("a", "download");
  3697. addAttrs("link script img", "crossorigin");
  3698. addAttrs("img", "loading");
  3699. addAttrs("iframe", "sandbox seamless allowfullscreen loading");
  3700. }
  3701. each$h(split$1("a form meter progress dfn"), function(name2) {
  3702. if (schema[name2]) {
  3703. delete schema[name2].children[name2];
  3704. }
  3705. });
  3706. delete schema.caption.children.table;
  3707. delete schema.script;
  3708. mapCache[type2] = schema;
  3709. return schema;
  3710. };
  3711. var compileElementMap = function(value2, mode) {
  3712. var styles;
  3713. if (value2) {
  3714. styles = {};
  3715. if (typeof value2 === "string") {
  3716. value2 = { "*": value2 };
  3717. }
  3718. each$h(value2, function(value3, key) {
  3719. styles[key] = styles[key.toUpperCase()] = mode === "map" ? makeMap$2(value3, /[, ]/) : explode$3(value3, /[, ]/);
  3720. });
  3721. }
  3722. return styles;
  3723. };
  3724. var Schema = function(settings) {
  3725. var elements = {};
  3726. var children2 = {};
  3727. var patternElements = [];
  3728. var customElementsMap = {}, specialElements = {};
  3729. var createLookupTable = function(option, defaultValue, extendWith) {
  3730. var value2 = settings[option];
  3731. if (!value2) {
  3732. value2 = mapCache[option];
  3733. if (!value2) {
  3734. value2 = createMap(defaultValue, extendWith);
  3735. mapCache[option] = value2;
  3736. }
  3737. } else {
  3738. value2 = makeMap$2(value2, /[, ]/, makeMap$2(value2.toUpperCase(), /[, ]/));
  3739. }
  3740. return value2;
  3741. };
  3742. settings = settings || {};
  3743. var schemaItems = compileSchema(settings.schema);
  3744. if (settings.verify_html === false) {
  3745. settings.valid_elements = "*[*]";
  3746. }
  3747. var validStyles = compileElementMap(settings.valid_styles);
  3748. var invalidStyles = compileElementMap(settings.invalid_styles, "map");
  3749. var validClasses = compileElementMap(settings.valid_classes, "map");
  3750. var whiteSpaceElementsMap = createLookupTable("whitespace_elements", "pre script noscript style textarea video audio iframe object code");
  3751. var selfClosingElementsMap = createLookupTable("self_closing_elements", "colgroup dd dt li option p td tfoot th thead tr");
  3752. var shortEndedElementsMap = createLookupTable("short_ended_elements", "area base basefont br col frame hr img input isindex link meta param embed source wbr track");
  3753. var boolAttrMap = createLookupTable("boolean_attributes", "checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls");
  3754. var nonEmptyOrMoveCaretBeforeOnEnter = "td th iframe video audio object script code";
  3755. var nonEmptyElementsMap = createLookupTable("non_empty_elements", nonEmptyOrMoveCaretBeforeOnEnter + " pre", shortEndedElementsMap);
  3756. var moveCaretBeforeOnEnterElementsMap = createLookupTable("move_caret_before_on_enter_elements", nonEmptyOrMoveCaretBeforeOnEnter + " table", shortEndedElementsMap);
  3757. var 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");
  3758. var 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);
  3759. var textInlineElementsMap = createLookupTable("text_inline_elements", "span strong b em i font s strike u var cite dfn code mark q sup sub samp");
  3760. each$h((settings.special || "script noscript iframe noframes noembed title style textarea xmp").split(" "), function(name2) {
  3761. specialElements[name2] = new RegExp("</" + name2 + "[^>]*>", "gi");
  3762. });
  3763. var patternToRegExp = function(str) {
  3764. return new RegExp("^" + str.replace(/([?+*])/g, ".$1") + "$");
  3765. };
  3766. var addValidElements = function(validElements) {
  3767. var ei, el, ai, al, matches2, element, attr, attrData, elementName, attrName, attrType, attributes2, attributesOrder, prefix, outputName, globalAttributes, globalAttributesOrder, value2;
  3768. var elementRuleRegExp = /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)])?$/, attrRuleRegExp = /^([!\-])?(\w+[\\:]:\w+|[^=:<]+)?(?:([=:<])(.*))?$/, hasPatternsRegExp = /[*?+]/;
  3769. if (validElements) {
  3770. var validElementsArr = split$1(validElements, ",");
  3771. if (elements["@"]) {
  3772. globalAttributes = elements["@"].attributes;
  3773. globalAttributesOrder = elements["@"].attributesOrder;
  3774. }
  3775. for (ei = 0, el = validElementsArr.length; ei < el; ei++) {
  3776. matches2 = elementRuleRegExp.exec(validElementsArr[ei]);
  3777. if (matches2) {
  3778. prefix = matches2[1];
  3779. elementName = matches2[2];
  3780. outputName = matches2[3];
  3781. attrData = matches2[5];
  3782. attributes2 = {};
  3783. attributesOrder = [];
  3784. element = {
  3785. attributes: attributes2,
  3786. attributesOrder
  3787. };
  3788. if (prefix === "#") {
  3789. element.paddEmpty = true;
  3790. }
  3791. if (prefix === "-") {
  3792. element.removeEmpty = true;
  3793. }
  3794. if (matches2[4] === "!") {
  3795. element.removeEmptyAttrs = true;
  3796. }
  3797. if (globalAttributes) {
  3798. each$j(globalAttributes, function(value3, key) {
  3799. attributes2[key] = value3;
  3800. });
  3801. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  3802. }
  3803. if (attrData) {
  3804. attrData = split$1(attrData, "|");
  3805. for (ai = 0, al = attrData.length; ai < al; ai++) {
  3806. matches2 = attrRuleRegExp.exec(attrData[ai]);
  3807. if (matches2) {
  3808. attr = {};
  3809. attrType = matches2[1];
  3810. attrName = matches2[2].replace(/[\\:]:/g, ":");
  3811. prefix = matches2[3];
  3812. value2 = matches2[4];
  3813. if (attrType === "!") {
  3814. element.attributesRequired = element.attributesRequired || [];
  3815. element.attributesRequired.push(attrName);
  3816. attr.required = true;
  3817. }
  3818. if (attrType === "-") {
  3819. delete attributes2[attrName];
  3820. attributesOrder.splice(inArray$2(attributesOrder, attrName), 1);
  3821. continue;
  3822. }
  3823. if (prefix) {
  3824. if (prefix === "=") {
  3825. element.attributesDefault = element.attributesDefault || [];
  3826. element.attributesDefault.push({
  3827. name: attrName,
  3828. value: value2
  3829. });
  3830. attr.defaultValue = value2;
  3831. }
  3832. if (prefix === ":") {
  3833. element.attributesForced = element.attributesForced || [];
  3834. element.attributesForced.push({
  3835. name: attrName,
  3836. value: value2
  3837. });
  3838. attr.forcedValue = value2;
  3839. }
  3840. if (prefix === "<") {
  3841. attr.validValues = makeMap$2(value2, "?");
  3842. }
  3843. }
  3844. if (hasPatternsRegExp.test(attrName)) {
  3845. element.attributePatterns = element.attributePatterns || [];
  3846. attr.pattern = patternToRegExp(attrName);
  3847. element.attributePatterns.push(attr);
  3848. } else {
  3849. if (!attributes2[attrName]) {
  3850. attributesOrder.push(attrName);
  3851. }
  3852. attributes2[attrName] = attr;
  3853. }
  3854. }
  3855. }
  3856. }
  3857. if (!globalAttributes && elementName === "@") {
  3858. globalAttributes = attributes2;
  3859. globalAttributesOrder = attributesOrder;
  3860. }
  3861. if (outputName) {
  3862. element.outputName = elementName;
  3863. elements[outputName] = element;
  3864. }
  3865. if (hasPatternsRegExp.test(elementName)) {
  3866. element.pattern = patternToRegExp(elementName);
  3867. patternElements.push(element);
  3868. } else {
  3869. elements[elementName] = element;
  3870. }
  3871. }
  3872. }
  3873. }
  3874. };
  3875. var setValidElements = function(validElements) {
  3876. elements = {};
  3877. patternElements = [];
  3878. addValidElements(validElements);
  3879. each$h(schemaItems, function(element, name2) {
  3880. children2[name2] = element.children;
  3881. });
  3882. };
  3883. var addCustomElements = function(customElements) {
  3884. var customElementRegExp = /^(~)?(.+)$/;
  3885. if (customElements) {
  3886. mapCache.text_block_elements = mapCache.block_elements = null;
  3887. each$h(split$1(customElements, ","), function(rule) {
  3888. var matches2 = customElementRegExp.exec(rule), inline = matches2[1] === "~", cloneName = inline ? "span" : "div", name2 = matches2[2];
  3889. children2[name2] = children2[cloneName];
  3890. customElementsMap[name2] = cloneName;
  3891. if (!inline) {
  3892. blockElementsMap[name2.toUpperCase()] = {};
  3893. blockElementsMap[name2] = {};
  3894. }
  3895. if (!elements[name2]) {
  3896. var customRule = elements[cloneName];
  3897. customRule = extend$5({}, customRule);
  3898. delete customRule.removeEmptyAttrs;
  3899. delete customRule.removeEmpty;
  3900. elements[name2] = customRule;
  3901. }
  3902. each$h(children2, function(element, elmName) {
  3903. if (element[cloneName]) {
  3904. children2[elmName] = element = extend$5({}, children2[elmName]);
  3905. element[name2] = element[cloneName];
  3906. }
  3907. });
  3908. });
  3909. }
  3910. };
  3911. var addValidChildren = function(validChildren) {
  3912. var childRuleRegExp = /^([+\-]?)([A-Za-z0-9_\-.\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]+)\[([^\]]+)]$/;
  3913. mapCache[settings.schema] = null;
  3914. if (validChildren) {
  3915. each$h(split$1(validChildren, ","), function(rule) {
  3916. var matches2 = childRuleRegExp.exec(rule);
  3917. var parent2, prefix;
  3918. if (matches2) {
  3919. prefix = matches2[1];
  3920. if (prefix) {
  3921. parent2 = children2[matches2[2]];
  3922. } else {
  3923. parent2 = children2[matches2[2]] = { "#comment": {} };
  3924. }
  3925. parent2 = children2[matches2[2]];
  3926. each$h(split$1(matches2[3], "|"), function(child2) {
  3927. if (prefix === "-") {
  3928. delete parent2[child2];
  3929. } else {
  3930. parent2[child2] = {};
  3931. }
  3932. });
  3933. }
  3934. });
  3935. }
  3936. };
  3937. var getElementRule = function(name2) {
  3938. var element = elements[name2], i;
  3939. if (element) {
  3940. return element;
  3941. }
  3942. i = patternElements.length;
  3943. while (i--) {
  3944. element = patternElements[i];
  3945. if (element.pattern.test(name2)) {
  3946. return element;
  3947. }
  3948. }
  3949. };
  3950. if (!settings.valid_elements) {
  3951. each$h(schemaItems, function(element, name2) {
  3952. elements[name2] = {
  3953. attributes: element.attributes,
  3954. attributesOrder: element.attributesOrder
  3955. };
  3956. children2[name2] = element.children;
  3957. });
  3958. if (settings.schema !== "html5") {
  3959. each$h(split$1("strong/b em/i"), function(item) {
  3960. var items = split$1(item, "/");
  3961. elements[items[1]].outputName = items[0];
  3962. });
  3963. }
  3964. each$h(textInlineElementsMap, function(_val, name2) {
  3965. if (elements[name2]) {
  3966. if (settings.padd_empty_block_inline_children) {
  3967. elements[name2].paddInEmptyBlock = true;
  3968. }
  3969. elements[name2].removeEmpty = true;
  3970. }
  3971. });
  3972. each$h(split$1("ol ul blockquote a table tbody"), function(name2) {
  3973. if (elements[name2]) {
  3974. elements[name2].removeEmpty = true;
  3975. }
  3976. });
  3977. each$h(split$1("p h1 h2 h3 h4 h5 h6 th td pre div address caption li"), function(name2) {
  3978. elements[name2].paddEmpty = true;
  3979. });
  3980. each$h(split$1("span"), function(name2) {
  3981. elements[name2].removeEmptyAttrs = true;
  3982. });
  3983. } else {
  3984. setValidElements(settings.valid_elements);
  3985. }
  3986. addCustomElements(settings.custom_elements);
  3987. addValidChildren(settings.valid_children);
  3988. addValidElements(settings.extended_valid_elements);
  3989. addValidChildren("+ol[ul|ol],+ul[ul|ol]");
  3990. each$h({
  3991. dd: "dl",
  3992. dt: "dl",
  3993. li: "ul ol",
  3994. td: "tr",
  3995. th: "tr",
  3996. tr: "tbody thead tfoot",
  3997. tbody: "table",
  3998. thead: "table",
  3999. tfoot: "table",
  4000. legend: "fieldset",
  4001. area: "map",
  4002. param: "video audio object"
  4003. }, function(parents2, item) {
  4004. if (elements[item]) {
  4005. elements[item].parentsRequired = split$1(parents2);
  4006. }
  4007. });
  4008. if (settings.invalid_elements) {
  4009. each$h(explode$3(settings.invalid_elements), function(item) {
  4010. if (elements[item]) {
  4011. delete elements[item];
  4012. }
  4013. });
  4014. }
  4015. if (!getElementRule("span")) {
  4016. addValidElements("span[!data-mce-type|*]");
  4017. }
  4018. var getValidStyles = constant(validStyles);
  4019. var getInvalidStyles = constant(invalidStyles);
  4020. var getValidClasses = constant(validClasses);
  4021. var getBoolAttrs = constant(boolAttrMap);
  4022. var getBlockElements = constant(blockElementsMap);
  4023. var getTextBlockElements = constant(textBlockElementsMap);
  4024. var getTextInlineElements = constant(textInlineElementsMap);
  4025. var getShortEndedElements = constant(shortEndedElementsMap);
  4026. var getSelfClosingElements = constant(selfClosingElementsMap);
  4027. var getNonEmptyElements = constant(nonEmptyElementsMap);
  4028. var getMoveCaretBeforeOnEnterElements = constant(moveCaretBeforeOnEnterElementsMap);
  4029. var getWhiteSpaceElements = constant(whiteSpaceElementsMap);
  4030. var getSpecialElements = constant(specialElements);
  4031. var isValidChild = function(name2, child2) {
  4032. var parent2 = children2[name2.toLowerCase()];
  4033. return !!(parent2 && parent2[child2.toLowerCase()]);
  4034. };
  4035. var isValid2 = function(name2, attr) {
  4036. var attrPatterns, i;
  4037. var rule = getElementRule(name2);
  4038. if (rule) {
  4039. if (attr) {
  4040. if (rule.attributes[attr]) {
  4041. return true;
  4042. }
  4043. attrPatterns = rule.attributePatterns;
  4044. if (attrPatterns) {
  4045. i = attrPatterns.length;
  4046. while (i--) {
  4047. if (attrPatterns[i].pattern.test(name2)) {
  4048. return true;
  4049. }
  4050. }
  4051. }
  4052. } else {
  4053. return true;
  4054. }
  4055. }
  4056. return false;
  4057. };
  4058. var getCustomElements = constant(customElementsMap);
  4059. return {
  4060. children: children2,
  4061. elements,
  4062. getValidStyles,
  4063. getValidClasses,
  4064. getBlockElements,
  4065. getInvalidStyles,
  4066. getShortEndedElements,
  4067. getTextBlockElements,
  4068. getTextInlineElements,
  4069. getBoolAttrs,
  4070. getElementRule,
  4071. getSelfClosingElements,
  4072. getNonEmptyElements,
  4073. getMoveCaretBeforeOnEnterElements,
  4074. getWhiteSpaceElements,
  4075. getSpecialElements,
  4076. isValidChild,
  4077. isValid: isValid2,
  4078. getCustomElements,
  4079. addValidElements,
  4080. setValidElements,
  4081. addCustomElements,
  4082. addValidChildren
  4083. };
  4084. };
  4085. var toHex = function(match2, r2, g, b) {
  4086. var hex = function(val) {
  4087. val = parseInt(val, 10).toString(16);
  4088. return val.length > 1 ? val : "0" + val;
  4089. };
  4090. return "#" + hex(r2) + hex(g) + hex(b);
  4091. };
  4092. var Styles = function(settings, schema) {
  4093. var _this = this;
  4094. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi;
  4095. var urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi;
  4096. var styleRegExp = /\s*([^:]+):\s*([^;]+);?/g;
  4097. var trimRightRegExp = /\s+$/;
  4098. var i;
  4099. var encodingLookup = {};
  4100. var validStyles;
  4101. var invalidStyles;
  4102. var invisibleChar = zeroWidth;
  4103. settings = settings || {};
  4104. if (schema) {
  4105. validStyles = schema.getValidStyles();
  4106. invalidStyles = schema.getInvalidStyles();
  4107. }
  4108. var encodingItems = (`\\" \\' \\; \\: ; : ` + invisibleChar).split(" ");
  4109. for (i = 0; i < encodingItems.length; i++) {
  4110. encodingLookup[encodingItems[i]] = invisibleChar + i;
  4111. encodingLookup[invisibleChar + i] = encodingItems[i];
  4112. }
  4113. return {
  4114. toHex: function(color) {
  4115. return color.replace(rgbRegExp, toHex);
  4116. },
  4117. parse: function(css) {
  4118. var styles = {};
  4119. var matches2, name2, value2, isEncoded;
  4120. var urlConverter = settings.url_converter;
  4121. var urlConverterScope = settings.url_converter_scope || _this;
  4122. var compress = function(prefix, suffix, noJoin) {
  4123. var top = styles[prefix + "-top" + suffix];
  4124. if (!top) {
  4125. return;
  4126. }
  4127. var right = styles[prefix + "-right" + suffix];
  4128. if (!right) {
  4129. return;
  4130. }
  4131. var bottom = styles[prefix + "-bottom" + suffix];
  4132. if (!bottom) {
  4133. return;
  4134. }
  4135. var left = styles[prefix + "-left" + suffix];
  4136. if (!left) {
  4137. return;
  4138. }
  4139. var box = [
  4140. top,
  4141. right,
  4142. bottom,
  4143. left
  4144. ];
  4145. i = box.length - 1;
  4146. while (i--) {
  4147. if (box[i] !== box[i + 1]) {
  4148. break;
  4149. }
  4150. }
  4151. if (i > -1 && noJoin) {
  4152. return;
  4153. }
  4154. styles[prefix + suffix] = i === -1 ? box[0] : box.join(" ");
  4155. delete styles[prefix + "-top" + suffix];
  4156. delete styles[prefix + "-right" + suffix];
  4157. delete styles[prefix + "-bottom" + suffix];
  4158. delete styles[prefix + "-left" + suffix];
  4159. };
  4160. var canCompress = function(key) {
  4161. var value3 = styles[key], i2;
  4162. if (!value3) {
  4163. return;
  4164. }
  4165. value3 = value3.split(" ");
  4166. i2 = value3.length;
  4167. while (i2--) {
  4168. if (value3[i2] !== value3[0]) {
  4169. return false;
  4170. }
  4171. }
  4172. styles[key] = value3[0];
  4173. return true;
  4174. };
  4175. var compress2 = function(target, a, b, c) {
  4176. if (!canCompress(a)) {
  4177. return;
  4178. }
  4179. if (!canCompress(b)) {
  4180. return;
  4181. }
  4182. if (!canCompress(c)) {
  4183. return;
  4184. }
  4185. styles[target] = styles[a] + " " + styles[b] + " " + styles[c];
  4186. delete styles[a];
  4187. delete styles[b];
  4188. delete styles[c];
  4189. };
  4190. var encode = function(str) {
  4191. isEncoded = true;
  4192. return encodingLookup[str];
  4193. };
  4194. var decode2 = function(str, keepSlashes) {
  4195. if (isEncoded) {
  4196. str = str.replace(/\uFEFF[0-9]/g, function(str2) {
  4197. return encodingLookup[str2];
  4198. });
  4199. }
  4200. if (!keepSlashes) {
  4201. str = str.replace(/\\([\'\";:])/g, "$1");
  4202. }
  4203. return str;
  4204. };
  4205. var decodeSingleHexSequence = function(escSeq) {
  4206. return String.fromCharCode(parseInt(escSeq.slice(1), 16));
  4207. };
  4208. var decodeHexSequences = function(value3) {
  4209. return value3.replace(/\\[0-9a-f]+/gi, decodeSingleHexSequence);
  4210. };
  4211. var processUrl = function(match2, url, url2, url3, str, str2) {
  4212. str = str || str2;
  4213. if (str) {
  4214. str = decode2(str);
  4215. return "'" + str.replace(/\'/g, "\\'") + "'";
  4216. }
  4217. url = decode2(url || url2 || url3);
  4218. if (!settings.allow_script_urls) {
  4219. var scriptUrl = url.replace(/[\s\r\n]+/g, "");
  4220. if (/(java|vb)script:/i.test(scriptUrl)) {
  4221. return "";
  4222. }
  4223. if (!settings.allow_svg_data_urls && /^data:image\/svg/i.test(scriptUrl)) {
  4224. return "";
  4225. }
  4226. }
  4227. if (urlConverter) {
  4228. url = urlConverter.call(urlConverterScope, url, "style");
  4229. }
  4230. return "url('" + url.replace(/\'/g, "\\'") + "')";
  4231. };
  4232. if (css) {
  4233. css = css.replace(/[\u0000-\u001F]/g, "");
  4234. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  4235. return str.replace(/[;:]/g, encode);
  4236. });
  4237. while (matches2 = styleRegExp.exec(css)) {
  4238. styleRegExp.lastIndex = matches2.index + matches2[0].length;
  4239. name2 = matches2[1].replace(trimRightRegExp, "").toLowerCase();
  4240. value2 = matches2[2].replace(trimRightRegExp, "");
  4241. if (name2 && value2) {
  4242. name2 = decodeHexSequences(name2);
  4243. value2 = decodeHexSequences(value2);
  4244. if (name2.indexOf(invisibleChar) !== -1 || name2.indexOf('"') !== -1) {
  4245. continue;
  4246. }
  4247. if (!settings.allow_script_urls && (name2 === "behavior" || /expression\s*\(|\/\*|\*\//.test(value2))) {
  4248. continue;
  4249. }
  4250. if (name2 === "font-weight" && value2 === "700") {
  4251. value2 = "bold";
  4252. } else if (name2 === "color" || name2 === "background-color") {
  4253. value2 = value2.toLowerCase();
  4254. }
  4255. value2 = value2.replace(rgbRegExp, toHex);
  4256. value2 = value2.replace(urlOrStrRegExp, processUrl);
  4257. styles[name2] = isEncoded ? decode2(value2, true) : value2;
  4258. }
  4259. }
  4260. compress("border", "", true);
  4261. compress("border", "-width");
  4262. compress("border", "-color");
  4263. compress("border", "-style");
  4264. compress("padding", "");
  4265. compress("margin", "");
  4266. compress2("border", "border-width", "border-style", "border-color");
  4267. if (styles.border === "medium none") {
  4268. delete styles.border;
  4269. }
  4270. if (styles["border-image"] === "none") {
  4271. delete styles["border-image"];
  4272. }
  4273. }
  4274. return styles;
  4275. },
  4276. serialize: function(styles, elementName) {
  4277. var css = "";
  4278. var serializeStyles = function(name2) {
  4279. var value2;
  4280. var styleList = validStyles[name2];
  4281. if (styleList) {
  4282. for (var i_1 = 0, l = styleList.length; i_1 < l; i_1++) {
  4283. name2 = styleList[i_1];
  4284. value2 = styles[name2];
  4285. if (value2) {
  4286. css += (css.length > 0 ? " " : "") + name2 + ": " + value2 + ";";
  4287. }
  4288. }
  4289. }
  4290. };
  4291. var isValid2 = function(name2, elementName2) {
  4292. var styleMap = invalidStyles["*"];
  4293. if (styleMap && styleMap[name2]) {
  4294. return false;
  4295. }
  4296. styleMap = invalidStyles[elementName2];
  4297. return !(styleMap && styleMap[name2]);
  4298. };
  4299. if (elementName && validStyles) {
  4300. serializeStyles("*");
  4301. serializeStyles(elementName);
  4302. } else {
  4303. each$j(styles, function(value2, name2) {
  4304. if (value2 && (!invalidStyles || isValid2(name2, elementName))) {
  4305. css += (css.length > 0 ? " " : "") + name2 + ": " + value2 + ";";
  4306. }
  4307. });
  4308. }
  4309. return css;
  4310. }
  4311. };
  4312. };
  4313. var deprecated = {
  4314. keyLocation: true,
  4315. layerX: true,
  4316. layerY: true,
  4317. returnValue: true,
  4318. webkitMovementX: true,
  4319. webkitMovementY: true,
  4320. keyIdentifier: true,
  4321. mozPressure: true
  4322. };
  4323. var isNativeEvent = function(event) {
  4324. return event instanceof Event || isFunction(event.initEvent);
  4325. };
  4326. var hasIsDefaultPrevented = function(event) {
  4327. return event.isDefaultPrevented === always || event.isDefaultPrevented === never;
  4328. };
  4329. var needsNormalizing = function(event) {
  4330. return isNullable(event.preventDefault) || isNativeEvent(event);
  4331. };
  4332. var clone$2 = function(originalEvent, data2) {
  4333. var event = data2 !== null && data2 !== void 0 ? data2 : {};
  4334. for (var name_1 in originalEvent) {
  4335. if (!has$2(deprecated, name_1)) {
  4336. event[name_1] = originalEvent[name_1];
  4337. }
  4338. }
  4339. if (isNonNullable(event.composedPath)) {
  4340. event.composedPath = function() {
  4341. return originalEvent.composedPath();
  4342. };
  4343. }
  4344. return event;
  4345. };
  4346. var normalize$3 = function(type2, originalEvent, fallbackTarget, data2) {
  4347. var _a;
  4348. var event = clone$2(originalEvent, data2);
  4349. event.type = type2;
  4350. if (isNullable(event.target)) {
  4351. event.target = (_a = event.srcElement) !== null && _a !== void 0 ? _a : fallbackTarget;
  4352. }
  4353. if (needsNormalizing(originalEvent)) {
  4354. event.preventDefault = function() {
  4355. event.defaultPrevented = true;
  4356. event.isDefaultPrevented = always;
  4357. if (isFunction(originalEvent.preventDefault)) {
  4358. originalEvent.preventDefault();
  4359. } else if (isNativeEvent(originalEvent)) {
  4360. originalEvent.returnValue = false;
  4361. }
  4362. };
  4363. event.stopPropagation = function() {
  4364. event.cancelBubble = true;
  4365. event.isPropagationStopped = always;
  4366. if (isFunction(originalEvent.stopPropagation)) {
  4367. originalEvent.stopPropagation();
  4368. } else if (isNativeEvent(originalEvent)) {
  4369. originalEvent.cancelBubble = true;
  4370. }
  4371. };
  4372. event.stopImmediatePropagation = function() {
  4373. event.isImmediatePropagationStopped = always;
  4374. event.stopPropagation();
  4375. };
  4376. if (!hasIsDefaultPrevented(event)) {
  4377. event.isDefaultPrevented = event.defaultPrevented === true ? always : never;
  4378. event.isPropagationStopped = event.cancelBubble === true ? always : never;
  4379. event.isImmediatePropagationStopped = never;
  4380. }
  4381. }
  4382. return event;
  4383. };
  4384. var eventExpandoPrefix = "mce-data-";
  4385. var mouseEventRe = /^(?:mouse|contextmenu)|click/;
  4386. var addEvent = function(target, name2, callback, capture) {
  4387. if (target.addEventListener) {
  4388. target.addEventListener(name2, callback, capture || false);
  4389. } else if (target.attachEvent) {
  4390. target.attachEvent("on" + name2, callback);
  4391. }
  4392. };
  4393. var removeEvent = function(target, name2, callback, capture) {
  4394. if (target.removeEventListener) {
  4395. target.removeEventListener(name2, callback, capture || false);
  4396. } else if (target.detachEvent) {
  4397. target.detachEvent("on" + name2, callback);
  4398. }
  4399. };
  4400. var isMouseEvent = function(event) {
  4401. return isNonNullable(event) && mouseEventRe.test(event.type);
  4402. };
  4403. var fix = function(originalEvent, data2) {
  4404. var event = normalize$3(originalEvent.type, originalEvent, document, data2);
  4405. if (isMouseEvent(originalEvent) && isUndefined(originalEvent.pageX) && !isUndefined(originalEvent.clientX)) {
  4406. var eventDoc = event.target.ownerDocument || document;
  4407. var doc2 = eventDoc.documentElement;
  4408. var body = eventDoc.body;
  4409. var mouseEvent = event;
  4410. mouseEvent.pageX = originalEvent.clientX + (doc2 && doc2.scrollLeft || body && body.scrollLeft || 0) - (doc2 && doc2.clientLeft || body && body.clientLeft || 0);
  4411. mouseEvent.pageY = originalEvent.clientY + (doc2 && doc2.scrollTop || body && body.scrollTop || 0) - (doc2 && doc2.clientTop || body && body.clientTop || 0);
  4412. }
  4413. if (isUndefined(event.metaKey)) {
  4414. event.metaKey = false;
  4415. }
  4416. return event;
  4417. };
  4418. var bindOnReady = function(win, callback, eventUtils) {
  4419. var doc2 = win.document, event = { type: "ready" };
  4420. if (eventUtils.domLoaded) {
  4421. callback(event);
  4422. return;
  4423. }
  4424. var isDocReady = function() {
  4425. return doc2.readyState === "complete" || doc2.readyState === "interactive" && doc2.body;
  4426. };
  4427. var readyHandler = function() {
  4428. removeEvent(win, "DOMContentLoaded", readyHandler);
  4429. removeEvent(win, "load", readyHandler);
  4430. if (!eventUtils.domLoaded) {
  4431. eventUtils.domLoaded = true;
  4432. callback(event);
  4433. }
  4434. win = null;
  4435. };
  4436. if (isDocReady()) {
  4437. readyHandler();
  4438. } else {
  4439. addEvent(win, "DOMContentLoaded", readyHandler);
  4440. }
  4441. if (!eventUtils.domLoaded) {
  4442. addEvent(win, "load", readyHandler);
  4443. }
  4444. };
  4445. var EventUtils = function() {
  4446. function EventUtils2() {
  4447. this.domLoaded = false;
  4448. this.events = {};
  4449. this.count = 1;
  4450. this.expando = eventExpandoPrefix + (+new Date()).toString(32);
  4451. this.hasMouseEnterLeave = "onmouseenter" in document.documentElement;
  4452. this.hasFocusIn = "onfocusin" in document.documentElement;
  4453. this.count = 1;
  4454. }
  4455. EventUtils2.prototype.bind = function(target, names, callback, scope) {
  4456. var self2 = this;
  4457. var id, callbackList, i, name2, fakeName, nativeHandler, capture;
  4458. var win = window;
  4459. var defaultNativeHandler = function(evt) {
  4460. self2.executeHandlers(fix(evt || win.event), id);
  4461. };
  4462. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4463. return;
  4464. }
  4465. if (!target[self2.expando]) {
  4466. id = self2.count++;
  4467. target[self2.expando] = id;
  4468. self2.events[id] = {};
  4469. } else {
  4470. id = target[self2.expando];
  4471. }
  4472. scope = scope || target;
  4473. var namesList = names.split(" ");
  4474. i = namesList.length;
  4475. while (i--) {
  4476. name2 = namesList[i];
  4477. nativeHandler = defaultNativeHandler;
  4478. fakeName = capture = false;
  4479. if (name2 === "DOMContentLoaded") {
  4480. name2 = "ready";
  4481. }
  4482. if (self2.domLoaded && name2 === "ready" && target.readyState === "complete") {
  4483. callback.call(scope, fix({ type: name2 }));
  4484. continue;
  4485. }
  4486. if (!self2.hasMouseEnterLeave) {
  4487. fakeName = self2.mouseEnterLeave[name2];
  4488. if (fakeName) {
  4489. nativeHandler = function(evt) {
  4490. var current = evt.currentTarget;
  4491. var related = evt.relatedTarget;
  4492. if (related && current.contains) {
  4493. related = current.contains(related);
  4494. } else {
  4495. while (related && related !== current) {
  4496. related = related.parentNode;
  4497. }
  4498. }
  4499. if (!related) {
  4500. evt = fix(evt || win.event);
  4501. evt.type = evt.type === "mouseout" ? "mouseleave" : "mouseenter";
  4502. evt.target = current;
  4503. self2.executeHandlers(evt, id);
  4504. }
  4505. };
  4506. }
  4507. }
  4508. if (!self2.hasFocusIn && (name2 === "focusin" || name2 === "focusout")) {
  4509. capture = true;
  4510. fakeName = name2 === "focusin" ? "focus" : "blur";
  4511. nativeHandler = function(evt) {
  4512. evt = fix(evt || win.event);
  4513. evt.type = evt.type === "focus" ? "focusin" : "focusout";
  4514. self2.executeHandlers(evt, id);
  4515. };
  4516. }
  4517. callbackList = self2.events[id][name2];
  4518. if (!callbackList) {
  4519. self2.events[id][name2] = callbackList = [{
  4520. func: callback,
  4521. scope
  4522. }];
  4523. callbackList.fakeName = fakeName;
  4524. callbackList.capture = capture;
  4525. callbackList.nativeHandler = nativeHandler;
  4526. if (name2 === "ready") {
  4527. bindOnReady(target, nativeHandler, self2);
  4528. } else {
  4529. addEvent(target, fakeName || name2, nativeHandler, capture);
  4530. }
  4531. } else {
  4532. if (name2 === "ready" && self2.domLoaded) {
  4533. callback(fix({ type: name2 }));
  4534. } else {
  4535. callbackList.push({
  4536. func: callback,
  4537. scope
  4538. });
  4539. }
  4540. }
  4541. }
  4542. target = callbackList = null;
  4543. return callback;
  4544. };
  4545. EventUtils2.prototype.unbind = function(target, names, callback) {
  4546. var callbackList, i, ci, name2, eventMap;
  4547. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4548. return this;
  4549. }
  4550. var id = target[this.expando];
  4551. if (id) {
  4552. eventMap = this.events[id];
  4553. if (names) {
  4554. var namesList = names.split(" ");
  4555. i = namesList.length;
  4556. while (i--) {
  4557. name2 = namesList[i];
  4558. callbackList = eventMap[name2];
  4559. if (callbackList) {
  4560. if (callback) {
  4561. ci = callbackList.length;
  4562. while (ci--) {
  4563. if (callbackList[ci].func === callback) {
  4564. var nativeHandler = callbackList.nativeHandler;
  4565. var fakeName = callbackList.fakeName, capture = callbackList.capture;
  4566. callbackList = callbackList.slice(0, ci).concat(callbackList.slice(ci + 1));
  4567. callbackList.nativeHandler = nativeHandler;
  4568. callbackList.fakeName = fakeName;
  4569. callbackList.capture = capture;
  4570. eventMap[name2] = callbackList;
  4571. }
  4572. }
  4573. }
  4574. if (!callback || callbackList.length === 0) {
  4575. delete eventMap[name2];
  4576. removeEvent(target, callbackList.fakeName || name2, callbackList.nativeHandler, callbackList.capture);
  4577. }
  4578. }
  4579. }
  4580. } else {
  4581. each$j(eventMap, function(callbackList2, name3) {
  4582. removeEvent(target, callbackList2.fakeName || name3, callbackList2.nativeHandler, callbackList2.capture);
  4583. });
  4584. eventMap = {};
  4585. }
  4586. for (name2 in eventMap) {
  4587. if (has$2(eventMap, name2)) {
  4588. return this;
  4589. }
  4590. }
  4591. delete this.events[id];
  4592. try {
  4593. delete target[this.expando];
  4594. } catch (ex) {
  4595. target[this.expando] = null;
  4596. }
  4597. }
  4598. return this;
  4599. };
  4600. EventUtils2.prototype.fire = function(target, name2, args) {
  4601. var id;
  4602. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4603. return this;
  4604. }
  4605. var event = fix({
  4606. type: name2,
  4607. target
  4608. }, args);
  4609. do {
  4610. id = target[this.expando];
  4611. if (id) {
  4612. this.executeHandlers(event, id);
  4613. }
  4614. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  4615. } while (target && !event.isPropagationStopped());
  4616. return this;
  4617. };
  4618. EventUtils2.prototype.clean = function(target) {
  4619. var i, children2;
  4620. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4621. return this;
  4622. }
  4623. if (target[this.expando]) {
  4624. this.unbind(target);
  4625. }
  4626. if (!target.getElementsByTagName) {
  4627. target = target.document;
  4628. }
  4629. if (target && target.getElementsByTagName) {
  4630. this.unbind(target);
  4631. children2 = target.getElementsByTagName("*");
  4632. i = children2.length;
  4633. while (i--) {
  4634. target = children2[i];
  4635. if (target[this.expando]) {
  4636. this.unbind(target);
  4637. }
  4638. }
  4639. }
  4640. return this;
  4641. };
  4642. EventUtils2.prototype.destroy = function() {
  4643. this.events = {};
  4644. };
  4645. EventUtils2.prototype.cancel = function(e) {
  4646. if (e) {
  4647. e.preventDefault();
  4648. e.stopImmediatePropagation();
  4649. }
  4650. return false;
  4651. };
  4652. EventUtils2.prototype.executeHandlers = function(evt, id) {
  4653. var container = this.events[id];
  4654. var callbackList = container && container[evt.type];
  4655. if (callbackList) {
  4656. for (var i = 0, l = callbackList.length; i < l; i++) {
  4657. var callback = callbackList[i];
  4658. if (callback && callback.func.call(callback.scope, evt) === false) {
  4659. evt.preventDefault();
  4660. }
  4661. if (evt.isImmediatePropagationStopped()) {
  4662. return;
  4663. }
  4664. }
  4665. }
  4666. };
  4667. EventUtils2.Event = new EventUtils2();
  4668. return EventUtils2;
  4669. }();
  4670. var support, Expr, getText, isXML, tokenize, compile, select$1, outermostContext, sortInput, hasDuplicate, setDocument, document$1, docElem, documentIsHTML, rbuggyQSA, rbuggyMatches, matches, contains, expando = "sizzle" + -new Date(), preferredDoc = window.document, dirruns = 0, done = 0, classCache = createCache(), tokenCache = createCache(), compilerCache = createCache(), sortOrder = function(a, b) {
  4671. if (a === b) {
  4672. hasDuplicate = true;
  4673. }
  4674. return 0;
  4675. }, strundefined = "undefined", MAX_NEGATIVE = 1 << 31, hasOwn = {}.hasOwnProperty, arr = [], pop = arr.pop, push_native = arr.push, push$1 = arr.push, slice$1 = arr.slice, indexOf = arr.indexOf || function(elem) {
  4676. var i = 0, len = this.length;
  4677. for (; i < len; i++) {
  4678. if (this[i] === elem) {
  4679. return i;
  4680. }
  4681. }
  4682. return -1;
  4683. }, 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 = {
  4684. ID: new RegExp("^#(" + identifier + ")"),
  4685. CLASS: new RegExp("^\\.(" + identifier + ")"),
  4686. TAG: new RegExp("^(" + identifier + "|[*])"),
  4687. ATTR: new RegExp("^" + attributes),
  4688. PSEUDO: new RegExp("^" + pseudos),
  4689. CHILD: new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + "*(\\d+)|))" + whitespace + "*\\)|)", "i"),
  4690. bool: new RegExp("^(?:" + booleans + ")$", "i"),
  4691. needsContext: new RegExp("^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i")
  4692. }, rinputs = /^(?:input|select|textarea|button)$/i, rheader = /^h\d$/i, rnative = /^[^{]+\{\s*\[native \w/, rquickExpr$1 = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, rsibling = /[+~]/, rescape = /'|\\/g, runescape = new RegExp("\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig"), funescape = function(_, escaped, escapedWhitespace) {
  4693. var high = "0x" + escaped - 65536;
  4694. return high !== high || escapedWhitespace ? escaped : high < 0 ? String.fromCharCode(high + 65536) : String.fromCharCode(high >> 10 | 55296, high & 1023 | 56320);
  4695. };
  4696. try {
  4697. push$1.apply(arr = slice$1.call(preferredDoc.childNodes), preferredDoc.childNodes);
  4698. arr[preferredDoc.childNodes.length].nodeType;
  4699. } catch (e) {
  4700. push$1 = {
  4701. apply: arr.length ? function(target, els) {
  4702. push_native.apply(target, slice$1.call(els));
  4703. } : function(target, els) {
  4704. var j = target.length, i = 0;
  4705. while (target[j++] = els[i++]) {
  4706. }
  4707. target.length = j - 1;
  4708. }
  4709. };
  4710. }
  4711. var Sizzle = function(selector, context2, results, seed2) {
  4712. var match2, elem, m, nodeType, i, groups, old, nid, newContext, newSelector;
  4713. if ((context2 ? context2.ownerDocument || context2 : preferredDoc) !== document$1) {
  4714. setDocument(context2);
  4715. }
  4716. context2 = context2 || document$1;
  4717. results = results || [];
  4718. if (!selector || typeof selector !== "string") {
  4719. return results;
  4720. }
  4721. if ((nodeType = context2.nodeType) !== 1 && nodeType !== 9) {
  4722. return [];
  4723. }
  4724. if (documentIsHTML && !seed2) {
  4725. if (match2 = rquickExpr$1.exec(selector)) {
  4726. if (m = match2[1]) {
  4727. if (nodeType === 9) {
  4728. elem = context2.getElementById(m);
  4729. if (elem && elem.parentNode) {
  4730. if (elem.id === m) {
  4731. results.push(elem);
  4732. return results;
  4733. }
  4734. } else {
  4735. return results;
  4736. }
  4737. } else {
  4738. if (context2.ownerDocument && (elem = context2.ownerDocument.getElementById(m)) && contains(context2, elem) && elem.id === m) {
  4739. results.push(elem);
  4740. return results;
  4741. }
  4742. }
  4743. } else if (match2[2]) {
  4744. push$1.apply(results, context2.getElementsByTagName(selector));
  4745. return results;
  4746. } else if ((m = match2[3]) && support.getElementsByClassName) {
  4747. push$1.apply(results, context2.getElementsByClassName(m));
  4748. return results;
  4749. }
  4750. }
  4751. if (support.qsa && (!rbuggyQSA || !rbuggyQSA.test(selector))) {
  4752. nid = old = expando;
  4753. newContext = context2;
  4754. newSelector = nodeType === 9 && selector;
  4755. if (nodeType === 1 && context2.nodeName.toLowerCase() !== "object") {
  4756. groups = tokenize(selector);
  4757. if (old = context2.getAttribute("id")) {
  4758. nid = old.replace(rescape, "\\$&");
  4759. } else {
  4760. context2.setAttribute("id", nid);
  4761. }
  4762. nid = "[id='" + nid + "'] ";
  4763. i = groups.length;
  4764. while (i--) {
  4765. groups[i] = nid + toSelector(groups[i]);
  4766. }
  4767. newContext = rsibling.test(selector) && testContext(context2.parentNode) || context2;
  4768. newSelector = groups.join(",");
  4769. }
  4770. if (newSelector) {
  4771. try {
  4772. push$1.apply(results, newContext.querySelectorAll(newSelector));
  4773. return results;
  4774. } catch (qsaError) {
  4775. } finally {
  4776. if (!old) {
  4777. context2.removeAttribute("id");
  4778. }
  4779. }
  4780. }
  4781. }
  4782. }
  4783. return select$1(selector.replace(rtrim, "$1"), context2, results, seed2);
  4784. };
  4785. function createCache() {
  4786. var keys2 = [];
  4787. function cache(key, value2) {
  4788. if (keys2.push(key + " ") > Expr.cacheLength) {
  4789. delete cache[keys2.shift()];
  4790. }
  4791. return cache[key + " "] = value2;
  4792. }
  4793. return cache;
  4794. }
  4795. function markFunction(fn) {
  4796. fn[expando] = true;
  4797. return fn;
  4798. }
  4799. function siblingCheck(a, b) {
  4800. var cur = b && a, diff2 = cur && a.nodeType === 1 && b.nodeType === 1 && (~b.sourceIndex || MAX_NEGATIVE) - (~a.sourceIndex || MAX_NEGATIVE);
  4801. if (diff2) {
  4802. return diff2;
  4803. }
  4804. if (cur) {
  4805. while (cur = cur.nextSibling) {
  4806. if (cur === b) {
  4807. return -1;
  4808. }
  4809. }
  4810. }
  4811. return a ? 1 : -1;
  4812. }
  4813. function createInputPseudo(type2) {
  4814. return function(elem) {
  4815. var name2 = elem.nodeName.toLowerCase();
  4816. return name2 === "input" && elem.type === type2;
  4817. };
  4818. }
  4819. function createButtonPseudo(type2) {
  4820. return function(elem) {
  4821. var name2 = elem.nodeName.toLowerCase();
  4822. return (name2 === "input" || name2 === "button") && elem.type === type2;
  4823. };
  4824. }
  4825. function createPositionalPseudo(fn) {
  4826. return markFunction(function(argument) {
  4827. argument = +argument;
  4828. return markFunction(function(seed2, matches2) {
  4829. var j, matchIndexes = fn([], seed2.length, argument), i = matchIndexes.length;
  4830. while (i--) {
  4831. if (seed2[j = matchIndexes[i]]) {
  4832. seed2[j] = !(matches2[j] = seed2[j]);
  4833. }
  4834. }
  4835. });
  4836. });
  4837. }
  4838. function testContext(context2) {
  4839. return context2 && typeof context2.getElementsByTagName !== strundefined && context2;
  4840. }
  4841. support = Sizzle.support = {};
  4842. isXML = Sizzle.isXML = function(elem) {
  4843. var documentElement2 = elem && (elem.ownerDocument || elem).documentElement;
  4844. return documentElement2 ? documentElement2.nodeName !== "HTML" : false;
  4845. };
  4846. setDocument = Sizzle.setDocument = function(node) {
  4847. var hasCompare, doc2 = node ? node.ownerDocument || node : preferredDoc, parent2 = doc2.defaultView;
  4848. function getTop(win) {
  4849. try {
  4850. return win.top;
  4851. } catch (ex) {
  4852. }
  4853. return null;
  4854. }
  4855. if (doc2 === document$1 || doc2.nodeType !== 9 || !doc2.documentElement) {
  4856. return document$1;
  4857. }
  4858. document$1 = doc2;
  4859. docElem = doc2.documentElement;
  4860. documentIsHTML = !isXML(doc2);
  4861. if (parent2 && parent2 !== getTop(parent2)) {
  4862. if (parent2.addEventListener) {
  4863. parent2.addEventListener("unload", function() {
  4864. setDocument();
  4865. }, false);
  4866. } else if (parent2.attachEvent) {
  4867. parent2.attachEvent("onunload", function() {
  4868. setDocument();
  4869. });
  4870. }
  4871. }
  4872. support.attributes = true;
  4873. support.getElementsByTagName = true;
  4874. support.getElementsByClassName = rnative.test(doc2.getElementsByClassName);
  4875. support.getById = true;
  4876. Expr.find.ID = function(id, context2) {
  4877. if (typeof context2.getElementById !== strundefined && documentIsHTML) {
  4878. var m = context2.getElementById(id);
  4879. return m && m.parentNode ? [m] : [];
  4880. }
  4881. };
  4882. Expr.filter.ID = function(id) {
  4883. var attrId = id.replace(runescape, funescape);
  4884. return function(elem) {
  4885. return elem.getAttribute("id") === attrId;
  4886. };
  4887. };
  4888. Expr.find.TAG = support.getElementsByTagName ? function(tag, context2) {
  4889. if (typeof context2.getElementsByTagName !== strundefined) {
  4890. return context2.getElementsByTagName(tag);
  4891. }
  4892. } : function(tag, context2) {
  4893. var elem, tmp = [], i = 0, results = context2.getElementsByTagName(tag);
  4894. if (tag === "*") {
  4895. while (elem = results[i++]) {
  4896. if (elem.nodeType === 1) {
  4897. tmp.push(elem);
  4898. }
  4899. }
  4900. return tmp;
  4901. }
  4902. return results;
  4903. };
  4904. Expr.find.CLASS = support.getElementsByClassName && function(className, context2) {
  4905. if (documentIsHTML) {
  4906. return context2.getElementsByClassName(className);
  4907. }
  4908. };
  4909. rbuggyMatches = [];
  4910. rbuggyQSA = [];
  4911. support.disconnectedMatch = true;
  4912. rbuggyQSA = rbuggyQSA.length && new RegExp(rbuggyQSA.join("|"));
  4913. rbuggyMatches = rbuggyMatches.length && new RegExp(rbuggyMatches.join("|"));
  4914. hasCompare = rnative.test(docElem.compareDocumentPosition);
  4915. contains = hasCompare || rnative.test(docElem.contains) ? function(a, b) {
  4916. var adown = a.nodeType === 9 ? a.documentElement : a, bup = b && b.parentNode;
  4917. return a === bup || !!(bup && bup.nodeType === 1 && (adown.contains ? adown.contains(bup) : a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16));
  4918. } : function(a, b) {
  4919. if (b) {
  4920. while (b = b.parentNode) {
  4921. if (b === a) {
  4922. return true;
  4923. }
  4924. }
  4925. }
  4926. return false;
  4927. };
  4928. sortOrder = hasCompare ? function(a, b) {
  4929. if (a === b) {
  4930. hasDuplicate = true;
  4931. return 0;
  4932. }
  4933. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  4934. if (compare) {
  4935. return compare;
  4936. }
  4937. compare = (a.ownerDocument || a) === (b.ownerDocument || b) ? a.compareDocumentPosition(b) : 1;
  4938. if (compare & 1 || !support.sortDetached && b.compareDocumentPosition(a) === compare) {
  4939. if (a === doc2 || a.ownerDocument === preferredDoc && contains(preferredDoc, a)) {
  4940. return -1;
  4941. }
  4942. if (b === doc2 || b.ownerDocument === preferredDoc && contains(preferredDoc, b)) {
  4943. return 1;
  4944. }
  4945. return sortInput ? indexOf.call(sortInput, a) - indexOf.call(sortInput, b) : 0;
  4946. }
  4947. return compare & 4 ? -1 : 1;
  4948. } : function(a, b) {
  4949. if (a === b) {
  4950. hasDuplicate = true;
  4951. return 0;
  4952. }
  4953. var cur, i = 0, aup = a.parentNode, bup = b.parentNode, ap = [a], bp = [b];
  4954. if (!aup || !bup) {
  4955. return a === doc2 ? -1 : b === doc2 ? 1 : aup ? -1 : bup ? 1 : sortInput ? indexOf.call(sortInput, a) - indexOf.call(sortInput, b) : 0;
  4956. } else if (aup === bup) {
  4957. return siblingCheck(a, b);
  4958. }
  4959. cur = a;
  4960. while (cur = cur.parentNode) {
  4961. ap.unshift(cur);
  4962. }
  4963. cur = b;
  4964. while (cur = cur.parentNode) {
  4965. bp.unshift(cur);
  4966. }
  4967. while (ap[i] === bp[i]) {
  4968. i++;
  4969. }
  4970. return i ? siblingCheck(ap[i], bp[i]) : ap[i] === preferredDoc ? -1 : bp[i] === preferredDoc ? 1 : 0;
  4971. };
  4972. return doc2;
  4973. };
  4974. Sizzle.matches = function(expr, elements) {
  4975. return Sizzle(expr, null, null, elements);
  4976. };
  4977. Sizzle.matchesSelector = function(elem, expr) {
  4978. if ((elem.ownerDocument || elem) !== document$1) {
  4979. setDocument(elem);
  4980. }
  4981. expr = expr.replace(rattributeQuotes, "='$1']");
  4982. if (support.matchesSelector && documentIsHTML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && (!rbuggyQSA || !rbuggyQSA.test(expr))) {
  4983. try {
  4984. var ret = matches.call(elem, expr);
  4985. if (ret || support.disconnectedMatch || elem.document && elem.document.nodeType !== 11) {
  4986. return ret;
  4987. }
  4988. } catch (e) {
  4989. }
  4990. }
  4991. return Sizzle(expr, document$1, null, [elem]).length > 0;
  4992. };
  4993. Sizzle.contains = function(context2, elem) {
  4994. if ((context2.ownerDocument || context2) !== document$1) {
  4995. setDocument(context2);
  4996. }
  4997. return contains(context2, elem);
  4998. };
  4999. Sizzle.attr = function(elem, name2) {
  5000. if ((elem.ownerDocument || elem) !== document$1) {
  5001. setDocument(elem);
  5002. }
  5003. var fn = Expr.attrHandle[name2.toLowerCase()], val = fn && hasOwn.call(Expr.attrHandle, name2.toLowerCase()) ? fn(elem, name2, !documentIsHTML) : void 0;
  5004. return val !== void 0 ? val : support.attributes || !documentIsHTML ? elem.getAttribute(name2) : (val = elem.getAttributeNode(name2)) && val.specified ? val.value : null;
  5005. };
  5006. Sizzle.error = function(msg) {
  5007. throw new Error("Syntax error, unrecognized expression: " + msg);
  5008. };
  5009. Sizzle.uniqueSort = function(results) {
  5010. var elem, duplicates = [], j = 0, i = 0;
  5011. hasDuplicate = !support.detectDuplicates;
  5012. sortInput = !support.sortStable && results.slice(0);
  5013. results.sort(sortOrder);
  5014. if (hasDuplicate) {
  5015. while (elem = results[i++]) {
  5016. if (elem === results[i]) {
  5017. j = duplicates.push(i);
  5018. }
  5019. }
  5020. while (j--) {
  5021. results.splice(duplicates[j], 1);
  5022. }
  5023. }
  5024. sortInput = null;
  5025. return results;
  5026. };
  5027. getText = Sizzle.getText = function(elem) {
  5028. var node, ret = "", i = 0, nodeType = elem.nodeType;
  5029. if (!nodeType) {
  5030. while (node = elem[i++]) {
  5031. ret += getText(node);
  5032. }
  5033. } else if (nodeType === 1 || nodeType === 9 || nodeType === 11) {
  5034. if (typeof elem.textContent === "string") {
  5035. return elem.textContent;
  5036. } else {
  5037. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  5038. ret += getText(elem);
  5039. }
  5040. }
  5041. } else if (nodeType === 3 || nodeType === 4) {
  5042. return elem.nodeValue;
  5043. }
  5044. return ret;
  5045. };
  5046. Expr = Sizzle.selectors = {
  5047. cacheLength: 50,
  5048. createPseudo: markFunction,
  5049. match: matchExpr,
  5050. attrHandle: {},
  5051. find: {},
  5052. relative: {
  5053. ">": {
  5054. dir: "parentNode",
  5055. first: true
  5056. },
  5057. " ": { dir: "parentNode" },
  5058. "+": {
  5059. dir: "previousSibling",
  5060. first: true
  5061. },
  5062. "~": { dir: "previousSibling" }
  5063. },
  5064. preFilter: {
  5065. ATTR: function(match2) {
  5066. match2[1] = match2[1].replace(runescape, funescape);
  5067. match2[3] = (match2[3] || match2[4] || match2[5] || "").replace(runescape, funescape);
  5068. if (match2[2] === "~=") {
  5069. match2[3] = " " + match2[3] + " ";
  5070. }
  5071. return match2.slice(0, 4);
  5072. },
  5073. CHILD: function(match2) {
  5074. match2[1] = match2[1].toLowerCase();
  5075. if (match2[1].slice(0, 3) === "nth") {
  5076. if (!match2[3]) {
  5077. Sizzle.error(match2[0]);
  5078. }
  5079. match2[4] = +(match2[4] ? match2[5] + (match2[6] || 1) : 2 * (match2[3] === "even" || match2[3] === "odd"));
  5080. match2[5] = +(match2[7] + match2[8] || match2[3] === "odd");
  5081. } else if (match2[3]) {
  5082. Sizzle.error(match2[0]);
  5083. }
  5084. return match2;
  5085. },
  5086. PSEUDO: function(match2) {
  5087. var excess, unquoted = !match2[6] && match2[2];
  5088. if (matchExpr.CHILD.test(match2[0])) {
  5089. return null;
  5090. }
  5091. if (match2[3]) {
  5092. match2[2] = match2[4] || match2[5] || "";
  5093. } else if (unquoted && rpseudo.test(unquoted) && (excess = tokenize(unquoted, true)) && (excess = unquoted.indexOf(")", unquoted.length - excess) - unquoted.length)) {
  5094. match2[0] = match2[0].slice(0, excess);
  5095. match2[2] = unquoted.slice(0, excess);
  5096. }
  5097. return match2.slice(0, 3);
  5098. }
  5099. },
  5100. filter: {
  5101. TAG: function(nodeNameSelector) {
  5102. var nodeName = nodeNameSelector.replace(runescape, funescape).toLowerCase();
  5103. return nodeNameSelector === "*" ? function() {
  5104. return true;
  5105. } : function(elem) {
  5106. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  5107. };
  5108. },
  5109. CLASS: function(className) {
  5110. var pattern = classCache[className + " "];
  5111. return pattern || (pattern = new RegExp("(^|" + whitespace + ")" + className + "(" + whitespace + "|$)")) && classCache(className, function(elem) {
  5112. return pattern.test(typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute("class") || "");
  5113. });
  5114. },
  5115. ATTR: function(name2, operator, check) {
  5116. return function(elem) {
  5117. var result = Sizzle.attr(elem, name2);
  5118. if (result == null) {
  5119. return operator === "!=";
  5120. }
  5121. if (!operator) {
  5122. return true;
  5123. }
  5124. result += "";
  5125. 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;
  5126. };
  5127. },
  5128. CHILD: function(type2, what, argument, first2, last2) {
  5129. var simple = type2.slice(0, 3) !== "nth", forward = type2.slice(-4) !== "last", ofType = what === "of-type";
  5130. return first2 === 1 && last2 === 0 ? function(elem) {
  5131. return !!elem.parentNode;
  5132. } : function(elem, context2, xml) {
  5133. var cache, outerCache, node, diff2, nodeIndex2, start2, dir2 = simple !== forward ? "nextSibling" : "previousSibling", parent2 = elem.parentNode, name2 = ofType && elem.nodeName.toLowerCase(), useCache = !xml && !ofType;
  5134. if (parent2) {
  5135. if (simple) {
  5136. while (dir2) {
  5137. node = elem;
  5138. while (node = node[dir2]) {
  5139. if (ofType ? node.nodeName.toLowerCase() === name2 : node.nodeType === 1) {
  5140. return false;
  5141. }
  5142. }
  5143. start2 = dir2 = type2 === "only" && !start2 && "nextSibling";
  5144. }
  5145. return true;
  5146. }
  5147. start2 = [forward ? parent2.firstChild : parent2.lastChild];
  5148. if (forward && useCache) {
  5149. outerCache = parent2[expando] || (parent2[expando] = {});
  5150. cache = outerCache[type2] || [];
  5151. nodeIndex2 = cache[0] === dirruns && cache[1];
  5152. diff2 = cache[0] === dirruns && cache[2];
  5153. node = nodeIndex2 && parent2.childNodes[nodeIndex2];
  5154. while (node = ++nodeIndex2 && node && node[dir2] || (diff2 = nodeIndex2 = 0) || start2.pop()) {
  5155. if (node.nodeType === 1 && ++diff2 && node === elem) {
  5156. outerCache[type2] = [
  5157. dirruns,
  5158. nodeIndex2,
  5159. diff2
  5160. ];
  5161. break;
  5162. }
  5163. }
  5164. } else if (useCache && (cache = (elem[expando] || (elem[expando] = {}))[type2]) && cache[0] === dirruns) {
  5165. diff2 = cache[1];
  5166. } else {
  5167. while (node = ++nodeIndex2 && node && node[dir2] || (diff2 = nodeIndex2 = 0) || start2.pop()) {
  5168. if ((ofType ? node.nodeName.toLowerCase() === name2 : node.nodeType === 1) && ++diff2) {
  5169. if (useCache) {
  5170. (node[expando] || (node[expando] = {}))[type2] = [
  5171. dirruns,
  5172. diff2
  5173. ];
  5174. }
  5175. if (node === elem) {
  5176. break;
  5177. }
  5178. }
  5179. }
  5180. }
  5181. diff2 -= last2;
  5182. return diff2 === first2 || diff2 % first2 === 0 && diff2 / first2 >= 0;
  5183. }
  5184. };
  5185. },
  5186. PSEUDO: function(pseudo, argument) {
  5187. var args, fn = Expr.pseudos[pseudo] || Expr.setFilters[pseudo.toLowerCase()] || Sizzle.error("unsupported pseudo: " + pseudo);
  5188. if (fn[expando]) {
  5189. return fn(argument);
  5190. }
  5191. if (fn.length > 1) {
  5192. args = [
  5193. pseudo,
  5194. pseudo,
  5195. "",
  5196. argument
  5197. ];
  5198. return Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function(seed2, matches2) {
  5199. var idx, matched = fn(seed2, argument), i = matched.length;
  5200. while (i--) {
  5201. idx = indexOf.call(seed2, matched[i]);
  5202. seed2[idx] = !(matches2[idx] = matched[i]);
  5203. }
  5204. }) : function(elem) {
  5205. return fn(elem, 0, args);
  5206. };
  5207. }
  5208. return fn;
  5209. }
  5210. },
  5211. pseudos: {
  5212. not: markFunction(function(selector) {
  5213. var input = [], results = [], matcher = compile(selector.replace(rtrim, "$1"));
  5214. return matcher[expando] ? markFunction(function(seed2, matches2, context2, xml) {
  5215. var elem, unmatched = matcher(seed2, null, xml, []), i = seed2.length;
  5216. while (i--) {
  5217. if (elem = unmatched[i]) {
  5218. seed2[i] = !(matches2[i] = elem);
  5219. }
  5220. }
  5221. }) : function(elem, context2, xml) {
  5222. input[0] = elem;
  5223. matcher(input, null, xml, results);
  5224. input[0] = null;
  5225. return !results.pop();
  5226. };
  5227. }),
  5228. has: markFunction(function(selector) {
  5229. return function(elem) {
  5230. return Sizzle(selector, elem).length > 0;
  5231. };
  5232. }),
  5233. contains: markFunction(function(text) {
  5234. text = text.replace(runescape, funescape);
  5235. return function(elem) {
  5236. return (elem.textContent || elem.innerText || getText(elem)).indexOf(text) > -1;
  5237. };
  5238. }),
  5239. lang: markFunction(function(lang) {
  5240. if (!ridentifier.test(lang || "")) {
  5241. Sizzle.error("unsupported lang: " + lang);
  5242. }
  5243. lang = lang.replace(runescape, funescape).toLowerCase();
  5244. return function(elem) {
  5245. var elemLang;
  5246. do {
  5247. if (elemLang = documentIsHTML ? elem.lang : elem.getAttribute("xml:lang") || elem.getAttribute("lang")) {
  5248. elemLang = elemLang.toLowerCase();
  5249. return elemLang === lang || elemLang.indexOf(lang + "-") === 0;
  5250. }
  5251. } while ((elem = elem.parentNode) && elem.nodeType === 1);
  5252. return false;
  5253. };
  5254. }),
  5255. target: function(elem) {
  5256. var hash = window.location && window.location.hash;
  5257. return hash && hash.slice(1) === elem.id;
  5258. },
  5259. root: function(elem) {
  5260. return elem === docElem;
  5261. },
  5262. focus: function(elem) {
  5263. return elem === document$1.activeElement && (!document$1.hasFocus || document$1.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  5264. },
  5265. enabled: function(elem) {
  5266. return elem.disabled === false;
  5267. },
  5268. disabled: function(elem) {
  5269. return elem.disabled === true;
  5270. },
  5271. checked: function(elem) {
  5272. var nodeName = elem.nodeName.toLowerCase();
  5273. return nodeName === "input" && !!elem.checked || nodeName === "option" && !!elem.selected;
  5274. },
  5275. selected: function(elem) {
  5276. if (elem.parentNode) {
  5277. elem.parentNode.selectedIndex;
  5278. }
  5279. return elem.selected === true;
  5280. },
  5281. empty: function(elem) {
  5282. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  5283. if (elem.nodeType < 6) {
  5284. return false;
  5285. }
  5286. }
  5287. return true;
  5288. },
  5289. parent: function(elem) {
  5290. return !Expr.pseudos.empty(elem);
  5291. },
  5292. header: function(elem) {
  5293. return rheader.test(elem.nodeName);
  5294. },
  5295. input: function(elem) {
  5296. return rinputs.test(elem.nodeName);
  5297. },
  5298. button: function(elem) {
  5299. var name2 = elem.nodeName.toLowerCase();
  5300. return name2 === "input" && elem.type === "button" || name2 === "button";
  5301. },
  5302. text: function(elem) {
  5303. var attr;
  5304. return elem.nodeName.toLowerCase() === "input" && elem.type === "text" && ((attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text");
  5305. },
  5306. first: createPositionalPseudo(function() {
  5307. return [0];
  5308. }),
  5309. last: createPositionalPseudo(function(matchIndexes, length) {
  5310. return [length - 1];
  5311. }),
  5312. eq: createPositionalPseudo(function(matchIndexes, length, argument) {
  5313. return [argument < 0 ? argument + length : argument];
  5314. }),
  5315. even: createPositionalPseudo(function(matchIndexes, length) {
  5316. var i = 0;
  5317. for (; i < length; i += 2) {
  5318. matchIndexes.push(i);
  5319. }
  5320. return matchIndexes;
  5321. }),
  5322. odd: createPositionalPseudo(function(matchIndexes, length) {
  5323. var i = 1;
  5324. for (; i < length; i += 2) {
  5325. matchIndexes.push(i);
  5326. }
  5327. return matchIndexes;
  5328. }),
  5329. lt: createPositionalPseudo(function(matchIndexes, length, argument) {
  5330. var i = argument < 0 ? argument + length : argument;
  5331. for (; --i >= 0; ) {
  5332. matchIndexes.push(i);
  5333. }
  5334. return matchIndexes;
  5335. }),
  5336. gt: createPositionalPseudo(function(matchIndexes, length, argument) {
  5337. var i = argument < 0 ? argument + length : argument;
  5338. for (; ++i < length; ) {
  5339. matchIndexes.push(i);
  5340. }
  5341. return matchIndexes;
  5342. })
  5343. }
  5344. };
  5345. Expr.pseudos.nth = Expr.pseudos.eq;
  5346. each$k([
  5347. "radio",
  5348. "checkbox",
  5349. "file",
  5350. "password",
  5351. "image"
  5352. ], function(i) {
  5353. Expr.pseudos[i] = createInputPseudo(i);
  5354. });
  5355. each$k([
  5356. "submit",
  5357. "reset"
  5358. ], function(i) {
  5359. Expr.pseudos[i] = createButtonPseudo(i);
  5360. });
  5361. function setFilters() {
  5362. }
  5363. setFilters.prototype = Expr.filters = Expr.pseudos;
  5364. Expr.setFilters = new setFilters();
  5365. tokenize = Sizzle.tokenize = function(selector, parseOnly) {
  5366. var matched, match2, tokens, type2, soFar, groups, preFilters, cached2 = tokenCache[selector + " "];
  5367. if (cached2) {
  5368. return parseOnly ? 0 : cached2.slice(0);
  5369. }
  5370. soFar = selector;
  5371. groups = [];
  5372. preFilters = Expr.preFilter;
  5373. while (soFar) {
  5374. if (!matched || (match2 = rcomma.exec(soFar))) {
  5375. if (match2) {
  5376. soFar = soFar.slice(match2[0].length) || soFar;
  5377. }
  5378. groups.push(tokens = []);
  5379. }
  5380. matched = false;
  5381. if (match2 = rcombinators.exec(soFar)) {
  5382. matched = match2.shift();
  5383. tokens.push({
  5384. value: matched,
  5385. type: match2[0].replace(rtrim, " ")
  5386. });
  5387. soFar = soFar.slice(matched.length);
  5388. }
  5389. for (type2 in Expr.filter) {
  5390. if (!Expr.filter.hasOwnProperty(type2)) {
  5391. continue;
  5392. }
  5393. if ((match2 = matchExpr[type2].exec(soFar)) && (!preFilters[type2] || (match2 = preFilters[type2](match2)))) {
  5394. matched = match2.shift();
  5395. tokens.push({
  5396. value: matched,
  5397. type: type2,
  5398. matches: match2
  5399. });
  5400. soFar = soFar.slice(matched.length);
  5401. }
  5402. }
  5403. if (!matched) {
  5404. break;
  5405. }
  5406. }
  5407. return parseOnly ? soFar.length : soFar ? Sizzle.error(selector) : tokenCache(selector, groups).slice(0);
  5408. };
  5409. function toSelector(tokens) {
  5410. var i = 0, len = tokens.length, selector = "";
  5411. for (; i < len; i++) {
  5412. selector += tokens[i].value;
  5413. }
  5414. return selector;
  5415. }
  5416. function addCombinator(matcher, combinator, base) {
  5417. var dir2 = combinator.dir, checkNonElements = base && dir2 === "parentNode", doneName = done++;
  5418. return combinator.first ? function(elem, context2, xml) {
  5419. while (elem = elem[dir2]) {
  5420. if (elem.nodeType === 1 || checkNonElements) {
  5421. return matcher(elem, context2, xml);
  5422. }
  5423. }
  5424. } : function(elem, context2, xml) {
  5425. var oldCache, outerCache, newCache = [
  5426. dirruns,
  5427. doneName
  5428. ];
  5429. if (xml) {
  5430. while (elem = elem[dir2]) {
  5431. if (elem.nodeType === 1 || checkNonElements) {
  5432. if (matcher(elem, context2, xml)) {
  5433. return true;
  5434. }
  5435. }
  5436. }
  5437. } else {
  5438. while (elem = elem[dir2]) {
  5439. if (elem.nodeType === 1 || checkNonElements) {
  5440. outerCache = elem[expando] || (elem[expando] = {});
  5441. if ((oldCache = outerCache[dir2]) && oldCache[0] === dirruns && oldCache[1] === doneName) {
  5442. return newCache[2] = oldCache[2];
  5443. } else {
  5444. outerCache[dir2] = newCache;
  5445. if (newCache[2] = matcher(elem, context2, xml)) {
  5446. return true;
  5447. }
  5448. }
  5449. }
  5450. }
  5451. }
  5452. };
  5453. }
  5454. function elementMatcher(matchers) {
  5455. return matchers.length > 1 ? function(elem, context2, xml) {
  5456. var i = matchers.length;
  5457. while (i--) {
  5458. if (!matchers[i](elem, context2, xml)) {
  5459. return false;
  5460. }
  5461. }
  5462. return true;
  5463. } : matchers[0];
  5464. }
  5465. function multipleContexts(selector, contexts, results) {
  5466. var i = 0, len = contexts.length;
  5467. for (; i < len; i++) {
  5468. Sizzle(selector, contexts[i], results);
  5469. }
  5470. return results;
  5471. }
  5472. function condense(unmatched, map2, filter2, context2, xml) {
  5473. var elem, newUnmatched = [], i = 0, len = unmatched.length, mapped = map2 != null;
  5474. for (; i < len; i++) {
  5475. if (elem = unmatched[i]) {
  5476. if (!filter2 || filter2(elem, context2, xml)) {
  5477. newUnmatched.push(elem);
  5478. if (mapped) {
  5479. map2.push(i);
  5480. }
  5481. }
  5482. }
  5483. }
  5484. return newUnmatched;
  5485. }
  5486. function setMatcher(preFilter, selector, matcher, postFilter, postFinder, postSelector) {
  5487. if (postFilter && !postFilter[expando]) {
  5488. postFilter = setMatcher(postFilter);
  5489. }
  5490. if (postFinder && !postFinder[expando]) {
  5491. postFinder = setMatcher(postFinder, postSelector);
  5492. }
  5493. return markFunction(function(seed2, results, context2, xml) {
  5494. var temp, i, elem, preMap = [], postMap = [], preexisting = results.length, elems = seed2 || multipleContexts(selector || "*", context2.nodeType ? [context2] : context2, []), matcherIn = preFilter && (seed2 || !selector) ? condense(elems, preMap, preFilter, context2, xml) : elems, matcherOut = matcher ? postFinder || (seed2 ? preFilter : preexisting || postFilter) ? [] : results : matcherIn;
  5495. if (matcher) {
  5496. matcher(matcherIn, matcherOut, context2, xml);
  5497. }
  5498. if (postFilter) {
  5499. temp = condense(matcherOut, postMap);
  5500. postFilter(temp, [], context2, xml);
  5501. i = temp.length;
  5502. while (i--) {
  5503. if (elem = temp[i]) {
  5504. matcherOut[postMap[i]] = !(matcherIn[postMap[i]] = elem);
  5505. }
  5506. }
  5507. }
  5508. if (seed2) {
  5509. if (postFinder || preFilter) {
  5510. if (postFinder) {
  5511. temp = [];
  5512. i = matcherOut.length;
  5513. while (i--) {
  5514. if (elem = matcherOut[i]) {
  5515. temp.push(matcherIn[i] = elem);
  5516. }
  5517. }
  5518. postFinder(null, matcherOut = [], temp, xml);
  5519. }
  5520. i = matcherOut.length;
  5521. while (i--) {
  5522. if ((elem = matcherOut[i]) && (temp = postFinder ? indexOf.call(seed2, elem) : preMap[i]) > -1) {
  5523. seed2[temp] = !(results[temp] = elem);
  5524. }
  5525. }
  5526. }
  5527. } else {
  5528. matcherOut = condense(matcherOut === results ? matcherOut.splice(preexisting, matcherOut.length) : matcherOut);
  5529. if (postFinder) {
  5530. postFinder(null, results, matcherOut, xml);
  5531. } else {
  5532. push$1.apply(results, matcherOut);
  5533. }
  5534. }
  5535. });
  5536. }
  5537. function matcherFromTokens(tokens) {
  5538. 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) {
  5539. return elem === checkContext;
  5540. }, implicitRelative, true), matchAnyContext = addCombinator(function(elem) {
  5541. return indexOf.call(checkContext, elem) > -1;
  5542. }, implicitRelative, true), matchers = [function(elem, context2, xml) {
  5543. var ret = !leadingRelative && (xml || context2 !== outermostContext) || ((checkContext = context2).nodeType ? matchContext(elem, context2, xml) : matchAnyContext(elem, context2, xml));
  5544. checkContext = null;
  5545. return ret;
  5546. }];
  5547. for (; i < len; i++) {
  5548. if (matcher = Expr.relative[tokens[i].type]) {
  5549. matchers = [addCombinator(elementMatcher(matchers), matcher)];
  5550. } else {
  5551. matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches);
  5552. if (matcher[expando]) {
  5553. j = ++i;
  5554. for (; j < len; j++) {
  5555. if (Expr.relative[tokens[j].type]) {
  5556. break;
  5557. }
  5558. }
  5559. 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));
  5560. }
  5561. matchers.push(matcher);
  5562. }
  5563. }
  5564. return elementMatcher(matchers);
  5565. }
  5566. function matcherFromGroupMatchers(elementMatchers, setMatchers) {
  5567. var bySet = setMatchers.length > 0, byElement = elementMatchers.length > 0, superMatcher = function(seed2, context2, xml, results, outermost) {
  5568. var elem, j, matcher, matchedCount = 0, i = "0", unmatched = seed2 && [], setMatched = [], contextBackup = outermostContext, elems = seed2 || byElement && Expr.find.TAG("*", outermost), dirrunsUnique = dirruns += contextBackup == null ? 1 : Math.random() || 0.1, len = elems.length;
  5569. if (outermost) {
  5570. outermostContext = context2 !== document$1 && context2;
  5571. }
  5572. for (; i !== len && (elem = elems[i]) != null; i++) {
  5573. if (byElement && elem) {
  5574. j = 0;
  5575. while (matcher = elementMatchers[j++]) {
  5576. if (matcher(elem, context2, xml)) {
  5577. results.push(elem);
  5578. break;
  5579. }
  5580. }
  5581. if (outermost) {
  5582. dirruns = dirrunsUnique;
  5583. }
  5584. }
  5585. if (bySet) {
  5586. if (elem = !matcher && elem) {
  5587. matchedCount--;
  5588. }
  5589. if (seed2) {
  5590. unmatched.push(elem);
  5591. }
  5592. }
  5593. }
  5594. matchedCount += i;
  5595. if (bySet && i !== matchedCount) {
  5596. j = 0;
  5597. while (matcher = setMatchers[j++]) {
  5598. matcher(unmatched, setMatched, context2, xml);
  5599. }
  5600. if (seed2) {
  5601. if (matchedCount > 0) {
  5602. while (i--) {
  5603. if (!(unmatched[i] || setMatched[i])) {
  5604. setMatched[i] = pop.call(results);
  5605. }
  5606. }
  5607. }
  5608. setMatched = condense(setMatched);
  5609. }
  5610. push$1.apply(results, setMatched);
  5611. if (outermost && !seed2 && setMatched.length > 0 && matchedCount + setMatchers.length > 1) {
  5612. Sizzle.uniqueSort(results);
  5613. }
  5614. }
  5615. if (outermost) {
  5616. dirruns = dirrunsUnique;
  5617. outermostContext = contextBackup;
  5618. }
  5619. return unmatched;
  5620. };
  5621. return bySet ? markFunction(superMatcher) : superMatcher;
  5622. }
  5623. compile = Sizzle.compile = function(selector, match2) {
  5624. var i, setMatchers = [], elementMatchers = [], cached2 = compilerCache[selector + " "];
  5625. if (!cached2) {
  5626. if (!match2) {
  5627. match2 = tokenize(selector);
  5628. }
  5629. i = match2.length;
  5630. while (i--) {
  5631. cached2 = matcherFromTokens(match2[i]);
  5632. if (cached2[expando]) {
  5633. setMatchers.push(cached2);
  5634. } else {
  5635. elementMatchers.push(cached2);
  5636. }
  5637. }
  5638. cached2 = compilerCache(selector, matcherFromGroupMatchers(elementMatchers, setMatchers));
  5639. cached2.selector = selector;
  5640. }
  5641. return cached2;
  5642. };
  5643. select$1 = Sizzle.select = function(selector, context2, results, seed2) {
  5644. var i, tokens, token, type2, find2, compiled = typeof selector === "function" && selector, match2 = !seed2 && tokenize(selector = compiled.selector || selector);
  5645. results = results || [];
  5646. if (match2.length === 1) {
  5647. tokens = match2[0] = match2[0].slice(0);
  5648. if (tokens.length > 2 && (token = tokens[0]).type === "ID" && support.getById && context2.nodeType === 9 && documentIsHTML && Expr.relative[tokens[1].type]) {
  5649. context2 = (Expr.find.ID(token.matches[0].replace(runescape, funescape), context2) || [])[0];
  5650. if (!context2) {
  5651. return results;
  5652. } else if (compiled) {
  5653. context2 = context2.parentNode;
  5654. }
  5655. selector = selector.slice(tokens.shift().value.length);
  5656. }
  5657. i = matchExpr.needsContext.test(selector) ? 0 : tokens.length;
  5658. while (i--) {
  5659. token = tokens[i];
  5660. if (Expr.relative[type2 = token.type]) {
  5661. break;
  5662. }
  5663. if (find2 = Expr.find[type2]) {
  5664. if (seed2 = find2(token.matches[0].replace(runescape, funescape), rsibling.test(tokens[0].type) && testContext(context2.parentNode) || context2)) {
  5665. tokens.splice(i, 1);
  5666. selector = seed2.length && toSelector(tokens);
  5667. if (!selector) {
  5668. push$1.apply(results, seed2);
  5669. return results;
  5670. }
  5671. break;
  5672. }
  5673. }
  5674. }
  5675. }
  5676. (compiled || compile(selector, match2))(seed2, context2, !documentIsHTML, results, rsibling.test(selector) && testContext(context2.parentNode) || context2);
  5677. return results;
  5678. };
  5679. support.sortStable = expando.split("").sort(sortOrder).join("") === expando;
  5680. support.detectDuplicates = !!hasDuplicate;
  5681. setDocument();
  5682. support.sortDetached = true;
  5683. var doc = document;
  5684. var push = Array.prototype.push;
  5685. var slice = Array.prototype.slice;
  5686. var rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/;
  5687. var Event$1 = EventUtils.Event;
  5688. var skipUniques = Tools.makeMap("children,contents,next,prev");
  5689. var isDefined = function(obj) {
  5690. return typeof obj !== "undefined";
  5691. };
  5692. var isString = function(obj) {
  5693. return typeof obj === "string";
  5694. };
  5695. var isWindow = function(obj) {
  5696. return obj && obj === obj.window;
  5697. };
  5698. var createFragment$1 = function(html, fragDoc) {
  5699. fragDoc = fragDoc || doc;
  5700. var container = fragDoc.createElement("div");
  5701. var frag = fragDoc.createDocumentFragment();
  5702. container.innerHTML = html;
  5703. var node;
  5704. while (node = container.firstChild) {
  5705. frag.appendChild(node);
  5706. }
  5707. return frag;
  5708. };
  5709. var domManipulate = function(targetNodes, sourceItem, callback, reverse2) {
  5710. var i;
  5711. if (isString(sourceItem)) {
  5712. sourceItem = createFragment$1(sourceItem, getElementDocument(targetNodes[0]));
  5713. } else if (sourceItem.length && !sourceItem.nodeType) {
  5714. sourceItem = DomQuery.makeArray(sourceItem);
  5715. if (reverse2) {
  5716. for (i = sourceItem.length - 1; i >= 0; i--) {
  5717. domManipulate(targetNodes, sourceItem[i], callback, reverse2);
  5718. }
  5719. } else {
  5720. for (i = 0; i < sourceItem.length; i++) {
  5721. domManipulate(targetNodes, sourceItem[i], callback, reverse2);
  5722. }
  5723. }
  5724. return targetNodes;
  5725. }
  5726. if (sourceItem.nodeType) {
  5727. i = targetNodes.length;
  5728. while (i--) {
  5729. callback.call(targetNodes[i], sourceItem);
  5730. }
  5731. }
  5732. return targetNodes;
  5733. };
  5734. var hasClass = function(node, className) {
  5735. return node && className && (" " + node.className + " ").indexOf(" " + className + " ") !== -1;
  5736. };
  5737. var wrap$2 = function(elements, wrapper, all2) {
  5738. var lastParent, newWrapper;
  5739. wrapper = DomQuery(wrapper)[0];
  5740. elements.each(function() {
  5741. var self2 = this;
  5742. if (!all2 || lastParent !== self2.parentNode) {
  5743. lastParent = self2.parentNode;
  5744. newWrapper = wrapper.cloneNode(false);
  5745. self2.parentNode.insertBefore(newWrapper, self2);
  5746. newWrapper.appendChild(self2);
  5747. } else {
  5748. newWrapper.appendChild(self2);
  5749. }
  5750. });
  5751. return elements;
  5752. };
  5753. var numericCssMap = Tools.makeMap("fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom", " ");
  5754. var booleanMap = Tools.makeMap("checked compact declare defer disabled ismap multiple nohref noshade nowrap readonly selected", " ");
  5755. var propFix = {
  5756. for: "htmlFor",
  5757. class: "className",
  5758. readonly: "readOnly"
  5759. };
  5760. var cssFix = { float: "cssFloat" };
  5761. var attrHooks = {}, cssHooks = {};
  5762. var DomQueryConstructor = function(selector, context2) {
  5763. return new DomQuery.fn.init(selector, context2);
  5764. };
  5765. var inArray$1 = function(item, array) {
  5766. var i;
  5767. if (array.indexOf) {
  5768. return array.indexOf(item);
  5769. }
  5770. i = array.length;
  5771. while (i--) {
  5772. if (array[i] === item) {
  5773. return i;
  5774. }
  5775. }
  5776. return -1;
  5777. };
  5778. var whiteSpaceRegExp = /^\s*|\s*$/g;
  5779. var trim$1 = function(str) {
  5780. return str === null || str === void 0 ? "" : ("" + str).replace(whiteSpaceRegExp, "");
  5781. };
  5782. var each$g = function(obj, callback) {
  5783. var length, key, i, value2;
  5784. if (obj) {
  5785. length = obj.length;
  5786. if (length === void 0) {
  5787. for (key in obj) {
  5788. if (obj.hasOwnProperty(key)) {
  5789. value2 = obj[key];
  5790. if (callback.call(value2, key, value2) === false) {
  5791. break;
  5792. }
  5793. }
  5794. }
  5795. } else {
  5796. for (i = 0; i < length; i++) {
  5797. value2 = obj[i];
  5798. if (callback.call(value2, i, value2) === false) {
  5799. break;
  5800. }
  5801. }
  5802. }
  5803. }
  5804. return obj;
  5805. };
  5806. var grep$2 = function(array, callback) {
  5807. var out = [];
  5808. each$g(array, function(i, item) {
  5809. if (callback(item, i)) {
  5810. out.push(item);
  5811. }
  5812. });
  5813. return out;
  5814. };
  5815. var getElementDocument = function(element) {
  5816. if (!element) {
  5817. return doc;
  5818. }
  5819. if (element.nodeType === 9) {
  5820. return element;
  5821. }
  5822. return element.ownerDocument;
  5823. };
  5824. DomQueryConstructor.fn = DomQueryConstructor.prototype = {
  5825. constructor: DomQueryConstructor,
  5826. selector: "",
  5827. context: null,
  5828. length: 0,
  5829. init: function(selector, context2) {
  5830. var self2 = this;
  5831. var match2, node;
  5832. if (!selector) {
  5833. return self2;
  5834. }
  5835. if (selector.nodeType) {
  5836. self2.context = self2[0] = selector;
  5837. self2.length = 1;
  5838. return self2;
  5839. }
  5840. if (context2 && context2.nodeType) {
  5841. self2.context = context2;
  5842. } else {
  5843. if (context2) {
  5844. return DomQuery(selector).attr(context2);
  5845. }
  5846. self2.context = context2 = document;
  5847. }
  5848. if (isString(selector)) {
  5849. self2.selector = selector;
  5850. if (selector.charAt(0) === "<" && selector.charAt(selector.length - 1) === ">" && selector.length >= 3) {
  5851. match2 = [
  5852. null,
  5853. selector,
  5854. null
  5855. ];
  5856. } else {
  5857. match2 = rquickExpr.exec(selector);
  5858. }
  5859. if (match2) {
  5860. if (match2[1]) {
  5861. node = createFragment$1(selector, getElementDocument(context2)).firstChild;
  5862. while (node) {
  5863. push.call(self2, node);
  5864. node = node.nextSibling;
  5865. }
  5866. } else {
  5867. node = getElementDocument(context2).getElementById(match2[2]);
  5868. if (!node) {
  5869. return self2;
  5870. }
  5871. if (node.id !== match2[2]) {
  5872. return self2.find(selector);
  5873. }
  5874. self2.length = 1;
  5875. self2[0] = node;
  5876. }
  5877. } else {
  5878. return DomQuery(context2).find(selector);
  5879. }
  5880. } else {
  5881. this.add(selector, false);
  5882. }
  5883. return self2;
  5884. },
  5885. toArray: function() {
  5886. return Tools.toArray(this);
  5887. },
  5888. add: function(items, sort2) {
  5889. var self2 = this;
  5890. var nodes, i;
  5891. if (isString(items)) {
  5892. return self2.add(DomQuery(items));
  5893. }
  5894. if (sort2 !== false) {
  5895. nodes = DomQuery.unique(self2.toArray().concat(DomQuery.makeArray(items)));
  5896. self2.length = nodes.length;
  5897. for (i = 0; i < nodes.length; i++) {
  5898. self2[i] = nodes[i];
  5899. }
  5900. } else {
  5901. push.apply(self2, DomQuery.makeArray(items));
  5902. }
  5903. return self2;
  5904. },
  5905. attr: function(name2, value2) {
  5906. var self2 = this;
  5907. var hook;
  5908. if (typeof name2 === "object") {
  5909. each$g(name2, function(name3, value3) {
  5910. self2.attr(name3, value3);
  5911. });
  5912. } else if (isDefined(value2)) {
  5913. this.each(function() {
  5914. var hook2;
  5915. if (this.nodeType === 1) {
  5916. hook2 = attrHooks[name2];
  5917. if (hook2 && hook2.set) {
  5918. hook2.set(this, value2);
  5919. return;
  5920. }
  5921. if (value2 === null) {
  5922. this.removeAttribute(name2, 2);
  5923. } else {
  5924. this.setAttribute(name2, value2, 2);
  5925. }
  5926. }
  5927. });
  5928. } else {
  5929. if (self2[0] && self2[0].nodeType === 1) {
  5930. hook = attrHooks[name2];
  5931. if (hook && hook.get) {
  5932. return hook.get(self2[0], name2);
  5933. }
  5934. if (booleanMap[name2]) {
  5935. return self2.prop(name2) ? name2 : void 0;
  5936. }
  5937. value2 = self2[0].getAttribute(name2, 2);
  5938. if (value2 === null) {
  5939. value2 = void 0;
  5940. }
  5941. }
  5942. return value2;
  5943. }
  5944. return self2;
  5945. },
  5946. removeAttr: function(name2) {
  5947. return this.attr(name2, null);
  5948. },
  5949. prop: function(name2, value2) {
  5950. var self2 = this;
  5951. name2 = propFix[name2] || name2;
  5952. if (typeof name2 === "object") {
  5953. each$g(name2, function(name3, value3) {
  5954. self2.prop(name3, value3);
  5955. });
  5956. } else if (isDefined(value2)) {
  5957. this.each(function() {
  5958. if (this.nodeType === 1) {
  5959. this[name2] = value2;
  5960. }
  5961. });
  5962. } else {
  5963. if (self2[0] && self2[0].nodeType && name2 in self2[0]) {
  5964. return self2[0][name2];
  5965. }
  5966. return value2;
  5967. }
  5968. return self2;
  5969. },
  5970. css: function(name2, value2) {
  5971. var self2 = this;
  5972. var elm, hook;
  5973. var camel = function(name3) {
  5974. return name3.replace(/-(\D)/g, function(a, b) {
  5975. return b.toUpperCase();
  5976. });
  5977. };
  5978. var dashed = function(name3) {
  5979. return name3.replace(/[A-Z]/g, function(a) {
  5980. return "-" + a;
  5981. });
  5982. };
  5983. if (typeof name2 === "object") {
  5984. each$g(name2, function(name3, value3) {
  5985. self2.css(name3, value3);
  5986. });
  5987. } else {
  5988. if (isDefined(value2)) {
  5989. name2 = camel(name2);
  5990. if (typeof value2 === "number" && !numericCssMap[name2]) {
  5991. value2 = value2.toString() + "px";
  5992. }
  5993. self2.each(function() {
  5994. var style = this.style;
  5995. hook = cssHooks[name2];
  5996. if (hook && hook.set) {
  5997. hook.set(this, value2);
  5998. return;
  5999. }
  6000. try {
  6001. this.style[cssFix[name2] || name2] = value2;
  6002. } catch (ex) {
  6003. }
  6004. if (value2 === null || value2 === "") {
  6005. if (style.removeProperty) {
  6006. style.removeProperty(dashed(name2));
  6007. } else {
  6008. style.removeAttribute(name2);
  6009. }
  6010. }
  6011. });
  6012. } else {
  6013. elm = self2[0];
  6014. hook = cssHooks[name2];
  6015. if (hook && hook.get) {
  6016. return hook.get(elm);
  6017. }
  6018. if (elm.ownerDocument.defaultView) {
  6019. try {
  6020. return elm.ownerDocument.defaultView.getComputedStyle(elm, null).getPropertyValue(dashed(name2));
  6021. } catch (ex) {
  6022. return void 0;
  6023. }
  6024. } else if (elm.currentStyle) {
  6025. return elm.currentStyle[camel(name2)];
  6026. } else {
  6027. return "";
  6028. }
  6029. }
  6030. }
  6031. return self2;
  6032. },
  6033. remove: function() {
  6034. var self2 = this;
  6035. var node, i = this.length;
  6036. while (i--) {
  6037. node = self2[i];
  6038. Event$1.clean(node);
  6039. if (node.parentNode) {
  6040. node.parentNode.removeChild(node);
  6041. }
  6042. }
  6043. return this;
  6044. },
  6045. empty: function() {
  6046. var self2 = this;
  6047. var node, i = this.length;
  6048. while (i--) {
  6049. node = self2[i];
  6050. while (node.firstChild) {
  6051. node.removeChild(node.firstChild);
  6052. }
  6053. }
  6054. return this;
  6055. },
  6056. html: function(value2) {
  6057. var self2 = this;
  6058. var i;
  6059. if (isDefined(value2)) {
  6060. i = self2.length;
  6061. try {
  6062. while (i--) {
  6063. self2[i].innerHTML = value2;
  6064. }
  6065. } catch (ex) {
  6066. DomQuery(self2[i]).empty().append(value2);
  6067. }
  6068. return self2;
  6069. }
  6070. return self2[0] ? self2[0].innerHTML : "";
  6071. },
  6072. text: function(value2) {
  6073. var self2 = this;
  6074. var i;
  6075. if (isDefined(value2)) {
  6076. i = self2.length;
  6077. while (i--) {
  6078. if ("innerText" in self2[i]) {
  6079. self2[i].innerText = value2;
  6080. } else {
  6081. self2[0].textContent = value2;
  6082. }
  6083. }
  6084. return self2;
  6085. }
  6086. return self2[0] ? self2[0].innerText || self2[0].textContent : "";
  6087. },
  6088. append: function() {
  6089. return domManipulate(this, arguments, function(node) {
  6090. if (this.nodeType === 1 || this.host && this.host.nodeType === 1) {
  6091. this.appendChild(node);
  6092. }
  6093. });
  6094. },
  6095. prepend: function() {
  6096. return domManipulate(this, arguments, function(node) {
  6097. if (this.nodeType === 1 || this.host && this.host.nodeType === 1) {
  6098. this.insertBefore(node, this.firstChild);
  6099. }
  6100. }, true);
  6101. },
  6102. before: function() {
  6103. var self2 = this;
  6104. if (self2[0] && self2[0].parentNode) {
  6105. return domManipulate(self2, arguments, function(node) {
  6106. this.parentNode.insertBefore(node, this);
  6107. });
  6108. }
  6109. return self2;
  6110. },
  6111. after: function() {
  6112. var self2 = this;
  6113. if (self2[0] && self2[0].parentNode) {
  6114. return domManipulate(self2, arguments, function(node) {
  6115. this.parentNode.insertBefore(node, this.nextSibling);
  6116. }, true);
  6117. }
  6118. return self2;
  6119. },
  6120. appendTo: function(val) {
  6121. DomQuery(val).append(this);
  6122. return this;
  6123. },
  6124. prependTo: function(val) {
  6125. DomQuery(val).prepend(this);
  6126. return this;
  6127. },
  6128. replaceWith: function(content) {
  6129. return this.before(content).remove();
  6130. },
  6131. wrap: function(content) {
  6132. return wrap$2(this, content);
  6133. },
  6134. wrapAll: function(content) {
  6135. return wrap$2(this, content, true);
  6136. },
  6137. wrapInner: function(content) {
  6138. this.each(function() {
  6139. DomQuery(this).contents().wrapAll(content);
  6140. });
  6141. return this;
  6142. },
  6143. unwrap: function() {
  6144. return this.parent().each(function() {
  6145. DomQuery(this).replaceWith(this.childNodes);
  6146. });
  6147. },
  6148. clone: function() {
  6149. var result = [];
  6150. this.each(function() {
  6151. result.push(this.cloneNode(true));
  6152. });
  6153. return DomQuery(result);
  6154. },
  6155. addClass: function(className) {
  6156. return this.toggleClass(className, true);
  6157. },
  6158. removeClass: function(className) {
  6159. return this.toggleClass(className, false);
  6160. },
  6161. toggleClass: function(className, state) {
  6162. var self2 = this;
  6163. if (typeof className !== "string") {
  6164. return self2;
  6165. }
  6166. if (className.indexOf(" ") !== -1) {
  6167. each$g(className.split(" "), function() {
  6168. self2.toggleClass(this, state);
  6169. });
  6170. } else {
  6171. self2.each(function(index, node) {
  6172. var classState = hasClass(node, className);
  6173. if (classState !== state) {
  6174. var existingClassName = node.className;
  6175. if (classState) {
  6176. node.className = trim$1((" " + existingClassName + " ").replace(" " + className + " ", " "));
  6177. } else {
  6178. node.className += existingClassName ? " " + className : className;
  6179. }
  6180. }
  6181. });
  6182. }
  6183. return self2;
  6184. },
  6185. hasClass: function(className) {
  6186. return hasClass(this[0], className);
  6187. },
  6188. each: function(callback) {
  6189. return each$g(this, callback);
  6190. },
  6191. on: function(name2, callback) {
  6192. return this.each(function() {
  6193. Event$1.bind(this, name2, callback);
  6194. });
  6195. },
  6196. off: function(name2, callback) {
  6197. return this.each(function() {
  6198. Event$1.unbind(this, name2, callback);
  6199. });
  6200. },
  6201. trigger: function(name2) {
  6202. return this.each(function() {
  6203. if (typeof name2 === "object") {
  6204. Event$1.fire(this, name2.type, name2);
  6205. } else {
  6206. Event$1.fire(this, name2);
  6207. }
  6208. });
  6209. },
  6210. show: function() {
  6211. return this.css("display", "");
  6212. },
  6213. hide: function() {
  6214. return this.css("display", "none");
  6215. },
  6216. slice: function() {
  6217. return DomQuery(slice.apply(this, arguments));
  6218. },
  6219. eq: function(index) {
  6220. return index === -1 ? this.slice(index) : this.slice(index, +index + 1);
  6221. },
  6222. first: function() {
  6223. return this.eq(0);
  6224. },
  6225. last: function() {
  6226. return this.eq(-1);
  6227. },
  6228. find: function(selector) {
  6229. var i, l;
  6230. var ret = [];
  6231. for (i = 0, l = this.length; i < l; i++) {
  6232. DomQuery.find(selector, this[i], ret);
  6233. }
  6234. return DomQuery(ret);
  6235. },
  6236. filter: function(selector) {
  6237. if (typeof selector === "function") {
  6238. return DomQuery(grep$2(this.toArray(), function(item, i) {
  6239. return selector(i, item);
  6240. }));
  6241. }
  6242. return DomQuery(DomQuery.filter(selector, this.toArray()));
  6243. },
  6244. closest: function(selector) {
  6245. var result = [];
  6246. if (selector instanceof DomQuery) {
  6247. selector = selector[0];
  6248. }
  6249. this.each(function(i, node) {
  6250. while (node) {
  6251. if (typeof selector === "string" && DomQuery(node).is(selector)) {
  6252. result.push(node);
  6253. break;
  6254. } else if (node === selector) {
  6255. result.push(node);
  6256. break;
  6257. }
  6258. node = node.parentNode;
  6259. }
  6260. });
  6261. return DomQuery(result);
  6262. },
  6263. offset: function(offset) {
  6264. var elm, doc2, docElm;
  6265. var x = 0, y = 0, pos;
  6266. if (!offset) {
  6267. elm = this[0];
  6268. if (elm) {
  6269. doc2 = elm.ownerDocument;
  6270. docElm = doc2.documentElement;
  6271. if (elm.getBoundingClientRect) {
  6272. pos = elm.getBoundingClientRect();
  6273. x = pos.left + (docElm.scrollLeft || doc2.body.scrollLeft) - docElm.clientLeft;
  6274. y = pos.top + (docElm.scrollTop || doc2.body.scrollTop) - docElm.clientTop;
  6275. }
  6276. }
  6277. return {
  6278. left: x,
  6279. top: y
  6280. };
  6281. }
  6282. return this.css(offset);
  6283. },
  6284. push,
  6285. sort: Array.prototype.sort,
  6286. splice: Array.prototype.splice
  6287. };
  6288. Tools.extend(DomQueryConstructor, {
  6289. extend: Tools.extend,
  6290. makeArray: function(object) {
  6291. if (isWindow(object) || object.nodeType) {
  6292. return [object];
  6293. }
  6294. return Tools.toArray(object);
  6295. },
  6296. inArray: inArray$1,
  6297. isArray: Tools.isArray,
  6298. each: each$g,
  6299. trim: trim$1,
  6300. grep: grep$2,
  6301. find: Sizzle,
  6302. expr: Sizzle.selectors,
  6303. unique: Sizzle.uniqueSort,
  6304. text: Sizzle.getText,
  6305. contains: Sizzle.contains,
  6306. filter: function(expr, elems, not2) {
  6307. var i = elems.length;
  6308. if (not2) {
  6309. expr = ":not(" + expr + ")";
  6310. }
  6311. while (i--) {
  6312. if (elems[i].nodeType !== 1) {
  6313. elems.splice(i, 1);
  6314. }
  6315. }
  6316. if (elems.length === 1) {
  6317. elems = DomQuery.find.matchesSelector(elems[0], expr) ? [elems[0]] : [];
  6318. } else {
  6319. elems = DomQuery.find.matches(expr, elems);
  6320. }
  6321. return elems;
  6322. }
  6323. });
  6324. var dir = function(el, prop, until) {
  6325. var matched = [];
  6326. var cur = el[prop];
  6327. if (typeof until !== "string" && until instanceof DomQuery) {
  6328. until = until[0];
  6329. }
  6330. while (cur && cur.nodeType !== 9) {
  6331. if (until !== void 0) {
  6332. if (cur === until) {
  6333. break;
  6334. }
  6335. if (typeof until === "string" && DomQuery(cur).is(until)) {
  6336. break;
  6337. }
  6338. }
  6339. if (cur.nodeType === 1) {
  6340. matched.push(cur);
  6341. }
  6342. cur = cur[prop];
  6343. }
  6344. return matched;
  6345. };
  6346. var sibling$1 = function(node, siblingName, nodeType, until) {
  6347. var result = [];
  6348. if (until instanceof DomQuery) {
  6349. until = until[0];
  6350. }
  6351. for (; node; node = node[siblingName]) {
  6352. if (nodeType && node.nodeType !== nodeType) {
  6353. continue;
  6354. }
  6355. if (until !== void 0) {
  6356. if (node === until) {
  6357. break;
  6358. }
  6359. if (typeof until === "string" && DomQuery(node).is(until)) {
  6360. break;
  6361. }
  6362. }
  6363. result.push(node);
  6364. }
  6365. return result;
  6366. };
  6367. var firstSibling = function(node, siblingName, nodeType) {
  6368. for (node = node[siblingName]; node; node = node[siblingName]) {
  6369. if (node.nodeType === nodeType) {
  6370. return node;
  6371. }
  6372. }
  6373. return null;
  6374. };
  6375. each$g({
  6376. parent: function(node) {
  6377. var parent2 = node.parentNode;
  6378. return parent2 && parent2.nodeType !== 11 ? parent2 : null;
  6379. },
  6380. parents: function(node) {
  6381. return dir(node, "parentNode");
  6382. },
  6383. next: function(node) {
  6384. return firstSibling(node, "nextSibling", 1);
  6385. },
  6386. prev: function(node) {
  6387. return firstSibling(node, "previousSibling", 1);
  6388. },
  6389. children: function(node) {
  6390. return sibling$1(node.firstChild, "nextSibling", 1);
  6391. },
  6392. contents: function(node) {
  6393. return Tools.toArray((node.nodeName === "iframe" ? node.contentDocument || node.contentWindow.document : node).childNodes);
  6394. }
  6395. }, function(name2, fn) {
  6396. DomQueryConstructor.fn[name2] = function(selector) {
  6397. var self2 = this;
  6398. var result = [];
  6399. self2.each(function() {
  6400. var nodes = fn.call(result, this, selector, result);
  6401. if (nodes) {
  6402. if (DomQuery.isArray(nodes)) {
  6403. result.push.apply(result, nodes);
  6404. } else {
  6405. result.push(nodes);
  6406. }
  6407. }
  6408. });
  6409. if (this.length > 1) {
  6410. if (!skipUniques[name2]) {
  6411. result = DomQuery.unique(result);
  6412. }
  6413. if (name2.indexOf("parents") === 0) {
  6414. result = result.reverse();
  6415. }
  6416. }
  6417. var wrappedResult = DomQuery(result);
  6418. if (selector) {
  6419. return wrappedResult.filter(selector);
  6420. }
  6421. return wrappedResult;
  6422. };
  6423. });
  6424. each$g({
  6425. parentsUntil: function(node, until) {
  6426. return dir(node, "parentNode", until);
  6427. },
  6428. nextUntil: function(node, until) {
  6429. return sibling$1(node, "nextSibling", 1, until).slice(1);
  6430. },
  6431. prevUntil: function(node, until) {
  6432. return sibling$1(node, "previousSibling", 1, until).slice(1);
  6433. }
  6434. }, function(name2, fn) {
  6435. DomQueryConstructor.fn[name2] = function(selector, filter2) {
  6436. var self2 = this;
  6437. var result = [];
  6438. self2.each(function() {
  6439. var nodes = fn.call(result, this, selector, result);
  6440. if (nodes) {
  6441. if (DomQuery.isArray(nodes)) {
  6442. result.push.apply(result, nodes);
  6443. } else {
  6444. result.push(nodes);
  6445. }
  6446. }
  6447. });
  6448. if (this.length > 1) {
  6449. result = DomQuery.unique(result);
  6450. if (name2.indexOf("parents") === 0 || name2 === "prevUntil") {
  6451. result = result.reverse();
  6452. }
  6453. }
  6454. var wrappedResult = DomQuery(result);
  6455. if (filter2) {
  6456. return wrappedResult.filter(filter2);
  6457. }
  6458. return wrappedResult;
  6459. };
  6460. });
  6461. DomQueryConstructor.fn.is = function(selector) {
  6462. return !!selector && this.filter(selector).length > 0;
  6463. };
  6464. DomQueryConstructor.fn.init.prototype = DomQueryConstructor.fn;
  6465. DomQueryConstructor.overrideDefaults = function(callback) {
  6466. var defaults;
  6467. var sub = function(selector, context2) {
  6468. defaults = defaults || callback();
  6469. if (arguments.length === 0) {
  6470. selector = defaults.element;
  6471. }
  6472. if (!context2) {
  6473. context2 = defaults.context;
  6474. }
  6475. return new sub.fn.init(selector, context2);
  6476. };
  6477. DomQuery.extend(sub, this);
  6478. return sub;
  6479. };
  6480. DomQueryConstructor.attrHooks = attrHooks;
  6481. DomQueryConstructor.cssHooks = cssHooks;
  6482. var DomQuery = DomQueryConstructor;
  6483. var each$f = Tools.each;
  6484. var grep$1 = Tools.grep;
  6485. var isIE = Env.ie;
  6486. var simpleSelectorRe = /^([a-z0-9],?)+$/i;
  6487. var setupAttrHooks = function(styles, settings, getContext) {
  6488. var keepValues = settings.keep_values;
  6489. var keepUrlHook = {
  6490. set: function($elm, value2, name2) {
  6491. if (settings.url_converter && value2 !== null) {
  6492. value2 = settings.url_converter.call(settings.url_converter_scope || getContext(), value2, name2, $elm[0]);
  6493. }
  6494. $elm.attr("data-mce-" + name2, value2).attr(name2, value2);
  6495. },
  6496. get: function($elm, name2) {
  6497. return $elm.attr("data-mce-" + name2) || $elm.attr(name2);
  6498. }
  6499. };
  6500. var attrHooks2 = {
  6501. style: {
  6502. set: function($elm, value2) {
  6503. if (value2 !== null && typeof value2 === "object") {
  6504. $elm.css(value2);
  6505. return;
  6506. }
  6507. if (keepValues) {
  6508. $elm.attr("data-mce-style", value2);
  6509. }
  6510. if (value2 !== null && typeof value2 === "string") {
  6511. $elm.removeAttr("style");
  6512. $elm.css(styles.parse(value2));
  6513. } else {
  6514. $elm.attr("style", value2);
  6515. }
  6516. },
  6517. get: function($elm) {
  6518. var value2 = $elm.attr("data-mce-style") || $elm.attr("style");
  6519. value2 = styles.serialize(styles.parse(value2), $elm[0].nodeName);
  6520. return value2;
  6521. }
  6522. }
  6523. };
  6524. if (keepValues) {
  6525. attrHooks2.href = attrHooks2.src = keepUrlHook;
  6526. }
  6527. return attrHooks2;
  6528. };
  6529. var updateInternalStyleAttr = function(styles, $elm) {
  6530. var rawValue = $elm.attr("style");
  6531. var value2 = styles.serialize(styles.parse(rawValue), $elm[0].nodeName);
  6532. if (!value2) {
  6533. value2 = null;
  6534. }
  6535. $elm.attr("data-mce-style", value2);
  6536. };
  6537. var findNodeIndex = function(node, normalized) {
  6538. var idx = 0, lastNodeType, nodeType;
  6539. if (node) {
  6540. for (lastNodeType = node.nodeType, node = node.previousSibling; node; node = node.previousSibling) {
  6541. nodeType = node.nodeType;
  6542. if (normalized && nodeType === 3) {
  6543. if (nodeType === lastNodeType || !node.nodeValue.length) {
  6544. continue;
  6545. }
  6546. }
  6547. idx++;
  6548. lastNodeType = nodeType;
  6549. }
  6550. }
  6551. return idx;
  6552. };
  6553. var DOMUtils = function(doc2, settings) {
  6554. if (settings === void 0) {
  6555. settings = {};
  6556. }
  6557. var addedStyles = {};
  6558. var win = window;
  6559. var files = {};
  6560. var counter = 0;
  6561. var stdMode = true;
  6562. var boxModel = true;
  6563. var styleSheetLoader = instance.forElement(SugarElement.fromDom(doc2), {
  6564. contentCssCors: settings.contentCssCors,
  6565. referrerPolicy: settings.referrerPolicy
  6566. });
  6567. var boundEvents = [];
  6568. var schema = settings.schema ? settings.schema : Schema({});
  6569. var styles = Styles({
  6570. url_converter: settings.url_converter,
  6571. url_converter_scope: settings.url_converter_scope
  6572. }, settings.schema);
  6573. var events = settings.ownEvents ? new EventUtils() : EventUtils.Event;
  6574. var blockElementsMap = schema.getBlockElements();
  6575. var $ = DomQuery.overrideDefaults(function() {
  6576. return {
  6577. context: doc2,
  6578. element: self2.getRoot()
  6579. };
  6580. });
  6581. var isBlock2 = function(node) {
  6582. if (typeof node === "string") {
  6583. return !!blockElementsMap[node];
  6584. } else if (node) {
  6585. var type2 = node.nodeType;
  6586. if (type2) {
  6587. return !!(type2 === 1 && blockElementsMap[node.nodeName]);
  6588. }
  6589. }
  6590. return false;
  6591. };
  6592. var get2 = function(elm) {
  6593. return elm && doc2 && isString$1(elm) ? doc2.getElementById(elm) : elm;
  6594. };
  6595. var $$ = function(elm) {
  6596. return $(typeof elm === "string" ? get2(elm) : elm);
  6597. };
  6598. var getAttrib = function(elm, name2, defaultVal) {
  6599. var hook, value2;
  6600. var $elm = $$(elm);
  6601. if ($elm.length) {
  6602. hook = attrHooks2[name2];
  6603. if (hook && hook.get) {
  6604. value2 = hook.get($elm, name2);
  6605. } else {
  6606. value2 = $elm.attr(name2);
  6607. }
  6608. }
  6609. if (typeof value2 === "undefined") {
  6610. value2 = defaultVal || "";
  6611. }
  6612. return value2;
  6613. };
  6614. var getAttribs = function(elm) {
  6615. var node = get2(elm);
  6616. if (!node) {
  6617. return [];
  6618. }
  6619. return node.attributes;
  6620. };
  6621. var setAttrib = function(elm, name2, value2) {
  6622. if (value2 === "") {
  6623. value2 = null;
  6624. }
  6625. var $elm = $$(elm);
  6626. var originalValue = $elm.attr(name2);
  6627. if (!$elm.length) {
  6628. return;
  6629. }
  6630. var hook = attrHooks2[name2];
  6631. if (hook && hook.set) {
  6632. hook.set($elm, value2, name2);
  6633. } else {
  6634. $elm.attr(name2, value2);
  6635. }
  6636. if (originalValue !== value2 && settings.onSetAttrib) {
  6637. settings.onSetAttrib({
  6638. attrElm: $elm,
  6639. attrName: name2,
  6640. attrValue: value2
  6641. });
  6642. }
  6643. };
  6644. var clone2 = function(node, deep2) {
  6645. if (!isIE || node.nodeType !== 1 || deep2) {
  6646. return node.cloneNode(deep2);
  6647. } else {
  6648. var clone_1 = doc2.createElement(node.nodeName);
  6649. each$f(getAttribs(node), function(attr) {
  6650. setAttrib(clone_1, attr.nodeName, getAttrib(node, attr.nodeName));
  6651. });
  6652. return clone_1;
  6653. }
  6654. };
  6655. var getRoot = function() {
  6656. return settings.root_element || doc2.body;
  6657. };
  6658. var getViewPort = function(argWin) {
  6659. var vp = getBounds(argWin);
  6660. return {
  6661. x: vp.x,
  6662. y: vp.y,
  6663. w: vp.width,
  6664. h: vp.height
  6665. };
  6666. };
  6667. var getPos$1 = function(elm, rootElm) {
  6668. return getPos(doc2.body, get2(elm), rootElm);
  6669. };
  6670. var setStyle = function(elm, name2, value2) {
  6671. var $elm = isString$1(name2) ? $$(elm).css(name2, value2) : $$(elm).css(name2);
  6672. if (settings.update_styles) {
  6673. updateInternalStyleAttr(styles, $elm);
  6674. }
  6675. };
  6676. var setStyles = function(elm, stylesArg) {
  6677. var $elm = $$(elm).css(stylesArg);
  6678. if (settings.update_styles) {
  6679. updateInternalStyleAttr(styles, $elm);
  6680. }
  6681. };
  6682. var getStyle2 = function(elm, name2, computed) {
  6683. var $elm = $$(elm);
  6684. if (computed) {
  6685. return $elm.css(name2);
  6686. }
  6687. name2 = name2.replace(/-(\D)/g, function(a, b) {
  6688. return b.toUpperCase();
  6689. });
  6690. if (name2 === "float") {
  6691. name2 = Env.browser.isIE() ? "styleFloat" : "cssFloat";
  6692. }
  6693. return $elm[0] && $elm[0].style ? $elm[0].style[name2] : void 0;
  6694. };
  6695. var getSize = function(elm) {
  6696. var w, h;
  6697. elm = get2(elm);
  6698. w = getStyle2(elm, "width");
  6699. h = getStyle2(elm, "height");
  6700. if (w.indexOf("px") === -1) {
  6701. w = 0;
  6702. }
  6703. if (h.indexOf("px") === -1) {
  6704. h = 0;
  6705. }
  6706. return {
  6707. w: parseInt(w, 10) || elm.offsetWidth || elm.clientWidth,
  6708. h: parseInt(h, 10) || elm.offsetHeight || elm.clientHeight
  6709. };
  6710. };
  6711. var getRect = function(elm) {
  6712. elm = get2(elm);
  6713. var pos = getPos$1(elm);
  6714. var size = getSize(elm);
  6715. return {
  6716. x: pos.x,
  6717. y: pos.y,
  6718. w: size.w,
  6719. h: size.h
  6720. };
  6721. };
  6722. var is2 = function(elm, selector) {
  6723. var i;
  6724. if (!elm) {
  6725. return false;
  6726. }
  6727. if (!Array.isArray(elm)) {
  6728. if (selector === "*") {
  6729. return elm.nodeType === 1;
  6730. }
  6731. if (simpleSelectorRe.test(selector)) {
  6732. var selectors = selector.toLowerCase().split(/,/);
  6733. var elmName = elm.nodeName.toLowerCase();
  6734. for (i = selectors.length - 1; i >= 0; i--) {
  6735. if (selectors[i] === elmName) {
  6736. return true;
  6737. }
  6738. }
  6739. return false;
  6740. }
  6741. if (elm.nodeType && elm.nodeType !== 1) {
  6742. return false;
  6743. }
  6744. }
  6745. var elms = !Array.isArray(elm) ? [elm] : elm;
  6746. return Sizzle(selector, elms[0].ownerDocument || elms[0], null, elms).length > 0;
  6747. };
  6748. var getParents2 = function(elm, selector, root, collect) {
  6749. var result = [];
  6750. var selectorVal;
  6751. var node = get2(elm);
  6752. collect = collect === void 0;
  6753. root = root || (getRoot().nodeName !== "BODY" ? getRoot().parentNode : null);
  6754. if (Tools.is(selector, "string")) {
  6755. selectorVal = selector;
  6756. if (selector === "*") {
  6757. selector = function(node2) {
  6758. return node2.nodeType === 1;
  6759. };
  6760. } else {
  6761. selector = function(node2) {
  6762. return is2(node2, selectorVal);
  6763. };
  6764. }
  6765. }
  6766. while (node) {
  6767. if (node === root || isNullable(node.nodeType) || isDocument$1(node) || isDocumentFragment(node)) {
  6768. break;
  6769. }
  6770. if (!selector || typeof selector === "function" && selector(node)) {
  6771. if (collect) {
  6772. result.push(node);
  6773. } else {
  6774. return [node];
  6775. }
  6776. }
  6777. node = node.parentNode;
  6778. }
  6779. return collect ? result : null;
  6780. };
  6781. var getParent = function(node, selector, root) {
  6782. var parents2 = getParents2(node, selector, root, false);
  6783. return parents2 && parents2.length > 0 ? parents2[0] : null;
  6784. };
  6785. var _findSib = function(node, selector, name2) {
  6786. var func = selector;
  6787. if (node) {
  6788. if (typeof selector === "string") {
  6789. func = function(node2) {
  6790. return is2(node2, selector);
  6791. };
  6792. }
  6793. for (node = node[name2]; node; node = node[name2]) {
  6794. if (typeof func === "function" && func(node)) {
  6795. return node;
  6796. }
  6797. }
  6798. }
  6799. return null;
  6800. };
  6801. var getNext = function(node, selector) {
  6802. return _findSib(node, selector, "nextSibling");
  6803. };
  6804. var getPrev = function(node, selector) {
  6805. return _findSib(node, selector, "previousSibling");
  6806. };
  6807. var select2 = function(selector, scope) {
  6808. return Sizzle(selector, get2(scope) || settings.root_element || doc2, []);
  6809. };
  6810. var run = function(elm, func, scope) {
  6811. var result;
  6812. var node = typeof elm === "string" ? get2(elm) : elm;
  6813. if (!node) {
  6814. return false;
  6815. }
  6816. if (Tools.isArray(node) && (node.length || node.length === 0)) {
  6817. result = [];
  6818. each$f(node, function(elm2, i) {
  6819. if (elm2) {
  6820. result.push(func.call(scope, typeof elm2 === "string" ? get2(elm2) : elm2, i));
  6821. }
  6822. });
  6823. return result;
  6824. }
  6825. var context2 = scope ? scope : this;
  6826. return func.call(context2, node);
  6827. };
  6828. var setAttribs = function(elm, attrs) {
  6829. $$(elm).each(function(i, node) {
  6830. each$f(attrs, function(value2, name2) {
  6831. setAttrib(node, name2, value2);
  6832. });
  6833. });
  6834. };
  6835. var setHTML = function(elm, html) {
  6836. var $elm = $$(elm);
  6837. if (isIE) {
  6838. $elm.each(function(i, target) {
  6839. if (target.canHaveHTML === false) {
  6840. return;
  6841. }
  6842. while (target.firstChild) {
  6843. target.removeChild(target.firstChild);
  6844. }
  6845. try {
  6846. target.innerHTML = "<br>" + html;
  6847. target.removeChild(target.firstChild);
  6848. } catch (ex) {
  6849. DomQuery("<div></div>").html("<br>" + html).contents().slice(1).appendTo(target);
  6850. }
  6851. return html;
  6852. });
  6853. } else {
  6854. $elm.html(html);
  6855. }
  6856. };
  6857. var add2 = function(parentElm, name2, attrs, html, create3) {
  6858. return run(parentElm, function(parentElm2) {
  6859. var newElm = typeof name2 === "string" ? doc2.createElement(name2) : name2;
  6860. setAttribs(newElm, attrs);
  6861. if (html) {
  6862. if (typeof html !== "string" && html.nodeType) {
  6863. newElm.appendChild(html);
  6864. } else if (typeof html === "string") {
  6865. setHTML(newElm, html);
  6866. }
  6867. }
  6868. return !create3 ? parentElm2.appendChild(newElm) : newElm;
  6869. });
  6870. };
  6871. var create2 = function(name2, attrs, html) {
  6872. return add2(doc2.createElement(name2), name2, attrs, html, true);
  6873. };
  6874. var decode2 = Entities.decode;
  6875. var encode = Entities.encodeAllRaw;
  6876. var createHTML = function(name2, attrs, html) {
  6877. var outHtml = "", key;
  6878. outHtml += "<" + name2;
  6879. for (key in attrs) {
  6880. if (hasNonNullableKey(attrs, key)) {
  6881. outHtml += " " + key + '="' + encode(attrs[key]) + '"';
  6882. }
  6883. }
  6884. if (typeof html !== "undefined") {
  6885. return outHtml + ">" + html + "</" + name2 + ">";
  6886. }
  6887. return outHtml + " />";
  6888. };
  6889. var createFragment2 = function(html) {
  6890. var node;
  6891. var container = doc2.createElement("div");
  6892. var frag = doc2.createDocumentFragment();
  6893. frag.appendChild(container);
  6894. if (html) {
  6895. container.innerHTML = html;
  6896. }
  6897. while (node = container.firstChild) {
  6898. frag.appendChild(node);
  6899. }
  6900. frag.removeChild(container);
  6901. return frag;
  6902. };
  6903. var remove2 = function(node, keepChildren) {
  6904. var $node = $$(node);
  6905. if (keepChildren) {
  6906. $node.each(function() {
  6907. var child2;
  6908. while (child2 = this.firstChild) {
  6909. if (child2.nodeType === 3 && child2.data.length === 0) {
  6910. this.removeChild(child2);
  6911. } else {
  6912. this.parentNode.insertBefore(child2, this);
  6913. }
  6914. }
  6915. }).remove();
  6916. } else {
  6917. $node.remove();
  6918. }
  6919. return $node.length > 1 ? $node.toArray() : $node[0];
  6920. };
  6921. var removeAllAttribs = function(e) {
  6922. return run(e, function(e2) {
  6923. var i;
  6924. var attrs = e2.attributes;
  6925. for (i = attrs.length - 1; i >= 0; i--) {
  6926. e2.removeAttributeNode(attrs.item(i));
  6927. }
  6928. });
  6929. };
  6930. var parseStyle = function(cssText) {
  6931. return styles.parse(cssText);
  6932. };
  6933. var serializeStyle = function(stylesArg, name2) {
  6934. return styles.serialize(stylesArg, name2);
  6935. };
  6936. var addStyle = function(cssText) {
  6937. var head2, styleElm;
  6938. if (self2 !== DOMUtils.DOM && doc2 === document) {
  6939. if (addedStyles[cssText]) {
  6940. return;
  6941. }
  6942. addedStyles[cssText] = true;
  6943. }
  6944. styleElm = doc2.getElementById("mceDefaultStyles");
  6945. if (!styleElm) {
  6946. styleElm = doc2.createElement("style");
  6947. styleElm.id = "mceDefaultStyles";
  6948. styleElm.type = "text/css";
  6949. head2 = doc2.getElementsByTagName("head")[0];
  6950. if (head2.firstChild) {
  6951. head2.insertBefore(styleElm, head2.firstChild);
  6952. } else {
  6953. head2.appendChild(styleElm);
  6954. }
  6955. }
  6956. if (styleElm.styleSheet) {
  6957. styleElm.styleSheet.cssText += cssText;
  6958. } else {
  6959. styleElm.appendChild(doc2.createTextNode(cssText));
  6960. }
  6961. };
  6962. var loadCSS = function(urls) {
  6963. if (!urls) {
  6964. urls = "";
  6965. }
  6966. each$k(urls.split(","), function(url) {
  6967. files[url] = true;
  6968. styleSheetLoader.load(url, noop);
  6969. });
  6970. };
  6971. var toggleClass2 = function(elm, cls, state) {
  6972. $$(elm).toggleClass(cls, state).each(function() {
  6973. if (this.className === "") {
  6974. DomQuery(this).attr("class", null);
  6975. }
  6976. });
  6977. };
  6978. var addClass = function(elm, cls) {
  6979. $$(elm).addClass(cls);
  6980. };
  6981. var removeClass = function(elm, cls) {
  6982. toggleClass2(elm, cls, false);
  6983. };
  6984. var hasClass2 = function(elm, cls) {
  6985. return $$(elm).hasClass(cls);
  6986. };
  6987. var show = function(elm) {
  6988. $$(elm).show();
  6989. };
  6990. var hide = function(elm) {
  6991. $$(elm).hide();
  6992. };
  6993. var isHidden = function(elm) {
  6994. return $$(elm).css("display") === "none";
  6995. };
  6996. var uniqueId2 = function(prefix) {
  6997. return (!prefix ? "mce_" : prefix) + counter++;
  6998. };
  6999. var getOuterHTML = function(elm) {
  7000. var node = typeof elm === "string" ? get2(elm) : elm;
  7001. return isElement$5(node) ? node.outerHTML : DomQuery("<div></div>").append(DomQuery(node).clone()).html();
  7002. };
  7003. var setOuterHTML = function(elm, html) {
  7004. $$(elm).each(function() {
  7005. try {
  7006. if ("outerHTML" in this) {
  7007. this.outerHTML = html;
  7008. return;
  7009. }
  7010. } catch (ex) {
  7011. }
  7012. remove2(DomQuery(this).html(html), true);
  7013. });
  7014. };
  7015. var insertAfter2 = function(node, reference) {
  7016. var referenceNode = get2(reference);
  7017. return run(node, function(node2) {
  7018. var parent2 = referenceNode.parentNode;
  7019. var nextSibling2 = referenceNode.nextSibling;
  7020. if (nextSibling2) {
  7021. parent2.insertBefore(node2, nextSibling2);
  7022. } else {
  7023. parent2.appendChild(node2);
  7024. }
  7025. return node2;
  7026. });
  7027. };
  7028. var replace = function(newElm, oldElm, keepChildren) {
  7029. return run(oldElm, function(oldElm2) {
  7030. if (Tools.is(oldElm2, "array")) {
  7031. newElm = newElm.cloneNode(true);
  7032. }
  7033. if (keepChildren) {
  7034. each$f(grep$1(oldElm2.childNodes), function(node) {
  7035. newElm.appendChild(node);
  7036. });
  7037. }
  7038. return oldElm2.parentNode.replaceChild(newElm, oldElm2);
  7039. });
  7040. };
  7041. var rename = function(elm, name2) {
  7042. var newElm;
  7043. if (elm.nodeName !== name2.toUpperCase()) {
  7044. newElm = create2(name2);
  7045. each$f(getAttribs(elm), function(attrNode) {
  7046. setAttrib(newElm, attrNode.nodeName, getAttrib(elm, attrNode.nodeName));
  7047. });
  7048. replace(newElm, elm, true);
  7049. }
  7050. return newElm || elm;
  7051. };
  7052. var findCommonAncestor = function(a, b) {
  7053. var ps = a, pe;
  7054. while (ps) {
  7055. pe = b;
  7056. while (pe && ps !== pe) {
  7057. pe = pe.parentNode;
  7058. }
  7059. if (ps === pe) {
  7060. break;
  7061. }
  7062. ps = ps.parentNode;
  7063. }
  7064. if (!ps && a.ownerDocument) {
  7065. return a.ownerDocument.documentElement;
  7066. }
  7067. return ps;
  7068. };
  7069. var toHex2 = function(rgbVal) {
  7070. return styles.toHex(Tools.trim(rgbVal));
  7071. };
  7072. var isNonEmptyElement2 = function(node) {
  7073. if (isElement$5(node)) {
  7074. var isNamedAnchor2 = node.nodeName.toLowerCase() === "a" && !getAttrib(node, "href") && getAttrib(node, "id");
  7075. if (getAttrib(node, "name") || getAttrib(node, "data-mce-bookmark") || isNamedAnchor2) {
  7076. return true;
  7077. }
  7078. }
  7079. return false;
  7080. };
  7081. var isEmpty2 = function(node, elements) {
  7082. var type2, name2, brCount = 0;
  7083. if (isNonEmptyElement2(node)) {
  7084. return false;
  7085. }
  7086. node = node.firstChild;
  7087. if (node) {
  7088. var walker = new DomTreeWalker(node, node.parentNode);
  7089. var whitespace2 = schema ? schema.getWhiteSpaceElements() : {};
  7090. elements = elements || (schema ? schema.getNonEmptyElements() : null);
  7091. do {
  7092. type2 = node.nodeType;
  7093. if (isElement$5(node)) {
  7094. var bogusVal = node.getAttribute("data-mce-bogus");
  7095. if (bogusVal) {
  7096. node = walker.next(bogusVal === "all");
  7097. continue;
  7098. }
  7099. name2 = node.nodeName.toLowerCase();
  7100. if (elements && elements[name2]) {
  7101. if (name2 === "br") {
  7102. brCount++;
  7103. node = walker.next();
  7104. continue;
  7105. }
  7106. return false;
  7107. }
  7108. if (isNonEmptyElement2(node)) {
  7109. return false;
  7110. }
  7111. }
  7112. if (type2 === 8) {
  7113. return false;
  7114. }
  7115. if (type2 === 3 && !isWhitespaceText(node.nodeValue)) {
  7116. return false;
  7117. }
  7118. if (type2 === 3 && node.parentNode && whitespace2[node.parentNode.nodeName] && isWhitespaceText(node.nodeValue)) {
  7119. return false;
  7120. }
  7121. node = walker.next();
  7122. } while (node);
  7123. }
  7124. return brCount <= 1;
  7125. };
  7126. var createRng = function() {
  7127. return doc2.createRange();
  7128. };
  7129. var split2 = function(parentElm, splitElm, replacementElm) {
  7130. var range2 = createRng();
  7131. var beforeFragment;
  7132. var afterFragment;
  7133. var parentNode;
  7134. if (parentElm && splitElm) {
  7135. range2.setStart(parentElm.parentNode, findNodeIndex(parentElm));
  7136. range2.setEnd(splitElm.parentNode, findNodeIndex(splitElm));
  7137. beforeFragment = range2.extractContents();
  7138. range2 = createRng();
  7139. range2.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1);
  7140. range2.setEnd(parentElm.parentNode, findNodeIndex(parentElm) + 1);
  7141. afterFragment = range2.extractContents();
  7142. parentNode = parentElm.parentNode;
  7143. parentNode.insertBefore(trimNode(self2, beforeFragment), parentElm);
  7144. if (replacementElm) {
  7145. parentNode.insertBefore(replacementElm, parentElm);
  7146. } else {
  7147. parentNode.insertBefore(splitElm, parentElm);
  7148. }
  7149. parentNode.insertBefore(trimNode(self2, afterFragment), parentElm);
  7150. remove2(parentElm);
  7151. return replacementElm || splitElm;
  7152. }
  7153. };
  7154. var bind2 = function(target, name2, func, scope) {
  7155. if (Tools.isArray(target)) {
  7156. var i = target.length;
  7157. var rv = [];
  7158. while (i--) {
  7159. rv[i] = bind2(target[i], name2, func, scope);
  7160. }
  7161. return rv;
  7162. }
  7163. if (settings.collect && (target === doc2 || target === win)) {
  7164. boundEvents.push([
  7165. target,
  7166. name2,
  7167. func,
  7168. scope
  7169. ]);
  7170. }
  7171. var output = events.bind(target, name2, func, scope || self2);
  7172. return output;
  7173. };
  7174. var unbind = function(target, name2, func) {
  7175. if (Tools.isArray(target)) {
  7176. var i = target.length;
  7177. var rv = [];
  7178. while (i--) {
  7179. rv[i] = unbind(target[i], name2, func);
  7180. }
  7181. return rv;
  7182. } else {
  7183. if (boundEvents.length > 0 && (target === doc2 || target === win)) {
  7184. var i = boundEvents.length;
  7185. while (i--) {
  7186. var item = boundEvents[i];
  7187. if (target === item[0] && (!name2 || name2 === item[1]) && (!func || func === item[2])) {
  7188. events.unbind(item[0], item[1], item[2]);
  7189. }
  7190. }
  7191. }
  7192. return events.unbind(target, name2, func);
  7193. }
  7194. };
  7195. var fire = function(target, name2, evt) {
  7196. return events.fire(target, name2, evt);
  7197. };
  7198. var getContentEditable = function(node) {
  7199. if (node && isElement$5(node)) {
  7200. var contentEditable = node.getAttribute("data-mce-contenteditable");
  7201. if (contentEditable && contentEditable !== "inherit") {
  7202. return contentEditable;
  7203. }
  7204. return node.contentEditable !== "inherit" ? node.contentEditable : null;
  7205. } else {
  7206. return null;
  7207. }
  7208. };
  7209. var getContentEditableParent = function(node) {
  7210. var root = getRoot();
  7211. var state = null;
  7212. for (; node && node !== root; node = node.parentNode) {
  7213. state = getContentEditable(node);
  7214. if (state !== null) {
  7215. break;
  7216. }
  7217. }
  7218. return state;
  7219. };
  7220. var destroy2 = function() {
  7221. if (boundEvents.length > 0) {
  7222. var i = boundEvents.length;
  7223. while (i--) {
  7224. var item = boundEvents[i];
  7225. events.unbind(item[0], item[1], item[2]);
  7226. }
  7227. }
  7228. each$j(files, function(_, url) {
  7229. styleSheetLoader.unload(url);
  7230. delete files[url];
  7231. });
  7232. if (Sizzle.setDocument) {
  7233. Sizzle.setDocument();
  7234. }
  7235. };
  7236. var isChildOf = function(node, parent2) {
  7237. if (!isIE) {
  7238. return node === parent2 || parent2.contains(node);
  7239. } else {
  7240. while (node) {
  7241. if (parent2 === node) {
  7242. return true;
  7243. }
  7244. node = node.parentNode;
  7245. }
  7246. return false;
  7247. }
  7248. };
  7249. var dumpRng = function(r2) {
  7250. return "startContainer: " + r2.startContainer.nodeName + ", startOffset: " + r2.startOffset + ", endContainer: " + r2.endContainer.nodeName + ", endOffset: " + r2.endOffset;
  7251. };
  7252. var self2 = {
  7253. doc: doc2,
  7254. settings,
  7255. win,
  7256. files,
  7257. stdMode,
  7258. boxModel,
  7259. styleSheetLoader,
  7260. boundEvents,
  7261. styles,
  7262. schema,
  7263. events,
  7264. isBlock: isBlock2,
  7265. $,
  7266. $$,
  7267. root: null,
  7268. clone: clone2,
  7269. getRoot,
  7270. getViewPort,
  7271. getRect,
  7272. getSize,
  7273. getParent,
  7274. getParents: getParents2,
  7275. get: get2,
  7276. getNext,
  7277. getPrev,
  7278. select: select2,
  7279. is: is2,
  7280. add: add2,
  7281. create: create2,
  7282. createHTML,
  7283. createFragment: createFragment2,
  7284. remove: remove2,
  7285. setStyle,
  7286. getStyle: getStyle2,
  7287. setStyles,
  7288. removeAllAttribs,
  7289. setAttrib,
  7290. setAttribs,
  7291. getAttrib,
  7292. getPos: getPos$1,
  7293. parseStyle,
  7294. serializeStyle,
  7295. addStyle,
  7296. loadCSS,
  7297. addClass,
  7298. removeClass,
  7299. hasClass: hasClass2,
  7300. toggleClass: toggleClass2,
  7301. show,
  7302. hide,
  7303. isHidden,
  7304. uniqueId: uniqueId2,
  7305. setHTML,
  7306. getOuterHTML,
  7307. setOuterHTML,
  7308. decode: decode2,
  7309. encode,
  7310. insertAfter: insertAfter2,
  7311. replace,
  7312. rename,
  7313. findCommonAncestor,
  7314. toHex: toHex2,
  7315. run,
  7316. getAttribs,
  7317. isEmpty: isEmpty2,
  7318. createRng,
  7319. nodeIndex: findNodeIndex,
  7320. split: split2,
  7321. bind: bind2,
  7322. unbind,
  7323. fire,
  7324. getContentEditable,
  7325. getContentEditableParent,
  7326. destroy: destroy2,
  7327. isChildOf,
  7328. dumpRng
  7329. };
  7330. var attrHooks2 = setupAttrHooks(styles, settings, constant(self2));
  7331. return self2;
  7332. };
  7333. DOMUtils.DOM = DOMUtils(document);
  7334. DOMUtils.nodeIndex = findNodeIndex;
  7335. var DOM$a = DOMUtils.DOM;
  7336. var each$e = Tools.each, grep = Tools.grep;
  7337. var QUEUED = 0;
  7338. var LOADING = 1;
  7339. var LOADED = 2;
  7340. var FAILED = 3;
  7341. var ScriptLoader = function() {
  7342. function ScriptLoader2(settings) {
  7343. if (settings === void 0) {
  7344. settings = {};
  7345. }
  7346. this.states = {};
  7347. this.queue = [];
  7348. this.scriptLoadedCallbacks = {};
  7349. this.queueLoadedCallbacks = [];
  7350. this.loading = 0;
  7351. this.settings = settings;
  7352. }
  7353. ScriptLoader2.prototype._setReferrerPolicy = function(referrerPolicy) {
  7354. this.settings.referrerPolicy = referrerPolicy;
  7355. };
  7356. ScriptLoader2.prototype.loadScript = function(url, success, failure) {
  7357. var dom2 = DOM$a;
  7358. var elm;
  7359. var cleanup = function() {
  7360. dom2.remove(id);
  7361. if (elm) {
  7362. elm.onerror = elm.onload = elm = null;
  7363. }
  7364. };
  7365. var done2 = function() {
  7366. cleanup();
  7367. success();
  7368. };
  7369. var error2 = function() {
  7370. cleanup();
  7371. if (isFunction(failure)) {
  7372. failure();
  7373. } else {
  7374. if (typeof console !== "undefined" && console.log) {
  7375. console.log("Failed to load script: " + url);
  7376. }
  7377. }
  7378. };
  7379. var id = dom2.uniqueId();
  7380. elm = document.createElement("script");
  7381. elm.id = id;
  7382. elm.type = "text/javascript";
  7383. elm.src = Tools._addCacheSuffix(url);
  7384. if (this.settings.referrerPolicy) {
  7385. dom2.setAttrib(elm, "referrerpolicy", this.settings.referrerPolicy);
  7386. }
  7387. elm.onload = done2;
  7388. elm.onerror = error2;
  7389. (document.getElementsByTagName("head")[0] || document.body).appendChild(elm);
  7390. };
  7391. ScriptLoader2.prototype.isDone = function(url) {
  7392. return this.states[url] === LOADED;
  7393. };
  7394. ScriptLoader2.prototype.markDone = function(url) {
  7395. this.states[url] = LOADED;
  7396. };
  7397. ScriptLoader2.prototype.add = function(url, success, scope, failure) {
  7398. var state = this.states[url];
  7399. this.queue.push(url);
  7400. if (state === void 0) {
  7401. this.states[url] = QUEUED;
  7402. }
  7403. if (success) {
  7404. if (!this.scriptLoadedCallbacks[url]) {
  7405. this.scriptLoadedCallbacks[url] = [];
  7406. }
  7407. this.scriptLoadedCallbacks[url].push({
  7408. success,
  7409. failure,
  7410. scope: scope || this
  7411. });
  7412. }
  7413. };
  7414. ScriptLoader2.prototype.load = function(url, success, scope, failure) {
  7415. return this.add(url, success, scope, failure);
  7416. };
  7417. ScriptLoader2.prototype.remove = function(url) {
  7418. delete this.states[url];
  7419. delete this.scriptLoadedCallbacks[url];
  7420. };
  7421. ScriptLoader2.prototype.loadQueue = function(success, scope, failure) {
  7422. this.loadScripts(this.queue, success, scope, failure);
  7423. };
  7424. ScriptLoader2.prototype.loadScripts = function(scripts, success, scope, failure) {
  7425. var self2 = this;
  7426. var failures = [];
  7427. var execCallbacks = function(name2, url) {
  7428. each$e(self2.scriptLoadedCallbacks[url], function(callback) {
  7429. if (isFunction(callback[name2])) {
  7430. callback[name2].call(callback.scope);
  7431. }
  7432. });
  7433. self2.scriptLoadedCallbacks[url] = void 0;
  7434. };
  7435. self2.queueLoadedCallbacks.push({
  7436. success,
  7437. failure,
  7438. scope: scope || this
  7439. });
  7440. var loadScripts2 = function() {
  7441. var loadingScripts = grep(scripts);
  7442. scripts.length = 0;
  7443. each$e(loadingScripts, function(url) {
  7444. if (self2.states[url] === LOADED) {
  7445. execCallbacks("success", url);
  7446. return;
  7447. }
  7448. if (self2.states[url] === FAILED) {
  7449. execCallbacks("failure", url);
  7450. return;
  7451. }
  7452. if (self2.states[url] !== LOADING) {
  7453. self2.states[url] = LOADING;
  7454. self2.loading++;
  7455. self2.loadScript(url, function() {
  7456. self2.states[url] = LOADED;
  7457. self2.loading--;
  7458. execCallbacks("success", url);
  7459. loadScripts2();
  7460. }, function() {
  7461. self2.states[url] = FAILED;
  7462. self2.loading--;
  7463. failures.push(url);
  7464. execCallbacks("failure", url);
  7465. loadScripts2();
  7466. });
  7467. }
  7468. });
  7469. if (!self2.loading) {
  7470. var notifyCallbacks = self2.queueLoadedCallbacks.slice(0);
  7471. self2.queueLoadedCallbacks.length = 0;
  7472. each$e(notifyCallbacks, function(callback) {
  7473. if (failures.length === 0) {
  7474. if (isFunction(callback.success)) {
  7475. callback.success.call(callback.scope);
  7476. }
  7477. } else {
  7478. if (isFunction(callback.failure)) {
  7479. callback.failure.call(callback.scope, failures);
  7480. }
  7481. }
  7482. });
  7483. }
  7484. };
  7485. loadScripts2();
  7486. };
  7487. ScriptLoader2.ScriptLoader = new ScriptLoader2();
  7488. return ScriptLoader2;
  7489. }();
  7490. var Cell = function(initial) {
  7491. var value2 = initial;
  7492. var get2 = function() {
  7493. return value2;
  7494. };
  7495. var set2 = function(v) {
  7496. value2 = v;
  7497. };
  7498. return {
  7499. get: get2,
  7500. set: set2
  7501. };
  7502. };
  7503. var isRaw = function(str) {
  7504. return isObject(str) && has$2(str, "raw");
  7505. };
  7506. var isTokenised = function(str) {
  7507. return isArray$1(str) && str.length > 1;
  7508. };
  7509. var data = {};
  7510. var currentCode = Cell("en");
  7511. var getLanguageData = function() {
  7512. return get$9(data, currentCode.get());
  7513. };
  7514. var getData = function() {
  7515. return map$2(data, function(value2) {
  7516. return __assign({}, value2);
  7517. });
  7518. };
  7519. var setCode = function(newCode) {
  7520. if (newCode) {
  7521. currentCode.set(newCode);
  7522. }
  7523. };
  7524. var getCode = function() {
  7525. return currentCode.get();
  7526. };
  7527. var add$4 = function(code, items) {
  7528. var langData = data[code];
  7529. if (!langData) {
  7530. data[code] = langData = {};
  7531. }
  7532. each$j(items, function(translation, name2) {
  7533. langData[name2.toLowerCase()] = translation;
  7534. });
  7535. };
  7536. var translate = function(text) {
  7537. var langData = getLanguageData().getOr({});
  7538. var toString = function(obj) {
  7539. if (isFunction(obj)) {
  7540. return Object.prototype.toString.call(obj);
  7541. }
  7542. return !isEmpty2(obj) ? "" + obj : "";
  7543. };
  7544. var isEmpty2 = function(text2) {
  7545. return text2 === "" || text2 === null || text2 === void 0;
  7546. };
  7547. var getLangData = function(text2) {
  7548. var textstr = toString(text2);
  7549. return get$9(langData, textstr.toLowerCase()).map(toString).getOr(textstr);
  7550. };
  7551. var removeContext = function(str) {
  7552. return str.replace(/{context:\w+}$/, "");
  7553. };
  7554. if (isEmpty2(text)) {
  7555. return "";
  7556. }
  7557. if (isRaw(text)) {
  7558. return toString(text.raw);
  7559. }
  7560. if (isTokenised(text)) {
  7561. var values_1 = text.slice(1);
  7562. var substitued = getLangData(text[0]).replace(/\{([0-9]+)\}/g, function($1, $2) {
  7563. return has$2(values_1, $2) ? toString(values_1[$2]) : $1;
  7564. });
  7565. return removeContext(substitued);
  7566. }
  7567. return removeContext(getLangData(text));
  7568. };
  7569. var isRtl$1 = function() {
  7570. return getLanguageData().bind(function(items) {
  7571. return get$9(items, "_dir");
  7572. }).exists(function(dir2) {
  7573. return dir2 === "rtl";
  7574. });
  7575. };
  7576. var hasCode = function(code) {
  7577. return has$2(data, code);
  7578. };
  7579. var I18n = {
  7580. getData,
  7581. setCode,
  7582. getCode,
  7583. add: add$4,
  7584. translate,
  7585. isRtl: isRtl$1,
  7586. hasCode
  7587. };
  7588. var AddOnManager = function() {
  7589. var items = [];
  7590. var urls = {};
  7591. var lookup = {};
  7592. var _listeners = [];
  7593. var runListeners = function(name2, state) {
  7594. var matchedListeners = filter$4(_listeners, function(listener) {
  7595. return listener.name === name2 && listener.state === state;
  7596. });
  7597. each$k(matchedListeners, function(listener) {
  7598. return listener.callback();
  7599. });
  7600. };
  7601. var get2 = function(name2) {
  7602. if (lookup[name2]) {
  7603. return lookup[name2].instance;
  7604. }
  7605. return void 0;
  7606. };
  7607. var dependencies = function(name2) {
  7608. var result;
  7609. if (lookup[name2]) {
  7610. result = lookup[name2].dependencies;
  7611. }
  7612. return result || [];
  7613. };
  7614. var requireLangPack = function(name2, languages) {
  7615. if (AddOnManager.languageLoad !== false) {
  7616. waitFor(name2, function() {
  7617. var language = I18n.getCode();
  7618. var wrappedLanguages = "," + (languages || "") + ",";
  7619. if (!language || languages && wrappedLanguages.indexOf("," + language + ",") === -1) {
  7620. return;
  7621. }
  7622. ScriptLoader.ScriptLoader.add(urls[name2] + "/langs/" + language + ".js");
  7623. }, "loaded");
  7624. }
  7625. };
  7626. var add2 = function(id, addOn, dependencies2) {
  7627. var addOnConstructor = addOn;
  7628. items.push(addOnConstructor);
  7629. lookup[id] = {
  7630. instance: addOnConstructor,
  7631. dependencies: dependencies2
  7632. };
  7633. runListeners(id, "added");
  7634. return addOnConstructor;
  7635. };
  7636. var remove2 = function(name2) {
  7637. delete urls[name2];
  7638. delete lookup[name2];
  7639. };
  7640. var createUrl = function(baseUrl, dep) {
  7641. if (typeof dep === "object") {
  7642. return dep;
  7643. }
  7644. return typeof baseUrl === "string" ? {
  7645. prefix: "",
  7646. resource: dep,
  7647. suffix: ""
  7648. } : {
  7649. prefix: baseUrl.prefix,
  7650. resource: dep,
  7651. suffix: baseUrl.suffix
  7652. };
  7653. };
  7654. var addComponents = function(pluginName, scripts) {
  7655. var pluginUrl = urls[pluginName];
  7656. each$k(scripts, function(script) {
  7657. ScriptLoader.ScriptLoader.add(pluginUrl + "/" + script);
  7658. });
  7659. };
  7660. var loadDependencies = function(name2, addOnUrl, success, scope) {
  7661. var deps = dependencies(name2);
  7662. each$k(deps, function(dep) {
  7663. var newUrl = createUrl(addOnUrl, dep);
  7664. load(newUrl.resource, newUrl, void 0, void 0);
  7665. });
  7666. if (success) {
  7667. if (scope) {
  7668. success.call(scope);
  7669. } else {
  7670. success.call(ScriptLoader);
  7671. }
  7672. }
  7673. };
  7674. var load = function(name2, addOnUrl, success, scope, failure) {
  7675. if (urls[name2]) {
  7676. return;
  7677. }
  7678. var urlString = typeof addOnUrl === "string" ? addOnUrl : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix;
  7679. if (urlString.indexOf("/") !== 0 && urlString.indexOf("://") === -1) {
  7680. urlString = AddOnManager.baseURL + "/" + urlString;
  7681. }
  7682. urls[name2] = urlString.substring(0, urlString.lastIndexOf("/"));
  7683. var done2 = function() {
  7684. runListeners(name2, "loaded");
  7685. loadDependencies(name2, addOnUrl, success, scope);
  7686. };
  7687. if (lookup[name2]) {
  7688. done2();
  7689. } else {
  7690. ScriptLoader.ScriptLoader.add(urlString, done2, scope, failure);
  7691. }
  7692. };
  7693. var waitFor = function(name2, callback, state) {
  7694. if (state === void 0) {
  7695. state = "added";
  7696. }
  7697. if (has$2(lookup, name2) && state === "added") {
  7698. callback();
  7699. } else if (has$2(urls, name2) && state === "loaded") {
  7700. callback();
  7701. } else {
  7702. _listeners.push({
  7703. name: name2,
  7704. state,
  7705. callback
  7706. });
  7707. }
  7708. };
  7709. return {
  7710. items,
  7711. urls,
  7712. lookup,
  7713. _listeners,
  7714. get: get2,
  7715. dependencies,
  7716. requireLangPack,
  7717. add: add2,
  7718. remove: remove2,
  7719. createUrl,
  7720. addComponents,
  7721. load,
  7722. waitFor
  7723. };
  7724. };
  7725. AddOnManager.languageLoad = true;
  7726. AddOnManager.baseURL = "";
  7727. AddOnManager.PluginManager = AddOnManager();
  7728. AddOnManager.ThemeManager = AddOnManager();
  7729. var singleton = function(doRevoke) {
  7730. var subject = Cell(Optional.none());
  7731. var revoke = function() {
  7732. return subject.get().each(doRevoke);
  7733. };
  7734. var clear2 = function() {
  7735. revoke();
  7736. subject.set(Optional.none());
  7737. };
  7738. var isSet = function() {
  7739. return subject.get().isSome();
  7740. };
  7741. var get2 = function() {
  7742. return subject.get();
  7743. };
  7744. var set2 = function(s) {
  7745. revoke();
  7746. subject.set(Optional.some(s));
  7747. };
  7748. return {
  7749. clear: clear2,
  7750. isSet,
  7751. get: get2,
  7752. set: set2
  7753. };
  7754. };
  7755. var value = function() {
  7756. var subject = singleton(noop);
  7757. var on2 = function(f) {
  7758. return subject.get().each(f);
  7759. };
  7760. return __assign(__assign({}, subject), { on: on2 });
  7761. };
  7762. var first = function(fn, rate) {
  7763. var timer = null;
  7764. var cancel = function() {
  7765. if (!isNull(timer)) {
  7766. clearTimeout(timer);
  7767. timer = null;
  7768. }
  7769. };
  7770. var throttle = function() {
  7771. var args = [];
  7772. for (var _i = 0; _i < arguments.length; _i++) {
  7773. args[_i] = arguments[_i];
  7774. }
  7775. if (isNull(timer)) {
  7776. timer = setTimeout(function() {
  7777. timer = null;
  7778. fn.apply(null, args);
  7779. }, rate);
  7780. }
  7781. };
  7782. return {
  7783. cancel,
  7784. throttle
  7785. };
  7786. };
  7787. var last = function(fn, rate) {
  7788. var timer = null;
  7789. var cancel = function() {
  7790. if (!isNull(timer)) {
  7791. clearTimeout(timer);
  7792. timer = null;
  7793. }
  7794. };
  7795. var throttle = function() {
  7796. var args = [];
  7797. for (var _i = 0; _i < arguments.length; _i++) {
  7798. args[_i] = arguments[_i];
  7799. }
  7800. cancel();
  7801. timer = setTimeout(function() {
  7802. timer = null;
  7803. fn.apply(null, args);
  7804. }, rate);
  7805. };
  7806. return {
  7807. cancel,
  7808. throttle
  7809. };
  7810. };
  7811. var read$4 = function(element, attr) {
  7812. var value2 = get$6(element, attr);
  7813. return value2 === void 0 || value2 === "" ? [] : value2.split(" ");
  7814. };
  7815. var add$3 = function(element, attr, id) {
  7816. var old = read$4(element, attr);
  7817. var nu2 = old.concat([id]);
  7818. set$1(element, attr, nu2.join(" "));
  7819. return true;
  7820. };
  7821. var remove$5 = function(element, attr, id) {
  7822. var nu2 = filter$4(read$4(element, attr), function(v) {
  7823. return v !== id;
  7824. });
  7825. if (nu2.length > 0) {
  7826. set$1(element, attr, nu2.join(" "));
  7827. } else {
  7828. remove$6(element, attr);
  7829. }
  7830. return false;
  7831. };
  7832. var supports = function(element) {
  7833. return element.dom.classList !== void 0;
  7834. };
  7835. var get$4 = function(element) {
  7836. return read$4(element, "class");
  7837. };
  7838. var add$2 = function(element, clazz) {
  7839. return add$3(element, "class", clazz);
  7840. };
  7841. var remove$4 = function(element, clazz) {
  7842. return remove$5(element, "class", clazz);
  7843. };
  7844. var add$1 = function(element, clazz) {
  7845. if (supports(element)) {
  7846. element.dom.classList.add(clazz);
  7847. } else {
  7848. add$2(element, clazz);
  7849. }
  7850. };
  7851. var cleanClass = function(element) {
  7852. var classList = supports(element) ? element.dom.classList : get$4(element);
  7853. if (classList.length === 0) {
  7854. remove$6(element, "class");
  7855. }
  7856. };
  7857. var remove$3 = function(element, clazz) {
  7858. if (supports(element)) {
  7859. var classList = element.dom.classList;
  7860. classList.remove(clazz);
  7861. } else {
  7862. remove$4(element, clazz);
  7863. }
  7864. cleanClass(element);
  7865. };
  7866. var has = function(element, clazz) {
  7867. return supports(element) && element.dom.classList.contains(clazz);
  7868. };
  7869. var descendants$1 = function(scope, predicate) {
  7870. var result = [];
  7871. each$k(children(scope), function(x) {
  7872. if (predicate(x)) {
  7873. result = result.concat([x]);
  7874. }
  7875. result = result.concat(descendants$1(x, predicate));
  7876. });
  7877. return result;
  7878. };
  7879. var descendants = function(scope, selector) {
  7880. return all(selector, scope);
  7881. };
  7882. var annotation = constant("mce-annotation");
  7883. var dataAnnotation = constant("data-mce-annotation");
  7884. var dataAnnotationId = constant("data-mce-annotation-uid");
  7885. var identify = function(editor, annotationName) {
  7886. var rng = editor.selection.getRng();
  7887. var start2 = SugarElement.fromDom(rng.startContainer);
  7888. var root = SugarElement.fromDom(editor.getBody());
  7889. var selector = annotationName.fold(function() {
  7890. return "." + annotation();
  7891. }, function(an) {
  7892. return "[" + dataAnnotation() + '="' + an + '"]';
  7893. });
  7894. var newStart = child$1(start2, rng.startOffset).getOr(start2);
  7895. var closest2 = closest$2(newStart, selector, function(n) {
  7896. return eq(n, root);
  7897. });
  7898. var getAttr = function(c, property) {
  7899. if (has$1(c, property)) {
  7900. return Optional.some(get$6(c, property));
  7901. } else {
  7902. return Optional.none();
  7903. }
  7904. };
  7905. return closest2.bind(function(c) {
  7906. return getAttr(c, "" + dataAnnotationId()).bind(function(uid) {
  7907. return getAttr(c, "" + dataAnnotation()).map(function(name2) {
  7908. var elements = findMarkers(editor, uid);
  7909. return {
  7910. uid,
  7911. name: name2,
  7912. elements
  7913. };
  7914. });
  7915. });
  7916. });
  7917. };
  7918. var isAnnotation = function(elem) {
  7919. return isElement$6(elem) && has(elem, annotation());
  7920. };
  7921. var findMarkers = function(editor, uid) {
  7922. var body = SugarElement.fromDom(editor.getBody());
  7923. return descendants(body, "[" + dataAnnotationId() + '="' + uid + '"]');
  7924. };
  7925. var findAll = function(editor, name2) {
  7926. var body = SugarElement.fromDom(editor.getBody());
  7927. var markers = descendants(body, "[" + dataAnnotation() + '="' + name2 + '"]');
  7928. var directory = {};
  7929. each$k(markers, function(m) {
  7930. var uid = get$6(m, dataAnnotationId());
  7931. var nodesAlready = get$9(directory, uid).getOr([]);
  7932. directory[uid] = nodesAlready.concat([m]);
  7933. });
  7934. return directory;
  7935. };
  7936. var setup$n = function(editor, _registry) {
  7937. var changeCallbacks = Cell({});
  7938. var initData = function() {
  7939. return {
  7940. listeners: [],
  7941. previous: value()
  7942. };
  7943. };
  7944. var withCallbacks = function(name2, f) {
  7945. updateCallbacks(name2, function(data2) {
  7946. f(data2);
  7947. return data2;
  7948. });
  7949. };
  7950. var updateCallbacks = function(name2, f) {
  7951. var callbackMap = changeCallbacks.get();
  7952. var data2 = get$9(callbackMap, name2).getOrThunk(initData);
  7953. var outputData = f(data2);
  7954. callbackMap[name2] = outputData;
  7955. changeCallbacks.set(callbackMap);
  7956. };
  7957. var fireCallbacks = function(name2, uid, elements) {
  7958. withCallbacks(name2, function(data2) {
  7959. each$k(data2.listeners, function(f) {
  7960. return f(true, name2, {
  7961. uid,
  7962. nodes: map$3(elements, function(elem) {
  7963. return elem.dom;
  7964. })
  7965. });
  7966. });
  7967. });
  7968. };
  7969. var fireNoAnnotation = function(name2) {
  7970. withCallbacks(name2, function(data2) {
  7971. each$k(data2.listeners, function(f) {
  7972. return f(false, name2);
  7973. });
  7974. });
  7975. };
  7976. var onNodeChange = last(function() {
  7977. var callbackMap = changeCallbacks.get();
  7978. var annotations = sort(keys(callbackMap));
  7979. each$k(annotations, function(name2) {
  7980. updateCallbacks(name2, function(data2) {
  7981. var prev = data2.previous.get();
  7982. identify(editor, Optional.some(name2)).fold(function() {
  7983. if (prev.isSome()) {
  7984. fireNoAnnotation(name2);
  7985. data2.previous.clear();
  7986. }
  7987. }, function(_a) {
  7988. var uid = _a.uid, name3 = _a.name, elements = _a.elements;
  7989. if (!is$1(prev, uid)) {
  7990. fireCallbacks(name3, uid, elements);
  7991. data2.previous.set(uid);
  7992. }
  7993. });
  7994. return {
  7995. previous: data2.previous,
  7996. listeners: data2.listeners
  7997. };
  7998. });
  7999. });
  8000. }, 30);
  8001. editor.on("remove", function() {
  8002. onNodeChange.cancel();
  8003. });
  8004. editor.on("NodeChange", function() {
  8005. onNodeChange.throttle();
  8006. });
  8007. var addListener = function(name2, f) {
  8008. updateCallbacks(name2, function(data2) {
  8009. return {
  8010. previous: data2.previous,
  8011. listeners: data2.listeners.concat([f])
  8012. };
  8013. });
  8014. };
  8015. return { addListener };
  8016. };
  8017. var setup$m = function(editor, registry2) {
  8018. var identifyParserNode = function(span) {
  8019. return Optional.from(span.attr(dataAnnotation())).bind(registry2.lookup);
  8020. };
  8021. editor.on("init", function() {
  8022. editor.serializer.addNodeFilter("span", function(spans) {
  8023. each$k(spans, function(span) {
  8024. identifyParserNode(span).each(function(settings) {
  8025. if (settings.persistent === false) {
  8026. span.unwrap();
  8027. }
  8028. });
  8029. });
  8030. });
  8031. });
  8032. };
  8033. var create$7 = function() {
  8034. var annotations = {};
  8035. var register2 = function(name2, settings) {
  8036. annotations[name2] = {
  8037. name: name2,
  8038. settings
  8039. };
  8040. };
  8041. var lookup = function(name2) {
  8042. return get$9(annotations, name2).map(function(a) {
  8043. return a.settings;
  8044. });
  8045. };
  8046. return {
  8047. register: register2,
  8048. lookup
  8049. };
  8050. };
  8051. var unique = 0;
  8052. var generate = function(prefix) {
  8053. var date = new Date();
  8054. var time = date.getTime();
  8055. var random = Math.floor(Math.random() * 1e9);
  8056. unique++;
  8057. return prefix + "_" + random + unique + String(time);
  8058. };
  8059. var add = function(element, classes) {
  8060. each$k(classes, function(x) {
  8061. add$1(element, x);
  8062. });
  8063. };
  8064. var fromHtml = function(html, scope) {
  8065. var doc2 = scope || document;
  8066. var div = doc2.createElement("div");
  8067. div.innerHTML = html;
  8068. return children(SugarElement.fromDom(div));
  8069. };
  8070. var fromDom$1 = function(nodes) {
  8071. return map$3(nodes, SugarElement.fromDom);
  8072. };
  8073. var get$3 = function(element) {
  8074. return element.dom.innerHTML;
  8075. };
  8076. var set = function(element, content) {
  8077. var owner2 = owner$1(element);
  8078. var docDom = owner2.dom;
  8079. var fragment = SugarElement.fromDom(docDom.createDocumentFragment());
  8080. var contentElements = fromHtml(content, docDom);
  8081. append(fragment, contentElements);
  8082. empty(element);
  8083. append$1(element, fragment);
  8084. };
  8085. var clone$1 = function(original, isDeep) {
  8086. return SugarElement.fromDom(original.dom.cloneNode(isDeep));
  8087. };
  8088. var shallow = function(original) {
  8089. return clone$1(original, false);
  8090. };
  8091. var deep$1 = function(original) {
  8092. return clone$1(original, true);
  8093. };
  8094. var TextWalker = function(startNode, rootNode, isBoundary) {
  8095. if (isBoundary === void 0) {
  8096. isBoundary = never;
  8097. }
  8098. var walker = new DomTreeWalker(startNode, rootNode);
  8099. var walk2 = function(direction) {
  8100. var next;
  8101. do {
  8102. next = walker[direction]();
  8103. } while (next && !isText$7(next) && !isBoundary(next));
  8104. return Optional.from(next).filter(isText$7);
  8105. };
  8106. return {
  8107. current: function() {
  8108. return Optional.from(walker.current()).filter(isText$7);
  8109. },
  8110. next: function() {
  8111. return walk2("next");
  8112. },
  8113. prev: function() {
  8114. return walk2("prev");
  8115. },
  8116. prev2: function() {
  8117. return walk2("prev2");
  8118. }
  8119. };
  8120. };
  8121. var TextSeeker = function(dom2, isBoundary) {
  8122. var isBlockBoundary = isBoundary ? isBoundary : function(node) {
  8123. return dom2.isBlock(node) || isBr$5(node) || isContentEditableFalse$b(node);
  8124. };
  8125. var walk2 = function(node, offset, walker, process2) {
  8126. if (isText$7(node)) {
  8127. var newOffset = process2(node, offset, node.data);
  8128. if (newOffset !== -1) {
  8129. return Optional.some({
  8130. container: node,
  8131. offset: newOffset
  8132. });
  8133. }
  8134. }
  8135. return walker().bind(function(next) {
  8136. return walk2(next.container, next.offset, walker, process2);
  8137. });
  8138. };
  8139. var backwards = function(node, offset, process2, root) {
  8140. var walker = TextWalker(node, root, isBlockBoundary);
  8141. return walk2(node, offset, function() {
  8142. return walker.prev().map(function(prev) {
  8143. return {
  8144. container: prev,
  8145. offset: prev.length
  8146. };
  8147. });
  8148. }, process2).getOrNull();
  8149. };
  8150. var forwards = function(node, offset, process2, root) {
  8151. var walker = TextWalker(node, root, isBlockBoundary);
  8152. return walk2(node, offset, function() {
  8153. return walker.next().map(function(next) {
  8154. return {
  8155. container: next,
  8156. offset: 0
  8157. };
  8158. });
  8159. }, process2).getOrNull();
  8160. };
  8161. return {
  8162. backwards,
  8163. forwards
  8164. };
  8165. };
  8166. var round$2 = Math.round;
  8167. var clone = function(rect) {
  8168. if (!rect) {
  8169. return {
  8170. left: 0,
  8171. top: 0,
  8172. bottom: 0,
  8173. right: 0,
  8174. width: 0,
  8175. height: 0
  8176. };
  8177. }
  8178. return {
  8179. left: round$2(rect.left),
  8180. top: round$2(rect.top),
  8181. bottom: round$2(rect.bottom),
  8182. right: round$2(rect.right),
  8183. width: round$2(rect.width),
  8184. height: round$2(rect.height)
  8185. };
  8186. };
  8187. var collapse = function(rect, toStart) {
  8188. rect = clone(rect);
  8189. if (toStart) {
  8190. rect.right = rect.left;
  8191. } else {
  8192. rect.left = rect.left + rect.width;
  8193. rect.right = rect.left;
  8194. }
  8195. rect.width = 0;
  8196. return rect;
  8197. };
  8198. var isEqual = function(rect1, rect2) {
  8199. return rect1.left === rect2.left && rect1.top === rect2.top && rect1.bottom === rect2.bottom && rect1.right === rect2.right;
  8200. };
  8201. var isValidOverflow = function(overflowY, rect1, rect2) {
  8202. return overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2;
  8203. };
  8204. var isAbove$1 = function(rect1, rect2) {
  8205. var halfHeight = Math.min(rect2.height / 2, rect1.height / 2);
  8206. if (rect1.bottom - halfHeight < rect2.top) {
  8207. return true;
  8208. }
  8209. if (rect1.top > rect2.bottom) {
  8210. return false;
  8211. }
  8212. return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2);
  8213. };
  8214. var isBelow$1 = function(rect1, rect2) {
  8215. if (rect1.top > rect2.bottom) {
  8216. return true;
  8217. }
  8218. if (rect1.bottom < rect2.top) {
  8219. return false;
  8220. }
  8221. return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2);
  8222. };
  8223. var containsXY = function(rect, clientX, clientY) {
  8224. return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
  8225. };
  8226. var clamp$2 = function(value2, min2, max2) {
  8227. return Math.min(Math.max(value2, min2), max2);
  8228. };
  8229. var getSelectedNode = function(range2) {
  8230. var startContainer = range2.startContainer, startOffset = range2.startOffset;
  8231. if (startContainer.hasChildNodes() && range2.endOffset === startOffset + 1) {
  8232. return startContainer.childNodes[startOffset];
  8233. }
  8234. return null;
  8235. };
  8236. var getNode$1 = function(container, offset) {
  8237. if (isElement$5(container) && container.hasChildNodes()) {
  8238. var childNodes = container.childNodes;
  8239. var safeOffset = clamp$2(offset, 0, childNodes.length - 1);
  8240. return childNodes[safeOffset];
  8241. } else {
  8242. return container;
  8243. }
  8244. };
  8245. var getNodeUnsafe = function(container, offset) {
  8246. if (offset < 0 && isElement$5(container) && container.hasChildNodes()) {
  8247. return void 0;
  8248. } else {
  8249. return getNode$1(container, offset);
  8250. }
  8251. };
  8252. 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]");
  8253. var isExtendingChar = function(ch) {
  8254. return typeof ch === "string" && ch.charCodeAt(0) >= 768 && extendingChars.test(ch);
  8255. };
  8256. var or = function() {
  8257. var args = [];
  8258. for (var _i = 0; _i < arguments.length; _i++) {
  8259. args[_i] = arguments[_i];
  8260. }
  8261. return function(x) {
  8262. for (var i = 0; i < args.length; i++) {
  8263. if (args[i](x)) {
  8264. return true;
  8265. }
  8266. }
  8267. return false;
  8268. };
  8269. };
  8270. var and = function() {
  8271. var args = [];
  8272. for (var _i = 0; _i < arguments.length; _i++) {
  8273. args[_i] = arguments[_i];
  8274. }
  8275. return function(x) {
  8276. for (var i = 0; i < args.length; i++) {
  8277. if (!args[i](x)) {
  8278. return false;
  8279. }
  8280. }
  8281. return true;
  8282. };
  8283. };
  8284. var isElement$3 = isElement$5;
  8285. var isCaretCandidate$2 = isCaretCandidate$3;
  8286. var isBlock$1 = matchStyleValues("display", "block table");
  8287. var isFloated = matchStyleValues("float", "left right");
  8288. var isValidElementCaretCandidate = and(isElement$3, isCaretCandidate$2, not(isFloated));
  8289. var isNotPre = not(matchStyleValues("white-space", "pre pre-line pre-wrap"));
  8290. var isText$4 = isText$7;
  8291. var isBr$2 = isBr$5;
  8292. var nodeIndex$1 = DOMUtils.nodeIndex;
  8293. var resolveIndex$1 = getNodeUnsafe;
  8294. var createRange$1 = function(doc2) {
  8295. return "createRange" in doc2 ? doc2.createRange() : DOMUtils.DOM.createRng();
  8296. };
  8297. var isWhiteSpace$1 = function(chr) {
  8298. return chr && /[\r\n\t ]/.test(chr);
  8299. };
  8300. var isRange = function(rng) {
  8301. return !!rng.setStart && !!rng.setEnd;
  8302. };
  8303. var isHiddenWhiteSpaceRange = function(range2) {
  8304. var container = range2.startContainer;
  8305. var offset = range2.startOffset;
  8306. if (isWhiteSpace$1(range2.toString()) && isNotPre(container.parentNode) && isText$7(container)) {
  8307. var text = container.data;
  8308. if (isWhiteSpace$1(text[offset - 1]) || isWhiteSpace$1(text[offset + 1])) {
  8309. return true;
  8310. }
  8311. }
  8312. return false;
  8313. };
  8314. var getBrClientRect = function(brNode) {
  8315. var doc2 = brNode.ownerDocument;
  8316. var rng = createRange$1(doc2);
  8317. var nbsp$1 = doc2.createTextNode(nbsp);
  8318. var parentNode = brNode.parentNode;
  8319. parentNode.insertBefore(nbsp$1, brNode);
  8320. rng.setStart(nbsp$1, 0);
  8321. rng.setEnd(nbsp$1, 1);
  8322. var clientRect = clone(rng.getBoundingClientRect());
  8323. parentNode.removeChild(nbsp$1);
  8324. return clientRect;
  8325. };
  8326. var getBoundingClientRectWebKitText = function(rng) {
  8327. var sc = rng.startContainer;
  8328. var ec = rng.endContainer;
  8329. var so = rng.startOffset;
  8330. var eo = rng.endOffset;
  8331. if (sc === ec && isText$7(ec) && so === 0 && eo === 1) {
  8332. var newRng = rng.cloneRange();
  8333. newRng.setEndAfter(ec);
  8334. return getBoundingClientRect$1(newRng);
  8335. } else {
  8336. return null;
  8337. }
  8338. };
  8339. var isZeroRect = function(r2) {
  8340. return r2.left === 0 && r2.right === 0 && r2.top === 0 && r2.bottom === 0;
  8341. };
  8342. var getBoundingClientRect$1 = function(item) {
  8343. var clientRect;
  8344. var clientRects = item.getClientRects();
  8345. if (clientRects.length > 0) {
  8346. clientRect = clone(clientRects[0]);
  8347. } else {
  8348. clientRect = clone(item.getBoundingClientRect());
  8349. }
  8350. if (!isRange(item) && isBr$2(item) && isZeroRect(clientRect)) {
  8351. return getBrClientRect(item);
  8352. }
  8353. if (isZeroRect(clientRect) && isRange(item)) {
  8354. return getBoundingClientRectWebKitText(item);
  8355. }
  8356. return clientRect;
  8357. };
  8358. var collapseAndInflateWidth = function(clientRect, toStart) {
  8359. var newClientRect = collapse(clientRect, toStart);
  8360. newClientRect.width = 1;
  8361. newClientRect.right = newClientRect.left + 1;
  8362. return newClientRect;
  8363. };
  8364. var getCaretPositionClientRects = function(caretPosition) {
  8365. var clientRects = [];
  8366. var addUniqueAndValidRect = function(clientRect) {
  8367. if (clientRect.height === 0) {
  8368. return;
  8369. }
  8370. if (clientRects.length > 0) {
  8371. if (isEqual(clientRect, clientRects[clientRects.length - 1])) {
  8372. return;
  8373. }
  8374. }
  8375. clientRects.push(clientRect);
  8376. };
  8377. var addCharacterOffset = function(container2, offset2) {
  8378. var range2 = createRange$1(container2.ownerDocument);
  8379. if (offset2 < container2.data.length) {
  8380. if (isExtendingChar(container2.data[offset2])) {
  8381. return clientRects;
  8382. }
  8383. if (isExtendingChar(container2.data[offset2 - 1])) {
  8384. range2.setStart(container2, offset2);
  8385. range2.setEnd(container2, offset2 + 1);
  8386. if (!isHiddenWhiteSpaceRange(range2)) {
  8387. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range2), false));
  8388. return clientRects;
  8389. }
  8390. }
  8391. }
  8392. if (offset2 > 0) {
  8393. range2.setStart(container2, offset2 - 1);
  8394. range2.setEnd(container2, offset2);
  8395. if (!isHiddenWhiteSpaceRange(range2)) {
  8396. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range2), false));
  8397. }
  8398. }
  8399. if (offset2 < container2.data.length) {
  8400. range2.setStart(container2, offset2);
  8401. range2.setEnd(container2, offset2 + 1);
  8402. if (!isHiddenWhiteSpaceRange(range2)) {
  8403. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range2), true));
  8404. }
  8405. }
  8406. };
  8407. var container = caretPosition.container();
  8408. var offset = caretPosition.offset();
  8409. if (isText$4(container)) {
  8410. addCharacterOffset(container, offset);
  8411. return clientRects;
  8412. }
  8413. if (isElement$3(container)) {
  8414. if (caretPosition.isAtEnd()) {
  8415. var node = resolveIndex$1(container, offset);
  8416. if (isText$4(node)) {
  8417. addCharacterOffset(node, node.data.length);
  8418. }
  8419. if (isValidElementCaretCandidate(node) && !isBr$2(node)) {
  8420. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false));
  8421. }
  8422. } else {
  8423. var node = resolveIndex$1(container, offset);
  8424. if (isText$4(node)) {
  8425. addCharacterOffset(node, 0);
  8426. }
  8427. if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) {
  8428. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false));
  8429. return clientRects;
  8430. }
  8431. var beforeNode = resolveIndex$1(caretPosition.container(), caretPosition.offset() - 1);
  8432. if (isValidElementCaretCandidate(beforeNode) && !isBr$2(beforeNode)) {
  8433. if (isBlock$1(beforeNode) || isBlock$1(node) || !isValidElementCaretCandidate(node)) {
  8434. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(beforeNode), false));
  8435. }
  8436. }
  8437. if (isValidElementCaretCandidate(node)) {
  8438. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), true));
  8439. }
  8440. }
  8441. }
  8442. return clientRects;
  8443. };
  8444. var CaretPosition = function(container, offset, clientRects) {
  8445. var isAtStart = function() {
  8446. if (isText$4(container)) {
  8447. return offset === 0;
  8448. }
  8449. return offset === 0;
  8450. };
  8451. var isAtEnd = function() {
  8452. if (isText$4(container)) {
  8453. return offset >= container.data.length;
  8454. }
  8455. return offset >= container.childNodes.length;
  8456. };
  8457. var toRange = function() {
  8458. var range2 = createRange$1(container.ownerDocument);
  8459. range2.setStart(container, offset);
  8460. range2.setEnd(container, offset);
  8461. return range2;
  8462. };
  8463. var getClientRects2 = function() {
  8464. if (!clientRects) {
  8465. clientRects = getCaretPositionClientRects(CaretPosition(container, offset));
  8466. }
  8467. return clientRects;
  8468. };
  8469. var isVisible = function() {
  8470. return getClientRects2().length > 0;
  8471. };
  8472. var isEqual2 = function(caretPosition) {
  8473. return caretPosition && container === caretPosition.container() && offset === caretPosition.offset();
  8474. };
  8475. var getNode2 = function(before2) {
  8476. return resolveIndex$1(container, before2 ? offset - 1 : offset);
  8477. };
  8478. return {
  8479. container: constant(container),
  8480. offset: constant(offset),
  8481. toRange,
  8482. getClientRects: getClientRects2,
  8483. isVisible,
  8484. isAtStart,
  8485. isAtEnd,
  8486. isEqual: isEqual2,
  8487. getNode: getNode2
  8488. };
  8489. };
  8490. CaretPosition.fromRangeStart = function(range2) {
  8491. return CaretPosition(range2.startContainer, range2.startOffset);
  8492. };
  8493. CaretPosition.fromRangeEnd = function(range2) {
  8494. return CaretPosition(range2.endContainer, range2.endOffset);
  8495. };
  8496. CaretPosition.after = function(node) {
  8497. return CaretPosition(node.parentNode, nodeIndex$1(node) + 1);
  8498. };
  8499. CaretPosition.before = function(node) {
  8500. return CaretPosition(node.parentNode, nodeIndex$1(node));
  8501. };
  8502. CaretPosition.isAbove = function(pos1, pos2) {
  8503. return lift2(head(pos2.getClientRects()), last$2(pos1.getClientRects()), isAbove$1).getOr(false);
  8504. };
  8505. CaretPosition.isBelow = function(pos1, pos2) {
  8506. return lift2(last$2(pos2.getClientRects()), head(pos1.getClientRects()), isBelow$1).getOr(false);
  8507. };
  8508. CaretPosition.isAtStart = function(pos) {
  8509. return pos ? pos.isAtStart() : false;
  8510. };
  8511. CaretPosition.isAtEnd = function(pos) {
  8512. return pos ? pos.isAtEnd() : false;
  8513. };
  8514. CaretPosition.isTextPosition = function(pos) {
  8515. return pos ? isText$7(pos.container()) : false;
  8516. };
  8517. CaretPosition.isElementPosition = function(pos) {
  8518. return CaretPosition.isTextPosition(pos) === false;
  8519. };
  8520. var trimEmptyTextNode$1 = function(dom2, node) {
  8521. if (isText$7(node) && node.data.length === 0) {
  8522. dom2.remove(node);
  8523. }
  8524. };
  8525. var insertNode = function(dom2, rng, node) {
  8526. rng.insertNode(node);
  8527. trimEmptyTextNode$1(dom2, node.previousSibling);
  8528. trimEmptyTextNode$1(dom2, node.nextSibling);
  8529. };
  8530. var insertFragment = function(dom2, rng, frag) {
  8531. var firstChild2 = Optional.from(frag.firstChild);
  8532. var lastChild2 = Optional.from(frag.lastChild);
  8533. rng.insertNode(frag);
  8534. firstChild2.each(function(child2) {
  8535. return trimEmptyTextNode$1(dom2, child2.previousSibling);
  8536. });
  8537. lastChild2.each(function(child2) {
  8538. return trimEmptyTextNode$1(dom2, child2.nextSibling);
  8539. });
  8540. };
  8541. var rangeInsertNode = function(dom2, rng, node) {
  8542. if (isDocumentFragment(node)) {
  8543. insertFragment(dom2, rng, node);
  8544. } else {
  8545. insertNode(dom2, rng, node);
  8546. }
  8547. };
  8548. var isText$3 = isText$7;
  8549. var isBogus = isBogus$2;
  8550. var nodeIndex = DOMUtils.nodeIndex;
  8551. var normalizedParent = function(node) {
  8552. var parentNode = node.parentNode;
  8553. if (isBogus(parentNode)) {
  8554. return normalizedParent(parentNode);
  8555. }
  8556. return parentNode;
  8557. };
  8558. var getChildNodes = function(node) {
  8559. if (!node) {
  8560. return [];
  8561. }
  8562. return reduce(node.childNodes, function(result, node2) {
  8563. if (isBogus(node2) && node2.nodeName !== "BR") {
  8564. result = result.concat(getChildNodes(node2));
  8565. } else {
  8566. result.push(node2);
  8567. }
  8568. return result;
  8569. }, []);
  8570. };
  8571. var normalizedTextOffset = function(node, offset) {
  8572. while (node = node.previousSibling) {
  8573. if (!isText$3(node)) {
  8574. break;
  8575. }
  8576. offset += node.data.length;
  8577. }
  8578. return offset;
  8579. };
  8580. var equal = function(a) {
  8581. return function(b) {
  8582. return a === b;
  8583. };
  8584. };
  8585. var normalizedNodeIndex = function(node) {
  8586. var nodes, index;
  8587. nodes = getChildNodes(normalizedParent(node));
  8588. index = findIndex$1(nodes, equal(node), node);
  8589. nodes = nodes.slice(0, index + 1);
  8590. var numTextFragments = reduce(nodes, function(result, node2, i) {
  8591. if (isText$3(node2) && isText$3(nodes[i - 1])) {
  8592. result++;
  8593. }
  8594. return result;
  8595. }, 0);
  8596. nodes = filter$2(nodes, matchNodeNames([node.nodeName]));
  8597. index = findIndex$1(nodes, equal(node), node);
  8598. return index - numTextFragments;
  8599. };
  8600. var createPathItem = function(node) {
  8601. var name2;
  8602. if (isText$3(node)) {
  8603. name2 = "text()";
  8604. } else {
  8605. name2 = node.nodeName.toLowerCase();
  8606. }
  8607. return name2 + "[" + normalizedNodeIndex(node) + "]";
  8608. };
  8609. var parentsUntil$1 = function(root, node, predicate) {
  8610. var parents2 = [];
  8611. for (node = node.parentNode; node !== root; node = node.parentNode) {
  8612. if (predicate && predicate(node)) {
  8613. break;
  8614. }
  8615. parents2.push(node);
  8616. }
  8617. return parents2;
  8618. };
  8619. var create$6 = function(root, caretPosition) {
  8620. var container, offset, path = [], outputOffset, childNodes, parents2;
  8621. container = caretPosition.container();
  8622. offset = caretPosition.offset();
  8623. if (isText$3(container)) {
  8624. outputOffset = normalizedTextOffset(container, offset);
  8625. } else {
  8626. childNodes = container.childNodes;
  8627. if (offset >= childNodes.length) {
  8628. outputOffset = "after";
  8629. offset = childNodes.length - 1;
  8630. } else {
  8631. outputOffset = "before";
  8632. }
  8633. container = childNodes[offset];
  8634. }
  8635. path.push(createPathItem(container));
  8636. parents2 = parentsUntil$1(root, container);
  8637. parents2 = filter$2(parents2, not(isBogus$2));
  8638. path = path.concat(map$1(parents2, function(node) {
  8639. return createPathItem(node);
  8640. }));
  8641. return path.reverse().join("/") + "," + outputOffset;
  8642. };
  8643. var resolvePathItem = function(node, name2, index) {
  8644. var nodes = getChildNodes(node);
  8645. nodes = filter$2(nodes, function(node2, index2) {
  8646. return !isText$3(node2) || !isText$3(nodes[index2 - 1]);
  8647. });
  8648. nodes = filter$2(nodes, matchNodeNames([name2]));
  8649. return nodes[index];
  8650. };
  8651. var findTextPosition = function(container, offset) {
  8652. var node = container, targetOffset = 0, dataLen;
  8653. while (isText$3(node)) {
  8654. dataLen = node.data.length;
  8655. if (offset >= targetOffset && offset <= targetOffset + dataLen) {
  8656. container = node;
  8657. offset = offset - targetOffset;
  8658. break;
  8659. }
  8660. if (!isText$3(node.nextSibling)) {
  8661. container = node;
  8662. offset = dataLen;
  8663. break;
  8664. }
  8665. targetOffset += dataLen;
  8666. node = node.nextSibling;
  8667. }
  8668. if (isText$3(container) && offset > container.data.length) {
  8669. offset = container.data.length;
  8670. }
  8671. return CaretPosition(container, offset);
  8672. };
  8673. var resolve$2 = function(root, path) {
  8674. var offset;
  8675. if (!path) {
  8676. return null;
  8677. }
  8678. var parts = path.split(",");
  8679. var paths = parts[0].split("/");
  8680. offset = parts.length > 1 ? parts[1] : "before";
  8681. var container = reduce(paths, function(result, value2) {
  8682. var match2 = /([\w\-\(\)]+)\[([0-9]+)\]/.exec(value2);
  8683. if (!match2) {
  8684. return null;
  8685. }
  8686. if (match2[1] === "text()") {
  8687. match2[1] = "#text";
  8688. }
  8689. return resolvePathItem(result, match2[1], parseInt(match2[2], 10));
  8690. }, root);
  8691. if (!container) {
  8692. return null;
  8693. }
  8694. if (!isText$3(container)) {
  8695. if (offset === "after") {
  8696. offset = nodeIndex(container) + 1;
  8697. } else {
  8698. offset = nodeIndex(container);
  8699. }
  8700. return CaretPosition(container.parentNode, offset);
  8701. }
  8702. return findTextPosition(container, parseInt(offset, 10));
  8703. };
  8704. var isContentEditableFalse$9 = isContentEditableFalse$b;
  8705. var getNormalizedTextOffset = function(trim2, container, offset) {
  8706. var node, trimmedOffset;
  8707. trimmedOffset = trim2(container.data.slice(0, offset)).length;
  8708. for (node = container.previousSibling; node && isText$7(node); node = node.previousSibling) {
  8709. trimmedOffset += trim2(node.data).length;
  8710. }
  8711. return trimmedOffset;
  8712. };
  8713. var getPoint = function(dom2, trim2, normalized, rng, start2) {
  8714. var container = rng[start2 ? "startContainer" : "endContainer"];
  8715. var offset = rng[start2 ? "startOffset" : "endOffset"];
  8716. var point = [];
  8717. var childNodes, after2 = 0;
  8718. var root = dom2.getRoot();
  8719. if (isText$7(container)) {
  8720. point.push(normalized ? getNormalizedTextOffset(trim2, container, offset) : offset);
  8721. } else {
  8722. childNodes = container.childNodes;
  8723. if (offset >= childNodes.length && childNodes.length) {
  8724. after2 = 1;
  8725. offset = Math.max(0, childNodes.length - 1);
  8726. }
  8727. point.push(dom2.nodeIndex(childNodes[offset], normalized) + after2);
  8728. }
  8729. for (; container && container !== root; container = container.parentNode) {
  8730. point.push(dom2.nodeIndex(container, normalized));
  8731. }
  8732. return point;
  8733. };
  8734. var getLocation = function(trim2, selection, normalized, rng) {
  8735. var dom2 = selection.dom, bookmark = {};
  8736. bookmark.start = getPoint(dom2, trim2, normalized, rng, true);
  8737. if (!selection.isCollapsed()) {
  8738. bookmark.end = getPoint(dom2, trim2, normalized, rng, false);
  8739. }
  8740. if (isRangeInCaretContainerBlock(rng)) {
  8741. bookmark.isFakeCaret = true;
  8742. }
  8743. return bookmark;
  8744. };
  8745. var findIndex = function(dom2, name2, element) {
  8746. var count2 = 0;
  8747. Tools.each(dom2.select(name2), function(node) {
  8748. if (node.getAttribute("data-mce-bogus") === "all") {
  8749. return;
  8750. }
  8751. if (node === element) {
  8752. return false;
  8753. }
  8754. count2++;
  8755. });
  8756. return count2;
  8757. };
  8758. var moveEndPoint$1 = function(rng, start2) {
  8759. var container, offset, childNodes;
  8760. var prefix = start2 ? "start" : "end";
  8761. container = rng[prefix + "Container"];
  8762. offset = rng[prefix + "Offset"];
  8763. if (isElement$5(container) && container.nodeName === "TR") {
  8764. childNodes = container.childNodes;
  8765. container = childNodes[Math.min(start2 ? offset : offset - 1, childNodes.length - 1)];
  8766. if (container) {
  8767. offset = start2 ? 0 : container.childNodes.length;
  8768. rng["set" + (start2 ? "Start" : "End")](container, offset);
  8769. }
  8770. }
  8771. };
  8772. var normalizeTableCellSelection = function(rng) {
  8773. moveEndPoint$1(rng, true);
  8774. moveEndPoint$1(rng, false);
  8775. return rng;
  8776. };
  8777. var findSibling = function(node, offset) {
  8778. var sibling2;
  8779. if (isElement$5(node)) {
  8780. node = getNode$1(node, offset);
  8781. if (isContentEditableFalse$9(node)) {
  8782. return node;
  8783. }
  8784. }
  8785. if (isCaretContainer$2(node)) {
  8786. if (isText$7(node) && isCaretContainerBlock$1(node)) {
  8787. node = node.parentNode;
  8788. }
  8789. sibling2 = node.previousSibling;
  8790. if (isContentEditableFalse$9(sibling2)) {
  8791. return sibling2;
  8792. }
  8793. sibling2 = node.nextSibling;
  8794. if (isContentEditableFalse$9(sibling2)) {
  8795. return sibling2;
  8796. }
  8797. }
  8798. };
  8799. var findAdjacentContentEditableFalseElm = function(rng) {
  8800. return findSibling(rng.startContainer, rng.startOffset) || findSibling(rng.endContainer, rng.endOffset);
  8801. };
  8802. var getOffsetBookmark = function(trim2, normalized, selection) {
  8803. var element = selection.getNode();
  8804. var name2 = element ? element.nodeName : null;
  8805. var rng = selection.getRng();
  8806. if (isContentEditableFalse$9(element) || name2 === "IMG") {
  8807. return {
  8808. name: name2,
  8809. index: findIndex(selection.dom, name2, element)
  8810. };
  8811. }
  8812. var sibling2 = findAdjacentContentEditableFalseElm(rng);
  8813. if (sibling2) {
  8814. name2 = sibling2.tagName;
  8815. return {
  8816. name: name2,
  8817. index: findIndex(selection.dom, name2, sibling2)
  8818. };
  8819. }
  8820. return getLocation(trim2, selection, normalized, rng);
  8821. };
  8822. var getCaretBookmark = function(selection) {
  8823. var rng = selection.getRng();
  8824. return {
  8825. start: create$6(selection.dom.getRoot(), CaretPosition.fromRangeStart(rng)),
  8826. end: create$6(selection.dom.getRoot(), CaretPosition.fromRangeEnd(rng))
  8827. };
  8828. };
  8829. var getRangeBookmark = function(selection) {
  8830. return { rng: selection.getRng() };
  8831. };
  8832. var createBookmarkSpan = function(dom2, id, filled) {
  8833. var args = {
  8834. "data-mce-type": "bookmark",
  8835. id,
  8836. "style": "overflow:hidden;line-height:0px"
  8837. };
  8838. return filled ? dom2.create("span", args, "&#xFEFF;") : dom2.create("span", args);
  8839. };
  8840. var getPersistentBookmark = function(selection, filled) {
  8841. var dom2 = selection.dom;
  8842. var rng = selection.getRng();
  8843. var id = dom2.uniqueId();
  8844. var collapsed = selection.isCollapsed();
  8845. var element = selection.getNode();
  8846. var name2 = element.nodeName;
  8847. if (name2 === "IMG") {
  8848. return {
  8849. name: name2,
  8850. index: findIndex(dom2, name2, element)
  8851. };
  8852. }
  8853. var rng2 = normalizeTableCellSelection(rng.cloneRange());
  8854. if (!collapsed) {
  8855. rng2.collapse(false);
  8856. var endBookmarkNode = createBookmarkSpan(dom2, id + "_end", filled);
  8857. rangeInsertNode(dom2, rng2, endBookmarkNode);
  8858. }
  8859. rng = normalizeTableCellSelection(rng);
  8860. rng.collapse(true);
  8861. var startBookmarkNode = createBookmarkSpan(dom2, id + "_start", filled);
  8862. rangeInsertNode(dom2, rng, startBookmarkNode);
  8863. selection.moveToBookmark({
  8864. id,
  8865. keep: true
  8866. });
  8867. return { id };
  8868. };
  8869. var getBookmark$2 = function(selection, type2, normalized) {
  8870. if (type2 === 2) {
  8871. return getOffsetBookmark(trim$2, normalized, selection);
  8872. } else if (type2 === 3) {
  8873. return getCaretBookmark(selection);
  8874. } else if (type2) {
  8875. return getRangeBookmark(selection);
  8876. } else {
  8877. return getPersistentBookmark(selection, false);
  8878. }
  8879. };
  8880. var getUndoBookmark = curry(getOffsetBookmark, identity, true);
  8881. var DOM$9 = DOMUtils.DOM;
  8882. var defaultPreviewStyles = "font-family font-size font-weight font-style text-decoration text-transform color background-color border border-radius outline text-shadow";
  8883. var getBodySetting = function(editor, name2, defaultValue) {
  8884. var value2 = editor.getParam(name2, defaultValue);
  8885. if (value2.indexOf("=") !== -1) {
  8886. var bodyObj = editor.getParam(name2, "", "hash");
  8887. return get$9(bodyObj, editor.id).getOr(defaultValue);
  8888. } else {
  8889. return value2;
  8890. }
  8891. };
  8892. var getIframeAttrs = function(editor) {
  8893. return editor.getParam("iframe_attrs", {});
  8894. };
  8895. var getDocType = function(editor) {
  8896. return editor.getParam("doctype", "<!DOCTYPE html>");
  8897. };
  8898. var getDocumentBaseUrl = function(editor) {
  8899. return editor.getParam("document_base_url", "");
  8900. };
  8901. var getBodyId = function(editor) {
  8902. return getBodySetting(editor, "body_id", "tinymce");
  8903. };
  8904. var getBodyClass = function(editor) {
  8905. return getBodySetting(editor, "body_class", "");
  8906. };
  8907. var getContentSecurityPolicy = function(editor) {
  8908. return editor.getParam("content_security_policy", "");
  8909. };
  8910. var shouldPutBrInPre$1 = function(editor) {
  8911. return editor.getParam("br_in_pre", true);
  8912. };
  8913. var getForcedRootBlock = function(editor) {
  8914. if (editor.getParam("force_p_newlines", false)) {
  8915. return "p";
  8916. }
  8917. var block = editor.getParam("forced_root_block", "p");
  8918. if (block === false) {
  8919. return "";
  8920. } else if (block === true) {
  8921. return "p";
  8922. } else {
  8923. return block;
  8924. }
  8925. };
  8926. var getForcedRootBlockAttrs = function(editor) {
  8927. return editor.getParam("forced_root_block_attrs", {});
  8928. };
  8929. var getBrNewLineSelector = function(editor) {
  8930. return editor.getParam("br_newline_selector", ".mce-toc h2,figcaption,caption");
  8931. };
  8932. var getNoNewLineSelector = function(editor) {
  8933. return editor.getParam("no_newline_selector", "");
  8934. };
  8935. var shouldKeepStyles = function(editor) {
  8936. return editor.getParam("keep_styles", true);
  8937. };
  8938. var shouldEndContainerOnEmptyBlock = function(editor) {
  8939. return editor.getParam("end_container_on_empty_block", false);
  8940. };
  8941. var getFontStyleValues = function(editor) {
  8942. return Tools.explode(editor.getParam("font_size_style_values", "xx-small,x-small,small,medium,large,x-large,xx-large"));
  8943. };
  8944. var getFontSizeClasses = function(editor) {
  8945. return Tools.explode(editor.getParam("font_size_classes", ""));
  8946. };
  8947. var getImagesDataImgFilter = function(editor) {
  8948. return editor.getParam("images_dataimg_filter", always, "function");
  8949. };
  8950. var isAutomaticUploadsEnabled = function(editor) {
  8951. return editor.getParam("automatic_uploads", true, "boolean");
  8952. };
  8953. var shouldReuseFileName = function(editor) {
  8954. return editor.getParam("images_reuse_filename", false, "boolean");
  8955. };
  8956. var shouldReplaceBlobUris = function(editor) {
  8957. return editor.getParam("images_replace_blob_uris", true, "boolean");
  8958. };
  8959. var getIconPackName = function(editor) {
  8960. return editor.getParam("icons", "", "string");
  8961. };
  8962. var getIconsUrl = function(editor) {
  8963. return editor.getParam("icons_url", "", "string");
  8964. };
  8965. var getImageUploadUrl = function(editor) {
  8966. return editor.getParam("images_upload_url", "", "string");
  8967. };
  8968. var getImageUploadBasePath = function(editor) {
  8969. return editor.getParam("images_upload_base_path", "", "string");
  8970. };
  8971. var getImagesUploadCredentials = function(editor) {
  8972. return editor.getParam("images_upload_credentials", false, "boolean");
  8973. };
  8974. var getImagesUploadHandler = function(editor) {
  8975. return editor.getParam("images_upload_handler", null, "function");
  8976. };
  8977. var shouldUseContentCssCors = function(editor) {
  8978. return editor.getParam("content_css_cors", false, "boolean");
  8979. };
  8980. var getReferrerPolicy = function(editor) {
  8981. return editor.getParam("referrer_policy", "", "string");
  8982. };
  8983. var getLanguageCode = function(editor) {
  8984. return editor.getParam("language", "en", "string");
  8985. };
  8986. var getLanguageUrl = function(editor) {
  8987. return editor.getParam("language_url", "", "string");
  8988. };
  8989. var shouldIndentUseMargin = function(editor) {
  8990. return editor.getParam("indent_use_margin", false);
  8991. };
  8992. var getIndentation = function(editor) {
  8993. return editor.getParam("indentation", "40px", "string");
  8994. };
  8995. var getContentCss = function(editor) {
  8996. var contentCss = editor.getParam("content_css");
  8997. if (isString$1(contentCss)) {
  8998. return map$3(contentCss.split(","), trim$4);
  8999. } else if (isArray$1(contentCss)) {
  9000. return contentCss;
  9001. } else if (contentCss === false || editor.inline) {
  9002. return [];
  9003. } else {
  9004. return ["default"];
  9005. }
  9006. };
  9007. var getFontCss = function(editor) {
  9008. var fontCss = editor.getParam("font_css", []);
  9009. return isArray$1(fontCss) ? fontCss : map$3(fontCss.split(","), trim$4);
  9010. };
  9011. var getDirectionality = function(editor) {
  9012. return editor.getParam("directionality", I18n.isRtl() ? "rtl" : void 0);
  9013. };
  9014. var getInlineBoundarySelector = function(editor) {
  9015. return editor.getParam("inline_boundaries_selector", "a[href],code,.mce-annotation", "string");
  9016. };
  9017. var getObjectResizing = function(editor) {
  9018. var selector = editor.getParam("object_resizing");
  9019. if (selector === false || Env.iOS) {
  9020. return false;
  9021. } else {
  9022. return isString$1(selector) ? selector : "table,img,figure.image,div,video,iframe";
  9023. }
  9024. };
  9025. var getResizeImgProportional = function(editor) {
  9026. return editor.getParam("resize_img_proportional", true, "boolean");
  9027. };
  9028. var getPlaceholder = function(editor) {
  9029. return editor.getParam("placeholder", DOM$9.getAttrib(editor.getElement(), "placeholder"), "string");
  9030. };
  9031. var getEventRoot = function(editor) {
  9032. return editor.getParam("event_root");
  9033. };
  9034. var getServiceMessage = function(editor) {
  9035. return editor.getParam("service_message");
  9036. };
  9037. var getTheme = function(editor) {
  9038. return editor.getParam("theme");
  9039. };
  9040. var shouldValidate = function(editor) {
  9041. return editor.getParam("validate");
  9042. };
  9043. var isInlineBoundariesEnabled = function(editor) {
  9044. return editor.getParam("inline_boundaries") !== false;
  9045. };
  9046. var getFormats = function(editor) {
  9047. return editor.getParam("formats");
  9048. };
  9049. var getPreviewStyles = function(editor) {
  9050. var style = editor.getParam("preview_styles", defaultPreviewStyles);
  9051. if (isString$1(style)) {
  9052. return style;
  9053. } else {
  9054. return "";
  9055. }
  9056. };
  9057. var canFormatEmptyLines = function(editor) {
  9058. return editor.getParam("format_empty_lines", false, "boolean");
  9059. };
  9060. var getCustomUiSelector = function(editor) {
  9061. return editor.getParam("custom_ui_selector", "", "string");
  9062. };
  9063. var getThemeUrl = function(editor) {
  9064. return editor.getParam("theme_url");
  9065. };
  9066. var isInline = function(editor) {
  9067. return editor.getParam("inline");
  9068. };
  9069. var hasHiddenInput = function(editor) {
  9070. return editor.getParam("hidden_input");
  9071. };
  9072. var shouldPatchSubmit = function(editor) {
  9073. return editor.getParam("submit_patch");
  9074. };
  9075. var isEncodingXml = function(editor) {
  9076. return editor.getParam("encoding") === "xml";
  9077. };
  9078. var shouldAddFormSubmitTrigger = function(editor) {
  9079. return editor.getParam("add_form_submit_trigger");
  9080. };
  9081. var shouldAddUnloadTrigger = function(editor) {
  9082. return editor.getParam("add_unload_trigger");
  9083. };
  9084. var hasForcedRootBlock = function(editor) {
  9085. return getForcedRootBlock(editor) !== "";
  9086. };
  9087. var getCustomUndoRedoLevels = function(editor) {
  9088. return editor.getParam("custom_undo_redo_levels", 0, "number");
  9089. };
  9090. var shouldDisableNodeChange = function(editor) {
  9091. return editor.getParam("disable_nodechange");
  9092. };
  9093. var isReadOnly$1 = function(editor) {
  9094. return editor.getParam("readonly");
  9095. };
  9096. var hasContentCssCors = function(editor) {
  9097. return editor.getParam("content_css_cors");
  9098. };
  9099. var getPlugins = function(editor) {
  9100. return editor.getParam("plugins", "", "string");
  9101. };
  9102. var getExternalPlugins$1 = function(editor) {
  9103. return editor.getParam("external_plugins");
  9104. };
  9105. var shouldBlockUnsupportedDrop = function(editor) {
  9106. return editor.getParam("block_unsupported_drop", true, "boolean");
  9107. };
  9108. var isVisualAidsEnabled = function(editor) {
  9109. return editor.getParam("visual", true, "boolean");
  9110. };
  9111. var getVisualAidsTableClass = function(editor) {
  9112. return editor.getParam("visual_table_class", "mce-item-table", "string");
  9113. };
  9114. var getVisualAidsAnchorClass = function(editor) {
  9115. return editor.getParam("visual_anchor_class", "mce-item-anchor", "string");
  9116. };
  9117. var getIframeAriaText = function(editor) {
  9118. return editor.getParam("iframe_aria_text", "Rich Text Area. Press ALT-0 for help.", "string");
  9119. };
  9120. var isElement$2 = isElement$5;
  9121. var isText$2 = isText$7;
  9122. var removeNode$1 = function(node) {
  9123. var parentNode = node.parentNode;
  9124. if (parentNode) {
  9125. parentNode.removeChild(node);
  9126. }
  9127. };
  9128. var trimCount = function(text) {
  9129. var trimmedText = trim$2(text);
  9130. return {
  9131. count: text.length - trimmedText.length,
  9132. text: trimmedText
  9133. };
  9134. };
  9135. var deleteZwspChars = function(caretContainer) {
  9136. var idx;
  9137. while ((idx = caretContainer.data.lastIndexOf(ZWSP$1)) !== -1) {
  9138. caretContainer.deleteData(idx, 1);
  9139. }
  9140. };
  9141. var removeUnchanged = function(caretContainer, pos) {
  9142. remove$2(caretContainer);
  9143. return pos;
  9144. };
  9145. var removeTextAndReposition = function(caretContainer, pos) {
  9146. var before2 = trimCount(caretContainer.data.substr(0, pos.offset()));
  9147. var after2 = trimCount(caretContainer.data.substr(pos.offset()));
  9148. var text = before2.text + after2.text;
  9149. if (text.length > 0) {
  9150. deleteZwspChars(caretContainer);
  9151. return CaretPosition(caretContainer, pos.offset() - before2.count);
  9152. } else {
  9153. return pos;
  9154. }
  9155. };
  9156. var removeElementAndReposition = function(caretContainer, pos) {
  9157. var parentNode = pos.container();
  9158. var newPosition = indexOf$2(from(parentNode.childNodes), caretContainer).map(function(index) {
  9159. return index < pos.offset() ? CaretPosition(parentNode, pos.offset() - 1) : pos;
  9160. }).getOr(pos);
  9161. remove$2(caretContainer);
  9162. return newPosition;
  9163. };
  9164. var removeTextCaretContainer = function(caretContainer, pos) {
  9165. return isText$2(caretContainer) && pos.container() === caretContainer ? removeTextAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
  9166. };
  9167. var removeElementCaretContainer = function(caretContainer, pos) {
  9168. return pos.container() === caretContainer.parentNode ? removeElementAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
  9169. };
  9170. var removeAndReposition = function(container, pos) {
  9171. return CaretPosition.isTextPosition(pos) ? removeTextCaretContainer(container, pos) : removeElementCaretContainer(container, pos);
  9172. };
  9173. var remove$2 = function(caretContainerNode) {
  9174. if (isElement$2(caretContainerNode) && isCaretContainer$2(caretContainerNode)) {
  9175. if (hasContent(caretContainerNode)) {
  9176. caretContainerNode.removeAttribute("data-mce-caret");
  9177. } else {
  9178. removeNode$1(caretContainerNode);
  9179. }
  9180. }
  9181. if (isText$2(caretContainerNode)) {
  9182. deleteZwspChars(caretContainerNode);
  9183. if (caretContainerNode.data.length === 0) {
  9184. removeNode$1(caretContainerNode);
  9185. }
  9186. }
  9187. };
  9188. var browser$2 = detect().browser;
  9189. var isContentEditableFalse$8 = isContentEditableFalse$b;
  9190. var isMedia$1 = isMedia$2;
  9191. var isTableCell$3 = isTableCell$5;
  9192. var inlineFakeCaretSelector = "*[contentEditable=false],video,audio,embed,object";
  9193. var getAbsoluteClientRect = function(root, element, before2) {
  9194. var clientRect = collapse(element.getBoundingClientRect(), before2);
  9195. var scrollX;
  9196. var scrollY;
  9197. if (root.tagName === "BODY") {
  9198. var docElm = root.ownerDocument.documentElement;
  9199. scrollX = root.scrollLeft || docElm.scrollLeft;
  9200. scrollY = root.scrollTop || docElm.scrollTop;
  9201. } else {
  9202. var rootRect = root.getBoundingClientRect();
  9203. scrollX = root.scrollLeft - rootRect.left;
  9204. scrollY = root.scrollTop - rootRect.top;
  9205. }
  9206. clientRect.left += scrollX;
  9207. clientRect.right += scrollX;
  9208. clientRect.top += scrollY;
  9209. clientRect.bottom += scrollY;
  9210. clientRect.width = 1;
  9211. var margin = element.offsetWidth - element.clientWidth;
  9212. if (margin > 0) {
  9213. if (before2) {
  9214. margin *= -1;
  9215. }
  9216. clientRect.left += margin;
  9217. clientRect.right += margin;
  9218. }
  9219. return clientRect;
  9220. };
  9221. var trimInlineCaretContainers = function(root) {
  9222. var fakeCaretTargetNodes = descendants(SugarElement.fromDom(root), inlineFakeCaretSelector);
  9223. for (var i = 0; i < fakeCaretTargetNodes.length; i++) {
  9224. var node = fakeCaretTargetNodes[i].dom;
  9225. var sibling2 = node.previousSibling;
  9226. if (endsWithCaretContainer$1(sibling2)) {
  9227. var data2 = sibling2.data;
  9228. if (data2.length === 1) {
  9229. sibling2.parentNode.removeChild(sibling2);
  9230. } else {
  9231. sibling2.deleteData(data2.length - 1, 1);
  9232. }
  9233. }
  9234. sibling2 = node.nextSibling;
  9235. if (startsWithCaretContainer$1(sibling2)) {
  9236. var data2 = sibling2.data;
  9237. if (data2.length === 1) {
  9238. sibling2.parentNode.removeChild(sibling2);
  9239. } else {
  9240. sibling2.deleteData(0, 1);
  9241. }
  9242. }
  9243. }
  9244. };
  9245. var FakeCaret = function(editor, root, isBlock2, hasFocus2) {
  9246. var lastVisualCaret = value();
  9247. var cursorInterval;
  9248. var caretContainerNode;
  9249. var rootBlock = getForcedRootBlock(editor);
  9250. var caretBlock = rootBlock.length > 0 ? rootBlock : "p";
  9251. var show = function(before2, element) {
  9252. var rng;
  9253. hide();
  9254. if (isTableCell$3(element)) {
  9255. return null;
  9256. }
  9257. if (isBlock2(element)) {
  9258. caretContainerNode = insertBlock$1(caretBlock, element, before2);
  9259. var clientRect = getAbsoluteClientRect(root, element, before2);
  9260. DomQuery(caretContainerNode).css("top", clientRect.top);
  9261. var caret = DomQuery('<div class="mce-visual-caret" data-mce-bogus="all"></div>').css(__assign({}, clientRect)).appendTo(root)[0];
  9262. lastVisualCaret.set({
  9263. caret,
  9264. element,
  9265. before: before2
  9266. });
  9267. if (before2) {
  9268. DomQuery(caret).addClass("mce-visual-caret-before");
  9269. }
  9270. startBlink();
  9271. rng = element.ownerDocument.createRange();
  9272. rng.setStart(caretContainerNode, 0);
  9273. rng.setEnd(caretContainerNode, 0);
  9274. } else {
  9275. caretContainerNode = insertInline$1(element, before2);
  9276. rng = element.ownerDocument.createRange();
  9277. if (isInlineFakeCaretTarget(caretContainerNode.nextSibling)) {
  9278. rng.setStart(caretContainerNode, 0);
  9279. rng.setEnd(caretContainerNode, 0);
  9280. } else {
  9281. rng.setStart(caretContainerNode, 1);
  9282. rng.setEnd(caretContainerNode, 1);
  9283. }
  9284. return rng;
  9285. }
  9286. return rng;
  9287. };
  9288. var hide = function() {
  9289. trimInlineCaretContainers(root);
  9290. if (caretContainerNode) {
  9291. remove$2(caretContainerNode);
  9292. caretContainerNode = null;
  9293. }
  9294. lastVisualCaret.on(function(caretState) {
  9295. DomQuery(caretState.caret).remove();
  9296. lastVisualCaret.clear();
  9297. });
  9298. if (cursorInterval) {
  9299. Delay.clearInterval(cursorInterval);
  9300. cursorInterval = void 0;
  9301. }
  9302. };
  9303. var startBlink = function() {
  9304. cursorInterval = Delay.setInterval(function() {
  9305. if (hasFocus2()) {
  9306. DomQuery("div.mce-visual-caret", root).toggleClass("mce-visual-caret-hidden");
  9307. } else {
  9308. DomQuery("div.mce-visual-caret", root).addClass("mce-visual-caret-hidden");
  9309. }
  9310. }, 500);
  9311. };
  9312. var reposition2 = function() {
  9313. lastVisualCaret.on(function(caretState) {
  9314. var clientRect = getAbsoluteClientRect(root, caretState.element, caretState.before);
  9315. DomQuery(caretState.caret).css(__assign({}, clientRect));
  9316. });
  9317. };
  9318. var destroy2 = function() {
  9319. return Delay.clearInterval(cursorInterval);
  9320. };
  9321. var getCss = function() {
  9322. 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;}";
  9323. };
  9324. return {
  9325. show,
  9326. hide,
  9327. getCss,
  9328. reposition: reposition2,
  9329. destroy: destroy2
  9330. };
  9331. };
  9332. var isFakeCaretTableBrowser = function() {
  9333. return browser$2.isIE() || browser$2.isEdge() || browser$2.isFirefox();
  9334. };
  9335. var isInlineFakeCaretTarget = function(node) {
  9336. return isContentEditableFalse$8(node) || isMedia$1(node);
  9337. };
  9338. var isFakeCaretTarget = function(node) {
  9339. return isInlineFakeCaretTarget(node) || isTable$3(node) && isFakeCaretTableBrowser();
  9340. };
  9341. var isContentEditableFalse$7 = isContentEditableFalse$b;
  9342. var isMedia = isMedia$2;
  9343. var isBlockLike = matchStyleValues("display", "block table table-cell table-caption list-item");
  9344. var isCaretContainer = isCaretContainer$2;
  9345. var isCaretContainerBlock = isCaretContainerBlock$1;
  9346. var isElement$1 = isElement$5;
  9347. var isCaretCandidate$1 = isCaretCandidate$3;
  9348. var isForwards = function(direction) {
  9349. return direction > 0;
  9350. };
  9351. var isBackwards = function(direction) {
  9352. return direction < 0;
  9353. };
  9354. var skipCaretContainers = function(walk2, shallow2) {
  9355. var node;
  9356. while (node = walk2(shallow2)) {
  9357. if (!isCaretContainerBlock(node)) {
  9358. return node;
  9359. }
  9360. }
  9361. return null;
  9362. };
  9363. var findNode$1 = function(node, direction, predicateFn, rootNode, shallow2) {
  9364. var walker = new DomTreeWalker(node, rootNode);
  9365. var isCefOrCaretContainer = isContentEditableFalse$7(node) || isCaretContainerBlock(node);
  9366. if (isBackwards(direction)) {
  9367. if (isCefOrCaretContainer) {
  9368. node = skipCaretContainers(walker.prev.bind(walker), true);
  9369. if (predicateFn(node)) {
  9370. return node;
  9371. }
  9372. }
  9373. while (node = skipCaretContainers(walker.prev.bind(walker), shallow2)) {
  9374. if (predicateFn(node)) {
  9375. return node;
  9376. }
  9377. }
  9378. }
  9379. if (isForwards(direction)) {
  9380. if (isCefOrCaretContainer) {
  9381. node = skipCaretContainers(walker.next.bind(walker), true);
  9382. if (predicateFn(node)) {
  9383. return node;
  9384. }
  9385. }
  9386. while (node = skipCaretContainers(walker.next.bind(walker), shallow2)) {
  9387. if (predicateFn(node)) {
  9388. return node;
  9389. }
  9390. }
  9391. }
  9392. return null;
  9393. };
  9394. var getParentBlock$2 = function(node, rootNode) {
  9395. while (node && node !== rootNode) {
  9396. if (isBlockLike(node)) {
  9397. return node;
  9398. }
  9399. node = node.parentNode;
  9400. }
  9401. return null;
  9402. };
  9403. var isInSameBlock = function(caretPosition1, caretPosition2, rootNode) {
  9404. return getParentBlock$2(caretPosition1.container(), rootNode) === getParentBlock$2(caretPosition2.container(), rootNode);
  9405. };
  9406. var getChildNodeAtRelativeOffset = function(relativeOffset, caretPosition) {
  9407. if (!caretPosition) {
  9408. return null;
  9409. }
  9410. var container = caretPosition.container();
  9411. var offset = caretPosition.offset();
  9412. if (!isElement$1(container)) {
  9413. return null;
  9414. }
  9415. return container.childNodes[offset + relativeOffset];
  9416. };
  9417. var beforeAfter = function(before2, node) {
  9418. var range2 = node.ownerDocument.createRange();
  9419. if (before2) {
  9420. range2.setStartBefore(node);
  9421. range2.setEndBefore(node);
  9422. } else {
  9423. range2.setStartAfter(node);
  9424. range2.setEndAfter(node);
  9425. }
  9426. return range2;
  9427. };
  9428. var isNodesInSameBlock = function(root, node1, node2) {
  9429. return getParentBlock$2(node1, root) === getParentBlock$2(node2, root);
  9430. };
  9431. var lean = function(left, root, node) {
  9432. var siblingName = left ? "previousSibling" : "nextSibling";
  9433. while (node && node !== root) {
  9434. var sibling2 = node[siblingName];
  9435. if (isCaretContainer(sibling2)) {
  9436. sibling2 = sibling2[siblingName];
  9437. }
  9438. if (isContentEditableFalse$7(sibling2) || isMedia(sibling2)) {
  9439. if (isNodesInSameBlock(root, sibling2, node)) {
  9440. return sibling2;
  9441. }
  9442. break;
  9443. }
  9444. if (isCaretCandidate$1(sibling2)) {
  9445. break;
  9446. }
  9447. node = node.parentNode;
  9448. }
  9449. return null;
  9450. };
  9451. var before$2 = curry(beforeAfter, true);
  9452. var after$2 = curry(beforeAfter, false);
  9453. var normalizeRange = function(direction, root, range2) {
  9454. var node;
  9455. var leanLeft = curry(lean, true, root);
  9456. var leanRight2 = curry(lean, false, root);
  9457. var container = range2.startContainer;
  9458. var offset = range2.startOffset;
  9459. if (isCaretContainerBlock$1(container)) {
  9460. if (!isElement$1(container)) {
  9461. container = container.parentNode;
  9462. }
  9463. var location_1 = container.getAttribute("data-mce-caret");
  9464. if (location_1 === "before") {
  9465. node = container.nextSibling;
  9466. if (isFakeCaretTarget(node)) {
  9467. return before$2(node);
  9468. }
  9469. }
  9470. if (location_1 === "after") {
  9471. node = container.previousSibling;
  9472. if (isFakeCaretTarget(node)) {
  9473. return after$2(node);
  9474. }
  9475. }
  9476. }
  9477. if (!range2.collapsed) {
  9478. return range2;
  9479. }
  9480. if (isText$7(container)) {
  9481. if (isCaretContainer(container)) {
  9482. if (direction === 1) {
  9483. node = leanRight2(container);
  9484. if (node) {
  9485. return before$2(node);
  9486. }
  9487. node = leanLeft(container);
  9488. if (node) {
  9489. return after$2(node);
  9490. }
  9491. }
  9492. if (direction === -1) {
  9493. node = leanLeft(container);
  9494. if (node) {
  9495. return after$2(node);
  9496. }
  9497. node = leanRight2(container);
  9498. if (node) {
  9499. return before$2(node);
  9500. }
  9501. }
  9502. return range2;
  9503. }
  9504. if (endsWithCaretContainer$1(container) && offset >= container.data.length - 1) {
  9505. if (direction === 1) {
  9506. node = leanRight2(container);
  9507. if (node) {
  9508. return before$2(node);
  9509. }
  9510. }
  9511. return range2;
  9512. }
  9513. if (startsWithCaretContainer$1(container) && offset <= 1) {
  9514. if (direction === -1) {
  9515. node = leanLeft(container);
  9516. if (node) {
  9517. return after$2(node);
  9518. }
  9519. }
  9520. return range2;
  9521. }
  9522. if (offset === container.data.length) {
  9523. node = leanRight2(container);
  9524. if (node) {
  9525. return before$2(node);
  9526. }
  9527. return range2;
  9528. }
  9529. if (offset === 0) {
  9530. node = leanLeft(container);
  9531. if (node) {
  9532. return after$2(node);
  9533. }
  9534. return range2;
  9535. }
  9536. }
  9537. return range2;
  9538. };
  9539. var getRelativeCefElm = function(forward, caretPosition) {
  9540. return Optional.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition)).filter(isContentEditableFalse$7);
  9541. };
  9542. var getNormalizedRangeEndPoint = function(direction, root, range2) {
  9543. var normalizedRange = normalizeRange(direction, root, range2);
  9544. if (direction === -1) {
  9545. return CaretPosition.fromRangeStart(normalizedRange);
  9546. }
  9547. return CaretPosition.fromRangeEnd(normalizedRange);
  9548. };
  9549. var getElementFromPosition = function(pos) {
  9550. return Optional.from(pos.getNode()).map(SugarElement.fromDom);
  9551. };
  9552. var getElementFromPrevPosition = function(pos) {
  9553. return Optional.from(pos.getNode(true)).map(SugarElement.fromDom);
  9554. };
  9555. var getVisualCaretPosition = function(walkFn, caretPosition) {
  9556. while (caretPosition = walkFn(caretPosition)) {
  9557. if (caretPosition.isVisible()) {
  9558. return caretPosition;
  9559. }
  9560. }
  9561. return caretPosition;
  9562. };
  9563. var isMoveInsideSameBlock = function(from2, to2) {
  9564. var inSameBlock = isInSameBlock(from2, to2);
  9565. if (!inSameBlock && isBr$5(from2.getNode())) {
  9566. return true;
  9567. }
  9568. return inSameBlock;
  9569. };
  9570. var HDirection;
  9571. (function(HDirection2) {
  9572. HDirection2[HDirection2["Backwards"] = -1] = "Backwards";
  9573. HDirection2[HDirection2["Forwards"] = 1] = "Forwards";
  9574. })(HDirection || (HDirection = {}));
  9575. var isContentEditableFalse$6 = isContentEditableFalse$b;
  9576. var isText$1 = isText$7;
  9577. var isElement = isElement$5;
  9578. var isBr$1 = isBr$5;
  9579. var isCaretCandidate = isCaretCandidate$3;
  9580. var isAtomic = isAtomic$1;
  9581. var isEditableCaretCandidate = isEditableCaretCandidate$1;
  9582. var getParents$3 = function(node, root) {
  9583. var parents2 = [];
  9584. while (node && node !== root) {
  9585. parents2.push(node);
  9586. node = node.parentNode;
  9587. }
  9588. return parents2;
  9589. };
  9590. var nodeAtIndex = function(container, offset) {
  9591. if (container.hasChildNodes() && offset < container.childNodes.length) {
  9592. return container.childNodes[offset];
  9593. }
  9594. return null;
  9595. };
  9596. var getCaretCandidatePosition = function(direction, node) {
  9597. if (isForwards(direction)) {
  9598. if (isCaretCandidate(node.previousSibling) && !isText$1(node.previousSibling)) {
  9599. return CaretPosition.before(node);
  9600. }
  9601. if (isText$1(node)) {
  9602. return CaretPosition(node, 0);
  9603. }
  9604. }
  9605. if (isBackwards(direction)) {
  9606. if (isCaretCandidate(node.nextSibling) && !isText$1(node.nextSibling)) {
  9607. return CaretPosition.after(node);
  9608. }
  9609. if (isText$1(node)) {
  9610. return CaretPosition(node, node.data.length);
  9611. }
  9612. }
  9613. if (isBackwards(direction)) {
  9614. if (isBr$1(node)) {
  9615. return CaretPosition.before(node);
  9616. }
  9617. return CaretPosition.after(node);
  9618. }
  9619. return CaretPosition.before(node);
  9620. };
  9621. var moveForwardFromBr = function(root, nextNode) {
  9622. var nextSibling2 = nextNode.nextSibling;
  9623. if (nextSibling2 && isCaretCandidate(nextSibling2)) {
  9624. if (isText$1(nextSibling2)) {
  9625. return CaretPosition(nextSibling2, 0);
  9626. } else {
  9627. return CaretPosition.before(nextSibling2);
  9628. }
  9629. } else {
  9630. return findCaretPosition$1(HDirection.Forwards, CaretPosition.after(nextNode), root);
  9631. }
  9632. };
  9633. var findCaretPosition$1 = function(direction, startPos, root) {
  9634. var node;
  9635. var nextNode;
  9636. var innerNode;
  9637. var caretPosition;
  9638. if (!isElement(root) || !startPos) {
  9639. return null;
  9640. }
  9641. if (startPos.isEqual(CaretPosition.after(root)) && root.lastChild) {
  9642. caretPosition = CaretPosition.after(root.lastChild);
  9643. if (isBackwards(direction) && isCaretCandidate(root.lastChild) && isElement(root.lastChild)) {
  9644. return isBr$1(root.lastChild) ? CaretPosition.before(root.lastChild) : caretPosition;
  9645. }
  9646. } else {
  9647. caretPosition = startPos;
  9648. }
  9649. var container = caretPosition.container();
  9650. var offset = caretPosition.offset();
  9651. if (isText$1(container)) {
  9652. if (isBackwards(direction) && offset > 0) {
  9653. return CaretPosition(container, --offset);
  9654. }
  9655. if (isForwards(direction) && offset < container.length) {
  9656. return CaretPosition(container, ++offset);
  9657. }
  9658. node = container;
  9659. } else {
  9660. if (isBackwards(direction) && offset > 0) {
  9661. nextNode = nodeAtIndex(container, offset - 1);
  9662. if (isCaretCandidate(nextNode)) {
  9663. if (!isAtomic(nextNode)) {
  9664. innerNode = findNode$1(nextNode, direction, isEditableCaretCandidate, nextNode);
  9665. if (innerNode) {
  9666. if (isText$1(innerNode)) {
  9667. return CaretPosition(innerNode, innerNode.data.length);
  9668. }
  9669. return CaretPosition.after(innerNode);
  9670. }
  9671. }
  9672. if (isText$1(nextNode)) {
  9673. return CaretPosition(nextNode, nextNode.data.length);
  9674. }
  9675. return CaretPosition.before(nextNode);
  9676. }
  9677. }
  9678. if (isForwards(direction) && offset < container.childNodes.length) {
  9679. nextNode = nodeAtIndex(container, offset);
  9680. if (isCaretCandidate(nextNode)) {
  9681. if (isBr$1(nextNode)) {
  9682. return moveForwardFromBr(root, nextNode);
  9683. }
  9684. if (!isAtomic(nextNode)) {
  9685. innerNode = findNode$1(nextNode, direction, isEditableCaretCandidate, nextNode);
  9686. if (innerNode) {
  9687. if (isText$1(innerNode)) {
  9688. return CaretPosition(innerNode, 0);
  9689. }
  9690. return CaretPosition.before(innerNode);
  9691. }
  9692. }
  9693. if (isText$1(nextNode)) {
  9694. return CaretPosition(nextNode, 0);
  9695. }
  9696. return CaretPosition.after(nextNode);
  9697. }
  9698. }
  9699. node = nextNode ? nextNode : caretPosition.getNode();
  9700. }
  9701. if (isForwards(direction) && caretPosition.isAtEnd() || isBackwards(direction) && caretPosition.isAtStart()) {
  9702. node = findNode$1(node, direction, always, root, true);
  9703. if (isEditableCaretCandidate(node, root)) {
  9704. return getCaretCandidatePosition(direction, node);
  9705. }
  9706. }
  9707. nextNode = findNode$1(node, direction, isEditableCaretCandidate, root);
  9708. var rootContentEditableFalseElm = last$1(filter$4(getParents$3(container, root), isContentEditableFalse$6));
  9709. if (rootContentEditableFalseElm && (!nextNode || !rootContentEditableFalseElm.contains(nextNode))) {
  9710. if (isForwards(direction)) {
  9711. caretPosition = CaretPosition.after(rootContentEditableFalseElm);
  9712. } else {
  9713. caretPosition = CaretPosition.before(rootContentEditableFalseElm);
  9714. }
  9715. return caretPosition;
  9716. }
  9717. if (nextNode) {
  9718. return getCaretCandidatePosition(direction, nextNode);
  9719. }
  9720. return null;
  9721. };
  9722. var CaretWalker = function(root) {
  9723. return {
  9724. next: function(caretPosition) {
  9725. return findCaretPosition$1(HDirection.Forwards, caretPosition, root);
  9726. },
  9727. prev: function(caretPosition) {
  9728. return findCaretPosition$1(HDirection.Backwards, caretPosition, root);
  9729. }
  9730. };
  9731. };
  9732. var walkToPositionIn = function(forward, root, start2) {
  9733. var position = forward ? CaretPosition.before(start2) : CaretPosition.after(start2);
  9734. return fromPosition(forward, root, position);
  9735. };
  9736. var afterElement = function(node) {
  9737. return isBr$5(node) ? CaretPosition.before(node) : CaretPosition.after(node);
  9738. };
  9739. var isBeforeOrStart = function(position) {
  9740. if (CaretPosition.isTextPosition(position)) {
  9741. return position.offset() === 0;
  9742. } else {
  9743. return isCaretCandidate$3(position.getNode());
  9744. }
  9745. };
  9746. var isAfterOrEnd = function(position) {
  9747. if (CaretPosition.isTextPosition(position)) {
  9748. var container = position.container();
  9749. return position.offset() === container.data.length;
  9750. } else {
  9751. return isCaretCandidate$3(position.getNode(true));
  9752. }
  9753. };
  9754. var isBeforeAfterSameElement = function(from2, to2) {
  9755. return !CaretPosition.isTextPosition(from2) && !CaretPosition.isTextPosition(to2) && from2.getNode() === to2.getNode(true);
  9756. };
  9757. var isAtBr = function(position) {
  9758. return !CaretPosition.isTextPosition(position) && isBr$5(position.getNode());
  9759. };
  9760. var shouldSkipPosition = function(forward, from2, to2) {
  9761. if (forward) {
  9762. return !isBeforeAfterSameElement(from2, to2) && !isAtBr(from2) && isAfterOrEnd(from2) && isBeforeOrStart(to2);
  9763. } else {
  9764. return !isBeforeAfterSameElement(to2, from2) && isBeforeOrStart(from2) && isAfterOrEnd(to2);
  9765. }
  9766. };
  9767. var fromPosition = function(forward, root, pos) {
  9768. var walker = CaretWalker(root);
  9769. return Optional.from(forward ? walker.next(pos) : walker.prev(pos));
  9770. };
  9771. var navigate = function(forward, root, from2) {
  9772. return fromPosition(forward, root, from2).bind(function(to2) {
  9773. if (isInSameBlock(from2, to2, root) && shouldSkipPosition(forward, from2, to2)) {
  9774. return fromPosition(forward, root, to2);
  9775. } else {
  9776. return Optional.some(to2);
  9777. }
  9778. });
  9779. };
  9780. var navigateIgnore = function(forward, root, from2, ignoreFilter) {
  9781. return navigate(forward, root, from2).bind(function(pos) {
  9782. return ignoreFilter(pos) ? navigateIgnore(forward, root, pos, ignoreFilter) : Optional.some(pos);
  9783. });
  9784. };
  9785. var positionIn = function(forward, element) {
  9786. var startNode = forward ? element.firstChild : element.lastChild;
  9787. if (isText$7(startNode)) {
  9788. return Optional.some(CaretPosition(startNode, forward ? 0 : startNode.data.length));
  9789. } else if (startNode) {
  9790. if (isCaretCandidate$3(startNode)) {
  9791. return Optional.some(forward ? CaretPosition.before(startNode) : afterElement(startNode));
  9792. } else {
  9793. return walkToPositionIn(forward, element, startNode);
  9794. }
  9795. } else {
  9796. return Optional.none();
  9797. }
  9798. };
  9799. var nextPosition = curry(fromPosition, true);
  9800. var prevPosition = curry(fromPosition, false);
  9801. var firstPositionIn = curry(positionIn, true);
  9802. var lastPositionIn = curry(positionIn, false);
  9803. var CARET_ID$1 = "_mce_caret";
  9804. var isCaretNode = function(node) {
  9805. return isElement$5(node) && node.id === CARET_ID$1;
  9806. };
  9807. var getParentCaretContainer = function(body, node) {
  9808. while (node && node !== body) {
  9809. if (node.id === CARET_ID$1) {
  9810. return node;
  9811. }
  9812. node = node.parentNode;
  9813. }
  9814. return null;
  9815. };
  9816. var isStringPathBookmark = function(bookmark) {
  9817. return isString$1(bookmark.start);
  9818. };
  9819. var isRangeBookmark = function(bookmark) {
  9820. return has$2(bookmark, "rng");
  9821. };
  9822. var isIdBookmark = function(bookmark) {
  9823. return has$2(bookmark, "id");
  9824. };
  9825. var isIndexBookmark = function(bookmark) {
  9826. return has$2(bookmark, "name");
  9827. };
  9828. var isPathBookmark = function(bookmark) {
  9829. return Tools.isArray(bookmark.start);
  9830. };
  9831. var addBogus = function(dom2, node) {
  9832. if (isElement$5(node) && dom2.isBlock(node) && !node.innerHTML && !Env.ie) {
  9833. node.innerHTML = '<br data-mce-bogus="1" />';
  9834. }
  9835. return node;
  9836. };
  9837. var resolveCaretPositionBookmark = function(dom2, bookmark) {
  9838. var pos;
  9839. var rng = dom2.createRng();
  9840. pos = resolve$2(dom2.getRoot(), bookmark.start);
  9841. rng.setStart(pos.container(), pos.offset());
  9842. pos = resolve$2(dom2.getRoot(), bookmark.end);
  9843. rng.setEnd(pos.container(), pos.offset());
  9844. return rng;
  9845. };
  9846. var insertZwsp = function(node, rng) {
  9847. var textNode = node.ownerDocument.createTextNode(ZWSP$1);
  9848. node.appendChild(textNode);
  9849. rng.setStart(textNode, 0);
  9850. rng.setEnd(textNode, 0);
  9851. };
  9852. var isEmpty$1 = function(node) {
  9853. return node.hasChildNodes() === false;
  9854. };
  9855. var tryFindRangePosition = function(node, rng) {
  9856. return lastPositionIn(node).fold(never, function(pos) {
  9857. rng.setStart(pos.container(), pos.offset());
  9858. rng.setEnd(pos.container(), pos.offset());
  9859. return true;
  9860. });
  9861. };
  9862. var padEmptyCaretContainer = function(root, node, rng) {
  9863. if (isEmpty$1(node) && getParentCaretContainer(root, node)) {
  9864. insertZwsp(node, rng);
  9865. return true;
  9866. } else {
  9867. return false;
  9868. }
  9869. };
  9870. var setEndPoint = function(dom2, start2, bookmark, rng) {
  9871. var point = bookmark[start2 ? "start" : "end"];
  9872. var i, node, offset, children2;
  9873. var root = dom2.getRoot();
  9874. if (point) {
  9875. offset = point[0];
  9876. for (node = root, i = point.length - 1; i >= 1; i--) {
  9877. children2 = node.childNodes;
  9878. if (padEmptyCaretContainer(root, node, rng)) {
  9879. return true;
  9880. }
  9881. if (point[i] > children2.length - 1) {
  9882. if (padEmptyCaretContainer(root, node, rng)) {
  9883. return true;
  9884. }
  9885. return tryFindRangePosition(node, rng);
  9886. }
  9887. node = children2[point[i]];
  9888. }
  9889. if (node.nodeType === 3) {
  9890. offset = Math.min(point[0], node.nodeValue.length);
  9891. }
  9892. if (node.nodeType === 1) {
  9893. offset = Math.min(point[0], node.childNodes.length);
  9894. }
  9895. if (start2) {
  9896. rng.setStart(node, offset);
  9897. } else {
  9898. rng.setEnd(node, offset);
  9899. }
  9900. }
  9901. return true;
  9902. };
  9903. var isValidTextNode = function(node) {
  9904. return isText$7(node) && node.data.length > 0;
  9905. };
  9906. var restoreEndPoint = function(dom2, suffix, bookmark) {
  9907. var marker = dom2.get(bookmark.id + "_" + suffix), node, idx, next, prev;
  9908. var keep = bookmark.keep;
  9909. var container, offset;
  9910. if (marker) {
  9911. node = marker.parentNode;
  9912. if (suffix === "start") {
  9913. if (!keep) {
  9914. idx = dom2.nodeIndex(marker);
  9915. } else {
  9916. if (marker.hasChildNodes()) {
  9917. node = marker.firstChild;
  9918. idx = 1;
  9919. } else if (isValidTextNode(marker.nextSibling)) {
  9920. node = marker.nextSibling;
  9921. idx = 0;
  9922. } else if (isValidTextNode(marker.previousSibling)) {
  9923. node = marker.previousSibling;
  9924. idx = marker.previousSibling.data.length;
  9925. } else {
  9926. node = marker.parentNode;
  9927. idx = dom2.nodeIndex(marker) + 1;
  9928. }
  9929. }
  9930. container = node;
  9931. offset = idx;
  9932. } else {
  9933. if (!keep) {
  9934. idx = dom2.nodeIndex(marker);
  9935. } else {
  9936. if (marker.hasChildNodes()) {
  9937. node = marker.firstChild;
  9938. idx = 1;
  9939. } else if (isValidTextNode(marker.previousSibling)) {
  9940. node = marker.previousSibling;
  9941. idx = marker.previousSibling.data.length;
  9942. } else {
  9943. node = marker.parentNode;
  9944. idx = dom2.nodeIndex(marker);
  9945. }
  9946. }
  9947. container = node;
  9948. offset = idx;
  9949. }
  9950. if (!keep) {
  9951. prev = marker.previousSibling;
  9952. next = marker.nextSibling;
  9953. Tools.each(Tools.grep(marker.childNodes), function(node2) {
  9954. if (isText$7(node2)) {
  9955. node2.nodeValue = node2.nodeValue.replace(/\uFEFF/g, "");
  9956. }
  9957. });
  9958. while (marker = dom2.get(bookmark.id + "_" + suffix)) {
  9959. dom2.remove(marker, true);
  9960. }
  9961. if (prev && next && prev.nodeType === next.nodeType && isText$7(prev) && !Env.opera) {
  9962. idx = prev.nodeValue.length;
  9963. prev.appendData(next.nodeValue);
  9964. dom2.remove(next);
  9965. container = prev;
  9966. offset = idx;
  9967. }
  9968. }
  9969. return Optional.some(CaretPosition(container, offset));
  9970. } else {
  9971. return Optional.none();
  9972. }
  9973. };
  9974. var resolvePaths = function(dom2, bookmark) {
  9975. var rng = dom2.createRng();
  9976. if (setEndPoint(dom2, true, bookmark, rng) && setEndPoint(dom2, false, bookmark, rng)) {
  9977. return Optional.some(rng);
  9978. } else {
  9979. return Optional.none();
  9980. }
  9981. };
  9982. var resolveId = function(dom2, bookmark) {
  9983. var startPos = restoreEndPoint(dom2, "start", bookmark);
  9984. var endPos = restoreEndPoint(dom2, "end", bookmark);
  9985. return lift2(startPos, endPos.or(startPos), function(spos, epos) {
  9986. var rng = dom2.createRng();
  9987. rng.setStart(addBogus(dom2, spos.container()), spos.offset());
  9988. rng.setEnd(addBogus(dom2, epos.container()), epos.offset());
  9989. return rng;
  9990. });
  9991. };
  9992. var resolveIndex = function(dom2, bookmark) {
  9993. return Optional.from(dom2.select(bookmark.name)[bookmark.index]).map(function(elm) {
  9994. var rng = dom2.createRng();
  9995. rng.selectNode(elm);
  9996. return rng;
  9997. });
  9998. };
  9999. var resolve$1 = function(selection, bookmark) {
  10000. var dom2 = selection.dom;
  10001. if (bookmark) {
  10002. if (isPathBookmark(bookmark)) {
  10003. return resolvePaths(dom2, bookmark);
  10004. } else if (isStringPathBookmark(bookmark)) {
  10005. return Optional.some(resolveCaretPositionBookmark(dom2, bookmark));
  10006. } else if (isIdBookmark(bookmark)) {
  10007. return resolveId(dom2, bookmark);
  10008. } else if (isIndexBookmark(bookmark)) {
  10009. return resolveIndex(dom2, bookmark);
  10010. } else if (isRangeBookmark(bookmark)) {
  10011. return Optional.some(bookmark.rng);
  10012. }
  10013. }
  10014. return Optional.none();
  10015. };
  10016. var getBookmark$1 = function(selection, type2, normalized) {
  10017. return getBookmark$2(selection, type2, normalized);
  10018. };
  10019. var moveToBookmark = function(selection, bookmark) {
  10020. resolve$1(selection, bookmark).each(function(rng) {
  10021. selection.setRng(rng);
  10022. });
  10023. };
  10024. var isBookmarkNode$1 = function(node) {
  10025. return isElement$5(node) && node.tagName === "SPAN" && node.getAttribute("data-mce-type") === "bookmark";
  10026. };
  10027. var is = function(expected) {
  10028. return function(actual) {
  10029. return expected === actual;
  10030. };
  10031. };
  10032. var isNbsp = is(nbsp);
  10033. var isWhiteSpace = function(chr) {
  10034. return chr !== "" && " \f\n\r \v".indexOf(chr) !== -1;
  10035. };
  10036. var isContent = function(chr) {
  10037. return !isWhiteSpace(chr) && !isNbsp(chr);
  10038. };
  10039. var isNode = function(node) {
  10040. return !!node.nodeType;
  10041. };
  10042. var isInlineBlock = function(node) {
  10043. return node && /^(IMG)$/.test(node.nodeName);
  10044. };
  10045. var moveStart = function(dom2, selection, rng) {
  10046. var offset = rng.startOffset;
  10047. var container = rng.startContainer;
  10048. if (container === rng.endContainer) {
  10049. if (isInlineBlock(container.childNodes[offset])) {
  10050. return;
  10051. }
  10052. }
  10053. if (isElement$5(container)) {
  10054. var nodes = container.childNodes;
  10055. var walker = void 0;
  10056. if (offset < nodes.length) {
  10057. container = nodes[offset];
  10058. walker = new DomTreeWalker(container, dom2.getParent(container, dom2.isBlock));
  10059. } else {
  10060. container = nodes[nodes.length - 1];
  10061. walker = new DomTreeWalker(container, dom2.getParent(container, dom2.isBlock));
  10062. walker.next(true);
  10063. }
  10064. for (var node = walker.current(); node; node = walker.next()) {
  10065. if (isText$7(node) && !isWhiteSpaceNode$1(node)) {
  10066. rng.setStart(node, 0);
  10067. selection.setRng(rng);
  10068. return;
  10069. }
  10070. }
  10071. }
  10072. };
  10073. var getNonWhiteSpaceSibling = function(node, next, inc) {
  10074. if (node) {
  10075. var nextName = next ? "nextSibling" : "previousSibling";
  10076. for (node = inc ? node : node[nextName]; node; node = node[nextName]) {
  10077. if (isElement$5(node) || !isWhiteSpaceNode$1(node)) {
  10078. return node;
  10079. }
  10080. }
  10081. }
  10082. };
  10083. var isTextBlock$1 = function(editor, name2) {
  10084. if (isNode(name2)) {
  10085. name2 = name2.nodeName;
  10086. }
  10087. return !!editor.schema.getTextBlockElements()[name2.toLowerCase()];
  10088. };
  10089. var isValid = function(ed, parent2, child2) {
  10090. return ed.schema.isValidChild(parent2, child2);
  10091. };
  10092. var isWhiteSpaceNode$1 = function(node, allowSpaces) {
  10093. if (allowSpaces === void 0) {
  10094. allowSpaces = false;
  10095. }
  10096. if (isNonNullable(node) && isText$7(node)) {
  10097. var data2 = allowSpaces ? node.data.replace(/ /g, "\xA0") : node.data;
  10098. return isWhitespaceText(data2);
  10099. } else {
  10100. return false;
  10101. }
  10102. };
  10103. var isEmptyTextNode$1 = function(node) {
  10104. return isNonNullable(node) && isText$7(node) && node.length === 0;
  10105. };
  10106. var replaceVars = function(value2, vars) {
  10107. if (isFunction(value2)) {
  10108. value2 = value2(vars);
  10109. } else if (isNonNullable(vars)) {
  10110. value2 = value2.replace(/%(\w+)/g, function(str, name2) {
  10111. return vars[name2] || str;
  10112. });
  10113. }
  10114. return value2;
  10115. };
  10116. var isEq$5 = function(str1, str2) {
  10117. str1 = str1 || "";
  10118. str2 = str2 || "";
  10119. str1 = "" + (str1.nodeName || str1);
  10120. str2 = "" + (str2.nodeName || str2);
  10121. return str1.toLowerCase() === str2.toLowerCase();
  10122. };
  10123. var normalizeStyleValue = function(dom2, value2, name2) {
  10124. if (name2 === "color" || name2 === "backgroundColor") {
  10125. value2 = dom2.toHex(value2);
  10126. }
  10127. if (name2 === "fontWeight" && value2 === 700) {
  10128. value2 = "bold";
  10129. }
  10130. if (name2 === "fontFamily") {
  10131. value2 = value2.replace(/[\'\"]/g, "").replace(/,\s+/g, ",");
  10132. }
  10133. return "" + value2;
  10134. };
  10135. var getStyle = function(dom2, node, name2) {
  10136. return normalizeStyleValue(dom2, dom2.getStyle(node, name2), name2);
  10137. };
  10138. var getTextDecoration = function(dom2, node) {
  10139. var decoration;
  10140. dom2.getParent(node, function(n) {
  10141. decoration = dom2.getStyle(n, "text-decoration");
  10142. return decoration && decoration !== "none";
  10143. });
  10144. return decoration;
  10145. };
  10146. var getParents$2 = function(dom2, node, selector) {
  10147. return dom2.getParents(node, selector, dom2.getRoot());
  10148. };
  10149. var isVariableFormatName = function(editor, formatName) {
  10150. var hasVariableValues = function(format) {
  10151. var isVariableValue = function(val) {
  10152. return val.length > 1 && val.charAt(0) === "%";
  10153. };
  10154. return exists([
  10155. "styles",
  10156. "attributes"
  10157. ], function(key) {
  10158. return get$9(format, key).exists(function(field) {
  10159. var fieldValues = isArray$1(field) ? field : values(field);
  10160. return exists(fieldValues, isVariableValue);
  10161. });
  10162. });
  10163. };
  10164. return exists(editor.formatter.get(formatName), hasVariableValues);
  10165. };
  10166. var areSimilarFormats = function(editor, formatName, otherFormatName) {
  10167. var validKeys = [
  10168. "inline",
  10169. "block",
  10170. "selector",
  10171. "attributes",
  10172. "styles",
  10173. "classes"
  10174. ];
  10175. var filterObj = function(format) {
  10176. return filter$3(format, function(_, key) {
  10177. return exists(validKeys, function(validKey) {
  10178. return validKey === key;
  10179. });
  10180. });
  10181. };
  10182. return exists(editor.formatter.get(formatName), function(fmt1) {
  10183. var filteredFmt1 = filterObj(fmt1);
  10184. return exists(editor.formatter.get(otherFormatName), function(fmt2) {
  10185. var filteredFmt2 = filterObj(fmt2);
  10186. return equal$1(filteredFmt1, filteredFmt2);
  10187. });
  10188. });
  10189. };
  10190. var isBlockFormat = function(format) {
  10191. return hasNonNullableKey(format, "block");
  10192. };
  10193. var isSelectorFormat = function(format) {
  10194. return hasNonNullableKey(format, "selector");
  10195. };
  10196. var isInlineFormat = function(format) {
  10197. return hasNonNullableKey(format, "inline");
  10198. };
  10199. var isMixedFormat = function(format) {
  10200. return isSelectorFormat(format) && isInlineFormat(format) && is$1(get$9(format, "mixed"), true);
  10201. };
  10202. var shouldExpandToSelector = function(format) {
  10203. return isSelectorFormat(format) && format.expand !== false && !isInlineFormat(format);
  10204. };
  10205. var isBookmarkNode = isBookmarkNode$1;
  10206. var getParents$1 = getParents$2;
  10207. var isWhiteSpaceNode = isWhiteSpaceNode$1;
  10208. var isTextBlock = isTextBlock$1;
  10209. var isBogusBr = function(node) {
  10210. return isBr$5(node) && node.getAttribute("data-mce-bogus") && !node.nextSibling;
  10211. };
  10212. var findParentContentEditable = function(dom2, node) {
  10213. var parent2 = node;
  10214. while (parent2) {
  10215. if (isElement$5(parent2) && dom2.getContentEditable(parent2)) {
  10216. return dom2.getContentEditable(parent2) === "false" ? parent2 : node;
  10217. }
  10218. parent2 = parent2.parentNode;
  10219. }
  10220. return node;
  10221. };
  10222. var walkText = function(start2, node, offset, predicate) {
  10223. var str = node.data;
  10224. for (var i = offset; start2 ? i >= 0 : i < str.length; start2 ? i-- : i++) {
  10225. if (predicate(str.charAt(i))) {
  10226. return start2 ? i + 1 : i;
  10227. }
  10228. }
  10229. return -1;
  10230. };
  10231. var findSpace = function(start2, node, offset) {
  10232. return walkText(start2, node, offset, function(c) {
  10233. return isNbsp(c) || isWhiteSpace(c);
  10234. });
  10235. };
  10236. var findContent = function(start2, node, offset) {
  10237. return walkText(start2, node, offset, isContent);
  10238. };
  10239. var findWordEndPoint = function(dom2, body, container, offset, start2, includeTrailingSpaces) {
  10240. var lastTextNode;
  10241. var rootNode = dom2.getParent(container, dom2.isBlock) || body;
  10242. var walk2 = function(container2, offset2, pred) {
  10243. var textSeeker = TextSeeker(dom2);
  10244. var walker = start2 ? textSeeker.backwards : textSeeker.forwards;
  10245. return Optional.from(walker(container2, offset2, function(text, textOffset) {
  10246. if (isBookmarkNode(text.parentNode)) {
  10247. return -1;
  10248. } else {
  10249. lastTextNode = text;
  10250. return pred(start2, text, textOffset);
  10251. }
  10252. }, rootNode));
  10253. };
  10254. var spaceResult = walk2(container, offset, findSpace);
  10255. return spaceResult.bind(function(result) {
  10256. return includeTrailingSpaces ? walk2(result.container, result.offset + (start2 ? -1 : 0), findContent) : Optional.some(result);
  10257. }).orThunk(function() {
  10258. return lastTextNode ? Optional.some({
  10259. container: lastTextNode,
  10260. offset: start2 ? 0 : lastTextNode.length
  10261. }) : Optional.none();
  10262. });
  10263. };
  10264. var findSelectorEndPoint = function(dom2, formatList, rng, container, siblingName) {
  10265. if (isText$7(container) && isEmpty$3(container.data) && container[siblingName]) {
  10266. container = container[siblingName];
  10267. }
  10268. var parents2 = getParents$1(dom2, container);
  10269. for (var i = 0; i < parents2.length; i++) {
  10270. for (var y = 0; y < formatList.length; y++) {
  10271. var curFormat = formatList[y];
  10272. if (isNonNullable(curFormat.collapsed) && curFormat.collapsed !== rng.collapsed) {
  10273. continue;
  10274. }
  10275. if (isSelectorFormat(curFormat) && dom2.is(parents2[i], curFormat.selector)) {
  10276. return parents2[i];
  10277. }
  10278. }
  10279. }
  10280. return container;
  10281. };
  10282. var findBlockEndPoint = function(editor, formatList, container, siblingName) {
  10283. var node = container;
  10284. var dom2 = editor.dom;
  10285. var root = dom2.getRoot();
  10286. var format = formatList[0];
  10287. if (isBlockFormat(format)) {
  10288. node = format.wrapper ? null : dom2.getParent(container, format.block, root);
  10289. }
  10290. if (!node) {
  10291. var scopeRoot = dom2.getParent(container, "LI,TD,TH");
  10292. node = dom2.getParent(isText$7(container) ? container.parentNode : container, function(node2) {
  10293. return node2 !== root && isTextBlock(editor, node2);
  10294. }, scopeRoot);
  10295. }
  10296. if (node && isBlockFormat(format) && format.wrapper) {
  10297. node = getParents$1(dom2, node, "ul,ol").reverse()[0] || node;
  10298. }
  10299. if (!node) {
  10300. node = container;
  10301. while (node[siblingName] && !dom2.isBlock(node[siblingName])) {
  10302. node = node[siblingName];
  10303. if (isEq$5(node, "br")) {
  10304. break;
  10305. }
  10306. }
  10307. }
  10308. return node || container;
  10309. };
  10310. var isAtBlockBoundary$1 = function(dom2, root, container, siblingName) {
  10311. var parent2 = container.parentNode;
  10312. if (isNonNullable(container[siblingName])) {
  10313. return false;
  10314. } else if (parent2 === root || isNullable(parent2) || dom2.isBlock(parent2)) {
  10315. return true;
  10316. } else {
  10317. return isAtBlockBoundary$1(dom2, root, parent2, siblingName);
  10318. }
  10319. };
  10320. var findParentContainer = function(dom2, formatList, container, offset, start2) {
  10321. var parent2 = container;
  10322. var siblingName = start2 ? "previousSibling" : "nextSibling";
  10323. var root = dom2.getRoot();
  10324. if (isText$7(container) && !isWhiteSpaceNode(container)) {
  10325. if (start2 ? offset > 0 : offset < container.data.length) {
  10326. return container;
  10327. }
  10328. }
  10329. while (true) {
  10330. if (!formatList[0].block_expand && dom2.isBlock(parent2)) {
  10331. return parent2;
  10332. }
  10333. for (var sibling2 = parent2[siblingName]; sibling2; sibling2 = sibling2[siblingName]) {
  10334. var allowSpaces = isText$7(sibling2) && !isAtBlockBoundary$1(dom2, root, sibling2, siblingName);
  10335. if (!isBookmarkNode(sibling2) && !isBogusBr(sibling2) && !isWhiteSpaceNode(sibling2, allowSpaces)) {
  10336. return parent2;
  10337. }
  10338. }
  10339. if (parent2 === root || parent2.parentNode === root) {
  10340. container = parent2;
  10341. break;
  10342. }
  10343. parent2 = parent2.parentNode;
  10344. }
  10345. return container;
  10346. };
  10347. var isSelfOrParentBookmark = function(container) {
  10348. return isBookmarkNode(container.parentNode) || isBookmarkNode(container);
  10349. };
  10350. var expandRng = function(editor, rng, formatList, includeTrailingSpace) {
  10351. if (includeTrailingSpace === void 0) {
  10352. includeTrailingSpace = false;
  10353. }
  10354. var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
  10355. var dom2 = editor.dom;
  10356. var format = formatList[0];
  10357. if (isElement$5(startContainer) && startContainer.hasChildNodes()) {
  10358. startContainer = getNode$1(startContainer, startOffset);
  10359. if (isText$7(startContainer)) {
  10360. startOffset = 0;
  10361. }
  10362. }
  10363. if (isElement$5(endContainer) && endContainer.hasChildNodes()) {
  10364. endContainer = getNode$1(endContainer, rng.collapsed ? endOffset : endOffset - 1);
  10365. if (isText$7(endContainer)) {
  10366. endOffset = endContainer.nodeValue.length;
  10367. }
  10368. }
  10369. startContainer = findParentContentEditable(dom2, startContainer);
  10370. endContainer = findParentContentEditable(dom2, endContainer);
  10371. if (isSelfOrParentBookmark(startContainer)) {
  10372. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  10373. if (rng.collapsed) {
  10374. startContainer = startContainer.previousSibling || startContainer;
  10375. } else {
  10376. startContainer = startContainer.nextSibling || startContainer;
  10377. }
  10378. if (isText$7(startContainer)) {
  10379. startOffset = rng.collapsed ? startContainer.length : 0;
  10380. }
  10381. }
  10382. if (isSelfOrParentBookmark(endContainer)) {
  10383. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  10384. if (rng.collapsed) {
  10385. endContainer = endContainer.nextSibling || endContainer;
  10386. } else {
  10387. endContainer = endContainer.previousSibling || endContainer;
  10388. }
  10389. if (isText$7(endContainer)) {
  10390. endOffset = rng.collapsed ? 0 : endContainer.length;
  10391. }
  10392. }
  10393. if (rng.collapsed) {
  10394. var startPoint = findWordEndPoint(dom2, editor.getBody(), startContainer, startOffset, true, includeTrailingSpace);
  10395. startPoint.each(function(_a) {
  10396. var container = _a.container, offset = _a.offset;
  10397. startContainer = container;
  10398. startOffset = offset;
  10399. });
  10400. var endPoint = findWordEndPoint(dom2, editor.getBody(), endContainer, endOffset, false, includeTrailingSpace);
  10401. endPoint.each(function(_a) {
  10402. var container = _a.container, offset = _a.offset;
  10403. endContainer = container;
  10404. endOffset = offset;
  10405. });
  10406. }
  10407. if (isInlineFormat(format) || format.block_expand) {
  10408. if (!isInlineFormat(format) || (!isText$7(startContainer) || startOffset === 0)) {
  10409. startContainer = findParentContainer(dom2, formatList, startContainer, startOffset, true);
  10410. }
  10411. if (!isInlineFormat(format) || (!isText$7(endContainer) || endOffset === endContainer.nodeValue.length)) {
  10412. endContainer = findParentContainer(dom2, formatList, endContainer, endOffset, false);
  10413. }
  10414. }
  10415. if (shouldExpandToSelector(format)) {
  10416. startContainer = findSelectorEndPoint(dom2, formatList, rng, startContainer, "previousSibling");
  10417. endContainer = findSelectorEndPoint(dom2, formatList, rng, endContainer, "nextSibling");
  10418. }
  10419. if (isBlockFormat(format) || isSelectorFormat(format)) {
  10420. startContainer = findBlockEndPoint(editor, formatList, startContainer, "previousSibling");
  10421. endContainer = findBlockEndPoint(editor, formatList, endContainer, "nextSibling");
  10422. if (isBlockFormat(format)) {
  10423. if (!dom2.isBlock(startContainer)) {
  10424. startContainer = findParentContainer(dom2, formatList, startContainer, startOffset, true);
  10425. }
  10426. if (!dom2.isBlock(endContainer)) {
  10427. endContainer = findParentContainer(dom2, formatList, endContainer, endOffset, false);
  10428. }
  10429. }
  10430. }
  10431. if (isElement$5(startContainer)) {
  10432. startOffset = dom2.nodeIndex(startContainer);
  10433. startContainer = startContainer.parentNode;
  10434. }
  10435. if (isElement$5(endContainer)) {
  10436. endOffset = dom2.nodeIndex(endContainer) + 1;
  10437. endContainer = endContainer.parentNode;
  10438. }
  10439. return {
  10440. startContainer,
  10441. startOffset,
  10442. endContainer,
  10443. endOffset
  10444. };
  10445. };
  10446. var walk$2 = function(dom2, rng, callback) {
  10447. var startOffset = rng.startOffset;
  10448. var startContainer = getNode$1(rng.startContainer, startOffset);
  10449. var endOffset = rng.endOffset;
  10450. var endContainer = getNode$1(rng.endContainer, endOffset - 1);
  10451. var exclude = function(nodes) {
  10452. var firstNode = nodes[0];
  10453. if (isText$7(firstNode) && firstNode === startContainer && startOffset >= firstNode.data.length) {
  10454. nodes.splice(0, 1);
  10455. }
  10456. var lastNode = nodes[nodes.length - 1];
  10457. if (endOffset === 0 && nodes.length > 0 && lastNode === endContainer && isText$7(lastNode)) {
  10458. nodes.splice(nodes.length - 1, 1);
  10459. }
  10460. return nodes;
  10461. };
  10462. var collectSiblings = function(node, name2, endNode) {
  10463. var siblings3 = [];
  10464. for (; node && node !== endNode; node = node[name2]) {
  10465. siblings3.push(node);
  10466. }
  10467. return siblings3;
  10468. };
  10469. var findEndPoint = function(node, root) {
  10470. return dom2.getParent(node, function(node2) {
  10471. return node2.parentNode === root;
  10472. }, root);
  10473. };
  10474. var walkBoundary = function(startNode, endNode, next) {
  10475. var siblingName = next ? "nextSibling" : "previousSibling";
  10476. for (var node = startNode, parent_1 = node.parentNode; node && node !== endNode; node = parent_1) {
  10477. parent_1 = node.parentNode;
  10478. var siblings_1 = collectSiblings(node === startNode ? node : node[siblingName], siblingName);
  10479. if (siblings_1.length) {
  10480. if (!next) {
  10481. siblings_1.reverse();
  10482. }
  10483. callback(exclude(siblings_1));
  10484. }
  10485. }
  10486. };
  10487. if (startContainer === endContainer) {
  10488. return callback(exclude([startContainer]));
  10489. }
  10490. var ancestor2 = dom2.findCommonAncestor(startContainer, endContainer);
  10491. if (dom2.isChildOf(startContainer, endContainer)) {
  10492. return walkBoundary(startContainer, ancestor2, true);
  10493. }
  10494. if (dom2.isChildOf(endContainer, startContainer)) {
  10495. return walkBoundary(endContainer, ancestor2);
  10496. }
  10497. var startPoint = findEndPoint(startContainer, ancestor2) || startContainer;
  10498. var endPoint = findEndPoint(endContainer, ancestor2) || endContainer;
  10499. walkBoundary(startContainer, startPoint, true);
  10500. var siblings2 = collectSiblings(startPoint === startContainer ? startPoint : startPoint.nextSibling, "nextSibling", endPoint === endContainer ? endPoint.nextSibling : endPoint);
  10501. if (siblings2.length) {
  10502. callback(exclude(siblings2));
  10503. }
  10504. walkBoundary(endContainer, endPoint);
  10505. };
  10506. var getRanges = function(selection) {
  10507. var ranges = [];
  10508. if (selection) {
  10509. for (var i = 0; i < selection.rangeCount; i++) {
  10510. ranges.push(selection.getRangeAt(i));
  10511. }
  10512. }
  10513. return ranges;
  10514. };
  10515. var getSelectedNodes = function(ranges) {
  10516. return bind(ranges, function(range2) {
  10517. var node = getSelectedNode(range2);
  10518. return node ? [SugarElement.fromDom(node)] : [];
  10519. });
  10520. };
  10521. var hasMultipleRanges = function(selection) {
  10522. return getRanges(selection).length > 1;
  10523. };
  10524. var getCellsFromRanges = function(ranges) {
  10525. return filter$4(getSelectedNodes(ranges), isTableCell$4);
  10526. };
  10527. var getCellsFromElement = function(elm) {
  10528. return descendants(elm, "td[data-mce-selected],th[data-mce-selected]");
  10529. };
  10530. var getCellsFromElementOrRanges = function(ranges, element) {
  10531. var selectedCells = getCellsFromElement(element);
  10532. return selectedCells.length > 0 ? selectedCells : getCellsFromRanges(ranges);
  10533. };
  10534. var getCellsFromEditor = function(editor) {
  10535. return getCellsFromElementOrRanges(getRanges(editor.selection.getSel()), SugarElement.fromDom(editor.getBody()));
  10536. };
  10537. var getClosestTable = function(cell, isRoot) {
  10538. return ancestor$2(cell, "table", isRoot);
  10539. };
  10540. var getStartNode = function(rng) {
  10541. var sc = rng.startContainer, so = rng.startOffset;
  10542. if (isText$7(sc)) {
  10543. return so === 0 ? Optional.some(SugarElement.fromDom(sc)) : Optional.none();
  10544. } else {
  10545. return Optional.from(sc.childNodes[so]).map(SugarElement.fromDom);
  10546. }
  10547. };
  10548. var getEndNode = function(rng) {
  10549. var ec = rng.endContainer, eo = rng.endOffset;
  10550. if (isText$7(ec)) {
  10551. return eo === ec.data.length ? Optional.some(SugarElement.fromDom(ec)) : Optional.none();
  10552. } else {
  10553. return Optional.from(ec.childNodes[eo - 1]).map(SugarElement.fromDom);
  10554. }
  10555. };
  10556. var getFirstChildren = function(node) {
  10557. return firstChild(node).fold(constant([node]), function(child2) {
  10558. return [node].concat(getFirstChildren(child2));
  10559. });
  10560. };
  10561. var getLastChildren$1 = function(node) {
  10562. return lastChild(node).fold(constant([node]), function(child2) {
  10563. if (name(child2) === "br") {
  10564. return prevSibling(child2).map(function(sibling2) {
  10565. return [node].concat(getLastChildren$1(sibling2));
  10566. }).getOr([]);
  10567. } else {
  10568. return [node].concat(getLastChildren$1(child2));
  10569. }
  10570. });
  10571. };
  10572. var hasAllContentsSelected = function(elm, rng) {
  10573. return lift2(getStartNode(rng), getEndNode(rng), function(startNode, endNode) {
  10574. var start2 = find$3(getFirstChildren(elm), curry(eq, startNode));
  10575. var end2 = find$3(getLastChildren$1(elm), curry(eq, endNode));
  10576. return start2.isSome() && end2.isSome();
  10577. }).getOr(false);
  10578. };
  10579. var moveEndPoint = function(dom2, rng, node, start2) {
  10580. var root = node, walker = new DomTreeWalker(node, root);
  10581. var moveCaretBeforeOnEnterElementsMap = filter$3(dom2.schema.getMoveCaretBeforeOnEnterElements(), function(_, name2) {
  10582. return !contains$3([
  10583. "td",
  10584. "th",
  10585. "table"
  10586. ], name2.toLowerCase());
  10587. });
  10588. do {
  10589. if (isText$7(node) && Tools.trim(node.nodeValue).length !== 0) {
  10590. if (start2) {
  10591. rng.setStart(node, 0);
  10592. } else {
  10593. rng.setEnd(node, node.nodeValue.length);
  10594. }
  10595. return;
  10596. }
  10597. if (moveCaretBeforeOnEnterElementsMap[node.nodeName]) {
  10598. if (start2) {
  10599. rng.setStartBefore(node);
  10600. } else {
  10601. if (node.nodeName === "BR") {
  10602. rng.setEndBefore(node);
  10603. } else {
  10604. rng.setEndAfter(node);
  10605. }
  10606. }
  10607. return;
  10608. }
  10609. } while (node = start2 ? walker.next() : walker.prev());
  10610. if (root.nodeName === "BODY") {
  10611. if (start2) {
  10612. rng.setStart(root, 0);
  10613. } else {
  10614. rng.setEnd(root, root.childNodes.length);
  10615. }
  10616. }
  10617. };
  10618. var hasAnyRanges = function(editor) {
  10619. var sel = editor.selection.getSel();
  10620. return sel && sel.rangeCount > 0;
  10621. };
  10622. var runOnRanges = function(editor, executor) {
  10623. var fakeSelectionNodes = getCellsFromEditor(editor);
  10624. if (fakeSelectionNodes.length > 0) {
  10625. each$k(fakeSelectionNodes, function(elem) {
  10626. var node = elem.dom;
  10627. var fakeNodeRng = editor.dom.createRng();
  10628. fakeNodeRng.setStartBefore(node);
  10629. fakeNodeRng.setEndAfter(node);
  10630. executor(fakeNodeRng, true);
  10631. });
  10632. } else {
  10633. executor(editor.selection.getRng(), false);
  10634. }
  10635. };
  10636. var preserve = function(selection, fillBookmark, executor) {
  10637. var bookmark = getPersistentBookmark(selection, fillBookmark);
  10638. executor(bookmark);
  10639. selection.moveToBookmark(bookmark);
  10640. };
  10641. var NodeValue = function(is2, name2) {
  10642. var get2 = function(element) {
  10643. if (!is2(element)) {
  10644. throw new Error("Can only get " + name2 + " value of a " + name2 + " node");
  10645. }
  10646. return getOption(element).getOr("");
  10647. };
  10648. var getOption = function(element) {
  10649. return is2(element) ? Optional.from(element.dom.nodeValue) : Optional.none();
  10650. };
  10651. var set2 = function(element, value2) {
  10652. if (!is2(element)) {
  10653. throw new Error("Can only set raw " + name2 + " value of a " + name2 + " node");
  10654. }
  10655. element.dom.nodeValue = value2;
  10656. };
  10657. return {
  10658. get: get2,
  10659. getOption,
  10660. set: set2
  10661. };
  10662. };
  10663. var api$1 = NodeValue(isText$8, "text");
  10664. var get$2 = function(element) {
  10665. return api$1.get(element);
  10666. };
  10667. var isZeroWidth = function(elem) {
  10668. return isText$8(elem) && get$2(elem) === ZWSP$1;
  10669. };
  10670. var context = function(editor, elem, wrapName, nodeName) {
  10671. return parent(elem).fold(function() {
  10672. return "skipping";
  10673. }, function(parent2) {
  10674. if (nodeName === "br" || isZeroWidth(elem)) {
  10675. return "valid";
  10676. } else if (isAnnotation(elem)) {
  10677. return "existing";
  10678. } else if (isCaretNode(elem.dom)) {
  10679. return "caret";
  10680. } else if (!isValid(editor, wrapName, nodeName) || !isValid(editor, name(parent2), wrapName)) {
  10681. return "invalid-child";
  10682. } else {
  10683. return "valid";
  10684. }
  10685. });
  10686. };
  10687. var applyWordGrab = function(editor, rng) {
  10688. var r2 = expandRng(editor, rng, [{ inline: "span" }]);
  10689. rng.setStart(r2.startContainer, r2.startOffset);
  10690. rng.setEnd(r2.endContainer, r2.endOffset);
  10691. editor.selection.setRng(rng);
  10692. };
  10693. var makeAnnotation = function(eDoc, _a, annotationName, decorate) {
  10694. var _b = _a.uid, uid = _b === void 0 ? generate("mce-annotation") : _b, data2 = __rest(_a, ["uid"]);
  10695. var master = SugarElement.fromTag("span", eDoc);
  10696. add$1(master, annotation());
  10697. set$1(master, "" + dataAnnotationId(), uid);
  10698. set$1(master, "" + dataAnnotation(), annotationName);
  10699. var _c = decorate(uid, data2), _d = _c.attributes, attributes2 = _d === void 0 ? {} : _d, _e = _c.classes, classes = _e === void 0 ? [] : _e;
  10700. setAll$1(master, attributes2);
  10701. add(master, classes);
  10702. return master;
  10703. };
  10704. var annotate = function(editor, rng, annotationName, decorate, data2) {
  10705. var newWrappers = [];
  10706. var master = makeAnnotation(editor.getDoc(), data2, annotationName, decorate);
  10707. var wrapper = value();
  10708. var finishWrapper = function() {
  10709. wrapper.clear();
  10710. };
  10711. var getOrOpenWrapper = function() {
  10712. return wrapper.get().getOrThunk(function() {
  10713. var nu2 = shallow(master);
  10714. newWrappers.push(nu2);
  10715. wrapper.set(nu2);
  10716. return nu2;
  10717. });
  10718. };
  10719. var processElements = function(elems) {
  10720. each$k(elems, processElement);
  10721. };
  10722. var processElement = function(elem) {
  10723. var ctx = context(editor, elem, "span", name(elem));
  10724. switch (ctx) {
  10725. case "invalid-child": {
  10726. finishWrapper();
  10727. var children$1 = children(elem);
  10728. processElements(children$1);
  10729. finishWrapper();
  10730. break;
  10731. }
  10732. case "valid": {
  10733. var w = getOrOpenWrapper();
  10734. wrap$3(elem, w);
  10735. break;
  10736. }
  10737. }
  10738. };
  10739. var processNodes = function(nodes) {
  10740. var elems = map$3(nodes, SugarElement.fromDom);
  10741. processElements(elems);
  10742. };
  10743. walk$2(editor.dom, rng, function(nodes) {
  10744. finishWrapper();
  10745. processNodes(nodes);
  10746. });
  10747. return newWrappers;
  10748. };
  10749. var annotateWithBookmark = function(editor, name2, settings, data2) {
  10750. editor.undoManager.transact(function() {
  10751. var selection = editor.selection;
  10752. var initialRng = selection.getRng();
  10753. var hasFakeSelection = getCellsFromEditor(editor).length > 0;
  10754. if (initialRng.collapsed && !hasFakeSelection) {
  10755. applyWordGrab(editor, initialRng);
  10756. }
  10757. if (selection.getRng().collapsed && !hasFakeSelection) {
  10758. var wrapper = makeAnnotation(editor.getDoc(), data2, name2, settings.decorate);
  10759. set(wrapper, nbsp);
  10760. selection.getRng().insertNode(wrapper.dom);
  10761. selection.select(wrapper.dom);
  10762. } else {
  10763. preserve(selection, false, function() {
  10764. runOnRanges(editor, function(selectionRng) {
  10765. annotate(editor, selectionRng, name2, settings.decorate, data2);
  10766. });
  10767. });
  10768. }
  10769. });
  10770. };
  10771. var Annotator = function(editor) {
  10772. var registry2 = create$7();
  10773. setup$m(editor, registry2);
  10774. var changes = setup$n(editor);
  10775. return {
  10776. register: function(name2, settings) {
  10777. registry2.register(name2, settings);
  10778. },
  10779. annotate: function(name2, data2) {
  10780. registry2.lookup(name2).each(function(settings) {
  10781. annotateWithBookmark(editor, name2, settings, data2);
  10782. });
  10783. },
  10784. annotationChanged: function(name2, callback) {
  10785. changes.addListener(name2, callback);
  10786. },
  10787. remove: function(name2) {
  10788. identify(editor, Optional.some(name2)).each(function(_a) {
  10789. var elements = _a.elements;
  10790. each$k(elements, unwrap);
  10791. });
  10792. },
  10793. getAll: function(name2) {
  10794. var directory = findAll(editor, name2);
  10795. return map$2(directory, function(elems) {
  10796. return map$3(elems, function(elem) {
  10797. return elem.dom;
  10798. });
  10799. });
  10800. }
  10801. };
  10802. };
  10803. var BookmarkManager = function(selection) {
  10804. return {
  10805. getBookmark: curry(getBookmark$1, selection),
  10806. moveToBookmark: curry(moveToBookmark, selection)
  10807. };
  10808. };
  10809. BookmarkManager.isBookmarkNode = isBookmarkNode$1;
  10810. var getContentEditableRoot$1 = function(root, node) {
  10811. while (node && node !== root) {
  10812. if (isContentEditableTrue$4(node) || isContentEditableFalse$b(node)) {
  10813. return node;
  10814. }
  10815. node = node.parentNode;
  10816. }
  10817. return null;
  10818. };
  10819. var isXYWithinRange = function(clientX, clientY, range2) {
  10820. if (range2.collapsed) {
  10821. return false;
  10822. }
  10823. if (Env.browser.isIE() && range2.startOffset === range2.endOffset - 1 && range2.startContainer === range2.endContainer) {
  10824. var elm = range2.startContainer.childNodes[range2.startOffset];
  10825. if (isElement$5(elm)) {
  10826. return exists(elm.getClientRects(), function(rect) {
  10827. return containsXY(rect, clientX, clientY);
  10828. });
  10829. }
  10830. }
  10831. return exists(range2.getClientRects(), function(rect) {
  10832. return containsXY(rect, clientX, clientY);
  10833. });
  10834. };
  10835. var firePreProcess = function(editor, args) {
  10836. return editor.fire("PreProcess", args);
  10837. };
  10838. var firePostProcess = function(editor, args) {
  10839. return editor.fire("PostProcess", args);
  10840. };
  10841. var fireRemove = function(editor) {
  10842. return editor.fire("remove");
  10843. };
  10844. var fireDetach = function(editor) {
  10845. return editor.fire("detach");
  10846. };
  10847. var fireSwitchMode = function(editor, mode) {
  10848. return editor.fire("SwitchMode", { mode });
  10849. };
  10850. var fireObjectResizeStart = function(editor, target, width, height, origin) {
  10851. editor.fire("ObjectResizeStart", {
  10852. target,
  10853. width,
  10854. height,
  10855. origin
  10856. });
  10857. };
  10858. var fireObjectResized = function(editor, target, width, height, origin) {
  10859. editor.fire("ObjectResized", {
  10860. target,
  10861. width,
  10862. height,
  10863. origin
  10864. });
  10865. };
  10866. var firePreInit = function(editor) {
  10867. return editor.fire("PreInit");
  10868. };
  10869. var firePostRender = function(editor) {
  10870. return editor.fire("PostRender");
  10871. };
  10872. var fireInit = function(editor) {
  10873. return editor.fire("Init");
  10874. };
  10875. var firePlaceholderToggle = function(editor, state) {
  10876. return editor.fire("PlaceholderToggle", { state });
  10877. };
  10878. var fireError = function(editor, errorType, error2) {
  10879. return editor.fire(errorType, error2);
  10880. };
  10881. var fireFormatApply = function(editor, format, node, vars) {
  10882. return editor.fire("FormatApply", {
  10883. format,
  10884. node,
  10885. vars
  10886. });
  10887. };
  10888. var fireFormatRemove = function(editor, format, node, vars) {
  10889. return editor.fire("FormatRemove", {
  10890. format,
  10891. node,
  10892. vars
  10893. });
  10894. };
  10895. var VK = {
  10896. BACKSPACE: 8,
  10897. DELETE: 46,
  10898. DOWN: 40,
  10899. ENTER: 13,
  10900. ESC: 27,
  10901. LEFT: 37,
  10902. RIGHT: 39,
  10903. SPACEBAR: 32,
  10904. TAB: 9,
  10905. UP: 38,
  10906. PAGE_UP: 33,
  10907. PAGE_DOWN: 34,
  10908. END: 35,
  10909. HOME: 36,
  10910. modifierPressed: function(e) {
  10911. return e.shiftKey || e.ctrlKey || e.altKey || VK.metaKeyPressed(e);
  10912. },
  10913. metaKeyPressed: function(e) {
  10914. return Env.mac ? e.metaKey : e.ctrlKey && !e.altKey;
  10915. }
  10916. };
  10917. var isContentEditableFalse$5 = isContentEditableFalse$b;
  10918. var ControlSelection = function(selection, editor) {
  10919. var elementSelectionAttr = "data-mce-selected";
  10920. var dom2 = editor.dom, each2 = Tools.each;
  10921. var selectedElm, selectedElmGhost, resizeHelper, selectedHandle, resizeBackdrop;
  10922. var startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted;
  10923. var width, height;
  10924. var editableDoc = editor.getDoc(), rootDocument = document;
  10925. var abs = Math.abs, round2 = Math.round, rootElement = editor.getBody();
  10926. var startScrollWidth, startScrollHeight;
  10927. var resizeHandles = {
  10928. nw: [
  10929. 0,
  10930. 0,
  10931. -1,
  10932. -1
  10933. ],
  10934. ne: [
  10935. 1,
  10936. 0,
  10937. 1,
  10938. -1
  10939. ],
  10940. se: [
  10941. 1,
  10942. 1,
  10943. 1,
  10944. 1
  10945. ],
  10946. sw: [
  10947. 0,
  10948. 1,
  10949. -1,
  10950. 1
  10951. ]
  10952. };
  10953. var isImage = function(elm) {
  10954. return elm && (elm.nodeName === "IMG" || editor.dom.is(elm, "figure.image"));
  10955. };
  10956. var isMedia2 = function(elm) {
  10957. return isMedia$2(elm) || dom2.hasClass(elm, "mce-preview-object");
  10958. };
  10959. var isEventOnImageOutsideRange = function(evt, range2) {
  10960. if (evt.type === "longpress" || evt.type.indexOf("touch") === 0) {
  10961. var touch = evt.touches[0];
  10962. return isImage(evt.target) && !isXYWithinRange(touch.clientX, touch.clientY, range2);
  10963. } else {
  10964. return isImage(evt.target) && !isXYWithinRange(evt.clientX, evt.clientY, range2);
  10965. }
  10966. };
  10967. var contextMenuSelectImage = function(evt) {
  10968. var target = evt.target;
  10969. if (isEventOnImageOutsideRange(evt, editor.selection.getRng()) && !evt.isDefaultPrevented()) {
  10970. editor.selection.select(target);
  10971. }
  10972. };
  10973. var getResizeTargets = function(elm) {
  10974. if (dom2.is(elm, "figure.image")) {
  10975. return [elm.querySelector("img")];
  10976. } else if (dom2.hasClass(elm, "mce-preview-object") && isNonNullable(elm.firstElementChild)) {
  10977. return [
  10978. elm,
  10979. elm.firstElementChild
  10980. ];
  10981. } else {
  10982. return [elm];
  10983. }
  10984. };
  10985. var isResizable = function(elm) {
  10986. var selector = getObjectResizing(editor);
  10987. if (!selector) {
  10988. return false;
  10989. }
  10990. if (elm.getAttribute("data-mce-resize") === "false") {
  10991. return false;
  10992. }
  10993. if (elm === editor.getBody()) {
  10994. return false;
  10995. }
  10996. if (dom2.hasClass(elm, "mce-preview-object")) {
  10997. return is$2(SugarElement.fromDom(elm.firstElementChild), selector);
  10998. } else {
  10999. return is$2(SugarElement.fromDom(elm), selector);
  11000. }
  11001. };
  11002. var createGhostElement = function(elm) {
  11003. if (isMedia2(elm)) {
  11004. return dom2.create("img", { src: Env.transparentSrc });
  11005. } else {
  11006. return elm.cloneNode(true);
  11007. }
  11008. };
  11009. var setSizeProp = function(element, name2, value2) {
  11010. if (isNonNullable(value2)) {
  11011. var targets = getResizeTargets(element);
  11012. each$k(targets, function(target) {
  11013. if (target.style[name2] || !editor.schema.isValid(target.nodeName.toLowerCase(), name2)) {
  11014. dom2.setStyle(target, name2, value2);
  11015. } else {
  11016. dom2.setAttrib(target, name2, "" + value2);
  11017. }
  11018. });
  11019. }
  11020. };
  11021. var setGhostElmSize = function(ghostElm, width2, height2) {
  11022. setSizeProp(ghostElm, "width", width2);
  11023. setSizeProp(ghostElm, "height", height2);
  11024. };
  11025. var resizeGhostElement = function(e) {
  11026. var deltaX, deltaY, proportional;
  11027. var resizeHelperX, resizeHelperY;
  11028. deltaX = e.screenX - startX;
  11029. deltaY = e.screenY - startY;
  11030. width = deltaX * selectedHandle[2] + startW;
  11031. height = deltaY * selectedHandle[3] + startH;
  11032. width = width < 5 ? 5 : width;
  11033. height = height < 5 ? 5 : height;
  11034. if ((isImage(selectedElm) || isMedia2(selectedElm)) && getResizeImgProportional(editor) !== false) {
  11035. proportional = !VK.modifierPressed(e);
  11036. } else {
  11037. proportional = VK.modifierPressed(e);
  11038. }
  11039. if (proportional) {
  11040. if (abs(deltaX) > abs(deltaY)) {
  11041. height = round2(width * ratio);
  11042. width = round2(height / ratio);
  11043. } else {
  11044. width = round2(height / ratio);
  11045. height = round2(width * ratio);
  11046. }
  11047. }
  11048. setGhostElmSize(selectedElmGhost, width, height);
  11049. resizeHelperX = selectedHandle.startPos.x + deltaX;
  11050. resizeHelperY = selectedHandle.startPos.y + deltaY;
  11051. resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0;
  11052. resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0;
  11053. dom2.setStyles(resizeHelper, {
  11054. left: resizeHelperX,
  11055. top: resizeHelperY,
  11056. display: "block"
  11057. });
  11058. resizeHelper.innerHTML = width + " &times; " + height;
  11059. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  11060. dom2.setStyle(selectedElmGhost, "left", selectedElmX + (startW - width));
  11061. }
  11062. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  11063. dom2.setStyle(selectedElmGhost, "top", selectedElmY + (startH - height));
  11064. }
  11065. deltaX = rootElement.scrollWidth - startScrollWidth;
  11066. deltaY = rootElement.scrollHeight - startScrollHeight;
  11067. if (deltaX + deltaY !== 0) {
  11068. dom2.setStyles(resizeHelper, {
  11069. left: resizeHelperX - deltaX,
  11070. top: resizeHelperY - deltaY
  11071. });
  11072. }
  11073. if (!resizeStarted) {
  11074. fireObjectResizeStart(editor, selectedElm, startW, startH, "corner-" + selectedHandle.name);
  11075. resizeStarted = true;
  11076. }
  11077. };
  11078. var endGhostResize = function() {
  11079. var wasResizeStarted = resizeStarted;
  11080. resizeStarted = false;
  11081. if (wasResizeStarted) {
  11082. setSizeProp(selectedElm, "width", width);
  11083. setSizeProp(selectedElm, "height", height);
  11084. }
  11085. dom2.unbind(editableDoc, "mousemove", resizeGhostElement);
  11086. dom2.unbind(editableDoc, "mouseup", endGhostResize);
  11087. if (rootDocument !== editableDoc) {
  11088. dom2.unbind(rootDocument, "mousemove", resizeGhostElement);
  11089. dom2.unbind(rootDocument, "mouseup", endGhostResize);
  11090. }
  11091. dom2.remove(selectedElmGhost);
  11092. dom2.remove(resizeHelper);
  11093. dom2.remove(resizeBackdrop);
  11094. showResizeRect(selectedElm);
  11095. if (wasResizeStarted) {
  11096. fireObjectResized(editor, selectedElm, width, height, "corner-" + selectedHandle.name);
  11097. dom2.setAttrib(selectedElm, "style", dom2.getAttrib(selectedElm, "style"));
  11098. }
  11099. editor.nodeChanged();
  11100. };
  11101. var showResizeRect = function(targetElm) {
  11102. unbindResizeHandleEvents();
  11103. var position = dom2.getPos(targetElm, rootElement);
  11104. var selectedElmX2 = position.x;
  11105. var selectedElmY2 = position.y;
  11106. var rect = targetElm.getBoundingClientRect();
  11107. var targetWidth = rect.width || rect.right - rect.left;
  11108. var targetHeight = rect.height || rect.bottom - rect.top;
  11109. if (selectedElm !== targetElm) {
  11110. hideResizeRect();
  11111. selectedElm = targetElm;
  11112. width = height = 0;
  11113. }
  11114. var e = editor.fire("ObjectSelected", { target: targetElm });
  11115. var selectedValue = dom2.getAttrib(selectedElm, elementSelectionAttr, "1");
  11116. if (isResizable(targetElm) && !e.isDefaultPrevented()) {
  11117. each2(resizeHandles, function(handle2, name2) {
  11118. var handleElm;
  11119. var startDrag = function(e2) {
  11120. var target = getResizeTargets(selectedElm)[0];
  11121. startX = e2.screenX;
  11122. startY = e2.screenY;
  11123. startW = target.clientWidth;
  11124. startH = target.clientHeight;
  11125. ratio = startH / startW;
  11126. selectedHandle = handle2;
  11127. selectedHandle.name = name2;
  11128. selectedHandle.startPos = {
  11129. x: targetWidth * handle2[0] + selectedElmX2,
  11130. y: targetHeight * handle2[1] + selectedElmY2
  11131. };
  11132. startScrollWidth = rootElement.scrollWidth;
  11133. startScrollHeight = rootElement.scrollHeight;
  11134. resizeBackdrop = dom2.add(rootElement, "div", {
  11135. "class": "mce-resize-backdrop",
  11136. "data-mce-bogus": "all"
  11137. });
  11138. dom2.setStyles(resizeBackdrop, {
  11139. position: "fixed",
  11140. left: "0",
  11141. top: "0",
  11142. width: "100%",
  11143. height: "100%"
  11144. });
  11145. selectedElmGhost = createGhostElement(selectedElm);
  11146. dom2.addClass(selectedElmGhost, "mce-clonedresizable");
  11147. dom2.setAttrib(selectedElmGhost, "data-mce-bogus", "all");
  11148. selectedElmGhost.contentEditable = "false";
  11149. dom2.setStyles(selectedElmGhost, {
  11150. left: selectedElmX2,
  11151. top: selectedElmY2,
  11152. margin: 0
  11153. });
  11154. setGhostElmSize(selectedElmGhost, targetWidth, targetHeight);
  11155. selectedElmGhost.removeAttribute(elementSelectionAttr);
  11156. rootElement.appendChild(selectedElmGhost);
  11157. dom2.bind(editableDoc, "mousemove", resizeGhostElement);
  11158. dom2.bind(editableDoc, "mouseup", endGhostResize);
  11159. if (rootDocument !== editableDoc) {
  11160. dom2.bind(rootDocument, "mousemove", resizeGhostElement);
  11161. dom2.bind(rootDocument, "mouseup", endGhostResize);
  11162. }
  11163. resizeHelper = dom2.add(rootElement, "div", {
  11164. "class": "mce-resize-helper",
  11165. "data-mce-bogus": "all"
  11166. }, startW + " &times; " + startH);
  11167. };
  11168. handleElm = dom2.get("mceResizeHandle" + name2);
  11169. if (handleElm) {
  11170. dom2.remove(handleElm);
  11171. }
  11172. handleElm = dom2.add(rootElement, "div", {
  11173. "id": "mceResizeHandle" + name2,
  11174. "data-mce-bogus": "all",
  11175. "class": "mce-resizehandle",
  11176. "unselectable": true,
  11177. "style": "cursor:" + name2 + "-resize; margin:0; padding:0"
  11178. });
  11179. if (Env.ie === 11) {
  11180. handleElm.contentEditable = false;
  11181. }
  11182. dom2.bind(handleElm, "mousedown", function(e2) {
  11183. e2.stopImmediatePropagation();
  11184. e2.preventDefault();
  11185. startDrag(e2);
  11186. });
  11187. handle2.elm = handleElm;
  11188. dom2.setStyles(handleElm, {
  11189. left: targetWidth * handle2[0] + selectedElmX2 - handleElm.offsetWidth / 2,
  11190. top: targetHeight * handle2[1] + selectedElmY2 - handleElm.offsetHeight / 2
  11191. });
  11192. });
  11193. } else {
  11194. hideResizeRect();
  11195. }
  11196. if (!dom2.getAttrib(selectedElm, elementSelectionAttr)) {
  11197. selectedElm.setAttribute(elementSelectionAttr, selectedValue);
  11198. }
  11199. };
  11200. var hideResizeRect = function() {
  11201. unbindResizeHandleEvents();
  11202. if (selectedElm) {
  11203. selectedElm.removeAttribute(elementSelectionAttr);
  11204. }
  11205. each$j(resizeHandles, function(value2, name2) {
  11206. var handleElm = dom2.get("mceResizeHandle" + name2);
  11207. if (handleElm) {
  11208. dom2.unbind(handleElm);
  11209. dom2.remove(handleElm);
  11210. }
  11211. });
  11212. };
  11213. var updateResizeRect = function(e) {
  11214. var startElm, controlElm;
  11215. var isChildOrEqual = function(node, parent2) {
  11216. if (node) {
  11217. do {
  11218. if (node === parent2) {
  11219. return true;
  11220. }
  11221. } while (node = node.parentNode);
  11222. }
  11223. };
  11224. if (resizeStarted || editor.removed) {
  11225. return;
  11226. }
  11227. each2(dom2.select("img[data-mce-selected],hr[data-mce-selected]"), function(img) {
  11228. img.removeAttribute(elementSelectionAttr);
  11229. });
  11230. controlElm = e.type === "mousedown" ? e.target : selection.getNode();
  11231. controlElm = dom2.$(controlElm).closest("table,img,figure.image,hr,video,span.mce-preview-object")[0];
  11232. if (isChildOrEqual(controlElm, rootElement)) {
  11233. disableGeckoResize();
  11234. startElm = selection.getStart(true);
  11235. if (isChildOrEqual(startElm, controlElm) && isChildOrEqual(selection.getEnd(true), controlElm)) {
  11236. showResizeRect(controlElm);
  11237. return;
  11238. }
  11239. }
  11240. hideResizeRect();
  11241. };
  11242. var isWithinContentEditableFalse = function(elm) {
  11243. return isContentEditableFalse$5(getContentEditableRoot$1(editor.getBody(), elm));
  11244. };
  11245. var unbindResizeHandleEvents = function() {
  11246. each$j(resizeHandles, function(handle2) {
  11247. if (handle2.elm) {
  11248. dom2.unbind(handle2.elm);
  11249. delete handle2.elm;
  11250. }
  11251. });
  11252. };
  11253. var disableGeckoResize = function() {
  11254. try {
  11255. editor.getDoc().execCommand("enableObjectResizing", false, "false");
  11256. } catch (ex) {
  11257. }
  11258. };
  11259. editor.on("init", function() {
  11260. disableGeckoResize();
  11261. if (Env.browser.isIE() || Env.browser.isEdge()) {
  11262. editor.on("mousedown click", function(e) {
  11263. var target = e.target, nodeName = target.nodeName;
  11264. if (!resizeStarted && /^(TABLE|IMG|HR)$/.test(nodeName) && !isWithinContentEditableFalse(target)) {
  11265. if (e.button !== 2) {
  11266. editor.selection.select(target, nodeName === "TABLE");
  11267. }
  11268. if (e.type === "mousedown") {
  11269. editor.nodeChanged();
  11270. }
  11271. }
  11272. });
  11273. var handleMSControlSelect_1 = function(e) {
  11274. var delayedSelect = function(node) {
  11275. Delay.setEditorTimeout(editor, function() {
  11276. return editor.selection.select(node);
  11277. });
  11278. };
  11279. if (isWithinContentEditableFalse(e.target) || isMedia$2(e.target)) {
  11280. e.preventDefault();
  11281. delayedSelect(e.target);
  11282. return;
  11283. }
  11284. if (/^(TABLE|IMG|HR)$/.test(e.target.nodeName)) {
  11285. e.preventDefault();
  11286. if (e.target.tagName === "IMG") {
  11287. delayedSelect(e.target);
  11288. }
  11289. }
  11290. };
  11291. dom2.bind(rootElement, "mscontrolselect", handleMSControlSelect_1);
  11292. editor.on("remove", function() {
  11293. return dom2.unbind(rootElement, "mscontrolselect", handleMSControlSelect_1);
  11294. });
  11295. }
  11296. var throttledUpdateResizeRect = Delay.throttle(function(e) {
  11297. if (!editor.composing) {
  11298. updateResizeRect(e);
  11299. }
  11300. });
  11301. editor.on("nodechange ResizeEditor ResizeWindow ResizeContent drop FullscreenStateChanged", throttledUpdateResizeRect);
  11302. editor.on("keyup compositionend", function(e) {
  11303. if (selectedElm && selectedElm.nodeName === "TABLE") {
  11304. throttledUpdateResizeRect(e);
  11305. }
  11306. });
  11307. editor.on("hide blur", hideResizeRect);
  11308. editor.on("contextmenu longpress", contextMenuSelectImage, true);
  11309. });
  11310. editor.on("remove", unbindResizeHandleEvents);
  11311. var destroy2 = function() {
  11312. selectedElm = selectedElmGhost = resizeBackdrop = null;
  11313. };
  11314. return {
  11315. isResizable,
  11316. showResizeRect,
  11317. hideResizeRect,
  11318. updateResizeRect,
  11319. destroy: destroy2
  11320. };
  11321. };
  11322. var hasCeProperty = function(node) {
  11323. return isContentEditableTrue$4(node) || isContentEditableFalse$b(node);
  11324. };
  11325. var findParent$1 = function(node, rootNode, predicate) {
  11326. while (node && node !== rootNode) {
  11327. if (predicate(node)) {
  11328. return node;
  11329. }
  11330. node = node.parentNode;
  11331. }
  11332. return null;
  11333. };
  11334. var findClosestIeRange = function(clientX, clientY, doc2) {
  11335. var rects;
  11336. var element = doc2.elementFromPoint(clientX, clientY);
  11337. var rng = doc2.body.createTextRange();
  11338. if (!element || element.tagName === "HTML") {
  11339. element = doc2.body;
  11340. }
  11341. rng.moveToElementText(element);
  11342. rects = Tools.toArray(rng.getClientRects());
  11343. rects = rects.sort(function(a, b) {
  11344. a = Math.abs(Math.max(a.top - clientY, a.bottom - clientY));
  11345. b = Math.abs(Math.max(b.top - clientY, b.bottom - clientY));
  11346. return a - b;
  11347. });
  11348. if (rects.length > 0) {
  11349. clientY = (rects[0].bottom + rects[0].top) / 2;
  11350. try {
  11351. rng.moveToPoint(clientX, clientY);
  11352. rng.collapse(true);
  11353. return rng;
  11354. } catch (ex) {
  11355. }
  11356. }
  11357. return null;
  11358. };
  11359. var moveOutOfContentEditableFalse = function(rng, rootNode) {
  11360. var parentElement = rng && rng.parentElement ? rng.parentElement() : null;
  11361. return isContentEditableFalse$b(findParent$1(parentElement, rootNode, hasCeProperty)) ? null : rng;
  11362. };
  11363. var fromPoint = function(clientX, clientY, doc2) {
  11364. var rng, point;
  11365. var pointDoc = doc2;
  11366. if (pointDoc.caretPositionFromPoint) {
  11367. point = pointDoc.caretPositionFromPoint(clientX, clientY);
  11368. if (point) {
  11369. rng = doc2.createRange();
  11370. rng.setStart(point.offsetNode, point.offset);
  11371. rng.collapse(true);
  11372. }
  11373. } else if (pointDoc.caretRangeFromPoint) {
  11374. rng = pointDoc.caretRangeFromPoint(clientX, clientY);
  11375. } else if (pointDoc.body.createTextRange) {
  11376. rng = pointDoc.body.createTextRange();
  11377. try {
  11378. rng.moveToPoint(clientX, clientY);
  11379. rng.collapse(true);
  11380. } catch (ex) {
  11381. rng = findClosestIeRange(clientX, clientY, doc2);
  11382. }
  11383. return moveOutOfContentEditableFalse(rng, doc2.body);
  11384. }
  11385. return rng;
  11386. };
  11387. var isEq$4 = function(rng1, rng2) {
  11388. return rng1 && rng2 && (rng1.startContainer === rng2.startContainer && rng1.startOffset === rng2.startOffset) && (rng1.endContainer === rng2.endContainer && rng1.endOffset === rng2.endOffset);
  11389. };
  11390. var findParent = function(node, rootNode, predicate) {
  11391. while (node && node !== rootNode) {
  11392. if (predicate(node)) {
  11393. return node;
  11394. }
  11395. node = node.parentNode;
  11396. }
  11397. return null;
  11398. };
  11399. var hasParent$1 = function(node, rootNode, predicate) {
  11400. return findParent(node, rootNode, predicate) !== null;
  11401. };
  11402. var hasParentWithName = function(node, rootNode, name2) {
  11403. return hasParent$1(node, rootNode, function(node2) {
  11404. return node2.nodeName === name2;
  11405. });
  11406. };
  11407. var isTable = function(node) {
  11408. return node && node.nodeName === "TABLE";
  11409. };
  11410. var isTableCell$2 = function(node) {
  11411. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
  11412. };
  11413. var isCeFalseCaretContainer = function(node, rootNode) {
  11414. return isCaretContainer$2(node) && hasParent$1(node, rootNode, isCaretNode) === false;
  11415. };
  11416. var hasBrBeforeAfter = function(dom2, node, left) {
  11417. var walker = new DomTreeWalker(node, dom2.getParent(node.parentNode, dom2.isBlock) || dom2.getRoot());
  11418. while (node = walker[left ? "prev" : "next"]()) {
  11419. if (isBr$5(node)) {
  11420. return true;
  11421. }
  11422. }
  11423. };
  11424. var isPrevNode = function(node, name2) {
  11425. return node.previousSibling && node.previousSibling.nodeName === name2;
  11426. };
  11427. var hasContentEditableFalseParent = function(body, node) {
  11428. while (node && node !== body) {
  11429. if (isContentEditableFalse$b(node)) {
  11430. return true;
  11431. }
  11432. node = node.parentNode;
  11433. }
  11434. return false;
  11435. };
  11436. var findTextNodeRelative = function(dom2, isAfterNode, collapsed, left, startNode) {
  11437. var lastInlineElement;
  11438. var body = dom2.getRoot();
  11439. var node;
  11440. var nonEmptyElementsMap = dom2.schema.getNonEmptyElements();
  11441. var parentBlockContainer = dom2.getParent(startNode.parentNode, dom2.isBlock) || body;
  11442. if (left && isBr$5(startNode) && isAfterNode && dom2.isEmpty(parentBlockContainer)) {
  11443. return Optional.some(CaretPosition(startNode.parentNode, dom2.nodeIndex(startNode)));
  11444. }
  11445. var walker = new DomTreeWalker(startNode, parentBlockContainer);
  11446. while (node = walker[left ? "prev" : "next"]()) {
  11447. if (dom2.getContentEditableParent(node) === "false" || isCeFalseCaretContainer(node, body)) {
  11448. return Optional.none();
  11449. }
  11450. if (isText$7(node) && node.nodeValue.length > 0) {
  11451. if (hasParentWithName(node, body, "A") === false) {
  11452. return Optional.some(CaretPosition(node, left ? node.nodeValue.length : 0));
  11453. }
  11454. return Optional.none();
  11455. }
  11456. if (dom2.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  11457. return Optional.none();
  11458. }
  11459. lastInlineElement = node;
  11460. }
  11461. if (collapsed && lastInlineElement) {
  11462. return Optional.some(CaretPosition(lastInlineElement, 0));
  11463. }
  11464. return Optional.none();
  11465. };
  11466. var normalizeEndPoint = function(dom2, collapsed, start2, rng) {
  11467. var container, offset;
  11468. var body = dom2.getRoot();
  11469. var node;
  11470. var directionLeft, normalized = false;
  11471. container = rng[(start2 ? "start" : "end") + "Container"];
  11472. offset = rng[(start2 ? "start" : "end") + "Offset"];
  11473. var isAfterNode = isElement$5(container) && offset === container.childNodes.length;
  11474. var nonEmptyElementsMap = dom2.schema.getNonEmptyElements();
  11475. directionLeft = start2;
  11476. if (isCaretContainer$2(container)) {
  11477. return Optional.none();
  11478. }
  11479. if (isElement$5(container) && offset > container.childNodes.length - 1) {
  11480. directionLeft = false;
  11481. }
  11482. if (isDocument$1(container)) {
  11483. container = body;
  11484. offset = 0;
  11485. }
  11486. if (container === body) {
  11487. if (directionLeft) {
  11488. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  11489. if (node) {
  11490. if (isCaretContainer$2(node)) {
  11491. return Optional.none();
  11492. }
  11493. if (nonEmptyElementsMap[node.nodeName] || isTable(node)) {
  11494. return Optional.none();
  11495. }
  11496. }
  11497. }
  11498. if (container.hasChildNodes()) {
  11499. offset = Math.min(!directionLeft && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1);
  11500. container = container.childNodes[offset];
  11501. offset = isText$7(container) && isAfterNode ? container.data.length : 0;
  11502. if (!collapsed && container === body.lastChild && isTable(container)) {
  11503. return Optional.none();
  11504. }
  11505. if (hasContentEditableFalseParent(body, container) || isCaretContainer$2(container)) {
  11506. return Optional.none();
  11507. }
  11508. if (container.hasChildNodes() && isTable(container) === false) {
  11509. node = container;
  11510. var walker = new DomTreeWalker(container, body);
  11511. do {
  11512. if (isContentEditableFalse$b(node) || isCaretContainer$2(node)) {
  11513. normalized = false;
  11514. break;
  11515. }
  11516. if (isText$7(node) && node.nodeValue.length > 0) {
  11517. offset = directionLeft ? 0 : node.nodeValue.length;
  11518. container = node;
  11519. normalized = true;
  11520. break;
  11521. }
  11522. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] && !isTableCell$2(node)) {
  11523. offset = dom2.nodeIndex(node);
  11524. container = node.parentNode;
  11525. if (!directionLeft) {
  11526. offset++;
  11527. }
  11528. normalized = true;
  11529. break;
  11530. }
  11531. } while (node = directionLeft ? walker.next() : walker.prev());
  11532. }
  11533. }
  11534. }
  11535. if (collapsed) {
  11536. if (isText$7(container) && offset === 0) {
  11537. findTextNodeRelative(dom2, isAfterNode, collapsed, true, container).each(function(pos) {
  11538. container = pos.container();
  11539. offset = pos.offset();
  11540. normalized = true;
  11541. });
  11542. }
  11543. if (isElement$5(container)) {
  11544. node = container.childNodes[offset];
  11545. if (!node) {
  11546. node = container.childNodes[offset - 1];
  11547. }
  11548. if (node && isBr$5(node) && !isPrevNode(node, "A") && !hasBrBeforeAfter(dom2, node, false) && !hasBrBeforeAfter(dom2, node, true)) {
  11549. findTextNodeRelative(dom2, isAfterNode, collapsed, true, node).each(function(pos) {
  11550. container = pos.container();
  11551. offset = pos.offset();
  11552. normalized = true;
  11553. });
  11554. }
  11555. }
  11556. }
  11557. if (directionLeft && !collapsed && isText$7(container) && offset === container.nodeValue.length) {
  11558. findTextNodeRelative(dom2, isAfterNode, collapsed, false, container).each(function(pos) {
  11559. container = pos.container();
  11560. offset = pos.offset();
  11561. normalized = true;
  11562. });
  11563. }
  11564. return normalized ? Optional.some(CaretPosition(container, offset)) : Optional.none();
  11565. };
  11566. var normalize$2 = function(dom2, rng) {
  11567. var collapsed = rng.collapsed, normRng = rng.cloneRange();
  11568. var startPos = CaretPosition.fromRangeStart(rng);
  11569. normalizeEndPoint(dom2, collapsed, true, normRng).each(function(pos) {
  11570. if (!collapsed || !CaretPosition.isAbove(startPos, pos)) {
  11571. normRng.setStart(pos.container(), pos.offset());
  11572. }
  11573. });
  11574. if (!collapsed) {
  11575. normalizeEndPoint(dom2, collapsed, false, normRng).each(function(pos) {
  11576. normRng.setEnd(pos.container(), pos.offset());
  11577. });
  11578. }
  11579. if (collapsed) {
  11580. normRng.collapse(true);
  11581. }
  11582. return isEq$4(rng, normRng) ? Optional.none() : Optional.some(normRng);
  11583. };
  11584. var splitText = function(node, offset) {
  11585. return node.splitText(offset);
  11586. };
  11587. var split = function(rng) {
  11588. var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
  11589. if (startContainer === endContainer && isText$7(startContainer)) {
  11590. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  11591. endContainer = splitText(startContainer, startOffset);
  11592. startContainer = endContainer.previousSibling;
  11593. if (endOffset > startOffset) {
  11594. endOffset = endOffset - startOffset;
  11595. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  11596. endOffset = endContainer.nodeValue.length;
  11597. startOffset = 0;
  11598. } else {
  11599. endOffset = 0;
  11600. }
  11601. }
  11602. } else {
  11603. if (isText$7(startContainer) && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  11604. startContainer = splitText(startContainer, startOffset);
  11605. startOffset = 0;
  11606. }
  11607. if (isText$7(endContainer) && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  11608. endContainer = splitText(endContainer, endOffset).previousSibling;
  11609. endOffset = endContainer.nodeValue.length;
  11610. }
  11611. }
  11612. return {
  11613. startContainer,
  11614. startOffset,
  11615. endContainer,
  11616. endOffset
  11617. };
  11618. };
  11619. var RangeUtils = function(dom2) {
  11620. var walk2 = function(rng, callback) {
  11621. return walk$2(dom2, rng, callback);
  11622. };
  11623. var split$12 = split;
  11624. var normalize2 = function(rng) {
  11625. return normalize$2(dom2, rng).fold(never, function(normalizedRng) {
  11626. rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);
  11627. rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);
  11628. return true;
  11629. });
  11630. };
  11631. return {
  11632. walk: walk2,
  11633. split: split$12,
  11634. normalize: normalize2
  11635. };
  11636. };
  11637. RangeUtils.compareRanges = isEq$4;
  11638. RangeUtils.getCaretRangeFromPoint = fromPoint;
  11639. RangeUtils.getSelectedNode = getSelectedNode;
  11640. RangeUtils.getNode = getNode$1;
  11641. var Dimension = function(name2, getOffset) {
  11642. var set2 = function(element, h) {
  11643. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  11644. throw new Error(name2 + ".set accepts only positive integer values. Value was " + h);
  11645. }
  11646. var dom2 = element.dom;
  11647. if (isSupported(dom2)) {
  11648. dom2.style[name2] = h + "px";
  11649. }
  11650. };
  11651. var get2 = function(element) {
  11652. var r2 = getOffset(element);
  11653. if (r2 <= 0 || r2 === null) {
  11654. var css = get$5(element, name2);
  11655. return parseFloat(css) || 0;
  11656. }
  11657. return r2;
  11658. };
  11659. var getOuter = get2;
  11660. var aggregate = function(element, properties) {
  11661. return foldl(properties, function(acc, property) {
  11662. var val = get$5(element, property);
  11663. var value2 = val === void 0 ? 0 : parseInt(val, 10);
  11664. return isNaN(value2) ? acc : acc + value2;
  11665. }, 0);
  11666. };
  11667. var max2 = function(element, value2, properties) {
  11668. var cumulativeInclusions = aggregate(element, properties);
  11669. var absoluteMax = value2 > cumulativeInclusions ? value2 - cumulativeInclusions : 0;
  11670. return absoluteMax;
  11671. };
  11672. return {
  11673. set: set2,
  11674. get: get2,
  11675. getOuter,
  11676. aggregate,
  11677. max: max2
  11678. };
  11679. };
  11680. var api = Dimension("height", function(element) {
  11681. var dom2 = element.dom;
  11682. return inBody(element) ? dom2.getBoundingClientRect().height : dom2.offsetHeight;
  11683. });
  11684. var get$1 = function(element) {
  11685. return api.get(element);
  11686. };
  11687. var walkUp = function(navigation, doc2) {
  11688. var frame = navigation.view(doc2);
  11689. return frame.fold(constant([]), function(f) {
  11690. var parent2 = navigation.owner(f);
  11691. var rest = walkUp(navigation, parent2);
  11692. return [f].concat(rest);
  11693. });
  11694. };
  11695. var pathTo = function(element, navigation) {
  11696. var d = navigation.owner(element);
  11697. return walkUp(navigation, d);
  11698. };
  11699. var view = function(doc2) {
  11700. var _a;
  11701. var element = doc2.dom === document ? Optional.none() : Optional.from((_a = doc2.dom.defaultView) === null || _a === void 0 ? void 0 : _a.frameElement);
  11702. return element.map(SugarElement.fromDom);
  11703. };
  11704. var owner = function(element) {
  11705. return documentOrOwner(element);
  11706. };
  11707. var Navigation = Object.freeze({
  11708. __proto__: null,
  11709. view,
  11710. owner
  11711. });
  11712. var find$1 = function(element) {
  11713. var doc2 = SugarElement.fromDom(document);
  11714. var scroll = get$8(doc2);
  11715. var frames = pathTo(element, Navigation);
  11716. var offset = viewport(element);
  11717. var r2 = foldr(frames, function(b, a) {
  11718. var loc = viewport(a);
  11719. return {
  11720. left: b.left + loc.left,
  11721. top: b.top + loc.top
  11722. };
  11723. }, {
  11724. left: 0,
  11725. top: 0
  11726. });
  11727. return SugarPosition(r2.left + offset.left + scroll.left, r2.top + offset.top + scroll.top);
  11728. };
  11729. var excludeFromDescend = function(element) {
  11730. return name(element) === "textarea";
  11731. };
  11732. var fireScrollIntoViewEvent = function(editor, data2) {
  11733. var scrollEvent = editor.fire("ScrollIntoView", data2);
  11734. return scrollEvent.isDefaultPrevented();
  11735. };
  11736. var fireAfterScrollIntoViewEvent = function(editor, data2) {
  11737. editor.fire("AfterScrollIntoView", data2);
  11738. };
  11739. var descend = function(element, offset) {
  11740. var children$1 = children(element);
  11741. if (children$1.length === 0 || excludeFromDescend(element)) {
  11742. return {
  11743. element,
  11744. offset
  11745. };
  11746. } else if (offset < children$1.length && !excludeFromDescend(children$1[offset])) {
  11747. return {
  11748. element: children$1[offset],
  11749. offset: 0
  11750. };
  11751. } else {
  11752. var last2 = children$1[children$1.length - 1];
  11753. if (excludeFromDescend(last2)) {
  11754. return {
  11755. element,
  11756. offset
  11757. };
  11758. } else {
  11759. if (name(last2) === "img") {
  11760. return {
  11761. element: last2,
  11762. offset: 1
  11763. };
  11764. } else if (isText$8(last2)) {
  11765. return {
  11766. element: last2,
  11767. offset: get$2(last2).length
  11768. };
  11769. } else {
  11770. return {
  11771. element: last2,
  11772. offset: children(last2).length
  11773. };
  11774. }
  11775. }
  11776. }
  11777. };
  11778. var markerInfo = function(element, cleanupFun) {
  11779. var pos = absolute(element);
  11780. var height = get$1(element);
  11781. return {
  11782. element,
  11783. bottom: pos.top + height,
  11784. height,
  11785. pos,
  11786. cleanup: cleanupFun
  11787. };
  11788. };
  11789. var createMarker = function(element, offset) {
  11790. var startPoint = descend(element, offset);
  11791. var span = SugarElement.fromHtml('<span data-mce-bogus="all" style="display: inline-block;">' + ZWSP$1 + "</span>");
  11792. before$4(startPoint.element, span);
  11793. return markerInfo(span, function() {
  11794. return remove$7(span);
  11795. });
  11796. };
  11797. var elementMarker = function(element) {
  11798. return markerInfo(SugarElement.fromDom(element), noop);
  11799. };
  11800. var withMarker = function(editor, f, rng, alignToTop) {
  11801. preserveWith(editor, function(_s, _e) {
  11802. return applyWithMarker(editor, f, rng, alignToTop);
  11803. }, rng);
  11804. };
  11805. var withScrollEvents = function(editor, doc2, f, marker, alignToTop) {
  11806. var data2 = {
  11807. elm: marker.element.dom,
  11808. alignToTop
  11809. };
  11810. if (fireScrollIntoViewEvent(editor, data2)) {
  11811. return;
  11812. }
  11813. var scrollTop = get$8(doc2).top;
  11814. f(doc2, scrollTop, marker, alignToTop);
  11815. fireAfterScrollIntoViewEvent(editor, data2);
  11816. };
  11817. var applyWithMarker = function(editor, f, rng, alignToTop) {
  11818. var body = SugarElement.fromDom(editor.getBody());
  11819. var doc2 = SugarElement.fromDom(editor.getDoc());
  11820. reflow(body);
  11821. var marker = createMarker(SugarElement.fromDom(rng.startContainer), rng.startOffset);
  11822. withScrollEvents(editor, doc2, f, marker, alignToTop);
  11823. marker.cleanup();
  11824. };
  11825. var withElement = function(editor, element, f, alignToTop) {
  11826. var doc2 = SugarElement.fromDom(editor.getDoc());
  11827. withScrollEvents(editor, doc2, f, elementMarker(element), alignToTop);
  11828. };
  11829. var preserveWith = function(editor, f, rng) {
  11830. var startElement = rng.startContainer;
  11831. var startOffset = rng.startOffset;
  11832. var endElement = rng.endContainer;
  11833. var endOffset = rng.endOffset;
  11834. f(SugarElement.fromDom(startElement), SugarElement.fromDom(endElement));
  11835. var newRng = editor.dom.createRng();
  11836. newRng.setStart(startElement, startOffset);
  11837. newRng.setEnd(endElement, endOffset);
  11838. editor.selection.setRng(rng);
  11839. };
  11840. var scrollToMarker = function(marker, viewHeight, alignToTop, doc2) {
  11841. var pos = marker.pos;
  11842. if (alignToTop) {
  11843. to(pos.left, pos.top, doc2);
  11844. } else {
  11845. var y = pos.top - viewHeight + marker.height;
  11846. to(pos.left, y, doc2);
  11847. }
  11848. };
  11849. var intoWindowIfNeeded = function(doc2, scrollTop, viewHeight, marker, alignToTop) {
  11850. var viewportBottom = viewHeight + scrollTop;
  11851. var markerTop = marker.pos.top;
  11852. var markerBottom = marker.bottom;
  11853. var largerThanViewport = markerBottom - markerTop >= viewHeight;
  11854. if (markerTop < scrollTop) {
  11855. scrollToMarker(marker, viewHeight, alignToTop !== false, doc2);
  11856. } else if (markerTop > viewportBottom) {
  11857. var align = largerThanViewport ? alignToTop !== false : alignToTop === true;
  11858. scrollToMarker(marker, viewHeight, align, doc2);
  11859. } else if (markerBottom > viewportBottom && !largerThanViewport) {
  11860. scrollToMarker(marker, viewHeight, alignToTop === true, doc2);
  11861. }
  11862. };
  11863. var intoWindow = function(doc2, scrollTop, marker, alignToTop) {
  11864. var viewHeight = doc2.dom.defaultView.innerHeight;
  11865. intoWindowIfNeeded(doc2, scrollTop, viewHeight, marker, alignToTop);
  11866. };
  11867. var intoFrame = function(doc2, scrollTop, marker, alignToTop) {
  11868. var frameViewHeight = doc2.dom.defaultView.innerHeight;
  11869. intoWindowIfNeeded(doc2, scrollTop, frameViewHeight, marker, alignToTop);
  11870. var op = find$1(marker.element);
  11871. var viewportBounds = getBounds(window);
  11872. if (op.top < viewportBounds.y) {
  11873. intoView(marker.element, alignToTop !== false);
  11874. } else if (op.top > viewportBounds.bottom) {
  11875. intoView(marker.element, alignToTop === true);
  11876. }
  11877. };
  11878. var rangeIntoWindow = function(editor, rng, alignToTop) {
  11879. return withMarker(editor, intoWindow, rng, alignToTop);
  11880. };
  11881. var elementIntoWindow = function(editor, element, alignToTop) {
  11882. return withElement(editor, element, intoWindow, alignToTop);
  11883. };
  11884. var rangeIntoFrame = function(editor, rng, alignToTop) {
  11885. return withMarker(editor, intoFrame, rng, alignToTop);
  11886. };
  11887. var elementIntoFrame = function(editor, element, alignToTop) {
  11888. return withElement(editor, element, intoFrame, alignToTop);
  11889. };
  11890. var scrollElementIntoView = function(editor, element, alignToTop) {
  11891. var scroller = editor.inline ? elementIntoWindow : elementIntoFrame;
  11892. scroller(editor, element, alignToTop);
  11893. };
  11894. var scrollRangeIntoView = function(editor, rng, alignToTop) {
  11895. var scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame;
  11896. scroller(editor, rng, alignToTop);
  11897. };
  11898. var getDocument = function() {
  11899. return SugarElement.fromDom(document);
  11900. };
  11901. var focus$1 = function(element) {
  11902. return element.dom.focus();
  11903. };
  11904. var hasFocus$1 = function(element) {
  11905. var root = getRootNode(element).dom;
  11906. return element.dom === root.activeElement;
  11907. };
  11908. var active = function(root) {
  11909. if (root === void 0) {
  11910. root = getDocument();
  11911. }
  11912. return Optional.from(root.dom.activeElement).map(SugarElement.fromDom);
  11913. };
  11914. var search = function(element) {
  11915. return active(getRootNode(element)).filter(function(e) {
  11916. return element.dom.contains(e.dom);
  11917. });
  11918. };
  11919. var create$5 = function(start2, soffset, finish, foffset) {
  11920. return {
  11921. start: start2,
  11922. soffset,
  11923. finish,
  11924. foffset
  11925. };
  11926. };
  11927. var SimRange = { create: create$5 };
  11928. var adt$1 = Adt.generate([
  11929. { before: ["element"] },
  11930. {
  11931. on: [
  11932. "element",
  11933. "offset"
  11934. ]
  11935. },
  11936. { after: ["element"] }
  11937. ]);
  11938. var cata = function(subject, onBefore, onOn, onAfter) {
  11939. return subject.fold(onBefore, onOn, onAfter);
  11940. };
  11941. var getStart$2 = function(situ) {
  11942. return situ.fold(identity, identity, identity);
  11943. };
  11944. var before$1 = adt$1.before;
  11945. var on = adt$1.on;
  11946. var after$1 = adt$1.after;
  11947. var Situ = {
  11948. before: before$1,
  11949. on,
  11950. after: after$1,
  11951. cata,
  11952. getStart: getStart$2
  11953. };
  11954. var adt = Adt.generate([
  11955. { domRange: ["rng"] },
  11956. {
  11957. relative: [
  11958. "startSitu",
  11959. "finishSitu"
  11960. ]
  11961. },
  11962. {
  11963. exact: [
  11964. "start",
  11965. "soffset",
  11966. "finish",
  11967. "foffset"
  11968. ]
  11969. }
  11970. ]);
  11971. var exactFromRange = function(simRange) {
  11972. return adt.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset);
  11973. };
  11974. var getStart$1 = function(selection) {
  11975. return selection.match({
  11976. domRange: function(rng) {
  11977. return SugarElement.fromDom(rng.startContainer);
  11978. },
  11979. relative: function(startSitu, _finishSitu) {
  11980. return Situ.getStart(startSitu);
  11981. },
  11982. exact: function(start2, _soffset, _finish, _foffset) {
  11983. return start2;
  11984. }
  11985. });
  11986. };
  11987. var domRange = adt.domRange;
  11988. var relative = adt.relative;
  11989. var exact = adt.exact;
  11990. var getWin = function(selection) {
  11991. var start2 = getStart$1(selection);
  11992. return defaultView(start2);
  11993. };
  11994. var range = SimRange.create;
  11995. var SimSelection = {
  11996. domRange,
  11997. relative,
  11998. exact,
  11999. exactFromRange,
  12000. getWin,
  12001. range
  12002. };
  12003. var browser$1 = detect().browser;
  12004. var clamp$1 = function(offset, element) {
  12005. var max2 = isText$8(element) ? get$2(element).length : children(element).length + 1;
  12006. if (offset > max2) {
  12007. return max2;
  12008. } else if (offset < 0) {
  12009. return 0;
  12010. }
  12011. return offset;
  12012. };
  12013. var normalizeRng = function(rng) {
  12014. return SimSelection.range(rng.start, clamp$1(rng.soffset, rng.start), rng.finish, clamp$1(rng.foffset, rng.finish));
  12015. };
  12016. var isOrContains = function(root, elm) {
  12017. return !isRestrictedNode(elm.dom) && (contains$1(root, elm) || eq(root, elm));
  12018. };
  12019. var isRngInRoot = function(root) {
  12020. return function(rng) {
  12021. return isOrContains(root, rng.start) && isOrContains(root, rng.finish);
  12022. };
  12023. };
  12024. var shouldStore = function(editor) {
  12025. return editor.inline === true || browser$1.isIE();
  12026. };
  12027. var nativeRangeToSelectionRange = function(r2) {
  12028. return SimSelection.range(SugarElement.fromDom(r2.startContainer), r2.startOffset, SugarElement.fromDom(r2.endContainer), r2.endOffset);
  12029. };
  12030. var readRange = function(win) {
  12031. var selection = win.getSelection();
  12032. var rng = !selection || selection.rangeCount === 0 ? Optional.none() : Optional.from(selection.getRangeAt(0));
  12033. return rng.map(nativeRangeToSelectionRange);
  12034. };
  12035. var getBookmark = function(root) {
  12036. var win = defaultView(root);
  12037. return readRange(win.dom).filter(isRngInRoot(root));
  12038. };
  12039. var validate = function(root, bookmark) {
  12040. return Optional.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng);
  12041. };
  12042. var bookmarkToNativeRng = function(bookmark) {
  12043. var rng = document.createRange();
  12044. try {
  12045. rng.setStart(bookmark.start.dom, bookmark.soffset);
  12046. rng.setEnd(bookmark.finish.dom, bookmark.foffset);
  12047. return Optional.some(rng);
  12048. } catch (_) {
  12049. return Optional.none();
  12050. }
  12051. };
  12052. var store = function(editor) {
  12053. var newBookmark = shouldStore(editor) ? getBookmark(SugarElement.fromDom(editor.getBody())) : Optional.none();
  12054. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
  12055. };
  12056. var storeNative = function(editor, rng) {
  12057. var root = SugarElement.fromDom(editor.getBody());
  12058. var range2 = shouldStore(editor) ? Optional.from(rng) : Optional.none();
  12059. var newBookmark = range2.map(nativeRangeToSelectionRange).filter(isRngInRoot(root));
  12060. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
  12061. };
  12062. var getRng = function(editor) {
  12063. var bookmark = editor.bookmark ? editor.bookmark : Optional.none();
  12064. return bookmark.bind(function(x) {
  12065. return validate(SugarElement.fromDom(editor.getBody()), x);
  12066. }).bind(bookmarkToNativeRng);
  12067. };
  12068. var restore = function(editor) {
  12069. getRng(editor).each(function(rng) {
  12070. return editor.selection.setRng(rng);
  12071. });
  12072. };
  12073. var isEditorUIElement$1 = function(elm) {
  12074. var className = elm.className.toString();
  12075. return className.indexOf("tox-") !== -1 || className.indexOf("mce-") !== -1;
  12076. };
  12077. var FocusManager = { isEditorUIElement: isEditorUIElement$1 };
  12078. var isManualNodeChange = function(e) {
  12079. return e.type === "nodechange" && e.selectionChange;
  12080. };
  12081. var registerPageMouseUp = function(editor, throttledStore) {
  12082. var mouseUpPage = function() {
  12083. throttledStore.throttle();
  12084. };
  12085. DOMUtils.DOM.bind(document, "mouseup", mouseUpPage);
  12086. editor.on("remove", function() {
  12087. DOMUtils.DOM.unbind(document, "mouseup", mouseUpPage);
  12088. });
  12089. };
  12090. var registerFocusOut = function(editor) {
  12091. editor.on("focusout", function() {
  12092. store(editor);
  12093. });
  12094. };
  12095. var registerMouseUp = function(editor, throttledStore) {
  12096. editor.on("mouseup touchend", function(_e) {
  12097. throttledStore.throttle();
  12098. });
  12099. };
  12100. var registerEditorEvents = function(editor, throttledStore) {
  12101. var browser2 = detect().browser;
  12102. if (browser2.isIE()) {
  12103. registerFocusOut(editor);
  12104. } else {
  12105. registerMouseUp(editor, throttledStore);
  12106. }
  12107. editor.on("keyup NodeChange", function(e) {
  12108. if (!isManualNodeChange(e)) {
  12109. store(editor);
  12110. }
  12111. });
  12112. };
  12113. var register$3 = function(editor) {
  12114. var throttledStore = first(function() {
  12115. store(editor);
  12116. }, 0);
  12117. editor.on("init", function() {
  12118. if (editor.inline) {
  12119. registerPageMouseUp(editor, throttledStore);
  12120. }
  12121. registerEditorEvents(editor, throttledStore);
  12122. });
  12123. editor.on("remove", function() {
  12124. throttledStore.cancel();
  12125. });
  12126. };
  12127. var documentFocusInHandler;
  12128. var DOM$8 = DOMUtils.DOM;
  12129. var isEditorUIElement = function(elm) {
  12130. return FocusManager.isEditorUIElement(elm);
  12131. };
  12132. var isEditorContentAreaElement = function(elm) {
  12133. var classList = elm.classList;
  12134. if (classList !== void 0) {
  12135. return classList.contains("tox-edit-area") || classList.contains("tox-edit-area__iframe") || classList.contains("mce-content-body");
  12136. } else {
  12137. return false;
  12138. }
  12139. };
  12140. var isUIElement = function(editor, elm) {
  12141. var customSelector = getCustomUiSelector(editor);
  12142. var parent2 = DOM$8.getParent(elm, function(elm2) {
  12143. return isEditorUIElement(elm2) || (customSelector ? editor.dom.is(elm2, customSelector) : false);
  12144. });
  12145. return parent2 !== null;
  12146. };
  12147. var getActiveElement = function(editor) {
  12148. try {
  12149. var root = getRootNode(SugarElement.fromDom(editor.getElement()));
  12150. return active(root).fold(function() {
  12151. return document.body;
  12152. }, function(x) {
  12153. return x.dom;
  12154. });
  12155. } catch (ex) {
  12156. return document.body;
  12157. }
  12158. };
  12159. var registerEvents$1 = function(editorManager, e) {
  12160. var editor = e.editor;
  12161. register$3(editor);
  12162. editor.on("focusin", function() {
  12163. var focusedEditor = editorManager.focusedEditor;
  12164. if (focusedEditor !== editor) {
  12165. if (focusedEditor) {
  12166. focusedEditor.fire("blur", { focusedEditor: editor });
  12167. }
  12168. editorManager.setActive(editor);
  12169. editorManager.focusedEditor = editor;
  12170. editor.fire("focus", { blurredEditor: focusedEditor });
  12171. editor.focus(true);
  12172. }
  12173. });
  12174. editor.on("focusout", function() {
  12175. Delay.setEditorTimeout(editor, function() {
  12176. var focusedEditor = editorManager.focusedEditor;
  12177. if (!isUIElement(editor, getActiveElement(editor)) && focusedEditor === editor) {
  12178. editor.fire("blur", { focusedEditor: null });
  12179. editorManager.focusedEditor = null;
  12180. }
  12181. });
  12182. });
  12183. if (!documentFocusInHandler) {
  12184. documentFocusInHandler = function(e2) {
  12185. var activeEditor = editorManager.activeEditor;
  12186. if (activeEditor) {
  12187. getOriginalEventTarget(e2).each(function(target) {
  12188. if (target.ownerDocument === document) {
  12189. if (target !== document.body && !isUIElement(activeEditor, target) && editorManager.focusedEditor === activeEditor) {
  12190. activeEditor.fire("blur", { focusedEditor: null });
  12191. editorManager.focusedEditor = null;
  12192. }
  12193. }
  12194. });
  12195. }
  12196. };
  12197. DOM$8.bind(document, "focusin", documentFocusInHandler);
  12198. }
  12199. };
  12200. var unregisterDocumentEvents = function(editorManager, e) {
  12201. if (editorManager.focusedEditor === e.editor) {
  12202. editorManager.focusedEditor = null;
  12203. }
  12204. if (!editorManager.activeEditor) {
  12205. DOM$8.unbind(document, "focusin", documentFocusInHandler);
  12206. documentFocusInHandler = null;
  12207. }
  12208. };
  12209. var setup$l = function(editorManager) {
  12210. editorManager.on("AddEditor", curry(registerEvents$1, editorManager));
  12211. editorManager.on("RemoveEditor", curry(unregisterDocumentEvents, editorManager));
  12212. };
  12213. var getContentEditableHost = function(editor, node) {
  12214. return editor.dom.getParent(node, function(node2) {
  12215. return editor.dom.getContentEditable(node2) === "true";
  12216. });
  12217. };
  12218. var getCollapsedNode = function(rng) {
  12219. return rng.collapsed ? Optional.from(getNode$1(rng.startContainer, rng.startOffset)).map(SugarElement.fromDom) : Optional.none();
  12220. };
  12221. var getFocusInElement = function(root, rng) {
  12222. return getCollapsedNode(rng).bind(function(node) {
  12223. if (isTableSection(node)) {
  12224. return Optional.some(node);
  12225. } else if (contains$1(root, node) === false) {
  12226. return Optional.some(root);
  12227. } else {
  12228. return Optional.none();
  12229. }
  12230. });
  12231. };
  12232. var normalizeSelection$1 = function(editor, rng) {
  12233. getFocusInElement(SugarElement.fromDom(editor.getBody()), rng).bind(function(elm) {
  12234. return firstPositionIn(elm.dom);
  12235. }).fold(function() {
  12236. editor.selection.normalize();
  12237. return;
  12238. }, function(caretPos) {
  12239. return editor.selection.setRng(caretPos.toRange());
  12240. });
  12241. };
  12242. var focusBody = function(body) {
  12243. if (body.setActive) {
  12244. try {
  12245. body.setActive();
  12246. } catch (ex) {
  12247. body.focus();
  12248. }
  12249. } else {
  12250. body.focus();
  12251. }
  12252. };
  12253. var hasElementFocus = function(elm) {
  12254. return hasFocus$1(elm) || search(elm).isSome();
  12255. };
  12256. var hasIframeFocus = function(editor) {
  12257. return editor.iframeElement && hasFocus$1(SugarElement.fromDom(editor.iframeElement));
  12258. };
  12259. var hasInlineFocus = function(editor) {
  12260. var rawBody = editor.getBody();
  12261. return rawBody && hasElementFocus(SugarElement.fromDom(rawBody));
  12262. };
  12263. var hasUiFocus = function(editor) {
  12264. var dos = getRootNode(SugarElement.fromDom(editor.getElement()));
  12265. return active(dos).filter(function(elem) {
  12266. return !isEditorContentAreaElement(elem.dom) && isUIElement(editor, elem.dom);
  12267. }).isSome();
  12268. };
  12269. var hasFocus = function(editor) {
  12270. return editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor);
  12271. };
  12272. var hasEditorOrUiFocus = function(editor) {
  12273. return hasFocus(editor) || hasUiFocus(editor);
  12274. };
  12275. var focusEditor = function(editor) {
  12276. var selection = editor.selection;
  12277. var body = editor.getBody();
  12278. var rng = selection.getRng();
  12279. editor.quirks.refreshContentEditable();
  12280. if (editor.bookmark !== void 0 && hasFocus(editor) === false) {
  12281. getRng(editor).each(function(bookmarkRng) {
  12282. editor.selection.setRng(bookmarkRng);
  12283. rng = bookmarkRng;
  12284. });
  12285. }
  12286. var contentEditableHost = getContentEditableHost(editor, selection.getNode());
  12287. if (editor.$.contains(body, contentEditableHost)) {
  12288. focusBody(contentEditableHost);
  12289. normalizeSelection$1(editor, rng);
  12290. activateEditor(editor);
  12291. return;
  12292. }
  12293. if (!editor.inline) {
  12294. if (!Env.opera) {
  12295. focusBody(body);
  12296. }
  12297. editor.getWin().focus();
  12298. }
  12299. if (Env.gecko || editor.inline) {
  12300. focusBody(body);
  12301. normalizeSelection$1(editor, rng);
  12302. }
  12303. activateEditor(editor);
  12304. };
  12305. var activateEditor = function(editor) {
  12306. return editor.editorManager.setActive(editor);
  12307. };
  12308. var focus = function(editor, skipFocus) {
  12309. if (editor.removed) {
  12310. return;
  12311. }
  12312. if (skipFocus) {
  12313. activateEditor(editor);
  12314. } else {
  12315. focusEditor(editor);
  12316. }
  12317. };
  12318. var getEndpointElement = function(root, rng, start2, real, resolve2) {
  12319. var container = start2 ? rng.startContainer : rng.endContainer;
  12320. var offset = start2 ? rng.startOffset : rng.endOffset;
  12321. return Optional.from(container).map(SugarElement.fromDom).map(function(elm) {
  12322. return !real || !rng.collapsed ? child$1(elm, resolve2(elm, offset)).getOr(elm) : elm;
  12323. }).bind(function(elm) {
  12324. return isElement$6(elm) ? Optional.some(elm) : parent(elm).filter(isElement$6);
  12325. }).map(function(elm) {
  12326. return elm.dom;
  12327. }).getOr(root);
  12328. };
  12329. var getStart = function(root, rng, real) {
  12330. return getEndpointElement(root, rng, true, real, function(elm, offset) {
  12331. return Math.min(childNodesCount(elm), offset);
  12332. });
  12333. };
  12334. var getEnd = function(root, rng, real) {
  12335. return getEndpointElement(root, rng, false, real, function(elm, offset) {
  12336. return offset > 0 ? offset - 1 : offset;
  12337. });
  12338. };
  12339. var skipEmptyTextNodes = function(node, forwards) {
  12340. var orig = node;
  12341. while (node && isText$7(node) && node.length === 0) {
  12342. node = forwards ? node.nextSibling : node.previousSibling;
  12343. }
  12344. return node || orig;
  12345. };
  12346. var getNode = function(root, rng) {
  12347. var elm, startContainer, endContainer;
  12348. if (!rng) {
  12349. return root;
  12350. }
  12351. startContainer = rng.startContainer;
  12352. endContainer = rng.endContainer;
  12353. var startOffset = rng.startOffset;
  12354. var endOffset = rng.endOffset;
  12355. elm = rng.commonAncestorContainer;
  12356. if (!rng.collapsed) {
  12357. if (startContainer === endContainer) {
  12358. if (endOffset - startOffset < 2) {
  12359. if (startContainer.hasChildNodes()) {
  12360. elm = startContainer.childNodes[startOffset];
  12361. }
  12362. }
  12363. }
  12364. if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
  12365. if (startContainer.length === startOffset) {
  12366. startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);
  12367. } else {
  12368. startContainer = startContainer.parentNode;
  12369. }
  12370. if (endOffset === 0) {
  12371. endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);
  12372. } else {
  12373. endContainer = endContainer.parentNode;
  12374. }
  12375. if (startContainer && startContainer === endContainer) {
  12376. return startContainer;
  12377. }
  12378. }
  12379. }
  12380. if (elm && elm.nodeType === 3) {
  12381. return elm.parentNode;
  12382. }
  12383. return elm;
  12384. };
  12385. var getSelectedBlocks = function(dom2, rng, startElm, endElm) {
  12386. var node;
  12387. var selectedBlocks = [];
  12388. var root = dom2.getRoot();
  12389. startElm = dom2.getParent(startElm || getStart(root, rng, rng.collapsed), dom2.isBlock);
  12390. endElm = dom2.getParent(endElm || getEnd(root, rng, rng.collapsed), dom2.isBlock);
  12391. if (startElm && startElm !== root) {
  12392. selectedBlocks.push(startElm);
  12393. }
  12394. if (startElm && endElm && startElm !== endElm) {
  12395. node = startElm;
  12396. var walker = new DomTreeWalker(startElm, root);
  12397. while ((node = walker.next()) && node !== endElm) {
  12398. if (dom2.isBlock(node)) {
  12399. selectedBlocks.push(node);
  12400. }
  12401. }
  12402. }
  12403. if (endElm && startElm !== endElm && endElm !== root) {
  12404. selectedBlocks.push(endElm);
  12405. }
  12406. return selectedBlocks;
  12407. };
  12408. var select = function(dom2, node, content) {
  12409. return Optional.from(node).map(function(node2) {
  12410. var idx = dom2.nodeIndex(node2);
  12411. var rng = dom2.createRng();
  12412. rng.setStart(node2.parentNode, idx);
  12413. rng.setEnd(node2.parentNode, idx + 1);
  12414. if (content) {
  12415. moveEndPoint(dom2, rng, node2, true);
  12416. moveEndPoint(dom2, rng, node2, false);
  12417. }
  12418. return rng;
  12419. });
  12420. };
  12421. var processRanges = function(editor, ranges) {
  12422. return map$3(ranges, function(range2) {
  12423. var evt = editor.fire("GetSelectionRange", { range: range2 });
  12424. return evt.range !== range2 ? evt.range : range2;
  12425. });
  12426. };
  12427. var typeLookup = {
  12428. "#text": 3,
  12429. "#comment": 8,
  12430. "#cdata": 4,
  12431. "#pi": 7,
  12432. "#doctype": 10,
  12433. "#document-fragment": 11
  12434. };
  12435. var walk$1 = function(node, root, prev) {
  12436. var startName = prev ? "lastChild" : "firstChild";
  12437. var siblingName = prev ? "prev" : "next";
  12438. if (node[startName]) {
  12439. return node[startName];
  12440. }
  12441. if (node !== root) {
  12442. var sibling2 = node[siblingName];
  12443. if (sibling2) {
  12444. return sibling2;
  12445. }
  12446. for (var parent_1 = node.parent; parent_1 && parent_1 !== root; parent_1 = parent_1.parent) {
  12447. sibling2 = parent_1[siblingName];
  12448. if (sibling2) {
  12449. return sibling2;
  12450. }
  12451. }
  12452. }
  12453. };
  12454. var isEmptyTextNode = function(node) {
  12455. if (!isWhitespaceText(node.value)) {
  12456. return false;
  12457. }
  12458. var parentNode = node.parent;
  12459. if (parentNode && (parentNode.name !== "span" || parentNode.attr("style")) && /^[ ]+$/.test(node.value)) {
  12460. return false;
  12461. }
  12462. return true;
  12463. };
  12464. var isNonEmptyElement = function(node) {
  12465. var isNamedAnchor2 = node.name === "a" && !node.attr("href") && node.attr("id");
  12466. return node.attr("name") || node.attr("id") && !node.firstChild || node.attr("data-mce-bookmark") || isNamedAnchor2;
  12467. };
  12468. var AstNode = function() {
  12469. function AstNode2(name2, type2) {
  12470. this.name = name2;
  12471. this.type = type2;
  12472. if (type2 === 1) {
  12473. this.attributes = [];
  12474. this.attributes.map = {};
  12475. }
  12476. }
  12477. AstNode2.create = function(name2, attrs) {
  12478. var node = new AstNode2(name2, typeLookup[name2] || 1);
  12479. if (attrs) {
  12480. each$j(attrs, function(value2, attrName) {
  12481. node.attr(attrName, value2);
  12482. });
  12483. }
  12484. return node;
  12485. };
  12486. AstNode2.prototype.replace = function(node) {
  12487. var self2 = this;
  12488. if (node.parent) {
  12489. node.remove();
  12490. }
  12491. self2.insert(node, self2);
  12492. self2.remove();
  12493. return self2;
  12494. };
  12495. AstNode2.prototype.attr = function(name2, value2) {
  12496. var self2 = this;
  12497. var attrs;
  12498. if (typeof name2 !== "string") {
  12499. if (name2 !== void 0 && name2 !== null) {
  12500. each$j(name2, function(value3, key) {
  12501. self2.attr(key, value3);
  12502. });
  12503. }
  12504. return self2;
  12505. }
  12506. if (attrs = self2.attributes) {
  12507. if (value2 !== void 0) {
  12508. if (value2 === null) {
  12509. if (name2 in attrs.map) {
  12510. delete attrs.map[name2];
  12511. var i = attrs.length;
  12512. while (i--) {
  12513. if (attrs[i].name === name2) {
  12514. attrs.splice(i, 1);
  12515. return self2;
  12516. }
  12517. }
  12518. }
  12519. return self2;
  12520. }
  12521. if (name2 in attrs.map) {
  12522. var i = attrs.length;
  12523. while (i--) {
  12524. if (attrs[i].name === name2) {
  12525. attrs[i].value = value2;
  12526. break;
  12527. }
  12528. }
  12529. } else {
  12530. attrs.push({
  12531. name: name2,
  12532. value: value2
  12533. });
  12534. }
  12535. attrs.map[name2] = value2;
  12536. return self2;
  12537. }
  12538. return attrs.map[name2];
  12539. }
  12540. };
  12541. AstNode2.prototype.clone = function() {
  12542. var self2 = this;
  12543. var clone2 = new AstNode2(self2.name, self2.type);
  12544. var selfAttrs;
  12545. if (selfAttrs = self2.attributes) {
  12546. var cloneAttrs = [];
  12547. cloneAttrs.map = {};
  12548. for (var i = 0, l = selfAttrs.length; i < l; i++) {
  12549. var selfAttr = selfAttrs[i];
  12550. if (selfAttr.name !== "id") {
  12551. cloneAttrs[cloneAttrs.length] = {
  12552. name: selfAttr.name,
  12553. value: selfAttr.value
  12554. };
  12555. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  12556. }
  12557. }
  12558. clone2.attributes = cloneAttrs;
  12559. }
  12560. clone2.value = self2.value;
  12561. clone2.shortEnded = self2.shortEnded;
  12562. return clone2;
  12563. };
  12564. AstNode2.prototype.wrap = function(wrapper) {
  12565. var self2 = this;
  12566. self2.parent.insert(wrapper, self2);
  12567. wrapper.append(self2);
  12568. return self2;
  12569. };
  12570. AstNode2.prototype.unwrap = function() {
  12571. var self2 = this;
  12572. for (var node = self2.firstChild; node; ) {
  12573. var next = node.next;
  12574. self2.insert(node, self2, true);
  12575. node = next;
  12576. }
  12577. self2.remove();
  12578. };
  12579. AstNode2.prototype.remove = function() {
  12580. var self2 = this, parent2 = self2.parent, next = self2.next, prev = self2.prev;
  12581. if (parent2) {
  12582. if (parent2.firstChild === self2) {
  12583. parent2.firstChild = next;
  12584. if (next) {
  12585. next.prev = null;
  12586. }
  12587. } else {
  12588. prev.next = next;
  12589. }
  12590. if (parent2.lastChild === self2) {
  12591. parent2.lastChild = prev;
  12592. if (prev) {
  12593. prev.next = null;
  12594. }
  12595. } else {
  12596. next.prev = prev;
  12597. }
  12598. self2.parent = self2.next = self2.prev = null;
  12599. }
  12600. return self2;
  12601. };
  12602. AstNode2.prototype.append = function(node) {
  12603. var self2 = this;
  12604. if (node.parent) {
  12605. node.remove();
  12606. }
  12607. var last2 = self2.lastChild;
  12608. if (last2) {
  12609. last2.next = node;
  12610. node.prev = last2;
  12611. self2.lastChild = node;
  12612. } else {
  12613. self2.lastChild = self2.firstChild = node;
  12614. }
  12615. node.parent = self2;
  12616. return node;
  12617. };
  12618. AstNode2.prototype.insert = function(node, refNode, before2) {
  12619. if (node.parent) {
  12620. node.remove();
  12621. }
  12622. var parent2 = refNode.parent || this;
  12623. if (before2) {
  12624. if (refNode === parent2.firstChild) {
  12625. parent2.firstChild = node;
  12626. } else {
  12627. refNode.prev.next = node;
  12628. }
  12629. node.prev = refNode.prev;
  12630. node.next = refNode;
  12631. refNode.prev = node;
  12632. } else {
  12633. if (refNode === parent2.lastChild) {
  12634. parent2.lastChild = node;
  12635. } else {
  12636. refNode.next.prev = node;
  12637. }
  12638. node.next = refNode.next;
  12639. node.prev = refNode;
  12640. refNode.next = node;
  12641. }
  12642. node.parent = parent2;
  12643. return node;
  12644. };
  12645. AstNode2.prototype.getAll = function(name2) {
  12646. var self2 = this;
  12647. var collection = [];
  12648. for (var node = self2.firstChild; node; node = walk$1(node, self2)) {
  12649. if (node.name === name2) {
  12650. collection.push(node);
  12651. }
  12652. }
  12653. return collection;
  12654. };
  12655. AstNode2.prototype.children = function() {
  12656. var self2 = this;
  12657. var collection = [];
  12658. for (var node = self2.firstChild; node; node = node.next) {
  12659. collection.push(node);
  12660. }
  12661. return collection;
  12662. };
  12663. AstNode2.prototype.empty = function() {
  12664. var self2 = this;
  12665. if (self2.firstChild) {
  12666. var nodes = [];
  12667. for (var node = self2.firstChild; node; node = walk$1(node, self2)) {
  12668. nodes.push(node);
  12669. }
  12670. var i = nodes.length;
  12671. while (i--) {
  12672. var node = nodes[i];
  12673. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  12674. }
  12675. }
  12676. self2.firstChild = self2.lastChild = null;
  12677. return self2;
  12678. };
  12679. AstNode2.prototype.isEmpty = function(elements, whitespace2, predicate) {
  12680. if (whitespace2 === void 0) {
  12681. whitespace2 = {};
  12682. }
  12683. var self2 = this;
  12684. var node = self2.firstChild;
  12685. if (isNonEmptyElement(self2)) {
  12686. return false;
  12687. }
  12688. if (node) {
  12689. do {
  12690. if (node.type === 1) {
  12691. if (node.attr("data-mce-bogus")) {
  12692. continue;
  12693. }
  12694. if (elements[node.name]) {
  12695. return false;
  12696. }
  12697. if (isNonEmptyElement(node)) {
  12698. return false;
  12699. }
  12700. }
  12701. if (node.type === 8) {
  12702. return false;
  12703. }
  12704. if (node.type === 3 && !isEmptyTextNode(node)) {
  12705. return false;
  12706. }
  12707. if (node.type === 3 && node.parent && whitespace2[node.parent.name] && isWhitespaceText(node.value)) {
  12708. return false;
  12709. }
  12710. if (predicate && predicate(node)) {
  12711. return false;
  12712. }
  12713. } while (node = walk$1(node, self2));
  12714. }
  12715. return true;
  12716. };
  12717. AstNode2.prototype.walk = function(prev) {
  12718. return walk$1(this, null, prev);
  12719. };
  12720. return AstNode2;
  12721. }();
  12722. var extractBase64DataUris = function(html) {
  12723. var dataImageUri = /data:[^;<"'\s]+;base64,([a-z0-9\+\/=\s]+)/gi;
  12724. var chunks = [];
  12725. var uris = {};
  12726. var prefix = generate("img");
  12727. var matches2;
  12728. var index = 0;
  12729. var count2 = 0;
  12730. while (matches2 = dataImageUri.exec(html)) {
  12731. var uri = matches2[0];
  12732. var imageId = prefix + "_" + count2++;
  12733. uris[imageId] = uri;
  12734. if (index < matches2.index) {
  12735. chunks.push(html.substr(index, matches2.index - index));
  12736. }
  12737. chunks.push(imageId);
  12738. index = matches2.index + uri.length;
  12739. }
  12740. var re = new RegExp(prefix + "_[0-9]+", "g");
  12741. if (index === 0) {
  12742. return {
  12743. prefix,
  12744. uris,
  12745. html,
  12746. re
  12747. };
  12748. } else {
  12749. if (index < html.length) {
  12750. chunks.push(html.substr(index));
  12751. }
  12752. return {
  12753. prefix,
  12754. uris,
  12755. html: chunks.join(""),
  12756. re
  12757. };
  12758. }
  12759. };
  12760. var restoreDataUris = function(html, result) {
  12761. return html.replace(result.re, function(imageId) {
  12762. return get$9(result.uris, imageId).getOr(imageId);
  12763. });
  12764. };
  12765. var parseDataUri$1 = function(uri) {
  12766. var matches2 = /data:([^;]+);base64,([a-z0-9\+\/=\s]+)/i.exec(uri);
  12767. if (matches2) {
  12768. return Optional.some({
  12769. type: matches2[1],
  12770. data: decodeURIComponent(matches2[2])
  12771. });
  12772. } else {
  12773. return Optional.none();
  12774. }
  12775. };
  12776. var each$d = Tools.each, trim = Tools.trim;
  12777. var queryParts = "source protocol authority userInfo user password host port relative path directory file query anchor".split(" ");
  12778. var DEFAULT_PORTS = {
  12779. ftp: 21,
  12780. http: 80,
  12781. https: 443,
  12782. mailto: 25
  12783. };
  12784. var safeSvgDataUrlElements = [
  12785. "img",
  12786. "video"
  12787. ];
  12788. var blockSvgDataUris = function(allowSvgDataUrls, tagName) {
  12789. if (isNonNullable(allowSvgDataUrls)) {
  12790. return !allowSvgDataUrls;
  12791. } else {
  12792. return isNonNullable(tagName) ? !contains$3(safeSvgDataUrlElements, tagName) : true;
  12793. }
  12794. };
  12795. var isInvalidUri = function(settings, uri, tagName) {
  12796. if (settings.allow_html_data_urls) {
  12797. return false;
  12798. } else if (/^data:image\//i.test(uri)) {
  12799. return blockSvgDataUris(settings.allow_svg_data_urls, tagName) && /^data:image\/svg\+xml/i.test(uri);
  12800. } else {
  12801. return /^data:/i.test(uri);
  12802. }
  12803. };
  12804. var URI = function() {
  12805. function URI2(url, settings) {
  12806. url = trim(url);
  12807. this.settings = settings || {};
  12808. var baseUri = this.settings.base_uri;
  12809. var self2 = this;
  12810. if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
  12811. self2.source = url;
  12812. return;
  12813. }
  12814. var isProtocolRelative = url.indexOf("//") === 0;
  12815. if (url.indexOf("/") === 0 && !isProtocolRelative) {
  12816. url = (baseUri ? baseUri.protocol || "http" : "http") + "://mce_host" + url;
  12817. }
  12818. if (!/^[\w\-]*:?\/\//.test(url)) {
  12819. var baseUrl = this.settings.base_uri ? this.settings.base_uri.path : new URI2(document.location.href).directory;
  12820. if (this.settings.base_uri && this.settings.base_uri.protocol == "") {
  12821. url = "//mce_host" + self2.toAbsPath(baseUrl, url);
  12822. } else {
  12823. var match2 = /([^#?]*)([#?]?.*)/.exec(url);
  12824. url = (baseUri && baseUri.protocol || "http") + "://mce_host" + self2.toAbsPath(baseUrl, match2[1]) + match2[2];
  12825. }
  12826. }
  12827. url = url.replace(/@@/g, "(mce_at)");
  12828. var urlMatch = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?(\[[a-zA-Z0-9:.%]+\]|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
  12829. each$d(queryParts, function(v, i) {
  12830. var part = urlMatch[i];
  12831. if (part) {
  12832. part = part.replace(/\(mce_at\)/g, "@@");
  12833. }
  12834. self2[v] = part;
  12835. });
  12836. if (baseUri) {
  12837. if (!self2.protocol) {
  12838. self2.protocol = baseUri.protocol;
  12839. }
  12840. if (!self2.userInfo) {
  12841. self2.userInfo = baseUri.userInfo;
  12842. }
  12843. if (!self2.port && self2.host === "mce_host") {
  12844. self2.port = baseUri.port;
  12845. }
  12846. if (!self2.host || self2.host === "mce_host") {
  12847. self2.host = baseUri.host;
  12848. }
  12849. self2.source = "";
  12850. }
  12851. if (isProtocolRelative) {
  12852. self2.protocol = "";
  12853. }
  12854. }
  12855. URI2.parseDataUri = function(uri) {
  12856. var type2;
  12857. var uriComponents = decodeURIComponent(uri).split(",");
  12858. var matches2 = /data:([^;]+)/.exec(uriComponents[0]);
  12859. if (matches2) {
  12860. type2 = matches2[1];
  12861. }
  12862. return {
  12863. type: type2,
  12864. data: uriComponents[1]
  12865. };
  12866. };
  12867. URI2.isDomSafe = function(uri, context2, options) {
  12868. if (options === void 0) {
  12869. options = {};
  12870. }
  12871. if (options.allow_script_urls) {
  12872. return true;
  12873. } else {
  12874. var decodedUri = Entities.decode(uri).replace(/[\s\u0000-\u001F]+/g, "");
  12875. try {
  12876. decodedUri = decodeURIComponent(decodedUri);
  12877. } catch (ex) {
  12878. decodedUri = unescape(decodedUri);
  12879. }
  12880. if (/((java|vb)script|mhtml):/i.test(decodedUri)) {
  12881. return false;
  12882. }
  12883. return !isInvalidUri(options, decodedUri, context2);
  12884. }
  12885. };
  12886. URI2.getDocumentBaseUrl = function(loc) {
  12887. var baseUrl;
  12888. if (loc.protocol.indexOf("http") !== 0 && loc.protocol !== "file:") {
  12889. baseUrl = loc.href;
  12890. } else {
  12891. baseUrl = loc.protocol + "//" + loc.host + loc.pathname;
  12892. }
  12893. if (/^[^:]+:\/\/\/?[^\/]+\//.test(baseUrl)) {
  12894. baseUrl = baseUrl.replace(/[\?#].*$/, "").replace(/[\/\\][^\/]+$/, "");
  12895. if (!/[\/\\]$/.test(baseUrl)) {
  12896. baseUrl += "/";
  12897. }
  12898. }
  12899. return baseUrl;
  12900. };
  12901. URI2.prototype.setPath = function(path) {
  12902. var pathMatch = /^(.*?)\/?(\w+)?$/.exec(path);
  12903. this.path = pathMatch[0];
  12904. this.directory = pathMatch[1];
  12905. this.file = pathMatch[2];
  12906. this.source = "";
  12907. this.getURI();
  12908. };
  12909. URI2.prototype.toRelative = function(uri) {
  12910. var output;
  12911. if (uri === "./") {
  12912. return uri;
  12913. }
  12914. var relativeUri = new URI2(uri, { base_uri: this });
  12915. if (relativeUri.host !== "mce_host" && this.host !== relativeUri.host && relativeUri.host || this.port !== relativeUri.port || this.protocol !== relativeUri.protocol && relativeUri.protocol !== "") {
  12916. return relativeUri.getURI();
  12917. }
  12918. var tu = this.getURI(), uu = relativeUri.getURI();
  12919. if (tu === uu || tu.charAt(tu.length - 1) === "/" && tu.substr(0, tu.length - 1) === uu) {
  12920. return tu;
  12921. }
  12922. output = this.toRelPath(this.path, relativeUri.path);
  12923. if (relativeUri.query) {
  12924. output += "?" + relativeUri.query;
  12925. }
  12926. if (relativeUri.anchor) {
  12927. output += "#" + relativeUri.anchor;
  12928. }
  12929. return output;
  12930. };
  12931. URI2.prototype.toAbsolute = function(uri, noHost) {
  12932. var absoluteUri = new URI2(uri, { base_uri: this });
  12933. return absoluteUri.getURI(noHost && this.isSameOrigin(absoluteUri));
  12934. };
  12935. URI2.prototype.isSameOrigin = function(uri) {
  12936. if (this.host == uri.host && this.protocol == uri.protocol) {
  12937. if (this.port == uri.port) {
  12938. return true;
  12939. }
  12940. var defaultPort = DEFAULT_PORTS[this.protocol];
  12941. if (defaultPort && (this.port || defaultPort) == (uri.port || defaultPort)) {
  12942. return true;
  12943. }
  12944. }
  12945. return false;
  12946. };
  12947. URI2.prototype.toRelPath = function(base, path) {
  12948. var breakPoint = 0, out = "", i, l;
  12949. var normalizedBase = base.substring(0, base.lastIndexOf("/")).split("/");
  12950. var items = path.split("/");
  12951. if (normalizedBase.length >= items.length) {
  12952. for (i = 0, l = normalizedBase.length; i < l; i++) {
  12953. if (i >= items.length || normalizedBase[i] !== items[i]) {
  12954. breakPoint = i + 1;
  12955. break;
  12956. }
  12957. }
  12958. }
  12959. if (normalizedBase.length < items.length) {
  12960. for (i = 0, l = items.length; i < l; i++) {
  12961. if (i >= normalizedBase.length || normalizedBase[i] !== items[i]) {
  12962. breakPoint = i + 1;
  12963. break;
  12964. }
  12965. }
  12966. }
  12967. if (breakPoint === 1) {
  12968. return path;
  12969. }
  12970. for (i = 0, l = normalizedBase.length - (breakPoint - 1); i < l; i++) {
  12971. out += "../";
  12972. }
  12973. for (i = breakPoint - 1, l = items.length; i < l; i++) {
  12974. if (i !== breakPoint - 1) {
  12975. out += "/" + items[i];
  12976. } else {
  12977. out += items[i];
  12978. }
  12979. }
  12980. return out;
  12981. };
  12982. URI2.prototype.toAbsPath = function(base, path) {
  12983. var i, nb = 0, o = [], outPath;
  12984. var tr = /\/$/.test(path) ? "/" : "";
  12985. var normalizedBase = base.split("/");
  12986. var normalizedPath = path.split("/");
  12987. each$d(normalizedBase, function(k) {
  12988. if (k) {
  12989. o.push(k);
  12990. }
  12991. });
  12992. normalizedBase = o;
  12993. for (i = normalizedPath.length - 1, o = []; i >= 0; i--) {
  12994. if (normalizedPath[i].length === 0 || normalizedPath[i] === ".") {
  12995. continue;
  12996. }
  12997. if (normalizedPath[i] === "..") {
  12998. nb++;
  12999. continue;
  13000. }
  13001. if (nb > 0) {
  13002. nb--;
  13003. continue;
  13004. }
  13005. o.push(normalizedPath[i]);
  13006. }
  13007. i = normalizedBase.length - nb;
  13008. if (i <= 0) {
  13009. outPath = reverse(o).join("/");
  13010. } else {
  13011. outPath = normalizedBase.slice(0, i).join("/") + "/" + reverse(o).join("/");
  13012. }
  13013. if (outPath.indexOf("/") !== 0) {
  13014. outPath = "/" + outPath;
  13015. }
  13016. if (tr && outPath.lastIndexOf("/") !== outPath.length - 1) {
  13017. outPath += tr;
  13018. }
  13019. return outPath;
  13020. };
  13021. URI2.prototype.getURI = function(noProtoHost) {
  13022. if (noProtoHost === void 0) {
  13023. noProtoHost = false;
  13024. }
  13025. var s;
  13026. if (!this.source || noProtoHost) {
  13027. s = "";
  13028. if (!noProtoHost) {
  13029. if (this.protocol) {
  13030. s += this.protocol + "://";
  13031. } else {
  13032. s += "//";
  13033. }
  13034. if (this.userInfo) {
  13035. s += this.userInfo + "@";
  13036. }
  13037. if (this.host) {
  13038. s += this.host;
  13039. }
  13040. if (this.port) {
  13041. s += ":" + this.port;
  13042. }
  13043. }
  13044. if (this.path) {
  13045. s += this.path;
  13046. }
  13047. if (this.query) {
  13048. s += "?" + this.query;
  13049. }
  13050. if (this.anchor) {
  13051. s += "#" + this.anchor;
  13052. }
  13053. this.source = s;
  13054. }
  13055. return this.source;
  13056. };
  13057. return URI2;
  13058. }();
  13059. var filteredClobberElements = Tools.makeMap("button,fieldset,form,iframe,img,image,input,object,output,select,textarea");
  13060. var isValidPrefixAttrName = function(name2) {
  13061. return name2.indexOf("data-") === 0 || name2.indexOf("aria-") === 0;
  13062. };
  13063. var findMatchingEndTagIndex = function(schema, html, startIndex) {
  13064. var startTagRegExp = /<([!?\/])?([A-Za-z0-9\-_:.]+)/g;
  13065. var endTagRegExp = /(?:\s(?:[^'">]+(?:"[^"]*"|'[^']*'))*[^"'>]*(?:"[^">]*|'[^'>]*)?|\s*|\/)>/g;
  13066. var shortEndedElements = schema.getShortEndedElements();
  13067. var count2 = 1, index = startIndex;
  13068. while (count2 !== 0) {
  13069. startTagRegExp.lastIndex = index;
  13070. while (true) {
  13071. var startMatch = startTagRegExp.exec(html);
  13072. if (startMatch === null) {
  13073. return index;
  13074. } else if (startMatch[1] === "!") {
  13075. if (startsWith(startMatch[2], "--")) {
  13076. index = findCommentEndIndex(html, false, startMatch.index + "!--".length);
  13077. } else {
  13078. index = findCommentEndIndex(html, true, startMatch.index + 1);
  13079. }
  13080. break;
  13081. } else {
  13082. endTagRegExp.lastIndex = startTagRegExp.lastIndex;
  13083. var endMatch = endTagRegExp.exec(html);
  13084. if (isNull(endMatch) || endMatch.index !== startTagRegExp.lastIndex) {
  13085. continue;
  13086. }
  13087. if (startMatch[1] === "/") {
  13088. count2 -= 1;
  13089. } else if (!has$2(shortEndedElements, startMatch[2])) {
  13090. count2 += 1;
  13091. }
  13092. index = startTagRegExp.lastIndex + endMatch[0].length;
  13093. break;
  13094. }
  13095. }
  13096. }
  13097. return index;
  13098. };
  13099. var isConditionalComment = function(html, startIndex) {
  13100. return /^\s*\[if [\w\W]+\]>.*<!\[endif\](--!?)?>/.test(html.substr(startIndex));
  13101. };
  13102. var findCommentEndIndex = function(html, isBogus2, startIndex) {
  13103. if (startIndex === void 0) {
  13104. startIndex = 0;
  13105. }
  13106. var lcHtml = html.toLowerCase();
  13107. if (lcHtml.indexOf("[if ", startIndex) !== -1 && isConditionalComment(lcHtml, startIndex)) {
  13108. var endIfIndex = lcHtml.indexOf("[endif]", startIndex);
  13109. return lcHtml.indexOf(">", endIfIndex);
  13110. } else {
  13111. if (isBogus2) {
  13112. var endIndex = lcHtml.indexOf(">", startIndex);
  13113. return endIndex !== -1 ? endIndex : lcHtml.length;
  13114. } else {
  13115. var endCommentRegexp = /--!?>/g;
  13116. endCommentRegexp.lastIndex = startIndex;
  13117. var match2 = endCommentRegexp.exec(html);
  13118. return match2 ? match2.index + match2[0].length : lcHtml.length;
  13119. }
  13120. }
  13121. };
  13122. var checkBogusAttribute = function(regExp, attrString) {
  13123. var matches2 = regExp.exec(attrString);
  13124. if (matches2) {
  13125. var name_1 = matches2[1];
  13126. var value2 = matches2[2];
  13127. return typeof name_1 === "string" && name_1.toLowerCase() === "data-mce-bogus" ? value2 : null;
  13128. } else {
  13129. return null;
  13130. }
  13131. };
  13132. var SaxParser = function(settings, schema) {
  13133. var _a;
  13134. if (schema === void 0) {
  13135. schema = Schema();
  13136. }
  13137. settings = settings || {};
  13138. var doc2 = (_a = settings.document) !== null && _a !== void 0 ? _a : document;
  13139. var form = doc2.createElement("form");
  13140. if (settings.fix_self_closing !== false) {
  13141. settings.fix_self_closing = true;
  13142. }
  13143. var comment = settings.comment ? settings.comment : noop;
  13144. var cdata = settings.cdata ? settings.cdata : noop;
  13145. var text = settings.text ? settings.text : noop;
  13146. var start2 = settings.start ? settings.start : noop;
  13147. var end2 = settings.end ? settings.end : noop;
  13148. var pi = settings.pi ? settings.pi : noop;
  13149. var doctype = settings.doctype ? settings.doctype : noop;
  13150. var parseInternal = function(base64Extract, format) {
  13151. if (format === void 0) {
  13152. format = "html";
  13153. }
  13154. var html = base64Extract.html;
  13155. var matches2, index = 0, value2, endRegExp;
  13156. var stack = [];
  13157. var attrList, i, textData, name2;
  13158. var isInternalElement, isShortEnded;
  13159. var elementRule, isValidElement, attr, attribsValue, validAttributesMap, validAttributePatterns;
  13160. var attributesRequired, attributesDefault, attributesForced;
  13161. var anyAttributesRequired, attrValue, idCount = 0;
  13162. var decode2 = Entities.decode;
  13163. var filteredUrlAttrs = Tools.makeMap("src,href,data,background,action,formaction,poster,xlink:href");
  13164. var parsingMode = format === "html" ? 0 : 1;
  13165. var processEndTag = function(name3) {
  13166. var pos, i2;
  13167. pos = stack.length;
  13168. while (pos--) {
  13169. if (stack[pos].name === name3) {
  13170. break;
  13171. }
  13172. }
  13173. if (pos >= 0) {
  13174. for (i2 = stack.length - 1; i2 >= pos; i2--) {
  13175. name3 = stack[i2];
  13176. if (name3.valid) {
  13177. end2(name3.name);
  13178. }
  13179. }
  13180. stack.length = pos;
  13181. }
  13182. };
  13183. var processText = function(value3, raw) {
  13184. return text(restoreDataUris(value3, base64Extract), raw);
  13185. };
  13186. var processComment = function(value3) {
  13187. if (value3 === "") {
  13188. return;
  13189. }
  13190. if (value3.charAt(0) === ">") {
  13191. value3 = " " + value3;
  13192. }
  13193. if (!settings.allow_conditional_comments && value3.substr(0, 3).toLowerCase() === "[if") {
  13194. value3 = " " + value3;
  13195. }
  13196. comment(restoreDataUris(value3, base64Extract));
  13197. };
  13198. var processAttr = function(value3) {
  13199. return restoreDataUris(value3, base64Extract);
  13200. };
  13201. var processMalformedComment = function(value3, startIndex) {
  13202. var startTag = value3 || "";
  13203. var isBogus2 = !startsWith(startTag, "--");
  13204. var endIndex = findCommentEndIndex(html, isBogus2, startIndex);
  13205. value3 = html.substr(startIndex, endIndex - startIndex);
  13206. processComment(isBogus2 ? startTag + value3 : value3);
  13207. return endIndex + 1;
  13208. };
  13209. var parseAttribute = function(tagName, name3, value3, val2, val3) {
  13210. name3 = name3.toLowerCase();
  13211. value3 = processAttr(name3 in fillAttrsMap ? name3 : decode2(value3 || val2 || val3 || ""));
  13212. if (validate2 && !isInternalElement && isValidPrefixAttrName(name3) === false) {
  13213. var attrRule = validAttributesMap[name3];
  13214. if (!attrRule && validAttributePatterns) {
  13215. var i_1 = validAttributePatterns.length;
  13216. while (i_1--) {
  13217. attrRule = validAttributePatterns[i_1];
  13218. if (attrRule.pattern.test(name3)) {
  13219. break;
  13220. }
  13221. }
  13222. if (i_1 === -1) {
  13223. attrRule = null;
  13224. }
  13225. }
  13226. if (!attrRule) {
  13227. return;
  13228. }
  13229. if (attrRule.validValues && !(value3 in attrRule.validValues)) {
  13230. return;
  13231. }
  13232. }
  13233. var isNameOrId = name3 === "name" || name3 === "id";
  13234. if (isNameOrId && tagName in filteredClobberElements && (value3 in doc2 || value3 in form)) {
  13235. return;
  13236. }
  13237. if (filteredUrlAttrs[name3] && !URI.isDomSafe(value3, tagName, settings)) {
  13238. return;
  13239. }
  13240. if (isInternalElement && (name3 in filteredUrlAttrs || name3.indexOf("on") === 0)) {
  13241. return;
  13242. }
  13243. attrList.map[name3] = value3;
  13244. attrList.push({
  13245. name: name3,
  13246. value: value3
  13247. });
  13248. };
  13249. var tokenRegExp = new RegExp(`<(?:(?:!--([\\w\\W]*?)--!?>)|(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|(?:![Dd][Oo][Cc][Tt][Yy][Pp][Ee]([\\w\\W]*?)>)|(?:!(--)?)|(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|(?:\\/([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)>)|(?:([A-Za-z][A-Za-z0-9\\-_:.]*)(\\s(?:[^'">]+(?:"[^"]*"|'[^']*'))*[^"'>]*(?:"[^">]*|'[^'>]*)?|\\s*|\\/)>))`, "g");
  13250. var attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
  13251. var shortEndedElements = schema.getShortEndedElements();
  13252. var selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  13253. var fillAttrsMap = schema.getBoolAttrs();
  13254. var validate2 = settings.validate;
  13255. var removeInternalElements = settings.remove_internals;
  13256. var fixSelfClosing = settings.fix_self_closing;
  13257. var specialElements = schema.getSpecialElements();
  13258. var processHtml = html + ">";
  13259. while (matches2 = tokenRegExp.exec(processHtml)) {
  13260. var matchText = matches2[0];
  13261. if (index < matches2.index) {
  13262. processText(decode2(html.substr(index, matches2.index - index)));
  13263. }
  13264. if (value2 = matches2[7]) {
  13265. value2 = value2.toLowerCase();
  13266. if (value2.charAt(0) === ":") {
  13267. value2 = value2.substr(1);
  13268. }
  13269. processEndTag(value2);
  13270. } else if (value2 = matches2[8]) {
  13271. if (matches2.index + matchText.length > html.length) {
  13272. processText(decode2(html.substr(matches2.index)));
  13273. index = matches2.index + matchText.length;
  13274. continue;
  13275. }
  13276. value2 = value2.toLowerCase();
  13277. if (value2.charAt(0) === ":") {
  13278. value2 = value2.substr(1);
  13279. }
  13280. isShortEnded = value2 in shortEndedElements;
  13281. if (fixSelfClosing && selfClosing[value2] && stack.length > 0 && stack[stack.length - 1].name === value2) {
  13282. processEndTag(value2);
  13283. }
  13284. var bogusValue = checkBogusAttribute(attrRegExp, matches2[9]);
  13285. if (bogusValue !== null) {
  13286. if (bogusValue === "all") {
  13287. index = findMatchingEndTagIndex(schema, html, tokenRegExp.lastIndex);
  13288. tokenRegExp.lastIndex = index;
  13289. continue;
  13290. }
  13291. isValidElement = false;
  13292. }
  13293. if (!validate2 || (elementRule = schema.getElementRule(value2))) {
  13294. isValidElement = true;
  13295. if (validate2) {
  13296. validAttributesMap = elementRule.attributes;
  13297. validAttributePatterns = elementRule.attributePatterns;
  13298. }
  13299. if (attribsValue = matches2[9]) {
  13300. isInternalElement = attribsValue.indexOf("data-mce-type") !== -1;
  13301. if (isInternalElement && removeInternalElements) {
  13302. isValidElement = false;
  13303. }
  13304. attrList = [];
  13305. attrList.map = {};
  13306. attribsValue.replace(attrRegExp, function(match2, name3, val, val2, val3) {
  13307. parseAttribute(value2, name3, val, val2, val3);
  13308. return "";
  13309. });
  13310. } else {
  13311. attrList = [];
  13312. attrList.map = {};
  13313. }
  13314. if (validate2 && !isInternalElement) {
  13315. attributesRequired = elementRule.attributesRequired;
  13316. attributesDefault = elementRule.attributesDefault;
  13317. attributesForced = elementRule.attributesForced;
  13318. anyAttributesRequired = elementRule.removeEmptyAttrs;
  13319. if (anyAttributesRequired && !attrList.length) {
  13320. isValidElement = false;
  13321. }
  13322. if (attributesForced) {
  13323. i = attributesForced.length;
  13324. while (i--) {
  13325. attr = attributesForced[i];
  13326. name2 = attr.name;
  13327. attrValue = attr.value;
  13328. if (attrValue === "{$uid}") {
  13329. attrValue = "mce_" + idCount++;
  13330. }
  13331. attrList.map[name2] = attrValue;
  13332. attrList.push({
  13333. name: name2,
  13334. value: attrValue
  13335. });
  13336. }
  13337. }
  13338. if (attributesDefault) {
  13339. i = attributesDefault.length;
  13340. while (i--) {
  13341. attr = attributesDefault[i];
  13342. name2 = attr.name;
  13343. if (!(name2 in attrList.map)) {
  13344. attrValue = attr.value;
  13345. if (attrValue === "{$uid}") {
  13346. attrValue = "mce_" + idCount++;
  13347. }
  13348. attrList.map[name2] = attrValue;
  13349. attrList.push({
  13350. name: name2,
  13351. value: attrValue
  13352. });
  13353. }
  13354. }
  13355. }
  13356. if (attributesRequired) {
  13357. i = attributesRequired.length;
  13358. while (i--) {
  13359. if (attributesRequired[i] in attrList.map) {
  13360. break;
  13361. }
  13362. }
  13363. if (i === -1) {
  13364. isValidElement = false;
  13365. }
  13366. }
  13367. if (attr = attrList.map["data-mce-bogus"]) {
  13368. if (attr === "all") {
  13369. index = findMatchingEndTagIndex(schema, html, tokenRegExp.lastIndex);
  13370. tokenRegExp.lastIndex = index;
  13371. continue;
  13372. }
  13373. isValidElement = false;
  13374. }
  13375. }
  13376. if (isValidElement) {
  13377. start2(value2, attrList, isShortEnded);
  13378. }
  13379. } else {
  13380. isValidElement = false;
  13381. }
  13382. if (endRegExp = specialElements[value2]) {
  13383. endRegExp.lastIndex = index = matches2.index + matchText.length;
  13384. if (matches2 = endRegExp.exec(html)) {
  13385. if (isValidElement) {
  13386. textData = html.substr(index, matches2.index - index);
  13387. }
  13388. index = matches2.index + matches2[0].length;
  13389. } else {
  13390. textData = html.substr(index);
  13391. index = html.length;
  13392. }
  13393. if (isValidElement) {
  13394. if (textData.length > 0) {
  13395. processText(textData, true);
  13396. }
  13397. end2(value2);
  13398. }
  13399. tokenRegExp.lastIndex = index;
  13400. continue;
  13401. }
  13402. if (!isShortEnded) {
  13403. if (!attribsValue || attribsValue.indexOf("/") !== attribsValue.length - 1) {
  13404. stack.push({
  13405. name: value2,
  13406. valid: isValidElement
  13407. });
  13408. } else if (isValidElement) {
  13409. end2(value2);
  13410. }
  13411. }
  13412. } else if (value2 = matches2[1]) {
  13413. processComment(value2);
  13414. } else if (value2 = matches2[2]) {
  13415. var isValidCdataSection = parsingMode === 1 || settings.preserve_cdata || stack.length > 0 && schema.isValidChild(stack[stack.length - 1].name, "#cdata");
  13416. if (isValidCdataSection) {
  13417. cdata(value2);
  13418. } else {
  13419. index = processMalformedComment("", matches2.index + 2);
  13420. tokenRegExp.lastIndex = index;
  13421. continue;
  13422. }
  13423. } else if (value2 = matches2[3]) {
  13424. doctype(value2);
  13425. } else if ((value2 = matches2[4]) || matchText === "<!") {
  13426. index = processMalformedComment(value2, matches2.index + matchText.length);
  13427. tokenRegExp.lastIndex = index;
  13428. continue;
  13429. } else if (value2 = matches2[5]) {
  13430. if (parsingMode === 1) {
  13431. pi(value2, matches2[6]);
  13432. } else {
  13433. index = processMalformedComment("?", matches2.index + 2);
  13434. tokenRegExp.lastIndex = index;
  13435. continue;
  13436. }
  13437. }
  13438. index = matches2.index + matchText.length;
  13439. }
  13440. if (index < html.length) {
  13441. processText(decode2(html.substr(index)));
  13442. }
  13443. for (i = stack.length - 1; i >= 0; i--) {
  13444. value2 = stack[i];
  13445. if (value2.valid) {
  13446. end2(value2.name);
  13447. }
  13448. }
  13449. };
  13450. var parse = function(html, format) {
  13451. if (format === void 0) {
  13452. format = "html";
  13453. }
  13454. parseInternal(extractBase64DataUris(html), format);
  13455. };
  13456. return { parse };
  13457. };
  13458. SaxParser.findEndTag = findMatchingEndTagIndex;
  13459. var trimHtml = function(tempAttrs, html) {
  13460. var trimContentRegExp = new RegExp(["\\s?(" + tempAttrs.join("|") + ')="[^"]+"'].join("|"), "gi");
  13461. return html.replace(trimContentRegExp, "");
  13462. };
  13463. var trimInternal = function(serializer, html) {
  13464. var bogusAllRegExp = /<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g;
  13465. var schema = serializer.schema;
  13466. var content = trimHtml(serializer.getTempAttrs(), html);
  13467. var shortEndedElements = schema.getShortEndedElements();
  13468. var matches2;
  13469. while (matches2 = bogusAllRegExp.exec(content)) {
  13470. var index = bogusAllRegExp.lastIndex;
  13471. var matchLength = matches2[0].length;
  13472. var endTagIndex = void 0;
  13473. if (shortEndedElements[matches2[1]]) {
  13474. endTagIndex = index;
  13475. } else {
  13476. endTagIndex = SaxParser.findEndTag(schema, content, index);
  13477. }
  13478. content = content.substring(0, index - matchLength) + content.substring(endTagIndex);
  13479. bogusAllRegExp.lastIndex = index - matchLength;
  13480. }
  13481. return trim$2(content);
  13482. };
  13483. var trimExternal = trimInternal;
  13484. var trimEmptyContents = function(editor, html) {
  13485. var blockName = getForcedRootBlock(editor);
  13486. var emptyRegExp = new RegExp("^(<" + blockName + "[^>]*>(&nbsp;|&#160;|\\s|\xA0|<br \\/>|)<\\/" + blockName + ">[\r\n]*|<br \\/>[\r\n]*)$");
  13487. return html.replace(emptyRegExp, "");
  13488. };
  13489. var setupArgs$3 = function(args, format) {
  13490. return __assign(__assign({}, args), {
  13491. format,
  13492. get: true,
  13493. getInner: true
  13494. });
  13495. };
  13496. var getContentFromBody = function(editor, args, format, body) {
  13497. var defaultedArgs = setupArgs$3(args, format);
  13498. var updatedArgs = args.no_events ? defaultedArgs : editor.fire("BeforeGetContent", defaultedArgs);
  13499. var content;
  13500. if (updatedArgs.format === "raw") {
  13501. content = Tools.trim(trimExternal(editor.serializer, body.innerHTML));
  13502. } else if (updatedArgs.format === "text") {
  13503. content = editor.dom.isEmpty(body) ? "" : trim$2(body.innerText || body.textContent);
  13504. } else if (updatedArgs.format === "tree") {
  13505. content = editor.serializer.serialize(body, updatedArgs);
  13506. } else {
  13507. content = trimEmptyContents(editor, editor.serializer.serialize(body, updatedArgs));
  13508. }
  13509. if (!contains$3([
  13510. "text",
  13511. "tree"
  13512. ], updatedArgs.format) && !isWsPreserveElement(SugarElement.fromDom(body))) {
  13513. updatedArgs.content = Tools.trim(content);
  13514. } else {
  13515. updatedArgs.content = content;
  13516. }
  13517. if (updatedArgs.no_events) {
  13518. return updatedArgs.content;
  13519. } else {
  13520. return editor.fire("GetContent", updatedArgs).content;
  13521. }
  13522. };
  13523. var getContentInternal = function(editor, args, format) {
  13524. return Optional.from(editor.getBody()).fold(constant(args.format === "tree" ? new AstNode("body", 11) : ""), function(body) {
  13525. return getContentFromBody(editor, args, format, body);
  13526. });
  13527. };
  13528. var each$c = Tools.each;
  13529. var ElementUtils = function(dom2) {
  13530. var compare = function(node1, node2) {
  13531. if (node1.nodeName !== node2.nodeName) {
  13532. return false;
  13533. }
  13534. var getAttribs = function(node) {
  13535. var attribs = {};
  13536. each$c(dom2.getAttribs(node), function(attr) {
  13537. var name2 = attr.nodeName.toLowerCase();
  13538. if (name2.indexOf("_") !== 0 && name2 !== "style" && name2.indexOf("data-") !== 0) {
  13539. attribs[name2] = dom2.getAttrib(node, name2);
  13540. }
  13541. });
  13542. return attribs;
  13543. };
  13544. var compareObjects = function(obj1, obj2) {
  13545. var value2, name2;
  13546. for (name2 in obj1) {
  13547. if (has$2(obj1, name2)) {
  13548. value2 = obj2[name2];
  13549. if (typeof value2 === "undefined") {
  13550. return false;
  13551. }
  13552. if (obj1[name2] !== value2) {
  13553. return false;
  13554. }
  13555. delete obj2[name2];
  13556. }
  13557. }
  13558. for (name2 in obj2) {
  13559. if (has$2(obj2, name2)) {
  13560. return false;
  13561. }
  13562. }
  13563. return true;
  13564. };
  13565. if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
  13566. return false;
  13567. }
  13568. if (!compareObjects(dom2.parseStyle(dom2.getAttrib(node1, "style")), dom2.parseStyle(dom2.getAttrib(node2, "style")))) {
  13569. return false;
  13570. }
  13571. return !isBookmarkNode$1(node1) && !isBookmarkNode$1(node2);
  13572. };
  13573. return { compare };
  13574. };
  13575. var makeMap$1 = Tools.makeMap;
  13576. var Writer = function(settings) {
  13577. var html = [];
  13578. settings = settings || {};
  13579. var indent = settings.indent;
  13580. var indentBefore = makeMap$1(settings.indent_before || "");
  13581. var indentAfter = makeMap$1(settings.indent_after || "");
  13582. var encode = Entities.getEncodeFunc(settings.entity_encoding || "raw", settings.entities);
  13583. var htmlOutput = settings.element_format === "html";
  13584. return {
  13585. start: function(name2, attrs, empty2) {
  13586. var i, l, attr, value2;
  13587. if (indent && indentBefore[name2] && html.length > 0) {
  13588. value2 = html[html.length - 1];
  13589. if (value2.length > 0 && value2 !== "\n") {
  13590. html.push("\n");
  13591. }
  13592. }
  13593. html.push("<", name2);
  13594. if (attrs) {
  13595. for (i = 0, l = attrs.length; i < l; i++) {
  13596. attr = attrs[i];
  13597. html.push(" ", attr.name, '="', encode(attr.value, true), '"');
  13598. }
  13599. }
  13600. if (!empty2 || htmlOutput) {
  13601. html[html.length] = ">";
  13602. } else {
  13603. html[html.length] = " />";
  13604. }
  13605. if (empty2 && indent && indentAfter[name2] && html.length > 0) {
  13606. value2 = html[html.length - 1];
  13607. if (value2.length > 0 && value2 !== "\n") {
  13608. html.push("\n");
  13609. }
  13610. }
  13611. },
  13612. end: function(name2) {
  13613. var value2;
  13614. html.push("</", name2, ">");
  13615. if (indent && indentAfter[name2] && html.length > 0) {
  13616. value2 = html[html.length - 1];
  13617. if (value2.length > 0 && value2 !== "\n") {
  13618. html.push("\n");
  13619. }
  13620. }
  13621. },
  13622. text: function(text, raw) {
  13623. if (text.length > 0) {
  13624. html[html.length] = raw ? text : encode(text);
  13625. }
  13626. },
  13627. cdata: function(text) {
  13628. html.push("<![CDATA[", text, "]]>");
  13629. },
  13630. comment: function(text) {
  13631. html.push("<!--", text, "-->");
  13632. },
  13633. pi: function(name2, text) {
  13634. if (text) {
  13635. html.push("<?", name2, " ", encode(text), "?>");
  13636. } else {
  13637. html.push("<?", name2, "?>");
  13638. }
  13639. if (indent) {
  13640. html.push("\n");
  13641. }
  13642. },
  13643. doctype: function(text) {
  13644. html.push("<!DOCTYPE", text, ">", indent ? "\n" : "");
  13645. },
  13646. reset: function() {
  13647. html.length = 0;
  13648. },
  13649. getContent: function() {
  13650. return html.join("").replace(/\n$/, "");
  13651. }
  13652. };
  13653. };
  13654. var HtmlSerializer = function(settings, schema) {
  13655. if (schema === void 0) {
  13656. schema = Schema();
  13657. }
  13658. var writer = Writer(settings);
  13659. settings = settings || {};
  13660. settings.validate = "validate" in settings ? settings.validate : true;
  13661. var serialize2 = function(node) {
  13662. var validate2 = settings.validate;
  13663. var handlers = {
  13664. 3: function(node2) {
  13665. writer.text(node2.value, node2.raw);
  13666. },
  13667. 8: function(node2) {
  13668. writer.comment(node2.value);
  13669. },
  13670. 7: function(node2) {
  13671. writer.pi(node2.name, node2.value);
  13672. },
  13673. 10: function(node2) {
  13674. writer.doctype(node2.value);
  13675. },
  13676. 4: function(node2) {
  13677. writer.cdata(node2.value);
  13678. },
  13679. 11: function(node2) {
  13680. if (node2 = node2.firstChild) {
  13681. do {
  13682. walk2(node2);
  13683. } while (node2 = node2.next);
  13684. }
  13685. }
  13686. };
  13687. writer.reset();
  13688. var walk2 = function(node2) {
  13689. var handler = handlers[node2.type];
  13690. if (!handler) {
  13691. var name_1 = node2.name;
  13692. var isEmpty2 = node2.shortEnded;
  13693. var attrs = node2.attributes;
  13694. if (validate2 && attrs && attrs.length > 1) {
  13695. var sortedAttrs = [];
  13696. sortedAttrs.map = {};
  13697. var elementRule = schema.getElementRule(node2.name);
  13698. if (elementRule) {
  13699. for (var i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  13700. var attrName = elementRule.attributesOrder[i];
  13701. if (attrName in attrs.map) {
  13702. var attrValue = attrs.map[attrName];
  13703. sortedAttrs.map[attrName] = attrValue;
  13704. sortedAttrs.push({
  13705. name: attrName,
  13706. value: attrValue
  13707. });
  13708. }
  13709. }
  13710. for (var i = 0, l = attrs.length; i < l; i++) {
  13711. var attrName = attrs[i].name;
  13712. if (!(attrName in sortedAttrs.map)) {
  13713. var attrValue = attrs.map[attrName];
  13714. sortedAttrs.map[attrName] = attrValue;
  13715. sortedAttrs.push({
  13716. name: attrName,
  13717. value: attrValue
  13718. });
  13719. }
  13720. }
  13721. attrs = sortedAttrs;
  13722. }
  13723. }
  13724. writer.start(node2.name, attrs, isEmpty2);
  13725. if (!isEmpty2) {
  13726. if (node2 = node2.firstChild) {
  13727. do {
  13728. walk2(node2);
  13729. } while (node2 = node2.next);
  13730. }
  13731. writer.end(name_1);
  13732. }
  13733. } else {
  13734. handler(node2);
  13735. }
  13736. };
  13737. if (node.type === 1 && !settings.inner) {
  13738. walk2(node);
  13739. } else {
  13740. handlers[11](node);
  13741. }
  13742. return writer.getContent();
  13743. };
  13744. return { serialize: serialize2 };
  13745. };
  13746. var nonInheritableStyles = /* @__PURE__ */ new Set();
  13747. (function() {
  13748. var nonInheritableStylesArr = [
  13749. "margin",
  13750. "margin-left",
  13751. "margin-right",
  13752. "margin-top",
  13753. "margin-bottom",
  13754. "padding",
  13755. "padding-left",
  13756. "padding-right",
  13757. "padding-top",
  13758. "padding-bottom",
  13759. "border",
  13760. "border-width",
  13761. "border-style",
  13762. "border-color",
  13763. "background",
  13764. "background-attachment",
  13765. "background-clip",
  13766. "background-color",
  13767. "background-image",
  13768. "background-origin",
  13769. "background-position",
  13770. "background-repeat",
  13771. "background-size",
  13772. "float",
  13773. "position",
  13774. "left",
  13775. "right",
  13776. "top",
  13777. "bottom",
  13778. "z-index",
  13779. "display",
  13780. "transform",
  13781. "width",
  13782. "max-width",
  13783. "min-width",
  13784. "height",
  13785. "max-height",
  13786. "min-height",
  13787. "overflow",
  13788. "overflow-x",
  13789. "overflow-y",
  13790. "text-overflow",
  13791. "vertical-align",
  13792. "transition",
  13793. "transition-delay",
  13794. "transition-duration",
  13795. "transition-property",
  13796. "transition-timing-function"
  13797. ];
  13798. each$k(nonInheritableStylesArr, function(style) {
  13799. nonInheritableStyles.add(style);
  13800. });
  13801. })();
  13802. var shorthandStyleProps = [
  13803. "font",
  13804. "text-decoration",
  13805. "text-emphasis"
  13806. ];
  13807. var getStyleProps = function(dom2, node) {
  13808. return keys(dom2.parseStyle(dom2.getAttrib(node, "style")));
  13809. };
  13810. var isNonInheritableStyle = function(style) {
  13811. return nonInheritableStyles.has(style);
  13812. };
  13813. var hasInheritableStyles = function(dom2, node) {
  13814. return forall(getStyleProps(dom2, node), function(style) {
  13815. return !isNonInheritableStyle(style);
  13816. });
  13817. };
  13818. var getLonghandStyleProps = function(styles) {
  13819. return filter$4(styles, function(style) {
  13820. return exists(shorthandStyleProps, function(prop) {
  13821. return startsWith(style, prop);
  13822. });
  13823. });
  13824. };
  13825. var hasStyleConflict = function(dom2, node, parentNode) {
  13826. var nodeStyleProps = getStyleProps(dom2, node);
  13827. var parentNodeStyleProps = getStyleProps(dom2, parentNode);
  13828. var valueMismatch = function(prop) {
  13829. var nodeValue = dom2.getStyle(node, prop);
  13830. var parentValue = dom2.getStyle(parentNode, prop);
  13831. return isNotEmpty(nodeValue) && isNotEmpty(parentValue) && nodeValue !== parentValue;
  13832. };
  13833. return exists(nodeStyleProps, function(nodeStyleProp) {
  13834. var propExists = function(props) {
  13835. return exists(props, function(prop) {
  13836. return prop === nodeStyleProp;
  13837. });
  13838. };
  13839. if (!propExists(parentNodeStyleProps) && propExists(shorthandStyleProps)) {
  13840. var longhandProps = getLonghandStyleProps(parentNodeStyleProps);
  13841. return exists(longhandProps, valueMismatch);
  13842. } else {
  13843. return valueMismatch(nodeStyleProp);
  13844. }
  13845. });
  13846. };
  13847. var isChar = function(forward, predicate, pos) {
  13848. return Optional.from(pos.container()).filter(isText$7).exists(function(text) {
  13849. var delta = forward ? 0 : -1;
  13850. return predicate(text.data.charAt(pos.offset() + delta));
  13851. });
  13852. };
  13853. var isBeforeSpace = curry(isChar, true, isWhiteSpace);
  13854. var isAfterSpace = curry(isChar, false, isWhiteSpace);
  13855. var isEmptyText = function(pos) {
  13856. var container = pos.container();
  13857. return isText$7(container) && (container.data.length === 0 || isZwsp(container.data) && BookmarkManager.isBookmarkNode(container.parentNode));
  13858. };
  13859. var matchesElementPosition = function(before2, predicate) {
  13860. return function(pos) {
  13861. return Optional.from(getChildNodeAtRelativeOffset(before2 ? 0 : -1, pos)).filter(predicate).isSome();
  13862. };
  13863. };
  13864. var isImageBlock = function(node) {
  13865. return isImg(node) && get$5(SugarElement.fromDom(node), "display") === "block";
  13866. };
  13867. var isCefNode = function(node) {
  13868. return isContentEditableFalse$b(node) && !isBogusAll$1(node);
  13869. };
  13870. var isBeforeImageBlock = matchesElementPosition(true, isImageBlock);
  13871. var isAfterImageBlock = matchesElementPosition(false, isImageBlock);
  13872. var isBeforeMedia = matchesElementPosition(true, isMedia$2);
  13873. var isAfterMedia = matchesElementPosition(false, isMedia$2);
  13874. var isBeforeTable = matchesElementPosition(true, isTable$3);
  13875. var isAfterTable = matchesElementPosition(false, isTable$3);
  13876. var isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode);
  13877. var isAfterContentEditableFalse = matchesElementPosition(false, isCefNode);
  13878. var getLastChildren = function(elm) {
  13879. var children2 = [];
  13880. var rawNode = elm.dom;
  13881. while (rawNode) {
  13882. children2.push(SugarElement.fromDom(rawNode));
  13883. rawNode = rawNode.lastChild;
  13884. }
  13885. return children2;
  13886. };
  13887. var removeTrailingBr = function(elm) {
  13888. var allBrs = descendants(elm, "br");
  13889. var brs = filter$4(getLastChildren(elm).slice(-1), isBr$4);
  13890. if (allBrs.length === brs.length) {
  13891. each$k(brs, remove$7);
  13892. }
  13893. };
  13894. var fillWithPaddingBr = function(elm) {
  13895. empty(elm);
  13896. append$1(elm, SugarElement.fromHtml('<br data-mce-bogus="1">'));
  13897. };
  13898. var trimBlockTrailingBr = function(elm) {
  13899. lastChild(elm).each(function(lastChild2) {
  13900. prevSibling(lastChild2).each(function(lastChildPrevSibling) {
  13901. if (isBlock$2(elm) && isBr$4(lastChild2) && isBlock$2(lastChildPrevSibling)) {
  13902. remove$7(lastChild2);
  13903. }
  13904. });
  13905. });
  13906. };
  13907. var dropLast = function(xs) {
  13908. return xs.slice(0, -1);
  13909. };
  13910. var parentsUntil = function(start2, root, predicate) {
  13911. if (contains$1(root, start2)) {
  13912. return dropLast(parents$1(start2, function(elm) {
  13913. return predicate(elm) || eq(elm, root);
  13914. }));
  13915. } else {
  13916. return [];
  13917. }
  13918. };
  13919. var parents = function(start2, root) {
  13920. return parentsUntil(start2, root, never);
  13921. };
  13922. var parentsAndSelf = function(start2, root) {
  13923. return [start2].concat(parents(start2, root));
  13924. };
  13925. var navigateIgnoreEmptyTextNodes = function(forward, root, from2) {
  13926. return navigateIgnore(forward, root, from2, isEmptyText);
  13927. };
  13928. var getClosestBlock$1 = function(root, pos) {
  13929. return find$3(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2);
  13930. };
  13931. var isAtBeforeAfterBlockBoundary = function(forward, root, pos) {
  13932. return navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(function(newPos) {
  13933. return getClosestBlock$1(root, pos).fold(function() {
  13934. return isInSameBlock(newPos, pos, root.dom) === false;
  13935. }, function(fromBlock) {
  13936. return isInSameBlock(newPos, pos, root.dom) === false && contains$1(fromBlock, SugarElement.fromDom(newPos.container()));
  13937. });
  13938. });
  13939. };
  13940. var isAtBlockBoundary = function(forward, root, pos) {
  13941. return getClosestBlock$1(root, pos).fold(function() {
  13942. return navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(function(newPos) {
  13943. return isInSameBlock(newPos, pos, root.dom) === false;
  13944. });
  13945. }, function(parent2) {
  13946. return navigateIgnoreEmptyTextNodes(forward, parent2.dom, pos).isNone();
  13947. });
  13948. };
  13949. var isAtStartOfBlock = curry(isAtBlockBoundary, false);
  13950. var isAtEndOfBlock = curry(isAtBlockBoundary, true);
  13951. var isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false);
  13952. var isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true);
  13953. var isBr = function(pos) {
  13954. return getElementFromPosition(pos).exists(isBr$4);
  13955. };
  13956. var findBr = function(forward, root, pos) {
  13957. var parentBlocks = filter$4(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2);
  13958. var scope = head(parentBlocks).getOr(root);
  13959. return fromPosition(forward, scope.dom, pos).filter(isBr);
  13960. };
  13961. var isBeforeBr$1 = function(root, pos) {
  13962. return getElementFromPosition(pos).exists(isBr$4) || findBr(true, root, pos).isSome();
  13963. };
  13964. var isAfterBr = function(root, pos) {
  13965. return getElementFromPrevPosition(pos).exists(isBr$4) || findBr(false, root, pos).isSome();
  13966. };
  13967. var findPreviousBr = curry(findBr, false);
  13968. var findNextBr = curry(findBr, true);
  13969. var isInMiddleOfText = function(pos) {
  13970. return CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd();
  13971. };
  13972. var getClosestBlock = function(root, pos) {
  13973. var parentBlocks = filter$4(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2);
  13974. return head(parentBlocks).getOr(root);
  13975. };
  13976. var hasSpaceBefore = function(root, pos) {
  13977. if (isInMiddleOfText(pos)) {
  13978. return isAfterSpace(pos);
  13979. } else {
  13980. return isAfterSpace(pos) || prevPosition(getClosestBlock(root, pos).dom, pos).exists(isAfterSpace);
  13981. }
  13982. };
  13983. var hasSpaceAfter = function(root, pos) {
  13984. if (isInMiddleOfText(pos)) {
  13985. return isBeforeSpace(pos);
  13986. } else {
  13987. return isBeforeSpace(pos) || nextPosition(getClosestBlock(root, pos).dom, pos).exists(isBeforeSpace);
  13988. }
  13989. };
  13990. var isPreValue = function(value2) {
  13991. return contains$3([
  13992. "pre",
  13993. "pre-wrap"
  13994. ], value2);
  13995. };
  13996. var isInPre = function(pos) {
  13997. return getElementFromPosition(pos).bind(function(elm) {
  13998. return closest$3(elm, isElement$6);
  13999. }).exists(function(elm) {
  14000. return isPreValue(get$5(elm, "white-space"));
  14001. });
  14002. };
  14003. var isAtBeginningOfBody = function(root, pos) {
  14004. return prevPosition(root.dom, pos).isNone();
  14005. };
  14006. var isAtEndOfBody = function(root, pos) {
  14007. return nextPosition(root.dom, pos).isNone();
  14008. };
  14009. var isAtLineBoundary = function(root, pos) {
  14010. return isAtBeginningOfBody(root, pos) || isAtEndOfBody(root, pos) || isAtStartOfBlock(root, pos) || isAtEndOfBlock(root, pos) || isAfterBr(root, pos) || isBeforeBr$1(root, pos);
  14011. };
  14012. var needsToHaveNbsp = function(root, pos) {
  14013. if (isInPre(pos)) {
  14014. return false;
  14015. } else {
  14016. return isAtLineBoundary(root, pos) || hasSpaceBefore(root, pos) || hasSpaceAfter(root, pos);
  14017. }
  14018. };
  14019. var needsToBeNbspLeft = function(root, pos) {
  14020. if (isInPre(pos)) {
  14021. return false;
  14022. } else {
  14023. return isAtStartOfBlock(root, pos) || isBeforeBlock(root, pos) || isAfterBr(root, pos) || hasSpaceBefore(root, pos);
  14024. }
  14025. };
  14026. var leanRight = function(pos) {
  14027. var container = pos.container();
  14028. var offset = pos.offset();
  14029. if (isText$7(container) && offset < container.data.length) {
  14030. return CaretPosition(container, offset + 1);
  14031. } else {
  14032. return pos;
  14033. }
  14034. };
  14035. var needsToBeNbspRight = function(root, pos) {
  14036. if (isInPre(pos)) {
  14037. return false;
  14038. } else {
  14039. return isAtEndOfBlock(root, pos) || isAfterBlock(root, pos) || isBeforeBr$1(root, pos) || hasSpaceAfter(root, pos);
  14040. }
  14041. };
  14042. var needsToBeNbsp = function(root, pos) {
  14043. return needsToBeNbspLeft(root, pos) || needsToBeNbspRight(root, leanRight(pos));
  14044. };
  14045. var isNbspAt = function(text, offset) {
  14046. return isNbsp(text.charAt(offset));
  14047. };
  14048. var hasNbsp = function(pos) {
  14049. var container = pos.container();
  14050. return isText$7(container) && contains$2(container.data, nbsp);
  14051. };
  14052. var normalizeNbspMiddle = function(text) {
  14053. var chars = text.split("");
  14054. return map$3(chars, function(chr, i) {
  14055. if (isNbsp(chr) && i > 0 && i < chars.length - 1 && isContent(chars[i - 1]) && isContent(chars[i + 1])) {
  14056. return " ";
  14057. } else {
  14058. return chr;
  14059. }
  14060. }).join("");
  14061. };
  14062. var normalizeNbspAtStart = function(root, node) {
  14063. var text = node.data;
  14064. var firstPos = CaretPosition(node, 0);
  14065. if (isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos)) {
  14066. node.data = " " + text.slice(1);
  14067. return true;
  14068. } else {
  14069. return false;
  14070. }
  14071. };
  14072. var normalizeNbspInMiddleOfTextNode = function(node) {
  14073. var text = node.data;
  14074. var newText = normalizeNbspMiddle(text);
  14075. if (newText !== text) {
  14076. node.data = newText;
  14077. return true;
  14078. } else {
  14079. return false;
  14080. }
  14081. };
  14082. var normalizeNbspAtEnd = function(root, node) {
  14083. var text = node.data;
  14084. var lastPos = CaretPosition(node, text.length - 1);
  14085. if (isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos)) {
  14086. node.data = text.slice(0, -1) + " ";
  14087. return true;
  14088. } else {
  14089. return false;
  14090. }
  14091. };
  14092. var normalizeNbsps = function(root, pos) {
  14093. return Optional.some(pos).filter(hasNbsp).bind(function(pos2) {
  14094. var container = pos2.container();
  14095. var normalized = normalizeNbspAtStart(root, container) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container);
  14096. return normalized ? Optional.some(pos2) : Optional.none();
  14097. });
  14098. };
  14099. var normalizeNbspsInEditor = function(editor) {
  14100. var root = SugarElement.fromDom(editor.getBody());
  14101. if (editor.selection.isCollapsed()) {
  14102. normalizeNbsps(root, CaretPosition.fromRangeStart(editor.selection.getRng())).each(function(pos) {
  14103. editor.selection.setRng(pos.toRange());
  14104. });
  14105. }
  14106. };
  14107. var normalizeContent = function(content, isStartOfContent, isEndOfContent) {
  14108. var result = foldl(content, function(acc, c) {
  14109. if (isWhiteSpace(c) || isNbsp(c)) {
  14110. if (acc.previousCharIsSpace || acc.str === "" && isStartOfContent || acc.str.length === content.length - 1 && isEndOfContent) {
  14111. return {
  14112. previousCharIsSpace: false,
  14113. str: acc.str + nbsp
  14114. };
  14115. } else {
  14116. return {
  14117. previousCharIsSpace: true,
  14118. str: acc.str + " "
  14119. };
  14120. }
  14121. } else {
  14122. return {
  14123. previousCharIsSpace: false,
  14124. str: acc.str + c
  14125. };
  14126. }
  14127. }, {
  14128. previousCharIsSpace: false,
  14129. str: ""
  14130. });
  14131. return result.str;
  14132. };
  14133. var normalize$1 = function(node, offset, count2) {
  14134. if (count2 === 0) {
  14135. return;
  14136. }
  14137. var elm = SugarElement.fromDom(node);
  14138. var root = ancestor$3(elm, isBlock$2).getOr(elm);
  14139. var whitespace2 = node.data.slice(offset, offset + count2);
  14140. var isEndOfContent = offset + count2 >= node.data.length && needsToBeNbspRight(root, CaretPosition(node, node.data.length));
  14141. var isStartOfContent = offset === 0 && needsToBeNbspLeft(root, CaretPosition(node, 0));
  14142. node.replaceData(offset, count2, normalizeContent(whitespace2, isStartOfContent, isEndOfContent));
  14143. };
  14144. var normalizeWhitespaceAfter = function(node, offset) {
  14145. var content = node.data.slice(offset);
  14146. var whitespaceCount = content.length - lTrim(content).length;
  14147. normalize$1(node, offset, whitespaceCount);
  14148. };
  14149. var normalizeWhitespaceBefore = function(node, offset) {
  14150. var content = node.data.slice(0, offset);
  14151. var whitespaceCount = content.length - rTrim(content).length;
  14152. normalize$1(node, offset - whitespaceCount, whitespaceCount);
  14153. };
  14154. var mergeTextNodes = function(prevNode, nextNode, normalizeWhitespace, mergeToPrev) {
  14155. if (mergeToPrev === void 0) {
  14156. mergeToPrev = true;
  14157. }
  14158. var whitespaceOffset = rTrim(prevNode.data).length;
  14159. var newNode = mergeToPrev ? prevNode : nextNode;
  14160. var removeNode2 = mergeToPrev ? nextNode : prevNode;
  14161. if (mergeToPrev) {
  14162. newNode.appendData(removeNode2.data);
  14163. } else {
  14164. newNode.insertData(0, removeNode2.data);
  14165. }
  14166. remove$7(SugarElement.fromDom(removeNode2));
  14167. if (normalizeWhitespace) {
  14168. normalizeWhitespaceAfter(newNode, whitespaceOffset);
  14169. }
  14170. return newNode;
  14171. };
  14172. var needsReposition = function(pos, elm) {
  14173. var container = pos.container();
  14174. var offset = pos.offset();
  14175. return CaretPosition.isTextPosition(pos) === false && container === elm.parentNode && offset > CaretPosition.before(elm).offset();
  14176. };
  14177. var reposition = function(elm, pos) {
  14178. return needsReposition(pos, elm) ? CaretPosition(pos.container(), pos.offset() - 1) : pos;
  14179. };
  14180. var beforeOrStartOf = function(node) {
  14181. return isText$7(node) ? CaretPosition(node, 0) : CaretPosition.before(node);
  14182. };
  14183. var afterOrEndOf = function(node) {
  14184. return isText$7(node) ? CaretPosition(node, node.data.length) : CaretPosition.after(node);
  14185. };
  14186. var getPreviousSiblingCaretPosition = function(elm) {
  14187. if (isCaretCandidate$3(elm.previousSibling)) {
  14188. return Optional.some(afterOrEndOf(elm.previousSibling));
  14189. } else {
  14190. return elm.previousSibling ? lastPositionIn(elm.previousSibling) : Optional.none();
  14191. }
  14192. };
  14193. var getNextSiblingCaretPosition = function(elm) {
  14194. if (isCaretCandidate$3(elm.nextSibling)) {
  14195. return Optional.some(beforeOrStartOf(elm.nextSibling));
  14196. } else {
  14197. return elm.nextSibling ? firstPositionIn(elm.nextSibling) : Optional.none();
  14198. }
  14199. };
  14200. var findCaretPositionBackwardsFromElm = function(rootElement, elm) {
  14201. var startPosition = CaretPosition.before(elm.previousSibling ? elm.previousSibling : elm.parentNode);
  14202. return prevPosition(rootElement, startPosition).fold(function() {
  14203. return nextPosition(rootElement, CaretPosition.after(elm));
  14204. }, Optional.some);
  14205. };
  14206. var findCaretPositionForwardsFromElm = function(rootElement, elm) {
  14207. return nextPosition(rootElement, CaretPosition.after(elm)).fold(function() {
  14208. return prevPosition(rootElement, CaretPosition.before(elm));
  14209. }, Optional.some);
  14210. };
  14211. var findCaretPositionBackwards = function(rootElement, elm) {
  14212. return getPreviousSiblingCaretPosition(elm).orThunk(function() {
  14213. return getNextSiblingCaretPosition(elm);
  14214. }).orThunk(function() {
  14215. return findCaretPositionBackwardsFromElm(rootElement, elm);
  14216. });
  14217. };
  14218. var findCaretPositionForward = function(rootElement, elm) {
  14219. return getNextSiblingCaretPosition(elm).orThunk(function() {
  14220. return getPreviousSiblingCaretPosition(elm);
  14221. }).orThunk(function() {
  14222. return findCaretPositionForwardsFromElm(rootElement, elm);
  14223. });
  14224. };
  14225. var findCaretPosition = function(forward, rootElement, elm) {
  14226. return forward ? findCaretPositionForward(rootElement, elm) : findCaretPositionBackwards(rootElement, elm);
  14227. };
  14228. var findCaretPosOutsideElmAfterDelete = function(forward, rootElement, elm) {
  14229. return findCaretPosition(forward, rootElement, elm).map(curry(reposition, elm));
  14230. };
  14231. var setSelection$1 = function(editor, forward, pos) {
  14232. pos.fold(function() {
  14233. editor.focus();
  14234. }, function(pos2) {
  14235. editor.selection.setRng(pos2.toRange(), forward);
  14236. });
  14237. };
  14238. var eqRawNode = function(rawNode) {
  14239. return function(elm) {
  14240. return elm.dom === rawNode;
  14241. };
  14242. };
  14243. var isBlock = function(editor, elm) {
  14244. return elm && has$2(editor.schema.getBlockElements(), name(elm));
  14245. };
  14246. var paddEmptyBlock = function(elm) {
  14247. if (isEmpty$2(elm)) {
  14248. var br = SugarElement.fromHtml('<br data-mce-bogus="1">');
  14249. empty(elm);
  14250. append$1(elm, br);
  14251. return Optional.some(CaretPosition.before(br.dom));
  14252. } else {
  14253. return Optional.none();
  14254. }
  14255. };
  14256. var deleteNormalized = function(elm, afterDeletePosOpt, normalizeWhitespace) {
  14257. var prevTextOpt = prevSibling(elm).filter(isText$8);
  14258. var nextTextOpt = nextSibling(elm).filter(isText$8);
  14259. remove$7(elm);
  14260. return lift3(prevTextOpt, nextTextOpt, afterDeletePosOpt, function(prev, next, pos) {
  14261. var prevNode = prev.dom, nextNode = next.dom;
  14262. var offset = prevNode.data.length;
  14263. mergeTextNodes(prevNode, nextNode, normalizeWhitespace);
  14264. return pos.container() === nextNode ? CaretPosition(prevNode, offset) : pos;
  14265. }).orThunk(function() {
  14266. if (normalizeWhitespace) {
  14267. prevTextOpt.each(function(elm2) {
  14268. return normalizeWhitespaceBefore(elm2.dom, elm2.dom.length);
  14269. });
  14270. nextTextOpt.each(function(elm2) {
  14271. return normalizeWhitespaceAfter(elm2.dom, 0);
  14272. });
  14273. }
  14274. return afterDeletePosOpt;
  14275. });
  14276. };
  14277. var isInlineElement = function(editor, element) {
  14278. return has$2(editor.schema.getTextInlineElements(), name(element));
  14279. };
  14280. var deleteElement$2 = function(editor, forward, elm, moveCaret2) {
  14281. if (moveCaret2 === void 0) {
  14282. moveCaret2 = true;
  14283. }
  14284. var afterDeletePos = findCaretPosOutsideElmAfterDelete(forward, editor.getBody(), elm.dom);
  14285. var parentBlock = ancestor$3(elm, curry(isBlock, editor), eqRawNode(editor.getBody()));
  14286. var normalizedAfterDeletePos = deleteNormalized(elm, afterDeletePos, isInlineElement(editor, elm));
  14287. if (editor.dom.isEmpty(editor.getBody())) {
  14288. editor.setContent("");
  14289. editor.selection.setCursorLocation();
  14290. } else {
  14291. parentBlock.bind(paddEmptyBlock).fold(function() {
  14292. if (moveCaret2) {
  14293. setSelection$1(editor, forward, normalizedAfterDeletePos);
  14294. }
  14295. }, function(paddPos) {
  14296. if (moveCaret2) {
  14297. setSelection$1(editor, forward, Optional.some(paddPos));
  14298. }
  14299. });
  14300. }
  14301. };
  14302. var isRootFromElement = function(root) {
  14303. return function(cur) {
  14304. return eq(root, cur);
  14305. };
  14306. };
  14307. var getTableCells = function(table) {
  14308. return descendants(table, "td,th");
  14309. };
  14310. var getTableDetailsFromRange = function(rng, isRoot) {
  14311. var getTable2 = function(node) {
  14312. return getClosestTable(SugarElement.fromDom(node), isRoot);
  14313. };
  14314. var startTable = getTable2(rng.startContainer);
  14315. var endTable = getTable2(rng.endContainer);
  14316. var isStartInTable = startTable.isSome();
  14317. var isEndInTable = endTable.isSome();
  14318. var isSameTable = lift2(startTable, endTable, eq).getOr(false);
  14319. var isMultiTable = !isSameTable && isStartInTable && isEndInTable;
  14320. return {
  14321. startTable,
  14322. endTable,
  14323. isStartInTable,
  14324. isEndInTable,
  14325. isSameTable,
  14326. isMultiTable
  14327. };
  14328. };
  14329. var tableCellRng = function(start2, end2) {
  14330. return {
  14331. start: start2,
  14332. end: end2
  14333. };
  14334. };
  14335. var tableSelection = function(rng, table, cells) {
  14336. return {
  14337. rng,
  14338. table,
  14339. cells
  14340. };
  14341. };
  14342. var deleteAction = Adt.generate([
  14343. {
  14344. singleCellTable: [
  14345. "rng",
  14346. "cell"
  14347. ]
  14348. },
  14349. { fullTable: ["table"] },
  14350. {
  14351. partialTable: [
  14352. "cells",
  14353. "outsideDetails"
  14354. ]
  14355. },
  14356. {
  14357. multiTable: [
  14358. "startTableCells",
  14359. "endTableCells",
  14360. "betweenRng"
  14361. ]
  14362. }
  14363. ]);
  14364. var getClosestCell$1 = function(container, isRoot) {
  14365. return closest$2(SugarElement.fromDom(container), "td,th", isRoot);
  14366. };
  14367. var isExpandedCellRng = function(cellRng) {
  14368. return !eq(cellRng.start, cellRng.end);
  14369. };
  14370. var getTableFromCellRng = function(cellRng, isRoot) {
  14371. return getClosestTable(cellRng.start, isRoot).bind(function(startParentTable) {
  14372. return getClosestTable(cellRng.end, isRoot).bind(function(endParentTable) {
  14373. return someIf(eq(startParentTable, endParentTable), startParentTable);
  14374. });
  14375. });
  14376. };
  14377. var isSingleCellTable = function(cellRng, isRoot) {
  14378. return !isExpandedCellRng(cellRng) && getTableFromCellRng(cellRng, isRoot).exists(function(table) {
  14379. var rows = table.dom.rows;
  14380. return rows.length === 1 && rows[0].cells.length === 1;
  14381. });
  14382. };
  14383. var getCellRng = function(rng, isRoot) {
  14384. var startCell = getClosestCell$1(rng.startContainer, isRoot);
  14385. var endCell = getClosestCell$1(rng.endContainer, isRoot);
  14386. return lift2(startCell, endCell, tableCellRng);
  14387. };
  14388. var getCellRangeFromStartTable = function(isRoot) {
  14389. return function(startCell) {
  14390. return getClosestTable(startCell, isRoot).bind(function(table) {
  14391. return last$2(getTableCells(table)).map(function(endCell) {
  14392. return tableCellRng(startCell, endCell);
  14393. });
  14394. });
  14395. };
  14396. };
  14397. var getCellRangeFromEndTable = function(isRoot) {
  14398. return function(endCell) {
  14399. return getClosestTable(endCell, isRoot).bind(function(table) {
  14400. return head(getTableCells(table)).map(function(startCell) {
  14401. return tableCellRng(startCell, endCell);
  14402. });
  14403. });
  14404. };
  14405. };
  14406. var getTableSelectionFromCellRng = function(isRoot) {
  14407. return function(cellRng) {
  14408. return getTableFromCellRng(cellRng, isRoot).map(function(table) {
  14409. return tableSelection(cellRng, table, getTableCells(table));
  14410. });
  14411. };
  14412. };
  14413. var getTableSelections = function(cellRng, selectionDetails, rng, isRoot) {
  14414. if (rng.collapsed || !cellRng.forall(isExpandedCellRng)) {
  14415. return Optional.none();
  14416. } else if (selectionDetails.isSameTable) {
  14417. var sameTableSelection = cellRng.bind(getTableSelectionFromCellRng(isRoot));
  14418. return Optional.some({
  14419. start: sameTableSelection,
  14420. end: sameTableSelection
  14421. });
  14422. } else {
  14423. var startCell = getClosestCell$1(rng.startContainer, isRoot);
  14424. var endCell = getClosestCell$1(rng.endContainer, isRoot);
  14425. var startTableSelection = startCell.bind(getCellRangeFromStartTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot));
  14426. var endTableSelection = endCell.bind(getCellRangeFromEndTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot));
  14427. return Optional.some({
  14428. start: startTableSelection,
  14429. end: endTableSelection
  14430. });
  14431. }
  14432. };
  14433. var getCellIndex = function(cells, cell) {
  14434. return findIndex$2(cells, function(x) {
  14435. return eq(x, cell);
  14436. });
  14437. };
  14438. var getSelectedCells = function(tableSelection2) {
  14439. return lift2(getCellIndex(tableSelection2.cells, tableSelection2.rng.start), getCellIndex(tableSelection2.cells, tableSelection2.rng.end), function(startIndex, endIndex) {
  14440. return tableSelection2.cells.slice(startIndex, endIndex + 1);
  14441. });
  14442. };
  14443. var isSingleCellTableContentSelected = function(optCellRng, rng, isRoot) {
  14444. return optCellRng.exists(function(cellRng) {
  14445. return isSingleCellTable(cellRng, isRoot) && hasAllContentsSelected(cellRng.start, rng);
  14446. });
  14447. };
  14448. var unselectCells = function(rng, selectionDetails) {
  14449. var startTable = selectionDetails.startTable, endTable = selectionDetails.endTable;
  14450. var otherContentRng = rng.cloneRange();
  14451. startTable.each(function(table) {
  14452. return otherContentRng.setStartAfter(table.dom);
  14453. });
  14454. endTable.each(function(table) {
  14455. return otherContentRng.setEndBefore(table.dom);
  14456. });
  14457. return otherContentRng;
  14458. };
  14459. var handleSingleTable = function(cellRng, selectionDetails, rng, isRoot) {
  14460. return getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(function(_a) {
  14461. var start2 = _a.start, end2 = _a.end;
  14462. return start2.or(end2);
  14463. }).bind(function(tableSelection2) {
  14464. var isSameTable = selectionDetails.isSameTable;
  14465. var selectedCells = getSelectedCells(tableSelection2).getOr([]);
  14466. if (isSameTable && tableSelection2.cells.length === selectedCells.length) {
  14467. return Optional.some(deleteAction.fullTable(tableSelection2.table));
  14468. } else if (selectedCells.length > 0) {
  14469. if (isSameTable) {
  14470. return Optional.some(deleteAction.partialTable(selectedCells, Optional.none()));
  14471. } else {
  14472. var otherContentRng = unselectCells(rng, selectionDetails);
  14473. return Optional.some(deleteAction.partialTable(selectedCells, Optional.some(__assign(__assign({}, selectionDetails), { rng: otherContentRng }))));
  14474. }
  14475. } else {
  14476. return Optional.none();
  14477. }
  14478. });
  14479. };
  14480. var handleMultiTable = function(cellRng, selectionDetails, rng, isRoot) {
  14481. return getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(function(_a) {
  14482. var start2 = _a.start, end2 = _a.end;
  14483. var startTableSelectedCells = start2.bind(getSelectedCells).getOr([]);
  14484. var endTableSelectedCells = end2.bind(getSelectedCells).getOr([]);
  14485. if (startTableSelectedCells.length > 0 && endTableSelectedCells.length > 0) {
  14486. var otherContentRng = unselectCells(rng, selectionDetails);
  14487. return Optional.some(deleteAction.multiTable(startTableSelectedCells, endTableSelectedCells, otherContentRng));
  14488. } else {
  14489. return Optional.none();
  14490. }
  14491. });
  14492. };
  14493. var getActionFromRange = function(root, rng) {
  14494. var isRoot = isRootFromElement(root);
  14495. var optCellRng = getCellRng(rng, isRoot);
  14496. var selectionDetails = getTableDetailsFromRange(rng, isRoot);
  14497. if (isSingleCellTableContentSelected(optCellRng, rng, isRoot)) {
  14498. return optCellRng.map(function(cellRng) {
  14499. return deleteAction.singleCellTable(rng, cellRng.start);
  14500. });
  14501. } else if (selectionDetails.isMultiTable) {
  14502. return handleMultiTable(optCellRng, selectionDetails, rng, isRoot);
  14503. } else {
  14504. return handleSingleTable(optCellRng, selectionDetails, rng, isRoot);
  14505. }
  14506. };
  14507. var freefallRtl = function(root) {
  14508. var child2 = isComment$1(root) ? prevSibling(root) : lastChild(root);
  14509. return child2.bind(freefallRtl).orThunk(function() {
  14510. return Optional.some(root);
  14511. });
  14512. };
  14513. var cleanCells = function(cells) {
  14514. return each$k(cells, function(cell) {
  14515. remove$6(cell, "contenteditable");
  14516. fillWithPaddingBr(cell);
  14517. });
  14518. };
  14519. var getOutsideBlock = function(editor, container) {
  14520. return Optional.from(editor.dom.getParent(container, editor.dom.isBlock)).map(SugarElement.fromDom);
  14521. };
  14522. var handleEmptyBlock = function(editor, startInTable, emptyBlock2) {
  14523. emptyBlock2.each(function(block) {
  14524. if (startInTable) {
  14525. remove$7(block);
  14526. } else {
  14527. fillWithPaddingBr(block);
  14528. editor.selection.setCursorLocation(block.dom, 0);
  14529. }
  14530. });
  14531. };
  14532. var deleteContentInsideCell = function(editor, cell, rng, isFirstCellInSelection) {
  14533. var insideTableRng = rng.cloneRange();
  14534. if (isFirstCellInSelection) {
  14535. insideTableRng.setStart(rng.startContainer, rng.startOffset);
  14536. insideTableRng.setEndAfter(cell.dom.lastChild);
  14537. } else {
  14538. insideTableRng.setStartBefore(cell.dom.firstChild);
  14539. insideTableRng.setEnd(rng.endContainer, rng.endOffset);
  14540. }
  14541. deleteCellContents(editor, insideTableRng, cell, false);
  14542. };
  14543. var collapseAndRestoreCellSelection = function(editor) {
  14544. var selectedCells = getCellsFromEditor(editor);
  14545. var selectedNode = SugarElement.fromDom(editor.selection.getNode());
  14546. if (isTableCell$5(selectedNode.dom) && isEmpty$2(selectedNode)) {
  14547. editor.selection.setCursorLocation(selectedNode.dom, 0);
  14548. } else {
  14549. editor.selection.collapse(true);
  14550. }
  14551. if (selectedCells.length > 1 && exists(selectedCells, function(cell) {
  14552. return eq(cell, selectedNode);
  14553. })) {
  14554. set$1(selectedNode, "data-mce-selected", "1");
  14555. }
  14556. };
  14557. var emptySingleTableCells = function(editor, cells, outsideDetails) {
  14558. var editorRng = editor.selection.getRng();
  14559. var cellsToClean = outsideDetails.bind(function(_a) {
  14560. var rng = _a.rng, isStartInTable = _a.isStartInTable;
  14561. var outsideBlock = getOutsideBlock(editor, isStartInTable ? rng.endContainer : rng.startContainer);
  14562. rng.deleteContents();
  14563. handleEmptyBlock(editor, isStartInTable, outsideBlock.filter(isEmpty$2));
  14564. var endPointCell = isStartInTable ? cells[0] : cells[cells.length - 1];
  14565. deleteContentInsideCell(editor, endPointCell, editorRng, isStartInTable);
  14566. if (!isEmpty$2(endPointCell)) {
  14567. return Optional.some(isStartInTable ? cells.slice(1) : cells.slice(0, -1));
  14568. } else {
  14569. return Optional.none();
  14570. }
  14571. }).getOr(cells);
  14572. cleanCells(cellsToClean);
  14573. collapseAndRestoreCellSelection(editor);
  14574. return true;
  14575. };
  14576. var emptyMultiTableCells = function(editor, startTableCells, endTableCells, betweenRng) {
  14577. var rng = editor.selection.getRng();
  14578. var startCell = startTableCells[0];
  14579. var endCell = endTableCells[endTableCells.length - 1];
  14580. deleteContentInsideCell(editor, startCell, rng, true);
  14581. deleteContentInsideCell(editor, endCell, rng, false);
  14582. var startTableCellsToClean = isEmpty$2(startCell) ? startTableCells : startTableCells.slice(1);
  14583. var endTableCellsToClean = isEmpty$2(endCell) ? endTableCells : endTableCells.slice(0, -1);
  14584. cleanCells(startTableCellsToClean.concat(endTableCellsToClean));
  14585. betweenRng.deleteContents();
  14586. collapseAndRestoreCellSelection(editor);
  14587. return true;
  14588. };
  14589. var deleteCellContents = function(editor, rng, cell, moveSelection2) {
  14590. if (moveSelection2 === void 0) {
  14591. moveSelection2 = true;
  14592. }
  14593. rng.deleteContents();
  14594. var lastNode = freefallRtl(cell).getOr(cell);
  14595. var lastBlock = SugarElement.fromDom(editor.dom.getParent(lastNode.dom, editor.dom.isBlock));
  14596. if (isEmpty$2(lastBlock)) {
  14597. fillWithPaddingBr(lastBlock);
  14598. if (moveSelection2) {
  14599. editor.selection.setCursorLocation(lastBlock.dom, 0);
  14600. }
  14601. }
  14602. if (!eq(cell, lastBlock)) {
  14603. var additionalCleanupNodes = is$1(parent(lastBlock), cell) ? [] : siblings(lastBlock);
  14604. each$k(additionalCleanupNodes.concat(children(cell)), function(node) {
  14605. if (!eq(node, lastBlock) && !contains$1(node, lastBlock) && isEmpty$2(node)) {
  14606. remove$7(node);
  14607. }
  14608. });
  14609. }
  14610. return true;
  14611. };
  14612. var deleteTableElement = function(editor, table) {
  14613. deleteElement$2(editor, false, table);
  14614. return true;
  14615. };
  14616. var deleteCellRange = function(editor, rootElm, rng) {
  14617. return getActionFromRange(rootElm, rng).map(function(action2) {
  14618. return action2.fold(curry(deleteCellContents, editor), curry(deleteTableElement, editor), curry(emptySingleTableCells, editor), curry(emptyMultiTableCells, editor));
  14619. });
  14620. };
  14621. var deleteCaptionRange = function(editor, caption) {
  14622. return emptyElement(editor, caption);
  14623. };
  14624. var deleteTableRange = function(editor, rootElm, rng, startElm) {
  14625. return getParentCaption(rootElm, startElm).fold(function() {
  14626. return deleteCellRange(editor, rootElm, rng);
  14627. }, function(caption) {
  14628. return deleteCaptionRange(editor, caption);
  14629. }).getOr(false);
  14630. };
  14631. var deleteRange$2 = function(editor, startElm, selectedCells) {
  14632. var rootNode = SugarElement.fromDom(editor.getBody());
  14633. var rng = editor.selection.getRng();
  14634. return selectedCells.length !== 0 ? emptySingleTableCells(editor, selectedCells, Optional.none()) : deleteTableRange(editor, rootNode, rng, startElm);
  14635. };
  14636. var getParentCell = function(rootElm, elm) {
  14637. return find$3(parentsAndSelf(elm, rootElm), isTableCell$4);
  14638. };
  14639. var getParentCaption = function(rootElm, elm) {
  14640. return find$3(parentsAndSelf(elm, rootElm), isTag("caption"));
  14641. };
  14642. var deleteBetweenCells = function(editor, rootElm, forward, fromCell, from2) {
  14643. return navigate(forward, editor.getBody(), from2).bind(function(to2) {
  14644. return getParentCell(rootElm, SugarElement.fromDom(to2.getNode())).map(function(toCell) {
  14645. return eq(toCell, fromCell) === false;
  14646. });
  14647. });
  14648. };
  14649. var emptyElement = function(editor, elm) {
  14650. fillWithPaddingBr(elm);
  14651. editor.selection.setCursorLocation(elm.dom, 0);
  14652. return Optional.some(true);
  14653. };
  14654. var isDeleteOfLastCharPos = function(fromCaption, forward, from2, to2) {
  14655. return firstPositionIn(fromCaption.dom).bind(function(first2) {
  14656. return lastPositionIn(fromCaption.dom).map(function(last2) {
  14657. return forward ? from2.isEqual(first2) && to2.isEqual(last2) : from2.isEqual(last2) && to2.isEqual(first2);
  14658. });
  14659. }).getOr(true);
  14660. };
  14661. var emptyCaretCaption = function(editor, elm) {
  14662. return emptyElement(editor, elm);
  14663. };
  14664. var validateCaretCaption = function(rootElm, fromCaption, to2) {
  14665. return getParentCaption(rootElm, SugarElement.fromDom(to2.getNode())).map(function(toCaption) {
  14666. return eq(toCaption, fromCaption) === false;
  14667. });
  14668. };
  14669. var deleteCaretInsideCaption = function(editor, rootElm, forward, fromCaption, from2) {
  14670. return navigate(forward, editor.getBody(), from2).bind(function(to2) {
  14671. return isDeleteOfLastCharPos(fromCaption, forward, from2, to2) ? emptyCaretCaption(editor, fromCaption) : validateCaretCaption(rootElm, fromCaption, to2);
  14672. }).or(Optional.some(true));
  14673. };
  14674. var deleteCaretCells = function(editor, forward, rootElm, startElm) {
  14675. var from2 = CaretPosition.fromRangeStart(editor.selection.getRng());
  14676. return getParentCell(rootElm, startElm).bind(function(fromCell) {
  14677. return isEmpty$2(fromCell) ? emptyElement(editor, fromCell) : deleteBetweenCells(editor, rootElm, forward, fromCell, from2);
  14678. }).getOr(false);
  14679. };
  14680. var deleteCaretCaption = function(editor, forward, rootElm, fromCaption) {
  14681. var from2 = CaretPosition.fromRangeStart(editor.selection.getRng());
  14682. return isEmpty$2(fromCaption) ? emptyElement(editor, fromCaption) : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from2);
  14683. };
  14684. var isNearTable = function(forward, pos) {
  14685. return forward ? isBeforeTable(pos) : isAfterTable(pos);
  14686. };
  14687. var isBeforeOrAfterTable = function(editor, forward) {
  14688. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
  14689. return isNearTable(forward, fromPos) || fromPosition(forward, editor.getBody(), fromPos).exists(function(pos) {
  14690. return isNearTable(forward, pos);
  14691. });
  14692. };
  14693. var deleteCaret$3 = function(editor, forward, startElm) {
  14694. var rootElm = SugarElement.fromDom(editor.getBody());
  14695. return getParentCaption(rootElm, startElm).fold(function() {
  14696. return deleteCaretCells(editor, forward, rootElm, startElm) || isBeforeOrAfterTable(editor, forward);
  14697. }, function(fromCaption) {
  14698. return deleteCaretCaption(editor, forward, rootElm, fromCaption).getOr(false);
  14699. });
  14700. };
  14701. var backspaceDelete$9 = function(editor, forward) {
  14702. var startElm = SugarElement.fromDom(editor.selection.getStart(true));
  14703. var cells = getCellsFromEditor(editor);
  14704. return editor.selection.isCollapsed() && cells.length === 0 ? deleteCaret$3(editor, forward, startElm) : deleteRange$2(editor, startElm, cells);
  14705. };
  14706. var createRange = function(sc, so, ec, eo) {
  14707. var rng = document.createRange();
  14708. rng.setStart(sc, so);
  14709. rng.setEnd(ec, eo);
  14710. return rng;
  14711. };
  14712. var normalizeBlockSelectionRange = function(rng) {
  14713. var startPos = CaretPosition.fromRangeStart(rng);
  14714. var endPos = CaretPosition.fromRangeEnd(rng);
  14715. var rootNode = rng.commonAncestorContainer;
  14716. return fromPosition(false, rootNode, endPos).map(function(newEndPos) {
  14717. if (!isInSameBlock(startPos, endPos, rootNode) && isInSameBlock(startPos, newEndPos, rootNode)) {
  14718. return createRange(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset());
  14719. } else {
  14720. return rng;
  14721. }
  14722. }).getOr(rng);
  14723. };
  14724. var normalize = function(rng) {
  14725. return rng.collapsed ? rng : normalizeBlockSelectionRange(rng);
  14726. };
  14727. var hasOnlyOneChild$1 = function(node) {
  14728. return node.firstChild && node.firstChild === node.lastChild;
  14729. };
  14730. var isPaddingNode = function(node) {
  14731. return node.name === "br" || node.value === nbsp;
  14732. };
  14733. var isPaddedEmptyBlock = function(schema, node) {
  14734. var blockElements = schema.getBlockElements();
  14735. return blockElements[node.name] && hasOnlyOneChild$1(node) && isPaddingNode(node.firstChild);
  14736. };
  14737. var isEmptyFragmentElement = function(schema, node) {
  14738. var nonEmptyElements = schema.getNonEmptyElements();
  14739. return node && (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node));
  14740. };
  14741. var isListFragment = function(schema, fragment) {
  14742. var firstChild2 = fragment.firstChild;
  14743. var lastChild2 = fragment.lastChild;
  14744. if (firstChild2 && firstChild2.name === "meta") {
  14745. firstChild2 = firstChild2.next;
  14746. }
  14747. if (lastChild2 && lastChild2.attr("id") === "mce_marker") {
  14748. lastChild2 = lastChild2.prev;
  14749. }
  14750. if (isEmptyFragmentElement(schema, lastChild2)) {
  14751. lastChild2 = lastChild2.prev;
  14752. }
  14753. if (!firstChild2 || firstChild2 !== lastChild2) {
  14754. return false;
  14755. }
  14756. return firstChild2.name === "ul" || firstChild2.name === "ol";
  14757. };
  14758. var cleanupDomFragment = function(domFragment) {
  14759. var firstChild2 = domFragment.firstChild;
  14760. var lastChild2 = domFragment.lastChild;
  14761. if (firstChild2 && firstChild2.nodeName === "META") {
  14762. firstChild2.parentNode.removeChild(firstChild2);
  14763. }
  14764. if (lastChild2 && lastChild2.id === "mce_marker") {
  14765. lastChild2.parentNode.removeChild(lastChild2);
  14766. }
  14767. return domFragment;
  14768. };
  14769. var toDomFragment = function(dom2, serializer, fragment) {
  14770. var html = serializer.serialize(fragment);
  14771. var domFragment = dom2.createFragment(html);
  14772. return cleanupDomFragment(domFragment);
  14773. };
  14774. var listItems = function(elm) {
  14775. return filter$4(elm.childNodes, function(child2) {
  14776. return child2.nodeName === "LI";
  14777. });
  14778. };
  14779. var isPadding = function(node) {
  14780. return node.data === nbsp || isBr$5(node);
  14781. };
  14782. var isListItemPadded = function(node) {
  14783. return node && node.firstChild && node.firstChild === node.lastChild && isPadding(node.firstChild);
  14784. };
  14785. var isEmptyOrPadded = function(elm) {
  14786. return !elm.firstChild || isListItemPadded(elm);
  14787. };
  14788. var trimListItems = function(elms) {
  14789. return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1]) ? elms.slice(0, -1) : elms;
  14790. };
  14791. var getParentLi = function(dom2, node) {
  14792. var parentBlock = dom2.getParent(node, dom2.isBlock);
  14793. return parentBlock && parentBlock.nodeName === "LI" ? parentBlock : null;
  14794. };
  14795. var isParentBlockLi = function(dom2, node) {
  14796. return !!getParentLi(dom2, node);
  14797. };
  14798. var getSplit = function(parentNode, rng) {
  14799. var beforeRng = rng.cloneRange();
  14800. var afterRng = rng.cloneRange();
  14801. beforeRng.setStartBefore(parentNode);
  14802. afterRng.setEndAfter(parentNode);
  14803. return [
  14804. beforeRng.cloneContents(),
  14805. afterRng.cloneContents()
  14806. ];
  14807. };
  14808. var findFirstIn = function(node, rootNode) {
  14809. var caretPos = CaretPosition.before(node);
  14810. var caretWalker = CaretWalker(rootNode);
  14811. var newCaretPos = caretWalker.next(caretPos);
  14812. return newCaretPos ? newCaretPos.toRange() : null;
  14813. };
  14814. var findLastOf = function(node, rootNode) {
  14815. var caretPos = CaretPosition.after(node);
  14816. var caretWalker = CaretWalker(rootNode);
  14817. var newCaretPos = caretWalker.prev(caretPos);
  14818. return newCaretPos ? newCaretPos.toRange() : null;
  14819. };
  14820. var insertMiddle = function(target, elms, rootNode, rng) {
  14821. var parts = getSplit(target, rng);
  14822. var parentElm = target.parentNode;
  14823. parentElm.insertBefore(parts[0], target);
  14824. Tools.each(elms, function(li) {
  14825. parentElm.insertBefore(li, target);
  14826. });
  14827. parentElm.insertBefore(parts[1], target);
  14828. parentElm.removeChild(target);
  14829. return findLastOf(elms[elms.length - 1], rootNode);
  14830. };
  14831. var insertBefore$1 = function(target, elms, rootNode) {
  14832. var parentElm = target.parentNode;
  14833. Tools.each(elms, function(elm) {
  14834. parentElm.insertBefore(elm, target);
  14835. });
  14836. return findFirstIn(target, rootNode);
  14837. };
  14838. var insertAfter$1 = function(target, elms, rootNode, dom2) {
  14839. dom2.insertAfter(elms.reverse(), target);
  14840. return findLastOf(elms[0], rootNode);
  14841. };
  14842. var insertAtCaret$1 = function(serializer, dom2, rng, fragment) {
  14843. var domFragment = toDomFragment(dom2, serializer, fragment);
  14844. var liTarget = getParentLi(dom2, rng.startContainer);
  14845. var liElms = trimListItems(listItems(domFragment.firstChild));
  14846. var BEGINNING = 1, END = 2;
  14847. var rootNode = dom2.getRoot();
  14848. var isAt = function(location) {
  14849. var caretPos = CaretPosition.fromRangeStart(rng);
  14850. var caretWalker = CaretWalker(dom2.getRoot());
  14851. var newPos = location === BEGINNING ? caretWalker.prev(caretPos) : caretWalker.next(caretPos);
  14852. return newPos ? getParentLi(dom2, newPos.getNode()) !== liTarget : true;
  14853. };
  14854. if (isAt(BEGINNING)) {
  14855. return insertBefore$1(liTarget, liElms, rootNode);
  14856. } else if (isAt(END)) {
  14857. return insertAfter$1(liTarget, liElms, rootNode, dom2);
  14858. }
  14859. return insertMiddle(liTarget, liElms, rootNode, rng);
  14860. };
  14861. var trimOrPadLeftRight = function(dom2, rng, html) {
  14862. var root = SugarElement.fromDom(dom2.getRoot());
  14863. if (needsToBeNbspLeft(root, CaretPosition.fromRangeStart(rng))) {
  14864. html = html.replace(/^ /, "&nbsp;");
  14865. } else {
  14866. html = html.replace(/^&nbsp;/, " ");
  14867. }
  14868. if (needsToBeNbspRight(root, CaretPosition.fromRangeEnd(rng))) {
  14869. html = html.replace(/(&nbsp;| )(<br( \/)>)?$/, "&nbsp;");
  14870. } else {
  14871. html = html.replace(/&nbsp;(<br( \/)?>)?$/, " ");
  14872. }
  14873. return html;
  14874. };
  14875. var isTableCell$1 = isTableCell$5;
  14876. var isTableCellContentSelected = function(dom2, rng, cell) {
  14877. if (cell !== null) {
  14878. var endCell = dom2.getParent(rng.endContainer, isTableCell$1);
  14879. return cell === endCell && hasAllContentsSelected(SugarElement.fromDom(cell), rng);
  14880. } else {
  14881. return false;
  14882. }
  14883. };
  14884. var validInsertion = function(editor, value2, parentNode) {
  14885. if (parentNode.getAttribute("data-mce-bogus") === "all") {
  14886. parentNode.parentNode.insertBefore(editor.dom.createFragment(value2), parentNode);
  14887. } else {
  14888. var node = parentNode.firstChild;
  14889. var node2 = parentNode.lastChild;
  14890. if (!node || node === node2 && node.nodeName === "BR") {
  14891. editor.dom.setHTML(parentNode, value2);
  14892. } else {
  14893. editor.selection.setContent(value2);
  14894. }
  14895. }
  14896. };
  14897. var trimBrsFromTableCell = function(dom2, elm) {
  14898. Optional.from(dom2.getParent(elm, "td,th")).map(SugarElement.fromDom).each(trimBlockTrailingBr);
  14899. };
  14900. var reduceInlineTextElements = function(editor, merge2) {
  14901. var textInlineElements = editor.schema.getTextInlineElements();
  14902. var dom2 = editor.dom;
  14903. if (merge2) {
  14904. var root_1 = editor.getBody();
  14905. var elementUtils_1 = ElementUtils(dom2);
  14906. Tools.each(dom2.select("*[data-mce-fragment]"), function(node) {
  14907. var isInline2 = isNonNullable(textInlineElements[node.nodeName.toLowerCase()]);
  14908. if (isInline2 && hasInheritableStyles(dom2, node)) {
  14909. for (var parentNode = node.parentNode; isNonNullable(parentNode) && parentNode !== root_1; parentNode = parentNode.parentNode) {
  14910. var styleConflict = hasStyleConflict(dom2, node, parentNode);
  14911. if (styleConflict) {
  14912. break;
  14913. }
  14914. if (elementUtils_1.compare(parentNode, node)) {
  14915. dom2.remove(node, true);
  14916. break;
  14917. }
  14918. }
  14919. }
  14920. });
  14921. }
  14922. };
  14923. var markFragmentElements = function(fragment) {
  14924. var node = fragment;
  14925. while (node = node.walk()) {
  14926. if (node.type === 1) {
  14927. node.attr("data-mce-fragment", "1");
  14928. }
  14929. }
  14930. };
  14931. var unmarkFragmentElements = function(elm) {
  14932. Tools.each(elm.getElementsByTagName("*"), function(elm2) {
  14933. elm2.removeAttribute("data-mce-fragment");
  14934. });
  14935. };
  14936. var isPartOfFragment = function(node) {
  14937. return !!node.getAttribute("data-mce-fragment");
  14938. };
  14939. var canHaveChildren = function(editor, node) {
  14940. return node && !editor.schema.getShortEndedElements()[node.nodeName];
  14941. };
  14942. var moveSelectionToMarker = function(editor, marker) {
  14943. var nextRng;
  14944. var dom2 = editor.dom;
  14945. var selection = editor.selection;
  14946. if (!marker) {
  14947. return;
  14948. }
  14949. selection.scrollIntoView(marker);
  14950. var parentEditableElm = getContentEditableRoot$1(editor.getBody(), marker);
  14951. if (dom2.getContentEditable(parentEditableElm) === "false") {
  14952. dom2.remove(marker);
  14953. selection.select(parentEditableElm);
  14954. return;
  14955. }
  14956. var rng = dom2.createRng();
  14957. var node = marker.previousSibling;
  14958. if (isText$7(node)) {
  14959. rng.setStart(node, node.nodeValue.length);
  14960. if (!Env.ie) {
  14961. var node2 = marker.nextSibling;
  14962. if (isText$7(node2)) {
  14963. node.appendData(node2.data);
  14964. node2.parentNode.removeChild(node2);
  14965. }
  14966. }
  14967. } else {
  14968. rng.setStartBefore(marker);
  14969. rng.setEndBefore(marker);
  14970. }
  14971. var findNextCaretRng = function(rng2) {
  14972. var caretPos = CaretPosition.fromRangeStart(rng2);
  14973. var caretWalker = CaretWalker(editor.getBody());
  14974. caretPos = caretWalker.next(caretPos);
  14975. if (caretPos) {
  14976. return caretPos.toRange();
  14977. }
  14978. };
  14979. var parentBlock = dom2.getParent(marker, dom2.isBlock);
  14980. dom2.remove(marker);
  14981. if (parentBlock && dom2.isEmpty(parentBlock)) {
  14982. editor.$(parentBlock).empty();
  14983. rng.setStart(parentBlock, 0);
  14984. rng.setEnd(parentBlock, 0);
  14985. if (!isTableCell$1(parentBlock) && !isPartOfFragment(parentBlock) && (nextRng = findNextCaretRng(rng))) {
  14986. rng = nextRng;
  14987. dom2.remove(parentBlock);
  14988. } else {
  14989. dom2.add(parentBlock, dom2.create("br", { "data-mce-bogus": "1" }));
  14990. }
  14991. }
  14992. selection.setRng(rng);
  14993. };
  14994. var deleteSelectedContent = function(editor) {
  14995. var dom2 = editor.dom;
  14996. var rng = normalize(editor.selection.getRng());
  14997. editor.selection.setRng(rng);
  14998. var startCell = dom2.getParent(rng.startContainer, isTableCell$1);
  14999. if (isTableCellContentSelected(dom2, rng, startCell)) {
  15000. deleteCellContents(editor, rng, SugarElement.fromDom(startCell));
  15001. } else {
  15002. editor.getDoc().execCommand("Delete", false, null);
  15003. }
  15004. };
  15005. var insertHtmlAtCaret = function(editor, value2, details) {
  15006. var parentNode;
  15007. var rng, node;
  15008. var selection = editor.selection;
  15009. var dom2 = editor.dom;
  15010. if (/^ | $/.test(value2)) {
  15011. value2 = trimOrPadLeftRight(dom2, selection.getRng(), value2);
  15012. }
  15013. var parser = editor.parser;
  15014. var merge2 = details.merge;
  15015. var serializer = HtmlSerializer({ validate: shouldValidate(editor) }, editor.schema);
  15016. var bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">&#xFEFF;</span>';
  15017. var args = editor.fire("BeforeSetContent", {
  15018. content: value2,
  15019. format: "html",
  15020. selection: true,
  15021. paste: details.paste
  15022. });
  15023. if (args.isDefaultPrevented()) {
  15024. editor.fire("SetContent", {
  15025. content: args.content,
  15026. format: "html",
  15027. selection: true,
  15028. paste: details.paste
  15029. });
  15030. return;
  15031. }
  15032. value2 = args.content;
  15033. if (value2.indexOf("{$caret}") === -1) {
  15034. value2 += "{$caret}";
  15035. }
  15036. value2 = value2.replace(/\{\$caret\}/, bookmarkHtml);
  15037. rng = selection.getRng();
  15038. var caretElement = rng.startContainer || (rng.parentElement ? rng.parentElement() : null);
  15039. var body = editor.getBody();
  15040. if (caretElement === body && selection.isCollapsed()) {
  15041. if (dom2.isBlock(body.firstChild) && canHaveChildren(editor, body.firstChild) && dom2.isEmpty(body.firstChild)) {
  15042. rng = dom2.createRng();
  15043. rng.setStart(body.firstChild, 0);
  15044. rng.setEnd(body.firstChild, 0);
  15045. selection.setRng(rng);
  15046. }
  15047. }
  15048. if (!selection.isCollapsed()) {
  15049. deleteSelectedContent(editor);
  15050. }
  15051. parentNode = selection.getNode();
  15052. var parserArgs = {
  15053. context: parentNode.nodeName.toLowerCase(),
  15054. data: details.data,
  15055. insert: true
  15056. };
  15057. var fragment = parser.parse(value2, parserArgs);
  15058. if (details.paste === true && isListFragment(editor.schema, fragment) && isParentBlockLi(dom2, parentNode)) {
  15059. rng = insertAtCaret$1(serializer, dom2, selection.getRng(), fragment);
  15060. selection.setRng(rng);
  15061. editor.fire("SetContent", args);
  15062. return;
  15063. }
  15064. markFragmentElements(fragment);
  15065. node = fragment.lastChild;
  15066. if (node.attr("id") === "mce_marker") {
  15067. var marker = node;
  15068. for (node = node.prev; node; node = node.walk(true)) {
  15069. if (node.type === 3 || !dom2.isBlock(node.name)) {
  15070. if (editor.schema.isValidChild(node.parent.name, "span")) {
  15071. node.parent.insert(marker, node, node.name === "br");
  15072. }
  15073. break;
  15074. }
  15075. }
  15076. }
  15077. editor._selectionOverrides.showBlockCaretContainer(parentNode);
  15078. if (!parserArgs.invalid) {
  15079. value2 = serializer.serialize(fragment);
  15080. validInsertion(editor, value2, parentNode);
  15081. } else {
  15082. editor.selection.setContent(bookmarkHtml);
  15083. parentNode = selection.getNode();
  15084. var rootNode = editor.getBody();
  15085. if (parentNode.nodeType === 9) {
  15086. parentNode = node = rootNode;
  15087. } else {
  15088. node = parentNode;
  15089. }
  15090. while (node !== rootNode) {
  15091. parentNode = node;
  15092. node = node.parentNode;
  15093. }
  15094. value2 = parentNode === rootNode ? rootNode.innerHTML : dom2.getOuterHTML(parentNode);
  15095. value2 = serializer.serialize(parser.parse(value2.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  15096. return serializer.serialize(fragment);
  15097. })));
  15098. if (parentNode === rootNode) {
  15099. dom2.setHTML(rootNode, value2);
  15100. } else {
  15101. dom2.setOuterHTML(parentNode, value2);
  15102. }
  15103. }
  15104. reduceInlineTextElements(editor, merge2);
  15105. moveSelectionToMarker(editor, dom2.get("mce_marker"));
  15106. unmarkFragmentElements(editor.getBody());
  15107. trimBrsFromTableCell(dom2, selection.getStart());
  15108. editor.fire("SetContent", args);
  15109. editor.addVisual();
  15110. };
  15111. var traverse = function(node, fn) {
  15112. fn(node);
  15113. if (node.firstChild) {
  15114. traverse(node.firstChild, fn);
  15115. }
  15116. if (node.next) {
  15117. traverse(node.next, fn);
  15118. }
  15119. };
  15120. var findMatchingNodes = function(nodeFilters, attributeFilters, node) {
  15121. var nodeMatches = {};
  15122. var attrMatches = {};
  15123. var matches2 = [];
  15124. if (node.firstChild) {
  15125. traverse(node.firstChild, function(node2) {
  15126. each$k(nodeFilters, function(filter2) {
  15127. if (filter2.name === node2.name) {
  15128. if (nodeMatches[filter2.name]) {
  15129. nodeMatches[filter2.name].nodes.push(node2);
  15130. } else {
  15131. nodeMatches[filter2.name] = {
  15132. filter: filter2,
  15133. nodes: [node2]
  15134. };
  15135. }
  15136. }
  15137. });
  15138. each$k(attributeFilters, function(filter2) {
  15139. if (typeof node2.attr(filter2.name) === "string") {
  15140. if (attrMatches[filter2.name]) {
  15141. attrMatches[filter2.name].nodes.push(node2);
  15142. } else {
  15143. attrMatches[filter2.name] = {
  15144. filter: filter2,
  15145. nodes: [node2]
  15146. };
  15147. }
  15148. }
  15149. });
  15150. });
  15151. }
  15152. for (var name_1 in nodeMatches) {
  15153. if (has$2(nodeMatches, name_1)) {
  15154. matches2.push(nodeMatches[name_1]);
  15155. }
  15156. }
  15157. for (var name_2 in attrMatches) {
  15158. if (has$2(attrMatches, name_2)) {
  15159. matches2.push(attrMatches[name_2]);
  15160. }
  15161. }
  15162. return matches2;
  15163. };
  15164. var filter$1 = function(nodeFilters, attributeFilters, node) {
  15165. var matches2 = findMatchingNodes(nodeFilters, attributeFilters, node);
  15166. each$k(matches2, function(match2) {
  15167. each$k(match2.filter.callbacks, function(callback) {
  15168. callback(match2.nodes, match2.filter.name, {});
  15169. });
  15170. });
  15171. };
  15172. var defaultFormat$1 = "html";
  15173. var isTreeNode = function(content) {
  15174. return content instanceof AstNode;
  15175. };
  15176. var moveSelection = function(editor) {
  15177. if (hasFocus(editor)) {
  15178. firstPositionIn(editor.getBody()).each(function(pos) {
  15179. var node = pos.getNode();
  15180. var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos;
  15181. editor.selection.setRng(caretPos.toRange());
  15182. });
  15183. }
  15184. };
  15185. var setEditorHtml = function(editor, html, noSelection) {
  15186. editor.dom.setHTML(editor.getBody(), html);
  15187. if (noSelection !== true) {
  15188. moveSelection(editor);
  15189. }
  15190. };
  15191. var setContentString = function(editor, body, content, args) {
  15192. if (content.length === 0 || /^\s+$/.test(content)) {
  15193. var padd = '<br data-mce-bogus="1">';
  15194. if (body.nodeName === "TABLE") {
  15195. content = "<tr><td>" + padd + "</td></tr>";
  15196. } else if (/^(UL|OL)$/.test(body.nodeName)) {
  15197. content = "<li>" + padd + "</li>";
  15198. }
  15199. var forcedRootBlockName = getForcedRootBlock(editor);
  15200. if (forcedRootBlockName && editor.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) {
  15201. content = padd;
  15202. content = editor.dom.createHTML(forcedRootBlockName, getForcedRootBlockAttrs(editor), content);
  15203. } else if (!content) {
  15204. content = '<br data-mce-bogus="1">';
  15205. }
  15206. setEditorHtml(editor, content, args.no_selection);
  15207. editor.fire("SetContent", args);
  15208. } else {
  15209. if (args.format !== "raw") {
  15210. content = HtmlSerializer({ validate: editor.validate }, editor.schema).serialize(editor.parser.parse(content, {
  15211. isRootContent: true,
  15212. insert: true
  15213. }));
  15214. }
  15215. args.content = isWsPreserveElement(SugarElement.fromDom(body)) ? content : Tools.trim(content);
  15216. setEditorHtml(editor, args.content, args.no_selection);
  15217. if (!args.no_events) {
  15218. editor.fire("SetContent", args);
  15219. }
  15220. }
  15221. return args.content;
  15222. };
  15223. var setContentTree = function(editor, body, content, args) {
  15224. filter$1(editor.parser.getNodeFilters(), editor.parser.getAttributeFilters(), content);
  15225. var html = HtmlSerializer({ validate: editor.validate }, editor.schema).serialize(content);
  15226. args.content = isWsPreserveElement(SugarElement.fromDom(body)) ? html : Tools.trim(html);
  15227. setEditorHtml(editor, args.content, args.no_selection);
  15228. if (!args.no_events) {
  15229. editor.fire("SetContent", args);
  15230. }
  15231. return content;
  15232. };
  15233. var setupArgs$2 = function(args, content) {
  15234. return __assign(__assign({ format: defaultFormat$1 }, args), {
  15235. set: true,
  15236. content: isTreeNode(content) ? "" : content
  15237. });
  15238. };
  15239. var setContentInternal = function(editor, content, args) {
  15240. var defaultedArgs = setupArgs$2(args, content);
  15241. var updatedArgs = args.no_events ? defaultedArgs : editor.fire("BeforeSetContent", defaultedArgs);
  15242. if (!isTreeNode(content)) {
  15243. content = updatedArgs.content;
  15244. }
  15245. return Optional.from(editor.getBody()).fold(constant(content), function(body) {
  15246. return isTreeNode(content) ? setContentTree(editor, body, content, updatedArgs) : setContentString(editor, body, content, updatedArgs);
  15247. });
  15248. };
  15249. var sibling = function(scope, predicate) {
  15250. return sibling$2(scope, predicate).isSome();
  15251. };
  15252. var ensureIsRoot = function(isRoot) {
  15253. return isFunction(isRoot) ? isRoot : never;
  15254. };
  15255. var ancestor = function(scope, transform, isRoot) {
  15256. var element = scope.dom;
  15257. var stop2 = ensureIsRoot(isRoot);
  15258. while (element.parentNode) {
  15259. element = element.parentNode;
  15260. var el = SugarElement.fromDom(element);
  15261. var transformed = transform(el);
  15262. if (transformed.isSome()) {
  15263. return transformed;
  15264. } else if (stop2(el)) {
  15265. break;
  15266. }
  15267. }
  15268. return Optional.none();
  15269. };
  15270. var closest$1 = function(scope, transform, isRoot) {
  15271. var current = transform(scope);
  15272. var stop2 = ensureIsRoot(isRoot);
  15273. return current.orThunk(function() {
  15274. return stop2(scope) ? Optional.none() : ancestor(scope, transform, stop2);
  15275. });
  15276. };
  15277. var isEq$3 = isEq$5;
  15278. var matchesUnInheritedFormatSelector = function(ed, node, name2) {
  15279. var formatList = ed.formatter.get(name2);
  15280. if (formatList) {
  15281. for (var i = 0; i < formatList.length; i++) {
  15282. var format = formatList[i];
  15283. if (isSelectorFormat(format) && format.inherit === false && ed.dom.is(node, format.selector)) {
  15284. return true;
  15285. }
  15286. }
  15287. }
  15288. return false;
  15289. };
  15290. var matchParents = function(editor, node, name2, vars, similar) {
  15291. var root = editor.dom.getRoot();
  15292. if (node === root) {
  15293. return false;
  15294. }
  15295. node = editor.dom.getParent(node, function(node2) {
  15296. if (matchesUnInheritedFormatSelector(editor, node2, name2)) {
  15297. return true;
  15298. }
  15299. return node2.parentNode === root || !!matchNode(editor, node2, name2, vars, true);
  15300. });
  15301. return !!matchNode(editor, node, name2, vars, similar);
  15302. };
  15303. var matchName$1 = function(dom2, node, format) {
  15304. if (isEq$3(node, format.inline)) {
  15305. return true;
  15306. }
  15307. if (isEq$3(node, format.block)) {
  15308. return true;
  15309. }
  15310. if (format.selector) {
  15311. return node.nodeType === 1 && dom2.is(node, format.selector);
  15312. }
  15313. };
  15314. var matchItems = function(dom2, node, format, itemName, similar, vars) {
  15315. var items = format[itemName];
  15316. if (isFunction(format.onmatch)) {
  15317. return format.onmatch(node, format, itemName);
  15318. }
  15319. if (items) {
  15320. if (isUndefined(items.length)) {
  15321. for (var key in items) {
  15322. if (has$2(items, key)) {
  15323. var value2 = itemName === "attributes" ? dom2.getAttrib(node, key) : getStyle(dom2, node, key);
  15324. var expectedValue = replaceVars(items[key], vars);
  15325. var isEmptyValue = isNullable(value2) || isEmpty$3(value2);
  15326. if (isEmptyValue && isNullable(expectedValue)) {
  15327. continue;
  15328. }
  15329. if (similar && isEmptyValue && !format.exact) {
  15330. return false;
  15331. }
  15332. if ((!similar || format.exact) && !isEq$3(value2, normalizeStyleValue(dom2, expectedValue, key))) {
  15333. return false;
  15334. }
  15335. }
  15336. }
  15337. } else {
  15338. for (var i = 0; i < items.length; i++) {
  15339. if (itemName === "attributes" ? dom2.getAttrib(node, items[i]) : getStyle(dom2, node, items[i])) {
  15340. return true;
  15341. }
  15342. }
  15343. }
  15344. }
  15345. return true;
  15346. };
  15347. var matchNode = function(ed, node, name2, vars, similar) {
  15348. var formatList = ed.formatter.get(name2);
  15349. var dom2 = ed.dom;
  15350. if (formatList && node) {
  15351. for (var i = 0; i < formatList.length; i++) {
  15352. var format = formatList[i];
  15353. if (matchName$1(ed.dom, node, format) && matchItems(dom2, node, format, "attributes", similar, vars) && matchItems(dom2, node, format, "styles", similar, vars)) {
  15354. var classes = format.classes;
  15355. if (classes) {
  15356. for (var x = 0; x < classes.length; x++) {
  15357. if (!ed.dom.hasClass(node, replaceVars(classes[x], vars))) {
  15358. return;
  15359. }
  15360. }
  15361. }
  15362. return format;
  15363. }
  15364. }
  15365. }
  15366. };
  15367. var match$2 = function(editor, name2, vars, node, similar) {
  15368. if (node) {
  15369. return matchParents(editor, node, name2, vars, similar);
  15370. }
  15371. node = editor.selection.getNode();
  15372. if (matchParents(editor, node, name2, vars, similar)) {
  15373. return true;
  15374. }
  15375. var startNode = editor.selection.getStart();
  15376. if (startNode !== node) {
  15377. if (matchParents(editor, startNode, name2, vars, similar)) {
  15378. return true;
  15379. }
  15380. }
  15381. return false;
  15382. };
  15383. var matchAll = function(editor, names, vars) {
  15384. var matchedFormatNames = [];
  15385. var checkedMap = {};
  15386. var startElement = editor.selection.getStart();
  15387. editor.dom.getParent(startElement, function(node) {
  15388. for (var i = 0; i < names.length; i++) {
  15389. var name_1 = names[i];
  15390. if (!checkedMap[name_1] && matchNode(editor, node, name_1, vars)) {
  15391. checkedMap[name_1] = true;
  15392. matchedFormatNames.push(name_1);
  15393. }
  15394. }
  15395. }, editor.dom.getRoot());
  15396. return matchedFormatNames;
  15397. };
  15398. var closest = function(editor, names) {
  15399. var isRoot = function(elm) {
  15400. return eq(elm, SugarElement.fromDom(editor.getBody()));
  15401. };
  15402. var match2 = function(elm, name2) {
  15403. return matchNode(editor, elm.dom, name2) ? Optional.some(name2) : Optional.none();
  15404. };
  15405. return Optional.from(editor.selection.getStart(true)).bind(function(rawElm) {
  15406. return closest$1(SugarElement.fromDom(rawElm), function(elm) {
  15407. return findMap(names, function(name2) {
  15408. return match2(elm, name2);
  15409. });
  15410. }, isRoot);
  15411. }).getOrNull();
  15412. };
  15413. var canApply = function(editor, name2) {
  15414. var formatList = editor.formatter.get(name2);
  15415. var dom2 = editor.dom;
  15416. if (formatList) {
  15417. var startNode = editor.selection.getStart();
  15418. var parents2 = getParents$2(dom2, startNode);
  15419. for (var x = formatList.length - 1; x >= 0; x--) {
  15420. var format = formatList[x];
  15421. if (!isSelectorFormat(format) || isNonNullable(format.defaultBlock)) {
  15422. return true;
  15423. }
  15424. for (var i = parents2.length - 1; i >= 0; i--) {
  15425. if (dom2.is(parents2[i], format.selector)) {
  15426. return true;
  15427. }
  15428. }
  15429. }
  15430. }
  15431. return false;
  15432. };
  15433. var matchAllOnNode = function(editor, node, formatNames) {
  15434. return foldl(formatNames, function(acc, name2) {
  15435. var matchSimilar = isVariableFormatName(editor, name2);
  15436. if (editor.formatter.matchNode(node, name2, {}, matchSimilar)) {
  15437. return acc.concat([name2]);
  15438. } else {
  15439. return acc;
  15440. }
  15441. }, []);
  15442. };
  15443. var ZWSP = ZWSP$1, CARET_ID = "_mce_caret";
  15444. var importNode = function(ownerDocument, node) {
  15445. return ownerDocument.importNode(node, true);
  15446. };
  15447. var getEmptyCaretContainers = function(node) {
  15448. var nodes = [];
  15449. while (node) {
  15450. if (node.nodeType === 3 && node.nodeValue !== ZWSP || node.childNodes.length > 1) {
  15451. return [];
  15452. }
  15453. if (node.nodeType === 1) {
  15454. nodes.push(node);
  15455. }
  15456. node = node.firstChild;
  15457. }
  15458. return nodes;
  15459. };
  15460. var isCaretContainerEmpty = function(node) {
  15461. return getEmptyCaretContainers(node).length > 0;
  15462. };
  15463. var findFirstTextNode = function(node) {
  15464. if (node) {
  15465. var walker = new DomTreeWalker(node, node);
  15466. for (node = walker.current(); node; node = walker.next()) {
  15467. if (isText$7(node)) {
  15468. return node;
  15469. }
  15470. }
  15471. }
  15472. return null;
  15473. };
  15474. var createCaretContainer = function(fill) {
  15475. var caretContainer = SugarElement.fromTag("span");
  15476. setAll$1(caretContainer, {
  15477. "id": CARET_ID,
  15478. "data-mce-bogus": "1",
  15479. "data-mce-type": "format-caret"
  15480. });
  15481. if (fill) {
  15482. append$1(caretContainer, SugarElement.fromText(ZWSP));
  15483. }
  15484. return caretContainer;
  15485. };
  15486. var trimZwspFromCaretContainer = function(caretContainerNode) {
  15487. var textNode = findFirstTextNode(caretContainerNode);
  15488. if (textNode && textNode.nodeValue.charAt(0) === ZWSP) {
  15489. textNode.deleteData(0, 1);
  15490. }
  15491. return textNode;
  15492. };
  15493. var removeCaretContainerNode = function(editor, node, moveCaret2) {
  15494. if (moveCaret2 === void 0) {
  15495. moveCaret2 = true;
  15496. }
  15497. var dom2 = editor.dom, selection = editor.selection;
  15498. if (isCaretContainerEmpty(node)) {
  15499. deleteElement$2(editor, false, SugarElement.fromDom(node), moveCaret2);
  15500. } else {
  15501. var rng = selection.getRng();
  15502. var block = dom2.getParent(node, dom2.isBlock);
  15503. var startContainer = rng.startContainer;
  15504. var startOffset = rng.startOffset;
  15505. var endContainer = rng.endContainer;
  15506. var endOffset = rng.endOffset;
  15507. var textNode = trimZwspFromCaretContainer(node);
  15508. dom2.remove(node, true);
  15509. if (startContainer === textNode && startOffset > 0) {
  15510. rng.setStart(textNode, startOffset - 1);
  15511. }
  15512. if (endContainer === textNode && endOffset > 0) {
  15513. rng.setEnd(textNode, endOffset - 1);
  15514. }
  15515. if (block && dom2.isEmpty(block)) {
  15516. fillWithPaddingBr(SugarElement.fromDom(block));
  15517. }
  15518. selection.setRng(rng);
  15519. }
  15520. };
  15521. var removeCaretContainer = function(editor, node, moveCaret2) {
  15522. if (moveCaret2 === void 0) {
  15523. moveCaret2 = true;
  15524. }
  15525. var dom2 = editor.dom, selection = editor.selection;
  15526. if (!node) {
  15527. node = getParentCaretContainer(editor.getBody(), selection.getStart());
  15528. if (!node) {
  15529. while (node = dom2.get(CARET_ID)) {
  15530. removeCaretContainerNode(editor, node, false);
  15531. }
  15532. }
  15533. } else {
  15534. removeCaretContainerNode(editor, node, moveCaret2);
  15535. }
  15536. };
  15537. var insertCaretContainerNode = function(editor, caretContainer, formatNode) {
  15538. var dom2 = editor.dom, block = dom2.getParent(formatNode, curry(isTextBlock$1, editor));
  15539. if (block && dom2.isEmpty(block)) {
  15540. formatNode.parentNode.replaceChild(caretContainer, formatNode);
  15541. } else {
  15542. removeTrailingBr(SugarElement.fromDom(formatNode));
  15543. if (dom2.isEmpty(formatNode)) {
  15544. formatNode.parentNode.replaceChild(caretContainer, formatNode);
  15545. } else {
  15546. dom2.insertAfter(caretContainer, formatNode);
  15547. }
  15548. }
  15549. };
  15550. var appendNode = function(parentNode, node) {
  15551. parentNode.appendChild(node);
  15552. return node;
  15553. };
  15554. var insertFormatNodesIntoCaretContainer = function(formatNodes, caretContainer) {
  15555. var innerMostFormatNode = foldr(formatNodes, function(parentNode, formatNode) {
  15556. return appendNode(parentNode, formatNode.cloneNode(false));
  15557. }, caretContainer);
  15558. return appendNode(innerMostFormatNode, innerMostFormatNode.ownerDocument.createTextNode(ZWSP));
  15559. };
  15560. var cleanFormatNode = function(editor, caretContainer, formatNode, name2, vars, similar) {
  15561. var formatter = editor.formatter;
  15562. var dom2 = editor.dom;
  15563. var validFormats = filter$4(keys(formatter.get()), function(formatName) {
  15564. return formatName !== name2 && !contains$2(formatName, "removeformat");
  15565. });
  15566. var matchedFormats = matchAllOnNode(editor, formatNode, validFormats);
  15567. var uniqueFormats = filter$4(matchedFormats, function(fmtName) {
  15568. return !areSimilarFormats(editor, fmtName, name2);
  15569. });
  15570. if (uniqueFormats.length > 0) {
  15571. var clonedFormatNode = formatNode.cloneNode(false);
  15572. dom2.add(caretContainer, clonedFormatNode);
  15573. formatter.remove(name2, vars, clonedFormatNode, similar);
  15574. dom2.remove(clonedFormatNode);
  15575. return Optional.some(clonedFormatNode);
  15576. } else {
  15577. return Optional.none();
  15578. }
  15579. };
  15580. var applyCaretFormat = function(editor, name2, vars) {
  15581. var caretContainer, textNode;
  15582. var selection = editor.selection;
  15583. var selectionRng = selection.getRng();
  15584. var offset = selectionRng.startOffset;
  15585. var container = selectionRng.startContainer;
  15586. var text = container.nodeValue;
  15587. caretContainer = getParentCaretContainer(editor.getBody(), selection.getStart());
  15588. if (caretContainer) {
  15589. textNode = findFirstTextNode(caretContainer);
  15590. }
  15591. var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/;
  15592. if (text && offset > 0 && offset < text.length && wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) {
  15593. var bookmark = selection.getBookmark();
  15594. selectionRng.collapse(true);
  15595. var rng = expandRng(editor, selectionRng, editor.formatter.get(name2));
  15596. rng = split(rng);
  15597. editor.formatter.apply(name2, vars, rng);
  15598. selection.moveToBookmark(bookmark);
  15599. } else {
  15600. if (!caretContainer || textNode.nodeValue !== ZWSP) {
  15601. caretContainer = importNode(editor.getDoc(), createCaretContainer(true).dom);
  15602. textNode = caretContainer.firstChild;
  15603. selectionRng.insertNode(caretContainer);
  15604. offset = 1;
  15605. editor.formatter.apply(name2, vars, caretContainer);
  15606. } else {
  15607. editor.formatter.apply(name2, vars, caretContainer);
  15608. }
  15609. selection.setCursorLocation(textNode, offset);
  15610. }
  15611. };
  15612. var removeCaretFormat = function(editor, name2, vars, similar) {
  15613. var dom2 = editor.dom;
  15614. var selection = editor.selection;
  15615. var hasContentAfter, node, formatNode;
  15616. var parents2 = [];
  15617. var rng = selection.getRng();
  15618. var container = rng.startContainer;
  15619. var offset = rng.startOffset;
  15620. node = container;
  15621. if (container.nodeType === 3) {
  15622. if (offset !== container.nodeValue.length) {
  15623. hasContentAfter = true;
  15624. }
  15625. node = node.parentNode;
  15626. }
  15627. while (node) {
  15628. if (matchNode(editor, node, name2, vars, similar)) {
  15629. formatNode = node;
  15630. break;
  15631. }
  15632. if (node.nextSibling) {
  15633. hasContentAfter = true;
  15634. }
  15635. parents2.push(node);
  15636. node = node.parentNode;
  15637. }
  15638. if (!formatNode) {
  15639. return;
  15640. }
  15641. if (hasContentAfter) {
  15642. var bookmark = selection.getBookmark();
  15643. rng.collapse(true);
  15644. var expandedRng = expandRng(editor, rng, editor.formatter.get(name2), true);
  15645. expandedRng = split(expandedRng);
  15646. editor.formatter.remove(name2, vars, expandedRng, similar);
  15647. selection.moveToBookmark(bookmark);
  15648. } else {
  15649. var caretContainer = getParentCaretContainer(editor.getBody(), formatNode);
  15650. var newCaretContainer = createCaretContainer(false).dom;
  15651. insertCaretContainerNode(editor, newCaretContainer, caretContainer !== null ? caretContainer : formatNode);
  15652. var cleanedFormatNode = cleanFormatNode(editor, newCaretContainer, formatNode, name2, vars, similar);
  15653. var caretTextNode = insertFormatNodesIntoCaretContainer(parents2.concat(cleanedFormatNode.toArray()), newCaretContainer);
  15654. removeCaretContainerNode(editor, caretContainer, false);
  15655. selection.setCursorLocation(caretTextNode, 1);
  15656. if (dom2.isEmpty(formatNode)) {
  15657. dom2.remove(formatNode);
  15658. }
  15659. }
  15660. };
  15661. var disableCaretContainer = function(editor, keyCode) {
  15662. var selection = editor.selection, body = editor.getBody();
  15663. removeCaretContainer(editor, null, false);
  15664. if ((keyCode === 8 || keyCode === 46) && selection.isCollapsed() && selection.getStart().innerHTML === ZWSP) {
  15665. removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
  15666. }
  15667. if (keyCode === 37 || keyCode === 39) {
  15668. removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
  15669. }
  15670. };
  15671. var setup$k = function(editor) {
  15672. editor.on("mouseup keydown", function(e) {
  15673. disableCaretContainer(editor, e.keyCode);
  15674. });
  15675. };
  15676. var replaceWithCaretFormat = function(targetNode, formatNodes) {
  15677. var caretContainer = createCaretContainer(false);
  15678. var innerMost = insertFormatNodesIntoCaretContainer(formatNodes, caretContainer.dom);
  15679. before$4(SugarElement.fromDom(targetNode), caretContainer);
  15680. remove$7(SugarElement.fromDom(targetNode));
  15681. return CaretPosition(innerMost, 0);
  15682. };
  15683. var isFormatElement = function(editor, element) {
  15684. var inlineElements = editor.schema.getTextInlineElements();
  15685. return has$2(inlineElements, name(element)) && !isCaretNode(element.dom) && !isBogus$2(element.dom);
  15686. };
  15687. var isEmptyCaretFormatElement = function(element) {
  15688. return isCaretNode(element.dom) && isCaretContainerEmpty(element.dom);
  15689. };
  15690. var postProcessHooks = {};
  15691. var filter = filter$2;
  15692. var each$b = each$i;
  15693. var addPostProcessHook = function(name2, hook) {
  15694. var hooks = postProcessHooks[name2];
  15695. if (!hooks) {
  15696. postProcessHooks[name2] = [];
  15697. }
  15698. postProcessHooks[name2].push(hook);
  15699. };
  15700. var postProcess$1 = function(name2, editor) {
  15701. each$b(postProcessHooks[name2], function(hook) {
  15702. hook(editor);
  15703. });
  15704. };
  15705. addPostProcessHook("pre", function(editor) {
  15706. var rng = editor.selection.getRng();
  15707. var blocks2;
  15708. var hasPreSibling = function(pre) {
  15709. return isPre(pre.previousSibling) && indexOf$1(blocks2, pre.previousSibling) !== -1;
  15710. };
  15711. var joinPre = function(pre1, pre2) {
  15712. DomQuery(pre2).remove();
  15713. DomQuery(pre1).append("<br><br>").append(pre2.childNodes);
  15714. };
  15715. var isPre = matchNodeNames(["pre"]);
  15716. if (!rng.collapsed) {
  15717. blocks2 = editor.selection.getSelectedBlocks();
  15718. each$b(filter(filter(blocks2, isPre), hasPreSibling), function(pre) {
  15719. joinPre(pre.previousSibling, pre);
  15720. });
  15721. }
  15722. });
  15723. var each$a = Tools.each;
  15724. var isElementNode$1 = function(node) {
  15725. return isElement$5(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$2(node);
  15726. };
  15727. var findElementSibling = function(node, siblingName) {
  15728. for (var sibling2 = node; sibling2; sibling2 = sibling2[siblingName]) {
  15729. if (isText$7(sibling2) && isNotEmpty(sibling2.data)) {
  15730. return node;
  15731. }
  15732. if (isElement$5(sibling2) && !isBookmarkNode$1(sibling2)) {
  15733. return sibling2;
  15734. }
  15735. }
  15736. return node;
  15737. };
  15738. var mergeSiblingsNodes = function(dom2, prev, next) {
  15739. var elementUtils = ElementUtils(dom2);
  15740. if (prev && next) {
  15741. prev = findElementSibling(prev, "previousSibling");
  15742. next = findElementSibling(next, "nextSibling");
  15743. if (elementUtils.compare(prev, next)) {
  15744. for (var sibling2 = prev.nextSibling; sibling2 && sibling2 !== next; ) {
  15745. var tmpSibling = sibling2;
  15746. sibling2 = sibling2.nextSibling;
  15747. prev.appendChild(tmpSibling);
  15748. }
  15749. dom2.remove(next);
  15750. Tools.each(Tools.grep(next.childNodes), function(node) {
  15751. prev.appendChild(node);
  15752. });
  15753. return prev;
  15754. }
  15755. }
  15756. return next;
  15757. };
  15758. var mergeSiblings = function(dom2, format, vars, node) {
  15759. if (node && format.merge_siblings !== false) {
  15760. var newNode = mergeSiblingsNodes(dom2, getNonWhiteSpaceSibling(node), node);
  15761. mergeSiblingsNodes(dom2, newNode, getNonWhiteSpaceSibling(newNode, true));
  15762. }
  15763. };
  15764. var clearChildStyles = function(dom2, format, node) {
  15765. if (format.clear_child_styles) {
  15766. var selector = format.links ? "*:not(a)" : "*";
  15767. each$a(dom2.select(selector, node), function(node2) {
  15768. if (isElementNode$1(node2)) {
  15769. each$a(format.styles, function(value2, name2) {
  15770. dom2.setStyle(node2, name2, "");
  15771. });
  15772. }
  15773. });
  15774. }
  15775. };
  15776. var processChildElements = function(node, filter2, process2) {
  15777. each$a(node.childNodes, function(node2) {
  15778. if (isElementNode$1(node2)) {
  15779. if (filter2(node2)) {
  15780. process2(node2);
  15781. }
  15782. if (node2.hasChildNodes()) {
  15783. processChildElements(node2, filter2, process2);
  15784. }
  15785. }
  15786. });
  15787. };
  15788. var unwrapEmptySpan = function(dom2, node) {
  15789. if (node.nodeName === "SPAN" && dom2.getAttribs(node).length === 0) {
  15790. dom2.remove(node, true);
  15791. }
  15792. };
  15793. var hasStyle = function(dom2, name2) {
  15794. return function(node) {
  15795. return !!(node && getStyle(dom2, node, name2));
  15796. };
  15797. };
  15798. var applyStyle = function(dom2, name2, value2) {
  15799. return function(node) {
  15800. dom2.setStyle(node, name2, value2);
  15801. if (node.getAttribute("style") === "") {
  15802. node.removeAttribute("style");
  15803. }
  15804. unwrapEmptySpan(dom2, node);
  15805. };
  15806. };
  15807. var removeResult = Adt.generate([
  15808. { keep: [] },
  15809. { rename: ["name"] },
  15810. { removed: [] }
  15811. ]);
  15812. var MCE_ATTR_RE = /^(src|href|style)$/;
  15813. var each$9 = Tools.each;
  15814. var isEq$2 = isEq$5;
  15815. var isTableCellOrRow = function(node) {
  15816. return /^(TR|TH|TD)$/.test(node.nodeName);
  15817. };
  15818. var isChildOfInlineParent = function(dom2, node, parent2) {
  15819. return dom2.isChildOf(node, parent2) && node !== parent2 && !dom2.isBlock(parent2);
  15820. };
  15821. var getContainer = function(ed, rng, start2) {
  15822. var container = rng[start2 ? "startContainer" : "endContainer"];
  15823. var offset = rng[start2 ? "startOffset" : "endOffset"];
  15824. if (isElement$5(container)) {
  15825. var lastIdx = container.childNodes.length - 1;
  15826. if (!start2 && offset) {
  15827. offset--;
  15828. }
  15829. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  15830. }
  15831. if (isText$7(container) && start2 && offset >= container.nodeValue.length) {
  15832. container = new DomTreeWalker(container, ed.getBody()).next() || container;
  15833. }
  15834. if (isText$7(container) && !start2 && offset === 0) {
  15835. container = new DomTreeWalker(container, ed.getBody()).prev() || container;
  15836. }
  15837. return container;
  15838. };
  15839. var normalizeTableSelection = function(node, start2) {
  15840. var prop = start2 ? "firstChild" : "lastChild";
  15841. if (isTableCellOrRow(node) && node[prop]) {
  15842. var childNode = node[prop];
  15843. if (node.nodeName === "TR") {
  15844. return childNode[prop] || childNode;
  15845. } else {
  15846. return childNode;
  15847. }
  15848. }
  15849. return node;
  15850. };
  15851. var wrap$1 = function(dom2, node, name2, attrs) {
  15852. var wrapper = dom2.create(name2, attrs);
  15853. node.parentNode.insertBefore(wrapper, node);
  15854. wrapper.appendChild(node);
  15855. return wrapper;
  15856. };
  15857. var wrapWithSiblings = function(dom2, node, next, name2, attrs) {
  15858. var start2 = SugarElement.fromDom(node);
  15859. var wrapper = SugarElement.fromDom(dom2.create(name2, attrs));
  15860. var siblings2 = next ? nextSiblings(start2) : prevSiblings(start2);
  15861. append(wrapper, siblings2);
  15862. if (next) {
  15863. before$4(start2, wrapper);
  15864. prepend(wrapper, start2);
  15865. } else {
  15866. after$3(start2, wrapper);
  15867. append$1(wrapper, start2);
  15868. }
  15869. return wrapper.dom;
  15870. };
  15871. var matchName = function(dom2, node, format) {
  15872. if (isInlineFormat(format) && isEq$2(node, format.inline)) {
  15873. return true;
  15874. }
  15875. if (isBlockFormat(format) && isEq$2(node, format.block)) {
  15876. return true;
  15877. }
  15878. if (isSelectorFormat(format)) {
  15879. return isElement$5(node) && dom2.is(node, format.selector);
  15880. }
  15881. };
  15882. var isColorFormatAndAnchor = function(node, format) {
  15883. return format.links && node.nodeName === "A";
  15884. };
  15885. var find = function(dom2, node, next, inc) {
  15886. var sibling2 = getNonWhiteSpaceSibling(node, next, inc);
  15887. return isNullable(sibling2) || sibling2.nodeName === "BR" || dom2.isBlock(sibling2);
  15888. };
  15889. var removeNode = function(ed, node, format) {
  15890. var parentNode = node.parentNode;
  15891. var rootBlockElm;
  15892. var dom2 = ed.dom, forcedRootBlock = getForcedRootBlock(ed);
  15893. if (isBlockFormat(format)) {
  15894. if (!forcedRootBlock) {
  15895. if (dom2.isBlock(node) && !dom2.isBlock(parentNode)) {
  15896. if (!find(dom2, node, false) && !find(dom2, node.firstChild, true, true)) {
  15897. node.insertBefore(dom2.create("br"), node.firstChild);
  15898. }
  15899. if (!find(dom2, node, true) && !find(dom2, node.lastChild, false, true)) {
  15900. node.appendChild(dom2.create("br"));
  15901. }
  15902. }
  15903. } else {
  15904. if (parentNode === dom2.getRoot()) {
  15905. if (!format.list_block || !isEq$2(node, format.list_block)) {
  15906. each$k(from(node.childNodes), function(node2) {
  15907. if (isValid(ed, forcedRootBlock, node2.nodeName.toLowerCase())) {
  15908. if (!rootBlockElm) {
  15909. rootBlockElm = wrap$1(dom2, node2, forcedRootBlock);
  15910. dom2.setAttribs(rootBlockElm, ed.settings.forced_root_block_attrs);
  15911. } else {
  15912. rootBlockElm.appendChild(node2);
  15913. }
  15914. } else {
  15915. rootBlockElm = null;
  15916. }
  15917. });
  15918. }
  15919. }
  15920. }
  15921. }
  15922. if (isMixedFormat(format) && !isEq$2(format.inline, node)) {
  15923. return;
  15924. }
  15925. dom2.remove(node, true);
  15926. };
  15927. var removeFormatInternal = function(ed, format, vars, node, compareNode) {
  15928. var stylesModified;
  15929. var dom2 = ed.dom;
  15930. if (!matchName(dom2, node, format) && !isColorFormatAndAnchor(node, format)) {
  15931. return removeResult.keep();
  15932. }
  15933. var elm = node;
  15934. if (isInlineFormat(format) && format.remove === "all" && isArray$1(format.preserve_attributes)) {
  15935. var attrsToPreserve = filter$4(dom2.getAttribs(elm), function(attr) {
  15936. return contains$3(format.preserve_attributes, attr.name.toLowerCase());
  15937. });
  15938. dom2.removeAllAttribs(elm);
  15939. each$k(attrsToPreserve, function(attr) {
  15940. return dom2.setAttrib(elm, attr.name, attr.value);
  15941. });
  15942. if (attrsToPreserve.length > 0) {
  15943. return removeResult.rename("span");
  15944. }
  15945. }
  15946. if (format.remove !== "all") {
  15947. each$9(format.styles, function(value2, name2) {
  15948. value2 = normalizeStyleValue(dom2, replaceVars(value2, vars), name2 + "");
  15949. if (isNumber(name2)) {
  15950. name2 = value2;
  15951. compareNode = null;
  15952. }
  15953. if (format.remove_similar || (!compareNode || isEq$2(getStyle(dom2, compareNode, name2), value2))) {
  15954. dom2.setStyle(elm, name2, "");
  15955. }
  15956. stylesModified = true;
  15957. });
  15958. if (stylesModified && dom2.getAttrib(elm, "style") === "") {
  15959. elm.removeAttribute("style");
  15960. elm.removeAttribute("data-mce-style");
  15961. }
  15962. each$9(format.attributes, function(value2, name2) {
  15963. var valueOut;
  15964. value2 = replaceVars(value2, vars);
  15965. if (isNumber(name2)) {
  15966. name2 = value2;
  15967. compareNode = null;
  15968. }
  15969. if (format.remove_similar || (!compareNode || isEq$2(dom2.getAttrib(compareNode, name2), value2))) {
  15970. if (name2 === "class") {
  15971. value2 = dom2.getAttrib(elm, name2);
  15972. if (value2) {
  15973. valueOut = "";
  15974. each$k(value2.split(/\s+/), function(cls) {
  15975. if (/mce\-\w+/.test(cls)) {
  15976. valueOut += (valueOut ? " " : "") + cls;
  15977. }
  15978. });
  15979. if (valueOut) {
  15980. dom2.setAttrib(elm, name2, valueOut);
  15981. return;
  15982. }
  15983. }
  15984. }
  15985. if (MCE_ATTR_RE.test(name2)) {
  15986. elm.removeAttribute("data-mce-" + name2);
  15987. }
  15988. if (name2 === "style" && matchNodeNames(["li"])(elm) && dom2.getStyle(elm, "list-style-type") === "none") {
  15989. elm.removeAttribute(name2);
  15990. dom2.setStyle(elm, "list-style-type", "none");
  15991. return;
  15992. }
  15993. if (name2 === "class") {
  15994. elm.removeAttribute("className");
  15995. }
  15996. elm.removeAttribute(name2);
  15997. }
  15998. });
  15999. each$9(format.classes, function(value2) {
  16000. value2 = replaceVars(value2, vars);
  16001. if (!compareNode || dom2.hasClass(compareNode, value2)) {
  16002. dom2.removeClass(elm, value2);
  16003. }
  16004. });
  16005. var attrs = dom2.getAttribs(elm);
  16006. for (var i = 0; i < attrs.length; i++) {
  16007. var attrName = attrs[i].nodeName;
  16008. if (attrName.indexOf("_") !== 0 && attrName.indexOf("data-") !== 0) {
  16009. return removeResult.keep();
  16010. }
  16011. }
  16012. }
  16013. if (format.remove !== "none") {
  16014. removeNode(ed, elm, format);
  16015. return removeResult.removed();
  16016. }
  16017. return removeResult.keep();
  16018. };
  16019. var removeFormat$1 = function(ed, format, vars, node, compareNode) {
  16020. return removeFormatInternal(ed, format, vars, node, compareNode).fold(never, function(newName) {
  16021. ed.dom.rename(node, newName);
  16022. return true;
  16023. }, always);
  16024. };
  16025. var findFormatRoot = function(editor, container, name2, vars, similar) {
  16026. var formatRoot;
  16027. each$k(getParents$2(editor.dom, container.parentNode).reverse(), function(parent2) {
  16028. if (!formatRoot && parent2.id !== "_start" && parent2.id !== "_end") {
  16029. var format = matchNode(editor, parent2, name2, vars, similar);
  16030. if (format && format.split !== false) {
  16031. formatRoot = parent2;
  16032. }
  16033. }
  16034. });
  16035. return formatRoot;
  16036. };
  16037. var removeFormatFromClone = function(editor, format, vars, clone2) {
  16038. return removeFormatInternal(editor, format, vars, clone2, clone2).fold(constant(clone2), function(newName) {
  16039. var fragment = editor.dom.createFragment();
  16040. fragment.appendChild(clone2);
  16041. return editor.dom.rename(clone2, newName);
  16042. }, constant(null));
  16043. };
  16044. var wrapAndSplit = function(editor, formatList, formatRoot, container, target, split2, format, vars) {
  16045. var clone2, lastClone, firstClone;
  16046. var dom2 = editor.dom;
  16047. if (formatRoot) {
  16048. var formatRootParent = formatRoot.parentNode;
  16049. for (var parent_1 = container.parentNode; parent_1 && parent_1 !== formatRootParent; parent_1 = parent_1.parentNode) {
  16050. clone2 = dom2.clone(parent_1, false);
  16051. for (var i = 0; i < formatList.length; i++) {
  16052. clone2 = removeFormatFromClone(editor, formatList[i], vars, clone2);
  16053. if (clone2 === null) {
  16054. break;
  16055. }
  16056. }
  16057. if (clone2) {
  16058. if (lastClone) {
  16059. clone2.appendChild(lastClone);
  16060. }
  16061. if (!firstClone) {
  16062. firstClone = clone2;
  16063. }
  16064. lastClone = clone2;
  16065. }
  16066. }
  16067. if (split2 && (!format.mixed || !dom2.isBlock(formatRoot))) {
  16068. container = dom2.split(formatRoot, container);
  16069. }
  16070. if (lastClone) {
  16071. target.parentNode.insertBefore(lastClone, target);
  16072. firstClone.appendChild(target);
  16073. if (isInlineFormat(format)) {
  16074. mergeSiblings(dom2, format, vars, lastClone);
  16075. }
  16076. }
  16077. }
  16078. return container;
  16079. };
  16080. var remove$1 = function(ed, name2, vars, node, similar) {
  16081. var formatList = ed.formatter.get(name2);
  16082. var format = formatList[0];
  16083. var contentEditable = true;
  16084. var dom2 = ed.dom;
  16085. var selection = ed.selection;
  16086. var splitToFormatRoot = function(container) {
  16087. var formatRoot = findFormatRoot(ed, container, name2, vars, similar);
  16088. return wrapAndSplit(ed, formatList, formatRoot, container, container, true, format, vars);
  16089. };
  16090. var isRemoveBookmarkNode = function(node2) {
  16091. return isBookmarkNode$1(node2) && isElement$5(node2) && (node2.id === "_start" || node2.id === "_end");
  16092. };
  16093. var removeNodeFormat = function(node2) {
  16094. return exists(formatList, function(fmt) {
  16095. return removeFormat$1(ed, fmt, vars, node2, node2);
  16096. });
  16097. };
  16098. var process2 = function(node2) {
  16099. var lastContentEditable = true;
  16100. var hasContentEditableState2 = false;
  16101. if (isElement$5(node2) && dom2.getContentEditable(node2)) {
  16102. lastContentEditable = contentEditable;
  16103. contentEditable = dom2.getContentEditable(node2) === "true";
  16104. hasContentEditableState2 = true;
  16105. }
  16106. var children2 = from(node2.childNodes);
  16107. if (contentEditable && !hasContentEditableState2) {
  16108. var removed = removeNodeFormat(node2);
  16109. var currentNodeMatches = removed || exists(formatList, function(f) {
  16110. return matchName$1(dom2, node2, f);
  16111. });
  16112. var parentNode = node2.parentNode;
  16113. if (!currentNodeMatches && isNonNullable(parentNode) && shouldExpandToSelector(format)) {
  16114. removeNodeFormat(parentNode);
  16115. }
  16116. }
  16117. if (format.deep) {
  16118. if (children2.length) {
  16119. for (var i2 = 0; i2 < children2.length; i2++) {
  16120. process2(children2[i2]);
  16121. }
  16122. if (hasContentEditableState2) {
  16123. contentEditable = lastContentEditable;
  16124. }
  16125. }
  16126. }
  16127. var textDecorations = [
  16128. "underline",
  16129. "line-through",
  16130. "overline"
  16131. ];
  16132. each$k(textDecorations, function(decoration) {
  16133. if (isElement$5(node2) && ed.dom.getStyle(node2, "text-decoration") === decoration && node2.parentNode && getTextDecoration(dom2, node2.parentNode) === decoration) {
  16134. removeFormat$1(ed, {
  16135. deep: false,
  16136. exact: true,
  16137. inline: "span",
  16138. styles: { textDecoration: decoration }
  16139. }, null, node2);
  16140. }
  16141. });
  16142. };
  16143. var unwrap2 = function(start2) {
  16144. var node2 = dom2.get(start2 ? "_start" : "_end");
  16145. var out = node2[start2 ? "firstChild" : "lastChild"];
  16146. if (isRemoveBookmarkNode(out)) {
  16147. out = out[start2 ? "firstChild" : "lastChild"];
  16148. }
  16149. if (isText$7(out) && out.data.length === 0) {
  16150. out = start2 ? node2.previousSibling || node2.nextSibling : node2.nextSibling || node2.previousSibling;
  16151. }
  16152. dom2.remove(node2, true);
  16153. return out;
  16154. };
  16155. var removeRngStyle = function(rng2) {
  16156. var startContainer, endContainer;
  16157. var expandedRng = expandRng(ed, rng2, formatList, rng2.collapsed);
  16158. if (format.split) {
  16159. expandedRng = split(expandedRng);
  16160. startContainer = getContainer(ed, expandedRng, true);
  16161. endContainer = getContainer(ed, expandedRng);
  16162. if (startContainer !== endContainer) {
  16163. startContainer = normalizeTableSelection(startContainer, true);
  16164. endContainer = normalizeTableSelection(endContainer, false);
  16165. if (isChildOfInlineParent(dom2, startContainer, endContainer)) {
  16166. var marker = Optional.from(startContainer.firstChild).getOr(startContainer);
  16167. splitToFormatRoot(wrapWithSiblings(dom2, marker, true, "span", {
  16168. "id": "_start",
  16169. "data-mce-type": "bookmark"
  16170. }));
  16171. unwrap2(true);
  16172. return;
  16173. }
  16174. if (isChildOfInlineParent(dom2, endContainer, startContainer)) {
  16175. var marker = Optional.from(endContainer.lastChild).getOr(endContainer);
  16176. splitToFormatRoot(wrapWithSiblings(dom2, marker, false, "span", {
  16177. "id": "_end",
  16178. "data-mce-type": "bookmark"
  16179. }));
  16180. unwrap2(false);
  16181. return;
  16182. }
  16183. startContainer = wrap$1(dom2, startContainer, "span", {
  16184. "id": "_start",
  16185. "data-mce-type": "bookmark"
  16186. });
  16187. endContainer = wrap$1(dom2, endContainer, "span", {
  16188. "id": "_end",
  16189. "data-mce-type": "bookmark"
  16190. });
  16191. var newRng = dom2.createRng();
  16192. newRng.setStartAfter(startContainer);
  16193. newRng.setEndBefore(endContainer);
  16194. walk$2(dom2, newRng, function(nodes) {
  16195. each$k(nodes, function(n) {
  16196. if (!isBookmarkNode$1(n) && !isBookmarkNode$1(n.parentNode)) {
  16197. splitToFormatRoot(n);
  16198. }
  16199. });
  16200. });
  16201. splitToFormatRoot(startContainer);
  16202. splitToFormatRoot(endContainer);
  16203. startContainer = unwrap2(true);
  16204. endContainer = unwrap2();
  16205. } else {
  16206. startContainer = endContainer = splitToFormatRoot(startContainer);
  16207. }
  16208. expandedRng.startContainer = startContainer.parentNode ? startContainer.parentNode : startContainer;
  16209. expandedRng.startOffset = dom2.nodeIndex(startContainer);
  16210. expandedRng.endContainer = endContainer.parentNode ? endContainer.parentNode : endContainer;
  16211. expandedRng.endOffset = dom2.nodeIndex(endContainer) + 1;
  16212. }
  16213. walk$2(dom2, expandedRng, function(nodes) {
  16214. each$k(nodes, process2);
  16215. });
  16216. };
  16217. if (node) {
  16218. if (isNode(node)) {
  16219. var rng = dom2.createRng();
  16220. rng.setStartBefore(node);
  16221. rng.setEndAfter(node);
  16222. removeRngStyle(rng);
  16223. } else {
  16224. removeRngStyle(node);
  16225. }
  16226. fireFormatRemove(ed, name2, node, vars);
  16227. return;
  16228. }
  16229. if (dom2.getContentEditable(selection.getNode()) === "false") {
  16230. node = selection.getNode();
  16231. for (var i = 0; i < formatList.length; i++) {
  16232. if (formatList[i].ceFalseOverride) {
  16233. if (removeFormat$1(ed, formatList[i], vars, node, node)) {
  16234. break;
  16235. }
  16236. }
  16237. }
  16238. fireFormatRemove(ed, name2, node, vars);
  16239. return;
  16240. }
  16241. if (!selection.isCollapsed() || !isInlineFormat(format) || getCellsFromEditor(ed).length) {
  16242. preserve(selection, true, function() {
  16243. runOnRanges(ed, removeRngStyle);
  16244. });
  16245. if (isInlineFormat(format) && match$2(ed, name2, vars, selection.getStart())) {
  16246. moveStart(dom2, selection, selection.getRng());
  16247. }
  16248. ed.nodeChanged();
  16249. } else {
  16250. removeCaretFormat(ed, name2, vars, similar);
  16251. }
  16252. fireFormatRemove(ed, name2, node, vars);
  16253. };
  16254. var each$8 = Tools.each;
  16255. var mergeTextDecorationsAndColor = function(dom2, format, vars, node) {
  16256. var processTextDecorationsAndColor = function(n) {
  16257. if (n.nodeType === 1 && n.parentNode && n.parentNode.nodeType === 1) {
  16258. var textDecoration = getTextDecoration(dom2, n.parentNode);
  16259. if (dom2.getStyle(n, "color") && textDecoration) {
  16260. dom2.setStyle(n, "text-decoration", textDecoration);
  16261. } else if (dom2.getStyle(n, "text-decoration") === textDecoration) {
  16262. dom2.setStyle(n, "text-decoration", null);
  16263. }
  16264. }
  16265. };
  16266. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  16267. Tools.walk(node, processTextDecorationsAndColor, "childNodes");
  16268. processTextDecorationsAndColor(node);
  16269. }
  16270. };
  16271. var mergeBackgroundColorAndFontSize = function(dom2, format, vars, node) {
  16272. if (format.styles && format.styles.backgroundColor) {
  16273. processChildElements(node, hasStyle(dom2, "fontSize"), applyStyle(dom2, "backgroundColor", replaceVars(format.styles.backgroundColor, vars)));
  16274. }
  16275. };
  16276. var mergeSubSup = function(dom2, format, vars, node) {
  16277. if (isInlineFormat(format) && (format.inline === "sub" || format.inline === "sup")) {
  16278. processChildElements(node, hasStyle(dom2, "fontSize"), applyStyle(dom2, "fontSize", ""));
  16279. dom2.remove(dom2.select(format.inline === "sup" ? "sub" : "sup", node), true);
  16280. }
  16281. };
  16282. var mergeWithChildren = function(editor, formatList, vars, node) {
  16283. each$8(formatList, function(format) {
  16284. if (isInlineFormat(format)) {
  16285. each$8(editor.dom.select(format.inline, node), function(child2) {
  16286. if (!isElementNode$1(child2)) {
  16287. return;
  16288. }
  16289. removeFormat$1(editor, format, vars, child2, format.exact ? child2 : null);
  16290. });
  16291. }
  16292. clearChildStyles(editor.dom, format, node);
  16293. });
  16294. };
  16295. var mergeWithParents = function(editor, format, name2, vars, node) {
  16296. if (matchNode(editor, node.parentNode, name2, vars)) {
  16297. if (removeFormat$1(editor, format, vars, node)) {
  16298. return;
  16299. }
  16300. }
  16301. if (format.merge_with_parents) {
  16302. editor.dom.getParent(node.parentNode, function(parent2) {
  16303. if (matchNode(editor, parent2, name2, vars)) {
  16304. removeFormat$1(editor, format, vars, node);
  16305. return true;
  16306. }
  16307. });
  16308. }
  16309. };
  16310. var each$7 = Tools.each;
  16311. var isElementNode = function(node) {
  16312. return isElement$5(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$2(node);
  16313. };
  16314. var canFormatBR = function(editor, format, node, parentName) {
  16315. if (canFormatEmptyLines(editor) && isInlineFormat(format)) {
  16316. var validBRParentElements = getTextRootBlockElements(editor.schema);
  16317. var hasCaretNodeSibling = sibling(SugarElement.fromDom(node), function(sibling2) {
  16318. return isCaretNode(sibling2.dom);
  16319. });
  16320. return hasNonNullableKey(validBRParentElements, parentName) && isEmpty$2(SugarElement.fromDom(node.parentNode), false) && !hasCaretNodeSibling;
  16321. } else {
  16322. return false;
  16323. }
  16324. };
  16325. var applyFormat$1 = function(ed, name2, vars, node) {
  16326. var formatList = ed.formatter.get(name2);
  16327. var format = formatList[0];
  16328. var isCollapsed = !node && ed.selection.isCollapsed();
  16329. var dom2 = ed.dom;
  16330. var selection = ed.selection;
  16331. var setElementFormat = function(elm, fmt) {
  16332. if (fmt === void 0) {
  16333. fmt = format;
  16334. }
  16335. if (isFunction(fmt.onformat)) {
  16336. fmt.onformat(elm, fmt, vars, node);
  16337. }
  16338. each$7(fmt.styles, function(value2, name3) {
  16339. dom2.setStyle(elm, name3, replaceVars(value2, vars));
  16340. });
  16341. if (fmt.styles) {
  16342. var styleVal = dom2.getAttrib(elm, "style");
  16343. if (styleVal) {
  16344. dom2.setAttrib(elm, "data-mce-style", styleVal);
  16345. }
  16346. }
  16347. each$7(fmt.attributes, function(value2, name3) {
  16348. dom2.setAttrib(elm, name3, replaceVars(value2, vars));
  16349. });
  16350. each$7(fmt.classes, function(value2) {
  16351. value2 = replaceVars(value2, vars);
  16352. if (!dom2.hasClass(elm, value2)) {
  16353. dom2.addClass(elm, value2);
  16354. }
  16355. });
  16356. };
  16357. var applyNodeStyle = function(formatList2, node2) {
  16358. var found = false;
  16359. each$7(formatList2, function(format2) {
  16360. if (!isSelectorFormat(format2)) {
  16361. return false;
  16362. }
  16363. if (isNonNullable(format2.collapsed) && format2.collapsed !== isCollapsed) {
  16364. return;
  16365. }
  16366. if (dom2.is(node2, format2.selector) && !isCaretNode(node2)) {
  16367. setElementFormat(node2, format2);
  16368. found = true;
  16369. return false;
  16370. }
  16371. });
  16372. return found;
  16373. };
  16374. var createWrapElement = function(wrapName) {
  16375. if (isString$1(wrapName)) {
  16376. var wrapElm = dom2.create(wrapName);
  16377. setElementFormat(wrapElm);
  16378. return wrapElm;
  16379. } else {
  16380. return null;
  16381. }
  16382. };
  16383. var applyRngStyle = function(dom3, rng2, nodeSpecific) {
  16384. var newWrappers = [];
  16385. var contentEditable = true;
  16386. var wrapName = format.inline || format.block;
  16387. var wrapElm = createWrapElement(wrapName);
  16388. walk$2(dom3, rng2, function(nodes) {
  16389. var currentWrapElm;
  16390. var process2 = function(node2) {
  16391. var hasContentEditableState2 = false;
  16392. var lastContentEditable = contentEditable;
  16393. var nodeName = node2.nodeName.toLowerCase();
  16394. var parentNode = node2.parentNode;
  16395. var parentName = parentNode.nodeName.toLowerCase();
  16396. if (isElement$5(node2) && dom3.getContentEditable(node2)) {
  16397. lastContentEditable = contentEditable;
  16398. contentEditable = dom3.getContentEditable(node2) === "true";
  16399. hasContentEditableState2 = true;
  16400. }
  16401. if (isBr$5(node2) && !canFormatBR(ed, format, node2, parentName)) {
  16402. currentWrapElm = null;
  16403. if (isBlockFormat(format)) {
  16404. dom3.remove(node2);
  16405. }
  16406. return;
  16407. }
  16408. if (isBlockFormat(format) && format.wrapper && matchNode(ed, node2, name2, vars)) {
  16409. currentWrapElm = null;
  16410. return;
  16411. }
  16412. if (contentEditable && !hasContentEditableState2 && isBlockFormat(format) && !format.wrapper && isTextBlock$1(ed, nodeName) && isValid(ed, parentName, wrapName)) {
  16413. var elm = dom3.rename(node2, wrapName);
  16414. setElementFormat(elm);
  16415. newWrappers.push(elm);
  16416. currentWrapElm = null;
  16417. return;
  16418. }
  16419. if (isSelectorFormat(format)) {
  16420. var found = applyNodeStyle(formatList, node2);
  16421. if (!found && isNonNullable(parentNode) && shouldExpandToSelector(format)) {
  16422. found = applyNodeStyle(formatList, parentNode);
  16423. }
  16424. if (!isInlineFormat(format) || found) {
  16425. currentWrapElm = null;
  16426. return;
  16427. }
  16428. }
  16429. if (contentEditable && !hasContentEditableState2 && isValid(ed, wrapName, nodeName) && isValid(ed, parentName, wrapName) && !(!nodeSpecific && isText$7(node2) && isZwsp(node2.data)) && !isCaretNode(node2) && (!isInlineFormat(format) || !dom3.isBlock(node2))) {
  16430. if (!currentWrapElm) {
  16431. currentWrapElm = dom3.clone(wrapElm, false);
  16432. node2.parentNode.insertBefore(currentWrapElm, node2);
  16433. newWrappers.push(currentWrapElm);
  16434. }
  16435. currentWrapElm.appendChild(node2);
  16436. } else {
  16437. currentWrapElm = null;
  16438. each$k(from(node2.childNodes), process2);
  16439. if (hasContentEditableState2) {
  16440. contentEditable = lastContentEditable;
  16441. }
  16442. currentWrapElm = null;
  16443. }
  16444. };
  16445. each$k(nodes, process2);
  16446. });
  16447. if (format.links === true) {
  16448. each$k(newWrappers, function(node2) {
  16449. var process2 = function(node3) {
  16450. if (node3.nodeName === "A") {
  16451. setElementFormat(node3, format);
  16452. }
  16453. each$k(from(node3.childNodes), process2);
  16454. };
  16455. process2(node2);
  16456. });
  16457. }
  16458. each$k(newWrappers, function(node2) {
  16459. var getChildCount = function(node3) {
  16460. var count2 = 0;
  16461. each$k(node3.childNodes, function(node4) {
  16462. if (!isEmptyTextNode$1(node4) && !isBookmarkNode$1(node4)) {
  16463. count2++;
  16464. }
  16465. });
  16466. return count2;
  16467. };
  16468. var mergeStyles = function(node3) {
  16469. var childElement = find$3(node3.childNodes, isElementNode).filter(function(child2) {
  16470. return matchName$1(dom3, child2, format);
  16471. });
  16472. return childElement.map(function(child2) {
  16473. var clone2 = dom3.clone(child2, false);
  16474. setElementFormat(clone2);
  16475. dom3.replace(clone2, node3, true);
  16476. dom3.remove(child2, true);
  16477. return clone2;
  16478. }).getOr(node3);
  16479. };
  16480. var childCount = getChildCount(node2);
  16481. if ((newWrappers.length > 1 || !dom3.isBlock(node2)) && childCount === 0) {
  16482. dom3.remove(node2, true);
  16483. return;
  16484. }
  16485. if (isInlineFormat(format) || isBlockFormat(format) && format.wrapper) {
  16486. if (!format.exact && childCount === 1) {
  16487. node2 = mergeStyles(node2);
  16488. }
  16489. mergeWithChildren(ed, formatList, vars, node2);
  16490. mergeWithParents(ed, format, name2, vars, node2);
  16491. mergeBackgroundColorAndFontSize(dom3, format, vars, node2);
  16492. mergeTextDecorationsAndColor(dom3, format, vars, node2);
  16493. mergeSubSup(dom3, format, vars, node2);
  16494. mergeSiblings(dom3, format, vars, node2);
  16495. }
  16496. });
  16497. };
  16498. if (dom2.getContentEditable(selection.getNode()) === "false") {
  16499. node = selection.getNode();
  16500. for (var i = 0, l = formatList.length; i < l; i++) {
  16501. var formatItem = formatList[i];
  16502. if (formatItem.ceFalseOverride && isSelectorFormat(formatItem) && dom2.is(node, formatItem.selector)) {
  16503. setElementFormat(node, formatItem);
  16504. break;
  16505. }
  16506. }
  16507. fireFormatApply(ed, name2, node, vars);
  16508. return;
  16509. }
  16510. if (format) {
  16511. if (node) {
  16512. if (isNode(node)) {
  16513. if (!applyNodeStyle(formatList, node)) {
  16514. var rng = dom2.createRng();
  16515. rng.setStartBefore(node);
  16516. rng.setEndAfter(node);
  16517. applyRngStyle(dom2, expandRng(ed, rng, formatList), true);
  16518. }
  16519. } else {
  16520. applyRngStyle(dom2, node, true);
  16521. }
  16522. } else {
  16523. if (!isCollapsed || !isInlineFormat(format) || getCellsFromEditor(ed).length) {
  16524. var curSelNode = selection.getNode();
  16525. var firstFormat = formatList[0];
  16526. if (!ed.settings.forced_root_block && firstFormat.defaultBlock && !dom2.getParent(curSelNode, dom2.isBlock)) {
  16527. applyFormat$1(ed, firstFormat.defaultBlock);
  16528. }
  16529. selection.setRng(normalize(selection.getRng()));
  16530. preserve(selection, true, function() {
  16531. runOnRanges(ed, function(selectionRng, fake) {
  16532. var expandedRng = fake ? selectionRng : expandRng(ed, selectionRng, formatList);
  16533. applyRngStyle(dom2, expandedRng, false);
  16534. });
  16535. });
  16536. moveStart(dom2, selection, selection.getRng());
  16537. ed.nodeChanged();
  16538. } else {
  16539. applyCaretFormat(ed, name2, vars);
  16540. }
  16541. }
  16542. postProcess$1(name2, ed);
  16543. }
  16544. fireFormatApply(ed, name2, node, vars);
  16545. };
  16546. var hasVars = function(value2) {
  16547. return has$2(value2, "vars");
  16548. };
  16549. var setup$j = function(registeredFormatListeners, editor) {
  16550. registeredFormatListeners.set({});
  16551. editor.on("NodeChange", function(e) {
  16552. updateAndFireChangeCallbacks(editor, e.element, registeredFormatListeners.get());
  16553. });
  16554. editor.on("FormatApply FormatRemove", function(e) {
  16555. var element = Optional.from(e.node).map(function(nodeOrRange) {
  16556. return isNode(nodeOrRange) ? nodeOrRange : nodeOrRange.startContainer;
  16557. }).bind(function(node) {
  16558. return isElement$5(node) ? Optional.some(node) : Optional.from(node.parentElement);
  16559. }).getOrThunk(function() {
  16560. return fallbackElement(editor);
  16561. });
  16562. updateAndFireChangeCallbacks(editor, element, registeredFormatListeners.get());
  16563. });
  16564. };
  16565. var fallbackElement = function(editor) {
  16566. return editor.selection.getStart();
  16567. };
  16568. var matchingNode = function(editor, parents2, format, similar, vars) {
  16569. var isMatchingNode = function(node) {
  16570. var matchingFormat = editor.formatter.matchNode(node, format, vars !== null && vars !== void 0 ? vars : {}, similar);
  16571. return !isUndefined(matchingFormat);
  16572. };
  16573. var isUnableToMatch = function(node) {
  16574. if (matchesUnInheritedFormatSelector(editor, node, format)) {
  16575. return true;
  16576. } else {
  16577. if (!similar) {
  16578. return isNonNullable(editor.formatter.matchNode(node, format, vars, true));
  16579. } else {
  16580. return false;
  16581. }
  16582. }
  16583. };
  16584. return findUntil$1(parents2, isMatchingNode, isUnableToMatch);
  16585. };
  16586. var getParents = function(editor, elm) {
  16587. var element = elm !== null && elm !== void 0 ? elm : fallbackElement(editor);
  16588. return filter$4(getParents$2(editor.dom, element), function(node) {
  16589. return isElement$5(node) && !isBogus$2(node);
  16590. });
  16591. };
  16592. var updateAndFireChangeCallbacks = function(editor, elm, registeredCallbacks) {
  16593. var parents2 = getParents(editor, elm);
  16594. each$j(registeredCallbacks, function(data2, format) {
  16595. var runIfChanged = function(spec) {
  16596. var match2 = matchingNode(editor, parents2, format, spec.similar, hasVars(spec) ? spec.vars : void 0);
  16597. var isSet = match2.isSome();
  16598. if (spec.state.get() !== isSet) {
  16599. spec.state.set(isSet);
  16600. var node_1 = match2.getOr(elm);
  16601. if (hasVars(spec)) {
  16602. spec.callback(isSet, {
  16603. node: node_1,
  16604. format,
  16605. parents: parents2
  16606. });
  16607. } else {
  16608. each$k(spec.callbacks, function(callback) {
  16609. return callback(isSet, {
  16610. node: node_1,
  16611. format,
  16612. parents: parents2
  16613. });
  16614. });
  16615. }
  16616. }
  16617. };
  16618. each$k([
  16619. data2.withSimilar,
  16620. data2.withoutSimilar
  16621. ], runIfChanged);
  16622. each$k(data2.withVars, runIfChanged);
  16623. });
  16624. };
  16625. var addListeners = function(editor, registeredFormatListeners, formats, callback, similar, vars) {
  16626. var formatChangeItems = registeredFormatListeners.get();
  16627. each$k(formats.split(","), function(format) {
  16628. var group = get$9(formatChangeItems, format).getOrThunk(function() {
  16629. var base = {
  16630. withSimilar: {
  16631. state: Cell(false),
  16632. similar: true,
  16633. callbacks: []
  16634. },
  16635. withoutSimilar: {
  16636. state: Cell(false),
  16637. similar: false,
  16638. callbacks: []
  16639. },
  16640. withVars: []
  16641. };
  16642. formatChangeItems[format] = base;
  16643. return base;
  16644. });
  16645. var getCurrent = function() {
  16646. var parents2 = getParents(editor);
  16647. return matchingNode(editor, parents2, format, similar, vars).isSome();
  16648. };
  16649. if (isUndefined(vars)) {
  16650. var toAppendTo = similar ? group.withSimilar : group.withoutSimilar;
  16651. toAppendTo.callbacks.push(callback);
  16652. if (toAppendTo.callbacks.length === 1) {
  16653. toAppendTo.state.set(getCurrent());
  16654. }
  16655. } else {
  16656. group.withVars.push({
  16657. state: Cell(getCurrent()),
  16658. similar,
  16659. vars,
  16660. callback
  16661. });
  16662. }
  16663. });
  16664. registeredFormatListeners.set(formatChangeItems);
  16665. };
  16666. var removeListeners = function(registeredFormatListeners, formats, callback) {
  16667. var formatChangeItems = registeredFormatListeners.get();
  16668. each$k(formats.split(","), function(format) {
  16669. return get$9(formatChangeItems, format).each(function(group) {
  16670. formatChangeItems[format] = {
  16671. withSimilar: __assign(__assign({}, group.withSimilar), {
  16672. callbacks: filter$4(group.withSimilar.callbacks, function(cb) {
  16673. return cb !== callback;
  16674. })
  16675. }),
  16676. withoutSimilar: __assign(__assign({}, group.withoutSimilar), {
  16677. callbacks: filter$4(group.withoutSimilar.callbacks, function(cb) {
  16678. return cb !== callback;
  16679. })
  16680. }),
  16681. withVars: filter$4(group.withVars, function(item) {
  16682. return item.callback !== callback;
  16683. })
  16684. };
  16685. });
  16686. });
  16687. registeredFormatListeners.set(formatChangeItems);
  16688. };
  16689. var formatChangedInternal = function(editor, registeredFormatListeners, formats, callback, similar, vars) {
  16690. if (registeredFormatListeners.get() === null) {
  16691. setup$j(registeredFormatListeners, editor);
  16692. }
  16693. addListeners(editor, registeredFormatListeners, formats, callback, similar, vars);
  16694. return {
  16695. unbind: function() {
  16696. return removeListeners(registeredFormatListeners, formats, callback);
  16697. }
  16698. };
  16699. };
  16700. var toggle = function(editor, name2, vars, node) {
  16701. var fmt = editor.formatter.get(name2);
  16702. if (match$2(editor, name2, vars, node) && (!("toggle" in fmt[0]) || fmt[0].toggle)) {
  16703. remove$1(editor, name2, vars, node);
  16704. } else {
  16705. applyFormat$1(editor, name2, vars, node);
  16706. }
  16707. };
  16708. var fromElements = function(elements, scope) {
  16709. var doc2 = scope || document;
  16710. var fragment = doc2.createDocumentFragment();
  16711. each$k(elements, function(element) {
  16712. fragment.appendChild(element.dom);
  16713. });
  16714. return SugarElement.fromDom(fragment);
  16715. };
  16716. var tableModel = function(element, width, rows) {
  16717. return {
  16718. element,
  16719. width,
  16720. rows
  16721. };
  16722. };
  16723. var tableRow = function(element, cells) {
  16724. return {
  16725. element,
  16726. cells
  16727. };
  16728. };
  16729. var cellPosition = function(x, y) {
  16730. return {
  16731. x,
  16732. y
  16733. };
  16734. };
  16735. var getSpan = function(td, key) {
  16736. var value2 = parseInt(get$6(td, key), 10);
  16737. return isNaN(value2) ? 1 : value2;
  16738. };
  16739. var fillout = function(table, x, y, tr, td) {
  16740. var rowspan = getSpan(td, "rowspan");
  16741. var colspan = getSpan(td, "colspan");
  16742. var rows = table.rows;
  16743. for (var y2 = y; y2 < y + rowspan; y2++) {
  16744. if (!rows[y2]) {
  16745. rows[y2] = tableRow(deep$1(tr), []);
  16746. }
  16747. for (var x2 = x; x2 < x + colspan; x2++) {
  16748. var cells = rows[y2].cells;
  16749. cells[x2] = y2 === y && x2 === x ? td : shallow(td);
  16750. }
  16751. }
  16752. };
  16753. var cellExists = function(table, x, y) {
  16754. var rows = table.rows;
  16755. var cells = rows[y] ? rows[y].cells : [];
  16756. return !!cells[x];
  16757. };
  16758. var skipCellsX = function(table, x, y) {
  16759. while (cellExists(table, x, y)) {
  16760. x++;
  16761. }
  16762. return x;
  16763. };
  16764. var getWidth = function(rows) {
  16765. return foldl(rows, function(acc, row) {
  16766. return row.cells.length > acc ? row.cells.length : acc;
  16767. }, 0);
  16768. };
  16769. var findElementPos = function(table, element) {
  16770. var rows = table.rows;
  16771. for (var y = 0; y < rows.length; y++) {
  16772. var cells = rows[y].cells;
  16773. for (var x = 0; x < cells.length; x++) {
  16774. if (eq(cells[x], element)) {
  16775. return Optional.some(cellPosition(x, y));
  16776. }
  16777. }
  16778. }
  16779. return Optional.none();
  16780. };
  16781. var extractRows = function(table, sx, sy, ex, ey) {
  16782. var newRows = [];
  16783. var rows = table.rows;
  16784. for (var y = sy; y <= ey; y++) {
  16785. var cells = rows[y].cells;
  16786. var slice2 = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1);
  16787. newRows.push(tableRow(rows[y].element, slice2));
  16788. }
  16789. return newRows;
  16790. };
  16791. var subTable = function(table, startPos, endPos) {
  16792. var sx = startPos.x, sy = startPos.y;
  16793. var ex = endPos.x, ey = endPos.y;
  16794. var newRows = sy < ey ? extractRows(table, sx, sy, ex, ey) : extractRows(table, sx, ey, ex, sy);
  16795. return tableModel(table.element, getWidth(newRows), newRows);
  16796. };
  16797. var createDomTable = function(table, rows) {
  16798. var tableElement = shallow(table.element);
  16799. var tableBody = SugarElement.fromTag("tbody");
  16800. append(tableBody, rows);
  16801. append$1(tableElement, tableBody);
  16802. return tableElement;
  16803. };
  16804. var modelRowsToDomRows = function(table) {
  16805. return map$3(table.rows, function(row) {
  16806. var cells = map$3(row.cells, function(cell) {
  16807. var td = deep$1(cell);
  16808. remove$6(td, "colspan");
  16809. remove$6(td, "rowspan");
  16810. return td;
  16811. });
  16812. var tr = shallow(row.element);
  16813. append(tr, cells);
  16814. return tr;
  16815. });
  16816. };
  16817. var fromDom = function(tableElm) {
  16818. var table = tableModel(shallow(tableElm), 0, []);
  16819. each$k(descendants(tableElm, "tr"), function(tr, y) {
  16820. each$k(descendants(tr, "td,th"), function(td, x) {
  16821. fillout(table, skipCellsX(table, x, y), y, tr, td);
  16822. });
  16823. });
  16824. return tableModel(table.element, getWidth(table.rows), table.rows);
  16825. };
  16826. var toDom = function(table) {
  16827. return createDomTable(table, modelRowsToDomRows(table));
  16828. };
  16829. var subsection = function(table, startElement, endElement) {
  16830. return findElementPos(table, startElement).bind(function(startPos) {
  16831. return findElementPos(table, endElement).map(function(endPos) {
  16832. return subTable(table, startPos, endPos);
  16833. });
  16834. });
  16835. };
  16836. var findParentListContainer = function(parents2) {
  16837. return find$3(parents2, function(elm) {
  16838. return name(elm) === "ul" || name(elm) === "ol";
  16839. });
  16840. };
  16841. var getFullySelectedListWrappers = function(parents2, rng) {
  16842. return find$3(parents2, function(elm) {
  16843. return name(elm) === "li" && hasAllContentsSelected(elm, rng);
  16844. }).fold(constant([]), function(_li) {
  16845. return findParentListContainer(parents2).map(function(listCont) {
  16846. var listElm = SugarElement.fromTag(name(listCont));
  16847. var listStyles = filter$3(getAllRaw(listCont), function(_style, name2) {
  16848. return startsWith(name2, "list-style");
  16849. });
  16850. setAll(listElm, listStyles);
  16851. return [
  16852. SugarElement.fromTag("li"),
  16853. listElm
  16854. ];
  16855. }).getOr([]);
  16856. });
  16857. };
  16858. var wrap = function(innerElm, elms) {
  16859. var wrapped = foldl(elms, function(acc, elm) {
  16860. append$1(elm, acc);
  16861. return elm;
  16862. }, innerElm);
  16863. return elms.length > 0 ? fromElements([wrapped]) : wrapped;
  16864. };
  16865. var directListWrappers = function(commonAnchorContainer) {
  16866. if (isListItem(commonAnchorContainer)) {
  16867. return parent(commonAnchorContainer).filter(isList).fold(constant([]), function(listElm) {
  16868. return [
  16869. commonAnchorContainer,
  16870. listElm
  16871. ];
  16872. });
  16873. } else {
  16874. return isList(commonAnchorContainer) ? [commonAnchorContainer] : [];
  16875. }
  16876. };
  16877. var getWrapElements = function(rootNode, rng) {
  16878. var commonAnchorContainer = SugarElement.fromDom(rng.commonAncestorContainer);
  16879. var parents2 = parentsAndSelf(commonAnchorContainer, rootNode);
  16880. var wrapElements = filter$4(parents2, function(elm) {
  16881. return isInline$1(elm) || isHeading(elm);
  16882. });
  16883. var listWrappers = getFullySelectedListWrappers(parents2, rng);
  16884. var allWrappers = wrapElements.concat(listWrappers.length ? listWrappers : directListWrappers(commonAnchorContainer));
  16885. return map$3(allWrappers, shallow);
  16886. };
  16887. var emptyFragment = function() {
  16888. return fromElements([]);
  16889. };
  16890. var getFragmentFromRange = function(rootNode, rng) {
  16891. return wrap(SugarElement.fromDom(rng.cloneContents()), getWrapElements(rootNode, rng));
  16892. };
  16893. var getParentTable = function(rootElm, cell) {
  16894. return ancestor$2(cell, "table", curry(eq, rootElm));
  16895. };
  16896. var getTableFragment = function(rootNode, selectedTableCells) {
  16897. return getParentTable(rootNode, selectedTableCells[0]).bind(function(tableElm) {
  16898. var firstCell = selectedTableCells[0];
  16899. var lastCell = selectedTableCells[selectedTableCells.length - 1];
  16900. var fullTableModel = fromDom(tableElm);
  16901. return subsection(fullTableModel, firstCell, lastCell).map(function(sectionedTableModel) {
  16902. return fromElements([toDom(sectionedTableModel)]);
  16903. });
  16904. }).getOrThunk(emptyFragment);
  16905. };
  16906. var getSelectionFragment = function(rootNode, ranges) {
  16907. return ranges.length > 0 && ranges[0].collapsed ? emptyFragment() : getFragmentFromRange(rootNode, ranges[0]);
  16908. };
  16909. var read$3 = function(rootNode, ranges) {
  16910. var selectedCells = getCellsFromElementOrRanges(ranges, rootNode);
  16911. return selectedCells.length > 0 ? getTableFragment(rootNode, selectedCells) : getSelectionFragment(rootNode, ranges);
  16912. };
  16913. var trimLeadingCollapsibleText = function(text) {
  16914. return text.replace(/^[ \f\n\r\t\v]+/, "");
  16915. };
  16916. var isCollapsibleWhitespace = function(text, index) {
  16917. return index >= 0 && index < text.length && isWhiteSpace(text.charAt(index));
  16918. };
  16919. var getInnerText = function(bin, shouldTrim) {
  16920. var text = trim$2(bin.innerText);
  16921. return shouldTrim ? trimLeadingCollapsibleText(text) : text;
  16922. };
  16923. var getContextNodeName = function(parentBlockOpt) {
  16924. return parentBlockOpt.map(function(block) {
  16925. return block.nodeName;
  16926. }).getOr("div").toLowerCase();
  16927. };
  16928. var getTextContent = function(editor) {
  16929. return Optional.from(editor.selection.getRng()).map(function(rng) {
  16930. var parentBlockOpt = Optional.from(editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock));
  16931. var body = editor.getBody();
  16932. var contextNodeName = getContextNodeName(parentBlockOpt);
  16933. var shouldTrimSpaces = Env.browser.isIE() && contextNodeName !== "pre";
  16934. var bin = editor.dom.add(body, contextNodeName, {
  16935. "data-mce-bogus": "all",
  16936. "style": "overflow: hidden; opacity: 0;"
  16937. }, rng.cloneContents());
  16938. var text = getInnerText(bin, shouldTrimSpaces);
  16939. var nonRenderedText = trim$2(bin.textContent);
  16940. editor.dom.remove(bin);
  16941. if (isCollapsibleWhitespace(nonRenderedText, 0) || isCollapsibleWhitespace(nonRenderedText, nonRenderedText.length - 1)) {
  16942. var parentBlock = parentBlockOpt.getOr(body);
  16943. var parentBlockText = getInnerText(parentBlock, shouldTrimSpaces);
  16944. var textIndex = parentBlockText.indexOf(text);
  16945. if (textIndex === -1) {
  16946. return text;
  16947. } else {
  16948. var hasProceedingSpace = isCollapsibleWhitespace(parentBlockText, textIndex - 1);
  16949. var hasTrailingSpace = isCollapsibleWhitespace(parentBlockText, textIndex + text.length);
  16950. return (hasProceedingSpace ? " " : "") + text + (hasTrailingSpace ? " " : "");
  16951. }
  16952. } else {
  16953. return text;
  16954. }
  16955. }).getOr("");
  16956. };
  16957. var getSerializedContent = function(editor, args) {
  16958. var rng = editor.selection.getRng(), tmpElm = editor.dom.create("body");
  16959. var sel = editor.selection.getSel();
  16960. var ranges = processRanges(editor, getRanges(sel));
  16961. var fragment = args.contextual ? read$3(SugarElement.fromDom(editor.getBody()), ranges).dom : rng.cloneContents();
  16962. if (fragment) {
  16963. tmpElm.appendChild(fragment);
  16964. }
  16965. return editor.selection.serializer.serialize(tmpElm, args);
  16966. };
  16967. var setupArgs$1 = function(args, format) {
  16968. return __assign(__assign({}, args), {
  16969. format,
  16970. get: true,
  16971. selection: true
  16972. });
  16973. };
  16974. var getSelectedContentInternal = function(editor, format, args) {
  16975. if (args === void 0) {
  16976. args = {};
  16977. }
  16978. var defaultedArgs = setupArgs$1(args, format);
  16979. var updatedArgs = editor.fire("BeforeGetContent", defaultedArgs);
  16980. if (updatedArgs.isDefaultPrevented()) {
  16981. editor.fire("GetContent", updatedArgs);
  16982. return updatedArgs.content;
  16983. }
  16984. if (updatedArgs.format === "text") {
  16985. return getTextContent(editor);
  16986. } else {
  16987. updatedArgs.getInner = true;
  16988. var content = getSerializedContent(editor, updatedArgs);
  16989. if (updatedArgs.format === "tree") {
  16990. return content;
  16991. } else {
  16992. updatedArgs.content = editor.selection.isCollapsed() ? "" : content;
  16993. editor.fire("GetContent", updatedArgs);
  16994. return updatedArgs.content;
  16995. }
  16996. }
  16997. };
  16998. var KEEP = 0, INSERT = 1, DELETE = 2;
  16999. var diff = function(left, right) {
  17000. var size = left.length + right.length + 2;
  17001. var vDown = new Array(size);
  17002. var vUp = new Array(size);
  17003. var snake = function(start2, end2, diag) {
  17004. return {
  17005. start: start2,
  17006. end: end2,
  17007. diag
  17008. };
  17009. };
  17010. var buildScript = function(start1, end1, start2, end2, script2) {
  17011. var middle = getMiddleSnake(start1, end1, start2, end2);
  17012. if (middle === null || middle.start === end1 && middle.diag === end1 - end2 || middle.end === start1 && middle.diag === start1 - start2) {
  17013. var i = start1;
  17014. var j = start2;
  17015. while (i < end1 || j < end2) {
  17016. if (i < end1 && j < end2 && left[i] === right[j]) {
  17017. script2.push([
  17018. KEEP,
  17019. left[i]
  17020. ]);
  17021. ++i;
  17022. ++j;
  17023. } else {
  17024. if (end1 - start1 > end2 - start2) {
  17025. script2.push([
  17026. DELETE,
  17027. left[i]
  17028. ]);
  17029. ++i;
  17030. } else {
  17031. script2.push([
  17032. INSERT,
  17033. right[j]
  17034. ]);
  17035. ++j;
  17036. }
  17037. }
  17038. }
  17039. } else {
  17040. buildScript(start1, middle.start, start2, middle.start - middle.diag, script2);
  17041. for (var i2 = middle.start; i2 < middle.end; ++i2) {
  17042. script2.push([
  17043. KEEP,
  17044. left[i2]
  17045. ]);
  17046. }
  17047. buildScript(middle.end, end1, middle.end - middle.diag, end2, script2);
  17048. }
  17049. };
  17050. var buildSnake = function(start2, diag, end1, end2) {
  17051. var end3 = start2;
  17052. while (end3 - diag < end2 && end3 < end1 && left[end3] === right[end3 - diag]) {
  17053. ++end3;
  17054. }
  17055. return snake(start2, end3, diag);
  17056. };
  17057. var getMiddleSnake = function(start1, end1, start2, end2) {
  17058. var m = end1 - start1;
  17059. var n = end2 - start2;
  17060. if (m === 0 || n === 0) {
  17061. return null;
  17062. }
  17063. var delta = m - n;
  17064. var sum = n + m;
  17065. var offset = (sum % 2 === 0 ? sum : sum + 1) / 2;
  17066. vDown[1 + offset] = start1;
  17067. vUp[1 + offset] = end1 + 1;
  17068. var d, k, i, x, y;
  17069. for (d = 0; d <= offset; ++d) {
  17070. for (k = -d; k <= d; k += 2) {
  17071. i = k + offset;
  17072. if (k === -d || k !== d && vDown[i - 1] < vDown[i + 1]) {
  17073. vDown[i] = vDown[i + 1];
  17074. } else {
  17075. vDown[i] = vDown[i - 1] + 1;
  17076. }
  17077. x = vDown[i];
  17078. y = x - start1 + start2 - k;
  17079. while (x < end1 && y < end2 && left[x] === right[y]) {
  17080. vDown[i] = ++x;
  17081. ++y;
  17082. }
  17083. if (delta % 2 !== 0 && delta - d <= k && k <= delta + d) {
  17084. if (vUp[i - delta] <= vDown[i]) {
  17085. return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2);
  17086. }
  17087. }
  17088. }
  17089. for (k = delta - d; k <= delta + d; k += 2) {
  17090. i = k + offset - delta;
  17091. if (k === delta - d || k !== delta + d && vUp[i + 1] <= vUp[i - 1]) {
  17092. vUp[i] = vUp[i + 1] - 1;
  17093. } else {
  17094. vUp[i] = vUp[i - 1];
  17095. }
  17096. x = vUp[i] - 1;
  17097. y = x - start1 + start2 - k;
  17098. while (x >= start1 && y >= start2 && left[x] === right[y]) {
  17099. vUp[i] = x--;
  17100. y--;
  17101. }
  17102. if (delta % 2 === 0 && -d <= k && k <= d) {
  17103. if (vUp[i] <= vDown[i + delta]) {
  17104. return buildSnake(vUp[i], k + start1 - start2, end1, end2);
  17105. }
  17106. }
  17107. }
  17108. }
  17109. };
  17110. var script = [];
  17111. buildScript(0, left.length, 0, right.length, script);
  17112. return script;
  17113. };
  17114. var getOuterHtml = function(elm) {
  17115. if (isElement$5(elm)) {
  17116. return elm.outerHTML;
  17117. } else if (isText$7(elm)) {
  17118. return Entities.encodeRaw(elm.data, false);
  17119. } else if (isComment(elm)) {
  17120. return "<!--" + elm.data + "-->";
  17121. }
  17122. return "";
  17123. };
  17124. var createFragment = function(html) {
  17125. var node;
  17126. var container = document.createElement("div");
  17127. var frag = document.createDocumentFragment();
  17128. if (html) {
  17129. container.innerHTML = html;
  17130. }
  17131. while (node = container.firstChild) {
  17132. frag.appendChild(node);
  17133. }
  17134. return frag;
  17135. };
  17136. var insertAt = function(elm, html, index) {
  17137. var fragment = createFragment(html);
  17138. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  17139. var target = elm.childNodes[index];
  17140. target.parentNode.insertBefore(fragment, target);
  17141. } else {
  17142. elm.appendChild(fragment);
  17143. }
  17144. };
  17145. var removeAt = function(elm, index) {
  17146. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  17147. var target = elm.childNodes[index];
  17148. target.parentNode.removeChild(target);
  17149. }
  17150. };
  17151. var applyDiff = function(diff2, elm) {
  17152. var index = 0;
  17153. each$k(diff2, function(action2) {
  17154. if (action2[0] === KEEP) {
  17155. index++;
  17156. } else if (action2[0] === INSERT) {
  17157. insertAt(elm, action2[1], index);
  17158. index++;
  17159. } else if (action2[0] === DELETE) {
  17160. removeAt(elm, index);
  17161. }
  17162. });
  17163. };
  17164. var read$2 = function(elm) {
  17165. return filter$4(map$3(from(elm.childNodes), getOuterHtml), function(item) {
  17166. return item.length > 0;
  17167. });
  17168. };
  17169. var write = function(fragments, elm) {
  17170. var currentFragments = map$3(from(elm.childNodes), getOuterHtml);
  17171. applyDiff(diff(currentFragments, fragments), elm);
  17172. return elm;
  17173. };
  17174. var lazyTempDocument = cached(function() {
  17175. return document.implementation.createHTMLDocument("undo");
  17176. });
  17177. var hasIframes = function(html) {
  17178. return html.indexOf("</iframe>") !== -1;
  17179. };
  17180. var createFragmentedLevel = function(fragments) {
  17181. return {
  17182. type: "fragmented",
  17183. fragments,
  17184. content: "",
  17185. bookmark: null,
  17186. beforeBookmark: null
  17187. };
  17188. };
  17189. var createCompleteLevel = function(content) {
  17190. return {
  17191. type: "complete",
  17192. fragments: null,
  17193. content,
  17194. bookmark: null,
  17195. beforeBookmark: null
  17196. };
  17197. };
  17198. var createFromEditor = function(editor) {
  17199. var fragments = read$2(editor.getBody());
  17200. var trimmedFragments = bind(fragments, function(html) {
  17201. var trimmed = trimInternal(editor.serializer, html);
  17202. return trimmed.length > 0 ? [trimmed] : [];
  17203. });
  17204. var content = trimmedFragments.join("");
  17205. return hasIframes(content) ? createFragmentedLevel(trimmedFragments) : createCompleteLevel(content);
  17206. };
  17207. var applyToEditor = function(editor, level, before2) {
  17208. var bookmark = before2 ? level.beforeBookmark : level.bookmark;
  17209. if (level.type === "fragmented") {
  17210. write(level.fragments, editor.getBody());
  17211. } else {
  17212. editor.setContent(level.content, {
  17213. format: "raw",
  17214. no_selection: isNonNullable(bookmark) && isPathBookmark(bookmark) ? !bookmark.isFakeCaret : true
  17215. });
  17216. }
  17217. editor.selection.moveToBookmark(bookmark);
  17218. };
  17219. var getLevelContent = function(level) {
  17220. return level.type === "fragmented" ? level.fragments.join("") : level.content;
  17221. };
  17222. var getCleanLevelContent = function(level) {
  17223. var elm = SugarElement.fromTag("body", lazyTempDocument());
  17224. set(elm, getLevelContent(level));
  17225. each$k(descendants(elm, "*[data-mce-bogus]"), unwrap);
  17226. return get$3(elm);
  17227. };
  17228. var hasEqualContent = function(level1, level2) {
  17229. return getLevelContent(level1) === getLevelContent(level2);
  17230. };
  17231. var hasEqualCleanedContent = function(level1, level2) {
  17232. return getCleanLevelContent(level1) === getCleanLevelContent(level2);
  17233. };
  17234. var isEq$1 = function(level1, level2) {
  17235. if (!level1 || !level2) {
  17236. return false;
  17237. } else if (hasEqualContent(level1, level2)) {
  17238. return true;
  17239. } else {
  17240. return hasEqualCleanedContent(level1, level2);
  17241. }
  17242. };
  17243. var isUnlocked = function(locks) {
  17244. return locks.get() === 0;
  17245. };
  17246. var setTyping = function(undoManager, typing, locks) {
  17247. if (isUnlocked(locks)) {
  17248. undoManager.typing = typing;
  17249. }
  17250. };
  17251. var endTyping = function(undoManager, locks) {
  17252. if (undoManager.typing) {
  17253. setTyping(undoManager, false, locks);
  17254. undoManager.add();
  17255. }
  17256. };
  17257. var endTypingLevelIgnoreLocks = function(undoManager) {
  17258. if (undoManager.typing) {
  17259. undoManager.typing = false;
  17260. undoManager.add();
  17261. }
  17262. };
  17263. var beforeChange$1 = function(editor, locks, beforeBookmark) {
  17264. if (isUnlocked(locks)) {
  17265. beforeBookmark.set(getUndoBookmark(editor.selection));
  17266. }
  17267. };
  17268. var addUndoLevel$1 = function(editor, undoManager, index, locks, beforeBookmark, level, event) {
  17269. var currentLevel = createFromEditor(editor);
  17270. level = level || {};
  17271. level = Tools.extend(level, currentLevel);
  17272. if (isUnlocked(locks) === false || editor.removed) {
  17273. return null;
  17274. }
  17275. var lastLevel = undoManager.data[index.get()];
  17276. if (editor.fire("BeforeAddUndo", {
  17277. level,
  17278. lastLevel,
  17279. originalEvent: event
  17280. }).isDefaultPrevented()) {
  17281. return null;
  17282. }
  17283. if (lastLevel && isEq$1(lastLevel, level)) {
  17284. return null;
  17285. }
  17286. if (undoManager.data[index.get()]) {
  17287. beforeBookmark.get().each(function(bm) {
  17288. undoManager.data[index.get()].beforeBookmark = bm;
  17289. });
  17290. }
  17291. var customUndoRedoLevels = getCustomUndoRedoLevels(editor);
  17292. if (customUndoRedoLevels) {
  17293. if (undoManager.data.length > customUndoRedoLevels) {
  17294. for (var i = 0; i < undoManager.data.length - 1; i++) {
  17295. undoManager.data[i] = undoManager.data[i + 1];
  17296. }
  17297. undoManager.data.length--;
  17298. index.set(undoManager.data.length);
  17299. }
  17300. }
  17301. level.bookmark = getUndoBookmark(editor.selection);
  17302. if (index.get() < undoManager.data.length - 1) {
  17303. undoManager.data.length = index.get() + 1;
  17304. }
  17305. undoManager.data.push(level);
  17306. index.set(undoManager.data.length - 1);
  17307. var args = {
  17308. level,
  17309. lastLevel,
  17310. originalEvent: event
  17311. };
  17312. if (index.get() > 0) {
  17313. editor.setDirty(true);
  17314. editor.fire("AddUndo", args);
  17315. editor.fire("change", args);
  17316. } else {
  17317. editor.fire("AddUndo", args);
  17318. }
  17319. return level;
  17320. };
  17321. var clear$1 = function(editor, undoManager, index) {
  17322. undoManager.data = [];
  17323. index.set(0);
  17324. undoManager.typing = false;
  17325. editor.fire("ClearUndos");
  17326. };
  17327. var extra$1 = function(editor, undoManager, index, callback1, callback2) {
  17328. if (undoManager.transact(callback1)) {
  17329. var bookmark = undoManager.data[index.get()].bookmark;
  17330. var lastLevel = undoManager.data[index.get() - 1];
  17331. applyToEditor(editor, lastLevel, true);
  17332. if (undoManager.transact(callback2)) {
  17333. undoManager.data[index.get() - 1].beforeBookmark = bookmark;
  17334. }
  17335. }
  17336. };
  17337. var redo$1 = function(editor, index, data2) {
  17338. var level;
  17339. if (index.get() < data2.length - 1) {
  17340. index.set(index.get() + 1);
  17341. level = data2[index.get()];
  17342. applyToEditor(editor, level, false);
  17343. editor.setDirty(true);
  17344. editor.fire("Redo", { level });
  17345. }
  17346. return level;
  17347. };
  17348. var undo$1 = function(editor, undoManager, locks, index) {
  17349. var level;
  17350. if (undoManager.typing) {
  17351. undoManager.add();
  17352. undoManager.typing = false;
  17353. setTyping(undoManager, false, locks);
  17354. }
  17355. if (index.get() > 0) {
  17356. index.set(index.get() - 1);
  17357. level = undoManager.data[index.get()];
  17358. applyToEditor(editor, level, true);
  17359. editor.setDirty(true);
  17360. editor.fire("Undo", { level });
  17361. }
  17362. return level;
  17363. };
  17364. var reset$1 = function(undoManager) {
  17365. undoManager.clear();
  17366. undoManager.add();
  17367. };
  17368. var hasUndo$1 = function(editor, undoManager, index) {
  17369. return index.get() > 0 || undoManager.typing && undoManager.data[0] && !isEq$1(createFromEditor(editor), undoManager.data[0]);
  17370. };
  17371. var hasRedo$1 = function(undoManager, index) {
  17372. return index.get() < undoManager.data.length - 1 && !undoManager.typing;
  17373. };
  17374. var transact$1 = function(undoManager, locks, callback) {
  17375. endTyping(undoManager, locks);
  17376. undoManager.beforeChange();
  17377. undoManager.ignore(callback);
  17378. return undoManager.add();
  17379. };
  17380. var ignore$1 = function(locks, callback) {
  17381. try {
  17382. locks.set(locks.get() + 1);
  17383. callback();
  17384. } finally {
  17385. locks.set(locks.get() - 1);
  17386. }
  17387. };
  17388. var addVisualInternal = function(editor, elm) {
  17389. var dom2 = editor.dom;
  17390. var scope = isNonNullable(elm) ? elm : editor.getBody();
  17391. if (isUndefined(editor.hasVisual)) {
  17392. editor.hasVisual = isVisualAidsEnabled(editor);
  17393. }
  17394. each$k(dom2.select("table,a", scope), function(matchedElm) {
  17395. switch (matchedElm.nodeName) {
  17396. case "TABLE":
  17397. var cls = getVisualAidsTableClass(editor);
  17398. var value2 = dom2.getAttrib(matchedElm, "border");
  17399. if ((!value2 || value2 === "0") && editor.hasVisual) {
  17400. dom2.addClass(matchedElm, cls);
  17401. } else {
  17402. dom2.removeClass(matchedElm, cls);
  17403. }
  17404. break;
  17405. case "A":
  17406. if (!dom2.getAttrib(matchedElm, "href")) {
  17407. var value_1 = dom2.getAttrib(matchedElm, "name") || matchedElm.id;
  17408. var cls_1 = getVisualAidsAnchorClass(editor);
  17409. if (value_1 && editor.hasVisual) {
  17410. dom2.addClass(matchedElm, cls_1);
  17411. } else {
  17412. dom2.removeClass(matchedElm, cls_1);
  17413. }
  17414. }
  17415. break;
  17416. }
  17417. });
  17418. editor.fire("VisualAid", {
  17419. element: elm,
  17420. hasVisual: editor.hasVisual
  17421. });
  17422. };
  17423. var makePlainAdaptor = function(editor) {
  17424. return {
  17425. undoManager: {
  17426. beforeChange: function(locks, beforeBookmark) {
  17427. return beforeChange$1(editor, locks, beforeBookmark);
  17428. },
  17429. add: function(undoManager, index, locks, beforeBookmark, level, event) {
  17430. return addUndoLevel$1(editor, undoManager, index, locks, beforeBookmark, level, event);
  17431. },
  17432. undo: function(undoManager, locks, index) {
  17433. return undo$1(editor, undoManager, locks, index);
  17434. },
  17435. redo: function(index, data2) {
  17436. return redo$1(editor, index, data2);
  17437. },
  17438. clear: function(undoManager, index) {
  17439. return clear$1(editor, undoManager, index);
  17440. },
  17441. reset: function(undoManager) {
  17442. return reset$1(undoManager);
  17443. },
  17444. hasUndo: function(undoManager, index) {
  17445. return hasUndo$1(editor, undoManager, index);
  17446. },
  17447. hasRedo: function(undoManager, index) {
  17448. return hasRedo$1(undoManager, index);
  17449. },
  17450. transact: function(undoManager, locks, callback) {
  17451. return transact$1(undoManager, locks, callback);
  17452. },
  17453. ignore: function(locks, callback) {
  17454. return ignore$1(locks, callback);
  17455. },
  17456. extra: function(undoManager, index, callback1, callback2) {
  17457. return extra$1(editor, undoManager, index, callback1, callback2);
  17458. }
  17459. },
  17460. formatter: {
  17461. match: function(name2, vars, node, similar) {
  17462. return match$2(editor, name2, vars, node, similar);
  17463. },
  17464. matchAll: function(names, vars) {
  17465. return matchAll(editor, names, vars);
  17466. },
  17467. matchNode: function(node, name2, vars, similar) {
  17468. return matchNode(editor, node, name2, vars, similar);
  17469. },
  17470. canApply: function(name2) {
  17471. return canApply(editor, name2);
  17472. },
  17473. closest: function(names) {
  17474. return closest(editor, names);
  17475. },
  17476. apply: function(name2, vars, node) {
  17477. return applyFormat$1(editor, name2, vars, node);
  17478. },
  17479. remove: function(name2, vars, node, similar) {
  17480. return remove$1(editor, name2, vars, node, similar);
  17481. },
  17482. toggle: function(name2, vars, node) {
  17483. return toggle(editor, name2, vars, node);
  17484. },
  17485. formatChanged: function(registeredFormatListeners, formats, callback, similar, vars) {
  17486. return formatChangedInternal(editor, registeredFormatListeners, formats, callback, similar, vars);
  17487. }
  17488. },
  17489. editor: {
  17490. getContent: function(args, format) {
  17491. return getContentInternal(editor, args, format);
  17492. },
  17493. setContent: function(content, args) {
  17494. return setContentInternal(editor, content, args);
  17495. },
  17496. insertContent: function(value2, details) {
  17497. return insertHtmlAtCaret(editor, value2, details);
  17498. },
  17499. addVisual: function(elm) {
  17500. return addVisualInternal(editor, elm);
  17501. }
  17502. },
  17503. selection: {
  17504. getContent: function(format, args) {
  17505. return getSelectedContentInternal(editor, format, args);
  17506. }
  17507. },
  17508. raw: {
  17509. getModel: function() {
  17510. return Optional.none();
  17511. }
  17512. }
  17513. };
  17514. };
  17515. var makeRtcAdaptor = function(rtcEditor) {
  17516. var defaultVars = function(vars) {
  17517. return isObject(vars) ? vars : {};
  17518. };
  17519. var undoManager = rtcEditor.undoManager, formatter = rtcEditor.formatter, editor = rtcEditor.editor, selection = rtcEditor.selection, raw = rtcEditor.raw;
  17520. return {
  17521. undoManager: {
  17522. beforeChange: undoManager.beforeChange,
  17523. add: undoManager.add,
  17524. undo: undoManager.undo,
  17525. redo: undoManager.redo,
  17526. clear: undoManager.clear,
  17527. reset: undoManager.reset,
  17528. hasUndo: undoManager.hasUndo,
  17529. hasRedo: undoManager.hasRedo,
  17530. transact: function(_undoManager, _locks, fn) {
  17531. return undoManager.transact(fn);
  17532. },
  17533. ignore: function(_locks, callback) {
  17534. return undoManager.ignore(callback);
  17535. },
  17536. extra: function(_undoManager, _index, callback1, callback2) {
  17537. return undoManager.extra(callback1, callback2);
  17538. }
  17539. },
  17540. formatter: {
  17541. match: function(name2, vars, _node, similar) {
  17542. return formatter.match(name2, defaultVars(vars), similar);
  17543. },
  17544. matchAll: formatter.matchAll,
  17545. matchNode: formatter.matchNode,
  17546. canApply: function(name2) {
  17547. return formatter.canApply(name2);
  17548. },
  17549. closest: function(names) {
  17550. return formatter.closest(names);
  17551. },
  17552. apply: function(name2, vars, _node) {
  17553. return formatter.apply(name2, defaultVars(vars));
  17554. },
  17555. remove: function(name2, vars, _node, _similar) {
  17556. return formatter.remove(name2, defaultVars(vars));
  17557. },
  17558. toggle: function(name2, vars, _node) {
  17559. return formatter.toggle(name2, defaultVars(vars));
  17560. },
  17561. formatChanged: function(_rfl, formats, callback, similar, vars) {
  17562. return formatter.formatChanged(formats, callback, similar, vars);
  17563. }
  17564. },
  17565. editor: {
  17566. getContent: function(args, _format) {
  17567. return editor.getContent(args);
  17568. },
  17569. setContent: function(content, args) {
  17570. return editor.setContent(content, args);
  17571. },
  17572. insertContent: function(content, _details) {
  17573. return editor.insertContent(content);
  17574. },
  17575. addVisual: editor.addVisual
  17576. },
  17577. selection: {
  17578. getContent: function(_format, args) {
  17579. return selection.getContent(args);
  17580. }
  17581. },
  17582. raw: {
  17583. getModel: function() {
  17584. return Optional.some(raw.getRawModel());
  17585. }
  17586. }
  17587. };
  17588. };
  17589. var makeNoopAdaptor = function() {
  17590. var nul = constant(null);
  17591. var empty2 = constant("");
  17592. return {
  17593. undoManager: {
  17594. beforeChange: noop,
  17595. add: nul,
  17596. undo: nul,
  17597. redo: nul,
  17598. clear: noop,
  17599. reset: noop,
  17600. hasUndo: never,
  17601. hasRedo: never,
  17602. transact: nul,
  17603. ignore: noop,
  17604. extra: noop
  17605. },
  17606. formatter: {
  17607. match: never,
  17608. matchAll: constant([]),
  17609. matchNode: constant(void 0),
  17610. canApply: never,
  17611. closest: empty2,
  17612. apply: noop,
  17613. remove: noop,
  17614. toggle: noop,
  17615. formatChanged: constant({ unbind: noop })
  17616. },
  17617. editor: {
  17618. getContent: empty2,
  17619. setContent: empty2,
  17620. insertContent: noop,
  17621. addVisual: noop
  17622. },
  17623. selection: { getContent: empty2 },
  17624. raw: { getModel: constant(Optional.none()) }
  17625. };
  17626. };
  17627. var isRtc = function(editor) {
  17628. return has$2(editor.plugins, "rtc");
  17629. };
  17630. var getRtcSetup = function(editor) {
  17631. return get$9(editor.plugins, "rtc").bind(function(rtcPlugin) {
  17632. return Optional.from(rtcPlugin.setup);
  17633. });
  17634. };
  17635. var setup$i = function(editor) {
  17636. var editorCast = editor;
  17637. return getRtcSetup(editor).fold(function() {
  17638. editorCast.rtcInstance = makePlainAdaptor(editor);
  17639. return Optional.none();
  17640. }, function(setup2) {
  17641. editorCast.rtcInstance = makeNoopAdaptor();
  17642. return Optional.some(function() {
  17643. return setup2().then(function(rtcEditor) {
  17644. editorCast.rtcInstance = makeRtcAdaptor(rtcEditor);
  17645. return rtcEditor.rtc.isRemote;
  17646. });
  17647. });
  17648. });
  17649. };
  17650. var getRtcInstanceWithFallback = function(editor) {
  17651. return editor.rtcInstance ? editor.rtcInstance : makePlainAdaptor(editor);
  17652. };
  17653. var getRtcInstanceWithError = function(editor) {
  17654. var rtcInstance = editor.rtcInstance;
  17655. if (!rtcInstance) {
  17656. throw new Error("Failed to get RTC instance not yet initialized.");
  17657. } else {
  17658. return rtcInstance;
  17659. }
  17660. };
  17661. var beforeChange = function(editor, locks, beforeBookmark) {
  17662. getRtcInstanceWithError(editor).undoManager.beforeChange(locks, beforeBookmark);
  17663. };
  17664. var addUndoLevel = function(editor, undoManager, index, locks, beforeBookmark, level, event) {
  17665. return getRtcInstanceWithError(editor).undoManager.add(undoManager, index, locks, beforeBookmark, level, event);
  17666. };
  17667. var undo = function(editor, undoManager, locks, index) {
  17668. return getRtcInstanceWithError(editor).undoManager.undo(undoManager, locks, index);
  17669. };
  17670. var redo = function(editor, index, data2) {
  17671. return getRtcInstanceWithError(editor).undoManager.redo(index, data2);
  17672. };
  17673. var clear = function(editor, undoManager, index) {
  17674. getRtcInstanceWithError(editor).undoManager.clear(undoManager, index);
  17675. };
  17676. var reset = function(editor, undoManager) {
  17677. getRtcInstanceWithError(editor).undoManager.reset(undoManager);
  17678. };
  17679. var hasUndo = function(editor, undoManager, index) {
  17680. return getRtcInstanceWithError(editor).undoManager.hasUndo(undoManager, index);
  17681. };
  17682. var hasRedo = function(editor, undoManager, index) {
  17683. return getRtcInstanceWithError(editor).undoManager.hasRedo(undoManager, index);
  17684. };
  17685. var transact = function(editor, undoManager, locks, callback) {
  17686. return getRtcInstanceWithError(editor).undoManager.transact(undoManager, locks, callback);
  17687. };
  17688. var ignore = function(editor, locks, callback) {
  17689. getRtcInstanceWithError(editor).undoManager.ignore(locks, callback);
  17690. };
  17691. var extra = function(editor, undoManager, index, callback1, callback2) {
  17692. getRtcInstanceWithError(editor).undoManager.extra(undoManager, index, callback1, callback2);
  17693. };
  17694. var matchFormat = function(editor, name2, vars, node, similar) {
  17695. return getRtcInstanceWithError(editor).formatter.match(name2, vars, node, similar);
  17696. };
  17697. var matchAllFormats = function(editor, names, vars) {
  17698. return getRtcInstanceWithError(editor).formatter.matchAll(names, vars);
  17699. };
  17700. var matchNodeFormat = function(editor, node, name2, vars, similar) {
  17701. return getRtcInstanceWithError(editor).formatter.matchNode(node, name2, vars, similar);
  17702. };
  17703. var canApplyFormat = function(editor, name2) {
  17704. return getRtcInstanceWithError(editor).formatter.canApply(name2);
  17705. };
  17706. var closestFormat = function(editor, names) {
  17707. return getRtcInstanceWithError(editor).formatter.closest(names);
  17708. };
  17709. var applyFormat = function(editor, name2, vars, node) {
  17710. getRtcInstanceWithError(editor).formatter.apply(name2, vars, node);
  17711. };
  17712. var removeFormat = function(editor, name2, vars, node, similar) {
  17713. getRtcInstanceWithError(editor).formatter.remove(name2, vars, node, similar);
  17714. };
  17715. var toggleFormat = function(editor, name2, vars, node) {
  17716. getRtcInstanceWithError(editor).formatter.toggle(name2, vars, node);
  17717. };
  17718. var formatChanged = function(editor, registeredFormatListeners, formats, callback, similar, vars) {
  17719. return getRtcInstanceWithError(editor).formatter.formatChanged(registeredFormatListeners, formats, callback, similar, vars);
  17720. };
  17721. var getContent$2 = function(editor, args, format) {
  17722. return getRtcInstanceWithFallback(editor).editor.getContent(args, format);
  17723. };
  17724. var setContent$2 = function(editor, content, args) {
  17725. return getRtcInstanceWithFallback(editor).editor.setContent(content, args);
  17726. };
  17727. var insertContent = function(editor, value2, details) {
  17728. return getRtcInstanceWithFallback(editor).editor.insertContent(value2, details);
  17729. };
  17730. var getSelectedContent = function(editor, format, args) {
  17731. return getRtcInstanceWithError(editor).selection.getContent(format, args);
  17732. };
  17733. var addVisual$1 = function(editor, elm) {
  17734. return getRtcInstanceWithError(editor).editor.addVisual(elm);
  17735. };
  17736. var getContent$1 = function(editor, args) {
  17737. if (args === void 0) {
  17738. args = {};
  17739. }
  17740. var format = args.format ? args.format : "html";
  17741. return getSelectedContent(editor, format, args);
  17742. };
  17743. var removeEmpty = function(text) {
  17744. if (text.dom.length === 0) {
  17745. remove$7(text);
  17746. return Optional.none();
  17747. } else {
  17748. return Optional.some(text);
  17749. }
  17750. };
  17751. var walkPastBookmark = function(node, start2) {
  17752. return node.filter(function(elm) {
  17753. return BookmarkManager.isBookmarkNode(elm.dom);
  17754. }).bind(start2 ? nextSibling : prevSibling);
  17755. };
  17756. var merge = function(outer, inner, rng, start2) {
  17757. var outerElm = outer.dom;
  17758. var innerElm = inner.dom;
  17759. var oldLength = start2 ? outerElm.length : innerElm.length;
  17760. if (start2) {
  17761. mergeTextNodes(outerElm, innerElm, false, !start2);
  17762. rng.setStart(innerElm, oldLength);
  17763. } else {
  17764. mergeTextNodes(innerElm, outerElm, false, !start2);
  17765. rng.setEnd(innerElm, oldLength);
  17766. }
  17767. };
  17768. var normalizeTextIfRequired = function(inner, start2) {
  17769. parent(inner).each(function(root) {
  17770. var text = inner.dom;
  17771. if (start2 && needsToBeNbspLeft(root, CaretPosition(text, 0))) {
  17772. normalizeWhitespaceAfter(text, 0);
  17773. } else if (!start2 && needsToBeNbspRight(root, CaretPosition(text, text.length))) {
  17774. normalizeWhitespaceBefore(text, text.length);
  17775. }
  17776. });
  17777. };
  17778. var mergeAndNormalizeText = function(outerNode, innerNode, rng, start2) {
  17779. outerNode.bind(function(outer) {
  17780. var normalizer = start2 ? normalizeWhitespaceBefore : normalizeWhitespaceAfter;
  17781. normalizer(outer.dom, start2 ? outer.dom.length : 0);
  17782. return innerNode.filter(isText$8).map(function(inner) {
  17783. return merge(outer, inner, rng, start2);
  17784. });
  17785. }).orThunk(function() {
  17786. var innerTextNode = walkPastBookmark(innerNode, start2).or(innerNode).filter(isText$8);
  17787. return innerTextNode.map(function(inner) {
  17788. return normalizeTextIfRequired(inner, start2);
  17789. });
  17790. });
  17791. };
  17792. var rngSetContent = function(rng, fragment) {
  17793. var firstChild2 = Optional.from(fragment.firstChild).map(SugarElement.fromDom);
  17794. var lastChild2 = Optional.from(fragment.lastChild).map(SugarElement.fromDom);
  17795. rng.deleteContents();
  17796. rng.insertNode(fragment);
  17797. var prevText = firstChild2.bind(prevSibling).filter(isText$8).bind(removeEmpty);
  17798. var nextText = lastChild2.bind(nextSibling).filter(isText$8).bind(removeEmpty);
  17799. mergeAndNormalizeText(prevText, firstChild2, rng, true);
  17800. mergeAndNormalizeText(nextText, lastChild2, rng, false);
  17801. rng.collapse(false);
  17802. };
  17803. var setupArgs = function(args, content) {
  17804. return __assign(__assign({ format: "html" }, args), {
  17805. set: true,
  17806. selection: true,
  17807. content
  17808. });
  17809. };
  17810. var cleanContent = function(editor, args) {
  17811. if (args.format !== "raw") {
  17812. var rng = editor.selection.getRng();
  17813. var contextBlock = editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock);
  17814. var contextArgs = contextBlock ? { context: contextBlock.nodeName.toLowerCase() } : {};
  17815. var node = editor.parser.parse(args.content, __assign(__assign({
  17816. isRootContent: true,
  17817. forced_root_block: false
  17818. }, contextArgs), args));
  17819. return HtmlSerializer({ validate: editor.validate }, editor.schema).serialize(node);
  17820. } else {
  17821. return args.content;
  17822. }
  17823. };
  17824. var setContent$1 = function(editor, content, args) {
  17825. if (args === void 0) {
  17826. args = {};
  17827. }
  17828. var defaultedArgs = setupArgs(args, content);
  17829. var updatedArgs = defaultedArgs;
  17830. if (!defaultedArgs.no_events) {
  17831. var eventArgs = editor.fire("BeforeSetContent", defaultedArgs);
  17832. if (eventArgs.isDefaultPrevented()) {
  17833. editor.fire("SetContent", eventArgs);
  17834. return;
  17835. } else {
  17836. updatedArgs = eventArgs;
  17837. }
  17838. }
  17839. updatedArgs.content = cleanContent(editor, updatedArgs);
  17840. var rng = editor.selection.getRng();
  17841. rngSetContent(rng, rng.createContextualFragment(updatedArgs.content));
  17842. editor.selection.setRng(rng);
  17843. scrollRangeIntoView(editor, rng);
  17844. if (!updatedArgs.no_events) {
  17845. editor.fire("SetContent", updatedArgs);
  17846. }
  17847. };
  17848. var deleteFromCallbackMap = function(callbackMap, selector, callback) {
  17849. if (callbackMap && has$2(callbackMap, selector)) {
  17850. var newCallbacks = filter$4(callbackMap[selector], function(cb) {
  17851. return cb !== callback;
  17852. });
  17853. if (newCallbacks.length === 0) {
  17854. delete callbackMap[selector];
  17855. } else {
  17856. callbackMap[selector] = newCallbacks;
  17857. }
  17858. }
  17859. };
  17860. function SelectorChanged(dom2, editor) {
  17861. var selectorChangedData;
  17862. var currentSelectors;
  17863. var findMatchingNode = function(selector, nodes) {
  17864. return find$3(nodes, function(node) {
  17865. return dom2.is(node, selector);
  17866. });
  17867. };
  17868. var getParents2 = function(elem) {
  17869. return dom2.getParents(elem, null, dom2.getRoot());
  17870. };
  17871. return {
  17872. selectorChangedWithUnbind: function(selector, callback) {
  17873. if (!selectorChangedData) {
  17874. selectorChangedData = {};
  17875. currentSelectors = {};
  17876. editor.on("NodeChange", function(e) {
  17877. var node = e.element;
  17878. var parents2 = getParents2(node);
  17879. var matchedSelectors = {};
  17880. Tools.each(selectorChangedData, function(callbacks, selector2) {
  17881. findMatchingNode(selector2, parents2).each(function(node2) {
  17882. if (!currentSelectors[selector2]) {
  17883. each$k(callbacks, function(callback2) {
  17884. callback2(true, {
  17885. node: node2,
  17886. selector: selector2,
  17887. parents: parents2
  17888. });
  17889. });
  17890. currentSelectors[selector2] = callbacks;
  17891. }
  17892. matchedSelectors[selector2] = callbacks;
  17893. });
  17894. });
  17895. Tools.each(currentSelectors, function(callbacks, selector2) {
  17896. if (!matchedSelectors[selector2]) {
  17897. delete currentSelectors[selector2];
  17898. Tools.each(callbacks, function(callback2) {
  17899. callback2(false, {
  17900. node,
  17901. selector: selector2,
  17902. parents: parents2
  17903. });
  17904. });
  17905. }
  17906. });
  17907. });
  17908. }
  17909. if (!selectorChangedData[selector]) {
  17910. selectorChangedData[selector] = [];
  17911. }
  17912. selectorChangedData[selector].push(callback);
  17913. findMatchingNode(selector, getParents2(editor.selection.getStart())).each(function() {
  17914. currentSelectors[selector] = selectorChangedData[selector];
  17915. });
  17916. return {
  17917. unbind: function() {
  17918. deleteFromCallbackMap(selectorChangedData, selector, callback);
  17919. deleteFromCallbackMap(currentSelectors, selector, callback);
  17920. }
  17921. };
  17922. }
  17923. };
  17924. }
  17925. var isNativeIeSelection = function(rng) {
  17926. return !!rng.select;
  17927. };
  17928. var isAttachedToDom = function(node) {
  17929. return !!(node && node.ownerDocument) && contains$1(SugarElement.fromDom(node.ownerDocument), SugarElement.fromDom(node));
  17930. };
  17931. var isValidRange = function(rng) {
  17932. if (!rng) {
  17933. return false;
  17934. } else if (isNativeIeSelection(rng)) {
  17935. return true;
  17936. } else {
  17937. return isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer);
  17938. }
  17939. };
  17940. var EditorSelection = function(dom2, win, serializer, editor) {
  17941. var selectedRange;
  17942. var explicitRange;
  17943. var selectorChangedWithUnbind = SelectorChanged(dom2, editor).selectorChangedWithUnbind;
  17944. var setCursorLocation = function(node, offset) {
  17945. var rng = dom2.createRng();
  17946. if (isNonNullable(node) && isNonNullable(offset)) {
  17947. rng.setStart(node, offset);
  17948. rng.setEnd(node, offset);
  17949. setRng(rng);
  17950. collapse2(false);
  17951. } else {
  17952. moveEndPoint(dom2, rng, editor.getBody(), true);
  17953. setRng(rng);
  17954. }
  17955. };
  17956. var getContent2 = function(args) {
  17957. return getContent$1(editor, args);
  17958. };
  17959. var setContent2 = function(content, args) {
  17960. return setContent$1(editor, content, args);
  17961. };
  17962. var getStart$12 = function(real) {
  17963. return getStart(editor.getBody(), getRng$1(), real);
  17964. };
  17965. var getEnd$1 = function(real) {
  17966. return getEnd(editor.getBody(), getRng$1(), real);
  17967. };
  17968. var getBookmark2 = function(type2, normalized) {
  17969. return bookmarkManager.getBookmark(type2, normalized);
  17970. };
  17971. var moveToBookmark2 = function(bookmark) {
  17972. return bookmarkManager.moveToBookmark(bookmark);
  17973. };
  17974. var select$12 = function(node, content) {
  17975. select(dom2, node, content).each(setRng);
  17976. return node;
  17977. };
  17978. var isCollapsed = function() {
  17979. var rng = getRng$1(), sel = getSel();
  17980. if (!rng || rng.item) {
  17981. return false;
  17982. }
  17983. if (rng.compareEndPoints) {
  17984. return rng.compareEndPoints("StartToEnd", rng) === 0;
  17985. }
  17986. return !sel || rng.collapsed;
  17987. };
  17988. var collapse2 = function(toStart) {
  17989. var rng = getRng$1();
  17990. rng.collapse(!!toStart);
  17991. setRng(rng);
  17992. };
  17993. var getSel = function() {
  17994. return win.getSelection ? win.getSelection() : win.document.selection;
  17995. };
  17996. var getRng$1 = function() {
  17997. var selection, rng, elm;
  17998. var tryCompareBoundaryPoints = function(how, sourceRange, destinationRange) {
  17999. try {
  18000. return sourceRange.compareBoundaryPoints(how, destinationRange);
  18001. } catch (ex) {
  18002. return -1;
  18003. }
  18004. };
  18005. var doc2 = win.document;
  18006. if (editor.bookmark !== void 0 && hasFocus(editor) === false) {
  18007. var bookmark = getRng(editor);
  18008. if (bookmark.isSome()) {
  18009. return bookmark.map(function(r2) {
  18010. return processRanges(editor, [r2])[0];
  18011. }).getOr(doc2.createRange());
  18012. }
  18013. }
  18014. try {
  18015. if ((selection = getSel()) && !isRestrictedNode(selection.anchorNode)) {
  18016. if (selection.rangeCount > 0) {
  18017. rng = selection.getRangeAt(0);
  18018. } else {
  18019. rng = selection.createRange ? selection.createRange() : doc2.createRange();
  18020. }
  18021. rng = processRanges(editor, [rng])[0];
  18022. }
  18023. } catch (ex) {
  18024. }
  18025. if (!rng) {
  18026. rng = doc2.createRange ? doc2.createRange() : doc2.body.createTextRange();
  18027. }
  18028. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  18029. elm = dom2.getRoot();
  18030. rng.setStart(elm, 0);
  18031. rng.setEnd(elm, 0);
  18032. }
  18033. if (selectedRange && explicitRange) {
  18034. if (tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) === 0 && tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0) {
  18035. rng = explicitRange;
  18036. } else {
  18037. selectedRange = null;
  18038. explicitRange = null;
  18039. }
  18040. }
  18041. return rng;
  18042. };
  18043. var setRng = function(rng, forward) {
  18044. var node;
  18045. if (!isValidRange(rng)) {
  18046. return;
  18047. }
  18048. var ieRange = isNativeIeSelection(rng) ? rng : null;
  18049. if (ieRange) {
  18050. explicitRange = null;
  18051. try {
  18052. ieRange.select();
  18053. } catch (ex) {
  18054. }
  18055. return;
  18056. }
  18057. var sel = getSel();
  18058. var evt = editor.fire("SetSelectionRange", {
  18059. range: rng,
  18060. forward
  18061. });
  18062. rng = evt.range;
  18063. if (sel) {
  18064. explicitRange = rng;
  18065. try {
  18066. sel.removeAllRanges();
  18067. sel.addRange(rng);
  18068. } catch (ex) {
  18069. }
  18070. if (forward === false && sel.extend) {
  18071. sel.collapse(rng.endContainer, rng.endOffset);
  18072. sel.extend(rng.startContainer, rng.startOffset);
  18073. }
  18074. selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
  18075. }
  18076. if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent && !Env.ie) {
  18077. if (rng.endOffset - rng.startOffset < 2) {
  18078. if (rng.startContainer.hasChildNodes()) {
  18079. node = rng.startContainer.childNodes[rng.startOffset];
  18080. if (node && node.tagName === "IMG") {
  18081. sel.setBaseAndExtent(rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset);
  18082. if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) {
  18083. sel.setBaseAndExtent(node, 0, node, 1);
  18084. }
  18085. }
  18086. }
  18087. }
  18088. }
  18089. editor.fire("AfterSetSelectionRange", {
  18090. range: rng,
  18091. forward
  18092. });
  18093. };
  18094. var setNode = function(elm) {
  18095. setContent2(dom2.getOuterHTML(elm));
  18096. return elm;
  18097. };
  18098. var getNode$12 = function() {
  18099. return getNode(editor.getBody(), getRng$1());
  18100. };
  18101. var getSelectedBlocks$1 = function(startElm, endElm) {
  18102. return getSelectedBlocks(dom2, getRng$1(), startElm, endElm);
  18103. };
  18104. var isForward = function() {
  18105. var sel = getSel();
  18106. var anchorNode = sel === null || sel === void 0 ? void 0 : sel.anchorNode;
  18107. var focusNode = sel === null || sel === void 0 ? void 0 : sel.focusNode;
  18108. if (!sel || !anchorNode || !focusNode || isRestrictedNode(anchorNode) || isRestrictedNode(focusNode)) {
  18109. return true;
  18110. }
  18111. var anchorRange = dom2.createRng();
  18112. anchorRange.setStart(anchorNode, sel.anchorOffset);
  18113. anchorRange.collapse(true);
  18114. var focusRange = dom2.createRng();
  18115. focusRange.setStart(focusNode, sel.focusOffset);
  18116. focusRange.collapse(true);
  18117. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  18118. };
  18119. var normalize2 = function() {
  18120. var rng = getRng$1();
  18121. var sel = getSel();
  18122. if (!hasMultipleRanges(sel) && hasAnyRanges(editor)) {
  18123. var normRng = normalize$2(dom2, rng);
  18124. normRng.each(function(normRng2) {
  18125. setRng(normRng2, isForward());
  18126. });
  18127. return normRng.getOr(rng);
  18128. }
  18129. return rng;
  18130. };
  18131. var selectorChanged = function(selector, callback) {
  18132. selectorChangedWithUnbind(selector, callback);
  18133. return exports2;
  18134. };
  18135. var getScrollContainer = function() {
  18136. var scrollContainer;
  18137. var node = dom2.getRoot();
  18138. while (node && node.nodeName !== "BODY") {
  18139. if (node.scrollHeight > node.clientHeight) {
  18140. scrollContainer = node;
  18141. break;
  18142. }
  18143. node = node.parentNode;
  18144. }
  18145. return scrollContainer;
  18146. };
  18147. var scrollIntoView = function(elm, alignToTop) {
  18148. if (isNonNullable(elm)) {
  18149. scrollElementIntoView(editor, elm, alignToTop);
  18150. } else {
  18151. scrollRangeIntoView(editor, getRng$1(), alignToTop);
  18152. }
  18153. };
  18154. var placeCaretAt = function(clientX, clientY) {
  18155. return setRng(fromPoint(clientX, clientY, editor.getDoc()));
  18156. };
  18157. var getBoundingClientRect2 = function() {
  18158. var rng = getRng$1();
  18159. return rng.collapsed ? CaretPosition.fromRangeStart(rng).getClientRects()[0] : rng.getBoundingClientRect();
  18160. };
  18161. var destroy2 = function() {
  18162. win = selectedRange = explicitRange = null;
  18163. controlSelection.destroy();
  18164. };
  18165. var exports2 = {
  18166. bookmarkManager: null,
  18167. controlSelection: null,
  18168. dom: dom2,
  18169. win,
  18170. serializer,
  18171. editor,
  18172. collapse: collapse2,
  18173. setCursorLocation,
  18174. getContent: getContent2,
  18175. setContent: setContent2,
  18176. getBookmark: getBookmark2,
  18177. moveToBookmark: moveToBookmark2,
  18178. select: select$12,
  18179. isCollapsed,
  18180. isForward,
  18181. setNode,
  18182. getNode: getNode$12,
  18183. getSel,
  18184. setRng,
  18185. getRng: getRng$1,
  18186. getStart: getStart$12,
  18187. getEnd: getEnd$1,
  18188. getSelectedBlocks: getSelectedBlocks$1,
  18189. normalize: normalize2,
  18190. selectorChanged,
  18191. selectorChangedWithUnbind,
  18192. getScrollContainer,
  18193. scrollIntoView,
  18194. placeCaretAt,
  18195. getBoundingClientRect: getBoundingClientRect2,
  18196. destroy: destroy2
  18197. };
  18198. var bookmarkManager = BookmarkManager(exports2);
  18199. var controlSelection = ControlSelection(exports2, editor);
  18200. exports2.bookmarkManager = bookmarkManager;
  18201. exports2.controlSelection = controlSelection;
  18202. return exports2;
  18203. };
  18204. var removeAttrs = function(node, names) {
  18205. each$k(names, function(name2) {
  18206. node.attr(name2, null);
  18207. });
  18208. };
  18209. var addFontToSpansFilter = function(domParser, styles, fontSizes) {
  18210. domParser.addNodeFilter("font", function(nodes) {
  18211. each$k(nodes, function(node) {
  18212. var props = styles.parse(node.attr("style"));
  18213. var color = node.attr("color");
  18214. var face = node.attr("face");
  18215. var size = node.attr("size");
  18216. if (color) {
  18217. props.color = color;
  18218. }
  18219. if (face) {
  18220. props["font-family"] = face;
  18221. }
  18222. if (size) {
  18223. props["font-size"] = fontSizes[parseInt(node.attr("size"), 10) - 1];
  18224. }
  18225. node.name = "span";
  18226. node.attr("style", styles.serialize(props));
  18227. removeAttrs(node, [
  18228. "color",
  18229. "face",
  18230. "size"
  18231. ]);
  18232. });
  18233. });
  18234. };
  18235. var addStrikeToSpanFilter = function(domParser, styles) {
  18236. domParser.addNodeFilter("strike", function(nodes) {
  18237. each$k(nodes, function(node) {
  18238. var props = styles.parse(node.attr("style"));
  18239. props["text-decoration"] = "line-through";
  18240. node.name = "span";
  18241. node.attr("style", styles.serialize(props));
  18242. });
  18243. });
  18244. };
  18245. var addFilters = function(domParser, settings) {
  18246. var styles = Styles();
  18247. if (settings.convert_fonts_to_spans) {
  18248. addFontToSpansFilter(domParser, styles, Tools.explode(settings.font_size_legacy_values));
  18249. }
  18250. addStrikeToSpanFilter(domParser, styles);
  18251. };
  18252. var register$2 = function(domParser, settings) {
  18253. if (settings.inline_styles) {
  18254. addFilters(domParser, settings);
  18255. }
  18256. };
  18257. var blobUriToBlob = function(url) {
  18258. return new promiseObj(function(resolve2, reject) {
  18259. var rejectWithError = function() {
  18260. reject("Cannot convert " + url + " to Blob. Resource might not exist or is inaccessible.");
  18261. };
  18262. try {
  18263. var xhr_1 = new XMLHttpRequest();
  18264. xhr_1.open("GET", url, true);
  18265. xhr_1.responseType = "blob";
  18266. xhr_1.onload = function() {
  18267. if (xhr_1.status === 200) {
  18268. resolve2(xhr_1.response);
  18269. } else {
  18270. rejectWithError();
  18271. }
  18272. };
  18273. xhr_1.onerror = rejectWithError;
  18274. xhr_1.send();
  18275. } catch (ex) {
  18276. rejectWithError();
  18277. }
  18278. });
  18279. };
  18280. var parseDataUri = function(uri) {
  18281. var type2;
  18282. var uriParts = decodeURIComponent(uri).split(",");
  18283. var matches2 = /data:([^;]+)/.exec(uriParts[0]);
  18284. if (matches2) {
  18285. type2 = matches2[1];
  18286. }
  18287. return {
  18288. type: type2,
  18289. data: uriParts[1]
  18290. };
  18291. };
  18292. var buildBlob = function(type2, data2) {
  18293. var str;
  18294. try {
  18295. str = atob(data2);
  18296. } catch (e) {
  18297. return Optional.none();
  18298. }
  18299. var arr2 = new Uint8Array(str.length);
  18300. for (var i = 0; i < arr2.length; i++) {
  18301. arr2[i] = str.charCodeAt(i);
  18302. }
  18303. return Optional.some(new Blob([arr2], { type: type2 }));
  18304. };
  18305. var dataUriToBlob = function(uri) {
  18306. return new promiseObj(function(resolve2) {
  18307. var _a = parseDataUri(uri), type2 = _a.type, data2 = _a.data;
  18308. buildBlob(type2, data2).fold(function() {
  18309. return resolve2(new Blob([]));
  18310. }, resolve2);
  18311. });
  18312. };
  18313. var uriToBlob = function(url) {
  18314. if (url.indexOf("blob:") === 0) {
  18315. return blobUriToBlob(url);
  18316. }
  18317. if (url.indexOf("data:") === 0) {
  18318. return dataUriToBlob(url);
  18319. }
  18320. return null;
  18321. };
  18322. var blobToDataUri = function(blob) {
  18323. return new promiseObj(function(resolve2) {
  18324. var reader = new FileReader();
  18325. reader.onloadend = function() {
  18326. resolve2(reader.result);
  18327. };
  18328. reader.readAsDataURL(blob);
  18329. });
  18330. };
  18331. var count$1 = 0;
  18332. var uniqueId = function(prefix) {
  18333. return (prefix || "blobid") + count$1++;
  18334. };
  18335. var imageToBlobInfo = function(blobCache, img, resolve2, reject) {
  18336. var base64, blobInfo;
  18337. if (img.src.indexOf("blob:") === 0) {
  18338. blobInfo = blobCache.getByUri(img.src);
  18339. if (blobInfo) {
  18340. resolve2({
  18341. image: img,
  18342. blobInfo
  18343. });
  18344. } else {
  18345. uriToBlob(img.src).then(function(blob) {
  18346. blobToDataUri(blob).then(function(dataUri) {
  18347. base64 = parseDataUri(dataUri).data;
  18348. blobInfo = blobCache.create(uniqueId(), blob, base64);
  18349. blobCache.add(blobInfo);
  18350. resolve2({
  18351. image: img,
  18352. blobInfo
  18353. });
  18354. });
  18355. }, function(err) {
  18356. reject(err);
  18357. });
  18358. }
  18359. return;
  18360. }
  18361. var _a = parseDataUri(img.src), data2 = _a.data, type2 = _a.type;
  18362. base64 = data2;
  18363. blobInfo = blobCache.getByData(base64, type2);
  18364. if (blobInfo) {
  18365. resolve2({
  18366. image: img,
  18367. blobInfo
  18368. });
  18369. } else {
  18370. uriToBlob(img.src).then(function(blob) {
  18371. blobInfo = blobCache.create(uniqueId(), blob, base64);
  18372. blobCache.add(blobInfo);
  18373. resolve2({
  18374. image: img,
  18375. blobInfo
  18376. });
  18377. }, function(err) {
  18378. reject(err);
  18379. });
  18380. }
  18381. };
  18382. var getAllImages = function(elm) {
  18383. return elm ? from(elm.getElementsByTagName("img")) : [];
  18384. };
  18385. var ImageScanner = function(uploadStatus, blobCache) {
  18386. var cachedPromises = {};
  18387. var findAll2 = function(elm, predicate) {
  18388. if (!predicate) {
  18389. predicate = always;
  18390. }
  18391. var images = filter$4(getAllImages(elm), function(img) {
  18392. var src = img.src;
  18393. if (!Env.fileApi) {
  18394. return false;
  18395. }
  18396. if (img.hasAttribute("data-mce-bogus")) {
  18397. return false;
  18398. }
  18399. if (img.hasAttribute("data-mce-placeholder")) {
  18400. return false;
  18401. }
  18402. if (!src || src === Env.transparentSrc) {
  18403. return false;
  18404. }
  18405. if (src.indexOf("blob:") === 0) {
  18406. return !uploadStatus.isUploaded(src) && predicate(img);
  18407. }
  18408. if (src.indexOf("data:") === 0) {
  18409. return predicate(img);
  18410. }
  18411. return false;
  18412. });
  18413. var promises = map$3(images, function(img) {
  18414. if (cachedPromises[img.src] !== void 0) {
  18415. return new promiseObj(function(resolve2) {
  18416. cachedPromises[img.src].then(function(imageInfo) {
  18417. if (typeof imageInfo === "string") {
  18418. return imageInfo;
  18419. }
  18420. resolve2({
  18421. image: img,
  18422. blobInfo: imageInfo.blobInfo
  18423. });
  18424. });
  18425. });
  18426. }
  18427. var newPromise = new promiseObj(function(resolve2, reject) {
  18428. imageToBlobInfo(blobCache, img, resolve2, reject);
  18429. }).then(function(result) {
  18430. delete cachedPromises[result.image.src];
  18431. return result;
  18432. }).catch(function(error2) {
  18433. delete cachedPromises[img.src];
  18434. return error2;
  18435. });
  18436. cachedPromises[img.src] = newPromise;
  18437. return newPromise;
  18438. });
  18439. return promiseObj.all(promises);
  18440. };
  18441. return { findAll: findAll2 };
  18442. };
  18443. var paddEmptyNode = function(settings, args, blockElements, node) {
  18444. var brPreferred = settings.padd_empty_with_br || args.insert;
  18445. if (brPreferred && blockElements[node.name]) {
  18446. node.empty().append(new AstNode("br", 1)).shortEnded = true;
  18447. } else {
  18448. node.empty().append(new AstNode("#text", 3)).value = nbsp;
  18449. }
  18450. };
  18451. var isPaddedWithNbsp = function(node) {
  18452. return hasOnlyChild(node, "#text") && node.firstChild.value === nbsp;
  18453. };
  18454. var hasOnlyChild = function(node, name2) {
  18455. return node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name2;
  18456. };
  18457. var isPadded = function(schema, node) {
  18458. var rule = schema.getElementRule(node.name);
  18459. return rule && rule.paddEmpty;
  18460. };
  18461. var isEmpty = function(schema, nonEmptyElements, whitespaceElements, node) {
  18462. return node.isEmpty(nonEmptyElements, whitespaceElements, function(node2) {
  18463. return isPadded(schema, node2);
  18464. });
  18465. };
  18466. var isLineBreakNode = function(node, blockElements) {
  18467. return node && (has$2(blockElements, node.name) || node.name === "br");
  18468. };
  18469. var isBogusImage = function(img) {
  18470. return isNonNullable(img.attr("data-mce-bogus"));
  18471. };
  18472. var isInternalImageSource = function(img) {
  18473. return img.attr("src") === Env.transparentSrc || isNonNullable(img.attr("data-mce-placeholder"));
  18474. };
  18475. var isValidDataImg = function(img, settings) {
  18476. if (settings.images_dataimg_filter) {
  18477. var imgElem_1 = new Image();
  18478. imgElem_1.src = img.attr("src");
  18479. each$j(img.attributes.map, function(value2, key) {
  18480. imgElem_1.setAttribute(key, value2);
  18481. });
  18482. return settings.images_dataimg_filter(imgElem_1);
  18483. } else {
  18484. return true;
  18485. }
  18486. };
  18487. var registerBase64ImageFilter = function(parser, settings) {
  18488. var blobCache = settings.blob_cache;
  18489. var processImage = function(img) {
  18490. var inputSrc = img.attr("src");
  18491. if (isInternalImageSource(img) || isBogusImage(img)) {
  18492. return;
  18493. }
  18494. parseDataUri$1(inputSrc).filter(function() {
  18495. return isValidDataImg(img, settings);
  18496. }).bind(function(_a) {
  18497. var type2 = _a.type, data2 = _a.data;
  18498. return Optional.from(blobCache.getByData(data2, type2)).orThunk(function() {
  18499. return buildBlob(type2, data2).map(function(blob) {
  18500. var blobInfo = blobCache.create(uniqueId(), blob, data2);
  18501. blobCache.add(blobInfo);
  18502. return blobInfo;
  18503. });
  18504. });
  18505. }).each(function(blobInfo) {
  18506. img.attr("src", blobInfo.blobUri());
  18507. });
  18508. };
  18509. if (blobCache) {
  18510. parser.addAttributeFilter("src", function(nodes) {
  18511. return each$k(nodes, processImage);
  18512. });
  18513. }
  18514. };
  18515. var register$1 = function(parser, settings) {
  18516. var schema = parser.schema;
  18517. if (settings.remove_trailing_brs) {
  18518. parser.addNodeFilter("br", function(nodes, _, args) {
  18519. var i;
  18520. var l = nodes.length;
  18521. var node;
  18522. var blockElements = Tools.extend({}, schema.getBlockElements());
  18523. var nonEmptyElements = schema.getNonEmptyElements();
  18524. var parent2, lastParent, prev, prevName;
  18525. var whiteSpaceElements = schema.getWhiteSpaceElements();
  18526. var elementRule, textNode;
  18527. blockElements.body = 1;
  18528. for (i = 0; i < l; i++) {
  18529. node = nodes[i];
  18530. parent2 = node.parent;
  18531. if (blockElements[node.parent.name] && node === parent2.lastChild) {
  18532. prev = node.prev;
  18533. while (prev) {
  18534. prevName = prev.name;
  18535. if (prevName !== "span" || prev.attr("data-mce-type") !== "bookmark") {
  18536. if (prevName === "br") {
  18537. node = null;
  18538. }
  18539. break;
  18540. }
  18541. prev = prev.prev;
  18542. }
  18543. if (node) {
  18544. node.remove();
  18545. if (isEmpty(schema, nonEmptyElements, whiteSpaceElements, parent2)) {
  18546. elementRule = schema.getElementRule(parent2.name);
  18547. if (elementRule) {
  18548. if (elementRule.removeEmpty) {
  18549. parent2.remove();
  18550. } else if (elementRule.paddEmpty) {
  18551. paddEmptyNode(settings, args, blockElements, parent2);
  18552. }
  18553. }
  18554. }
  18555. }
  18556. } else {
  18557. lastParent = node;
  18558. while (parent2 && parent2.firstChild === lastParent && parent2.lastChild === lastParent) {
  18559. lastParent = parent2;
  18560. if (blockElements[parent2.name]) {
  18561. break;
  18562. }
  18563. parent2 = parent2.parent;
  18564. }
  18565. if (lastParent === parent2 && settings.padd_empty_with_br !== true) {
  18566. textNode = new AstNode("#text", 3);
  18567. textNode.value = nbsp;
  18568. node.replace(textNode);
  18569. }
  18570. }
  18571. }
  18572. });
  18573. }
  18574. parser.addAttributeFilter("href", function(nodes) {
  18575. var i = nodes.length;
  18576. var appendRel = function(rel) {
  18577. var parts = rel.split(" ").filter(function(p) {
  18578. return p.length > 0;
  18579. });
  18580. return parts.concat(["noopener"]).sort().join(" ");
  18581. };
  18582. var addNoOpener = function(rel) {
  18583. var newRel = rel ? Tools.trim(rel) : "";
  18584. if (!/\b(noopener)\b/g.test(newRel)) {
  18585. return appendRel(newRel);
  18586. } else {
  18587. return newRel;
  18588. }
  18589. };
  18590. if (!settings.allow_unsafe_link_target) {
  18591. while (i--) {
  18592. var node = nodes[i];
  18593. if (node.name === "a" && node.attr("target") === "_blank") {
  18594. node.attr("rel", addNoOpener(node.attr("rel")));
  18595. }
  18596. }
  18597. }
  18598. });
  18599. if (!settings.allow_html_in_named_anchor) {
  18600. parser.addAttributeFilter("id,name", function(nodes) {
  18601. var i = nodes.length, sibling2, prevSibling2, parent2, node;
  18602. while (i--) {
  18603. node = nodes[i];
  18604. if (node.name === "a" && node.firstChild && !node.attr("href")) {
  18605. parent2 = node.parent;
  18606. sibling2 = node.lastChild;
  18607. do {
  18608. prevSibling2 = sibling2.prev;
  18609. parent2.insert(sibling2, node);
  18610. sibling2 = prevSibling2;
  18611. } while (sibling2);
  18612. }
  18613. }
  18614. });
  18615. }
  18616. if (settings.fix_list_elements) {
  18617. parser.addNodeFilter("ul,ol", function(nodes) {
  18618. var i = nodes.length, node, parentNode;
  18619. while (i--) {
  18620. node = nodes[i];
  18621. parentNode = node.parent;
  18622. if (parentNode.name === "ul" || parentNode.name === "ol") {
  18623. if (node.prev && node.prev.name === "li") {
  18624. node.prev.append(node);
  18625. } else {
  18626. var li = new AstNode("li", 1);
  18627. li.attr("style", "list-style-type: none");
  18628. node.wrap(li);
  18629. }
  18630. }
  18631. }
  18632. });
  18633. }
  18634. if (settings.validate && schema.getValidClasses()) {
  18635. parser.addAttributeFilter("class", function(nodes) {
  18636. var validClasses = schema.getValidClasses();
  18637. var i = nodes.length;
  18638. while (i--) {
  18639. var node = nodes[i];
  18640. var classList = node.attr("class").split(" ");
  18641. var classValue = "";
  18642. for (var ci = 0; ci < classList.length; ci++) {
  18643. var className = classList[ci];
  18644. var valid = false;
  18645. var validClassesMap = validClasses["*"];
  18646. if (validClassesMap && validClassesMap[className]) {
  18647. valid = true;
  18648. }
  18649. validClassesMap = validClasses[node.name];
  18650. if (!valid && validClassesMap && validClassesMap[className]) {
  18651. valid = true;
  18652. }
  18653. if (valid) {
  18654. if (classValue) {
  18655. classValue += " ";
  18656. }
  18657. classValue += className;
  18658. }
  18659. }
  18660. if (!classValue.length) {
  18661. classValue = null;
  18662. }
  18663. node.attr("class", classValue);
  18664. }
  18665. });
  18666. }
  18667. registerBase64ImageFilter(parser, settings);
  18668. };
  18669. var makeMap = Tools.makeMap, each$6 = Tools.each, explode$2 = Tools.explode, extend$4 = Tools.extend;
  18670. var DomParser = function(settings, schema) {
  18671. if (schema === void 0) {
  18672. schema = Schema();
  18673. }
  18674. var nodeFilters = {};
  18675. var attributeFilters = [];
  18676. var matchedNodes = {};
  18677. var matchedAttributes = {};
  18678. settings = settings || {};
  18679. settings.validate = "validate" in settings ? settings.validate : true;
  18680. settings.root_name = settings.root_name || "body";
  18681. var fixInvalidChildren = function(nodes) {
  18682. var nonSplitableElements = makeMap("tr,td,th,tbody,thead,tfoot,table");
  18683. var nonEmptyElements = schema.getNonEmptyElements();
  18684. var whitespaceElements = schema.getWhiteSpaceElements();
  18685. var textBlockElements = schema.getTextBlockElements();
  18686. var specialElements = schema.getSpecialElements();
  18687. var removeOrUnwrapInvalidNode = function(node2, originalNodeParent) {
  18688. if (originalNodeParent === void 0) {
  18689. originalNodeParent = node2.parent;
  18690. }
  18691. if (specialElements[node2.name]) {
  18692. node2.empty().remove();
  18693. } else {
  18694. var children2 = node2.children();
  18695. for (var _i = 0, children_1 = children2; _i < children_1.length; _i++) {
  18696. var childNode2 = children_1[_i];
  18697. if (!schema.isValidChild(originalNodeParent.name, childNode2.name)) {
  18698. removeOrUnwrapInvalidNode(childNode2, originalNodeParent);
  18699. }
  18700. }
  18701. node2.unwrap();
  18702. }
  18703. };
  18704. for (var ni = 0; ni < nodes.length; ni++) {
  18705. var node = nodes[ni];
  18706. var parent_1 = void 0, newParent = void 0, tempNode = void 0;
  18707. if (!node.parent || node.fixed) {
  18708. continue;
  18709. }
  18710. if (textBlockElements[node.name] && node.parent.name === "li") {
  18711. var sibling2 = node.next;
  18712. while (sibling2) {
  18713. if (textBlockElements[sibling2.name]) {
  18714. sibling2.name = "li";
  18715. sibling2.fixed = true;
  18716. node.parent.insert(sibling2, node.parent);
  18717. } else {
  18718. break;
  18719. }
  18720. sibling2 = sibling2.next;
  18721. }
  18722. node.unwrap();
  18723. continue;
  18724. }
  18725. var parents2 = [node];
  18726. for (parent_1 = node.parent; parent_1 && !schema.isValidChild(parent_1.name, node.name) && !nonSplitableElements[parent_1.name]; parent_1 = parent_1.parent) {
  18727. parents2.push(parent_1);
  18728. }
  18729. if (parent_1 && parents2.length > 1) {
  18730. if (schema.isValidChild(parent_1.name, node.name)) {
  18731. parents2.reverse();
  18732. newParent = filterNode(parents2[0].clone());
  18733. var currentNode = newParent;
  18734. for (var i = 0; i < parents2.length - 1; i++) {
  18735. if (schema.isValidChild(currentNode.name, parents2[i].name)) {
  18736. tempNode = filterNode(parents2[i].clone());
  18737. currentNode.append(tempNode);
  18738. } else {
  18739. tempNode = currentNode;
  18740. }
  18741. for (var childNode = parents2[i].firstChild; childNode && childNode !== parents2[i + 1]; ) {
  18742. var nextNode = childNode.next;
  18743. tempNode.append(childNode);
  18744. childNode = nextNode;
  18745. }
  18746. currentNode = tempNode;
  18747. }
  18748. if (!isEmpty(schema, nonEmptyElements, whitespaceElements, newParent)) {
  18749. parent_1.insert(newParent, parents2[0], true);
  18750. parent_1.insert(node, newParent);
  18751. } else {
  18752. parent_1.insert(node, parents2[0], true);
  18753. }
  18754. parent_1 = parents2[0];
  18755. if (isEmpty(schema, nonEmptyElements, whitespaceElements, parent_1) || hasOnlyChild(parent_1, "br")) {
  18756. parent_1.empty().remove();
  18757. }
  18758. } else {
  18759. removeOrUnwrapInvalidNode(node);
  18760. }
  18761. } else if (node.parent) {
  18762. if (node.name === "li") {
  18763. var sibling2 = node.prev;
  18764. if (sibling2 && (sibling2.name === "ul" || sibling2.name === "ol")) {
  18765. sibling2.append(node);
  18766. continue;
  18767. }
  18768. sibling2 = node.next;
  18769. if (sibling2 && (sibling2.name === "ul" || sibling2.name === "ol")) {
  18770. sibling2.insert(node, sibling2.firstChild, true);
  18771. continue;
  18772. }
  18773. node.wrap(filterNode(new AstNode("ul", 1)));
  18774. continue;
  18775. }
  18776. if (schema.isValidChild(node.parent.name, "div") && schema.isValidChild("div", node.name)) {
  18777. node.wrap(filterNode(new AstNode("div", 1)));
  18778. } else {
  18779. removeOrUnwrapInvalidNode(node);
  18780. }
  18781. }
  18782. }
  18783. };
  18784. var filterNode = function(node) {
  18785. var name2 = node.name;
  18786. if (name2 in nodeFilters) {
  18787. var list = matchedNodes[name2];
  18788. if (list) {
  18789. list.push(node);
  18790. } else {
  18791. matchedNodes[name2] = [node];
  18792. }
  18793. }
  18794. var i = attributeFilters.length;
  18795. while (i--) {
  18796. var attrName = attributeFilters[i].name;
  18797. if (attrName in node.attributes.map) {
  18798. var list = matchedAttributes[attrName];
  18799. if (list) {
  18800. list.push(node);
  18801. } else {
  18802. matchedAttributes[attrName] = [node];
  18803. }
  18804. }
  18805. }
  18806. return node;
  18807. };
  18808. var addNodeFilter = function(name2, callback) {
  18809. each$6(explode$2(name2), function(name3) {
  18810. var list = nodeFilters[name3];
  18811. if (!list) {
  18812. nodeFilters[name3] = list = [];
  18813. }
  18814. list.push(callback);
  18815. });
  18816. };
  18817. var getNodeFilters = function() {
  18818. var out = [];
  18819. for (var name_1 in nodeFilters) {
  18820. if (has$2(nodeFilters, name_1)) {
  18821. out.push({
  18822. name: name_1,
  18823. callbacks: nodeFilters[name_1]
  18824. });
  18825. }
  18826. }
  18827. return out;
  18828. };
  18829. var addAttributeFilter = function(name2, callback) {
  18830. each$6(explode$2(name2), function(name3) {
  18831. var i;
  18832. for (i = 0; i < attributeFilters.length; i++) {
  18833. if (attributeFilters[i].name === name3) {
  18834. attributeFilters[i].callbacks.push(callback);
  18835. return;
  18836. }
  18837. }
  18838. attributeFilters.push({
  18839. name: name3,
  18840. callbacks: [callback]
  18841. });
  18842. });
  18843. };
  18844. var getAttributeFilters = function() {
  18845. return [].concat(attributeFilters);
  18846. };
  18847. var parse = function(html, args) {
  18848. var nodes, i, l, fi, fl, list, name2;
  18849. var invalidChildren = [];
  18850. var node;
  18851. var getRootBlockName = function(name3) {
  18852. if (name3 === false) {
  18853. return "";
  18854. } else if (name3 === true) {
  18855. return "p";
  18856. } else {
  18857. return name3;
  18858. }
  18859. };
  18860. args = args || {};
  18861. matchedNodes = {};
  18862. matchedAttributes = {};
  18863. var blockElements = extend$4(makeMap("script,style,head,html,body,title,meta,param"), schema.getBlockElements());
  18864. var textRootBlockElements = getTextRootBlockElements(schema);
  18865. var nonEmptyElements = schema.getNonEmptyElements();
  18866. var children2 = schema.children;
  18867. var validate2 = settings.validate;
  18868. var forcedRootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  18869. var rootBlockName = getRootBlockName(forcedRootBlockName);
  18870. var whiteSpaceElements = schema.getWhiteSpaceElements();
  18871. var startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  18872. var endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  18873. var allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  18874. var isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  18875. var isInWhiteSpacePreservedElement = has$2(whiteSpaceElements, args.context) || has$2(whiteSpaceElements, settings.root_name);
  18876. var addRootBlocks2 = function() {
  18877. var node2 = rootNode.firstChild, rootBlockNode = null;
  18878. var trim2 = function(rootBlock) {
  18879. if (rootBlock) {
  18880. node2 = rootBlock.firstChild;
  18881. if (node2 && node2.type === 3) {
  18882. node2.value = node2.value.replace(startWhiteSpaceRegExp, "");
  18883. }
  18884. node2 = rootBlock.lastChild;
  18885. if (node2 && node2.type === 3) {
  18886. node2.value = node2.value.replace(endWhiteSpaceRegExp, "");
  18887. }
  18888. }
  18889. };
  18890. if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
  18891. return;
  18892. }
  18893. while (node2) {
  18894. var next = node2.next;
  18895. if (node2.type === 3 || node2.type === 1 && node2.name !== "p" && !blockElements[node2.name] && !node2.attr("data-mce-type")) {
  18896. if (!rootBlockNode) {
  18897. rootBlockNode = createNode(rootBlockName, 1);
  18898. rootBlockNode.attr(settings.forced_root_block_attrs);
  18899. rootNode.insert(rootBlockNode, node2);
  18900. rootBlockNode.append(node2);
  18901. } else {
  18902. rootBlockNode.append(node2);
  18903. }
  18904. } else {
  18905. trim2(rootBlockNode);
  18906. rootBlockNode = null;
  18907. }
  18908. node2 = next;
  18909. }
  18910. trim2(rootBlockNode);
  18911. };
  18912. var createNode = function(name3, type2) {
  18913. var node2 = new AstNode(name3, type2);
  18914. var list2;
  18915. if (name3 in nodeFilters) {
  18916. list2 = matchedNodes[name3];
  18917. if (list2) {
  18918. list2.push(node2);
  18919. } else {
  18920. matchedNodes[name3] = [node2];
  18921. }
  18922. }
  18923. return node2;
  18924. };
  18925. var removeWhitespaceBefore = function(node2) {
  18926. var blockElements2 = schema.getBlockElements();
  18927. for (var textNode = node2.prev; textNode && textNode.type === 3; ) {
  18928. var textVal = textNode.value.replace(endWhiteSpaceRegExp, "");
  18929. if (textVal.length > 0) {
  18930. textNode.value = textVal;
  18931. return;
  18932. }
  18933. var textNodeNext = textNode.next;
  18934. if (textNodeNext) {
  18935. if (textNodeNext.type === 3 && textNodeNext.value.length) {
  18936. textNode = textNode.prev;
  18937. continue;
  18938. }
  18939. if (!blockElements2[textNodeNext.name] && textNodeNext.name !== "script" && textNodeNext.name !== "style") {
  18940. textNode = textNode.prev;
  18941. continue;
  18942. }
  18943. }
  18944. var sibling2 = textNode.prev;
  18945. textNode.remove();
  18946. textNode = sibling2;
  18947. }
  18948. };
  18949. var cloneAndExcludeBlocks = function(input) {
  18950. var output = {};
  18951. for (var name_2 in input) {
  18952. if (name_2 !== "li" && name_2 !== "p") {
  18953. output[name_2] = input[name_2];
  18954. }
  18955. }
  18956. return output;
  18957. };
  18958. var isTextRootBlockEmpty = function(node2) {
  18959. var tempNode = node2;
  18960. while (isNonNullable(tempNode)) {
  18961. if (tempNode.name in textRootBlockElements) {
  18962. return isEmpty(schema, nonEmptyElements, whiteSpaceElements, tempNode);
  18963. } else {
  18964. tempNode = tempNode.parent;
  18965. }
  18966. }
  18967. return false;
  18968. };
  18969. var parser = SaxParser({
  18970. validate: validate2,
  18971. document: settings.document,
  18972. allow_html_data_urls: settings.allow_html_data_urls,
  18973. allow_svg_data_urls: settings.allow_svg_data_urls,
  18974. allow_script_urls: settings.allow_script_urls,
  18975. allow_conditional_comments: settings.allow_conditional_comments,
  18976. preserve_cdata: settings.preserve_cdata,
  18977. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  18978. cdata: function(text) {
  18979. node.append(createNode("#cdata", 4)).value = text;
  18980. },
  18981. text: function(text, raw) {
  18982. var textNode;
  18983. if (!isInWhiteSpacePreservedElement) {
  18984. text = text.replace(allWhiteSpaceRegExp, " ");
  18985. if (isLineBreakNode(node.lastChild, blockElements)) {
  18986. text = text.replace(startWhiteSpaceRegExp, "");
  18987. }
  18988. }
  18989. if (text.length !== 0) {
  18990. textNode = createNode("#text", 3);
  18991. textNode.raw = !!raw;
  18992. node.append(textNode).value = text;
  18993. }
  18994. },
  18995. comment: function(text) {
  18996. node.append(createNode("#comment", 8)).value = text;
  18997. },
  18998. pi: function(name3, text) {
  18999. node.append(createNode(name3, 7)).value = text;
  19000. removeWhitespaceBefore(node);
  19001. },
  19002. doctype: function(text) {
  19003. var newNode = node.append(createNode("#doctype", 10));
  19004. newNode.value = text;
  19005. removeWhitespaceBefore(node);
  19006. },
  19007. start: function(name3, attrs, empty2) {
  19008. var elementRule = validate2 ? schema.getElementRule(name3) : {};
  19009. if (elementRule) {
  19010. var newNode = createNode(elementRule.outputName || name3, 1);
  19011. newNode.attributes = attrs;
  19012. newNode.shortEnded = empty2;
  19013. node.append(newNode);
  19014. var parent_2 = children2[node.name];
  19015. if (parent_2 && children2[newNode.name] && !parent_2[newNode.name]) {
  19016. invalidChildren.push(newNode);
  19017. }
  19018. var attrFiltersLen = attributeFilters.length;
  19019. while (attrFiltersLen--) {
  19020. var attrName = attributeFilters[attrFiltersLen].name;
  19021. if (attrName in attrs.map) {
  19022. list = matchedAttributes[attrName];
  19023. if (list) {
  19024. list.push(newNode);
  19025. } else {
  19026. matchedAttributes[attrName] = [newNode];
  19027. }
  19028. }
  19029. }
  19030. if (blockElements[name3]) {
  19031. removeWhitespaceBefore(newNode);
  19032. }
  19033. if (!empty2) {
  19034. node = newNode;
  19035. }
  19036. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name3]) {
  19037. isInWhiteSpacePreservedElement = true;
  19038. }
  19039. }
  19040. },
  19041. end: function(name3) {
  19042. var textNode, text, sibling2;
  19043. var elementRule = validate2 ? schema.getElementRule(name3) : {};
  19044. if (elementRule) {
  19045. if (blockElements[name3]) {
  19046. if (!isInWhiteSpacePreservedElement) {
  19047. textNode = node.firstChild;
  19048. if (textNode && textNode.type === 3) {
  19049. text = textNode.value.replace(startWhiteSpaceRegExp, "");
  19050. if (text.length > 0) {
  19051. textNode.value = text;
  19052. textNode = textNode.next;
  19053. } else {
  19054. sibling2 = textNode.next;
  19055. textNode.remove();
  19056. textNode = sibling2;
  19057. while (textNode && textNode.type === 3) {
  19058. text = textNode.value;
  19059. sibling2 = textNode.next;
  19060. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  19061. textNode.remove();
  19062. textNode = sibling2;
  19063. }
  19064. textNode = sibling2;
  19065. }
  19066. }
  19067. }
  19068. textNode = node.lastChild;
  19069. if (textNode && textNode.type === 3) {
  19070. text = textNode.value.replace(endWhiteSpaceRegExp, "");
  19071. if (text.length > 0) {
  19072. textNode.value = text;
  19073. textNode = textNode.prev;
  19074. } else {
  19075. sibling2 = textNode.prev;
  19076. textNode.remove();
  19077. textNode = sibling2;
  19078. while (textNode && textNode.type === 3) {
  19079. text = textNode.value;
  19080. sibling2 = textNode.prev;
  19081. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  19082. textNode.remove();
  19083. textNode = sibling2;
  19084. }
  19085. textNode = sibling2;
  19086. }
  19087. }
  19088. }
  19089. }
  19090. }
  19091. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name3]) {
  19092. isInWhiteSpacePreservedElement = false;
  19093. }
  19094. var isNodeEmpty = isEmpty(schema, nonEmptyElements, whiteSpaceElements, node);
  19095. var parentNode = node.parent;
  19096. if (elementRule.paddInEmptyBlock && isNodeEmpty && isTextRootBlockEmpty(node)) {
  19097. paddEmptyNode(settings, args, blockElements, node);
  19098. } else if (elementRule.removeEmpty && isNodeEmpty) {
  19099. if (blockElements[node.name]) {
  19100. node.empty().remove();
  19101. } else {
  19102. node.unwrap();
  19103. }
  19104. } else if (elementRule.paddEmpty && (isPaddedWithNbsp(node) || isNodeEmpty)) {
  19105. paddEmptyNode(settings, args, blockElements, node);
  19106. }
  19107. node = parentNode;
  19108. }
  19109. }
  19110. }, schema);
  19111. var rootNode = node = new AstNode(args.context || settings.root_name, 11);
  19112. parser.parse(html, args.format);
  19113. if (validate2 && invalidChildren.length) {
  19114. if (!args.context) {
  19115. fixInvalidChildren(invalidChildren);
  19116. } else {
  19117. args.invalid = true;
  19118. }
  19119. }
  19120. if (rootBlockName && (rootNode.name === "body" || args.isRootContent)) {
  19121. addRootBlocks2();
  19122. }
  19123. if (!args.invalid) {
  19124. for (name2 in matchedNodes) {
  19125. if (!has$2(matchedNodes, name2)) {
  19126. continue;
  19127. }
  19128. list = nodeFilters[name2];
  19129. nodes = matchedNodes[name2];
  19130. fi = nodes.length;
  19131. while (fi--) {
  19132. if (!nodes[fi].parent) {
  19133. nodes.splice(fi, 1);
  19134. }
  19135. }
  19136. for (i = 0, l = list.length; i < l; i++) {
  19137. list[i](nodes, name2, args);
  19138. }
  19139. }
  19140. for (i = 0, l = attributeFilters.length; i < l; i++) {
  19141. list = attributeFilters[i];
  19142. if (list.name in matchedAttributes) {
  19143. nodes = matchedAttributes[list.name];
  19144. fi = nodes.length;
  19145. while (fi--) {
  19146. if (!nodes[fi].parent) {
  19147. nodes.splice(fi, 1);
  19148. }
  19149. }
  19150. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) {
  19151. list.callbacks[fi](nodes, list.name, args);
  19152. }
  19153. }
  19154. }
  19155. }
  19156. return rootNode;
  19157. };
  19158. var exports2 = {
  19159. schema,
  19160. addAttributeFilter,
  19161. getAttributeFilters,
  19162. addNodeFilter,
  19163. getNodeFilters,
  19164. filterNode,
  19165. parse
  19166. };
  19167. register$1(exports2, settings);
  19168. register$2(exports2, settings);
  19169. return exports2;
  19170. };
  19171. var register = function(htmlParser, settings, dom2) {
  19172. htmlParser.addAttributeFilter("data-mce-tabindex", function(nodes, name2) {
  19173. var i = nodes.length;
  19174. while (i--) {
  19175. var node = nodes[i];
  19176. node.attr("tabindex", node.attr("data-mce-tabindex"));
  19177. node.attr(name2, null);
  19178. }
  19179. });
  19180. htmlParser.addAttributeFilter("src,href,style", function(nodes, name2) {
  19181. var internalName = "data-mce-" + name2;
  19182. var urlConverter = settings.url_converter;
  19183. var urlConverterScope = settings.url_converter_scope;
  19184. var i = nodes.length;
  19185. while (i--) {
  19186. var node = nodes[i];
  19187. var value2 = node.attr(internalName);
  19188. if (value2 !== void 0) {
  19189. node.attr(name2, value2.length > 0 ? value2 : null);
  19190. node.attr(internalName, null);
  19191. } else {
  19192. value2 = node.attr(name2);
  19193. if (name2 === "style") {
  19194. value2 = dom2.serializeStyle(dom2.parseStyle(value2), node.name);
  19195. } else if (urlConverter) {
  19196. value2 = urlConverter.call(urlConverterScope, value2, name2, node.name);
  19197. }
  19198. node.attr(name2, value2.length > 0 ? value2 : null);
  19199. }
  19200. }
  19201. });
  19202. htmlParser.addAttributeFilter("class", function(nodes) {
  19203. var i = nodes.length;
  19204. while (i--) {
  19205. var node = nodes[i];
  19206. var value2 = node.attr("class");
  19207. if (value2) {
  19208. value2 = node.attr("class").replace(/(?:^|\s)mce-item-\w+(?!\S)/g, "");
  19209. node.attr("class", value2.length > 0 ? value2 : null);
  19210. }
  19211. }
  19212. });
  19213. htmlParser.addAttributeFilter("data-mce-type", function(nodes, name2, args) {
  19214. var i = nodes.length;
  19215. while (i--) {
  19216. var node = nodes[i];
  19217. if (node.attr("data-mce-type") === "bookmark" && !args.cleanup) {
  19218. var hasChildren = Optional.from(node.firstChild).exists(function(firstChild2) {
  19219. return !isZwsp(firstChild2.value);
  19220. });
  19221. if (hasChildren) {
  19222. node.unwrap();
  19223. } else {
  19224. node.remove();
  19225. }
  19226. }
  19227. }
  19228. });
  19229. htmlParser.addNodeFilter("noscript", function(nodes) {
  19230. var i = nodes.length;
  19231. while (i--) {
  19232. var node = nodes[i].firstChild;
  19233. if (node) {
  19234. node.value = Entities.decode(node.value);
  19235. }
  19236. }
  19237. });
  19238. htmlParser.addNodeFilter("script,style", function(nodes, name2) {
  19239. var trim2 = function(value3) {
  19240. return value3.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, "");
  19241. };
  19242. var i = nodes.length;
  19243. while (i--) {
  19244. var node = nodes[i];
  19245. var value2 = node.firstChild ? node.firstChild.value : "";
  19246. if (name2 === "script") {
  19247. var type2 = node.attr("type");
  19248. if (type2) {
  19249. node.attr("type", type2 === "mce-no/type" ? null : type2.replace(/^mce\-/, ""));
  19250. }
  19251. if (settings.element_format === "xhtml" && value2.length > 0) {
  19252. node.firstChild.value = "// <![CDATA[\n" + trim2(value2) + "\n// ]]>";
  19253. }
  19254. } else {
  19255. if (settings.element_format === "xhtml" && value2.length > 0) {
  19256. node.firstChild.value = "<!--\n" + trim2(value2) + "\n-->";
  19257. }
  19258. }
  19259. }
  19260. });
  19261. htmlParser.addNodeFilter("#comment", function(nodes) {
  19262. var i = nodes.length;
  19263. while (i--) {
  19264. var node = nodes[i];
  19265. if (settings.preserve_cdata && node.value.indexOf("[CDATA[") === 0) {
  19266. node.name = "#cdata";
  19267. node.type = 4;
  19268. node.value = dom2.decode(node.value.replace(/^\[CDATA\[|\]\]$/g, ""));
  19269. } else if (node.value.indexOf("mce:protected ") === 0) {
  19270. node.name = "#text";
  19271. node.type = 3;
  19272. node.raw = true;
  19273. node.value = unescape(node.value).substr(14);
  19274. }
  19275. }
  19276. });
  19277. htmlParser.addNodeFilter("xml:namespace,input", function(nodes, name2) {
  19278. var i = nodes.length;
  19279. while (i--) {
  19280. var node = nodes[i];
  19281. if (node.type === 7) {
  19282. node.remove();
  19283. } else if (node.type === 1) {
  19284. if (name2 === "input" && !node.attr("type")) {
  19285. node.attr("type", "text");
  19286. }
  19287. }
  19288. }
  19289. });
  19290. htmlParser.addAttributeFilter("data-mce-type", function(nodes) {
  19291. each$k(nodes, function(node) {
  19292. if (node.attr("data-mce-type") === "format-caret") {
  19293. if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) {
  19294. node.remove();
  19295. } else {
  19296. node.unwrap();
  19297. }
  19298. }
  19299. });
  19300. });
  19301. htmlParser.addAttributeFilter("data-mce-src,data-mce-href,data-mce-style,data-mce-selected,data-mce-expando,data-mce-type,data-mce-resize,data-mce-placeholder", function(nodes, name2) {
  19302. var i = nodes.length;
  19303. while (i--) {
  19304. nodes[i].attr(name2, null);
  19305. }
  19306. });
  19307. };
  19308. var trimTrailingBr = function(rootNode) {
  19309. var isBr2 = function(node) {
  19310. return node && node.name === "br";
  19311. };
  19312. var brNode1 = rootNode.lastChild;
  19313. if (isBr2(brNode1)) {
  19314. var brNode2 = brNode1.prev;
  19315. if (isBr2(brNode2)) {
  19316. brNode1.remove();
  19317. brNode2.remove();
  19318. }
  19319. }
  19320. };
  19321. var preProcess = function(editor, node, args) {
  19322. var oldDoc;
  19323. var dom2 = editor.dom;
  19324. var clonedNode = node.cloneNode(true);
  19325. var impl = document.implementation;
  19326. if (impl.createHTMLDocument) {
  19327. var doc_1 = impl.createHTMLDocument("");
  19328. Tools.each(clonedNode.nodeName === "BODY" ? clonedNode.childNodes : [clonedNode], function(node2) {
  19329. doc_1.body.appendChild(doc_1.importNode(node2, true));
  19330. });
  19331. if (clonedNode.nodeName !== "BODY") {
  19332. clonedNode = doc_1.body.firstChild;
  19333. } else {
  19334. clonedNode = doc_1.body;
  19335. }
  19336. oldDoc = dom2.doc;
  19337. dom2.doc = doc_1;
  19338. }
  19339. firePreProcess(editor, __assign(__assign({}, args), { node: clonedNode }));
  19340. if (oldDoc) {
  19341. dom2.doc = oldDoc;
  19342. }
  19343. return clonedNode;
  19344. };
  19345. var shouldFireEvent = function(editor, args) {
  19346. return editor && editor.hasEventListeners("PreProcess") && !args.no_events;
  19347. };
  19348. var process = function(editor, node, args) {
  19349. return shouldFireEvent(editor, args) ? preProcess(editor, node, args) : node;
  19350. };
  19351. var addTempAttr = function(htmlParser, tempAttrs, name2) {
  19352. if (Tools.inArray(tempAttrs, name2) === -1) {
  19353. htmlParser.addAttributeFilter(name2, function(nodes, name3) {
  19354. var i = nodes.length;
  19355. while (i--) {
  19356. nodes[i].attr(name3, null);
  19357. }
  19358. });
  19359. tempAttrs.push(name2);
  19360. }
  19361. };
  19362. var postProcess = function(editor, args, content) {
  19363. if (!args.no_events && editor) {
  19364. var outArgs = firePostProcess(editor, __assign(__assign({}, args), { content }));
  19365. return outArgs.content;
  19366. } else {
  19367. return content;
  19368. }
  19369. };
  19370. var getHtmlFromNode = function(dom2, node, args) {
  19371. var html = trim$2(args.getInner ? node.innerHTML : dom2.getOuterHTML(node));
  19372. return args.selection || isWsPreserveElement(SugarElement.fromDom(node)) ? html : Tools.trim(html);
  19373. };
  19374. var parseHtml = function(htmlParser, html, args) {
  19375. var parserArgs = args.selection ? __assign({ forced_root_block: false }, args) : args;
  19376. var rootNode = htmlParser.parse(html, parserArgs);
  19377. trimTrailingBr(rootNode);
  19378. return rootNode;
  19379. };
  19380. var serializeNode = function(settings, schema, node) {
  19381. var htmlSerializer = HtmlSerializer(settings, schema);
  19382. return htmlSerializer.serialize(node);
  19383. };
  19384. var toHtml = function(editor, settings, schema, rootNode, args) {
  19385. var content = serializeNode(settings, schema, rootNode);
  19386. return postProcess(editor, args, content);
  19387. };
  19388. var DomSerializerImpl = function(settings, editor) {
  19389. var tempAttrs = ["data-mce-selected"];
  19390. var dom2 = editor && editor.dom ? editor.dom : DOMUtils.DOM;
  19391. var schema = editor && editor.schema ? editor.schema : Schema(settings);
  19392. settings.entity_encoding = settings.entity_encoding || "named";
  19393. settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
  19394. var htmlParser = DomParser(settings, schema);
  19395. register(htmlParser, settings, dom2);
  19396. var serialize2 = function(node, parserArgs) {
  19397. if (parserArgs === void 0) {
  19398. parserArgs = {};
  19399. }
  19400. var args = __assign({ format: "html" }, parserArgs);
  19401. var targetNode = process(editor, node, args);
  19402. var html = getHtmlFromNode(dom2, targetNode, args);
  19403. var rootNode = parseHtml(htmlParser, html, args);
  19404. return args.format === "tree" ? rootNode : toHtml(editor, settings, schema, rootNode, args);
  19405. };
  19406. return {
  19407. schema,
  19408. addNodeFilter: htmlParser.addNodeFilter,
  19409. addAttributeFilter: htmlParser.addAttributeFilter,
  19410. serialize: serialize2,
  19411. addRules: schema.addValidElements,
  19412. setRules: schema.setValidElements,
  19413. addTempAttr: curry(addTempAttr, htmlParser, tempAttrs),
  19414. getTempAttrs: constant(tempAttrs),
  19415. getNodeFilters: htmlParser.getNodeFilters,
  19416. getAttributeFilters: htmlParser.getAttributeFilters
  19417. };
  19418. };
  19419. var DomSerializer = function(settings, editor) {
  19420. var domSerializer = DomSerializerImpl(settings, editor);
  19421. return {
  19422. schema: domSerializer.schema,
  19423. addNodeFilter: domSerializer.addNodeFilter,
  19424. addAttributeFilter: domSerializer.addAttributeFilter,
  19425. serialize: domSerializer.serialize,
  19426. addRules: domSerializer.addRules,
  19427. setRules: domSerializer.setRules,
  19428. addTempAttr: domSerializer.addTempAttr,
  19429. getTempAttrs: domSerializer.getTempAttrs,
  19430. getNodeFilters: domSerializer.getNodeFilters,
  19431. getAttributeFilters: domSerializer.getAttributeFilters
  19432. };
  19433. };
  19434. var defaultFormat = "html";
  19435. var getContent = function(editor, args) {
  19436. if (args === void 0) {
  19437. args = {};
  19438. }
  19439. var format = args.format ? args.format : defaultFormat;
  19440. return getContent$2(editor, args, format);
  19441. };
  19442. var setContent = function(editor, content, args) {
  19443. if (args === void 0) {
  19444. args = {};
  19445. }
  19446. return setContent$2(editor, content, args);
  19447. };
  19448. var DOM$7 = DOMUtils.DOM;
  19449. var restoreOriginalStyles = function(editor) {
  19450. DOM$7.setStyle(editor.id, "display", editor.orgDisplay);
  19451. };
  19452. var safeDestroy = function(x) {
  19453. return Optional.from(x).each(function(x2) {
  19454. return x2.destroy();
  19455. });
  19456. };
  19457. var clearDomReferences = function(editor) {
  19458. editor.contentAreaContainer = editor.formElement = editor.container = editor.editorContainer = null;
  19459. editor.bodyElement = editor.contentDocument = editor.contentWindow = null;
  19460. editor.iframeElement = editor.targetElm = null;
  19461. if (editor.selection) {
  19462. editor.selection = editor.selection.win = editor.selection.dom = editor.selection.dom.doc = null;
  19463. }
  19464. };
  19465. var restoreForm = function(editor) {
  19466. var form = editor.formElement;
  19467. if (form) {
  19468. if (form._mceOldSubmit) {
  19469. form.submit = form._mceOldSubmit;
  19470. form._mceOldSubmit = null;
  19471. }
  19472. DOM$7.unbind(form, "submit reset", editor.formEventDelegate);
  19473. }
  19474. };
  19475. var remove = function(editor) {
  19476. if (!editor.removed) {
  19477. var _selectionOverrides = editor._selectionOverrides, editorUpload = editor.editorUpload;
  19478. var body = editor.getBody();
  19479. var element = editor.getElement();
  19480. if (body) {
  19481. editor.save({ is_removing: true });
  19482. }
  19483. editor.removed = true;
  19484. editor.unbindAllNativeEvents();
  19485. if (editor.hasHiddenInput && element) {
  19486. DOM$7.remove(element.nextSibling);
  19487. }
  19488. fireRemove(editor);
  19489. editor.editorManager.remove(editor);
  19490. if (!editor.inline && body) {
  19491. restoreOriginalStyles(editor);
  19492. }
  19493. fireDetach(editor);
  19494. DOM$7.remove(editor.getContainer());
  19495. safeDestroy(_selectionOverrides);
  19496. safeDestroy(editorUpload);
  19497. editor.destroy();
  19498. }
  19499. };
  19500. var destroy = function(editor, automatic) {
  19501. var selection = editor.selection, dom2 = editor.dom;
  19502. if (editor.destroyed) {
  19503. return;
  19504. }
  19505. if (!automatic && !editor.removed) {
  19506. editor.remove();
  19507. return;
  19508. }
  19509. if (!automatic) {
  19510. editor.editorManager.off("beforeunload", editor._beforeUnload);
  19511. if (editor.theme && editor.theme.destroy) {
  19512. editor.theme.destroy();
  19513. }
  19514. safeDestroy(selection);
  19515. safeDestroy(dom2);
  19516. }
  19517. restoreForm(editor);
  19518. clearDomReferences(editor);
  19519. editor.destroyed = true;
  19520. };
  19521. var deep = function(old, nu2) {
  19522. var bothObjects = isObject(old) && isObject(nu2);
  19523. return bothObjects ? deepMerge(old, nu2) : nu2;
  19524. };
  19525. var baseMerge = function(merger) {
  19526. return function() {
  19527. var objects = [];
  19528. for (var _i = 0; _i < arguments.length; _i++) {
  19529. objects[_i] = arguments[_i];
  19530. }
  19531. if (objects.length === 0) {
  19532. throw new Error("Can't merge zero objects");
  19533. }
  19534. var ret = {};
  19535. for (var j = 0; j < objects.length; j++) {
  19536. var curObject = objects[j];
  19537. for (var key in curObject) {
  19538. if (has$2(curObject, key)) {
  19539. ret[key] = merger(ret[key], curObject[key]);
  19540. }
  19541. }
  19542. }
  19543. return ret;
  19544. };
  19545. };
  19546. var deepMerge = baseMerge(deep);
  19547. var deprecatedSettings = "autoresize_on_init,content_editable_state,convert_fonts_to_spans,inline_styles,padd_empty_with_br,block_elements,boolean_attributes,editor_deselector,editor_selector,elements,file_browser_callback_types,filepicker_validator_handler,force_hex_style_colors,force_p_newlines,gecko_spellcheck,images_dataimg_filter,media_scripts,mode,move_caret_before_on_enter_elements,non_empty_elements,self_closing_elements,short_ended_elements,special,spellchecker_select_languages,spellchecker_whitelist,tab_focus,table_responsive_width,text_block_elements,text_inline_elements,toolbar_drawer,types,validate,whitespace_elements,paste_word_valid_elements,paste_retain_style_properties,paste_convert_word_fake_lists".split(",");
  19548. var deprecatedPlugins = "bbcode,colorpicker,contextmenu,fullpage,legacyoutput,spellchecker,textcolor".split(",");
  19549. var movedToPremiumPlugins = "imagetools,toc".split(",");
  19550. var getDeprecatedSettings = function(settings) {
  19551. var settingNames = filter$4(deprecatedSettings, function(setting) {
  19552. return has$2(settings, setting);
  19553. });
  19554. var forcedRootBlock = settings.forced_root_block;
  19555. if (forcedRootBlock === false || forcedRootBlock === "") {
  19556. settingNames.push("forced_root_block (false only)");
  19557. }
  19558. return sort(settingNames);
  19559. };
  19560. var getDeprecatedPlugins = function(settings) {
  19561. var plugins = Tools.makeMap(settings.plugins, " ");
  19562. var hasPlugin = function(plugin) {
  19563. return has$2(plugins, plugin);
  19564. };
  19565. var pluginNames = __spreadArray(__spreadArray([], filter$4(deprecatedPlugins, hasPlugin), true), bind(movedToPremiumPlugins, function(plugin) {
  19566. return hasPlugin(plugin) ? [plugin + " (moving to premium)"] : [];
  19567. }), true);
  19568. return sort(pluginNames);
  19569. };
  19570. var logDeprecationsWarning = function(rawSettings, finalSettings) {
  19571. var deprecatedSettings2 = getDeprecatedSettings(rawSettings);
  19572. var deprecatedPlugins2 = getDeprecatedPlugins(finalSettings);
  19573. var hasDeprecatedPlugins = deprecatedPlugins2.length > 0;
  19574. var hasDeprecatedSettings = deprecatedSettings2.length > 0;
  19575. var isLegacyMobileTheme = finalSettings.theme === "mobile";
  19576. if (hasDeprecatedPlugins || hasDeprecatedSettings || isLegacyMobileTheme) {
  19577. var listJoiner = "\n- ";
  19578. var themesMessage = isLegacyMobileTheme ? "\n\nThemes:" + listJoiner + "mobile" : "";
  19579. var pluginsMessage = hasDeprecatedPlugins ? "\n\nPlugins:" + listJoiner + deprecatedPlugins2.join(listJoiner) : "";
  19580. var settingsMessage = hasDeprecatedSettings ? "\n\nSettings:" + listJoiner + deprecatedSettings2.join(listJoiner) : "";
  19581. console.warn("The following deprecated features are currently enabled, these will be removed in TinyMCE 6.0. See https://www.tiny.cloud/docs/release-notes/6.0-upcoming-changes/ for more information." + themesMessage + pluginsMessage + settingsMessage);
  19582. }
  19583. };
  19584. var sectionResult = function(sections, settings) {
  19585. return {
  19586. sections: constant(sections),
  19587. settings: constant(settings)
  19588. };
  19589. };
  19590. var deviceDetection = detect().deviceType;
  19591. var isTouch = deviceDetection.isTouch();
  19592. var isPhone = deviceDetection.isPhone();
  19593. var isTablet = deviceDetection.isTablet();
  19594. var legacyMobilePlugins = [
  19595. "lists",
  19596. "autolink",
  19597. "autosave"
  19598. ];
  19599. var defaultTouchSettings = {
  19600. table_grid: false,
  19601. object_resizing: false,
  19602. resize: false
  19603. };
  19604. var normalizePlugins = function(plugins) {
  19605. var pluginNames = isArray$1(plugins) ? plugins.join(" ") : plugins;
  19606. var trimmedPlugins = map$3(isString$1(pluginNames) ? pluginNames.split(" ") : [], trim$4);
  19607. return filter$4(trimmedPlugins, function(item) {
  19608. return item.length > 0;
  19609. });
  19610. };
  19611. var filterLegacyMobilePlugins = function(plugins) {
  19612. return filter$4(plugins, curry(contains$3, legacyMobilePlugins));
  19613. };
  19614. var extractSections = function(keys2, settings) {
  19615. var result = bifilter(settings, function(value2, key) {
  19616. return contains$3(keys2, key);
  19617. });
  19618. return sectionResult(result.t, result.f);
  19619. };
  19620. var getSection = function(sectionResult2, name2, defaults) {
  19621. if (defaults === void 0) {
  19622. defaults = {};
  19623. }
  19624. var sections = sectionResult2.sections();
  19625. var sectionSettings = get$9(sections, name2).getOr({});
  19626. return Tools.extend({}, defaults, sectionSettings);
  19627. };
  19628. var hasSection = function(sectionResult2, name2) {
  19629. return has$2(sectionResult2.sections(), name2);
  19630. };
  19631. var isSectionTheme = function(sectionResult2, name2, theme) {
  19632. var section = sectionResult2.sections();
  19633. return hasSection(sectionResult2, name2) && section[name2].theme === theme;
  19634. };
  19635. var getSectionConfig = function(sectionResult2, name2) {
  19636. return hasSection(sectionResult2, name2) ? sectionResult2.sections()[name2] : {};
  19637. };
  19638. var getToolbarMode = function(settings, defaultVal) {
  19639. return get$9(settings, "toolbar_mode").orThunk(function() {
  19640. return get$9(settings, "toolbar_drawer").map(function(val) {
  19641. return val === false ? "wrap" : val;
  19642. });
  19643. }).getOr(defaultVal);
  19644. };
  19645. var getDefaultSettings = function(settings, id, documentBaseUrl, isTouch2, editor) {
  19646. var baseDefaults = {
  19647. id,
  19648. theme: "silver",
  19649. toolbar_mode: getToolbarMode(settings, "floating"),
  19650. plugins: "",
  19651. document_base_url: documentBaseUrl,
  19652. add_form_submit_trigger: true,
  19653. submit_patch: true,
  19654. add_unload_trigger: true,
  19655. convert_urls: true,
  19656. relative_urls: true,
  19657. remove_script_host: true,
  19658. object_resizing: true,
  19659. doctype: "<!DOCTYPE html>",
  19660. visual: true,
  19661. font_size_legacy_values: "xx-small,small,medium,large,x-large,xx-large,300%",
  19662. forced_root_block: "p",
  19663. hidden_input: true,
  19664. inline_styles: true,
  19665. convert_fonts_to_spans: true,
  19666. indent: true,
  19667. 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",
  19668. 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",
  19669. entity_encoding: "named",
  19670. url_converter: editor.convertURL,
  19671. url_converter_scope: editor
  19672. };
  19673. return __assign(__assign({}, baseDefaults), isTouch2 ? defaultTouchSettings : {});
  19674. };
  19675. var getDefaultMobileSettings = function(mobileSettings, isPhone2) {
  19676. var defaultMobileSettings = {
  19677. resize: false,
  19678. toolbar_mode: getToolbarMode(mobileSettings, "scrolling"),
  19679. toolbar_sticky: false
  19680. };
  19681. var defaultPhoneSettings = { menubar: false };
  19682. return __assign(__assign(__assign({}, defaultTouchSettings), defaultMobileSettings), isPhone2 ? defaultPhoneSettings : {});
  19683. };
  19684. var getExternalPlugins = function(overrideSettings, settings) {
  19685. var userDefinedExternalPlugins = settings.external_plugins ? settings.external_plugins : {};
  19686. if (overrideSettings && overrideSettings.external_plugins) {
  19687. return Tools.extend({}, overrideSettings.external_plugins, userDefinedExternalPlugins);
  19688. } else {
  19689. return userDefinedExternalPlugins;
  19690. }
  19691. };
  19692. var combinePlugins = function(forcedPlugins, plugins) {
  19693. return [].concat(normalizePlugins(forcedPlugins)).concat(normalizePlugins(plugins));
  19694. };
  19695. var getPlatformPlugins = function(isMobileDevice, sectionResult2, desktopPlugins, mobilePlugins) {
  19696. if (isMobileDevice && isSectionTheme(sectionResult2, "mobile", "mobile")) {
  19697. return filterLegacyMobilePlugins(mobilePlugins);
  19698. } else if (isMobileDevice && hasSection(sectionResult2, "mobile")) {
  19699. return mobilePlugins;
  19700. } else {
  19701. return desktopPlugins;
  19702. }
  19703. };
  19704. var processPlugins = function(isMobileDevice, sectionResult2, defaultOverrideSettings, settings) {
  19705. var forcedPlugins = normalizePlugins(defaultOverrideSettings.forced_plugins);
  19706. var desktopPlugins = normalizePlugins(settings.plugins);
  19707. var mobileConfig = getSectionConfig(sectionResult2, "mobile");
  19708. var mobilePlugins = mobileConfig.plugins ? normalizePlugins(mobileConfig.plugins) : desktopPlugins;
  19709. var platformPlugins = getPlatformPlugins(isMobileDevice, sectionResult2, desktopPlugins, mobilePlugins);
  19710. var combinedPlugins = combinePlugins(forcedPlugins, platformPlugins);
  19711. if (Env.browser.isIE() && contains$3(combinedPlugins, "rtc")) {
  19712. throw new Error("RTC plugin is not supported on IE 11.");
  19713. }
  19714. return Tools.extend(settings, { plugins: combinedPlugins.join(" ") });
  19715. };
  19716. var isOnMobile = function(isMobileDevice, sectionResult2) {
  19717. return isMobileDevice && hasSection(sectionResult2, "mobile");
  19718. };
  19719. var combineSettings = function(isMobileDevice, isPhone2, defaultSettings, defaultOverrideSettings, settings) {
  19720. var defaultDeviceSettings = isMobileDevice ? { mobile: getDefaultMobileSettings(settings.mobile || {}, isPhone2) } : {};
  19721. var sectionResult2 = extractSections(["mobile"], deepMerge(defaultDeviceSettings, settings));
  19722. var extendedSettings = Tools.extend(defaultSettings, defaultOverrideSettings, sectionResult2.settings(), isOnMobile(isMobileDevice, sectionResult2) ? getSection(sectionResult2, "mobile") : {}, {
  19723. validate: true,
  19724. external_plugins: getExternalPlugins(defaultOverrideSettings, sectionResult2.settings())
  19725. });
  19726. return processPlugins(isMobileDevice, sectionResult2, defaultOverrideSettings, extendedSettings);
  19727. };
  19728. var getEditorSettings = function(editor, id, documentBaseUrl, defaultOverrideSettings, settings) {
  19729. var defaultSettings = getDefaultSettings(settings, id, documentBaseUrl, isTouch, editor);
  19730. var finalSettings = combineSettings(isPhone || isTablet, isPhone, defaultSettings, defaultOverrideSettings, settings);
  19731. if (finalSettings.deprecation_warnings !== false) {
  19732. logDeprecationsWarning(settings, finalSettings);
  19733. }
  19734. return finalSettings;
  19735. };
  19736. var getFiltered = function(predicate, editor, name2) {
  19737. return Optional.from(editor.settings[name2]).filter(predicate);
  19738. };
  19739. var getParamObject = function(value2) {
  19740. var output = {};
  19741. if (typeof value2 === "string") {
  19742. each$k(value2.indexOf("=") > 0 ? value2.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value2.split(","), function(val) {
  19743. var arr2 = val.split("=");
  19744. if (arr2.length > 1) {
  19745. output[Tools.trim(arr2[0])] = Tools.trim(arr2[1]);
  19746. } else {
  19747. output[Tools.trim(arr2[0])] = Tools.trim(arr2[0]);
  19748. }
  19749. });
  19750. } else {
  19751. output = value2;
  19752. }
  19753. return output;
  19754. };
  19755. var isArrayOf = function(p) {
  19756. return function(a) {
  19757. return isArray$1(a) && forall(a, p);
  19758. };
  19759. };
  19760. var getParam = function(editor, name2, defaultVal, type2) {
  19761. var value2 = name2 in editor.settings ? editor.settings[name2] : defaultVal;
  19762. if (type2 === "hash") {
  19763. return getParamObject(value2);
  19764. } else if (type2 === "string") {
  19765. return getFiltered(isString$1, editor, name2).getOr(defaultVal);
  19766. } else if (type2 === "number") {
  19767. return getFiltered(isNumber, editor, name2).getOr(defaultVal);
  19768. } else if (type2 === "boolean") {
  19769. return getFiltered(isBoolean, editor, name2).getOr(defaultVal);
  19770. } else if (type2 === "object") {
  19771. return getFiltered(isObject, editor, name2).getOr(defaultVal);
  19772. } else if (type2 === "array") {
  19773. return getFiltered(isArray$1, editor, name2).getOr(defaultVal);
  19774. } else if (type2 === "string[]") {
  19775. return getFiltered(isArrayOf(isString$1), editor, name2).getOr(defaultVal);
  19776. } else if (type2 === "function") {
  19777. return getFiltered(isFunction, editor, name2).getOr(defaultVal);
  19778. } else {
  19779. return value2;
  19780. }
  19781. };
  19782. var CreateIconManager = function() {
  19783. var lookup = {};
  19784. var add2 = function(id, iconPack) {
  19785. lookup[id] = iconPack;
  19786. };
  19787. var get2 = function(id) {
  19788. if (lookup[id]) {
  19789. return lookup[id];
  19790. }
  19791. return { icons: {} };
  19792. };
  19793. var has2 = function(id) {
  19794. return has$2(lookup, id);
  19795. };
  19796. return {
  19797. add: add2,
  19798. get: get2,
  19799. has: has2
  19800. };
  19801. };
  19802. var IconManager = CreateIconManager();
  19803. var getProp = function(propName, elm) {
  19804. var rawElm = elm.dom;
  19805. return rawElm[propName];
  19806. };
  19807. var getComputedSizeProp = function(propName, elm) {
  19808. return parseInt(get$5(elm, propName), 10);
  19809. };
  19810. var getClientWidth = curry(getProp, "clientWidth");
  19811. var getClientHeight = curry(getProp, "clientHeight");
  19812. var getMarginTop = curry(getComputedSizeProp, "margin-top");
  19813. var getMarginLeft = curry(getComputedSizeProp, "margin-left");
  19814. var getBoundingClientRect = function(elm) {
  19815. return elm.dom.getBoundingClientRect();
  19816. };
  19817. var isInsideElementContentArea = function(bodyElm, clientX, clientY) {
  19818. var clientWidth = getClientWidth(bodyElm);
  19819. var clientHeight = getClientHeight(bodyElm);
  19820. return clientX >= 0 && clientY >= 0 && clientX <= clientWidth && clientY <= clientHeight;
  19821. };
  19822. var transpose = function(inline, elm, clientX, clientY) {
  19823. var clientRect = getBoundingClientRect(elm);
  19824. var deltaX = inline ? clientRect.left + elm.dom.clientLeft + getMarginLeft(elm) : 0;
  19825. var deltaY = inline ? clientRect.top + elm.dom.clientTop + getMarginTop(elm) : 0;
  19826. var x = clientX - deltaX;
  19827. var y = clientY - deltaY;
  19828. return {
  19829. x,
  19830. y
  19831. };
  19832. };
  19833. var isXYInContentArea = function(editor, clientX, clientY) {
  19834. var bodyElm = SugarElement.fromDom(editor.getBody());
  19835. var targetElm = editor.inline ? bodyElm : documentElement(bodyElm);
  19836. var transposedPoint = transpose(editor.inline, targetElm, clientX, clientY);
  19837. return isInsideElementContentArea(targetElm, transposedPoint.x, transposedPoint.y);
  19838. };
  19839. var fromDomSafe = function(node) {
  19840. return Optional.from(node).map(SugarElement.fromDom);
  19841. };
  19842. var isEditorAttachedToDom = function(editor) {
  19843. var rawContainer = editor.inline ? editor.getBody() : editor.getContentAreaContainer();
  19844. return fromDomSafe(rawContainer).map(inBody).getOr(false);
  19845. };
  19846. var NotificationManagerImpl = function() {
  19847. var unimplemented = function() {
  19848. throw new Error("Theme did not provide a NotificationManager implementation.");
  19849. };
  19850. return {
  19851. open: unimplemented,
  19852. close: unimplemented,
  19853. reposition: unimplemented,
  19854. getArgs: unimplemented
  19855. };
  19856. };
  19857. var NotificationManager = function(editor) {
  19858. var notifications = [];
  19859. var getImplementation = function() {
  19860. var theme = editor.theme;
  19861. return theme && theme.getNotificationManagerImpl ? theme.getNotificationManagerImpl() : NotificationManagerImpl();
  19862. };
  19863. var getTopNotification = function() {
  19864. return Optional.from(notifications[0]);
  19865. };
  19866. var isEqual2 = function(a, b) {
  19867. return a.type === b.type && a.text === b.text && !a.progressBar && !a.timeout && !b.progressBar && !b.timeout;
  19868. };
  19869. var reposition2 = function() {
  19870. if (notifications.length > 0) {
  19871. getImplementation().reposition(notifications);
  19872. }
  19873. };
  19874. var addNotification = function(notification) {
  19875. notifications.push(notification);
  19876. };
  19877. var closeNotification = function(notification) {
  19878. findIndex$2(notifications, function(otherNotification) {
  19879. return otherNotification === notification;
  19880. }).each(function(index) {
  19881. notifications.splice(index, 1);
  19882. });
  19883. };
  19884. var open = function(spec, fireEvent2) {
  19885. if (fireEvent2 === void 0) {
  19886. fireEvent2 = true;
  19887. }
  19888. if (editor.removed || !isEditorAttachedToDom(editor)) {
  19889. return;
  19890. }
  19891. if (fireEvent2) {
  19892. editor.fire("BeforeOpenNotification", { notification: spec });
  19893. }
  19894. return find$3(notifications, function(notification) {
  19895. return isEqual2(getImplementation().getArgs(notification), spec);
  19896. }).getOrThunk(function() {
  19897. editor.editorManager.setActive(editor);
  19898. var notification = getImplementation().open(spec, function() {
  19899. closeNotification(notification);
  19900. reposition2();
  19901. getTopNotification().fold(function() {
  19902. return editor.focus();
  19903. }, function(top) {
  19904. return focus$1(SugarElement.fromDom(top.getEl()));
  19905. });
  19906. });
  19907. addNotification(notification);
  19908. reposition2();
  19909. editor.fire("OpenNotification", { notification: __assign({}, notification) });
  19910. return notification;
  19911. });
  19912. };
  19913. var close = function() {
  19914. getTopNotification().each(function(notification) {
  19915. getImplementation().close(notification);
  19916. closeNotification(notification);
  19917. reposition2();
  19918. });
  19919. };
  19920. var getNotifications = constant(notifications);
  19921. var registerEvents2 = function(editor2) {
  19922. editor2.on("SkinLoaded", function() {
  19923. var serviceMessage = getServiceMessage(editor2);
  19924. if (serviceMessage) {
  19925. open({
  19926. text: serviceMessage,
  19927. type: "warning",
  19928. timeout: 0
  19929. }, false);
  19930. }
  19931. reposition2();
  19932. });
  19933. editor2.on("show ResizeEditor ResizeWindow NodeChange", function() {
  19934. Delay.requestAnimationFrame(reposition2);
  19935. });
  19936. editor2.on("remove", function() {
  19937. each$k(notifications.slice(), function(notification) {
  19938. getImplementation().close(notification);
  19939. });
  19940. });
  19941. };
  19942. registerEvents2(editor);
  19943. return {
  19944. open,
  19945. close,
  19946. getNotifications
  19947. };
  19948. };
  19949. var PluginManager = AddOnManager.PluginManager;
  19950. var ThemeManager = AddOnManager.ThemeManager;
  19951. function WindowManagerImpl() {
  19952. var unimplemented = function() {
  19953. throw new Error("Theme did not provide a WindowManager implementation.");
  19954. };
  19955. return {
  19956. open: unimplemented,
  19957. openUrl: unimplemented,
  19958. alert: unimplemented,
  19959. confirm: unimplemented,
  19960. close: unimplemented,
  19961. getParams: unimplemented,
  19962. setParams: unimplemented
  19963. };
  19964. }
  19965. var WindowManager = function(editor) {
  19966. var dialogs = [];
  19967. var getImplementation = function() {
  19968. var theme = editor.theme;
  19969. return theme && theme.getWindowManagerImpl ? theme.getWindowManagerImpl() : WindowManagerImpl();
  19970. };
  19971. var funcBind = function(scope, f) {
  19972. return function() {
  19973. var args = [];
  19974. for (var _i = 0; _i < arguments.length; _i++) {
  19975. args[_i] = arguments[_i];
  19976. }
  19977. return f ? f.apply(scope, args) : void 0;
  19978. };
  19979. };
  19980. var fireOpenEvent = function(dialog) {
  19981. editor.fire("OpenWindow", { dialog });
  19982. };
  19983. var fireCloseEvent = function(dialog) {
  19984. editor.fire("CloseWindow", { dialog });
  19985. };
  19986. var addDialog = function(dialog) {
  19987. dialogs.push(dialog);
  19988. fireOpenEvent(dialog);
  19989. };
  19990. var closeDialog = function(dialog) {
  19991. fireCloseEvent(dialog);
  19992. dialogs = filter$4(dialogs, function(otherDialog) {
  19993. return otherDialog !== dialog;
  19994. });
  19995. if (dialogs.length === 0) {
  19996. editor.focus();
  19997. }
  19998. };
  19999. var getTopDialog = function() {
  20000. return Optional.from(dialogs[dialogs.length - 1]);
  20001. };
  20002. var storeSelectionAndOpenDialog = function(openDialog) {
  20003. editor.editorManager.setActive(editor);
  20004. store(editor);
  20005. var dialog = openDialog();
  20006. addDialog(dialog);
  20007. return dialog;
  20008. };
  20009. var open = function(args, params) {
  20010. return storeSelectionAndOpenDialog(function() {
  20011. return getImplementation().open(args, params, closeDialog);
  20012. });
  20013. };
  20014. var openUrl = function(args) {
  20015. return storeSelectionAndOpenDialog(function() {
  20016. return getImplementation().openUrl(args, closeDialog);
  20017. });
  20018. };
  20019. var alert = function(message, callback, scope) {
  20020. var windowManagerImpl = getImplementation();
  20021. windowManagerImpl.alert(message, funcBind(scope ? scope : windowManagerImpl, callback));
  20022. };
  20023. var confirm = function(message, callback, scope) {
  20024. var windowManagerImpl = getImplementation();
  20025. windowManagerImpl.confirm(message, funcBind(scope ? scope : windowManagerImpl, callback));
  20026. };
  20027. var close = function() {
  20028. getTopDialog().each(function(dialog) {
  20029. getImplementation().close(dialog);
  20030. closeDialog(dialog);
  20031. });
  20032. };
  20033. editor.on("remove", function() {
  20034. each$k(dialogs, function(dialog) {
  20035. getImplementation().close(dialog);
  20036. });
  20037. });
  20038. return {
  20039. open,
  20040. openUrl,
  20041. alert,
  20042. confirm,
  20043. close
  20044. };
  20045. };
  20046. var displayNotification = function(editor, message) {
  20047. editor.notificationManager.open({
  20048. type: "error",
  20049. text: message
  20050. });
  20051. };
  20052. var displayError = function(editor, message) {
  20053. if (editor._skinLoaded) {
  20054. displayNotification(editor, message);
  20055. } else {
  20056. editor.on("SkinLoaded", function() {
  20057. displayNotification(editor, message);
  20058. });
  20059. }
  20060. };
  20061. var uploadError = function(editor, message) {
  20062. displayError(editor, I18n.translate([
  20063. "Failed to upload image: {0}",
  20064. message
  20065. ]));
  20066. };
  20067. var logError = function(editor, errorType, msg) {
  20068. fireError(editor, errorType, { message: msg });
  20069. console.error(msg);
  20070. };
  20071. var createLoadError = function(type2, url, name2) {
  20072. return name2 ? "Failed to load " + type2 + ": " + name2 + " from url " + url : "Failed to load " + type2 + " url: " + url;
  20073. };
  20074. var pluginLoadError = function(editor, url, name2) {
  20075. logError(editor, "PluginLoadError", createLoadError("plugin", url, name2));
  20076. };
  20077. var iconsLoadError = function(editor, url, name2) {
  20078. logError(editor, "IconsLoadError", createLoadError("icons", url, name2));
  20079. };
  20080. var languageLoadError = function(editor, url, name2) {
  20081. logError(editor, "LanguageLoadError", createLoadError("language", url, name2));
  20082. };
  20083. var pluginInitError = function(editor, name2, err) {
  20084. var message = I18n.translate([
  20085. "Failed to initialize plugin: {0}",
  20086. name2
  20087. ]);
  20088. fireError(editor, "PluginLoadError", { message });
  20089. initError(message, err);
  20090. displayError(editor, message);
  20091. };
  20092. var initError = function(message) {
  20093. var x = [];
  20094. for (var _i = 1; _i < arguments.length; _i++) {
  20095. x[_i - 1] = arguments[_i];
  20096. }
  20097. var console2 = window.console;
  20098. if (console2) {
  20099. if (console2.error) {
  20100. console2.error.apply(console2, __spreadArray([message], x, false));
  20101. } else {
  20102. console2.log.apply(console2, __spreadArray([message], x, false));
  20103. }
  20104. }
  20105. };
  20106. var isContentCssSkinName = function(url) {
  20107. return /^[a-z0-9\-]+$/i.test(url);
  20108. };
  20109. var getContentCssUrls = function(editor) {
  20110. return transformToUrls(editor, getContentCss(editor));
  20111. };
  20112. var getFontCssUrls = function(editor) {
  20113. return transformToUrls(editor, getFontCss(editor));
  20114. };
  20115. var transformToUrls = function(editor, cssLinks) {
  20116. var skinUrl = editor.editorManager.baseURL + "/skins/content";
  20117. var suffix = editor.editorManager.suffix;
  20118. var contentCssFile = "content" + suffix + ".css";
  20119. var inline = editor.inline === true;
  20120. return map$3(cssLinks, function(url) {
  20121. if (isContentCssSkinName(url) && !inline) {
  20122. return skinUrl + "/" + url + "/" + contentCssFile;
  20123. } else {
  20124. return editor.documentBaseURI.toAbsolute(url);
  20125. }
  20126. });
  20127. };
  20128. var appendContentCssFromSettings = function(editor) {
  20129. editor.contentCSS = editor.contentCSS.concat(getContentCssUrls(editor), getFontCssUrls(editor));
  20130. };
  20131. var UploadStatus = function() {
  20132. var PENDING = 1, UPLOADED = 2;
  20133. var blobUriStatuses = {};
  20134. var createStatus = function(status, resultUri) {
  20135. return {
  20136. status,
  20137. resultUri
  20138. };
  20139. };
  20140. var hasBlobUri = function(blobUri) {
  20141. return blobUri in blobUriStatuses;
  20142. };
  20143. var getResultUri = function(blobUri) {
  20144. var result = blobUriStatuses[blobUri];
  20145. return result ? result.resultUri : null;
  20146. };
  20147. var isPending = function(blobUri) {
  20148. return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === PENDING : false;
  20149. };
  20150. var isUploaded = function(blobUri) {
  20151. return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === UPLOADED : false;
  20152. };
  20153. var markPending = function(blobUri) {
  20154. blobUriStatuses[blobUri] = createStatus(PENDING, null);
  20155. };
  20156. var markUploaded = function(blobUri, resultUri) {
  20157. blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri);
  20158. };
  20159. var removeFailed = function(blobUri) {
  20160. delete blobUriStatuses[blobUri];
  20161. };
  20162. var destroy2 = function() {
  20163. blobUriStatuses = {};
  20164. };
  20165. return {
  20166. hasBlobUri,
  20167. getResultUri,
  20168. isPending,
  20169. isUploaded,
  20170. markPending,
  20171. markUploaded,
  20172. removeFailed,
  20173. destroy: destroy2
  20174. };
  20175. };
  20176. var count = 0;
  20177. var seed = function() {
  20178. var rnd = function() {
  20179. return Math.round(Math.random() * 4294967295).toString(36);
  20180. };
  20181. var now = new Date().getTime();
  20182. return "s" + now.toString(36) + rnd() + rnd() + rnd();
  20183. };
  20184. var uuid = function(prefix) {
  20185. return prefix + count++ + seed();
  20186. };
  20187. var BlobCache = function() {
  20188. var cache = [];
  20189. var mimeToExt = function(mime) {
  20190. var mimes = {
  20191. "image/jpeg": "jpg",
  20192. "image/jpg": "jpg",
  20193. "image/gif": "gif",
  20194. "image/png": "png",
  20195. "image/apng": "apng",
  20196. "image/avif": "avif",
  20197. "image/svg+xml": "svg",
  20198. "image/webp": "webp",
  20199. "image/bmp": "bmp",
  20200. "image/tiff": "tiff"
  20201. };
  20202. return mimes[mime.toLowerCase()] || "dat";
  20203. };
  20204. var create2 = function(o, blob, base64, name2, filename) {
  20205. if (isString$1(o)) {
  20206. var id = o;
  20207. return toBlobInfo({
  20208. id,
  20209. name: name2,
  20210. filename,
  20211. blob,
  20212. base64
  20213. });
  20214. } else if (isObject(o)) {
  20215. return toBlobInfo(o);
  20216. } else {
  20217. throw new Error("Unknown input type");
  20218. }
  20219. };
  20220. var toBlobInfo = function(o) {
  20221. if (!o.blob || !o.base64) {
  20222. throw new Error("blob and base64 representations of the image are required for BlobInfo to be created");
  20223. }
  20224. var id = o.id || uuid("blobid");
  20225. var name2 = o.name || id;
  20226. var blob = o.blob;
  20227. return {
  20228. id: constant(id),
  20229. name: constant(name2),
  20230. filename: constant(o.filename || name2 + "." + mimeToExt(blob.type)),
  20231. blob: constant(blob),
  20232. base64: constant(o.base64),
  20233. blobUri: constant(o.blobUri || URL.createObjectURL(blob)),
  20234. uri: constant(o.uri)
  20235. };
  20236. };
  20237. var add2 = function(blobInfo) {
  20238. if (!get2(blobInfo.id())) {
  20239. cache.push(blobInfo);
  20240. }
  20241. };
  20242. var findFirst = function(predicate) {
  20243. return find$3(cache, predicate).getOrUndefined();
  20244. };
  20245. var get2 = function(id) {
  20246. return findFirst(function(cachedBlobInfo) {
  20247. return cachedBlobInfo.id() === id;
  20248. });
  20249. };
  20250. var getByUri = function(blobUri) {
  20251. return findFirst(function(blobInfo) {
  20252. return blobInfo.blobUri() === blobUri;
  20253. });
  20254. };
  20255. var getByData = function(base64, type2) {
  20256. return findFirst(function(blobInfo) {
  20257. return blobInfo.base64() === base64 && blobInfo.blob().type === type2;
  20258. });
  20259. };
  20260. var removeByUri = function(blobUri) {
  20261. cache = filter$4(cache, function(blobInfo) {
  20262. if (blobInfo.blobUri() === blobUri) {
  20263. URL.revokeObjectURL(blobInfo.blobUri());
  20264. return false;
  20265. }
  20266. return true;
  20267. });
  20268. };
  20269. var destroy2 = function() {
  20270. each$k(cache, function(cachedBlobInfo) {
  20271. URL.revokeObjectURL(cachedBlobInfo.blobUri());
  20272. });
  20273. cache = [];
  20274. };
  20275. return {
  20276. create: create2,
  20277. add: add2,
  20278. get: get2,
  20279. getByUri,
  20280. getByData,
  20281. findFirst,
  20282. removeByUri,
  20283. destroy: destroy2
  20284. };
  20285. };
  20286. var Uploader = function(uploadStatus, settings) {
  20287. var pendingPromises = {};
  20288. var pathJoin = function(path1, path2) {
  20289. if (path1) {
  20290. return path1.replace(/\/$/, "") + "/" + path2.replace(/^\//, "");
  20291. }
  20292. return path2;
  20293. };
  20294. var defaultHandler = function(blobInfo, success, failure, progress) {
  20295. var xhr = new XMLHttpRequest();
  20296. xhr.open("POST", settings.url);
  20297. xhr.withCredentials = settings.credentials;
  20298. xhr.upload.onprogress = function(e) {
  20299. progress(e.loaded / e.total * 100);
  20300. };
  20301. xhr.onerror = function() {
  20302. failure("Image upload failed due to a XHR Transport error. Code: " + xhr.status);
  20303. };
  20304. xhr.onload = function() {
  20305. if (xhr.status < 200 || xhr.status >= 300) {
  20306. failure("HTTP Error: " + xhr.status);
  20307. return;
  20308. }
  20309. var json = JSON.parse(xhr.responseText);
  20310. if (!json || typeof json.location !== "string") {
  20311. failure("Invalid JSON: " + xhr.responseText);
  20312. return;
  20313. }
  20314. success(pathJoin(settings.basePath, json.location));
  20315. };
  20316. var formData = new FormData();
  20317. formData.append("file", blobInfo.blob(), blobInfo.filename());
  20318. xhr.send(formData);
  20319. };
  20320. var noUpload = function() {
  20321. return new promiseObj(function(resolve2) {
  20322. resolve2([]);
  20323. });
  20324. };
  20325. var handlerSuccess = function(blobInfo, url) {
  20326. return {
  20327. url,
  20328. blobInfo,
  20329. status: true
  20330. };
  20331. };
  20332. var handlerFailure = function(blobInfo, message, options) {
  20333. return {
  20334. url: "",
  20335. blobInfo,
  20336. status: false,
  20337. error: {
  20338. message,
  20339. options
  20340. }
  20341. };
  20342. };
  20343. var resolvePending = function(blobUri, result) {
  20344. Tools.each(pendingPromises[blobUri], function(resolve2) {
  20345. resolve2(result);
  20346. });
  20347. delete pendingPromises[blobUri];
  20348. };
  20349. var uploadBlobInfo = function(blobInfo, handler, openNotification2) {
  20350. uploadStatus.markPending(blobInfo.blobUri());
  20351. return new promiseObj(function(resolve2) {
  20352. var notification, progress;
  20353. try {
  20354. var closeNotification_1 = function() {
  20355. if (notification) {
  20356. notification.close();
  20357. progress = noop;
  20358. }
  20359. };
  20360. var success = function(url) {
  20361. closeNotification_1();
  20362. uploadStatus.markUploaded(blobInfo.blobUri(), url);
  20363. resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url));
  20364. resolve2(handlerSuccess(blobInfo, url));
  20365. };
  20366. var failure = function(error2, options) {
  20367. var failureOptions = options ? options : {};
  20368. closeNotification_1();
  20369. uploadStatus.removeFailed(blobInfo.blobUri());
  20370. resolvePending(blobInfo.blobUri(), handlerFailure(blobInfo, error2, failureOptions));
  20371. resolve2(handlerFailure(blobInfo, error2, failureOptions));
  20372. };
  20373. progress = function(percent) {
  20374. if (percent < 0 || percent > 100) {
  20375. return;
  20376. }
  20377. Optional.from(notification).orThunk(function() {
  20378. return Optional.from(openNotification2).map(apply);
  20379. }).each(function(n) {
  20380. notification = n;
  20381. n.progressBar.value(percent);
  20382. });
  20383. };
  20384. handler(blobInfo, success, failure, progress);
  20385. } catch (ex) {
  20386. resolve2(handlerFailure(blobInfo, ex.message, {}));
  20387. }
  20388. });
  20389. };
  20390. var isDefaultHandler = function(handler) {
  20391. return handler === defaultHandler;
  20392. };
  20393. var pendingUploadBlobInfo = function(blobInfo) {
  20394. var blobUri = blobInfo.blobUri();
  20395. return new promiseObj(function(resolve2) {
  20396. pendingPromises[blobUri] = pendingPromises[blobUri] || [];
  20397. pendingPromises[blobUri].push(resolve2);
  20398. });
  20399. };
  20400. var uploadBlobs = function(blobInfos, openNotification2) {
  20401. blobInfos = Tools.grep(blobInfos, function(blobInfo) {
  20402. return !uploadStatus.isUploaded(blobInfo.blobUri());
  20403. });
  20404. return promiseObj.all(Tools.map(blobInfos, function(blobInfo) {
  20405. return uploadStatus.isPending(blobInfo.blobUri()) ? pendingUploadBlobInfo(blobInfo) : uploadBlobInfo(blobInfo, settings.handler, openNotification2);
  20406. }));
  20407. };
  20408. var upload = function(blobInfos, openNotification2) {
  20409. return !settings.url && isDefaultHandler(settings.handler) ? noUpload() : uploadBlobs(blobInfos, openNotification2);
  20410. };
  20411. if (isFunction(settings.handler) === false) {
  20412. settings.handler = defaultHandler;
  20413. }
  20414. return { upload };
  20415. };
  20416. var openNotification = function(editor) {
  20417. return function() {
  20418. return editor.notificationManager.open({
  20419. text: editor.translate("Image uploading..."),
  20420. type: "info",
  20421. timeout: -1,
  20422. progressBar: true
  20423. });
  20424. };
  20425. };
  20426. var createUploader = function(editor, uploadStatus) {
  20427. return Uploader(uploadStatus, {
  20428. url: getImageUploadUrl(editor),
  20429. basePath: getImageUploadBasePath(editor),
  20430. credentials: getImagesUploadCredentials(editor),
  20431. handler: getImagesUploadHandler(editor)
  20432. });
  20433. };
  20434. var ImageUploader = function(editor) {
  20435. var uploadStatus = UploadStatus();
  20436. var uploader = createUploader(editor, uploadStatus);
  20437. return {
  20438. upload: function(blobInfos, showNotification) {
  20439. if (showNotification === void 0) {
  20440. showNotification = true;
  20441. }
  20442. return uploader.upload(blobInfos, showNotification ? openNotification(editor) : void 0);
  20443. }
  20444. };
  20445. };
  20446. var UploadChangeHandler = function(editor) {
  20447. var lastChangedLevel = Cell(null);
  20448. editor.on("change AddUndo", function(e) {
  20449. lastChangedLevel.set(__assign({}, e.level));
  20450. });
  20451. var fireIfChanged = function() {
  20452. var data2 = editor.undoManager.data;
  20453. last$2(data2).filter(function(level) {
  20454. return !isEq$1(lastChangedLevel.get(), level);
  20455. }).each(function(level) {
  20456. editor.setDirty(true);
  20457. editor.fire("change", {
  20458. level,
  20459. lastLevel: get$a(data2, data2.length - 2).getOrNull()
  20460. });
  20461. });
  20462. };
  20463. return { fireIfChanged };
  20464. };
  20465. var EditorUpload = function(editor) {
  20466. var blobCache = BlobCache();
  20467. var uploader, imageScanner;
  20468. var uploadStatus = UploadStatus();
  20469. var urlFilters = [];
  20470. var changeHandler = UploadChangeHandler(editor);
  20471. var aliveGuard = function(callback) {
  20472. return function(result) {
  20473. if (editor.selection) {
  20474. return callback(result);
  20475. }
  20476. return [];
  20477. };
  20478. };
  20479. var cacheInvalidator = function(url) {
  20480. return url + (url.indexOf("?") === -1 ? "?" : "&") + new Date().getTime();
  20481. };
  20482. var replaceString = function(content, search2, replace) {
  20483. var index = 0;
  20484. do {
  20485. index = content.indexOf(search2, index);
  20486. if (index !== -1) {
  20487. content = content.substring(0, index) + replace + content.substr(index + search2.length);
  20488. index += replace.length - search2.length + 1;
  20489. }
  20490. } while (index !== -1);
  20491. return content;
  20492. };
  20493. var replaceImageUrl = function(content, targetUrl, replacementUrl) {
  20494. var replacementString = 'src="' + replacementUrl + '"' + (replacementUrl === Env.transparentSrc ? ' data-mce-placeholder="1"' : "");
  20495. content = replaceString(content, 'src="' + targetUrl + '"', replacementString);
  20496. content = replaceString(content, 'data-mce-src="' + targetUrl + '"', 'data-mce-src="' + replacementUrl + '"');
  20497. return content;
  20498. };
  20499. var replaceUrlInUndoStack = function(targetUrl, replacementUrl) {
  20500. each$k(editor.undoManager.data, function(level) {
  20501. if (level.type === "fragmented") {
  20502. level.fragments = map$3(level.fragments, function(fragment) {
  20503. return replaceImageUrl(fragment, targetUrl, replacementUrl);
  20504. });
  20505. } else {
  20506. level.content = replaceImageUrl(level.content, targetUrl, replacementUrl);
  20507. }
  20508. });
  20509. };
  20510. var replaceImageUriInView = function(image, resultUri) {
  20511. var src = editor.convertURL(resultUri, "src");
  20512. replaceUrlInUndoStack(image.src, resultUri);
  20513. editor.$(image).attr({
  20514. "src": shouldReuseFileName(editor) ? cacheInvalidator(resultUri) : resultUri,
  20515. "data-mce-src": src
  20516. });
  20517. };
  20518. var uploadImages = function(callback) {
  20519. if (!uploader) {
  20520. uploader = createUploader(editor, uploadStatus);
  20521. }
  20522. return scanForImages().then(aliveGuard(function(imageInfos) {
  20523. var blobInfos = map$3(imageInfos, function(imageInfo) {
  20524. return imageInfo.blobInfo;
  20525. });
  20526. return uploader.upload(blobInfos, openNotification(editor)).then(aliveGuard(function(result) {
  20527. var imagesToRemove = [];
  20528. var filteredResult = map$3(result, function(uploadInfo, index) {
  20529. var blobInfo = imageInfos[index].blobInfo;
  20530. var image = imageInfos[index].image;
  20531. if (uploadInfo.status && shouldReplaceBlobUris(editor)) {
  20532. blobCache.removeByUri(image.src);
  20533. if (isRtc(editor))
  20534. ;
  20535. else {
  20536. replaceImageUriInView(image, uploadInfo.url);
  20537. }
  20538. } else if (uploadInfo.error) {
  20539. if (uploadInfo.error.options.remove) {
  20540. replaceUrlInUndoStack(image.getAttribute("src"), Env.transparentSrc);
  20541. imagesToRemove.push(image);
  20542. }
  20543. uploadError(editor, uploadInfo.error.message);
  20544. }
  20545. return {
  20546. element: image,
  20547. status: uploadInfo.status,
  20548. uploadUri: uploadInfo.url,
  20549. blobInfo
  20550. };
  20551. });
  20552. if (filteredResult.length > 0) {
  20553. changeHandler.fireIfChanged();
  20554. }
  20555. if (imagesToRemove.length > 0) {
  20556. if (isRtc(editor)) {
  20557. console.error("Removing images on failed uploads is currently unsupported for RTC");
  20558. } else {
  20559. editor.undoManager.transact(function() {
  20560. each$k(imagesToRemove, function(element) {
  20561. editor.dom.remove(element);
  20562. blobCache.removeByUri(element.src);
  20563. });
  20564. });
  20565. }
  20566. }
  20567. if (callback) {
  20568. callback(filteredResult);
  20569. }
  20570. return filteredResult;
  20571. }));
  20572. }));
  20573. };
  20574. var uploadImagesAuto = function(callback) {
  20575. if (isAutomaticUploadsEnabled(editor)) {
  20576. return uploadImages(callback);
  20577. }
  20578. };
  20579. var isValidDataUriImage = function(imgElm) {
  20580. if (forall(urlFilters, function(filter2) {
  20581. return filter2(imgElm);
  20582. }) === false) {
  20583. return false;
  20584. }
  20585. if (imgElm.getAttribute("src").indexOf("data:") === 0) {
  20586. var dataImgFilter = getImagesDataImgFilter(editor);
  20587. return dataImgFilter(imgElm);
  20588. }
  20589. return true;
  20590. };
  20591. var addFilter = function(filter2) {
  20592. urlFilters.push(filter2);
  20593. };
  20594. var scanForImages = function() {
  20595. if (!imageScanner) {
  20596. imageScanner = ImageScanner(uploadStatus, blobCache);
  20597. }
  20598. return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(aliveGuard(function(result) {
  20599. result = filter$4(result, function(resultItem) {
  20600. if (typeof resultItem === "string") {
  20601. displayError(editor, resultItem);
  20602. return false;
  20603. }
  20604. return true;
  20605. });
  20606. if (isRtc(editor))
  20607. ;
  20608. else {
  20609. each$k(result, function(resultItem) {
  20610. replaceUrlInUndoStack(resultItem.image.src, resultItem.blobInfo.blobUri());
  20611. resultItem.image.src = resultItem.blobInfo.blobUri();
  20612. resultItem.image.removeAttribute("data-mce-src");
  20613. });
  20614. }
  20615. return result;
  20616. }));
  20617. };
  20618. var destroy2 = function() {
  20619. blobCache.destroy();
  20620. uploadStatus.destroy();
  20621. imageScanner = uploader = null;
  20622. };
  20623. var replaceBlobUris = function(content) {
  20624. return content.replace(/src="(blob:[^"]+)"/g, function(match2, blobUri) {
  20625. var resultUri = uploadStatus.getResultUri(blobUri);
  20626. if (resultUri) {
  20627. return 'src="' + resultUri + '"';
  20628. }
  20629. var blobInfo = blobCache.getByUri(blobUri);
  20630. if (!blobInfo) {
  20631. blobInfo = foldl(editor.editorManager.get(), function(result, editor2) {
  20632. return result || editor2.editorUpload && editor2.editorUpload.blobCache.getByUri(blobUri);
  20633. }, null);
  20634. }
  20635. if (blobInfo) {
  20636. var blob = blobInfo.blob();
  20637. return 'src="data:' + blob.type + ";base64," + blobInfo.base64() + '"';
  20638. }
  20639. return match2;
  20640. });
  20641. };
  20642. editor.on("SetContent", function() {
  20643. if (isAutomaticUploadsEnabled(editor)) {
  20644. uploadImagesAuto();
  20645. } else {
  20646. scanForImages();
  20647. }
  20648. });
  20649. editor.on("RawSaveContent", function(e) {
  20650. e.content = replaceBlobUris(e.content);
  20651. });
  20652. editor.on("GetContent", function(e) {
  20653. if (e.source_view || e.format === "raw" || e.format === "tree") {
  20654. return;
  20655. }
  20656. e.content = replaceBlobUris(e.content);
  20657. });
  20658. editor.on("PostRender", function() {
  20659. editor.parser.addNodeFilter("img", function(images) {
  20660. each$k(images, function(img) {
  20661. var src = img.attr("src");
  20662. if (blobCache.getByUri(src)) {
  20663. return;
  20664. }
  20665. var resultUri = uploadStatus.getResultUri(src);
  20666. if (resultUri) {
  20667. img.attr("src", resultUri);
  20668. }
  20669. });
  20670. });
  20671. });
  20672. return {
  20673. blobCache,
  20674. addFilter,
  20675. uploadImages,
  20676. uploadImagesAuto,
  20677. scanForImages,
  20678. destroy: destroy2
  20679. };
  20680. };
  20681. var get = function(dom2) {
  20682. var formats = {
  20683. valigntop: [{
  20684. selector: "td,th",
  20685. styles: { verticalAlign: "top" }
  20686. }],
  20687. valignmiddle: [{
  20688. selector: "td,th",
  20689. styles: { verticalAlign: "middle" }
  20690. }],
  20691. valignbottom: [{
  20692. selector: "td,th",
  20693. styles: { verticalAlign: "bottom" }
  20694. }],
  20695. alignleft: [
  20696. {
  20697. selector: "figure.image",
  20698. collapsed: false,
  20699. classes: "align-left",
  20700. ceFalseOverride: true,
  20701. preview: "font-family font-size"
  20702. },
  20703. {
  20704. selector: "figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",
  20705. styles: { textAlign: "left" },
  20706. inherit: false,
  20707. preview: false,
  20708. defaultBlock: "div"
  20709. },
  20710. {
  20711. selector: "img,table,audio,video",
  20712. collapsed: false,
  20713. styles: { float: "left" },
  20714. preview: "font-family font-size"
  20715. }
  20716. ],
  20717. aligncenter: [
  20718. {
  20719. selector: "figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",
  20720. styles: { textAlign: "center" },
  20721. inherit: false,
  20722. preview: "font-family font-size",
  20723. defaultBlock: "div"
  20724. },
  20725. {
  20726. selector: "figure.image",
  20727. collapsed: false,
  20728. classes: "align-center",
  20729. ceFalseOverride: true,
  20730. preview: "font-family font-size"
  20731. },
  20732. {
  20733. selector: "img,audio,video",
  20734. collapsed: false,
  20735. styles: {
  20736. display: "block",
  20737. marginLeft: "auto",
  20738. marginRight: "auto"
  20739. },
  20740. preview: false
  20741. },
  20742. {
  20743. selector: "table",
  20744. collapsed: false,
  20745. styles: {
  20746. marginLeft: "auto",
  20747. marginRight: "auto"
  20748. },
  20749. preview: "font-family font-size"
  20750. }
  20751. ],
  20752. alignright: [
  20753. {
  20754. selector: "figure.image",
  20755. collapsed: false,
  20756. classes: "align-right",
  20757. ceFalseOverride: true,
  20758. preview: "font-family font-size"
  20759. },
  20760. {
  20761. selector: "figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",
  20762. styles: { textAlign: "right" },
  20763. inherit: false,
  20764. preview: "font-family font-size",
  20765. defaultBlock: "div"
  20766. },
  20767. {
  20768. selector: "img,table,audio,video",
  20769. collapsed: false,
  20770. styles: { float: "right" },
  20771. preview: "font-family font-size"
  20772. }
  20773. ],
  20774. alignjustify: [{
  20775. selector: "figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",
  20776. styles: { textAlign: "justify" },
  20777. inherit: false,
  20778. defaultBlock: "div",
  20779. preview: "font-family font-size"
  20780. }],
  20781. bold: [
  20782. {
  20783. inline: "strong",
  20784. remove: "all",
  20785. preserve_attributes: [
  20786. "class",
  20787. "style"
  20788. ]
  20789. },
  20790. {
  20791. inline: "span",
  20792. styles: { fontWeight: "bold" }
  20793. },
  20794. {
  20795. inline: "b",
  20796. remove: "all",
  20797. preserve_attributes: [
  20798. "class",
  20799. "style"
  20800. ]
  20801. }
  20802. ],
  20803. italic: [
  20804. {
  20805. inline: "em",
  20806. remove: "all",
  20807. preserve_attributes: [
  20808. "class",
  20809. "style"
  20810. ]
  20811. },
  20812. {
  20813. inline: "span",
  20814. styles: { fontStyle: "italic" }
  20815. },
  20816. {
  20817. inline: "i",
  20818. remove: "all",
  20819. preserve_attributes: [
  20820. "class",
  20821. "style"
  20822. ]
  20823. }
  20824. ],
  20825. underline: [
  20826. {
  20827. inline: "span",
  20828. styles: { textDecoration: "underline" },
  20829. exact: true
  20830. },
  20831. {
  20832. inline: "u",
  20833. remove: "all",
  20834. preserve_attributes: [
  20835. "class",
  20836. "style"
  20837. ]
  20838. }
  20839. ],
  20840. strikethrough: [
  20841. {
  20842. inline: "span",
  20843. styles: { textDecoration: "line-through" },
  20844. exact: true
  20845. },
  20846. {
  20847. inline: "strike",
  20848. remove: "all",
  20849. preserve_attributes: [
  20850. "class",
  20851. "style"
  20852. ]
  20853. },
  20854. {
  20855. inline: "s",
  20856. remove: "all",
  20857. preserve_attributes: [
  20858. "class",
  20859. "style"
  20860. ]
  20861. }
  20862. ],
  20863. forecolor: {
  20864. inline: "span",
  20865. styles: { color: "%value" },
  20866. links: true,
  20867. remove_similar: true,
  20868. clear_child_styles: true
  20869. },
  20870. hilitecolor: {
  20871. inline: "span",
  20872. styles: { backgroundColor: "%value" },
  20873. links: true,
  20874. remove_similar: true,
  20875. clear_child_styles: true
  20876. },
  20877. fontname: {
  20878. inline: "span",
  20879. toggle: false,
  20880. styles: { fontFamily: "%value" },
  20881. clear_child_styles: true
  20882. },
  20883. fontsize: {
  20884. inline: "span",
  20885. toggle: false,
  20886. styles: { fontSize: "%value" },
  20887. clear_child_styles: true
  20888. },
  20889. lineheight: {
  20890. selector: "h1,h2,h3,h4,h5,h6,p,li,td,th,div",
  20891. defaultBlock: "p",
  20892. styles: { lineHeight: "%value" }
  20893. },
  20894. fontsize_class: {
  20895. inline: "span",
  20896. attributes: { class: "%value" }
  20897. },
  20898. blockquote: {
  20899. block: "blockquote",
  20900. wrapper: true,
  20901. remove: "all"
  20902. },
  20903. subscript: { inline: "sub" },
  20904. superscript: { inline: "sup" },
  20905. code: { inline: "code" },
  20906. link: {
  20907. inline: "a",
  20908. selector: "a",
  20909. remove: "all",
  20910. split: true,
  20911. deep: true,
  20912. onmatch: function(node, _fmt, _itemName) {
  20913. return isElement$5(node) && node.hasAttribute("href");
  20914. },
  20915. onformat: function(elm, _fmt, vars) {
  20916. Tools.each(vars, function(value2, key) {
  20917. dom2.setAttrib(elm, key, value2);
  20918. });
  20919. }
  20920. },
  20921. lang: {
  20922. inline: "span",
  20923. clear_child_styles: true,
  20924. remove_similar: true,
  20925. attributes: {
  20926. "lang": "%value",
  20927. "data-mce-lang": function(vars) {
  20928. var _a;
  20929. return (_a = vars === null || vars === void 0 ? void 0 : vars.customValue) !== null && _a !== void 0 ? _a : null;
  20930. }
  20931. }
  20932. },
  20933. removeformat: [
  20934. {
  20935. selector: "b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,small",
  20936. remove: "all",
  20937. split: true,
  20938. expand: false,
  20939. block_expand: true,
  20940. deep: true
  20941. },
  20942. {
  20943. selector: "span",
  20944. attributes: [
  20945. "style",
  20946. "class"
  20947. ],
  20948. remove: "empty",
  20949. split: true,
  20950. expand: false,
  20951. deep: true
  20952. },
  20953. {
  20954. selector: "*",
  20955. attributes: [
  20956. "style",
  20957. "class"
  20958. ],
  20959. split: false,
  20960. expand: false,
  20961. deep: true
  20962. }
  20963. ]
  20964. };
  20965. Tools.each("p h1 h2 h3 h4 h5 h6 div address pre dt dd samp".split(/\s/), function(name2) {
  20966. formats[name2] = {
  20967. block: name2,
  20968. remove: "all"
  20969. };
  20970. });
  20971. return formats;
  20972. };
  20973. var FormatRegistry = function(editor) {
  20974. var formats = {};
  20975. var get$12 = function(name2) {
  20976. return isNonNullable(name2) ? formats[name2] : formats;
  20977. };
  20978. var has2 = function(name2) {
  20979. return has$2(formats, name2);
  20980. };
  20981. var register2 = function(name2, format) {
  20982. if (name2) {
  20983. if (!isString$1(name2)) {
  20984. each$j(name2, function(format2, name3) {
  20985. register2(name3, format2);
  20986. });
  20987. } else {
  20988. if (!isArray$1(format)) {
  20989. format = [format];
  20990. }
  20991. each$k(format, function(format2) {
  20992. if (isUndefined(format2.deep)) {
  20993. format2.deep = !isSelectorFormat(format2);
  20994. }
  20995. if (isUndefined(format2.split)) {
  20996. format2.split = !isSelectorFormat(format2) || isInlineFormat(format2);
  20997. }
  20998. if (isUndefined(format2.remove) && isSelectorFormat(format2) && !isInlineFormat(format2)) {
  20999. format2.remove = "none";
  21000. }
  21001. if (isSelectorFormat(format2) && isInlineFormat(format2)) {
  21002. format2.mixed = true;
  21003. format2.block_expand = true;
  21004. }
  21005. if (isString$1(format2.classes)) {
  21006. format2.classes = format2.classes.split(/\s+/);
  21007. }
  21008. });
  21009. formats[name2] = format;
  21010. }
  21011. }
  21012. };
  21013. var unregister = function(name2) {
  21014. if (name2 && formats[name2]) {
  21015. delete formats[name2];
  21016. }
  21017. return formats;
  21018. };
  21019. register2(get(editor.dom));
  21020. register2(getFormats(editor));
  21021. return {
  21022. get: get$12,
  21023. has: has2,
  21024. register: register2,
  21025. unregister
  21026. };
  21027. };
  21028. var each$5 = Tools.each;
  21029. var dom = DOMUtils.DOM;
  21030. var parsedSelectorToHtml = function(ancestry, editor) {
  21031. var elm, item, fragment;
  21032. var schema = editor && editor.schema || Schema({});
  21033. var decorate = function(elm2, item2) {
  21034. if (item2.classes.length) {
  21035. dom.addClass(elm2, item2.classes.join(" "));
  21036. }
  21037. dom.setAttribs(elm2, item2.attrs);
  21038. };
  21039. var createElement = function(sItem) {
  21040. item = typeof sItem === "string" ? {
  21041. name: sItem,
  21042. classes: [],
  21043. attrs: {}
  21044. } : sItem;
  21045. var elm2 = dom.create(item.name);
  21046. decorate(elm2, item);
  21047. return elm2;
  21048. };
  21049. var getRequiredParent = function(elm2, candidate) {
  21050. var name2 = typeof elm2 !== "string" ? elm2.nodeName.toLowerCase() : elm2;
  21051. var elmRule = schema.getElementRule(name2);
  21052. var parentsRequired = elmRule && elmRule.parentsRequired;
  21053. if (parentsRequired && parentsRequired.length) {
  21054. return candidate && Tools.inArray(parentsRequired, candidate) !== -1 ? candidate : parentsRequired[0];
  21055. } else {
  21056. return false;
  21057. }
  21058. };
  21059. var wrapInHtml = function(elm2, ancestry2, siblings2) {
  21060. var parent2, parentCandidate;
  21061. var ancestor2 = ancestry2.length > 0 && ancestry2[0];
  21062. var ancestorName = ancestor2 && ancestor2.name;
  21063. var parentRequired = getRequiredParent(elm2, ancestorName);
  21064. if (parentRequired) {
  21065. if (ancestorName === parentRequired) {
  21066. parentCandidate = ancestry2[0];
  21067. ancestry2 = ancestry2.slice(1);
  21068. } else {
  21069. parentCandidate = parentRequired;
  21070. }
  21071. } else if (ancestor2) {
  21072. parentCandidate = ancestry2[0];
  21073. ancestry2 = ancestry2.slice(1);
  21074. } else if (!siblings2) {
  21075. return elm2;
  21076. }
  21077. if (parentCandidate) {
  21078. parent2 = createElement(parentCandidate);
  21079. parent2.appendChild(elm2);
  21080. }
  21081. if (siblings2) {
  21082. if (!parent2) {
  21083. parent2 = dom.create("div");
  21084. parent2.appendChild(elm2);
  21085. }
  21086. Tools.each(siblings2, function(sibling2) {
  21087. var siblingElm = createElement(sibling2);
  21088. parent2.insertBefore(siblingElm, elm2);
  21089. });
  21090. }
  21091. return wrapInHtml(parent2, ancestry2, parentCandidate && parentCandidate.siblings);
  21092. };
  21093. if (ancestry && ancestry.length) {
  21094. item = ancestry[0];
  21095. elm = createElement(item);
  21096. fragment = dom.create("div");
  21097. fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings));
  21098. return fragment;
  21099. } else {
  21100. return "";
  21101. }
  21102. };
  21103. var parseSelectorItem = function(item) {
  21104. var tagName;
  21105. var obj = {
  21106. classes: [],
  21107. attrs: {}
  21108. };
  21109. item = obj.selector = Tools.trim(item);
  21110. if (item !== "*") {
  21111. tagName = item.replace(/(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g, function($0, $1, $2, $3, $4) {
  21112. switch ($1) {
  21113. case "#":
  21114. obj.attrs.id = $2;
  21115. break;
  21116. case ".":
  21117. obj.classes.push($2);
  21118. break;
  21119. case ":":
  21120. if (Tools.inArray("checked disabled enabled read-only required".split(" "), $2) !== -1) {
  21121. obj.attrs[$2] = $2;
  21122. }
  21123. break;
  21124. }
  21125. if ($3 === "[") {
  21126. var m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/);
  21127. if (m) {
  21128. obj.attrs[m[1]] = m[2];
  21129. }
  21130. }
  21131. return "";
  21132. });
  21133. }
  21134. obj.name = tagName || "div";
  21135. return obj;
  21136. };
  21137. var parseSelector = function(selector) {
  21138. if (!selector || typeof selector !== "string") {
  21139. return [];
  21140. }
  21141. selector = selector.split(/\s*,\s*/)[0];
  21142. selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, "$1");
  21143. return Tools.map(selector.split(/(?:>|\s+(?![^\[\]]+\]))/), function(item) {
  21144. var siblings2 = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem);
  21145. var obj = siblings2.pop();
  21146. if (siblings2.length) {
  21147. obj.siblings = siblings2;
  21148. }
  21149. return obj;
  21150. }).reverse();
  21151. };
  21152. var getCssText = function(editor, format) {
  21153. var name2, previewFrag;
  21154. var previewCss = "", parentFontSize;
  21155. var previewStyles = getPreviewStyles(editor);
  21156. if (previewStyles === "") {
  21157. return "";
  21158. }
  21159. var removeVars = function(val) {
  21160. return val.replace(/%(\w+)/g, "");
  21161. };
  21162. if (typeof format === "string") {
  21163. format = editor.formatter.get(format);
  21164. if (!format) {
  21165. return;
  21166. }
  21167. format = format[0];
  21168. }
  21169. if ("preview" in format) {
  21170. var previewOpt = get$9(format, "preview");
  21171. if (is$1(previewOpt, false)) {
  21172. return "";
  21173. } else {
  21174. previewStyles = previewOpt.getOr(previewStyles);
  21175. }
  21176. }
  21177. name2 = format.block || format.inline || "span";
  21178. var items = parseSelector(format.selector);
  21179. if (items.length) {
  21180. if (!items[0].name) {
  21181. items[0].name = name2;
  21182. }
  21183. name2 = format.selector;
  21184. previewFrag = parsedSelectorToHtml(items, editor);
  21185. } else {
  21186. previewFrag = parsedSelectorToHtml([name2], editor);
  21187. }
  21188. var previewElm = dom.select(name2, previewFrag)[0] || previewFrag.firstChild;
  21189. each$5(format.styles, function(value2, name3) {
  21190. var newValue = removeVars(value2);
  21191. if (newValue) {
  21192. dom.setStyle(previewElm, name3, newValue);
  21193. }
  21194. });
  21195. each$5(format.attributes, function(value2, name3) {
  21196. var newValue = removeVars(value2);
  21197. if (newValue) {
  21198. dom.setAttrib(previewElm, name3, newValue);
  21199. }
  21200. });
  21201. each$5(format.classes, function(value2) {
  21202. var newValue = removeVars(value2);
  21203. if (!dom.hasClass(previewElm, newValue)) {
  21204. dom.addClass(previewElm, newValue);
  21205. }
  21206. });
  21207. editor.fire("PreviewFormats");
  21208. dom.setStyles(previewFrag, {
  21209. position: "absolute",
  21210. left: -65535
  21211. });
  21212. editor.getBody().appendChild(previewFrag);
  21213. parentFontSize = dom.getStyle(editor.getBody(), "fontSize", true);
  21214. parentFontSize = /px$/.test(parentFontSize) ? parseInt(parentFontSize, 10) : 0;
  21215. each$5(previewStyles.split(" "), function(name3) {
  21216. var value2 = dom.getStyle(previewElm, name3, true);
  21217. if (name3 === "background-color" && /transparent|rgba\s*\([^)]+,\s*0\)/.test(value2)) {
  21218. value2 = dom.getStyle(editor.getBody(), name3, true);
  21219. if (dom.toHex(value2).toLowerCase() === "#ffffff") {
  21220. return;
  21221. }
  21222. }
  21223. if (name3 === "color") {
  21224. if (dom.toHex(value2).toLowerCase() === "#000000") {
  21225. return;
  21226. }
  21227. }
  21228. if (name3 === "font-size") {
  21229. if (/em|%$/.test(value2)) {
  21230. if (parentFontSize === 0) {
  21231. return;
  21232. }
  21233. var numValue = parseFloat(value2) / (/%$/.test(value2) ? 100 : 1);
  21234. value2 = numValue * parentFontSize + "px";
  21235. }
  21236. }
  21237. if (name3 === "border" && value2) {
  21238. previewCss += "padding:0 2px;";
  21239. }
  21240. previewCss += name3 + ":" + value2 + ";";
  21241. });
  21242. editor.fire("AfterPreviewFormats");
  21243. dom.remove(previewFrag);
  21244. return previewCss;
  21245. };
  21246. var setup$h = function(editor) {
  21247. editor.addShortcut("meta+b", "", "Bold");
  21248. editor.addShortcut("meta+i", "", "Italic");
  21249. editor.addShortcut("meta+u", "", "Underline");
  21250. for (var i = 1; i <= 6; i++) {
  21251. editor.addShortcut("access+" + i, "", [
  21252. "FormatBlock",
  21253. false,
  21254. "h" + i
  21255. ]);
  21256. }
  21257. editor.addShortcut("access+7", "", [
  21258. "FormatBlock",
  21259. false,
  21260. "p"
  21261. ]);
  21262. editor.addShortcut("access+8", "", [
  21263. "FormatBlock",
  21264. false,
  21265. "div"
  21266. ]);
  21267. editor.addShortcut("access+9", "", [
  21268. "FormatBlock",
  21269. false,
  21270. "address"
  21271. ]);
  21272. };
  21273. var Formatter = function(editor) {
  21274. var formats = FormatRegistry(editor);
  21275. var formatChangeState = Cell(null);
  21276. setup$h(editor);
  21277. setup$k(editor);
  21278. return {
  21279. get: formats.get,
  21280. has: formats.has,
  21281. register: formats.register,
  21282. unregister: formats.unregister,
  21283. apply: function(name2, vars, node) {
  21284. applyFormat(editor, name2, vars, node);
  21285. },
  21286. remove: function(name2, vars, node, similar) {
  21287. removeFormat(editor, name2, vars, node, similar);
  21288. },
  21289. toggle: function(name2, vars, node) {
  21290. toggleFormat(editor, name2, vars, node);
  21291. },
  21292. match: function(name2, vars, node, similar) {
  21293. return matchFormat(editor, name2, vars, node, similar);
  21294. },
  21295. closest: function(names) {
  21296. return closestFormat(editor, names);
  21297. },
  21298. matchAll: function(names, vars) {
  21299. return matchAllFormats(editor, names, vars);
  21300. },
  21301. matchNode: function(node, name2, vars, similar) {
  21302. return matchNodeFormat(editor, node, name2, vars, similar);
  21303. },
  21304. canApply: function(name2) {
  21305. return canApplyFormat(editor, name2);
  21306. },
  21307. formatChanged: function(formats2, callback, similar, vars) {
  21308. return formatChanged(editor, formatChangeState, formats2, callback, similar, vars);
  21309. },
  21310. getCssText: curry(getCssText, editor)
  21311. };
  21312. };
  21313. var shouldIgnoreCommand = function(cmd) {
  21314. switch (cmd.toLowerCase()) {
  21315. case "undo":
  21316. case "redo":
  21317. case "mcerepaint":
  21318. case "mcefocus":
  21319. return true;
  21320. default:
  21321. return false;
  21322. }
  21323. };
  21324. var registerEvents = function(editor, undoManager, locks) {
  21325. var isFirstTypedCharacter = Cell(false);
  21326. var addNonTypingUndoLevel = function(e) {
  21327. setTyping(undoManager, false, locks);
  21328. undoManager.add({}, e);
  21329. };
  21330. editor.on("init", function() {
  21331. undoManager.add();
  21332. });
  21333. editor.on("BeforeExecCommand", function(e) {
  21334. var cmd = e.command;
  21335. if (!shouldIgnoreCommand(cmd)) {
  21336. endTyping(undoManager, locks);
  21337. undoManager.beforeChange();
  21338. }
  21339. });
  21340. editor.on("ExecCommand", function(e) {
  21341. var cmd = e.command;
  21342. if (!shouldIgnoreCommand(cmd)) {
  21343. addNonTypingUndoLevel(e);
  21344. }
  21345. });
  21346. editor.on("ObjectResizeStart cut", function() {
  21347. undoManager.beforeChange();
  21348. });
  21349. editor.on("SaveContent ObjectResized blur", addNonTypingUndoLevel);
  21350. editor.on("dragend", addNonTypingUndoLevel);
  21351. editor.on("keyup", function(e) {
  21352. var keyCode = e.keyCode;
  21353. if (e.isDefaultPrevented()) {
  21354. return;
  21355. }
  21356. if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45 || e.ctrlKey) {
  21357. addNonTypingUndoLevel();
  21358. editor.nodeChanged();
  21359. }
  21360. if (keyCode === 46 || keyCode === 8) {
  21361. editor.nodeChanged();
  21362. }
  21363. if (isFirstTypedCharacter.get() && undoManager.typing && isEq$1(createFromEditor(editor), undoManager.data[0]) === false) {
  21364. if (editor.isDirty() === false) {
  21365. editor.setDirty(true);
  21366. editor.fire("change", {
  21367. level: undoManager.data[0],
  21368. lastLevel: null
  21369. });
  21370. }
  21371. editor.fire("TypingUndo");
  21372. isFirstTypedCharacter.set(false);
  21373. editor.nodeChanged();
  21374. }
  21375. });
  21376. editor.on("keydown", function(e) {
  21377. var keyCode = e.keyCode;
  21378. if (e.isDefaultPrevented()) {
  21379. return;
  21380. }
  21381. if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45) {
  21382. if (undoManager.typing) {
  21383. addNonTypingUndoLevel(e);
  21384. }
  21385. return;
  21386. }
  21387. var modKey = e.ctrlKey && !e.altKey || e.metaKey;
  21388. if ((keyCode < 16 || keyCode > 20) && keyCode !== 224 && keyCode !== 91 && !undoManager.typing && !modKey) {
  21389. undoManager.beforeChange();
  21390. setTyping(undoManager, true, locks);
  21391. undoManager.add({}, e);
  21392. isFirstTypedCharacter.set(true);
  21393. }
  21394. });
  21395. editor.on("mousedown", function(e) {
  21396. if (undoManager.typing) {
  21397. addNonTypingUndoLevel(e);
  21398. }
  21399. });
  21400. var isInsertReplacementText = function(event) {
  21401. return event.inputType === "insertReplacementText";
  21402. };
  21403. var isInsertTextDataNull = function(event) {
  21404. return event.inputType === "insertText" && event.data === null;
  21405. };
  21406. var isInsertFromPasteOrDrop = function(event) {
  21407. return event.inputType === "insertFromPaste" || event.inputType === "insertFromDrop";
  21408. };
  21409. editor.on("input", function(e) {
  21410. if (e.inputType && (isInsertReplacementText(e) || isInsertTextDataNull(e) || isInsertFromPasteOrDrop(e))) {
  21411. addNonTypingUndoLevel(e);
  21412. }
  21413. });
  21414. editor.on("AddUndo Undo Redo ClearUndos", function(e) {
  21415. if (!e.isDefaultPrevented()) {
  21416. editor.nodeChanged();
  21417. }
  21418. });
  21419. };
  21420. var addKeyboardShortcuts = function(editor) {
  21421. editor.addShortcut("meta+z", "", "Undo");
  21422. editor.addShortcut("meta+y,meta+shift+z", "", "Redo");
  21423. };
  21424. var UndoManager = function(editor) {
  21425. var beforeBookmark = value();
  21426. var locks = Cell(0);
  21427. var index = Cell(0);
  21428. var undoManager = {
  21429. data: [],
  21430. typing: false,
  21431. beforeChange: function() {
  21432. beforeChange(editor, locks, beforeBookmark);
  21433. },
  21434. add: function(level, event) {
  21435. return addUndoLevel(editor, undoManager, index, locks, beforeBookmark, level, event);
  21436. },
  21437. undo: function() {
  21438. return undo(editor, undoManager, locks, index);
  21439. },
  21440. redo: function() {
  21441. return redo(editor, index, undoManager.data);
  21442. },
  21443. clear: function() {
  21444. clear(editor, undoManager, index);
  21445. },
  21446. reset: function() {
  21447. reset(editor, undoManager);
  21448. },
  21449. hasUndo: function() {
  21450. return hasUndo(editor, undoManager, index);
  21451. },
  21452. hasRedo: function() {
  21453. return hasRedo(editor, undoManager, index);
  21454. },
  21455. transact: function(callback) {
  21456. return transact(editor, undoManager, locks, callback);
  21457. },
  21458. ignore: function(callback) {
  21459. ignore(editor, locks, callback);
  21460. },
  21461. extra: function(callback1, callback2) {
  21462. extra(editor, undoManager, index, callback1, callback2);
  21463. }
  21464. };
  21465. if (!isRtc(editor)) {
  21466. registerEvents(editor, undoManager, locks);
  21467. }
  21468. addKeyboardShortcuts(editor);
  21469. return undoManager;
  21470. };
  21471. var nonTypingKeycodes = [
  21472. 9,
  21473. 27,
  21474. VK.HOME,
  21475. VK.END,
  21476. 19,
  21477. 20,
  21478. 44,
  21479. 144,
  21480. 145,
  21481. 33,
  21482. 34,
  21483. 45,
  21484. 16,
  21485. 17,
  21486. 18,
  21487. 91,
  21488. 92,
  21489. 93,
  21490. VK.DOWN,
  21491. VK.UP,
  21492. VK.LEFT,
  21493. VK.RIGHT
  21494. ].concat(Env.browser.isFirefox() ? [224] : []);
  21495. var placeholderAttr = "data-mce-placeholder";
  21496. var isKeyboardEvent = function(e) {
  21497. return e.type === "keydown" || e.type === "keyup";
  21498. };
  21499. var isDeleteEvent = function(e) {
  21500. var keyCode = e.keyCode;
  21501. return keyCode === VK.BACKSPACE || keyCode === VK.DELETE;
  21502. };
  21503. var isNonTypingKeyboardEvent = function(e) {
  21504. if (isKeyboardEvent(e)) {
  21505. var keyCode = e.keyCode;
  21506. return !isDeleteEvent(e) && (VK.metaKeyPressed(e) || e.altKey || keyCode >= 112 && keyCode <= 123 || contains$3(nonTypingKeycodes, keyCode));
  21507. } else {
  21508. return false;
  21509. }
  21510. };
  21511. var isTypingKeyboardEvent = function(e) {
  21512. return isKeyboardEvent(e) && !(isDeleteEvent(e) || e.type === "keyup" && e.keyCode === 229);
  21513. };
  21514. var isVisuallyEmpty = function(dom2, rootElm, forcedRootBlock) {
  21515. if (isEmpty$2(SugarElement.fromDom(rootElm), false)) {
  21516. var isForcedRootBlockFalse = forcedRootBlock === "";
  21517. var firstElement2 = rootElm.firstElementChild;
  21518. if (!firstElement2) {
  21519. return true;
  21520. } else if (dom2.getStyle(rootElm.firstElementChild, "padding-left") || dom2.getStyle(rootElm.firstElementChild, "padding-right")) {
  21521. return false;
  21522. } else {
  21523. return isForcedRootBlockFalse ? !dom2.isBlock(firstElement2) : forcedRootBlock === firstElement2.nodeName.toLowerCase();
  21524. }
  21525. } else {
  21526. return false;
  21527. }
  21528. };
  21529. var setup$g = function(editor) {
  21530. var dom2 = editor.dom;
  21531. var rootBlock = getForcedRootBlock(editor);
  21532. var placeholder = getPlaceholder(editor);
  21533. var updatePlaceholder = function(e, initial) {
  21534. if (isNonTypingKeyboardEvent(e)) {
  21535. return;
  21536. }
  21537. var body = editor.getBody();
  21538. var showPlaceholder = isTypingKeyboardEvent(e) ? false : isVisuallyEmpty(dom2, body, rootBlock);
  21539. var isPlaceholderShown = dom2.getAttrib(body, placeholderAttr) !== "";
  21540. if (isPlaceholderShown !== showPlaceholder || initial) {
  21541. dom2.setAttrib(body, placeholderAttr, showPlaceholder ? placeholder : null);
  21542. dom2.setAttrib(body, "aria-placeholder", showPlaceholder ? placeholder : null);
  21543. firePlaceholderToggle(editor, showPlaceholder);
  21544. editor.on(showPlaceholder ? "keydown" : "keyup", updatePlaceholder);
  21545. editor.off(showPlaceholder ? "keyup" : "keydown", updatePlaceholder);
  21546. }
  21547. };
  21548. if (placeholder) {
  21549. editor.on("init", function(e) {
  21550. updatePlaceholder(e, true);
  21551. editor.on("change SetContent ExecCommand", updatePlaceholder);
  21552. editor.on("paste", function(e2) {
  21553. return Delay.setEditorTimeout(editor, function() {
  21554. return updatePlaceholder(e2);
  21555. });
  21556. });
  21557. });
  21558. }
  21559. };
  21560. var strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/;
  21561. var hasStrongRtl = function(text) {
  21562. return strongRtl.test(text);
  21563. };
  21564. var isInlineTarget = function(editor, elm) {
  21565. return is$2(SugarElement.fromDom(elm), getInlineBoundarySelector(editor));
  21566. };
  21567. var isRtl = function(element) {
  21568. return DOMUtils.DOM.getStyle(element, "direction", true) === "rtl" || hasStrongRtl(element.textContent);
  21569. };
  21570. var findInlineParents = function(isInlineTarget2, rootNode, pos) {
  21571. return filter$4(DOMUtils.DOM.getParents(pos.container(), "*", rootNode), isInlineTarget2);
  21572. };
  21573. var findRootInline = function(isInlineTarget2, rootNode, pos) {
  21574. var parents2 = findInlineParents(isInlineTarget2, rootNode, pos);
  21575. return Optional.from(parents2[parents2.length - 1]);
  21576. };
  21577. var hasSameParentBlock = function(rootNode, node1, node2) {
  21578. var block1 = getParentBlock$2(node1, rootNode);
  21579. var block2 = getParentBlock$2(node2, rootNode);
  21580. return block1 && block1 === block2;
  21581. };
  21582. var isAtZwsp = function(pos) {
  21583. return isBeforeInline(pos) || isAfterInline(pos);
  21584. };
  21585. var normalizePosition = function(forward, pos) {
  21586. if (!pos) {
  21587. return pos;
  21588. }
  21589. var container = pos.container(), offset = pos.offset();
  21590. if (forward) {
  21591. if (isCaretContainerInline(container)) {
  21592. if (isText$7(container.nextSibling)) {
  21593. return CaretPosition(container.nextSibling, 0);
  21594. } else {
  21595. return CaretPosition.after(container);
  21596. }
  21597. } else {
  21598. return isBeforeInline(pos) ? CaretPosition(container, offset + 1) : pos;
  21599. }
  21600. } else {
  21601. if (isCaretContainerInline(container)) {
  21602. if (isText$7(container.previousSibling)) {
  21603. return CaretPosition(container.previousSibling, container.previousSibling.data.length);
  21604. } else {
  21605. return CaretPosition.before(container);
  21606. }
  21607. } else {
  21608. return isAfterInline(pos) ? CaretPosition(container, offset - 1) : pos;
  21609. }
  21610. }
  21611. };
  21612. var normalizeForwards = curry(normalizePosition, true);
  21613. var normalizeBackwards = curry(normalizePosition, false);
  21614. var isBeforeRoot = function(rootNode) {
  21615. return function(elm) {
  21616. return eq(rootNode, SugarElement.fromDom(elm.dom.parentNode));
  21617. };
  21618. };
  21619. var isTextBlockOrListItem = function(element) {
  21620. return isTextBlock$2(element) || isListItem(element);
  21621. };
  21622. var getParentBlock$1 = function(rootNode, elm) {
  21623. if (contains$1(rootNode, elm)) {
  21624. return closest$3(elm, isTextBlockOrListItem, isBeforeRoot(rootNode));
  21625. } else {
  21626. return Optional.none();
  21627. }
  21628. };
  21629. var placeCaretInEmptyBody = function(editor) {
  21630. var body = editor.getBody();
  21631. var node = body.firstChild && editor.dom.isBlock(body.firstChild) ? body.firstChild : body;
  21632. editor.selection.setCursorLocation(node, 0);
  21633. };
  21634. var paddEmptyBody = function(editor) {
  21635. if (editor.dom.isEmpty(editor.getBody())) {
  21636. editor.setContent("");
  21637. placeCaretInEmptyBody(editor);
  21638. }
  21639. };
  21640. var willDeleteLastPositionInElement = function(forward, fromPos, elm) {
  21641. return lift2(firstPositionIn(elm), lastPositionIn(elm), function(firstPos, lastPos) {
  21642. var normalizedFirstPos = normalizePosition(true, firstPos);
  21643. var normalizedLastPos = normalizePosition(false, lastPos);
  21644. var normalizedFromPos = normalizePosition(false, fromPos);
  21645. if (forward) {
  21646. return nextPosition(elm, normalizedFromPos).exists(function(nextPos) {
  21647. return nextPos.isEqual(normalizedLastPos) && fromPos.isEqual(normalizedFirstPos);
  21648. });
  21649. } else {
  21650. return prevPosition(elm, normalizedFromPos).exists(function(prevPos) {
  21651. return prevPos.isEqual(normalizedFirstPos) && fromPos.isEqual(normalizedLastPos);
  21652. });
  21653. }
  21654. }).getOr(true);
  21655. };
  21656. var blockPosition = function(block, position) {
  21657. return {
  21658. block,
  21659. position
  21660. };
  21661. };
  21662. var blockBoundary = function(from2, to2) {
  21663. return {
  21664. from: from2,
  21665. to: to2
  21666. };
  21667. };
  21668. var getBlockPosition = function(rootNode, pos) {
  21669. var rootElm = SugarElement.fromDom(rootNode);
  21670. var containerElm = SugarElement.fromDom(pos.container());
  21671. return getParentBlock$1(rootElm, containerElm).map(function(block) {
  21672. return blockPosition(block, pos);
  21673. });
  21674. };
  21675. var isDifferentBlocks = function(blockBoundary2) {
  21676. return eq(blockBoundary2.from.block, blockBoundary2.to.block) === false;
  21677. };
  21678. var hasSameParent = function(blockBoundary2) {
  21679. return parent(blockBoundary2.from.block).bind(function(parent1) {
  21680. return parent(blockBoundary2.to.block).filter(function(parent2) {
  21681. return eq(parent1, parent2);
  21682. });
  21683. }).isSome();
  21684. };
  21685. var isEditable$1 = function(blockBoundary2) {
  21686. return isContentEditableFalse$b(blockBoundary2.from.block.dom) === false && isContentEditableFalse$b(blockBoundary2.to.block.dom) === false;
  21687. };
  21688. var skipLastBr = function(rootNode, forward, blockPosition2) {
  21689. if (isBr$5(blockPosition2.position.getNode()) && isEmpty$2(blockPosition2.block) === false) {
  21690. return positionIn(false, blockPosition2.block.dom).bind(function(lastPositionInBlock) {
  21691. if (lastPositionInBlock.isEqual(blockPosition2.position)) {
  21692. return fromPosition(forward, rootNode, lastPositionInBlock).bind(function(to2) {
  21693. return getBlockPosition(rootNode, to2);
  21694. });
  21695. } else {
  21696. return Optional.some(blockPosition2);
  21697. }
  21698. }).getOr(blockPosition2);
  21699. } else {
  21700. return blockPosition2;
  21701. }
  21702. };
  21703. var readFromRange = function(rootNode, forward, rng) {
  21704. var fromBlockPos = getBlockPosition(rootNode, CaretPosition.fromRangeStart(rng));
  21705. var toBlockPos = fromBlockPos.bind(function(blockPos) {
  21706. return fromPosition(forward, rootNode, blockPos.position).bind(function(to2) {
  21707. return getBlockPosition(rootNode, to2).map(function(blockPos2) {
  21708. return skipLastBr(rootNode, forward, blockPos2);
  21709. });
  21710. });
  21711. });
  21712. return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(function(blockBoundary2) {
  21713. return isDifferentBlocks(blockBoundary2) && hasSameParent(blockBoundary2) && isEditable$1(blockBoundary2);
  21714. });
  21715. };
  21716. var read$1 = function(rootNode, forward, rng) {
  21717. return rng.collapsed ? readFromRange(rootNode, forward, rng) : Optional.none();
  21718. };
  21719. var getChildrenUntilBlockBoundary = function(block) {
  21720. var children$1 = children(block);
  21721. return findIndex$2(children$1, isBlock$2).fold(constant(children$1), function(index) {
  21722. return children$1.slice(0, index);
  21723. });
  21724. };
  21725. var extractChildren = function(block) {
  21726. var children2 = getChildrenUntilBlockBoundary(block);
  21727. each$k(children2, remove$7);
  21728. return children2;
  21729. };
  21730. var removeEmptyRoot = function(rootNode, block) {
  21731. var parents2 = parentsAndSelf(block, rootNode);
  21732. return find$3(parents2.reverse(), function(element) {
  21733. return isEmpty$2(element);
  21734. }).each(remove$7);
  21735. };
  21736. var isEmptyBefore = function(el) {
  21737. return filter$4(prevSiblings(el), function(el2) {
  21738. return !isEmpty$2(el2);
  21739. }).length === 0;
  21740. };
  21741. var nestedBlockMerge = function(rootNode, fromBlock, toBlock, insertionPoint) {
  21742. if (isEmpty$2(toBlock)) {
  21743. fillWithPaddingBr(toBlock);
  21744. return firstPositionIn(toBlock.dom);
  21745. }
  21746. if (isEmptyBefore(insertionPoint) && isEmpty$2(fromBlock)) {
  21747. before$4(insertionPoint, SugarElement.fromTag("br"));
  21748. }
  21749. var position = prevPosition(toBlock.dom, CaretPosition.before(insertionPoint.dom));
  21750. each$k(extractChildren(fromBlock), function(child2) {
  21751. before$4(insertionPoint, child2);
  21752. });
  21753. removeEmptyRoot(rootNode, fromBlock);
  21754. return position;
  21755. };
  21756. var sidelongBlockMerge = function(rootNode, fromBlock, toBlock) {
  21757. if (isEmpty$2(toBlock)) {
  21758. remove$7(toBlock);
  21759. if (isEmpty$2(fromBlock)) {
  21760. fillWithPaddingBr(fromBlock);
  21761. }
  21762. return firstPositionIn(fromBlock.dom);
  21763. }
  21764. var position = lastPositionIn(toBlock.dom);
  21765. each$k(extractChildren(fromBlock), function(child2) {
  21766. append$1(toBlock, child2);
  21767. });
  21768. removeEmptyRoot(rootNode, fromBlock);
  21769. return position;
  21770. };
  21771. var findInsertionPoint = function(toBlock, block) {
  21772. var parentsAndSelf$1 = parentsAndSelf(block, toBlock);
  21773. return Optional.from(parentsAndSelf$1[parentsAndSelf$1.length - 1]);
  21774. };
  21775. var getInsertionPoint = function(fromBlock, toBlock) {
  21776. return contains$1(toBlock, fromBlock) ? findInsertionPoint(toBlock, fromBlock) : Optional.none();
  21777. };
  21778. var trimBr = function(first2, block) {
  21779. positionIn(first2, block.dom).map(function(position) {
  21780. return position.getNode();
  21781. }).map(SugarElement.fromDom).filter(isBr$4).each(remove$7);
  21782. };
  21783. var mergeBlockInto = function(rootNode, fromBlock, toBlock) {
  21784. trimBr(true, fromBlock);
  21785. trimBr(false, toBlock);
  21786. return getInsertionPoint(fromBlock, toBlock).fold(curry(sidelongBlockMerge, rootNode, fromBlock, toBlock), curry(nestedBlockMerge, rootNode, fromBlock, toBlock));
  21787. };
  21788. var mergeBlocks = function(rootNode, forward, block1, block2) {
  21789. return forward ? mergeBlockInto(rootNode, block2, block1) : mergeBlockInto(rootNode, block1, block2);
  21790. };
  21791. var backspaceDelete$8 = function(editor, forward) {
  21792. var rootNode = SugarElement.fromDom(editor.getBody());
  21793. var position = read$1(rootNode.dom, forward, editor.selection.getRng()).bind(function(blockBoundary2) {
  21794. return mergeBlocks(rootNode, forward, blockBoundary2.from.block, blockBoundary2.to.block);
  21795. });
  21796. position.each(function(pos) {
  21797. editor.selection.setRng(pos.toRange());
  21798. });
  21799. return position.isSome();
  21800. };
  21801. var deleteRangeMergeBlocks = function(rootNode, selection) {
  21802. var rng = selection.getRng();
  21803. return lift2(getParentBlock$1(rootNode, SugarElement.fromDom(rng.startContainer)), getParentBlock$1(rootNode, SugarElement.fromDom(rng.endContainer)), function(block1, block2) {
  21804. if (eq(block1, block2) === false) {
  21805. rng.deleteContents();
  21806. mergeBlocks(rootNode, true, block1, block2).each(function(pos) {
  21807. selection.setRng(pos.toRange());
  21808. });
  21809. return true;
  21810. } else {
  21811. return false;
  21812. }
  21813. }).getOr(false);
  21814. };
  21815. var isRawNodeInTable = function(root, rawNode) {
  21816. var node = SugarElement.fromDom(rawNode);
  21817. var isRoot = curry(eq, root);
  21818. return ancestor$3(node, isTableCell$4, isRoot).isSome();
  21819. };
  21820. var isSelectionInTable = function(root, rng) {
  21821. return isRawNodeInTable(root, rng.startContainer) || isRawNodeInTable(root, rng.endContainer);
  21822. };
  21823. var isEverythingSelected = function(root, rng) {
  21824. var noPrevious = prevPosition(root.dom, CaretPosition.fromRangeStart(rng)).isNone();
  21825. var noNext = nextPosition(root.dom, CaretPosition.fromRangeEnd(rng)).isNone();
  21826. return !isSelectionInTable(root, rng) && noPrevious && noNext;
  21827. };
  21828. var emptyEditor = function(editor) {
  21829. editor.setContent("");
  21830. editor.selection.setCursorLocation();
  21831. return true;
  21832. };
  21833. var deleteRange$1 = function(editor) {
  21834. var rootNode = SugarElement.fromDom(editor.getBody());
  21835. var rng = editor.selection.getRng();
  21836. return isEverythingSelected(rootNode, rng) ? emptyEditor(editor) : deleteRangeMergeBlocks(rootNode, editor.selection);
  21837. };
  21838. var backspaceDelete$7 = function(editor, _forward) {
  21839. return editor.selection.isCollapsed() ? false : deleteRange$1(editor);
  21840. };
  21841. var isContentEditableTrue$2 = isContentEditableTrue$4;
  21842. var isContentEditableFalse$4 = isContentEditableFalse$b;
  21843. var showCaret = function(direction, editor, node, before2, scrollIntoView) {
  21844. return Optional.from(editor._selectionOverrides.showCaret(direction, node, before2, scrollIntoView));
  21845. };
  21846. var getNodeRange = function(node) {
  21847. var rng = node.ownerDocument.createRange();
  21848. rng.selectNode(node);
  21849. return rng;
  21850. };
  21851. var selectNode = function(editor, node) {
  21852. var e = editor.fire("BeforeObjectSelected", { target: node });
  21853. if (e.isDefaultPrevented()) {
  21854. return Optional.none();
  21855. }
  21856. return Optional.some(getNodeRange(node));
  21857. };
  21858. var renderCaretAtRange = function(editor, range2, scrollIntoView) {
  21859. var normalizedRange = normalizeRange(1, editor.getBody(), range2);
  21860. var caretPosition = CaretPosition.fromRangeStart(normalizedRange);
  21861. var caretPositionNode = caretPosition.getNode();
  21862. if (isInlineFakeCaretTarget(caretPositionNode)) {
  21863. return showCaret(1, editor, caretPositionNode, !caretPosition.isAtEnd(), false);
  21864. }
  21865. var caretPositionBeforeNode = caretPosition.getNode(true);
  21866. if (isInlineFakeCaretTarget(caretPositionBeforeNode)) {
  21867. return showCaret(1, editor, caretPositionBeforeNode, false, false);
  21868. }
  21869. var ceRoot = editor.dom.getParent(caretPosition.getNode(), function(node) {
  21870. return isContentEditableFalse$4(node) || isContentEditableTrue$2(node);
  21871. });
  21872. if (isInlineFakeCaretTarget(ceRoot)) {
  21873. return showCaret(1, editor, ceRoot, false, scrollIntoView);
  21874. }
  21875. return Optional.none();
  21876. };
  21877. var renderRangeCaret = function(editor, range2, scrollIntoView) {
  21878. return range2.collapsed ? renderCaretAtRange(editor, range2, scrollIntoView).getOr(range2) : range2;
  21879. };
  21880. var isBeforeBoundary = function(pos) {
  21881. return isBeforeContentEditableFalse(pos) || isBeforeMedia(pos);
  21882. };
  21883. var isAfterBoundary = function(pos) {
  21884. return isAfterContentEditableFalse(pos) || isAfterMedia(pos);
  21885. };
  21886. var trimEmptyTextNode = function(dom2, node) {
  21887. if (isText$7(node) && node.data.length === 0) {
  21888. dom2.remove(node);
  21889. }
  21890. };
  21891. var deleteContentAndShowCaret = function(editor, range2, node, direction, forward, peekCaretPosition) {
  21892. showCaret(direction, editor, peekCaretPosition.getNode(!forward), forward, true).each(function(caretRange) {
  21893. if (range2.collapsed) {
  21894. var deleteRange2 = range2.cloneRange();
  21895. if (forward) {
  21896. deleteRange2.setEnd(caretRange.startContainer, caretRange.startOffset);
  21897. } else {
  21898. deleteRange2.setStart(caretRange.endContainer, caretRange.endOffset);
  21899. }
  21900. deleteRange2.deleteContents();
  21901. } else {
  21902. range2.deleteContents();
  21903. }
  21904. editor.selection.setRng(caretRange);
  21905. });
  21906. trimEmptyTextNode(editor.dom, node);
  21907. return true;
  21908. };
  21909. var deleteBoundaryText = function(editor, forward) {
  21910. var range2 = editor.selection.getRng();
  21911. if (!isText$7(range2.commonAncestorContainer)) {
  21912. return false;
  21913. }
  21914. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  21915. var caretWalker = CaretWalker(editor.getBody());
  21916. var getNextPosFn = curry(getVisualCaretPosition, forward ? caretWalker.next : caretWalker.prev);
  21917. var isBeforeFn = forward ? isBeforeBoundary : isAfterBoundary;
  21918. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range2);
  21919. var nextCaretPosition = normalizePosition(forward, getNextPosFn(caretPosition));
  21920. if (!nextCaretPosition || !isMoveInsideSameBlock(caretPosition, nextCaretPosition)) {
  21921. return false;
  21922. } else if (isBeforeFn(nextCaretPosition)) {
  21923. return deleteContentAndShowCaret(editor, range2, caretPosition.getNode(), direction, forward, nextCaretPosition);
  21924. }
  21925. var peekCaretPosition = getNextPosFn(nextCaretPosition);
  21926. if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
  21927. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  21928. return deleteContentAndShowCaret(editor, range2, caretPosition.getNode(), direction, forward, peekCaretPosition);
  21929. }
  21930. }
  21931. return false;
  21932. };
  21933. var backspaceDelete$6 = function(editor, forward) {
  21934. return deleteBoundaryText(editor, forward);
  21935. };
  21936. var isCompoundElement = function(node) {
  21937. return isTableCell$4(SugarElement.fromDom(node)) || isListItem(SugarElement.fromDom(node));
  21938. };
  21939. var DeleteAction = Adt.generate([
  21940. { remove: ["element"] },
  21941. { moveToElement: ["element"] },
  21942. { moveToPosition: ["position"] }
  21943. ]);
  21944. var isAtContentEditableBlockCaret = function(forward, from2) {
  21945. var elm = from2.getNode(forward === false);
  21946. var caretLocation = forward ? "after" : "before";
  21947. return isElement$5(elm) && elm.getAttribute("data-mce-caret") === caretLocation;
  21948. };
  21949. var isDeleteFromCefDifferentBlocks = function(root, forward, from2, to2) {
  21950. var inSameBlock = function(elm) {
  21951. return isInline$1(SugarElement.fromDom(elm)) && !isInSameBlock(from2, to2, root);
  21952. };
  21953. return getRelativeCefElm(!forward, from2).fold(function() {
  21954. return getRelativeCefElm(forward, to2).fold(never, inSameBlock);
  21955. }, inSameBlock);
  21956. };
  21957. var deleteEmptyBlockOrMoveToCef = function(root, forward, from2, to2) {
  21958. var toCefElm = to2.getNode(forward === false);
  21959. return getParentBlock$1(SugarElement.fromDom(root), SugarElement.fromDom(from2.getNode())).map(function(blockElm) {
  21960. return isEmpty$2(blockElm) ? DeleteAction.remove(blockElm.dom) : DeleteAction.moveToElement(toCefElm);
  21961. }).orThunk(function() {
  21962. return Optional.some(DeleteAction.moveToElement(toCefElm));
  21963. });
  21964. };
  21965. var findCefPosition = function(root, forward, from2) {
  21966. return fromPosition(forward, root, from2).bind(function(to2) {
  21967. if (isCompoundElement(to2.getNode())) {
  21968. return Optional.none();
  21969. } else if (isDeleteFromCefDifferentBlocks(root, forward, from2, to2)) {
  21970. return Optional.none();
  21971. } else if (forward && isContentEditableFalse$b(to2.getNode())) {
  21972. return deleteEmptyBlockOrMoveToCef(root, forward, from2, to2);
  21973. } else if (forward === false && isContentEditableFalse$b(to2.getNode(true))) {
  21974. return deleteEmptyBlockOrMoveToCef(root, forward, from2, to2);
  21975. } else if (forward && isAfterContentEditableFalse(from2)) {
  21976. return Optional.some(DeleteAction.moveToPosition(to2));
  21977. } else if (forward === false && isBeforeContentEditableFalse(from2)) {
  21978. return Optional.some(DeleteAction.moveToPosition(to2));
  21979. } else {
  21980. return Optional.none();
  21981. }
  21982. });
  21983. };
  21984. var getContentEditableBlockAction = function(forward, elm) {
  21985. if (forward && isContentEditableFalse$b(elm.nextSibling)) {
  21986. return Optional.some(DeleteAction.moveToElement(elm.nextSibling));
  21987. } else if (forward === false && isContentEditableFalse$b(elm.previousSibling)) {
  21988. return Optional.some(DeleteAction.moveToElement(elm.previousSibling));
  21989. } else {
  21990. return Optional.none();
  21991. }
  21992. };
  21993. var skipMoveToActionFromInlineCefToContent = function(root, from2, deleteAction2) {
  21994. return deleteAction2.fold(function(elm) {
  21995. return Optional.some(DeleteAction.remove(elm));
  21996. }, function(elm) {
  21997. return Optional.some(DeleteAction.moveToElement(elm));
  21998. }, function(to2) {
  21999. if (isInSameBlock(from2, to2, root)) {
  22000. return Optional.none();
  22001. } else {
  22002. return Optional.some(DeleteAction.moveToPosition(to2));
  22003. }
  22004. });
  22005. };
  22006. var getContentEditableAction = function(root, forward, from2) {
  22007. if (isAtContentEditableBlockCaret(forward, from2)) {
  22008. return getContentEditableBlockAction(forward, from2.getNode(forward === false)).fold(function() {
  22009. return findCefPosition(root, forward, from2);
  22010. }, Optional.some);
  22011. } else {
  22012. return findCefPosition(root, forward, from2).bind(function(deleteAction2) {
  22013. return skipMoveToActionFromInlineCefToContent(root, from2, deleteAction2);
  22014. });
  22015. }
  22016. };
  22017. var read = function(root, forward, rng) {
  22018. var normalizedRange = normalizeRange(forward ? 1 : -1, root, rng);
  22019. var from2 = CaretPosition.fromRangeStart(normalizedRange);
  22020. var rootElement = SugarElement.fromDom(root);
  22021. if (forward === false && isAfterContentEditableFalse(from2)) {
  22022. return Optional.some(DeleteAction.remove(from2.getNode(true)));
  22023. } else if (forward && isBeforeContentEditableFalse(from2)) {
  22024. return Optional.some(DeleteAction.remove(from2.getNode()));
  22025. } else if (forward === false && isBeforeContentEditableFalse(from2) && isAfterBr(rootElement, from2)) {
  22026. return findPreviousBr(rootElement, from2).map(function(br) {
  22027. return DeleteAction.remove(br.getNode());
  22028. });
  22029. } else if (forward && isAfterContentEditableFalse(from2) && isBeforeBr$1(rootElement, from2)) {
  22030. return findNextBr(rootElement, from2).map(function(br) {
  22031. return DeleteAction.remove(br.getNode());
  22032. });
  22033. } else {
  22034. return getContentEditableAction(root, forward, from2);
  22035. }
  22036. };
  22037. var deleteElement$1 = function(editor, forward) {
  22038. return function(element) {
  22039. editor._selectionOverrides.hideFakeCaret();
  22040. deleteElement$2(editor, forward, SugarElement.fromDom(element));
  22041. return true;
  22042. };
  22043. };
  22044. var moveToElement = function(editor, forward) {
  22045. return function(element) {
  22046. var pos = forward ? CaretPosition.before(element) : CaretPosition.after(element);
  22047. editor.selection.setRng(pos.toRange());
  22048. return true;
  22049. };
  22050. };
  22051. var moveToPosition = function(editor) {
  22052. return function(pos) {
  22053. editor.selection.setRng(pos.toRange());
  22054. return true;
  22055. };
  22056. };
  22057. var getAncestorCe = function(editor, node) {
  22058. return Optional.from(getContentEditableRoot$1(editor.getBody(), node));
  22059. };
  22060. var backspaceDeleteCaret = function(editor, forward) {
  22061. var selectedNode = editor.selection.getNode();
  22062. return getAncestorCe(editor, selectedNode).filter(isContentEditableFalse$b).fold(function() {
  22063. return read(editor.getBody(), forward, editor.selection.getRng()).exists(function(deleteAction2) {
  22064. return deleteAction2.fold(deleteElement$1(editor, forward), moveToElement(editor, forward), moveToPosition(editor));
  22065. });
  22066. }, always);
  22067. };
  22068. var deleteOffscreenSelection = function(rootElement) {
  22069. each$k(descendants(rootElement, ".mce-offscreen-selection"), remove$7);
  22070. };
  22071. var backspaceDeleteRange = function(editor, forward) {
  22072. var selectedNode = editor.selection.getNode();
  22073. if (isContentEditableFalse$b(selectedNode) && !isTableCell$5(selectedNode)) {
  22074. var hasCefAncestor = getAncestorCe(editor, selectedNode.parentNode).filter(isContentEditableFalse$b);
  22075. return hasCefAncestor.fold(function() {
  22076. deleteOffscreenSelection(SugarElement.fromDom(editor.getBody()));
  22077. deleteElement$2(editor, forward, SugarElement.fromDom(editor.selection.getNode()));
  22078. paddEmptyBody(editor);
  22079. return true;
  22080. }, always);
  22081. }
  22082. return false;
  22083. };
  22084. var paddEmptyElement = function(editor) {
  22085. var dom2 = editor.dom, selection = editor.selection;
  22086. var ceRoot = getContentEditableRoot$1(editor.getBody(), selection.getNode());
  22087. if (isContentEditableTrue$4(ceRoot) && dom2.isBlock(ceRoot) && dom2.isEmpty(ceRoot)) {
  22088. var br = dom2.create("br", { "data-mce-bogus": "1" });
  22089. dom2.setHTML(ceRoot, "");
  22090. ceRoot.appendChild(br);
  22091. selection.setRng(CaretPosition.before(br).toRange());
  22092. }
  22093. return true;
  22094. };
  22095. var backspaceDelete$5 = function(editor, forward) {
  22096. if (editor.selection.isCollapsed()) {
  22097. return backspaceDeleteCaret(editor, forward);
  22098. } else {
  22099. return backspaceDeleteRange(editor, forward);
  22100. }
  22101. };
  22102. var deleteCaret$2 = function(editor, forward) {
  22103. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
  22104. return fromPosition(forward, editor.getBody(), fromPos).filter(function(pos) {
  22105. return forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos);
  22106. }).bind(function(pos) {
  22107. return Optional.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, pos));
  22108. }).exists(function(elm) {
  22109. editor.selection.select(elm);
  22110. return true;
  22111. });
  22112. };
  22113. var backspaceDelete$4 = function(editor, forward) {
  22114. return editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : false;
  22115. };
  22116. var isText = isText$7;
  22117. var startsWithCaretContainer = function(node) {
  22118. return isText(node) && node.data[0] === ZWSP$1;
  22119. };
  22120. var endsWithCaretContainer = function(node) {
  22121. return isText(node) && node.data[node.data.length - 1] === ZWSP$1;
  22122. };
  22123. var createZwsp = function(node) {
  22124. return node.ownerDocument.createTextNode(ZWSP$1);
  22125. };
  22126. var insertBefore = function(node) {
  22127. if (isText(node.previousSibling)) {
  22128. if (endsWithCaretContainer(node.previousSibling)) {
  22129. return node.previousSibling;
  22130. } else {
  22131. node.previousSibling.appendData(ZWSP$1);
  22132. return node.previousSibling;
  22133. }
  22134. } else if (isText(node)) {
  22135. if (startsWithCaretContainer(node)) {
  22136. return node;
  22137. } else {
  22138. node.insertData(0, ZWSP$1);
  22139. return node;
  22140. }
  22141. } else {
  22142. var newNode = createZwsp(node);
  22143. node.parentNode.insertBefore(newNode, node);
  22144. return newNode;
  22145. }
  22146. };
  22147. var insertAfter = function(node) {
  22148. if (isText(node.nextSibling)) {
  22149. if (startsWithCaretContainer(node.nextSibling)) {
  22150. return node.nextSibling;
  22151. } else {
  22152. node.nextSibling.insertData(0, ZWSP$1);
  22153. return node.nextSibling;
  22154. }
  22155. } else if (isText(node)) {
  22156. if (endsWithCaretContainer(node)) {
  22157. return node;
  22158. } else {
  22159. node.appendData(ZWSP$1);
  22160. return node;
  22161. }
  22162. } else {
  22163. var newNode = createZwsp(node);
  22164. if (node.nextSibling) {
  22165. node.parentNode.insertBefore(newNode, node.nextSibling);
  22166. } else {
  22167. node.parentNode.appendChild(newNode);
  22168. }
  22169. return newNode;
  22170. }
  22171. };
  22172. var insertInline = function(before2, node) {
  22173. return before2 ? insertBefore(node) : insertAfter(node);
  22174. };
  22175. var insertInlineBefore = curry(insertInline, true);
  22176. var insertInlineAfter = curry(insertInline, false);
  22177. var insertInlinePos = function(pos, before2) {
  22178. if (isText$7(pos.container())) {
  22179. return insertInline(before2, pos.container());
  22180. } else {
  22181. return insertInline(before2, pos.getNode());
  22182. }
  22183. };
  22184. var isPosCaretContainer = function(pos, caret) {
  22185. var caretNode = caret.get();
  22186. return caretNode && pos.container() === caretNode && isCaretContainerInline(caretNode);
  22187. };
  22188. var renderCaret = function(caret, location) {
  22189. return location.fold(function(element) {
  22190. remove$2(caret.get());
  22191. var text = insertInlineBefore(element);
  22192. caret.set(text);
  22193. return Optional.some(CaretPosition(text, text.length - 1));
  22194. }, function(element) {
  22195. return firstPositionIn(element).map(function(pos) {
  22196. if (!isPosCaretContainer(pos, caret)) {
  22197. remove$2(caret.get());
  22198. var text = insertInlinePos(pos, true);
  22199. caret.set(text);
  22200. return CaretPosition(text, 1);
  22201. } else {
  22202. return CaretPosition(caret.get(), 1);
  22203. }
  22204. });
  22205. }, function(element) {
  22206. return lastPositionIn(element).map(function(pos) {
  22207. if (!isPosCaretContainer(pos, caret)) {
  22208. remove$2(caret.get());
  22209. var text = insertInlinePos(pos, false);
  22210. caret.set(text);
  22211. return CaretPosition(text, text.length - 1);
  22212. } else {
  22213. return CaretPosition(caret.get(), caret.get().length - 1);
  22214. }
  22215. });
  22216. }, function(element) {
  22217. remove$2(caret.get());
  22218. var text = insertInlineAfter(element);
  22219. caret.set(text);
  22220. return Optional.some(CaretPosition(text, 1));
  22221. });
  22222. };
  22223. var evaluateUntil = function(fns, args) {
  22224. for (var i = 0; i < fns.length; i++) {
  22225. var result = fns[i].apply(null, args);
  22226. if (result.isSome()) {
  22227. return result;
  22228. }
  22229. }
  22230. return Optional.none();
  22231. };
  22232. var Location = Adt.generate([
  22233. { before: ["element"] },
  22234. { start: ["element"] },
  22235. { end: ["element"] },
  22236. { after: ["element"] }
  22237. ]);
  22238. var rescope$1 = function(rootNode, node) {
  22239. var parentBlock = getParentBlock$2(node, rootNode);
  22240. return parentBlock ? parentBlock : rootNode;
  22241. };
  22242. var before = function(isInlineTarget2, rootNode, pos) {
  22243. var nPos = normalizeForwards(pos);
  22244. var scope = rescope$1(rootNode, nPos.container());
  22245. return findRootInline(isInlineTarget2, scope, nPos).fold(function() {
  22246. return nextPosition(scope, nPos).bind(curry(findRootInline, isInlineTarget2, scope)).map(function(inline) {
  22247. return Location.before(inline);
  22248. });
  22249. }, Optional.none);
  22250. };
  22251. var isNotInsideFormatCaretContainer = function(rootNode, elm) {
  22252. return getParentCaretContainer(rootNode, elm) === null;
  22253. };
  22254. var findInsideRootInline = function(isInlineTarget2, rootNode, pos) {
  22255. return findRootInline(isInlineTarget2, rootNode, pos).filter(curry(isNotInsideFormatCaretContainer, rootNode));
  22256. };
  22257. var start$1 = function(isInlineTarget2, rootNode, pos) {
  22258. var nPos = normalizeBackwards(pos);
  22259. return findInsideRootInline(isInlineTarget2, rootNode, nPos).bind(function(inline) {
  22260. var prevPos = prevPosition(inline, nPos);
  22261. return prevPos.isNone() ? Optional.some(Location.start(inline)) : Optional.none();
  22262. });
  22263. };
  22264. var end = function(isInlineTarget2, rootNode, pos) {
  22265. var nPos = normalizeForwards(pos);
  22266. return findInsideRootInline(isInlineTarget2, rootNode, nPos).bind(function(inline) {
  22267. var nextPos = nextPosition(inline, nPos);
  22268. return nextPos.isNone() ? Optional.some(Location.end(inline)) : Optional.none();
  22269. });
  22270. };
  22271. var after = function(isInlineTarget2, rootNode, pos) {
  22272. var nPos = normalizeBackwards(pos);
  22273. var scope = rescope$1(rootNode, nPos.container());
  22274. return findRootInline(isInlineTarget2, scope, nPos).fold(function() {
  22275. return prevPosition(scope, nPos).bind(curry(findRootInline, isInlineTarget2, scope)).map(function(inline) {
  22276. return Location.after(inline);
  22277. });
  22278. }, Optional.none);
  22279. };
  22280. var isValidLocation = function(location) {
  22281. return isRtl(getElement(location)) === false;
  22282. };
  22283. var readLocation = function(isInlineTarget2, rootNode, pos) {
  22284. var location = evaluateUntil([
  22285. before,
  22286. start$1,
  22287. end,
  22288. after
  22289. ], [
  22290. isInlineTarget2,
  22291. rootNode,
  22292. pos
  22293. ]);
  22294. return location.filter(isValidLocation);
  22295. };
  22296. var getElement = function(location) {
  22297. return location.fold(identity, identity, identity, identity);
  22298. };
  22299. var getName = function(location) {
  22300. return location.fold(constant("before"), constant("start"), constant("end"), constant("after"));
  22301. };
  22302. var outside = function(location) {
  22303. return location.fold(Location.before, Location.before, Location.after, Location.after);
  22304. };
  22305. var inside = function(location) {
  22306. return location.fold(Location.start, Location.start, Location.end, Location.end);
  22307. };
  22308. var isEq = function(location1, location2) {
  22309. return getName(location1) === getName(location2) && getElement(location1) === getElement(location2);
  22310. };
  22311. var betweenInlines = function(forward, isInlineTarget2, rootNode, from2, to2, location) {
  22312. return lift2(findRootInline(isInlineTarget2, rootNode, from2), findRootInline(isInlineTarget2, rootNode, to2), function(fromInline, toInline) {
  22313. if (fromInline !== toInline && hasSameParentBlock(rootNode, fromInline, toInline)) {
  22314. return Location.after(forward ? fromInline : toInline);
  22315. } else {
  22316. return location;
  22317. }
  22318. }).getOr(location);
  22319. };
  22320. var skipNoMovement = function(fromLocation, toLocation) {
  22321. return fromLocation.fold(always, function(fromLocation2) {
  22322. return !isEq(fromLocation2, toLocation);
  22323. });
  22324. };
  22325. var findLocationTraverse = function(forward, isInlineTarget2, rootNode, fromLocation, pos) {
  22326. var from2 = normalizePosition(forward, pos);
  22327. var to2 = fromPosition(forward, rootNode, from2).map(curry(normalizePosition, forward));
  22328. var location = to2.fold(function() {
  22329. return fromLocation.map(outside);
  22330. }, function(to3) {
  22331. return readLocation(isInlineTarget2, rootNode, to3).map(curry(betweenInlines, forward, isInlineTarget2, rootNode, from2, to3)).filter(curry(skipNoMovement, fromLocation));
  22332. });
  22333. return location.filter(isValidLocation);
  22334. };
  22335. var findLocationSimple = function(forward, location) {
  22336. if (forward) {
  22337. return location.fold(compose(Optional.some, Location.start), Optional.none, compose(Optional.some, Location.after), Optional.none);
  22338. } else {
  22339. return location.fold(Optional.none, compose(Optional.some, Location.before), Optional.none, compose(Optional.some, Location.end));
  22340. }
  22341. };
  22342. var findLocation$1 = function(forward, isInlineTarget2, rootNode, pos) {
  22343. var from2 = normalizePosition(forward, pos);
  22344. var fromLocation = readLocation(isInlineTarget2, rootNode, from2);
  22345. return readLocation(isInlineTarget2, rootNode, from2).bind(curry(findLocationSimple, forward)).orThunk(function() {
  22346. return findLocationTraverse(forward, isInlineTarget2, rootNode, fromLocation, pos);
  22347. });
  22348. };
  22349. curry(findLocation$1, false);
  22350. curry(findLocation$1, true);
  22351. var hasSelectionModifyApi = function(editor) {
  22352. return isFunction(editor.selection.getSel().modify);
  22353. };
  22354. var moveRel = function(forward, selection, pos) {
  22355. var delta = forward ? 1 : -1;
  22356. selection.setRng(CaretPosition(pos.container(), pos.offset() + delta).toRange());
  22357. selection.getSel().modify("move", forward ? "forward" : "backward", "word");
  22358. return true;
  22359. };
  22360. var moveByWord = function(forward, editor) {
  22361. var rng = editor.selection.getRng();
  22362. var pos = forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng);
  22363. if (!hasSelectionModifyApi(editor)) {
  22364. return false;
  22365. } else if (forward && isBeforeInline(pos)) {
  22366. return moveRel(true, editor.selection, pos);
  22367. } else if (!forward && isAfterInline(pos)) {
  22368. return moveRel(false, editor.selection, pos);
  22369. } else {
  22370. return false;
  22371. }
  22372. };
  22373. var BreakType;
  22374. (function(BreakType2) {
  22375. BreakType2[BreakType2["Br"] = 0] = "Br";
  22376. BreakType2[BreakType2["Block"] = 1] = "Block";
  22377. BreakType2[BreakType2["Wrap"] = 2] = "Wrap";
  22378. BreakType2[BreakType2["Eol"] = 3] = "Eol";
  22379. })(BreakType || (BreakType = {}));
  22380. var flip = function(direction, positions) {
  22381. return direction === HDirection.Backwards ? reverse(positions) : positions;
  22382. };
  22383. var walk = function(direction, caretWalker, pos) {
  22384. return direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos);
  22385. };
  22386. var getBreakType = function(scope, direction, currentPos, nextPos) {
  22387. if (isBr$5(nextPos.getNode(direction === HDirection.Forwards))) {
  22388. return BreakType.Br;
  22389. } else if (isInSameBlock(currentPos, nextPos) === false) {
  22390. return BreakType.Block;
  22391. } else {
  22392. return BreakType.Wrap;
  22393. }
  22394. };
  22395. var getPositionsUntil = function(predicate, direction, scope, start2) {
  22396. var caretWalker = CaretWalker(scope);
  22397. var currentPos = start2;
  22398. var positions = [];
  22399. while (currentPos) {
  22400. var nextPos = walk(direction, caretWalker, currentPos);
  22401. if (!nextPos) {
  22402. break;
  22403. }
  22404. if (isBr$5(nextPos.getNode(false))) {
  22405. if (direction === HDirection.Forwards) {
  22406. return {
  22407. positions: flip(direction, positions).concat([nextPos]),
  22408. breakType: BreakType.Br,
  22409. breakAt: Optional.some(nextPos)
  22410. };
  22411. } else {
  22412. return {
  22413. positions: flip(direction, positions),
  22414. breakType: BreakType.Br,
  22415. breakAt: Optional.some(nextPos)
  22416. };
  22417. }
  22418. }
  22419. if (!nextPos.isVisible()) {
  22420. currentPos = nextPos;
  22421. continue;
  22422. }
  22423. if (predicate(currentPos, nextPos)) {
  22424. var breakType = getBreakType(scope, direction, currentPos, nextPos);
  22425. return {
  22426. positions: flip(direction, positions),
  22427. breakType,
  22428. breakAt: Optional.some(nextPos)
  22429. };
  22430. }
  22431. positions.push(nextPos);
  22432. currentPos = nextPos;
  22433. }
  22434. return {
  22435. positions: flip(direction, positions),
  22436. breakType: BreakType.Eol,
  22437. breakAt: Optional.none()
  22438. };
  22439. };
  22440. var getAdjacentLinePositions = function(direction, getPositionsUntilBreak, scope, start2) {
  22441. return getPositionsUntilBreak(scope, start2).breakAt.map(function(pos) {
  22442. var positions = getPositionsUntilBreak(scope, pos).positions;
  22443. return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions);
  22444. }).getOr([]);
  22445. };
  22446. var findClosestHorizontalPositionFromPoint = function(positions, x) {
  22447. return foldl(positions, function(acc, newPos) {
  22448. return acc.fold(function() {
  22449. return Optional.some(newPos);
  22450. }, function(lastPos) {
  22451. return lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), function(lastRect, newRect) {
  22452. var lastDist = Math.abs(x - lastRect.left);
  22453. var newDist = Math.abs(x - newRect.left);
  22454. return newDist <= lastDist ? newPos : lastPos;
  22455. }).or(acc);
  22456. });
  22457. }, Optional.none());
  22458. };
  22459. var findClosestHorizontalPosition = function(positions, pos) {
  22460. return head(pos.getClientRects()).bind(function(targetRect) {
  22461. return findClosestHorizontalPositionFromPoint(positions, targetRect.left);
  22462. });
  22463. };
  22464. var getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1);
  22465. var getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1);
  22466. var getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine);
  22467. var getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine);
  22468. var isAtFirstLine = function(scope, pos) {
  22469. return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone();
  22470. };
  22471. var isAtLastLine = function(scope, pos) {
  22472. return getPositionsUntilNextLine(scope, pos).breakAt.isNone();
  22473. };
  22474. var getFirstLinePositions = function(scope) {
  22475. return firstPositionIn(scope).map(function(pos) {
  22476. return [pos].concat(getPositionsUntilNextLine(scope, pos).positions);
  22477. }).getOr([]);
  22478. };
  22479. var getLastLinePositions = function(scope) {
  22480. return lastPositionIn(scope).map(function(pos) {
  22481. return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos);
  22482. }).getOr([]);
  22483. };
  22484. var getNodeClientRects = function(node) {
  22485. var toArrayWithNode = function(clientRects) {
  22486. return map$3(clientRects, function(rect) {
  22487. var clientRect = clone(rect);
  22488. clientRect.node = node;
  22489. return clientRect;
  22490. });
  22491. };
  22492. if (isElement$5(node)) {
  22493. return toArrayWithNode(node.getClientRects());
  22494. }
  22495. if (isText$7(node)) {
  22496. var rng = node.ownerDocument.createRange();
  22497. rng.setStart(node, 0);
  22498. rng.setEnd(node, node.data.length);
  22499. return toArrayWithNode(rng.getClientRects());
  22500. }
  22501. };
  22502. var getClientRects = function(nodes) {
  22503. return bind(nodes, getNodeClientRects);
  22504. };
  22505. var VDirection;
  22506. (function(VDirection2) {
  22507. VDirection2[VDirection2["Up"] = -1] = "Up";
  22508. VDirection2[VDirection2["Down"] = 1] = "Down";
  22509. })(VDirection || (VDirection = {}));
  22510. var findUntil = function(direction, root, predicateFn, node) {
  22511. while (node = findNode$1(node, direction, isEditableCaretCandidate$1, root)) {
  22512. if (predicateFn(node)) {
  22513. return;
  22514. }
  22515. }
  22516. };
  22517. var walkUntil$1 = function(direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) {
  22518. var line = 0;
  22519. var result = [];
  22520. var add2 = function(node2) {
  22521. var clientRects = getClientRects([node2]);
  22522. if (direction === -1) {
  22523. clientRects = clientRects.reverse();
  22524. }
  22525. for (var i = 0; i < clientRects.length; i++) {
  22526. var clientRect = clientRects[i];
  22527. if (isBeflowFn(clientRect, targetClientRect)) {
  22528. continue;
  22529. }
  22530. if (result.length > 0 && isAboveFn(clientRect, last$1(result))) {
  22531. line++;
  22532. }
  22533. clientRect.line = line;
  22534. if (predicateFn(clientRect)) {
  22535. return true;
  22536. }
  22537. result.push(clientRect);
  22538. }
  22539. };
  22540. var targetClientRect = last$1(caretPosition.getClientRects());
  22541. if (!targetClientRect) {
  22542. return result;
  22543. }
  22544. var node = caretPosition.getNode();
  22545. add2(node);
  22546. findUntil(direction, root, add2, node);
  22547. return result;
  22548. };
  22549. var aboveLineNumber = function(lineNumber, clientRect) {
  22550. return clientRect.line > lineNumber;
  22551. };
  22552. var isLineNumber = function(lineNumber, clientRect) {
  22553. return clientRect.line === lineNumber;
  22554. };
  22555. var upUntil = curry(walkUntil$1, VDirection.Up, isAbove$1, isBelow$1);
  22556. var downUntil = curry(walkUntil$1, VDirection.Down, isBelow$1, isAbove$1);
  22557. var positionsUntil = function(direction, root, predicateFn, node) {
  22558. var caretWalker = CaretWalker(root);
  22559. var walkFn;
  22560. var isBelowFn;
  22561. var isAboveFn;
  22562. var caretPosition;
  22563. var result = [];
  22564. var line = 0;
  22565. var getClientRect = function(caretPosition2) {
  22566. if (direction === 1) {
  22567. return last$1(caretPosition2.getClientRects());
  22568. }
  22569. return last$1(caretPosition2.getClientRects());
  22570. };
  22571. if (direction === 1) {
  22572. walkFn = caretWalker.next;
  22573. isBelowFn = isBelow$1;
  22574. isAboveFn = isAbove$1;
  22575. caretPosition = CaretPosition.after(node);
  22576. } else {
  22577. walkFn = caretWalker.prev;
  22578. isBelowFn = isAbove$1;
  22579. isAboveFn = isBelow$1;
  22580. caretPosition = CaretPosition.before(node);
  22581. }
  22582. var targetClientRect = getClientRect(caretPosition);
  22583. do {
  22584. if (!caretPosition.isVisible()) {
  22585. continue;
  22586. }
  22587. var rect = getClientRect(caretPosition);
  22588. if (isAboveFn(rect, targetClientRect)) {
  22589. continue;
  22590. }
  22591. if (result.length > 0 && isBelowFn(rect, last$1(result))) {
  22592. line++;
  22593. }
  22594. var clientRect = clone(rect);
  22595. clientRect.position = caretPosition;
  22596. clientRect.line = line;
  22597. if (predicateFn(clientRect)) {
  22598. return result;
  22599. }
  22600. result.push(clientRect);
  22601. } while (caretPosition = walkFn(caretPosition));
  22602. return result;
  22603. };
  22604. var isAboveLine = function(lineNumber) {
  22605. return function(clientRect) {
  22606. return aboveLineNumber(lineNumber, clientRect);
  22607. };
  22608. };
  22609. var isLine = function(lineNumber) {
  22610. return function(clientRect) {
  22611. return isLineNumber(lineNumber, clientRect);
  22612. };
  22613. };
  22614. var isContentEditableFalse$3 = isContentEditableFalse$b;
  22615. var findNode = findNode$1;
  22616. var distanceToRectLeft = function(clientRect, clientX) {
  22617. return Math.abs(clientRect.left - clientX);
  22618. };
  22619. var distanceToRectRight = function(clientRect, clientX) {
  22620. return Math.abs(clientRect.right - clientX);
  22621. };
  22622. var isInsideX = function(clientX, clientRect) {
  22623. return clientX >= clientRect.left && clientX <= clientRect.right;
  22624. };
  22625. var isInsideY = function(clientY, clientRect) {
  22626. return clientY >= clientRect.top && clientY <= clientRect.bottom;
  22627. };
  22628. var isNodeClientRect = function(rect) {
  22629. return hasNonNullableKey(rect, "node");
  22630. };
  22631. var findClosestClientRect = function(clientRects, clientX, allowInside) {
  22632. if (allowInside === void 0) {
  22633. allowInside = always;
  22634. }
  22635. return reduce(clientRects, function(oldClientRect, clientRect) {
  22636. if (isInsideX(clientX, clientRect)) {
  22637. return allowInside(clientRect) ? clientRect : oldClientRect;
  22638. }
  22639. if (isInsideX(clientX, oldClientRect)) {
  22640. return allowInside(oldClientRect) ? oldClientRect : clientRect;
  22641. }
  22642. var oldDistance = Math.min(distanceToRectLeft(oldClientRect, clientX), distanceToRectRight(oldClientRect, clientX));
  22643. var newDistance = Math.min(distanceToRectLeft(clientRect, clientX), distanceToRectRight(clientRect, clientX));
  22644. if (newDistance === oldDistance && isNodeClientRect(clientRect) && isContentEditableFalse$3(clientRect.node)) {
  22645. return clientRect;
  22646. }
  22647. if (newDistance < oldDistance) {
  22648. return clientRect;
  22649. }
  22650. return oldClientRect;
  22651. });
  22652. };
  22653. var walkUntil = function(direction, root, predicateFn, startNode, includeChildren) {
  22654. var node = findNode(startNode, direction, isEditableCaretCandidate$1, root, !includeChildren);
  22655. do {
  22656. if (!node || predicateFn(node)) {
  22657. return;
  22658. }
  22659. } while (node = findNode(node, direction, isEditableCaretCandidate$1, root));
  22660. };
  22661. var findLineNodeRects = function(root, targetNodeRect, includeChildren) {
  22662. if (includeChildren === void 0) {
  22663. includeChildren = true;
  22664. }
  22665. var clientRects = [];
  22666. var collect = function(checkPosFn, node) {
  22667. var lineRects = filter$4(getClientRects([node]), function(clientRect) {
  22668. return !checkPosFn(clientRect, targetNodeRect);
  22669. });
  22670. clientRects = clientRects.concat(lineRects);
  22671. return lineRects.length === 0;
  22672. };
  22673. clientRects.push(targetNodeRect);
  22674. walkUntil(VDirection.Up, root, curry(collect, isAbove$1), targetNodeRect.node, includeChildren);
  22675. walkUntil(VDirection.Down, root, curry(collect, isBelow$1), targetNodeRect.node, includeChildren);
  22676. return clientRects;
  22677. };
  22678. var getFakeCaretTargets = function(root) {
  22679. return filter$4(from(root.getElementsByTagName("*")), isFakeCaretTarget);
  22680. };
  22681. var caretInfo = function(clientRect, clientX) {
  22682. return {
  22683. node: clientRect.node,
  22684. before: distanceToRectLeft(clientRect, clientX) < distanceToRectRight(clientRect, clientX)
  22685. };
  22686. };
  22687. var closestFakeCaret = function(root, clientX, clientY) {
  22688. var fakeTargetNodeRects = getClientRects(getFakeCaretTargets(root));
  22689. var targetNodeRects = filter$4(fakeTargetNodeRects, curry(isInsideY, clientY));
  22690. var checkInside = function(clientRect) {
  22691. return !isTable$3(clientRect.node) && !isMedia$2(clientRect.node);
  22692. };
  22693. var closestNodeRect = findClosestClientRect(targetNodeRects, clientX, checkInside);
  22694. if (closestNodeRect) {
  22695. var includeChildren = checkInside(closestNodeRect);
  22696. closestNodeRect = findClosestClientRect(findLineNodeRects(root, closestNodeRect, includeChildren), clientX, checkInside);
  22697. if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
  22698. return caretInfo(closestNodeRect, clientX);
  22699. }
  22700. }
  22701. return null;
  22702. };
  22703. var moveToRange = function(editor, rng) {
  22704. editor.selection.setRng(rng);
  22705. scrollRangeIntoView(editor, editor.selection.getRng());
  22706. };
  22707. var renderRangeCaretOpt = function(editor, range2, scrollIntoView) {
  22708. return Optional.some(renderRangeCaret(editor, range2, scrollIntoView));
  22709. };
  22710. var moveHorizontally = function(editor, direction, range2, isBefore, isAfter, isElement2) {
  22711. var forwards = direction === HDirection.Forwards;
  22712. var caretWalker = CaretWalker(editor.getBody());
  22713. var getNextPosFn = curry(getVisualCaretPosition, forwards ? caretWalker.next : caretWalker.prev);
  22714. var isBeforeFn = forwards ? isBefore : isAfter;
  22715. if (!range2.collapsed) {
  22716. var node = getSelectedNode(range2);
  22717. if (isElement2(node)) {
  22718. return showCaret(direction, editor, node, direction === HDirection.Backwards, false);
  22719. }
  22720. }
  22721. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range2);
  22722. if (isBeforeFn(caretPosition)) {
  22723. return selectNode(editor, caretPosition.getNode(!forwards));
  22724. }
  22725. var nextCaretPosition = normalizePosition(forwards, getNextPosFn(caretPosition));
  22726. var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range2);
  22727. if (!nextCaretPosition) {
  22728. return rangeIsInContainerBlock ? Optional.some(range2) : Optional.none();
  22729. }
  22730. if (isBeforeFn(nextCaretPosition)) {
  22731. return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, false);
  22732. }
  22733. var peekCaretPosition = getNextPosFn(nextCaretPosition);
  22734. if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
  22735. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  22736. return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, false);
  22737. }
  22738. }
  22739. if (rangeIsInContainerBlock) {
  22740. return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false);
  22741. }
  22742. return Optional.none();
  22743. };
  22744. var moveVertically = function(editor, direction, range2, isBefore, isAfter, isElement2) {
  22745. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range2);
  22746. var caretClientRect = last$1(caretPosition.getClientRects());
  22747. var forwards = direction === VDirection.Down;
  22748. if (!caretClientRect) {
  22749. return Optional.none();
  22750. }
  22751. var walkerFn = forwards ? downUntil : upUntil;
  22752. var linePositions = walkerFn(editor.getBody(), isAboveLine(1), caretPosition);
  22753. var nextLinePositions = filter$4(linePositions, isLine(1));
  22754. var clientX = caretClientRect.left;
  22755. var nextLineRect = findClosestClientRect(nextLinePositions, clientX);
  22756. if (nextLineRect && isElement2(nextLineRect.node)) {
  22757. var dist1 = Math.abs(clientX - nextLineRect.left);
  22758. var dist2 = Math.abs(clientX - nextLineRect.right);
  22759. return showCaret(direction, editor, nextLineRect.node, dist1 < dist2, false);
  22760. }
  22761. var currentNode;
  22762. if (isBefore(caretPosition)) {
  22763. currentNode = caretPosition.getNode();
  22764. } else if (isAfter(caretPosition)) {
  22765. currentNode = caretPosition.getNode(true);
  22766. } else {
  22767. currentNode = getSelectedNode(range2);
  22768. }
  22769. if (currentNode) {
  22770. var caretPositions = positionsUntil(direction, editor.getBody(), isAboveLine(1), currentNode);
  22771. var closestNextLineRect = findClosestClientRect(filter$4(caretPositions, isLine(1)), clientX);
  22772. if (closestNextLineRect) {
  22773. return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
  22774. }
  22775. closestNextLineRect = last$1(filter$4(caretPositions, isLine(0)));
  22776. if (closestNextLineRect) {
  22777. return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
  22778. }
  22779. }
  22780. if (nextLinePositions.length === 0) {
  22781. return getLineEndPoint(editor, forwards).filter(forwards ? isAfter : isBefore).map(function(pos) {
  22782. return renderRangeCaret(editor, pos.toRange(), false);
  22783. });
  22784. }
  22785. return Optional.none();
  22786. };
  22787. var getLineEndPoint = function(editor, forward) {
  22788. var rng = editor.selection.getRng();
  22789. var body = editor.getBody();
  22790. if (forward) {
  22791. var from2 = CaretPosition.fromRangeEnd(rng);
  22792. var result = getPositionsUntilNextLine(body, from2);
  22793. return last$2(result.positions);
  22794. } else {
  22795. var from2 = CaretPosition.fromRangeStart(rng);
  22796. var result = getPositionsUntilPreviousLine(body, from2);
  22797. return head(result.positions);
  22798. }
  22799. };
  22800. var moveToLineEndPoint$3 = function(editor, forward, isElementPosition) {
  22801. return getLineEndPoint(editor, forward).filter(isElementPosition).exists(function(pos) {
  22802. editor.selection.setRng(pos.toRange());
  22803. return true;
  22804. });
  22805. };
  22806. var setCaretPosition = function(editor, pos) {
  22807. var rng = editor.dom.createRng();
  22808. rng.setStart(pos.container(), pos.offset());
  22809. rng.setEnd(pos.container(), pos.offset());
  22810. editor.selection.setRng(rng);
  22811. };
  22812. var setSelected = function(state, elm) {
  22813. if (state) {
  22814. elm.setAttribute("data-mce-selected", "inline-boundary");
  22815. } else {
  22816. elm.removeAttribute("data-mce-selected");
  22817. }
  22818. };
  22819. var renderCaretLocation = function(editor, caret, location) {
  22820. return renderCaret(caret, location).map(function(pos) {
  22821. setCaretPosition(editor, pos);
  22822. return location;
  22823. });
  22824. };
  22825. var findLocation = function(editor, caret, forward) {
  22826. var rootNode = editor.getBody();
  22827. var from2 = CaretPosition.fromRangeStart(editor.selection.getRng());
  22828. var isInlineTarget$1 = curry(isInlineTarget, editor);
  22829. var location = findLocation$1(forward, isInlineTarget$1, rootNode, from2);
  22830. return location.bind(function(location2) {
  22831. return renderCaretLocation(editor, caret, location2);
  22832. });
  22833. };
  22834. var toggleInlines = function(isInlineTarget2, dom2, elms) {
  22835. var inlineBoundaries = map$3(descendants(SugarElement.fromDom(dom2.getRoot()), '*[data-mce-selected="inline-boundary"]'), function(e) {
  22836. return e.dom;
  22837. });
  22838. var selectedInlines = filter$4(inlineBoundaries, isInlineTarget2);
  22839. var targetInlines = filter$4(elms, isInlineTarget2);
  22840. each$k(difference(selectedInlines, targetInlines), curry(setSelected, false));
  22841. each$k(difference(targetInlines, selectedInlines), curry(setSelected, true));
  22842. };
  22843. var safeRemoveCaretContainer = function(editor, caret) {
  22844. if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) {
  22845. var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
  22846. if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) {
  22847. setCaretPosition(editor, removeAndReposition(caret.get(), pos));
  22848. caret.set(null);
  22849. }
  22850. }
  22851. };
  22852. var renderInsideInlineCaret = function(isInlineTarget2, editor, caret, elms) {
  22853. if (editor.selection.isCollapsed()) {
  22854. var inlines = filter$4(elms, isInlineTarget2);
  22855. each$k(inlines, function(_inline) {
  22856. var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
  22857. readLocation(isInlineTarget2, editor.getBody(), pos).bind(function(location) {
  22858. return renderCaretLocation(editor, caret, location);
  22859. });
  22860. });
  22861. }
  22862. };
  22863. var move$2 = function(editor, caret, forward) {
  22864. return isInlineBoundariesEnabled(editor) ? findLocation(editor, caret, forward).isSome() : false;
  22865. };
  22866. var moveWord = function(forward, editor, _caret) {
  22867. return isInlineBoundariesEnabled(editor) ? moveByWord(forward, editor) : false;
  22868. };
  22869. var setupSelectedState = function(editor) {
  22870. var caret = Cell(null);
  22871. var isInlineTarget$1 = curry(isInlineTarget, editor);
  22872. editor.on("NodeChange", function(e) {
  22873. if (isInlineBoundariesEnabled(editor) && !(Env.browser.isIE() && e.initial)) {
  22874. toggleInlines(isInlineTarget$1, editor.dom, e.parents);
  22875. safeRemoveCaretContainer(editor, caret);
  22876. renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents);
  22877. }
  22878. });
  22879. return caret;
  22880. };
  22881. var moveNextWord = curry(moveWord, true);
  22882. var movePrevWord = curry(moveWord, false);
  22883. var moveToLineEndPoint$2 = function(editor, forward, caret) {
  22884. if (isInlineBoundariesEnabled(editor)) {
  22885. var linePoint = getLineEndPoint(editor, forward).getOrThunk(function() {
  22886. var rng = editor.selection.getRng();
  22887. return forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng);
  22888. });
  22889. return readLocation(curry(isInlineTarget, editor), editor.getBody(), linePoint).exists(function(loc) {
  22890. var outsideLoc = outside(loc);
  22891. return renderCaret(caret, outsideLoc).exists(function(pos) {
  22892. setCaretPosition(editor, pos);
  22893. return true;
  22894. });
  22895. });
  22896. } else {
  22897. return false;
  22898. }
  22899. };
  22900. var rangeFromPositions = function(from2, to2) {
  22901. var range2 = document.createRange();
  22902. range2.setStart(from2.container(), from2.offset());
  22903. range2.setEnd(to2.container(), to2.offset());
  22904. return range2;
  22905. };
  22906. var hasOnlyTwoOrLessPositionsLeft = function(elm) {
  22907. return lift2(firstPositionIn(elm), lastPositionIn(elm), function(firstPos, lastPos) {
  22908. var normalizedFirstPos = normalizePosition(true, firstPos);
  22909. var normalizedLastPos = normalizePosition(false, lastPos);
  22910. return nextPosition(elm, normalizedFirstPos).forall(function(pos) {
  22911. return pos.isEqual(normalizedLastPos);
  22912. });
  22913. }).getOr(true);
  22914. };
  22915. var setCaretLocation = function(editor, caret) {
  22916. return function(location) {
  22917. return renderCaret(caret, location).exists(function(pos) {
  22918. setCaretPosition(editor, pos);
  22919. return true;
  22920. });
  22921. };
  22922. };
  22923. var deleteFromTo = function(editor, caret, from2, to2) {
  22924. var rootNode = editor.getBody();
  22925. var isInlineTarget$1 = curry(isInlineTarget, editor);
  22926. editor.undoManager.ignore(function() {
  22927. editor.selection.setRng(rangeFromPositions(from2, to2));
  22928. editor.execCommand("Delete");
  22929. readLocation(isInlineTarget$1, rootNode, CaretPosition.fromRangeStart(editor.selection.getRng())).map(inside).map(setCaretLocation(editor, caret));
  22930. });
  22931. editor.nodeChanged();
  22932. };
  22933. var rescope = function(rootNode, node) {
  22934. var parentBlock = getParentBlock$2(node, rootNode);
  22935. return parentBlock ? parentBlock : rootNode;
  22936. };
  22937. var backspaceDeleteCollapsed = function(editor, caret, forward, from2) {
  22938. var rootNode = rescope(editor.getBody(), from2.container());
  22939. var isInlineTarget$1 = curry(isInlineTarget, editor);
  22940. var fromLocation = readLocation(isInlineTarget$1, rootNode, from2);
  22941. return fromLocation.bind(function(location) {
  22942. if (forward) {
  22943. return location.fold(constant(Optional.some(inside(location))), Optional.none, constant(Optional.some(outside(location))), Optional.none);
  22944. } else {
  22945. return location.fold(Optional.none, constant(Optional.some(outside(location))), Optional.none, constant(Optional.some(inside(location))));
  22946. }
  22947. }).map(setCaretLocation(editor, caret)).getOrThunk(function() {
  22948. var toPosition = navigate(forward, rootNode, from2);
  22949. var toLocation = toPosition.bind(function(pos) {
  22950. return readLocation(isInlineTarget$1, rootNode, pos);
  22951. });
  22952. return lift2(fromLocation, toLocation, function() {
  22953. return findRootInline(isInlineTarget$1, rootNode, from2).exists(function(elm) {
  22954. if (hasOnlyTwoOrLessPositionsLeft(elm)) {
  22955. deleteElement$2(editor, forward, SugarElement.fromDom(elm));
  22956. return true;
  22957. } else {
  22958. return false;
  22959. }
  22960. });
  22961. }).orThunk(function() {
  22962. return toLocation.bind(function(_) {
  22963. return toPosition.map(function(to2) {
  22964. if (forward) {
  22965. deleteFromTo(editor, caret, from2, to2);
  22966. } else {
  22967. deleteFromTo(editor, caret, to2, from2);
  22968. }
  22969. return true;
  22970. });
  22971. });
  22972. }).getOr(false);
  22973. });
  22974. };
  22975. var backspaceDelete$3 = function(editor, caret, forward) {
  22976. if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) {
  22977. var from2 = CaretPosition.fromRangeStart(editor.selection.getRng());
  22978. return backspaceDeleteCollapsed(editor, caret, forward, from2);
  22979. }
  22980. return false;
  22981. };
  22982. var getParentInlines = function(rootElm, startElm) {
  22983. var parents2 = parentsAndSelf(startElm, rootElm);
  22984. return findIndex$2(parents2, isBlock$2).fold(constant(parents2), function(index) {
  22985. return parents2.slice(0, index);
  22986. });
  22987. };
  22988. var hasOnlyOneChild = function(elm) {
  22989. return childNodesCount(elm) === 1;
  22990. };
  22991. var deleteLastPosition = function(forward, editor, target, parentInlines) {
  22992. var isFormatElement$1 = curry(isFormatElement, editor);
  22993. var formatNodes = map$3(filter$4(parentInlines, isFormatElement$1), function(elm) {
  22994. return elm.dom;
  22995. });
  22996. if (formatNodes.length === 0) {
  22997. deleteElement$2(editor, forward, target);
  22998. } else {
  22999. var pos = replaceWithCaretFormat(target.dom, formatNodes);
  23000. editor.selection.setRng(pos.toRange());
  23001. }
  23002. };
  23003. var deleteCaret$1 = function(editor, forward) {
  23004. var rootElm = SugarElement.fromDom(editor.getBody());
  23005. var startElm = SugarElement.fromDom(editor.selection.getStart());
  23006. var parentInlines = filter$4(getParentInlines(rootElm, startElm), hasOnlyOneChild);
  23007. return last$2(parentInlines).exists(function(target) {
  23008. var fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
  23009. if (willDeleteLastPositionInElement(forward, fromPos, target.dom) && !isEmptyCaretFormatElement(target)) {
  23010. deleteLastPosition(forward, editor, target, parentInlines);
  23011. return true;
  23012. } else {
  23013. return false;
  23014. }
  23015. });
  23016. };
  23017. var backspaceDelete$2 = function(editor, forward) {
  23018. return editor.selection.isCollapsed() ? deleteCaret$1(editor, forward) : false;
  23019. };
  23020. var deleteElement = function(editor, forward, element) {
  23021. editor._selectionOverrides.hideFakeCaret();
  23022. deleteElement$2(editor, forward, SugarElement.fromDom(element));
  23023. return true;
  23024. };
  23025. var deleteCaret = function(editor, forward) {
  23026. var isNearMedia = forward ? isBeforeMedia : isAfterMedia;
  23027. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  23028. var fromPos = getNormalizedRangeEndPoint(direction, editor.getBody(), editor.selection.getRng());
  23029. if (isNearMedia(fromPos)) {
  23030. return deleteElement(editor, forward, fromPos.getNode(!forward));
  23031. } else {
  23032. return Optional.from(normalizePosition(forward, fromPos)).filter(function(pos) {
  23033. return isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos);
  23034. }).exists(function(pos) {
  23035. return deleteElement(editor, forward, pos.getNode(!forward));
  23036. });
  23037. }
  23038. };
  23039. var deleteRange = function(editor, forward) {
  23040. var selectedNode = editor.selection.getNode();
  23041. return isMedia$2(selectedNode) ? deleteElement(editor, forward, selectedNode) : false;
  23042. };
  23043. var backspaceDelete$1 = function(editor, forward) {
  23044. return editor.selection.isCollapsed() ? deleteCaret(editor, forward) : deleteRange(editor, forward);
  23045. };
  23046. var isEditable = function(target) {
  23047. return closest$3(target, function(elm) {
  23048. return isContentEditableTrue$4(elm.dom) || isContentEditableFalse$b(elm.dom);
  23049. }).exists(function(elm) {
  23050. return isContentEditableTrue$4(elm.dom);
  23051. });
  23052. };
  23053. var parseIndentValue = function(value2) {
  23054. var number = parseInt(value2, 10);
  23055. return isNaN(number) ? 0 : number;
  23056. };
  23057. var getIndentStyleName = function(useMargin, element) {
  23058. var indentStyleName = useMargin || isTable$2(element) ? "margin" : "padding";
  23059. var suffix = get$5(element, "direction") === "rtl" ? "-right" : "-left";
  23060. return indentStyleName + suffix;
  23061. };
  23062. var indentElement = function(dom2, command, useMargin, value2, unit, element) {
  23063. var indentStyleName = getIndentStyleName(useMargin, SugarElement.fromDom(element));
  23064. if (command === "outdent") {
  23065. var styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value2);
  23066. dom2.setStyle(element, indentStyleName, styleValue ? styleValue + unit : "");
  23067. } else {
  23068. var styleValue = parseIndentValue(element.style[indentStyleName]) + value2 + unit;
  23069. dom2.setStyle(element, indentStyleName, styleValue);
  23070. }
  23071. };
  23072. var validateBlocks = function(editor, blocks2) {
  23073. return forall(blocks2, function(block) {
  23074. var indentStyleName = getIndentStyleName(shouldIndentUseMargin(editor), block);
  23075. var intentValue = getRaw(block, indentStyleName).map(parseIndentValue).getOr(0);
  23076. var contentEditable = editor.dom.getContentEditable(block.dom);
  23077. return contentEditable !== "false" && intentValue > 0;
  23078. });
  23079. };
  23080. var canOutdent = function(editor) {
  23081. var blocks2 = getBlocksToIndent(editor);
  23082. return !editor.mode.isReadOnly() && (blocks2.length > 1 || validateBlocks(editor, blocks2));
  23083. };
  23084. var isListComponent = function(el) {
  23085. return isList(el) || isListItem(el);
  23086. };
  23087. var parentIsListComponent = function(el) {
  23088. return parent(el).exists(isListComponent);
  23089. };
  23090. var getBlocksToIndent = function(editor) {
  23091. return filter$4(fromDom$1(editor.selection.getSelectedBlocks()), function(el) {
  23092. return !isListComponent(el) && !parentIsListComponent(el) && isEditable(el);
  23093. });
  23094. };
  23095. var handle = function(editor, command) {
  23096. var dom2 = editor.dom, selection = editor.selection, formatter = editor.formatter;
  23097. var indentation = getIndentation(editor);
  23098. var indentUnit = /[a-z%]+$/i.exec(indentation)[0];
  23099. var indentValue = parseInt(indentation, 10);
  23100. var useMargin = shouldIndentUseMargin(editor);
  23101. var forcedRootBlock = getForcedRootBlock(editor);
  23102. if (!editor.queryCommandState("InsertUnorderedList") && !editor.queryCommandState("InsertOrderedList")) {
  23103. if (forcedRootBlock === "" && !dom2.getParent(selection.getNode(), dom2.isBlock)) {
  23104. formatter.apply("div");
  23105. }
  23106. }
  23107. each$k(getBlocksToIndent(editor), function(block) {
  23108. indentElement(dom2, command, useMargin, indentValue, indentUnit, block.dom);
  23109. });
  23110. };
  23111. var backspaceDelete = function(editor, _forward) {
  23112. if (editor.selection.isCollapsed() && canOutdent(editor)) {
  23113. var dom2 = editor.dom;
  23114. var rng = editor.selection.getRng();
  23115. var pos = CaretPosition.fromRangeStart(rng);
  23116. var block = dom2.getParent(rng.startContainer, dom2.isBlock);
  23117. if (block !== null && isAtStartOfBlock(SugarElement.fromDom(block), pos)) {
  23118. handle(editor, "outdent");
  23119. return true;
  23120. }
  23121. }
  23122. return false;
  23123. };
  23124. var nativeCommand = function(editor, command) {
  23125. editor.getDoc().execCommand(command, false, null);
  23126. };
  23127. var deleteCommand = function(editor, caret) {
  23128. if (backspaceDelete(editor)) {
  23129. return;
  23130. } else if (backspaceDelete$5(editor, false)) {
  23131. return;
  23132. } else if (backspaceDelete$6(editor, false)) {
  23133. return;
  23134. } else if (backspaceDelete$3(editor, caret, false)) {
  23135. return;
  23136. } else if (backspaceDelete$8(editor, false)) {
  23137. return;
  23138. } else if (backspaceDelete$9(editor)) {
  23139. return;
  23140. } else if (backspaceDelete$4(editor, false)) {
  23141. return;
  23142. } else if (backspaceDelete$1(editor, false)) {
  23143. return;
  23144. } else if (backspaceDelete$7(editor)) {
  23145. return;
  23146. } else if (backspaceDelete$2(editor, false)) {
  23147. return;
  23148. } else {
  23149. nativeCommand(editor, "Delete");
  23150. paddEmptyBody(editor);
  23151. }
  23152. };
  23153. var forwardDeleteCommand = function(editor, caret) {
  23154. if (backspaceDelete$5(editor, true)) {
  23155. return;
  23156. } else if (backspaceDelete$6(editor, true)) {
  23157. return;
  23158. } else if (backspaceDelete$3(editor, caret, true)) {
  23159. return;
  23160. } else if (backspaceDelete$8(editor, true)) {
  23161. return;
  23162. } else if (backspaceDelete$9(editor)) {
  23163. return;
  23164. } else if (backspaceDelete$4(editor, true)) {
  23165. return;
  23166. } else if (backspaceDelete$1(editor, true)) {
  23167. return;
  23168. } else if (backspaceDelete$7(editor)) {
  23169. return;
  23170. } else if (backspaceDelete$2(editor, true)) {
  23171. return;
  23172. } else {
  23173. nativeCommand(editor, "ForwardDelete");
  23174. }
  23175. };
  23176. var setup$f = function(editor, caret) {
  23177. editor.addCommand("delete", function() {
  23178. deleteCommand(editor, caret);
  23179. });
  23180. editor.addCommand("forwardDelete", function() {
  23181. forwardDeleteCommand(editor, caret);
  23182. });
  23183. };
  23184. var SIGNIFICANT_MOVE = 5;
  23185. var LONGPRESS_DELAY = 400;
  23186. var getTouch = function(event) {
  23187. if (event.touches === void 0 || event.touches.length !== 1) {
  23188. return Optional.none();
  23189. }
  23190. return Optional.some(event.touches[0]);
  23191. };
  23192. var isFarEnough = function(touch, data2) {
  23193. var distX = Math.abs(touch.clientX - data2.x);
  23194. var distY = Math.abs(touch.clientY - data2.y);
  23195. return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
  23196. };
  23197. var setup$e = function(editor) {
  23198. var startData = value();
  23199. var longpressFired = Cell(false);
  23200. var debounceLongpress = last(function(e) {
  23201. editor.fire("longpress", __assign(__assign({}, e), { type: "longpress" }));
  23202. longpressFired.set(true);
  23203. }, LONGPRESS_DELAY);
  23204. editor.on("touchstart", function(e) {
  23205. getTouch(e).each(function(touch) {
  23206. debounceLongpress.cancel();
  23207. var data2 = {
  23208. x: touch.clientX,
  23209. y: touch.clientY,
  23210. target: e.target
  23211. };
  23212. debounceLongpress.throttle(e);
  23213. longpressFired.set(false);
  23214. startData.set(data2);
  23215. });
  23216. }, true);
  23217. editor.on("touchmove", function(e) {
  23218. debounceLongpress.cancel();
  23219. getTouch(e).each(function(touch) {
  23220. startData.on(function(data2) {
  23221. if (isFarEnough(touch, data2)) {
  23222. startData.clear();
  23223. longpressFired.set(false);
  23224. editor.fire("longpresscancel");
  23225. }
  23226. });
  23227. });
  23228. }, true);
  23229. editor.on("touchend touchcancel", function(e) {
  23230. debounceLongpress.cancel();
  23231. if (e.type === "touchcancel") {
  23232. return;
  23233. }
  23234. startData.get().filter(function(data2) {
  23235. return data2.target.isEqualNode(e.target);
  23236. }).each(function() {
  23237. if (longpressFired.get()) {
  23238. e.preventDefault();
  23239. } else {
  23240. editor.fire("tap", __assign(__assign({}, e), { type: "tap" }));
  23241. }
  23242. });
  23243. }, true);
  23244. };
  23245. var isBlockElement = function(blockElements, node) {
  23246. return has$2(blockElements, node.nodeName);
  23247. };
  23248. var isValidTarget = function(blockElements, node) {
  23249. if (isText$7(node)) {
  23250. return true;
  23251. } else if (isElement$5(node)) {
  23252. return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node);
  23253. } else {
  23254. return false;
  23255. }
  23256. };
  23257. var hasBlockParent = function(blockElements, root, node) {
  23258. return exists(parents(SugarElement.fromDom(node), SugarElement.fromDom(root)), function(elm) {
  23259. return isBlockElement(blockElements, elm.dom);
  23260. });
  23261. };
  23262. var shouldRemoveTextNode = function(blockElements, node) {
  23263. if (isText$7(node)) {
  23264. if (node.nodeValue.length === 0) {
  23265. return true;
  23266. } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) {
  23267. return true;
  23268. }
  23269. }
  23270. return false;
  23271. };
  23272. var addRootBlocks = function(editor) {
  23273. var dom2 = editor.dom, selection = editor.selection;
  23274. var schema = editor.schema, blockElements = schema.getBlockElements();
  23275. var node = selection.getStart();
  23276. var rootNode = editor.getBody();
  23277. var rootBlockNode, tempNode, wrapped;
  23278. var forcedRootBlock = getForcedRootBlock(editor);
  23279. if (!node || !isElement$5(node) || !forcedRootBlock) {
  23280. return;
  23281. }
  23282. var rootNodeName = rootNode.nodeName.toLowerCase();
  23283. if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) {
  23284. return;
  23285. }
  23286. var rng = selection.getRng();
  23287. var startContainer = rng.startContainer;
  23288. var startOffset = rng.startOffset;
  23289. var endContainer = rng.endContainer;
  23290. var endOffset = rng.endOffset;
  23291. var restoreSelection = hasFocus(editor);
  23292. node = rootNode.firstChild;
  23293. while (node) {
  23294. if (isValidTarget(blockElements, node)) {
  23295. if (shouldRemoveTextNode(blockElements, node)) {
  23296. tempNode = node;
  23297. node = node.nextSibling;
  23298. dom2.remove(tempNode);
  23299. continue;
  23300. }
  23301. if (!rootBlockNode) {
  23302. rootBlockNode = dom2.create(forcedRootBlock, getForcedRootBlockAttrs(editor));
  23303. node.parentNode.insertBefore(rootBlockNode, node);
  23304. wrapped = true;
  23305. }
  23306. tempNode = node;
  23307. node = node.nextSibling;
  23308. rootBlockNode.appendChild(tempNode);
  23309. } else {
  23310. rootBlockNode = null;
  23311. node = node.nextSibling;
  23312. }
  23313. }
  23314. if (wrapped && restoreSelection) {
  23315. rng.setStart(startContainer, startOffset);
  23316. rng.setEnd(endContainer, endOffset);
  23317. selection.setRng(rng);
  23318. editor.nodeChanged();
  23319. }
  23320. };
  23321. var setup$d = function(editor) {
  23322. if (getForcedRootBlock(editor)) {
  23323. editor.on("NodeChange", curry(addRootBlocks, editor));
  23324. }
  23325. };
  23326. var findBlockCaretContainer = function(editor) {
  23327. return descendant(SugarElement.fromDom(editor.getBody()), "*[data-mce-caret]").map(function(elm) {
  23328. return elm.dom;
  23329. }).getOrNull();
  23330. };
  23331. var removeIeControlRect = function(editor) {
  23332. editor.selection.setRng(editor.selection.getRng());
  23333. };
  23334. var showBlockCaretContainer = function(editor, blockCaretContainer) {
  23335. if (blockCaretContainer.hasAttribute("data-mce-caret")) {
  23336. showCaretContainerBlock(blockCaretContainer);
  23337. removeIeControlRect(editor);
  23338. editor.selection.scrollIntoView(blockCaretContainer);
  23339. }
  23340. };
  23341. var handleBlockContainer = function(editor, e) {
  23342. var blockCaretContainer = findBlockCaretContainer(editor);
  23343. if (!blockCaretContainer) {
  23344. return;
  23345. }
  23346. if (e.type === "compositionstart") {
  23347. e.preventDefault();
  23348. e.stopPropagation();
  23349. showBlockCaretContainer(editor, blockCaretContainer);
  23350. return;
  23351. }
  23352. if (hasContent(blockCaretContainer)) {
  23353. showBlockCaretContainer(editor, blockCaretContainer);
  23354. editor.undoManager.add();
  23355. }
  23356. };
  23357. var setup$c = function(editor) {
  23358. editor.on("keyup compositionstart", curry(handleBlockContainer, editor));
  23359. };
  23360. var isContentEditableFalse$2 = isContentEditableFalse$b;
  23361. var moveToCeFalseHorizontally = function(direction, editor, range2) {
  23362. return moveHorizontally(editor, direction, range2, isBeforeContentEditableFalse, isAfterContentEditableFalse, isContentEditableFalse$2);
  23363. };
  23364. var moveToCeFalseVertically = function(direction, editor, range2) {
  23365. var isBefore = function(caretPosition) {
  23366. return isBeforeContentEditableFalse(caretPosition) || isBeforeTable(caretPosition);
  23367. };
  23368. var isAfter = function(caretPosition) {
  23369. return isAfterContentEditableFalse(caretPosition) || isAfterTable(caretPosition);
  23370. };
  23371. return moveVertically(editor, direction, range2, isBefore, isAfter, isContentEditableFalse$2);
  23372. };
  23373. var createTextBlock = function(editor) {
  23374. var textBlock = editor.dom.create(getForcedRootBlock(editor));
  23375. if (!Env.ie || Env.ie >= 11) {
  23376. textBlock.innerHTML = '<br data-mce-bogus="1">';
  23377. }
  23378. return textBlock;
  23379. };
  23380. var exitPreBlock = function(editor, direction, range2) {
  23381. var caretWalker = CaretWalker(editor.getBody());
  23382. var getVisualCaretPosition$1 = curry(getVisualCaretPosition, direction === 1 ? caretWalker.next : caretWalker.prev);
  23383. if (range2.collapsed && hasForcedRootBlock(editor)) {
  23384. var pre = editor.dom.getParent(range2.startContainer, "PRE");
  23385. if (!pre) {
  23386. return;
  23387. }
  23388. var caretPos = getVisualCaretPosition$1(CaretPosition.fromRangeStart(range2));
  23389. if (!caretPos) {
  23390. var newBlock = createTextBlock(editor);
  23391. if (direction === 1) {
  23392. editor.$(pre).after(newBlock);
  23393. } else {
  23394. editor.$(pre).before(newBlock);
  23395. }
  23396. editor.selection.select(newBlock, true);
  23397. editor.selection.collapse();
  23398. }
  23399. }
  23400. };
  23401. var getHorizontalRange = function(editor, forward) {
  23402. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  23403. var range2 = editor.selection.getRng();
  23404. return moveToCeFalseHorizontally(direction, editor, range2).orThunk(function() {
  23405. exitPreBlock(editor, direction, range2);
  23406. return Optional.none();
  23407. });
  23408. };
  23409. var getVerticalRange = function(editor, down) {
  23410. var direction = down ? 1 : -1;
  23411. var range2 = editor.selection.getRng();
  23412. return moveToCeFalseVertically(direction, editor, range2).orThunk(function() {
  23413. exitPreBlock(editor, direction, range2);
  23414. return Optional.none();
  23415. });
  23416. };
  23417. var moveH$2 = function(editor, forward) {
  23418. return getHorizontalRange(editor, forward).exists(function(newRange) {
  23419. moveToRange(editor, newRange);
  23420. return true;
  23421. });
  23422. };
  23423. var moveV$3 = function(editor, down) {
  23424. return getVerticalRange(editor, down).exists(function(newRange) {
  23425. moveToRange(editor, newRange);
  23426. return true;
  23427. });
  23428. };
  23429. var moveToLineEndPoint$1 = function(editor, forward) {
  23430. var isCefPosition = forward ? isAfterContentEditableFalse : isBeforeContentEditableFalse;
  23431. return moveToLineEndPoint$3(editor, forward, isCefPosition);
  23432. };
  23433. var isTarget = function(node) {
  23434. return contains$3(["figcaption"], name(node));
  23435. };
  23436. var rangeBefore = function(target) {
  23437. var rng = document.createRange();
  23438. rng.setStartBefore(target.dom);
  23439. rng.setEndBefore(target.dom);
  23440. return rng;
  23441. };
  23442. var insertElement = function(root, elm, forward) {
  23443. if (forward) {
  23444. append$1(root, elm);
  23445. } else {
  23446. prepend(root, elm);
  23447. }
  23448. };
  23449. var insertBr = function(root, forward) {
  23450. var br = SugarElement.fromTag("br");
  23451. insertElement(root, br, forward);
  23452. return rangeBefore(br);
  23453. };
  23454. var insertBlock = function(root, forward, blockName, attrs) {
  23455. var block = SugarElement.fromTag(blockName);
  23456. var br = SugarElement.fromTag("br");
  23457. setAll$1(block, attrs);
  23458. append$1(block, br);
  23459. insertElement(root, block, forward);
  23460. return rangeBefore(br);
  23461. };
  23462. var insertEmptyLine = function(root, rootBlockName, attrs, forward) {
  23463. if (rootBlockName === "") {
  23464. return insertBr(root, forward);
  23465. } else {
  23466. return insertBlock(root, forward, rootBlockName, attrs);
  23467. }
  23468. };
  23469. var getClosestTargetBlock = function(pos, root) {
  23470. var isRoot = curry(eq, root);
  23471. return closest$3(SugarElement.fromDom(pos.container()), isBlock$2, isRoot).filter(isTarget);
  23472. };
  23473. var isAtFirstOrLastLine = function(root, forward, pos) {
  23474. return forward ? isAtLastLine(root.dom, pos) : isAtFirstLine(root.dom, pos);
  23475. };
  23476. var moveCaretToNewEmptyLine = function(editor, forward) {
  23477. var root = SugarElement.fromDom(editor.getBody());
  23478. var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
  23479. var rootBlock = getForcedRootBlock(editor);
  23480. var rootBlockAttrs = getForcedRootBlockAttrs(editor);
  23481. return getClosestTargetBlock(pos, root).exists(function() {
  23482. if (isAtFirstOrLastLine(root, forward, pos)) {
  23483. var rng = insertEmptyLine(root, rootBlock, rootBlockAttrs, forward);
  23484. editor.selection.setRng(rng);
  23485. return true;
  23486. } else {
  23487. return false;
  23488. }
  23489. });
  23490. };
  23491. var moveV$2 = function(editor, forward) {
  23492. if (editor.selection.isCollapsed()) {
  23493. return moveCaretToNewEmptyLine(editor, forward);
  23494. } else {
  23495. return false;
  23496. }
  23497. };
  23498. var defaultPatterns = function(patterns) {
  23499. return map$3(patterns, function(pattern) {
  23500. return __assign({
  23501. shiftKey: false,
  23502. altKey: false,
  23503. ctrlKey: false,
  23504. metaKey: false,
  23505. keyCode: 0,
  23506. action: noop
  23507. }, pattern);
  23508. });
  23509. };
  23510. var matchesEvent = function(pattern, evt) {
  23511. return evt.keyCode === pattern.keyCode && evt.shiftKey === pattern.shiftKey && evt.altKey === pattern.altKey && evt.ctrlKey === pattern.ctrlKey && evt.metaKey === pattern.metaKey;
  23512. };
  23513. var match$1 = function(patterns, evt) {
  23514. return bind(defaultPatterns(patterns), function(pattern) {
  23515. return matchesEvent(pattern, evt) ? [pattern] : [];
  23516. });
  23517. };
  23518. var action = function(f) {
  23519. var x = [];
  23520. for (var _i = 1; _i < arguments.length; _i++) {
  23521. x[_i - 1] = arguments[_i];
  23522. }
  23523. return function() {
  23524. return f.apply(null, x);
  23525. };
  23526. };
  23527. var execute = function(patterns, evt) {
  23528. return find$3(match$1(patterns, evt), function(pattern) {
  23529. return pattern.action();
  23530. });
  23531. };
  23532. var moveH$1 = function(editor, forward) {
  23533. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  23534. var range2 = editor.selection.getRng();
  23535. return moveHorizontally(editor, direction, range2, isBeforeMedia, isAfterMedia, isMedia$2).exists(function(newRange) {
  23536. moveToRange(editor, newRange);
  23537. return true;
  23538. });
  23539. };
  23540. var moveV$1 = function(editor, down) {
  23541. var direction = down ? 1 : -1;
  23542. var range2 = editor.selection.getRng();
  23543. return moveVertically(editor, direction, range2, isBeforeMedia, isAfterMedia, isMedia$2).exists(function(newRange) {
  23544. moveToRange(editor, newRange);
  23545. return true;
  23546. });
  23547. };
  23548. var moveToLineEndPoint = function(editor, forward) {
  23549. var isNearMedia = forward ? isAfterMedia : isBeforeMedia;
  23550. return moveToLineEndPoint$3(editor, forward, isNearMedia);
  23551. };
  23552. var deflate = function(rect, delta) {
  23553. return {
  23554. left: rect.left - delta,
  23555. top: rect.top - delta,
  23556. right: rect.right + delta * 2,
  23557. bottom: rect.bottom + delta * 2,
  23558. width: rect.width + delta,
  23559. height: rect.height + delta
  23560. };
  23561. };
  23562. var getCorners = function(getYAxisValue, tds) {
  23563. return bind(tds, function(td) {
  23564. var rect = deflate(clone(td.getBoundingClientRect()), -1);
  23565. return [
  23566. {
  23567. x: rect.left,
  23568. y: getYAxisValue(rect),
  23569. cell: td
  23570. },
  23571. {
  23572. x: rect.right,
  23573. y: getYAxisValue(rect),
  23574. cell: td
  23575. }
  23576. ];
  23577. });
  23578. };
  23579. var findClosestCorner = function(corners, x, y) {
  23580. return foldl(corners, function(acc, newCorner) {
  23581. return acc.fold(function() {
  23582. return Optional.some(newCorner);
  23583. }, function(oldCorner) {
  23584. var oldDist = Math.sqrt(Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y));
  23585. var newDist = Math.sqrt(Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y));
  23586. return Optional.some(newDist < oldDist ? newCorner : oldCorner);
  23587. });
  23588. }, Optional.none());
  23589. };
  23590. var getClosestCell = function(getYAxisValue, isTargetCorner, table, x, y) {
  23591. var cells = descendants(SugarElement.fromDom(table), "td,th,caption").map(function(e) {
  23592. return e.dom;
  23593. });
  23594. var corners = filter$4(getCorners(getYAxisValue, cells), function(corner) {
  23595. return isTargetCorner(corner, y);
  23596. });
  23597. return findClosestCorner(corners, x, y).map(function(corner) {
  23598. return corner.cell;
  23599. });
  23600. };
  23601. var getBottomValue = function(rect) {
  23602. return rect.bottom;
  23603. };
  23604. var getTopValue = function(rect) {
  23605. return rect.top;
  23606. };
  23607. var isAbove = function(corner, y) {
  23608. return corner.y < y;
  23609. };
  23610. var isBelow = function(corner, y) {
  23611. return corner.y > y;
  23612. };
  23613. var getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove);
  23614. var getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow);
  23615. var findClosestPositionInAboveCell = function(table, pos) {
  23616. return head(pos.getClientRects()).bind(function(rect) {
  23617. return getClosestCellAbove(table, rect.left, rect.top);
  23618. }).bind(function(cell) {
  23619. return findClosestHorizontalPosition(getLastLinePositions(cell), pos);
  23620. });
  23621. };
  23622. var findClosestPositionInBelowCell = function(table, pos) {
  23623. return last$2(pos.getClientRects()).bind(function(rect) {
  23624. return getClosestCellBelow(table, rect.left, rect.top);
  23625. }).bind(function(cell) {
  23626. return findClosestHorizontalPosition(getFirstLinePositions(cell), pos);
  23627. });
  23628. };
  23629. var hasNextBreak = function(getPositionsUntil2, scope, lineInfo) {
  23630. return lineInfo.breakAt.exists(function(breakPos) {
  23631. return getPositionsUntil2(scope, breakPos).breakAt.isSome();
  23632. });
  23633. };
  23634. var startsWithWrapBreak = function(lineInfo) {
  23635. return lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0;
  23636. };
  23637. var startsWithBrBreak = function(lineInfo) {
  23638. return lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1;
  23639. };
  23640. var isAtTableCellLine = function(getPositionsUntil2, scope, pos) {
  23641. var lineInfo = getPositionsUntil2(scope, pos);
  23642. if (startsWithWrapBreak(lineInfo) || !isBr$5(pos.getNode()) && startsWithBrBreak(lineInfo)) {
  23643. return !hasNextBreak(getPositionsUntil2, scope, lineInfo);
  23644. } else {
  23645. return lineInfo.breakAt.isNone();
  23646. }
  23647. };
  23648. var isAtFirstTableCellLine = curry(isAtTableCellLine, getPositionsUntilPreviousLine);
  23649. var isAtLastTableCellLine = curry(isAtTableCellLine, getPositionsUntilNextLine);
  23650. var isCaretAtStartOrEndOfTable = function(forward, rng, table) {
  23651. var caretPos = CaretPosition.fromRangeStart(rng);
  23652. return positionIn(!forward, table).exists(function(pos) {
  23653. return pos.isEqual(caretPos);
  23654. });
  23655. };
  23656. var navigateHorizontally = function(editor, forward, table, _td) {
  23657. var rng = editor.selection.getRng();
  23658. var direction = forward ? 1 : -1;
  23659. if (isFakeCaretTableBrowser() && isCaretAtStartOrEndOfTable(forward, rng, table)) {
  23660. showCaret(direction, editor, table, !forward, false).each(function(newRng) {
  23661. moveToRange(editor, newRng);
  23662. });
  23663. return true;
  23664. }
  23665. return false;
  23666. };
  23667. var getClosestAbovePosition = function(root, table, start2) {
  23668. return findClosestPositionInAboveCell(table, start2).orThunk(function() {
  23669. return head(start2.getClientRects()).bind(function(rect) {
  23670. return findClosestHorizontalPositionFromPoint(getPositionsAbove(root, CaretPosition.before(table)), rect.left);
  23671. });
  23672. }).getOr(CaretPosition.before(table));
  23673. };
  23674. var getClosestBelowPosition = function(root, table, start2) {
  23675. return findClosestPositionInBelowCell(table, start2).orThunk(function() {
  23676. return head(start2.getClientRects()).bind(function(rect) {
  23677. return findClosestHorizontalPositionFromPoint(getPositionsBelow(root, CaretPosition.after(table)), rect.left);
  23678. });
  23679. }).getOr(CaretPosition.after(table));
  23680. };
  23681. var getTable = function(previous, pos) {
  23682. var node = pos.getNode(previous);
  23683. return isElement$5(node) && node.nodeName === "TABLE" ? Optional.some(node) : Optional.none();
  23684. };
  23685. var renderBlock = function(down, editor, table, pos) {
  23686. var forcedRootBlock = getForcedRootBlock(editor);
  23687. if (forcedRootBlock) {
  23688. editor.undoManager.transact(function() {
  23689. var element = SugarElement.fromTag(forcedRootBlock);
  23690. setAll$1(element, getForcedRootBlockAttrs(editor));
  23691. append$1(element, SugarElement.fromTag("br"));
  23692. if (down) {
  23693. after$3(SugarElement.fromDom(table), element);
  23694. } else {
  23695. before$4(SugarElement.fromDom(table), element);
  23696. }
  23697. var rng = editor.dom.createRng();
  23698. rng.setStart(element.dom, 0);
  23699. rng.setEnd(element.dom, 0);
  23700. moveToRange(editor, rng);
  23701. });
  23702. } else {
  23703. moveToRange(editor, pos.toRange());
  23704. }
  23705. };
  23706. var moveCaret = function(editor, down, pos) {
  23707. var table = down ? getTable(true, pos) : getTable(false, pos);
  23708. var last2 = down === false;
  23709. table.fold(function() {
  23710. return moveToRange(editor, pos.toRange());
  23711. }, function(table2) {
  23712. return positionIn(last2, editor.getBody()).filter(function(lastPos) {
  23713. return lastPos.isEqual(pos);
  23714. }).fold(function() {
  23715. return moveToRange(editor, pos.toRange());
  23716. }, function(_) {
  23717. return renderBlock(down, editor, table2, pos);
  23718. });
  23719. });
  23720. };
  23721. var navigateVertically = function(editor, down, table, td) {
  23722. var rng = editor.selection.getRng();
  23723. var pos = CaretPosition.fromRangeStart(rng);
  23724. var root = editor.getBody();
  23725. if (!down && isAtFirstTableCellLine(td, pos)) {
  23726. var newPos = getClosestAbovePosition(root, table, pos);
  23727. moveCaret(editor, down, newPos);
  23728. return true;
  23729. } else if (down && isAtLastTableCellLine(td, pos)) {
  23730. var newPos = getClosestBelowPosition(root, table, pos);
  23731. moveCaret(editor, down, newPos);
  23732. return true;
  23733. } else {
  23734. return false;
  23735. }
  23736. };
  23737. var move$1 = function(editor, forward, mover) {
  23738. return Optional.from(editor.dom.getParent(editor.selection.getNode(), "td,th")).bind(function(td) {
  23739. return Optional.from(editor.dom.getParent(td, "table")).map(function(table) {
  23740. return mover(editor, forward, table, td);
  23741. });
  23742. }).getOr(false);
  23743. };
  23744. var moveH = function(editor, forward) {
  23745. return move$1(editor, forward, navigateHorizontally);
  23746. };
  23747. var moveV = function(editor, forward) {
  23748. return move$1(editor, forward, navigateVertically);
  23749. };
  23750. var executeKeydownOverride$3 = function(editor, caret, evt) {
  23751. var os2 = detect().os;
  23752. execute([
  23753. {
  23754. keyCode: VK.RIGHT,
  23755. action: action(moveH$2, editor, true)
  23756. },
  23757. {
  23758. keyCode: VK.LEFT,
  23759. action: action(moveH$2, editor, false)
  23760. },
  23761. {
  23762. keyCode: VK.UP,
  23763. action: action(moveV$3, editor, false)
  23764. },
  23765. {
  23766. keyCode: VK.DOWN,
  23767. action: action(moveV$3, editor, true)
  23768. },
  23769. {
  23770. keyCode: VK.RIGHT,
  23771. action: action(moveH, editor, true)
  23772. },
  23773. {
  23774. keyCode: VK.LEFT,
  23775. action: action(moveH, editor, false)
  23776. },
  23777. {
  23778. keyCode: VK.UP,
  23779. action: action(moveV, editor, false)
  23780. },
  23781. {
  23782. keyCode: VK.DOWN,
  23783. action: action(moveV, editor, true)
  23784. },
  23785. {
  23786. keyCode: VK.RIGHT,
  23787. action: action(moveH$1, editor, true)
  23788. },
  23789. {
  23790. keyCode: VK.LEFT,
  23791. action: action(moveH$1, editor, false)
  23792. },
  23793. {
  23794. keyCode: VK.UP,
  23795. action: action(moveV$1, editor, false)
  23796. },
  23797. {
  23798. keyCode: VK.DOWN,
  23799. action: action(moveV$1, editor, true)
  23800. },
  23801. {
  23802. keyCode: VK.RIGHT,
  23803. action: action(move$2, editor, caret, true)
  23804. },
  23805. {
  23806. keyCode: VK.LEFT,
  23807. action: action(move$2, editor, caret, false)
  23808. },
  23809. {
  23810. keyCode: VK.RIGHT,
  23811. ctrlKey: !os2.isOSX(),
  23812. altKey: os2.isOSX(),
  23813. action: action(moveNextWord, editor, caret)
  23814. },
  23815. {
  23816. keyCode: VK.LEFT,
  23817. ctrlKey: !os2.isOSX(),
  23818. altKey: os2.isOSX(),
  23819. action: action(movePrevWord, editor, caret)
  23820. },
  23821. {
  23822. keyCode: VK.UP,
  23823. action: action(moveV$2, editor, false)
  23824. },
  23825. {
  23826. keyCode: VK.DOWN,
  23827. action: action(moveV$2, editor, true)
  23828. }
  23829. ], evt).each(function(_) {
  23830. evt.preventDefault();
  23831. });
  23832. };
  23833. var setup$b = function(editor, caret) {
  23834. editor.on("keydown", function(evt) {
  23835. if (evt.isDefaultPrevented() === false) {
  23836. executeKeydownOverride$3(editor, caret, evt);
  23837. }
  23838. });
  23839. };
  23840. var executeKeydownOverride$2 = function(editor, caret, evt) {
  23841. execute([
  23842. {
  23843. keyCode: VK.BACKSPACE,
  23844. action: action(backspaceDelete, editor, false)
  23845. },
  23846. {
  23847. keyCode: VK.BACKSPACE,
  23848. action: action(backspaceDelete$5, editor, false)
  23849. },
  23850. {
  23851. keyCode: VK.DELETE,
  23852. action: action(backspaceDelete$5, editor, true)
  23853. },
  23854. {
  23855. keyCode: VK.BACKSPACE,
  23856. action: action(backspaceDelete$6, editor, false)
  23857. },
  23858. {
  23859. keyCode: VK.DELETE,
  23860. action: action(backspaceDelete$6, editor, true)
  23861. },
  23862. {
  23863. keyCode: VK.BACKSPACE,
  23864. action: action(backspaceDelete$3, editor, caret, false)
  23865. },
  23866. {
  23867. keyCode: VK.DELETE,
  23868. action: action(backspaceDelete$3, editor, caret, true)
  23869. },
  23870. {
  23871. keyCode: VK.BACKSPACE,
  23872. action: action(backspaceDelete$9, editor, false)
  23873. },
  23874. {
  23875. keyCode: VK.DELETE,
  23876. action: action(backspaceDelete$9, editor, true)
  23877. },
  23878. {
  23879. keyCode: VK.BACKSPACE,
  23880. action: action(backspaceDelete$4, editor, false)
  23881. },
  23882. {
  23883. keyCode: VK.DELETE,
  23884. action: action(backspaceDelete$4, editor, true)
  23885. },
  23886. {
  23887. keyCode: VK.BACKSPACE,
  23888. action: action(backspaceDelete$1, editor, false)
  23889. },
  23890. {
  23891. keyCode: VK.DELETE,
  23892. action: action(backspaceDelete$1, editor, true)
  23893. },
  23894. {
  23895. keyCode: VK.BACKSPACE,
  23896. action: action(backspaceDelete$7, editor, false)
  23897. },
  23898. {
  23899. keyCode: VK.DELETE,
  23900. action: action(backspaceDelete$7, editor, true)
  23901. },
  23902. {
  23903. keyCode: VK.BACKSPACE,
  23904. action: action(backspaceDelete$8, editor, false)
  23905. },
  23906. {
  23907. keyCode: VK.DELETE,
  23908. action: action(backspaceDelete$8, editor, true)
  23909. },
  23910. {
  23911. keyCode: VK.BACKSPACE,
  23912. action: action(backspaceDelete$2, editor, false)
  23913. },
  23914. {
  23915. keyCode: VK.DELETE,
  23916. action: action(backspaceDelete$2, editor, true)
  23917. }
  23918. ], evt).each(function(_) {
  23919. evt.preventDefault();
  23920. });
  23921. };
  23922. var executeKeyupOverride = function(editor, evt) {
  23923. execute([
  23924. {
  23925. keyCode: VK.BACKSPACE,
  23926. action: action(paddEmptyElement, editor)
  23927. },
  23928. {
  23929. keyCode: VK.DELETE,
  23930. action: action(paddEmptyElement, editor)
  23931. }
  23932. ], evt);
  23933. };
  23934. var setup$a = function(editor, caret) {
  23935. editor.on("keydown", function(evt) {
  23936. if (evt.isDefaultPrevented() === false) {
  23937. executeKeydownOverride$2(editor, caret, evt);
  23938. }
  23939. });
  23940. editor.on("keyup", function(evt) {
  23941. if (evt.isDefaultPrevented() === false) {
  23942. executeKeyupOverride(editor, evt);
  23943. }
  23944. });
  23945. };
  23946. var firstNonWhiteSpaceNodeSibling = function(node) {
  23947. while (node) {
  23948. if (node.nodeType === 1 || node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data)) {
  23949. return node;
  23950. }
  23951. node = node.nextSibling;
  23952. }
  23953. };
  23954. var moveToCaretPosition = function(editor, root) {
  23955. var node, lastNode = root;
  23956. var dom2 = editor.dom;
  23957. var moveCaretBeforeOnEnterElementsMap = editor.schema.getMoveCaretBeforeOnEnterElements();
  23958. if (!root) {
  23959. return;
  23960. }
  23961. if (/^(LI|DT|DD)$/.test(root.nodeName)) {
  23962. var firstChild2 = firstNonWhiteSpaceNodeSibling(root.firstChild);
  23963. if (firstChild2 && /^(UL|OL|DL)$/.test(firstChild2.nodeName)) {
  23964. root.insertBefore(dom2.doc.createTextNode(nbsp), root.firstChild);
  23965. }
  23966. }
  23967. var rng = dom2.createRng();
  23968. root.normalize();
  23969. if (root.hasChildNodes()) {
  23970. var walker = new DomTreeWalker(root, root);
  23971. while (node = walker.current()) {
  23972. if (isText$7(node)) {
  23973. rng.setStart(node, 0);
  23974. rng.setEnd(node, 0);
  23975. break;
  23976. }
  23977. if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
  23978. rng.setStartBefore(node);
  23979. rng.setEndBefore(node);
  23980. break;
  23981. }
  23982. lastNode = node;
  23983. node = walker.next();
  23984. }
  23985. if (!node) {
  23986. rng.setStart(lastNode, 0);
  23987. rng.setEnd(lastNode, 0);
  23988. }
  23989. } else {
  23990. if (isBr$5(root)) {
  23991. if (root.nextSibling && dom2.isBlock(root.nextSibling)) {
  23992. rng.setStartBefore(root);
  23993. rng.setEndBefore(root);
  23994. } else {
  23995. rng.setStartAfter(root);
  23996. rng.setEndAfter(root);
  23997. }
  23998. } else {
  23999. rng.setStart(root, 0);
  24000. rng.setEnd(root, 0);
  24001. }
  24002. }
  24003. editor.selection.setRng(rng);
  24004. scrollRangeIntoView(editor, rng);
  24005. };
  24006. var getEditableRoot$1 = function(dom2, node) {
  24007. var root = dom2.getRoot();
  24008. var parent2, editableRoot;
  24009. parent2 = node;
  24010. while (parent2 !== root && dom2.getContentEditable(parent2) !== "false") {
  24011. if (dom2.getContentEditable(parent2) === "true") {
  24012. editableRoot = parent2;
  24013. }
  24014. parent2 = parent2.parentNode;
  24015. }
  24016. return parent2 !== root ? editableRoot : root;
  24017. };
  24018. var getParentBlock = function(editor) {
  24019. return Optional.from(editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock));
  24020. };
  24021. var getParentBlockName = function(editor) {
  24022. return getParentBlock(editor).fold(constant(""), function(parentBlock) {
  24023. return parentBlock.nodeName.toUpperCase();
  24024. });
  24025. };
  24026. var isListItemParentBlock = function(editor) {
  24027. return getParentBlock(editor).filter(function(elm) {
  24028. return isListItem(SugarElement.fromDom(elm));
  24029. }).isSome();
  24030. };
  24031. var hasFirstChild = function(elm, name2) {
  24032. return elm.firstChild && elm.firstChild.nodeName === name2;
  24033. };
  24034. var isFirstChild = function(elm) {
  24035. var _a;
  24036. return ((_a = elm.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild) === elm;
  24037. };
  24038. var hasParent = function(elm, parentName) {
  24039. return elm && elm.parentNode && elm.parentNode.nodeName === parentName;
  24040. };
  24041. var isListBlock = function(elm) {
  24042. return elm && /^(OL|UL|LI)$/.test(elm.nodeName);
  24043. };
  24044. var isNestedList = function(elm) {
  24045. return isListBlock(elm) && isListBlock(elm.parentNode);
  24046. };
  24047. var getContainerBlock = function(containerBlock) {
  24048. var containerBlockParent = containerBlock.parentNode;
  24049. if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) {
  24050. return containerBlockParent;
  24051. }
  24052. return containerBlock;
  24053. };
  24054. var isFirstOrLastLi = function(containerBlock, parentBlock, first2) {
  24055. var node = containerBlock[first2 ? "firstChild" : "lastChild"];
  24056. while (node) {
  24057. if (isElement$5(node)) {
  24058. break;
  24059. }
  24060. node = node[first2 ? "nextSibling" : "previousSibling"];
  24061. }
  24062. return node === parentBlock;
  24063. };
  24064. var insert$3 = function(editor, createNewBlock, containerBlock, parentBlock, newBlockName) {
  24065. var dom2 = editor.dom;
  24066. var rng = editor.selection.getRng();
  24067. if (containerBlock === editor.getBody()) {
  24068. return;
  24069. }
  24070. if (isNestedList(containerBlock)) {
  24071. newBlockName = "LI";
  24072. }
  24073. var newBlock = newBlockName ? createNewBlock(newBlockName) : dom2.create("BR");
  24074. if (isFirstOrLastLi(containerBlock, parentBlock, true) && isFirstOrLastLi(containerBlock, parentBlock, false)) {
  24075. if (hasParent(containerBlock, "LI")) {
  24076. var containerBlockParent = getContainerBlock(containerBlock);
  24077. dom2.insertAfter(newBlock, containerBlockParent);
  24078. if (isFirstChild(containerBlock)) {
  24079. dom2.remove(containerBlockParent);
  24080. } else {
  24081. dom2.remove(containerBlock);
  24082. }
  24083. } else {
  24084. dom2.replace(newBlock, containerBlock);
  24085. }
  24086. } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) {
  24087. if (hasParent(containerBlock, "LI")) {
  24088. dom2.insertAfter(newBlock, getContainerBlock(containerBlock));
  24089. newBlock.appendChild(dom2.doc.createTextNode(" "));
  24090. newBlock.appendChild(containerBlock);
  24091. } else {
  24092. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  24093. }
  24094. dom2.remove(parentBlock);
  24095. } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) {
  24096. dom2.insertAfter(newBlock, getContainerBlock(containerBlock));
  24097. dom2.remove(parentBlock);
  24098. } else {
  24099. containerBlock = getContainerBlock(containerBlock);
  24100. var tmpRng = rng.cloneRange();
  24101. tmpRng.setStartAfter(parentBlock);
  24102. tmpRng.setEndAfter(containerBlock);
  24103. var fragment = tmpRng.extractContents();
  24104. if (newBlockName === "LI" && hasFirstChild(fragment, "LI")) {
  24105. newBlock = fragment.firstChild;
  24106. dom2.insertAfter(fragment, containerBlock);
  24107. } else {
  24108. dom2.insertAfter(fragment, containerBlock);
  24109. dom2.insertAfter(newBlock, containerBlock);
  24110. }
  24111. dom2.remove(parentBlock);
  24112. }
  24113. moveToCaretPosition(editor, newBlock);
  24114. };
  24115. var trimZwsp = function(fragment) {
  24116. each$k(descendants$1(SugarElement.fromDom(fragment), isText$8), function(text) {
  24117. var rawNode = text.dom;
  24118. rawNode.nodeValue = trim$2(rawNode.nodeValue);
  24119. });
  24120. };
  24121. var isEmptyAnchor = function(dom2, elm) {
  24122. return elm && elm.nodeName === "A" && dom2.isEmpty(elm);
  24123. };
  24124. var isTableCell = function(node) {
  24125. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
  24126. };
  24127. var emptyBlock = function(elm) {
  24128. elm.innerHTML = '<br data-mce-bogus="1">';
  24129. };
  24130. var containerAndSiblingName = function(container, nodeName) {
  24131. return container.nodeName === nodeName || container.previousSibling && container.previousSibling.nodeName === nodeName;
  24132. };
  24133. var canSplitBlock = function(dom2, node) {
  24134. return node && dom2.isBlock(node) && !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) && !/^(fixed|absolute)/i.test(node.style.position) && dom2.getContentEditable(node) !== "true";
  24135. };
  24136. var trimInlineElementsOnLeftSideOfBlock = function(dom2, nonEmptyElementsMap, block) {
  24137. var node = block;
  24138. var firstChilds = [];
  24139. var i;
  24140. if (!node) {
  24141. return;
  24142. }
  24143. while (node = node.firstChild) {
  24144. if (dom2.isBlock(node)) {
  24145. return;
  24146. }
  24147. if (isElement$5(node) && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  24148. firstChilds.push(node);
  24149. }
  24150. }
  24151. i = firstChilds.length;
  24152. while (i--) {
  24153. node = firstChilds[i];
  24154. if (!node.hasChildNodes() || node.firstChild === node.lastChild && node.firstChild.nodeValue === "") {
  24155. dom2.remove(node);
  24156. } else {
  24157. if (isEmptyAnchor(dom2, node)) {
  24158. dom2.remove(node);
  24159. }
  24160. }
  24161. }
  24162. };
  24163. var normalizeZwspOffset = function(start2, container, offset) {
  24164. if (isText$7(container) === false) {
  24165. return offset;
  24166. } else if (start2) {
  24167. return offset === 1 && container.data.charAt(offset - 1) === ZWSP$1 ? 0 : offset;
  24168. } else {
  24169. return offset === container.data.length - 1 && container.data.charAt(offset) === ZWSP$1 ? container.data.length : offset;
  24170. }
  24171. };
  24172. var includeZwspInRange = function(rng) {
  24173. var newRng = rng.cloneRange();
  24174. newRng.setStart(rng.startContainer, normalizeZwspOffset(true, rng.startContainer, rng.startOffset));
  24175. newRng.setEnd(rng.endContainer, normalizeZwspOffset(false, rng.endContainer, rng.endOffset));
  24176. return newRng;
  24177. };
  24178. var trimLeadingLineBreaks = function(node) {
  24179. do {
  24180. if (isText$7(node)) {
  24181. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, "");
  24182. }
  24183. node = node.firstChild;
  24184. } while (node);
  24185. };
  24186. var getEditableRoot = function(dom2, node) {
  24187. var root = dom2.getRoot();
  24188. var parent2, editableRoot;
  24189. parent2 = node;
  24190. while (parent2 !== root && dom2.getContentEditable(parent2) !== "false") {
  24191. if (dom2.getContentEditable(parent2) === "true") {
  24192. editableRoot = parent2;
  24193. }
  24194. parent2 = parent2.parentNode;
  24195. }
  24196. return parent2 !== root ? editableRoot : root;
  24197. };
  24198. var applyAttributes = function(editor, node, forcedRootBlockAttrs) {
  24199. var dom2 = editor.dom;
  24200. Optional.from(forcedRootBlockAttrs.style).map(dom2.parseStyle).each(function(attrStyles) {
  24201. var currentStyles = getAllRaw(SugarElement.fromDom(node));
  24202. var newStyles = __assign(__assign({}, currentStyles), attrStyles);
  24203. dom2.setStyles(node, newStyles);
  24204. });
  24205. var attrClassesOpt = Optional.from(forcedRootBlockAttrs.class).map(function(attrClasses) {
  24206. return attrClasses.split(/\s+/);
  24207. });
  24208. var currentClassesOpt = Optional.from(node.className).map(function(currentClasses) {
  24209. return filter$4(currentClasses.split(/\s+/), function(clazz) {
  24210. return clazz !== "";
  24211. });
  24212. });
  24213. lift2(attrClassesOpt, currentClassesOpt, function(attrClasses, currentClasses) {
  24214. var filteredClasses = filter$4(currentClasses, function(clazz) {
  24215. return !contains$3(attrClasses, clazz);
  24216. });
  24217. var newClasses = __spreadArray(__spreadArray([], attrClasses, true), filteredClasses, true);
  24218. dom2.setAttrib(node, "class", newClasses.join(" "));
  24219. });
  24220. var appliedAttrs = [
  24221. "style",
  24222. "class"
  24223. ];
  24224. var remainingAttrs = filter$3(forcedRootBlockAttrs, function(_, attrs) {
  24225. return !contains$3(appliedAttrs, attrs);
  24226. });
  24227. dom2.setAttribs(node, remainingAttrs);
  24228. };
  24229. var setForcedBlockAttrs = function(editor, node) {
  24230. var forcedRootBlockName = getForcedRootBlock(editor);
  24231. if (forcedRootBlockName && forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()) {
  24232. var forcedRootBlockAttrs = getForcedRootBlockAttrs(editor);
  24233. applyAttributes(editor, node, forcedRootBlockAttrs);
  24234. }
  24235. };
  24236. var wrapSelfAndSiblingsInDefaultBlock = function(editor, newBlockName, rng, container, offset) {
  24237. var newBlock, parentBlock, startNode, node, next, rootBlockName;
  24238. var blockName = newBlockName || "P";
  24239. var dom2 = editor.dom, editableRoot = getEditableRoot(dom2, container);
  24240. parentBlock = dom2.getParent(container, dom2.isBlock);
  24241. if (!parentBlock || !canSplitBlock(dom2, parentBlock)) {
  24242. parentBlock = parentBlock || editableRoot;
  24243. if (parentBlock === editor.getBody() || isTableCell(parentBlock)) {
  24244. rootBlockName = parentBlock.nodeName.toLowerCase();
  24245. } else {
  24246. rootBlockName = parentBlock.parentNode.nodeName.toLowerCase();
  24247. }
  24248. if (!parentBlock.hasChildNodes()) {
  24249. newBlock = dom2.create(blockName);
  24250. setForcedBlockAttrs(editor, newBlock);
  24251. parentBlock.appendChild(newBlock);
  24252. rng.setStart(newBlock, 0);
  24253. rng.setEnd(newBlock, 0);
  24254. return newBlock;
  24255. }
  24256. node = container;
  24257. while (node.parentNode !== parentBlock) {
  24258. node = node.parentNode;
  24259. }
  24260. while (node && !dom2.isBlock(node)) {
  24261. startNode = node;
  24262. node = node.previousSibling;
  24263. }
  24264. if (startNode && editor.schema.isValidChild(rootBlockName, blockName.toLowerCase())) {
  24265. newBlock = dom2.create(blockName);
  24266. setForcedBlockAttrs(editor, newBlock);
  24267. startNode.parentNode.insertBefore(newBlock, startNode);
  24268. node = startNode;
  24269. while (node && !dom2.isBlock(node)) {
  24270. next = node.nextSibling;
  24271. newBlock.appendChild(node);
  24272. node = next;
  24273. }
  24274. rng.setStart(container, offset);
  24275. rng.setEnd(container, offset);
  24276. }
  24277. }
  24278. return container;
  24279. };
  24280. var addBrToBlockIfNeeded = function(dom2, block) {
  24281. block.normalize();
  24282. var lastChild2 = block.lastChild;
  24283. if (!lastChild2 || /^(left|right)$/gi.test(dom2.getStyle(lastChild2, "float", true))) {
  24284. dom2.add(block, "br");
  24285. }
  24286. };
  24287. var insert$2 = function(editor, evt) {
  24288. var tmpRng, container, offset, parentBlock;
  24289. var newBlock, fragment, containerBlock, parentBlockName, newBlockName, isAfterLastNodeInContainer;
  24290. var dom2 = editor.dom;
  24291. var schema = editor.schema, nonEmptyElementsMap = schema.getNonEmptyElements();
  24292. var rng = editor.selection.getRng();
  24293. var createNewBlock = function(name2) {
  24294. var node = container, block, clonedNode, caretNode;
  24295. var textInlineElements = schema.getTextInlineElements();
  24296. if (name2 || parentBlockName === "TABLE" || parentBlockName === "HR") {
  24297. block = dom2.create(name2 || newBlockName);
  24298. } else {
  24299. block = parentBlock.cloneNode(false);
  24300. }
  24301. caretNode = block;
  24302. if (shouldKeepStyles(editor) === false) {
  24303. dom2.setAttrib(block, "style", null);
  24304. dom2.setAttrib(block, "class", null);
  24305. } else {
  24306. do {
  24307. if (textInlineElements[node.nodeName]) {
  24308. if (isCaretNode(node) || isBookmarkNode$1(node)) {
  24309. continue;
  24310. }
  24311. clonedNode = node.cloneNode(false);
  24312. dom2.setAttrib(clonedNode, "id", "");
  24313. if (block.hasChildNodes()) {
  24314. clonedNode.appendChild(block.firstChild);
  24315. block.appendChild(clonedNode);
  24316. } else {
  24317. caretNode = clonedNode;
  24318. block.appendChild(clonedNode);
  24319. }
  24320. }
  24321. } while ((node = node.parentNode) && node !== editableRoot);
  24322. }
  24323. setForcedBlockAttrs(editor, block);
  24324. emptyBlock(caretNode);
  24325. return block;
  24326. };
  24327. var isCaretAtStartOrEndOfBlock = function(start2) {
  24328. var node, name2;
  24329. var normalizedOffset = normalizeZwspOffset(start2, container, offset);
  24330. if (isText$7(container) && (start2 ? normalizedOffset > 0 : normalizedOffset < container.nodeValue.length)) {
  24331. return false;
  24332. }
  24333. if (container.parentNode === parentBlock && isAfterLastNodeInContainer && !start2) {
  24334. return true;
  24335. }
  24336. if (start2 && isElement$5(container) && container === parentBlock.firstChild) {
  24337. return true;
  24338. }
  24339. if (containerAndSiblingName(container, "TABLE") || containerAndSiblingName(container, "HR")) {
  24340. return isAfterLastNodeInContainer && !start2 || !isAfterLastNodeInContainer && start2;
  24341. }
  24342. var walker = new DomTreeWalker(container, parentBlock);
  24343. if (isText$7(container)) {
  24344. if (start2 && normalizedOffset === 0) {
  24345. walker.prev();
  24346. } else if (!start2 && normalizedOffset === container.nodeValue.length) {
  24347. walker.next();
  24348. }
  24349. }
  24350. while (node = walker.current()) {
  24351. if (isElement$5(node)) {
  24352. if (!node.getAttribute("data-mce-bogus")) {
  24353. name2 = node.nodeName.toLowerCase();
  24354. if (nonEmptyElementsMap[name2] && name2 !== "br") {
  24355. return false;
  24356. }
  24357. }
  24358. } else if (isText$7(node) && !isWhitespaceText(node.nodeValue)) {
  24359. return false;
  24360. }
  24361. if (start2) {
  24362. walker.prev();
  24363. } else {
  24364. walker.next();
  24365. }
  24366. }
  24367. return true;
  24368. };
  24369. var insertNewBlockAfter = function() {
  24370. if (/^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) && containerBlockName !== "HGROUP") {
  24371. newBlock = createNewBlock(newBlockName);
  24372. } else {
  24373. newBlock = createNewBlock();
  24374. }
  24375. if (shouldEndContainerOnEmptyBlock(editor) && canSplitBlock(dom2, containerBlock) && dom2.isEmpty(parentBlock)) {
  24376. newBlock = dom2.split(containerBlock, parentBlock);
  24377. } else {
  24378. dom2.insertAfter(newBlock, parentBlock);
  24379. }
  24380. moveToCaretPosition(editor, newBlock);
  24381. };
  24382. normalize$2(dom2, rng).each(function(normRng) {
  24383. rng.setStart(normRng.startContainer, normRng.startOffset);
  24384. rng.setEnd(normRng.endContainer, normRng.endOffset);
  24385. });
  24386. container = rng.startContainer;
  24387. offset = rng.startOffset;
  24388. newBlockName = getForcedRootBlock(editor);
  24389. var shiftKey = !!(evt && evt.shiftKey);
  24390. var ctrlKey = !!(evt && evt.ctrlKey);
  24391. if (isElement$5(container) && container.hasChildNodes()) {
  24392. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  24393. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  24394. if (isAfterLastNodeInContainer && isText$7(container)) {
  24395. offset = container.nodeValue.length;
  24396. } else {
  24397. offset = 0;
  24398. }
  24399. }
  24400. var editableRoot = getEditableRoot(dom2, container);
  24401. if (!editableRoot) {
  24402. return;
  24403. }
  24404. if (newBlockName && !shiftKey || !newBlockName && shiftKey) {
  24405. container = wrapSelfAndSiblingsInDefaultBlock(editor, newBlockName, rng, container, offset);
  24406. }
  24407. parentBlock = dom2.getParent(container, dom2.isBlock);
  24408. containerBlock = parentBlock ? dom2.getParent(parentBlock.parentNode, dom2.isBlock) : null;
  24409. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : "";
  24410. var containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : "";
  24411. if (containerBlockName === "LI" && !ctrlKey) {
  24412. parentBlock = containerBlock;
  24413. containerBlock = containerBlock.parentNode;
  24414. parentBlockName = containerBlockName;
  24415. }
  24416. if (/^(LI|DT|DD)$/.test(parentBlockName)) {
  24417. if (dom2.isEmpty(parentBlock)) {
  24418. insert$3(editor, createNewBlock, containerBlock, parentBlock, newBlockName);
  24419. return;
  24420. }
  24421. }
  24422. if (newBlockName && parentBlock === editor.getBody()) {
  24423. return;
  24424. }
  24425. newBlockName = newBlockName || "P";
  24426. if (isCaretContainerBlock$1(parentBlock)) {
  24427. newBlock = showCaretContainerBlock(parentBlock);
  24428. if (dom2.isEmpty(parentBlock)) {
  24429. emptyBlock(parentBlock);
  24430. }
  24431. setForcedBlockAttrs(editor, newBlock);
  24432. moveToCaretPosition(editor, newBlock);
  24433. } else if (isCaretAtStartOrEndOfBlock()) {
  24434. insertNewBlockAfter();
  24435. } else if (isCaretAtStartOrEndOfBlock(true)) {
  24436. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  24437. moveToCaretPosition(editor, containerAndSiblingName(parentBlock, "HR") ? newBlock : parentBlock);
  24438. } else {
  24439. tmpRng = includeZwspInRange(rng).cloneRange();
  24440. tmpRng.setEndAfter(parentBlock);
  24441. fragment = tmpRng.extractContents();
  24442. trimZwsp(fragment);
  24443. trimLeadingLineBreaks(fragment);
  24444. newBlock = fragment.firstChild;
  24445. dom2.insertAfter(fragment, parentBlock);
  24446. trimInlineElementsOnLeftSideOfBlock(dom2, nonEmptyElementsMap, newBlock);
  24447. addBrToBlockIfNeeded(dom2, parentBlock);
  24448. if (dom2.isEmpty(parentBlock)) {
  24449. emptyBlock(parentBlock);
  24450. }
  24451. newBlock.normalize();
  24452. if (dom2.isEmpty(newBlock)) {
  24453. dom2.remove(newBlock);
  24454. insertNewBlockAfter();
  24455. } else {
  24456. setForcedBlockAttrs(editor, newBlock);
  24457. moveToCaretPosition(editor, newBlock);
  24458. }
  24459. }
  24460. dom2.setAttrib(newBlock, "id", "");
  24461. editor.fire("NewBlock", { newBlock });
  24462. };
  24463. var hasRightSideContent = function(schema, container, parentBlock) {
  24464. var walker = new DomTreeWalker(container, parentBlock);
  24465. var node;
  24466. var nonEmptyElementsMap = schema.getNonEmptyElements();
  24467. while (node = walker.next()) {
  24468. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
  24469. return true;
  24470. }
  24471. }
  24472. };
  24473. var moveSelectionToBr = function(editor, brElm, extraBr) {
  24474. var rng = editor.dom.createRng();
  24475. if (!extraBr) {
  24476. rng.setStartAfter(brElm);
  24477. rng.setEndAfter(brElm);
  24478. } else {
  24479. rng.setStartBefore(brElm);
  24480. rng.setEndBefore(brElm);
  24481. }
  24482. editor.selection.setRng(rng);
  24483. scrollRangeIntoView(editor, rng);
  24484. };
  24485. var insertBrAtCaret = function(editor, evt) {
  24486. var selection = editor.selection;
  24487. var dom2 = editor.dom;
  24488. var rng = selection.getRng();
  24489. var brElm;
  24490. var extraBr;
  24491. normalize$2(dom2, rng).each(function(normRng) {
  24492. rng.setStart(normRng.startContainer, normRng.startOffset);
  24493. rng.setEnd(normRng.endContainer, normRng.endOffset);
  24494. });
  24495. var offset = rng.startOffset;
  24496. var container = rng.startContainer;
  24497. if (container.nodeType === 1 && container.hasChildNodes()) {
  24498. var isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  24499. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  24500. if (isAfterLastNodeInContainer && container.nodeType === 3) {
  24501. offset = container.nodeValue.length;
  24502. } else {
  24503. offset = 0;
  24504. }
  24505. }
  24506. var parentBlock = dom2.getParent(container, dom2.isBlock);
  24507. var containerBlock = parentBlock ? dom2.getParent(parentBlock.parentNode, dom2.isBlock) : null;
  24508. var containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : "";
  24509. var isControlKey = !!(evt && evt.ctrlKey);
  24510. if (containerBlockName === "LI" && !isControlKey) {
  24511. parentBlock = containerBlock;
  24512. }
  24513. if (container && container.nodeType === 3 && offset >= container.nodeValue.length) {
  24514. if (!hasRightSideContent(editor.schema, container, parentBlock)) {
  24515. brElm = dom2.create("br");
  24516. rng.insertNode(brElm);
  24517. rng.setStartAfter(brElm);
  24518. rng.setEndAfter(brElm);
  24519. extraBr = true;
  24520. }
  24521. }
  24522. brElm = dom2.create("br");
  24523. rangeInsertNode(dom2, rng, brElm);
  24524. moveSelectionToBr(editor, brElm, extraBr);
  24525. editor.undoManager.add();
  24526. };
  24527. var insertBrBefore = function(editor, inline) {
  24528. var br = SugarElement.fromTag("br");
  24529. before$4(SugarElement.fromDom(inline), br);
  24530. editor.undoManager.add();
  24531. };
  24532. var insertBrAfter = function(editor, inline) {
  24533. if (!hasBrAfter(editor.getBody(), inline)) {
  24534. after$3(SugarElement.fromDom(inline), SugarElement.fromTag("br"));
  24535. }
  24536. var br = SugarElement.fromTag("br");
  24537. after$3(SugarElement.fromDom(inline), br);
  24538. moveSelectionToBr(editor, br.dom, false);
  24539. editor.undoManager.add();
  24540. };
  24541. var isBeforeBr = function(pos) {
  24542. return isBr$5(pos.getNode());
  24543. };
  24544. var hasBrAfter = function(rootNode, startNode) {
  24545. if (isBeforeBr(CaretPosition.after(startNode))) {
  24546. return true;
  24547. } else {
  24548. return nextPosition(rootNode, CaretPosition.after(startNode)).map(function(pos) {
  24549. return isBr$5(pos.getNode());
  24550. }).getOr(false);
  24551. }
  24552. };
  24553. var isAnchorLink = function(elm) {
  24554. return elm && elm.nodeName === "A" && "href" in elm;
  24555. };
  24556. var isInsideAnchor = function(location) {
  24557. return location.fold(never, isAnchorLink, isAnchorLink, never);
  24558. };
  24559. var readInlineAnchorLocation = function(editor) {
  24560. var isInlineTarget$1 = curry(isInlineTarget, editor);
  24561. var position = CaretPosition.fromRangeStart(editor.selection.getRng());
  24562. return readLocation(isInlineTarget$1, editor.getBody(), position).filter(isInsideAnchor);
  24563. };
  24564. var insertBrOutsideAnchor = function(editor, location) {
  24565. location.fold(noop, curry(insertBrBefore, editor), curry(insertBrAfter, editor), noop);
  24566. };
  24567. var insert$1 = function(editor, evt) {
  24568. var anchorLocation = readInlineAnchorLocation(editor);
  24569. if (anchorLocation.isSome()) {
  24570. anchorLocation.each(curry(insertBrOutsideAnchor, editor));
  24571. } else {
  24572. insertBrAtCaret(editor, evt);
  24573. }
  24574. };
  24575. var matchesSelector = function(editor, selector) {
  24576. return getParentBlock(editor).filter(function(parentBlock) {
  24577. return selector.length > 0 && is$2(SugarElement.fromDom(parentBlock), selector);
  24578. }).isSome();
  24579. };
  24580. var shouldInsertBr = function(editor) {
  24581. return matchesSelector(editor, getBrNewLineSelector(editor));
  24582. };
  24583. var shouldBlockNewLine$1 = function(editor) {
  24584. return matchesSelector(editor, getNoNewLineSelector(editor));
  24585. };
  24586. var newLineAction = Adt.generate([
  24587. { br: [] },
  24588. { block: [] },
  24589. { none: [] }
  24590. ]);
  24591. var shouldBlockNewLine = function(editor, _shiftKey) {
  24592. return shouldBlockNewLine$1(editor);
  24593. };
  24594. var isBrMode = function(requiredState) {
  24595. return function(editor, _shiftKey) {
  24596. var brMode = getForcedRootBlock(editor) === "";
  24597. return brMode === requiredState;
  24598. };
  24599. };
  24600. var inListBlock = function(requiredState) {
  24601. return function(editor, _shiftKey) {
  24602. return isListItemParentBlock(editor) === requiredState;
  24603. };
  24604. };
  24605. var inBlock = function(blockName, requiredState) {
  24606. return function(editor, _shiftKey) {
  24607. var state = getParentBlockName(editor) === blockName.toUpperCase();
  24608. return state === requiredState;
  24609. };
  24610. };
  24611. var inPreBlock = function(requiredState) {
  24612. return inBlock("pre", requiredState);
  24613. };
  24614. var inSummaryBlock = function() {
  24615. return inBlock("summary", true);
  24616. };
  24617. var shouldPutBrInPre = function(requiredState) {
  24618. return function(editor, _shiftKey) {
  24619. return shouldPutBrInPre$1(editor) === requiredState;
  24620. };
  24621. };
  24622. var inBrContext = function(editor, _shiftKey) {
  24623. return shouldInsertBr(editor);
  24624. };
  24625. var hasShiftKey = function(_editor, shiftKey) {
  24626. return shiftKey;
  24627. };
  24628. var canInsertIntoEditableRoot = function(editor) {
  24629. var forcedRootBlock = getForcedRootBlock(editor);
  24630. var rootEditable = getEditableRoot$1(editor.dom, editor.selection.getStart());
  24631. return rootEditable && editor.schema.isValidChild(rootEditable.nodeName, forcedRootBlock ? forcedRootBlock : "P");
  24632. };
  24633. var match = function(predicates, action2) {
  24634. return function(editor, shiftKey) {
  24635. var isMatch = foldl(predicates, function(res, p) {
  24636. return res && p(editor, shiftKey);
  24637. }, true);
  24638. return isMatch ? Optional.some(action2) : Optional.none();
  24639. };
  24640. };
  24641. var getAction = function(editor, evt) {
  24642. return evaluateUntil([
  24643. match([shouldBlockNewLine], newLineAction.none()),
  24644. match([inSummaryBlock()], newLineAction.br()),
  24645. match([
  24646. inPreBlock(true),
  24647. shouldPutBrInPre(false),
  24648. hasShiftKey
  24649. ], newLineAction.br()),
  24650. match([
  24651. inPreBlock(true),
  24652. shouldPutBrInPre(false)
  24653. ], newLineAction.block()),
  24654. match([
  24655. inPreBlock(true),
  24656. shouldPutBrInPre(true),
  24657. hasShiftKey
  24658. ], newLineAction.block()),
  24659. match([
  24660. inPreBlock(true),
  24661. shouldPutBrInPre(true)
  24662. ], newLineAction.br()),
  24663. match([
  24664. inListBlock(true),
  24665. hasShiftKey
  24666. ], newLineAction.br()),
  24667. match([inListBlock(true)], newLineAction.block()),
  24668. match([
  24669. isBrMode(true),
  24670. hasShiftKey,
  24671. canInsertIntoEditableRoot
  24672. ], newLineAction.block()),
  24673. match([isBrMode(true)], newLineAction.br()),
  24674. match([inBrContext], newLineAction.br()),
  24675. match([
  24676. isBrMode(false),
  24677. hasShiftKey
  24678. ], newLineAction.br()),
  24679. match([canInsertIntoEditableRoot], newLineAction.block())
  24680. ], [
  24681. editor,
  24682. !!(evt && evt.shiftKey)
  24683. ]).getOr(newLineAction.none());
  24684. };
  24685. var insert = function(editor, evt) {
  24686. getAction(editor, evt).fold(function() {
  24687. insert$1(editor, evt);
  24688. }, function() {
  24689. insert$2(editor, evt);
  24690. }, noop);
  24691. };
  24692. var handleEnterKeyEvent = function(editor, event) {
  24693. if (event.isDefaultPrevented()) {
  24694. return;
  24695. }
  24696. event.preventDefault();
  24697. endTypingLevelIgnoreLocks(editor.undoManager);
  24698. editor.undoManager.transact(function() {
  24699. if (editor.selection.isCollapsed() === false) {
  24700. editor.execCommand("Delete");
  24701. }
  24702. insert(editor, event);
  24703. });
  24704. };
  24705. var setup$9 = function(editor) {
  24706. editor.on("keydown", function(event) {
  24707. if (event.keyCode === VK.ENTER) {
  24708. handleEnterKeyEvent(editor, event);
  24709. }
  24710. });
  24711. };
  24712. var executeKeydownOverride$1 = function(editor, caret, evt) {
  24713. execute([
  24714. {
  24715. keyCode: VK.END,
  24716. action: action(moveToLineEndPoint$1, editor, true)
  24717. },
  24718. {
  24719. keyCode: VK.HOME,
  24720. action: action(moveToLineEndPoint$1, editor, false)
  24721. },
  24722. {
  24723. keyCode: VK.END,
  24724. action: action(moveToLineEndPoint, editor, true)
  24725. },
  24726. {
  24727. keyCode: VK.HOME,
  24728. action: action(moveToLineEndPoint, editor, false)
  24729. },
  24730. {
  24731. keyCode: VK.END,
  24732. action: action(moveToLineEndPoint$2, editor, true, caret)
  24733. },
  24734. {
  24735. keyCode: VK.HOME,
  24736. action: action(moveToLineEndPoint$2, editor, false, caret)
  24737. }
  24738. ], evt).each(function(_) {
  24739. evt.preventDefault();
  24740. });
  24741. };
  24742. var setup$8 = function(editor, caret) {
  24743. editor.on("keydown", function(evt) {
  24744. if (evt.isDefaultPrevented() === false) {
  24745. executeKeydownOverride$1(editor, caret, evt);
  24746. }
  24747. });
  24748. };
  24749. var browser = detect().browser;
  24750. var setupIeInput = function(editor) {
  24751. var keypressThrotter = first(function() {
  24752. if (!editor.composing) {
  24753. normalizeNbspsInEditor(editor);
  24754. }
  24755. }, 0);
  24756. if (browser.isIE()) {
  24757. editor.on("keypress", function(_e) {
  24758. keypressThrotter.throttle();
  24759. });
  24760. editor.on("remove", function(_e) {
  24761. keypressThrotter.cancel();
  24762. });
  24763. }
  24764. };
  24765. var setup$7 = function(editor) {
  24766. setupIeInput(editor);
  24767. editor.on("input", function(e) {
  24768. if (e.isComposing === false) {
  24769. normalizeNbspsInEditor(editor);
  24770. }
  24771. });
  24772. };
  24773. var platform = detect();
  24774. var executeKeyupAction = function(editor, caret, evt) {
  24775. execute([
  24776. {
  24777. keyCode: VK.PAGE_UP,
  24778. action: action(moveToLineEndPoint$2, editor, false, caret)
  24779. },
  24780. {
  24781. keyCode: VK.PAGE_DOWN,
  24782. action: action(moveToLineEndPoint$2, editor, true, caret)
  24783. }
  24784. ], evt);
  24785. };
  24786. var stopImmediatePropagation = function(e) {
  24787. return e.stopImmediatePropagation();
  24788. };
  24789. var isPageUpDown = function(evt) {
  24790. return evt.keyCode === VK.PAGE_UP || evt.keyCode === VK.PAGE_DOWN;
  24791. };
  24792. var setNodeChangeBlocker = function(blocked, editor, block) {
  24793. if (block && !blocked.get()) {
  24794. editor.on("NodeChange", stopImmediatePropagation, true);
  24795. } else if (!block && blocked.get()) {
  24796. editor.off("NodeChange", stopImmediatePropagation);
  24797. }
  24798. blocked.set(block);
  24799. };
  24800. var setup$6 = function(editor, caret) {
  24801. if (platform.os.isOSX()) {
  24802. return;
  24803. }
  24804. var blocked = Cell(false);
  24805. editor.on("keydown", function(evt) {
  24806. if (isPageUpDown(evt)) {
  24807. setNodeChangeBlocker(blocked, editor, true);
  24808. }
  24809. });
  24810. editor.on("keyup", function(evt) {
  24811. if (evt.isDefaultPrevented() === false) {
  24812. executeKeyupAction(editor, caret, evt);
  24813. }
  24814. if (isPageUpDown(evt) && blocked.get()) {
  24815. setNodeChangeBlocker(blocked, editor, false);
  24816. editor.nodeChanged();
  24817. }
  24818. });
  24819. };
  24820. var insertTextAtPosition = function(text, pos) {
  24821. var container = pos.container();
  24822. var offset = pos.offset();
  24823. if (isText$7(container)) {
  24824. container.insertData(offset, text);
  24825. return Optional.some(CaretPosition(container, offset + text.length));
  24826. } else {
  24827. return getElementFromPosition(pos).map(function(elm) {
  24828. var textNode = SugarElement.fromText(text);
  24829. if (pos.isAtEnd()) {
  24830. after$3(elm, textNode);
  24831. } else {
  24832. before$4(elm, textNode);
  24833. }
  24834. return CaretPosition(textNode.dom, text.length);
  24835. });
  24836. }
  24837. };
  24838. var insertNbspAtPosition = curry(insertTextAtPosition, nbsp);
  24839. var insertSpaceAtPosition = curry(insertTextAtPosition, " ");
  24840. var locationToCaretPosition = function(root) {
  24841. return function(location) {
  24842. return location.fold(function(element) {
  24843. return prevPosition(root.dom, CaretPosition.before(element));
  24844. }, function(element) {
  24845. return firstPositionIn(element);
  24846. }, function(element) {
  24847. return lastPositionIn(element);
  24848. }, function(element) {
  24849. return nextPosition(root.dom, CaretPosition.after(element));
  24850. });
  24851. };
  24852. };
  24853. var insertInlineBoundarySpaceOrNbsp = function(root, pos) {
  24854. return function(checkPos) {
  24855. return needsToHaveNbsp(root, checkPos) ? insertNbspAtPosition(pos) : insertSpaceAtPosition(pos);
  24856. };
  24857. };
  24858. var setSelection = function(editor) {
  24859. return function(pos) {
  24860. editor.selection.setRng(pos.toRange());
  24861. editor.nodeChanged();
  24862. return true;
  24863. };
  24864. };
  24865. var insertSpaceOrNbspAtSelection = function(editor) {
  24866. var pos = CaretPosition.fromRangeStart(editor.selection.getRng());
  24867. var root = SugarElement.fromDom(editor.getBody());
  24868. if (editor.selection.isCollapsed()) {
  24869. var isInlineTarget$1 = curry(isInlineTarget, editor);
  24870. var caretPosition = CaretPosition.fromRangeStart(editor.selection.getRng());
  24871. return readLocation(isInlineTarget$1, editor.getBody(), caretPosition).bind(locationToCaretPosition(root)).bind(insertInlineBoundarySpaceOrNbsp(root, pos)).exists(setSelection(editor));
  24872. } else {
  24873. return false;
  24874. }
  24875. };
  24876. var executeKeydownOverride = function(editor, evt) {
  24877. execute([{
  24878. keyCode: VK.SPACEBAR,
  24879. action: action(insertSpaceOrNbspAtSelection, editor)
  24880. }], evt).each(function(_) {
  24881. evt.preventDefault();
  24882. });
  24883. };
  24884. var setup$5 = function(editor) {
  24885. editor.on("keydown", function(evt) {
  24886. if (evt.isDefaultPrevented() === false) {
  24887. executeKeydownOverride(editor, evt);
  24888. }
  24889. });
  24890. };
  24891. var registerKeyboardOverrides = function(editor) {
  24892. var caret = setupSelectedState(editor);
  24893. setup$c(editor);
  24894. setup$b(editor, caret);
  24895. setup$a(editor, caret);
  24896. setup$9(editor);
  24897. setup$5(editor);
  24898. setup$7(editor);
  24899. setup$8(editor, caret);
  24900. setup$6(editor, caret);
  24901. return caret;
  24902. };
  24903. var setup$4 = function(editor) {
  24904. if (!isRtc(editor)) {
  24905. return registerKeyboardOverrides(editor);
  24906. } else {
  24907. return Cell(null);
  24908. }
  24909. };
  24910. var NodeChange = function() {
  24911. function NodeChange2(editor) {
  24912. this.lastPath = [];
  24913. this.editor = editor;
  24914. var lastRng;
  24915. var self2 = this;
  24916. if (!("onselectionchange" in editor.getDoc())) {
  24917. editor.on("NodeChange click mouseup keyup focus", function(e) {
  24918. var nativeRng = editor.selection.getRng();
  24919. var fakeRng = {
  24920. startContainer: nativeRng.startContainer,
  24921. startOffset: nativeRng.startOffset,
  24922. endContainer: nativeRng.endContainer,
  24923. endOffset: nativeRng.endOffset
  24924. };
  24925. if (e.type === "nodechange" || !isEq$4(fakeRng, lastRng)) {
  24926. editor.fire("SelectionChange");
  24927. }
  24928. lastRng = fakeRng;
  24929. });
  24930. }
  24931. editor.on("contextmenu", function() {
  24932. editor.fire("SelectionChange");
  24933. });
  24934. editor.on("SelectionChange", function() {
  24935. var startElm = editor.selection.getStart(true);
  24936. if (!startElm || !Env.range && editor.selection.isCollapsed()) {
  24937. return;
  24938. }
  24939. if (hasAnyRanges(editor) && !self2.isSameElementPath(startElm) && editor.dom.isChildOf(startElm, editor.getBody())) {
  24940. editor.nodeChanged({ selectionChange: true });
  24941. }
  24942. });
  24943. editor.on("mouseup", function(e) {
  24944. if (!e.isDefaultPrevented() && hasAnyRanges(editor)) {
  24945. if (editor.selection.getNode().nodeName === "IMG") {
  24946. Delay.setEditorTimeout(editor, function() {
  24947. editor.nodeChanged();
  24948. });
  24949. } else {
  24950. editor.nodeChanged();
  24951. }
  24952. }
  24953. });
  24954. }
  24955. NodeChange2.prototype.nodeChanged = function(args) {
  24956. var selection = this.editor.selection;
  24957. var node, parents2, root;
  24958. if (this.editor.initialized && selection && !shouldDisableNodeChange(this.editor) && !this.editor.mode.isReadOnly()) {
  24959. root = this.editor.getBody();
  24960. node = selection.getStart(true) || root;
  24961. if (node.ownerDocument !== this.editor.getDoc() || !this.editor.dom.isChildOf(node, root)) {
  24962. node = root;
  24963. }
  24964. parents2 = [];
  24965. this.editor.dom.getParent(node, function(node2) {
  24966. if (node2 === root) {
  24967. return true;
  24968. }
  24969. parents2.push(node2);
  24970. });
  24971. args = args || {};
  24972. args.element = node;
  24973. args.parents = parents2;
  24974. this.editor.fire("NodeChange", args);
  24975. }
  24976. };
  24977. NodeChange2.prototype.isSameElementPath = function(startElm) {
  24978. var i;
  24979. var currentPath = this.editor.$(startElm).parentsUntil(this.editor.getBody()).add(startElm);
  24980. if (currentPath.length === this.lastPath.length) {
  24981. for (i = currentPath.length; i >= 0; i--) {
  24982. if (currentPath[i] !== this.lastPath[i]) {
  24983. break;
  24984. }
  24985. }
  24986. if (i === -1) {
  24987. this.lastPath = currentPath;
  24988. return true;
  24989. }
  24990. }
  24991. this.lastPath = currentPath;
  24992. return false;
  24993. };
  24994. return NodeChange2;
  24995. }();
  24996. var preventSummaryToggle = function(editor) {
  24997. editor.on("click", function(e) {
  24998. if (editor.dom.getParent(e.target, "details")) {
  24999. e.preventDefault();
  25000. }
  25001. });
  25002. };
  25003. var filterDetails = function(editor) {
  25004. editor.parser.addNodeFilter("details", function(elms) {
  25005. each$k(elms, function(details) {
  25006. details.attr("data-mce-open", details.attr("open"));
  25007. details.attr("open", "open");
  25008. });
  25009. });
  25010. editor.serializer.addNodeFilter("details", function(elms) {
  25011. each$k(elms, function(details) {
  25012. var open = details.attr("data-mce-open");
  25013. details.attr("open", isString$1(open) ? open : null);
  25014. details.attr("data-mce-open", null);
  25015. });
  25016. });
  25017. };
  25018. var setup$3 = function(editor) {
  25019. preventSummaryToggle(editor);
  25020. filterDetails(editor);
  25021. };
  25022. var isTextBlockNode = function(node) {
  25023. return isElement$5(node) && isTextBlock$2(SugarElement.fromDom(node));
  25024. };
  25025. var normalizeSelection = function(editor) {
  25026. var rng = editor.selection.getRng();
  25027. var startPos = CaretPosition.fromRangeStart(rng);
  25028. var endPos = CaretPosition.fromRangeEnd(rng);
  25029. if (CaretPosition.isElementPosition(startPos)) {
  25030. var container = startPos.container();
  25031. if (isTextBlockNode(container)) {
  25032. firstPositionIn(container).each(function(pos) {
  25033. return rng.setStart(pos.container(), pos.offset());
  25034. });
  25035. }
  25036. }
  25037. if (CaretPosition.isElementPosition(endPos)) {
  25038. var container = startPos.container();
  25039. if (isTextBlockNode(container)) {
  25040. lastPositionIn(container).each(function(pos) {
  25041. return rng.setEnd(pos.container(), pos.offset());
  25042. });
  25043. }
  25044. }
  25045. editor.selection.setRng(normalize(rng));
  25046. };
  25047. var setup$2 = function(editor) {
  25048. editor.on("click", function(e) {
  25049. if (e.detail >= 3) {
  25050. normalizeSelection(editor);
  25051. }
  25052. });
  25053. };
  25054. var getAbsolutePosition = function(elm) {
  25055. var clientRect = elm.getBoundingClientRect();
  25056. var doc2 = elm.ownerDocument;
  25057. var docElem2 = doc2.documentElement;
  25058. var win = doc2.defaultView;
  25059. return {
  25060. top: clientRect.top + win.pageYOffset - docElem2.clientTop,
  25061. left: clientRect.left + win.pageXOffset - docElem2.clientLeft
  25062. };
  25063. };
  25064. var getBodyPosition = function(editor) {
  25065. return editor.inline ? getAbsolutePosition(editor.getBody()) : {
  25066. left: 0,
  25067. top: 0
  25068. };
  25069. };
  25070. var getScrollPosition = function(editor) {
  25071. var body = editor.getBody();
  25072. return editor.inline ? {
  25073. left: body.scrollLeft,
  25074. top: body.scrollTop
  25075. } : {
  25076. left: 0,
  25077. top: 0
  25078. };
  25079. };
  25080. var getBodyScroll = function(editor) {
  25081. var body = editor.getBody(), docElm = editor.getDoc().documentElement;
  25082. var inlineScroll = {
  25083. left: body.scrollLeft,
  25084. top: body.scrollTop
  25085. };
  25086. var iframeScroll = {
  25087. left: body.scrollLeft || docElm.scrollLeft,
  25088. top: body.scrollTop || docElm.scrollTop
  25089. };
  25090. return editor.inline ? inlineScroll : iframeScroll;
  25091. };
  25092. var getMousePosition = function(editor, event) {
  25093. if (event.target.ownerDocument !== editor.getDoc()) {
  25094. var iframePosition = getAbsolutePosition(editor.getContentAreaContainer());
  25095. var scrollPosition = getBodyScroll(editor);
  25096. return {
  25097. left: event.pageX - iframePosition.left + scrollPosition.left,
  25098. top: event.pageY - iframePosition.top + scrollPosition.top
  25099. };
  25100. }
  25101. return {
  25102. left: event.pageX,
  25103. top: event.pageY
  25104. };
  25105. };
  25106. var calculatePosition = function(bodyPosition, scrollPosition, mousePosition) {
  25107. return {
  25108. pageX: mousePosition.left - bodyPosition.left + scrollPosition.left,
  25109. pageY: mousePosition.top - bodyPosition.top + scrollPosition.top
  25110. };
  25111. };
  25112. var calc = function(editor, event) {
  25113. return calculatePosition(getBodyPosition(editor), getScrollPosition(editor), getMousePosition(editor, event));
  25114. };
  25115. var isContentEditableFalse$1 = isContentEditableFalse$b, isContentEditableTrue$1 = isContentEditableTrue$4;
  25116. var isDraggable = function(rootElm, elm) {
  25117. return isContentEditableFalse$1(elm) && elm !== rootElm;
  25118. };
  25119. var isValidDropTarget = function(editor, targetElement, dragElement) {
  25120. if (targetElement === dragElement || editor.dom.isChildOf(targetElement, dragElement)) {
  25121. return false;
  25122. }
  25123. return !isContentEditableFalse$1(targetElement);
  25124. };
  25125. var cloneElement = function(elm) {
  25126. var cloneElm = elm.cloneNode(true);
  25127. cloneElm.removeAttribute("data-mce-selected");
  25128. return cloneElm;
  25129. };
  25130. var createGhost = function(editor, elm, width, height) {
  25131. var dom2 = editor.dom;
  25132. var clonedElm = elm.cloneNode(true);
  25133. dom2.setStyles(clonedElm, {
  25134. width,
  25135. height
  25136. });
  25137. dom2.setAttrib(clonedElm, "data-mce-selected", null);
  25138. var ghostElm = dom2.create("div", {
  25139. "class": "mce-drag-container",
  25140. "data-mce-bogus": "all",
  25141. "unselectable": "on",
  25142. "contenteditable": "false"
  25143. });
  25144. dom2.setStyles(ghostElm, {
  25145. position: "absolute",
  25146. opacity: 0.5,
  25147. overflow: "hidden",
  25148. border: 0,
  25149. padding: 0,
  25150. margin: 0,
  25151. width,
  25152. height
  25153. });
  25154. dom2.setStyles(clonedElm, {
  25155. margin: 0,
  25156. boxSizing: "border-box"
  25157. });
  25158. ghostElm.appendChild(clonedElm);
  25159. return ghostElm;
  25160. };
  25161. var appendGhostToBody = function(ghostElm, bodyElm) {
  25162. if (ghostElm.parentNode !== bodyElm) {
  25163. bodyElm.appendChild(ghostElm);
  25164. }
  25165. };
  25166. var moveGhost = function(ghostElm, position, width, height, maxX, maxY) {
  25167. var overflowX = 0, overflowY = 0;
  25168. ghostElm.style.left = position.pageX + "px";
  25169. ghostElm.style.top = position.pageY + "px";
  25170. if (position.pageX + width > maxX) {
  25171. overflowX = position.pageX + width - maxX;
  25172. }
  25173. if (position.pageY + height > maxY) {
  25174. overflowY = position.pageY + height - maxY;
  25175. }
  25176. ghostElm.style.width = width - overflowX + "px";
  25177. ghostElm.style.height = height - overflowY + "px";
  25178. };
  25179. var removeElement = function(elm) {
  25180. if (elm && elm.parentNode) {
  25181. elm.parentNode.removeChild(elm);
  25182. }
  25183. };
  25184. var isLeftMouseButtonPressed = function(e) {
  25185. return e.button === 0;
  25186. };
  25187. var applyRelPos = function(state, position) {
  25188. return {
  25189. pageX: position.pageX - state.relX,
  25190. pageY: position.pageY + 5
  25191. };
  25192. };
  25193. var start = function(state, editor) {
  25194. return function(e) {
  25195. if (isLeftMouseButtonPressed(e)) {
  25196. var ceElm = find$3(editor.dom.getParents(e.target), or(isContentEditableFalse$1, isContentEditableTrue$1)).getOr(null);
  25197. if (isDraggable(editor.getBody(), ceElm)) {
  25198. var elmPos = editor.dom.getPos(ceElm);
  25199. var bodyElm = editor.getBody();
  25200. var docElm = editor.getDoc().documentElement;
  25201. state.set({
  25202. element: ceElm,
  25203. dragging: false,
  25204. screenX: e.screenX,
  25205. screenY: e.screenY,
  25206. maxX: (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2,
  25207. maxY: (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2,
  25208. relX: e.pageX - elmPos.x,
  25209. relY: e.pageY - elmPos.y,
  25210. width: ceElm.offsetWidth,
  25211. height: ceElm.offsetHeight,
  25212. ghost: createGhost(editor, ceElm, ceElm.offsetWidth, ceElm.offsetHeight)
  25213. });
  25214. }
  25215. }
  25216. };
  25217. };
  25218. var move = function(state, editor) {
  25219. var throttledPlaceCaretAt = Delay.throttle(function(clientX, clientY) {
  25220. editor._selectionOverrides.hideFakeCaret();
  25221. editor.selection.placeCaretAt(clientX, clientY);
  25222. }, 0);
  25223. editor.on("remove", throttledPlaceCaretAt.stop);
  25224. return function(e) {
  25225. return state.on(function(state2) {
  25226. var movement = Math.max(Math.abs(e.screenX - state2.screenX), Math.abs(e.screenY - state2.screenY));
  25227. if (!state2.dragging && movement > 10) {
  25228. var args = editor.fire("dragstart", { target: state2.element });
  25229. if (args.isDefaultPrevented()) {
  25230. return;
  25231. }
  25232. state2.dragging = true;
  25233. editor.focus();
  25234. }
  25235. if (state2.dragging) {
  25236. var targetPos = applyRelPos(state2, calc(editor, e));
  25237. appendGhostToBody(state2.ghost, editor.getBody());
  25238. moveGhost(state2.ghost, targetPos, state2.width, state2.height, state2.maxX, state2.maxY);
  25239. throttledPlaceCaretAt(e.clientX, e.clientY);
  25240. }
  25241. });
  25242. };
  25243. };
  25244. var getRawTarget = function(selection) {
  25245. var rng = selection.getSel().getRangeAt(0);
  25246. var startContainer = rng.startContainer;
  25247. return startContainer.nodeType === 3 ? startContainer.parentNode : startContainer;
  25248. };
  25249. var drop = function(state, editor) {
  25250. return function(e) {
  25251. state.on(function(state2) {
  25252. if (state2.dragging) {
  25253. if (isValidDropTarget(editor, getRawTarget(editor.selection), state2.element)) {
  25254. var targetClone_1 = cloneElement(state2.element);
  25255. var args = editor.fire("drop", {
  25256. clientX: e.clientX,
  25257. clientY: e.clientY
  25258. });
  25259. if (!args.isDefaultPrevented()) {
  25260. editor.undoManager.transact(function() {
  25261. removeElement(state2.element);
  25262. editor.insertContent(editor.dom.getOuterHTML(targetClone_1));
  25263. editor._selectionOverrides.hideFakeCaret();
  25264. });
  25265. }
  25266. }
  25267. editor.fire("dragend");
  25268. }
  25269. });
  25270. removeDragState(state);
  25271. };
  25272. };
  25273. var stop = function(state, editor) {
  25274. return function() {
  25275. state.on(function(state2) {
  25276. if (state2.dragging) {
  25277. editor.fire("dragend");
  25278. }
  25279. });
  25280. removeDragState(state);
  25281. };
  25282. };
  25283. var removeDragState = function(state) {
  25284. state.on(function(state2) {
  25285. removeElement(state2.ghost);
  25286. });
  25287. state.clear();
  25288. };
  25289. var bindFakeDragEvents = function(editor) {
  25290. var state = value();
  25291. var pageDom = DOMUtils.DOM;
  25292. var rootDocument = document;
  25293. var dragStartHandler = start(state, editor);
  25294. var dragHandler = move(state, editor);
  25295. var dropHandler = drop(state, editor);
  25296. var dragEndHandler = stop(state, editor);
  25297. editor.on("mousedown", dragStartHandler);
  25298. editor.on("mousemove", dragHandler);
  25299. editor.on("mouseup", dropHandler);
  25300. pageDom.bind(rootDocument, "mousemove", dragHandler);
  25301. pageDom.bind(rootDocument, "mouseup", dragEndHandler);
  25302. editor.on("remove", function() {
  25303. pageDom.unbind(rootDocument, "mousemove", dragHandler);
  25304. pageDom.unbind(rootDocument, "mouseup", dragEndHandler);
  25305. });
  25306. editor.on("keydown", function(e) {
  25307. if (e.keyCode === VK.ESC) {
  25308. dragEndHandler();
  25309. }
  25310. });
  25311. };
  25312. var blockIeDrop = function(editor) {
  25313. editor.on("drop", function(e) {
  25314. var realTarget = typeof e.clientX !== "undefined" ? editor.getDoc().elementFromPoint(e.clientX, e.clientY) : null;
  25315. if (isContentEditableFalse$1(realTarget) || editor.dom.getContentEditableParent(realTarget) === "false") {
  25316. e.preventDefault();
  25317. }
  25318. });
  25319. };
  25320. var blockUnsupportedFileDrop = function(editor) {
  25321. var preventFileDrop = function(e) {
  25322. if (!e.isDefaultPrevented()) {
  25323. var dataTransfer = e.dataTransfer;
  25324. if (dataTransfer && (contains$3(dataTransfer.types, "Files") || dataTransfer.files.length > 0)) {
  25325. e.preventDefault();
  25326. if (e.type === "drop") {
  25327. displayError(editor, "Dropped file type is not supported");
  25328. }
  25329. }
  25330. }
  25331. };
  25332. var preventFileDropIfUIElement = function(e) {
  25333. if (isUIElement(editor, e.target)) {
  25334. preventFileDrop(e);
  25335. }
  25336. };
  25337. var setup2 = function() {
  25338. var pageDom = DOMUtils.DOM;
  25339. var dom2 = editor.dom;
  25340. var doc2 = document;
  25341. var editorRoot = editor.inline ? editor.getBody() : editor.getDoc();
  25342. var eventNames = [
  25343. "drop",
  25344. "dragover"
  25345. ];
  25346. each$k(eventNames, function(name2) {
  25347. pageDom.bind(doc2, name2, preventFileDropIfUIElement);
  25348. dom2.bind(editorRoot, name2, preventFileDrop);
  25349. });
  25350. editor.on("remove", function() {
  25351. each$k(eventNames, function(name2) {
  25352. pageDom.unbind(doc2, name2, preventFileDropIfUIElement);
  25353. dom2.unbind(editorRoot, name2, preventFileDrop);
  25354. });
  25355. });
  25356. };
  25357. editor.on("init", function() {
  25358. Delay.setEditorTimeout(editor, setup2, 0);
  25359. });
  25360. };
  25361. var init$2 = function(editor) {
  25362. bindFakeDragEvents(editor);
  25363. blockIeDrop(editor);
  25364. if (shouldBlockUnsupportedDrop(editor)) {
  25365. blockUnsupportedFileDrop(editor);
  25366. }
  25367. };
  25368. var setup$1 = function(editor) {
  25369. var renderFocusCaret = first(function() {
  25370. if (!editor.removed && editor.getBody().contains(document.activeElement)) {
  25371. var rng = editor.selection.getRng();
  25372. if (rng.collapsed) {
  25373. var caretRange = renderRangeCaret(editor, rng, false);
  25374. editor.selection.setRng(caretRange);
  25375. }
  25376. }
  25377. }, 0);
  25378. editor.on("focus", function() {
  25379. renderFocusCaret.throttle();
  25380. });
  25381. editor.on("blur", function() {
  25382. renderFocusCaret.cancel();
  25383. });
  25384. };
  25385. var setup = function(editor) {
  25386. editor.on("init", function() {
  25387. editor.on("focusin", function(e) {
  25388. var target = e.target;
  25389. if (isMedia$2(target)) {
  25390. var ceRoot = getContentEditableRoot$1(editor.getBody(), target);
  25391. var node = isContentEditableFalse$b(ceRoot) ? ceRoot : target;
  25392. if (editor.selection.getNode() !== node) {
  25393. selectNode(editor, node).each(function(rng) {
  25394. return editor.selection.setRng(rng);
  25395. });
  25396. }
  25397. }
  25398. });
  25399. });
  25400. };
  25401. var isContentEditableTrue = isContentEditableTrue$4;
  25402. var isContentEditableFalse = isContentEditableFalse$b;
  25403. var getContentEditableRoot = function(editor, node) {
  25404. return getContentEditableRoot$1(editor.getBody(), node);
  25405. };
  25406. var SelectionOverrides = function(editor) {
  25407. var selection = editor.selection, dom2 = editor.dom;
  25408. var isBlock2 = dom2.isBlock;
  25409. var rootNode = editor.getBody();
  25410. var fakeCaret = FakeCaret(editor, rootNode, isBlock2, function() {
  25411. return hasFocus(editor);
  25412. });
  25413. var realSelectionId = "sel-" + dom2.uniqueId();
  25414. var elementSelectionAttr = "data-mce-selected";
  25415. var selectedElement;
  25416. var isFakeSelectionElement = function(node) {
  25417. return dom2.hasClass(node, "mce-offscreen-selection");
  25418. };
  25419. var isFakeSelectionTargetElement = function(node) {
  25420. return node !== rootNode && (isContentEditableFalse(node) || isMedia$2(node)) && dom2.isChildOf(node, rootNode);
  25421. };
  25422. var isNearFakeSelectionElement = function(pos) {
  25423. return isBeforeContentEditableFalse(pos) || isAfterContentEditableFalse(pos) || isBeforeMedia(pos) || isAfterMedia(pos);
  25424. };
  25425. var getRealSelectionElement = function() {
  25426. var container = dom2.get(realSelectionId);
  25427. return container ? container.getElementsByTagName("*")[0] : container;
  25428. };
  25429. var setRange = function(range2) {
  25430. if (range2) {
  25431. selection.setRng(range2);
  25432. }
  25433. };
  25434. var getRange = selection.getRng;
  25435. var showCaret2 = function(direction, node, before2, scrollIntoView) {
  25436. if (scrollIntoView === void 0) {
  25437. scrollIntoView = true;
  25438. }
  25439. var e = editor.fire("ShowCaret", {
  25440. target: node,
  25441. direction,
  25442. before: before2
  25443. });
  25444. if (e.isDefaultPrevented()) {
  25445. return null;
  25446. }
  25447. if (scrollIntoView) {
  25448. selection.scrollIntoView(node, direction === -1);
  25449. }
  25450. return fakeCaret.show(before2, node);
  25451. };
  25452. var showBlockCaretContainer2 = function(blockCaretContainer) {
  25453. if (blockCaretContainer.hasAttribute("data-mce-caret")) {
  25454. showCaretContainerBlock(blockCaretContainer);
  25455. setRange(getRange());
  25456. selection.scrollIntoView(blockCaretContainer);
  25457. }
  25458. };
  25459. var registerEvents2 = function() {
  25460. editor.on("mouseup", function(e) {
  25461. var range2 = getRange();
  25462. if (range2.collapsed && isXYInContentArea(editor, e.clientX, e.clientY)) {
  25463. renderCaretAtRange(editor, range2, false).each(setRange);
  25464. }
  25465. });
  25466. editor.on("click", function(e) {
  25467. var contentEditableRoot = getContentEditableRoot(editor, e.target);
  25468. if (contentEditableRoot) {
  25469. if (isContentEditableFalse(contentEditableRoot)) {
  25470. e.preventDefault();
  25471. editor.focus();
  25472. }
  25473. if (isContentEditableTrue(contentEditableRoot)) {
  25474. if (dom2.isChildOf(contentEditableRoot, selection.getNode())) {
  25475. removeElementSelection();
  25476. }
  25477. }
  25478. }
  25479. });
  25480. editor.on("blur NewBlock", removeElementSelection);
  25481. editor.on("ResizeWindow FullscreenStateChanged", fakeCaret.reposition);
  25482. var hasNormalCaretPosition = function(elm) {
  25483. var start2 = elm.firstChild;
  25484. if (isNullable(start2)) {
  25485. return false;
  25486. }
  25487. var startPos = CaretPosition.before(start2);
  25488. if (isBr$5(startPos.getNode()) && elm.childNodes.length === 1) {
  25489. return !isNearFakeSelectionElement(startPos);
  25490. } else {
  25491. var caretWalker = CaretWalker(elm);
  25492. var newPos = caretWalker.next(startPos);
  25493. return newPos && !isNearFakeSelectionElement(newPos);
  25494. }
  25495. };
  25496. var isInSameBlock2 = function(node1, node2) {
  25497. var block1 = dom2.getParent(node1, isBlock2);
  25498. var block2 = dom2.getParent(node2, isBlock2);
  25499. return block1 === block2;
  25500. };
  25501. var hasBetterMouseTarget = function(targetNode, caretNode) {
  25502. var targetBlock = dom2.getParent(targetNode, isBlock2);
  25503. var caretBlock = dom2.getParent(caretNode, isBlock2);
  25504. if (isNullable(targetBlock)) {
  25505. return false;
  25506. }
  25507. if (targetNode !== caretBlock && dom2.isChildOf(targetBlock, caretBlock) && isContentEditableFalse(getContentEditableRoot(editor, targetBlock)) === false) {
  25508. return true;
  25509. }
  25510. return !dom2.isChildOf(caretBlock, targetBlock) && !isInSameBlock2(targetBlock, caretBlock) && hasNormalCaretPosition(targetBlock);
  25511. };
  25512. editor.on("tap", function(e) {
  25513. var targetElm = e.target;
  25514. var contentEditableRoot = getContentEditableRoot(editor, targetElm);
  25515. if (isContentEditableFalse(contentEditableRoot)) {
  25516. e.preventDefault();
  25517. selectNode(editor, contentEditableRoot).each(setElementSelection);
  25518. } else if (isFakeSelectionTargetElement(targetElm)) {
  25519. selectNode(editor, targetElm).each(setElementSelection);
  25520. }
  25521. }, true);
  25522. editor.on("mousedown", function(e) {
  25523. var targetElm = e.target;
  25524. if (targetElm !== rootNode && targetElm.nodeName !== "HTML" && !dom2.isChildOf(targetElm, rootNode)) {
  25525. return;
  25526. }
  25527. if (isXYInContentArea(editor, e.clientX, e.clientY) === false) {
  25528. return;
  25529. }
  25530. var contentEditableRoot = getContentEditableRoot(editor, targetElm);
  25531. if (contentEditableRoot) {
  25532. if (isContentEditableFalse(contentEditableRoot)) {
  25533. e.preventDefault();
  25534. selectNode(editor, contentEditableRoot).each(setElementSelection);
  25535. } else {
  25536. removeElementSelection();
  25537. if (!(isContentEditableTrue(contentEditableRoot) && e.shiftKey) && !isXYWithinRange(e.clientX, e.clientY, selection.getRng())) {
  25538. hideFakeCaret();
  25539. selection.placeCaretAt(e.clientX, e.clientY);
  25540. }
  25541. }
  25542. } else if (isFakeSelectionTargetElement(targetElm)) {
  25543. selectNode(editor, targetElm).each(setElementSelection);
  25544. } else if (isFakeCaretTarget(targetElm) === false) {
  25545. removeElementSelection();
  25546. hideFakeCaret();
  25547. var fakeCaretInfo = closestFakeCaret(rootNode, e.clientX, e.clientY);
  25548. if (fakeCaretInfo) {
  25549. if (!hasBetterMouseTarget(targetElm, fakeCaretInfo.node)) {
  25550. e.preventDefault();
  25551. var range2 = showCaret2(1, fakeCaretInfo.node, fakeCaretInfo.before, false);
  25552. setRange(range2);
  25553. editor.getBody().focus();
  25554. }
  25555. }
  25556. }
  25557. });
  25558. editor.on("keypress", function(e) {
  25559. if (VK.modifierPressed(e)) {
  25560. return;
  25561. }
  25562. if (isContentEditableFalse(selection.getNode())) {
  25563. e.preventDefault();
  25564. }
  25565. });
  25566. editor.on("GetSelectionRange", function(e) {
  25567. var rng = e.range;
  25568. if (selectedElement) {
  25569. if (!selectedElement.parentNode) {
  25570. selectedElement = null;
  25571. return;
  25572. }
  25573. rng = rng.cloneRange();
  25574. rng.selectNode(selectedElement);
  25575. e.range = rng;
  25576. }
  25577. });
  25578. editor.on("SetSelectionRange", function(e) {
  25579. e.range = normalizeShortEndedElementSelection(e.range);
  25580. var rng = setElementSelection(e.range, e.forward);
  25581. if (rng) {
  25582. e.range = rng;
  25583. }
  25584. });
  25585. var isPasteBin = function(node) {
  25586. return node.id === "mcepastebin";
  25587. };
  25588. editor.on("AfterSetSelectionRange", function(e) {
  25589. var rng = e.range;
  25590. var parentNode = rng.startContainer.parentNode;
  25591. if (!isRangeInCaretContainer(rng) && !isPasteBin(parentNode)) {
  25592. hideFakeCaret();
  25593. }
  25594. if (!isFakeSelectionElement(parentNode)) {
  25595. removeElementSelection();
  25596. }
  25597. });
  25598. editor.on("copy", function(e) {
  25599. var clipboardData = e.clipboardData;
  25600. if (!e.isDefaultPrevented() && e.clipboardData && !Env.ie) {
  25601. var realSelectionElement = getRealSelectionElement();
  25602. if (realSelectionElement) {
  25603. e.preventDefault();
  25604. clipboardData.clearData();
  25605. clipboardData.setData("text/html", realSelectionElement.outerHTML);
  25606. clipboardData.setData("text/plain", realSelectionElement.outerText || realSelectionElement.innerText);
  25607. }
  25608. }
  25609. });
  25610. init$2(editor);
  25611. setup$1(editor);
  25612. setup(editor);
  25613. };
  25614. var isWithinCaretContainer = function(node) {
  25615. return isCaretContainer$2(node) || startsWithCaretContainer$1(node) || endsWithCaretContainer$1(node);
  25616. };
  25617. var isRangeInCaretContainer = function(rng) {
  25618. return isWithinCaretContainer(rng.startContainer) || isWithinCaretContainer(rng.endContainer);
  25619. };
  25620. var normalizeShortEndedElementSelection = function(rng) {
  25621. var shortEndedElements = editor.schema.getShortEndedElements();
  25622. var newRng = dom2.createRng();
  25623. var startContainer = rng.startContainer;
  25624. var startOffset = rng.startOffset;
  25625. var endContainer = rng.endContainer;
  25626. var endOffset = rng.endOffset;
  25627. if (has$2(shortEndedElements, startContainer.nodeName.toLowerCase())) {
  25628. if (startOffset === 0) {
  25629. newRng.setStartBefore(startContainer);
  25630. } else {
  25631. newRng.setStartAfter(startContainer);
  25632. }
  25633. } else {
  25634. newRng.setStart(startContainer, startOffset);
  25635. }
  25636. if (has$2(shortEndedElements, endContainer.nodeName.toLowerCase())) {
  25637. if (endOffset === 0) {
  25638. newRng.setEndBefore(endContainer);
  25639. } else {
  25640. newRng.setEndAfter(endContainer);
  25641. }
  25642. } else {
  25643. newRng.setEnd(endContainer, endOffset);
  25644. }
  25645. return newRng;
  25646. };
  25647. var setupOffscreenSelection = function(node, targetClone, origTargetClone) {
  25648. var $ = editor.$;
  25649. var $realSelectionContainer = descendant(SugarElement.fromDom(editor.getBody()), "#" + realSelectionId).fold(function() {
  25650. return $([]);
  25651. }, function(elm) {
  25652. return $([elm.dom]);
  25653. });
  25654. if ($realSelectionContainer.length === 0) {
  25655. $realSelectionContainer = $('<div data-mce-bogus="all" class="mce-offscreen-selection"></div>').attr("id", realSelectionId);
  25656. $realSelectionContainer.appendTo(editor.getBody());
  25657. }
  25658. var newRange = dom2.createRng();
  25659. if (targetClone === origTargetClone && Env.ie) {
  25660. $realSelectionContainer.empty().append('<p style="font-size: 0" data-mce-bogus="all">\xA0</p>').append(targetClone);
  25661. newRange.setStartAfter($realSelectionContainer[0].firstChild.firstChild);
  25662. newRange.setEndAfter(targetClone);
  25663. } else {
  25664. $realSelectionContainer.empty().append(nbsp).append(targetClone).append(nbsp);
  25665. newRange.setStart($realSelectionContainer[0].firstChild, 1);
  25666. newRange.setEnd($realSelectionContainer[0].lastChild, 0);
  25667. }
  25668. $realSelectionContainer.css({ top: dom2.getPos(node, editor.getBody()).y });
  25669. $realSelectionContainer[0].focus();
  25670. var sel = selection.getSel();
  25671. sel.removeAllRanges();
  25672. sel.addRange(newRange);
  25673. return newRange;
  25674. };
  25675. var selectElement = function(elm) {
  25676. var targetClone = elm.cloneNode(true);
  25677. var e = editor.fire("ObjectSelected", {
  25678. target: elm,
  25679. targetClone
  25680. });
  25681. if (e.isDefaultPrevented()) {
  25682. return null;
  25683. }
  25684. var range2 = setupOffscreenSelection(elm, e.targetClone, targetClone);
  25685. var nodeElm = SugarElement.fromDom(elm);
  25686. each$k(descendants(SugarElement.fromDom(editor.getBody()), "*[data-mce-selected]"), function(elm2) {
  25687. if (!eq(nodeElm, elm2)) {
  25688. remove$6(elm2, elementSelectionAttr);
  25689. }
  25690. });
  25691. if (!dom2.getAttrib(elm, elementSelectionAttr)) {
  25692. elm.setAttribute(elementSelectionAttr, "1");
  25693. }
  25694. selectedElement = elm;
  25695. hideFakeCaret();
  25696. return range2;
  25697. };
  25698. var setElementSelection = function(range2, forward) {
  25699. if (!range2) {
  25700. return null;
  25701. }
  25702. if (range2.collapsed) {
  25703. if (!isRangeInCaretContainer(range2)) {
  25704. var dir2 = forward ? 1 : -1;
  25705. var caretPosition = getNormalizedRangeEndPoint(dir2, rootNode, range2);
  25706. var beforeNode = caretPosition.getNode(!forward);
  25707. if (isFakeCaretTarget(beforeNode)) {
  25708. return showCaret2(dir2, beforeNode, forward ? !caretPosition.isAtEnd() : false, false);
  25709. }
  25710. var afterNode = caretPosition.getNode(forward);
  25711. if (isFakeCaretTarget(afterNode)) {
  25712. return showCaret2(dir2, afterNode, forward ? false : !caretPosition.isAtEnd(), false);
  25713. }
  25714. }
  25715. return null;
  25716. }
  25717. var startContainer = range2.startContainer;
  25718. var startOffset = range2.startOffset;
  25719. var endOffset = range2.endOffset;
  25720. if (startContainer.nodeType === 3 && startOffset === 0 && isContentEditableFalse(startContainer.parentNode)) {
  25721. startContainer = startContainer.parentNode;
  25722. startOffset = dom2.nodeIndex(startContainer);
  25723. startContainer = startContainer.parentNode;
  25724. }
  25725. if (startContainer.nodeType !== 1) {
  25726. return null;
  25727. }
  25728. if (endOffset === startOffset + 1 && startContainer === range2.endContainer) {
  25729. var node = startContainer.childNodes[startOffset];
  25730. if (isFakeSelectionTargetElement(node)) {
  25731. return selectElement(node);
  25732. }
  25733. }
  25734. return null;
  25735. };
  25736. var removeElementSelection = function() {
  25737. if (selectedElement) {
  25738. selectedElement.removeAttribute(elementSelectionAttr);
  25739. }
  25740. descendant(SugarElement.fromDom(editor.getBody()), "#" + realSelectionId).each(remove$7);
  25741. selectedElement = null;
  25742. };
  25743. var destroy2 = function() {
  25744. fakeCaret.destroy();
  25745. selectedElement = null;
  25746. };
  25747. var hideFakeCaret = function() {
  25748. fakeCaret.hide();
  25749. };
  25750. if (Env.ceFalse && !isRtc(editor)) {
  25751. registerEvents2();
  25752. }
  25753. return {
  25754. showCaret: showCaret2,
  25755. showBlockCaretContainer: showBlockCaretContainer2,
  25756. hideFakeCaret,
  25757. destroy: destroy2
  25758. };
  25759. };
  25760. var Quirks = function(editor) {
  25761. var each2 = Tools.each;
  25762. var BACKSPACE = VK.BACKSPACE, DELETE2 = VK.DELETE, dom2 = editor.dom, selection = editor.selection, parser = editor.parser;
  25763. var isGecko = Env.gecko, isIE2 = Env.ie, isWebKit = Env.webkit;
  25764. var mceInternalUrlPrefix = "data:text/mce-internal,";
  25765. var mceInternalDataType = isIE2 ? "Text" : "URL";
  25766. var setEditorCommandState2 = function(cmd, state) {
  25767. try {
  25768. editor.getDoc().execCommand(cmd, false, state);
  25769. } catch (ex) {
  25770. }
  25771. };
  25772. var isDefaultPrevented = function(e) {
  25773. return e.isDefaultPrevented();
  25774. };
  25775. var setMceInternalContent = function(e) {
  25776. var selectionHtml, internalContent;
  25777. if (e.dataTransfer) {
  25778. if (editor.selection.isCollapsed() && e.target.tagName === "IMG") {
  25779. selection.select(e.target);
  25780. }
  25781. selectionHtml = editor.selection.getContent();
  25782. if (selectionHtml.length > 0) {
  25783. internalContent = mceInternalUrlPrefix + escape(editor.id) + "," + escape(selectionHtml);
  25784. e.dataTransfer.setData(mceInternalDataType, internalContent);
  25785. }
  25786. }
  25787. };
  25788. var getMceInternalContent = function(e) {
  25789. var internalContent;
  25790. if (e.dataTransfer) {
  25791. internalContent = e.dataTransfer.getData(mceInternalDataType);
  25792. if (internalContent && internalContent.indexOf(mceInternalUrlPrefix) >= 0) {
  25793. internalContent = internalContent.substr(mceInternalUrlPrefix.length).split(",");
  25794. return {
  25795. id: unescape(internalContent[0]),
  25796. html: unescape(internalContent[1])
  25797. };
  25798. }
  25799. }
  25800. return null;
  25801. };
  25802. var insertClipboardContents = function(content, internal) {
  25803. if (editor.queryCommandSupported("mceInsertClipboardContent")) {
  25804. editor.execCommand("mceInsertClipboardContent", false, {
  25805. content,
  25806. internal
  25807. });
  25808. } else {
  25809. editor.execCommand("mceInsertContent", false, content);
  25810. }
  25811. };
  25812. var emptyEditorWhenDeleting = function() {
  25813. var serializeRng = function(rng) {
  25814. var body = dom2.create("body");
  25815. var contents = rng.cloneContents();
  25816. body.appendChild(contents);
  25817. return selection.serializer.serialize(body, { format: "html" });
  25818. };
  25819. var allContentsSelected = function(rng) {
  25820. var selection2 = serializeRng(rng);
  25821. var allRng = dom2.createRng();
  25822. allRng.selectNode(editor.getBody());
  25823. var allSelection = serializeRng(allRng);
  25824. return selection2 === allSelection;
  25825. };
  25826. editor.on("keydown", function(e) {
  25827. var keyCode = e.keyCode;
  25828. var isCollapsed, body;
  25829. if (!isDefaultPrevented(e) && (keyCode === DELETE2 || keyCode === BACKSPACE)) {
  25830. isCollapsed = editor.selection.isCollapsed();
  25831. body = editor.getBody();
  25832. if (isCollapsed && !dom2.isEmpty(body)) {
  25833. return;
  25834. }
  25835. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  25836. return;
  25837. }
  25838. e.preventDefault();
  25839. editor.setContent("");
  25840. if (body.firstChild && dom2.isBlock(body.firstChild)) {
  25841. editor.selection.setCursorLocation(body.firstChild, 0);
  25842. } else {
  25843. editor.selection.setCursorLocation(body, 0);
  25844. }
  25845. editor.nodeChanged();
  25846. }
  25847. });
  25848. };
  25849. var selectAll = function() {
  25850. editor.shortcuts.add("meta+a", null, "SelectAll");
  25851. };
  25852. var documentElementEditingFocus = function() {
  25853. if (!editor.inline) {
  25854. dom2.bind(editor.getDoc(), "mousedown mouseup", function(e) {
  25855. var rng;
  25856. if (e.target === editor.getDoc().documentElement) {
  25857. rng = selection.getRng();
  25858. editor.getBody().focus();
  25859. if (e.type === "mousedown") {
  25860. if (isCaretContainer$2(rng.startContainer)) {
  25861. return;
  25862. }
  25863. selection.placeCaretAt(e.clientX, e.clientY);
  25864. } else {
  25865. selection.setRng(rng);
  25866. }
  25867. }
  25868. });
  25869. }
  25870. };
  25871. var removeHrOnBackspace = function() {
  25872. editor.on("keydown", function(e) {
  25873. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  25874. if (!editor.getBody().getElementsByTagName("hr").length) {
  25875. return;
  25876. }
  25877. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  25878. var node = selection.getNode();
  25879. var previousSibling = node.previousSibling;
  25880. if (node.nodeName === "HR") {
  25881. dom2.remove(node);
  25882. e.preventDefault();
  25883. return;
  25884. }
  25885. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  25886. dom2.remove(previousSibling);
  25887. e.preventDefault();
  25888. }
  25889. }
  25890. }
  25891. });
  25892. };
  25893. var focusBody2 = function() {
  25894. if (!Range.prototype.getClientRects) {
  25895. editor.on("mousedown", function(e) {
  25896. if (!isDefaultPrevented(e) && e.target.nodeName === "HTML") {
  25897. var body_1 = editor.getBody();
  25898. body_1.blur();
  25899. Delay.setEditorTimeout(editor, function() {
  25900. body_1.focus();
  25901. });
  25902. }
  25903. });
  25904. }
  25905. };
  25906. var selectControlElements = function() {
  25907. editor.on("click", function(e) {
  25908. var target = e.target;
  25909. if (/^(IMG|HR)$/.test(target.nodeName) && dom2.getContentEditableParent(target) !== "false") {
  25910. e.preventDefault();
  25911. editor.selection.select(target);
  25912. editor.nodeChanged();
  25913. }
  25914. if (target.nodeName === "A" && dom2.hasClass(target, "mce-item-anchor")) {
  25915. e.preventDefault();
  25916. selection.select(target);
  25917. }
  25918. });
  25919. };
  25920. var removeStylesWhenDeletingAcrossBlockElements = function() {
  25921. var getAttributeApplyFunction = function() {
  25922. var template = dom2.getAttribs(selection.getStart().cloneNode(false));
  25923. return function() {
  25924. var target = selection.getStart();
  25925. if (target !== editor.getBody()) {
  25926. dom2.setAttrib(target, "style", null);
  25927. each2(template, function(attr) {
  25928. target.setAttributeNode(attr.cloneNode(true));
  25929. });
  25930. }
  25931. };
  25932. };
  25933. var isSelectionAcrossElements = function() {
  25934. return !selection.isCollapsed() && dom2.getParent(selection.getStart(), dom2.isBlock) !== dom2.getParent(selection.getEnd(), dom2.isBlock);
  25935. };
  25936. editor.on("keypress", function(e) {
  25937. var applyAttributes2;
  25938. if (!isDefaultPrevented(e) && (e.keyCode === 8 || e.keyCode === 46) && isSelectionAcrossElements()) {
  25939. applyAttributes2 = getAttributeApplyFunction();
  25940. editor.getDoc().execCommand("delete", false, null);
  25941. applyAttributes2();
  25942. e.preventDefault();
  25943. return false;
  25944. }
  25945. });
  25946. dom2.bind(editor.getDoc(), "cut", function(e) {
  25947. var applyAttributes2;
  25948. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  25949. applyAttributes2 = getAttributeApplyFunction();
  25950. Delay.setEditorTimeout(editor, function() {
  25951. applyAttributes2();
  25952. });
  25953. }
  25954. });
  25955. };
  25956. var disableBackspaceIntoATable = function() {
  25957. editor.on("keydown", function(e) {
  25958. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  25959. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  25960. var previousSibling = selection.getNode().previousSibling;
  25961. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
  25962. e.preventDefault();
  25963. return false;
  25964. }
  25965. }
  25966. }
  25967. });
  25968. };
  25969. var removeBlockQuoteOnBackSpace = function() {
  25970. editor.on("keydown", function(e) {
  25971. var rng, parent2;
  25972. if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) {
  25973. return;
  25974. }
  25975. rng = selection.getRng();
  25976. var container = rng.startContainer;
  25977. var offset = rng.startOffset;
  25978. var root = dom2.getRoot();
  25979. parent2 = container;
  25980. if (!rng.collapsed || offset !== 0) {
  25981. return;
  25982. }
  25983. while (parent2 && parent2.parentNode && parent2.parentNode.firstChild === parent2 && parent2.parentNode !== root) {
  25984. parent2 = parent2.parentNode;
  25985. }
  25986. if (parent2.tagName === "BLOCKQUOTE") {
  25987. editor.formatter.toggle("blockquote", null, parent2);
  25988. rng = dom2.createRng();
  25989. rng.setStart(container, 0);
  25990. rng.setEnd(container, 0);
  25991. selection.setRng(rng);
  25992. }
  25993. });
  25994. };
  25995. var setGeckoEditingOptions = function() {
  25996. var setOpts = function() {
  25997. setEditorCommandState2("StyleWithCSS", false);
  25998. setEditorCommandState2("enableInlineTableEditing", false);
  25999. if (!getObjectResizing(editor)) {
  26000. setEditorCommandState2("enableObjectResizing", false);
  26001. }
  26002. };
  26003. if (!isReadOnly$1(editor)) {
  26004. editor.on("BeforeExecCommand mousedown", setOpts);
  26005. }
  26006. };
  26007. var addBrAfterLastLinks = function() {
  26008. var fixLinks = function() {
  26009. each2(dom2.select("a"), function(node) {
  26010. var parentNode = node.parentNode;
  26011. var root = dom2.getRoot();
  26012. if (parentNode.lastChild === node) {
  26013. while (parentNode && !dom2.isBlock(parentNode)) {
  26014. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  26015. return;
  26016. }
  26017. parentNode = parentNode.parentNode;
  26018. }
  26019. dom2.add(parentNode, "br", { "data-mce-bogus": 1 });
  26020. }
  26021. });
  26022. };
  26023. editor.on("SetContent ExecCommand", function(e) {
  26024. if (e.type === "setcontent" || e.command === "mceInsertLink") {
  26025. fixLinks();
  26026. }
  26027. });
  26028. };
  26029. var setDefaultBlockType = function() {
  26030. if (getForcedRootBlock(editor)) {
  26031. editor.on("init", function() {
  26032. setEditorCommandState2("DefaultParagraphSeparator", getForcedRootBlock(editor));
  26033. });
  26034. }
  26035. };
  26036. var normalizeSelection2 = function() {
  26037. editor.on("keyup focusin mouseup", function(e) {
  26038. if (!VK.modifierPressed(e)) {
  26039. selection.normalize();
  26040. }
  26041. }, true);
  26042. };
  26043. var showBrokenImageIcon = function() {
  26044. editor.contentStyles.push("img:-moz-broken {-moz-force-broken-image-icon:1;min-width:24px;min-height:24px}");
  26045. };
  26046. var restoreFocusOnKeyDown = function() {
  26047. if (!editor.inline) {
  26048. editor.on("keydown", function() {
  26049. if (document.activeElement === document.body) {
  26050. editor.getWin().focus();
  26051. }
  26052. });
  26053. }
  26054. };
  26055. var bodyHeight = function() {
  26056. if (!editor.inline) {
  26057. editor.contentStyles.push("body {min-height: 150px}");
  26058. editor.on("click", function(e) {
  26059. var rng;
  26060. if (e.target.nodeName === "HTML") {
  26061. if (Env.ie > 11) {
  26062. editor.getBody().focus();
  26063. return;
  26064. }
  26065. rng = editor.selection.getRng();
  26066. editor.getBody().focus();
  26067. editor.selection.setRng(rng);
  26068. editor.selection.normalize();
  26069. editor.nodeChanged();
  26070. }
  26071. });
  26072. }
  26073. };
  26074. var blockCmdArrowNavigation = function() {
  26075. if (Env.mac) {
  26076. editor.on("keydown", function(e) {
  26077. if (VK.metaKeyPressed(e) && !e.shiftKey && (e.keyCode === 37 || e.keyCode === 39)) {
  26078. e.preventDefault();
  26079. var selection_1 = editor.selection.getSel();
  26080. selection_1.modify("move", e.keyCode === 37 ? "backward" : "forward", "lineboundary");
  26081. }
  26082. });
  26083. }
  26084. };
  26085. var disableAutoUrlDetect = function() {
  26086. setEditorCommandState2("AutoUrlDetect", false);
  26087. };
  26088. var tapLinksAndImages = function() {
  26089. editor.on("click", function(e) {
  26090. var elm = e.target;
  26091. do {
  26092. if (elm.tagName === "A") {
  26093. e.preventDefault();
  26094. return;
  26095. }
  26096. } while (elm = elm.parentNode);
  26097. });
  26098. editor.contentStyles.push(".mce-content-body {-webkit-touch-callout: none}");
  26099. };
  26100. var blockFormSubmitInsideEditor = function() {
  26101. editor.on("init", function() {
  26102. editor.dom.bind(editor.getBody(), "submit", function(e) {
  26103. e.preventDefault();
  26104. });
  26105. });
  26106. };
  26107. var removeAppleInterchangeBrs = function() {
  26108. parser.addNodeFilter("br", function(nodes) {
  26109. var i = nodes.length;
  26110. while (i--) {
  26111. if (nodes[i].attr("class") === "Apple-interchange-newline") {
  26112. nodes[i].remove();
  26113. }
  26114. }
  26115. });
  26116. };
  26117. var ieInternalDragAndDrop = function() {
  26118. editor.on("dragstart", function(e) {
  26119. setMceInternalContent(e);
  26120. });
  26121. editor.on("drop", function(e) {
  26122. if (!isDefaultPrevented(e)) {
  26123. var internalContent = getMceInternalContent(e);
  26124. if (internalContent && internalContent.id !== editor.id) {
  26125. e.preventDefault();
  26126. var rng = fromPoint(e.x, e.y, editor.getDoc());
  26127. selection.setRng(rng);
  26128. insertClipboardContents(internalContent.html, true);
  26129. }
  26130. }
  26131. });
  26132. };
  26133. var refreshContentEditable = noop;
  26134. var isHidden = function() {
  26135. if (!isGecko || editor.removed) {
  26136. return false;
  26137. }
  26138. var sel = editor.selection.getSel();
  26139. return !sel || !sel.rangeCount || sel.rangeCount === 0;
  26140. };
  26141. var setupRtc = function() {
  26142. if (isWebKit) {
  26143. documentElementEditingFocus();
  26144. selectControlElements();
  26145. blockFormSubmitInsideEditor();
  26146. selectAll();
  26147. if (Env.iOS) {
  26148. restoreFocusOnKeyDown();
  26149. bodyHeight();
  26150. tapLinksAndImages();
  26151. }
  26152. }
  26153. if (isGecko) {
  26154. focusBody2();
  26155. setGeckoEditingOptions();
  26156. showBrokenImageIcon();
  26157. blockCmdArrowNavigation();
  26158. }
  26159. };
  26160. var setup2 = function() {
  26161. removeBlockQuoteOnBackSpace();
  26162. emptyEditorWhenDeleting();
  26163. if (!Env.windowsPhone) {
  26164. normalizeSelection2();
  26165. }
  26166. if (isWebKit) {
  26167. documentElementEditingFocus();
  26168. selectControlElements();
  26169. setDefaultBlockType();
  26170. blockFormSubmitInsideEditor();
  26171. disableBackspaceIntoATable();
  26172. removeAppleInterchangeBrs();
  26173. if (Env.iOS) {
  26174. restoreFocusOnKeyDown();
  26175. bodyHeight();
  26176. tapLinksAndImages();
  26177. } else {
  26178. selectAll();
  26179. }
  26180. }
  26181. if (Env.ie >= 11) {
  26182. bodyHeight();
  26183. disableBackspaceIntoATable();
  26184. }
  26185. if (Env.ie) {
  26186. selectAll();
  26187. disableAutoUrlDetect();
  26188. ieInternalDragAndDrop();
  26189. }
  26190. if (isGecko) {
  26191. removeHrOnBackspace();
  26192. focusBody2();
  26193. removeStylesWhenDeletingAcrossBlockElements();
  26194. setGeckoEditingOptions();
  26195. addBrAfterLastLinks();
  26196. showBrokenImageIcon();
  26197. blockCmdArrowNavigation();
  26198. disableBackspaceIntoATable();
  26199. }
  26200. };
  26201. if (isRtc(editor)) {
  26202. setupRtc();
  26203. } else {
  26204. setup2();
  26205. }
  26206. return {
  26207. refreshContentEditable,
  26208. isHidden
  26209. };
  26210. };
  26211. var DOM$6 = DOMUtils.DOM;
  26212. var appendStyle = function(editor, text) {
  26213. var body = SugarElement.fromDom(editor.getBody());
  26214. var container = getStyleContainer(getRootNode(body));
  26215. var style = SugarElement.fromTag("style");
  26216. set$1(style, "type", "text/css");
  26217. append$1(style, SugarElement.fromText(text));
  26218. append$1(container, style);
  26219. editor.on("remove", function() {
  26220. remove$7(style);
  26221. });
  26222. };
  26223. var getRootName = function(editor) {
  26224. return editor.inline ? editor.getElement().nodeName.toLowerCase() : void 0;
  26225. };
  26226. var removeUndefined = function(obj) {
  26227. return filter$3(obj, function(v) {
  26228. return isUndefined(v) === false;
  26229. });
  26230. };
  26231. var mkSchemaSettings = function(editor) {
  26232. var settings = editor.settings;
  26233. return removeUndefined({
  26234. block_elements: settings.block_elements,
  26235. boolean_attributes: settings.boolean_attributes,
  26236. custom_elements: settings.custom_elements,
  26237. extended_valid_elements: settings.extended_valid_elements,
  26238. invalid_elements: settings.invalid_elements,
  26239. invalid_styles: settings.invalid_styles,
  26240. move_caret_before_on_enter_elements: settings.move_caret_before_on_enter_elements,
  26241. non_empty_elements: settings.non_empty_elements,
  26242. schema: settings.schema,
  26243. self_closing_elements: settings.self_closing_elements,
  26244. short_ended_elements: settings.short_ended_elements,
  26245. special: settings.special,
  26246. text_block_elements: settings.text_block_elements,
  26247. text_inline_elements: settings.text_inline_elements,
  26248. valid_children: settings.valid_children,
  26249. valid_classes: settings.valid_classes,
  26250. valid_elements: settings.valid_elements,
  26251. valid_styles: settings.valid_styles,
  26252. verify_html: settings.verify_html,
  26253. whitespace_elements: settings.whitespace_elements,
  26254. padd_empty_block_inline_children: settings.format_empty_lines
  26255. });
  26256. };
  26257. var mkParserSettings = function(editor) {
  26258. var settings = editor.settings;
  26259. var blobCache = editor.editorUpload.blobCache;
  26260. return removeUndefined({
  26261. allow_conditional_comments: settings.allow_conditional_comments,
  26262. allow_html_data_urls: settings.allow_html_data_urls,
  26263. allow_svg_data_urls: settings.allow_svg_data_urls,
  26264. allow_html_in_named_anchor: settings.allow_html_in_named_anchor,
  26265. allow_script_urls: settings.allow_script_urls,
  26266. allow_unsafe_link_target: settings.allow_unsafe_link_target,
  26267. convert_fonts_to_spans: settings.convert_fonts_to_spans,
  26268. fix_list_elements: settings.fix_list_elements,
  26269. font_size_legacy_values: settings.font_size_legacy_values,
  26270. forced_root_block: settings.forced_root_block,
  26271. forced_root_block_attrs: settings.forced_root_block_attrs,
  26272. padd_empty_with_br: settings.padd_empty_with_br,
  26273. preserve_cdata: settings.preserve_cdata,
  26274. remove_trailing_brs: settings.remove_trailing_brs,
  26275. inline_styles: settings.inline_styles,
  26276. root_name: getRootName(editor),
  26277. validate: true,
  26278. blob_cache: blobCache,
  26279. document: editor.getDoc(),
  26280. images_dataimg_filter: settings.images_dataimg_filter
  26281. });
  26282. };
  26283. var mkSerializerSettings = function(editor) {
  26284. var settings = editor.settings;
  26285. return __assign(__assign(__assign({}, mkParserSettings(editor)), mkSchemaSettings(editor)), removeUndefined({
  26286. url_converter: settings.url_converter,
  26287. url_converter_scope: settings.url_converter_scope,
  26288. element_format: settings.element_format,
  26289. entities: settings.entities,
  26290. entity_encoding: settings.entity_encoding,
  26291. indent: settings.indent,
  26292. indent_after: settings.indent_after,
  26293. indent_before: settings.indent_before
  26294. }));
  26295. };
  26296. var createParser = function(editor) {
  26297. var parser = DomParser(mkParserSettings(editor), editor.schema);
  26298. parser.addAttributeFilter("src,href,style,tabindex", function(nodes, name2) {
  26299. var i = nodes.length, node, value2;
  26300. var dom2 = editor.dom;
  26301. var internalName = "data-mce-" + name2;
  26302. while (i--) {
  26303. node = nodes[i];
  26304. value2 = node.attr(name2);
  26305. if (value2 && !node.attr(internalName)) {
  26306. if (value2.indexOf("data:") === 0 || value2.indexOf("blob:") === 0) {
  26307. continue;
  26308. }
  26309. if (name2 === "style") {
  26310. value2 = dom2.serializeStyle(dom2.parseStyle(value2), node.name);
  26311. if (!value2.length) {
  26312. value2 = null;
  26313. }
  26314. node.attr(internalName, value2);
  26315. node.attr(name2, value2);
  26316. } else if (name2 === "tabindex") {
  26317. node.attr(internalName, value2);
  26318. node.attr(name2, null);
  26319. } else {
  26320. node.attr(internalName, editor.convertURL(value2, name2, node.name));
  26321. }
  26322. }
  26323. }
  26324. });
  26325. parser.addNodeFilter("script", function(nodes) {
  26326. var i = nodes.length;
  26327. while (i--) {
  26328. var node = nodes[i];
  26329. var type2 = node.attr("type") || "no/type";
  26330. if (type2.indexOf("mce-") !== 0) {
  26331. node.attr("type", "mce-" + type2);
  26332. }
  26333. }
  26334. });
  26335. if (editor.settings.preserve_cdata) {
  26336. parser.addNodeFilter("#cdata", function(nodes) {
  26337. var i = nodes.length;
  26338. while (i--) {
  26339. var node = nodes[i];
  26340. node.type = 8;
  26341. node.name = "#comment";
  26342. node.value = "[CDATA[" + editor.dom.encode(node.value) + "]]";
  26343. }
  26344. });
  26345. }
  26346. parser.addNodeFilter("p,h1,h2,h3,h4,h5,h6,div", function(nodes) {
  26347. var i = nodes.length;
  26348. var nonEmptyElements = editor.schema.getNonEmptyElements();
  26349. while (i--) {
  26350. var node = nodes[i];
  26351. if (node.isEmpty(nonEmptyElements) && node.getAll("br").length === 0) {
  26352. node.append(new AstNode("br", 1)).shortEnded = true;
  26353. }
  26354. }
  26355. });
  26356. return parser;
  26357. };
  26358. var autoFocus = function(editor) {
  26359. if (editor.settings.auto_focus) {
  26360. Delay.setEditorTimeout(editor, function() {
  26361. var focusEditor2;
  26362. if (editor.settings.auto_focus === true) {
  26363. focusEditor2 = editor;
  26364. } else {
  26365. focusEditor2 = editor.editorManager.get(editor.settings.auto_focus);
  26366. }
  26367. if (!focusEditor2.destroyed) {
  26368. focusEditor2.focus();
  26369. }
  26370. }, 100);
  26371. }
  26372. };
  26373. var moveSelectionToFirstCaretPosition = function(editor) {
  26374. var root = editor.dom.getRoot();
  26375. if (!editor.inline && (!hasAnyRanges(editor) || editor.selection.getStart(true) === root)) {
  26376. firstPositionIn(root).each(function(pos) {
  26377. var node = pos.getNode();
  26378. var caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos;
  26379. if (Env.browser.isIE()) {
  26380. storeNative(editor, caretPos.toRange());
  26381. } else {
  26382. editor.selection.setRng(caretPos.toRange());
  26383. }
  26384. });
  26385. }
  26386. };
  26387. var initEditor = function(editor) {
  26388. editor.bindPendingEventDelegates();
  26389. editor.initialized = true;
  26390. fireInit(editor);
  26391. editor.focus(true);
  26392. moveSelectionToFirstCaretPosition(editor);
  26393. editor.nodeChanged({ initial: true });
  26394. editor.execCallback("init_instance_callback", editor);
  26395. autoFocus(editor);
  26396. };
  26397. var getStyleSheetLoader$1 = function(editor) {
  26398. return editor.inline ? editor.ui.styleSheetLoader : editor.dom.styleSheetLoader;
  26399. };
  26400. var makeStylesheetLoadingPromises = function(editor, css, framedFonts) {
  26401. var promises = [new promiseObj(function(resolve2, reject) {
  26402. return getStyleSheetLoader$1(editor).loadAll(css, resolve2, reject);
  26403. })];
  26404. if (editor.inline) {
  26405. return promises;
  26406. } else {
  26407. return promises.concat([new promiseObj(function(resolve2, reject) {
  26408. return editor.ui.styleSheetLoader.loadAll(framedFonts, resolve2, reject);
  26409. })]);
  26410. }
  26411. };
  26412. var loadContentCss = function(editor) {
  26413. var styleSheetLoader = getStyleSheetLoader$1(editor);
  26414. var fontCss = getFontCss(editor);
  26415. var css = editor.contentCSS;
  26416. var removeCss = function() {
  26417. styleSheetLoader.unloadAll(css);
  26418. if (!editor.inline) {
  26419. editor.ui.styleSheetLoader.unloadAll(fontCss);
  26420. }
  26421. };
  26422. var loaded = function() {
  26423. if (editor.removed) {
  26424. removeCss();
  26425. } else {
  26426. editor.on("remove", removeCss);
  26427. }
  26428. };
  26429. if (editor.contentStyles.length > 0) {
  26430. var contentCssText_1 = "";
  26431. Tools.each(editor.contentStyles, function(style) {
  26432. contentCssText_1 += style + "\r\n";
  26433. });
  26434. editor.dom.addStyle(contentCssText_1);
  26435. }
  26436. var allStylesheets = promiseObj.all(makeStylesheetLoadingPromises(editor, css, fontCss)).then(loaded).catch(loaded);
  26437. if (editor.settings.content_style) {
  26438. appendStyle(editor, editor.settings.content_style);
  26439. }
  26440. return allStylesheets;
  26441. };
  26442. var preInit = function(editor) {
  26443. var settings = editor.settings, doc2 = editor.getDoc(), body = editor.getBody();
  26444. firePreInit(editor);
  26445. if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
  26446. doc2.body.spellcheck = false;
  26447. DOM$6.setAttrib(body, "spellcheck", "false");
  26448. }
  26449. editor.quirks = Quirks(editor);
  26450. firePostRender(editor);
  26451. var directionality = getDirectionality(editor);
  26452. if (directionality !== void 0) {
  26453. body.dir = directionality;
  26454. }
  26455. if (settings.protect) {
  26456. editor.on("BeforeSetContent", function(e) {
  26457. Tools.each(settings.protect, function(pattern) {
  26458. e.content = e.content.replace(pattern, function(str) {
  26459. return "<!--mce:protected " + escape(str) + "-->";
  26460. });
  26461. });
  26462. });
  26463. }
  26464. editor.on("SetContent", function() {
  26465. editor.addVisual(editor.getBody());
  26466. });
  26467. editor.on("compositionstart compositionend", function(e) {
  26468. editor.composing = e.type === "compositionstart";
  26469. });
  26470. };
  26471. var loadInitialContent = function(editor) {
  26472. if (!isRtc(editor)) {
  26473. editor.load({
  26474. initial: true,
  26475. format: "html"
  26476. });
  26477. }
  26478. editor.startContent = editor.getContent({ format: "raw" });
  26479. };
  26480. var initEditorWithInitialContent = function(editor) {
  26481. if (editor.removed !== true) {
  26482. loadInitialContent(editor);
  26483. initEditor(editor);
  26484. }
  26485. };
  26486. var initContentBody = function(editor, skipWrite) {
  26487. var settings = editor.settings;
  26488. var targetElm = editor.getElement();
  26489. var doc2 = editor.getDoc();
  26490. if (!settings.inline) {
  26491. editor.getElement().style.visibility = editor.orgVisibility;
  26492. }
  26493. if (!skipWrite && !editor.inline) {
  26494. doc2.open();
  26495. doc2.write(editor.iframeHTML);
  26496. doc2.close();
  26497. }
  26498. if (editor.inline) {
  26499. DOM$6.addClass(targetElm, "mce-content-body");
  26500. editor.contentDocument = doc2 = document;
  26501. editor.contentWindow = window;
  26502. editor.bodyElement = targetElm;
  26503. editor.contentAreaContainer = targetElm;
  26504. }
  26505. var body = editor.getBody();
  26506. body.disabled = true;
  26507. editor.readonly = !!settings.readonly;
  26508. if (!editor.readonly) {
  26509. if (editor.inline && DOM$6.getStyle(body, "position", true) === "static") {
  26510. body.style.position = "relative";
  26511. }
  26512. body.contentEditable = editor.getParam("content_editable_state", true);
  26513. }
  26514. body.disabled = false;
  26515. editor.editorUpload = EditorUpload(editor);
  26516. editor.schema = Schema(mkSchemaSettings(editor));
  26517. editor.dom = DOMUtils(doc2, {
  26518. keep_values: true,
  26519. url_converter: editor.convertURL,
  26520. url_converter_scope: editor,
  26521. hex_colors: settings.force_hex_style_colors,
  26522. update_styles: true,
  26523. root_element: editor.inline ? editor.getBody() : null,
  26524. collect: function() {
  26525. return editor.inline;
  26526. },
  26527. schema: editor.schema,
  26528. contentCssCors: shouldUseContentCssCors(editor),
  26529. referrerPolicy: getReferrerPolicy(editor),
  26530. onSetAttrib: function(e) {
  26531. editor.fire("SetAttrib", e);
  26532. }
  26533. });
  26534. editor.parser = createParser(editor);
  26535. editor.serializer = DomSerializer(mkSerializerSettings(editor), editor);
  26536. editor.selection = EditorSelection(editor.dom, editor.getWin(), editor.serializer, editor);
  26537. editor.annotator = Annotator(editor);
  26538. editor.formatter = Formatter(editor);
  26539. editor.undoManager = UndoManager(editor);
  26540. editor._nodeChangeDispatcher = new NodeChange(editor);
  26541. editor._selectionOverrides = SelectionOverrides(editor);
  26542. setup$e(editor);
  26543. setup$3(editor);
  26544. if (!isRtc(editor)) {
  26545. setup$2(editor);
  26546. }
  26547. var caret = setup$4(editor);
  26548. setup$f(editor, caret);
  26549. setup$d(editor);
  26550. setup$g(editor);
  26551. var setupRtcThunk = setup$i(editor);
  26552. preInit(editor);
  26553. setupRtcThunk.fold(function() {
  26554. loadContentCss(editor).then(function() {
  26555. return initEditorWithInitialContent(editor);
  26556. });
  26557. }, function(setupRtc) {
  26558. editor.setProgressState(true);
  26559. loadContentCss(editor).then(function() {
  26560. setupRtc().then(function(_rtcMode) {
  26561. editor.setProgressState(false);
  26562. initEditorWithInitialContent(editor);
  26563. }, function(err) {
  26564. editor.notificationManager.open({
  26565. type: "error",
  26566. text: String(err)
  26567. });
  26568. initEditorWithInitialContent(editor);
  26569. });
  26570. });
  26571. });
  26572. };
  26573. var DOM$5 = DOMUtils.DOM;
  26574. var relaxDomain = function(editor, ifr) {
  26575. if (document.domain !== window.location.hostname && Env.browser.isIE()) {
  26576. var bodyUuid = uuid("mce");
  26577. editor[bodyUuid] = function() {
  26578. initContentBody(editor);
  26579. };
  26580. var domainRelaxUrl = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinymce.get("' + editor.id + '");document.write(ed.iframeHTML);document.close();ed.' + bodyUuid + "(true);})()";
  26581. DOM$5.setAttrib(ifr, "src", domainRelaxUrl);
  26582. return true;
  26583. }
  26584. return false;
  26585. };
  26586. var createIframeElement = function(id, title, height, customAttrs) {
  26587. var iframe = SugarElement.fromTag("iframe");
  26588. setAll$1(iframe, customAttrs);
  26589. setAll$1(iframe, {
  26590. id: id + "_ifr",
  26591. frameBorder: "0",
  26592. allowTransparency: "true",
  26593. title
  26594. });
  26595. add$1(iframe, "tox-edit-area__iframe");
  26596. return iframe;
  26597. };
  26598. var getIframeHtml = function(editor) {
  26599. var iframeHTML = getDocType(editor) + "<html><head>";
  26600. if (getDocumentBaseUrl(editor) !== editor.documentBaseUrl) {
  26601. iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />';
  26602. }
  26603. iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  26604. var bodyId = getBodyId(editor);
  26605. var bodyClass = getBodyClass(editor);
  26606. var translatedAriaText = editor.translate(getIframeAriaText(editor));
  26607. if (getContentSecurityPolicy(editor)) {
  26608. iframeHTML += '<meta http-equiv="Content-Security-Policy" content="' + getContentSecurityPolicy(editor) + '" />';
  26609. }
  26610. iframeHTML += "</head>" + ('<body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '" data-id="' + editor.id + '" aria-label="' + translatedAriaText + '">') + "<br></body></html>";
  26611. return iframeHTML;
  26612. };
  26613. var createIframe = function(editor, o) {
  26614. var iframeTitle = editor.translate("Rich Text Area");
  26615. var ifr = createIframeElement(editor.id, iframeTitle, o.height, getIframeAttrs(editor)).dom;
  26616. ifr.onload = function() {
  26617. ifr.onload = null;
  26618. editor.fire("load");
  26619. };
  26620. var isDomainRelaxed = relaxDomain(editor, ifr);
  26621. editor.contentAreaContainer = o.iframeContainer;
  26622. editor.iframeElement = ifr;
  26623. editor.iframeHTML = getIframeHtml(editor);
  26624. DOM$5.add(o.iframeContainer, ifr);
  26625. return isDomainRelaxed;
  26626. };
  26627. var init$1 = function(editor, boxInfo) {
  26628. var isDomainRelaxed = createIframe(editor, boxInfo);
  26629. if (boxInfo.editorContainer) {
  26630. DOM$5.get(boxInfo.editorContainer).style.display = editor.orgDisplay;
  26631. editor.hidden = DOM$5.isHidden(boxInfo.editorContainer);
  26632. }
  26633. editor.getElement().style.display = "none";
  26634. DOM$5.setAttrib(editor.id, "aria-hidden", "true");
  26635. if (!isDomainRelaxed) {
  26636. initContentBody(editor);
  26637. }
  26638. };
  26639. var DOM$4 = DOMUtils.DOM;
  26640. var initPlugin = function(editor, initializedPlugins, plugin) {
  26641. var Plugin = PluginManager.get(plugin);
  26642. var pluginUrl = PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, "");
  26643. plugin = Tools.trim(plugin);
  26644. if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) {
  26645. Tools.each(PluginManager.dependencies(plugin), function(dep) {
  26646. initPlugin(editor, initializedPlugins, dep);
  26647. });
  26648. if (editor.plugins[plugin]) {
  26649. return;
  26650. }
  26651. try {
  26652. var pluginInstance = new Plugin(editor, pluginUrl, editor.$);
  26653. editor.plugins[plugin] = pluginInstance;
  26654. if (pluginInstance.init) {
  26655. pluginInstance.init(editor, pluginUrl);
  26656. initializedPlugins.push(plugin);
  26657. }
  26658. } catch (e) {
  26659. pluginInitError(editor, plugin, e);
  26660. }
  26661. }
  26662. };
  26663. var trimLegacyPrefix = function(name2) {
  26664. return name2.replace(/^\-/, "");
  26665. };
  26666. var initPlugins = function(editor) {
  26667. var initializedPlugins = [];
  26668. Tools.each(getPlugins(editor).split(/[ ,]/), function(name2) {
  26669. initPlugin(editor, initializedPlugins, trimLegacyPrefix(name2));
  26670. });
  26671. };
  26672. var initIcons = function(editor) {
  26673. var iconPackName = Tools.trim(getIconPackName(editor));
  26674. var currentIcons = editor.ui.registry.getAll().icons;
  26675. var loadIcons2 = __assign(__assign({}, IconManager.get("default").icons), IconManager.get(iconPackName).icons);
  26676. each$j(loadIcons2, function(svgData, icon) {
  26677. if (!has$2(currentIcons, icon)) {
  26678. editor.ui.registry.addIcon(icon, svgData);
  26679. }
  26680. });
  26681. };
  26682. var initTheme = function(editor) {
  26683. var theme = getTheme(editor);
  26684. if (isString$1(theme)) {
  26685. editor.settings.theme = trimLegacyPrefix(theme);
  26686. var Theme = ThemeManager.get(theme);
  26687. editor.theme = new Theme(editor, ThemeManager.urls[theme]);
  26688. if (editor.theme.init) {
  26689. editor.theme.init(editor, ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ""), editor.$);
  26690. }
  26691. } else {
  26692. editor.theme = {};
  26693. }
  26694. };
  26695. var renderFromLoadedTheme = function(editor) {
  26696. return editor.theme.renderUI();
  26697. };
  26698. var renderFromThemeFunc = function(editor) {
  26699. var elm = editor.getElement();
  26700. var theme = getTheme(editor);
  26701. var info = theme(editor, elm);
  26702. if (info.editorContainer.nodeType) {
  26703. info.editorContainer.id = info.editorContainer.id || editor.id + "_parent";
  26704. }
  26705. if (info.iframeContainer && info.iframeContainer.nodeType) {
  26706. info.iframeContainer.id = info.iframeContainer.id || editor.id + "_iframecontainer";
  26707. }
  26708. info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight;
  26709. return info;
  26710. };
  26711. var createThemeFalseResult = function(element) {
  26712. return {
  26713. editorContainer: element,
  26714. iframeContainer: element,
  26715. api: {}
  26716. };
  26717. };
  26718. var renderThemeFalseIframe = function(targetElement) {
  26719. var iframeContainer = DOM$4.create("div");
  26720. DOM$4.insertAfter(iframeContainer, targetElement);
  26721. return createThemeFalseResult(iframeContainer);
  26722. };
  26723. var renderThemeFalse = function(editor) {
  26724. var targetElement = editor.getElement();
  26725. return editor.inline ? createThemeFalseResult(null) : renderThemeFalseIframe(targetElement);
  26726. };
  26727. var renderThemeUi = function(editor) {
  26728. var elm = editor.getElement();
  26729. editor.orgDisplay = elm.style.display;
  26730. if (isString$1(getTheme(editor))) {
  26731. return renderFromLoadedTheme(editor);
  26732. } else if (isFunction(getTheme(editor))) {
  26733. return renderFromThemeFunc(editor);
  26734. } else {
  26735. return renderThemeFalse(editor);
  26736. }
  26737. };
  26738. var augmentEditorUiApi = function(editor, api2) {
  26739. var uiApiFacade = {
  26740. show: Optional.from(api2.show).getOr(noop),
  26741. hide: Optional.from(api2.hide).getOr(noop),
  26742. disable: Optional.from(api2.disable).getOr(noop),
  26743. isDisabled: Optional.from(api2.isDisabled).getOr(never),
  26744. enable: function() {
  26745. if (!editor.mode.isReadOnly()) {
  26746. Optional.from(api2.enable).map(call);
  26747. }
  26748. }
  26749. };
  26750. editor.ui = __assign(__assign({}, editor.ui), uiApiFacade);
  26751. };
  26752. var init = function(editor) {
  26753. editor.fire("ScriptsLoaded");
  26754. initIcons(editor);
  26755. initTheme(editor);
  26756. initPlugins(editor);
  26757. var renderInfo = renderThemeUi(editor);
  26758. augmentEditorUiApi(editor, Optional.from(renderInfo.api).getOr({}));
  26759. var boxInfo = {
  26760. editorContainer: renderInfo.editorContainer,
  26761. iframeContainer: renderInfo.iframeContainer
  26762. };
  26763. editor.editorContainer = boxInfo.editorContainer ? boxInfo.editorContainer : null;
  26764. appendContentCssFromSettings(editor);
  26765. if (editor.inline) {
  26766. return initContentBody(editor);
  26767. } else {
  26768. return init$1(editor, boxInfo);
  26769. }
  26770. };
  26771. var DOM$3 = DOMUtils.DOM;
  26772. var hasSkipLoadPrefix = function(name2) {
  26773. return name2.charAt(0) === "-";
  26774. };
  26775. var loadLanguage = function(scriptLoader, editor) {
  26776. var languageCode = getLanguageCode(editor);
  26777. var languageUrl = getLanguageUrl(editor);
  26778. if (I18n.hasCode(languageCode) === false && languageCode !== "en") {
  26779. var url_1 = languageUrl !== "" ? languageUrl : editor.editorManager.baseURL + "/langs/" + languageCode + ".js";
  26780. scriptLoader.add(url_1, noop, void 0, function() {
  26781. languageLoadError(editor, url_1, languageCode);
  26782. });
  26783. }
  26784. };
  26785. var loadTheme = function(scriptLoader, editor, suffix, callback) {
  26786. var theme = getTheme(editor);
  26787. if (isString$1(theme)) {
  26788. if (!hasSkipLoadPrefix(theme) && !has$2(ThemeManager.urls, theme)) {
  26789. var themeUrl = getThemeUrl(editor);
  26790. if (themeUrl) {
  26791. ThemeManager.load(theme, editor.documentBaseURI.toAbsolute(themeUrl));
  26792. } else {
  26793. ThemeManager.load(theme, "themes/" + theme + "/theme" + suffix + ".js");
  26794. }
  26795. }
  26796. scriptLoader.loadQueue(function() {
  26797. ThemeManager.waitFor(theme, callback);
  26798. });
  26799. } else {
  26800. callback();
  26801. }
  26802. };
  26803. var getIconsUrlMetaFromUrl = function(editor) {
  26804. return Optional.from(getIconsUrl(editor)).filter(function(url) {
  26805. return url.length > 0;
  26806. }).map(function(url) {
  26807. return {
  26808. url,
  26809. name: Optional.none()
  26810. };
  26811. });
  26812. };
  26813. var getIconsUrlMetaFromName = function(editor, name2, suffix) {
  26814. return Optional.from(name2).filter(function(name3) {
  26815. return name3.length > 0 && !IconManager.has(name3);
  26816. }).map(function(name3) {
  26817. return {
  26818. url: editor.editorManager.baseURL + "/icons/" + name3 + "/icons" + suffix + ".js",
  26819. name: Optional.some(name3)
  26820. };
  26821. });
  26822. };
  26823. var loadIcons = function(scriptLoader, editor, suffix) {
  26824. var defaultIconsUrl = getIconsUrlMetaFromName(editor, "default", suffix);
  26825. var customIconsUrl = getIconsUrlMetaFromUrl(editor).orThunk(function() {
  26826. return getIconsUrlMetaFromName(editor, getIconPackName(editor), "");
  26827. });
  26828. each$k(cat([
  26829. defaultIconsUrl,
  26830. customIconsUrl
  26831. ]), function(urlMeta) {
  26832. scriptLoader.add(urlMeta.url, noop, void 0, function() {
  26833. iconsLoadError(editor, urlMeta.url, urlMeta.name.getOrUndefined());
  26834. });
  26835. });
  26836. };
  26837. var loadPlugins = function(editor, suffix) {
  26838. Tools.each(getExternalPlugins$1(editor), function(url, name2) {
  26839. PluginManager.load(name2, url, noop, void 0, function() {
  26840. pluginLoadError(editor, url, name2);
  26841. });
  26842. editor.settings.plugins += " " + name2;
  26843. });
  26844. Tools.each(getPlugins(editor).split(/[ ,]/), function(plugin) {
  26845. plugin = Tools.trim(plugin);
  26846. if (plugin && !PluginManager.urls[plugin]) {
  26847. if (hasSkipLoadPrefix(plugin)) {
  26848. plugin = plugin.substr(1, plugin.length);
  26849. var dependencies = PluginManager.dependencies(plugin);
  26850. Tools.each(dependencies, function(depPlugin) {
  26851. var defaultSettings = {
  26852. prefix: "plugins/",
  26853. resource: depPlugin,
  26854. suffix: "/plugin" + suffix + ".js"
  26855. };
  26856. var dep = PluginManager.createUrl(defaultSettings, depPlugin);
  26857. PluginManager.load(dep.resource, dep, noop, void 0, function() {
  26858. pluginLoadError(editor, dep.prefix + dep.resource + dep.suffix, dep.resource);
  26859. });
  26860. });
  26861. } else {
  26862. var url_2 = {
  26863. prefix: "plugins/",
  26864. resource: plugin,
  26865. suffix: "/plugin" + suffix + ".js"
  26866. };
  26867. PluginManager.load(plugin, url_2, noop, void 0, function() {
  26868. pluginLoadError(editor, url_2.prefix + url_2.resource + url_2.suffix, plugin);
  26869. });
  26870. }
  26871. }
  26872. });
  26873. };
  26874. var loadScripts = function(editor, suffix) {
  26875. var scriptLoader = ScriptLoader.ScriptLoader;
  26876. loadTheme(scriptLoader, editor, suffix, function() {
  26877. loadLanguage(scriptLoader, editor);
  26878. loadIcons(scriptLoader, editor, suffix);
  26879. loadPlugins(editor, suffix);
  26880. scriptLoader.loadQueue(function() {
  26881. if (!editor.removed) {
  26882. init(editor);
  26883. }
  26884. }, editor, function() {
  26885. if (!editor.removed) {
  26886. init(editor);
  26887. }
  26888. });
  26889. });
  26890. };
  26891. var getStyleSheetLoader = function(element, editor) {
  26892. return instance.forElement(element, {
  26893. contentCssCors: hasContentCssCors(editor),
  26894. referrerPolicy: getReferrerPolicy(editor)
  26895. });
  26896. };
  26897. var render = function(editor) {
  26898. var id = editor.id;
  26899. I18n.setCode(getLanguageCode(editor));
  26900. var readyHandler = function() {
  26901. DOM$3.unbind(window, "ready", readyHandler);
  26902. editor.render();
  26903. };
  26904. if (!EventUtils.Event.domLoaded) {
  26905. DOM$3.bind(window, "ready", readyHandler);
  26906. return;
  26907. }
  26908. if (!editor.getElement()) {
  26909. return;
  26910. }
  26911. if (!Env.contentEditable) {
  26912. return;
  26913. }
  26914. var element = SugarElement.fromDom(editor.getElement());
  26915. var snapshot = clone$3(element);
  26916. editor.on("remove", function() {
  26917. eachr(element.dom.attributes, function(attr) {
  26918. return remove$6(element, attr.name);
  26919. });
  26920. setAll$1(element, snapshot);
  26921. });
  26922. editor.ui.styleSheetLoader = getStyleSheetLoader(element, editor);
  26923. if (!isInline(editor)) {
  26924. editor.orgVisibility = editor.getElement().style.visibility;
  26925. editor.getElement().style.visibility = "hidden";
  26926. } else {
  26927. editor.inline = true;
  26928. }
  26929. var form = editor.getElement().form || DOM$3.getParent(id, "form");
  26930. if (form) {
  26931. editor.formElement = form;
  26932. if (hasHiddenInput(editor) && !isTextareaOrInput(editor.getElement())) {
  26933. DOM$3.insertAfter(DOM$3.create("input", {
  26934. type: "hidden",
  26935. name: id
  26936. }), id);
  26937. editor.hasHiddenInput = true;
  26938. }
  26939. editor.formEventDelegate = function(e) {
  26940. editor.fire(e.type, e);
  26941. };
  26942. DOM$3.bind(form, "submit reset", editor.formEventDelegate);
  26943. editor.on("reset", function() {
  26944. editor.resetContent();
  26945. });
  26946. if (shouldPatchSubmit(editor) && !form.submit.nodeType && !form.submit.length && !form._mceOldSubmit) {
  26947. form._mceOldSubmit = form.submit;
  26948. form.submit = function() {
  26949. editor.editorManager.triggerSave();
  26950. editor.setDirty(false);
  26951. return form._mceOldSubmit(form);
  26952. };
  26953. }
  26954. }
  26955. editor.windowManager = WindowManager(editor);
  26956. editor.notificationManager = NotificationManager(editor);
  26957. if (isEncodingXml(editor)) {
  26958. editor.on("GetContent", function(e) {
  26959. if (e.save) {
  26960. e.content = DOM$3.encode(e.content);
  26961. }
  26962. });
  26963. }
  26964. if (shouldAddFormSubmitTrigger(editor)) {
  26965. editor.on("submit", function() {
  26966. if (editor.initialized) {
  26967. editor.save();
  26968. }
  26969. });
  26970. }
  26971. if (shouldAddUnloadTrigger(editor)) {
  26972. editor._beforeUnload = function() {
  26973. if (editor.initialized && !editor.destroyed && !editor.isHidden()) {
  26974. editor.save({
  26975. format: "raw",
  26976. no_events: true,
  26977. set_dirty: false
  26978. });
  26979. }
  26980. };
  26981. editor.editorManager.on("BeforeUnload", editor._beforeUnload);
  26982. }
  26983. editor.editorManager.add(editor);
  26984. loadScripts(editor, editor.suffix);
  26985. };
  26986. var addVisual = function(editor, elm) {
  26987. return addVisual$1(editor, elm);
  26988. };
  26989. var legacyPropNames = {
  26990. "font-size": "size",
  26991. "font-family": "face"
  26992. };
  26993. var getSpecifiedFontProp = function(propName, rootElm, elm) {
  26994. var getProperty = function(elm2) {
  26995. return getRaw(elm2, propName).orThunk(function() {
  26996. if (name(elm2) === "font") {
  26997. return get$9(legacyPropNames, propName).bind(function(legacyPropName) {
  26998. return getOpt(elm2, legacyPropName);
  26999. });
  27000. } else {
  27001. return Optional.none();
  27002. }
  27003. });
  27004. };
  27005. var isRoot = function(elm2) {
  27006. return eq(SugarElement.fromDom(rootElm), elm2);
  27007. };
  27008. return closest$1(SugarElement.fromDom(elm), function(elm2) {
  27009. return getProperty(elm2);
  27010. }, isRoot);
  27011. };
  27012. var normalizeFontFamily = function(fontFamily) {
  27013. return fontFamily.replace(/[\'\"\\]/g, "").replace(/,\s+/g, ",");
  27014. };
  27015. var getComputedFontProp = function(propName, elm) {
  27016. return Optional.from(DOMUtils.DOM.getStyle(elm, propName, true));
  27017. };
  27018. var getFontProp = function(propName) {
  27019. return function(rootElm, elm) {
  27020. return Optional.from(elm).map(SugarElement.fromDom).filter(isElement$6).bind(function(element) {
  27021. return getSpecifiedFontProp(propName, rootElm, element.dom).or(getComputedFontProp(propName, element.dom));
  27022. }).getOr("");
  27023. };
  27024. };
  27025. var getFontSize = getFontProp("font-size");
  27026. var getFontFamily = compose(normalizeFontFamily, getFontProp("font-family"));
  27027. var findFirstCaretElement = function(editor) {
  27028. return firstPositionIn(editor.getBody()).map(function(caret) {
  27029. var container = caret.container();
  27030. return isText$7(container) ? container.parentNode : container;
  27031. });
  27032. };
  27033. var getCaretElement = function(editor) {
  27034. return Optional.from(editor.selection.getRng()).bind(function(rng) {
  27035. var root = editor.getBody();
  27036. var atStartOfNode = rng.startContainer === root && rng.startOffset === 0;
  27037. return atStartOfNode ? Optional.none() : Optional.from(editor.selection.getStart(true));
  27038. });
  27039. };
  27040. var bindRange = function(editor, binder) {
  27041. return getCaretElement(editor).orThunk(curry(findFirstCaretElement, editor)).map(SugarElement.fromDom).filter(isElement$6).bind(binder);
  27042. };
  27043. var mapRange = function(editor, mapper) {
  27044. return bindRange(editor, compose1(Optional.some, mapper));
  27045. };
  27046. var fromFontSizeNumber = function(editor, value2) {
  27047. if (/^[0-9.]+$/.test(value2)) {
  27048. var fontSizeNumber = parseInt(value2, 10);
  27049. if (fontSizeNumber >= 1 && fontSizeNumber <= 7) {
  27050. var fontSizes = getFontStyleValues(editor);
  27051. var fontClasses = getFontSizeClasses(editor);
  27052. if (fontClasses) {
  27053. return fontClasses[fontSizeNumber - 1] || value2;
  27054. } else {
  27055. return fontSizes[fontSizeNumber - 1] || value2;
  27056. }
  27057. } else {
  27058. return value2;
  27059. }
  27060. } else {
  27061. return value2;
  27062. }
  27063. };
  27064. var normalizeFontNames = function(font) {
  27065. var fonts = font.split(/\s*,\s*/);
  27066. return map$3(fonts, function(font2) {
  27067. if (font2.indexOf(" ") !== -1 && !(startsWith(font2, '"') || startsWith(font2, "'"))) {
  27068. return "'" + font2 + "'";
  27069. } else {
  27070. return font2;
  27071. }
  27072. }).join(",");
  27073. };
  27074. var fontNameAction = function(editor, value2) {
  27075. var font = fromFontSizeNumber(editor, value2);
  27076. editor.formatter.toggle("fontname", { value: normalizeFontNames(font) });
  27077. editor.nodeChanged();
  27078. };
  27079. var fontNameQuery = function(editor) {
  27080. return mapRange(editor, function(elm) {
  27081. return getFontFamily(editor.getBody(), elm.dom);
  27082. }).getOr("");
  27083. };
  27084. var fontSizeAction = function(editor, value2) {
  27085. editor.formatter.toggle("fontsize", { value: fromFontSizeNumber(editor, value2) });
  27086. editor.nodeChanged();
  27087. };
  27088. var fontSizeQuery = function(editor) {
  27089. return mapRange(editor, function(elm) {
  27090. return getFontSize(editor.getBody(), elm.dom);
  27091. }).getOr("");
  27092. };
  27093. var lineHeightQuery = function(editor) {
  27094. return mapRange(editor, function(elm) {
  27095. var root = SugarElement.fromDom(editor.getBody());
  27096. var specifiedStyle = closest$1(elm, function(elm2) {
  27097. return getRaw(elm2, "line-height");
  27098. }, curry(eq, root));
  27099. var computedStyle = function() {
  27100. var lineHeight = parseFloat(get$5(elm, "line-height"));
  27101. var fontSize = parseFloat(get$5(elm, "font-size"));
  27102. return String(lineHeight / fontSize);
  27103. };
  27104. return specifiedStyle.getOrThunk(computedStyle);
  27105. }).getOr("");
  27106. };
  27107. var lineHeightAction = function(editor, lineHeight) {
  27108. editor.formatter.toggle("lineheight", { value: String(lineHeight) });
  27109. editor.nodeChanged();
  27110. };
  27111. var processValue = function(value2) {
  27112. if (typeof value2 !== "string") {
  27113. var details = Tools.extend({
  27114. paste: value2.paste,
  27115. data: { paste: value2.paste }
  27116. }, value2);
  27117. return {
  27118. content: value2.content,
  27119. details
  27120. };
  27121. }
  27122. return {
  27123. content: value2,
  27124. details: {}
  27125. };
  27126. };
  27127. var insertAtCaret = function(editor, value2) {
  27128. var result = processValue(value2);
  27129. insertContent(editor, result.content, result.details);
  27130. };
  27131. var each$4 = Tools.each;
  27132. var map = Tools.map, inArray = Tools.inArray;
  27133. var EditorCommands = function() {
  27134. function EditorCommands2(editor) {
  27135. this.commands = {
  27136. state: {},
  27137. exec: {},
  27138. value: {}
  27139. };
  27140. this.editor = editor;
  27141. this.setupCommands(editor);
  27142. }
  27143. EditorCommands2.prototype.execCommand = function(command, ui, value2, args) {
  27144. var func, state = false;
  27145. var self2 = this;
  27146. if (self2.editor.removed) {
  27147. return;
  27148. }
  27149. if (command.toLowerCase() !== "mcefocus") {
  27150. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(command) && (!args || !args.skip_focus)) {
  27151. self2.editor.focus();
  27152. } else {
  27153. restore(self2.editor);
  27154. }
  27155. }
  27156. args = self2.editor.fire("BeforeExecCommand", {
  27157. command,
  27158. ui,
  27159. value: value2
  27160. });
  27161. if (args.isDefaultPrevented()) {
  27162. return false;
  27163. }
  27164. var customCommand = command.toLowerCase();
  27165. if (func = self2.commands.exec[customCommand]) {
  27166. func(customCommand, ui, value2);
  27167. self2.editor.fire("ExecCommand", {
  27168. command,
  27169. ui,
  27170. value: value2
  27171. });
  27172. return true;
  27173. }
  27174. each$4(this.editor.plugins, function(p) {
  27175. if (p.execCommand && p.execCommand(command, ui, value2)) {
  27176. self2.editor.fire("ExecCommand", {
  27177. command,
  27178. ui,
  27179. value: value2
  27180. });
  27181. state = true;
  27182. return false;
  27183. }
  27184. });
  27185. if (state) {
  27186. return state;
  27187. }
  27188. if (self2.editor.theme && self2.editor.theme.execCommand && self2.editor.theme.execCommand(command, ui, value2)) {
  27189. self2.editor.fire("ExecCommand", {
  27190. command,
  27191. ui,
  27192. value: value2
  27193. });
  27194. return true;
  27195. }
  27196. try {
  27197. state = self2.editor.getDoc().execCommand(command, ui, value2);
  27198. } catch (ex) {
  27199. }
  27200. if (state) {
  27201. self2.editor.fire("ExecCommand", {
  27202. command,
  27203. ui,
  27204. value: value2
  27205. });
  27206. return true;
  27207. }
  27208. return false;
  27209. };
  27210. EditorCommands2.prototype.queryCommandState = function(command) {
  27211. var func;
  27212. if (this.editor.quirks.isHidden() || this.editor.removed) {
  27213. return;
  27214. }
  27215. command = command.toLowerCase();
  27216. if (func = this.commands.state[command]) {
  27217. return func(command);
  27218. }
  27219. try {
  27220. return this.editor.getDoc().queryCommandState(command);
  27221. } catch (ex) {
  27222. }
  27223. return false;
  27224. };
  27225. EditorCommands2.prototype.queryCommandValue = function(command) {
  27226. var func;
  27227. if (this.editor.quirks.isHidden() || this.editor.removed) {
  27228. return;
  27229. }
  27230. command = command.toLowerCase();
  27231. if (func = this.commands.value[command]) {
  27232. return func(command);
  27233. }
  27234. try {
  27235. return this.editor.getDoc().queryCommandValue(command);
  27236. } catch (ex) {
  27237. }
  27238. };
  27239. EditorCommands2.prototype.addCommands = function(commandList, type2) {
  27240. if (type2 === void 0) {
  27241. type2 = "exec";
  27242. }
  27243. var self2 = this;
  27244. each$4(commandList, function(callback, command) {
  27245. each$4(command.toLowerCase().split(","), function(command2) {
  27246. self2.commands[type2][command2] = callback;
  27247. });
  27248. });
  27249. };
  27250. EditorCommands2.prototype.addCommand = function(command, callback, scope) {
  27251. var _this = this;
  27252. command = command.toLowerCase();
  27253. this.commands.exec[command] = function(command2, ui, value2, args) {
  27254. return callback.call(scope || _this.editor, ui, value2, args);
  27255. };
  27256. };
  27257. EditorCommands2.prototype.queryCommandSupported = function(command) {
  27258. command = command.toLowerCase();
  27259. if (this.commands.exec[command]) {
  27260. return true;
  27261. }
  27262. try {
  27263. return this.editor.getDoc().queryCommandSupported(command);
  27264. } catch (ex) {
  27265. }
  27266. return false;
  27267. };
  27268. EditorCommands2.prototype.addQueryStateHandler = function(command, callback, scope) {
  27269. var _this = this;
  27270. command = command.toLowerCase();
  27271. this.commands.state[command] = function() {
  27272. return callback.call(scope || _this.editor);
  27273. };
  27274. };
  27275. EditorCommands2.prototype.addQueryValueHandler = function(command, callback, scope) {
  27276. var _this = this;
  27277. command = command.toLowerCase();
  27278. this.commands.value[command] = function() {
  27279. return callback.call(scope || _this.editor);
  27280. };
  27281. };
  27282. EditorCommands2.prototype.hasCustomCommand = function(command) {
  27283. command = command.toLowerCase();
  27284. return !!this.commands.exec[command];
  27285. };
  27286. EditorCommands2.prototype.execNativeCommand = function(command, ui, value2) {
  27287. if (ui === void 0) {
  27288. ui = false;
  27289. }
  27290. if (value2 === void 0) {
  27291. value2 = null;
  27292. }
  27293. return this.editor.getDoc().execCommand(command, ui, value2);
  27294. };
  27295. EditorCommands2.prototype.isFormatMatch = function(name2) {
  27296. return this.editor.formatter.match(name2);
  27297. };
  27298. EditorCommands2.prototype.toggleFormat = function(name2, value2) {
  27299. this.editor.formatter.toggle(name2, value2);
  27300. this.editor.nodeChanged();
  27301. };
  27302. EditorCommands2.prototype.storeSelection = function(type2) {
  27303. this.selectionBookmark = this.editor.selection.getBookmark(type2);
  27304. };
  27305. EditorCommands2.prototype.restoreSelection = function() {
  27306. this.editor.selection.moveToBookmark(this.selectionBookmark);
  27307. };
  27308. EditorCommands2.prototype.setupCommands = function(editor) {
  27309. var self2 = this;
  27310. this.addCommands({
  27311. "mceResetDesignMode,mceBeginUndoLevel": noop,
  27312. "mceEndUndoLevel,mceAddUndoLevel": function() {
  27313. editor.undoManager.add();
  27314. },
  27315. "mceFocus": function(_command, _ui, value2) {
  27316. focus(editor, value2);
  27317. },
  27318. "Cut,Copy,Paste": function(command) {
  27319. var doc2 = editor.getDoc();
  27320. var failed;
  27321. try {
  27322. self2.execNativeCommand(command);
  27323. } catch (ex) {
  27324. failed = true;
  27325. }
  27326. if (command === "paste" && !doc2.queryCommandEnabled(command)) {
  27327. failed = true;
  27328. }
  27329. if (failed || !doc2.queryCommandSupported(command)) {
  27330. var msg = editor.translate("Your browser doesn't support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.");
  27331. if (Env.mac) {
  27332. msg = msg.replace(/Ctrl\+/g, "\u2318+");
  27333. }
  27334. editor.notificationManager.open({
  27335. text: msg,
  27336. type: "error"
  27337. });
  27338. }
  27339. },
  27340. "unlink": function() {
  27341. if (editor.selection.isCollapsed()) {
  27342. var elm = editor.dom.getParent(editor.selection.getStart(), "a");
  27343. if (elm) {
  27344. editor.dom.remove(elm, true);
  27345. }
  27346. return;
  27347. }
  27348. editor.formatter.remove("link");
  27349. },
  27350. "JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone": function(command) {
  27351. var align = command.substring(7);
  27352. if (align === "full") {
  27353. align = "justify";
  27354. }
  27355. each$4("left,center,right,justify".split(","), function(name2) {
  27356. if (align !== name2) {
  27357. editor.formatter.remove("align" + name2);
  27358. }
  27359. });
  27360. if (align !== "none") {
  27361. self2.toggleFormat("align" + align);
  27362. }
  27363. },
  27364. "InsertUnorderedList,InsertOrderedList": function(command) {
  27365. var listParent;
  27366. self2.execNativeCommand(command);
  27367. var listElm = editor.dom.getParent(editor.selection.getNode(), "ol,ul");
  27368. if (listElm) {
  27369. listParent = listElm.parentNode;
  27370. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  27371. self2.storeSelection();
  27372. editor.dom.split(listParent, listElm);
  27373. self2.restoreSelection();
  27374. }
  27375. }
  27376. },
  27377. "Bold,Italic,Underline,Strikethrough,Superscript,Subscript": function(command) {
  27378. self2.toggleFormat(command);
  27379. },
  27380. "ForeColor,HiliteColor": function(command, ui, value2) {
  27381. self2.toggleFormat(command, { value: value2 });
  27382. },
  27383. "FontName": function(command, ui, value2) {
  27384. fontNameAction(editor, value2);
  27385. },
  27386. "FontSize": function(command, ui, value2) {
  27387. fontSizeAction(editor, value2);
  27388. },
  27389. "LineHeight": function(command, ui, value2) {
  27390. lineHeightAction(editor, value2);
  27391. },
  27392. "Lang": function(command, ui, lang) {
  27393. self2.toggleFormat(command, {
  27394. value: lang.code,
  27395. customValue: lang.customCode
  27396. });
  27397. },
  27398. "RemoveFormat": function(command) {
  27399. editor.formatter.remove(command);
  27400. },
  27401. "mceBlockQuote": function() {
  27402. self2.toggleFormat("blockquote");
  27403. },
  27404. "FormatBlock": function(command, ui, value2) {
  27405. return self2.toggleFormat(value2 || "p");
  27406. },
  27407. "mceCleanup": function() {
  27408. var bookmark = editor.selection.getBookmark();
  27409. editor.setContent(editor.getContent());
  27410. editor.selection.moveToBookmark(bookmark);
  27411. },
  27412. "mceRemoveNode": function(command, ui, value2) {
  27413. var node = value2 || editor.selection.getNode();
  27414. if (node !== editor.getBody()) {
  27415. self2.storeSelection();
  27416. editor.dom.remove(node, true);
  27417. self2.restoreSelection();
  27418. }
  27419. },
  27420. "mceSelectNodeDepth": function(command, ui, value2) {
  27421. var counter = 0;
  27422. editor.dom.getParent(editor.selection.getNode(), function(node) {
  27423. if (node.nodeType === 1 && counter++ === value2) {
  27424. editor.selection.select(node);
  27425. return false;
  27426. }
  27427. }, editor.getBody());
  27428. },
  27429. "mceSelectNode": function(command, ui, value2) {
  27430. editor.selection.select(value2);
  27431. },
  27432. "mceInsertContent": function(command, ui, value2) {
  27433. insertAtCaret(editor, value2);
  27434. },
  27435. "mceInsertRawHTML": function(command, ui, value2) {
  27436. editor.selection.setContent("tiny_mce_marker");
  27437. var content = editor.getContent();
  27438. editor.setContent(content.replace(/tiny_mce_marker/g, function() {
  27439. return value2;
  27440. }));
  27441. },
  27442. "mceInsertNewLine": function(command, ui, value2) {
  27443. insert(editor, value2);
  27444. },
  27445. "mceToggleFormat": function(command, ui, value2) {
  27446. self2.toggleFormat(value2);
  27447. },
  27448. "mceSetContent": function(command, ui, value2) {
  27449. editor.setContent(value2);
  27450. },
  27451. "Indent,Outdent": function(command) {
  27452. handle(editor, command);
  27453. },
  27454. "mceRepaint": noop,
  27455. "InsertHorizontalRule": function() {
  27456. editor.execCommand("mceInsertContent", false, "<hr />");
  27457. },
  27458. "mceToggleVisualAid": function() {
  27459. editor.hasVisual = !editor.hasVisual;
  27460. editor.addVisual();
  27461. },
  27462. "mceReplaceContent": function(command, ui, value2) {
  27463. editor.execCommand("mceInsertContent", false, value2.replace(/\{\$selection\}/g, editor.selection.getContent({ format: "text" })));
  27464. },
  27465. "mceInsertLink": function(command, ui, value2) {
  27466. if (typeof value2 === "string") {
  27467. value2 = { href: value2 };
  27468. }
  27469. var anchor = editor.dom.getParent(editor.selection.getNode(), "a");
  27470. value2.href = value2.href.replace(/ /g, "%20");
  27471. if (!anchor || !value2.href) {
  27472. editor.formatter.remove("link");
  27473. }
  27474. if (value2.href) {
  27475. editor.formatter.apply("link", value2, anchor);
  27476. }
  27477. },
  27478. "selectAll": function() {
  27479. var editingHost = editor.dom.getParent(editor.selection.getStart(), isContentEditableTrue$4);
  27480. if (editingHost) {
  27481. var rng = editor.dom.createRng();
  27482. rng.selectNodeContents(editingHost);
  27483. editor.selection.setRng(rng);
  27484. }
  27485. },
  27486. "mceNewDocument": function() {
  27487. editor.setContent("");
  27488. },
  27489. "InsertLineBreak": function(command, ui, value2) {
  27490. insert$1(editor, value2);
  27491. return true;
  27492. }
  27493. });
  27494. var alignStates = function(name2) {
  27495. return function() {
  27496. var selection = editor.selection;
  27497. var nodes = selection.isCollapsed() ? [editor.dom.getParent(selection.getNode(), editor.dom.isBlock)] : selection.getSelectedBlocks();
  27498. var matches2 = map(nodes, function(node) {
  27499. return !!editor.formatter.matchNode(node, name2);
  27500. });
  27501. return inArray(matches2, true) !== -1;
  27502. };
  27503. };
  27504. self2.addCommands({
  27505. "JustifyLeft": alignStates("alignleft"),
  27506. "JustifyCenter": alignStates("aligncenter"),
  27507. "JustifyRight": alignStates("alignright"),
  27508. "JustifyFull": alignStates("alignjustify"),
  27509. "Bold,Italic,Underline,Strikethrough,Superscript,Subscript": function(command) {
  27510. return self2.isFormatMatch(command);
  27511. },
  27512. "mceBlockQuote": function() {
  27513. return self2.isFormatMatch("blockquote");
  27514. },
  27515. "Outdent": function() {
  27516. return canOutdent(editor);
  27517. },
  27518. "InsertUnorderedList,InsertOrderedList": function(command) {
  27519. var list = editor.dom.getParent(editor.selection.getNode(), "ul,ol");
  27520. return list && (command === "insertunorderedlist" && list.tagName === "UL" || command === "insertorderedlist" && list.tagName === "OL");
  27521. }
  27522. }, "state");
  27523. self2.addCommands({
  27524. Undo: function() {
  27525. editor.undoManager.undo();
  27526. },
  27527. Redo: function() {
  27528. editor.undoManager.redo();
  27529. }
  27530. });
  27531. self2.addQueryValueHandler("FontName", function() {
  27532. return fontNameQuery(editor);
  27533. }, this);
  27534. self2.addQueryValueHandler("FontSize", function() {
  27535. return fontSizeQuery(editor);
  27536. }, this);
  27537. self2.addQueryValueHandler("LineHeight", function() {
  27538. return lineHeightQuery(editor);
  27539. }, this);
  27540. };
  27541. return EditorCommands2;
  27542. }();
  27543. var internalContentEditableAttr = "data-mce-contenteditable";
  27544. var toggleClass = function(elm, cls, state) {
  27545. if (has(elm, cls) && state === false) {
  27546. remove$3(elm, cls);
  27547. } else if (state) {
  27548. add$1(elm, cls);
  27549. }
  27550. };
  27551. var setEditorCommandState = function(editor, cmd, state) {
  27552. try {
  27553. editor.getDoc().execCommand(cmd, false, String(state));
  27554. } catch (ex) {
  27555. }
  27556. };
  27557. var setContentEditable = function(elm, state) {
  27558. elm.dom.contentEditable = state ? "true" : "false";
  27559. };
  27560. var switchOffContentEditableTrue = function(elm) {
  27561. each$k(descendants(elm, '*[contenteditable="true"]'), function(elm2) {
  27562. set$1(elm2, internalContentEditableAttr, "true");
  27563. setContentEditable(elm2, false);
  27564. });
  27565. };
  27566. var switchOnContentEditableTrue = function(elm) {
  27567. each$k(descendants(elm, "*[" + internalContentEditableAttr + '="true"]'), function(elm2) {
  27568. remove$6(elm2, internalContentEditableAttr);
  27569. setContentEditable(elm2, true);
  27570. });
  27571. };
  27572. var removeFakeSelection = function(editor) {
  27573. Optional.from(editor.selection.getNode()).each(function(elm) {
  27574. elm.removeAttribute("data-mce-selected");
  27575. });
  27576. };
  27577. var restoreFakeSelection = function(editor) {
  27578. editor.selection.setRng(editor.selection.getRng());
  27579. };
  27580. var toggleReadOnly = function(editor, state) {
  27581. var body = SugarElement.fromDom(editor.getBody());
  27582. toggleClass(body, "mce-content-readonly", state);
  27583. if (state) {
  27584. editor.selection.controlSelection.hideResizeRect();
  27585. editor._selectionOverrides.hideFakeCaret();
  27586. removeFakeSelection(editor);
  27587. editor.readonly = true;
  27588. setContentEditable(body, false);
  27589. switchOffContentEditableTrue(body);
  27590. } else {
  27591. editor.readonly = false;
  27592. setContentEditable(body, true);
  27593. switchOnContentEditableTrue(body);
  27594. setEditorCommandState(editor, "StyleWithCSS", false);
  27595. setEditorCommandState(editor, "enableInlineTableEditing", false);
  27596. setEditorCommandState(editor, "enableObjectResizing", false);
  27597. if (hasEditorOrUiFocus(editor)) {
  27598. editor.focus();
  27599. }
  27600. restoreFakeSelection(editor);
  27601. editor.nodeChanged();
  27602. }
  27603. };
  27604. var isReadOnly = function(editor) {
  27605. return editor.readonly;
  27606. };
  27607. var registerFilters = function(editor) {
  27608. editor.parser.addAttributeFilter("contenteditable", function(nodes) {
  27609. if (isReadOnly(editor)) {
  27610. each$k(nodes, function(node) {
  27611. node.attr(internalContentEditableAttr, node.attr("contenteditable"));
  27612. node.attr("contenteditable", "false");
  27613. });
  27614. }
  27615. });
  27616. editor.serializer.addAttributeFilter(internalContentEditableAttr, function(nodes) {
  27617. if (isReadOnly(editor)) {
  27618. each$k(nodes, function(node) {
  27619. node.attr("contenteditable", node.attr(internalContentEditableAttr));
  27620. });
  27621. }
  27622. });
  27623. editor.serializer.addTempAttr(internalContentEditableAttr);
  27624. };
  27625. var registerReadOnlyContentFilters = function(editor) {
  27626. if (editor.serializer) {
  27627. registerFilters(editor);
  27628. } else {
  27629. editor.on("PreInit", function() {
  27630. registerFilters(editor);
  27631. });
  27632. }
  27633. };
  27634. var isClickEvent = function(e) {
  27635. return e.type === "click";
  27636. };
  27637. var getAnchorHrefOpt = function(editor, elm) {
  27638. var isRoot = function(elm2) {
  27639. return eq(elm2, SugarElement.fromDom(editor.getBody()));
  27640. };
  27641. return closest$2(elm, "a", isRoot).bind(function(a) {
  27642. return getOpt(a, "href");
  27643. });
  27644. };
  27645. var processReadonlyEvents = function(editor, e) {
  27646. if (isClickEvent(e) && !VK.metaKeyPressed(e)) {
  27647. var elm = SugarElement.fromDom(e.target);
  27648. getAnchorHrefOpt(editor, elm).each(function(href) {
  27649. e.preventDefault();
  27650. if (/^#/.test(href)) {
  27651. var targetEl = editor.dom.select(href + ',[name="' + removeLeading(href, "#") + '"]');
  27652. if (targetEl.length) {
  27653. editor.selection.scrollIntoView(targetEl[0], true);
  27654. }
  27655. } else {
  27656. window.open(href, "_blank", "rel=noopener noreferrer,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes");
  27657. }
  27658. });
  27659. }
  27660. };
  27661. var registerReadOnlySelectionBlockers = function(editor) {
  27662. editor.on("ShowCaret", function(e) {
  27663. if (isReadOnly(editor)) {
  27664. e.preventDefault();
  27665. }
  27666. });
  27667. editor.on("ObjectSelected", function(e) {
  27668. if (isReadOnly(editor)) {
  27669. e.preventDefault();
  27670. }
  27671. });
  27672. };
  27673. 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", " ");
  27674. var EventDispatcher = function() {
  27675. function EventDispatcher2(settings) {
  27676. this.bindings = {};
  27677. this.settings = settings || {};
  27678. this.scope = this.settings.scope || this;
  27679. this.toggleEvent = this.settings.toggleEvent || never;
  27680. }
  27681. EventDispatcher2.isNative = function(name2) {
  27682. return !!nativeEvents[name2.toLowerCase()];
  27683. };
  27684. EventDispatcher2.prototype.fire = function(name2, args) {
  27685. var lcName = name2.toLowerCase();
  27686. var event = normalize$3(lcName, args || {}, this.scope);
  27687. if (this.settings.beforeFire) {
  27688. this.settings.beforeFire(event);
  27689. }
  27690. var handlers = this.bindings[lcName];
  27691. if (handlers) {
  27692. for (var i = 0, l = handlers.length; i < l; i++) {
  27693. var callback = handlers[i];
  27694. if (callback.removed) {
  27695. continue;
  27696. }
  27697. if (callback.once) {
  27698. this.off(lcName, callback.func);
  27699. }
  27700. if (event.isImmediatePropagationStopped()) {
  27701. return event;
  27702. }
  27703. if (callback.func.call(this.scope, event) === false) {
  27704. event.preventDefault();
  27705. return event;
  27706. }
  27707. }
  27708. }
  27709. return event;
  27710. };
  27711. EventDispatcher2.prototype.on = function(name2, callback, prepend2, extra2) {
  27712. if (callback === false) {
  27713. callback = never;
  27714. }
  27715. if (callback) {
  27716. var wrappedCallback = {
  27717. func: callback,
  27718. removed: false
  27719. };
  27720. if (extra2) {
  27721. Tools.extend(wrappedCallback, extra2);
  27722. }
  27723. var names = name2.toLowerCase().split(" ");
  27724. var i = names.length;
  27725. while (i--) {
  27726. var currentName = names[i];
  27727. var handlers = this.bindings[currentName];
  27728. if (!handlers) {
  27729. handlers = [];
  27730. this.toggleEvent(currentName, true);
  27731. }
  27732. if (prepend2) {
  27733. handlers = __spreadArray([wrappedCallback], handlers, true);
  27734. } else {
  27735. handlers = __spreadArray(__spreadArray([], handlers, true), [wrappedCallback], false);
  27736. }
  27737. this.bindings[currentName] = handlers;
  27738. }
  27739. }
  27740. return this;
  27741. };
  27742. EventDispatcher2.prototype.off = function(name2, callback) {
  27743. var _this = this;
  27744. if (name2) {
  27745. var names = name2.toLowerCase().split(" ");
  27746. var i = names.length;
  27747. while (i--) {
  27748. var currentName = names[i];
  27749. var handlers = this.bindings[currentName];
  27750. if (!currentName) {
  27751. each$j(this.bindings, function(_value, bindingName) {
  27752. _this.toggleEvent(bindingName, false);
  27753. delete _this.bindings[bindingName];
  27754. });
  27755. return this;
  27756. }
  27757. if (handlers) {
  27758. if (!callback) {
  27759. handlers.length = 0;
  27760. } else {
  27761. var filteredHandlers = partition(handlers, function(handler) {
  27762. return handler.func === callback;
  27763. });
  27764. handlers = filteredHandlers.fail;
  27765. this.bindings[currentName] = handlers;
  27766. each$k(filteredHandlers.pass, function(handler) {
  27767. handler.removed = true;
  27768. });
  27769. }
  27770. if (!handlers.length) {
  27771. this.toggleEvent(name2, false);
  27772. delete this.bindings[currentName];
  27773. }
  27774. }
  27775. }
  27776. } else {
  27777. each$j(this.bindings, function(_value, name3) {
  27778. _this.toggleEvent(name3, false);
  27779. });
  27780. this.bindings = {};
  27781. }
  27782. return this;
  27783. };
  27784. EventDispatcher2.prototype.once = function(name2, callback, prepend2) {
  27785. return this.on(name2, callback, prepend2, { once: true });
  27786. };
  27787. EventDispatcher2.prototype.has = function(name2) {
  27788. name2 = name2.toLowerCase();
  27789. return !(!this.bindings[name2] || this.bindings[name2].length === 0);
  27790. };
  27791. return EventDispatcher2;
  27792. }();
  27793. var getEventDispatcher = function(obj) {
  27794. if (!obj._eventDispatcher) {
  27795. obj._eventDispatcher = new EventDispatcher({
  27796. scope: obj,
  27797. toggleEvent: function(name2, state) {
  27798. if (EventDispatcher.isNative(name2) && obj.toggleNativeEvent) {
  27799. obj.toggleNativeEvent(name2, state);
  27800. }
  27801. }
  27802. });
  27803. }
  27804. return obj._eventDispatcher;
  27805. };
  27806. var Observable = {
  27807. fire: function(name2, args, bubble) {
  27808. var self2 = this;
  27809. if (self2.removed && name2 !== "remove" && name2 !== "detach") {
  27810. return args;
  27811. }
  27812. var dispatcherArgs = getEventDispatcher(self2).fire(name2, args);
  27813. if (bubble !== false && self2.parent) {
  27814. var parent_1 = self2.parent();
  27815. while (parent_1 && !dispatcherArgs.isPropagationStopped()) {
  27816. parent_1.fire(name2, dispatcherArgs, false);
  27817. parent_1 = parent_1.parent();
  27818. }
  27819. }
  27820. return dispatcherArgs;
  27821. },
  27822. on: function(name2, callback, prepend2) {
  27823. return getEventDispatcher(this).on(name2, callback, prepend2);
  27824. },
  27825. off: function(name2, callback) {
  27826. return getEventDispatcher(this).off(name2, callback);
  27827. },
  27828. once: function(name2, callback) {
  27829. return getEventDispatcher(this).once(name2, callback);
  27830. },
  27831. hasEventListeners: function(name2) {
  27832. return getEventDispatcher(this).has(name2);
  27833. }
  27834. };
  27835. var DOM$2 = DOMUtils.DOM;
  27836. var customEventRootDelegates;
  27837. var getEventTarget = function(editor, eventName) {
  27838. if (eventName === "selectionchange") {
  27839. return editor.getDoc();
  27840. }
  27841. if (!editor.inline && /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)) {
  27842. return editor.getDoc().documentElement;
  27843. }
  27844. var eventRoot = getEventRoot(editor);
  27845. if (eventRoot) {
  27846. if (!editor.eventRoot) {
  27847. editor.eventRoot = DOM$2.select(eventRoot)[0];
  27848. }
  27849. return editor.eventRoot;
  27850. }
  27851. return editor.getBody();
  27852. };
  27853. var isListening = function(editor) {
  27854. return !editor.hidden && !isReadOnly(editor);
  27855. };
  27856. var fireEvent = function(editor, eventName, e) {
  27857. if (isListening(editor)) {
  27858. editor.fire(eventName, e);
  27859. } else if (isReadOnly(editor)) {
  27860. processReadonlyEvents(editor, e);
  27861. }
  27862. };
  27863. var bindEventDelegate = function(editor, eventName) {
  27864. var delegate;
  27865. if (!editor.delegates) {
  27866. editor.delegates = {};
  27867. }
  27868. if (editor.delegates[eventName] || editor.removed) {
  27869. return;
  27870. }
  27871. var eventRootElm = getEventTarget(editor, eventName);
  27872. if (getEventRoot(editor)) {
  27873. if (!customEventRootDelegates) {
  27874. customEventRootDelegates = {};
  27875. editor.editorManager.on("removeEditor", function() {
  27876. if (!editor.editorManager.activeEditor) {
  27877. if (customEventRootDelegates) {
  27878. each$j(customEventRootDelegates, function(_value, name2) {
  27879. editor.dom.unbind(getEventTarget(editor, name2));
  27880. });
  27881. customEventRootDelegates = null;
  27882. }
  27883. }
  27884. });
  27885. }
  27886. if (customEventRootDelegates[eventName]) {
  27887. return;
  27888. }
  27889. delegate = function(e) {
  27890. var target = e.target;
  27891. var editors2 = editor.editorManager.get();
  27892. var i = editors2.length;
  27893. while (i--) {
  27894. var body = editors2[i].getBody();
  27895. if (body === target || DOM$2.isChildOf(target, body)) {
  27896. fireEvent(editors2[i], eventName, e);
  27897. }
  27898. }
  27899. };
  27900. customEventRootDelegates[eventName] = delegate;
  27901. DOM$2.bind(eventRootElm, eventName, delegate);
  27902. } else {
  27903. delegate = function(e) {
  27904. fireEvent(editor, eventName, e);
  27905. };
  27906. DOM$2.bind(eventRootElm, eventName, delegate);
  27907. editor.delegates[eventName] = delegate;
  27908. }
  27909. };
  27910. var EditorObservable = __assign(__assign({}, Observable), {
  27911. bindPendingEventDelegates: function() {
  27912. var self2 = this;
  27913. Tools.each(self2._pendingNativeEvents, function(name2) {
  27914. bindEventDelegate(self2, name2);
  27915. });
  27916. },
  27917. toggleNativeEvent: function(name2, state) {
  27918. var self2 = this;
  27919. if (name2 === "focus" || name2 === "blur") {
  27920. return;
  27921. }
  27922. if (self2.removed) {
  27923. return;
  27924. }
  27925. if (state) {
  27926. if (self2.initialized) {
  27927. bindEventDelegate(self2, name2);
  27928. } else {
  27929. if (!self2._pendingNativeEvents) {
  27930. self2._pendingNativeEvents = [name2];
  27931. } else {
  27932. self2._pendingNativeEvents.push(name2);
  27933. }
  27934. }
  27935. } else if (self2.initialized) {
  27936. self2.dom.unbind(getEventTarget(self2, name2), name2, self2.delegates[name2]);
  27937. delete self2.delegates[name2];
  27938. }
  27939. },
  27940. unbindAllNativeEvents: function() {
  27941. var self2 = this;
  27942. var body = self2.getBody();
  27943. var dom2 = self2.dom;
  27944. if (self2.delegates) {
  27945. each$j(self2.delegates, function(value2, name2) {
  27946. self2.dom.unbind(getEventTarget(self2, name2), name2, value2);
  27947. });
  27948. delete self2.delegates;
  27949. }
  27950. if (!self2.inline && body && dom2) {
  27951. body.onload = null;
  27952. dom2.unbind(self2.getWin());
  27953. dom2.unbind(self2.getDoc());
  27954. }
  27955. if (dom2) {
  27956. dom2.unbind(body);
  27957. dom2.unbind(self2.getContainer());
  27958. }
  27959. }
  27960. });
  27961. var defaultModes = [
  27962. "design",
  27963. "readonly"
  27964. ];
  27965. var switchToMode = function(editor, activeMode, availableModes, mode) {
  27966. var oldMode = availableModes[activeMode.get()];
  27967. var newMode = availableModes[mode];
  27968. try {
  27969. newMode.activate();
  27970. } catch (e) {
  27971. console.error("problem while activating editor mode " + mode + ":", e);
  27972. return;
  27973. }
  27974. oldMode.deactivate();
  27975. if (oldMode.editorReadOnly !== newMode.editorReadOnly) {
  27976. toggleReadOnly(editor, newMode.editorReadOnly);
  27977. }
  27978. activeMode.set(mode);
  27979. fireSwitchMode(editor, mode);
  27980. };
  27981. var setMode = function(editor, availableModes, activeMode, mode) {
  27982. if (mode === activeMode.get()) {
  27983. return;
  27984. } else if (!has$2(availableModes, mode)) {
  27985. throw new Error("Editor mode '" + mode + "' is invalid");
  27986. }
  27987. if (editor.initialized) {
  27988. switchToMode(editor, activeMode, availableModes, mode);
  27989. } else {
  27990. editor.on("init", function() {
  27991. return switchToMode(editor, activeMode, availableModes, mode);
  27992. });
  27993. }
  27994. };
  27995. var registerMode = function(availableModes, mode, api2) {
  27996. var _a;
  27997. if (contains$3(defaultModes, mode)) {
  27998. throw new Error("Cannot override default mode " + mode);
  27999. }
  28000. return __assign(__assign({}, availableModes), (_a = {}, _a[mode] = __assign(__assign({}, api2), {
  28001. deactivate: function() {
  28002. try {
  28003. api2.deactivate();
  28004. } catch (e) {
  28005. console.error("problem while deactivating editor mode " + mode + ":", e);
  28006. }
  28007. }
  28008. }), _a));
  28009. };
  28010. var create$4 = function(editor) {
  28011. var activeMode = Cell("design");
  28012. var availableModes = Cell({
  28013. design: {
  28014. activate: noop,
  28015. deactivate: noop,
  28016. editorReadOnly: false
  28017. },
  28018. readonly: {
  28019. activate: noop,
  28020. deactivate: noop,
  28021. editorReadOnly: true
  28022. }
  28023. });
  28024. registerReadOnlyContentFilters(editor);
  28025. registerReadOnlySelectionBlockers(editor);
  28026. return {
  28027. isReadOnly: function() {
  28028. return isReadOnly(editor);
  28029. },
  28030. set: function(mode) {
  28031. return setMode(editor, availableModes.get(), activeMode, mode);
  28032. },
  28033. get: function() {
  28034. return activeMode.get();
  28035. },
  28036. register: function(mode, api2) {
  28037. availableModes.set(registerMode(availableModes.get(), mode, api2));
  28038. }
  28039. };
  28040. };
  28041. var each$3 = Tools.each, explode$1 = Tools.explode;
  28042. var keyCodeLookup = {
  28043. f1: 112,
  28044. f2: 113,
  28045. f3: 114,
  28046. f4: 115,
  28047. f5: 116,
  28048. f6: 117,
  28049. f7: 118,
  28050. f8: 119,
  28051. f9: 120,
  28052. f10: 121,
  28053. f11: 122,
  28054. f12: 123
  28055. };
  28056. var modifierNames = Tools.makeMap("alt,ctrl,shift,meta,access");
  28057. var parseShortcut = function(pattern) {
  28058. var key;
  28059. var shortcut = {};
  28060. each$3(explode$1(pattern.toLowerCase(), "+"), function(value2) {
  28061. if (value2 in modifierNames) {
  28062. shortcut[value2] = true;
  28063. } else {
  28064. if (/^[0-9]{2,}$/.test(value2)) {
  28065. shortcut.keyCode = parseInt(value2, 10);
  28066. } else {
  28067. shortcut.charCode = value2.charCodeAt(0);
  28068. shortcut.keyCode = keyCodeLookup[value2] || value2.toUpperCase().charCodeAt(0);
  28069. }
  28070. }
  28071. });
  28072. var id = [shortcut.keyCode];
  28073. for (key in modifierNames) {
  28074. if (shortcut[key]) {
  28075. id.push(key);
  28076. } else {
  28077. shortcut[key] = false;
  28078. }
  28079. }
  28080. shortcut.id = id.join(",");
  28081. if (shortcut.access) {
  28082. shortcut.alt = true;
  28083. if (Env.mac) {
  28084. shortcut.ctrl = true;
  28085. } else {
  28086. shortcut.shift = true;
  28087. }
  28088. }
  28089. if (shortcut.meta) {
  28090. if (Env.mac) {
  28091. shortcut.meta = true;
  28092. } else {
  28093. shortcut.ctrl = true;
  28094. shortcut.meta = false;
  28095. }
  28096. }
  28097. return shortcut;
  28098. };
  28099. var Shortcuts = function() {
  28100. function Shortcuts2(editor) {
  28101. this.shortcuts = {};
  28102. this.pendingPatterns = [];
  28103. this.editor = editor;
  28104. var self2 = this;
  28105. editor.on("keyup keypress keydown", function(e) {
  28106. if ((self2.hasModifier(e) || self2.isFunctionKey(e)) && !e.isDefaultPrevented()) {
  28107. each$3(self2.shortcuts, function(shortcut) {
  28108. if (self2.matchShortcut(e, shortcut)) {
  28109. self2.pendingPatterns = shortcut.subpatterns.slice(0);
  28110. if (e.type === "keydown") {
  28111. self2.executeShortcutAction(shortcut);
  28112. }
  28113. return true;
  28114. }
  28115. });
  28116. if (self2.matchShortcut(e, self2.pendingPatterns[0])) {
  28117. if (self2.pendingPatterns.length === 1) {
  28118. if (e.type === "keydown") {
  28119. self2.executeShortcutAction(self2.pendingPatterns[0]);
  28120. }
  28121. }
  28122. self2.pendingPatterns.shift();
  28123. }
  28124. }
  28125. });
  28126. }
  28127. Shortcuts2.prototype.add = function(pattern, desc, cmdFunc, scope) {
  28128. var self2 = this;
  28129. var func = self2.normalizeCommandFunc(cmdFunc);
  28130. each$3(explode$1(Tools.trim(pattern)), function(pattern2) {
  28131. var shortcut = self2.createShortcut(pattern2, desc, func, scope);
  28132. self2.shortcuts[shortcut.id] = shortcut;
  28133. });
  28134. return true;
  28135. };
  28136. Shortcuts2.prototype.remove = function(pattern) {
  28137. var shortcut = this.createShortcut(pattern);
  28138. if (this.shortcuts[shortcut.id]) {
  28139. delete this.shortcuts[shortcut.id];
  28140. return true;
  28141. }
  28142. return false;
  28143. };
  28144. Shortcuts2.prototype.normalizeCommandFunc = function(cmdFunc) {
  28145. var self2 = this;
  28146. var cmd = cmdFunc;
  28147. if (typeof cmd === "string") {
  28148. return function() {
  28149. self2.editor.execCommand(cmd, false, null);
  28150. };
  28151. } else if (Tools.isArray(cmd)) {
  28152. return function() {
  28153. self2.editor.execCommand(cmd[0], cmd[1], cmd[2]);
  28154. };
  28155. } else {
  28156. return cmd;
  28157. }
  28158. };
  28159. Shortcuts2.prototype.createShortcut = function(pattern, desc, cmdFunc, scope) {
  28160. var shortcuts = Tools.map(explode$1(pattern, ">"), parseShortcut);
  28161. shortcuts[shortcuts.length - 1] = Tools.extend(shortcuts[shortcuts.length - 1], {
  28162. func: cmdFunc,
  28163. scope: scope || this.editor
  28164. });
  28165. return Tools.extend(shortcuts[0], {
  28166. desc: this.editor.translate(desc),
  28167. subpatterns: shortcuts.slice(1)
  28168. });
  28169. };
  28170. Shortcuts2.prototype.hasModifier = function(e) {
  28171. return e.altKey || e.ctrlKey || e.metaKey;
  28172. };
  28173. Shortcuts2.prototype.isFunctionKey = function(e) {
  28174. return e.type === "keydown" && e.keyCode >= 112 && e.keyCode <= 123;
  28175. };
  28176. Shortcuts2.prototype.matchShortcut = function(e, shortcut) {
  28177. if (!shortcut) {
  28178. return false;
  28179. }
  28180. if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) {
  28181. return false;
  28182. }
  28183. if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) {
  28184. return false;
  28185. }
  28186. if (e.keyCode === shortcut.keyCode || e.charCode && e.charCode === shortcut.charCode) {
  28187. e.preventDefault();
  28188. return true;
  28189. }
  28190. return false;
  28191. };
  28192. Shortcuts2.prototype.executeShortcutAction = function(shortcut) {
  28193. return shortcut.func ? shortcut.func.call(shortcut.scope) : null;
  28194. };
  28195. return Shortcuts2;
  28196. }();
  28197. var create$3 = function() {
  28198. var buttons = {};
  28199. var menuItems = {};
  28200. var popups = {};
  28201. var icons = {};
  28202. var contextMenus = {};
  28203. var contextToolbars = {};
  28204. var sidebars = {};
  28205. var add2 = function(collection, type2) {
  28206. return function(name2, spec) {
  28207. return collection[name2.toLowerCase()] = __assign(__assign({}, spec), { type: type2 });
  28208. };
  28209. };
  28210. var addIcon = function(name2, svgData) {
  28211. return icons[name2.toLowerCase()] = svgData;
  28212. };
  28213. return {
  28214. addButton: add2(buttons, "button"),
  28215. addGroupToolbarButton: add2(buttons, "grouptoolbarbutton"),
  28216. addToggleButton: add2(buttons, "togglebutton"),
  28217. addMenuButton: add2(buttons, "menubutton"),
  28218. addSplitButton: add2(buttons, "splitbutton"),
  28219. addMenuItem: add2(menuItems, "menuitem"),
  28220. addNestedMenuItem: add2(menuItems, "nestedmenuitem"),
  28221. addToggleMenuItem: add2(menuItems, "togglemenuitem"),
  28222. addAutocompleter: add2(popups, "autocompleter"),
  28223. addContextMenu: add2(contextMenus, "contextmenu"),
  28224. addContextToolbar: add2(contextToolbars, "contexttoolbar"),
  28225. addContextForm: add2(contextToolbars, "contextform"),
  28226. addSidebar: add2(sidebars, "sidebar"),
  28227. addIcon,
  28228. getAll: function() {
  28229. return {
  28230. buttons,
  28231. menuItems,
  28232. icons,
  28233. popups,
  28234. contextMenus,
  28235. contextToolbars,
  28236. sidebars
  28237. };
  28238. }
  28239. };
  28240. };
  28241. var registry = function() {
  28242. var bridge = create$3();
  28243. return {
  28244. addAutocompleter: bridge.addAutocompleter,
  28245. addButton: bridge.addButton,
  28246. addContextForm: bridge.addContextForm,
  28247. addContextMenu: bridge.addContextMenu,
  28248. addContextToolbar: bridge.addContextToolbar,
  28249. addIcon: bridge.addIcon,
  28250. addMenuButton: bridge.addMenuButton,
  28251. addMenuItem: bridge.addMenuItem,
  28252. addNestedMenuItem: bridge.addNestedMenuItem,
  28253. addSidebar: bridge.addSidebar,
  28254. addSplitButton: bridge.addSplitButton,
  28255. addToggleButton: bridge.addToggleButton,
  28256. addGroupToolbarButton: bridge.addGroupToolbarButton,
  28257. addToggleMenuItem: bridge.addToggleMenuItem,
  28258. getAll: bridge.getAll
  28259. };
  28260. };
  28261. var DOM$1 = DOMUtils.DOM;
  28262. var extend$3 = Tools.extend, each$2 = Tools.each;
  28263. var resolve = Tools.resolve;
  28264. var ie = Env.ie;
  28265. var Editor = function() {
  28266. function Editor2(id, settings, editorManager) {
  28267. var _this = this;
  28268. this.plugins = {};
  28269. this.contentCSS = [];
  28270. this.contentStyles = [];
  28271. this.loadedCSS = {};
  28272. this.isNotDirty = false;
  28273. this.editorManager = editorManager;
  28274. this.documentBaseUrl = editorManager.documentBaseURL;
  28275. extend$3(this, EditorObservable);
  28276. this.settings = getEditorSettings(this, id, this.documentBaseUrl, editorManager.defaultSettings, settings);
  28277. if (this.settings.suffix) {
  28278. editorManager.suffix = this.settings.suffix;
  28279. }
  28280. this.suffix = editorManager.suffix;
  28281. if (this.settings.base_url) {
  28282. editorManager._setBaseUrl(this.settings.base_url);
  28283. }
  28284. this.baseUri = editorManager.baseURI;
  28285. if (this.settings.referrer_policy) {
  28286. ScriptLoader.ScriptLoader._setReferrerPolicy(this.settings.referrer_policy);
  28287. DOMUtils.DOM.styleSheetLoader._setReferrerPolicy(this.settings.referrer_policy);
  28288. }
  28289. AddOnManager.languageLoad = this.settings.language_load;
  28290. AddOnManager.baseURL = editorManager.baseURL;
  28291. this.id = id;
  28292. this.setDirty(false);
  28293. this.documentBaseURI = new URI(this.settings.document_base_url, { base_uri: this.baseUri });
  28294. this.baseURI = this.baseUri;
  28295. this.inline = !!this.settings.inline;
  28296. this.shortcuts = new Shortcuts(this);
  28297. this.editorCommands = new EditorCommands(this);
  28298. if (this.settings.cache_suffix) {
  28299. Env.cacheSuffix = this.settings.cache_suffix.replace(/^[\?\&]+/, "");
  28300. }
  28301. this.ui = {
  28302. registry: registry(),
  28303. styleSheetLoader: void 0,
  28304. show: noop,
  28305. hide: noop,
  28306. enable: noop,
  28307. disable: noop,
  28308. isDisabled: never
  28309. };
  28310. var self2 = this;
  28311. var modeInstance = create$4(self2);
  28312. this.mode = modeInstance;
  28313. this.setMode = modeInstance.set;
  28314. editorManager.fire("SetupEditor", { editor: this });
  28315. this.execCallback("setup", this);
  28316. this.$ = DomQuery.overrideDefaults(function() {
  28317. return {
  28318. context: _this.inline ? _this.getBody() : _this.getDoc(),
  28319. element: _this.getBody()
  28320. };
  28321. });
  28322. }
  28323. Editor2.prototype.render = function() {
  28324. render(this);
  28325. };
  28326. Editor2.prototype.focus = function(skipFocus) {
  28327. this.execCommand("mceFocus", false, skipFocus);
  28328. };
  28329. Editor2.prototype.hasFocus = function() {
  28330. return hasFocus(this);
  28331. };
  28332. Editor2.prototype.execCallback = function(name2) {
  28333. var x = [];
  28334. for (var _i = 1; _i < arguments.length; _i++) {
  28335. x[_i - 1] = arguments[_i];
  28336. }
  28337. var self2 = this;
  28338. var callback = self2.settings[name2], scope;
  28339. if (!callback) {
  28340. return;
  28341. }
  28342. if (self2.callbackLookup && (scope = self2.callbackLookup[name2])) {
  28343. callback = scope.func;
  28344. scope = scope.scope;
  28345. }
  28346. if (typeof callback === "string") {
  28347. scope = callback.replace(/\.\w+$/, "");
  28348. scope = scope ? resolve(scope) : 0;
  28349. callback = resolve(callback);
  28350. self2.callbackLookup = self2.callbackLookup || {};
  28351. self2.callbackLookup[name2] = {
  28352. func: callback,
  28353. scope
  28354. };
  28355. }
  28356. return callback.apply(scope || self2, x);
  28357. };
  28358. Editor2.prototype.translate = function(text) {
  28359. return I18n.translate(text);
  28360. };
  28361. Editor2.prototype.getParam = function(name2, defaultVal, type2) {
  28362. return getParam(this, name2, defaultVal, type2);
  28363. };
  28364. Editor2.prototype.hasPlugin = function(name2, loaded) {
  28365. var hasPlugin = contains$3(getPlugins(this).split(/[ ,]/), name2);
  28366. if (hasPlugin) {
  28367. return loaded ? PluginManager.get(name2) !== void 0 : true;
  28368. } else {
  28369. return false;
  28370. }
  28371. };
  28372. Editor2.prototype.nodeChanged = function(args) {
  28373. this._nodeChangeDispatcher.nodeChanged(args);
  28374. };
  28375. Editor2.prototype.addCommand = function(name2, callback, scope) {
  28376. this.editorCommands.addCommand(name2, callback, scope);
  28377. };
  28378. Editor2.prototype.addQueryStateHandler = function(name2, callback, scope) {
  28379. this.editorCommands.addQueryStateHandler(name2, callback, scope);
  28380. };
  28381. Editor2.prototype.addQueryValueHandler = function(name2, callback, scope) {
  28382. this.editorCommands.addQueryValueHandler(name2, callback, scope);
  28383. };
  28384. Editor2.prototype.addShortcut = function(pattern, desc, cmdFunc, scope) {
  28385. this.shortcuts.add(pattern, desc, cmdFunc, scope);
  28386. };
  28387. Editor2.prototype.execCommand = function(cmd, ui, value2, args) {
  28388. return this.editorCommands.execCommand(cmd, ui, value2, args);
  28389. };
  28390. Editor2.prototype.queryCommandState = function(cmd) {
  28391. return this.editorCommands.queryCommandState(cmd);
  28392. };
  28393. Editor2.prototype.queryCommandValue = function(cmd) {
  28394. return this.editorCommands.queryCommandValue(cmd);
  28395. };
  28396. Editor2.prototype.queryCommandSupported = function(cmd) {
  28397. return this.editorCommands.queryCommandSupported(cmd);
  28398. };
  28399. Editor2.prototype.show = function() {
  28400. var self2 = this;
  28401. if (self2.hidden) {
  28402. self2.hidden = false;
  28403. if (self2.inline) {
  28404. self2.getBody().contentEditable = "true";
  28405. } else {
  28406. DOM$1.show(self2.getContainer());
  28407. DOM$1.hide(self2.id);
  28408. }
  28409. self2.load();
  28410. self2.fire("show");
  28411. }
  28412. };
  28413. Editor2.prototype.hide = function() {
  28414. var self2 = this, doc2 = self2.getDoc();
  28415. if (!self2.hidden) {
  28416. if (ie && doc2 && !self2.inline) {
  28417. doc2.execCommand("SelectAll");
  28418. }
  28419. self2.save();
  28420. if (self2.inline) {
  28421. self2.getBody().contentEditable = "false";
  28422. if (self2 === self2.editorManager.focusedEditor) {
  28423. self2.editorManager.focusedEditor = null;
  28424. }
  28425. } else {
  28426. DOM$1.hide(self2.getContainer());
  28427. DOM$1.setStyle(self2.id, "display", self2.orgDisplay);
  28428. }
  28429. self2.hidden = true;
  28430. self2.fire("hide");
  28431. }
  28432. };
  28433. Editor2.prototype.isHidden = function() {
  28434. return !!this.hidden;
  28435. };
  28436. Editor2.prototype.setProgressState = function(state, time) {
  28437. this.fire("ProgressState", {
  28438. state,
  28439. time
  28440. });
  28441. };
  28442. Editor2.prototype.load = function(args) {
  28443. var self2 = this;
  28444. var elm = self2.getElement(), html;
  28445. if (self2.removed) {
  28446. return "";
  28447. }
  28448. if (elm) {
  28449. args = args || {};
  28450. args.load = true;
  28451. var value2 = isTextareaOrInput(elm) ? elm.value : elm.innerHTML;
  28452. html = self2.setContent(value2, args);
  28453. args.element = elm;
  28454. if (!args.no_events) {
  28455. self2.fire("LoadContent", args);
  28456. }
  28457. args.element = elm = null;
  28458. return html;
  28459. }
  28460. };
  28461. Editor2.prototype.save = function(args) {
  28462. var self2 = this;
  28463. var elm = self2.getElement(), html, form;
  28464. if (!elm || !self2.initialized || self2.removed) {
  28465. return;
  28466. }
  28467. args = args || {};
  28468. args.save = true;
  28469. args.element = elm;
  28470. html = args.content = self2.getContent(args);
  28471. if (!args.no_events) {
  28472. self2.fire("SaveContent", args);
  28473. }
  28474. if (args.format === "raw") {
  28475. self2.fire("RawSaveContent", args);
  28476. }
  28477. html = args.content;
  28478. if (!isTextareaOrInput(elm)) {
  28479. if (args.is_removing || !self2.inline) {
  28480. elm.innerHTML = html;
  28481. }
  28482. if (form = DOM$1.getParent(self2.id, "form")) {
  28483. each$2(form.elements, function(elm2) {
  28484. if (elm2.name === self2.id) {
  28485. elm2.value = html;
  28486. return false;
  28487. }
  28488. });
  28489. }
  28490. } else {
  28491. elm.value = html;
  28492. }
  28493. args.element = elm = null;
  28494. if (args.set_dirty !== false) {
  28495. self2.setDirty(false);
  28496. }
  28497. return html;
  28498. };
  28499. Editor2.prototype.setContent = function(content, args) {
  28500. return setContent(this, content, args);
  28501. };
  28502. Editor2.prototype.getContent = function(args) {
  28503. return getContent(this, args);
  28504. };
  28505. Editor2.prototype.insertContent = function(content, args) {
  28506. if (args) {
  28507. content = extend$3({ content }, args);
  28508. }
  28509. this.execCommand("mceInsertContent", false, content);
  28510. };
  28511. Editor2.prototype.resetContent = function(initialContent) {
  28512. if (initialContent === void 0) {
  28513. setContent(this, this.startContent, { format: "raw" });
  28514. } else {
  28515. setContent(this, initialContent);
  28516. }
  28517. this.undoManager.reset();
  28518. this.setDirty(false);
  28519. this.nodeChanged();
  28520. };
  28521. Editor2.prototype.isDirty = function() {
  28522. return !this.isNotDirty;
  28523. };
  28524. Editor2.prototype.setDirty = function(state) {
  28525. var oldState = !this.isNotDirty;
  28526. this.isNotDirty = !state;
  28527. if (state && state !== oldState) {
  28528. this.fire("dirty");
  28529. }
  28530. };
  28531. Editor2.prototype.getContainer = function() {
  28532. var self2 = this;
  28533. if (!self2.container) {
  28534. self2.container = DOM$1.get(self2.editorContainer || self2.id + "_parent");
  28535. }
  28536. return self2.container;
  28537. };
  28538. Editor2.prototype.getContentAreaContainer = function() {
  28539. return this.contentAreaContainer;
  28540. };
  28541. Editor2.prototype.getElement = function() {
  28542. if (!this.targetElm) {
  28543. this.targetElm = DOM$1.get(this.id);
  28544. }
  28545. return this.targetElm;
  28546. };
  28547. Editor2.prototype.getWin = function() {
  28548. var self2 = this;
  28549. var elm;
  28550. if (!self2.contentWindow) {
  28551. elm = self2.iframeElement;
  28552. if (elm) {
  28553. self2.contentWindow = elm.contentWindow;
  28554. }
  28555. }
  28556. return self2.contentWindow;
  28557. };
  28558. Editor2.prototype.getDoc = function() {
  28559. var self2 = this;
  28560. var win;
  28561. if (!self2.contentDocument) {
  28562. win = self2.getWin();
  28563. if (win) {
  28564. self2.contentDocument = win.document;
  28565. }
  28566. }
  28567. return self2.contentDocument;
  28568. };
  28569. Editor2.prototype.getBody = function() {
  28570. var doc2 = this.getDoc();
  28571. return this.bodyElement || (doc2 ? doc2.body : null);
  28572. };
  28573. Editor2.prototype.convertURL = function(url, name2, elm) {
  28574. var self2 = this, settings = self2.settings;
  28575. if (settings.urlconverter_callback) {
  28576. return self2.execCallback("urlconverter_callback", url, elm, true, name2);
  28577. }
  28578. if (!settings.convert_urls || elm && elm.nodeName === "LINK" || url.indexOf("file:") === 0 || url.length === 0) {
  28579. return url;
  28580. }
  28581. if (settings.relative_urls) {
  28582. return self2.documentBaseURI.toRelative(url);
  28583. }
  28584. url = self2.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  28585. return url;
  28586. };
  28587. Editor2.prototype.addVisual = function(elm) {
  28588. addVisual(this, elm);
  28589. };
  28590. Editor2.prototype.remove = function() {
  28591. remove(this);
  28592. };
  28593. Editor2.prototype.destroy = function(automatic) {
  28594. destroy(this, automatic);
  28595. };
  28596. Editor2.prototype.uploadImages = function(callback) {
  28597. return this.editorUpload.uploadImages(callback);
  28598. };
  28599. Editor2.prototype._scanForImages = function() {
  28600. return this.editorUpload.scanForImages();
  28601. };
  28602. Editor2.prototype.addButton = function() {
  28603. 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");
  28604. };
  28605. Editor2.prototype.addSidebar = function() {
  28606. throw new Error("editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead");
  28607. };
  28608. Editor2.prototype.addMenuItem = function() {
  28609. throw new Error("editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead");
  28610. };
  28611. Editor2.prototype.addContextToolbar = function() {
  28612. throw new Error("editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead");
  28613. };
  28614. return Editor2;
  28615. }();
  28616. var DOM = DOMUtils.DOM;
  28617. var explode = Tools.explode, each$1 = Tools.each, extend$2 = Tools.extend;
  28618. var instanceCounter = 0, boundGlobalEvents = false;
  28619. var beforeUnloadDelegate;
  28620. var legacyEditors = [];
  28621. var editors = [];
  28622. var isValidLegacyKey = function(id) {
  28623. return id !== "length";
  28624. };
  28625. var globalEventDelegate = function(e) {
  28626. var type2 = e.type;
  28627. each$1(EditorManager.get(), function(editor) {
  28628. switch (type2) {
  28629. case "scroll":
  28630. editor.fire("ScrollWindow", e);
  28631. break;
  28632. case "resize":
  28633. editor.fire("ResizeWindow", e);
  28634. break;
  28635. }
  28636. });
  28637. };
  28638. var toggleGlobalEvents = function(state) {
  28639. if (state !== boundGlobalEvents) {
  28640. if (state) {
  28641. DomQuery(window).on("resize scroll", globalEventDelegate);
  28642. } else {
  28643. DomQuery(window).off("resize scroll", globalEventDelegate);
  28644. }
  28645. boundGlobalEvents = state;
  28646. }
  28647. };
  28648. var removeEditorFromList = function(targetEditor) {
  28649. var oldEditors = editors;
  28650. delete legacyEditors[targetEditor.id];
  28651. for (var i = 0; i < legacyEditors.length; i++) {
  28652. if (legacyEditors[i] === targetEditor) {
  28653. legacyEditors.splice(i, 1);
  28654. break;
  28655. }
  28656. }
  28657. editors = filter$4(editors, function(editor) {
  28658. return targetEditor !== editor;
  28659. });
  28660. if (EditorManager.activeEditor === targetEditor) {
  28661. EditorManager.activeEditor = editors.length > 0 ? editors[0] : null;
  28662. }
  28663. if (EditorManager.focusedEditor === targetEditor) {
  28664. EditorManager.focusedEditor = null;
  28665. }
  28666. return oldEditors.length !== editors.length;
  28667. };
  28668. var purgeDestroyedEditor = function(editor) {
  28669. if (editor && editor.initialized && !(editor.getContainer() || editor.getBody()).parentNode) {
  28670. removeEditorFromList(editor);
  28671. editor.unbindAllNativeEvents();
  28672. editor.destroy(true);
  28673. editor.removed = true;
  28674. editor = null;
  28675. }
  28676. return editor;
  28677. };
  28678. var isQuirksMode = document.compatMode !== "CSS1Compat";
  28679. var EditorManager = __assign(__assign({}, Observable), {
  28680. baseURI: null,
  28681. baseURL: null,
  28682. defaultSettings: {},
  28683. documentBaseURL: null,
  28684. suffix: null,
  28685. $: DomQuery,
  28686. majorVersion: "5",
  28687. minorVersion: "10.5",
  28688. releaseDate: "2022-05-25",
  28689. editors: legacyEditors,
  28690. i18n: I18n,
  28691. activeEditor: null,
  28692. focusedEditor: null,
  28693. settings: {},
  28694. setup: function() {
  28695. var self2 = this;
  28696. var baseURL, documentBaseURL, suffix = "";
  28697. documentBaseURL = URI.getDocumentBaseUrl(document.location);
  28698. if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) {
  28699. documentBaseURL = documentBaseURL.replace(/[\?#].*$/, "").replace(/[\/\\][^\/]+$/, "");
  28700. if (!/[\/\\]$/.test(documentBaseURL)) {
  28701. documentBaseURL += "/";
  28702. }
  28703. }
  28704. var preInit2 = window.tinymce || window.tinyMCEPreInit;
  28705. if (preInit2) {
  28706. baseURL = preInit2.base || preInit2.baseURL;
  28707. suffix = preInit2.suffix;
  28708. } else {
  28709. var scripts = document.getElementsByTagName("script");
  28710. for (var i = 0; i < scripts.length; i++) {
  28711. var src = scripts[i].src || "";
  28712. if (src === "") {
  28713. continue;
  28714. }
  28715. var srcScript = src.substring(src.lastIndexOf("/"));
  28716. if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
  28717. if (srcScript.indexOf(".min") !== -1) {
  28718. suffix = ".min";
  28719. }
  28720. baseURL = src.substring(0, src.lastIndexOf("/"));
  28721. break;
  28722. }
  28723. }
  28724. if (!baseURL && document.currentScript) {
  28725. var src = document.currentScript.src;
  28726. if (src.indexOf(".min") !== -1) {
  28727. suffix = ".min";
  28728. }
  28729. baseURL = src.substring(0, src.lastIndexOf("/"));
  28730. }
  28731. }
  28732. self2.baseURL = new URI(documentBaseURL).toAbsolute(baseURL);
  28733. self2.documentBaseURL = documentBaseURL;
  28734. self2.baseURI = new URI(self2.baseURL);
  28735. self2.suffix = suffix;
  28736. setup$l(self2);
  28737. },
  28738. overrideDefaults: function(defaultSettings) {
  28739. var baseUrl = defaultSettings.base_url;
  28740. if (baseUrl) {
  28741. this._setBaseUrl(baseUrl);
  28742. }
  28743. var suffix = defaultSettings.suffix;
  28744. if (defaultSettings.suffix) {
  28745. this.suffix = suffix;
  28746. }
  28747. this.defaultSettings = defaultSettings;
  28748. var pluginBaseUrls = defaultSettings.plugin_base_urls;
  28749. if (pluginBaseUrls !== void 0) {
  28750. each$j(pluginBaseUrls, function(pluginBaseUrl, pluginName) {
  28751. AddOnManager.PluginManager.urls[pluginName] = pluginBaseUrl;
  28752. });
  28753. }
  28754. },
  28755. init: function(settings) {
  28756. var self2 = this;
  28757. var result;
  28758. var 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", " ");
  28759. var isInvalidInlineTarget = function(settings2, elm) {
  28760. return settings2.inline && elm.tagName.toLowerCase() in invalidInlineTargets;
  28761. };
  28762. var createId = function(elm) {
  28763. var id = elm.id;
  28764. if (!id) {
  28765. id = get$9(elm, "name").filter(function(name2) {
  28766. return !DOM.get(name2);
  28767. }).getOrThunk(DOM.uniqueId);
  28768. elm.setAttribute("id", id);
  28769. }
  28770. return id;
  28771. };
  28772. var execCallback = function(name2) {
  28773. var callback = settings[name2];
  28774. if (!callback) {
  28775. return;
  28776. }
  28777. return callback.apply(self2, []);
  28778. };
  28779. var hasClass2 = function(elm, className) {
  28780. return className.constructor === RegExp ? className.test(elm.className) : DOM.hasClass(elm, className);
  28781. };
  28782. var findTargets = function(settings2) {
  28783. var targets = [];
  28784. if (Env.browser.isIE() && Env.browser.version.major < 11) {
  28785. 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/");
  28786. return [];
  28787. } else if (isQuirksMode) {
  28788. initError("Failed to initialize the editor as the document is not in standards mode. TinyMCE requires standards mode.");
  28789. return [];
  28790. }
  28791. if (settings2.types) {
  28792. each$1(settings2.types, function(type2) {
  28793. targets = targets.concat(DOM.select(type2.selector));
  28794. });
  28795. return targets;
  28796. } else if (settings2.selector) {
  28797. return DOM.select(settings2.selector);
  28798. } else if (settings2.target) {
  28799. return [settings2.target];
  28800. }
  28801. switch (settings2.mode) {
  28802. case "exact":
  28803. var l = settings2.elements || "";
  28804. if (l.length > 0) {
  28805. each$1(explode(l), function(id) {
  28806. var elm = DOM.get(id);
  28807. if (elm) {
  28808. targets.push(elm);
  28809. } else {
  28810. each$1(document.forms, function(f) {
  28811. each$1(f.elements, function(e) {
  28812. if (e.name === id) {
  28813. id = "mce_editor_" + instanceCounter++;
  28814. DOM.setAttrib(e, "id", id);
  28815. targets.push(e);
  28816. }
  28817. });
  28818. });
  28819. }
  28820. });
  28821. }
  28822. break;
  28823. case "textareas":
  28824. case "specific_textareas":
  28825. each$1(DOM.select("textarea"), function(elm) {
  28826. if (settings2.editor_deselector && hasClass2(elm, settings2.editor_deselector)) {
  28827. return;
  28828. }
  28829. if (!settings2.editor_selector || hasClass2(elm, settings2.editor_selector)) {
  28830. targets.push(elm);
  28831. }
  28832. });
  28833. break;
  28834. }
  28835. return targets;
  28836. };
  28837. var provideResults = function(editors2) {
  28838. result = editors2;
  28839. };
  28840. var initEditors = function() {
  28841. var initCount = 0;
  28842. var editors2 = [];
  28843. var targets;
  28844. var createEditor = function(id, settings2, targetElm) {
  28845. var editor = new Editor(id, settings2, self2);
  28846. editors2.push(editor);
  28847. editor.on("init", function() {
  28848. if (++initCount === targets.length) {
  28849. provideResults(editors2);
  28850. }
  28851. });
  28852. editor.targetElm = editor.targetElm || targetElm;
  28853. editor.render();
  28854. };
  28855. DOM.unbind(window, "ready", initEditors);
  28856. execCallback("onpageload");
  28857. targets = DomQuery.unique(findTargets(settings));
  28858. if (settings.types) {
  28859. each$1(settings.types, function(type2) {
  28860. Tools.each(targets, function(elm) {
  28861. if (DOM.is(elm, type2.selector)) {
  28862. createEditor(createId(elm), extend$2({}, settings, type2), elm);
  28863. return false;
  28864. }
  28865. return true;
  28866. });
  28867. });
  28868. return;
  28869. }
  28870. Tools.each(targets, function(elm) {
  28871. purgeDestroyedEditor(self2.get(elm.id));
  28872. });
  28873. targets = Tools.grep(targets, function(elm) {
  28874. return !self2.get(elm.id);
  28875. });
  28876. if (targets.length === 0) {
  28877. provideResults([]);
  28878. } else {
  28879. each$1(targets, function(elm) {
  28880. if (isInvalidInlineTarget(settings, elm)) {
  28881. initError("Could not initialize inline editor on invalid inline target element", elm);
  28882. } else {
  28883. createEditor(createId(elm), settings, elm);
  28884. }
  28885. });
  28886. }
  28887. };
  28888. self2.settings = settings;
  28889. DOM.bind(window, "ready", initEditors);
  28890. return new promiseObj(function(resolve2) {
  28891. if (result) {
  28892. resolve2(result);
  28893. } else {
  28894. provideResults = function(editors2) {
  28895. resolve2(editors2);
  28896. };
  28897. }
  28898. });
  28899. },
  28900. get: function(id) {
  28901. if (arguments.length === 0) {
  28902. return editors.slice(0);
  28903. } else if (isString$1(id)) {
  28904. return find$3(editors, function(editor) {
  28905. return editor.id === id;
  28906. }).getOr(null);
  28907. } else if (isNumber(id)) {
  28908. return editors[id] ? editors[id] : null;
  28909. } else {
  28910. return null;
  28911. }
  28912. },
  28913. add: function(editor) {
  28914. var self2 = this;
  28915. var existingEditor = legacyEditors[editor.id];
  28916. if (existingEditor === editor) {
  28917. return editor;
  28918. }
  28919. if (self2.get(editor.id) === null) {
  28920. if (isValidLegacyKey(editor.id)) {
  28921. legacyEditors[editor.id] = editor;
  28922. }
  28923. legacyEditors.push(editor);
  28924. editors.push(editor);
  28925. }
  28926. toggleGlobalEvents(true);
  28927. self2.activeEditor = editor;
  28928. self2.fire("AddEditor", { editor });
  28929. if (!beforeUnloadDelegate) {
  28930. beforeUnloadDelegate = function(e) {
  28931. var event = self2.fire("BeforeUnload");
  28932. if (event.returnValue) {
  28933. e.preventDefault();
  28934. e.returnValue = event.returnValue;
  28935. return event.returnValue;
  28936. }
  28937. };
  28938. window.addEventListener("beforeunload", beforeUnloadDelegate);
  28939. }
  28940. return editor;
  28941. },
  28942. createEditor: function(id, settings) {
  28943. return this.add(new Editor(id, settings, this));
  28944. },
  28945. remove: function(selector) {
  28946. var self2 = this;
  28947. var i, editor;
  28948. if (!selector) {
  28949. for (i = editors.length - 1; i >= 0; i--) {
  28950. self2.remove(editors[i]);
  28951. }
  28952. return;
  28953. }
  28954. if (isString$1(selector)) {
  28955. each$1(DOM.select(selector), function(elm) {
  28956. editor = self2.get(elm.id);
  28957. if (editor) {
  28958. self2.remove(editor);
  28959. }
  28960. });
  28961. return;
  28962. }
  28963. editor = selector;
  28964. if (isNull(self2.get(editor.id))) {
  28965. return null;
  28966. }
  28967. if (removeEditorFromList(editor)) {
  28968. self2.fire("RemoveEditor", { editor });
  28969. }
  28970. if (editors.length === 0) {
  28971. window.removeEventListener("beforeunload", beforeUnloadDelegate);
  28972. }
  28973. editor.remove();
  28974. toggleGlobalEvents(editors.length > 0);
  28975. return editor;
  28976. },
  28977. execCommand: function(cmd, ui, value2) {
  28978. var self2 = this, editor = self2.get(value2);
  28979. switch (cmd) {
  28980. case "mceAddEditor":
  28981. if (!self2.get(value2)) {
  28982. new Editor(value2, self2.settings, self2).render();
  28983. }
  28984. return true;
  28985. case "mceRemoveEditor":
  28986. if (editor) {
  28987. editor.remove();
  28988. }
  28989. return true;
  28990. case "mceToggleEditor":
  28991. if (!editor) {
  28992. self2.execCommand("mceAddEditor", false, value2);
  28993. return true;
  28994. }
  28995. if (editor.isHidden()) {
  28996. editor.show();
  28997. } else {
  28998. editor.hide();
  28999. }
  29000. return true;
  29001. }
  29002. if (self2.activeEditor) {
  29003. return self2.activeEditor.execCommand(cmd, ui, value2);
  29004. }
  29005. return false;
  29006. },
  29007. triggerSave: function() {
  29008. each$1(editors, function(editor) {
  29009. editor.save();
  29010. });
  29011. },
  29012. addI18n: function(code, items) {
  29013. I18n.add(code, items);
  29014. },
  29015. translate: function(text) {
  29016. return I18n.translate(text);
  29017. },
  29018. setActive: function(editor) {
  29019. var activeEditor = this.activeEditor;
  29020. if (this.activeEditor !== editor) {
  29021. if (activeEditor) {
  29022. activeEditor.fire("deactivate", { relatedTarget: editor });
  29023. }
  29024. editor.fire("activate", { relatedTarget: activeEditor });
  29025. }
  29026. this.activeEditor = editor;
  29027. },
  29028. _setBaseUrl: function(baseUrl) {
  29029. this.baseURL = new URI(this.documentBaseURL).toAbsolute(baseUrl.replace(/\/+$/, ""));
  29030. this.baseURI = new URI(this.baseURL);
  29031. }
  29032. });
  29033. EditorManager.setup();
  29034. var min$1 = Math.min, max$1 = Math.max, round$1 = Math.round;
  29035. var relativePosition = function(rect, targetRect, rel) {
  29036. var x = targetRect.x;
  29037. var y = targetRect.y;
  29038. var w = rect.w;
  29039. var h = rect.h;
  29040. var targetW = targetRect.w;
  29041. var targetH = targetRect.h;
  29042. var relChars = (rel || "").split("");
  29043. if (relChars[0] === "b") {
  29044. y += targetH;
  29045. }
  29046. if (relChars[1] === "r") {
  29047. x += targetW;
  29048. }
  29049. if (relChars[0] === "c") {
  29050. y += round$1(targetH / 2);
  29051. }
  29052. if (relChars[1] === "c") {
  29053. x += round$1(targetW / 2);
  29054. }
  29055. if (relChars[3] === "b") {
  29056. y -= h;
  29057. }
  29058. if (relChars[4] === "r") {
  29059. x -= w;
  29060. }
  29061. if (relChars[3] === "c") {
  29062. y -= round$1(h / 2);
  29063. }
  29064. if (relChars[4] === "c") {
  29065. x -= round$1(w / 2);
  29066. }
  29067. return create$2(x, y, w, h);
  29068. };
  29069. var findBestRelativePosition = function(rect, targetRect, constrainRect, rels) {
  29070. var pos, i;
  29071. for (i = 0; i < rels.length; i++) {
  29072. pos = relativePosition(rect, targetRect, rels[i]);
  29073. 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) {
  29074. return rels[i];
  29075. }
  29076. }
  29077. return null;
  29078. };
  29079. var inflate = function(rect, w, h) {
  29080. return create$2(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2);
  29081. };
  29082. var intersect = function(rect, cropRect) {
  29083. var x1 = max$1(rect.x, cropRect.x);
  29084. var y1 = max$1(rect.y, cropRect.y);
  29085. var x2 = min$1(rect.x + rect.w, cropRect.x + cropRect.w);
  29086. var y2 = min$1(rect.y + rect.h, cropRect.y + cropRect.h);
  29087. if (x2 - x1 < 0 || y2 - y1 < 0) {
  29088. return null;
  29089. }
  29090. return create$2(x1, y1, x2 - x1, y2 - y1);
  29091. };
  29092. var clamp = function(rect, clampRect, fixedSize) {
  29093. var x1 = rect.x;
  29094. var y1 = rect.y;
  29095. var x2 = rect.x + rect.w;
  29096. var y2 = rect.y + rect.h;
  29097. var cx2 = clampRect.x + clampRect.w;
  29098. var cy2 = clampRect.y + clampRect.h;
  29099. var underflowX1 = max$1(0, clampRect.x - x1);
  29100. var underflowY1 = max$1(0, clampRect.y - y1);
  29101. var overflowX2 = max$1(0, x2 - cx2);
  29102. var overflowY2 = max$1(0, y2 - cy2);
  29103. x1 += underflowX1;
  29104. y1 += underflowY1;
  29105. if (fixedSize) {
  29106. x2 += underflowX1;
  29107. y2 += underflowY1;
  29108. x1 -= overflowX2;
  29109. y1 -= overflowY2;
  29110. }
  29111. x2 -= overflowX2;
  29112. y2 -= overflowY2;
  29113. return create$2(x1, y1, x2 - x1, y2 - y1);
  29114. };
  29115. var create$2 = function(x, y, w, h) {
  29116. return {
  29117. x,
  29118. y,
  29119. w,
  29120. h
  29121. };
  29122. };
  29123. var fromClientRect = function(clientRect) {
  29124. return create$2(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
  29125. };
  29126. var Rect = {
  29127. inflate,
  29128. relativePosition,
  29129. findBestRelativePosition,
  29130. intersect,
  29131. clamp,
  29132. create: create$2,
  29133. fromClientRect
  29134. };
  29135. var awaiter = function(resolveCb, rejectCb, timeout) {
  29136. if (timeout === void 0) {
  29137. timeout = 1e3;
  29138. }
  29139. var done2 = false;
  29140. var timer = null;
  29141. var complete = function(completer) {
  29142. return function() {
  29143. var args = [];
  29144. for (var _i = 0; _i < arguments.length; _i++) {
  29145. args[_i] = arguments[_i];
  29146. }
  29147. if (!done2) {
  29148. done2 = true;
  29149. if (timer !== null) {
  29150. clearTimeout(timer);
  29151. timer = null;
  29152. }
  29153. completer.apply(null, args);
  29154. }
  29155. };
  29156. };
  29157. var resolve2 = complete(resolveCb);
  29158. var reject = complete(rejectCb);
  29159. var start2 = function() {
  29160. var args = [];
  29161. for (var _i = 0; _i < arguments.length; _i++) {
  29162. args[_i] = arguments[_i];
  29163. }
  29164. if (!done2 && timer === null) {
  29165. timer = setTimeout(function() {
  29166. return reject.apply(null, args);
  29167. }, timeout);
  29168. }
  29169. };
  29170. return {
  29171. start: start2,
  29172. resolve: resolve2,
  29173. reject
  29174. };
  29175. };
  29176. var create$1 = function() {
  29177. var tasks = {};
  29178. var resultFns = {};
  29179. var load = function(id, url) {
  29180. var loadErrMsg = 'Script at URL "' + url + '" failed to load';
  29181. var runErrMsg = 'Script at URL "' + url + "\" did not call `tinymce.Resource.add('" + id + "', data)` within 1 second";
  29182. if (tasks[id] !== void 0) {
  29183. return tasks[id];
  29184. } else {
  29185. var task = new promiseObj(function(resolve2, reject) {
  29186. var waiter = awaiter(resolve2, reject);
  29187. resultFns[id] = waiter.resolve;
  29188. ScriptLoader.ScriptLoader.loadScript(url, function() {
  29189. return waiter.start(runErrMsg);
  29190. }, function() {
  29191. return waiter.reject(loadErrMsg);
  29192. });
  29193. });
  29194. tasks[id] = task;
  29195. return task;
  29196. }
  29197. };
  29198. var add2 = function(id, data2) {
  29199. if (resultFns[id] !== void 0) {
  29200. resultFns[id](data2);
  29201. delete resultFns[id];
  29202. }
  29203. tasks[id] = promiseObj.resolve(data2);
  29204. };
  29205. return {
  29206. load,
  29207. add: add2
  29208. };
  29209. };
  29210. var Resource = create$1();
  29211. var each = Tools.each, extend$1 = Tools.extend;
  29212. var extendClass, initializing;
  29213. var Class = function() {
  29214. };
  29215. Class.extend = extendClass = function(props) {
  29216. var self2 = this;
  29217. var _super = self2.prototype;
  29218. var Class2 = function() {
  29219. var i, mixins, mixin;
  29220. var self3 = this;
  29221. if (!initializing) {
  29222. if (self3.init) {
  29223. self3.init.apply(self3, arguments);
  29224. }
  29225. mixins = self3.Mixins;
  29226. if (mixins) {
  29227. i = mixins.length;
  29228. while (i--) {
  29229. mixin = mixins[i];
  29230. if (mixin.init) {
  29231. mixin.init.apply(self3, arguments);
  29232. }
  29233. }
  29234. }
  29235. }
  29236. };
  29237. var dummy = function() {
  29238. return this;
  29239. };
  29240. var createMethod = function(name2, fn) {
  29241. return function() {
  29242. var self3 = this;
  29243. var tmp = self3._super;
  29244. self3._super = _super[name2];
  29245. var ret = fn.apply(self3, arguments);
  29246. self3._super = tmp;
  29247. return ret;
  29248. };
  29249. };
  29250. initializing = true;
  29251. var prototype = new self2();
  29252. initializing = false;
  29253. if (props.Mixins) {
  29254. each(props.Mixins, function(mixin) {
  29255. for (var name_1 in mixin) {
  29256. if (name_1 !== "init") {
  29257. props[name_1] = mixin[name_1];
  29258. }
  29259. }
  29260. });
  29261. if (_super.Mixins) {
  29262. props.Mixins = _super.Mixins.concat(props.Mixins);
  29263. }
  29264. }
  29265. if (props.Methods) {
  29266. each(props.Methods.split(","), function(name2) {
  29267. props[name2] = dummy;
  29268. });
  29269. }
  29270. if (props.Properties) {
  29271. each(props.Properties.split(","), function(name2) {
  29272. var fieldName = "_" + name2;
  29273. props[name2] = function(value2) {
  29274. var self3 = this;
  29275. if (value2 !== void 0) {
  29276. self3[fieldName] = value2;
  29277. return self3;
  29278. }
  29279. return self3[fieldName];
  29280. };
  29281. });
  29282. }
  29283. if (props.Statics) {
  29284. each(props.Statics, function(func, name2) {
  29285. Class2[name2] = func;
  29286. });
  29287. }
  29288. if (props.Defaults && _super.Defaults) {
  29289. props.Defaults = extend$1({}, _super.Defaults, props.Defaults);
  29290. }
  29291. each$j(props, function(member, name2) {
  29292. if (typeof member === "function" && _super[name2]) {
  29293. prototype[name2] = createMethod(name2, member);
  29294. } else {
  29295. prototype[name2] = member;
  29296. }
  29297. });
  29298. Class2.prototype = prototype;
  29299. Class2.constructor = Class2;
  29300. Class2.extend = extendClass;
  29301. return Class2;
  29302. };
  29303. var min = Math.min, max = Math.max, round = Math.round;
  29304. var Color = function(value2) {
  29305. var self2 = {};
  29306. var r2 = 0, g = 0, b = 0;
  29307. var rgb2hsv = function(r3, g2, b2) {
  29308. var h, s, v;
  29309. h = 0;
  29310. s = 0;
  29311. v = 0;
  29312. r3 = r3 / 255;
  29313. g2 = g2 / 255;
  29314. b2 = b2 / 255;
  29315. var minRGB = min(r3, min(g2, b2));
  29316. var maxRGB = max(r3, max(g2, b2));
  29317. if (minRGB === maxRGB) {
  29318. v = minRGB;
  29319. return {
  29320. h: 0,
  29321. s: 0,
  29322. v: v * 100
  29323. };
  29324. }
  29325. var d = r3 === minRGB ? g2 - b2 : b2 === minRGB ? r3 - g2 : b2 - r3;
  29326. h = r3 === minRGB ? 3 : b2 === minRGB ? 1 : 5;
  29327. h = 60 * (h - d / (maxRGB - minRGB));
  29328. s = (maxRGB - minRGB) / maxRGB;
  29329. v = maxRGB;
  29330. return {
  29331. h: round(h),
  29332. s: round(s * 100),
  29333. v: round(v * 100)
  29334. };
  29335. };
  29336. var hsvToRgb = function(hue, saturation, brightness) {
  29337. hue = (parseInt(hue, 10) || 0) % 360;
  29338. saturation = parseInt(saturation, 10) / 100;
  29339. brightness = parseInt(brightness, 10) / 100;
  29340. saturation = max(0, min(saturation, 1));
  29341. brightness = max(0, min(brightness, 1));
  29342. if (saturation === 0) {
  29343. r2 = g = b = round(255 * brightness);
  29344. return;
  29345. }
  29346. var side = hue / 60;
  29347. var chroma = brightness * saturation;
  29348. var x = chroma * (1 - Math.abs(side % 2 - 1));
  29349. var match2 = brightness - chroma;
  29350. switch (Math.floor(side)) {
  29351. case 0:
  29352. r2 = chroma;
  29353. g = x;
  29354. b = 0;
  29355. break;
  29356. case 1:
  29357. r2 = x;
  29358. g = chroma;
  29359. b = 0;
  29360. break;
  29361. case 2:
  29362. r2 = 0;
  29363. g = chroma;
  29364. b = x;
  29365. break;
  29366. case 3:
  29367. r2 = 0;
  29368. g = x;
  29369. b = chroma;
  29370. break;
  29371. case 4:
  29372. r2 = x;
  29373. g = 0;
  29374. b = chroma;
  29375. break;
  29376. case 5:
  29377. r2 = chroma;
  29378. g = 0;
  29379. b = x;
  29380. break;
  29381. default:
  29382. r2 = g = b = 0;
  29383. }
  29384. r2 = round(255 * (r2 + match2));
  29385. g = round(255 * (g + match2));
  29386. b = round(255 * (b + match2));
  29387. };
  29388. var toHex2 = function() {
  29389. var hex = function(val) {
  29390. val = parseInt(val, 10).toString(16);
  29391. return val.length > 1 ? val : "0" + val;
  29392. };
  29393. return "#" + hex(r2) + hex(g) + hex(b);
  29394. };
  29395. var toRgb = function() {
  29396. return {
  29397. r: r2,
  29398. g,
  29399. b
  29400. };
  29401. };
  29402. var toHsv = function() {
  29403. return rgb2hsv(r2, g, b);
  29404. };
  29405. var parse = function(value3) {
  29406. var matches2;
  29407. if (typeof value3 === "object") {
  29408. if ("r" in value3) {
  29409. r2 = value3.r;
  29410. g = value3.g;
  29411. b = value3.b;
  29412. } else if ("v" in value3) {
  29413. hsvToRgb(value3.h, value3.s, value3.v);
  29414. }
  29415. } else {
  29416. if (matches2 = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(value3)) {
  29417. r2 = parseInt(matches2[1], 10);
  29418. g = parseInt(matches2[2], 10);
  29419. b = parseInt(matches2[3], 10);
  29420. } else if (matches2 = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value3)) {
  29421. r2 = parseInt(matches2[1], 16);
  29422. g = parseInt(matches2[2], 16);
  29423. b = parseInt(matches2[3], 16);
  29424. } else if (matches2 = /#([0-F])([0-F])([0-F])/gi.exec(value3)) {
  29425. r2 = parseInt(matches2[1] + matches2[1], 16);
  29426. g = parseInt(matches2[2] + matches2[2], 16);
  29427. b = parseInt(matches2[3] + matches2[3], 16);
  29428. }
  29429. }
  29430. r2 = r2 < 0 ? 0 : r2 > 255 ? 255 : r2;
  29431. g = g < 0 ? 0 : g > 255 ? 255 : g;
  29432. b = b < 0 ? 0 : b > 255 ? 255 : b;
  29433. return self2;
  29434. };
  29435. if (value2) {
  29436. parse(value2);
  29437. }
  29438. self2.toRgb = toRgb;
  29439. self2.toHsv = toHsv;
  29440. self2.toHex = toHex2;
  29441. self2.parse = parse;
  29442. return self2;
  29443. };
  29444. var serialize = function(obj) {
  29445. var data2 = JSON.stringify(obj);
  29446. if (!isString$1(data2)) {
  29447. return data2;
  29448. }
  29449. return data2.replace(/[\u0080-\uFFFF]/g, function(match2) {
  29450. var hexCode = match2.charCodeAt(0).toString(16);
  29451. return "\\u" + "0000".substring(hexCode.length) + hexCode;
  29452. });
  29453. };
  29454. var JSONUtils = {
  29455. serialize,
  29456. parse: function(text) {
  29457. try {
  29458. return JSON.parse(text);
  29459. } catch (ex) {
  29460. }
  29461. }
  29462. };
  29463. var JSONP = {
  29464. callbacks: {},
  29465. count: 0,
  29466. send: function(settings) {
  29467. var self2 = this, dom2 = DOMUtils.DOM, count2 = settings.count !== void 0 ? settings.count : self2.count;
  29468. var id = "tinymce_jsonp_" + count2;
  29469. self2.callbacks[count2] = function(json) {
  29470. dom2.remove(id);
  29471. delete self2.callbacks[count2];
  29472. settings.callback(json);
  29473. };
  29474. dom2.add(dom2.doc.body, "script", {
  29475. id,
  29476. src: settings.url,
  29477. type: "text/javascript"
  29478. });
  29479. self2.count++;
  29480. }
  29481. };
  29482. var XHR = __assign(__assign({}, Observable), {
  29483. send: function(settings) {
  29484. var xhr, count2 = 0;
  29485. var ready = function() {
  29486. if (!settings.async || xhr.readyState === 4 || count2++ > 1e4) {
  29487. if (settings.success && count2 < 1e4 && xhr.status === 200) {
  29488. settings.success.call(settings.success_scope, "" + xhr.responseText, xhr, settings);
  29489. } else if (settings.error) {
  29490. settings.error.call(settings.error_scope, count2 > 1e4 ? "TIMED_OUT" : "GENERAL", xhr, settings);
  29491. }
  29492. xhr = null;
  29493. } else {
  29494. Delay.setTimeout(ready, 10);
  29495. }
  29496. };
  29497. settings.scope = settings.scope || this;
  29498. settings.success_scope = settings.success_scope || settings.scope;
  29499. settings.error_scope = settings.error_scope || settings.scope;
  29500. settings.async = settings.async !== false;
  29501. settings.data = settings.data || "";
  29502. XHR.fire("beforeInitialize", { settings });
  29503. xhr = new XMLHttpRequest();
  29504. if (xhr.overrideMimeType) {
  29505. xhr.overrideMimeType(settings.content_type);
  29506. }
  29507. xhr.open(settings.type || (settings.data ? "POST" : "GET"), settings.url, settings.async);
  29508. if (settings.crossDomain) {
  29509. xhr.withCredentials = true;
  29510. }
  29511. if (settings.content_type) {
  29512. xhr.setRequestHeader("Content-Type", settings.content_type);
  29513. }
  29514. if (settings.requestheaders) {
  29515. Tools.each(settings.requestheaders, function(header) {
  29516. xhr.setRequestHeader(header.key, header.value);
  29517. });
  29518. }
  29519. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  29520. xhr = XHR.fire("beforeSend", {
  29521. xhr,
  29522. settings
  29523. }).xhr;
  29524. xhr.send(settings.data);
  29525. if (!settings.async) {
  29526. return ready();
  29527. }
  29528. Delay.setTimeout(ready, 10);
  29529. }
  29530. });
  29531. var extend = Tools.extend;
  29532. var JSONRequest = function() {
  29533. function JSONRequest2(settings) {
  29534. this.settings = extend({}, settings);
  29535. this.count = 0;
  29536. }
  29537. JSONRequest2.sendRPC = function(o) {
  29538. return new JSONRequest2().send(o);
  29539. };
  29540. JSONRequest2.prototype.send = function(args) {
  29541. var ecb = args.error, scb = args.success;
  29542. var xhrArgs = extend(this.settings, args);
  29543. xhrArgs.success = function(c, x) {
  29544. c = JSONUtils.parse(c);
  29545. if (typeof c === "undefined") {
  29546. c = { error: "JSON Parse error." };
  29547. }
  29548. if (c.error) {
  29549. ecb.call(xhrArgs.error_scope || xhrArgs.scope, c.error, x);
  29550. } else {
  29551. scb.call(xhrArgs.success_scope || xhrArgs.scope, c.result);
  29552. }
  29553. };
  29554. xhrArgs.error = function(ty, x) {
  29555. if (ecb) {
  29556. ecb.call(xhrArgs.error_scope || xhrArgs.scope, ty, x);
  29557. }
  29558. };
  29559. xhrArgs.data = JSONUtils.serialize({
  29560. id: args.id || "c" + this.count++,
  29561. method: args.method,
  29562. params: args.params
  29563. });
  29564. xhrArgs.content_type = "application/json";
  29565. XHR.send(xhrArgs);
  29566. };
  29567. return JSONRequest2;
  29568. }();
  29569. var create = function() {
  29570. return function() {
  29571. var data2 = {};
  29572. var keys2 = [];
  29573. var storage = {
  29574. getItem: function(key) {
  29575. var item = data2[key];
  29576. return item ? item : null;
  29577. },
  29578. setItem: function(key, value2) {
  29579. keys2.push(key);
  29580. data2[key] = String(value2);
  29581. },
  29582. key: function(index) {
  29583. return keys2[index];
  29584. },
  29585. removeItem: function(key) {
  29586. keys2 = keys2.filter(function(k) {
  29587. return k === key;
  29588. });
  29589. delete data2[key];
  29590. },
  29591. clear: function() {
  29592. keys2 = [];
  29593. data2 = {};
  29594. },
  29595. length: 0
  29596. };
  29597. Object.defineProperty(storage, "length", {
  29598. get: function() {
  29599. return keys2.length;
  29600. },
  29601. configurable: false,
  29602. enumerable: false
  29603. });
  29604. return storage;
  29605. }();
  29606. };
  29607. var localStorage;
  29608. try {
  29609. var test = "__storage_test__";
  29610. localStorage = window.localStorage;
  29611. localStorage.setItem(test, test);
  29612. localStorage.removeItem(test);
  29613. } catch (e) {
  29614. localStorage = create();
  29615. }
  29616. var LocalStorage = localStorage;
  29617. var publicApi = {
  29618. geom: { Rect },
  29619. util: {
  29620. Promise: promiseObj,
  29621. Delay,
  29622. Tools,
  29623. VK,
  29624. URI,
  29625. Class,
  29626. EventDispatcher,
  29627. Observable,
  29628. I18n,
  29629. XHR,
  29630. JSON: JSONUtils,
  29631. JSONRequest,
  29632. JSONP,
  29633. LocalStorage,
  29634. Color,
  29635. ImageUploader
  29636. },
  29637. dom: {
  29638. EventUtils,
  29639. Sizzle,
  29640. DomQuery,
  29641. TreeWalker: DomTreeWalker,
  29642. TextSeeker,
  29643. DOMUtils,
  29644. ScriptLoader,
  29645. RangeUtils,
  29646. Serializer: DomSerializer,
  29647. StyleSheetLoader,
  29648. ControlSelection,
  29649. BookmarkManager,
  29650. Selection: EditorSelection,
  29651. Event: EventUtils.Event
  29652. },
  29653. html: {
  29654. Styles,
  29655. Entities,
  29656. Node: AstNode,
  29657. Schema,
  29658. SaxParser,
  29659. DomParser,
  29660. Writer,
  29661. Serializer: HtmlSerializer
  29662. },
  29663. Env,
  29664. AddOnManager,
  29665. Annotator,
  29666. Formatter,
  29667. UndoManager,
  29668. EditorCommands,
  29669. WindowManager,
  29670. NotificationManager,
  29671. EditorObservable,
  29672. Shortcuts,
  29673. Editor,
  29674. FocusManager,
  29675. EditorManager,
  29676. DOM: DOMUtils.DOM,
  29677. ScriptLoader: ScriptLoader.ScriptLoader,
  29678. PluginManager,
  29679. ThemeManager,
  29680. IconManager,
  29681. Resource,
  29682. trim: Tools.trim,
  29683. isArray: Tools.isArray,
  29684. is: Tools.is,
  29685. toArray: Tools.toArray,
  29686. makeMap: Tools.makeMap,
  29687. each: Tools.each,
  29688. map: Tools.map,
  29689. grep: Tools.grep,
  29690. inArray: Tools.inArray,
  29691. extend: Tools.extend,
  29692. create: Tools.create,
  29693. walk: Tools.walk,
  29694. createNS: Tools.createNS,
  29695. resolve: Tools.resolve,
  29696. explode: Tools.explode,
  29697. _addCacheSuffix: Tools._addCacheSuffix,
  29698. isOpera: Env.opera,
  29699. isWebKit: Env.webkit,
  29700. isIE: Env.ie,
  29701. isGecko: Env.gecko,
  29702. isMac: Env.mac
  29703. };
  29704. var tinymce = Tools.extend(EditorManager, publicApi);
  29705. var exportToModuleLoaders = function(tinymce2) {
  29706. if (typeof module === "object") {
  29707. try {
  29708. module.exports = tinymce2;
  29709. } catch (_) {
  29710. }
  29711. }
  29712. };
  29713. var exportToWindowGlobal = function(tinymce2) {
  29714. window.tinymce = tinymce2;
  29715. window.tinyMCE = tinymce2;
  29716. };
  29717. exportToWindowGlobal(tinymce);
  29718. exportToModuleLoaders(tinymce);
  29719. })();
  29720. }
  29721. });
  29722. // dep:tinymce_tinymce
  29723. init_define_APP_INFO();
  29724. var tinymce_tinymce_default = require_tinymce();
  29725. export {
  29726. tinymce_tinymce_default as default
  29727. };
  29728. //# sourceMappingURL=tinymce_tinymce.js.map