WordPress/wp-includes/js/dist/rich-text.min.js

2 lines
33 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*! This file is auto-generated */
!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{__UNSTABLE_LINE_SEPARATOR:function(){return x},__experimentalRichText:function(){return Ze},__unstableCreateElement:function(){return E},__unstableFormatEdit:function(){return Je},__unstableInsertLineSeparator:function(){return G},__unstableIsEmptyLine:function(){return B},__unstableToDom:function(){return pe},__unstableUseRichText:function(){return Ge},applyFormat:function(){return T},concat:function(){return W},create:function(){return F},getActiveFormat:function(){return M},getActiveFormats:function(){return k},getActiveObject:function(){return $},getTextContent:function(){return P},insert:function(){return K},insertObject:function(){return Z},isCollapsed:function(){return V},isEmpty:function(){return I},join:function(){return H},registerFormatType:function(){return z},remove:function(){return X},removeFormat:function(){return U},replace:function(){return Y},slice:function(){return J},split:function(){return Q},store:function(){return h},toHTMLString:function(){return ye},toggleFormat:function(){return Le},unregisterFormatType:function(){return De},useAnchor:function(){return $e},useAnchorRef:function(){return Me}});var n={};e.r(n),e.d(n,{getFormatType:function(){return f},getFormatTypeForBareElement:function(){return d},getFormatTypeForClassName:function(){return m},getFormatTypes:function(){return u}});var r={};e.r(r),e.d(r,{addFormatTypes:function(){return p},removeFormatTypes:function(){return g}});var a=window.wp.data,o=window.lodash;var i=(0,a.combineReducers)({formatTypes:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;switch(t.type){case"ADD_FORMAT_TYPES":return{...e,...t.formatTypes.reduce(((e,t)=>({...e,[t.name]:t})),{})};case"REMOVE_FORMAT_TYPES":return(0,o.omit)(e,t.names)}return e}}),s={};function c(e){return[e]}function l(e,t,n){var r;if(e.length!==t.length)return!1;for(r=n;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}const u=function(e,t){var n,r=t||c;function a(e){var t,r,a,o,i,c=n,l=!0;for(t=0;t<e.length;t++){if(r=e[t],!(i=r)||"object"!=typeof i){l=!1;break}c.has(r)?c=c.get(r):(a=new WeakMap,c.set(r,a),c=a)}return c.has(s)||((o=function(){var e={clear:function(){e.head=null}};return e}()).isUniqueByDependants=l,c.set(s,o)),c.get(s)}function o(){n=new WeakMap}function i(){var t,n,o,i,s,c=arguments.length;for(i=new Array(c),o=0;o<c;o++)i[o]=arguments[o];for((t=a(s=r.apply(null,i))).isUniqueByDependants||(t.lastDependants&&!l(s,t.lastDependants,0)&&t.clear(),t.lastDependants=s),n=t.head;n;){if(l(n.args,i,1))return n!==t.head&&(n.prev.next=n.next,n.next&&(n.next.prev=n.prev),n.next=t.head,n.prev=null,t.head.prev=n,t.head=n),n.val;n=n.next}return n={val:e.apply(null,i)},i[0]=null,n.args=i,t.head&&(t.head.prev=n,n.next=t.head),t.head=n,n.val}return i.getDependants=r,i.clear=o,o(),i}((e=>Object.values(e.formatTypes)),(e=>[e.formatTypes]));function f(e,t){return e.formatTypes[t]}function d(e,t){return(0,o.find)(u(e),(e=>{let{className:n,tagName:r}=e;return null===n&&t===r}))}function m(e,t){return(0,o.find)(u(e),(e=>{let{className:n}=e;return null!==n&&` ${t} `.indexOf(` ${n} `)>=0}))}function p(e){return{type:"ADD_FORMAT_TYPES",formatTypes:(0,o.castArray)(e)}}function g(e){return{type:"REMOVE_FORMAT_TYPES",names:(0,o.castArray)(e)}}const h=(0,a.createReduxStore)("core/rich-text",{reducer:i,selectors:n,actions:r});function v(e,t){if(e===t)return!0;if(!e||!t)return!1;if(e.type!==t.type)return!1;const n=e.attributes,r=t.attributes;if(n===r)return!0;if(!n||!r)return!1;const a=Object.keys(n),o=Object.keys(r);if(a.length!==o.length)return!1;const i=a.length;for(let e=0;e<i;e++){const t=a[e];if(n[t]!==r[t])return!1}return!0}function y(e){const t=e.formats.slice();return t.forEach(((e,n)=>{const r=t[n-1];if(r){const a=e.slice();a.forEach(((e,t)=>{const n=r[t];v(e,n)&&(a[t]=n)})),t[n]=a}})),{...e,formats:t}}function b(e,t,n){return(e=e.slice())[t]=n,e}function T(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.start,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e.end;const{formats:a,activeFormats:o}=e,i=a.slice();if(n===r){var s;const e=null===(s=i[n])||void 0===s?void 0:s.find((e=>{let{type:n}=e;return n===t.type}));if(e){const a=i[n].indexOf(e);for(;i[n]&&i[n][a]===e;)i[n]=b(i[n],a,t),n--;for(r++;i[r]&&i[r][a]===e;)i[r]=b(i[r],a,t),r++}}else{let e=1/0;for(let a=n;a<r;a++)if(i[a]){i[a]=i[a].filter((e=>{let{type:n}=e;return n!==t.type}));const n=i[a].length;n<e&&(e=n)}else i[a]=[],e=0;for(let a=n;a<r;a++)i[a].splice(e,0,t)}return y({...e,formats:i,activeFormats:[...(null==o?void 0:o.filter((e=>{let{type:n}=e;return n!==t.type})))||[],t]})}function E(e,t){let{implementation:n}=e;return E.body||(E.body=n.createHTMLDocument("").body),E.body.innerHTML=t,E.body}(0,a.register)(h);const x="\u2028",w="";function _(e){let t,{type:n,attributes:r}=e;if(r&&r.class&&(t=(0,a.select)(h).getFormatTypeForClassName(r.class),t&&(r.class=` ${r.class} `.replace(` ${t.className} `," ").trim(),r.class||delete r.class)),t||(t=(0,a.select)(h).getFormatTypeForBareElement(n)),!t)return r?{type:n,attributes:r}:{type:n};if(t.__experimentalCreatePrepareEditableTree&&!t.__experimentalCreateOnChangeEditableValue)return null;if(!r)return{type:t.name};const o={},i={},s={...r};for(const e in t.attributes){const n=t.attributes[e];o[e]=s[n],t.__unstableFilterAttributeValue&&(o[e]=t.__unstableFilterAttributeValue(e,o[e])),delete s[n],void 0===o[e]&&delete o[e]}for(const e in s)i[e]=r[e];return{type:t.name,attributes:o,unregisteredAttributes:i}}function F(){let{element:e,text:t,html:n,range:r,multilineTag:a,multilineWrapperTags:o,__unstableIsEditableTree:i,preserveWhiteSpace:s}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return"string"==typeof t&&t.length>0?{formats:Array(t.length),replacements:Array(t.length),text:t}:("string"==typeof n&&n.length>0&&(e=E(document,n)),"object"!=typeof e?{formats:[],replacements:[],text:""}:a?L({element:e,range:r,multilineTag:a,multilineWrapperTags:o,isEditableTree:i,preserveWhiteSpace:s}):S({element:e,range:r,isEditableTree:i,preserveWhiteSpace:s}))}function C(e,t,n,r){if(!n)return;const{parentNode:a}=t,{startContainer:o,startOffset:i,endContainer:s,endOffset:c}=n,l=e.text.length;void 0!==r.start?e.start=l+r.start:t===o&&t.nodeType===t.TEXT_NODE?e.start=l+i:a===o&&t===o.childNodes[i]?e.start=l:a===o&&t===o.childNodes[i-1]?e.start=l+r.text.length:t===o&&(e.start=l),void 0!==r.end?e.end=l+r.end:t===s&&t.nodeType===t.TEXT_NODE?e.end=l+c:a===s&&t===s.childNodes[c-1]?e.end=l+r.text.length:a===s&&t===s.childNodes[c]?e.end=l:t===s&&(e.end=l+c)}function N(e,t,n){if(!t)return;const{startContainer:r,endContainer:a}=t;let{startOffset:o,endOffset:i}=t;return e===r&&(o=n(e.nodeValue.slice(0,o)).length),e===a&&(i=n(e.nodeValue.slice(0,i)).length),{startContainer:r,startOffset:o,endContainer:a,endOffset:i}}function A(e){return e.replace(/[\n\r\t]+/g," ")}function R(e){return e.replace(new RegExp("[\ufeff]","gu"),"")}function S(e){let{element:t,range:n,multilineTag:r,multilineWrapperTags:a,currentWrapperTags:o=[],isEditableTree:i,preserveWhiteSpace:s}=e;const c={formats:[],replacements:[],text:""};if(!t)return c;if(!t.hasChildNodes())return C(c,t,n,{formats:[],replacements:[],text:""}),c;const l=t.childNodes.length;for(let u=0;u<l;u++){const f=t.childNodes[u],d=f.nodeName.toLowerCase();if(f.nodeType===f.TEXT_NODE){let g=R;s||(g=e=>R(A(e)));const h=g(f.nodeValue);n=N(f,n,g),C(c,f,n,{text:h}),c.formats.length+=h.length,c.replacements.length+=h.length,c.text+=h;continue}if(f.nodeType!==f.ELEMENT_NODE)continue;if(i&&(f.getAttribute("data-rich-text-placeholder")||"br"===d&&!f.getAttribute("data-rich-text-line-break"))){C(c,f,n,{formats:[],replacements:[],text:""});continue}if("script"===d){const v={formats:[,],replacements:[{type:d,attributes:{"data-rich-text-script":f.getAttribute("data-rich-text-script")||encodeURIComponent(f.innerHTML)}}],text:w};C(c,f,n,v),O(c,v);continue}if("br"===d){C(c,f,n,{formats:[],replacements:[],text:""}),O(c,F({text:"\n"}));continue}const m=_({type:d,attributes:D({element:f})});if(a&&-1!==a.indexOf(d)){const y=L({element:f,range:n,multilineTag:r,multilineWrapperTags:a,currentWrapperTags:[...o,m],isEditableTree:i,preserveWhiteSpace:s});C(c,f,n,y),O(c,y);continue}const p=S({element:f,range:n,multilineTag:r,multilineWrapperTags:a,isEditableTree:i,preserveWhiteSpace:s});if(C(c,f,n,p),m)if(0===p.text.length)m.attributes&&O(c,{formats:[,],replacements:[m],text:w});else{function b(e){if(b.formats===e)return b.newFormats;const t=e?[m,...e]:[m];return b.formats=e,b.newFormats=t,t}b.newFormats=[m],O(c,{...p,formats:Array.from(p.formats,b)})}else O(c,p)}return c}function L(e){let{element:t,range:n,multilineTag:r,multilineWrapperTags:a,currentWrapperTags:o=[],isEditableTree:i,preserveWhiteSpace:s}=e;const c={formats:[],replacements:[],text:""};if(!t||!t.hasChildNodes())return c;const l=t.children.length;for(let e=0;e<l;e++){const l=t.children[e];if(l.nodeName.toLowerCase()!==r)continue;const u=S({element:l,range:n,multilineTag:r,multilineWrapperTags:a,currentWrapperTags:o,isEditableTree:i,preserveWhiteSpace:s});(0!==e||o.length>0)&&O(c,{formats:[,],replacements:o.length>0?[o]:[,],text:x}),C(c,l,n,u),O(c,u)}return c}function D(e){let{element:t}=e;if(!t.hasAttributes())return;const n=t.attributes.length;let r;for(let e=0;e<n;e++){const{name:n,value:a}=t.attributes[e];if(0===n.indexOf("data-rich-text-"))continue;r=r||{},r[/^on/i.test(n)?"data-disable-rich-text-"+n:n]=a}return r}function O(e,t){return e.formats=e.formats.concat(t.formats),e.replacements=e.replacements.concat(t.replacements),e.text+=t.text,e}function W(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return y(t.reduce(O,F()))}function k(e){let{formats:t,start:n,end:r,activeFormats:a}=e,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(void 0===n)return o;if(n===r){if(a)return a;const e=t[n-1]||o,r=t[n]||o;return e.length<r.length?e:r}return t[n]||o}function M(e,t){return(0,o.find)(k(e),{type:t})}function $(e){let{start:t,end:n,replacements:r,text:a}=e;if(t+1===n&&a[t]===w)return r[t]}const j=new RegExp(`[${x}]`,"g");function P(e){let{text:t}=e;return t.replace(j,(e=>e===w?"":"\n"))}function V(e){let{start:t,end:n}=e;if(void 0!==t&&void 0!==n)return t===n}function I(e){let{text:t}=e;return 0===t.length}function B(e){let{text:t,start:n,end:r}=e;return n===r&&(0===t.length||(0===n&&t.slice(0,1)===x||(n===t.length&&t.slice(-1)===x||t.slice(n-1,r+1)===`${x}${x}`)))}function H(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"string"==typeof t&&(t=F({text:t})),y(e.reduce(((e,n)=>{let{formats:r,replacements:a,text:o}=n;return{formats:e.formats.concat(t.formats,r),replacements:e.replacements.concat(t.replacements,a),text:e.text+t.text+o}})))}function z(e,t){if("string"==typeof(t={name:e,...t}).name)if(/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(t.name))if((0,a.select)(h).getFormatType(t.name))window.console.error('Format "'+t.name+'" is already registered.');else if("string"==typeof t.tagName&&""!==t.tagName)if("string"==typeof t.className&&""!==t.className||null===t.className)if(/^[_a-zA-Z]+[a-zA-Z0-9-]*$/.test(t.className)){if(null===t.className){const e=(0,a.select)(h).getFormatTypeForBareElement(t.tagName);if(e)return void window.console.error(`Format "${e.name}" is already registered to handle bare tag name "${t.tagName}".`)}else{const e=(0,a.select)(h).getFormatTypeForClassName(t.className);if(e)return void window.console.error(`Format "${e.name}" is already registered to handle class name "${t.className}".`)}if("title"in t&&""!==t.title)if("keywords"in t&&t.keywords.length>3)window.console.error('The format "'+t.name+'" can have a maximum of 3 keywords.');else{if("string"==typeof t.title)return(0,a.dispatch)(h).addFormatTypes(t),t;window.console.error("Format titles must be strings.")}else window.console.error('The format "'+t.name+'" must have a title.')}else window.console.error("A class name must begin with a letter, followed by any number of hyphens, letters, or numbers.");else window.console.error("Format class names must be a string, or null to handle bare elements.");else window.console.error("Format tag names must be a string.");else window.console.error("Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format");else window.console.error("Format names must be strings.")}function U(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.start,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e.end;const{formats:a,activeFormats:o}=e,i=a.slice();if(n===r){var s;const e=null===(s=i[n])||void 0===s?void 0:s.find((e=>{let{type:n}=e;return n===t}));if(e){for(;null!==(c=i[n])&&void 0!==c&&c.find((t=>t===e));){var c;q(i,n,t),n--}for(r++;null!==(l=i[r])&&void 0!==l&&l.find((t=>t===e));){var l;q(i,r,t),r++}}}else for(let e=n;e<r;e++)i[e]&&q(i,e,t);return y({...e,formats:i,activeFormats:(null==o?void 0:o.filter((e=>{let{type:n}=e;return n!==t})))||[]})}function q(e,t,n){const r=e[t].filter((e=>{let{type:t}=e;return t!==n}));r.length?e[t]=r:delete e[t]}function K(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.start,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e.end;const{formats:a,replacements:o,text:i}=e;"string"==typeof t&&(t=F({text:t}));const s=n+t.text.length;return y({formats:a.slice(0,n).concat(t.formats,a.slice(r)),replacements:o.slice(0,n).concat(t.replacements,o.slice(r)),text:i.slice(0,n)+t.text+i.slice(r),start:s,end:s})}function X(e,t,n){return K(e,F(),t,n)}function Y(e,t,n){let{formats:r,replacements:a,text:o,start:i,end:s}=e;return o=o.replace(t,(function(e){for(var t=arguments.length,o=new Array(t>1?t-1:0),c=1;c<t;c++)o[c-1]=arguments[c];const l=o[o.length-2];let u,f,d=n;return"function"==typeof d&&(d=n(e,...o)),"object"==typeof d?(u=d.formats,f=d.replacements,d=d.text):(u=Array(d.length),f=Array(d.length),r[l]&&(u=u.fill(r[l]))),r=r.slice(0,l).concat(u,r.slice(l+e.length)),a=a.slice(0,l).concat(f,a.slice(l+e.length)),i&&(i=s=l+d.length),d})),y({formats:r,replacements:a,text:o,start:i,end:s})}function G(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.start,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.end;const r=e.text.slice(0,t),a=r.lastIndexOf(x),o=e.replacements[a];let i=[,];o&&(i=[o]);const s={formats:[,],replacements:i,text:x};return K(e,s,t,n)}function Z(e,t,n,r){return K(e,{formats:[,],replacements:[t],text:w},n,r)}function J(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.start,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.end;const{formats:r,replacements:a,text:o}=e;return void 0===t||void 0===n?{...e}:{formats:r.slice(t,n),replacements:a.slice(t,n),text:o.slice(t,n)}}function Q(e,t){let{formats:n,replacements:r,text:a,start:o,end:i}=e;if("string"!=typeof t)return ee(...arguments);let s=0;return a.split(t).map((e=>{const a=s,c={formats:n.slice(a,a+e.length),replacements:r.slice(a,a+e.length),text:e};return s+=t.length+e.length,void 0!==o&&void 0!==i&&(o>=a&&o<s?c.start=o-a:o<a&&i>a&&(c.start=0),i>=a&&i<s?c.end=i-a:o<s&&i>s&&(c.end=e.length)),c}))}function ee(e){let{formats:t,replacements:n,text:r,start:a,end:o}=e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o;if(void 0===a||void 0===o)return;const c={formats:t.slice(0,i),replacements:n.slice(0,i),text:r.slice(0,i)},l={formats:t.slice(s),replacements:n.slice(s),text:r.slice(s),start:0,end:0};return[Y(c,/\u2028+$/,""),Y(l,/^\u2028+/,"")]}function te(e,t){if(t)return e;const n={};for(const t in e){let r=t;t.startsWith("data-disable-rich-text-")&&(r=t.slice("data-disable-rich-text-".length)),n[r]=e[t]}return n}function ne(e){let{type:t,attributes:n,unregisteredAttributes:r,object:o,boundaryClass:i,isEditableTree:s}=e;const c=(l=t,(0,a.select)(h).getFormatType(l));var l;let u={};if(i&&(u["data-rich-text-format-boundary"]="true"),!c)return n&&(u={...n,...u}),{type:t,attributes:te(u,s),object:o};u={...r,...u};for(const e in n){const t=!!c.attributes&&c.attributes[e];t?u[t]=n[e]:u[e]=n[e]}return c.className&&(u.class?u.class=`${c.className} ${u.class}`:u.class=c.className),{type:c.tagName,object:c.object,attributes:te(u,s)}}function re(e,t,n){do{if(e[n]!==t[n])return!1}while(n--);return!0}function ae(e){let{value:t,multilineTag:n,preserveWhiteSpace:r,createEmpty:a,append:o,getLastChild:i,getParent:s,isText:c,getText:l,remove:u,appendText:f,onStartIndex:d,onEndIndex:m,isEditableTree:p,placeholder:g}=e;const{formats:h,replacements:v,text:y,start:b,end:T}=t,E=h.length+1,_=a(),F={type:n},C=k(t),N=C[C.length-1];let A,R,S;n?(o(o(_,{type:n}),""),R=A=[F]):o(_,"");for(let e=0;e<E;e++){const t=y.charAt(e),a=p&&(!S||S===x||"\n"===S);let E=h[e];n&&(E=t===x?A=(v[e]||[]).reduce(((e,t)=>(e.push(t,F),e)),[F]):[...A,...E||[]]);let C=i(_);if(a&&t===x){let e=C;for(;!c(e);)e=i(e);o(s(e),"\ufeff")}if(S===x){let t=C;for(;!c(t);)t=i(t);d&&b===e&&d(_,t),m&&T===e&&m(_,t)}if(E&&E.forEach(((e,n)=>{if(C&&R&&re(E,R,n)&&(t!==x||E.length-1!==n))return void(C=i(C));const{type:r,attributes:a,unregisteredAttributes:f}=e,d=p&&t!==x&&e===N,m=s(C),g=o(m,ne({type:r,attributes:a,unregisteredAttributes:f,boundaryClass:d,isEditableTree:p}));c(C)&&0===l(C).length&&u(C),C=o(g,"")})),t!==x){var L;if(0===e&&(d&&0===b&&d(_,C),m&&0===T&&m(_,C)),t===w)p||"script"!==(null===(L=v[e])||void 0===L?void 0:L.type)?C=o(s(C),ne({...v[e],object:!0,isEditableTree:p})):(C=o(s(C),ne({type:"script",isEditableTree:p})),o(C,{html:decodeURIComponent(v[e].attributes["data-rich-text-script"])})),C=o(s(C),"");else r||"\n"!==t?c(C)?f(C,t):C=o(s(C),t):(C=o(s(C),{type:"br",attributes:p?{"data-rich-text-line-break":"true"}:void 0,object:!0}),C=o(s(C),""));d&&b===e+1&&d(_,C),m&&T===e+1&&m(_,C),a&&e===y.length&&(o(s(C),"\ufeff"),g&&0===y.length&&o(s(C),{type:"span",attributes:{"data-rich-text-placeholder":g,contenteditable:"false",style:"pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;"}})),R=E,S=t}else R=E,S=t}return _}function oe(e,t,n){const r=e.parentNode;let a=0;for(;e=e.previousSibling;)a++;return n=[a,...n],r!==t&&(n=oe(r,t,n)),n}function ie(e,t){for(t=[...t];e&&t.length>1;)e=e.childNodes[t.shift()];return{node:e,offset:t[0]}}function se(e,t){"string"==typeof t&&(t=e.ownerDocument.createTextNode(t));const{type:n,attributes:r}=t;if(n){t=e.ownerDocument.createElement(n);for(const e in r)t.setAttribute(e,r[e])}return e.appendChild(t)}function ce(e,t){e.appendData(t)}function le(e){let{lastChild:t}=e;return t}function ue(e){let{parentNode:t}=e;return t}function fe(e){return e.nodeType===e.TEXT_NODE}function de(e){let{nodeValue:t}=e;return t}function me(e){return e.parentNode.removeChild(e)}function pe(e){let{value:t,multilineTag:n,prepareEditableTree:r,isEditableTree:a=!0,placeholder:o,doc:i=document}=e,s=[],c=[];r&&(t={...t,formats:r(t)});return{body:ae({value:t,multilineTag:n,createEmpty:()=>E(i,""),append:se,getLastChild:le,getParent:ue,isText:fe,getText:de,remove:me,appendText:ce,onStartIndex(e,t){s=oe(t,e,[t.nodeValue.length])},onEndIndex(e,t){c=oe(t,e,[t.nodeValue.length])},isEditableTree:a,placeholder:o}),selection:{startPath:s,endPath:c}}}function ge(e){let{value:t,current:n,multilineTag:r,prepareEditableTree:a,__unstableDomOnly:o,placeholder:i}=e;const{body:s,selection:c}=pe({value:t,multilineTag:r,prepareEditableTree:a,placeholder:i,doc:n.ownerDocument});he(s,n),void 0===t.start||o||function(e,t){let{startPath:n,endPath:r}=e;const{node:a,offset:o}=ie(t,n),{node:i,offset:s}=ie(t,r),{ownerDocument:c}=t,{defaultView:l}=c,u=l.getSelection(),f=c.createRange();f.setStart(a,o),f.setEnd(i,s);const{activeElement:d}=c;if(u.rangeCount>0){if(m=f,p=u.getRangeAt(0),m.startContainer===p.startContainer&&m.startOffset===p.startOffset&&m.endContainer===p.endContainer&&m.endOffset===p.endOffset)return;u.removeAllRanges()}var m,p;u.addRange(f),d!==c.activeElement&&d instanceof l.HTMLElement&&d.focus()}(c,n)}function he(e,t){let n,r=0;for(;n=e.firstChild;){const a=t.childNodes[r];if(a)if(a.isEqualNode(n))e.removeChild(n);else if(a.nodeName!==n.nodeName||a.nodeType===a.TEXT_NODE&&a.data!==n.data)t.replaceChild(n,a);else{const t=a.attributes,r=n.attributes;if(t){let e=t.length;for(;e--;){const{name:r}=t[e];n.getAttribute(r)||a.removeAttribute(r)}}if(r)for(let e=0;e<r.length;e++){const{name:t,value:n}=r[e];a.getAttribute(t)!==n&&a.setAttribute(t,n)}he(n,a),e.removeChild(n)}else t.appendChild(n);r++}for(;t.childNodes[r];)t.removeChild(t.childNodes[r])}var ve=window.wp.escapeHtml;function ye(e){let{value:t,multilineTag:n,preserveWhiteSpace:r}=e;return Ae(ae({value:t,multilineTag:n,preserveWhiteSpace:r,createEmpty:be,append:Ee,getLastChild:Te,getParent:we,isText:_e,getText:Fe,remove:Ce,appendText:xe}).children)}function be(){return{}}function Te(e){let{children:t}=e;return t&&t[t.length-1]}function Ee(e,t){return"string"==typeof t&&(t={text:t}),t.parent=e,e.children=e.children||[],e.children.push(t),t}function xe(e,t){e.text+=t}function we(e){let{parent:t}=e;return t}function _e(e){let{text:t}=e;return"string"==typeof t}function Fe(e){let{text:t}=e;return t}function Ce(e){const t=e.parent.children.indexOf(e);return-1!==t&&e.parent.children.splice(t,1),e}function Ne(e){let{type:t,attributes:n,object:r,children:a}=e,o="";for(const e in n)(0,ve.isValidAttributeName)(e)&&(o+=` ${e}="${(0,ve.escapeAttribute)(n[e])}"`);return r?`<${t}${o}>`:`<${t}${o}>${Ae(a)}</${t}>`}function Ae(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e.map((e=>void 0!==e.html?e.html:void 0===e.text?Ne(e):(0,ve.escapeEditableHTML)(e.text))).join("")}var Re=window.wp.a11y,Se=window.wp.i18n;function Le(e,t){return M(e,t.type)?(t.title&&(0,Re.speak)((0,Se.sprintf)((0,Se.__)("%s removed."),t.title),"assertive"),U(e,t.type)):(t.title&&(0,Re.speak)((0,Se.sprintf)((0,Se.__)("%s applied."),t.title),"assertive"),T(e,t))}function De(e){const t=(0,a.select)(h).getFormatType(e);if(t)return(0,a.dispatch)(h).removeFormatTypes(e),t;window.console.error(`Format ${e} is not registered.`)}var Oe=window.wp.element,We=window.wp.deprecated,ke=e.n(We);function Me(e){let{ref:t,value:n,settings:r={}}=e;ke()("`useAnchorRef` hook",{since:"6.1",version:"6.3",alternative:"`useAnchor` hook"});const{tagName:a,className:o,name:i}=r,s=i?M(n,i):void 0;return(0,Oe.useMemo)((()=>{if(!t.current)return;const{ownerDocument:{defaultView:e}}=t.current,n=e.getSelection();if(!n.rangeCount)return;const r=n.getRangeAt(0);if(!s)return r;let i=r.startContainer;for(i=i.nextElementSibling||i;i.nodeType!==i.ELEMENT_NODE;)i=i.parentNode;return i.closest(a+(o?"."+o:""))}),[s,n.start,n.end,a,o])}function $e(e){let{editableContentElement:t,value:n,settings:r={}}=e;const{tagName:a,className:o,name:i}=r,s=i?M(n,i):void 0;return(0,Oe.useMemo)((()=>{if(!t)return;const{ownerDocument:{defaultView:e}}=t,n=e.getSelection();if(!n.rangeCount)return;const r=n.getRangeAt(0);if(!s)return{ownerDocument:r.startContainer.ownerDocument,getBoundingClientRect(){return r.getBoundingClientRect()}};let i=r.startContainer;for(i=i.nextElementSibling||i;i.nodeType!==i.ELEMENT_NODE;)i=i.parentNode;return i.closest(a+(o?"."+o:""))}),[t,s,n.start,n.end,a,o])}var je=window.wp.compose;function Pe(e){let{record:t}=e;const n=(0,Oe.useRef)(),{activeFormats:r=[]}=t.current;return(0,Oe.useEffect)((()=>{if(!r||!r.length)return;const e="*[data-rich-text-format-boundary]",t=n.current.querySelector(e);if(!t)return;const{ownerDocument:a}=t,{defaultView:o}=a,i=`${`.rich-text:focus ${e}`} {${`background-color: ${o.getComputedStyle(t).color.replace(")",", 0.2)").replace("rgb","rgba")}`}}`,s="rich-text-boundary-style";let c=a.getElementById(s);c||(c=a.createElement("style"),c.id=s,a.head.appendChild(c)),c.innerHTML!==i&&(c.innerHTML=i)}),[r]),n}function Ve(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,je.useRefEffect)((e=>{function n(n){const{record:r,multilineTag:a,preserveWhiteSpace:o}=t.current;if(V(r.current)||!e.contains(e.ownerDocument.activeElement))return;const i=J(r.current),s=P(i),c=ye({value:i,multilineTag:a,preserveWhiteSpace:o});n.clipboardData.setData("text/plain",s),n.clipboardData.setData("text/html",c),n.clipboardData.setData("rich-text","true"),n.clipboardData.setData("rich-text-multi-line-tag",a||""),n.preventDefault()}return e.addEventListener("copy",n),()=>{e.removeEventListener("copy",n)}}),[])}var Ie=window.wp.keycodes;const Be=[];function He(e){const[,t]=(0,Oe.useReducer)((()=>({}))),n=(0,Oe.useRef)(e);return n.current=e,(0,je.useRefEffect)((e=>{function r(r){const{keyCode:a,shiftKey:o,altKey:i,metaKey:s,ctrlKey:c}=r;if(o||i||s||c||a!==Ie.LEFT&&a!==Ie.RIGHT)return;const{record:l,applyRecord:u}=n.current,{text:f,formats:d,start:m,end:p,activeFormats:g=[]}=l.current,h=V(l.current),{ownerDocument:v}=e,{defaultView:y}=v,{direction:b}=y.getComputedStyle(e),T="rtl"===b?Ie.RIGHT:Ie.LEFT,E=r.keyCode===T;if(h&&0===g.length){if(0===m&&E)return;if(p===f.length&&!E)return}if(!h)return;const x=d[m-1]||Be,w=d[m]||Be,_=E?x:w,F=g.every(((e,t)=>e===_[t]));let C=g.length;if(F?C<_.length&&C++:C--,C===g.length)return void(l.current._newActiveFormats=_);r.preventDefault();const N=(F?_:E?w:x).slice(0,C),A={...l.current,activeFormats:N};l.current=A,u(A),t()}return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}}),[])}const ze=new Set(["insertParagraph","insertOrderedList","insertUnorderedList","insertHorizontalRule","insertLink"]),Ue=[],qe="data-rich-text-placeholder";function Ke(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,je.useRefEffect)((e=>{const{ownerDocument:n}=e,{defaultView:r}=n;let a,o=!1;function i(e){if(o)return;let n;e&&(n=e.inputType);const{record:r,applyRecord:a,createRecord:i,handleChange:s}=t.current;if(n&&(0===n.indexOf("format")||ze.has(n)))return void a(r.current);const c=i(),{start:l,activeFormats:u=[]}=r.current,f=function(e){let{value:t,start:n,end:r,formats:a}=e;const o=Math.min(n,r),i=Math.max(n,r),s=t.formats[o-1]||[],c=t.formats[i]||[];for(t.activeFormats=a.map(((e,t)=>{if(s[t]){if(v(e,s[t]))return s[t]}else if(c[t]&&v(e,c[t]))return c[t];return e}));--r>=n;)t.activeFormats.length>0?t.formats[r]=t.activeFormats:delete t.formats[r];return t}({value:c,start:l,end:c.start,formats:u});s(f)}function s(a){const{record:s,applyRecord:c,createRecord:l,isSelected:u,onSelectionChange:f}=t.current;if("true"!==e.contentEditable)return;if(n.activeElement!==e){if("true"!==n.activeElement.contentEditable)return;if(!n.activeElement.contains(e))return;const t=r.getSelection(),{anchorNode:a,focusNode:o}=t;if(e.contains(a)&&e!==a&&e.contains(o)&&e!==o){const{start:e,end:t}=l();s.current.activeFormats=Ue,f(e,t)}else if(e.contains(a)&&e!==a){const{start:e,end:t=e}=l();s.current.activeFormats=Ue,f(t)}else if(e.contains(o)){const{start:e,end:t=e}=l();s.current.activeFormats=Ue,f(void 0,t)}return}if("selectionchange"!==a.type&&!u)return;if(o)return;const{start:d,end:m,text:p}=l(),g=s.current;if(p!==g.text)return void i();if(d===g.start&&m===g.end)return void(0===g.text.length&&0===d&&function(e){const t=e.getSelection(),{anchorNode:n,anchorOffset:r}=t;if(n.nodeType!==n.ELEMENT_NODE)return;const a=n.childNodes[r];a&&a.nodeType===a.ELEMENT_NODE&&a.hasAttribute(qe)&&t.collapseToStart()}(r));const h={...g,start:d,end:m,activeFormats:g._newActiveFormats,_newActiveFormats:void 0},v=k(h,Ue);h.activeFormats=v,s.current=h,c(h,{domOnly:!0}),f(d,m)}function c(){var t;o=!0,n.removeEventListener("selectionchange",s),null===(t=e.querySelector(`[${qe}]`))||void 0===t||t.remove()}function l(){o=!1,i({inputType:"insertText"}),n.addEventListener("selectionchange",s)}function u(){const{record:n,isSelected:o,onSelectionChange:i,applyRecord:c}=t.current;if(!e.parentElement.closest('[contenteditable="true"]')){if(o)c(n.current),i(n.current.start,n.current.end);else{const e=void 0;n.current={...n.current,start:e,end:e,activeFormats:Ue},i(e,e)}a=r.requestAnimationFrame(s)}}return e.addEventListener("input",i),e.addEventListener("compositionstart",c),e.addEventListener("compositionend",l),e.addEventListener("focus",u),e.addEventListener("keyup",s),e.addEventListener("mouseup",s),e.addEventListener("touchend",s),n.addEventListener("selectionchange",s),()=>{e.removeEventListener("input",i),e.removeEventListener("compositionstart",c),e.removeEventListener("compositionend",l),e.removeEventListener("focus",u),e.removeEventListener("keyup",s),e.removeEventListener("mouseup",s),e.removeEventListener("touchend",s),n.removeEventListener("selectionchange",s),r.cancelAnimationFrame(a)}}),[])}function Xe(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const{replacements:n,text:r,start:a,end:o}=e,i=V(e);let s,c=a-1,l=i?a-1:a,u=o;if(t||(c=o,l=a,u=i?o+1:o),r[c]===x){if(i&&n[c]&&n[c].length){const t=n.slice();t[c]=n[c].slice(0,-1),s={...e,replacements:t}}else s=X(e,l,u);return s}}function Ye(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,je.useRefEffect)((e=>{function n(e){const{keyCode:n}=e,{createRecord:r,handleChange:a,multilineTag:o}=t.current;if(e.defaultPrevented)return;if(n!==Ie.DELETE&&n!==Ie.BACKSPACE)return;const i=r(),{start:s,end:c,text:l}=i,u=n===Ie.BACKSPACE;if(0===s&&0!==c&&c===l.length)return a(X(i)),void e.preventDefault();if(o){let t;t=u&&0===i.start&&0===i.end&&B(i)?Xe(i,!u):Xe(i,u),t&&(a(t),e.preventDefault())}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[])}function Ge(e){let{value:t="",selectionStart:n,selectionEnd:r,placeholder:o,preserveWhiteSpace:i,onSelectionChange:s,onChange:c,__unstableMultilineTag:l,__unstableDisableFormats:u,__unstableIsSelected:f,__unstableDependencies:d=[],__unstableAfterParse:m,__unstableBeforeSerialize:p,__unstableAddInvisibleFormats:g}=e;const h=(0,a.useRegistry)(),[,v]=(0,Oe.useReducer)((()=>({}))),y=(0,Oe.useRef)();function b(){const{ownerDocument:{defaultView:e}}=y.current,t=e.getSelection(),n=t.rangeCount>0?t.getRangeAt(0):null;return F({element:y.current,range:n,multilineTag:l,multilineWrapperTags:"li"===l?["ul","ol"]:void 0,__unstableIsEditableTree:!0,preserveWhiteSpace:i})}function T(e){let{domOnly:t}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ge({value:e,current:y.current,multilineTag:l,multilineWrapperTags:"li"===l?["ul","ol"]:void 0,prepareEditableTree:g,__unstableDomOnly:t,placeholder:o})}const E=(0,Oe.useRef)(t),x=(0,Oe.useRef)();function w(){E.current=t,x.current=F({html:t,multilineTag:l,multilineWrapperTags:"li"===l?["ul","ol"]:void 0,preserveWhiteSpace:i}),u&&(x.current.formats=Array(t.length),x.current.replacements=Array(t.length)),m&&(x.current.formats=m(x.current)),x.current.start=n,x.current.end=r}const _=(0,Oe.useRef)(!1);if(x.current)n===x.current.start&&r===x.current.end||(_.current=f,x.current={...x.current,start:n,end:r});else{var C,N,A;w();"core/text-color"===(null===(C=x.current)||void 0===C||null===(N=C.formats[0])||void 0===N||null===(A=N[0])||void 0===A?void 0:A.type)&&function(e){x.current=e,E.current=ye({value:p?{...e,formats:p(e)}:e,multilineTag:l,preserveWhiteSpace:i});const{formats:t,text:n}=e;h.batch((()=>{c(E.current,{__unstableFormats:t,__unstableText:n})})),v()}(x.current)}function R(e){x.current=e,T(e),E.current=u?e.text:ye({value:p?{...e,formats:p(e)}:e,multilineTag:l,preserveWhiteSpace:i});const{start:t,end:n,formats:r,text:a}=e;h.batch((()=>{s(t,n),c(E.current,{__unstableFormats:r,__unstableText:a})})),v()}function S(){w(),T(x.current)}const L=(0,Oe.useRef)(!1);(0,Oe.useLayoutEffect)((()=>{L.current&&t!==E.current&&(S(),v())}),[t]),(0,Oe.useLayoutEffect)((()=>{_.current&&(y.current.ownerDocument.activeElement!==y.current&&y.current.focus(),S(),_.current=!1)}),[_.current]);const D=(0,je.useMergeRefs)([y,(0,Oe.useCallback)((e=>{e&&(e.style.whiteSpace="pre-wrap",e.style.minWidth="1px")}),[]),Pe({record:x}),Ve({record:x,multilineTag:l,preserveWhiteSpace:i}),(0,je.useRefEffect)((e=>{function t(t){const{target:n}=t;if(n===e||n.textContent)return;const{ownerDocument:r}=n,{defaultView:a}=r,o=r.createRange(),i=a.getSelection();o.selectNode(n),i.removeAllRanges(),i.addRange(o)}return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}),[]),He({record:x,applyRecord:T}),Ye({createRecord:b,handleChange:R,multilineTag:l}),Ke({record:x,applyRecord:T,createRecord:b,handleChange:R,isSelected:f,onSelectionChange:s}),(0,je.useRefEffect)((()=>{S(),L.current=!0}),[o,...d])]);return{value:x.current,onChange:R,ref:D}}function Ze(){}function Je(e){let{formatTypes:t,onChange:n,onFocus:r,value:a,forwardedRef:o}=e;return t.map((e=>{const{name:t,edit:i}=e;if(!i)return null;const s=M(a,t),c=void 0!==s,l=$(a),u=void 0!==l&&l.type===t;return(0,Oe.createElement)(i,{key:t,isActive:c,activeAttributes:c&&s.attributes||{},isObjectActive:u,activeObjectAttributes:u&&l.attributes||{},value:a,onChange:n,onFocus:r,contentRef:o})}))}(window.wp=window.wp||{}).richText=t}();