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

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