10 lines
21 KiB
JavaScript
10 lines
21 KiB
JavaScript
/*!
|
|
* Tiny FullpageHTML plugin
|
|
*
|
|
* Copyright (c) 2025 Ephox Corporation DBA Tiny Technologies, Inc.
|
|
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
|
|
*
|
|
* Version: 8.3.0-112
|
|
*/
|
|
|
|
!function(){"use strict";const e=e=>t=>typeof t===e,t=e=>"string"===(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(n=o=e,(r=String).prototype.isPrototypeOf(n)||o.constructor?.name===r.name)?"string":t;var n,o,r})(e),n=e("boolean"),o=e=>null==e,r=e=>!o(e),s=e("function"),a=e("number"),l=()=>{},i=e=>()=>e,c=e=>e,d=i(!1),u=i(!0);class m{tag;value;static singletonNone=new m(!1);constructor(e,t){this.tag=e,this.value=t}static some(e){return new m(!0,e)}static none(){return m.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?m.some(e(this.value)):m.none()}bind(e){return this.tag?e(this.value):m.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:m.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(e??"Called getOrDie on None")}static from(e){return r(e)?m.some(e):m.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}const p=(e,t)=>{for(let n=0,o=e.length;n<o;n++)if(t(e[n],n))return!0;return!1},g=(e,t)=>{for(let n=0,o=e.length;n<o;n++)t(e[n],n)},h=(e,t,n)=>(g(e,((e,o)=>{n=t(n,e,o)})),n),y=(e,t)=>((e,t,n)=>{for(let o=0,r=e.length;o<r;o++){const r=e[o];if(t(r,o))return m.some(r);if(n(r,o))break}return m.none()})(e,t,d),f=Object.keys,v=(e,t)=>{const n=f(e);for(let o=0,r=n.length;o<r;o++){const r=n[o];t(e[r],r)}},b=(e,t)=>C(e,((e,n)=>({k:n,v:t(e,n)}))),C=(e,t)=>{const n={};return v(e,((e,o)=>{const r=t(e,o);n[r.k]=r.v})),n},w=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},S=(x=/^\s+|\s+$/g,e=>e.replace(x,""));var x;const P=(e,t)=>{const{type:n,message:o}=t;e.notificationManager.open({type:n,text:o})},k=e=>{(e=>{switch(e){case"error":return console.error;case"info":return console.info;case"warn":return console.warn;default:return console.log}})(e.type)(e.message)},$=(e,t)=>{const{protect:n,allowList:o=[],blockList:s=[]}=null!=e?e:{};let a;return a=r(n)?n:o.length>0||s.length>0||t,{protect:a,allowList:o,blockList:s}},R=e=>{const{protect:t,allowList:n,blockList:o}=null!=e?e:{};return e=>{const r=e.toLowerCase();return n.length>0?!p(n,(e=>e.toLowerCase()===r)):o.length>0?p(o,(e=>e.toLowerCase()===r)):t}},_=e=>{const t=R(e);return(e,n)=>{const o=((e,t)=>`${e}:${t}`)(n,e.toLowerCase());return t(o)}},E=(e,t,n,o)=>{const r=Reflect.get(e,"on"),s={protectedEventHandlers:[],cleanupScheduled:!1},a=(e,t)=>{o&&console.log(`[EventsProxy] ${e}`,t||"")},i=t=>{"invalid"===t&&s.protectedEventHandlers.length>0&&(a("Removing event handlers",s.protectedEventHandlers),g(s.protectedEventHandlers,(t=>{e.off(t.name,t.callback)})),s.protectedEventHandlers=[])},c=t.onStatusChange(i);return e.on("remove",c),(o,c,d)=>{a(`Adding event listener: ${o}`,{shouldProtect:n(o)});const u=((e,o)=>{const r=n(e),a=t.getStatus(),i=r&&"invalid"===a?l:o;return r&&s.protectedEventHandlers.push({name:e,callback:i}),i})(o,c);return s.cleanupScheduled||(s.cleanupScheduled=!0,window.setTimeout((()=>{i(t.getStatus()),s.cleanupScheduled=!1}),0)),Reflect.apply(r,e,[o,u,d])}},T=(e,t,n)=>o=>{const s="invalid"!==t.getStatus()&&r(n)?n(o):l,a=((e,t,n)=>{const o=e=>{"invalid"===e&&n.setEnabled(!1)},r=()=>o(t.getStatus());o(t.getStatus()),e.on("NodeChange",r);const s=t.onStatusChange(o);return()=>{e.off("NodeChange",r),s()}})(e,t,o);return e=>{null==s||s(e),a()}},O=(e,t,n)=>(...o)=>{var r;return"invalid"===e.getStatus()?n:null!==(r=null==t?void 0:t(...o))&&void 0!==r?r:n},L=(e,t)=>O(e,t,Promise.resolve([])),A=(e,t)=>O(e,t,[]),M=(e,t)=>O(e,t,!1),N=(e,n,o,r)=>{const s=n=>{const{command:s,value:a}=n,l=m.from(a).filter(t).map((e=>e.toLowerCase())),i=s.toLowerCase()===r.toLowerCase(),c=l.exists((e=>o.has(e))),d=l.exists((t=>t===e.queryCommandValue(r)));i&&c&&!d&&n.preventDefault()},a=n.onStatusChange((t=>{if("invalid"===t){e.on("BeforeExecCommand",s);const t=()=>{const t=e.queryCommandValue(r);o.has(t.toLowerCase())&&e.execCommand(r,!1,t)};e.initialized?t():e.on("init",t)}}));e.on("remove",(()=>{a(),e.off("BeforeExecCommand",s)}))},H=(e,n,o,r,s,a=!1)=>{const l=new Set,i=new Set,c=(e,t)=>{a&&console.log(`[UiProxy] ${e}`,t||"")};((e,t,n)=>{N(e,t,n,"ToggleView")})(e,o,l),((e,t,n)=>{N(e,t,n,"ToggleSidebar")})(e,o,i);const d=(t,n,a,l)=>{const i=s(t,a);return c(`${l}: ${t}`,{spec:n,context:r,shouldProtect:i}),i?{...n,onSetup:T(e,o,n.onSetup)}:n};return new Proxy(n,{get:(e,n,a)=>{const u=Reflect.get(e,n,a);if(!t(n))return u;switch(n){case"addButton":case"addGroupToolbarButton":case"addToggleButton":case"addMenuButton":case"addSplitButton":return(...t)=>{const[o,r,...s]=t,a=d(o,r,"button",String(n));return Reflect.apply(u,e,[o,a,...s])};case"addMenuItem":case"addToggleMenuItem":case"addNestedMenuItem":return(...t)=>{const[o,r,...s]=t,a=d(o,r,"menuitem",String(n));return Reflect.apply(u,e,[o,a,...s])};case"addAutocompleter":return(...t)=>{const[a,l,...i]=t,d=s(a,"autocompleter");if(c(`${String(n)}: ${a}`,{spec:l,context:r,shouldProtect:d}),d){const t={...l,fetch:L(o,l.fetch)};return Reflect.apply(u,e,[a,t,...i])}return Reflect.apply(u,e,[a,l,...i])};case"addSidebar":return(...t)=>{const[o,a,...l]=t,d=s(o,"sidebar");if(c(`${String(n)}: ${o}`,{spec:a,context:r,shouldProtect:d}),d){i.add(o.toLowerCase());const t={...a};return Reflect.apply(u,e,[o,t,...l])}return Reflect.apply(u,e,[o,a,...l])};case"addView":return(...t)=>{const[o,a,...i]=t,d=s(o,"view");if(c(`${String(n)}: ${o}`,{spec:a,context:r,shouldProtect:d}),d){l.add(o.toLowerCase());const t={...a};return Reflect.apply(u,e,[o,t,...i])}return Reflect.apply(u,e,[o,a,...i])};case"addContextMenu":return(...t)=>{const[a,l,...i]=t,d=s(a,"contextmenu");if(c(`${String(n)}: ${a}`,{spec:l,context:r,shouldProtect:d}),d){const t={...l,update:A(o,l.update)};return Reflect.apply(u,e,[a,t,...i])}return Reflect.apply(u,e,[a,l,...i])};case"addContextToolbar":case"addContextForm":return(...t)=>{const[a,l,...i]=t,d=s(a,"contexttoolbar");if(c(`${String(n)}: ${a}`,{spec:l,context:r,shouldProtect:d}),d){const t={...l,predicate:M(o,l.predicate)};return Reflect.apply(u,e,[a,t,...i])}return Reflect.apply(u,e,[a,l,...i])};case"addIcon":case"getAll":case"addContext":return u}}})},j=new Set(["addCommand","addCommands","addQueryStateHandler","addQueryValueHandler"]),z=e=>(t,n)=>{e&&console.log(`[EditorProxy] ${t}`,n||"")},D=(e,t)=>{const{statusProvider:n,uiContext:o,protection:r,debug:a=!1}=t,{events:i,commands:c,ui:d}=r;z(a)("Creating enhanced editor with options:",{hasStatusProvider:!!n,uiContext:o,debug:a,protection:r});const{editorUiProxy:u,editorCommandsProxy:m,editorEventListenerProxy:p}=((e,t,n,o,r,s,a)=>{const i=s.protect?{...e.ui,registry:H(e,e.ui.registry,t,n,_(s),a)}:e.ui,c=o.protect?((e,t,n,o,r)=>{const s={protectedCommands:[],cleanupScheduled:!1},a=(e,t)=>{r&&console.log(`[CommandsProxy] ${e}`,t||"")},i=(e,t)=>{const r=o(e),a=n.getStatus();return r&&s.protectedCommands.push(e),r&&"invalid"===a?l:t},c=t=>{"invalid"===t&&s.protectedCommands.length>0&&(a("Removing commands",s.protectedCommands),g(s.protectedCommands,(t=>{e.editorCommands.removeCommand(t)})),s.protectedCommands=[])},d=()=>{s.cleanupScheduled||(s.cleanupScheduled=!0,window.setTimeout((()=>{c(n.getStatus()),s.cleanupScheduled=!1}),0))},u=n.onStatusChange(c);return e.on("remove",u),new Proxy(t,{get:(e,n,r)=>{if(a(`Accessing property: ${String(n)}`),"addCommand"===n){const s=Reflect.get(e,n,r);return(e,n,...r)=>{a(`Adding command: ${e}`,{shouldProtect:o(e)});const l=i(e,n);return d(),Reflect.apply(s,t,[e,l,...r])}}if("addCommands"===n){const o=Reflect.get(e,n,r);return(e,n="exec")=>{a(`Adding commands (${n})`,{commandCount:Object.keys(e).length,willApplyEnforcement:"exec"===n});const r="exec"!==n?e:b(e,((e,t)=>i(t,e)));return d(),Reflect.apply(o,t,[r,n])}}return Reflect.get(e,n,r)}})})(e,e.editorCommands,t,R(o),a):e.editorCommands;return{editorUiProxy:i,editorCommandsProxy:c,editorEventListenerProxy:r.protect?E(e,t,R(r),a):e.on.bind(e)}})(e,n,o||"",c,i,d,a),h=((e,t,n,o)=>(r,a,l)=>{const i=String(a);if("on"===a)return z(o)("on intercepted"),n;if(j.has(i))return z(o)(`${i} intercepted`),t[i].bind(t);if("editorCommands"===a)return z(o)("editorCommands accessed"),t;if("ui"===a)return z(o)("ui accessed"),e;const c=Reflect.get(r,a,l);return s(c)?c.bind(r):c})(u,m,p,a);return new Proxy(e,{get:h,set:(e,t,n,o)=>Reflect.set(e,t,n,o),has:(e,t)=>Reflect.has(e,t),ownKeys:e=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(e,t)=>Reflect.getOwnPropertyDescriptor(e,t),defineProperty:(e,t,n)=>Reflect.defineProperty(e,t,n),deleteProperty:(e,t)=>Reflect.deleteProperty(e,t),isExtensible:e=>Reflect.isExtensible(e),preventExtensions:e=>Reflect.preventExtensions(e),getPrototypeOf:e=>Reflect.getPrototypeOf(e),setPrototypeOf:(e,t)=>Reflect.setPrototypeOf(e,t)})},q=e=>parseInt(e,10),B=(e,t)=>{const n=e-t;return 0===n?0:n>0?1:-1},I=(e,t,n)=>({major:e,minor:t,patch:n}),V=e=>{const t=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return t?I(q(t[1]),q(t[2]),q(t[3])):I(0,0,0)},F=(e,t)=>!!e&&-1===((e,t)=>{const n=B(e.major,t.major);if(0!==n)return n;const o=B(e.minor,t.minor);if(0!==o)return o;const r=B(e.patch,t.patch);return 0!==r?r:0})((e=>V((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),V(t)),K=V("8.3.0"),U=`${K.major}.${K.minor}.0`,G=`${K.major+1}.0.0`,W=(e,t)=>{const{setup:n,protection:a}=t;return(l,i)=>{if(!((e,t)=>F(e,U)?(console.error(`The "${t}" plugin requires at least version ${U} of TinyMCE.`),!1):!!F(e,G)||(console.error(`The "${t}" plugin requires at least version ${U} of TinyMCE but less than ${G}.`),!1))(tinymce,e)||((e,t)=>!!(e=>{var t;const n=null===(t=e.options.get("license_key"))||void 0===t?void 0:t.toLowerCase(),r=e.options.get("online_license_key");return o(r)&&"gpl"===n})(e)&&(((e,t)=>{const{console:n,editor:o}=t;r(o)&&(e._skinLoaded?P(e,o):e.on("SkinLoaded",(()=>{P(e,o)}))),r(n)&&k(n)})(e,{console:{type:"error",message:[`The "${t}" plugin requires a valid TinyMCE license key.`,"Read more: https://www.tiny.cloud/docs/tinymce/latest/license-key/"].join(" ")}}),!0))(l,e))return{};const c=(e=>{const{protect:t=!0,events:n,commands:o,ui:r,api:s}=null!=e?e:{};return{protect:t,events:$(n,false),commands:$(o,true),ui:$(r,true),api:$(s,true)}})(a),d=((e="pre-validation")=>{const t=w(e),n=new Set;let o=!1;const{enableLogging:r=!1}={},s=(e,...t)=>{r&&console.log(`[StatusProvider] ${e}`,...t)};return{setStatus:e=>{const o=t.get();if(o===e)return s("Status unchanged:",e),!1;t.set(e),s("Status changed:",o,"->",e);const r={currentStatus:e,previousStatus:o},a=Array.from(n);return g(a,(e=>{e(r.currentStatus,r.previousStatus)})),!0},onStatusChange:e=>(n.add(e),s("Callback registered, total listeners:",n.size),()=>{n.delete(e)&&s("Callback unregistered, remaining listeners:",n.size)}),getStatus:t.get,hasListeners:()=>n.size>0,destroy:()=>{o||(s("Destroying StatusProvider, clearing",n.size,"listeners"),n.clear(),o=!0)}}})(),u=((e,t,n)=>{const o=`commercial-license-${t}`;return e.ui.registry.addContext(o,(()=>"invalid"!==n.getStatus()&&!e.mode.isReadOnly())),e.licenseKeyManager.validate({plugin:t}).then((e=>{n.setStatus(e?"valid":"invalid")}),(e=>{console.error(e),console.error(`An unknown error occurred when trying to validate "${t}" plugin.`),n.setStatus("invalid")})),{ui:{context:o}}})(l,e,d),m=c.protect?D(l,{statusProvider:d,uiContext:u.ui.context,debug:t.debug||!1,protection:c}):l,p=((e,t)=>({pluginCode:e,enforcer:{isInvalid:()=>"invalid"===t.getStatus(),onInvalid:e=>t.onStatusChange(((t,n)=>{"invalid"===t&&e(t,n)}))}}))(e,d);return((e,t,n,o)=>{if(t.protect&&t.api.protect&&r(e)){const l=R(t.api);return(a=e=>"invalid"===n.getStatus()&&l(e),(e,t)=>b(e,((e,n)=>s(e)?(...o)=>{if(a(n.toLowerCase())){const e=`Method "${r(t)?`${t}.`:""}${n}" is not available due to license key restrictions.`,o=new Error(e);throw console.error(e),o}return e(...o)}:e)))(e,o)}var a;return e})(n(m,i,p),c,d,e)}},Q=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},Y=(e,t)=>{const n=(t||document).createElement("div");if(n.innerHTML=e,!n.hasChildNodes()||n.childNodes.length>1){const t="HTML does not have a single root node";throw console.error(t,e),new Error(t)}return Q(n.childNodes[0])},J=(e,t)=>{const n=(t||document).createElement(e);return Q(n)},X=Q,Z=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,ee=(e,t)=>{const n=void 0===t?document:t.dom;return Z(n)?[]:((e,t)=>{const n=e.length,o=new Array(n);for(let r=0;r<n;r++){const n=e[r];o[r]=t(n,r)}return o})(n.querySelectorAll(e),X)},te=(e,t)=>{const n=void 0===t?document:t.dom;return Z(n)?m.none():m.from(n.querySelector(e)).map(X)},ne=e=>1===(e=>e.dom.nodeType)(e);const oe=(e,t)=>{e.dom.appendChild(t.dom)},re=(e,o,r)=>{((e,o,r)=>{if(!(t(r)||n(r)||a(r)))throw console.error("Invalid call to Attribute.set. Key ",o,":: Value ",r,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(o,r+"")})(e.dom,o,r)},se=(e,t)=>{const n=e.dom.getAttribute(t);return null===n?void 0:n},ae=(e,t)=>m.from(se(e,t)),le=(e,t)=>{const n=e.dom;return!(!n||!n.hasAttribute)&&n.hasAttribute(t)},ie=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},ce=e=>t=>t.options.get(e),de=e=>t=>m.from(ce(e)(t)),ue=ce("fullpagehtml_hide_in_source_view"),me=de("fullpagehtml_default_encoding"),pe=de("fullpagehtml_default_body_style"),ge=de("fullpagehtml_default_title"),he=ce("fullpagehtml_default_doctype"),ye=de("protect"),fe=ce("indent"),ve=ce("xss_sanitization"),be=e=>X((new DOMParser).parseFromString(e,"text/html")),Ce=e=>null===e.dom.textContent?m.none():m.from(e.dom.textContent),we=e=>m.from(e.dom.doctype).map((e=>"<!DOCTYPE "+e.name+">")),Se=e=>{const t=ee("meta",e);return y(t,(e=>"Content-Type"===se(e,"http-equiv"))).bind((e=>ae(e,"content").bind((e=>{const t=/charset\s*=\s*(.*)\s*/gi.exec(e);return t?m.from(t[1]):m.none()})))).orThunk((()=>(e=>{for(let n=0;n<e.length;n++){const o=(t=e[n],ae(t,"charset"));if(o.isSome())return o}var t;return m.none()})(t)))},xe=e=>te("body",e).bind((e=>ae(e,"style"))),Pe=e=>{let t="";const n=ee("style",e);return g(n,(e=>{var n;(n=e,(e=>{const t=e.dom.childNodes;return m.from(t[0]).map(X)})(n)).each((e=>t+=e.dom.nodeValue))})),""===t?m.none():m.from(t)},ke=e=>{const t=[];return g(ee("link",e),(e=>{const n=se(e,"data-mce-href")||se(e,"href");"stylesheet"===se(e,"rel")&&se(e,"data-mce-fullpagehtml")&&n&&t.push(n)})),t.length>0?m.from(t):m.none()},$e=(e,t)=>{const n=ee("meta",t);return y(n,(t=>se(t,"name")===e)).bind((e=>ae(e,"content")))},Re={doctype:m.none(),title:m.none(),encoding:m.none(),bodystyle:m.none(),headstyle:m.none(),stylesheets:m.none(),keywords:m.none(),description:m.none(),robots:m.none(),author:m.none()},_e=(e,t,n)=>{const o=be(t),r=te("head",o).fold((()=>({...Re,doctype:we(o),bodystyle:xe(o)})),(e=>{return{title:(t=e,te("title",t).bind(Ce)),doctype:we(o),encoding:Se(e),bodystyle:xe(o),headstyle:Pe(e),stylesheets:ke(e),keywords:$e("keywords",e),description:$e("description",e),robots:$e("robots",e),author:$e("author",e)};var t}));return n&&je(r)?{...Re,doctype:m.from(he(e)),title:ge(e),encoding:me(e),bodystyle:pe(e)}:r},Ee=e=>e.map((e=>e)).getOr(""),Te=(e,t,n)=>y(ee(e,t),n),Oe=(e,t,n,o)=>Te(e,t,n).getOrThunk((()=>{const e=J(o);return oe(t,e),e})),Le=(e,t,n)=>{const o=Oe("meta",e,(e=>se(e,"name")===t),"meta");re(o,"name",t),re(o,"content",n)},Ae=(e,t)=>{Te("meta",e,(e=>se(e,"name")===t)).each((e=>ie(e)))},Me=(e,t)=>{const n=te("head",be(t)).getOr(X(document.createElement("head")));e.encoding.fold((()=>(e=>{g(ee("meta",e),(e=>{"Content-Type"===se(e,"http-equiv")&&ie(e)}))})(n)),(e=>((e,t)=>{const n=Oe("meta",e,(e=>"Content-Type"===se(e,"http-equiv")),"meta");Te("meta",e,(e=>le(e,"charset"))).each((e=>ie(e))),re(n,"http-equiv","Content-Type"),re(n,"content","text/html; charset="+t)})(n,e))),e.title.fold((()=>(e=>{te("title",e).each((e=>ie(e)))})(n)),(e=>((e,t)=>{Oe("title",e,u,"title").dom.innerText=t})(n,e))),e.keywords.fold((()=>Ae(n,"keywords")),(e=>Le(n,"keywords",e))),e.description.fold((()=>Ae(n,"description")),(e=>Le(n,"description",e))),e.robots.fold((()=>Ae(n,"robots")),(e=>Le(n,"robots",e))),e.author.fold((()=>Ae(n,"author")),(e=>Le(n,"author",e)));const o=Ee(e.doctype)+"<html>"+He().serialize(n.dom);return o.endsWith("<body></body>")?o.slice(0,o.length-13):o},Ne=(e,t)=>{const n=X(document.createElement("body")),o=te("body",be(t)).getOr(X(document.createElement("body")));var r,s,a;((e,t)=>{t.each((t=>{re(e,"style",t)}))})(n,e.bodystyle),r=o,s=n,a=f(h(o.dom.attributes,((e,t)=>(e[t.name]=t.value,e)),{})),ne(r)&&ne(s)&&g(a,(e=>{((e,t,n)=>{le(t,n)||ae(e,n).each((e=>re(t,n,e)))})(r,s,e)}));const l=He().serialize(n.dom);return l.substring(l.startsWith("<head></head>")?13:0,l.length-7)},He=()=>({serialize:e=>e.outerHTML}),je=e=>(e=>{for(let t=0,n=e.length;t<n;++t)if(!0!==e[t].isNone())return!1;return!0})(Object.values(e)),ze=(e,t,n,o)=>{const r=((e,t,n,o)=>{const r=_e(e,n,!1),s=je(r)?{data:_e(e,"",!0),content:o?t:n}:{data:r,content:n},a=Me(s.data,s.content),l=Ne(s.data,s.content),i=fe(e),c=ve(e),d=tinymce.html.DomParser({root_name:"#document",sanitize:c},e.schema).parse("<head>"+a+l+"</head>"),u=tinymce.html.Serializer({validate:!0,indent:i,indent_before:"head,html,body,meta,title,script,link,style",indent_after:"head,html,body,meta,title,script,link,style"},e.schema).serialize(d),m=i?Ee(s.data.doctype)+"\n<html>\n"+u:Ee(s.data.doctype)+"<html>"+u;return{text:m.slice(0,m.length-7),data:s.data}})(e,n.get(),((e,t)=>{const n=e.getOr([]);return n.length>0?h(n,((e,t)=>e.replace(t,(e=>"\x3c!--mce:protected "+escape(e)+"--\x3e"))),t):t})(ye(e),t),o);if(n.set(r.text),e.inline)return;const s=(e=>m.from(X(e.getDoc().head)))(e);De(e,s,r.data),qe(s,r.data)},De=(e,t,n)=>{e.dom.remove("fullpagehtml_styles"),n.headstyle.each((e=>t.each((t=>{oe(t,Y(`<style id="fullpagehtml_styles">${e}</style>`))})))),e.inline||e.getBody().setAttribute("style",n.bodystyle.getOr(""))},qe=(e,t)=>{const n={};g(e.map((e=>ee("link",e))).getOr([]),(e=>{const t=se(e,"data-mce-href")||se(e,"href");"stylesheet"===se(e,"rel")&&se(e,"data-mce-fullpagehtml")&&t&&(n[t]=e)})),g(t.stylesheets.getOr([]),(t=>{t&&(n[t]||e.each((e=>{oe(e,Y(`<link rel="stylesheet" text="text/css" data-mce-fullpagehtml="1" href="${t}">`))})),delete n[t])}));const o=((e,t)=>{const n=[];return v(e,((e,o)=>{n.push(t(e,o))})),n})(n,c);g(o,(e=>{ie(e)}))},Be="Metadata and document properties";((e,t)=>{const{i18n:n=!0}=t;n&&tinymce.PluginManager.requireLangPack(e,"ar,bg-BG,ca,cs,da,de,el,es,eu,fa,fi,fr-FR,he-IL,hi,hr,hu-HU,id,it,ja,kk,ko-KR,ms,nb-NO,nl,pl,pt-BR,pt-PT,ro,ru,sk,sl-SI,sv-SE,th-TH,tr,uk,vi,zh-CN,zh-TW"),tinymce.PluginManager.add(e,W(e,t))})("fullpagehtml",{setup:e=>{const t=w("");return((e,t)=>{e.on("BeforeSetContent",(n=>{if(n.selection)return;let o=n.content;"raw"===n.format&&t.get()||n.source_view&&ue(e)||(0===o.length&&t.get().length>0&&(o=S(t.get())+"\n</body></html>"),ze(e,o,t,!1))})),e.on("GetContent",(n=>{"html"!==n.format||n.selection||n.source_view&&ue(e)||(n.content=(S(t.get())+"\n"+S(n.content)+"\n</body>\n</html>").replace(/<!--mce:protected ([\s\S]*?)-->/g,((e,t)=>unescape(t))))}))})(e,t),(e=>{const t=e.options.register;t("fullpagehtml_default_doctype",{processor:"string",default:"<!DOCTYPE html>"}),t("fullpagehtml_hide_in_source_view",{processor:"boolean",default:!1}),t("fullpagehtml_default_encoding",{processor:"string"}),t("fullpagehtml_default_body_style",{processor:"string"}),t("fullpagehtml_default_title",{processor:"string"})})(e),((e,t)=>{e.addCommand("mceFullPageHtmlProperties",(()=>{((e,t)=>{const n=_e(e,t.get(),!0),o={title:n.title.getOr(""),keywords:n.keywords.getOr(""),description:n.description.getOr(""),robots:n.robots.getOr(""),author:n.author.getOr(""),encoding:n.encoding.getOr("")};e.windowManager.open({title:"Metadata and Document Properties",size:"normal",body:{type:"panel",items:[{name:"title",type:"input",label:"Title"},{name:"keywords",type:"input",label:"Keywords"},{name:"description",type:"input",label:"Description"},{name:"robots",type:"input",label:"Robots"},{name:"author",type:"input",label:"Author"},{name:"encoding",type:"input",label:"Encoding"}]},buttons:[{type:"cancel",name:"cancel",text:"Cancel"},{type:"submit",name:"save",text:"Save",primary:!0}],initialData:o,onSubmit:o=>{const r=o.getData(),s={...n,title:""===r.title?m.none():m.from(r.title),keywords:""===r.keywords?m.none():m.from(r.keywords),description:""===r.description?m.none():m.from(r.description),robots:""===r.robots?m.none():m.from(r.robots),author:""===r.author?m.none():m.from(r.author),encoding:""===r.encoding?m.none():m.from(r.encoding)};ze(e,Me(s,t.get())+Ne(n,t.get()),t,!0),o.close()}})})(e,t)}))})(e,t),(e=>{e.ui.registry.addButton("fullpagehtml",{tooltip:Be,icon:"document-gear-properties",onAction:()=>{e.execCommand("mceFullPageHtmlProperties")}}),e.ui.registry.addMenuItem("fullpagehtml",{text:Be,icon:"document-gear-properties",onAction:()=>{e.execCommand("mceFullPageHtmlProperties")}})})(e),{}}})}(); |