123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.1.5 (2019-12-19)
  8. */
  9. (function (domGlobals) {
  10. 'use strict';
  11. var noop = function () {
  12. };
  13. var compose = function (fa, fb) {
  14. return function () {
  15. var args = [];
  16. for (var _i = 0; _i < arguments.length; _i++) {
  17. args[_i] = arguments[_i];
  18. }
  19. return fa(fb.apply(null, args));
  20. };
  21. };
  22. var constant = function (value) {
  23. return function () {
  24. return value;
  25. };
  26. };
  27. var identity = function (x) {
  28. return x;
  29. };
  30. function curry(fn) {
  31. var initialArgs = [];
  32. for (var _i = 1; _i < arguments.length; _i++) {
  33. initialArgs[_i - 1] = arguments[_i];
  34. }
  35. return function () {
  36. var restArgs = [];
  37. for (var _i = 0; _i < arguments.length; _i++) {
  38. restArgs[_i] = arguments[_i];
  39. }
  40. var all = initialArgs.concat(restArgs);
  41. return fn.apply(null, all);
  42. };
  43. }
  44. var not = function (f) {
  45. return function () {
  46. var args = [];
  47. for (var _i = 0; _i < arguments.length; _i++) {
  48. args[_i] = arguments[_i];
  49. }
  50. return !f.apply(null, args);
  51. };
  52. };
  53. var die = function (msg) {
  54. return function () {
  55. throw new Error(msg);
  56. };
  57. };
  58. var never = constant(false);
  59. var always = constant(true);
  60. var none = function () {
  61. return NONE;
  62. };
  63. var NONE = function () {
  64. var eq = function (o) {
  65. return o.isNone();
  66. };
  67. var call = function (thunk) {
  68. return thunk();
  69. };
  70. var id = function (n) {
  71. return n;
  72. };
  73. var me = {
  74. fold: function (n, s) {
  75. return n();
  76. },
  77. is: never,
  78. isSome: never,
  79. isNone: always,
  80. getOr: id,
  81. getOrThunk: call,
  82. getOrDie: function (msg) {
  83. throw new Error(msg || 'error: getOrDie called on none.');
  84. },
  85. getOrNull: constant(null),
  86. getOrUndefined: constant(undefined),
  87. or: id,
  88. orThunk: call,
  89. map: none,
  90. each: noop,
  91. bind: none,
  92. exists: never,
  93. forall: always,
  94. filter: none,
  95. equals: eq,
  96. equals_: eq,
  97. toArray: function () {
  98. return [];
  99. },
  100. toString: constant('none()')
  101. };
  102. if (Object.freeze) {
  103. Object.freeze(me);
  104. }
  105. return me;
  106. }();
  107. var some = function (a) {
  108. var constant_a = constant(a);
  109. var self = function () {
  110. return me;
  111. };
  112. var bind = function (f) {
  113. return f(a);
  114. };
  115. var me = {
  116. fold: function (n, s) {
  117. return s(a);
  118. },
  119. is: function (v) {
  120. return a === v;
  121. },
  122. isSome: always,
  123. isNone: never,
  124. getOr: constant_a,
  125. getOrThunk: constant_a,
  126. getOrDie: constant_a,
  127. getOrNull: constant_a,
  128. getOrUndefined: constant_a,
  129. or: self,
  130. orThunk: self,
  131. map: function (f) {
  132. return some(f(a));
  133. },
  134. each: function (f) {
  135. f(a);
  136. },
  137. bind: bind,
  138. exists: bind,
  139. forall: bind,
  140. filter: function (f) {
  141. return f(a) ? me : NONE;
  142. },
  143. toArray: function () {
  144. return [a];
  145. },
  146. toString: function () {
  147. return 'some(' + a + ')';
  148. },
  149. equals: function (o) {
  150. return o.is(a);
  151. },
  152. equals_: function (o, elementEq) {
  153. return o.fold(never, function (b) {
  154. return elementEq(a, b);
  155. });
  156. }
  157. };
  158. return me;
  159. };
  160. var from = function (value) {
  161. return value === null || value === undefined ? NONE : some(value);
  162. };
  163. var Option = {
  164. some: some,
  165. none: none,
  166. from: from
  167. };
  168. var typeOf = function (x) {
  169. if (x === null) {
  170. return 'null';
  171. }
  172. var t = typeof x;
  173. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  174. return 'array';
  175. }
  176. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  177. return 'string';
  178. }
  179. return t;
  180. };
  181. var isType = function (type) {
  182. return function (value) {
  183. return typeOf(value) === type;
  184. };
  185. };
  186. var isString = isType('string');
  187. var isObject = isType('object');
  188. var isArray = isType('array');
  189. var isNull = isType('null');
  190. var isBoolean = isType('boolean');
  191. var isFunction = isType('function');
  192. var isNumber = isType('number');
  193. var nativeSlice = Array.prototype.slice;
  194. var nativeIndexOf = Array.prototype.indexOf;
  195. var nativePush = Array.prototype.push;
  196. var rawIndexOf = function (ts, t) {
  197. return nativeIndexOf.call(ts, t);
  198. };
  199. var indexOf = function (xs, x) {
  200. var r = rawIndexOf(xs, x);
  201. return r === -1 ? Option.none() : Option.some(r);
  202. };
  203. var contains = function (xs, x) {
  204. return rawIndexOf(xs, x) > -1;
  205. };
  206. var exists = function (xs, pred) {
  207. for (var i = 0, len = xs.length; i < len; i++) {
  208. var x = xs[i];
  209. if (pred(x, i)) {
  210. return true;
  211. }
  212. }
  213. return false;
  214. };
  215. var map = function (xs, f) {
  216. var len = xs.length;
  217. var r = new Array(len);
  218. for (var i = 0; i < len; i++) {
  219. var x = xs[i];
  220. r[i] = f(x, i);
  221. }
  222. return r;
  223. };
  224. var each = function (xs, f) {
  225. for (var i = 0, len = xs.length; i < len; i++) {
  226. var x = xs[i];
  227. f(x, i);
  228. }
  229. };
  230. var eachr = function (xs, f) {
  231. for (var i = xs.length - 1; i >= 0; i--) {
  232. var x = xs[i];
  233. f(x, i);
  234. }
  235. };
  236. var partition = function (xs, pred) {
  237. var pass = [];
  238. var fail = [];
  239. for (var i = 0, len = xs.length; i < len; i++) {
  240. var x = xs[i];
  241. var arr = pred(x, i) ? pass : fail;
  242. arr.push(x);
  243. }
  244. return {
  245. pass: pass,
  246. fail: fail
  247. };
  248. };
  249. var filter = function (xs, pred) {
  250. var r = [];
  251. for (var i = 0, len = xs.length; i < len; i++) {
  252. var x = xs[i];
  253. if (pred(x, i)) {
  254. r.push(x);
  255. }
  256. }
  257. return r;
  258. };
  259. var foldr = function (xs, f, acc) {
  260. eachr(xs, function (x) {
  261. acc = f(acc, x);
  262. });
  263. return acc;
  264. };
  265. var foldl = function (xs, f, acc) {
  266. each(xs, function (x) {
  267. acc = f(acc, x);
  268. });
  269. return acc;
  270. };
  271. var find = function (xs, pred) {
  272. for (var i = 0, len = xs.length; i < len; i++) {
  273. var x = xs[i];
  274. if (pred(x, i)) {
  275. return Option.some(x);
  276. }
  277. }
  278. return Option.none();
  279. };
  280. var findIndex = function (xs, pred) {
  281. for (var i = 0, len = xs.length; i < len; i++) {
  282. var x = xs[i];
  283. if (pred(x, i)) {
  284. return Option.some(i);
  285. }
  286. }
  287. return Option.none();
  288. };
  289. var flatten = function (xs) {
  290. var r = [];
  291. for (var i = 0, len = xs.length; i < len; ++i) {
  292. if (!isArray(xs[i])) {
  293. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  294. }
  295. nativePush.apply(r, xs[i]);
  296. }
  297. return r;
  298. };
  299. var bind = function (xs, f) {
  300. var output = map(xs, f);
  301. return flatten(output);
  302. };
  303. var forall = function (xs, pred) {
  304. for (var i = 0, len = xs.length; i < len; ++i) {
  305. var x = xs[i];
  306. if (pred(x, i) !== true) {
  307. return false;
  308. }
  309. }
  310. return true;
  311. };
  312. var reverse = function (xs) {
  313. var r = nativeSlice.call(xs, 0);
  314. r.reverse();
  315. return r;
  316. };
  317. var difference = function (a1, a2) {
  318. return filter(a1, function (x) {
  319. return !contains(a2, x);
  320. });
  321. };
  322. var mapToObject = function (xs, f) {
  323. var r = {};
  324. for (var i = 0, len = xs.length; i < len; i++) {
  325. var x = xs[i];
  326. r[String(x)] = f(x, i);
  327. }
  328. return r;
  329. };
  330. var sort = function (xs, comparator) {
  331. var copy = nativeSlice.call(xs, 0);
  332. copy.sort(comparator);
  333. return copy;
  334. };
  335. var head = function (xs) {
  336. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  337. };
  338. var last = function (xs) {
  339. return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
  340. };
  341. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  342. return nativeSlice.call(x);
  343. };
  344. var __assign = function () {
  345. __assign = Object.assign || function __assign(t) {
  346. for (var s, i = 1, n = arguments.length; i < n; i++) {
  347. s = arguments[i];
  348. for (var p in s)
  349. if (Object.prototype.hasOwnProperty.call(s, p))
  350. t[p] = s[p];
  351. }
  352. return t;
  353. };
  354. return __assign.apply(this, arguments);
  355. };
  356. function __rest(s, e) {
  357. var t = {};
  358. for (var p in s)
  359. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  360. t[p] = s[p];
  361. if (s != null && typeof Object.getOwnPropertySymbols === 'function')
  362. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  363. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  364. t[p[i]] = s[p[i]];
  365. }
  366. return t;
  367. }
  368. var isNodeType = function (type) {
  369. return function (node) {
  370. return !!node && node.nodeType === type;
  371. };
  372. };
  373. var isRestrictedNode = function (node) {
  374. return !!node && !Object.getPrototypeOf(node);
  375. };
  376. var isElement = isNodeType(1);
  377. var matchNodeNames = function (names) {
  378. var lowercasedNames = names.map(function (s) {
  379. return s.toLowerCase();
  380. });
  381. return function (node) {
  382. if (node && node.nodeName) {
  383. var nodeName = node.nodeName.toLowerCase();
  384. return contains(lowercasedNames, nodeName);
  385. }
  386. return false;
  387. };
  388. };
  389. var matchStyleValues = function (name, values) {
  390. var items = values.toLowerCase().split(' ');
  391. return function (node) {
  392. var i, cssValue;
  393. if (isElement(node)) {
  394. for (i = 0; i < items.length; i++) {
  395. var computed = node.ownerDocument.defaultView.getComputedStyle(node, null);
  396. cssValue = computed ? computed.getPropertyValue(name) : null;
  397. if (cssValue === items[i]) {
  398. return true;
  399. }
  400. }
  401. }
  402. return false;
  403. };
  404. };
  405. var hasPropValue = function (propName, propValue) {
  406. return function (node) {
  407. return isElement(node) && node[propName] === propValue;
  408. };
  409. };
  410. var hasAttribute = function (attrName, attrValue) {
  411. return function (node) {
  412. return isElement(node) && node.hasAttribute(attrName);
  413. };
  414. };
  415. var hasAttributeValue = function (attrName, attrValue) {
  416. return function (node) {
  417. return isElement(node) && node.getAttribute(attrName) === attrValue;
  418. };
  419. };
  420. var isBogus = function (node) {
  421. return isElement(node) && node.hasAttribute('data-mce-bogus');
  422. };
  423. var isBogusAll = function (node) {
  424. return isElement(node) && node.getAttribute('data-mce-bogus') === 'all';
  425. };
  426. var isTable = function (node) {
  427. return isElement(node) && node.tagName === 'TABLE';
  428. };
  429. var hasContentEditableState = function (value) {
  430. return function (node) {
  431. if (isElement(node)) {
  432. if (node.contentEditable === value) {
  433. return true;
  434. }
  435. if (node.getAttribute('data-mce-contenteditable') === value) {
  436. return true;
  437. }
  438. }
  439. return false;
  440. };
  441. };
  442. var isTextareaOrInput = matchNodeNames([
  443. 'textarea',
  444. 'input'
  445. ]);
  446. var isText = isNodeType(3);
  447. var isComment = isNodeType(8);
  448. var isDocument = isNodeType(9);
  449. var isDocumentFragment = isNodeType(11);
  450. var isBr = matchNodeNames(['br']);
  451. var isContentEditableTrue = hasContentEditableState('true');
  452. var isContentEditableFalse = hasContentEditableState('false');
  453. var NodeType = {
  454. isText: isText,
  455. isElement: isElement,
  456. isComment: isComment,
  457. isDocument: isDocument,
  458. isDocumentFragment: isDocumentFragment,
  459. isBr: isBr,
  460. isContentEditableTrue: isContentEditableTrue,
  461. isContentEditableFalse: isContentEditableFalse,
  462. isRestrictedNode: isRestrictedNode,
  463. matchNodeNames: matchNodeNames,
  464. hasPropValue: hasPropValue,
  465. hasAttribute: hasAttribute,
  466. hasAttributeValue: hasAttributeValue,
  467. matchStyleValues: matchStyleValues,
  468. isBogus: isBogus,
  469. isBogusAll: isBogusAll,
  470. isTable: isTable,
  471. isTextareaOrInput: isTextareaOrInput
  472. };
  473. var Cell = function (initial) {
  474. var value = initial;
  475. var get = function () {
  476. return value;
  477. };
  478. var set = function (v) {
  479. value = v;
  480. };
  481. var clone = function () {
  482. return Cell(get());
  483. };
  484. return {
  485. get: get,
  486. set: set,
  487. clone: clone
  488. };
  489. };
  490. var firstMatch = function (regexes, s) {
  491. for (var i = 0; i < regexes.length; i++) {
  492. var x = regexes[i];
  493. if (x.test(s)) {
  494. return x;
  495. }
  496. }
  497. return undefined;
  498. };
  499. var find$1 = function (regexes, agent) {
  500. var r = firstMatch(regexes, agent);
  501. if (!r) {
  502. return {
  503. major: 0,
  504. minor: 0
  505. };
  506. }
  507. var group = function (i) {
  508. return Number(agent.replace(r, '$' + i));
  509. };
  510. return nu(group(1), group(2));
  511. };
  512. var detect = function (versionRegexes, agent) {
  513. var cleanedAgent = String(agent).toLowerCase();
  514. if (versionRegexes.length === 0) {
  515. return unknown();
  516. }
  517. return find$1(versionRegexes, cleanedAgent);
  518. };
  519. var unknown = function () {
  520. return nu(0, 0);
  521. };
  522. var nu = function (major, minor) {
  523. return {
  524. major: major,
  525. minor: minor
  526. };
  527. };
  528. var Version = {
  529. nu: nu,
  530. detect: detect,
  531. unknown: unknown
  532. };
  533. var edge = 'Edge';
  534. var chrome = 'Chrome';
  535. var ie = 'IE';
  536. var opera = 'Opera';
  537. var firefox = 'Firefox';
  538. var safari = 'Safari';
  539. var isBrowser = function (name, current) {
  540. return function () {
  541. return current === name;
  542. };
  543. };
  544. var unknown$1 = function () {
  545. return nu$1({
  546. current: undefined,
  547. version: Version.unknown()
  548. });
  549. };
  550. var nu$1 = function (info) {
  551. var current = info.current;
  552. var version = info.version;
  553. return {
  554. current: current,
  555. version: version,
  556. isEdge: isBrowser(edge, current),
  557. isChrome: isBrowser(chrome, current),
  558. isIE: isBrowser(ie, current),
  559. isOpera: isBrowser(opera, current),
  560. isFirefox: isBrowser(firefox, current),
  561. isSafari: isBrowser(safari, current)
  562. };
  563. };
  564. var Browser = {
  565. unknown: unknown$1,
  566. nu: nu$1,
  567. edge: constant(edge),
  568. chrome: constant(chrome),
  569. ie: constant(ie),
  570. opera: constant(opera),
  571. firefox: constant(firefox),
  572. safari: constant(safari)
  573. };
  574. var windows = 'Windows';
  575. var ios = 'iOS';
  576. var android = 'Android';
  577. var linux = 'Linux';
  578. var osx = 'OSX';
  579. var solaris = 'Solaris';
  580. var freebsd = 'FreeBSD';
  581. var isOS = function (name, current) {
  582. return function () {
  583. return current === name;
  584. };
  585. };
  586. var unknown$2 = function () {
  587. return nu$2({
  588. current: undefined,
  589. version: Version.unknown()
  590. });
  591. };
  592. var nu$2 = function (info) {
  593. var current = info.current;
  594. var version = info.version;
  595. return {
  596. current: current,
  597. version: version,
  598. isWindows: isOS(windows, current),
  599. isiOS: isOS(ios, current),
  600. isAndroid: isOS(android, current),
  601. isOSX: isOS(osx, current),
  602. isLinux: isOS(linux, current),
  603. isSolaris: isOS(solaris, current),
  604. isFreeBSD: isOS(freebsd, current)
  605. };
  606. };
  607. var OperatingSystem = {
  608. unknown: unknown$2,
  609. nu: nu$2,
  610. windows: constant(windows),
  611. ios: constant(ios),
  612. android: constant(android),
  613. linux: constant(linux),
  614. osx: constant(osx),
  615. solaris: constant(solaris),
  616. freebsd: constant(freebsd)
  617. };
  618. var DeviceType = function (os, browser, userAgent, mediaMatch) {
  619. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  620. var isiPhone = os.isiOS() && !isiPad;
  621. var isMobile = os.isiOS() || os.isAndroid();
  622. var isTouch = isMobile || mediaMatch('(pointer:coarse)');
  623. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
  624. var isPhone = isiPhone || isMobile && !isTablet;
  625. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  626. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  627. return {
  628. isiPad: constant(isiPad),
  629. isiPhone: constant(isiPhone),
  630. isTablet: constant(isTablet),
  631. isPhone: constant(isPhone),
  632. isTouch: constant(isTouch),
  633. isAndroid: os.isAndroid,
  634. isiOS: os.isiOS,
  635. isWebView: constant(iOSwebview),
  636. isDesktop: constant(isDesktop)
  637. };
  638. };
  639. var detect$1 = function (candidates, userAgent) {
  640. var agent = String(userAgent).toLowerCase();
  641. return find(candidates, function (candidate) {
  642. return candidate.search(agent);
  643. });
  644. };
  645. var detectBrowser = function (browsers, userAgent) {
  646. return detect$1(browsers, userAgent).map(function (browser) {
  647. var version = Version.detect(browser.versionRegexes, userAgent);
  648. return {
  649. current: browser.name,
  650. version: version
  651. };
  652. });
  653. };
  654. var detectOs = function (oses, userAgent) {
  655. return detect$1(oses, userAgent).map(function (os) {
  656. var version = Version.detect(os.versionRegexes, userAgent);
  657. return {
  658. current: os.name,
  659. version: version
  660. };
  661. });
  662. };
  663. var UaString = {
  664. detectBrowser: detectBrowser,
  665. detectOs: detectOs
  666. };
  667. var checkRange = function (str, substr, start) {
  668. if (substr === '') {
  669. return true;
  670. }
  671. if (str.length < substr.length) {
  672. return false;
  673. }
  674. var x = str.substr(start, start + substr.length);
  675. return x === substr;
  676. };
  677. var contains$1 = function (str, substr) {
  678. return str.indexOf(substr) !== -1;
  679. };
  680. var startsWith = function (str, prefix) {
  681. return checkRange(str, prefix, 0);
  682. };
  683. var trim = function (str) {
  684. return str.replace(/^\s+|\s+$/g, '');
  685. };
  686. var lTrim = function (str) {
  687. return str.replace(/^\s+/g, '');
  688. };
  689. var rTrim = function (str) {
  690. return str.replace(/\s+$/g, '');
  691. };
  692. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  693. var checkContains = function (target) {
  694. return function (uastring) {
  695. return contains$1(uastring, target);
  696. };
  697. };
  698. var browsers = [
  699. {
  700. name: 'Edge',
  701. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  702. search: function (uastring) {
  703. return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
  704. }
  705. },
  706. {
  707. name: 'Chrome',
  708. versionRegexes: [
  709. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  710. normalVersionRegex
  711. ],
  712. search: function (uastring) {
  713. return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
  714. }
  715. },
  716. {
  717. name: 'IE',
  718. versionRegexes: [
  719. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  720. /.*?rv:([0-9]+)\.([0-9]+).*/
  721. ],
  722. search: function (uastring) {
  723. return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
  724. }
  725. },
  726. {
  727. name: 'Opera',
  728. versionRegexes: [
  729. normalVersionRegex,
  730. /.*?opera\/([0-9]+)\.([0-9]+).*/
  731. ],
  732. search: checkContains('opera')
  733. },
  734. {
  735. name: 'Firefox',
  736. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  737. search: checkContains('firefox')
  738. },
  739. {
  740. name: 'Safari',
  741. versionRegexes: [
  742. normalVersionRegex,
  743. /.*?cpu os ([0-9]+)_([0-9]+).*/
  744. ],
  745. search: function (uastring) {
  746. return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
  747. }
  748. }
  749. ];
  750. var oses = [
  751. {
  752. name: 'Windows',
  753. search: checkContains('win'),
  754. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  755. },
  756. {
  757. name: 'iOS',
  758. search: function (uastring) {
  759. return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
  760. },
  761. versionRegexes: [
  762. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  763. /.*cpu os ([0-9]+)_([0-9]+).*/,
  764. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  765. ]
  766. },
  767. {
  768. name: 'Android',
  769. search: checkContains('android'),
  770. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  771. },
  772. {
  773. name: 'OSX',
  774. search: checkContains('os x'),
  775. versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
  776. },
  777. {
  778. name: 'Linux',
  779. search: checkContains('linux'),
  780. versionRegexes: []
  781. },
  782. {
  783. name: 'Solaris',
  784. search: checkContains('sunos'),
  785. versionRegexes: []
  786. },
  787. {
  788. name: 'FreeBSD',
  789. search: checkContains('freebsd'),
  790. versionRegexes: []
  791. }
  792. ];
  793. var PlatformInfo = {
  794. browsers: constant(browsers),
  795. oses: constant(oses)
  796. };
  797. var detect$2 = function (userAgent, mediaMatch) {
  798. var browsers = PlatformInfo.browsers();
  799. var oses = PlatformInfo.oses();
  800. var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
  801. var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  802. var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
  803. return {
  804. browser: browser,
  805. os: os,
  806. deviceType: deviceType
  807. };
  808. };
  809. var PlatformDetection = { detect: detect$2 };
  810. var mediaMatch = function (query) {
  811. return domGlobals.window.matchMedia(query).matches;
  812. };
  813. var platform = Cell(PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch));
  814. var detect$3 = function () {
  815. return platform.get();
  816. };
  817. var fromHtml = function (html, scope) {
  818. var doc = scope || domGlobals.document;
  819. var div = doc.createElement('div');
  820. div.innerHTML = html;
  821. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  822. domGlobals.console.error('HTML does not have a single root node', html);
  823. throw new Error('HTML must have a single root node');
  824. }
  825. return fromDom(div.childNodes[0]);
  826. };
  827. var fromTag = function (tag, scope) {
  828. var doc = scope || domGlobals.document;
  829. var node = doc.createElement(tag);
  830. return fromDom(node);
  831. };
  832. var fromText = function (text, scope) {
  833. var doc = scope || domGlobals.document;
  834. var node = doc.createTextNode(text);
  835. return fromDom(node);
  836. };
  837. var fromDom = function (node) {
  838. if (node === null || node === undefined) {
  839. throw new Error('Node cannot be null or undefined');
  840. }
  841. return { dom: constant(node) };
  842. };
  843. var fromPoint = function (docElm, x, y) {
  844. var doc = docElm.dom();
  845. return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
  846. };
  847. var Element = {
  848. fromHtml: fromHtml,
  849. fromTag: fromTag,
  850. fromText: fromText,
  851. fromDom: fromDom,
  852. fromPoint: fromPoint
  853. };
  854. var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
  855. var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
  856. var COMMENT = domGlobals.Node.COMMENT_NODE;
  857. var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
  858. var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
  859. var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
  860. var ELEMENT = domGlobals.Node.ELEMENT_NODE;
  861. var TEXT = domGlobals.Node.TEXT_NODE;
  862. var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
  863. var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
  864. var ENTITY = domGlobals.Node.ENTITY_NODE;
  865. var NOTATION = domGlobals.Node.NOTATION_NODE;
  866. var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
  867. var name = function (element) {
  868. var r = element.dom().nodeName;
  869. return r.toLowerCase();
  870. };
  871. var type = function (element) {
  872. return element.dom().nodeType;
  873. };
  874. var isType$1 = function (t) {
  875. return function (element) {
  876. return type(element) === t;
  877. };
  878. };
  879. var isElement$1 = isType$1(ELEMENT);
  880. var isText$1 = isType$1(TEXT);
  881. var keys = Object.keys;
  882. var hasOwnProperty = Object.hasOwnProperty;
  883. var each$1 = function (obj, f) {
  884. var props = keys(obj);
  885. for (var k = 0, len = props.length; k < len; k++) {
  886. var i = props[k];
  887. var x = obj[i];
  888. f(x, i);
  889. }
  890. };
  891. var map$1 = function (obj, f) {
  892. return tupleMap(obj, function (x, i) {
  893. return {
  894. k: i,
  895. v: f(x, i)
  896. };
  897. });
  898. };
  899. var tupleMap = function (obj, f) {
  900. var r = {};
  901. each$1(obj, function (x, i) {
  902. var tuple = f(x, i);
  903. r[tuple.k] = tuple.v;
  904. });
  905. return r;
  906. };
  907. var bifilter = function (obj, pred) {
  908. var t = {};
  909. var f = {};
  910. each$1(obj, function (x, i) {
  911. var branch = pred(x, i) ? t : f;
  912. branch[i] = x;
  913. });
  914. return {
  915. t: t,
  916. f: f
  917. };
  918. };
  919. var get = function (obj, key) {
  920. return has(obj, key) ? Option.from(obj[key]) : Option.none();
  921. };
  922. var has = function (obj, key) {
  923. return hasOwnProperty.call(obj, key);
  924. };
  925. var isSupported = function (dom) {
  926. return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
  927. };
  928. var inBody = function (element) {
  929. var dom = isText$1(element) ? element.dom().parentNode : element.dom();
  930. return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
  931. };
  932. var rawSet = function (dom, key, value) {
  933. if (isString(value) || isBoolean(value) || isNumber(value)) {
  934. dom.setAttribute(key, value + '');
  935. } else {
  936. domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  937. throw new Error('Attribute value was not simple');
  938. }
  939. };
  940. var set = function (element, key, value) {
  941. rawSet(element.dom(), key, value);
  942. };
  943. var setAll = function (element, attrs) {
  944. var dom = element.dom();
  945. each$1(attrs, function (v, k) {
  946. rawSet(dom, k, v);
  947. });
  948. };
  949. var get$1 = function (element, key) {
  950. var v = element.dom().getAttribute(key);
  951. return v === null ? undefined : v;
  952. };
  953. var has$1 = function (element, key) {
  954. var dom = element.dom();
  955. return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
  956. };
  957. var remove = function (element, key) {
  958. element.dom().removeAttribute(key);
  959. };
  960. var get$2 = function (element, property) {
  961. var dom = element.dom();
  962. var styles = domGlobals.window.getComputedStyle(dom);
  963. var r = styles.getPropertyValue(property);
  964. var v = r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
  965. return v === null ? undefined : v;
  966. };
  967. var getUnsafeProperty = function (dom, property) {
  968. return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
  969. };
  970. var getRaw = function (element, property) {
  971. var dom = element.dom();
  972. var raw = getUnsafeProperty(dom, property);
  973. return Option.from(raw).filter(function (r) {
  974. return r.length > 0;
  975. });
  976. };
  977. var reflow = function (e) {
  978. return e.dom().offsetWidth;
  979. };
  980. var Immutable = function () {
  981. var fields = [];
  982. for (var _i = 0; _i < arguments.length; _i++) {
  983. fields[_i] = arguments[_i];
  984. }
  985. return function () {
  986. var values = [];
  987. for (var _i = 0; _i < arguments.length; _i++) {
  988. values[_i] = arguments[_i];
  989. }
  990. if (fields.length !== values.length) {
  991. throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
  992. }
  993. var struct = {};
  994. each(fields, function (name, i) {
  995. struct[name] = constant(values[i]);
  996. });
  997. return struct;
  998. };
  999. };
  1000. var toArray = function (target, f) {
  1001. var r = [];
  1002. var recurse = function (e) {
  1003. r.push(e);
  1004. return f(e);
  1005. };
  1006. var cur = f(target);
  1007. do {
  1008. cur = cur.bind(recurse);
  1009. } while (cur.isSome());
  1010. return r;
  1011. };
  1012. var Recurse = { toArray: toArray };
  1013. var compareDocumentPosition = function (a, b, match) {
  1014. return (a.compareDocumentPosition(b) & match) !== 0;
  1015. };
  1016. var documentPositionPreceding = function (a, b) {
  1017. return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_PRECEDING);
  1018. };
  1019. var documentPositionContainedBy = function (a, b) {
  1020. return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
  1021. };
  1022. var Node = {
  1023. documentPositionPreceding: documentPositionPreceding,
  1024. documentPositionContainedBy: documentPositionContainedBy
  1025. };
  1026. var ELEMENT$1 = ELEMENT;
  1027. var DOCUMENT$1 = DOCUMENT;
  1028. var is = function (element, selector) {
  1029. var dom = element.dom();
  1030. if (dom.nodeType !== ELEMENT$1) {
  1031. return false;
  1032. } else {
  1033. var elem = dom;
  1034. if (elem.matches !== undefined) {
  1035. return elem.matches(selector);
  1036. } else if (elem.msMatchesSelector !== undefined) {
  1037. return elem.msMatchesSelector(selector);
  1038. } else if (elem.webkitMatchesSelector !== undefined) {
  1039. return elem.webkitMatchesSelector(selector);
  1040. } else if (elem.mozMatchesSelector !== undefined) {
  1041. return elem.mozMatchesSelector(selector);
  1042. } else {
  1043. throw new Error('Browser lacks native selectors');
  1044. }
  1045. }
  1046. };
  1047. var bypassSelector = function (dom) {
  1048. return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
  1049. };
  1050. var all = function (selector, scope) {
  1051. var base = scope === undefined ? domGlobals.document : scope.dom();
  1052. return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
  1053. };
  1054. var one = function (selector, scope) {
  1055. var base = scope === undefined ? domGlobals.document : scope.dom();
  1056. return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
  1057. };
  1058. var eq = function (e1, e2) {
  1059. return e1.dom() === e2.dom();
  1060. };
  1061. var regularContains = function (e1, e2) {
  1062. var d1 = e1.dom();
  1063. var d2 = e2.dom();
  1064. return d1 === d2 ? false : d1.contains(d2);
  1065. };
  1066. var ieContains = function (e1, e2) {
  1067. return Node.documentPositionContainedBy(e1.dom(), e2.dom());
  1068. };
  1069. var browser = detect$3().browser;
  1070. var contains$2 = browser.isIE() ? ieContains : regularContains;
  1071. var owner = function (element) {
  1072. return Element.fromDom(element.dom().ownerDocument);
  1073. };
  1074. var documentElement = function (element) {
  1075. return Element.fromDom(element.dom().ownerDocument.documentElement);
  1076. };
  1077. var defaultView = function (element) {
  1078. return Element.fromDom(element.dom().ownerDocument.defaultView);
  1079. };
  1080. var parent = function (element) {
  1081. return Option.from(element.dom().parentNode).map(Element.fromDom);
  1082. };
  1083. var parents = function (element, isRoot) {
  1084. var stop = isFunction(isRoot) ? isRoot : never;
  1085. var dom = element.dom();
  1086. var ret = [];
  1087. while (dom.parentNode !== null && dom.parentNode !== undefined) {
  1088. var rawParent = dom.parentNode;
  1089. var p = Element.fromDom(rawParent);
  1090. ret.push(p);
  1091. if (stop(p) === true) {
  1092. break;
  1093. } else {
  1094. dom = rawParent;
  1095. }
  1096. }
  1097. return ret;
  1098. };
  1099. var prevSibling = function (element) {
  1100. return Option.from(element.dom().previousSibling).map(Element.fromDom);
  1101. };
  1102. var nextSibling = function (element) {
  1103. return Option.from(element.dom().nextSibling).map(Element.fromDom);
  1104. };
  1105. var prevSiblings = function (element) {
  1106. return reverse(Recurse.toArray(element, prevSibling));
  1107. };
  1108. var nextSiblings = function (element) {
  1109. return Recurse.toArray(element, nextSibling);
  1110. };
  1111. var children = function (element) {
  1112. return map(element.dom().childNodes, Element.fromDom);
  1113. };
  1114. var child = function (element, index) {
  1115. var cs = element.dom().childNodes;
  1116. return Option.from(cs[index]).map(Element.fromDom);
  1117. };
  1118. var firstChild = function (element) {
  1119. return child(element, 0);
  1120. };
  1121. var lastChild = function (element) {
  1122. return child(element, element.dom().childNodes.length - 1);
  1123. };
  1124. var childNodesCount = function (element) {
  1125. return element.dom().childNodes.length;
  1126. };
  1127. var spot = Immutable('element', 'offset');
  1128. var browser$1 = detect$3().browser;
  1129. var firstElement = function (nodes) {
  1130. return find(nodes, isElement$1);
  1131. };
  1132. var getTableCaptionDeltaY = function (elm) {
  1133. if (browser$1.isFirefox() && name(elm) === 'table') {
  1134. return firstElement(children(elm)).filter(function (elm) {
  1135. return name(elm) === 'caption';
  1136. }).bind(function (caption) {
  1137. return firstElement(nextSiblings(caption)).map(function (body) {
  1138. var bodyTop = body.dom().offsetTop;
  1139. var captionTop = caption.dom().offsetTop;
  1140. var captionHeight = caption.dom().offsetHeight;
  1141. return bodyTop <= captionTop ? -captionHeight : 0;
  1142. });
  1143. }).getOr(0);
  1144. } else {
  1145. return 0;
  1146. }
  1147. };
  1148. var hasChild = function (elm, child) {
  1149. return elm.children && contains(elm.children, child);
  1150. };
  1151. var getPos = function (body, elm, rootElm) {
  1152. var x = 0, y = 0, offsetParent;
  1153. var doc = body.ownerDocument;
  1154. var pos;
  1155. rootElm = rootElm ? rootElm : body;
  1156. if (elm) {
  1157. if (rootElm === body && elm.getBoundingClientRect && get$2(Element.fromDom(body), 'position') === 'static') {
  1158. pos = elm.getBoundingClientRect();
  1159. x = pos.left + (doc.documentElement.scrollLeft || body.scrollLeft) - doc.documentElement.clientLeft;
  1160. y = pos.top + (doc.documentElement.scrollTop || body.scrollTop) - doc.documentElement.clientTop;
  1161. return {
  1162. x: x,
  1163. y: y
  1164. };
  1165. }
  1166. offsetParent = elm;
  1167. while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
  1168. x += offsetParent.offsetLeft || 0;
  1169. y += offsetParent.offsetTop || 0;
  1170. offsetParent = offsetParent.offsetParent;
  1171. }
  1172. offsetParent = elm.parentNode;
  1173. while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
  1174. x -= offsetParent.scrollLeft || 0;
  1175. y -= offsetParent.scrollTop || 0;
  1176. offsetParent = offsetParent.parentNode;
  1177. }
  1178. y += getTableCaptionDeltaY(Element.fromDom(elm));
  1179. }
  1180. return {
  1181. x: x,
  1182. y: y
  1183. };
  1184. };
  1185. var Position = { getPos: getPos };
  1186. var exports$1 = {}, module$1 = { exports: exports$1 };
  1187. (function (define, exports, module, require) {
  1188. (function (f) {
  1189. if (typeof exports === 'object' && typeof module !== 'undefined') {
  1190. module.exports = f();
  1191. } else if (typeof define === 'function' && define.amd) {
  1192. define([], f);
  1193. } else {
  1194. var g;
  1195. if (typeof window !== 'undefined') {
  1196. g = window;
  1197. } else if (typeof global !== 'undefined') {
  1198. g = global;
  1199. } else if (typeof self !== 'undefined') {
  1200. g = self;
  1201. } else {
  1202. g = this;
  1203. }
  1204. g.EphoxContactWrapper = f();
  1205. }
  1206. }(function () {
  1207. return function () {
  1208. function r(e, n, t) {
  1209. function o(i, f) {
  1210. if (!n[i]) {
  1211. if (!e[i]) {
  1212. var c = 'function' == typeof require && require;
  1213. if (!f && c)
  1214. return c(i, !0);
  1215. if (u)
  1216. return u(i, !0);
  1217. var a = new Error('Cannot find module \'' + i + '\'');
  1218. throw a.code = 'MODULE_NOT_FOUND', a;
  1219. }
  1220. var p = n[i] = { exports: {} };
  1221. e[i][0].call(p.exports, function (r) {
  1222. var n = e[i][1][r];
  1223. return o(n || r);
  1224. }, p, p.exports, r, e, n, t);
  1225. }
  1226. return n[i].exports;
  1227. }
  1228. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  1229. o(t[i]);
  1230. return o;
  1231. }
  1232. return r;
  1233. }()({
  1234. 1: [
  1235. function (require, module, exports) {
  1236. var process = module.exports = {};
  1237. var cachedSetTimeout;
  1238. var cachedClearTimeout;
  1239. function defaultSetTimout() {
  1240. throw new Error('setTimeout has not been defined');
  1241. }
  1242. function defaultClearTimeout() {
  1243. throw new Error('clearTimeout has not been defined');
  1244. }
  1245. (function () {
  1246. try {
  1247. if (typeof setTimeout === 'function') {
  1248. cachedSetTimeout = setTimeout;
  1249. } else {
  1250. cachedSetTimeout = defaultSetTimout;
  1251. }
  1252. } catch (e) {
  1253. cachedSetTimeout = defaultSetTimout;
  1254. }
  1255. try {
  1256. if (typeof clearTimeout === 'function') {
  1257. cachedClearTimeout = clearTimeout;
  1258. } else {
  1259. cachedClearTimeout = defaultClearTimeout;
  1260. }
  1261. } catch (e) {
  1262. cachedClearTimeout = defaultClearTimeout;
  1263. }
  1264. }());
  1265. function runTimeout(fun) {
  1266. if (cachedSetTimeout === setTimeout) {
  1267. return setTimeout(fun, 0);
  1268. }
  1269. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1270. cachedSetTimeout = setTimeout;
  1271. return setTimeout(fun, 0);
  1272. }
  1273. try {
  1274. return cachedSetTimeout(fun, 0);
  1275. } catch (e) {
  1276. try {
  1277. return cachedSetTimeout.call(null, fun, 0);
  1278. } catch (e) {
  1279. return cachedSetTimeout.call(this, fun, 0);
  1280. }
  1281. }
  1282. }
  1283. function runClearTimeout(marker) {
  1284. if (cachedClearTimeout === clearTimeout) {
  1285. return clearTimeout(marker);
  1286. }
  1287. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1288. cachedClearTimeout = clearTimeout;
  1289. return clearTimeout(marker);
  1290. }
  1291. try {
  1292. return cachedClearTimeout(marker);
  1293. } catch (e) {
  1294. try {
  1295. return cachedClearTimeout.call(null, marker);
  1296. } catch (e) {
  1297. return cachedClearTimeout.call(this, marker);
  1298. }
  1299. }
  1300. }
  1301. var queue = [];
  1302. var draining = false;
  1303. var currentQueue;
  1304. var queueIndex = -1;
  1305. function cleanUpNextTick() {
  1306. if (!draining || !currentQueue) {
  1307. return;
  1308. }
  1309. draining = false;
  1310. if (currentQueue.length) {
  1311. queue = currentQueue.concat(queue);
  1312. } else {
  1313. queueIndex = -1;
  1314. }
  1315. if (queue.length) {
  1316. drainQueue();
  1317. }
  1318. }
  1319. function drainQueue() {
  1320. if (draining) {
  1321. return;
  1322. }
  1323. var timeout = runTimeout(cleanUpNextTick);
  1324. draining = true;
  1325. var len = queue.length;
  1326. while (len) {
  1327. currentQueue = queue;
  1328. queue = [];
  1329. while (++queueIndex < len) {
  1330. if (currentQueue) {
  1331. currentQueue[queueIndex].run();
  1332. }
  1333. }
  1334. queueIndex = -1;
  1335. len = queue.length;
  1336. }
  1337. currentQueue = null;
  1338. draining = false;
  1339. runClearTimeout(timeout);
  1340. }
  1341. process.nextTick = function (fun) {
  1342. var args = new Array(arguments.length - 1);
  1343. if (arguments.length > 1) {
  1344. for (var i = 1; i < arguments.length; i++) {
  1345. args[i - 1] = arguments[i];
  1346. }
  1347. }
  1348. queue.push(new Item(fun, args));
  1349. if (queue.length === 1 && !draining) {
  1350. runTimeout(drainQueue);
  1351. }
  1352. };
  1353. function Item(fun, array) {
  1354. this.fun = fun;
  1355. this.array = array;
  1356. }
  1357. Item.prototype.run = function () {
  1358. this.fun.apply(null, this.array);
  1359. };
  1360. process.title = 'browser';
  1361. process.browser = true;
  1362. process.env = {};
  1363. process.argv = [];
  1364. process.version = '';
  1365. process.versions = {};
  1366. function noop() {
  1367. }
  1368. process.on = noop;
  1369. process.addListener = noop;
  1370. process.once = noop;
  1371. process.off = noop;
  1372. process.removeListener = noop;
  1373. process.removeAllListeners = noop;
  1374. process.emit = noop;
  1375. process.prependListener = noop;
  1376. process.prependOnceListener = noop;
  1377. process.listeners = function (name) {
  1378. return [];
  1379. };
  1380. process.binding = function (name) {
  1381. throw new Error('process.binding is not supported');
  1382. };
  1383. process.cwd = function () {
  1384. return '/';
  1385. };
  1386. process.chdir = function (dir) {
  1387. throw new Error('process.chdir is not supported');
  1388. };
  1389. process.umask = function () {
  1390. return 0;
  1391. };
  1392. },
  1393. {}
  1394. ],
  1395. 2: [
  1396. function (require, module, exports) {
  1397. (function (setImmediate) {
  1398. (function (root) {
  1399. var setTimeoutFunc = setTimeout;
  1400. function noop() {
  1401. }
  1402. function bind(fn, thisArg) {
  1403. return function () {
  1404. fn.apply(thisArg, arguments);
  1405. };
  1406. }
  1407. function Promise(fn) {
  1408. if (typeof this !== 'object')
  1409. throw new TypeError('Promises must be constructed via new');
  1410. if (typeof fn !== 'function')
  1411. throw new TypeError('not a function');
  1412. this._state = 0;
  1413. this._handled = false;
  1414. this._value = undefined;
  1415. this._deferreds = [];
  1416. doResolve(fn, this);
  1417. }
  1418. function handle(self, deferred) {
  1419. while (self._state === 3) {
  1420. self = self._value;
  1421. }
  1422. if (self._state === 0) {
  1423. self._deferreds.push(deferred);
  1424. return;
  1425. }
  1426. self._handled = true;
  1427. Promise._immediateFn(function () {
  1428. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  1429. if (cb === null) {
  1430. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  1431. return;
  1432. }
  1433. var ret;
  1434. try {
  1435. ret = cb(self._value);
  1436. } catch (e) {
  1437. reject(deferred.promise, e);
  1438. return;
  1439. }
  1440. resolve(deferred.promise, ret);
  1441. });
  1442. }
  1443. function resolve(self, newValue) {
  1444. try {
  1445. if (newValue === self)
  1446. throw new TypeError('A promise cannot be resolved with itself.');
  1447. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  1448. var then = newValue.then;
  1449. if (newValue instanceof Promise) {
  1450. self._state = 3;
  1451. self._value = newValue;
  1452. finale(self);
  1453. return;
  1454. } else if (typeof then === 'function') {
  1455. doResolve(bind(then, newValue), self);
  1456. return;
  1457. }
  1458. }
  1459. self._state = 1;
  1460. self._value = newValue;
  1461. finale(self);
  1462. } catch (e) {
  1463. reject(self, e);
  1464. }
  1465. }
  1466. function reject(self, newValue) {
  1467. self._state = 2;
  1468. self._value = newValue;
  1469. finale(self);
  1470. }
  1471. function finale(self) {
  1472. if (self._state === 2 && self._deferreds.length === 0) {
  1473. Promise._immediateFn(function () {
  1474. if (!self._handled) {
  1475. Promise._unhandledRejectionFn(self._value);
  1476. }
  1477. });
  1478. }
  1479. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  1480. handle(self, self._deferreds[i]);
  1481. }
  1482. self._deferreds = null;
  1483. }
  1484. function Handler(onFulfilled, onRejected, promise) {
  1485. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  1486. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  1487. this.promise = promise;
  1488. }
  1489. function doResolve(fn, self) {
  1490. var done = false;
  1491. try {
  1492. fn(function (value) {
  1493. if (done)
  1494. return;
  1495. done = true;
  1496. resolve(self, value);
  1497. }, function (reason) {
  1498. if (done)
  1499. return;
  1500. done = true;
  1501. reject(self, reason);
  1502. });
  1503. } catch (ex) {
  1504. if (done)
  1505. return;
  1506. done = true;
  1507. reject(self, ex);
  1508. }
  1509. }
  1510. Promise.prototype['catch'] = function (onRejected) {
  1511. return this.then(null, onRejected);
  1512. };
  1513. Promise.prototype.then = function (onFulfilled, onRejected) {
  1514. var prom = new this.constructor(noop);
  1515. handle(this, new Handler(onFulfilled, onRejected, prom));
  1516. return prom;
  1517. };
  1518. Promise.all = function (arr) {
  1519. var args = Array.prototype.slice.call(arr);
  1520. return new Promise(function (resolve, reject) {
  1521. if (args.length === 0)
  1522. return resolve([]);
  1523. var remaining = args.length;
  1524. function res(i, val) {
  1525. try {
  1526. if (val && (typeof val === 'object' || typeof val === 'function')) {
  1527. var then = val.then;
  1528. if (typeof then === 'function') {
  1529. then.call(val, function (val) {
  1530. res(i, val);
  1531. }, reject);
  1532. return;
  1533. }
  1534. }
  1535. args[i] = val;
  1536. if (--remaining === 0) {
  1537. resolve(args);
  1538. }
  1539. } catch (ex) {
  1540. reject(ex);
  1541. }
  1542. }
  1543. for (var i = 0; i < args.length; i++) {
  1544. res(i, args[i]);
  1545. }
  1546. });
  1547. };
  1548. Promise.resolve = function (value) {
  1549. if (value && typeof value === 'object' && value.constructor === Promise) {
  1550. return value;
  1551. }
  1552. return new Promise(function (resolve) {
  1553. resolve(value);
  1554. });
  1555. };
  1556. Promise.reject = function (value) {
  1557. return new Promise(function (resolve, reject) {
  1558. reject(value);
  1559. });
  1560. };
  1561. Promise.race = function (values) {
  1562. return new Promise(function (resolve, reject) {
  1563. for (var i = 0, len = values.length; i < len; i++) {
  1564. values[i].then(resolve, reject);
  1565. }
  1566. });
  1567. };
  1568. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  1569. setImmediate(fn);
  1570. } : function (fn) {
  1571. setTimeoutFunc(fn, 0);
  1572. };
  1573. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  1574. if (typeof console !== 'undefined' && console) {
  1575. console.warn('Possible Unhandled Promise Rejection:', err);
  1576. }
  1577. };
  1578. Promise._setImmediateFn = function _setImmediateFn(fn) {
  1579. Promise._immediateFn = fn;
  1580. };
  1581. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  1582. Promise._unhandledRejectionFn = fn;
  1583. };
  1584. if (typeof module !== 'undefined' && module.exports) {
  1585. module.exports = Promise;
  1586. } else if (!root.Promise) {
  1587. root.Promise = Promise;
  1588. }
  1589. }(this));
  1590. }.call(this, require('timers').setImmediate));
  1591. },
  1592. { 'timers': 3 }
  1593. ],
  1594. 3: [
  1595. function (require, module, exports) {
  1596. (function (setImmediate, clearImmediate) {
  1597. var nextTick = require('process/browser.js').nextTick;
  1598. var apply = Function.prototype.apply;
  1599. var slice = Array.prototype.slice;
  1600. var immediateIds = {};
  1601. var nextImmediateId = 0;
  1602. exports.setTimeout = function () {
  1603. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  1604. };
  1605. exports.setInterval = function () {
  1606. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  1607. };
  1608. exports.clearTimeout = exports.clearInterval = function (timeout) {
  1609. timeout.close();
  1610. };
  1611. function Timeout(id, clearFn) {
  1612. this._id = id;
  1613. this._clearFn = clearFn;
  1614. }
  1615. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  1616. };
  1617. Timeout.prototype.close = function () {
  1618. this._clearFn.call(window, this._id);
  1619. };
  1620. exports.enroll = function (item, msecs) {
  1621. clearTimeout(item._idleTimeoutId);
  1622. item._idleTimeout = msecs;
  1623. };
  1624. exports.unenroll = function (item) {
  1625. clearTimeout(item._idleTimeoutId);
  1626. item._idleTimeout = -1;
  1627. };
  1628. exports._unrefActive = exports.active = function (item) {
  1629. clearTimeout(item._idleTimeoutId);
  1630. var msecs = item._idleTimeout;
  1631. if (msecs >= 0) {
  1632. item._idleTimeoutId = setTimeout(function onTimeout() {
  1633. if (item._onTimeout)
  1634. item._onTimeout();
  1635. }, msecs);
  1636. }
  1637. };
  1638. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  1639. var id = nextImmediateId++;
  1640. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  1641. immediateIds[id] = true;
  1642. nextTick(function onNextTick() {
  1643. if (immediateIds[id]) {
  1644. if (args) {
  1645. fn.apply(null, args);
  1646. } else {
  1647. fn.call(null);
  1648. }
  1649. exports.clearImmediate(id);
  1650. }
  1651. });
  1652. return id;
  1653. };
  1654. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  1655. delete immediateIds[id];
  1656. };
  1657. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  1658. },
  1659. {
  1660. 'process/browser.js': 1,
  1661. 'timers': 3
  1662. }
  1663. ],
  1664. 4: [
  1665. function (require, module, exports) {
  1666. var promisePolyfill = require('promise-polyfill');
  1667. var Global = function () {
  1668. if (typeof window !== 'undefined') {
  1669. return window;
  1670. } else {
  1671. return Function('return this;')();
  1672. }
  1673. }();
  1674. module.exports = { boltExport: Global.Promise || promisePolyfill };
  1675. },
  1676. { 'promise-polyfill': 2 }
  1677. ]
  1678. }, {}, [4])(4);
  1679. }));
  1680. }(undefined, exports$1, module$1, undefined));
  1681. var Promise = module$1.exports.boltExport;
  1682. var nu$3 = function (baseFn) {
  1683. var data = Option.none();
  1684. var callbacks = [];
  1685. var map = function (f) {
  1686. return nu$3(function (nCallback) {
  1687. get(function (data) {
  1688. nCallback(f(data));
  1689. });
  1690. });
  1691. };
  1692. var get = function (nCallback) {
  1693. if (isReady()) {
  1694. call(nCallback);
  1695. } else {
  1696. callbacks.push(nCallback);
  1697. }
  1698. };
  1699. var set = function (x) {
  1700. data = Option.some(x);
  1701. run(callbacks);
  1702. callbacks = [];
  1703. };
  1704. var isReady = function () {
  1705. return data.isSome();
  1706. };
  1707. var run = function (cbs) {
  1708. each(cbs, call);
  1709. };
  1710. var call = function (cb) {
  1711. data.each(function (x) {
  1712. domGlobals.setTimeout(function () {
  1713. cb(x);
  1714. }, 0);
  1715. });
  1716. };
  1717. baseFn(set);
  1718. return {
  1719. get: get,
  1720. map: map,
  1721. isReady: isReady
  1722. };
  1723. };
  1724. var pure = function (a) {
  1725. return nu$3(function (callback) {
  1726. callback(a);
  1727. });
  1728. };
  1729. var LazyValue = {
  1730. nu: nu$3,
  1731. pure: pure
  1732. };
  1733. var errorReporter = function (err) {
  1734. domGlobals.setTimeout(function () {
  1735. throw err;
  1736. }, 0);
  1737. };
  1738. var make = function (run) {
  1739. var get = function (callback) {
  1740. run().then(callback, errorReporter);
  1741. };
  1742. var map = function (fab) {
  1743. return make(function () {
  1744. return run().then(fab);
  1745. });
  1746. };
  1747. var bind = function (aFutureB) {
  1748. return make(function () {
  1749. return run().then(function (v) {
  1750. return aFutureB(v).toPromise();
  1751. });
  1752. });
  1753. };
  1754. var anonBind = function (futureB) {
  1755. return make(function () {
  1756. return run().then(function () {
  1757. return futureB.toPromise();
  1758. });
  1759. });
  1760. };
  1761. var toLazy = function () {
  1762. return LazyValue.nu(get);
  1763. };
  1764. var toCached = function () {
  1765. var cache = null;
  1766. return make(function () {
  1767. if (cache === null) {
  1768. cache = run();
  1769. }
  1770. return cache;
  1771. });
  1772. };
  1773. var toPromise = run;
  1774. return {
  1775. map: map,
  1776. bind: bind,
  1777. anonBind: anonBind,
  1778. toLazy: toLazy,
  1779. toCached: toCached,
  1780. toPromise: toPromise,
  1781. get: get
  1782. };
  1783. };
  1784. var nu$4 = function (baseFn) {
  1785. return make(function () {
  1786. return new Promise(baseFn);
  1787. });
  1788. };
  1789. var pure$1 = function (a) {
  1790. return make(function () {
  1791. return Promise.resolve(a);
  1792. });
  1793. };
  1794. var Future = {
  1795. nu: nu$4,
  1796. pure: pure$1
  1797. };
  1798. var par = function (asyncValues, nu) {
  1799. return nu(function (callback) {
  1800. var r = [];
  1801. var count = 0;
  1802. var cb = function (i) {
  1803. return function (value) {
  1804. r[i] = value;
  1805. count++;
  1806. if (count >= asyncValues.length) {
  1807. callback(r);
  1808. }
  1809. };
  1810. };
  1811. if (asyncValues.length === 0) {
  1812. callback([]);
  1813. } else {
  1814. each(asyncValues, function (asyncValue, i) {
  1815. asyncValue.get(cb(i));
  1816. });
  1817. }
  1818. });
  1819. };
  1820. var par$1 = function (futures) {
  1821. return par(futures, Future.nu);
  1822. };
  1823. var value = function (o) {
  1824. var is = function (v) {
  1825. return o === v;
  1826. };
  1827. var or = function (opt) {
  1828. return value(o);
  1829. };
  1830. var orThunk = function (f) {
  1831. return value(o);
  1832. };
  1833. var map = function (f) {
  1834. return value(f(o));
  1835. };
  1836. var mapError = function (f) {
  1837. return value(o);
  1838. };
  1839. var each = function (f) {
  1840. f(o);
  1841. };
  1842. var bind = function (f) {
  1843. return f(o);
  1844. };
  1845. var fold = function (_, onValue) {
  1846. return onValue(o);
  1847. };
  1848. var exists = function (f) {
  1849. return f(o);
  1850. };
  1851. var forall = function (f) {
  1852. return f(o);
  1853. };
  1854. var toOption = function () {
  1855. return Option.some(o);
  1856. };
  1857. return {
  1858. is: is,
  1859. isValue: always,
  1860. isError: never,
  1861. getOr: constant(o),
  1862. getOrThunk: constant(o),
  1863. getOrDie: constant(o),
  1864. or: or,
  1865. orThunk: orThunk,
  1866. fold: fold,
  1867. map: map,
  1868. mapError: mapError,
  1869. each: each,
  1870. bind: bind,
  1871. exists: exists,
  1872. forall: forall,
  1873. toOption: toOption
  1874. };
  1875. };
  1876. var error = function (message) {
  1877. var getOrThunk = function (f) {
  1878. return f();
  1879. };
  1880. var getOrDie = function () {
  1881. return die(String(message))();
  1882. };
  1883. var or = function (opt) {
  1884. return opt;
  1885. };
  1886. var orThunk = function (f) {
  1887. return f();
  1888. };
  1889. var map = function (f) {
  1890. return error(message);
  1891. };
  1892. var mapError = function (f) {
  1893. return error(f(message));
  1894. };
  1895. var bind = function (f) {
  1896. return error(message);
  1897. };
  1898. var fold = function (onError, _) {
  1899. return onError(message);
  1900. };
  1901. return {
  1902. is: never,
  1903. isValue: never,
  1904. isError: always,
  1905. getOr: identity,
  1906. getOrThunk: getOrThunk,
  1907. getOrDie: getOrDie,
  1908. or: or,
  1909. orThunk: orThunk,
  1910. fold: fold,
  1911. map: map,
  1912. mapError: mapError,
  1913. each: noop,
  1914. bind: bind,
  1915. exists: never,
  1916. forall: always,
  1917. toOption: Option.none
  1918. };
  1919. };
  1920. var fromOption = function (opt, err) {
  1921. return opt.fold(function () {
  1922. return error(err);
  1923. }, value);
  1924. };
  1925. var Result = {
  1926. value: value,
  1927. error: error,
  1928. fromOption: fromOption
  1929. };
  1930. var promise = function () {
  1931. function bind(fn, thisArg) {
  1932. return function () {
  1933. fn.apply(thisArg, arguments);
  1934. };
  1935. }
  1936. var isArray = Array.isArray || function (value) {
  1937. return Object.prototype.toString.call(value) === '[object Array]';
  1938. };
  1939. var Promise = function (fn) {
  1940. if (typeof this !== 'object') {
  1941. throw new TypeError('Promises must be constructed via new');
  1942. }
  1943. if (typeof fn !== 'function') {
  1944. throw new TypeError('not a function');
  1945. }
  1946. this._state = null;
  1947. this._value = null;
  1948. this._deferreds = [];
  1949. doResolve(fn, bind(resolve, this), bind(reject, this));
  1950. };
  1951. var asap = Promise.immediateFn || typeof domGlobals.setImmediate === 'function' && domGlobals.setImmediate || function (fn) {
  1952. domGlobals.setTimeout(fn, 1);
  1953. };
  1954. function handle(deferred) {
  1955. var me = this;
  1956. if (this._state === null) {
  1957. this._deferreds.push(deferred);
  1958. return;
  1959. }
  1960. asap(function () {
  1961. var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
  1962. if (cb === null) {
  1963. (me._state ? deferred.resolve : deferred.reject)(me._value);
  1964. return;
  1965. }
  1966. var ret;
  1967. try {
  1968. ret = cb(me._value);
  1969. } catch (e) {
  1970. deferred.reject(e);
  1971. return;
  1972. }
  1973. deferred.resolve(ret);
  1974. });
  1975. }
  1976. function resolve(newValue) {
  1977. try {
  1978. if (newValue === this) {
  1979. throw new TypeError('A promise cannot be resolved with itself.');
  1980. }
  1981. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  1982. var then = newValue.then;
  1983. if (typeof then === 'function') {
  1984. doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
  1985. return;
  1986. }
  1987. }
  1988. this._state = true;
  1989. this._value = newValue;
  1990. finale.call(this);
  1991. } catch (e) {
  1992. reject.call(this, e);
  1993. }
  1994. }
  1995. function reject(newValue) {
  1996. this._state = false;
  1997. this._value = newValue;
  1998. finale.call(this);
  1999. }
  2000. function finale() {
  2001. for (var i = 0, len = this._deferreds.length; i < len; i++) {
  2002. handle.call(this, this._deferreds[i]);
  2003. }
  2004. this._deferreds = null;
  2005. }
  2006. function Handler(onFulfilled, onRejected, resolve, reject) {
  2007. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  2008. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  2009. this.resolve = resolve;
  2010. this.reject = reject;
  2011. }
  2012. function doResolve(fn, onFulfilled, onRejected) {
  2013. var done = false;
  2014. try {
  2015. fn(function (value) {
  2016. if (done) {
  2017. return;
  2018. }
  2019. done = true;
  2020. onFulfilled(value);
  2021. }, function (reason) {
  2022. if (done) {
  2023. return;
  2024. }
  2025. done = true;
  2026. onRejected(reason);
  2027. });
  2028. } catch (ex) {
  2029. if (done) {
  2030. return;
  2031. }
  2032. done = true;
  2033. onRejected(ex);
  2034. }
  2035. }
  2036. Promise.prototype.catch = function (onRejected) {
  2037. return this.then(null, onRejected);
  2038. };
  2039. Promise.prototype.then = function (onFulfilled, onRejected) {
  2040. var me = this;
  2041. return new Promise(function (resolve, reject) {
  2042. handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
  2043. });
  2044. };
  2045. Promise.all = function () {
  2046. var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
  2047. return new Promise(function (resolve, reject) {
  2048. if (args.length === 0) {
  2049. return resolve([]);
  2050. }
  2051. var remaining = args.length;
  2052. function res(i, val) {
  2053. try {
  2054. if (val && (typeof val === 'object' || typeof val === 'function')) {
  2055. var then = val.then;
  2056. if (typeof then === 'function') {
  2057. then.call(val, function (val) {
  2058. res(i, val);
  2059. }, reject);
  2060. return;
  2061. }
  2062. }
  2063. args[i] = val;
  2064. if (--remaining === 0) {
  2065. resolve(args);
  2066. }
  2067. } catch (ex) {
  2068. reject(ex);
  2069. }
  2070. }
  2071. for (var i = 0; i < args.length; i++) {
  2072. res(i, args[i]);
  2073. }
  2074. });
  2075. };
  2076. Promise.resolve = function (value) {
  2077. if (value && typeof value === 'object' && value.constructor === Promise) {
  2078. return value;
  2079. }
  2080. return new Promise(function (resolve) {
  2081. resolve(value);
  2082. });
  2083. };
  2084. Promise.reject = function (value) {
  2085. return new Promise(function (resolve, reject) {
  2086. reject(value);
  2087. });
  2088. };
  2089. Promise.race = function (values) {
  2090. return new Promise(function (resolve, reject) {
  2091. for (var i = 0, len = values.length; i < len; i++) {
  2092. values[i].then(resolve, reject);
  2093. }
  2094. });
  2095. };
  2096. return Promise;
  2097. };
  2098. var promiseObj = window.Promise ? window.Promise : promise();
  2099. var requestAnimationFramePromise;
  2100. var requestAnimationFrame = function (callback, element) {
  2101. var i, requestAnimationFrameFunc = domGlobals.window.requestAnimationFrame;
  2102. var vendors = [
  2103. 'ms',
  2104. 'moz',
  2105. 'webkit'
  2106. ];
  2107. var featurefill = function (callback) {
  2108. domGlobals.window.setTimeout(callback, 0);
  2109. };
  2110. for (i = 0; i < vendors.length && !requestAnimationFrameFunc; i++) {
  2111. requestAnimationFrameFunc = domGlobals.window[vendors[i] + 'RequestAnimationFrame'];
  2112. }
  2113. if (!requestAnimationFrameFunc) {
  2114. requestAnimationFrameFunc = featurefill;
  2115. }
  2116. requestAnimationFrameFunc(callback, element);
  2117. };
  2118. var wrappedSetTimeout = function (callback, time) {
  2119. if (typeof time !== 'number') {
  2120. time = 0;
  2121. }
  2122. return domGlobals.setTimeout(callback, time);
  2123. };
  2124. var wrappedSetInterval = function (callback, time) {
  2125. if (typeof time !== 'number') {
  2126. time = 1;
  2127. }
  2128. return domGlobals.setInterval(callback, time);
  2129. };
  2130. var wrappedClearTimeout = function (id) {
  2131. return domGlobals.clearTimeout(id);
  2132. };
  2133. var wrappedClearInterval = function (id) {
  2134. return domGlobals.clearInterval(id);
  2135. };
  2136. var debounce = function (callback, time) {
  2137. var timer, func;
  2138. func = function () {
  2139. var args = [];
  2140. for (var _i = 0; _i < arguments.length; _i++) {
  2141. args[_i] = arguments[_i];
  2142. }
  2143. domGlobals.clearTimeout(timer);
  2144. timer = wrappedSetTimeout(function () {
  2145. callback.apply(this, args);
  2146. }, time);
  2147. };
  2148. func.stop = function () {
  2149. domGlobals.clearTimeout(timer);
  2150. };
  2151. return func;
  2152. };
  2153. var Delay = {
  2154. requestAnimationFrame: function (callback, element) {
  2155. if (requestAnimationFramePromise) {
  2156. requestAnimationFramePromise.then(callback);
  2157. return;
  2158. }
  2159. requestAnimationFramePromise = new promiseObj(function (resolve) {
  2160. if (!element) {
  2161. element = domGlobals.document.body;
  2162. }
  2163. requestAnimationFrame(resolve, element);
  2164. }).then(callback);
  2165. },
  2166. setTimeout: wrappedSetTimeout,
  2167. setInterval: wrappedSetInterval,
  2168. setEditorTimeout: function (editor, callback, time) {
  2169. return wrappedSetTimeout(function () {
  2170. if (!editor.removed) {
  2171. callback();
  2172. }
  2173. }, time);
  2174. },
  2175. setEditorInterval: function (editor, callback, time) {
  2176. var timer;
  2177. timer = wrappedSetInterval(function () {
  2178. if (!editor.removed) {
  2179. callback();
  2180. } else {
  2181. domGlobals.clearInterval(timer);
  2182. }
  2183. }, time);
  2184. return timer;
  2185. },
  2186. debounce: debounce,
  2187. throttle: debounce,
  2188. clearInterval: wrappedClearInterval,
  2189. clearTimeout: wrappedClearTimeout
  2190. };
  2191. var userAgent = domGlobals.navigator.userAgent;
  2192. var platform$1 = detect$3();
  2193. var browser$2 = platform$1.browser;
  2194. var os = platform$1.os;
  2195. var deviceType = platform$1.deviceType;
  2196. var webkit = /WebKit/.test(userAgent) && !browser$2.isEdge();
  2197. var fileApi = 'FormData' in domGlobals.window && 'FileReader' in domGlobals.window && 'URL' in domGlobals.window && !!domGlobals.URL.createObjectURL;
  2198. var windowsPhone = userAgent.indexOf('Windows Phone') !== -1;
  2199. var Env = {
  2200. opera: browser$2.isOpera(),
  2201. webkit: webkit,
  2202. ie: browser$2.isIE() || browser$2.isEdge() ? browser$2.version.major : false,
  2203. gecko: browser$2.isFirefox(),
  2204. mac: os.isOSX() || os.isiOS(),
  2205. iOS: deviceType.isiPad() || deviceType.isiPhone(),
  2206. android: os.isAndroid(),
  2207. contentEditable: true,
  2208. transparentSrc: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  2209. caretAfter: true,
  2210. range: domGlobals.window.getSelection && 'Range' in domGlobals.window,
  2211. documentMode: browser$2.isIE() ? domGlobals.document.documentMode || 7 : 10,
  2212. fileApi: fileApi,
  2213. ceFalse: true,
  2214. cacheSuffix: null,
  2215. container: null,
  2216. experimentalShadowDom: false,
  2217. canHaveCSP: !browser$2.isIE(),
  2218. desktop: deviceType.isDesktop(),
  2219. windowsPhone: windowsPhone,
  2220. browser: {
  2221. current: browser$2.current,
  2222. version: browser$2.version,
  2223. isChrome: browser$2.isChrome,
  2224. isEdge: browser$2.isEdge,
  2225. isFirefox: browser$2.isFirefox,
  2226. isIE: browser$2.isIE,
  2227. isOpera: browser$2.isOpera,
  2228. isSafari: browser$2.isSafari
  2229. },
  2230. os: {
  2231. current: os.current,
  2232. version: os.version,
  2233. isAndroid: os.isAndroid,
  2234. isFreeBSD: os.isFreeBSD,
  2235. isiOS: os.isiOS,
  2236. isLinux: os.isLinux,
  2237. isOSX: os.isOSX,
  2238. isSolaris: os.isSolaris,
  2239. isWindows: os.isWindows
  2240. },
  2241. deviceType: {
  2242. isDesktop: deviceType.isDesktop,
  2243. isiPad: deviceType.isiPad,
  2244. isiPhone: deviceType.isiPhone,
  2245. isPhone: deviceType.isPhone,
  2246. isTablet: deviceType.isTablet,
  2247. isTouch: deviceType.isTouch,
  2248. isWebView: deviceType.isWebView
  2249. }
  2250. };
  2251. var isArray$1 = Array.isArray;
  2252. var toArray$1 = function (obj) {
  2253. var array = obj, i, l;
  2254. if (!isArray$1(obj)) {
  2255. array = [];
  2256. for (i = 0, l = obj.length; i < l; i++) {
  2257. array[i] = obj[i];
  2258. }
  2259. }
  2260. return array;
  2261. };
  2262. var each$2 = function (o, cb, s) {
  2263. var n, l;
  2264. if (!o) {
  2265. return 0;
  2266. }
  2267. s = s || o;
  2268. if (o.length !== undefined) {
  2269. for (n = 0, l = o.length; n < l; n++) {
  2270. if (cb.call(s, o[n], n, o) === false) {
  2271. return 0;
  2272. }
  2273. }
  2274. } else {
  2275. for (n in o) {
  2276. if (o.hasOwnProperty(n)) {
  2277. if (cb.call(s, o[n], n, o) === false) {
  2278. return 0;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. return 1;
  2284. };
  2285. var map$2 = function (array, callback) {
  2286. var out = [];
  2287. each$2(array, function (item, index) {
  2288. out.push(callback(item, index, array));
  2289. });
  2290. return out;
  2291. };
  2292. var filter$1 = function (a, f) {
  2293. var o = [];
  2294. each$2(a, function (v, index) {
  2295. if (!f || f(v, index, a)) {
  2296. o.push(v);
  2297. }
  2298. });
  2299. return o;
  2300. };
  2301. var indexOf$1 = function (a, v) {
  2302. var i, l;
  2303. if (a) {
  2304. for (i = 0, l = a.length; i < l; i++) {
  2305. if (a[i] === v) {
  2306. return i;
  2307. }
  2308. }
  2309. }
  2310. return -1;
  2311. };
  2312. var reduce = function (collection, iteratee, accumulator, thisArg) {
  2313. var i = 0;
  2314. if (arguments.length < 3) {
  2315. accumulator = collection[0];
  2316. }
  2317. for (; i < collection.length; i++) {
  2318. accumulator = iteratee.call(thisArg, accumulator, collection[i], i);
  2319. }
  2320. return accumulator;
  2321. };
  2322. var findIndex$1 = function (array, predicate, thisArg) {
  2323. var i, l;
  2324. for (i = 0, l = array.length; i < l; i++) {
  2325. if (predicate.call(thisArg, array[i], i, array)) {
  2326. return i;
  2327. }
  2328. }
  2329. return -1;
  2330. };
  2331. var find$2 = function (array, predicate, thisArg) {
  2332. var idx = findIndex$1(array, predicate, thisArg);
  2333. if (idx !== -1) {
  2334. return array[idx];
  2335. }
  2336. return undefined;
  2337. };
  2338. var last$1 = function (collection) {
  2339. return collection[collection.length - 1];
  2340. };
  2341. var ArrUtils = {
  2342. isArray: isArray$1,
  2343. toArray: toArray$1,
  2344. each: each$2,
  2345. map: map$2,
  2346. filter: filter$1,
  2347. indexOf: indexOf$1,
  2348. reduce: reduce,
  2349. findIndex: findIndex$1,
  2350. find: find$2,
  2351. last: last$1
  2352. };
  2353. var whiteSpaceRegExp = /^\s*|\s*$/g;
  2354. var trim$1 = function (str) {
  2355. return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp, '');
  2356. };
  2357. var is$1 = function (obj, type) {
  2358. if (!type) {
  2359. return obj !== undefined;
  2360. }
  2361. if (type === 'array' && ArrUtils.isArray(obj)) {
  2362. return true;
  2363. }
  2364. return typeof obj === type;
  2365. };
  2366. var makeMap = function (items, delim, map) {
  2367. var i;
  2368. items = items || [];
  2369. delim = delim || ',';
  2370. if (typeof items === 'string') {
  2371. items = items.split(delim);
  2372. }
  2373. map = map || {};
  2374. i = items.length;
  2375. while (i--) {
  2376. map[items[i]] = {};
  2377. }
  2378. return map;
  2379. };
  2380. var hasOwnProperty$1 = function (obj, prop) {
  2381. return Object.prototype.hasOwnProperty.call(obj, prop);
  2382. };
  2383. var create = function (s, p, root) {
  2384. var self = this;
  2385. var sp, ns, cn, scn, c, de = 0;
  2386. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  2387. cn = s[3].match(/(^|\.)(\w+)$/i)[2];
  2388. ns = self.createNS(s[3].replace(/\.\w+$/, ''), root);
  2389. if (ns[cn]) {
  2390. return;
  2391. }
  2392. if (s[2] === 'static') {
  2393. ns[cn] = p;
  2394. if (this.onCreate) {
  2395. this.onCreate(s[2], s[3], ns[cn]);
  2396. }
  2397. return;
  2398. }
  2399. if (!p[cn]) {
  2400. p[cn] = function () {
  2401. };
  2402. de = 1;
  2403. }
  2404. ns[cn] = p[cn];
  2405. self.extend(ns[cn].prototype, p);
  2406. if (s[5]) {
  2407. sp = self.resolve(s[5]).prototype;
  2408. scn = s[5].match(/\.(\w+)$/i)[1];
  2409. c = ns[cn];
  2410. if (de) {
  2411. ns[cn] = function () {
  2412. return sp[scn].apply(this, arguments);
  2413. };
  2414. } else {
  2415. ns[cn] = function () {
  2416. this.parent = sp[scn];
  2417. return c.apply(this, arguments);
  2418. };
  2419. }
  2420. ns[cn].prototype[cn] = ns[cn];
  2421. self.each(sp, function (f, n) {
  2422. ns[cn].prototype[n] = sp[n];
  2423. });
  2424. self.each(p, function (f, n) {
  2425. if (sp[n]) {
  2426. ns[cn].prototype[n] = function () {
  2427. this.parent = sp[n];
  2428. return f.apply(this, arguments);
  2429. };
  2430. } else {
  2431. if (n !== cn) {
  2432. ns[cn].prototype[n] = f;
  2433. }
  2434. }
  2435. });
  2436. }
  2437. self.each(p.static, function (f, n) {
  2438. ns[cn][n] = f;
  2439. });
  2440. };
  2441. var extend = function (obj, ext) {
  2442. var x = [];
  2443. for (var _i = 2; _i < arguments.length; _i++) {
  2444. x[_i - 2] = arguments[_i];
  2445. }
  2446. var i, l, name;
  2447. var args = arguments;
  2448. var value;
  2449. for (i = 1, l = args.length; i < l; i++) {
  2450. ext = args[i];
  2451. for (name in ext) {
  2452. if (ext.hasOwnProperty(name)) {
  2453. value = ext[name];
  2454. if (value !== undefined) {
  2455. obj[name] = value;
  2456. }
  2457. }
  2458. }
  2459. }
  2460. return obj;
  2461. };
  2462. var walk = function (o, f, n, s) {
  2463. s = s || this;
  2464. if (o) {
  2465. if (n) {
  2466. o = o[n];
  2467. }
  2468. ArrUtils.each(o, function (o, i) {
  2469. if (f.call(s, o, i, n) === false) {
  2470. return false;
  2471. }
  2472. walk(o, f, n, s);
  2473. });
  2474. }
  2475. };
  2476. var createNS = function (n, o) {
  2477. var i, v;
  2478. o = o || domGlobals.window;
  2479. n = n.split('.');
  2480. for (i = 0; i < n.length; i++) {
  2481. v = n[i];
  2482. if (!o[v]) {
  2483. o[v] = {};
  2484. }
  2485. o = o[v];
  2486. }
  2487. return o;
  2488. };
  2489. var resolve = function (n, o) {
  2490. var i, l;
  2491. o = o || domGlobals.window;
  2492. n = n.split('.');
  2493. for (i = 0, l = n.length; i < l; i++) {
  2494. o = o[n[i]];
  2495. if (!o) {
  2496. break;
  2497. }
  2498. }
  2499. return o;
  2500. };
  2501. var explode = function (s, d) {
  2502. if (!s || is$1(s, 'array')) {
  2503. return s;
  2504. }
  2505. return ArrUtils.map(s.split(d || ','), trim$1);
  2506. };
  2507. var _addCacheSuffix = function (url) {
  2508. var cacheSuffix = Env.cacheSuffix;
  2509. if (cacheSuffix) {
  2510. url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix;
  2511. }
  2512. return url;
  2513. };
  2514. var Tools = {
  2515. trim: trim$1,
  2516. isArray: ArrUtils.isArray,
  2517. is: is$1,
  2518. toArray: ArrUtils.toArray,
  2519. makeMap: makeMap,
  2520. each: ArrUtils.each,
  2521. map: ArrUtils.map,
  2522. grep: ArrUtils.filter,
  2523. inArray: ArrUtils.indexOf,
  2524. hasOwn: hasOwnProperty$1,
  2525. extend: extend,
  2526. create: create,
  2527. walk: walk,
  2528. createNS: createNS,
  2529. resolve: resolve,
  2530. explode: explode,
  2531. _addCacheSuffix: _addCacheSuffix
  2532. };
  2533. function StyleSheetLoader(document, settings) {
  2534. if (settings === void 0) {
  2535. settings = {};
  2536. }
  2537. var idCount = 0;
  2538. var loadedStates = {};
  2539. var maxLoadTime;
  2540. maxLoadTime = settings.maxLoadTime || 5000;
  2541. var _setReferrerPolicy = function (referrerPolicy) {
  2542. settings.referrerPolicy = referrerPolicy;
  2543. };
  2544. var appendToHead = function (node) {
  2545. document.getElementsByTagName('head')[0].appendChild(node);
  2546. };
  2547. var load = function (url, loadedCallback, errorCallback) {
  2548. var link, style, startTime, state;
  2549. var resolve = function (status) {
  2550. state.status = status;
  2551. state.passed = [];
  2552. state.failed = [];
  2553. if (link) {
  2554. link.onload = null;
  2555. link.onerror = null;
  2556. link = null;
  2557. }
  2558. };
  2559. var passed = function () {
  2560. var callbacks = state.passed;
  2561. var i = callbacks.length;
  2562. while (i--) {
  2563. callbacks[i]();
  2564. }
  2565. resolve(2);
  2566. };
  2567. var failed = function () {
  2568. var callbacks = state.failed;
  2569. var i = callbacks.length;
  2570. while (i--) {
  2571. callbacks[i]();
  2572. }
  2573. resolve(3);
  2574. };
  2575. var isOldWebKit = function () {
  2576. var webKitChunks = domGlobals.navigator.userAgent.match(/WebKit\/(\d*)/);
  2577. return !!(webKitChunks && parseInt(webKitChunks[1], 10) < 536);
  2578. };
  2579. var wait = function (testCallback, waitCallback) {
  2580. if (!testCallback()) {
  2581. if (new Date().getTime() - startTime < maxLoadTime) {
  2582. Delay.setTimeout(waitCallback);
  2583. } else {
  2584. failed();
  2585. }
  2586. }
  2587. };
  2588. var waitForWebKitLinkLoaded = function () {
  2589. wait(function () {
  2590. var styleSheets = document.styleSheets;
  2591. var styleSheet, i = styleSheets.length, owner;
  2592. while (i--) {
  2593. styleSheet = styleSheets[i];
  2594. owner = styleSheet.ownerNode ? styleSheet.ownerNode : styleSheet.owningElement;
  2595. if (owner && owner.id === link.id) {
  2596. passed();
  2597. return true;
  2598. }
  2599. }
  2600. }, waitForWebKitLinkLoaded);
  2601. };
  2602. var waitForGeckoLinkLoaded = function () {
  2603. wait(function () {
  2604. try {
  2605. var cssRules = style.sheet.cssRules;
  2606. passed();
  2607. return !!cssRules;
  2608. } catch (ex) {
  2609. }
  2610. }, waitForGeckoLinkLoaded);
  2611. };
  2612. url = Tools._addCacheSuffix(url);
  2613. if (!loadedStates[url]) {
  2614. state = {
  2615. passed: [],
  2616. failed: []
  2617. };
  2618. loadedStates[url] = state;
  2619. } else {
  2620. state = loadedStates[url];
  2621. }
  2622. if (loadedCallback) {
  2623. state.passed.push(loadedCallback);
  2624. }
  2625. if (errorCallback) {
  2626. state.failed.push(errorCallback);
  2627. }
  2628. if (state.status === 1) {
  2629. return;
  2630. }
  2631. if (state.status === 2) {
  2632. passed();
  2633. return;
  2634. }
  2635. if (state.status === 3) {
  2636. failed();
  2637. return;
  2638. }
  2639. state.status = 1;
  2640. link = document.createElement('link');
  2641. link.rel = 'stylesheet';
  2642. link.type = 'text/css';
  2643. link.id = 'u' + idCount++;
  2644. link.async = false;
  2645. link.defer = false;
  2646. startTime = new Date().getTime();
  2647. if (settings.contentCssCors) {
  2648. link.crossOrigin = 'anonymous';
  2649. }
  2650. if (settings.referrerPolicy) {
  2651. set(Element.fromDom(link), 'referrerpolicy', settings.referrerPolicy);
  2652. }
  2653. if ('onload' in link && !isOldWebKit()) {
  2654. link.onload = waitForWebKitLinkLoaded;
  2655. link.onerror = failed;
  2656. } else {
  2657. if (domGlobals.navigator.userAgent.indexOf('Firefox') > 0) {
  2658. style = document.createElement('style');
  2659. style.textContent = '@import "' + url + '"';
  2660. waitForGeckoLinkLoaded();
  2661. appendToHead(style);
  2662. return;
  2663. }
  2664. waitForWebKitLinkLoaded();
  2665. }
  2666. appendToHead(link);
  2667. link.href = url;
  2668. };
  2669. var loadF = function (url) {
  2670. return Future.nu(function (resolve) {
  2671. load(url, compose(resolve, constant(Result.value(url))), compose(resolve, constant(Result.error(url))));
  2672. });
  2673. };
  2674. var unbox = function (result) {
  2675. return result.fold(identity, identity);
  2676. };
  2677. var loadAll = function (urls, success, failure) {
  2678. par$1(map(urls, loadF)).get(function (result) {
  2679. var parts = partition(result, function (r) {
  2680. return r.isValue();
  2681. });
  2682. if (parts.fail.length > 0) {
  2683. failure(parts.fail.map(unbox));
  2684. } else {
  2685. success(parts.pass.map(unbox));
  2686. }
  2687. });
  2688. };
  2689. return {
  2690. load: load,
  2691. loadAll: loadAll,
  2692. _setReferrerPolicy: _setReferrerPolicy
  2693. };
  2694. }
  2695. var blocks = [
  2696. 'article',
  2697. 'aside',
  2698. 'details',
  2699. 'div',
  2700. 'dt',
  2701. 'figcaption',
  2702. 'footer',
  2703. 'form',
  2704. 'fieldset',
  2705. 'header',
  2706. 'hgroup',
  2707. 'html',
  2708. 'main',
  2709. 'nav',
  2710. 'section',
  2711. 'summary',
  2712. 'body',
  2713. 'p',
  2714. 'dl',
  2715. 'multicol',
  2716. 'dd',
  2717. 'figure',
  2718. 'address',
  2719. 'center',
  2720. 'blockquote',
  2721. 'h1',
  2722. 'h2',
  2723. 'h3',
  2724. 'h4',
  2725. 'h5',
  2726. 'h6',
  2727. 'listing',
  2728. 'xmp',
  2729. 'pre',
  2730. 'plaintext',
  2731. 'menu',
  2732. 'dir',
  2733. 'ul',
  2734. 'ol',
  2735. 'li',
  2736. 'hr',
  2737. 'table',
  2738. 'tbody',
  2739. 'thead',
  2740. 'tfoot',
  2741. 'th',
  2742. 'tr',
  2743. 'td',
  2744. 'caption'
  2745. ];
  2746. var voids = [
  2747. 'area',
  2748. 'base',
  2749. 'basefont',
  2750. 'br',
  2751. 'col',
  2752. 'frame',
  2753. 'hr',
  2754. 'img',
  2755. 'input',
  2756. 'isindex',
  2757. 'link',
  2758. 'meta',
  2759. 'param',
  2760. 'embed',
  2761. 'source',
  2762. 'wbr',
  2763. 'track'
  2764. ];
  2765. var tableCells = [
  2766. 'td',
  2767. 'th'
  2768. ];
  2769. var tableSections = [
  2770. 'thead',
  2771. 'tbody',
  2772. 'tfoot'
  2773. ];
  2774. var textBlocks = [
  2775. 'h1',
  2776. 'h2',
  2777. 'h3',
  2778. 'h4',
  2779. 'h5',
  2780. 'h6',
  2781. 'p',
  2782. 'div',
  2783. 'address',
  2784. 'pre',
  2785. 'form',
  2786. 'blockquote',
  2787. 'center',
  2788. 'dir',
  2789. 'fieldset',
  2790. 'header',
  2791. 'footer',
  2792. 'article',
  2793. 'section',
  2794. 'hgroup',
  2795. 'aside',
  2796. 'nav',
  2797. 'figure'
  2798. ];
  2799. var headings = [
  2800. 'h1',
  2801. 'h2',
  2802. 'h3',
  2803. 'h4',
  2804. 'h5',
  2805. 'h6'
  2806. ];
  2807. var listItems = [
  2808. 'li',
  2809. 'dd',
  2810. 'dt'
  2811. ];
  2812. var lists = [
  2813. 'ul',
  2814. 'ol',
  2815. 'dl'
  2816. ];
  2817. var wsElements = [
  2818. 'pre',
  2819. 'script',
  2820. 'textarea',
  2821. 'style'
  2822. ];
  2823. var lazyLookup = function (items) {
  2824. var lookup;
  2825. return function (node) {
  2826. lookup = lookup ? lookup : mapToObject(items, constant(true));
  2827. return lookup.hasOwnProperty(name(node));
  2828. };
  2829. };
  2830. var isHeading = lazyLookup(headings);
  2831. var isBlock = lazyLookup(blocks);
  2832. var isTable$1 = function (node) {
  2833. return name(node) === 'table';
  2834. };
  2835. var isInline = function (node) {
  2836. return isElement$1(node) && !isBlock(node);
  2837. };
  2838. var isBr$1 = function (node) {
  2839. return isElement$1(node) && name(node) === 'br';
  2840. };
  2841. var isTextBlock = lazyLookup(textBlocks);
  2842. var isList = lazyLookup(lists);
  2843. var isListItem = lazyLookup(listItems);
  2844. var isVoid = lazyLookup(voids);
  2845. var isTableSection = lazyLookup(tableSections);
  2846. var isTableCell = lazyLookup(tableCells);
  2847. var isWsPreserveElement = lazyLookup(wsElements);
  2848. var surroundedBySpans = function (node) {
  2849. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName === 'SPAN';
  2850. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName === 'SPAN';
  2851. return previousIsSpan && nextIsSpan;
  2852. };
  2853. var isBookmarkNode = function (node) {
  2854. return node && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark';
  2855. };
  2856. var trimNode = function (dom, node) {
  2857. var i, children = node.childNodes;
  2858. if (NodeType.isElement(node) && isBookmarkNode(node)) {
  2859. return;
  2860. }
  2861. for (i = children.length - 1; i >= 0; i--) {
  2862. trimNode(dom, children[i]);
  2863. }
  2864. if (NodeType.isDocument(node) === false) {
  2865. if (NodeType.isText(node) && node.nodeValue.length > 0) {
  2866. var trimmedLength = Tools.trim(node.nodeValue).length;
  2867. if (dom.isBlock(node.parentNode) || trimmedLength > 0) {
  2868. return;
  2869. }
  2870. if (trimmedLength === 0 && surroundedBySpans(node)) {
  2871. return;
  2872. }
  2873. } else if (NodeType.isElement(node)) {
  2874. children = node.childNodes;
  2875. if (children.length === 1 && isBookmarkNode(children[0])) {
  2876. node.parentNode.insertBefore(children[0], node);
  2877. }
  2878. if (children.length || isVoid(Element.fromDom(node))) {
  2879. return;
  2880. }
  2881. }
  2882. dom.remove(node);
  2883. }
  2884. return node;
  2885. };
  2886. var TrimNode = { trimNode: trimNode };
  2887. var makeMap$1 = Tools.makeMap;
  2888. var namedEntities, baseEntities, reverseEntities;
  2889. var attrsCharsRegExp = /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  2890. var textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  2891. var rawCharsRegExp = /[<>&\"\']/g;
  2892. var entityRegExp = /&#([a-z0-9]+);?|&([a-z0-9]+);/gi;
  2893. var asciiMap = {
  2894. 128: '\u20AC',
  2895. 130: '\u201A',
  2896. 131: '\u0192',
  2897. 132: '\u201E',
  2898. 133: '\u2026',
  2899. 134: '\u2020',
  2900. 135: '\u2021',
  2901. 136: '\u02c6',
  2902. 137: '\u2030',
  2903. 138: '\u0160',
  2904. 139: '\u2039',
  2905. 140: '\u0152',
  2906. 142: '\u017d',
  2907. 145: '\u2018',
  2908. 146: '\u2019',
  2909. 147: '\u201C',
  2910. 148: '\u201D',
  2911. 149: '\u2022',
  2912. 150: '\u2013',
  2913. 151: '\u2014',
  2914. 152: '\u02DC',
  2915. 153: '\u2122',
  2916. 154: '\u0161',
  2917. 155: '\u203A',
  2918. 156: '\u0153',
  2919. 158: '\u017e',
  2920. 159: '\u0178'
  2921. };
  2922. baseEntities = {
  2923. '"': '&quot;',
  2924. '\'': '&#39;',
  2925. '<': '&lt;',
  2926. '>': '&gt;',
  2927. '&': '&amp;',
  2928. '`': '&#96;'
  2929. };
  2930. reverseEntities = {
  2931. '&lt;': '<',
  2932. '&gt;': '>',
  2933. '&amp;': '&',
  2934. '&quot;': '"',
  2935. '&apos;': '\''
  2936. };
  2937. var nativeDecode = function (text) {
  2938. var elm;
  2939. elm = Element.fromTag('div').dom();
  2940. elm.innerHTML = text;
  2941. return elm.textContent || elm.innerText || text;
  2942. };
  2943. var buildEntitiesLookup = function (items, radix) {
  2944. var i, chr, entity;
  2945. var lookup = {};
  2946. if (items) {
  2947. items = items.split(',');
  2948. radix = radix || 10;
  2949. for (i = 0; i < items.length; i += 2) {
  2950. chr = String.fromCharCode(parseInt(items[i], radix));
  2951. if (!baseEntities[chr]) {
  2952. entity = '&' + items[i + 1] + ';';
  2953. lookup[chr] = entity;
  2954. lookup[entity] = chr;
  2955. }
  2956. }
  2957. return lookup;
  2958. }
  2959. };
  2960. namedEntities = buildEntitiesLookup('50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' + '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' + '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' + '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' + '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' + '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' + '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' + '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' + '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' + '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' + 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' + 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' + 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' + 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' + 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' + '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' + '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' + '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' + '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' + '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' + 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' + 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' + 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' + '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' + '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
  2961. var encodeRaw = function (text, attr) {
  2962. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2963. return baseEntities[chr] || chr;
  2964. });
  2965. };
  2966. var encodeAllRaw = function (text) {
  2967. return ('' + text).replace(rawCharsRegExp, function (chr) {
  2968. return baseEntities[chr] || chr;
  2969. });
  2970. };
  2971. var encodeNumeric = function (text, attr) {
  2972. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2973. if (chr.length > 1) {
  2974. return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';
  2975. }
  2976. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  2977. });
  2978. };
  2979. var encodeNamed = function (text, attr, entities) {
  2980. entities = entities || namedEntities;
  2981. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2982. return baseEntities[chr] || entities[chr] || chr;
  2983. });
  2984. };
  2985. var getEncodeFunc = function (name, entities) {
  2986. var entitiesMap = buildEntitiesLookup(entities) || namedEntities;
  2987. var encodeNamedAndNumeric = function (text, attr) {
  2988. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function (chr) {
  2989. if (baseEntities[chr] !== undefined) {
  2990. return baseEntities[chr];
  2991. }
  2992. if (entitiesMap[chr] !== undefined) {
  2993. return entitiesMap[chr];
  2994. }
  2995. if (chr.length > 1) {
  2996. return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';
  2997. }
  2998. return '&#' + chr.charCodeAt(0) + ';';
  2999. });
  3000. };
  3001. var encodeCustomNamed = function (text, attr) {
  3002. return encodeNamed(text, attr, entitiesMap);
  3003. };
  3004. var nameMap = makeMap$1(name.replace(/\+/g, ','));
  3005. if (nameMap.named && nameMap.numeric) {
  3006. return encodeNamedAndNumeric;
  3007. }
  3008. if (nameMap.named) {
  3009. if (entities) {
  3010. return encodeCustomNamed;
  3011. }
  3012. return encodeNamed;
  3013. }
  3014. if (nameMap.numeric) {
  3015. return encodeNumeric;
  3016. }
  3017. return encodeRaw;
  3018. };
  3019. var decode = function (text) {
  3020. return text.replace(entityRegExp, function (all, numeric) {
  3021. if (numeric) {
  3022. if (numeric.charAt(0).toLowerCase() === 'x') {
  3023. numeric = parseInt(numeric.substr(1), 16);
  3024. } else {
  3025. numeric = parseInt(numeric, 10);
  3026. }
  3027. if (numeric > 65535) {
  3028. numeric -= 65536;
  3029. return String.fromCharCode(55296 + (numeric >> 10), 56320 + (numeric & 1023));
  3030. }
  3031. return asciiMap[numeric] || String.fromCharCode(numeric);
  3032. }
  3033. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  3034. });
  3035. };
  3036. var Entities = {
  3037. encodeRaw: encodeRaw,
  3038. encodeAllRaw: encodeAllRaw,
  3039. encodeNumeric: encodeNumeric,
  3040. encodeNamed: encodeNamed,
  3041. getEncodeFunc: getEncodeFunc,
  3042. decode: decode
  3043. };
  3044. var mapCache = {}, dummyObj = {};
  3045. var makeMap$2 = Tools.makeMap, each$3 = Tools.each, extend$1 = Tools.extend, explode$1 = Tools.explode, inArray = Tools.inArray;
  3046. var split = function (items, delim) {
  3047. items = Tools.trim(items);
  3048. return items ? items.split(delim || ' ') : [];
  3049. };
  3050. var compileSchema = function (type) {
  3051. var schema = {};
  3052. var globalAttributes, blockContent;
  3053. var phrasingContent, flowContent, html4BlockContent, html4PhrasingContent;
  3054. var add = function (name, attributes, children) {
  3055. var ni, attributesOrder, element;
  3056. var arrayToMap = function (array, obj) {
  3057. var map = {};
  3058. var i, l;
  3059. for (i = 0, l = array.length; i < l; i++) {
  3060. map[array[i]] = obj || {};
  3061. }
  3062. return map;
  3063. };
  3064. children = children || [];
  3065. attributes = attributes || '';
  3066. if (typeof children === 'string') {
  3067. children = split(children);
  3068. }
  3069. name = split(name);
  3070. ni = name.length;
  3071. while (ni--) {
  3072. attributesOrder = split([
  3073. globalAttributes,
  3074. attributes
  3075. ].join(' '));
  3076. element = {
  3077. attributes: arrayToMap(attributesOrder),
  3078. attributesOrder: attributesOrder,
  3079. children: arrayToMap(children, dummyObj)
  3080. };
  3081. schema[name[ni]] = element;
  3082. }
  3083. };
  3084. var addAttrs = function (name, attributes) {
  3085. var ni, schemaItem, i, l;
  3086. name = split(name);
  3087. ni = name.length;
  3088. attributes = split(attributes);
  3089. while (ni--) {
  3090. schemaItem = schema[name[ni]];
  3091. for (i = 0, l = attributes.length; i < l; i++) {
  3092. schemaItem.attributes[attributes[i]] = {};
  3093. schemaItem.attributesOrder.push(attributes[i]);
  3094. }
  3095. }
  3096. };
  3097. if (mapCache[type]) {
  3098. return mapCache[type];
  3099. }
  3100. globalAttributes = 'id accesskey class dir lang style tabindex title role';
  3101. blockContent = 'address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul';
  3102. phrasingContent = 'a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd ' + 'label map noscript object q s samp script select small span strong sub sup ' + 'textarea u var #text #comment';
  3103. if (type !== 'html4') {
  3104. globalAttributes += ' contenteditable contextmenu draggable dropzone ' + 'hidden spellcheck translate';
  3105. blockContent += ' article aside details dialog figure main header footer hgroup section nav';
  3106. phrasingContent += ' audio canvas command datalist mark meter output picture ' + 'progress time wbr video ruby bdi keygen';
  3107. }
  3108. if (type !== 'html5-strict') {
  3109. globalAttributes += ' xml:lang';
  3110. html4PhrasingContent = 'acronym applet basefont big font strike tt';
  3111. phrasingContent = [
  3112. phrasingContent,
  3113. html4PhrasingContent
  3114. ].join(' ');
  3115. each$3(split(html4PhrasingContent), function (name) {
  3116. add(name, '', phrasingContent);
  3117. });
  3118. html4BlockContent = 'center dir isindex noframes';
  3119. blockContent = [
  3120. blockContent,
  3121. html4BlockContent
  3122. ].join(' ');
  3123. flowContent = [
  3124. blockContent,
  3125. phrasingContent
  3126. ].join(' ');
  3127. each$3(split(html4BlockContent), function (name) {
  3128. add(name, '', flowContent);
  3129. });
  3130. }
  3131. flowContent = flowContent || [
  3132. blockContent,
  3133. phrasingContent
  3134. ].join(' ');
  3135. add('html', 'manifest', 'head body');
  3136. add('head', '', 'base command link meta noscript script style title');
  3137. add('title hr noscript br');
  3138. add('base', 'href target');
  3139. add('link', 'href rel media hreflang type sizes hreflang');
  3140. add('meta', 'name http-equiv content charset');
  3141. add('style', 'media type scoped');
  3142. add('script', 'src async defer type charset');
  3143. add('body', 'onafterprint onbeforeprint onbeforeunload onblur onerror onfocus ' + 'onhashchange onload onmessage onoffline ononline onpagehide onpageshow ' + 'onpopstate onresize onscroll onstorage onunload', flowContent);
  3144. add('address dt dd div caption', '', flowContent);
  3145. add('h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn', '', phrasingContent);
  3146. add('blockquote', 'cite', flowContent);
  3147. add('ol', 'reversed start type', 'li');
  3148. add('ul', '', 'li');
  3149. add('li', 'value', flowContent);
  3150. add('dl', '', 'dt dd');
  3151. add('a', 'href target rel media hreflang type', phrasingContent);
  3152. add('q', 'cite', phrasingContent);
  3153. add('ins del', 'cite datetime', flowContent);
  3154. add('img', 'src sizes srcset alt usemap ismap width height');
  3155. add('iframe', 'src name width height', flowContent);
  3156. add('embed', 'src type width height');
  3157. add('object', 'data type typemustmatch name usemap form width height', [
  3158. flowContent,
  3159. 'param'
  3160. ].join(' '));
  3161. add('param', 'name value');
  3162. add('map', 'name', [
  3163. flowContent,
  3164. 'area'
  3165. ].join(' '));
  3166. add('area', 'alt coords shape href target rel media hreflang type');
  3167. add('table', 'border', 'caption colgroup thead tfoot tbody tr' + (type === 'html4' ? ' col' : ''));
  3168. add('colgroup', 'span', 'col');
  3169. add('col', 'span');
  3170. add('tbody thead tfoot', '', 'tr');
  3171. add('tr', '', 'td th');
  3172. add('td', 'colspan rowspan headers', flowContent);
  3173. add('th', 'colspan rowspan headers scope abbr', flowContent);
  3174. add('form', 'accept-charset action autocomplete enctype method name novalidate target', flowContent);
  3175. add('fieldset', 'disabled form name', [
  3176. flowContent,
  3177. 'legend'
  3178. ].join(' '));
  3179. add('label', 'form for', phrasingContent);
  3180. add('input', 'accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate ' + 'formtarget height list max maxlength min multiple name pattern readonly required size src step type value width');
  3181. add('button', 'disabled form formaction formenctype formmethod formnovalidate formtarget name type value', type === 'html4' ? flowContent : phrasingContent);
  3182. add('select', 'disabled form multiple name required size', 'option optgroup');
  3183. add('optgroup', 'disabled label', 'option');
  3184. add('option', 'disabled label selected value');
  3185. add('textarea', 'cols dirname disabled form maxlength name readonly required rows wrap');
  3186. add('menu', 'type label', [
  3187. flowContent,
  3188. 'li'
  3189. ].join(' '));
  3190. add('noscript', '', flowContent);
  3191. if (type !== 'html4') {
  3192. add('wbr');
  3193. add('ruby', '', [
  3194. phrasingContent,
  3195. 'rt rp'
  3196. ].join(' '));
  3197. add('figcaption', '', flowContent);
  3198. add('mark rt rp summary bdi', '', phrasingContent);
  3199. add('canvas', 'width height', flowContent);
  3200. add('video', 'src crossorigin poster preload autoplay mediagroup loop ' + 'muted controls width height buffered', [
  3201. flowContent,
  3202. 'track source'
  3203. ].join(' '));
  3204. add('audio', 'src crossorigin preload autoplay mediagroup loop muted controls ' + 'buffered volume', [
  3205. flowContent,
  3206. 'track source'
  3207. ].join(' '));
  3208. add('picture', '', 'img source');
  3209. add('source', 'src srcset type media sizes');
  3210. add('track', 'kind src srclang label default');
  3211. add('datalist', '', [
  3212. phrasingContent,
  3213. 'option'
  3214. ].join(' '));
  3215. add('article section nav aside main header footer', '', flowContent);
  3216. add('hgroup', '', 'h1 h2 h3 h4 h5 h6');
  3217. add('figure', '', [
  3218. flowContent,
  3219. 'figcaption'
  3220. ].join(' '));
  3221. add('time', 'datetime', phrasingContent);
  3222. add('dialog', 'open', flowContent);
  3223. add('command', 'type label icon disabled checked radiogroup command');
  3224. add('output', 'for form name', phrasingContent);
  3225. add('progress', 'value max', phrasingContent);
  3226. add('meter', 'value min max low high optimum', phrasingContent);
  3227. add('details', 'open', [
  3228. flowContent,
  3229. 'summary'
  3230. ].join(' '));
  3231. add('keygen', 'autofocus challenge disabled form keytype name');
  3232. }
  3233. if (type !== 'html5-strict') {
  3234. addAttrs('script', 'language xml:space');
  3235. addAttrs('style', 'xml:space');
  3236. addAttrs('object', 'declare classid code codebase codetype archive standby align border hspace vspace');
  3237. addAttrs('embed', 'align name hspace vspace');
  3238. addAttrs('param', 'valuetype type');
  3239. addAttrs('a', 'charset name rev shape coords');
  3240. addAttrs('br', 'clear');
  3241. addAttrs('applet', 'codebase archive code object alt name width height align hspace vspace');
  3242. addAttrs('img', 'name longdesc align border hspace vspace');
  3243. addAttrs('iframe', 'longdesc frameborder marginwidth marginheight scrolling align');
  3244. addAttrs('font basefont', 'size color face');
  3245. addAttrs('input', 'usemap align');
  3246. addAttrs('select', 'onchange');
  3247. addAttrs('textarea');
  3248. addAttrs('h1 h2 h3 h4 h5 h6 div p legend caption', 'align');
  3249. addAttrs('ul', 'type compact');
  3250. addAttrs('li', 'type');
  3251. addAttrs('ol dl menu dir', 'compact');
  3252. addAttrs('pre', 'width xml:space');
  3253. addAttrs('hr', 'align noshade size width');
  3254. addAttrs('isindex', 'prompt');
  3255. addAttrs('table', 'summary width frame rules cellspacing cellpadding align bgcolor');
  3256. addAttrs('col', 'width align char charoff valign');
  3257. addAttrs('colgroup', 'width align char charoff valign');
  3258. addAttrs('thead', 'align char charoff valign');
  3259. addAttrs('tr', 'align char charoff valign bgcolor');
  3260. addAttrs('th', 'axis align char charoff valign nowrap bgcolor width height');
  3261. addAttrs('form', 'accept');
  3262. addAttrs('td', 'abbr axis scope align char charoff valign nowrap bgcolor width height');
  3263. addAttrs('tfoot', 'align char charoff valign');
  3264. addAttrs('tbody', 'align char charoff valign');
  3265. addAttrs('area', 'nohref');
  3266. addAttrs('body', 'background bgcolor text link vlink alink');
  3267. }
  3268. if (type !== 'html4') {
  3269. addAttrs('input button select textarea', 'autofocus');
  3270. addAttrs('input textarea', 'placeholder');
  3271. addAttrs('a', 'download');
  3272. addAttrs('link script img', 'crossorigin');
  3273. addAttrs('iframe', 'sandbox seamless allowfullscreen');
  3274. }
  3275. each$3(split('a form meter progress dfn'), function (name) {
  3276. if (schema[name]) {
  3277. delete schema[name].children[name];
  3278. }
  3279. });
  3280. delete schema.caption.children.table;
  3281. delete schema.script;
  3282. mapCache[type] = schema;
  3283. return schema;
  3284. };
  3285. var compileElementMap = function (value, mode) {
  3286. var styles;
  3287. if (value) {
  3288. styles = {};
  3289. if (typeof value === 'string') {
  3290. value = { '*': value };
  3291. }
  3292. each$3(value, function (value, key) {
  3293. styles[key] = styles[key.toUpperCase()] = mode === 'map' ? makeMap$2(value, /[, ]/) : explode$1(value, /[, ]/);
  3294. });
  3295. }
  3296. return styles;
  3297. };
  3298. function Schema(settings) {
  3299. var elements = {};
  3300. var children = {};
  3301. var patternElements = [];
  3302. var validStyles;
  3303. var invalidStyles;
  3304. var schemaItems;
  3305. var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, validClasses;
  3306. var blockElementsMap, nonEmptyElementsMap, moveCaretBeforeOnEnterElementsMap, textBlockElementsMap, textInlineElementsMap;
  3307. var customElementsMap = {}, specialElements = {};
  3308. var createLookupTable = function (option, defaultValue, extendWith) {
  3309. var value = settings[option];
  3310. if (!value) {
  3311. value = mapCache[option];
  3312. if (!value) {
  3313. value = makeMap$2(defaultValue, ' ', makeMap$2(defaultValue.toUpperCase(), ' '));
  3314. value = extend$1(value, extendWith);
  3315. mapCache[option] = value;
  3316. }
  3317. } else {
  3318. value = makeMap$2(value, /[, ]/, makeMap$2(value.toUpperCase(), /[, ]/));
  3319. }
  3320. return value;
  3321. };
  3322. settings = settings || {};
  3323. schemaItems = compileSchema(settings.schema);
  3324. if (settings.verify_html === false) {
  3325. settings.valid_elements = '*[*]';
  3326. }
  3327. validStyles = compileElementMap(settings.valid_styles);
  3328. invalidStyles = compileElementMap(settings.invalid_styles, 'map');
  3329. validClasses = compileElementMap(settings.valid_classes, 'map');
  3330. whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea video audio iframe object code');
  3331. selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
  3332. shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link ' + 'meta param embed source wbr track');
  3333. boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize ' + 'noshade nowrap readonly selected autoplay loop controls');
  3334. nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object ' + 'script pre code', shortEndedElementsMap);
  3335. moveCaretBeforeOnEnterElementsMap = createLookupTable('move_caret_before_on_enter_elements', 'table', nonEmptyElementsMap);
  3336. textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' + 'blockquote center dir fieldset header footer article section hgroup aside main nav figure');
  3337. blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + 'th tr td li ol ul caption dl dt dd noscript menu isindex option ' + 'datalist select optgroup figcaption details summary', textBlockElementsMap);
  3338. textInlineElementsMap = createLookupTable('text_inline_elements', 'span strong b em i font strike u var cite ' + 'dfn code mark q sup sub samp');
  3339. each$3((settings.special || 'script noscript noframes noembed title style textarea xmp').split(' '), function (name) {
  3340. specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi');
  3341. });
  3342. var patternToRegExp = function (str) {
  3343. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  3344. };
  3345. var addValidElements = function (validElements) {
  3346. var ei, el, ai, al, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, prefix, outputName, globalAttributes, globalAttributesOrder, key, value;
  3347. var elementRuleRegExp = /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)\])?$/, attrRuleRegExp = /^([!\-])?(\w+[\\:]:\w+|[^=:<]+)?(?:([=:<])(.*))?$/, hasPatternsRegExp = /[*?+]/;
  3348. if (validElements) {
  3349. validElements = split(validElements, ',');
  3350. if (elements['@']) {
  3351. globalAttributes = elements['@'].attributes;
  3352. globalAttributesOrder = elements['@'].attributesOrder;
  3353. }
  3354. for (ei = 0, el = validElements.length; ei < el; ei++) {
  3355. matches = elementRuleRegExp.exec(validElements[ei]);
  3356. if (matches) {
  3357. prefix = matches[1];
  3358. elementName = matches[2];
  3359. outputName = matches[3];
  3360. attrData = matches[5];
  3361. attributes = {};
  3362. attributesOrder = [];
  3363. element = {
  3364. attributes: attributes,
  3365. attributesOrder: attributesOrder
  3366. };
  3367. if (prefix === '#') {
  3368. element.paddEmpty = true;
  3369. }
  3370. if (prefix === '-') {
  3371. element.removeEmpty = true;
  3372. }
  3373. if (matches[4] === '!') {
  3374. element.removeEmptyAttrs = true;
  3375. }
  3376. if (globalAttributes) {
  3377. for (key in globalAttributes) {
  3378. attributes[key] = globalAttributes[key];
  3379. }
  3380. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  3381. }
  3382. if (attrData) {
  3383. attrData = split(attrData, '|');
  3384. for (ai = 0, al = attrData.length; ai < al; ai++) {
  3385. matches = attrRuleRegExp.exec(attrData[ai]);
  3386. if (matches) {
  3387. attr = {};
  3388. attrType = matches[1];
  3389. attrName = matches[2].replace(/[\\:]:/g, ':');
  3390. prefix = matches[3];
  3391. value = matches[4];
  3392. if (attrType === '!') {
  3393. element.attributesRequired = element.attributesRequired || [];
  3394. element.attributesRequired.push(attrName);
  3395. attr.required = true;
  3396. }
  3397. if (attrType === '-') {
  3398. delete attributes[attrName];
  3399. attributesOrder.splice(inArray(attributesOrder, attrName), 1);
  3400. continue;
  3401. }
  3402. if (prefix) {
  3403. if (prefix === '=') {
  3404. element.attributesDefault = element.attributesDefault || [];
  3405. element.attributesDefault.push({
  3406. name: attrName,
  3407. value: value
  3408. });
  3409. attr.defaultValue = value;
  3410. }
  3411. if (prefix === ':') {
  3412. element.attributesForced = element.attributesForced || [];
  3413. element.attributesForced.push({
  3414. name: attrName,
  3415. value: value
  3416. });
  3417. attr.forcedValue = value;
  3418. }
  3419. if (prefix === '<') {
  3420. attr.validValues = makeMap$2(value, '?');
  3421. }
  3422. }
  3423. if (hasPatternsRegExp.test(attrName)) {
  3424. element.attributePatterns = element.attributePatterns || [];
  3425. attr.pattern = patternToRegExp(attrName);
  3426. element.attributePatterns.push(attr);
  3427. } else {
  3428. if (!attributes[attrName]) {
  3429. attributesOrder.push(attrName);
  3430. }
  3431. attributes[attrName] = attr;
  3432. }
  3433. }
  3434. }
  3435. }
  3436. if (!globalAttributes && elementName === '@') {
  3437. globalAttributes = attributes;
  3438. globalAttributesOrder = attributesOrder;
  3439. }
  3440. if (outputName) {
  3441. element.outputName = elementName;
  3442. elements[outputName] = element;
  3443. }
  3444. if (hasPatternsRegExp.test(elementName)) {
  3445. element.pattern = patternToRegExp(elementName);
  3446. patternElements.push(element);
  3447. } else {
  3448. elements[elementName] = element;
  3449. }
  3450. }
  3451. }
  3452. }
  3453. };
  3454. var setValidElements = function (validElements) {
  3455. elements = {};
  3456. patternElements = [];
  3457. addValidElements(validElements);
  3458. each$3(schemaItems, function (element, name) {
  3459. children[name] = element.children;
  3460. });
  3461. };
  3462. var addCustomElements = function (customElements) {
  3463. var customElementRegExp = /^(~)?(.+)$/;
  3464. if (customElements) {
  3465. mapCache.text_block_elements = mapCache.block_elements = null;
  3466. each$3(split(customElements, ','), function (rule) {
  3467. var matches = customElementRegExp.exec(rule), inline = matches[1] === '~', cloneName = inline ? 'span' : 'div', name = matches[2];
  3468. children[name] = children[cloneName];
  3469. customElementsMap[name] = cloneName;
  3470. if (!inline) {
  3471. blockElementsMap[name.toUpperCase()] = {};
  3472. blockElementsMap[name] = {};
  3473. }
  3474. if (!elements[name]) {
  3475. var customRule = elements[cloneName];
  3476. customRule = extend$1({}, customRule);
  3477. delete customRule.removeEmptyAttrs;
  3478. delete customRule.removeEmpty;
  3479. elements[name] = customRule;
  3480. }
  3481. each$3(children, function (element, elmName) {
  3482. if (element[cloneName]) {
  3483. children[elmName] = element = extend$1({}, children[elmName]);
  3484. element[name] = element[cloneName];
  3485. }
  3486. });
  3487. });
  3488. }
  3489. };
  3490. var addValidChildren = function (validChildren) {
  3491. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  3492. mapCache[settings.schema] = null;
  3493. if (validChildren) {
  3494. each$3(split(validChildren, ','), function (rule) {
  3495. var matches = childRuleRegExp.exec(rule);
  3496. var parent, prefix;
  3497. if (matches) {
  3498. prefix = matches[1];
  3499. if (prefix) {
  3500. parent = children[matches[2]];
  3501. } else {
  3502. parent = children[matches[2]] = { '#comment': {} };
  3503. }
  3504. parent = children[matches[2]];
  3505. each$3(split(matches[3], '|'), function (child) {
  3506. if (prefix === '-') {
  3507. delete parent[child];
  3508. } else {
  3509. parent[child] = {};
  3510. }
  3511. });
  3512. }
  3513. });
  3514. }
  3515. };
  3516. var getElementRule = function (name) {
  3517. var element = elements[name], i;
  3518. if (element) {
  3519. return element;
  3520. }
  3521. i = patternElements.length;
  3522. while (i--) {
  3523. element = patternElements[i];
  3524. if (element.pattern.test(name)) {
  3525. return element;
  3526. }
  3527. }
  3528. };
  3529. if (!settings.valid_elements) {
  3530. each$3(schemaItems, function (element, name) {
  3531. elements[name] = {
  3532. attributes: element.attributes,
  3533. attributesOrder: element.attributesOrder
  3534. };
  3535. children[name] = element.children;
  3536. });
  3537. if (settings.schema !== 'html5') {
  3538. each$3(split('strong/b em/i'), function (item) {
  3539. item = split(item, '/');
  3540. elements[item[1]].outputName = item[0];
  3541. });
  3542. }
  3543. each$3(split('ol ul sub sup blockquote span font a table tbody tr strong em b i'), function (name) {
  3544. if (elements[name]) {
  3545. elements[name].removeEmpty = true;
  3546. }
  3547. });
  3548. each$3(split('p h1 h2 h3 h4 h5 h6 th td pre div address caption li'), function (name) {
  3549. elements[name].paddEmpty = true;
  3550. });
  3551. each$3(split('span'), function (name) {
  3552. elements[name].removeEmptyAttrs = true;
  3553. });
  3554. } else {
  3555. setValidElements(settings.valid_elements);
  3556. }
  3557. addCustomElements(settings.custom_elements);
  3558. addValidChildren(settings.valid_children);
  3559. addValidElements(settings.extended_valid_elements);
  3560. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  3561. each$3({
  3562. dd: 'dl',
  3563. dt: 'dl',
  3564. li: 'ul ol',
  3565. td: 'tr',
  3566. th: 'tr',
  3567. tr: 'tbody thead tfoot',
  3568. tbody: 'table',
  3569. thead: 'table',
  3570. tfoot: 'table',
  3571. legend: 'fieldset',
  3572. area: 'map',
  3573. param: 'video audio object'
  3574. }, function (parents, item) {
  3575. if (elements[item]) {
  3576. elements[item].parentsRequired = split(parents);
  3577. }
  3578. });
  3579. if (settings.invalid_elements) {
  3580. each$3(explode$1(settings.invalid_elements), function (item) {
  3581. if (elements[item]) {
  3582. delete elements[item];
  3583. }
  3584. });
  3585. }
  3586. if (!getElementRule('span')) {
  3587. addValidElements('span[!data-mce-type|*]');
  3588. }
  3589. var getValidStyles = function () {
  3590. return validStyles;
  3591. };
  3592. var getInvalidStyles = function () {
  3593. return invalidStyles;
  3594. };
  3595. var getValidClasses = function () {
  3596. return validClasses;
  3597. };
  3598. var getBoolAttrs = function () {
  3599. return boolAttrMap;
  3600. };
  3601. var getBlockElements = function () {
  3602. return blockElementsMap;
  3603. };
  3604. var getTextBlockElements = function () {
  3605. return textBlockElementsMap;
  3606. };
  3607. var getTextInlineElements = function () {
  3608. return textInlineElementsMap;
  3609. };
  3610. var getShortEndedElements = function () {
  3611. return shortEndedElementsMap;
  3612. };
  3613. var getSelfClosingElements = function () {
  3614. return selfClosingElementsMap;
  3615. };
  3616. var getNonEmptyElements = function () {
  3617. return nonEmptyElementsMap;
  3618. };
  3619. var getMoveCaretBeforeOnEnterElements = function () {
  3620. return moveCaretBeforeOnEnterElementsMap;
  3621. };
  3622. var getWhiteSpaceElements = function () {
  3623. return whiteSpaceElementsMap;
  3624. };
  3625. var getSpecialElements = function () {
  3626. return specialElements;
  3627. };
  3628. var isValidChild = function (name, child) {
  3629. var parent = children[name.toLowerCase()];
  3630. return !!(parent && parent[child.toLowerCase()]);
  3631. };
  3632. var isValid = function (name, attr) {
  3633. var attrPatterns, i;
  3634. var rule = getElementRule(name);
  3635. if (rule) {
  3636. if (attr) {
  3637. if (rule.attributes[attr]) {
  3638. return true;
  3639. }
  3640. attrPatterns = rule.attributePatterns;
  3641. if (attrPatterns) {
  3642. i = attrPatterns.length;
  3643. while (i--) {
  3644. if (attrPatterns[i].pattern.test(name)) {
  3645. return true;
  3646. }
  3647. }
  3648. }
  3649. } else {
  3650. return true;
  3651. }
  3652. }
  3653. return false;
  3654. };
  3655. var getCustomElements = function () {
  3656. return customElementsMap;
  3657. };
  3658. return {
  3659. children: children,
  3660. elements: elements,
  3661. getValidStyles: getValidStyles,
  3662. getValidClasses: getValidClasses,
  3663. getBlockElements: getBlockElements,
  3664. getInvalidStyles: getInvalidStyles,
  3665. getShortEndedElements: getShortEndedElements,
  3666. getTextBlockElements: getTextBlockElements,
  3667. getTextInlineElements: getTextInlineElements,
  3668. getBoolAttrs: getBoolAttrs,
  3669. getElementRule: getElementRule,
  3670. getSelfClosingElements: getSelfClosingElements,
  3671. getNonEmptyElements: getNonEmptyElements,
  3672. getMoveCaretBeforeOnEnterElements: getMoveCaretBeforeOnEnterElements,
  3673. getWhiteSpaceElements: getWhiteSpaceElements,
  3674. getSpecialElements: getSpecialElements,
  3675. isValidChild: isValidChild,
  3676. isValid: isValid,
  3677. getCustomElements: getCustomElements,
  3678. addValidElements: addValidElements,
  3679. setValidElements: setValidElements,
  3680. addCustomElements: addCustomElements,
  3681. addValidChildren: addValidChildren
  3682. };
  3683. }
  3684. var toHex = function (match, r, g, b) {
  3685. var hex = function (val) {
  3686. val = parseInt(val, 10).toString(16);
  3687. return val.length > 1 ? val : '0' + val;
  3688. };
  3689. return '#' + hex(r) + hex(g) + hex(b);
  3690. };
  3691. var Styles = function (settings, schema) {
  3692. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi;
  3693. var urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi;
  3694. var styleRegExp = /\s*([^:]+):\s*([^;]+);?/g;
  3695. var trimRightRegExp = /\s+$/;
  3696. var i;
  3697. var encodingLookup = {};
  3698. var encodingItems;
  3699. var validStyles;
  3700. var invalidStyles;
  3701. var invisibleChar = '\uFEFF';
  3702. settings = settings || {};
  3703. if (schema) {
  3704. validStyles = schema.getValidStyles();
  3705. invalidStyles = schema.getInvalidStyles();
  3706. }
  3707. encodingItems = ('\\" \\\' \\; \\: ; : ' + invisibleChar).split(' ');
  3708. for (i = 0; i < encodingItems.length; i++) {
  3709. encodingLookup[encodingItems[i]] = invisibleChar + i;
  3710. encodingLookup[invisibleChar + i] = encodingItems[i];
  3711. }
  3712. return {
  3713. toHex: function (color) {
  3714. return color.replace(rgbRegExp, toHex);
  3715. },
  3716. parse: function (css) {
  3717. var styles = {};
  3718. var matches, name, value, isEncoded;
  3719. var urlConverter = settings.url_converter;
  3720. var urlConverterScope = settings.url_converter_scope || this;
  3721. var compress = function (prefix, suffix, noJoin) {
  3722. var top, right, bottom, left;
  3723. top = styles[prefix + '-top' + suffix];
  3724. if (!top) {
  3725. return;
  3726. }
  3727. right = styles[prefix + '-right' + suffix];
  3728. if (!right) {
  3729. return;
  3730. }
  3731. bottom = styles[prefix + '-bottom' + suffix];
  3732. if (!bottom) {
  3733. return;
  3734. }
  3735. left = styles[prefix + '-left' + suffix];
  3736. if (!left) {
  3737. return;
  3738. }
  3739. var box = [
  3740. top,
  3741. right,
  3742. bottom,
  3743. left
  3744. ];
  3745. i = box.length - 1;
  3746. while (i--) {
  3747. if (box[i] !== box[i + 1]) {
  3748. break;
  3749. }
  3750. }
  3751. if (i > -1 && noJoin) {
  3752. return;
  3753. }
  3754. styles[prefix + suffix] = i === -1 ? box[0] : box.join(' ');
  3755. delete styles[prefix + '-top' + suffix];
  3756. delete styles[prefix + '-right' + suffix];
  3757. delete styles[prefix + '-bottom' + suffix];
  3758. delete styles[prefix + '-left' + suffix];
  3759. };
  3760. var canCompress = function (key) {
  3761. var value = styles[key], i;
  3762. if (!value) {
  3763. return;
  3764. }
  3765. value = value.split(' ');
  3766. i = value.length;
  3767. while (i--) {
  3768. if (value[i] !== value[0]) {
  3769. return false;
  3770. }
  3771. }
  3772. styles[key] = value[0];
  3773. return true;
  3774. };
  3775. var compress2 = function (target, a, b, c) {
  3776. if (!canCompress(a)) {
  3777. return;
  3778. }
  3779. if (!canCompress(b)) {
  3780. return;
  3781. }
  3782. if (!canCompress(c)) {
  3783. return;
  3784. }
  3785. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  3786. delete styles[a];
  3787. delete styles[b];
  3788. delete styles[c];
  3789. };
  3790. var encode = function (str) {
  3791. isEncoded = true;
  3792. return encodingLookup[str];
  3793. };
  3794. var decode = function (str, keepSlashes) {
  3795. if (isEncoded) {
  3796. str = str.replace(/\uFEFF[0-9]/g, function (str) {
  3797. return encodingLookup[str];
  3798. });
  3799. }
  3800. if (!keepSlashes) {
  3801. str = str.replace(/\\([\'\";:])/g, '$1');
  3802. }
  3803. return str;
  3804. };
  3805. var decodeSingleHexSequence = function (escSeq) {
  3806. return String.fromCharCode(parseInt(escSeq.slice(1), 16));
  3807. };
  3808. var decodeHexSequences = function (value) {
  3809. return value.replace(/\\[0-9a-f]+/gi, decodeSingleHexSequence);
  3810. };
  3811. var processUrl = function (match, url, url2, url3, str, str2) {
  3812. str = str || str2;
  3813. if (str) {
  3814. str = decode(str);
  3815. return '\'' + str.replace(/\'/g, '\\\'') + '\'';
  3816. }
  3817. url = decode(url || url2 || url3);
  3818. if (!settings.allow_script_urls) {
  3819. var scriptUrl = url.replace(/[\s\r\n]+/g, '');
  3820. if (/(java|vb)script:/i.test(scriptUrl)) {
  3821. return '';
  3822. }
  3823. if (!settings.allow_svg_data_urls && /^data:image\/svg/i.test(scriptUrl)) {
  3824. return '';
  3825. }
  3826. }
  3827. if (urlConverter) {
  3828. url = urlConverter.call(urlConverterScope, url, 'style');
  3829. }
  3830. return 'url(\'' + url.replace(/\'/g, '\\\'') + '\')';
  3831. };
  3832. if (css) {
  3833. css = css.replace(/[\u0000-\u001F]/g, '');
  3834. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function (str) {
  3835. return str.replace(/[;:]/g, encode);
  3836. });
  3837. while (matches = styleRegExp.exec(css)) {
  3838. styleRegExp.lastIndex = matches.index + matches[0].length;
  3839. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  3840. value = matches[2].replace(trimRightRegExp, '');
  3841. if (name && value) {
  3842. name = decodeHexSequences(name);
  3843. value = decodeHexSequences(value);
  3844. if (name.indexOf(invisibleChar) !== -1 || name.indexOf('"') !== -1) {
  3845. continue;
  3846. }
  3847. if (!settings.allow_script_urls && (name === 'behavior' || /expression\s*\(|\/\*|\*\//.test(value))) {
  3848. continue;
  3849. }
  3850. if (name === 'font-weight' && value === '700') {
  3851. value = 'bold';
  3852. } else if (name === 'color' || name === 'background-color') {
  3853. value = value.toLowerCase();
  3854. }
  3855. value = value.replace(rgbRegExp, toHex);
  3856. value = value.replace(urlOrStrRegExp, processUrl);
  3857. styles[name] = isEncoded ? decode(value, true) : value;
  3858. }
  3859. }
  3860. compress('border', '', true);
  3861. compress('border', '-width');
  3862. compress('border', '-color');
  3863. compress('border', '-style');
  3864. compress('padding', '');
  3865. compress('margin', '');
  3866. compress2('border', 'border-width', 'border-style', 'border-color');
  3867. if (styles.border === 'medium none') {
  3868. delete styles.border;
  3869. }
  3870. if (styles['border-image'] === 'none') {
  3871. delete styles['border-image'];
  3872. }
  3873. }
  3874. return styles;
  3875. },
  3876. serialize: function (styles, elementName) {
  3877. var css = '', name, value;
  3878. var serializeStyles = function (name) {
  3879. var styleList, i, l, value;
  3880. styleList = validStyles[name];
  3881. if (styleList) {
  3882. for (i = 0, l = styleList.length; i < l; i++) {
  3883. name = styleList[i];
  3884. value = styles[name];
  3885. if (value) {
  3886. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  3887. }
  3888. }
  3889. }
  3890. };
  3891. var isValid = function (name, elementName) {
  3892. var styleMap;
  3893. styleMap = invalidStyles['*'];
  3894. if (styleMap && styleMap[name]) {
  3895. return false;
  3896. }
  3897. styleMap = invalidStyles[elementName];
  3898. if (styleMap && styleMap[name]) {
  3899. return false;
  3900. }
  3901. return true;
  3902. };
  3903. if (elementName && validStyles) {
  3904. serializeStyles('*');
  3905. serializeStyles(elementName);
  3906. } else {
  3907. for (name in styles) {
  3908. value = styles[name];
  3909. if (value && (!invalidStyles || isValid(name, elementName))) {
  3910. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  3911. }
  3912. }
  3913. }
  3914. return css;
  3915. }
  3916. };
  3917. };
  3918. var eventExpandoPrefix = 'mce-data-';
  3919. var mouseEventRe = /^(?:mouse|contextmenu)|click/;
  3920. var deprecated = {
  3921. keyLocation: 1,
  3922. layerX: 1,
  3923. layerY: 1,
  3924. returnValue: 1,
  3925. webkitMovementX: 1,
  3926. webkitMovementY: 1,
  3927. keyIdentifier: 1,
  3928. mozPressure: 1
  3929. };
  3930. var hasIsDefaultPrevented = function (event) {
  3931. return event.isDefaultPrevented === returnTrue || event.isDefaultPrevented === returnFalse;
  3932. };
  3933. var returnFalse = function () {
  3934. return false;
  3935. };
  3936. var returnTrue = function () {
  3937. return true;
  3938. };
  3939. var addEvent = function (target, name, callback, capture) {
  3940. if (target.addEventListener) {
  3941. target.addEventListener(name, callback, capture || false);
  3942. } else if (target.attachEvent) {
  3943. target.attachEvent('on' + name, callback);
  3944. }
  3945. };
  3946. var removeEvent = function (target, name, callback, capture) {
  3947. if (target.removeEventListener) {
  3948. target.removeEventListener(name, callback, capture || false);
  3949. } else if (target.detachEvent) {
  3950. target.detachEvent('on' + name, callback);
  3951. }
  3952. };
  3953. var getTargetFromShadowDom = function (event, defaultTarget) {
  3954. if (event.composedPath) {
  3955. var composedPath = event.composedPath();
  3956. if (composedPath && composedPath.length > 0) {
  3957. return composedPath[0];
  3958. }
  3959. }
  3960. return defaultTarget;
  3961. };
  3962. var fix = function (originalEvent, data) {
  3963. var name;
  3964. var event = data || {};
  3965. for (name in originalEvent) {
  3966. if (!deprecated[name]) {
  3967. event[name] = originalEvent[name];
  3968. }
  3969. }
  3970. if (!event.target) {
  3971. event.target = event.srcElement || domGlobals.document;
  3972. }
  3973. if (Env.experimentalShadowDom) {
  3974. event.target = getTargetFromShadowDom(originalEvent, event.target);
  3975. }
  3976. if (originalEvent && mouseEventRe.test(originalEvent.type) && originalEvent.pageX === undefined && originalEvent.clientX !== undefined) {
  3977. var eventDoc = event.target.ownerDocument || domGlobals.document;
  3978. var doc = eventDoc.documentElement;
  3979. var body = eventDoc.body;
  3980. event.pageX = originalEvent.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  3981. event.pageY = originalEvent.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  3982. }
  3983. event.preventDefault = function () {
  3984. event.isDefaultPrevented = returnTrue;
  3985. if (originalEvent) {
  3986. if (originalEvent.preventDefault) {
  3987. originalEvent.preventDefault();
  3988. } else {
  3989. originalEvent.returnValue = false;
  3990. }
  3991. }
  3992. };
  3993. event.stopPropagation = function () {
  3994. event.isPropagationStopped = returnTrue;
  3995. if (originalEvent) {
  3996. if (originalEvent.stopPropagation) {
  3997. originalEvent.stopPropagation();
  3998. } else {
  3999. originalEvent.cancelBubble = true;
  4000. }
  4001. }
  4002. };
  4003. event.stopImmediatePropagation = function () {
  4004. event.isImmediatePropagationStopped = returnTrue;
  4005. event.stopPropagation();
  4006. };
  4007. if (hasIsDefaultPrevented(event) === false) {
  4008. event.isDefaultPrevented = returnFalse;
  4009. event.isPropagationStopped = returnFalse;
  4010. event.isImmediatePropagationStopped = returnFalse;
  4011. }
  4012. if (typeof event.metaKey === 'undefined') {
  4013. event.metaKey = false;
  4014. }
  4015. return event;
  4016. };
  4017. var bindOnReady = function (win, callback, eventUtils) {
  4018. var doc = win.document, event = { type: 'ready' };
  4019. if (eventUtils.domLoaded) {
  4020. callback(event);
  4021. return;
  4022. }
  4023. var isDocReady = function () {
  4024. return doc.readyState === 'complete' || doc.readyState === 'interactive' && doc.body;
  4025. };
  4026. var readyHandler = function () {
  4027. removeEvent(win, 'DOMContentLoaded', readyHandler);
  4028. removeEvent(win, 'load', readyHandler);
  4029. if (!eventUtils.domLoaded) {
  4030. eventUtils.domLoaded = true;
  4031. callback(event);
  4032. }
  4033. };
  4034. if (isDocReady()) {
  4035. readyHandler();
  4036. } else {
  4037. addEvent(win, 'DOMContentLoaded', readyHandler);
  4038. }
  4039. addEvent(win, 'load', readyHandler);
  4040. };
  4041. var EventUtils = function () {
  4042. function EventUtils() {
  4043. this.domLoaded = false;
  4044. this.events = {};
  4045. this.count = 1;
  4046. this.expando = eventExpandoPrefix + (+new Date()).toString(32);
  4047. this.hasMouseEnterLeave = 'onmouseenter' in domGlobals.document.documentElement;
  4048. this.hasFocusIn = 'onfocusin' in domGlobals.document.documentElement;
  4049. this.count = 1;
  4050. }
  4051. EventUtils.prototype.bind = function (target, names, callback, scope) {
  4052. var self = this;
  4053. var id, callbackList, i, name, fakeName, nativeHandler, capture;
  4054. var win = domGlobals.window;
  4055. var defaultNativeHandler = function (evt) {
  4056. self.executeHandlers(fix(evt || win.event), id);
  4057. };
  4058. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4059. return;
  4060. }
  4061. if (!target[self.expando]) {
  4062. id = self.count++;
  4063. target[self.expando] = id;
  4064. self.events[id] = {};
  4065. } else {
  4066. id = target[self.expando];
  4067. }
  4068. scope = scope || target;
  4069. var namesList = names.split(' ');
  4070. i = namesList.length;
  4071. while (i--) {
  4072. name = namesList[i];
  4073. nativeHandler = defaultNativeHandler;
  4074. fakeName = capture = false;
  4075. if (name === 'DOMContentLoaded') {
  4076. name = 'ready';
  4077. }
  4078. if (self.domLoaded && name === 'ready' && target.readyState === 'complete') {
  4079. callback.call(scope, fix({ type: name }));
  4080. continue;
  4081. }
  4082. if (!self.hasMouseEnterLeave) {
  4083. fakeName = self.mouseEnterLeave[name];
  4084. if (fakeName) {
  4085. nativeHandler = function (evt) {
  4086. var current, related;
  4087. current = evt.currentTarget;
  4088. related = evt.relatedTarget;
  4089. if (related && current.contains) {
  4090. related = current.contains(related);
  4091. } else {
  4092. while (related && related !== current) {
  4093. related = related.parentNode;
  4094. }
  4095. }
  4096. if (!related) {
  4097. evt = fix(evt || win.event);
  4098. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
  4099. evt.target = current;
  4100. self.executeHandlers(evt, id);
  4101. }
  4102. };
  4103. }
  4104. }
  4105. if (!self.hasFocusIn && (name === 'focusin' || name === 'focusout')) {
  4106. capture = true;
  4107. fakeName = name === 'focusin' ? 'focus' : 'blur';
  4108. nativeHandler = function (evt) {
  4109. evt = fix(evt || win.event);
  4110. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
  4111. self.executeHandlers(evt, id);
  4112. };
  4113. }
  4114. callbackList = self.events[id][name];
  4115. if (!callbackList) {
  4116. self.events[id][name] = callbackList = [{
  4117. func: callback,
  4118. scope: scope
  4119. }];
  4120. callbackList.fakeName = fakeName;
  4121. callbackList.capture = capture;
  4122. callbackList.nativeHandler = nativeHandler;
  4123. if (name === 'ready') {
  4124. bindOnReady(target, nativeHandler, self);
  4125. } else {
  4126. addEvent(target, fakeName || name, nativeHandler, capture);
  4127. }
  4128. } else {
  4129. if (name === 'ready' && self.domLoaded) {
  4130. callback(fix({ type: name }));
  4131. } else {
  4132. callbackList.push({
  4133. func: callback,
  4134. scope: scope
  4135. });
  4136. }
  4137. }
  4138. }
  4139. target = callbackList = 0;
  4140. return callback;
  4141. };
  4142. EventUtils.prototype.unbind = function (target, names, callback) {
  4143. var id, callbackList, i, ci, name, eventMap;
  4144. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4145. return this;
  4146. }
  4147. id = target[this.expando];
  4148. if (id) {
  4149. eventMap = this.events[id];
  4150. if (names) {
  4151. var namesList = names.split(' ');
  4152. i = namesList.length;
  4153. while (i--) {
  4154. name = namesList[i];
  4155. callbackList = eventMap[name];
  4156. if (callbackList) {
  4157. if (callback) {
  4158. ci = callbackList.length;
  4159. while (ci--) {
  4160. if (callbackList[ci].func === callback) {
  4161. var nativeHandler = callbackList.nativeHandler;
  4162. var fakeName = callbackList.fakeName, capture = callbackList.capture;
  4163. callbackList = callbackList.slice(0, ci).concat(callbackList.slice(ci + 1));
  4164. callbackList.nativeHandler = nativeHandler;
  4165. callbackList.fakeName = fakeName;
  4166. callbackList.capture = capture;
  4167. eventMap[name] = callbackList;
  4168. }
  4169. }
  4170. }
  4171. if (!callback || callbackList.length === 0) {
  4172. delete eventMap[name];
  4173. removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
  4174. }
  4175. }
  4176. }
  4177. } else {
  4178. for (name in eventMap) {
  4179. callbackList = eventMap[name];
  4180. removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
  4181. }
  4182. eventMap = {};
  4183. }
  4184. for (name in eventMap) {
  4185. return this;
  4186. }
  4187. delete this.events[id];
  4188. try {
  4189. delete target[this.expando];
  4190. } catch (ex) {
  4191. target[this.expando] = null;
  4192. }
  4193. }
  4194. return this;
  4195. };
  4196. EventUtils.prototype.fire = function (target, name, args) {
  4197. var id;
  4198. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4199. return this;
  4200. }
  4201. var event = fix(null, args);
  4202. event.type = name;
  4203. event.target = target;
  4204. do {
  4205. id = target[this.expando];
  4206. if (id) {
  4207. this.executeHandlers(event, id);
  4208. }
  4209. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  4210. } while (target && !event.isPropagationStopped());
  4211. return this;
  4212. };
  4213. EventUtils.prototype.clean = function (target) {
  4214. var i, children;
  4215. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4216. return this;
  4217. }
  4218. if (target[this.expando]) {
  4219. this.unbind(target);
  4220. }
  4221. if (!target.getElementsByTagName) {
  4222. target = target.document;
  4223. }
  4224. if (target && target.getElementsByTagName) {
  4225. this.unbind(target);
  4226. children = target.getElementsByTagName('*');
  4227. i = children.length;
  4228. while (i--) {
  4229. target = children[i];
  4230. if (target[this.expando]) {
  4231. this.unbind(target);
  4232. }
  4233. }
  4234. }
  4235. return this;
  4236. };
  4237. EventUtils.prototype.destroy = function () {
  4238. this.events = {};
  4239. };
  4240. EventUtils.prototype.cancel = function (e) {
  4241. if (e) {
  4242. e.preventDefault();
  4243. e.stopImmediatePropagation();
  4244. }
  4245. return false;
  4246. };
  4247. EventUtils.prototype.executeHandlers = function (evt, id) {
  4248. var callbackList, i, l, callback;
  4249. var container = this.events[id];
  4250. callbackList = container && container[evt.type];
  4251. if (callbackList) {
  4252. for (i = 0, l = callbackList.length; i < l; i++) {
  4253. callback = callbackList[i];
  4254. if (callback && callback.func.call(callback.scope, evt) === false) {
  4255. evt.preventDefault();
  4256. }
  4257. if (evt.isImmediatePropagationStopped()) {
  4258. return;
  4259. }
  4260. }
  4261. }
  4262. };
  4263. EventUtils.Event = new EventUtils();
  4264. return EventUtils;
  4265. }();
  4266. var i, support, Expr, getText, isXML, tokenize, compile, select, outermostContext, sortInput, hasDuplicate, setDocument, document, docElem, documentIsHTML, rbuggyQSA, rbuggyMatches, matches, contains$3, expando = 'sizzle' + -new Date(), preferredDoc = domGlobals.window.document, dirruns = 0, done = 0, classCache = createCache(), tokenCache = createCache(), compilerCache = createCache(), sortOrder = function (a, b) {
  4267. if (a === b) {
  4268. hasDuplicate = true;
  4269. }
  4270. return 0;
  4271. }, strundefined = typeof undefined, MAX_NEGATIVE = 1 << 31, hasOwn = {}.hasOwnProperty, arr = [], pop = arr.pop, push_native = arr.push, push = arr.push, slice = arr.slice, indexOf$2 = arr.indexOf || function (elem) {
  4272. var i = 0, len = this.length;
  4273. for (; i < len; i++) {
  4274. if (this[i] === elem) {
  4275. return i;
  4276. }
  4277. }
  4278. return -1;
  4279. }, booleans = 'checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped', whitespace = '[\\x20\\t\\r\\n\\f]', identifier = '(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+', attributes = '\\[' + whitespace + '*(' + identifier + ')(?:' + whitespace + '*([*^$|!~]?=)' + whitespace + '*(?:\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)"|(' + identifier + '))|)' + whitespace + '*\\]', pseudos = ':(' + identifier + ')(?:\\((' + '(\'((?:\\\\.|[^\\\\\'])*)\'|"((?:\\\\.|[^\\\\"])*)")|' + '((?:\\\\.|[^\\\\()[\\]]|' + attributes + ')*)|' + '.*' + ')\\)|)', rtrim = new RegExp('^' + whitespace + '+|((?:^|[^\\\\])(?:\\\\.)*)' + whitespace + '+$', 'g'), rcomma = new RegExp('^' + whitespace + '*,' + whitespace + '*'), rcombinators = new RegExp('^' + whitespace + '*([>+~]|' + whitespace + ')' + whitespace + '*'), rattributeQuotes = new RegExp('=' + whitespace + '*([^\\]\'"]*?)' + whitespace + '*\\]', 'g'), rpseudo = new RegExp(pseudos), ridentifier = new RegExp('^' + identifier + '$'), matchExpr = {
  4280. ID: new RegExp('^#(' + identifier + ')'),
  4281. CLASS: new RegExp('^\\.(' + identifier + ')'),
  4282. TAG: new RegExp('^(' + identifier + '|[*])'),
  4283. ATTR: new RegExp('^' + attributes),
  4284. PSEUDO: new RegExp('^' + pseudos),
  4285. CHILD: new RegExp('^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(' + whitespace + '*(even|odd|(([+-]|)(\\d*)n|)' + whitespace + '*(?:([+-]|)' + whitespace + '*(\\d+)|))' + whitespace + '*\\)|)', 'i'),
  4286. bool: new RegExp('^(?:' + booleans + ')$', 'i'),
  4287. needsContext: new RegExp('^' + whitespace + '*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(' + whitespace + '*((?:-\\d)?\\d*)' + whitespace + '*\\)|)(?=[^-]|$)', 'i')
  4288. }, rinputs = /^(?:input|select|textarea|button)$/i, rheader = /^h\d$/i, rnative = /^[^{]+\{\s*\[native \w/, rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, rsibling = /[+~]/, rescape = /'|\\/g, runescape = new RegExp('\\\\([\\da-f]{1,6}' + whitespace + '?|(' + whitespace + ')|.)', 'ig'), funescape = function (_, escaped, escapedWhitespace) {
  4289. var high = '0x' + escaped - 65536;
  4290. return high !== high || escapedWhitespace ? escaped : high < 0 ? String.fromCharCode(high + 65536) : String.fromCharCode(high >> 10 | 55296, high & 1023 | 56320);
  4291. };
  4292. try {
  4293. push.apply(arr = slice.call(preferredDoc.childNodes), preferredDoc.childNodes);
  4294. arr[preferredDoc.childNodes.length].nodeType;
  4295. } catch (e) {
  4296. push = {
  4297. apply: arr.length ? function (target, els) {
  4298. push_native.apply(target, slice.call(els));
  4299. } : function (target, els) {
  4300. var j = target.length, i = 0;
  4301. while (target[j++] = els[i++]) {
  4302. }
  4303. target.length = j - 1;
  4304. }
  4305. };
  4306. }
  4307. var Sizzle = function (selector, context, results, seed) {
  4308. var match, elem, m, nodeType, i, groups, old, nid, newContext, newSelector;
  4309. if ((context ? context.ownerDocument || context : preferredDoc) !== document) {
  4310. setDocument(context);
  4311. }
  4312. context = context || document;
  4313. results = results || [];
  4314. if (!selector || typeof selector !== 'string') {
  4315. return results;
  4316. }
  4317. if ((nodeType = context.nodeType) !== 1 && nodeType !== 9) {
  4318. return [];
  4319. }
  4320. if (documentIsHTML && !seed) {
  4321. if (match = rquickExpr.exec(selector)) {
  4322. if (m = match[1]) {
  4323. if (nodeType === 9) {
  4324. elem = context.getElementById(m);
  4325. if (elem && elem.parentNode) {
  4326. if (elem.id === m) {
  4327. results.push(elem);
  4328. return results;
  4329. }
  4330. } else {
  4331. return results;
  4332. }
  4333. } else {
  4334. if (context.ownerDocument && (elem = context.ownerDocument.getElementById(m)) && contains$3(context, elem) && elem.id === m) {
  4335. results.push(elem);
  4336. return results;
  4337. }
  4338. }
  4339. } else if (match[2]) {
  4340. push.apply(results, context.getElementsByTagName(selector));
  4341. return results;
  4342. } else if ((m = match[3]) && support.getElementsByClassName) {
  4343. push.apply(results, context.getElementsByClassName(m));
  4344. return results;
  4345. }
  4346. }
  4347. if (support.qsa && (!rbuggyQSA || !rbuggyQSA.test(selector))) {
  4348. nid = old = expando;
  4349. newContext = context;
  4350. newSelector = nodeType === 9 && selector;
  4351. if (nodeType === 1 && context.nodeName.toLowerCase() !== 'object') {
  4352. groups = tokenize(selector);
  4353. if (old = context.getAttribute('id')) {
  4354. nid = old.replace(rescape, '\\$&');
  4355. } else {
  4356. context.setAttribute('id', nid);
  4357. }
  4358. nid = '[id=\'' + nid + '\'] ';
  4359. i = groups.length;
  4360. while (i--) {
  4361. groups[i] = nid + toSelector(groups[i]);
  4362. }
  4363. newContext = rsibling.test(selector) && testContext(context.parentNode) || context;
  4364. newSelector = groups.join(',');
  4365. }
  4366. if (newSelector) {
  4367. try {
  4368. push.apply(results, newContext.querySelectorAll(newSelector));
  4369. return results;
  4370. } catch (qsaError) {
  4371. } finally {
  4372. if (!old) {
  4373. context.removeAttribute('id');
  4374. }
  4375. }
  4376. }
  4377. }
  4378. }
  4379. return select(selector.replace(rtrim, '$1'), context, results, seed);
  4380. };
  4381. function createCache() {
  4382. var keys = [];
  4383. function cache(key, value) {
  4384. if (keys.push(key + ' ') > Expr.cacheLength) {
  4385. delete cache[keys.shift()];
  4386. }
  4387. return cache[key + ' '] = value;
  4388. }
  4389. return cache;
  4390. }
  4391. function markFunction(fn) {
  4392. fn[expando] = true;
  4393. return fn;
  4394. }
  4395. function siblingCheck(a, b) {
  4396. var cur = b && a, diff = cur && a.nodeType === 1 && b.nodeType === 1 && (~b.sourceIndex || MAX_NEGATIVE) - (~a.sourceIndex || MAX_NEGATIVE);
  4397. if (diff) {
  4398. return diff;
  4399. }
  4400. if (cur) {
  4401. while (cur = cur.nextSibling) {
  4402. if (cur === b) {
  4403. return -1;
  4404. }
  4405. }
  4406. }
  4407. return a ? 1 : -1;
  4408. }
  4409. function createInputPseudo(type) {
  4410. return function (elem) {
  4411. var name = elem.nodeName.toLowerCase();
  4412. return name === 'input' && elem.type === type;
  4413. };
  4414. }
  4415. function createButtonPseudo(type) {
  4416. return function (elem) {
  4417. var name = elem.nodeName.toLowerCase();
  4418. return (name === 'input' || name === 'button') && elem.type === type;
  4419. };
  4420. }
  4421. function createPositionalPseudo(fn) {
  4422. return markFunction(function (argument) {
  4423. argument = +argument;
  4424. return markFunction(function (seed, matches) {
  4425. var j, matchIndexes = fn([], seed.length, argument), i = matchIndexes.length;
  4426. while (i--) {
  4427. if (seed[j = matchIndexes[i]]) {
  4428. seed[j] = !(matches[j] = seed[j]);
  4429. }
  4430. }
  4431. });
  4432. });
  4433. }
  4434. function testContext(context) {
  4435. return context && typeof context.getElementsByTagName !== strundefined && context;
  4436. }
  4437. support = Sizzle.support = {};
  4438. isXML = Sizzle.isXML = function (elem) {
  4439. var documentElement = elem && (elem.ownerDocument || elem).documentElement;
  4440. return documentElement ? documentElement.nodeName !== 'HTML' : false;
  4441. };
  4442. setDocument = Sizzle.setDocument = function (node) {
  4443. var hasCompare, doc = node ? node.ownerDocument || node : preferredDoc, parent = doc.defaultView;
  4444. function getTop(win) {
  4445. try {
  4446. return win.top;
  4447. } catch (ex) {
  4448. }
  4449. return null;
  4450. }
  4451. if (doc === document || doc.nodeType !== 9 || !doc.documentElement) {
  4452. return document;
  4453. }
  4454. document = doc;
  4455. docElem = doc.documentElement;
  4456. documentIsHTML = !isXML(doc);
  4457. if (parent && parent !== getTop(parent)) {
  4458. if (parent.addEventListener) {
  4459. parent.addEventListener('unload', function () {
  4460. setDocument();
  4461. }, false);
  4462. } else if (parent.attachEvent) {
  4463. parent.attachEvent('onunload', function () {
  4464. setDocument();
  4465. });
  4466. }
  4467. }
  4468. support.attributes = true;
  4469. support.getElementsByTagName = true;
  4470. support.getElementsByClassName = rnative.test(doc.getElementsByClassName);
  4471. support.getById = true;
  4472. Expr.find.ID = function (id, context) {
  4473. if (typeof context.getElementById !== strundefined && documentIsHTML) {
  4474. var m = context.getElementById(id);
  4475. return m && m.parentNode ? [m] : [];
  4476. }
  4477. };
  4478. Expr.filter.ID = function (id) {
  4479. var attrId = id.replace(runescape, funescape);
  4480. return function (elem) {
  4481. return elem.getAttribute('id') === attrId;
  4482. };
  4483. };
  4484. Expr.find.TAG = support.getElementsByTagName ? function (tag, context) {
  4485. if (typeof context.getElementsByTagName !== strundefined) {
  4486. return context.getElementsByTagName(tag);
  4487. }
  4488. } : function (tag, context) {
  4489. var elem, tmp = [], i = 0, results = context.getElementsByTagName(tag);
  4490. if (tag === '*') {
  4491. while (elem = results[i++]) {
  4492. if (elem.nodeType === 1) {
  4493. tmp.push(elem);
  4494. }
  4495. }
  4496. return tmp;
  4497. }
  4498. return results;
  4499. };
  4500. Expr.find.CLASS = support.getElementsByClassName && function (className, context) {
  4501. if (documentIsHTML) {
  4502. return context.getElementsByClassName(className);
  4503. }
  4504. };
  4505. rbuggyMatches = [];
  4506. rbuggyQSA = [];
  4507. support.disconnectedMatch = true;
  4508. rbuggyQSA = rbuggyQSA.length && new RegExp(rbuggyQSA.join('|'));
  4509. rbuggyMatches = rbuggyMatches.length && new RegExp(rbuggyMatches.join('|'));
  4510. hasCompare = rnative.test(docElem.compareDocumentPosition);
  4511. contains$3 = hasCompare || rnative.test(docElem.contains) ? function (a, b) {
  4512. var adown = a.nodeType === 9 ? a.documentElement : a, bup = b && b.parentNode;
  4513. return a === bup || !!(bup && bup.nodeType === 1 && (adown.contains ? adown.contains(bup) : a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16));
  4514. } : function (a, b) {
  4515. if (b) {
  4516. while (b = b.parentNode) {
  4517. if (b === a) {
  4518. return true;
  4519. }
  4520. }
  4521. }
  4522. return false;
  4523. };
  4524. sortOrder = hasCompare ? function (a, b) {
  4525. if (a === b) {
  4526. hasDuplicate = true;
  4527. return 0;
  4528. }
  4529. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  4530. if (compare) {
  4531. return compare;
  4532. }
  4533. compare = (a.ownerDocument || a) === (b.ownerDocument || b) ? a.compareDocumentPosition(b) : 1;
  4534. if (compare & 1 || !support.sortDetached && b.compareDocumentPosition(a) === compare) {
  4535. if (a === doc || a.ownerDocument === preferredDoc && contains$3(preferredDoc, a)) {
  4536. return -1;
  4537. }
  4538. if (b === doc || b.ownerDocument === preferredDoc && contains$3(preferredDoc, b)) {
  4539. return 1;
  4540. }
  4541. return sortInput ? indexOf$2.call(sortInput, a) - indexOf$2.call(sortInput, b) : 0;
  4542. }
  4543. return compare & 4 ? -1 : 1;
  4544. } : function (a, b) {
  4545. if (a === b) {
  4546. hasDuplicate = true;
  4547. return 0;
  4548. }
  4549. var cur, i = 0, aup = a.parentNode, bup = b.parentNode, ap = [a], bp = [b];
  4550. if (!aup || !bup) {
  4551. return a === doc ? -1 : b === doc ? 1 : aup ? -1 : bup ? 1 : sortInput ? indexOf$2.call(sortInput, a) - indexOf$2.call(sortInput, b) : 0;
  4552. } else if (aup === bup) {
  4553. return siblingCheck(a, b);
  4554. }
  4555. cur = a;
  4556. while (cur = cur.parentNode) {
  4557. ap.unshift(cur);
  4558. }
  4559. cur = b;
  4560. while (cur = cur.parentNode) {
  4561. bp.unshift(cur);
  4562. }
  4563. while (ap[i] === bp[i]) {
  4564. i++;
  4565. }
  4566. return i ? siblingCheck(ap[i], bp[i]) : ap[i] === preferredDoc ? -1 : bp[i] === preferredDoc ? 1 : 0;
  4567. };
  4568. return doc;
  4569. };
  4570. Sizzle.matches = function (expr, elements) {
  4571. return Sizzle(expr, null, null, elements);
  4572. };
  4573. Sizzle.matchesSelector = function (elem, expr) {
  4574. if ((elem.ownerDocument || elem) !== document) {
  4575. setDocument(elem);
  4576. }
  4577. expr = expr.replace(rattributeQuotes, '=\'$1\']');
  4578. if (support.matchesSelector && documentIsHTML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && (!rbuggyQSA || !rbuggyQSA.test(expr))) {
  4579. try {
  4580. var ret = matches.call(elem, expr);
  4581. if (ret || support.disconnectedMatch || elem.document && elem.document.nodeType !== 11) {
  4582. return ret;
  4583. }
  4584. } catch (e) {
  4585. }
  4586. }
  4587. return Sizzle(expr, document, null, [elem]).length > 0;
  4588. };
  4589. Sizzle.contains = function (context, elem) {
  4590. if ((context.ownerDocument || context) !== document) {
  4591. setDocument(context);
  4592. }
  4593. return contains$3(context, elem);
  4594. };
  4595. Sizzle.attr = function (elem, name) {
  4596. if ((elem.ownerDocument || elem) !== document) {
  4597. setDocument(elem);
  4598. }
  4599. var fn = Expr.attrHandle[name.toLowerCase()], val = fn && hasOwn.call(Expr.attrHandle, name.toLowerCase()) ? fn(elem, name, !documentIsHTML) : undefined;
  4600. return val !== undefined ? val : support.attributes || !documentIsHTML ? elem.getAttribute(name) : (val = elem.getAttributeNode(name)) && val.specified ? val.value : null;
  4601. };
  4602. Sizzle.error = function (msg) {
  4603. throw new Error('Syntax error, unrecognized expression: ' + msg);
  4604. };
  4605. Sizzle.uniqueSort = function (results) {
  4606. var elem, duplicates = [], j = 0, i = 0;
  4607. hasDuplicate = !support.detectDuplicates;
  4608. sortInput = !support.sortStable && results.slice(0);
  4609. results.sort(sortOrder);
  4610. if (hasDuplicate) {
  4611. while (elem = results[i++]) {
  4612. if (elem === results[i]) {
  4613. j = duplicates.push(i);
  4614. }
  4615. }
  4616. while (j--) {
  4617. results.splice(duplicates[j], 1);
  4618. }
  4619. }
  4620. sortInput = null;
  4621. return results;
  4622. };
  4623. getText = Sizzle.getText = function (elem) {
  4624. var node, ret = '', i = 0, nodeType = elem.nodeType;
  4625. if (!nodeType) {
  4626. while (node = elem[i++]) {
  4627. ret += getText(node);
  4628. }
  4629. } else if (nodeType === 1 || nodeType === 9 || nodeType === 11) {
  4630. if (typeof elem.textContent === 'string') {
  4631. return elem.textContent;
  4632. } else {
  4633. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  4634. ret += getText(elem);
  4635. }
  4636. }
  4637. } else if (nodeType === 3 || nodeType === 4) {
  4638. return elem.nodeValue;
  4639. }
  4640. return ret;
  4641. };
  4642. Expr = Sizzle.selectors = {
  4643. cacheLength: 50,
  4644. createPseudo: markFunction,
  4645. match: matchExpr,
  4646. attrHandle: {},
  4647. find: {},
  4648. relative: {
  4649. '>': {
  4650. dir: 'parentNode',
  4651. first: true
  4652. },
  4653. ' ': { dir: 'parentNode' },
  4654. '+': {
  4655. dir: 'previousSibling',
  4656. first: true
  4657. },
  4658. '~': { dir: 'previousSibling' }
  4659. },
  4660. preFilter: {
  4661. ATTR: function (match) {
  4662. match[1] = match[1].replace(runescape, funescape);
  4663. match[3] = (match[3] || match[4] || match[5] || '').replace(runescape, funescape);
  4664. if (match[2] === '~=') {
  4665. match[3] = ' ' + match[3] + ' ';
  4666. }
  4667. return match.slice(0, 4);
  4668. },
  4669. CHILD: function (match) {
  4670. match[1] = match[1].toLowerCase();
  4671. if (match[1].slice(0, 3) === 'nth') {
  4672. if (!match[3]) {
  4673. Sizzle.error(match[0]);
  4674. }
  4675. match[4] = +(match[4] ? match[5] + (match[6] || 1) : 2 * (match[3] === 'even' || match[3] === 'odd'));
  4676. match[5] = +(match[7] + match[8] || match[3] === 'odd');
  4677. } else if (match[3]) {
  4678. Sizzle.error(match[0]);
  4679. }
  4680. return match;
  4681. },
  4682. PSEUDO: function (match) {
  4683. var excess, unquoted = !match[6] && match[2];
  4684. if (matchExpr.CHILD.test(match[0])) {
  4685. return null;
  4686. }
  4687. if (match[3]) {
  4688. match[2] = match[4] || match[5] || '';
  4689. } else if (unquoted && rpseudo.test(unquoted) && (excess = tokenize(unquoted, true)) && (excess = unquoted.indexOf(')', unquoted.length - excess) - unquoted.length)) {
  4690. match[0] = match[0].slice(0, excess);
  4691. match[2] = unquoted.slice(0, excess);
  4692. }
  4693. return match.slice(0, 3);
  4694. }
  4695. },
  4696. filter: {
  4697. TAG: function (nodeNameSelector) {
  4698. var nodeName = nodeNameSelector.replace(runescape, funescape).toLowerCase();
  4699. return nodeNameSelector === '*' ? function () {
  4700. return true;
  4701. } : function (elem) {
  4702. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  4703. };
  4704. },
  4705. CLASS: function (className) {
  4706. var pattern = classCache[className + ' '];
  4707. return pattern || (pattern = new RegExp('(^|' + whitespace + ')' + className + '(' + whitespace + '|$)')) && classCache(className, function (elem) {
  4708. return pattern.test(typeof elem.className === 'string' && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute('class') || '');
  4709. });
  4710. },
  4711. ATTR: function (name, operator, check) {
  4712. return function (elem) {
  4713. var result = Sizzle.attr(elem, name);
  4714. if (result == null) {
  4715. return operator === '!=';
  4716. }
  4717. if (!operator) {
  4718. return true;
  4719. }
  4720. result += '';
  4721. return operator === '=' ? result === check : operator === '!=' ? result !== check : operator === '^=' ? check && result.indexOf(check) === 0 : operator === '*=' ? check && result.indexOf(check) > -1 : operator === '$=' ? check && result.slice(-check.length) === check : operator === '~=' ? (' ' + result + ' ').indexOf(check) > -1 : operator === '|=' ? result === check || result.slice(0, check.length + 1) === check + '-' : false;
  4722. };
  4723. },
  4724. CHILD: function (type, what, argument, first, last) {
  4725. var simple = type.slice(0, 3) !== 'nth', forward = type.slice(-4) !== 'last', ofType = what === 'of-type';
  4726. return first === 1 && last === 0 ? function (elem) {
  4727. return !!elem.parentNode;
  4728. } : function (elem, context, xml) {
  4729. var cache, outerCache, node, diff, nodeIndex, start, dir = simple !== forward ? 'nextSibling' : 'previousSibling', parent = elem.parentNode, name = ofType && elem.nodeName.toLowerCase(), useCache = !xml && !ofType;
  4730. if (parent) {
  4731. if (simple) {
  4732. while (dir) {
  4733. node = elem;
  4734. while (node = node[dir]) {
  4735. if (ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) {
  4736. return false;
  4737. }
  4738. }
  4739. start = dir = type === 'only' && !start && 'nextSibling';
  4740. }
  4741. return true;
  4742. }
  4743. start = [forward ? parent.firstChild : parent.lastChild];
  4744. if (forward && useCache) {
  4745. outerCache = parent[expando] || (parent[expando] = {});
  4746. cache = outerCache[type] || [];
  4747. nodeIndex = cache[0] === dirruns && cache[1];
  4748. diff = cache[0] === dirruns && cache[2];
  4749. node = nodeIndex && parent.childNodes[nodeIndex];
  4750. while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) {
  4751. if (node.nodeType === 1 && ++diff && node === elem) {
  4752. outerCache[type] = [
  4753. dirruns,
  4754. nodeIndex,
  4755. diff
  4756. ];
  4757. break;
  4758. }
  4759. }
  4760. } else if (useCache && (cache = (elem[expando] || (elem[expando] = {}))[type]) && cache[0] === dirruns) {
  4761. diff = cache[1];
  4762. } else {
  4763. while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) {
  4764. if ((ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) && ++diff) {
  4765. if (useCache) {
  4766. (node[expando] || (node[expando] = {}))[type] = [
  4767. dirruns,
  4768. diff
  4769. ];
  4770. }
  4771. if (node === elem) {
  4772. break;
  4773. }
  4774. }
  4775. }
  4776. }
  4777. diff -= last;
  4778. return diff === first || diff % first === 0 && diff / first >= 0;
  4779. }
  4780. };
  4781. },
  4782. PSEUDO: function (pseudo, argument) {
  4783. var args, fn = Expr.pseudos[pseudo] || Expr.setFilters[pseudo.toLowerCase()] || Sizzle.error('unsupported pseudo: ' + pseudo);
  4784. if (fn[expando]) {
  4785. return fn(argument);
  4786. }
  4787. if (fn.length > 1) {
  4788. args = [
  4789. pseudo,
  4790. pseudo,
  4791. '',
  4792. argument
  4793. ];
  4794. return Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function (seed, matches) {
  4795. var idx, matched = fn(seed, argument), i = matched.length;
  4796. while (i--) {
  4797. idx = indexOf$2.call(seed, matched[i]);
  4798. seed[idx] = !(matches[idx] = matched[i]);
  4799. }
  4800. }) : function (elem) {
  4801. return fn(elem, 0, args);
  4802. };
  4803. }
  4804. return fn;
  4805. }
  4806. },
  4807. pseudos: {
  4808. not: markFunction(function (selector) {
  4809. var input = [], results = [], matcher = compile(selector.replace(rtrim, '$1'));
  4810. return matcher[expando] ? markFunction(function (seed, matches, context, xml) {
  4811. var elem, unmatched = matcher(seed, null, xml, []), i = seed.length;
  4812. while (i--) {
  4813. if (elem = unmatched[i]) {
  4814. seed[i] = !(matches[i] = elem);
  4815. }
  4816. }
  4817. }) : function (elem, context, xml) {
  4818. input[0] = elem;
  4819. matcher(input, null, xml, results);
  4820. return !results.pop();
  4821. };
  4822. }),
  4823. has: markFunction(function (selector) {
  4824. return function (elem) {
  4825. return Sizzle(selector, elem).length > 0;
  4826. };
  4827. }),
  4828. contains: markFunction(function (text) {
  4829. text = text.replace(runescape, funescape);
  4830. return function (elem) {
  4831. return (elem.textContent || elem.innerText || getText(elem)).indexOf(text) > -1;
  4832. };
  4833. }),
  4834. lang: markFunction(function (lang) {
  4835. if (!ridentifier.test(lang || '')) {
  4836. Sizzle.error('unsupported lang: ' + lang);
  4837. }
  4838. lang = lang.replace(runescape, funescape).toLowerCase();
  4839. return function (elem) {
  4840. var elemLang;
  4841. do {
  4842. if (elemLang = documentIsHTML ? elem.lang : elem.getAttribute('xml:lang') || elem.getAttribute('lang')) {
  4843. elemLang = elemLang.toLowerCase();
  4844. return elemLang === lang || elemLang.indexOf(lang + '-') === 0;
  4845. }
  4846. } while ((elem = elem.parentNode) && elem.nodeType === 1);
  4847. return false;
  4848. };
  4849. }),
  4850. target: function (elem) {
  4851. var hash = domGlobals.window.location && domGlobals.window.location.hash;
  4852. return hash && hash.slice(1) === elem.id;
  4853. },
  4854. root: function (elem) {
  4855. return elem === docElem;
  4856. },
  4857. focus: function (elem) {
  4858. return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  4859. },
  4860. enabled: function (elem) {
  4861. return elem.disabled === false;
  4862. },
  4863. disabled: function (elem) {
  4864. return elem.disabled === true;
  4865. },
  4866. checked: function (elem) {
  4867. var nodeName = elem.nodeName.toLowerCase();
  4868. return nodeName === 'input' && !!elem.checked || nodeName === 'option' && !!elem.selected;
  4869. },
  4870. selected: function (elem) {
  4871. if (elem.parentNode) {
  4872. elem.parentNode.selectedIndex;
  4873. }
  4874. return elem.selected === true;
  4875. },
  4876. empty: function (elem) {
  4877. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  4878. if (elem.nodeType < 6) {
  4879. return false;
  4880. }
  4881. }
  4882. return true;
  4883. },
  4884. parent: function (elem) {
  4885. return !Expr.pseudos.empty(elem);
  4886. },
  4887. header: function (elem) {
  4888. return rheader.test(elem.nodeName);
  4889. },
  4890. input: function (elem) {
  4891. return rinputs.test(elem.nodeName);
  4892. },
  4893. button: function (elem) {
  4894. var name = elem.nodeName.toLowerCase();
  4895. return name === 'input' && elem.type === 'button' || name === 'button';
  4896. },
  4897. text: function (elem) {
  4898. var attr;
  4899. return elem.nodeName.toLowerCase() === 'input' && elem.type === 'text' && ((attr = elem.getAttribute('type')) == null || attr.toLowerCase() === 'text');
  4900. },
  4901. first: createPositionalPseudo(function () {
  4902. return [0];
  4903. }),
  4904. last: createPositionalPseudo(function (matchIndexes, length) {
  4905. return [length - 1];
  4906. }),
  4907. eq: createPositionalPseudo(function (matchIndexes, length, argument) {
  4908. return [argument < 0 ? argument + length : argument];
  4909. }),
  4910. even: createPositionalPseudo(function (matchIndexes, length) {
  4911. var i = 0;
  4912. for (; i < length; i += 2) {
  4913. matchIndexes.push(i);
  4914. }
  4915. return matchIndexes;
  4916. }),
  4917. odd: createPositionalPseudo(function (matchIndexes, length) {
  4918. var i = 1;
  4919. for (; i < length; i += 2) {
  4920. matchIndexes.push(i);
  4921. }
  4922. return matchIndexes;
  4923. }),
  4924. lt: createPositionalPseudo(function (matchIndexes, length, argument) {
  4925. var i = argument < 0 ? argument + length : argument;
  4926. for (; --i >= 0;) {
  4927. matchIndexes.push(i);
  4928. }
  4929. return matchIndexes;
  4930. }),
  4931. gt: createPositionalPseudo(function (matchIndexes, length, argument) {
  4932. var i = argument < 0 ? argument + length : argument;
  4933. for (; ++i < length;) {
  4934. matchIndexes.push(i);
  4935. }
  4936. return matchIndexes;
  4937. })
  4938. }
  4939. };
  4940. Expr.pseudos.nth = Expr.pseudos.eq;
  4941. for (i in {
  4942. radio: true,
  4943. checkbox: true,
  4944. file: true,
  4945. password: true,
  4946. image: true
  4947. }) {
  4948. Expr.pseudos[i] = createInputPseudo(i);
  4949. }
  4950. for (i in {
  4951. submit: true,
  4952. reset: true
  4953. }) {
  4954. Expr.pseudos[i] = createButtonPseudo(i);
  4955. }
  4956. function setFilters() {
  4957. }
  4958. setFilters.prototype = Expr.filters = Expr.pseudos;
  4959. Expr.setFilters = new setFilters();
  4960. tokenize = Sizzle.tokenize = function (selector, parseOnly) {
  4961. var matched, match, tokens, type, soFar, groups, preFilters, cached = tokenCache[selector + ' '];
  4962. if (cached) {
  4963. return parseOnly ? 0 : cached.slice(0);
  4964. }
  4965. soFar = selector;
  4966. groups = [];
  4967. preFilters = Expr.preFilter;
  4968. while (soFar) {
  4969. if (!matched || (match = rcomma.exec(soFar))) {
  4970. if (match) {
  4971. soFar = soFar.slice(match[0].length) || soFar;
  4972. }
  4973. groups.push(tokens = []);
  4974. }
  4975. matched = false;
  4976. if (match = rcombinators.exec(soFar)) {
  4977. matched = match.shift();
  4978. tokens.push({
  4979. value: matched,
  4980. type: match[0].replace(rtrim, ' ')
  4981. });
  4982. soFar = soFar.slice(matched.length);
  4983. }
  4984. for (type in Expr.filter) {
  4985. if (!Expr.filter.hasOwnProperty(type))
  4986. continue;
  4987. if ((match = matchExpr[type].exec(soFar)) && (!preFilters[type] || (match = preFilters[type](match)))) {
  4988. matched = match.shift();
  4989. tokens.push({
  4990. value: matched,
  4991. type: type,
  4992. matches: match
  4993. });
  4994. soFar = soFar.slice(matched.length);
  4995. }
  4996. }
  4997. if (!matched) {
  4998. break;
  4999. }
  5000. }
  5001. return parseOnly ? soFar.length : soFar ? Sizzle.error(selector) : tokenCache(selector, groups).slice(0);
  5002. };
  5003. function toSelector(tokens) {
  5004. var i = 0, len = tokens.length, selector = '';
  5005. for (; i < len; i++) {
  5006. selector += tokens[i].value;
  5007. }
  5008. return selector;
  5009. }
  5010. function addCombinator(matcher, combinator, base) {
  5011. var dir = combinator.dir, checkNonElements = base && dir === 'parentNode', doneName = done++;
  5012. return combinator.first ? function (elem, context, xml) {
  5013. while (elem = elem[dir]) {
  5014. if (elem.nodeType === 1 || checkNonElements) {
  5015. return matcher(elem, context, xml);
  5016. }
  5017. }
  5018. } : function (elem, context, xml) {
  5019. var oldCache, outerCache, newCache = [
  5020. dirruns,
  5021. doneName
  5022. ];
  5023. if (xml) {
  5024. while (elem = elem[dir]) {
  5025. if (elem.nodeType === 1 || checkNonElements) {
  5026. if (matcher(elem, context, xml)) {
  5027. return true;
  5028. }
  5029. }
  5030. }
  5031. } else {
  5032. while (elem = elem[dir]) {
  5033. if (elem.nodeType === 1 || checkNonElements) {
  5034. outerCache = elem[expando] || (elem[expando] = {});
  5035. if ((oldCache = outerCache[dir]) && oldCache[0] === dirruns && oldCache[1] === doneName) {
  5036. return newCache[2] = oldCache[2];
  5037. } else {
  5038. outerCache[dir] = newCache;
  5039. if (newCache[2] = matcher(elem, context, xml)) {
  5040. return true;
  5041. }
  5042. }
  5043. }
  5044. }
  5045. }
  5046. };
  5047. }
  5048. function elementMatcher(matchers) {
  5049. return matchers.length > 1 ? function (elem, context, xml) {
  5050. var i = matchers.length;
  5051. while (i--) {
  5052. if (!matchers[i](elem, context, xml)) {
  5053. return false;
  5054. }
  5055. }
  5056. return true;
  5057. } : matchers[0];
  5058. }
  5059. function multipleContexts(selector, contexts, results) {
  5060. var i = 0, len = contexts.length;
  5061. for (; i < len; i++) {
  5062. Sizzle(selector, contexts[i], results);
  5063. }
  5064. return results;
  5065. }
  5066. function condense(unmatched, map, filter, context, xml) {
  5067. var elem, newUnmatched = [], i = 0, len = unmatched.length, mapped = map != null;
  5068. for (; i < len; i++) {
  5069. if (elem = unmatched[i]) {
  5070. if (!filter || filter(elem, context, xml)) {
  5071. newUnmatched.push(elem);
  5072. if (mapped) {
  5073. map.push(i);
  5074. }
  5075. }
  5076. }
  5077. }
  5078. return newUnmatched;
  5079. }
  5080. function setMatcher(preFilter, selector, matcher, postFilter, postFinder, postSelector) {
  5081. if (postFilter && !postFilter[expando]) {
  5082. postFilter = setMatcher(postFilter);
  5083. }
  5084. if (postFinder && !postFinder[expando]) {
  5085. postFinder = setMatcher(postFinder, postSelector);
  5086. }
  5087. return markFunction(function (seed, results, context, xml) {
  5088. var temp, i, elem, preMap = [], postMap = [], preexisting = results.length, elems = seed || multipleContexts(selector || '*', context.nodeType ? [context] : context, []), matcherIn = preFilter && (seed || !selector) ? condense(elems, preMap, preFilter, context, xml) : elems, matcherOut = matcher ? postFinder || (seed ? preFilter : preexisting || postFilter) ? [] : results : matcherIn;
  5089. if (matcher) {
  5090. matcher(matcherIn, matcherOut, context, xml);
  5091. }
  5092. if (postFilter) {
  5093. temp = condense(matcherOut, postMap);
  5094. postFilter(temp, [], context, xml);
  5095. i = temp.length;
  5096. while (i--) {
  5097. if (elem = temp[i]) {
  5098. matcherOut[postMap[i]] = !(matcherIn[postMap[i]] = elem);
  5099. }
  5100. }
  5101. }
  5102. if (seed) {
  5103. if (postFinder || preFilter) {
  5104. if (postFinder) {
  5105. temp = [];
  5106. i = matcherOut.length;
  5107. while (i--) {
  5108. if (elem = matcherOut[i]) {
  5109. temp.push(matcherIn[i] = elem);
  5110. }
  5111. }
  5112. postFinder(null, matcherOut = [], temp, xml);
  5113. }
  5114. i = matcherOut.length;
  5115. while (i--) {
  5116. if ((elem = matcherOut[i]) && (temp = postFinder ? indexOf$2.call(seed, elem) : preMap[i]) > -1) {
  5117. seed[temp] = !(results[temp] = elem);
  5118. }
  5119. }
  5120. }
  5121. } else {
  5122. matcherOut = condense(matcherOut === results ? matcherOut.splice(preexisting, matcherOut.length) : matcherOut);
  5123. if (postFinder) {
  5124. postFinder(null, results, matcherOut, xml);
  5125. } else {
  5126. push.apply(results, matcherOut);
  5127. }
  5128. }
  5129. });
  5130. }
  5131. function matcherFromTokens(tokens) {
  5132. var checkContext, matcher, j, len = tokens.length, leadingRelative = Expr.relative[tokens[0].type], implicitRelative = leadingRelative || Expr.relative[' '], i = leadingRelative ? 1 : 0, matchContext = addCombinator(function (elem) {
  5133. return elem === checkContext;
  5134. }, implicitRelative, true), matchAnyContext = addCombinator(function (elem) {
  5135. return indexOf$2.call(checkContext, elem) > -1;
  5136. }, implicitRelative, true), matchers = [function (elem, context, xml) {
  5137. return !leadingRelative && (xml || context !== outermostContext) || ((checkContext = context).nodeType ? matchContext(elem, context, xml) : matchAnyContext(elem, context, xml));
  5138. }];
  5139. for (; i < len; i++) {
  5140. if (matcher = Expr.relative[tokens[i].type]) {
  5141. matchers = [addCombinator(elementMatcher(matchers), matcher)];
  5142. } else {
  5143. matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches);
  5144. if (matcher[expando]) {
  5145. j = ++i;
  5146. for (; j < len; j++) {
  5147. if (Expr.relative[tokens[j].type]) {
  5148. break;
  5149. }
  5150. }
  5151. return setMatcher(i > 1 && elementMatcher(matchers), i > 1 && toSelector(tokens.slice(0, i - 1).concat({ value: tokens[i - 2].type === ' ' ? '*' : '' })).replace(rtrim, '$1'), matcher, i < j && matcherFromTokens(tokens.slice(i, j)), j < len && matcherFromTokens(tokens = tokens.slice(j)), j < len && toSelector(tokens));
  5152. }
  5153. matchers.push(matcher);
  5154. }
  5155. }
  5156. return elementMatcher(matchers);
  5157. }
  5158. function matcherFromGroupMatchers(elementMatchers, setMatchers) {
  5159. var bySet = setMatchers.length > 0, byElement = elementMatchers.length > 0, superMatcher = function (seed, context, xml, results, outermost) {
  5160. var elem, j, matcher, matchedCount = 0, i = '0', unmatched = seed && [], setMatched = [], contextBackup = outermostContext, elems = seed || byElement && Expr.find.TAG('*', outermost), dirrunsUnique = dirruns += contextBackup == null ? 1 : Math.random() || 0.1, len = elems.length;
  5161. if (outermost) {
  5162. outermostContext = context !== document && context;
  5163. }
  5164. for (; i !== len && (elem = elems[i]) != null; i++) {
  5165. if (byElement && elem) {
  5166. j = 0;
  5167. while (matcher = elementMatchers[j++]) {
  5168. if (matcher(elem, context, xml)) {
  5169. results.push(elem);
  5170. break;
  5171. }
  5172. }
  5173. if (outermost) {
  5174. dirruns = dirrunsUnique;
  5175. }
  5176. }
  5177. if (bySet) {
  5178. if (elem = !matcher && elem) {
  5179. matchedCount--;
  5180. }
  5181. if (seed) {
  5182. unmatched.push(elem);
  5183. }
  5184. }
  5185. }
  5186. matchedCount += i;
  5187. if (bySet && i !== matchedCount) {
  5188. j = 0;
  5189. while (matcher = setMatchers[j++]) {
  5190. matcher(unmatched, setMatched, context, xml);
  5191. }
  5192. if (seed) {
  5193. if (matchedCount > 0) {
  5194. while (i--) {
  5195. if (!(unmatched[i] || setMatched[i])) {
  5196. setMatched[i] = pop.call(results);
  5197. }
  5198. }
  5199. }
  5200. setMatched = condense(setMatched);
  5201. }
  5202. push.apply(results, setMatched);
  5203. if (outermost && !seed && setMatched.length > 0 && matchedCount + setMatchers.length > 1) {
  5204. Sizzle.uniqueSort(results);
  5205. }
  5206. }
  5207. if (outermost) {
  5208. dirruns = dirrunsUnique;
  5209. outermostContext = contextBackup;
  5210. }
  5211. return unmatched;
  5212. };
  5213. return bySet ? markFunction(superMatcher) : superMatcher;
  5214. }
  5215. compile = Sizzle.compile = function (selector, match) {
  5216. var i, setMatchers = [], elementMatchers = [], cached = compilerCache[selector + ' '];
  5217. if (!cached) {
  5218. if (!match) {
  5219. match = tokenize(selector);
  5220. }
  5221. i = match.length;
  5222. while (i--) {
  5223. cached = matcherFromTokens(match[i]);
  5224. if (cached[expando]) {
  5225. setMatchers.push(cached);
  5226. } else {
  5227. elementMatchers.push(cached);
  5228. }
  5229. }
  5230. cached = compilerCache(selector, matcherFromGroupMatchers(elementMatchers, setMatchers));
  5231. cached.selector = selector;
  5232. }
  5233. return cached;
  5234. };
  5235. select = Sizzle.select = function (selector, context, results, seed) {
  5236. var i, tokens, token, type, find, compiled = typeof selector === 'function' && selector, match = !seed && tokenize(selector = compiled.selector || selector);
  5237. results = results || [];
  5238. if (match.length === 1) {
  5239. tokens = match[0] = match[0].slice(0);
  5240. if (tokens.length > 2 && (token = tokens[0]).type === 'ID' && support.getById && context.nodeType === 9 && documentIsHTML && Expr.relative[tokens[1].type]) {
  5241. context = (Expr.find.ID(token.matches[0].replace(runescape, funescape), context) || [])[0];
  5242. if (!context) {
  5243. return results;
  5244. } else if (compiled) {
  5245. context = context.parentNode;
  5246. }
  5247. selector = selector.slice(tokens.shift().value.length);
  5248. }
  5249. i = matchExpr.needsContext.test(selector) ? 0 : tokens.length;
  5250. while (i--) {
  5251. token = tokens[i];
  5252. if (Expr.relative[type = token.type]) {
  5253. break;
  5254. }
  5255. if (find = Expr.find[type]) {
  5256. if (seed = find(token.matches[0].replace(runescape, funescape), rsibling.test(tokens[0].type) && testContext(context.parentNode) || context)) {
  5257. tokens.splice(i, 1);
  5258. selector = seed.length && toSelector(tokens);
  5259. if (!selector) {
  5260. push.apply(results, seed);
  5261. return results;
  5262. }
  5263. break;
  5264. }
  5265. }
  5266. }
  5267. }
  5268. (compiled || compile(selector, match))(seed, context, !documentIsHTML, results, rsibling.test(selector) && testContext(context.parentNode) || context);
  5269. return results;
  5270. };
  5271. support.sortStable = expando.split('').sort(sortOrder).join('') === expando;
  5272. support.detectDuplicates = !!hasDuplicate;
  5273. setDocument();
  5274. support.sortDetached = true;
  5275. var doc = domGlobals.document, push$1 = Array.prototype.push, slice$1 = Array.prototype.slice;
  5276. var rquickExpr$1 = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/;
  5277. var Event = EventUtils.Event;
  5278. var skipUniques = Tools.makeMap('children,contents,next,prev');
  5279. var isDefined = function (obj) {
  5280. return typeof obj !== 'undefined';
  5281. };
  5282. var isString$1 = function (obj) {
  5283. return typeof obj === 'string';
  5284. };
  5285. var isWindow = function (obj) {
  5286. return obj && obj === obj.window;
  5287. };
  5288. var createFragment = function (html, fragDoc) {
  5289. var frag, node, container;
  5290. fragDoc = fragDoc || doc;
  5291. container = fragDoc.createElement('div');
  5292. frag = fragDoc.createDocumentFragment();
  5293. container.innerHTML = html;
  5294. while (node = container.firstChild) {
  5295. frag.appendChild(node);
  5296. }
  5297. return frag;
  5298. };
  5299. var domManipulate = function (targetNodes, sourceItem, callback, reverse) {
  5300. var i;
  5301. if (isString$1(sourceItem)) {
  5302. sourceItem = createFragment(sourceItem, getElementDocument(targetNodes[0]));
  5303. } else if (sourceItem.length && !sourceItem.nodeType) {
  5304. sourceItem = DomQuery.makeArray(sourceItem);
  5305. if (reverse) {
  5306. for (i = sourceItem.length - 1; i >= 0; i--) {
  5307. domManipulate(targetNodes, sourceItem[i], callback, reverse);
  5308. }
  5309. } else {
  5310. for (i = 0; i < sourceItem.length; i++) {
  5311. domManipulate(targetNodes, sourceItem[i], callback, reverse);
  5312. }
  5313. }
  5314. return targetNodes;
  5315. }
  5316. if (sourceItem.nodeType) {
  5317. i = targetNodes.length;
  5318. while (i--) {
  5319. callback.call(targetNodes[i], sourceItem);
  5320. }
  5321. }
  5322. return targetNodes;
  5323. };
  5324. var hasClass = function (node, className) {
  5325. return node && className && (' ' + node.className + ' ').indexOf(' ' + className + ' ') !== -1;
  5326. };
  5327. var wrap = function (elements, wrapper, all) {
  5328. var lastParent, newWrapper;
  5329. wrapper = DomQuery(wrapper)[0];
  5330. elements.each(function () {
  5331. var self = this;
  5332. if (!all || lastParent !== self.parentNode) {
  5333. lastParent = self.parentNode;
  5334. newWrapper = wrapper.cloneNode(false);
  5335. self.parentNode.insertBefore(newWrapper, self);
  5336. newWrapper.appendChild(self);
  5337. } else {
  5338. newWrapper.appendChild(self);
  5339. }
  5340. });
  5341. return elements;
  5342. };
  5343. var numericCssMap = Tools.makeMap('fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom', ' ');
  5344. var booleanMap = Tools.makeMap('checked compact declare defer disabled ismap multiple nohref noshade nowrap readonly selected', ' ');
  5345. var propFix = {
  5346. for: 'htmlFor',
  5347. class: 'className',
  5348. readonly: 'readOnly'
  5349. };
  5350. var cssFix = { float: 'cssFloat' };
  5351. var attrHooks = {}, cssHooks = {};
  5352. var DomQueryConstructor = function (selector, context) {
  5353. return new DomQuery.fn.init(selector, context);
  5354. };
  5355. var inArray$1 = function (item, array) {
  5356. var i;
  5357. if (array.indexOf) {
  5358. return array.indexOf(item);
  5359. }
  5360. i = array.length;
  5361. while (i--) {
  5362. if (array[i] === item) {
  5363. return i;
  5364. }
  5365. }
  5366. return -1;
  5367. };
  5368. var whiteSpaceRegExp$1 = /^\s*|\s*$/g;
  5369. var trim$2 = function (str) {
  5370. return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp$1, '');
  5371. };
  5372. var each$4 = function (obj, callback) {
  5373. var length, key, i, value;
  5374. if (obj) {
  5375. length = obj.length;
  5376. if (length === undefined) {
  5377. for (key in obj) {
  5378. if (obj.hasOwnProperty(key)) {
  5379. value = obj[key];
  5380. if (callback.call(value, key, value) === false) {
  5381. break;
  5382. }
  5383. }
  5384. }
  5385. } else {
  5386. for (i = 0; i < length; i++) {
  5387. value = obj[i];
  5388. if (callback.call(value, i, value) === false) {
  5389. break;
  5390. }
  5391. }
  5392. }
  5393. }
  5394. return obj;
  5395. };
  5396. var grep = function (array, callback) {
  5397. var out = [];
  5398. each$4(array, function (i, item) {
  5399. if (callback(item, i)) {
  5400. out.push(item);
  5401. }
  5402. });
  5403. return out;
  5404. };
  5405. var getElementDocument = function (element) {
  5406. if (!element) {
  5407. return doc;
  5408. }
  5409. if (element.nodeType === 9) {
  5410. return element;
  5411. }
  5412. return element.ownerDocument;
  5413. };
  5414. DomQueryConstructor.fn = DomQueryConstructor.prototype = {
  5415. constructor: DomQueryConstructor,
  5416. selector: '',
  5417. context: null,
  5418. length: 0,
  5419. init: function (selector, context) {
  5420. var self = this;
  5421. var match, node;
  5422. if (!selector) {
  5423. return self;
  5424. }
  5425. if (selector.nodeType) {
  5426. self.context = self[0] = selector;
  5427. self.length = 1;
  5428. return self;
  5429. }
  5430. if (context && context.nodeType) {
  5431. self.context = context;
  5432. } else {
  5433. if (context) {
  5434. return DomQuery(selector).attr(context);
  5435. }
  5436. self.context = context = domGlobals.document;
  5437. }
  5438. if (isString$1(selector)) {
  5439. self.selector = selector;
  5440. if (selector.charAt(0) === '<' && selector.charAt(selector.length - 1) === '>' && selector.length >= 3) {
  5441. match = [
  5442. null,
  5443. selector,
  5444. null
  5445. ];
  5446. } else {
  5447. match = rquickExpr$1.exec(selector);
  5448. }
  5449. if (match) {
  5450. if (match[1]) {
  5451. node = createFragment(selector, getElementDocument(context)).firstChild;
  5452. while (node) {
  5453. push$1.call(self, node);
  5454. node = node.nextSibling;
  5455. }
  5456. } else {
  5457. node = getElementDocument(context).getElementById(match[2]);
  5458. if (!node) {
  5459. return self;
  5460. }
  5461. if (node.id !== match[2]) {
  5462. return self.find(selector);
  5463. }
  5464. self.length = 1;
  5465. self[0] = node;
  5466. }
  5467. } else {
  5468. return DomQuery(context).find(selector);
  5469. }
  5470. } else {
  5471. this.add(selector, false);
  5472. }
  5473. return self;
  5474. },
  5475. toArray: function () {
  5476. return Tools.toArray(this);
  5477. },
  5478. add: function (items, sort) {
  5479. var self = this;
  5480. var nodes, i;
  5481. if (isString$1(items)) {
  5482. return self.add(DomQuery(items));
  5483. }
  5484. if (sort !== false) {
  5485. nodes = DomQuery.unique(self.toArray().concat(DomQuery.makeArray(items)));
  5486. self.length = nodes.length;
  5487. for (i = 0; i < nodes.length; i++) {
  5488. self[i] = nodes[i];
  5489. }
  5490. } else {
  5491. push$1.apply(self, DomQuery.makeArray(items));
  5492. }
  5493. return self;
  5494. },
  5495. attr: function (name, value) {
  5496. var self = this;
  5497. var hook;
  5498. if (typeof name === 'object') {
  5499. each$4(name, function (name, value) {
  5500. self.attr(name, value);
  5501. });
  5502. } else if (isDefined(value)) {
  5503. this.each(function () {
  5504. var hook;
  5505. if (this.nodeType === 1) {
  5506. hook = attrHooks[name];
  5507. if (hook && hook.set) {
  5508. hook.set(this, value);
  5509. return;
  5510. }
  5511. if (value === null) {
  5512. this.removeAttribute(name, 2);
  5513. } else {
  5514. this.setAttribute(name, value, 2);
  5515. }
  5516. }
  5517. });
  5518. } else {
  5519. if (self[0] && self[0].nodeType === 1) {
  5520. hook = attrHooks[name];
  5521. if (hook && hook.get) {
  5522. return hook.get(self[0], name);
  5523. }
  5524. if (booleanMap[name]) {
  5525. return self.prop(name) ? name : undefined;
  5526. }
  5527. value = self[0].getAttribute(name, 2);
  5528. if (value === null) {
  5529. value = undefined;
  5530. }
  5531. }
  5532. return value;
  5533. }
  5534. return self;
  5535. },
  5536. removeAttr: function (name) {
  5537. return this.attr(name, null);
  5538. },
  5539. prop: function (name, value) {
  5540. var self = this;
  5541. name = propFix[name] || name;
  5542. if (typeof name === 'object') {
  5543. each$4(name, function (name, value) {
  5544. self.prop(name, value);
  5545. });
  5546. } else if (isDefined(value)) {
  5547. this.each(function () {
  5548. if (this.nodeType === 1) {
  5549. this[name] = value;
  5550. }
  5551. });
  5552. } else {
  5553. if (self[0] && self[0].nodeType && name in self[0]) {
  5554. return self[0][name];
  5555. }
  5556. return value;
  5557. }
  5558. return self;
  5559. },
  5560. css: function (name, value) {
  5561. var self = this;
  5562. var elm, hook;
  5563. var camel = function (name) {
  5564. return name.replace(/-(\D)/g, function (a, b) {
  5565. return b.toUpperCase();
  5566. });
  5567. };
  5568. var dashed = function (name) {
  5569. return name.replace(/[A-Z]/g, function (a) {
  5570. return '-' + a;
  5571. });
  5572. };
  5573. if (typeof name === 'object') {
  5574. each$4(name, function (name, value) {
  5575. self.css(name, value);
  5576. });
  5577. } else {
  5578. if (isDefined(value)) {
  5579. name = camel(name);
  5580. if (typeof value === 'number' && !numericCssMap[name]) {
  5581. value = value.toString() + 'px';
  5582. }
  5583. self.each(function () {
  5584. var style = this.style;
  5585. hook = cssHooks[name];
  5586. if (hook && hook.set) {
  5587. hook.set(this, value);
  5588. return;
  5589. }
  5590. try {
  5591. this.style[cssFix[name] || name] = value;
  5592. } catch (ex) {
  5593. }
  5594. if (value === null || value === '') {
  5595. if (style.removeProperty) {
  5596. style.removeProperty(dashed(name));
  5597. } else {
  5598. style.removeAttribute(name);
  5599. }
  5600. }
  5601. });
  5602. } else {
  5603. elm = self[0];
  5604. hook = cssHooks[name];
  5605. if (hook && hook.get) {
  5606. return hook.get(elm);
  5607. }
  5608. if (elm.ownerDocument.defaultView) {
  5609. try {
  5610. return elm.ownerDocument.defaultView.getComputedStyle(elm, null).getPropertyValue(dashed(name));
  5611. } catch (ex) {
  5612. return undefined;
  5613. }
  5614. } else if (elm.currentStyle) {
  5615. return elm.currentStyle[camel(name)];
  5616. } else {
  5617. return '';
  5618. }
  5619. }
  5620. }
  5621. return self;
  5622. },
  5623. remove: function () {
  5624. var self = this;
  5625. var node, i = this.length;
  5626. while (i--) {
  5627. node = self[i];
  5628. Event.clean(node);
  5629. if (node.parentNode) {
  5630. node.parentNode.removeChild(node);
  5631. }
  5632. }
  5633. return this;
  5634. },
  5635. empty: function () {
  5636. var self = this;
  5637. var node, i = this.length;
  5638. while (i--) {
  5639. node = self[i];
  5640. while (node.firstChild) {
  5641. node.removeChild(node.firstChild);
  5642. }
  5643. }
  5644. return this;
  5645. },
  5646. html: function (value) {
  5647. var self = this;
  5648. var i;
  5649. if (isDefined(value)) {
  5650. i = self.length;
  5651. try {
  5652. while (i--) {
  5653. self[i].innerHTML = value;
  5654. }
  5655. } catch (ex) {
  5656. DomQuery(self[i]).empty().append(value);
  5657. }
  5658. return self;
  5659. }
  5660. return self[0] ? self[0].innerHTML : '';
  5661. },
  5662. text: function (value) {
  5663. var self = this;
  5664. var i;
  5665. if (isDefined(value)) {
  5666. i = self.length;
  5667. while (i--) {
  5668. if ('innerText' in self[i]) {
  5669. self[i].innerText = value;
  5670. } else {
  5671. self[0].textContent = value;
  5672. }
  5673. }
  5674. return self;
  5675. }
  5676. return self[0] ? self[0].innerText || self[0].textContent : '';
  5677. },
  5678. append: function () {
  5679. return domManipulate(this, arguments, function (node) {
  5680. if (this.nodeType === 1 || this.host && this.host.nodeType === 1) {
  5681. this.appendChild(node);
  5682. }
  5683. });
  5684. },
  5685. prepend: function () {
  5686. return domManipulate(this, arguments, function (node) {
  5687. if (this.nodeType === 1 || this.host && this.host.nodeType === 1) {
  5688. this.insertBefore(node, this.firstChild);
  5689. }
  5690. }, true);
  5691. },
  5692. before: function () {
  5693. var self = this;
  5694. if (self[0] && self[0].parentNode) {
  5695. return domManipulate(self, arguments, function (node) {
  5696. this.parentNode.insertBefore(node, this);
  5697. });
  5698. }
  5699. return self;
  5700. },
  5701. after: function () {
  5702. var self = this;
  5703. if (self[0] && self[0].parentNode) {
  5704. return domManipulate(self, arguments, function (node) {
  5705. this.parentNode.insertBefore(node, this.nextSibling);
  5706. }, true);
  5707. }
  5708. return self;
  5709. },
  5710. appendTo: function (val) {
  5711. DomQuery(val).append(this);
  5712. return this;
  5713. },
  5714. prependTo: function (val) {
  5715. DomQuery(val).prepend(this);
  5716. return this;
  5717. },
  5718. replaceWith: function (content) {
  5719. return this.before(content).remove();
  5720. },
  5721. wrap: function (content) {
  5722. return wrap(this, content);
  5723. },
  5724. wrapAll: function (content) {
  5725. return wrap(this, content, true);
  5726. },
  5727. wrapInner: function (content) {
  5728. this.each(function () {
  5729. DomQuery(this).contents().wrapAll(content);
  5730. });
  5731. return this;
  5732. },
  5733. unwrap: function () {
  5734. return this.parent().each(function () {
  5735. DomQuery(this).replaceWith(this.childNodes);
  5736. });
  5737. },
  5738. clone: function () {
  5739. var result = [];
  5740. this.each(function () {
  5741. result.push(this.cloneNode(true));
  5742. });
  5743. return DomQuery(result);
  5744. },
  5745. addClass: function (className) {
  5746. return this.toggleClass(className, true);
  5747. },
  5748. removeClass: function (className) {
  5749. return this.toggleClass(className, false);
  5750. },
  5751. toggleClass: function (className, state) {
  5752. var self = this;
  5753. if (typeof className !== 'string') {
  5754. return self;
  5755. }
  5756. if (className.indexOf(' ') !== -1) {
  5757. each$4(className.split(' '), function () {
  5758. self.toggleClass(this, state);
  5759. });
  5760. } else {
  5761. self.each(function (index, node) {
  5762. var existingClassName, classState;
  5763. classState = hasClass(node, className);
  5764. if (classState !== state) {
  5765. existingClassName = node.className;
  5766. if (classState) {
  5767. node.className = trim$2((' ' + existingClassName + ' ').replace(' ' + className + ' ', ' '));
  5768. } else {
  5769. node.className += existingClassName ? ' ' + className : className;
  5770. }
  5771. }
  5772. });
  5773. }
  5774. return self;
  5775. },
  5776. hasClass: function (className) {
  5777. return hasClass(this[0], className);
  5778. },
  5779. each: function (callback) {
  5780. return each$4(this, callback);
  5781. },
  5782. on: function (name, callback) {
  5783. return this.each(function () {
  5784. Event.bind(this, name, callback);
  5785. });
  5786. },
  5787. off: function (name, callback) {
  5788. return this.each(function () {
  5789. Event.unbind(this, name, callback);
  5790. });
  5791. },
  5792. trigger: function (name) {
  5793. return this.each(function () {
  5794. if (typeof name === 'object') {
  5795. Event.fire(this, name.type, name);
  5796. } else {
  5797. Event.fire(this, name);
  5798. }
  5799. });
  5800. },
  5801. show: function () {
  5802. return this.css('display', '');
  5803. },
  5804. hide: function () {
  5805. return this.css('display', 'none');
  5806. },
  5807. slice: function () {
  5808. return new DomQuery(slice$1.apply(this, arguments));
  5809. },
  5810. eq: function (index) {
  5811. return index === -1 ? this.slice(index) : this.slice(index, +index + 1);
  5812. },
  5813. first: function () {
  5814. return this.eq(0);
  5815. },
  5816. last: function () {
  5817. return this.eq(-1);
  5818. },
  5819. find: function (selector) {
  5820. var i, l;
  5821. var ret = [];
  5822. for (i = 0, l = this.length; i < l; i++) {
  5823. DomQuery.find(selector, this[i], ret);
  5824. }
  5825. return DomQuery(ret);
  5826. },
  5827. filter: function (selector) {
  5828. if (typeof selector === 'function') {
  5829. return DomQuery(grep(this.toArray(), function (item, i) {
  5830. return selector(i, item);
  5831. }));
  5832. }
  5833. return DomQuery(DomQuery.filter(selector, this.toArray()));
  5834. },
  5835. closest: function (selector) {
  5836. var result = [];
  5837. if (selector instanceof DomQuery) {
  5838. selector = selector[0];
  5839. }
  5840. this.each(function (i, node) {
  5841. while (node) {
  5842. if (typeof selector === 'string' && DomQuery(node).is(selector)) {
  5843. result.push(node);
  5844. break;
  5845. } else if (node === selector) {
  5846. result.push(node);
  5847. break;
  5848. }
  5849. node = node.parentNode;
  5850. }
  5851. });
  5852. return DomQuery(result);
  5853. },
  5854. offset: function (offset) {
  5855. var elm, doc, docElm;
  5856. var x = 0, y = 0, pos;
  5857. if (!offset) {
  5858. elm = this[0];
  5859. if (elm) {
  5860. doc = elm.ownerDocument;
  5861. docElm = doc.documentElement;
  5862. if (elm.getBoundingClientRect) {
  5863. pos = elm.getBoundingClientRect();
  5864. x = pos.left + (docElm.scrollLeft || doc.body.scrollLeft) - docElm.clientLeft;
  5865. y = pos.top + (docElm.scrollTop || doc.body.scrollTop) - docElm.clientTop;
  5866. }
  5867. }
  5868. return {
  5869. left: x,
  5870. top: y
  5871. };
  5872. }
  5873. return this.css(offset);
  5874. },
  5875. push: push$1,
  5876. sort: Array.prototype.sort,
  5877. splice: Array.prototype.splice
  5878. };
  5879. Tools.extend(DomQueryConstructor, {
  5880. extend: Tools.extend,
  5881. makeArray: function (object) {
  5882. if (isWindow(object) || object.nodeType) {
  5883. return [object];
  5884. }
  5885. return Tools.toArray(object);
  5886. },
  5887. inArray: inArray$1,
  5888. isArray: Tools.isArray,
  5889. each: each$4,
  5890. trim: trim$2,
  5891. grep: grep,
  5892. find: Sizzle,
  5893. expr: Sizzle.selectors,
  5894. unique: Sizzle.uniqueSort,
  5895. text: Sizzle.getText,
  5896. contains: Sizzle.contains,
  5897. filter: function (expr, elems, not) {
  5898. var i = elems.length;
  5899. if (not) {
  5900. expr = ':not(' + expr + ')';
  5901. }
  5902. while (i--) {
  5903. if (elems[i].nodeType !== 1) {
  5904. elems.splice(i, 1);
  5905. }
  5906. }
  5907. if (elems.length === 1) {
  5908. elems = DomQuery.find.matchesSelector(elems[0], expr) ? [elems[0]] : [];
  5909. } else {
  5910. elems = DomQuery.find.matches(expr, elems);
  5911. }
  5912. return elems;
  5913. }
  5914. });
  5915. var dir = function (el, prop, until) {
  5916. var matched = [];
  5917. var cur = el[prop];
  5918. if (typeof until !== 'string' && until instanceof DomQuery) {
  5919. until = until[0];
  5920. }
  5921. while (cur && cur.nodeType !== 9) {
  5922. if (until !== undefined) {
  5923. if (cur === until) {
  5924. break;
  5925. }
  5926. if (typeof until === 'string' && DomQuery(cur).is(until)) {
  5927. break;
  5928. }
  5929. }
  5930. if (cur.nodeType === 1) {
  5931. matched.push(cur);
  5932. }
  5933. cur = cur[prop];
  5934. }
  5935. return matched;
  5936. };
  5937. var sibling = function (node, siblingName, nodeType, until) {
  5938. var result = [];
  5939. if (until instanceof DomQuery) {
  5940. until = until[0];
  5941. }
  5942. for (; node; node = node[siblingName]) {
  5943. if (nodeType && node.nodeType !== nodeType) {
  5944. continue;
  5945. }
  5946. if (until !== undefined) {
  5947. if (node === until) {
  5948. break;
  5949. }
  5950. if (typeof until === 'string' && DomQuery(node).is(until)) {
  5951. break;
  5952. }
  5953. }
  5954. result.push(node);
  5955. }
  5956. return result;
  5957. };
  5958. var firstSibling = function (node, siblingName, nodeType) {
  5959. for (node = node[siblingName]; node; node = node[siblingName]) {
  5960. if (node.nodeType === nodeType) {
  5961. return node;
  5962. }
  5963. }
  5964. return null;
  5965. };
  5966. each$4({
  5967. parent: function (node) {
  5968. var parent = node.parentNode;
  5969. return parent && parent.nodeType !== 11 ? parent : null;
  5970. },
  5971. parents: function (node) {
  5972. return dir(node, 'parentNode');
  5973. },
  5974. next: function (node) {
  5975. return firstSibling(node, 'nextSibling', 1);
  5976. },
  5977. prev: function (node) {
  5978. return firstSibling(node, 'previousSibling', 1);
  5979. },
  5980. children: function (node) {
  5981. return sibling(node.firstChild, 'nextSibling', 1);
  5982. },
  5983. contents: function (node) {
  5984. return Tools.toArray((node.nodeName === 'iframe' ? node.contentDocument || node.contentWindow.document : node).childNodes);
  5985. }
  5986. }, function (name, fn) {
  5987. DomQueryConstructor.fn[name] = function (selector) {
  5988. var self = this;
  5989. var result = [];
  5990. self.each(function () {
  5991. var nodes = fn.call(result, this, selector, result);
  5992. if (nodes) {
  5993. if (DomQuery.isArray(nodes)) {
  5994. result.push.apply(result, nodes);
  5995. } else {
  5996. result.push(nodes);
  5997. }
  5998. }
  5999. });
  6000. if (this.length > 1) {
  6001. if (!skipUniques[name]) {
  6002. result = DomQuery.unique(result);
  6003. }
  6004. if (name.indexOf('parents') === 0) {
  6005. result = result.reverse();
  6006. }
  6007. }
  6008. var wrappedResult = DomQuery(result);
  6009. if (selector) {
  6010. return wrappedResult.filter(selector);
  6011. }
  6012. return wrappedResult;
  6013. };
  6014. });
  6015. each$4({
  6016. parentsUntil: function (node, until) {
  6017. return dir(node, 'parentNode', until);
  6018. },
  6019. nextUntil: function (node, until) {
  6020. return sibling(node, 'nextSibling', 1, until).slice(1);
  6021. },
  6022. prevUntil: function (node, until) {
  6023. return sibling(node, 'previousSibling', 1, until).slice(1);
  6024. }
  6025. }, function (name, fn) {
  6026. DomQueryConstructor.fn[name] = function (selector, filter) {
  6027. var self = this;
  6028. var result = [];
  6029. self.each(function () {
  6030. var nodes = fn.call(result, this, selector, result);
  6031. if (nodes) {
  6032. if (DomQuery.isArray(nodes)) {
  6033. result.push.apply(result, nodes);
  6034. } else {
  6035. result.push(nodes);
  6036. }
  6037. }
  6038. });
  6039. if (this.length > 1) {
  6040. result = DomQuery.unique(result);
  6041. if (name.indexOf('parents') === 0 || name === 'prevUntil') {
  6042. result = result.reverse();
  6043. }
  6044. }
  6045. var wrappedResult = DomQuery(result);
  6046. if (filter) {
  6047. return wrappedResult.filter(filter);
  6048. }
  6049. return wrappedResult;
  6050. };
  6051. });
  6052. DomQueryConstructor.fn.is = function (selector) {
  6053. return !!selector && this.filter(selector).length > 0;
  6054. };
  6055. DomQueryConstructor.fn.init.prototype = DomQueryConstructor.fn;
  6056. DomQueryConstructor.overrideDefaults = function (callback) {
  6057. var defaults;
  6058. var sub = function (selector, context) {
  6059. defaults = defaults || callback();
  6060. if (arguments.length === 0) {
  6061. selector = defaults.element;
  6062. }
  6063. if (!context) {
  6064. context = defaults.context;
  6065. }
  6066. return new sub.fn.init(selector, context);
  6067. };
  6068. DomQuery.extend(sub, this);
  6069. return sub;
  6070. };
  6071. DomQueryConstructor.attrHooks = attrHooks;
  6072. DomQueryConstructor.cssHooks = cssHooks;
  6073. var DomQuery = DomQueryConstructor;
  6074. var TreeWalker = function () {
  6075. function TreeWalker(startNode, rootNode) {
  6076. this.node = startNode;
  6077. this.rootNode = rootNode;
  6078. this.current = this.current.bind(this);
  6079. this.next = this.next.bind(this);
  6080. this.prev = this.prev.bind(this);
  6081. this.prev2 = this.prev2.bind(this);
  6082. }
  6083. TreeWalker.prototype.current = function () {
  6084. return this.node;
  6085. };
  6086. TreeWalker.prototype.next = function (shallow) {
  6087. this.node = this.findSibling(this.node, 'firstChild', 'nextSibling', shallow);
  6088. return this.node;
  6089. };
  6090. TreeWalker.prototype.prev = function (shallow) {
  6091. this.node = this.findSibling(this.node, 'lastChild', 'previousSibling', shallow);
  6092. return this.node;
  6093. };
  6094. TreeWalker.prototype.prev2 = function (shallow) {
  6095. this.node = this.findPreviousNode(this.node, 'lastChild', 'previousSibling', shallow);
  6096. return this.node;
  6097. };
  6098. TreeWalker.prototype.findSibling = function (node, startName, siblingName, shallow) {
  6099. var sibling, parent;
  6100. if (node) {
  6101. if (!shallow && node[startName]) {
  6102. return node[startName];
  6103. }
  6104. if (node !== this.rootNode) {
  6105. sibling = node[siblingName];
  6106. if (sibling) {
  6107. return sibling;
  6108. }
  6109. for (parent = node.parentNode; parent && parent !== this.rootNode; parent = parent.parentNode) {
  6110. sibling = parent[siblingName];
  6111. if (sibling) {
  6112. return sibling;
  6113. }
  6114. }
  6115. }
  6116. }
  6117. };
  6118. TreeWalker.prototype.findPreviousNode = function (node, startName, siblingName, shallow) {
  6119. var sibling, parent, child;
  6120. if (node) {
  6121. sibling = node[siblingName];
  6122. if (this.rootNode && sibling === this.rootNode) {
  6123. return;
  6124. }
  6125. if (sibling) {
  6126. if (!shallow) {
  6127. for (child = sibling[startName]; child; child = child[startName]) {
  6128. if (!child[startName]) {
  6129. return child;
  6130. }
  6131. }
  6132. }
  6133. return sibling;
  6134. }
  6135. parent = node.parentNode;
  6136. if (parent && parent !== this.rootNode) {
  6137. return parent;
  6138. }
  6139. }
  6140. };
  6141. return TreeWalker;
  6142. }();
  6143. var before = function (marker, element) {
  6144. var parent$1 = parent(marker);
  6145. parent$1.each(function (v) {
  6146. v.dom().insertBefore(element.dom(), marker.dom());
  6147. });
  6148. };
  6149. var after = function (marker, element) {
  6150. var sibling = nextSibling(marker);
  6151. sibling.fold(function () {
  6152. var parent$1 = parent(marker);
  6153. parent$1.each(function (v) {
  6154. append(v, element);
  6155. });
  6156. }, function (v) {
  6157. before(v, element);
  6158. });
  6159. };
  6160. var prepend = function (parent, element) {
  6161. var firstChild$1 = firstChild(parent);
  6162. firstChild$1.fold(function () {
  6163. append(parent, element);
  6164. }, function (v) {
  6165. parent.dom().insertBefore(element.dom(), v.dom());
  6166. });
  6167. };
  6168. var append = function (parent, element) {
  6169. parent.dom().appendChild(element.dom());
  6170. };
  6171. var wrap$1 = function (element, wrapper) {
  6172. before(element, wrapper);
  6173. append(wrapper, element);
  6174. };
  6175. var before$1 = function (marker, elements) {
  6176. each(elements, function (x) {
  6177. before(marker, x);
  6178. });
  6179. };
  6180. var append$1 = function (parent, elements) {
  6181. each(elements, function (x) {
  6182. append(parent, x);
  6183. });
  6184. };
  6185. var empty = function (element) {
  6186. element.dom().textContent = '';
  6187. each(children(element), function (rogue) {
  6188. remove$1(rogue);
  6189. });
  6190. };
  6191. var remove$1 = function (element) {
  6192. var dom = element.dom();
  6193. if (dom.parentNode !== null) {
  6194. dom.parentNode.removeChild(dom);
  6195. }
  6196. };
  6197. var unwrap = function (wrapper) {
  6198. var children$1 = children(wrapper);
  6199. if (children$1.length > 0) {
  6200. before$1(wrapper, children$1);
  6201. }
  6202. remove$1(wrapper);
  6203. };
  6204. var r = function (left, top) {
  6205. var translate = function (x, y) {
  6206. return r(left + x, top + y);
  6207. };
  6208. return {
  6209. left: constant(left),
  6210. top: constant(top),
  6211. translate: translate
  6212. };
  6213. };
  6214. var Position$1 = r;
  6215. var boxPosition = function (dom) {
  6216. var box = dom.getBoundingClientRect();
  6217. return Position$1(box.left, box.top);
  6218. };
  6219. var firstDefinedOrZero = function (a, b) {
  6220. return a !== undefined ? a : b !== undefined ? b : 0;
  6221. };
  6222. var absolute = function (element) {
  6223. var doc = element.dom().ownerDocument;
  6224. var body = doc.body;
  6225. var win = doc.defaultView;
  6226. var html = doc.documentElement;
  6227. if (body === element.dom()) {
  6228. return Position$1(body.offsetLeft, body.offsetTop);
  6229. }
  6230. var scrollTop = firstDefinedOrZero(win.pageYOffset, html.scrollTop);
  6231. var scrollLeft = firstDefinedOrZero(win.pageXOffset, html.scrollLeft);
  6232. var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
  6233. var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
  6234. return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  6235. };
  6236. var viewport = function (element) {
  6237. var dom = element.dom();
  6238. var doc = dom.ownerDocument;
  6239. var body = doc.body;
  6240. if (body === dom) {
  6241. return Position$1(body.offsetLeft, body.offsetTop);
  6242. }
  6243. if (!inBody(element)) {
  6244. return Position$1(0, 0);
  6245. }
  6246. return boxPosition(dom);
  6247. };
  6248. var isSafari = detect$3().browser.isSafari();
  6249. var get$3 = function (_DOC) {
  6250. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  6251. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  6252. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  6253. return Position$1(x, y);
  6254. };
  6255. var to = function (x, y, _DOC) {
  6256. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  6257. var win = doc.defaultView;
  6258. win.scrollTo(x, y);
  6259. };
  6260. var intoView = function (element, alignToTop) {
  6261. if (isSafari && isFunction(element.dom().scrollIntoViewIfNeeded)) {
  6262. element.dom().scrollIntoViewIfNeeded(false);
  6263. } else {
  6264. element.dom().scrollIntoView(alignToTop);
  6265. }
  6266. };
  6267. var bounds = function (x, y, width, height) {
  6268. return {
  6269. x: constant(x),
  6270. y: constant(y),
  6271. width: constant(width),
  6272. height: constant(height),
  6273. right: constant(x + width),
  6274. bottom: constant(y + height)
  6275. };
  6276. };
  6277. var getBounds = function (_win) {
  6278. var win = _win === undefined ? domGlobals.window : _win;
  6279. var doc = win.document;
  6280. var scroll = get$3(Element.fromDom(doc));
  6281. var visualViewport = win['visualViewport'];
  6282. if (visualViewport !== undefined) {
  6283. return bounds(Math.max(visualViewport.pageLeft, scroll.left()), Math.max(visualViewport.pageTop, scroll.top()), visualViewport.width, visualViewport.height);
  6284. } else {
  6285. var html = doc.documentElement;
  6286. var width = html.clientWidth;
  6287. var height = html.clientHeight;
  6288. return bounds(scroll.left(), scroll.top(), width, height);
  6289. }
  6290. };
  6291. var each$5 = Tools.each;
  6292. var grep$1 = Tools.grep;
  6293. var isIE = Env.ie;
  6294. var simpleSelectorRe = /^([a-z0-9],?)+$/i;
  6295. var whiteSpaceRegExp$2 = /^[ \t\r\n]*$/;
  6296. var setupAttrHooks = function (styles, settings, getContext) {
  6297. var keepValues = settings.keep_values;
  6298. var keepUrlHook = {
  6299. set: function ($elm, value, name) {
  6300. if (settings.url_converter) {
  6301. value = settings.url_converter.call(settings.url_converter_scope || getContext(), value, name, $elm[0]);
  6302. }
  6303. $elm.attr('data-mce-' + name, value).attr(name, value);
  6304. },
  6305. get: function ($elm, name) {
  6306. return $elm.attr('data-mce-' + name) || $elm.attr(name);
  6307. }
  6308. };
  6309. var attrHooks = {
  6310. style: {
  6311. set: function ($elm, value) {
  6312. if (value !== null && typeof value === 'object') {
  6313. $elm.css(value);
  6314. return;
  6315. }
  6316. if (keepValues) {
  6317. $elm.attr('data-mce-style', value);
  6318. }
  6319. $elm.attr('style', value);
  6320. },
  6321. get: function ($elm) {
  6322. var value = $elm.attr('data-mce-style') || $elm.attr('style');
  6323. value = styles.serialize(styles.parse(value), $elm[0].nodeName);
  6324. return value;
  6325. }
  6326. }
  6327. };
  6328. if (keepValues) {
  6329. attrHooks.href = attrHooks.src = keepUrlHook;
  6330. }
  6331. return attrHooks;
  6332. };
  6333. var updateInternalStyleAttr = function (styles, $elm) {
  6334. var rawValue = $elm.attr('style');
  6335. var value = styles.serialize(styles.parse(rawValue), $elm[0].nodeName);
  6336. if (!value) {
  6337. value = null;
  6338. }
  6339. $elm.attr('data-mce-style', value);
  6340. };
  6341. var findNodeIndex = function (node, normalized) {
  6342. var idx = 0, lastNodeType, nodeType;
  6343. if (node) {
  6344. for (lastNodeType = node.nodeType, node = node.previousSibling; node; node = node.previousSibling) {
  6345. nodeType = node.nodeType;
  6346. if (normalized && nodeType === 3) {
  6347. if (nodeType === lastNodeType || !node.nodeValue.length) {
  6348. continue;
  6349. }
  6350. }
  6351. idx++;
  6352. lastNodeType = nodeType;
  6353. }
  6354. }
  6355. return idx;
  6356. };
  6357. function DOMUtils(doc, settings) {
  6358. var _this = this;
  6359. if (settings === void 0) {
  6360. settings = {};
  6361. }
  6362. var attrHooks;
  6363. var addedStyles = {};
  6364. var win = domGlobals.window;
  6365. var files = {};
  6366. var counter = 0;
  6367. var stdMode = true;
  6368. var boxModel = true;
  6369. var styleSheetLoader = StyleSheetLoader(doc, {
  6370. contentCssCors: settings.contentCssCors,
  6371. referrerPolicy: settings.referrerPolicy
  6372. });
  6373. var boundEvents = [];
  6374. var schema = settings.schema ? settings.schema : Schema({});
  6375. var styles = Styles({
  6376. url_converter: settings.url_converter,
  6377. url_converter_scope: settings.url_converter_scope
  6378. }, settings.schema);
  6379. var events = settings.ownEvents ? new EventUtils() : EventUtils.Event;
  6380. var blockElementsMap = schema.getBlockElements();
  6381. var $ = DomQuery.overrideDefaults(function () {
  6382. return {
  6383. context: doc,
  6384. element: self.getRoot()
  6385. };
  6386. });
  6387. var isBlock = function (node) {
  6388. if (typeof node === 'string') {
  6389. return !!blockElementsMap[node];
  6390. } else if (node) {
  6391. var type = node.nodeType;
  6392. if (type) {
  6393. return !!(type === 1 && blockElementsMap[node.nodeName]);
  6394. }
  6395. }
  6396. return false;
  6397. };
  6398. var get = function (elm) {
  6399. if (elm && doc && typeof elm === 'string') {
  6400. var node = doc.getElementById(elm);
  6401. if (node && node.id !== elm) {
  6402. return doc.getElementsByName(elm)[1];
  6403. } else {
  6404. return node;
  6405. }
  6406. }
  6407. return elm;
  6408. };
  6409. var $$ = function (elm) {
  6410. if (typeof elm === 'string') {
  6411. elm = get(elm);
  6412. }
  6413. return $(elm);
  6414. };
  6415. var getAttrib = function (elm, name, defaultVal) {
  6416. var hook, value;
  6417. var $elm = $$(elm);
  6418. if ($elm.length) {
  6419. hook = attrHooks[name];
  6420. if (hook && hook.get) {
  6421. value = hook.get($elm, name);
  6422. } else {
  6423. value = $elm.attr(name);
  6424. }
  6425. }
  6426. if (typeof value === 'undefined') {
  6427. value = defaultVal || '';
  6428. }
  6429. return value;
  6430. };
  6431. var getAttribs = function (elm) {
  6432. var node = get(elm);
  6433. if (!node) {
  6434. return [];
  6435. }
  6436. return node.attributes;
  6437. };
  6438. var setAttrib = function (elm, name, value) {
  6439. var originalValue, hook;
  6440. if (value === '') {
  6441. value = null;
  6442. }
  6443. var $elm = $$(elm);
  6444. originalValue = $elm.attr(name);
  6445. if (!$elm.length) {
  6446. return;
  6447. }
  6448. hook = attrHooks[name];
  6449. if (hook && hook.set) {
  6450. hook.set($elm, value, name);
  6451. } else {
  6452. $elm.attr(name, value);
  6453. }
  6454. if (originalValue !== value && settings.onSetAttrib) {
  6455. settings.onSetAttrib({
  6456. attrElm: $elm,
  6457. attrName: name,
  6458. attrValue: value
  6459. });
  6460. }
  6461. };
  6462. var clone = function (node, deep) {
  6463. if (!isIE || node.nodeType !== 1 || deep) {
  6464. return node.cloneNode(deep);
  6465. }
  6466. if (!deep) {
  6467. var clone_1 = doc.createElement(node.nodeName);
  6468. each$5(getAttribs(node), function (attr) {
  6469. setAttrib(clone_1, attr.nodeName, getAttrib(node, attr.nodeName));
  6470. });
  6471. return clone_1;
  6472. }
  6473. return null;
  6474. };
  6475. var getRoot = function () {
  6476. return settings.root_element || doc.body;
  6477. };
  6478. var getViewPort = function (argWin) {
  6479. var vp = getBounds(argWin);
  6480. return {
  6481. x: vp.x(),
  6482. y: vp.y(),
  6483. w: vp.width(),
  6484. h: vp.height()
  6485. };
  6486. };
  6487. var getPos = function (elm, rootElm) {
  6488. return Position.getPos(doc.body, get(elm), rootElm);
  6489. };
  6490. var setStyle = function (elm, name, value) {
  6491. var $elm = isString(name) ? $$(elm).css(name, value) : $$(elm).css(name);
  6492. if (settings.update_styles) {
  6493. updateInternalStyleAttr(styles, $elm);
  6494. }
  6495. };
  6496. var setStyles = function (elm, stylesArg) {
  6497. var $elm = $$(elm).css(stylesArg);
  6498. if (settings.update_styles) {
  6499. updateInternalStyleAttr(styles, $elm);
  6500. }
  6501. };
  6502. var getStyle = function (elm, name, computed) {
  6503. var $elm = $$(elm);
  6504. if (computed) {
  6505. return $elm.css(name);
  6506. }
  6507. name = name.replace(/-(\D)/g, function (a, b) {
  6508. return b.toUpperCase();
  6509. });
  6510. if (name === 'float') {
  6511. name = Env.browser.isIE() ? 'styleFloat' : 'cssFloat';
  6512. }
  6513. return $elm[0] && $elm[0].style ? $elm[0].style[name] : undefined;
  6514. };
  6515. var getSize = function (elm) {
  6516. var w, h;
  6517. elm = get(elm);
  6518. w = getStyle(elm, 'width');
  6519. h = getStyle(elm, 'height');
  6520. if (w.indexOf('px') === -1) {
  6521. w = 0;
  6522. }
  6523. if (h.indexOf('px') === -1) {
  6524. h = 0;
  6525. }
  6526. return {
  6527. w: parseInt(w, 10) || elm.offsetWidth || elm.clientWidth,
  6528. h: parseInt(h, 10) || elm.offsetHeight || elm.clientHeight
  6529. };
  6530. };
  6531. var getRect = function (elm) {
  6532. var pos, size;
  6533. elm = get(elm);
  6534. pos = getPos(elm);
  6535. size = getSize(elm);
  6536. return {
  6537. x: pos.x,
  6538. y: pos.y,
  6539. w: size.w,
  6540. h: size.h
  6541. };
  6542. };
  6543. var is = function (elm, selector) {
  6544. var i;
  6545. if (!elm) {
  6546. return false;
  6547. }
  6548. if (!Array.isArray(elm)) {
  6549. if (selector === '*') {
  6550. return elm.nodeType === 1;
  6551. }
  6552. if (simpleSelectorRe.test(selector)) {
  6553. var selectors = selector.toLowerCase().split(/,/);
  6554. var elmName = elm.nodeName.toLowerCase();
  6555. for (i = selectors.length - 1; i >= 0; i--) {
  6556. if (selectors[i] === elmName) {
  6557. return true;
  6558. }
  6559. }
  6560. return false;
  6561. }
  6562. if (elm.nodeType && elm.nodeType !== 1) {
  6563. return false;
  6564. }
  6565. }
  6566. var elms = !Array.isArray(elm) ? [elm] : elm;
  6567. return Sizzle(selector, elms[0].ownerDocument || elms[0], null, elms).length > 0;
  6568. };
  6569. var getParents = function (elm, selector, root, collect) {
  6570. var result = [];
  6571. var selectorVal;
  6572. var node = get(elm);
  6573. collect = collect === undefined;
  6574. root = root || (getRoot().nodeName !== 'BODY' ? getRoot().parentNode : null);
  6575. if (Tools.is(selector, 'string')) {
  6576. selectorVal = selector;
  6577. if (selector === '*') {
  6578. selector = function (node) {
  6579. return node.nodeType === 1;
  6580. };
  6581. } else {
  6582. selector = function (node) {
  6583. return is(node, selectorVal);
  6584. };
  6585. }
  6586. }
  6587. while (node) {
  6588. if (node === root || !node.nodeType || node.nodeType === 9) {
  6589. break;
  6590. }
  6591. if (!selector || typeof selector === 'function' && selector(node)) {
  6592. if (collect) {
  6593. result.push(node);
  6594. } else {
  6595. return [node];
  6596. }
  6597. }
  6598. node = node.parentNode;
  6599. }
  6600. return collect ? result : null;
  6601. };
  6602. var getParent = function (node, selector, root) {
  6603. var parents = getParents(node, selector, root, false);
  6604. return parents && parents.length > 0 ? parents[0] : null;
  6605. };
  6606. var _findSib = function (node, selector, name) {
  6607. var func = selector;
  6608. if (node) {
  6609. if (typeof selector === 'string') {
  6610. func = function (node) {
  6611. return is(node, selector);
  6612. };
  6613. }
  6614. for (node = node[name]; node; node = node[name]) {
  6615. if (typeof func === 'function' && func(node)) {
  6616. return node;
  6617. }
  6618. }
  6619. }
  6620. return null;
  6621. };
  6622. var getNext = function (node, selector) {
  6623. return _findSib(node, selector, 'nextSibling');
  6624. };
  6625. var getPrev = function (node, selector) {
  6626. return _findSib(node, selector, 'previousSibling');
  6627. };
  6628. var select = function (selector, scope) {
  6629. return Sizzle(selector, get(scope) || settings.root_element || doc, []);
  6630. };
  6631. var run = function (elm, func, scope) {
  6632. var result;
  6633. var node = typeof elm === 'string' ? get(elm) : elm;
  6634. if (!node) {
  6635. return false;
  6636. }
  6637. if (Tools.isArray(node) && (node.length || node.length === 0)) {
  6638. result = [];
  6639. each$5(node, function (elm, i) {
  6640. if (elm) {
  6641. if (typeof elm === 'string') {
  6642. elm = get(elm);
  6643. }
  6644. result.push(func.call(scope, elm, i));
  6645. }
  6646. });
  6647. return result;
  6648. }
  6649. var context = scope ? scope : _this;
  6650. return func.call(context, node);
  6651. };
  6652. var setAttribs = function (elm, attrs) {
  6653. $$(elm).each(function (i, node) {
  6654. each$5(attrs, function (value, name) {
  6655. setAttrib(node, name, value);
  6656. });
  6657. });
  6658. };
  6659. var setHTML = function (elm, html) {
  6660. var $elm = $$(elm);
  6661. if (isIE) {
  6662. $elm.each(function (i, target) {
  6663. if (target.canHaveHTML === false) {
  6664. return;
  6665. }
  6666. while (target.firstChild) {
  6667. target.removeChild(target.firstChild);
  6668. }
  6669. try {
  6670. target.innerHTML = '<br>' + html;
  6671. target.removeChild(target.firstChild);
  6672. } catch (ex) {
  6673. DomQuery('<div></div>').html('<br>' + html).contents().slice(1).appendTo(target);
  6674. }
  6675. return html;
  6676. });
  6677. } else {
  6678. $elm.html(html);
  6679. }
  6680. };
  6681. var add = function (parentElm, name, attrs, html, create) {
  6682. return run(parentElm, function (parentElm) {
  6683. var newElm = typeof name === 'string' ? doc.createElement(name) : name;
  6684. setAttribs(newElm, attrs);
  6685. if (html) {
  6686. if (typeof html !== 'string' && html.nodeType) {
  6687. newElm.appendChild(html);
  6688. } else if (typeof html === 'string') {
  6689. setHTML(newElm, html);
  6690. }
  6691. }
  6692. return !create ? parentElm.appendChild(newElm) : newElm;
  6693. });
  6694. };
  6695. var create = function (name, attrs, html) {
  6696. return add(doc.createElement(name), name, attrs, html, true);
  6697. };
  6698. var decode = Entities.decode;
  6699. var encode = Entities.encodeAllRaw;
  6700. var createHTML = function (name, attrs, html) {
  6701. var outHtml = '', key;
  6702. outHtml += '<' + name;
  6703. for (key in attrs) {
  6704. if (attrs.hasOwnProperty(key) && attrs[key] !== null && typeof attrs[key] !== 'undefined') {
  6705. outHtml += ' ' + key + '="' + encode(attrs[key]) + '"';
  6706. }
  6707. }
  6708. if (typeof html !== 'undefined') {
  6709. return outHtml + '>' + html + '</' + name + '>';
  6710. }
  6711. return outHtml + ' />';
  6712. };
  6713. var createFragment = function (html) {
  6714. var node;
  6715. var container = doc.createElement('div');
  6716. var frag = doc.createDocumentFragment();
  6717. if (html) {
  6718. container.innerHTML = html;
  6719. }
  6720. while (node = container.firstChild) {
  6721. frag.appendChild(node);
  6722. }
  6723. return frag;
  6724. };
  6725. var remove = function (node, keepChildren) {
  6726. var $node = $$(node);
  6727. if (keepChildren) {
  6728. $node.each(function () {
  6729. var child;
  6730. while (child = this.firstChild) {
  6731. if (child.nodeType === 3 && child.data.length === 0) {
  6732. this.removeChild(child);
  6733. } else {
  6734. this.parentNode.insertBefore(child, this);
  6735. }
  6736. }
  6737. }).remove();
  6738. } else {
  6739. $node.remove();
  6740. }
  6741. return $node.length > 1 ? $node.toArray() : $node[0];
  6742. };
  6743. var removeAllAttribs = function (e) {
  6744. return run(e, function (e) {
  6745. var i;
  6746. var attrs = e.attributes;
  6747. for (i = attrs.length - 1; i >= 0; i--) {
  6748. e.removeAttributeNode(attrs.item(i));
  6749. }
  6750. });
  6751. };
  6752. var parseStyle = function (cssText) {
  6753. return styles.parse(cssText);
  6754. };
  6755. var serializeStyle = function (stylesArg, name) {
  6756. return styles.serialize(stylesArg, name);
  6757. };
  6758. var addStyle = function (cssText) {
  6759. var head, styleElm;
  6760. if (self !== DOMUtils.DOM && doc === domGlobals.document) {
  6761. if (addedStyles[cssText]) {
  6762. return;
  6763. }
  6764. addedStyles[cssText] = true;
  6765. }
  6766. styleElm = doc.getElementById('mceDefaultStyles');
  6767. if (!styleElm) {
  6768. styleElm = doc.createElement('style');
  6769. styleElm.id = 'mceDefaultStyles';
  6770. styleElm.type = 'text/css';
  6771. head = doc.getElementsByTagName('head')[0];
  6772. if (head.firstChild) {
  6773. head.insertBefore(styleElm, head.firstChild);
  6774. } else {
  6775. head.appendChild(styleElm);
  6776. }
  6777. }
  6778. if (styleElm.styleSheet) {
  6779. styleElm.styleSheet.cssText += cssText;
  6780. } else {
  6781. styleElm.appendChild(doc.createTextNode(cssText));
  6782. }
  6783. };
  6784. var loadCSS = function (url) {
  6785. var head;
  6786. if (self !== DOMUtils.DOM && doc === domGlobals.document) {
  6787. DOMUtils.DOM.loadCSS(url);
  6788. return;
  6789. }
  6790. if (!url) {
  6791. url = '';
  6792. }
  6793. head = doc.getElementsByTagName('head')[0];
  6794. each$5(url.split(','), function (url) {
  6795. var link;
  6796. url = Tools._addCacheSuffix(url);
  6797. if (files[url]) {
  6798. return;
  6799. }
  6800. files[url] = true;
  6801. link = create('link', __assign(__assign({
  6802. rel: 'stylesheet',
  6803. type: 'text/css',
  6804. href: url
  6805. }, settings.contentCssCors ? { crossOrigin: 'anonymous' } : {}), settings.referrerPolicy ? { referrerPolicy: settings.referrerPolicy } : {}));
  6806. head.appendChild(link);
  6807. });
  6808. };
  6809. var toggleClass = function (elm, cls, state) {
  6810. $$(elm).toggleClass(cls, state).each(function () {
  6811. if (this.className === '') {
  6812. DomQuery(this).attr('class', null);
  6813. }
  6814. });
  6815. };
  6816. var addClass = function (elm, cls) {
  6817. $$(elm).addClass(cls);
  6818. };
  6819. var removeClass = function (elm, cls) {
  6820. toggleClass(elm, cls, false);
  6821. };
  6822. var hasClass = function (elm, cls) {
  6823. return $$(elm).hasClass(cls);
  6824. };
  6825. var show = function (elm) {
  6826. $$(elm).show();
  6827. };
  6828. var hide = function (elm) {
  6829. $$(elm).hide();
  6830. };
  6831. var isHidden = function (elm) {
  6832. return $$(elm).css('display') === 'none';
  6833. };
  6834. var uniqueId = function (prefix) {
  6835. return (!prefix ? 'mce_' : prefix) + counter++;
  6836. };
  6837. var getOuterHTML = function (elm) {
  6838. var node = typeof elm === 'string' ? get(elm) : elm;
  6839. return NodeType.isElement(node) ? node.outerHTML : DomQuery('<div></div>').append(DomQuery(node).clone()).html();
  6840. };
  6841. var setOuterHTML = function (elm, html) {
  6842. $$(elm).each(function () {
  6843. try {
  6844. if ('outerHTML' in this) {
  6845. this.outerHTML = html;
  6846. return;
  6847. }
  6848. } catch (ex) {
  6849. }
  6850. remove(DomQuery(this).html(html), true);
  6851. });
  6852. };
  6853. var insertAfter = function (node, reference) {
  6854. var referenceNode = get(reference);
  6855. return run(node, function (node) {
  6856. var parent, nextSibling;
  6857. parent = referenceNode.parentNode;
  6858. nextSibling = referenceNode.nextSibling;
  6859. if (nextSibling) {
  6860. parent.insertBefore(node, nextSibling);
  6861. } else {
  6862. parent.appendChild(node);
  6863. }
  6864. return node;
  6865. });
  6866. };
  6867. var replace = function (newElm, oldElm, keepChildren) {
  6868. return run(oldElm, function (oldElm) {
  6869. if (Tools.is(oldElm, 'array')) {
  6870. newElm = newElm.cloneNode(true);
  6871. }
  6872. if (keepChildren) {
  6873. each$5(grep$1(oldElm.childNodes), function (node) {
  6874. newElm.appendChild(node);
  6875. });
  6876. }
  6877. return oldElm.parentNode.replaceChild(newElm, oldElm);
  6878. });
  6879. };
  6880. var rename = function (elm, name) {
  6881. var newElm;
  6882. if (elm.nodeName !== name.toUpperCase()) {
  6883. newElm = create(name);
  6884. each$5(getAttribs(elm), function (attrNode) {
  6885. setAttrib(newElm, attrNode.nodeName, getAttrib(elm, attrNode.nodeName));
  6886. });
  6887. replace(newElm, elm, true);
  6888. }
  6889. return newElm || elm;
  6890. };
  6891. var findCommonAncestor = function (a, b) {
  6892. var ps = a, pe;
  6893. while (ps) {
  6894. pe = b;
  6895. while (pe && ps !== pe) {
  6896. pe = pe.parentNode;
  6897. }
  6898. if (ps === pe) {
  6899. break;
  6900. }
  6901. ps = ps.parentNode;
  6902. }
  6903. if (!ps && a.ownerDocument) {
  6904. return a.ownerDocument.documentElement;
  6905. }
  6906. return ps;
  6907. };
  6908. var toHex = function (rgbVal) {
  6909. return styles.toHex(Tools.trim(rgbVal));
  6910. };
  6911. var isEmpty = function (node, elements) {
  6912. var i, attributes, type, name, brCount = 0;
  6913. node = node.firstChild;
  6914. if (node) {
  6915. var walker = new TreeWalker(node, node.parentNode);
  6916. var whitespace = schema ? schema.getWhiteSpaceElements() : {};
  6917. elements = elements || (schema ? schema.getNonEmptyElements() : null);
  6918. do {
  6919. type = node.nodeType;
  6920. if (NodeType.isElement(node)) {
  6921. var bogusVal = node.getAttribute('data-mce-bogus');
  6922. if (bogusVal) {
  6923. node = walker.next(bogusVal === 'all');
  6924. continue;
  6925. }
  6926. name = node.nodeName.toLowerCase();
  6927. if (elements && elements[name]) {
  6928. if (name === 'br') {
  6929. brCount++;
  6930. node = walker.next();
  6931. continue;
  6932. }
  6933. return false;
  6934. }
  6935. attributes = getAttribs(node);
  6936. i = attributes.length;
  6937. while (i--) {
  6938. name = attributes[i].nodeName;
  6939. if (name === 'name' || name === 'data-mce-bookmark') {
  6940. return false;
  6941. }
  6942. }
  6943. }
  6944. if (type === 8) {
  6945. return false;
  6946. }
  6947. if (type === 3 && !whiteSpaceRegExp$2.test(node.nodeValue)) {
  6948. return false;
  6949. }
  6950. if (type === 3 && node.parentNode && whitespace[node.parentNode.nodeName] && whiteSpaceRegExp$2.test(node.nodeValue)) {
  6951. return false;
  6952. }
  6953. node = walker.next();
  6954. } while (node);
  6955. }
  6956. return brCount <= 1;
  6957. };
  6958. var createRng = function () {
  6959. return doc.createRange();
  6960. };
  6961. var split = function (parentElm, splitElm, replacementElm) {
  6962. var r = createRng(), bef, aft, pa;
  6963. if (parentElm && splitElm) {
  6964. r.setStart(parentElm.parentNode, findNodeIndex(parentElm));
  6965. r.setEnd(splitElm.parentNode, findNodeIndex(splitElm));
  6966. bef = r.extractContents();
  6967. r = createRng();
  6968. r.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1);
  6969. r.setEnd(parentElm.parentNode, findNodeIndex(parentElm) + 1);
  6970. aft = r.extractContents();
  6971. pa = parentElm.parentNode;
  6972. pa.insertBefore(TrimNode.trimNode(self, bef), parentElm);
  6973. if (replacementElm) {
  6974. pa.insertBefore(replacementElm, parentElm);
  6975. } else {
  6976. pa.insertBefore(splitElm, parentElm);
  6977. }
  6978. pa.insertBefore(TrimNode.trimNode(self, aft), parentElm);
  6979. remove(parentElm);
  6980. return replacementElm || splitElm;
  6981. }
  6982. };
  6983. var bind = function (target, name, func, scope) {
  6984. if (Tools.isArray(target)) {
  6985. var i = target.length;
  6986. var rv = [];
  6987. while (i--) {
  6988. rv[i] = bind(target[i], name, func, scope);
  6989. }
  6990. return rv;
  6991. }
  6992. if (settings.collect && (target === doc || target === win)) {
  6993. boundEvents.push([
  6994. target,
  6995. name,
  6996. func,
  6997. scope
  6998. ]);
  6999. }
  7000. return events.bind(target, name, func, scope || self);
  7001. };
  7002. var unbind = function (target, name, func) {
  7003. var i;
  7004. if (Tools.isArray(target)) {
  7005. i = target.length;
  7006. var rv = [];
  7007. while (i--) {
  7008. rv[i] = unbind(target[i], name, func);
  7009. }
  7010. return rv;
  7011. }
  7012. if (boundEvents && (target === doc || target === win)) {
  7013. i = boundEvents.length;
  7014. while (i--) {
  7015. var item = boundEvents[i];
  7016. if (target === item[0] && (!name || name === item[1]) && (!func || func === item[2])) {
  7017. events.unbind(item[0], item[1], item[2]);
  7018. }
  7019. }
  7020. }
  7021. return events.unbind(target, name, func);
  7022. };
  7023. var fire = function (target, name, evt) {
  7024. return events.fire(target, name, evt);
  7025. };
  7026. var getContentEditable = function (node) {
  7027. if (node && NodeType.isElement(node)) {
  7028. var contentEditable = node.getAttribute('data-mce-contenteditable');
  7029. if (contentEditable && contentEditable !== 'inherit') {
  7030. return contentEditable;
  7031. }
  7032. return node.contentEditable !== 'inherit' ? node.contentEditable : null;
  7033. } else {
  7034. return null;
  7035. }
  7036. };
  7037. var getContentEditableParent = function (node) {
  7038. var root = getRoot();
  7039. var state = null;
  7040. for (; node && node !== root; node = node.parentNode) {
  7041. state = getContentEditable(node);
  7042. if (state !== null) {
  7043. break;
  7044. }
  7045. }
  7046. return state;
  7047. };
  7048. var destroy = function () {
  7049. if (boundEvents) {
  7050. var i = boundEvents.length;
  7051. while (i--) {
  7052. var item = boundEvents[i];
  7053. events.unbind(item[0], item[1], item[2]);
  7054. }
  7055. }
  7056. if (Sizzle.setDocument) {
  7057. Sizzle.setDocument();
  7058. }
  7059. };
  7060. var isChildOf = function (node, parent) {
  7061. while (node) {
  7062. if (parent === node) {
  7063. return true;
  7064. }
  7065. node = node.parentNode;
  7066. }
  7067. return false;
  7068. };
  7069. var dumpRng = function (r) {
  7070. return 'startContainer: ' + r.startContainer.nodeName + ', startOffset: ' + r.startOffset + ', endContainer: ' + r.endContainer.nodeName + ', endOffset: ' + r.endOffset;
  7071. };
  7072. var self = {
  7073. doc: doc,
  7074. settings: settings,
  7075. win: win,
  7076. files: files,
  7077. stdMode: stdMode,
  7078. boxModel: boxModel,
  7079. styleSheetLoader: styleSheetLoader,
  7080. boundEvents: boundEvents,
  7081. styles: styles,
  7082. schema: schema,
  7083. events: events,
  7084. isBlock: isBlock,
  7085. $: $,
  7086. $$: $$,
  7087. root: null,
  7088. clone: clone,
  7089. getRoot: getRoot,
  7090. getViewPort: getViewPort,
  7091. getRect: getRect,
  7092. getSize: getSize,
  7093. getParent: getParent,
  7094. getParents: getParents,
  7095. get: get,
  7096. getNext: getNext,
  7097. getPrev: getPrev,
  7098. select: select,
  7099. is: is,
  7100. add: add,
  7101. create: create,
  7102. createHTML: createHTML,
  7103. createFragment: createFragment,
  7104. remove: remove,
  7105. setStyle: setStyle,
  7106. getStyle: getStyle,
  7107. setStyles: setStyles,
  7108. removeAllAttribs: removeAllAttribs,
  7109. setAttrib: setAttrib,
  7110. setAttribs: setAttribs,
  7111. getAttrib: getAttrib,
  7112. getPos: getPos,
  7113. parseStyle: parseStyle,
  7114. serializeStyle: serializeStyle,
  7115. addStyle: addStyle,
  7116. loadCSS: loadCSS,
  7117. addClass: addClass,
  7118. removeClass: removeClass,
  7119. hasClass: hasClass,
  7120. toggleClass: toggleClass,
  7121. show: show,
  7122. hide: hide,
  7123. isHidden: isHidden,
  7124. uniqueId: uniqueId,
  7125. setHTML: setHTML,
  7126. getOuterHTML: getOuterHTML,
  7127. setOuterHTML: setOuterHTML,
  7128. decode: decode,
  7129. encode: encode,
  7130. insertAfter: insertAfter,
  7131. replace: replace,
  7132. rename: rename,
  7133. findCommonAncestor: findCommonAncestor,
  7134. toHex: toHex,
  7135. run: run,
  7136. getAttribs: getAttribs,
  7137. isEmpty: isEmpty,
  7138. createRng: createRng,
  7139. nodeIndex: findNodeIndex,
  7140. split: split,
  7141. bind: bind,
  7142. unbind: unbind,
  7143. fire: fire,
  7144. getContentEditable: getContentEditable,
  7145. getContentEditableParent: getContentEditableParent,
  7146. destroy: destroy,
  7147. isChildOf: isChildOf,
  7148. dumpRng: dumpRng
  7149. };
  7150. attrHooks = setupAttrHooks(styles, settings, function () {
  7151. return self;
  7152. });
  7153. return self;
  7154. }
  7155. (function (DOMUtils) {
  7156. DOMUtils.DOM = DOMUtils(domGlobals.document);
  7157. DOMUtils.nodeIndex = findNodeIndex;
  7158. }(DOMUtils || (DOMUtils = {})));
  7159. var DOMUtils$1 = DOMUtils;
  7160. var DOM = DOMUtils$1.DOM;
  7161. var each$6 = Tools.each, grep$2 = Tools.grep;
  7162. var QUEUED = 0;
  7163. var LOADING = 1;
  7164. var LOADED = 2;
  7165. var FAILED = 3;
  7166. var ScriptLoader = function () {
  7167. function ScriptLoader(settings) {
  7168. if (settings === void 0) {
  7169. settings = {};
  7170. }
  7171. this.states = {};
  7172. this.queue = [];
  7173. this.scriptLoadedCallbacks = {};
  7174. this.queueLoadedCallbacks = [];
  7175. this.loading = 0;
  7176. this.settings = settings;
  7177. }
  7178. ScriptLoader.prototype._setReferrerPolicy = function (referrerPolicy) {
  7179. this.settings.referrerPolicy = referrerPolicy;
  7180. };
  7181. ScriptLoader.prototype.loadScript = function (url, success, failure) {
  7182. var dom = DOM;
  7183. var elm, id;
  7184. var done = function () {
  7185. dom.remove(id);
  7186. if (elm) {
  7187. elm.onreadystatechange = elm.onload = elm = null;
  7188. }
  7189. success();
  7190. };
  7191. var error = function () {
  7192. if (isFunction(failure)) {
  7193. failure();
  7194. } else {
  7195. if (typeof domGlobals.console !== 'undefined' && domGlobals.console.log) {
  7196. domGlobals.console.log('Failed to load script: ' + url);
  7197. }
  7198. }
  7199. };
  7200. id = dom.uniqueId();
  7201. elm = domGlobals.document.createElement('script');
  7202. elm.id = id;
  7203. elm.type = 'text/javascript';
  7204. elm.src = Tools._addCacheSuffix(url);
  7205. if (this.settings.referrerPolicy) {
  7206. dom.setAttrib(elm, 'referrerpolicy', this.settings.referrerPolicy);
  7207. }
  7208. elm.onload = done;
  7209. elm.onerror = error;
  7210. (domGlobals.document.getElementsByTagName('head')[0] || domGlobals.document.body).appendChild(elm);
  7211. };
  7212. ScriptLoader.prototype.isDone = function (url) {
  7213. return this.states[url] === LOADED;
  7214. };
  7215. ScriptLoader.prototype.markDone = function (url) {
  7216. this.states[url] = LOADED;
  7217. };
  7218. ScriptLoader.prototype.add = function (url, success, scope, failure) {
  7219. var state = this.states[url];
  7220. if (state === undefined) {
  7221. this.queue.push(url);
  7222. this.states[url] = QUEUED;
  7223. }
  7224. if (success) {
  7225. if (!this.scriptLoadedCallbacks[url]) {
  7226. this.scriptLoadedCallbacks[url] = [];
  7227. }
  7228. this.scriptLoadedCallbacks[url].push({
  7229. success: success,
  7230. failure: failure,
  7231. scope: scope || this
  7232. });
  7233. }
  7234. };
  7235. ScriptLoader.prototype.load = function (url, success, scope, failure) {
  7236. return this.add(url, success, scope, failure);
  7237. };
  7238. ScriptLoader.prototype.remove = function (url) {
  7239. delete this.states[url];
  7240. delete this.scriptLoadedCallbacks[url];
  7241. };
  7242. ScriptLoader.prototype.loadQueue = function (success, scope, failure) {
  7243. this.loadScripts(this.queue, success, scope, failure);
  7244. };
  7245. ScriptLoader.prototype.loadScripts = function (scripts, success, scope, failure) {
  7246. var self = this;
  7247. var loadScripts;
  7248. var failures = [];
  7249. var execCallbacks = function (name, url) {
  7250. each$6(self.scriptLoadedCallbacks[url], function (callback) {
  7251. if (isFunction(callback[name])) {
  7252. callback[name].call(callback.scope);
  7253. }
  7254. });
  7255. self.scriptLoadedCallbacks[url] = undefined;
  7256. };
  7257. self.queueLoadedCallbacks.push({
  7258. success: success,
  7259. failure: failure,
  7260. scope: scope || this
  7261. });
  7262. loadScripts = function () {
  7263. var loadingScripts = grep$2(scripts);
  7264. scripts.length = 0;
  7265. each$6(loadingScripts, function (url) {
  7266. if (self.states[url] === LOADED) {
  7267. execCallbacks('success', url);
  7268. return;
  7269. }
  7270. if (self.states[url] === FAILED) {
  7271. execCallbacks('failure', url);
  7272. return;
  7273. }
  7274. if (self.states[url] !== LOADING) {
  7275. self.states[url] = LOADING;
  7276. self.loading++;
  7277. self.loadScript(url, function () {
  7278. self.states[url] = LOADED;
  7279. self.loading--;
  7280. execCallbacks('success', url);
  7281. loadScripts();
  7282. }, function () {
  7283. self.states[url] = FAILED;
  7284. self.loading--;
  7285. failures.push(url);
  7286. execCallbacks('failure', url);
  7287. loadScripts();
  7288. });
  7289. }
  7290. });
  7291. if (!self.loading) {
  7292. var notifyCallbacks = self.queueLoadedCallbacks.slice(0);
  7293. self.queueLoadedCallbacks.length = 0;
  7294. each$6(notifyCallbacks, function (callback) {
  7295. if (failures.length === 0) {
  7296. if (isFunction(callback.success)) {
  7297. callback.success.call(callback.scope);
  7298. }
  7299. } else {
  7300. if (isFunction(callback.failure)) {
  7301. callback.failure.call(callback.scope, failures);
  7302. }
  7303. }
  7304. });
  7305. }
  7306. };
  7307. loadScripts();
  7308. };
  7309. ScriptLoader.ScriptLoader = new ScriptLoader();
  7310. return ScriptLoader;
  7311. }();
  7312. var isRaw = function (str) {
  7313. return isObject(str) && has(str, 'raw');
  7314. };
  7315. var isTokenised = function (str) {
  7316. return isArray(str) && str.length > 1;
  7317. };
  7318. var data = {};
  7319. var currentCode = Cell('en');
  7320. var getData = function () {
  7321. return map$1(data, function (value) {
  7322. return __assign({}, value);
  7323. });
  7324. };
  7325. var setCode = function (newCode) {
  7326. if (newCode) {
  7327. currentCode.set(newCode);
  7328. }
  7329. };
  7330. var getCode = function () {
  7331. return currentCode.get();
  7332. };
  7333. var add = function (code, items) {
  7334. var langData = data[code];
  7335. if (!langData) {
  7336. data[code] = langData = {};
  7337. }
  7338. for (var name in items) {
  7339. langData[name.toLowerCase()] = items[name];
  7340. }
  7341. };
  7342. var translate = function (text) {
  7343. var langData = data[currentCode.get()] || {};
  7344. var toString = function (obj) {
  7345. if (isFunction(obj)) {
  7346. return Object.prototype.toString.call(obj);
  7347. }
  7348. return !isEmpty(obj) ? '' + obj : '';
  7349. };
  7350. var isEmpty = function (text) {
  7351. return text === '' || text === null || text === undefined;
  7352. };
  7353. var getLangData = function (text) {
  7354. var textstr = toString(text);
  7355. var lowercaseTextstr = textstr.toLowerCase();
  7356. return has(langData, lowercaseTextstr) ? toString(langData[lowercaseTextstr]) : textstr;
  7357. };
  7358. var removeContext = function (str) {
  7359. return str.replace(/{context:\w+}$/, '');
  7360. };
  7361. var translated = function (text) {
  7362. return text;
  7363. };
  7364. if (isEmpty(text)) {
  7365. return translated('');
  7366. }
  7367. if (isRaw(text)) {
  7368. return translated(toString(text.raw));
  7369. }
  7370. if (isTokenised(text)) {
  7371. var values_1 = text.slice(1);
  7372. var substitued = getLangData(text[0]).replace(/\{([0-9]+)\}/g, function ($1, $2) {
  7373. return has(values_1, $2) ? toString(values_1[$2]) : $1;
  7374. });
  7375. return translated(removeContext(substitued));
  7376. }
  7377. return translated(removeContext(getLangData(text)));
  7378. };
  7379. var isRtl = function () {
  7380. return get(data, currentCode.get()).bind(function (items) {
  7381. return get(items, '_dir');
  7382. }).exists(function (dir) {
  7383. return dir === 'rtl';
  7384. });
  7385. };
  7386. var hasCode = function (code) {
  7387. return has(data, code);
  7388. };
  7389. var I18n = {
  7390. getData: getData,
  7391. setCode: setCode,
  7392. getCode: getCode,
  7393. add: add,
  7394. translate: translate,
  7395. isRtl: isRtl,
  7396. hasCode: hasCode
  7397. };
  7398. var each$7 = Tools.each;
  7399. function AddOnManager() {
  7400. var _this = this;
  7401. var items = [];
  7402. var urls = {};
  7403. var lookup = {};
  7404. var _listeners = [];
  7405. var get = function (name) {
  7406. if (lookup[name]) {
  7407. return lookup[name].instance;
  7408. }
  7409. return undefined;
  7410. };
  7411. var dependencies = function (name) {
  7412. var result;
  7413. if (lookup[name]) {
  7414. result = lookup[name].dependencies;
  7415. }
  7416. return result || [];
  7417. };
  7418. var requireLangPack = function (name, languages) {
  7419. var language = I18n.getCode();
  7420. if (language && AddOnManager.languageLoad !== false) {
  7421. if (languages) {
  7422. languages = ',' + languages + ',';
  7423. if (languages.indexOf(',' + language.substr(0, 2) + ',') !== -1) {
  7424. language = language.substr(0, 2);
  7425. } else if (languages.indexOf(',' + language + ',') === -1) {
  7426. return;
  7427. }
  7428. }
  7429. ScriptLoader.ScriptLoader.add(urls[name] + '/langs/' + language + '.js');
  7430. }
  7431. };
  7432. var add = function (id, addOn, dependencies) {
  7433. items.push(addOn);
  7434. lookup[id] = {
  7435. instance: addOn,
  7436. dependencies: dependencies
  7437. };
  7438. var result = partition(_listeners, function (listener) {
  7439. return listener.name === id;
  7440. });
  7441. _listeners = result.fail;
  7442. each$7(result.pass, function (listener) {
  7443. listener.callback();
  7444. });
  7445. return addOn;
  7446. };
  7447. var remove = function (name) {
  7448. delete urls[name];
  7449. delete lookup[name];
  7450. };
  7451. var createUrl = function (baseUrl, dep) {
  7452. if (typeof dep === 'object') {
  7453. return dep;
  7454. }
  7455. return typeof baseUrl === 'string' ? {
  7456. prefix: '',
  7457. resource: dep,
  7458. suffix: ''
  7459. } : {
  7460. prefix: baseUrl.prefix,
  7461. resource: dep,
  7462. suffix: baseUrl.suffix
  7463. };
  7464. };
  7465. var addComponents = function (pluginName, scripts) {
  7466. var pluginUrl = _this.urls[pluginName];
  7467. each$7(scripts, function (script) {
  7468. ScriptLoader.ScriptLoader.add(pluginUrl + '/' + script);
  7469. });
  7470. };
  7471. var loadDependencies = function (name, addOnUrl, success, scope) {
  7472. var deps = dependencies(name);
  7473. each$7(deps, function (dep) {
  7474. var newUrl = createUrl(addOnUrl, dep);
  7475. load(newUrl.resource, newUrl, undefined, undefined);
  7476. });
  7477. if (success) {
  7478. if (scope) {
  7479. success.call(scope);
  7480. } else {
  7481. success.call(ScriptLoader);
  7482. }
  7483. }
  7484. };
  7485. var load = function (name, addOnUrl, success, scope, failure) {
  7486. if (urls[name]) {
  7487. return;
  7488. }
  7489. var urlString = typeof addOnUrl === 'string' ? addOnUrl : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix;
  7490. if (urlString.indexOf('/') !== 0 && urlString.indexOf('://') === -1) {
  7491. urlString = AddOnManager.baseURL + '/' + urlString;
  7492. }
  7493. urls[name] = urlString.substring(0, urlString.lastIndexOf('/'));
  7494. if (lookup[name]) {
  7495. loadDependencies(name, addOnUrl, success, scope);
  7496. } else {
  7497. ScriptLoader.ScriptLoader.add(urlString, function () {
  7498. return loadDependencies(name, addOnUrl, success, scope);
  7499. }, scope, failure);
  7500. }
  7501. };
  7502. var waitFor = function (name, callback) {
  7503. if (lookup.hasOwnProperty(name)) {
  7504. callback();
  7505. } else {
  7506. _listeners.push({
  7507. name: name,
  7508. callback: callback
  7509. });
  7510. }
  7511. };
  7512. return {
  7513. items: items,
  7514. urls: urls,
  7515. lookup: lookup,
  7516. _listeners: _listeners,
  7517. get: get,
  7518. dependencies: dependencies,
  7519. requireLangPack: requireLangPack,
  7520. add: add,
  7521. remove: remove,
  7522. createUrl: createUrl,
  7523. addComponents: addComponents,
  7524. load: load,
  7525. waitFor: waitFor
  7526. };
  7527. }
  7528. (function (AddOnManager) {
  7529. AddOnManager.PluginManager = AddOnManager();
  7530. AddOnManager.ThemeManager = AddOnManager();
  7531. }(AddOnManager || (AddOnManager = {})));
  7532. var AddOnManager$1 = AddOnManager;
  7533. var first = function (fn, rate) {
  7534. var timer = null;
  7535. var cancel = function () {
  7536. if (timer !== null) {
  7537. domGlobals.clearTimeout(timer);
  7538. timer = null;
  7539. }
  7540. };
  7541. var throttle = function () {
  7542. var args = [];
  7543. for (var _i = 0; _i < arguments.length; _i++) {
  7544. args[_i] = arguments[_i];
  7545. }
  7546. if (timer === null) {
  7547. timer = domGlobals.setTimeout(function () {
  7548. fn.apply(null, args);
  7549. timer = null;
  7550. }, rate);
  7551. }
  7552. };
  7553. return {
  7554. cancel: cancel,
  7555. throttle: throttle
  7556. };
  7557. };
  7558. var last$2 = function (fn, rate) {
  7559. var timer = null;
  7560. var cancel = function () {
  7561. if (timer !== null) {
  7562. domGlobals.clearTimeout(timer);
  7563. timer = null;
  7564. }
  7565. };
  7566. var throttle = function () {
  7567. var args = [];
  7568. for (var _i = 0; _i < arguments.length; _i++) {
  7569. args[_i] = arguments[_i];
  7570. }
  7571. if (timer !== null) {
  7572. domGlobals.clearTimeout(timer);
  7573. }
  7574. timer = domGlobals.setTimeout(function () {
  7575. fn.apply(null, args);
  7576. timer = null;
  7577. }, rate);
  7578. };
  7579. return {
  7580. cancel: cancel,
  7581. throttle: throttle
  7582. };
  7583. };
  7584. var read = function (element, attr) {
  7585. var value = get$1(element, attr);
  7586. return value === undefined || value === '' ? [] : value.split(' ');
  7587. };
  7588. var add$1 = function (element, attr, id) {
  7589. var old = read(element, attr);
  7590. var nu = old.concat([id]);
  7591. set(element, attr, nu.join(' '));
  7592. return true;
  7593. };
  7594. var remove$2 = function (element, attr, id) {
  7595. var nu = filter(read(element, attr), function (v) {
  7596. return v !== id;
  7597. });
  7598. if (nu.length > 0) {
  7599. set(element, attr, nu.join(' '));
  7600. } else {
  7601. remove(element, attr);
  7602. }
  7603. return false;
  7604. };
  7605. var supports = function (element) {
  7606. return element.dom().classList !== undefined;
  7607. };
  7608. var get$4 = function (element) {
  7609. return read(element, 'class');
  7610. };
  7611. var add$2 = function (element, clazz) {
  7612. return add$1(element, 'class', clazz);
  7613. };
  7614. var remove$3 = function (element, clazz) {
  7615. return remove$2(element, 'class', clazz);
  7616. };
  7617. var add$3 = function (element, clazz) {
  7618. if (supports(element)) {
  7619. element.dom().classList.add(clazz);
  7620. } else {
  7621. add$2(element, clazz);
  7622. }
  7623. };
  7624. var cleanClass = function (element) {
  7625. var classList = supports(element) ? element.dom().classList : get$4(element);
  7626. if (classList.length === 0) {
  7627. remove(element, 'class');
  7628. }
  7629. };
  7630. var remove$4 = function (element, clazz) {
  7631. if (supports(element)) {
  7632. var classList = element.dom().classList;
  7633. classList.remove(clazz);
  7634. } else {
  7635. remove$3(element, clazz);
  7636. }
  7637. cleanClass(element);
  7638. };
  7639. var has$2 = function (element, clazz) {
  7640. return supports(element) && element.dom().classList.contains(clazz);
  7641. };
  7642. var descendants = function (scope, predicate) {
  7643. var result = [];
  7644. each(children(scope), function (x) {
  7645. if (predicate(x)) {
  7646. result = result.concat([x]);
  7647. }
  7648. result = result.concat(descendants(x, predicate));
  7649. });
  7650. return result;
  7651. };
  7652. var descendants$1 = function (scope, selector) {
  7653. return all(selector, scope);
  7654. };
  7655. function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
  7656. return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
  7657. }
  7658. var ancestor = function (scope, predicate, isRoot) {
  7659. var element = scope.dom();
  7660. var stop = isFunction(isRoot) ? isRoot : constant(false);
  7661. while (element.parentNode) {
  7662. element = element.parentNode;
  7663. var el = Element.fromDom(element);
  7664. if (predicate(el)) {
  7665. return Option.some(el);
  7666. } else if (stop(el)) {
  7667. break;
  7668. }
  7669. }
  7670. return Option.none();
  7671. };
  7672. var closest = function (scope, predicate, isRoot) {
  7673. var is = function (s, test) {
  7674. return test(s);
  7675. };
  7676. return ClosestOrAncestor(is, ancestor, scope, predicate, isRoot);
  7677. };
  7678. var ancestor$1 = function (scope, selector, isRoot) {
  7679. return ancestor(scope, function (e) {
  7680. return is(e, selector);
  7681. }, isRoot);
  7682. };
  7683. var descendant = function (scope, selector) {
  7684. return one(selector, scope);
  7685. };
  7686. var closest$1 = function (scope, selector, isRoot) {
  7687. return ClosestOrAncestor(is, ancestor$1, scope, selector, isRoot);
  7688. };
  7689. var annotation = constant('mce-annotation');
  7690. var dataAnnotation = constant('data-mce-annotation');
  7691. var dataAnnotationId = constant('data-mce-annotation-uid');
  7692. var identify = function (editor, annotationName) {
  7693. var rng = editor.selection.getRng();
  7694. var start = Element.fromDom(rng.startContainer);
  7695. var root = Element.fromDom(editor.getBody());
  7696. var selector = annotationName.fold(function () {
  7697. return '.' + annotation();
  7698. }, function (an) {
  7699. return '[' + dataAnnotation() + '="' + an + '"]';
  7700. });
  7701. var newStart = child(start, rng.startOffset).getOr(start);
  7702. var closest = closest$1(newStart, selector, function (n) {
  7703. return eq(n, root);
  7704. });
  7705. var getAttr = function (c, property) {
  7706. if (has$1(c, property)) {
  7707. return Option.some(get$1(c, property));
  7708. } else {
  7709. return Option.none();
  7710. }
  7711. };
  7712. return closest.bind(function (c) {
  7713. return getAttr(c, '' + dataAnnotationId()).bind(function (uid) {
  7714. return getAttr(c, '' + dataAnnotation()).map(function (name) {
  7715. var elements = findMarkers(editor, uid);
  7716. return {
  7717. uid: uid,
  7718. name: name,
  7719. elements: elements
  7720. };
  7721. });
  7722. });
  7723. });
  7724. };
  7725. var isAnnotation = function (elem) {
  7726. return isElement$1(elem) && has$2(elem, annotation());
  7727. };
  7728. var findMarkers = function (editor, uid) {
  7729. var body = Element.fromDom(editor.getBody());
  7730. return descendants$1(body, '[' + dataAnnotationId() + '="' + uid + '"]');
  7731. };
  7732. var findAll = function (editor, name) {
  7733. var body = Element.fromDom(editor.getBody());
  7734. var markers = descendants$1(body, '[' + dataAnnotation() + '="' + name + '"]');
  7735. var directory = {};
  7736. each(markers, function (m) {
  7737. var uid = get$1(m, dataAnnotationId());
  7738. var nodesAlready = directory.hasOwnProperty(uid) ? directory[uid] : [];
  7739. directory[uid] = nodesAlready.concat([m]);
  7740. });
  7741. return directory;
  7742. };
  7743. var setup = function (editor, registry) {
  7744. var changeCallbacks = Cell({});
  7745. var initData = function () {
  7746. return {
  7747. listeners: [],
  7748. previous: Cell(Option.none())
  7749. };
  7750. };
  7751. var withCallbacks = function (name, f) {
  7752. updateCallbacks(name, function (data) {
  7753. f(data);
  7754. return data;
  7755. });
  7756. };
  7757. var updateCallbacks = function (name, f) {
  7758. var callbackMap = changeCallbacks.get();
  7759. var data = callbackMap.hasOwnProperty(name) ? callbackMap[name] : initData();
  7760. var outputData = f(data);
  7761. callbackMap[name] = outputData;
  7762. changeCallbacks.set(callbackMap);
  7763. };
  7764. var fireCallbacks = function (name, uid, elements) {
  7765. withCallbacks(name, function (data) {
  7766. each(data.listeners, function (f) {
  7767. return f(true, name, {
  7768. uid: uid,
  7769. nodes: map(elements, function (elem) {
  7770. return elem.dom();
  7771. })
  7772. });
  7773. });
  7774. });
  7775. };
  7776. var fireNoAnnotation = function (name) {
  7777. withCallbacks(name, function (data) {
  7778. each(data.listeners, function (f) {
  7779. return f(false, name);
  7780. });
  7781. });
  7782. };
  7783. var onNodeChange = last$2(function () {
  7784. var callbackMap = changeCallbacks.get();
  7785. var annotations = sort(keys(callbackMap));
  7786. each(annotations, function (name) {
  7787. updateCallbacks(name, function (data) {
  7788. var prev = data.previous.get();
  7789. identify(editor, Option.some(name)).fold(function () {
  7790. if (prev.isSome()) {
  7791. fireNoAnnotation(name);
  7792. data.previous.set(Option.none());
  7793. }
  7794. }, function (_a) {
  7795. var uid = _a.uid, name = _a.name, elements = _a.elements;
  7796. if (!prev.is(uid)) {
  7797. fireCallbacks(name, uid, elements);
  7798. data.previous.set(Option.some(uid));
  7799. }
  7800. });
  7801. return {
  7802. previous: data.previous,
  7803. listeners: data.listeners
  7804. };
  7805. });
  7806. });
  7807. }, 30);
  7808. editor.on('remove', function () {
  7809. onNodeChange.cancel();
  7810. });
  7811. editor.on('NodeChange', function () {
  7812. onNodeChange.throttle();
  7813. });
  7814. var addListener = function (name, f) {
  7815. updateCallbacks(name, function (data) {
  7816. return {
  7817. previous: data.previous,
  7818. listeners: data.listeners.concat([f])
  7819. };
  7820. });
  7821. };
  7822. return { addListener: addListener };
  7823. };
  7824. var setup$1 = function (editor, registry) {
  7825. var identifyParserNode = function (span) {
  7826. return Option.from(span.attr(dataAnnotation())).bind(registry.lookup);
  7827. };
  7828. editor.on('init', function () {
  7829. editor.serializer.addNodeFilter('span', function (spans) {
  7830. each(spans, function (span) {
  7831. identifyParserNode(span).each(function (settings) {
  7832. if (settings.persistent === false) {
  7833. span.unwrap();
  7834. }
  7835. });
  7836. });
  7837. });
  7838. });
  7839. };
  7840. var create$1 = function () {
  7841. var annotations = {};
  7842. var register = function (name, settings) {
  7843. annotations[name] = {
  7844. name: name,
  7845. settings: settings
  7846. };
  7847. };
  7848. var lookup = function (name) {
  7849. return annotations.hasOwnProperty(name) ? Option.from(annotations[name]).map(function (a) {
  7850. return a.settings;
  7851. }) : Option.none();
  7852. };
  7853. return {
  7854. register: register,
  7855. lookup: lookup
  7856. };
  7857. };
  7858. var unique = 0;
  7859. var generate = function (prefix) {
  7860. var date = new Date();
  7861. var time = date.getTime();
  7862. var random = Math.floor(Math.random() * 1000000000);
  7863. unique++;
  7864. return prefix + '_' + random + unique + String(time);
  7865. };
  7866. var add$4 = function (element, classes) {
  7867. each(classes, function (x) {
  7868. add$3(element, x);
  7869. });
  7870. };
  7871. var clone = function (original, isDeep) {
  7872. return Element.fromDom(original.dom().cloneNode(isDeep));
  7873. };
  7874. var shallow = function (original) {
  7875. return clone(original, false);
  7876. };
  7877. var deep = function (original) {
  7878. return clone(original, true);
  7879. };
  7880. var fromHtml$1 = function (html, scope) {
  7881. var doc = scope || domGlobals.document;
  7882. var div = doc.createElement('div');
  7883. div.innerHTML = html;
  7884. return children(Element.fromDom(div));
  7885. };
  7886. var get$5 = function (element) {
  7887. return element.dom().innerHTML;
  7888. };
  7889. var set$1 = function (element, content) {
  7890. var owner$1 = owner(element);
  7891. var docDom = owner$1.dom();
  7892. var fragment = Element.fromDom(docDom.createDocumentFragment());
  7893. var contentElements = fromHtml$1(content, docDom);
  7894. append$1(fragment, contentElements);
  7895. empty(element);
  7896. append(element, fragment);
  7897. };
  7898. var ZWSP = '\uFEFF';
  7899. var isZwsp = function (chr) {
  7900. return chr === ZWSP;
  7901. };
  7902. var trim$3 = function (text) {
  7903. return text.replace(new RegExp(ZWSP, 'g'), '');
  7904. };
  7905. var Zwsp = {
  7906. isZwsp: isZwsp,
  7907. ZWSP: ZWSP,
  7908. trim: trim$3
  7909. };
  7910. var isElement$2 = NodeType.isElement;
  7911. var isText$2 = NodeType.isText;
  7912. var isCaretContainerBlock = function (node) {
  7913. if (isText$2(node)) {
  7914. node = node.parentNode;
  7915. }
  7916. return isElement$2(node) && node.hasAttribute('data-mce-caret');
  7917. };
  7918. var isCaretContainerInline = function (node) {
  7919. return isText$2(node) && Zwsp.isZwsp(node.data);
  7920. };
  7921. var isCaretContainer = function (node) {
  7922. return isCaretContainerBlock(node) || isCaretContainerInline(node);
  7923. };
  7924. var hasContent = function (node) {
  7925. return node.firstChild !== node.lastChild || !NodeType.isBr(node.firstChild);
  7926. };
  7927. var insertInline = function (node, before) {
  7928. var doc, sibling, textNode, parentNode;
  7929. doc = node.ownerDocument;
  7930. textNode = doc.createTextNode(Zwsp.ZWSP);
  7931. parentNode = node.parentNode;
  7932. if (!before) {
  7933. sibling = node.nextSibling;
  7934. if (isText$2(sibling)) {
  7935. if (isCaretContainer(sibling)) {
  7936. return sibling;
  7937. }
  7938. if (startsWithCaretContainer(sibling)) {
  7939. sibling.splitText(1);
  7940. return sibling;
  7941. }
  7942. }
  7943. if (node.nextSibling) {
  7944. parentNode.insertBefore(textNode, node.nextSibling);
  7945. } else {
  7946. parentNode.appendChild(textNode);
  7947. }
  7948. } else {
  7949. sibling = node.previousSibling;
  7950. if (isText$2(sibling)) {
  7951. if (isCaretContainer(sibling)) {
  7952. return sibling;
  7953. }
  7954. if (endsWithCaretContainer(sibling)) {
  7955. return sibling.splitText(sibling.data.length - 1);
  7956. }
  7957. }
  7958. parentNode.insertBefore(textNode, node);
  7959. }
  7960. return textNode;
  7961. };
  7962. var isBeforeInline = function (pos) {
  7963. var container = pos.container();
  7964. if (!pos || !NodeType.isText(container)) {
  7965. return false;
  7966. }
  7967. return container.data.charAt(pos.offset()) === Zwsp.ZWSP || pos.isAtStart() && isCaretContainerInline(container.previousSibling);
  7968. };
  7969. var isAfterInline = function (pos) {
  7970. var container = pos.container();
  7971. if (!pos || !NodeType.isText(container)) {
  7972. return false;
  7973. }
  7974. return container.data.charAt(pos.offset() - 1) === Zwsp.ZWSP || pos.isAtEnd() && isCaretContainerInline(container.nextSibling);
  7975. };
  7976. var createBogusBr = function () {
  7977. var br = domGlobals.document.createElement('br');
  7978. br.setAttribute('data-mce-bogus', '1');
  7979. return br;
  7980. };
  7981. var insertBlock = function (blockName, node, before) {
  7982. var doc, blockNode, parentNode;
  7983. doc = node.ownerDocument;
  7984. blockNode = doc.createElement(blockName);
  7985. blockNode.setAttribute('data-mce-caret', before ? 'before' : 'after');
  7986. blockNode.setAttribute('data-mce-bogus', 'all');
  7987. blockNode.appendChild(createBogusBr());
  7988. parentNode = node.parentNode;
  7989. if (!before) {
  7990. if (node.nextSibling) {
  7991. parentNode.insertBefore(blockNode, node.nextSibling);
  7992. } else {
  7993. parentNode.appendChild(blockNode);
  7994. }
  7995. } else {
  7996. parentNode.insertBefore(blockNode, node);
  7997. }
  7998. return blockNode;
  7999. };
  8000. var startsWithCaretContainer = function (node) {
  8001. return isText$2(node) && node.data[0] === Zwsp.ZWSP;
  8002. };
  8003. var endsWithCaretContainer = function (node) {
  8004. return isText$2(node) && node.data[node.data.length - 1] === Zwsp.ZWSP;
  8005. };
  8006. var trimBogusBr = function (elm) {
  8007. var brs = elm.getElementsByTagName('br');
  8008. var lastBr = brs[brs.length - 1];
  8009. if (NodeType.isBogus(lastBr)) {
  8010. lastBr.parentNode.removeChild(lastBr);
  8011. }
  8012. };
  8013. var showCaretContainerBlock = function (caretContainer) {
  8014. if (caretContainer && caretContainer.hasAttribute('data-mce-caret')) {
  8015. trimBogusBr(caretContainer);
  8016. caretContainer.removeAttribute('data-mce-caret');
  8017. caretContainer.removeAttribute('data-mce-bogus');
  8018. caretContainer.removeAttribute('style');
  8019. caretContainer.removeAttribute('_moz_abspos');
  8020. return caretContainer;
  8021. }
  8022. return null;
  8023. };
  8024. var isRangeInCaretContainerBlock = function (range) {
  8025. return isCaretContainerBlock(range.startContainer);
  8026. };
  8027. var isContentEditableTrue$1 = NodeType.isContentEditableTrue;
  8028. var isContentEditableFalse$1 = NodeType.isContentEditableFalse;
  8029. var isBr$2 = NodeType.isBr;
  8030. var isText$3 = NodeType.isText;
  8031. var isInvalidTextElement = NodeType.matchNodeNames([
  8032. 'script',
  8033. 'style',
  8034. 'textarea'
  8035. ]);
  8036. var isAtomicInline = NodeType.matchNodeNames([
  8037. 'img',
  8038. 'input',
  8039. 'textarea',
  8040. 'hr',
  8041. 'iframe',
  8042. 'video',
  8043. 'audio',
  8044. 'object'
  8045. ]);
  8046. var isTable$2 = NodeType.matchNodeNames(['table']);
  8047. var isCaretContainer$1 = isCaretContainer;
  8048. var isCaretCandidate = function (node) {
  8049. if (isCaretContainer$1(node)) {
  8050. return false;
  8051. }
  8052. if (isText$3(node)) {
  8053. if (isInvalidTextElement(node.parentNode)) {
  8054. return false;
  8055. }
  8056. return true;
  8057. }
  8058. return isAtomicInline(node) || isBr$2(node) || isTable$2(node) || isNonUiContentEditableFalse(node);
  8059. };
  8060. var isUnselectable = function (node) {
  8061. return NodeType.isElement(node) && node.getAttribute('unselectable') === 'true';
  8062. };
  8063. var isNonUiContentEditableFalse = function (node) {
  8064. return isUnselectable(node) === false && isContentEditableFalse$1(node);
  8065. };
  8066. var isInEditable = function (node, root) {
  8067. for (node = node.parentNode; node && node !== root; node = node.parentNode) {
  8068. if (isNonUiContentEditableFalse(node)) {
  8069. return false;
  8070. }
  8071. if (isContentEditableTrue$1(node)) {
  8072. return true;
  8073. }
  8074. }
  8075. return true;
  8076. };
  8077. var isAtomicContentEditableFalse = function (node) {
  8078. if (!isNonUiContentEditableFalse(node)) {
  8079. return false;
  8080. }
  8081. return foldl(from$1(node.getElementsByTagName('*')), function (result, elm) {
  8082. return result || isContentEditableTrue$1(elm);
  8083. }, false) !== true;
  8084. };
  8085. var isAtomic = function (node) {
  8086. return isAtomicInline(node) || isAtomicContentEditableFalse(node);
  8087. };
  8088. var isEditableCaretCandidate = function (node, root) {
  8089. return isCaretCandidate(node) && isInEditable(node, root);
  8090. };
  8091. var round = Math.round;
  8092. var clone$1 = function (rect) {
  8093. if (!rect) {
  8094. return {
  8095. left: 0,
  8096. top: 0,
  8097. bottom: 0,
  8098. right: 0,
  8099. width: 0,
  8100. height: 0
  8101. };
  8102. }
  8103. return {
  8104. left: round(rect.left),
  8105. top: round(rect.top),
  8106. bottom: round(rect.bottom),
  8107. right: round(rect.right),
  8108. width: round(rect.width),
  8109. height: round(rect.height)
  8110. };
  8111. };
  8112. var collapse = function (rect, toStart) {
  8113. rect = clone$1(rect);
  8114. if (toStart) {
  8115. rect.right = rect.left;
  8116. } else {
  8117. rect.left = rect.left + rect.width;
  8118. rect.right = rect.left;
  8119. }
  8120. rect.width = 0;
  8121. return rect;
  8122. };
  8123. var isEqual = function (rect1, rect2) {
  8124. return rect1.left === rect2.left && rect1.top === rect2.top && rect1.bottom === rect2.bottom && rect1.right === rect2.right;
  8125. };
  8126. var isValidOverflow = function (overflowY, rect1, rect2) {
  8127. return overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2;
  8128. };
  8129. var isAbove = function (rect1, rect2) {
  8130. if (rect1.bottom - rect1.height / 2 < rect2.top) {
  8131. return true;
  8132. }
  8133. if (rect1.top > rect2.bottom) {
  8134. return false;
  8135. }
  8136. return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2);
  8137. };
  8138. var isBelow = function (rect1, rect2) {
  8139. if (rect1.top > rect2.bottom) {
  8140. return true;
  8141. }
  8142. if (rect1.bottom < rect2.top) {
  8143. return false;
  8144. }
  8145. return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2);
  8146. };
  8147. var containsXY = function (rect, clientX, clientY) {
  8148. return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
  8149. };
  8150. var getSelectedNode = function (range) {
  8151. var startContainer = range.startContainer, startOffset = range.startOffset;
  8152. if (startContainer.hasChildNodes() && range.endOffset === startOffset + 1) {
  8153. return startContainer.childNodes[startOffset];
  8154. }
  8155. return null;
  8156. };
  8157. var getNode = function (container, offset) {
  8158. if (container.nodeType === 1 && container.hasChildNodes()) {
  8159. if (offset >= container.childNodes.length) {
  8160. offset = container.childNodes.length - 1;
  8161. }
  8162. container = container.childNodes[offset];
  8163. }
  8164. return container;
  8165. };
  8166. var extendingChars = new RegExp('[\u0300-\u036f\u0483-\u0487\u0488-\u0489\u0591-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u061a' + '\u064b-\u065f\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0' + '\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0902\u093a\u093c' + '\u0941-\u0948\u094d\u0951-\u0957\u0962-\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2-\u09e3' + '\u0a01-\u0a02\u0a3c\u0a41-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a51\u0a70-\u0a71\u0a75\u0a81-\u0a82\u0abc' + '\u0ac1-\u0ac5\u0ac7-\u0ac8\u0acd\u0ae2-\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57' + '\u0b62-\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c00\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56' + '\u0c62-\u0c63\u0c81\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc-\u0ccd\u0cd5-\u0cd6\u0ce2-\u0ce3\u0d01\u0d3e\u0d41-\u0d44' + '\u0d4d\u0d57\u0d62-\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9' + '\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86-\u0f87\u0f8d-\u0f97' + '\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039-\u103a\u103d-\u103e\u1058-\u1059\u105e-\u1060\u1071-\u1074' + '\u1082\u1085-\u1086\u108d\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b4-\u17b5' + '\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193b\u1a17-\u1a18' + '\u1a1b\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1ab0-\u1abd\u1ABE\u1b00-\u1b03\u1b34' + '\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80-\u1b81\u1ba2-\u1ba5\u1ba8-\u1ba9\u1bab-\u1bad\u1be6\u1be8-\u1be9' + '\u1bed\u1bef-\u1bf1\u1c2c-\u1c33\u1c36-\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1cf4\u1cf8-\u1cf9' + '\u1dc0-\u1df5\u1dfc-\u1dff\u200c-\u200d\u20d0-\u20dc\u20DD-\u20E0\u20e1\u20E2-\u20E4\u20e5-\u20f0\u2cef-\u2cf1' + '\u2d7f\u2de0-\u2dff\u302a-\u302d\u302e-\u302f\u3099-\u309a\ua66f\uA670-\uA672\ua674-\ua67d\ua69e-\ua69f\ua6f0-\ua6f1' + '\ua802\ua806\ua80b\ua825-\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc' + '\ua9e5\uaa29-\uaa2e\uaa31-\uaa32\uaa35-\uaa36\uaa43\uaa4c\uaa7c\uaab0\uaab2-\uaab4\uaab7-\uaab8\uaabe-\uaabf\uaac1' + '\uaaec-\uaaed\uaaf6\uabe5\uabe8\uabed\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\uff9e-\uff9f]');
  8167. var isExtendingChar = function (ch) {
  8168. return typeof ch === 'string' && ch.charCodeAt(0) >= 768 && extendingChars.test(ch);
  8169. };
  8170. var lift2 = function (oa, ob, f) {
  8171. return oa.isSome() && ob.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie())) : Option.none();
  8172. };
  8173. var lift3 = function (oa, ob, oc, f) {
  8174. return oa.isSome() && ob.isSome() && oc.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Option.none();
  8175. };
  8176. var someIf = function (b, a) {
  8177. return b ? Option.some(a) : Option.none();
  8178. };
  8179. var slice$2 = [].slice;
  8180. var or = function () {
  8181. var x = [];
  8182. for (var _i = 0; _i < arguments.length; _i++) {
  8183. x[_i] = arguments[_i];
  8184. }
  8185. var args = slice$2.call(arguments);
  8186. return function (x) {
  8187. for (var i = 0; i < args.length; i++) {
  8188. if (args[i](x)) {
  8189. return true;
  8190. }
  8191. }
  8192. return false;
  8193. };
  8194. };
  8195. var and = function () {
  8196. var x = [];
  8197. for (var _i = 0; _i < arguments.length; _i++) {
  8198. x[_i] = arguments[_i];
  8199. }
  8200. var args = slice$2.call(arguments);
  8201. return function (x) {
  8202. for (var i = 0; i < args.length; i++) {
  8203. if (!args[i](x)) {
  8204. return false;
  8205. }
  8206. }
  8207. return true;
  8208. };
  8209. };
  8210. var Predicate = {
  8211. and: and,
  8212. or: or
  8213. };
  8214. var isElement$3 = NodeType.isElement;
  8215. var isCaretCandidate$1 = isCaretCandidate;
  8216. var isBlock$1 = NodeType.matchStyleValues('display', 'block table');
  8217. var isFloated = NodeType.matchStyleValues('float', 'left right');
  8218. var isValidElementCaretCandidate = Predicate.and(isElement$3, isCaretCandidate$1, not(isFloated));
  8219. var isNotPre = not(NodeType.matchStyleValues('white-space', 'pre pre-line pre-wrap'));
  8220. var isText$4 = NodeType.isText;
  8221. var isBr$3 = NodeType.isBr;
  8222. var nodeIndex = DOMUtils$1.nodeIndex;
  8223. var resolveIndex = getNode;
  8224. var createRange = function (doc) {
  8225. return 'createRange' in doc ? doc.createRange() : DOMUtils$1.DOM.createRng();
  8226. };
  8227. var isWhiteSpace = function (chr) {
  8228. return chr && /[\r\n\t ]/.test(chr);
  8229. };
  8230. var isRange = function (rng) {
  8231. return !!rng.setStart && !!rng.setEnd;
  8232. };
  8233. var isHiddenWhiteSpaceRange = function (range) {
  8234. var container = range.startContainer;
  8235. var offset = range.startOffset;
  8236. var text;
  8237. if (isWhiteSpace(range.toString()) && isNotPre(container.parentNode) && NodeType.isText(container)) {
  8238. text = container.data;
  8239. if (isWhiteSpace(text[offset - 1]) || isWhiteSpace(text[offset + 1])) {
  8240. return true;
  8241. }
  8242. }
  8243. return false;
  8244. };
  8245. var getBrClientRect = function (brNode) {
  8246. var doc = brNode.ownerDocument;
  8247. var rng = createRange(doc);
  8248. var nbsp = doc.createTextNode('\xA0');
  8249. var parentNode = brNode.parentNode;
  8250. var clientRect;
  8251. parentNode.insertBefore(nbsp, brNode);
  8252. rng.setStart(nbsp, 0);
  8253. rng.setEnd(nbsp, 1);
  8254. clientRect = clone$1(rng.getBoundingClientRect());
  8255. parentNode.removeChild(nbsp);
  8256. return clientRect;
  8257. };
  8258. var getBoundingClientRectWebKitText = function (rng) {
  8259. var sc = rng.startContainer;
  8260. var ec = rng.endContainer;
  8261. var so = rng.startOffset;
  8262. var eo = rng.endOffset;
  8263. if (sc === ec && NodeType.isText(ec) && so === 0 && eo === 1) {
  8264. var newRng = rng.cloneRange();
  8265. newRng.setEndAfter(ec);
  8266. return getBoundingClientRect(newRng);
  8267. } else {
  8268. return null;
  8269. }
  8270. };
  8271. var isZeroRect = function (r) {
  8272. return r.left === 0 && r.right === 0 && r.top === 0 && r.bottom === 0;
  8273. };
  8274. var getBoundingClientRect = function (item) {
  8275. var clientRect, clientRects;
  8276. clientRects = item.getClientRects();
  8277. if (clientRects.length > 0) {
  8278. clientRect = clone$1(clientRects[0]);
  8279. } else {
  8280. clientRect = clone$1(item.getBoundingClientRect());
  8281. }
  8282. if (!isRange(item) && isBr$3(item) && isZeroRect(clientRect)) {
  8283. return getBrClientRect(item);
  8284. }
  8285. if (isZeroRect(clientRect) && isRange(item)) {
  8286. return getBoundingClientRectWebKitText(item);
  8287. }
  8288. return clientRect;
  8289. };
  8290. var collapseAndInflateWidth = function (clientRect, toStart) {
  8291. var newClientRect = collapse(clientRect, toStart);
  8292. newClientRect.width = 1;
  8293. newClientRect.right = newClientRect.left + 1;
  8294. return newClientRect;
  8295. };
  8296. var getCaretPositionClientRects = function (caretPosition) {
  8297. var clientRects = [];
  8298. var beforeNode, node;
  8299. var addUniqueAndValidRect = function (clientRect) {
  8300. if (clientRect.height === 0) {
  8301. return;
  8302. }
  8303. if (clientRects.length > 0) {
  8304. if (isEqual(clientRect, clientRects[clientRects.length - 1])) {
  8305. return;
  8306. }
  8307. }
  8308. clientRects.push(clientRect);
  8309. };
  8310. var addCharacterOffset = function (container, offset) {
  8311. var range = createRange(container.ownerDocument);
  8312. if (offset < container.data.length) {
  8313. if (isExtendingChar(container.data[offset])) {
  8314. return clientRects;
  8315. }
  8316. if (isExtendingChar(container.data[offset - 1])) {
  8317. range.setStart(container, offset);
  8318. range.setEnd(container, offset + 1);
  8319. if (!isHiddenWhiteSpaceRange(range)) {
  8320. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(range), false));
  8321. return clientRects;
  8322. }
  8323. }
  8324. }
  8325. if (offset > 0) {
  8326. range.setStart(container, offset - 1);
  8327. range.setEnd(container, offset);
  8328. if (!isHiddenWhiteSpaceRange(range)) {
  8329. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(range), false));
  8330. }
  8331. }
  8332. if (offset < container.data.length) {
  8333. range.setStart(container, offset);
  8334. range.setEnd(container, offset + 1);
  8335. if (!isHiddenWhiteSpaceRange(range)) {
  8336. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(range), true));
  8337. }
  8338. }
  8339. };
  8340. if (isText$4(caretPosition.container())) {
  8341. addCharacterOffset(caretPosition.container(), caretPosition.offset());
  8342. return clientRects;
  8343. }
  8344. if (isElement$3(caretPosition.container())) {
  8345. if (caretPosition.isAtEnd()) {
  8346. node = resolveIndex(caretPosition.container(), caretPosition.offset());
  8347. if (isText$4(node)) {
  8348. addCharacterOffset(node, node.data.length);
  8349. }
  8350. if (isValidElementCaretCandidate(node) && !isBr$3(node)) {
  8351. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(node), false));
  8352. }
  8353. } else {
  8354. node = resolveIndex(caretPosition.container(), caretPosition.offset());
  8355. if (isText$4(node)) {
  8356. addCharacterOffset(node, 0);
  8357. }
  8358. if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) {
  8359. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(node), false));
  8360. return clientRects;
  8361. }
  8362. beforeNode = resolveIndex(caretPosition.container(), caretPosition.offset() - 1);
  8363. if (isValidElementCaretCandidate(beforeNode) && !isBr$3(beforeNode)) {
  8364. if (isBlock$1(beforeNode) || isBlock$1(node) || !isValidElementCaretCandidate(node)) {
  8365. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(beforeNode), false));
  8366. }
  8367. }
  8368. if (isValidElementCaretCandidate(node)) {
  8369. addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect(node), true));
  8370. }
  8371. }
  8372. }
  8373. return clientRects;
  8374. };
  8375. function CaretPosition(container, offset, clientRects) {
  8376. var isAtStart = function () {
  8377. if (isText$4(container)) {
  8378. return offset === 0;
  8379. }
  8380. return offset === 0;
  8381. };
  8382. var isAtEnd = function () {
  8383. if (isText$4(container)) {
  8384. return offset >= container.data.length;
  8385. }
  8386. return offset >= container.childNodes.length;
  8387. };
  8388. var toRange = function () {
  8389. var range;
  8390. range = createRange(container.ownerDocument);
  8391. range.setStart(container, offset);
  8392. range.setEnd(container, offset);
  8393. return range;
  8394. };
  8395. var getClientRects = function () {
  8396. if (!clientRects) {
  8397. clientRects = getCaretPositionClientRects(CaretPosition(container, offset));
  8398. }
  8399. return clientRects;
  8400. };
  8401. var isVisible = function () {
  8402. return getClientRects().length > 0;
  8403. };
  8404. var isEqual = function (caretPosition) {
  8405. return caretPosition && container === caretPosition.container() && offset === caretPosition.offset();
  8406. };
  8407. var getNode = function (before) {
  8408. return resolveIndex(container, before ? offset - 1 : offset);
  8409. };
  8410. return {
  8411. container: constant(container),
  8412. offset: constant(offset),
  8413. toRange: toRange,
  8414. getClientRects: getClientRects,
  8415. isVisible: isVisible,
  8416. isAtStart: isAtStart,
  8417. isAtEnd: isAtEnd,
  8418. isEqual: isEqual,
  8419. getNode: getNode
  8420. };
  8421. }
  8422. (function (CaretPosition) {
  8423. CaretPosition.fromRangeStart = function (range) {
  8424. return CaretPosition(range.startContainer, range.startOffset);
  8425. };
  8426. CaretPosition.fromRangeEnd = function (range) {
  8427. return CaretPosition(range.endContainer, range.endOffset);
  8428. };
  8429. CaretPosition.after = function (node) {
  8430. return CaretPosition(node.parentNode, nodeIndex(node) + 1);
  8431. };
  8432. CaretPosition.before = function (node) {
  8433. return CaretPosition(node.parentNode, nodeIndex(node));
  8434. };
  8435. CaretPosition.isAbove = function (pos1, pos2) {
  8436. return lift2(head(pos2.getClientRects()), last(pos1.getClientRects()), isAbove).getOr(false);
  8437. };
  8438. CaretPosition.isBelow = function (pos1, pos2) {
  8439. return lift2(last(pos2.getClientRects()), head(pos1.getClientRects()), isBelow).getOr(false);
  8440. };
  8441. CaretPosition.isAtStart = function (pos) {
  8442. return pos ? pos.isAtStart() : false;
  8443. };
  8444. CaretPosition.isAtEnd = function (pos) {
  8445. return pos ? pos.isAtEnd() : false;
  8446. };
  8447. CaretPosition.isTextPosition = function (pos) {
  8448. return pos ? NodeType.isText(pos.container()) : false;
  8449. };
  8450. CaretPosition.isElementPosition = function (pos) {
  8451. return CaretPosition.isTextPosition(pos) === false;
  8452. };
  8453. }(CaretPosition || (CaretPosition = {})));
  8454. var CaretPosition$1 = CaretPosition;
  8455. var isText$5 = NodeType.isText;
  8456. var isBogus$1 = NodeType.isBogus;
  8457. var nodeIndex$1 = DOMUtils$1.nodeIndex;
  8458. var normalizedParent = function (node) {
  8459. var parentNode = node.parentNode;
  8460. if (isBogus$1(parentNode)) {
  8461. return normalizedParent(parentNode);
  8462. }
  8463. return parentNode;
  8464. };
  8465. var getChildNodes = function (node) {
  8466. if (!node) {
  8467. return [];
  8468. }
  8469. return ArrUtils.reduce(node.childNodes, function (result, node) {
  8470. if (isBogus$1(node) && node.nodeName !== 'BR') {
  8471. result = result.concat(getChildNodes(node));
  8472. } else {
  8473. result.push(node);
  8474. }
  8475. return result;
  8476. }, []);
  8477. };
  8478. var normalizedTextOffset = function (node, offset) {
  8479. while (node = node.previousSibling) {
  8480. if (!isText$5(node)) {
  8481. break;
  8482. }
  8483. offset += node.data.length;
  8484. }
  8485. return offset;
  8486. };
  8487. var equal = function (a) {
  8488. return function (b) {
  8489. return a === b;
  8490. };
  8491. };
  8492. var normalizedNodeIndex = function (node) {
  8493. var nodes, index, numTextFragments;
  8494. nodes = getChildNodes(normalizedParent(node));
  8495. index = ArrUtils.findIndex(nodes, equal(node), node);
  8496. nodes = nodes.slice(0, index + 1);
  8497. numTextFragments = ArrUtils.reduce(nodes, function (result, node, i) {
  8498. if (isText$5(node) && isText$5(nodes[i - 1])) {
  8499. result++;
  8500. }
  8501. return result;
  8502. }, 0);
  8503. nodes = ArrUtils.filter(nodes, NodeType.matchNodeNames([node.nodeName]));
  8504. index = ArrUtils.findIndex(nodes, equal(node), node);
  8505. return index - numTextFragments;
  8506. };
  8507. var createPathItem = function (node) {
  8508. var name;
  8509. if (isText$5(node)) {
  8510. name = 'text()';
  8511. } else {
  8512. name = node.nodeName.toLowerCase();
  8513. }
  8514. return name + '[' + normalizedNodeIndex(node) + ']';
  8515. };
  8516. var parentsUntil = function (root, node, predicate) {
  8517. var parents = [];
  8518. for (node = node.parentNode; node !== root; node = node.parentNode) {
  8519. if (predicate && predicate(node)) {
  8520. break;
  8521. }
  8522. parents.push(node);
  8523. }
  8524. return parents;
  8525. };
  8526. var create$2 = function (root, caretPosition) {
  8527. var container, offset, path = [], outputOffset, childNodes, parents;
  8528. container = caretPosition.container();
  8529. offset = caretPosition.offset();
  8530. if (isText$5(container)) {
  8531. outputOffset = normalizedTextOffset(container, offset);
  8532. } else {
  8533. childNodes = container.childNodes;
  8534. if (offset >= childNodes.length) {
  8535. outputOffset = 'after';
  8536. offset = childNodes.length - 1;
  8537. } else {
  8538. outputOffset = 'before';
  8539. }
  8540. container = childNodes[offset];
  8541. }
  8542. path.push(createPathItem(container));
  8543. parents = parentsUntil(root, container);
  8544. parents = ArrUtils.filter(parents, not(NodeType.isBogus));
  8545. path = path.concat(ArrUtils.map(parents, function (node) {
  8546. return createPathItem(node);
  8547. }));
  8548. return path.reverse().join('/') + ',' + outputOffset;
  8549. };
  8550. var resolvePathItem = function (node, name, index) {
  8551. var nodes = getChildNodes(node);
  8552. nodes = ArrUtils.filter(nodes, function (node, index) {
  8553. return !isText$5(node) || !isText$5(nodes[index - 1]);
  8554. });
  8555. nodes = ArrUtils.filter(nodes, NodeType.matchNodeNames([name]));
  8556. return nodes[index];
  8557. };
  8558. var findTextPosition = function (container, offset) {
  8559. var node = container, targetOffset = 0, dataLen;
  8560. while (isText$5(node)) {
  8561. dataLen = node.data.length;
  8562. if (offset >= targetOffset && offset <= targetOffset + dataLen) {
  8563. container = node;
  8564. offset = offset - targetOffset;
  8565. break;
  8566. }
  8567. if (!isText$5(node.nextSibling)) {
  8568. container = node;
  8569. offset = dataLen;
  8570. break;
  8571. }
  8572. targetOffset += dataLen;
  8573. node = node.nextSibling;
  8574. }
  8575. if (isText$5(container) && offset > container.data.length) {
  8576. offset = container.data.length;
  8577. }
  8578. return CaretPosition$1(container, offset);
  8579. };
  8580. var resolve$1 = function (root, path) {
  8581. var parts, container, offset;
  8582. if (!path) {
  8583. return null;
  8584. }
  8585. parts = path.split(',');
  8586. path = parts[0].split('/');
  8587. offset = parts.length > 1 ? parts[1] : 'before';
  8588. container = ArrUtils.reduce(path, function (result, value) {
  8589. value = /([\w\-\(\)]+)\[([0-9]+)\]/.exec(value);
  8590. if (!value) {
  8591. return null;
  8592. }
  8593. if (value[1] === 'text()') {
  8594. value[1] = '#text';
  8595. }
  8596. return resolvePathItem(result, value[1], parseInt(value[2], 10));
  8597. }, root);
  8598. if (!container) {
  8599. return null;
  8600. }
  8601. if (!isText$5(container)) {
  8602. if (offset === 'after') {
  8603. offset = nodeIndex$1(container) + 1;
  8604. } else {
  8605. offset = nodeIndex$1(container);
  8606. }
  8607. return CaretPosition$1(container.parentNode, offset);
  8608. }
  8609. return findTextPosition(container, parseInt(offset, 10));
  8610. };
  8611. var trimEmptyTextNode = function (dom, node) {
  8612. if (NodeType.isText(node) && node.data.length === 0) {
  8613. dom.remove(node);
  8614. }
  8615. };
  8616. var insertNode = function (dom, rng, node) {
  8617. rng.insertNode(node);
  8618. trimEmptyTextNode(dom, node.previousSibling);
  8619. trimEmptyTextNode(dom, node.nextSibling);
  8620. };
  8621. var insertFragment = function (dom, rng, frag) {
  8622. var firstChild = Option.from(frag.firstChild);
  8623. var lastChild = Option.from(frag.lastChild);
  8624. rng.insertNode(frag);
  8625. firstChild.each(function (child) {
  8626. return trimEmptyTextNode(dom, child.previousSibling);
  8627. });
  8628. lastChild.each(function (child) {
  8629. return trimEmptyTextNode(dom, child.nextSibling);
  8630. });
  8631. };
  8632. var rangeInsertNode = function (dom, rng, node) {
  8633. if (NodeType.isDocumentFragment(node)) {
  8634. insertFragment(dom, rng, node);
  8635. } else {
  8636. insertNode(dom, rng, node);
  8637. }
  8638. };
  8639. var isContentEditableFalse$2 = NodeType.isContentEditableFalse;
  8640. var getNormalizedTextOffset = function (trim, container, offset) {
  8641. var node, trimmedOffset;
  8642. trimmedOffset = trim(container.data.slice(0, offset)).length;
  8643. for (node = container.previousSibling; node && NodeType.isText(node); node = node.previousSibling) {
  8644. trimmedOffset += trim(node.data).length;
  8645. }
  8646. return trimmedOffset;
  8647. };
  8648. var getPoint = function (dom, trim, normalized, rng, start) {
  8649. var container = rng[start ? 'startContainer' : 'endContainer'];
  8650. var offset = rng[start ? 'startOffset' : 'endOffset'];
  8651. var point = [];
  8652. var childNodes, after = 0;
  8653. var root = dom.getRoot();
  8654. if (NodeType.isText(container)) {
  8655. point.push(normalized ? getNormalizedTextOffset(trim, container, offset) : offset);
  8656. } else {
  8657. childNodes = container.childNodes;
  8658. if (offset >= childNodes.length && childNodes.length) {
  8659. after = 1;
  8660. offset = Math.max(0, childNodes.length - 1);
  8661. }
  8662. point.push(dom.nodeIndex(childNodes[offset], normalized) + after);
  8663. }
  8664. for (; container && container !== root; container = container.parentNode) {
  8665. point.push(dom.nodeIndex(container, normalized));
  8666. }
  8667. return point;
  8668. };
  8669. var getLocation = function (trim, selection, normalized, rng) {
  8670. var dom = selection.dom, bookmark = {};
  8671. bookmark.start = getPoint(dom, trim, normalized, rng, true);
  8672. if (!selection.isCollapsed()) {
  8673. bookmark.end = getPoint(dom, trim, normalized, rng, false);
  8674. }
  8675. return bookmark;
  8676. };
  8677. var findIndex$2 = function (dom, name, element) {
  8678. var count = 0;
  8679. Tools.each(dom.select(name), function (node) {
  8680. if (node.getAttribute('data-mce-bogus') === 'all') {
  8681. return;
  8682. }
  8683. if (node === element) {
  8684. return false;
  8685. }
  8686. count++;
  8687. });
  8688. return count;
  8689. };
  8690. var moveEndPoint = function (rng, start) {
  8691. var container, offset, childNodes;
  8692. var prefix = start ? 'start' : 'end';
  8693. container = rng[prefix + 'Container'];
  8694. offset = rng[prefix + 'Offset'];
  8695. if (NodeType.isElement(container) && container.nodeName === 'TR') {
  8696. childNodes = container.childNodes;
  8697. container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
  8698. if (container) {
  8699. offset = start ? 0 : container.childNodes.length;
  8700. rng['set' + (start ? 'Start' : 'End')](container, offset);
  8701. }
  8702. }
  8703. };
  8704. var normalizeTableCellSelection = function (rng) {
  8705. moveEndPoint(rng, true);
  8706. moveEndPoint(rng, false);
  8707. return rng;
  8708. };
  8709. var findSibling = function (node, offset) {
  8710. var sibling;
  8711. if (NodeType.isElement(node)) {
  8712. node = getNode(node, offset);
  8713. if (isContentEditableFalse$2(node)) {
  8714. return node;
  8715. }
  8716. }
  8717. if (isCaretContainer(node)) {
  8718. if (NodeType.isText(node) && isCaretContainerBlock(node)) {
  8719. node = node.parentNode;
  8720. }
  8721. sibling = node.previousSibling;
  8722. if (isContentEditableFalse$2(sibling)) {
  8723. return sibling;
  8724. }
  8725. sibling = node.nextSibling;
  8726. if (isContentEditableFalse$2(sibling)) {
  8727. return sibling;
  8728. }
  8729. }
  8730. };
  8731. var findAdjacentContentEditableFalseElm = function (rng) {
  8732. return findSibling(rng.startContainer, rng.startOffset) || findSibling(rng.endContainer, rng.endOffset);
  8733. };
  8734. var getOffsetBookmark = function (trim, normalized, selection) {
  8735. var element = selection.getNode();
  8736. var name = element ? element.nodeName : null;
  8737. var rng = selection.getRng();
  8738. if (isContentEditableFalse$2(element) || name === 'IMG') {
  8739. return {
  8740. name: name,
  8741. index: findIndex$2(selection.dom, name, element)
  8742. };
  8743. }
  8744. var sibling = findAdjacentContentEditableFalseElm(rng);
  8745. if (sibling) {
  8746. name = sibling.tagName;
  8747. return {
  8748. name: name,
  8749. index: findIndex$2(selection.dom, name, sibling)
  8750. };
  8751. }
  8752. return getLocation(trim, selection, normalized, rng);
  8753. };
  8754. var getCaretBookmark = function (selection) {
  8755. var rng = selection.getRng();
  8756. return {
  8757. start: create$2(selection.dom.getRoot(), CaretPosition$1.fromRangeStart(rng)),
  8758. end: create$2(selection.dom.getRoot(), CaretPosition$1.fromRangeEnd(rng))
  8759. };
  8760. };
  8761. var getRangeBookmark = function (selection) {
  8762. return { rng: selection.getRng() };
  8763. };
  8764. var createBookmarkSpan = function (dom, id, filled) {
  8765. var args = {
  8766. 'data-mce-type': 'bookmark',
  8767. 'id': id,
  8768. 'style': 'overflow:hidden;line-height:0px'
  8769. };
  8770. return filled ? dom.create('span', args, '&#xFEFF;') : dom.create('span', args);
  8771. };
  8772. var getPersistentBookmark = function (selection, filled) {
  8773. var dom = selection.dom;
  8774. var rng = selection.getRng();
  8775. var id = dom.uniqueId();
  8776. var collapsed = selection.isCollapsed();
  8777. var element = selection.getNode();
  8778. var name = element.nodeName;
  8779. if (name === 'IMG') {
  8780. return {
  8781. name: name,
  8782. index: findIndex$2(dom, name, element)
  8783. };
  8784. }
  8785. var rng2 = normalizeTableCellSelection(rng.cloneRange());
  8786. if (!collapsed) {
  8787. rng2.collapse(false);
  8788. var endBookmarkNode = createBookmarkSpan(dom, id + '_end', filled);
  8789. rangeInsertNode(dom, rng2, endBookmarkNode);
  8790. }
  8791. rng = normalizeTableCellSelection(rng);
  8792. rng.collapse(true);
  8793. var startBookmarkNode = createBookmarkSpan(dom, id + '_start', filled);
  8794. rangeInsertNode(dom, rng, startBookmarkNode);
  8795. selection.moveToBookmark({
  8796. id: id,
  8797. keep: 1
  8798. });
  8799. return { id: id };
  8800. };
  8801. var getBookmark = function (selection, type, normalized) {
  8802. if (type === 2) {
  8803. return getOffsetBookmark(Zwsp.trim, normalized, selection);
  8804. } else if (type === 3) {
  8805. return getCaretBookmark(selection);
  8806. } else if (type) {
  8807. return getRangeBookmark(selection);
  8808. } else {
  8809. return getPersistentBookmark(selection, false);
  8810. }
  8811. };
  8812. var GetBookmark = {
  8813. getBookmark: getBookmark,
  8814. getUndoBookmark: curry(getOffsetBookmark, identity, true),
  8815. getPersistentBookmark: getPersistentBookmark
  8816. };
  8817. var CARET_ID = '_mce_caret';
  8818. var isCaretNode = function (node) {
  8819. return NodeType.isElement(node) && node.id === CARET_ID;
  8820. };
  8821. var getParentCaretContainer = function (body, node) {
  8822. while (node && node !== body) {
  8823. if (node.id === CARET_ID) {
  8824. return node;
  8825. }
  8826. node = node.parentNode;
  8827. }
  8828. return null;
  8829. };
  8830. var isElement$4 = NodeType.isElement;
  8831. var isText$6 = NodeType.isText;
  8832. var removeNode = function (node) {
  8833. var parentNode = node.parentNode;
  8834. if (parentNode) {
  8835. parentNode.removeChild(node);
  8836. }
  8837. };
  8838. var getNodeValue = function (node) {
  8839. try {
  8840. return node.nodeValue;
  8841. } catch (ex) {
  8842. return '';
  8843. }
  8844. };
  8845. var setNodeValue = function (node, text) {
  8846. if (text.length === 0) {
  8847. removeNode(node);
  8848. } else {
  8849. node.nodeValue = text;
  8850. }
  8851. };
  8852. var trimCount = function (text) {
  8853. var trimmedText = Zwsp.trim(text);
  8854. return {
  8855. count: text.length - trimmedText.length,
  8856. text: trimmedText
  8857. };
  8858. };
  8859. var removeUnchanged = function (caretContainer, pos) {
  8860. remove$5(caretContainer);
  8861. return pos;
  8862. };
  8863. var removeTextAndReposition = function (caretContainer, pos) {
  8864. var before = trimCount(caretContainer.data.substr(0, pos.offset()));
  8865. var after = trimCount(caretContainer.data.substr(pos.offset()));
  8866. var text = before.text + after.text;
  8867. if (text.length > 0) {
  8868. setNodeValue(caretContainer, text);
  8869. return CaretPosition$1(caretContainer, pos.offset() - before.count);
  8870. } else {
  8871. return pos;
  8872. }
  8873. };
  8874. var removeElementAndReposition = function (caretContainer, pos) {
  8875. var parentNode = pos.container();
  8876. var newPosition = indexOf(from$1(parentNode.childNodes), caretContainer).map(function (index) {
  8877. return index < pos.offset() ? CaretPosition$1(parentNode, pos.offset() - 1) : pos;
  8878. }).getOr(pos);
  8879. remove$5(caretContainer);
  8880. return newPosition;
  8881. };
  8882. var removeTextCaretContainer = function (caretContainer, pos) {
  8883. return isText$6(caretContainer) && pos.container() === caretContainer ? removeTextAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
  8884. };
  8885. var removeElementCaretContainer = function (caretContainer, pos) {
  8886. return pos.container() === caretContainer.parentNode ? removeElementAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
  8887. };
  8888. var removeAndReposition = function (container, pos) {
  8889. return CaretPosition$1.isTextPosition(pos) ? removeTextCaretContainer(container, pos) : removeElementCaretContainer(container, pos);
  8890. };
  8891. var remove$5 = function (caretContainerNode) {
  8892. if (isElement$4(caretContainerNode) && isCaretContainer(caretContainerNode)) {
  8893. if (hasContent(caretContainerNode)) {
  8894. caretContainerNode.removeAttribute('data-mce-caret');
  8895. } else {
  8896. removeNode(caretContainerNode);
  8897. }
  8898. }
  8899. if (isText$6(caretContainerNode)) {
  8900. var text = Zwsp.trim(getNodeValue(caretContainerNode));
  8901. setNodeValue(caretContainerNode, text);
  8902. }
  8903. };
  8904. var CaretContainerRemove = {
  8905. removeAndReposition: removeAndReposition,
  8906. remove: remove$5
  8907. };
  8908. var browser$3 = detect$3().browser;
  8909. var isContentEditableFalse$3 = NodeType.isContentEditableFalse;
  8910. var isTableCell$1 = function (node) {
  8911. return NodeType.isElement(node) && /^(TD|TH)$/i.test(node.tagName);
  8912. };
  8913. var getAbsoluteClientRect = function (root, element, before) {
  8914. var clientRect = collapse(element.getBoundingClientRect(), before);
  8915. var docElm, scrollX, scrollY, margin, rootRect;
  8916. if (root.tagName === 'BODY') {
  8917. docElm = root.ownerDocument.documentElement;
  8918. scrollX = root.scrollLeft || docElm.scrollLeft;
  8919. scrollY = root.scrollTop || docElm.scrollTop;
  8920. } else {
  8921. rootRect = root.getBoundingClientRect();
  8922. scrollX = root.scrollLeft - rootRect.left;
  8923. scrollY = root.scrollTop - rootRect.top;
  8924. }
  8925. clientRect.left += scrollX;
  8926. clientRect.right += scrollX;
  8927. clientRect.top += scrollY;
  8928. clientRect.bottom += scrollY;
  8929. clientRect.width = 1;
  8930. margin = element.offsetWidth - element.clientWidth;
  8931. if (margin > 0) {
  8932. if (before) {
  8933. margin *= -1;
  8934. }
  8935. clientRect.left += margin;
  8936. clientRect.right += margin;
  8937. }
  8938. return clientRect;
  8939. };
  8940. var trimInlineCaretContainers = function (root) {
  8941. var contentEditableFalseNodes, node, sibling, i, data;
  8942. contentEditableFalseNodes = DomQuery('*[contentEditable=false]', root);
  8943. for (i = 0; i < contentEditableFalseNodes.length; i++) {
  8944. node = contentEditableFalseNodes[i];
  8945. sibling = node.previousSibling;
  8946. if (endsWithCaretContainer(sibling)) {
  8947. data = sibling.data;
  8948. if (data.length === 1) {
  8949. sibling.parentNode.removeChild(sibling);
  8950. } else {
  8951. sibling.deleteData(data.length - 1, 1);
  8952. }
  8953. }
  8954. sibling = node.nextSibling;
  8955. if (startsWithCaretContainer(sibling)) {
  8956. data = sibling.data;
  8957. if (data.length === 1) {
  8958. sibling.parentNode.removeChild(sibling);
  8959. } else {
  8960. sibling.deleteData(0, 1);
  8961. }
  8962. }
  8963. }
  8964. };
  8965. var FakeCaret = function (root, isBlock, hasFocus) {
  8966. var lastVisualCaret = Cell(Option.none());
  8967. var cursorInterval, caretContainerNode;
  8968. var show = function (before, element) {
  8969. var clientRect, rng;
  8970. hide();
  8971. if (isTableCell$1(element)) {
  8972. return null;
  8973. }
  8974. if (isBlock(element)) {
  8975. caretContainerNode = insertBlock('p', element, before);
  8976. clientRect = getAbsoluteClientRect(root, element, before);
  8977. DomQuery(caretContainerNode).css('top', clientRect.top);
  8978. var caret = DomQuery('<div class="mce-visual-caret" data-mce-bogus="all"></div>').css(clientRect).appendTo(root)[0];
  8979. lastVisualCaret.set(Option.some({
  8980. caret: caret,
  8981. element: element,
  8982. before: before
  8983. }));
  8984. lastVisualCaret.get().each(function (caretState) {
  8985. if (before) {
  8986. DomQuery(caretState.caret).addClass('mce-visual-caret-before');
  8987. }
  8988. });
  8989. startBlink();
  8990. rng = element.ownerDocument.createRange();
  8991. rng.setStart(caretContainerNode, 0);
  8992. rng.setEnd(caretContainerNode, 0);
  8993. } else {
  8994. caretContainerNode = insertInline(element, before);
  8995. rng = element.ownerDocument.createRange();
  8996. if (isContentEditableFalse$3(caretContainerNode.nextSibling)) {
  8997. rng.setStart(caretContainerNode, 0);
  8998. rng.setEnd(caretContainerNode, 0);
  8999. } else {
  9000. rng.setStart(caretContainerNode, 1);
  9001. rng.setEnd(caretContainerNode, 1);
  9002. }
  9003. return rng;
  9004. }
  9005. return rng;
  9006. };
  9007. var hide = function () {
  9008. trimInlineCaretContainers(root);
  9009. if (caretContainerNode) {
  9010. CaretContainerRemove.remove(caretContainerNode);
  9011. caretContainerNode = null;
  9012. }
  9013. lastVisualCaret.get().each(function (caretState) {
  9014. DomQuery(caretState.caret).remove();
  9015. lastVisualCaret.set(Option.none());
  9016. });
  9017. Delay.clearInterval(cursorInterval);
  9018. };
  9019. var startBlink = function () {
  9020. cursorInterval = Delay.setInterval(function () {
  9021. if (hasFocus()) {
  9022. DomQuery('div.mce-visual-caret', root).toggleClass('mce-visual-caret-hidden');
  9023. } else {
  9024. DomQuery('div.mce-visual-caret', root).addClass('mce-visual-caret-hidden');
  9025. }
  9026. }, 500);
  9027. };
  9028. var reposition = function () {
  9029. lastVisualCaret.get().each(function (caretState) {
  9030. var clientRect = getAbsoluteClientRect(root, caretState.element, caretState.before);
  9031. DomQuery(caretState.caret).css(__assign({}, clientRect));
  9032. });
  9033. };
  9034. var destroy = function () {
  9035. return Delay.clearInterval(cursorInterval);
  9036. };
  9037. var getCss = function () {
  9038. return '.mce-visual-caret {' + 'position: absolute;' + 'background-color: black;' + 'background-color: currentcolor;' + '}' + '.mce-visual-caret-hidden {' + 'display: none;' + '}' + '*[data-mce-caret] {' + 'position: absolute;' + 'left: -1000px;' + 'right: auto;' + 'top: 0;' + 'margin: 0;' + 'padding: 0;' + '}';
  9039. };
  9040. return {
  9041. show: show,
  9042. hide: hide,
  9043. getCss: getCss,
  9044. reposition: reposition,
  9045. destroy: destroy
  9046. };
  9047. };
  9048. var isFakeCaretTableBrowser = function () {
  9049. return browser$3.isIE() || browser$3.isEdge() || browser$3.isFirefox();
  9050. };
  9051. var isFakeCaretTarget = function (node) {
  9052. return isContentEditableFalse$3(node) || NodeType.isTable(node) && isFakeCaretTableBrowser();
  9053. };
  9054. var isContentEditableFalse$4 = NodeType.isContentEditableFalse;
  9055. var isBlockLike = NodeType.matchStyleValues('display', 'block table table-cell table-caption list-item');
  9056. var isCaretContainer$2 = isCaretContainer;
  9057. var isCaretContainerBlock$1 = isCaretContainerBlock;
  9058. var isElement$5 = NodeType.isElement;
  9059. var isCaretCandidate$2 = isCaretCandidate;
  9060. var isForwards = function (direction) {
  9061. return direction > 0;
  9062. };
  9063. var isBackwards = function (direction) {
  9064. return direction < 0;
  9065. };
  9066. var skipCaretContainers = function (walk, shallow) {
  9067. var node;
  9068. while (node = walk(shallow)) {
  9069. if (!isCaretContainerBlock$1(node)) {
  9070. return node;
  9071. }
  9072. }
  9073. return null;
  9074. };
  9075. var findNode = function (node, direction, predicateFn, rootNode, shallow) {
  9076. var walker = new TreeWalker(node, rootNode);
  9077. if (isBackwards(direction)) {
  9078. if (isContentEditableFalse$4(node) || isCaretContainerBlock$1(node)) {
  9079. node = skipCaretContainers(walker.prev, true);
  9080. if (predicateFn(node)) {
  9081. return node;
  9082. }
  9083. }
  9084. while (node = skipCaretContainers(walker.prev, shallow)) {
  9085. if (predicateFn(node)) {
  9086. return node;
  9087. }
  9088. }
  9089. }
  9090. if (isForwards(direction)) {
  9091. if (isContentEditableFalse$4(node) || isCaretContainerBlock$1(node)) {
  9092. node = skipCaretContainers(walker.next, true);
  9093. if (predicateFn(node)) {
  9094. return node;
  9095. }
  9096. }
  9097. while (node = skipCaretContainers(walker.next, shallow)) {
  9098. if (predicateFn(node)) {
  9099. return node;
  9100. }
  9101. }
  9102. }
  9103. return null;
  9104. };
  9105. var getParentBlock = function (node, rootNode) {
  9106. while (node && node !== rootNode) {
  9107. if (isBlockLike(node)) {
  9108. return node;
  9109. }
  9110. node = node.parentNode;
  9111. }
  9112. return null;
  9113. };
  9114. var isInSameBlock = function (caretPosition1, caretPosition2, rootNode) {
  9115. return getParentBlock(caretPosition1.container(), rootNode) === getParentBlock(caretPosition2.container(), rootNode);
  9116. };
  9117. var getChildNodeAtRelativeOffset = function (relativeOffset, caretPosition) {
  9118. var container, offset;
  9119. if (!caretPosition) {
  9120. return null;
  9121. }
  9122. container = caretPosition.container();
  9123. offset = caretPosition.offset();
  9124. if (!isElement$5(container)) {
  9125. return null;
  9126. }
  9127. return container.childNodes[offset + relativeOffset];
  9128. };
  9129. var beforeAfter = function (before, node) {
  9130. var range = node.ownerDocument.createRange();
  9131. if (before) {
  9132. range.setStartBefore(node);
  9133. range.setEndBefore(node);
  9134. } else {
  9135. range.setStartAfter(node);
  9136. range.setEndAfter(node);
  9137. }
  9138. return range;
  9139. };
  9140. var isNodesInSameBlock = function (root, node1, node2) {
  9141. return getParentBlock(node1, root) === getParentBlock(node2, root);
  9142. };
  9143. var lean = function (left, root, node) {
  9144. var sibling, siblingName;
  9145. if (left) {
  9146. siblingName = 'previousSibling';
  9147. } else {
  9148. siblingName = 'nextSibling';
  9149. }
  9150. while (node && node !== root) {
  9151. sibling = node[siblingName];
  9152. if (isCaretContainer$2(sibling)) {
  9153. sibling = sibling[siblingName];
  9154. }
  9155. if (isContentEditableFalse$4(sibling)) {
  9156. if (isNodesInSameBlock(root, sibling, node)) {
  9157. return sibling;
  9158. }
  9159. break;
  9160. }
  9161. if (isCaretCandidate$2(sibling)) {
  9162. break;
  9163. }
  9164. node = node.parentNode;
  9165. }
  9166. return null;
  9167. };
  9168. var before$2 = curry(beforeAfter, true);
  9169. var after$1 = curry(beforeAfter, false);
  9170. var normalizeRange = function (direction, root, range) {
  9171. var node, container, offset, location;
  9172. var leanLeft = curry(lean, true, root);
  9173. var leanRight = curry(lean, false, root);
  9174. container = range.startContainer;
  9175. offset = range.startOffset;
  9176. if (isCaretContainerBlock(container)) {
  9177. if (!isElement$5(container)) {
  9178. container = container.parentNode;
  9179. }
  9180. location = container.getAttribute('data-mce-caret');
  9181. if (location === 'before') {
  9182. node = container.nextSibling;
  9183. if (isFakeCaretTarget(node)) {
  9184. return before$2(node);
  9185. }
  9186. }
  9187. if (location === 'after') {
  9188. node = container.previousSibling;
  9189. if (isFakeCaretTarget(node)) {
  9190. return after$1(node);
  9191. }
  9192. }
  9193. }
  9194. if (!range.collapsed) {
  9195. return range;
  9196. }
  9197. if (NodeType.isText(container)) {
  9198. if (isCaretContainer$2(container)) {
  9199. if (direction === 1) {
  9200. node = leanRight(container);
  9201. if (node) {
  9202. return before$2(node);
  9203. }
  9204. node = leanLeft(container);
  9205. if (node) {
  9206. return after$1(node);
  9207. }
  9208. }
  9209. if (direction === -1) {
  9210. node = leanLeft(container);
  9211. if (node) {
  9212. return after$1(node);
  9213. }
  9214. node = leanRight(container);
  9215. if (node) {
  9216. return before$2(node);
  9217. }
  9218. }
  9219. return range;
  9220. }
  9221. if (endsWithCaretContainer(container) && offset >= container.data.length - 1) {
  9222. if (direction === 1) {
  9223. node = leanRight(container);
  9224. if (node) {
  9225. return before$2(node);
  9226. }
  9227. }
  9228. return range;
  9229. }
  9230. if (startsWithCaretContainer(container) && offset <= 1) {
  9231. if (direction === -1) {
  9232. node = leanLeft(container);
  9233. if (node) {
  9234. return after$1(node);
  9235. }
  9236. }
  9237. return range;
  9238. }
  9239. if (offset === container.data.length) {
  9240. node = leanRight(container);
  9241. if (node) {
  9242. return before$2(node);
  9243. }
  9244. return range;
  9245. }
  9246. if (offset === 0) {
  9247. node = leanLeft(container);
  9248. if (node) {
  9249. return after$1(node);
  9250. }
  9251. return range;
  9252. }
  9253. }
  9254. return range;
  9255. };
  9256. var getRelativeCefElm = function (forward, caretPosition) {
  9257. return Option.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition)).filter(isContentEditableFalse$4);
  9258. };
  9259. var getNormalizedRangeEndPoint = function (direction, root, range) {
  9260. var normalizedRange = normalizeRange(direction, root, range);
  9261. if (direction === -1) {
  9262. return CaretPosition.fromRangeStart(normalizedRange);
  9263. }
  9264. return CaretPosition.fromRangeEnd(normalizedRange);
  9265. };
  9266. var getElementFromPosition = function (pos) {
  9267. return Option.from(pos.getNode()).map(Element.fromDom);
  9268. };
  9269. var getElementFromPrevPosition = function (pos) {
  9270. return Option.from(pos.getNode(true)).map(Element.fromDom);
  9271. };
  9272. var getVisualCaretPosition = function (walkFn, caretPosition) {
  9273. while (caretPosition = walkFn(caretPosition)) {
  9274. if (caretPosition.isVisible()) {
  9275. return caretPosition;
  9276. }
  9277. }
  9278. return caretPosition;
  9279. };
  9280. var isMoveInsideSameBlock = function (from, to) {
  9281. var inSameBlock = isInSameBlock(from, to);
  9282. if (!inSameBlock && NodeType.isBr(from.getNode())) {
  9283. return true;
  9284. }
  9285. return inSameBlock;
  9286. };
  9287. var HDirection;
  9288. (function (HDirection) {
  9289. HDirection[HDirection['Backwards'] = -1] = 'Backwards';
  9290. HDirection[HDirection['Forwards'] = 1] = 'Forwards';
  9291. }(HDirection || (HDirection = {})));
  9292. var isContentEditableFalse$5 = NodeType.isContentEditableFalse;
  9293. var isText$7 = NodeType.isText;
  9294. var isElement$6 = NodeType.isElement;
  9295. var isBr$4 = NodeType.isBr;
  9296. var isCaretCandidate$3 = isCaretCandidate;
  9297. var isAtomic$1 = isAtomic;
  9298. var isEditableCaretCandidate$1 = isEditableCaretCandidate;
  9299. var getParents = function (node, root) {
  9300. var parents = [];
  9301. while (node && node !== root) {
  9302. parents.push(node);
  9303. node = node.parentNode;
  9304. }
  9305. return parents;
  9306. };
  9307. var nodeAtIndex = function (container, offset) {
  9308. if (container.hasChildNodes() && offset < container.childNodes.length) {
  9309. return container.childNodes[offset];
  9310. }
  9311. return null;
  9312. };
  9313. var getCaretCandidatePosition = function (direction, node) {
  9314. if (isForwards(direction)) {
  9315. if (isCaretCandidate$3(node.previousSibling) && !isText$7(node.previousSibling)) {
  9316. return CaretPosition$1.before(node);
  9317. }
  9318. if (isText$7(node)) {
  9319. return CaretPosition$1(node, 0);
  9320. }
  9321. }
  9322. if (isBackwards(direction)) {
  9323. if (isCaretCandidate$3(node.nextSibling) && !isText$7(node.nextSibling)) {
  9324. return CaretPosition$1.after(node);
  9325. }
  9326. if (isText$7(node)) {
  9327. return CaretPosition$1(node, node.data.length);
  9328. }
  9329. }
  9330. if (isBackwards(direction)) {
  9331. if (isBr$4(node)) {
  9332. return CaretPosition$1.before(node);
  9333. }
  9334. return CaretPosition$1.after(node);
  9335. }
  9336. return CaretPosition$1.before(node);
  9337. };
  9338. var moveForwardFromBr = function (root, nextNode) {
  9339. var nextSibling = nextNode.nextSibling;
  9340. if (nextSibling && isCaretCandidate$3(nextSibling)) {
  9341. if (isText$7(nextSibling)) {
  9342. return CaretPosition$1(nextSibling, 0);
  9343. } else {
  9344. return CaretPosition$1.before(nextSibling);
  9345. }
  9346. } else {
  9347. return findCaretPosition(HDirection.Forwards, CaretPosition$1.after(nextNode), root);
  9348. }
  9349. };
  9350. var findCaretPosition = function (direction, startPos, root) {
  9351. var node, nextNode, innerNode;
  9352. var rootContentEditableFalseElm, caretPosition;
  9353. if (!isElement$6(root) || !startPos) {
  9354. return null;
  9355. }
  9356. if (startPos.isEqual(CaretPosition$1.after(root)) && root.lastChild) {
  9357. caretPosition = CaretPosition$1.after(root.lastChild);
  9358. if (isBackwards(direction) && isCaretCandidate$3(root.lastChild) && isElement$6(root.lastChild)) {
  9359. return isBr$4(root.lastChild) ? CaretPosition$1.before(root.lastChild) : caretPosition;
  9360. }
  9361. } else {
  9362. caretPosition = startPos;
  9363. }
  9364. var container = caretPosition.container();
  9365. var offset = caretPosition.offset();
  9366. if (isText$7(container)) {
  9367. if (isBackwards(direction) && offset > 0) {
  9368. return CaretPosition$1(container, --offset);
  9369. }
  9370. if (isForwards(direction) && offset < container.length) {
  9371. return CaretPosition$1(container, ++offset);
  9372. }
  9373. node = container;
  9374. } else {
  9375. if (isBackwards(direction) && offset > 0) {
  9376. nextNode = nodeAtIndex(container, offset - 1);
  9377. if (isCaretCandidate$3(nextNode)) {
  9378. if (!isAtomic$1(nextNode)) {
  9379. innerNode = findNode(nextNode, direction, isEditableCaretCandidate$1, nextNode);
  9380. if (innerNode) {
  9381. if (isText$7(innerNode)) {
  9382. return CaretPosition$1(innerNode, innerNode.data.length);
  9383. }
  9384. return CaretPosition$1.after(innerNode);
  9385. }
  9386. }
  9387. if (isText$7(nextNode)) {
  9388. return CaretPosition$1(nextNode, nextNode.data.length);
  9389. }
  9390. return CaretPosition$1.before(nextNode);
  9391. }
  9392. }
  9393. if (isForwards(direction) && offset < container.childNodes.length) {
  9394. nextNode = nodeAtIndex(container, offset);
  9395. if (isCaretCandidate$3(nextNode)) {
  9396. if (isBr$4(nextNode)) {
  9397. return moveForwardFromBr(root, nextNode);
  9398. }
  9399. if (!isAtomic$1(nextNode)) {
  9400. innerNode = findNode(nextNode, direction, isEditableCaretCandidate$1, nextNode);
  9401. if (innerNode) {
  9402. if (isText$7(innerNode)) {
  9403. return CaretPosition$1(innerNode, 0);
  9404. }
  9405. return CaretPosition$1.before(innerNode);
  9406. }
  9407. }
  9408. if (isText$7(nextNode)) {
  9409. return CaretPosition$1(nextNode, 0);
  9410. }
  9411. return CaretPosition$1.after(nextNode);
  9412. }
  9413. }
  9414. node = nextNode ? nextNode : caretPosition.getNode();
  9415. }
  9416. if (isForwards(direction) && caretPosition.isAtEnd() || isBackwards(direction) && caretPosition.isAtStart()) {
  9417. node = findNode(node, direction, constant(true), root, true);
  9418. if (isEditableCaretCandidate$1(node, root)) {
  9419. return getCaretCandidatePosition(direction, node);
  9420. }
  9421. }
  9422. nextNode = findNode(node, direction, isEditableCaretCandidate$1, root);
  9423. rootContentEditableFalseElm = ArrUtils.last(filter(getParents(container, root), isContentEditableFalse$5));
  9424. if (rootContentEditableFalseElm && (!nextNode || !rootContentEditableFalseElm.contains(nextNode))) {
  9425. if (isForwards(direction)) {
  9426. caretPosition = CaretPosition$1.after(rootContentEditableFalseElm);
  9427. } else {
  9428. caretPosition = CaretPosition$1.before(rootContentEditableFalseElm);
  9429. }
  9430. return caretPosition;
  9431. }
  9432. if (nextNode) {
  9433. return getCaretCandidatePosition(direction, nextNode);
  9434. }
  9435. return null;
  9436. };
  9437. var CaretWalker = function (root) {
  9438. return {
  9439. next: function (caretPosition) {
  9440. return findCaretPosition(HDirection.Forwards, caretPosition, root);
  9441. },
  9442. prev: function (caretPosition) {
  9443. return findCaretPosition(HDirection.Backwards, caretPosition, root);
  9444. }
  9445. };
  9446. };
  9447. var walkToPositionIn = function (forward, root, start) {
  9448. var position = forward ? CaretPosition$1.before(start) : CaretPosition$1.after(start);
  9449. return fromPosition(forward, root, position);
  9450. };
  9451. var afterElement = function (node) {
  9452. return NodeType.isBr(node) ? CaretPosition$1.before(node) : CaretPosition$1.after(node);
  9453. };
  9454. var isBeforeOrStart = function (position) {
  9455. if (CaretPosition$1.isTextPosition(position)) {
  9456. return position.offset() === 0;
  9457. } else {
  9458. return isCaretCandidate(position.getNode());
  9459. }
  9460. };
  9461. var isAfterOrEnd = function (position) {
  9462. if (CaretPosition$1.isTextPosition(position)) {
  9463. var container = position.container();
  9464. return position.offset() === container.data.length;
  9465. } else {
  9466. return isCaretCandidate(position.getNode(true));
  9467. }
  9468. };
  9469. var isBeforeAfterSameElement = function (from, to) {
  9470. return !CaretPosition$1.isTextPosition(from) && !CaretPosition$1.isTextPosition(to) && from.getNode() === to.getNode(true);
  9471. };
  9472. var isAtBr = function (position) {
  9473. return !CaretPosition$1.isTextPosition(position) && NodeType.isBr(position.getNode());
  9474. };
  9475. var shouldSkipPosition = function (forward, from, to) {
  9476. if (forward) {
  9477. return !isBeforeAfterSameElement(from, to) && !isAtBr(from) && isAfterOrEnd(from) && isBeforeOrStart(to);
  9478. } else {
  9479. return !isBeforeAfterSameElement(to, from) && isBeforeOrStart(from) && isAfterOrEnd(to);
  9480. }
  9481. };
  9482. var fromPosition = function (forward, root, pos) {
  9483. var walker = CaretWalker(root);
  9484. return Option.from(forward ? walker.next(pos) : walker.prev(pos));
  9485. };
  9486. var navigate = function (forward, root, from) {
  9487. return fromPosition(forward, root, from).bind(function (to) {
  9488. if (isInSameBlock(from, to, root) && shouldSkipPosition(forward, from, to)) {
  9489. return fromPosition(forward, root, to);
  9490. } else {
  9491. return Option.some(to);
  9492. }
  9493. });
  9494. };
  9495. var navigateIgnore = function (forward, root, from, ignoreFilter) {
  9496. return navigate(forward, root, from).bind(function (pos) {
  9497. return ignoreFilter(pos) ? navigateIgnore(forward, root, pos, ignoreFilter) : Option.some(pos);
  9498. });
  9499. };
  9500. var positionIn = function (forward, element) {
  9501. var startNode = forward ? element.firstChild : element.lastChild;
  9502. if (NodeType.isText(startNode)) {
  9503. return Option.some(CaretPosition$1(startNode, forward ? 0 : startNode.data.length));
  9504. } else if (startNode) {
  9505. if (isCaretCandidate(startNode)) {
  9506. return Option.some(forward ? CaretPosition$1.before(startNode) : afterElement(startNode));
  9507. } else {
  9508. return walkToPositionIn(forward, element, startNode);
  9509. }
  9510. } else {
  9511. return Option.none();
  9512. }
  9513. };
  9514. var nextPosition = curry(fromPosition, true);
  9515. var prevPosition = curry(fromPosition, false);
  9516. var CaretFinder = {
  9517. fromPosition: fromPosition,
  9518. nextPosition: nextPosition,
  9519. prevPosition: prevPosition,
  9520. navigate: navigate,
  9521. navigateIgnore: navigateIgnore,
  9522. positionIn: positionIn,
  9523. firstPositionIn: curry(positionIn, true),
  9524. lastPositionIn: curry(positionIn, false)
  9525. };
  9526. var isStringPathBookmark = function (bookmark) {
  9527. return typeof bookmark.start === 'string';
  9528. };
  9529. var isRangeBookmark = function (bookmark) {
  9530. return bookmark.hasOwnProperty('rng');
  9531. };
  9532. var isIdBookmark = function (bookmark) {
  9533. return bookmark.hasOwnProperty('id');
  9534. };
  9535. var isIndexBookmark = function (bookmark) {
  9536. return bookmark.hasOwnProperty('name');
  9537. };
  9538. var isPathBookmark = function (bookmark) {
  9539. return Tools.isArray(bookmark.start);
  9540. };
  9541. var addBogus = function (dom, node) {
  9542. if (NodeType.isElement(node) && dom.isBlock(node) && !node.innerHTML && !Env.ie) {
  9543. node.innerHTML = '<br data-mce-bogus="1" />';
  9544. }
  9545. return node;
  9546. };
  9547. var resolveCaretPositionBookmark = function (dom, bookmark) {
  9548. var rng, pos;
  9549. rng = dom.createRng();
  9550. pos = resolve$1(dom.getRoot(), bookmark.start);
  9551. rng.setStart(pos.container(), pos.offset());
  9552. pos = resolve$1(dom.getRoot(), bookmark.end);
  9553. rng.setEnd(pos.container(), pos.offset());
  9554. return rng;
  9555. };
  9556. var insertZwsp = function (node, rng) {
  9557. var textNode = node.ownerDocument.createTextNode(Zwsp.ZWSP);
  9558. node.appendChild(textNode);
  9559. rng.setStart(textNode, 0);
  9560. rng.setEnd(textNode, 0);
  9561. };
  9562. var isEmpty = function (node) {
  9563. return node.hasChildNodes() === false;
  9564. };
  9565. var tryFindRangePosition = function (node, rng) {
  9566. return CaretFinder.lastPositionIn(node).fold(function () {
  9567. return false;
  9568. }, function (pos) {
  9569. rng.setStart(pos.container(), pos.offset());
  9570. rng.setEnd(pos.container(), pos.offset());
  9571. return true;
  9572. });
  9573. };
  9574. var padEmptyCaretContainer = function (root, node, rng) {
  9575. if (isEmpty(node) && getParentCaretContainer(root, node)) {
  9576. insertZwsp(node, rng);
  9577. return true;
  9578. } else {
  9579. return false;
  9580. }
  9581. };
  9582. var setEndPoint = function (dom, start, bookmark, rng) {
  9583. var point = bookmark[start ? 'start' : 'end'];
  9584. var i, node, offset, children;
  9585. var root = dom.getRoot();
  9586. if (point) {
  9587. offset = point[0];
  9588. for (node = root, i = point.length - 1; i >= 1; i--) {
  9589. children = node.childNodes;
  9590. if (padEmptyCaretContainer(root, node, rng)) {
  9591. return true;
  9592. }
  9593. if (point[i] > children.length - 1) {
  9594. if (padEmptyCaretContainer(root, node, rng)) {
  9595. return true;
  9596. }
  9597. return tryFindRangePosition(node, rng);
  9598. }
  9599. node = children[point[i]];
  9600. }
  9601. if (node.nodeType === 3) {
  9602. offset = Math.min(point[0], node.nodeValue.length);
  9603. }
  9604. if (node.nodeType === 1) {
  9605. offset = Math.min(point[0], node.childNodes.length);
  9606. }
  9607. if (start) {
  9608. rng.setStart(node, offset);
  9609. } else {
  9610. rng.setEnd(node, offset);
  9611. }
  9612. }
  9613. return true;
  9614. };
  9615. var isValidTextNode = function (node) {
  9616. return NodeType.isText(node) && node.data.length > 0;
  9617. };
  9618. var restoreEndPoint = function (dom, suffix, bookmark) {
  9619. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev;
  9620. var keep = bookmark.keep;
  9621. var container, offset;
  9622. if (marker) {
  9623. node = marker.parentNode;
  9624. if (suffix === 'start') {
  9625. if (!keep) {
  9626. idx = dom.nodeIndex(marker);
  9627. } else {
  9628. if (marker.hasChildNodes()) {
  9629. node = marker.firstChild;
  9630. idx = 1;
  9631. } else if (isValidTextNode(marker.nextSibling)) {
  9632. node = marker.nextSibling;
  9633. idx = 0;
  9634. } else if (isValidTextNode(marker.previousSibling)) {
  9635. node = marker.previousSibling;
  9636. idx = marker.previousSibling.data.length;
  9637. } else {
  9638. node = marker.parentNode;
  9639. idx = dom.nodeIndex(marker) + 1;
  9640. }
  9641. }
  9642. container = node;
  9643. offset = idx;
  9644. } else {
  9645. if (!keep) {
  9646. idx = dom.nodeIndex(marker);
  9647. } else {
  9648. if (marker.hasChildNodes()) {
  9649. node = marker.firstChild;
  9650. idx = 1;
  9651. } else if (isValidTextNode(marker.previousSibling)) {
  9652. node = marker.previousSibling;
  9653. idx = marker.previousSibling.data.length;
  9654. } else {
  9655. node = marker.parentNode;
  9656. idx = dom.nodeIndex(marker);
  9657. }
  9658. }
  9659. container = node;
  9660. offset = idx;
  9661. }
  9662. if (!keep) {
  9663. prev = marker.previousSibling;
  9664. next = marker.nextSibling;
  9665. Tools.each(Tools.grep(marker.childNodes), function (node) {
  9666. if (NodeType.isText(node)) {
  9667. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  9668. }
  9669. });
  9670. while (marker = dom.get(bookmark.id + '_' + suffix)) {
  9671. dom.remove(marker, true);
  9672. }
  9673. if (prev && next && prev.nodeType === next.nodeType && NodeType.isText(prev) && !Env.opera) {
  9674. idx = prev.nodeValue.length;
  9675. prev.appendData(next.nodeValue);
  9676. dom.remove(next);
  9677. if (suffix === 'start') {
  9678. container = prev;
  9679. offset = idx;
  9680. } else {
  9681. container = prev;
  9682. offset = idx;
  9683. }
  9684. }
  9685. }
  9686. return Option.some(CaretPosition$1(container, offset));
  9687. } else {
  9688. return Option.none();
  9689. }
  9690. };
  9691. var resolvePaths = function (dom, bookmark) {
  9692. var rng = dom.createRng();
  9693. if (setEndPoint(dom, true, bookmark, rng) && setEndPoint(dom, false, bookmark, rng)) {
  9694. return Option.some(rng);
  9695. } else {
  9696. return Option.none();
  9697. }
  9698. };
  9699. var resolveId = function (dom, bookmark) {
  9700. var startPos = restoreEndPoint(dom, 'start', bookmark);
  9701. var endPos = restoreEndPoint(dom, 'end', bookmark);
  9702. return lift2(startPos, endPos.or(startPos), function (spos, epos) {
  9703. var rng = dom.createRng();
  9704. rng.setStart(addBogus(dom, spos.container()), spos.offset());
  9705. rng.setEnd(addBogus(dom, epos.container()), epos.offset());
  9706. return rng;
  9707. });
  9708. };
  9709. var resolveIndex$1 = function (dom, bookmark) {
  9710. return Option.from(dom.select(bookmark.name)[bookmark.index]).map(function (elm) {
  9711. var rng = dom.createRng();
  9712. rng.selectNode(elm);
  9713. return rng;
  9714. });
  9715. };
  9716. var resolve$2 = function (selection, bookmark) {
  9717. var dom = selection.dom;
  9718. if (bookmark) {
  9719. if (isPathBookmark(bookmark)) {
  9720. return resolvePaths(dom, bookmark);
  9721. } else if (isStringPathBookmark(bookmark)) {
  9722. return Option.some(resolveCaretPositionBookmark(dom, bookmark));
  9723. } else if (isIdBookmark(bookmark)) {
  9724. return resolveId(dom, bookmark);
  9725. } else if (isIndexBookmark(bookmark)) {
  9726. return resolveIndex$1(dom, bookmark);
  9727. } else if (isRangeBookmark(bookmark)) {
  9728. return Option.some(bookmark.rng);
  9729. }
  9730. }
  9731. return Option.none();
  9732. };
  9733. var ResolveBookmark = { resolve: resolve$2 };
  9734. var getBookmark$1 = function (selection, type, normalized) {
  9735. return GetBookmark.getBookmark(selection, type, normalized);
  9736. };
  9737. var moveToBookmark = function (selection, bookmark) {
  9738. ResolveBookmark.resolve(selection, bookmark).each(function (rng) {
  9739. selection.setRng(rng);
  9740. });
  9741. };
  9742. var isBookmarkNode$1 = function (node) {
  9743. return NodeType.isElement(node) && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark';
  9744. };
  9745. var Bookmarks = {
  9746. getBookmark: getBookmark$1,
  9747. moveToBookmark: moveToBookmark,
  9748. isBookmarkNode: isBookmarkNode$1
  9749. };
  9750. var isInlineBlock = function (node) {
  9751. return node && /^(IMG)$/.test(node.nodeName);
  9752. };
  9753. var moveStart = function (dom, selection, rng) {
  9754. var offset = rng.startOffset;
  9755. var container = rng.startContainer, walker, node, nodes;
  9756. if (rng.startContainer === rng.endContainer) {
  9757. if (isInlineBlock(rng.startContainer.childNodes[rng.startOffset])) {
  9758. return;
  9759. }
  9760. }
  9761. if (container.nodeType === 1) {
  9762. nodes = container.childNodes;
  9763. if (offset < nodes.length) {
  9764. container = nodes[offset];
  9765. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  9766. } else {
  9767. container = nodes[nodes.length - 1];
  9768. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  9769. walker.next(true);
  9770. }
  9771. for (node = walker.current(); node; node = walker.next()) {
  9772. if (node.nodeType === 3 && !isWhiteSpaceNode(node)) {
  9773. rng.setStart(node, 0);
  9774. selection.setRng(rng);
  9775. return;
  9776. }
  9777. }
  9778. }
  9779. };
  9780. var getNonWhiteSpaceSibling = function (node, next, inc) {
  9781. if (node) {
  9782. next = next ? 'nextSibling' : 'previousSibling';
  9783. for (node = inc ? node : node[next]; node; node = node[next]) {
  9784. if (node.nodeType === 1 || !isWhiteSpaceNode(node)) {
  9785. return node;
  9786. }
  9787. }
  9788. }
  9789. };
  9790. var isTextBlock$1 = function (editor, name) {
  9791. if (name.nodeType) {
  9792. name = name.nodeName;
  9793. }
  9794. return !!editor.schema.getTextBlockElements()[name.toLowerCase()];
  9795. };
  9796. var isValid = function (ed, parent, child) {
  9797. return ed.schema.isValidChild(parent, child);
  9798. };
  9799. var isWhiteSpaceNode = function (node) {
  9800. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  9801. };
  9802. var replaceVars = function (value, vars) {
  9803. if (typeof value !== 'string') {
  9804. value = value(vars);
  9805. } else if (vars) {
  9806. value = value.replace(/%(\w+)/g, function (str, name) {
  9807. return vars[name] || str;
  9808. });
  9809. }
  9810. return value;
  9811. };
  9812. var isEq = function (str1, str2) {
  9813. str1 = str1 || '';
  9814. str2 = str2 || '';
  9815. str1 = '' + (str1.nodeName || str1);
  9816. str2 = '' + (str2.nodeName || str2);
  9817. return str1.toLowerCase() === str2.toLowerCase();
  9818. };
  9819. var normalizeStyleValue = function (dom, value, name) {
  9820. if (name === 'color' || name === 'backgroundColor') {
  9821. value = dom.toHex(value);
  9822. }
  9823. if (name === 'fontWeight' && value === 700) {
  9824. value = 'bold';
  9825. }
  9826. if (name === 'fontFamily') {
  9827. value = value.replace(/[\'\"]/g, '').replace(/,\s+/g, ',');
  9828. }
  9829. return '' + value;
  9830. };
  9831. var getStyle = function (dom, node, name) {
  9832. return normalizeStyleValue(dom, dom.getStyle(node, name), name);
  9833. };
  9834. var getTextDecoration = function (dom, node) {
  9835. var decoration;
  9836. dom.getParent(node, function (n) {
  9837. decoration = dom.getStyle(n, 'text-decoration');
  9838. return decoration && decoration !== 'none';
  9839. });
  9840. return decoration;
  9841. };
  9842. var getParents$1 = function (dom, node, selector) {
  9843. return dom.getParents(node, selector, dom.getRoot());
  9844. };
  9845. var FormatUtils = {
  9846. isInlineBlock: isInlineBlock,
  9847. moveStart: moveStart,
  9848. getNonWhiteSpaceSibling: getNonWhiteSpaceSibling,
  9849. isTextBlock: isTextBlock$1,
  9850. isValid: isValid,
  9851. isWhiteSpaceNode: isWhiteSpaceNode,
  9852. replaceVars: replaceVars,
  9853. isEq: isEq,
  9854. normalizeStyleValue: normalizeStyleValue,
  9855. getStyle: getStyle,
  9856. getTextDecoration: getTextDecoration,
  9857. getParents: getParents$1
  9858. };
  9859. var isBookmarkNode$2 = Bookmarks.isBookmarkNode;
  9860. var getParents$2 = FormatUtils.getParents, isWhiteSpaceNode$1 = FormatUtils.isWhiteSpaceNode, isTextBlock$2 = FormatUtils.isTextBlock;
  9861. var findLeaf = function (node, offset) {
  9862. if (typeof offset === 'undefined') {
  9863. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  9864. }
  9865. while (node && node.hasChildNodes()) {
  9866. node = node.childNodes[offset];
  9867. if (node) {
  9868. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  9869. }
  9870. }
  9871. return {
  9872. node: node,
  9873. offset: offset
  9874. };
  9875. };
  9876. var excludeTrailingWhitespace = function (endContainer, endOffset) {
  9877. var leaf = findLeaf(endContainer, endOffset);
  9878. if (leaf.node) {
  9879. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling) {
  9880. leaf = findLeaf(leaf.node.previousSibling);
  9881. }
  9882. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 && leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  9883. if (leaf.offset > 1) {
  9884. endContainer = leaf.node;
  9885. endContainer.splitText(leaf.offset - 1);
  9886. }
  9887. }
  9888. }
  9889. return endContainer;
  9890. };
  9891. var isBogusBr = function (node) {
  9892. return node.nodeName === 'BR' && node.getAttribute('data-mce-bogus') && !node.nextSibling;
  9893. };
  9894. var findParentContentEditable = function (dom, node) {
  9895. var parent = node;
  9896. while (parent) {
  9897. if (parent.nodeType === 1 && dom.getContentEditable(parent)) {
  9898. return dom.getContentEditable(parent) === 'false' ? parent : node;
  9899. }
  9900. parent = parent.parentNode;
  9901. }
  9902. return node;
  9903. };
  9904. var findSpace = function (start, remove, node, offset) {
  9905. var pos, pos2;
  9906. var str = node.nodeValue;
  9907. if (typeof offset === 'undefined') {
  9908. offset = start ? str.length : 0;
  9909. }
  9910. if (start) {
  9911. pos = str.lastIndexOf(' ', offset);
  9912. pos2 = str.lastIndexOf('\xA0', offset);
  9913. pos = pos > pos2 ? pos : pos2;
  9914. if (pos !== -1 && !remove && (pos < offset || !start) && pos <= str.length) {
  9915. pos++;
  9916. }
  9917. } else {
  9918. pos = str.indexOf(' ', offset);
  9919. pos2 = str.indexOf('\xA0', offset);
  9920. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  9921. }
  9922. return pos;
  9923. };
  9924. var findWordEndPoint = function (dom, body, container, offset, start, remove) {
  9925. var node, pos, lastTextNode;
  9926. if (container.nodeType === 3) {
  9927. pos = findSpace(start, remove, container, offset);
  9928. if (pos !== -1) {
  9929. return {
  9930. container: container,
  9931. offset: pos
  9932. };
  9933. }
  9934. lastTextNode = container;
  9935. }
  9936. var walker = new TreeWalker(container, dom.getParent(container, dom.isBlock) || body);
  9937. while (node = walker[start ? 'prev' : 'next']()) {
  9938. if (node.nodeType === 3 && !isBookmarkNode$2(node.parentNode)) {
  9939. lastTextNode = node;
  9940. pos = findSpace(start, remove, node);
  9941. if (pos !== -1) {
  9942. return {
  9943. container: node,
  9944. offset: pos
  9945. };
  9946. }
  9947. } else if (dom.isBlock(node) || FormatUtils.isEq(node, 'BR')) {
  9948. break;
  9949. }
  9950. }
  9951. if (lastTextNode) {
  9952. if (start) {
  9953. offset = 0;
  9954. } else {
  9955. offset = lastTextNode.length;
  9956. }
  9957. return {
  9958. container: lastTextNode,
  9959. offset: offset
  9960. };
  9961. }
  9962. };
  9963. var findSelectorEndPoint = function (dom, format, rng, container, siblingName) {
  9964. var parents, i, y, curFormat;
  9965. if (container.nodeType === 3 && container.nodeValue.length === 0 && container[siblingName]) {
  9966. container = container[siblingName];
  9967. }
  9968. parents = getParents$2(dom, container);
  9969. for (i = 0; i < parents.length; i++) {
  9970. for (y = 0; y < format.length; y++) {
  9971. curFormat = format[y];
  9972. if ('collapsed' in curFormat && curFormat.collapsed !== rng.collapsed) {
  9973. continue;
  9974. }
  9975. if (dom.is(parents[i], curFormat.selector)) {
  9976. return parents[i];
  9977. }
  9978. }
  9979. }
  9980. return container;
  9981. };
  9982. var findBlockEndPoint = function (editor, format, container, siblingName) {
  9983. var node;
  9984. var dom = editor.dom;
  9985. var root = dom.getRoot();
  9986. if (!format[0].wrapper) {
  9987. node = dom.getParent(container, format[0].block, root);
  9988. }
  9989. if (!node) {
  9990. var scopeRoot = dom.getParent(container, 'LI,TD,TH');
  9991. node = dom.getParent(container.nodeType === 3 ? container.parentNode : container, function (node) {
  9992. return node !== root && isTextBlock$2(editor, node);
  9993. }, scopeRoot);
  9994. }
  9995. if (node && format[0].wrapper) {
  9996. node = getParents$2(dom, node, 'ul,ol').reverse()[0] || node;
  9997. }
  9998. if (!node) {
  9999. node = container;
  10000. while (node[siblingName] && !dom.isBlock(node[siblingName])) {
  10001. node = node[siblingName];
  10002. if (FormatUtils.isEq(node, 'br')) {
  10003. break;
  10004. }
  10005. }
  10006. }
  10007. return node || container;
  10008. };
  10009. var findParentContainer = function (dom, format, startContainer, startOffset, endContainer, endOffset, start) {
  10010. var container, parent, sibling, siblingName, root;
  10011. container = parent = start ? startContainer : endContainer;
  10012. siblingName = start ? 'previousSibling' : 'nextSibling';
  10013. root = dom.getRoot();
  10014. if (container.nodeType === 3 && !isWhiteSpaceNode$1(container)) {
  10015. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  10016. return container;
  10017. }
  10018. }
  10019. while (true) {
  10020. if (!format[0].block_expand && dom.isBlock(parent)) {
  10021. return parent;
  10022. }
  10023. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  10024. if (!isBookmarkNode$2(sibling) && !isWhiteSpaceNode$1(sibling) && !isBogusBr(sibling)) {
  10025. return parent;
  10026. }
  10027. }
  10028. if (parent === root || parent.parentNode === root) {
  10029. container = parent;
  10030. break;
  10031. }
  10032. parent = parent.parentNode;
  10033. }
  10034. return container;
  10035. };
  10036. var expandRng = function (editor, rng, format, remove) {
  10037. var endPoint, startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
  10038. var dom = editor.dom;
  10039. if (startContainer.nodeType === 1 && startContainer.hasChildNodes()) {
  10040. startContainer = getNode(startContainer, startOffset);
  10041. if (startContainer.nodeType === 3) {
  10042. startOffset = 0;
  10043. }
  10044. }
  10045. if (endContainer.nodeType === 1 && endContainer.hasChildNodes()) {
  10046. endContainer = getNode(endContainer, rng.collapsed ? endOffset : endOffset - 1);
  10047. if (endContainer.nodeType === 3) {
  10048. endOffset = endContainer.nodeValue.length;
  10049. }
  10050. }
  10051. startContainer = findParentContentEditable(dom, startContainer);
  10052. endContainer = findParentContentEditable(dom, endContainer);
  10053. if (isBookmarkNode$2(startContainer.parentNode) || isBookmarkNode$2(startContainer)) {
  10054. startContainer = isBookmarkNode$2(startContainer) ? startContainer : startContainer.parentNode;
  10055. if (rng.collapsed) {
  10056. startContainer = startContainer.previousSibling || startContainer;
  10057. } else {
  10058. startContainer = startContainer.nextSibling || startContainer;
  10059. }
  10060. if (startContainer.nodeType === 3) {
  10061. startOffset = rng.collapsed ? startContainer.length : 0;
  10062. }
  10063. }
  10064. if (isBookmarkNode$2(endContainer.parentNode) || isBookmarkNode$2(endContainer)) {
  10065. endContainer = isBookmarkNode$2(endContainer) ? endContainer : endContainer.parentNode;
  10066. if (rng.collapsed) {
  10067. endContainer = endContainer.nextSibling || endContainer;
  10068. } else {
  10069. endContainer = endContainer.previousSibling || endContainer;
  10070. }
  10071. if (endContainer.nodeType === 3) {
  10072. endOffset = rng.collapsed ? 0 : endContainer.length;
  10073. }
  10074. }
  10075. if (rng.collapsed) {
  10076. endPoint = findWordEndPoint(dom, editor.getBody(), startContainer, startOffset, true, remove);
  10077. if (endPoint) {
  10078. startContainer = endPoint.container;
  10079. startOffset = endPoint.offset;
  10080. }
  10081. endPoint = findWordEndPoint(dom, editor.getBody(), endContainer, endOffset, false, remove);
  10082. if (endPoint) {
  10083. endContainer = endPoint.container;
  10084. endOffset = endPoint.offset;
  10085. }
  10086. }
  10087. if (format[0].inline) {
  10088. endContainer = remove ? endContainer : excludeTrailingWhitespace(endContainer, endOffset);
  10089. }
  10090. if (format[0].inline || format[0].block_expand) {
  10091. if (!format[0].inline || (startContainer.nodeType !== 3 || startOffset === 0)) {
  10092. startContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, true);
  10093. }
  10094. if (!format[0].inline || (endContainer.nodeType !== 3 || endOffset === endContainer.nodeValue.length)) {
  10095. endContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, false);
  10096. }
  10097. }
  10098. if (format[0].selector && format[0].expand !== false && !format[0].inline) {
  10099. startContainer = findSelectorEndPoint(dom, format, rng, startContainer, 'previousSibling');
  10100. endContainer = findSelectorEndPoint(dom, format, rng, endContainer, 'nextSibling');
  10101. }
  10102. if (format[0].block || format[0].selector) {
  10103. startContainer = findBlockEndPoint(editor, format, startContainer, 'previousSibling');
  10104. endContainer = findBlockEndPoint(editor, format, endContainer, 'nextSibling');
  10105. if (format[0].block) {
  10106. if (!dom.isBlock(startContainer)) {
  10107. startContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, true);
  10108. }
  10109. if (!dom.isBlock(endContainer)) {
  10110. endContainer = findParentContainer(dom, format, startContainer, startOffset, endContainer, endOffset, false);
  10111. }
  10112. }
  10113. }
  10114. if (startContainer.nodeType === 1) {
  10115. startOffset = dom.nodeIndex(startContainer);
  10116. startContainer = startContainer.parentNode;
  10117. }
  10118. if (endContainer.nodeType === 1) {
  10119. endOffset = dom.nodeIndex(endContainer) + 1;
  10120. endContainer = endContainer.parentNode;
  10121. }
  10122. return {
  10123. startContainer: startContainer,
  10124. startOffset: startOffset,
  10125. endContainer: endContainer,
  10126. endOffset: endOffset
  10127. };
  10128. };
  10129. var ExpandRange = { expandRng: expandRng };
  10130. var each$8 = Tools.each;
  10131. var getEndChild = function (container, index) {
  10132. var childNodes = container.childNodes;
  10133. index--;
  10134. if (index > childNodes.length - 1) {
  10135. index = childNodes.length - 1;
  10136. } else if (index < 0) {
  10137. index = 0;
  10138. }
  10139. return childNodes[index] || container;
  10140. };
  10141. var walk$1 = function (dom, rng, callback) {
  10142. var startContainer = rng.startContainer;
  10143. var startOffset = rng.startOffset;
  10144. var endContainer = rng.endContainer;
  10145. var endOffset = rng.endOffset;
  10146. var ancestor;
  10147. var startPoint;
  10148. var endPoint;
  10149. var node;
  10150. var parent;
  10151. var siblings;
  10152. var nodes;
  10153. nodes = dom.select('td[data-mce-selected],th[data-mce-selected]');
  10154. if (nodes.length > 0) {
  10155. each$8(nodes, function (node) {
  10156. callback([node]);
  10157. });
  10158. return;
  10159. }
  10160. var exclude = function (nodes) {
  10161. var node;
  10162. node = nodes[0];
  10163. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  10164. nodes.splice(0, 1);
  10165. }
  10166. node = nodes[nodes.length - 1];
  10167. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  10168. nodes.splice(nodes.length - 1, 1);
  10169. }
  10170. return nodes;
  10171. };
  10172. var collectSiblings = function (node, name, endNode) {
  10173. var siblings = [];
  10174. for (; node && node !== endNode; node = node[name]) {
  10175. siblings.push(node);
  10176. }
  10177. return siblings;
  10178. };
  10179. var findEndPoint = function (node, root) {
  10180. do {
  10181. if (node.parentNode === root) {
  10182. return node;
  10183. }
  10184. node = node.parentNode;
  10185. } while (node);
  10186. };
  10187. var walkBoundary = function (startNode, endNode, next) {
  10188. var siblingName = next ? 'nextSibling' : 'previousSibling';
  10189. for (node = startNode, parent = node.parentNode; node && node !== endNode; node = parent) {
  10190. parent = node.parentNode;
  10191. siblings = collectSiblings(node === startNode ? node : node[siblingName], siblingName);
  10192. if (siblings.length) {
  10193. if (!next) {
  10194. siblings.reverse();
  10195. }
  10196. callback(exclude(siblings));
  10197. }
  10198. }
  10199. };
  10200. if (startContainer.nodeType === 1 && startContainer.hasChildNodes()) {
  10201. startContainer = startContainer.childNodes[startOffset];
  10202. }
  10203. if (endContainer.nodeType === 1 && endContainer.hasChildNodes()) {
  10204. endContainer = getEndChild(endContainer, endOffset);
  10205. }
  10206. if (startContainer === endContainer) {
  10207. return callback(exclude([startContainer]));
  10208. }
  10209. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  10210. for (node = startContainer; node; node = node.parentNode) {
  10211. if (node === endContainer) {
  10212. return walkBoundary(startContainer, ancestor, true);
  10213. }
  10214. if (node === ancestor) {
  10215. break;
  10216. }
  10217. }
  10218. for (node = endContainer; node; node = node.parentNode) {
  10219. if (node === startContainer) {
  10220. return walkBoundary(endContainer, ancestor);
  10221. }
  10222. if (node === ancestor) {
  10223. break;
  10224. }
  10225. }
  10226. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  10227. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  10228. walkBoundary(startContainer, startPoint, true);
  10229. siblings = collectSiblings(startPoint === startContainer ? startPoint : startPoint.nextSibling, 'nextSibling', endPoint === endContainer ? endPoint.nextSibling : endPoint);
  10230. if (siblings.length) {
  10231. callback(exclude(siblings));
  10232. }
  10233. walkBoundary(endContainer, endPoint);
  10234. };
  10235. var RangeWalk = { walk: walk$1 };
  10236. var zeroWidth = function () {
  10237. return '\uFEFF';
  10238. };
  10239. function NodeValue (is, name) {
  10240. var get = function (element) {
  10241. if (!is(element)) {
  10242. throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
  10243. }
  10244. return getOption(element).getOr('');
  10245. };
  10246. var getOption = function (element) {
  10247. return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
  10248. };
  10249. var set = function (element, value) {
  10250. if (!is(element)) {
  10251. throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
  10252. }
  10253. element.dom().nodeValue = value;
  10254. };
  10255. return {
  10256. get: get,
  10257. getOption: getOption,
  10258. set: set
  10259. };
  10260. }
  10261. var api = NodeValue(isText$1, 'text');
  10262. var get$6 = function (element) {
  10263. return api.get(element);
  10264. };
  10265. var isZeroWidth = function (elem) {
  10266. return isText$1(elem) && get$6(elem) === zeroWidth();
  10267. };
  10268. var context = function (editor, elem, wrapName, nodeName) {
  10269. return parent(elem).fold(function () {
  10270. return 'skipping';
  10271. }, function (parent) {
  10272. if (nodeName === 'br' || isZeroWidth(elem)) {
  10273. return 'valid';
  10274. } else if (isAnnotation(elem)) {
  10275. return 'existing';
  10276. } else if (isCaretNode(elem)) {
  10277. return 'caret';
  10278. } else if (!FormatUtils.isValid(editor, wrapName, nodeName) || !FormatUtils.isValid(editor, name(parent), wrapName)) {
  10279. return 'invalid-child';
  10280. } else {
  10281. return 'valid';
  10282. }
  10283. });
  10284. };
  10285. var shouldApplyToTrailingSpaces = function (rng) {
  10286. return rng.startContainer.nodeType === 3 && rng.startContainer.nodeValue.length >= rng.startOffset && rng.startContainer.nodeValue[rng.startOffset] === '\xA0';
  10287. };
  10288. var applyWordGrab = function (editor, rng) {
  10289. var r = ExpandRange.expandRng(editor, rng, [{ inline: true }], shouldApplyToTrailingSpaces(rng));
  10290. rng.setStart(r.startContainer, r.startOffset);
  10291. rng.setEnd(r.endContainer, r.endOffset);
  10292. editor.selection.setRng(rng);
  10293. };
  10294. var makeAnnotation = function (eDoc, _a, annotationName, decorate) {
  10295. var _b = _a.uid, uid = _b === void 0 ? generate('mce-annotation') : _b, data = __rest(_a, ['uid']);
  10296. var master = Element.fromTag('span', eDoc);
  10297. add$3(master, annotation());
  10298. set(master, '' + dataAnnotationId(), uid);
  10299. set(master, '' + dataAnnotation(), annotationName);
  10300. var _c = decorate(uid, data), _d = _c.attributes, attributes = _d === void 0 ? {} : _d, _e = _c.classes, classes = _e === void 0 ? [] : _e;
  10301. setAll(master, attributes);
  10302. add$4(master, classes);
  10303. return master;
  10304. };
  10305. var annotate = function (editor, rng, annotationName, decorate, data) {
  10306. var newWrappers = [];
  10307. var master = makeAnnotation(editor.getDoc(), data, annotationName, decorate);
  10308. var wrapper = Cell(Option.none());
  10309. var finishWrapper = function () {
  10310. wrapper.set(Option.none());
  10311. };
  10312. var getOrOpenWrapper = function () {
  10313. return wrapper.get().getOrThunk(function () {
  10314. var nu = shallow(master);
  10315. newWrappers.push(nu);
  10316. wrapper.set(Option.some(nu));
  10317. return nu;
  10318. });
  10319. };
  10320. var processElements = function (elems) {
  10321. each(elems, processElement);
  10322. };
  10323. var processElement = function (elem) {
  10324. var ctx = context(editor, elem, 'span', name(elem));
  10325. switch (ctx) {
  10326. case 'invalid-child': {
  10327. finishWrapper();
  10328. var children$1 = children(elem);
  10329. processElements(children$1);
  10330. finishWrapper();
  10331. break;
  10332. }
  10333. case 'valid': {
  10334. var w = getOrOpenWrapper();
  10335. wrap$1(elem, w);
  10336. break;
  10337. }
  10338. case 'skipping':
  10339. case 'existing':
  10340. case 'caret':
  10341. }
  10342. };
  10343. var processNodes = function (nodes) {
  10344. var elems = map(nodes, Element.fromDom);
  10345. processElements(elems);
  10346. };
  10347. RangeWalk.walk(editor.dom, rng, function (nodes) {
  10348. finishWrapper();
  10349. processNodes(nodes);
  10350. });
  10351. return newWrappers;
  10352. };
  10353. var annotateWithBookmark = function (editor, name, settings, data) {
  10354. editor.undoManager.transact(function () {
  10355. var initialRng = editor.selection.getRng();
  10356. if (initialRng.collapsed) {
  10357. applyWordGrab(editor, initialRng);
  10358. }
  10359. if (editor.selection.getRng().collapsed) {
  10360. var wrapper = makeAnnotation(editor.getDoc(), data, name, settings.decorate);
  10361. set$1(wrapper, '\xA0');
  10362. editor.selection.getRng().insertNode(wrapper.dom());
  10363. editor.selection.select(wrapper.dom());
  10364. } else {
  10365. var bookmark = GetBookmark.getPersistentBookmark(editor.selection, false);
  10366. var rng = editor.selection.getRng();
  10367. annotate(editor, rng, name, settings.decorate, data);
  10368. editor.selection.moveToBookmark(bookmark);
  10369. }
  10370. });
  10371. };
  10372. var Annotator = function (editor) {
  10373. var registry = create$1();
  10374. setup$1(editor, registry);
  10375. var changes = setup(editor);
  10376. return {
  10377. register: function (name, settings) {
  10378. registry.register(name, settings);
  10379. },
  10380. annotate: function (name, data) {
  10381. registry.lookup(name).each(function (settings) {
  10382. annotateWithBookmark(editor, name, settings, data);
  10383. });
  10384. },
  10385. annotationChanged: function (name, callback) {
  10386. changes.addListener(name, callback);
  10387. },
  10388. remove: function (name) {
  10389. identify(editor, Option.some(name)).each(function (_a) {
  10390. var elements = _a.elements;
  10391. each(elements, unwrap);
  10392. });
  10393. },
  10394. getAll: function (name) {
  10395. var directory = findAll(editor, name);
  10396. return map$1(directory, function (elems) {
  10397. return map(elems, function (elem) {
  10398. return elem.dom();
  10399. });
  10400. });
  10401. }
  10402. };
  10403. };
  10404. var whiteSpaceRegExp$3 = /^[ \t\r\n]*$/;
  10405. var typeLookup = {
  10406. '#text': 3,
  10407. '#comment': 8,
  10408. '#cdata': 4,
  10409. '#pi': 7,
  10410. '#doctype': 10,
  10411. '#document-fragment': 11
  10412. };
  10413. var walk$2 = function (node, root, prev) {
  10414. var startName = prev ? 'lastChild' : 'firstChild';
  10415. var siblingName = prev ? 'prev' : 'next';
  10416. if (node[startName]) {
  10417. return node[startName];
  10418. }
  10419. if (node !== root) {
  10420. var sibling = node[siblingName];
  10421. if (sibling) {
  10422. return sibling;
  10423. }
  10424. for (var parent = node.parent; parent && parent !== root; parent = parent.parent) {
  10425. sibling = parent[siblingName];
  10426. if (sibling) {
  10427. return sibling;
  10428. }
  10429. }
  10430. }
  10431. };
  10432. var Node$1 = function () {
  10433. function Node(name, type) {
  10434. this.name = name;
  10435. this.type = type;
  10436. if (type === 1) {
  10437. this.attributes = [];
  10438. this.attributes.map = {};
  10439. }
  10440. }
  10441. Node.create = function (name, attrs) {
  10442. var node = new Node(name, typeLookup[name] || 1);
  10443. if (attrs) {
  10444. for (var attrName in attrs) {
  10445. node.attr(attrName, attrs[attrName]);
  10446. }
  10447. }
  10448. return node;
  10449. };
  10450. Node.prototype.replace = function (node) {
  10451. var self = this;
  10452. if (node.parent) {
  10453. node.remove();
  10454. }
  10455. self.insert(node, self);
  10456. self.remove();
  10457. return self;
  10458. };
  10459. Node.prototype.attr = function (name, value) {
  10460. var self = this;
  10461. var attrs;
  10462. if (typeof name !== 'string') {
  10463. for (var key in name) {
  10464. self.attr(key, name[key]);
  10465. }
  10466. return self;
  10467. }
  10468. if (attrs = self.attributes) {
  10469. if (value !== undefined) {
  10470. if (value === null) {
  10471. if (name in attrs.map) {
  10472. delete attrs.map[name];
  10473. var i = attrs.length;
  10474. while (i--) {
  10475. if (attrs[i].name === name) {
  10476. attrs.splice(i, 1);
  10477. return self;
  10478. }
  10479. }
  10480. }
  10481. return self;
  10482. }
  10483. if (name in attrs.map) {
  10484. var i = attrs.length;
  10485. while (i--) {
  10486. if (attrs[i].name === name) {
  10487. attrs[i].value = value;
  10488. break;
  10489. }
  10490. }
  10491. } else {
  10492. attrs.push({
  10493. name: name,
  10494. value: value
  10495. });
  10496. }
  10497. attrs.map[name] = value;
  10498. return self;
  10499. }
  10500. return attrs.map[name];
  10501. }
  10502. };
  10503. Node.prototype.clone = function () {
  10504. var self = this;
  10505. var clone = new Node(self.name, self.type);
  10506. var selfAttrs;
  10507. if (selfAttrs = self.attributes) {
  10508. var cloneAttrs = [];
  10509. cloneAttrs.map = {};
  10510. for (var i = 0, l = selfAttrs.length; i < l; i++) {
  10511. var selfAttr = selfAttrs[i];
  10512. if (selfAttr.name !== 'id') {
  10513. cloneAttrs[cloneAttrs.length] = {
  10514. name: selfAttr.name,
  10515. value: selfAttr.value
  10516. };
  10517. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  10518. }
  10519. }
  10520. clone.attributes = cloneAttrs;
  10521. }
  10522. clone.value = self.value;
  10523. clone.shortEnded = self.shortEnded;
  10524. return clone;
  10525. };
  10526. Node.prototype.wrap = function (wrapper) {
  10527. var self = this;
  10528. self.parent.insert(wrapper, self);
  10529. wrapper.append(self);
  10530. return self;
  10531. };
  10532. Node.prototype.unwrap = function () {
  10533. var self = this;
  10534. for (var node = self.firstChild; node;) {
  10535. var next = node.next;
  10536. self.insert(node, self, true);
  10537. node = next;
  10538. }
  10539. self.remove();
  10540. };
  10541. Node.prototype.remove = function () {
  10542. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  10543. if (parent) {
  10544. if (parent.firstChild === self) {
  10545. parent.firstChild = next;
  10546. if (next) {
  10547. next.prev = null;
  10548. }
  10549. } else {
  10550. prev.next = next;
  10551. }
  10552. if (parent.lastChild === self) {
  10553. parent.lastChild = prev;
  10554. if (prev) {
  10555. prev.next = null;
  10556. }
  10557. } else {
  10558. next.prev = prev;
  10559. }
  10560. self.parent = self.next = self.prev = null;
  10561. }
  10562. return self;
  10563. };
  10564. Node.prototype.append = function (node) {
  10565. var self = this;
  10566. if (node.parent) {
  10567. node.remove();
  10568. }
  10569. var last = self.lastChild;
  10570. if (last) {
  10571. last.next = node;
  10572. node.prev = last;
  10573. self.lastChild = node;
  10574. } else {
  10575. self.lastChild = self.firstChild = node;
  10576. }
  10577. node.parent = self;
  10578. return node;
  10579. };
  10580. Node.prototype.insert = function (node, refNode, before) {
  10581. if (node.parent) {
  10582. node.remove();
  10583. }
  10584. var parent = refNode.parent || this;
  10585. if (before) {
  10586. if (refNode === parent.firstChild) {
  10587. parent.firstChild = node;
  10588. } else {
  10589. refNode.prev.next = node;
  10590. }
  10591. node.prev = refNode.prev;
  10592. node.next = refNode;
  10593. refNode.prev = node;
  10594. } else {
  10595. if (refNode === parent.lastChild) {
  10596. parent.lastChild = node;
  10597. } else {
  10598. refNode.next.prev = node;
  10599. }
  10600. node.next = refNode.next;
  10601. node.prev = refNode;
  10602. refNode.next = node;
  10603. }
  10604. node.parent = parent;
  10605. return node;
  10606. };
  10607. Node.prototype.getAll = function (name) {
  10608. var self = this;
  10609. var collection = [];
  10610. for (var node = self.firstChild; node; node = walk$2(node, self)) {
  10611. if (node.name === name) {
  10612. collection.push(node);
  10613. }
  10614. }
  10615. return collection;
  10616. };
  10617. Node.prototype.empty = function () {
  10618. var self = this;
  10619. if (self.firstChild) {
  10620. var nodes = [];
  10621. for (var node = self.firstChild; node; node = walk$2(node, self)) {
  10622. nodes.push(node);
  10623. }
  10624. var i = nodes.length;
  10625. while (i--) {
  10626. var node = nodes[i];
  10627. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  10628. }
  10629. }
  10630. self.firstChild = self.lastChild = null;
  10631. return self;
  10632. };
  10633. Node.prototype.isEmpty = function (elements, whitespace, predicate) {
  10634. if (whitespace === void 0) {
  10635. whitespace = {};
  10636. }
  10637. var self = this;
  10638. var node = self.firstChild;
  10639. if (node) {
  10640. do {
  10641. if (node.type === 1) {
  10642. if (node.attr('data-mce-bogus')) {
  10643. continue;
  10644. }
  10645. if (elements[node.name]) {
  10646. return false;
  10647. }
  10648. var i = node.attributes.length;
  10649. while (i--) {
  10650. var name = node.attributes[i].name;
  10651. if (name === 'name' || name.indexOf('data-mce-bookmark') === 0) {
  10652. return false;
  10653. }
  10654. }
  10655. }
  10656. if (node.type === 8) {
  10657. return false;
  10658. }
  10659. if (node.type === 3 && !whiteSpaceRegExp$3.test(node.value)) {
  10660. return false;
  10661. }
  10662. if (node.type === 3 && node.parent && whitespace[node.parent.name] && whiteSpaceRegExp$3.test(node.value)) {
  10663. return false;
  10664. }
  10665. if (predicate && predicate(node)) {
  10666. return false;
  10667. }
  10668. } while (node = walk$2(node, self));
  10669. }
  10670. return true;
  10671. };
  10672. Node.prototype.walk = function (prev) {
  10673. return walk$2(this, null, prev);
  10674. };
  10675. return Node;
  10676. }();
  10677. var isValidPrefixAttrName = function (name) {
  10678. return name.indexOf('data-') === 0 || name.indexOf('aria-') === 0;
  10679. };
  10680. var trimComments = function (text) {
  10681. return text.replace(/<!--|-->/g, '');
  10682. };
  10683. var isInvalidUri = function (settings, uri) {
  10684. if (settings.allow_html_data_urls) {
  10685. return false;
  10686. } else if (/^data:image\//i.test(uri)) {
  10687. return settings.allow_svg_data_urls === false && /^data:image\/svg\+xml/i.test(uri);
  10688. } else {
  10689. return /^data:/i.test(uri);
  10690. }
  10691. };
  10692. var findEndTagIndex = function (schema, html, startIndex) {
  10693. var count = 1, index, matches, tokenRegExp, shortEndedElements;
  10694. shortEndedElements = schema.getShortEndedElements();
  10695. tokenRegExp = /<([!?\/])?([A-Za-z0-9\-_\:\.]+)((?:\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\/|\s+)>/g;
  10696. tokenRegExp.lastIndex = index = startIndex;
  10697. while (matches = tokenRegExp.exec(html)) {
  10698. index = tokenRegExp.lastIndex;
  10699. if (matches[1] === '/') {
  10700. count--;
  10701. } else if (!matches[1]) {
  10702. if (matches[2] in shortEndedElements) {
  10703. continue;
  10704. }
  10705. count++;
  10706. }
  10707. if (count === 0) {
  10708. break;
  10709. }
  10710. }
  10711. return index;
  10712. };
  10713. var checkBogusAttribute = function (regExp, attrString) {
  10714. var matches = regExp.exec(attrString);
  10715. if (matches) {
  10716. var name = matches[1];
  10717. var value = matches[2];
  10718. return typeof name === 'string' && name.toLowerCase() === 'data-mce-bogus' ? value : null;
  10719. } else {
  10720. return null;
  10721. }
  10722. };
  10723. function SaxParser(settings, schema) {
  10724. if (schema === void 0) {
  10725. schema = Schema();
  10726. }
  10727. var noop = function () {
  10728. };
  10729. settings = settings || {};
  10730. if (settings.fix_self_closing !== false) {
  10731. settings.fix_self_closing = true;
  10732. }
  10733. var comment = settings.comment ? settings.comment : noop;
  10734. var cdata = settings.cdata ? settings.cdata : noop;
  10735. var text = settings.text ? settings.text : noop;
  10736. var start = settings.start ? settings.start : noop;
  10737. var end = settings.end ? settings.end : noop;
  10738. var pi = settings.pi ? settings.pi : noop;
  10739. var doctype = settings.doctype ? settings.doctype : noop;
  10740. var parse = function (html) {
  10741. var matches, index = 0, value, endRegExp;
  10742. var stack = [];
  10743. var attrList, i, textData, name;
  10744. var isInternalElement, removeInternalElements, shortEndedElements, fillAttrsMap, isShortEnded;
  10745. var validate, elementRule, isValidElement, attr, attribsValue, validAttributesMap, validAttributePatterns;
  10746. var attributesRequired, attributesDefault, attributesForced, processHtml;
  10747. var anyAttributesRequired, selfClosing, tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0;
  10748. var decode = Entities.decode;
  10749. var fixSelfClosing;
  10750. var filteredUrlAttrs = Tools.makeMap('src,href,data,background,formaction,poster,xlink:href');
  10751. var scriptUriRegExp = /((java|vb)script|mhtml):/i;
  10752. var processEndTag = function (name) {
  10753. var pos, i;
  10754. pos = stack.length;
  10755. while (pos--) {
  10756. if (stack[pos].name === name) {
  10757. break;
  10758. }
  10759. }
  10760. if (pos >= 0) {
  10761. for (i = stack.length - 1; i >= pos; i--) {
  10762. name = stack[i];
  10763. if (name.valid) {
  10764. end(name.name);
  10765. }
  10766. }
  10767. stack.length = pos;
  10768. }
  10769. };
  10770. var parseAttribute = function (match, name, value, val2, val3) {
  10771. var attrRule, i;
  10772. var trimRegExp = /[\s\u0000-\u001F]+/g;
  10773. name = name.toLowerCase();
  10774. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || '');
  10775. if (validate && !isInternalElement && isValidPrefixAttrName(name) === false) {
  10776. attrRule = validAttributesMap[name];
  10777. if (!attrRule && validAttributePatterns) {
  10778. i = validAttributePatterns.length;
  10779. while (i--) {
  10780. attrRule = validAttributePatterns[i];
  10781. if (attrRule.pattern.test(name)) {
  10782. break;
  10783. }
  10784. }
  10785. if (i === -1) {
  10786. attrRule = null;
  10787. }
  10788. }
  10789. if (!attrRule) {
  10790. return;
  10791. }
  10792. if (attrRule.validValues && !(value in attrRule.validValues)) {
  10793. return;
  10794. }
  10795. }
  10796. if (filteredUrlAttrs[name] && !settings.allow_script_urls) {
  10797. var uri = value.replace(trimRegExp, '');
  10798. try {
  10799. uri = decodeURIComponent(uri);
  10800. } catch (ex) {
  10801. uri = unescape(uri);
  10802. }
  10803. if (scriptUriRegExp.test(uri)) {
  10804. return;
  10805. }
  10806. if (isInvalidUri(settings, uri)) {
  10807. return;
  10808. }
  10809. }
  10810. if (isInternalElement && (name in filteredUrlAttrs || name.indexOf('on') === 0)) {
  10811. return;
  10812. }
  10813. attrList.map[name] = value;
  10814. attrList.push({
  10815. name: name,
  10816. value: value
  10817. });
  10818. };
  10819. tokenRegExp = new RegExp('<(?:' + '(?:!--([\\w\\W]*?)--!?>)|' + '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + '(?:!DOCTYPE([\\w\\W]*?)>)|' + '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + '(?:\\/([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)>)|' + '(?:([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + ')', 'g');
  10820. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
  10821. shortEndedElements = schema.getShortEndedElements();
  10822. selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  10823. fillAttrsMap = schema.getBoolAttrs();
  10824. validate = settings.validate;
  10825. removeInternalElements = settings.remove_internals;
  10826. fixSelfClosing = settings.fix_self_closing;
  10827. specialElements = schema.getSpecialElements();
  10828. processHtml = html + '>';
  10829. while (matches = tokenRegExp.exec(processHtml)) {
  10830. if (index < matches.index) {
  10831. text(decode(html.substr(index, matches.index - index)));
  10832. }
  10833. if (value = matches[6]) {
  10834. value = value.toLowerCase();
  10835. if (value.charAt(0) === ':') {
  10836. value = value.substr(1);
  10837. }
  10838. processEndTag(value);
  10839. } else if (value = matches[7]) {
  10840. if (matches.index + matches[0].length > html.length) {
  10841. text(decode(html.substr(matches.index)));
  10842. index = matches.index + matches[0].length;
  10843. continue;
  10844. }
  10845. value = value.toLowerCase();
  10846. if (value.charAt(0) === ':') {
  10847. value = value.substr(1);
  10848. }
  10849. isShortEnded = value in shortEndedElements;
  10850. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value) {
  10851. processEndTag(value);
  10852. }
  10853. var bogusValue = checkBogusAttribute(attrRegExp, matches[8]);
  10854. if (bogusValue !== null) {
  10855. if (bogusValue === 'all') {
  10856. index = findEndTagIndex(schema, html, tokenRegExp.lastIndex);
  10857. tokenRegExp.lastIndex = index;
  10858. continue;
  10859. }
  10860. isValidElement = false;
  10861. }
  10862. if (!validate || (elementRule = schema.getElementRule(value))) {
  10863. isValidElement = true;
  10864. if (validate) {
  10865. validAttributesMap = elementRule.attributes;
  10866. validAttributePatterns = elementRule.attributePatterns;
  10867. }
  10868. if (attribsValue = matches[8]) {
  10869. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1;
  10870. if (isInternalElement && removeInternalElements) {
  10871. isValidElement = false;
  10872. }
  10873. attrList = [];
  10874. attrList.map = {};
  10875. attribsValue.replace(attrRegExp, parseAttribute);
  10876. } else {
  10877. attrList = [];
  10878. attrList.map = {};
  10879. }
  10880. if (validate && !isInternalElement) {
  10881. attributesRequired = elementRule.attributesRequired;
  10882. attributesDefault = elementRule.attributesDefault;
  10883. attributesForced = elementRule.attributesForced;
  10884. anyAttributesRequired = elementRule.removeEmptyAttrs;
  10885. if (anyAttributesRequired && !attrList.length) {
  10886. isValidElement = false;
  10887. }
  10888. if (attributesForced) {
  10889. i = attributesForced.length;
  10890. while (i--) {
  10891. attr = attributesForced[i];
  10892. name = attr.name;
  10893. attrValue = attr.value;
  10894. if (attrValue === '{$uid}') {
  10895. attrValue = 'mce_' + idCount++;
  10896. }
  10897. attrList.map[name] = attrValue;
  10898. attrList.push({
  10899. name: name,
  10900. value: attrValue
  10901. });
  10902. }
  10903. }
  10904. if (attributesDefault) {
  10905. i = attributesDefault.length;
  10906. while (i--) {
  10907. attr = attributesDefault[i];
  10908. name = attr.name;
  10909. if (!(name in attrList.map)) {
  10910. attrValue = attr.value;
  10911. if (attrValue === '{$uid}') {
  10912. attrValue = 'mce_' + idCount++;
  10913. }
  10914. attrList.map[name] = attrValue;
  10915. attrList.push({
  10916. name: name,
  10917. value: attrValue
  10918. });
  10919. }
  10920. }
  10921. }
  10922. if (attributesRequired) {
  10923. i = attributesRequired.length;
  10924. while (i--) {
  10925. if (attributesRequired[i] in attrList.map) {
  10926. break;
  10927. }
  10928. }
  10929. if (i === -1) {
  10930. isValidElement = false;
  10931. }
  10932. }
  10933. if (attr = attrList.map['data-mce-bogus']) {
  10934. if (attr === 'all') {
  10935. index = findEndTagIndex(schema, html, tokenRegExp.lastIndex);
  10936. tokenRegExp.lastIndex = index;
  10937. continue;
  10938. }
  10939. isValidElement = false;
  10940. }
  10941. }
  10942. if (isValidElement) {
  10943. start(value, attrList, isShortEnded);
  10944. }
  10945. } else {
  10946. isValidElement = false;
  10947. }
  10948. if (endRegExp = specialElements[value]) {
  10949. endRegExp.lastIndex = index = matches.index + matches[0].length;
  10950. if (matches = endRegExp.exec(html)) {
  10951. if (isValidElement) {
  10952. textData = html.substr(index, matches.index - index);
  10953. }
  10954. index = matches.index + matches[0].length;
  10955. } else {
  10956. textData = html.substr(index);
  10957. index = html.length;
  10958. }
  10959. if (isValidElement) {
  10960. if (textData.length > 0) {
  10961. text(textData, true);
  10962. }
  10963. end(value);
  10964. }
  10965. tokenRegExp.lastIndex = index;
  10966. continue;
  10967. }
  10968. if (!isShortEnded) {
  10969. if (!attribsValue || attribsValue.indexOf('/') !== attribsValue.length - 1) {
  10970. stack.push({
  10971. name: value,
  10972. valid: isValidElement
  10973. });
  10974. } else if (isValidElement) {
  10975. end(value);
  10976. }
  10977. }
  10978. } else if (value = matches[1]) {
  10979. if (value.charAt(0) === '>') {
  10980. value = ' ' + value;
  10981. }
  10982. if (!settings.allow_conditional_comments && value.substr(0, 3).toLowerCase() === '[if') {
  10983. value = ' ' + value;
  10984. }
  10985. comment(value);
  10986. } else if (value = matches[2]) {
  10987. cdata(trimComments(value));
  10988. } else if (value = matches[3]) {
  10989. doctype(value);
  10990. } else if (value = matches[4]) {
  10991. pi(value, matches[5]);
  10992. }
  10993. index = matches.index + matches[0].length;
  10994. }
  10995. if (index < html.length) {
  10996. text(decode(html.substr(index)));
  10997. }
  10998. for (i = stack.length - 1; i >= 0; i--) {
  10999. value = stack[i];
  11000. if (value.valid) {
  11001. end(value.name);
  11002. }
  11003. }
  11004. };
  11005. return { parse: parse };
  11006. }
  11007. (function (SaxParser) {
  11008. SaxParser.findEndTag = findEndTagIndex;
  11009. }(SaxParser || (SaxParser = {})));
  11010. var SaxParser$1 = SaxParser;
  11011. var trimHtml = function (tempAttrs, html) {
  11012. var trimContentRegExp = new RegExp(['\\s?(' + tempAttrs.join('|') + ')="[^"]+"'].join('|'), 'gi');
  11013. return html.replace(trimContentRegExp, '');
  11014. };
  11015. var trimInternal = function (serializer, html) {
  11016. var content = html;
  11017. var bogusAllRegExp = /<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g;
  11018. var endTagIndex, index, matchLength, matches, shortEndedElements;
  11019. var schema = serializer.schema;
  11020. content = trimHtml(serializer.getTempAttrs(), content);
  11021. shortEndedElements = schema.getShortEndedElements();
  11022. while (matches = bogusAllRegExp.exec(content)) {
  11023. index = bogusAllRegExp.lastIndex;
  11024. matchLength = matches[0].length;
  11025. if (shortEndedElements[matches[1]]) {
  11026. endTagIndex = index;
  11027. } else {
  11028. endTagIndex = SaxParser$1.findEndTag(schema, content, index);
  11029. }
  11030. content = content.substring(0, index - matchLength) + content.substring(endTagIndex);
  11031. bogusAllRegExp.lastIndex = index - matchLength;
  11032. }
  11033. return Zwsp.trim(content);
  11034. };
  11035. var trimExternal = trimInternal;
  11036. var TrimHtml = {
  11037. trimExternal: trimExternal,
  11038. trimInternal: trimInternal
  11039. };
  11040. var getBodySetting = function (editor, name, defaultValue) {
  11041. var value = editor.getParam(name, defaultValue);
  11042. if (value.indexOf('=') !== -1) {
  11043. var bodyObj = editor.getParam(name, '', 'hash');
  11044. return bodyObj.hasOwnProperty(editor.id) ? bodyObj[editor.id] : defaultValue;
  11045. } else {
  11046. return value;
  11047. }
  11048. };
  11049. var getIframeAttrs = function (editor) {
  11050. return editor.getParam('iframe_attrs', {});
  11051. };
  11052. var getDocType = function (editor) {
  11053. return editor.getParam('doctype', '<!DOCTYPE html>');
  11054. };
  11055. var getDocumentBaseUrl = function (editor) {
  11056. return editor.getParam('document_base_url', '');
  11057. };
  11058. var getBodyId = function (editor) {
  11059. return getBodySetting(editor, 'body_id', 'tinymce');
  11060. };
  11061. var getBodyClass = function (editor) {
  11062. return getBodySetting(editor, 'body_class', '');
  11063. };
  11064. var getContentSecurityPolicy = function (editor) {
  11065. return editor.getParam('content_security_policy', '');
  11066. };
  11067. var shouldPutBrInPre = function (editor) {
  11068. return editor.getParam('br_in_pre', true);
  11069. };
  11070. var getForcedRootBlock = function (editor) {
  11071. if (editor.getParam('force_p_newlines', false)) {
  11072. return 'p';
  11073. }
  11074. var block = editor.getParam('forced_root_block', 'p');
  11075. if (block === false) {
  11076. return '';
  11077. } else if (block === true) {
  11078. return 'p';
  11079. } else {
  11080. return block;
  11081. }
  11082. };
  11083. var getForcedRootBlockAttrs = function (editor) {
  11084. return editor.getParam('forced_root_block_attrs', {});
  11085. };
  11086. var getBrNewLineSelector = function (editor) {
  11087. return editor.getParam('br_newline_selector', '.mce-toc h2,figcaption,caption');
  11088. };
  11089. var getNoNewLineSelector = function (editor) {
  11090. return editor.getParam('no_newline_selector', '');
  11091. };
  11092. var shouldKeepStyles = function (editor) {
  11093. return editor.getParam('keep_styles', true);
  11094. };
  11095. var shouldEndContainerOnEmptyBlock = function (editor) {
  11096. return editor.getParam('end_container_on_empty_block', false);
  11097. };
  11098. var getFontStyleValues = function (editor) {
  11099. return Tools.explode(editor.getParam('font_size_style_values', 'xx-small,x-small,small,medium,large,x-large,xx-large'));
  11100. };
  11101. var getFontSizeClasses = function (editor) {
  11102. return Tools.explode(editor.getParam('font_size_classes', ''));
  11103. };
  11104. var getImagesDataImgFilter = function (editor) {
  11105. return editor.getParam('images_dataimg_filter', constant(true), 'function');
  11106. };
  11107. var isAutomaticUploadsEnabled = function (editor) {
  11108. return editor.getParam('automatic_uploads', true, 'boolean');
  11109. };
  11110. var shouldReuseFileName = function (editor) {
  11111. return editor.getParam('images_reuse_filename', false, 'boolean');
  11112. };
  11113. var shouldReplaceBlobUris = function (editor) {
  11114. return editor.getParam('images_replace_blob_uris', true, 'boolean');
  11115. };
  11116. var getIconPackName = function (editor) {
  11117. return editor.getParam('icons', '', 'string');
  11118. };
  11119. var getIconsUrl = function (editor) {
  11120. return editor.getParam('icons_url', '', 'string');
  11121. };
  11122. var getImageUploadUrl = function (editor) {
  11123. return editor.getParam('images_upload_url', '', 'string');
  11124. };
  11125. var getImageUploadBasePath = function (editor) {
  11126. return editor.getParam('images_upload_base_path', '', 'string');
  11127. };
  11128. var getImagesUploadCredentials = function (editor) {
  11129. return editor.getParam('images_upload_credentials', false, 'boolean');
  11130. };
  11131. var getImagesUploadHandler = function (editor) {
  11132. return editor.getParam('images_upload_handler', null, 'function');
  11133. };
  11134. var shouldUseContentCssCors = function (editor) {
  11135. return editor.getParam('content_css_cors', false, 'boolean');
  11136. };
  11137. var getReferrerPolicy = function (editor) {
  11138. return editor.getParam('referrer_policy', '', 'string');
  11139. };
  11140. var getLanguageCode = function (editor) {
  11141. return editor.getParam('language', 'en', 'string');
  11142. };
  11143. var getLanguageUrl = function (editor) {
  11144. return editor.getParam('language_url', '', 'string');
  11145. };
  11146. var shouldIndentUseMargin = function (editor) {
  11147. return editor.getParam('indent_use_margin', false);
  11148. };
  11149. var getIndentation = function (editor) {
  11150. return editor.getParam('indentation', '40px', 'string');
  11151. };
  11152. var getContentCss = function (editor) {
  11153. var contentCss = editor.settings.content_css;
  11154. if (isString(contentCss)) {
  11155. return map(contentCss.split(','), trim);
  11156. } else if (isArray(contentCss)) {
  11157. return contentCss;
  11158. } else if (contentCss === false || editor.inline) {
  11159. return [];
  11160. } else {
  11161. return ['default'];
  11162. }
  11163. };
  11164. var getDirectionality = function (editor) {
  11165. return editor.getParam('directionality', I18n.isRtl() ? 'rtl' : undefined);
  11166. };
  11167. var getInlineBoundarySelector = function (editor) {
  11168. return editor.getParam('inline_boundaries_selector', 'a[href],code,.mce-annotation', 'string');
  11169. };
  11170. var Settings = {
  11171. getIframeAttrs: getIframeAttrs,
  11172. getDocType: getDocType,
  11173. getDocumentBaseUrl: getDocumentBaseUrl,
  11174. getBodyId: getBodyId,
  11175. getBodyClass: getBodyClass,
  11176. getContentSecurityPolicy: getContentSecurityPolicy,
  11177. shouldPutBrInPre: shouldPutBrInPre,
  11178. getForcedRootBlock: getForcedRootBlock,
  11179. getForcedRootBlockAttrs: getForcedRootBlockAttrs,
  11180. getBrNewLineSelector: getBrNewLineSelector,
  11181. getNoNewLineSelector: getNoNewLineSelector,
  11182. shouldKeepStyles: shouldKeepStyles,
  11183. shouldEndContainerOnEmptyBlock: shouldEndContainerOnEmptyBlock,
  11184. getFontStyleValues: getFontStyleValues,
  11185. getFontSizeClasses: getFontSizeClasses,
  11186. getIconPackName: getIconPackName,
  11187. getIconsUrl: getIconsUrl,
  11188. getImagesDataImgFilter: getImagesDataImgFilter,
  11189. isAutomaticUploadsEnabled: isAutomaticUploadsEnabled,
  11190. shouldReuseFileName: shouldReuseFileName,
  11191. shouldReplaceBlobUris: shouldReplaceBlobUris,
  11192. getImageUploadUrl: getImageUploadUrl,
  11193. getImageUploadBasePath: getImageUploadBasePath,
  11194. getImagesUploadCredentials: getImagesUploadCredentials,
  11195. getImagesUploadHandler: getImagesUploadHandler,
  11196. shouldUseContentCssCors: shouldUseContentCssCors,
  11197. getReferrerPolicy: getReferrerPolicy,
  11198. getLanguageCode: getLanguageCode,
  11199. getLanguageUrl: getLanguageUrl,
  11200. shouldIndentUseMargin: shouldIndentUseMargin,
  11201. getIndentation: getIndentation,
  11202. getContentCss: getContentCss,
  11203. getDirectionality: getDirectionality,
  11204. getInlineBoundarySelector: getInlineBoundarySelector
  11205. };
  11206. var defaultFormat = 'html';
  11207. var trimEmptyContents = function (editor, html) {
  11208. var blockName = Settings.getForcedRootBlock(editor);
  11209. var emptyRegExp = new RegExp('^(<' + blockName + '[^>]*>(&nbsp;|&#160;|\\s|\xA0|<br \\/>|)<\\/' + blockName + '>[\r\n]*|<br \\/>[\r\n]*)$');
  11210. return html.replace(emptyRegExp, '');
  11211. };
  11212. var getContentFromBody = function (editor, args, body) {
  11213. var content;
  11214. args.format = args.format ? args.format : defaultFormat;
  11215. args.get = true;
  11216. args.getInner = true;
  11217. if (!args.no_events) {
  11218. editor.fire('BeforeGetContent', args);
  11219. }
  11220. if (args.format === 'raw') {
  11221. content = Tools.trim(TrimHtml.trimExternal(editor.serializer, body.innerHTML));
  11222. } else if (args.format === 'text') {
  11223. content = Zwsp.trim(body.innerText || body.textContent);
  11224. } else if (args.format === 'tree') {
  11225. return editor.serializer.serialize(body, args);
  11226. } else {
  11227. content = trimEmptyContents(editor, editor.serializer.serialize(body, args));
  11228. }
  11229. if (args.format !== 'text' && !isWsPreserveElement(Element.fromDom(body))) {
  11230. args.content = Tools.trim(content);
  11231. } else {
  11232. args.content = content;
  11233. }
  11234. if (!args.no_events) {
  11235. editor.fire('GetContent', args);
  11236. }
  11237. return args.content;
  11238. };
  11239. var getContent = function (editor, args) {
  11240. if (args === void 0) {
  11241. args = {};
  11242. }
  11243. return Option.from(editor.getBody()).fold(constant(args.format === 'tree' ? new Node$1('body', 11) : ''), function (body) {
  11244. return getContentFromBody(editor, args, body);
  11245. });
  11246. };
  11247. var makeMap$3 = Tools.makeMap;
  11248. var Writer = function (settings) {
  11249. var html = [];
  11250. var indent, indentBefore, indentAfter, encode, htmlOutput;
  11251. settings = settings || {};
  11252. indent = settings.indent;
  11253. indentBefore = makeMap$3(settings.indent_before || '');
  11254. indentAfter = makeMap$3(settings.indent_after || '');
  11255. encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  11256. htmlOutput = settings.element_format === 'html';
  11257. return {
  11258. start: function (name, attrs, empty) {
  11259. var i, l, attr, value;
  11260. if (indent && indentBefore[name] && html.length > 0) {
  11261. value = html[html.length - 1];
  11262. if (value.length > 0 && value !== '\n') {
  11263. html.push('\n');
  11264. }
  11265. }
  11266. html.push('<', name);
  11267. if (attrs) {
  11268. for (i = 0, l = attrs.length; i < l; i++) {
  11269. attr = attrs[i];
  11270. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  11271. }
  11272. }
  11273. if (!empty || htmlOutput) {
  11274. html[html.length] = '>';
  11275. } else {
  11276. html[html.length] = ' />';
  11277. }
  11278. if (empty && indent && indentAfter[name] && html.length > 0) {
  11279. value = html[html.length - 1];
  11280. if (value.length > 0 && value !== '\n') {
  11281. html.push('\n');
  11282. }
  11283. }
  11284. },
  11285. end: function (name) {
  11286. var value;
  11287. html.push('</', name, '>');
  11288. if (indent && indentAfter[name] && html.length > 0) {
  11289. value = html[html.length - 1];
  11290. if (value.length > 0 && value !== '\n') {
  11291. html.push('\n');
  11292. }
  11293. }
  11294. },
  11295. text: function (text, raw) {
  11296. if (text.length > 0) {
  11297. html[html.length] = raw ? text : encode(text);
  11298. }
  11299. },
  11300. cdata: function (text) {
  11301. html.push('<![CDATA[', text, ']]>');
  11302. },
  11303. comment: function (text) {
  11304. html.push('<!--', text, '-->');
  11305. },
  11306. pi: function (name, text) {
  11307. if (text) {
  11308. html.push('<?', name, ' ', encode(text), '?>');
  11309. } else {
  11310. html.push('<?', name, '?>');
  11311. }
  11312. if (indent) {
  11313. html.push('\n');
  11314. }
  11315. },
  11316. doctype: function (text) {
  11317. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  11318. },
  11319. reset: function () {
  11320. html.length = 0;
  11321. },
  11322. getContent: function () {
  11323. return html.join('').replace(/\n$/, '');
  11324. }
  11325. };
  11326. };
  11327. var Serializer = function (settings, schema) {
  11328. if (schema === void 0) {
  11329. schema = Schema();
  11330. }
  11331. var writer = Writer(settings);
  11332. settings = settings || {};
  11333. settings.validate = 'validate' in settings ? settings.validate : true;
  11334. var serialize = function (node) {
  11335. var handlers, validate;
  11336. validate = settings.validate;
  11337. handlers = {
  11338. 3: function (node) {
  11339. writer.text(node.value, node.raw);
  11340. },
  11341. 8: function (node) {
  11342. writer.comment(node.value);
  11343. },
  11344. 7: function (node) {
  11345. writer.pi(node.name, node.value);
  11346. },
  11347. 10: function (node) {
  11348. writer.doctype(node.value);
  11349. },
  11350. 4: function (node) {
  11351. writer.cdata(node.value);
  11352. },
  11353. 11: function (node) {
  11354. if (node = node.firstChild) {
  11355. do {
  11356. walk(node);
  11357. } while (node = node.next);
  11358. }
  11359. }
  11360. };
  11361. writer.reset();
  11362. var walk = function (node) {
  11363. var handler = handlers[node.type];
  11364. var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  11365. if (!handler) {
  11366. name = node.name;
  11367. isEmpty = node.shortEnded;
  11368. attrs = node.attributes;
  11369. if (validate && attrs && attrs.length > 1) {
  11370. sortedAttrs = [];
  11371. sortedAttrs.map = {};
  11372. elementRule = schema.getElementRule(node.name);
  11373. if (elementRule) {
  11374. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  11375. attrName = elementRule.attributesOrder[i];
  11376. if (attrName in attrs.map) {
  11377. attrValue = attrs.map[attrName];
  11378. sortedAttrs.map[attrName] = attrValue;
  11379. sortedAttrs.push({
  11380. name: attrName,
  11381. value: attrValue
  11382. });
  11383. }
  11384. }
  11385. for (i = 0, l = attrs.length; i < l; i++) {
  11386. attrName = attrs[i].name;
  11387. if (!(attrName in sortedAttrs.map)) {
  11388. attrValue = attrs.map[attrName];
  11389. sortedAttrs.map[attrName] = attrValue;
  11390. sortedAttrs.push({
  11391. name: attrName,
  11392. value: attrValue
  11393. });
  11394. }
  11395. }
  11396. attrs = sortedAttrs;
  11397. }
  11398. }
  11399. writer.start(node.name, attrs, isEmpty);
  11400. if (!isEmpty) {
  11401. if (node = node.firstChild) {
  11402. do {
  11403. walk(node);
  11404. } while (node = node.next);
  11405. }
  11406. writer.end(name);
  11407. }
  11408. } else {
  11409. handler(node);
  11410. }
  11411. };
  11412. if (node.type === 1 && !settings.inner) {
  11413. walk(node);
  11414. } else {
  11415. handlers[11](node);
  11416. }
  11417. return writer.getContent();
  11418. };
  11419. return { serialize: serialize };
  11420. };
  11421. var traverse = function (node, fn) {
  11422. fn(node);
  11423. if (node.firstChild) {
  11424. traverse(node.firstChild, fn);
  11425. }
  11426. if (node.next) {
  11427. traverse(node.next, fn);
  11428. }
  11429. };
  11430. var findMatchingNodes = function (nodeFilters, attributeFilters, node) {
  11431. var nodeMatches = {};
  11432. var attrMatches = {};
  11433. var matches = [];
  11434. if (node.firstChild) {
  11435. traverse(node.firstChild, function (node) {
  11436. each(nodeFilters, function (filter) {
  11437. if (filter.name === node.name) {
  11438. if (nodeMatches[filter.name]) {
  11439. nodeMatches[filter.name].nodes.push(node);
  11440. } else {
  11441. nodeMatches[filter.name] = {
  11442. filter: filter,
  11443. nodes: [node]
  11444. };
  11445. }
  11446. }
  11447. });
  11448. each(attributeFilters, function (filter) {
  11449. if (typeof node.attr(filter.name) === 'string') {
  11450. if (attrMatches[filter.name]) {
  11451. attrMatches[filter.name].nodes.push(node);
  11452. } else {
  11453. attrMatches[filter.name] = {
  11454. filter: filter,
  11455. nodes: [node]
  11456. };
  11457. }
  11458. }
  11459. });
  11460. });
  11461. }
  11462. for (var name in nodeMatches) {
  11463. if (nodeMatches.hasOwnProperty(name)) {
  11464. matches.push(nodeMatches[name]);
  11465. }
  11466. }
  11467. for (var name in attrMatches) {
  11468. if (attrMatches.hasOwnProperty(name)) {
  11469. matches.push(attrMatches[name]);
  11470. }
  11471. }
  11472. return matches;
  11473. };
  11474. var filter$2 = function (nodeFilters, attributeFilters, node) {
  11475. var matches = findMatchingNodes(nodeFilters, attributeFilters, node);
  11476. each(matches, function (match) {
  11477. each(match.filter.callbacks, function (callback) {
  11478. callback(match.nodes, match.filter.name, {});
  11479. });
  11480. });
  11481. };
  11482. var hasFocus = function (element) {
  11483. var doc = owner(element).dom();
  11484. return element.dom() === doc.activeElement;
  11485. };
  11486. var active = function (_doc) {
  11487. var doc = _doc !== undefined ? _doc.dom() : domGlobals.document;
  11488. return Option.from(doc.activeElement).map(Element.fromDom);
  11489. };
  11490. var search = function (element) {
  11491. return active(owner(element)).filter(function (e) {
  11492. return element.dom().contains(e.dom());
  11493. });
  11494. };
  11495. var generate$1 = function (cases) {
  11496. if (!isArray(cases)) {
  11497. throw new Error('cases must be an array');
  11498. }
  11499. if (cases.length === 0) {
  11500. throw new Error('there must be at least one case');
  11501. }
  11502. var constructors = [];
  11503. var adt = {};
  11504. each(cases, function (acase, count) {
  11505. var keys$1 = keys(acase);
  11506. if (keys$1.length !== 1) {
  11507. throw new Error('one and only one name per case');
  11508. }
  11509. var key = keys$1[0];
  11510. var value = acase[key];
  11511. if (adt[key] !== undefined) {
  11512. throw new Error('duplicate key detected:' + key);
  11513. } else if (key === 'cata') {
  11514. throw new Error('cannot have a case named cata (sorry)');
  11515. } else if (!isArray(value)) {
  11516. throw new Error('case arguments must be an array');
  11517. }
  11518. constructors.push(key);
  11519. adt[key] = function () {
  11520. var argLength = arguments.length;
  11521. if (argLength !== value.length) {
  11522. throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
  11523. }
  11524. var args = new Array(argLength);
  11525. for (var i = 0; i < args.length; i++) {
  11526. args[i] = arguments[i];
  11527. }
  11528. var match = function (branches) {
  11529. var branchKeys = keys(branches);
  11530. if (constructors.length !== branchKeys.length) {
  11531. throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
  11532. }
  11533. var allReqd = forall(constructors, function (reqKey) {
  11534. return contains(branchKeys, reqKey);
  11535. });
  11536. if (!allReqd) {
  11537. throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
  11538. }
  11539. return branches[key].apply(null, args);
  11540. };
  11541. return {
  11542. fold: function () {
  11543. if (arguments.length !== cases.length) {
  11544. throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
  11545. }
  11546. var target = arguments[count];
  11547. return target.apply(null, args);
  11548. },
  11549. match: match,
  11550. log: function (label) {
  11551. domGlobals.console.log(label, {
  11552. constructors: constructors,
  11553. constructor: key,
  11554. params: args
  11555. });
  11556. }
  11557. };
  11558. };
  11559. });
  11560. return adt;
  11561. };
  11562. var Adt = { generate: generate$1 };
  11563. var create$3 = Immutable('start', 'soffset', 'finish', 'foffset');
  11564. var SimRange = { create: create$3 };
  11565. var adt = Adt.generate([
  11566. { before: ['element'] },
  11567. {
  11568. on: [
  11569. 'element',
  11570. 'offset'
  11571. ]
  11572. },
  11573. { after: ['element'] }
  11574. ]);
  11575. var cata = function (subject, onBefore, onOn, onAfter) {
  11576. return subject.fold(onBefore, onOn, onAfter);
  11577. };
  11578. var getStart = function (situ) {
  11579. return situ.fold(identity, identity, identity);
  11580. };
  11581. var before$3 = adt.before;
  11582. var on = adt.on;
  11583. var after$2 = adt.after;
  11584. var Situ = {
  11585. before: before$3,
  11586. on: on,
  11587. after: after$2,
  11588. cata: cata,
  11589. getStart: getStart
  11590. };
  11591. var adt$1 = Adt.generate([
  11592. { domRange: ['rng'] },
  11593. {
  11594. relative: [
  11595. 'startSitu',
  11596. 'finishSitu'
  11597. ]
  11598. },
  11599. {
  11600. exact: [
  11601. 'start',
  11602. 'soffset',
  11603. 'finish',
  11604. 'foffset'
  11605. ]
  11606. }
  11607. ]);
  11608. var exactFromRange = function (simRange) {
  11609. return adt$1.exact(simRange.start(), simRange.soffset(), simRange.finish(), simRange.foffset());
  11610. };
  11611. var getStart$1 = function (selection) {
  11612. return selection.match({
  11613. domRange: function (rng) {
  11614. return Element.fromDom(rng.startContainer);
  11615. },
  11616. relative: function (startSitu, finishSitu) {
  11617. return Situ.getStart(startSitu);
  11618. },
  11619. exact: function (start, soffset, finish, foffset) {
  11620. return start;
  11621. }
  11622. });
  11623. };
  11624. var domRange = adt$1.domRange;
  11625. var relative = adt$1.relative;
  11626. var exact = adt$1.exact;
  11627. var getWin = function (selection) {
  11628. var start = getStart$1(selection);
  11629. return defaultView(start);
  11630. };
  11631. var range = SimRange.create;
  11632. var Selection = {
  11633. domRange: domRange,
  11634. relative: relative,
  11635. exact: exact,
  11636. exactFromRange: exactFromRange,
  11637. getWin: getWin,
  11638. range: range
  11639. };
  11640. var browser$4 = detect$3().browser;
  11641. var clamp = function (offset, element) {
  11642. var max = isText$1(element) ? get$6(element).length : children(element).length + 1;
  11643. if (offset > max) {
  11644. return max;
  11645. } else if (offset < 0) {
  11646. return 0;
  11647. }
  11648. return offset;
  11649. };
  11650. var normalizeRng = function (rng) {
  11651. return Selection.range(rng.start(), clamp(rng.soffset(), rng.start()), rng.finish(), clamp(rng.foffset(), rng.finish()));
  11652. };
  11653. var isOrContains = function (root, elm) {
  11654. return !NodeType.isRestrictedNode(elm.dom()) && (contains$2(root, elm) || eq(root, elm));
  11655. };
  11656. var isRngInRoot = function (root) {
  11657. return function (rng) {
  11658. return isOrContains(root, rng.start()) && isOrContains(root, rng.finish());
  11659. };
  11660. };
  11661. var shouldStore = function (editor) {
  11662. return editor.inline === true || browser$4.isIE();
  11663. };
  11664. var nativeRangeToSelectionRange = function (r) {
  11665. return Selection.range(Element.fromDom(r.startContainer), r.startOffset, Element.fromDom(r.endContainer), r.endOffset);
  11666. };
  11667. var readRange = function (win) {
  11668. var selection = win.getSelection();
  11669. var rng = !selection || selection.rangeCount === 0 ? Option.none() : Option.from(selection.getRangeAt(0));
  11670. return rng.map(nativeRangeToSelectionRange);
  11671. };
  11672. var getBookmark$2 = function (root) {
  11673. var win = defaultView(root);
  11674. return readRange(win.dom()).filter(isRngInRoot(root));
  11675. };
  11676. var validate = function (root, bookmark) {
  11677. return Option.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng);
  11678. };
  11679. var bookmarkToNativeRng = function (bookmark) {
  11680. var rng = domGlobals.document.createRange();
  11681. try {
  11682. rng.setStart(bookmark.start().dom(), bookmark.soffset());
  11683. rng.setEnd(bookmark.finish().dom(), bookmark.foffset());
  11684. return Option.some(rng);
  11685. } catch (_) {
  11686. return Option.none();
  11687. }
  11688. };
  11689. var store = function (editor) {
  11690. var newBookmark = shouldStore(editor) ? getBookmark$2(Element.fromDom(editor.getBody())) : Option.none();
  11691. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
  11692. };
  11693. var storeNative = function (editor, rng) {
  11694. var root = Element.fromDom(editor.getBody());
  11695. var range = shouldStore(editor) ? Option.from(rng) : Option.none();
  11696. var newBookmark = range.map(nativeRangeToSelectionRange).filter(isRngInRoot(root));
  11697. editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
  11698. };
  11699. var getRng = function (editor) {
  11700. var bookmark = editor.bookmark ? editor.bookmark : Option.none();
  11701. return bookmark.bind(function (x) {
  11702. return validate(Element.fromDom(editor.getBody()), x);
  11703. }).bind(bookmarkToNativeRng);
  11704. };
  11705. var restore = function (editor) {
  11706. getRng(editor).each(function (rng) {
  11707. editor.selection.setRng(rng);
  11708. });
  11709. };
  11710. var SelectionBookmark = {
  11711. store: store,
  11712. storeNative: storeNative,
  11713. readRange: readRange,
  11714. restore: restore,
  11715. getRng: getRng,
  11716. getBookmark: getBookmark$2,
  11717. validate: validate
  11718. };
  11719. var isEditorUIElement = function (elm) {
  11720. var className = elm.className.toString();
  11721. return className.indexOf('tox-') !== -1 || className.indexOf('mce-') !== -1;
  11722. };
  11723. var FocusManager = { isEditorUIElement: isEditorUIElement };
  11724. var isManualNodeChange = function (e) {
  11725. return e.type === 'nodechange' && e.selectionChange;
  11726. };
  11727. var registerPageMouseUp = function (editor, throttledStore) {
  11728. var mouseUpPage = function () {
  11729. throttledStore.throttle();
  11730. };
  11731. DOMUtils$1.DOM.bind(domGlobals.document, 'mouseup', mouseUpPage);
  11732. editor.on('remove', function () {
  11733. DOMUtils$1.DOM.unbind(domGlobals.document, 'mouseup', mouseUpPage);
  11734. });
  11735. };
  11736. var registerFocusOut = function (editor) {
  11737. editor.on('focusout', function () {
  11738. SelectionBookmark.store(editor);
  11739. });
  11740. };
  11741. var registerMouseUp = function (editor, throttledStore) {
  11742. editor.on('mouseup touchend', function (e) {
  11743. throttledStore.throttle();
  11744. });
  11745. };
  11746. var registerEditorEvents = function (editor, throttledStore) {
  11747. var browser = detect$3().browser;
  11748. if (browser.isIE()) {
  11749. registerFocusOut(editor);
  11750. } else {
  11751. registerMouseUp(editor, throttledStore);
  11752. }
  11753. editor.on('keyup NodeChange', function (e) {
  11754. if (!isManualNodeChange(e)) {
  11755. SelectionBookmark.store(editor);
  11756. }
  11757. });
  11758. };
  11759. var register = function (editor) {
  11760. var throttledStore = first(function () {
  11761. SelectionBookmark.store(editor);
  11762. }, 0);
  11763. editor.on('init', function () {
  11764. if (editor.inline) {
  11765. registerPageMouseUp(editor, throttledStore);
  11766. }
  11767. registerEditorEvents(editor, throttledStore);
  11768. });
  11769. editor.on('remove', function () {
  11770. throttledStore.cancel();
  11771. });
  11772. };
  11773. var SelectionRestore = { register: register };
  11774. var documentFocusInHandler;
  11775. var DOM$1 = DOMUtils$1.DOM;
  11776. var isEditorUIElement$1 = function (elm) {
  11777. return FocusManager.isEditorUIElement(elm);
  11778. };
  11779. var isEditorContentAreaElement = function (elm) {
  11780. var classList = elm.classList;
  11781. if (classList !== undefined) {
  11782. return classList.contains('tox-edit-area') || classList.contains('tox-edit-area__iframe') || classList.contains('mce-content-body');
  11783. } else {
  11784. return false;
  11785. }
  11786. };
  11787. var isUIElement = function (editor, elm) {
  11788. var customSelector = editor ? editor.settings.custom_ui_selector : '';
  11789. var parent = DOM$1.getParent(elm, function (elm) {
  11790. return isEditorUIElement$1(elm) || (customSelector ? editor.dom.is(elm, customSelector) : false);
  11791. });
  11792. return parent !== null;
  11793. };
  11794. var getActiveElement = function () {
  11795. try {
  11796. return domGlobals.document.activeElement;
  11797. } catch (ex) {
  11798. return domGlobals.document.body;
  11799. }
  11800. };
  11801. var registerEvents = function (editorManager, e) {
  11802. var editor = e.editor;
  11803. SelectionRestore.register(editor);
  11804. editor.on('focusin', function () {
  11805. var self = this;
  11806. var focusedEditor = editorManager.focusedEditor;
  11807. if (focusedEditor !== self) {
  11808. if (focusedEditor) {
  11809. focusedEditor.fire('blur', { focusedEditor: self });
  11810. }
  11811. editorManager.setActive(self);
  11812. editorManager.focusedEditor = self;
  11813. self.fire('focus', { blurredEditor: focusedEditor });
  11814. self.focus(true);
  11815. }
  11816. });
  11817. editor.on('focusout', function () {
  11818. var self = this;
  11819. Delay.setEditorTimeout(self, function () {
  11820. var focusedEditor = editorManager.focusedEditor;
  11821. if (!isUIElement(self, getActiveElement()) && focusedEditor === self) {
  11822. self.fire('blur', { focusedEditor: null });
  11823. editorManager.focusedEditor = null;
  11824. }
  11825. });
  11826. });
  11827. if (!documentFocusInHandler) {
  11828. documentFocusInHandler = function (e) {
  11829. var activeEditor = editorManager.activeEditor;
  11830. var target;
  11831. target = e.target;
  11832. if (activeEditor && target.ownerDocument === domGlobals.document) {
  11833. if (target !== domGlobals.document.body && !isUIElement(activeEditor, target) && editorManager.focusedEditor === activeEditor) {
  11834. activeEditor.fire('blur', { focusedEditor: null });
  11835. editorManager.focusedEditor = null;
  11836. }
  11837. }
  11838. };
  11839. DOM$1.bind(domGlobals.document, 'focusin', documentFocusInHandler);
  11840. }
  11841. };
  11842. var unregisterDocumentEvents = function (editorManager, e) {
  11843. if (editorManager.focusedEditor === e.editor) {
  11844. editorManager.focusedEditor = null;
  11845. }
  11846. if (!editorManager.activeEditor) {
  11847. DOM$1.unbind(domGlobals.document, 'focusin', documentFocusInHandler);
  11848. documentFocusInHandler = null;
  11849. }
  11850. };
  11851. var setup$2 = function (editorManager) {
  11852. editorManager.on('AddEditor', curry(registerEvents, editorManager));
  11853. editorManager.on('RemoveEditor', curry(unregisterDocumentEvents, editorManager));
  11854. };
  11855. var FocusController = {
  11856. setup: setup$2,
  11857. isEditorUIElement: isEditorUIElement$1,
  11858. isEditorContentAreaElement: isEditorContentAreaElement,
  11859. isUIElement: isUIElement
  11860. };
  11861. var getContentEditableHost = function (editor, node) {
  11862. return editor.dom.getParent(node, function (node) {
  11863. return editor.dom.getContentEditable(node) === 'true';
  11864. });
  11865. };
  11866. var getCollapsedNode = function (rng) {
  11867. return rng.collapsed ? Option.from(getNode(rng.startContainer, rng.startOffset)).map(Element.fromDom) : Option.none();
  11868. };
  11869. var getFocusInElement = function (root, rng) {
  11870. return getCollapsedNode(rng).bind(function (node) {
  11871. if (isTableSection(node)) {
  11872. return Option.some(node);
  11873. } else if (contains$2(root, node) === false) {
  11874. return Option.some(root);
  11875. } else {
  11876. return Option.none();
  11877. }
  11878. });
  11879. };
  11880. var normalizeSelection = function (editor, rng) {
  11881. getFocusInElement(Element.fromDom(editor.getBody()), rng).bind(function (elm) {
  11882. return CaretFinder.firstPositionIn(elm.dom());
  11883. }).fold(function () {
  11884. editor.selection.normalize();
  11885. return;
  11886. }, function (caretPos) {
  11887. return editor.selection.setRng(caretPos.toRange());
  11888. });
  11889. };
  11890. var focusBody = function (body) {
  11891. if (body.setActive) {
  11892. try {
  11893. body.setActive();
  11894. } catch (ex) {
  11895. body.focus();
  11896. }
  11897. } else {
  11898. body.focus();
  11899. }
  11900. };
  11901. var hasElementFocus = function (elm) {
  11902. return hasFocus(elm) || search(elm).isSome();
  11903. };
  11904. var hasIframeFocus = function (editor) {
  11905. return editor.iframeElement && hasFocus(Element.fromDom(editor.iframeElement));
  11906. };
  11907. var hasInlineFocus = function (editor) {
  11908. var rawBody = editor.getBody();
  11909. return rawBody && hasElementFocus(Element.fromDom(rawBody));
  11910. };
  11911. var hasUiFocus = function (editor) {
  11912. return active().filter(function (elem) {
  11913. return !FocusController.isEditorContentAreaElement(elem.dom()) && FocusController.isUIElement(editor, elem.dom());
  11914. }).isSome();
  11915. };
  11916. var hasFocus$1 = function (editor) {
  11917. return editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor);
  11918. };
  11919. var hasEditorOrUiFocus = function (editor) {
  11920. return hasFocus$1(editor) || hasUiFocus(editor);
  11921. };
  11922. var focusEditor = function (editor) {
  11923. var selection = editor.selection;
  11924. var body = editor.getBody();
  11925. var rng = selection.getRng();
  11926. editor.quirks.refreshContentEditable();
  11927. if (editor.bookmark !== undefined && hasFocus$1(editor) === false) {
  11928. SelectionBookmark.getRng(editor).each(function (bookmarkRng) {
  11929. editor.selection.setRng(bookmarkRng);
  11930. rng = bookmarkRng;
  11931. });
  11932. }
  11933. var contentEditableHost = getContentEditableHost(editor, selection.getNode());
  11934. if (editor.$.contains(body, contentEditableHost)) {
  11935. focusBody(contentEditableHost);
  11936. normalizeSelection(editor, rng);
  11937. activateEditor(editor);
  11938. return;
  11939. }
  11940. if (!editor.inline) {
  11941. if (!Env.opera) {
  11942. focusBody(body);
  11943. }
  11944. editor.getWin().focus();
  11945. }
  11946. if (Env.gecko || editor.inline) {
  11947. focusBody(body);
  11948. normalizeSelection(editor, rng);
  11949. }
  11950. activateEditor(editor);
  11951. };
  11952. var activateEditor = function (editor) {
  11953. return editor.editorManager.setActive(editor);
  11954. };
  11955. var focus = function (editor, skipFocus) {
  11956. if (editor.removed) {
  11957. return;
  11958. }
  11959. skipFocus ? activateEditor(editor) : focusEditor(editor);
  11960. };
  11961. var EditorFocus = {
  11962. focus: focus,
  11963. hasFocus: hasFocus$1,
  11964. hasEditorOrUiFocus: hasEditorOrUiFocus
  11965. };
  11966. var defaultFormat$1 = 'html';
  11967. var isTreeNode = function (content) {
  11968. return content instanceof Node$1;
  11969. };
  11970. var moveSelection = function (editor) {
  11971. if (EditorFocus.hasFocus(editor)) {
  11972. CaretFinder.firstPositionIn(editor.getBody()).each(function (pos) {
  11973. var node = pos.getNode();
  11974. var caretPos = NodeType.isTable(node) ? CaretFinder.firstPositionIn(node).getOr(pos) : pos;
  11975. editor.selection.setRng(caretPos.toRange());
  11976. });
  11977. }
  11978. };
  11979. var setEditorHtml = function (editor, html) {
  11980. editor.dom.setHTML(editor.getBody(), html);
  11981. moveSelection(editor);
  11982. };
  11983. var setContentString = function (editor, body, content, args) {
  11984. var forcedRootBlockName, padd;
  11985. if (content.length === 0 || /^\s+$/.test(content)) {
  11986. padd = '<br data-mce-bogus="1">';
  11987. if (body.nodeName === 'TABLE') {
  11988. content = '<tr><td>' + padd + '</td></tr>';
  11989. } else if (/^(UL|OL)$/.test(body.nodeName)) {
  11990. content = '<li>' + padd + '</li>';
  11991. }
  11992. forcedRootBlockName = Settings.getForcedRootBlock(editor);
  11993. if (forcedRootBlockName && editor.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) {
  11994. content = padd;
  11995. content = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs, content);
  11996. } else if (!content) {
  11997. content = '<br data-mce-bogus="1">';
  11998. }
  11999. setEditorHtml(editor, content);
  12000. editor.fire('SetContent', args);
  12001. } else {
  12002. if (args.format !== 'raw') {
  12003. content = Serializer({ validate: editor.validate }, editor.schema).serialize(editor.parser.parse(content, {
  12004. isRootContent: true,
  12005. insert: true
  12006. }));
  12007. }
  12008. args.content = isWsPreserveElement(Element.fromDom(body)) ? content : Tools.trim(content);
  12009. setEditorHtml(editor, args.content);
  12010. if (!args.no_events) {
  12011. editor.fire('SetContent', args);
  12012. }
  12013. }
  12014. return args.content;
  12015. };
  12016. var setContentTree = function (editor, body, content, args) {
  12017. filter$2(editor.parser.getNodeFilters(), editor.parser.getAttributeFilters(), content);
  12018. var html = Serializer({ validate: editor.validate }, editor.schema).serialize(content);
  12019. args.content = isWsPreserveElement(Element.fromDom(body)) ? html : Tools.trim(html);
  12020. setEditorHtml(editor, args.content);
  12021. if (!args.no_events) {
  12022. editor.fire('SetContent', args);
  12023. }
  12024. return content;
  12025. };
  12026. var setContent = function (editor, content, args) {
  12027. if (args === void 0) {
  12028. args = {};
  12029. }
  12030. args.format = args.format ? args.format : defaultFormat$1;
  12031. args.set = true;
  12032. args.content = isTreeNode(content) ? '' : content;
  12033. if (!isTreeNode(content) && !args.no_events) {
  12034. editor.fire('BeforeSetContent', args);
  12035. content = args.content;
  12036. }
  12037. return Option.from(editor.getBody()).fold(constant(content), function (body) {
  12038. return isTreeNode(content) ? setContentTree(editor, body, content, args) : setContentString(editor, body, content, args);
  12039. });
  12040. };
  12041. var firePreProcess = function (editor, args) {
  12042. return editor.fire('PreProcess', args);
  12043. };
  12044. var firePostProcess = function (editor, args) {
  12045. return editor.fire('PostProcess', args);
  12046. };
  12047. var fireRemove = function (editor) {
  12048. return editor.fire('remove');
  12049. };
  12050. var fireDetach = function (editor) {
  12051. return editor.fire('detach');
  12052. };
  12053. var fireSwitchMode = function (editor, mode) {
  12054. return editor.fire('SwitchMode', { mode: mode });
  12055. };
  12056. var fireObjectResizeStart = function (editor, target, width, height) {
  12057. editor.fire('ObjectResizeStart', {
  12058. target: target,
  12059. width: width,
  12060. height: height
  12061. });
  12062. };
  12063. var fireObjectResized = function (editor, target, width, height) {
  12064. editor.fire('ObjectResized', {
  12065. target: target,
  12066. width: width,
  12067. height: height
  12068. });
  12069. };
  12070. var Events = {
  12071. firePreProcess: firePreProcess,
  12072. firePostProcess: firePostProcess,
  12073. fireRemove: fireRemove,
  12074. fireDetach: fireDetach,
  12075. fireSwitchMode: fireSwitchMode,
  12076. fireObjectResizeStart: fireObjectResizeStart,
  12077. fireObjectResized: fireObjectResized
  12078. };
  12079. var DOM$2 = DOMUtils$1.DOM;
  12080. var restoreOriginalStyles = function (editor) {
  12081. DOM$2.setStyle(editor.id, 'display', editor.orgDisplay);
  12082. };
  12083. var safeDestroy = function (x) {
  12084. return Option.from(x).each(function (x) {
  12085. return x.destroy();
  12086. });
  12087. };
  12088. var clearDomReferences = function (editor) {
  12089. editor.contentAreaContainer = editor.formElement = editor.container = editor.editorContainer = null;
  12090. editor.bodyElement = editor.contentDocument = editor.contentWindow = null;
  12091. editor.iframeElement = editor.targetElm = null;
  12092. if (editor.selection) {
  12093. editor.selection = editor.selection.win = editor.selection.dom = editor.selection.dom.doc = null;
  12094. }
  12095. };
  12096. var restoreForm = function (editor) {
  12097. var form = editor.formElement;
  12098. if (form) {
  12099. if (form._mceOldSubmit) {
  12100. form.submit = form._mceOldSubmit;
  12101. form._mceOldSubmit = null;
  12102. }
  12103. DOM$2.unbind(form, 'submit reset', editor.formEventDelegate);
  12104. }
  12105. };
  12106. var remove$6 = function (editor) {
  12107. if (!editor.removed) {
  12108. var _selectionOverrides = editor._selectionOverrides, editorUpload = editor.editorUpload;
  12109. var body = editor.getBody();
  12110. var element = editor.getElement();
  12111. if (body) {
  12112. editor.save({ is_removing: true });
  12113. }
  12114. editor.removed = true;
  12115. editor.unbindAllNativeEvents();
  12116. if (editor.hasHiddenInput && element) {
  12117. DOM$2.remove(element.nextSibling);
  12118. }
  12119. Events.fireRemove(editor);
  12120. editor.editorManager.remove(editor);
  12121. if (!editor.inline && body) {
  12122. restoreOriginalStyles(editor);
  12123. }
  12124. Events.fireDetach(editor);
  12125. DOM$2.remove(editor.getContainer());
  12126. safeDestroy(_selectionOverrides);
  12127. safeDestroy(editorUpload);
  12128. editor.destroy();
  12129. }
  12130. };
  12131. var destroy = function (editor, automatic) {
  12132. var selection = editor.selection, dom = editor.dom;
  12133. if (editor.destroyed) {
  12134. return;
  12135. }
  12136. if (!automatic && !editor.removed) {
  12137. editor.remove();
  12138. return;
  12139. }
  12140. if (!automatic) {
  12141. editor.editorManager.off('beforeunload', editor._beforeUnload);
  12142. if (editor.theme && editor.theme.destroy) {
  12143. editor.theme.destroy();
  12144. }
  12145. safeDestroy(selection);
  12146. safeDestroy(dom);
  12147. }
  12148. restoreForm(editor);
  12149. clearDomReferences(editor);
  12150. editor.destroyed = true;
  12151. };
  12152. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  12153. var shallow$1 = function (old, nu) {
  12154. return nu;
  12155. };
  12156. var deep$1 = function (old, nu) {
  12157. var bothObjects = isObject(old) && isObject(nu);
  12158. return bothObjects ? deepMerge(old, nu) : nu;
  12159. };
  12160. var baseMerge = function (merger) {
  12161. return function () {
  12162. var objects = new Array(arguments.length);
  12163. for (var i = 0; i < objects.length; i++) {
  12164. objects[i] = arguments[i];
  12165. }
  12166. if (objects.length === 0) {
  12167. throw new Error('Can\'t merge zero objects');
  12168. }
  12169. var ret = {};
  12170. for (var j = 0; j < objects.length; j++) {
  12171. var curObject = objects[j];
  12172. for (var key in curObject) {
  12173. if (hasOwnProperty$2.call(curObject, key)) {
  12174. ret[key] = merger(ret[key], curObject[key]);
  12175. }
  12176. }
  12177. }
  12178. return ret;
  12179. };
  12180. };
  12181. var deepMerge = baseMerge(deep$1);
  12182. var merge = baseMerge(shallow$1);
  12183. var sectionResult = Immutable('sections', 'settings');
  12184. var deviceDetection = detect$3().deviceType;
  12185. var isTouch = deviceDetection.isTouch();
  12186. var isPhone = deviceDetection.isPhone();
  12187. var isTablet = deviceDetection.isTablet();
  12188. var legacyMobilePlugins = [
  12189. 'lists',
  12190. 'autolink',
  12191. 'autosave'
  12192. ];
  12193. var defaultTouchSettings = {
  12194. table_grid: false,
  12195. object_resizing: false,
  12196. resize: false
  12197. };
  12198. var normalizePlugins = function (plugins) {
  12199. var pluginNames = isArray(plugins) ? plugins.join(' ') : plugins;
  12200. var trimmedPlugins = map(isString(pluginNames) ? pluginNames.split(' ') : [], trim);
  12201. return filter(trimmedPlugins, function (item) {
  12202. return item.length > 0;
  12203. });
  12204. };
  12205. var filterLegacyMobilePlugins = function (plugins) {
  12206. return filter(plugins, curry(contains, legacyMobilePlugins));
  12207. };
  12208. var extractSections = function (keys, settings) {
  12209. var result = bifilter(settings, function (value, key) {
  12210. return contains(keys, key);
  12211. });
  12212. return sectionResult(result.t, result.f);
  12213. };
  12214. var getSection = function (sectionResult, name, defaults) {
  12215. if (defaults === void 0) {
  12216. defaults = {};
  12217. }
  12218. var sections = sectionResult.sections();
  12219. var sectionSettings = sections.hasOwnProperty(name) ? sections[name] : {};
  12220. return Tools.extend({}, defaults, sectionSettings);
  12221. };
  12222. var hasSection = function (sectionResult, name) {
  12223. return sectionResult.sections().hasOwnProperty(name);
  12224. };
  12225. var isSectionTheme = function (sectionResult, name, theme) {
  12226. var section = sectionResult.sections();
  12227. return hasSection(sectionResult, name) && section[name].theme === theme;
  12228. };
  12229. var getSectionConfig = function (sectionResult, name) {
  12230. return hasSection(sectionResult, name) ? sectionResult.sections()[name] : {};
  12231. };
  12232. var getDefaultSettings = function (id, documentBaseUrl, isTouch, editor) {
  12233. var baseDefaults = {
  12234. id: id,
  12235. theme: 'silver',
  12236. toolbar_drawer: 'floating',
  12237. plugins: '',
  12238. document_base_url: documentBaseUrl,
  12239. add_form_submit_trigger: true,
  12240. submit_patch: true,
  12241. add_unload_trigger: true,
  12242. convert_urls: true,
  12243. relative_urls: true,
  12244. remove_script_host: true,
  12245. object_resizing: true,
  12246. doctype: '<!DOCTYPE html>',
  12247. visual: true,
  12248. font_size_legacy_values: 'xx-small,small,medium,large,x-large,xx-large,300%',
  12249. forced_root_block: 'p',
  12250. hidden_input: true,
  12251. inline_styles: true,
  12252. convert_fonts_to_spans: true,
  12253. indent: true,
  12254. 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',
  12255. 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',
  12256. entity_encoding: 'named',
  12257. url_converter: editor.convertURL,
  12258. url_converter_scope: editor
  12259. };
  12260. return __assign(__assign({}, baseDefaults), isTouch ? defaultTouchSettings : {});
  12261. };
  12262. var getDefaultMobileSettings = function (isPhone) {
  12263. var defaultMobileSettings = {
  12264. resize: false,
  12265. toolbar_drawer: 'scrolling',
  12266. toolbar_sticky: false
  12267. };
  12268. var defaultPhoneSettings = { menubar: false };
  12269. return __assign(__assign(__assign({}, defaultTouchSettings), defaultMobileSettings), isPhone ? defaultPhoneSettings : {});
  12270. };
  12271. var getExternalPlugins = function (overrideSettings, settings) {
  12272. var userDefinedExternalPlugins = settings.external_plugins ? settings.external_plugins : {};
  12273. if (overrideSettings && overrideSettings.external_plugins) {
  12274. return Tools.extend({}, overrideSettings.external_plugins, userDefinedExternalPlugins);
  12275. } else {
  12276. return userDefinedExternalPlugins;
  12277. }
  12278. };
  12279. var combinePlugins = function (forcedPlugins, plugins) {
  12280. return [].concat(normalizePlugins(forcedPlugins)).concat(normalizePlugins(plugins));
  12281. };
  12282. var processPlugins = function (isMobileDevice, sectionResult, defaultOverrideSettings, settings) {
  12283. var forcedPlugins = normalizePlugins(defaultOverrideSettings.forced_plugins);
  12284. var desktopPlugins = normalizePlugins(settings.plugins);
  12285. var mobileConfig = getSectionConfig(sectionResult, 'mobile');
  12286. var mobilePlugins = mobileConfig.plugins ? normalizePlugins(mobileConfig.plugins) : desktopPlugins;
  12287. var platformPlugins = isMobileDevice && isSectionTheme(sectionResult, 'mobile', 'mobile') ? filterLegacyMobilePlugins(mobilePlugins) : isMobileDevice && hasSection(sectionResult, 'mobile') ? mobilePlugins : desktopPlugins;
  12288. var combinedPlugins = combinePlugins(forcedPlugins, platformPlugins);
  12289. return Tools.extend(settings, { plugins: combinedPlugins.join(' ') });
  12290. };
  12291. var isOnMobile = function (isMobileDevice, sectionResult) {
  12292. return isMobileDevice && hasSection(sectionResult, 'mobile');
  12293. };
  12294. var combineSettings = function (isMobileDevice, isPhone, defaultSettings, defaultOverrideSettings, settings) {
  12295. var defaultDeviceSettings = isMobileDevice ? { mobile: getDefaultMobileSettings(isPhone) } : {};
  12296. var sectionResult = extractSections(['mobile'], deepMerge(defaultDeviceSettings, settings));
  12297. var extendedSettings = Tools.extend(defaultSettings, defaultOverrideSettings, sectionResult.settings(), isOnMobile(isMobileDevice, sectionResult) ? getSection(sectionResult, 'mobile') : {}, {
  12298. validate: true,
  12299. external_plugins: getExternalPlugins(defaultOverrideSettings, sectionResult.settings())
  12300. });
  12301. return processPlugins(isMobileDevice, sectionResult, defaultOverrideSettings, extendedSettings);
  12302. };
  12303. var getEditorSettings = function (editor, id, documentBaseUrl, defaultOverrideSettings, settings) {
  12304. var defaultSettings = getDefaultSettings(id, documentBaseUrl, isTouch, editor);
  12305. return combineSettings(isPhone || isTablet, isPhone, defaultSettings, defaultOverrideSettings, settings);
  12306. };
  12307. var getFiltered = function (predicate, editor, name) {
  12308. return Option.from(editor.settings[name]).filter(predicate);
  12309. };
  12310. var getParamObject = function (value) {
  12311. var output = {};
  12312. if (typeof value === 'string') {
  12313. each(value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(','), function (val) {
  12314. var arr = val.split('=');
  12315. if (arr.length > 1) {
  12316. output[Tools.trim(arr[0])] = Tools.trim(arr[1]);
  12317. } else {
  12318. output[Tools.trim(arr[0])] = Tools.trim(arr[0]);
  12319. }
  12320. });
  12321. } else {
  12322. output = value;
  12323. }
  12324. return output;
  12325. };
  12326. var isArrayOf = function (p) {
  12327. return function (a) {
  12328. return isArray(a) && forall(a, p);
  12329. };
  12330. };
  12331. var getParam = function (editor, name, defaultVal, type) {
  12332. var value = name in editor.settings ? editor.settings[name] : defaultVal;
  12333. if (type === 'hash') {
  12334. return getParamObject(value);
  12335. } else if (type === 'string') {
  12336. return getFiltered(isString, editor, name).getOr(defaultVal);
  12337. } else if (type === 'number') {
  12338. return getFiltered(isNumber, editor, name).getOr(defaultVal);
  12339. } else if (type === 'boolean') {
  12340. return getFiltered(isBoolean, editor, name).getOr(defaultVal);
  12341. } else if (type === 'object') {
  12342. return getFiltered(isObject, editor, name).getOr(defaultVal);
  12343. } else if (type === 'array') {
  12344. return getFiltered(isArray, editor, name).getOr(defaultVal);
  12345. } else if (type === 'string[]') {
  12346. return getFiltered(isArrayOf(isString), editor, name).getOr(defaultVal);
  12347. } else if (type === 'function') {
  12348. return getFiltered(isFunction, editor, name).getOr(defaultVal);
  12349. } else {
  12350. return value;
  12351. }
  12352. };
  12353. var getProp = function (propName, elm) {
  12354. var rawElm = elm.dom();
  12355. return rawElm[propName];
  12356. };
  12357. var getComputedSizeProp = function (propName, elm) {
  12358. return parseInt(get$2(elm, propName), 10);
  12359. };
  12360. var getClientWidth = curry(getProp, 'clientWidth');
  12361. var getClientHeight = curry(getProp, 'clientHeight');
  12362. var getMarginTop = curry(getComputedSizeProp, 'margin-top');
  12363. var getMarginLeft = curry(getComputedSizeProp, 'margin-left');
  12364. var getBoundingClientRect$1 = function (elm) {
  12365. return elm.dom().getBoundingClientRect();
  12366. };
  12367. var isInsideElementContentArea = function (bodyElm, clientX, clientY) {
  12368. var clientWidth = getClientWidth(bodyElm);
  12369. var clientHeight = getClientHeight(bodyElm);
  12370. return clientX >= 0 && clientY >= 0 && clientX <= clientWidth && clientY <= clientHeight;
  12371. };
  12372. var transpose = function (inline, elm, clientX, clientY) {
  12373. var clientRect = getBoundingClientRect$1(elm);
  12374. var deltaX = inline ? clientRect.left + elm.dom().clientLeft + getMarginLeft(elm) : 0;
  12375. var deltaY = inline ? clientRect.top + elm.dom().clientTop + getMarginTop(elm) : 0;
  12376. var x = clientX - deltaX;
  12377. var y = clientY - deltaY;
  12378. return {
  12379. x: x,
  12380. y: y
  12381. };
  12382. };
  12383. var isXYInContentArea = function (editor, clientX, clientY) {
  12384. var bodyElm = Element.fromDom(editor.getBody());
  12385. var targetElm = editor.inline ? bodyElm : documentElement(bodyElm);
  12386. var transposedPoint = transpose(editor.inline, targetElm, clientX, clientY);
  12387. return isInsideElementContentArea(targetElm, transposedPoint.x, transposedPoint.y);
  12388. };
  12389. var fromDomSafe = function (node) {
  12390. return Option.from(node).map(Element.fromDom);
  12391. };
  12392. var isEditorAttachedToDom = function (editor) {
  12393. var rawContainer = editor.inline ? editor.getBody() : editor.getContentAreaContainer();
  12394. return fromDomSafe(rawContainer).map(function (container) {
  12395. return contains$2(owner(container), container);
  12396. }).getOr(false);
  12397. };
  12398. var EditorView = {
  12399. isXYInContentArea: isXYInContentArea,
  12400. isEditorAttachedToDom: isEditorAttachedToDom
  12401. };
  12402. function NotificationManagerImpl() {
  12403. var unimplemented = function () {
  12404. throw new Error('Theme did not provide a NotificationManager implementation.');
  12405. };
  12406. return {
  12407. open: unimplemented,
  12408. close: unimplemented,
  12409. reposition: unimplemented,
  12410. getArgs: unimplemented
  12411. };
  12412. }
  12413. function NotificationManager(editor) {
  12414. var notifications = [];
  12415. var getImplementation = function () {
  12416. var theme = editor.theme;
  12417. return theme && theme.getNotificationManagerImpl ? theme.getNotificationManagerImpl() : NotificationManagerImpl();
  12418. };
  12419. var getTopNotification = function () {
  12420. return Option.from(notifications[0]);
  12421. };
  12422. var isEqual = function (a, b) {
  12423. return a.type === b.type && a.text === b.text && !a.progressBar && !a.timeout && !b.progressBar && !b.timeout;
  12424. };
  12425. var reposition = function () {
  12426. if (notifications.length > 0) {
  12427. getImplementation().reposition(notifications);
  12428. }
  12429. };
  12430. var addNotification = function (notification) {
  12431. notifications.push(notification);
  12432. };
  12433. var closeNotification = function (notification) {
  12434. findIndex(notifications, function (otherNotification) {
  12435. return otherNotification === notification;
  12436. }).each(function (index) {
  12437. notifications.splice(index, 1);
  12438. });
  12439. };
  12440. var open = function (spec) {
  12441. if (editor.removed || !EditorView.isEditorAttachedToDom(editor)) {
  12442. return;
  12443. }
  12444. return find(notifications, function (notification) {
  12445. return isEqual(getImplementation().getArgs(notification), spec);
  12446. }).getOrThunk(function () {
  12447. editor.editorManager.setActive(editor);
  12448. var notification = getImplementation().open(spec, function () {
  12449. closeNotification(notification);
  12450. reposition();
  12451. });
  12452. addNotification(notification);
  12453. reposition();
  12454. return notification;
  12455. });
  12456. };
  12457. var close = function () {
  12458. getTopNotification().each(function (notification) {
  12459. getImplementation().close(notification);
  12460. closeNotification(notification);
  12461. reposition();
  12462. });
  12463. };
  12464. var getNotifications = function () {
  12465. return notifications;
  12466. };
  12467. var registerEvents = function (editor) {
  12468. editor.on('SkinLoaded', function () {
  12469. var serviceMessage = editor.settings.service_message;
  12470. if (serviceMessage) {
  12471. open({
  12472. text: serviceMessage,
  12473. type: 'warning',
  12474. timeout: 0
  12475. });
  12476. }
  12477. });
  12478. editor.on('ResizeEditor ResizeWindow NodeChange', function () {
  12479. Delay.requestAnimationFrame(reposition);
  12480. });
  12481. editor.on('remove', function () {
  12482. each(notifications.slice(), function (notification) {
  12483. getImplementation().close(notification);
  12484. });
  12485. });
  12486. };
  12487. registerEvents(editor);
  12488. return {
  12489. open: open,
  12490. close: close,
  12491. getNotifications: getNotifications
  12492. };
  12493. }
  12494. function WindowManagerImpl () {
  12495. var unimplemented = function () {
  12496. throw new Error('Theme did not provide a WindowManager implementation.');
  12497. };
  12498. return {
  12499. open: unimplemented,
  12500. openUrl: unimplemented,
  12501. alert: unimplemented,
  12502. confirm: unimplemented,
  12503. close: unimplemented,
  12504. getParams: unimplemented,
  12505. setParams: unimplemented
  12506. };
  12507. }
  12508. var WindowManager = function (editor) {
  12509. var dialogs = [];
  12510. var getImplementation = function () {
  12511. var theme = editor.theme;
  12512. return theme && theme.getWindowManagerImpl ? theme.getWindowManagerImpl() : WindowManagerImpl();
  12513. };
  12514. var funcBind = function (scope, f) {
  12515. return function () {
  12516. return f ? f.apply(scope, arguments) : undefined;
  12517. };
  12518. };
  12519. var fireOpenEvent = function (dialog) {
  12520. editor.fire('OpenWindow', { dialog: dialog });
  12521. };
  12522. var fireCloseEvent = function (dialog) {
  12523. editor.fire('CloseWindow', { dialog: dialog });
  12524. };
  12525. var addDialog = function (dialog) {
  12526. dialogs.push(dialog);
  12527. fireOpenEvent(dialog);
  12528. };
  12529. var closeDialog = function (dialog) {
  12530. fireCloseEvent(dialog);
  12531. dialogs = filter(dialogs, function (otherDialog) {
  12532. return otherDialog !== dialog;
  12533. });
  12534. if (dialogs.length === 0) {
  12535. editor.focus();
  12536. }
  12537. };
  12538. var getTopDialog = function () {
  12539. return Option.from(dialogs[dialogs.length - 1]);
  12540. };
  12541. var storeSelectionAndOpenDialog = function (openDialog) {
  12542. editor.editorManager.setActive(editor);
  12543. SelectionBookmark.store(editor);
  12544. var dialog = openDialog();
  12545. addDialog(dialog);
  12546. return dialog;
  12547. };
  12548. var open = function (args, params) {
  12549. return storeSelectionAndOpenDialog(function () {
  12550. return getImplementation().open(args, params, closeDialog);
  12551. });
  12552. };
  12553. var openUrl = function (args) {
  12554. return storeSelectionAndOpenDialog(function () {
  12555. return getImplementation().openUrl(args, closeDialog);
  12556. });
  12557. };
  12558. var alert = function (message, callback, scope) {
  12559. getImplementation().alert(message, funcBind(scope ? scope : this, callback));
  12560. };
  12561. var confirm = function (message, callback, scope) {
  12562. getImplementation().confirm(message, funcBind(scope ? scope : this, callback));
  12563. };
  12564. var close = function () {
  12565. getTopDialog().each(function (dialog) {
  12566. getImplementation().close(dialog);
  12567. closeDialog(dialog);
  12568. });
  12569. };
  12570. editor.on('remove', function () {
  12571. each(dialogs, function (dialog) {
  12572. getImplementation().close(dialog);
  12573. });
  12574. });
  12575. return {
  12576. open: open,
  12577. openUrl: openUrl,
  12578. alert: alert,
  12579. confirm: confirm,
  12580. close: close
  12581. };
  12582. };
  12583. var displayNotification = function (editor, message) {
  12584. editor.notificationManager.open({
  12585. type: 'error',
  12586. text: message
  12587. });
  12588. };
  12589. var displayError = function (editor, message) {
  12590. if (editor._skinLoaded) {
  12591. displayNotification(editor, message);
  12592. } else {
  12593. editor.on('SkinLoaded', function () {
  12594. displayNotification(editor, message);
  12595. });
  12596. }
  12597. };
  12598. var uploadError = function (editor, message) {
  12599. displayError(editor, I18n.translate([
  12600. 'Failed to upload image: {0}',
  12601. message
  12602. ]));
  12603. };
  12604. var logError = function (msg) {
  12605. domGlobals.console.error(msg);
  12606. };
  12607. var createLoadError = function (type, url, name) {
  12608. return name ? 'Failed to load ' + type + ': ' + name + ' from url ' + url : 'Failed to load ' + type + ' url: ' + url;
  12609. };
  12610. var pluginLoadError = function (url, name) {
  12611. logError(createLoadError('plugin', url, name));
  12612. };
  12613. var iconsLoadError = function (url, name) {
  12614. logError(createLoadError('icons', url, name));
  12615. };
  12616. var languageLoadError = function (url, name) {
  12617. logError(createLoadError('language', url, name));
  12618. };
  12619. var pluginInitError = function (editor, name, err) {
  12620. var message = I18n.translate([
  12621. 'Failed to initialize plugin: {0}',
  12622. name
  12623. ]);
  12624. initError(message, err);
  12625. displayError(editor, message);
  12626. };
  12627. var initError = function (message) {
  12628. var x = [];
  12629. for (var _i = 1; _i < arguments.length; _i++) {
  12630. x[_i - 1] = arguments[_i];
  12631. }
  12632. var console = domGlobals.window.console;
  12633. if (console) {
  12634. if (console.error) {
  12635. console.error.apply(console, arguments);
  12636. } else {
  12637. console.log.apply(console, arguments);
  12638. }
  12639. }
  12640. };
  12641. var ErrorReporter = {
  12642. pluginLoadError: pluginLoadError,
  12643. iconsLoadError: iconsLoadError,
  12644. languageLoadError: languageLoadError,
  12645. pluginInitError: pluginInitError,
  12646. uploadError: uploadError,
  12647. displayError: displayError,
  12648. initError: initError
  12649. };
  12650. var getAll = function () {
  12651. return {
  12652. 'accessibility-check': '<svg width="24" height="24"><path d="M12 2a2 2 0 0 1 2 2 2 2 0 0 1-2 2 2 2 0 0 1-2-2c0-1.1.9-2 2-2zm8 7h-5v12c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-5c0-.6-.4-1-1-1a1 1 0 0 0-1 1v5c0 .6-.4 1-1 1a1 1 0 0 1-1-1V9H4a1 1 0 1 1 0-2h16c.6 0 1 .4 1 1s-.4 1-1 1z" fill-rule="nonzero"/></svg>',
  12653. 'action-next': '<svg width="24" height="24"><path fill-rule="nonzero" d="M5.7 7.3a1 1 0 0 0-1.4 1.4l7.7 7.7 7.7-7.7a1 1 0 1 0-1.4-1.4L12 13.6 5.7 7.3z"/></svg>',
  12654. 'action-prev': '<svg width="24" height="24"><path fill-rule="nonzero" d="M18.3 15.7a1 1 0 0 0 1.4-1.4L12 6.6l-7.7 7.7a1 1 0 0 0 1.4 1.4L12 9.4l6.3 6.3z"/></svg>',
  12655. 'align-center': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm3 4h8c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 1 1 0-2zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2zm-3-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12656. 'align-justify': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0 4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12657. 'align-left': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 4h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12658. 'align-none': '<svg width="24" height="24"><path d="M14.2 5L13 7H5a1 1 0 1 1 0-2h9.2zm4 0h.8a1 1 0 0 1 0 2h-2l1.2-2zm-6.4 4l-1.2 2H5a1 1 0 0 1 0-2h6.8zm4 0H19a1 1 0 0 1 0 2h-4.4l1.2-2zm-6.4 4l-1.2 2H5a1 1 0 0 1 0-2h4.4zm4 0H19a1 1 0 0 1 0 2h-6.8l1.2-2zM7 17l-1.2 2H5a1 1 0 0 1 0-2h2zm4 0h8a1 1 0 0 1 0 2H9.8l1.2-2zm5.2-13.5l1.3.7-9.7 16.3-1.3-.7 9.7-16.3z" fill-rule="evenodd"/></svg>',
  12659. 'align-right': '<svg width="24" height="24"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm6 4h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm-6-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12660. 'arrow-left': '<svg width="24" height="24"><path d="M5.6 13l12 6a1 1 0 0 0 1.4-1V6a1 1 0 0 0-1.4-.9l-12 6a1 1 0 0 0 0 1.8z" fill-rule="evenodd"/></svg>',
  12661. 'arrow-right': '<svg width="24" height="24"><path d="M18.5 13l-12 6A1 1 0 0 1 5 18V6a1 1 0 0 1 1.4-.9l12 6a1 1 0 0 1 0 1.8z" fill-rule="evenodd"/></svg>',
  12662. 'bold': '<svg width="24" height="24"><path d="M7.8 19c-.3 0-.5 0-.6-.2l-.2-.5V5.7c0-.2 0-.4.2-.5l.6-.2h5c1.5 0 2.7.3 3.5 1 .7.6 1.1 1.4 1.1 2.5a3 3 0 0 1-.6 1.9c-.4.6-1 1-1.6 1.2.4.1.9.3 1.3.6s.8.7 1 1.2c.4.4.5 1 .5 1.6 0 1.3-.4 2.3-1.3 3-.8.7-2.1 1-3.8 1H7.8zm5-8.3c.6 0 1.2-.1 1.6-.5.4-.3.6-.7.6-1.3 0-1.1-.8-1.7-2.3-1.7H9.3v3.5h3.4zm.5 6c.7 0 1.3-.1 1.7-.4.4-.4.6-.9.6-1.5s-.2-1-.7-1.4c-.4-.3-1-.4-2-.4H9.4v3.8h4z" fill-rule="evenodd"/></svg>',
  12663. 'bookmark': '<svg width="24" height="24"><path d="M6 4v17l6-4 6 4V4c0-.6-.4-1-1-1H7a1 1 0 0 0-1 1z" fill-rule="nonzero"/></svg>',
  12664. 'border-width': '<svg width="24" height="24"><path d="M5 14.8h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2zm-.5 3.7h15c.3 0 .5.2.5.5s-.2.5-.5.5h-15a.5.5 0 1 1 0-1zm.5-8.3h14c.6 0 1 .4 1 1v1c0 .5-.4 1-1 1H5a1 1 0 0 1-1-1v-1c0-.6.4-1 1-1zm0-5.7h14c.6 0 1 .4 1 1v2c0 .6-.4 1-1 1H5a1 1 0 0 1-1-1v-2c0-.6.4-1 1-1z" fill-rule="evenodd"/></svg>',
  12665. 'brightness': '<svg width="24" height="24"><path d="M12 17c.3 0 .5.1.7.3.2.2.3.4.3.7v1c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3 1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7v-1c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3zm0-10a1 1 0 0 1-.7-.3A1 1 0 0 1 11 6V5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3.3 0 .5.1.7.3.2.2.3.4.3.7v1c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3zm7 4c.3 0 .5.1.7.3.2.2.3.4.3.7 0 .3-.1.5-.3.7a1 1 0 0 1-.7.3h-1a1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h1zM7 12c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3H5a1 1 0 0 1-.7-.3A1 1 0 0 1 4 12c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h1c.3 0 .5.1.7.3.2.2.3.4.3.7zm10 3.5l.7.8c.2.1.3.4.3.6 0 .3-.1.6-.3.8a1 1 0 0 1-.8.3 1 1 0 0 1-.6-.3l-.8-.7a1 1 0 0 1-.3-.8c0-.2.1-.5.3-.7a1 1 0 0 1 1.4 0zm-10-7l-.7-.8a1 1 0 0 1-.3-.6c0-.3.1-.6.3-.8.2-.2.5-.3.8-.3.2 0 .5.1.7.3l.7.7c.2.2.3.5.3.8 0 .2-.1.5-.3.7a1 1 0 0 1-.7.3 1 1 0 0 1-.8-.3zm10 0a1 1 0 0 1-.8.3 1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7c0-.3.1-.6.3-.8l.8-.7c.1-.2.4-.3.6-.3.3 0 .6.1.8.3.2.2.3.5.3.8 0 .2-.1.5-.3.7l-.7.7zm-10 7c.2-.2.5-.3.8-.3.2 0 .5.1.7.3a1 1 0 0 1 0 1.4l-.8.8a1 1 0 0 1-.6.3 1 1 0 0 1-.8-.3 1 1 0 0 1-.3-.8c0-.2.1-.5.3-.6l.7-.8zM12 8a4 4 0 0 1 3.7 2.4 4 4 0 0 1 0 3.2A4 4 0 0 1 12 16a4 4 0 0 1-3.7-2.4 4 4 0 0 1 0-3.2A4 4 0 0 1 12 8zm0 6.5c.7 0 1.3-.2 1.8-.7.5-.5.7-1.1.7-1.8s-.2-1.3-.7-1.8c-.5-.5-1.1-.7-1.8-.7s-1.3.2-1.8.7c-.5.5-.7 1.1-.7 1.8s.2 1.3.7 1.8c.5.5 1.1.7 1.8.7z" fill-rule="evenodd"/></svg>',
  12666. 'browse': '<svg width="24" height="24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-4v-2h4V8H5v10h4v2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm-8 9.4l-2.3 2.3a1 1 0 1 1-1.4-1.4l4-4a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1-1.4 1.4L13 13.4V20a1 1 0 0 1-2 0v-6.6z" fill-rule="nonzero"/></svg>',
  12667. 'cancel': '<svg width="24" height="24"><path d="M12 4.6a7.4 7.4 0 1 1 0 14.8 7.4 7.4 0 0 1 0-14.8zM12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zm0 8L14.8 8l1 1.1-2.7 2.8 2.7 2.7-1.1 1.1-2.7-2.7-2.7 2.7-1-1.1 2.6-2.7-2.7-2.7 1-1.1 2.8 2.7z" fill-rule="nonzero"/></svg>',
  12668. 'change-case': '<svg width="24" height="24"><path d="M18.4 18.2v-.6c-.5.8-1.3 1.2-2.4 1.2-2.2 0-3.3-1.6-3.3-4.8 0-3.1 1-4.7 3.3-4.7 1.1 0 1.8.3 2.4 1.1v-.6c0-.5.4-.8.8-.8s.8.3.8.8v8.4c0 .5-.4.8-.8.8a.8.8 0 0 1-.8-.8zm-2-7.4c-1.3 0-1.8.9-1.8 3.2 0 2.4.5 3.3 1.7 3.3 1.3 0 1.8-.9 1.8-3.2 0-2.4-.5-3.3-1.7-3.3zM10 15.7H5.5l-.8 2.6a1 1 0 0 1-1 .7h-.2a.7.7 0 0 1-.7-1l4-12a1 1 0 1 1 2 0l4 12a.7.7 0 0 1-.8 1h-.2a1 1 0 0 1-1-.7l-.8-2.6zm-.3-1.5l-2-6.5-1.9 6.5h3.9z" fill-rule="evenodd"/></svg>',
  12669. 'character-count': '<svg width="24" height="24"><path d="M4 11.5h16v1H4v-1zm4.8-6.8V10H7.7V5.8h-1v-1h2zM11 8.3V9h2v1h-3V7.7l2-1v-.9h-2v-1h3v2.4l-2 1zm6.3-3.4V10h-3.1V9h2.1V8h-2.1V6.8h2.1v-1h-2.1v-1h3.1zM5.8 16.4c0-.5.2-.8.5-1 .2-.2.6-.3 1.2-.3l.8.1c.2 0 .4.2.5.3l.4.4v2.8l.2.3H8.2v-.1-.2l-.6.3H7c-.4 0-.7 0-1-.2a1 1 0 0 1-.3-.9c0-.3 0-.6.3-.8.3-.2.7-.4 1.2-.4l.6-.2h.3v-.2l-.1-.2a.8.8 0 0 0-.5-.1 1 1 0 0 0-.4 0l-.3.4h-1zm2.3.8h-.2l-.2.1-.4.1a1 1 0 0 0-.4.2l-.2.2.1.3.5.1h.4l.4-.4v-.6zm2-3.4h1.2v1.7l.5-.3h.5c.5 0 .9.1 1.2.5.3.4.5.8.5 1.4 0 .6-.2 1.1-.5 1.5-.3.4-.7.6-1.3.6l-.6-.1-.4-.4v.4h-1.1v-5.4zm1.1 3.3c0 .3 0 .6.2.8a.7.7 0 0 0 1.2 0l.2-.8c0-.4 0-.6-.2-.8a.7.7 0 0 0-.6-.3l-.6.3-.2.8zm6.1-.5c0-.2 0-.3-.2-.4a.8.8 0 0 0-.5-.2c-.3 0-.5.1-.6.3l-.2.9c0 .3 0 .6.2.8.1.2.3.3.6.3.2 0 .4 0 .5-.2l.2-.4h1.1c0 .5-.3.8-.6 1.1a2 2 0 0 1-1.3.4c-.5 0-1-.2-1.3-.6a2 2 0 0 1-.5-1.4c0-.6.1-1.1.5-1.5.3-.4.8-.5 1.4-.5.5 0 1 0 1.2.3.4.3.5.7.5 1.2h-1v-.1z" fill-rule="evenodd"/></svg>',
  12670. 'checklist-rtl': '<svg width="24" height="24"><path d="M5 17h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2zm14.2 11c.2-.4.6-.5.9-.3.3.2.4.6.2 1L18 20c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L18 14c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L18 8c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8z" fill-rule="evenodd"/></svg>',
  12671. 'checklist': '<svg width="24" height="24"><path d="M11 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8a1 1 0 0 1 0 2h-8a1 1 0 0 1 0-2zM7.2 16c.2-.4.6-.5.9-.3.3.2.4.6.2 1L6 20c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L6 14c-.2.3-.7.4-1 0l-1.3-1.3a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8zm0-6c.2-.4.6-.5.9-.3.3.2.4.6.2 1L6 8c-.2.3-.7.4-1 0L3.8 6.9a.7.7 0 0 1 0-1c.3-.2.7-.2 1 0l.7.9 1.7-2.8z" fill-rule="evenodd"/></svg>',
  12672. 'checkmark': '<svg width="24" height="24"><path d="M18.2 5.4a1 1 0 0 1 1.6 1.2l-8 12a1 1 0 0 1-1.5.1l-5-5a1 1 0 1 1 1.4-1.4l4.1 4.1 7.4-11z" fill-rule="nonzero"/></svg>',
  12673. 'chevron-down': '<svg width="10" height="10"><path d="M8.7 2.2c.3-.3.8-.3 1 0 .4.4.4.9 0 1.2L5.7 7.8c-.3.3-.9.3-1.2 0L.2 3.4a.8.8 0 0 1 0-1.2c.3-.3.8-.3 1.1 0L5 6l3.7-3.8z" fill-rule="nonzero"/></svg>',
  12674. 'chevron-left': '<svg width="10" height="10"><path d="M7.8 1.3L4 5l3.8 3.7c.3.3.3.8 0 1-.4.4-.9.4-1.2 0L2.2 5.7a.8.8 0 0 1 0-1.2L6.6.2C7 0 7.4 0 7.8.2c.3.3.3.8 0 1.1z" fill-rule="nonzero"/></svg>',
  12675. 'chevron-right': '<svg width="10" height="10"><path d="M2.2 1.3a.8.8 0 0 1 0-1c.4-.4.9-.4 1.2 0l4.4 4.1c.3.4.3.9 0 1.2L3.4 9.8c-.3.3-.8.3-1.2 0a.8.8 0 0 1 0-1.1L6 5 2.2 1.3z" fill-rule="nonzero"/></svg>',
  12676. 'chevron-up': '<svg width="10" height="10"><path d="M8.7 7.8L5 4 1.3 7.8c-.3.3-.8.3-1 0a.8.8 0 0 1 0-1.2l4.1-4.4c.3-.3.9-.3 1.2 0l4.2 4.4c.3.3.3.9 0 1.2-.3.3-.8.3-1.1 0z" fill-rule="nonzero"/></svg>',
  12677. 'close': '<svg width="24" height="24"><path d="M17.3 8.2L13.4 12l3.9 3.8a1 1 0 0 1-1.5 1.5L12 13.4l-3.8 3.9a1 1 0 0 1-1.5-1.5l3.9-3.8-3.9-3.8a1 1 0 0 1 1.5-1.5l3.8 3.9 3.8-3.9a1 1 0 0 1 1.5 1.5z" fill-rule="evenodd"/></svg>',
  12678. 'code-sample': '<svg width="24" height="26"><path d="M7.1 11a2.8 2.8 0 0 1-.8 2 2.8 2.8 0 0 1 .8 2v1.7c0 .3.1.6.4.8.2.3.5.4.8.4.3 0 .4.2.4.4v.8c0 .2-.1.4-.4.4-.7 0-1.4-.3-2-.8-.5-.6-.8-1.3-.8-2V15c0-.3-.1-.6-.4-.8-.2-.3-.5-.4-.8-.4a.4.4 0 0 1-.4-.4v-.8c0-.2.2-.4.4-.4.3 0 .6-.1.8-.4.3-.2.4-.5.4-.8V9.3c0-.7.3-1.4.8-2 .6-.5 1.3-.8 2-.8.3 0 .4.2.4.4v.8c0 .2-.1.4-.4.4-.3 0-.6.1-.8.4-.3.2-.4.5-.4.8V11zm9.8 0V9.3c0-.3-.1-.6-.4-.8-.2-.3-.5-.4-.8-.4a.4.4 0 0 1-.4-.4V7c0-.2.1-.4.4-.4.7 0 1.4.3 2 .8.5.6.8 1.3.8 2V11c0 .3.1.6.4.8.2.3.5.4.8.4.2 0 .4.2.4.4v.8c0 .2-.2.4-.4.4-.3 0-.6.1-.8.4-.3.2-.4.5-.4.8v1.7c0 .7-.3 1.4-.8 2-.6.5-1.3.8-2 .8a.4.4 0 0 1-.4-.4v-.8c0-.2.1-.4.4-.4.3 0 .6-.1.8-.4.3-.2.4-.5.4-.8V15a2.8 2.8 0 0 1 .8-2 2.8 2.8 0 0 1-.8-2zm-3.3-.4c0 .4-.1.8-.5 1.1-.3.3-.7.5-1.1.5-.4 0-.8-.2-1.1-.5-.4-.3-.5-.7-.5-1.1 0-.5.1-.9.5-1.2.3-.3.7-.4 1.1-.4.4 0 .8.1 1.1.4.4.3.5.7.5 1.2zM12 13c.4 0 .8.1 1.1.5.4.3.5.7.5 1.1 0 1-.1 1.6-.5 2a3 3 0 0 1-1.1 1c-.4.3-.8.4-1.1.4a.5.5 0 0 1-.5-.5V17a3 3 0 0 0 1-.2l.6-.6c-.6 0-1-.2-1.3-.5-.2-.3-.3-.7-.3-1 0-.5.1-1 .5-1.2.3-.4.7-.5 1.1-.5z" fill-rule="evenodd"/></svg>',
  12679. 'color-levels': '<svg width="24" height="24"><path d="M17.5 11.4A9 9 0 0 1 18 14c0 .5 0 1-.2 1.4 0 .4-.3.9-.5 1.3a6.2 6.2 0 0 1-3.7 3 5.7 5.7 0 0 1-3.2 0A5.9 5.9 0 0 1 7.6 18a6.2 6.2 0 0 1-1.4-2.6 6.7 6.7 0 0 1 0-2.8c0-.4.1-.9.3-1.3a13.6 13.6 0 0 1 2.3-4A20 20 0 0 1 12 4a26.4 26.4 0 0 1 3.2 3.4 18.2 18.2 0 0 1 2.3 4zm-2 4.5c.4-.7.5-1.4.5-2a7.3 7.3 0 0 0-1-3.2c.2.6.2 1.2.2 1.9a4.5 4.5 0 0 1-1.3 3 5.3 5.3 0 0 1-2.3 1.5 4.9 4.9 0 0 1-2 .1 4.3 4.3 0 0 0 2.4.8 4 4 0 0 0 2-.6 4 4 0 0 0 1.5-1.5z" fill-rule="evenodd"/></svg>',
  12680. 'color-picker': '<svg width="24" height="24"><path d="M12 3a9 9 0 0 0 0 18 1.5 1.5 0 0 0 1.1-2.5c-.2-.3-.4-.6-.4-1 0-.8.7-1.5 1.5-1.5H16a5 5 0 0 0 5-5c0-4.4-4-8-9-8zm-5.5 9a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm3-4a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm5 0a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm3 4a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3z" fill-rule="nonzero"/></svg>',
  12681. 'color-swatch-remove-color': '<svg width="24" height="24"><path stroke="#000" stroke-width="2" d="M21 3L3 21" fill-rule="evenodd"/></svg>',
  12682. 'color-swatch': '<svg width="24" height="24"><rect x="3" y="3" width="18" height="18" rx="1" fill-rule="evenodd"/></svg>',
  12683. 'comment-add': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M9 19l3-2h7c.6 0 1-.4 1-1V6c0-.6-.4-1-1-1H5a1 1 0 0 0-1 1v10c0 .6.4 1 1 1h4v2zm-2 4v-4H5a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h14a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-6.4L7 23z"/><path d="M13 10h2a1 1 0 0 1 0 2h-2v2a1 1 0 0 1-2 0v-2H9a1 1 0 0 1 0-2h2V8a1 1 0 0 1 2 0v2z"/></g></svg>',
  12684. 'comment': '<svg width="24" height="24"><path fill-rule="nonzero" d="M9 19l3-2h7c.6 0 1-.4 1-1V6c0-.6-.4-1-1-1H5a1 1 0 0 0-1 1v10c0 .6.4 1 1 1h4v2zm-2 4v-4H5a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h14a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-6.4L7 23z"/></svg>',
  12685. 'contrast': '<svg width="24" height="24"><path d="M12 4a7.8 7.8 0 0 1 5.7 2.3A8 8 0 1 1 12 4zm-6 8a6 6 0 0 0 6 6V6a6 6 0 0 0-6 6z" fill-rule="evenodd"/></svg>',
  12686. 'copy': '<svg width="24" height="24"><path d="M16 3H6a2 2 0 0 0-2 2v11h2V5h10V3zm1 4a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V9c0-1.2.9-2 2-2h7zm0 12V9h-7v10h7z" fill-rule="nonzero"/></svg>',
  12687. 'crop': '<svg width="24" height="24"><path d="M17 8v7h2c.6 0 1 .4 1 1s-.4 1-1 1h-2v2c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-2H7V9H5a1 1 0 1 1 0-2h2V5c0-.6.4-1 1-1s1 .4 1 1v2h7l3-3 1 1-3 3zM9 9v5l5-5H9zm1 6h5v-5l-5 5z" fill-rule="evenodd"/></svg>',
  12688. 'cut': '<svg width="24" height="24"><path d="M18 15c.6.7 1 1.4 1 2.3 0 .8-.2 1.5-.7 2l-.8.5-1 .2c-.4 0-.8 0-1.2-.3a3.9 3.9 0 0 1-2.1-2.2c-.2-.5-.3-1-.2-1.5l-1-1-1 1c0 .5 0 1-.2 1.5-.1.5-.4 1-.9 1.4-.3.4-.7.6-1.2.8l-1.2.3c-.4 0-.7 0-1-.2-.3 0-.6-.3-.8-.5-.5-.5-.8-1.2-.7-2 0-.9.4-1.6 1-2.2A3.7 3.7 0 0 1 8.6 14H9l1-1-4-4-.5-1a3.3 3.3 0 0 1 0-2c0-.4.3-.7.5-1l6 6 6-6 .5 1a3.3 3.3 0 0 1 0 2c0 .4-.3.7-.5 1l-4 4 1 1h.5c.4 0 .8 0 1.2.3.5.2.9.4 1.2.8zm-8.5 2.2l.1-.4v-.3-.4a1 1 0 0 0-.2-.5 1 1 0 0 0-.4-.2 1.6 1.6 0 0 0-.8 0 2.6 2.6 0 0 0-.8.3 2.5 2.5 0 0 0-.9 1.1l-.1.4v.7l.2.5.5.2h.7a2.5 2.5 0 0 0 .8-.3 2.8 2.8 0 0 0 1-1zm2.5-2.8c.4 0 .7-.1 1-.4.3-.3.4-.6.4-1s-.1-.7-.4-1c-.3-.3-.6-.4-1-.4s-.7.1-1 .4c-.3.3-.4.6-.4 1s.1.7.4 1c.3.3.6.4 1 .4zm5.4 4l.2-.5v-.4-.3a2.6 2.6 0 0 0-.3-.8 2.4 2.4 0 0 0-.7-.7 2.5 2.5 0 0 0-.8-.3 1.5 1.5 0 0 0-.8 0 1 1 0 0 0-.4.2 1 1 0 0 0-.2.5 1.5 1.5 0 0 0 0 .7v.4l.3.4.3.4a2.8 2.8 0 0 0 .8.5l.4.1h.7l.5-.2z" fill-rule="evenodd"/></svg>',
  12689. 'document-properties': '<svg width="24" height="24"><path d="M14.4 3H7a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h10a2 2 0 0 0 2-2V7.6L14.4 3zM17 19H7V5h6v4h4v10z" fill-rule="nonzero"/></svg>',
  12690. 'drag': '<svg width="24" height="24"><path d="M13 5h2v2h-2V5zm0 4h2v2h-2V9zM9 9h2v2H9V9zm4 4h2v2h-2v-2zm-4 0h2v2H9v-2zm0 4h2v2H9v-2zm4 0h2v2h-2v-2zM9 5h2v2H9V5z" fill-rule="evenodd"/></svg>',
  12691. 'duplicate': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M16 3v2H6v11H4V5c0-1.1.9-2 2-2h10zm3 8h-2V9h-7v10h9a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V9c0-1.2.9-2 2-2h7a2 2 0 0 1 2 2v2z"/><path d="M17 14h1a1 1 0 0 1 0 2h-1v1a1 1 0 0 1-2 0v-1h-1a1 1 0 0 1 0-2h1v-1a1 1 0 0 1 2 0v1z"/></g></svg>',
  12692. 'edit-block': '<svg width="24" height="24"><path fill-rule="nonzero" d="M19.8 8.8l-9.4 9.4c-.2.2-.5.4-.9.4l-5.4 1.2 1.2-5.4.5-.8 9.4-9.4c.7-.7 1.8-.7 2.5 0l2.1 2.1c.7.7.7 1.8 0 2.5zm-2-.2l1-.9v-.3l-2.2-2.2a.3.3 0 0 0-.3 0l-1 1L18 8.5zm-1 1l-2.5-2.4-6 6 2.5 2.5 6-6zm-7 7.1l-2.6-2.4-.3.3-.1.2-.7 3 3.1-.6h.1l.4-.5z"/></svg>',
  12693. 'edit-image': '<svg width="24" height="24"><path d="M18 16h2V7a2 2 0 0 0-2-2H7v2h11v9zM6 17h15a1 1 0 0 1 0 2h-1v1a1 1 0 0 1-2 0v-1H6a2 2 0 0 1-2-2V7H3a1 1 0 1 1 0-2h1V4a1 1 0 1 1 2 0v13zm3-5.3l1.3 2 3-4.7 3.7 6H7l2-3.3z" fill-rule="nonzero"/></svg>',
  12694. 'embed-page': '<svg width="24" height="24"><path d="M19 6V5H5v14h2A13 13 0 0 1 19 6zm0 1.4c-.8.8-1.6 2.4-2.2 4.6H19V7.4zm0 5.6h-2.4c-.4 1.8-.6 3.8-.6 6h3v-6zm-4 6c0-2.2.2-4.2.6-6H13c-.7 1.8-1.1 3.8-1.1 6h3zm-4 0c0-2.2.4-4.2 1-6H9.6A12 12 0 0 0 8 19h3zM4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm11.8 9c.4-1.9 1-3.4 1.8-4.5a9.2 9.2 0 0 0-4 4.5h2.2zm-3.4 0a12 12 0 0 1 2.8-4 12 12 0 0 0-5 4h2.2z" fill-rule="nonzero"/></svg>',
  12695. 'embed': '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm1 2v14h14V5H5zm4.8 2.6l5.6 4a.5.5 0 0 1 0 .8l-5.6 4A.5.5 0 0 1 9 16V8a.5.5 0 0 1 .8-.4z" fill-rule="nonzero"/></svg>',
  12696. 'emoji': '<svg width="24" height="24"><path d="M9 11c.6 0 1-.4 1-1s-.4-1-1-1a1 1 0 0 0-1 1c0 .6.4 1 1 1zm6 0c.6 0 1-.4 1-1s-.4-1-1-1a1 1 0 0 0-1 1c0 .6.4 1 1 1zm-3 5.5c2.1 0 4-1.5 4.4-3.5H7.6c.5 2 2.3 3.5 4.4 3.5zM12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zm0 14.5a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13z" fill-rule="nonzero"/></svg>',
  12697. 'fill': '<svg width="24" height="26"><path d="M16.6 12l-9-9-1.4 1.4 2.4 2.4-5.2 5.1c-.5.6-.5 1.6 0 2.2L9 19.6a1.5 1.5 0 0 0 2.2 0l5.5-5.5c.5-.6.5-1.6 0-2.2zM5.2 13L10 8.2l4.8 4.8H5.2zM19 14.5s-2 2.2-2 3.5c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.3-2-3.5-2-3.5z" fill-rule="nonzero"/></svg>',
  12698. 'flip-horizontally': '<svg width="24" height="24"><path d="M14 19h2v-2h-2v2zm4-8h2V9h-2v2zM4 7v10c0 1.1.9 2 2 2h3v-2H6V7h3V5H6a2 2 0 0 0-2 2zm14-2v2h2a2 2 0 0 0-2-2zm-7 16h2V3h-2v18zm7-6h2v-2h-2v2zm-4-8h2V5h-2v2zm4 12a2 2 0 0 0 2-2h-2v2z" fill-rule="nonzero"/></svg>',
  12699. 'flip-vertically': '<svg width="24" height="24"><path d="M5 14v2h2v-2H5zm8 4v2h2v-2h-2zm4-14H7a2 2 0 0 0-2 2v3h2V6h10v3h2V6a2 2 0 0 0-2-2zm2 14h-2v2a2 2 0 0 0 2-2zM3 11v2h18v-2H3zm6 7v2h2v-2H9zm8-4v2h2v-2h-2zM5 18c0 1.1.9 2 2 2v-2H5z" fill-rule="nonzero"/></svg>',
  12700. 'format-painter': '<svg width="24" height="24"><path d="M18 5V4c0-.5-.4-1-1-1H5a1 1 0 0 0-1 1v4c0 .6.5 1 1 1h12c.6 0 1-.4 1-1V7h1v4H9v9c0 .6.4 1 1 1h2c.6 0 1-.4 1-1v-7h8V5h-3z" fill-rule="nonzero"/></svg>',
  12701. 'fullscreen': '<svg width="24" height="24"><path d="M15.3 10l-1.2-1.3 2.9-3h-2.3a.9.9 0 1 1 0-1.7H19c.5 0 .9.4.9.9v4.4a.9.9 0 1 1-1.8 0V7l-2.9 3zm0 4l3 3v-2.3a.9.9 0 1 1 1.7 0V19c0 .5-.4.9-.9.9h-4.4a.9.9 0 1 1 0-1.8H17l-3-2.9 1.3-1.2zM10 15.4l-2.9 3h2.3a.9.9 0 1 1 0 1.7H5a.9.9 0 0 1-.9-.9v-4.4a.9.9 0 1 1 1.8 0V17l2.9-3 1.2 1.3zM8.7 10L5.7 7v2.3a.9.9 0 0 1-1.7 0V5c0-.5.4-.9.9-.9h4.4a.9.9 0 0 1 0 1.8H7l3 2.9-1.3 1.2z" fill-rule="nonzero"/></svg>',
  12702. 'gallery': '<svg width="24" height="24"><path fill-rule="nonzero" d="M5 15.7l2.3-2.2c.3-.3.7-.3 1 0L11 16l5.1-5c.3-.4.8-.4 1 0l2 1.9V8H5v7.7zM5 18V19h3l1.8-1.9-2-2L5 17.9zm14-3l-2.5-2.4-6.4 6.5H19v-4zM4 6h16c.6 0 1 .4 1 1v13c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V7c0-.6.4-1 1-1zm6 7a2 2 0 1 1 0-4 2 2 0 0 1 0 4zM4.5 4h15a.5.5 0 1 1 0 1h-15a.5.5 0 0 1 0-1zm2-2h11a.5.5 0 1 1 0 1h-11a.5.5 0 0 1 0-1z"/></svg>',
  12703. 'gamma': '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm1 2v14h14V5H5zm6.5 11.8V14L9.2 8.7a5.1 5.1 0 0 0-.4-.8l-.1-.2H8 8v-1l.3-.1.3-.1h.7a1 1 0 0 1 .6.5l.1.3a8.5 8.5 0 0 1 .3.6l1.9 4.6 2-5.2a1 1 0 0 1 1-.6.5.5 0 0 1 .5.6L13 14v2.8a.7.7 0 0 1-1.4 0z" fill-rule="nonzero"/></svg>',
  12704. 'help': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M12 5.5a6.5 6.5 0 0 0-6 9 6.3 6.3 0 0 0 1.4 2l1 1a6.3 6.3 0 0 0 3.6 1 6.5 6.5 0 0 0 6-9 6.3 6.3 0 0 0-1.4-2l-1-1a6.3 6.3 0 0 0-3.6-1zM12 4a7.8 7.8 0 0 1 5.7 2.3A8 8 0 1 1 12 4z"/><path d="M9.6 9.7a.7.7 0 0 1-.7-.8c0-1.1 1.5-1.8 3.2-1.8 1.8 0 3.2.8 3.2 2.4 0 1.4-.4 2.1-1.5 2.8-.2 0-.3.1-.3.2a2 2 0 0 0-.8.8.8.8 0 0 1-1.4-.6c.3-.7.8-1 1.3-1.5l.4-.2c.7-.4.8-.6.8-1.5 0-.5-.6-.9-1.7-.9-.5 0-1 .1-1.4.3-.2 0-.3.1-.3.2v-.2c0 .4-.4.8-.8.8z" fill-rule="nonzero"/><circle cx="12" cy="16" r="1"/></g></svg>',
  12705. 'highlight-bg-color': '<svg width="24" height="24"><g fill-rule="evenodd"><path id="tox-icon-highlight-bg-color__color" d="M3 18h18v3H3z"/><path fill-rule="nonzero" d="M7.7 16.7H3l3.3-3.3-.7-.8L10.2 8l4 4.1-4 4.2c-.2.2-.6.2-.8 0l-.6-.7-1.1 1.1zm5-7.5L11 7.4l3-2.9a2 2 0 0 1 2.6 0L18 6c.7.7.7 2 0 2.7l-2.9 2.9-1.8-1.8-.5-.6"/></g></svg>',
  12706. 'home': '<svg width="24" height="24"><path fill-rule="nonzero" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>',
  12707. 'horizontal-rule': '<svg width="24" height="24"><path d="M4 11h16v2H4z" fill-rule="evenodd"/></svg>',
  12708. 'image-options': '<svg width="24" height="24"><path d="M6 10a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm12 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm-6 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2z" fill-rule="nonzero"/></svg>',
  12709. 'image': '<svg width="24" height="24"><path d="M5 15.7l3.3-3.2c.3-.3.7-.3 1 0L12 15l4.1-4c.3-.4.8-.4 1 0l2 1.9V5H5v10.7zM5 18V19h3l2.8-2.9-2-2L5 17.9zm14-3l-2.5-2.4-6.4 6.5H19v-4zM4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1zm6 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4z" fill-rule="nonzero"/></svg>',
  12710. 'indent': '<svg width="24" height="24"><path d="M7 5h12c.6 0 1 .4 1 1s-.4 1-1 1H7a1 1 0 1 1 0-2zm5 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm0 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm-5 4h12a1 1 0 0 1 0 2H7a1 1 0 0 1 0-2zm-2.6-3.8L6.2 12l-1.8-1.2a1 1 0 0 1 1.2-1.6l3 2a1 1 0 0 1 0 1.6l-3 2a1 1 0 1 1-1.2-1.6z" fill-rule="evenodd"/></svg>',
  12711. 'info': '<svg width="24" height="24"><path d="M12 4a7.8 7.8 0 0 1 5.7 2.3A8 8 0 1 1 12 4zm-1 3v2h2V7h-2zm3 10v-1h-1v-5h-3v1h1v4h-1v1h4z" fill-rule="evenodd"/></svg>',
  12712. 'insert-character': '<svg width="24" height="24"><path d="M15 18h4l1-2v4h-6v-3.3l1.4-1a6 6 0 0 0 1.8-2.9 6.3 6.3 0 0 0-.1-4.1 5.8 5.8 0 0 0-3-3.2c-.6-.3-1.3-.5-2.1-.5a5.1 5.1 0 0 0-3.9 1.8 6.3 6.3 0 0 0-1.3 6 6.2 6.2 0 0 0 1.8 3l1.4.9V20H4v-4l1 2h4v-.5l-2-1L5.4 15A6.5 6.5 0 0 1 4 11c0-1 .2-1.9.6-2.7A7 7 0 0 1 6.3 6C7.1 5.4 8 5 9 4.5c1-.3 2-.5 3.1-.5a8.8 8.8 0 0 1 5.7 2 7 7 0 0 1 1.7 2.3 6 6 0 0 1 .2 4.8c-.2.7-.6 1.3-1 1.9a7.6 7.6 0 0 1-3.6 2.5v.5z" fill-rule="evenodd"/></svg>',
  12713. 'insert-time': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M12 19a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm0 2a9 9 0 1 1 0-18 9 9 0 0 1 0 18z"/><path d="M16 12h-3V7c0-.6-.4-1-1-1a1 1 0 0 0-1 1v7h5c.6 0 1-.4 1-1s-.4-1-1-1z"/></g></svg>',
  12714. 'invert': '<svg width="24" height="24"><path d="M18 19.3L16.5 18a5.8 5.8 0 0 1-3.1 1.9 6.1 6.1 0 0 1-5.5-1.6A5.8 5.8 0 0 1 6 14v-.3l.1-1.2A13.9 13.9 0 0 1 7.7 9l-3-3 .7-.8 2.8 2.9 9 8.9 1.5 1.6-.7.6zm0-5.5v.3l-.1 1.1-.4 1-1.2-1.2a4.3 4.3 0 0 0 .2-1v-.2c0-.4 0-.8-.2-1.3l-.5-1.4a14.8 14.8 0 0 0-3-4.2L12 6a26.1 26.1 0 0 0-2.2 2.5l-1-1a20.9 20.9 0 0 1 2.9-3.3L12 4l1 .8a22.2 22.2 0 0 1 4 5.4c.6 1.2 1 2.4 1 3.6z" fill-rule="evenodd"/></svg>',
  12715. 'italic': '<svg width="24" height="24"><path d="M16.7 4.7l-.1.9h-.3c-.6 0-1 0-1.4.3-.3.3-.4.6-.5 1.1l-2.1 9.8v.6c0 .5.4.8 1.4.8h.2l-.2.8H8l.2-.8h.2c1.1 0 1.8-.5 2-1.5l2-9.8.1-.5c0-.6-.4-.8-1.4-.8h-.3l.2-.9h5.8z" fill-rule="evenodd"/></svg>',
  12716. 'line': '<svg width="24" height="24"><path d="M15 9l-8 8H4v-3l8-8 3 3zm1-1l-3-3 1-1h1c-.2 0 0 0 0 0l2 2s0 .2 0 0v1l-1 1zM4 18h16v2H4v-2z" fill-rule="evenodd"/></svg>',
  12717. 'link': '<svg width="24" height="24"><path d="M6.2 12.3a1 1 0 0 1 1.4 1.4l-2.1 2a2 2 0 1 0 2.7 2.8l4.8-4.8a1 1 0 0 0 0-1.4 1 1 0 1 1 1.4-1.3 2.9 2.9 0 0 1 0 4L9.6 20a3.9 3.9 0 0 1-5.5-5.5l2-2zm11.6-.6a1 1 0 0 1-1.4-1.4l2-2a2 2 0 1 0-2.6-2.8L11 10.3a1 1 0 0 0 0 1.4A1 1 0 1 1 9.6 13a2.9 2.9 0 0 1 0-4L14.4 4a3.9 3.9 0 0 1 5.5 5.5l-2 2z" fill-rule="nonzero"/></svg>',
  12718. 'list-bull-circle': '<svg width="48" height="48"><g fill-rule="evenodd"><path d="M11 16a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0 1a3 3 0 1 1 0-6 3 3 0 0 1 0 6zM11 26a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0 1a3 3 0 1 1 0-6 3 3 0 0 1 0 6zM11 36a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0 1a3 3 0 1 1 0-6 3 3 0 0 1 0 6z" fill-rule="nonzero"/><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/></g></svg>',
  12719. 'list-bull-default': '<svg width="48" height="48"><g fill-rule="evenodd"><circle cx="11" cy="14" r="3"/><circle cx="11" cy="24" r="3"/><circle cx="11" cy="34" r="3"/><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/></g></svg>',
  12720. 'list-bull-square': '<svg width="48" height="48"><g fill-rule="evenodd"><path d="M8 11h6v6H8zM8 21h6v6H8zM8 31h6v6H8z"/><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/></g></svg>',
  12721. 'list-num-default-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M37.4 17v-4.8l-1.6 1v-1.1l1.6-1h1.2V17zM33.3 17.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm1.7 5.7c0-1.2 1-2 2.2-2 1.3 0 2.1.8 2.1 1.8 0 .7-.3 1.2-1.3 2.2l-1.2 1v.2h2.6v1h-4.3v-.9l2-1.9c.8-.8 1-1.1 1-1.5 0-.5-.4-.8-1-.8-.5 0-.9.3-.9.9H35zm-1.7 4.3c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm3.2 7.3v-1h.7c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7s-1 .3-1 .8H35c0-1.1 1-1.8 2.2-1.8 1.2 0 2.1.6 2.1 1.6 0 .7-.4 1.2-1 1.3v.1c.7.1 1.3.7 1.3 1.4 0 1-1 1.9-2.4 1.9-1.3 0-2.2-.8-2.3-2h1.2c0 .6.5 1 1.1 1 .6 0 1-.4 1-1 0-.5-.3-.8-1-.8h-.7zm-3.3 2.7c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7z"/></g></svg>',
  12722. 'list-num-default': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M10 17v-4.8l-1.5 1v-1.1l1.6-1h1.2V17h-1.2zm3.6.1c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zm-5 5.7c0-1.2.8-2 2.1-2s2.1.8 2.1 1.8c0 .7-.3 1.2-1.4 2.2l-1.1 1v.2h2.6v1H8.6v-.9l2-1.9c.8-.8 1-1.1 1-1.5 0-.5-.4-.8-1-.8-.5 0-.9.3-.9.9H8.5zm6.3 4.3c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zM10 34.4v-1h.7c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7s-1 .3-1 .8H8.6c0-1.1 1-1.8 2.2-1.8 1.3 0 2.1.6 2.1 1.6 0 .7-.4 1.2-1 1.3v.1c.8.1 1.3.7 1.3 1.4 0 1-1 1.9-2.4 1.9-1.3 0-2.2-.8-2.3-2h1.2c0 .6.5 1 1.1 1 .7 0 1-.4 1-1 0-.5-.3-.8-1-.8h-.7zm4.7 2.7c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7z"/></g></svg>',
  12723. 'list-num-lower-alpha-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M36.5 16c-.9 0-1.5-.5-1.5-1.3s.6-1.3 1.8-1.4h1v-.4c0-.4-.2-.6-.7-.6-.4 0-.7.1-.8.4h-1.1c0-.8.8-1.4 2-1.4S39 12 39 13V16h-1.2v-.6c-.3.4-.8.7-1.4.7zm.4-.8c.6 0 1-.4 1-.9V14h-1c-.5.1-.7.3-.7.6 0 .4.3.6.7.6zM33.1 16.1c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7zM37.7 26c-.7 0-1.2-.2-1.5-.7v.7H35v-6.3h1.2v2.5c.3-.5.8-.9 1.5-.9 1.1 0 1.8 1 1.8 2.4 0 1.5-.7 2.4-1.8 2.4zm-.5-3.6c-.6 0-1 .5-1 1.3s.4 1.4 1 1.4c.7 0 1-.6 1-1.4 0-.8-.3-1.3-1-1.3zM33.2 26.1c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7zm6 7h-1c-.1-.5-.4-.8-1-.8s-1 .5-1 1.4c0 1 .4 1.4 1 1.4.5 0 .9-.2 1-.7h1c0 1-.8 1.7-2 1.7-1.4 0-2.2-.9-2.2-2.4s.8-2.4 2.2-2.4c1.2 0 2 .7 2 1.7zm-6.1 3c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12724. 'list-num-lower-alpha': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M10.3 15.2c.5 0 1-.4 1-.9V14h-1c-.5.1-.8.3-.8.6 0 .4.3.6.8.6zm-.4.9c-1 0-1.5-.6-1.5-1.4 0-.8.6-1.3 1.7-1.4h1.1v-.4c0-.4-.2-.6-.7-.6-.5 0-.8.1-.9.4h-1c0-.8.8-1.4 2-1.4 1.1 0 1.8.6 1.8 1.6V16h-1.1v-.6h-.1c-.2.4-.7.7-1.3.7zm4.6 0c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm-3.2 10c-.6 0-1.2-.3-1.4-.8v.7H8.5v-6.3H10v2.5c.3-.5.8-.9 1.4-.9 1.2 0 1.9 1 1.9 2.4 0 1.5-.7 2.4-1.9 2.4zm-.4-3.7c-.7 0-1 .5-1 1.3s.3 1.4 1 1.4c.6 0 1-.6 1-1.4 0-.8-.4-1.3-1-1.3zm4 3.7c-.5 0-.7-.3-.7-.7 0-.4.2-.7.7-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm-2.2 7h-1.2c0-.5-.4-.8-.9-.8-.6 0-1 .5-1 1.4 0 1 .4 1.4 1 1.4.5 0 .8-.2 1-.7h1c0 1-.8 1.7-2 1.7-1.4 0-2.2-.9-2.2-2.4s.8-2.4 2.2-2.4c1.2 0 2 .7 2 1.7zm1.8 3c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12725. 'list-num-lower-greek-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M37.4 16c-1.2 0-2-.8-2-2.3 0-1.5.8-2.4 2-2.4.6 0 1 .4 1.3 1v-.9H40v3.2c0 .4.1.5.4.5h.2v.9h-.6c-.6 0-1-.2-1-.7h-.2c-.2.4-.7.8-1.3.8zm.3-1c.6 0 1-.5 1-1.3s-.4-1.3-1-1.3-1 .5-1 1.3.4 1.4 1 1.4zM33.3 16.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zM36 21.9c0-1.5.8-2.3 2.1-2.3 1.2 0 2 .6 2 1.6 0 .6-.3 1-.9 1.3.9.3 1.3.8 1.3 1.7 0 1.2-.7 1.9-1.8 1.9-.6 0-1.1-.3-1.4-.8v2.2H36V22zm1.8 1.2v-1h.3c.5 0 .9-.2.9-.7 0-.5-.3-.8-.9-.8-.5 0-.8.3-.8 1v2.2c0 .8.4 1.3 1 1.3s1-.4 1-1-.4-1-1.2-1h-.3zM33.3 26.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zM37.1 34.6L34.8 30h1.4l1.7 3.5 1.7-3.5h1.1l-2.2 4.6v.1c.5.8.7 1.4.7 1.8 0 .4-.2.8-.4 1-.2.2-.6.3-1 .3-.9 0-1.3-.4-1.3-1.2 0-.5.2-1 .5-1.7l.1-.2zm.7 1a2 2 0 0 0-.4.9c0 .3.1.4.4.4.3 0 .4-.1.4-.4 0-.2-.1-.6-.4-1zM33.3 36.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12726. 'list-num-lower-greek': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M10.5 15c.7 0 1-.5 1-1.3s-.3-1.3-1-1.3c-.5 0-.9.5-.9 1.3s.4 1.4 1 1.4zm-.3 1c-1.1 0-1.8-.8-1.8-2.3 0-1.5.7-2.4 1.8-2.4.7 0 1.1.4 1.3 1h.1v-.9h1.2v3.2c0 .4.1.5.4.5h.2v.9h-.6c-.6 0-1-.2-1.1-.7h-.1c-.2.4-.7.8-1.4.8zm5 .1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.7-.7.5 0 .8.3.8.7 0 .4-.3.7-.8.7zm-4.9 7v-1h.3c.6 0 1-.2 1-.7 0-.5-.4-.8-1-.8-.5 0-.8.3-.8 1v2.2c0 .8.4 1.3 1.1 1.3.6 0 1-.4 1-1s-.5-1-1.3-1h-.3zM8.6 22c0-1.5.7-2.3 2-2.3 1.2 0 2 .6 2 1.6 0 .6-.3 1-.8 1.3.8.3 1.3.8 1.3 1.7 0 1.2-.8 1.9-1.9 1.9-.6 0-1.1-.3-1.3-.8v2.2H8.5V22zm6.2 4.2c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zm-4.5 8.5L8 30h1.4l1.7 3.5 1.7-3.5h1.1l-2.2 4.6v.1c.5.8.7 1.4.7 1.8 0 .4-.1.8-.4 1-.2.2-.6.3-1 .3-.9 0-1.3-.4-1.3-1.2 0-.5.2-1 .5-1.7l.1-.2zm.7 1a2 2 0 0 0-.4.9c0 .3.1.4.4.4.3 0 .4-.1.4-.4 0-.2-.1-.6-.4-1zm4.5.5c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12727. 'list-num-lower-roman-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M32.9 16v-1.2h-1.3V16H33zm0 10v-1.2h-1.3V26H33zm0 10v-1.2h-1.3V36H33z"/><path fill-rule="nonzero" d="M36 21h-1.5v5H36zM36 31h-1.5v5H36zM39 21h-1.5v5H39zM39 31h-1.5v5H39zM42 31h-1.5v5H42zM36 11h-1.5v5H36zM36 19h-1.5v1H36zM36 29h-1.5v1H36zM39 19h-1.5v1H39zM39 29h-1.5v1H39zM42 29h-1.5v1H42zM36 9h-1.5v1H36z"/></g></svg>',
  12728. 'list-num-lower-roman': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M15.1 16v-1.2h1.3V16H15zm0 10v-1.2h1.3V26H15zm0 10v-1.2h1.3V36H15z"/><path fill-rule="nonzero" d="M12 21h1.5v5H12zM12 31h1.5v5H12zM9 21h1.5v5H9zM9 31h1.5v5H9zM6 31h1.5v5H6zM12 11h1.5v5H12zM12 19h1.5v1H12zM12 29h1.5v1H12zM9 19h1.5v1H9zM9 29h1.5v1H9zM6 29h1.5v1H6zM12 9h1.5v1H12z"/></g></svg>',
  12729. 'list-num-upper-alpha-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M39.3 17l-.5-1.4h-2l-.5 1.4H35l2-6h1.6l2 6h-1.3zm-1.6-4.7l-.7 2.3h1.6l-.8-2.3zM33.4 17c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zm4.7 9.9h-2.7v-6H38c1.2 0 1.9.6 1.9 1.5 0 .6-.5 1.2-1 1.3.7.1 1.3.7 1.3 1.5 0 1-.8 1.7-2 1.7zm-1.4-5v1.5h1c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7h-1zm0 4h1.1c.7 0 1.1-.3 1.1-.8 0-.6-.4-.9-1.1-.9h-1.1V26zM33 27.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm4.9 10c-1.8 0-2.8-1.1-2.8-3.1s1-3.1 2.8-3.1c1.4 0 2.5.9 2.6 2.2h-1.3c0-.7-.6-1.1-1.3-1.1-1 0-1.6.7-1.6 2s.6 2 1.6 2c.7 0 1.2-.4 1.4-1h1.2c-.1 1.3-1.2 2.2-2.6 2.2zm-4.5 0c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12730. 'list-num-upper-alpha': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M12.6 17l-.5-1.4h-2L9.5 17H8.3l2-6H12l2 6h-1.3zM11 12.3l-.7 2.3h1.6l-.8-2.3zm4.7 4.8c-.4 0-.7-.3-.7-.7 0-.4.3-.7.7-.7.5 0 .7.3.7.7 0 .4-.2.7-.7.7zM11.4 27H8.7v-6h2.6c1.2 0 1.9.6 1.9 1.5 0 .6-.5 1.2-1 1.3.7.1 1.3.7 1.3 1.5 0 1-.8 1.7-2 1.7zM10 22v1.5h1c.6 0 1-.3 1-.8 0-.4-.4-.7-1-.7h-1zm0 4H11c.7 0 1.1-.3 1.1-.8 0-.6-.4-.9-1.1-.9H10V26zm5.4 1.1c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7zm-4.1 10c-1.8 0-2.8-1.1-2.8-3.1s1-3.1 2.8-3.1c1.4 0 2.5.9 2.6 2.2h-1.3c0-.7-.6-1.1-1.3-1.1-1 0-1.6.7-1.6 2s.6 2 1.6 2c.7 0 1.2-.4 1.4-1h1.2c-.1 1.3-1.2 2.2-2.6 2.2zm4.5 0c-.5 0-.8-.3-.8-.7 0-.4.3-.7.8-.7.4 0 .7.3.7.7 0 .4-.3.7-.7.7z"/></g></svg>',
  12731. 'list-num-upper-roman-rtl': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M8 12h22v4H8zM8 22h22v4H8zM8 32h22v4H8z"/><path d="M31.6 17v-1.2H33V17h-1.3zm0 10v-1.2H33V27h-1.3zm0 10v-1.2H33V37h-1.3z"/><path fill-rule="nonzero" d="M34.5 20H36v7h-1.5zM34.5 30H36v7h-1.5zM37.5 20H39v7h-1.5zM37.5 30H39v7h-1.5zM40.5 30H42v7h-1.5zM34.5 10H36v7h-1.5z"/></g></svg>',
  12732. 'list-num-upper-roman': '<svg width="48" height="48"><g fill-rule="evenodd"><path opacity=".2" d="M18 12h22v4H18zM18 22h22v4H18zM18 32h22v4H18z"/><path d="M15.1 17v-1.2h1.3V17H15zm0 10v-1.2h1.3V27H15zm0 10v-1.2h1.3V37H15z"/><path fill-rule="nonzero" d="M12 20h1.5v7H12zM12 30h1.5v7H12zM9 20h1.5v7H9zM9 30h1.5v7H9zM6 30h1.5v7H6zM12 10h1.5v7H12z"/></g></svg>',
  12733. 'lock': '<svg width="24" height="24"><path d="M16.3 11c.2 0 .3 0 .5.2l.2.6v7.4c0 .3 0 .4-.2.6l-.6.2H7.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6v-7.4c0-.3 0-.4.2-.6l.5-.2H8V8c0-.8.3-1.5.9-2.1.6-.6 1.3-.9 2.1-.9h2c.8 0 1.5.3 2.1.9.6.6.9 1.3.9 2.1v3h.3zM10 8v3h4V8a1 1 0 0 0-.3-.7A1 1 0 0 0 13 7h-2a1 1 0 0 0-.7.3 1 1 0 0 0-.3.7z" fill-rule="evenodd"/></svg>',
  12734. 'ltr': '<svg width="24" height="24"><path d="M11 5h7a1 1 0 0 1 0 2h-1v11a1 1 0 0 1-2 0V7h-2v11a1 1 0 0 1-2 0v-6c-.5 0-1 0-1.4-.3A3.4 3.4 0 0 1 7.8 10a3.3 3.3 0 0 1 0-2.8 3.4 3.4 0 0 1 1.8-1.8L11 5zM4.4 16.2L6.2 15l-1.8-1.2a1 1 0 0 1 1.2-1.6l3 2a1 1 0 0 1 0 1.6l-3 2a1 1 0 1 1-1.2-1.6z" fill-rule="evenodd"/></svg>',
  12735. 'more-drawer': '<svg width="24" height="24"><path d="M6 10a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm12 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2zm-6 0a2 2 0 0 0-2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2 2 2 0 0 0-2-2z" fill-rule="nonzero"/></svg>',
  12736. 'new-document': '<svg width="24" height="24"><path d="M14.4 3H7a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h10a2 2 0 0 0 2-2V7.6L14.4 3zM17 19H7V5h6v4h4v10z" fill-rule="nonzero"/></svg>',
  12737. 'new-tab': '<svg width="24" height="24"><path d="M15 13l2-2v8H5V7h8l-2 2H7v8h8v-4zm4-8v5.5l-2-2-5.6 5.5H10v-1.4L15.5 7l-2-2H19z" fill-rule="evenodd"/></svg>',
  12738. 'non-breaking': '<svg width="24" height="24"><path d="M11 11H8a1 1 0 1 1 0-2h3V6c0-.6.4-1 1-1s1 .4 1 1v3h3c.6 0 1 .4 1 1s-.4 1-1 1h-3v3c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-3zm10 4v5H3v-5c0-.6.4-1 1-1s1 .4 1 1v3h14v-3c0-.6.4-1 1-1s1 .4 1 1z" fill-rule="evenodd"/></svg>',
  12739. 'notice': '<svg width="24" height="24"><path d="M17.8 9.8L15.4 4 20 8.5v7L15.5 20h-7L4 15.5v-7L8.5 4h7l2.3 5.8zm0 0l2.2 5.7-2.3-5.8zM13 17v-2h-2v2h2zm0-4V7h-2v6h2z" fill-rule="evenodd"/></svg>',
  12740. 'ordered-list-rtl': '<svg width="24" height="24"><path d="M6 17h8a1 1 0 0 1 0 2H6a1 1 0 0 1 0-2zm0-6h8a1 1 0 0 1 0 2H6a1 1 0 0 1 0-2zm0-6h8a1 1 0 0 1 0 2H6a1 1 0 1 1 0-2zm13-1v3.5a.5.5 0 1 1-1 0V5h-.5a.5.5 0 1 1 0-1H19zm-1 8.8l.2.2h1.3a.5.5 0 1 1 0 1h-1.6a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0-.2-.2h-1.3a.5.5 0 0 1-.5-.5c0-.3.2-.5.5-.5h1.6c.5 0 .9.4.9 1v.1c0 .4-.3.8-.6 1l-1.2.4-.2.3zm2 4.2v2c0 .6-.4 1-1 1h-1.5a.5.5 0 0 1 0-1h1.2a.3.3 0 1 0 0-.6h-1.3a.4.4 0 1 1 0-.8h1.3a.3.3 0 0 0 0-.6h-1.2a.5.5 0 1 1 0-1H19c.6 0 1 .4 1 1z" fill-rule="evenodd"/></svg>',
  12741. 'ordered-list': '<svg width="24" height="24"><path d="M10 17h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0-6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 1 1 0-2zM6 4v3.5c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.5V5h-.5a.5.5 0 0 1 0-1H6zm-1 8.8l.2.2h1.3c.3 0 .5.2.5.5s-.2.5-.5.5H4.9a1 1 0 0 1-.9-1V13c0-.4.3-.8.6-1l1.2-.4.2-.3a.2.2 0 0 0-.2-.2H4.5a.5.5 0 0 1-.5-.5c0-.3.2-.5.5-.5h1.6c.5 0 .9.4.9 1v.1c0 .4-.3.8-.6 1l-1.2.4-.2.3zM7 17v2c0 .6-.4 1-1 1H4.5a.5.5 0 0 1 0-1h1.2c.2 0 .3-.1.3-.3 0-.2-.1-.3-.3-.3H4.4a.4.4 0 1 1 0-.8h1.3c.2 0 .3-.1.3-.3 0-.2-.1-.3-.3-.3H4.5a.5.5 0 1 1 0-1H6c.6 0 1 .4 1 1z" fill-rule="evenodd"/></svg>',
  12742. 'orientation': '<svg width="24" height="24"><path d="M7.3 6.4L1 13l6.4 6.5 6.5-6.5-6.5-6.5zM3.7 13l3.6-3.7L11 13l-3.7 3.7-3.6-3.7zM12 6l2.8 2.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0L9.2 5.7a.8.8 0 0 1 0-1.2L13.6.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L12 4h1a9 9 0 1 1-4.3 16.9l1.5-1.5A7 7 0 1 0 13 6h-1z" fill-rule="nonzero"/></svg>',
  12743. 'outdent': '<svg width="24" height="24"><path d="M7 5h12c.6 0 1 .4 1 1s-.4 1-1 1H7a1 1 0 1 1 0-2zm5 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm0 4h7c.6 0 1 .4 1 1s-.4 1-1 1h-7a1 1 0 0 1 0-2zm-5 4h12a1 1 0 0 1 0 2H7a1 1 0 0 1 0-2zm1.6-3.8a1 1 0 0 1-1.2 1.6l-3-2a1 1 0 0 1 0-1.6l3-2a1 1 0 0 1 1.2 1.6L6.8 12l1.8 1.2z" fill-rule="evenodd"/></svg>',
  12744. 'page-break': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M5 11c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h1c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2zm4 0c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h1c.6 0 1 .4 1 1s-.4 1-1 1h-1a1 1 0 0 1 0-2zm4 0c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zM7 3v5h10V3c0-.6.4-1 1-1s1 .4 1 1v7H5V3c0-.6.4-1 1-1s1 .4 1 1zM6 22a1 1 0 0 1-1-1v-7h14v7c0 .6-.4 1-1 1a1 1 0 0 1-1-1v-5H7v5c0 .6-.4 1-1 1z"/></g></svg>',
  12745. 'paste-text': '<svg width="24" height="24"><path d="M18 9V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h3V9h9zM9 20H6a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2h3.2A3 3 0 0 1 12 1a3 3 0 0 1 2.8 2H18a2 2 0 0 1 2 2v4h1v12H9v-1zm1.5-9.5v9h9v-9h-9zM12 3a1 1 0 0 0-1 1c0 .5.4 1 1 1s1-.5 1-1-.4-1-1-1zm0 9h6v2h-.5l-.5-1h-1v4h.8v1h-3.6v-1h.8v-4h-1l-.5 1H12v-2z" fill-rule="nonzero"/></svg>',
  12746. 'paste': '<svg width="24" height="24"><path d="M18 9V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h3V9h9zM9 20H6a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2h3.2A3 3 0 0 1 12 1a3 3 0 0 1 2.8 2H18a2 2 0 0 1 2 2v4h1v12H9v-1zm1.5-9.5v9h9v-9h-9zM12 3a1 1 0 0 0-1 1c0 .5.4 1 1 1s1-.5 1-1-.4-1-1-1z" fill-rule="nonzero"/></svg>',
  12747. 'permanent-pen': '<svg width="24" height="24"><path d="M10.5 17.5L8 20H3v-3l3.5-3.5a2 2 0 0 1 0-3L14 3l1 1-7.3 7.3a1 1 0 0 0 0 1.4l3.6 3.6c.4.4 1 .4 1.4 0L20 9l1 1-7.6 7.6a2 2 0 0 1-2.8 0l-.1-.1z" fill-rule="nonzero"/></svg>',
  12748. 'plus': '<svg width="24" height="24"><g fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke="#000" stroke-width="2"><path d="M12 5v14M5 12h14"/></g></svg>',
  12749. 'preferences': '<svg width="24" height="24"><path d="M20.1 13.5l-1.9.2a5.8 5.8 0 0 1-.6 1.5l1.2 1.5c.4.4.3 1 0 1.4l-.7.7a1 1 0 0 1-1.4 0l-1.5-1.2a6.2 6.2 0 0 1-1.5.6l-.2 1.9c0 .5-.5.9-1 .9h-1a1 1 0 0 1-1-.9l-.2-1.9a5.8 5.8 0 0 1-1.5-.6l-1.5 1.2a1 1 0 0 1-1.4 0l-.7-.7a1 1 0 0 1 0-1.4l1.2-1.5a6.2 6.2 0 0 1-.6-1.5l-1.9-.2a1 1 0 0 1-.9-1v-1c0-.5.4-1 .9-1l1.9-.2a5.8 5.8 0 0 1 .6-1.5L5.2 7.3a1 1 0 0 1 0-1.4l.7-.7a1 1 0 0 1 1.4 0l1.5 1.2a6.2 6.2 0 0 1 1.5-.6l.2-1.9c0-.5.5-.9 1-.9h1c.5 0 1 .4 1 .9l.2 1.9a5.8 5.8 0 0 1 1.5.6l1.5-1.2a1 1 0 0 1 1.4 0l.7.7c.3.4.4 1 0 1.4l-1.2 1.5a6.2 6.2 0 0 1 .6 1.5l1.9.2c.5 0 .9.5.9 1v1c0 .5-.4 1-.9 1zM12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z" fill-rule="evenodd"/></svg>',
  12750. 'preview': '<svg width="24" height="24"><path d="M3.5 12.5c.5.8 1.1 1.6 1.8 2.3 2 2 4.2 3.2 6.7 3.2s4.7-1.2 6.7-3.2a16.2 16.2 0 0 0 2.1-2.8 15.7 15.7 0 0 0-2.1-2.8c-2-2-4.2-3.2-6.7-3.2a9.3 9.3 0 0 0-6.7 3.2A16.2 16.2 0 0 0 3.2 12c0 .2.2.3.3.5zm-2.4-1l.7-1.2L4 7.8C6.2 5.4 8.9 4 12 4c3 0 5.8 1.4 8.1 3.8a18.2 18.2 0 0 1 2.8 3.7v1l-.7 1.2-2.1 2.5c-2.3 2.4-5 3.8-8.1 3.8-3 0-5.8-1.4-8.1-3.8a18.2 18.2 0 0 1-2.8-3.7 1 1 0 0 1 0-1zm12-3.3a2 2 0 1 0 2.7 2.6 4 4 0 1 1-2.6-2.6z" fill-rule="nonzero"/></svg>',
  12751. 'print': '<svg width="24" height="24"><path d="M18 8H6a3 3 0 0 0-3 3v6h2v3h14v-3h2v-6a3 3 0 0 0-3-3zm-1 10H7v-4h10v4zm.5-5c-.8 0-1.5-.7-1.5-1.5s.7-1.5 1.5-1.5 1.5.7 1.5 1.5-.7 1.5-1.5 1.5zm.5-8H6v2h12V5z" fill-rule="nonzero"/></svg>',
  12752. 'quote': '<svg width="24" height="24"><path d="M7.5 17h.9c.4 0 .7-.2.9-.6L11 13V8c0-.6-.4-1-1-1H6a1 1 0 0 0-1 1v4c0 .6.4 1 1 1h2l-1.3 2.7a1 1 0 0 0 .8 1.3zm8 0h.9c.4 0 .7-.2.9-.6L19 13V8c0-.6-.4-1-1-1h-4a1 1 0 0 0-1 1v4c0 .6.4 1 1 1h2l-1.3 2.7a1 1 0 0 0 .8 1.3z" fill-rule="nonzero"/></svg>',
  12753. 'redo': '<svg width="24" height="24"><path d="M17.6 10H12c-2.8 0-4.4 1.4-4.9 3.5-.4 2 .3 4 1.4 4.6a1 1 0 1 1-1 1.8c-2-1.2-2.9-4.1-2.3-6.8.6-3 3-5.1 6.8-5.1h5.6l-3.3-3.3a1 1 0 1 1 1.4-1.4l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4l3.3-3.3z" fill-rule="nonzero"/></svg>',
  12754. 'reload': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M5 22.1l-1.2-4.7v-.2a1 1 0 0 1 1-1l5 .4a1 1 0 1 1-.2 2l-2.2-.2a7.8 7.8 0 0 0 8.4.2 7.5 7.5 0 0 0 3.5-6.4 1 1 0 1 1 2 0 9.5 9.5 0 0 1-4.5 8 9.9 9.9 0 0 1-10.2 0l.4 1.4a1 1 0 1 1-2 .5zM13.6 7.4c0-.5.5-1 1-.9l2.8.2a8 8 0 0 0-9.5-1 7.5 7.5 0 0 0-3.6 7 1 1 0 0 1-2 0 9.5 9.5 0 0 1 4.5-8.6 10 10 0 0 1 10.9.3l-.3-1a1 1 0 0 1 2-.5l1.1 4.8a1 1 0 0 1-1 1.2l-5-.4a1 1 0 0 1-.9-1z"/></g></svg>',
  12755. 'remove-formatting': '<svg width="24" height="24"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8zM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1z" fill-rule="evenodd"/></svg>',
  12756. 'remove': '<svg width="24" height="24"><path d="M16 7h3a1 1 0 0 1 0 2h-1v9a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3V9H5a1 1 0 1 1 0-2h3V6a3 3 0 0 1 3-3h2a3 3 0 0 1 3 3v1zm-2 0V6c0-.6-.4-1-1-1h-2a1 1 0 0 0-1 1v1h4zm2 2H8v9c0 .6.4 1 1 1h6c.6 0 1-.4 1-1V9zm-7 3a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4zm4 0a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4z" fill-rule="nonzero"/></svg>',
  12757. 'resize-handle': '<svg width="10" height="10"><g fill-rule="nonzero"><path d="M8.1 1.1A.5.5 0 1 1 9 2l-7 7A.5.5 0 1 1 1 8l7-7zM8.1 5.1A.5.5 0 1 1 9 6l-3 3A.5.5 0 1 1 5 8l3-3z"/></g></svg>',
  12758. 'resize': '<svg width="24" height="24"><path d="M4 5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h6c.3 0 .5.1.7.3.2.2.3.4.3.7 0 .3-.1.5-.3.7a1 1 0 0 1-.7.3H7.4L18 16.6V13c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3.3 0 .5.1.7.3.2.2.3.4.3.7v6c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3h-6a1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h3.6L6 7.4V11c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3 1 1 0 0 1-.7-.3A1 1 0 0 1 4 11V5z" fill-rule="evenodd"/></svg>',
  12759. 'restore-draft': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M17 13c0 .6-.4 1-1 1h-4V8c0-.6.4-1 1-1s1 .4 1 1v4h2c.6 0 1 .4 1 1z"/><path d="M4.7 10H9a1 1 0 0 1 0 2H3a1 1 0 0 1-1-1V5a1 1 0 1 1 2 0v3l2.5-2.4a9.2 9.2 0 0 1 10.8-1.5A9 9 0 0 1 13.4 21c-2.4.1-4.7-.7-6.5-2.2a1 1 0 1 1 1.3-1.5 7.2 7.2 0 0 0 11.6-3.7 7 7 0 0 0-3.5-7.7A7.2 7.2 0 0 0 8 7L4.7 10z" fill-rule="nonzero"/></g></svg>',
  12760. 'rotate-left': '<svg width="24" height="24"><path d="M4.7 10H9a1 1 0 0 1 0 2H3a1 1 0 0 1-1-1V5a1 1 0 1 1 2 0v3l2.5-2.4a9.2 9.2 0 0 1 10.8-1.5A9 9 0 0 1 13.4 21c-2.4.1-4.7-.7-6.5-2.2a1 1 0 1 1 1.3-1.5 7.2 7.2 0 0 0 11.6-3.7 7 7 0 0 0-3.5-7.7A7.2 7.2 0 0 0 8 7L4.7 10z" fill-rule="nonzero"/></svg>',
  12761. 'rotate-right': '<svg width="24" height="24"><path d="M20 8V5a1 1 0 0 1 2 0v6c0 .6-.4 1-1 1h-6a1 1 0 0 1 0-2h4.3L16 7A7.2 7.2 0 0 0 7.7 6a7 7 0 0 0 3 13.1c1.9.1 3.7-.5 5-1.7a1 1 0 0 1 1.4 1.5A9.2 9.2 0 0 1 2.2 14c-.9-3.9 1-8 4.5-9.9 3.5-1.9 8-1.3 10.8 1.5L20 8z" fill-rule="nonzero"/></svg>',
  12762. 'rtl': '<svg width="24" height="24"><path d="M8 5h8v2h-2v12h-2V7h-2v12H8v-7c-.5 0-1 0-1.4-.3A3.4 3.4 0 0 1 4.8 10a3.3 3.3 0 0 1 0-2.8 3.4 3.4 0 0 1 1.8-1.8L8 5zm12 11.2a1 1 0 1 1-1 1.6l-3-2a1 1 0 0 1 0-1.6l3-2a1 1 0 1 1 1 1.6L18.4 15l1.8 1.2z" fill-rule="evenodd"/></svg>',
  12763. 'save': '<svg width="24" height="24"><path d="M5 16h14a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2zm0 2v2h14v-2H5zm10 0h2v2h-2v-2zm-4-6.4L8.7 9.3a1 1 0 1 0-1.4 1.4l4 4c.4.4 1 .4 1.4 0l4-4a1 1 0 1 0-1.4-1.4L13 11.6V4a1 1 0 0 0-2 0v7.6z" fill-rule="nonzero"/></svg>',
  12764. 'search': '<svg width="24" height="24"><path d="M16 17.3a8 8 0 1 1 1.4-1.4l4.3 4.4a1 1 0 0 1-1.4 1.4l-4.4-4.3zm-5-.3a6 6 0 1 0 0-12 6 6 0 0 0 0 12z" fill-rule="nonzero"/></svg>',
  12765. 'select-all': '<svg width="24" height="24"><path d="M3 5h2V3a2 2 0 0 0-2 2zm0 8h2v-2H3v2zm4 8h2v-2H7v2zM3 9h2V7H3v2zm10-6h-2v2h2V3zm6 0v2h2a2 2 0 0 0-2-2zM5 21v-2H3c0 1.1.9 2 2 2zm-2-4h2v-2H3v2zM9 3H7v2h2V3zm2 18h2v-2h-2v2zm8-8h2v-2h-2v2zm0 8a2 2 0 0 0 2-2h-2v2zm0-12h2V7h-2v2zm0 8h2v-2h-2v2zm-4 4h2v-2h-2v2zm0-16h2V3h-2v2zM7 17h10V7H7v10zm2-8h6v6H9V9z" fill-rule="nonzero"/></svg>',
  12766. 'selected': '<svg width="24" height="24"><path fill-rule="nonzero" d="M6 4h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2zm3.6 10.9L7 12.3a.7.7 0 0 0-1 1L9.6 17 18 8.6a.7.7 0 0 0 0-1 .7.7 0 0 0-1 0l-7.4 7.3z"/></svg>',
  12767. 'settings': '<svg width="24" height="24"><path d="M11 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8v.3c0 .2 0 .3-.2.5l-.6.2H7.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6V8H5a1 1 0 1 1 0-2h2v-.3c0-.2 0-.3.2-.5l.5-.2h2.5c.3 0 .4 0 .6.2l.2.5V6zM8 8h2V6H8v2zm9 2.8v.2h2c.6 0 1 .4 1 1s-.4 1-1 1h-2v.3c0 .2 0 .3-.2.5l-.6.2h-2.4c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6V13H5a1 1 0 0 1 0-2h8v-.3c0-.2 0-.3.2-.5l.6-.2h2.4c.3 0 .4 0 .6.2l.2.6zM14 13h2v-2h-2v2zm-3 2.8v.2h8c.6 0 1 .4 1 1s-.4 1-1 1h-8v.3c0 .2 0 .3-.2.5l-.6.2H7.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6V18H5a1 1 0 0 1 0-2h2v-.3c0-.2 0-.3.2-.5l.5-.2h2.5c.3 0 .4 0 .6.2l.2.6zM8 18h2v-2H8v2z" fill-rule="evenodd"/></svg>',
  12768. 'sharpen': '<svg width="24" height="24"><path d="M16 6l4 4-8 9-8-9 4-4h8zm-4 10.2l5.5-6.2-.1-.1H12v-.3h5.1l-.2-.2H12V9h4.6l-.2-.2H12v-.3h4.1l-.2-.2H12V8h3.6l-.2-.2H8.7L6.5 10l.1.1H12v.3H6.9l.2.2H12v.3H7.3l.2.2H12v.3H7.7l.3.2h4v.3H8.2l.2.2H12v.3H8.6l.3.2H12v.3H9l.3.2H12v.3H9.5l.2.2H12v.3h-2l.2.2H12v.3h-1.6l.2.2H12v.3h-1.1l.2.2h.9v.3h-.7l.2.2h.5v.3h-.3l.3.2z" fill-rule="evenodd"/></svg>',
  12769. 'sourcecode': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7zM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7z"/></g></svg>',
  12770. 'spell-check': '<svg width="24" height="24"><path d="M6 8v3H5V5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h2c.3 0 .5.1.7.3.2.2.3.4.3.7v6H8V8H6zm0-3v2h2V5H6zm13 0h-3v5h3v1h-3a1 1 0 0 1-.7-.3 1 1 0 0 1-.3-.7V5c0-.3.1-.5.3-.7.2-.2.4-.3.7-.3h3v1zm-5 1.5l-.1.7c-.1.2-.3.3-.6.3.3 0 .5.1.6.3l.1.7V10c0 .3-.1.5-.3.7a1 1 0 0 1-.7.3h-3V4h3c.3 0 .5.1.7.3.2.2.3.4.3.7v1.5zM13 10V8h-2v2h2zm0-3V5h-2v2h2zm3 5l1 1-6.5 7L7 15.5l1.3-1 2.2 2.2L16 12z" fill-rule="evenodd"/></svg>',
  12771. 'strike-through': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M15.6 8.5c-.5-.7-1-1.1-1.3-1.3-.6-.4-1.3-.6-2-.6-2.7 0-2.8 1.7-2.8 2.1 0 1.6 1.8 2 3.2 2.3 4.4.9 4.6 2.8 4.6 3.9 0 1.4-.7 4.1-5 4.1A6.2 6.2 0 0 1 7 16.4l1.5-1.1c.4.6 1.6 2 3.7 2 1.6 0 2.5-.4 3-1.2.4-.8.3-2-.8-2.6-.7-.4-1.6-.7-2.9-1-1-.2-3.9-.8-3.9-3.6C7.6 6 10.3 5 12.4 5c2.9 0 4.2 1.6 4.7 2.4l-1.5 1.1z"/><path d="M5 11h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2z" fill-rule="nonzero"/></g></svg>',
  12772. 'subscript': '<svg width="24" height="24"><path d="M10.4 10l4.6 4.6-1.4 1.4L9 11.4 4.4 16 3 14.6 7.6 10 3 5.4 4.4 4 9 8.6 13.6 4 15 5.4 10.4 10zM21 19h-5v-1l1-.8 1.7-1.6c.3-.4.5-.8.5-1.2 0-.3 0-.6-.2-.7-.2-.2-.5-.3-.9-.3a2 2 0 0 0-.8.2l-.7.3-.4-1.1 1-.6 1.2-.2c.8 0 1.4.3 1.8.7.4.4.6.9.6 1.5s-.2 1.1-.5 1.6a8 8 0 0 1-1.3 1.3l-.6.6h2.6V19z" fill-rule="nonzero"/></svg>',
  12773. 'superscript': '<svg width="24" height="24"><path d="M15 9.4L10.4 14l4.6 4.6-1.4 1.4L9 15.4 4.4 20 3 18.6 7.6 14 3 9.4 4.4 8 9 12.6 13.6 8 15 9.4zm5.9 1.6h-5v-1l1-.8 1.7-1.6c.3-.5.5-.9.5-1.3 0-.3 0-.5-.2-.7-.2-.2-.5-.3-.9-.3l-.8.2-.7.4-.4-1.2c.2-.2.5-.4 1-.5.3-.2.8-.2 1.2-.2.8 0 1.4.2 1.8.6.4.4.6 1 .6 1.6 0 .5-.2 1-.5 1.5l-1.3 1.4-.6.5h2.6V11z" fill-rule="nonzero"/></svg>',
  12774. 'table-cell-properties': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm10 10h-4v3h4v-3zm0-8h-4v3h4V7zM9 7H5v3h4V7zm-4 4v3h4v-3H5zm10 0v3h4v-3h-4zm0-1h4V7h-4v3zM5 15v3h4v-3H5zm10 3h4v-3h-4v3z" fill-rule="evenodd"/></svg>',
  12775. 'table-cell-select-all': '<svg width="24" height="24"><path d="M12.5 5.5v6h6v-6h-6zm-1 0h-6v6h6v-6zm1 13h6v-6h-6v6zm-1 0v-6h-6v6h6zm-7-14h15v15h-15v-15z" fill-rule="nonzero"/></svg>',
  12776. 'table-cell-select-inner': '<svg width="24" height="24"><g fill-rule="nonzero"><path d="M5.5 5.5v13h13v-13h-13zm-1-1h15v15h-15v-15z" opacity=".2"/><path d="M11.5 11.5v-7h1v7h7v1h-7v7h-1v-7h-7v-1h7z"/></g></svg>',
  12777. 'table-delete-column': '<svg width="24" height="24"><path d="M9 11.2l1 1v.2l-1 1v-2.2zm5 1l1-1v2.2l-1-1v-.2zM20 5v14H4V5h16zm-1 2h-4v.8l-.2-.2-.8.8V7h-4v1.4l-.8-.8-.2.2V7H5v11h4v-1.8l.5.5.5-.4V18h4v-1.8l.8.8.2-.3V18h4V7zm-3.9 3.4l-1.8 1.9 1.8 1.9c.4.3.4.9 0 1.2-.3.3-.8.3-1.2 0L12 13.5l-1.8 1.9a.8.8 0 0 1-1.2 0 .9.9 0 0 1 0-1.2l1.8-1.9-1.9-2a.9.9 0 0 1 1.2-1.2l2 2 1.8-1.8c.3-.4.9-.4 1.2 0a.8.8 0 0 1 0 1.1z" fill-rule="evenodd"/></svg>',
  12778. 'table-delete-row': '<svg width="24" height="24"><path d="M16.7 8.8l1.1 1.2-2.4 2.5L18 15l-1.2 1.2-2.5-2.5-2.4 2.5-1.3-1.2 2.5-2.5-2.5-2.5 1.2-1.3 2.6 2.6 2.4-2.5zM4 5h16v14H4V5zm15 5V7H5v3h4.8l1 1H5v3h5.8l-1 1H5v3h14v-3h-.4l-1-1H19v-3h-1.3l1-1h.3z" fill-rule="evenodd"/></svg>',
  12779. 'table-delete-table': '<svg width="24" height="26"><path d="M4 6h16v14H4V6zm1 2v11h14V8H5zm11.7 8.7l-1.5 1.5L12 15l-3.3 3.2-1.4-1.5 3.2-3.2-3.3-3.2 1.5-1.5L12 12l3.2-3.2 1.5 1.5-3.2 3.2 3.2 3.2z" fill-rule="evenodd"/></svg>',
  12780. 'table-insert-column-after': '<svg width="24" height="24"><path d="M14.3 9c.4 0 .7.3.7.6v2.2h2.1c.4 0 .7.3.7.7 0 .4-.3.7-.7.7H15v2.2c0 .3-.3.6-.7.6a.7.7 0 0 1-.6-.6v-2.2h-2.2a.7.7 0 0 1 0-1.4h2.2V9.6c0-.3.3-.6.6-.6zM4 5h16v14H4V5zm5 13v-3H5v3h4zm0-4v-3H5v3h4zm0-4V7H5v3h4zm10 8V7h-9v11h9z" fill-rule="evenodd"/></svg>',
  12781. 'table-insert-column-before': '<svg width="24" height="24"><path d="M9.7 16a.7.7 0 0 1-.7-.6v-2.2H6.9a.7.7 0 0 1 0-1.4H9V9.6c0-.3.3-.6.7-.6.3 0 .6.3.6.6v2.2h2.2c.4 0 .8.3.8.7 0 .4-.4.7-.8.7h-2.2v2.2c0 .3-.3.6-.6.6zM4 5h16v14H4V5zm10 13V7H5v11h9zm5 0v-3h-4v3h4zm0-4v-3h-4v3h4zm0-4V7h-4v3h4z" fill-rule="evenodd"/></svg>',
  12782. 'table-insert-row-above': '<svg width="24" height="24"><path d="M14.8 10.5c0 .3-.2.5-.5.5h-1.8v1.8c0 .3-.2.5-.5.5a.5.5 0 0 1-.5-.6V11H9.7a.5.5 0 0 1 0-1h1.8V8.3c0-.3.2-.6.5-.6s.5.3.5.6V10h1.8c.3 0 .5.2.5.5zM4 5h16v14H4V5zm5 13v-3H5v3h4zm5 0v-3h-4v3h4zm5 0v-3h-4v3h4zm0-4V7H5v7h14z" fill-rule="evenodd"/></svg>',
  12783. 'table-insert-row-after': '<svg width="24" height="24"><path d="M9.2 14.5c0-.3.2-.5.5-.5h1.8v-1.8c0-.3.2-.5.5-.5s.5.2.5.6V14h1.8c.3 0 .5.2.5.5s-.2.5-.5.5h-1.8v1.7c0 .3-.2.6-.5.6a.5.5 0 0 1-.5-.6V15H9.7a.5.5 0 0 1-.5-.5zM4 5h16v14H4V5zm6 2v3h4V7h-4zM5 7v3h4V7H5zm14 11v-7H5v7h14zm0-8V7h-4v3h4z" fill-rule="evenodd"/></svg>',
  12784. 'table-left-header': '<svg width="24" height="24"><path d="M4 5h16v13H4V5zm10 12v-3h-4v3h4zm0-4v-3h-4v3h4zm0-4V6h-4v3h4zm5 8v-3h-4v3h4zm0-4v-3h-4v3h4zm0-4V6h-4v3h4z" fill-rule="evenodd"/></svg>',
  12785. 'table-merge-cells': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm6 13h9v-7h-9v7zm4-11h-4v3h4V7zM9 7H5v3h4V7zm-4 4v3h4v-3H5zm10-1h4V7h-4v3zM5 15v3h4v-3H5z" fill-rule="evenodd"/></svg>',
  12786. 'table-row-properties': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm10 10h-4v3h4v-3zm0-8h-4v3h4V7zM9 7H5v3h4V7zm6 3h4V7h-4v3zM5 15v3h4v-3H5zm10 3h4v-3h-4v3z" fill-rule="evenodd"/></svg>',
  12787. 'table-split-cells': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm6 2v3h4V7h-4zM9 18v-3H5v3h4zm0-4v-3H5v3h4zm0-4V7H5v3h4zm10 8v-7h-9v7h9zm0-8V7h-4v3h4zm-3.5 4.5l1.5 1.6c.3.2.3.7 0 1-.2.2-.7.2-1 0l-1.5-1.6-1.6 1.5c-.2.3-.7.3-1 0a.7.7 0 0 1 0-1l1.6-1.5-1.5-1.6a.7.7 0 0 1 1-1l1.5 1.6 1.6-1.5c.2-.3.7-.3 1 0 .2.2.2.7 0 1l-1.6 1.5z" fill-rule="evenodd"/></svg>',
  12788. 'table-top-header': '<svg width="24" height="24"><path d="M4 5h16v13H4V5zm5 12v-3H5v3h4zm0-4v-3H5v3h4zm5 4v-3h-4v3h4zm0-4v-3h-4v3h4zm5 4v-3h-4v3h4zm0-4v-3h-4v3h4z" fill-rule="evenodd"/></svg>',
  12789. 'table': '<svg width="24" height="24"><path d="M4 5h16v14H4V5zm6 9h4v-3h-4v3zm4 1h-4v3h4v-3zm0-8h-4v3h4V7zM9 7H5v3h4V7zm-4 4v3h4v-3H5zm10 0v3h4v-3h-4zm0-1h4V7h-4v3zM5 15v3h4v-3H5zm10 3h4v-3h-4v3z" fill-rule="evenodd"/></svg>',
  12790. 'template': '<svg width="24" height="24"><path d="M19 19v-1H5v1h14zM9 16v-4a5 5 0 1 1 6 0v4h4a2 2 0 0 1 2 2v3H3v-3c0-1.1.9-2 2-2h4zm4 0v-5l.8-.6a3 3 0 1 0-3.6 0l.8.6v5h2z" fill-rule="nonzero"/></svg>',
  12791. 'temporary-placeholder': '<svg width="24" height="24"><g fill-rule="evenodd"><path d="M9 7.6V6h2.5V4.5a.5.5 0 1 1 1 0V6H15v1.6a8 8 0 1 1-6 0zm-2.6 5.3a.5.5 0 0 0 .3.6c.3 0 .6 0 .6-.3l.1-.2a5 5 0 0 1 3.3-2.8c.3-.1.4-.4.4-.6-.1-.3-.4-.5-.6-.4a6 6 0 0 0-4.1 3.7z"/><circle cx="14" cy="4" r="1"/><circle cx="12" cy="2" r="1"/><circle cx="10" cy="4" r="1"/></g></svg>',
  12792. 'text-color': '<svg width="24" height="24"><g fill-rule="evenodd"><path id="tox-icon-text-color__color" d="M3 18h18v3H3z"/><path d="M8.7 16h-.8a.5.5 0 0 1-.5-.6l2.7-9c.1-.3.3-.4.5-.4h2.8c.2 0 .4.1.5.4l2.7 9a.5.5 0 0 1-.5.6h-.8a.5.5 0 0 1-.4-.4l-.7-2.2c0-.3-.3-.4-.5-.4h-3.4c-.2 0-.4.1-.5.4l-.7 2.2c0 .3-.2.4-.4.4zm2.6-7.6l-.6 2a.5.5 0 0 0 .5.6h1.6a.5.5 0 0 0 .5-.6l-.6-2c0-.3-.3-.4-.5-.4h-.4c-.2 0-.4.1-.5.4z"/></g></svg>',
  12793. 'toc': '<svg width="24" height="24"><path d="M5 5c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 1 1 0-2zm3 0h11c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 1 1 0-2zm-3 8c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h11c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2zm0-4c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 1 1 0-2zm3 0h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm-3 8c.6 0 1 .4 1 1s-.4 1-1 1a1 1 0 0 1 0-2zm3 0h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12794. 'translate': '<svg width="24" height="24"><path d="M12.7 14.3l-.3.7-.4.7-2.2-2.2-3.1 3c-.3.4-.8.4-1 0a.7.7 0 0 1 0-1l3.1-3A12.4 12.4 0 0 1 6.7 9H8a10.1 10.1 0 0 0 1.7 2.4c.5-.5 1-1.1 1.4-1.8l.9-2H4.7a.7.7 0 1 1 0-1.5h4.4v-.7c0-.4.3-.8.7-.8.4 0 .7.4.7.8v.7H15c.4 0 .8.3.8.7 0 .4-.4.8-.8.8h-1.4a12.3 12.3 0 0 1-1 2.4 13.5 13.5 0 0 1-1.7 2.3l1.9 1.8zm4.3-3l2.7 7.3a.5.5 0 0 1-.4.7 1 1 0 0 1-1-.7l-.6-1.5h-3.4l-.6 1.5a1 1 0 0 1-1 .7.5.5 0 0 1-.4-.7l2.7-7.4a1 1 0 1 1 2 0zm-2.2 4.4h2.4L16 12.5l-1.2 3.2z" fill-rule="evenodd"/></svg>',
  12795. 'underline': '<svg width="24" height="24"><path d="M16 5c.6 0 1 .4 1 1v5.5a4 4 0 0 1-.4 1.8l-1 1.4a5.3 5.3 0 0 1-5.5 1 5 5 0 0 1-1.6-1c-.5-.4-.8-.9-1.1-1.4a4 4 0 0 1-.4-1.8V6c0-.6.4-1 1-1s1 .4 1 1v5.5c0 .3 0 .6.2 1l.6.7a3.3 3.3 0 0 0 2.2.8 3.4 3.4 0 0 0 2.2-.8c.3-.2.4-.5.6-.8l.2-.9V6c0-.6.4-1 1-1zM8 17h8c.6 0 1 .4 1 1s-.4 1-1 1H8a1 1 0 0 1 0-2z" fill-rule="evenodd"/></svg>',
  12796. 'undo': '<svg width="24" height="24"><path d="M6.4 8H12c3.7 0 6.2 2 6.8 5.1.6 2.7-.4 5.6-2.3 6.8a1 1 0 0 1-1-1.8c1.1-.6 1.8-2.7 1.4-4.6-.5-2.1-2.1-3.5-4.9-3.5H6.4l3.3 3.3a1 1 0 1 1-1.4 1.4l-5-5a1 1 0 0 1 0-1.4l5-5a1 1 0 0 1 1.4 1.4L6.4 8z" fill-rule="nonzero"/></svg>',
  12797. 'unlink': '<svg width="24" height="24"><path d="M6.2 12.3a1 1 0 0 1 1.4 1.4l-2 2a2 2 0 1 0 2.6 2.8l4.8-4.8a1 1 0 0 0 0-1.4 1 1 0 1 1 1.4-1.3 2.9 2.9 0 0 1 0 4L9.6 20a3.9 3.9 0 0 1-5.5-5.5l2-2zm11.6-.6a1 1 0 0 1-1.4-1.4l2.1-2a2 2 0 1 0-2.7-2.8L11 10.3a1 1 0 0 0 0 1.4A1 1 0 1 1 9.6 13a2.9 2.9 0 0 1 0-4L14.4 4a3.9 3.9 0 0 1 5.5 5.5l-2 2zM7.6 6.3a.8.8 0 0 1-1 1.1L3.3 4.2a.7.7 0 1 1 1-1l3.2 3.1zM5.1 8.6a.8.8 0 0 1 0 1.5H3a.8.8 0 0 1 0-1.5H5zm5-3.5a.8.8 0 0 1-1.5 0V3a.8.8 0 0 1 1.5 0V5zm6 11.8a.8.8 0 0 1 1-1l3.2 3.2a.8.8 0 0 1-1 1L16 17zm-2.2 2a.8.8 0 0 1 1.5 0V21a.8.8 0 0 1-1.5 0V19zm5-3.5a.7.7 0 1 1 0-1.5H21a.8.8 0 0 1 0 1.5H19z" fill-rule="nonzero"/></svg>',
  12798. 'unlock': '<svg width="24" height="24"><path d="M16 5c.8 0 1.5.3 2.1.9.6.6.9 1.3.9 2.1v3h-2V8a1 1 0 0 0-.3-.7A1 1 0 0 0 16 7h-2a1 1 0 0 0-.7.3 1 1 0 0 0-.3.7v3h.3c.2 0 .3 0 .5.2l.2.6v7.4c0 .3 0 .4-.2.6l-.6.2H4.8c-.3 0-.4 0-.6-.2a.7.7 0 0 1-.2-.6v-7.4c0-.3 0-.4.2-.6l.5-.2H11V8c0-.8.3-1.5.9-2.1.6-.6 1.3-.9 2.1-.9h2z" fill-rule="evenodd"/></svg>',
  12799. 'unordered-list': '<svg width="24" height="24"><path d="M11 5h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zm0 6h8c.6 0 1 .4 1 1s-.4 1-1 1h-8a1 1 0 0 1 0-2zM4.5 6c0-.4.1-.8.4-1 .3-.4.7-.5 1.1-.5.4 0 .8.1 1 .4.4.3.5.7.5 1.1 0 .4-.1.8-.4 1-.3.4-.7.5-1.1.5-.4 0-.8-.1-1-.4-.4-.3-.5-.7-.5-1.1zm0 6c0-.4.1-.8.4-1 .3-.4.7-.5 1.1-.5.4 0 .8.1 1 .4.4.3.5.7.5 1.1 0 .4-.1.8-.4 1-.3.4-.7.5-1.1.5-.4 0-.8-.1-1-.4-.4-.3-.5-.7-.5-1.1zm0 6c0-.4.1-.8.4-1 .3-.4.7-.5 1.1-.5.4 0 .8.1 1 .4.4.3.5.7.5 1.1 0 .4-.1.8-.4 1-.3.4-.7.5-1.1.5-.4 0-.8-.1-1-.4-.4-.3-.5-.7-.5-1.1z" fill-rule="evenodd"/></svg>',
  12800. 'unselected': '<svg width="24" height="24"><path fill-rule="nonzero" d="M6 4h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2zm0 1a1 1 0 0 0-1 1v12c0 .6.4 1 1 1h12c.6 0 1-.4 1-1V6c0-.6-.4-1-1-1H6z"/></svg>',
  12801. 'upload': '<svg width="24" height="24"><path d="M18 19v-2a1 1 0 0 1 2 0v3c0 .6-.4 1-1 1H5a1 1 0 0 1-1-1v-3a1 1 0 0 1 2 0v2h12zM11 6.4L8.7 8.7a1 1 0 0 1-1.4-1.4l4-4a1 1 0 0 1 1.4 0l4 4a1 1 0 1 1-1.4 1.4L13 6.4V16a1 1 0 0 1-2 0V6.4z" fill-rule="nonzero"/></svg>',
  12802. 'user': '<svg width="24" height="24"><path d="M12 24a12 12 0 1 1 0-24 12 12 0 0 1 0 24zm-8.7-5.3a11 11 0 0 0 17.4 0C19.4 16.3 14.6 15 12 15c-2.6 0-7.4 1.3-8.7 3.7zM12 13c2.2 0 4-2 4-4.5S14.2 4 12 4 8 6 8 8.5 9.8 13 12 13z" fill-rule="nonzero"/></svg>',
  12803. 'visualblocks': '<svg width="24" height="24"><path d="M9 19v2H7v-2h2zm-4 0v2a2 2 0 0 1-2-2h2zm8 0v2h-2v-2h2zm8 0a2 2 0 0 1-2 2v-2h2zm-4 0v2h-2v-2h2zM15 7a1 1 0 0 1 0 2v7a1 1 0 0 1-2 0V9h-1v7a1 1 0 0 1-2 0v-4a2.5 2.5 0 0 1-.2-5H15zM5 15v2H3v-2h2zm16 0v2h-2v-2h2zM5 11v2H3v-2h2zm16 0v2h-2v-2h2zM5 7v2H3V7h2zm16 0v2h-2V7h2zM5 3v2H3c0-1.1.9-2 2-2zm8 0v2h-2V3h2zm6 0a2 2 0 0 1 2 2h-2V3zM9 3v2H7V3h2zm8 0v2h-2V3h2z" fill-rule="evenodd"/></svg>',
  12804. 'visualchars': '<svg width="24" height="24"><path d="M10 5h7a1 1 0 0 1 0 2h-1v11a1 1 0 0 1-2 0V7h-2v11a1 1 0 0 1-2 0v-6c-.5 0-1 0-1.4-.3A3.4 3.4 0 0 1 6.8 10a3.3 3.3 0 0 1 0-2.8 3.4 3.4 0 0 1 1.8-1.8L10 5z" fill-rule="evenodd"/></svg>',
  12805. 'warning': '<svg width="24" height="24"><path d="M19.8 18.3c.2.5.3.9 0 1.2-.1.3-.5.5-1 .5H5.2c-.5 0-.9-.2-1-.5-.3-.3-.2-.7 0-1.2L11 4.7l.5-.5.5-.2c.2 0 .3 0 .5.2.2 0 .3.3.5.5l6.8 13.6zM12 18c.3 0 .5-.1.7-.3.2-.2.3-.4.3-.7a1 1 0 0 0-.3-.7 1 1 0 0 0-.7-.3 1 1 0 0 0-.7.3 1 1 0 0 0-.3.7c0 .3.1.5.3.7.2.2.4.3.7.3zm.7-3l.3-4a1 1 0 0 0-.3-.7 1 1 0 0 0-.7-.3 1 1 0 0 0-.7.3 1 1 0 0 0-.3.7l.3 4h1.4z" fill-rule="evenodd"/></svg>',
  12806. 'zoom-in': '<svg width="24" height="24"><path d="M16 17.3a8 8 0 1 1 1.4-1.4l4.3 4.4a1 1 0 0 1-1.4 1.4l-4.4-4.3zm-5-.3a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm-1-9a1 1 0 0 1 2 0v6a1 1 0 0 1-2 0V8zm-2 4a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2H8z" fill-rule="nonzero"/></svg>',
  12807. 'zoom-out': '<svg width="24" height="24"><path d="M16 17.3a8 8 0 1 1 1.4-1.4l4.3 4.4a1 1 0 0 1-1.4 1.4l-4.4-4.3zm-5-.3a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm-3-5a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2H8z" fill-rule="nonzero"/></svg>'
  12808. };
  12809. };
  12810. var CreateIconManager = function () {
  12811. var lookup = {};
  12812. var add = function (id, iconPack) {
  12813. lookup[id] = iconPack;
  12814. };
  12815. var get = function (id) {
  12816. if (lookup[id]) {
  12817. return lookup[id];
  12818. }
  12819. return { icons: {} };
  12820. };
  12821. var has$1 = function (id) {
  12822. return has(lookup, id);
  12823. };
  12824. return {
  12825. add: add,
  12826. get: get,
  12827. has: has$1
  12828. };
  12829. };
  12830. var IconManager = CreateIconManager();
  12831. var PluginManager = AddOnManager$1.PluginManager;
  12832. var ThemeManager = AddOnManager$1.ThemeManager;
  12833. function Uploader(uploadStatus, settings) {
  12834. var pendingPromises = {};
  12835. var pathJoin = function (path1, path2) {
  12836. if (path1) {
  12837. return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
  12838. }
  12839. return path2;
  12840. };
  12841. var defaultHandler = function (blobInfo, success, failure, progress) {
  12842. var xhr, formData;
  12843. xhr = new domGlobals.XMLHttpRequest();
  12844. xhr.open('POST', settings.url);
  12845. xhr.withCredentials = settings.credentials;
  12846. xhr.upload.onprogress = function (e) {
  12847. progress(e.loaded / e.total * 100);
  12848. };
  12849. xhr.onerror = function () {
  12850. failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
  12851. };
  12852. xhr.onload = function () {
  12853. var json;
  12854. if (xhr.status < 200 || xhr.status >= 300) {
  12855. failure('HTTP Error: ' + xhr.status);
  12856. return;
  12857. }
  12858. json = JSON.parse(xhr.responseText);
  12859. if (!json || typeof json.location !== 'string') {
  12860. failure('Invalid JSON: ' + xhr.responseText);
  12861. return;
  12862. }
  12863. success(pathJoin(settings.basePath, json.location));
  12864. };
  12865. formData = new domGlobals.FormData();
  12866. formData.append('file', blobInfo.blob(), blobInfo.filename());
  12867. xhr.send(formData);
  12868. };
  12869. var noUpload = function () {
  12870. return new promiseObj(function (resolve) {
  12871. resolve([]);
  12872. });
  12873. };
  12874. var handlerSuccess = function (blobInfo, url) {
  12875. return {
  12876. url: url,
  12877. blobInfo: blobInfo,
  12878. status: true
  12879. };
  12880. };
  12881. var handlerFailure = function (blobInfo, error) {
  12882. return {
  12883. url: '',
  12884. blobInfo: blobInfo,
  12885. status: false,
  12886. error: error
  12887. };
  12888. };
  12889. var resolvePending = function (blobUri, result) {
  12890. Tools.each(pendingPromises[blobUri], function (resolve) {
  12891. resolve(result);
  12892. });
  12893. delete pendingPromises[blobUri];
  12894. };
  12895. var uploadBlobInfo = function (blobInfo, handler, openNotification) {
  12896. uploadStatus.markPending(blobInfo.blobUri());
  12897. return new promiseObj(function (resolve) {
  12898. var notification, progress;
  12899. var noop = function () {
  12900. };
  12901. try {
  12902. var closeNotification_1 = function () {
  12903. if (notification) {
  12904. notification.close();
  12905. progress = noop;
  12906. }
  12907. };
  12908. var success = function (url) {
  12909. closeNotification_1();
  12910. uploadStatus.markUploaded(blobInfo.blobUri(), url);
  12911. resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url));
  12912. resolve(handlerSuccess(blobInfo, url));
  12913. };
  12914. var failure = function (error) {
  12915. closeNotification_1();
  12916. uploadStatus.removeFailed(blobInfo.blobUri());
  12917. resolvePending(blobInfo.blobUri(), handlerFailure(blobInfo, error));
  12918. resolve(handlerFailure(blobInfo, error));
  12919. };
  12920. progress = function (percent) {
  12921. if (percent < 0 || percent > 100) {
  12922. return;
  12923. }
  12924. if (!notification) {
  12925. notification = openNotification();
  12926. }
  12927. notification.progressBar.value(percent);
  12928. };
  12929. handler(blobInfo, success, failure, progress);
  12930. } catch (ex) {
  12931. resolve(handlerFailure(blobInfo, ex.message));
  12932. }
  12933. });
  12934. };
  12935. var isDefaultHandler = function (handler) {
  12936. return handler === defaultHandler;
  12937. };
  12938. var pendingUploadBlobInfo = function (blobInfo) {
  12939. var blobUri = blobInfo.blobUri();
  12940. return new promiseObj(function (resolve) {
  12941. pendingPromises[blobUri] = pendingPromises[blobUri] || [];
  12942. pendingPromises[blobUri].push(resolve);
  12943. });
  12944. };
  12945. var uploadBlobs = function (blobInfos, openNotification) {
  12946. blobInfos = Tools.grep(blobInfos, function (blobInfo) {
  12947. return !uploadStatus.isUploaded(blobInfo.blobUri());
  12948. });
  12949. return promiseObj.all(Tools.map(blobInfos, function (blobInfo) {
  12950. return uploadStatus.isPending(blobInfo.blobUri()) ? pendingUploadBlobInfo(blobInfo) : uploadBlobInfo(blobInfo, settings.handler, openNotification);
  12951. }));
  12952. };
  12953. var upload = function (blobInfos, openNotification) {
  12954. return !settings.url && isDefaultHandler(settings.handler) ? noUpload() : uploadBlobs(blobInfos, openNotification);
  12955. };
  12956. if (isFunction(settings.handler) === false) {
  12957. settings.handler = defaultHandler;
  12958. }
  12959. return { upload: upload };
  12960. }
  12961. var blobUriToBlob = function (url) {
  12962. return new promiseObj(function (resolve, reject) {
  12963. var rejectWithError = function () {
  12964. reject('Cannot convert ' + url + ' to Blob. Resource might not exist or is inaccessible.');
  12965. };
  12966. try {
  12967. var xhr = new domGlobals.XMLHttpRequest();
  12968. xhr.open('GET', url, true);
  12969. xhr.responseType = 'blob';
  12970. xhr.onload = function () {
  12971. if (this.status === 200) {
  12972. resolve(this.response);
  12973. } else {
  12974. rejectWithError();
  12975. }
  12976. };
  12977. xhr.onerror = rejectWithError;
  12978. xhr.send();
  12979. } catch (ex) {
  12980. rejectWithError();
  12981. }
  12982. });
  12983. };
  12984. var parseDataUri = function (uri) {
  12985. var type, matches;
  12986. var uriParts = decodeURIComponent(uri).split(',');
  12987. matches = /data:([^;]+)/.exec(uriParts[0]);
  12988. if (matches) {
  12989. type = matches[1];
  12990. }
  12991. return {
  12992. type: type,
  12993. data: uriParts[1]
  12994. };
  12995. };
  12996. var dataUriToBlob = function (uri) {
  12997. return new promiseObj(function (resolve) {
  12998. var str, arr, i;
  12999. var uriParts = parseDataUri(uri);
  13000. try {
  13001. str = domGlobals.atob(uriParts.data);
  13002. } catch (e) {
  13003. resolve(new domGlobals.Blob([]));
  13004. return;
  13005. }
  13006. arr = new Uint8Array(str.length);
  13007. for (i = 0; i < arr.length; i++) {
  13008. arr[i] = str.charCodeAt(i);
  13009. }
  13010. resolve(new domGlobals.Blob([arr], { type: uriParts.type }));
  13011. });
  13012. };
  13013. var uriToBlob = function (url) {
  13014. if (url.indexOf('blob:') === 0) {
  13015. return blobUriToBlob(url);
  13016. }
  13017. if (url.indexOf('data:') === 0) {
  13018. return dataUriToBlob(url);
  13019. }
  13020. return null;
  13021. };
  13022. var blobToDataUri = function (blob) {
  13023. return new promiseObj(function (resolve) {
  13024. var reader = new domGlobals.FileReader();
  13025. reader.onloadend = function () {
  13026. resolve(reader.result);
  13027. };
  13028. reader.readAsDataURL(blob);
  13029. });
  13030. };
  13031. var Conversions = {
  13032. uriToBlob: uriToBlob,
  13033. blobToDataUri: blobToDataUri,
  13034. parseDataUri: parseDataUri
  13035. };
  13036. var count = 0;
  13037. var uniqueId = function (prefix) {
  13038. return (prefix || 'blobid') + count++;
  13039. };
  13040. var imageToBlobInfo = function (blobCache, img, resolve, reject) {
  13041. var base64, blobInfo;
  13042. if (img.src.indexOf('blob:') === 0) {
  13043. blobInfo = blobCache.getByUri(img.src);
  13044. if (blobInfo) {
  13045. resolve({
  13046. image: img,
  13047. blobInfo: blobInfo
  13048. });
  13049. } else {
  13050. Conversions.uriToBlob(img.src).then(function (blob) {
  13051. Conversions.blobToDataUri(blob).then(function (dataUri) {
  13052. base64 = Conversions.parseDataUri(dataUri).data;
  13053. blobInfo = blobCache.create(uniqueId(), blob, base64);
  13054. blobCache.add(blobInfo);
  13055. resolve({
  13056. image: img,
  13057. blobInfo: blobInfo
  13058. });
  13059. });
  13060. }, function (err) {
  13061. reject(err);
  13062. });
  13063. }
  13064. return;
  13065. }
  13066. base64 = Conversions.parseDataUri(img.src).data;
  13067. blobInfo = blobCache.findFirst(function (cachedBlobInfo) {
  13068. return cachedBlobInfo.base64() === base64;
  13069. });
  13070. if (blobInfo) {
  13071. resolve({
  13072. image: img,
  13073. blobInfo: blobInfo
  13074. });
  13075. } else {
  13076. Conversions.uriToBlob(img.src).then(function (blob) {
  13077. blobInfo = blobCache.create(uniqueId(), blob, base64);
  13078. blobCache.add(blobInfo);
  13079. resolve({
  13080. image: img,
  13081. blobInfo: blobInfo
  13082. });
  13083. }, function (err) {
  13084. reject(err);
  13085. });
  13086. }
  13087. };
  13088. var getAllImages = function (elm) {
  13089. return elm ? from$1(elm.getElementsByTagName('img')) : [];
  13090. };
  13091. function ImageScanner(uploadStatus, blobCache) {
  13092. var cachedPromises = {};
  13093. var findAll = function (elm, predicate) {
  13094. var images;
  13095. if (!predicate) {
  13096. predicate = constant(true);
  13097. }
  13098. images = filter(getAllImages(elm), function (img) {
  13099. var src = img.src;
  13100. if (!Env.fileApi) {
  13101. return false;
  13102. }
  13103. if (img.hasAttribute('data-mce-bogus')) {
  13104. return false;
  13105. }
  13106. if (img.hasAttribute('data-mce-placeholder')) {
  13107. return false;
  13108. }
  13109. if (!src || src === Env.transparentSrc) {
  13110. return false;
  13111. }
  13112. if (src.indexOf('blob:') === 0) {
  13113. return !uploadStatus.isUploaded(src) && predicate(img);
  13114. }
  13115. if (src.indexOf('data:') === 0) {
  13116. return predicate(img);
  13117. }
  13118. return false;
  13119. });
  13120. var promises = map(images, function (img) {
  13121. if (cachedPromises[img.src]) {
  13122. return new promiseObj(function (resolve) {
  13123. cachedPromises[img.src].then(function (imageInfo) {
  13124. if (typeof imageInfo === 'string') {
  13125. return imageInfo;
  13126. }
  13127. resolve({
  13128. image: img,
  13129. blobInfo: imageInfo.blobInfo
  13130. });
  13131. });
  13132. });
  13133. }
  13134. var newPromise = new promiseObj(function (resolve, reject) {
  13135. imageToBlobInfo(blobCache, img, resolve, reject);
  13136. }).then(function (result) {
  13137. delete cachedPromises[result.image.src];
  13138. return result;
  13139. }).catch(function (error) {
  13140. delete cachedPromises[img.src];
  13141. return error;
  13142. });
  13143. cachedPromises[img.src] = newPromise;
  13144. return newPromise;
  13145. });
  13146. return promiseObj.all(promises);
  13147. };
  13148. return { findAll: findAll };
  13149. }
  13150. var count$1 = 0;
  13151. var seed = function () {
  13152. var rnd = function () {
  13153. return Math.round(Math.random() * 4294967295).toString(36);
  13154. };
  13155. var now = new Date().getTime();
  13156. return 's' + now.toString(36) + rnd() + rnd() + rnd();
  13157. };
  13158. var uuid = function (prefix) {
  13159. return prefix + count$1++ + seed();
  13160. };
  13161. var Uuid = { uuid: uuid };
  13162. var BlobCache = function () {
  13163. var cache = [];
  13164. var mimeToExt = function (mime) {
  13165. var mimes = {
  13166. 'image/jpeg': 'jpg',
  13167. 'image/jpg': 'jpg',
  13168. 'image/gif': 'gif',
  13169. 'image/png': 'png'
  13170. };
  13171. return mimes[mime.toLowerCase()] || 'dat';
  13172. };
  13173. var create = function (o, blob, base64, filename) {
  13174. if (isString(o)) {
  13175. var id = o;
  13176. return toBlobInfo({
  13177. id: id,
  13178. name: filename,
  13179. blob: blob,
  13180. base64: base64
  13181. });
  13182. } else if (isObject(o)) {
  13183. return toBlobInfo(o);
  13184. } else {
  13185. throw new Error('Unknown input type');
  13186. }
  13187. };
  13188. var toBlobInfo = function (o) {
  13189. var id, name;
  13190. if (!o.blob || !o.base64) {
  13191. throw new Error('blob and base64 representations of the image are required for BlobInfo to be created');
  13192. }
  13193. id = o.id || Uuid.uuid('blobid');
  13194. name = o.name || id;
  13195. return {
  13196. id: constant(id),
  13197. name: constant(name),
  13198. filename: constant(name + '.' + mimeToExt(o.blob.type)),
  13199. blob: constant(o.blob),
  13200. base64: constant(o.base64),
  13201. blobUri: constant(o.blobUri || domGlobals.URL.createObjectURL(o.blob)),
  13202. uri: constant(o.uri)
  13203. };
  13204. };
  13205. var add = function (blobInfo) {
  13206. if (!get(blobInfo.id())) {
  13207. cache.push(blobInfo);
  13208. }
  13209. };
  13210. var get = function (id) {
  13211. return findFirst(function (cachedBlobInfo) {
  13212. return cachedBlobInfo.id() === id;
  13213. });
  13214. };
  13215. var findFirst = function (predicate) {
  13216. return filter(cache, predicate)[0];
  13217. };
  13218. var getByUri = function (blobUri) {
  13219. return findFirst(function (blobInfo) {
  13220. return blobInfo.blobUri() === blobUri;
  13221. });
  13222. };
  13223. var removeByUri = function (blobUri) {
  13224. cache = filter(cache, function (blobInfo) {
  13225. if (blobInfo.blobUri() === blobUri) {
  13226. domGlobals.URL.revokeObjectURL(blobInfo.blobUri());
  13227. return false;
  13228. }
  13229. return true;
  13230. });
  13231. };
  13232. var destroy = function () {
  13233. each(cache, function (cachedBlobInfo) {
  13234. domGlobals.URL.revokeObjectURL(cachedBlobInfo.blobUri());
  13235. });
  13236. cache = [];
  13237. };
  13238. return {
  13239. create: create,
  13240. add: add,
  13241. get: get,
  13242. getByUri: getByUri,
  13243. findFirst: findFirst,
  13244. removeByUri: removeByUri,
  13245. destroy: destroy
  13246. };
  13247. };
  13248. function UploadStatus () {
  13249. var PENDING = 1, UPLOADED = 2;
  13250. var blobUriStatuses = {};
  13251. var createStatus = function (status, resultUri) {
  13252. return {
  13253. status: status,
  13254. resultUri: resultUri
  13255. };
  13256. };
  13257. var hasBlobUri = function (blobUri) {
  13258. return blobUri in blobUriStatuses;
  13259. };
  13260. var getResultUri = function (blobUri) {
  13261. var result = blobUriStatuses[blobUri];
  13262. return result ? result.resultUri : null;
  13263. };
  13264. var isPending = function (blobUri) {
  13265. return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === PENDING : false;
  13266. };
  13267. var isUploaded = function (blobUri) {
  13268. return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === UPLOADED : false;
  13269. };
  13270. var markPending = function (blobUri) {
  13271. blobUriStatuses[blobUri] = createStatus(PENDING, null);
  13272. };
  13273. var markUploaded = function (blobUri, resultUri) {
  13274. blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri);
  13275. };
  13276. var removeFailed = function (blobUri) {
  13277. delete blobUriStatuses[blobUri];
  13278. };
  13279. var destroy = function () {
  13280. blobUriStatuses = {};
  13281. };
  13282. return {
  13283. hasBlobUri: hasBlobUri,
  13284. getResultUri: getResultUri,
  13285. isPending: isPending,
  13286. isUploaded: isUploaded,
  13287. markPending: markPending,
  13288. markUploaded: markUploaded,
  13289. removeFailed: removeFailed,
  13290. destroy: destroy
  13291. };
  13292. }
  13293. var EditorUpload = function (editor) {
  13294. var blobCache = BlobCache();
  13295. var uploader, imageScanner;
  13296. var uploadStatus = UploadStatus();
  13297. var urlFilters = [];
  13298. var aliveGuard = function (callback) {
  13299. return function (result) {
  13300. if (editor.selection) {
  13301. return callback(result);
  13302. }
  13303. return [];
  13304. };
  13305. };
  13306. var cacheInvalidator = function () {
  13307. return '?' + new Date().getTime();
  13308. };
  13309. var replaceString = function (content, search, replace) {
  13310. var index = 0;
  13311. do {
  13312. index = content.indexOf(search, index);
  13313. if (index !== -1) {
  13314. content = content.substring(0, index) + replace + content.substr(index + search.length);
  13315. index += replace.length - search.length + 1;
  13316. }
  13317. } while (index !== -1);
  13318. return content;
  13319. };
  13320. var replaceImageUrl = function (content, targetUrl, replacementUrl) {
  13321. content = replaceString(content, 'src="' + targetUrl + '"', 'src="' + replacementUrl + '"');
  13322. content = replaceString(content, 'data-mce-src="' + targetUrl + '"', 'data-mce-src="' + replacementUrl + '"');
  13323. return content;
  13324. };
  13325. var replaceUrlInUndoStack = function (targetUrl, replacementUrl) {
  13326. each(editor.undoManager.data, function (level) {
  13327. if (level.type === 'fragmented') {
  13328. level.fragments = map(level.fragments, function (fragment) {
  13329. return replaceImageUrl(fragment, targetUrl, replacementUrl);
  13330. });
  13331. } else {
  13332. level.content = replaceImageUrl(level.content, targetUrl, replacementUrl);
  13333. }
  13334. });
  13335. };
  13336. var openNotification = function () {
  13337. return editor.notificationManager.open({
  13338. text: editor.translate('Image uploading...'),
  13339. type: 'info',
  13340. timeout: -1,
  13341. progressBar: true
  13342. });
  13343. };
  13344. var replaceImageUri = function (image, resultUri) {
  13345. blobCache.removeByUri(image.src);
  13346. replaceUrlInUndoStack(image.src, resultUri);
  13347. editor.$(image).attr({
  13348. 'src': Settings.shouldReuseFileName(editor) ? resultUri + cacheInvalidator() : resultUri,
  13349. 'data-mce-src': editor.convertURL(resultUri, 'src')
  13350. });
  13351. };
  13352. var uploadImages = function (callback) {
  13353. if (!uploader) {
  13354. uploader = Uploader(uploadStatus, {
  13355. url: Settings.getImageUploadUrl(editor),
  13356. basePath: Settings.getImageUploadBasePath(editor),
  13357. credentials: Settings.getImagesUploadCredentials(editor),
  13358. handler: Settings.getImagesUploadHandler(editor)
  13359. });
  13360. }
  13361. return scanForImages().then(aliveGuard(function (imageInfos) {
  13362. var blobInfos;
  13363. blobInfos = map(imageInfos, function (imageInfo) {
  13364. return imageInfo.blobInfo;
  13365. });
  13366. return uploader.upload(blobInfos, openNotification).then(aliveGuard(function (result) {
  13367. var filteredResult = map(result, function (uploadInfo, index) {
  13368. var image = imageInfos[index].image;
  13369. if (uploadInfo.status && Settings.shouldReplaceBlobUris(editor)) {
  13370. replaceImageUri(image, uploadInfo.url);
  13371. } else if (uploadInfo.error) {
  13372. ErrorReporter.uploadError(editor, uploadInfo.error);
  13373. }
  13374. return {
  13375. element: image,
  13376. status: uploadInfo.status
  13377. };
  13378. });
  13379. if (callback) {
  13380. callback(filteredResult);
  13381. }
  13382. return filteredResult;
  13383. }));
  13384. }));
  13385. };
  13386. var uploadImagesAuto = function (callback) {
  13387. if (Settings.isAutomaticUploadsEnabled(editor)) {
  13388. return uploadImages(callback);
  13389. }
  13390. };
  13391. var isValidDataUriImage = function (imgElm) {
  13392. if (forall(urlFilters, function (filter) {
  13393. return filter(imgElm);
  13394. }) === false) {
  13395. return false;
  13396. }
  13397. if (imgElm.getAttribute('src').indexOf('data:') === 0) {
  13398. var dataImgFilter = Settings.getImagesDataImgFilter(editor);
  13399. return dataImgFilter(imgElm);
  13400. }
  13401. return true;
  13402. };
  13403. var addFilter = function (filter) {
  13404. urlFilters.push(filter);
  13405. };
  13406. var scanForImages = function () {
  13407. if (!imageScanner) {
  13408. imageScanner = ImageScanner(uploadStatus, blobCache);
  13409. }
  13410. return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(aliveGuard(function (result) {
  13411. result = filter(result, function (resultItem) {
  13412. if (typeof resultItem === 'string') {
  13413. ErrorReporter.displayError(editor, resultItem);
  13414. return false;
  13415. }
  13416. return true;
  13417. });
  13418. each(result, function (resultItem) {
  13419. replaceUrlInUndoStack(resultItem.image.src, resultItem.blobInfo.blobUri());
  13420. resultItem.image.src = resultItem.blobInfo.blobUri();
  13421. resultItem.image.removeAttribute('data-mce-src');
  13422. });
  13423. return result;
  13424. }));
  13425. };
  13426. var destroy = function () {
  13427. blobCache.destroy();
  13428. uploadStatus.destroy();
  13429. imageScanner = uploader = null;
  13430. };
  13431. var replaceBlobUris = function (content) {
  13432. return content.replace(/src="(blob:[^"]+)"/g, function (match, blobUri) {
  13433. var resultUri = uploadStatus.getResultUri(blobUri);
  13434. if (resultUri) {
  13435. return 'src="' + resultUri + '"';
  13436. }
  13437. var blobInfo = blobCache.getByUri(blobUri);
  13438. if (!blobInfo) {
  13439. blobInfo = foldl(editor.editorManager.get(), function (result, editor) {
  13440. return result || editor.editorUpload && editor.editorUpload.blobCache.getByUri(blobUri);
  13441. }, null);
  13442. }
  13443. if (blobInfo) {
  13444. var blob = blobInfo.blob();
  13445. return 'src="data:' + blob.type + ';base64,' + blobInfo.base64() + '"';
  13446. }
  13447. return match;
  13448. });
  13449. };
  13450. editor.on('SetContent', function () {
  13451. if (Settings.isAutomaticUploadsEnabled(editor)) {
  13452. uploadImagesAuto();
  13453. } else {
  13454. scanForImages();
  13455. }
  13456. });
  13457. editor.on('RawSaveContent', function (e) {
  13458. e.content = replaceBlobUris(e.content);
  13459. });
  13460. editor.on('GetContent', function (e) {
  13461. if (e.source_view || e.format === 'raw') {
  13462. return;
  13463. }
  13464. e.content = replaceBlobUris(e.content);
  13465. });
  13466. editor.on('PostRender', function () {
  13467. editor.parser.addNodeFilter('img', function (images) {
  13468. each(images, function (img) {
  13469. var src = img.attr('src');
  13470. if (blobCache.getByUri(src)) {
  13471. return;
  13472. }
  13473. var resultUri = uploadStatus.getResultUri(src);
  13474. if (resultUri) {
  13475. img.attr('src', resultUri);
  13476. }
  13477. });
  13478. });
  13479. });
  13480. return {
  13481. blobCache: blobCache,
  13482. addFilter: addFilter,
  13483. uploadImages: uploadImages,
  13484. uploadImagesAuto: uploadImagesAuto,
  13485. scanForImages: scanForImages,
  13486. destroy: destroy
  13487. };
  13488. };
  13489. var dropLast = function (xs) {
  13490. return xs.slice(0, -1);
  13491. };
  13492. var parentsUntil$1 = function (start, root, predicate) {
  13493. if (contains$2(root, start)) {
  13494. return dropLast(parents(start, function (elm) {
  13495. return predicate(elm) || eq(elm, root);
  13496. }));
  13497. } else {
  13498. return [];
  13499. }
  13500. };
  13501. var parents$1 = function (start, root) {
  13502. return parentsUntil$1(start, root, constant(false));
  13503. };
  13504. var parentsAndSelf = function (start, root) {
  13505. return [start].concat(parents$1(start, root));
  13506. };
  13507. var Parents = {
  13508. parentsUntil: parentsUntil$1,
  13509. parents: parents$1,
  13510. parentsAndSelf: parentsAndSelf
  13511. };
  13512. var isBlockElement = function (blockElements, node) {
  13513. return blockElements.hasOwnProperty(node.nodeName);
  13514. };
  13515. var isValidTarget = function (blockElements, node) {
  13516. if (NodeType.isText(node)) {
  13517. return true;
  13518. } else if (NodeType.isElement(node)) {
  13519. return !isBlockElement(blockElements, node) && !Bookmarks.isBookmarkNode(node);
  13520. } else {
  13521. return false;
  13522. }
  13523. };
  13524. var hasBlockParent = function (blockElements, root, node) {
  13525. return exists(Parents.parents(Element.fromDom(node), Element.fromDom(root)), function (elm) {
  13526. return isBlockElement(blockElements, elm.dom());
  13527. });
  13528. };
  13529. var shouldRemoveTextNode = function (blockElements, node) {
  13530. if (NodeType.isText(node)) {
  13531. if (node.nodeValue.length === 0) {
  13532. return true;
  13533. } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) {
  13534. return true;
  13535. }
  13536. }
  13537. return false;
  13538. };
  13539. var addRootBlocks = function (editor) {
  13540. var dom = editor.dom, selection = editor.selection;
  13541. var schema = editor.schema, blockElements = schema.getBlockElements();
  13542. var node = selection.getStart();
  13543. var rootNode = editor.getBody();
  13544. var rng;
  13545. var startContainer, startOffset, endContainer, endOffset, rootBlockNode;
  13546. var tempNode, wrapped, restoreSelection;
  13547. var rootNodeName;
  13548. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  13549. if (!node || !NodeType.isElement(node) || !forcedRootBlock) {
  13550. return;
  13551. }
  13552. rootNodeName = rootNode.nodeName.toLowerCase();
  13553. if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) {
  13554. return;
  13555. }
  13556. rng = selection.getRng();
  13557. startContainer = rng.startContainer;
  13558. startOffset = rng.startOffset;
  13559. endContainer = rng.endContainer;
  13560. endOffset = rng.endOffset;
  13561. restoreSelection = EditorFocus.hasFocus(editor);
  13562. node = rootNode.firstChild;
  13563. while (node) {
  13564. if (isValidTarget(blockElements, node)) {
  13565. if (shouldRemoveTextNode(blockElements, node)) {
  13566. tempNode = node;
  13567. node = node.nextSibling;
  13568. dom.remove(tempNode);
  13569. continue;
  13570. }
  13571. if (!rootBlockNode) {
  13572. rootBlockNode = dom.create(forcedRootBlock, Settings.getForcedRootBlockAttrs(editor));
  13573. node.parentNode.insertBefore(rootBlockNode, node);
  13574. wrapped = true;
  13575. }
  13576. tempNode = node;
  13577. node = node.nextSibling;
  13578. rootBlockNode.appendChild(tempNode);
  13579. } else {
  13580. rootBlockNode = null;
  13581. node = node.nextSibling;
  13582. }
  13583. }
  13584. if (wrapped && restoreSelection) {
  13585. rng.setStart(startContainer, startOffset);
  13586. rng.setEnd(endContainer, endOffset);
  13587. selection.setRng(rng);
  13588. editor.nodeChanged();
  13589. }
  13590. };
  13591. var setup$3 = function (editor) {
  13592. if (Settings.getForcedRootBlock(editor)) {
  13593. editor.on('NodeChange', curry(addRootBlocks, editor));
  13594. }
  13595. };
  13596. var ForceBlocks = { setup: setup$3 };
  13597. var isEq$1 = function (rng1, rng2) {
  13598. return rng1 && rng2 && (rng1.startContainer === rng2.startContainer && rng1.startOffset === rng2.startOffset) && (rng1.endContainer === rng2.endContainer && rng1.endOffset === rng2.endOffset);
  13599. };
  13600. var RangeCompare = { isEq: isEq$1 };
  13601. var getStartNode = function (rng) {
  13602. var sc = rng.startContainer, so = rng.startOffset;
  13603. if (NodeType.isText(sc)) {
  13604. return so === 0 ? Option.some(Element.fromDom(sc)) : Option.none();
  13605. } else {
  13606. return Option.from(sc.childNodes[so]).map(Element.fromDom);
  13607. }
  13608. };
  13609. var getEndNode = function (rng) {
  13610. var ec = rng.endContainer, eo = rng.endOffset;
  13611. if (NodeType.isText(ec)) {
  13612. return eo === ec.data.length ? Option.some(Element.fromDom(ec)) : Option.none();
  13613. } else {
  13614. return Option.from(ec.childNodes[eo - 1]).map(Element.fromDom);
  13615. }
  13616. };
  13617. var getFirstChildren = function (node) {
  13618. return firstChild(node).fold(constant([node]), function (child) {
  13619. return [node].concat(getFirstChildren(child));
  13620. });
  13621. };
  13622. var getLastChildren = function (node) {
  13623. return lastChild(node).fold(constant([node]), function (child) {
  13624. if (name(child) === 'br') {
  13625. return prevSibling(child).map(function (sibling) {
  13626. return [node].concat(getLastChildren(sibling));
  13627. }).getOr([]);
  13628. } else {
  13629. return [node].concat(getLastChildren(child));
  13630. }
  13631. });
  13632. };
  13633. var hasAllContentsSelected = function (elm, rng) {
  13634. return lift2(getStartNode(rng), getEndNode(rng), function (startNode, endNode) {
  13635. var start = find(getFirstChildren(elm), curry(eq, startNode));
  13636. var end = find(getLastChildren(elm), curry(eq, endNode));
  13637. return start.isSome() && end.isSome();
  13638. }).getOr(false);
  13639. };
  13640. var moveEndPoint$1 = function (dom, rng, node, start) {
  13641. var root = node, walker = new TreeWalker(node, root);
  13642. var nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  13643. do {
  13644. if (node.nodeType === 3 && Tools.trim(node.nodeValue).length !== 0) {
  13645. if (start) {
  13646. rng.setStart(node, 0);
  13647. } else {
  13648. rng.setEnd(node, node.nodeValue.length);
  13649. }
  13650. return;
  13651. }
  13652. if (nonEmptyElementsMap[node.nodeName] && !/^(TD|TH)$/.test(node.nodeName)) {
  13653. if (start) {
  13654. rng.setStartBefore(node);
  13655. } else {
  13656. if (node.nodeName === 'BR') {
  13657. rng.setEndBefore(node);
  13658. } else {
  13659. rng.setEndAfter(node);
  13660. }
  13661. }
  13662. return;
  13663. }
  13664. } while (node = start ? walker.next() : walker.prev());
  13665. if (root.nodeName === 'BODY') {
  13666. if (start) {
  13667. rng.setStart(root, 0);
  13668. } else {
  13669. rng.setEnd(root, root.childNodes.length);
  13670. }
  13671. }
  13672. };
  13673. var hasAnyRanges = function (editor) {
  13674. var sel = editor.selection.getSel();
  13675. return sel && sel.rangeCount > 0;
  13676. };
  13677. var NodeChange = function () {
  13678. function NodeChange(editor) {
  13679. this.lastPath = [];
  13680. this.editor = editor;
  13681. var lastRng;
  13682. var self = this;
  13683. if (!('onselectionchange' in editor.getDoc())) {
  13684. editor.on('NodeChange click mouseup keyup focus', function (e) {
  13685. var nativeRng, fakeRng;
  13686. nativeRng = editor.selection.getRng();
  13687. fakeRng = {
  13688. startContainer: nativeRng.startContainer,
  13689. startOffset: nativeRng.startOffset,
  13690. endContainer: nativeRng.endContainer,
  13691. endOffset: nativeRng.endOffset
  13692. };
  13693. if (e.type === 'nodechange' || !RangeCompare.isEq(fakeRng, lastRng)) {
  13694. editor.fire('SelectionChange');
  13695. }
  13696. lastRng = fakeRng;
  13697. });
  13698. }
  13699. editor.on('contextmenu', function () {
  13700. editor.fire('SelectionChange');
  13701. });
  13702. editor.on('SelectionChange', function () {
  13703. var startElm = editor.selection.getStart(true);
  13704. if (!startElm || !Env.range && editor.selection.isCollapsed()) {
  13705. return;
  13706. }
  13707. if (hasAnyRanges(editor) && !self.isSameElementPath(startElm) && editor.dom.isChildOf(startElm, editor.getBody())) {
  13708. editor.nodeChanged({ selectionChange: true });
  13709. }
  13710. });
  13711. editor.on('mouseup', function (e) {
  13712. if (!e.isDefaultPrevented() && hasAnyRanges(editor)) {
  13713. if (editor.selection.getNode().nodeName === 'IMG') {
  13714. Delay.setEditorTimeout(editor, function () {
  13715. editor.nodeChanged();
  13716. });
  13717. } else {
  13718. editor.nodeChanged();
  13719. }
  13720. }
  13721. });
  13722. }
  13723. NodeChange.prototype.nodeChanged = function (args) {
  13724. var selection = this.editor.selection;
  13725. var node, parents, root;
  13726. if (this.editor.initialized && selection && !this.editor.settings.disable_nodechange && !this.editor.readonly) {
  13727. root = this.editor.getBody();
  13728. node = selection.getStart(true) || root;
  13729. if (node.ownerDocument !== this.editor.getDoc() || !this.editor.dom.isChildOf(node, root)) {
  13730. node = root;
  13731. }
  13732. parents = [];
  13733. this.editor.dom.getParent(node, function (node) {
  13734. if (node === root) {
  13735. return true;
  13736. }
  13737. parents.push(node);
  13738. });
  13739. args = args || {};
  13740. args.element = node;
  13741. args.parents = parents;
  13742. this.editor.fire('NodeChange', args);
  13743. }
  13744. };
  13745. NodeChange.prototype.isSameElementPath = function (startElm) {
  13746. var i, currentPath;
  13747. currentPath = this.editor.$(startElm).parentsUntil(this.editor.getBody()).add(startElm);
  13748. if (currentPath.length === this.lastPath.length) {
  13749. for (i = currentPath.length; i >= 0; i--) {
  13750. if (currentPath[i] !== this.lastPath[i]) {
  13751. break;
  13752. }
  13753. }
  13754. if (i === -1) {
  13755. this.lastPath = currentPath;
  13756. return true;
  13757. }
  13758. }
  13759. this.lastPath = currentPath;
  13760. return false;
  13761. };
  13762. return NodeChange;
  13763. }();
  13764. var VK = {
  13765. BACKSPACE: 8,
  13766. DELETE: 46,
  13767. DOWN: 40,
  13768. ENTER: 13,
  13769. LEFT: 37,
  13770. RIGHT: 39,
  13771. SPACEBAR: 32,
  13772. TAB: 9,
  13773. UP: 38,
  13774. END: 35,
  13775. HOME: 36,
  13776. modifierPressed: function (e) {
  13777. return e.shiftKey || e.ctrlKey || e.altKey || this.metaKeyPressed(e);
  13778. },
  13779. metaKeyPressed: function (e) {
  13780. return Env.mac ? e.metaKey : e.ctrlKey && !e.altKey;
  13781. }
  13782. };
  13783. var is$2 = function (expected) {
  13784. return function (actual) {
  13785. return expected === actual;
  13786. };
  13787. };
  13788. var isNbsp = is$2('\xA0');
  13789. var isWhiteSpace$1 = function (chr) {
  13790. return /^[\r\n\t ]$/.test(chr);
  13791. };
  13792. var isContent = function (chr) {
  13793. return !isWhiteSpace$1(chr) && !isNbsp(chr);
  13794. };
  13795. var isChar = function (forward, predicate, pos) {
  13796. return Option.from(pos.container()).filter(NodeType.isText).exists(function (text) {
  13797. var delta = forward ? 0 : -1;
  13798. return predicate(text.data.charAt(pos.offset() + delta));
  13799. });
  13800. };
  13801. var isBeforeSpace = curry(isChar, true, isWhiteSpace$1);
  13802. var isAfterSpace = curry(isChar, false, isWhiteSpace$1);
  13803. var isEmptyText = function (pos) {
  13804. var container = pos.container();
  13805. return NodeType.isText(container) && container.data.length === 0;
  13806. };
  13807. var matchesElementPosition = function (before, predicate) {
  13808. return function (pos) {
  13809. return Option.from(getChildNodeAtRelativeOffset(before ? 0 : -1, pos)).filter(predicate).isSome();
  13810. };
  13811. };
  13812. var isImageBlock = function (node) {
  13813. return node.nodeName === 'IMG' && get$2(Element.fromDom(node), 'display') === 'block';
  13814. };
  13815. var isCefNode = function (node) {
  13816. return NodeType.isContentEditableFalse(node) && !NodeType.isBogusAll(node);
  13817. };
  13818. var isBeforeImageBlock = matchesElementPosition(true, isImageBlock);
  13819. var isAfterImageBlock = matchesElementPosition(false, isImageBlock);
  13820. var isBeforeTable = matchesElementPosition(true, NodeType.isTable);
  13821. var isAfterTable = matchesElementPosition(false, NodeType.isTable);
  13822. var isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode);
  13823. var isAfterContentEditableFalse = matchesElementPosition(false, isCefNode);
  13824. var getNodeClientRects = function (node) {
  13825. var toArrayWithNode = function (clientRects) {
  13826. return map(clientRects, function (clientRect) {
  13827. clientRect = clone$1(clientRect);
  13828. clientRect.node = node;
  13829. return clientRect;
  13830. });
  13831. };
  13832. if (NodeType.isElement(node)) {
  13833. return toArrayWithNode(node.getClientRects());
  13834. }
  13835. if (NodeType.isText(node)) {
  13836. var rng = node.ownerDocument.createRange();
  13837. rng.setStart(node, 0);
  13838. rng.setEnd(node, node.data.length);
  13839. return toArrayWithNode(rng.getClientRects());
  13840. }
  13841. };
  13842. var getClientRects = function (node) {
  13843. return foldl(node, function (result, node) {
  13844. return result.concat(getNodeClientRects(node));
  13845. }, []);
  13846. };
  13847. var VDirection;
  13848. (function (VDirection) {
  13849. VDirection[VDirection['Up'] = -1] = 'Up';
  13850. VDirection[VDirection['Down'] = 1] = 'Down';
  13851. }(VDirection || (VDirection = {})));
  13852. var findUntil = function (direction, root, predicateFn, node) {
  13853. while (node = findNode(node, direction, isEditableCaretCandidate, root)) {
  13854. if (predicateFn(node)) {
  13855. return;
  13856. }
  13857. }
  13858. };
  13859. var walkUntil = function (direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) {
  13860. var line = 0, node;
  13861. var result = [];
  13862. var targetClientRect;
  13863. var add = function (node) {
  13864. var i, clientRect, clientRects;
  13865. clientRects = getClientRects([node]);
  13866. if (direction === -1) {
  13867. clientRects = clientRects.reverse();
  13868. }
  13869. for (i = 0; i < clientRects.length; i++) {
  13870. clientRect = clientRects[i];
  13871. if (isBeflowFn(clientRect, targetClientRect)) {
  13872. continue;
  13873. }
  13874. if (result.length > 0 && isAboveFn(clientRect, ArrUtils.last(result))) {
  13875. line++;
  13876. }
  13877. clientRect.line = line;
  13878. if (predicateFn(clientRect)) {
  13879. return true;
  13880. }
  13881. result.push(clientRect);
  13882. }
  13883. };
  13884. targetClientRect = ArrUtils.last(caretPosition.getClientRects());
  13885. if (!targetClientRect) {
  13886. return result;
  13887. }
  13888. node = caretPosition.getNode();
  13889. add(node);
  13890. findUntil(direction, root, add, node);
  13891. return result;
  13892. };
  13893. var aboveLineNumber = function (lineNumber, clientRect) {
  13894. return clientRect.line > lineNumber;
  13895. };
  13896. var isLineNumber = function (lineNumber, clientRect) {
  13897. return clientRect.line === lineNumber;
  13898. };
  13899. var upUntil = curry(walkUntil, VDirection.Up, isAbove, isBelow);
  13900. var downUntil = curry(walkUntil, VDirection.Down, isBelow, isAbove);
  13901. var positionsUntil = function (direction, root, predicateFn, node) {
  13902. var caretWalker = CaretWalker(root);
  13903. var walkFn, isBelowFn, isAboveFn, caretPosition;
  13904. var result = [];
  13905. var line = 0, clientRect, targetClientRect;
  13906. var getClientRect = function (caretPosition) {
  13907. if (direction === 1) {
  13908. return ArrUtils.last(caretPosition.getClientRects());
  13909. }
  13910. return ArrUtils.last(caretPosition.getClientRects());
  13911. };
  13912. if (direction === 1) {
  13913. walkFn = caretWalker.next;
  13914. isBelowFn = isBelow;
  13915. isAboveFn = isAbove;
  13916. caretPosition = CaretPosition$1.after(node);
  13917. } else {
  13918. walkFn = caretWalker.prev;
  13919. isBelowFn = isAbove;
  13920. isAboveFn = isBelow;
  13921. caretPosition = CaretPosition$1.before(node);
  13922. }
  13923. targetClientRect = getClientRect(caretPosition);
  13924. do {
  13925. if (!caretPosition.isVisible()) {
  13926. continue;
  13927. }
  13928. clientRect = getClientRect(caretPosition);
  13929. if (isAboveFn(clientRect, targetClientRect)) {
  13930. continue;
  13931. }
  13932. if (result.length > 0 && isBelowFn(clientRect, ArrUtils.last(result))) {
  13933. line++;
  13934. }
  13935. clientRect = clone$1(clientRect);
  13936. clientRect.position = caretPosition;
  13937. clientRect.line = line;
  13938. if (predicateFn(clientRect)) {
  13939. return result;
  13940. }
  13941. result.push(clientRect);
  13942. } while (caretPosition = walkFn(caretPosition));
  13943. return result;
  13944. };
  13945. var isAboveLine = function (lineNumber) {
  13946. return function (clientRect) {
  13947. return aboveLineNumber(lineNumber, clientRect);
  13948. };
  13949. };
  13950. var isLine = function (lineNumber) {
  13951. return function (clientRect) {
  13952. return isLineNumber(lineNumber, clientRect);
  13953. };
  13954. };
  13955. var isContentEditableFalse$6 = NodeType.isContentEditableFalse;
  13956. var findNode$1 = findNode;
  13957. var distanceToRectLeft = function (clientRect, clientX) {
  13958. return Math.abs(clientRect.left - clientX);
  13959. };
  13960. var distanceToRectRight = function (clientRect, clientX) {
  13961. return Math.abs(clientRect.right - clientX);
  13962. };
  13963. var isInside = function (clientX, clientRect) {
  13964. return clientX >= clientRect.left && clientX <= clientRect.right;
  13965. };
  13966. var findClosestClientRect = function (clientRects, clientX) {
  13967. return ArrUtils.reduce(clientRects, function (oldClientRect, clientRect) {
  13968. var oldDistance, newDistance;
  13969. oldDistance = Math.min(distanceToRectLeft(oldClientRect, clientX), distanceToRectRight(oldClientRect, clientX));
  13970. newDistance = Math.min(distanceToRectLeft(clientRect, clientX), distanceToRectRight(clientRect, clientX));
  13971. if (isInside(clientX, clientRect)) {
  13972. return clientRect;
  13973. }
  13974. if (isInside(clientX, oldClientRect)) {
  13975. return oldClientRect;
  13976. }
  13977. if (newDistance === oldDistance && isContentEditableFalse$6(clientRect.node)) {
  13978. return clientRect;
  13979. }
  13980. if (newDistance < oldDistance) {
  13981. return clientRect;
  13982. }
  13983. return oldClientRect;
  13984. });
  13985. };
  13986. var walkUntil$1 = function (direction, root, predicateFn, node) {
  13987. while (node = findNode$1(node, direction, isEditableCaretCandidate, root)) {
  13988. if (predicateFn(node)) {
  13989. return;
  13990. }
  13991. }
  13992. };
  13993. var findLineNodeRects = function (root, targetNodeRect) {
  13994. var clientRects = [];
  13995. var collect = function (checkPosFn, node) {
  13996. var lineRects;
  13997. lineRects = filter(getClientRects([node]), function (clientRect) {
  13998. return !checkPosFn(clientRect, targetNodeRect);
  13999. });
  14000. clientRects = clientRects.concat(lineRects);
  14001. return lineRects.length === 0;
  14002. };
  14003. clientRects.push(targetNodeRect);
  14004. walkUntil$1(VDirection.Up, root, curry(collect, isAbove), targetNodeRect.node);
  14005. walkUntil$1(VDirection.Down, root, curry(collect, isBelow), targetNodeRect.node);
  14006. return clientRects;
  14007. };
  14008. var getFakeCaretTargets = function (root) {
  14009. return filter(from$1(root.getElementsByTagName('*')), isFakeCaretTarget);
  14010. };
  14011. var caretInfo = function (clientRect, clientX) {
  14012. return {
  14013. node: clientRect.node,
  14014. before: distanceToRectLeft(clientRect, clientX) < distanceToRectRight(clientRect, clientX)
  14015. };
  14016. };
  14017. var closestCaret = function (root, clientX, clientY) {
  14018. var closestNodeRect;
  14019. var contentEditableFalseNodeRects = getClientRects(getFakeCaretTargets(root));
  14020. var targetNodeRects = filter(contentEditableFalseNodeRects, function (rect) {
  14021. return clientY >= rect.top && clientY <= rect.bottom;
  14022. });
  14023. closestNodeRect = findClosestClientRect(targetNodeRects, clientX);
  14024. if (closestNodeRect) {
  14025. closestNodeRect = findClosestClientRect(findLineNodeRects(root, closestNodeRect), clientX);
  14026. if (closestNodeRect && isFakeCaretTarget(closestNodeRect.node)) {
  14027. return caretInfo(closestNodeRect, clientX);
  14028. }
  14029. }
  14030. return null;
  14031. };
  14032. var isXYWithinRange = function (clientX, clientY, range) {
  14033. if (range.collapsed) {
  14034. return false;
  14035. }
  14036. if (Env.browser.isIE() && range.startOffset === range.endOffset - 1 && range.startContainer === range.endContainer) {
  14037. var elm = range.startContainer.childNodes[range.startOffset];
  14038. if (NodeType.isElement(elm)) {
  14039. return exists(elm.getClientRects(), function (rect) {
  14040. return containsXY(rect, clientX, clientY);
  14041. });
  14042. }
  14043. }
  14044. return exists(range.getClientRects(), function (rect) {
  14045. return containsXY(rect, clientX, clientY);
  14046. });
  14047. };
  14048. var RangePoint = { isXYWithinRange: isXYWithinRange };
  14049. var getAbsolutePosition = function (elm) {
  14050. var doc, docElem, win, clientRect;
  14051. clientRect = elm.getBoundingClientRect();
  14052. doc = elm.ownerDocument;
  14053. docElem = doc.documentElement;
  14054. win = doc.defaultView;
  14055. return {
  14056. top: clientRect.top + win.pageYOffset - docElem.clientTop,
  14057. left: clientRect.left + win.pageXOffset - docElem.clientLeft
  14058. };
  14059. };
  14060. var getBodyPosition = function (editor) {
  14061. return editor.inline ? getAbsolutePosition(editor.getBody()) : {
  14062. left: 0,
  14063. top: 0
  14064. };
  14065. };
  14066. var getScrollPosition = function (editor) {
  14067. var body = editor.getBody();
  14068. return editor.inline ? {
  14069. left: body.scrollLeft,
  14070. top: body.scrollTop
  14071. } : {
  14072. left: 0,
  14073. top: 0
  14074. };
  14075. };
  14076. var getBodyScroll = function (editor) {
  14077. var body = editor.getBody(), docElm = editor.getDoc().documentElement;
  14078. var inlineScroll = {
  14079. left: body.scrollLeft,
  14080. top: body.scrollTop
  14081. };
  14082. var iframeScroll = {
  14083. left: body.scrollLeft || docElm.scrollLeft,
  14084. top: body.scrollTop || docElm.scrollTop
  14085. };
  14086. return editor.inline ? inlineScroll : iframeScroll;
  14087. };
  14088. var getMousePosition = function (editor, event) {
  14089. if (event.target.ownerDocument !== editor.getDoc()) {
  14090. var iframePosition = getAbsolutePosition(editor.getContentAreaContainer());
  14091. var scrollPosition = getBodyScroll(editor);
  14092. return {
  14093. left: event.pageX - iframePosition.left + scrollPosition.left,
  14094. top: event.pageY - iframePosition.top + scrollPosition.top
  14095. };
  14096. }
  14097. return {
  14098. left: event.pageX,
  14099. top: event.pageY
  14100. };
  14101. };
  14102. var calculatePosition = function (bodyPosition, scrollPosition, mousePosition) {
  14103. return {
  14104. pageX: mousePosition.left - bodyPosition.left + scrollPosition.left,
  14105. pageY: mousePosition.top - bodyPosition.top + scrollPosition.top
  14106. };
  14107. };
  14108. var calc = function (editor, event) {
  14109. return calculatePosition(getBodyPosition(editor), getScrollPosition(editor), getMousePosition(editor, event));
  14110. };
  14111. var MousePosition = { calc: calc };
  14112. var isContentEditableFalse$7 = NodeType.isContentEditableFalse, isContentEditableTrue$2 = NodeType.isContentEditableTrue;
  14113. var isDraggable = function (rootElm, elm) {
  14114. return isContentEditableFalse$7(elm) && elm !== rootElm;
  14115. };
  14116. var isValidDropTarget = function (editor, targetElement, dragElement) {
  14117. if (targetElement === dragElement || editor.dom.isChildOf(targetElement, dragElement)) {
  14118. return false;
  14119. }
  14120. return !isContentEditableFalse$7(targetElement);
  14121. };
  14122. var cloneElement = function (elm) {
  14123. var cloneElm = elm.cloneNode(true);
  14124. cloneElm.removeAttribute('data-mce-selected');
  14125. return cloneElm;
  14126. };
  14127. var createGhost = function (editor, elm, width, height) {
  14128. var clonedElm = elm.cloneNode(true);
  14129. editor.dom.setStyles(clonedElm, {
  14130. width: width,
  14131. height: height
  14132. });
  14133. editor.dom.setAttrib(clonedElm, 'data-mce-selected', null);
  14134. var ghostElm = editor.dom.create('div', {
  14135. 'class': 'mce-drag-container',
  14136. 'data-mce-bogus': 'all',
  14137. 'unselectable': 'on',
  14138. 'contenteditable': 'false'
  14139. });
  14140. editor.dom.setStyles(ghostElm, {
  14141. position: 'absolute',
  14142. opacity: 0.5,
  14143. overflow: 'hidden',
  14144. border: 0,
  14145. padding: 0,
  14146. margin: 0,
  14147. width: width,
  14148. height: height
  14149. });
  14150. editor.dom.setStyles(clonedElm, {
  14151. margin: 0,
  14152. boxSizing: 'border-box'
  14153. });
  14154. ghostElm.appendChild(clonedElm);
  14155. return ghostElm;
  14156. };
  14157. var appendGhostToBody = function (ghostElm, bodyElm) {
  14158. if (ghostElm.parentNode !== bodyElm) {
  14159. bodyElm.appendChild(ghostElm);
  14160. }
  14161. };
  14162. var moveGhost = function (ghostElm, position, width, height, maxX, maxY) {
  14163. var overflowX = 0, overflowY = 0;
  14164. ghostElm.style.left = position.pageX + 'px';
  14165. ghostElm.style.top = position.pageY + 'px';
  14166. if (position.pageX + width > maxX) {
  14167. overflowX = position.pageX + width - maxX;
  14168. }
  14169. if (position.pageY + height > maxY) {
  14170. overflowY = position.pageY + height - maxY;
  14171. }
  14172. ghostElm.style.width = width - overflowX + 'px';
  14173. ghostElm.style.height = height - overflowY + 'px';
  14174. };
  14175. var removeElement = function (elm) {
  14176. if (elm && elm.parentNode) {
  14177. elm.parentNode.removeChild(elm);
  14178. }
  14179. };
  14180. var isLeftMouseButtonPressed = function (e) {
  14181. return e.button === 0;
  14182. };
  14183. var hasDraggableElement = function (state) {
  14184. return state.element;
  14185. };
  14186. var applyRelPos = function (state, position) {
  14187. return {
  14188. pageX: position.pageX - state.relX,
  14189. pageY: position.pageY + 5
  14190. };
  14191. };
  14192. var start = function (state, editor) {
  14193. return function (e) {
  14194. if (isLeftMouseButtonPressed(e)) {
  14195. var ceElm = find(editor.dom.getParents(e.target), Predicate.or(isContentEditableFalse$7, isContentEditableTrue$2)).getOr(null);
  14196. if (isDraggable(editor.getBody(), ceElm)) {
  14197. var elmPos = editor.dom.getPos(ceElm);
  14198. var bodyElm = editor.getBody();
  14199. var docElm = editor.getDoc().documentElement;
  14200. state.element = ceElm;
  14201. state.screenX = e.screenX;
  14202. state.screenY = e.screenY;
  14203. state.maxX = (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2;
  14204. state.maxY = (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2;
  14205. state.relX = e.pageX - elmPos.x;
  14206. state.relY = e.pageY - elmPos.y;
  14207. state.width = ceElm.offsetWidth;
  14208. state.height = ceElm.offsetHeight;
  14209. state.ghost = createGhost(editor, ceElm, state.width, state.height);
  14210. }
  14211. }
  14212. };
  14213. };
  14214. var move = function (state, editor) {
  14215. var throttledPlaceCaretAt = Delay.throttle(function (clientX, clientY) {
  14216. editor._selectionOverrides.hideFakeCaret();
  14217. editor.selection.placeCaretAt(clientX, clientY);
  14218. }, 0);
  14219. return function (e) {
  14220. var movement = Math.max(Math.abs(e.screenX - state.screenX), Math.abs(e.screenY - state.screenY));
  14221. if (hasDraggableElement(state) && !state.dragging && movement > 10) {
  14222. var args = editor.fire('dragstart', { target: state.element });
  14223. if (args.isDefaultPrevented()) {
  14224. return;
  14225. }
  14226. state.dragging = true;
  14227. editor.focus();
  14228. }
  14229. if (state.dragging) {
  14230. var targetPos = applyRelPos(state, MousePosition.calc(editor, e));
  14231. appendGhostToBody(state.ghost, editor.getBody());
  14232. moveGhost(state.ghost, targetPos, state.width, state.height, state.maxX, state.maxY);
  14233. throttledPlaceCaretAt(e.clientX, e.clientY);
  14234. }
  14235. };
  14236. };
  14237. var getRawTarget = function (selection) {
  14238. var rng = selection.getSel().getRangeAt(0);
  14239. var startContainer = rng.startContainer;
  14240. return startContainer.nodeType === 3 ? startContainer.parentNode : startContainer;
  14241. };
  14242. var drop = function (state, editor) {
  14243. return function (e) {
  14244. if (state.dragging) {
  14245. if (isValidDropTarget(editor, getRawTarget(editor.selection), state.element)) {
  14246. var targetClone_1 = cloneElement(state.element);
  14247. var args = editor.fire('drop', {
  14248. targetClone: targetClone_1,
  14249. clientX: e.clientX,
  14250. clientY: e.clientY
  14251. });
  14252. if (!args.isDefaultPrevented()) {
  14253. targetClone_1 = args.targetClone;
  14254. editor.undoManager.transact(function () {
  14255. removeElement(state.element);
  14256. editor.insertContent(editor.dom.getOuterHTML(targetClone_1));
  14257. editor._selectionOverrides.hideFakeCaret();
  14258. });
  14259. }
  14260. }
  14261. }
  14262. removeDragState(state);
  14263. };
  14264. };
  14265. var stop = function (state, editor) {
  14266. return function () {
  14267. if (state.dragging) {
  14268. editor.fire('dragend');
  14269. }
  14270. removeDragState(state);
  14271. };
  14272. };
  14273. var removeDragState = function (state) {
  14274. state.dragging = false;
  14275. state.element = null;
  14276. removeElement(state.ghost);
  14277. };
  14278. var bindFakeDragEvents = function (editor) {
  14279. var state = {};
  14280. var pageDom, dragStartHandler, dragHandler, dropHandler, dragEndHandler, rootDocument;
  14281. pageDom = DOMUtils$1.DOM;
  14282. rootDocument = domGlobals.document;
  14283. dragStartHandler = start(state, editor);
  14284. dragHandler = move(state, editor);
  14285. dropHandler = drop(state, editor);
  14286. dragEndHandler = stop(state, editor);
  14287. editor.on('mousedown', dragStartHandler);
  14288. editor.on('mousemove', dragHandler);
  14289. editor.on('mouseup', dropHandler);
  14290. pageDom.bind(rootDocument, 'mousemove', dragHandler);
  14291. pageDom.bind(rootDocument, 'mouseup', dragEndHandler);
  14292. editor.on('remove', function () {
  14293. pageDom.unbind(rootDocument, 'mousemove', dragHandler);
  14294. pageDom.unbind(rootDocument, 'mouseup', dragEndHandler);
  14295. });
  14296. };
  14297. var blockIeDrop = function (editor) {
  14298. editor.on('drop', function (e) {
  14299. var realTarget = typeof e.clientX !== 'undefined' ? editor.getDoc().elementFromPoint(e.clientX, e.clientY) : null;
  14300. if (isContentEditableFalse$7(realTarget) || isContentEditableFalse$7(editor.dom.getContentEditableParent(realTarget))) {
  14301. e.preventDefault();
  14302. }
  14303. });
  14304. };
  14305. var init = function (editor) {
  14306. bindFakeDragEvents(editor);
  14307. blockIeDrop(editor);
  14308. };
  14309. var DragDropOverrides = { init: init };
  14310. var isContentEditableTrue$3 = NodeType.isContentEditableTrue;
  14311. var isContentEditableFalse$8 = NodeType.isContentEditableFalse;
  14312. var showCaret = function (direction, editor, node, before, scrollIntoView) {
  14313. return editor._selectionOverrides.showCaret(direction, node, before, scrollIntoView);
  14314. };
  14315. var getNodeRange = function (node) {
  14316. var rng = node.ownerDocument.createRange();
  14317. rng.selectNode(node);
  14318. return rng;
  14319. };
  14320. var selectNode = function (editor, node) {
  14321. var e = editor.fire('BeforeObjectSelected', { target: node });
  14322. if (e.isDefaultPrevented()) {
  14323. return null;
  14324. }
  14325. return getNodeRange(node);
  14326. };
  14327. var renderCaretAtRange = function (editor, range, scrollIntoView) {
  14328. var normalizedRange = normalizeRange(1, editor.getBody(), range);
  14329. var caretPosition = CaretPosition$1.fromRangeStart(normalizedRange);
  14330. var caretPositionNode = caretPosition.getNode();
  14331. if (isContentEditableFalse$8(caretPositionNode)) {
  14332. return showCaret(1, editor, caretPositionNode, !caretPosition.isAtEnd(), false);
  14333. }
  14334. var caretPositionBeforeNode = caretPosition.getNode(true);
  14335. if (isContentEditableFalse$8(caretPositionBeforeNode)) {
  14336. return showCaret(1, editor, caretPositionBeforeNode, false, false);
  14337. }
  14338. var ceRoot = editor.dom.getParent(caretPosition.getNode(), function (node) {
  14339. return isContentEditableFalse$8(node) || isContentEditableTrue$3(node);
  14340. });
  14341. if (isContentEditableFalse$8(ceRoot)) {
  14342. return showCaret(1, editor, ceRoot, false, scrollIntoView);
  14343. }
  14344. return null;
  14345. };
  14346. var renderRangeCaret = function (editor, range, scrollIntoView) {
  14347. if (!range || !range.collapsed) {
  14348. return range;
  14349. }
  14350. var caretRange = renderCaretAtRange(editor, range, scrollIntoView);
  14351. if (caretRange) {
  14352. return caretRange;
  14353. }
  14354. return range;
  14355. };
  14356. var setup$4 = function (editor) {
  14357. var renderFocusCaret = first(function () {
  14358. if (!editor.removed && editor.getBody().contains(domGlobals.document.activeElement)) {
  14359. var rng = editor.selection.getRng();
  14360. if (rng.collapsed) {
  14361. var caretRange = renderRangeCaret(editor, editor.selection.getRng(), false);
  14362. editor.selection.setRng(caretRange);
  14363. }
  14364. }
  14365. }, 0);
  14366. editor.on('focus', function () {
  14367. renderFocusCaret.throttle();
  14368. });
  14369. editor.on('blur', function () {
  14370. renderFocusCaret.cancel();
  14371. });
  14372. };
  14373. var CefFocus = { setup: setup$4 };
  14374. var isContentEditableTrue$4 = NodeType.isContentEditableTrue;
  14375. var isContentEditableFalse$9 = NodeType.isContentEditableFalse;
  14376. var getContentEditableRoot = function (editor, node) {
  14377. var root = editor.getBody();
  14378. while (node && node !== root) {
  14379. if (isContentEditableTrue$4(node) || isContentEditableFalse$9(node)) {
  14380. return node;
  14381. }
  14382. node = node.parentNode;
  14383. }
  14384. return null;
  14385. };
  14386. var SelectionOverrides = function (editor) {
  14387. var isBlock = function (node) {
  14388. return editor.dom.isBlock(node);
  14389. };
  14390. var rootNode = editor.getBody();
  14391. var fakeCaret = FakeCaret(editor.getBody(), isBlock, function () {
  14392. return EditorFocus.hasFocus(editor);
  14393. });
  14394. var realSelectionId = 'sel-' + editor.dom.uniqueId();
  14395. var selectedContentEditableNode;
  14396. var isFakeSelectionElement = function (elm) {
  14397. return editor.dom.hasClass(elm, 'mce-offscreen-selection');
  14398. };
  14399. var getRealSelectionElement = function () {
  14400. var container = editor.dom.get(realSelectionId);
  14401. return container ? container.getElementsByTagName('*')[0] : container;
  14402. };
  14403. var setRange = function (range) {
  14404. if (range) {
  14405. editor.selection.setRng(range);
  14406. }
  14407. };
  14408. var getRange = function () {
  14409. return editor.selection.getRng();
  14410. };
  14411. var showCaret = function (direction, node, before, scrollIntoView) {
  14412. if (scrollIntoView === void 0) {
  14413. scrollIntoView = true;
  14414. }
  14415. var e;
  14416. e = editor.fire('ShowCaret', {
  14417. target: node,
  14418. direction: direction,
  14419. before: before
  14420. });
  14421. if (e.isDefaultPrevented()) {
  14422. return null;
  14423. }
  14424. if (scrollIntoView) {
  14425. editor.selection.scrollIntoView(node, direction === -1);
  14426. }
  14427. return fakeCaret.show(before, node);
  14428. };
  14429. var showBlockCaretContainer = function (blockCaretContainer) {
  14430. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  14431. showCaretContainerBlock(blockCaretContainer);
  14432. setRange(getRange());
  14433. editor.selection.scrollIntoView(blockCaretContainer);
  14434. }
  14435. };
  14436. var registerEvents = function () {
  14437. editor.on('mouseup', function (e) {
  14438. var range = getRange();
  14439. if (range.collapsed && EditorView.isXYInContentArea(editor, e.clientX, e.clientY)) {
  14440. setRange(renderCaretAtRange(editor, range, false));
  14441. }
  14442. });
  14443. editor.on('click', function (e) {
  14444. var contentEditableRoot;
  14445. contentEditableRoot = getContentEditableRoot(editor, e.target);
  14446. if (contentEditableRoot) {
  14447. if (isContentEditableFalse$9(contentEditableRoot)) {
  14448. e.preventDefault();
  14449. editor.focus();
  14450. }
  14451. if (isContentEditableTrue$4(contentEditableRoot)) {
  14452. if (editor.dom.isChildOf(contentEditableRoot, editor.selection.getNode())) {
  14453. removeContentEditableSelection();
  14454. }
  14455. }
  14456. }
  14457. });
  14458. editor.on('blur NewBlock', function () {
  14459. removeContentEditableSelection();
  14460. });
  14461. editor.on('ResizeWindow FullscreenStateChanged', function () {
  14462. return fakeCaret.reposition();
  14463. });
  14464. var handleTouchSelect = function (editor) {
  14465. var moved = false;
  14466. editor.on('touchstart', function () {
  14467. moved = false;
  14468. });
  14469. editor.on('touchmove', function () {
  14470. moved = true;
  14471. });
  14472. editor.on('touchend', function (e) {
  14473. if (!moved) {
  14474. var contentEditableRoot = getContentEditableRoot(editor, e.target);
  14475. if (isContentEditableFalse$9(contentEditableRoot)) {
  14476. e.preventDefault();
  14477. setContentEditableSelection(selectNode(editor, contentEditableRoot));
  14478. }
  14479. }
  14480. }, true);
  14481. };
  14482. var hasNormalCaretPosition = function (elm) {
  14483. var caretWalker = CaretWalker(elm);
  14484. if (!elm.firstChild) {
  14485. return false;
  14486. }
  14487. var startPos = CaretPosition$1.before(elm.firstChild);
  14488. var newPos = caretWalker.next(startPos);
  14489. return newPos && !isBeforeContentEditableFalse(newPos) && !isAfterContentEditableFalse(newPos);
  14490. };
  14491. var isInSameBlock = function (node1, node2) {
  14492. var block1 = editor.dom.getParent(node1, editor.dom.isBlock);
  14493. var block2 = editor.dom.getParent(node2, editor.dom.isBlock);
  14494. return block1 === block2;
  14495. };
  14496. var hasBetterMouseTarget = function (targetNode, caretNode) {
  14497. var targetBlock = editor.dom.getParent(targetNode, editor.dom.isBlock);
  14498. var caretBlock = editor.dom.getParent(caretNode, editor.dom.isBlock);
  14499. if (targetBlock && editor.dom.isChildOf(targetBlock, caretBlock) && isContentEditableFalse$9(getContentEditableRoot(editor, targetBlock)) === false) {
  14500. return true;
  14501. }
  14502. return targetBlock && !isInSameBlock(targetBlock, caretBlock) && hasNormalCaretPosition(targetBlock);
  14503. };
  14504. handleTouchSelect(editor);
  14505. editor.on('mousedown', function (e) {
  14506. var contentEditableRoot;
  14507. var targetElm = e.target;
  14508. if (targetElm !== rootNode && targetElm.nodeName !== 'HTML' && !editor.dom.isChildOf(targetElm, rootNode)) {
  14509. return;
  14510. }
  14511. if (EditorView.isXYInContentArea(editor, e.clientX, e.clientY) === false) {
  14512. return;
  14513. }
  14514. contentEditableRoot = getContentEditableRoot(editor, targetElm);
  14515. if (contentEditableRoot) {
  14516. if (isContentEditableFalse$9(contentEditableRoot)) {
  14517. e.preventDefault();
  14518. setContentEditableSelection(selectNode(editor, contentEditableRoot));
  14519. } else {
  14520. removeContentEditableSelection();
  14521. if (!(isContentEditableTrue$4(contentEditableRoot) && e.shiftKey) && !RangePoint.isXYWithinRange(e.clientX, e.clientY, editor.selection.getRng())) {
  14522. hideFakeCaret();
  14523. editor.selection.placeCaretAt(e.clientX, e.clientY);
  14524. }
  14525. }
  14526. } else if (isFakeCaretTarget(targetElm) === false) {
  14527. removeContentEditableSelection();
  14528. hideFakeCaret();
  14529. var caretInfo = closestCaret(rootNode, e.clientX, e.clientY);
  14530. if (caretInfo) {
  14531. if (!hasBetterMouseTarget(e.target, caretInfo.node)) {
  14532. e.preventDefault();
  14533. var range = showCaret(1, caretInfo.node, caretInfo.before, false);
  14534. editor.getBody().focus();
  14535. setRange(range);
  14536. }
  14537. }
  14538. }
  14539. });
  14540. editor.on('keypress', function (e) {
  14541. if (VK.modifierPressed(e)) {
  14542. return;
  14543. }
  14544. switch (e.keyCode) {
  14545. default:
  14546. if (isContentEditableFalse$9(editor.selection.getNode())) {
  14547. e.preventDefault();
  14548. }
  14549. break;
  14550. }
  14551. });
  14552. editor.on('GetSelectionRange', function (e) {
  14553. var rng = e.range;
  14554. if (selectedContentEditableNode) {
  14555. if (!selectedContentEditableNode.parentNode) {
  14556. selectedContentEditableNode = null;
  14557. return;
  14558. }
  14559. rng = rng.cloneRange();
  14560. rng.selectNode(selectedContentEditableNode);
  14561. e.range = rng;
  14562. }
  14563. });
  14564. editor.on('SetSelectionRange', function (e) {
  14565. e.range = normalizeShortEndedElementSelection(e.range);
  14566. var rng = setContentEditableSelection(e.range, e.forward);
  14567. if (rng) {
  14568. e.range = rng;
  14569. }
  14570. });
  14571. var isPasteBin = function (node) {
  14572. return node.id === 'mcepastebin';
  14573. };
  14574. editor.on('AfterSetSelectionRange', function (e) {
  14575. var rng = e.range;
  14576. if (!isRangeInCaretContainer(rng) && !isPasteBin(rng.startContainer.parentNode)) {
  14577. hideFakeCaret();
  14578. }
  14579. if (!isFakeSelectionElement(rng.startContainer.parentNode)) {
  14580. removeContentEditableSelection();
  14581. }
  14582. });
  14583. editor.on('copy', function (e) {
  14584. var clipboardData = e.clipboardData;
  14585. if (!e.isDefaultPrevented() && e.clipboardData && !Env.ie) {
  14586. var realSelectionElement = getRealSelectionElement();
  14587. if (realSelectionElement) {
  14588. e.preventDefault();
  14589. clipboardData.clearData();
  14590. clipboardData.setData('text/html', realSelectionElement.outerHTML);
  14591. clipboardData.setData('text/plain', realSelectionElement.outerText);
  14592. }
  14593. }
  14594. });
  14595. DragDropOverrides.init(editor);
  14596. CefFocus.setup(editor);
  14597. };
  14598. var isWithinCaretContainer = function (node) {
  14599. return isCaretContainer(node) || startsWithCaretContainer(node) || endsWithCaretContainer(node);
  14600. };
  14601. var isRangeInCaretContainer = function (rng) {
  14602. return isWithinCaretContainer(rng.startContainer) || isWithinCaretContainer(rng.endContainer);
  14603. };
  14604. var normalizeShortEndedElementSelection = function (rng) {
  14605. var shortEndedElements = editor.schema.getShortEndedElements();
  14606. var newRng = editor.dom.createRng();
  14607. var startContainer = rng.startContainer;
  14608. var startOffset = rng.startOffset;
  14609. var endContainer = rng.endContainer;
  14610. var endOffset = rng.endOffset;
  14611. if (has(shortEndedElements, startContainer.nodeName.toLowerCase())) {
  14612. if (startOffset === 0) {
  14613. newRng.setStartBefore(startContainer);
  14614. } else {
  14615. newRng.setStartAfter(startContainer);
  14616. }
  14617. } else {
  14618. newRng.setStart(startContainer, startOffset);
  14619. }
  14620. if (has(shortEndedElements, endContainer.nodeName.toLowerCase())) {
  14621. if (endOffset === 0) {
  14622. newRng.setEndBefore(endContainer);
  14623. } else {
  14624. newRng.setEndAfter(endContainer);
  14625. }
  14626. } else {
  14627. newRng.setEnd(endContainer, endOffset);
  14628. }
  14629. return newRng;
  14630. };
  14631. var setContentEditableSelection = function (range, forward) {
  14632. var node;
  14633. var $ = editor.$;
  14634. var dom = editor.dom;
  14635. var $realSelectionContainer, sel, startContainer, startOffset, endOffset, e, caretPosition, targetClone, origTargetClone;
  14636. if (!range) {
  14637. return null;
  14638. }
  14639. if (range.collapsed) {
  14640. if (!isRangeInCaretContainer(range)) {
  14641. if (forward === false) {
  14642. caretPosition = getNormalizedRangeEndPoint(-1, rootNode, range);
  14643. if (isFakeCaretTarget(caretPosition.getNode(true))) {
  14644. return showCaret(-1, caretPosition.getNode(true), false, false);
  14645. }
  14646. if (isFakeCaretTarget(caretPosition.getNode())) {
  14647. return showCaret(-1, caretPosition.getNode(), !caretPosition.isAtEnd(), false);
  14648. }
  14649. } else {
  14650. caretPosition = getNormalizedRangeEndPoint(1, rootNode, range);
  14651. if (isFakeCaretTarget(caretPosition.getNode())) {
  14652. return showCaret(1, caretPosition.getNode(), !caretPosition.isAtEnd(), false);
  14653. }
  14654. if (isFakeCaretTarget(caretPosition.getNode(true))) {
  14655. return showCaret(1, caretPosition.getNode(true), false, false);
  14656. }
  14657. }
  14658. }
  14659. return null;
  14660. }
  14661. startContainer = range.startContainer;
  14662. startOffset = range.startOffset;
  14663. endOffset = range.endOffset;
  14664. if (startContainer.nodeType === 3 && startOffset === 0 && isContentEditableFalse$9(startContainer.parentNode)) {
  14665. startContainer = startContainer.parentNode;
  14666. startOffset = dom.nodeIndex(startContainer);
  14667. startContainer = startContainer.parentNode;
  14668. }
  14669. if (startContainer.nodeType !== 1) {
  14670. return null;
  14671. }
  14672. if (endOffset === startOffset + 1 && startContainer === range.endContainer) {
  14673. node = startContainer.childNodes[startOffset];
  14674. }
  14675. if (!isContentEditableFalse$9(node)) {
  14676. return null;
  14677. }
  14678. targetClone = origTargetClone = node.cloneNode(true);
  14679. e = editor.fire('ObjectSelected', {
  14680. target: node,
  14681. targetClone: targetClone
  14682. });
  14683. if (e.isDefaultPrevented()) {
  14684. return null;
  14685. }
  14686. $realSelectionContainer = descendant(Element.fromDom(editor.getBody()), '#' + realSelectionId).fold(function () {
  14687. return $([]);
  14688. }, function (elm) {
  14689. return $([elm.dom()]);
  14690. });
  14691. targetClone = e.targetClone;
  14692. if ($realSelectionContainer.length === 0) {
  14693. $realSelectionContainer = $('<div data-mce-bogus="all" class="mce-offscreen-selection"></div>').attr('id', realSelectionId);
  14694. $realSelectionContainer.appendTo(editor.getBody());
  14695. }
  14696. range = editor.dom.createRng();
  14697. if (targetClone === origTargetClone && Env.ie) {
  14698. $realSelectionContainer.empty().append('<p style="font-size: 0" data-mce-bogus="all">\xA0</p>').append(targetClone);
  14699. range.setStartAfter($realSelectionContainer[0].firstChild.firstChild);
  14700. range.setEndAfter(targetClone);
  14701. } else {
  14702. $realSelectionContainer.empty().append('\xA0').append(targetClone).append('\xA0');
  14703. range.setStart($realSelectionContainer[0].firstChild, 1);
  14704. range.setEnd($realSelectionContainer[0].lastChild, 0);
  14705. }
  14706. $realSelectionContainer.css({ top: dom.getPos(node, editor.getBody()).y });
  14707. $realSelectionContainer[0].focus();
  14708. sel = editor.selection.getSel();
  14709. sel.removeAllRanges();
  14710. sel.addRange(range);
  14711. var nodeElm = Element.fromDom(node);
  14712. each(descendants$1(Element.fromDom(editor.getBody()), '*[data-mce-selected]'), function (elm) {
  14713. if (!eq(nodeElm, elm)) {
  14714. remove(elm, 'data-mce-selected');
  14715. }
  14716. });
  14717. if (!editor.dom.getAttrib(node, 'data-mce-selected')) {
  14718. node.setAttribute('data-mce-selected', '1');
  14719. }
  14720. selectedContentEditableNode = node;
  14721. hideFakeCaret();
  14722. return range;
  14723. };
  14724. var removeContentEditableSelection = function () {
  14725. if (selectedContentEditableNode) {
  14726. selectedContentEditableNode.removeAttribute('data-mce-selected');
  14727. descendant(Element.fromDom(editor.getBody()), '#' + realSelectionId).each(remove$1);
  14728. selectedContentEditableNode = null;
  14729. }
  14730. descendant(Element.fromDom(editor.getBody()), '#' + realSelectionId).each(remove$1);
  14731. selectedContentEditableNode = null;
  14732. };
  14733. var destroy = function () {
  14734. fakeCaret.destroy();
  14735. selectedContentEditableNode = null;
  14736. };
  14737. var hideFakeCaret = function () {
  14738. fakeCaret.hide();
  14739. };
  14740. if (Env.ceFalse) {
  14741. registerEvents();
  14742. }
  14743. return {
  14744. showCaret: showCaret,
  14745. showBlockCaretContainer: showBlockCaretContainer,
  14746. hideFakeCaret: hideFakeCaret,
  14747. destroy: destroy
  14748. };
  14749. };
  14750. var KEEP = 0, INSERT = 1, DELETE = 2;
  14751. var diff = function (left, right) {
  14752. var size = left.length + right.length + 2;
  14753. var vDown = new Array(size);
  14754. var vUp = new Array(size);
  14755. var snake = function (start, end, diag) {
  14756. return {
  14757. start: start,
  14758. end: end,
  14759. diag: diag
  14760. };
  14761. };
  14762. var buildScript = function (start1, end1, start2, end2, script) {
  14763. var middle = getMiddleSnake(start1, end1, start2, end2);
  14764. if (middle === null || middle.start === end1 && middle.diag === end1 - end2 || middle.end === start1 && middle.diag === start1 - start2) {
  14765. var i = start1;
  14766. var j = start2;
  14767. while (i < end1 || j < end2) {
  14768. if (i < end1 && j < end2 && left[i] === right[j]) {
  14769. script.push([
  14770. KEEP,
  14771. left[i]
  14772. ]);
  14773. ++i;
  14774. ++j;
  14775. } else {
  14776. if (end1 - start1 > end2 - start2) {
  14777. script.push([
  14778. DELETE,
  14779. left[i]
  14780. ]);
  14781. ++i;
  14782. } else {
  14783. script.push([
  14784. INSERT,
  14785. right[j]
  14786. ]);
  14787. ++j;
  14788. }
  14789. }
  14790. }
  14791. } else {
  14792. buildScript(start1, middle.start, start2, middle.start - middle.diag, script);
  14793. for (var i2 = middle.start; i2 < middle.end; ++i2) {
  14794. script.push([
  14795. KEEP,
  14796. left[i2]
  14797. ]);
  14798. }
  14799. buildScript(middle.end, end1, middle.end - middle.diag, end2, script);
  14800. }
  14801. };
  14802. var buildSnake = function (start, diag, end1, end2) {
  14803. var end = start;
  14804. while (end - diag < end2 && end < end1 && left[end] === right[end - diag]) {
  14805. ++end;
  14806. }
  14807. return snake(start, end, diag);
  14808. };
  14809. var getMiddleSnake = function (start1, end1, start2, end2) {
  14810. var m = end1 - start1;
  14811. var n = end2 - start2;
  14812. if (m === 0 || n === 0) {
  14813. return null;
  14814. }
  14815. var delta = m - n;
  14816. var sum = n + m;
  14817. var offset = (sum % 2 === 0 ? sum : sum + 1) / 2;
  14818. vDown[1 + offset] = start1;
  14819. vUp[1 + offset] = end1 + 1;
  14820. var d, k, i, x, y;
  14821. for (d = 0; d <= offset; ++d) {
  14822. for (k = -d; k <= d; k += 2) {
  14823. i = k + offset;
  14824. if (k === -d || k !== d && vDown[i - 1] < vDown[i + 1]) {
  14825. vDown[i] = vDown[i + 1];
  14826. } else {
  14827. vDown[i] = vDown[i - 1] + 1;
  14828. }
  14829. x = vDown[i];
  14830. y = x - start1 + start2 - k;
  14831. while (x < end1 && y < end2 && left[x] === right[y]) {
  14832. vDown[i] = ++x;
  14833. ++y;
  14834. }
  14835. if (delta % 2 !== 0 && delta - d <= k && k <= delta + d) {
  14836. if (vUp[i - delta] <= vDown[i]) {
  14837. return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2);
  14838. }
  14839. }
  14840. }
  14841. for (k = delta - d; k <= delta + d; k += 2) {
  14842. i = k + offset - delta;
  14843. if (k === delta - d || k !== delta + d && vUp[i + 1] <= vUp[i - 1]) {
  14844. vUp[i] = vUp[i + 1] - 1;
  14845. } else {
  14846. vUp[i] = vUp[i - 1];
  14847. }
  14848. x = vUp[i] - 1;
  14849. y = x - start1 + start2 - k;
  14850. while (x >= start1 && y >= start2 && left[x] === right[y]) {
  14851. vUp[i] = x--;
  14852. y--;
  14853. }
  14854. if (delta % 2 === 0 && -d <= k && k <= d) {
  14855. if (vUp[i] <= vDown[i + delta]) {
  14856. return buildSnake(vUp[i], k + start1 - start2, end1, end2);
  14857. }
  14858. }
  14859. }
  14860. }
  14861. };
  14862. var script = [];
  14863. buildScript(0, left.length, 0, right.length, script);
  14864. return script;
  14865. };
  14866. var Diff = {
  14867. KEEP: KEEP,
  14868. DELETE: DELETE,
  14869. INSERT: INSERT,
  14870. diff: diff
  14871. };
  14872. var getOuterHtml = function (elm) {
  14873. if (NodeType.isElement(elm)) {
  14874. return elm.outerHTML;
  14875. } else if (NodeType.isText(elm)) {
  14876. return Entities.encodeRaw(elm.data, false);
  14877. } else if (NodeType.isComment(elm)) {
  14878. return '<!--' + elm.data + '-->';
  14879. }
  14880. return '';
  14881. };
  14882. var createFragment$1 = function (html) {
  14883. var frag, node, container;
  14884. container = domGlobals.document.createElement('div');
  14885. frag = domGlobals.document.createDocumentFragment();
  14886. if (html) {
  14887. container.innerHTML = html;
  14888. }
  14889. while (node = container.firstChild) {
  14890. frag.appendChild(node);
  14891. }
  14892. return frag;
  14893. };
  14894. var insertAt = function (elm, html, index) {
  14895. var fragment = createFragment$1(html);
  14896. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  14897. var target = elm.childNodes[index];
  14898. target.parentNode.insertBefore(fragment, target);
  14899. } else {
  14900. elm.appendChild(fragment);
  14901. }
  14902. };
  14903. var removeAt = function (elm, index) {
  14904. if (elm.hasChildNodes() && index < elm.childNodes.length) {
  14905. var target = elm.childNodes[index];
  14906. target.parentNode.removeChild(target);
  14907. }
  14908. };
  14909. var applyDiff = function (diff, elm) {
  14910. var index = 0;
  14911. each(diff, function (action) {
  14912. if (action[0] === Diff.KEEP) {
  14913. index++;
  14914. } else if (action[0] === Diff.INSERT) {
  14915. insertAt(elm, action[1], index);
  14916. index++;
  14917. } else if (action[0] === Diff.DELETE) {
  14918. removeAt(elm, index);
  14919. }
  14920. });
  14921. };
  14922. var read$1 = function (elm) {
  14923. return filter(map(from$1(elm.childNodes), getOuterHtml), function (item) {
  14924. return item.length > 0;
  14925. });
  14926. };
  14927. var write = function (fragments, elm) {
  14928. var currentFragments = map(from$1(elm.childNodes), getOuterHtml);
  14929. applyDiff(Diff.diff(currentFragments, fragments), elm);
  14930. return elm;
  14931. };
  14932. var Fragments = {
  14933. read: read$1,
  14934. write: write
  14935. };
  14936. var undoLevelDocument = Cell(Option.none());
  14937. var lazyTempDocument = function () {
  14938. return undoLevelDocument.get().getOrThunk(function () {
  14939. var doc = domGlobals.document.implementation.createHTMLDocument('undo');
  14940. undoLevelDocument.set(Option.some(doc));
  14941. return doc;
  14942. });
  14943. };
  14944. var hasIframes = function (html) {
  14945. return html.indexOf('</iframe>') !== -1;
  14946. };
  14947. var createFragmentedLevel = function (fragments) {
  14948. return {
  14949. type: 'fragmented',
  14950. fragments: fragments,
  14951. content: '',
  14952. bookmark: null,
  14953. beforeBookmark: null
  14954. };
  14955. };
  14956. var createCompleteLevel = function (content) {
  14957. return {
  14958. type: 'complete',
  14959. fragments: null,
  14960. content: content,
  14961. bookmark: null,
  14962. beforeBookmark: null
  14963. };
  14964. };
  14965. var createFromEditor = function (editor) {
  14966. var fragments, content, trimmedFragments;
  14967. fragments = Fragments.read(editor.getBody());
  14968. trimmedFragments = bind(fragments, function (html) {
  14969. var trimmed = TrimHtml.trimInternal(editor.serializer, html);
  14970. return trimmed.length > 0 ? [trimmed] : [];
  14971. });
  14972. content = trimmedFragments.join('');
  14973. return hasIframes(content) ? createFragmentedLevel(trimmedFragments) : createCompleteLevel(content);
  14974. };
  14975. var applyToEditor = function (editor, level, before) {
  14976. if (level.type === 'fragmented') {
  14977. Fragments.write(level.fragments, editor.getBody());
  14978. } else {
  14979. editor.setContent(level.content, { format: 'raw' });
  14980. }
  14981. editor.selection.moveToBookmark(before ? level.beforeBookmark : level.bookmark);
  14982. };
  14983. var getLevelContent = function (level) {
  14984. return level.type === 'fragmented' ? level.fragments.join('') : level.content;
  14985. };
  14986. var getCleanLevelContent = function (level) {
  14987. var elm = Element.fromTag('body', lazyTempDocument());
  14988. set$1(elm, getLevelContent(level));
  14989. each(descendants$1(elm, '*[data-mce-bogus]'), unwrap);
  14990. return get$5(elm);
  14991. };
  14992. var hasEqualContent = function (level1, level2) {
  14993. return getLevelContent(level1) === getLevelContent(level2);
  14994. };
  14995. var hasEqualCleanedContent = function (level1, level2) {
  14996. return getCleanLevelContent(level1) === getCleanLevelContent(level2);
  14997. };
  14998. var isEq$2 = function (level1, level2) {
  14999. if (!level1 || !level2) {
  15000. return false;
  15001. } else if (hasEqualContent(level1, level2)) {
  15002. return true;
  15003. } else {
  15004. return hasEqualCleanedContent(level1, level2);
  15005. }
  15006. };
  15007. var Levels = {
  15008. createFragmentedLevel: createFragmentedLevel,
  15009. createCompleteLevel: createCompleteLevel,
  15010. createFromEditor: createFromEditor,
  15011. applyToEditor: applyToEditor,
  15012. isEq: isEq$2
  15013. };
  15014. var isUnlocked = function (locks) {
  15015. return locks.get() === 0;
  15016. };
  15017. var setTyping = function (undoManager, typing, locks) {
  15018. if (isUnlocked(locks)) {
  15019. undoManager.typing = typing;
  15020. }
  15021. };
  15022. var endTyping = function (undoManager, locks) {
  15023. if (undoManager.typing) {
  15024. setTyping(undoManager, false, locks);
  15025. undoManager.add();
  15026. }
  15027. };
  15028. var endTypingLevelIgnoreLocks = function (undoManager) {
  15029. if (undoManager.typing) {
  15030. undoManager.typing = false;
  15031. undoManager.add();
  15032. }
  15033. };
  15034. var beforeChange = function (editor, locks, beforeBookmark) {
  15035. if (isUnlocked(locks)) {
  15036. beforeBookmark.set(Option.some(GetBookmark.getUndoBookmark(editor.selection)));
  15037. }
  15038. };
  15039. var addUndoLevel = function (editor, undoManager, index, locks, beforeBookmark, level, event) {
  15040. var settings = editor.settings;
  15041. var currentLevel = Levels.createFromEditor(editor);
  15042. level = level || {};
  15043. level = Tools.extend(level, currentLevel);
  15044. if (isUnlocked(locks) === false || editor.removed) {
  15045. return null;
  15046. }
  15047. var lastLevel = undoManager.data[index.get()];
  15048. if (editor.fire('BeforeAddUndo', {
  15049. level: level,
  15050. lastLevel: lastLevel,
  15051. originalEvent: event
  15052. }).isDefaultPrevented()) {
  15053. return null;
  15054. }
  15055. if (lastLevel && Levels.isEq(lastLevel, level)) {
  15056. return null;
  15057. }
  15058. if (undoManager.data[index.get()]) {
  15059. beforeBookmark.get().each(function (bm) {
  15060. undoManager.data[index.get()].beforeBookmark = bm;
  15061. });
  15062. }
  15063. if (settings.custom_undo_redo_levels) {
  15064. if (undoManager.data.length > settings.custom_undo_redo_levels) {
  15065. for (var i = 0; i < undoManager.data.length - 1; i++) {
  15066. undoManager.data[i] = undoManager.data[i + 1];
  15067. }
  15068. undoManager.data.length--;
  15069. index.set(undoManager.data.length);
  15070. }
  15071. }
  15072. level.bookmark = GetBookmark.getUndoBookmark(editor.selection);
  15073. if (index.get() < undoManager.data.length - 1) {
  15074. undoManager.data.length = index.get() + 1;
  15075. }
  15076. undoManager.data.push(level);
  15077. index.set(undoManager.data.length - 1);
  15078. var args = {
  15079. level: level,
  15080. lastLevel: lastLevel,
  15081. originalEvent: event
  15082. };
  15083. editor.fire('AddUndo', args);
  15084. if (index.get() > 0) {
  15085. editor.setDirty(true);
  15086. editor.fire('change', args);
  15087. }
  15088. return level;
  15089. };
  15090. var clear = function (editor, undoManager, index) {
  15091. undoManager.data = [];
  15092. index.set(0);
  15093. undoManager.typing = false;
  15094. editor.fire('ClearUndos');
  15095. };
  15096. var extra = function (editor, undoManager, index, callback1, callback2) {
  15097. if (undoManager.transact(callback1)) {
  15098. var bookmark = undoManager.data[index.get()].bookmark;
  15099. var lastLevel = undoManager.data[index.get() - 1];
  15100. Levels.applyToEditor(editor, lastLevel, true);
  15101. if (undoManager.transact(callback2)) {
  15102. undoManager.data[index.get() - 1].beforeBookmark = bookmark;
  15103. }
  15104. }
  15105. };
  15106. var redo = function (editor, index, data) {
  15107. var level;
  15108. if (index.get() < data.length - 1) {
  15109. index.set(index.get() + 1);
  15110. level = data[index.get()];
  15111. Levels.applyToEditor(editor, level, false);
  15112. editor.setDirty(true);
  15113. editor.fire('Redo', { level: level });
  15114. }
  15115. return level;
  15116. };
  15117. var undo = function (editor, undoManager, locks, index) {
  15118. var level;
  15119. if (undoManager.typing) {
  15120. undoManager.add();
  15121. undoManager.typing = false;
  15122. setTyping(undoManager, false, locks);
  15123. }
  15124. if (index.get() > 0) {
  15125. index.set(index.get() - 1);
  15126. level = undoManager.data[index.get()];
  15127. Levels.applyToEditor(editor, level, true);
  15128. editor.setDirty(true);
  15129. editor.fire('Undo', { level: level });
  15130. }
  15131. return level;
  15132. };
  15133. var reset = function (undoManager) {
  15134. undoManager.clear();
  15135. undoManager.add();
  15136. };
  15137. var hasUndo = function (editor, undoManager, index) {
  15138. return index.get() > 0 || undoManager.typing && undoManager.data[0] && !Levels.isEq(Levels.createFromEditor(editor), undoManager.data[0]);
  15139. };
  15140. var hasRedo = function (undoManager, index) {
  15141. return index.get() < undoManager.data.length - 1 && !undoManager.typing;
  15142. };
  15143. var transact = function (undoManager, locks, callback) {
  15144. endTyping(undoManager, locks);
  15145. undoManager.beforeChange();
  15146. undoManager.ignore(callback);
  15147. return undoManager.add();
  15148. };
  15149. var ignore = function (locks, callback) {
  15150. try {
  15151. locks.set(locks.get() + 1);
  15152. callback();
  15153. } finally {
  15154. locks.set(locks.get() - 1);
  15155. }
  15156. };
  15157. var registerEvents$1 = function (editor, undoManager, locks) {
  15158. var isFirstTypedCharacter = Cell(false);
  15159. var addNonTypingUndoLevel = function (e) {
  15160. setTyping(undoManager, false, locks);
  15161. undoManager.add({}, e);
  15162. };
  15163. editor.on('init', function () {
  15164. undoManager.add();
  15165. });
  15166. editor.on('BeforeExecCommand', function (e) {
  15167. var cmd = e.command;
  15168. if (cmd !== 'Undo' && cmd !== 'Redo' && cmd !== 'mceRepaint') {
  15169. endTyping(undoManager, locks);
  15170. undoManager.beforeChange();
  15171. }
  15172. });
  15173. editor.on('ExecCommand', function (e) {
  15174. var cmd = e.command;
  15175. if (cmd !== 'Undo' && cmd !== 'Redo' && cmd !== 'mceRepaint') {
  15176. addNonTypingUndoLevel(e);
  15177. }
  15178. });
  15179. editor.on('ObjectResizeStart cut', function () {
  15180. undoManager.beforeChange();
  15181. });
  15182. editor.on('SaveContent ObjectResized blur', addNonTypingUndoLevel);
  15183. editor.on('dragend', addNonTypingUndoLevel);
  15184. editor.on('keyup', function (e) {
  15185. var keyCode = e.keyCode;
  15186. if (e.isDefaultPrevented()) {
  15187. return;
  15188. }
  15189. if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45 || e.ctrlKey) {
  15190. addNonTypingUndoLevel();
  15191. editor.nodeChanged();
  15192. }
  15193. if (keyCode === 46 || keyCode === 8) {
  15194. editor.nodeChanged();
  15195. }
  15196. if (isFirstTypedCharacter.get() && undoManager.typing && Levels.isEq(Levels.createFromEditor(editor), undoManager.data[0]) === false) {
  15197. if (editor.isDirty() === false) {
  15198. editor.setDirty(true);
  15199. editor.fire('change', {
  15200. level: undoManager.data[0],
  15201. lastLevel: null
  15202. });
  15203. }
  15204. editor.fire('TypingUndo');
  15205. isFirstTypedCharacter.set(false);
  15206. editor.nodeChanged();
  15207. }
  15208. });
  15209. editor.on('keydown', function (e) {
  15210. var keyCode = e.keyCode;
  15211. if (e.isDefaultPrevented()) {
  15212. return;
  15213. }
  15214. if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45) {
  15215. if (undoManager.typing) {
  15216. addNonTypingUndoLevel(e);
  15217. }
  15218. return;
  15219. }
  15220. var modKey = e.ctrlKey && !e.altKey || e.metaKey;
  15221. if ((keyCode < 16 || keyCode > 20) && keyCode !== 224 && keyCode !== 91 && !undoManager.typing && !modKey) {
  15222. undoManager.beforeChange();
  15223. setTyping(undoManager, true, locks);
  15224. undoManager.add({}, e);
  15225. isFirstTypedCharacter.set(true);
  15226. }
  15227. });
  15228. editor.on('mousedown', function (e) {
  15229. if (undoManager.typing) {
  15230. addNonTypingUndoLevel(e);
  15231. }
  15232. });
  15233. var isInsertReplacementText = function (event) {
  15234. return event.inputType === 'insertReplacementText';
  15235. };
  15236. var isInsertTextDataNull = function (event) {
  15237. return event.inputType === 'insertText' && event.data === null;
  15238. };
  15239. editor.on('input', function (e) {
  15240. if (e.inputType && (isInsertReplacementText(e) || isInsertTextDataNull(e))) {
  15241. addNonTypingUndoLevel(e);
  15242. }
  15243. });
  15244. editor.on('AddUndo Undo Redo ClearUndos', function (e) {
  15245. if (!e.isDefaultPrevented()) {
  15246. editor.nodeChanged();
  15247. }
  15248. });
  15249. };
  15250. var addKeyboardShortcuts = function (editor) {
  15251. editor.addShortcut('meta+z', '', 'Undo');
  15252. editor.addShortcut('meta+y,meta+shift+z', '', 'Redo');
  15253. };
  15254. var UndoManager = function (editor) {
  15255. var beforeBookmark = Cell(Option.none());
  15256. var locks = Cell(0);
  15257. var index = Cell(0);
  15258. var undoManager = {
  15259. data: [],
  15260. typing: false,
  15261. beforeChange: function () {
  15262. beforeChange(editor, locks, beforeBookmark);
  15263. },
  15264. add: function (level, event) {
  15265. return addUndoLevel(editor, undoManager, index, locks, beforeBookmark, level, event);
  15266. },
  15267. undo: function () {
  15268. return undo(editor, undoManager, locks, index);
  15269. },
  15270. redo: function () {
  15271. return redo(editor, index, undoManager.data);
  15272. },
  15273. clear: function () {
  15274. clear(editor, undoManager, index);
  15275. },
  15276. reset: function () {
  15277. reset(undoManager);
  15278. },
  15279. hasUndo: function () {
  15280. return hasUndo(editor, undoManager, index);
  15281. },
  15282. hasRedo: function () {
  15283. return hasRedo(undoManager, index);
  15284. },
  15285. transact: function (callback) {
  15286. return transact(undoManager, locks, callback);
  15287. },
  15288. ignore: function (callback) {
  15289. ignore(locks, callback);
  15290. },
  15291. extra: function (callback1, callback2) {
  15292. extra(editor, undoManager, index, callback1, callback2);
  15293. }
  15294. };
  15295. registerEvents$1(editor, undoManager, locks);
  15296. addKeyboardShortcuts(editor);
  15297. return undoManager;
  15298. };
  15299. var getLastChildren$1 = function (elm) {
  15300. var children = [];
  15301. var rawNode = elm.dom();
  15302. while (rawNode) {
  15303. children.push(Element.fromDom(rawNode));
  15304. rawNode = rawNode.lastChild;
  15305. }
  15306. return children;
  15307. };
  15308. var removeTrailingBr = function (elm) {
  15309. var allBrs = descendants$1(elm, 'br');
  15310. var brs = filter(getLastChildren$1(elm).slice(-1), isBr$1);
  15311. if (allBrs.length === brs.length) {
  15312. each(brs, remove$1);
  15313. }
  15314. };
  15315. var fillWithPaddingBr = function (elm) {
  15316. empty(elm);
  15317. append(elm, Element.fromHtml('<br data-mce-bogus="1">'));
  15318. };
  15319. var isPaddingContents = function (elm) {
  15320. return isText$1(elm) ? get$6(elm) === '\xA0' : isBr$1(elm);
  15321. };
  15322. var isPaddedElement = function (elm) {
  15323. return filter(children(elm), isPaddingContents).length === 1;
  15324. };
  15325. var trimBlockTrailingBr = function (elm) {
  15326. lastChild(elm).each(function (lastChild) {
  15327. prevSibling(lastChild).each(function (lastChildPrevSibling) {
  15328. if (isBlock(elm) && isBr$1(lastChild) && isBlock(lastChildPrevSibling)) {
  15329. remove$1(lastChild);
  15330. }
  15331. });
  15332. });
  15333. };
  15334. var PaddingBr = {
  15335. removeTrailingBr: removeTrailingBr,
  15336. fillWithPaddingBr: fillWithPaddingBr,
  15337. isPaddedElement: isPaddedElement,
  15338. trimBlockTrailingBr: trimBlockTrailingBr
  15339. };
  15340. var isEq$3 = FormatUtils.isEq;
  15341. var matchesUnInheritedFormatSelector = function (ed, node, name) {
  15342. var formatList = ed.formatter.get(name);
  15343. if (formatList) {
  15344. for (var i = 0; i < formatList.length; i++) {
  15345. if (formatList[i].inherit === false && ed.dom.is(node, formatList[i].selector)) {
  15346. return true;
  15347. }
  15348. }
  15349. }
  15350. return false;
  15351. };
  15352. var matchParents = function (editor, node, name, vars) {
  15353. var root = editor.dom.getRoot();
  15354. if (node === root) {
  15355. return false;
  15356. }
  15357. node = editor.dom.getParent(node, function (node) {
  15358. if (matchesUnInheritedFormatSelector(editor, node, name)) {
  15359. return true;
  15360. }
  15361. return node.parentNode === root || !!matchNode(editor, node, name, vars, true);
  15362. });
  15363. return matchNode(editor, node, name, vars);
  15364. };
  15365. var matchName = function (dom, node, format) {
  15366. if (isEq$3(node, format.inline)) {
  15367. return true;
  15368. }
  15369. if (isEq$3(node, format.block)) {
  15370. return true;
  15371. }
  15372. if (format.selector) {
  15373. return node.nodeType === 1 && dom.is(node, format.selector);
  15374. }
  15375. };
  15376. var matchItems = function (dom, node, format, itemName, similar, vars) {
  15377. var key, value;
  15378. var items = format[itemName];
  15379. var i;
  15380. if (format.onmatch) {
  15381. return format.onmatch(node, format, itemName);
  15382. }
  15383. if (items) {
  15384. if (typeof items.length === 'undefined') {
  15385. for (key in items) {
  15386. if (items.hasOwnProperty(key)) {
  15387. if (itemName === 'attributes') {
  15388. value = dom.getAttrib(node, key);
  15389. } else {
  15390. value = FormatUtils.getStyle(dom, node, key);
  15391. }
  15392. if (similar && !value && !format.exact) {
  15393. return;
  15394. }
  15395. if ((!similar || format.exact) && !isEq$3(value, FormatUtils.normalizeStyleValue(dom, FormatUtils.replaceVars(items[key], vars), key))) {
  15396. return;
  15397. }
  15398. }
  15399. }
  15400. } else {
  15401. for (i = 0; i < items.length; i++) {
  15402. if (itemName === 'attributes' ? dom.getAttrib(node, items[i]) : FormatUtils.getStyle(dom, node, items[i])) {
  15403. return format;
  15404. }
  15405. }
  15406. }
  15407. }
  15408. return format;
  15409. };
  15410. var matchNode = function (ed, node, name, vars, similar) {
  15411. var formatList = ed.formatter.get(name);
  15412. var format, i, x, classes;
  15413. var dom = ed.dom;
  15414. if (formatList && node) {
  15415. for (i = 0; i < formatList.length; i++) {
  15416. format = formatList[i];
  15417. if (matchName(ed.dom, node, format) && matchItems(dom, node, format, 'attributes', similar, vars) && matchItems(dom, node, format, 'styles', similar, vars)) {
  15418. if (classes = format.classes) {
  15419. for (x = 0; x < classes.length; x++) {
  15420. if (!ed.dom.hasClass(node, classes[x])) {
  15421. return;
  15422. }
  15423. }
  15424. }
  15425. return format;
  15426. }
  15427. }
  15428. }
  15429. };
  15430. var match = function (editor, name, vars, node) {
  15431. var startNode;
  15432. if (node) {
  15433. return matchParents(editor, node, name, vars);
  15434. }
  15435. node = editor.selection.getNode();
  15436. if (matchParents(editor, node, name, vars)) {
  15437. return true;
  15438. }
  15439. startNode = editor.selection.getStart();
  15440. if (startNode !== node) {
  15441. if (matchParents(editor, startNode, name, vars)) {
  15442. return true;
  15443. }
  15444. }
  15445. return false;
  15446. };
  15447. var matchAll = function (editor, names, vars) {
  15448. var startElement;
  15449. var matchedFormatNames = [];
  15450. var checkedMap = {};
  15451. startElement = editor.selection.getStart();
  15452. editor.dom.getParent(startElement, function (node) {
  15453. var i, name;
  15454. for (i = 0; i < names.length; i++) {
  15455. name = names[i];
  15456. if (!checkedMap[name] && matchNode(editor, node, name, vars)) {
  15457. checkedMap[name] = true;
  15458. matchedFormatNames.push(name);
  15459. }
  15460. }
  15461. }, editor.dom.getRoot());
  15462. return matchedFormatNames;
  15463. };
  15464. var canApply = function (editor, name) {
  15465. var formatList = editor.formatter.get(name);
  15466. var startNode, parents, i, x, selector;
  15467. var dom = editor.dom;
  15468. if (formatList) {
  15469. startNode = editor.selection.getStart();
  15470. parents = FormatUtils.getParents(dom, startNode);
  15471. for (x = formatList.length - 1; x >= 0; x--) {
  15472. selector = formatList[x].selector;
  15473. if (!selector || formatList[x].defaultBlock) {
  15474. return true;
  15475. }
  15476. for (i = parents.length - 1; i >= 0; i--) {
  15477. if (dom.is(parents[i], selector)) {
  15478. return true;
  15479. }
  15480. }
  15481. }
  15482. }
  15483. return false;
  15484. };
  15485. var MatchFormat = {
  15486. matchNode: matchNode,
  15487. matchName: matchName,
  15488. match: match,
  15489. matchAll: matchAll,
  15490. canApply: canApply,
  15491. matchesUnInheritedFormatSelector: matchesUnInheritedFormatSelector
  15492. };
  15493. var splitText = function (node, offset) {
  15494. return node.splitText(offset);
  15495. };
  15496. var split$1 = function (rng) {
  15497. var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
  15498. if (startContainer === endContainer && NodeType.isText(startContainer)) {
  15499. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  15500. endContainer = splitText(startContainer, startOffset);
  15501. startContainer = endContainer.previousSibling;
  15502. if (endOffset > startOffset) {
  15503. endOffset = endOffset - startOffset;
  15504. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  15505. endOffset = endContainer.nodeValue.length;
  15506. startOffset = 0;
  15507. } else {
  15508. endOffset = 0;
  15509. }
  15510. }
  15511. } else {
  15512. if (NodeType.isText(startContainer) && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  15513. startContainer = splitText(startContainer, startOffset);
  15514. startOffset = 0;
  15515. }
  15516. if (NodeType.isText(endContainer) && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  15517. endContainer = splitText(endContainer, endOffset).previousSibling;
  15518. endOffset = endContainer.nodeValue.length;
  15519. }
  15520. }
  15521. return {
  15522. startContainer: startContainer,
  15523. startOffset: startOffset,
  15524. endContainer: endContainer,
  15525. endOffset: endOffset
  15526. };
  15527. };
  15528. var isCollapsibleWhitespace = function (c) {
  15529. return ' \f\n\r\t\x0B'.indexOf(c) !== -1;
  15530. };
  15531. var normalizeContent = function (content, isStartOfContent, isEndOfContent) {
  15532. var result = foldl(content, function (acc, c) {
  15533. if (isCollapsibleWhitespace(c) || c === '\xA0') {
  15534. if (acc.previousCharIsSpace || acc.str === '' && isStartOfContent || acc.str.length === content.length - 1 && isEndOfContent) {
  15535. return {
  15536. previousCharIsSpace: false,
  15537. str: acc.str + '\xA0'
  15538. };
  15539. } else {
  15540. return {
  15541. previousCharIsSpace: true,
  15542. str: acc.str + ' '
  15543. };
  15544. }
  15545. } else {
  15546. return {
  15547. previousCharIsSpace: false,
  15548. str: acc.str + c
  15549. };
  15550. }
  15551. }, {
  15552. previousCharIsSpace: false,
  15553. str: ''
  15554. });
  15555. return result.str;
  15556. };
  15557. var normalize = function (node, offset, count) {
  15558. if (count === 0) {
  15559. return;
  15560. }
  15561. var whitespace = node.data.slice(offset, offset + count);
  15562. var isEndOfContent = offset + count >= node.data.length;
  15563. var isStartOfContent = offset === 0;
  15564. node.replaceData(offset, count, normalizeContent(whitespace, isStartOfContent, isEndOfContent));
  15565. };
  15566. var normalizeWhitespaceAfter = function (node, offset) {
  15567. var content = node.data.slice(offset);
  15568. var whitespaceCount = content.length - lTrim(content).length;
  15569. return normalize(node, offset, whitespaceCount);
  15570. };
  15571. var normalizeWhitespaceBefore = function (node, offset) {
  15572. var content = node.data.slice(0, offset);
  15573. var whitespaceCount = content.length - rTrim(content).length;
  15574. return normalize(node, offset - whitespaceCount, whitespaceCount);
  15575. };
  15576. var mergeTextNodes = function (prevNode, nextNode, normalizeWhitespace) {
  15577. var whitespaceOffset = rTrim(prevNode.data).length;
  15578. prevNode.appendData(nextNode.data);
  15579. remove$1(Element.fromDom(nextNode));
  15580. if (normalizeWhitespace) {
  15581. normalizeWhitespaceAfter(prevNode, whitespaceOffset);
  15582. }
  15583. return prevNode;
  15584. };
  15585. var ancestor$2 = function (scope, selector, isRoot) {
  15586. return ancestor$1(scope, selector, isRoot).isSome();
  15587. };
  15588. var hasWhitespacePreserveParent = function (rootNode, node) {
  15589. var rootElement = Element.fromDom(rootNode);
  15590. var startNode = Element.fromDom(node);
  15591. return ancestor$2(startNode, 'pre,code', curry(eq, rootElement));
  15592. };
  15593. var isWhitespace = function (rootNode, node) {
  15594. return NodeType.isText(node) && /^[ \t\r\n]*$/.test(node.data) && hasWhitespacePreserveParent(rootNode, node) === false;
  15595. };
  15596. var isNamedAnchor = function (node) {
  15597. return NodeType.isElement(node) && node.nodeName === 'A' && node.hasAttribute('name');
  15598. };
  15599. var isContent$1 = function (rootNode, node) {
  15600. return isCaretCandidate(node) && isWhitespace(rootNode, node) === false || isNamedAnchor(node) || isBookmark(node);
  15601. };
  15602. var isBookmark = NodeType.hasAttribute('data-mce-bookmark');
  15603. var isBogus$2 = NodeType.hasAttribute('data-mce-bogus');
  15604. var isBogusAll$1 = NodeType.hasAttributeValue('data-mce-bogus', 'all');
  15605. var isEmptyNode = function (targetNode) {
  15606. var node, brCount = 0;
  15607. if (isContent$1(targetNode, targetNode)) {
  15608. return false;
  15609. } else {
  15610. node = targetNode.firstChild;
  15611. if (!node) {
  15612. return true;
  15613. }
  15614. var walker = new TreeWalker(node, targetNode);
  15615. do {
  15616. if (isBogusAll$1(node)) {
  15617. node = walker.next(true);
  15618. continue;
  15619. }
  15620. if (isBogus$2(node)) {
  15621. node = walker.next();
  15622. continue;
  15623. }
  15624. if (NodeType.isBr(node)) {
  15625. brCount++;
  15626. node = walker.next();
  15627. continue;
  15628. }
  15629. if (isContent$1(targetNode, node)) {
  15630. return false;
  15631. }
  15632. node = walker.next();
  15633. } while (node);
  15634. return brCount <= 1;
  15635. }
  15636. };
  15637. var isEmpty$1 = function (elm) {
  15638. return isEmptyNode(elm.dom());
  15639. };
  15640. var Empty = { isEmpty: isEmpty$1 };
  15641. var needsReposition = function (pos, elm) {
  15642. var container = pos.container();
  15643. var offset = pos.offset();
  15644. return CaretPosition$1.isTextPosition(pos) === false && container === elm.parentNode && offset > CaretPosition$1.before(elm).offset();
  15645. };
  15646. var reposition = function (elm, pos) {
  15647. return needsReposition(pos, elm) ? CaretPosition$1(pos.container(), pos.offset() - 1) : pos;
  15648. };
  15649. var beforeOrStartOf = function (node) {
  15650. return NodeType.isText(node) ? CaretPosition$1(node, 0) : CaretPosition$1.before(node);
  15651. };
  15652. var afterOrEndOf = function (node) {
  15653. return NodeType.isText(node) ? CaretPosition$1(node, node.data.length) : CaretPosition$1.after(node);
  15654. };
  15655. var getPreviousSiblingCaretPosition = function (elm) {
  15656. if (isCaretCandidate(elm.previousSibling)) {
  15657. return Option.some(afterOrEndOf(elm.previousSibling));
  15658. } else {
  15659. return elm.previousSibling ? CaretFinder.lastPositionIn(elm.previousSibling) : Option.none();
  15660. }
  15661. };
  15662. var getNextSiblingCaretPosition = function (elm) {
  15663. if (isCaretCandidate(elm.nextSibling)) {
  15664. return Option.some(beforeOrStartOf(elm.nextSibling));
  15665. } else {
  15666. return elm.nextSibling ? CaretFinder.firstPositionIn(elm.nextSibling) : Option.none();
  15667. }
  15668. };
  15669. var findCaretPositionBackwardsFromElm = function (rootElement, elm) {
  15670. var startPosition = CaretPosition$1.before(elm.previousSibling ? elm.previousSibling : elm.parentNode);
  15671. return CaretFinder.prevPosition(rootElement, startPosition).fold(function () {
  15672. return CaretFinder.nextPosition(rootElement, CaretPosition$1.after(elm));
  15673. }, Option.some);
  15674. };
  15675. var findCaretPositionForwardsFromElm = function (rootElement, elm) {
  15676. return CaretFinder.nextPosition(rootElement, CaretPosition$1.after(elm)).fold(function () {
  15677. return CaretFinder.prevPosition(rootElement, CaretPosition$1.before(elm));
  15678. }, Option.some);
  15679. };
  15680. var findCaretPositionBackwards = function (rootElement, elm) {
  15681. return getPreviousSiblingCaretPosition(elm).orThunk(function () {
  15682. return getNextSiblingCaretPosition(elm);
  15683. }).orThunk(function () {
  15684. return findCaretPositionBackwardsFromElm(rootElement, elm);
  15685. });
  15686. };
  15687. var findCaretPositionForward = function (rootElement, elm) {
  15688. return getNextSiblingCaretPosition(elm).orThunk(function () {
  15689. return getPreviousSiblingCaretPosition(elm);
  15690. }).orThunk(function () {
  15691. return findCaretPositionForwardsFromElm(rootElement, elm);
  15692. });
  15693. };
  15694. var findCaretPosition$1 = function (forward, rootElement, elm) {
  15695. return forward ? findCaretPositionForward(rootElement, elm) : findCaretPositionBackwards(rootElement, elm);
  15696. };
  15697. var findCaretPosOutsideElmAfterDelete = function (forward, rootElement, elm) {
  15698. return findCaretPosition$1(forward, rootElement, elm).map(curry(reposition, elm));
  15699. };
  15700. var setSelection = function (editor, forward, pos) {
  15701. pos.fold(function () {
  15702. editor.focus();
  15703. }, function (pos) {
  15704. editor.selection.setRng(pos.toRange(), forward);
  15705. });
  15706. };
  15707. var eqRawNode = function (rawNode) {
  15708. return function (elm) {
  15709. return elm.dom() === rawNode;
  15710. };
  15711. };
  15712. var isBlock$2 = function (editor, elm) {
  15713. return elm && editor.schema.getBlockElements().hasOwnProperty(name(elm));
  15714. };
  15715. var paddEmptyBlock = function (elm) {
  15716. if (Empty.isEmpty(elm)) {
  15717. var br = Element.fromHtml('<br data-mce-bogus="1">');
  15718. empty(elm);
  15719. append(elm, br);
  15720. return Option.some(CaretPosition$1.before(br.dom()));
  15721. } else {
  15722. return Option.none();
  15723. }
  15724. };
  15725. var deleteNormalized = function (elm, afterDeletePosOpt, normalizeWhitespace) {
  15726. var prevTextOpt = prevSibling(elm).filter(isText$1);
  15727. var nextTextOpt = nextSibling(elm).filter(isText$1);
  15728. remove$1(elm);
  15729. return lift3(prevTextOpt, nextTextOpt, afterDeletePosOpt, function (prev, next, pos) {
  15730. var prevNode = prev.dom(), nextNode = next.dom();
  15731. var offset = prevNode.data.length;
  15732. mergeTextNodes(prevNode, nextNode, normalizeWhitespace);
  15733. return pos.container() === nextNode ? CaretPosition$1(prevNode, offset) : pos;
  15734. }).orThunk(function () {
  15735. if (normalizeWhitespace) {
  15736. prevTextOpt.each(function (elm) {
  15737. return normalizeWhitespaceBefore(elm.dom(), elm.dom().length);
  15738. });
  15739. nextTextOpt.each(function (elm) {
  15740. return normalizeWhitespaceAfter(elm.dom(), 0);
  15741. });
  15742. }
  15743. return afterDeletePosOpt;
  15744. });
  15745. };
  15746. var isInlineElement = function (editor, element) {
  15747. return has(editor.schema.getTextInlineElements(), name(element));
  15748. };
  15749. var deleteElement = function (editor, forward, elm, moveCaret) {
  15750. if (moveCaret === void 0) {
  15751. moveCaret = true;
  15752. }
  15753. var afterDeletePos = findCaretPosOutsideElmAfterDelete(forward, editor.getBody(), elm.dom());
  15754. var parentBlock = ancestor(elm, curry(isBlock$2, editor), eqRawNode(editor.getBody()));
  15755. var normalizedAfterDeletePos = deleteNormalized(elm, afterDeletePos, isInlineElement(editor, elm));
  15756. if (editor.dom.isEmpty(editor.getBody())) {
  15757. editor.setContent('');
  15758. editor.selection.setCursorLocation();
  15759. } else {
  15760. parentBlock.bind(paddEmptyBlock).fold(function () {
  15761. if (moveCaret) {
  15762. setSelection(editor, forward, normalizedAfterDeletePos);
  15763. }
  15764. }, function (paddPos) {
  15765. if (moveCaret) {
  15766. setSelection(editor, forward, Option.some(paddPos));
  15767. }
  15768. });
  15769. }
  15770. };
  15771. var DeleteElement = { deleteElement: deleteElement };
  15772. var ZWSP$1 = Zwsp.ZWSP, CARET_ID$1 = '_mce_caret';
  15773. var importNode = function (ownerDocument, node) {
  15774. return ownerDocument.importNode(node, true);
  15775. };
  15776. var getEmptyCaretContainers = function (node) {
  15777. var nodes = [];
  15778. while (node) {
  15779. if (node.nodeType === 3 && node.nodeValue !== ZWSP$1 || node.childNodes.length > 1) {
  15780. return [];
  15781. }
  15782. if (node.nodeType === 1) {
  15783. nodes.push(node);
  15784. }
  15785. node = node.firstChild;
  15786. }
  15787. return nodes;
  15788. };
  15789. var isCaretContainerEmpty = function (node) {
  15790. return getEmptyCaretContainers(node).length > 0;
  15791. };
  15792. var findFirstTextNode = function (node) {
  15793. if (node) {
  15794. var walker = new TreeWalker(node, node);
  15795. for (node = walker.current(); node; node = walker.next()) {
  15796. if (node.nodeType === 3) {
  15797. return node;
  15798. }
  15799. }
  15800. }
  15801. return null;
  15802. };
  15803. var createCaretContainer = function (fill) {
  15804. var caretContainer = Element.fromTag('span');
  15805. setAll(caretContainer, {
  15806. 'id': CARET_ID$1,
  15807. 'data-mce-bogus': '1',
  15808. 'data-mce-type': 'format-caret'
  15809. });
  15810. if (fill) {
  15811. append(caretContainer, Element.fromText(ZWSP$1));
  15812. }
  15813. return caretContainer;
  15814. };
  15815. var trimZwspFromCaretContainer = function (caretContainerNode) {
  15816. var textNode = findFirstTextNode(caretContainerNode);
  15817. if (textNode && textNode.nodeValue.charAt(0) === ZWSP$1) {
  15818. textNode.deleteData(0, 1);
  15819. }
  15820. return textNode;
  15821. };
  15822. var removeCaretContainerNode = function (editor, node, moveCaret) {
  15823. if (moveCaret === void 0) {
  15824. moveCaret = true;
  15825. }
  15826. var dom = editor.dom, selection = editor.selection;
  15827. if (isCaretContainerEmpty(node)) {
  15828. DeleteElement.deleteElement(editor, false, Element.fromDom(node), moveCaret);
  15829. } else {
  15830. var rng = selection.getRng();
  15831. var block = dom.getParent(node, dom.isBlock);
  15832. var textNode = trimZwspFromCaretContainer(node);
  15833. if (rng.startContainer === textNode && rng.startOffset > 0) {
  15834. rng.setStart(textNode, rng.startOffset - 1);
  15835. }
  15836. if (rng.endContainer === textNode && rng.endOffset > 0) {
  15837. rng.setEnd(textNode, rng.endOffset - 1);
  15838. }
  15839. dom.remove(node, true);
  15840. if (block && dom.isEmpty(block)) {
  15841. PaddingBr.fillWithPaddingBr(Element.fromDom(block));
  15842. }
  15843. selection.setRng(rng);
  15844. }
  15845. };
  15846. var removeCaretContainer = function (editor, node, moveCaret) {
  15847. if (moveCaret === void 0) {
  15848. moveCaret = true;
  15849. }
  15850. var dom = editor.dom, selection = editor.selection;
  15851. if (!node) {
  15852. node = getParentCaretContainer(editor.getBody(), selection.getStart());
  15853. if (!node) {
  15854. while (node = dom.get(CARET_ID$1)) {
  15855. removeCaretContainerNode(editor, node, false);
  15856. }
  15857. }
  15858. } else {
  15859. removeCaretContainerNode(editor, node, moveCaret);
  15860. }
  15861. };
  15862. var insertCaretContainerNode = function (editor, caretContainer, formatNode) {
  15863. var dom = editor.dom, block = dom.getParent(formatNode, curry(FormatUtils.isTextBlock, editor));
  15864. if (block && dom.isEmpty(block)) {
  15865. formatNode.parentNode.replaceChild(caretContainer, formatNode);
  15866. } else {
  15867. PaddingBr.removeTrailingBr(Element.fromDom(formatNode));
  15868. if (dom.isEmpty(formatNode)) {
  15869. formatNode.parentNode.replaceChild(caretContainer, formatNode);
  15870. } else {
  15871. dom.insertAfter(caretContainer, formatNode);
  15872. }
  15873. }
  15874. };
  15875. var appendNode = function (parentNode, node) {
  15876. parentNode.appendChild(node);
  15877. return node;
  15878. };
  15879. var insertFormatNodesIntoCaretContainer = function (formatNodes, caretContainer) {
  15880. var innerMostFormatNode = foldr(formatNodes, function (parentNode, formatNode) {
  15881. return appendNode(parentNode, formatNode.cloneNode(false));
  15882. }, caretContainer);
  15883. return appendNode(innerMostFormatNode, innerMostFormatNode.ownerDocument.createTextNode(ZWSP$1));
  15884. };
  15885. var applyCaretFormat = function (editor, name, vars) {
  15886. var rng, caretContainer, textNode, offset, bookmark, container, text;
  15887. var selection = editor.selection;
  15888. rng = selection.getRng();
  15889. offset = rng.startOffset;
  15890. container = rng.startContainer;
  15891. text = container.nodeValue;
  15892. caretContainer = getParentCaretContainer(editor.getBody(), selection.getStart());
  15893. if (caretContainer) {
  15894. textNode = findFirstTextNode(caretContainer);
  15895. }
  15896. var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/;
  15897. if (text && offset > 0 && offset < text.length && wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) {
  15898. bookmark = selection.getBookmark();
  15899. rng.collapse(true);
  15900. rng = ExpandRange.expandRng(editor, rng, editor.formatter.get(name));
  15901. rng = split$1(rng);
  15902. editor.formatter.apply(name, vars, rng);
  15903. selection.moveToBookmark(bookmark);
  15904. } else {
  15905. if (!caretContainer || textNode.nodeValue !== ZWSP$1) {
  15906. caretContainer = importNode(editor.getDoc(), createCaretContainer(true).dom());
  15907. textNode = caretContainer.firstChild;
  15908. rng.insertNode(caretContainer);
  15909. offset = 1;
  15910. editor.formatter.apply(name, vars, caretContainer);
  15911. } else {
  15912. editor.formatter.apply(name, vars, caretContainer);
  15913. }
  15914. selection.setCursorLocation(textNode, offset);
  15915. }
  15916. };
  15917. var removeCaretFormat = function (editor, name, vars, similar) {
  15918. var dom = editor.dom, selection = editor.selection;
  15919. var container, offset, bookmark;
  15920. var hasContentAfter, node, formatNode;
  15921. var parents = [], rng = selection.getRng();
  15922. var caretContainer;
  15923. container = rng.startContainer;
  15924. offset = rng.startOffset;
  15925. node = container;
  15926. if (container.nodeType === 3) {
  15927. if (offset !== container.nodeValue.length) {
  15928. hasContentAfter = true;
  15929. }
  15930. node = node.parentNode;
  15931. }
  15932. while (node) {
  15933. if (MatchFormat.matchNode(editor, node, name, vars, similar)) {
  15934. formatNode = node;
  15935. break;
  15936. }
  15937. if (node.nextSibling) {
  15938. hasContentAfter = true;
  15939. }
  15940. parents.push(node);
  15941. node = node.parentNode;
  15942. }
  15943. if (!formatNode) {
  15944. return;
  15945. }
  15946. if (hasContentAfter) {
  15947. bookmark = selection.getBookmark();
  15948. rng.collapse(true);
  15949. var expandedRng = ExpandRange.expandRng(editor, rng, editor.formatter.get(name), true);
  15950. expandedRng = split$1(expandedRng);
  15951. editor.formatter.remove(name, vars, expandedRng);
  15952. selection.moveToBookmark(bookmark);
  15953. } else {
  15954. caretContainer = getParentCaretContainer(editor.getBody(), formatNode);
  15955. var newCaretContainer = createCaretContainer(false).dom();
  15956. var caretNode = insertFormatNodesIntoCaretContainer(parents, newCaretContainer);
  15957. if (caretContainer) {
  15958. insertCaretContainerNode(editor, newCaretContainer, caretContainer);
  15959. } else {
  15960. insertCaretContainerNode(editor, newCaretContainer, formatNode);
  15961. }
  15962. removeCaretContainerNode(editor, caretContainer, false);
  15963. selection.setCursorLocation(caretNode, 1);
  15964. if (dom.isEmpty(formatNode)) {
  15965. dom.remove(formatNode);
  15966. }
  15967. }
  15968. };
  15969. var disableCaretContainer = function (editor, keyCode) {
  15970. var selection = editor.selection, body = editor.getBody();
  15971. removeCaretContainer(editor, null, false);
  15972. if ((keyCode === 8 || keyCode === 46) && selection.isCollapsed() && selection.getStart().innerHTML === ZWSP$1) {
  15973. removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
  15974. }
  15975. if (keyCode === 37 || keyCode === 39) {
  15976. removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
  15977. }
  15978. };
  15979. var setup$5 = function (editor) {
  15980. editor.on('mouseup keydown', function (e) {
  15981. disableCaretContainer(editor, e.keyCode);
  15982. });
  15983. };
  15984. var replaceWithCaretFormat = function (targetNode, formatNodes) {
  15985. var caretContainer = createCaretContainer(false);
  15986. var innerMost = insertFormatNodesIntoCaretContainer(formatNodes, caretContainer.dom());
  15987. before(Element.fromDom(targetNode), caretContainer);
  15988. remove$1(Element.fromDom(targetNode));
  15989. return CaretPosition$1(innerMost, 0);
  15990. };
  15991. var isFormatElement = function (editor, element) {
  15992. var inlineElements = editor.schema.getTextInlineElements();
  15993. return inlineElements.hasOwnProperty(name(element)) && !isCaretNode(element.dom()) && !NodeType.isBogus(element.dom());
  15994. };
  15995. var isEmptyCaretFormatElement = function (element) {
  15996. return isCaretNode(element.dom()) && isCaretContainerEmpty(element.dom());
  15997. };
  15998. var postProcessHooks = {}, filter$3 = ArrUtils.filter, each$9 = ArrUtils.each;
  15999. var addPostProcessHook = function (name, hook) {
  16000. var hooks = postProcessHooks[name];
  16001. if (!hooks) {
  16002. postProcessHooks[name] = hooks = [];
  16003. }
  16004. postProcessHooks[name].push(hook);
  16005. };
  16006. var postProcess = function (name, editor) {
  16007. each$9(postProcessHooks[name], function (hook) {
  16008. hook(editor);
  16009. });
  16010. };
  16011. addPostProcessHook('pre', function (editor) {
  16012. var rng = editor.selection.getRng();
  16013. var isPre, blocks;
  16014. var hasPreSibling = function (pre) {
  16015. return isPre(pre.previousSibling) && ArrUtils.indexOf(blocks, pre.previousSibling) !== -1;
  16016. };
  16017. var joinPre = function (pre1, pre2) {
  16018. DomQuery(pre2).remove();
  16019. DomQuery(pre1).append('<br><br>').append(pre2.childNodes);
  16020. };
  16021. isPre = NodeType.matchNodeNames(['pre']);
  16022. if (!rng.collapsed) {
  16023. blocks = editor.selection.getSelectedBlocks();
  16024. each$9(filter$3(filter$3(blocks, isPre), hasPreSibling), function (pre) {
  16025. joinPre(pre.previousSibling, pre);
  16026. });
  16027. }
  16028. });
  16029. var Hooks = { postProcess: postProcess };
  16030. var each$a = Tools.each;
  16031. var ElementUtils = function (dom) {
  16032. this.compare = function (node1, node2) {
  16033. if (node1.nodeName !== node2.nodeName) {
  16034. return false;
  16035. }
  16036. var getAttribs = function (node) {
  16037. var attribs = {};
  16038. each$a(dom.getAttribs(node), function (attr) {
  16039. var name = attr.nodeName.toLowerCase();
  16040. if (name.indexOf('_') !== 0 && name !== 'style' && name.indexOf('data-') !== 0) {
  16041. attribs[name] = dom.getAttrib(node, name);
  16042. }
  16043. });
  16044. return attribs;
  16045. };
  16046. var compareObjects = function (obj1, obj2) {
  16047. var value, name;
  16048. for (name in obj1) {
  16049. if (obj1.hasOwnProperty(name)) {
  16050. value = obj2[name];
  16051. if (typeof value === 'undefined') {
  16052. return false;
  16053. }
  16054. if (obj1[name] !== value) {
  16055. return false;
  16056. }
  16057. delete obj2[name];
  16058. }
  16059. }
  16060. for (name in obj2) {
  16061. if (obj2.hasOwnProperty(name)) {
  16062. return false;
  16063. }
  16064. }
  16065. return true;
  16066. };
  16067. if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
  16068. return false;
  16069. }
  16070. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) {
  16071. return false;
  16072. }
  16073. return !Bookmarks.isBookmarkNode(node1) && !Bookmarks.isBookmarkNode(node2);
  16074. };
  16075. };
  16076. var MCE_ATTR_RE = /^(src|href|style)$/;
  16077. var each$b = Tools.each;
  16078. var isEq$4 = FormatUtils.isEq;
  16079. var isTableCell$2 = function (node) {
  16080. return /^(TH|TD)$/.test(node.nodeName);
  16081. };
  16082. var isChildOfInlineParent = function (dom, node, parent) {
  16083. return dom.isChildOf(node, parent) && node !== parent && !dom.isBlock(parent);
  16084. };
  16085. var getContainer = function (ed, rng, start) {
  16086. var container, offset, lastIdx;
  16087. container = rng[start ? 'startContainer' : 'endContainer'];
  16088. offset = rng[start ? 'startOffset' : 'endOffset'];
  16089. if (NodeType.isElement(container)) {
  16090. lastIdx = container.childNodes.length - 1;
  16091. if (!start && offset) {
  16092. offset--;
  16093. }
  16094. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  16095. }
  16096. if (NodeType.isText(container) && start && offset >= container.nodeValue.length) {
  16097. container = new TreeWalker(container, ed.getBody()).next() || container;
  16098. }
  16099. if (NodeType.isText(container) && !start && offset === 0) {
  16100. container = new TreeWalker(container, ed.getBody()).prev() || container;
  16101. }
  16102. return container;
  16103. };
  16104. var wrap$2 = function (dom, node, name, attrs) {
  16105. var wrapper = dom.create(name, attrs);
  16106. node.parentNode.insertBefore(wrapper, node);
  16107. wrapper.appendChild(node);
  16108. return wrapper;
  16109. };
  16110. var wrapWithSiblings = function (dom, node, next, name, attrs) {
  16111. var start = Element.fromDom(node);
  16112. var wrapper = Element.fromDom(dom.create(name, attrs));
  16113. var siblings = next ? nextSiblings(start) : prevSiblings(start);
  16114. append$1(wrapper, siblings);
  16115. if (next) {
  16116. before(start, wrapper);
  16117. prepend(wrapper, start);
  16118. } else {
  16119. after(start, wrapper);
  16120. append(wrapper, start);
  16121. }
  16122. return wrapper.dom();
  16123. };
  16124. var matchName$1 = function (dom, node, format) {
  16125. if (isEq$4(node, format.inline)) {
  16126. return true;
  16127. }
  16128. if (isEq$4(node, format.block)) {
  16129. return true;
  16130. }
  16131. if (format.selector) {
  16132. return NodeType.isElement(node) && dom.is(node, format.selector);
  16133. }
  16134. };
  16135. var isColorFormatAndAnchor = function (node, format) {
  16136. return format.links && node.tagName === 'A';
  16137. };
  16138. var find$3 = function (dom, node, next, inc) {
  16139. node = FormatUtils.getNonWhiteSpaceSibling(node, next, inc);
  16140. return !node || (node.nodeName === 'BR' || dom.isBlock(node));
  16141. };
  16142. var removeNode$1 = function (ed, node, format) {
  16143. var parentNode = node.parentNode;
  16144. var rootBlockElm;
  16145. var dom = ed.dom, forcedRootBlock = Settings.getForcedRootBlock(ed);
  16146. if (format.block) {
  16147. if (!forcedRootBlock) {
  16148. if (dom.isBlock(node) && !dom.isBlock(parentNode)) {
  16149. if (!find$3(dom, node, false) && !find$3(dom, node.firstChild, true, 1)) {
  16150. node.insertBefore(dom.create('br'), node.firstChild);
  16151. }
  16152. if (!find$3(dom, node, true) && !find$3(dom, node.lastChild, false, 1)) {
  16153. node.appendChild(dom.create('br'));
  16154. }
  16155. }
  16156. } else {
  16157. if (parentNode === dom.getRoot()) {
  16158. if (!format.list_block || !isEq$4(node, format.list_block)) {
  16159. each$b(Tools.grep(node.childNodes), function (node) {
  16160. if (FormatUtils.isValid(ed, forcedRootBlock, node.nodeName.toLowerCase())) {
  16161. if (!rootBlockElm) {
  16162. rootBlockElm = wrap$2(dom, node, forcedRootBlock);
  16163. dom.setAttribs(rootBlockElm, ed.settings.forced_root_block_attrs);
  16164. } else {
  16165. rootBlockElm.appendChild(node);
  16166. }
  16167. } else {
  16168. rootBlockElm = 0;
  16169. }
  16170. });
  16171. }
  16172. }
  16173. }
  16174. }
  16175. if (format.selector && format.inline && !isEq$4(format.inline, node)) {
  16176. return;
  16177. }
  16178. dom.remove(node, 1);
  16179. };
  16180. var removeFormat = function (ed, format, vars, node, compareNode) {
  16181. var i, attrs, stylesModified;
  16182. var dom = ed.dom;
  16183. if (!matchName$1(dom, node, format) && !isColorFormatAndAnchor(node, format)) {
  16184. return false;
  16185. }
  16186. if (format.remove !== 'all') {
  16187. each$b(format.styles, function (value, name) {
  16188. value = FormatUtils.normalizeStyleValue(dom, FormatUtils.replaceVars(value, vars), name);
  16189. if (typeof name === 'number') {
  16190. name = value;
  16191. compareNode = 0;
  16192. }
  16193. if (format.remove_similar || (!compareNode || isEq$4(FormatUtils.getStyle(dom, compareNode, name), value))) {
  16194. dom.setStyle(node, name, '');
  16195. }
  16196. stylesModified = 1;
  16197. });
  16198. if (stylesModified && dom.getAttrib(node, 'style') === '') {
  16199. node.removeAttribute('style');
  16200. node.removeAttribute('data-mce-style');
  16201. }
  16202. each$b(format.attributes, function (value, name) {
  16203. var valueOut;
  16204. value = FormatUtils.replaceVars(value, vars);
  16205. if (typeof name === 'number') {
  16206. name = value;
  16207. compareNode = 0;
  16208. }
  16209. if (format.remove_similar || (!compareNode || isEq$4(dom.getAttrib(compareNode, name), value))) {
  16210. if (name === 'class') {
  16211. value = dom.getAttrib(node, name);
  16212. if (value) {
  16213. valueOut = '';
  16214. each$b(value.split(/\s+/), function (cls) {
  16215. if (/mce\-\w+/.test(cls)) {
  16216. valueOut += (valueOut ? ' ' : '') + cls;
  16217. }
  16218. });
  16219. if (valueOut) {
  16220. dom.setAttrib(node, name, valueOut);
  16221. return;
  16222. }
  16223. }
  16224. }
  16225. if (name === 'class') {
  16226. node.removeAttribute('className');
  16227. }
  16228. if (MCE_ATTR_RE.test(name)) {
  16229. node.removeAttribute('data-mce-' + name);
  16230. }
  16231. node.removeAttribute(name);
  16232. }
  16233. });
  16234. each$b(format.classes, function (value) {
  16235. value = FormatUtils.replaceVars(value, vars);
  16236. if (!compareNode || dom.hasClass(compareNode, value)) {
  16237. dom.removeClass(node, value);
  16238. }
  16239. });
  16240. attrs = dom.getAttribs(node);
  16241. for (i = 0; i < attrs.length; i++) {
  16242. var attrName = attrs[i].nodeName;
  16243. if (attrName.indexOf('_') !== 0 && attrName.indexOf('data-') !== 0) {
  16244. return false;
  16245. }
  16246. }
  16247. }
  16248. if (format.remove !== 'none') {
  16249. removeNode$1(ed, node, format);
  16250. return true;
  16251. }
  16252. };
  16253. var findFormatRoot = function (editor, container, name, vars, similar) {
  16254. var formatRoot;
  16255. each$b(FormatUtils.getParents(editor.dom, container.parentNode).reverse(), function (parent) {
  16256. var format;
  16257. if (!formatRoot && parent.id !== '_start' && parent.id !== '_end') {
  16258. format = MatchFormat.matchNode(editor, parent, name, vars, similar);
  16259. if (format && format.split !== false) {
  16260. formatRoot = parent;
  16261. }
  16262. }
  16263. });
  16264. return formatRoot;
  16265. };
  16266. var wrapAndSplit = function (editor, formatList, formatRoot, container, target, split, format, vars) {
  16267. var parent, clone, lastClone, firstClone, i, formatRootParent;
  16268. var dom = editor.dom;
  16269. if (formatRoot) {
  16270. formatRootParent = formatRoot.parentNode;
  16271. for (parent = container.parentNode; parent && parent !== formatRootParent; parent = parent.parentNode) {
  16272. clone = dom.clone(parent, false);
  16273. for (i = 0; i < formatList.length; i++) {
  16274. if (removeFormat(editor, formatList[i], vars, clone, clone)) {
  16275. clone = 0;
  16276. break;
  16277. }
  16278. }
  16279. if (clone) {
  16280. if (lastClone) {
  16281. clone.appendChild(lastClone);
  16282. }
  16283. if (!firstClone) {
  16284. firstClone = clone;
  16285. }
  16286. lastClone = clone;
  16287. }
  16288. }
  16289. if (split && (!format.mixed || !dom.isBlock(formatRoot))) {
  16290. container = dom.split(formatRoot, container);
  16291. }
  16292. if (lastClone) {
  16293. target.parentNode.insertBefore(lastClone, target);
  16294. firstClone.appendChild(target);
  16295. }
  16296. }
  16297. return container;
  16298. };
  16299. var remove$7 = function (ed, name, vars, node, similar) {
  16300. var formatList = ed.formatter.get(name), format = formatList[0];
  16301. var bookmark, rng, contentEditable = true;
  16302. var dom = ed.dom;
  16303. var selection = ed.selection;
  16304. var splitToFormatRoot = function (container) {
  16305. var formatRoot = findFormatRoot(ed, container, name, vars, similar);
  16306. return wrapAndSplit(ed, formatList, formatRoot, container, container, true, format, vars);
  16307. };
  16308. var isRemoveBookmarkNode = function (node) {
  16309. return Bookmarks.isBookmarkNode(node) && NodeType.isElement(node) && (node.id === '_start' || node.id === '_end');
  16310. };
  16311. var process = function (node) {
  16312. var children, i, l, lastContentEditable, hasContentEditableState;
  16313. if (NodeType.isElement(node) && dom.getContentEditable(node)) {
  16314. lastContentEditable = contentEditable;
  16315. contentEditable = dom.getContentEditable(node) === 'true';
  16316. hasContentEditableState = true;
  16317. }
  16318. children = Tools.grep(node.childNodes);
  16319. if (contentEditable && !hasContentEditableState) {
  16320. for (i = 0, l = formatList.length; i < l; i++) {
  16321. if (removeFormat(ed, formatList[i], vars, node, node)) {
  16322. break;
  16323. }
  16324. }
  16325. }
  16326. if (format.deep) {
  16327. if (children.length) {
  16328. for (i = 0, l = children.length; i < l; i++) {
  16329. process(children[i]);
  16330. }
  16331. if (hasContentEditableState) {
  16332. contentEditable = lastContentEditable;
  16333. }
  16334. }
  16335. }
  16336. };
  16337. var unwrap = function (start) {
  16338. var node = dom.get(start ? '_start' : '_end');
  16339. var out = node[start ? 'firstChild' : 'lastChild'];
  16340. if (isRemoveBookmarkNode(out)) {
  16341. out = out[start ? 'firstChild' : 'lastChild'];
  16342. }
  16343. if (NodeType.isText(out) && out.data.length === 0) {
  16344. out = start ? node.previousSibling || node.nextSibling : node.nextSibling || node.previousSibling;
  16345. }
  16346. dom.remove(node, true);
  16347. return out;
  16348. };
  16349. var removeRngStyle = function (rng) {
  16350. var startContainer, endContainer;
  16351. var commonAncestorContainer = rng.commonAncestorContainer;
  16352. rng = ExpandRange.expandRng(ed, rng, formatList, true);
  16353. if (format.split) {
  16354. rng = split$1(rng);
  16355. startContainer = getContainer(ed, rng, true);
  16356. endContainer = getContainer(ed, rng);
  16357. if (startContainer !== endContainer) {
  16358. if (/^(TR|TH|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
  16359. if (startContainer.nodeName === 'TR') {
  16360. startContainer = startContainer.firstChild.firstChild || startContainer;
  16361. } else {
  16362. startContainer = startContainer.firstChild || startContainer;
  16363. }
  16364. }
  16365. if (commonAncestorContainer && /^T(HEAD|BODY|FOOT|R)$/.test(commonAncestorContainer.nodeName) && isTableCell$2(endContainer) && endContainer.firstChild) {
  16366. endContainer = endContainer.firstChild || endContainer;
  16367. }
  16368. if (isChildOfInlineParent(dom, startContainer, endContainer)) {
  16369. var marker = Option.from(startContainer.firstChild).getOr(startContainer);
  16370. splitToFormatRoot(wrapWithSiblings(dom, marker, true, 'span', {
  16371. 'id': '_start',
  16372. 'data-mce-type': 'bookmark'
  16373. }));
  16374. unwrap(true);
  16375. return;
  16376. }
  16377. if (isChildOfInlineParent(dom, endContainer, startContainer)) {
  16378. var marker = Option.from(endContainer.lastChild).getOr(endContainer);
  16379. splitToFormatRoot(wrapWithSiblings(dom, marker, false, 'span', {
  16380. 'id': '_end',
  16381. 'data-mce-type': 'bookmark'
  16382. }));
  16383. unwrap(false);
  16384. return;
  16385. }
  16386. startContainer = wrap$2(dom, startContainer, 'span', {
  16387. 'id': '_start',
  16388. 'data-mce-type': 'bookmark'
  16389. });
  16390. endContainer = wrap$2(dom, endContainer, 'span', {
  16391. 'id': '_end',
  16392. 'data-mce-type': 'bookmark'
  16393. });
  16394. splitToFormatRoot(startContainer);
  16395. splitToFormatRoot(endContainer);
  16396. startContainer = unwrap(true);
  16397. endContainer = unwrap();
  16398. } else {
  16399. startContainer = endContainer = splitToFormatRoot(startContainer);
  16400. }
  16401. rng.startContainer = startContainer.parentNode ? startContainer.parentNode : startContainer;
  16402. rng.startOffset = dom.nodeIndex(startContainer);
  16403. rng.endContainer = endContainer.parentNode ? endContainer.parentNode : endContainer;
  16404. rng.endOffset = dom.nodeIndex(endContainer) + 1;
  16405. }
  16406. RangeWalk.walk(dom, rng, function (nodes) {
  16407. each$b(nodes, function (node) {
  16408. process(node);
  16409. if (NodeType.isElement(node) && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && FormatUtils.getTextDecoration(dom, node.parentNode) === 'underline') {
  16410. removeFormat(ed, {
  16411. deep: false,
  16412. exact: true,
  16413. inline: 'span',
  16414. styles: { textDecoration: 'underline' }
  16415. }, null, node);
  16416. }
  16417. });
  16418. });
  16419. };
  16420. if (node) {
  16421. if (node.nodeType) {
  16422. rng = dom.createRng();
  16423. rng.setStartBefore(node);
  16424. rng.setEndAfter(node);
  16425. removeRngStyle(rng);
  16426. } else {
  16427. removeRngStyle(node);
  16428. }
  16429. return;
  16430. }
  16431. if (dom.getContentEditable(selection.getNode()) === 'false') {
  16432. node = selection.getNode();
  16433. for (var i = 0, l = formatList.length; i < l; i++) {
  16434. if (formatList[i].ceFalseOverride) {
  16435. if (removeFormat(ed, formatList[i], vars, node, node)) {
  16436. break;
  16437. }
  16438. }
  16439. }
  16440. return;
  16441. }
  16442. if (!selection.isCollapsed() || !format.inline || dom.select('td[data-mce-selected],th[data-mce-selected]').length) {
  16443. bookmark = GetBookmark.getPersistentBookmark(ed.selection, true);
  16444. removeRngStyle(selection.getRng());
  16445. selection.moveToBookmark(bookmark);
  16446. if (format.inline && MatchFormat.match(ed, name, vars, selection.getStart())) {
  16447. FormatUtils.moveStart(dom, selection, selection.getRng());
  16448. }
  16449. ed.nodeChanged();
  16450. } else {
  16451. removeCaretFormat(ed, name, vars, similar);
  16452. }
  16453. };
  16454. var RemoveFormat = {
  16455. removeFormat: removeFormat,
  16456. remove: remove$7
  16457. };
  16458. var each$c = Tools.each;
  16459. var isElementNode = function (node) {
  16460. return node && node.nodeType === 1 && !Bookmarks.isBookmarkNode(node) && !isCaretNode(node) && !NodeType.isBogus(node);
  16461. };
  16462. var findElementSibling = function (node, siblingName) {
  16463. var sibling;
  16464. for (sibling = node; sibling; sibling = sibling[siblingName]) {
  16465. if (sibling.nodeType === 3 && sibling.nodeValue.length !== 0) {
  16466. return node;
  16467. }
  16468. if (sibling.nodeType === 1 && !Bookmarks.isBookmarkNode(sibling)) {
  16469. return sibling;
  16470. }
  16471. }
  16472. return node;
  16473. };
  16474. var mergeSiblingsNodes = function (dom, prev, next) {
  16475. var sibling, tmpSibling;
  16476. var elementUtils = new ElementUtils(dom);
  16477. if (prev && next) {
  16478. prev = findElementSibling(prev, 'previousSibling');
  16479. next = findElementSibling(next, 'nextSibling');
  16480. if (elementUtils.compare(prev, next)) {
  16481. for (sibling = prev.nextSibling; sibling && sibling !== next;) {
  16482. tmpSibling = sibling;
  16483. sibling = sibling.nextSibling;
  16484. prev.appendChild(tmpSibling);
  16485. }
  16486. dom.remove(next);
  16487. Tools.each(Tools.grep(next.childNodes), function (node) {
  16488. prev.appendChild(node);
  16489. });
  16490. return prev;
  16491. }
  16492. }
  16493. return next;
  16494. };
  16495. var processChildElements = function (node, filter, process) {
  16496. each$c(node.childNodes, function (node) {
  16497. if (isElementNode(node)) {
  16498. if (filter(node)) {
  16499. process(node);
  16500. }
  16501. if (node.hasChildNodes()) {
  16502. processChildElements(node, filter, process);
  16503. }
  16504. }
  16505. });
  16506. };
  16507. var hasStyle = function (dom, name) {
  16508. return curry(function (name, node) {
  16509. return !!(node && FormatUtils.getStyle(dom, node, name));
  16510. }, name);
  16511. };
  16512. var applyStyle = function (dom, name, value) {
  16513. return curry(function (name, value, node) {
  16514. dom.setStyle(node, name, value);
  16515. if (node.getAttribute('style') === '') {
  16516. node.removeAttribute('style');
  16517. }
  16518. unwrapEmptySpan(dom, node);
  16519. }, name, value);
  16520. };
  16521. var unwrapEmptySpan = function (dom, node) {
  16522. if (node.nodeName === 'SPAN' && dom.getAttribs(node).length === 0) {
  16523. dom.remove(node, true);
  16524. }
  16525. };
  16526. var processUnderlineAndColor = function (dom, node) {
  16527. var textDecoration;
  16528. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  16529. textDecoration = FormatUtils.getTextDecoration(dom, node.parentNode);
  16530. if (dom.getStyle(node, 'color') && textDecoration) {
  16531. dom.setStyle(node, 'text-decoration', textDecoration);
  16532. } else if (dom.getStyle(node, 'text-decoration') === textDecoration) {
  16533. dom.setStyle(node, 'text-decoration', null);
  16534. }
  16535. }
  16536. };
  16537. var mergeUnderlineAndColor = function (dom, format, vars, node) {
  16538. if (format.styles.color || format.styles.textDecoration) {
  16539. Tools.walk(node, curry(processUnderlineAndColor, dom), 'childNodes');
  16540. processUnderlineAndColor(dom, node);
  16541. }
  16542. };
  16543. var mergeBackgroundColorAndFontSize = function (dom, format, vars, node) {
  16544. if (format.styles && format.styles.backgroundColor) {
  16545. processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'backgroundColor', FormatUtils.replaceVars(format.styles.backgroundColor, vars)));
  16546. }
  16547. };
  16548. var mergeSubSup = function (dom, format, vars, node) {
  16549. if (format.inline === 'sub' || format.inline === 'sup') {
  16550. processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'fontSize', ''));
  16551. dom.remove(dom.select(format.inline === 'sup' ? 'sub' : 'sup', node), true);
  16552. }
  16553. };
  16554. var mergeSiblings = function (dom, format, vars, node) {
  16555. if (node && format.merge_siblings !== false) {
  16556. node = mergeSiblingsNodes(dom, FormatUtils.getNonWhiteSpaceSibling(node), node);
  16557. node = mergeSiblingsNodes(dom, node, FormatUtils.getNonWhiteSpaceSibling(node, true));
  16558. }
  16559. };
  16560. var clearChildStyles = function (dom, format, node) {
  16561. if (format.clear_child_styles) {
  16562. var selector = format.links ? '*:not(a)' : '*';
  16563. each$c(dom.select(selector, node), function (node) {
  16564. if (isElementNode(node)) {
  16565. each$c(format.styles, function (value, name) {
  16566. dom.setStyle(node, name, '');
  16567. });
  16568. }
  16569. });
  16570. }
  16571. };
  16572. var mergeWithChildren = function (editor, formatList, vars, node) {
  16573. each$c(formatList, function (format) {
  16574. each$c(editor.dom.select(format.inline, node), function (child) {
  16575. if (!isElementNode(child)) {
  16576. return;
  16577. }
  16578. RemoveFormat.removeFormat(editor, format, vars, child, format.exact ? child : null);
  16579. });
  16580. clearChildStyles(editor.dom, format, node);
  16581. });
  16582. };
  16583. var mergeWithParents = function (editor, format, name, vars, node) {
  16584. if (MatchFormat.matchNode(editor, node.parentNode, name, vars)) {
  16585. if (RemoveFormat.removeFormat(editor, format, vars, node)) {
  16586. return;
  16587. }
  16588. }
  16589. if (format.merge_with_parents) {
  16590. editor.dom.getParent(node.parentNode, function (parent) {
  16591. if (MatchFormat.matchNode(editor, parent, name, vars)) {
  16592. RemoveFormat.removeFormat(editor, format, vars, node);
  16593. return true;
  16594. }
  16595. });
  16596. }
  16597. };
  16598. var MergeFormats = {
  16599. mergeWithChildren: mergeWithChildren,
  16600. mergeUnderlineAndColor: mergeUnderlineAndColor,
  16601. mergeBackgroundColorAndFontSize: mergeBackgroundColorAndFontSize,
  16602. mergeSubSup: mergeSubSup,
  16603. mergeSiblings: mergeSiblings,
  16604. mergeWithParents: mergeWithParents
  16605. };
  16606. var createRange$1 = function (sc, so, ec, eo) {
  16607. var rng = domGlobals.document.createRange();
  16608. rng.setStart(sc, so);
  16609. rng.setEnd(ec, eo);
  16610. return rng;
  16611. };
  16612. var normalizeBlockSelectionRange = function (rng) {
  16613. var startPos = CaretPosition$1.fromRangeStart(rng);
  16614. var endPos = CaretPosition$1.fromRangeEnd(rng);
  16615. var rootNode = rng.commonAncestorContainer;
  16616. return CaretFinder.fromPosition(false, rootNode, endPos).map(function (newEndPos) {
  16617. if (!isInSameBlock(startPos, endPos, rootNode) && isInSameBlock(startPos, newEndPos, rootNode)) {
  16618. return createRange$1(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset());
  16619. } else {
  16620. return rng;
  16621. }
  16622. }).getOr(rng);
  16623. };
  16624. var normalize$1 = function (rng) {
  16625. return rng.collapsed ? rng : normalizeBlockSelectionRange(rng);
  16626. };
  16627. var RangeNormalizer = { normalize: normalize$1 };
  16628. var each$d = Tools.each;
  16629. var isElementNode$1 = function (node) {
  16630. return node && node.nodeType === 1 && !Bookmarks.isBookmarkNode(node) && !isCaretNode(node) && !NodeType.isBogus(node);
  16631. };
  16632. var applyFormat = function (ed, name, vars, node) {
  16633. var formatList = ed.formatter.get(name);
  16634. var format = formatList[0];
  16635. var bookmark, rng;
  16636. var isCollapsed = !node && ed.selection.isCollapsed();
  16637. var dom = ed.dom, selection = ed.selection;
  16638. var setElementFormat = function (elm, fmt) {
  16639. fmt = fmt || format;
  16640. if (elm) {
  16641. if (fmt.onformat) {
  16642. fmt.onformat(elm, fmt, vars, node);
  16643. }
  16644. each$d(fmt.styles, function (value, name) {
  16645. dom.setStyle(elm, name, FormatUtils.replaceVars(value, vars));
  16646. });
  16647. if (fmt.styles) {
  16648. var styleVal = dom.getAttrib(elm, 'style');
  16649. if (styleVal) {
  16650. elm.setAttribute('data-mce-style', styleVal);
  16651. }
  16652. }
  16653. each$d(fmt.attributes, function (value, name) {
  16654. dom.setAttrib(elm, name, FormatUtils.replaceVars(value, vars));
  16655. });
  16656. each$d(fmt.classes, function (value) {
  16657. value = FormatUtils.replaceVars(value, vars);
  16658. if (!dom.hasClass(elm, value)) {
  16659. dom.addClass(elm, value);
  16660. }
  16661. });
  16662. }
  16663. };
  16664. var applyNodeStyle = function (formatList, node) {
  16665. var found = false;
  16666. if (!format.selector) {
  16667. return false;
  16668. }
  16669. each$d(formatList, function (format) {
  16670. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  16671. return;
  16672. }
  16673. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  16674. setElementFormat(node, format);
  16675. found = true;
  16676. return false;
  16677. }
  16678. });
  16679. return found;
  16680. };
  16681. var applyRngStyle = function (dom, rng, bookmark, nodeSpecific) {
  16682. var newWrappers = [];
  16683. var wrapName, wrapElm, contentEditable = true;
  16684. wrapName = format.inline || format.block;
  16685. wrapElm = dom.create(wrapName);
  16686. setElementFormat(wrapElm);
  16687. RangeWalk.walk(dom, rng, function (nodes) {
  16688. var currentWrapElm;
  16689. var process = function (node) {
  16690. var nodeName, parentName, hasContentEditableState, lastContentEditable;
  16691. lastContentEditable = contentEditable;
  16692. nodeName = node.nodeName.toLowerCase();
  16693. parentName = node.parentNode.nodeName.toLowerCase();
  16694. if (node.nodeType === 1 && dom.getContentEditable(node)) {
  16695. lastContentEditable = contentEditable;
  16696. contentEditable = dom.getContentEditable(node) === 'true';
  16697. hasContentEditableState = true;
  16698. }
  16699. if (FormatUtils.isEq(nodeName, 'br')) {
  16700. currentWrapElm = 0;
  16701. if (format.block) {
  16702. dom.remove(node);
  16703. }
  16704. return;
  16705. }
  16706. if (format.wrapper && MatchFormat.matchNode(ed, node, name, vars)) {
  16707. currentWrapElm = 0;
  16708. return;
  16709. }
  16710. if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && FormatUtils.isTextBlock(ed, nodeName) && FormatUtils.isValid(ed, parentName, wrapName)) {
  16711. node = dom.rename(node, wrapName);
  16712. setElementFormat(node);
  16713. newWrappers.push(node);
  16714. currentWrapElm = 0;
  16715. return;
  16716. }
  16717. if (format.selector) {
  16718. var found = applyNodeStyle(formatList, node);
  16719. if (!format.inline || found) {
  16720. currentWrapElm = 0;
  16721. return;
  16722. }
  16723. }
  16724. if (contentEditable && !hasContentEditableState && FormatUtils.isValid(ed, wrapName, nodeName) && FormatUtils.isValid(ed, parentName, wrapName) && !(!nodeSpecific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node) && (!format.inline || !dom.isBlock(node))) {
  16725. if (!currentWrapElm) {
  16726. currentWrapElm = dom.clone(wrapElm, false);
  16727. node.parentNode.insertBefore(currentWrapElm, node);
  16728. newWrappers.push(currentWrapElm);
  16729. }
  16730. currentWrapElm.appendChild(node);
  16731. } else {
  16732. currentWrapElm = 0;
  16733. each$d(Tools.grep(node.childNodes), process);
  16734. if (hasContentEditableState) {
  16735. contentEditable = lastContentEditable;
  16736. }
  16737. currentWrapElm = 0;
  16738. }
  16739. };
  16740. each$d(nodes, process);
  16741. });
  16742. if (format.links === true) {
  16743. each$d(newWrappers, function (node) {
  16744. var process = function (node) {
  16745. if (node.nodeName === 'A') {
  16746. setElementFormat(node, format);
  16747. }
  16748. each$d(Tools.grep(node.childNodes), process);
  16749. };
  16750. process(node);
  16751. });
  16752. }
  16753. each$d(newWrappers, function (node) {
  16754. var childCount;
  16755. var getChildCount = function (node) {
  16756. var count = 0;
  16757. each$d(node.childNodes, function (node) {
  16758. if (!FormatUtils.isWhiteSpaceNode(node) && !Bookmarks.isBookmarkNode(node)) {
  16759. count++;
  16760. }
  16761. });
  16762. return count;
  16763. };
  16764. var getChildElementNode = function (root) {
  16765. var child = false;
  16766. each$d(root.childNodes, function (node) {
  16767. if (isElementNode$1(node)) {
  16768. child = node;
  16769. return false;
  16770. }
  16771. });
  16772. return child;
  16773. };
  16774. var mergeStyles = function (node) {
  16775. var child, clone;
  16776. child = getChildElementNode(node);
  16777. if (child && !Bookmarks.isBookmarkNode(child) && MatchFormat.matchName(dom, child, format)) {
  16778. clone = dom.clone(child, false);
  16779. setElementFormat(clone);
  16780. dom.replace(clone, node, true);
  16781. dom.remove(child, 1);
  16782. }
  16783. return clone || node;
  16784. };
  16785. childCount = getChildCount(node);
  16786. if ((newWrappers.length > 1 || !dom.isBlock(node)) && childCount === 0) {
  16787. dom.remove(node, 1);
  16788. return;
  16789. }
  16790. if (format.inline || format.wrapper) {
  16791. if (!format.exact && childCount === 1) {
  16792. node = mergeStyles(node);
  16793. }
  16794. MergeFormats.mergeWithChildren(ed, formatList, vars, node);
  16795. MergeFormats.mergeWithParents(ed, format, name, vars, node);
  16796. MergeFormats.mergeBackgroundColorAndFontSize(dom, format, vars, node);
  16797. MergeFormats.mergeSubSup(dom, format, vars, node);
  16798. MergeFormats.mergeSiblings(dom, format, vars, node);
  16799. }
  16800. });
  16801. };
  16802. if (dom.getContentEditable(selection.getNode()) === 'false') {
  16803. node = selection.getNode();
  16804. for (var i = 0, l = formatList.length; i < l; i++) {
  16805. if (formatList[i].ceFalseOverride && dom.is(node, formatList[i].selector)) {
  16806. setElementFormat(node, formatList[i]);
  16807. return;
  16808. }
  16809. }
  16810. return;
  16811. }
  16812. if (format) {
  16813. if (node) {
  16814. if (node.nodeType) {
  16815. if (!applyNodeStyle(formatList, node)) {
  16816. rng = dom.createRng();
  16817. rng.setStartBefore(node);
  16818. rng.setEndAfter(node);
  16819. applyRngStyle(dom, ExpandRange.expandRng(ed, rng, formatList), null, true);
  16820. }
  16821. } else {
  16822. applyRngStyle(dom, node, null, true);
  16823. }
  16824. } else {
  16825. if (!isCollapsed || !format.inline || dom.select('td[data-mce-selected],th[data-mce-selected]').length) {
  16826. var curSelNode = ed.selection.getNode();
  16827. if (!ed.settings.forced_root_block && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
  16828. applyFormat(ed, formatList[0].defaultBlock);
  16829. }
  16830. ed.selection.setRng(RangeNormalizer.normalize(ed.selection.getRng()));
  16831. bookmark = GetBookmark.getPersistentBookmark(ed.selection, true);
  16832. applyRngStyle(dom, ExpandRange.expandRng(ed, selection.getRng(), formatList));
  16833. if (format.styles) {
  16834. MergeFormats.mergeUnderlineAndColor(dom, format, vars, curSelNode);
  16835. }
  16836. selection.moveToBookmark(bookmark);
  16837. FormatUtils.moveStart(dom, selection, selection.getRng());
  16838. ed.nodeChanged();
  16839. } else {
  16840. applyCaretFormat(ed, name, vars);
  16841. }
  16842. }
  16843. Hooks.postProcess(name, ed);
  16844. }
  16845. };
  16846. var ApplyFormat = { applyFormat: applyFormat };
  16847. var setup$6 = function (registeredFormatListeners, editor) {
  16848. var currentFormats = Cell({});
  16849. registeredFormatListeners.set({});
  16850. editor.on('NodeChange', function (e) {
  16851. updateAndFireChangeCallbacks(editor, e.element, currentFormats, registeredFormatListeners.get());
  16852. });
  16853. };
  16854. var updateAndFireChangeCallbacks = function (editor, elm, currentFormats, formatChangeData) {
  16855. var formatsList = keys(currentFormats.get());
  16856. var newFormats = {};
  16857. var matchedFormats = {};
  16858. var parents = filter(FormatUtils.getParents(editor.dom, elm), function (node) {
  16859. return node.nodeType === 1 && !node.getAttribute('data-mce-bogus');
  16860. });
  16861. each$1(formatChangeData, function (data, format) {
  16862. Tools.each(parents, function (node) {
  16863. if (editor.formatter.matchNode(node, format, {}, data.similar)) {
  16864. if (formatsList.indexOf(format) === -1) {
  16865. each(data.callbacks, function (callback) {
  16866. callback(true, {
  16867. node: node,
  16868. format: format,
  16869. parents: parents
  16870. });
  16871. });
  16872. newFormats[format] = data.callbacks;
  16873. }
  16874. matchedFormats[format] = data.callbacks;
  16875. return false;
  16876. }
  16877. if (MatchFormat.matchesUnInheritedFormatSelector(editor, node, format)) {
  16878. return false;
  16879. }
  16880. });
  16881. });
  16882. var remainingFormats = filterRemainingFormats(currentFormats.get(), matchedFormats, elm, parents);
  16883. currentFormats.set(__assign(__assign({}, newFormats), remainingFormats));
  16884. };
  16885. var filterRemainingFormats = function (currentFormats, matchedFormats, elm, parents) {
  16886. return bifilter(currentFormats, function (callbacks, format) {
  16887. if (!has(matchedFormats, format)) {
  16888. each(callbacks, function (callback) {
  16889. callback(false, {
  16890. node: elm,
  16891. format: format,
  16892. parents: parents
  16893. });
  16894. });
  16895. return false;
  16896. } else {
  16897. return true;
  16898. }
  16899. }).t;
  16900. };
  16901. var addListeners = function (registeredFormatListeners, formats, callback, similar) {
  16902. var formatChangeItems = registeredFormatListeners.get();
  16903. each(formats.split(','), function (format) {
  16904. if (!formatChangeItems[format]) {
  16905. formatChangeItems[format] = {
  16906. similar: similar,
  16907. callbacks: []
  16908. };
  16909. }
  16910. formatChangeItems[format].callbacks.push(callback);
  16911. });
  16912. registeredFormatListeners.set(formatChangeItems);
  16913. };
  16914. var removeListeners = function (registeredFormatListeners, formats, callback) {
  16915. var formatChangeItems = registeredFormatListeners.get();
  16916. each(formats.split(','), function (format) {
  16917. formatChangeItems[format].callbacks = filter(formatChangeItems[format].callbacks, function (c) {
  16918. return c !== callback;
  16919. });
  16920. if (formatChangeItems[format].callbacks.length === 0) {
  16921. delete formatChangeItems[format];
  16922. }
  16923. });
  16924. registeredFormatListeners.set(formatChangeItems);
  16925. };
  16926. var formatChanged = function (editor, registeredFormatListeners, formats, callback, similar) {
  16927. if (registeredFormatListeners.get() === null) {
  16928. setup$6(registeredFormatListeners, editor);
  16929. }
  16930. addListeners(registeredFormatListeners, formats, callback, similar);
  16931. return {
  16932. unbind: function () {
  16933. return removeListeners(registeredFormatListeners, formats, callback);
  16934. }
  16935. };
  16936. };
  16937. var get$7 = function (dom) {
  16938. var formats = {
  16939. valigntop: [{
  16940. selector: 'td,th',
  16941. styles: { verticalAlign: 'top' }
  16942. }],
  16943. valignmiddle: [{
  16944. selector: 'td,th',
  16945. styles: { verticalAlign: 'middle' }
  16946. }],
  16947. valignbottom: [{
  16948. selector: 'td,th',
  16949. styles: { verticalAlign: 'bottom' }
  16950. }],
  16951. alignleft: [
  16952. {
  16953. selector: 'figure.image',
  16954. collapsed: false,
  16955. classes: 'align-left',
  16956. ceFalseOverride: true,
  16957. preview: 'font-family font-size'
  16958. },
  16959. {
  16960. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  16961. styles: { textAlign: 'left' },
  16962. inherit: false,
  16963. preview: false,
  16964. defaultBlock: 'div'
  16965. },
  16966. {
  16967. selector: 'img,table',
  16968. collapsed: false,
  16969. styles: { float: 'left' },
  16970. preview: 'font-family font-size'
  16971. }
  16972. ],
  16973. aligncenter: [
  16974. {
  16975. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  16976. styles: { textAlign: 'center' },
  16977. inherit: false,
  16978. preview: 'font-family font-size',
  16979. defaultBlock: 'div'
  16980. },
  16981. {
  16982. selector: 'figure.image',
  16983. collapsed: false,
  16984. classes: 'align-center',
  16985. ceFalseOverride: true,
  16986. preview: 'font-family font-size'
  16987. },
  16988. {
  16989. selector: 'img',
  16990. collapsed: false,
  16991. styles: {
  16992. display: 'block',
  16993. marginLeft: 'auto',
  16994. marginRight: 'auto'
  16995. },
  16996. preview: false
  16997. },
  16998. {
  16999. selector: 'table',
  17000. collapsed: false,
  17001. styles: {
  17002. marginLeft: 'auto',
  17003. marginRight: 'auto'
  17004. },
  17005. preview: 'font-family font-size'
  17006. }
  17007. ],
  17008. alignright: [
  17009. {
  17010. selector: 'figure.image',
  17011. collapsed: false,
  17012. classes: 'align-right',
  17013. ceFalseOverride: true,
  17014. preview: 'font-family font-size'
  17015. },
  17016. {
  17017. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  17018. styles: { textAlign: 'right' },
  17019. inherit: false,
  17020. preview: 'font-family font-size',
  17021. defaultBlock: 'div'
  17022. },
  17023. {
  17024. selector: 'img,table',
  17025. collapsed: false,
  17026. styles: { float: 'right' },
  17027. preview: 'font-family font-size'
  17028. }
  17029. ],
  17030. alignjustify: [{
  17031. selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li',
  17032. styles: { textAlign: 'justify' },
  17033. inherit: false,
  17034. defaultBlock: 'div',
  17035. preview: 'font-family font-size'
  17036. }],
  17037. bold: [
  17038. {
  17039. inline: 'strong',
  17040. remove: 'all'
  17041. },
  17042. {
  17043. inline: 'span',
  17044. styles: { fontWeight: 'bold' }
  17045. },
  17046. {
  17047. inline: 'b',
  17048. remove: 'all'
  17049. }
  17050. ],
  17051. italic: [
  17052. {
  17053. inline: 'em',
  17054. remove: 'all'
  17055. },
  17056. {
  17057. inline: 'span',
  17058. styles: { fontStyle: 'italic' }
  17059. },
  17060. {
  17061. inline: 'i',
  17062. remove: 'all'
  17063. }
  17064. ],
  17065. underline: [
  17066. {
  17067. inline: 'span',
  17068. styles: { textDecoration: 'underline' },
  17069. exact: true
  17070. },
  17071. {
  17072. inline: 'u',
  17073. remove: 'all'
  17074. }
  17075. ],
  17076. strikethrough: [
  17077. {
  17078. inline: 'span',
  17079. styles: { textDecoration: 'line-through' },
  17080. exact: true
  17081. },
  17082. {
  17083. inline: 'strike',
  17084. remove: 'all'
  17085. }
  17086. ],
  17087. forecolor: {
  17088. inline: 'span',
  17089. styles: { color: '%value' },
  17090. links: true,
  17091. remove_similar: true,
  17092. clear_child_styles: true
  17093. },
  17094. hilitecolor: {
  17095. inline: 'span',
  17096. styles: { backgroundColor: '%value' },
  17097. links: true,
  17098. remove_similar: true,
  17099. clear_child_styles: true
  17100. },
  17101. fontname: {
  17102. inline: 'span',
  17103. toggle: false,
  17104. styles: { fontFamily: '%value' },
  17105. clear_child_styles: true
  17106. },
  17107. fontsize: {
  17108. inline: 'span',
  17109. toggle: false,
  17110. styles: { fontSize: '%value' },
  17111. clear_child_styles: true
  17112. },
  17113. fontsize_class: {
  17114. inline: 'span',
  17115. attributes: { class: '%value' }
  17116. },
  17117. blockquote: {
  17118. block: 'blockquote',
  17119. wrapper: true,
  17120. remove: 'all'
  17121. },
  17122. subscript: { inline: 'sub' },
  17123. superscript: { inline: 'sup' },
  17124. code: { inline: 'code' },
  17125. link: {
  17126. inline: 'a',
  17127. selector: 'a',
  17128. remove: 'all',
  17129. split: true,
  17130. deep: true,
  17131. onmatch: function () {
  17132. return true;
  17133. },
  17134. onformat: function (elm, fmt, vars) {
  17135. Tools.each(vars, function (value, key) {
  17136. dom.setAttrib(elm, key, value);
  17137. });
  17138. }
  17139. },
  17140. removeformat: [
  17141. {
  17142. selector: 'b,strong,em,i,font,u,strike,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins',
  17143. remove: 'all',
  17144. split: true,
  17145. expand: false,
  17146. block_expand: true,
  17147. deep: true
  17148. },
  17149. {
  17150. selector: 'span',
  17151. attributes: [
  17152. 'style',
  17153. 'class'
  17154. ],
  17155. remove: 'empty',
  17156. split: true,
  17157. expand: false,
  17158. deep: true
  17159. },
  17160. {
  17161. selector: '*',
  17162. attributes: [
  17163. 'style',
  17164. 'class'
  17165. ],
  17166. split: false,
  17167. expand: false,
  17168. deep: true
  17169. }
  17170. ]
  17171. };
  17172. Tools.each('p h1 h2 h3 h4 h5 h6 div address pre div dt dd samp'.split(/\s/), function (name) {
  17173. formats[name] = {
  17174. block: name,
  17175. remove: 'all'
  17176. };
  17177. });
  17178. return formats;
  17179. };
  17180. var DefaultFormats = { get: get$7 };
  17181. function FormatRegistry(editor) {
  17182. var formats = {};
  17183. var get = function (name) {
  17184. return name ? formats[name] : formats;
  17185. };
  17186. var has$1 = function (name) {
  17187. return has(formats, name);
  17188. };
  17189. var register = function (name, format) {
  17190. if (name) {
  17191. if (typeof name !== 'string') {
  17192. Tools.each(name, function (format, name) {
  17193. register(name, format);
  17194. });
  17195. } else {
  17196. if (!isArray(format)) {
  17197. format = [format];
  17198. }
  17199. Tools.each(format, function (format) {
  17200. if (typeof format.deep === 'undefined') {
  17201. format.deep = !format.selector;
  17202. }
  17203. if (typeof format.split === 'undefined') {
  17204. format.split = !format.selector || format.inline;
  17205. }
  17206. if (typeof format.remove === 'undefined' && format.selector && !format.inline) {
  17207. format.remove = 'none';
  17208. }
  17209. if (format.selector && format.inline) {
  17210. format.mixed = true;
  17211. format.block_expand = true;
  17212. }
  17213. if (typeof format.classes === 'string') {
  17214. format.classes = format.classes.split(/\s+/);
  17215. }
  17216. });
  17217. formats[name] = format;
  17218. }
  17219. }
  17220. };
  17221. var unregister = function (name) {
  17222. if (name && formats[name]) {
  17223. delete formats[name];
  17224. }
  17225. return formats;
  17226. };
  17227. register(DefaultFormats.get(editor.dom));
  17228. register(editor.settings.formats);
  17229. return {
  17230. get: get,
  17231. has: has$1,
  17232. register: register,
  17233. unregister: unregister
  17234. };
  17235. }
  17236. var each$e = Tools.each;
  17237. var dom = DOMUtils$1.DOM;
  17238. var parsedSelectorToHtml = function (ancestry, editor) {
  17239. var elm, item, fragment;
  17240. var schema = editor && editor.schema || Schema({});
  17241. var decorate = function (elm, item) {
  17242. if (item.classes.length) {
  17243. dom.addClass(elm, item.classes.join(' '));
  17244. }
  17245. dom.setAttribs(elm, item.attrs);
  17246. };
  17247. var createElement = function (sItem) {
  17248. var elm;
  17249. item = typeof sItem === 'string' ? {
  17250. name: sItem,
  17251. classes: [],
  17252. attrs: {}
  17253. } : sItem;
  17254. elm = dom.create(item.name);
  17255. decorate(elm, item);
  17256. return elm;
  17257. };
  17258. var getRequiredParent = function (elm, candidate) {
  17259. var name = typeof elm !== 'string' ? elm.nodeName.toLowerCase() : elm;
  17260. var elmRule = schema.getElementRule(name);
  17261. var parentsRequired = elmRule && elmRule.parentsRequired;
  17262. if (parentsRequired && parentsRequired.length) {
  17263. return candidate && Tools.inArray(parentsRequired, candidate) !== -1 ? candidate : parentsRequired[0];
  17264. } else {
  17265. return false;
  17266. }
  17267. };
  17268. var wrapInHtml = function (elm, ancestry, siblings) {
  17269. var parent, parentCandidate, parentRequired;
  17270. var ancestor = ancestry.length > 0 && ancestry[0];
  17271. var ancestorName = ancestor && ancestor.name;
  17272. parentRequired = getRequiredParent(elm, ancestorName);
  17273. if (parentRequired) {
  17274. if (ancestorName === parentRequired) {
  17275. parentCandidate = ancestry[0];
  17276. ancestry = ancestry.slice(1);
  17277. } else {
  17278. parentCandidate = parentRequired;
  17279. }
  17280. } else if (ancestor) {
  17281. parentCandidate = ancestry[0];
  17282. ancestry = ancestry.slice(1);
  17283. } else if (!siblings) {
  17284. return elm;
  17285. }
  17286. if (parentCandidate) {
  17287. parent = createElement(parentCandidate);
  17288. parent.appendChild(elm);
  17289. }
  17290. if (siblings) {
  17291. if (!parent) {
  17292. parent = dom.create('div');
  17293. parent.appendChild(elm);
  17294. }
  17295. Tools.each(siblings, function (sibling) {
  17296. var siblingElm = createElement(sibling);
  17297. parent.insertBefore(siblingElm, elm);
  17298. });
  17299. }
  17300. return wrapInHtml(parent, ancestry, parentCandidate && parentCandidate.siblings);
  17301. };
  17302. if (ancestry && ancestry.length) {
  17303. item = ancestry[0];
  17304. elm = createElement(item);
  17305. fragment = dom.create('div');
  17306. fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings));
  17307. return fragment;
  17308. } else {
  17309. return '';
  17310. }
  17311. };
  17312. var selectorToHtml = function (selector, editor) {
  17313. return parsedSelectorToHtml(parseSelector(selector), editor);
  17314. };
  17315. var parseSelectorItem = function (item) {
  17316. var tagName;
  17317. var obj = {
  17318. classes: [],
  17319. attrs: {}
  17320. };
  17321. item = obj.selector = Tools.trim(item);
  17322. if (item !== '*') {
  17323. tagName = item.replace(/(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g, function ($0, $1, $2, $3, $4) {
  17324. switch ($1) {
  17325. case '#':
  17326. obj.attrs.id = $2;
  17327. break;
  17328. case '.':
  17329. obj.classes.push($2);
  17330. break;
  17331. case ':':
  17332. if (Tools.inArray('checked disabled enabled read-only required'.split(' '), $2) !== -1) {
  17333. obj.attrs[$2] = $2;
  17334. }
  17335. break;
  17336. }
  17337. if ($3 === '[') {
  17338. var m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/);
  17339. if (m) {
  17340. obj.attrs[m[1]] = m[2];
  17341. }
  17342. }
  17343. return '';
  17344. });
  17345. }
  17346. obj.name = tagName || 'div';
  17347. return obj;
  17348. };
  17349. var parseSelector = function (selector) {
  17350. if (!selector || typeof selector !== 'string') {
  17351. return [];
  17352. }
  17353. selector = selector.split(/\s*,\s*/)[0];
  17354. selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, '$1');
  17355. return Tools.map(selector.split(/(?:>|\s+(?![^\[\]]+\]))/), function (item) {
  17356. var siblings = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem);
  17357. var obj = siblings.pop();
  17358. if (siblings.length) {
  17359. obj.siblings = siblings;
  17360. }
  17361. return obj;
  17362. }).reverse();
  17363. };
  17364. var getCssText = function (editor, format) {
  17365. var name, previewFrag, previewElm, items;
  17366. var previewCss = '', parentFontSize, previewStyles;
  17367. previewStyles = editor.settings.preview_styles;
  17368. if (previewStyles === false) {
  17369. return '';
  17370. }
  17371. if (typeof previewStyles !== 'string') {
  17372. previewStyles = 'font-family font-size font-weight font-style text-decoration ' + 'text-transform color background-color border border-radius outline text-shadow';
  17373. }
  17374. var removeVars = function (val) {
  17375. return val.replace(/%(\w+)/g, '');
  17376. };
  17377. if (typeof format === 'string') {
  17378. format = editor.formatter.get(format);
  17379. if (!format) {
  17380. return;
  17381. }
  17382. format = format[0];
  17383. }
  17384. if ('preview' in format) {
  17385. previewStyles = format.preview;
  17386. if (previewStyles === false) {
  17387. return '';
  17388. }
  17389. }
  17390. name = format.block || format.inline || 'span';
  17391. items = parseSelector(format.selector);
  17392. if (items.length) {
  17393. if (!items[0].name) {
  17394. items[0].name = name;
  17395. }
  17396. name = format.selector;
  17397. previewFrag = parsedSelectorToHtml(items, editor);
  17398. } else {
  17399. previewFrag = parsedSelectorToHtml([name], editor);
  17400. }
  17401. previewElm = dom.select(name, previewFrag)[0] || previewFrag.firstChild;
  17402. each$e(format.styles, function (value, name) {
  17403. value = removeVars(value);
  17404. if (value) {
  17405. dom.setStyle(previewElm, name, value);
  17406. }
  17407. });
  17408. each$e(format.attributes, function (value, name) {
  17409. value = removeVars(value);
  17410. if (value) {
  17411. dom.setAttrib(previewElm, name, value);
  17412. }
  17413. });
  17414. each$e(format.classes, function (value) {
  17415. value = removeVars(value);
  17416. if (!dom.hasClass(previewElm, value)) {
  17417. dom.addClass(previewElm, value);
  17418. }
  17419. });
  17420. editor.fire('PreviewFormats');
  17421. dom.setStyles(previewFrag, {
  17422. position: 'absolute',
  17423. left: -65535
  17424. });
  17425. editor.getBody().appendChild(previewFrag);
  17426. parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true);
  17427. parentFontSize = /px$/.test(parentFontSize) ? parseInt(parentFontSize, 10) : 0;
  17428. each$e(previewStyles.split(' '), function (name) {
  17429. var value = dom.getStyle(previewElm, name, true);
  17430. if (name === 'background-color' && /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)) {
  17431. value = dom.getStyle(editor.getBody(), name, true);
  17432. if (dom.toHex(value).toLowerCase() === '#ffffff') {
  17433. return;
  17434. }
  17435. }
  17436. if (name === 'color') {
  17437. if (dom.toHex(value).toLowerCase() === '#000000') {
  17438. return;
  17439. }
  17440. }
  17441. if (name === 'font-size') {
  17442. if (/em|%$/.test(value)) {
  17443. if (parentFontSize === 0) {
  17444. return;
  17445. }
  17446. var numValue = parseFloat(value) / (/%$/.test(value) ? 100 : 1);
  17447. value = numValue * parentFontSize + 'px';
  17448. }
  17449. }
  17450. if (name === 'border' && value) {
  17451. previewCss += 'padding:0 2px;';
  17452. }
  17453. previewCss += name + ':' + value + ';';
  17454. });
  17455. editor.fire('AfterPreviewFormats');
  17456. dom.remove(previewFrag);
  17457. return previewCss;
  17458. };
  17459. var Preview = {
  17460. getCssText: getCssText,
  17461. parseSelector: parseSelector,
  17462. selectorToHtml: selectorToHtml
  17463. };
  17464. var toggle = function (editor, formats, name, vars, node) {
  17465. var fmt = formats.get(name);
  17466. if (MatchFormat.match(editor, name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle)) {
  17467. RemoveFormat.remove(editor, name, vars, node);
  17468. } else {
  17469. ApplyFormat.applyFormat(editor, name, vars, node);
  17470. }
  17471. };
  17472. var ToggleFormat = { toggle: toggle };
  17473. var setup$7 = function (editor) {
  17474. editor.addShortcut('meta+b', '', 'Bold');
  17475. editor.addShortcut('meta+i', '', 'Italic');
  17476. editor.addShortcut('meta+u', '', 'Underline');
  17477. for (var i = 1; i <= 6; i++) {
  17478. editor.addShortcut('access+' + i, '', [
  17479. 'FormatBlock',
  17480. false,
  17481. 'h' + i
  17482. ]);
  17483. }
  17484. editor.addShortcut('access+7', '', [
  17485. 'FormatBlock',
  17486. false,
  17487. 'p'
  17488. ]);
  17489. editor.addShortcut('access+8', '', [
  17490. 'FormatBlock',
  17491. false,
  17492. 'div'
  17493. ]);
  17494. editor.addShortcut('access+9', '', [
  17495. 'FormatBlock',
  17496. false,
  17497. 'address'
  17498. ]);
  17499. };
  17500. var FormatShortcuts = { setup: setup$7 };
  17501. var Formatter = function (editor) {
  17502. var formats = FormatRegistry(editor);
  17503. var formatChangeState = Cell(null);
  17504. FormatShortcuts.setup(editor);
  17505. setup$5(editor);
  17506. return {
  17507. get: formats.get,
  17508. has: formats.has,
  17509. register: formats.register,
  17510. unregister: formats.unregister,
  17511. apply: curry(ApplyFormat.applyFormat, editor),
  17512. remove: curry(RemoveFormat.remove, editor),
  17513. toggle: curry(ToggleFormat.toggle, editor, formats),
  17514. match: curry(MatchFormat.match, editor),
  17515. matchAll: curry(MatchFormat.matchAll, editor),
  17516. matchNode: curry(MatchFormat.matchNode, editor),
  17517. canApply: curry(MatchFormat.canApply, editor),
  17518. formatChanged: curry(formatChanged, editor, formatChangeState),
  17519. getCssText: curry(Preview.getCssText, editor)
  17520. };
  17521. };
  17522. var register$1 = function (htmlParser, settings, dom) {
  17523. htmlParser.addAttributeFilter('data-mce-tabindex', function (nodes, name) {
  17524. var i = nodes.length, node;
  17525. while (i--) {
  17526. node = nodes[i];
  17527. node.attr('tabindex', node.attr('data-mce-tabindex'));
  17528. node.attr(name, null);
  17529. }
  17530. });
  17531. htmlParser.addAttributeFilter('src,href,style', function (nodes, name) {
  17532. var i = nodes.length, node, value;
  17533. var internalName = 'data-mce-' + name;
  17534. var urlConverter = settings.url_converter;
  17535. var urlConverterScope = settings.url_converter_scope;
  17536. while (i--) {
  17537. node = nodes[i];
  17538. value = node.attr(internalName);
  17539. if (value !== undefined) {
  17540. node.attr(name, value.length > 0 ? value : null);
  17541. node.attr(internalName, null);
  17542. } else {
  17543. value = node.attr(name);
  17544. if (name === 'style') {
  17545. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  17546. } else if (urlConverter) {
  17547. value = urlConverter.call(urlConverterScope, value, name, node.name);
  17548. }
  17549. node.attr(name, value.length > 0 ? value : null);
  17550. }
  17551. }
  17552. });
  17553. htmlParser.addAttributeFilter('class', function (nodes) {
  17554. var i = nodes.length, node, value;
  17555. while (i--) {
  17556. node = nodes[i];
  17557. value = node.attr('class');
  17558. if (value) {
  17559. value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, '');
  17560. node.attr('class', value.length > 0 ? value : null);
  17561. }
  17562. }
  17563. });
  17564. htmlParser.addAttributeFilter('data-mce-type', function (nodes, name, args) {
  17565. var i = nodes.length, node;
  17566. while (i--) {
  17567. node = nodes[i];
  17568. if (node.attr('data-mce-type') === 'bookmark' && !args.cleanup) {
  17569. var hasChildren = Option.from(node.firstChild).exists(function (firstChild) {
  17570. return !Zwsp.isZwsp(firstChild.value);
  17571. });
  17572. if (hasChildren) {
  17573. node.unwrap();
  17574. } else {
  17575. node.remove();
  17576. }
  17577. }
  17578. }
  17579. });
  17580. htmlParser.addNodeFilter('noscript', function (nodes) {
  17581. var i = nodes.length, node;
  17582. while (i--) {
  17583. node = nodes[i].firstChild;
  17584. if (node) {
  17585. node.value = Entities.decode(node.value);
  17586. }
  17587. }
  17588. });
  17589. htmlParser.addNodeFilter('script,style', function (nodes, name) {
  17590. var i = nodes.length, node, value, type;
  17591. var trim = function (value) {
  17592. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n').replace(/^[\r\n]*|[\r\n]*$/g, '').replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '').replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  17593. };
  17594. while (i--) {
  17595. node = nodes[i];
  17596. value = node.firstChild ? node.firstChild.value : '';
  17597. if (name === 'script') {
  17598. type = node.attr('type');
  17599. if (type) {
  17600. node.attr('type', type === 'mce-no/type' ? null : type.replace(/^mce\-/, ''));
  17601. }
  17602. if (settings.element_format === 'xhtml' && value.length > 0) {
  17603. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  17604. }
  17605. } else {
  17606. if (settings.element_format === 'xhtml' && value.length > 0) {
  17607. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  17608. }
  17609. }
  17610. }
  17611. });
  17612. htmlParser.addNodeFilter('#comment', function (nodes) {
  17613. var i = nodes.length, node;
  17614. while (i--) {
  17615. node = nodes[i];
  17616. if (node.value.indexOf('[CDATA[') === 0) {
  17617. node.name = '#cdata';
  17618. node.type = 4;
  17619. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  17620. } else if (node.value.indexOf('mce:protected ') === 0) {
  17621. node.name = '#text';
  17622. node.type = 3;
  17623. node.raw = true;
  17624. node.value = unescape(node.value).substr(14);
  17625. }
  17626. }
  17627. });
  17628. htmlParser.addNodeFilter('xml:namespace,input', function (nodes, name) {
  17629. var i = nodes.length, node;
  17630. while (i--) {
  17631. node = nodes[i];
  17632. if (node.type === 7) {
  17633. node.remove();
  17634. } else if (node.type === 1) {
  17635. if (name === 'input' && !node.attr('type')) {
  17636. node.attr('type', 'text');
  17637. }
  17638. }
  17639. }
  17640. });
  17641. htmlParser.addAttributeFilter('data-mce-type', function (nodes) {
  17642. each(nodes, function (node) {
  17643. if (node.attr('data-mce-type') === 'format-caret') {
  17644. if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) {
  17645. node.remove();
  17646. } else {
  17647. node.unwrap();
  17648. }
  17649. }
  17650. });
  17651. });
  17652. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style,' + 'data-mce-selected,data-mce-expando,' + 'data-mce-type,data-mce-resize', function (nodes, name) {
  17653. var i = nodes.length;
  17654. while (i--) {
  17655. nodes[i].attr(name, null);
  17656. }
  17657. });
  17658. };
  17659. var trimTrailingBr = function (rootNode) {
  17660. var brNode1, brNode2;
  17661. var isBr = function (node) {
  17662. return node && node.name === 'br';
  17663. };
  17664. brNode1 = rootNode.lastChild;
  17665. if (isBr(brNode1)) {
  17666. brNode2 = brNode1.prev;
  17667. if (isBr(brNode2)) {
  17668. brNode1.remove();
  17669. brNode2.remove();
  17670. }
  17671. }
  17672. };
  17673. var DomSerializerFilters = {
  17674. register: register$1,
  17675. trimTrailingBr: trimTrailingBr
  17676. };
  17677. var preProcess = function (editor, node, args) {
  17678. var impl, doc, oldDoc;
  17679. var dom = editor.dom;
  17680. node = node.cloneNode(true);
  17681. impl = domGlobals.document.implementation;
  17682. if (impl.createHTMLDocument) {
  17683. doc = impl.createHTMLDocument('');
  17684. Tools.each(node.nodeName === 'BODY' ? node.childNodes : [node], function (node) {
  17685. doc.body.appendChild(doc.importNode(node, true));
  17686. });
  17687. if (node.nodeName !== 'BODY') {
  17688. node = doc.body.firstChild;
  17689. } else {
  17690. node = doc.body;
  17691. }
  17692. oldDoc = dom.doc;
  17693. dom.doc = doc;
  17694. }
  17695. Events.firePreProcess(editor, merge(args, { node: node }));
  17696. if (oldDoc) {
  17697. dom.doc = oldDoc;
  17698. }
  17699. return node;
  17700. };
  17701. var shouldFireEvent = function (editor, args) {
  17702. return editor && editor.hasEventListeners('PreProcess') && !args.no_events;
  17703. };
  17704. var process = function (editor, node, args) {
  17705. return shouldFireEvent(editor, args) ? preProcess(editor, node, args) : node;
  17706. };
  17707. var DomSerializerPreProcess = { process: process };
  17708. var removeAttrs = function (node, names) {
  17709. each(names, function (name) {
  17710. node.attr(name, null);
  17711. });
  17712. };
  17713. var addFontToSpansFilter = function (domParser, styles, fontSizes) {
  17714. domParser.addNodeFilter('font', function (nodes) {
  17715. each(nodes, function (node) {
  17716. var props = styles.parse(node.attr('style'));
  17717. var color = node.attr('color');
  17718. var face = node.attr('face');
  17719. var size = node.attr('size');
  17720. if (color) {
  17721. props.color = color;
  17722. }
  17723. if (face) {
  17724. props['font-family'] = face;
  17725. }
  17726. if (size) {
  17727. props['font-size'] = fontSizes[parseInt(node.attr('size'), 10) - 1];
  17728. }
  17729. node.name = 'span';
  17730. node.attr('style', styles.serialize(props));
  17731. removeAttrs(node, [
  17732. 'color',
  17733. 'face',
  17734. 'size'
  17735. ]);
  17736. });
  17737. });
  17738. };
  17739. var addStrikeToSpanFilter = function (domParser, styles) {
  17740. domParser.addNodeFilter('strike', function (nodes) {
  17741. each(nodes, function (node) {
  17742. var props = styles.parse(node.attr('style'));
  17743. props['text-decoration'] = 'line-through';
  17744. node.name = 'span';
  17745. node.attr('style', styles.serialize(props));
  17746. });
  17747. });
  17748. };
  17749. var addFilters = function (domParser, settings) {
  17750. var styles = Styles();
  17751. if (settings.convert_fonts_to_spans) {
  17752. addFontToSpansFilter(domParser, styles, Tools.explode(settings.font_size_legacy_values));
  17753. }
  17754. addStrikeToSpanFilter(domParser, styles);
  17755. };
  17756. var register$2 = function (domParser, settings) {
  17757. if (settings.inline_styles) {
  17758. addFilters(domParser, settings);
  17759. }
  17760. };
  17761. var LegacyFilter = { register: register$2 };
  17762. var paddEmptyNode = function (settings, args, blockElements, node) {
  17763. var brPreferred = settings.padd_empty_with_br || args.insert;
  17764. if (brPreferred && blockElements[node.name]) {
  17765. node.empty().append(new Node$1('br', 1)).shortEnded = true;
  17766. } else {
  17767. node.empty().append(new Node$1('#text', 3)).value = '\xA0';
  17768. }
  17769. };
  17770. var isPaddedWithNbsp = function (node) {
  17771. return hasOnlyChild(node, '#text') && node.firstChild.value === '\xA0';
  17772. };
  17773. var hasOnlyChild = function (node, name) {
  17774. return node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name;
  17775. };
  17776. var isPadded = function (schema, node) {
  17777. var rule = schema.getElementRule(node.name);
  17778. return rule && rule.paddEmpty;
  17779. };
  17780. var isEmpty$2 = function (schema, nonEmptyElements, whitespaceElements, node) {
  17781. return node.isEmpty(nonEmptyElements, whitespaceElements, function (node) {
  17782. return isPadded(schema, node);
  17783. });
  17784. };
  17785. var isLineBreakNode = function (node, blockElements) {
  17786. return node && (blockElements[node.name] || node.name === 'br');
  17787. };
  17788. var register$3 = function (parser, settings) {
  17789. var schema = parser.schema;
  17790. if (settings.remove_trailing_brs) {
  17791. parser.addNodeFilter('br', function (nodes, _, args) {
  17792. var i;
  17793. var l = nodes.length;
  17794. var node;
  17795. var blockElements = Tools.extend({}, schema.getBlockElements());
  17796. var nonEmptyElements = schema.getNonEmptyElements();
  17797. var parent, lastParent, prev, prevName;
  17798. var whiteSpaceElements = schema.getNonEmptyElements();
  17799. var elementRule, textNode;
  17800. blockElements.body = 1;
  17801. for (i = 0; i < l; i++) {
  17802. node = nodes[i];
  17803. parent = node.parent;
  17804. if (blockElements[node.parent.name] && node === parent.lastChild) {
  17805. prev = node.prev;
  17806. while (prev) {
  17807. prevName = prev.name;
  17808. if (prevName !== 'span' || prev.attr('data-mce-type') !== 'bookmark') {
  17809. if (prevName !== 'br') {
  17810. break;
  17811. }
  17812. if (prevName === 'br') {
  17813. node = null;
  17814. break;
  17815. }
  17816. }
  17817. prev = prev.prev;
  17818. }
  17819. if (node) {
  17820. node.remove();
  17821. if (isEmpty$2(schema, nonEmptyElements, whiteSpaceElements, parent)) {
  17822. elementRule = schema.getElementRule(parent.name);
  17823. if (elementRule) {
  17824. if (elementRule.removeEmpty) {
  17825. parent.remove();
  17826. } else if (elementRule.paddEmpty) {
  17827. paddEmptyNode(settings, args, blockElements, parent);
  17828. }
  17829. }
  17830. }
  17831. }
  17832. } else {
  17833. lastParent = node;
  17834. while (parent && parent.firstChild === lastParent && parent.lastChild === lastParent) {
  17835. lastParent = parent;
  17836. if (blockElements[parent.name]) {
  17837. break;
  17838. }
  17839. parent = parent.parent;
  17840. }
  17841. if (lastParent === parent && settings.padd_empty_with_br !== true) {
  17842. textNode = new Node$1('#text', 3);
  17843. textNode.value = '\xA0';
  17844. node.replace(textNode);
  17845. }
  17846. }
  17847. }
  17848. });
  17849. }
  17850. parser.addAttributeFilter('href', function (nodes) {
  17851. var i = nodes.length, node;
  17852. var appendRel = function (rel) {
  17853. var parts = rel.split(' ').filter(function (p) {
  17854. return p.length > 0;
  17855. });
  17856. return parts.concat(['noopener']).sort().join(' ');
  17857. };
  17858. var addNoOpener = function (rel) {
  17859. var newRel = rel ? Tools.trim(rel) : '';
  17860. if (!/\b(noopener)\b/g.test(newRel)) {
  17861. return appendRel(newRel);
  17862. } else {
  17863. return newRel;
  17864. }
  17865. };
  17866. if (!settings.allow_unsafe_link_target) {
  17867. while (i--) {
  17868. node = nodes[i];
  17869. if (node.name === 'a' && node.attr('target') === '_blank') {
  17870. node.attr('rel', addNoOpener(node.attr('rel')));
  17871. }
  17872. }
  17873. }
  17874. });
  17875. if (!settings.allow_html_in_named_anchor) {
  17876. parser.addAttributeFilter('id,name', function (nodes) {
  17877. var i = nodes.length, sibling, prevSibling, parent, node;
  17878. while (i--) {
  17879. node = nodes[i];
  17880. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  17881. parent = node.parent;
  17882. sibling = node.lastChild;
  17883. do {
  17884. prevSibling = sibling.prev;
  17885. parent.insert(sibling, node);
  17886. sibling = prevSibling;
  17887. } while (sibling);
  17888. }
  17889. }
  17890. });
  17891. }
  17892. if (settings.fix_list_elements) {
  17893. parser.addNodeFilter('ul,ol', function (nodes) {
  17894. var i = nodes.length, node, parentNode;
  17895. while (i--) {
  17896. node = nodes[i];
  17897. parentNode = node.parent;
  17898. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  17899. if (node.prev && node.prev.name === 'li') {
  17900. node.prev.append(node);
  17901. } else {
  17902. var li = new Node$1('li', 1);
  17903. li.attr('style', 'list-style-type: none');
  17904. node.wrap(li);
  17905. }
  17906. }
  17907. }
  17908. });
  17909. }
  17910. if (settings.validate && schema.getValidClasses()) {
  17911. parser.addAttributeFilter('class', function (nodes) {
  17912. var i = nodes.length, node, classList, ci, className, classValue;
  17913. var validClasses = schema.getValidClasses();
  17914. var validClassesMap, valid;
  17915. while (i--) {
  17916. node = nodes[i];
  17917. classList = node.attr('class').split(' ');
  17918. classValue = '';
  17919. for (ci = 0; ci < classList.length; ci++) {
  17920. className = classList[ci];
  17921. valid = false;
  17922. validClassesMap = validClasses['*'];
  17923. if (validClassesMap && validClassesMap[className]) {
  17924. valid = true;
  17925. }
  17926. validClassesMap = validClasses[node.name];
  17927. if (!valid && validClassesMap && validClassesMap[className]) {
  17928. valid = true;
  17929. }
  17930. if (valid) {
  17931. if (classValue) {
  17932. classValue += ' ';
  17933. }
  17934. classValue += className;
  17935. }
  17936. }
  17937. if (!classValue.length) {
  17938. classValue = null;
  17939. }
  17940. node.attr('class', classValue);
  17941. }
  17942. });
  17943. }
  17944. };
  17945. var makeMap$4 = Tools.makeMap, each$f = Tools.each, explode$2 = Tools.explode, extend$2 = Tools.extend;
  17946. var DomParser = function (settings, schema) {
  17947. if (schema === void 0) {
  17948. schema = Schema();
  17949. }
  17950. var nodeFilters = {};
  17951. var attributeFilters = [];
  17952. var matchedNodes = {};
  17953. var matchedAttributes = {};
  17954. settings = settings || {};
  17955. settings.validate = 'validate' in settings ? settings.validate : true;
  17956. settings.root_name = settings.root_name || 'body';
  17957. var fixInvalidChildren = function (nodes) {
  17958. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i;
  17959. var nonEmptyElements, whitespaceElements, nonSplitableElements, textBlockElements, specialElements, sibling, nextNode;
  17960. nonSplitableElements = makeMap$4('tr,td,th,tbody,thead,tfoot,table');
  17961. nonEmptyElements = schema.getNonEmptyElements();
  17962. whitespaceElements = schema.getWhiteSpaceElements();
  17963. textBlockElements = schema.getTextBlockElements();
  17964. specialElements = schema.getSpecialElements();
  17965. for (ni = 0; ni < nodes.length; ni++) {
  17966. node = nodes[ni];
  17967. if (!node.parent || node.fixed) {
  17968. continue;
  17969. }
  17970. if (textBlockElements[node.name] && node.parent.name === 'li') {
  17971. sibling = node.next;
  17972. while (sibling) {
  17973. if (textBlockElements[sibling.name]) {
  17974. sibling.name = 'li';
  17975. sibling.fixed = true;
  17976. node.parent.insert(sibling, node.parent);
  17977. } else {
  17978. break;
  17979. }
  17980. sibling = sibling.next;
  17981. }
  17982. node.unwrap(node);
  17983. continue;
  17984. }
  17985. parents = [node];
  17986. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent) {
  17987. parents.push(parent);
  17988. }
  17989. if (parent && parents.length > 1) {
  17990. parents.reverse();
  17991. newParent = currentNode = filterNode(parents[0].clone());
  17992. for (i = 0; i < parents.length - 1; i++) {
  17993. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  17994. tempNode = filterNode(parents[i].clone());
  17995. currentNode.append(tempNode);
  17996. } else {
  17997. tempNode = currentNode;
  17998. }
  17999. for (childNode = parents[i].firstChild; childNode && childNode !== parents[i + 1];) {
  18000. nextNode = childNode.next;
  18001. tempNode.append(childNode);
  18002. childNode = nextNode;
  18003. }
  18004. currentNode = tempNode;
  18005. }
  18006. if (!isEmpty$2(schema, nonEmptyElements, whitespaceElements, newParent)) {
  18007. parent.insert(newParent, parents[0], true);
  18008. parent.insert(node, newParent);
  18009. } else {
  18010. parent.insert(node, parents[0], true);
  18011. }
  18012. parent = parents[0];
  18013. if (isEmpty$2(schema, nonEmptyElements, whitespaceElements, parent) || hasOnlyChild(parent, 'br')) {
  18014. parent.empty().remove();
  18015. }
  18016. } else if (node.parent) {
  18017. if (node.name === 'li') {
  18018. sibling = node.prev;
  18019. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  18020. sibling.append(node);
  18021. continue;
  18022. }
  18023. sibling = node.next;
  18024. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  18025. sibling.insert(node, sibling.firstChild, true);
  18026. continue;
  18027. }
  18028. node.wrap(filterNode(new Node$1('ul', 1)));
  18029. continue;
  18030. }
  18031. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  18032. node.wrap(filterNode(new Node$1('div', 1)));
  18033. } else {
  18034. if (specialElements[node.name]) {
  18035. node.empty().remove();
  18036. } else {
  18037. node.unwrap();
  18038. }
  18039. }
  18040. }
  18041. }
  18042. };
  18043. var filterNode = function (node) {
  18044. var i, name, list;
  18045. name = node.name;
  18046. if (name in nodeFilters) {
  18047. list = matchedNodes[name];
  18048. if (list) {
  18049. list.push(node);
  18050. } else {
  18051. matchedNodes[name] = [node];
  18052. }
  18053. }
  18054. i = attributeFilters.length;
  18055. while (i--) {
  18056. name = attributeFilters[i].name;
  18057. if (name in node.attributes.map) {
  18058. list = matchedAttributes[name];
  18059. if (list) {
  18060. list.push(node);
  18061. } else {
  18062. matchedAttributes[name] = [node];
  18063. }
  18064. }
  18065. }
  18066. return node;
  18067. };
  18068. var addNodeFilter = function (name, callback) {
  18069. each$f(explode$2(name), function (name) {
  18070. var list = nodeFilters[name];
  18071. if (!list) {
  18072. nodeFilters[name] = list = [];
  18073. }
  18074. list.push(callback);
  18075. });
  18076. };
  18077. var getNodeFilters = function () {
  18078. var out = [];
  18079. for (var name in nodeFilters) {
  18080. if (nodeFilters.hasOwnProperty(name)) {
  18081. out.push({
  18082. name: name,
  18083. callbacks: nodeFilters[name]
  18084. });
  18085. }
  18086. }
  18087. return out;
  18088. };
  18089. var addAttributeFilter = function (name, callback) {
  18090. each$f(explode$2(name), function (name) {
  18091. var i;
  18092. for (i = 0; i < attributeFilters.length; i++) {
  18093. if (attributeFilters[i].name === name) {
  18094. attributeFilters[i].callbacks.push(callback);
  18095. return;
  18096. }
  18097. }
  18098. attributeFilters.push({
  18099. name: name,
  18100. callbacks: [callback]
  18101. });
  18102. });
  18103. };
  18104. var getAttributeFilters = function () {
  18105. return [].concat(attributeFilters);
  18106. };
  18107. var parse = function (html, args) {
  18108. var parser, nodes, i, l, fi, fl, list, name;
  18109. var blockElements;
  18110. var invalidChildren = [];
  18111. var isInWhiteSpacePreservedElement;
  18112. var node;
  18113. var getRootBlockName = function (name) {
  18114. if (name === false) {
  18115. return '';
  18116. } else if (name === true) {
  18117. return 'p';
  18118. } else {
  18119. return name;
  18120. }
  18121. };
  18122. args = args || {};
  18123. matchedNodes = {};
  18124. matchedAttributes = {};
  18125. blockElements = extend$2(makeMap$4('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  18126. var nonEmptyElements = schema.getNonEmptyElements();
  18127. var children = schema.children;
  18128. var validate = settings.validate;
  18129. var forcedRootBlockName = 'forced_root_block' in args ? args.forced_root_block : settings.forced_root_block;
  18130. var rootBlockName = getRootBlockName(forcedRootBlockName);
  18131. var whiteSpaceElements = schema.getWhiteSpaceElements();
  18132. var startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  18133. var endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  18134. var allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  18135. var isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  18136. isInWhiteSpacePreservedElement = whiteSpaceElements.hasOwnProperty(args.context) || whiteSpaceElements.hasOwnProperty(settings.root_name);
  18137. var addRootBlocks = function () {
  18138. var node = rootNode.firstChild, next, rootBlockNode;
  18139. var trim = function (rootBlockNode) {
  18140. if (rootBlockNode) {
  18141. node = rootBlockNode.firstChild;
  18142. if (node && node.type === 3) {
  18143. node.value = node.value.replace(startWhiteSpaceRegExp, '');
  18144. }
  18145. node = rootBlockNode.lastChild;
  18146. if (node && node.type === 3) {
  18147. node.value = node.value.replace(endWhiteSpaceRegExp, '');
  18148. }
  18149. }
  18150. };
  18151. if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
  18152. return;
  18153. }
  18154. while (node) {
  18155. next = node.next;
  18156. if (node.type === 3 || node.type === 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type')) {
  18157. if (!rootBlockNode) {
  18158. rootBlockNode = createNode(rootBlockName, 1);
  18159. rootBlockNode.attr(settings.forced_root_block_attrs);
  18160. rootNode.insert(rootBlockNode, node);
  18161. rootBlockNode.append(node);
  18162. } else {
  18163. rootBlockNode.append(node);
  18164. }
  18165. } else {
  18166. trim(rootBlockNode);
  18167. rootBlockNode = null;
  18168. }
  18169. node = next;
  18170. }
  18171. trim(rootBlockNode);
  18172. };
  18173. var createNode = function (name, type) {
  18174. var node = new Node$1(name, type);
  18175. var list;
  18176. if (name in nodeFilters) {
  18177. list = matchedNodes[name];
  18178. if (list) {
  18179. list.push(node);
  18180. } else {
  18181. matchedNodes[name] = [node];
  18182. }
  18183. }
  18184. return node;
  18185. };
  18186. var removeWhitespaceBefore = function (node) {
  18187. var textNode, textNodeNext, textVal, sibling;
  18188. var blockElements = schema.getBlockElements();
  18189. for (textNode = node.prev; textNode && textNode.type === 3;) {
  18190. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  18191. if (textVal.length > 0) {
  18192. textNode.value = textVal;
  18193. return;
  18194. }
  18195. textNodeNext = textNode.next;
  18196. if (textNodeNext) {
  18197. if (textNodeNext.type === 3 && textNodeNext.value.length) {
  18198. textNode = textNode.prev;
  18199. continue;
  18200. }
  18201. if (!blockElements[textNodeNext.name] && textNodeNext.name !== 'script' && textNodeNext.name !== 'style') {
  18202. textNode = textNode.prev;
  18203. continue;
  18204. }
  18205. }
  18206. sibling = textNode.prev;
  18207. textNode.remove();
  18208. textNode = sibling;
  18209. }
  18210. };
  18211. var cloneAndExcludeBlocks = function (input) {
  18212. var name;
  18213. var output = {};
  18214. for (name in input) {
  18215. if (name !== 'li' && name !== 'p') {
  18216. output[name] = input[name];
  18217. }
  18218. }
  18219. return output;
  18220. };
  18221. parser = SaxParser$1({
  18222. validate: validate,
  18223. allow_script_urls: settings.allow_script_urls,
  18224. allow_conditional_comments: settings.allow_conditional_comments,
  18225. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  18226. cdata: function (text) {
  18227. node.append(createNode('#cdata', 4)).value = text;
  18228. },
  18229. text: function (text, raw) {
  18230. var textNode;
  18231. if (!isInWhiteSpacePreservedElement) {
  18232. text = text.replace(allWhiteSpaceRegExp, ' ');
  18233. if (isLineBreakNode(node.lastChild, blockElements)) {
  18234. text = text.replace(startWhiteSpaceRegExp, '');
  18235. }
  18236. }
  18237. if (text.length !== 0) {
  18238. textNode = createNode('#text', 3);
  18239. textNode.raw = !!raw;
  18240. node.append(textNode).value = text;
  18241. }
  18242. },
  18243. comment: function (text) {
  18244. node.append(createNode('#comment', 8)).value = text;
  18245. },
  18246. pi: function (name, text) {
  18247. node.append(createNode(name, 7)).value = text;
  18248. removeWhitespaceBefore(node);
  18249. },
  18250. doctype: function (text) {
  18251. var newNode;
  18252. newNode = node.append(createNode('#doctype', 10));
  18253. newNode.value = text;
  18254. removeWhitespaceBefore(node);
  18255. },
  18256. start: function (name, attrs, empty) {
  18257. var newNode, attrFiltersLen, elementRule, attrName, parent;
  18258. elementRule = validate ? schema.getElementRule(name) : {};
  18259. if (elementRule) {
  18260. newNode = createNode(elementRule.outputName || name, 1);
  18261. newNode.attributes = attrs;
  18262. newNode.shortEnded = empty;
  18263. node.append(newNode);
  18264. parent = children[node.name];
  18265. if (parent && children[newNode.name] && !parent[newNode.name]) {
  18266. invalidChildren.push(newNode);
  18267. }
  18268. attrFiltersLen = attributeFilters.length;
  18269. while (attrFiltersLen--) {
  18270. attrName = attributeFilters[attrFiltersLen].name;
  18271. if (attrName in attrs.map) {
  18272. list = matchedAttributes[attrName];
  18273. if (list) {
  18274. list.push(newNode);
  18275. } else {
  18276. matchedAttributes[attrName] = [newNode];
  18277. }
  18278. }
  18279. }
  18280. if (blockElements[name]) {
  18281. removeWhitespaceBefore(newNode);
  18282. }
  18283. if (!empty) {
  18284. node = newNode;
  18285. }
  18286. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  18287. isInWhiteSpacePreservedElement = true;
  18288. }
  18289. }
  18290. },
  18291. end: function (name) {
  18292. var textNode, elementRule, text, sibling, tempNode;
  18293. elementRule = validate ? schema.getElementRule(name) : {};
  18294. if (elementRule) {
  18295. if (blockElements[name]) {
  18296. if (!isInWhiteSpacePreservedElement) {
  18297. textNode = node.firstChild;
  18298. if (textNode && textNode.type === 3) {
  18299. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  18300. if (text.length > 0) {
  18301. textNode.value = text;
  18302. textNode = textNode.next;
  18303. } else {
  18304. sibling = textNode.next;
  18305. textNode.remove();
  18306. textNode = sibling;
  18307. while (textNode && textNode.type === 3) {
  18308. text = textNode.value;
  18309. sibling = textNode.next;
  18310. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  18311. textNode.remove();
  18312. textNode = sibling;
  18313. }
  18314. textNode = sibling;
  18315. }
  18316. }
  18317. }
  18318. textNode = node.lastChild;
  18319. if (textNode && textNode.type === 3) {
  18320. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  18321. if (text.length > 0) {
  18322. textNode.value = text;
  18323. textNode = textNode.prev;
  18324. } else {
  18325. sibling = textNode.prev;
  18326. textNode.remove();
  18327. textNode = sibling;
  18328. while (textNode && textNode.type === 3) {
  18329. text = textNode.value;
  18330. sibling = textNode.prev;
  18331. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  18332. textNode.remove();
  18333. textNode = sibling;
  18334. }
  18335. textNode = sibling;
  18336. }
  18337. }
  18338. }
  18339. }
  18340. }
  18341. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  18342. isInWhiteSpacePreservedElement = false;
  18343. }
  18344. if (elementRule.removeEmpty && isEmpty$2(schema, nonEmptyElements, whiteSpaceElements, node)) {
  18345. if (!node.attr('name') && !node.attr('id')) {
  18346. tempNode = node.parent;
  18347. if (blockElements[node.name]) {
  18348. node.empty().remove();
  18349. } else {
  18350. node.unwrap();
  18351. }
  18352. node = tempNode;
  18353. return;
  18354. }
  18355. }
  18356. if (elementRule.paddEmpty && (isPaddedWithNbsp(node) || isEmpty$2(schema, nonEmptyElements, whiteSpaceElements, node))) {
  18357. paddEmptyNode(settings, args, blockElements, node);
  18358. }
  18359. node = node.parent;
  18360. }
  18361. }
  18362. }, schema);
  18363. var rootNode = node = new Node$1(args.context || settings.root_name, 11);
  18364. parser.parse(html);
  18365. if (validate && invalidChildren.length) {
  18366. if (!args.context) {
  18367. fixInvalidChildren(invalidChildren);
  18368. } else {
  18369. args.invalid = true;
  18370. }
  18371. }
  18372. if (rootBlockName && (rootNode.name === 'body' || args.isRootContent)) {
  18373. addRootBlocks();
  18374. }
  18375. if (!args.invalid) {
  18376. for (name in matchedNodes) {
  18377. if (!matchedNodes.hasOwnProperty(name)) {
  18378. continue;
  18379. }
  18380. list = nodeFilters[name];
  18381. nodes = matchedNodes[name];
  18382. fi = nodes.length;
  18383. while (fi--) {
  18384. if (!nodes[fi].parent) {
  18385. nodes.splice(fi, 1);
  18386. }
  18387. }
  18388. for (i = 0, l = list.length; i < l; i++) {
  18389. list[i](nodes, name, args);
  18390. }
  18391. }
  18392. for (i = 0, l = attributeFilters.length; i < l; i++) {
  18393. list = attributeFilters[i];
  18394. if (list.name in matchedAttributes) {
  18395. nodes = matchedAttributes[list.name];
  18396. fi = nodes.length;
  18397. while (fi--) {
  18398. if (!nodes[fi].parent) {
  18399. nodes.splice(fi, 1);
  18400. }
  18401. }
  18402. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) {
  18403. list.callbacks[fi](nodes, list.name, args);
  18404. }
  18405. }
  18406. }
  18407. }
  18408. return rootNode;
  18409. };
  18410. var exports = {
  18411. schema: schema,
  18412. addAttributeFilter: addAttributeFilter,
  18413. getAttributeFilters: getAttributeFilters,
  18414. addNodeFilter: addNodeFilter,
  18415. getNodeFilters: getNodeFilters,
  18416. filterNode: filterNode,
  18417. parse: parse
  18418. };
  18419. register$3(exports, settings);
  18420. LegacyFilter.register(exports, settings);
  18421. return exports;
  18422. };
  18423. var addTempAttr = function (htmlParser, tempAttrs, name) {
  18424. if (Tools.inArray(tempAttrs, name) === -1) {
  18425. htmlParser.addAttributeFilter(name, function (nodes, name) {
  18426. var i = nodes.length;
  18427. while (i--) {
  18428. nodes[i].attr(name, null);
  18429. }
  18430. });
  18431. tempAttrs.push(name);
  18432. }
  18433. };
  18434. var postProcess$1 = function (editor, args, content) {
  18435. if (!args.no_events && editor) {
  18436. var outArgs = Events.firePostProcess(editor, merge(args, { content: content }));
  18437. return outArgs.content;
  18438. } else {
  18439. return content;
  18440. }
  18441. };
  18442. var getHtmlFromNode = function (dom, node, args) {
  18443. var html = Zwsp.trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node));
  18444. return args.selection || isWsPreserveElement(Element.fromDom(node)) ? html : Tools.trim(html);
  18445. };
  18446. var parseHtml = function (htmlParser, html, args) {
  18447. var parserArgs = args.selection ? merge({ forced_root_block: false }, args) : args;
  18448. var rootNode = htmlParser.parse(html, parserArgs);
  18449. DomSerializerFilters.trimTrailingBr(rootNode);
  18450. return rootNode;
  18451. };
  18452. var serializeNode = function (settings, schema, node) {
  18453. var htmlSerializer = Serializer(settings, schema);
  18454. return htmlSerializer.serialize(node);
  18455. };
  18456. var toHtml = function (editor, settings, schema, rootNode, args) {
  18457. var content = serializeNode(settings, schema, rootNode);
  18458. return postProcess$1(editor, args, content);
  18459. };
  18460. var DomSerializer = function (settings, editor) {
  18461. var dom, schema, htmlParser;
  18462. var tempAttrs = ['data-mce-selected'];
  18463. dom = editor && editor.dom ? editor.dom : DOMUtils$1.DOM;
  18464. schema = editor && editor.schema ? editor.schema : Schema(settings);
  18465. settings.entity_encoding = settings.entity_encoding || 'named';
  18466. settings.remove_trailing_brs = 'remove_trailing_brs' in settings ? settings.remove_trailing_brs : true;
  18467. htmlParser = DomParser(settings, schema);
  18468. DomSerializerFilters.register(htmlParser, settings, dom);
  18469. var serialize = function (node, parserArgs) {
  18470. var args = merge({ format: 'html' }, parserArgs ? parserArgs : {});
  18471. var targetNode = DomSerializerPreProcess.process(editor, node, args);
  18472. var html = getHtmlFromNode(dom, targetNode, args);
  18473. var rootNode = parseHtml(htmlParser, html, args);
  18474. return args.format === 'tree' ? rootNode : toHtml(editor, settings, schema, rootNode, args);
  18475. };
  18476. return {
  18477. schema: schema,
  18478. addNodeFilter: htmlParser.addNodeFilter,
  18479. addAttributeFilter: htmlParser.addAttributeFilter,
  18480. serialize: serialize,
  18481. addRules: function (rules) {
  18482. schema.addValidElements(rules);
  18483. },
  18484. setRules: function (rules) {
  18485. schema.setValidElements(rules);
  18486. },
  18487. addTempAttr: curry(addTempAttr, htmlParser, tempAttrs),
  18488. getTempAttrs: function () {
  18489. return tempAttrs;
  18490. }
  18491. };
  18492. };
  18493. var Serializer$1 = function (settings, editor) {
  18494. var domSerializer = DomSerializer(settings, editor);
  18495. return {
  18496. schema: domSerializer.schema,
  18497. addNodeFilter: domSerializer.addNodeFilter,
  18498. addAttributeFilter: domSerializer.addAttributeFilter,
  18499. serialize: domSerializer.serialize,
  18500. addRules: domSerializer.addRules,
  18501. setRules: domSerializer.setRules,
  18502. addTempAttr: domSerializer.addTempAttr,
  18503. getTempAttrs: domSerializer.getTempAttrs
  18504. };
  18505. };
  18506. function BookmarkManager(selection) {
  18507. return {
  18508. getBookmark: curry(Bookmarks.getBookmark, selection),
  18509. moveToBookmark: curry(Bookmarks.moveToBookmark, selection)
  18510. };
  18511. }
  18512. (function (BookmarkManager) {
  18513. BookmarkManager.isBookmarkNode = Bookmarks.isBookmarkNode;
  18514. }(BookmarkManager || (BookmarkManager = {})));
  18515. var BookmarkManager$1 = BookmarkManager;
  18516. var isContentEditableFalse$a = NodeType.isContentEditableFalse;
  18517. var isContentEditableTrue$5 = NodeType.isContentEditableTrue;
  18518. var getContentEditableRoot$1 = function (root, node) {
  18519. while (node && node !== root) {
  18520. if (isContentEditableTrue$5(node) || isContentEditableFalse$a(node)) {
  18521. return node;
  18522. }
  18523. node = node.parentNode;
  18524. }
  18525. return null;
  18526. };
  18527. var ControlSelection = function (selection, editor) {
  18528. var dom = editor.dom, each = Tools.each;
  18529. var selectedElm, selectedElmGhost, resizeHelper, resizeHandles, selectedHandle;
  18530. var startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted;
  18531. var width, height;
  18532. var editableDoc = editor.getDoc(), rootDocument = domGlobals.document;
  18533. var abs = Math.abs, round = Math.round, rootElement = editor.getBody();
  18534. var startScrollWidth, startScrollHeight;
  18535. resizeHandles = {
  18536. nw: [
  18537. 0,
  18538. 0,
  18539. -1,
  18540. -1
  18541. ],
  18542. ne: [
  18543. 1,
  18544. 0,
  18545. 1,
  18546. -1
  18547. ],
  18548. se: [
  18549. 1,
  18550. 1,
  18551. 1,
  18552. 1
  18553. ],
  18554. sw: [
  18555. 0,
  18556. 1,
  18557. -1,
  18558. 1
  18559. ]
  18560. };
  18561. var isImage = function (elm) {
  18562. return elm && (elm.nodeName === 'IMG' || editor.dom.is(elm, 'figure.image'));
  18563. };
  18564. var isEventOnImageOutsideRange = function (evt, range) {
  18565. if (evt.type === 'longpress' || evt.type.indexOf('touch') === 0) {
  18566. var touch = evt.touches[0];
  18567. return isImage(evt.target) && !RangePoint.isXYWithinRange(touch.clientX, touch.clientY, range);
  18568. } else {
  18569. return isImage(evt.target) && !RangePoint.isXYWithinRange(evt.clientX, evt.clientY, range);
  18570. }
  18571. };
  18572. var contextMenuSelectImage = function (evt) {
  18573. var target = evt.target;
  18574. if (isEventOnImageOutsideRange(evt, editor.selection.getRng()) && !evt.isDefaultPrevented()) {
  18575. editor.selection.select(target);
  18576. }
  18577. };
  18578. var getResizeTarget = function (elm) {
  18579. return editor.dom.is(elm, 'figure.image') ? elm.querySelector('img') : elm;
  18580. };
  18581. var isResizable = function (elm) {
  18582. var selector = editor.settings.object_resizing;
  18583. if (selector === false || Env.iOS) {
  18584. return false;
  18585. }
  18586. if (typeof selector !== 'string') {
  18587. selector = 'table,img,figure.image,div';
  18588. }
  18589. if (elm.getAttribute('data-mce-resize') === 'false') {
  18590. return false;
  18591. }
  18592. if (elm === editor.getBody()) {
  18593. return false;
  18594. }
  18595. return is(Element.fromDom(elm), selector);
  18596. };
  18597. var resizeGhostElement = function (e) {
  18598. var deltaX, deltaY, proportional;
  18599. var resizeHelperX, resizeHelperY;
  18600. deltaX = e.screenX - startX;
  18601. deltaY = e.screenY - startY;
  18602. width = deltaX * selectedHandle[2] + startW;
  18603. height = deltaY * selectedHandle[3] + startH;
  18604. width = width < 5 ? 5 : width;
  18605. height = height < 5 ? 5 : height;
  18606. if (isImage(selectedElm) && editor.settings.resize_img_proportional !== false) {
  18607. proportional = !VK.modifierPressed(e);
  18608. } else {
  18609. proportional = VK.modifierPressed(e) || isImage(selectedElm) && selectedHandle[2] * selectedHandle[3] !== 0;
  18610. }
  18611. if (proportional) {
  18612. if (abs(deltaX) > abs(deltaY)) {
  18613. height = round(width * ratio);
  18614. width = round(height / ratio);
  18615. } else {
  18616. width = round(height / ratio);
  18617. height = round(width * ratio);
  18618. }
  18619. }
  18620. dom.setStyles(getResizeTarget(selectedElmGhost), {
  18621. width: width,
  18622. height: height
  18623. });
  18624. resizeHelperX = selectedHandle.startPos.x + deltaX;
  18625. resizeHelperY = selectedHandle.startPos.y + deltaY;
  18626. resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0;
  18627. resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0;
  18628. dom.setStyles(resizeHelper, {
  18629. left: resizeHelperX,
  18630. top: resizeHelperY,
  18631. display: 'block'
  18632. });
  18633. resizeHelper.innerHTML = width + ' &times; ' + height;
  18634. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  18635. dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
  18636. }
  18637. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  18638. dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
  18639. }
  18640. deltaX = rootElement.scrollWidth - startScrollWidth;
  18641. deltaY = rootElement.scrollHeight - startScrollHeight;
  18642. if (deltaX + deltaY !== 0) {
  18643. dom.setStyles(resizeHelper, {
  18644. left: resizeHelperX - deltaX,
  18645. top: resizeHelperY - deltaY
  18646. });
  18647. }
  18648. if (!resizeStarted) {
  18649. Events.fireObjectResizeStart(editor, selectedElm, startW, startH);
  18650. resizeStarted = true;
  18651. }
  18652. };
  18653. var endGhostResize = function () {
  18654. resizeStarted = false;
  18655. var setSizeProp = function (name, value) {
  18656. if (value) {
  18657. if (selectedElm.style[name] || !editor.schema.isValid(selectedElm.nodeName.toLowerCase(), name)) {
  18658. dom.setStyle(getResizeTarget(selectedElm), name, value);
  18659. } else {
  18660. dom.setAttrib(getResizeTarget(selectedElm), name, value);
  18661. }
  18662. }
  18663. };
  18664. setSizeProp('width', width);
  18665. setSizeProp('height', height);
  18666. dom.unbind(editableDoc, 'mousemove', resizeGhostElement);
  18667. dom.unbind(editableDoc, 'mouseup', endGhostResize);
  18668. if (rootDocument !== editableDoc) {
  18669. dom.unbind(rootDocument, 'mousemove', resizeGhostElement);
  18670. dom.unbind(rootDocument, 'mouseup', endGhostResize);
  18671. }
  18672. dom.remove(selectedElmGhost);
  18673. dom.remove(resizeHelper);
  18674. showResizeRect(selectedElm);
  18675. Events.fireObjectResized(editor, selectedElm, width, height);
  18676. dom.setAttrib(selectedElm, 'style', dom.getAttrib(selectedElm, 'style'));
  18677. editor.nodeChanged();
  18678. };
  18679. var showResizeRect = function (targetElm) {
  18680. var position, targetWidth, targetHeight, e, rect;
  18681. hideResizeRect();
  18682. unbindResizeHandleEvents();
  18683. position = dom.getPos(targetElm, rootElement);
  18684. selectedElmX = position.x;
  18685. selectedElmY = position.y;
  18686. rect = targetElm.getBoundingClientRect();
  18687. targetWidth = rect.width || rect.right - rect.left;
  18688. targetHeight = rect.height || rect.bottom - rect.top;
  18689. if (selectedElm !== targetElm) {
  18690. selectedElm = targetElm;
  18691. width = height = 0;
  18692. }
  18693. e = editor.fire('ObjectSelected', { target: targetElm });
  18694. if (isResizable(targetElm) && !e.isDefaultPrevented()) {
  18695. each(resizeHandles, function (handle, name) {
  18696. var handleElm;
  18697. var startDrag = function (e) {
  18698. startX = e.screenX;
  18699. startY = e.screenY;
  18700. startW = getResizeTarget(selectedElm).clientWidth;
  18701. startH = getResizeTarget(selectedElm).clientHeight;
  18702. ratio = startH / startW;
  18703. selectedHandle = handle;
  18704. handle.startPos = {
  18705. x: targetWidth * handle[0] + selectedElmX,
  18706. y: targetHeight * handle[1] + selectedElmY
  18707. };
  18708. startScrollWidth = rootElement.scrollWidth;
  18709. startScrollHeight = rootElement.scrollHeight;
  18710. selectedElmGhost = selectedElm.cloneNode(true);
  18711. dom.addClass(selectedElmGhost, 'mce-clonedresizable');
  18712. dom.setAttrib(selectedElmGhost, 'data-mce-bogus', 'all');
  18713. selectedElmGhost.contentEditable = false;
  18714. selectedElmGhost.unSelectabe = true;
  18715. dom.setStyles(selectedElmGhost, {
  18716. left: selectedElmX,
  18717. top: selectedElmY,
  18718. margin: 0
  18719. });
  18720. selectedElmGhost.removeAttribute('data-mce-selected');
  18721. rootElement.appendChild(selectedElmGhost);
  18722. dom.bind(editableDoc, 'mousemove', resizeGhostElement);
  18723. dom.bind(editableDoc, 'mouseup', endGhostResize);
  18724. if (rootDocument !== editableDoc) {
  18725. dom.bind(rootDocument, 'mousemove', resizeGhostElement);
  18726. dom.bind(rootDocument, 'mouseup', endGhostResize);
  18727. }
  18728. resizeHelper = dom.add(rootElement, 'div', {
  18729. 'class': 'mce-resize-helper',
  18730. 'data-mce-bogus': 'all'
  18731. }, startW + ' &times; ' + startH);
  18732. };
  18733. handleElm = dom.get('mceResizeHandle' + name);
  18734. if (handleElm) {
  18735. dom.remove(handleElm);
  18736. }
  18737. handleElm = dom.add(rootElement, 'div', {
  18738. 'id': 'mceResizeHandle' + name,
  18739. 'data-mce-bogus': 'all',
  18740. 'class': 'mce-resizehandle',
  18741. 'unselectable': true,
  18742. 'style': 'cursor:' + name + '-resize; margin:0; padding:0'
  18743. });
  18744. if (Env.ie === 11) {
  18745. handleElm.contentEditable = false;
  18746. }
  18747. dom.bind(handleElm, 'mousedown', function (e) {
  18748. e.stopImmediatePropagation();
  18749. e.preventDefault();
  18750. startDrag(e);
  18751. });
  18752. handle.elm = handleElm;
  18753. dom.setStyles(handleElm, {
  18754. left: targetWidth * handle[0] + selectedElmX - handleElm.offsetWidth / 2,
  18755. top: targetHeight * handle[1] + selectedElmY - handleElm.offsetHeight / 2
  18756. });
  18757. });
  18758. } else {
  18759. hideResizeRect();
  18760. }
  18761. selectedElm.setAttribute('data-mce-selected', '1');
  18762. };
  18763. var hideResizeRect = function () {
  18764. var name, handleElm;
  18765. unbindResizeHandleEvents();
  18766. if (selectedElm) {
  18767. selectedElm.removeAttribute('data-mce-selected');
  18768. }
  18769. for (name in resizeHandles) {
  18770. handleElm = dom.get('mceResizeHandle' + name);
  18771. if (handleElm) {
  18772. dom.unbind(handleElm);
  18773. dom.remove(handleElm);
  18774. }
  18775. }
  18776. };
  18777. var updateResizeRect = function (e) {
  18778. var startElm, controlElm;
  18779. var isChildOrEqual = function (node, parent) {
  18780. if (node) {
  18781. do {
  18782. if (node === parent) {
  18783. return true;
  18784. }
  18785. } while (node = node.parentNode);
  18786. }
  18787. };
  18788. if (resizeStarted || editor.removed) {
  18789. return;
  18790. }
  18791. each(dom.select('img[data-mce-selected],hr[data-mce-selected]'), function (img) {
  18792. img.removeAttribute('data-mce-selected');
  18793. });
  18794. controlElm = e.type === 'mousedown' ? e.target : selection.getNode();
  18795. controlElm = dom.$(controlElm).closest('table,img,figure.image,hr')[0];
  18796. if (isChildOrEqual(controlElm, rootElement)) {
  18797. disableGeckoResize();
  18798. startElm = selection.getStart(true);
  18799. if (isChildOrEqual(startElm, controlElm) && isChildOrEqual(selection.getEnd(true), controlElm)) {
  18800. showResizeRect(controlElm);
  18801. return;
  18802. }
  18803. }
  18804. hideResizeRect();
  18805. };
  18806. var isWithinContentEditableFalse = function (elm) {
  18807. return isContentEditableFalse$a(getContentEditableRoot$1(editor.getBody(), elm));
  18808. };
  18809. var unbindResizeHandleEvents = function () {
  18810. for (var name in resizeHandles) {
  18811. var handle = resizeHandles[name];
  18812. if (handle.elm) {
  18813. dom.unbind(handle.elm);
  18814. delete handle.elm;
  18815. }
  18816. }
  18817. };
  18818. var disableGeckoResize = function () {
  18819. try {
  18820. editor.getDoc().execCommand('enableObjectResizing', false, false);
  18821. } catch (ex) {
  18822. }
  18823. };
  18824. editor.on('init', function () {
  18825. disableGeckoResize();
  18826. if (Env.browser.isIE() || Env.browser.isEdge()) {
  18827. editor.on('mousedown click', function (e) {
  18828. var target = e.target, nodeName = target.nodeName;
  18829. if (!resizeStarted && /^(TABLE|IMG|HR)$/.test(nodeName) && !isWithinContentEditableFalse(target)) {
  18830. if (e.button !== 2) {
  18831. editor.selection.select(target, nodeName === 'TABLE');
  18832. }
  18833. if (e.type === 'mousedown') {
  18834. editor.nodeChanged();
  18835. }
  18836. }
  18837. });
  18838. editor.dom.bind(rootElement, 'mscontrolselect', function (e) {
  18839. var delayedSelect = function (node) {
  18840. Delay.setEditorTimeout(editor, function () {
  18841. editor.selection.select(node);
  18842. });
  18843. };
  18844. if (isWithinContentEditableFalse(e.target)) {
  18845. e.preventDefault();
  18846. delayedSelect(e.target);
  18847. return;
  18848. }
  18849. if (/^(TABLE|IMG|HR)$/.test(e.target.nodeName)) {
  18850. e.preventDefault();
  18851. if (e.target.tagName === 'IMG') {
  18852. delayedSelect(e.target);
  18853. }
  18854. }
  18855. });
  18856. }
  18857. var throttledUpdateResizeRect = Delay.throttle(function (e) {
  18858. if (!editor.composing) {
  18859. updateResizeRect(e);
  18860. }
  18861. });
  18862. editor.on('nodechange ResizeEditor ResizeWindow drop FullscreenStateChanged', throttledUpdateResizeRect);
  18863. editor.on('keyup compositionend', function (e) {
  18864. if (selectedElm && selectedElm.nodeName === 'TABLE') {
  18865. throttledUpdateResizeRect(e);
  18866. }
  18867. });
  18868. editor.on('hide blur', hideResizeRect);
  18869. editor.on('contextmenu longpress', contextMenuSelectImage, true);
  18870. });
  18871. editor.on('remove', unbindResizeHandleEvents);
  18872. var destroy = function () {
  18873. selectedElm = selectedElmGhost = null;
  18874. };
  18875. return {
  18876. isResizable: isResizable,
  18877. showResizeRect: showResizeRect,
  18878. hideResizeRect: hideResizeRect,
  18879. updateResizeRect: updateResizeRect,
  18880. destroy: destroy
  18881. };
  18882. };
  18883. function Dimension (name, getOffset) {
  18884. var set = function (element, h) {
  18885. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  18886. throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
  18887. }
  18888. var dom = element.dom();
  18889. if (isSupported(dom)) {
  18890. dom.style[name] = h + 'px';
  18891. }
  18892. };
  18893. var get = function (element) {
  18894. var r = getOffset(element);
  18895. if (r <= 0 || r === null) {
  18896. var css = get$2(element, name);
  18897. return parseFloat(css) || 0;
  18898. }
  18899. return r;
  18900. };
  18901. var getOuter = get;
  18902. var aggregate = function (element, properties) {
  18903. return foldl(properties, function (acc, property) {
  18904. var val = get$2(element, property);
  18905. var value = val === undefined ? 0 : parseInt(val, 10);
  18906. return isNaN(value) ? acc : acc + value;
  18907. }, 0);
  18908. };
  18909. var max = function (element, value, properties) {
  18910. var cumulativeInclusions = aggregate(element, properties);
  18911. var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
  18912. return absoluteMax;
  18913. };
  18914. return {
  18915. set: set,
  18916. get: get,
  18917. getOuter: getOuter,
  18918. aggregate: aggregate,
  18919. max: max
  18920. };
  18921. }
  18922. var api$1 = Dimension('height', function (element) {
  18923. var dom = element.dom();
  18924. return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
  18925. });
  18926. var get$8 = function (element) {
  18927. return api$1.get(element);
  18928. };
  18929. var walkUp = function (navigation, doc) {
  18930. var frame = navigation.view(doc);
  18931. return frame.fold(constant([]), function (f) {
  18932. var parent = navigation.owner(f);
  18933. var rest = walkUp(navigation, parent);
  18934. return [f].concat(rest);
  18935. });
  18936. };
  18937. var pathTo = function (element, navigation) {
  18938. var d = navigation.owner(element);
  18939. return walkUp(navigation, d);
  18940. };
  18941. var view = function (doc) {
  18942. var element = doc.dom() === domGlobals.document ? Option.none() : Option.from(doc.dom().defaultView.frameElement);
  18943. return element.map(Element.fromDom);
  18944. };
  18945. var owner$1 = function (element) {
  18946. return owner(element);
  18947. };
  18948. var Navigation = /*#__PURE__*/Object.freeze({
  18949. view: view,
  18950. owner: owner$1
  18951. });
  18952. var find$4 = function (element) {
  18953. var doc = Element.fromDom(domGlobals.document);
  18954. var scroll = get$3(doc);
  18955. var frames = pathTo(element, Navigation);
  18956. var offset = viewport(element);
  18957. var r = foldr(frames, function (b, a) {
  18958. var loc = viewport(a);
  18959. return {
  18960. left: b.left + loc.left(),
  18961. top: b.top + loc.top()
  18962. };
  18963. }, {
  18964. left: 0,
  18965. top: 0
  18966. });
  18967. return Position$1(r.left + offset.left() + scroll.left(), r.top + offset.top() + scroll.top());
  18968. };
  18969. var excludeFromDescend = function (element) {
  18970. return name(element) === 'textarea';
  18971. };
  18972. var descend = function (element, offset) {
  18973. var children$1 = children(element);
  18974. if (children$1.length === 0 || excludeFromDescend(element)) {
  18975. return {
  18976. element: element,
  18977. offset: offset
  18978. };
  18979. } else if (offset < children$1.length && !excludeFromDescend(children$1[offset])) {
  18980. return {
  18981. element: children$1[offset],
  18982. offset: 0
  18983. };
  18984. } else {
  18985. var last = children$1[children$1.length - 1];
  18986. if (excludeFromDescend(last)) {
  18987. return {
  18988. element: element,
  18989. offset: offset
  18990. };
  18991. } else {
  18992. if (name(last) === 'img') {
  18993. return {
  18994. element: last,
  18995. offset: 1
  18996. };
  18997. } else if (isText$1(last)) {
  18998. return {
  18999. element: last,
  19000. offset: get$6(last).length
  19001. };
  19002. } else {
  19003. return {
  19004. element: last,
  19005. offset: children(last).length
  19006. };
  19007. }
  19008. }
  19009. }
  19010. };
  19011. var markerInfo = function (element, cleanupFun) {
  19012. var pos = absolute(element);
  19013. var height = get$8(element);
  19014. return {
  19015. element: element,
  19016. bottom: pos.top() + height,
  19017. pos: pos,
  19018. cleanup: cleanupFun
  19019. };
  19020. };
  19021. var createMarker = function (element, offset) {
  19022. var startPoint = descend(element, offset);
  19023. var span = Element.fromHtml('<span data-mce-bogus="all">' + Zwsp.ZWSP + '</span>');
  19024. before(startPoint.element, span);
  19025. return markerInfo(span, function () {
  19026. return remove$1(span);
  19027. });
  19028. };
  19029. var elementMarker = function (element) {
  19030. return markerInfo(Element.fromDom(element), noop);
  19031. };
  19032. var withMarker = function (editor, f, rng, alignToTop) {
  19033. preserveWith(editor, function (_s, _e) {
  19034. return applyWithMarker(editor, f, rng, alignToTop);
  19035. }, rng);
  19036. };
  19037. var applyWithMarker = function (editor, f, rng, alignToTop) {
  19038. var body = Element.fromDom(editor.getBody());
  19039. var doc = Element.fromDom(editor.getDoc());
  19040. reflow(body);
  19041. var scrollTop = get$3(doc).top();
  19042. var marker = createMarker(Element.fromDom(rng.startContainer), rng.startOffset);
  19043. f(doc, scrollTop, marker, alignToTop);
  19044. marker.cleanup();
  19045. };
  19046. var withElement = function (editor, element, f, alignToTop) {
  19047. var doc = Element.fromDom(editor.getDoc());
  19048. var scrollTop = get$3(doc).top();
  19049. f(doc, scrollTop, element, alignToTop);
  19050. };
  19051. var preserveWith = function (editor, f, rng) {
  19052. var startElement = rng.startContainer;
  19053. var startOffset = rng.startOffset;
  19054. var endElement = rng.endContainer;
  19055. var endOffset = rng.endOffset;
  19056. f(Element.fromDom(startElement), Element.fromDom(endElement));
  19057. var newRng = editor.dom.createRng();
  19058. newRng.setStart(startElement, startOffset);
  19059. newRng.setEnd(endElement, endOffset);
  19060. editor.selection.setRng(rng);
  19061. };
  19062. var fireScrollIntoViewEvent = function (editor, elm, alignToTop) {
  19063. var scrollEvent = editor.fire('ScrollIntoView', {
  19064. elm: elm,
  19065. alignToTop: alignToTop
  19066. });
  19067. return scrollEvent.isDefaultPrevented();
  19068. };
  19069. var scrollTo = function (marker, viewHeight, alignToTop, doc) {
  19070. var pos = marker.pos;
  19071. if (alignToTop) {
  19072. to(pos.left(), pos.top(), doc);
  19073. } else {
  19074. var y = pos.top() - viewHeight + (marker.bottom - pos.top());
  19075. to(pos.left(), y, doc);
  19076. }
  19077. };
  19078. var intoWindowIfNeeded = function (doc, scrollTop, viewHeight, marker, alignToTop) {
  19079. if (marker.pos.top() < scrollTop) {
  19080. scrollTo(marker, viewHeight, alignToTop !== false, doc);
  19081. } else if (marker.bottom > viewHeight + scrollTop) {
  19082. scrollTo(marker, viewHeight, alignToTop === true, doc);
  19083. }
  19084. };
  19085. var intoWindow = function (doc, scrollTop, marker, alignToTop) {
  19086. var viewHeight = doc.dom().defaultView.innerHeight;
  19087. intoWindowIfNeeded(doc, scrollTop, viewHeight, marker, alignToTop);
  19088. };
  19089. var intoFrame = function (editor, doc, scrollTop, marker, alignToTop) {
  19090. var frameViewHeight = doc.dom().defaultView.innerHeight;
  19091. intoWindowIfNeeded(doc, scrollTop, frameViewHeight, marker, alignToTop);
  19092. var op = find$4(marker.element);
  19093. var viewportBounds = getBounds(domGlobals.window);
  19094. if (op.top() < viewportBounds.y()) {
  19095. intoView(marker.element, alignToTop !== false);
  19096. } else if (op.top() > viewportBounds.bottom()) {
  19097. intoView(marker.element, alignToTop === true);
  19098. }
  19099. };
  19100. var rangeIntoWindow = function (editor, rng, alignToTop) {
  19101. return withMarker(editor, curry(intoWindow), rng, alignToTop);
  19102. };
  19103. var elementIntoWindow = function (editor, element, alignToTop) {
  19104. return withElement(editor, elementMarker(element), curry(intoWindow), alignToTop);
  19105. };
  19106. var rangeIntoFrame = function (editor, rng, alignToTop) {
  19107. return withMarker(editor, curry(intoFrame, editor), rng, alignToTop);
  19108. };
  19109. var elementIntoFrame = function (editor, element, alignToTop) {
  19110. return withElement(editor, elementMarker(element), curry(intoFrame, editor), alignToTop);
  19111. };
  19112. var elementIntoView = function (editor, element, alignToTop) {
  19113. if (fireScrollIntoViewEvent(editor, element, alignToTop)) {
  19114. return;
  19115. }
  19116. var scroller = editor.inline ? elementIntoWindow : elementIntoFrame;
  19117. scroller(editor, element, alignToTop);
  19118. };
  19119. var rangeIntoView = function (editor, rng, alignToTop) {
  19120. var scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame;
  19121. scroller(editor, rng, alignToTop);
  19122. };
  19123. var ScrollIntoView = {
  19124. scrollElementIntoView: elementIntoView,
  19125. scrollRangeIntoView: rangeIntoView
  19126. };
  19127. var hasCeProperty = function (node) {
  19128. return NodeType.isContentEditableTrue(node) || NodeType.isContentEditableFalse(node);
  19129. };
  19130. var findParent = function (node, rootNode, predicate) {
  19131. while (node && node !== rootNode) {
  19132. if (predicate(node)) {
  19133. return node;
  19134. }
  19135. node = node.parentNode;
  19136. }
  19137. return null;
  19138. };
  19139. var findClosestIeRange = function (clientX, clientY, doc) {
  19140. var element, rng, rects;
  19141. element = doc.elementFromPoint(clientX, clientY);
  19142. rng = doc.body.createTextRange();
  19143. if (!element || element.tagName === 'HTML') {
  19144. element = doc.body;
  19145. }
  19146. rng.moveToElementText(element);
  19147. rects = Tools.toArray(rng.getClientRects());
  19148. rects = rects.sort(function (a, b) {
  19149. a = Math.abs(Math.max(a.top - clientY, a.bottom - clientY));
  19150. b = Math.abs(Math.max(b.top - clientY, b.bottom - clientY));
  19151. return a - b;
  19152. });
  19153. if (rects.length > 0) {
  19154. clientY = (rects[0].bottom + rects[0].top) / 2;
  19155. try {
  19156. rng.moveToPoint(clientX, clientY);
  19157. rng.collapse(true);
  19158. return rng;
  19159. } catch (ex) {
  19160. }
  19161. }
  19162. return null;
  19163. };
  19164. var moveOutOfContentEditableFalse = function (rng, rootNode) {
  19165. var parentElement = rng && rng.parentElement ? rng.parentElement() : null;
  19166. return NodeType.isContentEditableFalse(findParent(parentElement, rootNode, hasCeProperty)) ? null : rng;
  19167. };
  19168. var fromPoint$1 = function (clientX, clientY, doc) {
  19169. var rng, point;
  19170. var pointDoc = doc;
  19171. if (pointDoc.caretPositionFromPoint) {
  19172. point = pointDoc.caretPositionFromPoint(clientX, clientY);
  19173. if (point) {
  19174. rng = doc.createRange();
  19175. rng.setStart(point.offsetNode, point.offset);
  19176. rng.collapse(true);
  19177. }
  19178. } else if (doc.caretRangeFromPoint) {
  19179. rng = doc.caretRangeFromPoint(clientX, clientY);
  19180. } else if (pointDoc.body.createTextRange) {
  19181. rng = pointDoc.body.createTextRange();
  19182. try {
  19183. rng.moveToPoint(clientX, clientY);
  19184. rng.collapse(true);
  19185. } catch (ex) {
  19186. rng = findClosestIeRange(clientX, clientY, doc);
  19187. }
  19188. return moveOutOfContentEditableFalse(rng, doc.body);
  19189. }
  19190. return rng;
  19191. };
  19192. var CaretRangeFromPoint = { fromPoint: fromPoint$1 };
  19193. var processRanges = function (editor, ranges) {
  19194. return map(ranges, function (range) {
  19195. var evt = editor.fire('GetSelectionRange', { range: range });
  19196. return evt.range !== range ? evt.range : range;
  19197. });
  19198. };
  19199. var EventProcessRanges = { processRanges: processRanges };
  19200. var fromElements = function (elements, scope) {
  19201. var doc = scope || domGlobals.document;
  19202. var fragment = doc.createDocumentFragment();
  19203. each(elements, function (element) {
  19204. fragment.appendChild(element.dom());
  19205. });
  19206. return Element.fromDom(fragment);
  19207. };
  19208. var tableModel = Immutable('element', 'width', 'rows');
  19209. var tableRow = Immutable('element', 'cells');
  19210. var cellPosition = Immutable('x', 'y');
  19211. var getSpan = function (td, key) {
  19212. var value = parseInt(get$1(td, key), 10);
  19213. return isNaN(value) ? 1 : value;
  19214. };
  19215. var fillout = function (table, x, y, tr, td) {
  19216. var rowspan = getSpan(td, 'rowspan');
  19217. var colspan = getSpan(td, 'colspan');
  19218. var rows = table.rows();
  19219. for (var y2 = y; y2 < y + rowspan; y2++) {
  19220. if (!rows[y2]) {
  19221. rows[y2] = tableRow(deep(tr), []);
  19222. }
  19223. for (var x2 = x; x2 < x + colspan; x2++) {
  19224. var cells = rows[y2].cells();
  19225. cells[x2] = y2 === y && x2 === x ? td : shallow(td);
  19226. }
  19227. }
  19228. };
  19229. var cellExists = function (table, x, y) {
  19230. var rows = table.rows();
  19231. var cells = rows[y] ? rows[y].cells() : [];
  19232. return !!cells[x];
  19233. };
  19234. var skipCellsX = function (table, x, y) {
  19235. while (cellExists(table, x, y)) {
  19236. x++;
  19237. }
  19238. return x;
  19239. };
  19240. var getWidth = function (rows) {
  19241. return foldl(rows, function (acc, row) {
  19242. return row.cells().length > acc ? row.cells().length : acc;
  19243. }, 0);
  19244. };
  19245. var findElementPos = function (table, element) {
  19246. var rows = table.rows();
  19247. for (var y = 0; y < rows.length; y++) {
  19248. var cells = rows[y].cells();
  19249. for (var x = 0; x < cells.length; x++) {
  19250. if (eq(cells[x], element)) {
  19251. return Option.some(cellPosition(x, y));
  19252. }
  19253. }
  19254. }
  19255. return Option.none();
  19256. };
  19257. var extractRows = function (table, sx, sy, ex, ey) {
  19258. var newRows = [];
  19259. var rows = table.rows();
  19260. for (var y = sy; y <= ey; y++) {
  19261. var cells = rows[y].cells();
  19262. var slice = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1);
  19263. newRows.push(tableRow(rows[y].element(), slice));
  19264. }
  19265. return newRows;
  19266. };
  19267. var subTable = function (table, startPos, endPos) {
  19268. var sx = startPos.x(), sy = startPos.y();
  19269. var ex = endPos.x(), ey = endPos.y();
  19270. var newRows = sy < ey ? extractRows(table, sx, sy, ex, ey) : extractRows(table, sx, ey, ex, sy);
  19271. return tableModel(table.element(), getWidth(newRows), newRows);
  19272. };
  19273. var createDomTable = function (table, rows) {
  19274. var tableElement = shallow(table.element());
  19275. var tableBody = Element.fromTag('tbody');
  19276. append$1(tableBody, rows);
  19277. append(tableElement, tableBody);
  19278. return tableElement;
  19279. };
  19280. var modelRowsToDomRows = function (table) {
  19281. return map(table.rows(), function (row) {
  19282. var cells = map(row.cells(), function (cell) {
  19283. var td = deep(cell);
  19284. remove(td, 'colspan');
  19285. remove(td, 'rowspan');
  19286. return td;
  19287. });
  19288. var tr = shallow(row.element());
  19289. append$1(tr, cells);
  19290. return tr;
  19291. });
  19292. };
  19293. var fromDom$1 = function (tableElm) {
  19294. var table = tableModel(shallow(tableElm), 0, []);
  19295. each(descendants$1(tableElm, 'tr'), function (tr, y) {
  19296. each(descendants$1(tr, 'td,th'), function (td, x) {
  19297. fillout(table, skipCellsX(table, x, y), y, tr, td);
  19298. });
  19299. });
  19300. return tableModel(table.element(), getWidth(table.rows()), table.rows());
  19301. };
  19302. var toDom = function (table) {
  19303. return createDomTable(table, modelRowsToDomRows(table));
  19304. };
  19305. var subsection = function (table, startElement, endElement) {
  19306. return findElementPos(table, startElement).bind(function (startPos) {
  19307. return findElementPos(table, endElement).map(function (endPos) {
  19308. return subTable(table, startPos, endPos);
  19309. });
  19310. });
  19311. };
  19312. var SimpleTableModel = {
  19313. fromDom: fromDom$1,
  19314. toDom: toDom,
  19315. subsection: subsection
  19316. };
  19317. var getRanges = function (selection) {
  19318. var ranges = [];
  19319. if (selection) {
  19320. for (var i = 0; i < selection.rangeCount; i++) {
  19321. ranges.push(selection.getRangeAt(i));
  19322. }
  19323. }
  19324. return ranges;
  19325. };
  19326. var getSelectedNodes = function (ranges) {
  19327. return bind(ranges, function (range) {
  19328. var node = getSelectedNode(range);
  19329. return node ? [Element.fromDom(node)] : [];
  19330. });
  19331. };
  19332. var hasMultipleRanges = function (selection) {
  19333. return getRanges(selection).length > 1;
  19334. };
  19335. var MultiRange = {
  19336. getRanges: getRanges,
  19337. getSelectedNodes: getSelectedNodes,
  19338. hasMultipleRanges: hasMultipleRanges
  19339. };
  19340. var getCellsFromRanges = function (ranges) {
  19341. return filter(MultiRange.getSelectedNodes(ranges), isTableCell);
  19342. };
  19343. var getCellsFromElement = function (elm) {
  19344. return descendants$1(elm, 'td[data-mce-selected],th[data-mce-selected]');
  19345. };
  19346. var getCellsFromElementOrRanges = function (ranges, element) {
  19347. var selectedCells = getCellsFromElement(element);
  19348. var rangeCells = getCellsFromRanges(ranges);
  19349. return selectedCells.length > 0 ? selectedCells : rangeCells;
  19350. };
  19351. var getCellsFromEditor = function (editor) {
  19352. return getCellsFromElementOrRanges(MultiRange.getRanges(editor.selection.getSel()), Element.fromDom(editor.getBody()));
  19353. };
  19354. var TableCellSelection = {
  19355. getCellsFromRanges: getCellsFromRanges,
  19356. getCellsFromElement: getCellsFromElement,
  19357. getCellsFromElementOrRanges: getCellsFromElementOrRanges,
  19358. getCellsFromEditor: getCellsFromEditor
  19359. };
  19360. var findParentListContainer = function (parents) {
  19361. return find(parents, function (elm) {
  19362. return name(elm) === 'ul' || name(elm) === 'ol';
  19363. });
  19364. };
  19365. var getFullySelectedListWrappers = function (parents, rng) {
  19366. return find(parents, function (elm) {
  19367. return name(elm) === 'li' && hasAllContentsSelected(elm, rng);
  19368. }).fold(constant([]), function (li) {
  19369. return findParentListContainer(parents).map(function (listCont) {
  19370. return [
  19371. Element.fromTag('li'),
  19372. Element.fromTag(name(listCont))
  19373. ];
  19374. }).getOr([]);
  19375. });
  19376. };
  19377. var wrap$3 = function (innerElm, elms) {
  19378. var wrapped = foldl(elms, function (acc, elm) {
  19379. append(elm, acc);
  19380. return elm;
  19381. }, innerElm);
  19382. return elms.length > 0 ? fromElements([wrapped]) : wrapped;
  19383. };
  19384. var directListWrappers = function (commonAnchorContainer) {
  19385. if (isListItem(commonAnchorContainer)) {
  19386. return parent(commonAnchorContainer).filter(isList).fold(constant([]), function (listElm) {
  19387. return [
  19388. commonAnchorContainer,
  19389. listElm
  19390. ];
  19391. });
  19392. } else {
  19393. return isList(commonAnchorContainer) ? [commonAnchorContainer] : [];
  19394. }
  19395. };
  19396. var getWrapElements = function (rootNode, rng) {
  19397. var commonAnchorContainer = Element.fromDom(rng.commonAncestorContainer);
  19398. var parents = Parents.parentsAndSelf(commonAnchorContainer, rootNode);
  19399. var wrapElements = filter(parents, function (elm) {
  19400. return isInline(elm) || isHeading(elm);
  19401. });
  19402. var listWrappers = getFullySelectedListWrappers(parents, rng);
  19403. var allWrappers = wrapElements.concat(listWrappers.length ? listWrappers : directListWrappers(commonAnchorContainer));
  19404. return map(allWrappers, shallow);
  19405. };
  19406. var emptyFragment = function () {
  19407. return fromElements([]);
  19408. };
  19409. var getFragmentFromRange = function (rootNode, rng) {
  19410. return wrap$3(Element.fromDom(rng.cloneContents()), getWrapElements(rootNode, rng));
  19411. };
  19412. var getParentTable = function (rootElm, cell) {
  19413. return ancestor$1(cell, 'table', curry(eq, rootElm));
  19414. };
  19415. var getTableFragment = function (rootNode, selectedTableCells) {
  19416. return getParentTable(rootNode, selectedTableCells[0]).bind(function (tableElm) {
  19417. var firstCell = selectedTableCells[0];
  19418. var lastCell = selectedTableCells[selectedTableCells.length - 1];
  19419. var fullTableModel = SimpleTableModel.fromDom(tableElm);
  19420. return SimpleTableModel.subsection(fullTableModel, firstCell, lastCell).map(function (sectionedTableModel) {
  19421. return fromElements([SimpleTableModel.toDom(sectionedTableModel)]);
  19422. });
  19423. }).getOrThunk(emptyFragment);
  19424. };
  19425. var getSelectionFragment = function (rootNode, ranges) {
  19426. return ranges.length > 0 && ranges[0].collapsed ? emptyFragment() : getFragmentFromRange(rootNode, ranges[0]);
  19427. };
  19428. var read$2 = function (rootNode, ranges) {
  19429. var selectedCells = TableCellSelection.getCellsFromElementOrRanges(ranges, rootNode);
  19430. return selectedCells.length > 0 ? getTableFragment(rootNode, selectedCells) : getSelectionFragment(rootNode, ranges);
  19431. };
  19432. var FragmentReader = { read: read$2 };
  19433. var getTextContent = function (editor) {
  19434. return Option.from(editor.selection.getRng()).map(function (rng) {
  19435. var bin = editor.dom.add(editor.getBody(), 'div', {
  19436. 'data-mce-bogus': 'all',
  19437. 'style': 'overflow: hidden; opacity: 0;'
  19438. }, rng.cloneContents());
  19439. var text = Zwsp.trim(bin.innerText);
  19440. editor.dom.remove(bin);
  19441. return text;
  19442. }).getOr('');
  19443. };
  19444. var getHtmlContent = function (editor, args) {
  19445. var rng = editor.selection.getRng(), tmpElm = editor.dom.create('body');
  19446. var sel = editor.selection.getSel();
  19447. var fragment;
  19448. var ranges = EventProcessRanges.processRanges(editor, MultiRange.getRanges(sel));
  19449. fragment = args.contextual ? FragmentReader.read(Element.fromDom(editor.getBody()), ranges).dom() : rng.cloneContents();
  19450. if (fragment) {
  19451. tmpElm.appendChild(fragment);
  19452. }
  19453. return editor.selection.serializer.serialize(tmpElm, args);
  19454. };
  19455. var getContent$1 = function (editor, args) {
  19456. if (args === void 0) {
  19457. args = {};
  19458. }
  19459. args.get = true;
  19460. args.format = args.format || 'html';
  19461. args.selection = true;
  19462. args = editor.fire('BeforeGetContent', args);
  19463. if (args.isDefaultPrevented()) {
  19464. editor.fire('GetContent', args);
  19465. return args.content;
  19466. }
  19467. if (args.format === 'text') {
  19468. return getTextContent(editor);
  19469. } else {
  19470. args.getInner = true;
  19471. var content = getHtmlContent(editor, args);
  19472. if (args.format === 'tree') {
  19473. return content;
  19474. } else {
  19475. args.content = editor.selection.isCollapsed() ? '' : content;
  19476. editor.fire('GetContent', args);
  19477. return args.content;
  19478. }
  19479. }
  19480. };
  19481. var GetSelectionContent = { getContent: getContent$1 };
  19482. var findParent$1 = function (node, rootNode, predicate) {
  19483. while (node && node !== rootNode) {
  19484. if (predicate(node)) {
  19485. return node;
  19486. }
  19487. node = node.parentNode;
  19488. }
  19489. return null;
  19490. };
  19491. var hasParent = function (node, rootNode, predicate) {
  19492. return findParent$1(node, rootNode, predicate) !== null;
  19493. };
  19494. var hasParentWithName = function (node, rootNode, name) {
  19495. return hasParent(node, rootNode, function (node) {
  19496. return node.nodeName === name;
  19497. });
  19498. };
  19499. var isTable$3 = function (node) {
  19500. return node && node.nodeName === 'TABLE';
  19501. };
  19502. var isTableCell$3 = function (node) {
  19503. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
  19504. };
  19505. var isCeFalseCaretContainer = function (node, rootNode) {
  19506. return isCaretContainer(node) && hasParent(node, rootNode, isCaretNode) === false;
  19507. };
  19508. var hasBrBeforeAfter = function (dom, node, left) {
  19509. var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || dom.getRoot());
  19510. while (node = walker[left ? 'prev' : 'next']()) {
  19511. if (NodeType.isBr(node)) {
  19512. return true;
  19513. }
  19514. }
  19515. };
  19516. var isPrevNode = function (node, name) {
  19517. return node.previousSibling && node.previousSibling.nodeName === name;
  19518. };
  19519. var hasContentEditableFalseParent = function (body, node) {
  19520. while (node && node !== body) {
  19521. if (NodeType.isContentEditableFalse(node)) {
  19522. return true;
  19523. }
  19524. node = node.parentNode;
  19525. }
  19526. return false;
  19527. };
  19528. var findTextNodeRelative = function (dom, isAfterNode, collapsed, left, startNode) {
  19529. var lastInlineElement;
  19530. var body = dom.getRoot();
  19531. var node;
  19532. var nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  19533. var parentBlockContainer = dom.getParent(startNode.parentNode, dom.isBlock) || body;
  19534. if (left && NodeType.isBr(startNode) && isAfterNode && dom.isEmpty(parentBlockContainer)) {
  19535. return Option.some(CaretPosition(startNode.parentNode, dom.nodeIndex(startNode)));
  19536. }
  19537. var walker = new TreeWalker(startNode, parentBlockContainer);
  19538. while (node = walker[left ? 'prev' : 'next']()) {
  19539. if (dom.getContentEditableParent(node) === 'false' || isCeFalseCaretContainer(node, body)) {
  19540. return Option.none();
  19541. }
  19542. if (NodeType.isText(node) && node.nodeValue.length > 0) {
  19543. if (hasParentWithName(node, body, 'A') === false) {
  19544. return Option.some(CaretPosition(node, left ? node.nodeValue.length : 0));
  19545. }
  19546. return Option.none();
  19547. }
  19548. if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  19549. return Option.none();
  19550. }
  19551. lastInlineElement = node;
  19552. }
  19553. if (collapsed && lastInlineElement) {
  19554. return Option.some(CaretPosition(lastInlineElement, 0));
  19555. }
  19556. return Option.none();
  19557. };
  19558. var normalizeEndPoint = function (dom, collapsed, start, rng) {
  19559. var container, offset;
  19560. var body = dom.getRoot();
  19561. var node, nonEmptyElementsMap;
  19562. var directionLeft, isAfterNode, normalized = false;
  19563. container = rng[(start ? 'start' : 'end') + 'Container'];
  19564. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  19565. isAfterNode = NodeType.isElement(container) && offset === container.childNodes.length;
  19566. nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  19567. directionLeft = start;
  19568. if (isCaretContainer(container)) {
  19569. return Option.none();
  19570. }
  19571. if (NodeType.isElement(container) && offset > container.childNodes.length - 1) {
  19572. directionLeft = false;
  19573. }
  19574. if (NodeType.isDocument(container)) {
  19575. container = body;
  19576. offset = 0;
  19577. }
  19578. if (container === body) {
  19579. if (directionLeft) {
  19580. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  19581. if (node) {
  19582. if (isCaretContainer(node)) {
  19583. return Option.none();
  19584. }
  19585. if (nonEmptyElementsMap[node.nodeName] || isTable$3(node)) {
  19586. return Option.none();
  19587. }
  19588. }
  19589. }
  19590. if (container.hasChildNodes()) {
  19591. offset = Math.min(!directionLeft && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1);
  19592. container = container.childNodes[offset];
  19593. offset = NodeType.isText(container) && isAfterNode ? container.data.length : 0;
  19594. if (!collapsed && container === body.lastChild && isTable$3(container)) {
  19595. return Option.none();
  19596. }
  19597. if (hasContentEditableFalseParent(body, container) || isCaretContainer(container)) {
  19598. return Option.none();
  19599. }
  19600. if (container.hasChildNodes() && isTable$3(container) === false) {
  19601. node = container;
  19602. var walker = new TreeWalker(container, body);
  19603. do {
  19604. if (NodeType.isContentEditableFalse(node) || isCaretContainer(node)) {
  19605. normalized = false;
  19606. break;
  19607. }
  19608. if (NodeType.isText(node) && node.nodeValue.length > 0) {
  19609. offset = directionLeft ? 0 : node.nodeValue.length;
  19610. container = node;
  19611. normalized = true;
  19612. break;
  19613. }
  19614. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] && !isTableCell$3(node)) {
  19615. offset = dom.nodeIndex(node);
  19616. container = node.parentNode;
  19617. if (!directionLeft) {
  19618. offset++;
  19619. }
  19620. normalized = true;
  19621. break;
  19622. }
  19623. } while (node = directionLeft ? walker.next() : walker.prev());
  19624. }
  19625. }
  19626. }
  19627. if (collapsed) {
  19628. if (NodeType.isText(container) && offset === 0) {
  19629. findTextNodeRelative(dom, isAfterNode, collapsed, true, container).each(function (pos) {
  19630. container = pos.container();
  19631. offset = pos.offset();
  19632. normalized = true;
  19633. });
  19634. }
  19635. if (NodeType.isElement(container)) {
  19636. node = container.childNodes[offset];
  19637. if (!node) {
  19638. node = container.childNodes[offset - 1];
  19639. }
  19640. if (node && NodeType.isBr(node) && !isPrevNode(node, 'A') && !hasBrBeforeAfter(dom, node, false) && !hasBrBeforeAfter(dom, node, true)) {
  19641. findTextNodeRelative(dom, isAfterNode, collapsed, true, node).each(function (pos) {
  19642. container = pos.container();
  19643. offset = pos.offset();
  19644. normalized = true;
  19645. });
  19646. }
  19647. }
  19648. }
  19649. if (directionLeft && !collapsed && NodeType.isText(container) && offset === container.nodeValue.length) {
  19650. findTextNodeRelative(dom, isAfterNode, collapsed, false, container).each(function (pos) {
  19651. container = pos.container();
  19652. offset = pos.offset();
  19653. normalized = true;
  19654. });
  19655. }
  19656. return normalized ? Option.some(CaretPosition(container, offset)) : Option.none();
  19657. };
  19658. var normalize$2 = function (dom, rng) {
  19659. var collapsed = rng.collapsed, normRng = rng.cloneRange();
  19660. var startPos = CaretPosition.fromRangeStart(rng);
  19661. normalizeEndPoint(dom, collapsed, true, normRng).each(function (pos) {
  19662. if (!collapsed || !CaretPosition.isAbove(startPos, pos)) {
  19663. normRng.setStart(pos.container(), pos.offset());
  19664. }
  19665. });
  19666. if (!collapsed) {
  19667. normalizeEndPoint(dom, collapsed, false, normRng).each(function (pos) {
  19668. normRng.setEnd(pos.container(), pos.offset());
  19669. });
  19670. }
  19671. if (collapsed) {
  19672. normRng.collapse(true);
  19673. }
  19674. return RangeCompare.isEq(rng, normRng) ? Option.none() : Option.some(normRng);
  19675. };
  19676. var NormalizeRange = { normalize: normalize$2 };
  19677. var prependData = function (target, data) {
  19678. target.insertData(0, data);
  19679. };
  19680. var removeEmpty = function (text) {
  19681. if (text.dom().length === 0) {
  19682. remove$1(text);
  19683. return Option.none();
  19684. }
  19685. return Option.some(text);
  19686. };
  19687. var rngSetContent = function (rng, fragment) {
  19688. var firstChild = Option.from(fragment.firstChild).map(Element.fromDom);
  19689. var lastChild = Option.from(fragment.lastChild).map(Element.fromDom);
  19690. rng.deleteContents();
  19691. rng.insertNode(fragment);
  19692. var prevText = firstChild.bind(prevSibling).filter(isText$1).bind(removeEmpty);
  19693. var nextText = lastChild.bind(nextSibling).filter(isText$1).bind(removeEmpty);
  19694. lift2(prevText, firstChild.filter(isText$1), function (prev, start) {
  19695. prependData(start.dom(), prev.dom().data);
  19696. remove$1(prev);
  19697. });
  19698. lift2(nextText, lastChild.filter(isText$1), function (next, end) {
  19699. var oldLength = end.dom().length;
  19700. end.dom().appendData(next.dom().data);
  19701. rng.setEnd(end.dom(), oldLength);
  19702. remove$1(next);
  19703. });
  19704. rng.collapse(false);
  19705. };
  19706. var setupArgs = function (args, content) {
  19707. args = args || { format: 'html' };
  19708. args.set = true;
  19709. args.selection = true;
  19710. args.content = content;
  19711. return args;
  19712. };
  19713. var setContent$1 = function (editor, content, args) {
  19714. args = setupArgs(args, content);
  19715. if (!args.no_events) {
  19716. args = editor.fire('BeforeSetContent', args);
  19717. if (args.isDefaultPrevented()) {
  19718. editor.fire('SetContent', args);
  19719. return;
  19720. }
  19721. }
  19722. var rng = editor.selection.getRng();
  19723. rngSetContent(rng, rng.createContextualFragment(args.content));
  19724. editor.selection.setRng(rng);
  19725. ScrollIntoView.scrollRangeIntoView(editor, rng);
  19726. if (!args.no_events) {
  19727. editor.fire('SetContent', args);
  19728. }
  19729. };
  19730. var SetSelectionContent = { setContent: setContent$1 };
  19731. var getEndpointElement = function (root, rng, start, real, resolve) {
  19732. var container = start ? rng.startContainer : rng.endContainer;
  19733. var offset = start ? rng.startOffset : rng.endOffset;
  19734. return Option.from(container).map(Element.fromDom).map(function (elm) {
  19735. return !real || !rng.collapsed ? child(elm, resolve(elm, offset)).getOr(elm) : elm;
  19736. }).bind(function (elm) {
  19737. return isElement$1(elm) ? Option.some(elm) : parent(elm);
  19738. }).map(function (elm) {
  19739. return elm.dom();
  19740. }).getOr(root);
  19741. };
  19742. var getStart$2 = function (root, rng, real) {
  19743. return getEndpointElement(root, rng, true, real, function (elm, offset) {
  19744. return Math.min(childNodesCount(elm), offset);
  19745. });
  19746. };
  19747. var getEnd = function (root, rng, real) {
  19748. return getEndpointElement(root, rng, false, real, function (elm, offset) {
  19749. return offset > 0 ? offset - 1 : offset;
  19750. });
  19751. };
  19752. var skipEmptyTextNodes = function (node, forwards) {
  19753. var orig = node;
  19754. while (node && NodeType.isText(node) && node.length === 0) {
  19755. node = forwards ? node.nextSibling : node.previousSibling;
  19756. }
  19757. return node || orig;
  19758. };
  19759. var getNode$1 = function (root, rng) {
  19760. var elm, startContainer, endContainer, startOffset, endOffset;
  19761. if (!rng) {
  19762. return root;
  19763. }
  19764. startContainer = rng.startContainer;
  19765. endContainer = rng.endContainer;
  19766. startOffset = rng.startOffset;
  19767. endOffset = rng.endOffset;
  19768. elm = rng.commonAncestorContainer;
  19769. if (!rng.collapsed) {
  19770. if (startContainer === endContainer) {
  19771. if (endOffset - startOffset < 2) {
  19772. if (startContainer.hasChildNodes()) {
  19773. elm = startContainer.childNodes[startOffset];
  19774. }
  19775. }
  19776. }
  19777. if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
  19778. if (startContainer.length === startOffset) {
  19779. startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);
  19780. } else {
  19781. startContainer = startContainer.parentNode;
  19782. }
  19783. if (endOffset === 0) {
  19784. endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);
  19785. } else {
  19786. endContainer = endContainer.parentNode;
  19787. }
  19788. if (startContainer && startContainer === endContainer) {
  19789. return startContainer;
  19790. }
  19791. }
  19792. }
  19793. if (elm && elm.nodeType === 3) {
  19794. return elm.parentNode;
  19795. }
  19796. return elm;
  19797. };
  19798. var getSelectedBlocks = function (dom, rng, startElm, endElm) {
  19799. var node, root;
  19800. var selectedBlocks = [];
  19801. root = dom.getRoot();
  19802. startElm = dom.getParent(startElm || getStart$2(root, rng, rng.collapsed), dom.isBlock);
  19803. endElm = dom.getParent(endElm || getEnd(root, rng, rng.collapsed), dom.isBlock);
  19804. if (startElm && startElm !== root) {
  19805. selectedBlocks.push(startElm);
  19806. }
  19807. if (startElm && endElm && startElm !== endElm) {
  19808. node = startElm;
  19809. var walker = new TreeWalker(startElm, root);
  19810. while ((node = walker.next()) && node !== endElm) {
  19811. if (dom.isBlock(node)) {
  19812. selectedBlocks.push(node);
  19813. }
  19814. }
  19815. }
  19816. if (endElm && startElm !== endElm && endElm !== root) {
  19817. selectedBlocks.push(endElm);
  19818. }
  19819. return selectedBlocks;
  19820. };
  19821. var select$1 = function (dom, node, content) {
  19822. return Option.from(node).map(function (node) {
  19823. var idx = dom.nodeIndex(node);
  19824. var rng = dom.createRng();
  19825. rng.setStart(node.parentNode, idx);
  19826. rng.setEnd(node.parentNode, idx + 1);
  19827. if (content) {
  19828. moveEndPoint$1(dom, rng, node, true);
  19829. moveEndPoint$1(dom, rng, node, false);
  19830. }
  19831. return rng;
  19832. });
  19833. };
  19834. var deleteFromCallbackMap = function (callbackMap, selector, callback) {
  19835. if (callbackMap && callbackMap.hasOwnProperty(selector)) {
  19836. var newCallbacks = filter(callbackMap[selector], function (cb) {
  19837. return cb !== callback;
  19838. });
  19839. if (newCallbacks.length === 0) {
  19840. delete callbackMap[selector];
  19841. } else {
  19842. callbackMap[selector] = newCallbacks;
  19843. }
  19844. }
  19845. };
  19846. function SelectorChanged (dom, editor) {
  19847. var selectorChangedData;
  19848. var currentSelectors;
  19849. return {
  19850. selectorChangedWithUnbind: function (selector, callback) {
  19851. if (!selectorChangedData) {
  19852. selectorChangedData = {};
  19853. currentSelectors = {};
  19854. editor.on('NodeChange', function (e) {
  19855. var node = e.element, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
  19856. Tools.each(selectorChangedData, function (callbacks, selector) {
  19857. Tools.each(parents, function (node) {
  19858. if (dom.is(node, selector)) {
  19859. if (!currentSelectors[selector]) {
  19860. Tools.each(callbacks, function (callback) {
  19861. callback(true, {
  19862. node: node,
  19863. selector: selector,
  19864. parents: parents
  19865. });
  19866. });
  19867. currentSelectors[selector] = callbacks;
  19868. }
  19869. matchedSelectors[selector] = callbacks;
  19870. return false;
  19871. }
  19872. });
  19873. });
  19874. Tools.each(currentSelectors, function (callbacks, selector) {
  19875. if (!matchedSelectors[selector]) {
  19876. delete currentSelectors[selector];
  19877. Tools.each(callbacks, function (callback) {
  19878. callback(false, {
  19879. node: node,
  19880. selector: selector,
  19881. parents: parents
  19882. });
  19883. });
  19884. }
  19885. });
  19886. });
  19887. }
  19888. if (!selectorChangedData[selector]) {
  19889. selectorChangedData[selector] = [];
  19890. }
  19891. selectorChangedData[selector].push(callback);
  19892. return {
  19893. unbind: function () {
  19894. deleteFromCallbackMap(selectorChangedData, selector, callback);
  19895. deleteFromCallbackMap(currentSelectors, selector, callback);
  19896. }
  19897. };
  19898. }
  19899. };
  19900. }
  19901. var isNativeIeSelection = function (rng) {
  19902. return !!rng.select;
  19903. };
  19904. var isAttachedToDom = function (node) {
  19905. return !!(node && node.ownerDocument) && contains$2(Element.fromDom(node.ownerDocument), Element.fromDom(node));
  19906. };
  19907. var isValidRange = function (rng) {
  19908. if (!rng) {
  19909. return false;
  19910. } else if (isNativeIeSelection(rng)) {
  19911. return true;
  19912. } else {
  19913. return isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer);
  19914. }
  19915. };
  19916. var Selection$1 = function (dom, win, serializer, editor) {
  19917. var bookmarkManager;
  19918. var controlSelection;
  19919. var selectedRange;
  19920. var explicitRange;
  19921. var selectorChangedWithUnbind = SelectorChanged(dom, editor).selectorChangedWithUnbind;
  19922. var setCursorLocation = function (node, offset) {
  19923. var rng = dom.createRng();
  19924. if (!node) {
  19925. moveEndPoint$1(dom, rng, editor.getBody(), true);
  19926. setRng(rng);
  19927. } else {
  19928. rng.setStart(node, offset);
  19929. rng.setEnd(node, offset);
  19930. setRng(rng);
  19931. collapse(false);
  19932. }
  19933. };
  19934. var getContent = function (args) {
  19935. return GetSelectionContent.getContent(editor, args);
  19936. };
  19937. var setContent = function (content, args) {
  19938. return SetSelectionContent.setContent(editor, content, args);
  19939. };
  19940. var getStart = function (real) {
  19941. return getStart$2(editor.getBody(), getRng(), real);
  19942. };
  19943. var getEnd$1 = function (real) {
  19944. return getEnd(editor.getBody(), getRng(), real);
  19945. };
  19946. var getBookmark = function (type, normalized) {
  19947. return bookmarkManager.getBookmark(type, normalized);
  19948. };
  19949. var moveToBookmark = function (bookmark) {
  19950. return bookmarkManager.moveToBookmark(bookmark);
  19951. };
  19952. var select = function (node, content) {
  19953. select$1(dom, node, content).each(setRng);
  19954. return node;
  19955. };
  19956. var isCollapsed = function () {
  19957. var rng = getRng(), sel = getSel();
  19958. if (!rng || rng.item) {
  19959. return false;
  19960. }
  19961. if (rng.compareEndPoints) {
  19962. return rng.compareEndPoints('StartToEnd', rng) === 0;
  19963. }
  19964. return !sel || rng.collapsed;
  19965. };
  19966. var collapse = function (toStart) {
  19967. var rng = getRng();
  19968. rng.collapse(!!toStart);
  19969. setRng(rng);
  19970. };
  19971. var getSel = function () {
  19972. return win.getSelection ? win.getSelection() : win.document.selection;
  19973. };
  19974. var getRng = function () {
  19975. var selection, rng, elm, doc;
  19976. var tryCompareBoundaryPoints = function (how, sourceRange, destinationRange) {
  19977. try {
  19978. return sourceRange.compareBoundaryPoints(how, destinationRange);
  19979. } catch (ex) {
  19980. return -1;
  19981. }
  19982. };
  19983. if (!win) {
  19984. return null;
  19985. }
  19986. doc = win.document;
  19987. if (typeof doc === 'undefined' || doc === null) {
  19988. return null;
  19989. }
  19990. if (editor.bookmark !== undefined && EditorFocus.hasFocus(editor) === false) {
  19991. var bookmark = SelectionBookmark.getRng(editor);
  19992. if (bookmark.isSome()) {
  19993. return bookmark.map(function (r) {
  19994. return EventProcessRanges.processRanges(editor, [r])[0];
  19995. }).getOr(doc.createRange());
  19996. }
  19997. }
  19998. try {
  19999. if ((selection = getSel()) && !NodeType.isRestrictedNode(selection.anchorNode)) {
  20000. if (selection.rangeCount > 0) {
  20001. rng = selection.getRangeAt(0);
  20002. } else {
  20003. rng = selection.createRange ? selection.createRange() : doc.createRange();
  20004. }
  20005. }
  20006. } catch (ex) {
  20007. }
  20008. rng = EventProcessRanges.processRanges(editor, [rng])[0];
  20009. if (!rng) {
  20010. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  20011. }
  20012. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  20013. elm = dom.getRoot();
  20014. rng.setStart(elm, 0);
  20015. rng.setEnd(elm, 0);
  20016. }
  20017. if (selectedRange && explicitRange) {
  20018. if (tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) === 0 && tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0) {
  20019. rng = explicitRange;
  20020. } else {
  20021. selectedRange = null;
  20022. explicitRange = null;
  20023. }
  20024. }
  20025. return rng;
  20026. };
  20027. var setRng = function (rng, forward) {
  20028. var sel, node, evt;
  20029. if (!isValidRange(rng)) {
  20030. return;
  20031. }
  20032. var ieRange = isNativeIeSelection(rng) ? rng : null;
  20033. if (ieRange) {
  20034. explicitRange = null;
  20035. try {
  20036. ieRange.select();
  20037. } catch (ex) {
  20038. }
  20039. return;
  20040. }
  20041. sel = getSel();
  20042. evt = editor.fire('SetSelectionRange', {
  20043. range: rng,
  20044. forward: forward
  20045. });
  20046. rng = evt.range;
  20047. if (sel) {
  20048. explicitRange = rng;
  20049. try {
  20050. sel.removeAllRanges();
  20051. sel.addRange(rng);
  20052. } catch (ex) {
  20053. }
  20054. if (forward === false && sel.extend) {
  20055. sel.collapse(rng.endContainer, rng.endOffset);
  20056. sel.extend(rng.startContainer, rng.startOffset);
  20057. }
  20058. selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
  20059. }
  20060. if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent && !Env.ie) {
  20061. if (rng.endOffset - rng.startOffset < 2) {
  20062. if (rng.startContainer.hasChildNodes()) {
  20063. node = rng.startContainer.childNodes[rng.startOffset];
  20064. if (node && node.tagName === 'IMG') {
  20065. sel.setBaseAndExtent(rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset);
  20066. if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) {
  20067. sel.setBaseAndExtent(node, 0, node, 1);
  20068. }
  20069. }
  20070. }
  20071. }
  20072. }
  20073. editor.fire('AfterSetSelectionRange', {
  20074. range: rng,
  20075. forward: forward
  20076. });
  20077. };
  20078. var setNode = function (elm) {
  20079. setContent(dom.getOuterHTML(elm));
  20080. return elm;
  20081. };
  20082. var getNode = function () {
  20083. return getNode$1(editor.getBody(), getRng());
  20084. };
  20085. var getSelectedBlocks$1 = function (startElm, endElm) {
  20086. return getSelectedBlocks(dom, getRng(), startElm, endElm);
  20087. };
  20088. var isForward = function () {
  20089. var sel = getSel();
  20090. var anchorRange, focusRange;
  20091. if (!sel || !sel.anchorNode || !sel.focusNode) {
  20092. return true;
  20093. }
  20094. anchorRange = dom.createRng();
  20095. anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
  20096. anchorRange.collapse(true);
  20097. focusRange = dom.createRng();
  20098. focusRange.setStart(sel.focusNode, sel.focusOffset);
  20099. focusRange.collapse(true);
  20100. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  20101. };
  20102. var normalize = function () {
  20103. var rng = getRng();
  20104. var sel = getSel();
  20105. if (!MultiRange.hasMultipleRanges(sel) && hasAnyRanges(editor)) {
  20106. var normRng = NormalizeRange.normalize(dom, rng);
  20107. normRng.each(function (normRng) {
  20108. setRng(normRng, isForward());
  20109. });
  20110. return normRng.getOr(rng);
  20111. }
  20112. return rng;
  20113. };
  20114. var selectorChanged = function (selector, callback) {
  20115. selectorChangedWithUnbind(selector, callback);
  20116. return exports;
  20117. };
  20118. var getScrollContainer = function () {
  20119. var scrollContainer;
  20120. var node = dom.getRoot();
  20121. while (node && node.nodeName !== 'BODY') {
  20122. if (node.scrollHeight > node.clientHeight) {
  20123. scrollContainer = node;
  20124. break;
  20125. }
  20126. node = node.parentNode;
  20127. }
  20128. return scrollContainer;
  20129. };
  20130. var scrollIntoView = function (elm, alignToTop) {
  20131. return ScrollIntoView.scrollElementIntoView(editor, elm, alignToTop);
  20132. };
  20133. var placeCaretAt = function (clientX, clientY) {
  20134. return setRng(CaretRangeFromPoint.fromPoint(clientX, clientY, editor.getDoc()));
  20135. };
  20136. var getBoundingClientRect = function () {
  20137. var rng = getRng();
  20138. return rng.collapsed ? CaretPosition$1.fromRangeStart(rng).getClientRects()[0] : rng.getBoundingClientRect();
  20139. };
  20140. var destroy = function () {
  20141. win = selectedRange = explicitRange = null;
  20142. controlSelection.destroy();
  20143. };
  20144. var exports = {
  20145. bookmarkManager: null,
  20146. controlSelection: null,
  20147. dom: dom,
  20148. win: win,
  20149. serializer: serializer,
  20150. editor: editor,
  20151. collapse: collapse,
  20152. setCursorLocation: setCursorLocation,
  20153. getContent: getContent,
  20154. setContent: setContent,
  20155. getBookmark: getBookmark,
  20156. moveToBookmark: moveToBookmark,
  20157. select: select,
  20158. isCollapsed: isCollapsed,
  20159. isForward: isForward,
  20160. setNode: setNode,
  20161. getNode: getNode,
  20162. getSel: getSel,
  20163. setRng: setRng,
  20164. getRng: getRng,
  20165. getStart: getStart,
  20166. getEnd: getEnd$1,
  20167. getSelectedBlocks: getSelectedBlocks$1,
  20168. normalize: normalize,
  20169. selectorChanged: selectorChanged,
  20170. selectorChangedWithUnbind: selectorChangedWithUnbind,
  20171. getScrollContainer: getScrollContainer,
  20172. scrollIntoView: scrollIntoView,
  20173. placeCaretAt: placeCaretAt,
  20174. getBoundingClientRect: getBoundingClientRect,
  20175. destroy: destroy
  20176. };
  20177. bookmarkManager = BookmarkManager$1(exports);
  20178. controlSelection = ControlSelection(exports, editor);
  20179. exports.bookmarkManager = bookmarkManager;
  20180. exports.controlSelection = controlSelection;
  20181. return exports;
  20182. };
  20183. var isText$8 = NodeType.isText;
  20184. var startsWithCaretContainer$1 = function (node) {
  20185. return isText$8(node) && node.data[0] === Zwsp.ZWSP;
  20186. };
  20187. var endsWithCaretContainer$1 = function (node) {
  20188. return isText$8(node) && node.data[node.data.length - 1] === Zwsp.ZWSP;
  20189. };
  20190. var createZwsp = function (node) {
  20191. return node.ownerDocument.createTextNode(Zwsp.ZWSP);
  20192. };
  20193. var insertBefore = function (node) {
  20194. if (isText$8(node.previousSibling)) {
  20195. if (endsWithCaretContainer$1(node.previousSibling)) {
  20196. return node.previousSibling;
  20197. } else {
  20198. node.previousSibling.appendData(Zwsp.ZWSP);
  20199. return node.previousSibling;
  20200. }
  20201. } else if (isText$8(node)) {
  20202. if (startsWithCaretContainer$1(node)) {
  20203. return node;
  20204. } else {
  20205. node.insertData(0, Zwsp.ZWSP);
  20206. return node;
  20207. }
  20208. } else {
  20209. var newNode = createZwsp(node);
  20210. node.parentNode.insertBefore(newNode, node);
  20211. return newNode;
  20212. }
  20213. };
  20214. var insertAfter = function (node) {
  20215. if (isText$8(node.nextSibling)) {
  20216. if (startsWithCaretContainer$1(node.nextSibling)) {
  20217. return node.nextSibling;
  20218. } else {
  20219. node.nextSibling.insertData(0, Zwsp.ZWSP);
  20220. return node.nextSibling;
  20221. }
  20222. } else if (isText$8(node)) {
  20223. if (endsWithCaretContainer$1(node)) {
  20224. return node;
  20225. } else {
  20226. node.appendData(Zwsp.ZWSP);
  20227. return node;
  20228. }
  20229. } else {
  20230. var newNode = createZwsp(node);
  20231. if (node.nextSibling) {
  20232. node.parentNode.insertBefore(newNode, node.nextSibling);
  20233. } else {
  20234. node.parentNode.appendChild(newNode);
  20235. }
  20236. return newNode;
  20237. }
  20238. };
  20239. var insertInline$1 = function (before, node) {
  20240. return before ? insertBefore(node) : insertAfter(node);
  20241. };
  20242. var insertInlineBefore = curry(insertInline$1, true);
  20243. var insertInlineAfter = curry(insertInline$1, false);
  20244. var insertInlinePos = function (pos, before) {
  20245. if (NodeType.isText(pos.container())) {
  20246. return insertInline$1(before, pos.container());
  20247. } else {
  20248. return insertInline$1(before, pos.getNode());
  20249. }
  20250. };
  20251. var isPosCaretContainer = function (pos, caret) {
  20252. var caretNode = caret.get();
  20253. return caretNode && pos.container() === caretNode && isCaretContainerInline(caretNode);
  20254. };
  20255. var renderCaret = function (caret, location) {
  20256. return location.fold(function (element) {
  20257. CaretContainerRemove.remove(caret.get());
  20258. var text = insertInlineBefore(element);
  20259. caret.set(text);
  20260. return Option.some(CaretPosition$1(text, text.length - 1));
  20261. }, function (element) {
  20262. return CaretFinder.firstPositionIn(element).map(function (pos) {
  20263. if (!isPosCaretContainer(pos, caret)) {
  20264. CaretContainerRemove.remove(caret.get());
  20265. var text = insertInlinePos(pos, true);
  20266. caret.set(text);
  20267. return CaretPosition$1(text, 1);
  20268. } else {
  20269. return CaretPosition$1(caret.get(), 1);
  20270. }
  20271. });
  20272. }, function (element) {
  20273. return CaretFinder.lastPositionIn(element).map(function (pos) {
  20274. if (!isPosCaretContainer(pos, caret)) {
  20275. CaretContainerRemove.remove(caret.get());
  20276. var text = insertInlinePos(pos, false);
  20277. caret.set(text);
  20278. return CaretPosition$1(text, text.length - 1);
  20279. } else {
  20280. return CaretPosition$1(caret.get(), caret.get().length - 1);
  20281. }
  20282. });
  20283. }, function (element) {
  20284. CaretContainerRemove.remove(caret.get());
  20285. var text = insertInlineAfter(element);
  20286. caret.set(text);
  20287. return Option.some(CaretPosition$1(text, 1));
  20288. });
  20289. };
  20290. var BoundaryCaret = { renderCaret: renderCaret };
  20291. var strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/;
  20292. var hasStrongRtl = function (text) {
  20293. return strongRtl.test(text);
  20294. };
  20295. var isInlineTarget = function (editor, elm) {
  20296. return is(Element.fromDom(elm), Settings.getInlineBoundarySelector(editor));
  20297. };
  20298. var isRtl$1 = function (element) {
  20299. return DOMUtils$1.DOM.getStyle(element, 'direction', true) === 'rtl' || hasStrongRtl(element.textContent);
  20300. };
  20301. var findInlineParents = function (isInlineTarget, rootNode, pos) {
  20302. return filter(DOMUtils$1.DOM.getParents(pos.container(), '*', rootNode), isInlineTarget);
  20303. };
  20304. var findRootInline = function (isInlineTarget, rootNode, pos) {
  20305. var parents = findInlineParents(isInlineTarget, rootNode, pos);
  20306. return Option.from(parents[parents.length - 1]);
  20307. };
  20308. var hasSameParentBlock = function (rootNode, node1, node2) {
  20309. var block1 = getParentBlock(node1, rootNode);
  20310. var block2 = getParentBlock(node2, rootNode);
  20311. return block1 && block1 === block2;
  20312. };
  20313. var isAtZwsp = function (pos) {
  20314. return isBeforeInline(pos) || isAfterInline(pos);
  20315. };
  20316. var normalizePosition = function (forward, pos) {
  20317. if (!pos) {
  20318. return pos;
  20319. }
  20320. var container = pos.container(), offset = pos.offset();
  20321. if (forward) {
  20322. if (isCaretContainerInline(container)) {
  20323. if (NodeType.isText(container.nextSibling)) {
  20324. return CaretPosition$1(container.nextSibling, 0);
  20325. } else {
  20326. return CaretPosition$1.after(container);
  20327. }
  20328. } else {
  20329. return isBeforeInline(pos) ? CaretPosition$1(container, offset + 1) : pos;
  20330. }
  20331. } else {
  20332. if (isCaretContainerInline(container)) {
  20333. if (NodeType.isText(container.previousSibling)) {
  20334. return CaretPosition$1(container.previousSibling, container.previousSibling.data.length);
  20335. } else {
  20336. return CaretPosition$1.before(container);
  20337. }
  20338. } else {
  20339. return isAfterInline(pos) ? CaretPosition$1(container, offset - 1) : pos;
  20340. }
  20341. }
  20342. };
  20343. var normalizeForwards = curry(normalizePosition, true);
  20344. var normalizeBackwards = curry(normalizePosition, false);
  20345. var InlineUtils = {
  20346. isInlineTarget: isInlineTarget,
  20347. findRootInline: findRootInline,
  20348. isRtl: isRtl$1,
  20349. isAtZwsp: isAtZwsp,
  20350. normalizePosition: normalizePosition,
  20351. normalizeForwards: normalizeForwards,
  20352. normalizeBackwards: normalizeBackwards,
  20353. hasSameParentBlock: hasSameParentBlock
  20354. };
  20355. var evaluateUntil = function (fns, args) {
  20356. for (var i = 0; i < fns.length; i++) {
  20357. var result = fns[i].apply(null, args);
  20358. if (result.isSome()) {
  20359. return result;
  20360. }
  20361. }
  20362. return Option.none();
  20363. };
  20364. var LazyEvaluator = { evaluateUntil: evaluateUntil };
  20365. var Location = Adt.generate([
  20366. { before: ['element'] },
  20367. { start: ['element'] },
  20368. { end: ['element'] },
  20369. { after: ['element'] }
  20370. ]);
  20371. var rescope = function (rootNode, node) {
  20372. var parentBlock = getParentBlock(node, rootNode);
  20373. return parentBlock ? parentBlock : rootNode;
  20374. };
  20375. var before$4 = function (isInlineTarget, rootNode, pos) {
  20376. var nPos = InlineUtils.normalizeForwards(pos);
  20377. var scope = rescope(rootNode, nPos.container());
  20378. return InlineUtils.findRootInline(isInlineTarget, scope, nPos).fold(function () {
  20379. return CaretFinder.nextPosition(scope, nPos).bind(curry(InlineUtils.findRootInline, isInlineTarget, scope)).map(function (inline) {
  20380. return Location.before(inline);
  20381. });
  20382. }, Option.none);
  20383. };
  20384. var isNotInsideFormatCaretContainer = function (rootNode, elm) {
  20385. return getParentCaretContainer(rootNode, elm) === null;
  20386. };
  20387. var findInsideRootInline = function (isInlineTarget, rootNode, pos) {
  20388. return InlineUtils.findRootInline(isInlineTarget, rootNode, pos).filter(curry(isNotInsideFormatCaretContainer, rootNode));
  20389. };
  20390. var start$1 = function (isInlineTarget, rootNode, pos) {
  20391. var nPos = InlineUtils.normalizeBackwards(pos);
  20392. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (inline) {
  20393. var prevPos = CaretFinder.prevPosition(inline, nPos);
  20394. return prevPos.isNone() ? Option.some(Location.start(inline)) : Option.none();
  20395. });
  20396. };
  20397. var end = function (isInlineTarget, rootNode, pos) {
  20398. var nPos = InlineUtils.normalizeForwards(pos);
  20399. return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(function (inline) {
  20400. var nextPos = CaretFinder.nextPosition(inline, nPos);
  20401. return nextPos.isNone() ? Option.some(Location.end(inline)) : Option.none();
  20402. });
  20403. };
  20404. var after$3 = function (isInlineTarget, rootNode, pos) {
  20405. var nPos = InlineUtils.normalizeBackwards(pos);
  20406. var scope = rescope(rootNode, nPos.container());
  20407. return InlineUtils.findRootInline(isInlineTarget, scope, nPos).fold(function () {
  20408. return CaretFinder.prevPosition(scope, nPos).bind(curry(InlineUtils.findRootInline, isInlineTarget, scope)).map(function (inline) {
  20409. return Location.after(inline);
  20410. });
  20411. }, Option.none);
  20412. };
  20413. var isValidLocation = function (location) {
  20414. return InlineUtils.isRtl(getElement(location)) === false;
  20415. };
  20416. var readLocation = function (isInlineTarget, rootNode, pos) {
  20417. var location = LazyEvaluator.evaluateUntil([
  20418. before$4,
  20419. start$1,
  20420. end,
  20421. after$3
  20422. ], [
  20423. isInlineTarget,
  20424. rootNode,
  20425. pos
  20426. ]);
  20427. return location.filter(isValidLocation);
  20428. };
  20429. var getElement = function (location) {
  20430. return location.fold(identity, identity, identity, identity);
  20431. };
  20432. var getName = function (location) {
  20433. return location.fold(constant('before'), constant('start'), constant('end'), constant('after'));
  20434. };
  20435. var outside = function (location) {
  20436. return location.fold(Location.before, Location.before, Location.after, Location.after);
  20437. };
  20438. var inside = function (location) {
  20439. return location.fold(Location.start, Location.start, Location.end, Location.end);
  20440. };
  20441. var isEq$5 = function (location1, location2) {
  20442. return getName(location1) === getName(location2) && getElement(location1) === getElement(location2);
  20443. };
  20444. var betweenInlines = function (forward, isInlineTarget, rootNode, from, to, location) {
  20445. return lift2(InlineUtils.findRootInline(isInlineTarget, rootNode, from), InlineUtils.findRootInline(isInlineTarget, rootNode, to), function (fromInline, toInline) {
  20446. if (fromInline !== toInline && InlineUtils.hasSameParentBlock(rootNode, fromInline, toInline)) {
  20447. return Location.after(forward ? fromInline : toInline);
  20448. } else {
  20449. return location;
  20450. }
  20451. }).getOr(location);
  20452. };
  20453. var skipNoMovement = function (fromLocation, toLocation) {
  20454. return fromLocation.fold(constant(true), function (fromLocation) {
  20455. return !isEq$5(fromLocation, toLocation);
  20456. });
  20457. };
  20458. var findLocationTraverse = function (forward, isInlineTarget, rootNode, fromLocation, pos) {
  20459. var from = InlineUtils.normalizePosition(forward, pos);
  20460. var to = CaretFinder.fromPosition(forward, rootNode, from).map(curry(InlineUtils.normalizePosition, forward));
  20461. var location = to.fold(function () {
  20462. return fromLocation.map(outside);
  20463. }, function (to) {
  20464. return readLocation(isInlineTarget, rootNode, to).map(curry(betweenInlines, forward, isInlineTarget, rootNode, from, to)).filter(curry(skipNoMovement, fromLocation));
  20465. });
  20466. return location.filter(isValidLocation);
  20467. };
  20468. var findLocationSimple = function (forward, location) {
  20469. if (forward) {
  20470. return location.fold(compose(Option.some, Location.start), Option.none, compose(Option.some, Location.after), Option.none);
  20471. } else {
  20472. return location.fold(Option.none, compose(Option.some, Location.before), Option.none, compose(Option.some, Location.end));
  20473. }
  20474. };
  20475. var findLocation = function (forward, isInlineTarget, rootNode, pos) {
  20476. var from = InlineUtils.normalizePosition(forward, pos);
  20477. var fromLocation = readLocation(isInlineTarget, rootNode, from);
  20478. return readLocation(isInlineTarget, rootNode, from).bind(curry(findLocationSimple, forward)).orThunk(function () {
  20479. return findLocationTraverse(forward, isInlineTarget, rootNode, fromLocation, pos);
  20480. });
  20481. };
  20482. var BoundaryLocation = {
  20483. readLocation: readLocation,
  20484. findLocation: findLocation,
  20485. prevLocation: curry(findLocation, false),
  20486. nextLocation: curry(findLocation, true),
  20487. getElement: getElement,
  20488. outside: outside,
  20489. inside: inside
  20490. };
  20491. var hasSelectionModifyApi = function (editor) {
  20492. return isFunction(editor.selection.getSel().modify);
  20493. };
  20494. var moveRel = function (forward, selection, pos) {
  20495. var delta = forward ? 1 : -1;
  20496. selection.setRng(CaretPosition$1(pos.container(), pos.offset() + delta).toRange());
  20497. selection.getSel().modify('move', forward ? 'forward' : 'backward', 'word');
  20498. return true;
  20499. };
  20500. var moveByWord = function (forward, editor) {
  20501. var rng = editor.selection.getRng();
  20502. var pos = forward ? CaretPosition$1.fromRangeEnd(rng) : CaretPosition$1.fromRangeStart(rng);
  20503. if (!hasSelectionModifyApi(editor)) {
  20504. return false;
  20505. } else if (forward && isBeforeInline(pos)) {
  20506. return moveRel(true, editor.selection, pos);
  20507. } else if (!forward && isAfterInline(pos)) {
  20508. return moveRel(false, editor.selection, pos);
  20509. } else {
  20510. return false;
  20511. }
  20512. };
  20513. var WordSelection = {
  20514. hasSelectionModifyApi: hasSelectionModifyApi,
  20515. moveByWord: moveByWord
  20516. };
  20517. var setCaretPosition = function (editor, pos) {
  20518. var rng = editor.dom.createRng();
  20519. rng.setStart(pos.container(), pos.offset());
  20520. rng.setEnd(pos.container(), pos.offset());
  20521. editor.selection.setRng(rng);
  20522. };
  20523. var isFeatureEnabled = function (editor) {
  20524. return editor.settings.inline_boundaries !== false;
  20525. };
  20526. var setSelected = function (state, elm) {
  20527. if (state) {
  20528. elm.setAttribute('data-mce-selected', 'inline-boundary');
  20529. } else {
  20530. elm.removeAttribute('data-mce-selected');
  20531. }
  20532. };
  20533. var renderCaretLocation = function (editor, caret, location) {
  20534. return BoundaryCaret.renderCaret(caret, location).map(function (pos) {
  20535. setCaretPosition(editor, pos);
  20536. return location;
  20537. });
  20538. };
  20539. var findLocation$1 = function (editor, caret, forward) {
  20540. var rootNode = editor.getBody();
  20541. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20542. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  20543. var location = BoundaryLocation.findLocation(forward, isInlineTarget, rootNode, from);
  20544. return location.bind(function (location) {
  20545. return renderCaretLocation(editor, caret, location);
  20546. });
  20547. };
  20548. var toggleInlines = function (isInlineTarget, dom, elms) {
  20549. var selectedInlines = filter(dom.select('*[data-mce-selected="inline-boundary"]'), isInlineTarget);
  20550. var targetInlines = filter(elms, isInlineTarget);
  20551. each(difference(selectedInlines, targetInlines), curry(setSelected, false));
  20552. each(difference(targetInlines, selectedInlines), curry(setSelected, true));
  20553. };
  20554. var safeRemoveCaretContainer = function (editor, caret) {
  20555. if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) {
  20556. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20557. if (CaretPosition$1.isTextPosition(pos) && InlineUtils.isAtZwsp(pos) === false) {
  20558. setCaretPosition(editor, CaretContainerRemove.removeAndReposition(caret.get(), pos));
  20559. caret.set(null);
  20560. }
  20561. }
  20562. };
  20563. var renderInsideInlineCaret = function (isInlineTarget, editor, caret, elms) {
  20564. if (editor.selection.isCollapsed()) {
  20565. var inlines = filter(elms, isInlineTarget);
  20566. each(inlines, function (inline) {
  20567. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20568. BoundaryLocation.readLocation(isInlineTarget, editor.getBody(), pos).bind(function (location) {
  20569. return renderCaretLocation(editor, caret, location);
  20570. });
  20571. });
  20572. }
  20573. };
  20574. var move$1 = function (editor, caret, forward) {
  20575. return function () {
  20576. return isFeatureEnabled(editor) ? findLocation$1(editor, caret, forward).isSome() : false;
  20577. };
  20578. };
  20579. var moveWord = function (forward, editor, caret) {
  20580. return function () {
  20581. return isFeatureEnabled(editor) ? WordSelection.moveByWord(forward, editor) : false;
  20582. };
  20583. };
  20584. var setupSelectedState = function (editor) {
  20585. var caret = Cell(null);
  20586. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  20587. editor.on('NodeChange', function (e) {
  20588. if (isFeatureEnabled(editor)) {
  20589. toggleInlines(isInlineTarget, editor.dom, e.parents);
  20590. safeRemoveCaretContainer(editor, caret);
  20591. renderInsideInlineCaret(isInlineTarget, editor, caret, e.parents);
  20592. }
  20593. });
  20594. return caret;
  20595. };
  20596. var moveNextWord = curry(moveWord, true);
  20597. var movePrevWord = curry(moveWord, false);
  20598. var BoundarySelection = {
  20599. move: move$1,
  20600. moveNextWord: moveNextWord,
  20601. movePrevWord: movePrevWord,
  20602. setupSelectedState: setupSelectedState,
  20603. setCaretPosition: setCaretPosition
  20604. };
  20605. var BreakType;
  20606. (function (BreakType) {
  20607. BreakType[BreakType['Br'] = 0] = 'Br';
  20608. BreakType[BreakType['Block'] = 1] = 'Block';
  20609. BreakType[BreakType['Wrap'] = 2] = 'Wrap';
  20610. BreakType[BreakType['Eol'] = 3] = 'Eol';
  20611. }(BreakType || (BreakType = {})));
  20612. var flip = function (direction, positions) {
  20613. return direction === HDirection.Backwards ? positions.reverse() : positions;
  20614. };
  20615. var walk$3 = function (direction, caretWalker, pos) {
  20616. return direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos);
  20617. };
  20618. var getBreakType = function (scope, direction, currentPos, nextPos) {
  20619. if (NodeType.isBr(nextPos.getNode(direction === HDirection.Forwards))) {
  20620. return BreakType.Br;
  20621. } else if (isInSameBlock(currentPos, nextPos) === false) {
  20622. return BreakType.Block;
  20623. } else {
  20624. return BreakType.Wrap;
  20625. }
  20626. };
  20627. var getPositionsUntil = function (predicate, direction, scope, start) {
  20628. var caretWalker = CaretWalker(scope);
  20629. var currentPos = start, nextPos;
  20630. var positions = [];
  20631. while (currentPos) {
  20632. nextPos = walk$3(direction, caretWalker, currentPos);
  20633. if (!nextPos) {
  20634. break;
  20635. }
  20636. if (NodeType.isBr(nextPos.getNode(false))) {
  20637. if (direction === HDirection.Forwards) {
  20638. return {
  20639. positions: flip(direction, positions).concat([nextPos]),
  20640. breakType: BreakType.Br,
  20641. breakAt: Option.some(nextPos)
  20642. };
  20643. } else {
  20644. return {
  20645. positions: flip(direction, positions),
  20646. breakType: BreakType.Br,
  20647. breakAt: Option.some(nextPos)
  20648. };
  20649. }
  20650. }
  20651. if (!nextPos.isVisible()) {
  20652. currentPos = nextPos;
  20653. continue;
  20654. }
  20655. if (predicate(currentPos, nextPos)) {
  20656. var breakType = getBreakType(scope, direction, currentPos, nextPos);
  20657. return {
  20658. positions: flip(direction, positions),
  20659. breakType: breakType,
  20660. breakAt: Option.some(nextPos)
  20661. };
  20662. }
  20663. positions.push(nextPos);
  20664. currentPos = nextPos;
  20665. }
  20666. return {
  20667. positions: flip(direction, positions),
  20668. breakType: BreakType.Eol,
  20669. breakAt: Option.none()
  20670. };
  20671. };
  20672. var getAdjacentLinePositions = function (direction, getPositionsUntilBreak, scope, start) {
  20673. return getPositionsUntilBreak(scope, start).breakAt.map(function (pos) {
  20674. var positions = getPositionsUntilBreak(scope, pos).positions;
  20675. return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions);
  20676. }).getOr([]);
  20677. };
  20678. var findClosestHorizontalPositionFromPoint = function (positions, x) {
  20679. return foldl(positions, function (acc, newPos) {
  20680. return acc.fold(function () {
  20681. return Option.some(newPos);
  20682. }, function (lastPos) {
  20683. return lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), function (lastRect, newRect) {
  20684. var lastDist = Math.abs(x - lastRect.left);
  20685. var newDist = Math.abs(x - newRect.left);
  20686. return newDist <= lastDist ? newPos : lastPos;
  20687. }).or(acc);
  20688. });
  20689. }, Option.none());
  20690. };
  20691. var findClosestHorizontalPosition = function (positions, pos) {
  20692. return head(pos.getClientRects()).bind(function (targetRect) {
  20693. return findClosestHorizontalPositionFromPoint(positions, targetRect.left);
  20694. });
  20695. };
  20696. var getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1);
  20697. var getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1);
  20698. var isAtFirstLine = function (scope, pos) {
  20699. return getPositionsUntilPreviousLine(scope, pos).breakAt.isNone();
  20700. };
  20701. var isAtLastLine = function (scope, pos) {
  20702. return getPositionsUntilNextLine(scope, pos).breakAt.isNone();
  20703. };
  20704. var getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine);
  20705. var getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine);
  20706. var getFirstLinePositions = function (scope) {
  20707. return CaretFinder.firstPositionIn(scope).map(function (pos) {
  20708. return [pos].concat(getPositionsUntilNextLine(scope, pos).positions);
  20709. }).getOr([]);
  20710. };
  20711. var getLastLinePositions = function (scope) {
  20712. return CaretFinder.lastPositionIn(scope).map(function (pos) {
  20713. return getPositionsUntilPreviousLine(scope, pos).positions.concat(pos);
  20714. }).getOr([]);
  20715. };
  20716. var isContentEditableFalse$b = NodeType.isContentEditableFalse;
  20717. var getSelectedNode$1 = getSelectedNode;
  20718. var moveToCeFalseHorizontally = function (direction, editor, getNextPosFn, range) {
  20719. var forwards = direction === HDirection.Forwards;
  20720. var isBeforeContentEditableFalseFn = forwards ? isBeforeContentEditableFalse : isAfterContentEditableFalse;
  20721. if (!range.collapsed) {
  20722. var node = getSelectedNode$1(range);
  20723. if (isContentEditableFalse$b(node)) {
  20724. return showCaret(direction, editor, node, direction === HDirection.Backwards, true);
  20725. }
  20726. }
  20727. var rangeIsInContainerBlock = isRangeInCaretContainerBlock(range);
  20728. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  20729. if (isBeforeContentEditableFalseFn(caretPosition)) {
  20730. return selectNode(editor, caretPosition.getNode(!forwards));
  20731. }
  20732. var nextCaretPosition = InlineUtils.normalizePosition(forwards, getNextPosFn(caretPosition));
  20733. if (!nextCaretPosition) {
  20734. if (rangeIsInContainerBlock) {
  20735. return range;
  20736. }
  20737. return null;
  20738. }
  20739. if (isBeforeContentEditableFalseFn(nextCaretPosition)) {
  20740. return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, true);
  20741. }
  20742. var peekCaretPosition = getNextPosFn(nextCaretPosition);
  20743. if (peekCaretPosition && isBeforeContentEditableFalseFn(peekCaretPosition)) {
  20744. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  20745. return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, true);
  20746. }
  20747. }
  20748. if (rangeIsInContainerBlock) {
  20749. return renderRangeCaret(editor, nextCaretPosition.toRange(), true);
  20750. }
  20751. return null;
  20752. };
  20753. var moveToCeFalseVertically = function (direction, editor, walkerFn, range) {
  20754. var caretPosition, linePositions, nextLinePositions;
  20755. var closestNextLineRect, caretClientRect, clientX;
  20756. var dist1, dist2, contentEditableFalseNode;
  20757. contentEditableFalseNode = getSelectedNode$1(range);
  20758. caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  20759. linePositions = walkerFn(editor.getBody(), isAboveLine(1), caretPosition);
  20760. nextLinePositions = filter(linePositions, isLine(1));
  20761. caretClientRect = ArrUtils.last(caretPosition.getClientRects());
  20762. if (isBeforeContentEditableFalse(caretPosition) || isBeforeTable(caretPosition)) {
  20763. contentEditableFalseNode = caretPosition.getNode();
  20764. }
  20765. if (isAfterContentEditableFalse(caretPosition) || isAfterTable(caretPosition)) {
  20766. contentEditableFalseNode = caretPosition.getNode(true);
  20767. }
  20768. if (!caretClientRect) {
  20769. return null;
  20770. }
  20771. clientX = caretClientRect.left;
  20772. closestNextLineRect = findClosestClientRect(nextLinePositions, clientX);
  20773. if (closestNextLineRect) {
  20774. if (isContentEditableFalse$b(closestNextLineRect.node)) {
  20775. dist1 = Math.abs(clientX - closestNextLineRect.left);
  20776. dist2 = Math.abs(clientX - closestNextLineRect.right);
  20777. return showCaret(direction, editor, closestNextLineRect.node, dist1 < dist2, true);
  20778. }
  20779. }
  20780. if (contentEditableFalseNode) {
  20781. var caretPositions = positionsUntil(direction, editor.getBody(), isAboveLine(1), contentEditableFalseNode);
  20782. closestNextLineRect = findClosestClientRect(filter(caretPositions, isLine(1)), clientX);
  20783. if (closestNextLineRect) {
  20784. return renderRangeCaret(editor, closestNextLineRect.position.toRange(), true);
  20785. }
  20786. closestNextLineRect = ArrUtils.last(filter(caretPositions, isLine(0)));
  20787. if (closestNextLineRect) {
  20788. return renderRangeCaret(editor, closestNextLineRect.position.toRange(), true);
  20789. }
  20790. }
  20791. };
  20792. var createTextBlock = function (editor) {
  20793. var textBlock = editor.dom.create(Settings.getForcedRootBlock(editor));
  20794. if (!Env.ie || Env.ie >= 11) {
  20795. textBlock.innerHTML = '<br data-mce-bogus="1">';
  20796. }
  20797. return textBlock;
  20798. };
  20799. var exitPreBlock = function (editor, direction, range) {
  20800. var pre, caretPos, newBlock;
  20801. var caretWalker = CaretWalker(editor.getBody());
  20802. var getNextVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.next);
  20803. var getPrevVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.prev);
  20804. if (range.collapsed && editor.settings.forced_root_block) {
  20805. pre = editor.dom.getParent(range.startContainer, 'PRE');
  20806. if (!pre) {
  20807. return;
  20808. }
  20809. if (direction === 1) {
  20810. caretPos = getNextVisualCaretPosition(CaretPosition$1.fromRangeStart(range));
  20811. } else {
  20812. caretPos = getPrevVisualCaretPosition(CaretPosition$1.fromRangeStart(range));
  20813. }
  20814. if (!caretPos) {
  20815. newBlock = createTextBlock(editor);
  20816. if (direction === 1) {
  20817. editor.$(pre).after(newBlock);
  20818. } else {
  20819. editor.$(pre).before(newBlock);
  20820. }
  20821. editor.selection.select(newBlock, true);
  20822. editor.selection.collapse();
  20823. }
  20824. }
  20825. };
  20826. var getHorizontalRange = function (editor, forward) {
  20827. var caretWalker = CaretWalker(editor.getBody());
  20828. var getNextVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.next);
  20829. var getPrevVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.prev);
  20830. var newRange;
  20831. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  20832. var getNextPosFn = forward ? getNextVisualCaretPosition : getPrevVisualCaretPosition;
  20833. var range = editor.selection.getRng();
  20834. newRange = moveToCeFalseHorizontally(direction, editor, getNextPosFn, range);
  20835. if (newRange) {
  20836. return newRange;
  20837. }
  20838. newRange = exitPreBlock(editor, direction, range);
  20839. if (newRange) {
  20840. return newRange;
  20841. }
  20842. return null;
  20843. };
  20844. var getVerticalRange = function (editor, down) {
  20845. var newRange;
  20846. var direction = down ? 1 : -1;
  20847. var walkerFn = down ? downUntil : upUntil;
  20848. var range = editor.selection.getRng();
  20849. newRange = moveToCeFalseVertically(direction, editor, walkerFn, range);
  20850. if (newRange) {
  20851. return newRange;
  20852. }
  20853. newRange = exitPreBlock(editor, direction, range);
  20854. if (newRange) {
  20855. return newRange;
  20856. }
  20857. return null;
  20858. };
  20859. var moveH = function (editor, forward) {
  20860. return function () {
  20861. var newRng = getHorizontalRange(editor, forward);
  20862. if (newRng) {
  20863. editor.selection.setRng(newRng);
  20864. return true;
  20865. } else {
  20866. return false;
  20867. }
  20868. };
  20869. };
  20870. var moveV = function (editor, down) {
  20871. return function () {
  20872. var newRng = getVerticalRange(editor, down);
  20873. if (newRng) {
  20874. editor.selection.setRng(newRng);
  20875. return true;
  20876. } else {
  20877. return false;
  20878. }
  20879. };
  20880. };
  20881. var isCefPosition = function (forward) {
  20882. return function (pos) {
  20883. return forward ? isAfterContentEditableFalse(pos) : isBeforeContentEditableFalse(pos);
  20884. };
  20885. };
  20886. var moveToLineEndPoint = function (editor, forward) {
  20887. return function () {
  20888. var from = forward ? CaretPosition$1.fromRangeEnd(editor.selection.getRng()) : CaretPosition$1.fromRangeStart(editor.selection.getRng());
  20889. var result = forward ? getPositionsUntilNextLine(editor.getBody(), from) : getPositionsUntilPreviousLine(editor.getBody(), from);
  20890. var to = forward ? last(result.positions) : head(result.positions);
  20891. return to.filter(isCefPosition(forward)).fold(constant(false), function (pos) {
  20892. editor.selection.setRng(pos.toRange());
  20893. return true;
  20894. });
  20895. };
  20896. };
  20897. var deflate = function (rect, delta) {
  20898. return {
  20899. left: rect.left - delta,
  20900. top: rect.top - delta,
  20901. right: rect.right + delta * 2,
  20902. bottom: rect.bottom + delta * 2,
  20903. width: rect.width + delta,
  20904. height: rect.height + delta
  20905. };
  20906. };
  20907. var getCorners = function (getYAxisValue, tds) {
  20908. return bind(tds, function (td) {
  20909. var rect = deflate(clone$1(td.getBoundingClientRect()), -1);
  20910. return [
  20911. {
  20912. x: rect.left,
  20913. y: getYAxisValue(rect),
  20914. cell: td
  20915. },
  20916. {
  20917. x: rect.right,
  20918. y: getYAxisValue(rect),
  20919. cell: td
  20920. }
  20921. ];
  20922. });
  20923. };
  20924. var findClosestCorner = function (corners, x, y) {
  20925. return foldl(corners, function (acc, newCorner) {
  20926. return acc.fold(function () {
  20927. return Option.some(newCorner);
  20928. }, function (oldCorner) {
  20929. var oldDist = Math.sqrt(Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y));
  20930. var newDist = Math.sqrt(Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y));
  20931. return Option.some(newDist < oldDist ? newCorner : oldCorner);
  20932. });
  20933. }, Option.none());
  20934. };
  20935. var getClosestCell = function (getYAxisValue, isTargetCorner, table, x, y) {
  20936. var cells = descendants$1(Element.fromDom(table), 'td,th,caption').map(function (e) {
  20937. return e.dom();
  20938. });
  20939. var corners = filter(getCorners(getYAxisValue, cells), function (corner) {
  20940. return isTargetCorner(corner, y);
  20941. });
  20942. return findClosestCorner(corners, x, y).map(function (corner) {
  20943. return corner.cell;
  20944. });
  20945. };
  20946. var getBottomValue = function (rect) {
  20947. return rect.bottom;
  20948. };
  20949. var getTopValue = function (rect) {
  20950. return rect.top;
  20951. };
  20952. var isAbove$1 = function (corner, y) {
  20953. return corner.y < y;
  20954. };
  20955. var isBelow$1 = function (corner, y) {
  20956. return corner.y > y;
  20957. };
  20958. var getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove$1);
  20959. var getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow$1);
  20960. var findClosestPositionInAboveCell = function (table, pos) {
  20961. return head(pos.getClientRects()).bind(function (rect) {
  20962. return getClosestCellAbove(table, rect.left, rect.top);
  20963. }).bind(function (cell) {
  20964. return findClosestHorizontalPosition(getLastLinePositions(cell), pos);
  20965. });
  20966. };
  20967. var findClosestPositionInBelowCell = function (table, pos) {
  20968. return last(pos.getClientRects()).bind(function (rect) {
  20969. return getClosestCellBelow(table, rect.left, rect.top);
  20970. }).bind(function (cell) {
  20971. return findClosestHorizontalPosition(getFirstLinePositions(cell), pos);
  20972. });
  20973. };
  20974. var moveToRange = function (editor, rng) {
  20975. editor.selection.setRng(rng);
  20976. ScrollIntoView.scrollRangeIntoView(editor, rng);
  20977. };
  20978. var hasNextBreak = function (getPositionsUntil, scope, lineInfo) {
  20979. return lineInfo.breakAt.map(function (breakPos) {
  20980. return getPositionsUntil(scope, breakPos).breakAt.isSome();
  20981. }).getOr(false);
  20982. };
  20983. var startsWithWrapBreak = function (lineInfo) {
  20984. return lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0;
  20985. };
  20986. var startsWithBrBreak = function (lineInfo) {
  20987. return lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1;
  20988. };
  20989. var isAtTableCellLine = function (getPositionsUntil, scope, pos) {
  20990. var lineInfo = getPositionsUntil(scope, pos);
  20991. if (startsWithWrapBreak(lineInfo) || !NodeType.isBr(pos.getNode()) && startsWithBrBreak(lineInfo)) {
  20992. return !hasNextBreak(getPositionsUntil, scope, lineInfo);
  20993. } else {
  20994. return lineInfo.breakAt.isNone();
  20995. }
  20996. };
  20997. var isAtFirstTableCellLine = curry(isAtTableCellLine, getPositionsUntilPreviousLine);
  20998. var isAtLastTableCellLine = curry(isAtTableCellLine, getPositionsUntilNextLine);
  20999. var isCaretAtStartOrEndOfTable = function (forward, rng, table) {
  21000. var caretPos = CaretPosition$1.fromRangeStart(rng);
  21001. return CaretFinder.positionIn(!forward, table).map(function (pos) {
  21002. return pos.isEqual(caretPos);
  21003. }).getOr(false);
  21004. };
  21005. var navigateHorizontally = function (editor, forward, table, td) {
  21006. var rng = editor.selection.getRng();
  21007. var direction = forward ? 1 : -1;
  21008. if (isFakeCaretTableBrowser() && isCaretAtStartOrEndOfTable(forward, rng, table)) {
  21009. var newRng = showCaret(direction, editor, table, !forward, true);
  21010. moveToRange(editor, newRng);
  21011. return true;
  21012. }
  21013. return false;
  21014. };
  21015. var getClosestAbovePosition = function (root, table, start) {
  21016. return findClosestPositionInAboveCell(table, start).orThunk(function () {
  21017. return head(start.getClientRects()).bind(function (rect) {
  21018. return findClosestHorizontalPositionFromPoint(getPositionsAbove(root, CaretPosition$1.before(table)), rect.left);
  21019. });
  21020. }).getOr(CaretPosition$1.before(table));
  21021. };
  21022. var getClosestBelowPosition = function (root, table, start) {
  21023. return findClosestPositionInBelowCell(table, start).orThunk(function () {
  21024. return head(start.getClientRects()).bind(function (rect) {
  21025. return findClosestHorizontalPositionFromPoint(getPositionsBelow(root, CaretPosition$1.after(table)), rect.left);
  21026. });
  21027. }).getOr(CaretPosition$1.after(table));
  21028. };
  21029. var getTable = function (previous, pos) {
  21030. var node = pos.getNode(previous);
  21031. return NodeType.isElement(node) && node.nodeName === 'TABLE' ? Option.some(node) : Option.none();
  21032. };
  21033. var renderBlock = function (down, editor, table, pos) {
  21034. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  21035. if (forcedRootBlock) {
  21036. editor.undoManager.transact(function () {
  21037. var element = Element.fromTag(forcedRootBlock);
  21038. setAll(element, Settings.getForcedRootBlockAttrs(editor));
  21039. append(element, Element.fromTag('br'));
  21040. if (down) {
  21041. after(Element.fromDom(table), element);
  21042. } else {
  21043. before(Element.fromDom(table), element);
  21044. }
  21045. var rng = editor.dom.createRng();
  21046. rng.setStart(element.dom(), 0);
  21047. rng.setEnd(element.dom(), 0);
  21048. moveToRange(editor, rng);
  21049. });
  21050. } else {
  21051. moveToRange(editor, pos.toRange());
  21052. }
  21053. };
  21054. var moveCaret = function (editor, down, pos) {
  21055. var table = down ? getTable(true, pos) : getTable(false, pos);
  21056. var last = down === false;
  21057. table.fold(function () {
  21058. return moveToRange(editor, pos.toRange());
  21059. }, function (table) {
  21060. return CaretFinder.positionIn(last, editor.getBody()).filter(function (lastPos) {
  21061. return lastPos.isEqual(pos);
  21062. }).fold(function () {
  21063. return moveToRange(editor, pos.toRange());
  21064. }, function (_) {
  21065. return renderBlock(down, editor, table, pos);
  21066. });
  21067. });
  21068. };
  21069. var navigateVertically = function (editor, down, table, td) {
  21070. var rng = editor.selection.getRng();
  21071. var pos = CaretPosition$1.fromRangeStart(rng);
  21072. var root = editor.getBody();
  21073. if (!down && isAtFirstTableCellLine(td, pos)) {
  21074. var newPos = getClosestAbovePosition(root, table, pos);
  21075. moveCaret(editor, down, newPos);
  21076. return true;
  21077. } else if (down && isAtLastTableCellLine(td, pos)) {
  21078. var newPos = getClosestBelowPosition(root, table, pos);
  21079. moveCaret(editor, down, newPos);
  21080. return true;
  21081. } else {
  21082. return false;
  21083. }
  21084. };
  21085. var moveH$1 = function (editor, forward) {
  21086. return function () {
  21087. return Option.from(editor.dom.getParent(editor.selection.getNode(), 'td,th')).bind(function (td) {
  21088. return Option.from(editor.dom.getParent(td, 'table')).map(function (table) {
  21089. return navigateHorizontally(editor, forward, table);
  21090. });
  21091. }).getOr(false);
  21092. };
  21093. };
  21094. var moveV$1 = function (editor, forward) {
  21095. return function () {
  21096. return Option.from(editor.dom.getParent(editor.selection.getNode(), 'td,th')).bind(function (td) {
  21097. return Option.from(editor.dom.getParent(td, 'table')).map(function (table) {
  21098. return navigateVertically(editor, forward, table, td);
  21099. });
  21100. }).getOr(false);
  21101. };
  21102. };
  21103. var isTarget = function (node) {
  21104. return contains(['figcaption'], name(node));
  21105. };
  21106. var rangeBefore = function (target) {
  21107. var rng = domGlobals.document.createRange();
  21108. rng.setStartBefore(target.dom());
  21109. rng.setEndBefore(target.dom());
  21110. return rng;
  21111. };
  21112. var insertElement = function (root, elm, forward) {
  21113. if (forward) {
  21114. append(root, elm);
  21115. } else {
  21116. prepend(root, elm);
  21117. }
  21118. };
  21119. var insertBr = function (root, forward) {
  21120. var br = Element.fromTag('br');
  21121. insertElement(root, br, forward);
  21122. return rangeBefore(br);
  21123. };
  21124. var insertBlock$1 = function (root, forward, blockName, attrs) {
  21125. var block = Element.fromTag(blockName);
  21126. var br = Element.fromTag('br');
  21127. setAll(block, attrs);
  21128. append(block, br);
  21129. insertElement(root, block, forward);
  21130. return rangeBefore(br);
  21131. };
  21132. var insertEmptyLine = function (root, rootBlockName, attrs, forward) {
  21133. if (rootBlockName === '') {
  21134. return insertBr(root, forward);
  21135. } else {
  21136. return insertBlock$1(root, forward, rootBlockName, attrs);
  21137. }
  21138. };
  21139. var getClosestTargetBlock = function (pos, root) {
  21140. var isRoot = curry(eq, root);
  21141. return closest(Element.fromDom(pos.container()), isBlock, isRoot).filter(isTarget);
  21142. };
  21143. var isAtFirstOrLastLine = function (root, forward, pos) {
  21144. return forward ? isAtLastLine(root.dom(), pos) : isAtFirstLine(root.dom(), pos);
  21145. };
  21146. var moveCaretToNewEmptyLine = function (editor, forward) {
  21147. var root = Element.fromDom(editor.getBody());
  21148. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  21149. var rootBlock = Settings.getForcedRootBlock(editor);
  21150. var rootBlockAttrs = Settings.getForcedRootBlockAttrs(editor);
  21151. return getClosestTargetBlock(pos, root).exists(function () {
  21152. if (isAtFirstOrLastLine(root, forward, pos)) {
  21153. var rng = insertEmptyLine(root, rootBlock, rootBlockAttrs, forward);
  21154. editor.selection.setRng(rng);
  21155. return true;
  21156. } else {
  21157. return false;
  21158. }
  21159. });
  21160. };
  21161. var moveV$2 = function (editor, forward) {
  21162. return function () {
  21163. if (editor.selection.isCollapsed()) {
  21164. return moveCaretToNewEmptyLine(editor, forward);
  21165. } else {
  21166. return false;
  21167. }
  21168. };
  21169. };
  21170. var defaultPatterns = function (patterns) {
  21171. return map(patterns, function (pattern) {
  21172. return merge({
  21173. shiftKey: false,
  21174. altKey: false,
  21175. ctrlKey: false,
  21176. metaKey: false,
  21177. keyCode: 0,
  21178. action: noop
  21179. }, pattern);
  21180. });
  21181. };
  21182. var matchesEvent = function (pattern, evt) {
  21183. return evt.keyCode === pattern.keyCode && evt.shiftKey === pattern.shiftKey && evt.altKey === pattern.altKey && evt.ctrlKey === pattern.ctrlKey && evt.metaKey === pattern.metaKey;
  21184. };
  21185. var match$1 = function (patterns, evt) {
  21186. return bind(defaultPatterns(patterns), function (pattern) {
  21187. return matchesEvent(pattern, evt) ? [pattern] : [];
  21188. });
  21189. };
  21190. var action = function (f) {
  21191. var x = [];
  21192. for (var _i = 1; _i < arguments.length; _i++) {
  21193. x[_i - 1] = arguments[_i];
  21194. }
  21195. var args = Array.prototype.slice.call(arguments, 1);
  21196. return function () {
  21197. return f.apply(null, args);
  21198. };
  21199. };
  21200. var execute = function (patterns, evt) {
  21201. return find(match$1(patterns, evt), function (pattern) {
  21202. return pattern.action();
  21203. });
  21204. };
  21205. var MatchKeys = {
  21206. match: match$1,
  21207. action: action,
  21208. execute: execute
  21209. };
  21210. var executeKeydownOverride = function (editor, caret, evt) {
  21211. var os = detect$3().os;
  21212. MatchKeys.execute([
  21213. {
  21214. keyCode: VK.RIGHT,
  21215. action: moveH(editor, true)
  21216. },
  21217. {
  21218. keyCode: VK.LEFT,
  21219. action: moveH(editor, false)
  21220. },
  21221. {
  21222. keyCode: VK.UP,
  21223. action: moveV(editor, false)
  21224. },
  21225. {
  21226. keyCode: VK.DOWN,
  21227. action: moveV(editor, true)
  21228. },
  21229. {
  21230. keyCode: VK.RIGHT,
  21231. action: moveH$1(editor, true)
  21232. },
  21233. {
  21234. keyCode: VK.LEFT,
  21235. action: moveH$1(editor, false)
  21236. },
  21237. {
  21238. keyCode: VK.UP,
  21239. action: moveV$1(editor, false)
  21240. },
  21241. {
  21242. keyCode: VK.DOWN,
  21243. action: moveV$1(editor, true)
  21244. },
  21245. {
  21246. keyCode: VK.RIGHT,
  21247. action: BoundarySelection.move(editor, caret, true)
  21248. },
  21249. {
  21250. keyCode: VK.LEFT,
  21251. action: BoundarySelection.move(editor, caret, false)
  21252. },
  21253. {
  21254. keyCode: VK.RIGHT,
  21255. ctrlKey: !os.isOSX(),
  21256. altKey: os.isOSX(),
  21257. action: BoundarySelection.moveNextWord(editor, caret)
  21258. },
  21259. {
  21260. keyCode: VK.LEFT,
  21261. ctrlKey: !os.isOSX(),
  21262. altKey: os.isOSX(),
  21263. action: BoundarySelection.movePrevWord(editor, caret)
  21264. },
  21265. {
  21266. keyCode: VK.UP,
  21267. action: moveV$2(editor, false)
  21268. },
  21269. {
  21270. keyCode: VK.DOWN,
  21271. action: moveV$2(editor, true)
  21272. }
  21273. ], evt).each(function (_) {
  21274. evt.preventDefault();
  21275. });
  21276. };
  21277. var setup$8 = function (editor, caret) {
  21278. editor.on('keydown', function (evt) {
  21279. if (evt.isDefaultPrevented() === false) {
  21280. executeKeydownOverride(editor, caret, evt);
  21281. }
  21282. });
  21283. };
  21284. var ArrowKeys = { setup: setup$8 };
  21285. var isBeforeRoot = function (rootNode) {
  21286. return function (elm) {
  21287. return eq(rootNode, Element.fromDom(elm.dom().parentNode));
  21288. };
  21289. };
  21290. var getParentBlock$1 = function (rootNode, elm) {
  21291. return contains$2(rootNode, elm) ? closest(elm, function (element) {
  21292. return isTextBlock(element) || isListItem(element);
  21293. }, isBeforeRoot(rootNode)) : Option.none();
  21294. };
  21295. var placeCaretInEmptyBody = function (editor) {
  21296. var body = editor.getBody();
  21297. var node = body.firstChild && editor.dom.isBlock(body.firstChild) ? body.firstChild : body;
  21298. editor.selection.setCursorLocation(node, 0);
  21299. };
  21300. var paddEmptyBody = function (editor) {
  21301. if (editor.dom.isEmpty(editor.getBody())) {
  21302. editor.setContent('');
  21303. placeCaretInEmptyBody(editor);
  21304. }
  21305. };
  21306. var willDeleteLastPositionInElement = function (forward, fromPos, elm) {
  21307. return lift2(CaretFinder.firstPositionIn(elm), CaretFinder.lastPositionIn(elm), function (firstPos, lastPos) {
  21308. var normalizedFirstPos = InlineUtils.normalizePosition(true, firstPos);
  21309. var normalizedLastPos = InlineUtils.normalizePosition(false, lastPos);
  21310. var normalizedFromPos = InlineUtils.normalizePosition(false, fromPos);
  21311. if (forward) {
  21312. return CaretFinder.nextPosition(elm, normalizedFromPos).map(function (nextPos) {
  21313. return nextPos.isEqual(normalizedLastPos) && fromPos.isEqual(normalizedFirstPos);
  21314. }).getOr(false);
  21315. } else {
  21316. return CaretFinder.prevPosition(elm, normalizedFromPos).map(function (prevPos) {
  21317. return prevPos.isEqual(normalizedFirstPos) && fromPos.isEqual(normalizedLastPos);
  21318. }).getOr(false);
  21319. }
  21320. }).getOr(true);
  21321. };
  21322. var DeleteUtils = {
  21323. getParentBlock: getParentBlock$1,
  21324. paddEmptyBody: paddEmptyBody,
  21325. willDeleteLastPositionInElement: willDeleteLastPositionInElement
  21326. };
  21327. var blockPosition = function (block, position) {
  21328. return {
  21329. block: constant(block),
  21330. position: constant(position)
  21331. };
  21332. };
  21333. var blockBoundary = function (from, to) {
  21334. return {
  21335. from: constant(from),
  21336. to: constant(to)
  21337. };
  21338. };
  21339. var getBlockPosition = function (rootNode, pos) {
  21340. var rootElm = Element.fromDom(rootNode);
  21341. var containerElm = Element.fromDom(pos.container());
  21342. return DeleteUtils.getParentBlock(rootElm, containerElm).map(function (block) {
  21343. return blockPosition(block, pos);
  21344. });
  21345. };
  21346. var isDifferentBlocks = function (blockBoundary) {
  21347. return eq(blockBoundary.from().block(), blockBoundary.to().block()) === false;
  21348. };
  21349. var hasSameParent = function (blockBoundary) {
  21350. return parent(blockBoundary.from().block()).bind(function (parent1) {
  21351. return parent(blockBoundary.to().block()).filter(function (parent2) {
  21352. return eq(parent1, parent2);
  21353. });
  21354. }).isSome();
  21355. };
  21356. var isEditable = function (blockBoundary) {
  21357. return NodeType.isContentEditableFalse(blockBoundary.from().block().dom()) === false && NodeType.isContentEditableFalse(blockBoundary.to().block().dom()) === false;
  21358. };
  21359. var skipLastBr = function (rootNode, forward, blockPosition) {
  21360. if (NodeType.isBr(blockPosition.position().getNode()) && Empty.isEmpty(blockPosition.block()) === false) {
  21361. return CaretFinder.positionIn(false, blockPosition.block().dom()).bind(function (lastPositionInBlock) {
  21362. if (lastPositionInBlock.isEqual(blockPosition.position())) {
  21363. return CaretFinder.fromPosition(forward, rootNode, lastPositionInBlock).bind(function (to) {
  21364. return getBlockPosition(rootNode, to);
  21365. });
  21366. } else {
  21367. return Option.some(blockPosition);
  21368. }
  21369. }).getOr(blockPosition);
  21370. } else {
  21371. return blockPosition;
  21372. }
  21373. };
  21374. var readFromRange = function (rootNode, forward, rng) {
  21375. var fromBlockPos = getBlockPosition(rootNode, CaretPosition$1.fromRangeStart(rng));
  21376. var toBlockPos = fromBlockPos.bind(function (blockPos) {
  21377. return CaretFinder.fromPosition(forward, rootNode, blockPos.position()).bind(function (to) {
  21378. return getBlockPosition(rootNode, to).map(function (blockPos) {
  21379. return skipLastBr(rootNode, forward, blockPos);
  21380. });
  21381. });
  21382. });
  21383. return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(function (blockBoundary) {
  21384. return isDifferentBlocks(blockBoundary) && hasSameParent(blockBoundary) && isEditable(blockBoundary);
  21385. });
  21386. };
  21387. var read$3 = function (rootNode, forward, rng) {
  21388. return rng.collapsed ? readFromRange(rootNode, forward, rng) : Option.none();
  21389. };
  21390. var BlockMergeBoundary = { read: read$3 };
  21391. var getChildrenUntilBlockBoundary = function (block) {
  21392. var children$1 = children(block);
  21393. return findIndex(children$1, isBlock).fold(function () {
  21394. return children$1;
  21395. }, function (index) {
  21396. return children$1.slice(0, index);
  21397. });
  21398. };
  21399. var extractChildren = function (block) {
  21400. var children = getChildrenUntilBlockBoundary(block);
  21401. each(children, remove$1);
  21402. return children;
  21403. };
  21404. var removeEmptyRoot = function (rootNode, block) {
  21405. var parents = Parents.parentsAndSelf(block, rootNode);
  21406. return find(parents.reverse(), Empty.isEmpty).each(remove$1);
  21407. };
  21408. var isEmptyBefore = function (el) {
  21409. return filter(prevSiblings(el), function (el) {
  21410. return !Empty.isEmpty(el);
  21411. }).length === 0;
  21412. };
  21413. var nestedBlockMerge = function (rootNode, fromBlock, toBlock, insertionPoint) {
  21414. if (Empty.isEmpty(toBlock)) {
  21415. PaddingBr.fillWithPaddingBr(toBlock);
  21416. return CaretFinder.firstPositionIn(toBlock.dom());
  21417. }
  21418. if (isEmptyBefore(insertionPoint) && Empty.isEmpty(fromBlock)) {
  21419. before(insertionPoint, Element.fromTag('br'));
  21420. }
  21421. var position = CaretFinder.prevPosition(toBlock.dom(), CaretPosition$1.before(insertionPoint.dom()));
  21422. each(extractChildren(fromBlock), function (child) {
  21423. before(insertionPoint, child);
  21424. });
  21425. removeEmptyRoot(rootNode, fromBlock);
  21426. return position;
  21427. };
  21428. var sidelongBlockMerge = function (rootNode, fromBlock, toBlock) {
  21429. if (Empty.isEmpty(toBlock)) {
  21430. remove$1(toBlock);
  21431. if (Empty.isEmpty(fromBlock)) {
  21432. PaddingBr.fillWithPaddingBr(fromBlock);
  21433. }
  21434. return CaretFinder.firstPositionIn(fromBlock.dom());
  21435. }
  21436. var position = CaretFinder.lastPositionIn(toBlock.dom());
  21437. each(extractChildren(fromBlock), function (child) {
  21438. append(toBlock, child);
  21439. });
  21440. removeEmptyRoot(rootNode, fromBlock);
  21441. return position;
  21442. };
  21443. var findInsertionPoint = function (toBlock, block) {
  21444. var parentsAndSelf = Parents.parentsAndSelf(block, toBlock);
  21445. return Option.from(parentsAndSelf[parentsAndSelf.length - 1]);
  21446. };
  21447. var getInsertionPoint = function (fromBlock, toBlock) {
  21448. return contains$2(toBlock, fromBlock) ? findInsertionPoint(toBlock, fromBlock) : Option.none();
  21449. };
  21450. var trimBr = function (first, block) {
  21451. CaretFinder.positionIn(first, block.dom()).map(function (position) {
  21452. return position.getNode();
  21453. }).map(Element.fromDom).filter(isBr$1).each(remove$1);
  21454. };
  21455. var mergeBlockInto = function (rootNode, fromBlock, toBlock) {
  21456. trimBr(true, fromBlock);
  21457. trimBr(false, toBlock);
  21458. return getInsertionPoint(fromBlock, toBlock).fold(curry(sidelongBlockMerge, rootNode, fromBlock, toBlock), curry(nestedBlockMerge, rootNode, fromBlock, toBlock));
  21459. };
  21460. var mergeBlocks = function (rootNode, forward, block1, block2) {
  21461. return forward ? mergeBlockInto(rootNode, block2, block1) : mergeBlockInto(rootNode, block1, block2);
  21462. };
  21463. var MergeBlocks = { mergeBlocks: mergeBlocks };
  21464. var backspaceDelete = function (editor, forward) {
  21465. var rootNode = Element.fromDom(editor.getBody());
  21466. var position = BlockMergeBoundary.read(rootNode.dom(), forward, editor.selection.getRng()).bind(function (blockBoundary) {
  21467. return MergeBlocks.mergeBlocks(rootNode, forward, blockBoundary.from().block(), blockBoundary.to().block());
  21468. });
  21469. position.each(function (pos) {
  21470. editor.selection.setRng(pos.toRange());
  21471. });
  21472. return position.isSome();
  21473. };
  21474. var BlockBoundaryDelete = { backspaceDelete: backspaceDelete };
  21475. var deleteRangeMergeBlocks = function (rootNode, selection) {
  21476. var rng = selection.getRng();
  21477. return lift2(DeleteUtils.getParentBlock(rootNode, Element.fromDom(rng.startContainer)), DeleteUtils.getParentBlock(rootNode, Element.fromDom(rng.endContainer)), function (block1, block2) {
  21478. if (eq(block1, block2) === false) {
  21479. rng.deleteContents();
  21480. MergeBlocks.mergeBlocks(rootNode, true, block1, block2).each(function (pos) {
  21481. selection.setRng(pos.toRange());
  21482. });
  21483. return true;
  21484. } else {
  21485. return false;
  21486. }
  21487. }).getOr(false);
  21488. };
  21489. var isRawNodeInTable = function (root, rawNode) {
  21490. var node = Element.fromDom(rawNode);
  21491. var isRoot = curry(eq, root);
  21492. return ancestor(node, isTableCell, isRoot).isSome();
  21493. };
  21494. var isSelectionInTable = function (root, rng) {
  21495. return isRawNodeInTable(root, rng.startContainer) || isRawNodeInTable(root, rng.endContainer);
  21496. };
  21497. var isEverythingSelected = function (root, rng) {
  21498. var noPrevious = CaretFinder.prevPosition(root.dom(), CaretPosition$1.fromRangeStart(rng)).isNone();
  21499. var noNext = CaretFinder.nextPosition(root.dom(), CaretPosition$1.fromRangeEnd(rng)).isNone();
  21500. return !isSelectionInTable(root, rng) && noPrevious && noNext;
  21501. };
  21502. var emptyEditor = function (editor) {
  21503. editor.setContent('');
  21504. editor.selection.setCursorLocation();
  21505. return true;
  21506. };
  21507. var deleteRange = function (editor) {
  21508. var rootNode = Element.fromDom(editor.getBody());
  21509. var rng = editor.selection.getRng();
  21510. return isEverythingSelected(rootNode, rng) ? emptyEditor(editor) : deleteRangeMergeBlocks(rootNode, editor.selection);
  21511. };
  21512. var backspaceDelete$1 = function (editor, forward) {
  21513. return editor.selection.isCollapsed() ? false : deleteRange(editor);
  21514. };
  21515. var BlockRangeDelete = { backspaceDelete: backspaceDelete$1 };
  21516. var isBr$5 = function (pos) {
  21517. return getElementFromPosition(pos).exists(isBr$1);
  21518. };
  21519. var findBr = function (forward, root, pos) {
  21520. var parentBlocks = filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), isBlock);
  21521. var scope = head(parentBlocks).getOr(root);
  21522. return CaretFinder.fromPosition(forward, scope.dom(), pos).filter(isBr$5);
  21523. };
  21524. var isBeforeBr = function (root, pos) {
  21525. return getElementFromPosition(pos).exists(isBr$1) || findBr(true, root, pos).isSome();
  21526. };
  21527. var isAfterBr = function (root, pos) {
  21528. return getElementFromPrevPosition(pos).exists(isBr$1) || findBr(false, root, pos).isSome();
  21529. };
  21530. var findPreviousBr = curry(findBr, false);
  21531. var findNextBr = curry(findBr, true);
  21532. var isCompoundElement = function (node) {
  21533. return isTableCell(Element.fromDom(node)) || isListItem(Element.fromDom(node));
  21534. };
  21535. var DeleteAction = Adt.generate([
  21536. { remove: ['element'] },
  21537. { moveToElement: ['element'] },
  21538. { moveToPosition: ['position'] }
  21539. ]);
  21540. var isAtContentEditableBlockCaret = function (forward, from) {
  21541. var elm = from.getNode(forward === false);
  21542. var caretLocation = forward ? 'after' : 'before';
  21543. return NodeType.isElement(elm) && elm.getAttribute('data-mce-caret') === caretLocation;
  21544. };
  21545. var isDeleteFromCefDifferentBlocks = function (root, forward, from, to) {
  21546. var inSameBlock = function (elm) {
  21547. return isInline(Element.fromDom(elm)) && !isInSameBlock(from, to, root);
  21548. };
  21549. return getRelativeCefElm(!forward, from).fold(function () {
  21550. return getRelativeCefElm(forward, to).fold(constant(false), inSameBlock);
  21551. }, inSameBlock);
  21552. };
  21553. var deleteEmptyBlockOrMoveToCef = function (root, forward, from, to) {
  21554. var toCefElm = to.getNode(forward === false);
  21555. return DeleteUtils.getParentBlock(Element.fromDom(root), Element.fromDom(from.getNode())).map(function (blockElm) {
  21556. return Empty.isEmpty(blockElm) ? DeleteAction.remove(blockElm.dom()) : DeleteAction.moveToElement(toCefElm);
  21557. }).orThunk(function () {
  21558. return Option.some(DeleteAction.moveToElement(toCefElm));
  21559. });
  21560. };
  21561. var findCefPosition = function (root, forward, from) {
  21562. return CaretFinder.fromPosition(forward, root, from).bind(function (to) {
  21563. if (isCompoundElement(to.getNode())) {
  21564. return Option.none();
  21565. } else if (isDeleteFromCefDifferentBlocks(root, forward, from, to)) {
  21566. return Option.none();
  21567. } else if (forward && NodeType.isContentEditableFalse(to.getNode())) {
  21568. return deleteEmptyBlockOrMoveToCef(root, forward, from, to);
  21569. } else if (forward === false && NodeType.isContentEditableFalse(to.getNode(true))) {
  21570. return deleteEmptyBlockOrMoveToCef(root, forward, from, to);
  21571. } else if (forward && isAfterContentEditableFalse(from)) {
  21572. return Option.some(DeleteAction.moveToPosition(to));
  21573. } else if (forward === false && isBeforeContentEditableFalse(from)) {
  21574. return Option.some(DeleteAction.moveToPosition(to));
  21575. } else {
  21576. return Option.none();
  21577. }
  21578. });
  21579. };
  21580. var getContentEditableBlockAction = function (forward, elm) {
  21581. if (forward && NodeType.isContentEditableFalse(elm.nextSibling)) {
  21582. return Option.some(DeleteAction.moveToElement(elm.nextSibling));
  21583. } else if (forward === false && NodeType.isContentEditableFalse(elm.previousSibling)) {
  21584. return Option.some(DeleteAction.moveToElement(elm.previousSibling));
  21585. } else {
  21586. return Option.none();
  21587. }
  21588. };
  21589. var skipMoveToActionFromInlineCefToContent = function (root, from, deleteAction) {
  21590. return deleteAction.fold(function (elm) {
  21591. return Option.some(DeleteAction.remove(elm));
  21592. }, function (elm) {
  21593. return Option.some(DeleteAction.moveToElement(elm));
  21594. }, function (to) {
  21595. if (isInSameBlock(from, to, root)) {
  21596. return Option.none();
  21597. } else {
  21598. return Option.some(DeleteAction.moveToPosition(to));
  21599. }
  21600. });
  21601. };
  21602. var getContentEditableAction = function (root, forward, from) {
  21603. if (isAtContentEditableBlockCaret(forward, from)) {
  21604. return getContentEditableBlockAction(forward, from.getNode(forward === false)).fold(function () {
  21605. return findCefPosition(root, forward, from);
  21606. }, Option.some);
  21607. } else {
  21608. return findCefPosition(root, forward, from).bind(function (deleteAction) {
  21609. return skipMoveToActionFromInlineCefToContent(root, from, deleteAction);
  21610. });
  21611. }
  21612. };
  21613. var read$4 = function (root, forward, rng) {
  21614. var normalizedRange = normalizeRange(forward ? 1 : -1, root, rng);
  21615. var from = CaretPosition$1.fromRangeStart(normalizedRange);
  21616. var rootElement = Element.fromDom(root);
  21617. if (forward === false && isAfterContentEditableFalse(from)) {
  21618. return Option.some(DeleteAction.remove(from.getNode(true)));
  21619. } else if (forward && isBeforeContentEditableFalse(from)) {
  21620. return Option.some(DeleteAction.remove(from.getNode()));
  21621. } else if (forward === false && isBeforeContentEditableFalse(from) && isAfterBr(rootElement, from)) {
  21622. return findPreviousBr(rootElement, from).map(function (br) {
  21623. return DeleteAction.remove(br.getNode());
  21624. });
  21625. } else if (forward && isAfterContentEditableFalse(from) && isBeforeBr(rootElement, from)) {
  21626. return findNextBr(rootElement, from).map(function (br) {
  21627. return DeleteAction.remove(br.getNode());
  21628. });
  21629. } else {
  21630. return getContentEditableAction(root, forward, from);
  21631. }
  21632. };
  21633. var deleteElement$1 = function (editor, forward) {
  21634. return function (element) {
  21635. editor._selectionOverrides.hideFakeCaret();
  21636. DeleteElement.deleteElement(editor, forward, Element.fromDom(element));
  21637. return true;
  21638. };
  21639. };
  21640. var moveToElement = function (editor, forward) {
  21641. return function (element) {
  21642. var pos = forward ? CaretPosition$1.before(element) : CaretPosition$1.after(element);
  21643. editor.selection.setRng(pos.toRange());
  21644. return true;
  21645. };
  21646. };
  21647. var moveToPosition = function (editor) {
  21648. return function (pos) {
  21649. editor.selection.setRng(pos.toRange());
  21650. return true;
  21651. };
  21652. };
  21653. var getAncestorCe = function (editor, node) {
  21654. return Option.from(getContentEditableRoot$2(editor.getBody(), node));
  21655. };
  21656. var backspaceDeleteCaret = function (editor, forward) {
  21657. var selectedNode = editor.selection.getNode();
  21658. return getAncestorCe(editor, selectedNode).filter(NodeType.isContentEditableFalse).fold(function () {
  21659. var result = read$4(editor.getBody(), forward, editor.selection.getRng()).map(function (deleteAction) {
  21660. return deleteAction.fold(deleteElement$1(editor, forward), moveToElement(editor, forward), moveToPosition(editor));
  21661. });
  21662. return result.getOr(false);
  21663. }, function () {
  21664. return true;
  21665. });
  21666. };
  21667. var deleteOffscreenSelection = function (rootElement) {
  21668. each(descendants$1(rootElement, '.mce-offscreen-selection'), remove$1);
  21669. };
  21670. var backspaceDeleteRange = function (editor, forward) {
  21671. var selectedNode = editor.selection.getNode();
  21672. if (NodeType.isContentEditableFalse(selectedNode)) {
  21673. var hasCefAncestor = getAncestorCe(editor, selectedNode.parentNode).filter(NodeType.isContentEditableFalse);
  21674. return hasCefAncestor.fold(function () {
  21675. deleteOffscreenSelection(Element.fromDom(editor.getBody()));
  21676. DeleteElement.deleteElement(editor, forward, Element.fromDom(editor.selection.getNode()));
  21677. DeleteUtils.paddEmptyBody(editor);
  21678. return true;
  21679. }, function () {
  21680. return true;
  21681. });
  21682. }
  21683. return false;
  21684. };
  21685. var getContentEditableRoot$2 = function (root, node) {
  21686. while (node && node !== root) {
  21687. if (NodeType.isContentEditableTrue(node) || NodeType.isContentEditableFalse(node)) {
  21688. return node;
  21689. }
  21690. node = node.parentNode;
  21691. }
  21692. return null;
  21693. };
  21694. var paddEmptyElement = function (editor) {
  21695. var br;
  21696. var ceRoot = getContentEditableRoot$2(editor.getBody(), editor.selection.getNode());
  21697. if (NodeType.isContentEditableTrue(ceRoot) && editor.dom.isBlock(ceRoot) && editor.dom.isEmpty(ceRoot)) {
  21698. br = editor.dom.create('br', { 'data-mce-bogus': '1' });
  21699. editor.dom.setHTML(ceRoot, '');
  21700. ceRoot.appendChild(br);
  21701. editor.selection.setRng(CaretPosition$1.before(br).toRange());
  21702. }
  21703. return true;
  21704. };
  21705. var backspaceDelete$2 = function (editor, forward) {
  21706. if (editor.selection.isCollapsed()) {
  21707. return backspaceDeleteCaret(editor, forward);
  21708. } else {
  21709. return backspaceDeleteRange(editor, forward);
  21710. }
  21711. };
  21712. var CefDelete = {
  21713. backspaceDelete: backspaceDelete$2,
  21714. paddEmptyElement: paddEmptyElement
  21715. };
  21716. var trimEmptyTextNode$1 = function (dom, node) {
  21717. if (NodeType.isText(node) && node.data.length === 0) {
  21718. dom.remove(node);
  21719. }
  21720. };
  21721. var deleteContentAndShowCaret = function (editor, range, node, direction, forward, peekCaretPosition) {
  21722. var caretRange = showCaret(direction, editor, peekCaretPosition.getNode(!forward), forward, true);
  21723. if (range.collapsed) {
  21724. var deleteRange = range.cloneRange();
  21725. if (forward) {
  21726. deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset);
  21727. } else {
  21728. deleteRange.setStart(caretRange.endContainer, caretRange.endOffset);
  21729. }
  21730. deleteRange.deleteContents();
  21731. } else {
  21732. range.deleteContents();
  21733. }
  21734. editor.selection.setRng(caretRange);
  21735. trimEmptyTextNode$1(editor.dom, node);
  21736. return true;
  21737. };
  21738. var deleteCefBoundaryText = function (editor, forward) {
  21739. var range = editor.selection.getRng();
  21740. if (!NodeType.isText(range.commonAncestorContainer)) {
  21741. return false;
  21742. }
  21743. var direction = forward ? HDirection.Forwards : HDirection.Backwards;
  21744. var caretWalker = CaretWalker(editor.getBody());
  21745. var getNextVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.next);
  21746. var getPrevVisualCaretPosition = curry(getVisualCaretPosition, caretWalker.prev);
  21747. var getNextPosFn = forward ? getNextVisualCaretPosition : getPrevVisualCaretPosition;
  21748. var isBeforeContentEditableFalseFn = forward ? isBeforeContentEditableFalse : isAfterContentEditableFalse;
  21749. var caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  21750. var nextCaretPosition = InlineUtils.normalizePosition(forward, getNextPosFn(caretPosition));
  21751. if (!nextCaretPosition || !isMoveInsideSameBlock(caretPosition, nextCaretPosition)) {
  21752. return false;
  21753. } else if (isBeforeContentEditableFalseFn(nextCaretPosition)) {
  21754. return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, nextCaretPosition);
  21755. }
  21756. var peekCaretPosition = getNextPosFn(nextCaretPosition);
  21757. if (peekCaretPosition && isBeforeContentEditableFalseFn(peekCaretPosition)) {
  21758. if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
  21759. return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, peekCaretPosition);
  21760. }
  21761. }
  21762. return false;
  21763. };
  21764. var backspaceDelete$3 = function (editor, forward) {
  21765. return deleteCefBoundaryText(editor, forward);
  21766. };
  21767. var CefBoundaryDelete = { backspaceDelete: backspaceDelete$3 };
  21768. var isFeatureEnabled$1 = function (editor) {
  21769. return editor.settings.inline_boundaries !== false;
  21770. };
  21771. var rangeFromPositions = function (from, to) {
  21772. var range = domGlobals.document.createRange();
  21773. range.setStart(from.container(), from.offset());
  21774. range.setEnd(to.container(), to.offset());
  21775. return range;
  21776. };
  21777. var hasOnlyTwoOrLessPositionsLeft = function (elm) {
  21778. return lift2(CaretFinder.firstPositionIn(elm), CaretFinder.lastPositionIn(elm), function (firstPos, lastPos) {
  21779. var normalizedFirstPos = InlineUtils.normalizePosition(true, firstPos);
  21780. var normalizedLastPos = InlineUtils.normalizePosition(false, lastPos);
  21781. return CaretFinder.nextPosition(elm, normalizedFirstPos).map(function (pos) {
  21782. return pos.isEqual(normalizedLastPos);
  21783. }).getOr(true);
  21784. }).getOr(true);
  21785. };
  21786. var setCaretLocation = function (editor, caret) {
  21787. return function (location) {
  21788. return BoundaryCaret.renderCaret(caret, location).map(function (pos) {
  21789. BoundarySelection.setCaretPosition(editor, pos);
  21790. return true;
  21791. }).getOr(false);
  21792. };
  21793. };
  21794. var deleteFromTo = function (editor, caret, from, to) {
  21795. var rootNode = editor.getBody();
  21796. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  21797. editor.undoManager.ignore(function () {
  21798. editor.selection.setRng(rangeFromPositions(from, to));
  21799. editor.execCommand('Delete');
  21800. BoundaryLocation.readLocation(isInlineTarget, rootNode, CaretPosition$1.fromRangeStart(editor.selection.getRng())).map(BoundaryLocation.inside).map(setCaretLocation(editor, caret));
  21801. });
  21802. editor.nodeChanged();
  21803. };
  21804. var rescope$1 = function (rootNode, node) {
  21805. var parentBlock = getParentBlock(node, rootNode);
  21806. return parentBlock ? parentBlock : rootNode;
  21807. };
  21808. var backspaceDeleteCollapsed = function (editor, caret, forward, from) {
  21809. var rootNode = rescope$1(editor.getBody(), from.container());
  21810. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  21811. var fromLocation = BoundaryLocation.readLocation(isInlineTarget, rootNode, from);
  21812. return fromLocation.bind(function (location) {
  21813. if (forward) {
  21814. return location.fold(constant(Option.some(BoundaryLocation.inside(location))), Option.none, constant(Option.some(BoundaryLocation.outside(location))), Option.none);
  21815. } else {
  21816. return location.fold(Option.none, constant(Option.some(BoundaryLocation.outside(location))), Option.none, constant(Option.some(BoundaryLocation.inside(location))));
  21817. }
  21818. }).map(setCaretLocation(editor, caret)).getOrThunk(function () {
  21819. var toPosition = CaretFinder.navigate(forward, rootNode, from);
  21820. var toLocation = toPosition.bind(function (pos) {
  21821. return BoundaryLocation.readLocation(isInlineTarget, rootNode, pos);
  21822. });
  21823. if (fromLocation.isSome() && toLocation.isSome()) {
  21824. return InlineUtils.findRootInline(isInlineTarget, rootNode, from).map(function (elm) {
  21825. if (hasOnlyTwoOrLessPositionsLeft(elm)) {
  21826. DeleteElement.deleteElement(editor, forward, Element.fromDom(elm));
  21827. return true;
  21828. } else {
  21829. return false;
  21830. }
  21831. }).getOr(false);
  21832. } else {
  21833. return toLocation.bind(function (_) {
  21834. return toPosition.map(function (to) {
  21835. if (forward) {
  21836. deleteFromTo(editor, caret, from, to);
  21837. } else {
  21838. deleteFromTo(editor, caret, to, from);
  21839. }
  21840. return true;
  21841. });
  21842. }).getOr(false);
  21843. }
  21844. });
  21845. };
  21846. var backspaceDelete$4 = function (editor, caret, forward) {
  21847. if (editor.selection.isCollapsed() && isFeatureEnabled$1(editor)) {
  21848. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  21849. return backspaceDeleteCollapsed(editor, caret, forward, from);
  21850. }
  21851. return false;
  21852. };
  21853. var BoundaryDelete = { backspaceDelete: backspaceDelete$4 };
  21854. var getParentInlines = function (rootElm, startElm) {
  21855. var parents = Parents.parentsAndSelf(startElm, rootElm);
  21856. return findIndex(parents, isBlock).fold(constant(parents), function (index) {
  21857. return parents.slice(0, index);
  21858. });
  21859. };
  21860. var hasOnlyOneChild = function (elm) {
  21861. return children(elm).length === 1;
  21862. };
  21863. var deleteLastPosition = function (forward, editor, target, parentInlines) {
  21864. var isFormatElement$1 = curry(isFormatElement, editor);
  21865. var formatNodes = map(filter(parentInlines, isFormatElement$1), function (elm) {
  21866. return elm.dom();
  21867. });
  21868. if (formatNodes.length === 0) {
  21869. DeleteElement.deleteElement(editor, forward, target);
  21870. } else {
  21871. var pos = replaceWithCaretFormat(target.dom(), formatNodes);
  21872. editor.selection.setRng(pos.toRange());
  21873. }
  21874. };
  21875. var deleteCaret = function (editor, forward) {
  21876. var rootElm = Element.fromDom(editor.getBody());
  21877. var startElm = Element.fromDom(editor.selection.getStart());
  21878. var parentInlines = filter(getParentInlines(rootElm, startElm), hasOnlyOneChild);
  21879. return last(parentInlines).map(function (target) {
  21880. var fromPos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  21881. if (DeleteUtils.willDeleteLastPositionInElement(forward, fromPos, target.dom()) && !isEmptyCaretFormatElement(target)) {
  21882. deleteLastPosition(forward, editor, target, parentInlines);
  21883. return true;
  21884. } else {
  21885. return false;
  21886. }
  21887. }).getOr(false);
  21888. };
  21889. var backspaceDelete$5 = function (editor, forward) {
  21890. return editor.selection.isCollapsed() ? deleteCaret(editor, forward) : false;
  21891. };
  21892. var InlineFormatDelete = { backspaceDelete: backspaceDelete$5 };
  21893. var tableCellRng = function (start, end) {
  21894. return {
  21895. start: constant(start),
  21896. end: constant(end)
  21897. };
  21898. };
  21899. var tableSelection = function (rng, table, cells) {
  21900. return {
  21901. rng: constant(rng),
  21902. table: constant(table),
  21903. cells: constant(cells)
  21904. };
  21905. };
  21906. var deleteAction = Adt.generate([
  21907. { removeTable: ['element'] },
  21908. { emptyCells: ['cells'] }
  21909. ]);
  21910. var isRootFromElement = function (root) {
  21911. return function (cur) {
  21912. return eq(root, cur);
  21913. };
  21914. };
  21915. var getClosestCell$1 = function (container, isRoot) {
  21916. return closest$1(Element.fromDom(container), 'td,th', isRoot);
  21917. };
  21918. var getClosestTable = function (cell, isRoot) {
  21919. return ancestor$1(cell, 'table', isRoot);
  21920. };
  21921. var isExpandedCellRng = function (cellRng) {
  21922. return eq(cellRng.start(), cellRng.end()) === false;
  21923. };
  21924. var getTableFromCellRng = function (cellRng, isRoot) {
  21925. return getClosestTable(cellRng.start(), isRoot).bind(function (startParentTable) {
  21926. return getClosestTable(cellRng.end(), isRoot).bind(function (endParentTable) {
  21927. return someIf(eq(startParentTable, endParentTable), startParentTable);
  21928. });
  21929. });
  21930. };
  21931. var getTableCells = function (table) {
  21932. return descendants$1(table, 'td,th');
  21933. };
  21934. var getCellRangeFromStartTable = function (cellRng, isRoot) {
  21935. return getClosestTable(cellRng.start(), isRoot).bind(function (table) {
  21936. return last(getTableCells(table)).map(function (endCell) {
  21937. return tableCellRng(cellRng.start(), endCell);
  21938. });
  21939. });
  21940. };
  21941. var partialSelection = function (isRoot, rng) {
  21942. var startCell = getClosestCell$1(rng.startContainer, isRoot);
  21943. var endCell = getClosestCell$1(rng.endContainer, isRoot);
  21944. return rng.collapsed ? Option.none() : lift2(startCell, endCell, tableCellRng).fold(function () {
  21945. return startCell.fold(function () {
  21946. return endCell.bind(function (endCell) {
  21947. return getClosestTable(endCell, isRoot).bind(function (table) {
  21948. return head(getTableCells(table)).map(function (startCell) {
  21949. return tableCellRng(startCell, endCell);
  21950. });
  21951. });
  21952. });
  21953. }, function (startCell) {
  21954. return getClosestTable(startCell, isRoot).bind(function (table) {
  21955. return last(getTableCells(table)).map(function (endCell) {
  21956. return tableCellRng(startCell, endCell);
  21957. });
  21958. });
  21959. });
  21960. }, function (cellRng) {
  21961. return isWithinSameTable(isRoot, cellRng) ? Option.none() : getCellRangeFromStartTable(cellRng, isRoot);
  21962. });
  21963. };
  21964. var isWithinSameTable = function (isRoot, cellRng) {
  21965. return getTableFromCellRng(cellRng, isRoot).isSome();
  21966. };
  21967. var getCellRng = function (rng, isRoot) {
  21968. var startCell = getClosestCell$1(rng.startContainer, isRoot);
  21969. var endCell = getClosestCell$1(rng.endContainer, isRoot);
  21970. return lift2(startCell, endCell, tableCellRng).filter(isExpandedCellRng).filter(function (cellRng) {
  21971. return isWithinSameTable(isRoot, cellRng);
  21972. }).orThunk(function () {
  21973. return partialSelection(isRoot, rng);
  21974. });
  21975. };
  21976. var getTableSelectionFromCellRng = function (cellRng, isRoot) {
  21977. return getTableFromCellRng(cellRng, isRoot).map(function (table) {
  21978. return tableSelection(cellRng, table, getTableCells(table));
  21979. });
  21980. };
  21981. var getTableSelectionFromRng = function (root, rng) {
  21982. var isRoot = isRootFromElement(root);
  21983. return getCellRng(rng, isRoot).bind(function (cellRng) {
  21984. return getTableSelectionFromCellRng(cellRng, isRoot);
  21985. });
  21986. };
  21987. var getCellIndex = function (cells, cell) {
  21988. return findIndex(cells, function (x) {
  21989. return eq(x, cell);
  21990. });
  21991. };
  21992. var getSelectedCells = function (tableSelection) {
  21993. return lift2(getCellIndex(tableSelection.cells(), tableSelection.rng().start()), getCellIndex(tableSelection.cells(), tableSelection.rng().end()), function (startIndex, endIndex) {
  21994. return tableSelection.cells().slice(startIndex, endIndex + 1);
  21995. });
  21996. };
  21997. var getAction = function (tableSelection) {
  21998. return getSelectedCells(tableSelection).map(function (selected) {
  21999. var cells = tableSelection.cells();
  22000. return selected.length === cells.length ? deleteAction.removeTable(tableSelection.table()) : deleteAction.emptyCells(selected);
  22001. });
  22002. };
  22003. var getActionFromRange = function (root, rng) {
  22004. return getTableSelectionFromRng(root, rng).bind(getAction);
  22005. };
  22006. var emptyCells = function (editor, cells) {
  22007. each(cells, PaddingBr.fillWithPaddingBr);
  22008. editor.selection.setCursorLocation(cells[0].dom(), 0);
  22009. return true;
  22010. };
  22011. var deleteTableElement = function (editor, table) {
  22012. DeleteElement.deleteElement(editor, false, table);
  22013. return true;
  22014. };
  22015. var deleteCellRange = function (editor, rootElm, rng) {
  22016. return getActionFromRange(rootElm, rng).map(function (action) {
  22017. return action.fold(curry(deleteTableElement, editor), curry(emptyCells, editor));
  22018. });
  22019. };
  22020. var deleteCaptionRange = function (editor, caption) {
  22021. return emptyElement(editor, caption);
  22022. };
  22023. var deleteTableRange = function (editor, rootElm, rng, startElm) {
  22024. return getParentCaption(rootElm, startElm).fold(function () {
  22025. return deleteCellRange(editor, rootElm, rng);
  22026. }, function (caption) {
  22027. return deleteCaptionRange(editor, caption);
  22028. }).getOr(false);
  22029. };
  22030. var deleteRange$1 = function (editor, startElm) {
  22031. var rootNode = Element.fromDom(editor.getBody());
  22032. var rng = editor.selection.getRng();
  22033. var selectedCells = TableCellSelection.getCellsFromEditor(editor);
  22034. return selectedCells.length !== 0 ? emptyCells(editor, selectedCells) : deleteTableRange(editor, rootNode, rng, startElm);
  22035. };
  22036. var getParentCell = function (rootElm, elm) {
  22037. return find(Parents.parentsAndSelf(elm, rootElm), isTableCell);
  22038. };
  22039. var getParentCaption = function (rootElm, elm) {
  22040. return find(Parents.parentsAndSelf(elm, rootElm), function (elm) {
  22041. return name(elm) === 'caption';
  22042. });
  22043. };
  22044. var deleteBetweenCells = function (editor, rootElm, forward, fromCell, from) {
  22045. return CaretFinder.navigate(forward, editor.getBody(), from).bind(function (to) {
  22046. return getParentCell(rootElm, Element.fromDom(to.getNode())).map(function (toCell) {
  22047. return eq(toCell, fromCell) === false;
  22048. });
  22049. });
  22050. };
  22051. var emptyElement = function (editor, elm) {
  22052. PaddingBr.fillWithPaddingBr(elm);
  22053. editor.selection.setCursorLocation(elm.dom(), 0);
  22054. return Option.some(true);
  22055. };
  22056. var isDeleteOfLastCharPos = function (fromCaption, forward, from, to) {
  22057. return CaretFinder.firstPositionIn(fromCaption.dom()).bind(function (first) {
  22058. return CaretFinder.lastPositionIn(fromCaption.dom()).map(function (last) {
  22059. return forward ? from.isEqual(first) && to.isEqual(last) : from.isEqual(last) && to.isEqual(first);
  22060. });
  22061. }).getOr(true);
  22062. };
  22063. var emptyCaretCaption = function (editor, elm) {
  22064. return emptyElement(editor, elm);
  22065. };
  22066. var validateCaretCaption = function (rootElm, fromCaption, to) {
  22067. return getParentCaption(rootElm, Element.fromDom(to.getNode())).map(function (toCaption) {
  22068. return eq(toCaption, fromCaption) === false;
  22069. });
  22070. };
  22071. var deleteCaretInsideCaption = function (editor, rootElm, forward, fromCaption, from) {
  22072. return CaretFinder.navigate(forward, editor.getBody(), from).bind(function (to) {
  22073. return isDeleteOfLastCharPos(fromCaption, forward, from, to) ? emptyCaretCaption(editor, fromCaption) : validateCaretCaption(rootElm, fromCaption, to);
  22074. }).or(Option.some(true));
  22075. };
  22076. var deleteCaretCells = function (editor, forward, rootElm, startElm) {
  22077. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22078. return getParentCell(rootElm, startElm).bind(function (fromCell) {
  22079. return Empty.isEmpty(fromCell) ? emptyElement(editor, fromCell) : deleteBetweenCells(editor, rootElm, forward, fromCell, from);
  22080. }).getOr(false);
  22081. };
  22082. var deleteCaretCaption = function (editor, forward, rootElm, fromCaption) {
  22083. var from = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22084. return Empty.isEmpty(fromCaption) ? emptyElement(editor, fromCaption) : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from);
  22085. };
  22086. var isNearTable = function (forward, pos) {
  22087. return forward ? isBeforeTable(pos) : isAfterTable(pos);
  22088. };
  22089. var isBeforeOrAfterTable = function (editor, forward) {
  22090. var fromPos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22091. return isNearTable(forward, fromPos) || CaretFinder.fromPosition(forward, editor.getBody(), fromPos).map(function (pos) {
  22092. return isNearTable(forward, pos);
  22093. }).getOr(false);
  22094. };
  22095. var deleteCaret$1 = function (editor, forward, startElm) {
  22096. var rootElm = Element.fromDom(editor.getBody());
  22097. return getParentCaption(rootElm, startElm).fold(function () {
  22098. return deleteCaretCells(editor, forward, rootElm, startElm) || isBeforeOrAfterTable(editor, forward);
  22099. }, function (fromCaption) {
  22100. return deleteCaretCaption(editor, forward, rootElm, fromCaption).getOr(false);
  22101. });
  22102. };
  22103. var backspaceDelete$6 = function (editor, forward) {
  22104. var startElm = Element.fromDom(editor.selection.getStart(true));
  22105. var cells = TableCellSelection.getCellsFromEditor(editor);
  22106. return editor.selection.isCollapsed() && cells.length === 0 ? deleteCaret$1(editor, forward, startElm) : deleteRange$1(editor, startElm);
  22107. };
  22108. var TableDelete = { backspaceDelete: backspaceDelete$6 };
  22109. var deleteCaret$2 = function (editor, forward) {
  22110. var fromPos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22111. return CaretFinder.fromPosition(forward, editor.getBody(), fromPos).filter(function (pos) {
  22112. return forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos);
  22113. }).bind(function (pos) {
  22114. return Option.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, pos));
  22115. }).map(function (elm) {
  22116. editor.selection.select(elm);
  22117. return true;
  22118. }).getOr(false);
  22119. };
  22120. var backspaceDelete$7 = function (editor, forward) {
  22121. return editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : false;
  22122. };
  22123. var PageBreakDelete = { backspaceDelete: backspaceDelete$7 };
  22124. var isEditable$1 = function (target) {
  22125. return closest(target, function (elm) {
  22126. return NodeType.isContentEditableTrue(elm.dom()) || NodeType.isContentEditableFalse(elm.dom());
  22127. }).exists(function (elm) {
  22128. return NodeType.isContentEditableTrue(elm.dom());
  22129. });
  22130. };
  22131. var parseIndentValue = function (value) {
  22132. var number = parseInt(value, 10);
  22133. return isNaN(number) ? 0 : number;
  22134. };
  22135. var getIndentStyleName = function (useMargin, element) {
  22136. var indentStyleName = useMargin || isTable$1(element) ? 'margin' : 'padding';
  22137. var suffix = get$2(element, 'direction') === 'rtl' ? '-right' : '-left';
  22138. return indentStyleName + suffix;
  22139. };
  22140. var indentElement = function (dom, command, useMargin, value, unit, element) {
  22141. var indentStyleName = getIndentStyleName(useMargin, Element.fromDom(element));
  22142. if (command === 'outdent') {
  22143. var styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value);
  22144. dom.setStyle(element, indentStyleName, styleValue ? styleValue + unit : '');
  22145. } else {
  22146. var styleValue = parseIndentValue(element.style[indentStyleName]) + value + unit;
  22147. dom.setStyle(element, indentStyleName, styleValue);
  22148. }
  22149. };
  22150. var validateBlocks = function (editor, blocks) {
  22151. return forall(blocks, function (block) {
  22152. var indentStyleName = getIndentStyleName(Settings.shouldIndentUseMargin(editor), block);
  22153. var intentValue = getRaw(block, indentStyleName).map(parseIndentValue).getOr(0);
  22154. var contentEditable = editor.dom.getContentEditable(block.dom());
  22155. return contentEditable !== 'false' && intentValue > 0;
  22156. });
  22157. };
  22158. var canOutdent = function (editor) {
  22159. var blocks = getBlocksToIndent(editor);
  22160. return editor.readonly !== true && (blocks.length > 1 || validateBlocks(editor, blocks));
  22161. };
  22162. var isListComponent = function (el) {
  22163. return isList(el) || isListItem(el);
  22164. };
  22165. var parentIsListComponent = function (el) {
  22166. return parent(el).map(isListComponent).getOr(false);
  22167. };
  22168. var getBlocksToIndent = function (editor) {
  22169. return filter(map(editor.selection.getSelectedBlocks(), Element.fromDom), function (el) {
  22170. return !isListComponent(el) && !parentIsListComponent(el) && isEditable$1(el);
  22171. });
  22172. };
  22173. var handle = function (editor, command) {
  22174. var dom = editor.dom, selection = editor.selection, formatter = editor.formatter;
  22175. var indentation = Settings.getIndentation(editor);
  22176. var indentUnit = /[a-z%]+$/i.exec(indentation)[0];
  22177. var indentValue = parseInt(indentation, 10);
  22178. var useMargin = Settings.shouldIndentUseMargin(editor);
  22179. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  22180. if (!editor.queryCommandState('InsertUnorderedList') && !editor.queryCommandState('InsertOrderedList')) {
  22181. if (forcedRootBlock === '' && !dom.getParent(selection.getNode(), dom.isBlock)) {
  22182. formatter.apply('div');
  22183. }
  22184. }
  22185. each(getBlocksToIndent(editor), function (block) {
  22186. indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom());
  22187. });
  22188. };
  22189. var navigateIgnoreEmptyTextNodes = function (forward, root, from) {
  22190. return CaretFinder.navigateIgnore(forward, root, from, isEmptyText);
  22191. };
  22192. var getClosestBlock = function (root, pos) {
  22193. return find(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), isBlock);
  22194. };
  22195. var isAtBeforeAfterBlockBoundary = function (forward, root, pos) {
  22196. return navigateIgnoreEmptyTextNodes(forward, root.dom(), pos).forall(function (newPos) {
  22197. return getClosestBlock(root, pos).fold(function () {
  22198. return isInSameBlock(newPos, pos, root.dom()) === false;
  22199. }, function (fromBlock) {
  22200. return isInSameBlock(newPos, pos, root.dom()) === false && contains$2(fromBlock, Element.fromDom(newPos.container()));
  22201. });
  22202. });
  22203. };
  22204. var isAtBlockBoundary = function (forward, root, pos) {
  22205. return getClosestBlock(root, pos).fold(function () {
  22206. return navigateIgnoreEmptyTextNodes(forward, root.dom(), pos).forall(function (newPos) {
  22207. return isInSameBlock(newPos, pos, root.dom()) === false;
  22208. });
  22209. }, function (parent) {
  22210. return navigateIgnoreEmptyTextNodes(forward, parent.dom(), pos).isNone();
  22211. });
  22212. };
  22213. var isAtStartOfBlock = curry(isAtBlockBoundary, false);
  22214. var isAtEndOfBlock = curry(isAtBlockBoundary, true);
  22215. var isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false);
  22216. var isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true);
  22217. var backspaceDelete$8 = function (editor, _caret, _forward) {
  22218. if (editor.selection.isCollapsed() && canOutdent(editor)) {
  22219. var dom = editor.dom;
  22220. var rng = editor.selection.getRng();
  22221. var pos = CaretPosition$1.fromRangeStart(rng);
  22222. var block = dom.getParent(rng.startContainer, dom.isBlock);
  22223. if (block !== null && isAtStartOfBlock(Element.fromDom(block), pos)) {
  22224. handle(editor, 'outdent');
  22225. return true;
  22226. }
  22227. }
  22228. return false;
  22229. };
  22230. var Outdent = { backspaceDelete: backspaceDelete$8 };
  22231. var executeKeydownOverride$1 = function (editor, caret, evt) {
  22232. MatchKeys.execute([
  22233. {
  22234. keyCode: VK.BACKSPACE,
  22235. action: MatchKeys.action(Outdent.backspaceDelete, editor, false)
  22236. },
  22237. {
  22238. keyCode: VK.BACKSPACE,
  22239. action: MatchKeys.action(CefDelete.backspaceDelete, editor, false)
  22240. },
  22241. {
  22242. keyCode: VK.DELETE,
  22243. action: MatchKeys.action(CefDelete.backspaceDelete, editor, true)
  22244. },
  22245. {
  22246. keyCode: VK.BACKSPACE,
  22247. action: MatchKeys.action(CefBoundaryDelete.backspaceDelete, editor, false)
  22248. },
  22249. {
  22250. keyCode: VK.DELETE,
  22251. action: MatchKeys.action(CefBoundaryDelete.backspaceDelete, editor, true)
  22252. },
  22253. {
  22254. keyCode: VK.BACKSPACE,
  22255. action: MatchKeys.action(BoundaryDelete.backspaceDelete, editor, caret, false)
  22256. },
  22257. {
  22258. keyCode: VK.DELETE,
  22259. action: MatchKeys.action(BoundaryDelete.backspaceDelete, editor, caret, true)
  22260. },
  22261. {
  22262. keyCode: VK.BACKSPACE,
  22263. action: MatchKeys.action(TableDelete.backspaceDelete, editor, false)
  22264. },
  22265. {
  22266. keyCode: VK.DELETE,
  22267. action: MatchKeys.action(TableDelete.backspaceDelete, editor, true)
  22268. },
  22269. {
  22270. keyCode: VK.BACKSPACE,
  22271. action: MatchKeys.action(PageBreakDelete.backspaceDelete, editor, false)
  22272. },
  22273. {
  22274. keyCode: VK.DELETE,
  22275. action: MatchKeys.action(PageBreakDelete.backspaceDelete, editor, true)
  22276. },
  22277. {
  22278. keyCode: VK.BACKSPACE,
  22279. action: MatchKeys.action(BlockRangeDelete.backspaceDelete, editor, false)
  22280. },
  22281. {
  22282. keyCode: VK.DELETE,
  22283. action: MatchKeys.action(BlockRangeDelete.backspaceDelete, editor, true)
  22284. },
  22285. {
  22286. keyCode: VK.BACKSPACE,
  22287. action: MatchKeys.action(BlockBoundaryDelete.backspaceDelete, editor, false)
  22288. },
  22289. {
  22290. keyCode: VK.DELETE,
  22291. action: MatchKeys.action(BlockBoundaryDelete.backspaceDelete, editor, true)
  22292. },
  22293. {
  22294. keyCode: VK.BACKSPACE,
  22295. action: MatchKeys.action(InlineFormatDelete.backspaceDelete, editor, false)
  22296. },
  22297. {
  22298. keyCode: VK.DELETE,
  22299. action: MatchKeys.action(InlineFormatDelete.backspaceDelete, editor, true)
  22300. }
  22301. ], evt).each(function (_) {
  22302. evt.preventDefault();
  22303. });
  22304. };
  22305. var executeKeyupOverride = function (editor, evt) {
  22306. MatchKeys.execute([
  22307. {
  22308. keyCode: VK.BACKSPACE,
  22309. action: MatchKeys.action(CefDelete.paddEmptyElement, editor)
  22310. },
  22311. {
  22312. keyCode: VK.DELETE,
  22313. action: MatchKeys.action(CefDelete.paddEmptyElement, editor)
  22314. }
  22315. ], evt);
  22316. };
  22317. var setup$9 = function (editor, caret) {
  22318. editor.on('keydown', function (evt) {
  22319. if (evt.isDefaultPrevented() === false) {
  22320. executeKeydownOverride$1(editor, caret, evt);
  22321. }
  22322. });
  22323. editor.on('keyup', function (evt) {
  22324. if (evt.isDefaultPrevented() === false) {
  22325. executeKeyupOverride(editor, evt);
  22326. }
  22327. });
  22328. };
  22329. var DeleteBackspaceKeys = { setup: setup$9 };
  22330. var firstNonWhiteSpaceNodeSibling = function (node) {
  22331. while (node) {
  22332. if (node.nodeType === 1 || node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data)) {
  22333. return node;
  22334. }
  22335. node = node.nextSibling;
  22336. }
  22337. };
  22338. var moveToCaretPosition = function (editor, root) {
  22339. var node, rng, lastNode = root;
  22340. var dom = editor.dom;
  22341. var moveCaretBeforeOnEnterElementsMap = editor.schema.getMoveCaretBeforeOnEnterElements();
  22342. if (!root) {
  22343. return;
  22344. }
  22345. if (/^(LI|DT|DD)$/.test(root.nodeName)) {
  22346. var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild);
  22347. if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
  22348. root.insertBefore(dom.doc.createTextNode('\xA0'), root.firstChild);
  22349. }
  22350. }
  22351. rng = dom.createRng();
  22352. root.normalize();
  22353. if (root.hasChildNodes()) {
  22354. var walker = new TreeWalker(root, root);
  22355. while (node = walker.current()) {
  22356. if (NodeType.isText(node)) {
  22357. rng.setStart(node, 0);
  22358. rng.setEnd(node, 0);
  22359. break;
  22360. }
  22361. if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
  22362. rng.setStartBefore(node);
  22363. rng.setEndBefore(node);
  22364. break;
  22365. }
  22366. lastNode = node;
  22367. node = walker.next();
  22368. }
  22369. if (!node) {
  22370. rng.setStart(lastNode, 0);
  22371. rng.setEnd(lastNode, 0);
  22372. }
  22373. } else {
  22374. if (NodeType.isBr(root)) {
  22375. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  22376. rng.setStartBefore(root);
  22377. rng.setEndBefore(root);
  22378. } else {
  22379. rng.setStartAfter(root);
  22380. rng.setEndAfter(root);
  22381. }
  22382. } else {
  22383. rng.setStart(root, 0);
  22384. rng.setEnd(root, 0);
  22385. }
  22386. }
  22387. editor.selection.setRng(rng);
  22388. editor.selection.scrollIntoView(root);
  22389. };
  22390. var getEditableRoot = function (dom, node) {
  22391. var root = dom.getRoot();
  22392. var parent, editableRoot;
  22393. parent = node;
  22394. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  22395. if (dom.getContentEditable(parent) === 'true') {
  22396. editableRoot = parent;
  22397. }
  22398. parent = parent.parentNode;
  22399. }
  22400. return parent !== root ? editableRoot : root;
  22401. };
  22402. var getParentBlock$2 = function (editor) {
  22403. return Option.from(editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock));
  22404. };
  22405. var getParentBlockName = function (editor) {
  22406. return getParentBlock$2(editor).fold(constant(''), function (parentBlock) {
  22407. return parentBlock.nodeName.toUpperCase();
  22408. });
  22409. };
  22410. var isListItemParentBlock = function (editor) {
  22411. return getParentBlock$2(editor).filter(function (elm) {
  22412. return isListItem(Element.fromDom(elm));
  22413. }).isSome();
  22414. };
  22415. var NewLineUtils = {
  22416. moveToCaretPosition: moveToCaretPosition,
  22417. getEditableRoot: getEditableRoot,
  22418. getParentBlock: getParentBlock$2,
  22419. getParentBlockName: getParentBlockName,
  22420. isListItemParentBlock: isListItemParentBlock
  22421. };
  22422. var hasFirstChild = function (elm, name) {
  22423. return elm.firstChild && elm.firstChild.nodeName === name;
  22424. };
  22425. var hasParent$1 = function (elm, parentName) {
  22426. return elm && elm.parentNode && elm.parentNode.nodeName === parentName;
  22427. };
  22428. var isListBlock = function (elm) {
  22429. return elm && /^(OL|UL|LI)$/.test(elm.nodeName);
  22430. };
  22431. var isNestedList = function (elm) {
  22432. return isListBlock(elm) && isListBlock(elm.parentNode);
  22433. };
  22434. var getContainerBlock = function (containerBlock) {
  22435. var containerBlockParent = containerBlock.parentNode;
  22436. if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) {
  22437. return containerBlockParent;
  22438. }
  22439. return containerBlock;
  22440. };
  22441. var isFirstOrLastLi = function (containerBlock, parentBlock, first) {
  22442. var node = containerBlock[first ? 'firstChild' : 'lastChild'];
  22443. while (node) {
  22444. if (NodeType.isElement(node)) {
  22445. break;
  22446. }
  22447. node = node[first ? 'nextSibling' : 'previousSibling'];
  22448. }
  22449. return node === parentBlock;
  22450. };
  22451. var insert = function (editor, createNewBlock, containerBlock, parentBlock, newBlockName) {
  22452. var dom = editor.dom;
  22453. var rng = editor.selection.getRng();
  22454. if (containerBlock === editor.getBody()) {
  22455. return;
  22456. }
  22457. if (isNestedList(containerBlock)) {
  22458. newBlockName = 'LI';
  22459. }
  22460. var newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
  22461. if (isFirstOrLastLi(containerBlock, parentBlock, true) && isFirstOrLastLi(containerBlock, parentBlock, false)) {
  22462. if (hasParent$1(containerBlock, 'LI')) {
  22463. dom.insertAfter(newBlock, getContainerBlock(containerBlock));
  22464. } else {
  22465. dom.replace(newBlock, containerBlock);
  22466. }
  22467. } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) {
  22468. if (hasParent$1(containerBlock, 'LI')) {
  22469. dom.insertAfter(newBlock, getContainerBlock(containerBlock));
  22470. newBlock.appendChild(dom.doc.createTextNode(' '));
  22471. newBlock.appendChild(containerBlock);
  22472. } else {
  22473. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  22474. }
  22475. } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) {
  22476. dom.insertAfter(newBlock, getContainerBlock(containerBlock));
  22477. } else {
  22478. containerBlock = getContainerBlock(containerBlock);
  22479. var tmpRng = rng.cloneRange();
  22480. tmpRng.setStartAfter(parentBlock);
  22481. tmpRng.setEndAfter(containerBlock);
  22482. var fragment = tmpRng.extractContents();
  22483. if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) {
  22484. newBlock = fragment.firstChild;
  22485. dom.insertAfter(fragment, containerBlock);
  22486. } else {
  22487. dom.insertAfter(fragment, containerBlock);
  22488. dom.insertAfter(newBlock, containerBlock);
  22489. }
  22490. }
  22491. dom.remove(parentBlock);
  22492. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22493. };
  22494. var InsertLi = { insert: insert };
  22495. var trimZwsp = function (fragment) {
  22496. each(descendants(Element.fromDom(fragment), isText$1), function (text) {
  22497. var rawNode = text.dom();
  22498. rawNode.nodeValue = Zwsp.trim(rawNode.nodeValue);
  22499. });
  22500. };
  22501. var isEmptyAnchor = function (dom, elm) {
  22502. return elm && elm.nodeName === 'A' && dom.isEmpty(elm);
  22503. };
  22504. var isTableCell$4 = function (node) {
  22505. return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
  22506. };
  22507. var emptyBlock = function (elm) {
  22508. elm.innerHTML = '<br data-mce-bogus="1">';
  22509. };
  22510. var containerAndSiblingName = function (container, nodeName) {
  22511. return container.nodeName === nodeName || container.previousSibling && container.previousSibling.nodeName === nodeName;
  22512. };
  22513. var canSplitBlock = function (dom, node) {
  22514. return node && dom.isBlock(node) && !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) && !/^(fixed|absolute)/i.test(node.style.position) && dom.getContentEditable(node) !== 'true';
  22515. };
  22516. var trimInlineElementsOnLeftSideOfBlock = function (dom, nonEmptyElementsMap, block) {
  22517. var node = block;
  22518. var firstChilds = [];
  22519. var i;
  22520. if (!node) {
  22521. return;
  22522. }
  22523. while (node = node.firstChild) {
  22524. if (dom.isBlock(node)) {
  22525. return;
  22526. }
  22527. if (NodeType.isElement(node) && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  22528. firstChilds.push(node);
  22529. }
  22530. }
  22531. i = firstChilds.length;
  22532. while (i--) {
  22533. node = firstChilds[i];
  22534. if (!node.hasChildNodes() || node.firstChild === node.lastChild && node.firstChild.nodeValue === '') {
  22535. dom.remove(node);
  22536. } else {
  22537. if (isEmptyAnchor(dom, node)) {
  22538. dom.remove(node);
  22539. }
  22540. }
  22541. }
  22542. };
  22543. var normalizeZwspOffset = function (start, container, offset) {
  22544. if (NodeType.isText(container) === false) {
  22545. return offset;
  22546. } else if (start) {
  22547. return offset === 1 && container.data.charAt(offset - 1) === Zwsp.ZWSP ? 0 : offset;
  22548. } else {
  22549. return offset === container.data.length - 1 && container.data.charAt(offset) === Zwsp.ZWSP ? container.data.length : offset;
  22550. }
  22551. };
  22552. var includeZwspInRange = function (rng) {
  22553. var newRng = rng.cloneRange();
  22554. newRng.setStart(rng.startContainer, normalizeZwspOffset(true, rng.startContainer, rng.startOffset));
  22555. newRng.setEnd(rng.endContainer, normalizeZwspOffset(false, rng.endContainer, rng.endOffset));
  22556. return newRng;
  22557. };
  22558. var trimLeadingLineBreaks = function (node) {
  22559. do {
  22560. if (NodeType.isText(node)) {
  22561. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
  22562. }
  22563. node = node.firstChild;
  22564. } while (node);
  22565. };
  22566. var getEditableRoot$1 = function (dom, node) {
  22567. var root = dom.getRoot();
  22568. var parent, editableRoot;
  22569. parent = node;
  22570. while (parent !== root && dom.getContentEditable(parent) !== 'false') {
  22571. if (dom.getContentEditable(parent) === 'true') {
  22572. editableRoot = parent;
  22573. }
  22574. parent = parent.parentNode;
  22575. }
  22576. return parent !== root ? editableRoot : root;
  22577. };
  22578. var setForcedBlockAttrs = function (editor, node) {
  22579. var forcedRootBlockName = Settings.getForcedRootBlock(editor);
  22580. if (forcedRootBlockName && forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()) {
  22581. editor.dom.setAttribs(node, Settings.getForcedRootBlockAttrs(editor));
  22582. }
  22583. };
  22584. var wrapSelfAndSiblingsInDefaultBlock = function (editor, newBlockName, rng, container, offset) {
  22585. var newBlock, parentBlock, startNode, node, next, rootBlockName;
  22586. var blockName = newBlockName || 'P';
  22587. var dom = editor.dom, editableRoot = getEditableRoot$1(dom, container);
  22588. parentBlock = dom.getParent(container, dom.isBlock);
  22589. if (!parentBlock || !canSplitBlock(dom, parentBlock)) {
  22590. parentBlock = parentBlock || editableRoot;
  22591. if (parentBlock === editor.getBody() || isTableCell$4(parentBlock)) {
  22592. rootBlockName = parentBlock.nodeName.toLowerCase();
  22593. } else {
  22594. rootBlockName = parentBlock.parentNode.nodeName.toLowerCase();
  22595. }
  22596. if (!parentBlock.hasChildNodes()) {
  22597. newBlock = dom.create(blockName);
  22598. setForcedBlockAttrs(editor, newBlock);
  22599. parentBlock.appendChild(newBlock);
  22600. rng.setStart(newBlock, 0);
  22601. rng.setEnd(newBlock, 0);
  22602. return newBlock;
  22603. }
  22604. node = container;
  22605. while (node.parentNode !== parentBlock) {
  22606. node = node.parentNode;
  22607. }
  22608. while (node && !dom.isBlock(node)) {
  22609. startNode = node;
  22610. node = node.previousSibling;
  22611. }
  22612. if (startNode && editor.schema.isValidChild(rootBlockName, blockName.toLowerCase())) {
  22613. newBlock = dom.create(blockName);
  22614. setForcedBlockAttrs(editor, newBlock);
  22615. startNode.parentNode.insertBefore(newBlock, startNode);
  22616. node = startNode;
  22617. while (node && !dom.isBlock(node)) {
  22618. next = node.nextSibling;
  22619. newBlock.appendChild(node);
  22620. node = next;
  22621. }
  22622. rng.setStart(container, offset);
  22623. rng.setEnd(container, offset);
  22624. }
  22625. }
  22626. return container;
  22627. };
  22628. var addBrToBlockIfNeeded = function (dom, block) {
  22629. var lastChild;
  22630. block.normalize();
  22631. lastChild = block.lastChild;
  22632. if (!lastChild || /^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true))) {
  22633. dom.add(block, 'br');
  22634. }
  22635. };
  22636. var insert$1 = function (editor, evt) {
  22637. var tmpRng, editableRoot, container, offset, parentBlock, shiftKey;
  22638. var newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
  22639. var dom = editor.dom;
  22640. var schema = editor.schema, nonEmptyElementsMap = schema.getNonEmptyElements();
  22641. var rng = editor.selection.getRng();
  22642. var createNewBlock = function (name) {
  22643. var node = container, block, clonedNode, caretNode;
  22644. var textInlineElements = schema.getTextInlineElements();
  22645. if (name || parentBlockName === 'TABLE' || parentBlockName === 'HR') {
  22646. block = dom.create(name || newBlockName);
  22647. setForcedBlockAttrs(editor, block);
  22648. } else {
  22649. block = parentBlock.cloneNode(false);
  22650. }
  22651. caretNode = block;
  22652. if (Settings.shouldKeepStyles(editor) === false) {
  22653. dom.setAttrib(block, 'style', null);
  22654. dom.setAttrib(block, 'class', null);
  22655. } else {
  22656. do {
  22657. if (textInlineElements[node.nodeName]) {
  22658. if (isCaretNode(node) || Bookmarks.isBookmarkNode(node)) {
  22659. continue;
  22660. }
  22661. clonedNode = node.cloneNode(false);
  22662. dom.setAttrib(clonedNode, 'id', '');
  22663. if (block.hasChildNodes()) {
  22664. clonedNode.appendChild(block.firstChild);
  22665. block.appendChild(clonedNode);
  22666. } else {
  22667. caretNode = clonedNode;
  22668. block.appendChild(clonedNode);
  22669. }
  22670. }
  22671. } while ((node = node.parentNode) && node !== editableRoot);
  22672. }
  22673. emptyBlock(caretNode);
  22674. return block;
  22675. };
  22676. var isCaretAtStartOrEndOfBlock = function (start) {
  22677. var node, name;
  22678. var normalizedOffset = normalizeZwspOffset(start, container, offset);
  22679. if (NodeType.isText(container) && (start ? normalizedOffset > 0 : normalizedOffset < container.nodeValue.length)) {
  22680. return false;
  22681. }
  22682. if (container.parentNode === parentBlock && isAfterLastNodeInContainer && !start) {
  22683. return true;
  22684. }
  22685. if (start && NodeType.isElement(container) && container === parentBlock.firstChild) {
  22686. return true;
  22687. }
  22688. if (containerAndSiblingName(container, 'TABLE') || containerAndSiblingName(container, 'HR')) {
  22689. return isAfterLastNodeInContainer && !start || !isAfterLastNodeInContainer && start;
  22690. }
  22691. var walker = new TreeWalker(container, parentBlock);
  22692. if (NodeType.isText(container)) {
  22693. if (start && normalizedOffset === 0) {
  22694. walker.prev();
  22695. } else if (!start && normalizedOffset === container.nodeValue.length) {
  22696. walker.next();
  22697. }
  22698. }
  22699. while (node = walker.current()) {
  22700. if (NodeType.isElement(node)) {
  22701. if (!node.getAttribute('data-mce-bogus')) {
  22702. name = node.nodeName.toLowerCase();
  22703. if (nonEmptyElementsMap[name] && name !== 'br') {
  22704. return false;
  22705. }
  22706. }
  22707. } else if (NodeType.isText(node) && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
  22708. return false;
  22709. }
  22710. if (start) {
  22711. walker.prev();
  22712. } else {
  22713. walker.next();
  22714. }
  22715. }
  22716. return true;
  22717. };
  22718. var insertNewBlockAfter = function () {
  22719. if (/^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) && containerBlockName !== 'HGROUP') {
  22720. newBlock = createNewBlock(newBlockName);
  22721. } else {
  22722. newBlock = createNewBlock();
  22723. }
  22724. if (Settings.shouldEndContainerOnEmptyBlock(editor) && canSplitBlock(dom, containerBlock) && dom.isEmpty(parentBlock)) {
  22725. newBlock = dom.split(containerBlock, parentBlock);
  22726. } else {
  22727. dom.insertAfter(newBlock, parentBlock);
  22728. }
  22729. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22730. };
  22731. NormalizeRange.normalize(dom, rng).each(function (normRng) {
  22732. rng.setStart(normRng.startContainer, normRng.startOffset);
  22733. rng.setEnd(normRng.endContainer, normRng.endOffset);
  22734. });
  22735. container = rng.startContainer;
  22736. offset = rng.startOffset;
  22737. newBlockName = Settings.getForcedRootBlock(editor);
  22738. shiftKey = !!(evt && evt.shiftKey);
  22739. var ctrlKey = !!(evt && evt.ctrlKey);
  22740. if (NodeType.isElement(container) && container.hasChildNodes()) {
  22741. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  22742. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  22743. if (isAfterLastNodeInContainer && NodeType.isText(container)) {
  22744. offset = container.nodeValue.length;
  22745. } else {
  22746. offset = 0;
  22747. }
  22748. }
  22749. editableRoot = getEditableRoot$1(dom, container);
  22750. if (!editableRoot) {
  22751. return;
  22752. }
  22753. if (newBlockName && !shiftKey || !newBlockName && shiftKey) {
  22754. container = wrapSelfAndSiblingsInDefaultBlock(editor, newBlockName, rng, container, offset);
  22755. }
  22756. parentBlock = dom.getParent(container, dom.isBlock);
  22757. containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  22758. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : '';
  22759. containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : '';
  22760. if (containerBlockName === 'LI' && !ctrlKey) {
  22761. parentBlock = containerBlock;
  22762. containerBlock = containerBlock.parentNode;
  22763. parentBlockName = containerBlockName;
  22764. }
  22765. if (/^(LI|DT|DD)$/.test(parentBlockName)) {
  22766. if (dom.isEmpty(parentBlock)) {
  22767. InsertLi.insert(editor, createNewBlock, containerBlock, parentBlock, newBlockName);
  22768. return;
  22769. }
  22770. }
  22771. if (newBlockName && parentBlock === editor.getBody()) {
  22772. return;
  22773. }
  22774. newBlockName = newBlockName || 'P';
  22775. if (isCaretContainerBlock(parentBlock)) {
  22776. newBlock = showCaretContainerBlock(parentBlock);
  22777. if (dom.isEmpty(parentBlock)) {
  22778. emptyBlock(parentBlock);
  22779. }
  22780. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22781. } else if (isCaretAtStartOrEndOfBlock()) {
  22782. insertNewBlockAfter();
  22783. } else if (isCaretAtStartOrEndOfBlock(true)) {
  22784. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  22785. NewLineUtils.moveToCaretPosition(editor, containerAndSiblingName(parentBlock, 'HR') ? newBlock : parentBlock);
  22786. } else {
  22787. tmpRng = includeZwspInRange(rng).cloneRange();
  22788. tmpRng.setEndAfter(parentBlock);
  22789. fragment = tmpRng.extractContents();
  22790. trimZwsp(fragment);
  22791. trimLeadingLineBreaks(fragment);
  22792. newBlock = fragment.firstChild;
  22793. dom.insertAfter(fragment, parentBlock);
  22794. trimInlineElementsOnLeftSideOfBlock(dom, nonEmptyElementsMap, newBlock);
  22795. addBrToBlockIfNeeded(dom, parentBlock);
  22796. if (dom.isEmpty(parentBlock)) {
  22797. emptyBlock(parentBlock);
  22798. }
  22799. newBlock.normalize();
  22800. if (dom.isEmpty(newBlock)) {
  22801. dom.remove(newBlock);
  22802. insertNewBlockAfter();
  22803. } else {
  22804. NewLineUtils.moveToCaretPosition(editor, newBlock);
  22805. }
  22806. }
  22807. dom.setAttrib(newBlock, 'id', '');
  22808. editor.fire('NewBlock', { newBlock: newBlock });
  22809. };
  22810. var InsertBlock = { insert: insert$1 };
  22811. var hasRightSideContent = function (schema, container, parentBlock) {
  22812. var walker = new TreeWalker(container, parentBlock);
  22813. var node;
  22814. var nonEmptyElementsMap = schema.getNonEmptyElements();
  22815. while (node = walker.next()) {
  22816. if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
  22817. return true;
  22818. }
  22819. }
  22820. };
  22821. var scrollToBr = function (dom, selection, brElm) {
  22822. var marker = dom.create('span', {}, '&nbsp;');
  22823. brElm.parentNode.insertBefore(marker, brElm);
  22824. selection.scrollIntoView(marker);
  22825. dom.remove(marker);
  22826. };
  22827. var moveSelectionToBr = function (dom, selection, brElm, extraBr) {
  22828. var rng = dom.createRng();
  22829. if (!extraBr) {
  22830. rng.setStartAfter(brElm);
  22831. rng.setEndAfter(brElm);
  22832. } else {
  22833. rng.setStartBefore(brElm);
  22834. rng.setEndBefore(brElm);
  22835. }
  22836. selection.setRng(rng);
  22837. };
  22838. var insertBrAtCaret = function (editor, evt) {
  22839. var selection = editor.selection;
  22840. var dom = editor.dom;
  22841. var rng = selection.getRng();
  22842. var brElm;
  22843. var extraBr;
  22844. NormalizeRange.normalize(dom, rng).each(function (normRng) {
  22845. rng.setStart(normRng.startContainer, normRng.startOffset);
  22846. rng.setEnd(normRng.endContainer, normRng.endOffset);
  22847. });
  22848. var offset = rng.startOffset;
  22849. var container = rng.startContainer;
  22850. if (container.nodeType === 1 && container.hasChildNodes()) {
  22851. var isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  22852. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  22853. if (isAfterLastNodeInContainer && container.nodeType === 3) {
  22854. offset = container.nodeValue.length;
  22855. } else {
  22856. offset = 0;
  22857. }
  22858. }
  22859. var parentBlock = dom.getParent(container, dom.isBlock);
  22860. var containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  22861. var containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : '';
  22862. var isControlKey = !!(evt && evt.ctrlKey);
  22863. if (containerBlockName === 'LI' && !isControlKey) {
  22864. parentBlock = containerBlock;
  22865. }
  22866. if (container && container.nodeType === 3 && offset >= container.nodeValue.length) {
  22867. if (!hasRightSideContent(editor.schema, container, parentBlock)) {
  22868. brElm = dom.create('br');
  22869. rng.insertNode(brElm);
  22870. rng.setStartAfter(brElm);
  22871. rng.setEndAfter(brElm);
  22872. extraBr = true;
  22873. }
  22874. }
  22875. brElm = dom.create('br');
  22876. rangeInsertNode(dom, rng, brElm);
  22877. scrollToBr(dom, selection, brElm);
  22878. moveSelectionToBr(dom, selection, brElm, extraBr);
  22879. editor.undoManager.add();
  22880. };
  22881. var insertBrBefore = function (editor, inline) {
  22882. var br = Element.fromTag('br');
  22883. before(Element.fromDom(inline), br);
  22884. editor.undoManager.add();
  22885. };
  22886. var insertBrAfter = function (editor, inline) {
  22887. if (!hasBrAfter(editor.getBody(), inline)) {
  22888. after(Element.fromDom(inline), Element.fromTag('br'));
  22889. }
  22890. var br = Element.fromTag('br');
  22891. after(Element.fromDom(inline), br);
  22892. scrollToBr(editor.dom, editor.selection, br.dom());
  22893. moveSelectionToBr(editor.dom, editor.selection, br.dom(), false);
  22894. editor.undoManager.add();
  22895. };
  22896. var isBeforeBr$1 = function (pos) {
  22897. return NodeType.isBr(pos.getNode());
  22898. };
  22899. var hasBrAfter = function (rootNode, startNode) {
  22900. if (isBeforeBr$1(CaretPosition$1.after(startNode))) {
  22901. return true;
  22902. } else {
  22903. return CaretFinder.nextPosition(rootNode, CaretPosition$1.after(startNode)).map(function (pos) {
  22904. return NodeType.isBr(pos.getNode());
  22905. }).getOr(false);
  22906. }
  22907. };
  22908. var isAnchorLink = function (elm) {
  22909. return elm && elm.nodeName === 'A' && 'href' in elm;
  22910. };
  22911. var isInsideAnchor = function (location) {
  22912. return location.fold(constant(false), isAnchorLink, isAnchorLink, constant(false));
  22913. };
  22914. var readInlineAnchorLocation = function (editor) {
  22915. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  22916. var position = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  22917. return BoundaryLocation.readLocation(isInlineTarget, editor.getBody(), position).filter(isInsideAnchor);
  22918. };
  22919. var insertBrOutsideAnchor = function (editor, location) {
  22920. location.fold(noop, curry(insertBrBefore, editor), curry(insertBrAfter, editor), noop);
  22921. };
  22922. var insert$2 = function (editor, evt) {
  22923. var anchorLocation = readInlineAnchorLocation(editor);
  22924. if (anchorLocation.isSome()) {
  22925. anchorLocation.each(curry(insertBrOutsideAnchor, editor));
  22926. } else {
  22927. insertBrAtCaret(editor, evt);
  22928. }
  22929. };
  22930. var InsertBr = { insert: insert$2 };
  22931. var matchesSelector = function (editor, selector) {
  22932. return NewLineUtils.getParentBlock(editor).filter(function (parentBlock) {
  22933. return selector.length > 0 && is(Element.fromDom(parentBlock), selector);
  22934. }).isSome();
  22935. };
  22936. var shouldInsertBr = function (editor) {
  22937. return matchesSelector(editor, Settings.getBrNewLineSelector(editor));
  22938. };
  22939. var shouldBlockNewLine = function (editor) {
  22940. return matchesSelector(editor, Settings.getNoNewLineSelector(editor));
  22941. };
  22942. var ContextSelectors = {
  22943. shouldInsertBr: shouldInsertBr,
  22944. shouldBlockNewLine: shouldBlockNewLine
  22945. };
  22946. var newLineAction = Adt.generate([
  22947. { br: [] },
  22948. { block: [] },
  22949. { none: [] }
  22950. ]);
  22951. var shouldBlockNewLine$1 = function (editor, shiftKey) {
  22952. return ContextSelectors.shouldBlockNewLine(editor);
  22953. };
  22954. var isBrMode = function (requiredState) {
  22955. return function (editor, shiftKey) {
  22956. var brMode = Settings.getForcedRootBlock(editor) === '';
  22957. return brMode === requiredState;
  22958. };
  22959. };
  22960. var inListBlock = function (requiredState) {
  22961. return function (editor, shiftKey) {
  22962. return NewLineUtils.isListItemParentBlock(editor) === requiredState;
  22963. };
  22964. };
  22965. var inBlock = function (blockName, requiredState) {
  22966. return function (editor, shiftKey) {
  22967. var state = NewLineUtils.getParentBlockName(editor) === blockName.toUpperCase();
  22968. return state === requiredState;
  22969. };
  22970. };
  22971. var inPreBlock = function (requiredState) {
  22972. return inBlock('pre', requiredState);
  22973. };
  22974. var inSummaryBlock = function () {
  22975. return inBlock('summary', true);
  22976. };
  22977. var shouldPutBrInPre$1 = function (requiredState) {
  22978. return function (editor, shiftKey) {
  22979. return Settings.shouldPutBrInPre(editor) === requiredState;
  22980. };
  22981. };
  22982. var inBrContext = function (editor, shiftKey) {
  22983. return ContextSelectors.shouldInsertBr(editor);
  22984. };
  22985. var hasShiftKey = function (editor, shiftKey) {
  22986. return shiftKey;
  22987. };
  22988. var canInsertIntoEditableRoot = function (editor) {
  22989. var forcedRootBlock = Settings.getForcedRootBlock(editor);
  22990. var rootEditable = NewLineUtils.getEditableRoot(editor.dom, editor.selection.getStart());
  22991. return rootEditable && editor.schema.isValidChild(rootEditable.nodeName, forcedRootBlock ? forcedRootBlock : 'P');
  22992. };
  22993. var match$2 = function (predicates, action) {
  22994. return function (editor, shiftKey) {
  22995. var isMatch = foldl(predicates, function (res, p) {
  22996. return res && p(editor, shiftKey);
  22997. }, true);
  22998. return isMatch ? Option.some(action) : Option.none();
  22999. };
  23000. };
  23001. var getAction$1 = function (editor, evt) {
  23002. return LazyEvaluator.evaluateUntil([
  23003. match$2([shouldBlockNewLine$1], newLineAction.none()),
  23004. match$2([inSummaryBlock()], newLineAction.br()),
  23005. match$2([
  23006. inPreBlock(true),
  23007. shouldPutBrInPre$1(false),
  23008. hasShiftKey
  23009. ], newLineAction.br()),
  23010. match$2([
  23011. inPreBlock(true),
  23012. shouldPutBrInPre$1(false)
  23013. ], newLineAction.block()),
  23014. match$2([
  23015. inPreBlock(true),
  23016. shouldPutBrInPre$1(true),
  23017. hasShiftKey
  23018. ], newLineAction.block()),
  23019. match$2([
  23020. inPreBlock(true),
  23021. shouldPutBrInPre$1(true)
  23022. ], newLineAction.br()),
  23023. match$2([
  23024. inListBlock(true),
  23025. hasShiftKey
  23026. ], newLineAction.br()),
  23027. match$2([inListBlock(true)], newLineAction.block()),
  23028. match$2([
  23029. isBrMode(true),
  23030. hasShiftKey,
  23031. canInsertIntoEditableRoot
  23032. ], newLineAction.block()),
  23033. match$2([isBrMode(true)], newLineAction.br()),
  23034. match$2([inBrContext], newLineAction.br()),
  23035. match$2([
  23036. isBrMode(false),
  23037. hasShiftKey
  23038. ], newLineAction.br()),
  23039. match$2([canInsertIntoEditableRoot], newLineAction.block())
  23040. ], [
  23041. editor,
  23042. !!(evt && evt.shiftKey)
  23043. ]).getOr(newLineAction.none());
  23044. };
  23045. var NewLineAction = { getAction: getAction$1 };
  23046. var insert$3 = function (editor, evt) {
  23047. NewLineAction.getAction(editor, evt).fold(function () {
  23048. InsertBr.insert(editor, evt);
  23049. }, function () {
  23050. InsertBlock.insert(editor, evt);
  23051. }, noop);
  23052. };
  23053. var InsertNewLine = { insert: insert$3 };
  23054. var handleEnterKeyEvent = function (editor, event) {
  23055. if (event.isDefaultPrevented()) {
  23056. return;
  23057. }
  23058. event.preventDefault();
  23059. endTypingLevelIgnoreLocks(editor.undoManager);
  23060. editor.undoManager.transact(function () {
  23061. if (editor.selection.isCollapsed() === false) {
  23062. editor.execCommand('Delete');
  23063. }
  23064. InsertNewLine.insert(editor, event);
  23065. });
  23066. };
  23067. var setup$a = function (editor) {
  23068. editor.on('keydown', function (event) {
  23069. if (event.keyCode === VK.ENTER) {
  23070. handleEnterKeyEvent(editor, event);
  23071. }
  23072. });
  23073. };
  23074. var EnterKey = { setup: setup$a };
  23075. var insertTextAtPosition = function (text, pos) {
  23076. var container = pos.container();
  23077. var offset = pos.offset();
  23078. if (NodeType.isText(container)) {
  23079. container.insertData(offset, text);
  23080. return Option.some(CaretPosition(container, offset + text.length));
  23081. } else {
  23082. return getElementFromPosition(pos).map(function (elm) {
  23083. var textNode = Element.fromText(text);
  23084. if (pos.isAtEnd()) {
  23085. after(elm, textNode);
  23086. } else {
  23087. before(elm, textNode);
  23088. }
  23089. return CaretPosition(textNode.dom(), text.length);
  23090. });
  23091. }
  23092. };
  23093. var insertNbspAtPosition = curry(insertTextAtPosition, '\xA0');
  23094. var insertSpaceAtPosition = curry(insertTextAtPosition, ' ');
  23095. var nbsp = '\xA0';
  23096. var isInMiddleOfText = function (pos) {
  23097. return CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd();
  23098. };
  23099. var getClosestBlock$1 = function (root, pos) {
  23100. var parentBlocks = filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), isBlock);
  23101. return head(parentBlocks).getOr(root);
  23102. };
  23103. var hasSpaceBefore = function (root, pos) {
  23104. if (isInMiddleOfText(pos)) {
  23105. return isAfterSpace(pos);
  23106. } else {
  23107. return isAfterSpace(pos) || CaretFinder.prevPosition(getClosestBlock$1(root, pos).dom(), pos).exists(isAfterSpace);
  23108. }
  23109. };
  23110. var hasSpaceAfter = function (root, pos) {
  23111. if (isInMiddleOfText(pos)) {
  23112. return isBeforeSpace(pos);
  23113. } else {
  23114. return isBeforeSpace(pos) || CaretFinder.nextPosition(getClosestBlock$1(root, pos).dom(), pos).exists(isBeforeSpace);
  23115. }
  23116. };
  23117. var isPreValue = function (value) {
  23118. return contains([
  23119. 'pre',
  23120. 'pre-wrap'
  23121. ], value);
  23122. };
  23123. var isInPre = function (pos) {
  23124. return getElementFromPosition(pos).bind(function (elm) {
  23125. return closest(elm, isElement$1);
  23126. }).exists(function (elm) {
  23127. return isPreValue(get$2(elm, 'white-space'));
  23128. });
  23129. };
  23130. var isAtBeginningOfBody = function (root, pos) {
  23131. return CaretFinder.prevPosition(root.dom(), pos).isNone();
  23132. };
  23133. var isAtEndOfBody = function (root, pos) {
  23134. return CaretFinder.nextPosition(root.dom(), pos).isNone();
  23135. };
  23136. var isAtLineBoundary = function (root, pos) {
  23137. return isAtBeginningOfBody(root, pos) || isAtEndOfBody(root, pos) || isAtStartOfBlock(root, pos) || isAtEndOfBlock(root, pos) || isAfterBr(root, pos) || isBeforeBr(root, pos);
  23138. };
  23139. var needsToHaveNbsp = function (root, pos) {
  23140. if (isInPre(pos)) {
  23141. return false;
  23142. } else {
  23143. return isAtLineBoundary(root, pos) || hasSpaceBefore(root, pos) || hasSpaceAfter(root, pos);
  23144. }
  23145. };
  23146. var needsToBeNbspLeft = function (root, pos) {
  23147. if (isInPre(pos)) {
  23148. return false;
  23149. } else {
  23150. return isAtStartOfBlock(root, pos) || isBeforeBlock(root, pos) || isAfterBr(root, pos) || hasSpaceBefore(root, pos);
  23151. }
  23152. };
  23153. var leanRight = function (pos) {
  23154. var container = pos.container();
  23155. var offset = pos.offset();
  23156. if (NodeType.isText(container) && offset < container.data.length) {
  23157. return CaretPosition(container, offset + 1);
  23158. } else {
  23159. return pos;
  23160. }
  23161. };
  23162. var needsToBeNbspRight = function (root, pos) {
  23163. var afterPos = leanRight(pos);
  23164. if (isInPre(afterPos)) {
  23165. return false;
  23166. } else {
  23167. return isAtEndOfBlock(root, afterPos) || isAfterBlock(root, afterPos) || isBeforeBr(root, afterPos) || hasSpaceAfter(root, afterPos);
  23168. }
  23169. };
  23170. var needsToBeNbsp = function (root, pos) {
  23171. return needsToBeNbspLeft(root, pos) || needsToBeNbspRight(root, pos);
  23172. };
  23173. var isNbspAt = function (text, offset) {
  23174. return isNbsp(text.charAt(offset));
  23175. };
  23176. var hasNbsp = function (pos) {
  23177. var container = pos.container();
  23178. return NodeType.isText(container) && contains$1(container.data, nbsp);
  23179. };
  23180. var normalizeNbspMiddle = function (text) {
  23181. var chars = text.split('');
  23182. return map(chars, function (chr, i) {
  23183. if (isNbsp(chr) && i > 0 && i < chars.length - 1 && isContent(chars[i - 1]) && isContent(chars[i + 1])) {
  23184. return ' ';
  23185. } else {
  23186. return chr;
  23187. }
  23188. }).join('');
  23189. };
  23190. var normalizeNbspAtStart = function (root, node) {
  23191. var text = node.data;
  23192. var firstPos = CaretPosition(node, 0);
  23193. if (isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos)) {
  23194. node.data = ' ' + text.slice(1);
  23195. return true;
  23196. } else {
  23197. return false;
  23198. }
  23199. };
  23200. var normalizeNbspInMiddleOfTextNode = function (node) {
  23201. var text = node.data;
  23202. var newText = normalizeNbspMiddle(text);
  23203. if (newText !== text) {
  23204. node.data = newText;
  23205. return true;
  23206. } else {
  23207. return false;
  23208. }
  23209. };
  23210. var normalizeNbspAtEnd = function (root, node) {
  23211. var text = node.data;
  23212. var lastPos = CaretPosition(node, text.length - 1);
  23213. if (isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos)) {
  23214. node.data = text.slice(0, -1) + ' ';
  23215. return true;
  23216. } else {
  23217. return false;
  23218. }
  23219. };
  23220. var normalizeNbsps = function (root, pos) {
  23221. return Option.some(pos).filter(hasNbsp).bind(function (pos) {
  23222. var container = pos.container();
  23223. var normalized = normalizeNbspAtStart(root, container) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container);
  23224. return normalized ? Option.some(pos) : Option.none();
  23225. });
  23226. };
  23227. var normalizeNbspsInEditor = function (editor) {
  23228. var root = Element.fromDom(editor.getBody());
  23229. if (editor.selection.isCollapsed()) {
  23230. normalizeNbsps(root, CaretPosition.fromRangeStart(editor.selection.getRng())).each(function (pos) {
  23231. editor.selection.setRng(pos.toRange());
  23232. });
  23233. }
  23234. };
  23235. var locationToCaretPosition = function (root) {
  23236. return function (location) {
  23237. return location.fold(function (element) {
  23238. return CaretFinder.prevPosition(root.dom(), CaretPosition$1.before(element));
  23239. }, function (element) {
  23240. return CaretFinder.firstPositionIn(element);
  23241. }, function (element) {
  23242. return CaretFinder.lastPositionIn(element);
  23243. }, function (element) {
  23244. return CaretFinder.nextPosition(root.dom(), CaretPosition$1.after(element));
  23245. });
  23246. };
  23247. };
  23248. var insertInlineBoundarySpaceOrNbsp = function (root, pos) {
  23249. return function (checkPos) {
  23250. return needsToHaveNbsp(root, checkPos) ? insertNbspAtPosition(pos) : insertSpaceAtPosition(pos);
  23251. };
  23252. };
  23253. var setSelection$1 = function (editor) {
  23254. return function (pos) {
  23255. editor.selection.setRng(pos.toRange());
  23256. editor.nodeChanged();
  23257. return true;
  23258. };
  23259. };
  23260. var insertSpaceOrNbspAtSelection = function (editor) {
  23261. var pos = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  23262. var root = Element.fromDom(editor.getBody());
  23263. if (editor.selection.isCollapsed()) {
  23264. var isInlineTarget = curry(InlineUtils.isInlineTarget, editor);
  23265. var caretPosition = CaretPosition$1.fromRangeStart(editor.selection.getRng());
  23266. return BoundaryLocation.readLocation(isInlineTarget, editor.getBody(), caretPosition).bind(locationToCaretPosition(root)).bind(insertInlineBoundarySpaceOrNbsp(root, pos)).exists(setSelection$1(editor));
  23267. } else {
  23268. return false;
  23269. }
  23270. };
  23271. var executeKeydownOverride$2 = function (editor, evt) {
  23272. MatchKeys.execute([{
  23273. keyCode: VK.SPACEBAR,
  23274. action: MatchKeys.action(insertSpaceOrNbspAtSelection, editor)
  23275. }], evt).each(function (_) {
  23276. evt.preventDefault();
  23277. });
  23278. };
  23279. var setup$b = function (editor) {
  23280. editor.on('keydown', function (evt) {
  23281. if (evt.isDefaultPrevented() === false) {
  23282. executeKeydownOverride$2(editor, evt);
  23283. }
  23284. });
  23285. };
  23286. var SpaceKey = { setup: setup$b };
  23287. var findBlockCaretContainer = function (editor) {
  23288. return descendant(Element.fromDom(editor.getBody()), '*[data-mce-caret]').fold(constant(null), function (elm) {
  23289. return elm.dom();
  23290. });
  23291. };
  23292. var removeIeControlRect = function (editor) {
  23293. editor.selection.setRng(editor.selection.getRng());
  23294. };
  23295. var showBlockCaretContainer = function (editor, blockCaretContainer) {
  23296. if (blockCaretContainer.hasAttribute('data-mce-caret')) {
  23297. showCaretContainerBlock(blockCaretContainer);
  23298. removeIeControlRect(editor);
  23299. editor.selection.scrollIntoView(blockCaretContainer);
  23300. }
  23301. };
  23302. var handleBlockContainer = function (editor, e) {
  23303. var blockCaretContainer = findBlockCaretContainer(editor);
  23304. if (!blockCaretContainer) {
  23305. return;
  23306. }
  23307. if (e.type === 'compositionstart') {
  23308. e.preventDefault();
  23309. e.stopPropagation();
  23310. showBlockCaretContainer(editor, blockCaretContainer);
  23311. return;
  23312. }
  23313. if (hasContent(blockCaretContainer)) {
  23314. showBlockCaretContainer(editor, blockCaretContainer);
  23315. editor.undoManager.add();
  23316. }
  23317. };
  23318. var setup$c = function (editor) {
  23319. editor.on('keyup compositionstart', curry(handleBlockContainer, editor));
  23320. };
  23321. var CaretContainerInput = { setup: setup$c };
  23322. var browser$5 = detect$3().browser;
  23323. var setupIeInput = function (editor) {
  23324. var keypressThrotter = first(function () {
  23325. if (!editor.composing) {
  23326. normalizeNbspsInEditor(editor);
  23327. }
  23328. }, 0);
  23329. if (browser$5.isIE()) {
  23330. editor.on('keypress', function (e) {
  23331. keypressThrotter.throttle();
  23332. });
  23333. editor.on('remove', function (e) {
  23334. keypressThrotter.cancel();
  23335. });
  23336. }
  23337. };
  23338. var setup$d = function (editor) {
  23339. setupIeInput(editor);
  23340. editor.on('input', function (e) {
  23341. if (e.isComposing === false) {
  23342. normalizeNbspsInEditor(editor);
  23343. }
  23344. });
  23345. };
  23346. var executeKeydownOverride$3 = function (editor, evt) {
  23347. MatchKeys.execute([
  23348. {
  23349. keyCode: VK.END,
  23350. action: moveToLineEndPoint(editor, true)
  23351. },
  23352. {
  23353. keyCode: VK.HOME,
  23354. action: moveToLineEndPoint(editor, false)
  23355. }
  23356. ], evt).each(function (_) {
  23357. evt.preventDefault();
  23358. });
  23359. };
  23360. var setup$e = function (editor) {
  23361. editor.on('keydown', function (evt) {
  23362. if (evt.isDefaultPrevented() === false) {
  23363. executeKeydownOverride$3(editor, evt);
  23364. }
  23365. });
  23366. };
  23367. var HomeEndKeys = { setup: setup$e };
  23368. var setup$f = function (editor) {
  23369. var caret = BoundarySelection.setupSelectedState(editor);
  23370. CaretContainerInput.setup(editor);
  23371. ArrowKeys.setup(editor, caret);
  23372. DeleteBackspaceKeys.setup(editor, caret);
  23373. EnterKey.setup(editor);
  23374. SpaceKey.setup(editor);
  23375. setup$d(editor);
  23376. HomeEndKeys.setup(editor);
  23377. };
  23378. var KeyboardOverrides = { setup: setup$f };
  23379. var Quirks = function (editor) {
  23380. var each = Tools.each;
  23381. var BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection, settings = editor.settings, parser = editor.parser;
  23382. var isGecko = Env.gecko, isIE = Env.ie, isWebKit = Env.webkit;
  23383. var mceInternalUrlPrefix = 'data:text/mce-internal,';
  23384. var mceInternalDataType = isIE ? 'Text' : 'URL';
  23385. var setEditorCommandState = function (cmd, state) {
  23386. try {
  23387. editor.getDoc().execCommand(cmd, false, state);
  23388. } catch (ex) {
  23389. }
  23390. };
  23391. var isDefaultPrevented = function (e) {
  23392. return e.isDefaultPrevented();
  23393. };
  23394. var setMceInternalContent = function (e) {
  23395. var selectionHtml, internalContent;
  23396. if (e.dataTransfer) {
  23397. if (editor.selection.isCollapsed() && e.target.tagName === 'IMG') {
  23398. selection.select(e.target);
  23399. }
  23400. selectionHtml = editor.selection.getContent();
  23401. if (selectionHtml.length > 0) {
  23402. internalContent = mceInternalUrlPrefix + escape(editor.id) + ',' + escape(selectionHtml);
  23403. e.dataTransfer.setData(mceInternalDataType, internalContent);
  23404. }
  23405. }
  23406. };
  23407. var getMceInternalContent = function (e) {
  23408. var internalContent;
  23409. if (e.dataTransfer) {
  23410. internalContent = e.dataTransfer.getData(mceInternalDataType);
  23411. if (internalContent && internalContent.indexOf(mceInternalUrlPrefix) >= 0) {
  23412. internalContent = internalContent.substr(mceInternalUrlPrefix.length).split(',');
  23413. return {
  23414. id: unescape(internalContent[0]),
  23415. html: unescape(internalContent[1])
  23416. };
  23417. }
  23418. }
  23419. return null;
  23420. };
  23421. var insertClipboardContents = function (content, internal) {
  23422. if (editor.queryCommandSupported('mceInsertClipboardContent')) {
  23423. editor.execCommand('mceInsertClipboardContent', false, {
  23424. content: content,
  23425. internal: internal
  23426. });
  23427. } else {
  23428. editor.execCommand('mceInsertContent', false, content);
  23429. }
  23430. };
  23431. var emptyEditorWhenDeleting = function () {
  23432. var serializeRng = function (rng) {
  23433. var body = dom.create('body');
  23434. var contents = rng.cloneContents();
  23435. body.appendChild(contents);
  23436. return selection.serializer.serialize(body, { format: 'html' });
  23437. };
  23438. var allContentsSelected = function (rng) {
  23439. var selection = serializeRng(rng);
  23440. var allRng = dom.createRng();
  23441. allRng.selectNode(editor.getBody());
  23442. var allSelection = serializeRng(allRng);
  23443. return selection === allSelection;
  23444. };
  23445. editor.on('keydown', function (e) {
  23446. var keyCode = e.keyCode;
  23447. var isCollapsed, body;
  23448. if (!isDefaultPrevented(e) && (keyCode === DELETE || keyCode === BACKSPACE)) {
  23449. isCollapsed = editor.selection.isCollapsed();
  23450. body = editor.getBody();
  23451. if (isCollapsed && !dom.isEmpty(body)) {
  23452. return;
  23453. }
  23454. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  23455. return;
  23456. }
  23457. e.preventDefault();
  23458. editor.setContent('');
  23459. if (body.firstChild && dom.isBlock(body.firstChild)) {
  23460. editor.selection.setCursorLocation(body.firstChild, 0);
  23461. } else {
  23462. editor.selection.setCursorLocation(body, 0);
  23463. }
  23464. editor.nodeChanged();
  23465. }
  23466. });
  23467. };
  23468. var selectAll = function () {
  23469. editor.shortcuts.add('meta+a', null, 'SelectAll');
  23470. };
  23471. var inputMethodFocus = function () {
  23472. if (!editor.inline) {
  23473. dom.bind(editor.getDoc(), 'mousedown mouseup', function (e) {
  23474. var rng;
  23475. if (e.target === editor.getDoc().documentElement) {
  23476. rng = selection.getRng();
  23477. editor.getBody().focus();
  23478. if (e.type === 'mousedown') {
  23479. if (isCaretContainer(rng.startContainer)) {
  23480. return;
  23481. }
  23482. selection.placeCaretAt(e.clientX, e.clientY);
  23483. } else {
  23484. selection.setRng(rng);
  23485. }
  23486. }
  23487. });
  23488. }
  23489. };
  23490. var removeHrOnBackspace = function () {
  23491. editor.on('keydown', function (e) {
  23492. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  23493. if (!editor.getBody().getElementsByTagName('hr').length) {
  23494. return;
  23495. }
  23496. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  23497. var node = selection.getNode();
  23498. var previousSibling = node.previousSibling;
  23499. if (node.nodeName === 'HR') {
  23500. dom.remove(node);
  23501. e.preventDefault();
  23502. return;
  23503. }
  23504. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'hr') {
  23505. dom.remove(previousSibling);
  23506. e.preventDefault();
  23507. }
  23508. }
  23509. }
  23510. });
  23511. };
  23512. var focusBody = function () {
  23513. if (!domGlobals.Range.prototype.getClientRects) {
  23514. editor.on('mousedown', function (e) {
  23515. if (!isDefaultPrevented(e) && e.target.nodeName === 'HTML') {
  23516. var body_1 = editor.getBody();
  23517. body_1.blur();
  23518. Delay.setEditorTimeout(editor, function () {
  23519. body_1.focus();
  23520. });
  23521. }
  23522. });
  23523. }
  23524. };
  23525. var selectControlElements = function () {
  23526. editor.on('click', function (e) {
  23527. var target = e.target;
  23528. if (/^(IMG|HR)$/.test(target.nodeName) && dom.getContentEditableParent(target) !== 'false') {
  23529. e.preventDefault();
  23530. editor.selection.select(target);
  23531. editor.nodeChanged();
  23532. }
  23533. if (target.nodeName === 'A' && dom.hasClass(target, 'mce-item-anchor')) {
  23534. e.preventDefault();
  23535. selection.select(target);
  23536. }
  23537. });
  23538. };
  23539. var removeStylesWhenDeletingAcrossBlockElements = function () {
  23540. var getAttributeApplyFunction = function () {
  23541. var template = dom.getAttribs(selection.getStart().cloneNode(false));
  23542. return function () {
  23543. var target = selection.getStart();
  23544. if (target !== editor.getBody()) {
  23545. dom.setAttrib(target, 'style', null);
  23546. each(template, function (attr) {
  23547. target.setAttributeNode(attr.cloneNode(true));
  23548. });
  23549. }
  23550. };
  23551. };
  23552. var isSelectionAcrossElements = function () {
  23553. return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) !== dom.getParent(selection.getEnd(), dom.isBlock);
  23554. };
  23555. editor.on('keypress', function (e) {
  23556. var applyAttributes;
  23557. if (!isDefaultPrevented(e) && (e.keyCode === 8 || e.keyCode === 46) && isSelectionAcrossElements()) {
  23558. applyAttributes = getAttributeApplyFunction();
  23559. editor.getDoc().execCommand('delete', false, null);
  23560. applyAttributes();
  23561. e.preventDefault();
  23562. return false;
  23563. }
  23564. });
  23565. dom.bind(editor.getDoc(), 'cut', function (e) {
  23566. var applyAttributes;
  23567. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  23568. applyAttributes = getAttributeApplyFunction();
  23569. Delay.setEditorTimeout(editor, function () {
  23570. applyAttributes();
  23571. });
  23572. }
  23573. });
  23574. };
  23575. var disableBackspaceIntoATable = function () {
  23576. editor.on('keydown', function (e) {
  23577. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  23578. if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
  23579. var previousSibling = selection.getNode().previousSibling;
  23580. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'table') {
  23581. e.preventDefault();
  23582. return false;
  23583. }
  23584. }
  23585. }
  23586. });
  23587. };
  23588. var removeBlockQuoteOnBackSpace = function () {
  23589. editor.on('keydown', function (e) {
  23590. var rng, container, offset, root, parent;
  23591. if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) {
  23592. return;
  23593. }
  23594. rng = selection.getRng();
  23595. container = rng.startContainer;
  23596. offset = rng.startOffset;
  23597. root = dom.getRoot();
  23598. parent = container;
  23599. if (!rng.collapsed || offset !== 0) {
  23600. return;
  23601. }
  23602. while (parent && parent.parentNode && parent.parentNode.firstChild === parent && parent.parentNode !== root) {
  23603. parent = parent.parentNode;
  23604. }
  23605. if (parent.tagName === 'BLOCKQUOTE') {
  23606. editor.formatter.toggle('blockquote', null, parent);
  23607. rng = dom.createRng();
  23608. rng.setStart(container, 0);
  23609. rng.setEnd(container, 0);
  23610. selection.setRng(rng);
  23611. }
  23612. });
  23613. };
  23614. var setGeckoEditingOptions = function () {
  23615. var setOpts = function () {
  23616. setEditorCommandState('StyleWithCSS', false);
  23617. setEditorCommandState('enableInlineTableEditing', false);
  23618. if (!settings.object_resizing) {
  23619. setEditorCommandState('enableObjectResizing', false);
  23620. }
  23621. };
  23622. if (!settings.readonly) {
  23623. editor.on('BeforeExecCommand mousedown', setOpts);
  23624. }
  23625. };
  23626. var addBrAfterLastLinks = function () {
  23627. var fixLinks = function () {
  23628. each(dom.select('a'), function (node) {
  23629. var parentNode = node.parentNode;
  23630. var root = dom.getRoot();
  23631. if (parentNode.lastChild === node) {
  23632. while (parentNode && !dom.isBlock(parentNode)) {
  23633. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  23634. return;
  23635. }
  23636. parentNode = parentNode.parentNode;
  23637. }
  23638. dom.add(parentNode, 'br', { 'data-mce-bogus': 1 });
  23639. }
  23640. });
  23641. };
  23642. editor.on('SetContent ExecCommand', function (e) {
  23643. if (e.type === 'setcontent' || e.command === 'mceInsertLink') {
  23644. fixLinks();
  23645. }
  23646. });
  23647. };
  23648. var setDefaultBlockType = function () {
  23649. if (settings.forced_root_block) {
  23650. editor.on('init', function () {
  23651. setEditorCommandState('DefaultParagraphSeparator', Settings.getForcedRootBlock(editor));
  23652. });
  23653. }
  23654. };
  23655. var normalizeSelection = function () {
  23656. editor.on('keyup focusin mouseup', function (e) {
  23657. if (!VK.modifierPressed(e)) {
  23658. selection.normalize();
  23659. }
  23660. }, true);
  23661. };
  23662. var showBrokenImageIcon = function () {
  23663. editor.contentStyles.push('img:-moz-broken {' + '-moz-force-broken-image-icon:1;' + 'min-width:24px;' + 'min-height:24px' + '}');
  23664. };
  23665. var restoreFocusOnKeyDown = function () {
  23666. if (!editor.inline) {
  23667. editor.on('keydown', function () {
  23668. if (domGlobals.document.activeElement === domGlobals.document.body) {
  23669. editor.getWin().focus();
  23670. }
  23671. });
  23672. }
  23673. };
  23674. var bodyHeight = function () {
  23675. if (!editor.inline) {
  23676. editor.contentStyles.push('body {min-height: 150px}');
  23677. editor.on('click', function (e) {
  23678. var rng;
  23679. if (e.target.nodeName === 'HTML') {
  23680. if (Env.ie > 11) {
  23681. editor.getBody().focus();
  23682. return;
  23683. }
  23684. rng = editor.selection.getRng();
  23685. editor.getBody().focus();
  23686. editor.selection.setRng(rng);
  23687. editor.selection.normalize();
  23688. editor.nodeChanged();
  23689. }
  23690. });
  23691. }
  23692. };
  23693. var blockCmdArrowNavigation = function () {
  23694. if (Env.mac) {
  23695. editor.on('keydown', function (e) {
  23696. if (VK.metaKeyPressed(e) && !e.shiftKey && (e.keyCode === 37 || e.keyCode === 39)) {
  23697. e.preventDefault();
  23698. var selection_1 = editor.selection.getSel();
  23699. selection_1.modify('move', e.keyCode === 37 ? 'backward' : 'forward', 'lineboundary');
  23700. }
  23701. });
  23702. }
  23703. };
  23704. var disableAutoUrlDetect = function () {
  23705. setEditorCommandState('AutoUrlDetect', false);
  23706. };
  23707. var tapLinksAndImages = function () {
  23708. editor.on('click', function (e) {
  23709. var elm = e.target;
  23710. do {
  23711. if (elm.tagName === 'A') {
  23712. e.preventDefault();
  23713. return;
  23714. }
  23715. } while (elm = elm.parentNode);
  23716. });
  23717. editor.contentStyles.push('.mce-content-body {-webkit-touch-callout: none}');
  23718. };
  23719. var blockFormSubmitInsideEditor = function () {
  23720. editor.on('init', function () {
  23721. editor.dom.bind(editor.getBody(), 'submit', function (e) {
  23722. e.preventDefault();
  23723. });
  23724. });
  23725. };
  23726. var removeAppleInterchangeBrs = function () {
  23727. parser.addNodeFilter('br', function (nodes) {
  23728. var i = nodes.length;
  23729. while (i--) {
  23730. if (nodes[i].attr('class') === 'Apple-interchange-newline') {
  23731. nodes[i].remove();
  23732. }
  23733. }
  23734. });
  23735. };
  23736. var ieInternalDragAndDrop = function () {
  23737. editor.on('dragstart', function (e) {
  23738. setMceInternalContent(e);
  23739. });
  23740. editor.on('drop', function (e) {
  23741. if (!isDefaultPrevented(e)) {
  23742. var internalContent = getMceInternalContent(e);
  23743. if (internalContent && internalContent.id !== editor.id) {
  23744. e.preventDefault();
  23745. var rng = CaretRangeFromPoint.fromPoint(e.x, e.y, editor.getDoc());
  23746. selection.setRng(rng);
  23747. insertClipboardContents(internalContent.html, true);
  23748. }
  23749. }
  23750. });
  23751. };
  23752. var refreshContentEditable = function () {
  23753. };
  23754. var isHidden = function () {
  23755. var sel;
  23756. if (!isGecko || editor.removed) {
  23757. return false;
  23758. }
  23759. sel = editor.selection.getSel();
  23760. return !sel || !sel.rangeCount || sel.rangeCount === 0;
  23761. };
  23762. removeBlockQuoteOnBackSpace();
  23763. emptyEditorWhenDeleting();
  23764. if (!Env.windowsPhone) {
  23765. normalizeSelection();
  23766. }
  23767. if (isWebKit) {
  23768. inputMethodFocus();
  23769. selectControlElements();
  23770. setDefaultBlockType();
  23771. blockFormSubmitInsideEditor();
  23772. disableBackspaceIntoATable();
  23773. removeAppleInterchangeBrs();
  23774. if (Env.iOS) {
  23775. restoreFocusOnKeyDown();
  23776. bodyHeight();
  23777. tapLinksAndImages();
  23778. } else {
  23779. selectAll();
  23780. }
  23781. }
  23782. if (Env.ie >= 11) {
  23783. bodyHeight();
  23784. disableBackspaceIntoATable();
  23785. }
  23786. if (Env.ie) {
  23787. selectAll();
  23788. disableAutoUrlDetect();
  23789. ieInternalDragAndDrop();
  23790. }
  23791. if (isGecko) {
  23792. removeHrOnBackspace();
  23793. focusBody();
  23794. removeStylesWhenDeletingAcrossBlockElements();
  23795. setGeckoEditingOptions();
  23796. addBrAfterLastLinks();
  23797. showBrokenImageIcon();
  23798. blockCmdArrowNavigation();
  23799. disableBackspaceIntoATable();
  23800. }
  23801. return {
  23802. refreshContentEditable: refreshContentEditable,
  23803. isHidden: isHidden
  23804. };
  23805. };
  23806. var isTextBlockNode = function (node) {
  23807. return NodeType.isElement(node) && isTextBlock(Element.fromDom(node));
  23808. };
  23809. var normalizeSelection$1 = function (editor) {
  23810. var rng = editor.selection.getRng();
  23811. var startPos = CaretPosition.fromRangeStart(rng);
  23812. var endPos = CaretPosition.fromRangeEnd(rng);
  23813. if (CaretPosition.isElementPosition(startPos)) {
  23814. var container = startPos.container();
  23815. if (isTextBlockNode(container)) {
  23816. CaretFinder.firstPositionIn(container).each(function (pos) {
  23817. return rng.setStart(pos.container(), pos.offset());
  23818. });
  23819. }
  23820. }
  23821. if (CaretPosition.isElementPosition(endPos)) {
  23822. var container = startPos.container();
  23823. if (isTextBlockNode(container)) {
  23824. CaretFinder.lastPositionIn(container).each(function (pos) {
  23825. return rng.setEnd(pos.container(), pos.offset());
  23826. });
  23827. }
  23828. }
  23829. editor.selection.setRng(RangeNormalizer.normalize(rng));
  23830. };
  23831. var setup$g = function (editor) {
  23832. editor.on('click', function (e) {
  23833. if (e.detail >= 3) {
  23834. normalizeSelection$1(editor);
  23835. }
  23836. });
  23837. };
  23838. var preventSummaryToggle = function (editor) {
  23839. editor.on('click', function (e) {
  23840. if (editor.dom.getParent(e.target, 'details')) {
  23841. e.preventDefault();
  23842. }
  23843. });
  23844. };
  23845. var filterDetails = function (editor) {
  23846. editor.parser.addNodeFilter('details', function (elms) {
  23847. each(elms, function (details) {
  23848. details.attr('data-mce-open', details.attr('open'));
  23849. details.attr('open', 'open');
  23850. });
  23851. });
  23852. editor.serializer.addNodeFilter('details', function (elms) {
  23853. each(elms, function (details) {
  23854. var open = details.attr('data-mce-open');
  23855. details.attr('open', isString(open) ? open : null);
  23856. details.attr('data-mce-open', null);
  23857. });
  23858. });
  23859. };
  23860. var setup$h = function (editor) {
  23861. preventSummaryToggle(editor);
  23862. filterDetails(editor);
  23863. };
  23864. var DOM$3 = DOMUtils$1.DOM;
  23865. var appendStyle = function (editor, text) {
  23866. var head = Element.fromDom(editor.getDoc().head);
  23867. var tag = Element.fromTag('style');
  23868. set(tag, 'type', 'text/css');
  23869. append(tag, Element.fromText(text));
  23870. append(head, tag);
  23871. };
  23872. var createParser = function (editor) {
  23873. var parser = DomParser(editor.settings, editor.schema);
  23874. parser.addAttributeFilter('src,href,style,tabindex', function (nodes, name) {
  23875. var i = nodes.length, node;
  23876. var dom = editor.dom;
  23877. var value, internalName;
  23878. while (i--) {
  23879. node = nodes[i];
  23880. value = node.attr(name);
  23881. internalName = 'data-mce-' + name;
  23882. if (!node.attr(internalName)) {
  23883. if (value.indexOf('data:') === 0 || value.indexOf('blob:') === 0) {
  23884. continue;
  23885. }
  23886. if (name === 'style') {
  23887. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  23888. if (!value.length) {
  23889. value = null;
  23890. }
  23891. node.attr(internalName, value);
  23892. node.attr(name, value);
  23893. } else if (name === 'tabindex') {
  23894. node.attr(internalName, value);
  23895. node.attr(name, null);
  23896. } else {
  23897. node.attr(internalName, editor.convertURL(value, name, node.name));
  23898. }
  23899. }
  23900. }
  23901. });
  23902. parser.addNodeFilter('script', function (nodes) {
  23903. var i = nodes.length, node, type;
  23904. while (i--) {
  23905. node = nodes[i];
  23906. type = node.attr('type') || 'no/type';
  23907. if (type.indexOf('mce-') !== 0) {
  23908. node.attr('type', 'mce-' + type);
  23909. }
  23910. }
  23911. });
  23912. parser.addNodeFilter('#cdata', function (nodes) {
  23913. var i = nodes.length, node;
  23914. while (i--) {
  23915. node = nodes[i];
  23916. node.type = 8;
  23917. node.name = '#comment';
  23918. node.value = '[CDATA[' + node.value + ']]';
  23919. }
  23920. });
  23921. parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function (nodes) {
  23922. var i = nodes.length, node;
  23923. var nonEmptyElements = editor.schema.getNonEmptyElements();
  23924. while (i--) {
  23925. node = nodes[i];
  23926. if (node.isEmpty(nonEmptyElements) && node.getAll('br').length === 0) {
  23927. node.append(new Node$1('br', 1)).shortEnded = true;
  23928. }
  23929. }
  23930. });
  23931. return parser;
  23932. };
  23933. var autoFocus = function (editor) {
  23934. if (editor.settings.auto_focus) {
  23935. Delay.setEditorTimeout(editor, function () {
  23936. var focusEditor;
  23937. if (editor.settings.auto_focus === true) {
  23938. focusEditor = editor;
  23939. } else {
  23940. focusEditor = editor.editorManager.get(editor.settings.auto_focus);
  23941. }
  23942. if (!focusEditor.destroyed) {
  23943. focusEditor.focus();
  23944. }
  23945. }, 100);
  23946. }
  23947. };
  23948. var initEditor = function (editor) {
  23949. editor.bindPendingEventDelegates();
  23950. editor.initialized = true;
  23951. editor.fire('init');
  23952. editor.focus(true);
  23953. editor.nodeChanged({ initial: true });
  23954. editor.execCallback('init_instance_callback', editor);
  23955. autoFocus(editor);
  23956. };
  23957. var getStyleSheetLoader = function (editor) {
  23958. return editor.inline ? DOM$3.styleSheetLoader : editor.dom.styleSheetLoader;
  23959. };
  23960. var initContentBody = function (editor, skipWrite) {
  23961. var settings = editor.settings;
  23962. var targetElm = editor.getElement();
  23963. var doc = editor.getDoc(), body, contentCssText;
  23964. if (!settings.inline) {
  23965. editor.getElement().style.visibility = editor.orgVisibility;
  23966. }
  23967. if (!skipWrite && !editor.inline) {
  23968. doc.open();
  23969. doc.write(editor.iframeHTML);
  23970. doc.close();
  23971. }
  23972. if (editor.inline) {
  23973. editor.on('remove', function () {
  23974. var bodyEl = this.getBody();
  23975. DOM$3.removeClass(bodyEl, 'mce-content-body');
  23976. DOM$3.removeClass(bodyEl, 'mce-edit-focus');
  23977. DOM$3.setAttrib(bodyEl, 'contentEditable', null);
  23978. });
  23979. DOM$3.addClass(targetElm, 'mce-content-body');
  23980. editor.contentDocument = doc = domGlobals.document;
  23981. editor.contentWindow = domGlobals.window;
  23982. editor.bodyElement = targetElm;
  23983. editor.contentAreaContainer = targetElm;
  23984. settings.root_name = targetElm.nodeName.toLowerCase();
  23985. }
  23986. body = editor.getBody();
  23987. body.disabled = true;
  23988. editor.readonly = settings.readonly;
  23989. if (!editor.readonly) {
  23990. if (editor.inline && DOM$3.getStyle(body, 'position', true) === 'static') {
  23991. body.style.position = 'relative';
  23992. }
  23993. body.contentEditable = editor.getParam('content_editable_state', true);
  23994. }
  23995. body.disabled = false;
  23996. editor.editorUpload = EditorUpload(editor);
  23997. editor.schema = Schema(settings);
  23998. editor.dom = DOMUtils$1(doc, {
  23999. keep_values: true,
  24000. url_converter: editor.convertURL,
  24001. url_converter_scope: editor,
  24002. hex_colors: settings.force_hex_style_colors,
  24003. update_styles: true,
  24004. root_element: editor.inline ? editor.getBody() : null,
  24005. collect: function () {
  24006. return editor.inline;
  24007. },
  24008. schema: editor.schema,
  24009. contentCssCors: Settings.shouldUseContentCssCors(editor),
  24010. referrerPolicy: Settings.getReferrerPolicy(editor),
  24011. onSetAttrib: function (e) {
  24012. editor.fire('SetAttrib', e);
  24013. }
  24014. });
  24015. editor.parser = createParser(editor);
  24016. editor.serializer = Serializer$1(settings, editor);
  24017. editor.selection = Selection$1(editor.dom, editor.getWin(), editor.serializer, editor);
  24018. editor.annotator = Annotator(editor);
  24019. editor.formatter = Formatter(editor);
  24020. editor.undoManager = UndoManager(editor);
  24021. editor._nodeChangeDispatcher = new NodeChange(editor);
  24022. editor._selectionOverrides = SelectionOverrides(editor);
  24023. setup$h(editor);
  24024. setup$g(editor);
  24025. KeyboardOverrides.setup(editor);
  24026. ForceBlocks.setup(editor);
  24027. editor.fire('PreInit');
  24028. if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
  24029. doc.body.spellcheck = false;
  24030. DOM$3.setAttrib(body, 'spellcheck', 'false');
  24031. }
  24032. editor.quirks = Quirks(editor);
  24033. editor.fire('PostRender');
  24034. var directionality = Settings.getDirectionality(editor);
  24035. if (directionality !== undefined) {
  24036. body.dir = directionality;
  24037. }
  24038. if (settings.protect) {
  24039. editor.on('BeforeSetContent', function (e) {
  24040. Tools.each(settings.protect, function (pattern) {
  24041. e.content = e.content.replace(pattern, function (str) {
  24042. return '<!--mce:protected ' + escape(str) + '-->';
  24043. });
  24044. });
  24045. });
  24046. }
  24047. editor.on('SetContent', function () {
  24048. editor.addVisual(editor.getBody());
  24049. });
  24050. editor.load({
  24051. initial: true,
  24052. format: 'html'
  24053. });
  24054. editor.startContent = editor.getContent({ format: 'raw' });
  24055. editor.on('compositionstart compositionend', function (e) {
  24056. editor.composing = e.type === 'compositionstart';
  24057. });
  24058. if (editor.contentStyles.length > 0) {
  24059. contentCssText = '';
  24060. Tools.each(editor.contentStyles, function (style) {
  24061. contentCssText += style + '\r\n';
  24062. });
  24063. editor.dom.addStyle(contentCssText);
  24064. }
  24065. getStyleSheetLoader(editor).loadAll(editor.contentCSS, function (_) {
  24066. initEditor(editor);
  24067. }, function (urls) {
  24068. initEditor(editor);
  24069. });
  24070. if (settings.content_style) {
  24071. appendStyle(editor, settings.content_style);
  24072. }
  24073. };
  24074. var InitContentBody = { initContentBody: initContentBody };
  24075. var DOM$4 = DOMUtils$1.DOM;
  24076. var relaxDomain = function (editor, ifr) {
  24077. if (domGlobals.document.domain !== domGlobals.window.location.hostname && Env.browser.isIE()) {
  24078. var bodyUuid = Uuid.uuid('mce');
  24079. editor[bodyUuid] = function () {
  24080. InitContentBody.initContentBody(editor);
  24081. };
  24082. var domainRelaxUrl = 'javascript:(function(){' + 'document.open();document.domain="' + domGlobals.document.domain + '";' + 'var ed = window.parent.tinymce.get("' + editor.id + '");document.write(ed.iframeHTML);' + 'document.close();ed.' + bodyUuid + '(true);})()';
  24083. DOM$4.setAttrib(ifr, 'src', domainRelaxUrl);
  24084. return true;
  24085. }
  24086. return false;
  24087. };
  24088. var createIframeElement = function (id, title, height, customAttrs) {
  24089. var iframe = Element.fromTag('iframe');
  24090. setAll(iframe, customAttrs);
  24091. setAll(iframe, {
  24092. id: id + '_ifr',
  24093. frameBorder: '0',
  24094. allowTransparency: 'true',
  24095. title: title
  24096. });
  24097. add$3(iframe, 'tox-edit-area__iframe');
  24098. return iframe;
  24099. };
  24100. var getIframeHtml = function (editor) {
  24101. var bodyId, bodyClass, iframeHTML;
  24102. iframeHTML = Settings.getDocType(editor) + '<html><head>';
  24103. if (Settings.getDocumentBaseUrl(editor) !== editor.documentBaseUrl) {
  24104. iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />';
  24105. }
  24106. iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  24107. bodyId = Settings.getBodyId(editor);
  24108. bodyClass = Settings.getBodyClass(editor);
  24109. if (Settings.getContentSecurityPolicy(editor)) {
  24110. iframeHTML += '<meta http-equiv="Content-Security-Policy" content="' + Settings.getContentSecurityPolicy(editor) + '" />';
  24111. }
  24112. iframeHTML += '</head><body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '" data-id="' + editor.id + '"><br></body></html>';
  24113. return iframeHTML;
  24114. };
  24115. var createIframe = function (editor, o) {
  24116. var title = editor.editorManager.translate('Rich Text Area. Press ALT-0 for help.');
  24117. var ifr = createIframeElement(editor.id, title, o.height, Settings.getIframeAttrs(editor)).dom();
  24118. ifr.onload = function () {
  24119. ifr.onload = null;
  24120. editor.fire('load');
  24121. };
  24122. var isDomainRelaxed = relaxDomain(editor, ifr);
  24123. editor.contentAreaContainer = o.iframeContainer;
  24124. editor.iframeElement = ifr;
  24125. editor.iframeHTML = getIframeHtml(editor);
  24126. DOM$4.add(o.iframeContainer, ifr);
  24127. return isDomainRelaxed;
  24128. };
  24129. var init$1 = function (editor, boxInfo) {
  24130. var isDomainRelaxed = createIframe(editor, boxInfo);
  24131. if (boxInfo.editorContainer) {
  24132. DOM$4.get(boxInfo.editorContainer).style.display = editor.orgDisplay;
  24133. editor.hidden = DOM$4.isHidden(boxInfo.editorContainer);
  24134. }
  24135. editor.getElement().style.display = 'none';
  24136. DOM$4.setAttrib(editor.id, 'aria-hidden', 'true');
  24137. if (!isDomainRelaxed) {
  24138. InitContentBody.initContentBody(editor);
  24139. }
  24140. };
  24141. var InitIframe = { init: init$1 };
  24142. var isContentCssSkinName = function (url) {
  24143. return /^[a-z0-9\-]+$/i.test(url);
  24144. };
  24145. var getContentCssUrls = function (editor) {
  24146. var contentCss = Settings.getContentCss(editor);
  24147. var skinUrl = editor.editorManager.baseURL + '/skins/content';
  24148. var suffix = editor.editorManager.suffix;
  24149. var contentCssFile = 'content' + suffix + '.css';
  24150. var inline = editor.inline === true;
  24151. return map(contentCss, function (url) {
  24152. if (isContentCssSkinName(url) && !inline) {
  24153. return skinUrl + '/' + url + '/' + contentCssFile;
  24154. } else {
  24155. return editor.documentBaseURI.toAbsolute(url);
  24156. }
  24157. });
  24158. };
  24159. var appendContentCssFromSettings = function (editor) {
  24160. editor.contentCSS = editor.contentCSS.concat(getContentCssUrls(editor));
  24161. };
  24162. var DOM$5 = DOMUtils$1.DOM;
  24163. var initPlugin = function (editor, initializedPlugins, plugin) {
  24164. var Plugin = PluginManager.get(plugin);
  24165. var pluginUrl = PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, '');
  24166. plugin = Tools.trim(plugin);
  24167. if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) {
  24168. Tools.each(PluginManager.dependencies(plugin), function (dep) {
  24169. initPlugin(editor, initializedPlugins, dep);
  24170. });
  24171. if (editor.plugins[plugin]) {
  24172. return;
  24173. }
  24174. try {
  24175. var pluginInstance = new Plugin(editor, pluginUrl, editor.$);
  24176. editor.plugins[plugin] = pluginInstance;
  24177. if (pluginInstance.init) {
  24178. pluginInstance.init(editor, pluginUrl);
  24179. initializedPlugins.push(plugin);
  24180. }
  24181. } catch (e) {
  24182. ErrorReporter.pluginInitError(editor, plugin, e);
  24183. }
  24184. }
  24185. };
  24186. var trimLegacyPrefix = function (name) {
  24187. return name.replace(/^\-/, '');
  24188. };
  24189. var initPlugins = function (editor) {
  24190. var initializedPlugins = [];
  24191. Tools.each(editor.settings.plugins.split(/[ ,]/), function (name) {
  24192. initPlugin(editor, initializedPlugins, trimLegacyPrefix(name));
  24193. });
  24194. };
  24195. var initIcons = function (editor) {
  24196. var iconPackName = Tools.trim(editor.settings.icons);
  24197. var currentIcons = editor.ui.registry.getAll().icons;
  24198. var defaultIcons = getAll();
  24199. var loadIcons = __assign(__assign({}, defaultIcons), IconManager.get(iconPackName).icons);
  24200. each$1(loadIcons, function (svgData, icon) {
  24201. if (!has(currentIcons, icon)) {
  24202. editor.ui.registry.addIcon(icon, svgData);
  24203. }
  24204. });
  24205. };
  24206. var initTheme = function (editor) {
  24207. var theme = editor.settings.theme;
  24208. if (isString(theme)) {
  24209. editor.settings.theme = trimLegacyPrefix(theme);
  24210. var Theme = ThemeManager.get(theme);
  24211. editor.theme = new Theme(editor, ThemeManager.urls[theme]);
  24212. if (editor.theme.init) {
  24213. editor.theme.init(editor, ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ''), editor.$);
  24214. }
  24215. } else {
  24216. editor.theme = {};
  24217. }
  24218. };
  24219. var renderFromLoadedTheme = function (editor) {
  24220. return editor.theme.renderUI();
  24221. };
  24222. var renderFromThemeFunc = function (editor) {
  24223. var elm = editor.getElement();
  24224. var theme = editor.settings.theme;
  24225. var info = theme(editor, elm);
  24226. if (info.editorContainer.nodeType) {
  24227. info.editorContainer.id = info.editorContainer.id || editor.id + '_parent';
  24228. }
  24229. if (info.iframeContainer && info.iframeContainer.nodeType) {
  24230. info.iframeContainer.id = info.iframeContainer.id || editor.id + '_iframecontainer';
  24231. }
  24232. info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight;
  24233. return info;
  24234. };
  24235. var createThemeFalseResult = function (element) {
  24236. return {
  24237. editorContainer: element,
  24238. iframeContainer: element
  24239. };
  24240. };
  24241. var renderThemeFalseIframe = function (targetElement) {
  24242. var iframeContainer = DOM$5.create('div');
  24243. DOM$5.insertAfter(iframeContainer, targetElement);
  24244. return createThemeFalseResult(iframeContainer);
  24245. };
  24246. var renderThemeFalse = function (editor) {
  24247. var targetElement = editor.getElement();
  24248. return editor.inline ? createThemeFalseResult(null) : renderThemeFalseIframe(targetElement);
  24249. };
  24250. var renderThemeUi = function (editor) {
  24251. var elm = editor.getElement();
  24252. editor.orgDisplay = elm.style.display;
  24253. if (isString(editor.settings.theme)) {
  24254. return renderFromLoadedTheme(editor);
  24255. } else if (isFunction(editor.settings.theme)) {
  24256. return renderFromThemeFunc(editor);
  24257. } else {
  24258. return renderThemeFalse(editor);
  24259. }
  24260. };
  24261. var init$2 = function (editor) {
  24262. editor.fire('ScriptsLoaded');
  24263. initIcons(editor);
  24264. initTheme(editor);
  24265. initPlugins(editor);
  24266. var boxInfo = renderThemeUi(editor);
  24267. editor.editorContainer = boxInfo.editorContainer ? boxInfo.editorContainer : null;
  24268. appendContentCssFromSettings(editor);
  24269. if (editor.inline) {
  24270. return InitContentBody.initContentBody(editor);
  24271. } else {
  24272. return InitIframe.init(editor, boxInfo);
  24273. }
  24274. };
  24275. var Init = { init: init$2 };
  24276. var DOM$6 = DOMUtils$1.DOM;
  24277. var hasSkipLoadPrefix = function (name) {
  24278. return name.charAt(0) === '-';
  24279. };
  24280. var loadLanguage = function (scriptLoader, editor) {
  24281. var languageCode = Settings.getLanguageCode(editor);
  24282. var languageUrl = Settings.getLanguageUrl(editor);
  24283. if (I18n.hasCode(languageCode) === false && languageCode !== 'en') {
  24284. var url_1 = languageUrl !== '' ? languageUrl : editor.editorManager.baseURL + '/langs/' + languageCode + '.js';
  24285. scriptLoader.add(url_1, noop, undefined, function () {
  24286. ErrorReporter.languageLoadError(url_1, languageCode);
  24287. });
  24288. }
  24289. };
  24290. var loadTheme = function (scriptLoader, editor, suffix, callback) {
  24291. var settings = editor.settings, theme = settings.theme;
  24292. if (isString(theme)) {
  24293. if (!hasSkipLoadPrefix(theme) && !ThemeManager.urls.hasOwnProperty(theme)) {
  24294. var themeUrl = settings.theme_url;
  24295. if (themeUrl) {
  24296. ThemeManager.load(theme, editor.documentBaseURI.toAbsolute(themeUrl));
  24297. } else {
  24298. ThemeManager.load(theme, 'themes/' + theme + '/theme' + suffix + '.js');
  24299. }
  24300. }
  24301. scriptLoader.loadQueue(function () {
  24302. ThemeManager.waitFor(theme, callback);
  24303. });
  24304. } else {
  24305. callback();
  24306. }
  24307. };
  24308. var getIconsUrlMetaFromUrl = function (editor) {
  24309. return Option.from(Settings.getIconsUrl(editor)).filter(function (url) {
  24310. return url.length > 0;
  24311. }).map(function (url) {
  24312. return {
  24313. url: url,
  24314. name: Option.none()
  24315. };
  24316. });
  24317. };
  24318. var getIconsUrlMetaFromName = function (editor) {
  24319. return Option.from(Settings.getIconPackName(editor)).filter(function (name) {
  24320. return name.length > 0 && !IconManager.has(name);
  24321. }).map(function (name) {
  24322. return {
  24323. url: editor.editorManager.baseURL + '/icons/' + name + '/icons.js',
  24324. name: Option.some(name)
  24325. };
  24326. });
  24327. };
  24328. var loadIcons = function (scriptLoader, editor) {
  24329. getIconsUrlMetaFromUrl(editor).orThunk(function () {
  24330. return getIconsUrlMetaFromName(editor);
  24331. }).each(function (urlMeta) {
  24332. scriptLoader.add(urlMeta.url, noop, undefined, function () {
  24333. ErrorReporter.iconsLoadError(urlMeta.url, urlMeta.name.getOrUndefined());
  24334. });
  24335. });
  24336. };
  24337. var loadPlugins = function (settings, suffix) {
  24338. if (isArray(settings.plugins)) {
  24339. settings.plugins = settings.plugins.join(' ');
  24340. }
  24341. Tools.each(settings.external_plugins, function (url, name) {
  24342. PluginManager.load(name, url, noop, undefined, function () {
  24343. ErrorReporter.pluginLoadError(name, url);
  24344. });
  24345. settings.plugins += ' ' + name;
  24346. });
  24347. Tools.each(settings.plugins.split(/[ ,]/), function (plugin) {
  24348. plugin = Tools.trim(plugin);
  24349. if (plugin && !PluginManager.urls[plugin]) {
  24350. if (hasSkipLoadPrefix(plugin)) {
  24351. plugin = plugin.substr(1, plugin.length);
  24352. var dependencies = PluginManager.dependencies(plugin);
  24353. Tools.each(dependencies, function (dep) {
  24354. var defaultSettings = {
  24355. prefix: 'plugins/',
  24356. resource: dep,
  24357. suffix: '/plugin' + suffix + '.js'
  24358. };
  24359. dep = PluginManager.createUrl(defaultSettings, dep);
  24360. PluginManager.load(dep.resource, dep, noop, undefined, function () {
  24361. ErrorReporter.pluginLoadError(dep.prefix + dep.resource + dep.suffix, dep.resource);
  24362. });
  24363. });
  24364. } else {
  24365. var url_2 = {
  24366. prefix: 'plugins/',
  24367. resource: plugin,
  24368. suffix: '/plugin' + suffix + '.js'
  24369. };
  24370. PluginManager.load(plugin, url_2, noop, undefined, function () {
  24371. ErrorReporter.pluginLoadError(url_2.prefix + url_2.resource + url_2.suffix, plugin);
  24372. });
  24373. }
  24374. }
  24375. });
  24376. };
  24377. var loadScripts = function (editor, suffix) {
  24378. var scriptLoader = ScriptLoader.ScriptLoader;
  24379. loadTheme(scriptLoader, editor, suffix, function () {
  24380. loadLanguage(scriptLoader, editor);
  24381. loadIcons(scriptLoader, editor);
  24382. loadPlugins(editor.settings, suffix);
  24383. scriptLoader.loadQueue(function () {
  24384. if (!editor.removed) {
  24385. Init.init(editor);
  24386. }
  24387. }, editor, function () {
  24388. if (!editor.removed) {
  24389. Init.init(editor);
  24390. }
  24391. });
  24392. });
  24393. };
  24394. var render = function (editor) {
  24395. var settings = editor.settings, id = editor.id;
  24396. I18n.setCode(Settings.getLanguageCode(editor));
  24397. var readyHandler = function () {
  24398. DOM$6.unbind(domGlobals.window, 'ready', readyHandler);
  24399. editor.render();
  24400. };
  24401. if (!EventUtils.Event.domLoaded) {
  24402. DOM$6.bind(domGlobals.window, 'ready', readyHandler);
  24403. return;
  24404. }
  24405. if (!editor.getElement()) {
  24406. return;
  24407. }
  24408. if (!Env.contentEditable) {
  24409. return;
  24410. }
  24411. if (!settings.inline) {
  24412. editor.orgVisibility = editor.getElement().style.visibility;
  24413. editor.getElement().style.visibility = 'hidden';
  24414. } else {
  24415. editor.inline = true;
  24416. }
  24417. var form = editor.getElement().form || DOM$6.getParent(id, 'form');
  24418. if (form) {
  24419. editor.formElement = form;
  24420. if (settings.hidden_input && !NodeType.isTextareaOrInput(editor.getElement())) {
  24421. DOM$6.insertAfter(DOM$6.create('input', {
  24422. type: 'hidden',
  24423. name: id
  24424. }), id);
  24425. editor.hasHiddenInput = true;
  24426. }
  24427. editor.formEventDelegate = function (e) {
  24428. editor.fire(e.type, e);
  24429. };
  24430. DOM$6.bind(form, 'submit reset', editor.formEventDelegate);
  24431. editor.on('reset', function () {
  24432. editor.resetContent();
  24433. });
  24434. if (settings.submit_patch && !form.submit.nodeType && !form.submit.length && !form._mceOldSubmit) {
  24435. form._mceOldSubmit = form.submit;
  24436. form.submit = function () {
  24437. editor.editorManager.triggerSave();
  24438. editor.setDirty(false);
  24439. return form._mceOldSubmit(form);
  24440. };
  24441. }
  24442. }
  24443. editor.windowManager = WindowManager(editor);
  24444. editor.notificationManager = NotificationManager(editor);
  24445. if (settings.encoding === 'xml') {
  24446. editor.on('GetContent', function (e) {
  24447. if (e.save) {
  24448. e.content = DOM$6.encode(e.content);
  24449. }
  24450. });
  24451. }
  24452. if (settings.add_form_submit_trigger) {
  24453. editor.on('submit', function () {
  24454. if (editor.initialized) {
  24455. editor.save();
  24456. }
  24457. });
  24458. }
  24459. if (settings.add_unload_trigger) {
  24460. editor._beforeUnload = function () {
  24461. if (editor.initialized && !editor.destroyed && !editor.isHidden()) {
  24462. editor.save({
  24463. format: 'raw',
  24464. no_events: true,
  24465. set_dirty: false
  24466. });
  24467. }
  24468. };
  24469. editor.editorManager.on('BeforeUnload', editor._beforeUnload);
  24470. }
  24471. editor.editorManager.add(editor);
  24472. loadScripts(editor, editor.suffix);
  24473. };
  24474. var Render = { render: render };
  24475. var internalContentEditableAttr = 'data-mce-contenteditable';
  24476. var toggleClass = function (elm, cls, state) {
  24477. if (has$2(elm, cls) && state === false) {
  24478. remove$4(elm, cls);
  24479. } else if (state) {
  24480. add$3(elm, cls);
  24481. }
  24482. };
  24483. var setEditorCommandState = function (editor, cmd, state) {
  24484. try {
  24485. editor.getDoc().execCommand(cmd, false, state);
  24486. } catch (ex) {
  24487. }
  24488. };
  24489. var setContentEditable = function (elm, state) {
  24490. elm.dom().contentEditable = state ? 'true' : 'false';
  24491. };
  24492. var switchOffContentEditableTrue = function (elm) {
  24493. each(descendants$1(elm, '*[contenteditable="true"]'), function (elm) {
  24494. set(elm, internalContentEditableAttr, 'true');
  24495. setContentEditable(elm, false);
  24496. });
  24497. };
  24498. var switchOnContentEditableTrue = function (elm) {
  24499. each(descendants$1(elm, '*[' + internalContentEditableAttr + '="true"]'), function (elm) {
  24500. remove(elm, internalContentEditableAttr);
  24501. setContentEditable(elm, true);
  24502. });
  24503. };
  24504. var removeFakeSelection = function (editor) {
  24505. Option.from(editor.selection.getNode()).each(function (elm) {
  24506. elm.removeAttribute('data-mce-selected');
  24507. });
  24508. };
  24509. var restoreFakeSelection = function (editor) {
  24510. editor.selection.setRng(editor.selection.getRng());
  24511. };
  24512. var toggleReadOnly = function (editor, state) {
  24513. var body = Element.fromDom(editor.getBody());
  24514. toggleClass(body, 'mce-content-readonly', state);
  24515. if (state) {
  24516. editor.selection.controlSelection.hideResizeRect();
  24517. editor._selectionOverrides.hideFakeCaret();
  24518. removeFakeSelection(editor);
  24519. editor.readonly = true;
  24520. setContentEditable(body, false);
  24521. switchOffContentEditableTrue(body);
  24522. } else {
  24523. editor.readonly = false;
  24524. setContentEditable(body, true);
  24525. switchOnContentEditableTrue(body);
  24526. setEditorCommandState(editor, 'StyleWithCSS', false);
  24527. setEditorCommandState(editor, 'enableInlineTableEditing', false);
  24528. setEditorCommandState(editor, 'enableObjectResizing', false);
  24529. if (EditorFocus.hasEditorOrUiFocus(editor)) {
  24530. editor.focus();
  24531. }
  24532. restoreFakeSelection(editor);
  24533. editor.nodeChanged();
  24534. }
  24535. };
  24536. var isReadOnly = function (editor) {
  24537. return editor.readonly === true;
  24538. };
  24539. var registerFilters = function (editor) {
  24540. editor.parser.addAttributeFilter('contenteditable', function (nodes) {
  24541. if (isReadOnly(editor)) {
  24542. each(nodes, function (node) {
  24543. node.attr(internalContentEditableAttr, node.attr('contenteditable'));
  24544. node.attr('contenteditable', 'false');
  24545. });
  24546. }
  24547. });
  24548. editor.serializer.addAttributeFilter(internalContentEditableAttr, function (nodes) {
  24549. if (isReadOnly(editor)) {
  24550. each(nodes, function (node) {
  24551. node.attr('contenteditable', node.attr(internalContentEditableAttr));
  24552. });
  24553. }
  24554. });
  24555. editor.serializer.addTempAttr(internalContentEditableAttr);
  24556. };
  24557. var registerReadOnlyContentFilters = function (editor) {
  24558. if (editor.serializer) {
  24559. registerFilters(editor);
  24560. } else {
  24561. editor.on('PreInit', function () {
  24562. registerFilters(editor);
  24563. });
  24564. }
  24565. };
  24566. var isClickEvent = function (e) {
  24567. return e.type === 'click';
  24568. };
  24569. var preventReadOnlyEvents = function (e) {
  24570. var target = e.target;
  24571. if (isClickEvent(e) && target.tagName === 'A' && !VK.metaKeyPressed(e)) {
  24572. e.preventDefault();
  24573. }
  24574. };
  24575. var registerReadOnlySelectionBlockers = function (editor) {
  24576. editor.on('ShowCaret', function (e) {
  24577. if (isReadOnly(editor)) {
  24578. e.preventDefault();
  24579. }
  24580. });
  24581. editor.on('ObjectSelected', function (e) {
  24582. if (isReadOnly(editor)) {
  24583. e.preventDefault();
  24584. }
  24585. });
  24586. };
  24587. var defaultModes = [
  24588. 'design',
  24589. 'readonly'
  24590. ];
  24591. var switchToMode = function (editor, activeMode, availableModes, mode) {
  24592. var oldMode = availableModes[activeMode.get()];
  24593. var newMode = availableModes[mode];
  24594. try {
  24595. newMode.activate();
  24596. } catch (e) {
  24597. domGlobals.console.error('problem while activating editor mode ' + mode + ':', e);
  24598. return;
  24599. }
  24600. oldMode.deactivate();
  24601. if (oldMode.editorReadOnly !== newMode.editorReadOnly) {
  24602. toggleReadOnly(editor, newMode.editorReadOnly);
  24603. }
  24604. activeMode.set(mode);
  24605. Events.fireSwitchMode(editor, mode);
  24606. };
  24607. var setMode = function (editor, availableModes, activeMode, mode) {
  24608. if (mode === activeMode.get()) {
  24609. return;
  24610. } else if (!has(availableModes, mode)) {
  24611. throw new Error('Editor mode \'' + mode + '\' is invalid');
  24612. }
  24613. if (editor.initialized) {
  24614. switchToMode(editor, activeMode, availableModes, mode);
  24615. } else {
  24616. editor.on('init', function () {
  24617. return switchToMode(editor, activeMode, availableModes, mode);
  24618. });
  24619. }
  24620. };
  24621. var registerMode = function (availableModes, mode, api) {
  24622. var _a;
  24623. if (contains(defaultModes, mode)) {
  24624. throw new Error('Cannot override default mode ' + mode);
  24625. }
  24626. return __assign(__assign({}, availableModes), (_a = {}, _a[mode] = __assign(__assign({}, api), {
  24627. deactivate: function () {
  24628. try {
  24629. api.deactivate();
  24630. } catch (e) {
  24631. domGlobals.console.error('problem while deactivating editor mode ' + mode + ':', e);
  24632. }
  24633. }
  24634. }), _a));
  24635. };
  24636. var create$4 = function (editor) {
  24637. var activeMode = Cell('design');
  24638. var availableModes = Cell({
  24639. design: {
  24640. activate: noop,
  24641. deactivate: noop,
  24642. editorReadOnly: false
  24643. },
  24644. readonly: {
  24645. activate: noop,
  24646. deactivate: noop,
  24647. editorReadOnly: true
  24648. }
  24649. });
  24650. registerReadOnlyContentFilters(editor);
  24651. registerReadOnlySelectionBlockers(editor);
  24652. return {
  24653. isReadOnly: function () {
  24654. return isReadOnly(editor);
  24655. },
  24656. set: function (mode) {
  24657. return setMode(editor, availableModes.get(), activeMode, mode);
  24658. },
  24659. get: function () {
  24660. return activeMode.get();
  24661. },
  24662. register: function (mode, api) {
  24663. availableModes.set(registerMode(availableModes.get(), mode, api));
  24664. }
  24665. };
  24666. };
  24667. var hasOnlyOneChild$1 = function (node) {
  24668. return node.firstChild && node.firstChild === node.lastChild;
  24669. };
  24670. var isPaddingNode = function (node) {
  24671. return node.name === 'br' || node.value === '\xA0';
  24672. };
  24673. var isPaddedEmptyBlock = function (schema, node) {
  24674. var blockElements = schema.getBlockElements();
  24675. return blockElements[node.name] && hasOnlyOneChild$1(node) && isPaddingNode(node.firstChild);
  24676. };
  24677. var isEmptyFragmentElement = function (schema, node) {
  24678. var nonEmptyElements = schema.getNonEmptyElements();
  24679. return node && (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node));
  24680. };
  24681. var isListFragment = function (schema, fragment) {
  24682. var firstChild = fragment.firstChild;
  24683. var lastChild = fragment.lastChild;
  24684. if (firstChild && firstChild.name === 'meta') {
  24685. firstChild = firstChild.next;
  24686. }
  24687. if (lastChild && lastChild.attr('id') === 'mce_marker') {
  24688. lastChild = lastChild.prev;
  24689. }
  24690. if (isEmptyFragmentElement(schema, lastChild)) {
  24691. lastChild = lastChild.prev;
  24692. }
  24693. if (!firstChild || firstChild !== lastChild) {
  24694. return false;
  24695. }
  24696. return firstChild.name === 'ul' || firstChild.name === 'ol';
  24697. };
  24698. var cleanupDomFragment = function (domFragment) {
  24699. var firstChild = domFragment.firstChild;
  24700. var lastChild = domFragment.lastChild;
  24701. if (firstChild && firstChild.nodeName === 'META') {
  24702. firstChild.parentNode.removeChild(firstChild);
  24703. }
  24704. if (lastChild && lastChild.id === 'mce_marker') {
  24705. lastChild.parentNode.removeChild(lastChild);
  24706. }
  24707. return domFragment;
  24708. };
  24709. var toDomFragment = function (dom, serializer, fragment) {
  24710. var html = serializer.serialize(fragment);
  24711. var domFragment = dom.createFragment(html);
  24712. return cleanupDomFragment(domFragment);
  24713. };
  24714. var listItems$1 = function (elm) {
  24715. return Tools.grep(elm.childNodes, function (child) {
  24716. return child.nodeName === 'LI';
  24717. });
  24718. };
  24719. var isPadding = function (node) {
  24720. return node.data === '\xA0' || NodeType.isBr(node);
  24721. };
  24722. var isListItemPadded = function (node) {
  24723. return node && node.firstChild && node.firstChild === node.lastChild && isPadding(node.firstChild);
  24724. };
  24725. var isEmptyOrPadded = function (elm) {
  24726. return !elm.firstChild || isListItemPadded(elm);
  24727. };
  24728. var trimListItems = function (elms) {
  24729. return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1]) ? elms.slice(0, -1) : elms;
  24730. };
  24731. var getParentLi = function (dom, node) {
  24732. var parentBlock = dom.getParent(node, dom.isBlock);
  24733. return parentBlock && parentBlock.nodeName === 'LI' ? parentBlock : null;
  24734. };
  24735. var isParentBlockLi = function (dom, node) {
  24736. return !!getParentLi(dom, node);
  24737. };
  24738. var getSplit = function (parentNode, rng) {
  24739. var beforeRng = rng.cloneRange();
  24740. var afterRng = rng.cloneRange();
  24741. beforeRng.setStartBefore(parentNode);
  24742. afterRng.setEndAfter(parentNode);
  24743. return [
  24744. beforeRng.cloneContents(),
  24745. afterRng.cloneContents()
  24746. ];
  24747. };
  24748. var findFirstIn = function (node, rootNode) {
  24749. var caretPos = CaretPosition$1.before(node);
  24750. var caretWalker = CaretWalker(rootNode);
  24751. var newCaretPos = caretWalker.next(caretPos);
  24752. return newCaretPos ? newCaretPos.toRange() : null;
  24753. };
  24754. var findLastOf = function (node, rootNode) {
  24755. var caretPos = CaretPosition$1.after(node);
  24756. var caretWalker = CaretWalker(rootNode);
  24757. var newCaretPos = caretWalker.prev(caretPos);
  24758. return newCaretPos ? newCaretPos.toRange() : null;
  24759. };
  24760. var insertMiddle = function (target, elms, rootNode, rng) {
  24761. var parts = getSplit(target, rng);
  24762. var parentElm = target.parentNode;
  24763. parentElm.insertBefore(parts[0], target);
  24764. Tools.each(elms, function (li) {
  24765. parentElm.insertBefore(li, target);
  24766. });
  24767. parentElm.insertBefore(parts[1], target);
  24768. parentElm.removeChild(target);
  24769. return findLastOf(elms[elms.length - 1], rootNode);
  24770. };
  24771. var insertBefore$1 = function (target, elms, rootNode) {
  24772. var parentElm = target.parentNode;
  24773. Tools.each(elms, function (elm) {
  24774. parentElm.insertBefore(elm, target);
  24775. });
  24776. return findFirstIn(target, rootNode);
  24777. };
  24778. var insertAfter$1 = function (target, elms, rootNode, dom) {
  24779. dom.insertAfter(elms.reverse(), target);
  24780. return findLastOf(elms[0], rootNode);
  24781. };
  24782. var insertAtCaret = function (serializer, dom, rng, fragment) {
  24783. var domFragment = toDomFragment(dom, serializer, fragment);
  24784. var liTarget = getParentLi(dom, rng.startContainer);
  24785. var liElms = trimListItems(listItems$1(domFragment.firstChild));
  24786. var BEGINNING = 1, END = 2;
  24787. var rootNode = dom.getRoot();
  24788. var isAt = function (location) {
  24789. var caretPos = CaretPosition$1.fromRangeStart(rng);
  24790. var caretWalker = CaretWalker(dom.getRoot());
  24791. var newPos = location === BEGINNING ? caretWalker.prev(caretPos) : caretWalker.next(caretPos);
  24792. return newPos ? getParentLi(dom, newPos.getNode()) !== liTarget : true;
  24793. };
  24794. if (isAt(BEGINNING)) {
  24795. return insertBefore$1(liTarget, liElms, rootNode);
  24796. } else if (isAt(END)) {
  24797. return insertAfter$1(liTarget, liElms, rootNode, dom);
  24798. }
  24799. return insertMiddle(liTarget, liElms, rootNode, rng);
  24800. };
  24801. var InsertList = {
  24802. isListFragment: isListFragment,
  24803. insertAtCaret: insertAtCaret,
  24804. isParentBlockLi: isParentBlockLi,
  24805. trimListItems: trimListItems,
  24806. listItems: listItems$1
  24807. };
  24808. var isAfterNbsp = function (container, offset) {
  24809. return NodeType.isText(container) && container.nodeValue[offset - 1] === '\xA0';
  24810. };
  24811. var trimOrPadLeftRight = function (rng, html) {
  24812. var container, offset;
  24813. container = rng.startContainer;
  24814. offset = rng.startOffset;
  24815. var hasSiblingText = function (siblingName) {
  24816. return container[siblingName] && container[siblingName].nodeType === 3;
  24817. };
  24818. if (container.nodeType === 3) {
  24819. if (offset > 0) {
  24820. html = html.replace(/^&nbsp;/, ' ');
  24821. } else if (!hasSiblingText('previousSibling')) {
  24822. html = html.replace(/^ /, '&nbsp;');
  24823. }
  24824. if (offset < container.length) {
  24825. html = html.replace(/&nbsp;(<br>|)$/, ' ');
  24826. } else if (!hasSiblingText('nextSibling')) {
  24827. html = html.replace(/(&nbsp;| )(<br>|)$/, '&nbsp;');
  24828. }
  24829. }
  24830. return html;
  24831. };
  24832. var trimNbspAfterDeleteAndPadValue = function (rng, value) {
  24833. var container, offset;
  24834. container = rng.startContainer;
  24835. offset = rng.startOffset;
  24836. if (container.nodeType === 3 && rng.collapsed) {
  24837. if (container.data[offset] === '\xA0') {
  24838. container.deleteData(offset, 1);
  24839. if (!/[\u00a0| ]$/.test(value)) {
  24840. value += ' ';
  24841. }
  24842. } else if (container.data[offset - 1] === '\xA0') {
  24843. container.deleteData(offset - 1, 1);
  24844. if (!/[\u00a0| ]$/.test(value)) {
  24845. value = ' ' + value;
  24846. }
  24847. }
  24848. }
  24849. return value;
  24850. };
  24851. var isTableCell$5 = NodeType.matchNodeNames([
  24852. 'td',
  24853. 'th'
  24854. ]);
  24855. var selectionSetContent = function (editor, content) {
  24856. var rng = editor.selection.getRng();
  24857. var container = rng.startContainer;
  24858. var offset = rng.startOffset;
  24859. if (rng.collapsed && isAfterNbsp(container, offset) && NodeType.isText(container)) {
  24860. container.insertData(offset - 1, ' ');
  24861. container.deleteData(offset, 1);
  24862. rng.setStart(container, offset);
  24863. rng.setEnd(container, offset);
  24864. editor.selection.setRng(rng);
  24865. }
  24866. editor.selection.setContent(content);
  24867. };
  24868. var validInsertion = function (editor, value, parentNode) {
  24869. if (parentNode.getAttribute('data-mce-bogus') === 'all') {
  24870. parentNode.parentNode.insertBefore(editor.dom.createFragment(value), parentNode);
  24871. } else {
  24872. var node = parentNode.firstChild;
  24873. var node2 = parentNode.lastChild;
  24874. if (!node || node === node2 && node.nodeName === 'BR') {
  24875. editor.dom.setHTML(parentNode, value);
  24876. } else {
  24877. selectionSetContent(editor, value);
  24878. }
  24879. }
  24880. };
  24881. var trimBrsFromTableCell = function (dom, elm) {
  24882. Option.from(dom.getParent(elm, 'td,th')).map(Element.fromDom).each(PaddingBr.trimBlockTrailingBr);
  24883. };
  24884. var reduceInlineTextElements = function (editor, merge) {
  24885. var textInlineElements = editor.schema.getTextInlineElements();
  24886. var dom = editor.dom;
  24887. if (merge) {
  24888. var root_1 = editor.getBody(), elementUtils_1 = new ElementUtils(dom);
  24889. Tools.each(dom.select('*[data-mce-fragment]'), function (node) {
  24890. for (var testNode = node.parentNode; testNode && testNode !== root_1; testNode = testNode.parentNode) {
  24891. if (textInlineElements[node.nodeName.toLowerCase()] && elementUtils_1.compare(testNode, node)) {
  24892. dom.remove(node, true);
  24893. }
  24894. }
  24895. });
  24896. }
  24897. };
  24898. var markFragmentElements = function (fragment) {
  24899. var node = fragment;
  24900. while (node = node.walk()) {
  24901. if (node.type === 1) {
  24902. node.attr('data-mce-fragment', '1');
  24903. }
  24904. }
  24905. };
  24906. var umarkFragmentElements = function (elm) {
  24907. Tools.each(elm.getElementsByTagName('*'), function (elm) {
  24908. elm.removeAttribute('data-mce-fragment');
  24909. });
  24910. };
  24911. var isPartOfFragment = function (node) {
  24912. return !!node.getAttribute('data-mce-fragment');
  24913. };
  24914. var canHaveChildren = function (editor, node) {
  24915. return node && !editor.schema.getShortEndedElements()[node.nodeName];
  24916. };
  24917. var moveSelectionToMarker = function (editor, marker) {
  24918. var parentEditableFalseElm, parentBlock, nextRng;
  24919. var dom = editor.dom, selection = editor.selection;
  24920. var node, node2;
  24921. var getContentEditableFalseParent = function (node) {
  24922. var root = editor.getBody();
  24923. for (; node && node !== root; node = node.parentNode) {
  24924. if (editor.dom.getContentEditable(node) === 'false') {
  24925. return node;
  24926. }
  24927. }
  24928. return null;
  24929. };
  24930. if (!marker) {
  24931. return;
  24932. }
  24933. editor.selection.scrollIntoView(marker);
  24934. parentEditableFalseElm = getContentEditableFalseParent(marker);
  24935. if (parentEditableFalseElm) {
  24936. dom.remove(marker);
  24937. selection.select(parentEditableFalseElm);
  24938. return;
  24939. }
  24940. var rng = dom.createRng();
  24941. node = marker.previousSibling;
  24942. if (node && node.nodeType === 3) {
  24943. rng.setStart(node, node.nodeValue.length);
  24944. if (!Env.ie) {
  24945. node2 = marker.nextSibling;
  24946. if (node2 && node2.nodeType === 3) {
  24947. node.appendData(node2.data);
  24948. node2.parentNode.removeChild(node2);
  24949. }
  24950. }
  24951. } else {
  24952. rng.setStartBefore(marker);
  24953. rng.setEndBefore(marker);
  24954. }
  24955. var findNextCaretRng = function (rng) {
  24956. var caretPos = CaretPosition$1.fromRangeStart(rng);
  24957. var caretWalker = CaretWalker(editor.getBody());
  24958. caretPos = caretWalker.next(caretPos);
  24959. if (caretPos) {
  24960. return caretPos.toRange();
  24961. }
  24962. };
  24963. parentBlock = dom.getParent(marker, dom.isBlock);
  24964. dom.remove(marker);
  24965. if (parentBlock && dom.isEmpty(parentBlock)) {
  24966. editor.$(parentBlock).empty();
  24967. rng.setStart(parentBlock, 0);
  24968. rng.setEnd(parentBlock, 0);
  24969. if (!isTableCell$5(parentBlock) && !isPartOfFragment(parentBlock) && (nextRng = findNextCaretRng(rng))) {
  24970. rng = nextRng;
  24971. dom.remove(parentBlock);
  24972. } else {
  24973. dom.add(parentBlock, dom.create('br', { 'data-mce-bogus': '1' }));
  24974. }
  24975. }
  24976. selection.setRng(rng);
  24977. };
  24978. var insertHtmlAtCaret = function (editor, value, details) {
  24979. var parser, serializer, parentNode, rootNode, fragment, args;
  24980. var marker, rng, node, bookmarkHtml, merge;
  24981. var selection = editor.selection, dom = editor.dom;
  24982. if (/^ | $/.test(value)) {
  24983. value = trimOrPadLeftRight(selection.getRng(), value);
  24984. }
  24985. parser = editor.parser;
  24986. merge = details.merge;
  24987. serializer = Serializer({ validate: editor.settings.validate }, editor.schema);
  24988. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">&#xFEFF;&#x200B;</span>';
  24989. args = {
  24990. content: value,
  24991. format: 'html',
  24992. selection: true,
  24993. paste: details.paste
  24994. };
  24995. args = editor.fire('BeforeSetContent', args);
  24996. if (args.isDefaultPrevented()) {
  24997. editor.fire('SetContent', {
  24998. content: args.content,
  24999. format: 'html',
  25000. selection: true,
  25001. paste: details.paste
  25002. });
  25003. return;
  25004. }
  25005. value = args.content;
  25006. if (value.indexOf('{$caret}') === -1) {
  25007. value += '{$caret}';
  25008. }
  25009. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  25010. rng = selection.getRng();
  25011. var caretElement = rng.startContainer || (rng.parentElement ? rng.parentElement() : null);
  25012. var body = editor.getBody();
  25013. if (caretElement === body && selection.isCollapsed()) {
  25014. if (dom.isBlock(body.firstChild) && canHaveChildren(editor, body.firstChild) && dom.isEmpty(body.firstChild)) {
  25015. rng = dom.createRng();
  25016. rng.setStart(body.firstChild, 0);
  25017. rng.setEnd(body.firstChild, 0);
  25018. selection.setRng(rng);
  25019. }
  25020. }
  25021. if (!selection.isCollapsed()) {
  25022. editor.selection.setRng(RangeNormalizer.normalize(editor.selection.getRng()));
  25023. editor.getDoc().execCommand('Delete', false, null);
  25024. value = trimNbspAfterDeleteAndPadValue(editor.selection.getRng(), value);
  25025. }
  25026. parentNode = selection.getNode();
  25027. var parserArgs = {
  25028. context: parentNode.nodeName.toLowerCase(),
  25029. data: details.data,
  25030. insert: true
  25031. };
  25032. fragment = parser.parse(value, parserArgs);
  25033. if (details.paste === true && InsertList.isListFragment(editor.schema, fragment) && InsertList.isParentBlockLi(dom, parentNode)) {
  25034. rng = InsertList.insertAtCaret(serializer, dom, editor.selection.getRng(), fragment);
  25035. editor.selection.setRng(rng);
  25036. editor.fire('SetContent', args);
  25037. return;
  25038. }
  25039. markFragmentElements(fragment);
  25040. node = fragment.lastChild;
  25041. if (node.attr('id') === 'mce_marker') {
  25042. marker = node;
  25043. for (node = node.prev; node; node = node.walk(true)) {
  25044. if (node.type === 3 || !dom.isBlock(node.name)) {
  25045. if (editor.schema.isValidChild(node.parent.name, 'span')) {
  25046. node.parent.insert(marker, node, node.name === 'br');
  25047. }
  25048. break;
  25049. }
  25050. }
  25051. }
  25052. editor._selectionOverrides.showBlockCaretContainer(parentNode);
  25053. if (!parserArgs.invalid) {
  25054. value = serializer.serialize(fragment);
  25055. validInsertion(editor, value, parentNode);
  25056. } else {
  25057. selectionSetContent(editor, bookmarkHtml);
  25058. parentNode = selection.getNode();
  25059. rootNode = editor.getBody();
  25060. if (parentNode.nodeType === 9) {
  25061. parentNode = node = rootNode;
  25062. } else {
  25063. node = parentNode;
  25064. }
  25065. while (node !== rootNode) {
  25066. parentNode = node;
  25067. node = node.parentNode;
  25068. }
  25069. value = parentNode === rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  25070. value = serializer.serialize(parser.parse(value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function () {
  25071. return serializer.serialize(fragment);
  25072. })));
  25073. if (parentNode === rootNode) {
  25074. dom.setHTML(rootNode, value);
  25075. } else {
  25076. dom.setOuterHTML(parentNode, value);
  25077. }
  25078. }
  25079. reduceInlineTextElements(editor, merge);
  25080. moveSelectionToMarker(editor, dom.get('mce_marker'));
  25081. umarkFragmentElements(editor.getBody());
  25082. trimBrsFromTableCell(editor.dom, editor.selection.getStart());
  25083. editor.fire('SetContent', args);
  25084. editor.addVisual();
  25085. };
  25086. var processValue = function (value) {
  25087. var details;
  25088. if (typeof value !== 'string') {
  25089. details = Tools.extend({
  25090. paste: value.paste,
  25091. data: { paste: value.paste }
  25092. }, value);
  25093. return {
  25094. content: value.content,
  25095. details: details
  25096. };
  25097. }
  25098. return {
  25099. content: value,
  25100. details: {}
  25101. };
  25102. };
  25103. var insertAtCaret$1 = function (editor, value) {
  25104. var result = processValue(value);
  25105. insertHtmlAtCaret(editor, result.content, result.details);
  25106. };
  25107. var InsertContent = { insertAtCaret: insertAtCaret$1 };
  25108. var nativeCommand = function (editor, command) {
  25109. editor.getDoc().execCommand(command, false, null);
  25110. };
  25111. var deleteCommand = function (editor) {
  25112. if (Outdent.backspaceDelete(editor, false)) {
  25113. return;
  25114. } else if (CefDelete.backspaceDelete(editor, false)) {
  25115. return;
  25116. } else if (CefBoundaryDelete.backspaceDelete(editor, false)) {
  25117. return;
  25118. } else if (BoundaryDelete.backspaceDelete(editor, false)) {
  25119. return;
  25120. } else if (BlockBoundaryDelete.backspaceDelete(editor, false)) {
  25121. return;
  25122. } else if (TableDelete.backspaceDelete(editor)) {
  25123. return;
  25124. } else if (BlockRangeDelete.backspaceDelete(editor, false)) {
  25125. return;
  25126. } else if (InlineFormatDelete.backspaceDelete(editor, false)) {
  25127. return;
  25128. } else {
  25129. nativeCommand(editor, 'Delete');
  25130. DeleteUtils.paddEmptyBody(editor);
  25131. }
  25132. };
  25133. var forwardDeleteCommand = function (editor) {
  25134. if (CefDelete.backspaceDelete(editor, true)) {
  25135. return;
  25136. } else if (CefBoundaryDelete.backspaceDelete(editor, true)) {
  25137. return;
  25138. } else if (BoundaryDelete.backspaceDelete(editor, true)) {
  25139. return;
  25140. } else if (BlockBoundaryDelete.backspaceDelete(editor, true)) {
  25141. return;
  25142. } else if (TableDelete.backspaceDelete(editor)) {
  25143. return;
  25144. } else if (BlockRangeDelete.backspaceDelete(editor, true)) {
  25145. return;
  25146. } else if (InlineFormatDelete.backspaceDelete(editor, true)) {
  25147. return;
  25148. } else {
  25149. nativeCommand(editor, 'ForwardDelete');
  25150. }
  25151. };
  25152. var DeleteCommands = {
  25153. deleteCommand: deleteCommand,
  25154. forwardDeleteCommand: forwardDeleteCommand
  25155. };
  25156. var getSpecifiedFontProp = function (propName, rootElm, elm) {
  25157. var getProperty = function (elm) {
  25158. return getRaw(elm, propName);
  25159. };
  25160. var isRoot = function (elm) {
  25161. return eq(Element.fromDom(rootElm), elm);
  25162. };
  25163. return closest(Element.fromDom(elm), function (elm) {
  25164. return getProperty(elm).isSome();
  25165. }, isRoot).bind(getProperty);
  25166. };
  25167. var round$1 = function (number, precision) {
  25168. var factor = Math.pow(10, precision);
  25169. return Math.round(number * factor) / factor;
  25170. };
  25171. var toPt = function (fontSize, precision) {
  25172. if (/[0-9.]+px$/.test(fontSize)) {
  25173. return round$1(parseInt(fontSize, 10) * 72 / 96, precision || 0) + 'pt';
  25174. }
  25175. return fontSize;
  25176. };
  25177. var normalizeFontFamily = function (fontFamily) {
  25178. return fontFamily.replace(/[\'\"\\]/g, '').replace(/,\s+/g, ',');
  25179. };
  25180. var getComputedFontProp = function (propName, elm) {
  25181. return Option.from(DOMUtils$1.DOM.getStyle(elm, propName, true));
  25182. };
  25183. var getFontProp = function (propName) {
  25184. return function (rootElm, elm) {
  25185. return Option.from(elm).map(Element.fromDom).filter(isElement$1).bind(function (element) {
  25186. return getSpecifiedFontProp(propName, rootElm, element.dom()).or(getComputedFontProp(propName, element.dom()));
  25187. }).getOr('');
  25188. };
  25189. };
  25190. var FontInfo = {
  25191. getFontSize: getFontProp('font-size'),
  25192. getFontFamily: compose(normalizeFontFamily, getFontProp('font-family')),
  25193. toPt: toPt
  25194. };
  25195. var findFirstCaretElement = function (editor) {
  25196. return CaretFinder.firstPositionIn(editor.getBody()).map(function (caret) {
  25197. var container = caret.container();
  25198. return NodeType.isText(container) ? container.parentNode : container;
  25199. });
  25200. };
  25201. var isRangeAtStartOfNode = function (rng, root) {
  25202. return rng.startContainer === root && rng.startOffset === 0;
  25203. };
  25204. var getCaretElement = function (editor) {
  25205. return Option.from(editor.selection.getRng()).bind(function (rng) {
  25206. var root = editor.getBody();
  25207. return isRangeAtStartOfNode(rng, root) ? Option.none() : Option.from(editor.selection.getStart(true));
  25208. });
  25209. };
  25210. var fromFontSizeNumber = function (editor, value) {
  25211. if (/^[0-9\.]+$/.test(value)) {
  25212. var fontSizeNumber = parseInt(value, 10);
  25213. if (fontSizeNumber >= 1 && fontSizeNumber <= 7) {
  25214. var fontSizes = Settings.getFontStyleValues(editor);
  25215. var fontClasses = Settings.getFontSizeClasses(editor);
  25216. if (fontClasses) {
  25217. return fontClasses[fontSizeNumber - 1] || value;
  25218. } else {
  25219. return fontSizes[fontSizeNumber - 1] || value;
  25220. }
  25221. } else {
  25222. return value;
  25223. }
  25224. } else {
  25225. return value;
  25226. }
  25227. };
  25228. var normalizeFontNames = function (font) {
  25229. var fonts = font.split(/\s*,\s*/);
  25230. return map(fonts, function (font) {
  25231. if (font.indexOf(' ') !== -1 && !(startsWith(font, '"') || startsWith(font, '\''))) {
  25232. return '\'' + font + '\'';
  25233. } else {
  25234. return font;
  25235. }
  25236. }).join(',');
  25237. };
  25238. var fontNameAction = function (editor, value) {
  25239. var font = fromFontSizeNumber(editor, value);
  25240. editor.formatter.toggle('fontname', { value: normalizeFontNames(font) });
  25241. editor.nodeChanged();
  25242. };
  25243. var fontNameQuery = function (editor) {
  25244. return getCaretElement(editor).fold(function () {
  25245. return findFirstCaretElement(editor).map(function (caretElement) {
  25246. return FontInfo.getFontFamily(editor.getBody(), caretElement);
  25247. }).getOr('');
  25248. }, function (caretElement) {
  25249. return FontInfo.getFontFamily(editor.getBody(), caretElement);
  25250. });
  25251. };
  25252. var fontSizeAction = function (editor, value) {
  25253. editor.formatter.toggle('fontsize', { value: fromFontSizeNumber(editor, value) });
  25254. editor.nodeChanged();
  25255. };
  25256. var fontSizeQuery = function (editor) {
  25257. return getCaretElement(editor).fold(function () {
  25258. return findFirstCaretElement(editor).map(function (caretElement) {
  25259. return FontInfo.getFontSize(editor.getBody(), caretElement);
  25260. }).getOr('');
  25261. }, function (caretElement) {
  25262. return FontInfo.getFontSize(editor.getBody(), caretElement);
  25263. });
  25264. };
  25265. var each$g = Tools.each;
  25266. var map$3 = Tools.map, inArray$2 = Tools.inArray;
  25267. var EditorCommands = function () {
  25268. function EditorCommands(editor) {
  25269. this.commands = {
  25270. state: {},
  25271. exec: {},
  25272. value: {}
  25273. };
  25274. this.editor = editor;
  25275. this.setupCommands(editor);
  25276. }
  25277. EditorCommands.prototype.execCommand = function (command, ui, value, args) {
  25278. var func, customCommand, state = false;
  25279. var self = this;
  25280. if (self.editor.removed) {
  25281. return;
  25282. }
  25283. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(command) && (!args || !args.skip_focus)) {
  25284. self.editor.focus();
  25285. } else {
  25286. SelectionBookmark.restore(self.editor);
  25287. }
  25288. args = self.editor.fire('BeforeExecCommand', {
  25289. command: command,
  25290. ui: ui,
  25291. value: value
  25292. });
  25293. if (args.isDefaultPrevented()) {
  25294. return false;
  25295. }
  25296. customCommand = command.toLowerCase();
  25297. if (func = self.commands.exec[customCommand]) {
  25298. func(customCommand, ui, value);
  25299. self.editor.fire('ExecCommand', {
  25300. command: command,
  25301. ui: ui,
  25302. value: value
  25303. });
  25304. return true;
  25305. }
  25306. each$g(this.editor.plugins, function (p) {
  25307. if (p.execCommand && p.execCommand(command, ui, value)) {
  25308. self.editor.fire('ExecCommand', {
  25309. command: command,
  25310. ui: ui,
  25311. value: value
  25312. });
  25313. state = true;
  25314. return false;
  25315. }
  25316. });
  25317. if (state) {
  25318. return state;
  25319. }
  25320. if (self.editor.theme && self.editor.theme.execCommand && self.editor.theme.execCommand(command, ui, value)) {
  25321. self.editor.fire('ExecCommand', {
  25322. command: command,
  25323. ui: ui,
  25324. value: value
  25325. });
  25326. return true;
  25327. }
  25328. try {
  25329. state = self.editor.getDoc().execCommand(command, ui, value);
  25330. } catch (ex) {
  25331. }
  25332. if (state) {
  25333. self.editor.fire('ExecCommand', {
  25334. command: command,
  25335. ui: ui,
  25336. value: value
  25337. });
  25338. return true;
  25339. }
  25340. return false;
  25341. };
  25342. EditorCommands.prototype.queryCommandState = function (command) {
  25343. var func;
  25344. if (this.editor.quirks.isHidden() || this.editor.removed) {
  25345. return;
  25346. }
  25347. command = command.toLowerCase();
  25348. if (func = this.commands.state[command]) {
  25349. return func(command);
  25350. }
  25351. try {
  25352. return this.editor.getDoc().queryCommandState(command);
  25353. } catch (ex) {
  25354. }
  25355. return false;
  25356. };
  25357. EditorCommands.prototype.queryCommandValue = function (command) {
  25358. var func;
  25359. if (this.editor.quirks.isHidden() || this.editor.removed) {
  25360. return;
  25361. }
  25362. command = command.toLowerCase();
  25363. if (func = this.commands.value[command]) {
  25364. return func(command);
  25365. }
  25366. try {
  25367. return this.editor.getDoc().queryCommandValue(command);
  25368. } catch (ex) {
  25369. }
  25370. };
  25371. EditorCommands.prototype.addCommands = function (commandList, type) {
  25372. var self = this;
  25373. type = type || 'exec';
  25374. each$g(commandList, function (callback, command) {
  25375. each$g(command.toLowerCase().split(','), function (command) {
  25376. self.commands[type][command] = callback;
  25377. });
  25378. });
  25379. };
  25380. EditorCommands.prototype.addCommand = function (command, callback, scope) {
  25381. var _this = this;
  25382. command = command.toLowerCase();
  25383. this.commands.exec[command] = function (command, ui, value, args) {
  25384. return callback.call(scope || _this.editor, ui, value, args);
  25385. };
  25386. };
  25387. EditorCommands.prototype.queryCommandSupported = function (command) {
  25388. command = command.toLowerCase();
  25389. if (this.commands.exec[command]) {
  25390. return true;
  25391. }
  25392. try {
  25393. return this.editor.getDoc().queryCommandSupported(command);
  25394. } catch (ex) {
  25395. }
  25396. return false;
  25397. };
  25398. EditorCommands.prototype.addQueryStateHandler = function (command, callback, scope) {
  25399. var _this = this;
  25400. command = command.toLowerCase();
  25401. this.commands.state[command] = function () {
  25402. return callback.call(scope || _this.editor);
  25403. };
  25404. };
  25405. EditorCommands.prototype.addQueryValueHandler = function (command, callback, scope) {
  25406. var _this = this;
  25407. command = command.toLowerCase();
  25408. this.commands.value[command] = function () {
  25409. return callback.call(scope || _this.editor);
  25410. };
  25411. };
  25412. EditorCommands.prototype.hasCustomCommand = function (command) {
  25413. command = command.toLowerCase();
  25414. return !!this.commands.exec[command];
  25415. };
  25416. EditorCommands.prototype.execNativeCommand = function (command, ui, value) {
  25417. if (ui === undefined) {
  25418. ui = false;
  25419. }
  25420. if (value === undefined) {
  25421. value = null;
  25422. }
  25423. return this.editor.getDoc().execCommand(command, ui, value);
  25424. };
  25425. EditorCommands.prototype.isFormatMatch = function (name) {
  25426. return this.editor.formatter.match(name);
  25427. };
  25428. EditorCommands.prototype.toggleFormat = function (name, value) {
  25429. this.editor.formatter.toggle(name, value ? { value: value } : undefined);
  25430. this.editor.nodeChanged();
  25431. };
  25432. EditorCommands.prototype.storeSelection = function (type) {
  25433. this.selectionBookmark = this.editor.selection.getBookmark(type);
  25434. };
  25435. EditorCommands.prototype.restoreSelection = function () {
  25436. this.editor.selection.moveToBookmark(this.selectionBookmark);
  25437. };
  25438. EditorCommands.prototype.setupCommands = function (editor) {
  25439. var self = this;
  25440. this.addCommands({
  25441. 'mceResetDesignMode,mceBeginUndoLevel': function () {
  25442. },
  25443. 'mceEndUndoLevel,mceAddUndoLevel': function () {
  25444. editor.undoManager.add();
  25445. },
  25446. 'Cut,Copy,Paste': function (command) {
  25447. var doc = editor.getDoc();
  25448. var failed;
  25449. try {
  25450. self.execNativeCommand(command);
  25451. } catch (ex) {
  25452. failed = true;
  25453. }
  25454. if (command === 'paste' && !doc.queryCommandEnabled(command)) {
  25455. failed = true;
  25456. }
  25457. if (failed || !doc.queryCommandSupported(command)) {
  25458. var msg = editor.translate('Your browser doesn\'t support direct access to the clipboard. ' + 'Please use the Ctrl+X/C/V keyboard shortcuts instead.');
  25459. if (Env.mac) {
  25460. msg = msg.replace(/Ctrl\+/g, '\u2318+');
  25461. }
  25462. editor.notificationManager.open({
  25463. text: msg,
  25464. type: 'error'
  25465. });
  25466. }
  25467. },
  25468. 'unlink': function () {
  25469. if (editor.selection.isCollapsed()) {
  25470. var elm = editor.dom.getParent(editor.selection.getStart(), 'a');
  25471. if (elm) {
  25472. editor.dom.remove(elm, true);
  25473. }
  25474. return;
  25475. }
  25476. editor.formatter.remove('link');
  25477. },
  25478. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone': function (command) {
  25479. var align = command.substring(7);
  25480. if (align === 'full') {
  25481. align = 'justify';
  25482. }
  25483. each$g('left,center,right,justify'.split(','), function (name) {
  25484. if (align !== name) {
  25485. editor.formatter.remove('align' + name);
  25486. }
  25487. });
  25488. if (align !== 'none') {
  25489. self.toggleFormat('align' + align);
  25490. }
  25491. },
  25492. 'InsertUnorderedList,InsertOrderedList': function (command) {
  25493. var listElm, listParent;
  25494. self.execNativeCommand(command);
  25495. listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
  25496. if (listElm) {
  25497. listParent = listElm.parentNode;
  25498. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  25499. self.storeSelection();
  25500. editor.dom.split(listParent, listElm);
  25501. self.restoreSelection();
  25502. }
  25503. }
  25504. },
  25505. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (command) {
  25506. self.toggleFormat(command);
  25507. },
  25508. 'ForeColor,HiliteColor': function (command, ui, value) {
  25509. self.toggleFormat(command, value);
  25510. },
  25511. 'FontName': function (command, ui, value) {
  25512. fontNameAction(editor, value);
  25513. },
  25514. 'FontSize': function (command, ui, value) {
  25515. fontSizeAction(editor, value);
  25516. },
  25517. 'RemoveFormat': function (command) {
  25518. editor.formatter.remove(command);
  25519. },
  25520. 'mceBlockQuote': function () {
  25521. self.toggleFormat('blockquote');
  25522. },
  25523. 'FormatBlock': function (command, ui, value) {
  25524. return self.toggleFormat(value || 'p');
  25525. },
  25526. 'mceCleanup': function () {
  25527. var bookmark = editor.selection.getBookmark();
  25528. editor.setContent(editor.getContent());
  25529. editor.selection.moveToBookmark(bookmark);
  25530. },
  25531. 'mceRemoveNode': function (command, ui, value) {
  25532. var node = value || editor.selection.getNode();
  25533. if (node !== editor.getBody()) {
  25534. self.storeSelection();
  25535. editor.dom.remove(node, true);
  25536. self.restoreSelection();
  25537. }
  25538. },
  25539. 'mceSelectNodeDepth': function (command, ui, value) {
  25540. var counter = 0;
  25541. editor.dom.getParent(editor.selection.getNode(), function (node) {
  25542. if (node.nodeType === 1 && counter++ === value) {
  25543. editor.selection.select(node);
  25544. return false;
  25545. }
  25546. }, editor.getBody());
  25547. },
  25548. 'mceSelectNode': function (command, ui, value) {
  25549. editor.selection.select(value);
  25550. },
  25551. 'mceInsertContent': function (command, ui, value) {
  25552. InsertContent.insertAtCaret(editor, value);
  25553. },
  25554. 'mceInsertRawHTML': function (command, ui, value) {
  25555. editor.selection.setContent('tiny_mce_marker');
  25556. var content = editor.getContent();
  25557. editor.setContent(content.replace(/tiny_mce_marker/g, function () {
  25558. return value;
  25559. }));
  25560. },
  25561. 'mceInsertNewLine': function (command, ui, value) {
  25562. InsertNewLine.insert(editor, value);
  25563. },
  25564. 'mceToggleFormat': function (command, ui, value) {
  25565. self.toggleFormat(value);
  25566. },
  25567. 'mceSetContent': function (command, ui, value) {
  25568. editor.setContent(value);
  25569. },
  25570. 'Indent,Outdent': function (command) {
  25571. handle(editor, command);
  25572. },
  25573. 'mceRepaint': function () {
  25574. },
  25575. 'InsertHorizontalRule': function () {
  25576. editor.execCommand('mceInsertContent', false, '<hr />');
  25577. },
  25578. 'mceToggleVisualAid': function () {
  25579. editor.hasVisual = !editor.hasVisual;
  25580. editor.addVisual();
  25581. },
  25582. 'mceReplaceContent': function (command, ui, value) {
  25583. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, editor.selection.getContent({ format: 'text' })));
  25584. },
  25585. 'mceInsertLink': function (command, ui, value) {
  25586. var anchor;
  25587. if (typeof value === 'string') {
  25588. value = { href: value };
  25589. }
  25590. anchor = editor.dom.getParent(editor.selection.getNode(), 'a');
  25591. value.href = value.href.replace(/ /g, '%20');
  25592. if (!anchor || !value.href) {
  25593. editor.formatter.remove('link');
  25594. }
  25595. if (value.href) {
  25596. editor.formatter.apply('link', value, anchor);
  25597. }
  25598. },
  25599. 'selectAll': function () {
  25600. var editingHost = editor.dom.getParent(editor.selection.getStart(), NodeType.isContentEditableTrue);
  25601. if (editingHost) {
  25602. var rng = editor.dom.createRng();
  25603. rng.selectNodeContents(editingHost);
  25604. editor.selection.setRng(rng);
  25605. }
  25606. },
  25607. 'delete': function () {
  25608. DeleteCommands.deleteCommand(editor);
  25609. },
  25610. 'forwardDelete': function () {
  25611. DeleteCommands.forwardDeleteCommand(editor);
  25612. },
  25613. 'mceNewDocument': function () {
  25614. editor.setContent('');
  25615. },
  25616. 'InsertLineBreak': function (command, ui, value) {
  25617. InsertBr.insert(editor, value);
  25618. return true;
  25619. }
  25620. });
  25621. var alignStates = function (name) {
  25622. return function () {
  25623. var nodes = editor.selection.isCollapsed() ? [editor.dom.getParent(editor.selection.getNode(), editor.dom.isBlock)] : editor.selection.getSelectedBlocks();
  25624. var matches = map$3(nodes, function (node) {
  25625. return !!editor.formatter.matchNode(node, name);
  25626. });
  25627. return inArray$2(matches, true) !== -1;
  25628. };
  25629. };
  25630. self.addCommands({
  25631. 'JustifyLeft': alignStates('alignleft'),
  25632. 'JustifyCenter': alignStates('aligncenter'),
  25633. 'JustifyRight': alignStates('alignright'),
  25634. 'JustifyFull': alignStates('alignjustify'),
  25635. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function (command) {
  25636. return self.isFormatMatch(command);
  25637. },
  25638. 'mceBlockQuote': function () {
  25639. return self.isFormatMatch('blockquote');
  25640. },
  25641. 'Outdent': function () {
  25642. return canOutdent(editor);
  25643. },
  25644. 'InsertUnorderedList,InsertOrderedList': function (command) {
  25645. var list = editor.dom.getParent(editor.selection.getNode(), 'ul,ol');
  25646. return list && (command === 'insertunorderedlist' && list.tagName === 'UL' || command === 'insertorderedlist' && list.tagName === 'OL');
  25647. }
  25648. }, 'state');
  25649. self.addCommands({
  25650. Undo: function () {
  25651. editor.undoManager.undo();
  25652. },
  25653. Redo: function () {
  25654. editor.undoManager.redo();
  25655. }
  25656. });
  25657. self.addQueryValueHandler('FontName', function () {
  25658. return fontNameQuery(editor);
  25659. }, this);
  25660. self.addQueryValueHandler('FontSize', function () {
  25661. return fontSizeQuery(editor);
  25662. }, this);
  25663. };
  25664. return EditorCommands;
  25665. }();
  25666. 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', ' ');
  25667. var EventDispatcher = function () {
  25668. function EventDispatcher(settings) {
  25669. this.bindings = {};
  25670. this.settings = settings || {};
  25671. this.scope = this.settings.scope || this;
  25672. this.toggleEvent = this.settings.toggleEvent || never;
  25673. }
  25674. EventDispatcher.isNative = function (name) {
  25675. return !!nativeEvents[name.toLowerCase()];
  25676. };
  25677. EventDispatcher.prototype.fire = function (name, args) {
  25678. var handlers, i, l, callback;
  25679. name = name.toLowerCase();
  25680. args = args || {};
  25681. args.type = name;
  25682. if (!args.target) {
  25683. args.target = this.scope;
  25684. }
  25685. if (!args.preventDefault) {
  25686. args.preventDefault = function () {
  25687. args.isDefaultPrevented = always;
  25688. };
  25689. args.stopPropagation = function () {
  25690. args.isPropagationStopped = always;
  25691. };
  25692. args.stopImmediatePropagation = function () {
  25693. args.isImmediatePropagationStopped = always;
  25694. };
  25695. args.isDefaultPrevented = never;
  25696. args.isPropagationStopped = never;
  25697. args.isImmediatePropagationStopped = never;
  25698. }
  25699. if (this.settings.beforeFire) {
  25700. this.settings.beforeFire(args);
  25701. }
  25702. handlers = this.bindings[name];
  25703. if (handlers) {
  25704. for (i = 0, l = handlers.length; i < l; i++) {
  25705. callback = handlers[i];
  25706. if (callback.once) {
  25707. this.off(name, callback.func);
  25708. }
  25709. if (args.isImmediatePropagationStopped()) {
  25710. args.stopPropagation();
  25711. return args;
  25712. }
  25713. if (callback.func.call(this.scope, args) === false) {
  25714. args.preventDefault();
  25715. return args;
  25716. }
  25717. }
  25718. }
  25719. return args;
  25720. };
  25721. EventDispatcher.prototype.on = function (name, callback, prepend, extra) {
  25722. var handlers, names, i;
  25723. if (callback === false) {
  25724. callback = never;
  25725. }
  25726. if (callback) {
  25727. var wrappedCallback = { func: callback };
  25728. if (extra) {
  25729. Tools.extend(wrappedCallback, extra);
  25730. }
  25731. names = name.toLowerCase().split(' ');
  25732. i = names.length;
  25733. while (i--) {
  25734. name = names[i];
  25735. handlers = this.bindings[name];
  25736. if (!handlers) {
  25737. handlers = this.bindings[name] = [];
  25738. this.toggleEvent(name, true);
  25739. }
  25740. if (prepend) {
  25741. handlers.unshift(wrappedCallback);
  25742. } else {
  25743. handlers.push(wrappedCallback);
  25744. }
  25745. }
  25746. }
  25747. return this;
  25748. };
  25749. EventDispatcher.prototype.off = function (name, callback) {
  25750. var i, handlers, bindingName, names, hi;
  25751. if (name) {
  25752. names = name.toLowerCase().split(' ');
  25753. i = names.length;
  25754. while (i--) {
  25755. name = names[i];
  25756. handlers = this.bindings[name];
  25757. if (!name) {
  25758. for (bindingName in this.bindings) {
  25759. this.toggleEvent(bindingName, false);
  25760. delete this.bindings[bindingName];
  25761. }
  25762. return this;
  25763. }
  25764. if (handlers) {
  25765. if (!callback) {
  25766. handlers.length = 0;
  25767. } else {
  25768. hi = handlers.length;
  25769. while (hi--) {
  25770. if (handlers[hi].func === callback) {
  25771. handlers = handlers.slice(0, hi).concat(handlers.slice(hi + 1));
  25772. this.bindings[name] = handlers;
  25773. }
  25774. }
  25775. }
  25776. if (!handlers.length) {
  25777. this.toggleEvent(name, false);
  25778. delete this.bindings[name];
  25779. }
  25780. }
  25781. }
  25782. } else {
  25783. for (name in this.bindings) {
  25784. this.toggleEvent(name, false);
  25785. }
  25786. this.bindings = {};
  25787. }
  25788. return this;
  25789. };
  25790. EventDispatcher.prototype.once = function (name, callback, prepend) {
  25791. return this.on(name, callback, prepend, { once: true });
  25792. };
  25793. EventDispatcher.prototype.has = function (name) {
  25794. name = name.toLowerCase();
  25795. return !(!this.bindings[name] || this.bindings[name].length === 0);
  25796. };
  25797. return EventDispatcher;
  25798. }();
  25799. var getEventDispatcher = function (obj) {
  25800. if (!obj._eventDispatcher) {
  25801. obj._eventDispatcher = new EventDispatcher({
  25802. scope: obj,
  25803. toggleEvent: function (name, state) {
  25804. if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) {
  25805. obj.toggleNativeEvent(name, state);
  25806. }
  25807. }
  25808. });
  25809. }
  25810. return obj._eventDispatcher;
  25811. };
  25812. var Observable = {
  25813. fire: function (name, args, bubble) {
  25814. var self = this;
  25815. if (self.removed && name !== 'remove' && name !== 'detach') {
  25816. return args;
  25817. }
  25818. var dispatcherArgs = getEventDispatcher(self).fire(name, args);
  25819. if (bubble !== false && self.parent) {
  25820. var parent = self.parent();
  25821. while (parent && !dispatcherArgs.isPropagationStopped()) {
  25822. parent.fire(name, dispatcherArgs, false);
  25823. parent = parent.parent();
  25824. }
  25825. }
  25826. return dispatcherArgs;
  25827. },
  25828. on: function (name, callback, prepend) {
  25829. return getEventDispatcher(this).on(name, callback, prepend);
  25830. },
  25831. off: function (name, callback) {
  25832. return getEventDispatcher(this).off(name, callback);
  25833. },
  25834. once: function (name, callback) {
  25835. return getEventDispatcher(this).once(name, callback);
  25836. },
  25837. hasEventListeners: function (name) {
  25838. return getEventDispatcher(this).has(name);
  25839. }
  25840. };
  25841. var DOM$7 = DOMUtils$1.DOM;
  25842. var customEventRootDelegates;
  25843. var getEventTarget = function (editor, eventName) {
  25844. if (eventName === 'selectionchange') {
  25845. return editor.getDoc();
  25846. }
  25847. if (!editor.inline && /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)) {
  25848. return editor.getDoc().documentElement;
  25849. }
  25850. if (editor.settings.event_root) {
  25851. if (!editor.eventRoot) {
  25852. editor.eventRoot = DOM$7.select(editor.settings.event_root)[0];
  25853. }
  25854. return editor.eventRoot;
  25855. }
  25856. return editor.getBody();
  25857. };
  25858. var isListening = function (editor) {
  25859. return !editor.hidden && !isReadOnly(editor);
  25860. };
  25861. var fireEvent = function (editor, eventName, e) {
  25862. if (isListening(editor)) {
  25863. editor.fire(eventName, e);
  25864. } else if (isReadOnly(editor)) {
  25865. preventReadOnlyEvents(e);
  25866. }
  25867. };
  25868. var bindEventDelegate = function (editor, eventName) {
  25869. var eventRootElm, delegate;
  25870. if (!editor.delegates) {
  25871. editor.delegates = {};
  25872. }
  25873. if (editor.delegates[eventName] || editor.removed) {
  25874. return;
  25875. }
  25876. eventRootElm = getEventTarget(editor, eventName);
  25877. if (editor.settings.event_root) {
  25878. if (!customEventRootDelegates) {
  25879. customEventRootDelegates = {};
  25880. editor.editorManager.on('removeEditor', function () {
  25881. var name;
  25882. if (!editor.editorManager.activeEditor) {
  25883. if (customEventRootDelegates) {
  25884. for (name in customEventRootDelegates) {
  25885. editor.dom.unbind(getEventTarget(editor, name));
  25886. }
  25887. customEventRootDelegates = null;
  25888. }
  25889. }
  25890. });
  25891. }
  25892. if (customEventRootDelegates[eventName]) {
  25893. return;
  25894. }
  25895. delegate = function (e) {
  25896. var target = e.target;
  25897. var editors = editor.editorManager.get();
  25898. var i = editors.length;
  25899. while (i--) {
  25900. var body = editors[i].getBody();
  25901. if (body === target || DOM$7.isChildOf(target, body)) {
  25902. fireEvent(editors[i], eventName, e);
  25903. }
  25904. }
  25905. };
  25906. customEventRootDelegates[eventName] = delegate;
  25907. DOM$7.bind(eventRootElm, eventName, delegate);
  25908. } else {
  25909. delegate = function (e) {
  25910. fireEvent(editor, eventName, e);
  25911. };
  25912. DOM$7.bind(eventRootElm, eventName, delegate);
  25913. editor.delegates[eventName] = delegate;
  25914. }
  25915. };
  25916. var EditorObservable = __assign(__assign({}, Observable), {
  25917. bindPendingEventDelegates: function () {
  25918. var self = this;
  25919. Tools.each(self._pendingNativeEvents, function (name) {
  25920. bindEventDelegate(self, name);
  25921. });
  25922. },
  25923. toggleNativeEvent: function (name, state) {
  25924. var self = this;
  25925. if (name === 'focus' || name === 'blur') {
  25926. return;
  25927. }
  25928. if (state) {
  25929. if (self.initialized) {
  25930. bindEventDelegate(self, name);
  25931. } else {
  25932. if (!self._pendingNativeEvents) {
  25933. self._pendingNativeEvents = [name];
  25934. } else {
  25935. self._pendingNativeEvents.push(name);
  25936. }
  25937. }
  25938. } else if (self.initialized) {
  25939. self.dom.unbind(getEventTarget(self, name), name, self.delegates[name]);
  25940. delete self.delegates[name];
  25941. }
  25942. },
  25943. unbindAllNativeEvents: function () {
  25944. var self = this;
  25945. var body = self.getBody();
  25946. var dom = self.dom;
  25947. var name;
  25948. if (self.delegates) {
  25949. for (name in self.delegates) {
  25950. self.dom.unbind(getEventTarget(self, name), name, self.delegates[name]);
  25951. }
  25952. delete self.delegates;
  25953. }
  25954. if (!self.inline && body && dom) {
  25955. body.onload = null;
  25956. dom.unbind(self.getWin());
  25957. dom.unbind(self.getDoc());
  25958. }
  25959. if (dom) {
  25960. dom.unbind(body);
  25961. dom.unbind(self.getContainer());
  25962. }
  25963. }
  25964. });
  25965. var each$h = Tools.each, explode$3 = Tools.explode;
  25966. var keyCodeLookup = {
  25967. f1: 112,
  25968. f2: 113,
  25969. f3: 114,
  25970. f4: 115,
  25971. f5: 116,
  25972. f6: 117,
  25973. f7: 118,
  25974. f8: 119,
  25975. f9: 120,
  25976. f10: 121,
  25977. f11: 122,
  25978. f12: 123
  25979. };
  25980. var modifierNames = Tools.makeMap('alt,ctrl,shift,meta,access');
  25981. var Shortcuts = function () {
  25982. function Shortcuts(editor) {
  25983. this.shortcuts = {};
  25984. this.pendingPatterns = [];
  25985. this.editor = editor;
  25986. var self = this;
  25987. editor.on('keyup keypress keydown', function (e) {
  25988. if ((self.hasModifier(e) || self.isFunctionKey(e)) && !e.isDefaultPrevented()) {
  25989. each$h(self.shortcuts, function (shortcut) {
  25990. if (self.matchShortcut(e, shortcut)) {
  25991. self.pendingPatterns = shortcut.subpatterns.slice(0);
  25992. if (e.type === 'keydown') {
  25993. self.executeShortcutAction(shortcut);
  25994. }
  25995. return true;
  25996. }
  25997. });
  25998. if (self.matchShortcut(e, self.pendingPatterns[0])) {
  25999. if (self.pendingPatterns.length === 1) {
  26000. if (e.type === 'keydown') {
  26001. self.executeShortcutAction(self.pendingPatterns[0]);
  26002. }
  26003. }
  26004. self.pendingPatterns.shift();
  26005. }
  26006. }
  26007. });
  26008. }
  26009. Shortcuts.prototype.add = function (pattern, desc, cmdFunc, scope) {
  26010. var self = this;
  26011. var cmd;
  26012. cmd = cmdFunc;
  26013. if (typeof cmdFunc === 'string') {
  26014. cmdFunc = function () {
  26015. self.editor.execCommand(cmd, false, null);
  26016. };
  26017. } else if (Tools.isArray(cmd)) {
  26018. cmdFunc = function () {
  26019. self.editor.execCommand(cmd[0], cmd[1], cmd[2]);
  26020. };
  26021. }
  26022. each$h(explode$3(Tools.trim(pattern)), function (pattern) {
  26023. var shortcut = self.createShortcut(pattern, desc, cmdFunc, scope);
  26024. self.shortcuts[shortcut.id] = shortcut;
  26025. });
  26026. return true;
  26027. };
  26028. Shortcuts.prototype.remove = function (pattern) {
  26029. var shortcut = this.createShortcut(pattern);
  26030. if (this.shortcuts[shortcut.id]) {
  26031. delete this.shortcuts[shortcut.id];
  26032. return true;
  26033. }
  26034. return false;
  26035. };
  26036. Shortcuts.prototype.parseShortcut = function (pattern) {
  26037. var id, key;
  26038. var shortcut = {};
  26039. each$h(explode$3(pattern.toLowerCase(), '+'), function (value) {
  26040. if (value in modifierNames) {
  26041. shortcut[value] = true;
  26042. } else {
  26043. if (/^[0-9]{2,}$/.test(value)) {
  26044. shortcut.keyCode = parseInt(value, 10);
  26045. } else {
  26046. shortcut.charCode = value.charCodeAt(0);
  26047. shortcut.keyCode = keyCodeLookup[value] || value.toUpperCase().charCodeAt(0);
  26048. }
  26049. }
  26050. });
  26051. id = [shortcut.keyCode];
  26052. for (key in modifierNames) {
  26053. if (shortcut[key]) {
  26054. id.push(key);
  26055. } else {
  26056. shortcut[key] = false;
  26057. }
  26058. }
  26059. shortcut.id = id.join(',');
  26060. if (shortcut.access) {
  26061. shortcut.alt = true;
  26062. if (Env.mac) {
  26063. shortcut.ctrl = true;
  26064. } else {
  26065. shortcut.shift = true;
  26066. }
  26067. }
  26068. if (shortcut.meta) {
  26069. if (Env.mac) {
  26070. shortcut.meta = true;
  26071. } else {
  26072. shortcut.ctrl = true;
  26073. shortcut.meta = false;
  26074. }
  26075. }
  26076. return shortcut;
  26077. };
  26078. Shortcuts.prototype.createShortcut = function (pattern, desc, cmdFunc, scope) {
  26079. var shortcuts;
  26080. shortcuts = Tools.map(explode$3(pattern, '>'), this.parseShortcut);
  26081. shortcuts[shortcuts.length - 1] = Tools.extend(shortcuts[shortcuts.length - 1], {
  26082. func: cmdFunc,
  26083. scope: scope || this.editor
  26084. });
  26085. return Tools.extend(shortcuts[0], {
  26086. desc: this.editor.translate(desc),
  26087. subpatterns: shortcuts.slice(1)
  26088. });
  26089. };
  26090. Shortcuts.prototype.hasModifier = function (e) {
  26091. return e.altKey || e.ctrlKey || e.metaKey;
  26092. };
  26093. Shortcuts.prototype.isFunctionKey = function (e) {
  26094. return e.type === 'keydown' && e.keyCode >= 112 && e.keyCode <= 123;
  26095. };
  26096. Shortcuts.prototype.matchShortcut = function (e, shortcut) {
  26097. if (!shortcut) {
  26098. return false;
  26099. }
  26100. if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) {
  26101. return false;
  26102. }
  26103. if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) {
  26104. return false;
  26105. }
  26106. if (e.keyCode === shortcut.keyCode || e.charCode && e.charCode === shortcut.charCode) {
  26107. e.preventDefault();
  26108. return true;
  26109. }
  26110. return false;
  26111. };
  26112. Shortcuts.prototype.executeShortcutAction = function (shortcut) {
  26113. return shortcut.func ? shortcut.func.call(shortcut.scope) : null;
  26114. };
  26115. return Shortcuts;
  26116. }();
  26117. var each$i = Tools.each, trim$4 = Tools.trim;
  26118. var queryParts = 'source protocol authority userInfo user password host port relative path directory file query anchor'.split(' ');
  26119. var DEFAULT_PORTS = {
  26120. ftp: 21,
  26121. http: 80,
  26122. https: 443,
  26123. mailto: 25
  26124. };
  26125. var URI = function () {
  26126. function URI(url, settings) {
  26127. url = trim$4(url);
  26128. this.settings = settings || {};
  26129. var baseUri = this.settings.base_uri;
  26130. var self = this;
  26131. if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
  26132. self.source = url;
  26133. return;
  26134. }
  26135. var isProtocolRelative = url.indexOf('//') === 0;
  26136. if (url.indexOf('/') === 0 && !isProtocolRelative) {
  26137. url = (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url;
  26138. }
  26139. if (!/^[\w\-]*:?\/\//.test(url)) {
  26140. var baseUrl = this.settings.base_uri ? this.settings.base_uri.path : new URI(domGlobals.document.location.href).directory;
  26141. if (this.settings.base_uri && this.settings.base_uri.protocol == '') {
  26142. url = '//mce_host' + self.toAbsPath(baseUrl, url);
  26143. } else {
  26144. var match = /([^#?]*)([#?]?.*)/.exec(url);
  26145. url = (baseUri && baseUri.protocol || 'http') + '://mce_host' + self.toAbsPath(baseUrl, match[1]) + match[2];
  26146. }
  26147. }
  26148. url = url.replace(/@@/g, '(mce_at)');
  26149. var urlMatch = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
  26150. each$i(queryParts, function (v, i) {
  26151. var part = urlMatch[i];
  26152. if (part) {
  26153. part = part.replace(/\(mce_at\)/g, '@@');
  26154. }
  26155. self[v] = part;
  26156. });
  26157. if (baseUri) {
  26158. if (!self.protocol) {
  26159. self.protocol = baseUri.protocol;
  26160. }
  26161. if (!self.userInfo) {
  26162. self.userInfo = baseUri.userInfo;
  26163. }
  26164. if (!self.port && self.host === 'mce_host') {
  26165. self.port = baseUri.port;
  26166. }
  26167. if (!self.host || self.host === 'mce_host') {
  26168. self.host = baseUri.host;
  26169. }
  26170. self.source = '';
  26171. }
  26172. if (isProtocolRelative) {
  26173. self.protocol = '';
  26174. }
  26175. }
  26176. URI.parseDataUri = function (uri) {
  26177. var type;
  26178. var uriComponents = decodeURIComponent(uri).split(',');
  26179. var matches = /data:([^;]+)/.exec(uriComponents[0]);
  26180. if (matches) {
  26181. type = matches[1];
  26182. }
  26183. return {
  26184. type: type,
  26185. data: uriComponents[1]
  26186. };
  26187. };
  26188. URI.getDocumentBaseUrl = function (loc) {
  26189. var baseUrl;
  26190. if (loc.protocol.indexOf('http') !== 0 && loc.protocol !== 'file:') {
  26191. baseUrl = loc.href;
  26192. } else {
  26193. baseUrl = loc.protocol + '//' + loc.host + loc.pathname;
  26194. }
  26195. if (/^[^:]+:\/\/\/?[^\/]+\//.test(baseUrl)) {
  26196. baseUrl = baseUrl.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  26197. if (!/[\/\\]$/.test(baseUrl)) {
  26198. baseUrl += '/';
  26199. }
  26200. }
  26201. return baseUrl;
  26202. };
  26203. URI.prototype.setPath = function (path) {
  26204. var pathMatch = /^(.*?)\/?(\w+)?$/.exec(path);
  26205. this.path = pathMatch[0];
  26206. this.directory = pathMatch[1];
  26207. this.file = pathMatch[2];
  26208. this.source = '';
  26209. this.getURI();
  26210. };
  26211. URI.prototype.toRelative = function (uri) {
  26212. var output;
  26213. if (uri === './') {
  26214. return uri;
  26215. }
  26216. var relativeUri = new URI(uri, { base_uri: this });
  26217. if (relativeUri.host !== 'mce_host' && this.host !== relativeUri.host && relativeUri.host || this.port !== relativeUri.port || this.protocol !== relativeUri.protocol && relativeUri.protocol !== '') {
  26218. return relativeUri.getURI();
  26219. }
  26220. var tu = this.getURI(), uu = relativeUri.getURI();
  26221. if (tu === uu || tu.charAt(tu.length - 1) === '/' && tu.substr(0, tu.length - 1) === uu) {
  26222. return tu;
  26223. }
  26224. output = this.toRelPath(this.path, relativeUri.path);
  26225. if (relativeUri.query) {
  26226. output += '?' + relativeUri.query;
  26227. }
  26228. if (relativeUri.anchor) {
  26229. output += '#' + relativeUri.anchor;
  26230. }
  26231. return output;
  26232. };
  26233. URI.prototype.toAbsolute = function (uri, noHost) {
  26234. var absoluteUri = new URI(uri, { base_uri: this });
  26235. return absoluteUri.getURI(noHost && this.isSameOrigin(absoluteUri));
  26236. };
  26237. URI.prototype.isSameOrigin = function (uri) {
  26238. if (this.host == uri.host && this.protocol == uri.protocol) {
  26239. if (this.port == uri.port) {
  26240. return true;
  26241. }
  26242. var defaultPort = DEFAULT_PORTS[this.protocol];
  26243. if (defaultPort && (this.port || defaultPort) == (uri.port || defaultPort)) {
  26244. return true;
  26245. }
  26246. }
  26247. return false;
  26248. };
  26249. URI.prototype.toRelPath = function (base, path) {
  26250. var items, breakPoint = 0, out = '', i, l;
  26251. var normalizedBase = base.substring(0, base.lastIndexOf('/')).split('/');
  26252. items = path.split('/');
  26253. if (normalizedBase.length >= items.length) {
  26254. for (i = 0, l = normalizedBase.length; i < l; i++) {
  26255. if (i >= items.length || normalizedBase[i] !== items[i]) {
  26256. breakPoint = i + 1;
  26257. break;
  26258. }
  26259. }
  26260. }
  26261. if (normalizedBase.length < items.length) {
  26262. for (i = 0, l = items.length; i < l; i++) {
  26263. if (i >= normalizedBase.length || normalizedBase[i] !== items[i]) {
  26264. breakPoint = i + 1;
  26265. break;
  26266. }
  26267. }
  26268. }
  26269. if (breakPoint === 1) {
  26270. return path;
  26271. }
  26272. for (i = 0, l = normalizedBase.length - (breakPoint - 1); i < l; i++) {
  26273. out += '../';
  26274. }
  26275. for (i = breakPoint - 1, l = items.length; i < l; i++) {
  26276. if (i !== breakPoint - 1) {
  26277. out += '/' + items[i];
  26278. } else {
  26279. out += items[i];
  26280. }
  26281. }
  26282. return out;
  26283. };
  26284. URI.prototype.toAbsPath = function (base, path) {
  26285. var i, nb = 0, o = [], tr, outPath;
  26286. tr = /\/$/.test(path) ? '/' : '';
  26287. var normalizedBase = base.split('/');
  26288. var normalizedPath = path.split('/');
  26289. each$i(normalizedBase, function (k) {
  26290. if (k) {
  26291. o.push(k);
  26292. }
  26293. });
  26294. normalizedBase = o;
  26295. for (i = normalizedPath.length - 1, o = []; i >= 0; i--) {
  26296. if (normalizedPath[i].length === 0 || normalizedPath[i] === '.') {
  26297. continue;
  26298. }
  26299. if (normalizedPath[i] === '..') {
  26300. nb++;
  26301. continue;
  26302. }
  26303. if (nb > 0) {
  26304. nb--;
  26305. continue;
  26306. }
  26307. o.push(normalizedPath[i]);
  26308. }
  26309. i = normalizedBase.length - nb;
  26310. if (i <= 0) {
  26311. outPath = o.reverse().join('/');
  26312. } else {
  26313. outPath = normalizedBase.slice(0, i).join('/') + '/' + o.reverse().join('/');
  26314. }
  26315. if (outPath.indexOf('/') !== 0) {
  26316. outPath = '/' + outPath;
  26317. }
  26318. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) {
  26319. outPath += tr;
  26320. }
  26321. return outPath;
  26322. };
  26323. URI.prototype.getURI = function (noProtoHost) {
  26324. if (noProtoHost === void 0) {
  26325. noProtoHost = false;
  26326. }
  26327. var s;
  26328. if (!this.source || noProtoHost) {
  26329. s = '';
  26330. if (!noProtoHost) {
  26331. if (this.protocol) {
  26332. s += this.protocol + '://';
  26333. } else {
  26334. s += '//';
  26335. }
  26336. if (this.userInfo) {
  26337. s += this.userInfo + '@';
  26338. }
  26339. if (this.host) {
  26340. s += this.host;
  26341. }
  26342. if (this.port) {
  26343. s += ':' + this.port;
  26344. }
  26345. }
  26346. if (this.path) {
  26347. s += this.path;
  26348. }
  26349. if (this.query) {
  26350. s += '?' + this.query;
  26351. }
  26352. if (this.anchor) {
  26353. s += '#' + this.anchor;
  26354. }
  26355. this.source = s;
  26356. }
  26357. return this.source;
  26358. };
  26359. return URI;
  26360. }();
  26361. var create$5 = function () {
  26362. var buttons = {};
  26363. var menuItems = {};
  26364. var popups = {};
  26365. var icons = {};
  26366. var contextMenus = {};
  26367. var contextToolbars = {};
  26368. var sidebars = {};
  26369. var add = function (collection, type) {
  26370. return function (name, spec) {
  26371. return collection[name.toLowerCase()] = __assign(__assign({}, spec), { type: type });
  26372. };
  26373. };
  26374. var addIcon = function (name, svgData) {
  26375. return icons[name.toLowerCase()] = svgData;
  26376. };
  26377. return {
  26378. addButton: add(buttons, 'button'),
  26379. addToggleButton: add(buttons, 'togglebutton'),
  26380. addMenuButton: add(buttons, 'menubutton'),
  26381. addSplitButton: add(buttons, 'splitbutton'),
  26382. addMenuItem: add(menuItems, 'menuitem'),
  26383. addNestedMenuItem: add(menuItems, 'nestedmenuitem'),
  26384. addToggleMenuItem: add(menuItems, 'togglemenuitem'),
  26385. addAutocompleter: add(popups, 'autocompleter'),
  26386. addContextMenu: add(contextMenus, 'contextmenu'),
  26387. addContextToolbar: add(contextToolbars, 'contexttoolbar'),
  26388. addContextForm: add(contextToolbars, 'contextform'),
  26389. addSidebar: add(sidebars, 'sidebar'),
  26390. addIcon: addIcon,
  26391. getAll: function () {
  26392. return {
  26393. buttons: buttons,
  26394. menuItems: menuItems,
  26395. icons: icons,
  26396. popups: popups,
  26397. contextMenus: contextMenus,
  26398. contextToolbars: contextToolbars,
  26399. sidebars: sidebars
  26400. };
  26401. }
  26402. };
  26403. };
  26404. var registry = function () {
  26405. var bridge = create$5();
  26406. return {
  26407. addAutocompleter: bridge.addAutocompleter,
  26408. addButton: bridge.addButton,
  26409. addContextForm: bridge.addContextForm,
  26410. addContextMenu: bridge.addContextMenu,
  26411. addContextToolbar: bridge.addContextToolbar,
  26412. addIcon: bridge.addIcon,
  26413. addMenuButton: bridge.addMenuButton,
  26414. addMenuItem: bridge.addMenuItem,
  26415. addNestedMenuItem: bridge.addNestedMenuItem,
  26416. addSidebar: bridge.addSidebar,
  26417. addSplitButton: bridge.addSplitButton,
  26418. addToggleButton: bridge.addToggleButton,
  26419. addToggleMenuItem: bridge.addToggleMenuItem,
  26420. getAll: bridge.getAll
  26421. };
  26422. };
  26423. var DOM$8 = DOMUtils$1.DOM;
  26424. var extend$3 = Tools.extend, each$j = Tools.each;
  26425. var resolve$3 = Tools.resolve;
  26426. var ie$1 = Env.ie;
  26427. var Editor = function () {
  26428. function Editor(id, settings, editorManager) {
  26429. var _this = this;
  26430. this.plugins = {};
  26431. this.contentCSS = [];
  26432. this.contentStyles = [];
  26433. this.loadedCSS = {};
  26434. this.isNotDirty = false;
  26435. this.editorManager = editorManager;
  26436. this.documentBaseUrl = editorManager.documentBaseURL;
  26437. extend$3(this, EditorObservable);
  26438. this.settings = getEditorSettings(this, id, this.documentBaseUrl, editorManager.defaultSettings, settings);
  26439. if (this.settings.suffix) {
  26440. editorManager.suffix = this.settings.suffix;
  26441. }
  26442. this.suffix = editorManager.suffix;
  26443. if (this.settings.base_url) {
  26444. editorManager._setBaseUrl(this.settings.base_url);
  26445. }
  26446. this.baseUri = editorManager.baseURI;
  26447. if (this.settings.referrer_policy) {
  26448. ScriptLoader.ScriptLoader._setReferrerPolicy(this.settings.referrer_policy);
  26449. DOMUtils$1.DOM.styleSheetLoader._setReferrerPolicy(this.settings.referrer_policy);
  26450. }
  26451. AddOnManager$1.languageLoad = this.settings.language_load;
  26452. AddOnManager$1.baseURL = editorManager.baseURL;
  26453. this.id = id;
  26454. this.setDirty(false);
  26455. this.documentBaseURI = new URI(this.settings.document_base_url, { base_uri: this.baseUri });
  26456. this.baseURI = this.baseUri;
  26457. this.inline = !!this.settings.inline;
  26458. this.shortcuts = new Shortcuts(this);
  26459. this.editorCommands = new EditorCommands(this);
  26460. if (this.settings.cache_suffix) {
  26461. Env.cacheSuffix = this.settings.cache_suffix.replace(/^[\?\&]+/, '');
  26462. }
  26463. this.ui = { registry: registry() };
  26464. var self = this;
  26465. var modeInstance = create$4(self);
  26466. this.mode = modeInstance;
  26467. this.setMode = modeInstance.set;
  26468. editorManager.fire('SetupEditor', { editor: this });
  26469. this.execCallback('setup', this);
  26470. this.$ = DomQuery.overrideDefaults(function () {
  26471. return {
  26472. context: _this.inline ? _this.getBody() : _this.getDoc(),
  26473. element: _this.getBody()
  26474. };
  26475. });
  26476. }
  26477. Editor.prototype.render = function () {
  26478. Render.render(this);
  26479. };
  26480. Editor.prototype.focus = function (skipFocus) {
  26481. EditorFocus.focus(this, skipFocus);
  26482. };
  26483. Editor.prototype.hasFocus = function () {
  26484. return EditorFocus.hasFocus(this);
  26485. };
  26486. Editor.prototype.execCallback = function (name) {
  26487. var x = [];
  26488. for (var _i = 1; _i < arguments.length; _i++) {
  26489. x[_i - 1] = arguments[_i];
  26490. }
  26491. var self = this;
  26492. var callback = self.settings[name], scope;
  26493. if (!callback) {
  26494. return;
  26495. }
  26496. if (self.callbackLookup && (scope = self.callbackLookup[name])) {
  26497. callback = scope.func;
  26498. scope = scope.scope;
  26499. }
  26500. if (typeof callback === 'string') {
  26501. scope = callback.replace(/\.\w+$/, '');
  26502. scope = scope ? resolve$3(scope) : 0;
  26503. callback = resolve$3(callback);
  26504. self.callbackLookup = self.callbackLookup || {};
  26505. self.callbackLookup[name] = {
  26506. func: callback,
  26507. scope: scope
  26508. };
  26509. }
  26510. return callback.apply(scope || self, Array.prototype.slice.call(arguments, 1));
  26511. };
  26512. Editor.prototype.translate = function (text) {
  26513. return I18n.translate(text);
  26514. };
  26515. Editor.prototype.getParam = function (name, defaultVal, type) {
  26516. return getParam(this, name, defaultVal, type);
  26517. };
  26518. Editor.prototype.nodeChanged = function (args) {
  26519. this._nodeChangeDispatcher.nodeChanged(args);
  26520. };
  26521. Editor.prototype.addCommand = function (name, callback, scope) {
  26522. this.editorCommands.addCommand(name, callback, scope);
  26523. };
  26524. Editor.prototype.addQueryStateHandler = function (name, callback, scope) {
  26525. this.editorCommands.addQueryStateHandler(name, callback, scope);
  26526. };
  26527. Editor.prototype.addQueryValueHandler = function (name, callback, scope) {
  26528. this.editorCommands.addQueryValueHandler(name, callback, scope);
  26529. };
  26530. Editor.prototype.addShortcut = function (pattern, desc, cmdFunc, scope) {
  26531. this.shortcuts.add(pattern, desc, cmdFunc, scope);
  26532. };
  26533. Editor.prototype.execCommand = function (cmd, ui, value, args) {
  26534. return this.editorCommands.execCommand(cmd, ui, value, args);
  26535. };
  26536. Editor.prototype.queryCommandState = function (cmd) {
  26537. return this.editorCommands.queryCommandState(cmd);
  26538. };
  26539. Editor.prototype.queryCommandValue = function (cmd) {
  26540. return this.editorCommands.queryCommandValue(cmd);
  26541. };
  26542. Editor.prototype.queryCommandSupported = function (cmd) {
  26543. return this.editorCommands.queryCommandSupported(cmd);
  26544. };
  26545. Editor.prototype.show = function () {
  26546. var self = this;
  26547. if (self.hidden) {
  26548. self.hidden = false;
  26549. if (self.inline) {
  26550. self.getBody().contentEditable = 'true';
  26551. } else {
  26552. DOM$8.show(self.getContainer());
  26553. DOM$8.hide(self.id);
  26554. }
  26555. self.load();
  26556. self.fire('show');
  26557. }
  26558. };
  26559. Editor.prototype.hide = function () {
  26560. var self = this, doc = self.getDoc();
  26561. if (!self.hidden) {
  26562. if (ie$1 && doc && !self.inline) {
  26563. doc.execCommand('SelectAll');
  26564. }
  26565. self.save();
  26566. if (self.inline) {
  26567. self.getBody().contentEditable = 'false';
  26568. if (self === self.editorManager.focusedEditor) {
  26569. self.editorManager.focusedEditor = null;
  26570. }
  26571. } else {
  26572. DOM$8.hide(self.getContainer());
  26573. DOM$8.setStyle(self.id, 'display', self.orgDisplay);
  26574. }
  26575. self.hidden = true;
  26576. self.fire('hide');
  26577. }
  26578. };
  26579. Editor.prototype.isHidden = function () {
  26580. return !!this.hidden;
  26581. };
  26582. Editor.prototype.setProgressState = function (state, time) {
  26583. this.fire('ProgressState', {
  26584. state: state,
  26585. time: time
  26586. });
  26587. };
  26588. Editor.prototype.load = function (args) {
  26589. var self = this;
  26590. var elm = self.getElement(), html;
  26591. if (self.removed) {
  26592. return '';
  26593. }
  26594. if (elm) {
  26595. args = args || {};
  26596. args.load = true;
  26597. var value = NodeType.isTextareaOrInput(elm) ? elm.value : elm.innerHTML;
  26598. html = self.setContent(value, args);
  26599. args.element = elm;
  26600. if (!args.no_events) {
  26601. self.fire('LoadContent', args);
  26602. }
  26603. args.element = elm = null;
  26604. return html;
  26605. }
  26606. };
  26607. Editor.prototype.save = function (args) {
  26608. var self = this;
  26609. var elm = self.getElement(), html, form;
  26610. if (!elm || !self.initialized || self.removed) {
  26611. return;
  26612. }
  26613. args = args || {};
  26614. args.save = true;
  26615. args.element = elm;
  26616. html = args.content = self.getContent(args);
  26617. if (!args.no_events) {
  26618. self.fire('SaveContent', args);
  26619. }
  26620. if (args.format === 'raw') {
  26621. self.fire('RawSaveContent', args);
  26622. }
  26623. html = args.content;
  26624. if (!NodeType.isTextareaOrInput(elm)) {
  26625. if (args.is_removing || !self.inline) {
  26626. elm.innerHTML = html;
  26627. }
  26628. if (form = DOM$8.getParent(self.id, 'form')) {
  26629. each$j(form.elements, function (elm) {
  26630. if (elm.name === self.id) {
  26631. elm.value = html;
  26632. return false;
  26633. }
  26634. });
  26635. }
  26636. } else {
  26637. elm.value = html;
  26638. }
  26639. args.element = elm = null;
  26640. if (args.set_dirty !== false) {
  26641. self.setDirty(false);
  26642. }
  26643. return html;
  26644. };
  26645. Editor.prototype.setContent = function (content, args) {
  26646. return setContent(this, content, args);
  26647. };
  26648. Editor.prototype.getContent = function (args) {
  26649. return getContent(this, args);
  26650. };
  26651. Editor.prototype.insertContent = function (content, args) {
  26652. if (args) {
  26653. content = extend$3({ content: content }, args);
  26654. }
  26655. this.execCommand('mceInsertContent', false, content);
  26656. };
  26657. Editor.prototype.resetContent = function (initialContent) {
  26658. if (initialContent === undefined) {
  26659. setContent(this, this.startContent, { format: 'raw' });
  26660. } else {
  26661. setContent(this, initialContent);
  26662. }
  26663. this.undoManager.reset();
  26664. this.setDirty(false);
  26665. this.nodeChanged();
  26666. };
  26667. Editor.prototype.isDirty = function () {
  26668. return !this.isNotDirty;
  26669. };
  26670. Editor.prototype.setDirty = function (state) {
  26671. var oldState = !this.isNotDirty;
  26672. this.isNotDirty = !state;
  26673. if (state && state !== oldState) {
  26674. this.fire('dirty');
  26675. }
  26676. };
  26677. Editor.prototype.getContainer = function () {
  26678. var self = this;
  26679. if (!self.container) {
  26680. self.container = DOM$8.get(self.editorContainer || self.id + '_parent');
  26681. }
  26682. return self.container;
  26683. };
  26684. Editor.prototype.getContentAreaContainer = function () {
  26685. return this.contentAreaContainer;
  26686. };
  26687. Editor.prototype.getElement = function () {
  26688. if (!this.targetElm) {
  26689. this.targetElm = DOM$8.get(this.id);
  26690. }
  26691. return this.targetElm;
  26692. };
  26693. Editor.prototype.getWin = function () {
  26694. var self = this;
  26695. var elm;
  26696. if (!self.contentWindow) {
  26697. elm = self.iframeElement;
  26698. if (elm) {
  26699. self.contentWindow = elm.contentWindow;
  26700. }
  26701. }
  26702. return self.contentWindow;
  26703. };
  26704. Editor.prototype.getDoc = function () {
  26705. var self = this;
  26706. var win;
  26707. if (!self.contentDocument) {
  26708. win = self.getWin();
  26709. if (win) {
  26710. self.contentDocument = win.document;
  26711. }
  26712. }
  26713. return self.contentDocument;
  26714. };
  26715. Editor.prototype.getBody = function () {
  26716. var doc = this.getDoc();
  26717. return this.bodyElement || (doc ? doc.body : null);
  26718. };
  26719. Editor.prototype.convertURL = function (url, name, elm) {
  26720. var self = this, settings = self.settings;
  26721. if (settings.urlconverter_callback) {
  26722. return self.execCallback('urlconverter_callback', url, elm, true, name);
  26723. }
  26724. if (!settings.convert_urls || elm && elm.nodeName === 'LINK' || url.indexOf('file:') === 0 || url.length === 0) {
  26725. return url;
  26726. }
  26727. if (settings.relative_urls) {
  26728. return self.documentBaseURI.toRelative(url);
  26729. }
  26730. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  26731. return url;
  26732. };
  26733. Editor.prototype.addVisual = function (elm) {
  26734. var self = this;
  26735. var settings = self.settings;
  26736. var dom = self.dom;
  26737. var cls;
  26738. elm = elm || self.getBody();
  26739. if (self.hasVisual === undefined) {
  26740. self.hasVisual = settings.visual;
  26741. }
  26742. each$j(dom.select('table,a', elm), function (elm) {
  26743. var value;
  26744. switch (elm.nodeName) {
  26745. case 'TABLE':
  26746. cls = settings.visual_table_class || 'mce-item-table';
  26747. value = dom.getAttrib(elm, 'border');
  26748. if ((!value || value === '0') && self.hasVisual) {
  26749. dom.addClass(elm, cls);
  26750. } else {
  26751. dom.removeClass(elm, cls);
  26752. }
  26753. return;
  26754. case 'A':
  26755. if (!dom.getAttrib(elm, 'href')) {
  26756. value = dom.getAttrib(elm, 'name') || elm.id;
  26757. cls = settings.visual_anchor_class || 'mce-item-anchor';
  26758. if (value && self.hasVisual) {
  26759. dom.addClass(elm, cls);
  26760. } else {
  26761. dom.removeClass(elm, cls);
  26762. }
  26763. }
  26764. return;
  26765. }
  26766. });
  26767. self.fire('VisualAid', {
  26768. element: elm,
  26769. hasVisual: self.hasVisual
  26770. });
  26771. };
  26772. Editor.prototype.remove = function () {
  26773. remove$6(this);
  26774. };
  26775. Editor.prototype.destroy = function (automatic) {
  26776. destroy(this, automatic);
  26777. };
  26778. Editor.prototype.uploadImages = function (callback) {
  26779. return this.editorUpload.uploadImages(callback);
  26780. };
  26781. Editor.prototype._scanForImages = function () {
  26782. return this.editorUpload.scanForImages();
  26783. };
  26784. Editor.prototype.addButton = function () {
  26785. 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');
  26786. };
  26787. Editor.prototype.addSidebar = function () {
  26788. throw new Error('editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead');
  26789. };
  26790. Editor.prototype.addMenuItem = function () {
  26791. throw new Error('editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead');
  26792. };
  26793. Editor.prototype.addContextToolbar = function () {
  26794. throw new Error('editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead');
  26795. };
  26796. return Editor;
  26797. }();
  26798. var DOM$9 = DOMUtils$1.DOM;
  26799. var explode$4 = Tools.explode, each$k = Tools.each, extend$4 = Tools.extend;
  26800. var instanceCounter = 0, boundGlobalEvents = false;
  26801. var beforeUnloadDelegate;
  26802. var legacyEditors = [];
  26803. var editors = [];
  26804. var isValidLegacyKey = function (id) {
  26805. return id !== 'length';
  26806. };
  26807. var globalEventDelegate = function (e) {
  26808. var type = e.type;
  26809. each$k(EditorManager.get(), function (editor) {
  26810. switch (type) {
  26811. case 'scroll':
  26812. editor.fire('ScrollWindow', e);
  26813. break;
  26814. case 'resize':
  26815. editor.fire('ResizeWindow', e);
  26816. break;
  26817. }
  26818. });
  26819. };
  26820. var toggleGlobalEvents = function (state) {
  26821. if (state !== boundGlobalEvents) {
  26822. if (state) {
  26823. DomQuery(window).on('resize scroll', globalEventDelegate);
  26824. } else {
  26825. DomQuery(window).off('resize scroll', globalEventDelegate);
  26826. }
  26827. boundGlobalEvents = state;
  26828. }
  26829. };
  26830. var removeEditorFromList = function (targetEditor) {
  26831. var oldEditors = editors;
  26832. delete legacyEditors[targetEditor.id];
  26833. for (var i = 0; i < legacyEditors.length; i++) {
  26834. if (legacyEditors[i] === targetEditor) {
  26835. legacyEditors.splice(i, 1);
  26836. break;
  26837. }
  26838. }
  26839. editors = filter(editors, function (editor) {
  26840. return targetEditor !== editor;
  26841. });
  26842. if (EditorManager.activeEditor === targetEditor) {
  26843. EditorManager.activeEditor = editors.length > 0 ? editors[0] : null;
  26844. }
  26845. if (EditorManager.focusedEditor === targetEditor) {
  26846. EditorManager.focusedEditor = null;
  26847. }
  26848. return oldEditors.length !== editors.length;
  26849. };
  26850. var purgeDestroyedEditor = function (editor) {
  26851. if (editor && editor.initialized && !(editor.getContainer() || editor.getBody()).parentNode) {
  26852. removeEditorFromList(editor);
  26853. editor.unbindAllNativeEvents();
  26854. editor.destroy(true);
  26855. editor.removed = true;
  26856. editor = null;
  26857. }
  26858. return editor;
  26859. };
  26860. var isQuirksMode = domGlobals.document.compatMode !== 'CSS1Compat';
  26861. var EditorManager = __assign(__assign({}, Observable), {
  26862. baseURI: null,
  26863. baseURL: null,
  26864. defaultSettings: {},
  26865. documentBaseURL: null,
  26866. suffix: null,
  26867. $: DomQuery,
  26868. majorVersion: '5',
  26869. minorVersion: '1.5',
  26870. releaseDate: '2019-12-19',
  26871. editors: legacyEditors,
  26872. i18n: I18n,
  26873. activeEditor: null,
  26874. focusedEditor: null,
  26875. settings: {},
  26876. setup: function () {
  26877. var self = this;
  26878. var baseURL, documentBaseURL, suffix = '';
  26879. documentBaseURL = URI.getDocumentBaseUrl(domGlobals.document.location);
  26880. if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) {
  26881. documentBaseURL = documentBaseURL.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  26882. if (!/[\/\\]$/.test(documentBaseURL)) {
  26883. documentBaseURL += '/';
  26884. }
  26885. }
  26886. var preInit = window.tinymce || window.tinyMCEPreInit;
  26887. if (preInit) {
  26888. baseURL = preInit.base || preInit.baseURL;
  26889. suffix = preInit.suffix;
  26890. } else {
  26891. var scripts = domGlobals.document.getElementsByTagName('script');
  26892. for (var i = 0; i < scripts.length; i++) {
  26893. var src = scripts[i].src || '';
  26894. if (src === '') {
  26895. continue;
  26896. }
  26897. var srcScript = src.substring(src.lastIndexOf('/'));
  26898. if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
  26899. if (srcScript.indexOf('.min') !== -1) {
  26900. suffix = '.min';
  26901. }
  26902. baseURL = src.substring(0, src.lastIndexOf('/'));
  26903. break;
  26904. }
  26905. }
  26906. if (!baseURL && domGlobals.document.currentScript) {
  26907. var src = domGlobals.document.currentScript.src;
  26908. if (src.indexOf('.min') !== -1) {
  26909. suffix = '.min';
  26910. }
  26911. baseURL = src.substring(0, src.lastIndexOf('/'));
  26912. }
  26913. }
  26914. self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL);
  26915. self.documentBaseURL = documentBaseURL;
  26916. self.baseURI = new URI(self.baseURL);
  26917. self.suffix = suffix;
  26918. FocusController.setup(self);
  26919. },
  26920. overrideDefaults: function (defaultSettings) {
  26921. var baseUrl, suffix;
  26922. baseUrl = defaultSettings.base_url;
  26923. if (baseUrl) {
  26924. this._setBaseUrl(baseUrl);
  26925. }
  26926. suffix = defaultSettings.suffix;
  26927. if (defaultSettings.suffix) {
  26928. this.suffix = suffix;
  26929. }
  26930. this.defaultSettings = defaultSettings;
  26931. var pluginBaseUrls = defaultSettings.plugin_base_urls;
  26932. for (var name in pluginBaseUrls) {
  26933. AddOnManager$1.PluginManager.urls[name] = pluginBaseUrls[name];
  26934. }
  26935. },
  26936. init: function (settings) {
  26937. var self = this;
  26938. var result, invalidInlineTargets;
  26939. 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', ' ');
  26940. var isInvalidInlineTarget = function (settings, elm) {
  26941. return settings.inline && elm.tagName.toLowerCase() in invalidInlineTargets;
  26942. };
  26943. var createId = function (elm) {
  26944. var id = elm.id;
  26945. if (!id) {
  26946. id = elm.name;
  26947. if (id && !DOM$9.get(id)) {
  26948. id = elm.name;
  26949. } else {
  26950. id = DOM$9.uniqueId();
  26951. }
  26952. elm.setAttribute('id', id);
  26953. }
  26954. return id;
  26955. };
  26956. var execCallback = function (name) {
  26957. var callback = settings[name];
  26958. if (!callback) {
  26959. return;
  26960. }
  26961. return callback.apply(self, Array.prototype.slice.call(arguments, 2));
  26962. };
  26963. var hasClass = function (elm, className) {
  26964. return className.constructor === RegExp ? className.test(elm.className) : DOM$9.hasClass(elm, className);
  26965. };
  26966. var findTargets = function (settings) {
  26967. var l, targets = [];
  26968. if (Env.browser.isIE() && Env.browser.version.major < 11) {
  26969. ErrorReporter.initError('TinyMCE does not support the browser you are using. For a list of supported' + ' browsers please see: https://www.tinymce.com/docs/get-started/system-requirements/');
  26970. return [];
  26971. } else if (isQuirksMode) {
  26972. ErrorReporter.initError('Failed to initialize the editor as the document is not in standards mode. ' + 'TinyMCE requires standards mode.');
  26973. return [];
  26974. }
  26975. if (settings.types) {
  26976. each$k(settings.types, function (type) {
  26977. targets = targets.concat(DOM$9.select(type.selector));
  26978. });
  26979. return targets;
  26980. } else if (settings.selector) {
  26981. return DOM$9.select(settings.selector);
  26982. } else if (settings.target) {
  26983. return [settings.target];
  26984. }
  26985. switch (settings.mode) {
  26986. case 'exact':
  26987. l = settings.elements || '';
  26988. if (l.length > 0) {
  26989. each$k(explode$4(l), function (id) {
  26990. var elm;
  26991. if (elm = DOM$9.get(id)) {
  26992. targets.push(elm);
  26993. } else {
  26994. each$k(domGlobals.document.forms, function (f) {
  26995. each$k(f.elements, function (e) {
  26996. if (e.name === id) {
  26997. id = 'mce_editor_' + instanceCounter++;
  26998. DOM$9.setAttrib(e, 'id', id);
  26999. targets.push(e);
  27000. }
  27001. });
  27002. });
  27003. }
  27004. });
  27005. }
  27006. break;
  27007. case 'textareas':
  27008. case 'specific_textareas':
  27009. each$k(DOM$9.select('textarea'), function (elm) {
  27010. if (settings.editor_deselector && hasClass(elm, settings.editor_deselector)) {
  27011. return;
  27012. }
  27013. if (!settings.editor_selector || hasClass(elm, settings.editor_selector)) {
  27014. targets.push(elm);
  27015. }
  27016. });
  27017. break;
  27018. }
  27019. return targets;
  27020. };
  27021. var provideResults = function (editors) {
  27022. result = editors;
  27023. };
  27024. var initEditors = function () {
  27025. var initCount = 0;
  27026. var editors = [];
  27027. var targets;
  27028. var createEditor = function (id, settings, targetElm) {
  27029. var editor = new Editor(id, settings, self);
  27030. editors.push(editor);
  27031. editor.on('init', function () {
  27032. if (++initCount === targets.length) {
  27033. provideResults(editors);
  27034. }
  27035. });
  27036. editor.targetElm = editor.targetElm || targetElm;
  27037. editor.render();
  27038. };
  27039. DOM$9.unbind(window, 'ready', initEditors);
  27040. execCallback('onpageload');
  27041. targets = DomQuery.unique(findTargets(settings));
  27042. if (settings.types) {
  27043. each$k(settings.types, function (type) {
  27044. Tools.each(targets, function (elm) {
  27045. if (DOM$9.is(elm, type.selector)) {
  27046. createEditor(createId(elm), extend$4({}, settings, type), elm);
  27047. return false;
  27048. }
  27049. return true;
  27050. });
  27051. });
  27052. return;
  27053. }
  27054. Tools.each(targets, function (elm) {
  27055. purgeDestroyedEditor(self.get(elm.id));
  27056. });
  27057. targets = Tools.grep(targets, function (elm) {
  27058. return !self.get(elm.id);
  27059. });
  27060. if (targets.length === 0) {
  27061. provideResults([]);
  27062. } else {
  27063. each$k(targets, function (elm) {
  27064. if (isInvalidInlineTarget(settings, elm)) {
  27065. ErrorReporter.initError('Could not initialize inline editor on invalid inline target element', elm);
  27066. } else {
  27067. createEditor(createId(elm), settings, elm);
  27068. }
  27069. });
  27070. }
  27071. };
  27072. self.settings = settings;
  27073. DOM$9.bind(window, 'ready', initEditors);
  27074. return new promiseObj(function (resolve) {
  27075. if (result) {
  27076. resolve(result);
  27077. } else {
  27078. provideResults = function (editors) {
  27079. resolve(editors);
  27080. };
  27081. }
  27082. });
  27083. },
  27084. get: function (id) {
  27085. if (arguments.length === 0) {
  27086. return editors.slice(0);
  27087. } else if (isString(id)) {
  27088. return find(editors, function (editor) {
  27089. return editor.id === id;
  27090. }).getOr(null);
  27091. } else if (isNumber(id)) {
  27092. return editors[id] ? editors[id] : null;
  27093. } else {
  27094. return null;
  27095. }
  27096. },
  27097. add: function (editor) {
  27098. var self = this;
  27099. var existingEditor;
  27100. existingEditor = legacyEditors[editor.id];
  27101. if (existingEditor === editor) {
  27102. return editor;
  27103. }
  27104. if (self.get(editor.id) === null) {
  27105. if (isValidLegacyKey(editor.id)) {
  27106. legacyEditors[editor.id] = editor;
  27107. }
  27108. legacyEditors.push(editor);
  27109. editors.push(editor);
  27110. }
  27111. toggleGlobalEvents(true);
  27112. self.activeEditor = editor;
  27113. self.fire('AddEditor', { editor: editor });
  27114. if (!beforeUnloadDelegate) {
  27115. beforeUnloadDelegate = function (e) {
  27116. var event = self.fire('BeforeUnload');
  27117. if (event.returnValue) {
  27118. e.preventDefault();
  27119. e.returnValue = event.returnValue;
  27120. return event.returnValue;
  27121. }
  27122. };
  27123. window.addEventListener('beforeunload', beforeUnloadDelegate);
  27124. }
  27125. return editor;
  27126. },
  27127. createEditor: function (id, settings) {
  27128. return this.add(new Editor(id, settings, this));
  27129. },
  27130. remove: function (selector) {
  27131. var self = this;
  27132. var i, editor;
  27133. if (!selector) {
  27134. for (i = editors.length - 1; i >= 0; i--) {
  27135. self.remove(editors[i]);
  27136. }
  27137. return;
  27138. }
  27139. if (isString(selector)) {
  27140. each$k(DOM$9.select(selector), function (elm) {
  27141. editor = self.get(elm.id);
  27142. if (editor) {
  27143. self.remove(editor);
  27144. }
  27145. });
  27146. return;
  27147. }
  27148. editor = selector;
  27149. if (isNull(self.get(editor.id))) {
  27150. return null;
  27151. }
  27152. if (removeEditorFromList(editor)) {
  27153. self.fire('RemoveEditor', { editor: editor });
  27154. }
  27155. if (editors.length === 0) {
  27156. window.removeEventListener('beforeunload', beforeUnloadDelegate);
  27157. }
  27158. editor.remove();
  27159. toggleGlobalEvents(editors.length > 0);
  27160. return editor;
  27161. },
  27162. execCommand: function (cmd, ui, value) {
  27163. var self = this, editor = self.get(value);
  27164. switch (cmd) {
  27165. case 'mceAddEditor':
  27166. if (!self.get(value)) {
  27167. new Editor(value, self.settings, self).render();
  27168. }
  27169. return true;
  27170. case 'mceRemoveEditor':
  27171. if (editor) {
  27172. editor.remove();
  27173. }
  27174. return true;
  27175. case 'mceToggleEditor':
  27176. if (!editor) {
  27177. self.execCommand('mceAddEditor', 0, value);
  27178. return true;
  27179. }
  27180. if (editor.isHidden()) {
  27181. editor.show();
  27182. } else {
  27183. editor.hide();
  27184. }
  27185. return true;
  27186. }
  27187. if (self.activeEditor) {
  27188. return self.activeEditor.execCommand(cmd, ui, value);
  27189. }
  27190. return false;
  27191. },
  27192. triggerSave: function () {
  27193. each$k(editors, function (editor) {
  27194. editor.save();
  27195. });
  27196. },
  27197. addI18n: function (code, items) {
  27198. I18n.add(code, items);
  27199. },
  27200. translate: function (text) {
  27201. return I18n.translate(text);
  27202. },
  27203. setActive: function (editor) {
  27204. var activeEditor = this.activeEditor;
  27205. if (this.activeEditor !== editor) {
  27206. if (activeEditor) {
  27207. activeEditor.fire('deactivate', { relatedTarget: editor });
  27208. }
  27209. editor.fire('activate', { relatedTarget: activeEditor });
  27210. }
  27211. this.activeEditor = editor;
  27212. },
  27213. _setBaseUrl: function (baseUrl) {
  27214. this.baseURL = new URI(this.documentBaseURL).toAbsolute(baseUrl.replace(/\/+$/, ''));
  27215. this.baseURI = new URI(this.baseURL);
  27216. }
  27217. });
  27218. EditorManager.setup();
  27219. function RangeUtils(dom) {
  27220. var walk = function (rng, callback) {
  27221. return RangeWalk.walk(dom, rng, callback);
  27222. };
  27223. var split = split$1;
  27224. var normalize = function (rng) {
  27225. return NormalizeRange.normalize(dom, rng).fold(constant(false), function (normalizedRng) {
  27226. rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);
  27227. rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);
  27228. return true;
  27229. });
  27230. };
  27231. return {
  27232. walk: walk,
  27233. split: split,
  27234. normalize: normalize
  27235. };
  27236. }
  27237. (function (RangeUtils) {
  27238. RangeUtils.compareRanges = RangeCompare.isEq;
  27239. RangeUtils.getCaretRangeFromPoint = CaretRangeFromPoint.fromPoint;
  27240. RangeUtils.getSelectedNode = getSelectedNode;
  27241. RangeUtils.getNode = getNode;
  27242. }(RangeUtils || (RangeUtils = {})));
  27243. var RangeUtils$1 = RangeUtils;
  27244. var awaiter = function (resolveCb, rejectCb, timeout) {
  27245. if (timeout === void 0) {
  27246. timeout = 1000;
  27247. }
  27248. var done = false;
  27249. var timer = null;
  27250. var complete = function (completer) {
  27251. return function () {
  27252. var args = [];
  27253. for (var _i = 0; _i < arguments.length; _i++) {
  27254. args[_i] = arguments[_i];
  27255. }
  27256. if (!done) {
  27257. done = true;
  27258. if (timer !== null) {
  27259. domGlobals.clearTimeout(timer);
  27260. timer = null;
  27261. }
  27262. completer.apply(null, args);
  27263. }
  27264. };
  27265. };
  27266. var resolve = complete(resolveCb);
  27267. var reject = complete(rejectCb);
  27268. var start = function () {
  27269. var args = [];
  27270. for (var _i = 0; _i < arguments.length; _i++) {
  27271. args[_i] = arguments[_i];
  27272. }
  27273. if (!done && timer === null) {
  27274. timer = domGlobals.setTimeout(function () {
  27275. return reject.apply(null, args);
  27276. }, timeout);
  27277. }
  27278. };
  27279. return {
  27280. start: start,
  27281. resolve: resolve,
  27282. reject: reject
  27283. };
  27284. };
  27285. var create$6 = function () {
  27286. var tasks = {};
  27287. var resultFns = {};
  27288. var load = function (id, url) {
  27289. var loadErrMsg = 'Script at URL "' + url + '" failed to load';
  27290. var runErrMsg = 'Script at URL "' + url + '" did not call `tinymce.Resource.add(\'' + id + '\', data)` within 1 second';
  27291. if (tasks[id] !== undefined) {
  27292. return tasks[id];
  27293. } else {
  27294. var task = new promiseObj(function (resolve, reject) {
  27295. var waiter = awaiter(resolve, reject);
  27296. resultFns[id] = waiter.resolve;
  27297. ScriptLoader.ScriptLoader.loadScript(url, function () {
  27298. return waiter.start(runErrMsg);
  27299. }, function () {
  27300. return waiter.reject(loadErrMsg);
  27301. });
  27302. });
  27303. tasks[id] = task;
  27304. return task;
  27305. }
  27306. };
  27307. var add = function (id, data) {
  27308. if (resultFns[id] !== undefined) {
  27309. resultFns[id](data);
  27310. delete resultFns[id];
  27311. }
  27312. tasks[id] = promiseObj.resolve(data);
  27313. };
  27314. return {
  27315. load: load,
  27316. add: add
  27317. };
  27318. };
  27319. var Resource = create$6();
  27320. var min = Math.min, max = Math.max, round$2 = Math.round;
  27321. var relativePosition = function (rect, targetRect, rel) {
  27322. var x, y, w, h, targetW, targetH;
  27323. x = targetRect.x;
  27324. y = targetRect.y;
  27325. w = rect.w;
  27326. h = rect.h;
  27327. targetW = targetRect.w;
  27328. targetH = targetRect.h;
  27329. rel = (rel || '').split('');
  27330. if (rel[0] === 'b') {
  27331. y += targetH;
  27332. }
  27333. if (rel[1] === 'r') {
  27334. x += targetW;
  27335. }
  27336. if (rel[0] === 'c') {
  27337. y += round$2(targetH / 2);
  27338. }
  27339. if (rel[1] === 'c') {
  27340. x += round$2(targetW / 2);
  27341. }
  27342. if (rel[3] === 'b') {
  27343. y -= h;
  27344. }
  27345. if (rel[4] === 'r') {
  27346. x -= w;
  27347. }
  27348. if (rel[3] === 'c') {
  27349. y -= round$2(h / 2);
  27350. }
  27351. if (rel[4] === 'c') {
  27352. x -= round$2(w / 2);
  27353. }
  27354. return create$7(x, y, w, h);
  27355. };
  27356. var findBestRelativePosition = function (rect, targetRect, constrainRect, rels) {
  27357. var pos, i;
  27358. for (i = 0; i < rels.length; i++) {
  27359. pos = relativePosition(rect, targetRect, rels[i]);
  27360. 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) {
  27361. return rels[i];
  27362. }
  27363. }
  27364. return null;
  27365. };
  27366. var inflate = function (rect, w, h) {
  27367. return create$7(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2);
  27368. };
  27369. var intersect = function (rect, cropRect) {
  27370. var x1, y1, x2, y2;
  27371. x1 = max(rect.x, cropRect.x);
  27372. y1 = max(rect.y, cropRect.y);
  27373. x2 = min(rect.x + rect.w, cropRect.x + cropRect.w);
  27374. y2 = min(rect.y + rect.h, cropRect.y + cropRect.h);
  27375. if (x2 - x1 < 0 || y2 - y1 < 0) {
  27376. return null;
  27377. }
  27378. return create$7(x1, y1, x2 - x1, y2 - y1);
  27379. };
  27380. var clamp$1 = function (rect, clampRect, fixedSize) {
  27381. var underflowX1, underflowY1, overflowX2, overflowY2, x1, y1, x2, y2, cx2, cy2;
  27382. x1 = rect.x;
  27383. y1 = rect.y;
  27384. x2 = rect.x + rect.w;
  27385. y2 = rect.y + rect.h;
  27386. cx2 = clampRect.x + clampRect.w;
  27387. cy2 = clampRect.y + clampRect.h;
  27388. underflowX1 = max(0, clampRect.x - x1);
  27389. underflowY1 = max(0, clampRect.y - y1);
  27390. overflowX2 = max(0, x2 - cx2);
  27391. overflowY2 = max(0, y2 - cy2);
  27392. x1 += underflowX1;
  27393. y1 += underflowY1;
  27394. if (fixedSize) {
  27395. x2 += underflowX1;
  27396. y2 += underflowY1;
  27397. x1 -= overflowX2;
  27398. y1 -= overflowY2;
  27399. }
  27400. x2 -= overflowX2;
  27401. y2 -= overflowY2;
  27402. return create$7(x1, y1, x2 - x1, y2 - y1);
  27403. };
  27404. var create$7 = function (x, y, w, h) {
  27405. return {
  27406. x: x,
  27407. y: y,
  27408. w: w,
  27409. h: h
  27410. };
  27411. };
  27412. var fromClientRect = function (clientRect) {
  27413. return create$7(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
  27414. };
  27415. var Rect = {
  27416. inflate: inflate,
  27417. relativePosition: relativePosition,
  27418. findBestRelativePosition: findBestRelativePosition,
  27419. intersect: intersect,
  27420. clamp: clamp$1,
  27421. create: create$7,
  27422. fromClientRect: fromClientRect
  27423. };
  27424. var each$l = Tools.each, extend$5 = Tools.extend;
  27425. var extendClass, initializing;
  27426. var Class = function () {
  27427. };
  27428. Class.extend = extendClass = function (prop) {
  27429. var self = this;
  27430. var _super = self.prototype;
  27431. var prototype, name, member;
  27432. var Class = function () {
  27433. var i, mixins, mixin;
  27434. var self = this;
  27435. if (!initializing) {
  27436. if (self.init) {
  27437. self.init.apply(self, arguments);
  27438. }
  27439. mixins = self.Mixins;
  27440. if (mixins) {
  27441. i = mixins.length;
  27442. while (i--) {
  27443. mixin = mixins[i];
  27444. if (mixin.init) {
  27445. mixin.init.apply(self, arguments);
  27446. }
  27447. }
  27448. }
  27449. }
  27450. };
  27451. var dummy = function () {
  27452. return this;
  27453. };
  27454. var createMethod = function (name, fn) {
  27455. return function () {
  27456. var self = this;
  27457. var tmp = self._super;
  27458. var ret;
  27459. self._super = _super[name];
  27460. ret = fn.apply(self, arguments);
  27461. self._super = tmp;
  27462. return ret;
  27463. };
  27464. };
  27465. initializing = true;
  27466. prototype = new self();
  27467. initializing = false;
  27468. if (prop.Mixins) {
  27469. each$l(prop.Mixins, function (mixin) {
  27470. for (var name_1 in mixin) {
  27471. if (name_1 !== 'init') {
  27472. prop[name_1] = mixin[name_1];
  27473. }
  27474. }
  27475. });
  27476. if (_super.Mixins) {
  27477. prop.Mixins = _super.Mixins.concat(prop.Mixins);
  27478. }
  27479. }
  27480. if (prop.Methods) {
  27481. each$l(prop.Methods.split(','), function (name) {
  27482. prop[name] = dummy;
  27483. });
  27484. }
  27485. if (prop.Properties) {
  27486. each$l(prop.Properties.split(','), function (name) {
  27487. var fieldName = '_' + name;
  27488. prop[name] = function (value) {
  27489. var self = this;
  27490. if (value !== undefined) {
  27491. self[fieldName] = value;
  27492. return self;
  27493. }
  27494. return self[fieldName];
  27495. };
  27496. });
  27497. }
  27498. if (prop.Statics) {
  27499. each$l(prop.Statics, function (func, name) {
  27500. Class[name] = func;
  27501. });
  27502. }
  27503. if (prop.Defaults && _super.Defaults) {
  27504. prop.Defaults = extend$5({}, _super.Defaults, prop.Defaults);
  27505. }
  27506. for (name in prop) {
  27507. member = prop[name];
  27508. if (typeof member === 'function' && _super[name]) {
  27509. prototype[name] = createMethod(name, member);
  27510. } else {
  27511. prototype[name] = member;
  27512. }
  27513. }
  27514. Class.prototype = prototype;
  27515. Class.constructor = Class;
  27516. Class.extend = extendClass;
  27517. return Class;
  27518. };
  27519. var min$1 = Math.min, max$1 = Math.max, round$3 = Math.round;
  27520. var Color = function (value) {
  27521. var self = {};
  27522. var r = 0, g = 0, b = 0;
  27523. var rgb2hsv = function (r, g, b) {
  27524. var h, s, v, d, minRGB, maxRGB;
  27525. h = 0;
  27526. s = 0;
  27527. v = 0;
  27528. r = r / 255;
  27529. g = g / 255;
  27530. b = b / 255;
  27531. minRGB = min$1(r, min$1(g, b));
  27532. maxRGB = max$1(r, max$1(g, b));
  27533. if (minRGB === maxRGB) {
  27534. v = minRGB;
  27535. return {
  27536. h: 0,
  27537. s: 0,
  27538. v: v * 100
  27539. };
  27540. }
  27541. d = r === minRGB ? g - b : b === minRGB ? r - g : b - r;
  27542. h = r === minRGB ? 3 : b === minRGB ? 1 : 5;
  27543. h = 60 * (h - d / (maxRGB - minRGB));
  27544. s = (maxRGB - minRGB) / maxRGB;
  27545. v = maxRGB;
  27546. return {
  27547. h: round$3(h),
  27548. s: round$3(s * 100),
  27549. v: round$3(v * 100)
  27550. };
  27551. };
  27552. var hsvToRgb = function (hue, saturation, brightness) {
  27553. var side, chroma, x, match;
  27554. hue = (parseInt(hue, 10) || 0) % 360;
  27555. saturation = parseInt(saturation, 10) / 100;
  27556. brightness = parseInt(brightness, 10) / 100;
  27557. saturation = max$1(0, min$1(saturation, 1));
  27558. brightness = max$1(0, min$1(brightness, 1));
  27559. if (saturation === 0) {
  27560. r = g = b = round$3(255 * brightness);
  27561. return;
  27562. }
  27563. side = hue / 60;
  27564. chroma = brightness * saturation;
  27565. x = chroma * (1 - Math.abs(side % 2 - 1));
  27566. match = brightness - chroma;
  27567. switch (Math.floor(side)) {
  27568. case 0:
  27569. r = chroma;
  27570. g = x;
  27571. b = 0;
  27572. break;
  27573. case 1:
  27574. r = x;
  27575. g = chroma;
  27576. b = 0;
  27577. break;
  27578. case 2:
  27579. r = 0;
  27580. g = chroma;
  27581. b = x;
  27582. break;
  27583. case 3:
  27584. r = 0;
  27585. g = x;
  27586. b = chroma;
  27587. break;
  27588. case 4:
  27589. r = x;
  27590. g = 0;
  27591. b = chroma;
  27592. break;
  27593. case 5:
  27594. r = chroma;
  27595. g = 0;
  27596. b = x;
  27597. break;
  27598. default:
  27599. r = g = b = 0;
  27600. }
  27601. r = round$3(255 * (r + match));
  27602. g = round$3(255 * (g + match));
  27603. b = round$3(255 * (b + match));
  27604. };
  27605. var toHex = function () {
  27606. var hex = function (val) {
  27607. val = parseInt(val, 10).toString(16);
  27608. return val.length > 1 ? val : '0' + val;
  27609. };
  27610. return '#' + hex(r) + hex(g) + hex(b);
  27611. };
  27612. var toRgb = function () {
  27613. return {
  27614. r: r,
  27615. g: g,
  27616. b: b
  27617. };
  27618. };
  27619. var toHsv = function () {
  27620. return rgb2hsv(r, g, b);
  27621. };
  27622. var parse = function (value) {
  27623. var matches;
  27624. if (typeof value === 'object') {
  27625. if ('r' in value) {
  27626. r = value.r;
  27627. g = value.g;
  27628. b = value.b;
  27629. } else if ('v' in value) {
  27630. hsvToRgb(value.h, value.s, value.v);
  27631. }
  27632. } else {
  27633. if (matches = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(value)) {
  27634. r = parseInt(matches[1], 10);
  27635. g = parseInt(matches[2], 10);
  27636. b = parseInt(matches[3], 10);
  27637. } else if (matches = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value)) {
  27638. r = parseInt(matches[1], 16);
  27639. g = parseInt(matches[2], 16);
  27640. b = parseInt(matches[3], 16);
  27641. } else if (matches = /#([0-F])([0-F])([0-F])/gi.exec(value)) {
  27642. r = parseInt(matches[1] + matches[1], 16);
  27643. g = parseInt(matches[2] + matches[2], 16);
  27644. b = parseInt(matches[3] + matches[3], 16);
  27645. }
  27646. }
  27647. r = r < 0 ? 0 : r > 255 ? 255 : r;
  27648. g = g < 0 ? 0 : g > 255 ? 255 : g;
  27649. b = b < 0 ? 0 : b > 255 ? 255 : b;
  27650. return self;
  27651. };
  27652. if (value) {
  27653. parse(value);
  27654. }
  27655. self.toRgb = toRgb;
  27656. self.toHsv = toHsv;
  27657. self.toHex = toHex;
  27658. self.parse = parse;
  27659. return self;
  27660. };
  27661. var serialize = function (obj) {
  27662. var data = JSON.stringify(obj);
  27663. if (!isString(data)) {
  27664. return data;
  27665. }
  27666. return data.replace(/[\u0080-\uFFFF]/g, function (match) {
  27667. var hexCode = match.charCodeAt(0).toString(16);
  27668. return '\\u' + '0000'.substring(hexCode.length) + hexCode;
  27669. });
  27670. };
  27671. var JSONUtils = {
  27672. serialize: serialize,
  27673. parse: function (text) {
  27674. try {
  27675. return JSON.parse(text);
  27676. } catch (ex) {
  27677. }
  27678. }
  27679. };
  27680. var JSONP = {
  27681. callbacks: {},
  27682. count: 0,
  27683. send: function (settings) {
  27684. var self = this, dom = DOMUtils$1.DOM, count = settings.count !== undefined ? settings.count : self.count;
  27685. var id = 'tinymce_jsonp_' + count;
  27686. self.callbacks[count] = function (json) {
  27687. dom.remove(id);
  27688. delete self.callbacks[count];
  27689. settings.callback(json);
  27690. };
  27691. dom.add(dom.doc.body, 'script', {
  27692. id: id,
  27693. src: settings.url,
  27694. type: 'text/javascript'
  27695. });
  27696. self.count++;
  27697. }
  27698. };
  27699. var XHR = __assign(__assign({}, Observable), {
  27700. send: function (settings) {
  27701. var xhr, count = 0;
  27702. var ready = function () {
  27703. if (!settings.async || xhr.readyState === 4 || count++ > 10000) {
  27704. if (settings.success && count < 10000 && xhr.status === 200) {
  27705. settings.success.call(settings.success_scope, '' + xhr.responseText, xhr, settings);
  27706. } else if (settings.error) {
  27707. settings.error.call(settings.error_scope, count > 10000 ? 'TIMED_OUT' : 'GENERAL', xhr, settings);
  27708. }
  27709. xhr = null;
  27710. } else {
  27711. Delay.setTimeout(ready, 10);
  27712. }
  27713. };
  27714. settings.scope = settings.scope || this;
  27715. settings.success_scope = settings.success_scope || settings.scope;
  27716. settings.error_scope = settings.error_scope || settings.scope;
  27717. settings.async = settings.async !== false;
  27718. settings.data = settings.data || '';
  27719. XHR.fire('beforeInitialize', { settings: settings });
  27720. xhr = new domGlobals.XMLHttpRequest();
  27721. if (xhr) {
  27722. if (xhr.overrideMimeType) {
  27723. xhr.overrideMimeType(settings.content_type);
  27724. }
  27725. xhr.open(settings.type || (settings.data ? 'POST' : 'GET'), settings.url, settings.async);
  27726. if (settings.crossDomain) {
  27727. xhr.withCredentials = true;
  27728. }
  27729. if (settings.content_type) {
  27730. xhr.setRequestHeader('Content-Type', settings.content_type);
  27731. }
  27732. if (settings.requestheaders) {
  27733. Tools.each(settings.requestheaders, function (header) {
  27734. xhr.setRequestHeader(header.key, header.value);
  27735. });
  27736. }
  27737. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  27738. xhr = XHR.fire('beforeSend', {
  27739. xhr: xhr,
  27740. settings: settings
  27741. }).xhr;
  27742. xhr.send(settings.data);
  27743. if (!settings.async) {
  27744. return ready();
  27745. }
  27746. Delay.setTimeout(ready, 10);
  27747. }
  27748. }
  27749. });
  27750. var extend$6 = Tools.extend;
  27751. var JSONRequest = function () {
  27752. function JSONRequest(settings) {
  27753. this.settings = extend$6({}, settings);
  27754. this.count = 0;
  27755. }
  27756. JSONRequest.sendRPC = function (o) {
  27757. return new JSONRequest().send(o);
  27758. };
  27759. JSONRequest.prototype.send = function (args) {
  27760. var ecb = args.error, scb = args.success;
  27761. var xhrArgs = extend$6(this.settings, args);
  27762. xhrArgs.success = function (c, x) {
  27763. c = JSONUtils.parse(c);
  27764. if (typeof c === 'undefined') {
  27765. c = { error: 'JSON Parse error.' };
  27766. }
  27767. if (c.error) {
  27768. ecb.call(xhrArgs.error_scope || xhrArgs.scope, c.error, x);
  27769. } else {
  27770. scb.call(xhrArgs.success_scope || xhrArgs.scope, c.result);
  27771. }
  27772. };
  27773. xhrArgs.error = function (ty, x) {
  27774. if (ecb) {
  27775. ecb.call(xhrArgs.error_scope || xhrArgs.scope, ty, x);
  27776. }
  27777. };
  27778. xhrArgs.data = JSONUtils.serialize({
  27779. id: args.id || 'c' + this.count++,
  27780. method: args.method,
  27781. params: args.params
  27782. });
  27783. xhrArgs.content_type = 'application/json';
  27784. XHR.send(xhrArgs);
  27785. };
  27786. return JSONRequest;
  27787. }();
  27788. var create$8 = function () {
  27789. return function () {
  27790. var data = {};
  27791. var keys = [];
  27792. var storage = {
  27793. getItem: function (key) {
  27794. var item = data[key];
  27795. return item ? item : null;
  27796. },
  27797. setItem: function (key, value) {
  27798. keys.push(key);
  27799. data[key] = String(value);
  27800. },
  27801. key: function (index) {
  27802. return keys[index];
  27803. },
  27804. removeItem: function (key) {
  27805. keys = keys.filter(function (k) {
  27806. return k === key;
  27807. });
  27808. delete data[key];
  27809. },
  27810. clear: function () {
  27811. keys = [];
  27812. data = {};
  27813. },
  27814. length: 0
  27815. };
  27816. Object.defineProperty(storage, 'length', {
  27817. get: function () {
  27818. return keys.length;
  27819. },
  27820. configurable: false,
  27821. enumerable: false
  27822. });
  27823. return storage;
  27824. }();
  27825. };
  27826. var localStorage;
  27827. try {
  27828. localStorage = domGlobals.window.localStorage;
  27829. } catch (e) {
  27830. localStorage = create$8();
  27831. }
  27832. var LocalStorage = localStorage;
  27833. var publicApi = {
  27834. geom: { Rect: Rect },
  27835. util: {
  27836. Promise: promiseObj,
  27837. Delay: Delay,
  27838. Tools: Tools,
  27839. VK: VK,
  27840. URI: URI,
  27841. Class: Class,
  27842. EventDispatcher: EventDispatcher,
  27843. Observable: Observable,
  27844. I18n: I18n,
  27845. XHR: XHR,
  27846. JSON: JSONUtils,
  27847. JSONRequest: JSONRequest,
  27848. JSONP: JSONP,
  27849. LocalStorage: LocalStorage,
  27850. Color: Color
  27851. },
  27852. dom: {
  27853. EventUtils: EventUtils,
  27854. Sizzle: Sizzle,
  27855. DomQuery: DomQuery,
  27856. TreeWalker: TreeWalker,
  27857. DOMUtils: DOMUtils$1,
  27858. ScriptLoader: ScriptLoader,
  27859. RangeUtils: RangeUtils$1,
  27860. Serializer: Serializer$1,
  27861. ControlSelection: ControlSelection,
  27862. BookmarkManager: BookmarkManager$1,
  27863. Selection: Selection$1,
  27864. Event: EventUtils.Event
  27865. },
  27866. html: {
  27867. Styles: Styles,
  27868. Entities: Entities,
  27869. Node: Node$1,
  27870. Schema: Schema,
  27871. SaxParser: SaxParser$1,
  27872. DomParser: DomParser,
  27873. Writer: Writer,
  27874. Serializer: Serializer
  27875. },
  27876. Env: Env,
  27877. AddOnManager: AddOnManager$1,
  27878. Annotator: Annotator,
  27879. Formatter: Formatter,
  27880. UndoManager: UndoManager,
  27881. EditorCommands: EditorCommands,
  27882. WindowManager: WindowManager,
  27883. NotificationManager: NotificationManager,
  27884. EditorObservable: EditorObservable,
  27885. Shortcuts: Shortcuts,
  27886. Editor: Editor,
  27887. FocusManager: FocusManager,
  27888. EditorManager: EditorManager,
  27889. DOM: DOMUtils$1.DOM,
  27890. ScriptLoader: ScriptLoader.ScriptLoader,
  27891. PluginManager: AddOnManager$1.PluginManager,
  27892. ThemeManager: AddOnManager$1.ThemeManager,
  27893. IconManager: IconManager,
  27894. Resource: Resource,
  27895. trim: Tools.trim,
  27896. isArray: Tools.isArray,
  27897. is: Tools.is,
  27898. toArray: Tools.toArray,
  27899. makeMap: Tools.makeMap,
  27900. each: Tools.each,
  27901. map: Tools.map,
  27902. grep: Tools.grep,
  27903. inArray: Tools.inArray,
  27904. extend: Tools.extend,
  27905. create: Tools.create,
  27906. walk: Tools.walk,
  27907. createNS: Tools.createNS,
  27908. resolve: Tools.resolve,
  27909. explode: Tools.explode,
  27910. _addCacheSuffix: Tools._addCacheSuffix,
  27911. isOpera: Env.opera,
  27912. isWebKit: Env.webkit,
  27913. isIE: Env.ie,
  27914. isGecko: Env.gecko,
  27915. isMac: Env.mac
  27916. };
  27917. var tinymce = Tools.extend(EditorManager, publicApi);
  27918. var exportToModuleLoaders = function (tinymce) {
  27919. if (typeof module === 'object') {
  27920. try {
  27921. module.exports = tinymce;
  27922. } catch (_) {
  27923. }
  27924. }
  27925. };
  27926. var exportToWindowGlobal = function (tinymce) {
  27927. window.tinymce = tinymce;
  27928. window.tinyMCE = tinymce;
  27929. };
  27930. exportToWindowGlobal(tinymce);
  27931. exportToModuleLoaders(tinymce);
  27932. }(window));