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

2 lines
30 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 */
(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(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:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r: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,{RichTextData:()=>B,__experimentalRichText:()=>Ge,__unstableCreateElement:()=>E,__unstableToDom:()=>we,__unstableUseRichText:()=>Ye,applyFormat:()=>b,concat:()=>J,create:()=>z,getActiveFormat:()=>Q,getActiveFormats:()=>N,getActiveObject:()=>ee,getTextContent:()=>V,insert:()=>ie,insertObject:()=>ue,isCollapsed:()=>te,isEmpty:()=>ne,join:()=>re,registerFormatType:()=>oe,remove:()=>ce,removeFormat:()=>ae,replace:()=>le,slice:()=>fe,split:()=>de,store:()=>g,toHTMLString:()=>O,toggleFormat:()=>Fe,unregisterFormatType:()=>Re,useAnchor:()=>$e,useAnchorRef:()=>Se});var n={};e.r(n),e.d(n,{getFormatType:()=>u,getFormatTypeForBareElement:()=>f,getFormatTypeForClassName:()=>d,getFormatTypes:()=>l});var r={};e.r(r),e.d(r,{addFormatTypes:()=>m,removeFormatTypes:()=>p});const o=window.wp.data;const a=(0,o.combineReducers)({formatTypes:function(e={},t){switch(t.type){case"ADD_FORMAT_TYPES":return{...e,...t.formatTypes.reduce(((e,t)=>({...e,[t.name]:t})),{})};case"REMOVE_FORMAT_TYPES":return Object.fromEntries(Object.entries(e).filter((([e])=>!t.names.includes(e))))}return e}});var s={};function i(e){return[e]}function c(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 l=function(e,t){var n,r=t||i;function o(){n=new WeakMap}function a(){var t,o,a,i,l,u=arguments.length;for(i=new Array(u),a=0;a<u;a++)i[a]=arguments[a];for(t=function(e){var t,r,o,a,i,c=n,l=!0;for(t=0;t<e.length;t++){if(!(i=r=e[t])||"object"!=typeof i){l=!1;break}c.has(r)?c=c.get(r):(o=new WeakMap,c.set(r,o),c=o)}return c.has(s)||((a=function(){var e={clear:function(){e.head=null}};return e}()).isUniqueByDependants=l,c.set(s,a)),c.get(s)}(l=r.apply(null,i)),t.isUniqueByDependants||(t.lastDependants&&!c(l,t.lastDependants,0)&&t.clear(),t.lastDependants=l),o=t.head;o;){if(c(o.args,i,1))return o!==t.head&&(o.prev.next=o.next,o.next&&(o.next.prev=o.prev),o.next=t.head,o.prev=null,t.head.prev=o,t.head=o),o.val;o=o.next}return o={val:e.apply(null,i)},i[0]=null,o.args=i,t.head&&(t.head.prev=o,o.next=t.head),t.head=o,o.val}return a.getDependants=r,a.clear=o,o(),a}((e=>Object.values(e.formatTypes)),(e=>[e.formatTypes]));function u(e,t){return e.formatTypes[t]}function f(e,t){const n=l(e);return n.find((({className:e,tagName:n})=>null===e&&t===n))||n.find((({className:e,tagName:t})=>null===e&&"*"===t))}function d(e,t){return l(e).find((({className:e})=>null!==e&&` ${t} `.indexOf(` ${e} `)>=0))}function m(e){return{type:"ADD_FORMAT_TYPES",formatTypes:Array.isArray(e)?e:[e]}}function p(e){return{type:"REMOVE_FORMAT_TYPES",names:Array.isArray(e)?e:[e]}}const g=(0,o.createReduxStore)("core/rich-text",{reducer:a,selectors:n,actions:r});function h(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 o=Object.keys(n),a=Object.keys(r);if(o.length!==a.length)return!1;const s=o.length;for(let e=0;e<s;e++){const t=o[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 o=e.slice();o.forEach(((e,t)=>{const n=r[t];h(e,n)&&(o[t]=n)})),t[n]=o}})),{...e,formats:t}}function v(e,t,n){return(e=e.slice())[t]=n,e}function b(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,s=o.slice();if(n===r){const e=s[n]?.find((({type:e})=>e===t.type));if(e){const o=s[n].indexOf(e);for(;s[n]&&s[n][o]===e;)s[n]=v(s[n],o,t),n--;for(r++;s[r]&&s[r][o]===e;)s[r]=v(s[r],o,t),r++}}else{let e=1/0;for(let o=n;o<r;o++)if(s[o]){s[o]=s[o].filter((({type:e})=>e!==t.type));const n=s[o].length;n<e&&(e=n)}else s[o]=[],e=0;for(let o=n;o<r;o++)s[o].splice(e,0,t)}return y({...e,formats:s,activeFormats:[...a?.filter((({type:e})=>e!==t.type))||[],t]})}function E({implementation:e},t){return E.body||(E.body=e.createHTMLDocument("").body),E.body.innerHTML=t,E.body}(0,o.register)(g);const T="",x="\ufeff",w=window.wp.escapeHtml;function N(e,t=[]){const{formats:n,start:r,end:o,activeFormats:a}=e;if(void 0===r)return t;if(r===o){if(a)return a;const e=n[r-1]||t,o=n[r]||t;return e.length<o.length?e:o}if(!n[r])return t;const s=n.slice(r,o),i=[...s[0]];let c=s.length;for(;c--;){const e=s[c];if(!e)return t;let n=i.length;for(;n--;){const t=i[n];e.find((e=>h(t,e)))||i.splice(n,1)}if(0===i.length)return t}return i||t}function C(e){return(0,o.select)(g).getFormatType(e)}function L(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(23)),n[r]=e[t]}return n}function _({type:e,tagName:t,attributes:n,unregisteredAttributes:r,object:o,boundaryClass:a,isEditableTree:s}){const i=C(e);let c={};if(a&&s&&(c["data-rich-text-format-boundary"]="true"),!i)return n&&(c={...n,...c}),{type:e,attributes:L(c,s),object:o};c={...r,...c};for(const e in n){const t=!!i.attributes&&i.attributes[e];t?c[t]=n[e]:c[e]=n[e]}return i.className&&(c.class?c.class=`${i.className} ${c.class}`:c.class=i.className),s&&!1===i.contentEditable&&(c.contenteditable="false"),{type:t||i.tagName,object:i.object,attributes:L(c,s)}}function F(e,t,n){do{if(e[n]!==t[n])return!1}while(n--);return!0}function R({value:e,createEmpty:t,append:n,getLastChild:r,getParent:o,isText:a,getText:s,remove:i,appendText:c,onStartIndex:l,onEndIndex:u,isEditableTree:f,placeholder:d}){const{formats:m,replacements:p,text:g,start:h,end:y}=e,v=m.length+1,b=t(),E=N(e),w=E[E.length-1];let L,R;n(b,"");for(let e=0;e<v;e++){const t=g.charAt(e),v=f&&(!R||"\n"===R),E=m[e];let N=r(b);if(E&&E.forEach(((e,t)=>{if(N&&L&&F(E,L,t))return void(N=r(N));const{type:c,tagName:l,attributes:u,unregisteredAttributes:d}=e,m=f&&e===w,p=o(N),g=n(p,_({type:c,tagName:l,attributes:u,unregisteredAttributes:d,boundaryClass:m,isEditableTree:f}));a(N)&&0===s(N).length&&i(N),N=n(g,"")})),0===e&&(l&&0===h&&l(b,N),u&&0===y&&u(b,N)),t===T){const t=p[e];if(!t)continue;const{type:r,attributes:a,innerHTML:s}=t,i=C(r);f||"script"!==r?!1===i?.contentEditable?(N=n(o(N),_({...t,isEditableTree:f,boundaryClass:h===e&&y===e+1})),s&&n(N,{html:s})):N=n(o(N),_({...t,object:!0,isEditableTree:f})):(N=n(o(N),_({type:"script",isEditableTree:f})),n(N,{html:decodeURIComponent(a["data-rich-text-script"])})),N=n(o(N),"")}else"\n"===t?(N=n(o(N),{type:"br",attributes:f?{"data-rich-text-line-break":"true"}:void 0,object:!0}),N=n(o(N),"")):a(N)?c(N,t):N=n(o(N),t);l&&h===e+1&&l(b,N),u&&y===e+1&&u(b,N),v&&e===g.length&&(n(o(N),x),d&&0===g.length&&n(o(N),{type:"span",attributes:{"data-rich-text-placeholder":d,style:"pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;"}})),L=E,R=t}return b}function O({value:e}){return j(R({value:e,createEmpty:A,append:S,getLastChild:D,getParent:k,isText:$,getText:H,remove:P,appendText:M}).children)}function A(){return{}}function D({children:e}){return e&&e[e.length-1]}function S(e,t){return"string"==typeof t&&(t={text:t}),t.parent=e,e.children=e.children||[],e.children.push(t),t}function M(e,t){e.text+=t}function k({parent:e}){return e}function $({text:e}){return"string"==typeof e}function H({text:e}){return e}function P(e){const t=e.parent.children.indexOf(e);return-1!==t&&e.parent.children.splice(t,1),e}function j(e=[]){return e.map((e=>void 0!==e.html?e.html:void 0===e.text?function({type:e,attributes:t,object:n,children:r}){let o="";for(const e in t)(0,w.isValidAttributeName)(e)&&(o+=` ${e}="${(0,w.escapeAttribute)(t[e])}"`);return n?`<${e}${o}>`:`<${e}${o}>${j(r)}</${e}>`}(e):(0,w.escapeEditableHTML)(e.text))).join("")}function V({text:e}){return e.replace(T,"")}function I({tagName:e,attributes:t}){let n;if(t&&t.class&&(n=(0,o.select)(g).getFormatTypeForClassName(t.class),n&&(t.class=` ${t.class} `.replace(` ${n.className} `," ").trim(),t.class||delete t.class)),n||(n=(0,o.select)(g).getFormatTypeForBareElement(e)),!n)return t?{type:e,attributes:t}:{type:e};if(n.__experimentalCreatePrepareEditableTree&&!n.__experimentalCreateOnChangeEditableValue)return null;if(!t)return{formatType:n,type:n.name,tagName:e};const r={},a={},s={...t};for(const e in n.attributes){const t=n.attributes[e];r[e]=s[t],delete s[t],void 0===r[e]&&delete r[e]}for(const e in s)a[e]=t[e];return!1===n.contentEditable&&delete a.contenteditable,{formatType:n,type:n.name,tagName:e,attributes:r,unregisteredAttributes:a}}class B{#e;static empty(){return new B}static fromPlainText(e){return new B(z({text:e}))}static fromHTMLString(e){return new B(z({html:e}))}static fromHTMLElement(e,t={}){const{preserveWhiteSpace:n=!1}=t,r=n?e:U(e),o=new B(z({element:r}));return Object.defineProperty(o,"originalHTML",{value:e.innerHTML}),o}constructor(e={formats:[],replacements:[],text:""}){this.#e=e}toPlainText(){return V(this.#e)}toHTMLString(){return this.originalHTML||O({value:this.#e})}valueOf(){return this.toHTMLString()}toString(){return this.toHTMLString()}toJSON(){return this.toHTMLString()}get length(){return this.text.length}get formats(){return this.#e.formats}get replacements(){return this.#e.replacements}get text(){return this.#e.text}}for(const e of Object.getOwnPropertyNames(String.prototype))B.prototype.hasOwnProperty(e)||Object.defineProperty(B.prototype,e,{value(...t){return this.toHTMLString()[e](...t)}});function z({element:e,text:t,html:n,range:r,__unstableIsEditableTree:o}={}){return n instanceof B?{text:n.text,formats:n.formats,replacements:n.replacements}:"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:""}:Y({element:e,range:r,isEditableTree:o}))}function W(e,t,n,r){if(!n)return;const{parentNode:o}=t,{startContainer:a,startOffset:s,endContainer:i,endOffset:c}=n,l=e.text.length;void 0!==r.start?e.start=l+r.start:t===a&&t.nodeType===t.TEXT_NODE?e.start=l+s:o===a&&t===a.childNodes[s]?e.start=l:o===a&&t===a.childNodes[s-1]?e.start=l+r.text.length:t===a&&(e.start=l),void 0!==r.end?e.end=l+r.end:t===i&&t.nodeType===t.TEXT_NODE?e.end=l+c:o===i&&t===i.childNodes[c-1]?e.end=l+r.text.length:o===i&&t===i.childNodes[c]?e.end=l:t===i&&(e.end=l+c)}function X(e,t,n){if(!t)return;const{startContainer:r,endContainer:o}=t;let{startOffset:a,endOffset:s}=t;return e===r&&(a=n(e.nodeValue.slice(0,a)).length),e===o&&(s=n(e.nodeValue.slice(0,s)).length),{startContainer:r,startOffset:a,endContainer:o,endOffset:s}}function U(e,t=!0){const n=e.cloneNode(!0);return n.normalize(),Array.from(n.childNodes).forEach(((e,n,r)=>{if(e.nodeType===e.TEXT_NODE){let o=e.nodeValue;/[\n\t\r\f]/.test(o)&&(o=o.replace(/[\n\t\r\f]+/g," ")),-1!==o.indexOf(" ")&&(o=o.replace(/ {2,}/g," ")),0===n&&o.startsWith(" ")?o=o.slice(1):t&&n===r.length-1&&o.endsWith(" ")&&(o=o.slice(0,-1)),e.nodeValue=o}else e.nodeType===e.ELEMENT_NODE&&U(e,!1)})),n}const q="\r";function K(e){return e.replace(new RegExp(`[${x}${T}${q}]`,"gu"),"")}function Y({element:e,range:t,isEditableTree:n}){const r={formats:[],replacements:[],text:""};if(!e)return r;if(!e.hasChildNodes())return W(r,e,t,{formats:[],replacements:[],text:""}),r;const o=e.childNodes.length;for(let a=0;a<o;a++){const s=e.childNodes[a],i=s.nodeName.toLowerCase();if(s.nodeType===s.TEXT_NODE){const u=K(s.nodeValue);W(r,s,t=X(s,t,K),{text:u}),r.formats.length+=u.length,r.replacements.length+=u.length,r.text+=u;continue}if(s.nodeType!==s.ELEMENT_NODE)continue;if(n&&(s.getAttribute("data-rich-text-placeholder")||"br"===i&&!s.getAttribute("data-rich-text-line-break"))){W(r,s,t,{formats:[],replacements:[],text:""});continue}if("script"===i){const f={formats:[,],replacements:[{type:i,attributes:{"data-rich-text-script":s.getAttribute("data-rich-text-script")||encodeURIComponent(s.innerHTML)}}],text:T};W(r,s,t,f),Z(r,f);continue}if("br"===i){W(r,s,t,{formats:[],replacements:[],text:""}),Z(r,z({text:"\n"}));continue}const c=I({tagName:i,attributes:G({element:s})});if(!1===c?.formatType?.contentEditable){delete c.formatType,W(r,s,t,{formats:[],replacements:[],text:""}),Z(r,{formats:[,],replacements:[{...c,innerHTML:s.innerHTML}],text:T});continue}c&&delete c.formatType;const l=Y({element:s,range:t,isEditableTree:n});if(W(r,s,t,l),c)if(0===l.text.length)c.attributes&&Z(r,{formats:[,],replacements:[c],text:T});else{function d(e){if(d.formats===e)return d.newFormats;const t=e?[c,...e]:[c];return d.formats=e,d.newFormats=t,t}d.newFormats=[c],Z(r,{...l,formats:Array.from(l.formats,d)})}else Z(r,l)}return r}function G({element:e}){if(!e.hasAttributes())return;const t=e.attributes.length;let n;for(let r=0;r<t;r++){const{name:t,value:o}=e.attributes[r];if(0===t.indexOf("data-rich-text-"))continue;n=n||{},n[/^on/i.test(t)?"data-disable-rich-text-"+t:t]=o}return n}function Z(e,t){return e.formats=e.formats.concat(t.formats),e.replacements=e.replacements.concat(t.replacements),e.text+=t.text,e}function J(...e){return y(e.reduce(Z,z()))}function Q(e,t){return N(e).find((({type:e})=>e===t))}function ee({start:e,end:t,replacements:n,text:r}){if(e+1===t&&r[e]===T)return n[e]}function te({start:e,end:t}){if(void 0!==e&&void 0!==t)return e===t}function ne({text:e}){return 0===e.length}function re(e,t=""){return"string"==typeof t&&(t=z({text:t})),y(e.reduce(((e,{formats:n,replacements:r,text:o})=>({formats:e.formats.concat(t.formats,n),replacements:e.replacements.concat(t.replacements,r),text:e.text+t.text+o}))))}function oe(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,o.select)(g).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,o.select)(g).getFormatTypeForBareElement(t.tagName);if(e&&"core/unknown"!==e.name)return void window.console.error(`Format "${e.name}" is already registered to handle bare tag name "${t.tagName}".`)}else{const e=(0,o.select)(g).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,o.dispatch)(g).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, underscores, 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 ae(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,s=o.slice();if(n===r){const e=s[n]?.find((({type:e})=>e===t));if(e){for(;s[n]?.find((t=>t===e));)se(s,n,t),n--;for(r++;s[r]?.find((t=>t===e));)se(s,r,t),r++}}else for(let e=n;e<r;e++)s[e]&&se(s,e,t);return y({...e,formats:s,activeFormats:a?.filter((({type:e})=>e!==t))||[]})}function se(e,t,n){const r=e[t].filter((({type:e})=>e!==n));r.length?e[t]=r:delete e[t]}function ie(e,t,n=e.start,r=e.end){const{formats:o,replacements:a,text:s}=e;"string"==typeof t&&(t=z({text:t}));const i=n+t.text.length;return y({formats:o.slice(0,n).concat(t.formats,o.slice(r)),replacements:a.slice(0,n).concat(t.replacements,a.slice(r)),text:s.slice(0,n)+t.text+s.slice(r),start:i,end:i})}function ce(e,t,n){return ie(e,z(),t,n)}function le({formats:e,replacements:t,text:n,start:r,end:o},a,s){return n=n.replace(a,((n,...a)=>{const i=a[a.length-2];let c,l,u=s;return"function"==typeof u&&(u=s(n,...a)),"object"==typeof u?(c=u.formats,l=u.replacements,u=u.text):(c=Array(u.length),l=Array(u.length),e[i]&&(c=c.fill(e[i]))),e=e.slice(0,i).concat(c,e.slice(i+n.length)),t=t.slice(0,i).concat(l,t.slice(i+n.length)),r&&(r=o=i+u.length),u})),y({formats:e,replacements:t,text:n,start:r,end:o})}function ue(e,t,n,r){return ie(e,{formats:[,],replacements:[t],text:T},n,r)}function fe(e,t=e.start,n=e.end){const{formats:r,replacements:o,text:a}=e;return void 0===t||void 0===n?{...e}:{formats:r.slice(t,n),replacements:o.slice(t,n),text:a.slice(t,n)}}function de({formats:e,replacements:t,text:n,start:r,end:o},a){if("string"!=typeof a)return function({formats:e,replacements:t,text:n,start:r,end:o},a=r,s=o){if(void 0===r||void 0===o)return;const i={formats:e.slice(0,a),replacements:t.slice(0,a),text:n.slice(0,a)},c={formats:e.slice(s),replacements:t.slice(s),text:n.slice(s),start:0,end:0};return[i,c]}(...arguments);let s=0;return n.split(a).map((n=>{const i=s,c={formats:e.slice(i,i+n.length),replacements:t.slice(i,i+n.length),text:n};return s+=a.length+n.length,void 0!==r&&void 0!==o&&(r>=i&&r<s?c.start=r-i:r<i&&o>i&&(c.start=0),o>=i&&o<s?c.end=o-i:r<s&&o>s&&(c.end=n.length)),c}))}function me(e,t){return e===t||e&&t&&e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset}function pe(e,t,n){const r=e.parentNode;let o=0;for(;e=e.previousSibling;)o++;return n=[o,...n],r!==t&&(n=pe(r,t,n)),n}function ge(e,t){for(t=[...t];e&&t.length>1;)e=e.childNodes[t.shift()];return{node:e,offset:t[0]}}function he(e,t){if(void 0!==t.html)return e.innerHTML+=t.html;"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 ye(e,t){e.appendData(t)}function ve({lastChild:e}){return e}function be({parentNode:e}){return e}function Ee(e){return e.nodeType===e.TEXT_NODE}function Te({nodeValue:e}){return e}function xe(e){return e.parentNode.removeChild(e)}function we({value:e,prepareEditableTree:t,isEditableTree:n=!0,placeholder:r,doc:o=document}){let a=[],s=[];t&&(e={...e,formats:t(e)});return{body:R({value:e,createEmpty:()=>E(o,""),append:he,getLastChild:ve,getParent:be,isText:Ee,getText:Te,remove:xe,appendText:ye,onStartIndex(e,t){a=pe(t,e,[t.nodeValue.length])},onEndIndex(e,t){s=pe(t,e,[t.nodeValue.length])},isEditableTree:n,placeholder:r}),selection:{startPath:a,endPath:s}}}function Ne({value:e,current:t,prepareEditableTree:n,__unstableDomOnly:r,placeholder:o}){const{body:a,selection:s}=we({value:e,prepareEditableTree:n,placeholder:o,doc:t.ownerDocument});Ce(a,t),void 0===e.start||r||function({startPath:e,endPath:t},n){const{node:r,offset:o}=ge(n,e),{node:a,offset:s}=ge(n,t),{ownerDocument:i}=n,{defaultView:c}=i,l=c.getSelection(),u=i.createRange();u.setStart(r,o),u.setEnd(a,s);const{activeElement:f}=i;if(l.rangeCount>0){if(me(u,l.getRangeAt(0)))return;l.removeAllRanges()}l.addRange(u),f!==i.activeElement&&f instanceof c.HTMLElement&&f.focus()}(s,t)}function Ce(e,t){let n,r=0;for(;n=e.firstChild;){const o=t.childNodes[r];if(o)if(o.isEqualNode(n))e.removeChild(n);else if(o.nodeName!==n.nodeName||o.nodeType===o.TEXT_NODE&&o.data!==n.data)t.replaceChild(n,o);else{const t=o.attributes,r=n.attributes;if(t){let e=t.length;for(;e--;){const{name:r}=t[e];n.getAttribute(r)||o.removeAttribute(r)}}if(r)for(let e=0;e<r.length;e++){const{name:t,value:n}=r[e];o.getAttribute(t)!==n&&o.setAttribute(t,n)}Ce(n,o),e.removeChild(n)}else t.appendChild(n);r++}for(;t.childNodes[r];)t.removeChild(t.childNodes[r])}const Le=window.wp.a11y,_e=window.wp.i18n;function Fe(e,t){return Q(e,t.type)?(t.title&&(0,Le.speak)((0,_e.sprintf)((0,_e.__)("%s removed."),t.title),"assertive"),ae(e,t.type)):(t.title&&(0,Le.speak)((0,_e.sprintf)((0,_e.__)("%s applied."),t.title),"assertive"),b(e,t))}function Re(e){const t=(0,o.select)(g).getFormatType(e);if(t)return(0,o.dispatch)(g).removeFormatTypes(e),t;window.console.error(`Format ${e} is not registered.`)}const Oe=window.wp.element,Ae=window.wp.deprecated;var De=e.n(Ae);function Se({ref:e,value:t,settings:n={}}){De()("`useAnchorRef` hook",{since:"6.1",alternative:"`useAnchor` hook"});const{tagName:r,className:o,name:a}=n,s=a?Q(t,a):void 0;return(0,Oe.useMemo)((()=>{if(!e.current)return;const{ownerDocument:{defaultView:t}}=e.current,n=t.getSelection();if(!n.rangeCount)return;const a=n.getRangeAt(0);if(!s)return a;let i=a.startContainer;for(i=i.nextElementSibling||i;i.nodeType!==i.ELEMENT_NODE;)i=i.parentNode;return i.closest(r+(o?"."+o:""))}),[s,t.start,t.end,r,o])}const Me=window.wp.compose;function ke(e,t,n){if(!e)return;const{ownerDocument:r}=e,{defaultView:o}=r,a=o.getSelection();if(!a)return;if(!a.rangeCount)return;const s=a.getRangeAt(0);if(!s||!s.startContainer)return;const i=function(e,t,n,r){let o=e.startContainer;if(o.nodeType===o.TEXT_NODE&&e.startOffset===o.length&&o.nextSibling)for(o=o.nextSibling;o.firstChild;)o=o.firstChild;if(o.nodeType!==o.ELEMENT_NODE&&(o=o.parentElement),!o)return;if(o===t)return;if(!t.contains(o))return;const a=n+(r?"."+r:"");for(;o!==t;){if(o.matches(a))return o;o=o.parentElement}}(s,e,t,n);return i||function(e,t){return{contextElement:t,getBoundingClientRect:()=>t.contains(e.startContainer)?e.getBoundingClientRect():t.getBoundingClientRect()}}(s,e)}function $e({editableContentElement:e,settings:t={}}){const{tagName:n,className:r,isActive:o}=t,[a,s]=(0,Oe.useState)((()=>ke(e,n,r))),i=(0,Me.usePrevious)(o);return(0,Oe.useLayoutEffect)((()=>{if(!e)return;const{ownerDocument:t}=e;(e===t.activeElement||!i&&o||i&&!o)&&s(ke(e,n,r))}),[e,n,r,o,i]),a}const He="pre-wrap",Pe="1px";function je({record:e}){const t=(0,Oe.useRef)(),{activeFormats:n=[],replacements:r,start:o}=e.current,a=r[o];return(0,Oe.useEffect)((()=>{if(!(n&&n.length||a))return;const e="*[data-rich-text-format-boundary]",r=t.current.querySelector(e);if(!r)return;const{ownerDocument:o}=r,{defaultView:s}=o,i=`${`.rich-text:focus ${e}`} {${`background-color: ${s.getComputedStyle(r).color.replace(")",", 0.2)").replace("rgb","rgba")}`}}`,c="rich-text-boundary-style";let l=o.getElementById(c);l||(l=o.createElement("style"),l.id=c,o.head.appendChild(l)),l.innerHTML!==i&&(l.innerHTML=i)}),[n,a]),t}function Ve(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Me.useRefEffect)((e=>{function n(n){const{record:r}=t.current,{ownerDocument:o}=e;if(te(r.current)||!e.contains(o.activeElement))return;const a=fe(r.current),s=V(a),i=O({value:a});n.clipboardData.setData("text/plain",s),n.clipboardData.setData("text/html",i),n.clipboardData.setData("rich-text","true"),n.preventDefault(),"cut"===n.type&&o.execCommand("delete")}return e.addEventListener("copy",n),e.addEventListener("cut",n),()=>{e.removeEventListener("copy",n),e.removeEventListener("cut",n)}}),[])}const Ie=window.wp.keycodes,Be=[];function ze(e){const[,t]=(0,Oe.useReducer)((()=>({}))),n=(0,Oe.useRef)(e);return n.current=e,(0,Me.useRefEffect)((e=>{function r(r){const{keyCode:o,shiftKey:a,altKey:s,metaKey:i,ctrlKey:c}=r;if(a||s||i||c||o!==Ie.LEFT&&o!==Ie.RIGHT)return;const{record:l,applyRecord:u}=n.current,{text:f,formats:d,start:m,end:p,activeFormats:g=[]}=l.current,h=te(l.current),{ownerDocument:y}=e,{defaultView:v}=y,{direction:b}=v.getComputedStyle(e),E="rtl"===b?Ie.RIGHT:Ie.LEFT,T=r.keyCode===E;if(h&&0===g.length){if(0===m&&T)return;if(p===f.length&&!T)return}if(!h)return;const x=d[m-1]||Be,w=d[m]||Be,N=T?x:w,C=g.every(((e,t)=>e===N[t]));let L=g.length;if(C?L<N.length&&L++:L--,L===g.length)return void(l.current._newActiveFormats=N);r.preventDefault();const _=(C?N:T?w:x).slice(0,L),F={...l.current,activeFormats:_};l.current=F,u(F),t()}return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}}),[])}const We=new Set(["insertParagraph","insertOrderedList","insertUnorderedList","insertHorizontalRule","insertLink"]),Xe=[],Ue="data-rich-text-placeholder";function qe(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Me.useRefEffect)((e=>{const{ownerDocument:n}=e,{defaultView:r}=n;let o=!1;function a(e){if(o)return;let n;e&&(n=e.inputType);const{record:r,applyRecord:a,createRecord:s,handleChange:i}=t.current;if(n&&(0===n.indexOf("format")||We.has(n)))return void a(r.current);const c=s(),{start:l,activeFormats:u=[]}=r.current,f=function({value:e,start:t,end:n,formats:r}){const o=Math.min(t,n),a=Math.max(t,n),s=e.formats[o-1]||[],i=e.formats[a]||[];for(e.activeFormats=r.map(((e,t)=>{if(s[t]){if(h(e,s[t]))return s[t]}else if(i[t]&&h(e,i[t]))return i[t];return e}));--n>=t;)e.activeFormats.length>0?e.formats[n]=e.activeFormats:delete e.formats[n];return e}({value:c,start:l,end:c.start,formats:u});i(f)}function s(){const{record:i,applyRecord:c,createRecord:l,onSelectionChange:u}=t.current;if("true"!==e.contentEditable)return;if(n.activeElement!==e)return void n.removeEventListener("selectionchange",s);if(o)return;const{start:f,end:d,text:m}=l(),p=i.current;if(m!==p.text)return void a();if(f===p.start&&d===p.end)return void(0===p.text.length&&0===f&&function(e){const t=e.getSelection(),{anchorNode:n,anchorOffset:r}=t;if(n.nodeType!==n.ELEMENT_NODE)return;const o=n.childNodes[r];o&&o.nodeType===o.ELEMENT_NODE&&o.hasAttribute(Ue)&&t.collapseToStart()}(r));const g={...p,start:f,end:d,activeFormats:p._newActiveFormats,_newActiveFormats:void 0},h=N(g,Xe);g.activeFormats=h,i.current=g,c(g,{domOnly:!0}),u(f,d)}function i(){o=!0,n.removeEventListener("selectionchange",s),e.querySelector(`[${Ue}]`)?.remove()}function c(){o=!1,a({inputType:"insertText"}),n.addEventListener("selectionchange",s)}function l(){const{record:r,isSelected:o,onSelectionChange:a,applyRecord:i}=t.current;if(!e.parentElement.closest('[contenteditable="true"]')){if(o)i(r.current,{domOnly:!0});else{const e=void 0;r.current={...r.current,start:e,end:e,activeFormats:Xe}}a(r.current.start,r.current.end),n.addEventListener("selectionchange",s)}}return e.addEventListener("input",a),e.addEventListener("compositionstart",i),e.addEventListener("compositionend",c),e.addEventListener("focus",l),()=>{e.removeEventListener("input",a),e.removeEventListener("compositionstart",i),e.removeEventListener("compositionend",c),e.removeEventListener("focus",l)}}),[])}function Ke(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Me.useRefEffect)((e=>{function n(e){const{keyCode:n}=e,{createRecord:r,handleChange:o}=t.current;if(e.defaultPrevented)return;if(n!==Ie.DELETE&&n!==Ie.BACKSPACE)return;const a=r(),{start:s,end:i,text:c}=a;0===s&&0!==i&&i===c.length&&(o(ce(a)),e.preventDefault())}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[])}function Ye({value:e="",selectionStart:t,selectionEnd:n,placeholder:r,onSelectionChange:a,preserveWhiteSpace:s,onChange:i,__unstableDisableFormats:c,__unstableIsSelected:l,__unstableDependencies:u=[],__unstableAfterParse:f,__unstableBeforeSerialize:d,__unstableAddInvisibleFormats:m}){const p=(0,o.useRegistry)(),[,g]=(0,Oe.useReducer)((()=>({}))),h=(0,Oe.useRef)();function y(){const{ownerDocument:{defaultView:e}}=h.current,t=e.getSelection(),n=t.rangeCount>0?t.getRangeAt(0):null;return z({element:h.current,range:n,__unstableIsEditableTree:!0})}function v(e,{domOnly:t}={}){Ne({value:e,current:h.current,prepareEditableTree:m,__unstableDomOnly:t,placeholder:r})}const b=(0,Oe.useRef)(e),E=(0,Oe.useRef)();function T(){b.current=e,E.current=e,e instanceof B||(E.current=e?B.fromHTMLString(e,{preserveWhiteSpace:s}):B.empty()),E.current={text:E.current.text,formats:E.current.formats,replacements:E.current.replacements},c&&(E.current.formats=Array(e.length),E.current.replacements=Array(e.length)),f&&(E.current.formats=f(E.current)),E.current.start=t,E.current.end=n}const x=(0,Oe.useRef)(!1);function w(t){if(E.current=t,v(t),c)b.current=t.text;else{const n=d?d(t):t.formats;t={...t,formats:n},b.current="string"==typeof e?O({value:t}):new B(t)}const{start:n,end:r,formats:o,text:s}=E.current;p.batch((()=>{a(n,r),i(b.current,{__unstableFormats:o,__unstableText:s})})),g()}function N(){T(),v(E.current)}E.current?t===E.current.start&&n===E.current.end||(x.current=l,E.current={...E.current,start:t,end:n,activeFormats:void 0}):(x.current=l,T());const C=(0,Oe.useRef)(!1);(0,Oe.useLayoutEffect)((()=>{C.current&&e!==b.current&&(N(),g())}),[e]),(0,Oe.useLayoutEffect)((()=>{x.current&&(h.current.ownerDocument.activeElement!==h.current&&h.current.focus(),v(E.current),x.current=!1)}),[x.current]);const L=(0,Me.useMergeRefs)([h,(0,Oe.useCallback)((e=>{e&&(e.style.whiteSpace=He,e.style.minWidth=Pe)}),[]),je({record:E}),Ve({record:E}),(0,Me.useRefEffect)((e=>{function t(t){const{target:n}=t;if(n===e||n.textContent&&n.isContentEditable)return;const{ownerDocument:r}=n,{defaultView:o}=r,a=o.getSelection();if(a.containsNode(n))return;const s=r.createRange(),i=n.isContentEditable?n:n.closest("[contenteditable]");s.selectNode(i),a.removeAllRanges(),a.addRange(s),t.preventDefault()}function n(n){n.relatedTarget&&!e.contains(n.relatedTarget)&&"A"===n.relatedTarget.tagName&&t(n)}return e.addEventListener("click",t),e.addEventListener("focusin",n),()=>{e.removeEventListener("click",t),e.removeEventListener("focusin",n)}}),[]),ze({record:E,applyRecord:v}),Ke({createRecord:y,handleChange:w}),qe({record:E,applyRecord:v,createRecord:y,handleChange:w,isSelected:l,onSelectionChange:a}),(0,Me.useRefEffect)((e=>{const{ownerDocument:t}=e,{defaultView:n}=t,r=n?.getSelection();let o;function a(){return r.rangeCount?r.getRangeAt(0):null}function s(e){const n="keydown"===e.type?"keyup":"pointerup";function r(){t.removeEventListener(n,s),t.removeEventListener("selectionchange",r),t.removeEventListener("input",r)}function s(){r(),me(o,a())||t.dispatchEvent(new Event("selectionchange"))}t.addEventListener(n,s),t.addEventListener("selectionchange",r),t.addEventListener("input",r),o=a()}return e.addEventListener("pointerdown",s),e.addEventListener("keydown",s),()=>{e.removeEventListener("pointerdown",s),e.removeEventListener("keydown",s)}}),[]),(0,Me.useRefEffect)((()=>{N(),C.current=!0}),[r,...u])]);return{value:E.current,getValue:()=>E.current,onChange:w,ref:L}}function Ge(){}(window.wp=window.wp||{}).richText=t})();