| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /******/ (() => { // webpackBootstrap 2 /******/ "use strict"; 3 /******/ // The require scope 4 /******/ var __webpack_require__ = {}; 5 /******/ 6 /************************************************************************/ 7 /******/ /* webpack/runtime/compat get default export */ 8 /******/ (() => { 9 /******/ // getDefaultExport function for compatibility with non-harmony modules 10 /******/ __webpack_require__.n = (module) => { 11 /******/ var getter = module && module.__esModule ? 12 /******/ () => (module['default']) : 13 /******/ () => (module); 14 /******/ __webpack_require__.d(getter, { a: getter }); 15 /******/ return getter; 16 /******/ }; 17 /******/ })(); 18 /******/ 19 /******/ /* webpack/runtime/define property getters */ 20 /******/ (() => { 21 /******/ // define getter functions for harmony exports 22 /******/ __webpack_require__.d = (exports, definition) => { 23 /******/ for(var key in definition) { 24 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 25 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 26 /******/ } 27 /******/ } 28 /******/ }; 29 /******/ })(); 30 /******/ 31 /******/ /* webpack/runtime/hasOwnProperty shorthand */ 32 /******/ (() => { 33 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 34 /******/ })(); 35 /******/ 36 /******/ /* webpack/runtime/make namespace object */ 37 /******/ (() => { 38 /******/ // define __esModule on exports 39 /******/ __webpack_require__.r = (exports) => { 40 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 41 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 42 /******/ } 43 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 44 /******/ }; 45 /******/ })(); 46 /******/ 47 /************************************************************************/ 48 var __webpack_exports__ = {}; 49 // ESM COMPAT FLAG 50 __webpack_require__.r(__webpack_exports__); 51 52 // EXPORTS 53 __webpack_require__.d(__webpack_exports__, { 54 RichTextData: () => (/* reexport */ RichTextData), 55 __experimentalRichText: () => (/* reexport */ __experimentalRichText), 56 __unstableCreateElement: () => (/* reexport */ createElement), 57 __unstableToDom: () => (/* reexport */ toDom), 58 __unstableUseRichText: () => (/* reexport */ useRichText), 59 applyFormat: () => (/* reexport */ applyFormat), 60 concat: () => (/* reexport */ concat), 61 create: () => (/* reexport */ create), 62 getActiveFormat: () => (/* reexport */ getActiveFormat), 63 getActiveFormats: () => (/* reexport */ getActiveFormats), 64 getActiveObject: () => (/* reexport */ getActiveObject), 65 getTextContent: () => (/* reexport */ getTextContent), 66 insert: () => (/* reexport */ insert), 67 insertObject: () => (/* reexport */ insertObject), 68 isCollapsed: () => (/* reexport */ isCollapsed), 69 isEmpty: () => (/* reexport */ isEmpty), 70 join: () => (/* reexport */ join), 71 registerFormatType: () => (/* reexport */ registerFormatType), 72 remove: () => (/* reexport */ remove_remove), 73 removeFormat: () => (/* reexport */ removeFormat), 74 replace: () => (/* reexport */ replace_replace), 75 slice: () => (/* reexport */ slice), 76 split: () => (/* reexport */ split), 77 store: () => (/* reexport */ store), 78 toHTMLString: () => (/* reexport */ toHTMLString), 79 toggleFormat: () => (/* reexport */ toggleFormat), 80 unregisterFormatType: () => (/* reexport */ unregisterFormatType), 81 useAnchor: () => (/* reexport */ useAnchor), 82 useAnchorRef: () => (/* reexport */ useAnchorRef) 83 }); 84 85 // NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js 86 var selectors_namespaceObject = {}; 87 __webpack_require__.r(selectors_namespaceObject); 88 __webpack_require__.d(selectors_namespaceObject, { 89 getFormatType: () => (getFormatType), 90 getFormatTypeForBareElement: () => (getFormatTypeForBareElement), 91 getFormatTypeForClassName: () => (getFormatTypeForClassName), 92 getFormatTypes: () => (getFormatTypes) 93 }); 94 95 // NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/actions.js 96 var actions_namespaceObject = {}; 97 __webpack_require__.r(actions_namespaceObject); 98 __webpack_require__.d(actions_namespaceObject, { 99 addFormatTypes: () => (addFormatTypes), 100 removeFormatTypes: () => (removeFormatTypes) 101 }); 102 103 ;// external ["wp","data"] 104 const external_wp_data_namespaceObject = window["wp"]["data"]; 105 ;// ./node_modules/@wordpress/rich-text/build-module/store/reducer.js 106 107 function formatTypes(state = {}, action) { 108 switch (action.type) { 109 case "ADD_FORMAT_TYPES": 110 return { 111 ...state, 112 // Key format types by their name. 113 ...action.formatTypes.reduce( 114 (newFormatTypes, type) => ({ 115 ...newFormatTypes, 116 [type.name]: type 117 }), 118 {} 119 ) 120 }; 121 case "REMOVE_FORMAT_TYPES": 122 return Object.fromEntries( 123 Object.entries(state).filter( 124 ([key]) => !action.names.includes(key) 125 ) 126 ); 127 } 128 return state; 129 } 130 var reducer_default = (0,external_wp_data_namespaceObject.combineReducers)({ formatTypes }); 131 132 133 ;// ./node_modules/@wordpress/rich-text/build-module/store/selectors.js 134 135 const getFormatTypes = (0,external_wp_data_namespaceObject.createSelector)( 136 (state) => Object.values(state.formatTypes), 137 (state) => [state.formatTypes] 138 ); 139 function getFormatType(state, name) { 140 return state.formatTypes[name]; 141 } 142 function getFormatTypeForBareElement(state, bareElementTagName) { 143 const formatTypes = getFormatTypes(state); 144 return formatTypes.find(({ className, tagName }) => { 145 return className === null && bareElementTagName === tagName; 146 }) || formatTypes.find(({ className, tagName }) => { 147 return className === null && "*" === tagName; 148 }); 149 } 150 function getFormatTypeForClassName(state, elementClassName) { 151 return getFormatTypes(state).find(({ className }) => { 152 if (className === null) { 153 return false; 154 } 155 return ` $elementClassName} `.indexOf(` $className} `) >= 0; 156 }); 157 } 158 159 160 ;// ./node_modules/@wordpress/rich-text/build-module/store/actions.js 161 function addFormatTypes(formatTypes) { 162 return { 163 type: "ADD_FORMAT_TYPES", 164 formatTypes: Array.isArray(formatTypes) ? formatTypes : [formatTypes] 165 }; 166 } 167 function removeFormatTypes(names) { 168 return { 169 type: "REMOVE_FORMAT_TYPES", 170 names: Array.isArray(names) ? names : [names] 171 }; 172 } 173 174 175 ;// ./node_modules/@wordpress/rich-text/build-module/store/index.js 176 177 178 179 180 const STORE_NAME = "core/rich-text"; 181 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, { 182 reducer: reducer_default, 183 selectors: selectors_namespaceObject, 184 actions: actions_namespaceObject 185 }); 186 (0,external_wp_data_namespaceObject.register)(store); 187 188 189 ;// ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js 190 function isFormatEqual(format1, format2) { 191 if (format1 === format2) { 192 return true; 193 } 194 if (!format1 || !format2) { 195 return false; 196 } 197 if (format1.type !== format2.type) { 198 return false; 199 } 200 const attributes1 = format1.attributes; 201 const attributes2 = format2.attributes; 202 if (attributes1 === attributes2) { 203 return true; 204 } 205 if (!attributes1 || !attributes2) { 206 return false; 207 } 208 const keys1 = Object.keys(attributes1); 209 const keys2 = Object.keys(attributes2); 210 if (keys1.length !== keys2.length) { 211 return false; 212 } 213 const length = keys1.length; 214 for (let i = 0; i < length; i++) { 215 const name = keys1[i]; 216 if (attributes1[name] !== attributes2[name]) { 217 return false; 218 } 219 } 220 return true; 221 } 222 223 224 ;// ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js 225 226 function normaliseFormats(value) { 227 const newFormats = value.formats.slice(); 228 newFormats.forEach((formatsAtIndex, index) => { 229 const formatsAtPreviousIndex = newFormats[index - 1]; 230 if (formatsAtPreviousIndex) { 231 const newFormatsAtIndex = formatsAtIndex.slice(); 232 newFormatsAtIndex.forEach((format, formatIndex) => { 233 const previousFormat = formatsAtPreviousIndex[formatIndex]; 234 if (isFormatEqual(format, previousFormat)) { 235 newFormatsAtIndex[formatIndex] = previousFormat; 236 } 237 }); 238 newFormats[index] = newFormatsAtIndex; 239 } 240 }); 241 return { 242 ...value, 243 formats: newFormats 244 }; 245 } 246 247 248 ;// ./node_modules/@wordpress/rich-text/build-module/apply-format.js 249 250 function replace(array, index, value) { 251 array = array.slice(); 252 array[index] = value; 253 return array; 254 } 255 function applyFormat(value, format, startIndex = value.start, endIndex = value.end) { 256 const { formats, activeFormats } = value; 257 const newFormats = formats.slice(); 258 if (startIndex === endIndex) { 259 const startFormat = newFormats[startIndex]?.find( 260 ({ type }) => type === format.type 261 ); 262 if (startFormat) { 263 const index = newFormats[startIndex].indexOf(startFormat); 264 while (newFormats[startIndex] && newFormats[startIndex][index] === startFormat) { 265 newFormats[startIndex] = replace( 266 newFormats[startIndex], 267 index, 268 format 269 ); 270 startIndex--; 271 } 272 endIndex++; 273 while (newFormats[endIndex] && newFormats[endIndex][index] === startFormat) { 274 newFormats[endIndex] = replace( 275 newFormats[endIndex], 276 index, 277 format 278 ); 279 endIndex++; 280 } 281 } 282 } else { 283 let position = Infinity; 284 for (let index = startIndex; index < endIndex; index++) { 285 if (newFormats[index]) { 286 newFormats[index] = newFormats[index].filter( 287 ({ type }) => type !== format.type 288 ); 289 const length = newFormats[index].length; 290 if (length < position) { 291 position = length; 292 } 293 } else { 294 newFormats[index] = []; 295 position = 0; 296 } 297 } 298 for (let index = startIndex; index < endIndex; index++) { 299 newFormats[index].splice(position, 0, format); 300 } 301 } 302 return normaliseFormats({ 303 ...value, 304 formats: newFormats, 305 // Always revise active formats. This serves as a placeholder for new 306 // inputs with the format so new input appears with the format applied, 307 // and ensures a format of the same type uses the latest values. 308 activeFormats: [ 309 ...activeFormats?.filter( 310 ({ type }) => type !== format.type 311 ) || [], 312 format 313 ] 314 }); 315 } 316 317 318 ;// ./node_modules/@wordpress/rich-text/build-module/create-element.js 319 function createElement({ implementation }, html) { 320 if (!createElement.body) { 321 createElement.body = implementation.createHTMLDocument("").body; 322 } 323 createElement.body.innerHTML = html; 324 return createElement.body; 325 } 326 327 328 ;// ./node_modules/@wordpress/rich-text/build-module/special-characters.js 329 const OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"; 330 const ZWNBSP = "\uFEFF"; 331 332 333 ;// external ["wp","escapeHtml"] 334 const external_wp_escapeHtml_namespaceObject = window["wp"]["escapeHtml"]; 335 ;// ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js 336 337 function getActiveFormats(value, EMPTY_ACTIVE_FORMATS = []) { 338 const { formats, start, end, activeFormats } = value; 339 if (start === void 0) { 340 return EMPTY_ACTIVE_FORMATS; 341 } 342 if (start === end) { 343 if (activeFormats) { 344 return activeFormats; 345 } 346 const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS; 347 const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; 348 if (formatsBefore.length < formatsAfter.length) { 349 return formatsBefore; 350 } 351 return formatsAfter; 352 } 353 if (!formats[start]) { 354 return EMPTY_ACTIVE_FORMATS; 355 } 356 const selectedFormats = formats.slice(start, end); 357 const _activeFormats = [...selectedFormats[0]]; 358 let i = selectedFormats.length; 359 while (i--) { 360 const formatsAtIndex = selectedFormats[i]; 361 if (!formatsAtIndex) { 362 return EMPTY_ACTIVE_FORMATS; 363 } 364 let ii = _activeFormats.length; 365 while (ii--) { 366 const format = _activeFormats[ii]; 367 if (!formatsAtIndex.find( 368 (_format) => isFormatEqual(format, _format) 369 )) { 370 _activeFormats.splice(ii, 1); 371 } 372 } 373 if (_activeFormats.length === 0) { 374 return EMPTY_ACTIVE_FORMATS; 375 } 376 } 377 return _activeFormats || EMPTY_ACTIVE_FORMATS; 378 } 379 380 381 ;// ./node_modules/@wordpress/rich-text/build-module/get-format-type.js 382 383 384 function get_format_type_getFormatType(name) { 385 return (0,external_wp_data_namespaceObject.select)(store).getFormatType(name); 386 } 387 388 389 ;// ./node_modules/@wordpress/rich-text/build-module/to-tree.js 390 391 392 393 function restoreOnAttributes(attributes, isEditableTree) { 394 if (isEditableTree) { 395 return attributes; 396 } 397 const newAttributes = {}; 398 for (const key in attributes) { 399 let newKey = key; 400 if (key.startsWith("data-disable-rich-text-")) { 401 newKey = key.slice("data-disable-rich-text-".length); 402 } 403 newAttributes[newKey] = attributes[key]; 404 } 405 return newAttributes; 406 } 407 function fromFormat({ 408 type, 409 tagName, 410 attributes, 411 unregisteredAttributes, 412 object, 413 boundaryClass, 414 isEditableTree 415 }) { 416 const formatType = get_format_type_getFormatType(type); 417 let elementAttributes = {}; 418 if (boundaryClass && isEditableTree) { 419 elementAttributes["data-rich-text-format-boundary"] = "true"; 420 } 421 if (!formatType) { 422 if (attributes) { 423 elementAttributes = { ...attributes, ...elementAttributes }; 424 } 425 return { 426 type, 427 attributes: restoreOnAttributes( 428 elementAttributes, 429 isEditableTree 430 ), 431 object 432 }; 433 } 434 elementAttributes = { ...unregisteredAttributes, ...elementAttributes }; 435 for (const name in attributes) { 436 const key = formatType.attributes ? formatType.attributes[name] : false; 437 if (key) { 438 elementAttributes[key] = attributes[name]; 439 } else { 440 elementAttributes[name] = attributes[name]; 441 } 442 } 443 if (formatType.className) { 444 if (elementAttributes.class) { 445 elementAttributes.class = `$formatType.className} $elementAttributes.class}`; 446 } else { 447 elementAttributes.class = formatType.className; 448 } 449 } 450 return { 451 type: tagName || formatType.tagName, 452 object: formatType.object, 453 attributes: restoreOnAttributes(elementAttributes, isEditableTree) 454 }; 455 } 456 function isEqualUntil(a, b, index) { 457 do { 458 if (a[index] !== b[index]) { 459 return false; 460 } 461 } while (index--); 462 return true; 463 } 464 function toTree({ 465 value, 466 preserveWhiteSpace, 467 createEmpty, 468 append, 469 getLastChild, 470 getParent, 471 isText, 472 getText, 473 remove, 474 appendText, 475 onStartIndex, 476 onEndIndex, 477 isEditableTree, 478 placeholder 479 }) { 480 const { formats, replacements, text, start, end } = value; 481 const formatsLength = formats.length + 1; 482 const tree = createEmpty(); 483 const activeFormats = getActiveFormats(value); 484 const deepestActiveFormat = activeFormats[activeFormats.length - 1]; 485 let lastCharacterFormats; 486 let lastCharacter; 487 append(tree, ""); 488 for (let i = 0; i < formatsLength; i++) { 489 const character = text.charAt(i); 490 const shouldInsertPadding = isEditableTree && // Pad the line if the line is empty. 491 (!lastCharacter || // Pad the line if the previous character is a line break, otherwise 492 // the line break won't be visible. 493 lastCharacter === "\n"); 494 const characterFormats = formats[i]; 495 let pointer = getLastChild(tree); 496 if (characterFormats) { 497 characterFormats.forEach((format, formatIndex) => { 498 if (pointer && lastCharacterFormats && // Reuse the last element if all formats remain the same. 499 isEqualUntil( 500 characterFormats, 501 lastCharacterFormats, 502 formatIndex 503 )) { 504 pointer = getLastChild(pointer); 505 return; 506 } 507 const { type, tagName, attributes, unregisteredAttributes } = format; 508 const boundaryClass = isEditableTree && format === deepestActiveFormat; 509 const parent = getParent(pointer); 510 const newNode = append( 511 parent, 512 fromFormat({ 513 type, 514 tagName, 515 attributes, 516 unregisteredAttributes, 517 boundaryClass, 518 isEditableTree 519 }) 520 ); 521 if (isText(pointer) && getText(pointer).length === 0) { 522 remove(pointer); 523 } 524 pointer = append(newNode, ""); 525 }); 526 } 527 if (i === 0) { 528 if (onStartIndex && start === 0) { 529 onStartIndex(tree, pointer); 530 } 531 if (onEndIndex && end === 0) { 532 onEndIndex(tree, pointer); 533 } 534 } 535 if (character === OBJECT_REPLACEMENT_CHARACTER) { 536 const replacement = replacements[i]; 537 if (!replacement) { 538 continue; 539 } 540 const { type, attributes, innerHTML } = replacement; 541 const formatType = get_format_type_getFormatType(type); 542 if (isEditableTree && type === "#comment") { 543 pointer = append(getParent(pointer), { 544 type: "span", 545 attributes: { 546 contenteditable: "false", 547 "data-rich-text-comment": attributes["data-rich-text-comment"] 548 } 549 }); 550 append( 551 append(pointer, { type: "span" }), 552 attributes["data-rich-text-comment"].trim() 553 ); 554 } else if (!isEditableTree && type === "script") { 555 pointer = append( 556 getParent(pointer), 557 fromFormat({ 558 type: "script", 559 isEditableTree 560 }) 561 ); 562 append(pointer, { 563 html: decodeURIComponent( 564 attributes["data-rich-text-script"] 565 ) 566 }); 567 } else if (formatType?.contentEditable === false) { 568 pointer = getParent(pointer); 569 if (isEditableTree) { 570 const attrs = { 571 contenteditable: "false", 572 "data-rich-text-bogus": true 573 }; 574 if (start === i && end === i + 1) { 575 attrs["data-rich-text-format-boundary"] = true; 576 } 577 pointer = append(pointer, { 578 type: "span", 579 attributes: attrs 580 }); 581 if (isEditableTree && i + 1 === text.length) { 582 append(getParent(pointer), ZWNBSP); 583 } 584 } 585 pointer = append( 586 pointer, 587 fromFormat({ 588 ...replacement, 589 isEditableTree 590 }) 591 ); 592 if (innerHTML) { 593 append(pointer, { 594 html: innerHTML 595 }); 596 } 597 } else { 598 pointer = append( 599 getParent(pointer), 600 fromFormat({ 601 ...replacement, 602 object: true, 603 isEditableTree 604 }) 605 ); 606 } 607 pointer = append(getParent(pointer), ""); 608 } else if (!preserveWhiteSpace && character === "\n") { 609 pointer = append(getParent(pointer), { 610 type: "br", 611 attributes: isEditableTree ? { 612 "data-rich-text-line-break": "true" 613 } : void 0, 614 object: true 615 }); 616 pointer = append(getParent(pointer), ""); 617 } else if (!isText(pointer)) { 618 pointer = append(getParent(pointer), character); 619 } else { 620 appendText(pointer, character); 621 } 622 if (onStartIndex && start === i + 1) { 623 onStartIndex(tree, pointer); 624 } 625 if (onEndIndex && end === i + 1) { 626 onEndIndex(tree, pointer); 627 } 628 if (shouldInsertPadding && i === text.length) { 629 append(getParent(pointer), ZWNBSP); 630 if (placeholder && text.length === 0) { 631 append(getParent(pointer), { 632 type: "span", 633 attributes: { 634 "data-rich-text-placeholder": placeholder, 635 // Necessary to prevent the placeholder from catching 636 // selection and being editable. 637 style: "pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;" 638 } 639 }); 640 } 641 } 642 lastCharacterFormats = characterFormats; 643 lastCharacter = character; 644 } 645 return tree; 646 } 647 648 649 ;// ./node_modules/@wordpress/rich-text/build-module/to-html-string.js 650 651 652 function toHTMLString({ value, preserveWhiteSpace }) { 653 const tree = toTree({ 654 value, 655 preserveWhiteSpace, 656 createEmpty, 657 append, 658 getLastChild, 659 getParent, 660 isText, 661 getText, 662 remove, 663 appendText 664 }); 665 return createChildrenHTML(tree.children); 666 } 667 function createEmpty() { 668 return {}; 669 } 670 function getLastChild({ children }) { 671 return children && children[children.length - 1]; 672 } 673 function append(parent, object) { 674 if (typeof object === "string") { 675 object = { text: object }; 676 } 677 object.parent = parent; 678 parent.children = parent.children || []; 679 parent.children.push(object); 680 return object; 681 } 682 function appendText(object, text) { 683 object.text += text; 684 } 685 function getParent({ parent }) { 686 return parent; 687 } 688 function isText({ text }) { 689 return typeof text === "string"; 690 } 691 function getText({ text }) { 692 return text; 693 } 694 function remove(object) { 695 const index = object.parent.children.indexOf(object); 696 if (index !== -1) { 697 object.parent.children.splice(index, 1); 698 } 699 return object; 700 } 701 function createElementHTML({ type, attributes, object, children }) { 702 if (type === "#comment") { 703 return `<!--$attributes["data-rich-text-comment"]}-->`; 704 } 705 let attributeString = ""; 706 for (const key in attributes) { 707 if (!(0,external_wp_escapeHtml_namespaceObject.isValidAttributeName)(key)) { 708 continue; 709 } 710 attributeString += ` $key}="${(0,external_wp_escapeHtml_namespaceObject.escapeAttribute)( 711 attributes[key] 712 )}"`; 713 } 714 if (object) { 715 return `<$type}$attributeString}>`; 716 } 717 return `<$type}$attributeString}>$createChildrenHTML( 718 children 719 )}</$type}>`; 720 } 721 function createChildrenHTML(children = []) { 722 return children.map((child) => { 723 if (child.html !== void 0) { 724 return child.html; 725 } 726 return child.text === void 0 ? createElementHTML(child) : (0,external_wp_escapeHtml_namespaceObject.escapeEditableHTML)(child.text); 727 }).join(""); 728 } 729 730 731 ;// ./node_modules/@wordpress/rich-text/build-module/get-text-content.js 732 733 function getTextContent({ text }) { 734 return text.replace(OBJECT_REPLACEMENT_CHARACTER, ""); 735 } 736 737 738 ;// ./node_modules/@wordpress/rich-text/build-module/create.js 739 740 741 742 743 744 745 746 function createEmptyValue() { 747 return { 748 formats: [], 749 replacements: [], 750 text: "" 751 }; 752 } 753 function toFormat({ tagName, attributes }) { 754 let formatType; 755 if (attributes && attributes.class) { 756 formatType = (0,external_wp_data_namespaceObject.select)(store).getFormatTypeForClassName( 757 attributes.class 758 ); 759 if (formatType) { 760 attributes.class = ` $attributes.class} `.replace(` $formatType.className} `, " ").trim(); 761 if (!attributes.class) { 762 delete attributes.class; 763 } 764 } 765 } 766 if (!formatType) { 767 formatType = (0,external_wp_data_namespaceObject.select)(store).getFormatTypeForBareElement(tagName); 768 } 769 if (!formatType) { 770 return attributes ? { type: tagName, attributes } : { type: tagName }; 771 } 772 if (formatType.__experimentalCreatePrepareEditableTree && !formatType.__experimentalCreateOnChangeEditableValue) { 773 return null; 774 } 775 if (!attributes) { 776 return { formatType, type: formatType.name, tagName }; 777 } 778 const registeredAttributes = {}; 779 const unregisteredAttributes = {}; 780 const _attributes = { ...attributes }; 781 for (const key in formatType.attributes) { 782 const name = formatType.attributes[key]; 783 registeredAttributes[key] = _attributes[name]; 784 delete _attributes[name]; 785 if (typeof registeredAttributes[key] === "undefined") { 786 delete registeredAttributes[key]; 787 } 788 } 789 for (const name in _attributes) { 790 unregisteredAttributes[name] = attributes[name]; 791 } 792 if (formatType.contentEditable === false) { 793 delete unregisteredAttributes.contenteditable; 794 } 795 return { 796 formatType, 797 type: formatType.name, 798 tagName, 799 attributes: registeredAttributes, 800 unregisteredAttributes 801 }; 802 } 803 class RichTextData { 804 #value; 805 static empty() { 806 return new RichTextData(); 807 } 808 static fromPlainText(text) { 809 return new RichTextData(create({ text })); 810 } 811 static fromHTMLString(html) { 812 return new RichTextData(create({ html })); 813 } 814 /** 815 * Create a RichTextData instance from an HTML element. 816 * 817 * @param {HTMLElement} htmlElement The HTML element to create the instance from. 818 * @param {{preserveWhiteSpace?: boolean}} options Options. 819 * @return {RichTextData} The RichTextData instance. 820 */ 821 static fromHTMLElement(htmlElement, options = {}) { 822 const { preserveWhiteSpace = false } = options; 823 const element = preserveWhiteSpace ? htmlElement : collapseWhiteSpace(htmlElement); 824 const richTextData = new RichTextData(create({ element })); 825 Object.defineProperty(richTextData, "originalHTML", { 826 value: htmlElement.innerHTML 827 }); 828 return richTextData; 829 } 830 constructor(init = createEmptyValue()) { 831 this.#value = init; 832 } 833 toPlainText() { 834 return getTextContent(this.#value); 835 } 836 // We could expose `toHTMLElement` at some point as well, but we'd only use 837 // it internally. 838 /** 839 * Convert the rich text value to an HTML string. 840 * 841 * @param {{preserveWhiteSpace?: boolean}} options Options. 842 * @return {string} The HTML string. 843 */ 844 toHTMLString({ preserveWhiteSpace } = {}) { 845 return this.originalHTML || toHTMLString({ value: this.#value, preserveWhiteSpace }); 846 } 847 valueOf() { 848 return this.toHTMLString(); 849 } 850 toString() { 851 return this.toHTMLString(); 852 } 853 toJSON() { 854 return this.toHTMLString(); 855 } 856 get length() { 857 return this.text.length; 858 } 859 get formats() { 860 return this.#value.formats; 861 } 862 get replacements() { 863 return this.#value.replacements; 864 } 865 get text() { 866 return this.#value.text; 867 } 868 } 869 for (const name of Object.getOwnPropertyNames(String.prototype)) { 870 if (RichTextData.prototype.hasOwnProperty(name)) { 871 continue; 872 } 873 Object.defineProperty(RichTextData.prototype, name, { 874 value(...args) { 875 return this.toHTMLString()[name](...args); 876 } 877 }); 878 } 879 function create({ 880 element, 881 text, 882 html, 883 range, 884 __unstableIsEditableTree: isEditableTree 885 } = {}) { 886 if (html instanceof RichTextData) { 887 return { 888 text: html.text, 889 formats: html.formats, 890 replacements: html.replacements 891 }; 892 } 893 if (typeof text === "string" && text.length > 0) { 894 return { 895 formats: Array(text.length), 896 replacements: Array(text.length), 897 text 898 }; 899 } 900 if (typeof html === "string" && html.length > 0) { 901 element = createElement(document, html); 902 } 903 if (typeof element !== "object") { 904 return createEmptyValue(); 905 } 906 return createFromElement({ 907 element, 908 range, 909 isEditableTree 910 }); 911 } 912 function accumulateSelection(accumulator, node, range, value) { 913 if (!range) { 914 return; 915 } 916 const { parentNode } = node; 917 const { startContainer, startOffset, endContainer, endOffset } = range; 918 const currentLength = accumulator.text.length; 919 if (value.start !== void 0) { 920 accumulator.start = currentLength + value.start; 921 } else if (node === startContainer && node.nodeType === node.TEXT_NODE) { 922 accumulator.start = currentLength + startOffset; 923 } else if (parentNode === startContainer && node === startContainer.childNodes[startOffset]) { 924 accumulator.start = currentLength; 925 } else if (parentNode === startContainer && node === startContainer.childNodes[startOffset - 1]) { 926 accumulator.start = currentLength + value.text.length; 927 } else if (node === startContainer) { 928 accumulator.start = currentLength; 929 } 930 if (value.end !== void 0) { 931 accumulator.end = currentLength + value.end; 932 } else if (node === endContainer && node.nodeType === node.TEXT_NODE) { 933 accumulator.end = currentLength + endOffset; 934 } else if (parentNode === endContainer && node === endContainer.childNodes[endOffset - 1]) { 935 accumulator.end = currentLength + value.text.length; 936 } else if (parentNode === endContainer && node === endContainer.childNodes[endOffset]) { 937 accumulator.end = currentLength; 938 } else if (node === endContainer) { 939 accumulator.end = currentLength + endOffset; 940 } 941 } 942 function filterRange(node, range, filter) { 943 if (!range) { 944 return; 945 } 946 const { startContainer, endContainer } = range; 947 let { startOffset, endOffset } = range; 948 if (node === startContainer) { 949 startOffset = filter(node.nodeValue.slice(0, startOffset)).length; 950 } 951 if (node === endContainer) { 952 endOffset = filter(node.nodeValue.slice(0, endOffset)).length; 953 } 954 return { startContainer, startOffset, endContainer, endOffset }; 955 } 956 function collapseWhiteSpace(element, isRoot = true) { 957 const clone = element.cloneNode(true); 958 clone.normalize(); 959 Array.from(clone.childNodes).forEach((node, i, nodes) => { 960 if (node.nodeType === node.TEXT_NODE) { 961 let newNodeValue = node.nodeValue; 962 if (/[\n\t\r\f]/.test(newNodeValue)) { 963 newNodeValue = newNodeValue.replace(/[\n\t\r\f]+/g, " "); 964 } 965 if (newNodeValue.indexOf(" ") !== -1) { 966 newNodeValue = newNodeValue.replace(/ {2,}/g, " "); 967 } 968 if (i === 0 && newNodeValue.startsWith(" ")) { 969 newNodeValue = newNodeValue.slice(1); 970 } else if (isRoot && i === nodes.length - 1 && newNodeValue.endsWith(" ")) { 971 newNodeValue = newNodeValue.slice(0, -1); 972 } 973 node.nodeValue = newNodeValue; 974 } else if (node.nodeType === node.ELEMENT_NODE) { 975 node.replaceWith(collapseWhiteSpace(node, false)); 976 } 977 }); 978 return clone; 979 } 980 const CARRIAGE_RETURN = "\r"; 981 function removeReservedCharacters(string) { 982 return string.replace( 983 new RegExp( 984 `[$ZWNBSP}$OBJECT_REPLACEMENT_CHARACTER}$CARRIAGE_RETURN}]`, 985 "gu" 986 ), 987 "" 988 ); 989 } 990 function createFromElement({ element, range, isEditableTree }) { 991 const accumulator = createEmptyValue(); 992 if (!element) { 993 return accumulator; 994 } 995 if (!element.hasChildNodes()) { 996 accumulateSelection(accumulator, element, range, createEmptyValue()); 997 return accumulator; 998 } 999 const length = element.childNodes.length; 1000 for (let index = 0; index < length; index++) { 1001 const node = element.childNodes[index]; 1002 const tagName = node.nodeName.toLowerCase(); 1003 if (node.nodeType === node.TEXT_NODE) { 1004 const text = removeReservedCharacters(node.nodeValue); 1005 range = filterRange(node, range, removeReservedCharacters); 1006 accumulateSelection(accumulator, node, range, { text }); 1007 accumulator.formats.length += text.length; 1008 accumulator.replacements.length += text.length; 1009 accumulator.text += text; 1010 continue; 1011 } 1012 if (node.nodeType === node.COMMENT_NODE || node.nodeType === node.ELEMENT_NODE && node.tagName === "SPAN" && node.hasAttribute("data-rich-text-comment")) { 1013 const value2 = { 1014 formats: [,], 1015 replacements: [ 1016 { 1017 type: "#comment", 1018 attributes: { 1019 "data-rich-text-comment": node.nodeType === node.COMMENT_NODE ? node.nodeValue : node.getAttribute( 1020 "data-rich-text-comment" 1021 ) 1022 } 1023 } 1024 ], 1025 text: OBJECT_REPLACEMENT_CHARACTER 1026 }; 1027 accumulateSelection(accumulator, node, range, value2); 1028 mergePair(accumulator, value2); 1029 continue; 1030 } 1031 if (node.nodeType !== node.ELEMENT_NODE) { 1032 continue; 1033 } 1034 if (isEditableTree && // Ignore any line breaks that are not inserted by us. 1035 tagName === "br" && !node.getAttribute("data-rich-text-line-break")) { 1036 accumulateSelection(accumulator, node, range, createEmptyValue()); 1037 continue; 1038 } 1039 if (tagName === "script") { 1040 const value2 = { 1041 formats: [,], 1042 replacements: [ 1043 { 1044 type: tagName, 1045 attributes: { 1046 "data-rich-text-script": node.getAttribute("data-rich-text-script") || encodeURIComponent(node.innerHTML) 1047 } 1048 } 1049 ], 1050 text: OBJECT_REPLACEMENT_CHARACTER 1051 }; 1052 accumulateSelection(accumulator, node, range, value2); 1053 mergePair(accumulator, value2); 1054 continue; 1055 } 1056 if (tagName === "br") { 1057 accumulateSelection(accumulator, node, range, createEmptyValue()); 1058 mergePair(accumulator, create({ text: "\n" })); 1059 continue; 1060 } 1061 const format = toFormat({ 1062 tagName, 1063 attributes: getAttributes({ element: node }) 1064 }); 1065 if (format?.formatType?.contentEditable === false) { 1066 delete format.formatType; 1067 accumulateSelection(accumulator, node, range, createEmptyValue()); 1068 mergePair(accumulator, { 1069 formats: [,], 1070 replacements: [ 1071 { 1072 ...format, 1073 innerHTML: node.innerHTML 1074 } 1075 ], 1076 text: OBJECT_REPLACEMENT_CHARACTER 1077 }); 1078 continue; 1079 } 1080 if (format) { 1081 delete format.formatType; 1082 } 1083 const value = createFromElement({ 1084 element: node, 1085 range, 1086 isEditableTree 1087 }); 1088 accumulateSelection(accumulator, node, range, value); 1089 if (!format || node.getAttribute("data-rich-text-placeholder") || node.getAttribute("data-rich-text-bogus")) { 1090 mergePair(accumulator, value); 1091 } else if (value.text.length === 0) { 1092 if (format.attributes) { 1093 mergePair(accumulator, { 1094 formats: [,], 1095 replacements: [format], 1096 text: OBJECT_REPLACEMENT_CHARACTER 1097 }); 1098 } 1099 } else { 1100 let mergeFormats2 = function(formats) { 1101 if (mergeFormats2.formats === formats) { 1102 return mergeFormats2.newFormats; 1103 } 1104 const newFormats = formats ? [format, ...formats] : [format]; 1105 mergeFormats2.formats = formats; 1106 mergeFormats2.newFormats = newFormats; 1107 return newFormats; 1108 }; 1109 var mergeFormats = mergeFormats2; 1110 mergeFormats2.newFormats = [format]; 1111 mergePair(accumulator, { 1112 ...value, 1113 formats: Array.from(value.formats, mergeFormats2) 1114 }); 1115 } 1116 } 1117 return accumulator; 1118 } 1119 function getAttributes({ element }) { 1120 if (!element.hasAttributes()) { 1121 return; 1122 } 1123 const length = element.attributes.length; 1124 let accumulator; 1125 for (let i = 0; i < length; i++) { 1126 const { name, value } = element.attributes[i]; 1127 if (name.indexOf("data-rich-text-") === 0) { 1128 continue; 1129 } 1130 const safeName = /^on/i.test(name) ? "data-disable-rich-text-" + name : name; 1131 accumulator = accumulator || {}; 1132 accumulator[safeName] = value; 1133 } 1134 return accumulator; 1135 } 1136 1137 1138 ;// ./node_modules/@wordpress/rich-text/build-module/concat.js 1139 1140 1141 function mergePair(a, b) { 1142 a.formats = a.formats.concat(b.formats); 1143 a.replacements = a.replacements.concat(b.replacements); 1144 a.text += b.text; 1145 return a; 1146 } 1147 function concat(...values) { 1148 return normaliseFormats(values.reduce(mergePair, create())); 1149 } 1150 1151 1152 ;// ./node_modules/@wordpress/rich-text/build-module/get-active-format.js 1153 1154 function getActiveFormat(value, formatType) { 1155 return getActiveFormats(value).find( 1156 ({ type }) => type === formatType 1157 ); 1158 } 1159 1160 1161 ;// ./node_modules/@wordpress/rich-text/build-module/get-active-object.js 1162 1163 function getActiveObject({ start, end, replacements, text }) { 1164 if (start + 1 !== end || text[start] !== OBJECT_REPLACEMENT_CHARACTER) { 1165 return; 1166 } 1167 return replacements[start]; 1168 } 1169 1170 1171 ;// ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js 1172 function isCollapsed({ 1173 start, 1174 end 1175 }) { 1176 if (start === void 0 || end === void 0) { 1177 return; 1178 } 1179 return start === end; 1180 } 1181 1182 1183 ;// ./node_modules/@wordpress/rich-text/build-module/is-empty.js 1184 function isEmpty({ text }) { 1185 return text.length === 0; 1186 } 1187 1188 1189 ;// ./node_modules/@wordpress/rich-text/build-module/join.js 1190 1191 1192 function join(values, separator = "") { 1193 if (typeof separator === "string") { 1194 separator = create({ text: separator }); 1195 } 1196 return normaliseFormats( 1197 values.reduce((accumulator, { formats, replacements, text }) => ({ 1198 formats: accumulator.formats.concat(separator.formats, formats), 1199 replacements: accumulator.replacements.concat( 1200 separator.replacements, 1201 replacements 1202 ), 1203 text: accumulator.text + separator.text + text 1204 })) 1205 ); 1206 } 1207 1208 1209 ;// ./node_modules/@wordpress/rich-text/build-module/register-format-type.js 1210 1211 1212 function registerFormatType(name, settings) { 1213 settings = { 1214 name, 1215 ...settings 1216 }; 1217 if (typeof settings.name !== "string") { 1218 window.console.error("Format names must be strings."); 1219 return; 1220 } 1221 if (!/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(settings.name)) { 1222 window.console.error( 1223 "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" 1224 ); 1225 return; 1226 } 1227 if ((0,external_wp_data_namespaceObject.select)(store).getFormatType(settings.name)) { 1228 window.console.error( 1229 'Format "' + settings.name + '" is already registered.' 1230 ); 1231 return; 1232 } 1233 if (typeof settings.tagName !== "string" || settings.tagName === "") { 1234 window.console.error("Format tag names must be a string."); 1235 return; 1236 } 1237 if ((typeof settings.className !== "string" || settings.className === "") && settings.className !== null) { 1238 window.console.error( 1239 "Format class names must be a string, or null to handle bare elements." 1240 ); 1241 return; 1242 } 1243 if (!/^[_a-zA-Z]+[a-zA-Z0-9_-]*$/.test(settings.className)) { 1244 window.console.error( 1245 "A class name must begin with a letter, followed by any number of hyphens, underscores, letters, or numbers." 1246 ); 1247 return; 1248 } 1249 if (settings.className === null) { 1250 const formatTypeForBareElement = (0,external_wp_data_namespaceObject.select)( 1251 store 1252 ).getFormatTypeForBareElement(settings.tagName); 1253 if (formatTypeForBareElement && formatTypeForBareElement.name !== "core/unknown") { 1254 window.console.error( 1255 `Format "$formatTypeForBareElement.name}" is already registered to handle bare tag name "$settings.tagName}".` 1256 ); 1257 return; 1258 } 1259 } else { 1260 const formatTypeForClassName = (0,external_wp_data_namespaceObject.select)( 1261 store 1262 ).getFormatTypeForClassName(settings.className); 1263 if (formatTypeForClassName) { 1264 window.console.error( 1265 `Format "$formatTypeForClassName.name}" is already registered to handle class name "$settings.className}".` 1266 ); 1267 return; 1268 } 1269 } 1270 if (!("title" in settings) || settings.title === "") { 1271 window.console.error( 1272 'The format "' + settings.name + '" must have a title.' 1273 ); 1274 return; 1275 } 1276 if ("keywords" in settings && settings.keywords.length > 3) { 1277 window.console.error( 1278 'The format "' + settings.name + '" can have a maximum of 3 keywords.' 1279 ); 1280 return; 1281 } 1282 if (typeof settings.title !== "string") { 1283 window.console.error("Format titles must be strings."); 1284 return; 1285 } 1286 (0,external_wp_data_namespaceObject.dispatch)(store).addFormatTypes(settings); 1287 return settings; 1288 } 1289 1290 1291 ;// ./node_modules/@wordpress/rich-text/build-module/remove-format.js 1292 1293 function removeFormat(value, formatType, startIndex = value.start, endIndex = value.end) { 1294 const { formats, activeFormats } = value; 1295 const newFormats = formats.slice(); 1296 if (startIndex === endIndex) { 1297 const format = newFormats[startIndex]?.find( 1298 ({ type }) => type === formatType 1299 ); 1300 if (format) { 1301 while (newFormats[startIndex]?.find( 1302 (newFormat) => newFormat === format 1303 )) { 1304 filterFormats(newFormats, startIndex, formatType); 1305 startIndex--; 1306 } 1307 endIndex++; 1308 while (newFormats[endIndex]?.find( 1309 (newFormat) => newFormat === format 1310 )) { 1311 filterFormats(newFormats, endIndex, formatType); 1312 endIndex++; 1313 } 1314 } 1315 } else { 1316 for (let i = startIndex; i < endIndex; i++) { 1317 if (newFormats[i]) { 1318 filterFormats(newFormats, i, formatType); 1319 } 1320 } 1321 } 1322 return normaliseFormats({ 1323 ...value, 1324 formats: newFormats, 1325 activeFormats: activeFormats?.filter(({ type }) => type !== formatType) || [] 1326 }); 1327 } 1328 function filterFormats(formats, index, formatType) { 1329 const newFormats = formats[index].filter( 1330 ({ type }) => type !== formatType 1331 ); 1332 if (newFormats.length) { 1333 formats[index] = newFormats; 1334 } else { 1335 delete formats[index]; 1336 } 1337 } 1338 1339 1340 ;// ./node_modules/@wordpress/rich-text/build-module/insert.js 1341 1342 1343 function insert(value, valueToInsert, startIndex = value.start, endIndex = value.end) { 1344 const { formats, replacements, text } = value; 1345 if (typeof valueToInsert === "string") { 1346 valueToInsert = create({ text: valueToInsert }); 1347 } 1348 const index = startIndex + valueToInsert.text.length; 1349 return normaliseFormats({ 1350 formats: formats.slice(0, startIndex).concat(valueToInsert.formats, formats.slice(endIndex)), 1351 replacements: replacements.slice(0, startIndex).concat( 1352 valueToInsert.replacements, 1353 replacements.slice(endIndex) 1354 ), 1355 text: text.slice(0, startIndex) + valueToInsert.text + text.slice(endIndex), 1356 start: index, 1357 end: index 1358 }); 1359 } 1360 1361 1362 ;// ./node_modules/@wordpress/rich-text/build-module/remove.js 1363 1364 1365 function remove_remove(value, startIndex, endIndex) { 1366 return insert(value, create(), startIndex, endIndex); 1367 } 1368 1369 1370 ;// ./node_modules/@wordpress/rich-text/build-module/replace.js 1371 1372 function replace_replace({ formats, replacements, text, start, end }, pattern, replacement) { 1373 text = text.replace(pattern, (match, ...rest) => { 1374 const offset = rest[rest.length - 2]; 1375 let newText = replacement; 1376 let newFormats; 1377 let newReplacements; 1378 if (typeof newText === "function") { 1379 newText = replacement(match, ...rest); 1380 } 1381 if (typeof newText === "object") { 1382 newFormats = newText.formats; 1383 newReplacements = newText.replacements; 1384 newText = newText.text; 1385 } else { 1386 newFormats = Array(newText.length); 1387 newReplacements = Array(newText.length); 1388 if (formats[offset]) { 1389 newFormats = newFormats.fill(formats[offset]); 1390 } 1391 } 1392 formats = formats.slice(0, offset).concat(newFormats, formats.slice(offset + match.length)); 1393 replacements = replacements.slice(0, offset).concat( 1394 newReplacements, 1395 replacements.slice(offset + match.length) 1396 ); 1397 if (start) { 1398 start = end = offset + newText.length; 1399 } 1400 return newText; 1401 }); 1402 return normaliseFormats({ formats, replacements, text, start, end }); 1403 } 1404 1405 1406 ;// ./node_modules/@wordpress/rich-text/build-module/insert-object.js 1407 1408 1409 function insertObject(value, formatToInsert, startIndex, endIndex) { 1410 const valueToInsert = { 1411 formats: [,], 1412 replacements: [formatToInsert], 1413 text: OBJECT_REPLACEMENT_CHARACTER 1414 }; 1415 return insert(value, valueToInsert, startIndex, endIndex); 1416 } 1417 1418 1419 ;// ./node_modules/@wordpress/rich-text/build-module/slice.js 1420 function slice(value, startIndex = value.start, endIndex = value.end) { 1421 const { formats, replacements, text } = value; 1422 if (startIndex === void 0 || endIndex === void 0) { 1423 return { ...value }; 1424 } 1425 return { 1426 formats: formats.slice(startIndex, endIndex), 1427 replacements: replacements.slice(startIndex, endIndex), 1428 text: text.slice(startIndex, endIndex) 1429 }; 1430 } 1431 1432 1433 ;// ./node_modules/@wordpress/rich-text/build-module/split.js 1434 function split({ formats, replacements, text, start, end }, string) { 1435 if (typeof string !== "string") { 1436 return splitAtSelection(...arguments); 1437 } 1438 let nextStart = 0; 1439 return text.split(string).map((substring) => { 1440 const startIndex = nextStart; 1441 const value = { 1442 formats: formats.slice(startIndex, startIndex + substring.length), 1443 replacements: replacements.slice( 1444 startIndex, 1445 startIndex + substring.length 1446 ), 1447 text: substring 1448 }; 1449 nextStart += string.length + substring.length; 1450 if (start !== void 0 && end !== void 0) { 1451 if (start >= startIndex && start < nextStart) { 1452 value.start = start - startIndex; 1453 } else if (start < startIndex && end > startIndex) { 1454 value.start = 0; 1455 } 1456 if (end >= startIndex && end < nextStart) { 1457 value.end = end - startIndex; 1458 } else if (start < nextStart && end > nextStart) { 1459 value.end = substring.length; 1460 } 1461 } 1462 return value; 1463 }); 1464 } 1465 function splitAtSelection({ formats, replacements, text, start, end }, startIndex = start, endIndex = end) { 1466 if (start === void 0 || end === void 0) { 1467 return; 1468 } 1469 const before = { 1470 formats: formats.slice(0, startIndex), 1471 replacements: replacements.slice(0, startIndex), 1472 text: text.slice(0, startIndex) 1473 }; 1474 const after = { 1475 formats: formats.slice(endIndex), 1476 replacements: replacements.slice(endIndex), 1477 text: text.slice(endIndex), 1478 start: 0, 1479 end: 0 1480 }; 1481 return [before, after]; 1482 } 1483 1484 1485 ;// ./node_modules/@wordpress/rich-text/build-module/is-range-equal.js 1486 function isRangeEqual(a, b) { 1487 return a === b || a && b && a.startContainer === b.startContainer && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset; 1488 } 1489 1490 1491 ;// ./node_modules/@wordpress/rich-text/build-module/to-dom.js 1492 1493 1494 1495 const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML"; 1496 function createPathToNode(node, rootNode, path) { 1497 const parentNode = node.parentNode; 1498 let i = 0; 1499 while (node = node.previousSibling) { 1500 i++; 1501 } 1502 path = [i, ...path]; 1503 if (parentNode !== rootNode) { 1504 path = createPathToNode(parentNode, rootNode, path); 1505 } 1506 return path; 1507 } 1508 function getNodeByPath(node, path) { 1509 path = [...path]; 1510 while (node && path.length > 1) { 1511 node = node.childNodes[path.shift()]; 1512 } 1513 return { 1514 node, 1515 offset: path[0] 1516 }; 1517 } 1518 function to_dom_append(element, child) { 1519 if (child.html !== void 0) { 1520 return element.innerHTML += child.html; 1521 } 1522 if (typeof child === "string") { 1523 child = element.ownerDocument.createTextNode(child); 1524 } 1525 const { type, attributes } = child; 1526 if (type) { 1527 if (type === "#comment") { 1528 child = element.ownerDocument.createComment( 1529 attributes["data-rich-text-comment"] 1530 ); 1531 } else { 1532 const parentNamespace = element.namespaceURI; 1533 if (type === "math") { 1534 child = element.ownerDocument.createElementNS( 1535 MATHML_NAMESPACE, 1536 type 1537 ); 1538 } else if (parentNamespace === MATHML_NAMESPACE) { 1539 if (element.tagName === "MTEXT") { 1540 child = element.ownerDocument.createElement(type); 1541 } else { 1542 child = element.ownerDocument.createElementNS( 1543 MATHML_NAMESPACE, 1544 type 1545 ); 1546 } 1547 } else { 1548 child = element.ownerDocument.createElement(type); 1549 } 1550 for (const key in attributes) { 1551 child.setAttribute(key, attributes[key]); 1552 } 1553 } 1554 } 1555 return element.appendChild(child); 1556 } 1557 function to_dom_appendText(node, text) { 1558 node.appendData(text); 1559 } 1560 function to_dom_getLastChild({ lastChild }) { 1561 return lastChild; 1562 } 1563 function to_dom_getParent({ parentNode }) { 1564 return parentNode; 1565 } 1566 function to_dom_isText(node) { 1567 return node.nodeType === node.TEXT_NODE; 1568 } 1569 function to_dom_getText({ nodeValue }) { 1570 return nodeValue; 1571 } 1572 function to_dom_remove(node) { 1573 return node.parentNode.removeChild(node); 1574 } 1575 function toDom({ 1576 value, 1577 prepareEditableTree, 1578 isEditableTree = true, 1579 placeholder, 1580 doc = document 1581 }) { 1582 let startPath = []; 1583 let endPath = []; 1584 if (prepareEditableTree) { 1585 value = { 1586 ...value, 1587 formats: prepareEditableTree(value) 1588 }; 1589 } 1590 const createEmpty = () => createElement(doc, ""); 1591 const tree = toTree({ 1592 value, 1593 createEmpty, 1594 append: to_dom_append, 1595 getLastChild: to_dom_getLastChild, 1596 getParent: to_dom_getParent, 1597 isText: to_dom_isText, 1598 getText: to_dom_getText, 1599 remove: to_dom_remove, 1600 appendText: to_dom_appendText, 1601 onStartIndex(body, pointer) { 1602 startPath = createPathToNode(pointer, body, [ 1603 pointer.nodeValue.length 1604 ]); 1605 }, 1606 onEndIndex(body, pointer) { 1607 endPath = createPathToNode(pointer, body, [ 1608 pointer.nodeValue.length 1609 ]); 1610 }, 1611 isEditableTree, 1612 placeholder 1613 }); 1614 return { 1615 body: tree, 1616 selection: { startPath, endPath } 1617 }; 1618 } 1619 function apply({ 1620 value, 1621 current, 1622 prepareEditableTree, 1623 __unstableDomOnly, 1624 placeholder 1625 }) { 1626 const { body, selection } = toDom({ 1627 value, 1628 prepareEditableTree, 1629 placeholder, 1630 doc: current.ownerDocument 1631 }); 1632 applyValue(body, current); 1633 if (value.start !== void 0 && !__unstableDomOnly) { 1634 applySelection(selection, current); 1635 } 1636 } 1637 function applyValue(future, current) { 1638 let i = 0; 1639 let futureChild; 1640 while (futureChild = future.firstChild) { 1641 const currentChild = current.childNodes[i]; 1642 if (!currentChild) { 1643 current.appendChild(futureChild); 1644 } else if (!currentChild.isEqualNode(futureChild)) { 1645 if (currentChild.nodeName !== futureChild.nodeName || currentChild.nodeType === currentChild.TEXT_NODE && currentChild.data !== futureChild.data) { 1646 current.replaceChild(futureChild, currentChild); 1647 } else { 1648 const currentAttributes = currentChild.attributes; 1649 const futureAttributes = futureChild.attributes; 1650 if (currentAttributes) { 1651 let ii = currentAttributes.length; 1652 while (ii--) { 1653 const { name } = currentAttributes[ii]; 1654 if (!futureChild.getAttribute(name)) { 1655 currentChild.removeAttribute(name); 1656 } 1657 } 1658 } 1659 if (futureAttributes) { 1660 for (let ii = 0; ii < futureAttributes.length; ii++) { 1661 const { name, value } = futureAttributes[ii]; 1662 if (currentChild.getAttribute(name) !== value) { 1663 currentChild.setAttribute(name, value); 1664 } 1665 } 1666 } 1667 applyValue(futureChild, currentChild); 1668 future.removeChild(futureChild); 1669 } 1670 } else { 1671 future.removeChild(futureChild); 1672 } 1673 i++; 1674 } 1675 while (current.childNodes[i]) { 1676 current.removeChild(current.childNodes[i]); 1677 } 1678 } 1679 function applySelection({ startPath, endPath }, current) { 1680 const { node: startContainer, offset: startOffset } = getNodeByPath( 1681 current, 1682 startPath 1683 ); 1684 const { node: endContainer, offset: endOffset } = getNodeByPath( 1685 current, 1686 endPath 1687 ); 1688 const { ownerDocument } = current; 1689 const { defaultView } = ownerDocument; 1690 const selection = defaultView.getSelection(); 1691 const range = ownerDocument.createRange(); 1692 range.setStart(startContainer, startOffset); 1693 range.setEnd(endContainer, endOffset); 1694 const { activeElement } = ownerDocument; 1695 if (selection.rangeCount > 0) { 1696 if (isRangeEqual(range, selection.getRangeAt(0))) { 1697 return; 1698 } 1699 selection.removeAllRanges(); 1700 } 1701 selection.addRange(range); 1702 if (activeElement !== ownerDocument.activeElement) { 1703 if (activeElement instanceof defaultView.HTMLElement) { 1704 activeElement.focus(); 1705 } 1706 } 1707 } 1708 1709 1710 ;// external ["wp","a11y"] 1711 const external_wp_a11y_namespaceObject = window["wp"]["a11y"]; 1712 ;// external ["wp","i18n"] 1713 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; 1714 ;// ./node_modules/@wordpress/rich-text/build-module/toggle-format.js 1715 1716 1717 1718 1719 1720 function toggleFormat(value, format) { 1721 if (getActiveFormat(value, format.type)) { 1722 if (format.title) { 1723 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)((0,external_wp_i18n_namespaceObject.__)("%s removed."), format.title), "assertive"); 1724 } 1725 return removeFormat(value, format.type); 1726 } 1727 if (format.title) { 1728 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)((0,external_wp_i18n_namespaceObject.__)("%s applied."), format.title), "assertive"); 1729 } 1730 return applyFormat(value, format); 1731 } 1732 1733 1734 ;// ./node_modules/@wordpress/rich-text/build-module/unregister-format-type.js 1735 1736 1737 function unregisterFormatType(name) { 1738 const oldFormat = (0,external_wp_data_namespaceObject.select)(store).getFormatType(name); 1739 if (!oldFormat) { 1740 window.console.error(`Format $name} is not registered.`); 1741 return; 1742 } 1743 (0,external_wp_data_namespaceObject.dispatch)(store).removeFormatTypes(name); 1744 return oldFormat; 1745 } 1746 1747 1748 ;// external ["wp","element"] 1749 const external_wp_element_namespaceObject = window["wp"]["element"]; 1750 ;// external ["wp","deprecated"] 1751 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; 1752 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); 1753 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js 1754 1755 1756 1757 function useAnchorRef({ ref, value, settings = {} }) { 1758 external_wp_deprecated_default()("`useAnchorRef` hook", { 1759 since: "6.1", 1760 alternative: "`useAnchor` hook" 1761 }); 1762 const { tagName, className, name } = settings; 1763 const activeFormat = name ? getActiveFormat(value, name) : void 0; 1764 return (0,external_wp_element_namespaceObject.useMemo)(() => { 1765 if (!ref.current) { 1766 return; 1767 } 1768 const { 1769 ownerDocument: { defaultView } 1770 } = ref.current; 1771 const selection = defaultView.getSelection(); 1772 if (!selection.rangeCount) { 1773 return; 1774 } 1775 const range = selection.getRangeAt(0); 1776 if (!activeFormat) { 1777 return range; 1778 } 1779 let element = range.startContainer; 1780 element = element.nextElementSibling || element; 1781 while (element.nodeType !== element.ELEMENT_NODE) { 1782 element = element.parentNode; 1783 } 1784 return element.closest( 1785 tagName + (className ? "." + className : "") 1786 ); 1787 }, [activeFormat, value.start, value.end, tagName, className]); 1788 } 1789 1790 1791 ;// external ["wp","compose"] 1792 const external_wp_compose_namespaceObject = window["wp"]["compose"]; 1793 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-anchor.js 1794 1795 1796 function getFormatElement(range, editableContentElement, tagName, className) { 1797 let element = range.startContainer; 1798 if (element.nodeType === element.TEXT_NODE && range.startOffset === element.length && element.nextSibling) { 1799 element = element.nextSibling; 1800 while (element.firstChild) { 1801 element = element.firstChild; 1802 } 1803 } 1804 if (element.nodeType !== element.ELEMENT_NODE) { 1805 element = element.parentElement; 1806 } 1807 if (!element) { 1808 return; 1809 } 1810 if (element === editableContentElement) { 1811 return; 1812 } 1813 if (!editableContentElement.contains(element)) { 1814 return; 1815 } 1816 const selector = tagName + (className ? "." + className : ""); 1817 while (element !== editableContentElement) { 1818 if (element.matches(selector)) { 1819 return element; 1820 } 1821 element = element.parentElement; 1822 } 1823 } 1824 function createVirtualAnchorElement(range, editableContentElement) { 1825 return { 1826 contextElement: editableContentElement, 1827 getBoundingClientRect() { 1828 return editableContentElement.contains(range.startContainer) ? range.getBoundingClientRect() : editableContentElement.getBoundingClientRect(); 1829 } 1830 }; 1831 } 1832 function getAnchor(editableContentElement, tagName, className) { 1833 if (!editableContentElement) { 1834 return; 1835 } 1836 const { ownerDocument } = editableContentElement; 1837 const { defaultView } = ownerDocument; 1838 const selection = defaultView.getSelection(); 1839 if (!selection) { 1840 return; 1841 } 1842 if (!selection.rangeCount) { 1843 return; 1844 } 1845 const range = selection.getRangeAt(0); 1846 if (!range || !range.startContainer) { 1847 return; 1848 } 1849 const formatElement = getFormatElement( 1850 range, 1851 editableContentElement, 1852 tagName, 1853 className 1854 ); 1855 if (formatElement) { 1856 return formatElement; 1857 } 1858 return createVirtualAnchorElement(range, editableContentElement); 1859 } 1860 function useAnchor({ editableContentElement, settings = {} }) { 1861 const { tagName, className, isActive } = settings; 1862 const [anchor, setAnchor] = (0,external_wp_element_namespaceObject.useState)( 1863 () => getAnchor(editableContentElement, tagName, className) 1864 ); 1865 const wasActive = (0,external_wp_compose_namespaceObject.usePrevious)(isActive); 1866 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { 1867 if (!editableContentElement) { 1868 return; 1869 } 1870 function callback() { 1871 setAnchor( 1872 getAnchor(editableContentElement, tagName, className) 1873 ); 1874 } 1875 function attach() { 1876 ownerDocument.addEventListener("selectionchange", callback); 1877 } 1878 function detach() { 1879 ownerDocument.removeEventListener("selectionchange", callback); 1880 } 1881 const { ownerDocument } = editableContentElement; 1882 if (editableContentElement === ownerDocument.activeElement || // When a link is created, we need to attach the popover to the newly created anchor. 1883 !wasActive && isActive || // Sometimes we're _removing_ an active anchor, such as the inline color popover. 1884 // When we add the color, it switches from a virtual anchor to a `<mark>` element. 1885 // When we _remove_ the color, it switches from a `<mark>` element to a virtual anchor. 1886 wasActive && !isActive) { 1887 setAnchor( 1888 getAnchor(editableContentElement, tagName, className) 1889 ); 1890 attach(); 1891 } 1892 editableContentElement.addEventListener("focusin", attach); 1893 editableContentElement.addEventListener("focusout", detach); 1894 return () => { 1895 detach(); 1896 editableContentElement.removeEventListener("focusin", attach); 1897 editableContentElement.removeEventListener("focusout", detach); 1898 }; 1899 }, [editableContentElement, tagName, className, isActive, wasActive]); 1900 return anchor; 1901 } 1902 1903 1904 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-default-style.js 1905 1906 const whiteSpace = "pre-wrap"; 1907 const minWidth = "1px"; 1908 function useDefaultStyle() { 1909 return (0,external_wp_element_namespaceObject.useCallback)((element) => { 1910 if (!element) { 1911 return; 1912 } 1913 element.style.whiteSpace = whiteSpace; 1914 element.style.minWidth = minWidth; 1915 }, []); 1916 } 1917 1918 1919 ;// ./node_modules/colord/index.mjs 1920 var r={grad:.9,turn:360,rad:360/(2*Math.PI)},t=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n+0},e=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r>t?r:t},u=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},a=function(r){return{r:e(r.r,0,255),g:e(r.g,0,255),b:e(r.b,0,255),a:e(r.a)}},o=function(r){return{r:n(r.r),g:n(r.g),b:n(r.b),a:n(r.a,3)}},i=/^#([0-9a-f]{3,8})$/i,s=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},h=function(r){var t=r.r,n=r.g,e=r.b,u=r.a,a=Math.max(t,n,e),o=a-Math.min(t,n,e),i=o?a===t?(n-e)/o:a===n?2+(e-t)/o:4+(t-n)/o:0;return{h:60*(i<0?i+6:i),s:a?o/a*100:0,v:a/255*100,a:u}},b=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var a=Math.floor(t),o=e*(1-n),i=e*(1-(t-a)*n),s=e*(1-(1-t+a)*n),h=a%6;return{r:255*[e,i,o,o,s,e][h],g:255*[s,e,e,i,o,o][h],b:255*[o,o,s,e,e,i][h],a:u}},g=function(r){return{h:u(r.h),s:e(r.s,0,100),l:e(r.l,0,100),a:e(r.a)}},d=function(r){return{h:n(r.h),s:n(r.s),l:n(r.l),a:n(r.a,3)}},f=function(r){return b((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e},c=function(r){return{h:(t=h(r)).h,s:(u=(200-(n=t.s))*(e=t.v)/100)>0&&u<200?n*e/100/(u<=100?u:200-u)*100:0,l:u/2,a:t.a};var t,n,e,u},l=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,p=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,v=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,m=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,y={string:[[function(r){var t=i.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?n(parseInt(r[3]+r[3],16)/255,2):1}:6===r.length||8===r.length?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?n(parseInt(r.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(r){var t=v.exec(r)||m.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:a({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(t){var n=l.exec(t)||p.exec(t);if(!n)return null;var e,u,a=g({h:(e=n[1],u=n[2],void 0===u&&(u="deg"),Number(e)*(r[u]||1)),s:Number(n[3]),l:Number(n[4]),a:void 0===n[5]?1:Number(n[5])/(n[6]?100:1)});return f(a)},"hsl"]],object:[[function(r){var n=r.r,e=r.g,u=r.b,o=r.a,i=void 0===o?1:o;return t(n)&&t(e)&&t(u)?a({r:Number(n),g:Number(e),b:Number(u),a:Number(i)}):null},"rgb"],[function(r){var n=r.h,e=r.s,u=r.l,a=r.a,o=void 0===a?1:a;if(!t(n)||!t(e)||!t(u))return null;var i=g({h:Number(n),s:Number(e),l:Number(u),a:Number(o)});return f(i)},"hsl"],[function(r){var n=r.h,a=r.s,o=r.v,i=r.a,s=void 0===i?1:i;if(!t(n)||!t(a)||!t(o))return null;var h=function(r){return{h:u(r.h),s:e(r.s,0,100),v:e(r.v,0,100),a:e(r.a)}}({h:Number(n),s:Number(a),v:Number(o),a:Number(s)});return b(h)},"hsv"]]},N=function(r,t){for(var n=0;n<t.length;n++){var e=t[n][0](r);if(e)return[e,t[n][1]]}return[null,void 0]},x=function(r){return"string"==typeof r?N(r.trim(),y.string):"object"==typeof r&&null!==r?N(r,y.object):[null,void 0]},I=function(r){return x(r)[1]},M=function(r,t){var n=c(r);return{h:n.h,s:e(n.s+100*t,0,100),l:n.l,a:n.a}},H=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},$=function(r,t){var n=c(r);return{h:n.h,s:n.s,l:e(n.l+100*t,0,100),a:n.a}},j=function(){function r(r){this.parsed=x(r)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return r.prototype.isValid=function(){return null!==this.parsed},r.prototype.brightness=function(){return n(H(this.rgba),2)},r.prototype.isDark=function(){return H(this.rgba)<.5},r.prototype.isLight=function(){return H(this.rgba)>=.5},r.prototype.toHex=function(){return r=o(this.rgba),t=r.r,e=r.g,u=r.b,i=(a=r.a)<1?s(n(255*a)):"","#"+s(t)+s(e)+s(u)+i;var r,t,e,u,a,i},r.prototype.toRgb=function(){return o(this.rgba)},r.prototype.toRgbString=function(){return r=o(this.rgba),t=r.r,n=r.g,e=r.b,(u=r.a)<1?"rgba("+t+", "+n+", "+e+", "+u+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,u},r.prototype.toHsl=function(){return d(c(this.rgba))},r.prototype.toHslString=function(){return r=d(c(this.rgba)),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u},r.prototype.toHsv=function(){return r=h(this.rgba),{h:n(r.h),s:n(r.s),v:n(r.v),a:n(r.a,3)};var r},r.prototype.invert=function(){return w({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r},r.prototype.saturate=function(r){return void 0===r&&(r=.1),w(M(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),w(M(this.rgba,-r))},r.prototype.grayscale=function(){return w(M(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),w($(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),w($(this.rgba,-r))},r.prototype.rotate=function(r){return void 0===r&&(r=15),this.hue(this.hue()+r)},r.prototype.alpha=function(r){return"number"==typeof r?w({r:(t=this.rgba).r,g:t.g,b:t.b,a:r}):n(this.rgba.a,3);var t},r.prototype.hue=function(r){var t=c(this.rgba);return"number"==typeof r?w({h:r,s:t.s,l:t.l,a:t.a}):n(t.h)},r.prototype.isEqual=function(r){return this.toHex()===w(r).toHex()},r}(),w=function(r){return r instanceof j?r:new j(r)},S=(/* unused pure expression or super */ null && ([])),k=function(r){r.forEach(function(r){S.indexOf(r)<0&&(r(j,y),S.push(r))})},E=function(){return new j({r:255*Math.random(),g:255*Math.random(),b:255*Math.random()})}; 1921 1922 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js 1923 1924 1925 function useBoundaryStyle({ record }) { 1926 const ref = (0,external_wp_element_namespaceObject.useRef)(); 1927 const { activeFormats = [], replacements, start } = record.current; 1928 const activeReplacement = replacements[start]; 1929 (0,external_wp_element_namespaceObject.useEffect)(() => { 1930 if ((!activeFormats || !activeFormats.length) && !activeReplacement) { 1931 return; 1932 } 1933 const boundarySelector = "*[data-rich-text-format-boundary]"; 1934 const element = ref.current.querySelector(boundarySelector); 1935 if (!element) { 1936 return; 1937 } 1938 const { ownerDocument } = element; 1939 const { defaultView } = ownerDocument; 1940 const computedStyle = defaultView.getComputedStyle(element); 1941 const newColor = w(computedStyle.color).alpha(0.2).toRgbString(); 1942 const selector = `.rich-text:focus $boundarySelector}`; 1943 const rule = `background-color: $newColor}`; 1944 const style = `$selector} {$rule}}`; 1945 const globalStyleId = "rich-text-boundary-style"; 1946 let globalStyle = ownerDocument.getElementById(globalStyleId); 1947 if (!globalStyle) { 1948 globalStyle = ownerDocument.createElement("style"); 1949 globalStyle.id = globalStyleId; 1950 ownerDocument.head.appendChild(globalStyle); 1951 } 1952 if (globalStyle.innerHTML !== style) { 1953 globalStyle.innerHTML = style; 1954 } 1955 }, [activeFormats, activeReplacement]); 1956 return ref; 1957 } 1958 1959 1960 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/copy-handler.js 1961 1962 1963 1964 1965 var copy_handler_default = (props) => (element) => { 1966 function onCopy(event) { 1967 const { record } = props.current; 1968 const { ownerDocument } = element; 1969 if (isCollapsed(record.current) || !element.contains(ownerDocument.activeElement)) { 1970 return; 1971 } 1972 const selectedRecord = slice(record.current); 1973 const plainText = getTextContent(selectedRecord); 1974 const html = toHTMLString({ value: selectedRecord }); 1975 event.clipboardData.setData("text/plain", plainText); 1976 event.clipboardData.setData("text/html", html); 1977 event.clipboardData.setData("rich-text", "true"); 1978 event.preventDefault(); 1979 if (event.type === "cut") { 1980 ownerDocument.execCommand("delete"); 1981 } 1982 } 1983 const { defaultView } = element.ownerDocument; 1984 defaultView.addEventListener("copy", onCopy); 1985 defaultView.addEventListener("cut", onCopy); 1986 return () => { 1987 defaultView.removeEventListener("copy", onCopy); 1988 defaultView.removeEventListener("cut", onCopy); 1989 }; 1990 }; 1991 1992 1993 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/select-object.js 1994 var select_object_default = () => (element) => { 1995 function onClick(event) { 1996 const { target } = event; 1997 if (target === element || target.textContent && target.isContentEditable) { 1998 return; 1999 } 2000 const { ownerDocument } = target; 2001 const { defaultView } = ownerDocument; 2002 const selection = defaultView.getSelection(); 2003 if (selection.containsNode(target)) { 2004 return; 2005 } 2006 const range = ownerDocument.createRange(); 2007 const nodeToSelect = target.isContentEditable ? target : target.closest("[contenteditable]"); 2008 range.selectNode(nodeToSelect); 2009 selection.removeAllRanges(); 2010 selection.addRange(range); 2011 event.preventDefault(); 2012 } 2013 function onFocusIn(event) { 2014 if (event.relatedTarget && !element.contains(event.relatedTarget) && event.relatedTarget.tagName === "A") { 2015 onClick(event); 2016 } 2017 } 2018 element.addEventListener("click", onClick); 2019 element.addEventListener("focusin", onFocusIn); 2020 return () => { 2021 element.removeEventListener("click", onClick); 2022 element.removeEventListener("focusin", onFocusIn); 2023 }; 2024 }; 2025 2026 2027 ;// external ["wp","keycodes"] 2028 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; 2029 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/format-boundaries.js 2030 2031 2032 const EMPTY_ACTIVE_FORMATS = []; 2033 var format_boundaries_default = (props) => (element) => { 2034 function onKeyDown(event) { 2035 const { keyCode, shiftKey, altKey, metaKey, ctrlKey } = event; 2036 if ( 2037 // Only override left and right keys without modifiers pressed. 2038 shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_wp_keycodes_namespaceObject.LEFT && keyCode !== external_wp_keycodes_namespaceObject.RIGHT 2039 ) { 2040 return; 2041 } 2042 const { record, applyRecord, forceRender } = props.current; 2043 const { 2044 text, 2045 formats, 2046 start, 2047 end, 2048 activeFormats: currentActiveFormats = [] 2049 } = record.current; 2050 const collapsed = isCollapsed(record.current); 2051 const { ownerDocument } = element; 2052 const { defaultView } = ownerDocument; 2053 const { direction } = defaultView.getComputedStyle(element); 2054 const reverseKey = direction === "rtl" ? external_wp_keycodes_namespaceObject.RIGHT : external_wp_keycodes_namespaceObject.LEFT; 2055 const isReverse = event.keyCode === reverseKey; 2056 if (collapsed && currentActiveFormats.length === 0) { 2057 if (start === 0 && isReverse) { 2058 return; 2059 } 2060 if (end === text.length && !isReverse) { 2061 return; 2062 } 2063 } 2064 if (!collapsed) { 2065 return; 2066 } 2067 const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS; 2068 const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; 2069 const destination = isReverse ? formatsBefore : formatsAfter; 2070 const isIncreasing = currentActiveFormats.every( 2071 (format, index) => format === destination[index] 2072 ); 2073 let newActiveFormatsLength = currentActiveFormats.length; 2074 if (!isIncreasing) { 2075 newActiveFormatsLength--; 2076 } else if (newActiveFormatsLength < destination.length) { 2077 newActiveFormatsLength++; 2078 } 2079 if (newActiveFormatsLength === currentActiveFormats.length) { 2080 record.current._newActiveFormats = destination; 2081 return; 2082 } 2083 event.preventDefault(); 2084 const origin = isReverse ? formatsAfter : formatsBefore; 2085 const source = isIncreasing ? destination : origin; 2086 const newActiveFormats = source.slice(0, newActiveFormatsLength); 2087 const newValue = { 2088 ...record.current, 2089 activeFormats: newActiveFormats 2090 }; 2091 record.current = newValue; 2092 applyRecord(newValue); 2093 forceRender(); 2094 } 2095 element.addEventListener("keydown", onKeyDown); 2096 return () => { 2097 element.removeEventListener("keydown", onKeyDown); 2098 }; 2099 }; 2100 2101 2102 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/delete.js 2103 2104 2105 var delete_default = (props) => (element) => { 2106 function onKeyDown(event) { 2107 const { keyCode } = event; 2108 const { createRecord, handleChange } = props.current; 2109 if (event.defaultPrevented) { 2110 return; 2111 } 2112 if (keyCode !== external_wp_keycodes_namespaceObject.DELETE && keyCode !== external_wp_keycodes_namespaceObject.BACKSPACE) { 2113 return; 2114 } 2115 const currentValue = createRecord(); 2116 const { start, end, text } = currentValue; 2117 if (start === 0 && end !== 0 && end === text.length) { 2118 handleChange(remove_remove(currentValue)); 2119 event.preventDefault(); 2120 } 2121 } 2122 element.addEventListener("keydown", onKeyDown); 2123 return () => { 2124 element.removeEventListener("keydown", onKeyDown); 2125 }; 2126 }; 2127 2128 2129 ;// ./node_modules/@wordpress/rich-text/build-module/update-formats.js 2130 2131 function updateFormats({ value, start, end, formats }) { 2132 const min = Math.min(start, end); 2133 const max = Math.max(start, end); 2134 const formatsBefore = value.formats[min - 1] || []; 2135 const formatsAfter = value.formats[max] || []; 2136 value.activeFormats = formats.map((format, index) => { 2137 if (formatsBefore[index]) { 2138 if (isFormatEqual(format, formatsBefore[index])) { 2139 return formatsBefore[index]; 2140 } 2141 } else if (formatsAfter[index]) { 2142 if (isFormatEqual(format, formatsAfter[index])) { 2143 return formatsAfter[index]; 2144 } 2145 } 2146 return format; 2147 }); 2148 while (--end >= start) { 2149 if (value.activeFormats.length > 0) { 2150 value.formats[end] = value.activeFormats; 2151 } else { 2152 delete value.formats[end]; 2153 } 2154 } 2155 return value; 2156 } 2157 2158 2159 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/input-and-selection.js 2160 2161 2162 const INSERTION_INPUT_TYPES_TO_IGNORE = /* @__PURE__ */ new Set([ 2163 "insertParagraph", 2164 "insertOrderedList", 2165 "insertUnorderedList", 2166 "insertHorizontalRule", 2167 "insertLink" 2168 ]); 2169 const input_and_selection_EMPTY_ACTIVE_FORMATS = []; 2170 const PLACEHOLDER_ATTR_NAME = "data-rich-text-placeholder"; 2171 function fixPlaceholderSelection(defaultView) { 2172 const selection = defaultView.getSelection(); 2173 const { anchorNode, anchorOffset } = selection; 2174 if (anchorNode.nodeType !== anchorNode.ELEMENT_NODE) { 2175 return; 2176 } 2177 const targetNode = anchorNode.childNodes[anchorOffset]; 2178 if (!targetNode || targetNode.nodeType !== targetNode.ELEMENT_NODE || !targetNode.hasAttribute(PLACEHOLDER_ATTR_NAME)) { 2179 return; 2180 } 2181 selection.collapseToStart(); 2182 } 2183 var input_and_selection_default = (props) => (element) => { 2184 const { ownerDocument } = element; 2185 const { defaultView } = ownerDocument; 2186 let isComposing = false; 2187 function onInput(event) { 2188 if (isComposing) { 2189 return; 2190 } 2191 let inputType; 2192 if (event) { 2193 inputType = event.inputType; 2194 } 2195 const { record, applyRecord, createRecord, handleChange } = props.current; 2196 if (inputType && (inputType.indexOf("format") === 0 || INSERTION_INPUT_TYPES_TO_IGNORE.has(inputType))) { 2197 applyRecord(record.current); 2198 return; 2199 } 2200 const currentValue = createRecord(); 2201 const { start, activeFormats: oldActiveFormats = [] } = record.current; 2202 const change = updateFormats({ 2203 value: currentValue, 2204 start, 2205 end: currentValue.start, 2206 formats: oldActiveFormats 2207 }); 2208 handleChange(change); 2209 } 2210 function handleSelectionChange() { 2211 const { record, applyRecord, createRecord, onSelectionChange } = props.current; 2212 if (element.contentEditable !== "true") { 2213 return; 2214 } 2215 if (ownerDocument.activeElement !== element) { 2216 ownerDocument.removeEventListener( 2217 "selectionchange", 2218 handleSelectionChange 2219 ); 2220 return; 2221 } 2222 if (isComposing) { 2223 return; 2224 } 2225 const { start, end, text } = createRecord(); 2226 const oldRecord = record.current; 2227 if (text !== oldRecord.text) { 2228 onInput(); 2229 return; 2230 } 2231 if (start === oldRecord.start && end === oldRecord.end) { 2232 if (oldRecord.text.length === 0 && start === 0) { 2233 fixPlaceholderSelection(defaultView); 2234 } 2235 return; 2236 } 2237 const newValue = { 2238 ...oldRecord, 2239 start, 2240 end, 2241 // _newActiveFormats may be set on arrow key navigation to control 2242 // the right boundary position. If undefined, getActiveFormats will 2243 // give the active formats according to the browser. 2244 activeFormats: oldRecord._newActiveFormats, 2245 _newActiveFormats: void 0 2246 }; 2247 const newActiveFormats = getActiveFormats( 2248 newValue, 2249 input_and_selection_EMPTY_ACTIVE_FORMATS 2250 ); 2251 newValue.activeFormats = newActiveFormats; 2252 record.current = newValue; 2253 applyRecord(newValue, { domOnly: true }); 2254 onSelectionChange(start, end); 2255 } 2256 function onCompositionStart() { 2257 isComposing = true; 2258 ownerDocument.removeEventListener( 2259 "selectionchange", 2260 handleSelectionChange 2261 ); 2262 element.querySelector(`[$PLACEHOLDER_ATTR_NAME}]`)?.remove(); 2263 } 2264 function onCompositionEnd() { 2265 isComposing = false; 2266 onInput({ inputType: "insertText" }); 2267 ownerDocument.addEventListener( 2268 "selectionchange", 2269 handleSelectionChange 2270 ); 2271 } 2272 function onFocus() { 2273 const { record, isSelected, onSelectionChange, applyRecord } = props.current; 2274 if (element.parentElement.closest('[contenteditable="true"]')) { 2275 return; 2276 } 2277 if (!isSelected) { 2278 const index = void 0; 2279 record.current = { 2280 ...record.current, 2281 start: index, 2282 end: index, 2283 activeFormats: input_and_selection_EMPTY_ACTIVE_FORMATS 2284 }; 2285 } else { 2286 applyRecord(record.current, { domOnly: true }); 2287 } 2288 onSelectionChange(record.current.start, record.current.end); 2289 window.queueMicrotask(handleSelectionChange); 2290 ownerDocument.addEventListener( 2291 "selectionchange", 2292 handleSelectionChange 2293 ); 2294 } 2295 element.addEventListener("input", onInput); 2296 element.addEventListener("compositionstart", onCompositionStart); 2297 element.addEventListener("compositionend", onCompositionEnd); 2298 element.addEventListener("focus", onFocus); 2299 return () => { 2300 element.removeEventListener("input", onInput); 2301 element.removeEventListener("compositionstart", onCompositionStart); 2302 element.removeEventListener("compositionend", onCompositionEnd); 2303 element.removeEventListener("focus", onFocus); 2304 }; 2305 }; 2306 2307 2308 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/selection-change-compat.js 2309 2310 var selection_change_compat_default = () => (element) => { 2311 const { ownerDocument } = element; 2312 const { defaultView } = ownerDocument; 2313 const selection = defaultView?.getSelection(); 2314 let range; 2315 function getRange() { 2316 return selection.rangeCount ? selection.getRangeAt(0) : null; 2317 } 2318 function onDown(event) { 2319 const type = event.type === "keydown" ? "keyup" : "pointerup"; 2320 function onCancel() { 2321 ownerDocument.removeEventListener(type, onUp); 2322 ownerDocument.removeEventListener("selectionchange", onCancel); 2323 ownerDocument.removeEventListener("input", onCancel); 2324 } 2325 function onUp() { 2326 onCancel(); 2327 if (isRangeEqual(range, getRange())) { 2328 return; 2329 } 2330 ownerDocument.dispatchEvent(new Event("selectionchange")); 2331 } 2332 ownerDocument.addEventListener(type, onUp); 2333 ownerDocument.addEventListener("selectionchange", onCancel); 2334 ownerDocument.addEventListener("input", onCancel); 2335 range = getRange(); 2336 } 2337 element.addEventListener("pointerdown", onDown); 2338 element.addEventListener("keydown", onDown); 2339 return () => { 2340 element.removeEventListener("pointerdown", onDown); 2341 element.removeEventListener("keydown", onDown); 2342 }; 2343 }; 2344 2345 2346 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/prevent-focus-capture.js 2347 function preventFocusCapture() { 2348 return (element) => { 2349 const { ownerDocument } = element; 2350 const { defaultView } = ownerDocument; 2351 let value = null; 2352 function onPointerDown(event) { 2353 if (event.defaultPrevented) { 2354 return; 2355 } 2356 if (event.target === element) { 2357 return; 2358 } 2359 if (!event.target.contains(element)) { 2360 return; 2361 } 2362 value = element.getAttribute("contenteditable"); 2363 element.setAttribute("contenteditable", "false"); 2364 defaultView.getSelection().removeAllRanges(); 2365 } 2366 function onPointerUp() { 2367 if (value !== null) { 2368 element.setAttribute("contenteditable", value); 2369 value = null; 2370 } 2371 } 2372 defaultView.addEventListener("pointerdown", onPointerDown); 2373 defaultView.addEventListener("pointerup", onPointerUp); 2374 return () => { 2375 defaultView.removeEventListener("pointerdown", onPointerDown); 2376 defaultView.removeEventListener("pointerup", onPointerUp); 2377 }; 2378 }; 2379 } 2380 2381 2382 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/index.js 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 const allEventListeners = [ 2393 copy_handler_default, 2394 select_object_default, 2395 format_boundaries_default, 2396 delete_default, 2397 input_and_selection_default, 2398 selection_change_compat_default, 2399 preventFocusCapture 2400 ]; 2401 function useEventListeners(props) { 2402 const propsRef = (0,external_wp_element_namespaceObject.useRef)(props); 2403 (0,external_wp_element_namespaceObject.useInsertionEffect)(() => { 2404 propsRef.current = props; 2405 }); 2406 const refEffects = (0,external_wp_element_namespaceObject.useMemo)( 2407 () => allEventListeners.map((refEffect) => refEffect(propsRef)), 2408 [propsRef] 2409 ); 2410 return (0,external_wp_compose_namespaceObject.useRefEffect)( 2411 (element) => { 2412 const cleanups = refEffects.map((effect) => effect(element)); 2413 return () => { 2414 cleanups.forEach((cleanup) => cleanup()); 2415 }; 2416 }, 2417 [refEffects] 2418 ); 2419 } 2420 2421 2422 ;// ./node_modules/@wordpress/rich-text/build-module/component/index.js 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 function useRichText({ 2433 value = "", 2434 selectionStart, 2435 selectionEnd, 2436 placeholder, 2437 onSelectionChange, 2438 preserveWhiteSpace, 2439 onChange, 2440 __unstableDisableFormats: disableFormats, 2441 __unstableIsSelected: isSelected, 2442 __unstableDependencies = [], 2443 __unstableAfterParse, 2444 __unstableBeforeSerialize, 2445 __unstableAddInvisibleFormats 2446 }) { 2447 const registry = (0,external_wp_data_namespaceObject.useRegistry)(); 2448 const [, forceRender] = (0,external_wp_element_namespaceObject.useReducer)(() => ({})); 2449 const ref = (0,external_wp_element_namespaceObject.useRef)(); 2450 function createRecord() { 2451 const { 2452 ownerDocument: { defaultView } 2453 } = ref.current; 2454 const selection = defaultView.getSelection(); 2455 const range = selection.rangeCount > 0 ? selection.getRangeAt(0) : null; 2456 return create({ 2457 element: ref.current, 2458 range, 2459 __unstableIsEditableTree: true 2460 }); 2461 } 2462 function applyRecord(newRecord, { domOnly } = {}) { 2463 apply({ 2464 value: newRecord, 2465 current: ref.current, 2466 prepareEditableTree: __unstableAddInvisibleFormats, 2467 __unstableDomOnly: domOnly, 2468 placeholder 2469 }); 2470 } 2471 const _valueRef = (0,external_wp_element_namespaceObject.useRef)(value); 2472 const recordRef = (0,external_wp_element_namespaceObject.useRef)(); 2473 function setRecordFromProps() { 2474 _valueRef.current = value; 2475 recordRef.current = value; 2476 if (!(value instanceof RichTextData)) { 2477 recordRef.current = value ? RichTextData.fromHTMLString(value, { preserveWhiteSpace }) : RichTextData.empty(); 2478 } 2479 recordRef.current = { 2480 text: recordRef.current.text, 2481 formats: recordRef.current.formats, 2482 replacements: recordRef.current.replacements 2483 }; 2484 if (disableFormats) { 2485 recordRef.current.formats = Array(value.length); 2486 recordRef.current.replacements = Array(value.length); 2487 } 2488 if (__unstableAfterParse) { 2489 recordRef.current.formats = __unstableAfterParse( 2490 recordRef.current 2491 ); 2492 } 2493 recordRef.current.start = selectionStart; 2494 recordRef.current.end = selectionEnd; 2495 } 2496 const hadSelectionUpdateRef = (0,external_wp_element_namespaceObject.useRef)(false); 2497 if (!recordRef.current) { 2498 hadSelectionUpdateRef.current = isSelected; 2499 setRecordFromProps(); 2500 } else if (selectionStart !== recordRef.current.start || selectionEnd !== recordRef.current.end) { 2501 hadSelectionUpdateRef.current = isSelected; 2502 recordRef.current = { 2503 ...recordRef.current, 2504 start: selectionStart, 2505 end: selectionEnd, 2506 activeFormats: void 0 2507 }; 2508 } 2509 function handleChange(newRecord) { 2510 recordRef.current = newRecord; 2511 applyRecord(newRecord); 2512 if (disableFormats) { 2513 _valueRef.current = newRecord.text; 2514 } else { 2515 const newFormats = __unstableBeforeSerialize ? __unstableBeforeSerialize(newRecord) : newRecord.formats; 2516 newRecord = { ...newRecord, formats: newFormats }; 2517 if (typeof value === "string") { 2518 _valueRef.current = toHTMLString({ 2519 value: newRecord, 2520 preserveWhiteSpace 2521 }); 2522 } else { 2523 _valueRef.current = new RichTextData(newRecord); 2524 } 2525 } 2526 const { start, end, formats, text } = recordRef.current; 2527 registry.batch(() => { 2528 onSelectionChange(start, end); 2529 onChange(_valueRef.current, { 2530 __unstableFormats: formats, 2531 __unstableText: text 2532 }); 2533 }); 2534 forceRender(); 2535 } 2536 function applyFromProps() { 2537 const previousValue = _valueRef.current; 2538 setRecordFromProps(); 2539 const contentLengthChanged = previousValue && typeof previousValue === "string" && typeof value === "string" && previousValue.length !== value.length; 2540 const hasFocus = ref.current?.contains( 2541 ref.current.ownerDocument.activeElement 2542 ); 2543 const skipSelection = contentLengthChanged && !hasFocus; 2544 applyRecord(recordRef.current, { domOnly: skipSelection }); 2545 } 2546 const didMountRef = (0,external_wp_element_namespaceObject.useRef)(false); 2547 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { 2548 if (didMountRef.current && value !== _valueRef.current) { 2549 applyFromProps(); 2550 forceRender(); 2551 } 2552 }, [value]); 2553 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { 2554 if (!hadSelectionUpdateRef.current) { 2555 return; 2556 } 2557 if (ref.current.ownerDocument.activeElement !== ref.current) { 2558 ref.current.focus(); 2559 } 2560 applyRecord(recordRef.current); 2561 hadSelectionUpdateRef.current = false; 2562 }, [hadSelectionUpdateRef.current]); 2563 const mergedRefs = (0,external_wp_compose_namespaceObject.useMergeRefs)([ 2564 ref, 2565 useDefaultStyle(), 2566 useBoundaryStyle({ record: recordRef }), 2567 useEventListeners({ 2568 record: recordRef, 2569 handleChange, 2570 applyRecord, 2571 createRecord, 2572 isSelected, 2573 onSelectionChange, 2574 forceRender 2575 }), 2576 (0,external_wp_compose_namespaceObject.useRefEffect)(() => { 2577 applyFromProps(); 2578 didMountRef.current = true; 2579 }, [placeholder, ...__unstableDependencies]) 2580 ]); 2581 return { 2582 value: recordRef.current, 2583 // A function to get the most recent value so event handlers in 2584 // useRichText implementations have access to it. For example when 2585 // listening to input events, we internally update the state, but this 2586 // state is not yet available to the input event handler because React 2587 // may re-render asynchronously. 2588 getValue: () => recordRef.current, 2589 onChange: handleChange, 2590 ref: mergedRefs 2591 }; 2592 } 2593 function __experimentalRichText() { 2594 } 2595 2596 2597 ;// ./node_modules/@wordpress/rich-text/build-module/index.js 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 (window.wp = window.wp || {}).richText = __webpack_exports__; 2628 /******/ })() 2629 ;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Oct 27 08:20:06 2025 | Cross-referenced by PHPXref |